animejs 4.4.1 → 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.
- package/README.md +2 -3
- package/dist/bundles/anime.esm.js +462 -213
- package/dist/bundles/anime.esm.min.js +2 -2
- package/dist/bundles/anime.umd.js +462 -213
- package/dist/bundles/anime.umd.min.js +2 -2
- package/dist/modules/adapters/index.cjs +14 -0
- package/dist/modules/adapters/index.d.ts +1 -0
- package/dist/modules/adapters/index.js +8 -0
- package/dist/modules/adapters/registry.cjs +149 -0
- package/dist/modules/adapters/registry.d.ts +65 -0
- package/dist/modules/adapters/registry.js +146 -0
- package/dist/modules/adapters/three/adapter.cjs +26 -0
- package/dist/modules/adapters/three/adapter.d.ts +15 -0
- package/dist/modules/adapters/three/adapter.js +24 -0
- package/dist/modules/adapters/three/helpers.cjs +297 -0
- package/dist/modules/adapters/three/helpers.d.ts +89 -0
- package/dist/modules/adapters/three/helpers.js +280 -0
- package/dist/modules/adapters/three/index.cjs +20 -0
- package/dist/modules/adapters/three/index.d.ts +2 -0
- package/dist/modules/adapters/three/index.js +12 -0
- package/dist/modules/adapters/three/instance.cjs +368 -0
- package/dist/modules/adapters/three/instance.d.ts +133 -0
- package/dist/modules/adapters/three/instance.js +365 -0
- package/dist/modules/adapters/three/object3d.cjs +214 -0
- package/dist/modules/adapters/three/object3d.d.ts +1 -0
- package/dist/modules/adapters/three/object3d.js +212 -0
- package/dist/modules/adapters/three/resolvers.cjs +105 -0
- package/dist/modules/adapters/three/resolvers.d.ts +1 -0
- package/dist/modules/adapters/three/resolvers.js +103 -0
- package/dist/modules/adapters/three/uniform.cjs +41 -0
- package/dist/modules/adapters/three/uniform.d.ts +1 -0
- package/dist/modules/adapters/three/uniform.js +39 -0
- package/dist/modules/animatable/animatable.cjs +2 -1
- package/dist/modules/animatable/animatable.d.ts +2 -1
- package/dist/modules/animatable/animatable.js +2 -1
- package/dist/modules/animatable/index.cjs +1 -1
- package/dist/modules/animatable/index.js +1 -1
- package/dist/modules/animation/additive.cjs +1 -1
- package/dist/modules/animation/additive.js +1 -1
- package/dist/modules/animation/animation.cjs +43 -16
- package/dist/modules/animation/animation.d.ts +5 -0
- package/dist/modules/animation/animation.js +45 -18
- package/dist/modules/animation/composition.cjs +38 -35
- package/dist/modules/animation/composition.js +38 -35
- package/dist/modules/animation/index.cjs +1 -1
- package/dist/modules/animation/index.js +1 -1
- package/dist/modules/core/clock.cjs +11 -15
- package/dist/modules/core/clock.d.ts +0 -2
- package/dist/modules/core/clock.js +11 -15
- package/dist/modules/core/colors.cjs +1 -1
- package/dist/modules/core/colors.js +1 -1
- package/dist/modules/core/consts.cjs +15 -1
- package/dist/modules/core/consts.d.ts +2 -0
- package/dist/modules/core/consts.js +14 -2
- package/dist/modules/core/globals.cjs +7 -4
- package/dist/modules/core/globals.d.ts +8 -2
- package/dist/modules/core/globals.js +8 -5
- package/dist/modules/core/helpers.cjs +2 -2
- package/dist/modules/core/helpers.js +3 -3
- package/dist/modules/core/render.cjs +64 -14
- package/dist/modules/core/render.js +65 -15
- package/dist/modules/core/styles.cjs +16 -2
- package/dist/modules/core/styles.js +16 -2
- package/dist/modules/core/targets.cjs +11 -13
- package/dist/modules/core/targets.js +11 -13
- package/dist/modules/core/transforms.cjs +1 -1
- package/dist/modules/core/transforms.js +1 -1
- package/dist/modules/core/units.cjs +1 -1
- package/dist/modules/core/units.js +1 -1
- package/dist/modules/core/values.cjs +73 -82
- package/dist/modules/core/values.d.ts +1 -2
- package/dist/modules/core/values.js +76 -84
- package/dist/modules/draggable/draggable.cjs +1 -1
- package/dist/modules/draggable/draggable.js +1 -1
- package/dist/modules/draggable/index.cjs +1 -1
- package/dist/modules/draggable/index.js +1 -1
- package/dist/modules/easings/cubic-bezier/index.cjs +1 -1
- package/dist/modules/easings/cubic-bezier/index.js +1 -1
- package/dist/modules/easings/eases/index.cjs +1 -1
- package/dist/modules/easings/eases/index.js +1 -1
- package/dist/modules/easings/eases/parser.cjs +3 -3
- package/dist/modules/easings/eases/parser.d.ts +4 -5
- package/dist/modules/easings/eases/parser.js +3 -3
- package/dist/modules/easings/index.cjs +1 -1
- package/dist/modules/easings/index.js +1 -1
- package/dist/modules/easings/irregular/index.cjs +1 -1
- package/dist/modules/easings/irregular/index.js +1 -1
- package/dist/modules/easings/linear/index.cjs +1 -1
- package/dist/modules/easings/linear/index.js +1 -1
- package/dist/modules/easings/none.cjs +1 -1
- package/dist/modules/easings/none.js +1 -1
- package/dist/modules/easings/spring/index.cjs +1 -1
- package/dist/modules/easings/spring/index.js +1 -1
- package/dist/modules/easings/steps/index.cjs +1 -1
- package/dist/modules/easings/steps/index.js +1 -1
- package/dist/modules/engine/engine.cjs +4 -2
- package/dist/modules/engine/engine.js +4 -2
- package/dist/modules/engine/index.cjs +1 -1
- package/dist/modules/engine/index.js +1 -1
- package/dist/modules/events/index.cjs +1 -1
- package/dist/modules/events/index.js +1 -1
- package/dist/modules/events/scroll.cjs +3 -1
- package/dist/modules/events/scroll.js +3 -1
- package/dist/modules/index.cjs +1 -1
- package/dist/modules/index.js +1 -1
- package/dist/modules/layout/index.cjs +1 -1
- package/dist/modules/layout/index.js +1 -1
- package/dist/modules/layout/layout.cjs +1 -1
- package/dist/modules/layout/layout.js +1 -1
- package/dist/modules/scope/index.cjs +1 -1
- package/dist/modules/scope/index.js +1 -1
- package/dist/modules/scope/scope.cjs +1 -1
- package/dist/modules/scope/scope.js +1 -1
- package/dist/modules/svg/drawable.cjs +1 -1
- package/dist/modules/svg/drawable.js +1 -1
- package/dist/modules/svg/helpers.cjs +1 -1
- package/dist/modules/svg/helpers.js +1 -1
- package/dist/modules/svg/index.cjs +1 -1
- package/dist/modules/svg/index.js +1 -1
- package/dist/modules/svg/morphto.cjs +1 -1
- package/dist/modules/svg/morphto.js +1 -1
- package/dist/modules/svg/motionpath.cjs +1 -1
- package/dist/modules/svg/motionpath.js +1 -1
- package/dist/modules/text/index.cjs +1 -1
- package/dist/modules/text/index.js +1 -1
- package/dist/modules/text/scramble.cjs +12 -2
- package/dist/modules/text/scramble.d.ts +9 -1
- package/dist/modules/text/scramble.js +12 -2
- package/dist/modules/text/split.cjs +2 -1
- package/dist/modules/text/split.js +2 -1
- package/dist/modules/timeline/index.cjs +1 -1
- package/dist/modules/timeline/index.js +1 -1
- package/dist/modules/timeline/position.cjs +1 -1
- package/dist/modules/timeline/position.js +1 -1
- package/dist/modules/timeline/timeline.cjs +14 -5
- package/dist/modules/timeline/timeline.d.ts +3 -3
- package/dist/modules/timeline/timeline.js +14 -5
- package/dist/modules/timer/index.cjs +1 -1
- package/dist/modules/timer/index.js +1 -1
- package/dist/modules/timer/timer.cjs +1 -1
- package/dist/modules/timer/timer.js +1 -1
- package/dist/modules/types/index.d.ts +36 -11
- package/dist/modules/utils/chainable.cjs +1 -1
- package/dist/modules/utils/chainable.js +1 -1
- package/dist/modules/utils/index.cjs +1 -1
- package/dist/modules/utils/index.js +1 -1
- package/dist/modules/utils/number.cjs +1 -1
- package/dist/modules/utils/number.js +1 -1
- package/dist/modules/utils/random.cjs +4 -3
- package/dist/modules/utils/random.d.ts +1 -1
- package/dist/modules/utils/random.js +4 -3
- package/dist/modules/utils/stagger.cjs +67 -13
- package/dist/modules/utils/stagger.js +69 -15
- package/dist/modules/utils/target.cjs +4 -1
- package/dist/modules/utils/target.js +4 -1
- package/dist/modules/utils/time.cjs +6 -5
- package/dist/modules/utils/time.d.ts +1 -1
- package/dist/modules/utils/time.js +6 -5
- package/dist/modules/waapi/composition.cjs +1 -1
- package/dist/modules/waapi/composition.js +1 -1
- package/dist/modules/waapi/index.cjs +1 -1
- package/dist/modules/waapi/index.js +1 -1
- package/dist/modules/waapi/waapi.cjs +1 -1
- package/dist/modules/waapi/waapi.js +1 -1
- package/package.json +38 -5
|
@@ -0,0 +1,297 @@
|
|
|
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
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generic read/write helpers for the three.js bindings. Each operates on a target (or target array) and walks to the leaf via a path tag - direct (`target[name]`), uniform (`target.uniforms[name].value`), or TSL node (`target[name].value`). Adapter and resolver files pass the matching `PATH_*` constant; the JIT specializes each call site so the branch in `leafAt` / `writeLeafScalar` constant-folds.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const COLOR_NORM = 1 / 255;
|
|
19
|
+
|
|
20
|
+
const AXIS_MAP = /** @type {Record<string, 'x' | 'y' | 'z' | 'w'>} */({ X: 'x', Y: 'y', Z: 'z', W: 'w' });
|
|
21
|
+
|
|
22
|
+
const PATH_DIRECT = 0;
|
|
23
|
+
const PATH_UNIFORM = 1;
|
|
24
|
+
const PATH_NODE = 2;
|
|
25
|
+
|
|
26
|
+
const KIND_COLOR = 0;
|
|
27
|
+
const KIND_SCALAR = 1;
|
|
28
|
+
const KIND_VECTOR = 2;
|
|
29
|
+
|
|
30
|
+
// Reuse one mutable descriptor across calls, callers must consume immediately since the next call mutates it.
|
|
31
|
+
const desc = { kind: 0, path: 0, base: '', axis: /** @type {'x' | 'y' | 'z' | 'w'} */('x') };
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Patches a column-major `Matrix4.elements` array in place with CSS-style `skewX(α)` / `skewY(β)`, the 3D extension `skewZ(γ)` (shears z by x), and a `transform-origin` shift.
|
|
35
|
+
*
|
|
36
|
+
* @param {number[]} e
|
|
37
|
+
* @param {number} skewX
|
|
38
|
+
* @param {number} skewY
|
|
39
|
+
* @param {number} skewZ
|
|
40
|
+
* @param {number} ox
|
|
41
|
+
* @param {number} oy
|
|
42
|
+
* @param {number} oz
|
|
43
|
+
*/
|
|
44
|
+
function applySkewOrigin(e, skewX, skewY, skewZ, ox, oy, oz) {
|
|
45
|
+
if (skewX !== 0) {
|
|
46
|
+
const t = Math.tan(number.degToRad(skewX));
|
|
47
|
+
e[4] += e[0] * t;
|
|
48
|
+
e[5] += e[1] * t;
|
|
49
|
+
e[6] += e[2] * t;
|
|
50
|
+
}
|
|
51
|
+
if (skewY !== 0) {
|
|
52
|
+
const t = Math.tan(number.degToRad(skewY));
|
|
53
|
+
e[0] += e[4] * t;
|
|
54
|
+
e[1] += e[5] * t;
|
|
55
|
+
e[2] += e[6] * t;
|
|
56
|
+
}
|
|
57
|
+
if (skewZ !== 0) {
|
|
58
|
+
const t = Math.tan(number.degToRad(skewZ));
|
|
59
|
+
e[0] += e[8] * t;
|
|
60
|
+
e[1] += e[9] * t;
|
|
61
|
+
e[2] += e[10] * t;
|
|
62
|
+
}
|
|
63
|
+
if (ox !== 0 || oy !== 0 || oz !== 0) {
|
|
64
|
+
e[12] += ox - (e[0] * ox + e[4] * oy + e[8] * oz);
|
|
65
|
+
e[13] += oy - (e[1] * ox + e[5] * oy + e[9] * oz);
|
|
66
|
+
e[14] += oz - (e[2] * ox + e[6] * oy + e[10] * oz);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {any} c
|
|
72
|
+
* @return {String | null}
|
|
73
|
+
*/
|
|
74
|
+
function readColorHex(c) {
|
|
75
|
+
return c ? `#${c.getHexString(three.SRGBColorSpace)}` : null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Returns `true` when `v` is a `Vector2/3/4` instance whose dimension covers `axis`. `Quaternion` and plain `{x,y,z,w}`-shaped objects are intentionally rejected.
|
|
80
|
+
*
|
|
81
|
+
* @param {any} v
|
|
82
|
+
* @param {'x' | 'y' | 'z' | 'w'} axis
|
|
83
|
+
* @return {boolean}
|
|
84
|
+
*/
|
|
85
|
+
function isVectorWith(v, axis) {
|
|
86
|
+
if (!v) return false;
|
|
87
|
+
if (axis === 'x' || axis === 'y') return !!(v.isVector2 || v.isVector3 || v.isVector4);
|
|
88
|
+
if (axis === 'z') return !!(v.isVector3 || v.isVector4);
|
|
89
|
+
return !!v.isVector4;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Classifies `target[name]` and returns a descriptor `{ kind, path, base, axis }` (or `null`). Used by the resolver entries in `resolvers.js` and by the `Object3D` adapter to build the matching access pattern for any three.js target (Object3D, Material, Texture, Fog, UniformNode).
|
|
94
|
+
*
|
|
95
|
+
* @param {any} target
|
|
96
|
+
* @param {string} name
|
|
97
|
+
* @return {{ kind: number, path: number, base: string, axis: 'x' | 'y' | 'z' | 'w' } | null}
|
|
98
|
+
*/
|
|
99
|
+
function classifyTargetProp(target, name) {
|
|
100
|
+
const value = target[name];
|
|
101
|
+
if (value !== undefined) {
|
|
102
|
+
if (value && value.isColor) {
|
|
103
|
+
desc.kind = KIND_COLOR; desc.path = PATH_DIRECT;
|
|
104
|
+
return desc;
|
|
105
|
+
}
|
|
106
|
+
if (value && value.isUniformNode) {
|
|
107
|
+
// Route TSL slot writes through node value, booleans share the scalar entry.
|
|
108
|
+
const v = value.value;
|
|
109
|
+
if (v && v.isColor) {
|
|
110
|
+
desc.kind = KIND_COLOR; desc.path = PATH_NODE;
|
|
111
|
+
return desc;
|
|
112
|
+
}
|
|
113
|
+
if (typeof v === 'number' || typeof v === 'boolean') {
|
|
114
|
+
desc.kind = KIND_SCALAR; desc.path = PATH_NODE;
|
|
115
|
+
return desc;
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
120
|
+
desc.kind = KIND_SCALAR; desc.path = PATH_DIRECT;
|
|
121
|
+
return desc;
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const uniforms = target.uniforms;
|
|
126
|
+
const u = uniforms && uniforms[name];
|
|
127
|
+
if (u) {
|
|
128
|
+
const uv = u.value;
|
|
129
|
+
if (uv && uv.isColor) {
|
|
130
|
+
desc.kind = KIND_COLOR; desc.path = PATH_UNIFORM;
|
|
131
|
+
return desc;
|
|
132
|
+
}
|
|
133
|
+
if (typeof uv === 'number') {
|
|
134
|
+
desc.kind = KIND_SCALAR; desc.path = PATH_UNIFORM;
|
|
135
|
+
return desc;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Decompose vector axis for names like posX, uOffsetY, uVec4W, colorNodeX.
|
|
139
|
+
const axis = AXIS_MAP[name[name.length - 1]];
|
|
140
|
+
if (axis) {
|
|
141
|
+
const base = name.slice(0, -1);
|
|
142
|
+
if (isVectorWith(target[base], axis)) {
|
|
143
|
+
desc.kind = KIND_VECTOR; desc.path = PATH_DIRECT; desc.base = base; desc.axis = axis;
|
|
144
|
+
return desc;
|
|
145
|
+
}
|
|
146
|
+
const baseSlot = target[base];
|
|
147
|
+
if (baseSlot && baseSlot.isUniformNode && isVectorWith(baseSlot.value, axis)) {
|
|
148
|
+
desc.kind = KIND_VECTOR; desc.path = PATH_NODE; desc.base = base; desc.axis = axis;
|
|
149
|
+
return desc;
|
|
150
|
+
}
|
|
151
|
+
const ub = uniforms && uniforms[base];
|
|
152
|
+
if (ub && isVectorWith(ub.value, axis)) {
|
|
153
|
+
desc.kind = KIND_VECTOR; desc.path = PATH_UNIFORM; desc.base = base; desc.axis = axis;
|
|
154
|
+
return desc;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function leafAt(target, name, path) {
|
|
161
|
+
if (path === PATH_DIRECT) return target[name];
|
|
162
|
+
if (path === PATH_UNIFORM) {
|
|
163
|
+
const u = target.uniforms;
|
|
164
|
+
const e = u && u[name];
|
|
165
|
+
return e ? e.value : null;
|
|
166
|
+
}
|
|
167
|
+
const n = target[name];
|
|
168
|
+
return n ? n.value : null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function writeLeafScalar(target, name, v, path) {
|
|
172
|
+
if (path === PATH_DIRECT) { target[name] = v; return; }
|
|
173
|
+
if (path === PATH_UNIFORM) {
|
|
174
|
+
const u = target.uniforms;
|
|
175
|
+
const e = u && u[name];
|
|
176
|
+
if (e) e.value = v;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const n = target[name];
|
|
180
|
+
if (n) n.value = v;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {any} target
|
|
185
|
+
* @param {string} name
|
|
186
|
+
* @param {number} path
|
|
187
|
+
* @param {number} [defaultValue]
|
|
188
|
+
* @return {number}
|
|
189
|
+
*/
|
|
190
|
+
function readScalar(target, name, path, defaultValue) {
|
|
191
|
+
if (defaultValue === undefined) defaultValue = 0;
|
|
192
|
+
if (!target) return defaultValue;
|
|
193
|
+
const first = Array.isArray(target) ? target[0] : target;
|
|
194
|
+
if (!first) return defaultValue;
|
|
195
|
+
const v = leafAt(first, name, path);
|
|
196
|
+
return v === undefined || v === null ? defaultValue : v;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @param {any} target
|
|
201
|
+
* @param {string} name
|
|
202
|
+
* @param {number} v
|
|
203
|
+
* @param {number} path
|
|
204
|
+
*/
|
|
205
|
+
function writeScalar(target, name, v, path) {
|
|
206
|
+
if (!target) return;
|
|
207
|
+
if (Array.isArray(target)) {
|
|
208
|
+
for (let i = 0, l = target.length; i < l; i++) writeLeafScalar(target[i], name, v, path);
|
|
209
|
+
} else {
|
|
210
|
+
writeLeafScalar(target, name, v, path);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @param {any} target
|
|
216
|
+
* @param {string} name
|
|
217
|
+
* @param {number} path
|
|
218
|
+
* @return {String | null}
|
|
219
|
+
*/
|
|
220
|
+
function readColorAt(target, name, path) {
|
|
221
|
+
if (!target) return null;
|
|
222
|
+
const first = Array.isArray(target) ? target[0] : target;
|
|
223
|
+
return readColorHex(first ? leafAt(first, name, path) : null);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @param {any} target
|
|
228
|
+
* @param {string} name
|
|
229
|
+
* @param {Array.<Number>} ns
|
|
230
|
+
* @param {number} path
|
|
231
|
+
*/
|
|
232
|
+
function writeColorAt(target, name, ns, path) {
|
|
233
|
+
if (!target) return;
|
|
234
|
+
const r = ns[0] * COLOR_NORM;
|
|
235
|
+
const g = ns[1] * COLOR_NORM;
|
|
236
|
+
const b = ns[2] * COLOR_NORM;
|
|
237
|
+
if (Array.isArray(target)) {
|
|
238
|
+
for (let i = 0, l = target.length; i < l; i++) {
|
|
239
|
+
const c = leafAt(target[i], name, path);
|
|
240
|
+
if (c) c.setRGB(r, g, b, three.SRGBColorSpace);
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
const c = leafAt(target, name, path);
|
|
244
|
+
if (c) c.setRGB(r, g, b, three.SRGBColorSpace);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @param {any} target
|
|
250
|
+
* @param {string} base
|
|
251
|
+
* @param {'x' | 'y' | 'z' | 'w'} axis
|
|
252
|
+
* @param {number} path
|
|
253
|
+
* @return {number}
|
|
254
|
+
*/
|
|
255
|
+
function readVectorAt(target, base, axis, path) {
|
|
256
|
+
if (!target) return 0;
|
|
257
|
+
const first = Array.isArray(target) ? target[0] : target;
|
|
258
|
+
const vec = first ? leafAt(first, base, path) : null;
|
|
259
|
+
return vec ? vec[axis] : 0;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @param {any} target
|
|
264
|
+
* @param {string} base
|
|
265
|
+
* @param {'x' | 'y' | 'z' | 'w'} axis
|
|
266
|
+
* @param {number} v
|
|
267
|
+
* @param {number} path
|
|
268
|
+
*/
|
|
269
|
+
function writeVectorAt(target, base, axis, v, path) {
|
|
270
|
+
if (!target) return;
|
|
271
|
+
if (Array.isArray(target)) {
|
|
272
|
+
for (let i = 0, l = target.length; i < l; i++) {
|
|
273
|
+
const vec = leafAt(target[i], base, path);
|
|
274
|
+
if (vec) vec[axis] = v;
|
|
275
|
+
}
|
|
276
|
+
} else {
|
|
277
|
+
const vec = leafAt(target, base, path);
|
|
278
|
+
if (vec) vec[axis] = v;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
exports.AXIS_MAP = AXIS_MAP;
|
|
283
|
+
exports.COLOR_NORM = COLOR_NORM;
|
|
284
|
+
exports.KIND_COLOR = KIND_COLOR;
|
|
285
|
+
exports.KIND_SCALAR = KIND_SCALAR;
|
|
286
|
+
exports.KIND_VECTOR = KIND_VECTOR;
|
|
287
|
+
exports.PATH_DIRECT = PATH_DIRECT;
|
|
288
|
+
exports.applySkewOrigin = applySkewOrigin;
|
|
289
|
+
exports.classifyTargetProp = classifyTargetProp;
|
|
290
|
+
exports.isVectorWith = isVectorWith;
|
|
291
|
+
exports.readColorAt = readColorAt;
|
|
292
|
+
exports.readColorHex = readColorHex;
|
|
293
|
+
exports.readScalar = readScalar;
|
|
294
|
+
exports.readVectorAt = readVectorAt;
|
|
295
|
+
exports.writeColorAt = writeColorAt;
|
|
296
|
+
exports.writeScalar = writeScalar;
|
|
297
|
+
exports.writeVectorAt = writeVectorAt;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patches a column-major `Matrix4.elements` array in place with CSS-style `skewX(α)` / `skewY(β)`, the 3D extension `skewZ(γ)` (shears z by x), and a `transform-origin` shift.
|
|
3
|
+
*
|
|
4
|
+
* @param {number[]} e
|
|
5
|
+
* @param {number} skewX
|
|
6
|
+
* @param {number} skewY
|
|
7
|
+
* @param {number} skewZ
|
|
8
|
+
* @param {number} ox
|
|
9
|
+
* @param {number} oy
|
|
10
|
+
* @param {number} oz
|
|
11
|
+
*/
|
|
12
|
+
export function applySkewOrigin(e: number[], skewX: number, skewY: number, skewZ: number, ox: number, oy: number, oz: number): void;
|
|
13
|
+
/**
|
|
14
|
+
* @param {any} c
|
|
15
|
+
* @return {String | null}
|
|
16
|
+
*/
|
|
17
|
+
export function readColorHex(c: any): string | null;
|
|
18
|
+
/**
|
|
19
|
+
* Returns `true` when `v` is a `Vector2/3/4` instance whose dimension covers `axis`. `Quaternion` and plain `{x,y,z,w}`-shaped objects are intentionally rejected.
|
|
20
|
+
*
|
|
21
|
+
* @param {any} v
|
|
22
|
+
* @param {'x' | 'y' | 'z' | 'w'} axis
|
|
23
|
+
* @return {boolean}
|
|
24
|
+
*/
|
|
25
|
+
export function isVectorWith(v: any, axis: "x" | "y" | "z" | "w"): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Classifies `target[name]` and returns a descriptor `{ kind, path, base, axis }` (or `null`). Used by the resolver entries in `resolvers.js` and by the `Object3D` adapter to build the matching access pattern for any three.js target (Object3D, Material, Texture, Fog, UniformNode).
|
|
28
|
+
*
|
|
29
|
+
* @param {any} target
|
|
30
|
+
* @param {string} name
|
|
31
|
+
* @return {{ kind: number, path: number, base: string, axis: 'x' | 'y' | 'z' | 'w' } | null}
|
|
32
|
+
*/
|
|
33
|
+
export function classifyTargetProp(target: any, name: string): {
|
|
34
|
+
kind: number;
|
|
35
|
+
path: number;
|
|
36
|
+
base: string;
|
|
37
|
+
axis: "x" | "y" | "z" | "w";
|
|
38
|
+
} | null;
|
|
39
|
+
/**
|
|
40
|
+
* @param {any} target
|
|
41
|
+
* @param {string} name
|
|
42
|
+
* @param {number} path
|
|
43
|
+
* @param {number} [defaultValue]
|
|
44
|
+
* @return {number}
|
|
45
|
+
*/
|
|
46
|
+
export function readScalar(target: any, name: string, path: number, defaultValue?: number): number;
|
|
47
|
+
/**
|
|
48
|
+
* @param {any} target
|
|
49
|
+
* @param {string} name
|
|
50
|
+
* @param {number} v
|
|
51
|
+
* @param {number} path
|
|
52
|
+
*/
|
|
53
|
+
export function writeScalar(target: any, name: string, v: number, path: number): void;
|
|
54
|
+
/**
|
|
55
|
+
* @param {any} target
|
|
56
|
+
* @param {string} name
|
|
57
|
+
* @param {number} path
|
|
58
|
+
* @return {String | null}
|
|
59
|
+
*/
|
|
60
|
+
export function readColorAt(target: any, name: string, path: number): string | null;
|
|
61
|
+
/**
|
|
62
|
+
* @param {any} target
|
|
63
|
+
* @param {string} name
|
|
64
|
+
* @param {Array.<Number>} ns
|
|
65
|
+
* @param {number} path
|
|
66
|
+
*/
|
|
67
|
+
export function writeColorAt(target: any, name: string, ns: Array<number>, path: number): void;
|
|
68
|
+
/**
|
|
69
|
+
* @param {any} target
|
|
70
|
+
* @param {string} base
|
|
71
|
+
* @param {'x' | 'y' | 'z' | 'w'} axis
|
|
72
|
+
* @param {number} path
|
|
73
|
+
* @return {number}
|
|
74
|
+
*/
|
|
75
|
+
export function readVectorAt(target: any, base: string, axis: "x" | "y" | "z" | "w", path: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* @param {any} target
|
|
78
|
+
* @param {string} base
|
|
79
|
+
* @param {'x' | 'y' | 'z' | 'w'} axis
|
|
80
|
+
* @param {number} v
|
|
81
|
+
* @param {number} path
|
|
82
|
+
*/
|
|
83
|
+
export function writeVectorAt(target: any, base: string, axis: "x" | "y" | "z" | "w", v: number, path: number): void;
|
|
84
|
+
export const COLOR_NORM: number;
|
|
85
|
+
export const AXIS_MAP: Record<string, "x" | "y" | "z" | "w">;
|
|
86
|
+
export const PATH_DIRECT: 0;
|
|
87
|
+
export const KIND_COLOR: 0;
|
|
88
|
+
export const KIND_SCALAR: 1;
|
|
89
|
+
export const KIND_VECTOR: 2;
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - adapters - ESM
|
|
3
|
+
* @version v4.5.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2026 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { SRGBColorSpace } from 'three';
|
|
9
|
+
import { degToRad } from '../../utils/number.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generic read/write helpers for the three.js bindings. Each operates on a target (or target array) and walks to the leaf via a path tag - direct (`target[name]`), uniform (`target.uniforms[name].value`), or TSL node (`target[name].value`). Adapter and resolver files pass the matching `PATH_*` constant; the JIT specializes each call site so the branch in `leafAt` / `writeLeafScalar` constant-folds.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const COLOR_NORM = 1 / 255;
|
|
17
|
+
|
|
18
|
+
const AXIS_MAP = /** @type {Record<string, 'x' | 'y' | 'z' | 'w'>} */({ X: 'x', Y: 'y', Z: 'z', W: 'w' });
|
|
19
|
+
|
|
20
|
+
const PATH_DIRECT = 0;
|
|
21
|
+
const PATH_UNIFORM = 1;
|
|
22
|
+
const PATH_NODE = 2;
|
|
23
|
+
|
|
24
|
+
const KIND_COLOR = 0;
|
|
25
|
+
const KIND_SCALAR = 1;
|
|
26
|
+
const KIND_VECTOR = 2;
|
|
27
|
+
|
|
28
|
+
// Reuse one mutable descriptor across calls, callers must consume immediately since the next call mutates it.
|
|
29
|
+
const desc = { kind: 0, path: 0, base: '', axis: /** @type {'x' | 'y' | 'z' | 'w'} */('x') };
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Patches a column-major `Matrix4.elements` array in place with CSS-style `skewX(α)` / `skewY(β)`, the 3D extension `skewZ(γ)` (shears z by x), and a `transform-origin` shift.
|
|
33
|
+
*
|
|
34
|
+
* @param {number[]} e
|
|
35
|
+
* @param {number} skewX
|
|
36
|
+
* @param {number} skewY
|
|
37
|
+
* @param {number} skewZ
|
|
38
|
+
* @param {number} ox
|
|
39
|
+
* @param {number} oy
|
|
40
|
+
* @param {number} oz
|
|
41
|
+
*/
|
|
42
|
+
function applySkewOrigin(e, skewX, skewY, skewZ, ox, oy, oz) {
|
|
43
|
+
if (skewX !== 0) {
|
|
44
|
+
const t = Math.tan(degToRad(skewX));
|
|
45
|
+
e[4] += e[0] * t;
|
|
46
|
+
e[5] += e[1] * t;
|
|
47
|
+
e[6] += e[2] * t;
|
|
48
|
+
}
|
|
49
|
+
if (skewY !== 0) {
|
|
50
|
+
const t = Math.tan(degToRad(skewY));
|
|
51
|
+
e[0] += e[4] * t;
|
|
52
|
+
e[1] += e[5] * t;
|
|
53
|
+
e[2] += e[6] * t;
|
|
54
|
+
}
|
|
55
|
+
if (skewZ !== 0) {
|
|
56
|
+
const t = Math.tan(degToRad(skewZ));
|
|
57
|
+
e[0] += e[8] * t;
|
|
58
|
+
e[1] += e[9] * t;
|
|
59
|
+
e[2] += e[10] * t;
|
|
60
|
+
}
|
|
61
|
+
if (ox !== 0 || oy !== 0 || oz !== 0) {
|
|
62
|
+
e[12] += ox - (e[0] * ox + e[4] * oy + e[8] * oz);
|
|
63
|
+
e[13] += oy - (e[1] * ox + e[5] * oy + e[9] * oz);
|
|
64
|
+
e[14] += oz - (e[2] * ox + e[6] * oy + e[10] * oz);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {any} c
|
|
70
|
+
* @return {String | null}
|
|
71
|
+
*/
|
|
72
|
+
function readColorHex(c) {
|
|
73
|
+
return c ? `#${c.getHexString(SRGBColorSpace)}` : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns `true` when `v` is a `Vector2/3/4` instance whose dimension covers `axis`. `Quaternion` and plain `{x,y,z,w}`-shaped objects are intentionally rejected.
|
|
78
|
+
*
|
|
79
|
+
* @param {any} v
|
|
80
|
+
* @param {'x' | 'y' | 'z' | 'w'} axis
|
|
81
|
+
* @return {boolean}
|
|
82
|
+
*/
|
|
83
|
+
function isVectorWith(v, axis) {
|
|
84
|
+
if (!v) return false;
|
|
85
|
+
if (axis === 'x' || axis === 'y') return !!(v.isVector2 || v.isVector3 || v.isVector4);
|
|
86
|
+
if (axis === 'z') return !!(v.isVector3 || v.isVector4);
|
|
87
|
+
return !!v.isVector4;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Classifies `target[name]` and returns a descriptor `{ kind, path, base, axis }` (or `null`). Used by the resolver entries in `resolvers.js` and by the `Object3D` adapter to build the matching access pattern for any three.js target (Object3D, Material, Texture, Fog, UniformNode).
|
|
92
|
+
*
|
|
93
|
+
* @param {any} target
|
|
94
|
+
* @param {string} name
|
|
95
|
+
* @return {{ kind: number, path: number, base: string, axis: 'x' | 'y' | 'z' | 'w' } | null}
|
|
96
|
+
*/
|
|
97
|
+
function classifyTargetProp(target, name) {
|
|
98
|
+
const value = target[name];
|
|
99
|
+
if (value !== undefined) {
|
|
100
|
+
if (value && value.isColor) {
|
|
101
|
+
desc.kind = KIND_COLOR; desc.path = PATH_DIRECT;
|
|
102
|
+
return desc;
|
|
103
|
+
}
|
|
104
|
+
if (value && value.isUniformNode) {
|
|
105
|
+
// Route TSL slot writes through node value, booleans share the scalar entry.
|
|
106
|
+
const v = value.value;
|
|
107
|
+
if (v && v.isColor) {
|
|
108
|
+
desc.kind = KIND_COLOR; desc.path = PATH_NODE;
|
|
109
|
+
return desc;
|
|
110
|
+
}
|
|
111
|
+
if (typeof v === 'number' || typeof v === 'boolean') {
|
|
112
|
+
desc.kind = KIND_SCALAR; desc.path = PATH_NODE;
|
|
113
|
+
return desc;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
118
|
+
desc.kind = KIND_SCALAR; desc.path = PATH_DIRECT;
|
|
119
|
+
return desc;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const uniforms = target.uniforms;
|
|
124
|
+
const u = uniforms && uniforms[name];
|
|
125
|
+
if (u) {
|
|
126
|
+
const uv = u.value;
|
|
127
|
+
if (uv && uv.isColor) {
|
|
128
|
+
desc.kind = KIND_COLOR; desc.path = PATH_UNIFORM;
|
|
129
|
+
return desc;
|
|
130
|
+
}
|
|
131
|
+
if (typeof uv === 'number') {
|
|
132
|
+
desc.kind = KIND_SCALAR; desc.path = PATH_UNIFORM;
|
|
133
|
+
return desc;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Decompose vector axis for names like posX, uOffsetY, uVec4W, colorNodeX.
|
|
137
|
+
const axis = AXIS_MAP[name[name.length - 1]];
|
|
138
|
+
if (axis) {
|
|
139
|
+
const base = name.slice(0, -1);
|
|
140
|
+
if (isVectorWith(target[base], axis)) {
|
|
141
|
+
desc.kind = KIND_VECTOR; desc.path = PATH_DIRECT; desc.base = base; desc.axis = axis;
|
|
142
|
+
return desc;
|
|
143
|
+
}
|
|
144
|
+
const baseSlot = target[base];
|
|
145
|
+
if (baseSlot && baseSlot.isUniformNode && isVectorWith(baseSlot.value, axis)) {
|
|
146
|
+
desc.kind = KIND_VECTOR; desc.path = PATH_NODE; desc.base = base; desc.axis = axis;
|
|
147
|
+
return desc;
|
|
148
|
+
}
|
|
149
|
+
const ub = uniforms && uniforms[base];
|
|
150
|
+
if (ub && isVectorWith(ub.value, axis)) {
|
|
151
|
+
desc.kind = KIND_VECTOR; desc.path = PATH_UNIFORM; desc.base = base; desc.axis = axis;
|
|
152
|
+
return desc;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function leafAt(target, name, path) {
|
|
159
|
+
if (path === PATH_DIRECT) return target[name];
|
|
160
|
+
if (path === PATH_UNIFORM) {
|
|
161
|
+
const u = target.uniforms;
|
|
162
|
+
const e = u && u[name];
|
|
163
|
+
return e ? e.value : null;
|
|
164
|
+
}
|
|
165
|
+
const n = target[name];
|
|
166
|
+
return n ? n.value : null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function writeLeafScalar(target, name, v, path) {
|
|
170
|
+
if (path === PATH_DIRECT) { target[name] = v; return; }
|
|
171
|
+
if (path === PATH_UNIFORM) {
|
|
172
|
+
const u = target.uniforms;
|
|
173
|
+
const e = u && u[name];
|
|
174
|
+
if (e) e.value = v;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const n = target[name];
|
|
178
|
+
if (n) n.value = v;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @param {any} target
|
|
183
|
+
* @param {string} name
|
|
184
|
+
* @param {number} path
|
|
185
|
+
* @param {number} [defaultValue]
|
|
186
|
+
* @return {number}
|
|
187
|
+
*/
|
|
188
|
+
function readScalar(target, name, path, defaultValue) {
|
|
189
|
+
if (defaultValue === undefined) defaultValue = 0;
|
|
190
|
+
if (!target) return defaultValue;
|
|
191
|
+
const first = Array.isArray(target) ? target[0] : target;
|
|
192
|
+
if (!first) return defaultValue;
|
|
193
|
+
const v = leafAt(first, name, path);
|
|
194
|
+
return v === undefined || v === null ? defaultValue : v;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @param {any} target
|
|
199
|
+
* @param {string} name
|
|
200
|
+
* @param {number} v
|
|
201
|
+
* @param {number} path
|
|
202
|
+
*/
|
|
203
|
+
function writeScalar(target, name, v, path) {
|
|
204
|
+
if (!target) return;
|
|
205
|
+
if (Array.isArray(target)) {
|
|
206
|
+
for (let i = 0, l = target.length; i < l; i++) writeLeafScalar(target[i], name, v, path);
|
|
207
|
+
} else {
|
|
208
|
+
writeLeafScalar(target, name, v, path);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @param {any} target
|
|
214
|
+
* @param {string} name
|
|
215
|
+
* @param {number} path
|
|
216
|
+
* @return {String | null}
|
|
217
|
+
*/
|
|
218
|
+
function readColorAt(target, name, path) {
|
|
219
|
+
if (!target) return null;
|
|
220
|
+
const first = Array.isArray(target) ? target[0] : target;
|
|
221
|
+
return readColorHex(first ? leafAt(first, name, path) : null);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* @param {any} target
|
|
226
|
+
* @param {string} name
|
|
227
|
+
* @param {Array.<Number>} ns
|
|
228
|
+
* @param {number} path
|
|
229
|
+
*/
|
|
230
|
+
function writeColorAt(target, name, ns, path) {
|
|
231
|
+
if (!target) return;
|
|
232
|
+
const r = ns[0] * COLOR_NORM;
|
|
233
|
+
const g = ns[1] * COLOR_NORM;
|
|
234
|
+
const b = ns[2] * COLOR_NORM;
|
|
235
|
+
if (Array.isArray(target)) {
|
|
236
|
+
for (let i = 0, l = target.length; i < l; i++) {
|
|
237
|
+
const c = leafAt(target[i], name, path);
|
|
238
|
+
if (c) c.setRGB(r, g, b, SRGBColorSpace);
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
const c = leafAt(target, name, path);
|
|
242
|
+
if (c) c.setRGB(r, g, b, SRGBColorSpace);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @param {any} target
|
|
248
|
+
* @param {string} base
|
|
249
|
+
* @param {'x' | 'y' | 'z' | 'w'} axis
|
|
250
|
+
* @param {number} path
|
|
251
|
+
* @return {number}
|
|
252
|
+
*/
|
|
253
|
+
function readVectorAt(target, base, axis, path) {
|
|
254
|
+
if (!target) return 0;
|
|
255
|
+
const first = Array.isArray(target) ? target[0] : target;
|
|
256
|
+
const vec = first ? leafAt(first, base, path) : null;
|
|
257
|
+
return vec ? vec[axis] : 0;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @param {any} target
|
|
262
|
+
* @param {string} base
|
|
263
|
+
* @param {'x' | 'y' | 'z' | 'w'} axis
|
|
264
|
+
* @param {number} v
|
|
265
|
+
* @param {number} path
|
|
266
|
+
*/
|
|
267
|
+
function writeVectorAt(target, base, axis, v, path) {
|
|
268
|
+
if (!target) return;
|
|
269
|
+
if (Array.isArray(target)) {
|
|
270
|
+
for (let i = 0, l = target.length; i < l; i++) {
|
|
271
|
+
const vec = leafAt(target[i], base, path);
|
|
272
|
+
if (vec) vec[axis] = v;
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
const vec = leafAt(target, base, path);
|
|
276
|
+
if (vec) vec[axis] = v;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export { AXIS_MAP, COLOR_NORM, KIND_COLOR, KIND_SCALAR, KIND_VECTOR, PATH_DIRECT, applySkewOrigin, classifyTargetProp, isVectorWith, readColorAt, readColorHex, readScalar, readVectorAt, writeColorAt, writeScalar, writeVectorAt };
|
|
@@ -0,0 +1,20 @@
|
|
|
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 adapter = require('./adapter.cjs');
|
|
11
|
+
require('./resolvers.cjs');
|
|
12
|
+
require('./uniform.cjs');
|
|
13
|
+
require('./object3d.cjs');
|
|
14
|
+
var instance = require('./instance.cjs');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
exports.threeAdapter = adapter.threeAdapter;
|
|
19
|
+
exports.commitChanges = instance.commitChanges;
|
|
20
|
+
exports.getInstances = instance.getInstances;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - adapters - ESM
|
|
3
|
+
* @version v4.5.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2026 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { threeAdapter } from './adapter.js';
|
|
9
|
+
import './resolvers.js';
|
|
10
|
+
import './uniform.js';
|
|
11
|
+
import './object3d.js';
|
|
12
|
+
export { commitChanges, getInstances } from './instance.js';
|