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