super-three 0.155.0 → 0.156.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 (108) hide show
  1. package/build/three.cjs +107 -125
  2. package/build/three.js +107 -125
  3. package/build/three.min.js +1 -1
  4. package/build/three.module.js +104 -126
  5. package/build/three.module.min.js +1 -1
  6. package/examples/jsm/controls/OrbitControls.js +13 -5
  7. package/examples/jsm/csm/CSMShader.js +35 -1
  8. package/examples/jsm/libs/tween.module.js +790 -735
  9. package/examples/jsm/libs/utif.module.js +1644 -1558
  10. package/examples/jsm/loaders/DDSLoader.js +46 -3
  11. package/examples/jsm/loaders/EXRLoader.js +4 -4
  12. package/examples/jsm/loaders/FBXLoader.js +2 -0
  13. package/examples/jsm/loaders/GLTFLoader.js +17 -7
  14. package/examples/jsm/loaders/KTX2Loader.js +126 -77
  15. package/examples/jsm/loaders/LogLuvLoader.js +2 -2
  16. package/examples/jsm/loaders/MMDLoader.js +10 -7
  17. package/examples/jsm/loaders/RGBELoader.js +48 -66
  18. package/examples/jsm/loaders/STLLoader.js +7 -0
  19. package/examples/jsm/nodes/Nodes.js +3 -0
  20. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +28 -2
  21. package/examples/jsm/nodes/accessors/CubeTextureNode.js +18 -3
  22. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +2 -4
  23. package/examples/jsm/nodes/accessors/LineMaterialNode.js +31 -0
  24. package/examples/jsm/nodes/accessors/MaterialNode.js +55 -33
  25. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +3 -0
  26. package/examples/jsm/nodes/accessors/Object3DNode.js +2 -2
  27. package/examples/jsm/nodes/accessors/TextureNode.js +6 -2
  28. package/examples/jsm/nodes/accessors/TextureStoreNode.js +29 -0
  29. package/examples/jsm/nodes/core/AttributeNode.js +2 -2
  30. package/examples/jsm/nodes/core/Node.js +17 -1
  31. package/examples/jsm/nodes/core/NodeBuilder.js +94 -12
  32. package/examples/jsm/nodes/core/NodeUniform.js +1 -1
  33. package/examples/jsm/nodes/core/OutputStructNode.js +58 -0
  34. package/examples/jsm/nodes/core/PropertyNode.js +2 -0
  35. package/examples/jsm/nodes/core/StackNode.js +4 -4
  36. package/examples/jsm/nodes/core/StructTypeNode.js +24 -0
  37. package/examples/jsm/nodes/display/ViewportNode.js +19 -5
  38. package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -0
  39. package/examples/jsm/nodes/materials/Materials.js +1 -0
  40. package/examples/jsm/nodes/materials/NodeMaterial.js +12 -3
  41. package/examples/jsm/nodes/math/HashNode.js +35 -0
  42. package/examples/jsm/nodes/shadernode/ShaderNode.js +4 -0
  43. package/examples/jsm/nodes/utils/SplitNode.js +1 -1
  44. package/examples/jsm/postprocessing/FilmPass.js +3 -5
  45. package/examples/jsm/postprocessing/RenderPass.js +30 -12
  46. package/examples/jsm/postprocessing/SAOPass.js +23 -98
  47. package/examples/jsm/postprocessing/SSAOPass.js +10 -30
  48. package/examples/jsm/renderers/common/Backend.js +11 -8
  49. package/examples/jsm/renderers/common/Binding.js +6 -0
  50. package/examples/jsm/renderers/common/Bindings.js +5 -4
  51. package/examples/jsm/renderers/common/Pipelines.js +2 -2
  52. package/examples/jsm/renderers/common/RenderContexts.js +26 -1
  53. package/examples/jsm/renderers/common/RenderList.js +12 -4
  54. package/examples/jsm/renderers/common/RenderObject.js +6 -2
  55. package/examples/jsm/renderers/common/Renderer.js +12 -3
  56. package/examples/jsm/renderers/common/SampledTexture.js +2 -1
  57. package/examples/jsm/renderers/common/Sampler.js +1 -1
  58. package/examples/jsm/renderers/common/StorageBuffer.js +1 -1
  59. package/examples/jsm/renderers/common/Textures.js +155 -15
  60. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +2 -2
  61. package/examples/jsm/renderers/common/nodes/NodeSampler.js +1 -1
  62. package/examples/jsm/renderers/common/nodes/Nodes.js +43 -9
  63. package/examples/jsm/renderers/webgl/WebGLBackend.js +607 -0
  64. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +118 -17
  65. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +84 -0
  66. package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +26 -0
  67. package/examples/jsm/renderers/webgl/utils/WebGLState.js +529 -0
  68. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +199 -0
  69. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +242 -0
  70. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +340 -0
  71. package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodeBuilder.js +1 -1
  72. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +279 -40
  73. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +18 -2
  74. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +89 -59
  75. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -2
  76. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +15 -2
  77. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +34 -9
  78. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +26 -135
  79. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +6 -5
  80. package/examples/jsm/shaders/FilmShader.js +11 -54
  81. package/examples/jsm/shaders/SAOShader.js +0 -13
  82. package/examples/jsm/shaders/SSAOShader.js +33 -26
  83. package/package.json +1 -1
  84. package/src/Three.js +1 -0
  85. package/src/audio/Audio.js +6 -0
  86. package/src/constants.js +4 -1
  87. package/src/core/Object3D.js +1 -14
  88. package/src/core/UniformsGroup.js +2 -2
  89. package/src/loaders/DataTextureLoader.js +0 -2
  90. package/src/materials/Material.js +2 -2
  91. package/src/math/Vector2.js +2 -2
  92. package/src/math/Vector3.js +3 -3
  93. package/src/math/Vector4.js +4 -4
  94. package/src/objects/Line.js +1 -1
  95. package/src/objects/Mesh.js +1 -1
  96. package/src/objects/Points.js +1 -1
  97. package/src/renderers/WebGLRenderer.js +21 -49
  98. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +11 -1
  99. package/src/renderers/shaders/ShaderLib/background.glsl.js +8 -0
  100. package/src/renderers/webgl/WebGLBackground.js +5 -14
  101. package/src/renderers/webgl/WebGLProgram.js +2 -0
  102. package/src/renderers/webgl/WebGLPrograms.js +5 -1
  103. package/src/renderers/webgl/WebGLTextures.js +4 -4
  104. package/src/renderers/webgl/WebGLUtils.js +27 -20
  105. package/src/textures/Texture.js +2 -2
  106. package/src/utils.js +9 -1
  107. /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/SlotNode.js +0 -0
  108. /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodes.js +0 -0
@@ -1,221 +1,219 @@
1
1
  /**
2
2
  * The Ease class provides a collection of easing functions for use with tween.js.
3
3
  */
