framer-motion 12.7.4 → 12.7.5-alpha.1
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 +1 -1
- package/dist/cjs/client.js +1 -1
- package/dist/cjs/{create-BErHrlzf.js → create-D5a67TOR.js} +99 -2828
- package/dist/cjs/dom-mini.js +82 -66
- package/dist/cjs/dom.js +276 -3011
- package/dist/cjs/index.js +149 -206
- package/dist/cjs/m.js +13 -170
- package/dist/cjs/mini.js +77 -9
- package/dist/dom-mini.js +1 -1
- package/dist/dom.d.ts +5 -94
- package/dist/dom.js +1 -1
- package/dist/es/animation/animate/sequence.mjs +1 -1
- package/dist/es/animation/animators/waapi/animate-elements.mjs +78 -10
- package/dist/es/animation/interfaces/motion-value.mjs +11 -30
- package/dist/es/animation/interfaces/visual-element-target.mjs +1 -2
- package/dist/es/animation/optimized-appear/store-id.mjs +1 -1
- package/dist/es/animation/sequence/create.mjs +2 -5
- package/dist/es/animation/sequence/utils/edit.mjs +2 -3
- package/dist/es/animation/utils/default-transitions.mjs +1 -1
- package/dist/es/animation/utils/stagger.mjs +1 -1
- package/dist/es/components/Reorder/utils/check-reorder.mjs +1 -1
- package/dist/es/dom.mjs +2 -18
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +1 -3
- package/dist/es/gestures/drag/utils/constraints.mjs +2 -3
- package/dist/es/gestures/focus.mjs +1 -1
- package/dist/es/gestures/pan/PanSession.mjs +1 -2
- package/dist/es/index.mjs +3 -24
- package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -1
- package/dist/es/projection/animation/mix-values.mjs +2 -4
- package/dist/es/projection/geometry/delta-apply.mjs +1 -1
- package/dist/es/projection/geometry/delta-calc.mjs +1 -1
- package/dist/es/projection/geometry/delta-remove.mjs +1 -2
- package/dist/es/projection/node/create-projection-node.mjs +3 -7
- package/dist/es/projection/styles/scale-border-radius.mjs +1 -1
- package/dist/es/projection/styles/scale-box-shadow.mjs +1 -2
- package/dist/es/projection/styles/scale-correction.mjs +1 -1
- package/dist/es/projection.mjs +1 -3
- package/dist/es/render/VisualElement.mjs +2 -9
- package/dist/es/render/dom/DOMVisualElement.mjs +1 -1
- package/dist/es/render/dom/scroll/attach-animation.mjs +17 -0
- package/dist/es/render/dom/scroll/attach-function.mjs +23 -0
- package/dist/es/render/dom/scroll/index.mjs +6 -82
- package/dist/es/render/dom/scroll/offsets/index.mjs +2 -3
- package/dist/es/render/dom/scroll/utils/get-timeline.mjs +30 -0
- package/dist/es/render/html/HTMLVisualElement.mjs +1 -3
- package/dist/es/render/html/utils/build-styles.mjs +1 -4
- package/dist/es/render/html/utils/build-transform.mjs +1 -3
- package/dist/es/render/svg/SVGVisualElement.mjs +1 -3
- package/dist/es/render/svg/config-motion.mjs +1 -2
- package/dist/es/render/svg/utils/path.mjs +1 -1
- package/dist/es/render/svg/utils/scrape-motion-values.mjs +1 -1
- package/dist/es/render/svg/utils/transform-origin.mjs +1 -1
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/utils/delay.mjs +1 -1
- package/dist/es/utils/transform.mjs +1 -1
- package/dist/es/utils/use-cycle.mjs +1 -1
- package/dist/es/utils/use-instant-transition.mjs +4 -4
- package/dist/es/value/use-spring.mjs +2 -3
- package/dist/es/value/use-will-change/get-will-change-name.mjs +1 -2
- package/dist/framer-motion.dev.js +3864 -3405
- package/dist/framer-motion.js +1 -1
- package/dist/m.d.ts +3 -50
- package/dist/mini.js +1 -1
- package/dist/size-rollup-animate.js +1 -1
- package/dist/size-rollup-dom-animation-assets.js +1 -1
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max-assets.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-rollup-motion.js +1 -1
- package/dist/size-rollup-scroll.js +1 -1
- package/dist/size-rollup-waapi-animate.js +1 -1
- package/dist/types/client.d.ts +4 -3
- package/dist/types/index.d.ts +56 -351
- package/dist/{types.d-B50aGbjN.d.ts → types.d-B1Voffvi.d.ts} +3 -138
- package/package.json +9 -9
- package/dist/es/animation/animators/AcceleratedAnimation.mjs +0 -319
- package/dist/es/animation/animators/BaseAnimation.mjs +0 -120
- package/dist/es/animation/animators/MainThreadAnimation.mjs +0 -394
- package/dist/es/animation/animators/drivers/driver-frameloop.mjs +0 -16
- package/dist/es/animation/animators/utils/accelerated-values.mjs +0 -14
- package/dist/es/animation/animators/utils/can-animate.mjs +0 -42
- package/dist/es/animation/animators/waapi/utils/supports-waapi.mjs +0 -5
- package/dist/es/animation/generators/inertia.mjs +0 -87
- package/dist/es/animation/generators/keyframes.mjs +0 -51
- package/dist/es/animation/generators/spring/defaults.mjs +0 -27
- package/dist/es/animation/generators/spring/find.mjs +0 -85
- package/dist/es/animation/generators/spring/index.mjs +0 -174
- package/dist/es/animation/generators/utils/velocity.mjs +0 -9
- package/dist/es/animation/utils/is-animatable.mjs +0 -30
- package/dist/es/animation/utils/is-none.mjs +0 -15
- package/dist/es/easing/anticipate.mjs +0 -5
- package/dist/es/easing/back.mjs +0 -9
- package/dist/es/easing/circ.mjs +0 -8
- package/dist/es/easing/cubic-bezier.mjs +0 -51
- package/dist/es/easing/ease.mjs +0 -7
- package/dist/es/easing/modifiers/mirror.mjs +0 -5
- package/dist/es/easing/modifiers/reverse.mjs +0 -5
- package/dist/es/easing/steps.mjs +0 -15
- package/dist/es/easing/utils/get-easing-for-segment.mjs +0 -8
- package/dist/es/easing/utils/is-easing-array.mjs +0 -5
- package/dist/es/easing/utils/map.mjs +0 -37
- package/dist/es/render/dom/DOMKeyframesResolver.mjs +0 -130
- package/dist/es/render/dom/scroll/observe.mjs +0 -18
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +0 -42
- package/dist/es/render/dom/utils/is-css-variable.mjs +0 -15
- package/dist/es/render/dom/utils/unit-conversion.mjs +0 -36
- package/dist/es/render/dom/value-types/animatable-none.mjs +0 -15
- package/dist/es/render/dom/value-types/defaults.mjs +0 -30
- package/dist/es/render/dom/value-types/dimensions.mjs +0 -15
- package/dist/es/render/dom/value-types/find.mjs +0 -15
- package/dist/es/render/dom/value-types/get-as-type.mjs +0 -10
- package/dist/es/render/dom/value-types/number-browser.mjs +0 -41
- package/dist/es/render/dom/value-types/number.mjs +0 -18
- package/dist/es/render/dom/value-types/test.mjs +0 -6
- package/dist/es/render/dom/value-types/transform.mjs +0 -31
- package/dist/es/render/dom/value-types/type-auto.mjs +0 -9
- package/dist/es/render/dom/value-types/type-int.mjs +0 -8
- package/dist/es/render/html/utils/keys-position.mjs +0 -13
- package/dist/es/render/html/utils/keys-transform.mjs +0 -28
- package/dist/es/render/html/utils/make-none-animatable.mjs +0 -30
- package/dist/es/render/html/utils/parse-transform.mjs +0 -83
- package/dist/es/render/utils/KeyframesResolver.mjs +0 -163
- package/dist/es/utils/clamp.mjs +0 -9
- package/dist/es/utils/hsla-to-rgba.mjs +0 -42
- package/dist/es/utils/interpolate.mjs +0 -76
- package/dist/es/utils/is-numerical-string.mjs +0 -6
- package/dist/es/utils/is-zero-value-string.mjs +0 -6
- package/dist/es/utils/mix/color.mjs +0 -47
- package/dist/es/utils/mix/complex.mjs +0 -93
- package/dist/es/utils/mix/immediate.mjs +0 -5
- package/dist/es/utils/mix/index.mjs +0 -14
- package/dist/es/utils/mix/number.mjs +0 -26
- package/dist/es/utils/mix/visibility.mjs +0 -16
- package/dist/es/utils/offsets/default.mjs +0 -9
- package/dist/es/utils/offsets/fill.mjs +0 -12
- package/dist/es/utils/offsets/time.mjs +0 -5
- package/dist/es/utils/pipe.mjs +0 -11
- package/dist/es/utils/use-instant-transition-state.mjs +0 -5
- package/dist/es/utils/wrap.mjs +0 -6
- package/dist/es/value/types/color/hex.mjs +0 -40
- package/dist/es/value/types/color/hsla.mjs +0 -22
- package/dist/es/value/types/color/index.mjs +0 -27
- package/dist/es/value/types/color/rgba.mjs +0 -25
- package/dist/es/value/types/color/utils.mjs +0 -29
- package/dist/es/value/types/complex/filter.mjs +0 -30
- package/dist/es/value/types/complex/index.mjs +0 -91
- package/dist/es/value/types/numbers/index.mjs +0 -17
- package/dist/es/value/types/numbers/units.mjs +0 -17
- package/dist/es/value/types/utils/color-regex.mjs +0 -3
- package/dist/es/value/types/utils/float-regex.mjs +0 -3
- package/dist/es/value/types/utils/is-nullish.mjs +0 -5
- package/dist/es/value/types/utils/sanitize.mjs +0 -5
- package/dist/es/value/types/utils/single-color-regex.mjs +0 -3
package/dist/cjs/m.js
CHANGED
|
@@ -381,41 +381,10 @@ function getProjectionFunctionality(props) {
|
|
|
381
381
|
};
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
|
|
385
|
-
const isCSSVariableName =
|
|
386
|
-
/*@__PURE__*/ checkStringStartsWith("--");
|
|
387
|
-
|
|
388
384
|
const scaleCorrectors = {};
|
|
389
385
|
|
|
390
|
-
/**
|
|
391
|
-
* Generate a list of every possible transform key.
|
|
392
|
-
*/
|
|
393
|
-
const transformPropOrder = [
|
|
394
|
-
"transformPerspective",
|
|
395
|
-
"x",
|
|
396
|
-
"y",
|
|
397
|
-
"z",
|
|
398
|
-
"translateX",
|
|
399
|
-
"translateY",
|
|
400
|
-
"translateZ",
|
|
401
|
-
"scale",
|
|
402
|
-
"scaleX",
|
|
403
|
-
"scaleY",
|
|
404
|
-
"rotate",
|
|
405
|
-
"rotateX",
|
|
406
|
-
"rotateY",
|
|
407
|
-
"rotateZ",
|
|
408
|
-
"skew",
|
|
409
|
-
"skewX",
|
|
410
|
-
"skewY",
|
|
411
|
-
];
|
|
412
|
-
/**
|
|
413
|
-
* A quick lookup for transform props.
|
|
414
|
-
*/
|
|
415
|
-
const transformProps = new Set(transformPropOrder);
|
|
416
|
-
|
|
417
386
|
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
418
|
-
return (transformProps.has(key) ||
|
|
387
|
+
return (motionDom.transformProps.has(key) ||
|
|
419
388
|
key.startsWith("origin") ||
|
|
420
389
|
((layout || layoutId !== undefined) &&
|
|
421
390
|
(!!scaleCorrectors[key] || key === "opacity")));
|
|
@@ -423,139 +392,13 @@ function isForcedMotionValue(key, { layout, layoutId }) {
|
|
|
423
392
|
|
|
424
393
|
const isMotionValue = (value) => Boolean(value && value.getVelocity);
|
|
425
394
|
|
|
426
|
-
/**
|
|
427
|
-
* Provided a value and a ValueType, returns the value as that value type.
|
|
428
|
-
*/
|
|
429
|
-
const getValueAsType = (value, type) => {
|
|
430
|
-
return type && typeof value === "number"
|
|
431
|
-
? type.transform(value)
|
|
432
|
-
: value;
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
const clamp = (min, max, v) => {
|
|
436
|
-
if (v > max)
|
|
437
|
-
return max;
|
|
438
|
-
if (v < min)
|
|
439
|
-
return min;
|
|
440
|
-
return v;
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
const number = {
|
|
444
|
-
test: (v) => typeof v === "number",
|
|
445
|
-
parse: parseFloat,
|
|
446
|
-
transform: (v) => v,
|
|
447
|
-
};
|
|
448
|
-
const alpha = {
|
|
449
|
-
...number,
|
|
450
|
-
transform: (v) => clamp(0, 1, v),
|
|
451
|
-
};
|
|
452
|
-
const scale = {
|
|
453
|
-
...number,
|
|
454
|
-
default: 1,
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
const createUnitType = (unit) => ({
|
|
458
|
-
test: (v) => typeof v === "string" && v.endsWith(unit) && v.split(" ").length === 1,
|
|
459
|
-
parse: parseFloat,
|
|
460
|
-
transform: (v) => `${v}${unit}`,
|
|
461
|
-
});
|
|
462
|
-
const degrees = /*@__PURE__*/ createUnitType("deg");
|
|
463
|
-
const percent = /*@__PURE__*/ createUnitType("%");
|
|
464
|
-
const px = /*@__PURE__*/ createUnitType("px");
|
|
465
|
-
const progressPercentage = {
|
|
466
|
-
...percent,
|
|
467
|
-
parse: (v) => percent.parse(v) / 100,
|
|
468
|
-
transform: (v) => percent.transform(v * 100),
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
const browserNumberValueTypes = {
|
|
472
|
-
// Border props
|
|
473
|
-
borderWidth: px,
|
|
474
|
-
borderTopWidth: px,
|
|
475
|
-
borderRightWidth: px,
|
|
476
|
-
borderBottomWidth: px,
|
|
477
|
-
borderLeftWidth: px,
|
|
478
|
-
borderRadius: px,
|
|
479
|
-
radius: px,
|
|
480
|
-
borderTopLeftRadius: px,
|
|
481
|
-
borderTopRightRadius: px,
|
|
482
|
-
borderBottomRightRadius: px,
|
|
483
|
-
borderBottomLeftRadius: px,
|
|
484
|
-
// Positioning props
|
|
485
|
-
width: px,
|
|
486
|
-
maxWidth: px,
|
|
487
|
-
height: px,
|
|
488
|
-
maxHeight: px,
|
|
489
|
-
top: px,
|
|
490
|
-
right: px,
|
|
491
|
-
bottom: px,
|
|
492
|
-
left: px,
|
|
493
|
-
// Spacing props
|
|
494
|
-
padding: px,
|
|
495
|
-
paddingTop: px,
|
|
496
|
-
paddingRight: px,
|
|
497
|
-
paddingBottom: px,
|
|
498
|
-
paddingLeft: px,
|
|
499
|
-
margin: px,
|
|
500
|
-
marginTop: px,
|
|
501
|
-
marginRight: px,
|
|
502
|
-
marginBottom: px,
|
|
503
|
-
marginLeft: px,
|
|
504
|
-
// Misc
|
|
505
|
-
backgroundPositionX: px,
|
|
506
|
-
backgroundPositionY: px,
|
|
507
|
-
};
|
|
508
|
-
|
|
509
|
-
const transformValueTypes = {
|
|
510
|
-
rotate: degrees,
|
|
511
|
-
rotateX: degrees,
|
|
512
|
-
rotateY: degrees,
|
|
513
|
-
rotateZ: degrees,
|
|
514
|
-
scale,
|
|
515
|
-
scaleX: scale,
|
|
516
|
-
scaleY: scale,
|
|
517
|
-
scaleZ: scale,
|
|
518
|
-
skew: degrees,
|
|
519
|
-
skewX: degrees,
|
|
520
|
-
skewY: degrees,
|
|
521
|
-
distance: px,
|
|
522
|
-
translateX: px,
|
|
523
|
-
translateY: px,
|
|
524
|
-
translateZ: px,
|
|
525
|
-
x: px,
|
|
526
|
-
y: px,
|
|
527
|
-
z: px,
|
|
528
|
-
perspective: px,
|
|
529
|
-
transformPerspective: px,
|
|
530
|
-
opacity: alpha,
|
|
531
|
-
originX: progressPercentage,
|
|
532
|
-
originY: progressPercentage,
|
|
533
|
-
originZ: px,
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
const int = {
|
|
537
|
-
...number,
|
|
538
|
-
transform: Math.round,
|
|
539
|
-
};
|
|
540
|
-
|
|
541
|
-
const numberValueTypes = {
|
|
542
|
-
...browserNumberValueTypes,
|
|
543
|
-
...transformValueTypes,
|
|
544
|
-
zIndex: int,
|
|
545
|
-
size: px,
|
|
546
|
-
// SVG
|
|
547
|
-
fillOpacity: alpha,
|
|
548
|
-
strokeOpacity: alpha,
|
|
549
|
-
numOctaves: int,
|
|
550
|
-
};
|
|
551
|
-
|
|
552
395
|
const translateAlias = {
|
|
553
396
|
x: "translateX",
|
|
554
397
|
y: "translateY",
|
|
555
398
|
z: "translateZ",
|
|
556
399
|
transformPerspective: "perspective",
|
|
557
400
|
};
|
|
558
|
-
const numTransforms = transformPropOrder.length;
|
|
401
|
+
const numTransforms = motionDom.transformPropOrder.length;
|
|
559
402
|
/**
|
|
560
403
|
* Build a CSS transform style from individual x/y/scale etc properties.
|
|
561
404
|
*
|
|
@@ -571,7 +414,7 @@ function buildTransform(latestValues, transform, transformTemplate) {
|
|
|
571
414
|
* are present to the transform string.
|
|
572
415
|
*/
|
|
573
416
|
for (let i = 0; i < numTransforms; i++) {
|
|
574
|
-
const key = transformPropOrder[i];
|
|
417
|
+
const key = motionDom.transformPropOrder[i];
|
|
575
418
|
const value = latestValues[key];
|
|
576
419
|
if (value === undefined)
|
|
577
420
|
continue;
|
|
@@ -583,7 +426,7 @@ function buildTransform(latestValues, transform, transformTemplate) {
|
|
|
583
426
|
valueIsDefault = parseFloat(value) === 0;
|
|
584
427
|
}
|
|
585
428
|
if (!valueIsDefault || transformTemplate) {
|
|
586
|
-
const valueAsType = getValueAsType(value, numberValueTypes[key]);
|
|
429
|
+
const valueAsType = motionDom.getValueAsType(value, motionDom.numberValueTypes[key]);
|
|
587
430
|
if (!valueIsDefault) {
|
|
588
431
|
transformIsDefault = false;
|
|
589
432
|
const transformName = translateAlias[key] || key;
|
|
@@ -619,18 +462,18 @@ function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
|
619
462
|
*/
|
|
620
463
|
for (const key in latestValues) {
|
|
621
464
|
const value = latestValues[key];
|
|
622
|
-
if (transformProps.has(key)) {
|
|
465
|
+
if (motionDom.transformProps.has(key)) {
|
|
623
466
|
// If this is a transform, flag to enable further transform processing
|
|
624
467
|
hasTransform = true;
|
|
625
468
|
continue;
|
|
626
469
|
}
|
|
627
|
-
else if (isCSSVariableName(key)) {
|
|
470
|
+
else if (motionDom.isCSSVariableName(key)) {
|
|
628
471
|
vars[key] = value;
|
|
629
472
|
continue;
|
|
630
473
|
}
|
|
631
474
|
else {
|
|
632
475
|
// Convert the value to its default value type, ie 0 -> "0px"
|
|
633
|
-
const valueAsType = getValueAsType(value, numberValueTypes[key]);
|
|
476
|
+
const valueAsType = motionDom.getValueAsType(value, motionDom.numberValueTypes[key]);
|
|
634
477
|
if (key.startsWith("origin")) {
|
|
635
478
|
// If this is a transform origin, flag and enable further transform-origin processing
|
|
636
479
|
hasTransformOrigin = true;
|
|
@@ -914,17 +757,17 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
914
757
|
// when defining props on a React component.
|
|
915
758
|
const keys = useDashCase ? dashKeys : camelKeys;
|
|
916
759
|
// Build the dash offset
|
|
917
|
-
attrs[keys.offset] = px.transform(-offset);
|
|
760
|
+
attrs[keys.offset] = motionDom.px.transform(-offset);
|
|
918
761
|
// Build the dash array
|
|
919
|
-
const pathLength = px.transform(length);
|
|
920
|
-
const pathSpacing = px.transform(spacing);
|
|
762
|
+
const pathLength = motionDom.px.transform(length);
|
|
763
|
+
const pathSpacing = motionDom.px.transform(spacing);
|
|
921
764
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
922
765
|
}
|
|
923
766
|
|
|
924
767
|
function calcOrigin(origin, offset, size) {
|
|
925
768
|
return typeof origin === "string"
|
|
926
769
|
? origin
|
|
927
|
-
: px.transform(offset + size * origin);
|
|
770
|
+
: motionDom.px.transform(offset + size * origin);
|
|
928
771
|
}
|
|
929
772
|
/**
|
|
930
773
|
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
@@ -1265,7 +1108,7 @@ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
|
1265
1108
|
for (const key in props) {
|
|
1266
1109
|
if (isMotionValue(props[key]) ||
|
|
1267
1110
|
isMotionValue(prevProps[key])) {
|
|
1268
|
-
const targetKey = transformPropOrder.indexOf(key) !== -1
|
|
1111
|
+
const targetKey = motionDom.transformPropOrder.indexOf(key) !== -1
|
|
1269
1112
|
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
|
|
1270
1113
|
: key;
|
|
1271
1114
|
newValues[targetKey] = props[key];
|
|
@@ -1285,7 +1128,7 @@ const svgMotionConfig = {
|
|
|
1285
1128
|
let hasTransform = !!props.drag;
|
|
1286
1129
|
if (!hasTransform) {
|
|
1287
1130
|
for (const key in latestValues) {
|
|
1288
|
-
if (transformProps.has(key)) {
|
|
1131
|
+
if (motionDom.transformProps.has(key)) {
|
|
1289
1132
|
hasTransform = true;
|
|
1290
1133
|
break;
|
|
1291
1134
|
}
|
package/dist/cjs/mini.js
CHANGED
|
@@ -29,7 +29,27 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
29
29
|
const elements = motionDom.resolveElements(elementOrSelector, scope);
|
|
30
30
|
const numElements = elements.length;
|
|
31
31
|
motionUtils.invariant(Boolean(numElements), "No valid element provided.");
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* WAAPI doesn't support interrupting animations.
|
|
34
|
+
*
|
|
35
|
+
* Therefore, starting animations requires a three-step process:
|
|
36
|
+
* 1. Stop existing animations (write styles to DOM)
|
|
37
|
+
* 2. Resolve keyframes (read styles from DOM)
|
|
38
|
+
* 3. Create new animations (write styles to DOM)
|
|
39
|
+
*
|
|
40
|
+
* The hybrid `animate()` function uses AsyncAnimation to resolve
|
|
41
|
+
* keyframes before creating new animations, which removes style
|
|
42
|
+
* thrashing. Here, we have much stricter filesize constraints.
|
|
43
|
+
* Therefore we do this in a synchronous way that ensures that
|
|
44
|
+
* at least within `animate()` calls there is no style thrashing.
|
|
45
|
+
*
|
|
46
|
+
* In the motion-native-animate-mini-interrupt benchmark this
|
|
47
|
+
* was 80% faster than a single loop.
|
|
48
|
+
*/
|
|
49
|
+
const animationDefinitions = [];
|
|
50
|
+
/**
|
|
51
|
+
* Step 1: Build options and stop existing animations (write)
|
|
52
|
+
*/
|
|
33
53
|
for (let i = 0; i < numElements; i++) {
|
|
34
54
|
const element = elements[i];
|
|
35
55
|
const elementTransition = { ...options };
|
|
@@ -40,20 +60,68 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
40
60
|
elementTransition.delay = elementTransition.delay(i, numElements);
|
|
41
61
|
}
|
|
42
62
|
for (const valueName in keyframes) {
|
|
43
|
-
|
|
63
|
+
let valueKeyframes = keyframes[valueName];
|
|
64
|
+
if (!Array.isArray(valueKeyframes)) {
|
|
65
|
+
valueKeyframes = [valueKeyframes];
|
|
66
|
+
}
|
|
44
67
|
const valueOptions = {
|
|
45
68
|
...motionDom.getValueTransition(elementTransition, valueName),
|
|
46
69
|
};
|
|
47
70
|
valueOptions.duration && (valueOptions.duration = motionUtils.secondsToMilliseconds(valueOptions.duration));
|
|
48
71
|
valueOptions.delay && (valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay));
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
/**
|
|
73
|
+
* If there's an existing animation playing on this element then stop it
|
|
74
|
+
* before creating a new one.
|
|
75
|
+
*/
|
|
76
|
+
const map = motionDom.getAnimationMap(element);
|
|
77
|
+
const key = motionDom.animationMapKey(valueName, valueOptions.pseudoElement || "");
|
|
78
|
+
const currentAnimation = map.get(key);
|
|
79
|
+
currentAnimation && currentAnimation.stop();
|
|
80
|
+
animationDefinitions.push({
|
|
81
|
+
map,
|
|
82
|
+
key,
|
|
83
|
+
unresolvedKeyframes: valueKeyframes,
|
|
84
|
+
options: {
|
|
85
|
+
...valueOptions,
|
|
86
|
+
element,
|
|
87
|
+
name: valueName,
|
|
88
|
+
allowFlatten: !elementTransition.type && !elementTransition.ease,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Step 2: Resolve keyframes (read)
|
|
95
|
+
*/
|
|
96
|
+
for (let i = 0; i < animationDefinitions.length; i++) {
|
|
97
|
+
const { unresolvedKeyframes, options: animationOptions } = animationDefinitions[i];
|
|
98
|
+
const { element, name, pseudoElement } = animationOptions;
|
|
99
|
+
if (!pseudoElement && unresolvedKeyframes[0] === null) {
|
|
100
|
+
unresolvedKeyframes[0] = motionDom.getComputedStyle(element, name);
|
|
101
|
+
}
|
|
102
|
+
motionDom.fillWildcards(unresolvedKeyframes);
|
|
103
|
+
motionDom.applyPxDefaults(unresolvedKeyframes, name);
|
|
104
|
+
/**
|
|
105
|
+
* If we only have one keyframe, explicitly read the initial keyframe
|
|
106
|
+
* from the computed style. This is to ensure consistency with WAAPI behaviour
|
|
107
|
+
* for restarting animations, for instance .play() after finish, when it
|
|
108
|
+
* has one vs two keyframes.
|
|
109
|
+
*/
|
|
110
|
+
if (!pseudoElement && unresolvedKeyframes.length < 2) {
|
|
111
|
+
unresolvedKeyframes.unshift(motionDom.getComputedStyle(element, name));
|
|
56
112
|
}
|
|
113
|
+
animationOptions.keyframes = unresolvedKeyframes;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Step 3: Create new animations (write)
|
|
117
|
+
*/
|
|
118
|
+
const animations = [];
|
|
119
|
+
for (let i = 0; i < animationDefinitions.length; i++) {
|
|
120
|
+
const { map, key, options: animationOptions } = animationDefinitions[i];
|
|
121
|
+
const animation = new motionDom.NativeAnimation(animationOptions);
|
|
122
|
+
map.set(key, animation);
|
|
123
|
+
animation.finished.finally(() => map.delete(key));
|
|
124
|
+
animations.push(animation);
|
|
57
125
|
}
|
|
58
126
|
return animations;
|
|
59
127
|
}
|
package/dist/dom-mini.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Motion={})}(this,(function(t){"use strict";function e(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}function n(t){let e;return()=>(void 0===e&&(e=t()),e)}const i=t=>t,a=(t,e,n)=>{const i=e-t;return 0===i?1:(n-t)/i},r=t=>1e3*t,o=t=>t/1e3,s=n((()=>void 0!==window.ScrollTimeline));class l{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map((t=>t.finished)))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t,e){const n=this.animations.map((n=>s()&&n.attachTimeline?n.attachTimeline(t):"function"==typeof e?e(n):void 0));return()=>{n.forEach(((t,e)=>{t&&t(),this.animations[e].stop()}))}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get startTime(){return this.getAll("startTime")}get duration(){let t=0;for(let e=0;e<this.animations.length;e++)t=Math.max(t,this.animations[e].duration);return t}runAll(t){this.animations.forEach((e=>e[t]()))}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}class u extends l{then(t,e){return this.finished.finally(t).then((()=>{}))}}const c=t=>t.startsWith("--"),h=(t,e,n)=>{c(e)?t.style.setProperty(e,n):t.style[e]=n},f=(t,e)=>c(e)?t.style.getPropertyValue(e):t.style[e],m=t=>null!==t;const d=n((()=>{try{document.createElement("div").animate({opacity:[1]})}catch(t){return!1}return!0})),p=new Set(["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderRadius","radius","borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius","width","maxWidth","height","maxHeight","top","right","bottom","left","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","margin","marginTop","marginRight","marginBottom","marginLeft","backgroundPositionX","backgroundPositionY"]);const y={};function g(t,e){const i=n(t);return()=>y[e]??i()}const A=g((()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0}),"linearEasing"),b=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,T={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:b([0,.65,.55,1]),circOut:b([.55,0,1,.45]),backIn:b([.31,.01,.66,-.59]),backOut:b([.33,1.53,.69,.99])};function v(t,e){return t?"function"==typeof t&&A()?((t,e,n=10)=>{let i="";const a=Math.max(Math.round(e/n),2);for(let e=0;e<a;e++)i+=t(e/(a-1))+", ";return`linear(${i.substring(0,i.length-2)})`})(t,e):(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?b(t):Array.isArray(t)?t.map((t=>v(t,e)||T.easeOut)):T[t]:void 0}function w(t){return"function"==typeof t&&"applyToOptions"in t}const x=new WeakMap;class k{constructor(t){if("animation"in t)return void(this.animation=t.animation);const{element:e,name:n,keyframes:i,pseudoElement:a,allowFlatten:r=!1}=t;let{transition:o}=t;this.isPseudoElement=Boolean(a),this.allowFlatten=r;const s=function(t){const e=x.get(t)||new Map;return x.set(t,e),e}(e),l=((t,e)=>`${t}:${e}`)(n,a||""),u=s.get(l);u&&u.stop();const c=function(t,e,n,i){Array.isArray(n)||(n=[n]);for(let a=0;a<n.length;a++)null===n[a]&&(n[a]=0!==a||i?n[a-1]:f(t,e)),"number"==typeof n[a]&&p.has(e)&&(n[a]=n[a]+"px");return!i&&!d()&&n.length<2&&n.unshift(f(t,e)),n}(e,n,i,a);o.type,o=function({type:t,...e}){return w(t)?t.applyToOptions(e):(e.duration??(e.duration=300),e.ease??(e.ease="easeOut"),e)}(o),this.animation=function(t,e,n,{delay:i=0,duration:a=300,repeat:r=0,repeatType:o="loop",ease:s="easeInOut",times:l}={},u){const c={[e]:n};l&&(c.offset=l);const h=v(s,a);return Array.isArray(h)&&(c.easing=h),t.animate(c,{delay:i,duration:a,easing:Array.isArray(h)?"linear":h,fill:"both",iterations:r+1,direction:"reverse"===o?"alternate":"normal",pseudoElement:u})}(e,n,c,o,a),!1===o.autoplay&&this.animation.pause(),this.removeAnimation=()=>s.delete(l),this.animation.onfinish=()=>{a||(h(e,n,function(t,{repeat:e,repeatType:n="loop"},i){const a=t.filter(m),r=e&&"loop"!==n&&e%2==1?0:a.length-1;return r&&void 0!==i?i:a[r]}(c,o)),this.cancel())},s.set(l,this)}play(){this.animation.play()}pause(){this.animation.pause()}complete(){this.animation.finish()}cancel(){try{this.animation.cancel()}catch(t){}this.removeAnimation()}stop(){const{state:t}=this;"idle"!==t&&"finished"!==t&&(this.commitStyles(),this.cancel())}commitStyles(){this.isPseudoElement||this.animation.commitStyles?.()}get duration(){const t=this.animation.effect?.getComputedTiming().duration||0;return o(Number(t))}get time(){return o(Number(this.animation.currentTime)||0)}set time(t){this.animation.currentTime=r(t)}get speed(){return this.animation.playbackRate}set speed(t){this.animation.playbackRate=t}get state(){return this.animation.playState}get startTime(){return Number(this.animation.startTime)}get finished(){return this.animation.finished}flatten(){this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"})}attachTimeline(t){return this.animation.timeline=t,this.animation.onfinish=null,i}then(t,e){return this.finished.then(t).catch(e)}}const M=2e4;function O(t,e=100,n){const i=n({...t,keyframes:[0,e]}),a=Math.min(function(t){let e=0,n=t.next(e);for(;!n.done&&e<M;)e+=50,n=t.next(e);return e>=M?1/0:e}(i),M);return{type:"keyframes",ease:t=>i.next(a*t).value/e,duration:o(a)}}function E(t,e,n){if(t instanceof EventTarget)return[t];if("string"==typeof t){let i=document;e&&(i=e.current);const a=n?.[t]??i.querySelectorAll(t);return a?Array.from(a):[]}return Array.from(t)}function R(t,e){return n=t,Array.isArray(n)&&"number"!=typeof n[0]?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t;var n}const W=(t,e,n)=>t+(e-t)*n;function B(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const r=a(0,e,i);t.push(W(n,1,r))}}function S(t){const e=[0];return B(e,t.length-1),e}function P(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?E(t,n,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function $(t,e,n){return t*(e+1)}function I(t,e,n,i){return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:i.get(e)??t}function L(t,n,i,a,r,o){!function(t,n,i){for(let a=0;a<t.length;a++){const r=t[a];r.at>n&&r.at<i&&(e(t,r),a--)}}(t,r,o);for(let e=0;e<n.length;e++)t.push({value:n[e],at:W(r,o,a[e]),easing:R(i,e)})}function F(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function N(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function j(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function q(t,e){return e[t]||(e[t]=[]),e[t]}function V(t){return Array.isArray(t)?t:[t]}function z(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const C=t=>"number"==typeof t,D=t=>t.every(C);function H(t,e,n,i){const a=E(t,i),o=a.length,s=[];for(let t=0;t<o;t++){const i=a[t],c={...n};"function"==typeof c.delay&&(c.delay=c.delay(t,o));for(const t in e){const n=e[t],a={...(l=c,u=t,l?.[u]??l?.default??l)};a.duration&&(a.duration=r(a.duration)),a.delay&&(a.delay=r(a.delay)),s.push(new k({element:i,name:t,keyframes:n,transition:a,allowFlatten:!c.type&&!c.ease}))}}var l,u;return s}const X=(t=>function(e,n,i){return new u(H(e,n,i,t))})();t.animate=X,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,o){const s=e.duration||.3,l=new Map,u=new Map,c={},h=new Map;let f=0,m=0,d=0;for(let n=0;n<t.length;n++){const a=t[n];if("string"==typeof a){h.set(a,m);continue}if(!Array.isArray(a)){h.set(a.name,I(m,a.at,f,h));continue}let[l,y,g={}]=a;void 0!==g.at&&(m=I(m,g.at,f,h));let A=0;const b=(t,n,i,a=0,l=0)=>{const u=V(t),{delay:c=0,times:h=S(u),type:f="keyframes",repeat:p,repeatType:y,repeatDelay:g=0,...b}=n;let{ease:T=e.ease||"easeOut",duration:v}=n;const x="function"==typeof c?c(a,l):c,k=u.length,M=w(f)?f:o?.[f];if(k<=2&&M){let t=100;if(2===k&&D(u)){const e=u[1]-u[0];t=Math.abs(e)}const e={...b};void 0!==v&&(e.duration=r(v));const n=O(e,t,M);T=n.ease,v=n.duration}v??(v=s);const E=m+x;1===h.length&&0===h[0]&&(h[1]=1);const W=h.length-u.length;if(W>0&&B(h,W),1===u.length&&u.unshift(null),p){v=$(v,p);const t=[...u],e=[...h];T=Array.isArray(T)?[...T]:[T];const n=[...T];for(let i=0;i<p;i++){u.push(...t);for(let a=0;a<t.length;a++)h.push(e[a]+(i+1)),T.push(0===a?"linear":R(n,a-1))}F(h,p)}const P=E+v;L(i,u,T,h,E,P),A=Math.max(x+v,A),d=Math.max(P,d)};if(p=l,Boolean(p&&p.getVelocity))b(y,g,q("default",j(l,u)));else{const t=P(l,y,i,c),e=t.length;for(let n=0;n<e;n++){const i=j(t[n],u);for(const t in y)b(y[t],z(g,t),q(t,i),n,e)}}f=m,m+=A}var p;return u.forEach(((t,i)=>{for(const r in t){const o=t[r];o.sort(N);const s=[],u=[],c=[];for(let t=0;t<o.length;t++){const{at:e,value:n,easing:i}=o[t];s.push(n),u.push(a(0,d,e)),c.push(i||"easeOut")}0!==u[0]&&(u.unshift(0),s.unshift(s[0]),c.unshift("easeInOut")),1!==u[u.length-1]&&(u.push(1),s.push(null)),l.has(i)||l.set(i,{keyframes:{},transition:{}});const h=l.get(i);h.keyframes[r]=s,h.transition[r]={...e,duration:d,ease:c,times:u,...n}}})),l}(t,e).forEach((({keyframes:t,transition:e},i)=>{n.push(...H(i,t,e))})),new u(n)}}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Motion={})}(this,(function(t){"use strict";function e(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}function n(t){let e;return()=>(void 0===e&&(e=t()),e)}const i=t=>t,s=(t,e,n)=>{const i=e-t;return 0===i?1:(n-t)/i},o=t=>1e3*t,a=t=>t/1e3;function r(t,e){return n=t,Array.isArray(n)&&"number"!=typeof n[0]?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t;var n}const u=(t,e,n)=>t+(e-t)*n,l=2e4;function h(t,e=100,n){const i=n({...t,keyframes:[0,e]}),s=Math.min(function(t){let e=0,n=t.next(e);for(;!n.done&&e<l;)e+=50,n=t.next(e);return e>=l?1/0:e}(i),l);return{type:"keyframes",ease:t=>i.next(s*t).value/e,duration:a(s)}}function c(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const o=s(0,e,i);t.push(u(n,1,o))}}function f(t){const e=[0];return c(e,t.length-1),e}const d=t=>null!==t;class m{constructor(){this.count=0,this.updateFinished()}get finished(){return this._finished}updateFinished(){this.count++,this._finished=new Promise((t=>{this.resolve=t}))}notifyFinished(){this.resolve()}then(t,e){return this.finished.then(t,e)}}function p(t){for(let e=1;e<t.length;e++)t[e]??(t[e]=t[e-1])}const y=t=>t.startsWith("--");const g=n((()=>void 0!==window.ScrollTimeline)),A={};function b(t,e){const i=n(t);return()=>A[e]??i()}const T=b((()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0}),"linearEasing"),v=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,w={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:v([0,.65,.55,1]),circOut:v([.55,0,1,.45]),backIn:v([.31,.01,.66,-.59]),backOut:v([.33,1.53,.69,.99])};function M(t,e){return t?"function"==typeof t?T()?((t,e,n=10)=>{let i="";const s=Math.max(Math.round(e/n),2);for(let e=0;e<s;e++)i+=t(e/(s-1))+", ";return`linear(${i.substring(0,i.length-2)})`})(t,e):"ease-out":(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?v(t):Array.isArray(t)?t.map((t=>M(t,e)||w.easeOut)):w[t]:void 0}function k(t){return"function"==typeof t&&"applyToOptions"in t}class x extends m{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,!t)return;const{element:e,name:n,keyframes:i,pseudoElement:s,allowFlatten:o=!1,finalKeyframe:a}=t;this.isPseudoElement=Boolean(s),this.allowFlatten=o,this.options=t,t.type;const r=function({type:t,...e}){return k(t)&&T()?t.applyToOptions(e):(e.duration??(e.duration=300),e.ease??(e.ease="easeOut"),e)}(t);this.animation=function(t,e,n,{delay:i=0,duration:s=300,repeat:o=0,repeatType:a="loop",ease:r="easeOut",times:u}={},l){const h={[e]:n};u&&(h.offset=u);const c=M(r,s);Array.isArray(c)&&(h.easing=c);const f={delay:i,duration:s,easing:Array.isArray(c)?"linear":c,fill:"both",iterations:o+1,direction:"reverse"===a?"alternate":"normal"};return l&&(f.pseudoElement=l),t.animate(h,f)}(e,n,i,r,s),!1===r.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!s){const t=function(t,{repeat:e,repeatType:n="loop"},i,s=1){const o=t.filter(d),a=s<0||e&&"loop"!==n&&e%2==1?0:o.length-1;return a&&void 0!==i?i:o[a]}(i,this.options,a,this.speed);this.updateMotionValue?this.updateMotionValue(t):function(t,e,n){y(e)?t.style.setProperty(e,n):t.style[e]=n}(e,n,t),this.animation.cancel()}this.notifyFinished()}}play(){this.isStopped||(this.animation.play(),"finished"===this.state&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch(t){}}stop(){if(this.isStopped)return;this.isStopped=!0;const{state:t}=this;"idle"!==t&&"finished"!==t&&(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||this.cancel())}commitStyles(){this.isPseudoElement||this.animation.commitStyles?.()}get duration(){const t=this.animation.effect?.getComputedTiming?.().duration||0;return a(Number(t))}get time(){return a(Number(this.animation.currentTime)||0)}set time(t){this.finishedTime=null,this.animation.currentTime=o(t)}get speed(){return this.animation.playbackRate}set speed(t){t<0&&(this.finishedTime=null),this.animation.playbackRate=t}get state(){return null!==this.finishedTime?"finished":this.animation.playState}get startTime(){return Number(this.animation.startTime)}set startTime(t){this.animation.startTime=t}attachTimeline({timeline:t,observe:e}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&g()?(this.animation.timeline=t,i):e(this)}}class E{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map((t=>t.finished)))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t){const e=this.animations.map((e=>e.attachTimeline(t)));return()=>{e.forEach(((t,e)=>{t&&t(),this.animations[e].stop()}))}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get state(){return this.getAll("state")}get startTime(){return this.getAll("startTime")}get duration(){let t=0;for(let e=0;e<this.animations.length;e++)t=Math.max(t,this.animations[e].duration);return t}runAll(t){this.animations.forEach((e=>e[t]()))}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}class O extends E{then(t,e){return this.finished.finally(t).then((()=>{}))}}const S=new WeakMap,R=(t,e="")=>`${t}:${e}`;function F(t){const e=S.get(t)||new Map;return S.set(t,e),e}function W(t,e){return t?.[e]??t?.default??t}const P=new Set(["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderRadius","radius","borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius","width","maxWidth","height","maxHeight","top","right","bottom","left","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","margin","marginTop","marginRight","marginBottom","marginLeft","backgroundPositionX","backgroundPositionY"]);function B(t,e){for(let n=0;n<t.length;n++)"number"==typeof t[n]&&P.has(e)&&(t[n]=t[n]+"px")}function $(t,e,n){if(t instanceof EventTarget)return[t];if("string"==typeof t){let i=document;e&&(i=e.current);const s=n?.[t]??i.querySelectorAll(t);return s?Array.from(s):[]}return Array.from(t)}function L(t,e){const n=window.getComputedStyle(t);return y(e)?n.getPropertyValue(e):n[e]}function V(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?$(t,n,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function I(t,e,n){return t*(e+1)}function N(t,e,n,i){return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:i.get(e)??t}function K(t,n,i,s,o,a){!function(t,n,i){for(let s=0;s<t.length;s++){const o=t[s];o.at>n&&o.at<i&&(e(t,o),s--)}}(t,o,a);for(let e=0;e<n.length;e++)t.push({value:n[e],at:u(o,a,s[e]),easing:r(i,e)})}function j(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function q(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function C(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function _(t,e){return e[t]||(e[t]=[]),e[t]}function z(t){return Array.isArray(t)?t:[t]}function D(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const H=t=>"number"==typeof t,X=t=>t.every(H);function Y(t,e,n,i){const s=$(t,i),a=s.length,r=[];for(let t=0;t<a;t++){const i=s[t],u={...n};"function"==typeof u.delay&&(u.delay=u.delay(t,a));for(const t in e){let n=e[t];Array.isArray(n)||(n=[n]);const s={...W(u,t)};s.duration&&(s.duration=o(s.duration)),s.delay&&(s.delay=o(s.delay));const a=F(i),l=R(t,s.pseudoElement||""),h=a.get(l);h&&h.stop(),r.push({map:a,key:l,unresolvedKeyframes:n,options:{...s,element:i,name:t,allowFlatten:!u.type&&!u.ease}})}}for(let t=0;t<r.length;t++){const{unresolvedKeyframes:e,options:n}=r[t],{element:i,name:s,pseudoElement:o}=n;o||null!==e[0]||(e[0]=L(i,s)),p(e),B(e,s),!o&&e.length<2&&e.unshift(L(i,s)),n.keyframes=e}const u=[];for(let t=0;t<r.length;t++){const{map:e,key:n,options:i}=r[t],s=new x(i);e.set(n,s),s.finished.finally((()=>e.delete(n))),u.push(s)}return u}const G=(t=>function(e,n,i){return new O(Y(e,n,i,t))})();t.animate=G,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,a){const u=e.duration||.3,l=new Map,d=new Map,m={},p=new Map;let y=0,g=0,A=0;for(let n=0;n<t.length;n++){const s=t[n];if("string"==typeof s){p.set(s,g);continue}if(!Array.isArray(s)){p.set(s.name,N(g,s.at,y,p));continue}let[l,T,v={}]=s;void 0!==v.at&&(g=N(g,v.at,y,p));let w=0;const M=(t,n,i,s=0,l=0)=>{const d=z(t),{delay:m=0,times:p=f(d),type:y="keyframes",repeat:b,repeatType:T,repeatDelay:v=0,...M}=n;let{ease:x=e.ease||"easeOut",duration:E}=n;const O="function"==typeof m?m(s,l):m,S=d.length,R=k(y)?y:a?.[y];if(S<=2&&R){let t=100;if(2===S&&X(d)){const e=d[1]-d[0];t=Math.abs(e)}const e={...M};void 0!==E&&(e.duration=o(E));const n=h(e,t,R);x=n.ease,E=n.duration}E??(E=u);const F=g+O;1===p.length&&0===p[0]&&(p[1]=1);const W=p.length-d.length;if(W>0&&c(p,W),1===d.length&&d.unshift(null),b){E=I(E,b);const t=[...d],e=[...p];x=Array.isArray(x)?[...x]:[x];const n=[...x];for(let i=0;i<b;i++){d.push(...t);for(let s=0;s<t.length;s++)p.push(e[s]+(i+1)),x.push(0===s?"linear":r(n,s-1))}j(p,b)}const P=F+E;K(i,d,x,p,F,P),w=Math.max(O+E,w),A=Math.max(P,A)};if(b=l,Boolean(b&&b.getVelocity))M(T,v,_("default",C(l,d)));else{const t=V(l,T,i,m),e=t.length;for(let n=0;n<e;n++){const i=C(t[n],d);for(const t in T)M(T[t],D(v,t),_(t,i),n,e)}}y=g,g+=w}var b;return d.forEach(((t,i)=>{for(const o in t){const a=t[o];a.sort(q);const r=[],u=[],h=[];for(let t=0;t<a.length;t++){const{at:e,value:n,easing:i}=a[t];r.push(n),u.push(s(0,A,e)),h.push(i||"easeOut")}0!==u[0]&&(u.unshift(0),r.unshift(r[0]),h.unshift("easeInOut")),1!==u[u.length-1]&&(u.push(1),r.push(null)),l.has(i)||l.set(i,{keyframes:{},transition:{}});const c=l.get(i);c.keyframes[o]=r,c.transition[o]={...e,duration:A,ease:h,times:u,...n}}})),l}(t,e).forEach((({keyframes:t,transition:e},i)=>{n.push(...Y(i,t,e))})),new O(n)}}));
|
package/dist/dom.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { MotionValue, UnresolvedValueKeyframe, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, AnimationPlaybackOptions, Easing, AnimationScope, AnimationPlaybackControlsWithThen, ValueAnimationTransition, EasingFunction, ProgressTimeline, AnimationPlaybackControls, EasingModifier, ValueAnimationOptions, KeyframeGenerator, DynamicOption } from 'motion-dom';
|
|
1
|
+
import { MotionValue, UnresolvedValueKeyframe, Transition, ElementOrSelector, DOMKeyframesDefinition, AnimationOptions, AnimationPlaybackOptions, AnimationScope, AnimationPlaybackControlsWithThen, ValueAnimationTransition, AnimationPlaybackControls, DynamicOption } from 'motion-dom';
|
|
3
2
|
export * from 'motion-dom';
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
interface Point {
|
|
8
|
-
x: number;
|
|
9
|
-
y: number;
|
|
10
|
-
}
|
|
3
|
+
import { Easing, EasingFunction, Point } from 'motion-utils';
|
|
4
|
+
export * from 'motion-utils';
|
|
11
5
|
|
|
12
6
|
type GenericKeyframesTarget<V> = V[] | Array<null | V>;
|
|
13
7
|
|
|
@@ -136,19 +130,7 @@ interface ScrollInfoOptions {
|
|
|
136
130
|
offset?: ScrollOffset;
|
|
137
131
|
}
|
|
138
132
|
|
|
139
|
-
declare
|
|
140
|
-
interface Window {
|
|
141
|
-
ScrollTimeline: ScrollTimeline;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
declare class ScrollTimeline implements ProgressTimeline {
|
|
145
|
-
constructor(options: ScrollOptions);
|
|
146
|
-
currentTime: null | {
|
|
147
|
-
value: number;
|
|
148
|
-
};
|
|
149
|
-
cancel?: VoidFunction;
|
|
150
|
-
}
|
|
151
|
-
declare function scroll(onScroll: OnScroll | AnimationPlaybackControls, { axis, ...options }?: ScrollOptions): VoidFunction;
|
|
133
|
+
declare function scroll(onScroll: OnScroll | AnimationPlaybackControls, { axis, container, ...options }?: ScrollOptions): VoidFunction;
|
|
152
134
|
|
|
153
135
|
declare function scrollInfo(onScroll: OnScrollInfo, { container, ...options }?: ScrollInfoOptions): () => void;
|
|
154
136
|
|
|
@@ -162,38 +144,6 @@ interface InViewOptions {
|
|
|
162
144
|
}
|
|
163
145
|
declare function inView(elementOrSelector: ElementOrSelector, onStart: (element: Element, entry: IntersectionObserverEntry) => void | ViewChangeHandler, { root, margin: rootMargin, amount }?: InViewOptions): VoidFunction;
|
|
164
146
|
|
|
165
|
-
declare const anticipate: (p: number) => number;
|
|
166
|
-
|
|
167
|
-
declare const backOut: (t: number) => number;
|
|
168
|
-
declare const backIn: motion_dom.EasingFunction;
|
|
169
|
-
declare const backInOut: motion_dom.EasingFunction;
|
|
170
|
-
|
|
171
|
-
declare const circIn: EasingFunction;
|
|
172
|
-
declare const circOut: EasingFunction;
|
|
173
|
-
declare const circInOut: EasingFunction;
|
|
174
|
-
|
|
175
|
-
declare function cubicBezier(mX1: number, mY1: number, mX2: number, mY2: number): (t: number) => number;
|
|
176
|
-
|
|
177
|
-
declare const easeIn: (t: number) => number;
|
|
178
|
-
declare const easeOut: (t: number) => number;
|
|
179
|
-
declare const easeInOut: (t: number) => number;
|
|
180
|
-
|
|
181
|
-
declare const mirrorEasing: EasingModifier;
|
|
182
|
-
|
|
183
|
-
declare const reverseEasing: EasingModifier;
|
|
184
|
-
|
|
185
|
-
type Direction = "start" | "end";
|
|
186
|
-
declare function steps(numSteps: number, direction?: Direction): EasingFunction;
|
|
187
|
-
|
|
188
|
-
declare function inertia({ keyframes, velocity, power, timeConstant, bounceDamping, bounceStiffness, modifyTarget, min, max, restDelta, restSpeed, }: ValueAnimationOptions<number>): KeyframeGenerator<number>;
|
|
189
|
-
|
|
190
|
-
declare function keyframes<T extends string | number>({ duration, keyframes: keyframeValues, times, ease, }: ValueAnimationOptions<T>): KeyframeGenerator<T>;
|
|
191
|
-
|
|
192
|
-
declare function spring(optionsOrVisualDuration?: ValueAnimationOptions<number> | number, bounce?: number): KeyframeGenerator<number>;
|
|
193
|
-
declare namespace spring {
|
|
194
|
-
var applyToOptions: (options: Transition) => Transition;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
147
|
type StaggerOrigin = "first" | "last" | "center" | number;
|
|
198
148
|
type StaggerOptions = {
|
|
199
149
|
startDelay?: number;
|
|
@@ -202,49 +152,12 @@ type StaggerOptions = {
|
|
|
202
152
|
};
|
|
203
153
|
declare function stagger(duration?: number, { startDelay, from, ease }?: StaggerOptions): DynamicOption<number>;
|
|
204
154
|
|
|
205
|
-
declare const clamp: (min: number, max: number, v: number) => number;
|
|
206
|
-
|
|
207
155
|
type DelayedFunction = (overshoot: number) => void;
|
|
208
156
|
declare function delayInSeconds(callback: DelayedFunction, timeout: number): () => void;
|
|
209
157
|
|
|
210
158
|
declare const distance: (a: number, b: number) => number;
|
|
211
159
|
declare function distance2D(a: Point, b: Point): number;
|
|
212
160
|
|
|
213
|
-
type Mix<T> = (v: number) => T;
|
|
214
|
-
type MixerFactory<T> = (from: T, to: T) => Mix<T>;
|
|
215
|
-
interface InterpolateOptions<T> {
|
|
216
|
-
clamp?: boolean;
|
|
217
|
-
ease?: EasingFunction | EasingFunction[];
|
|
218
|
-
mixer?: MixerFactory<T>;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Create a function that maps from a numerical input array to a generic output array.
|
|
222
|
-
*
|
|
223
|
-
* Accepts:
|
|
224
|
-
* - Numbers
|
|
225
|
-
* - Colors (hex, hsl, hsla, rgb, rgba)
|
|
226
|
-
* - Complex (combinations of one or more numbers or strings)
|
|
227
|
-
*
|
|
228
|
-
* ```jsx
|
|
229
|
-
* const mixColor = interpolate([0, 1], ['#fff', '#000'])
|
|
230
|
-
*
|
|
231
|
-
* mixColor(0.5) // 'rgba(128, 128, 128, 1)'
|
|
232
|
-
* ```
|
|
233
|
-
*
|
|
234
|
-
* TODO Revist this approach once we've moved to data models for values,
|
|
235
|
-
* probably not needed to pregenerate mixer functions.
|
|
236
|
-
*
|
|
237
|
-
* @public
|
|
238
|
-
*/
|
|
239
|
-
declare function interpolate<T>(input: number[], output: T[], { clamp: isClamp, ease, mixer }?: InterpolateOptions<T>): (v: number) => T;
|
|
240
|
-
|
|
241
|
-
type Mixer<T> = (p: number) => T;
|
|
242
|
-
|
|
243
|
-
declare function mix<T>(from: T, to: T): Mixer<T>;
|
|
244
|
-
declare function mix(from: number, to: number, p: number): number;
|
|
245
|
-
|
|
246
|
-
declare const pipe: (...transformers: Function[]) => Function;
|
|
247
|
-
|
|
248
161
|
/**
|
|
249
162
|
* @public
|
|
250
163
|
*/
|
|
@@ -338,6 +251,4 @@ declare function transform<T>(inputValue: number, inputRange: number[], outputRa
|
|
|
338
251
|
*/
|
|
339
252
|
declare function transform<T>(inputRange: number[], outputRange: T[], options?: TransformOptions<T>): (inputValue: number) => T;
|
|
340
253
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type DelayedFunction, type Direction, type InterpolateOptions, type MixerFactory, type MotionValueSegment, type MotionValueSegmentWithTransition, type ObjectSegment, type ObjectSegmentWithTransition, type ObjectTarget, type ResolvedAnimationDefinition, type ResolvedAnimationDefinitions, type Segment, type SequenceLabel, type SequenceLabelWithTime, type SequenceMap, type SequenceOptions, type SequenceTime, type ValueSequence, animate, animateMini, anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, clamp, createScopedAnimate, cubicBezier, delayInSeconds as delay, distance, distance2D, easeIn, easeInOut, easeOut, inView, inertia, interpolate, keyframes, mirrorEasing, mix, pipe, reverseEasing, scroll, scrollInfo, spring, stagger, steps, transform, wrap };
|
|
254
|
+
export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type DelayedFunction, type MotionValueSegment, type MotionValueSegmentWithTransition, type ObjectSegment, type ObjectSegmentWithTransition, type ObjectTarget, type ResolvedAnimationDefinition, type ResolvedAnimationDefinitions, type Segment, type SequenceLabel, type SequenceLabelWithTime, type SequenceMap, type SequenceOptions, type SequenceTime, type ValueSequence, animate, animateMini, createScopedAnimate, delayInSeconds as delay, distance, distance2D, inView, scroll, scrollInfo, stagger, transform };
|