etro 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/.env +2 -0
  2. package/.github/workflows/nodejs.yml +27 -0
  3. package/CHANGELOG.md +109 -0
  4. package/CODE_OF_CONDUCT.md +77 -0
  5. package/CONTRIBUTING.md +155 -0
  6. package/LICENSE +674 -0
  7. package/README.md +57 -0
  8. package/dist/etro.js +3397 -0
  9. package/docs/effect.js.html +1215 -0
  10. package/docs/event.js.html +145 -0
  11. package/docs/index.html +81 -0
  12. package/docs/index.js.html +92 -0
  13. package/docs/layer.js.html +888 -0
  14. package/docs/module-effect-GaussianBlurComponent.html +345 -0
  15. package/docs/module-effect.Brightness.html +339 -0
  16. package/docs/module-effect.Channels.html +319 -0
  17. package/docs/module-effect.ChromaKey.html +611 -0
  18. package/docs/module-effect.Contrast.html +339 -0
  19. package/docs/module-effect.EllipticalMask.html +200 -0
  20. package/docs/module-effect.GaussianBlur.html +202 -0
  21. package/docs/module-effect.GaussianBlurHorizontal.html +242 -0
  22. package/docs/module-effect.GaussianBlurVertical.html +242 -0
  23. package/docs/module-effect.Pixelate.html +330 -0
  24. package/docs/module-effect.Shader.html +1227 -0
  25. package/docs/module-effect.Stack.html +406 -0
  26. package/docs/module-effect.Transform.Matrix.html +193 -0
  27. package/docs/module-effect.Transform.html +1174 -0
  28. package/docs/module-effect.html +148 -0
  29. package/docs/module-event.html +473 -0
  30. package/docs/module-index.html +186 -0
  31. package/docs/module-layer-Media.html +1116 -0
  32. package/docs/module-layer-MediaMixin.html +164 -0
  33. package/docs/module-layer.Audio.html +1188 -0
  34. package/docs/module-layer.Base.html +629 -0
  35. package/docs/module-layer.Image.html +1421 -0
  36. package/docs/module-layer.Text.html +1731 -0
  37. package/docs/module-layer.Video.html +1938 -0
  38. package/docs/module-layer.Visual.html +1698 -0
  39. package/docs/module-layer.html +137 -0
  40. package/docs/module-movie.html +3118 -0
  41. package/docs/module-util.Color.html +702 -0
  42. package/docs/module-util.Font.html +395 -0
  43. package/docs/module-util.html +845 -0
  44. package/docs/movie.js.html +689 -0
  45. package/docs/scripts/collapse.js +20 -0
  46. package/docs/scripts/linenumber.js +25 -0
  47. package/docs/scripts/nav.js +12 -0
  48. package/docs/scripts/polyfill.js +4 -0
  49. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  50. package/docs/scripts/prettify/lang-css.js +2 -0
  51. package/docs/scripts/prettify/prettify.js +28 -0
  52. package/docs/scripts/search.js +83 -0
  53. package/docs/styles/jsdoc.css +671 -0
  54. package/docs/styles/prettify.css +79 -0
  55. package/docs/util.js.html +503 -0
  56. package/eslint.conf.js +28 -0
  57. package/eslint.test-conf.js +4 -0
  58. package/examples/application/readme-screenshot.html +86 -0
  59. package/examples/application/video-player.html +131 -0
  60. package/examples/application/webcam.html +28 -0
  61. package/examples/introduction/audio.html +52 -0
  62. package/examples/introduction/effects.html +56 -0
  63. package/examples/introduction/export.html +70 -0
  64. package/examples/introduction/functions.html +35 -0
  65. package/examples/introduction/hello-world1.html +33 -0
  66. package/examples/introduction/hello-world2.html +32 -0
  67. package/examples/introduction/keyframes.html +67 -0
  68. package/examples/introduction/media.html +55 -0
  69. package/examples/introduction/text.html +27 -0
  70. package/jsdoc.conf.json +3 -0
  71. package/karma.conf.js +60 -0
  72. package/package.json +63 -0
  73. package/private-todo.txt +70 -0
  74. package/rename-file.sh +18 -0
  75. package/rename-versions.sh +14 -0
  76. package/rename.sh +22 -0
  77. package/rollup.config.js +31 -0
  78. package/screenshots/2019-08-17_0.png +0 -0
  79. package/scripts/gen-effect-samples.html +99 -0
  80. package/scripts/save-effect-samples.js +43 -0
  81. package/spec/assets/effect/gaussian-blur-horizontal.png +0 -0
  82. package/spec/assets/effect/gaussian-blur-vertical.png +0 -0
  83. package/spec/assets/effect/original.png +0 -0
  84. package/spec/assets/effect/pixelate.png +0 -0
  85. package/spec/assets/effect/transform/multiply.png +0 -0
  86. package/spec/assets/effect/transform/rotate.png +0 -0
  87. package/spec/assets/effect/transform/scale-fraction.png +0 -0
  88. package/spec/assets/effect/transform/scale.png +0 -0
  89. package/spec/assets/effect/transform/translate-fraction.png +0 -0
  90. package/spec/assets/effect/transform/translate.png +0 -0
  91. package/spec/assets/layer/audio.wav +0 -0
  92. package/spec/assets/layer/image.jpg +0 -0
  93. package/spec/effect.spec.js +352 -0
  94. package/spec/event.spec.js +25 -0
  95. package/spec/layer.spec.js +128 -0
  96. package/spec/movie.spec.js +154 -0
  97. package/spec/util.spec.js +285 -0
  98. package/src/effect.js +1265 -0
  99. package/src/event.js +78 -0
  100. package/src/index.js +23 -0
  101. package/src/layer.js +875 -0
  102. package/src/movie.js +636 -0
  103. package/src/util.js +487 -0