4
- var Easing = {
5
- Linear: {
6
- None: function (amount) {
7
- return amount;
8
- },
9
- },
10
- Quadratic: {
11
- In: function (amount) {
12
- return amount * amount;
13
- },
14
- Out: function (amount) {
15
- return amount * (2 - amount);
16
- },
17
- InOut: function (amount) {
18
- if ((amount *= 2) < 1) {
19
- return 0.5 * amount * amount;
20
- }
21
- return -0.5 * (--amount * (amount - 2) - 1);
22
- },
23
- },
24
- Cubic: {
25
- In: function (amount) {
26
- return amount * amount * amount;
27
- },
28
- Out: function (amount) {
29
- return --amount * amount * amount + 1;
30
- },
31
- InOut: function (amount) {
32
- if ((amount *= 2) < 1) {
33
- return 0.5 * amount * amount * amount;
34
- }
35
- return 0.5 * ((amount -= 2) * amount * amount + 2);
36
- },
37
- },
38
- Quartic: {
39
- In: function (amount) {
40
- return amount * amount * amount * amount;
41
- },
42
- Out: function (amount) {
43
- return 1 - --amount * amount * amount * amount;
44
- },
45
- InOut: function (amount) {
46
- if ((amount *= 2) < 1) {
47
- return 0.5 * amount * amount * amount * amount;
48
- }
49
- return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
50
- },
51
- },
52
- Quintic: {
53
- In: function (amount) {
54
- return amount * amount * amount * amount * amount;
55
- },
56
- Out: function (amount) {
57
- return --amount * amount * amount * amount * amount + 1;
58
- },
59
- InOut: function (amount) {
60
- if ((amount *= 2) < 1) {
61
- return 0.5 * amount * amount * amount * amount * amount;
62
- }
63
- return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
64
- },
65
- },
66
- Sinusoidal: {
67
- In: function (amount) {
68
- return 1 - Math.cos((amount * Math.PI) / 2);
69
- },
70
- Out: function (amount) {
71
- return Math.sin((amount * Math.PI) / 2);
72
- },
73
- InOut: function (amount) {
74
- return 0.5 * (1 - Math.cos(Math.PI * amount));
75
- },
76
- },
77
- Exponential: {
78
- In: function (amount) {
79
- return amount === 0 ? 0 : Math.pow(1024, amount - 1);
80
- },
81
- Out: function (amount) {
82
- return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
83
- },
84
- InOut: function (amount) {
85
- if (amount === 0) {
86
- return 0;
87
- }
88
- if (amount === 1) {
89
- return 1;
90
- }
91
- if ((amount *= 2) < 1) {
92
- return 0.5 * Math.pow(1024, amount - 1);
93
- }
94
- return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
95
- },
96
- },
97
- Circular: {
98
- In: function (amount) {
99
- return 1 - Math.sqrt(1 - amount * amount);
100
- },
101
- Out: function (amount) {
102
- return Math.sqrt(1 - --amount * amount);
103
- },
104
- InOut: function (amount) {
105
- if ((amount *= 2) < 1) {
106
- return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
107
- }
108
- return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
109
- },
110
- },
111
- Elastic: {
112
- In: function (amount) {
113
- if (amount === 0) {
114
- return 0;
115
- }
116
- if (amount === 1) {
117
- return 1;
118
- }
119
- return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
120
- },
121
- Out: function (amount) {
122
- if (amount === 0) {
123
- return 0;
124
- }
125
- if (amount === 1) {
126
- return 1;
127
- }
128
- return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
129
- },
130
- InOut: function (amount) {
131
- if (amount === 0) {
132
- return 0;
133
- }
134
- if (amount === 1) {
135
- return 1;
136
- }
137
- amount *= 2;
138
- if (amount < 1) {
139
- return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
140
- }
141
- return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
142
- },
143
- },
144
- Back: {
145
- In: function (amount) {
146
- var s = 1.70158;
147
- return amount * amount * ((s + 1) * amount - s);
148
- },
149
- Out: function (amount) {
150
- var s = 1.70158;
151
- return --amount * amount * ((s + 1) * amount + s) + 1;
152
- },
153
- InOut: function (amount) {
154
- var s = 1.70158 * 1.525;
155
- if ((amount *= 2) < 1) {
156
- return 0.5 * (amount * amount * ((s + 1) * amount - s));
157
- }
158
- return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
159
- },
160
- },
161
- Bounce: {
162
- In: function (amount) {
163
- return 1 - Easing.Bounce.Out(1 - amount);
164
- },
165
- Out: function (amount) {
166
- if (amount < 1 / 2.75) {
167
- return 7.5625 * amount * amount;
168
- }
169
- else if (amount < 2 / 2.75) {
170
- return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
171
- }
172
- else if (amount < 2.5 / 2.75) {
173
- return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
174
- }
175
- else {
176
- return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
177
- }
178
- },
179
- InOut: function (amount) {
180
- if (amount < 0.5) {
181
- return Easing.Bounce.In(amount * 2) * 0.5;
182
- }
183
- return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
184
- },
185
- },
186
- };
4
+ var Easing = Object.freeze({
5
+ Linear: Object.freeze({
6
+ None: function (amount) {
7
+ return amount;
8
+ },
9
+ In: function (amount) {
10
+ return this.None(amount);
11
+ },
12
+ Out: function (amount) {
13
+ return this.None(amount);
14
+ },
15
+ InOut: function (amount) {
16
+ return this.None(amount);
17
+ },
18
+ }),
19
+ Quadratic: Object.freeze({
20
+ In: function (amount) {
21
+ return amount * amount;
22
+ },
23
+ Out: function (amount) {
24
+ return amount * (2 - amount);
25
+ },
26
+ InOut: function (amount) {
27
+ if ((amount *= 2) < 1) {
28
+ return 0.5 * amount * amount;
29
+ }
30
+ return -0.5 * (--amount * (amount - 2) - 1);
31
+ },
32
+ }),
33
+ Cubic: Object.freeze({
34
+ In: function (amount) {
35
+ return amount * amount * amount;
36
+ },
37
+ Out: function (amount) {
38
+ return --amount * amount * amount + 1;
39
+ },
40
+ InOut: function (amount) {
41
+ if ((amount *= 2) < 1) {
42
+ return 0.5 * amount * amount * amount;
43
+ }
44
+ return 0.5 * ((amount -= 2) * amount * amount + 2);
45
+ },
46
+ }),
47
+ Quartic: Object.freeze({
48
+ In: function (amount) {
49
+ return amount * amount * amount * amount;
50
+ },
51
+ Out: function (amount) {
52
+ return 1 - --amount * amount * amount * amount;
53
+ },
54
+ InOut: function (amount) {
55
+ if ((amount *= 2) < 1) {
56
+ return 0.5 * amount * amount * amount * amount;
57
+ }
58
+ return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
59
+ },
60
+ }),
61
+ Quintic: Object.freeze({
62
+ In: function (amount) {
63
+ return amount * amount * amount * amount * amount;
64
+ },
65
+ Out: function (amount) {
66
+ return --amount * amount * amount * amount * amount + 1;
67
+ },
68
+ InOut: function (amount) {
69
+ if ((amount *= 2) < 1) {
70
+ return 0.5 * amount * amount * amount * amount * amount;
71
+ }
72
+ return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
73
+ },
74
+ }),
75
+ Sinusoidal: Object.freeze({
76
+ In: function (amount) {
77
+ return 1 - Math.sin(((1.0 - amount) * Math.PI) / 2);
78
+ },
79
+ Out: function (amount) {
80
+ return Math.sin((amount * Math.PI) / 2);
81
+ },
82
+ InOut: function (amount) {
83
+ return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
84
+ },
85
+ }),
86
+ Exponential: Object.freeze({
87
+ In: function (amount) {
88
+ return amount === 0 ? 0 : Math.pow(1024, amount - 1);
89
+ },
90
+ Out: function (amount) {
91
+ return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
92
+ },
93
+ InOut: function (amount) {
94
+ if (amount === 0) {
95
+ return 0;
96
+ }
97
+ if (amount === 1) {
98
+ return 1;
99
+ }
100
+ if ((amount *= 2) < 1) {
101
+ return 0.5 * Math.pow(1024, amount - 1);
102
+ }
103
+ return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
104
+ },
105
+ }),
106
+ Circular: Object.freeze({
107
+ In: function (amount) {
108
+ return 1 - Math.sqrt(1 - amount * amount);
109
+ },
110
+ Out: function (amount) {
111
+ return Math.sqrt(1 - --amount * amount);
112
+ },
113
+ InOut: function (amount) {
114
+ if ((amount *= 2) < 1) {
115
+ return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
116
+ }
117
+ return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
118
+ },
119
+ }),
120
+ Elastic: Object.freeze({
121
+ In: function (amount) {
122
+ if (amount === 0) {
123
+ return 0;
124
+ }
125
+ if (amount === 1) {
126
+ return 1;
127
+ }
128
+ return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
129
+ },
130
+ Out: function (amount) {
131
+ if (amount === 0) {
132
+ return 0;
133
+ }
134
+ if (amount === 1) {
135
+ return 1;
136
+ }
137
+ return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
138
+ },
139
+ InOut: function (amount) {
140
+ if (amount === 0) {
141
+ return 0;
142
+ }
143
+ if (amount === 1) {
144
+ return 1;
145
+ }
146
+ amount *= 2;
147
+ if (amount < 1) {
148
+ return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
149
+ }
150
+ return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
151
+ },
152
+ }),
153
+ Back: Object.freeze({
154
+ In: function (amount) {
155
+ var s = 1.70158;
156
+ return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
157
+ },
158
+ Out: function (amount) {
159
+ var s = 1.70158;
160
+ return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
161
+ },
162
+ InOut: function (amount) {
163
+ var s = 1.70158 * 1.525;
164
+ if ((amount *= 2) < 1) {
165
+ return 0.5 * (amount * amount * ((s + 1) * amount - s));
166
+ }
167
+ return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
168
+ },
169
+ }),
170
+ Bounce: Object.freeze({
171
+ In: function (amount) {
172
+ return 1 - Easing.Bounce.Out(1 - amount);
173
+ },
174
+ Out: function (amount) {
175
+ if (amount < 1 / 2.75) {
176
+ return 7.5625 * amount * amount;
177
+ }
178
+ else if (amount < 2 / 2.75) {
179
+ return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
180
+ }
181
+ else if (amount < 2.5 / 2.75) {
182
+ return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
183
+ }
184
+ else {
185
+ return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
186
+ }
187
+ },
188
+ InOut: function (amount) {
189
+ if (amount < 0.5) {
190
+ return Easing.Bounce.In(amount * 2) * 0.5;
191
+ }
192
+ return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
193
+ },
194
+ }),
195
+ generatePow: function (power) {
196
+ if (power === void 0) { power = 4; }
197
+ power = power < Number.EPSILON ? Number.EPSILON : power;
198
+ power = power > 10000 ? 10000 : power;
199
+ return {
200
+ In: function (amount) {
201
+ return Math.pow(amount, power);
202
+ },
203
+ Out: function (amount) {
204
+ return 1 - Math.pow((1 - amount), power);
205
+ },
206
+ InOut: function (amount) {
207
+ if (amount < 0.5) {
208
+ return Math.pow((amount * 2), power) / 2;
209
+ }
210
+ return (1 - Math.pow((2 - amount * 2), power)) / 2 + 0.5;
211
+ },
212
+ };
213
+ },
214
+ });
187
215
 
