motion-v 0.13.0 → 0.13.1-alpha.1

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.
@@ -1,5 +1,6 @@
1
1
  import { isNumber, isCssVar } from "./utils.mjs";
2
2
  import { isTransform, transformAlias, transformDefinitions, buildTransformTemplate } from "./transform.mjs";
3
+ import { px } from "../value/types/numbers/units.mjs";
3
4
  import { isMotionValue } from "../utils/motion-value.mjs";
4
5
  const style = {
5
6
  get: (element, name) => {
@@ -60,15 +61,12 @@ const SVG_STYLE_TO_ATTRIBUTES = {
60
61
  cy: true,
61
62
  r: true,
62
63
  d: true,
63
- x: true,
64
- y: true,
65
64
  x1: true,
66
65
  y1: true,
67
66
  x2: true,
68
67
  y2: true,
69
68
  points: true,
70
69
  pathLength: true,
71
- transform: true,
72
70
  viewBox: true,
73
71
  width: true,
74
72
  height: true,
@@ -92,19 +90,31 @@ const SVG_STYLE_TO_ATTRIBUTES = {
92
90
  letterSpacing: true,
93
91
  vectorEffect: true
94
92
  };
93
+ function buildSVGPath(attrs, length, spacing = 1, offset = 0) {
94
+ attrs.pathLength = 1;
95
+ attrs["stroke-dashoffset"] = px.transform(-offset);
96
+ const pathLength = px.transform(length);
97
+ const pathSpacing = px.transform(spacing);
98
+ attrs["stroke-dasharray"] = `${pathLength} ${pathSpacing}`;
99
+ }
95
100
  function convertSvgStyleToAttributes(keyframes) {
96
101
  const attributes = {};
97
102
  const styleProps = {};
103
+ let shouldBuildPath = false;
98
104
  for (const key in keyframes) {
99
105
  if (key in SVG_STYLE_TO_ATTRIBUTES) {
100
- const attrKey = SVG_STYLE_TO_ATTRIBUTES[key];
101
- const attrName = typeof attrKey === "string" ? attrKey : key;
106
+ if (key === "pathLength") {
107
+ shouldBuildPath = true;
108
+ }
102
109
  const value = keyframes[key];
103
- attributes[attrName] = isMotionValue(value) ? value.get() : value;
110
+ attributes[key] = isMotionValue(value) ? value.get() : value;
104
111
  } else {
105
112
  styleProps[key] = keyframes[key];
106
113
  }
107
114
  }
115
+ if (shouldBuildPath) {
116
+ buildSVGPath(attributes, attributes.pathLength, attributes.pathSpacing, attributes.pathOffset);
117
+ }
108
118
  return {
109
119
  attributes,
110
120
  style: styleProps
@@ -6,6 +6,8 @@ function createUnitType(unit) {
6
6
  };
7
7
  }
8
8
  const percent = /* @__PURE__ */ createUnitType("%");
9
+ const px = /* @__PURE__ */ createUnitType("px");
9
10
  export {
10
- percent
11
+ percent,
12
+ px
11
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion-v",
3
- "version": "0.13.0",
3
+ "version": "0.13.1-alpha.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "MIT",