motion-dom 13.1.1 → 13.3.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 (93) hide show
  1. package/dist/cjs/index.js +6178 -5360
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/AsyncMotionValueAnimation.mjs +41 -38
  4. package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
  5. package/dist/es/animation/FollowAnimation.mjs +152 -0
  6. package/dist/es/animation/FollowAnimation.mjs.map +1 -0
  7. package/dist/es/animation/JSAnimation.mjs +7 -11
  8. package/dist/es/animation/JSAnimation.mjs.map +1 -1
  9. package/dist/es/animation/NativeAnimation.mjs +2 -0
  10. package/dist/es/animation/NativeAnimation.mjs.map +1 -1
  11. package/dist/es/animation/NativeAnimationWrapper.mjs +7 -0
  12. package/dist/es/animation/NativeAnimationWrapper.mjs.map +1 -1
  13. package/dist/es/animation/animate/effects.mjs +105 -0
  14. package/dist/es/animation/animate/effects.mjs.map +1 -0
  15. package/dist/es/animation/animate/element.mjs +80 -0
  16. package/dist/es/animation/animate/element.mjs.map +1 -0
  17. package/dist/es/animation/animate/single-value.mjs.map +1 -1
  18. package/dist/es/animation/generators/inertia.mjs +8 -6
  19. package/dist/es/animation/generators/inertia.mjs.map +1 -1
  20. package/dist/es/animation/generators/keyframes.mjs +25 -1
  21. package/dist/es/animation/generators/keyframes.mjs.map +1 -1
  22. package/dist/es/animation/generators/spring.mjs +119 -86
  23. package/dist/es/animation/generators/spring.mjs.map +1 -1
  24. package/dist/es/animation/generators/utils/calc-duration.mjs +5 -4
  25. package/dist/es/animation/generators/utils/calc-duration.mjs.map +1 -1
  26. package/dist/es/animation/generators/utils/velocity.mjs +13 -1
  27. package/dist/es/animation/generators/utils/velocity.mjs.map +1 -1
  28. package/dist/es/animation/interfaces/motion-value.mjs.map +1 -1
  29. package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
  30. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +12 -6
  31. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
  32. package/dist/es/animation/keyframes/KeyframesResolver.mjs +38 -7
  33. package/dist/es/animation/keyframes/KeyframesResolver.mjs.map +1 -1
  34. package/dist/es/animation/keyframes/utils/make-none-animatable.mjs +8 -2
  35. package/dist/es/animation/keyframes/utils/make-none-animatable.mjs.map +1 -1
  36. package/dist/es/animation/keyframes/utils/unit-conversion.mjs +45 -19
  37. package/dist/es/animation/keyframes/utils/unit-conversion.mjs.map +1 -1
  38. package/dist/es/animation/utils/WithPromise.mjs +12 -5
  39. package/dist/es/animation/utils/WithPromise.mjs.map +1 -1
  40. package/dist/es/animation/utils/arc.mjs +2 -1
  41. package/dist/es/animation/utils/arc.mjs.map +1 -1
  42. package/dist/es/animation/utils/can-animate.mjs +3 -1
  43. package/dist/es/animation/utils/can-animate.mjs.map +1 -1
  44. package/dist/es/animation/utils/notify-inspector.mjs +56 -0
  45. package/dist/es/animation/utils/notify-inspector.mjs.map +1 -0
  46. package/dist/es/animation/waapi/supports/waapi.mjs +8 -1
  47. package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
  48. package/dist/es/effects/MotionValueState.mjs +90 -26
  49. package/dist/es/effects/MotionValueState.mjs.map +1 -1
  50. package/dist/es/effects/attr/index.mjs +15 -9
  51. package/dist/es/effects/attr/index.mjs.map +1 -1
  52. package/dist/es/effects/prop/index.mjs +15 -2
  53. package/dist/es/effects/prop/index.mjs.map +1 -1
  54. package/dist/es/effects/style/index.mjs +52 -9
  55. package/dist/es/effects/style/index.mjs.map +1 -1
  56. package/dist/es/effects/style/transform.mjs +28 -25
  57. package/dist/es/effects/style/transform.mjs.map +1 -1
  58. package/dist/es/effects/svg/index.mjs +40 -7
  59. package/dist/es/effects/svg/index.mjs.map +1 -1
  60. package/dist/es/effects/utils/create-dom-effect.mjs +9 -1
  61. package/dist/es/effects/utils/create-dom-effect.mjs.map +1 -1
  62. package/dist/es/effects/utils/create-effect.mjs +8 -3
  63. package/dist/es/effects/utils/create-effect.mjs.map +1 -1
  64. package/dist/es/frameloop/render-step.mjs +5 -2
  65. package/dist/es/frameloop/render-step.mjs.map +1 -1
  66. package/dist/es/index.mjs +7 -3
  67. package/dist/es/index.mjs.map +1 -1
  68. package/dist/es/layout/LayoutAnimationBuilder.mjs +9 -1
  69. package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
  70. package/dist/es/projection/node/create-projection-node.mjs +4 -1
  71. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  72. package/dist/es/render/VisualElement.mjs +11 -2
  73. package/dist/es/render/VisualElement.mjs.map +1 -1
  74. package/dist/es/render/utils/is-controlling-variants.mjs +8 -2
  75. package/dist/es/render/utils/is-controlling-variants.mjs.map +1 -1
  76. package/dist/es/utils/mix/color.mjs +3 -2
  77. package/dist/es/utils/mix/color.mjs.map +1 -1
  78. package/dist/es/utils/mix/index.mjs +28 -0
  79. package/dist/es/utils/mix/index.mjs.map +1 -1
  80. package/dist/es/value/follow-value.mjs +33 -30
  81. package/dist/es/value/follow-value.mjs.map +1 -1
  82. package/dist/es/value/index.mjs +73 -29
  83. package/dist/es/value/index.mjs.map +1 -1
  84. package/dist/es/value/types/complex/index.mjs +17 -4
  85. package/dist/es/value/types/complex/index.mjs.map +1 -1
  86. package/dist/index.d.ts +307 -47
  87. package/dist/motion-dom.dev.js +6178 -5360
  88. package/dist/motion-dom.js +1 -1
  89. package/dist/size-rollup-motion-value.js +1 -1
  90. package/dist/size-rollup-motion-value.js.map +1 -1
  91. package/dist/size-rollup-style-effect.js +1 -1
  92. package/dist/size-rollup-style-effect.js.map +1 -1
  93. package/package.json +4 -4