188
- var now;
189
- // Include a performance.now polyfill.
190
- // In node.js, use process.hrtime.
191
- // eslint-disable-next-line
192
- // @ts-ignore
193
- if (typeof self === 'undefined' && typeof process !== 'undefined' && process.hrtime) {
194
- now = function () {
195
- // eslint-disable-next-line
196
- // @ts-ignore
197
- var time = process.hrtime();
198
- // Convert [seconds, nanoseconds] to milliseconds.
199
- return time[0] * 1000 + time[1] / 1000000;
200
- };
201
- }
202
- // In a browser, use self.performance.now if it is available.
203
- else if (typeof self !== 'undefined' && self.performance !== undefined && self.performance.now !== undefined) {
204
- // This must be bound, because directly assigning this function
205
- // leads to an invocation exception in Chrome.
206
- now = self.performance.now.bind(self.performance);
207
- }
208
- // Use Date.now if it is available.
209
- else if (Date.now !== undefined) {
210
- now = Date.now;
211
- }
212
- // Otherwise, use 'new Date().getTime()'.
213
- else {
214
- now = function () {
215
- return new Date().getTime();
216
- };
217
- }
218
- var now$1 = now;
216
+ var now = function () { return performance.now(); };
219
217
 
220
218
  /**
221
219
  * Controlling groups of tweens
@@ -224,146 +222,146 @@ var now$1 = now;
224
222
  * In these cases, you may want to create your own smaller groups of tween
225
223
  */
226
224
  var Group = /** @class */ (function () {
227
- function Group() {
228
- this._tweens = {};
229
- this._tweensAddedDuringUpdate = {};
230
- }
231
- Group.prototype.getAll = function () {
232
- var _this = this;
233
- return Object.keys(this._tweens).map(function (tweenId) {
234
- return _this._tweens[tweenId];
235
- });
236
- };
237
- Group.prototype.removeAll = function () {
238
- this._tweens = {};
239
- };
240
- Group.prototype.add = function (tween) {
241
- this._tweens[tween.getId()] = tween;
242
- this._tweensAddedDuringUpdate[tween.getId()] = tween;
243
- };
244
- Group.prototype.remove = function (tween) {
245
- delete this._tweens[tween.getId()];
246
- delete this._tweensAddedDuringUpdate[tween.getId()];
247
- };
248
- Group.prototype.update = function (time, preserve) {
249
- if (time === void 0) { time = now$1(); }
250
- if (preserve === void 0) { preserve = false; }
251
- var tweenIds = Object.keys(this._tweens);
252
- if (tweenIds.length === 0) {
253
- return false;
254
- }
255
- // Tweens are updated in "batches". If you add a new tween during an
256
- // update, then the new tween will be updated in the next batch.
257
- // If you remove a tween during an update, it may or may not be updated.
258
- // However, if the removed tween was added during the current batch,
259
- // then it will not be updated.
260
- while (tweenIds.length > 0) {
261
- this._tweensAddedDuringUpdate = {};
262
- for (var i = 0; i < tweenIds.length; i++) {
263
- var tween = this._tweens[tweenIds[i]];
264
- var autoStart = !preserve;
265
- if (tween && tween.update(time, autoStart) === false && !preserve) {
266
- delete this._tweens[tweenIds[i]];
267
- }
268
- }
269
- tweenIds = Object.keys(this._tweensAddedDuringUpdate);
270
- }
271
- return true;
272
- };
273
- return Group;
225
+ function Group() {
226
+ this._tweens = {};
227
+ this._tweensAddedDuringUpdate = {};
228
+ }
229
+ Group.prototype.getAll = function () {
230
+ var _this = this;
231
+ return Object.keys(this._tweens).map(function (tweenId) {
232
+ return _this._tweens[tweenId];
233
+ });
234
+ };
235
+ Group.prototype.removeAll = function () {
236
+ this._tweens = {};
237
+ };
238
+ Group.prototype.add = function (tween) {
239
+ this._tweens[tween.getId()] = tween;
240
+ this._tweensAddedDuringUpdate[tween.getId()] = tween;
241
+ };
242
+ Group.prototype.remove = function (tween) {
243
+ delete this._tweens[tween.getId()];
244
+ delete this._tweensAddedDuringUpdate[tween.getId()];
245
+ };
246
+ Group.prototype.update = function (time, preserve) {
247
+ if (time === void 0) { time = now(); }
248
+ if (preserve === void 0) { preserve = false; }
249
+ var tweenIds = Object.keys(this._tweens);
250
+ if (tweenIds.length === 0) {
251
+ return false;
252
+ }
253
+ // Tweens are updated in "batches". If you add a new tween during an
254
+ // update, then the new tween will be updated in the next batch.
255
+ // If you remove a tween during an update, it may or may not be updated.
256
+ // However, if the removed tween was added during the current batch,
257
+ // then it will not be updated.
258
+ while (tweenIds.length > 0) {
259
+ this._tweensAddedDuringUpdate = {};
260
+ for (var i = 0; i < tweenIds.length; i++) {
261
+ var tween = this._tweens[tweenIds[i]];
262
+ var autoStart = !preserve;
263
+ if (tween && tween.update(time, autoStart) === false && !preserve) {
264
+ delete this._tweens[tweenIds[i]];
265
+ }
266
+ }
267
+ tweenIds = Object.keys(this._tweensAddedDuringUpdate);
268
+ }
269
+ return true;
270
+ };
271
+ return Group;
274
272
  }());