@@ -0,0 +1,285 @@
1
+ describe('Util', function () {
2
+ describe('applyOptions', function () {
3
+ it('should not apply any options with no provided or default options', function () {
4
+ const etroobj = {
5
+ getDefaultOptions () {
6
+ return {}
7
+ }
8
+ }
9
+ const snapshot = { ...etroobj } // store state before applying options
10
+ etro.applyOptions({}, etroobj)
11
+ expect(etroobj).toEqual(snapshot) // should be the same as it was
12
+ })
13
+
14
+ it('should apply default options', function () {
15
+ const etroobj = {
16
+ getDefaultOptions () {
17
+ return defaultOpt
18
+ }
19
+ }
20
+ const snapshot = { ...etroobj } // store state before applying options
21
+ const defaultOpt = { foo: 1 }
22
+ etro.applyOptions({}, etroobj)
23
+ expect(etroobj).toEqual({ ...defaultOpt, ...snapshot }) // defaultOpt should be applied to etroobj
24
+ })
25
+
26
+ it('should not override provided options with default values', function () {
27
+ const etroobj = {
28
+ getDefaultOptions () {
29
+ return { foo: 1 }
30
+ }
31
+ }
32
+ const providedOpt = { foo: 2 }
33
+ etro.applyOptions(providedOpt, etroobj)
34
+ expect(etroobj.foo).toBe(providedOpt.foo)
35
+ })
36
+
37
+ it('should not override existing object state', function () {
38
+ const etroobj = {
39
+ foo: 0,
40
+ getDefaultOptions () {
41
+ return { foo: 1 }
42
+ }
43
+ }
44
+ const originalFoo = etroobj.foo
45
+ etro.applyOptions({ foo: 2 }, etroobj)
46
+ expect(etroobj.foo).toBe(originalFoo)
47
+ })
48
+
49
+ it('should not allow arbitrary options', function () {
50
+ const etroobj = {
51
+ getDefaultOptions () {
52
+ return {}
53
+ }
54
+ }
55
+ expect(() => etro.applyOptions({ foo: null }, etroobj).toThrow(new Error("Invalid option: 'foo'")))
56
+ })
57
+ })
58
+
59
+ describe('val', function () {
60
+ it('should work on simple values', function () {
61
+ // _movie is unique, so it won't depend on existing cache
62
+ const elem = { prop: 'value', movie: {}, propertyFilters: {} }
63
+ expect(etro.val(elem, 'prop', 0)).toBe(elem.prop)
64
+ })
65
+
66
+ it('should interpolate keyframes', function () {
67
+ const elem = {
68
+ prop: { 0: 0, 4: 1 },
69
+ movie: {}, // _movie is unique, so it won't depend on existing cache
70
+ propertyFilters: {}
71
+ }
72
+ for (let i = 0; i <= 4; i += Math.random()) {
73
+ expect(etro.val(elem, 'prop', i)).toBe(i / 4)
74
+ etro.clearCachedValues(elem.movie)
75
+ }
76
+ })
77
+
78
+ it('should work with noninterpolated keyframes', function () {
79
+ const elem = {
80
+ prop: { 0: 'start', 4: 'end' },
81
+ movie: {}, // _movie is unique, so it won't depend on existing cache
82
+ propertyFilters: {}
83
+ }
84
+ expect(etro.val(elem, 'prop', 0)).toBe(elem.prop[0])
85
+ etro.clearCachedValues(elem.movie)
86
+ expect(etro.val(elem, 'prop', 3)).toBe(elem.prop[0])
87
+ etro.clearCachedValues(elem.movie)
88
+ expect(etro.val(elem, 'prop', 4)).toBe(elem.prop[4])
89
+ etro.clearCachedValues(elem.movie)
90
+ })
91
+
92
+ it('should call property filters', function () {
93
+ const elem = {
94
+ prop: 'value',
95
+ movie: {},
96
+ propertyFilters: {
97
+ prop: () => 'new value'
98
+ }
99
+ }
100
+ expect(etro.val(elem, 'prop', 0)).toBe('new value')
101
+ })
102
+ })
103
+
104
+ describe('linearInterp', function () {
105
+ it('should interpolate numbers', function () {
106
+ expect(etro.linearInterp(5, 10, 0.5, undefined)).toBe(7.5)
107
+ })
108
+
109
+ it('should choose the first string', function () {
110
+ expect(etro.linearInterp('hello', 'world', 0.5)).toBe('hello')
111
+ })
112
+
113
+ it('should interpolate objects recursively', function () {
114
+ expect(etro.linearInterp(
115
+ {
116
+ foo: {
117
+ bar: 0
118
+ }
119
+ },
120
+ {
121
+ foo: {
122
+ bar: 100
123
+ }
124
+ },
125
+ 0.5,
126
+ undefined
127
+ )).toEqual(
128
+ {
129
+ foo: {
130
+ bar: 50
131
+ }
132
+ }
133
+ )
134
+ })
135
+ })
136
+
137
+ describe('cosineInterp', function () {
138
+ it('should interpolate numbers', function () {
139
+ const x1 = 5
140
+ const x2 = 10
141
+ const t = 0.5
142
+ const cos = Math.cos(t * Math.PI / 2)
143
+ expect(etro.cosineInterp(x1, x2, t, undefined))
144
+ .toBe(cos * x1 + (1 - cos) * x2)
145
+ })
146
+
147
+ it('should choose the first string', function () {
148
+ expect(etro.linearInterp('hello', 'world', 0.5)).toBe('hello')
149
+ })
150
+
151
+ it('should interpolate objects recursively', function () {
152
+ expect(etro.cosineInterp(
153
+ {
154
+ foo: {
155
+ bar: 0
156
+ }
157
+ },
158
+ {
159
+ foo: {
160
+ bar: 100
161
+ }
162
+ },
163
+ 0.5,
164
+ undefined
165
+ )).toEqual(
166
+ {
167
+ foo: {
168
+ bar: (1 - Math.cos(0.5 * Math.PI / 2)) * 100
169
+ }
170
+ }
171
+ )
172
+ })
173
+ })
174
+
175
+ describe('Color ->', function () {
176
+ it('toString() should convert to RGBA', function () {
177
+ expect(new etro.Color(255, 0, 255, 0.5).toString())
178
+ .toBe('rgba(255, 0, 255, 0.5)')
179
+ })
180
+ })
181
+
182
+ describe('parseColor', function () {
183
+ it('should parse RGB colors', function () {
184
+ expect(etro.parseColor('rgb(255,0,0)'))
185
+ .toEqual(new etro.Color(255, 0, 0))
186
+ })
187
+
188
+ it('should parse RGBA colors', function () {
189
+ expect(etro.parseColor('rgba(0,255,0,1)'))
190
+ .toEqual(new etro.Color(0, 255, 0, 1))
191
+ })
192
+
193
+ it('should parse hex colors', function () {
194
+ expect(etro.parseColor('#00f'))
195
+ .toEqual(new etro.Color(0, 0, 255))
196
+ })
197
+
198
+ it('should parse named colors', function () {
199
+ expect(etro.parseColor('blue'))
200
+ .toEqual(new etro.Color(0, 0, 255))
201
+ })
202
+ })
203
+
204
+ describe('Font ->', function () {
205
+ it('toString() should convert to CSS font', function () {
206
+ expect(new etro.Font(16, 'px', 'monospace').toString())
207
+ .toBe('16px monospace')
208
+ })
209
+ })
210
+
211
+ describe('parseFont', function () {
212
+ it('should parse CSS fonts', function () {
213
+ expect(etro.parseFont('16em monospace'))
214
+ .toEqual(new etro.Font(16, 'em', 'monospace'))
215
+ })
216
+
217
+ it('should work with multiple word fonts', function () {
218
+ expect(etro.parseFont('16px "Times New Roman"'))
219
+ .toEqual(new etro.Font(16, 'px', '"Times New Roman"'))
220
+ })
221
+ })
222
+
223
+ describe('watchPublic', function () {
224
+ it('should watch public properties', function () {
225
+ const element = etro.watchPublic({
226
+ // mock etro element
227
+ publicExcludes: [],
228
+ type: 'test'
229
+ })
230
+ element.foo = 0 // intiialize (must be after watchPublic)
231
+ const history = []
232
+ etro.event.subscribe(element, 'test.change.modify', event => history.push(event))
233
+
234
+ element.foo = 1
235
+ expect(history).toEqual([
236
+ {
237
+ target: element,
238
+ type: 'test.change.modify',
239
+ property: 'foo',
240
+ newValue: 1
241
+ }
242
+ ])
243
+ })
244
+
245
+ it("should watch recursive modifications that don't change the schema", function () {
246
+ const element = etro.watchPublic({
247
+ publicExcludes: [],
248
+ type: 'test'
249
+ })
250
+ element.foo = { bar: 0 } // intiialize (must be after watchPublic)
251
+ const history = []
252
+ etro.event.subscribe(element, 'test.change.modify', event => history.push(event))
253
+
254
+ element.foo.bar = 1
255
+ expect(history).toEqual([
256
+ {
257
+ target: element,
258
+ type: 'test.change.modify',
259
+ property: 'foo.bar',
260
+ newValue: 1
261
+ }
262
+ ])
263
+ })
264
+
265
+ it('should watch recursive modifications that change the schema', function () {
266
+ const element = etro.watchPublic({
267
+ publicExcludes: [],
268
+ type: 'test'
269
+ })
270
+ element.foo = {} // intiialize (must be after watchPublic)
271
+ const history = []
272
+ etro.event.subscribe(element, 'test.change.modify', event => history.push(event))
273
+
274
+ element.foo.bar = 1
275
+ expect(history).toEqual([
276
+ {
277
+ target: element,
278
+ type: 'test.change.modify',
279
+ property: 'foo.bar',
280
+ newValue: 1
281
+ }
282
+ ])
283
+ })
284
+ })
285
+ })