@voila.dev/motion 0.0.0-stage → 5.0.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -2
- package/dist/accessibility/reduced-motion.d.ts +13 -0
- package/dist/accessibility/reduced-motion.d.ts.map +1 -0
- package/dist/accessibility/reduced-motion.js +56 -0
- package/dist/accessibility/reduced-motion.js.map +7 -0
- package/dist/animate/animate.d.ts +21 -0
- package/dist/animate/animate.d.ts.map +1 -0
- package/dist/animate/animate.js +76 -0
- package/dist/animate/animate.js.map +7 -0
- package/dist/animate/controls.d.ts +16 -0
- package/dist/animate/controls.d.ts.map +1 -0
- package/dist/animate/controls.js +62 -0
- package/dist/animate/controls.js.map +7 -0
- package/dist/animate/dom.d.ts +11 -0
- package/dist/animate/dom.d.ts.map +1 -0
- package/dist/animate/dom.js +112 -0
- package/dist/animate/dom.js.map +7 -0
- package/dist/animate/js-animation.d.ts +25 -0
- package/dist/animate/js-animation.d.ts.map +1 -0
- package/dist/animate/js-animation.js +117 -0
- package/dist/animate/js-animation.js.map +7 -0
- package/dist/animate/plan.d.ts +17 -0
- package/dist/animate/plan.d.ts.map +1 -0
- package/dist/animate/plan.js +48 -0
- package/dist/animate/plan.js.map +7 -0
- package/dist/animate/style.d.ts +27 -0
- package/dist/animate/style.d.ts.map +1 -0
- package/dist/animate/style.js +96 -0
- package/dist/animate/style.js.map +7 -0
- package/dist/animate/types.d.ts +62 -0
- package/dist/animate/types.d.ts.map +1 -0
- package/dist/animate/types.js +1 -0
- package/dist/animate/types.js.map +7 -0
- package/dist/animate/value.d.ts +13 -0
- package/dist/animate/value.d.ts.map +1 -0
- package/dist/animate/value.js +71 -0
- package/dist/animate/value.js.map +7 -0
- package/dist/animate/waapi.d.ts +20 -0
- package/dist/animate/waapi.d.ts.map +1 -0
- package/dist/animate/waapi.js +152 -0
- package/dist/animate/waapi.js.map +7 -0
- package/dist/dom.d.ts +12 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +17 -0
- package/dist/dom.js.map +7 -0
- package/dist/easing/cubic-bezier.d.ts +4 -0
- package/dist/easing/cubic-bezier.d.ts.map +1 -0
- package/dist/easing/cubic-bezier.js +54 -0
- package/dist/easing/cubic-bezier.js.map +7 -0
- package/dist/easing/linear-css.d.ts +9 -0
- package/dist/easing/linear-css.d.ts.map +1 -0
- package/dist/easing/linear-css.js +30 -0
- package/dist/easing/linear-css.js.map +7 -0
- package/dist/easing/named.d.ts +16 -0
- package/dist/easing/named.d.ts.map +1 -0
- package/dist/easing/named.js +82 -0
- package/dist/easing/named.js.map +7 -0
- package/dist/easing/spring.d.ts +11 -0
- package/dist/easing/spring.d.ts.map +1 -0
- package/dist/easing/spring.js +18 -0
- package/dist/easing/spring.js.map +7 -0
- package/dist/easing/steps.d.ts +4 -0
- package/dist/easing/steps.d.ts.map +1 -0
- package/dist/easing/steps.js +14 -0
- package/dist/easing/steps.js.map +7 -0
- package/dist/easing/types.d.ts +5 -0
- package/dist/easing/types.d.ts.map +1 -0
- package/dist/easing/types.js +1 -0
- package/dist/easing/types.js.map +7 -0
- package/dist/frame/driver.d.ts +13 -0
- package/dist/frame/driver.d.ts.map +1 -0
- package/dist/frame/driver.js +42 -0
- package/dist/frame/driver.js.map +7 -0
- package/dist/frame/frame.d.ts +20 -0
- package/dist/frame/frame.d.ts.map +1 -0
- package/dist/frame/frame.js +77 -0
- package/dist/frame/frame.js.map +7 -0
- package/dist/generators/inertia.d.ts +20 -0
- package/dist/generators/inertia.d.ts.map +1 -0
- package/dist/generators/inertia.js +59 -0
- package/dist/generators/inertia.js.map +7 -0
- package/dist/generators/spring.d.ts +17 -0
- package/dist/generators/spring.d.ts.map +1 -0
- package/dist/generators/spring.js +87 -0
- package/dist/generators/spring.js.map +7 -0
- package/dist/generators/tween.d.ts +15 -0
- package/dist/generators/tween.d.ts.map +1 -0
- package/dist/generators/tween.js +51 -0
- package/dist/generators/tween.js.map +7 -0
- package/dist/generators/types.d.ts +30 -0
- package/dist/generators/types.d.ts.map +1 -0
- package/dist/generators/types.js +1 -0
- package/dist/generators/types.js.map +7 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +97 -0
- package/dist/index.js.map +7 -0
- package/dist/interpolate/array.d.ts +3 -0
- package/dist/interpolate/array.d.ts.map +1 -0
- package/dist/interpolate/array.js +12 -0
- package/dist/interpolate/array.js.map +7 -0
- package/dist/interpolate/color-parse.d.ts +14 -0
- package/dist/interpolate/color-parse.d.ts.map +1 -0
- package/dist/interpolate/color-parse.js +111 -0
- package/dist/interpolate/color-parse.js.map +7 -0
- package/dist/interpolate/color.d.ts +11 -0
- package/dist/interpolate/color.d.ts.map +1 -0
- package/dist/interpolate/color.js +74 -0
- package/dist/interpolate/color.js.map +7 -0
- package/dist/interpolate/complex.d.ts +7 -0
- package/dist/interpolate/complex.d.ts.map +1 -0
- package/dist/interpolate/complex.js +56 -0
- package/dist/interpolate/complex.js.map +7 -0
- package/dist/interpolate/interpolate.d.ts +16 -0
- package/dist/interpolate/interpolate.d.ts.map +1 -0
- package/dist/interpolate/interpolate.js +39 -0
- package/dist/interpolate/interpolate.js.map +7 -0
- package/dist/interpolate/mix.d.ts +8 -0
- package/dist/interpolate/mix.d.ts.map +1 -0
- package/dist/interpolate/mix.js +48 -0
- package/dist/interpolate/mix.js.map +7 -0
- package/dist/interpolate/number.d.ts +2 -0
- package/dist/interpolate/number.d.ts.map +1 -0
- package/dist/interpolate/number.js +7 -0
- package/dist/interpolate/number.js.map +7 -0
- package/dist/interpolate/object.d.ts +5 -0
- package/dist/interpolate/object.d.ts.map +1 -0
- package/dist/interpolate/object.js +17 -0
- package/dist/interpolate/object.js.map +7 -0
- package/dist/interpolate/path/flatten.d.ts +10 -0
- package/dist/interpolate/path/flatten.d.ts.map +1 -0
- package/dist/interpolate/path/flatten.js +135 -0
- package/dist/interpolate/path/flatten.js.map +7 -0
- package/dist/interpolate/path/morph.d.ts +9 -0
- package/dist/interpolate/path/morph.d.ts.map +1 -0
- package/dist/interpolate/path/morph.js +72 -0
- package/dist/interpolate/path/morph.js.map +7 -0
- package/dist/interpolate/path/parse.d.ts +24 -0
- package/dist/interpolate/path/parse.d.ts.map +1 -0
- package/dist/interpolate/path/parse.js +125 -0
- package/dist/interpolate/path/parse.js.map +7 -0
- package/dist/interpolate/path/rings.d.ts +13 -0
- package/dist/interpolate/path/rings.d.ts.map +1 -0
- package/dist/interpolate/path/rings.js +117 -0
- package/dist/interpolate/path/rings.js.map +7 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +19 -0
- package/dist/react/index.js.map +7 -0
- package/dist/react/presence.d.ts +27 -0
- package/dist/react/presence.d.ts.map +1 -0
- package/dist/react/presence.js +135 -0
- package/dist/react/presence.js.map +7 -0
- package/dist/react/use-animate.d.ts +17 -0
- package/dist/react/use-animate.d.ts.map +1 -0
- package/dist/react/use-animate.js +34 -0
- package/dist/react/use-animate.js.map +7 -0
- package/dist/react/use-motion-value.d.ts +4 -0
- package/dist/react/use-motion-value.d.ts.map +1 -0
- package/dist/react/use-motion-value.js +11 -0
- package/dist/react/use-motion-value.js.map +7 -0
- package/dist/react/use-reduced-motion.d.ts +7 -0
- package/dist/react/use-reduced-motion.d.ts.map +1 -0
- package/dist/react/use-reduced-motion.js +19 -0
- package/dist/react/use-reduced-motion.js.map +7 -0
- package/dist/react/use-spring.d.ts +9 -0
- package/dist/react/use-spring.d.ts.map +1 -0
- package/dist/react/use-spring.js +27 -0
- package/dist/react/use-spring.js.map +7 -0
- package/dist/react/use-transform.d.ts +13 -0
- package/dist/react/use-transform.d.ts.map +1 -0
- package/dist/react/use-transform.js +44 -0
- package/dist/react/use-transform.js.map +7 -0
- package/dist/sequence/sequence.d.ts +25 -0
- package/dist/sequence/sequence.d.ts.map +1 -0
- package/dist/sequence/sequence.js +68 -0
- package/dist/sequence/sequence.js.map +7 -0
- package/dist/stagger/stagger.d.ts +12 -0
- package/dist/stagger/stagger.d.ts.map +1 -0
- package/dist/stagger/stagger.js +21 -0
- package/dist/stagger/stagger.js.map +7 -0
- package/dist/testing/manual-frames.d.ts +11 -0
- package/dist/testing/manual-frames.d.ts.map +1 -0
- package/dist/testing/manual-frames.js +40 -0
- package/dist/testing/manual-frames.js.map +7 -0
- package/dist/value/motion-value.d.ts +27 -0
- package/dist/value/motion-value.d.ts.map +1 -0
- package/dist/value/motion-value.js +88 -0
- package/dist/value/motion-value.js.map +7 -0
- package/dist/value/transform.d.ts +16 -0
- package/dist/value/transform.d.ts.map +1 -0
- package/dist/value/transform.js +28 -0
- package/dist/value/transform.js.map +7 -0
- package/dist/view/in-view.d.ts +19 -0
- package/dist/view/in-view.d.ts.map +1 -0
- package/dist/view/in-view.js +46 -0
- package/dist/view/in-view.js.map +7 -0
- package/dist/view/resize.d.ts +13 -0
- package/dist/view/resize.d.ts.map +1 -0
- package/dist/view/resize.js +72 -0
- package/dist/view/resize.js.map +7 -0
- package/dist/view/resolve-elements.d.ts +3 -0
- package/dist/view/resolve-elements.d.ts.map +1 -0
- package/dist/view/resolve-elements.js +10 -0
- package/dist/view/resolve-elements.js.map +7 -0
- package/dist/view/scroll-measure.d.ts +16 -0
- package/dist/view/scroll-measure.d.ts.map +1 -0
- package/dist/view/scroll-measure.js +51 -0
- package/dist/view/scroll-measure.js.map +7 -0
- package/dist/view/scroll-offset.d.ts +28 -0
- package/dist/view/scroll-offset.d.ts.map +1 -0
- package/dist/view/scroll-offset.js +55 -0
- package/dist/view/scroll-offset.js.map +7 -0
- package/dist/view/scroll.d.ts +34 -0
- package/dist/view/scroll.d.ts.map +1 -0
- package/dist/view/scroll.js +83 -0
- package/dist/view/scroll.js.map +7 -0
- package/package.json +57 -5
- package/src/accessibility/reduced-motion.ts +75 -0
- package/src/animate/animate.ts +155 -0
- package/src/animate/controls.ts +76 -0
- package/src/animate/dom.ts +166 -0
- package/src/animate/js-animation.ts +151 -0
- package/src/animate/plan.ts +74 -0
- package/src/animate/style.ts +131 -0
- package/src/animate/types.ts +69 -0
- package/src/animate/value.ts +93 -0
- package/src/animate/waapi.ts +212 -0
- package/src/dom.ts +35 -0
- package/src/easing/cubic-bezier.ts +64 -0
- package/src/easing/linear-css.ts +41 -0
- package/src/easing/named.ts +88 -0
- package/src/easing/spring.ts +25 -0
- package/src/easing/steps.ts +16 -0
- package/src/easing/types.ts +18 -0
- package/src/frame/driver.ts +56 -0
- package/src/frame/frame.ts +102 -0
- package/src/generators/inertia.ts +88 -0
- package/src/generators/spring.ts +117 -0
- package/src/generators/tween.ts +74 -0
- package/src/generators/types.ts +31 -0
- package/src/index.ts +91 -0
- package/src/interpolate/array.ts +13 -0
- package/src/interpolate/color-parse.ts +136 -0
- package/src/interpolate/color.ts +97 -0
- package/src/interpolate/complex.ts +80 -0
- package/src/interpolate/interpolate.ts +60 -0
- package/src/interpolate/mix.ts +74 -0
- package/src/interpolate/number.ts +3 -0
- package/src/interpolate/object.ts +20 -0
- package/src/interpolate/path/flatten.ts +185 -0
- package/src/interpolate/path/morph.ts +100 -0
- package/src/interpolate/path/parse.ts +162 -0
- package/src/interpolate/path/rings.ts +151 -0
- package/src/react/index.ts +11 -0
- package/src/react/presence.tsx +194 -0
- package/src/react/use-animate.ts +46 -0
- package/src/react/use-motion-value.ts +9 -0
- package/src/react/use-reduced-motion.ts +22 -0
- package/src/react/use-spring.ts +35 -0
- package/src/react/use-transform.ts +73 -0
- package/src/sequence/sequence.ts +129 -0
- package/src/stagger/stagger.ts +36 -0
- package/src/testing/browser-commands.d.ts +11 -0
- package/src/testing/manual-frames.ts +49 -0
- package/src/value/motion-value.ts +131 -0
- package/src/value/transform.ts +61 -0
- package/src/view/in-view.ts +74 -0
- package/src/view/resize.ts +101 -0
- package/src/view/resolve-elements.ts +11 -0
- package/src/view/scroll-measure.ts +83 -0
- package/src/view/scroll-offset.ts +100 -0
- package/src/view/scroll.ts +143 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/interpolate/path/rings.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Point, Ring } from \"#/interpolate/path/flatten.ts\";\n\nfunction distance(a: Point, b: Point): number {\n\treturn Math.hypot(a[0] - b[0], a[1] - b[1]);\n}\n\n/** `count` points evenly spaced by arc length; a closed ring includes its closing edge. */\nexport function resample(ring: Ring, count: number): Point[] {\n\tconst points = ring.closed\n\t\t? [...ring.points, ring.points[0] as Point]\n\t\t: ring.points;\n\tconst lengths = [0];\n\tfor (let index = 1; index < points.length; index += 1) {\n\t\tlengths.push(\n\t\t\t(lengths[index - 1] as number) +\n\t\t\t\tdistance(points[index - 1] as Point, points[index] as Point),\n\t\t);\n\t}\n\tconst total = lengths[lengths.length - 1] as number;\n\tif (points.length < 2 || total === 0) {\n\t\treturn Array.from({ length: count }, () => points[0] as Point);\n\t}\n\tconst step = total / (ring.closed ? count : Math.max(1, count - 1));\n\tconst result: Point[] = [];\n\tlet segment = 1;\n\tfor (let index = 0; index < count; index += 1) {\n\t\tconst along = Math.min(total, index * step);\n\t\twhile (\n\t\t\tsegment < points.length - 1 &&\n\t\t\t(lengths[segment] as number) < along\n\t\t) {\n\t\t\tsegment += 1;\n\t\t}\n\t\tconst [a, b] = [points[segment - 1] as Point, points[segment] as Point];\n\t\tconst span =\n\t\t\t(lengths[segment] as number) - (lengths[segment - 1] as number);\n\t\tconst t =\n\t\t\tspan === 0 ? 0 : (along - (lengths[segment - 1] as number)) / span;\n\t\tresult.push([a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t]);\n\t}\n\treturn result;\n}\n\nexport function area(points: readonly Point[]): number {\n\tlet sum = 0;\n\tpoints.forEach((point, index) => {\n\t\tconst next = points[(index + 1) % points.length] as Point;\n\t\tsum += point[0] * next[1] - next[0] * point[1];\n\t});\n\treturn sum / 2;\n}\n\nexport function centroid(points: readonly Point[]): Point {\n\tconst sum = points.reduce<[number, number]>(\n\t\t(total, [x, y]) => [total[0] + x, total[1] + y],\n\t\t[0, 0],\n\t);\n\treturn [sum[0] / points.length, sum[1] / points.length];\n}\n\nfunction cost(\n\ta: readonly Point[],\n\tb: readonly Point[],\n\toffset: number,\n): number {\n\tlet sum = 0;\n\tfor (let index = 0; index < a.length; index += 1) {\n\t\tconst other = b[(index + offset) % b.length] as Point;\n\t\tconst point = a[index] as Point;\n\t\tsum += (point[0] - other[0]) ** 2 + (point[1] - other[1]) ** 2;\n\t}\n\treturn sum;\n}\n\n/**\n * `to` rearranged so each point travels as little as it can to its partner\n * in `from`: a closed ring may start anywhere and run either way round, an\n * open one may only run backwards. Both have the same length.\n */\nexport function alignRing(\n\tfrom: readonly Point[],\n\tto: readonly Point[],\n\tclosed: boolean,\n): Point[] {\n\tconst candidates = [to, [...to].reverse()];\n\tlet best = {\n\t\tpoints: to as readonly Point[],\n\t\toffset: 0,\n\t\tcost: Number.POSITIVE_INFINITY,\n\t};\n\tfor (const points of candidates) {\n\t\tconst offsets = closed ? points.length : 1;\n\t\tfor (let offset = 0; offset < offsets; offset += 1) {\n\t\t\tconst value = cost(from, points, offset);\n\t\t\tif (value < best.cost) {\n\t\t\t\tbest = { points, offset, cost: value };\n\t\t\t}\n\t\t}\n\t}\n\treturn best.points.map(\n\t\t(_point, index) =>\n\t\t\tbest.points[(index + best.offset) % best.points.length] as Point,\n\t);\n}\n\n/**\n * Pairs each ring of one shape with a ring of the other, nearest centroids and\n * closest areas first. A ring left over pairs with `undefined`: it grows from,\n * or shrinks to, its own centroid.\n */\nfunction describe(ring: Ring) {\n\treturn { centre: centroid(ring.points), size: Math.abs(area(ring.points)) };\n}\n\nexport function matchRings(\n\tfrom: readonly Ring[],\n\tto: readonly Ring[],\n): [Ring | undefined, Ring | undefined][] {\n\tconst starts = from.map(describe);\n\tconst ends = to.map(describe);\n\tconst pairs = starts.flatMap((start, i) =>\n\t\tends.map((end, j) => {\n\t\t\tconst scale = Math.sqrt(Math.max(start.size, end.size, 1));\n\t\t\treturn {\n\t\t\t\ti,\n\t\t\t\tj,\n\t\t\t\tscore:\n\t\t\t\t\tdistance(start.centre, end.centre) / scale +\n\t\t\t\t\tMath.abs(Math.log((start.size + 1) / (end.size + 1))),\n\t\t\t};\n\t\t}),\n\t);\n\tpairs.sort((a, b) => a.score - b.score);\n\tconst usedFrom = new Set<number>();\n\tconst usedTo = new Set<number>();\n\tconst result: [Ring | undefined, Ring | undefined][] = [];\n\tfor (const { i, j } of pairs) {\n\t\tif (!usedFrom.has(i) && !usedTo.has(j)) {\n\t\t\tusedFrom.add(i);\n\t\t\tusedTo.add(j);\n\t\t\tresult.push([from[i], to[j]]);\n\t\t}\n\t}\n\tfor (const [i, ring] of from.entries()) {\n\t\tif (!usedFrom.has(i)) result.push([ring, undefined]);\n\t}\n\tfor (const [j, ring] of to.entries()) {\n\t\tif (!usedTo.has(j)) result.push([undefined, ring]);\n\t}\n\treturn result;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,SAAS,GAAU,GAAkB;AAC7C,SAAO,KAAK,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3C;AAGO,SAAS,SAAS,MAAY,OAAwB;AAC5D,QAAM,SAAS,KAAK,SACjB,CAAC,GAAG,KAAK,QAAQ,KAAK,OAAO,CAAC,CAAU,IACxC,KAAK;AACR,QAAM,UAAU,CAAC,CAAC;AAClB,WAAS,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS,GAAG;AACtD,YAAQ;AAAA,MACN,QAAQ,QAAQ,CAAC,IACjB,SAAS,OAAO,QAAQ,CAAC,GAAY,OAAO,KAAK,CAAU;AAAA,IAC7D;AAAA,EACD;AACA,QAAM,QAAQ,QAAQ,QAAQ,SAAS,CAAC;AACxC,MAAI,OAAO,SAAS,KAAK,UAAU,GAAG;AACrC,WAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,GAAG,MAAM,OAAO,CAAC,CAAU;AA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AAI,MAAM,MAAM,IAAI,MAAM,CAAC,CAAC;AACzD,aAAO;AAAA,QACN;AAAA,QACA;AAAA,QACA,OACC,SAAS,MAAM,QAAQ,IAAI,MAAM,IAAI,QACrC,KAAK,IAAI,KAAK,KAAK,MAAM,OAAO,MAAM,IAAI,OAAO,EAAE,CAAC;AAAA,MACtD;AAAA,IACD,CAAC;AAAA,EACF;AACA,QAAM,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AACtC,QAAM,WAAW,oBAAI,IAAY;AACjC,QAAM,SAAS,oBAAI,IAAY;AAC/B,QAAM,SAAiD,CAAC;AACxD,aAAW,EAAE,GAAG,EAAE,KAAK,OAAO;AAC7B,QAAI,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,GAAG;AACvC,eAAS,IAAI,CAAC;AACd,aAAO,IAAI,CAAC;AACZ,aAAO,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AAAA,IAC7B;AAAA,EACD;AACA,aAAW,CAAC,GAAG,IAAI,KAAK,KAAK,QAAQ,GAAG;AACvC,QAAI,CAAC,SAAS,IAAI,CAAC,EAAG,QAAO,KAAK,CAAC,MAAM,MAAS,CAAC;AAAA,EACpD;AACA,aAAW,CAAC,GAAG,IAAI,KAAK,GAAG,QAAQ,GAAG;AACrC,QAAI,CAAC,OAAO,IAAI,CAAC,EAAG,QAAO,KAAK,CAAC,QAAW,IAAI,CAAC;AAAA,EAClD;AACA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { type Exit, Presence, type PresenceProps, usePresence, } from "./presence.js";
|
|
2
|
+
export { type AnimationScope, useAnimate } from "./use-animate.js";
|
|
3
|
+
export { useMotionValue } from "./use-motion-value.js";
|
|
4
|
+
export { useReducedMotion } from "./use-reduced-motion.js";
|
|
5
|
+
export { useSpring } from "./use-spring.js";
|
|
6
|
+
export { useTransform } from "./use-transform.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,IAAI,EACT,QAAQ,EACR,KAAK,aAAa,EAClB,WAAW,GACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,cAAc,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Presence,
|
|
3
|
+
usePresence
|
|
4
|
+
} from "./presence.js";
|
|
5
|
+
import { useAnimate } from "./use-animate.js";
|
|
6
|
+
import { useMotionValue } from "./use-motion-value.js";
|
|
7
|
+
import { useReducedMotion } from "./use-reduced-motion.js";
|
|
8
|
+
import { useSpring } from "./use-spring.js";
|
|
9
|
+
import { useTransform } from "./use-transform.js";
|
|
10
|
+
export {
|
|
11
|
+
Presence,
|
|
12
|
+
useAnimate,
|
|
13
|
+
useMotionValue,
|
|
14
|
+
usePresence,
|
|
15
|
+
useReducedMotion,
|
|
16
|
+
useSpring,
|
|
17
|
+
useTransform
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/react/index.ts"],
|
|
4
|
+
"sourcesContent": ["export {\n\ttype Exit,\n\tPresence,\n\ttype PresenceProps,\n\tusePresence,\n} from \"#/react/presence.tsx\";\nexport { type AnimationScope, useAnimate } from \"#/react/use-animate.ts\";\nexport { useMotionValue } from \"#/react/use-motion-value.ts\";\nexport { useReducedMotion } from \"#/react/use-reduced-motion.ts\";\nexport { useSpring } from \"#/react/use-spring.ts\";\nexport { useTransform } from \"#/react/use-transform.ts\";\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAEC;AAAA,EAEA;AAAA,OACM;AACP,SAA8B,kBAAkB;AAChD,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** Plays a child's way out; Presence removes it once the returned promise settles. */
|
|
3
|
+
export type Exit = (element: Element) => PromiseLike<unknown> | undefined;
|
|
4
|
+
declare module "react" {
|
|
5
|
+
interface Attributes {
|
|
6
|
+
/** Inside a `<Presence>`: plays this child's way out before it unmounts. */
|
|
7
|
+
exit?: Exit;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Whether this component is still wanted, and the function that lets it go
|
|
12
|
+
* once its own exit has played. Outside a Presence it is always present.
|
|
13
|
+
*/
|
|
14
|
+
export declare function usePresence(): readonly [boolean, () => void];
|
|
15
|
+
export interface PresenceProps {
|
|
16
|
+
readonly children?: React.ReactNode;
|
|
17
|
+
/** Called each time the last exiting child is gone. */
|
|
18
|
+
readonly onExitComplete?: () => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Keeps a removed child on screen until its exit has played: the `exit`
|
|
22
|
+
* prop it carries (given the child's element, through its ref), or the
|
|
23
|
+
* child's own `usePresence`. Children need a stable `key`. An exiting child
|
|
24
|
+
* is inert: it can't take focus or clicks on its way out.
|
|
25
|
+
*/
|
|
26
|
+
export declare function Presence({ children, onExitComplete }: PresenceProps): React.JSX.Element[];
|
|
27
|
+
//# sourceMappingURL=presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../../src/react/presence.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,sFAAsF;AACtF,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,WAAW,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;AAE1E,OAAO,QAAQ,OAAO,CAAC;IACtB,UAAU,UAAU;QACnB,4EAA4E;QAC5E,IAAI,CAAC,EAAE,IAAI,CAAC;KACZ;CACD;AAYD;;;GAGG;AACH,wBAAgB,WAAW,IAAI,SAAS,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,CAK5D;AAgCD,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACpC,uDAAuD;IACvD,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,aAAa,uBAsHnE"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
const PresenceContext = React.createContext(null);
|
|
4
|
+
function usePresence() {
|
|
5
|
+
const state = React.useContext(PresenceContext);
|
|
6
|
+
const register = state?.register;
|
|
7
|
+
React.useLayoutEffect(() => register?.(), [register]);
|
|
8
|
+
return [state?.isPresent ?? true, state?.safeToRemove ?? noop];
|
|
9
|
+
}
|
|
10
|
+
function noop() {
|
|
11
|
+
}
|
|
12
|
+
function keyedChildren(children) {
|
|
13
|
+
return React.Children.toArray(children).filter(
|
|
14
|
+
(child) => React.isValidElement(child)
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
function merge(previous, current) {
|
|
18
|
+
const keys = new Set(current.map((child) => child.key));
|
|
19
|
+
const merged = [...current];
|
|
20
|
+
for (const [index, child] of previous.entries()) {
|
|
21
|
+
if (keys.has(child.key)) continue;
|
|
22
|
+
const before = previous[index - 1]?.key;
|
|
23
|
+
const at = merged.findIndex((other) => other.key === before);
|
|
24
|
+
merged.splice(at + 1, 0, child);
|
|
25
|
+
}
|
|
26
|
+
return merged;
|
|
27
|
+
}
|
|
28
|
+
function Presence({ children, onExitComplete }) {
|
|
29
|
+
const current = keyedChildren(children);
|
|
30
|
+
const rendered = React.useRef(current);
|
|
31
|
+
const gone = React.useRef(/* @__PURE__ */ new Set());
|
|
32
|
+
const elements = React.useRef(/* @__PURE__ */ new Map());
|
|
33
|
+
const registered = React.useRef(/* @__PURE__ */ new Map());
|
|
34
|
+
const [, rerender] = React.useReducer((count) => count + 1, 0);
|
|
35
|
+
const currentKeys = new Set(current.map((child) => child.key));
|
|
36
|
+
const present = React.useRef(currentKeys);
|
|
37
|
+
present.current = currentKeys;
|
|
38
|
+
const leaving = React.useRef(
|
|
39
|
+
/* @__PURE__ */ new Map()
|
|
40
|
+
);
|
|
41
|
+
const shown = merge(
|
|
42
|
+
rendered.current.filter((child) => !gone.current.has(child.key)),
|
|
43
|
+
current
|
|
44
|
+
);
|
|
45
|
+
for (const key of currentKeys) gone.current.delete(key);
|
|
46
|
+
rendered.current = shown;
|
|
47
|
+
const exiting = shown.filter((child) => !currentKeys.has(child.key));
|
|
48
|
+
const remove = React.useCallback(
|
|
49
|
+
(key) => {
|
|
50
|
+
if (gone.current.has(key) || present.current.has(key)) return;
|
|
51
|
+
gone.current.add(key);
|
|
52
|
+
leaving.current.delete(key);
|
|
53
|
+
rerender();
|
|
54
|
+
const left = rendered.current.some(
|
|
55
|
+
(child) => !gone.current.has(child.key) && !present.current.has(child.key)
|
|
56
|
+
);
|
|
57
|
+
if (!left) onExitComplete?.();
|
|
58
|
+
},
|
|
59
|
+
[onExitComplete]
|
|
60
|
+
);
|
|
61
|
+
const exitingKeys = exiting.map((child) => child.key).join("\0");
|
|
62
|
+
React.useLayoutEffect(() => {
|
|
63
|
+
for (const [key, played] of leaving.current) {
|
|
64
|
+
if (!present.current.has(key)) continue;
|
|
65
|
+
leaving.current.delete(key);
|
|
66
|
+
elements.current.get(key)?.removeAttribute("inert");
|
|
67
|
+
played?.cancel?.();
|
|
68
|
+
}
|
|
69
|
+
for (const child of exiting) {
|
|
70
|
+
if (leaving.current.has(child.key)) continue;
|
|
71
|
+
const element = elements.current.get(child.key);
|
|
72
|
+
element?.setAttribute("inert", "");
|
|
73
|
+
const played = element && child.props.exit?.(element);
|
|
74
|
+
leaving.current.set(child.key, played);
|
|
75
|
+
if (played) {
|
|
76
|
+
Promise.resolve(played).then(
|
|
77
|
+
() => remove(child.key),
|
|
78
|
+
() => remove(child.key)
|
|
79
|
+
);
|
|
80
|
+
} else if (!registered.current.get(child.key)) {
|
|
81
|
+
remove(child.key);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}, [exitingKeys]);
|
|
85
|
+
const removeRef = React.useRef(remove);
|
|
86
|
+
removeRef.current = remove;
|
|
87
|
+
const slots = React.useRef(/* @__PURE__ */ new Map());
|
|
88
|
+
function slotFor(key) {
|
|
89
|
+
const existing = slots.current.get(key);
|
|
90
|
+
if (existing) return existing;
|
|
91
|
+
function register() {
|
|
92
|
+
registered.current.set(key, (registered.current.get(key) ?? 0) + 1);
|
|
93
|
+
return () => {
|
|
94
|
+
registered.current.set(key, (registered.current.get(key) ?? 1) - 1);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function safeToRemove() {
|
|
98
|
+
removeRef.current(key);
|
|
99
|
+
}
|
|
100
|
+
const slot = {
|
|
101
|
+
ownRef: void 0,
|
|
102
|
+
ref(element) {
|
|
103
|
+
if (element) elements.current.set(key, element);
|
|
104
|
+
else elements.current.delete(key);
|
|
105
|
+
const ownRef = slot.ownRef;
|
|
106
|
+
if (typeof ownRef === "function") ownRef(element);
|
|
107
|
+
else if (ownRef)
|
|
108
|
+
ownRef.current = element;
|
|
109
|
+
},
|
|
110
|
+
present: { isPresent: true, safeToRemove, register },
|
|
111
|
+
absent: { isPresent: false, safeToRemove, register }
|
|
112
|
+
};
|
|
113
|
+
slots.current.set(key, slot);
|
|
114
|
+
return slot;
|
|
115
|
+
}
|
|
116
|
+
return shown.map((child) => {
|
|
117
|
+
const key = child.key;
|
|
118
|
+
const { exit: _exit, ref: ownRef, ...props } = child.props;
|
|
119
|
+
const slot = slotFor(key);
|
|
120
|
+
slot.ownRef = ownRef;
|
|
121
|
+
return /* @__PURE__ */ jsx(
|
|
122
|
+
PresenceContext.Provider,
|
|
123
|
+
{
|
|
124
|
+
value: currentKeys.has(key) ? slot.present : slot.absent,
|
|
125
|
+
children: React.createElement(child.type, { ...props, ref: slot.ref })
|
|
126
|
+
},
|
|
127
|
+
key
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
Presence,
|
|
133
|
+
usePresence
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=presence.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/react/presence.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from \"react\";\n\n/** Plays a child's way out; Presence removes it once the returned promise settles. */\nexport type Exit = (element: Element) => PromiseLike<unknown> | undefined;\n\ndeclare module \"react\" {\n\tinterface Attributes {\n\t\t/** Inside a `<Presence>`: plays this child's way out before it unmounts. */\n\t\texit?: Exit;\n\t}\n}\n\ninterface PresenceState {\n\treadonly isPresent: boolean;\n\t/** For a child that animates its own exit: tells Presence it may go. */\n\treadonly safeToRemove: () => void;\n\t/** Called by `usePresence`: Presence then waits for `safeToRemove`. */\n\treadonly register: () => () => void;\n}\n\nconst PresenceContext = React.createContext<PresenceState | null>(null);\n\n/**\n * Whether this component is still wanted, and the function that lets it go\n * once its own exit has played. Outside a Presence it is always present.\n */\nexport function usePresence(): readonly [boolean, () => void] {\n\tconst state = React.useContext(PresenceContext);\n\tconst register = state?.register;\n\tReact.useLayoutEffect(() => register?.(), [register]);\n\treturn [state?.isPresent ?? true, state?.safeToRemove ?? noop];\n}\n\nfunction noop() {}\n\ntype Keyed = React.ReactElement<{ exit?: Exit; ref?: React.Ref<Element> }>;\n\nfunction keyedChildren(children: React.ReactNode): Keyed[] {\n\treturn React.Children.toArray(children).filter((child): child is Keyed =>\n\t\tReact.isValidElement(child),\n\t);\n}\n\n/** The new children, with the ones that left kept where they were. */\nfunction merge(previous: readonly Keyed[], current: readonly Keyed[]): Keyed[] {\n\tconst keys = new Set(current.map((child) => child.key));\n\tconst merged = [...current];\n\tfor (const [index, child] of previous.entries()) {\n\t\tif (keys.has(child.key)) continue;\n\t\tconst before = previous[index - 1]?.key;\n\t\tconst at = merged.findIndex((other) => other.key === before);\n\t\tmerged.splice(at + 1, 0, child);\n\t}\n\treturn merged;\n}\n\ninterface Slot {\n\townRef: React.Ref<Element> | undefined;\n\treadonly ref: (element: Element | null) => void;\n\treadonly present: PresenceState;\n\treadonly absent: PresenceState;\n}\n\nexport interface PresenceProps {\n\treadonly children?: React.ReactNode;\n\t/** Called each time the last exiting child is gone. */\n\treadonly onExitComplete?: () => void;\n}\n\n/**\n * Keeps a removed child on screen until its exit has played: the `exit`\n * prop it carries (given the child's element, through its ref), or the\n * child's own `usePresence`. Children need a stable `key`. An exiting child\n * is inert: it can't take focus or clicks on its way out.\n */\nexport function Presence({ children, onExitComplete }: PresenceProps) {\n\tconst current = keyedChildren(children);\n\tconst rendered = React.useRef<Keyed[]>(current);\n\tconst gone = React.useRef(new Set<string | null>());\n\tconst elements = React.useRef(new Map<string | null, Element>());\n\tconst registered = React.useRef(new Map<string | null, number>());\n\tconst [, rerender] = React.useReducer((count: number) => count + 1, 0);\n\n\tconst currentKeys = new Set(current.map((child) => child.key));\n\tconst present = React.useRef(currentKeys);\n\tpresent.current = currentKeys;\n\t/** Exits under way, so a later exit doesn't restart them, and a return can undo them. */\n\tconst leaving = React.useRef(\n\t\tnew Map<string | null, PromiseLike<unknown> | undefined>(),\n\t);\n\tconst shown = merge(\n\t\trendered.current.filter((child) => !gone.current.has(child.key)),\n\t\tcurrent,\n\t);\n\tfor (const key of currentKeys) gone.current.delete(key);\n\trendered.current = shown;\n\tconst exiting = shown.filter((child) => !currentKeys.has(child.key));\n\n\tconst remove = React.useCallback(\n\t\t(key: string | null) => {\n\t\t\t// Gone already, or back before its exit finished.\n\t\t\tif (gone.current.has(key) || present.current.has(key)) return;\n\t\t\tgone.current.add(key);\n\t\t\tleaving.current.delete(key);\n\t\t\trerender();\n\t\t\tconst left = rendered.current.some(\n\t\t\t\t(child) =>\n\t\t\t\t\t!gone.current.has(child.key) && !present.current.has(child.key),\n\t\t\t);\n\t\t\tif (!left) onExitComplete?.();\n\t\t},\n\t\t[onExitComplete],\n\t);\n\n\tconst exitingKeys = exiting.map((child) => child.key).join(\"\\u0000\");\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: keyed on the set of exiting children.\n\tReact.useLayoutEffect(() => {\n\t\tfor (const [key, played] of leaving.current) {\n\t\t\tif (!present.current.has(key)) continue;\n\t\t\tleaving.current.delete(key);\n\t\t\telements.current.get(key)?.removeAttribute(\"inert\");\n\t\t\t(played as { cancel?: () => void } | undefined)?.cancel?.();\n\t\t}\n\t\tfor (const child of exiting) {\n\t\t\tif (leaving.current.has(child.key)) continue;\n\t\t\tconst element = elements.current.get(child.key);\n\t\t\telement?.setAttribute(\"inert\", \"\");\n\t\t\tconst played = element && child.props.exit?.(element);\n\t\t\tleaving.current.set(child.key, played);\n\t\t\tif (played) {\n\t\t\t\tPromise.resolve(played).then(\n\t\t\t\t\t() => remove(child.key),\n\t\t\t\t\t() => remove(child.key),\n\t\t\t\t);\n\t\t\t} else if (!registered.current.get(child.key)) {\n\t\t\t\tremove(child.key);\n\t\t\t}\n\t\t}\n\t}, [exitingKeys]);\n\n\tconst removeRef = React.useRef(remove);\n\tremoveRef.current = remove;\n\tconst slots = React.useRef(new Map<string | null, Slot>());\n\n\t/**\n\t * Stable per key: the ref React sees and the context values never change\n\t * identity between renders, so a child's own callback ref isn't detached\n\t * and reattached each time, and `usePresence` consumers only re-render\n\t * when their presence flips.\n\t */\n\tfunction slotFor(key: string | null): Slot {\n\t\tconst existing = slots.current.get(key);\n\t\tif (existing) return existing;\n\t\tfunction register() {\n\t\t\tregistered.current.set(key, (registered.current.get(key) ?? 0) + 1);\n\t\t\treturn () => {\n\t\t\t\tregistered.current.set(key, (registered.current.get(key) ?? 1) - 1);\n\t\t\t};\n\t\t}\n\t\tfunction safeToRemove() {\n\t\t\tremoveRef.current(key);\n\t\t}\n\t\tconst slot: Slot = {\n\t\t\townRef: undefined,\n\t\t\tref(element) {\n\t\t\t\tif (element) elements.current.set(key, element);\n\t\t\t\telse elements.current.delete(key);\n\t\t\t\tconst ownRef = slot.ownRef;\n\t\t\t\tif (typeof ownRef === \"function\") ownRef(element);\n\t\t\t\telse if (ownRef)\n\t\t\t\t\t(ownRef as React.RefObject<Element | null>).current = element;\n\t\t\t},\n\t\t\tpresent: { isPresent: true, safeToRemove, register },\n\t\t\tabsent: { isPresent: false, safeToRemove, register },\n\t\t};\n\t\tslots.current.set(key, slot);\n\t\treturn slot;\n\t}\n\n\treturn shown.map((child) => {\n\t\tconst key = child.key;\n\t\tconst { exit: _exit, ref: ownRef, ...props } = child.props;\n\t\tconst slot = slotFor(key);\n\t\tslot.ownRef = ownRef;\n\t\treturn (\n\t\t\t<PresenceContext.Provider\n\t\t\t\tkey={key}\n\t\t\t\tvalue={currentKeys.has(key) ? slot.present : slot.absent}\n\t\t\t>\n\t\t\t\t{React.createElement(child.type, { ...props, ref: slot.ref })}\n\t\t\t</PresenceContext.Provider>\n\t\t);\n\t});\n}\n"],
|
|
5
|
+
"mappings": "AAyLG;AAzLH,YAAY,WAAW;AAoBvB,MAAM,kBAAkB,MAAM,cAAoC,IAAI;AAM/D,SAAS,cAA8C;AAC7D,QAAM,QAAQ,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AQ,IAAI,KAAK,IAAI;AAC3B,WAAO;AAAA,EACR;AAEA,SAAO,MAAM,IAAI,CAAC,UAAU;AAC3B,UAAM,MAAM,MAAM;AAClB,UAAM,EAAE,MAAM,OAAO,KAAK,QAAQ,GAAG,MAAM,IAAI,MAAM;AACrD,UAAM,OAAO,QAAQ,GAAG;AACxB,SAAK,SAAS;AACd,WACC;AAAA,MAAC,gBAAgB;AAAA,MAAhB;AAAA,QAEA,OAAO,YAAY,IAAI,GAAG,IAAI,KAAK,UAAU,KAAK;AAAA,QAEjD,gBAAM,cAAc,MAAM,MAAM,EAAE,GAAG,OAAO,KAAK,KAAK,IAAI,CAAC;AAAA;AAAA,MAHvD;AAAA,IAIN;AAAA,EAEF,CAAC;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Animate } from "../animate/animate.js";
|
|
2
|
+
import type { AnimationControls } from "../animate/types.js";
|
|
3
|
+
export interface AnimationScope<T extends Element = Element> {
|
|
4
|
+
current: T | null;
|
|
5
|
+
/** The animations started through this scope and still running. */
|
|
6
|
+
readonly animations: AnimationControls[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A ref to put on an element, and an `animate` whose selectors only match
|
|
10
|
+
* inside it. Every animation started through it stops on unmount, so a
|
|
11
|
+
* component never animates a node React already removed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useAnimate<T extends Element = HTMLElement>(): readonly [
|
|
14
|
+
AnimationScope<T>,
|
|
15
|
+
Animate
|
|
16
|
+
];
|
|
17
|
+
//# sourceMappingURL=use-animate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-animate.d.ts","sourceRoot":"","sources":["../../src/react/use-animate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IAC1D,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAClB,mEAAmE;IACnE,QAAQ,CAAC,UAAU,EAAE,iBAAiB,EAAE,CAAC;CACzC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,WAAW,KAAK,SAAS;IACvE,cAAc,CAAC,CAAC,CAAC;IACjB,OAAO;CACP,CA2BA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { createAnimate } from "../animate/animate.js";
|
|
3
|
+
function useAnimate() {
|
|
4
|
+
const [scope] = React.useState(() => ({
|
|
5
|
+
current: null,
|
|
6
|
+
animations: []
|
|
7
|
+
}));
|
|
8
|
+
const [scoped] = React.useState(() => {
|
|
9
|
+
const base = createAnimate(() => scope.current);
|
|
10
|
+
function tracked(...args) {
|
|
11
|
+
const controls = base(
|
|
12
|
+
...args
|
|
13
|
+
);
|
|
14
|
+
scope.animations.push(controls);
|
|
15
|
+
controls.finished.then(() => {
|
|
16
|
+
const index = scope.animations.indexOf(controls);
|
|
17
|
+
if (index !== -1) scope.animations.splice(index, 1);
|
|
18
|
+
});
|
|
19
|
+
return controls;
|
|
20
|
+
}
|
|
21
|
+
return tracked;
|
|
22
|
+
});
|
|
23
|
+
React.useEffect(
|
|
24
|
+
() => () => {
|
|
25
|
+
for (const controls of scope.animations.splice(0)) controls.stop();
|
|
26
|
+
},
|
|
27
|
+
[scope]
|
|
28
|
+
);
|
|
29
|
+
return [scope, scoped];
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
useAnimate
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=use-animate.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/react/use-animate.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from \"react\";\nimport { type Animate, createAnimate } from \"#/animate/animate.ts\";\nimport type { AnimationControls } from \"#/animate/types.ts\";\n\nexport interface AnimationScope<T extends Element = Element> {\n\tcurrent: T | null;\n\t/** The animations started through this scope and still running. */\n\treadonly animations: AnimationControls[];\n}\n\n/**\n * A ref to put on an element, and an `animate` whose selectors only match\n * inside it. Every animation started through it stops on unmount, so a\n * component never animates a node React already removed.\n */\nexport function useAnimate<T extends Element = HTMLElement>(): readonly [\n\tAnimationScope<T>,\n\tAnimate,\n] {\n\tconst [scope] = React.useState<AnimationScope<T>>(() => ({\n\t\tcurrent: null,\n\t\tanimations: [],\n\t}));\n\tconst [scoped] = React.useState(() => {\n\t\tconst base = createAnimate(() => scope.current);\n\t\tfunction tracked(...args: Parameters<typeof base>): AnimationControls {\n\t\t\tconst controls = (base as (...a: unknown[]) => AnimationControls)(\n\t\t\t\t...args,\n\t\t\t);\n\t\t\tscope.animations.push(controls);\n\t\t\tcontrols.finished.then(() => {\n\t\t\t\tconst index = scope.animations.indexOf(controls);\n\t\t\t\tif (index !== -1) scope.animations.splice(index, 1);\n\t\t\t});\n\t\t\treturn controls;\n\t\t}\n\t\treturn tracked as Animate;\n\t});\n\tReact.useEffect(\n\t\t() => () => {\n\t\t\tfor (const controls of scope.animations.splice(0)) controls.stop();\n\t\t},\n\t\t[scope],\n\t);\n\treturn [scope, scoped] as const;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AACvB,SAAuB,qBAAqB;AAcrC,SAAS,aAGd;AACD,QAAM,CAAC,KAAK,IAAI,MAAM,SAA4B,OAAO;AAAA,IACxD,SAAS;AAAA,IACT,YAAY,CAAC;AAAA,EACd,EAAE;AACF,QAAM,CAAC,MAAM,IAAI,MAAM,SAAS,MAAM;AACrC,UAAM,OAAO,cAAc,MAAM,MAAM,OAAO;AAC9C,aAAS,WAAW,MAAkD;AACrE,YAAM,WAAY;AAAA,QACjB,GAAG;AAAA,MACJ;AACA,YAAM,WAAW,KAAK,QAAQ;AAC9B,eAAS,SAAS,KAAK,MAAM;AAC5B,cAAM,QAAQ,MAAM,WAAW,QAAQ,QAAQ;AAC/C,YAAI,UAAU,GAAI,OAAM,WAAW,OAAO,OAAO,CAAC;AAAA,MACnD,CAAC;AACD,aAAO;AAAA,IACR;AACA,WAAO;AAAA,EACR,CAAC;AACD,QAAM;AAAA,IACL,MAAM,MAAM;AACX,iBAAW,YAAY,MAAM,WAAW,OAAO,CAAC,EAAG,UAAS,KAAK;AAAA,IAClE;AAAA,IACA,CAAC,KAAK;AAAA,EACP;AACA,SAAO,CAAC,OAAO,MAAM;AACtB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-motion-value.d.ts","sourceRoot":"","sources":["../../src/react/use-motion-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAe,MAAM,yBAAyB,CAAC;AAExE,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAI5D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { motionValue } from "../value/motion-value.js";
|
|
3
|
+
function useMotionValue(initial) {
|
|
4
|
+
const [value] = React.useState(() => motionValue(initial));
|
|
5
|
+
React.useEffect(() => () => value.stop(), [value]);
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
useMotionValue
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=use-motion-value.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/react/use-motion-value.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from \"react\";\nimport { type MotionValue, motionValue } from \"#/value/motion-value.ts\";\n\n/** A motion value that lives as long as the component, created once. */\nexport function useMotionValue<T>(initial: T): MotionValue<T> {\n\tconst [value] = React.useState(() => motionValue(initial));\n\tReact.useEffect(() => () => value.stop(), [value]);\n\treturn value;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AACvB,SAA2B,mBAAmB;AAGvC,SAAS,eAAkB,SAA4B;AAC7D,QAAM,CAAC,KAAK,IAAI,MAAM,SAAS,MAAM,YAAY,OAAO,CAAC;AACzD,QAAM,UAAU,MAAM,MAAM,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC;AACjD,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether motion should be reduced, following the global policy and the
|
|
3
|
+
* reader's setting as either changes. False on the server: the first client
|
|
4
|
+
* render matches, then corrects itself.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useReducedMotion(): boolean;
|
|
7
|
+
//# sourceMappingURL=use-reduced-motion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-reduced-motion.d.ts","sourceRoot":"","sources":["../../src/react/use-reduced-motion.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAM1C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
onReducedMotionChange,
|
|
4
|
+
shouldReduceMotion
|
|
5
|
+
} from "../accessibility/reduced-motion.js";
|
|
6
|
+
function serverSnapshot() {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
function useReducedMotion() {
|
|
10
|
+
return React.useSyncExternalStore(
|
|
11
|
+
onReducedMotionChange,
|
|
12
|
+
() => shouldReduceMotion(),
|
|
13
|
+
serverSnapshot
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
useReducedMotion
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=use-reduced-motion.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/react/use-reduced-motion.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from \"react\";\nimport {\n\tonReducedMotionChange,\n\tshouldReduceMotion,\n} from \"#/accessibility/reduced-motion.ts\";\n\nfunction serverSnapshot(): boolean {\n\treturn false;\n}\n\n/**\n * Whether motion should be reduced, following the global policy and the\n * reader's setting as either changes. False on the server: the first client\n * render matches, then corrects itself.\n */\nexport function useReducedMotion(): boolean {\n\treturn React.useSyncExternalStore(\n\t\tonReducedMotionChange,\n\t\t() => shouldReduceMotion(),\n\t\tserverSnapshot,\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AACvB;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAEP,SAAS,iBAA0B;AAClC,SAAO;AACR;AAOO,SAAS,mBAA4B;AAC3C,SAAO,MAAM;AAAA,IACZ;AAAA,IACA,MAAM,mBAAmB;AAAA,IACzB;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnimationOptions } from "../animate/types.js";
|
|
2
|
+
import { type MotionValue } from "../value/motion-value.js";
|
|
3
|
+
/**
|
|
4
|
+
* A value that springs towards `target` whenever it changes: a number from
|
|
5
|
+
* props, or another motion value it follows. A new target mid-flight keeps
|
|
6
|
+
* the speed the value has.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useSpring(target: number | MotionValue<number>, options?: AnimationOptions): MotionValue<number>;
|
|
9
|
+
//# sourceMappingURL=use-spring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-spring.d.ts","sourceRoot":"","sources":["../../src/react/use-spring.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,SAAS,CACxB,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,EACpC,OAAO,GAAE,gBAAqB,GAC5B,WAAW,CAAC,MAAM,CAAC,CAoBrB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { animate } from "../animate/animate.js";
|
|
3
|
+
import { useMotionValue } from "./use-motion-value.js";
|
|
4
|
+
import { isMotionValue } from "../value/motion-value.js";
|
|
5
|
+
function useSpring(target, options = {}) {
|
|
6
|
+
const value = useMotionValue(
|
|
7
|
+
isMotionValue(target) ? target.get() : target
|
|
8
|
+
);
|
|
9
|
+
const optionsRef = React.useRef(options);
|
|
10
|
+
optionsRef.current = options;
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
function follow(next) {
|
|
13
|
+
animate(value, next, { ...optionsRef.current, type: "spring" });
|
|
14
|
+
}
|
|
15
|
+
if (!isMotionValue(target)) {
|
|
16
|
+
if (value.get() !== target) follow(target);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const source = target;
|
|
20
|
+
return source.on("change", follow);
|
|
21
|
+
}, [target, value]);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
useSpring
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=use-spring.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/react/use-spring.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from \"react\";\nimport { animate } from \"#/animate/animate.ts\";\nimport type { AnimationOptions } from \"#/animate/types.ts\";\nimport { useMotionValue } from \"#/react/use-motion-value.ts\";\nimport { isMotionValue, type MotionValue } from \"#/value/motion-value.ts\";\n\n/**\n * A value that springs towards `target` whenever it changes: a number from\n * props, or another motion value it follows. A new target mid-flight keeps\n * the speed the value has.\n */\nexport function useSpring(\n\ttarget: number | MotionValue<number>,\n\toptions: AnimationOptions = {},\n): MotionValue<number> {\n\tconst value = useMotionValue(\n\t\tisMotionValue(target) ? (target as MotionValue<number>).get() : target,\n\t);\n\tconst optionsRef = React.useRef(options);\n\toptionsRef.current = options;\n\n\tReact.useEffect(() => {\n\t\tfunction follow(next: number) {\n\t\t\tanimate(value, next, { ...optionsRef.current, type: \"spring\" });\n\t\t}\n\t\tif (!isMotionValue(target)) {\n\t\t\tif (value.get() !== target) follow(target);\n\t\t\treturn;\n\t\t}\n\t\tconst source = target as MotionValue<number>;\n\t\treturn source.on(\"change\", follow);\n\t}, [target, value]);\n\n\treturn value;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AACvB,SAAS,eAAe;AAExB,SAAS,sBAAsB;AAC/B,SAAS,qBAAuC;AAOzC,SAAS,UACf,QACA,UAA4B,CAAC,GACP;AACtB,QAAM,QAAQ;AAAA,IACb,cAAc,MAAM,IAAK,OAA+B,IAAI,IAAI;AAAA,EACjE;AACA,QAAM,aAAa,MAAM,OAAO,OAAO;AACvC,aAAW,UAAU;AAErB,QAAM,UAAU,MAAM;AACrB,aAAS,OAAO,MAAc;AAC7B,cAAQ,OAAO,MAAM,EAAE,GAAG,WAAW,SAAS,MAAM,SAAS,CAAC;AAAA,IAC/D;AACA,QAAI,CAAC,cAAc,MAAM,GAAG;AAC3B,UAAI,MAAM,IAAI,MAAM,OAAQ,QAAO,MAAM;AACzC;AAAA,IACD;AACA,UAAM,SAAS;AACf,WAAO,OAAO,GAAG,UAAU,MAAM;AAAA,EAClC,GAAG,CAAC,QAAQ,KAAK,CAAC;AAElB,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type InterpolateOptions } from "../interpolate/interpolate.js";
|
|
2
|
+
import { type MotionValue } from "../value/motion-value.js";
|
|
3
|
+
/**
|
|
4
|
+
* A motion value derived from others: mapped from an input range to an
|
|
5
|
+
* output range, or computed by a function. It updates with its sources,
|
|
6
|
+
* without re-rendering the component.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useTransform<T>(source: MotionValue<number>, input: readonly number[], output: readonly T[], options?: InterpolateOptions<T>): MotionValue<T>;
|
|
9
|
+
export declare function useTransform<S, T>(source: MotionValue<S>, compute: (value: S) => T): MotionValue<T>;
|
|
10
|
+
export declare function useTransform<V extends readonly unknown[], T>(sources: {
|
|
11
|
+
readonly [K in keyof V]: MotionValue<V[K]>;
|
|
12
|
+
}, compute: (...values: V) => T): MotionValue<T>;
|
|
13
|
+
//# sourceMappingURL=use-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-transform.d.ts","sourceRoot":"","sources":["../../src/react/use-transform.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,kBAAkB,EAEvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,WAAW,EAAe,MAAM,yBAAyB,CAAC;AAExE;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC7B,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAC3B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,MAAM,EAAE,SAAS,CAAC,EAAE,EACpB,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC7B,WAAW,CAAC,CAAC,CAAC,CAAC;AAClB,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAChC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GACtB,WAAW,CAAC,CAAC,CAAC,CAAC;AAClB,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,CAAC,EAC3D,OAAO,EAAE;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,EACvD,OAAO,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,GAC1B,WAAW,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
interpolate
|
|
4
|
+
} from "../interpolate/interpolate.js";
|
|
5
|
+
import { motionValue } from "../value/motion-value.js";
|
|
6
|
+
function useTransform(...args) {
|
|
7
|
+
const [source, second, output, options] = args;
|
|
8
|
+
const sources = Array.isArray(source) ? source : [source];
|
|
9
|
+
const ranges = typeof second === "function" ? "" : JSON.stringify([second, output]);
|
|
10
|
+
const map = React.useMemo(
|
|
11
|
+
() => typeof second === "function" ? void 0 : interpolate(
|
|
12
|
+
second,
|
|
13
|
+
output,
|
|
14
|
+
options
|
|
15
|
+
),
|
|
16
|
+
[ranges]
|
|
17
|
+
);
|
|
18
|
+
const compute = map ?? second;
|
|
19
|
+
const latest = React.useRef(compute);
|
|
20
|
+
latest.current = compute;
|
|
21
|
+
function read() {
|
|
22
|
+
return latest.current(...sources.map((one) => one.get()));
|
|
23
|
+
}
|
|
24
|
+
const derived = React.useMemo(() => motionValue(read()), sources);
|
|
25
|
+
const computed = React.useRef(compute);
|
|
26
|
+
if (computed.current !== compute) {
|
|
27
|
+
computed.current = compute;
|
|
28
|
+
derived.set(read());
|
|
29
|
+
}
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
derived.set(read());
|
|
32
|
+
const unsubscribes = sources.map(
|
|
33
|
+
(one) => one.on("change", () => derived.set(read()))
|
|
34
|
+
);
|
|
35
|
+
return () => {
|
|
36
|
+
for (const unsubscribe of unsubscribes) unsubscribe();
|
|
37
|
+
};
|
|
38
|
+
}, [derived]);
|
|
39
|
+
return derived;
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
useTransform
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=use-transform.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/react/use-transform.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from \"react\";\nimport {\n\ttype InterpolateOptions,\n\tinterpolate,\n} from \"#/interpolate/interpolate.ts\";\nimport { type MotionValue, motionValue } from \"#/value/motion-value.ts\";\n\n/**\n * A motion value derived from others: mapped from an input range to an\n * output range, or computed by a function. It updates with its sources,\n * without re-rendering the component.\n */\nexport function useTransform<T>(\n\tsource: MotionValue<number>,\n\tinput: readonly number[],\n\toutput: readonly T[],\n\toptions?: InterpolateOptions<T>,\n): MotionValue<T>;\nexport function useTransform<S, T>(\n\tsource: MotionValue<S>,\n\tcompute: (value: S) => T,\n): MotionValue<T>;\nexport function useTransform<V extends readonly unknown[], T>(\n\tsources: { readonly [K in keyof V]: MotionValue<V[K]> },\n\tcompute: (...values: V) => T,\n): MotionValue<T>;\nexport function useTransform(...args: unknown[]): MotionValue<unknown> {\n\tconst [source, second, output, options] = args;\n\tconst sources = (\n\t\tArray.isArray(source) ? source : [source]\n\t) as MotionValue<unknown>[];\n\t// Ranges are usually inline arrays: rebuild the mapping when their contents change, not their identity.\n\tconst ranges =\n\t\ttypeof second === \"function\" ? \"\" : JSON.stringify([second, output]);\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: keyed on the ranges' contents.\n\tconst map = React.useMemo(\n\t\t() =>\n\t\t\ttypeof second === \"function\"\n\t\t\t\t? undefined\n\t\t\t\t: interpolate(\n\t\t\t\t\t\tsecond as readonly number[],\n\t\t\t\t\t\toutput as readonly unknown[],\n\t\t\t\t\t\toptions as InterpolateOptions<unknown>,\n\t\t\t\t\t),\n\t\t[ranges],\n\t);\n\tconst compute = (map ?? second) as (...values: unknown[]) => unknown;\n\tconst latest = React.useRef(compute);\n\tlatest.current = compute;\n\tfunction read(): unknown {\n\t\treturn latest.current(...sources.map((one) => one.get()));\n\t}\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: rebuilt only when a source changes.\n\tconst derived = React.useMemo(() => motionValue(read()), sources);\n\t// Rendered with new ranges or a new function: the value follows at once.\n\tconst computed = React.useRef(compute);\n\tif (computed.current !== compute) {\n\t\tcomputed.current = compute;\n\t\tderived.set(read());\n\t}\n\t// Subscribed in an effect, so StrictMode's unmount and remount leave it listening.\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: the sources are the identity of `derived`.\n\tReact.useEffect(() => {\n\t\tderived.set(read());\n\t\tconst unsubscribes = sources.map((one) =>\n\t\t\tone.on(\"change\", () => derived.set(read())),\n\t\t);\n\t\treturn () => {\n\t\t\tfor (const unsubscribe of unsubscribes) unsubscribe();\n\t\t};\n\t}, [derived]);\n\treturn derived;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AACvB;AAAA,EAEC;AAAA,OACM;AACP,SAA2B,mBAAmB;AAqBvC,SAAS,gBAAgB,MAAuC;AACtE,QAAM,CAAC,QAAQ,QAAQ,QAAQ,OAAO,IAAI;AAC1C,QAAM,UACL,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AAGzC,QAAM,SACL,OAAO,WAAW,aAAa,KAAK,KAAK,UAAU,CAAC,QAAQ,MAAM,CAAC;AAEpE,QAAM,MAAM,MAAM;AAAA,IACjB,MACC,OAAO,WAAW,aACf,SACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACH,CAAC,MAAM;AAAA,EACR;AACA,QAAM,UAAW,OAAO;AACxB,QAAM,SAAS,MAAM,OAAO,OAAO;AACnC,SAAO,UAAU;AACjB,WAAS,OAAgB;AACxB,WAAO,OAAO,QAAQ,GAAG,QAAQ,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC;AAAA,EACzD;AAEA,QAAM,UAAU,MAAM,QAAQ,MAAM,YAAY,KAAK,CAAC,GAAG,OAAO;AAEhE,QAAM,WAAW,MAAM,OAAO,OAAO;AACrC,MAAI,SAAS,YAAY,SAAS;AACjC,aAAS,UAAU;AACnB,YAAQ,IAAI,KAAK,CAAC;AAAA,EACnB;AAGA,QAAM,UAAU,MAAM;AACrB,YAAQ,IAAI,KAAK,CAAC;AAClB,UAAM,eAAe,QAAQ;AAAA,MAAI,CAAC,QACjC,IAAI,GAAG,UAAU,MAAM,QAAQ,IAAI,KAAK,CAAC,CAAC;AAAA,IAC3C;AACA,WAAO,MAAM;AACZ,iBAAW,eAAe,aAAc,aAAY;AAAA,IACrD;AAAA,EACD,GAAG,CAAC,OAAO,CAAC;AACZ,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AnimationControls, AnimationOptions, DOMKeyframes, ElementTarget, Keyframes } from "../animate/types.js";
|
|
2
|
+
import type { MotionValue } from "../value/motion-value.js";
|
|
3
|
+
/**
|
|
4
|
+
* When a segment starts: seconds from the start of the sequence, `"+0.1"` or
|
|
5
|
+
* `"-0.2"` from the end of the segment before, `"<"` with the segment before,
|
|
6
|
+
* or the name of a label.
|
|
7
|
+
*/
|
|
8
|
+
export type SequenceAt = number | `+${number}` | `-${number}` | "<" | string;
|
|
9
|
+
export interface SegmentOptions extends AnimationOptions {
|
|
10
|
+
readonly at?: SequenceAt;
|
|
11
|
+
}
|
|
12
|
+
export type Segment = readonly [ElementTarget, DOMKeyframes, SegmentOptions?] | readonly [MotionValue<any>, Keyframes<any>, SegmentOptions?] | string | {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly at?: SequenceAt;
|
|
15
|
+
};
|
|
16
|
+
export type AnimateOne = (target: unknown, keyframes: unknown, options: AnimationOptions) => AnimationControls;
|
|
17
|
+
export type ResolveTargets = (target: unknown) => readonly object[];
|
|
18
|
+
/**
|
|
19
|
+
* Launches every segment at once, each delayed to its place on the
|
|
20
|
+
* timeline, so the whole sequence shares one clock and can be scrubbed. A
|
|
21
|
+
* segment that animates a property an earlier segment already animates
|
|
22
|
+
* waits for that one to finish, then starts from where it left off.
|
|
23
|
+
*/
|
|
24
|
+
export declare function animateSequence(segments: readonly Segment[], options: AnimationOptions, animateOne: AnimateOne, resolveTargets: ResolveTargets): AnimationControls;
|
|
25
|
+
//# sourceMappingURL=sequence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../src/sequence/sequence.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,SAAS,EACT,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,GAAG,GAAG,MAAM,CAAC;AAE7E,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACvD,QAAQ,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,MAAM,MAAM,OAAO,GAChB,SAAS,CAAC,aAAa,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC,GAEvD,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,CAAC,GAC5D,MAAM,GACN;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,UAAU,CAAA;CAAE,CAAC;AAEvD,MAAM,MAAM,UAAU,GAAG,CACxB,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,gBAAgB,KACrB,iBAAiB,CAAC;AAEvB,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,SAAS,MAAM,EAAE,CAAC;AAepE;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,GAC5B,iBAAiB,CAmEnB"}
|