275
273
 
276
274
  /**
277
275
  *
278
276
  */
279
277
  var Interpolation = {
280
- Linear: function (v, k) {
281
- var m = v.length - 1;
282
- var f = m * k;
283
- var i = Math.floor(f);
284
- var fn = Interpolation.Utils.Linear;
285
- if (k < 0) {
286
- return fn(v[0], v[1], f);
287
- }
288
- if (k > 1) {
289
- return fn(v[m], v[m - 1], m - f);
290
- }
291
- return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
292
- },
293
- Bezier: function (v, k) {
294
- var b = 0;
295
- var n = v.length - 1;
296
- var pw = Math.pow;
297
- var bn = Interpolation.Utils.Bernstein;
298
- for (var i = 0; i <= n; i++) {
299
- b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
300
- }
301
- return b;
302
- },
303
- CatmullRom: function (v, k) {
304
- var m = v.length - 1;
305
- var f = m * k;
306
- var i = Math.floor(f);
307
- var fn = Interpolation.Utils.CatmullRom;
308
- if (v[0] === v[m]) {
309
- if (k < 0) {
310
- i = Math.floor((f = m * (1 + k)));
311
- }
312
- return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
313
- }
314
- else {
315
- if (k < 0) {
316
- return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
317
- }
318
- if (k > 1) {
319
- return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
320
- }
321
- return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
322
- }
323
- },
324
- Utils: {
325
- Linear: function (p0, p1, t) {
326
- return (p1 - p0) * t + p0;
327
- },
328
- Bernstein: function (n, i) {
329
- var fc = Interpolation.Utils.Factorial;
330
- return fc(n) / fc(i) / fc(n - i);
331
- },
332
- Factorial: (function () {
333
- var a = [1];
334
- return function (n) {
335
- var s = 1;
336
- if (a[n]) {
337
- return a[n];
338
- }
339
- for (var i = n; i > 1; i--) {
340
- s *= i;
341
- }
342
- a[n] = s;
343
- return s;
344
- };
345
- })(),
346
- CatmullRom: function (p0, p1, p2, p3, t) {
347
- var v0 = (p2 - p0) * 0.5;
348
- var v1 = (p3 - p1) * 0.5;
349
- var t2 = t * t;
350
- var t3 = t * t2;
351
- return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
352
- },
353
- },
278
+ Linear: function (v, k) {
279
+ var m = v.length - 1;
280
+ var f = m * k;
281
+ var i = Math.floor(f);
282
+ var fn = Interpolation.Utils.Linear;
283
+ if (k < 0) {
284
+ return fn(v[0], v[1], f);
285
+ }
286
+ if (k > 1) {
287
+ return fn(v[m], v[m - 1], m - f);
288
+ }
289
+ return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
290
+ },
291
+ Bezier: function (v, k) {
292
+ var b = 0;
293
+ var n = v.length - 1;
294
+ var pw = Math.pow;
295
+ var bn = Interpolation.Utils.Bernstein;
296
+ for (var i = 0; i <= n; i++) {
297
+ b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
298
+ }
299
+ return b;
300
+ },
301
+ CatmullRom: function (v, k) {
302
+ var m = v.length - 1;
303
+ var f = m * k;
304
+ var i = Math.floor(f);
305
+ var fn = Interpolation.Utils.CatmullRom;
306
+ if (v[0] === v[m]) {
307
+ if (k < 0) {
308
+ i = Math.floor((f = m * (1 + k)));
309
+ }
310
+ return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
311
+ }
312
+ else {
313
+ if (k < 0) {
314
+ return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
315
+ }
316
+ if (k > 1) {
317
+ return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
318
+ }
319
+ return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
320
+ }
321
+ },
322
+ Utils: {
323
+ Linear: function (p0, p1, t) {
324
+ return (p1 - p0) * t + p0;
325
+ },
326
+ Bernstein: function (n, i) {
327
+ var fc = Interpolation.Utils.Factorial;
328
+ return fc(n) / fc(i) / fc(n - i);
329
+ },
330
+ Factorial: (function () {
331
+ var a = [1];
332
+ return function (n) {
333
+ var s = 1;
334
+ if (a[n]) {
335
+ return a[n];
336
+ }
337
+ for (var i = n; i > 1; i--) {
338
+ s *= i;
339
+ }
340
+ a[n] = s;
341
+ return s;
342
+ };
343
+ })(),
344
+ CatmullRom: function (p0, p1, p2, p3, t) {
345
+ var v0 = (p2 - p0) * 0.5;
346
+ var v1 = (p3 - p1) * 0.5;
347
+ var t2 = t * t;
348
+ var t3 = t * t2;
349
+ return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
350
+ },
351
+ },
354
352
  };
355
353
 
356
354
  /**
357
355
  * Utils
358
356
  */
359
357
  var Sequence = /** @class */ (function () {
360
- function Sequence() {
361
- }
362
- Sequence.nextId = function () {
363
- return Sequence._nextId++;
364
- };
365
- Sequence._nextId = 0;
366
- return Sequence;
358
+ function Sequence() {
359
+ }
360
+ Sequence.nextId = function () {
361
+ return Sequence._nextId++;
362
+ };
363
+ Sequence._nextId = 0;
364
+ return Sequence;
367
365
  }());
368
366
 
369
367
  var mainGroup = new Group();
@@ -377,386 +375,444 @@ var mainGroup = new Group();
377
375
  * Thank you all, you're awesome!
378
376
  */
