motion-dom 12.7.4 → 12.7.5-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/cjs/index.js +2945 -475
  2. package/dist/es/animation/AsyncMotionValueAnimation.mjs +178 -0
  3. package/dist/es/animation/GroupAnimation.mjs +6 -15
  4. package/dist/es/animation/JSAnimation.mjs +345 -0
  5. package/dist/es/animation/NativeAnimation.mjs +64 -67
  6. package/dist/es/animation/NativeAnimationExtended.mjs +65 -0
  7. package/dist/es/animation/NativeAnimationWrapper.mjs +14 -0
  8. package/dist/es/animation/drivers/driver-frameloop.mjs +17 -0
  9. package/dist/es/animation/generators/inertia.mjs +87 -0
  10. package/dist/es/animation/generators/keyframes.mjs +49 -0
  11. package/dist/es/animation/generators/spring/defaults.mjs +27 -0
  12. package/dist/es/animation/generators/spring/find.mjs +84 -0
  13. package/dist/es/animation/generators/spring/index.mjs +175 -0
  14. package/dist/es/animation/generators/utils/velocity.mjs +9 -0
  15. package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +131 -0
  16. package/dist/es/animation/keyframes/KeyframesResolver.mjs +156 -0
  17. package/dist/es/animation/keyframes/get-final.mjs +3 -4
  18. package/dist/es/animation/keyframes/offsets/default.mjs +9 -0
  19. package/dist/es/animation/keyframes/offsets/fill.mjs +12 -0
  20. package/dist/es/animation/keyframes/offsets/time.mjs +5 -0
  21. package/dist/es/animation/keyframes/utils/apply-px-defaults.mjs +11 -0
  22. package/dist/es/animation/keyframes/utils/fill-wildcards.mjs +7 -0
  23. package/dist/es/animation/keyframes/utils/is-none.mjs +15 -0
  24. package/dist/es/animation/keyframes/utils/make-none-animatable.mjs +30 -0
  25. package/dist/es/animation/keyframes/utils/unit-conversion.mjs +36 -0
  26. package/dist/es/animation/utils/WithPromise.mjs +28 -0
  27. package/dist/es/animation/utils/active-animations.mjs +9 -0
  28. package/dist/es/animation/utils/can-animate.mjs +42 -0
  29. package/dist/es/animation/utils/css-variables-conversion.mjs +41 -0
  30. package/dist/es/animation/utils/is-animatable.mjs +30 -0
  31. package/dist/es/animation/utils/is-css-variable.mjs +15 -0
  32. package/dist/es/animation/utils/replace-transition-type.mjs +18 -0
  33. package/dist/es/animation/waapi/easing/is-supported.mjs +1 -1
  34. package/dist/es/animation/waapi/easing/map-easing.mjs +5 -3
  35. package/dist/es/animation/waapi/start-waapi-animation.mjs +6 -4
  36. package/dist/es/animation/waapi/supports/waapi.mjs +39 -0
  37. package/dist/es/animation/waapi/utils/accelerated-values.mjs +14 -0
  38. package/dist/es/animation/waapi/utils/apply-generator.mjs +2 -1
  39. package/dist/es/animation/waapi/utils/unsupported-easing.mjs +18 -0
  40. package/dist/es/frameloop/batcher.mjs +2 -1
  41. package/dist/es/frameloop/order.mjs +1 -0
  42. package/dist/es/index.mjs +49 -2
  43. package/dist/es/render/dom/is-css-var.mjs +3 -0
  44. package/dist/es/render/dom/parse-transform.mjs +83 -0
  45. package/dist/es/render/dom/style-computed.mjs +10 -0
  46. package/dist/es/render/dom/style-set.mjs +9 -0
  47. package/dist/es/render/utils/keys-position.mjs +13 -0
  48. package/dist/es/render/utils/keys-transform.mjs +28 -0
  49. package/dist/es/scroll/observe.mjs +18 -0
  50. package/dist/es/stats/index.mjs +2 -0
  51. package/dist/es/utils/interpolate.mjs +74 -0
  52. package/dist/es/utils/mix/color.mjs +47 -0
  53. package/dist/es/utils/mix/complex.mjs +92 -0
  54. package/dist/es/utils/mix/immediate.mjs +5 -0
  55. package/dist/es/utils/mix/index.mjs +14 -0
  56. package/dist/es/utils/mix/number.mjs +26 -0
  57. package/dist/es/utils/mix/visibility.mjs +16 -0
  58. package/dist/es/value/index.mjs +3 -1
  59. package/dist/es/value/types/auto.mjs +9 -0
  60. package/dist/es/value/types/color/hex.mjs +40 -0
  61. package/dist/es/value/types/color/hsla-to-rgba.mjs +42 -0
  62. package/dist/es/value/types/color/hsla.mjs +22 -0
  63. package/dist/es/value/types/color/index.mjs +27 -0
  64. package/dist/es/value/types/color/rgba.mjs +25 -0
  65. package/dist/es/value/types/color/utils.mjs +29 -0
  66. package/dist/es/value/types/complex/filter.mjs +30 -0
  67. package/dist/es/value/types/complex/index.mjs +91 -0
  68. package/dist/es/value/types/dimensions.mjs +15 -0
  69. package/dist/es/value/types/int.mjs +8 -0
  70. package/dist/es/value/types/maps/defaults.mjs +30 -0
  71. package/dist/es/value/types/maps/number.mjs +51 -0
  72. package/dist/es/value/types/maps/transform.mjs +31 -0
  73. package/dist/es/value/types/numbers/index.mjs +17 -0
  74. package/dist/es/value/types/numbers/units.mjs +18 -0
  75. package/dist/es/value/types/test.mjs +6 -0
  76. package/dist/es/value/types/utils/animatable-none.mjs +15 -0
  77. package/dist/es/value/types/utils/color-regex.mjs +3 -0
  78. package/dist/es/value/types/utils/find.mjs +15 -0
  79. package/dist/es/value/types/utils/float-regex.mjs +3 -0
  80. package/dist/es/value/types/utils/get-as-type.mjs +10 -0
  81. package/dist/es/value/types/utils/is-nullish.mjs +5 -0
  82. package/dist/es/value/types/utils/sanitize.mjs +5 -0
  83. package/dist/es/value/types/utils/single-color-regex.mjs +3 -0
  84. package/dist/es/view/start.mjs +4 -3
  85. package/dist/index.d.ts +945 -444
  86. package/dist/motion-dom.dev.js +2944 -475
  87. package/dist/motion-dom.js +1 -1
  88. package/package.json +3 -3
  89. package/dist/es/animation/keyframes/hydrate.mjs +0 -26
  90. package/dist/es/animation/waapi/utils/attach-timeline.mjs +0 -6
  91. package/dist/es/render/dom/style.mjs +0 -15
  92. package/dist/es/utils/is-bezier-definition.mjs +0 -3
