motion-dom 14.1.1 → 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.
Files changed (51) hide show
  1. package/dist/cjs/index.js +1205 -181
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/AsyncMotionValueAnimation.mjs +19 -1
  4. package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
  5. package/dist/es/animation/JSAnimation.mjs +54 -24
  6. package/dist/es/animation/JSAnimation.mjs.map +1 -1
  7. package/dist/es/animation/NativeAnimationExtended.mjs +47 -20
  8. package/dist/es/animation/NativeAnimationExtended.mjs.map +1 -1
  9. package/dist/es/animation/interfaces/motion-value.mjs +1 -0
  10. package/dist/es/animation/interfaces/motion-value.mjs.map +1 -1
  11. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +25 -1
  12. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
  13. package/dist/es/animation/waapi/supports/waapi.mjs +1 -1
  14. package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
  15. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +854 -0
  16. package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -0
  17. package/dist/es/animation/waapi/transforms/groups.mjs +4 -0
  18. package/dist/es/animation/waapi/transforms/groups.mjs.map +1 -0
  19. package/dist/es/effects/style/index.mjs +6 -3
  20. package/dist/es/effects/style/index.mjs.map +1 -1
  21. package/dist/es/effects/style/transform.mjs +2 -7
  22. package/dist/es/effects/style/transform.mjs.map +1 -1
  23. package/dist/es/index.mjs +3 -3
  24. package/dist/es/projection/node/create-projection-node.mjs +10 -0
  25. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  26. package/dist/es/render/VisualElement.mjs +16 -3
  27. package/dist/es/render/VisualElement.mjs.map +1 -1
  28. package/dist/es/render/dom/parse-transform.mjs +4 -2
  29. package/dist/es/render/dom/parse-transform.mjs.map +1 -1
  30. package/dist/es/render/html/utils/build-transform.mjs +1 -1
  31. package/dist/es/render/html/utils/build-transform.mjs.map +1 -1
  32. package/dist/es/render/svg/utils/scrape-motion-values.mjs +7 -2
  33. package/dist/es/render/svg/utils/scrape-motion-values.mjs.map +1 -1
  34. package/dist/es/render/utils/keys-transform.mjs +1 -0
  35. package/dist/es/render/utils/keys-transform.mjs.map +1 -1
  36. package/dist/es/utils/stagger.mjs +39 -6
  37. package/dist/es/utils/stagger.mjs.map +1 -1
  38. package/dist/es/value/index.mjs +12 -0
  39. package/dist/es/value/index.mjs.map +1 -1
  40. package/dist/es/value/types/complex/index.mjs +3 -2
  41. package/dist/es/value/types/complex/index.mjs.map +1 -1
  42. package/dist/es/value/utils/follow.mjs +19 -2
  43. package/dist/es/value/utils/follow.mjs.map +1 -1
  44. package/dist/index.d.ts +84 -14
  45. package/dist/motion-dom.dev.js +1205 -181
  46. package/dist/motion-dom.js +1 -1
  47. package/dist/size-rollup-motion-value.js +1 -1
  48. package/dist/size-rollup-motion-value.js.map +1 -1
  49. package/dist/size-rollup-style-effect.js +1 -1
  50. package/dist/size-rollup-style-effect.js.map +1 -1
  51. package/package.json +2 -2
package/dist/cjs/index.js CHANGED
@@ -249,8 +249,9 @@ const COLOR_TOKEN = "color";
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
@@ -1599,6 +1600,7 @@ class WithPromise {
1599
1600
  }
1600
1601
 
1601
1602
  const percentToProgress = (percent) => percent / 100;