379
377
  var Tween = /** @class */ (function () {
380
- function Tween(_object, _group) {
381
- if (_group === void 0) { _group = mainGroup; }
382
- this._object = _object;
383
- this._group = _group;
384
- this._isPaused = false;
385
- this._pauseStart = 0;
386
- this._valuesStart = {};
387
- this._valuesEnd = {};
388
- this._valuesStartRepeat = {};
389
- this._duration = 1000;
390
- this._initialRepeat = 0;
391
- this._repeat = 0;
392
- this._yoyo = false;
393
- this._isPlaying = false;
394
- this._reversed = false;
395
- this._delayTime = 0;
396
- this._startTime = 0;
397
- this._easingFunction = Easing.Linear.None;
398
- this._interpolationFunction = Interpolation.Linear;
399
- this._chainedTweens = [];
400
- this._onStartCallbackFired = false;
401
- this._id = Sequence.nextId();
402
- this._isChainStopped = false;
403
- this._goToEnd = false;
404
- }
405
- Tween.prototype.getId = function () {
406
- return this._id;
407
- };
408
- Tween.prototype.isPlaying = function () {
409
- return this._isPlaying;
410
- };
411
- Tween.prototype.isPaused = function () {
412
- return this._isPaused;
413
- };
414
- Tween.prototype.to = function (properties, duration) {
415
- // TODO? restore this, then update the 07_dynamic_to example to set fox
416
- // tween's to on each update. That way the behavior is opt-in (there's
417
- // currently no opt-out).
418
- // for (const prop in properties) this._valuesEnd[prop] = properties[prop]
419
- this._valuesEnd = Object.create(properties);
420
- if (duration !== undefined) {
421
- this._duration = duration;
422
- }
423
- return this;
424
- };
425
- Tween.prototype.duration = function (d) {
426
- this._duration = d;
427
- return this;
428
- };
429
- Tween.prototype.start = function (time) {
430
- if (this._isPlaying) {
431
- return this;
432
- }
433
- // eslint-disable-next-line
434
- this._group && this._group.add(this);
435
- this._repeat = this._initialRepeat;
436
- if (this._reversed) {
437
- // If we were reversed (f.e. using the yoyo feature) then we need to
438
- // flip the tween direction back to forward.
439
- this._reversed = false;
440
- for (var property in this._valuesStartRepeat) {
441
- this._swapEndStartRepeatValues(property);
442
- this._valuesStart[property] = this._valuesStartRepeat[property];
443
- }
444
- }
445
- this._isPlaying = true;
446
- this._isPaused = false;
447
- this._onStartCallbackFired = false;
448
- this._isChainStopped = false;
449
- this._startTime = time !== undefined ? (typeof time === 'string' ? now$1() + parseFloat(time) : time) : now$1();
450
- this._startTime += this._delayTime;
451
- this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat);
452
- return this;
453
- };
454
- Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat) {
455
- for (var property in _valuesEnd) {
456
- var startValue = _object[property];
457
- var startValueIsArray = Array.isArray(startValue);
458
- var propType = startValueIsArray ? 'array' : typeof startValue;
459
- var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
460
- // If `to()` specifies a property that doesn't exist in the source object,
461
- // we should not set that property in the object
462
- if (propType === 'undefined' || propType === 'function') {
463
- continue;
464
- }
465
- // Check if an Array was provided as property value
466
- if (isInterpolationList) {
467
- var endValues = _valuesEnd[property];
468
- if (endValues.length === 0) {
469
- continue;
470
- }
471
- // handle an array of relative values
472
- endValues = endValues.map(this._handleRelativeValue.bind(this, startValue));
473
- // Create a local copy of the Array with the start value at the front
474
- _valuesEnd[property] = [startValue].concat(endValues);
475
- }
476
- // handle the deepness of the values
477
- if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
478
- _valuesStart[property] = startValueIsArray ? [] : {};
479
- // eslint-disable-next-line
480
- for (var prop in startValue) {
481
- // eslint-disable-next-line
482
- // @ts-ignore FIXME?
483
- _valuesStart[property][prop] = startValue[prop];
484
- }
485
- _valuesStartRepeat[property] = startValueIsArray ? [] : {}; // TODO? repeat nested values? And yoyo? And array values?
486
- // eslint-disable-next-line
487
- // @ts-ignore FIXME?
488
- this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]);
489
- }
490
- else {
491
- // Save the starting value, but only once.
492
- if (typeof _valuesStart[property] === 'undefined') {
493
- _valuesStart[property] = startValue;
494
- }
495
- if (!startValueIsArray) {
496
- // eslint-disable-next-line
497
- // @ts-ignore FIXME?
498
- _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
499
- }
500
- if (isInterpolationList) {
501
- // eslint-disable-next-line
502
- // @ts-ignore FIXME?
503
- _valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();
504
- }
505
- else {
506
- _valuesStartRepeat[property] = _valuesStart[property] || 0;
507
- }
508
- }
509
- }
510
- };
511
- Tween.prototype.stop = function () {
512
- if (!this._isChainStopped) {
513
- this._isChainStopped = true;
514
- this.stopChainedTweens();
515
- }
516
- if (!this._isPlaying) {
517
- return this;
518
- }
519
- // eslint-disable-next-line
520
- this._group && this._group.remove(this);
521
- this._isPlaying = false;
522
- this._isPaused = false;
523
- if (this._onStopCallback) {
524
- this._onStopCallback(this._object);
525
- }
526
- return this;
527
- };
528
- Tween.prototype.end = function () {
529
- this._goToEnd = true;
530
- this.update(Infinity);
531
- return this;
532
- };
533
- Tween.prototype.pause = function (time) {
534
- if (time === void 0) { time = now$1(); }
535
- if (this._isPaused || !this._isPlaying) {
536
- return this;
537
- }
538
- this._isPaused = true;
539
- this._pauseStart = time;
540
- // eslint-disable-next-line
541
- this._group && this._group.remove(this);
542
- return this;
543
- };
544
- Tween.prototype.resume = function (time) {
545
- if (time === void 0) { time = now$1(); }
546
- if (!this._isPaused || !this._isPlaying) {
547
- return this;
548
- }
549
- this._isPaused = false;
550
- this._startTime += time - this._pauseStart;
551
- this._pauseStart = 0;
552
- // eslint-disable-next-line
553
- this._group && this._group.add(this);
554
- return this;
555
- };
556
- Tween.prototype.stopChainedTweens = function () {
557
- for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
558
- this._chainedTweens[i].stop();
559
- }
560
- return this;
561
- };
562
- Tween.prototype.group = function (group) {
563
- this._group = group;
564
- return this;
565
- };
566
- Tween.prototype.delay = function (amount) {
567
- this._delayTime = amount;
568
- return this;
569
- };
570
- Tween.prototype.repeat = function (times) {
571
- this._initialRepeat = times;
572
- this._repeat = times;
573
- return this;
574
- };
575
- Tween.prototype.repeatDelay = function (amount) {
576
- this._repeatDelayTime = amount;
577
- return this;
578
- };
579
- Tween.prototype.yoyo = function (yoyo) {
580
- this._yoyo = yoyo;
581
- return this;
582
- };
583
- Tween.prototype.easing = function (easingFunction) {
584
- this._easingFunction = easingFunction;
585
- return this;
586
- };
587
- Tween.prototype.interpolation = function (interpolationFunction) {
588
- this._interpolationFunction = interpolationFunction;
589
- return this;
590
- };
591
- Tween.prototype.chain = function () {
592
- var tweens = [];
593
- for (var _i = 0; _i < arguments.length; _i++) {
594
- tweens[_i] = arguments[_i];
595
- }
596
- this._chainedTweens = tweens;
597
- return this;
598
- };
599
- Tween.prototype.onStart = function (callback) {
600
- this._onStartCallback = callback;
601
- return this;
602
- };
603
- Tween.prototype.onUpdate = function (callback) {
604
- this._onUpdateCallback = callback;
605
- return this;
606
- };
607
- Tween.prototype.onRepeat = function (callback) {
608
- this._onRepeatCallback = callback;
609
- return this;
610
- };
611
- Tween.prototype.onComplete = function (callback) {
612
- this._onCompleteCallback = callback;
613
- return this;
614
- };
615
- Tween.prototype.onStop = function (callback) {
616
- this._onStopCallback = callback;
617
- return this;
618
- };
619
- /**
620
- * @returns true if the tween is still playing after the update, false
621
- * otherwise (calling update on a paused tween still returns true because
622
- * it is still playing, just paused).
623
- */
624
- Tween.prototype.update = function (time, autoStart) {
625
- if (time === void 0) { time = now$1(); }
626
- if (autoStart === void 0) { autoStart = true; }
627
- if (this._isPaused)
628
- return true;
629
- var property;
630
- var elapsed;
631
- var endTime = this._startTime + this._duration;
632
- if (!this._goToEnd && !this._isPlaying) {
633
- if (time > endTime)
634
- return false;
635
- if (autoStart)
636
- this.start(time);
637
- }
638
- this._goToEnd = false;
639
- if (time < this._startTime) {
640
- return true;
641
- }
642
- if (this._onStartCallbackFired === false) {
643
- if (this._onStartCallback) {
644
- this._onStartCallback(this._object);
645
- }
646
- this._onStartCallbackFired = true;
647
- }
648
- elapsed = (time - this._startTime) / this._duration;
649
- elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
650
- var value = this._easingFunction(elapsed);
651
- // properties transformations
652
- this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
653
- if (this._onUpdateCallback) {
654
- this._onUpdateCallback(this._object, elapsed);
655
- }
656
- if (elapsed === 1) {
657
- if (this._repeat > 0) {
658
- if (isFinite(this._repeat)) {
659
- this._repeat--;
660
- }
661
- // Reassign starting values, restart by making startTime = now
662
- for (property in this._valuesStartRepeat) {
663
- if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
664
- this._valuesStartRepeat[property] =
665
- // eslint-disable-next-line
666
- // @ts-ignore FIXME?
667
- this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
668
- }
669
- if (this._yoyo) {
670
- this._swapEndStartRepeatValues(property);
671
- }
672
- this._valuesStart[property] = this._valuesStartRepeat[property];
673
- }
674
- if (this._yoyo) {
675
- this._reversed = !this._reversed;
676
- }
677
- if (this._repeatDelayTime !== undefined) {
678
- this._startTime = time + this._repeatDelayTime;
679
- }
680
- else {
681
- this._startTime = time + this._delayTime;
682
- }
683
- if (this._onRepeatCallback) {
684
- this._onRepeatCallback(this._object);
685
- }
686
- return true;
687
- }
688
- else {
689
- if (this._onCompleteCallback) {
690
- this._onCompleteCallback(this._object);
691
- }
692
- for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
693
- // Make the chained tweens start exactly at the time they should,
694
- // even if the `update()` method was called way past the duration of the tween
695
- this._chainedTweens[i].start(this._startTime + this._duration);
696
- }
697
- this._isPlaying = false;
698
- return false;
699
- }
700
- }
701
- return true;
702
- };
703
- Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
704
- for (var property in _valuesEnd) {
705
- // Don't update properties that do not exist in the source object
706
- if (_valuesStart[property] === undefined) {
707
- continue;
708
- }
709
- var start = _valuesStart[property] || 0;
710
- var end = _valuesEnd[property];
711
- var startIsArray = Array.isArray(_object[property]);
712
- var endIsArray = Array.isArray(end);
713
- var isInterpolationList = !startIsArray && endIsArray;
714
- if (isInterpolationList) {
715
- _object[property] = this._interpolationFunction(end, value);
716
- }
717
- else if (typeof end === 'object' && end) {
718
- // eslint-disable-next-line
719
- // @ts-ignore FIXME?
720
- this._updateProperties(_object[property], start, end, value);
721
- }
722
- else {
723
- // Parses relative end values with start as base (e.g.: +10, -3)
724
- end = this._handleRelativeValue(start, end);
725
- // Protect against non numeric properties.
726
- if (typeof end === 'number') {
727
- // eslint-disable-next-line
728
- // @ts-ignore FIXME?
729
- _object[property] = start + (end - start) * value;
730
- }
731
- }
732
- }
733
- };
734
- Tween.prototype._handleRelativeValue = function (start, end) {
735
- if (typeof end !== 'string') {
736
- return end;
737
- }
738
- if (end.charAt(0) === '+' || end.charAt(0) === '-') {
739
- return start + parseFloat(end);
740
- }
741
- else {
742
- return parseFloat(end);
743
- }
744
- };
745
- Tween.prototype._swapEndStartRepeatValues = function (property) {
746
- var tmp = this._valuesStartRepeat[property];
747
- var endValue = this._valuesEnd[property];
748
- if (typeof endValue === 'string') {
749
- this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
750
- }
751
- else {
752
- this._valuesStartRepeat[property] = this._valuesEnd[property];
753
- }
754
- this._valuesEnd[property] = tmp;
755
- };
756
- return Tween;
378
+ function Tween(_object, _group) {
379
+ if (_group === void 0) { _group = mainGroup; }
380
+ this._object = _object;
381
+ this._group = _group;
382
+ this._isPaused = false;
383
+ this._pauseStart = 0;
384
+ this._valuesStart = {};
385
+ this._valuesEnd = {};
386
+ this._valuesStartRepeat = {};
387
+ this._duration = 1000;
388
+ this._isDynamic = false;
389
+ this._initialRepeat = 0;
390
+ this._repeat = 0;
391
+ this._yoyo = false;
392
+ this._isPlaying = false;
393
+ this._reversed = false;
394
+ this._delayTime = 0;
395
+ this._startTime = 0;
396
+ this._easingFunction = Easing.Linear.None;
397
+ this._interpolationFunction = Interpolation.Linear;
398
+ // eslint-disable-next-line
399
+ this._chainedTweens = [];
400
+ this._onStartCallbackFired = false;
401
+ this._onEveryStartCallbackFired = false;
402
+ this._id = Sequence.nextId();
403
+ this._isChainStopped = false;
404
+ this._propertiesAreSetUp = false;
405
+ this._goToEnd = false;
406
+ }
407
+ Tween.prototype.getId = function () {
408
+ return this._id;
409
+ };
410
+ Tween.prototype.isPlaying = function () {
411
+ return this._isPlaying;
412
+ };
413
+ Tween.prototype.isPaused = function () {
414
+ return this._isPaused;
415
+ };
416
+ Tween.prototype.to = function (target, duration) {
417
+ if (duration === void 0) { duration = 1000; }
418
+ if (this._isPlaying)
419
+ throw new Error('Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.');
420
+ this._valuesEnd = target;
421
+ this._propertiesAreSetUp = false;
422
+ this._duration = duration;
423
+ return this;
424
+ };
425
+ Tween.prototype.duration = function (duration) {
426
+ if (duration === void 0) { duration = 1000; }
427
+ this._duration = duration;
428
+ return this;
429
+ };
430
+ Tween.prototype.dynamic = function (dynamic) {
431
+ if (dynamic === void 0) { dynamic = false; }
432
+ this._isDynamic = dynamic;
433
+ return this;
434
+ };
435
+ Tween.prototype.start = function (time, overrideStartingValues) {
436
+ if (time === void 0) { time = now(); }
437
+ if (overrideStartingValues === void 0) { overrideStartingValues = false; }
438
+ if (this._isPlaying) {
439
+ return this;
440
+ }
441
+ // eslint-disable-next-line
442
+ this._group && this._group.add(this);
443
+ this._repeat = this._initialRepeat;
444
+ if (this._reversed) {
445
+ // If we were reversed (f.e. using the yoyo feature) then we need to
446
+ // flip the tween direction back to forward.
447
+ this._reversed = false;
448
+ for (var property in this._valuesStartRepeat) {
449
+ this._swapEndStartRepeatValues(property);
450
+ this._valuesStart[property] = this._valuesStartRepeat[property];
451
+ }
452
+ }
453
+ this._isPlaying = true;
454
+ this._isPaused = false;
455
+ this._onStartCallbackFired = false;
456
+ this._onEveryStartCallbackFired = false;
457
+ this._isChainStopped = false;
458
+ this._startTime = time;
459
+ this._startTime += this._delayTime;
460
+ if (!this._propertiesAreSetUp || overrideStartingValues) {
461
+ this._propertiesAreSetUp = true;
462
+ // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
463
+ if (!this._isDynamic) {
464
+ var tmp = {};
465
+ for (var prop in this._valuesEnd)
466
+ tmp[prop] = this._valuesEnd[prop];
467
+ this._valuesEnd = tmp;
468
+ }
469
+ this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
470
+ }
471
+ return this;
472
+ };
473
+ Tween.prototype.startFromCurrentValues = function (time) {
474
+ return this.start(time, true);
475
+ };
476
+ Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
477
+ for (var property in _valuesEnd) {
478
+ var startValue = _object[property];
479
+ var startValueIsArray = Array.isArray(startValue);
480
+ var propType = startValueIsArray ? 'array' : typeof startValue;
481
+ var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
482
+ // If `to()` specifies a property that doesn't exist in the source object,
483
+ // we should not set that property in the object
484
+ if (propType === 'undefined' || propType === 'function') {
485
+ continue;
486
+ }
487
+ // Check if an Array was provided as property value
488
+ if (isInterpolationList) {
489
+ var endValues = _valuesEnd[property];
490
+ if (endValues.length === 0) {
491
+ continue;
492
+ }
493
+ // Handle an array of relative values.
494
+ // Creates a local copy of the Array with the start value at the front
495
+ var temp = [startValue];
496
+ for (var i = 0, l = endValues.length; i < l; i += 1) {
497
+ var value = this._handleRelativeValue(startValue, endValues[i]);
498
+ if (isNaN(value)) {
499
+ isInterpolationList = false;
500
+ console.warn('Found invalid interpolation list. Skipping.');
501
+ break;
502
+ }
503
+ temp.push(value);
504
+ }
505
+ if (isInterpolationList) {
506
+ // if (_valuesStart[property] === undefined) { // handle end values only the first time. NOT NEEDED? setupProperties is now guarded by _propertiesAreSetUp.
507
+ _valuesEnd[property] = temp;
508
+ // }
509
+ }
510
+ }
511
+ // handle the deepness of the values
512
+ if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
513
+ _valuesStart[property] = startValueIsArray ? [] : {};
514
+ var nestedObject = startValue;
515
+ for (var prop in nestedObject) {
516
+ _valuesStart[property][prop] = nestedObject[prop];
517
+ }
518
+ // TODO? repeat nested values? And yoyo? And array values?
519
+ _valuesStartRepeat[property] = startValueIsArray ? [] : {};
520
+ var endValues = _valuesEnd[property];
521
+ // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
522
+ if (!this._isDynamic) {
523
+ var tmp = {};
524
+ for (var prop in endValues)
525
+ tmp[prop] = endValues[prop];
526
+ _valuesEnd[property] = endValues = tmp;
527
+ }
528
+ this._setupProperties(nestedObject, _valuesStart[property], endValues, _valuesStartRepeat[property], overrideStartingValues);
529
+ }
530
+ else {
531
+ // Save the starting value, but only once unless override is requested.
532
+ if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
533
+ _valuesStart[property] = startValue;
534
+ }
535
+ if (!startValueIsArray) {
536
+ // eslint-disable-next-line
537
+ // @ts-ignore FIXME?
538
+ _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
539
+ }
540
+ if (isInterpolationList) {
541
+ // eslint-disable-next-line
542
+ // @ts-ignore FIXME?
543
+ _valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();
544
+ }
545
+ else {
546
+ _valuesStartRepeat[property] = _valuesStart[property] || 0;
547
+ }
548
+ }
549
+ }
550
+ };
551
+ Tween.prototype.stop = function () {
552
+ if (!this._isChainStopped) {
553
+ this._isChainStopped = true;
554
+ this.stopChainedTweens();
555
+ }
556
+ if (!this._isPlaying) {
557
+ return this;
558
+ }
559
+ // eslint-disable-next-line
560
+ this._group && this._group.remove(this);
561
+ this._isPlaying = false;
562
+ this._isPaused = false;
563
+ if (this._onStopCallback) {
564
+ this._onStopCallback(this._object);
565
+ }
566
+ return this;
567
+ };
568
+ Tween.prototype.end = function () {
569
+ this._goToEnd = true;
570
+ this.update(Infinity);
571
+ return this;
572
+ };
573
+ Tween.prototype.pause = function (time) {
574
+ if (time === void 0) { time = now(); }
575
+ if (this._isPaused || !this._isPlaying) {
576
+ return this;
577
+ }
578
+ this._isPaused = true;
579
+ this._pauseStart = time;
580
+ // eslint-disable-next-line
581
+ this._group && this._group.remove(this);
582
+ return this;
583
+ };
584
+ Tween.prototype.resume = function (time) {
585
+ if (time === void 0) { time = now(); }
586
+ if (!this._isPaused || !this._isPlaying) {
587
+ return this;
588
+ }
589
+ this._isPaused = false;
590
+ this._startTime += time - this._pauseStart;
591
+ this._pauseStart = 0;
592
+ // eslint-disable-next-line
593
+ this._group && this._group.add(this);
594
+ return this;
595
+ };
596
+ Tween.prototype.stopChainedTweens = function () {
597
+ for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
598
+ this._chainedTweens[i].stop();
599
+ }
600
+ return this;
601
+ };
602
+ Tween.prototype.group = function (group) {
603
+ if (group === void 0) { group = mainGroup; }
604
+ this._group = group;
605
+ return this;
606
+ };
607
+ Tween.prototype.delay = function (amount) {
608
+ if (amount === void 0) { amount = 0; }
609
+ this._delayTime = amount;
610
+ return this;
611
+ };
612
+ Tween.prototype.repeat = function (times) {
613
+ if (times === void 0) { times = 0; }
614
+ this._initialRepeat = times;
615
+ this._repeat = times;
616
+ return this;
617
+ };
618
+ Tween.prototype.repeatDelay = function (amount) {
619
+ this._repeatDelayTime = amount;
620
+ return this;
621
+ };
622
+ Tween.prototype.yoyo = function (yoyo) {
623
+ if (yoyo === void 0) { yoyo = false; }
624
+ this._yoyo = yoyo;
625
+ return this;
626
+ };
627
+ Tween.prototype.easing = function (easingFunction) {
628
+ if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }
629
+ this._easingFunction = easingFunction;
630
+ return this;
631
+ };
632
+ Tween.prototype.interpolation = function (interpolationFunction) {
633
+ if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }
634
+ this._interpolationFunction = interpolationFunction;
635
+ return this;
636
+ };
637
+ // eslint-disable-next-line
638
+ Tween.prototype.chain = function () {
639
+ var tweens = [];
640
+ for (var _i = 0; _i < arguments.length; _i++) {
641
+ tweens[_i] = arguments[_i];
642
+ }
643
+ this._chainedTweens = tweens;
644
+ return this;
645
+ };
646
+ Tween.prototype.onStart = function (callback) {
647
+ this._onStartCallback = callback;
648
+ return this;
649
+ };
650
+ Tween.prototype.onEveryStart = function (callback) {
651
+ this._onEveryStartCallback = callback;
652
+ return this;
653
+ };
654
+ Tween.prototype.onUpdate = function (callback) {
655
+ this._onUpdateCallback = callback;
656
+ return this;
657
+ };
658
+ Tween.prototype.onRepeat = function (callback) {
659
+ this._onRepeatCallback = callback;
660
+ return this;
661
+ };
662
+ Tween.prototype.onComplete = function (callback) {
663
+ this._onCompleteCallback = callback;
664
+ return this;
665
+ };
666
+ Tween.prototype.onStop = function (callback) {
667
+ this._onStopCallback = callback;
668
+ return this;
669
+ };
670
+ /**
671
+ * @returns true if the tween is still playing after the update, false
672
+ * otherwise (calling update on a paused tween still returns true because
673
+ * it is still playing, just paused).
674
+ */
675
+ Tween.prototype.update = function (time, autoStart) {
676
+ if (time === void 0) { time = now(); }
677
+ if (autoStart === void 0) { autoStart = true; }
678
+ if (this._isPaused)
679
+ return true;
680
+ var property;
681
+ var elapsed;
682
+ var endTime = this._startTime + this._duration;
683
+ if (!this._goToEnd && !this._isPlaying) {
684
+ if (time > endTime)
685
+ return false;
686
+ if (autoStart)
687
+ this.start(time, true);
688
+ }
689
+ this._goToEnd = false;
690
+ if (time < this._startTime) {
691
+ return true;
692
+ }
693
+ if (this._onStartCallbackFired === false) {
694
+ if (this._onStartCallback) {
695
+ this._onStartCallback(this._object);
696
+ }
697
+ this._onStartCallbackFired = true;
698
+ }
699
+ if (this._onEveryStartCallbackFired === false) {
700
+ if (this._onEveryStartCallback) {
701
+ this._onEveryStartCallback(this._object);
702
+ }
703
+ this._onEveryStartCallbackFired = true;
704
+ }
705
+ elapsed = (time - this._startTime) / this._duration;
706
+ elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
707
+ var value = this._easingFunction(elapsed);
708
+ // properties transformations
709
+ this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
710
+ if (this._onUpdateCallback) {
711
+ this._onUpdateCallback(this._object, elapsed);
712
+ }
713
+ if (elapsed === 1) {
714
+ if (this._repeat > 0) {
715
+ if (isFinite(this._repeat)) {
716
+ this._repeat--;
717
+ }
718
+ // Reassign starting values, restart by making startTime = now
719
+ for (property in this._valuesStartRepeat) {
720
+ if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
721
+ this._valuesStartRepeat[property] =
722
+ // eslint-disable-next-line
723
+ // @ts-ignore FIXME?
724
+ this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
725
+ }
726
+ if (this._yoyo) {
727
+ this._swapEndStartRepeatValues(property);
728
+ }
729
+ this._valuesStart[property] = this._valuesStartRepeat[property];
730
+ }
731
+ if (this._yoyo) {
732
+ this._reversed = !this._reversed;
733
+ }
734
+ if (this._repeatDelayTime !== undefined) {
735
+ this._startTime = time + this._repeatDelayTime;
736
+ }
737
+ else {
738
+ this._startTime = time + this._delayTime;
739
+ }
740
+ if (this._onRepeatCallback) {
741
+ this._onRepeatCallback(this._object);
742
+ }
743
+ this._onEveryStartCallbackFired = false;
744
+ return true;
745
+ }
746
+ else {
747
+ if (this._onCompleteCallback) {
748
+ this._onCompleteCallback(this._object);
749
+ }
750
+ for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
751
+ // Make the chained tweens start exactly at the time they should,
752
+ // even if the `update()` method was called way past the duration of the tween
753
+ this._chainedTweens[i].start(this._startTime + this._duration, false);
754
+ }
755
+ this._isPlaying = false;
756
+ return false;
757
+ }
758
+ }
759
+ return true;
760
+ };
761
+ Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
762
+ for (var property in _valuesEnd) {
763
+ // Don't update properties that do not exist in the source object
764
+ if (_valuesStart[property] === undefined) {
765
+ continue;
766
+ }
767
+ var start = _valuesStart[property] || 0;
768
+ var end = _valuesEnd[property];
769
+ var startIsArray = Array.isArray(_object[property]);
770
+ var endIsArray = Array.isArray(end);
771
+ var isInterpolationList = !startIsArray && endIsArray;
772
+ if (isInterpolationList) {
773
+ _object[property] = this._interpolationFunction(end, value);
774
+ }
775
+ else if (typeof end === 'object' && end) {
776
+ // eslint-disable-next-line
777
+ // @ts-ignore FIXME?
778
+ this._updateProperties(_object[property], start, end, value);
779
+ }
780
+ else {
781
+ // Parses relative end values with start as base (e.g.: +10, -3)
782
+ end = this._handleRelativeValue(start, end);
783
+ // Protect against non numeric properties.
784
+ if (typeof end === 'number') {
785
+ // eslint-disable-next-line
786
+ // @ts-ignore FIXME?
787
+ _object[property] = start + (end - start) * value;
788
+ }
789
+ }
790
+ }
791
+ };
792
+ Tween.prototype._handleRelativeValue = function (start, end) {
793
+ if (typeof end !== 'string') {
794
+ return end;
795
+ }
796
+ if (end.charAt(0) === '+' || end.charAt(0) === '-') {
797
+ return start + parseFloat(end);
798
+ }
799
+ return parseFloat(end);
800
+ };
801
+ Tween.prototype._swapEndStartRepeatValues = function (property) {
802
+ var tmp = this._valuesStartRepeat[property];
803
+ var endValue = this._valuesEnd[property];
804
+ if (typeof endValue === 'string') {
805
+ this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
806
+ }
807
+ else {
808
+ this._valuesStartRepeat[property] = this._valuesEnd[property];
809
+ }
810
+ this._valuesEnd[property] = tmp;
811
+ };
812
+ return Tween;
757
813
  }());