@@ -17,6 +17,14 @@ const colorProperties = new Set([
17
17
  const supportsWaapi = /*@__PURE__*/ memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
18
18
  function supportsBrowserAnimation(options) {
19
19
  const { motionValue, name, repeatDelay, repeatType, damping, type, keyframes, } = options;
20
+ /**
21
+ * Most values can't be accelerated at all, so check the name before
22
+ * looking at the element or its props.
23
+ */
24
+ if (!name ||
25
+ !(acceleratedValues.has(name) || colorProperties.has(name))) {
26
+ return false;
27
+ }
20
28
  const subject = motionValue?.owner?.current;
21
29
  /**
22
30
  * We use instanceof checks instead of isHTMLElement()/isSVGElement()
@@ -31,7 +39,6 @@ function supportsBrowserAnimation(options) {
31
39
  }
32
40
  const { onUpdate, transformTemplate } = motionValue.owner.getProps();
33
41
  return (supportsWaapi() &&
34
- name &&
35
42
  /**
36
43
  * Force WAAPI for color properties with browser-only color formats
37
44
  * (oklch, oklab, lab, lch, etc.) that the JS animation path can't parse.
@@ -1 +1 @@
1
- {"version":3,"file":"waapi.mjs","sources":["../../../../../src/animation/waapi/supports/waapi.ts"],"sourcesContent":["import { memo } from \"motion-utils\"\nimport {\n AnyResolvedKeyframe,\n ValueAnimationOptionsWithRenderContext,\n} from \"../../types\"\nimport { acceleratedValues } from \"../utils/accelerated-values\"\nimport { hasBrowserOnlyColors } from \"../utils/is-browser-color\"\n\nconst colorProperties = new Set([\n \"color\",\n \"backgroundColor\",\n \"outlineColor\",\n \"fill\",\n \"stroke\",\n \"borderColor\",\n \"borderTopColor\",\n \"borderRightColor\",\n \"borderBottomColor\",\n \"borderLeftColor\",\n])\n\nconst supportsWaapi = /*@__PURE__*/ memo(() =>\n Object.hasOwnProperty.call(Element.prototype, \"animate\")\n)\n\nexport function supportsBrowserAnimation<T extends AnyResolvedKeyframe>(\n options: ValueAnimationOptionsWithRenderContext<T>\n) {\n const {\n motionValue,\n name,\n repeatDelay,\n repeatType,\n damping,\n type,\n keyframes,\n } = options\n\n const subject = motionValue?.owner?.current\n\n /**\n * We use instanceof checks instead of isHTMLElement()/isSVGElement()\n * because we explicitly **don't** want elements in different timing\n * contexts (i.e. popups) to be accelerated, as it's not possible to sync\n * these animations properly with those driven from the main window\n * frameloop.\n */\n if (\n !(subject instanceof HTMLElement) &&\n !(subject instanceof SVGElement)\n ) {\n return false\n }\n\n const { onUpdate, transformTemplate } = motionValue!.owner!.getProps()\n\n return (\n supportsWaapi() &&\n name &&\n /**\n * Force WAAPI for color properties with browser-only color formats\n * (oklch, oklab, lab, lch, etc.) that the JS animation path can't parse.\n */\n (acceleratedValues.has(name) ||\n (colorProperties.has(name) &&\n hasBrowserOnlyColors(keyframes))) &&\n (name !== \"transform\" || !transformTemplate) &&\n /**\n * If we're outputting values to onUpdate then we can't use WAAPI as there's\n * no way to read the value from WAAPI every frame.\n */\n !onUpdate &&\n !repeatDelay &&\n repeatType !== \"mirror\" &&\n damping !== 0 &&\n type !== \"inertia\"\n )\n}\n"],"names":[],"mappings":";;;;AAQA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC5B,OAAO;IACP,iBAAiB;IACjB,cAAc;IACd,MAAM;IACN,QAAQ;IACR,aAAa;IACb,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;IACnB,iBAAiB;AACpB,CAAA,CAAC;AAEF,MAAM,aAAa,iBAAiB,IAAI,CAAC,MACrC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAC3D;AAEK,SAAU,wBAAwB,CACpC,OAAkD,EAAA;AAElD,IAAA,MAAM,EACF,WAAW,EACX,IAAI,EACJ,WAAW,EACX,UAAU,EACV,OAAO,EACP,IAAI,EACJ,SAAS,GACZ,GAAG,OAAO;AAEX,IAAA,MAAM,OAAO,GAAG,WAAW,EAAE,KAAK,EAAE,OAAO;AAE3C;;;;;;AAMG;AACH,IAAA,IACI,EAAE,OAAO,YAAY,WAAW,CAAC;AACjC,QAAA,EAAE,OAAO,YAAY,UAAU,CAAC,EAClC;AACE,QAAA,OAAO,KAAK;IAChB;AAEA,IAAA,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,WAAY,CAAC,KAAM,CAAC,QAAQ,EAAE;IAEtE,QACI,aAAa,EAAE;QACf,IAAI;AACJ;;;AAGG;AACH,SAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC;AACxB,aAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;AACtB,gBAAA,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC;AACzC,SAAC,IAAI,KAAK,WAAW,IAAI,CAAC,iBAAiB,CAAC;AAC5C;;;AAGG;AACH,QAAA,CAAC,QAAQ;AACT,QAAA,CAAC,WAAW;AACZ,QAAA,UAAU,KAAK,QAAQ;AACvB,QAAA,OAAO,KAAK,CAAC;QACb,IAAI,KAAK,SAAS;AAE1B;;;;"}
1
+ {"version":3,"file":"waapi.mjs","sources":["../../../../../src/animation/waapi/supports/waapi.ts"],"sourcesContent":["import { memo } from \"motion-utils\"\nimport {\n AnyResolvedKeyframe,\n ValueAnimationOptionsWithRenderContext,\n} from \"../../types\"\nimport { acceleratedValues } from \"../utils/accelerated-values\"\nimport { hasBrowserOnlyColors } from \"../utils/is-browser-color\"\n\nconst colorProperties = new Set([\n \"color\",\n \"backgroundColor\",\n \"outlineColor\",\n \"fill\",\n \"stroke\",\n \"borderColor\",\n \"borderTopColor\",\n \"borderRightColor\",\n \"borderBottomColor\",\n \"borderLeftColor\",\n])\n\nconst supportsWaapi = /*@__PURE__*/ memo(() =>\n Object.hasOwnProperty.call(Element.prototype, \"animate\")\n)\n\nexport function supportsBrowserAnimation<T extends AnyResolvedKeyframe>(\n options: ValueAnimationOptionsWithRenderContext<T>\n) {\n const {\n motionValue,\n name,\n repeatDelay,\n repeatType,\n damping,\n type,\n keyframes,\n } = options\n\n /**\n * Most values can't be accelerated at all, so check the name before\n * looking at the element or its props.\n */\n if (\n !name ||\n !(acceleratedValues.has(name) || colorProperties.has(name))\n ) {\n return false\n }\n\n const subject = motionValue?.owner?.current\n\n /**\n * We use instanceof checks instead of isHTMLElement()/isSVGElement()\n * because we explicitly **don't** want elements in different timing\n * contexts (i.e. popups) to be accelerated, as it's not possible to sync\n * these animations properly with those driven from the main window\n * frameloop.\n */\n if (\n !(subject instanceof HTMLElement) &&\n !(subject instanceof SVGElement)\n ) {\n return false\n }\n\n const { onUpdate, transformTemplate } = motionValue!.owner!.getProps()\n\n return (\n supportsWaapi() &&\n /**\n * Force WAAPI for color properties with browser-only color formats\n * (oklch, oklab, lab, lch, etc.) that the JS animation path can't parse.\n */\n (acceleratedValues.has(name) ||\n (colorProperties.has(name) &&\n hasBrowserOnlyColors(keyframes))) &&\n (name !== \"transform\" || !transformTemplate) &&\n /**\n * If we're outputting values to onUpdate then we can't use WAAPI as there's\n * no way to read the value from WAAPI every frame.\n */\n !onUpdate &&\n !repeatDelay &&\n repeatType !== \"mirror\" &&\n damping !== 0 &&\n type !== \"inertia\"\n )\n}\n"],"names":[],"mappings":";;;;AAQA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC5B,OAAO;IACP,iBAAiB;IACjB,cAAc;IACd,MAAM;IACN,QAAQ;IACR,aAAa;IACb,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;IACnB,iBAAiB;AACpB,CAAA,CAAC;AAEF,MAAM,aAAa,iBAAiB,IAAI,CAAC,MACrC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAC3D;AAEK,SAAU,wBAAwB,CACpC,OAAkD,EAAA;AAElD,IAAA,MAAM,EACF,WAAW,EACX,IAAI,EACJ,WAAW,EACX,UAAU,EACV,OAAO,EACP,IAAI,EACJ,SAAS,GACZ,GAAG,OAAO;AAEX;;;AAGG;AACH,IAAA,IACI,CAAC,IAAI;AACL,QAAA,EAAE,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAC7D;AACE,QAAA,OAAO,KAAK;IAChB;AAEA,IAAA,MAAM,OAAO,GAAG,WAAW,EAAE,KAAK,EAAE,OAAO;AAE3C;;;;;;AAMG;AACH,IAAA,IACI,EAAE,OAAO,YAAY,WAAW,CAAC;AACjC,QAAA,EAAE,OAAO,YAAY,UAAU,CAAC,EAClC;AACE,QAAA,OAAO,KAAK;IAChB;AAEA,IAAA,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,WAAY,CAAC,KAAM,CAAC,QAAQ,EAAE;IAEtE,QACI,aAAa,EAAE;AACf;;;AAGG;AACH,SAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC;AACxB,aAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;AACtB,gBAAA,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC;AACzC,SAAC,IAAI,KAAK,WAAW,IAAI,CAAC,iBAAiB,CAAC;AAC5C;;;AAGG;AACH,QAAA,CAAC,QAAQ;AACT,QAAA,CAAC,WAAW;AACZ,QAAA,UAAU,KAAK,QAAQ;AACvB,QAAA,OAAO,KAAK,CAAC;QACb,IAAI,KAAK,SAAS;AAE1B;;;;"}
@@ -1,42 +1,106 @@
1
- import { frame, cancelFrame } from '../frameloop/frame.mjs';
2
- import { numberValueTypes } from '../value/types/maps/number.mjs';
3
- import { getValueAsType } from '../value/types/utils/get-as-type.mjs';
1
+ import { frame } from '../frameloop/frame.mjs';
4
2
 
5
3
  class MotionValueState {
6
- constructor() {
7
- this.latest = {};
4
+ /**
5
+ * @param step - The frameloop step renders are scheduled in. Defaults
6
+ * to `frame.render`. Effects that feed a render loop running in
7
+ * `frame.render` (GPU scenes) should write in `frame.preRender`.
8
+ */
9
+ constructor(step = frame.render) {
10
+ this.step = step;
8
11
  this.values = new Map();
12
+ /**
13
+ * Renders scheduled for the next flush, usually one or two (values
14
+ * bound to the same computed render, e.g. `x` and `y` to `transform`,
15
+ * share an entry). Tracked with a count rather than truncating the
16
+ * array so no backing store is reallocated every frame. Kept per
17
+ * state so pending writes can be flushed synchronously before the
18
+ * subject is measured.
19
+ */
20
+ this.pending = [];
21
+ this.numPending = 0;
22
+ /**
23
+ * Run the pending renders. Resetting the count first means a render
24
+ * scheduled while flushing lands in the next frame, as with the
25
+ * frameloop itself.
26
+ */
27
+ this.flush = () => {
28
+ const { pending, numPending } = this;
29
+ this.numPending = 0;
30
+ for (let i = 0; i < numPending; i++)
31
+ pending[i]();
32
+ };
9
33
  }
10
- set(name, value, render, computed, useDefaultValueType = true) {
11
- const existingValue = this.values.get(name);
12
- if (existingValue) {
13
- existingValue.onRemove();
14
- }
15
- const onChange = () => {
16
- const v = value.get();
17
- if (useDefaultValueType) {
18
- this.latest[name] = getValueAsType(v, numberValueTypes[name]);
19
- }
20
- else {
21
- this.latest[name] = v;
34
+ /**
35
+ * @param render - Writes the value to the subject. Renders read the
36
+ * motion value directly rather than a cached copy, so there is one
37
+ * place a value lives.
38
+ * @param computed - A value already in this state (e.g. `transform`)
39
+ * whose render should run whenever `value` changes.
40
+ */
41
+ set(name, value, render, computed) {
42
+ this.values.get(name)?.onRemove();
43
+ if (computed) {
44
+ for (const entry of this.values.values()) {
45
+ if (entry.value === computed)
46
+ render = entry.render;
22
47
  }
23
- render && frame.render(render);
24
- };
25
- onChange();
48
+ }
49
+ const onChange = () => render && this.schedule(render);
50
+ /**
51
+ * Values created ahead of a DOM read start out undefined and
52
+ * have nothing to render until they're set.
53
+ */
54
+ value.get() !== undefined && onChange();
26
55
  const cancelOnChange = value.on("change", onChange);
27
- computed && value.addDependent(computed);
28
- const remove = () => {
56
+ const onRemove = () => {
29
57
  cancelOnChange();
30
- render && cancelFrame(render);
58
+ render && !computed && this.cancel(render);
31
59
  this.values.delete(name);
32
- computed && value.removeDependent(computed);
33
60
  };
34
- this.values.set(name, { value, onRemove: remove });
35
- return remove;
61
+ this.values.set(name, {
62
+ value,
63
+ render: computed ? undefined : render,
64
+ onRemove,
65
+ });
66
+ return onRemove;
36
67
  }
37
68
  get(name) {
38
69
  return this.values.get(name)?.value;
39
70
  }
71
+ /**
72
+ * Detach every value from this state and return them, so another
73
+ * renderer can take them over. The state stays cached by its effect,
74
+ * so the bound transforms are reset too rather than leaking into
75
+ * values bound later.
76
+ */
77
+ release() {
78
+ const values = new Map();
79
+ this.values.forEach((entry, name) => {
80
+ values.set(name, entry.value);
81
+ entry.onRemove();
82
+ });
83
+ this.transformKeys = this.transformValues = undefined;
84
+ return values;
85
+ }
86
+ schedule(render) {
87
+ const { pending, numPending } = this;
88
+ for (let i = 0; i < numPending; i++) {
89
+ if (pending[i] === render)
90
+ return;
91
+ }
92
+ numPending || this.step(this.flush);
93
+ pending[this.numPending++] = render;
94
+ }
95
+ cancel(render) {
96
+ const { pending } = this;
97
+ for (let i = 0; i < this.numPending; i++) {
98
+ if (pending[i] === render) {
99
+ pending[i] = pending[--this.numPending];
100
+ return;
101
+ }
102
+ }
103
+ }
40
104
  }
41
105
 
42
106
  export { MotionValueState };
@@ -1 +1 @@
1
- {"version":3,"file":"MotionValueState.mjs","sources":["../../../src/effects/MotionValueState.ts"],"sourcesContent":["import { AnyResolvedKeyframe } from \"../animation/types\"\nimport { cancelFrame, frame } from \"../frameloop/frame\"\nimport { MotionValue } from \"../value\"\nimport { numberValueTypes } from \"../value/types/maps/number\"\nimport { getValueAsType } from \"../value/types/utils/get-as-type\"\n\nexport class MotionValueState {\n latest: { [name: string]: AnyResolvedKeyframe } = {}\n\n private values = new Map<\n string,\n { value: MotionValue; onRemove: VoidFunction }\n >()\n\n set(\n name: string,\n value: MotionValue,\n render?: VoidFunction,\n computed?: MotionValue,\n useDefaultValueType = true\n ) {\n const existingValue = this.values.get(name)\n\n if (existingValue) {\n existingValue.onRemove()\n }\n\n const onChange = () => {\n const v = value.get()\n\n if (useDefaultValueType) {\n this.latest[name] = getValueAsType(v, numberValueTypes[name])\n } else {\n this.latest[name] = v\n }\n\n render && frame.render(render)\n }\n\n onChange()\n\n const cancelOnChange = value.on(\"change\", onChange)\n\n computed && value.addDependent(computed)\n\n const remove = () => {\n cancelOnChange()\n render && cancelFrame(render)\n this.values.delete(name)\n computed && value.removeDependent(computed)\n }\n\n this.values.set(name, { value, onRemove: remove })\n\n return remove\n }\n\n get(name: string): Motion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IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAElD,QAAA,OAAO,MAAM;IACjB;AAEA,IAAA,GAAG,CAAC,IAAY,EAAA;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK;IACvC;AACH;;;;"}
1
+ {"version":3,"file":"MotionValueState.mjs","sources":["../../../src/effects/MotionValueState.ts"],"sourcesContent":["import { frame } from \"../frameloop/frame\"\nimport { Schedule } from \"../frameloop/types\"\nimport { MotionValue } from \"../value\"\n\ninterface Entry {\n value: MotionValue\n render?: VoidFunction\n onRemove: VoidFunction\n}\n\nexport class MotionValueState {\n /**\n * Transform keys bound to this state, in `transformPropOrder`, and\n * the value bound to each. Lets the transform builder visit only\n * bound transforms, reading each value directly.\n */\n transformKeys?: string[]\n transformValues?: Record<string, MotionValue>\n\n private values = new Map<string, Entry>()\n\n /**\n * Renders scheduled for the next flush, usually one or two (values\n * bound to the same computed render, e.g. `x` and `y` to `transform`,\n * share an entry). Tracked with a count rather than truncating the\n * array so no backing store is reallocated every frame. Kept per\n * state so pending writes can be flushed synchronously before the\n * subject is measured.\n */\n private pending: VoidFunction[] = []\n private numPending = 0\n\n /**\n * @param step - The frameloop step renders are scheduled in. Defaults\n * to `frame.render`. Effects that feed a render loop running in\n * `frame.render` (GPU scenes) should write in `frame.preRender`.\n */\n constructor(private step: Schedule = frame.render) {}\n\n /**\n * @param render - Writes the value to the subject. Renders read the\n * motion value directly rather than a cached copy, so there is one\n * place a value lives.\n * @param computed - A value already in this state (e.g. `transform`)\n * whose render should run whenever `value` changes.\n */\n set(\n name: string,\n value: MotionValue,\n render?: VoidFunction,\n computed?: MotionValue\n ): VoidFunction {\n this.values.get(name)?.onRemove()\n\n if (computed) {\n for (const entry of this.values.values()) {\n if (entry.value === computed) render = entry.render\n }\n }\n\n const onChange = () => render && this.schedule(render)\n\n /**\n * Values created ahead of a DOM read start out undefined and\n * have nothing to render until they're set.\n */\n value.get() !== undefined && onChange()\n\n const cancelOnChange = value.on(\"change\", onChange)\n\n const onRemove = () => {\n cancelOnChange()\n render && !computed && this.cancel(render)\n this.values.delete(name)\n }\n\n this.values.set(name, {\n value,\n render: computed ? undefined : render,\n onRemove,\n })\n\n return onRemove\n }\n\n get(name: string): MotionValue | undefined {\n return this.values.get(name)?.value\n }\n\n /**\n * Detach every value from this state and return them, so another\n * renderer can take them over. The state stays cached by its effect,\n * so the bound transforms are reset too rather than leaking into\n * values bound later.\n */\n release() {\n const values = new Map<string, MotionValue>()\n this.values.forEach((entry, name) => {\n values.set(name, entry.value)\n entry.onRemove()\n })\n this.transformKeys = this.transformValues = undefined\n return values\n }\n\n private schedule(render: VoidFunction) {\n const { pending, numPending } = this\n\n for (let i = 0; i < numPending; i++) {\n if (pending[i] === render) return\n }\n\n numPending || this.step(this.flush)\n\n pending[this.numPending++] = render\n }\n\n private cancel(render: VoidFunction) {\n const { pending } = this\n\n for (let i = 0; i < this.numPending; i++) {\n if (pending[i] === render) {\n pending[i] = pending[--this.numPending]\n return\n }\n }\n }\n\n /**\n * Run the pending renders. Resetting the count first means a render\n * scheduled while flushing lands in the next frame, as with the\n * frameloop itself.\n */\n flush = () => {\n const { pending, numPending } = this\n this.numPending = 0\n for (let i = 0; i < numPending; i++) pending[i]()\n }\n}\n"],"names":[],"mappings":";;MAUa,gBAAgB,CAAA;AAsBzB;;;;AAIG;IACH,WAAA,CAAoB,IAAA,GAAiB,KAAK,CAAC,MAAM,EAAA;QAA7B,IAAA,CAAA,IAAI,GAAJ,IAAI;AAlBhB,QAAA,IAAA,CAAA,MAAM,GAAG,IAAI,GAAG,EAAiB;AAEzC;;;;;;;AAOG;QACK,IAAA,CAAA,OAAO,GAAmB,EAAE;QAC5B,IAAA,CAAA,UAAU,GAAG,CAAC;AAkGtB;;;;AAIG;QACH,IAAA,CAAA,KAAK,GAAG,MAAK;AACT,YAAA,MA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AAYH;;;;"}
@@ -1,4 +1,6 @@
1
1
  import { camelToDash } from '../../render/dom/utils/camel-to-dash.mjs';
2
+ import { numberValueTypes } from '../../value/types/maps/number.mjs';
3
+ import { getValueAsType } from '../../value/types/utils/get-as-type.mjs';
2
4
  import { createSelectorEffect } from '../utils/create-dom-effect.mjs';
3
5
  import { createEffect } from '../utils/create-effect.mjs';
4
6
 
@@ -10,22 +12,26 @@ function canSetAsProperty(element, name) {
10
12
  // Check if it has a setter
11
13
  return descriptor && typeof descriptor.set === "function";
12
14
  }
13
- const addAttrValue = (element, state, key, value) => {
14
- const isProp = canSetAsProperty(element, key);
15
- const name = isProp
16
- ? key
17
- : key.startsWith("data") || key.startsWith("aria")
18
- ? camelToDash(key)
19
- : key;
15
+ /**
16
+ * `name` is the attribute written when it differs from the key the value
17
+ * is stored under, e.g. `attrX` -> `x`. Numbers take the attribute's
18
+ * default unit (`x: 100` -> `"100px"`), as they do when key and name match.
19
+ */
20
+ const addAttrValue = (element, state, key, value, name = key) => {
21
+ const isProp = canSetAsProperty(element, name);
22
+ if (!isProp && (name.startsWith("data") || name.startsWith("aria"))) {
23
+ name = camelToDash(name);
24
+ }
25
+ const type = numberValueTypes[key] || numberValueTypes[name];
20
26
  /**
21
27
  * Set attribute directly via property if available
22
28
  */
23
29
  const render = isProp
24
30
  ? () => {
25
- element[name] = state.latest[key];
31
+ element[name] = getValueAsType(value.get(), numberValueTypes[key]);
26
32
  }
27
33
  : () => {
28
- const v = state.latest[key];
34
+ const v = getValueAsType(value.get(), type);
29
35
  if (v === null || v === undefined) {
30
36
  element.removeAttribute(name);
31
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/effects/attr/index.ts"],"sourcesContent":["import { camelToDash } from \"../../render/dom/utils/camel-to-dash\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\n\nfunction canSetAsProperty(element: HTMLElement | SVGElement, name: string) {\n if (!(name in element)) return false\n\n const descriptor =\n Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), name) ||\n Object.getOwnPropertyDescriptor(element, name)\n\n // Check if it has a setter\n return descriptor && typeof descriptor.set === \"function\"\n}\n\nexport const addAttrValue = (\n element: HTMLElement | SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) => {\n const isProp = canSetAsProperty(element, key)\n const name = isProp\n ? key\n : key.startsWith(\"data\") || key.startsWith(\"aria\")\n ? camelToDash(key)\n : key\n\n /**\n * Set attribute directly via property if available\n */\n const render = isProp\n ? () => {\n ;(element as any)[name] = state.latest[key]\n }\n : () => {\n const v = state.latest[key]\n if (v === null || v === undefined) {\n element.removeAttribute(name)\n } else {\n element.setAttribute(name, String(v))\n }\n }\n\n return state.set(key, value, render)\n}\n\nexport const attrEffect = /*@__PURE__*/ createSelectorEffect(\n /*@__PURE__*/ createEffect(addAttrValue)\n)\n"],"names":[],"mappings":";;;;AAMA,SAAS,gBAAgB,CAAC,OAAiC,EAAE,IAAY,EAAA;AACrE,IAAA,IAAI,EAAE,IAAI,IAAI,OAAO,CAAC;AAAE,QAAA,OAAO,KAAK;AAEpC,IAAA,MAAM,UAAU,GACZ,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;AACrE,QAAA,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC;;IAGlD,OAAO,UAAU,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,UAAU;AAC7D;AAEO,MAAM,YAAY,GAAG,CACxB,OAAiC,EACjC,KAAuB,EACvB,GAAW,EACX,KAAkB,KAClB;IACA,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC;IAC7C,MAAM,IAAI,GAAG;AACT,UAAE;AACF,UAAE,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM;AACjD,cAAE,WAAW,CAAC,GAAG;cACf,GAAG;AAET;;AAEG;IACH,MAAM,MAAM,GAAG;UACT,MAAK;YACC,OAAe,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;QAC/C;UACA,MAAK;YACD,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;YAC3B,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,EAAE;AAC/B,gBAAA,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC;YACjC;iBAAO;gBACH,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;YACzC;AACJ,QAAA,CAAC;IAEP,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC;AACxC;AAEO,MAAM,UAAU,iBAAiB,oBAAoB;AACxD,cAAc,YAAY,CAAC,YAAY,CAAC;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/effects/attr/index.ts"],"sourcesContent":["import { camelToDash } from \"../../render/dom/utils/camel-to-dash\"\nimport { MotionValue } from \"../../value\"\nimport { numberValueTypes } from \"../../value/types/maps/number\"\nimport { getValueAsType } from \"../../value/types/utils/get-as-type\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\n\nfunction canSetAsProperty(element: HTMLElement | SVGElement, name: string) {\n if (!(name in element)) return false\n\n const descriptor =\n Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), name) ||\n Object.getOwnPropertyDescriptor(element, name)\n\n // Check if it has a setter\n return descriptor && typeof descriptor.set === \"function\"\n}\n\n/**\n * `name` is the attribute written when it differs from the key the value\n * is stored under, e.g. `attrX` -> `x`. Numbers take the attribute's\n * default unit (`x: 100` -> `\"100px\"`), as they do when key and name match.\n */\nexport const addAttrValue = (\n element: HTMLElement | SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue,\n name: string = key\n) => {\n const isProp = canSetAsProperty(element, name)\n if (!isProp && (name.startsWith(\"data\") || name.startsWith(\"aria\"))) {\n name = camelToDash(name)\n }\n\n const type = numberValueTypes[key] || numberValueTypes[name]\n\n /**\n * Set attribute directly via property if available\n */\n const render = isProp\n ? () => {\n ;(element as any)[name] = getValueAsType(\n value.get(),\n numberValueTypes[key]\n )\n }\n : () => {\n const v = getValueAsType(value.get(), type)\n if (v === null || v === undefined) {\n element.removeAttribute(name)\n } else {\n element.setAttribute(name, String(v))\n }\n }\n\n return state.set(key, value, render)\n}\n\nexport const attrEffect = /*@__PURE__*/ createSelectorEffect(\n /*@__PURE__*/ createEffect(addAttrValue)\n)\n"],"names":[],"mappings":";;;;;;AAQA,SAAS,gBAAgB,CAAC,OAAiC,EAAE,IAAY,EAAA;AACrE,IAAA,IAAI,EAAE,IAAI,IAAI,OAAO,CAAC;AAAE,QAAA,OAAO,KAAK;AAEpC,IAAA,MAAM,UAAU,GACZ,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;AACrE,QAAA,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC;;IAGlD,OAAO,UAAU,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,UAAU;AAC7D;AAEA;;;;AAIG;AACI,MAAM,YAAY,GAAG,CACxB,OAAiC,EACjC,KAAuB,EACvB,GAAW,EACX,KAAkB,EAClB,IAAA,GAAe,GAAG,KAClB;IACA,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC;AAC9C,IAAA,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE;AACjE,QAAA,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IAC5B;IAEA,MAAM,IAAI,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC;AAE5D;;AAEG;IACH,MAAM,MAAM,GAAG;UACT,MAAK;AACC,YAAA,OAAe,CAAC,IAAI,CAAC,GAAG,cAAc,CACpC,KAAK,CAAC,GAAG,EAAE,EACX,gBAAgB,CAAC,GAAG,CAAC,CACxB;QACL;UACA,MAAK;YACD,MAAM,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC;YAC3C,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,EAAE;AAC/B,gBAAA,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC;YACjC;iBAAO;gBACH,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;YACzC;AACJ,QAAA,CAAC;IAEP,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC;AACxC;AAEO,MAAM,UAAU,iBAAiB,oBAAoB;AACxD,cAAc,YAAY,CAAC,YAAY,CAAC;;;;"}
@@ -1,9 +1,22 @@
1
+ import { isObject } from 'motion-utils';
1
2
  import { createEffect } from '../utils/create-effect.mjs';
2
3
 
4
+ /**
5
+ * Writes motion values to the properties of any object. This is
6
+ * animate()'s fallback for subjects no registered effect claims.
7
+ */
3
8
  const propEffect = /*@__PURE__*/ createEffect((subject, state, key, value) => {
4
9
  return state.set(key, value, () => {
5
- subject[key] = state.latest[key];
6
- }, undefined, false);
10
+ subject[key] = value.get();
11
+ });
12
+ }, {
13
+ test: (subject) => isObject(subject),
14
+ read: (subject, key) => {
15
+ const value = subject[key];
16
+ return typeof value === "string" || typeof value === "number"
17
+ ? value
18
+ : undefined;
19
+ },
7
20
  });
8
21
 
9
22
  export { propEffect };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/effects/prop/index.ts"],"sourcesContent":["import { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createEffect } from \"../utils/create-effect\"\n\nexport const propEffect = /*@__PURE__*/ createEffect(\n (\n subject: { [key: string]: any },\n state: MotionValueState,\n key: string,\n value: MotionValue\n ) => {\n return state.set(\n key,\n value,\n () => {\n subject[key] = state.latest[key]\n },\n undefined,\n false\n )\n }\n)\n"],"names":[],"mappings":";;AAIO,MAAM,UAAU,iBAAiB,YAAY,CAChD,CACI,OAA+B,EAC/B,KAAuB,EACvB,GAAW,EACX,KAAkB,KAClB;IACA,OAAO,KAAK,CAAC,GAAG,CACZ,GAAG,EACH,KAAK,EACL,MAAK;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;AACpC,IAAA,CAAC,EACD,SAAS,EACT,KAAK,CACR;AACL,CAAC;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/effects/prop/index.ts"],"sourcesContent":["import { isObject } from \"motion-utils\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createEffect } from \"../utils/create-effect\"\n\ninterface PropSubject {\n [key: string]: any\n}\n\n/**\n * Writes motion values to the properties of any object. This is\n * animate()'s fallback for subjects no registered effect claims.\n */\nexport const propEffect = /*@__PURE__*/ createEffect(\n (\n subject: PropSubject,\n state: MotionValueState,\n key: string,\n value: MotionValue\n ) => {\n return state.set(\n key,\n value,\n () => {\n subject[key] = value.get()\n }\n )\n },\n {\n test: (subject: unknown): subject is PropSubject => isObject(subject),\n read: (subject, key) => {\n const value = subject[key]\n return typeof value === \"string\" || typeof value === \"number\"\n ? value\n : undefined\n },\n }\n)\n"],"names":[],"mappings":";;;AASA;;;AAGG;AACI,MAAM,UAAU,iBAAiB,YAAY,CAChD,CACI,OAAoB,EACpB,KAAuB,EACvB,GAAW,EACX,KAAkB,KAClB;IACA,OAAO,KAAK,CAAC,GAAG,CACZ,GAAG,EACH,KAAK,EACL,MAAK;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE;AAC9B,IAAA,CAAC,CACJ;AACL,CAAC,EACD;IACI,IAAI,EAAE,CAAC,OAAgB,KAA6B,QAAQ,CAAC,OAAO,CAAC;AACrE,IAAA,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,KAAI;AACnB,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC;QAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK;AACjD,cAAE;cACA,SAAS;IACnB,CAAC;AACJ,CAAA;;;;"}
@@ -1,16 +1,33 @@
1
1
  import { isCSSVar } from '../../render/dom/is-css-var.mjs';
2
- import { transformProps } from '../../render/utils/keys-transform.mjs';
2
+ import { readTransformValue } from '../../render/dom/parse-transform.mjs';
3
+ import { transformProps, transformPropOrder } from '../../render/utils/keys-transform.mjs';
3
4
  import { isHTMLElement } from '../../utils/is-html-element.mjs';
5
+ import { isSVGElement } from '../../utils/is-svg-element.mjs';
4
6
  import { MotionValue } from '../../value/index.mjs';
7
+ import { numberValueTypes } from '../../value/types/maps/number.mjs';
8
+ import { getValueAsType } from '../../value/types/utils/get-as-type.mjs';
5
9
  import { createSelectorEffect } from '../utils/create-dom-effect.mjs';
6
10
  import { createEffect } from '../utils/create-effect.mjs';
7
11
  import { buildTransform } from './transform.mjs';
8
12
 
9
13
  const originProps = new Set(["originX", "originY", "originZ"]);
14
+ /**
15
+ * A bound value in its default unit, e.g. `originX: 50` -> `"50%"`.
16
+ */
17
+ const styleValue = (state, key) => getValueAsType(state.get(key)?.get(), numberValueTypes[key]);
10
18
  const addStyleValue = (element, state, key, value) => {
11
19
  let render = undefined;
12
20
  let computed = undefined;
13
21
  if (transformProps.has(key)) {
22
+ if (key !== "pathRotation") {
23
+ const keys = (state.transformKeys ?? (state.transformKeys = []));
24
+ (state.transformValues ?? (state.transformValues = {}))[key] = value;
25
+ if (!keys.includes(key)) {
26
+ keys.push(key);
27
+ keys.sort((a, b) => transformPropOrder.indexOf(a) -
28
+ transformPropOrder.indexOf(b));
29
+ }
30
+ }
14
31
  if (!state.get("transform")) {
15
32
  // If this is an HTML element, we need to set the transform-box to fill-box
16
33
  // to normalise the transform relative to the element's bounding box
@@ -26,9 +43,9 @@ const addStyleValue = (element, state, key, value) => {
26
43
  else if (originProps.has(key)) {
27
44
  if (!state.get("transformOrigin")) {
28
45
  state.set("transformOrigin", new MotionValue(""), () => {
29
- const originX = state.latest.originX ?? "50%";
30
- const originY = state.latest.originY ?? "50%";
31
- const originZ = state.latest.originZ ?? 0;
46
+ const originX = styleValue(state, "originX") ?? "50%";
47
+ const originY = styleValue(state, "originY") ?? "50%";
48
+ const originZ = styleValue(state, "originZ") ?? 0;
32
49
  element.style.transformOrigin = `${originX} ${originY} ${originZ}`;
33
50
  });
34
51
  }
@@ -36,18 +53,44 @@ const addStyleValue = (element, state, key, value) => {
36
53
  }
37
54
  else if (isCSSVar(key)) {
38
55
  render = () => {
39
- element.style.setProperty(key, state.latest[key]);
56
+ element.style.setProperty(key, value.get());
40
57
  };
41
58
  }
42
59
  else {
43
60
  render = () => {
44
- element.style[key] = state.latest[key];
61
+ element.style[key] = getValueAsType(value.get(), numberValueTypes[key]);
45
62
  };
46
63
  }
47
64
  return state.set(key, value, render, computed);
48
65
  };
49
- const styleEffect = /*@__PURE__*/ createSelectorEffect(
50
- /*@__PURE__*/ createEffect(addStyleValue));
66
+ const isStyleSubject = (subject) => isHTMLElement(subject) || isSVGElement(subject);
67
+ /**
68
+ * Reads the current value of a style from the element, as the initial
69
+ * keyframe when `animate()` targets an element via this effect. Transforms
70
+ * are parsed out of the computed matrix; everything else is the computed
71
+ * style. Units aren't converted to match the target keyframes. A style
72
+ * the browser can't report is 0, as a VisualElement reports it.
73
+ */
74
+ const readStyleValue = (element, key) => {
75
+ if (transformProps.has(key)) {
76
+ return readTransformValue(element, key);
77
+ }
78
+ const computedStyle = getComputedStyle(element);
79
+ const value = isCSSVar(key)
80
+ ? computedStyle.getPropertyValue(key)
81
+ : computedStyle[key];
82
+ return (typeof value === "string" && value.trim()) || 0;
83
+ };
84
+ /**
85
+ * The per-element effect `animate()` binds through, so HTML values share
86
+ * state with a direct `styleEffect()` call. The exported `styleEffect`
87
+ * is this wrapped to also accept selectors.
88
+ */
89
+ const styleSubjectEffect = /*@__PURE__*/ createEffect(addStyleValue, {
90
+ test: isStyleSubject,
91
+ read: readStyleValue,
92
+ });
93
+ const styleEffect = /*@__PURE__*/ createSelectorEffect(styleSubjectEffect);
51
94
 
52
- export { addStyleValue, styleEffect };
95
+ export { addStyleValue, readStyleValue, styleEffect, styleSubjectEffect };
53
96
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/effects/style/index.ts"],"sourcesContent":["import { isCSSVar } from \"../../render/dom/is-css-var\"\nimport { transformProps } from \"../../render/utils/keys-transform\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { MotionValue } from \"../../value\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\nimport { buildTransform } from \"./transform\"\n\nconst originProps = new Set([\"originX\", \"originY\", \"originZ\"])\n\nexport const addStyleValue = (\n element: HTMLElement | SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) => {\n let render: VoidFunction | undefined = undefined\n let computed: MotionValue | undefined = undefined\n\n if (transformProps.has(key)) {\n if (!state.get(\"transform\")) {\n // If this is an HTML element, we need to set the transform-box to fill-box\n // to normalise the transform relative to the element's bounding box\n if (!isHTMLElement(element) && !state.get(\"transformBox\")) {\n addStyleValue(\n element,\n state,\n \"transformBox\",\n new MotionValue(\"fill-box\")\n )\n }\n\n state.set(\"transform\", new MotionValue(\"none\"), () => {\n element.style.transform = buildTransform(state)\n })\n }\n\n computed = state.get(\"transform\")\n } else if (originProps.has(key)) {\n if (!state.get(\"transformOrigin\")) {\n state.set(\"transformOrigin\", new MotionValue(\"\"), () => {\n const originX = state.latest.originX ?? \"50%\"\n const originY = state.latest.originY ?? \"50%\"\n const originZ = state.latest.originZ ?? 0\n element.style.transformOrigin = `${originX} ${originY} ${originZ}`\n })\n }\n\n computed = state.get(\"transformOrigin\")\n } else if (isCSSVar(key)) {\n render = () => {\n element.style.setProperty(key, state.latest[key] as string)\n }\n } else {\n render = () => {\n element.style[key as any] = state.latest[key] as string\n }\n }\n\n return state.set(key, value, render, computed)\n}\n\nexport const styleEffect = /*@__PURE__*/ createSelectorEffect(\n /*@__PURE__*/ createEffect(addStyleValue)\n)\n"],"names":[],"mappings":";;;;;;;;AASA,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAEvD,MAAM,aAAa,GAAG,CACzB,OAAiC,EACjC,KAAuB,EACvB,GAAW,EACX,KAAkB,KAClB;IACA,IAAI,MAAM,GAA6B,SAAS;IAChD,IAAI,QAAQ,GAA4B,SAAS;AAEjD,IAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACzB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;;;AAGzB,YAAA,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;AACvD,gBAAA,aAAa,CACT,OAAO,EACP,KAAK,EACL,cAAc,EACd,IAAI,WAAW,CAAC,UAAU,CAAC,CAC9B;YACL;AAEA,YAAA,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE,MAAK;gBACjD,OAAO,CAAC,KAAK,CAAC,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC;AACnD,YAAA,CAAC,CAAC;QACN;AAEA,QAAA,QAAQ,GAAG,KAAK,CA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../src/effects/style/index.ts"],"sourcesContent":["import { isCSSVar } from \"../../render/dom/is-css-var\"\nimport { readTransformValue } from \"../../render/dom/parse-transform\"\nimport {\n transformPropOrder,\n transformProps,\n} from \"../../render/utils/keys-transform\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { isSVGElement } from \"../../utils/is-svg-element\"\nimport { MotionValue } from \"../../value\"\nimport { numberValueTypes } from \"../../value/types/maps/number\"\nimport { getValueAsType } from \"../../value/types/utils/get-as-type\"\nimport { MotionValueState } from \"../MotionValueState\"\nimport { createSelectorEffect } from \"../utils/create-dom-effect\"\nimport { createEffect } from \"../utils/create-effect\"\nimport { buildTransform } from \"./transform\"\n\nconst originProps = new Set([\"originX\", \"originY\", \"originZ\"])\n\n/**\n * A bound value in its default unit, e.g. `originX: 50` -> `\"50%\"`.\n */\nconst styleValue = (state: MotionValueState, key: string) =>\n getValueAsType(state.get(key)?.get(), numberValueTypes[key])\n\nexport const addStyleValue = (\n element: HTMLElement | SVGElement,\n state: MotionValueState,\n key: string,\n value: MotionValue\n) => {\n let render: VoidFunction | undefined = undefined\n let computed: MotionValue | undefined = undefined\n\n if (transformProps.has(key)) {\n if (key !== \"pathRotation\") {\n const keys = (state.transformKeys ??= [])\n ;(state.transformValues ??= {})[key] = value\n\n if (!keys.includes(key)) {\n keys.push(key)\n keys.sort(\n (a, b) =>\n transformPropOrder.indexOf(a) -\n transformPropOrder.indexOf(b)\n )\n }\n }\n\n if (!state.get(\"transform\")) {\n // If this is an HTML element, we need to set the transform-box to fill-box\n // to normalise the transform relative to the element's bounding box\n if (!isHTMLElement(element) && !state.get(\"transformBox\")) {\n addStyleValue(\n element,\n state,\n \"transformBox\",\n new MotionValue(\"fill-box\")\n )\n }\n\n state.set(\"transform\", new MotionValue(\"none\"), () => {\n element.style.transform = buildTransform(state)\n })\n }\n\n computed = state.get(\"transform\")\n } else if (originProps.has(key)) {\n if (!state.get(\"transformOrigin\")) {\n state.set(\"transformOrigin\", new MotionValue(\"\"), () => {\n const originX = styleValue(state, \"originX\") ?? \"50%\"\n const originY = styleValue(state, \"originY\") ?? \"50%\"\n const originZ = styleValue(state, \"originZ\") ?? 0\n element.style.transformOrigin = `${originX} ${originY} ${originZ}`\n })\n }\n\n computed = state.get(\"transformOrigin\")\n } else if (isCSSVar(key)) {\n render = () => {\n element.style.setProperty(key, value.get() as string)\n }\n } else {\n render = () => {\n element.style[key as any] = getValueAsType(\n value.get(),\n numberValueTypes[key]\n ) as string\n }\n }\n\n return state.set(key, value, render, computed)\n}\n\nexport type StyleSubject = HTMLElement | SVGElement\n\nconst isStyleSubject = (subject: unknown): subject is StyleSubject =>\n isHTMLElement(subject) || isSVGElement(subject)\n\n/**\n * Reads the current value of a style from the element, as the initial\n * keyframe when `animate()` targets an element via this effect. Transforms\n * are parsed out of the computed matrix; everything else is the computed\n * style. Units aren't converted to match the target keyframes. A style\n * the browser can't report is 0, as a VisualElement reports it.\n */\nexport const readStyleValue = (element: StyleSubject, key: string) => {\n if (transformProps.has(key)) {\n return readTransformValue(element as HTMLElement, key)\n }\n\n const computedStyle = getComputedStyle(element)\n const value = isCSSVar(key)\n ? computedStyle.getPropertyValue(key)\n : computedStyle[key as any]\n\n return (typeof value === \"string\" && value.trim()) || 0\n}\n\n/**\n * The per-element effect `animate()` binds through, so HTML values share\n * state with a direct `styleEffect()` call. The exported `styleEffect`\n * is this wrapped to also accept selectors.\n */\nexport const styleSubjectEffect = /*@__PURE__*/ createEffect(addStyleValue, {\n test: isStyleSubject,\n read: readStyleValue,\n})\n\nexport const styleEffect = /*@__PURE__*/ createSelectorEffect(styleSubjectEffect)\n"],"names":[],"mappings":";;;;;;;;;;;;AAgBA,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAE9D;;AAEG;AACH,MAAM,UAAU,GAAG,CAAC,KAAuB,EAAE,GAAW,KACpD,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG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AgB,KACpC,aAAa,CAAC,OAAO,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC;AAEnD;;;;;;AAMG;MACU,cAAc,GAAG,CAAC,OAAqB,EAAE,GAAW,KAAI;AACjE,IAAA,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;AACzB,QAAA,OAAO,kBAAkB,CAAC,OAAsB,EAAE,GAAG,CAAC;IAC1D;AAEA,IAAA,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC;AAC/C,IAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG;AACtB,UAAE,aAAa,CAAC,gBAAgB,CAAC,GAAG;AACpC,UAAE,aAAa,CAAC,GAAU,CAAC;AAE/B,IAAA,OAAO,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;AAC3D;AAEA;;;;AAIG;MACU,kBAAkB,iBAAiB,YAAY,CAAC,aAAa,EAAE;AACxE,IAAA,IAAI,EAAE,cAAc;AACpB,IAAA,IAAI,EAAE,cAAc;AACvB,CAAA;AAEM,MAAM,WAAW,iBAAiB,oBAAoB,CAAC,kBAAkB;;;;"}
@@ -1,4 +1,5 @@
1
- import { transformPropOrder } from '../../render/utils/keys-transform.mjs';
1
+ import { transformValueTypes } from '../../value/types/maps/transform.mjs';
2
+ import { getValueAsType } from '../../value/types/utils/get-as-type.mjs';
2
3
 
3
4
  const translateAlias = {
4
5
  x: "translateX",
@@ -6,42 +7,44 @@ const translateAlias = {
6
7
  z: "translateZ",
7
8
  transformPerspective: "perspective",
8
9
  };
10
+ /**
11
+ * Cache of `translateX(`-style openers so each render is a few string
12
+ * concatenations rather than a template per transform.
13
+ */
14
+ const openers = {};
9
15
  function buildTransform(state) {
10
16
  let transform = "";
11
- let transformIsDefault = true;
17
+ const { transformKeys: keys = [], transformValues: values = {} } = state;
12
18
  /**
13
- * Loop over all possible transforms in order, adding the ones that
14
- * are present to the transform string.
19
+ * Loop over the bound transforms in order, adding the ones that
20
+ * aren't at their default value to the transform string.
15
21
  */
16
- for (let i = 0; i < transformPropOrder.length; i++) {
17
- const key = transformPropOrder[i];
18
- const value = state.latest[key];
22
+ for (let i = 0; i < keys.length; i++) {
23
+ const key = keys[i];
24
+ const value = values[key].get();
19
25
  if (value === undefined)
20
26
  continue;
21
- let valueIsDefault = true;
22
- if (typeof value === "number") {
23
- valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
24
- }
25
- else {
26
- const parsed = parseFloat(value);
27
- valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
28
- }
29
- if (!valueIsDefault) {
30
- transformIsDefault = false;
31
- const transformName = translateAlias[key] || key;
32
- transform += `${transformName}(${value}) `;
27
+ const parsed = typeof value === "number" ? value : parseFloat(value);
28
+ if (parsed !== (key.startsWith("scale") ? 1 : 0)) {
29
+ transform +=
30
+ (transform && " ") +
31
+ (openers[key] ||
32
+ (openers[key] = (translateAlias[key] || key) + "(")) +
33
+ getValueAsType(value, transformValueTypes[key]) +
34
+ ")";
33
35
  }
34
36
  }
35
37
  // See build-transform.ts: additive `rotate()` so user `rotate` isn't
36
38
  // clobbered. Not a `transformPropOrder` slot.
37
- const pathRotation = state.latest.pathRotation;
39
+ const pathRotation = state.get("pathRotation")?.get();
38
40
  if (pathRotation) {
39
- transformIsDefault = false;
40
- transform += `rotate(${typeof pathRotation === "number"
41
- ? `${pathRotation}deg`
42
- : pathRotation}) `;
41
+ transform +=
42
+ (transform && " ") +
43
+ "rotate(" +
44
+ getValueAsType(pathRotation, transformValueTypes.pathRotation) +
45
+ ")";
43
46
  }
44
- return transformIsDefault ? "none" : transform.trim();
47
+ return transform || "none";
45
48
  }
46
49
 
47
50
  export { buildTransform };
@@ -1 +1 @@
1
- {"version":3,"file":"transform.mjs","sources":["../../../../src/effects/style/transform.ts"],"sourcesContent":["import { transformPropOrder } from \"../../render/utils/keys-transform\"\nimport { MotionValueState } from \"../MotionValueState\"\n\nconst translateAlias = {\n x: \"translateX\",\n y: \"translateY\",\n z: \"translateZ\",\n transformPerspective: \"perspective\",\n}\n\nexport function buildTransform(state: MotionValueState) {\n let transform = \"\"\n let transformIsDefault = true\n\n /**\n * Loop over all possible transforms in order, adding the ones that\n * are present to the transform string.\n */\n for (let i = 0; i < transformPropOrder.length; i++) {\n const key = transformPropOrder[i] as keyof typeof translateAlias\n const value = state.latest[key]\n\n if (value === undefined) continue\n\n let valueIsDefault = true\n if (typeof value === \"number\") {\n valueIsDefault = value === (key.startsWith(\"scale\") ? 1 : 0)\n } else {\n const parsed = parseFloat(value)\n valueIsDefault = key.startsWith(\"scale\") ? parsed === 1 : parsed === 0\n }\n\n if (!valueIsDefault) {\n transformIsDefault = false\n const transformName = translateAlias[key] || key\n transform += `${transformName}(${value}) `\n }\n }\n\n // See build-transform.ts: additive `rotate()` so user `rotate` isn't\n // clobbered. Not a `transformPropOrder` slot.\n const pathRotation = state.latest.pathRotation\n if (pathRotation) {\n transformIsDefault = false\n transform += `rotate(${\n typeof pathRotation === \"number\"\n ? `${pathRotation}deg`\n : pathRotation\n }) `\n }\n\n return transformIsDefault ? \"none\" : transform.trim()\n}\n"],"names":[],"mappings":";;AAGA,MAAM,cAAc,GAAG;AACnB,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,oBAAoB,EAAE,aAAa;CACtC;AAEK,SAAU,cAAc,CAAC,KAAuB,EAAA;IAClD,IAAI,SAAS,GAAG,EAAE;IAClB,IAAI,kBAAkB,GAAG,IAAI;AAE7B;;;AAGG;AACH,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAChD,QAAA,MAAM,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAgC;QAChE,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;QAE/B,IAAI,KAAK,KAAK,SAAS;YAAE;QAEzB,IAAI,cAAc,GAAG,IAAI;AACzB,QAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC3B,YAAA,cAAc,GAAG,KAAK,MAAM,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChE;aAAO;AACH,YAAA,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;AAChC,YAAA,cAAc,GAAG,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,GAAG,MAAM,KAAK,CAAC;QAC1E;QAEA,IAAI,CAAC,cAAc,EAAE;YACjB,kBAAkB,GAAG,KAAK;YAC1B,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,GAAG;AAChD,YAAA,SAAS,IAAI,CAAA,EAAG,aAAa,CAAA,CAAA,EAAI,KAAK,IAAI;QAC9C;IACJ;;;AAIA,IAAA,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY;IAC9C,IAAI,YAAY,EAAE;QACd,kBAAkB,GAAG,KAAK;AAC1B,QAAA,SAAS,IAAI,CAAA,OAAA,EACT,OAAO,YAAY,KAAK;cAClB,CAAA,EAAG,YAAY,CAAA,GAAA;cACf,YACV,CAAA,EAAA,CAAI;IACR;AAEA,IAAA,OAAO,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE;AACzD;;;;"}
1
+ {"version":3,"file":"transform.mjs","sources":["../../../../src/effects/style/transform.ts"],"sourcesContent":["import { transformValueTypes } from \"../../value/types/maps/transform\"\nimport { getValueAsType } from \"../../value/types/utils/get-as-type\"\nimport { MotionValueState } from \"../MotionValueState\"\n\nconst translateAlias: Record<string, string> = {\n x: \"translateX\",\n y: \"translateY\",\n z: \"translateZ\",\n transformPerspective: \"perspective\",\n}\n\n/**\n * Cache of `translateX(`-style openers so each render is a few string\n * concatenations rather than a template per transform.\n */\nconst openers: Record<string, string> = {}\n\nexport function buildTransform(state: MotionValueState) {\n let transform = \"\"\n const { transformKeys: keys = [], transformValues: values = {} } = state\n\n /**\n * Loop over the bound transforms in order, adding the ones that\n * aren't at their default value to the transform string.\n */\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]\n const value = values[key].get()\n\n if (value === undefined) continue\n\n const parsed = typeof value === \"number\" ? value : parseFloat(value)\n\n if (parsed !== (key.startsWith(\"scale\") ? 1 : 0)) {\n transform +=\n (transform && \" \") +\n (openers[key] ||\n (openers[key] = (translateAlias[key] || key) + \"(\")) +\n getValueAsType(value, transformValueTypes[key]) +\n \")\"\n }\n }\n\n // See build-transform.ts: additive `rotate()` so user `rotate` isn't\n // clobbered. Not a `transformPropOrder` slot.\n const pathRotation = state.get(\"pathRotation\")?.get()\n if (pathRotation) {\n transform +=\n (transform && \" \") +\n \"rotate(\" +\n getValueAsType(pathRotation, transformValueTypes.pathRotation) +\n \")\"\n }\n\n return transform || \"none\"\n}\n"],"names":[],"mappings":";;;AAIA,MAAM,cAAc,GAA2B;AAC3C,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,oBAAoB,EAAE,aAAa;CACtC;AAED;;;AAGG;AACH,MAAM,OAAO,GAA2B,EAAE;AAEpC,SAAU,cAAc,CAAC,KAAuB,EAAA;IAClD,IAAI,SAAS,GAAG,EAAE;AAClB,IAAA,MAAM,EAAE,aAAa,EAAE,IAAI,GAAG,EAAE,EAAE,eAAe,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,KAAK;AAExE;;;AAGG;AACH,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAClC,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC;QACnB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE;QAE/B,IAAI,KAAK,KAAK,SAAS;YAAE;AAEzB,QAAA,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;AAEpE,QAAA,IAAI,MAAM,MAAM,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;YAC9C,SAAS;gBACL,CAAC,SAAS,IAAI,GAAG;qBAChB,OAAO,CAAC,GAAG,CAAC;AACT,yBAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC;AACxD,oBAAA,cAAc,CAAC,KAAK,EAAE,mBAAmB,CAAC,GAAG,CAAC,CAAC;AAC/C,oBAAA,GAAG;QACX;IACJ;;;IAIA,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,GAAG,EAAE;IACrD,IAAI,YAAY,EAAE;QACd,SAAS;YACL,CAAC,SAAS,IAAI,GAAG;gBACjB,SAAS;AACT,gBAAA,cAAc,CAAC,YAAY,EAAE,mBAAmB,CAAC,YAAY,CAAC;AAC9D,gBAAA,GAAG;IACX;IAEA,OAAO,SAAS,IAAI,MAAM;AAC9B;;;;"}
@@ -1,6 +1,11 @@
1
+ import { camelToDash } from '../../render/dom/utils/camel-to-dash.mjs';
2
+ import { cssStyleProperties } from '../../render/svg/utils/build-attrs.mjs';
3
+ import { transformProps } from '../../render/utils/keys-transform.mjs';
4
+ import { isSVGElement } from '../../utils/is-svg-element.mjs';
1
5
  import { MotionValue } from '../../value/index.mjs';
6
+ import { numberValueTypes } from '../../value/types/maps/number.mjs';
2
7
  import { addAttrValue } from '../attr/index.mjs';
3
- import { addStyleValue } from '../style/index.mjs';
8
+ import { addStyleValue, readStyleValue } from '../style/index.mjs';
4
9
  import { createSelectorEffect } from '../utils/create-dom-effect.mjs';
5
10
  import { createEffect } from '../utils/create-effect.mjs';
6
11
  import { frame } from '../../frameloop/frame.mjs';
@@ -10,14 +15,15 @@ function addSVGPathValue(element, state, key, value) {
10
15
  if (key === "pathOffset") {
11
16
  return state.set(key, value, () => {
12
17
  // Use unitless value to avoid Safari zoom bug
13
- const offset = state.latest[key];
18
+ const offset = value.get();
14
19
  element.setAttribute("stroke-dashoffset", `${-offset}`);
15
20
  });
16
21
  }
17
22
  else {
18
23
  if (!state.get("stroke-dasharray")) {
19
24
  state.set("stroke-dasharray", new MotionValue("1 1"), () => {
20
- const { pathLength = 1, pathSpacing } = state.latest;
25
+ const pathLength = state.get("pathLength")?.get() ?? 1;
26
+ const pathSpacing = state.get("pathSpacing")?.get();
21
27
  // Use unitless values to avoid Safari zoom bug
22
28
  element.setAttribute("stroke-dasharray", `${pathLength} ${pathSpacing ?? 1 - Number(pathLength)}`);
23
29
  });
@@ -30,16 +36,43 @@ const addSVGValue = (element, state, key, value) => {
30
36
  return addSVGPathValue(element, state, key, value);
31
37
  }
32
38
  else if (key.startsWith("attr")) {
33
- return addAttrValue(element, state, convertAttrKey(key), value);
39
+ return addAttrValue(element, state, key, value, convertAttrKey(key));
34
40
  }
35
41
  const handler = key in element.style ? addStyleValue : addAttrValue;
36
42
  return handler(element, state, key, value);
37
43
  };
38
- const svgEffect = /*@__PURE__*/ createSelectorEffect(
39
- /*@__PURE__*/ createEffect(addSVGValue));
44
+ /**
45
+ * Reads the current value of `key` from an SVG element as the origin of
46
+ * an animation, as the SVG VisualElement does: transforms start from
47
+ * their defaults, the few CSS-only properties come from computed style
48
+ * and everything else is read from the attribute, dash-cased
49
+ * (`strokeWidth` -> `stroke-width`) or, failing that, as written
50
+ * (`baseFrequency`).
51
+ */
52
+ const readSVGValue = (element, key) => {
53
+ if (transformProps.has(key)) {
54
+ return numberValueTypes[key]?.default || 0;
55
+ }
56
+ if (cssStyleProperties.includes(key)) {
57
+ return readStyleValue(element, key);
58
+ }
59
+ key = convertAttrKey(key);
60
+ return (element.getAttribute(camelToDash(key)) ??
61
+ element.getAttribute(key) ??
62
+ undefined);
63
+ };
64
+ /**
65
+ * The per-element effect `animate()` binds through, so SVG values share
66
+ * state with a direct `svgEffect()` call.
67
+ */
68
+ const svgSubjectEffect = /*@__PURE__*/ createEffect(addSVGValue, {
69
+ test: isSVGElement,
70
+ read: readSVGValue,
71
+ });
72
+ const svgEffect = /*@__PURE__*/ createSelectorEffect(svgSubjectEffect);
40
73
  function convertAttrKey(key) {
41
74
  return key.replace(/^attr([A-Z])/, (_, firstChar) => firstChar.toLowerCase());
42
75
  }
43
76
 
44
- export { svgEffect };
77
+ export { addSVGValue, readSVGValue, svgEffect, svgSubjectEffect };
45
78
  //# sourceMappingURL=index.mjs.map