motion-dom 12.24.10 → 12.26.2

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 (79) hide show
  1. package/dist/cjs/index.js +6214 -1836
  2. package/dist/es/animation/NativeAnimation.mjs +10 -2
  3. package/dist/es/animation/NativeAnimationExtended.mjs +11 -4
  4. package/dist/es/animation/animate/single-value.mjs +11 -0
  5. package/dist/es/animation/interfaces/motion-value.mjs +102 -0
  6. package/dist/es/animation/interfaces/visual-element-target.mjs +85 -0
  7. package/dist/es/animation/interfaces/visual-element-variant.mjs +59 -0
  8. package/dist/es/animation/interfaces/visual-element.mjs +26 -0
  9. package/dist/es/animation/optimized-appear/data-id.mjs +6 -0
  10. package/dist/es/animation/optimized-appear/get-appear-id.mjs +7 -0
  11. package/dist/es/animation/utils/calc-child-stagger.mjs +15 -0
  12. package/dist/es/animation/utils/default-transitions.mjs +40 -0
  13. package/dist/es/animation/utils/get-final-keyframe.mjs +12 -0
  14. package/dist/es/animation/utils/is-transition-defined.mjs +10 -0
  15. package/dist/es/events/add-dom-event.mjs +6 -0
  16. package/dist/es/index.mjs +71 -0
  17. package/dist/es/projection/animation/mix-values.mjs +66 -0
  18. package/dist/es/projection/geometry/conversion.mjs +33 -0
  19. package/dist/es/projection/geometry/copy.mjs +31 -0
  20. package/dist/es/projection/geometry/delta-apply.mjs +119 -0
  21. package/dist/es/projection/geometry/delta-calc.mjs +52 -0
  22. package/dist/es/projection/geometry/delta-remove.mjs +54 -0
  23. package/dist/es/projection/geometry/models.mjs +17 -0
  24. package/dist/es/projection/geometry/utils.mjs +31 -0
  25. package/dist/es/projection/node/DocumentProjectionNode.mjs +13 -0
  26. package/dist/es/projection/node/HTMLProjectionNode.mjs +27 -0
  27. package/dist/es/projection/node/create-projection-node.mjs +1628 -0
  28. package/dist/es/projection/node/group.mjs +24 -0
  29. package/dist/es/projection/node/state.mjs +19 -0
  30. package/dist/es/projection/shared/stack.mjs +100 -0
  31. package/dist/es/projection/styles/scale-border-radius.mjs +41 -0
  32. package/dist/es/projection/styles/scale-box-shadow.mjs +35 -0
  33. package/dist/es/projection/styles/scale-correction.mjs +30 -0
  34. package/dist/es/projection/styles/transform.mjs +49 -0
  35. package/dist/es/projection/utils/compare-by-depth.mjs +3 -0
  36. package/dist/es/projection/utils/each-axis.mjs +5 -0
  37. package/dist/es/projection/utils/flat-tree.mjs +24 -0
  38. package/dist/es/projection/utils/has-transform.mjs +26 -0
  39. package/dist/es/projection/utils/measure.mjs +17 -0
  40. package/dist/es/render/Feature.mjs +14 -0
  41. package/dist/es/render/VisualElement.mjs +510 -0
  42. package/dist/es/render/dom/DOMVisualElement.mjs +42 -0
  43. package/dist/es/render/html/HTMLVisualElement.mjs +44 -0
  44. package/dist/es/render/html/utils/build-styles.mjs +65 -0
  45. package/dist/es/render/html/utils/build-transform.mjs +62 -0
  46. package/dist/es/render/html/utils/render.mjs +17 -0
  47. package/dist/es/render/html/utils/scrape-motion-values.mjs +21 -0
  48. package/dist/es/render/object/ObjectVisualElement.mjs +41 -0
  49. package/dist/es/render/store.mjs +3 -0
  50. package/dist/es/render/svg/SVGVisualElement.mjs +45 -0
  51. package/dist/es/render/svg/utils/build-attrs.mjs +72 -0
  52. package/dist/es/render/svg/utils/camel-case-attrs.mjs +30 -0
  53. package/dist/es/render/svg/utils/is-svg-tag.mjs +3 -0
  54. package/dist/es/render/svg/utils/path.mjs +32 -0
  55. package/dist/es/render/svg/utils/render.mjs +12 -0
  56. package/dist/es/render/svg/utils/scrape-motion-values.mjs +19 -0
  57. package/dist/es/render/utils/animation-state.mjs +364 -0
  58. package/dist/es/render/utils/get-variant-context.mjs +32 -0
  59. package/dist/es/render/utils/is-animation-controls.mjs +7 -0
  60. package/dist/es/render/utils/is-controlling-variants.mjs +13 -0
  61. package/dist/es/render/utils/is-forced-motion-value.mjs +12 -0
  62. package/dist/es/render/utils/is-keyframes-target.mjs +5 -0
  63. package/dist/es/render/utils/is-variant-label.mjs +8 -0
  64. package/dist/es/render/utils/motion-values.mjs +55 -0
  65. package/dist/es/render/utils/reduced-motion/index.mjs +19 -0
  66. package/dist/es/render/utils/reduced-motion/state.mjs +5 -0
  67. package/dist/es/render/utils/resolve-dynamic-variants.mjs +8 -0
  68. package/dist/es/render/utils/resolve-variants.mjs +36 -0
  69. package/dist/es/render/utils/setters.mjs +31 -0
  70. package/dist/es/render/utils/shallow-compare.mjs +14 -0
  71. package/dist/es/render/utils/variant-props.mjs +12 -0
  72. package/dist/es/utils/delay.mjs +24 -0
  73. package/dist/es/value/utils/resolve-motion-value.mjs +10 -0
  74. package/dist/es/value/will-change/add-will-change.mjs +20 -0
  75. package/dist/es/value/will-change/is.mjs +7 -0
  76. package/dist/index.d.ts +3851 -2128
  77. package/dist/motion-dom.dev.js +6214 -1836
  78. package/dist/motion-dom.js +1 -1
  79. package/package.json +2 -2
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Bounding boxes tend to be defined as top, left, right, bottom. For various operations
3
+ * it's easier to consider each axis individually. This function returns a bounding box
4
+ * as a map of single-axis min/max values.
5
+ */
6
+ function convertBoundingBoxToBox({ top, left, right, bottom, }) {
7
+ return {
8
+ x: { min: left, max: right },
9
+ y: { min: top, max: bottom },
10
+ };
11
+ }
12
+ function convertBoxToBoundingBox({ x, y }) {
13
+ return { top: y.min, right: x.max, bottom: y.max, left: x.min };
14
+ }
15
+ /**
16
+ * Applies a TransformPoint function to a bounding box. TransformPoint is usually a function
17
+ * provided by Framer to allow measured points to be corrected for device scaling. This is used
18
+ * when measuring DOM elements and DOM event points.
19
+ */
20
+ function transformBoxPoints(point, transformPoint) {
21
+ if (!transformPoint)
22
+ return point;
23
+ const topLeft = transformPoint({ x: point.left, y: point.top });
24
+ const bottomRight = transformPoint({ x: point.right, y: point.bottom });
25
+ return {
26
+ top: topLeft.y,
27
+ left: topLeft.x,
28
+ bottom: bottomRight.y,
29
+ right: bottomRight.x,
30
+ };
31
+ }
32
+
33
+ export { convertBoundingBoxToBox, convertBoxToBoundingBox, transformBoxPoints };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Reset an axis to the provided origin box.
3
+ *
4
+ * This is a mutative operation.
5
+ */
6
+ function copyAxisInto(axis, originAxis) {
7
+ axis.min = originAxis.min;
8
+ axis.max = originAxis.max;
9
+ }
10
+ /**
11
+ * Reset a box to the provided origin box.
12
+ *
13
+ * This is a mutative operation.
14
+ */
15
+ function copyBoxInto(box, originBox) {
16
+ copyAxisInto(box.x, originBox.x);
17
+ copyAxisInto(box.y, originBox.y);
18
+ }
19
+ /**
20
+ * Reset a delta to the provided origin box.
21
+ *
22
+ * This is a mutative operation.
23
+ */
24
+ function copyAxisDeltaInto(delta, originDelta) {
25
+ delta.translate = originDelta.translate;
26
+ delta.scale = originDelta.scale;
27
+ delta.originPoint = originDelta.originPoint;
28
+ delta.origin = originDelta.origin;
29
+ }
30
+
31
+ export { copyAxisDeltaInto, copyAxisInto, copyBoxInto };
@@ -0,0 +1,119 @@
1
+ import { mixNumber } from '../../utils/mix/number.mjs';
2
+ import { hasTransform } from '../utils/has-transform.mjs';
3
+
4
+ /**
5
+ * Scales a point based on a factor and an originPoint
6
+ */
7
+ function scalePoint(point, scale, originPoint) {
8
+ const distanceFromOrigin = point - originPoint;
9
+ const scaled = scale * distanceFromOrigin;
10
+ return originPoint + scaled;
11
+ }
12
+ /**
13
+ * Applies a translate/scale delta to a point
14
+ */
15
+ function applyPointDelta(point, translate, scale, originPoint, boxScale) {
16
+ if (boxScale !== undefined) {
17
+ point = scalePoint(point, boxScale, originPoint);
18
+ }
19
+ return scalePoint(point, scale, originPoint) + translate;
20
+ }
21
+ /**
22
+ * Applies a translate/scale delta to an axis
23
+ */
24
+ function applyAxisDelta(axis, translate = 0, scale = 1, originPoint, boxScale) {
25
+ axis.min = applyPointDelta(axis.min, translate, scale, originPoint, boxScale);
26
+ axis.max = applyPointDelta(axis.max, translate, scale, originPoint, boxScale);
27
+ }
28
+ /**
29
+ * Applies a translate/scale delta to a box
30
+ */
31
+ function applyBoxDelta(box, { x, y }) {
32
+ applyAxisDelta(box.x, x.translate, x.scale, x.originPoint);
33
+ applyAxisDelta(box.y, y.translate, y.scale, y.originPoint);
34
+ }
35
+ const TREE_SCALE_SNAP_MIN = 0.999999999999;
36
+ const TREE_SCALE_SNAP_MAX = 1.0000000000001;
37
+ /**
38
+ * Apply a tree of deltas to a box. We do this to calculate the effect of all the transforms
39
+ * in a tree upon our box before then calculating how to project it into our desired viewport-relative box
40
+ *
41
+ * This is the final nested loop within updateLayoutDelta for future refactoring
42
+ */
43
+ function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
44
+ const treeLength = treePath.length;
45
+ if (!treeLength)
46
+ return;
47
+ // Reset the treeScale
48
+ treeScale.x = treeScale.y = 1;
49
+ let node;
50
+ let delta;
51
+ for (let i = 0; i < treeLength; i++) {
52
+ node = treePath[i];
53
+ delta = node.projectionDelta;
54
+ /**
55
+ * TODO: Prefer to remove this, but currently we have motion components with
56
+ * display: contents in Framer.
57
+ */
58
+ const { visualElement } = node.options;
59
+ if (visualElement &&
60
+ visualElement.props.style &&
61
+ visualElement.props.style.display === "contents") {
62
+ continue;
63
+ }
64
+ if (isSharedTransition &&
65
+ node.options.layoutScroll &&
66
+ node.scroll &&
67
+ node !== node.root) {
68
+ transformBox(box, {
69
+ x: -node.scroll.offset.x,
70
+ y: -node.scroll.offset.y,
71
+ });
72
+ }
73
+ if (delta) {
74
+ // Incoporate each ancestor's scale into a cumulative treeScale for this component
75
+ treeScale.x *= delta.x.scale;
76
+ treeScale.y *= delta.y.scale;
77
+ // Apply each ancestor's calculated delta into this component's recorded layout box
78
+ applyBoxDelta(box, delta);
79
+ }
80
+ if (isSharedTransition && hasTransform(node.latestValues)) {
81
+ transformBox(box, node.latestValues);
82
+ }
83
+ }
84
+ /**
85
+ * Snap tree scale back to 1 if it's within a non-perceivable threshold.
86
+ * This will help reduce useless scales getting rendered.
87
+ */
88
+ if (treeScale.x < TREE_SCALE_SNAP_MAX &&
89
+ treeScale.x > TREE_SCALE_SNAP_MIN) {
90
+ treeScale.x = 1.0;
91
+ }
92
+ if (treeScale.y < TREE_SCALE_SNAP_MAX &&
93
+ treeScale.y > TREE_SCALE_SNAP_MIN) {
94
+ treeScale.y = 1.0;
95
+ }
96
+ }
97
+ function translateAxis(axis, distance) {
98
+ axis.min = axis.min + distance;
99
+ axis.max = axis.max + distance;
100
+ }
101
+ /**
102
+ * Apply a transform to an axis from the latest resolved motion values.
103
+ * This function basically acts as a bridge between a flat motion value map
104
+ * and applyAxisDelta
105
+ */
106
+ function transformAxis(axis, axisTranslate, axisScale, boxScale, axisOrigin = 0.5) {
107
+ const originPoint = mixNumber(axis.min, axis.max, axisOrigin);
108
+ // Apply the axis delta to the final axis
109
+ applyAxisDelta(axis, axisTranslate, axisScale, originPoint, boxScale);
110
+ }
111
+ /**
112
+ * Apply a transform to a box from the latest resolved motion values.
113
+ */
114
+ function transformBox(box, transform) {
115
+ transformAxis(box.x, transform.x, transform.scaleX, transform.scale, transform.originX);
116
+ transformAxis(box.y, transform.y, transform.scaleY, transform.scale, transform.originY);
117
+ }
118
+
119
+ export { applyAxisDelta, applyBoxDelta, applyPointDelta, applyTreeDeltas, scalePoint, transformAxis, transformBox, translateAxis };
@@ -0,0 +1,52 @@
1
+ import { mixNumber } from '../../utils/mix/number.mjs';
2
+
3
+ const SCALE_PRECISION = 0.0001;
4
+ const SCALE_MIN = 1 - SCALE_PRECISION;
5
+ const SCALE_MAX = 1 + SCALE_PRECISION;
6
+ const TRANSLATE_PRECISION = 0.01;
7
+ const TRANSLATE_MIN = 0 - TRANSLATE_PRECISION;
8
+ const TRANSLATE_MAX = 0 + TRANSLATE_PRECISION;
9
+ function calcLength(axis) {
10
+ return axis.max - axis.min;
11
+ }
12
+ function isNear(value, target, maxDistance) {
13
+ return Math.abs(value - target) <= maxDistance;
14
+ }
15
+ function calcAxisDelta(delta, source, target, origin = 0.5) {
16
+ delta.origin = origin;
17
+ delta.originPoint = mixNumber(source.min, source.max, delta.origin);
18
+ delta.scale = calcLength(target) / calcLength(source);
19
+ delta.translate =
20
+ mixNumber(target.min, target.max, delta.origin) - delta.originPoint;
21
+ if ((delta.scale >= SCALE_MIN && delta.scale <= SCALE_MAX) ||
22
+ isNaN(delta.scale)) {
23
+ delta.scale = 1.0;
24
+ }
25
+ if ((delta.translate >= TRANSLATE_MIN &&
26
+ delta.translate <= TRANSLATE_MAX) ||
27
+ isNaN(delta.translate)) {
28
+ delta.translate = 0.0;
29
+ }
30
+ }
31
+ function calcBoxDelta(delta, source, target, origin) {
32
+ calcAxisDelta(delta.x, source.x, target.x, origin ? origin.originX : undefined);
33
+ calcAxisDelta(delta.y, source.y, target.y, origin ? origin.originY : undefined);
34
+ }
35
+ function calcRelativeAxis(target, relative, parent) {
36
+ target.min = parent.min + relative.min;
37
+ target.max = target.min + calcLength(relative);
38
+ }
39
+ function calcRelativeBox(target, relative, parent) {
40
+ calcRelativeAxis(target.x, relative.x, parent.x);
41
+ calcRelativeAxis(target.y, relative.y, parent.y);
42
+ }
43
+ function calcRelativeAxisPosition(target, layout, parent) {
44
+ target.min = layout.min - parent.min;
45
+ target.max = target.min + calcLength(layout);
46
+ }
47
+ function calcRelativePosition(target, layout, parent) {
48
+ calcRelativeAxisPosition(target.x, layout.x, parent.x);
49
+ calcRelativeAxisPosition(target.y, layout.y, parent.y);
50
+ }
51
+
52
+ export { calcAxisDelta, calcBoxDelta, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, isNear };
@@ -0,0 +1,54 @@
1
+ import { mixNumber } from '../../utils/mix/number.mjs';
2
+ import { percent } from '../../value/types/numbers/units.mjs';
3
+ import { scalePoint } from './delta-apply.mjs';
4
+
5
+ /**
6
+ * Remove a delta from a point. This is essentially the steps of applyPointDelta in reverse
7
+ */
8
+ function removePointDelta(point, translate, scale, originPoint, boxScale) {
9
+ point -= translate;
10
+ point = scalePoint(point, 1 / scale, originPoint);
11
+ if (boxScale !== undefined) {
12
+ point = scalePoint(point, 1 / boxScale, originPoint);
13
+ }
14
+ return point;
15
+ }
16
+ /**
17
+ * Remove a delta from an axis. This is essentially the steps of applyAxisDelta in reverse
18
+ */
19
+ function removeAxisDelta(axis, translate = 0, scale = 1, origin = 0.5, boxScale, originAxis = axis, sourceAxis = axis) {
20
+ if (percent.test(translate)) {
21
+ translate = parseFloat(translate);
22
+ const relativeProgress = mixNumber(sourceAxis.min, sourceAxis.max, translate / 100);
23
+ translate = relativeProgress - sourceAxis.min;
24
+ }
25
+ if (typeof translate !== "number")
26
+ return;
27
+ let originPoint = mixNumber(originAxis.min, originAxis.max, origin);
28
+ if (axis === originAxis)
29
+ originPoint -= translate;
30
+ axis.min = removePointDelta(axis.min, translate, scale, originPoint, boxScale);
31
+ axis.max = removePointDelta(axis.max, translate, scale, originPoint, boxScale);
32
+ }
33
+ /**
34
+ * Remove a transforms from an axis. This is essentially the steps of applyAxisTransforms in reverse
35
+ * and acts as a bridge between motion values and removeAxisDelta
36
+ */
37
+ function removeAxisTransforms(axis, transforms, [key, scaleKey, originKey], origin, sourceAxis) {
38
+ removeAxisDelta(axis, transforms[key], transforms[scaleKey], transforms[originKey], transforms.scale, origin, sourceAxis);
39
+ }
40
+ /**
41
+ * The names of the motion values we want to apply as translation, scale and origin.
42
+ */
43
+ const xKeys = ["x", "scaleX", "originX"];
44
+ const yKeys = ["y", "scaleY", "originY"];
45
+ /**
46
+ * Remove a transforms from an box. This is essentially the steps of applyAxisBox in reverse
47
+ * and acts as a bridge between motion values and removeAxisDelta
48
+ */
49
+ function removeBoxTransforms(box, transforms, originBox, sourceBox) {
50
+ removeAxisTransforms(box.x, transforms, xKeys, originBox ? originBox.x : undefined, sourceBox ? sourceBox.x : undefined);
51
+ removeAxisTransforms(box.y, transforms, yKeys, originBox ? originBox.y : undefined, sourceBox ? sourceBox.y : undefined);
52
+ }
53
+
54
+ export { removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removePointDelta };
@@ -0,0 +1,17 @@
1
+ const createAxisDelta = () => ({
2
+ translate: 0,
3
+ scale: 1,
4
+ origin: 0,
5
+ originPoint: 0,
6
+ });
7
+ const createDelta = () => ({
8
+ x: createAxisDelta(),
9
+ y: createAxisDelta(),
10
+ });
11
+ const createAxis = () => ({ min: 0, max: 0 });
12
+ const createBox = () => ({
13
+ x: createAxis(),
14
+ y: createAxis(),
15
+ });
16
+
17
+ export { createAxis, createAxisDelta, createBox, createDelta };
@@ -0,0 +1,31 @@
1
+ import { calcLength } from './delta-calc.mjs';
2
+
3
+ function isAxisDeltaZero(delta) {
4
+ return delta.translate === 0 && delta.scale === 1;
5
+ }
6
+ function isDeltaZero(delta) {
7
+ return isAxisDeltaZero(delta.x) && isAxisDeltaZero(delta.y);
8
+ }
9
+ function axisEquals(a, b) {
10
+ return a.min === b.min && a.max === b.max;
11
+ }
12
+ function boxEquals(a, b) {
13
+ return axisEquals(a.x, b.x) && axisEquals(a.y, b.y);
14
+ }
15
+ function axisEqualsRounded(a, b) {
16
+ return (Math.round(a.min) === Math.round(b.min) &&
17
+ Math.round(a.max) === Math.round(b.max));
18
+ }
19
+ function boxEqualsRounded(a, b) {
20
+ return axisEqualsRounded(a.x, b.x) && axisEqualsRounded(a.y, b.y);
21
+ }
22
+ function aspectRatio(box) {
23
+ return calcLength(box.x) / calcLength(box.y);
24
+ }
25
+ function axisDeltaEquals(a, b) {
26
+ return (a.translate === b.translate &&
27
+ a.scale === b.scale &&
28
+ a.originPoint === b.originPoint);
29
+ }
30
+
31
+ export { aspectRatio, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, isDeltaZero };
@@ -0,0 +1,13 @@
1
+ import { addDomEvent } from '../../events/add-dom-event.mjs';
2
+ import { createProjectionNode } from './create-projection-node.mjs';
3
+
4
+ const DocumentProjectionNode = createProjectionNode({
5
+ attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
6
+ measureScroll: () => ({
7
+ x: document.documentElement.scrollLeft || document.body.scrollLeft,
8
+ y: document.documentElement.scrollTop || document.body.scrollTop,
9
+ }),
10
+ checkIsScrollRoot: () => true,
11
+ });
12
+
13
+ export { DocumentProjectionNode };
@@ -0,0 +1,27 @@
1
+ import { createProjectionNode } from './create-projection-node.mjs';
2
+ import { DocumentProjectionNode } from './DocumentProjectionNode.mjs';
3
+
4
+ const rootProjectionNode = {
5
+ current: undefined,
6
+ };
7
+ const HTMLProjectionNode = createProjectionNode({
8
+ measureScroll: (instance) => ({
9
+ x: instance.scrollLeft,
10
+ y: instance.scrollTop,
11
+ }),
12
+ defaultParent: () => {
13
+ if (!rootProjectionNode.current) {
14
+ const documentNode = new DocumentProjectionNode({});
15
+ documentNode.mount(window);
16
+ documentNode.setOptions({ layoutScroll: true });
17
+ rootProjectionNode.current = documentNode;
18
+ }
19
+ return rootProjectionNode.current;
20
+ },
21
+ resetTransform: (instance, value) => {
22
+ instance.style.transform = value !== undefined ? value : "none";
23
+ },
24
+ checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
25
+ });
26
+
27
+ export { HTMLProjectionNode, rootProjectionNode };