animejs 4.3.6 → 4.4.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 +8 -11
- package/dist/bundles/anime.esm.js +1033 -421
- package/dist/bundles/anime.esm.min.js +2 -2
- package/dist/bundles/anime.umd.js +1038 -421
- package/dist/bundles/anime.umd.min.js +2 -2
- package/dist/modules/animatable/animatable.cjs +1 -1
- package/dist/modules/animatable/animatable.js +2 -2
- 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 +38 -16
- package/dist/modules/animation/animation.d.ts +2 -2
- package/dist/modules/animation/animation.js +42 -20
- package/dist/modules/animation/composition.cjs +1 -1
- package/dist/modules/animation/composition.js +3 -3
- package/dist/modules/animation/index.cjs +1 -1
- package/dist/modules/animation/index.js +1 -1
- package/dist/modules/core/clock.cjs +1 -1
- package/dist/modules/core/clock.js +1 -1
- package/dist/modules/core/colors.cjs +1 -1
- package/dist/modules/core/colors.js +1 -1
- package/dist/modules/core/consts.cjs +3 -9
- package/dist/modules/core/consts.d.ts +1 -5
- package/dist/modules/core/consts.js +4 -8
- package/dist/modules/core/globals.cjs +16 -5
- package/dist/modules/core/globals.d.ts +22 -1
- package/dist/modules/core/globals.js +18 -6
- package/dist/modules/core/helpers.cjs +7 -10
- package/dist/modules/core/helpers.js +8 -11
- package/dist/modules/core/render.cjs +66 -63
- package/dist/modules/core/render.js +68 -65
- package/dist/modules/core/styles.cjs +53 -32
- package/dist/modules/core/styles.d.ts +1 -0
- package/dist/modules/core/styles.js +55 -35
- package/dist/modules/core/targets.cjs +1 -1
- package/dist/modules/core/targets.js +1 -1
- package/dist/modules/core/transforms.cjs +129 -13
- package/dist/modules/core/transforms.d.ts +1 -0
- package/dist/modules/core/transforms.js +130 -15
- package/dist/modules/core/units.cjs +1 -1
- package/dist/modules/core/units.js +1 -1
- package/dist/modules/core/values.cjs +68 -8
- package/dist/modules/core/values.d.ts +5 -2
- package/dist/modules/core/values.js +69 -11
- 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 +1 -1
- package/dist/modules/easings/eases/parser.js +1 -1
- 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 +1 -1
- package/dist/modules/engine/engine.js +1 -1
- 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 +1 -1
- package/dist/modules/events/scroll.js +1 -1
- package/dist/modules/index.cjs +9 -1
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +4 -1
- package/dist/modules/layout/index.cjs +1 -1
- package/dist/modules/layout/index.js +1 -1
- package/dist/modules/layout/layout.cjs +29 -25
- package/dist/modules/layout/layout.d.ts +4 -3
- package/dist/modules/layout/layout.js +30 -26
- 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 +3 -6
- package/dist/modules/svg/morphto.js +3 -6
- package/dist/modules/svg/motionpath.cjs +1 -1
- package/dist/modules/svg/motionpath.js +1 -1
- package/dist/modules/text/index.cjs +3 -1
- package/dist/modules/text/index.d.ts +1 -0
- package/dist/modules/text/index.js +2 -1
- package/dist/modules/text/scramble.cjs +272 -0
- package/dist/modules/text/scramble.d.ts +3 -0
- package/dist/modules/text/scramble.js +270 -0
- package/dist/modules/text/split.cjs +5 -5
- package/dist/modules/text/split.d.ts +5 -5
- package/dist/modules/text/split.js +5 -5
- 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 +36 -18
- package/dist/modules/timeline/timeline.d.ts +6 -5
- package/dist/modules/timeline/timeline.js +37 -19
- package/dist/modules/timer/index.cjs +1 -1
- package/dist/modules/timer/index.js +1 -1
- package/dist/modules/timer/timer.cjs +8 -12
- package/dist/modules/timer/timer.d.ts +2 -0
- package/dist/modules/timer/timer.js +9 -13
- package/dist/modules/types/index.d.ts +76 -8
- package/dist/modules/utils/chainable.cjs +8 -5
- package/dist/modules/utils/chainable.js +8 -5
- package/dist/modules/utils/index.cjs +5 -1
- package/dist/modules/utils/index.d.ts +1 -0
- package/dist/modules/utils/index.js +2 -1
- package/dist/modules/utils/number.cjs +1 -1
- package/dist/modules/utils/number.js +1 -1
- package/dist/modules/utils/random.cjs +1 -1
- package/dist/modules/utils/random.js +1 -1
- package/dist/modules/utils/stagger.cjs +117 -20
- package/dist/modules/utils/stagger.js +118 -21
- package/dist/modules/utils/target.cjs +1 -1
- package/dist/modules/utils/target.js +1 -1
- package/dist/modules/utils/time.cjs +5 -3
- package/dist/modules/utils/time.d.ts +1 -1
- package/dist/modules/utils/time.js +5 -3
- 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 +19 -20
- package/dist/modules/waapi/waapi.js +20 -21
- package/package.json +2 -1
|
@@ -27,12 +27,12 @@ export type Renderable = JSAnimation | Timeline;
|
|
|
27
27
|
export type Tickable = Timer | Renderable;
|
|
28
28
|
export type CallbackArgument = Timer & JSAnimation & Timeline;
|
|
29
29
|
export type Revertible = Animatable | Tickable | WAAPIAnimation | Draggable | ScrollObserver | TextSplitter | Scope | AutoLayout;
|
|
30
|
-
export type StaggerFunction<T> = (target?: Target, index?: number,
|
|
30
|
+
export type StaggerFunction<T> = (target?: Target, index?: number, targets?: TargetsArray, prevTween?: Tween | null, tl?: Timeline) => T;
|
|
31
31
|
export type StaggerParams = {
|
|
32
32
|
start?: number | string;
|
|
33
|
-
from?: number | "first" | "center" | "last" | "random"
|
|
33
|
+
from?: number | "first" | "center" | "last" | "random" | Array<number>;
|
|
34
34
|
reversed?: boolean;
|
|
35
|
-
grid?: Array<number
|
|
35
|
+
grid?: Array<number> | boolean;
|
|
36
36
|
axis?: ("x" | "y");
|
|
37
37
|
use?: string | ((target: Target, i: number, length: number) => number);
|
|
38
38
|
total?: number;
|
|
@@ -57,8 +57,8 @@ export type PowerEasing = (power?: number | string) => EasingFunction;
|
|
|
57
57
|
export type BackEasing = (overshoot?: number | string) => EasingFunction;
|
|
58
58
|
export type ElasticEasing = (amplitude?: number | string, period?: number | string) => EasingFunction;
|
|
59
59
|
export type EasingFunctionWithParams = PowerEasing | BackEasing | ElasticEasing;
|
|
60
|
-
export type EasingParam = (string & {}) | EaseStringParamNames | EasingFunction | Spring;
|
|
61
|
-
export type WAAPIEasingParam = (string & {}) | EaseStringParamNames | WAAPIEaseStringParamNames | EasingFunction | Spring;
|
|
60
|
+
export type EasingParam = (string & {}) | EaseStringParamNames | EasingFunction | Spring | TweakRegister;
|
|
61
|
+
export type WAAPIEasingParam = (string & {}) | EaseStringParamNames | WAAPIEaseStringParamNames | EasingFunction | Spring | TweakRegister;
|
|
62
62
|
export type SpringParams = {
|
|
63
63
|
/**
|
|
64
64
|
* - Mass, default 1
|
|
@@ -112,9 +112,10 @@ export type TimerOptions = {
|
|
|
112
112
|
autoplay?: boolean | ScrollObserver;
|
|
113
113
|
frameRate?: number;
|
|
114
114
|
playbackRate?: number;
|
|
115
|
+
priority?: number;
|
|
115
116
|
};
|
|
116
117
|
export type TimerParams = TimerOptions & TickableCallbacks<Timer>;
|
|
117
|
-
export type FunctionValue = (target
|
|
118
|
+
export type FunctionValue = (target?: Target, index?: number, targets?: TargetsArray, prevTween?: Tween | null) => number | string | TweenObjectValue | EasingParam | Array<number | string | TweenObjectValue>;
|
|
118
119
|
export type TweenModifier = (value: number) => number | string;
|
|
119
120
|
export type ColorArray = [number, number, number, number];
|
|
120
121
|
export type Tween = {
|
|
@@ -246,7 +247,7 @@ export type TimelinePosition = number | `+=${number}` | `-=${number}` | `*=${num
|
|
|
246
247
|
* - `'label'` - Label: Position animation at a named label position (e.g., `'My Label'`)<br>
|
|
247
248
|
* - `stagger(String|Nummber)` - Stagger multi-elements animation positions (e.g., 10, 20, 30...)
|
|
248
249
|
*/
|
|
249
|
-
export type TimelineAnimationPosition = TimelinePosition | StaggerFunction<number | string
|
|
250
|
+
export type TimelineAnimationPosition = TimelinePosition | StaggerFunction<number | string> | TweakRegister;
|
|
250
251
|
export type TimelineOptions = {
|
|
251
252
|
defaults?: DefaultsParams;
|
|
252
253
|
playbackEase?: EasingParam;
|
|
@@ -254,7 +255,7 @@ export type TimelineOptions = {
|
|
|
254
255
|
};
|
|
255
256
|
export type TimelineParams = TimerOptions & TimelineOptions & TickableCallbacks<Timeline> & RenderableCallbacks<Timeline>;
|
|
256
257
|
export type WAAPITweenValue = string | number | Array<string> | Array<number>;
|
|
257
|
-
export type WAAPIFunctionValue = (target: DOMTarget, index: number,
|
|
258
|
+
export type WAAPIFunctionValue = (target: DOMTarget, index: number, targets: DOMTargetsArray) => WAAPITweenValue | WAAPIEasingParam;
|
|
258
259
|
export type WAAPIKeyframeValue = WAAPITweenValue | WAAPIFunctionValue | Array<string | number | WAAPIFunctionValue>;
|
|
259
260
|
export type WAAPITweenOptions = {
|
|
260
261
|
to?: WAAPIKeyframeValue;
|
|
@@ -392,6 +393,72 @@ export type TextSplitterParams = {
|
|
|
392
393
|
includeSpaces?: boolean;
|
|
393
394
|
debug?: boolean;
|
|
394
395
|
};
|
|
396
|
+
export type ScrambleTextParams = {
|
|
397
|
+
/**
|
|
398
|
+
* - the text to transition to, otherwise uses the original text
|
|
399
|
+
*/
|
|
400
|
+
text?: string | ((arg0: Target, arg1: number, arg2: TargetsArray) => string);
|
|
401
|
+
/**
|
|
402
|
+
* - the characters used for scramble; named sets: 'lowercase', 'uppercase', 'numbers', 'symbols', 'braille', 'blocks', 'shades'; range syntax: 'A-Z', 'a-z0-9'; defaults to 'a-zA-Z0-9!%#_'
|
|
403
|
+
*/
|
|
404
|
+
chars?: string | ((arg0: Target, arg1: number, arg2: TargetsArray) => string);
|
|
405
|
+
/**
|
|
406
|
+
* - the easing applied to the scramble animation
|
|
407
|
+
*/
|
|
408
|
+
ease?: EasingParam;
|
|
409
|
+
/**
|
|
410
|
+
* - where the reveal wave starts from, 'auto' (default) uses 'left' when text grows and 'right' when it shrinks
|
|
411
|
+
*/
|
|
412
|
+
from?: number | "left" | "center" | "right" | "random" | "auto";
|
|
413
|
+
/**
|
|
414
|
+
* - reverses the reveal order, so 'center' reveals from edges inward instead of center outward
|
|
415
|
+
*/
|
|
416
|
+
reversed?: boolean;
|
|
417
|
+
/**
|
|
418
|
+
* - characters displayed at the leading edge of the reveal wave; true uses '_', a number is a char code, a string is used directly
|
|
419
|
+
*/
|
|
420
|
+
cursor?: boolean | number | string;
|
|
421
|
+
/**
|
|
422
|
+
* - adds random timing offsets to each character's start and end, creating a more organic reveal
|
|
423
|
+
*/
|
|
424
|
+
perturbation?: number;
|
|
425
|
+
/**
|
|
426
|
+
* - a seed for the random number generator to produce reproducible scramble sequences
|
|
427
|
+
*/
|
|
428
|
+
seed?: number;
|
|
429
|
+
/**
|
|
430
|
+
* - controls the starting appearance: false shows original text, true scrambles it (default), '' starts from blank, ' ' replaces characters with spaces, a custom string (supports range syntax like 'A-Z') uses its characters as scramble set
|
|
431
|
+
*/
|
|
432
|
+
override?: boolean | string;
|
|
433
|
+
/**
|
|
434
|
+
* - characters per second entering the active zone; higher values make the reveal wave move faster (default: 60)
|
|
435
|
+
*/
|
|
436
|
+
revealRate?: number;
|
|
437
|
+
/**
|
|
438
|
+
* - time in ms each character spends scrambling before settling into its final glyph (default: 300)
|
|
439
|
+
*/
|
|
440
|
+
settleDuration?: number;
|
|
441
|
+
/**
|
|
442
|
+
* - how many times per second scramble characters cycle in the active zone (default: 30)
|
|
443
|
+
*/
|
|
444
|
+
settleRate?: number;
|
|
445
|
+
/**
|
|
446
|
+
* - if set to a value greater than 0, overrides the computed duration from interval and settle; if unset or 0, duration is calculated automatically from text length and timing parameters
|
|
447
|
+
*/
|
|
448
|
+
duration?: number | ((arg0: Target, arg1: number, arg2: TargetsArray) => number);
|
|
449
|
+
/**
|
|
450
|
+
* - delay in ms before the reveal wave starts within the scramble animation
|
|
451
|
+
*/
|
|
452
|
+
revealDelay?: number | ((arg0: Target, arg1: number, arg2: TargetsArray) => number);
|
|
453
|
+
/**
|
|
454
|
+
* - delay in ms before the entire scramble animation starts
|
|
455
|
+
*/
|
|
456
|
+
delay?: number | ((arg0: Target, arg1: number, arg2: TargetsArray) => number);
|
|
457
|
+
/**
|
|
458
|
+
* - callback fired each time a character changes during scramble; receives the current scrambled text and the eased progress (0-1)
|
|
459
|
+
*/
|
|
460
|
+
onChange?: (arg0: string, arg1: number) => void;
|
|
461
|
+
};
|
|
395
462
|
export type DrawableSVGGeometry = SVGGeometryElement & {
|
|
396
463
|
setAttribute(name: "draw", value: `${number} ${number}`): void;
|
|
397
464
|
draw: `${number} ${number}`;
|
|
@@ -408,5 +475,6 @@ import type { TextSplitter } from '../text/split.js';
|
|
|
408
475
|
import type { Scope } from '../scope/scope.js';
|
|
409
476
|
import type { AutoLayout } from '../layout/layout.js';
|
|
410
477
|
import type { Spring } from '../easings/spring/index.js';
|
|
478
|
+
import type { TweakRegister } from 'tweaks';
|
|
411
479
|
import type { tweenTypes } from '../core/consts.js';
|
|
412
480
|
import type { valueTypes } from '../core/consts.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Anime.js - utils - CJS
|
|
3
|
-
* @version v4.
|
|
3
|
+
* @version v4.4.0
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 - Julian Garnier
|
|
6
6
|
*/
|
|
@@ -36,10 +36,13 @@ const chain = fn => {
|
|
|
36
36
|
const result = fn(...args);
|
|
37
37
|
return new Proxy(consts.noop, {
|
|
38
38
|
apply: (_, __, [v]) => result(v),
|
|
39
|
-
get: (_, prop) =>
|
|
40
|
-
|
|
41
|
-
return (/**@
|
|
42
|
-
|
|
39
|
+
get: (_, prop) => {
|
|
40
|
+
if (!chainables[prop]) return undefined;
|
|
41
|
+
return chain(/**@param {...Number|String} nextArgs */(...nextArgs) => {
|
|
42
|
+
const nextResult = chainables[prop](...nextArgs);
|
|
43
|
+
return (/**@type {Number|String} */v) => nextResult(result(v));
|
|
44
|
+
})
|
|
45
|
+
}
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
48
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Anime.js - utils - ESM
|
|
3
|
-
* @version v4.
|
|
3
|
+
* @version v4.4.0
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 - Julian Garnier
|
|
6
6
|
*/
|
|
@@ -34,10 +34,13 @@ const chain = fn => {
|
|
|
34
34
|
const result = fn(...args);
|
|
35
35
|
return new Proxy(noop, {
|
|
36
36
|
apply: (_, __, [v]) => result(v),
|
|
37
|
-
get: (_, prop) =>
|
|
38
|
-
|
|
39
|
-
return (/**@
|
|
40
|
-
|
|
37
|
+
get: (_, prop) => {
|
|
38
|
+
if (!chainables[prop]) return undefined;
|
|
39
|
+
return chain(/**@param {...Number|String} nextArgs */(...nextArgs) => {
|
|
40
|
+
const nextResult = chainables[prop](...nextArgs);
|
|
41
|
+
return (/**@type {Number|String} */v) => nextResult(result(v));
|
|
42
|
+
})
|
|
43
|
+
}
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
46
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Anime.js - utils - CJS
|
|
3
|
-
* @version v4.
|
|
3
|
+
* @version v4.4.0
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 - Julian Garnier
|
|
6
6
|
*/
|
|
@@ -12,6 +12,7 @@ var random = require('./random.cjs');
|
|
|
12
12
|
var time = require('./time.cjs');
|
|
13
13
|
var target = require('./target.cjs');
|
|
14
14
|
var stagger = require('./stagger.cjs');
|
|
15
|
+
var helpers = require('../core/helpers.cjs');
|
|
15
16
|
var styles = require('../core/styles.cjs');
|
|
16
17
|
var targets = require('../core/targets.cjs');
|
|
17
18
|
|
|
@@ -39,5 +40,8 @@ exports.get = target.get;
|
|
|
39
40
|
exports.remove = target.remove;
|
|
40
41
|
exports.set = target.set;
|
|
41
42
|
exports.stagger = stagger.stagger;
|
|
43
|
+
exports.addChild = helpers.addChild;
|
|
44
|
+
exports.forEachChildren = helpers.forEachChildren;
|
|
45
|
+
exports.removeChild = helpers.removeChild;
|
|
42
46
|
exports.cleanInlineStyles = styles.cleanInlineStyles;
|
|
43
47
|
exports.$ = targets.registerTargets;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Anime.js - utils - ESM
|
|
3
|
-
* @version v4.
|
|
3
|
+
* @version v4.4.0
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 - Julian Garnier
|
|
6
6
|
*/
|
|
@@ -10,5 +10,6 @@ export { createSeededRandom, random, randomPick, shuffle } from './random.js';
|
|
|
10
10
|
export { keepTime, sync } from './time.js';
|
|
11
11
|
export { get, remove, set } from './target.js';
|
|
12
12
|
export { stagger } from './stagger.js';
|
|
13
|
+
export { addChild, forEachChildren, removeChild } from '../core/helpers.js';
|
|
13
14
|
export { cleanInlineStyles } from '../core/styles.js';
|
|
14
15
|
export { registerTargets as $ } from '../core/targets.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Anime.js - utils - CJS
|
|
3
|
-
* @version v4.
|
|
3
|
+
* @version v4.4.0
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2026 - Julian Garnier
|
|
6
6
|
*/
|
|
@@ -19,6 +19,7 @@ var random = require('./random.cjs');
|
|
|
19
19
|
* @import {
|
|
20
20
|
* StaggerParams,
|
|
21
21
|
* StaggerFunction,
|
|
22
|
+
* JSTarget,
|
|
22
23
|
* } from '../types/index.js'
|
|
23
24
|
*/
|
|
24
25
|
|
|
@@ -34,24 +35,28 @@ var random = require('./random.cjs');
|
|
|
34
35
|
* @param {StaggerParams} [params]
|
|
35
36
|
* @return {StaggerFunction<Number>}
|
|
36
37
|
*/
|
|
38
|
+
|
|
37
39
|
/**
|
|
38
40
|
* @overload
|
|
39
41
|
* @param {String} val
|
|
40
42
|
* @param {StaggerParams} [params]
|
|
41
43
|
* @return {StaggerFunction<String>}
|
|
42
44
|
*/
|
|
45
|
+
|
|
43
46
|
/**
|
|
44
47
|
* @overload
|
|
45
48
|
* @param {[Number, Number]} val
|
|
46
49
|
* @param {StaggerParams} [params]
|
|
47
50
|
* @return {StaggerFunction<Number>}
|
|
48
51
|
*/
|
|
52
|
+
|
|
49
53
|
/**
|
|
50
54
|
* @overload
|
|
51
55
|
* @param {[String, String]} val
|
|
52
56
|
* @param {StaggerParams} [params]
|
|
53
57
|
* @return {StaggerFunction<String>}
|
|
54
58
|
*/
|
|
59
|
+
|
|
55
60
|
/**
|
|
56
61
|
* @param {Number|String|[Number, Number]|[String, String]} val The staggered value or range
|
|
57
62
|
* @param {StaggerParams} [params] The stagger parameters
|
|
@@ -60,6 +65,7 @@ var random = require('./random.cjs');
|
|
|
60
65
|
const stagger = (val, params = {}) => {
|
|
61
66
|
let values$1 = [];
|
|
62
67
|
let maxValue = 0;
|
|
68
|
+
let cachedOffset;
|
|
63
69
|
const from = params.from;
|
|
64
70
|
const reversed = params.reversed;
|
|
65
71
|
const ease = params.ease;
|
|
@@ -67,12 +73,14 @@ const stagger = (val, params = {}) => {
|
|
|
67
73
|
const hasSpring = hasEasing && !helpers.isUnd(/** @type {Spring} */(ease).ease);
|
|
68
74
|
const staggerEase = hasSpring ? /** @type {Spring} */(ease).ease : hasEasing ? parser.parseEase(ease) : null;
|
|
69
75
|
const grid = params.grid;
|
|
76
|
+
const autoGrid = grid === true;
|
|
70
77
|
const axis = params.axis;
|
|
71
78
|
const customTotal = params.total;
|
|
72
79
|
const fromFirst = helpers.isUnd(from) || from === 0 || from === 'first';
|
|
73
80
|
const fromCenter = from === 'center';
|
|
74
81
|
const fromLast = from === 'last';
|
|
75
82
|
const fromRandom = from === 'random';
|
|
83
|
+
const fromArr = helpers.isArr(from);
|
|
76
84
|
const isRange = helpers.isArr(val);
|
|
77
85
|
const useProp = params.use;
|
|
78
86
|
const val1 = isRange ? helpers.parseNumber(val[0]) : helpers.parseNumber(val);
|
|
@@ -80,40 +88,129 @@ const stagger = (val, params = {}) => {
|
|
|
80
88
|
const unitMatch = consts.unitsExecRgx.exec((isRange ? val[1] : val) + consts.emptyString);
|
|
81
89
|
const start = params.start || 0 + (isRange ? val1 : 0);
|
|
82
90
|
let fromIndex = fromFirst ? 0 : helpers.isNum(from) ? from : 0;
|
|
83
|
-
return (target, i, t, tl) => {
|
|
91
|
+
return (target, i, t, _, tl) => {
|
|
84
92
|
const [ registeredTarget ] = targets.registerTargets(target);
|
|
85
|
-
const total = helpers.isUnd(customTotal) ? t : customTotal;
|
|
93
|
+
const total = helpers.isUnd(customTotal) ? t.length : customTotal;
|
|
86
94
|
const customIndex = !helpers.isUnd(useProp) ? helpers.isFnc(useProp) ? useProp(registeredTarget, i, total) : values.getOriginalAnimatableValue(registeredTarget, useProp) : false;
|
|
87
95
|
const staggerIndex = helpers.isNum(customIndex) || helpers.isStr(customIndex) && helpers.isNum(+customIndex) ? +customIndex : i;
|
|
88
96
|
if (fromCenter) fromIndex = (total - 1) / 2;
|
|
89
97
|
if (fromLast) fromIndex = total - 1;
|
|
90
98
|
if (!values$1.length) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
if (autoGrid) {
|
|
100
|
+
let hasPositions = true;
|
|
101
|
+
let minPosX = Infinity;
|
|
102
|
+
let minPosY = Infinity;
|
|
103
|
+
let maxPosX = -Infinity;
|
|
104
|
+
let maxPosY = -Infinity;
|
|
105
|
+
const pxArr = [];
|
|
106
|
+
const pyArr = [];
|
|
107
|
+
for (let index = 0; index < total; index++) {
|
|
108
|
+
const el = t[index];
|
|
109
|
+
let px = 0;
|
|
110
|
+
let py = 0;
|
|
111
|
+
let found = false;
|
|
112
|
+
if (el && helpers.isFnc(el.getBoundingClientRect)) {
|
|
113
|
+
const rect = el.getBoundingClientRect();
|
|
114
|
+
px = rect.left + rect.width / 2;
|
|
115
|
+
py = rect.top + rect.height / 2;
|
|
116
|
+
found = true;
|
|
117
|
+
} else {
|
|
118
|
+
const obj = /** @type {JSTarget} */(el);
|
|
119
|
+
if (obj && helpers.isNum(obj.x) && helpers.isNum(obj.y)) {
|
|
120
|
+
px = obj.x;
|
|
121
|
+
py = obj.y;
|
|
122
|
+
found = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (!found) {
|
|
126
|
+
hasPositions = false;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
pxArr.push(px);
|
|
130
|
+
pyArr.push(py);
|
|
131
|
+
if (px < minPosX) minPosX = px;
|
|
132
|
+
if (py < minPosY) minPosY = py;
|
|
133
|
+
if (px > maxPosX) maxPosX = px;
|
|
134
|
+
if (py > maxPosY) maxPosY = py;
|
|
135
|
+
}
|
|
136
|
+
if (hasPositions) {
|
|
137
|
+
let fX = pxArr[0];
|
|
138
|
+
let fY = pyArr[0];
|
|
139
|
+
if (fromArr) {
|
|
140
|
+
fX = minPosX + from[0] * (maxPosX - minPosX);
|
|
141
|
+
fY = minPosY + from[1] * (maxPosY - minPosY);
|
|
142
|
+
} else if (fromCenter) {
|
|
143
|
+
fX = (minPosX + maxPosX) / 2;
|
|
144
|
+
fY = (minPosY + maxPosY) / 2;
|
|
145
|
+
} else if (fromLast) {
|
|
146
|
+
fX = pxArr[total - 1];
|
|
147
|
+
fY = pyArr[total - 1];
|
|
148
|
+
} else if (helpers.isNum(from)) {
|
|
149
|
+
fX = pxArr[from];
|
|
150
|
+
fY = pyArr[from];
|
|
151
|
+
}
|
|
152
|
+
for (let index = 0; index < total; index++) {
|
|
153
|
+
const distanceX = fX - pxArr[index];
|
|
154
|
+
const distanceY = fY - pyArr[index];
|
|
155
|
+
let value = helpers.sqrt(distanceX * distanceX + distanceY * distanceY);
|
|
156
|
+
if (axis === 'x') value = -distanceX;
|
|
157
|
+
if (axis === 'y') value = -distanceY;
|
|
158
|
+
values$1.push(value);
|
|
159
|
+
}
|
|
160
|
+
let minDist = Infinity;
|
|
161
|
+
for (let index = 0, l = values$1.length; index < l; index++) {
|
|
162
|
+
const absVal = helpers.abs(values$1[index]);
|
|
163
|
+
if (absVal > 0 && absVal < minDist) minDist = absVal;
|
|
164
|
+
}
|
|
165
|
+
if (minDist > 0 && minDist < Infinity) {
|
|
166
|
+
for (let index = 0, l = values$1.length; index < l; index++) {
|
|
167
|
+
values$1[index] = values$1[index] / minDist;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
94
170
|
} else {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
171
|
+
for (let index = 0; index < total; index++) {
|
|
172
|
+
values$1.push(helpers.abs(fromIndex - index));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
for (let index = 0; index < total; index++) {
|
|
177
|
+
if (!grid) {
|
|
178
|
+
values$1.push(helpers.abs(fromIndex - index));
|
|
179
|
+
} else {
|
|
180
|
+
let fromX, fromY;
|
|
181
|
+
if (fromArr) {
|
|
182
|
+
fromX = from[0] * (grid[0] - 1);
|
|
183
|
+
fromY = from[1] * (grid[1] - 1);
|
|
184
|
+
} else if (fromCenter) {
|
|
185
|
+
fromX = (grid[0] - 1) / 2;
|
|
186
|
+
fromY = (grid[1] - 1) / 2;
|
|
187
|
+
} else {
|
|
188
|
+
fromX = fromIndex % grid[0];
|
|
189
|
+
fromY = helpers.floor(fromIndex / grid[0]);
|
|
190
|
+
}
|
|
191
|
+
const toX = index % grid[0];
|
|
192
|
+
const toY = helpers.floor(index / grid[0]);
|
|
193
|
+
const distanceX = fromX - toX;
|
|
194
|
+
const distanceY = fromY - toY;
|
|
195
|
+
let value = helpers.sqrt(distanceX * distanceX + distanceY * distanceY);
|
|
196
|
+
if (axis === 'x') value = -distanceX;
|
|
197
|
+
if (axis === 'y') value = -distanceY;
|
|
198
|
+
values$1.push(value);
|
|
199
|
+
}
|
|
105
200
|
}
|
|
106
|
-
maxValue = helpers.max(...values$1);
|
|
107
201
|
}
|
|
202
|
+
maxValue = helpers.max(...values$1);
|
|
108
203
|
if (staggerEase) values$1 = values$1.map(val => staggerEase(val / maxValue) * maxValue);
|
|
109
204
|
if (reversed) values$1 = values$1.map(val => axis ? (val < 0) ? val * -1 : -val : helpers.abs(maxValue - val));
|
|
110
205
|
if (fromRandom) values$1 = random.shuffle(values$1);
|
|
111
206
|
}
|
|
112
207
|
const spacing = isRange ? (val2 - val1) / maxValue : val1;
|
|
113
|
-
|
|
208
|
+
if (helpers.isUnd(cachedOffset)) {
|
|
209
|
+
cachedOffset = tl ? position.parseTimelinePosition(tl, helpers.isUnd(params.start) ? tl.iterationDuration : start) : /** @type {Number} */(start);
|
|
210
|
+
}
|
|
114
211
|
/** @type {String|Number} */
|
|
115
|
-
let output =
|
|
116
|
-
if (params.modifier) output = params.modifier(output);
|
|
212
|
+
let output = cachedOffset + ((spacing * helpers.round(values$1[staggerIndex], 2)) || 0);
|
|
213
|
+
if (params.modifier) output = params.modifier(/** @type {Number} */(output));
|
|
117
214
|
if (unitMatch) output = `${output}${unitMatch[2]}`;
|
|
118
215
|
return output;
|
|
119
216
|
}
|