1603
+ const round = (value) => Math.round(value * 10000) / 10000;
1602
1604
  class JSAnimation extends WithPromise {
1603
1605
  constructor(options) {
1604
1606
  super();
@@ -1707,10 +1709,10 @@ class JSAnimation extends WithPromise {
1707
1709
  }
1708
1710
  }
1709
1711
  tick(timestamp, sample = false) {
1710
- const { generator, totalDuration, mixKeyframes, mirroredGenerator, resolvedDuration, calculatedDuration, } = this;
1712
+ const { generator, totalDuration, calculatedDuration } = this;
1711
1713
  if (this.startTime === null)
1712
1714
  return generator.next(0);
1713
- const { delay = 0, keyframes, repeat, repeatType, repeatDelay, type, onUpdate, finalKeyframe, } = this.options;
1715
+ const { delay = 0, keyframes, type, onUpdate, finalKeyframe, } = this.options;
1714
1716
  if (this.startTime === this.pendingStartTime) {
1715
1717
  this.startTime = resolveStartTime(this.startTime, timestamp);
1716
1718
  }
@@ -1743,7 +1745,55 @@ class JSAnimation extends WithPromise {
1743
1745
  if (this.state === "finished" && this.holdTime === null) {
1744
1746
  this.currentTime = totalDuration;
1745
1747
  }
1746
- let elapsed = this.currentTime;
1748
+ const state = this.generate(this.currentTime, isInDelayPhase);
1749
+ let { done } = state;
1750
+ if (!isInDelayPhase && calculatedDuration !== null) {
1751
+ done =
1752
+ this.playbackSpeed >= 0
1753
+ ? this.currentTime >= totalDuration
1754
+ : this.currentTime <= 0;
1755
+ }
1756
+ const isAnimationFinished = this.holdTime === null &&
1757
+ (this.state === "finished" || (this.state === "running" && done));
1758
+ // TODO: The exception for inertia could be cleaner here
1759
+ if (isAnimationFinished && type !== inertia) {
1760
+ state.value = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
1761
+ }
1762
+ if (onUpdate) {
1763
+ onUpdate(state.value);
1764
+ }
1765
+ if (isAnimationFinished) {
1766
+ this.finish();
1767
+ }
1768
+ return state;
1769
+ }
1770
+ /**
1771
+ * This animation's time, including delay, at a timestamp.
1772
+ */
1773
+ at(timestamp) {
1774
+ return (this.holdTime ??
1775
+ round((timestamp - this.startTime) * this.playbackSpeed));
1776
+ }
1777
+ /**
1778
+ * The value at a timestamp, without changing this animation's state.
1779
+ * If resolved, it ends at the last resolved keyframe, which is in the
1780
+ * same unit as the others, rather than at finalKeyframe.
1781
+ */
1782
+ sampleAt(timestamp, resolved) {
1783
+ const { options, totalDuration } = this;
1784
+ const t = this.at(timestamp) - (options.delay || 0);
1785
+ return t >= totalDuration && options.type !== inertia
1786
+ ? getFinalKeyframe(options.keyframes, options, resolved ? undefined : options.finalKeyframe)
1787
+ : this.generate(Math.max(t, 0), t < 0).value;
1788
+ }
1789
+ /**
1790
+ * The generator's state `currentTime` ms after the delay, without
1791
+ * changing the animation's own state.
1792
+ */
1793
+ generate(currentTime, isInDelayPhase) {
1794
+ const { generator, totalDuration, mixKeyframes, mirroredGenerator, resolvedDuration, } = this;
1795
+ const { keyframes, repeat, repeatType, repeatDelay } = this.options;
1796
+ let elapsed = currentTime;
1747
1797
  let frameGenerator = generator;
1748
1798
  if (repeat) {
1749
1799
  /**
@@ -1751,7 +1801,7 @@ class JSAnimation extends WithPromise {
1751
1801
  * than duration we'll get values like 2.5 (midway through the
1752
1802
  * third iteration)
1753
1803
  */
1754
- const progress = Math.min(this.currentTime, totalDuration) / resolvedDuration;
1804
+ const progress = Math.min(currentTime, totalDuration) / resolvedDuration;
1755
1805
  /**
1756
1806
  * Get the current iteration (0 indexed). For instance the floor of
1757
1807
  * 2.5 is 2.
@@ -1804,25 +1854,6 @@ class JSAnimation extends WithPromise {
1804
1854
  if (mixKeyframes && !isInDelayPhase) {
1805
1855
  state.value = mixKeyframes(state.value);
1806
1856
  }
1807
- let { done } = state;
1808
- if (!isInDelayPhase && calculatedDuration !== null) {
1809
- done =
1810
- this.playbackSpeed >= 0
1811
- ? this.currentTime >= totalDuration
1812
- : this.currentTime <= 0;
1813
- }
1814
- const isAnimationFinished = this.holdTime === null &&
1815
- (this.state === "finished" || (this.state === "running" && done));
1816
- // TODO: The exception for inertia could be cleaner here
1817
- if (isAnimationFinished && type !== inertia) {
1818
- state.value = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
1819
- }
1820
- if (onUpdate) {
1821
- onUpdate(state.value);
1822
- }
1823
- if (isAnimationFinished) {
1824
- this.finish();
1825
- }
1826
1857
  return state;
1827
1858
  }
1828
1859
  /**
@@ -2163,6 +2194,7 @@ const matrix2dParsers = {
2163
2194
  translateY: 5,
2164
2195
  scaleX: 0,
2165
2196
  scaleY: 3,
2197
+ scaleZ: () => 1,
2166
2198
  scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,
2167
2199
  rotate,
2168
2200
  rotateZ: rotate,
@@ -2177,8 +2209,8 @@ const rebaseAngle = (angle) => {
2177
2209
  return angle;
2178
2210
  };
2179
2211
  const rotateZ = rotate;
2180
- const scaleX = (v) => Math.sqrt(v[0] * v[0] + v[1] * v[1]);
2181
- const scaleY = (v) => Math.sqrt(v[4] * v[4] + v[5] * v[5]);
2212
+ const scaleX = (v) => Math.hypot(v[0], v[1]);
2213
+ const scaleY = (v) => Math.hypot(v[4], v[5]);
2182
2214
  const matrix3dParsers = {
2183
2215
  x: 12,
2184
2216
  y: 13,
@@ -2188,6 +2220,7 @@ const matrix3dParsers = {
2188
2220
  translateZ: 14,
2189
2221
  scaleX,
2190
2222
  scaleY,
2223
+ scaleZ: (v) => Math.hypot(v[8], v[9], v[10]),
2191
2224
  scale: (v) => (scaleX(v) + scaleY(v)) / 2,
2192
2225
  rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),
2193
2226
  rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),
@@ -2247,6 +2280,7 @@ const transformPropOrder = [
2247
2280
  "scale",
2248
2281
  "scaleX",
2249
2282
  "scaleY",
2283
+ "scaleZ",
2250
2284
  "rotate",
2251
2285
  "rotateX",
2252
2286
  "rotateY",
@@ -2831,44 +2865,71 @@ class NativeAnimationExtended extends NativeAnimation {
2831
2865
  }
2832
2866
  this.options = options;
2833
2867
  }
2868
+ /**
2869
+ * The animation's time now, in ms. Wall-clock rather than WAAPI's
2870
+ * currentTime while running, as under CPU load currentTime may not
2871
+ * reflect the actual elapsed time, causing incorrect sampling and
2872
+ * visual jumps.
2873
+ */
2874
+ elapsed() {
2875
+ return this.state === "running"
2876
+ ? (time.now() - this.startTime) * this.speed
2877
+ : this.time * 1000;
2878
+ }
2879
+ /**
2880
+ * The value at a time, from a renderless JS animation.
2881
+ */
2882
+ sample(sampleTime) {
2883
+ if (!this.sampler) {
2884
+ const { motionValue, onUpdate, onComplete, onPlay, onStop, element, ...options } = this.options;
2885
+ /**
2886
+ * Stop it straight away so its driver doesn't run every frame.
2887
+ * It can still be sampled.
2888
+ */
2889
+ this.sampler = new JSAnimation({ ...options, autoplay: false });
2890
+ this.sampler.stop();
2891
+ }
2892
+ return this.sampler.sample(Math.max(0, sampleTime)).value;
2893
+ }
2894
+ /**
2895
+ * The value now, as WAAPI doesn't set the motion value while it runs.
2896
+ */
2897
+ liveValue() {
2898
+ const { state } = this;
2899
+ if (state === "running" || state === "paused") {
2900
+ return this.sample(this.elapsed());
2901
+ }
2902
+ }
2834
2903
  /**
2835
2904
  * WAAPI doesn't natively have any interruption capabilities.
2836
2905
  *
2837
2906
  * Rather than read committed styles back out of the DOM, we can
2838
- * create a renderless JS animation and sample it twice to calculate
2839
- * its current value, "previous" value, and therefore allow
2840
- * Motion to calculate velocity for any subsequent animation.
2907
+ * sample a renderless JS animation twice to calculate its current
2908
+ * value, "previous" value, and therefore allow Motion to calculate
2909
+ * velocity for any subsequent animation.
2841
2910
  */
2842
2911
  updateMotionValue(value) {
2843
- const { motionValue, onUpdate, onComplete, element, ...options } = this.options;
2912
+ const { motionValue, element, name } = this.options;
2844
2913
  if (!motionValue)
2845
2914
  return;
2846
2915
  if (value !== undefined) {
2847
2916
  motionValue.set(value);
2848
2917
  return;
2849
2918
  }
2850
- const sampleAnimation = new JSAnimation({
2851
- ...options,
2852
- autoplay: false,
2853
- });
2854
- /**
2855
- * Use wall-clock elapsed time for sampling.
2856
- * Under CPU load, WAAPI's currentTime may not reflect actual
2857
- * elapsed time, causing incorrect sampling and visual jumps.
2858
- */
2859
- const sampleTime = Math.max(sampleDelta, time.now() - this.startTime);
2860
- const delta = motionUtils.clamp(0, sampleDelta, sampleTime - sampleDelta);
2861
- const current = sampleAnimation.sample(sampleTime).value;
2919
+ const { speed } = this;
2920
+ const sampleTime = this.elapsed();
2921
+ const delta = this.state === "running" && speed
2922
+ ? motionUtils.clamp(0, sampleDelta, sampleTime)
2923
+ : 0;
2924
+ const current = this.sample(sampleTime);
2862
2925
  /**
2863
2926
  * Write the estimated value to inline style so it persists
2864
2927
  * after cancel(), covering the async gap before the next
2865
2928
  * animation starts.
2866
2929
  */
2867
- const { name } = this.options;
2868
2930
  if (element && name)
2869
2931
  setStyle(element, name, current);
2870
- motionValue.setWithVelocity(sampleAnimation.sample(Math.max(0, sampleTime - delta)).value, current, delta);
2871
- sampleAnimation.stop();
2932
+ motionValue.setWithVelocity(this.sample(sampleTime - delta * Math.sign(speed)), current, delta / Math.abs(speed || 1));
2872
2933
  }
2873
2934
  }
2874
2935
 
@@ -2982,44 +3043,953 @@ const supportsWaapi = /*@__PURE__*/ motionUtils.memo(() => Object.hasOwnProperty
2982
3043
  function supportsBrowserAnimation(options) {
2983
3044
  const { motionValue, name, repeatDelay, repeatType, damping, type, keyframes, } = options;
2984
3045
  /**
2985
- * Most values can't be accelerated at all, so check the name before
2986
- * looking at the element or its props.
3046
+ * Most values can't be accelerated at all, so check the name before
3047
+ * looking at the element or its props.
3048
+ */
3049
+ if (!name ||
3050
+ !(acceleratedValues.has(name) || colorProperties.has(name))) {
3051
+ return false;
3052
+ }
3053
+ const subject = motionValue?.owner?.current;
3054
+ /**
3055
+ * We use instanceof checks instead of isHTMLElement()/isSVGElement()
3056
+ * because we explicitly **don't** want elements in different timing
3057
+ * contexts (i.e. popups) to be accelerated, as it's not possible to sync
3058
+ * these animations properly with those driven from the main window
3059
+ * frameloop.
3060
+ */
3061
+ if (!(subject instanceof HTMLElement) &&
3062
+ !(subject instanceof SVGElement)) {
3063
+ return false;
3064
+ }
3065
+ const { onUpdate, transformTemplate } = motionValue.owner.getProps();
3066
+ return (supportsWaapi() &&
3067
+ /**
3068
+ * Force WAAPI for color properties with browser-only color formats
3069
+ * (oklch, oklab, lab, lch, etc.) that the JS animation path can't parse.
3070
+ */
3071
+ (acceleratedValues.has(name) ||
3072
+ (colorProperties.has(name) &&
3073
+ hasBrowserOnlyColors(keyframes))) &&
3074
+ (name !== "transform" || !transformTemplate) &&
3075
+ /**
3076
+ * If we're outputting values to onUpdate then we can't use WAAPI as there's
3077
+ * no way to read the value from WAAPI every frame.
3078
+ */
3079
+ !onUpdate &&
3080
+ !repeatDelay &&
3081
+ repeatType !== "mirror" &&
3082
+ damping !== 0 &&
3083
+ type !== "inertia");
3084
+ }
3085
+
3086
+ /**
3087
+ * Provided a value and a ValueType, returns the value as that value type.
3088
+ */
3089
+ const getValueAsType = (value, type) => {
3090
+ return type && typeof value === "number"
3091
+ ? type.transform(value)
3092
+ : value;
3093
+ };
3094
+
3095
+ const translateAlias = {
3096
+ x: "translateX",
3097
+ y: "translateY",
3098
+ z: "translateZ",
3099
+ transformPerspective: "perspective",
3100
+ };
3101
+ const numTransforms = transformPropOrder.length;
3102
+ /**
3103
+ * Build a CSS transform style from individual x/y/scale etc properties.
3104
+ *
3105
+ * This outputs with a default order of transforms/scales/rotations, this can be customised by
3106
+ * providing a transformTemplate function.
3107
+ */
3108
+ function buildTransform$1(latestValues, transform, transformTemplate) {
3109
+ // The transform string we're going to build into.
3110
+ let transformString = "";
3111
+ let transformIsDefault = true;
3112
+ /**
3113
+ * Loop over all possible transforms in order, adding the ones that
3114
+ * are present to the transform string.
3115
+ */
3116
+ for (let i = 0; i < numTransforms; i++) {
3117
+ const key = transformPropOrder[i];
3118
+ const value = latestValues[key];
3119
+ if (value === undefined)
3120
+ continue;
3121
+ let valueIsDefault = true;
3122
+ if (typeof value === "number") {
3123
+ valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
3124
+ }
3125
+ else {
3126
+ const parsed = parseFloat(value);
3127
+ valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
3128
+ }
3129
+ if (!valueIsDefault || transformTemplate) {
3130
+ const valueAsType = getValueAsType(value, numberValueTypes[key]);
3131
+ if (!valueIsDefault) {
3132
+ transformIsDefault = false;
3133
+ const transformName = translateAlias[key] || key;
3134
+ transformString += `${transformName}(${valueAsType}) `;
3135
+ }
3136
+ if (transformTemplate) {
3137
+ transform[key] = valueAsType;
3138
+ }
3139
+ }
3140
+ }
3141
+ // `pathRotation` composes onto `rotate` as a separate additive term so
3142
+ // the user's `rotate` is never clobbered. Deliberately not a slot in
3143
+ // `transformPropOrder`.
3144
+ const pathRotation = latestValues.pathRotation;
3145
+ if (pathRotation) {
3146
+ transformIsDefault = false;
3147
+ transformString += `rotate(${getValueAsType(pathRotation, numberValueTypes.pathRotation)}) `;
3148
+ }
3149
+ transformString = transformString.trim();
3150
+ // If we have a custom `transform` template, pass our transform values and
3151
+ // generated transformString to that before returning
3152
+ if (transformTemplate) {
3153
+ transformString = transformTemplate(transform, transformIsDefault ? "" : transformString);
3154
+ }
3155
+ else if (transformIsDefault) {
3156
+ transformString = "none";
3157
+ }
3158
+ return transformString;
3159
+ }
3160
+
3161
+ const transformGroups = new WeakMap();
3162
+
3163
+ /**
3164
+ * Sample at the interruption sampling rate, up to a cap for long
3165
+ * animations.
3166
+ */
3167
+ const maxSamples = 200;
3168
+ /**
3169
+ * How far values may stray from the WAAPI animation: as a fraction of
3170
+ * each value's change when they share an easing, otherwise in px or deg,
3171
+ * or for scale.
3172
+ */
3173
+ const easingTolerance = 0.001;
3174
+ const sampleTolerance = 0.1;
3175
+ const scaleTolerance = 0.001;
3176
+ /**
3177
+ * If an outside write, or a seek the WAAPI animation can't follow,
3178
+ * happens again within this window, the group is being driven every
3179
+ * frame (scrubbing, drag), which is cheaper on the main thread than
3180
+ * rebuilding the WAAPI animation every frame.
3181
+ */
3182
+ const churnWindow = 100;
3183
+ /**
3184
+ * Named easings that are the same cubic-bezier in JS and CSS.
3185
+ */
3186
+ const isNativeEasing = (ease) => /^(linear|ease(In|Out|InOut))$/.test(ease);
3187
+ const byTime = (a, b) => a - b;
3188
+ /**
3189
+ * n + 1 evenly spaced timestamps, from one timestamp to another.
3190
+ */
3191
+ const spread = (from, to, n) => {
3192
+ const result = [];
3193
+ for (let i = 0; i <= n; i++)
3194
+ result.push(mixNumber$1(from, to, i / n));
3195
+ return result;
3196
+ };
3197
+ const getOwner = (options) => options.motionValue.owner;
3198
+ const getGroup = (element) => transformGroups.get(element);
3199
+ const read = (owner, key) => owner.latestValues ? owner.latestValues[key] : owner.getValue(key)?.get();
3200
+ /**
3201
+ * Whether this animation should join its element's transform group.
3202
+ * Animations that can't be accelerated still join, so the group knows
3203
+ * to stay on the main thread while they run. Browsers without linear()
3204
+ * easing stay on the main thread.
3205
+ */
3206
+ const canGroupTransform = ({ name, motionValue, }) => name &&
3207
+ transformPropOrder.includes(name) &&
3208
+ motionValue?.owner?.current instanceof HTMLElement &&
3209
+ supportsWaapi() &&
3210
+ supportsLinearEasing();
3211
+ function canAccelerateTransform(options) {
3212
+ const owner = getOwner(options);
3213
+ const { onUpdate, transformTemplate } = owner.getProps();
3214
+ return (
3215
+ /**
3216
+ * A handoff from an optimised appear animation is already running
3217
+ * on its own WAAPI animation. onUpdate needs every value, every
3218
+ * frame.
3219
+ */
3220
+ !options.isHandoff &&
3221
+ !onUpdate &&
3222
+ !options.hasOnUpdate &&
3223
+ /**
3224
+ * transformTemplate could output anything.
3225
+ */
3226
+ !transformTemplate &&
3227
+ options.type !== "inertia" &&
3228
+ /**
3229
+ * A literal transform, or pathRotation, replaces or adds to the
3230
+ * transform we'd build. styleEffect builds its own as "none".
3231
+ */
3232
+ (read(owner, "transform") || "none") === "none" &&
3233
+ !read(owner, "pathRotation") &&
3234
+ /**
3235
+ * Layout animations write transform every frame.
3236
+ */
3237
+ !owner.projection?.isProjecting());
3238
+ }
3239
+ class TransformAnimation extends JSAnimation {
3240
+ constructor(options) {
3241
+ const element = getOwner(options).current;
3242
+ const { driver = frameloopDriver } = options;
3243
+ /**
3244
+ * Before JSAnimation replaces the type with its generator.
3245
+ */
3246
+ const canAccelerate = canAccelerateTransform(options);
3247
+ /**
3248
+ * The driver ticks on the main thread only once the group has
3249
+ * moved there. Until then, starting or stopping tells the group to
3250
+ * update its WAAPI animation.
3251
+ */
3252
+ options.driver = (update) => {
3253
+ const js = driver(update);
3254
+ return {
3255
+ js,
3256
+ now: js.now,
3257
+ start: (keepAlive = true) => {
3258
+ const group = getGroup(element);
3259
+ const isJS = !group || group.isJS;
3260
+ /**
3261
+ * keepAlive is false when seeking. Seeking the WAAPI
3262
+ * animation is free, but if a seek needs a rebuild and
3263
+ * keeps happening, the group moves to the main thread.
3264
+ */
3265
+ isJS
3266
+ ? js.start(keepAlive)
3267
+ : group.schedule(false, !keepAlive);
3268
+ },
3269
+ stop: () => {
3270
+ js.stop();
3271
+ const group = getGroup(element);
3272
+ group?.schedule(!group.isFinishing);
3273
+ },
3274
+ };
3275
+ };
3276
+ super(options);
3277
+ this.canAccelerate = canAccelerate;
3278
+ /**
3279
+ * stop is bound in JSAnimation, so wrap it rather than override.
3280
+ * Before stopping, set the motion value to where the WAAPI
3281
+ * animation is now, with velocity, for the next animation to
3282
+ * start from.
3283
+ */
3284
+ const { stop } = this;
3285
+ this.stop = () => {
3286
+ this.isAccelerated() && this.sync();
3287
+ stop();
3288
+ };
3289
+ }
3290
+ get group() {
3291
+ return getGroup(getOwner(this.options).current);
3292
+ }
3293
+ get js() {
3294
+ return this.driver?.js;
3295
+ }
3296
+ get name() {
3297
+ return this.options.name;
3298
+ }
3299
+ /**
3300
+ * When this stops moving, or, if it repeats forever, when it starts
3301
+ * repeating, and how long each repeat takes. Held (paused, or at
3302
+ * speed 0) animations never stop moving.
3303
+ */
3304
+ timing() {
3305
+ const { startTime, speed, totalDuration } = this;
3306
+ const { delay = 0, repeatType } = this.options;
3307
+ return this.holdTime !== null
3308
+ ? [Infinity, 0]
3309
+ : totalDuration === Infinity
3310
+ ? [
3311
+ startTime + delay / speed,
3312
+ (this.resolvedDuration * (repeatType === "loop" ? 1 : 2)) /
3313
+ speed || 1,
3314
+ ]
3315
+ : [startTime + (delay + totalDuration) / speed, 0];
3316
+ }
3317
+ /**
3318
+ * Whether this is running, or paused, on the compositor.
3319
+ */
3320
+ isAccelerated() {
3321
+ const { group, state } = this;
3322
+ return (group?.tracks.has(this) &&
3323
+ !group.isJS &&
3324
+ this.canAccelerate &&
3325
+ (state === "running" || state === "paused"));
3326
+ }
3327
+ /**
3328
+ * The value now, while this runs on the compositor and so doesn't
3329
+ * set its motion value every frame.
3330
+ */
3331
+ liveValue() {
3332
+ return this.isAccelerated() ? this.sampleAt(time.now()) : undefined;
3333
+ }
3334
+ /**
3335
+ * If this is a two-keyframe tween whose easing WAAPI runs exactly,
3336
+ * when it starts and stops moving, and that easing.
3337
+ */
3338
+ tween() {
3339
+ const { keyframes: keyframes$1, type, ease, times, repeat, delay = 0 } = this.options;
3340
+ const easing = motionUtils.isBezierDefinition(ease)
3341
+ ? cubicBezierAsString(ease)
3342
+ : isNativeEasing(ease) && supportedWaapiEasing[ease];
3343
+ if (easing &&
3344
+ !repeat &&
3345
+ !times &&
3346
+ keyframes$1.length === 2 &&
3347
+ type === keyframes &&
3348
+ this.holdTime === null) {
3349
+ const start = this.startTime + delay / this.speed;
3350
+ return [start, start + this.resolvedDuration / this.speed, easing];
3351
+ }
3352
+ }
3353
+ /**
3354
+ * The timestamps between two timestamps where this reaches a
3355
+ * keyframe or starts a repeat, where it can turn or jump.
3356
+ */
3357
+ boundaries(from, to) {
3358
+ const { startTime, speed, resolvedDuration, options } = this;
3359
+ const { delay = 0, repeat = 0, repeatDelay = 0, repeatType, times, keyframes: keyframes$1, type, } = options;
3360
+ const offsets = (type || keyframes) === keyframes
3361
+ ? times || defaultOffset(keyframes$1)
3362
+ : [0, 1];
3363
+ const start = startTime + delay / speed;
3364
+ const result = [];
3365
+ if (this.holdTime !== null || !(resolvedDuration > 0))
3366
+ return result;
3367
+ for (let i = Math.max(0, Math.floor(((from - start) * speed) / resolvedDuration)); i <= repeat; i++) {
3368
+ const iterationStart = start + (i * resolvedDuration) / speed;
3369
+ if (iterationStart > to)
3370
+ break;
3371
+ for (const offset of offsets) {
3372
+ const t = iterationStart +
3373
+ ((i % 2 && repeatType && repeatType !== "loop"
3374
+ ? 1 - offset
3375
+ : offset) *
3376
+ (resolvedDuration - repeatDelay)) /
3377
+ speed;
3378
+ t > from && t < to && result.push(t);
3379
+ }
3380
+ }
3381
+ return result;
3382
+ }
3383
+ /**
3384
+ * The value at a timestamp, as a number.
3385
+ */
3386
+ numberAt(timestamp) {
3387
+ return parseFloat(this.sampleAt(timestamp, true));
3388
+ }
3389
+ /**
3390
+ * Write the current value, and velocity, to the motion value.
3391
+ */
3392
+ sync() {
3393
+ const now = time.now();
3394
+ this.options.motionValue.setWithVelocity(this.sampleAt(now - sampleDelta, true), this.sampleAt(now, true), sampleDelta);
3395
+ }
3396
+ play() {
3397
+ /**
3398
+ * A stopped animation (one that was interrupted) can't play again,
3399
+ * so it mustn't join the group.
3400
+ */
3401
+ if (this.isStopped)
3402
+ return;
3403
+ (this.group || createGroup(getOwner(this.options))).tracks.add(this);
3404
+ super.play();
3405
+ }
3406
+ pause() {
3407
+ super.pause();
3408
+ if (this.isAccelerated()) {
3409
+ this.sync();
3410
+ this.group.schedule(false);
3411
+ }
3412
+ }
3413
+ /**
3414
+ * JSAnimation finishes on its next tick, which only happens on the
3415
+ * main thread, so finish now.
3416
+ */
3417
+ complete() {
3418
+ super.complete();
3419
+ const { group } = this;
3420
+ group && !group.isJS && this.canAccelerate && this.tick(time.now());
3421
+ }
3422
+ /**
3423
+ * Without a tick to rebase it, a held time still includes the delay,
3424
+ * so take it off here, as a JS animation does on its next tick.
3425
+ */
3426
+ get time() {
3427
+ if (this.isAccelerated()) {
3428
+ return motionUtils.millisecondsToSeconds(motionUtils.clamp(0, this.totalDuration, this.at(time.now()) - (this.options.delay || 0)));
3429
+ }
3430
+ return super.time;
3431
+ }
3432
+ set time(newTime) {
3433
+ super.time = newTime;
3434
+ }
3435
+ /**
3436
+ * Scroll timelines set time every frame, so run these on the main
3437
+ * thread.
3438
+ */
3439
+ attachTimeline(timeline) {
3440
+ this.canAccelerate = false;
3441
+ this.group?.demote(true);
3442
+ return super.attachTimeline(timeline);
3443
+ }
3444
+ }
3445
+ function createGroup(owner) {
3446
+ const element = owner.current;
3447
+ const tracks = new Set();
3448
+ const byKey = new Map();
3449
+ /**
3450
+ * Transforms that aren't animating, as built into the WAAPI animation.
3451
+ */
3452
+ let statics = {};
3453
+ /**
3454
+ * The transforms in the WAAPI animation, in order.
3455
+ */
3456
+ let keys = [];
3457
+ let built = new Map();
3458
+ let segments = [];
3459
+ let needsBuild = false;
3460
+ let isScheduled = false;
3461
+ let hasChurned = false;
3462
+ let lastChurn = -Infinity;
3463
+ const has = (key) => {
3464
+ for (const track of tracks)
3465
+ if (track.name === key)
3466
+ return true;
3467
+ };
3468
+ /**
3469
+ * The transform values at a timestamp or, without one, from the
3470
+ * motion values. Animations that don't repeat forever are sampled no
3471
+ * earlier than settled, so a loop that starts from an earlier cycle
3472
+ * boundary holds them at their end.
3473
+ */
3474
+ const valuesAt = (timestamp, settled) => {
3475
+ const values = {};
3476
+ for (const key of timestamp === undefined ? transformPropOrder : keys) {
3477
+ const track = byKey.get(key);
3478
+ const value = timestamp === undefined
3479
+ ? read(owner, key)
3480
+ : track
3481
+ ? track.sampleAt(settled > timestamp && !track.timing()[1]
3482
+ ? settled
3483
+ : timestamp)
3484
+ : statics[key];
3485
+ if (value !== undefined)
3486
+ values[key] = value;
3487
+ }
3488
+ return values;
3489
+ };
3490
+ /**
3491
+ * Build the transform at a timestamp. Unlike buildTransform, every key
3492
+ * is written, even at its default, so each keyframe has the same list
3493
+ * of functions and the browser interpolates them one by one.
3494
+ */
3495
+ const compose = (timestamp, settled) => {
3496
+ let transform = "";
3497
+ const values = valuesAt(timestamp, settled);
3498
+ for (const key in values) {
3499
+ transform +=
3500
+ (translateAlias[key] || key) +
3501
+ "(" +
3502
+ getValueAsType(values[key], numberValueTypes[key]) +
3503
+ ") ";
3504
+ }
3505
+ return transform || "none";
3506
+ };
3507
+ /**
3508
+ * Write the transform as an inline style, as the renderer would.
3509
+ */
3510
+ const commit = (values = valuesAt()) => {
3511
+ element.style.transform = buildTransform$1(values, {});
3512
+ };
3513
+ /**
3514
+ * Cancel the WAAPI animations, by default first committing the
3515
+ * transform. The renderer writes its own version on its next render.
3516
+ */
3517
+ const stop = (shouldCommit = true) => {
3518
+ shouldCommit && commit();
3519
+ segments.forEach(({ animation }) => animation.cancel());
3520
+ segments = [];
3521
+ };
3522
+ const add = (animation, offset, end = Infinity) => {
3523
+ const segment = { animation, offset, end };
3524
+ animation.startTime = time.now() + offset;
3525
+ /**
3526
+ * Animations finish when the WAAPI animation reaches their end.
3527
+ * Once a loop has taken over, the finished animation isn't needed.
3528
+ */
3529
+ if (end < Infinity) {
3530
+ animation.onfinish = () => {
3531
+ segment.isDone = true;
3532
+ if (segments.some((s) => s.end === Infinity)) {
3533
+ animation.cancel();
3534
+ segments = segments.filter((s) => s !== segment);
3535
+ }
3536
+ group.schedule(false);
3537
+ };
3538
+ }
3539
+ /**
3540
+ * Something else cancelled it, so carry on on the main thread.
3541
+ */
3542
+ animation.oncancel = () => segments.includes(segment) && group.demote();
3543
+ segments.push(segment);
3544
+ };
3545
+ /**
3546
+ * Where a value jumps between two timestamps, as when a repeat starts
3547
+ * again: the timestamps either side of the jump, or none if it moves
3548
+ * there continuously.
3549
+ */
3550
+ const jumpAt = (value, a, b) => {
3551
+ const change = (x, y) => Math.abs(value(y) - value(x));
3552
+ const size = change(a, b);
3553
+ while (b - a > 0.01) {
3554
+ const mid = (a + b) / 2;
3555
+ change(a, mid) > change(mid, b) ? (b = mid) : (a = mid);
3556
+ }
3557
+ return change(a, b) > size / 2 ? [a, b] : [];
3558
+ };
3559
+ /**
3560
+ * If every moving animation follows the same eased progress between
3561
+ * two timestamps, the easing that describes it.
3562
+ */
3563
+ const getEasing = (moving, from, to, bounds) => {
3564
+ const samples = Math.min(maxSamples, Math.max(2, Math.ceil((to - from) / sampleDelta)));
3565
+ /**
3566
+ * Too many keyframes or repeats to follow with this many samples.
3567
+ */
3568
+ if (bounds.length * 4 > samples)
3569
+ return;
3570
+ const at = spread(from, to, samples).concat(bounds).sort(byTime);
3571
+ const position = (t) => motionUtils.progress(from, to, t);
3572
+ let shared;
3573
+ let progressAt;
3574
+ for (const track of moving) {
3575
+ const values = at.map((t) => track.numberAt(t));
3576
+ const [first] = values;
3577
+ const range = values[values.length - 1] - first;
3578
+ const progress = values.map((value) => range ? (value - first) / range : value - first);
3579
+ /**
3580
+ * A value that doesn't change, like one still in its delay,
3581
+ * fits any easing. One that changes but ends where it started
3582
+ * fits none.
3583
+ */
3584
+ if (!range) {
3585
+ if (progress.some((p) => !(Math.abs(p) <= easingTolerance))) {
3586
+ return;
3587
+ }
3588
+ }
3589
+ else if (!shared) {
3590
+ shared = progress;
3591
+ progressAt = (t) => (track.numberAt(t) - first) / range;
3592
+ }
3593
+ else if (progress.some((p, i) => !(Math.abs(p - shared[i]) <= easingTolerance))) {
3594
+ return;
3595
+ }
3596
+ }
3597
+ if (!shared ||
3598
+ shared.every((p, i) => Math.abs(p - position(at[i])) <= easingTolerance)) {
3599
+ return "linear";
3600
+ }
3601
+ /**
3602
+ * A repeat that starts again jumps back, which takes two points at
3603
+ * the same position.
3604
+ */
3605
+ const points = [];
3606
+ const point = (t, p = progressAt(t)) => points.push(round(p) + " " + round(position(t) * 100) + "%");
3607
+ shared.forEach((p, i) => {
3608
+ i &&
3609
+ Math.abs(p - shared[i - 1]) > 0.2 &&
3610
+ jumpAt(progressAt, at[i - 1], at[i]).forEach((t) => point(t));
3611
+ point(at[i], p);
3612
+ });
3613
+ return "linear(" + points + ")";
3614
+ };
3615
+ /**
3616
+ * Sample timestamps between two timestamps, closer together where the
3617
+ * moving animations curve.
3618
+ */
3619
+ const sample = (moving, from, to, bounds) => {
3620
+ const times = [from];
3621
+ /**
3622
+ * Values that aren't numbers, like calc(), are left to the
3623
+ * browser to interpolate.
3624
+ */
3625
+ const isStraight = (a, b) => moving.every((track) => !(Math.abs(track.numberAt((a + b) / 2) -
3626
+ (track.numberAt(a) + track.numberAt(b)) / 2) >
3627
+ (track.name.startsWith("scale")
3628
+ ? scaleTolerance
3629
+ : sampleTolerance)));
3630
+ const split = (a, b, depth) => {
3631
+ if (b - a < 1 || isStraight(a, b)) {
3632
+ times.push(b);
3633
+ }
3634
+ else if (depth < 4) {
3635
+ split(a, (a + b) / 2, depth + 1);
3636
+ split((a + b) / 2, b, depth + 1);
3637
+ }
3638
+ else {
3639
+ /**
3640
+ * Keyframes either side of a jump, like a repeat starting
3641
+ * again, so it doesn't play as a quick sweep.
3642
+ */
3643
+ for (const track of moving) {
3644
+ times.push(...jumpAt((t) => track.numberAt(t), a, b));
3645
+ }
3646
+ times.push(b);
3647
+ }
3648
+ };
3649
+ /**
3650
+ * Split at least every 100ms, and at every keyframe and repeat,
3651
+ * either side of where a value can jump.
3652
+ */
3653
+ const ends = spread(from, to, Math.ceil((to - from) / 100));
3654
+ for (const t of bounds)
3655
+ ends.push(t, Math.min(t + 0.01, to));
3656
+ let start = from;
3657
+ for (const end of ends.sort(byTime)) {
3658
+ end > start && split(start, end, 0);
3659
+ start = end;
3660
+ }
3661
+ return times.sort(byTime);
3662
+ };
3663
+ /**
3664
+ * If every moving animation is the same tween, started together, as
3665
+ * happens for the values of one animate() call or transition, when
3666
+ * they move and their native easing.
3667
+ */
3668
+ const getTween = (moving) => {
3669
+ let shared;
3670
+ for (const track of moving) {
3671
+ const tween = track.tween();
3672
+ if (!tween ||
3673
+ shared?.some((v, i) => i < 2
3674
+ ? Math.abs(tween[i] - v) > 1
3675
+ : tween[i] !== v)) {
3676
+ return;
3677
+ }
3678
+ shared = tween;
3679
+ }
3680
+ return shared;
3681
+ };
3682
+ /**
3683
+ * A WAAPI animation of the composed transform between two timestamps.
2987
3684
  */
2988
- if (!name ||
2989
- !(acceleratedValues.has(name) || colorProperties.has(name))) {
2990
- return false;
2991
- }
2992
- const subject = motionValue?.owner?.current;
3685
+ const run = (moving, from, to, options = { fill: "both" }, settled, nativeEasing) => {
3686
+ const bounds = moving.flatMap((track) => track.boundaries(from, to));
3687
+ const easing = nativeEasing || getEasing(moving, from, to, bounds);
3688
+ const times = easing ? [from, to] : sample(moving, from, to, bounds);
3689
+ const transform = times.map((t) => compose(t, settled));
3690
+ let keyframes = { transform };
3691
+ if (!easing) {
3692
+ keyframes.offset = times.map((t) => motionUtils.progress(from, to, t));
3693
+ }
3694
+ /**
3695
+ * If nothing moves, don't hold a transform, which, even at its
3696
+ * default, would make the element a containing block. The empty
3697
+ * animation still finishes the animations.
3698
+ */
3699
+ if (transform.every((t) => t === transform[0])) {
3700
+ commit(valuesAt(from, settled));
3701
+ keyframes = null;
3702
+ }
3703
+ return element.animate(keyframes, {
3704
+ ...options,
3705
+ duration: to - from,
3706
+ easing: easing || "linear",
3707
+ });
3708
+ };
2993
3709
  /**
2994
- * We use instanceof checks instead of isHTMLElement()/isSVGElement()
2995
- * because we explicitly **don't** want elements in different timing
2996
- * contexts (i.e. popups) to be accelerated, as it's not possible to sync
2997
- * these animations properly with those driven from the main window
2998
- * frameloop.
3710
+ * Replace the WAAPI animations with ones built from now. Returns
3711
+ * undefined if the animations can't be composed.
2999
3712
  */
3000
- if (!(subject instanceof HTMLElement) &&
3001
- !(subject instanceof SVGElement)) {
3002
- return false;
3003
- }
3004
- const { onUpdate, transformTemplate } = motionValue.owner.getProps();
3005
- return (supportsWaapi() &&
3713
+ const animate = (now) => {
3006
3714
  /**
3007
- * Force WAAPI for color properties with browser-only color formats
3008
- * (oklch, oklab, lab, lch, etc.) that the JS animation path can't parse.
3715
+ * The finite part runs until the last finite animation (or the
3716
+ * last delay) ends. Infinitely repeating animations then continue
3717
+ * as one looping WAAPI animation, which needs them to share a
3718
+ * cycle.
3009
3719
  */
3010
- (acceleratedValues.has(name) ||
3011
- (colorProperties.has(name) &&
3012
- hasBrowserOnlyColors(keyframes))) &&
3013
- (name !== "transform" || !transformTemplate) &&
3720
+ let end = now;
3721
+ let cycle = 0;
3722
+ let cycleStart = 0;
3723
+ const moving = [];
3724
+ const looping = [];
3725
+ const ends = new Set();
3726
+ byKey.clear();
3727
+ built = new Map();
3728
+ for (const track of tracks) {
3729
+ byKey.set(track.name, track);
3730
+ const [trackEnd, trackCycle] = track.timing();
3731
+ const isHeld = trackEnd === Infinity;
3732
+ built.set(track, [track.at(now), track.speed, isHeld]);
3733
+ /**
3734
+ * Held animations don't move, so keep their motion values up
3735
+ * to date, as a JSAnimation would on a seek.
3736
+ */
3737
+ if (isHeld) {
3738
+ track.sync();
3739
+ continue;
3740
+ }
3741
+ if (track.speed < 0)
3742
+ return;
3743
+ if (trackCycle) {
3744
+ if (cycle) {
3745
+ const phase = (trackEnd - cycleStart) / trackCycle;
3746
+ if (Math.abs(trackCycle - cycle) > 1 ||
3747
+ Math.abs(phase - Math.round(phase)) * cycle > 1) {
3748
+ return;
3749
+ }
3750
+ }
3751
+ else {
3752
+ cycle = trackCycle;
3753
+ cycleStart = trackEnd;
3754
+ }
3755
+ looping.push(track);
3756
+ }
3757
+ else {
3758
+ ends.add(trackEnd);
3759
+ }
3760
+ moving.push(track);
3761
+ end = Math.max(end, trackEnd);
3762
+ }
3763
+ statics = {};
3014
3764
  /**
3015
- * If we're outputting values to onUpdate then we can't use WAAPI as there's
3016
- * no way to read the value from WAAPI every frame.
3765
+ * Transforms that aren't animating are left out at their default.
3017
3766
  */
3018
- !onUpdate &&
3019
- !repeatDelay &&
3020
- repeatType !== "mirror" &&
3021
- damping !== 0 &&
3022
- type !== "inertia");
3767
+ keys = transformPropOrder.filter((key) => {
3768
+ if (byKey.has(key))
3769
+ return true;
3770
+ const value = (statics[key] = read(owner, key));
3771
+ return (value !== undefined &&
3772
+ parseFloat(value) !==
3773
+ (key.startsWith("scale") ? 1 : 0));
3774
+ });
3775
+ stop(false);
3776
+ /**
3777
+ * Values that share one tween are one WAAPI animation of it, with
3778
+ * two keyframes and its own easing, from when they started.
3779
+ */
3780
+ const tween = !cycle && getTween(moving);
3781
+ try {
3782
+ if (tween && tween[1] > now) {
3783
+ const [from, to, easing] = tween;
3784
+ add(run(moving, from, to, undefined, undefined, easing), from - now, to - from);
3785
+ }
3786
+ else if (end > now) {
3787
+ add(run(moving, now, end), 0, end - now);
3788
+ /**
3789
+ * Animations that end sooner finish on the events of
3790
+ * empty animations that end with them.
3791
+ */
3792
+ ends.forEach((trackEnd) => trackEnd < end - 1 &&
3793
+ add(element.animate(null, {
3794
+ duration: trackEnd - now,
3795
+ }), 0, trackEnd - now));
3796
+ }
3797
+ if (cycle) {
3798
+ /**
3799
+ * Build one cycle from a cycle boundary, so it repeats
3800
+ * seamlessly, and start it part way through.
3801
+ */
3802
+ const from = cycleStart + Math.floor((end - cycleStart) / cycle) * cycle;
3803
+ add(run(looping, from, from + cycle, {
3804
+ iterations: Infinity,
3805
+ iterationStart: (end - from) / cycle,
3806
+ /**
3807
+ * It must not fill backwards over the finite part
3808
+ * that runs before it.
3809
+ */
3810
+ fill: "forwards",
3811
+ }, end), end - now);
3812
+ }
3813
+ }
3814
+ catch {
3815
+ return;
3816
+ }
3817
+ /**
3818
+ * Everything is held, so hold it with an inline style instead.
3819
+ */
3820
+ segments.length || stop();
3821
+ return true;
3822
+ };
3823
+ /**
3824
+ * If every animation has been paused, played, seeked or sped up
3825
+ * together since the WAAPI animation was built, do the same to it.
3826
+ * Returns false if it needs rebuilding instead.
3827
+ */
3828
+ const retime = (now) => {
3829
+ let elapsed;
3830
+ let rate = 0;
3831
+ for (const track of tracks) {
3832
+ const state = built.get(track);
3833
+ if (!state)
3834
+ return false;
3835
+ const [builtTime, builtSpeed, wasHeld] = state;
3836
+ const trackTime = track.at(now);
3837
+ const isHeld = track.timing()[0] === Infinity;
3838
+ if (wasHeld) {
3839
+ if (isHeld && trackTime === builtTime)
3840
+ continue;
3841
+ return false;
3842
+ }
3843
+ const trackElapsed = (trackTime - builtTime) / builtSpeed;
3844
+ const trackRate = isHeld ? 0 : track.speed / builtSpeed;
3845
+ if (elapsed === undefined) {
3846
+ elapsed = trackElapsed;
3847
+ rate = trackRate;
3848
+ }
3849
+ else if (Math.abs(trackElapsed - elapsed) > 1 ||
3850
+ trackRate !== rate) {
3851
+ return false;
3852
+ }
3853
+ }
3854
+ if (elapsed === undefined)
3855
+ return true;
3856
+ if (!segments.length)
3857
+ return false;
3858
+ for (const { offset, end, isDone } of segments) {
3859
+ const local = elapsed - offset;
3860
+ if (end < Infinity &&
3861
+ (isDone ? local < end - 1 : local < 0 || local >= end)) {
3862
+ return false;
3863
+ }
3864
+ }
3865
+ for (const { animation, offset, isDone } of segments) {
3866
+ if (isDone)
3867
+ continue;
3868
+ const local = elapsed - offset;
3869
+ if (rate) {
3870
+ animation.playbackRate = rate;
3871
+ animation.startTime = now - local / rate;
3872
+ }
3873
+ else {
3874
+ animation.pause();
3875
+ animation.currentTime = local;
3876
+ }
3877
+ }
3878
+ return true;
3879
+ };
3880
+ const build = () => {
3881
+ const now = time.now();
3882
+ /**
3883
+ * Finish the animations that have reached their end, which the
3884
+ * WAAPI animation has already rendered.
3885
+ */
3886
+ if (!group.isJS) {
3887
+ group.isFinishing = true;
3888
+ tracks.forEach((track) => {
3889
+ const [trackEnd, trackCycle] = track.timing();
3890
+ if (track.state === "running" &&
3891
+ track.speed > 0 &&
3892
+ !trackCycle &&
3893
+ trackEnd <= now + 1) {
3894
+ track.complete();
3895
+ /**
3896
+ * From now it's checked for outside writes like any
3897
+ * other static transform. If the WAAPI animation never
3898
+ * rendered it (it was instant), rebuild with its value.
3899
+ */
3900
+ statics[track.name] = read(owner, track.name);
3901
+ built.has(track) || (needsBuild = true);
3902
+ }
3903
+ });
3904
+ group.isFinishing = false;
3905
+ }
3906
+ isScheduled = false;
3907
+ tracks.forEach(({ state }, track) => {
3908
+ if (state === "idle" || state === "finished")
3909
+ tracks.delete(track);
3910
+ });
3911
+ if (!tracks.size) {
3912
+ transformGroups.delete(element);
3913
+ group.isJS || stop();
3914
+ return;
3915
+ }
3916
+ for (const track of tracks) {
3917
+ if (!track.canAccelerate)
3918
+ return group.demote(true);
3919
+ }
3920
+ /**
3921
+ * Everything that kept the group on the main thread has finished,
3922
+ * so move the remaining animations back to the compositor.
3923
+ */
3924
+ if (group.isJS) {
3925
+ group.isJS = false;
3926
+ needsBuild = true;
3927
+ tracks.forEach((track) => track.js?.stop());
3928
+ }
3929
+ const shouldBuild = needsBuild;
3930
+ const churned = hasChurned;
3931
+ needsBuild = hasChurned = false;
3932
+ if (shouldBuild || !retime(now)) {
3933
+ if (churned) {
3934
+ if (now - lastChurn < churnWindow)
3935
+ return group.demote();
3936
+ lastChurn = now;
3937
+ }
3938
+ if (!animate(now))
3939
+ return group.demote();
3940
+ }
3941
+ };
3942
+ const group = {
3943
+ tracks,
3944
+ isJS: false,
3945
+ isFinishing: false,
3946
+ schedule(build_, isChurn) {
3947
+ needsBuild || (needsBuild = build_);
3948
+ hasChurned || (hasChurned = !!isChurn);
3949
+ /**
3950
+ * Build in this frame's render step, so it's in place before
3951
+ * anything reads the DOM in postRender, or straight after the
3952
+ * current task outside of a frame.
3953
+ */
3954
+ if (!isScheduled) {
3955
+ isScheduled = true;
3956
+ frameData.isProcessing
3957
+ ? frame.render(build, false, true)
3958
+ : queueMicrotask(build);
3959
+ }
3960
+ },
3961
+ /**
3962
+ * An outside write. Rebuild once, but if it keeps happening, move
3963
+ * to the main thread.
3964
+ */
3965
+ check() {
3966
+ if (group.isJS)
3967
+ return;
3968
+ for (const key in statics) {
3969
+ if (read(owner, key) !== statics[key] && !has(key)) {
3970
+ return group.schedule(true, true);
3971
+ }
3972
+ }
3973
+ },
3974
+ demote(canReturn) {
3975
+ if (group.isJS)
3976
+ return;
3977
+ /**
3978
+ * Unless only another animation is holding the group on the
3979
+ * main thread, these animations stay there until they end.
3980
+ */
3981
+ tracks.forEach((track) => {
3982
+ track.isAccelerated() && track.sync();
3983
+ canReturn || (track.canAccelerate = false);
3984
+ });
3985
+ group.isJS = true;
3986
+ built = new Map();
3987
+ stop();
3988
+ tracks.forEach((track) => track.state === "running" && track.js?.start());
3989
+ },
3990
+ };
3991
+ transformGroups.set(element, group);
3992
+ return group;
3023
3993
  }
3024
3994
 
3025
3995
  class AsyncMotionValueAnimation extends WithPromise {
@@ -3091,6 +4061,11 @@ class AsyncMotionValueAnimation extends WithPromise {
3091
4061
  * values may not be valid CSS and would trigger browser warnings.
3092
4062
  */
3093
4063
  const useWaapi = canAnimateValue && !isHandoff && supportsBrowserAnimation(options);
4064
+ /**
4065
+ * Independent transforms (x, scale etc) on an HTML element are
4066
+ * composed into one WAAPI transform animation per element.
4067
+ */
4068
+ const isGroupedTransform = !useWaapi && canGroupTransform(options);
3094
4069
  /**
3095
4070
  * Resolve startTime for the animation. A startTime passed in options
3096
4071
  * (an optimised appear handoff syncing to its WAAPI animation) takes
@@ -3106,7 +4081,10 @@ class AsyncMotionValueAnimation extends WithPromise {
3106
4081
  * animation started in that moment stays in sync. WAAPI has no frame
3107
4082
  * of ours to do that on.
3108
4083
  */
3109
- if (sync && (useWaapi || this.resolvedAt !== this.createdAt)) {
4084
+ if (sync &&
4085
+ (useWaapi ||
4086
+ isGroupedTransform ||
4087
+ this.resolvedAt !== this.createdAt)) {
3110
4088
  options.startTime ?? (options.startTime = resolveStartTime(this.createdAt, this.resolvedAt));
3111
4089
  }
3112
4090
  let animation;
@@ -3124,6 +4102,9 @@ class AsyncMotionValueAnimation extends WithPromise {
3124
4102
  animation = new JSAnimation(options);
3125
4103
  }
3126
4104
  }
4105
+ else if (isGroupedTransform) {
4106
+ animation = new TransformAnimation(options);
4107
+ }
3127
4108
  else {
3128
4109
  animation = new JSAnimation(options);
3129
4110
  }
@@ -3139,6 +4120,12 @@ class AsyncMotionValueAnimation extends WithPromise {
3139
4120
  then(onResolve, _onReject) {
3140
4121
  return this.finished.finally(onResolve).then(() => { });
3141
4122
  }
4123
+ /**
4124
+ * The value now, if the animation runs on the compositor.
4125
+ */
4126
+ liveValue() {
4127
+ return this._animation?.liveValue?.();
4128
+ }
3142
4129
  get animation() {
3143
4130
  if (!this._animation) {
3144
4131
  this.keyframeResolver?.resume();
@@ -3576,6 +4563,18 @@ class MotionValue {
3576
4563
  if (collectMotionValues.current) {
3577
4564
  collectMotionValues.current.push(this);
3578
4565
  }
4566
+ /**
4567
+ * A value animating on the compositor isn't updated every frame,
4568
+ * so read it from its animation.
4569
+ */
4570
+ const sampled = this.animation?.liveValue?.();
4571
+ return sampled === undefined ? this.current : sampled;
4572
+ }
4573
+ /**
4574
+ * The value as last set. Unlike get(), this doesn't read an animation
4575
+ * running on the compositor, which renders the value itself.
4576
+ */
4577
+ getCurrent() {
3579
4578
  return this.current;
3580
4579
  }
3581
4580
  /**
@@ -3802,6 +4801,7 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
3802
4801
  name,
3803
4802
  motionValue: value,
3804
4803
  element: isHandoff ? undefined : element,
4804
+ hasOnUpdate: !!valueTransition.onUpdate,
3805
4805
  };
3806
4806
  /**
3807
4807
  * If there's no transition defined for this value, we can generate
@@ -4401,6 +5401,30 @@ class DOMKeyframesResolver extends KeyframeResolver {
4401
5401
  constructor(unresolvedKeyframes, onComplete, name, motionValue, element) {
4402
5402
  super(unresolvedKeyframes, onComplete, name, motionValue, element, true);
4403
5403
  }
5404
+ /**
5405
+ * Keyframes that don't need reading from the DOM, or measuring,
5406
+ * resolve straight away rather than in the frame loop's batched read.
5407
+ */
5408
+ scheduleResolve() {
5409
+ if (this.canReadNow()) {
5410
+ this.readKeyframes();
5411
+ if (!this.needsMeasurement)
5412
+ return this.complete();
5413
+ }
5414
+ super.scheduleResolve();
5415
+ }
5416
+ canReadNow() {
5417
+ const { unresolvedKeyframes, element, motionValue } = this;
5418
+ const origin = unresolvedKeyframes[0] ?? motionValue?.get();
5419
+ if (!element?.current || origin === undefined)
5420
+ return false;
5421
+ for (let i = 0; i < unresolvedKeyframes.length; i++) {
5422
+ if (containsCSSVariable(i ? unresolvedKeyframes[i] : origin)) {
5423
+ return false;
5424
+ }
5425
+ }
5426
+ return true;
5427
+ }
4404
5428
  readKeyframes() {
4405
5429
  const { unresolvedKeyframes, element, name } = this;
4406
5430
  if (!element || !element.current)
@@ -4744,15 +5768,6 @@ function isSVGElement(element) {
4744
5768
  return motionUtils.isObject(element) && "ownerSVGElement" in element;
4745
5769
  }
4746
5770
 
4747
- /**
4748
- * Provided a value and a ValueType, returns the value as that value type.
4749
- */
4750
- const getValueAsType = (value, type) => {
4751
- return type && typeof value === "number"
4752
- ? type.transform(value)
4753
- : value;
4754
- };
4755
-
4756
5771
  function resolveElements(elementOrSelector, scope, selectorCache) {
4757
5772
  if (elementOrSelector == null) {
4758
5773
  return [];
@@ -4926,18 +5941,12 @@ function createEffect(addValue, { step, ...options } = {}) {
4926
5941
  });
4927
5942
  }
4928
5943
 
4929
- const translateAlias$1 = {
4930
- x: "translateX",
4931
- y: "translateY",
4932
- z: "translateZ",
4933
- transformPerspective: "perspective",
4934
- };
4935
5944
  /**
4936
5945
  * Cache of `translateX(`-style openers so each render is a few string
4937
5946
  * concatenations rather than a template per transform.
4938
5947
  */
4939
5948
  const openers = {};
4940
- function buildTransform$1(state) {
5949
+ function buildTransform(state) {
4941
5950
  let transform = "";
4942
5951
  const { transformKeys: keys = [], transformValues: values = {} } = state;
4943
5952
  /**
@@ -4946,7 +5955,7 @@ function buildTransform$1(state) {
4946
5955
  */
4947
5956
  for (let i = 0; i < keys.length; i++) {
4948
5957
  const key = keys[i];
4949
- const value = values[key].get();
5958
+ const value = values[key].getCurrent();
4950
5959
  if (value === undefined)
4951
5960
  continue;
4952
5961
  const parsed = typeof value === "number" ? value : parseFloat(value);
@@ -4954,7 +5963,7 @@ function buildTransform$1(state) {
4954
5963
  transform +=
4955
5964
  (transform && " ") +
4956
5965
  (openers[key] ||
4957
- (openers[key] = (translateAlias$1[key] || key) + "(")) +
5966
+ (openers[key] = (translateAlias[key] || key) + "(")) +
4958
5967
  getValueAsType(value, transformValueTypes[key]) +
4959
5968
  ")";
4960
5969
  }
@@ -4997,7 +6006,8 @@ const addStyleValue = (element, state, key, value) => {
4997
6006
  addStyleValue(element, state, "transformBox", new MotionValue("fill-box"));
4998
6007
  }
4999
6008
  state.set("transform", new MotionValue("none"), () => {
5000
- element.style.transform = buildTransform$1(state);
6009
+ transformGroups.get(element)?.check();
6010
+ element.style.transform = buildTransform(state);
5001
6011
  });
5002
6012
  }
5003
6013
  computed = state.get("transform");
@@ -5015,12 +6025,12 @@ const addStyleValue = (element, state, key, value) => {
5015
6025
  }
5016
6026
  else if (isCSSVar(key)) {
5017
6027
  render = () => {
5018
- element.style.setProperty(key, value.get());
6028
+ element.style.setProperty(key, value.getCurrent());
5019
6029
  };
5020
6030
  }
5021
6031
  else {
5022
6032
  render = () => {
5023
- element.style[key] = getValueAsType(value.get(), numberValueTypes[key]);
6033
+ element.style[key] = getValueAsType(value.getCurrent(), numberValueTypes[key]);
5024
6034
  };
5025
6035
  }
5026
6036
  return state.set(key, value, render, computed);
@@ -5052,73 +6062,8 @@ const styleSubjectEffect = /*@__PURE__*/ createEffect(addStyleValue, {
5052
6062
  test: isStyleSubject,
5053
6063
  read: readStyleValue,
5054
6064
  });
5055
- const styleEffect = /*@__PURE__*/ createSelectorEffect(styleSubjectEffect);
5056
-
5057
- const translateAlias = {
5058
- x: "translateX",
5059
- y: "translateY",
5060
- z: "translateZ",
5061
- transformPerspective: "perspective",
5062
- };
5063
- const numTransforms = transformPropOrder.length;
5064
- /**
5065
- * Build a CSS transform style from individual x/y/scale etc properties.
5066
- *
5067
- * This outputs with a default order of transforms/scales/rotations, this can be customised by
5068
- * providing a transformTemplate function.
5069
- */
5070
- function buildTransform(latestValues, transform, transformTemplate) {
5071
- // The transform string we're going to build into.
5072
- let transformString = "";
5073
- let transformIsDefault = true;
5074
- /**
5075
- * Loop over all possible transforms in order, adding the ones that
5076
- * are present to the transform string.
5077
- */
5078
- for (let i = 0; i < numTransforms; i++) {
5079
- const key = transformPropOrder[i];
5080
- const value = latestValues[key];
5081
- if (value === undefined)
5082
- continue;
5083
- let valueIsDefault = true;
5084
- if (typeof value === "number") {
5085
- valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
5086
- }
5087
- else {
5088
- const parsed = parseFloat(value);
5089
- valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
5090
- }
5091
- if (!valueIsDefault || transformTemplate) {
5092
- const valueAsType = getValueAsType(value, numberValueTypes[key]);
5093
- if (!valueIsDefault) {
5094
- transformIsDefault = false;
5095
- const transformName = translateAlias[key] || key;
5096
- transformString += `${transformName}(${valueAsType}) `;
5097
- }
5098
- if (transformTemplate) {
5099
- transform[key] = valueAsType;
5100
- }
5101
- }
5102
- }
5103
- // `pathRotation` composes onto `rotate` as a separate additive term so
5104
- // the user's `rotate` is never clobbered. Deliberately not a slot in
5105
- // `transformPropOrder`.
5106
- const pathRotation = latestValues.pathRotation;
5107
- if (pathRotation) {
5108
- transformIsDefault = false;
5109
- transformString += `rotate(${getValueAsType(pathRotation, numberValueTypes.pathRotation)}) `;
5110
- }
5111
- transformString = transformString.trim();
5112
- // If we have a custom `transform` template, pass our transform values and
5113
- // generated transformString to that before returning
5114
- if (transformTemplate) {
5115
- transformString = transformTemplate(transform, transformIsDefault ? "" : transformString);
5116
- }
5117
- else if (transformIsDefault) {
5118
- transformString = "none";
5119
- }
5120
- return transformString;
5121
- }
6065
+ const styleEffect =
6066
+ /*@__PURE__*/ createSelectorEffect(styleSubjectEffect);
5122
6067
 
5123
6068
  function buildHTMLStyles(state, latestValues, transformTemplate) {
5124
6069
  const { style, vars, transformOrigin } = state;
@@ -5158,7 +6103,7 @@ function buildHTMLStyles(state, latestValues, transformTemplate) {
5158
6103
  }
5159
6104
  if (!latestValues.transform) {
5160
6105
  if (hasTransform || transformTemplate) {
5161
- style.transform = buildTransform(latestValues, state.transform, transformTemplate);
6106
+ style.transform = buildTransform$1(latestValues, state.transform, transformTemplate);
5162
6107
  }
5163
6108
  else if (style.transform) {
5164
6109
  /**
@@ -6120,13 +7065,46 @@ function getOriginIndex(from, total) {
6120
7065
  return from === "last" ? lastIndex : lastIndex / 2;
6121
7066
  }
6122
7067
  }
6123
- function stagger(duration = 0.1, { startDelay = 0, from = 0, ease } = {}) {
7068
+ function stagger(duration = 0.1, { startDelay = 0, from = 0, ease, grid } = {}) {
7069
+ /**
7070
+ * Distances from the origin for each element count. The final entry
7071
+ * holds the distance used to normalise easing.
7072
+ */
7073
+ const cache = {};
6124
7074
  return (i, total) => {
6125
- const fromIndex = typeof from === "number" ? from : getOriginIndex(from, total);
6126
- const distance = Math.abs(fromIndex - i);
6127
- let delay = duration * distance;
6128
- if (ease) {
6129
- const maxDelay = total * duration;
7075
+ let distances = cache[total];
7076
+ if (!distances) {
7077
+ const [columns, rows] = grid || [Infinity, 1];
7078
+ const lastX = Math.min(columns, total) - 1;
7079
+ const lastY = Math.max(rows, Math.ceil(total / columns)) - 1;
7080
+ const isIndex = typeof from === "number";
7081
+ const scale = from === "first" ? 0 : from === "last" ? 1 : 0.5;
7082
+ const originX = isIndex ? from % columns : lastX * scale;
7083
+ const originY = isIndex ? Math.floor(from / columns) : lastY * scale;
7084
+ distances = cache[total] = [];
7085
+ for (let j = 0; j < total; j++) {
7086
+ const x = j % columns;
7087
+ const y = Math.floor(j / columns);
7088
+ const edgeX = Math.min(x, lastX - x);
7089
+ const edgeY = Math.min(y, lastY - y);
7090
+ if (from === "random") {
7091
+ // Inside-out shuffle, so each element gets a distinct step
7092
+ const k = (Math.random() * (j + 1)) | 0;
7093
+ distances[j] = distances[k];
7094
+ distances[k] = j;
7095
+ }
7096
+ else {
7097
+ distances[j] =
7098
+ from === "edges"
7099
+ ? Math.min(lastX ? edgeX : edgeY, lastY ? edgeY : edgeX)
7100
+ : Math.hypot(x - originX, y - originY);
7101
+ }
7102
+ }
7103
+ distances.push(grid ? Math.max(...distances) : total);
7104
+ }
7105
+ let delay = duration * distances[i];
7106
+ const maxDelay = duration * distances[total];
7107
+ if (ease && maxDelay) {
6130
7108
  const easingFunction = motionUtils.easingDefinitionToFunction(ease);
6131
7109
  delay = easingFunction(delay / maxDelay) * maxDelay;
6132
7110
  }
@@ -6360,7 +7338,7 @@ function follow(value, source, options) {
6360
7338
  }, stopAnimation);
6361
7339
  if (isMotionValue(source)) {
6362
7340
  let skipNextAnimation = options.skipInitialAnimation === true;
6363
- const removeSourceOnChange = source.on("change", (v) => {
7341
+ const onSourceChange = (v) => {
6364
7342
  if (skipNextAnimation) {
6365
7343
  skipNextAnimation = false;
6366
7344
  value.jump(parseValue(v, unit), false);
@@ -6368,11 +7346,28 @@ function follow(value, source, options) {
6368
7346
  else {
6369
7347
  value.set(parseValue(v, unit));
6370
7348
  }
6371
- });
7349
+ };
7350
+ const removeSourceOnChange = source.on("change", onSourceChange);
7351
+ /**
7352
+ * Catch up on a change made before we subscribed, for instance
7353
+ * between a React render reading the source and the effect
7354
+ * attaching to it. Subtracting is falsy for equal or non-numeric
7355
+ * (NaN) values.
7356
+ */
7357
+ const latest = source.get();
7358
+ if (asNumber(latest) - asNumber(value.get()))
7359
+ onSourceChange(latest);
6372
7360
  const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
7361
+ /**
7362
+ * Stop our animation on detach, otherwise a re-attach (new
7363
+ * options, Strict Mode) starts a second animation that fights
7364
+ * this orphaned one. The catch-up above resumes from the
7365
+ * current value and velocity.
7366
+ */
6373
7367
  return () => {
6374
7368
  removeSourceOnChange();
6375
7369
  removeValueOnDestroy();
7370
+ stopAnimation();
6376
7371
  };
6377
7372
  }
6378
7373
  return stopAnimation;
@@ -8062,8 +9057,11 @@ class VisualElement {
8062
9057
  const removeOnChange = value.on("change", (latestValue) => {
8063
9058
  this.latestValues[key] = latestValue;
8064
9059
  this.props.onUpdate && frame.preRender(this.notifyUpdate);
8065
- if (valueIsTransform && this.projection) {
8066
- this.projection.isTransformDirty = true;
9060
+ if (valueIsTransform) {
9061
+ if (this.projection) {
9062
+ this.projection.isTransformDirty = true;
9063
+ }
9064
+ transformGroups.get(this.current)?.check();
8067
9065
  }
8068
9066
  this.scheduleRender();
8069
9067
  });
@@ -8147,9 +9145,18 @@ class VisualElement {
8147
9145
  * added to our map, old ones removed, and listeners updated.
8148
9146
  */
8149
9147
  update(props, presenceContext) {
8150
- if (props.transformTemplate || this.props.transformTemplate) {
9148
+ const { transformTemplate, onUpdate } = this.props;
9149
+ if (props.transformTemplate || transformTemplate) {
8151
9150
  this.scheduleRender();
8152
9151
  }
9152
+ /**
9153
+ * Transforms on the compositor can't use a new transformTemplate
9154
+ * or onUpdate, so move them to the main thread.
9155
+ */
9156
+ if ((props.transformTemplate && !transformTemplate) ||
9157
+ (props.onUpdate && !onUpdate)) {
9158
+ transformGroups.get(this.current)?.demote();
9159
+ }
8153
9160
  this.prevProps = this.props;
8154
9161
  this.props = props;
8155
9162
  this.prevPresenceContext = this.presenceContext;
@@ -8523,8 +9530,13 @@ function renderSVG(element, renderState, _styleProp, projection) {
8523
9530
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
8524
9531
  const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
8525
9532
  for (const key in props) {
8526
- if (isMotionValue(props[key]) ||
8527
- isMotionValue(prevProps[key])) {
9533
+ /**
9534
+ * A MotionValue child is rendered as text content by
9535
+ * DOMVisualElement, so it mustn't also be written as an attribute.
9536
+ */
9537
+ if (key !== "children" &&
9538
+ (isMotionValue(props[key]) ||
9539
+ isMotionValue(prevProps[key]))) {
8528
9540
  const targetKey = transformPropOrder.indexOf(key) !== -1
8529
9541
  ? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
8530
9542
  : key;
@@ -9445,6 +10457,7 @@ function resetDistortingTransform(key, visualElement, values, sharedAnimationVal
9445
10457
  }
9446
10458
  }
9447
10459
  }
10460
+ const demoteTransforms = ({ instance }) => instance && transformGroups.get(instance)?.demote();
9448
10461
  function cancelTreeOptimisedTransformAnimations(projectionNode) {
9449
10462
  projectionNode.hasCheckedOptimisedAppear = true;
9450
10463
  if (projectionNode.root === projectionNode)
@@ -9806,10 +10819,17 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
9806
10819
  !this.root.isUpdating && this.root.startUpdate();
9807
10820
  if (this.isLayoutDirty)
9808
10821
  return;
10822
+ /**
10823
+ * Accelerated transforms aren't reflected in latestValues or
10824
+ * removed by resetTransform, so move them back to the main
10825
+ * thread before this node, or its ancestors, are measured.
10826
+ */
10827
+ demoteTransforms(this);
9809
10828
  this.isLayoutDirty = true;
9810
10829
  for (let i = 0; i < this.path.length; i++) {
9811
10830
  const node = this.path[i];
9812
10831
  node.shouldResetTransform = true;
10832
+ demoteTransforms(node);
9813
10833
  /**
9814
10834
  * Percentage translates resolve against layoutBox dimensions,
9815
10835
  * so ancestors with them must be re-measured after transform reset.
@@ -10012,6 +11032,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
10012
11032
  const isResetRequested = this.isLayoutDirty ||
10013
11033
  this.shouldResetTransform ||
10014
11034
  this.options.alwaysMeasureLayout;
11035
+ isResetRequested && demoteTransforms(this);
10015
11036
  const hasProjection = this.projectionDelta && !isDeltaZero(this.projectionDelta);
10016
11037
  const transformTemplate = this.getTransformTemplate();
10017
11038
  const transformTemplateValue = transformTemplate
@@ -11624,7 +12645,7 @@ exports.buildHTMLStyles = buildHTMLStyles;
11624
12645
  exports.buildProjectionTransform = buildProjectionTransform;
11625
12646
  exports.buildSVGAttrs = buildSVGAttrs;
11626
12647
  exports.buildSVGPath = buildSVGPath;
11627
- exports.buildTransform = buildTransform;
12648
+ exports.buildTransform = buildTransform$1;
11628
12649
  exports.calcAxisDelta = calcAxisDelta;
11629
12650
  exports.calcBoxDelta = calcBoxDelta;
11630
12651
  exports.calcChildStagger = calcChildStagger;
@@ -11797,6 +12818,8 @@ exports.resolveVariantFromProps = resolveVariantFromProps;
11797
12818
  exports.rgbUnit = rgbUnit;
11798
12819
  exports.rgba = rgba;
11799
12820
  exports.rootProjectionNode = rootProjectionNode;
12821
+ exports.round = round;
12822
+ exports.sampleDelta = sampleDelta;
11800
12823
  exports.scale = scale;
11801
12824
  exports.scaleCorrectors = scaleCorrectors;
11802
12825
  exports.scalePoint = scalePoint;
@@ -11820,6 +12843,7 @@ exports.supportsLinearEasing = supportsLinearEasing;
11820
12843
  exports.supportsPartialKeyframes = supportsPartialKeyframes;
11821
12844
  exports.supportsScrollTimeline = supportsScrollTimeline;
11822
12845
  exports.supportsViewTimeline = supportsViewTimeline;
12846
+ exports.supportsWaapi = supportsWaapi;
11823
12847
  exports.svgEffect = svgEffect;
11824
12848
  exports.svgSubjectEffect = svgSubjectEffect;
11825
12849
  exports.sync = sync;