framer-motion 12.11.4 → 12.12.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.
Files changed (37) hide show
  1. package/dist/cjs/client.js +1 -1
  2. package/dist/cjs/{create-t9legXtK.js → create-BiMCrvDh.js} +75 -78
  3. package/dist/cjs/dom-mini.js +1 -3
  4. package/dist/cjs/dom.js +15 -17
  5. package/dist/cjs/index.js +15 -53
  6. package/dist/cjs/m.js +113 -115
  7. package/dist/dom.js +1 -1
  8. package/dist/es/animation/animate/single-value.mjs +1 -2
  9. package/dist/es/animation/animate/subject.mjs +1 -1
  10. package/dist/es/animation/sequence/create.mjs +1 -2
  11. package/dist/es/components/Reorder/Item.mjs +1 -1
  12. package/dist/es/index.mjs +0 -1
  13. package/dist/es/render/VisualElement.mjs +1 -2
  14. package/dist/es/render/dom/DOMVisualElement.mjs +1 -2
  15. package/dist/es/render/dom/use-render.mjs +2 -2
  16. package/dist/es/render/html/use-props.mjs +1 -1
  17. package/dist/es/render/html/utils/scrape-motion-values.mjs +1 -1
  18. package/dist/es/render/svg/utils/scrape-motion-values.mjs +1 -2
  19. package/dist/es/render/utils/motion-values.mjs +1 -2
  20. package/dist/es/value/use-motion-template.mjs +1 -1
  21. package/dist/es/value/use-spring.mjs +12 -52
  22. package/dist/es/value/use-will-change/is.mjs +1 -1
  23. package/dist/es/value/utils/resolve-motion-value.mjs +1 -1
  24. package/dist/framer-motion.dev.js +141 -110
  25. package/dist/framer-motion.js +1 -1
  26. package/dist/m.d.ts +3 -3
  27. package/dist/size-rollup-animate.js +1 -1
  28. package/dist/size-rollup-dom-animation-assets.js +1 -1
  29. package/dist/size-rollup-dom-animation-m.js +1 -1
  30. package/dist/size-rollup-dom-max-assets.js +1 -1
  31. package/dist/size-rollup-m.js +1 -1
  32. package/dist/size-rollup-motion.js +1 -1
  33. package/dist/types/client.d.ts +1 -1
  34. package/dist/types/index.d.ts +7 -9
  35. package/dist/{types.d-CQt5spQA.d.ts → types.d-CtuPurYT.d.ts} +3 -3
  36. package/package.json +3 -3
  37. package/dist/es/value/utils/is-motion-value.mjs +0 -3
package/dist/cjs/m.js CHANGED
@@ -390,8 +390,6 @@ function isForcedMotionValue(key, { layout, layoutId }) {
390
390
  (!!scaleCorrectors[key] || key === "opacity")));
391
391
  }
392
392
 
