framer-motion 12.6.2 → 12.6.3

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.
Files changed (66) hide show
  1. package/dist/cjs/client.js +1 -1
  2. package/dist/cjs/{create-BLp_edji.js → create-B2InJs4e.js} +68 -115
  3. package/dist/cjs/dom-mini.js +14 -219
  4. package/dist/cjs/dom.js +56 -199
  5. package/dist/cjs/index.js +32 -156
  6. package/dist/cjs/m.js +8 -12
  7. package/dist/cjs/mini.js +10 -214
  8. package/dist/dom-mini.d.ts +3 -3
  9. package/dist/dom-mini.js +1 -1
  10. package/dist/dom.d.ts +17 -14
  11. package/dist/dom.js +1 -1
  12. package/dist/es/animation/animate/index.mjs +2 -2
  13. package/dist/es/animation/animators/AcceleratedAnimation.mjs +5 -3
  14. package/dist/es/animation/animators/MainThreadAnimation.mjs +6 -4
  15. package/dist/es/animation/animators/waapi/animate-elements.mjs +10 -9
  16. package/dist/es/animation/animators/waapi/animate-sequence.mjs +2 -2
  17. package/dist/es/animation/animators/waapi/animate-style.mjs +2 -2
  18. package/dist/es/animation/generators/spring/index.mjs +9 -1
  19. package/dist/es/animation/interfaces/motion-value.mjs +2 -2
  20. package/dist/es/animation/interfaces/visual-element-target.mjs +1 -2
  21. package/dist/es/animation/interfaces/visual-element-variant.mjs +1 -2
  22. package/dist/es/animation/optimized-appear/handoff.mjs +2 -4
  23. package/dist/es/animation/optimized-appear/start.mjs +4 -6
  24. package/dist/es/animation/sequence/create.mjs +2 -2
  25. package/dist/es/animation/sequence/utils/calc-time.mjs +1 -2
  26. package/dist/es/components/AnimatePresence/index.mjs +2 -2
  27. package/dist/es/gestures/drag/VisualElementDragControls.mjs +5 -10
  28. package/dist/es/motion/features/animation/index.mjs +1 -2
  29. package/dist/es/motion/index.mjs +2 -3
  30. package/dist/es/motion/utils/use-visual-element.mjs +3 -5
  31. package/dist/es/projection/node/create-projection-node.mjs +17 -25
  32. package/dist/es/projection/styles/transform.mjs +1 -1
  33. package/dist/es/render/VisualElement.mjs +3 -4
  34. package/dist/es/render/dom/DOMKeyframesResolver.mjs +1 -2
  35. package/dist/es/render/dom/resize/handle-element.mjs +5 -6
  36. package/dist/es/render/dom/scroll/track.mjs +1 -2
  37. package/dist/es/render/dom/utils/css-variables-conversion.mjs +1 -1
  38. package/dist/es/render/dom/utils/filter-props.mjs +1 -1
  39. package/dist/es/render/html/utils/scrape-motion-values.mjs +1 -2
  40. package/dist/es/render/utils/KeyframesResolver.mjs +2 -3
  41. package/dist/es/render/utils/animation-state.mjs +3 -5
  42. package/dist/es/render/utils/motion-values.mjs +1 -1
  43. package/dist/es/render/utils/resolve-variants.mjs +1 -1
  44. package/dist/es/utils/mix/complex.mjs +1 -2
  45. package/dist/es/value/types/complex/index.mjs +2 -3
  46. package/dist/es/value/use-scroll.mjs +2 -2
  47. package/dist/framer-motion.dev.js +445 -414
  48. package/dist/framer-motion.js +1 -1
  49. package/dist/mini.d.ts +1 -1
  50. package/dist/mini.js +1 -1
  51. package/dist/size-rollup-animate.js +1 -1
  52. package/dist/size-rollup-dom-animation-assets.js +1 -1
  53. package/dist/size-rollup-dom-animation-m.js +1 -1
  54. package/dist/size-rollup-dom-animation.js +1 -1
  55. package/dist/size-rollup-dom-max-assets.js +1 -1
  56. package/dist/size-rollup-dom-max.js +1 -1
  57. package/dist/size-rollup-m.js +1 -1
  58. package/dist/size-rollup-motion.js +1 -1
  59. package/dist/size-rollup-scroll.js +1 -1
  60. package/dist/size-rollup-waapi-animate.js +1 -1
  61. package/dist/types/index.d.ts +28 -31
  62. package/package.json +4 -4
  63. package/dist/es/animation/animators/waapi/NativeAnimation.mjs +0 -112
  64. package/dist/es/animation/animators/waapi/index.mjs +0 -32
  65. package/dist/es/animation/animators/waapi/utils/style.mjs +0 -8
  66. package/dist/es/animation/animators/waapi/utils/supports-partial-keyframes.mjs +0 -13
