animejs 4.4.0 → 4.5.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 (165) hide show
  1. package/README.md +4 -5
  2. package/dist/bundles/anime.esm.js +491 -272
  3. package/dist/bundles/anime.esm.min.js +2 -2
  4. package/dist/bundles/anime.umd.js +491 -272
  5. package/dist/bundles/anime.umd.min.js +2 -2
  6. package/dist/modules/adapters/index.cjs +14 -0
  7. package/dist/modules/adapters/index.d.ts +1 -0
  8. package/dist/modules/adapters/index.js +8 -0
  9. package/dist/modules/adapters/registry.cjs +149 -0
  10. package/dist/modules/adapters/registry.d.ts +65 -0
  11. package/dist/modules/adapters/registry.js +146 -0
  12. package/dist/modules/adapters/three/adapter.cjs +26 -0
  13. package/dist/modules/adapters/three/adapter.d.ts +15 -0
  14. package/dist/modules/adapters/three/adapter.js +24 -0
  15. package/dist/modules/adapters/three/helpers.cjs +297 -0
  16. package/dist/modules/adapters/three/helpers.d.ts +89 -0
  17. package/dist/modules/adapters/three/helpers.js +280 -0
  18. package/dist/modules/adapters/three/index.cjs +20 -0
  19. package/dist/modules/adapters/three/index.d.ts +2 -0
  20. package/dist/modules/adapters/three/index.js +12 -0
  21. package/dist/modules/adapters/three/instance.cjs +368 -0
  22. package/dist/modules/adapters/three/instance.d.ts +133 -0
  23. package/dist/modules/adapters/three/instance.js +365 -0
  24. package/dist/modules/adapters/three/object3d.cjs +214 -0
  25. package/dist/modules/adapters/three/object3d.d.ts +1 -0
  26. package/dist/modules/adapters/three/object3d.js +212 -0
  27. package/dist/modules/adapters/three/resolvers.cjs +105 -0
  28. package/dist/modules/adapters/three/resolvers.d.ts +1 -0
  29. package/dist/modules/adapters/three/resolvers.js +103 -0
  30. package/dist/modules/adapters/three/uniform.cjs +41 -0
  31. package/dist/modules/adapters/three/uniform.d.ts +1 -0
  32. package/dist/modules/adapters/three/uniform.js +39 -0
  33. package/dist/modules/animatable/animatable.cjs +2 -1
  34. package/dist/modules/animatable/animatable.d.ts +2 -1
  35. package/dist/modules/animatable/animatable.js +2 -1
  36. package/dist/modules/animatable/index.cjs +1 -1
  37. package/dist/modules/animatable/index.js +1 -1
  38. package/dist/modules/animation/additive.cjs +1 -1
  39. package/dist/modules/animation/additive.js +1 -1
  40. package/dist/modules/animation/animation.cjs +43 -16
  41. package/dist/modules/animation/animation.d.ts +5 -0
  42. package/dist/modules/animation/animation.js +45 -18
  43. package/dist/modules/animation/composition.cjs +38 -35
  44. package/dist/modules/animation/composition.js +38 -35
  45. package/dist/modules/animation/index.cjs +1 -1
  46. package/dist/modules/animation/index.js +1 -1
  47. package/dist/modules/core/clock.cjs +11 -15
  48. package/dist/modules/core/clock.d.ts +0 -2
  49. package/dist/modules/core/clock.js +11 -15
  50. package/dist/modules/core/colors.cjs +1 -1
  51. package/dist/modules/core/colors.js +1 -1
  52. package/dist/modules/core/consts.cjs +15 -1
  53. package/dist/modules/core/consts.d.ts +2 -0
  54. package/dist/modules/core/consts.js +14 -2
  55. package/dist/modules/core/globals.cjs +7 -4
  56. package/dist/modules/core/globals.d.ts +8 -2
  57. package/dist/modules/core/globals.js +8 -5
  58. package/dist/modules/core/helpers.cjs +2 -2
  59. package/dist/modules/core/helpers.js +3 -3
  60. package/dist/modules/core/render.cjs +93 -73
  61. package/dist/modules/core/render.js +96 -76
  62. package/dist/modules/core/styles.cjs +16 -2
  63. package/dist/modules/core/styles.js +16 -2
  64. package/dist/modules/core/targets.cjs +11 -13
  65. package/dist/modules/core/targets.js +11 -13
  66. package/dist/modules/core/transforms.cjs +1 -1
  67. package/dist/modules/core/transforms.js +1 -1
  68. package/dist/modules/core/units.cjs +1 -1
  69. package/dist/modules/core/units.js +1 -1
  70. package/dist/modules/core/values.cjs +73 -82
  71. package/dist/modules/core/values.d.ts +1 -2
  72. package/dist/modules/core/values.js +76 -84
  73. package/dist/modules/draggable/draggable.cjs +1 -1
  74. package/dist/modules/draggable/draggable.js +1 -1
  75. package/dist/modules/draggable/index.cjs +1 -1
  76. package/dist/modules/draggable/index.js +1 -1
  77. package/dist/modules/easings/cubic-bezier/index.cjs +1 -1
  78. package/dist/modules/easings/cubic-bezier/index.js +1 -1
  79. package/dist/modules/easings/eases/index.cjs +1 -1
  80. package/dist/modules/easings/eases/index.js +1 -1
  81. package/dist/modules/easings/eases/parser.cjs +3 -3
  82. package/dist/modules/easings/eases/parser.d.ts +4 -5
  83. package/dist/modules/easings/eases/parser.js +3 -3
  84. package/dist/modules/easings/index.cjs +1 -1
  85. package/dist/modules/easings/index.js +1 -1
  86. package/dist/modules/easings/irregular/index.cjs +1 -1
  87. package/dist/modules/easings/irregular/index.js +1 -1
  88. package/dist/modules/easings/linear/index.cjs +1 -1
  89. package/dist/modules/easings/linear/index.js +1 -1
  90. package/dist/modules/easings/none.cjs +1 -1
  91. package/dist/modules/easings/none.js +1 -1
  92. package/dist/modules/easings/spring/index.cjs +1 -1
  93. package/dist/modules/easings/spring/index.js +1 -1
  94. package/dist/modules/easings/steps/index.cjs +1 -1
  95. package/dist/modules/easings/steps/index.js +1 -1
  96. package/dist/modules/engine/engine.cjs +4 -2
  97. package/dist/modules/engine/engine.js +4 -2
  98. package/dist/modules/engine/index.cjs +1 -1
  99. package/dist/modules/engine/index.js +1 -1
  100. package/dist/modules/events/index.cjs +1 -1
  101. package/dist/modules/events/index.js +1 -1
  102. package/dist/modules/events/scroll.cjs +3 -1
  103. package/dist/modules/events/scroll.js +3 -1
  104. package/dist/modules/index.cjs +1 -1
  105. package/dist/modules/index.js +1 -1
  106. package/dist/modules/layout/index.cjs +1 -1
  107. package/dist/modules/layout/index.js +1 -1
  108. package/dist/modules/layout/layout.cjs +1 -1
  109. package/dist/modules/layout/layout.js +1 -1
  110. package/dist/modules/scope/index.cjs +1 -1
  111. package/dist/modules/scope/index.js +1 -1
  112. package/dist/modules/scope/scope.cjs +1 -1
  113. package/dist/modules/scope/scope.js +1 -1
  114. package/dist/modules/svg/drawable.cjs +1 -1
  115. package/dist/modules/svg/drawable.js +1 -1
  116. package/dist/modules/svg/helpers.cjs +1 -1
  117. package/dist/modules/svg/helpers.js +1 -1
  118. package/dist/modules/svg/index.cjs +1 -1
  119. package/dist/modules/svg/index.js +1 -1
  120. package/dist/modules/svg/morphto.cjs +1 -1
  121. package/dist/modules/svg/morphto.js +1 -1
  122. package/dist/modules/svg/motionpath.cjs +1 -1
  123. package/dist/modules/svg/motionpath.js +1 -1
  124. package/dist/modules/text/index.cjs +1 -1
  125. package/dist/modules/text/index.js +1 -1
  126. package/dist/modules/text/scramble.cjs +12 -2
  127. package/dist/modules/text/scramble.d.ts +9 -1
  128. package/dist/modules/text/scramble.js +12 -2
  129. package/dist/modules/text/split.cjs +2 -1
  130. package/dist/modules/text/split.js +2 -1
  131. package/dist/modules/timeline/index.cjs +1 -1
  132. package/dist/modules/timeline/index.js +1 -1
  133. package/dist/modules/timeline/position.cjs +1 -1
  134. package/dist/modules/timeline/position.js +1 -1
  135. package/dist/modules/timeline/timeline.cjs +14 -5
  136. package/dist/modules/timeline/timeline.d.ts +3 -3
  137. package/dist/modules/timeline/timeline.js +14 -5
  138. package/dist/modules/timer/index.cjs +1 -1
  139. package/dist/modules/timer/index.js +1 -1
  140. package/dist/modules/timer/timer.cjs +1 -1
  141. package/dist/modules/timer/timer.js +1 -1
  142. package/dist/modules/types/index.d.ts +36 -11
  143. package/dist/modules/utils/chainable.cjs +1 -1
  144. package/dist/modules/utils/chainable.js +1 -1
  145. package/dist/modules/utils/index.cjs +1 -1
  146. package/dist/modules/utils/index.js +1 -1
  147. package/dist/modules/utils/number.cjs +1 -1
  148. package/dist/modules/utils/number.js +1 -1
  149. package/dist/modules/utils/random.cjs +4 -3
  150. package/dist/modules/utils/random.d.ts +1 -1
  151. package/dist/modules/utils/random.js +4 -3
  152. package/dist/modules/utils/stagger.cjs +67 -13
  153. package/dist/modules/utils/stagger.js +69 -15
  154. package/dist/modules/utils/target.cjs +4 -1
  155. package/dist/modules/utils/target.js +4 -1
  156. package/dist/modules/utils/time.cjs +6 -5
  157. package/dist/modules/utils/time.d.ts +1 -1
  158. package/dist/modules/utils/time.js +6 -5
  159. package/dist/modules/waapi/composition.cjs +1 -1
  160. package/dist/modules/waapi/composition.js +1 -1
  161. package/dist/modules/waapi/index.cjs +1 -1
  162. package/dist/modules/waapi/index.js +1 -1
  163. package/dist/modules/waapi/waapi.cjs +1 -1
  164. package/dist/modules/waapi/waapi.js +1 -1
  165. package/package.json +38 -5