393
- const isMotionValue = (value) => Boolean(value && value.getVelocity);
394
-
395
393
  const translateAlias = {
396
394
  x: "translateX",
397
395
  y: "translateY",
@@ -516,7 +514,7 @@ const createHtmlRenderState = () => ({
516
514
 
517
515
  function copyRawValuesOnly(target, source, props) {
518
516
  for (const key in source) {
519
- if (!isMotionValue(source[key]) && !isForcedMotionValue(key, props)) {
517
+ if (!motionDom.isMotionValue(source[key]) && !isForcedMotionValue(key, props)) {
520
518
  target[key] = source[key];
521
519
  }
522
520
  }
@@ -564,6 +562,112 @@ function useHTMLProps(props, visualState) {
564
562
  return htmlProps;
565
563
  }
566
564
 
565
+ const dashKeys = {
566
+ offset: "stroke-dashoffset",
567
+ array: "stroke-dasharray",
568
+ };
569
+ const camelKeys = {
570
+ offset: "strokeDashoffset",
571
+ array: "strokeDasharray",
572
+ };
573
+ /**
574
+ * Build SVG path properties. Uses the path's measured length to convert
575
+ * our custom pathLength, pathSpacing and pathOffset into stroke-dashoffset
576
+ * and stroke-dasharray attributes.
577
+ *
578
+ * This function is mutative to reduce per-frame GC.
579
+ */
580
+ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true) {
581
+ // Normalise path length by setting SVG attribute pathLength to 1
582
+ attrs.pathLength = 1;
583
+ // We use dash case when setting attributes directly to the DOM node and camel case
584
+ // when defining props on a React component.
585
+ const keys = useDashCase ? dashKeys : camelKeys;
586
+ // Build the dash offset
587
+ attrs[keys.offset] = motionDom.px.transform(-offset);
588
+ // Build the dash array
589
+ const pathLength = motionDom.px.transform(length);
590
+ const pathSpacing = motionDom.px.transform(spacing);
591
+ attrs[keys.array] = `${pathLength} ${pathSpacing}`;
592
+ }
593
+
594
+ /**
595
+ * Build SVG visual attrbutes, like cx and style.transform
596
+ */
597
+ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
598
+ // This is object creation, which we try to avoid per-frame.
599
+ ...latest }, isSVGTag, transformTemplate, styleProp) {
600
+ buildHTMLStyles(state, latest, transformTemplate);
601
+ /**
602
+ * For svg tags we just want to make sure viewBox is animatable and treat all the styles
603
+ * as normal HTML tags.
604
+ */
605
+ if (isSVGTag) {
606
+ if (state.style.viewBox) {
607
+ state.attrs.viewBox = state.style.viewBox;
608
+ }
609
+ return;
610
+ }
611
+ state.attrs = state.style;
612
+ state.style = {};
613
+ const { attrs, style } = state;
614
+ /**
615
+ * However, we apply transforms as CSS transforms.
616
+ * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
617
+ */
618
+ if (attrs.transform) {
619
+ style.transform = attrs.transform;
620
+ delete attrs.transform;
621
+ }
622
+ if (style.transform || attrs.transformOrigin) {
623
+ style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
624
+ delete attrs.transformOrigin;
625
+ }
626
+ if (style.transform) {
627
+ /**
628
+ * SVG's element transform-origin uses its own median as a reference.
629
+ * Therefore, transformBox becomes a fill-box
630
+ */
631
+ style.transformBox = styleProp?.transformBox ?? "fill-box";
632
+ delete attrs.transformBox;
633
+ }
634
+ // Render attrX/attrY/attrScale as attributes
635
+ if (attrX !== undefined)
636
+ attrs.x = attrX;
637
+ if (attrY !== undefined)
638
+ attrs.y = attrY;
639
+ if (attrScale !== undefined)
640
+ attrs.scale = attrScale;
641
+ // Build SVG path if one has been defined
642
+ if (pathLength !== undefined) {
643
+ buildSVGPath(attrs, pathLength, pathSpacing, pathOffset, false);
644
+ }
645
+ }
646
+
647
+ const createSvgRenderState = () => ({
648
+ ...createHtmlRenderState(),
649
+ attrs: {},
650
+ });
651
+
652
+ const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
653
+
654
+ function useSVGProps(props, visualState, _isStatic, Component) {
655
+ const visualProps = react.useMemo(() => {
656
+ const state = createSvgRenderState();
657
+ buildSVGAttrs(state, visualState, isSVGTag(Component), props.transformTemplate, props.style);
658
+ return {
659
+ ...state.attrs,
660
+ style: { ...state.style },
661
+ };
662
+ }, [visualState]);
663
+ if (props.style) {
664
+ const rawStyles = {};
665
+ copyRawValuesOnly(rawStyles, props.style, props);
666
+ visualProps.style = { ...rawStyles, ...visualProps.style };
667
+ }
668
+ return visualProps;
669
+ }
670
+
567
671
  /**
568
672
  * A list of all valid MotionProps.
569
673
  *
@@ -735,112 +839,6 @@ function isSVGComponent(Component) {
735
839
  return false;
736
840
  }
737
841
 
738
- const dashKeys = {
739
- offset: "stroke-dashoffset",
740
- array: "stroke-dasharray",
741
- };
742
- const camelKeys = {
743
- offset: "strokeDashoffset",
744
- array: "strokeDasharray",
745
- };
746
- /**
747
- * Build SVG path properties. Uses the path's measured length to convert
748
- * our custom pathLength, pathSpacing and pathOffset into stroke-dashoffset
749
- * and stroke-dasharray attributes.
750
- *
751
- * This function is mutative to reduce per-frame GC.
752
- */
753
- function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true) {
754
- // Normalise path length by setting SVG attribute pathLength to 1
755
- attrs.pathLength = 1;
756
- // We use dash case when setting attributes directly to the DOM node and camel case
757
- // when defining props on a React component.
758
- const keys = useDashCase ? dashKeys : camelKeys;
759
- // Build the dash offset
760
- attrs[keys.offset] = motionDom.px.transform(-offset);
761
- // Build the dash array
762
- const pathLength = motionDom.px.transform(length);
763
- const pathSpacing = motionDom.px.transform(spacing);
764
- attrs[keys.array] = `${pathLength} ${pathSpacing}`;
765
- }
766
-
767
- /**
768
- * Build SVG visual attrbutes, like cx and style.transform
769
- */
770
- function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
771
- // This is object creation, which we try to avoid per-frame.
772
- ...latest }, isSVGTag, transformTemplate, styleProp) {
773
- buildHTMLStyles(state, latest, transformTemplate);
774
- /**
775
- * For svg tags we just want to make sure viewBox is animatable and treat all the styles
776
- * as normal HTML tags.
777
- */
778
- if (isSVGTag) {
779
- if (state.style.viewBox) {
780
- state.attrs.viewBox = state.style.viewBox;
781
- }
782
- return;
783
- }
784
- state.attrs = state.style;
785
- state.style = {};
786
- const { attrs, style } = state;
787
- /**
788
- * However, we apply transforms as CSS transforms.
789
- * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
790
- */
791
- if (attrs.transform) {
792
- style.transform = attrs.transform;
793
- delete attrs.transform;
794
- }
795
- if (style.transform || attrs.transformOrigin) {
796
- style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
797
- delete attrs.transformOrigin;
798
- }
799
- if (style.transform) {
800
- /**
801
- * SVG's element transform-origin uses its own median as a reference.
802
- * Therefore, transformBox becomes a fill-box
803
- */
804
- style.transformBox = styleProp?.transformBox ?? "fill-box";
805
- delete attrs.transformBox;
806
- }
807
- // Render attrX/attrY/attrScale as attributes
808
- if (attrX !== undefined)
809
- attrs.x = attrX;
810
- if (attrY !== undefined)
811
- attrs.y = attrY;
812
- if (attrScale !== undefined)
813
- attrs.scale = attrScale;
814
- // Build SVG path if one has been defined
815
- if (pathLength !== undefined) {
816
- buildSVGPath(attrs, pathLength, pathSpacing, pathOffset, false);
817
- }
818
- }
819
-
820
- const createSvgRenderState = () => ({
821
- ...createHtmlRenderState(),
822
- attrs: {},
823
- });
824
-
825
- const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
826
-
827
- function useSVGProps(props, visualState, _isStatic, Component) {
828
- const visualProps = react.useMemo(() => {
829
- const state = createSvgRenderState();
830
- buildSVGAttrs(state, visualState, isSVGTag(Component), props.transformTemplate, props.style);
831
- return {
832
- ...state.attrs,
833
- style: { ...state.style },
834
- };
835
- }, [visualState]);
836
- if (props.style) {
837
- const rawStyles = {};
838
- copyRawValuesOnly(rawStyles, props.style, props);
839
- visualProps.style = { ...rawStyles, ...visualProps.style };
840
- }
841
- return visualProps;
842
- }
843
-
844
842
  function createUseRender(forwardMotionProps = false) {
845
843
  const useRender = (Component, props, ref, { latestValues }, isStatic) => {
846
844
  const useVisualProps = isSVGComponent(Component)
@@ -857,7 +855,7 @@ function createUseRender(forwardMotionProps = false) {
857
855
  * will be handled by the onChange handler
858
856
  */
859
857
  const { children } = props;
860
- const renderedChildren = react.useMemo(() => (isMotionValue(children) ? children.get() : children), [children]);
858
+ const renderedChildren = react.useMemo(() => (motionDom.isMotionValue(children) ? children.get() : children), [children]);
861
859
  return react.createElement(Component, {
862
860
  ...elementProps,
863
861
  children: renderedChildren,
@@ -922,7 +920,7 @@ function useConstant(init) {
922
920
  * TODO: Remove and move to library
923
921
  */
924
922
  function resolveMotionValue(value) {
925
- return isMotionValue(value) ? value.get() : value;
923
+ return motionDom.isMotionValue(value) ? value.get() : value;
926
924
  }
927
925
 
928
926
  function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
@@ -998,9 +996,9 @@ function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
998
996
  const { style } = props;
999
997
  const newValues = {};
1000
998
  for (const key in style) {
1001
- if (isMotionValue(style[key]) ||
999
+ if (motionDom.isMotionValue(style[key]) ||
1002
1000
  (prevProps.style &&
1003
- isMotionValue(prevProps.style[key])) ||
1001
+ motionDom.isMotionValue(prevProps.style[key])) ||
1004
1002
  isForcedMotionValue(key, props) ||
1005
1003
  visualElement?.getValue(key)?.liveStyle !== undefined) {
1006
1004
  newValues[key] = style[key];
@@ -1019,8 +1017,8 @@ const htmlMotionConfig = {
1019
1017
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
1020
1018
  const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
1021
1019
  for (const key in props) {
1022
- if (isMotionValue(props[key]) ||
1023
- isMotionValue(prevProps[key])) {
1020
+ if (motionDom.isMotionValue(props[key]) ||
1021
+ motionDom.isMotionValue(prevProps[key])) {
1024
1022
  const targetKey = motionDom.transformPropOrder.indexOf(key) !== -1
1025
1023
  ? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
1026
1024
  : key;