motion-dom 12.43.0 → 13.0.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.
- package/dist/cjs/index.js +14 -17
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/render/svg/SVGVisualElement.mjs +7 -1
- package/dist/es/render/svg/SVGVisualElement.mjs.map +1 -1
- package/dist/es/render/svg/utils/build-attrs.mjs +9 -18
- package/dist/es/render/svg/utils/build-attrs.mjs.map +1 -1
- package/dist/motion-dom.dev.js +14 -17
- package/dist/motion-dom.js +1 -1
- package/package.json +3 -3
|
@@ -3,7 +3,7 @@ import { getDefaultValueType } from '../../value/types/maps/defaults.mjs';
|
|
|
3
3
|
import { createBox } from '../../projection/geometry/models.mjs';
|
|
4
4
|
import { DOMVisualElement } from '../dom/DOMVisualElement.mjs';
|
|
5
5
|
import { camelToDash } from '../dom/utils/camel-to-dash.mjs';
|
|
6
|
-
import { buildSVGAttrs } from './utils/build-attrs.mjs';
|
|
6
|
+
import { cssStyleProperties, buildSVGAttrs } from './utils/build-attrs.mjs';
|
|
7
7
|
import { camelCaseAttributes } from './utils/camel-case-attrs.mjs';
|
|
8
8
|
import { isSVGTag } from './utils/is-svg-tag.mjs';
|
|
9
9
|
import { renderSVG } from './utils/render.mjs';
|
|
@@ -24,6 +24,12 @@ class SVGVisualElement extends DOMVisualElement {
|
|
|
24
24
|
const defaultType = getDefaultValueType(key);
|
|
25
25
|
return defaultType ? defaultType.default || 0 : 0;
|
|
26
26
|
}
|
|
27
|
+
if (cssStyleProperties.includes(key)) {
|
|
28
|
+
const computedStyle = getComputedStyle(instance);
|
|
29
|
+
const value = computedStyle[key];
|
|
30
|
+
if (typeof value === "string" && value)
|
|
31
|
+
return value.trim();
|
|
32
|
+
}
|
|
27
33
|
key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
|
|
28
34
|
return instance.getAttribute(key);
|
|
29
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SVGVisualElement.mjs","sources":["../../../../src/render/svg/SVGVisualElement.ts"],"sourcesContent":["import type { AnyResolvedKeyframe } from \"../../animation/types\"\nimport type { MotionValue } from \"../../value\"\nimport type { MotionNodeOptions } from \"../../node/types\"\nimport { transformProps } from \"../utils/keys-transform\"\nimport { getDefaultValueType } from \"../../value/types/maps/defaults\"\nimport { createBox } from \"../../projection/geometry/models\"\nimport { DOMVisualElement } from \"../dom/DOMVisualElement\"\nimport type { DOMVisualElementOptions } from \"../dom/types\"\nimport { camelToDash } from \"../dom/utils/camel-to-dash\"\nimport type { ResolvedValues } from \"../types\"\nimport type { VisualElement, MotionStyle } from \"../VisualElement\"\nimport { SVGRenderState } from \"./types\"\nimport { buildSVGAttrs } from \"./utils/build-attrs\"\nimport { camelCaseAttributes } from \"./utils/camel-case-attrs\"\nimport { isSVGTag } from \"./utils/is-svg-tag\"\nimport { renderSVG } from \"./utils/render\"\nimport { scrapeMotionValuesFromProps } from \"./utils/scrape-motion-values\"\nexport class SVGVisualElement extends DOMVisualElement<\n SVGElement,\n SVGRenderState,\n DOMVisualElementOptions\n> {\n type = \"svg\"\n\n isSVGTag = false\n\n getBaseTargetFromProps(\n props: MotionNodeOptions,\n key: string\n ): AnyResolvedKeyframe | MotionValue<any> | undefined {\n return props[key as keyof MotionNodeOptions]\n }\n\n readValueFromInstance(instance: SVGElement, key: string) {\n if (transformProps.has(key)) {\n const defaultType = getDefaultValueType(key)\n return defaultType ? defaultType.default || 0 : 0\n }\n key = !camelCaseAttributes.has(key) ? camelToDash(key) : key\n return instance.getAttribute(key)\n }\n\n measureInstanceViewportBox = createBox\n\n scrapeMotionValuesFromProps(\n props: MotionNodeOptions,\n prevProps: MotionNodeOptions,\n visualElement: VisualElement\n ) {\n return scrapeMotionValuesFromProps(props, prevProps, visualElement)\n }\n\n build(\n renderState: SVGRenderState,\n latestValues: ResolvedValues,\n props: MotionNodeOptions\n ) {\n buildSVGAttrs(\n renderState,\n latestValues,\n this.isSVGTag,\n props.transformTemplate,\n (props as any).style\n )\n }\n\n renderInstance(\n instance: SVGElement,\n renderState: SVGRenderState,\n styleProp?: MotionStyle | undefined,\n projection?: any\n ): void {\n renderSVG(instance, renderState, styleProp, projection)\n }\n\n mount(instance: SVGElement) {\n this.isSVGTag = isSVGTag(instance.tagName)\n super.mount(instance)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAiBM,MAAO,gBAAiB,SAAQ,gBAIrC,CAAA;AAJD,IAAA,WAAA,GAAA;;QAKI,IAAA,CAAA,IAAI,GAAG,KAAK;QAEZ,IAAA,CAAA,QAAQ,GAAG,KAAK;
|
|
1
|
+
{"version":3,"file":"SVGVisualElement.mjs","sources":["../../../../src/render/svg/SVGVisualElement.ts"],"sourcesContent":["import type { AnyResolvedKeyframe } from \"../../animation/types\"\nimport type { MotionValue } from \"../../value\"\nimport type { MotionNodeOptions } from \"../../node/types\"\nimport { transformProps } from \"../utils/keys-transform\"\nimport { getDefaultValueType } from \"../../value/types/maps/defaults\"\nimport { createBox } from \"../../projection/geometry/models\"\nimport { DOMVisualElement } from \"../dom/DOMVisualElement\"\nimport type { DOMVisualElementOptions } from \"../dom/types\"\nimport { camelToDash } from \"../dom/utils/camel-to-dash\"\nimport type { ResolvedValues } from \"../types\"\nimport type { VisualElement, MotionStyle } from \"../VisualElement\"\nimport { SVGRenderState } from \"./types\"\nimport { buildSVGAttrs, cssStyleProperties } from \"./utils/build-attrs\"\nimport { camelCaseAttributes } from \"./utils/camel-case-attrs\"\nimport { isSVGTag } from \"./utils/is-svg-tag\"\nimport { renderSVG } from \"./utils/render\"\nimport { scrapeMotionValuesFromProps } from \"./utils/scrape-motion-values\"\nexport class SVGVisualElement extends DOMVisualElement<\n SVGElement,\n SVGRenderState,\n DOMVisualElementOptions\n> {\n type = \"svg\"\n\n isSVGTag = false\n\n getBaseTargetFromProps(\n props: MotionNodeOptions,\n key: string\n ): AnyResolvedKeyframe | MotionValue<any> | undefined {\n return props[key as keyof MotionNodeOptions]\n }\n\n readValueFromInstance(instance: SVGElement, key: string) {\n if (transformProps.has(key)) {\n const defaultType = getDefaultValueType(key)\n return defaultType ? defaultType.default || 0 : 0\n }\n\n if (cssStyleProperties.includes(key)) {\n const computedStyle = getComputedStyle(instance)\n const value = computedStyle[key as keyof typeof computedStyle]\n if (typeof value === \"string\" && value) return value.trim()\n }\n\n key = !camelCaseAttributes.has(key) ? camelToDash(key) : key\n return instance.getAttribute(key)\n }\n\n measureInstanceViewportBox = createBox\n\n scrapeMotionValuesFromProps(\n props: MotionNodeOptions,\n prevProps: MotionNodeOptions,\n visualElement: VisualElement\n ) {\n return scrapeMotionValuesFromProps(props, prevProps, visualElement)\n }\n\n build(\n renderState: SVGRenderState,\n latestValues: ResolvedValues,\n props: MotionNodeOptions\n ) {\n buildSVGAttrs(\n renderState,\n latestValues,\n this.isSVGTag,\n props.transformTemplate,\n (props as any).style\n )\n }\n\n renderInstance(\n instance: SVGElement,\n renderState: SVGRenderState,\n styleProp?: MotionStyle | undefined,\n projection?: any\n ): void {\n renderSVG(instance, renderState, styleProp, projection)\n }\n\n mount(instance: SVGElement) {\n this.isSVGTag = isSVGTag(instance.tagName)\n super.mount(instance)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAiBM,MAAO,gBAAiB,SAAQ,gBAIrC,CAAA;AAJD,IAAA,WAAA,GAAA;;QAKI,IAAA,CAAA,IAAI,GAAG,KAAK;QAEZ,IAAA,CAAA,QAAQ,GAAG,KAAK;QAyBhB,IAAA,CAAA,0BAA0B,GAAG,SAAS;IAqC1C;IA5DI,sBAAsB,CAClB,KAAwB,EACxB,GAAW,EAAA;AAEX,QAAA,OAAO,KAAK,CAAC,GAA8B,CAAC;IAChD;IAEA,qBAAqB,CAAC,QAAoB,EAAE,GAAW,EAAA;AACnD,QAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;AACzB,YAAA,MAAM,WAAW,GAAG,mBAAmB,CAAC,GAAG,CAAC;AAC5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TMLStyles } from '../../html/utils/build-styles.mjs';
|
|
2
2
|
import { buildSVGPath } from './path.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const cssMotionPathProperties = [
|
|
4
|
+
const cssStyleProperties = [
|
|
5
|
+
"transform",
|
|
6
|
+
"opacity",
|
|
8
7
|
"offsetDistance",
|
|
9
8
|
"offsetPath",
|
|
10
9
|
"offsetRotate",
|
|
@@ -30,13 +29,11 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing
|
|
|
30
29
|
state.attrs = state.style;
|
|
31
30
|
state.style = {};
|
|
32
31
|
const { attrs, style } = state;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
style.transform = attrs.transform;
|
|
39
|
-
delete attrs.transform;
|
|
32
|
+
for (const key of cssStyleProperties) {
|
|
33
|
+
if (attrs[key] !== undefined) {
|
|
34
|
+
style[key] = attrs[key];
|
|
35
|
+
delete attrs[key];
|
|
36
|
+
}
|
|
40
37
|
}
|
|
41
38
|
if (style.transform || attrs.transformOrigin) {
|
|
42
39
|
style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
|
|
@@ -50,12 +47,6 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing
|
|
|
50
47
|
style.transformBox = styleProp?.transformBox ?? "fill-box";
|
|
51
48
|
delete attrs.transformBox;
|
|
52
49
|
}
|
|
53
|
-
for (const key of cssMotionPathProperties) {
|
|
54
|
-
if (attrs[key] !== undefined) {
|
|
55
|
-
style[key] = attrs[key];
|
|
56
|
-
delete attrs[key];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
50
|
// Render attrX/attrY/attrScale as attributes
|
|
60
51
|
if (attrX !== undefined)
|
|
61
52
|
attrs.x = attrX;
|
|
@@ -69,5 +60,5 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing
|
|
|
69
60
|
}
|
|
70
61
|
}
|
|
71
62
|
|
|
72
|
-
export { buildSVGAttrs };
|
|
63
|
+
export { buildSVGAttrs, cssStyleProperties };
|
|
73
64
|
//# sourceMappingURL=build-attrs.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-attrs.mjs","sources":["../../../../../src/render/svg/utils/build-attrs.ts"],"sourcesContent":["import type { MotionNodeOptions } from \"../../../node/types\"\nimport { buildHTMLStyles } from \"../../html/utils/build-styles\"\nimport { ResolvedValues } from \"../../types\"\nimport { SVGRenderState } from \"../types\"\nimport { buildSVGPath } from \"./path\"\n\
|
|
1
|
+
{"version":3,"file":"build-attrs.mjs","sources":["../../../../../src/render/svg/utils/build-attrs.ts"],"sourcesContent":["import type { MotionNodeOptions } from \"../../../node/types\"\nimport { buildHTMLStyles } from \"../../html/utils/build-styles\"\nimport { ResolvedValues } from \"../../types\"\nimport { SVGRenderState } from \"../types\"\nimport { buildSVGPath } from \"./path\"\n\nexport const cssStyleProperties = [\n \"transform\",\n \"opacity\",\n \"offsetDistance\",\n \"offsetPath\",\n \"offsetRotate\",\n \"offsetAnchor\",\n]\n\n/**\n * Build SVG visual attributes, like cx and style.transform\n */\nexport function buildSVGAttrs(\n state: SVGRenderState,\n {\n attrX,\n attrY,\n attrScale,\n pathLength,\n pathSpacing = 1,\n pathOffset = 0,\n // This is object creation, which we try to avoid per-frame.\n ...latest\n }: ResolvedValues,\n isSVGTag: boolean,\n transformTemplate?: MotionNodeOptions[\"transformTemplate\"],\n styleProp?: Record<string, any>\n) {\n buildHTMLStyles(state, latest, transformTemplate)\n\n /**\n * For svg tags we just want to make sure viewBox is animatable and treat all the styles\n * as normal HTML tags.\n */\n if (isSVGTag) {\n if (state.style.viewBox) {\n state.attrs.viewBox = state.style.viewBox\n }\n return\n }\n\n state.attrs = state.style\n state.style = {}\n const { attrs, style } = state\n\n for (const key of cssStyleProperties) {\n if (attrs[key] !== undefined) {\n style[key] = attrs[key]\n delete attrs[key]\n }\n }\n\n if (style.transform || attrs.transformOrigin) {\n style.transformOrigin = attrs.transformOrigin ?? \"50% 50%\"\n delete attrs.transformOrigin\n }\n\n if (style.transform) {\n /**\n * SVG's element transform-origin uses its own median as a reference.\n * Therefore, transformBox becomes a fill-box\n */\n style.transformBox = (styleProp?.transformBox as string) ?? \"fill-box\"\n delete attrs.transformBox\n }\n\n // Render attrX/attrY/attrScale as attributes\n if (attrX !== undefined) attrs.x = attrX\n if (attrY !== undefined) attrs.y = attrY\n if (attrScale !== undefined) attrs.scale = attrScale\n\n // Build SVG path if one has been defined\n if (pathLength !== undefined) {\n buildSVGPath(\n attrs,\n pathLength as number,\n pathSpacing as number,\n pathOffset as number,\n false\n )\n }\n}\n"],"names":[],"mappings":";;;AAMO,MAAM,kBAAkB,GAAG;IAC9B,WAAW;IACX,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,cAAc;IACd,cAAc;;AAGlB;;AAEG;AACG,SAAU,aAAa,CACzB,KAAqB,EACrB,EACI,KAAK,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,WAAW,GAAG,CAAC,EACf,UAAU,GAAG,CAAC;AACd;AACA,GAAG,MAAM,EACI,EACjB,QAAiB,EACjB,iBAA0D,EAC1D,SAA+B,EAAA;AAE/B,IAAA,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC;AAEjD;;;AAGG;IACH,IAAI,QAAQ,EAAE;AACV,QAAA,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE;YACrB,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO;QAC7C;QACA;IACJ;AAEA,IAAA,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK;AACzB,IAAA,KAAK,CAAC,KAAK,GAAG,EAAE;AAChB,IAAA,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK;AAE9B,IAAA,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE;AAClC,QAAA,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;YAC1B,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;AACvB,YAAA,OAAO,KAAK,CAAC,GAAG,CAAC;QACrB;IACJ;IAEA,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,eAAe,EAAE;QAC1C,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,IAAI,SAAS;QAC1D,OAAO,KAAK,CAAC,eAAe;IAChC;AAEA,IAAA,IAAI,KAAK,CAAC,SAAS,EAAE;AACjB;;;AAGG;QACH,KAAK,CAAC,YAAY,GAAI,SAAS,EAAE,YAAuB,IAAI,UAAU;QACtE,OAAO,KAAK,CAAC,YAAY;IAC7B;;IAGA,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,KAAK,CAAC,CAAC,GAAG,KAAK;IACxC,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,KAAK,CAAC,CAAC,GAAG,KAAK;IACxC,IAAI,SAAS,KAAK,SAAS;AAAE,QAAA,KAAK,CAAC,KAAK,GAAG,SAAS;;AAGpD,IAAA,IAAI,UAAU,KAAK,SAAS,EAAE;QAC1B,YAAY,CACR,KAAK,EACL,UAAoB,EACpB,WAAqB,EACrB,UAAoB,EACpB,KAAK,CACR;IACL;AACJ;;;;"}
|
package/dist/motion-dom.dev.js
CHANGED
|
@@ -7690,10 +7690,9 @@
|
|
|
7690
7690
|
attrs[keys.array] = `${length} ${spacing}`;
|
|
7691
7691
|
}
|
|
7692
7692
|
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
const cssMotionPathProperties = [
|
|
7693
|
+
const cssStyleProperties = [
|
|
7694
|
+
"transform",
|
|
7695
|
+
"opacity",
|
|
7697
7696
|
"offsetDistance",
|
|
7698
7697
|
"offsetPath",
|
|
7699
7698
|
"offsetRotate",
|
|
@@ -7719,13 +7718,11 @@
|
|
|
7719
7718
|
state.attrs = state.style;
|
|
7720
7719
|
state.style = {};
|
|
7721
7720
|
const { attrs, style } = state;
|
|
7722
|
-
|
|
7723
|
-
|
|
7724
|
-
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
style.transform = attrs.transform;
|
|
7728
|
-
delete attrs.transform;
|
|
7721
|
+
for (const key of cssStyleProperties) {
|
|
7722
|
+
if (attrs[key] !== undefined) {
|
|
7723
|
+
style[key] = attrs[key];
|
|
7724
|
+
delete attrs[key];
|
|
7725
|
+
}
|
|
7729
7726
|
}
|
|
7730
7727
|
if (style.transform || attrs.transformOrigin) {
|
|
7731
7728
|
style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
|
|
@@ -7739,12 +7736,6 @@
|
|
|
7739
7736
|
style.transformBox = styleProp?.transformBox ?? "fill-box";
|
|
7740
7737
|
delete attrs.transformBox;
|
|
7741
7738
|
}
|
|
7742
|
-
for (const key of cssMotionPathProperties) {
|
|
7743
|
-
if (attrs[key] !== undefined) {
|
|
7744
|
-
style[key] = attrs[key];
|
|
7745
|
-
delete attrs[key];
|
|
7746
|
-
}
|
|
7747
|
-
}
|
|
7748
7739
|
// Render attrX/attrY/attrScale as attributes
|
|
7749
7740
|
if (attrX !== undefined)
|
|
7750
7741
|
attrs.x = attrX;
|
|
@@ -7825,6 +7816,12 @@
|
|
|
7825
7816
|
const defaultType = getDefaultValueType(key);
|
|
7826
7817
|
return defaultType ? defaultType.default || 0 : 0;
|
|
7827
7818
|
}
|
|
7819
|
+
if (cssStyleProperties.includes(key)) {
|
|
7820
|
+
const computedStyle = getComputedStyle(instance);
|
|
7821
|
+
const value = computedStyle[key];
|
|
7822
|
+
if (typeof value === "string" && value)
|
|
7823
|
+
return value.trim();
|
|
7824
|
+
}
|
|
7828
7825
|
key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
|
|
7829
7826
|
return instance.getAttribute(key);
|
|
7830
7827
|
}
|