animejs 4.1.4 → 4.2.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 +17 -8
- package/{lib → dist/bundles}/anime.esm.js +6476 -6106
- package/dist/bundles/anime.esm.min.js +7 -0
- package/dist/bundles/anime.umd.js +8809 -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 +667 -0
- package/dist/modules/animation/animation.d.ts +45 -0
- package/dist/modules/animation/animation.js +664 -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 +159 -0
- package/dist/modules/core/consts.d.ts +61 -0
- package/dist/modules/core/consts.js +124 -0
- package/dist/modules/core/globals.cjs +78 -0
- package/dist/modules/core/globals.d.ts +29 -0
- package/dist/modules/core/globals.js +73 -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 +391 -0
- package/dist/modules/core/render.d.ts +4 -0
- package/dist/modules/core/render.js +388 -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 +226 -0
- package/dist/modules/core/values.d.ts +14 -0
- package/dist/modules/core/values.js +216 -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/index.cjs +64 -0
- package/dist/modules/easings/cubic-bezier/index.d.ts +2 -0
- package/dist/modules/easings/cubic-bezier/index.js +62 -0
- package/dist/modules/easings/eases/index.cjs +14 -0
- package/dist/modules/easings/eases/index.d.ts +1 -0
- package/dist/modules/easings/eases/index.js +8 -0
- package/dist/modules/easings/eases/parser.cjs +191 -0
- package/dist/modules/easings/eases/parser.d.ts +125 -0
- package/dist/modules/easings/eases/parser.js +185 -0
- package/dist/modules/easings/index.cjs +26 -0
- package/dist/modules/easings/index.d.ts +6 -0
- package/dist/modules/easings/index.js +13 -0
- package/dist/modules/easings/irregular/index.cjs +41 -0
- package/dist/modules/easings/irregular/index.d.ts +2 -0
- package/dist/modules/easings/irregular/index.js +39 -0
- package/dist/modules/easings/linear/index.cjs +59 -0
- package/dist/modules/easings/linear/index.d.ts +2 -0
- package/dist/modules/easings/linear/index.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/spring/index.cjs +255 -0
- package/dist/modules/easings/spring/index.d.ts +53 -0
- package/dist/modules/easings/spring/index.js +251 -0
- package/dist/modules/easings/steps/index.cjs +30 -0
- package/dist/modules/easings/steps/index.d.ts +2 -0
- package/dist/modules/easings/steps/index.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 +940 -0
- package/dist/modules/events/scroll.d.ts +191 -0
- package/dist/modules/events/scroll.js +936 -0
- package/dist/modules/index.cjs +102 -0
- package/dist/modules/index.d.ts +18 -0
- package/dist/modules/index.js +41 -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/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 +404 -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 +95 -0
- package/dist/modules/waapi/composition.d.ts +4 -0
- package/dist/modules/waapi/composition.js +92 -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 +492 -0
- package/dist/modules/waapi/waapi.d.ts +116 -0
- package/dist/modules/waapi/waapi.js +489 -0
- package/package.json +166 -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 -1127
- package/types/index.js +0 -7395
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - scope - ESM
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { doc, win } from '../core/consts.js';
|
|
9
|
+
import { globals, scope } from '../core/globals.js';
|
|
10
|
+
import { mergeObjects, isFnc } from '../core/helpers.js';
|
|
11
|
+
import { parseTargets } from '../core/targets.js';
|
|
12
|
+
import { keepTime } from '../utils/time.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @import {
|
|
16
|
+
* Tickable,
|
|
17
|
+
* ScopeParams,
|
|
18
|
+
* DOMTarget,
|
|
19
|
+
* ReactRef,
|
|
20
|
+
* AngularRef,
|
|
21
|
+
* DOMTargetSelector,
|
|
22
|
+
* DefaultsParams,
|
|
23
|
+
* ScopeConstructorCallback,
|
|
24
|
+
* ScopeCleanupCallback,
|
|
25
|
+
* Revertible,
|
|
26
|
+
* ScopeMethod,
|
|
27
|
+
* ScopedCallback,
|
|
28
|
+
* } from '../types/index.js'
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
class Scope {
|
|
32
|
+
/** @param {ScopeParams} [parameters] */
|
|
33
|
+
constructor(parameters = {}) {
|
|
34
|
+
if (scope.current) scope.current.register(this);
|
|
35
|
+
const rootParam = parameters.root;
|
|
36
|
+
/** @type {Document|DOMTarget} */
|
|
37
|
+
let root = doc;
|
|
38
|
+
if (rootParam) {
|
|
39
|
+
root = /** @type {ReactRef} */(rootParam).current ||
|
|
40
|
+
/** @type {AngularRef} */(rootParam).nativeElement ||
|
|
41
|
+
parseTargets(/** @type {DOMTargetSelector} */(rootParam))[0] ||
|
|
42
|
+
doc;
|
|
43
|
+
}
|
|
44
|
+
const scopeDefaults = parameters.defaults;
|
|
45
|
+
const globalDefault = globals.defaults;
|
|
46
|
+
const mediaQueries = parameters.mediaQueries;
|
|
47
|
+
/** @type {DefaultsParams} */
|
|
48
|
+
this.defaults = scopeDefaults ? mergeObjects(scopeDefaults, globalDefault) : globalDefault;
|
|
49
|
+
/** @type {Document|DOMTarget} */
|
|
50
|
+
this.root = root;
|
|
51
|
+
/** @type {Array<ScopeConstructorCallback>} */
|
|
52
|
+
this.constructors = [];
|
|
53
|
+
/** @type {Array<ScopeCleanupCallback>} */
|
|
54
|
+
this.revertConstructors = [];
|
|
55
|
+
/** @type {Array<Revertible>} */
|
|
56
|
+
this.revertibles = [];
|
|
57
|
+
/** @type {Array<ScopeConstructorCallback | ((scope: this) => Tickable)>} */
|
|
58
|
+
this.constructorsOnce = [];
|
|
59
|
+
/** @type {Array<ScopeCleanupCallback>} */
|
|
60
|
+
this.revertConstructorsOnce = [];
|
|
61
|
+
/** @type {Array<Revertible>} */
|
|
62
|
+
this.revertiblesOnce = [];
|
|
63
|
+
/** @type {Boolean} */
|
|
64
|
+
this.once = false;
|
|
65
|
+
/** @type {Number} */
|
|
66
|
+
this.onceIndex = 0;
|
|
67
|
+
/** @type {Record<String, ScopeMethod>} */
|
|
68
|
+
this.methods = {};
|
|
69
|
+
/** @type {Record<String, Boolean>} */
|
|
70
|
+
this.matches = {};
|
|
71
|
+
/** @type {Record<String, MediaQueryList>} */
|
|
72
|
+
this.mediaQueryLists = {};
|
|
73
|
+
/** @type {Record<String, any>} */
|
|
74
|
+
this.data = {};
|
|
75
|
+
if (mediaQueries) {
|
|
76
|
+
for (let mq in mediaQueries) {
|
|
77
|
+
const _mq = win.matchMedia(mediaQueries[mq]);
|
|
78
|
+
this.mediaQueryLists[mq] = _mq;
|
|
79
|
+
_mq.addEventListener('change', this);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {Revertible} revertible
|
|
86
|
+
*/
|
|
87
|
+
register(revertible) {
|
|
88
|
+
const store = this.once ? this.revertiblesOnce : this.revertibles;
|
|
89
|
+
store.push(revertible);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @template T
|
|
94
|
+
* @param {ScopedCallback<T>} cb
|
|
95
|
+
* @return {T}
|
|
96
|
+
*/
|
|
97
|
+
execute(cb) {
|
|
98
|
+
let activeScope = scope.current;
|
|
99
|
+
let activeRoot = scope.root;
|
|
100
|
+
let activeDefaults = globals.defaults;
|
|
101
|
+
scope.current = this;
|
|
102
|
+
scope.root = this.root;
|
|
103
|
+
globals.defaults = this.defaults;
|
|
104
|
+
const mqs = this.mediaQueryLists;
|
|
105
|
+
for (let mq in mqs) this.matches[mq] = mqs[mq].matches;
|
|
106
|
+
const returned = cb(this);
|
|
107
|
+
scope.current = activeScope;
|
|
108
|
+
scope.root = activeRoot;
|
|
109
|
+
globals.defaults = activeDefaults;
|
|
110
|
+
return returned;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @return {this}
|
|
115
|
+
*/
|
|
116
|
+
refresh() {
|
|
117
|
+
this.onceIndex = 0;
|
|
118
|
+
this.execute(() => {
|
|
119
|
+
let i = this.revertibles.length;
|
|
120
|
+
let y = this.revertConstructors.length;
|
|
121
|
+
while (i--) this.revertibles[i].revert();
|
|
122
|
+
while (y--) this.revertConstructors[y](this);
|
|
123
|
+
this.revertibles.length = 0;
|
|
124
|
+
this.revertConstructors.length = 0;
|
|
125
|
+
this.constructors.forEach((/** @type {ScopeConstructorCallback} */constructor) => {
|
|
126
|
+
const revertConstructor = constructor(this);
|
|
127
|
+
if (isFnc(revertConstructor)) {
|
|
128
|
+
this.revertConstructors.push(revertConstructor);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @overload
|
|
137
|
+
* @param {String} a1
|
|
138
|
+
* @param {ScopeMethod} a2
|
|
139
|
+
* @return {this}
|
|
140
|
+
*
|
|
141
|
+
* @overload
|
|
142
|
+
* @param {ScopeConstructorCallback} a1
|
|
143
|
+
* @return {this}
|
|
144
|
+
*
|
|
145
|
+
* @param {String|ScopeConstructorCallback} a1
|
|
146
|
+
* @param {ScopeMethod} [a2]
|
|
147
|
+
*/
|
|
148
|
+
add(a1, a2) {
|
|
149
|
+
this.once = false;
|
|
150
|
+
if (isFnc(a1)) {
|
|
151
|
+
const constructor = /** @type {ScopeConstructorCallback} */(a1);
|
|
152
|
+
this.constructors.push(constructor);
|
|
153
|
+
this.execute(() => {
|
|
154
|
+
const revertConstructor = constructor(this);
|
|
155
|
+
if (isFnc(revertConstructor)) {
|
|
156
|
+
this.revertConstructors.push(revertConstructor);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
this.methods[/** @type {String} */(a1)] = (/** @type {any} */...args) => this.execute(() => a2(...args));
|
|
161
|
+
}
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @param {ScopeConstructorCallback} scopeConstructorCallback
|
|
167
|
+
* @return {this}
|
|
168
|
+
*/
|
|
169
|
+
addOnce(scopeConstructorCallback) {
|
|
170
|
+
this.once = true;
|
|
171
|
+
if (isFnc(scopeConstructorCallback)) {
|
|
172
|
+
const currentIndex = this.onceIndex++;
|
|
173
|
+
const tracked = this.constructorsOnce[currentIndex];
|
|
174
|
+
if (tracked) return this;
|
|
175
|
+
const constructor = /** @type {ScopeConstructorCallback} */(scopeConstructorCallback);
|
|
176
|
+
this.constructorsOnce[currentIndex] = constructor;
|
|
177
|
+
this.execute(() => {
|
|
178
|
+
const revertConstructor = constructor(this);
|
|
179
|
+
if (isFnc(revertConstructor)) {
|
|
180
|
+
this.revertConstructorsOnce.push(revertConstructor);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @param {(scope: this) => Tickable} cb
|
|
189
|
+
* @return {Tickable}
|
|
190
|
+
*/
|
|
191
|
+
keepTime(cb) {
|
|
192
|
+
this.once = true;
|
|
193
|
+
const currentIndex = this.onceIndex++;
|
|
194
|
+
const tracked = /** @type {(scope: this) => Tickable} */(this.constructorsOnce[currentIndex]);
|
|
195
|
+
if (isFnc(tracked)) return tracked(this);
|
|
196
|
+
const constructor = /** @type {(scope: this) => Tickable} */(keepTime(cb));
|
|
197
|
+
this.constructorsOnce[currentIndex] = constructor;
|
|
198
|
+
let trackedTickable;
|
|
199
|
+
this.execute(() => {
|
|
200
|
+
trackedTickable = constructor(this);
|
|
201
|
+
});
|
|
202
|
+
return trackedTickable;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @param {Event} e
|
|
207
|
+
*/
|
|
208
|
+
handleEvent(e) {
|
|
209
|
+
switch (e.type) {
|
|
210
|
+
case 'change':
|
|
211
|
+
this.refresh();
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
revert() {
|
|
217
|
+
const revertibles = this.revertibles;
|
|
218
|
+
const revertConstructors = this.revertConstructors;
|
|
219
|
+
const revertiblesOnce = this.revertiblesOnce;
|
|
220
|
+
const revertConstructorsOnce = this.revertConstructorsOnce;
|
|
221
|
+
const mqs = this.mediaQueryLists;
|
|
222
|
+
let i = revertibles.length;
|
|
223
|
+
let j = revertConstructors.length;
|
|
224
|
+
let k = revertiblesOnce.length;
|
|
225
|
+
let l = revertConstructorsOnce.length;
|
|
226
|
+
while (i--) revertibles[i].revert();
|
|
227
|
+
while (j--) revertConstructors[j](this);
|
|
228
|
+
while (k--) revertiblesOnce[k].revert();
|
|
229
|
+
while (l--) revertConstructorsOnce[l](this);
|
|
230
|
+
for (let mq in mqs) mqs[mq].removeEventListener('change', this);
|
|
231
|
+
revertibles.length = 0;
|
|
232
|
+
revertConstructors.length = 0;
|
|
233
|
+
this.constructors.length = 0;
|
|
234
|
+
revertiblesOnce.length = 0;
|
|
235
|
+
revertConstructorsOnce.length = 0;
|
|
236
|
+
this.constructorsOnce.length = 0;
|
|
237
|
+
this.onceIndex = 0;
|
|
238
|
+
this.matches = {};
|
|
239
|
+
this.methods = {};
|
|
240
|
+
this.mediaQueryLists = {};
|
|
241
|
+
this.data = {};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @param {ScopeParams} [params]
|
|
247
|
+
* @return {Scope}
|
|
248
|
+
*/
|
|
249
|
+
const createScope = params => new Scope(params);
|
|
250
|
+
|
|
251
|
+
export { Scope, createScope };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - svg - CJS
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var consts = require('../core/consts.cjs');
|
|
11
|
+
var helpers = require('../core/helpers.cjs');
|
|
12
|
+
var targets = require('../core/targets.cjs');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @import {
|
|
16
|
+
* TargetsParam,
|
|
17
|
+
* DrawableSVGGeometry,
|
|
18
|
+
* } from '../types/index.js'
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {SVGGeometryElement} [$el]
|
|
23
|
+
* @return {Number}
|
|
24
|
+
*/
|
|
25
|
+
const getScaleFactor = $el => {
|
|
26
|
+
let scaleFactor = 1;
|
|
27
|
+
if ($el && $el.getCTM) {
|
|
28
|
+
const ctm = $el.getCTM();
|
|
29
|
+
if (ctm) {
|
|
30
|
+
const scaleX = helpers.sqrt(ctm.a * ctm.a + ctm.b * ctm.b);
|
|
31
|
+
const scaleY = helpers.sqrt(ctm.c * ctm.c + ctm.d * ctm.d);
|
|
32
|
+
scaleFactor = (scaleX + scaleY) / 2;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return scaleFactor;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Creates a proxy that wraps an SVGGeometryElement and adds drawing functionality.
|
|
40
|
+
* @param {SVGGeometryElement} $el - The SVG element to transform into a drawable
|
|
41
|
+
* @param {number} start - Starting position (0-1)
|
|
42
|
+
* @param {number} end - Ending position (0-1)
|
|
43
|
+
* @return {DrawableSVGGeometry} - Returns a proxy that preserves the original element's type with additional 'draw' attribute functionality
|
|
44
|
+
*/
|
|
45
|
+
const createDrawableProxy = ($el, start, end) => {
|
|
46
|
+
const pathLength = consts.K;
|
|
47
|
+
const computedStyles = getComputedStyle($el);
|
|
48
|
+
const strokeLineCap = computedStyles.strokeLinecap;
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
const $scalled = computedStyles.vectorEffect === 'non-scaling-stroke' ? $el : null;
|
|
51
|
+
let currentCap = strokeLineCap;
|
|
52
|
+
|
|
53
|
+
const proxy = new Proxy($el, {
|
|
54
|
+
get(target, property) {
|
|
55
|
+
const value = target[property];
|
|
56
|
+
if (property === consts.proxyTargetSymbol) return target;
|
|
57
|
+
if (property === 'setAttribute') {
|
|
58
|
+
return (...args) => {
|
|
59
|
+
if (args[0] === 'draw') {
|
|
60
|
+
const value = args[1];
|
|
61
|
+
const values = value.split(' ');
|
|
62
|
+
const v1 = +values[0];
|
|
63
|
+
const v2 = +values[1];
|
|
64
|
+
// TOTO: Benchmark if performing two slices is more performant than one split
|
|
65
|
+
// const spaceIndex = value.indexOf(' ');
|
|
66
|
+
// const v1 = round(+value.slice(0, spaceIndex), precision);
|
|
67
|
+
// const v2 = round(+value.slice(spaceIndex + 1), precision);
|
|
68
|
+
const scaleFactor = getScaleFactor($scalled);
|
|
69
|
+
const os = v1 * -pathLength * scaleFactor;
|
|
70
|
+
const d1 = (v2 * pathLength * scaleFactor) + os;
|
|
71
|
+
const d2 = (pathLength * scaleFactor +
|
|
72
|
+
((v1 === 0 && v2 === 1) || (v1 === 1 && v2 === 0) ? 0 : 10 * scaleFactor) - d1);
|
|
73
|
+
if (strokeLineCap !== 'butt') {
|
|
74
|
+
const newCap = v1 === v2 ? 'butt' : strokeLineCap;
|
|
75
|
+
if (currentCap !== newCap) {
|
|
76
|
+
target.style.strokeLinecap = `${newCap}`;
|
|
77
|
+
currentCap = newCap;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
target.setAttribute('stroke-dashoffset', `${os}`);
|
|
81
|
+
target.setAttribute('stroke-dasharray', `${d1} ${d2}`);
|
|
82
|
+
}
|
|
83
|
+
return Reflect.apply(value, target, args);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (helpers.isFnc(value)) {
|
|
88
|
+
return (...args) => Reflect.apply(value, target, args);
|
|
89
|
+
} else {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if ($el.getAttribute('pathLength') !== `${pathLength}`) {
|
|
96
|
+
$el.setAttribute('pathLength', `${pathLength}`);
|
|
97
|
+
proxy.setAttribute('draw', `${start} ${end}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return /** @type {DrawableSVGGeometry} */(proxy);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates drawable proxies for multiple SVG elements.
|
|
105
|
+
* @param {TargetsParam} selector - CSS selector, SVG element, or array of elements and selectors
|
|
106
|
+
* @param {number} [start=0] - Starting position (0-1)
|
|
107
|
+
* @param {number} [end=0] - Ending position (0-1)
|
|
108
|
+
* @return {Array<DrawableSVGGeometry>} - Array of proxied elements with drawing functionality
|
|
109
|
+
*/
|
|
110
|
+
const createDrawable = (selector, start = 0, end = 0) => {
|
|
111
|
+
const els = targets.parseTargets(selector);
|
|
112
|
+
return els.map($el => createDrawableProxy(
|
|
113
|
+
/** @type {SVGGeometryElement} */($el),
|
|
114
|
+
start,
|
|
115
|
+
end
|
|
116
|
+
));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
exports.createDrawable = createDrawable;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - svg - ESM
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { proxyTargetSymbol, K } from '../core/consts.js';
|
|
9
|
+
import { isFnc, sqrt } from '../core/helpers.js';
|
|
10
|
+
import { parseTargets } from '../core/targets.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @import {
|
|
14
|
+
* TargetsParam,
|
|
15
|
+
* DrawableSVGGeometry,
|
|
16
|
+
* } from '../types/index.js'
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {SVGGeometryElement} [$el]
|
|
21
|
+
* @return {Number}
|
|
22
|
+
*/
|
|
23
|
+
const getScaleFactor = $el => {
|
|
24
|
+
let scaleFactor = 1;
|
|
25
|
+
if ($el && $el.getCTM) {
|
|
26
|
+
const ctm = $el.getCTM();
|
|
27
|
+
if (ctm) {
|
|
28
|
+
const scaleX = sqrt(ctm.a * ctm.a + ctm.b * ctm.b);
|
|
29
|
+
const scaleY = sqrt(ctm.c * ctm.c + ctm.d * ctm.d);
|
|
30
|
+
scaleFactor = (scaleX + scaleY) / 2;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return scaleFactor;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a proxy that wraps an SVGGeometryElement and adds drawing functionality.
|
|
38
|
+
* @param {SVGGeometryElement} $el - The SVG element to transform into a drawable
|
|
39
|
+
* @param {number} start - Starting position (0-1)
|
|
40
|
+
* @param {number} end - Ending position (0-1)
|
|
41
|
+
* @return {DrawableSVGGeometry} - Returns a proxy that preserves the original element's type with additional 'draw' attribute functionality
|
|
42
|
+
*/
|
|
43
|
+
const createDrawableProxy = ($el, start, end) => {
|
|
44
|
+
const pathLength = K;
|
|
45
|
+
const computedStyles = getComputedStyle($el);
|
|
46
|
+
const strokeLineCap = computedStyles.strokeLinecap;
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
const $scalled = computedStyles.vectorEffect === 'non-scaling-stroke' ? $el : null;
|
|
49
|
+
let currentCap = strokeLineCap;
|
|
50
|
+
|
|
51
|
+
const proxy = new Proxy($el, {
|
|
52
|
+
get(target, property) {
|
|
53
|
+
const value = target[property];
|
|
54
|
+
if (property === proxyTargetSymbol) return target;
|
|
55
|
+
if (property === 'setAttribute') {
|
|
56
|
+
return (...args) => {
|
|
57
|
+
if (args[0] === 'draw') {
|
|
58
|
+
const value = args[1];
|
|
59
|
+
const values = value.split(' ');
|
|
60
|
+
const v1 = +values[0];
|
|
61
|
+
const v2 = +values[1];
|
|
62
|
+
// TOTO: Benchmark if performing two slices is more performant than one split
|
|
63
|
+
// const spaceIndex = value.indexOf(' ');
|
|
64
|
+
// const v1 = round(+value.slice(0, spaceIndex), precision);
|
|
65
|
+
// const v2 = round(+value.slice(spaceIndex + 1), precision);
|
|
66
|
+
const scaleFactor = getScaleFactor($scalled);
|
|
67
|
+
const os = v1 * -pathLength * scaleFactor;
|
|
68
|
+
const d1 = (v2 * pathLength * scaleFactor) + os;
|
|
69
|
+
const d2 = (pathLength * scaleFactor +
|
|
70
|
+
((v1 === 0 && v2 === 1) || (v1 === 1 && v2 === 0) ? 0 : 10 * scaleFactor) - d1);
|
|
71
|
+
if (strokeLineCap !== 'butt') {
|
|
72
|
+
const newCap = v1 === v2 ? 'butt' : strokeLineCap;
|
|
73
|
+
if (currentCap !== newCap) {
|
|
74
|
+
target.style.strokeLinecap = `${newCap}`;
|
|
75
|
+
currentCap = newCap;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
target.setAttribute('stroke-dashoffset', `${os}`);
|
|
79
|
+
target.setAttribute('stroke-dasharray', `${d1} ${d2}`);
|
|
80
|
+
}
|
|
81
|
+
return Reflect.apply(value, target, args);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (isFnc(value)) {
|
|
86
|
+
return (...args) => Reflect.apply(value, target, args);
|
|
87
|
+
} else {
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if ($el.getAttribute('pathLength') !== `${pathLength}`) {
|
|
94
|
+
$el.setAttribute('pathLength', `${pathLength}`);
|
|
95
|
+
proxy.setAttribute('draw', `${start} ${end}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return /** @type {DrawableSVGGeometry} */(proxy);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Creates drawable proxies for multiple SVG elements.
|
|
103
|
+
* @param {TargetsParam} selector - CSS selector, SVG element, or array of elements and selectors
|
|
104
|
+
* @param {number} [start=0] - Starting position (0-1)
|
|
105
|
+
* @param {number} [end=0] - Ending position (0-1)
|
|
106
|
+
* @return {Array<DrawableSVGGeometry>} - Array of proxied elements with drawing functionality
|
|
107
|
+
*/
|
|
108
|
+
const createDrawable = (selector, start = 0, end = 0) => {
|
|
109
|
+
const els = parseTargets(selector);
|
|
110
|
+
return els.map($el => createDrawableProxy(
|
|
111
|
+
/** @type {SVGGeometryElement} */($el),
|
|
112
|
+
start,
|
|
113
|
+
end
|
|
114
|
+
));
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export { createDrawable };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - svg - CJS
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var helpers = require('../core/helpers.cjs');
|
|
11
|
+
var targets = require('../core/targets.cjs');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @import {
|
|
15
|
+
* TargetsParam,
|
|
16
|
+
* } from '../types/index.js'
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {TargetsParam} path
|
|
21
|
+
* @return {SVGGeometryElement|void}
|
|
22
|
+
*/
|
|
23
|
+
const getPath = path => {
|
|
24
|
+
const parsedTargets = targets.parseTargets(path);
|
|
25
|
+
const $parsedSvg = /** @type {SVGGeometryElement} */(parsedTargets[0]);
|
|
26
|
+
if (!$parsedSvg || !helpers.isSvg($parsedSvg)) return console.warn(`${path} is not a valid SVGGeometryElement`);
|
|
27
|
+
return $parsedSvg;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.getPath = getPath;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - svg - ESM
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { isSvg } from '../core/helpers.js';
|
|
9
|
+
import { parseTargets } from '../core/targets.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @import {
|
|
13
|
+
* TargetsParam,
|
|
14
|
+
* } from '../types/index.js'
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {TargetsParam} path
|
|
19
|
+
* @return {SVGGeometryElement|void}
|
|
20
|
+
*/
|
|
21
|
+
const getPath = path => {
|
|
22
|
+
const parsedTargets = parseTargets(path);
|
|
23
|
+
const $parsedSvg = /** @type {SVGGeometryElement} */(parsedTargets[0]);
|
|
24
|
+
if (!$parsedSvg || !isSvg($parsedSvg)) return console.warn(`${path} is not a valid SVGGeometryElement`);
|
|
25
|
+
return $parsedSvg;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { getPath };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - svg - CJS
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var motionpath = require('./motionpath.cjs');
|
|
11
|
+
var drawable = require('./drawable.cjs');
|
|
12
|
+
var morphto = require('./morphto.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
exports.createMotionPath = motionpath.createMotionPath;
|
|
17
|
+
exports.createDrawable = drawable.createDrawable;
|
|
18
|
+
exports.morphTo = morphto.morphTo;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - svg - CJS
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var consts = require('../core/consts.cjs');
|
|
11
|
+
var helpers$1 = require('../core/helpers.cjs');
|
|
12
|
+
var helpers = require('./helpers.cjs');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @import {
|
|
16
|
+
* TargetsParam,
|
|
17
|
+
* FunctionValue
|
|
18
|
+
* } from '../types/index.js'
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {TargetsParam} path2
|
|
23
|
+
* @param {Number} [precision]
|
|
24
|
+
* @return {FunctionValue}
|
|
25
|
+
*/
|
|
26
|
+
const morphTo = (path2, precision = .33) => ($path1) => {
|
|
27
|
+
const $path2 = /** @type {SVGGeometryElement} */(helpers.getPath(path2));
|
|
28
|
+
if (!$path2) return;
|
|
29
|
+
const isPath = $path1.tagName === 'path';
|
|
30
|
+
const separator = isPath ? ' ' : ',';
|
|
31
|
+
const previousPoints = $path1[consts.morphPointsSymbol];
|
|
32
|
+
if (previousPoints) $path1.setAttribute(isPath ? 'd' : 'points', previousPoints);
|
|
33
|
+
|
|
34
|
+
let v1 = '', v2 = '';
|
|
35
|
+
|
|
36
|
+
if (!precision) {
|
|
37
|
+
v1 = $path1.getAttribute(isPath ? 'd' : 'points');
|
|
38
|
+
v2 = $path2.getAttribute(isPath ? 'd' : 'points');
|
|
39
|
+
} else {
|
|
40
|
+
const length1 = /** @type {SVGGeometryElement} */($path1).getTotalLength();
|
|
41
|
+
const length2 = $path2.getTotalLength();
|
|
42
|
+
const maxPoints = Math.max(Math.ceil(length1 * precision), Math.ceil(length2 * precision));
|
|
43
|
+
for (let i = 0; i < maxPoints; i++) {
|
|
44
|
+
const t = i / (maxPoints - 1);
|
|
45
|
+
const pointOnPath1 = /** @type {SVGGeometryElement} */($path1).getPointAtLength(length1 * t);
|
|
46
|
+
const pointOnPath2 = $path2.getPointAtLength(length2 * t);
|
|
47
|
+
const prefix = isPath ? (i === 0 ? 'M' : 'L') : '';
|
|
48
|
+
v1 += prefix + helpers$1.round(pointOnPath1.x, 3) + separator + pointOnPath1.y + ' ';
|
|
49
|
+
v2 += prefix + helpers$1.round(pointOnPath2.x, 3) + separator + pointOnPath2.y + ' ';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
$path1[consts.morphPointsSymbol] = v2;
|
|
54
|
+
|
|
55
|
+
return [v1, v2];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
exports.morphTo = morphTo;
|