@@ -87,7 +87,6 @@ function calculateRepeatDuration(duration, repeat, _repeatDelay) {
87
87
  * calculate an absolute time for the next keyframes.
88
88
  */
89
89
  function calcNextTime(current, next, prev, labels) {
90
- var _a;
91
90
  if (typeof next === "number") {
92
91
  return next;
93
92
  }
@@ -98,7 +97,7 @@ function calcNextTime(current, next, prev, labels) {
98
97
  return prev;
99
98
  }
100
99
  else {
101
- return (_a = labels.get(next)) !== null && _a !== void 0 ? _a : current;
100
+ return labels.get(next) ?? current;
102
101
  }
103
102
  }
104
103
 
@@ -211,7 +210,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
211
210
  const numKeyframes = valueKeyframesAsList.length;
212
211
  const createGenerator = motionDom.isGenerator(type)
213
212
  ? type
214
- : generators === null || generators === void 0 ? void 0 : generators[type];
213
+ : generators?.[type];
215
214
  if (numKeyframes <= 2 && createGenerator) {
216
215
  /**
217
216
  * As we're creating an easing function from a spring,
@@ -233,7 +232,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
233
232
  ease = springEasing.ease;
234
233
  duration = springEasing.duration;
235
234
  }
236
- duration !== null && duration !== void 0 ? duration : (duration = defaultDuration);
235
+ duration ?? (duration = defaultDuration);
237
236
  const startTime = currentTime + calculatedDelay;
238
237
  /**
239
238
  * If there's only one time offset of 0, fill in a second with length 1
@@ -392,212 +391,6 @@ function getValueTransition(transition, key) {
392
391
  const isNumber = (keyframe) => typeof keyframe === "number";
393
392
  const isNumberKeyframesArray = (keyframes) => keyframes.every(isNumber);
394
393
 
395
- function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}) {
396
- const keyframeOptions = { [valueName]: keyframes };
397
- if (times)
398
- keyframeOptions.offset = times;
399
- const easing = motionDom.mapEasingToNativeEasing(ease, duration);
400
- /**
401
- * If this is an easing array, apply to keyframes, not animation as a whole
402
- */
403
- if (Array.isArray(easing))
404
- keyframeOptions.easing = easing;
405
- if (motionDom.statsBuffer.value) {
406
- motionDom.activeAnimations.waapi++;
407
- }
408
- const animation = element.animate(keyframeOptions, {
409
- delay,
410
- duration,
411
- easing: !Array.isArray(easing) ? easing : "linear",
412
- fill: "both",
413
- iterations: repeat + 1,
414
- direction: repeatType === "reverse" ? "alternate" : "normal",
415
- });
416
- if (motionDom.statsBuffer.value) {
417
- animation.finished.finally(() => {
418
- motionDom.activeAnimations.waapi--;
419
- });
420
- }
421
- return animation;
422
- }
423
-
424
- const createUnitType = (unit) => ({
425
- test: (v) => typeof v === "string" && v.endsWith(unit) && v.split(" ").length === 1,
426
- parse: parseFloat,
427
- transform: (v) => `${v}${unit}`,
428
- });
429
- const px = /*@__PURE__*/ createUnitType("px");
430
-
431
- const browserNumberValueTypes = {
432
- // Border props
433
- borderWidth: px,
434
- borderTopWidth: px,
435
- borderRightWidth: px,
436
- borderBottomWidth: px,
437
- borderLeftWidth: px,
438
- borderRadius: px,
439
- radius: px,
440
- borderTopLeftRadius: px,
441
- borderTopRightRadius: px,
442
- borderBottomRightRadius: px,
443
- borderBottomLeftRadius: px,
444
- // Positioning props
445
- width: px,
446
- maxWidth: px,
447
- height: px,
448
- maxHeight: px,
449
- top: px,
450
- right: px,
451
- bottom: px,
452
- left: px,
453
- // Spacing props
454
- padding: px,
455
- paddingTop: px,
456
- paddingRight: px,
457
- paddingBottom: px,
458
- paddingLeft: px,
459
- margin: px,
460
- marginTop: px,
461
- marginRight: px,
462
- marginBottom: px,
463
- marginLeft: px,
464
- // Misc
465
- backgroundPositionX: px,
466
- backgroundPositionY: px,
467
- };
468
-
469
- const isNotNull = (value) => value !== null;
470
- function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
471
- const resolvedKeyframes = keyframes.filter(isNotNull);
472
- const index = repeat && repeatType !== "loop" && repeat % 2 === 1
473
- ? 0
474
- : resolvedKeyframes.length - 1;
475
- return !index || finalKeyframe === undefined
476
- ? resolvedKeyframes[index]
477
- : finalKeyframe;
478
- }
479
-
480
- function setCSSVar(element, name, value) {
481
- element.style.setProperty(name, value);
482
- }
483
- function setStyle(element, name, value) {
484
- element.style[name] = value;
485
- }
486
-
487
- const supportsPartialKeyframes = /*@__PURE__*/ motionUtils.memo(() => {
488
- try {
489
- document.createElement("div").animate({ opacity: [1] });
490
- }
491
- catch (e) {
492
- return false;
493
- }
494
- return true;
495
- });
496
-
497
- const supportsWaapi = /*@__PURE__*/ motionUtils.memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
498
-
499
- const state = new WeakMap();
500
- function hydrateKeyframes(valueName, keyframes, read) {
501
- for (let i = 0; i < keyframes.length; i++) {
502
- if (keyframes[i] === null) {
503
- keyframes[i] = i === 0 ? read() : keyframes[i - 1];
504
- }
505
- if (typeof keyframes[i] === "number" &&
506
- browserNumberValueTypes[valueName]) {
507
- keyframes[i] = browserNumberValueTypes[valueName].transform(keyframes[i]);
508
- }
509
- }
510
- if (!supportsPartialKeyframes() && keyframes.length < 2) {
511
- keyframes.unshift(read());
512
- }
513
- }
514
- const defaultEasing = "easeOut";
515
- function getElementAnimationState(element) {
516
- const animationState = state.get(element) || new Map();
517
- state.set(element, animationState);
518
- return state.get(element);
519
- }
520
- class NativeAnimation extends motionDom.NativeAnimationControls {
521
- constructor(element, valueName, valueKeyframes, options) {
522
- const isCSSVar = valueName.startsWith("--");
523
- motionUtils.invariant(typeof options.type !== "string", `animateMini doesn't support "type" as a string. Did you mean to import { spring } from "framer-motion"?`);
524
- const existingAnimation = getElementAnimationState(element).get(valueName);
525
- existingAnimation && existingAnimation.stop();
526
- const readInitialKeyframe = () => {
527
- return valueName.startsWith("--")
528
- ? element.style.getPropertyValue(valueName)
529
- : window.getComputedStyle(element)[valueName];
530
- };
531
- if (!Array.isArray(valueKeyframes)) {
532
- valueKeyframes = [valueKeyframes];
533
- }
534
- hydrateKeyframes(valueName, valueKeyframes, readInitialKeyframe);
535
- // TODO: Replace this with toString()?
536
- if (motionDom.isGenerator(options.type)) {
537
- const generatorOptions = motionDom.createGeneratorEasing(options, 100, options.type);
538
- options.ease = motionDom.supportsLinearEasing()
539
- ? generatorOptions.ease
540
- : defaultEasing;
541
- options.duration = motionUtils.secondsToMilliseconds(generatorOptions.duration);
542
- options.type = "keyframes";
543
- }
544
- else {
545
- options.ease = options.ease || defaultEasing;
546
- }
547
- const onFinish = () => {
548
- this.setValue(element, valueName, getFinalKeyframe(valueKeyframes, options));
549
- this.cancel();
550
- this.resolveFinishedPromise();
551
- };
552
- const init = () => {
553
- this.setValue = isCSSVar ? setCSSVar : setStyle;
554
- this.options = options;
555
- this.updateFinishedPromise();
556
- this.removeAnimation = () => {
557
- const elementState = state.get(element);
558
- elementState && elementState.delete(valueName);
559
- };
560
- };
561
- if (!supportsWaapi()) {
562
- super();
563
- init();
564
- onFinish();
565
- }
566
- else {
567
- super(startWaapiAnimation(element, valueName, valueKeyframes, options));
568
- init();
569
- if (options.autoplay === false) {
570
- this.animation.pause();
571
- }
572
- this.animation.onfinish = onFinish;
573
- getElementAnimationState(element).set(valueName, this);
574
- }
575
- }
576
- /**
577
- * Allows the returned animation to be awaited or promise-chained. Currently
578
- * resolves when the animation finishes at all but in a future update could/should
579
- * reject if its cancels.
580
- */
581
- then(resolve, reject) {
582
- return this.currentFinishedPromise.then(resolve, reject);
583
- }
584
- updateFinishedPromise() {
585
- this.currentFinishedPromise = new Promise((resolve) => {
586
- this.resolveFinishedPromise = resolve;
587
- });
588
- }
589
- play() {
590
- if (this.state === "finished") {
591
- this.updateFinishedPromise();
592
- }
593
- super.play();
594
- }
595
- cancel() {
596
- this.removeAnimation();
597
- super.cancel();
598
- }
599
- }
600
-
601
394
  function animateElements(elementOrSelector, keyframes, options, scope) {
602
395
  const elements = motionDom.resolveElements(elementOrSelector, scope);
603
396
  const numElements = elements.length;
@@ -617,13 +410,15 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
617
410
  const valueOptions = {
618
411
  ...motionDom.getValueTransition(elementTransition, valueName),
619
412
  };
620
- valueOptions.duration = valueOptions.duration
621
- ? motionUtils.secondsToMilliseconds(valueOptions.duration)
622
- : valueOptions.duration;
623
- valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay || 0);
624
- valueOptions.allowFlatten =
625
- !elementTransition.type && !elementTransition.ease;
626
- animations.push(new NativeAnimation(element, valueName, valueKeyframes, valueOptions));
413
+ valueOptions.duration && (valueOptions.duration = motionUtils.secondsToMilliseconds(valueOptions.duration));
414
+ valueOptions.delay && (valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay));
415
+ animations.push(new motionDom.NativeAnimation({
416
+ element,
417
+ name: valueName,
418
+ keyframes: valueKeyframes,
419
+ transition: valueOptions,
420
+ allowFlatten: !elementTransition.type && !elementTransition.ease,
421
+ }));
627
422
  }
628
423
  }
629
424
  return animations;
@@ -634,12 +429,12 @@ function animateSequence(definition, options) {
634
429
  createAnimationsFromSequence(definition, options).forEach(({ keyframes, transition }, element) => {
635
430
  animations.push(...animateElements(element, keyframes, transition));
636
431
  });
637
- return new motionDom.GroupPlaybackControls(animations);
432
+ return new motionDom.GroupAnimationWithThen(animations);
638
433
  }
639
434
 
640
435
  const createScopedWaapiAnimate = (scope) => {
641
436
  function scopedAnimate(elementOrSelector, keyframes, options) {
642
- return new motionDom.GroupPlaybackControls(animateElements(elementOrSelector, keyframes, options, scope));
437
+ return new motionDom.GroupAnimationWithThen(animateElements(elementOrSelector, keyframes, options, scope));
643
438
  }
644
439
  return scopedAnimate;
645
440
  };