@@ -0,0 +1,175 @@
1
+ import { millisecondsToSeconds, secondsToMilliseconds, clamp } from 'motion-utils';
2
+ import { generateLinearEasing } from '../../waapi/utils/linear.mjs';
3
+ import { calcGeneratorDuration, maxGeneratorDuration } from '../utils/calc-duration.mjs';
4
+ import { createGeneratorEasing } from '../utils/create-generator-easing.mjs';
5
+ import { calcGeneratorVelocity } from '../utils/velocity.mjs';
6
+ import { springDefaults } from './defaults.mjs';
7
+ import { findSpring, calcAngularFreq } from './find.mjs';
8
+
9
+ const durationKeys = ["duration", "bounce"];
10
+ const physicsKeys = ["stiffness", "damping", "mass"];
11
+ function isSpringType(options, keys) {
12
+ return keys.some((key) => options[key] !== undefined);
13
+ }
14
+ function getSpringOptions(options) {
15
+ let springOptions = {
16
+ velocity: springDefaults.velocity,
17
+ stiffness: springDefaults.stiffness,
18
+ damping: springDefaults.damping,
19
+ mass: springDefaults.mass,
20
+ isResolvedFromDuration: false,
21
+ ...options,
22
+ };
23
+ // stiffness/damping/mass overrides duration/bounce
24
+ if (!isSpringType(options, physicsKeys) &&
25
+ isSpringType(options, durationKeys)) {
26
+ if (options.visualDuration) {
27
+ const visualDuration = options.visualDuration;
28
+ const root = (2 * Math.PI) / (visualDuration * 1.2);
29
+ const stiffness = root * root;
30
+ const damping = 2 *
31
+ clamp(0.05, 1, 1 - (options.bounce || 0)) *
32
+ Math.sqrt(stiffness);
33
+ springOptions = {
34
+ ...springOptions,
35
+ mass: springDefaults.mass,
36
+ stiffness,
37
+ damping,
38
+ };
39
+ }
40
+ else {
41
+ const derived = findSpring(options);
42
+ springOptions = {
43
+ ...springOptions,
44
+ ...derived,
45
+ mass: springDefaults.mass,
46
+ };
47
+ springOptions.isResolvedFromDuration = true;
48
+ }
49
+ }
50
+ return springOptions;
51
+ }
52
+ function spring(optionsOrVisualDuration = springDefaults.visualDuration, bounce = springDefaults.bounce) {
53
+ const options = typeof optionsOrVisualDuration !== "object"
54
+ ? {
55
+ visualDuration: optionsOrVisualDuration,
56
+ keyframes: [0, 1],
57
+ bounce,
58
+ }
59
+ : optionsOrVisualDuration;
60
+ let { restSpeed, restDelta } = options;
61
+ const origin = options.keyframes[0];
62
+ const target = options.keyframes[options.keyframes.length - 1];
63
+ /**
64
+ * This is the Iterator-spec return value. We ensure it's mutable rather than using a generator
65
+ * to reduce GC during animation.
66
+ */
67
+ const state = { done: false, value: origin };
68
+ const { stiffness, damping, mass, duration, velocity, isResolvedFromDuration, } = getSpringOptions({
69
+ ...options,
70
+ velocity: -millisecondsToSeconds(options.velocity || 0),
71
+ });
72
+ const initialVelocity = velocity || 0.0;
73
+ const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
74
+ const initialDelta = target - origin;
75
+ const undampedAngularFreq = millisecondsToSeconds(Math.sqrt(stiffness / mass));
76
+ /**
77
+ * If we're working on a granular scale, use smaller defaults for determining
78
+ * when the spring is finished.
79
+ *
80
+ * These defaults have been selected emprically based on what strikes a good
81
+ * ratio between feeling good and finishing as soon as changes are imperceptible.
82
+ */
83
+ const isGranularScale = Math.abs(initialDelta) < 5;
84
+ restSpeed || (restSpeed = isGranularScale
85
+ ? springDefaults.restSpeed.granular
86
+ : springDefaults.restSpeed.default);
87
+ restDelta || (restDelta = isGranularScale
88
+ ? springDefaults.restDelta.granular
89
+ : springDefaults.restDelta.default);
90
+ let resolveSpring;
91
+ if (dampingRatio < 1) {
92
+ const angularFreq = calcAngularFreq(undampedAngularFreq, dampingRatio);
93
+ // Underdamped spring
94
+ resolveSpring = (t) => {
95
+ const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
96
+ return (target -
97
+ envelope *
98
+ (((initialVelocity +
99
+ dampingRatio * undampedAngularFreq * initialDelta) /
100
+ angularFreq) *
101
+ Math.sin(angularFreq * t) +
102
+ initialDelta * Math.cos(angularFreq * t)));
103
+ };
104
+ }
105
+ else if (dampingRatio === 1) {
106
+ // Critically damped spring
107
+ resolveSpring = (t) => target -
108
+ Math.exp(-undampedAngularFreq * t) *
109
+ (initialDelta +
110
+ (initialVelocity + undampedAngularFreq * initialDelta) * t);
111
+ }
112
+ else {
113
+ // Overdamped spring
114
+ const dampedAngularFreq = undampedAngularFreq * Math.sqrt(dampingRatio * dampingRatio - 1);
115
+ resolveSpring = (t) => {
116
+ const envelope = Math.exp(-dampingRatio * undampedAngularFreq * t);
117
+ // When performing sinh or cosh values can hit Infinity so we cap them here
118
+ const freqForT = Math.min(dampedAngularFreq * t, 300);
119
+ return (target -
120
+ (envelope *
121
+ ((initialVelocity +
122
+ dampingRatio * undampedAngularFreq * initialDelta) *
123
+ Math.sinh(freqForT) +
124
+ dampedAngularFreq *
125
+ initialDelta *
126
+ Math.cosh(freqForT))) /
127
+ dampedAngularFreq);
128
+ };
129
+ }
130
+ const generator = {
131
+ calculatedDuration: isResolvedFromDuration ? duration || null : null,
132
+ next: (t) => {
133
+ const current = resolveSpring(t);
134
+ if (!isResolvedFromDuration) {
135
+ let currentVelocity = 0.0;
136
+ /**
137
+ * We only need to calculate velocity for under-damped springs
138
+ * as over- and critically-damped springs can't overshoot, so
139
+ * checking only for displacement is enough.
140
+ */
141
+ if (dampingRatio < 1) {
142
+ currentVelocity =
143
+ t === 0
144
+ ? secondsToMilliseconds(initialVelocity)
145
+ : calcGeneratorVelocity(resolveSpring, t, current);
146
+ }
147
+ const isBelowVelocityThreshold = Math.abs(currentVelocity) <= restSpeed;
148
+ const isBelowDisplacementThreshold = Math.abs(target - current) <= restDelta;
149
+ state.done =
150
+ isBelowVelocityThreshold && isBelowDisplacementThreshold;
151
+ }
152
+ else {
153
+ state.done = t >= duration;
154
+ }
155
+ state.value = state.done ? target : current;
156
+ return state;
157
+ },
158
+ toString: () => {
159
+ const calculatedDuration = Math.min(calcGeneratorDuration(generator), maxGeneratorDuration);
160
+ const easing = generateLinearEasing((progress) => generator.next(calculatedDuration * progress).value, calculatedDuration, 30);
161
+ return calculatedDuration + "ms " + easing;
162
+ },
163
+ toTransition: () => { },
164
+ };
165
+ return generator;
166
+ }
167
+ spring.applyToOptions = (options) => {
168
+ const generatorOptions = createGeneratorEasing(options, 100, spring);
169
+ options.ease = generatorOptions.ease;
170
+ options.duration = secondsToMilliseconds(generatorOptions.duration);
171
+ options.type = "keyframes";
172
+ return options;
173
+ };
174
+
175
+ export { spring };
@@ -0,0 +1,9 @@
1
+ import { velocityPerSecond } from 'motion-utils';
2
+
3
+ const velocitySampleDuration = 5; // ms
4
+ function calcGeneratorVelocity(resolveValue, t, current) {
5
+ const prevT = Math.max(t - velocitySampleDuration, 0);
6
+ return velocityPerSecond(current - resolveValue(prevT), t - prevT);
7
+ }
8
+
9
+ export { calcGeneratorVelocity };
@@ -0,0 +1,131 @@
1
+ import { positionalKeys } from '../../render/utils/keys-position.mjs';
2
+ import { findDimensionValueType } from '../../value/types/dimensions.mjs';
3
+ import { getVariableValue } from '../utils/css-variables-conversion.mjs';
4
+ import { isCSSVariableToken } from '../utils/is-css-variable.mjs';
5
+ import { KeyframeResolver } from './KeyframesResolver.mjs';
6
+ import { isNone } from './utils/is-none.mjs';
7
+ import { makeNoneKeyframesAnimatable } from './utils/make-none-animatable.mjs';
8
+ import { isNumOrPxType, positionalValues } from './utils/unit-conversion.mjs';
9
+
10
+ class DOMKeyframesResolver extends KeyframeResolver {
11
+ constructor(unresolvedKeyframes, onComplete, name, motionValue, element) {
12
+ super(unresolvedKeyframes, onComplete, name, motionValue, element, true);
13
+ }
14
+ readKeyframes() {
15
+ const { unresolvedKeyframes, element, name } = this;
16
+ if (!element || !element.current)
17
+ return;
18
+ super.readKeyframes();
19
+ /**
20
+ * If any keyframe is a CSS variable, we need to find its value by sampling the element
21
+ */
22
+ for (let i = 0; i < unresolvedKeyframes.length; i++) {
23
+ let keyframe = unresolvedKeyframes[i];
24
+ if (typeof keyframe === "string") {
25
+ keyframe = keyframe.trim();
26
+ if (isCSSVariableToken(keyframe)) {
27
+ const resolved = getVariableValue(keyframe, element.current);
28
+ if (resolved !== undefined) {
29
+ unresolvedKeyframes[i] = resolved;
30
+ }
31
+ if (i === unresolvedKeyframes.length - 1) {
32
+ this.finalKeyframe = keyframe;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ /**
38
+ * Resolve "none" values. We do this potentially twice - once before and once after measuring keyframes.
39
+ * This could be seen as inefficient but it's a trade-off to avoid measurements in more situations, which
40
+ * have a far bigger performance impact.
41
+ */
42
+ this.resolveNoneKeyframes();
43
+ /**
44
+ * Check to see if unit type has changed. If so schedule jobs that will
45
+ * temporarily set styles to the destination keyframes.
46
+ * Skip if we have more than two keyframes or this isn't a positional value.
47
+ * TODO: We can throw if there are multiple keyframes and the value type changes.
48
+ */
49
+ if (!positionalKeys.has(name) || unresolvedKeyframes.length !== 2) {
50
+ return;
51
+ }
52
+ const [origin, target] = unresolvedKeyframes;
53
+ const originType = findDimensionValueType(origin);
54
+ const targetType = findDimensionValueType(target);
55
+ /**
56
+ * Either we don't recognise these value types or we can animate between them.
57
+ */
58
+ if (originType === targetType)
59
+ return;
60
+ /**
61
+ * If both values are numbers or pixels, we can animate between them by
62
+ * converting them to numbers.
63
+ */
64
+ if (isNumOrPxType(originType) && isNumOrPxType(targetType)) {
65
+ for (let i = 0; i < unresolvedKeyframes.length; i++) {
66
+ const value = unresolvedKeyframes[i];
67
+ if (typeof value === "string") {
68
+ unresolvedKeyframes[i] = parseFloat(value);
69
+ }
70
+ }
71
+ }
72
+ else {
73
+ /**
74
+ * Else, the only way to resolve this is by measuring the element.
75
+ */
76
+ this.needsMeasurement = true;
77
+ }
78
+ }
79
+ resolveNoneKeyframes() {
80
+ const { unresolvedKeyframes, name } = this;
81
+ const noneKeyframeIndexes = [];
82
+ for (let i = 0; i < unresolvedKeyframes.length; i++) {
83
+ if (unresolvedKeyframes[i] === null ||
84
+ isNone(unresolvedKeyframes[i])) {
85
+ noneKeyframeIndexes.push(i);
86
+ }
87
+ }
88
+ if (noneKeyframeIndexes.length) {
89
+ makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, name);
90
+ }
91
+ }
92
+ measureInitialState() {
93
+ const { element, unresolvedKeyframes, name } = this;
94
+ if (!element || !element.current)
95
+ return;
96
+ if (name === "height") {
97
+ this.suspendedScrollY = window.pageYOffset;
98
+ }
99
+ this.measuredOrigin = positionalValues[name](element.measureViewportBox(), window.getComputedStyle(element.current));
100
+ unresolvedKeyframes[0] = this.measuredOrigin;
101
+ // Set final key frame to measure after next render
102
+ const measureKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
103
+ if (measureKeyframe !== undefined) {
104
+ element.getValue(name, measureKeyframe).jump(measureKeyframe, false);
105
+ }
106
+ }
107
+ measureEndState() {
108
+ const { element, name, unresolvedKeyframes } = this;
109
+ if (!element || !element.current)
110
+ return;
111
+ const value = element.getValue(name);
112
+ value && value.jump(this.measuredOrigin, false);
113
+ const finalKeyframeIndex = unresolvedKeyframes.length - 1;
114
+ const finalKeyframe = unresolvedKeyframes[finalKeyframeIndex];
115
+ unresolvedKeyframes[finalKeyframeIndex] = positionalValues[name](element.measureViewportBox(), window.getComputedStyle(element.current));
116
+ if (finalKeyframe !== null && this.finalKeyframe === undefined) {
117
+ this.finalKeyframe = finalKeyframe;
118
+ }
119
+ // If we removed transform values, reapply them before the next render
120
+ if (this.removedTransforms?.length) {
121
+ this.removedTransforms.forEach(([unsetTransformName, unsetTransformValue]) => {
122
+ element
123
+ .getValue(unsetTransformName)
124
+ .set(unsetTransformValue);
125
+ });
126
+ }
127
+ this.resolveNoneKeyframes();
128
+ }
129
+ }
130
+
131
+ export { DOMKeyframesResolver };
@@ -0,0 +1,156 @@
1
+ import { fillWildcards } from './utils/fill-wildcards.mjs';
2
+ import { removeNonTranslationalTransform } from './utils/unit-conversion.mjs';
3
+ import { frame } from '../../frameloop/frame.mjs';
4
+
5
+ const toResolve = new Set();
6
+ let isScheduled = false;
7
+ let anyNeedsMeasurement = false;
8
+ let isForced = false;
9
+ function measureAllKeyframes() {
10
+ if (anyNeedsMeasurement) {
11
+ const resolversToMeasure = Array.from(toResolve).filter((resolver) => resolver.needsMeasurement);
12
+ const elementsToMeasure = new Set(resolversToMeasure.map((resolver) => resolver.element));
13
+ const transformsToRestore = new Map();
14
+ /**
15
+ * Write pass
16
+ * If we're measuring elements we want to remove bounding box-changing transforms.
17
+ */
18
+ elementsToMeasure.forEach((element) => {
19
+ const removedTransforms = removeNonTranslationalTransform(element);
20
+ if (!removedTransforms.length)
21
+ return;
22
+ transformsToRestore.set(element, removedTransforms);
23
+ element.render();
24
+ });
25
+ // Read
26
+ resolversToMeasure.forEach((resolver) => resolver.measureInitialState());
27
+ // Write
28
+ elementsToMeasure.forEach((element) => {
29
+ element.render();
30
+ const restore = transformsToRestore.get(element);
31
+ if (restore) {
32
+ restore.forEach(([key, value]) => {
33
+ element.getValue(key)?.set(value);
34
+ });
35
+ }
36
+ });
37
+ // Read
38
+ resolversToMeasure.forEach((resolver) => resolver.measureEndState());
39
+ // Write
40
+ resolversToMeasure.forEach((resolver) => {
41
+ if (resolver.suspendedScrollY !== undefined) {
42
+ window.scrollTo(0, resolver.suspendedScrollY);
43
+ }
44
+ });
45
+ }
46
+ anyNeedsMeasurement = false;
47
+ isScheduled = false;
48
+ toResolve.forEach((resolver) => resolver.complete(isForced));
49
+ toResolve.clear();
50
+ }
51
+ function readAllKeyframes() {
52
+ toResolve.forEach((resolver) => {
53
+ resolver.readKeyframes();
54
+ if (resolver.needsMeasurement) {
55
+ anyNeedsMeasurement = true;
56
+ }
57
+ });
58
+ }
59
+ function flushKeyframeResolvers() {
60
+ isForced = true;
61
+ readAllKeyframes();
62
+ measureAllKeyframes();
63
+ isForced = false;
64
+ }
65
+ class KeyframeResolver {
66
+ constructor(unresolvedKeyframes, onComplete, name, motionValue, element, isAsync = false) {
67
+ /**
68
+ * Track whether this resolver has completed. Once complete, it never
69
+ * needs to attempt keyframe resolution again.
70
+ */
71
+ this.isComplete = false;
72
+ /**
73
+ * Track whether this resolver is async. If it is, it'll be added to the
74
+ * resolver queue and flushed in the next frame. Resolvers that aren't going
75
+ * to trigger read/write thrashing don't need to be async.
76
+ */
77
+ this.isAsync = false;
78
+ /**
79
+ * Track whether this resolver needs to perform a measurement
80
+ * to resolve its keyframes.
81
+ */
82
+ this.needsMeasurement = false;
83
+ /**
84
+ * Track whether this resolver is currently scheduled to resolve
85
+ * to allow it to be cancelled and resumed externally.
86
+ */
87
+ this.isScheduled = false;
88
+ this.unresolvedKeyframes = [...unresolvedKeyframes];
89
+ this.onComplete = onComplete;
90
+ this.name = name;
91
+ this.motionValue = motionValue;
92
+ this.element = element;
93
+ this.isAsync = isAsync;
94
+ }
95
+ scheduleResolve() {
96
+ this.isScheduled = true;
97
+ if (this.isAsync) {
98
+ toResolve.add(this);
99
+ if (!isScheduled) {
100
+ isScheduled = true;
101
+ frame.read(readAllKeyframes);
102
+ frame.resolveKeyframes(measureAllKeyframes);
103
+ }
104
+ }
105
+ else {
106
+ this.readKeyframes();
107
+ this.complete();
108
+ }
109
+ }
110
+ readKeyframes() {
111
+ const { unresolvedKeyframes, name, element, motionValue } = this;
112
+ // If initial keyframe is null we need to read it from the DOM
113
+ if (unresolvedKeyframes[0] === null) {
114
+ const currentValue = motionValue?.get();
115
+ // TODO: This doesn't work if the final keyframe is a wildcard
116
+ const finalKeyframe = unresolvedKeyframes[unresolvedKeyframes.length - 1];
117
+ if (currentValue !== undefined) {
118
+ unresolvedKeyframes[0] = currentValue;
119
+ }
120
+ else if (element && name) {
121
+ const valueAsRead = element.readValue(name, finalKeyframe);
122
+ if (valueAsRead !== undefined && valueAsRead !== null) {
123
+ unresolvedKeyframes[0] = valueAsRead;
124
+ }
125
+ }
126
+ if (unresolvedKeyframes[0] === undefined) {
127
+ unresolvedKeyframes[0] = finalKeyframe;
128
+ }
129
+ if (motionValue && currentValue === undefined) {
130
+ motionValue.set(unresolvedKeyframes[0]);
131
+ }
132
+ }
133
+ fillWildcards(unresolvedKeyframes);
134
+ }
135
+ setFinalKeyframe() { }
136
+ measureInitialState() { }
137
+ renderEndStyles() { }
138
+ measureEndState() { }
139
+ complete(isForced = false) {
140
+ this.isComplete = true;
141
+ this.onComplete(this.unresolvedKeyframes, this.finalKeyframe, isForced);
142
+ toResolve.delete(this);
143
+ }
144
+ cancel() {
145
+ if (!this.isComplete) {
146
+ this.isScheduled = false;
147
+ toResolve.delete(this);
148
+ }
149
+ }
150
+ resume() {
151
+ if (!this.isComplete)
152
+ this.scheduleResolve();
153
+ }
154
+ }
155
+
156
+ export { KeyframeResolver, flushKeyframeResolvers };
@@ -1,9 +1,8 @@
1
1
  const isNotNull = (value) => value !== null;
2
- function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
2
+ function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe, speed = 1) {
3
3
  const resolvedKeyframes = keyframes.filter(isNotNull);
4
- const index = repeat && repeatType !== "loop" && repeat % 2 === 1
5
- ? 0
6
- : resolvedKeyframes.length - 1;
4
+ const useFirstKeyframe = speed < 0 || (repeat && repeatType !== "loop" && repeat % 2 === 1);
5
+ const index = useFirstKeyframe ? 0 : resolvedKeyframes.length - 1;
7
6
  return !index || finalKeyframe === undefined
8
7
  ? resolvedKeyframes[index]
9
8
  : finalKeyframe;
@@ -0,0 +1,9 @@
1
+ import { fillOffset } from './fill.mjs';
2
+
3
+ function defaultOffset(arr) {
4
+ const offset = [0];
5
+ fillOffset(offset, arr.length - 1);
6
+ return offset;
7
+ }
8
+
9
+ export { defaultOffset };
@@ -0,0 +1,12 @@
1
+ import { progress } from 'motion-utils';
2
+ import { mixNumber } from '../../../utils/mix/number.mjs';
3
+
4
+ function fillOffset(offset, remaining) {
5
+ const min = offset[offset.length - 1];
6
+ for (let i = 1; i <= remaining; i++) {
7
+ const offsetProgress = progress(0, remaining, i);
8
+ offset.push(mixNumber(min, 1, offsetProgress));
9
+ }
10
+ }
11
+
12
+ export { fillOffset };
@@ -0,0 +1,5 @@
1
+ function convertOffsetToTimes(offset, duration) {
2
+ return offset.map((o) => o * duration);
3
+ }
4
+
5
+ export { convertOffsetToTimes };
@@ -0,0 +1,11 @@
1
+ import { pxValues } from '../../waapi/utils/px-values.mjs';
2
+
3
+ function applyPxDefaults(keyframes, name) {
4
+ for (let i = 0; i < keyframes.length; i++) {
5
+ if (typeof keyframes[i] === "number" && pxValues.has(name)) {
6
+ keyframes[i] = keyframes[i] + "px";
7
+ }
8
+ }
9
+ }
10
+
11
+ export { applyPxDefaults };
@@ -0,0 +1,7 @@
1
+ function fillWildcards(keyframes) {
2
+ for (let i = 1; i < keyframes.length; i++) {
3
+ keyframes[i] ?? (keyframes[i] = keyframes[i - 1]);
4
+ }
5
+ }
6
+
7
+ export { fillWildcards };
@@ -0,0 +1,15 @@
1
+ import { isZeroValueString } from 'motion-utils';
2
+
3
+ function isNone(value) {
4
+ if (typeof value === "number") {
5
+ return value === 0;
6
+ }
7
+ else if (value !== null) {
8
+ return value === "none" || value === "0" || isZeroValueString(value);
9
+ }
10
+ else {
11
+ return true;
12
+ }
13
+ }
14
+
15
+ export { isNone };
@@ -0,0 +1,30 @@
1
+ import { analyseComplexValue } from '../../../value/types/complex/index.mjs';
2
+ import { getAnimatableNone } from '../../../value/types/utils/animatable-none.mjs';
3
+
4
+ /**
5
+ * If we encounter keyframes like "none" or "0" and we also have keyframes like
6
+ * "#fff" or "200px 200px" we want to find a keyframe to serve as a template for
7
+ * the "none" keyframes. In this case "#fff" or "200px 200px" - then these get turned into
8
+ * zero equivalents, i.e. "#fff0" or "0px 0px".
9
+ */
10
+ const invalidTemplates = new Set(["auto", "none", "0"]);
11
+ function makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, name) {
12
+ let i = 0;
13
+ let animatableTemplate = undefined;
14
+ while (i < unresolvedKeyframes.length && !animatableTemplate) {
15
+ const keyframe = unresolvedKeyframes[i];
16
+ if (typeof keyframe === "string" &&
17
+ !invalidTemplates.has(keyframe) &&
18
+ analyseComplexValue(keyframe).values.length) {
19
+ animatableTemplate = unresolvedKeyframes[i];
20
+ }
21
+ i++;
22
+ }
23
+ if (animatableTemplate && name) {
24
+ for (const noneIndex of noneKeyframeIndexes) {
25
+ unresolvedKeyframes[noneIndex] = getAnimatableNone(name, animatableTemplate);
26
+ }
27
+ }
28
+ }
29
+
30
+ export { makeNoneKeyframesAnimatable };
@@ -0,0 +1,36 @@
1
+ import { parseValueFromTransform } from '../../../render/dom/parse-transform.mjs';
2
+ import { transformPropOrder } from '../../../render/utils/keys-transform.mjs';
3
+ import { number } from '../../../value/types/numbers/index.mjs';
4
+ import { px } from '../../../value/types/numbers/units.mjs';
5
+
6
+ const isNumOrPxType = (v) => v === number || v === px;
7
+ const transformKeys = new Set(["x", "y", "z"]);
8
+ const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
9
+ function removeNonTranslationalTransform(visualElement) {
10
+ const removedTransforms = [];
11
+ nonTranslationalTransformKeys.forEach((key) => {
12
+ const value = visualElement.getValue(key);
13
+ if (value !== undefined) {
14
+ removedTransforms.push([key, value.get()]);
15
+ value.set(key.startsWith("scale") ? 1 : 0);
16
+ }
17
+ });
18
+ return removedTransforms;
19
+ }
20
+ const positionalValues = {
21
+ // Dimensions
22
+ width: ({ x }, { paddingLeft = "0", paddingRight = "0" }) => x.max - x.min - parseFloat(paddingLeft) - parseFloat(paddingRight),
23
+ height: ({ y }, { paddingTop = "0", paddingBottom = "0" }) => y.max - y.min - parseFloat(paddingTop) - parseFloat(paddingBottom),
24
+ top: (_bbox, { top }) => parseFloat(top),
25
+ left: (_bbox, { left }) => parseFloat(left),
26
+ bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
27
+ right: ({ x }, { left }) => parseFloat(left) + (x.max - x.min),
28
+ // Transform
29
+ x: (_bbox, { transform }) => parseValueFromTransform(transform, "x"),
30
+ y: (_bbox, { transform }) => parseValueFromTransform(transform, "y"),
31
+ };
32
+ // Alias translate longform names
33
+ positionalValues.translateX = positionalValues.x;
34
+ positionalValues.translateY = positionalValues.y;
35
+
36
+ export { isNumOrPxType, positionalValues, removeNonTranslationalTransform };
@@ -0,0 +1,28 @@
1
+ class WithPromise {
2
+ constructor() {
3
+ this.count = 0;
4
+ this.updateFinished();
5
+ }
6
+ get finished() {
7
+ return this._finished;
8
+ }
9
+ updateFinished() {
10
+ this.count++;
11
+ this._finished = new Promise((resolve) => {
12
+ this.resolve = resolve;
13
+ });
14
+ }
15
+ notifyFinished() {
16
+ this.resolve();
17
+ }
18
+ /**
19
+ * Allows the animation to be awaited.
20
+ *
21
+ * @deprecated Use `finished` instead.
22
+ */
23
+ then(onResolve, onReject) {
24
+ return this.finished.then(onResolve, onReject);
25
+ }
26
+ }
27
+
28
+ export { WithPromise };
@@ -0,0 +1,9 @@
1
+ const animationMaps = new WeakMap();
2
+ const animationMapKey = (name, pseudoElement = "") => `${name}:${pseudoElement}`;
3
+ function getAnimationMap(element) {
4
+ const map = animationMaps.get(element) || new Map();
5
+ animationMaps.set(element, map);
6
+ return map;
7
+ }
8
+
9
+ export { animationMapKey, getAnimationMap };