animejs 4.1.3 → 4.2.0-beta.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 +12 -8
- package/{lib → dist/bundles}/anime.esm.js +5237 -5049
- package/dist/bundles/anime.esm.min.js +7 -0
- package/dist/bundles/anime.umd.js +8621 -0
- package/dist/bundles/anime.umd.min.js +7 -0
- package/dist/modules/animatable/animatable.cjs +150 -0
- package/dist/modules/animatable/animatable.d.ts +28 -0
- package/dist/modules/animatable/animatable.js +147 -0
- package/dist/modules/animatable/index.cjs +15 -0
- package/dist/modules/animatable/index.d.ts +1 -0
- package/dist/modules/animatable/index.js +8 -0
- package/dist/modules/animation/additive.cjs +82 -0
- package/dist/modules/animation/additive.d.ts +15 -0
- package/dist/modules/animation/additive.js +79 -0
- package/dist/modules/animation/animation.cjs +660 -0
- package/dist/modules/animation/animation.d.ts +47 -0
- package/dist/modules/animation/animation.js +657 -0
- package/dist/modules/animation/composition.cjs +383 -0
- package/dist/modules/animation/composition.d.ts +10 -0
- package/dist/modules/animation/composition.js +377 -0
- package/dist/modules/animation/index.cjs +15 -0
- package/dist/modules/animation/index.d.ts +1 -0
- package/dist/modules/animation/index.js +8 -0
- package/dist/modules/core/clock.cjs +110 -0
- package/dist/modules/core/clock.d.ts +51 -0
- package/dist/modules/core/clock.js +108 -0
- package/dist/modules/core/colors.cjs +102 -0
- package/dist/modules/core/colors.d.ts +2 -0
- package/dist/modules/core/colors.js +100 -0
- package/dist/modules/core/consts.cjs +154 -0
- package/dist/modules/core/consts.d.ts +59 -0
- package/dist/modules/core/consts.js +121 -0
- package/dist/modules/core/globals.cjs +77 -0
- package/dist/modules/core/globals.d.ts +29 -0
- package/dist/modules/core/globals.js +72 -0
- package/dist/modules/core/helpers.cjs +304 -0
- package/dist/modules/core/helpers.d.ts +43 -0
- package/dist/modules/core/helpers.js +261 -0
- package/dist/modules/core/render.cjs +389 -0
- package/dist/modules/core/render.d.ts +4 -0
- package/dist/modules/core/render.js +386 -0
- package/dist/modules/core/styles.cjs +116 -0
- package/dist/modules/core/styles.d.ts +5 -0
- package/dist/modules/core/styles.js +113 -0
- package/dist/modules/core/targets.cjs +136 -0
- package/dist/modules/core/targets.d.ts +118 -0
- package/dist/modules/core/targets.js +132 -0
- package/dist/modules/core/transforms.cjs +49 -0
- package/dist/modules/core/transforms.d.ts +2 -0
- package/dist/modules/core/transforms.js +47 -0
- package/dist/modules/core/units.cjs +67 -0
- package/dist/modules/core/units.d.ts +3 -0
- package/dist/modules/core/units.js +65 -0
- package/dist/modules/core/values.cjs +215 -0
- package/dist/modules/core/values.d.ts +14 -0
- package/dist/modules/core/values.js +205 -0
- package/dist/modules/draggable/draggable.cjs +1226 -0
- package/dist/modules/draggable/draggable.d.ts +272 -0
- package/dist/modules/draggable/draggable.js +1223 -0
- package/dist/modules/draggable/index.cjs +15 -0
- package/dist/modules/draggable/index.d.ts +1 -0
- package/dist/modules/draggable/index.js +8 -0
- package/dist/modules/easings/cubic-bezier.cjs +64 -0
- package/dist/modules/easings/cubic-bezier.d.ts +2 -0
- package/dist/modules/easings/cubic-bezier.js +62 -0
- package/dist/modules/easings/eases.cjs +149 -0
- package/dist/modules/easings/eases.d.ts +111 -0
- package/dist/modules/easings/eases.js +146 -0
- package/dist/modules/easings/index.cjs +24 -0
- package/dist/modules/easings/index.d.ts +6 -0
- package/dist/modules/easings/index.js +13 -0
- package/dist/modules/easings/irregular.cjs +41 -0
- package/dist/modules/easings/irregular.d.ts +2 -0
- package/dist/modules/easings/irregular.js +39 -0
- package/dist/modules/easings/linear.cjs +59 -0
- package/dist/modules/easings/linear.d.ts +2 -0
- package/dist/modules/easings/linear.js +57 -0
- package/dist/modules/easings/none.cjs +19 -0
- package/dist/modules/easings/none.d.ts +8 -0
- package/dist/modules/easings/none.js +17 -0
- package/dist/modules/easings/parser.cjs +59 -0
- package/dist/modules/easings/parser.d.ts +21 -0
- package/dist/modules/easings/parser.js +55 -0
- package/dist/modules/easings/steps.cjs +30 -0
- package/dist/modules/easings/steps.d.ts +2 -0
- package/dist/modules/easings/steps.js +28 -0
- package/dist/modules/engine/engine.cjs +168 -0
- package/dist/modules/engine/engine.d.ts +21 -0
- package/dist/modules/engine/engine.js +166 -0
- package/dist/modules/engine/index.cjs +14 -0
- package/dist/modules/engine/index.d.ts +1 -0
- package/dist/modules/engine/index.js +8 -0
- package/dist/modules/events/index.cjs +16 -0
- package/dist/modules/events/index.d.ts +1 -0
- package/dist/modules/events/index.js +8 -0
- package/dist/modules/events/scroll.cjs +936 -0
- package/dist/modules/events/scroll.d.ts +189 -0
- package/dist/modules/events/scroll.js +932 -0
- package/dist/modules/index.cjs +103 -0
- package/dist/modules/index.d.ts +19 -0
- package/dist/modules/index.js +42 -0
- package/dist/modules/scope/index.cjs +15 -0
- package/dist/modules/scope/index.d.ts +1 -0
- package/dist/modules/scope/index.js +8 -0
- package/dist/modules/scope/scope.cjs +254 -0
- package/dist/modules/scope/scope.d.ts +115 -0
- package/dist/modules/scope/scope.js +251 -0
- package/dist/modules/spring/index.cjs +15 -0
- package/dist/modules/spring/index.d.ts +1 -0
- package/dist/modules/spring/index.js +8 -0
- package/dist/modules/spring/spring.cjs +133 -0
- package/dist/modules/spring/spring.d.ts +37 -0
- package/dist/modules/spring/spring.js +130 -0
- package/dist/modules/svg/drawable.cjs +119 -0
- package/dist/modules/svg/drawable.d.ts +3 -0
- package/dist/modules/svg/drawable.js +117 -0
- package/dist/modules/svg/helpers.cjs +30 -0
- package/dist/modules/svg/helpers.d.ts +2 -0
- package/dist/modules/svg/helpers.js +28 -0
- package/dist/modules/svg/index.cjs +18 -0
- package/dist/modules/svg/index.d.ts +3 -0
- package/dist/modules/svg/index.js +10 -0
- package/dist/modules/svg/morphto.cjs +58 -0
- package/dist/modules/svg/morphto.d.ts +3 -0
- package/dist/modules/svg/morphto.js +56 -0
- package/dist/modules/svg/motionpath.cjs +79 -0
- package/dist/modules/svg/motionpath.d.ts +7 -0
- package/dist/modules/svg/motionpath.js +77 -0
- package/dist/modules/text/index.cjs +16 -0
- package/dist/modules/text/index.d.ts +1 -0
- package/dist/modules/text/index.js +8 -0
- package/dist/modules/text/split.cjs +488 -0
- package/dist/modules/text/split.d.ts +62 -0
- package/dist/modules/text/split.js +484 -0
- package/dist/modules/timeline/index.cjs +15 -0
- package/dist/modules/timeline/index.d.ts +1 -0
- package/dist/modules/timeline/index.js +8 -0
- package/dist/modules/timeline/position.cjs +72 -0
- package/dist/modules/timeline/position.d.ts +3 -0
- package/dist/modules/timeline/position.js +70 -0
- package/dist/modules/timeline/timeline.cjs +312 -0
- package/dist/modules/timeline/timeline.d.ts +163 -0
- package/dist/modules/timeline/timeline.js +309 -0
- package/dist/modules/timer/index.cjs +15 -0
- package/dist/modules/timer/index.d.ts +1 -0
- package/dist/modules/timer/index.js +8 -0
- package/dist/modules/timer/timer.cjs +491 -0
- package/dist/modules/timer/timer.d.ts +141 -0
- package/dist/modules/timer/timer.js +488 -0
- package/dist/modules/types/index.d.ts +387 -0
- package/dist/modules/utils/chainable.cjs +190 -0
- package/dist/modules/utils/chainable.d.ts +135 -0
- package/dist/modules/utils/chainable.js +177 -0
- package/dist/modules/utils/index.cjs +43 -0
- package/dist/modules/utils/index.d.ts +5 -0
- package/dist/modules/utils/index.js +14 -0
- package/dist/modules/utils/number.cjs +97 -0
- package/dist/modules/utils/number.d.ts +9 -0
- package/dist/modules/utils/number.js +85 -0
- package/dist/modules/utils/random.cjs +77 -0
- package/dist/modules/utils/random.d.ts +22 -0
- package/dist/modules/utils/random.js +72 -0
- package/dist/modules/utils/stagger.cjs +122 -0
- package/dist/modules/utils/stagger.d.ts +30 -0
- package/dist/modules/utils/stagger.js +120 -0
- package/dist/modules/utils/target.cjs +130 -0
- package/dist/modules/utils/target.d.ts +126 -0
- package/dist/modules/utils/target.js +125 -0
- package/dist/modules/utils/time.cjs +57 -0
- package/dist/modules/utils/time.d.ts +5 -0
- package/dist/modules/utils/time.js +54 -0
- package/dist/modules/waapi/composition.cjs +89 -0
- package/dist/modules/waapi/composition.d.ts +4 -0
- package/dist/modules/waapi/composition.js +86 -0
- package/dist/modules/waapi/index.cjs +15 -0
- package/dist/modules/waapi/index.d.ts +1 -0
- package/dist/modules/waapi/index.js +8 -0
- package/dist/modules/waapi/waapi.cjs +473 -0
- package/dist/modules/waapi/waapi.d.ts +114 -0
- package/dist/modules/waapi/waapi.js +470 -0
- package/package.json +130 -33
- package/lib/anime.cjs +0 -9
- package/lib/anime.esm.min.js +0 -9
- package/lib/anime.iife.js +0 -9
- package/lib/anime.iife.min.js +0 -9
- package/lib/anime.min.cjs +0 -9
- package/lib/anime.umd.js +0 -9
- package/lib/anime.umd.min.js +0 -9
- package/lib/gui/index.js +0 -6341
- package/types/index.d.ts +0 -1126
- package/types/index.js +0 -7388
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - core - CJS
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var consts = require('./consts.cjs');
|
|
11
|
+
var helpers = require('./helpers.cjs');
|
|
12
|
+
var transforms = require('./transforms.cjs');
|
|
13
|
+
var colors = require('./colors.cjs');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @import {
|
|
17
|
+
* Target,
|
|
18
|
+
* DOMTarget,
|
|
19
|
+
* Tween,
|
|
20
|
+
* TweenPropValue,
|
|
21
|
+
* TweenDecomposedValue,
|
|
22
|
+
* } from '../types/index.js'
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @template T, D
|
|
27
|
+
* @param {T|undefined} targetValue
|
|
28
|
+
* @param {D} defaultValue
|
|
29
|
+
* @return {T|D}
|
|
30
|
+
*/
|
|
31
|
+
const setValue = (targetValue, defaultValue) => {
|
|
32
|
+
return helpers.isUnd(targetValue) ? defaultValue : targetValue;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {TweenPropValue} value
|
|
37
|
+
* @param {Target} target
|
|
38
|
+
* @param {Number} index
|
|
39
|
+
* @param {Number} total
|
|
40
|
+
* @param {Object} [store]
|
|
41
|
+
* @return {any}
|
|
42
|
+
*/
|
|
43
|
+
const getFunctionValue = (value, target, index, total, store) => {
|
|
44
|
+
if (helpers.isFnc(value)) {
|
|
45
|
+
const func = () => {
|
|
46
|
+
const computed = /** @type {Function} */(value)(target, index, total);
|
|
47
|
+
// Fallback to 0 if the function returns undefined / NaN / null / false / 0
|
|
48
|
+
return !isNaN(+computed) ? +computed : computed || 0;
|
|
49
|
+
};
|
|
50
|
+
if (store) {
|
|
51
|
+
store.func = func;
|
|
52
|
+
}
|
|
53
|
+
return func();
|
|
54
|
+
} else {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {Target} target
|
|
61
|
+
* @param {String} prop
|
|
62
|
+
* @return {tweenTypes}
|
|
63
|
+
*/
|
|
64
|
+
const getTweenType = (target, prop) => {
|
|
65
|
+
return !target[consts.isDomSymbol] ? consts.tweenTypes.OBJECT :
|
|
66
|
+
// Handle SVG attributes
|
|
67
|
+
target[consts.isSvgSymbol] && helpers.isValidSVGAttribute(target, prop) ? consts.tweenTypes.ATTRIBUTE :
|
|
68
|
+
// Handle CSS Transform properties differently than CSS to allow individual animations
|
|
69
|
+
consts.validTransforms.includes(prop) || consts.shortTransforms.get(prop) ? consts.tweenTypes.TRANSFORM :
|
|
70
|
+
// CSS variables
|
|
71
|
+
helpers.stringStartsWith(prop, '--') ? consts.tweenTypes.CSS_VAR :
|
|
72
|
+
// All other CSS properties
|
|
73
|
+
prop in /** @type {DOMTarget} */(target).style ? consts.tweenTypes.CSS :
|
|
74
|
+
// Handle other DOM Attributes
|
|
75
|
+
prop in target ? consts.tweenTypes.OBJECT :
|
|
76
|
+
consts.tweenTypes.ATTRIBUTE;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {DOMTarget} target
|
|
81
|
+
* @param {String} propName
|
|
82
|
+
* @param {Object} animationInlineStyles
|
|
83
|
+
* @return {String}
|
|
84
|
+
*/
|
|
85
|
+
const getCSSValue = (target, propName, animationInlineStyles) => {
|
|
86
|
+
const inlineStyles = target.style[propName];
|
|
87
|
+
if (inlineStyles && animationInlineStyles) {
|
|
88
|
+
animationInlineStyles[propName] = inlineStyles;
|
|
89
|
+
}
|
|
90
|
+
const value = inlineStyles || getComputedStyle(target[consts.proxyTargetSymbol] || target).getPropertyValue(propName);
|
|
91
|
+
return value === 'auto' ? '0' : value;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {Target} target
|
|
96
|
+
* @param {String} propName
|
|
97
|
+
* @param {tweenTypes} [tweenType]
|
|
98
|
+
* @param {Object|void} [animationInlineStyles]
|
|
99
|
+
* @return {String|Number}
|
|
100
|
+
*/
|
|
101
|
+
const getOriginalAnimatableValue = (target, propName, tweenType, animationInlineStyles) => {
|
|
102
|
+
const type = !helpers.isUnd(tweenType) ? tweenType : getTweenType(target, propName);
|
|
103
|
+
return type === consts.tweenTypes.OBJECT ? target[propName] || 0 :
|
|
104
|
+
type === consts.tweenTypes.ATTRIBUTE ? /** @type {DOMTarget} */(target).getAttribute(propName) :
|
|
105
|
+
type === consts.tweenTypes.TRANSFORM ? transforms.parseInlineTransforms(/** @type {DOMTarget} */(target), propName, animationInlineStyles) :
|
|
106
|
+
type === consts.tweenTypes.CSS_VAR ? getCSSValue(/** @type {DOMTarget} */(target), propName, animationInlineStyles).trimStart() :
|
|
107
|
+
getCSSValue(/** @type {DOMTarget} */(target), propName, animationInlineStyles);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {Number} x
|
|
112
|
+
* @param {Number} y
|
|
113
|
+
* @param {String} operator
|
|
114
|
+
* @return {Number}
|
|
115
|
+
*/
|
|
116
|
+
const getRelativeValue = (x, y, operator) => {
|
|
117
|
+
return operator === '-' ? x - y :
|
|
118
|
+
operator === '+' ? x + y :
|
|
119
|
+
x * y;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** @return {TweenDecomposedValue} */
|
|
123
|
+
const createDecomposedValueTargetObject = () => {
|
|
124
|
+
return {
|
|
125
|
+
/** @type {valueTypes} */
|
|
126
|
+
t: consts.valueTypes.NUMBER,
|
|
127
|
+
n: 0,
|
|
128
|
+
u: null,
|
|
129
|
+
o: null,
|
|
130
|
+
d: null,
|
|
131
|
+
s: null,
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {String|Number} rawValue
|
|
137
|
+
* @param {TweenDecomposedValue} targetObject
|
|
138
|
+
* @return {TweenDecomposedValue}
|
|
139
|
+
*/
|
|
140
|
+
const decomposeRawValue = (rawValue, targetObject) => {
|
|
141
|
+
/** @type {valueTypes} */
|
|
142
|
+
targetObject.t = consts.valueTypes.NUMBER;
|
|
143
|
+
targetObject.n = 0;
|
|
144
|
+
targetObject.u = null;
|
|
145
|
+
targetObject.o = null;
|
|
146
|
+
targetObject.d = null;
|
|
147
|
+
targetObject.s = null;
|
|
148
|
+
if (!rawValue) return targetObject;
|
|
149
|
+
const num = +rawValue;
|
|
150
|
+
if (!isNaN(num)) {
|
|
151
|
+
// It's a number
|
|
152
|
+
targetObject.n = num;
|
|
153
|
+
return targetObject;
|
|
154
|
+
} else {
|
|
155
|
+
// let str = /** @type {String} */(rawValue).trim();
|
|
156
|
+
let str = /** @type {String} */(rawValue);
|
|
157
|
+
// Parsing operators (+=, -=, *=) manually is much faster than using regex here
|
|
158
|
+
if (str[1] === '=') {
|
|
159
|
+
targetObject.o = str[0];
|
|
160
|
+
str = str.slice(2);
|
|
161
|
+
}
|
|
162
|
+
// Skip exec regex if the value type is complex or color to avoid long regex backtracking
|
|
163
|
+
const unitMatch = str.includes(' ') ? false : consts.unitsExecRgx.exec(str);
|
|
164
|
+
if (unitMatch) {
|
|
165
|
+
// Has a number and a unit
|
|
166
|
+
targetObject.t = consts.valueTypes.UNIT;
|
|
167
|
+
targetObject.n = +unitMatch[1];
|
|
168
|
+
targetObject.u = unitMatch[2];
|
|
169
|
+
return targetObject;
|
|
170
|
+
} else if (targetObject.o) {
|
|
171
|
+
// Has an operator (+=, -=, *=)
|
|
172
|
+
targetObject.n = +str;
|
|
173
|
+
return targetObject;
|
|
174
|
+
} else if (helpers.isCol(str)) {
|
|
175
|
+
// Is a color
|
|
176
|
+
targetObject.t = consts.valueTypes.COLOR;
|
|
177
|
+
targetObject.d = colors.convertColorStringValuesToRgbaArray(str);
|
|
178
|
+
return targetObject;
|
|
179
|
+
} else {
|
|
180
|
+
// Is a more complex string (generally svg coords, calc() or filters CSS values)
|
|
181
|
+
const matchedNumbers = str.match(consts.digitWithExponentRgx);
|
|
182
|
+
targetObject.t = consts.valueTypes.COMPLEX;
|
|
183
|
+
targetObject.d = matchedNumbers ? matchedNumbers.map(Number) : [];
|
|
184
|
+
targetObject.s = str.split(consts.digitWithExponentRgx) || [];
|
|
185
|
+
return targetObject;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @param {Tween} tween
|
|
192
|
+
* @param {TweenDecomposedValue} targetObject
|
|
193
|
+
* @return {TweenDecomposedValue}
|
|
194
|
+
*/
|
|
195
|
+
const decomposeTweenValue = (tween, targetObject) => {
|
|
196
|
+
targetObject.t = tween._valueType;
|
|
197
|
+
targetObject.n = tween._toNumber;
|
|
198
|
+
targetObject.u = tween._unit;
|
|
199
|
+
targetObject.o = null;
|
|
200
|
+
targetObject.d = helpers.cloneArray(tween._toNumbers);
|
|
201
|
+
targetObject.s = helpers.cloneArray(tween._strings);
|
|
202
|
+
return targetObject;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const decomposedOriginalValue = createDecomposedValueTargetObject();
|
|
206
|
+
|
|
207
|
+
exports.createDecomposedValueTargetObject = createDecomposedValueTargetObject;
|
|
208
|
+
exports.decomposeRawValue = decomposeRawValue;
|
|
209
|
+
exports.decomposeTweenValue = decomposeTweenValue;
|
|
210
|
+
exports.decomposedOriginalValue = decomposedOriginalValue;
|
|
211
|
+
exports.getFunctionValue = getFunctionValue;
|
|
212
|
+
exports.getOriginalAnimatableValue = getOriginalAnimatableValue;
|
|
213
|
+
exports.getRelativeValue = getRelativeValue;
|
|
214
|
+
exports.getTweenType = getTweenType;
|
|
215
|
+
exports.setValue = setValue;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function setValue<T, D>(targetValue: T | undefined, defaultValue: D): T | D;
|
|
2
|
+
export function getFunctionValue(value: TweenPropValue, target: Target, index: number, total: number, store?: any): any;
|
|
3
|
+
export function getTweenType(target: Target, prop: string): tweenTypes;
|
|
4
|
+
export function getOriginalAnimatableValue(target: Target, propName: string, tweenType?: tweenTypes, animationInlineStyles?: any | void): string | number;
|
|
5
|
+
export function getRelativeValue(x: number, y: number, operator: string): number;
|
|
6
|
+
export function createDecomposedValueTargetObject(): TweenDecomposedValue;
|
|
7
|
+
export function decomposeRawValue(rawValue: string | number, targetObject: TweenDecomposedValue): TweenDecomposedValue;
|
|
8
|
+
export function decomposeTweenValue(tween: Tween, targetObject: TweenDecomposedValue): TweenDecomposedValue;
|
|
9
|
+
export const decomposedOriginalValue: TweenDecomposedValue;
|
|
10
|
+
import type { TweenPropValue } from '../types/index.js';
|
|
11
|
+
import type { Target } from '../types/index.js';
|
|
12
|
+
import { tweenTypes } from './consts.js';
|
|
13
|
+
import type { TweenDecomposedValue } from '../types/index.js';
|
|
14
|
+
import type { Tween } from '../types/index.js';
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - core - ESM
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { tweenTypes, isDomSymbol, isSvgSymbol, validTransforms, shortTransforms, valueTypes, unitsExecRgx, digitWithExponentRgx, proxyTargetSymbol } from './consts.js';
|
|
9
|
+
import { isValidSVGAttribute, stringStartsWith, isUnd, isCol, isFnc, cloneArray } from './helpers.js';
|
|
10
|
+
import { parseInlineTransforms } from './transforms.js';
|
|
11
|
+
import { convertColorStringValuesToRgbaArray } from './colors.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @import {
|
|
15
|
+
* Target,
|
|
16
|
+
* DOMTarget,
|
|
17
|
+
* Tween,
|
|
18
|
+
* TweenPropValue,
|
|
19
|
+
* TweenDecomposedValue,
|
|
20
|
+
* } from '../types/index.js'
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @template T, D
|
|
25
|
+
* @param {T|undefined} targetValue
|
|
26
|
+
* @param {D} defaultValue
|
|
27
|
+
* @return {T|D}
|
|
28
|
+
*/
|
|
29
|
+
const setValue = (targetValue, defaultValue) => {
|
|
30
|
+
return isUnd(targetValue) ? defaultValue : targetValue;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {TweenPropValue} value
|
|
35
|
+
* @param {Target} target
|
|
36
|
+
* @param {Number} index
|
|
37
|
+
* @param {Number} total
|
|
38
|
+
* @param {Object} [store]
|
|
39
|
+
* @return {any}
|
|
40
|
+
*/
|
|
41
|
+
const getFunctionValue = (value, target, index, total, store) => {
|
|
42
|
+
if (isFnc(value)) {
|
|
43
|
+
const func = () => {
|
|
44
|
+
const computed = /** @type {Function} */(value)(target, index, total);
|
|
45
|
+
// Fallback to 0 if the function returns undefined / NaN / null / false / 0
|
|
46
|
+
return !isNaN(+computed) ? +computed : computed || 0;
|
|
47
|
+
};
|
|
48
|
+
if (store) {
|
|
49
|
+
store.func = func;
|
|
50
|
+
}
|
|
51
|
+
return func();
|
|
52
|
+
} else {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {Target} target
|
|
59
|
+
* @param {String} prop
|
|
60
|
+
* @return {tweenTypes}
|
|
61
|
+
*/
|
|
62
|
+
const getTweenType = (target, prop) => {
|
|
63
|
+
return !target[isDomSymbol] ? tweenTypes.OBJECT :
|
|
64
|
+
// Handle SVG attributes
|
|
65
|
+
target[isSvgSymbol] && isValidSVGAttribute(target, prop) ? tweenTypes.ATTRIBUTE :
|
|
66
|
+
// Handle CSS Transform properties differently than CSS to allow individual animations
|
|
67
|
+
validTransforms.includes(prop) || shortTransforms.get(prop) ? tweenTypes.TRANSFORM :
|
|
68
|
+
// CSS variables
|
|
69
|
+
stringStartsWith(prop, '--') ? tweenTypes.CSS_VAR :
|
|
70
|
+
// All other CSS properties
|
|
71
|
+
prop in /** @type {DOMTarget} */(target).style ? tweenTypes.CSS :
|
|
72
|
+
// Handle other DOM Attributes
|
|
73
|
+
prop in target ? tweenTypes.OBJECT :
|
|
74
|
+
tweenTypes.ATTRIBUTE;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {DOMTarget} target
|
|
79
|
+
* @param {String} propName
|
|
80
|
+
* @param {Object} animationInlineStyles
|
|
81
|
+
* @return {String}
|
|
82
|
+
*/
|
|
83
|
+
const getCSSValue = (target, propName, animationInlineStyles) => {
|
|
84
|
+
const inlineStyles = target.style[propName];
|
|
85
|
+
if (inlineStyles && animationInlineStyles) {
|
|
86
|
+
animationInlineStyles[propName] = inlineStyles;
|
|
87
|
+
}
|
|
88
|
+
const value = inlineStyles || getComputedStyle(target[proxyTargetSymbol] || target).getPropertyValue(propName);
|
|
89
|
+
return value === 'auto' ? '0' : value;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param {Target} target
|
|
94
|
+
* @param {String} propName
|
|
95
|
+
* @param {tweenTypes} [tweenType]
|
|
96
|
+
* @param {Object|void} [animationInlineStyles]
|
|
97
|
+
* @return {String|Number}
|
|
98
|
+
*/
|
|
99
|
+
const getOriginalAnimatableValue = (target, propName, tweenType, animationInlineStyles) => {
|
|
100
|
+
const type = !isUnd(tweenType) ? tweenType : getTweenType(target, propName);
|
|
101
|
+
return type === tweenTypes.OBJECT ? target[propName] || 0 :
|
|
102
|
+
type === tweenTypes.ATTRIBUTE ? /** @type {DOMTarget} */(target).getAttribute(propName) :
|
|
103
|
+
type === tweenTypes.TRANSFORM ? parseInlineTransforms(/** @type {DOMTarget} */(target), propName, animationInlineStyles) :
|
|
104
|
+
type === tweenTypes.CSS_VAR ? getCSSValue(/** @type {DOMTarget} */(target), propName, animationInlineStyles).trimStart() :
|
|
105
|
+
getCSSValue(/** @type {DOMTarget} */(target), propName, animationInlineStyles);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param {Number} x
|
|
110
|
+
* @param {Number} y
|
|
111
|
+
* @param {String} operator
|
|
112
|
+
* @return {Number}
|
|
113
|
+
*/
|
|
114
|
+
const getRelativeValue = (x, y, operator) => {
|
|
115
|
+
return operator === '-' ? x - y :
|
|
116
|
+
operator === '+' ? x + y :
|
|
117
|
+
x * y;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** @return {TweenDecomposedValue} */
|
|
121
|
+
const createDecomposedValueTargetObject = () => {
|
|
122
|
+
return {
|
|
123
|
+
/** @type {valueTypes} */
|
|
124
|
+
t: valueTypes.NUMBER,
|
|
125
|
+
n: 0,
|
|
126
|
+
u: null,
|
|
127
|
+
o: null,
|
|
128
|
+
d: null,
|
|
129
|
+
s: null,
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @param {String|Number} rawValue
|
|
135
|
+
* @param {TweenDecomposedValue} targetObject
|
|
136
|
+
* @return {TweenDecomposedValue}
|
|
137
|
+
*/
|
|
138
|
+
const decomposeRawValue = (rawValue, targetObject) => {
|
|
139
|
+
/** @type {valueTypes} */
|
|
140
|
+
targetObject.t = valueTypes.NUMBER;
|
|
141
|
+
targetObject.n = 0;
|
|
142
|
+
targetObject.u = null;
|
|
143
|
+
targetObject.o = null;
|
|
144
|
+
targetObject.d = null;
|
|
145
|
+
targetObject.s = null;
|
|
146
|
+
if (!rawValue) return targetObject;
|
|
147
|
+
const num = +rawValue;
|
|
148
|
+
if (!isNaN(num)) {
|
|
149
|
+
// It's a number
|
|
150
|
+
targetObject.n = num;
|
|
151
|
+
return targetObject;
|
|
152
|
+
} else {
|
|
153
|
+
// let str = /** @type {String} */(rawValue).trim();
|
|
154
|
+
let str = /** @type {String} */(rawValue);
|
|
155
|
+
// Parsing operators (+=, -=, *=) manually is much faster than using regex here
|
|
156
|
+
if (str[1] === '=') {
|
|
157
|
+
targetObject.o = str[0];
|
|
158
|
+
str = str.slice(2);
|
|
159
|
+
}
|
|
160
|
+
// Skip exec regex if the value type is complex or color to avoid long regex backtracking
|
|
161
|
+
const unitMatch = str.includes(' ') ? false : unitsExecRgx.exec(str);
|
|
162
|
+
if (unitMatch) {
|
|
163
|
+
// Has a number and a unit
|
|
164
|
+
targetObject.t = valueTypes.UNIT;
|
|
165
|
+
targetObject.n = +unitMatch[1];
|
|
166
|
+
targetObject.u = unitMatch[2];
|
|
167
|
+
return targetObject;
|
|
168
|
+
} else if (targetObject.o) {
|
|
169
|
+
// Has an operator (+=, -=, *=)
|
|
170
|
+
targetObject.n = +str;
|
|
171
|
+
return targetObject;
|
|
172
|
+
} else if (isCol(str)) {
|
|
173
|
+
// Is a color
|
|
174
|
+
targetObject.t = valueTypes.COLOR;
|
|
175
|
+
targetObject.d = convertColorStringValuesToRgbaArray(str);
|
|
176
|
+
return targetObject;
|
|
177
|
+
} else {
|
|
178
|
+
// Is a more complex string (generally svg coords, calc() or filters CSS values)
|
|
179
|
+
const matchedNumbers = str.match(digitWithExponentRgx);
|
|
180
|
+
targetObject.t = valueTypes.COMPLEX;
|
|
181
|
+
targetObject.d = matchedNumbers ? matchedNumbers.map(Number) : [];
|
|
182
|
+
targetObject.s = str.split(digitWithExponentRgx) || [];
|
|
183
|
+
return targetObject;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @param {Tween} tween
|
|
190
|
+
* @param {TweenDecomposedValue} targetObject
|
|
191
|
+
* @return {TweenDecomposedValue}
|
|
192
|
+
*/
|
|
193
|
+
const decomposeTweenValue = (tween, targetObject) => {
|
|
194
|
+
targetObject.t = tween._valueType;
|
|
195
|
+
targetObject.n = tween._toNumber;
|
|
196
|
+
targetObject.u = tween._unit;
|
|
197
|
+
targetObject.o = null;
|
|
198
|
+
targetObject.d = cloneArray(tween._toNumbers);
|
|
199
|
+
targetObject.s = cloneArray(tween._strings);
|
|
200
|
+
return targetObject;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const decomposedOriginalValue = createDecomposedValueTargetObject();
|
|
204
|
+
|
|
205
|
+
export { createDecomposedValueTargetObject, decomposeRawValue, decomposeTweenValue, decomposedOriginalValue, getFunctionValue, getOriginalAnimatableValue, getRelativeValue, getTweenType, setValue };
|