758
814
 
759
- var VERSION = '18.6.4';
815
+ var VERSION = '21.0.0';
760
816
 
761
817
  /**
762
818
  * Tween.js - Licensed under the MIT license
@@ -784,20 +840,19 @@ var add = TWEEN.add.bind(TWEEN);
784
840
  var remove = TWEEN.remove.bind(TWEEN);
785
841
  var update = TWEEN.update.bind(TWEEN);
786
842
  var exports = {
787
- Easing: Easing,
788
- Group: Group,
789
- Interpolation: Interpolation,
790
- now: now$1,
791
- Sequence: Sequence,
792
- nextId: nextId,
793
- Tween: Tween,
794
- VERSION: VERSION,
795
- getAll: getAll,
796
- removeAll: removeAll,
797
- add: add,
798
- remove: remove,
799
- update: update,
843
+ Easing: Easing,
844
+ Group: Group,
845
+ Interpolation: Interpolation,
846
+ now: now,
847
+ Sequence: Sequence,
848
+ nextId: nextId,
849
+ Tween: Tween,
850
+ VERSION: VERSION,
851
+ getAll: getAll,
852
+ removeAll: removeAll,
853
+ add: add,
854
+ remove: remove,
855
+ update: update,
800
856
  };
801
857
 
802
- export default exports;
803
- export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, getAll, nextId, now$1 as now, remove, removeAll, update };
858
+ export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };