motion-dom 12.24.11 → 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 (77) hide show
  1. package/dist/cjs/index.js +6197 -1833
  2. package/dist/es/animation/animate/single-value.mjs +11 -0
  3. package/dist/es/animation/interfaces/motion-value.mjs +102 -0
  4. package/dist/es/animation/interfaces/visual-element-target.mjs +85 -0
  5. package/dist/es/animation/interfaces/visual-element-variant.mjs +59 -0
  6. package/dist/es/animation/interfaces/visual-element.mjs +26 -0
  7. package/dist/es/animation/optimized-appear/data-id.mjs +6 -0
  8. package/dist/es/animation/optimized-appear/get-appear-id.mjs +7 -0
  9. package/dist/es/animation/utils/calc-child-stagger.mjs +15 -0
  10. package/dist/es/animation/utils/default-transitions.mjs +40 -0
  11. package/dist/es/animation/utils/get-final-keyframe.mjs +12 -0
  12. package/dist/es/animation/utils/is-transition-defined.mjs +10 -0
  13. package/dist/es/events/add-dom-event.mjs +6 -0
  14. package/dist/es/index.mjs +71 -0
  15. package/dist/es/projection/animation/mix-values.mjs +66 -0
  16. package/dist/es/projection/geometry/conversion.mjs +33 -0
  17. package/dist/es/projection/geometry/copy.mjs +31 -0
  18. package/dist/es/projection/geometry/delta-apply.mjs +119 -0
  19. package/dist/es/projection/geometry/delta-calc.mjs +52 -0
  20. package/dist/es/projection/geometry/delta-remove.mjs +54 -0
  21. package/dist/es/projection/geometry/models.mjs +17 -0
  22. package/dist/es/projection/geometry/utils.mjs +31 -0
  23. package/dist/es/projection/node/DocumentProjectionNode.mjs +13 -0
  24. package/dist/es/projection/node/HTMLProjectionNode.mjs +27 -0
  25. package/dist/es/projection/node/create-projection-node.mjs +1628 -0
  26. package/dist/es/projection/node/group.mjs +24 -0
  27. package/dist/es/projection/node/state.mjs +19 -0
  28. package/dist/es/projection/shared/stack.mjs +100 -0
  29. package/dist/es/projection/styles/scale-border-radius.mjs +41 -0
  30. package/dist/es/projection/styles/scale-box-shadow.mjs +35 -0
  31. package/dist/es/projection/styles/scale-correction.mjs +30 -0
  32. package/dist/es/projection/styles/transform.mjs +49 -0
  33. package/dist/es/projection/utils/compare-by-depth.mjs +3 -0
  34. package/dist/es/projection/utils/each-axis.mjs +5 -0
  35. package/dist/es/projection/utils/flat-tree.mjs +24 -0
  36. package/dist/es/projection/utils/has-transform.mjs +26 -0
  37. package/dist/es/projection/utils/measure.mjs +17 -0
  38. package/dist/es/render/Feature.mjs +14 -0
  39. package/dist/es/render/VisualElement.mjs +510 -0
  40. package/dist/es/render/dom/DOMVisualElement.mjs +42 -0
  41. package/dist/es/render/html/HTMLVisualElement.mjs +44 -0
  42. package/dist/es/render/html/utils/build-styles.mjs +65 -0
  43. package/dist/es/render/html/utils/build-transform.mjs +62 -0
  44. package/dist/es/render/html/utils/render.mjs +17 -0
  45. package/dist/es/render/html/utils/scrape-motion-values.mjs +21 -0
  46. package/dist/es/render/object/ObjectVisualElement.mjs +41 -0
  47. package/dist/es/render/store.mjs +3 -0
  48. package/dist/es/render/svg/SVGVisualElement.mjs +45 -0
  49. package/dist/es/render/svg/utils/build-attrs.mjs +72 -0
  50. package/dist/es/render/svg/utils/camel-case-attrs.mjs +30 -0
  51. package/dist/es/render/svg/utils/is-svg-tag.mjs +3 -0
  52. package/dist/es/render/svg/utils/path.mjs +32 -0
  53. package/dist/es/render/svg/utils/render.mjs +12 -0
  54. package/dist/es/render/svg/utils/scrape-motion-values.mjs +19 -0
  55. package/dist/es/render/utils/animation-state.mjs +364 -0
  56. package/dist/es/render/utils/get-variant-context.mjs +32 -0
  57. package/dist/es/render/utils/is-animation-controls.mjs +7 -0
  58. package/dist/es/render/utils/is-controlling-variants.mjs +13 -0
  59. package/dist/es/render/utils/is-forced-motion-value.mjs +12 -0
  60. package/dist/es/render/utils/is-keyframes-target.mjs +5 -0
  61. package/dist/es/render/utils/is-variant-label.mjs +8 -0
  62. package/dist/es/render/utils/motion-values.mjs +55 -0
  63. package/dist/es/render/utils/reduced-motion/index.mjs +19 -0
  64. package/dist/es/render/utils/reduced-motion/state.mjs +5 -0
  65. package/dist/es/render/utils/resolve-dynamic-variants.mjs +8 -0
  66. package/dist/es/render/utils/resolve-variants.mjs +36 -0
  67. package/dist/es/render/utils/setters.mjs +31 -0
  68. package/dist/es/render/utils/shallow-compare.mjs +14 -0
  69. package/dist/es/render/utils/variant-props.mjs +12 -0
  70. package/dist/es/utils/delay.mjs +24 -0
  71. package/dist/es/value/utils/resolve-motion-value.mjs +10 -0
  72. package/dist/es/value/will-change/add-will-change.mjs +20 -0
  73. package/dist/es/value/will-change/is.mjs +7 -0
  74. package/dist/index.d.ts +3853 -2136
  75. package/dist/motion-dom.dev.js +6197 -1833
  76. package/dist/motion-dom.js +1 -1
  77. package/package.json +2 -2
@@ -0,0 +1,62 @@
1
+ import { getValueAsType } from '../../../value/types/utils/get-as-type.mjs';
2
+ import { numberValueTypes } from '../../../value/types/maps/number.mjs';
3
+ import { transformPropOrder } from '../../utils/keys-transform.mjs';
4
+
5
+ const translateAlias = {
6
+ x: "translateX",
7
+ y: "translateY",
8
+ z: "translateZ",
9
+ transformPerspective: "perspective",
10
+ };
11
+ const numTransforms = transformPropOrder.length;
12
+ /**
13
+ * Build a CSS transform style from individual x/y/scale etc properties.
14
+ *
15
+ * This outputs with a default order of transforms/scales/rotations, this can be customised by
16
+ * providing a transformTemplate function.
17
+ */
18
+ function buildTransform(latestValues, transform, transformTemplate) {
19
+ // The transform string we're going to build into.
20
+ let transformString = "";
21
+ let transformIsDefault = true;
22
+ /**
23
+ * Loop over all possible transforms in order, adding the ones that
24
+ * are present to the transform string.
25
+ */
26
+ for (let i = 0; i < numTransforms; i++) {
27
+ const key = transformPropOrder[i];
28
+ const value = latestValues[key];
29
+ if (value === undefined)
30
+ continue;
31
+ let valueIsDefault = true;
32
+ if (typeof value === "number") {
33
+ valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
34
+ }
35
+ else {
36
+ valueIsDefault = parseFloat(value) === 0;
37
+ }
38
+ if (!valueIsDefault || transformTemplate) {
39
+ const valueAsType = getValueAsType(value, numberValueTypes[key]);
40
+ if (!valueIsDefault) {
41
+ transformIsDefault = false;
42
+ const transformName = translateAlias[key] || key;
43
+ transformString += `${transformName}(${valueAsType}) `;
44
+ }
45
+ if (transformTemplate) {
46
+ transform[key] = valueAsType;
47
+ }
48
+ }
49
+ }
50
+ transformString = transformString.trim();
51
+ // If we have a custom `transform` template, pass our transform values and
52
+ // generated transformString to that before returning
53
+ if (transformTemplate) {
54
+ transformString = transformTemplate(transform, transformIsDefault ? "" : transformString);
55
+ }
56
+ else if (transformIsDefault) {
57
+ transformString = "none";
58
+ }
59
+ return transformString;
60
+ }
61
+
62
+ export { buildTransform };
@@ -0,0 +1,17 @@
1
+ function renderHTML(element, { style, vars }, styleProp, projection) {
2
+ const elementStyle = element.style;
3
+ let key;
4
+ for (key in style) {
5
+ // CSSStyleDeclaration has [index: number]: string; in the types, so we use that as key type.
6
+ elementStyle[key] = style[key];
7
+ }
8
+ // Write projection styles directly to element style
9
+ projection?.applyProjectionStyles(elementStyle, styleProp);
10
+ for (key in vars) {
11
+ // Loop over any CSS variables and assign those.
12
+ // They can only be assigned using `setProperty`.
13
+ elementStyle.setProperty(key, vars[key]);
14
+ }
15
+ }
16
+
17
+ export { renderHTML };
@@ -0,0 +1,21 @@
1
+ import { isMotionValue } from '../../../value/utils/is-motion-value.mjs';
2
+ import { isForcedMotionValue } from '../../utils/is-forced-motion-value.mjs';
3
+
4
+ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
5
+ const style = props.style;
6
+ const prevStyle = prevProps?.style;
7
+ const newValues = {};
8
+ if (!style)
9
+ return newValues;
10
+ for (const key in style) {
11
+ if (isMotionValue(style[key]) ||
12
+ (prevStyle && isMotionValue(prevStyle[key])) ||
13
+ isForcedMotionValue(key, props) ||
14
+ visualElement?.getValue(key)?.liveStyle !== undefined) {
15
+ newValues[key] = style[key];
16
+ }
17
+ }
18
+ return newValues;
19
+ }
20
+
21
+ export { scrapeMotionValuesFromProps };
@@ -0,0 +1,41 @@
1
+ import { createBox } from '../../projection/geometry/models.mjs';
2
+ import { VisualElement } from '../VisualElement.mjs';
3
+
4
+ function isObjectKey(key, object) {
5
+ return key in object;
6
+ }
7
+ class ObjectVisualElement extends VisualElement {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.type = "object";
11
+ }
12
+ readValueFromInstance(instance, key) {
13
+ if (isObjectKey(key, instance)) {
14
+ const value = instance[key];
15
+ if (typeof value === "string" || typeof value === "number") {
16
+ return value;
17
+ }
18
+ }
19
+ return undefined;
20
+ }
21
+ getBaseTargetFromProps() {
22
+ return undefined;
23
+ }
24
+ removeValueFromRenderState(key, renderState) {
25
+ delete renderState.output[key];
26
+ }
27
+ measureInstanceViewportBox() {
28
+ return createBox();
29
+ }
30
+ build(renderState, latestValues) {
31
+ Object.assign(renderState.output, latestValues);
32
+ }
33
+ renderInstance(instance, { output }) {
34
+ Object.assign(instance, output);
35
+ }
36
+ sortInstanceNodePosition() {
37
+ return 0;
38
+ }
39
+ }
40
+
41
+ export { ObjectVisualElement };
@@ -0,0 +1,3 @@
1
+ const visualElementStore = new WeakMap();
2
+
3
+ export { visualElementStore };
@@ -0,0 +1,45 @@
1
+ import { transformProps } from '../utils/keys-transform.mjs';
2
+ import { getDefaultValueType } from '../../value/types/maps/defaults.mjs';
3
+ import { createBox } from '../../projection/geometry/models.mjs';
4
+ import { DOMVisualElement } from '../dom/DOMVisualElement.mjs';
5
+ import { camelToDash } from '../dom/utils/camel-to-dash.mjs';
6
+ import { buildSVGAttrs } from './utils/build-attrs.mjs';
7
+ import { camelCaseAttributes } from './utils/camel-case-attrs.mjs';
8
+ import { isSVGTag } from './utils/is-svg-tag.mjs';
9
+ import { renderSVG } from './utils/render.mjs';
10
+ import { scrapeMotionValuesFromProps } from './utils/scrape-motion-values.mjs';
11
+
12
+ class SVGVisualElement extends DOMVisualElement {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.type = "svg";
16
+ this.isSVGTag = false;
17
+ this.measureInstanceViewportBox = createBox;
18
+ }
19
+ getBaseTargetFromProps(props, key) {
20
+ return props[key];
21
+ }
22
+ readValueFromInstance(instance, key) {
23
+ if (transformProps.has(key)) {
24
+ const defaultType = getDefaultValueType(key);
25
+ return defaultType ? defaultType.default || 0 : 0;
26
+ }
27
+ key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
28
+ return instance.getAttribute(key);
29
+ }
30
+ scrapeMotionValuesFromProps(props, prevProps, visualElement) {
31
+ return scrapeMotionValuesFromProps(props, prevProps, visualElement);
32
+ }
33
+ build(renderState, latestValues, props) {
34
+ buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate, props.style);
35
+ }
36
+ renderInstance(instance, renderState, styleProp, projection) {
37
+ renderSVG(instance, renderState, styleProp, projection);
38
+ }
39
+ mount(instance) {
40
+ this.isSVGTag = isSVGTag(instance.tagName);
41
+ super.mount(instance);
42
+ }
43
+ }
44
+
45
+ export { SVGVisualElement };
@@ -0,0 +1,72 @@
1
+ import { buildHTMLStyles } from '../../html/utils/build-styles.mjs';
2
+ import { buildSVGPath } from './path.mjs';
3
+
4
+ /**
5
+ * CSS Motion Path properties that should remain as CSS styles on SVG elements.
6
+ */
7
+ const cssMotionPathProperties = [
8
+ "offsetDistance",
9
+ "offsetPath",
10
+ "offsetRotate",
11
+ "offsetAnchor",
12
+ ];
13
+ /**
14
+ * Build SVG visual attributes, like cx and style.transform
15
+ */
16
+ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
17
+ // This is object creation, which we try to avoid per-frame.
18
+ ...latest }, isSVGTag, transformTemplate, styleProp) {
19
+ buildHTMLStyles(state, latest, transformTemplate);
20
+ /**
21
+ * For svg tags we just want to make sure viewBox is animatable and treat all the styles
22
+ * as normal HTML tags.
23
+ */
24
+ if (isSVGTag) {
25
+ if (state.style.viewBox) {
26
+ state.attrs.viewBox = state.style.viewBox;
27
+ }
28
+ return;
29
+ }
30
+ state.attrs = state.style;
31
+ state.style = {};
32
+ const { attrs, style } = state;
33
+ /**
34
+ * However, we apply transforms as CSS transforms.
35
+ * So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
36
+ */
37
+ if (attrs.transform) {
38
+ style.transform = attrs.transform;
39
+ delete attrs.transform;
40
+ }
41
+ if (style.transform || attrs.transformOrigin) {
42
+ style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
43
+ delete attrs.transformOrigin;
44
+ }
45
+ if (style.transform) {
46
+ /**
47
+ * SVG's element transform-origin uses its own median as a reference.
48
+ * Therefore, transformBox becomes a fill-box
49
+ */
50
+ style.transformBox = styleProp?.transformBox ?? "fill-box";
51
+ delete attrs.transformBox;
52
+ }
53
+ for (const key of cssMotionPathProperties) {
54
+ if (attrs[key] !== undefined) {
55
+ style[key] = attrs[key];
56
+ delete attrs[key];
57
+ }
58
+ }
59
+ // Render attrX/attrY/attrScale as attributes
60
+ if (attrX !== undefined)
61
+ attrs.x = attrX;
62
+ if (attrY !== undefined)
63
+ attrs.y = attrY;
64
+ if (attrScale !== undefined)
65
+ attrs.scale = attrScale;
66
+ // Build SVG path if one has been defined
67
+ if (pathLength !== undefined) {
68
+ buildSVGPath(attrs, pathLength, pathSpacing, pathOffset, false);
69
+ }
70
+ }
71
+
72
+ export { buildSVGAttrs };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A set of attribute names that are always read/written as camel case.
3
+ */
4
+ const camelCaseAttributes = new Set([
5
+ "baseFrequency",
6
+ "diffuseConstant",
7
+ "kernelMatrix",
8
+ "kernelUnitLength",
9
+ "keySplines",
10
+ "keyTimes",
11
+ "limitingConeAngle",
12
+ "markerHeight",
13
+ "markerWidth",
14
+ "numOctaves",
15
+ "targetX",
16
+ "targetY",
17
+ "surfaceScale",
18
+ "specularConstant",
19
+ "specularExponent",
20
+ "stdDeviation",
21
+ "tableValues",
22
+ "viewBox",
23
+ "gradientTransform",
24
+ "pathLength",
25
+ "startOffset",
26
+ "textLength",
27
+ "lengthAdjust",
28
+ ]);
29
+
30
+ export { camelCaseAttributes };
@@ -0,0 +1,3 @@
1
+ const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
2
+
3
+ export { isSVGTag };
@@ -0,0 +1,32 @@
1
+ import { px } from '../../../value/types/numbers/units.mjs';
2
+
3
+ const dashKeys = {
4
+ offset: "stroke-dashoffset",
5
+ array: "stroke-dasharray",
6
+ };
7
+ const camelKeys = {
8
+ offset: "strokeDashoffset",
9
+ array: "strokeDasharray",
10
+ };
11
+ /**
12
+ * Build SVG path properties. Uses the path's measured length to convert
13
+ * our custom pathLength, pathSpacing and pathOffset into stroke-dashoffset
14
+ * and stroke-dasharray attributes.
15
+ *
16
+ * This function is mutative to reduce per-frame GC.
17
+ */
18
+ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true) {
19
+ // Normalise path length by setting SVG attribute pathLength to 1
20
+ attrs.pathLength = 1;
21
+ // We use dash case when setting attributes directly to the DOM node and camel case
22
+ // when defining props on a React component.
23
+ const keys = useDashCase ? dashKeys : camelKeys;
24
+ // Build the dash offset
25
+ attrs[keys.offset] = px.transform(-offset);
26
+ // Build the dash array
27
+ const pathLength = px.transform(length);
28
+ const pathSpacing = px.transform(spacing);
29
+ attrs[keys.array] = `${pathLength} ${pathSpacing}`;
30
+ }
31
+
32
+ export { buildSVGPath };
@@ -0,0 +1,12 @@
1
+ import { camelToDash } from '../../dom/utils/camel-to-dash.mjs';
2
+ import { renderHTML } from '../../html/utils/render.mjs';
3
+ import { camelCaseAttributes } from './camel-case-attrs.mjs';
4
+
5
+ function renderSVG(element, renderState, _styleProp, projection) {
6
+ renderHTML(element, renderState, undefined, projection);
7
+ for (const key in renderState.attrs) {
8
+ element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
9
+ }
10
+ }
11
+
12
+ export { renderSVG };
@@ -0,0 +1,19 @@
1
+ import { isMotionValue } from '../../../value/utils/is-motion-value.mjs';
2
+ import { transformPropOrder } from '../../utils/keys-transform.mjs';
3
+ import { scrapeMotionValuesFromProps as scrapeMotionValuesFromProps$1 } from '../../html/utils/scrape-motion-values.mjs';
4
+
5
+ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
6
+ const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
7
+ for (const key in props) {
8
+ if (isMotionValue(props[key]) ||
9
+ isMotionValue(prevProps[key])) {
10
+ const targetKey = transformPropOrder.indexOf(key) !== -1
11
+ ? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
12
+ : key;
13
+ newValues[targetKey] = props[key];
14
+ }
15
+ }
16
+ return newValues;
17
+ }
18
+
19
+ export { scrapeMotionValuesFromProps };