@@ -0,0 +1,365 @@
1
+ /**
2
+ * Anime.js - adapters - ESM
3
+ * @version v4.5.0
4
+ * @license MIT
5
+ * @copyright 2026 - Julian Garnier
6
+ */
7
+
8
+ import { SRGBColorSpace, Vector3, Euler, Matrix4, Quaternion, Color, BatchedMesh } from 'three';
9
+ import { radToDeg, degToRad } from '../../utils/number.js';
10
+ import { threeAdapter } from './adapter.js';
11
+ import { readColorHex, COLOR_NORM, applySkewOrigin, readScalar, PATH_DIRECT, writeScalar } from './helpers.js';
12
+
13
+ const hasSkewOrigin = (t) => !!(t._skewX || t._skewY || t._skewZ || t._originX || t._originY || t._originZ);
14
+
15
+ /**
16
+ * @import { Object3D, InstancedMesh } from 'three'
17
+ *
18
+ * @typedef {InstancedMesh | BatchedMesh} InstanceParent
19
+ */
20
+
21
+ const DIRTY_POS = 1;
22
+ const DIRTY_ROT = 2;
23
+ const DIRTY_SCALE = 4;
24
+ const DIRTY_SKEW = 8;
25
+
26
+ /** @type {WeakMap<InstanceParent, InstanceBinding>} */
27
+ const bindings = new WeakMap();
28
+
29
+ /**
30
+ * Per-mesh state for `InstancedMesh` / `BatchedMesh` animations. Holds the instance array, the dirty queue, and the chained `onBeforeRender` closure.
31
+ */
32
+ class InstanceBinding {
33
+
34
+ /** @param {InstanceParent} mesh */
35
+ constructor(mesh) {
36
+ this.mesh = mesh;
37
+ this.hasInstanceMatrix = 'instanceMatrix' in mesh;
38
+ /** @type {(Instance | null)[]} */
39
+ this.instances = [];
40
+ /** @type {Instance[]} */
41
+ this.dirtyList = [];
42
+ /** @type {Object3D['onBeforeRender'] | null} */
43
+ this.userOnBeforeRender = mesh.onBeforeRender || null;
44
+ this.chainedHandler = makeChainedHandler(this);
45
+ Object.defineProperty(mesh, 'onBeforeRender', {
46
+ configurable: true,
47
+ get: () => this.chainedHandler,
48
+ set: (fn) => { this.userOnBeforeRender = fn; },
49
+ });
50
+ }
51
+
52
+ flush() {
53
+ const list = this.dirtyList;
54
+ if (list.length === 0) return;
55
+ for (let i = 0, l = list.length; i < l; i++) list[i]._flush();
56
+ if (this.hasInstanceMatrix) /** @type {InstancedMesh} */(this.mesh).instanceMatrix.needsUpdate = true;
57
+ list.length = 0;
58
+ }
59
+
60
+ }
61
+
62
+ /**
63
+ * @param {InstanceBinding} binding
64
+ * @return {Object3D['onBeforeRender']}
65
+ */
66
+ function makeChainedHandler(binding) {
67
+ return function (renderer, scene, camera, geometry, material, group) {
68
+ binding.flush();
69
+ const u = binding.userOnBeforeRender;
70
+ if (u) u.call(binding.mesh, renderer, scene, camera, geometry, material, group);
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Per-instance adapter for `InstancedMesh` or `BatchedMesh`. Returned by `getInstances(mesh)`. Exposes the same flat properties as the mesh adapter, applied to a single instance id. Writes are coalesced and flushed before each render via `onBeforeRender`; call `commitChanges(mesh)` if you need to read `mesh.instanceMatrix` between a tick and a render.
76
+ *
77
+ * Caveats:
78
+ * - `opacity` writes the parent's shared material, every instance is affected.
79
+ * - `visible` is backed by `BatchedMesh.setVisibleAt`. On `InstancedMesh` it is a no-op, use `scale = 0` to hide an instance.
80
+ */
81
+ class Instance {
82
+
83
+ /**
84
+ * @param {InstanceBinding} binding
85
+ * @param {number} id
86
+ */
87
+ constructor(binding, id) {
88
+ this.isAnimejsInstanceProxy = true;
89
+ this.parent = binding.mesh;
90
+ this.id = id;
91
+ this._position = new Vector3();
92
+ this._rotation = new Euler(0, 0, 0, 'XYZ');
93
+ this._scale = new Vector3(1, 1, 1);
94
+ this._matrix = new Matrix4();
95
+ this._quat = new Quaternion();
96
+ // Pre-allocate _color so the hidden class stays stable, set color mutates it in place rather than re-binding the field.
97
+ this._color = new Color();
98
+ this._dirty = 0;
99
+ // Skew in degrees and transform-origin in object-space.
100
+ // applySkewOrigin computes Math.tan inline per non-zero axis, so we only carry the user-facing angle here.
101
+ this._skewX = 0;
102
+ this._skewY = 0;
103
+ this._skewZ = 0;
104
+ this._originX = 0;
105
+ this._originY = 0;
106
+ this._originZ = 0;
107
+ // Skip the position-only fast path in _flush whenever any skew or origin is non-zero, since both modify the matrix beyond pure translation.
108
+ this._hasSkewOrigin = false;
109
+ // Cache the binding dirty queue once so per-frame setters skip a property hop.
110
+ /** @type {Instance[]} */
111
+ this._dirtyList = binding.dirtyList;
112
+ // Cache parent capability flags once so per-frame setters skip prototype-chain in checks.
113
+ const parent = binding.mesh;
114
+ this._hasSetColor = 'setColorAt' in parent;
115
+ this._hasSetVisible = 'setVisibleAt' in parent;
116
+ this._hasGetVisible = 'getVisibleAt' in parent;
117
+
118
+ parent.getMatrixAt(id, this._matrix);
119
+ if (this._matrix.elements[15] === 0) this._matrix.identity();
120
+ this._matrix.decompose(this._position, this._quat, this._scale);
121
+ this._rotation.setFromQuaternion(this._quat, 'XYZ');
122
+
123
+ if ('getColorAt' in parent && 'instanceColor' in parent && parent.instanceColor) {
124
+ parent.getColorAt(id, this._color);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * @param {number} flag
130
+ */
131
+ _markDirty(flag) {
132
+ // Enqueue once per frame, later flags only OR into _dirty without re-pushing to the queue.
133
+ if (this._dirty === 0) this._dirtyList.push(this);
134
+ this._dirty |= flag;
135
+ }
136
+
137
+ _flush() {
138
+ const d = this._dirty;
139
+ if (!d) return;
140
+ const m = this._matrix;
141
+ const p = this._position;
142
+ if (d === DIRTY_POS && !this._hasSkewOrigin) {
143
+ const e = m.elements;
144
+ e[12] = p.x; e[13] = p.y; e[14] = p.z;
145
+ } else {
146
+ const q = this._quat;
147
+ if (d & DIRTY_ROT) q.setFromEuler(this._rotation);
148
+ m.compose(p, q, this._scale);
149
+ if (this._hasSkewOrigin) {
150
+ applySkewOrigin(m.elements, this._skewX, this._skewY, this._skewZ, this._originX, this._originY, this._originZ);
151
+ }
152
+ }
153
+ this.parent.setMatrixAt(this.id, m);
154
+ this._dirty = 0;
155
+ }
156
+
157
+ get x() { return this._position.x; }
158
+ set x(v) { this._position.x = v; this._markDirty(DIRTY_POS); }
159
+
160
+ get y() { return this._position.y; }
161
+ set y(v) { this._position.y = v; this._markDirty(DIRTY_POS); }
162
+
163
+ get z() { return this._position.z; }
164
+ set z(v) { this._position.z = v; this._markDirty(DIRTY_POS); }
165
+
166
+ get rotateX() { return radToDeg(this._rotation.x); }
167
+ set rotateX(v) { this._rotation.x = degToRad(v); this._markDirty(DIRTY_ROT); }
168
+
169
+ get rotateY() { return radToDeg(this._rotation.y); }
170
+ set rotateY(v) { this._rotation.y = degToRad(v); this._markDirty(DIRTY_ROT); }
171
+
172
+ get rotateZ() { return radToDeg(this._rotation.z); }
173
+ set rotateZ(v) { this._rotation.z = degToRad(v); this._markDirty(DIRTY_ROT); }
174
+
175
+ get scaleX() { return this._scale.x; }
176
+ set scaleX(v) { this._scale.x = v; this._markDirty(DIRTY_SCALE); }
177
+
178
+ get scaleY() { return this._scale.y; }
179
+ set scaleY(v) { this._scale.y = v; this._markDirty(DIRTY_SCALE); }
180
+
181
+ get scaleZ() { return this._scale.z; }
182
+ set scaleZ(v) { this._scale.z = v; this._markDirty(DIRTY_SCALE); }
183
+
184
+ get scale() { return this._scale.x; }
185
+ set scale(v) {
186
+ const s = this._scale;
187
+ s.x = v; s.y = v; s.z = v;
188
+ this._markDirty(DIRTY_SCALE);
189
+ }
190
+
191
+ get skewX() { return this._skewX; }
192
+ set skewX(v) {
193
+ this._skewX = v;
194
+ this._hasSkewOrigin = hasSkewOrigin(this);
195
+ this._markDirty(DIRTY_SKEW);
196
+ }
197
+
198
+ get skewY() { return this._skewY; }
199
+ set skewY(v) {
200
+ this._skewY = v;
201
+ this._hasSkewOrigin = hasSkewOrigin(this);
202
+ this._markDirty(DIRTY_SKEW);
203
+ }
204
+
205
+ get skewZ() { return this._skewZ; }
206
+ set skewZ(v) {
207
+ this._skewZ = v;
208
+ this._hasSkewOrigin = hasSkewOrigin(this);
209
+ this._markDirty(DIRTY_SKEW);
210
+ }
211
+
212
+ get transformOriginX() { return this._originX; }
213
+ set transformOriginX(v) {
214
+ this._originX = v;
215
+ this._hasSkewOrigin = hasSkewOrigin(this);
216
+ this._markDirty(DIRTY_SKEW);
217
+ }
218
+
219
+ get transformOriginY() { return this._originY; }
220
+ set transformOriginY(v) {
221
+ this._originY = v;
222
+ this._hasSkewOrigin = hasSkewOrigin(this);
223
+ this._markDirty(DIRTY_SKEW);
224
+ }
225
+
226
+ get transformOriginZ() { return this._originZ; }
227
+ set transformOriginZ(v) {
228
+ this._originZ = v;
229
+ this._hasSkewOrigin = hasSkewOrigin(this);
230
+ this._markDirty(DIRTY_SKEW);
231
+ }
232
+
233
+ get opacity() {
234
+ return readScalar(/** @type {any} */(this.parent).material, 'opacity', PATH_DIRECT, 1);
235
+ }
236
+ /** @param {number} v */
237
+ set opacity(v) {
238
+ writeScalar(/** @type {any} */(this.parent).material, 'opacity', v, PATH_DIRECT);
239
+ }
240
+
241
+ get visible() {
242
+ return this._hasGetVisible ? /** @type {any} */(this.parent).getVisibleAt(this.id) : true;
243
+ }
244
+ /** @param {boolean} v */
245
+ set visible(v) {
246
+ if (this._hasSetVisible) /** @type {any} */(this.parent).setVisibleAt(this.id, v);
247
+ }
248
+
249
+ }
250
+
251
+ /**
252
+ * Flushes pending matrix writes for every dirty instance of `mesh`.
253
+ * Called automatically before each render. Call it yourself if you read
254
+ * `mesh.instanceMatrix` between an animation tick and the next render.
255
+ *
256
+ * @param {InstanceParent} mesh
257
+ */
258
+ function commitChanges(mesh) {
259
+ const binding = bindings.get(mesh);
260
+ if (binding) binding.flush();
261
+ }
262
+
263
+ /**
264
+ * Returns an array of per-instance adapters for `mesh`. Index by id, deleted slots on `BatchedMesh` are `null`. Pass the array (or a slice / a single element) to `animate()`.
265
+ *
266
+ * animate(getInstances(mesh), { x: 100, delay: stagger(5) });
267
+ * animate(getInstances(mesh)[42], { scale: 2 });
268
+ *
269
+ * The same array reference is preserved across `mesh.count` / `addInstance` / `deleteInstance` calls. Entries are pushed, nulled, or truncated in place. Animations bound to an outdated reference keep tweening their original adapters.
270
+ *
271
+ * `mesh.onBeforeRender` is replaced with an accessor that flushes
272
+ * pending instance writes before each render and forwards to your
273
+ * handler. Assigning your own `mesh.onBeforeRender = fn` keeps the
274
+ * auto-flush, but reading `mesh.onBeforeRender` afterwards returns the
275
+ * chained dispatcher rather than `fn` itself, so identity checks
276
+ * (`mesh.onBeforeRender === fn`) will not match.
277
+ *
278
+ * @param {InstanceParent} mesh
279
+ * @return {(Instance | null)[]}
280
+ */
281
+ function getInstances(mesh) {
282
+ let binding = bindings.get(mesh);
283
+ if (!binding) {
284
+ binding = new InstanceBinding(mesh);
285
+ bindings.set(mesh, binding);
286
+ }
287
+ if (mesh instanceof BatchedMesh) {
288
+ return refreshBatched(binding);
289
+ }
290
+ return refreshInstanced(binding);
291
+ }
292
+
293
+ /**
294
+ * @param {InstanceBinding} binding
295
+ * @return {(Instance | null)[]}
296
+ */
297
+ function refreshInstanced(binding) {
298
+ const mesh = /** @type {InstancedMesh} */(binding.mesh);
299
+ const count = mesh.count;
300
+ const arr = binding.instances;
301
+ if (arr.length === 0 && count > 0) {
302
+ arr.length = count;
303
+ for (let i = 0; i < count; i++) arr[i] = new Instance(binding, i);
304
+ return arr;
305
+ }
306
+ if (arr.length < count) {
307
+ for (let i = arr.length; i < count; i++) arr.push(new Instance(binding, i));
308
+ } else if (arr.length > count) {
309
+ arr.length = count;
310
+ }
311
+ return arr;
312
+ }
313
+
314
+ /**
315
+ * @param {InstanceBinding} binding
316
+ * @return {(Instance | null)[]}
317
+ */
318
+ function refreshBatched(binding) {
319
+ const mesh = /** @type {BatchedMesh} */(binding.mesh);
320
+ const arr = binding.instances;
321
+ // Read three internal _instanceInfo to skip slots marked inactive by deleteInstance.
322
+ // Iterate the full slot count, not instanceCount, since deleted slots leave gaps but live ids past them must still be visited.
323
+ const instanceInfo = /** @type {{ _instanceInfo?: { active: boolean }[] }} */(mesh)._instanceInfo ?? [];
324
+ const len = instanceInfo.length;
325
+ if (arr.length < len) arr.length = len;
326
+ for (let i = 0; i < len; i++) {
327
+ const info = instanceInfo[i];
328
+ const inactive = info && info.active === false;
329
+ if (inactive) {
330
+ arr[i] = null;
331
+ } else if (!arr[i]) {
332
+ arr[i] = new Instance(binding, i);
333
+ }
334
+ }
335
+ if (arr.length > len) arr.length = len;
336
+ return arr;
337
+ }
338
+
339
+ const instanceAdapter = threeAdapter.registerTargetAdapter((t) => t instanceof Instance);
340
+ instanceAdapter.registerProperty('color',
341
+ (t) => readColorHex(t._color),
342
+ (t, _, tw) => {
343
+ if (!t._hasSetColor) return;
344
+ const ns = tw._numbers;
345
+ t._color.setRGB(ns[0] * COLOR_NORM, ns[1] * COLOR_NORM, ns[2] * COLOR_NORM, SRGBColorSpace);
346
+ const p = /** @type {any} */(t.parent);
347
+ p.setColorAt(t.id, t._color);
348
+ if (p.instanceColor) p.instanceColor.needsUpdate = true;
349
+ },
350
+ );
351
+ // Shorthand 3-token string x y z routed via the engine COMPLEX path.
352
+ // The setter reads tween _numbers for the per-frame lerped triplet.
353
+ instanceAdapter.registerProperty('transformOrigin',
354
+ (t) => `${t._originX} ${t._originY} ${t._originZ}`,
355
+ (t, _, tw) => {
356
+ const ns = tw._numbers;
357
+ t._originX = ns[0];
358
+ t._originY = ns[1];
359
+ t._originZ = ns[2];
360
+ t._hasSkewOrigin = hasSkewOrigin(t);
361
+ t._markDirty(DIRTY_SKEW);
362
+ },
363
+ );
364
+
365
+ export { commitChanges, getInstances };
@@ -0,0 +1,214 @@
1
+ /**
2
+ * Anime.js - adapters - CJS
3
+ * @version v4.5.0
4
+ * @license MIT
5
+ * @copyright 2026 - Julian Garnier
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ var three = require('three');
11
+ var number = require('../../utils/number.cjs');
12
+ var adapter = require('./adapter.cjs');
13
+ var helpers = require('./helpers.cjs');
14
+
15
+ /**
16
+ * `Object3D` adapter. Maps flat properties (position, rotation, scale, opacity, color, visible, light / audio / camera specifics) onto the matching three.js fields, and auto-detects material props (direct / uniform / TSL `UniformNode`) on the target's `material` at tween creation.
17
+ */
18
+
19
+
20
+ const colorTarget = (t) => t.isLight ? t : t.material;
21
+
22
+ // Per-mesh skew and transformOrigin state, stored under a private symbol so we add one hidden property instead of polluting the Object3D surface with seven underscored fields.
23
+ const skewSymbol = Symbol('animejs.skewOrigin');
24
+
25
+ // Fallback opacity storage for Object3D targets without a material such as Groups or CSS2DObjects.
26
+ // Without it reads always return the default 1, so reverse-direction tweens between two non-default values collapse to a no-op delta and the visibility flip never fires on the way back.
27
+ const opacitySymbol = Symbol('animejs.opacity');
28
+
29
+ /**
30
+ * Sets `o.visible` based on opacity and current scale. If `opacity` is omitted, reads it from `o.material` (defaults to `1` when no material is present).
31
+ *
32
+ * @param {Object3D & { material?: import('three').Material | import('three').Material[] }} o
33
+ * @param {number} [opacity]
34
+ */
35
+ function setVisibility(o, opacity) {
36
+ if (opacity === undefined) {
37
+ if (o.material) {
38
+ opacity = helpers.readScalar(o.material, 'opacity', helpers.PATH_DIRECT, 1);
39
+ } else {
40
+ const v = o[opacitySymbol];
41
+ opacity = v === undefined ? 1 : v;
42
+ }
43
+ }
44
+ const s = o.scale;
45
+ o.visible = !!(opacity && s.x && s.y && s.z);
46
+ }
47
+
48
+ /**
49
+ * Installs a per-mesh `updateMatrix` override on first skew / transformOrigin write. The override calls the original three.js compose, then patches the result with `applySkewOrigin` whenever any axis is non-zero. Idempotent.
50
+ *
51
+ * @param {any} mesh
52
+ * @return {{ skewX: number, skewY: number, skewZ: number, originX: number, originY: number, originZ: number }}
53
+ */
54
+ function installSkewMatrix(mesh) {
55
+ let s = mesh[skewSymbol];
56
+ if (s) return s;
57
+ s = mesh[skewSymbol] = { skewX: 0, skewY: 0, skewZ: 0, originX: 0, originY: 0, originZ: 0 };
58
+ const original = mesh.updateMatrix;
59
+ mesh.updateMatrix = function () {
60
+ original.call(this);
61
+ const st = this[skewSymbol];
62
+ if (st.skewX !== 0 || st.skewY !== 0 || st.skewZ !== 0 || st.originX !== 0 || st.originY !== 0 || st.originZ !== 0) {
63
+ helpers.applySkewOrigin(this.matrix.elements, st.skewX, st.skewY, st.skewZ, st.originX, st.originY, st.originZ);
64
+ }
65
+ };
66
+ return s;
67
+ }
68
+
69
+ const threeObject3D = adapter.threeAdapter.registerTargetAdapter((t) => t instanceof three.Object3D);
70
+
71
+ // Position
72
+ threeObject3D.registerProperty('x', (t) => t.position.x, (t, v) => { t.position.x = v; });
73
+ threeObject3D.registerProperty('y', (t) => t.position.y, (t, v) => { t.position.y = v; });
74
+ threeObject3D.registerProperty('z', (t) => t.position.z, (t, v) => { t.position.z = v; });
75
+
76
+ // Rotation in degrees
77
+ threeObject3D.registerProperty('rotateX', (t) => number.radToDeg(t.rotation.x), (t, v) => { t.rotation.x = number.degToRad(v); });
78
+ threeObject3D.registerProperty('rotateY', (t) => number.radToDeg(t.rotation.y), (t, v) => { t.rotation.y = number.degToRad(v); });
79
+ threeObject3D.registerProperty('rotateZ', (t) => number.radToDeg(t.rotation.z), (t, v) => { t.rotation.z = number.degToRad(v); });
80
+
81
+ // Scale per-axis and uniform
82
+ threeObject3D.registerProperty('scaleX', (t) => t.scale.x, (t, v) => { t.scale.x = v; setVisibility(t); });
83
+ threeObject3D.registerProperty('scaleY', (t) => t.scale.y, (t, v) => { t.scale.y = v; setVisibility(t); });
84
+ threeObject3D.registerProperty('scaleZ', (t) => t.scale.z, (t, v) => { t.scale.z = v; setVisibility(t); });
85
+ threeObject3D.registerProperty('scale',
86
+ (t) => t.scale.x,
87
+ (t, v) => {
88
+ t.scale.x = v; t.scale.y = v; t.scale.z = v;
89
+ setVisibility(t);
90
+ },
91
+ );
92
+
93
+ // Material
94
+ threeObject3D.registerProperty('visible', (t) => t.visible, (t, v) => { t.visible = !!v; });
95
+ threeObject3D.registerProperty('opacity',
96
+ (t) => {
97
+ if (t.material) return helpers.readScalar(t.material, 'opacity', helpers.PATH_DIRECT, 1);
98
+ const v = t[opacitySymbol];
99
+ return v === undefined ? 1 : v;
100
+ },
101
+ (t, v) => {
102
+ if (t.material) helpers.writeScalar(t.material, 'opacity', v, helpers.PATH_DIRECT);
103
+ else t[opacitySymbol] = v;
104
+ setVisibility(t, v);
105
+ },
106
+ (t) => !t.isLight,
107
+ );
108
+ threeObject3D.registerProperty('color',
109
+ (t) => helpers.readColorAt(colorTarget(t), 'color', helpers.PATH_DIRECT),
110
+ (t, _, tw) => helpers.writeColorAt(colorTarget(t), 'color', tw._numbers, helpers.PATH_DIRECT),
111
+ );
112
+
113
+ // HemisphereLight
114
+ threeObject3D.registerProperty('groundColor',
115
+ (t) => helpers.readColorAt(t, 'groundColor', helpers.PATH_DIRECT),
116
+ (t, _, tw) => helpers.writeColorAt(t, 'groundColor', tw._numbers, helpers.PATH_DIRECT),
117
+ (t) => !!t.groundColor,
118
+ );
119
+
120
+ // Scene background, lazily initializes scene background to a Color on first write so the user does not have to set one upfront.
121
+ threeObject3D.registerProperty('background',
122
+ (t) => {
123
+ const bg = /** @type {any} */(t).background;
124
+ return bg && bg.isColor ? helpers.readColorHex(bg) : '#000000';
125
+ },
126
+ (t, _, tw) => {
127
+ const scene = /** @type {any} */(t);
128
+ let bg = scene.background;
129
+ if (!bg || !bg.isColor) {
130
+ bg = new three.Color();
131
+ scene.background = bg;
132
+ }
133
+ const ns = tw._numbers;
134
+ bg.setRGB(ns[0] * helpers.COLOR_NORM, ns[1] * helpers.COLOR_NORM, ns[2] * helpers.COLOR_NORM, three.SRGBColorSpace);
135
+ },
136
+ (t) => !!t.isScene,
137
+ );
138
+
139
+ // Method-bridged props for Audio and PerspectiveCamera focalLength, read via getXxx and write via setXxx.
140
+ const registerMethodProp = (apiName, getter, setter, gate) => {
141
+ threeObject3D.registerProperty(apiName,
142
+ (t) => t[getter](),
143
+ (t, v) => { t[setter](v); },
144
+ (t) => !!t[gate],
145
+ );
146
+ };
147
+ registerMethodProp('volume', 'getVolume', 'setVolume', 'setVolume');
148
+ // PositionalAudio
149
+ registerMethodProp('refDistance', 'getRefDistance', 'setRefDistance', 'setRefDistance');
150
+ registerMethodProp('rolloffFactor', 'getRolloffFactor', 'setRolloffFactor', 'setRefDistance');
151
+ registerMethodProp('maxDistance', 'getMaxDistance', 'setMaxDistance', 'setRefDistance');
152
+ // PerspectiveCamera
153
+ registerMethodProp('focalLength', 'getFocalLength', 'setFocalLength', 'setFocalLength');
154
+
155
+ // Camera projection-update props, setter writes the value then calls updateProjectionMatrix.
156
+ const registerCameraProp = (apiName, gate) => {
157
+ threeObject3D.registerProperty(apiName,
158
+ (t) => t[apiName],
159
+ (t, v) => { t[apiName] = v; t.updateProjectionMatrix(); },
160
+ gate,
161
+ );
162
+ };
163
+ const isPersp = (t) => !!t.isPerspectiveCamera;
164
+ const isOrtho = (t) => !!t.isOrthographicCamera;
165
+ registerCameraProp('fov', isPersp);
166
+ registerCameraProp('aspect', isPersp);
167
+ registerCameraProp('left', isOrtho);
168
+ registerCameraProp('right', isOrtho);
169
+ registerCameraProp('top', isOrtho);
170
+ registerCameraProp('bottom', isOrtho);
171
+
172
+ // Skew in degrees and transform-origin in object-space.
173
+ // Patches mesh updateMatrix on first write so the standard PRS compose is followed by an in-place skew and origin shift.
174
+ // Reads default to 0 for meshes that have never been written.
175
+ /**
176
+ * @param {String} apiName
177
+ * @param {String} key
178
+ */
179
+ const registerSkewProp = (apiName, key) => {
180
+ threeObject3D.registerProperty(apiName,
181
+ (t) => { const s = /** @type {any} */(t)[skewSymbol]; return s ? s[key] : 0; },
182
+ (t, v) => { installSkewMatrix(t)[key] = v; },
183
+ );
184
+ };
185
+ registerSkewProp('skewX', 'skewX');
186
+ registerSkewProp('skewY', 'skewY');
187
+ registerSkewProp('skewZ', 'skewZ');
188
+ registerSkewProp('transformOriginX', 'originX');
189
+ registerSkewProp('transformOriginY', 'originY');
190
+ registerSkewProp('transformOriginZ', 'originZ');
191
+
192
+ // Shorthand 3-token string x y z or 2-string from-to array routed via the engine COMPLEX path.
193
+ // The setter reads tween _numbers for the per-frame lerped triplet.
194
+ threeObject3D.registerProperty('transformOrigin',
195
+ (t) => {
196
+ const s = /** @type {any} */(t)[skewSymbol];
197
+ return s ? `${s.originX} ${s.originY} ${s.originZ}` : '0 0 0';
198
+ },
199
+ (t, _, tw) => {
200
+ const s = installSkewMatrix(t);
201
+ const ns = tw._numbers;
202
+ s.originX = ns[0];
203
+ s.originY = ns[1];
204
+ s.originZ = ns[2];
205
+ },
206
+ );
207
+
208
+ // Shared by both camera types.
209
+ const isCamera = (t) => !!t.isPerspectiveCamera || !!t.isOrthographicCamera;
210
+ registerCameraProp('near', isCamera);
211
+ registerCameraProp('far', isCamera);
212
+ registerCameraProp('zoom', isCamera);
213
+
214
+ // Auto-detection for material props on meshes and direct Vector / Color fields on the target is provided by the shared resolvers in resolvers.js.
@@ -0,0 +1 @@
1
+ export {};