motion-dom 14.2.0 → 14.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.
@@ -10,6 +10,7 @@ const matrix2dParsers = {
10
10
  translateY: 5,
11
11
  scaleX: 0,
12
12
  scaleY: 3,
13
+ scaleZ: () => 1,
13
14
  scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,
14
15
  rotate,
15
16
  rotateZ: rotate,
@@ -24,8 +25,8 @@ const rebaseAngle = (angle) => {
24
25
  return angle;
25
26
  };
26
27
  const rotateZ = rotate;
27
- const scaleX = (v) => Math.sqrt(v[0] * v[0] + v[1] * v[1]);
28
- const scaleY = (v) => Math.sqrt(v[4] * v[4] + v[5] * v[5]);
28
+ const scaleX = (v) => Math.hypot(v[0], v[1]);
29
+ const scaleY = (v) => Math.hypot(v[4], v[5]);
29
30
  const matrix3dParsers = {
30
31
  x: 12,
31
32
  y: 13,
@@ -35,6 +36,7 @@ const matrix3dParsers = {
35
36
  translateZ: 14,
36
37
  scaleX,
37
38
  scaleY,
39
+ scaleZ: (v) => Math.hypot(v[8], v[9], v[10]),
38
40
  scale: (v) => (scaleX(v) + scaleY(v)) / 2,
39
41
  rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),
40
42
  rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),
@@ -1 +1 @@
1
- {"version":3,"file":"parse-transform.mjs","sources":["../../../../src/render/dom/parse-transform.ts"],"sourcesContent":["import { transformPropOrder } from \"../utils/keys-transform\"\n\nconst radToDeg = (rad: number) => (rad * 180) / Math.PI\n\ntype MatrixParser = (values: number[]) => number\n\ntype MatrixParsers = Record<\n (typeof transformPropOrder)[number],\n number | MatrixParser\n>\n\nconst rotate = (v: number[]) => {\n const angle = radToDeg(Math.atan2(v[1], v[0]))\n return rebaseAngle(angle)\n}\n\nconst matrix2dParsers: MatrixParsers = {\n x: 4,\n y: 5,\n translateX: 4,\n translateY: 5,\n scaleX: 0,\n scaleY: 3,\n scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,\n rotate,\n rotateZ: rotate,\n skewX: (v) => radToDeg(Math.atan(v[1])),\n skewY: (v) => radToDeg(Math.atan(v[2])),\n skew: (v) => (Math.abs(v[1]) + Math.abs(v[2])) / 2,\n} as const\n\nconst rebaseAngle = (angle: number) => {\n angle = angle % 360\n if (angle < 0) angle += 360\n return angle\n}\n\nconst rotateZ = rotate\n\nconst scaleX = (v: number[]) => Math.sqrt(v[0] * v[0] + v[1] * v[1])\nconst scaleY = (v: number[]) => Math.sqrt(v[4] * v[4] + v[5] * v[5])\n\nconst matrix3dParsers: MatrixParsers = {\n x: 12,\n y: 13,\n z: 14,\n translateX: 12,\n translateY: 13,\n translateZ: 14,\n scaleX,\n scaleY,\n scale: (v) => (scaleX(v) + scaleY(v)) / 2,\n rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),\n rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),\n rotateZ,\n rotate: rotateZ,\n skewX: (v) => radToDeg(Math.atan(v[4])),\n skewY: (v) => radToDeg(Math.atan(v[1])),\n skew: (v) => (Math.abs(v[1]) + Math.abs(v[4])) / 2,\n} as const\n\nexport function defaultTransformValue(name: string): number {\n return name.includes(\"scale\") ? 1 : 0\n}\n\nexport function parseValueFromTransform(\n transform: string | undefined,\n name: string\n): number {\n if (!transform || transform === \"none\") {\n return defaultTransformValue(name)\n }\n\n const matrix3dMatch = transform.match(/^matrix3d\\(([-\\d.e\\s,]+)\\)$/u)\n\n let parsers: MatrixParsers\n let match: RegExpMatchArray | null\n\n if (matrix3dMatch) {\n parsers = matrix3dParsers\n match = matrix3dMatch\n } else {\n const matrix2dMatch = transform.match(/^matrix\\(([-\\d.e\\s,]+)\\)$/u)\n\n parsers = matrix2dParsers\n match = matrix2dMatch\n }\n\n if (!match) {\n return defaultTransformValue(name)\n }\n\n const valueParser = parsers[name]\n const values = match[1].split(\",\").map(convertTransformToNumber)\n\n return typeof valueParser === \"function\"\n ? valueParser(values)\n : values[valueParser]\n}\n\nexport const readTransformValue = (instance: HTMLElement, name: string) => {\n const { transform = \"none\" } = getComputedStyle(instance)\n return parseValueFromTransform(transform, name)\n}\n\nfunction convertTransformToNumber(value: string): number {\n return parseFloat(value.trim())\n}\n"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG,CAAC,GAAW,KAAK,CAAC,GAAG,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE;AASvD,MAAM,MAAM,GAAG,CAAC,CAAW,KAAI;AAC3B,IAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,IAAA,OAAO,WAAW,CAAC,KAAK,CAAC;AAC7B,CAAC;AAED,MAAM,eAAe,GAAkB;AACnC,IAAA,CAAC,EAAE,CAAC;AACJ,IAAA,CAAC,EAAE,CAAC;AACJ,IAAA,UAAU,EAAE,CAAC;AACb,IAAA,UAAU,EAAE,CAAC;AACb,IAAA,MAAM,EAAE,CAAC;AACT,IAAA,MAAM,EAAE,CAAC;AACT,IAAA,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnD,MAAM;AACN,IAAA,OAAO,EAAE,MAAM;AACf,IAAA,KAAK,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,IAAA,KAAK,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,IAAA,IAAI,E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IAAI,CAAC,KAAK,EAAE;AACR,QAAA,OAAO,qBAAqB,CAAC,IAAI,CAAC;IACtC;AAEA,IAAA,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;AACjC,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,wBAAwB,CAAC;IAEhE,OAAO,OAAO,WAAW,KAAK;AAC1B,UAAE,WAAW,CAAC,MAAM;AACpB,UAAE,MAAM,CAAC,WAAW,CAAC;AAC7B;MAEa,kBAAkB,GAAG,CAAC,QAAqB,EAAE,IAAY,KAAI;IACtE,MAAM,EAAE,SAAS,GAAG,MAAM,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC;AACzD,IAAA,OAAO,uBAAuB,CAAC,SAAS,EAAE,IAAI,CAAC;AACnD;AAEA,SAAS,wBAAwB,CAAC,KAAa,EAAA;AAC3C,IAAA,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;AACnC;;;;"}
1
+ {"version":3,"file":"parse-transform.mjs","sources":["../../../../src/render/dom/parse-transform.ts"],"sourcesContent":["import { transformPropOrder } from \"../utils/keys-transform\"\n\nconst radToDeg = (rad: number) => (rad * 180) / Math.PI\n\ntype MatrixParser = (values: number[]) => number\n\ntype MatrixParsers = Record<\n (typeof transformPropOrder)[number],\n number | MatrixParser\n>\n\nconst rotate = (v: number[]) => {\n const angle = radToDeg(Math.atan2(v[1], v[0]))\n return rebaseAngle(angle)\n}\n\nconst matrix2dParsers: MatrixParsers = {\n x: 4,\n y: 5,\n translateX: 4,\n translateY: 5,\n scaleX: 0,\n scaleY: 3,\n scaleZ: () => 1,\n scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,\n rotate,\n rotateZ: rotate,\n skewX: (v) => radToDeg(Math.atan(v[1])),\n skewY: (v) => radToDeg(Math.atan(v[2])),\n skew: (v) => (Math.abs(v[1]) + Math.abs(v[2])) / 2,\n} as const\n\nconst rebaseAngle = (angle: number) => {\n angle = angle % 360\n if (angle < 0) angle += 360\n return angle\n}\n\nconst rotateZ = rotate\n\nconst scaleX = (v: number[]) => Math.hypot(v[0], v[1])\nconst scaleY = (v: number[]) => Math.hypot(v[4], v[5])\n\nconst matrix3dParsers: MatrixParsers = {\n x: 12,\n y: 13,\n z: 14,\n translateX: 12,\n translateY: 13,\n translateZ: 14,\n scaleX,\n scaleY,\n scaleZ: (v) => Math.hypot(v[8], v[9], v[10]),\n scale: (v) => (scaleX(v) + scaleY(v)) / 2,\n rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),\n rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),\n rotateZ,\n rotate: rotateZ,\n skewX: (v) => radToDeg(Math.atan(v[4])),\n skewY: (v) => radToDeg(Math.atan(v[1])),\n skew: (v) => (Math.abs(v[1]) + Math.abs(v[4])) / 2,\n} as const\n\nexport function defaultTransformValue(name: string): number {\n return name.includes(\"scale\") ? 1 : 0\n}\n\nexport function parseValueFromTransform(\n transform: string | undefined,\n name: string\n): number {\n if (!transform || transform === \"none\") {\n return defaultTransformValue(name)\n }\n\n const matrix3dMatch = transform.match(/^matrix3d\\(([-\\d.e\\s,]+)\\)$/u)\n\n let parsers: MatrixParsers\n let match: RegExpMatchArray | null\n\n if (matrix3dMatch) {\n parsers = matrix3dParsers\n match = matrix3dMatch\n } else {\n const matrix2dMatch = transform.match(/^matrix\\(([-\\d.e\\s,]+)\\)$/u)\n\n parsers = matrix2dParsers\n match = matrix2dMatch\n }\n\n if (!match) {\n return defaultTransformValue(name)\n }\n\n const valueParser = parsers[name]\n const values = match[1].split(\",\").map(convertTransformToNumber)\n\n return typeof valueParser === \"function\"\n ? valueParser(values)\n : values[valueParser]\n}\n\nexport const readTransformValue = (instance: HTMLElement, name: string) => {\n const { transform = \"none\" } = getComputedStyle(instance)\n return parseValueFromTransform(transform, name)\n}\n\nfunction convertTransformToNumber(value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,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,wBAAwB,CAAC;IAEhE,OAAO,OAAO,WAAW,KAAK;AAC1B,UAAE,WAAW,CAAC,MAAM;AACpB,UAAE,MAAM,CAAC,WAAW,CAAC;AAC7B;MAEa,kBAAkB,GAAG,CAAC,QAAqB,EAAE,IAAY,KAAI;IACtE,MAAM,EAAE,SAAS,GAAG,MAAM,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC;AACzD,IAAA,OAAO,uBAAuB,CAAC,SAAS,EAAE,IAAI,CAAC;AACnD;AAEA,SAAS,wBAAwB,CAAC,KAAa,EAAA;AAC3C,IAAA,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;AACnC;;;;"}
@@ -5,8 +5,13 @@ import { scrapeMotionValuesFromProps as scrapeMotionValuesFromProps$1 } from '..
5
5
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
6
6
  const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
7
7
  for (const key in props) {
8
- if (isMotionValue(props[key]) ||
9
- isMotionValue(prevProps[key])) {
8
+ /**
9
+ * A MotionValue child is rendered as text content by
10
+ * DOMVisualElement, so it mustn't also be written as an attribute.
11
+ */
12
+ if (key !== "children" &&
13
+ (isMotionValue(props[key]) ||
14
+ isMotionValue(prevProps[key]))) {
10
15
  const targetKey = transformPropOrder.indexOf(key) !== -1
11
16
  ? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
12
17
  : key;
@@ -1 +1 @@
1
- {"version":3,"file":"scrape-motion-values.mjs","sources":["../../../../../src/render/svg/utils/scrape-motion-values.ts"],"sourcesContent":["import { isMotionValue } from \"../../../value/utils/is-motion-value\"\nimport type { MotionNodeOptions } from \"../../../node/types\"\nimport { transformPropOrder } from \"../../utils/keys-transform\"\nimport { scrapeMotionValuesFromProps as scrapeHTMLMotionValuesFromProps } from \"../../html/utils/scrape-motion-values\"\nimport type { VisualElement } from \"../../VisualElement\"\n\nexport function scrapeMotionValuesFromProps(\n props: MotionNodeOptions,\n prevProps: MotionNodeOptions,\n visualElement?: VisualElement\n) {\n const newValues = scrapeHTMLMotionValuesFromProps(\n props,\n prevProps,\n visualElement\n )\n\n for (const key in props) {\n if (\n isMotionValue(props[key as keyof typeof props]) ||\n isMotionValue(prevProps[key as keyof typeof prevProps])\n ) {\n const targetKey =\n transformPropOrder.indexOf(key) !== -1\n ? \"attr\" + key.charAt(0).toUpperCase() + key.substring(1)\n : key\n\n newValues[targetKey] = props[key as keyof typeof props]\n }\n }\n\n return newValues\n}\n"],"names":["scrapeHTMLMotionValuesFromProps"],"mappings":";;;;SAMgB,2BAA2B,CACvC,KAAwB,EACxB,SAA4B,EAC5B,aAA6B,EAAA;IAE7B,MAAM,SAAS,GAAGA,6BAA+B,CAC7C,KAAK,EACL,SAAS,EACT,aAAa,CAChB;AAED,IAAA,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;AACrB,QAAA,IACI,aAAa,CAAC,KAAK,CAAC,GAAyB,CAAC,CAAC;AAC/C,YAAA,aAAa,CAAC,SAAS,CAAC,GAA6B,CAAC,CAAC,EACzD;YACE,MAAM,SAAS,GACX,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK;AAChC,kBAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC;kBACtD,GAAG;YAEb,SAAS,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,GAAyB,CAAC;QAC3D;IACJ;AAEA,IAAA,OAAO,SAAS;AACpB;;;;"}
1
+ {"version":3,"file":"scrape-motion-values.mjs","sources":["../../../../../src/render/svg/utils/scrape-motion-values.ts"],"sourcesContent":["import { isMotionValue } from \"../../../value/utils/is-motion-value\"\nimport type { MotionNodeOptions } from \"../../../node/types\"\nimport { transformPropOrder } from \"../../utils/keys-transform\"\nimport { scrapeMotionValuesFromProps as scrapeHTMLMotionValuesFromProps } from \"../../html/utils/scrape-motion-values\"\nimport type { VisualElement } from \"../../VisualElement\"\n\nexport function scrapeMotionValuesFromProps(\n props: MotionNodeOptions,\n prevProps: MotionNodeOptions,\n visualElement?: VisualElement\n) {\n const newValues = scrapeHTMLMotionValuesFromProps(\n props,\n prevProps,\n visualElement\n )\n\n for (const key in props) {\n /**\n * A MotionValue child is rendered as text content by\n * DOMVisualElement, so it mustn't also be written as an attribute.\n */\n if (\n key !== \"children\" &&\n (isMotionValue(props[key as keyof typeof props]) ||\n isMotionValue(prevProps[key as keyof typeof prevProps]))\n ) {\n const targetKey =\n transformPropOrder.indexOf(key) !== -1\n ? \"attr\" + key.charAt(0).toUpperCase() + key.substring(1)\n : key\n\n newValues[targetKey] = props[key as keyof typeof props]\n }\n }\n\n return newValues\n}\n"],"names":["scrapeHTMLMotionValuesFromProps"],"mappings":";;;;SAMgB,2BAA2B,CACvC,KAAwB,EACxB,SAA4B,EAC5B,aAA6B,EAAA;IAE7B,MAAM,SAAS,GAAGA,6BAA+B,CAC7C,KAAK,EACL,SAAS,EACT,aAAa,CAChB;AAED,IAAA,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;AACrB;;;AAGG;QACH,IACI,GAAG,KAAK,UAAU;AAClB,aAAC,aAAa,CAAC,KAAK,CAAC,GAAyB,CAAC,CAAC;gBAC5C,aAAa,CAAC,SAAS,CAAC,GAA6B,CAAC,CAAC,CAAC,EAC9D;YACE,MAAM,SAAS,GACX,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK;AAChC,kBAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC;kBACtD,GAAG;YAEb,SAAS,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,GAAyB,CAAC;QAC3D;IACJ;AAEA,IAAA,OAAO,SAAS;AACpB;;;;"}
@@ -12,6 +12,7 @@ const transformPropOrder = [
12
12
  "scale",
13
13
  "scaleX",
14
14
  "scaleY",
15
+ "scaleZ",
15
16
  "rotate",
16
17
  "rotateX",
17
18
  "rotateY",
@@ -1 +1 @@
1
- {"version":3,"file":"keys-transform.mjs","sources":["../../../../src/render/utils/keys-transform.ts"],"sourcesContent":["/**\n * Generate a list of every possible transform key.\n */\nexport const transformPropOrder = [\n \"transformPerspective\",\n \"x\",\n \"y\",\n \"z\",\n \"translateX\",\n \"translateY\",\n \"translateZ\",\n \"scale\",\n \"scaleX\",\n \"scaleY\",\n \"rotate\",\n \"rotateX\",\n \"rotateY\",\n \"rotateZ\",\n \"skew\",\n \"skewX\",\n \"skewY\",\n]\n\n/**\n * A quick lookup for transform props.\n *\n * `pathRotation` is a transform for routing purposes (skipped from raw\n * style application, wired to the transform composite, flags transform\n * dirty) but is intentionally NOT in `transformPropOrder` — it is\n * composed onto `rotate` at the build sites, not serialized in its own\n * slot, and must stay out of the order-array consumers (parse-transform,\n * unit-conversion, keys-position).\n */\nexport const transformProps = /*@__PURE__*/ (() =>\n new Set([...transformPropOrder, \"pathRotation\"]))()\n"],"names":[],"mappings":"AAAA;;AAEG;AACI,MAAM,kBAAkB,GAAG;IAC9B,sBAAsB;IACtB,GAAG;IACH,GAAG;IACH,GAAG;IACH,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,SAAS;IACT,MAAM;IACN,OAAO;IACP,OAAO;;AAGX;;;;;;;;;AASG;MACU,cAAc,iBAAiB,CAAC,MACzC,IAAI,GAAG,CAAC,CAAC,GAAG,kBAAkB,EAAE,cAAc,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"keys-transform.mjs","sources":["../../../../src/render/utils/keys-transform.ts"],"sourcesContent":["/**\n * Generate a list of every possible transform key.\n */\nexport const transformPropOrder = [\n \"transformPerspective\",\n \"x\",\n \"y\",\n \"z\",\n \"translateX\",\n \"translateY\",\n \"translateZ\",\n \"scale\",\n \"scaleX\",\n \"scaleY\",\n \"scaleZ\",\n \"rotate\",\n \"rotateX\",\n \"rotateY\",\n \"rotateZ\",\n \"skew\",\n \"skewX\",\n \"skewY\",\n]\n\n/**\n * A quick lookup for transform props.\n *\n * `pathRotation` is a transform for routing purposes (skipped from raw\n * style application, wired to the transform composite, flags transform\n * dirty) but is intentionally NOT in `transformPropOrder` — it is\n * composed onto `rotate` at the build sites, not serialized in its own\n * slot, and must stay out of the order-array consumers (parse-transform,\n * unit-conversion, keys-position).\n */\nexport const transformProps = /*@__PURE__*/ (() =>\n new Set([...transformPropOrder, \"pathRotation\"]))()\n"],"names":[],"mappings":"AAAA;;AAEG;AACI,MAAM,kBAAkB,GAAG;IAC9B,sBAAsB;IACtB,GAAG;IACH,GAAG;IACH,GAAG;IACH,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,SAAS;IACT,MAAM;IACN,OAAO;IACP,OAAO;;AAGX;;;;;;;;;AASG;MACU,cAAc,iBAAiB,CAAC,MACzC,IAAI,GAAG,CAAC,CAAC,GAAG,kBAAkB,EAAE,cAAc,CAAC,CAAC;;;;"}
@@ -9,13 +9,46 @@ function getOriginIndex(from, total) {
9
9
  return from === "last" ? lastIndex : lastIndex / 2;
10
10
  }
11
11
  }
12
- function stagger(duration = 0.1, { startDelay = 0, from = 0, ease } = {}) {
12
+ function stagger(duration = 0.1, { startDelay = 0, from = 0, ease, grid } = {}) {
13
+ /**
14
+ * Distances from the origin for each element count. The final entry
15
+ * holds the distance used to normalise easing.
16
+ */
17
+ const cache = {};
13
18
  return (i, total) => {
14
- const fromIndex = typeof from === "number" ? from : getOriginIndex(from, total);
15
- const distance = Math.abs(fromIndex - i);
16
- let delay = duration * distance;
17
- if (ease) {
18
- const maxDelay = total * duration;
19
+ let distances = cache[total];
20
+ if (!distances) {
21
+ const [columns, rows] = grid || [Infinity, 1];
22
+ const lastX = Math.min(columns, total) - 1;
23
+ const lastY = Math.max(rows, Math.ceil(total / columns)) - 1;
24
+ const isIndex = typeof from === "number";
25
+ const scale = from === "first" ? 0 : from === "last" ? 1 : 0.5;
26
+ const originX = isIndex ? from % columns : lastX * scale;
27
+ const originY = isIndex ? Math.floor(from / columns) : lastY * scale;
28
+ distances = cache[total] = [];
29
+ for (let j = 0; j < total; j++) {
30
+ const x = j % columns;
31
+ const y = Math.floor(j / columns);
32
+ const edgeX = Math.min(x, lastX - x);
33
+ const edgeY = Math.min(y, lastY - y);
34
+ if (from === "random") {
35
+ // Inside-out shuffle, so each element gets a distinct step
36
+ const k = (Math.random() * (j + 1)) | 0;
37
+ distances[j] = distances[k];
38
+ distances[k] = j;
39
+ }
40
+ else {
41
+ distances[j] =
42
+ from === "edges"
43
+ ? Math.min(lastX ? edgeX : edgeY, lastY ? edgeY : edgeX)
44
+ : Math.hypot(x - originX, y - originY);
45
+ }
46
+ }
47
+ distances.push(grid ? Math.max(...distances) : total);
48
+ }
49
+ let delay = duration * distances[i];
50
+ const maxDelay = duration * distances[total];
51
+ if (ease && maxDelay) {
19
52
  const easingFunction = easingDefinitionToFunction(ease);
20
53
  delay = easingFunction(delay / maxDelay) * maxDelay;
21
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stagger.mjs","sources":["../../../src/utils/stagger.ts"],"sourcesContent":["import { Easing, easingDefinitionToFunction } from \"motion-utils\"\nimport { DynamicOption } from \"../animation/types\"\n\nexport type StaggerOrigin = \"first\" | \"last\" | \"center\" | number\n\nexport type StaggerOptions = {\n startDelay?: number\n from?: StaggerOrigin\n ease?: Easing\n}\n\nexport function getOriginIndex(from: StaggerOrigin, total: number) {\n if (from === \"first\") {\n return 0\n } else {\n const lastIndex = total - 1\n return from === \"last\" ? lastIndex : lastIndex / 2\n }\n}\n\nexport function stagger(\n duration: number = 0.1,\n { startDelay = 0, from = 0, ease }: StaggerOptions = {}\n): DynamicOption<number> {\n return (i: number, total: number) => {\n const fromIndex =\n typeof from === \"number\" ? from : getOriginIndex(from, total)\n const distance = Math.abs(fromIndex - i)\n let delay = duration * distance\n\n if (ease) {\n const maxDelay = total * duration\n const easingFunction = easingDefinitionToFunction(ease)\n delay = easingFunction(delay / maxDelay) * maxDelay\n }\n\n return startDelay + delay\n }\n}\n"],"names":[],"mappings":";;AAWM,SAAU,cAAc,CAAC,IAAmB,EAAE,KAAa,EAAA;AAC7D,IAAA,IAAI,IAAI,KAAK,OAAO,EAAE;AAClB,QAAA,OAAO,CAAC;IACZ;SAAO;AACH,QAAA,MAAM,SAAS,GAAG,KAAK,GAAG,CAAC;AAC3B,QAAA,OAAO,IAAI,KAAK,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,CAAC;IACtD;AACJ;SAEgB,OAAO,CACnB,QAAA,GAAmB,GAAG,EACtB,EAAE,UAAU,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,KAAqB,EAAE,EAAA;AAEvD,IAAA,OAAO,CAAC,CAAS,EAAE,KAAa,KAAI;AAChC,QAAA,MAAM,SAAS,GACX,OAAO,IAAI,KAAK,QAAQ,GAAG,IAAI,GAAG,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC;QACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC;AACxC,QAAA,IAAI,KAAK,GAAG,QAAQ,GAAG,QAAQ;QAE/B,IAAI,IAAI,EAAE;AACN,YAAA,MAAM,QAAQ,GAAG,KAAK,GAAG,QAAQ;AACjC,YAAA,MAAM,cAAc,GAAG,0BAA0B,CAAC,IAAI,CAAC;YACvD,KAAK,GAAG,cAAc,CAAC,KAAK,GAAG,QAAQ,CAAC,GAAG,QAAQ;QACvD;QAEA,OAAO,UAAU,GAAG,KAAK;AAC7B,IAAA,CAAC;AACL;;;;"}
1
+ {"version":3,"file":"stagger.mjs","sources":["../../../src/utils/stagger.ts"],"sourcesContent":["import { Easing, easingDefinitionToFunction } from \"motion-utils\"\nimport { DynamicOption } from \"../animation/types\"\n\nexport type StaggerOrigin =\n | \"first\"\n | \"last\"\n | \"center\"\n | \"edges\"\n | \"random\"\n | number\n\nexport type StaggerOptions = {\n startDelay?: number\n from?: StaggerOrigin\n ease?: Easing\n /**\n * Treat elements as a grid of `[columns, rows]`, in reading order.\n * Delays are then based on the 2D distance from `from`.\n */\n grid?: [number, number]\n}\n\nexport function getOriginIndex(from: StaggerOrigin, total: number) {\n if (from === \"first\") {\n return 0\n } else {\n const lastIndex = total - 1\n return from === \"last\" ? lastIndex : lastIndex / 2\n }\n}\n\nexport function stagger(\n duration: number = 0.1,\n { startDelay = 0, from = 0, ease, grid }: StaggerOptions = {}\n): DynamicOption<number> {\n /**\n * Distances from the origin for each element count. The final entry\n * holds the distance used to normalise easing.\n */\n const cache: { [total: number]: number[] } = {}\n\n return (i: number, total: number) => {\n let distances = cache[total]\n\n if (!distances) {\n const [columns, rows] = grid || [Infinity, 1]\n const lastX = Math.min(columns, total) - 1\n const lastY = Math.max(rows, Math.ceil(total / columns)) - 1\n const isIndex = typeof from === \"number\"\n const scale = from === \"first\" ? 0 : from === \"last\" ? 1 : 0.5\n const originX = isIndex ? from % columns : lastX * scale\n const originY = isIndex ? Math.floor(from / columns) : lastY * scale\n\n distances = cache[total] = []\n\n for (let j = 0; j < total; j++) {\n const x = j % columns\n const y = Math.floor(j / columns)\n const edgeX = Math.min(x, lastX - x)\n const edgeY = Math.min(y, lastY - y)\n\n if (from === \"random\") {\n // Inside-out shuffle, so each element gets a distinct step\n const k = (Math.random() * (j + 1)) | 0\n distances[j] = distances[k]\n distances[k] = j\n } else {\n distances[j] =\n from === \"edges\"\n ? Math.min(\n lastX ? edgeX : edgeY,\n lastY ? edgeY : edgeX\n )\n : Math.hypot(x - originX, y - originY)\n }\n }\n\n distances.push(grid ? Math.max(...distances) : total)\n }\n\n let delay = duration * distances[i]\n const maxDelay = duration * distances[total]\n\n if (ease && maxDelay) {\n const easingFunction = easingDefinitionToFunction(ease)\n delay = easingFunction(delay / maxDelay) * maxDelay\n }\n\n return startDelay + delay\n }\n}\n"],"names":[],"mappings":";;AAsBM,SAAU,cAAc,CAAC,IAAmB,EAAE,KAAa,EAAA;AAC7D,IAAA,IAAI,IAAI,KAAK,OAAO,EAAE;AAClB,QAAA,OAAO,CAAC;IACZ;SAAO;AACH,QAAA,MAAM,SAAS,GAAG,KAAK,GAAG,CAAC;AAC3B,QAAA,OAAO,IAAI,KAAK,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,CAAC;IACtD;AACJ;SAEgB,OAAO,CACnB,WAAmB,GAAG,EACtB,EAAE,UAAU,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,KAAqB,EAAE,EAAA;AAE7D;;;AAGG;IACH,MAAM,KAAK,GAAkC,EAAE;AAE/C,IAAA,OAAO,CAAC,CAAS,EAAE,KAAa,KAAI;AAChC,QAAA,IAAI,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;QAE5B,IAAI,CAAC,SAAS,EAAE;AACZ,YAAA,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC7C,YAAA,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC;AAC1C,YAAA,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC;AAC5D,YAAA,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,QAAQ;YACxC,MAAM,KAAK,GAAG,IAAI,KAAK,OAAO,GAAG,CAAC,GAAG,IAAI,KAAK,MAAM,GAAG,CAAC,GAAG,GAAG;AAC9D,YAAA,MAAM,OAAO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AG,SAAS,CAAC,GAAG,KAAK,CAAC;QACzD;QAEA,IAAI,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;QACnC,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC;AAE5C,QAAA,IAAI,IAAI,IAAI,QAAQ,EAAE;AAClB,YAAA,MAAM,cAAc,GAAG,0BAA0B,CAAC,IAAI,CAAC;YACvD,KAAK,GAAG,cAAc,CAAC,KAAK,GAAG,QAAQ,CAAC,GAAG,QAAQ;QACvD;QAEA,OAAO,UAAU,GAAG,KAAK;AAC7B,IAAA,CAAC;AACL;;;;"}
@@ -19,8 +19,9 @@ const COLOR_TOKEN = "color";
19
19
  const VAR_TOKEN = "var";
20
20
  const VAR_FUNCTION_TOKEN = "var(";
21
21
  const SPLIT_TOKEN = "${}";
22
- // this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`
23
- const complexRegex = /var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)/giu;
22
+ // this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`.
23
+ // The lookahead skips digits in function names, like the 3 in matrix3d(.
24
+ const complexRegex = /var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)(?![a-z]*\()/giu;
24
25
  /**
25
26
  * Whether analyseComplexValue(value) would find any values, without
26
27
  * tokenising the string. CSS variables are resolved before this is
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../../src/value/types/complex/index.ts"],"sourcesContent":["import { AnyResolvedKeyframe } from \"../../../animation/types\"\nimport { CSSVariableToken } from \"../../../animation/utils/is-css-variable\"\nimport { color } from \"../color\"\nimport { Color } from \"../types\"\nimport { colorRegex } from \"../utils/color-regex\"\nimport { floatRegex } from \"../utils/float-regex\"\nimport { sanitize } from \"../utils/sanitize\"\n\n/**\n * Non-global copies of the token regexes so test() can use .test()\n * (no match array, stops at the first token) without lastIndex state.\n */\nconst hasFloat = /*@__PURE__*/ new RegExp(floatRegex.source)\nconst hasColor = /*@__PURE__*/ new RegExp(colorRegex.source, \"i\")\n\nfunction test(v: any) {\n return (\n isNaN(v) &&\n typeof v === \"string\" &&\n (hasFloat.test(v) || hasColor.test(v))\n )\n}\n\nconst NUMBER_TOKEN = \"number\"\nconst COLOR_TOKEN = \"color\"\nconst VAR_TOKEN = \"var\"\nconst VAR_FUNCTION_TOKEN = \"var(\"\nconst SPLIT_TOKEN = \"${}\"\n\nexport type ComplexValues = Array<\n CSSVariableToken | AnyResolvedKeyframe | Color\n>\n\nexport interface ValueIndexes {\n color: number[]\n number: number[]\n var: number[]\n}\n\nexport interface ComplexValueInfo {\n values: ComplexValues\n split: string[]\n indexes: ValueIndexes\n types: Array<keyof ValueIndexes>\n}\n\n// this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`\nconst complexRegex =\n /var\\s*\\(\\s*--(?:[\\w-]+\\s*|[\\w-]+\\s*,(?:\\s*[^)(\\s]|\\s*\\((?:[^)(]|\\([^)(]*\\))*\\))+\\s*)\\)|#[\\da-f]{3,8}|(?:rgb|hsl)a?\\((?:-?[\\d.]+%?[,\\s]+){2}-?[\\d.]+%?\\s*(?:[,/]\\s*)?(?:\\b\\d+(?:\\.\\d+)?|\\.\\d+)?%?\\)|-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)/giu\n\n/**\n * Whether analyseComplexValue(value) would find any values, without\n * tokenising the string. CSS variables are resolved before this is\n * used, so it's enough to look for a number or a color.\n */\nexport function hasComplexValues(value: AnyResolvedKeyframe) {\n const asString = value.toString()\n return hasFloat.test(asString) || hasColor.test(asString)\n}\n\nexport function analyseComplexValue(\n value: AnyResolvedKeyframe\n): ComplexValueInfo {\n const originalValue = value.toString()\n\n const values: ComplexValues = []\n const indexes: ValueIndexes = {\n color: [],\n number: [],\n var: [],\n }\n const types: Array<keyof ValueIndexes> = []\n\n let i = 0\n const tokenised = originalValue.replace(complexRegex, (parsedValue) => {\n if (color.test(parsedValue)) {\n indexes.color.push(i)\n types.push(COLOR_TOKEN)\n values.push(color.parse(parsedValue))\n } else if (parsedValue.startsWith(VAR_FUNCTION_TOKEN)) {\n indexes.var.push(i)\n types.push(VAR_TOKEN)\n values.push(parsedValue)\n } else {\n indexes.number.push(i)\n types.push(NUMBER_TOKEN)\n values.push(parseFloat(parsedValue))\n }\n ++i\n return SPLIT_TOKEN\n })\n const split = tokenised.split(SPLIT_TOKEN)\n\n return { values, split, indexes, types }\n}\n\nfunction parseComplexValue(v: AnyResolvedKeyframe) {\n return analyseComplexValue(v).values\n}\n\nfunction buildTransformer({ split, types }: ComplexValueInfo) {\n const numSections = split.length\n return (v: Array<CSSVariableToken | Color | number | string>) => {\n let output = \"\"\n for (let i = 0; i < numSections; i++) {\n output += split[i]\n if (v[i] !== undefined) {\n const type = types[i]\n if (type === NUMBER_TOKEN) {\n output += sanitize(v[i] as number)\n } else if (type === COLOR_TOKEN) {\n output += color.transform(v[i] as Color)\n } else {\n output += v[i]\n }\n }\n }\n\n return output\n }\n}\n\nfunction createTransformer(source: AnyResolvedKeyframe) {\n return buildTransformer(analyseComplexValue(source))\n}\n\nconst convertNumbersToZero = (v: number | string) =>\n typeof v === \"number\" ? 0 : color.test(v) ? color.getAnimatableNone(v) : v\n\n/**\n * Convert a parsed value to its zero equivalent, but preserve numbers\n * that act as divisors in CSS calc() expressions.\n *\n * analyseComplexValue extracts numbers from CSS strings and puts the\n * surrounding text into a `split` template array. For example:\n * \"calc(var(--gap) / 5)\" → values: [var(--gap), 5]\n * split: [\"calc(\", \" / \", \")\"]\n *\n * When building a zero-equivalent for animation, naively zeroing all\n * numbers turns the divisor into 0 → \"calc(var(--gap) / 0)\" → NaN.\n * We detect this by checking whether the text preceding a number\n * (split[i]) ends with \"/\" — the CSS calc division operator.\n */\nconst convertToZero = (\n value: ComplexValues[number],\n splitBefore: string\n): ComplexValues[number] => {\n if (typeof value === \"number\") {\n return splitBefore?.trim().endsWith(\"/\") ? value : 0\n }\n return convertNumbersToZero(value as string)\n}\n\nfunction getAnimatableNone(v: AnyResolvedKeyframe) {\n const info = analyseComplexValue(v)\n const transformer = buildTransformer(info)\n return transformer(\n info.values.map((value, i) => convertToZero(value, info.split[i]))\n )\n}\n\nexport const complex = {\n test,\n parse: parseComplexValue,\n createTransformer,\n getAnimatableNone,\n}\n"],"names":[],"mappings":";;;;;AAQA;;;AAGG;AACH,MAAM,QAAQ,iBAAiB,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;AAC5D,MAAM,QAAQ,iBAAiB,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;AAEjE,SAAS,IAAI,CAAC,CAAM,EAAA;AAChB,IAAA,QACI,KAAK,CAAC,CAAC,CAAC;QACR,OAAO,CAAC,KAAK,QAAQ;AACrB,SAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAE9C;AAEA,MAAM,YAAY,GAAG,QAAQ;AAC7B,MAAM,WAAW,GAAG,OAAO;AAC3B,MAAM,SAAS,GAAG,KAAK;AACvB,MAAM,kBAAkB,GAAG,MAAM;AACjC,MAAM,WAAW,GAAG,KAAK;AAmBzB;AACA,MAAM,YAAY,GACd,iOAAiO;AAErO;;;;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A,MAAM,oBAAoB,GAAG,CAAC,CAAkB,KAC5C,OAAO,CAAC,KAAK,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC;AAE9E;;;;;;;;;;;;;AAaG;AACH,MAAM,aAAa,GAAG,CAClB,KAA4B,EAC5B,WAAmB,KACI;AACvB,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC3B,QAAA,OAAO,WAAW,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC;IACxD;AACA,IAAA,OAAO,oBAAoB,CAAC,KAAe,CAAC;AAChD,CAAC;AAED,SAAS,iBAAiB,CAAC,CAAsB,EAAA;AAC7C,IAAA,MAAM,IAAI,GAAG,mBAAmB,CAAC,CAAC,CAAC;AACnC,IAAA,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,CAAC;AAC1C,IAAA,OAAO,WAAW,CACd,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CACrE;AACL;AAEO,MAAM,OAAO,GAAG;IACnB,IAAI;AACJ,IAAA,KAAK,EAAE,iBAAiB;IACxB,iBAAiB;IACjB,iBAAiB;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../../src/value/types/complex/index.ts"],"sourcesContent":["import { AnyResolvedKeyframe } from \"../../../animation/types\"\nimport { CSSVariableToken } from \"../../../animation/utils/is-css-variable\"\nimport { color } from \"../color\"\nimport { Color } from \"../types\"\nimport { colorRegex } from \"../utils/color-regex\"\nimport { floatRegex } from \"../utils/float-regex\"\nimport { sanitize } from \"../utils/sanitize\"\n\n/**\n * Non-global copies of the token regexes so test() can use .test()\n * (no match array, stops at the first token) without lastIndex state.\n */\nconst hasFloat = /*@__PURE__*/ new RegExp(floatRegex.source)\nconst hasColor = /*@__PURE__*/ new RegExp(colorRegex.source, \"i\")\n\nfunction test(v: any) {\n return (\n isNaN(v) &&\n typeof v === \"string\" &&\n (hasFloat.test(v) || hasColor.test(v))\n )\n}\n\nconst NUMBER_TOKEN = \"number\"\nconst COLOR_TOKEN = \"color\"\nconst VAR_TOKEN = \"var\"\nconst VAR_FUNCTION_TOKEN = \"var(\"\nconst SPLIT_TOKEN = \"${}\"\n\nexport type ComplexValues = Array<\n CSSVariableToken | AnyResolvedKeyframe | Color\n>\n\nexport interface ValueIndexes {\n color: number[]\n number: number[]\n var: number[]\n}\n\nexport interface ComplexValueInfo {\n values: ComplexValues\n split: string[]\n indexes: ValueIndexes\n types: Array<keyof ValueIndexes>\n}\n\n// this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`.\n// The lookahead skips digits in function names, like the 3 in matrix3d(.\nconst complexRegex =\n /var\\s*\\(\\s*--(?:[\\w-]+\\s*|[\\w-]+\\s*,(?:\\s*[^)(\\s]|\\s*\\((?:[^)(]|\\([^)(]*\\))*\\))+\\s*)\\)|#[\\da-f]{3,8}|(?:rgb|hsl)a?\\((?:-?[\\d.]+%?[,\\s]+){2}-?[\\d.]+%?\\s*(?:[,/]\\s*)?(?:\\b\\d+(?:\\.\\d+)?|\\.\\d+)?%?\\)|-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?![a-z]*\\()/giu\n\n/**\n * Whether analyseComplexValue(value) would find any values, without\n * tokenising the string. CSS variables are resolved before this is\n * used, so it's enough to look for a number or a color.\n */\nexport function hasComplexValues(value: AnyResolvedKeyframe) {\n const asString = value.toString()\n return hasFloat.test(asString) || hasColor.test(asString)\n}\n\nexport function analyseComplexValue(\n value: AnyResolvedKeyframe\n): ComplexValueInfo {\n const originalValue = value.toString()\n\n const values: ComplexValues = []\n const indexes: ValueIndexes = {\n color: [],\n number: [],\n var: [],\n }\n const types: Array<keyof ValueIndexes> = []\n\n let i = 0\n const tokenised = originalValue.replace(complexRegex, (parsedValue) => {\n if (color.test(parsedValue)) {\n indexes.color.push(i)\n types.push(COLOR_TOKEN)\n values.push(color.parse(parsedValue))\n } else if (parsedValue.startsWith(VAR_FUNCTION_TOKEN)) {\n indexes.var.push(i)\n types.push(VAR_TOKEN)\n values.push(parsedValue)\n } else {\n indexes.number.push(i)\n types.push(NUMBER_TOKEN)\n values.push(parseFloat(parsedValue))\n }\n ++i\n return SPLIT_TOKEN\n })\n const split = tokenised.split(SPLIT_TOKEN)\n\n return { values, split, indexes, types }\n}\n\nfunction parseComplexValue(v: AnyResolvedKeyframe) {\n return analyseComplexValue(v).values\n}\n\nfunction buildTransformer({ split, types }: ComplexValueInfo) {\n const numSections = split.length\n return (v: Array<CSSVariableToken | Color | number | string>) => {\n let output = \"\"\n for (let i = 0; i < numSections; i++) {\n output += split[i]\n if (v[i] !== undefined) {\n const type = types[i]\n if (type === NUMBER_TOKEN) {\n output += sanitize(v[i] as number)\n } else if (type === COLOR_TOKEN) {\n output += color.transform(v[i] as Color)\n } else {\n output += v[i]\n }\n }\n }\n\n return output\n }\n}\n\nfunction createTransformer(source: AnyResolvedKeyframe) {\n return buildTransformer(analyseComplexValue(source))\n}\n\nconst convertNumbersToZero = (v: number | string) =>\n typeof v === \"number\" ? 0 : color.test(v) ? color.getAnimatableNone(v) : v\n\n/**\n * Convert a parsed value to its zero equivalent, but preserve numbers\n * that act as divisors in CSS calc() expressions.\n *\n * analyseComplexValue extracts numbers from CSS strings and puts the\n * surrounding text into a `split` template array. For example:\n * \"calc(var(--gap) / 5)\" → values: [var(--gap), 5]\n * split: [\"calc(\", \" / \", \")\"]\n *\n * When building a zero-equivalent for animation, naively zeroing all\n * numbers turns the divisor into 0 → \"calc(var(--gap) / 0)\" → NaN.\n * We detect this by checking whether the text preceding a number\n * (split[i]) ends with \"/\" — the CSS calc division operator.\n */\nconst convertToZero = (\n value: ComplexValues[number],\n splitBefore: string\n): ComplexValues[number] => {\n if (typeof value === \"number\") {\n return splitBefore?.trim().endsWith(\"/\") ? value : 0\n }\n return convertNumbersToZero(value as string)\n}\n\nfunction getAnimatableNone(v: AnyResolvedKeyframe) {\n const info = analyseComplexValue(v)\n const transformer = buildTransformer(info)\n return transformer(\n info.values.map((value, i) => convertToZero(value, info.split[i]))\n )\n}\n\nexport const complex = {\n test,\n parse: parseComplexValue,\n createTransformer,\n getAnimatableNone,\n}\n"],"names":[],"mappings":";;;;;AAQA;;;AAGG;AACH,MAAM,QAAQ,iBAAiB,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;AAC5D,MAAM,QAAQ,iBAAiB,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;AAEjE,SAAS,IAAI,CAAC,CAAM,EAAA;AAChB,IAAA,QACI,KAAK,CAAC,CAAC,CAAC;QACR,OAAO,CAAC,KAAK,QAAQ;AACrB,SAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAE9C;AAEA,MAAM,YAAY,GAAG,QAAQ;AAC7B,MAAM,WAAW,GAAG,OAAO;AAC3B,MAAM,SAAS,GAAG,KAAK;AACvB,MAAM,kBAAkB,GAAG,MAAM;AACjC,MAAM,WAAW,GAAG,KAAK;AAmBzB;AACA;AACA,MAAM,YAAY,GACd,6OAA6O;AAEjP;;;;AAIG;AACG,SAAU,gBAAgB,CAAC,KAA0B,EAAA;AACvD,IAAA,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE;AACjC,IAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;AAC7D;AAEM,SAAU,mBAAmB,CAC/B,KAA0B,EAAA;AAE1B,IAAA,MAAM,aAAa,GAAG,KAAK,CAAC,QAAQ,EAAE;IAEtC,MAAM,MAAM,GAAkB,EAAE;AAChC,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AI,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC;IACxD;AACA,IAAA,OAAO,oBAAoB,CAAC,KAAe,CAAC;AAChD,CAAC;AAED,SAAS,iBAAiB,CAAC,CAAsB,EAAA;AAC7C,IAAA,MAAM,IAAI,GAAG,mBAAmB,CAAC,CAAC,CAAC;AACnC,IAAA,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,CAAC;AAC1C,IAAA,OAAO,WAAW,CACd,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CACrE;AACL;AAEO,MAAM,OAAO,GAAG;IACnB,IAAI;AACJ,IAAA,KAAK,EAAE,iBAAiB;IACxB,iBAAiB;IACjB,iBAAiB;;;;;"}
@@ -69,7 +69,7 @@ function follow(value, source, options) {
69
69
  }, stopAnimation);
70
70
  if (isMotionValue(source)) {
71
71
  let skipNextAnimation = options.skipInitialAnimation === true;
72
- const removeSourceOnChange = source.on("change", (v) => {
72
+ const onSourceChange = (v) => {
73
73
  if (skipNextAnimation) {
74
74
  skipNextAnimation = false;
75
75
  value.jump(parseValue(v, unit), false);
@@ -77,11 +77,28 @@ function follow(value, source, options) {
77
77
  else {
78
78
  value.set(parseValue(v, unit));
79
79
  }
80
- });
80
+ };
81
+ const removeSourceOnChange = source.on("change", onSourceChange);
82
+ /**
83
+ * Catch up on a change made before we subscribed, for instance
84
+ * between a React render reading the source and the effect
85
+ * attaching to it. Subtracting is falsy for equal or non-numeric
86
+ * (NaN) values.
87
+ */
88
+ const latest = source.get();
89
+ if (asNumber(latest) - asNumber(value.get()))
90
+ onSourceChange(latest);
81
91
  const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
92
+ /**
93
+ * Stop our animation on detach, otherwise a re-attach (new
94
+ * options, Strict Mode) starts a second animation that fights
95
+ * this orphaned one. The catch-up above resumes from the
96
+ * current value and velocity.
97
+ */
82
98
  return () => {
83
99
  removeSourceOnChange();
84
100
  removeValueOnDestroy();
101
+ stopAnimation();
85
102
  };
86
103
  }
87
104
  return stopAnimation;
@@ -1 +1 @@
1
- {"version":3,"file":"follow.mjs","sources":["../../../../src/value/utils/follow.ts"],"sourcesContent":["import type { MotionValue } from \"..\"\nimport { FollowAnimation } from \"../../animation/FollowAnimation\"\nimport type {\n AnyResolvedKeyframe,\n GeneratorFactory,\n ValueAnimationOptions,\n} from \"../../animation/types\"\nimport type { FollowValueOptions } from \"../follow-value\"\nimport { asNumber } from \"./as-number\"\nimport { isMotionValue } from \"./is-motion-value\"\n\nexport type FollowOptions = FollowValueOptions & { type: GeneratorFactory }\n\n/**\n * Animate `value` to its latest value with the generator in\n * `options.type`, tracking `source` if it's a `MotionValue`. Takes a\n * generator rather than a type name, so spring-only callers don't\n * bundle every generator.\n */\nexport function follow<T extends AnyResolvedKeyframe>(\n value: MotionValue<T>,\n source: T | MotionValue<T>,\n options: FollowOptions\n): VoidFunction {\n const initialValue = value.get()\n\n let activeAnimation: FollowAnimation | null = null\n let set: (v: T) => void\n\n const unit =\n typeof initialValue === \"string\"\n ? initialValue.replace(/[\\d.-]/g, \"\")\n : undefined\n\n const onUpdate = (v: number) => set((unit ? v + unit : v) as T)\n\n const onPlay = () => value[\"events\"].animationStart?.notify()\n\n const stopAnimation = () => {\n if (activeAnimation) {\n activeAnimation.stop()\n activeAnimation = null\n }\n value.animation = undefined\n }\n\n value.attach((v, safeSet) => {\n set = safeSet\n const target = asNumber(v)\n\n if (activeAnimation?.state === \"running\") {\n /**\n * Steer the running animation rather than replacing it. This\n * keeps its completion promise and uses its analytical velocity\n * for accuracy, preventing systematic velocity loss at high\n * frame rates (240hz+).\n */\n activeAnimation.setTarget(target, options.velocity)\n return\n }\n\n const current = asNumber(value.get())\n const velocity = activeAnimation\n ? activeAnimation.getGeneratorVelocity()\n : value.getVelocity()\n\n stopAnimation()\n\n // Don't animate if we're already at the target\n if (current === target) return\n\n const animationOptions: ValueAnimationOptions<number> = {\n keyframes: [current, target],\n velocity,\n restDelta: 0.001,\n restSpeed: 0.01,\n ...options,\n onUpdate,\n }\n\n const animation = (activeAnimation = new FollowAnimation({\n ...animationOptions,\n onPlay,\n }))\n\n value.animation = animation\n\n animation.then(() => {\n // Ignore if this animation has since been replaced\n if (activeAnimation !== animation) return\n activeAnimation = null\n value.animation = undefined\n value[\"events\"].animationComplete?.notify()\n })\n }, stopAnimation)\n\n if (isMotionValue(source)) {\n let skipNextAnimation = options.skipInitialAnimation === true\n\n const removeSourceOnChange = source.on(\"change\", (v) => {\n if (skipNextAnimation) {\n skipNextAnimation = false\n value.jump(parseValue(v, unit) as T, false)\n } else {\n value.set(parseValue(v, unit) as T)\n }\n })\n\n const removeValueOnDestroy = value.on(\"destroy\", removeSourceOnChange)\n\n return () => {\n removeSourceOnChange()\n removeValueOnDestroy()\n }\n }\n\n return stopAnimation\n}\n\nfunction parseValue(v: AnyResolvedKeyframe, unit?: string) {\n return unit ? v + unit : v\n}\n"],"names":[],"mappings":";;;;AAaA;;;;;AAKG;SACa,MAAM,CAClB,KAAqB,EACrB,MAA0B,EAC1B,OAAsB,EAAA;AAEtB,IAAA,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,EAAE;IAEhC,IAAI,eAAe,GAA2B,IAAI;AAClD,IAAA,IAAI,GAAmB;AAEvB,IAAA,MAAM,IAAI,GACN,OAAO,YAAY,KAAK;UAClB,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE;UAClC,SAAS;IAEnB,MAAM,QAAQ,GAAG,CAAC,CAAS,KAAK,GAAG,EAAE,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,EAAO;AAE/D,IAAA,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE;IAE7D,MAAM,aAAa,GAAG,MAAK;QACvB,IAAI,eAAe,EA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CAAC;IACN,CAAC,EAAE,aAAa,CAAC;AAEjB,IAAA,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;AACvB,QAAA,IAAI,iBAAiB,GAAG,OAAO,CAAC,oBAAoB,KAAK,IAAI;QAE7D,MAAM,oBAAoB,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAI;YACnD,IAAI,iBAAiB,EAAE;gBACnB,iBAAiB,GAAG,KAAK;AACzB,gBAAA,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAM,EAAE,KAAK,CAAC;YAC/C;iBAAO;gBACH,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAM,CAAC;YACvC;AACJ,QAAA,CAAC,CAAC;QAEF,MAAM,oBAAoB,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,oBAAoB,CAAC;AAEtE,QAAA,OAAO,MAAK;AACR,YAAA,oBAAoB,EAAE;AACtB,YAAA,oBAAoB,EAAE;AAC1B,QAAA,CAAC;IACL;AAEA,IAAA,OAAO,aAAa;AACxB;AAEA,SAAS,UAAU,CAAC,CAAsB,EAAE,IAAa,EAAA;IACrD,OAAO,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC;AAC9B;;;;"}
1
+ {"version":3,"file":"follow.mjs","sources":["../../../../src/value/utils/follow.ts"],"sourcesContent":["import type { MotionValue } from \"..\"\nimport { FollowAnimation } from \"../../animation/FollowAnimation\"\nimport type {\n AnyResolvedKeyframe,\n GeneratorFactory,\n ValueAnimationOptions,\n} from \"../../animation/types\"\nimport type { FollowValueOptions } from \"../follow-value\"\nimport { asNumber } from \"./as-number\"\nimport { isMotionValue } from \"./is-motion-value\"\n\nexport type FollowOptions = FollowValueOptions & { type: GeneratorFactory }\n\n/**\n * Animate `value` to its latest value with the generator in\n * `options.type`, tracking `source` if it's a `MotionValue`. Takes a\n * generator rather than a type name, so spring-only callers don't\n * bundle every generator.\n */\nexport function follow<T extends AnyResolvedKeyframe>(\n value: MotionValue<T>,\n source: T | MotionValue<T>,\n options: FollowOptions\n): VoidFunction {\n const initialValue = value.get()\n\n let activeAnimation: FollowAnimation | null = null\n let set: (v: T) => void\n\n const unit =\n typeof initialValue === \"string\"\n ? initialValue.replace(/[\\d.-]/g, \"\")\n : undefined\n\n const onUpdate = (v: number) => set((unit ? v + unit : v) as T)\n\n const onPlay = () => value[\"events\"].animationStart?.notify()\n\n const stopAnimation = () => {\n if (activeAnimation) {\n activeAnimation.stop()\n activeAnimation = null\n }\n value.animation = undefined\n }\n\n value.attach((v, safeSet) => {\n set = safeSet\n const target = asNumber(v)\n\n if (activeAnimation?.state === \"running\") {\n /**\n * Steer the running animation rather than replacing it. This\n * keeps its completion promise and uses its analytical velocity\n * for accuracy, preventing systematic velocity loss at high\n * frame rates (240hz+).\n */\n activeAnimation.setTarget(target, options.velocity)\n return\n }\n\n const current = asNumber(value.get())\n const velocity = activeAnimation\n ? activeAnimation.getGeneratorVelocity()\n : value.getVelocity()\n\n stopAnimation()\n\n // Don't animate if we're already at the target\n if (current === target) return\n\n const animationOptions: ValueAnimationOptions<number> = {\n keyframes: [current, target],\n velocity,\n restDelta: 0.001,\n restSpeed: 0.01,\n ...options,\n onUpdate,\n }\n\n const animation = (activeAnimation = new FollowAnimation({\n ...animationOptions,\n onPlay,\n }))\n\n value.animation = animation\n\n animation.then(() => {\n // Ignore if this animation has since been replaced\n if (activeAnimation !== animation) return\n activeAnimation = null\n value.animation = undefined\n value[\"events\"].animationComplete?.notify()\n })\n }, stopAnimation)\n\n if (isMotionValue(source)) {\n let skipNextAnimation = options.skipInitialAnimation === true\n\n const onSourceChange = (v: T) => {\n if (skipNextAnimation) {\n skipNextAnimation = false\n value.jump(parseValue(v, unit) as T, false)\n } else {\n value.set(parseValue(v, unit) as T)\n }\n }\n\n const removeSourceOnChange = source.on(\"change\", onSourceChange)\n\n /**\n * Catch up on a change made before we subscribed, for instance\n * between a React render reading the source and the effect\n * attaching to it. Subtracting is falsy for equal or non-numeric\n * (NaN) values.\n */\n const latest = source.get()\n if (asNumber(latest) - asNumber(value.get())) onSourceChange(latest)\n\n const removeValueOnDestroy = value.on(\"destroy\", removeSourceOnChange)\n\n /**\n * Stop our animation on detach, otherwise a re-attach (new\n * options, Strict Mode) starts a second animation that fights\n * this orphaned one. The catch-up above resumes from the\n * current value and velocity.\n */\n return () => {\n removeSourceOnChange()\n removeValueOnDestroy()\n stopAnimation()\n }\n }\n\n return stopAnimation\n}\n\nfunction parseValue(v: AnyResolvedKeyframe, unit?: string) {\n return unit ? v + unit : v\n}\n"],"names":[],"mappings":";;;;AAaA;;;;;AAKG;SACa,MAAM,CAClB,KAAqB,EACrB,MAA0B,EAC1B,OAAsB,EAAA;AAEtB,IAAA,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,EAAE;IAEhC,IAAI,eAAe,GAA2B,IAAI;AAClD,IAAA,IAAI,GAAmB;AAEvB,IAAA,MAAM,IAAI,GACN,OAAO,YAAY,KAAK;UAClB,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE;UAClC,SAAS;IAEnB,MAAM,QAAQ,GAAG,CAAC,CAAS,KAAK,GAAG,EAAE,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,EAAO;AAE/D,IAAA,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE;IAE7D,MAAM,aAAa,GAAG,MAAK;QACvB,IAAI,eAAe,EAAE;YACjB,eAAe,CAAC,IAAI,EAAE;YACtB,eAAe,GAAG,IAAI;QAC1B;AACA,QAAA,KAAK,CAAC,SAAS,GAAG,SAAS;AAC/B,IAAA,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,KAAI;QACxB,GAAG,GAAG,OAAO;AACb,QAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC;AAE1B,QAAA,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AC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAM,EAAE,KAAK,CAAC;YAC/C;iBAAO;gBACH,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAM,CAAC;YACvC;AACJ,QAAA,CAAC;QAED,MAAM,oBAAoB,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC;AAEhE;;;;;AAKG;AACH,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE;QAC3B,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;YAAE,cAAc,CAAC,MAAM,CAAC;QAEpE,MAAM,oBAAoB,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,oBAAoB,CAAC;AAEtE;;;;;AAKG;AACH,QAAA,OAAO,MAAK;AACR,YAAA,oBAAoB,EAAE;AACtB,YAAA,oBAAoB,EAAE;AACtB,YAAA,aAAa,EAAE;AACnB,QAAA,CAAC;IACL;AAEA,IAAA,OAAO,aAAa;AACxB;AAEA,SAAS,UAAU,CAAC,CAAsB,EAAE,IAAa,EAAA;IACrD,OAAO,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC;AAC9B;;;;"}
package/dist/index.d.ts CHANGED
@@ -3801,14 +3801,19 @@ declare const invisibleValues: Set<string>;
3801
3801
  */
3802
3802
  declare function mixVisibility(origin: string, target: string): (p: number) => string;
3803
3803
 
3804
- type StaggerOrigin = "first" | "last" | "center" | number;
3804
+ type StaggerOrigin = "first" | "last" | "center" | "edges" | "random" | number;
3805
3805
  type StaggerOptions = {
3806
3806
  startDelay?: number;
3807
3807
  from?: StaggerOrigin;
3808
3808
  ease?: Easing;
3809
+ /**
3810
+ * Treat elements as a grid of `[columns, rows]`, in reading order.
3811
+ * Delays are then based on the 2D distance from `from`.
3812
+ */
3813
+ grid?: [number, number];
3809
3814
  };
3810
3815
  declare function getOriginIndex(from: StaggerOrigin, total: number): number;
3811
- declare function stagger(duration?: number, { startDelay, from, ease }?: StaggerOptions): DynamicOption<number>;
3816
+ declare function stagger(duration?: number, { startDelay, from, ease, grid }?: StaggerOptions): DynamicOption<number>;
3812
3817
 
3813
3818
  /**
3814
3819
  * Add the ability for test suites to manually set support flags
@@ -249,8 +249,9 @@
249
249
  const VAR_TOKEN = "var";
250
250
  const VAR_FUNCTION_TOKEN = "var(";
251
251
  const SPLIT_TOKEN = "${}";
252
- // this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`
253
- const complexRegex = /var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)/giu;
252
+ // this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`.
253
+ // The lookahead skips digits in function names, like the 3 in matrix3d(.
254
+ const complexRegex = /var\s*\(\s*--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)|#[\da-f]{3,8}|(?:rgb|hsl)a?\((?:-?[\d.]+%?[,\s]+){2}-?[\d.]+%?\s*(?:[,/]\s*)?(?:\b\d+(?:\.\d+)?|\.\d+)?%?\)|-?(?:\d+(?:\.\d+)?|\.\d+)(?![a-z]*\()/giu;
254
255
  /**
255
256
  * Whether analyseComplexValue(value) would find any values, without
256
257
  * tokenising the string. CSS variables are resolved before this is
@@ -2192,6 +2193,7 @@
2192
2193
  translateY: 5,
2193
2194
  scaleX: 0,
2194
2195
  scaleY: 3,
2196
+ scaleZ: () => 1,
2195
2197
  scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,
2196
2198
  rotate,
2197
2199
  rotateZ: rotate,
@@ -2206,8 +2208,8 @@
2206
2208
  return angle;
2207
2209
  };
2208
2210
  const rotateZ = rotate;
2209
- const scaleX = (v) => Math.sqrt(v[0] * v[0] + v[1] * v[1]);
2210
- const scaleY = (v) => Math.sqrt(v[4] * v[4] + v[5] * v[5]);
2211
+ const scaleX = (v) => Math.hypot(v[0], v[1]);
2212
+ const scaleY = (v) => Math.hypot(v[4], v[5]);
2211
2213
  const matrix3dParsers = {
2212
2214
  x: 12,
2213
2215
  y: 13,
@@ -2217,6 +2219,7 @@
2217
2219
  translateZ: 14,
2218
2220
  scaleX,
2219
2221
  scaleY,
2222
+ scaleZ: (v) => Math.hypot(v[8], v[9], v[10]),
2220
2223
  scale: (v) => (scaleX(v) + scaleY(v)) / 2,
2221
2224
  rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),
2222
2225
  rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),
@@ -2276,6 +2279,7 @@
2276
2279
  "scale",
2277
2280
  "scaleX",
2278
2281
  "scaleY",
2282
+ "scaleZ",
2279
2283
  "rotate",
2280
2284
  "rotateX",
2281
2285
  "rotateY",
@@ -7060,13 +7064,46 @@
7060
7064
  return from === "last" ? lastIndex : lastIndex / 2;
7061
7065
  }
7062
7066
  }
7063
- function stagger(duration = 0.1, { startDelay = 0, from = 0, ease } = {}) {
7067
+ function stagger(duration = 0.1, { startDelay = 0, from = 0, ease, grid } = {}) {
7068
+ /**
7069
+ * Distances from the origin for each element count. The final entry
7070
+ * holds the distance used to normalise easing.
7071
+ */
7072
+ const cache = {};
7064
7073
  return (i, total) => {
7065
- const fromIndex = typeof from === "number" ? from : getOriginIndex(from, total);
7066
- const distance = Math.abs(fromIndex - i);
7067
- let delay = duration * distance;
7068
- if (ease) {
7069
- const maxDelay = total * duration;
7074
+ let distances = cache[total];
7075
+ if (!distances) {
7076
+ const [columns, rows] = grid || [Infinity, 1];
7077
+ const lastX = Math.min(columns, total) - 1;
7078
+ const lastY = Math.max(rows, Math.ceil(total / columns)) - 1;
7079
+ const isIndex = typeof from === "number";
7080
+ const scale = from === "first" ? 0 : from === "last" ? 1 : 0.5;
7081
+ const originX = isIndex ? from % columns : lastX * scale;
7082
+ const originY = isIndex ? Math.floor(from / columns) : lastY * scale;
7083
+ distances = cache[total] = [];
7084
+ for (let j = 0; j < total; j++) {
7085
+ const x = j % columns;
7086
+ const y = Math.floor(j / columns);
7087
+ const edgeX = Math.min(x, lastX - x);
7088
+ const edgeY = Math.min(y, lastY - y);
7089
+ if (from === "random") {
7090
+ // Inside-out shuffle, so each element gets a distinct step
7091
+ const k = (Math.random() * (j + 1)) | 0;
7092
+ distances[j] = distances[k];
7093
+ distances[k] = j;
7094
+ }
7095
+ else {
7096
+ distances[j] =
7097
+ from === "edges"
7098
+ ? Math.min(lastX ? edgeX : edgeY, lastY ? edgeY : edgeX)
7099
+ : Math.hypot(x - originX, y - originY);
7100
+ }
7101
+ }
7102
+ distances.push(grid ? Math.max(...distances) : total);
7103
+ }
7104
+ let delay = duration * distances[i];
7105
+ const maxDelay = duration * distances[total];
7106
+ if (ease && maxDelay) {
7070
7107
  const easingFunction = motionUtils.easingDefinitionToFunction(ease);
7071
7108
  delay = easingFunction(delay / maxDelay) * maxDelay;
7072
7109
  }
@@ -7300,7 +7337,7 @@
7300
7337
  }, stopAnimation);
7301
7338
  if (isMotionValue(source)) {
7302
7339
  let skipNextAnimation = options.skipInitialAnimation === true;
7303
- const removeSourceOnChange = source.on("change", (v) => {
7340
+ const onSourceChange = (v) => {
7304
7341
  if (skipNextAnimation) {
7305
7342
  skipNextAnimation = false;
7306
7343
  value.jump(parseValue(v, unit), false);
@@ -7308,11 +7345,28 @@
7308
7345
  else {
7309
7346
  value.set(parseValue(v, unit));
7310
7347
  }
7311
- });
7348
+ };
7349
+ const removeSourceOnChange = source.on("change", onSourceChange);
7350
+ /**
7351
+ * Catch up on a change made before we subscribed, for instance
7352
+ * between a React render reading the source and the effect
7353
+ * attaching to it. Subtracting is falsy for equal or non-numeric
7354
+ * (NaN) values.
7355
+ */
7356
+ const latest = source.get();
7357
+ if (asNumber(latest) - asNumber(value.get()))
7358
+ onSourceChange(latest);
7312
7359
  const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
7360
+ /**
7361
+ * Stop our animation on detach, otherwise a re-attach (new
7362
+ * options, Strict Mode) starts a second animation that fights
7363
+ * this orphaned one. The catch-up above resumes from the
7364
+ * current value and velocity.
7365
+ */
7313
7366
  return () => {
7314
7367
  removeSourceOnChange();
7315
7368
  removeValueOnDestroy();
7369
+ stopAnimation();
7316
7370
  };
7317
7371
  }
7318
7372
  return stopAnimation;
@@ -9475,8 +9529,13 @@
9475
9529
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
9476
9530
  const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
9477
9531
  for (const key in props) {
9478
- if (isMotionValue(props[key]) ||
9479
- isMotionValue(prevProps[key])) {
9532
+ /**
9533
+ * A MotionValue child is rendered as text content by
9534
+ * DOMVisualElement, so it mustn't also be written as an attribute.
9535
+ */
9536
+ if (key !== "children" &&
9537
+ (isMotionValue(props[key]) ||
9538
+ isMotionValue(prevProps[key]))) {
9480
9539
  const targetKey = transformPropOrder.indexOf(key) !== -1
9481
9540
  ? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
9482
9541
  : key;