motion-dom 12.7.3 → 12.7.5-alpha.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 (92) hide show
  1. package/dist/cjs/index.js +2946 -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 +346 -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 +2945 -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,42 @@
1
+ import { warning } from 'motion-utils';
2
+ import { isGenerator } from '../generators/utils/is-generator.mjs';
3
+ import { isAnimatable } from './is-animatable.mjs';
4
+
5
+ function hasKeyframesChanged(keyframes) {
6
+ const current = keyframes[0];
7
+ if (keyframes.length === 1)
8
+ return true;
9
+ for (let i = 0; i < keyframes.length; i++) {
10
+ if (keyframes[i] !== current)
11
+ return true;
12
+ }
13
+ }
14
+ function canAnimate(keyframes, name, type, velocity) {
15
+ /**
16
+ * Check if we're able to animate between the start and end keyframes,
17
+ * and throw a warning if we're attempting to animate between one that's
18
+ * animatable and another that isn't.
19
+ */
20
+ const originKeyframe = keyframes[0];
21
+ if (originKeyframe === null)
22
+ return false;
23
+ /**
24
+ * These aren't traditionally animatable but we do support them.
25
+ * In future we could look into making this more generic or replacing
26
+ * this function with mix() === mixImmediate
27
+ */
28
+ if (name === "display" || name === "visibility")
29
+ return true;
30
+ const targetKeyframe = keyframes[keyframes.length - 1];
31
+ const isOriginAnimatable = isAnimatable(originKeyframe, name);
32
+ const isTargetAnimatable = isAnimatable(targetKeyframe, name);
33
+ warning(isOriginAnimatable === isTargetAnimatable, `You are trying to animate ${name} from "${originKeyframe}" to "${targetKeyframe}". ${originKeyframe} is not an animatable value - to enable this animation set ${originKeyframe} to a value animatable to ${targetKeyframe} via the \`style\` property.`);
34
+ // Always skip if any of these are true
35
+ if (!isOriginAnimatable || !isTargetAnimatable) {
36
+ return false;
37
+ }
38
+ return (hasKeyframesChanged(keyframes) ||
39
+ ((type === "spring" || isGenerator(type)) && velocity));
40
+ }
41
+
42
+ export { canAnimate };
@@ -0,0 +1,41 @@
1
+ import { invariant, isNumericalString } from 'motion-utils';
2
+ import { isCSSVariableToken } from './is-css-variable.mjs';
3
+
4
+ /**
5
+ * Parse Framer's special CSS variable format into a CSS token and a fallback.
6
+ *
7
+ * ```
8
+ * `var(--foo, #fff)` => [`--foo`, '#fff']
9
+ * ```
10
+ *
11
+ * @param current
12
+ */
13
+ const splitCSSVariableRegex =
14
+ // eslint-disable-next-line redos-detector/no-unsafe-regex -- false positive, as it can match a lot of words
15
+ /^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;
16
+ function parseCSSVariable(current) {
17
+ const match = splitCSSVariableRegex.exec(current);
18
+ if (!match)
19
+ return [,];
20
+ const [, token1, token2, fallback] = match;
21
+ return [`--${token1 ?? token2}`, fallback];
22
+ }
23
+ const maxDepth = 4;
24
+ function getVariableValue(current, element, depth = 1) {
25
+ invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`);
26
+ const [token, fallback] = parseCSSVariable(current);
27
+ // No CSS variable detected
28
+ if (!token)
29
+ return;
30
+ // Attempt to read this CSS variable off the element
31
+ const resolved = window.getComputedStyle(element).getPropertyValue(token);
32
+ if (resolved) {
33
+ const trimmed = resolved.trim();
34
+ return isNumericalString(trimmed) ? parseFloat(trimmed) : trimmed;
35
+ }
36
+ return isCSSVariableToken(fallback)
37
+ ? getVariableValue(fallback, element, depth + 1)
38
+ : fallback;
39
+ }
40
+
41
+ export { getVariableValue, parseCSSVariable };
@@ -0,0 +1,30 @@
1
+ import { complex } from '../../value/types/complex/index.mjs';
2
+
3
+ /**
4
+ * Check if a value is animatable. Examples:
5
+ *
6
+ * ✅: 100, "100px", "#fff"
7
+ * ❌: "block", "url(2.jpg)"
8
+ * @param value
9
+ *
10
+ * @internal
11
+ */
12
+ const isAnimatable = (value, name) => {
13
+ // If the list of keys tat might be non-animatable grows, replace with Set
14
+ if (name === "zIndex")
15
+ return false;
16
+ // If it's a number or a keyframes array, we can animate it. We might at some point
17
+ // need to do a deep isAnimatable check of keyframes, or let Popmotion handle this,
18
+ // but for now lets leave it like this for performance reasons
19
+ if (typeof value === "number" || Array.isArray(value))
20
+ return true;
21
+ if (typeof value === "string" && // It's animatable if we have a string
22
+ (complex.test(value) || value === "0") && // And it contains numbers and/or colors
23
+ !value.startsWith("url(") // Unless it starts with "url("
24
+ ) {
25
+ return true;
26
+ }
27
+ return false;
28
+ };
29
+
30
+ export { isAnimatable };
@@ -0,0 +1,15 @@
1
+ const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
2
+ const isCSSVariableName =
3
+ /*@__PURE__*/ checkStringStartsWith("--");
4
+ const startsAsVariableToken =
5
+ /*@__PURE__*/ checkStringStartsWith("var(--");
6
+ const isCSSVariableToken = (value) => {
7
+ const startsWithToken = startsAsVariableToken(value);
8
+ if (!startsWithToken)
9
+ return false;
10
+ // Ensure any comments are stripped from the value as this can harm performance of the regex.
11
+ return singleCssVariableRegex.test(value.split("/*")[0].trim());
12
+ };
13
+ const singleCssVariableRegex = /var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;
14
+
15
+ export { isCSSVariableName, isCSSVariableToken };
@@ -0,0 +1,18 @@
1
+ import { inertia } from '../generators/inertia.mjs';
2
+ import { keyframes } from '../generators/keyframes.mjs';
3
+ import { spring } from '../generators/spring/index.mjs';
4
+
5
+ const transitionTypeMap = {
6
+ decay: inertia,
7
+ inertia,
8
+ tween: keyframes,
9
+ keyframes: keyframes,
10
+ spring,
11
+ };
12
+ function replaceTransitionType(transition) {
13
+ if (typeof transition.type === "string") {
14
+ transition.type = transitionTypeMap[transition.type];
15
+ }
16
+ }
17
+
18
+ export { replaceTransitionType };
@@ -1,4 +1,4 @@
1
- import { isBezierDefinition } from '../../../utils/is-bezier-definition.mjs';
1
+ import { isBezierDefinition } from 'motion-utils';
2
2
  import { supportsLinearEasing } from '../../../utils/supports/linear-easing.mjs';
3
3
  import { supportedWaapiEasing } from './supported.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { isBezierDefinition } from '../../../utils/is-bezier-definition.mjs';
1
+ import { isBezierDefinition } from 'motion-utils';
2
2
  import { supportsLinearEasing } from '../../../utils/supports/linear-easing.mjs';
3
3
  import { generateLinearEasing } from '../utils/linear.mjs';
4
4
  import { cubicBezierAsString } from './cubic-bezier.mjs';
@@ -8,8 +8,10 @@ function mapEasingToNativeEasing(easing, duration) {
8
8
  if (!easing) {
9
9
  return undefined;
10
10
  }
11
- else if (typeof easing === "function" && supportsLinearEasing()) {
12
- return generateLinearEasing(easing, duration);
11
+ else if (typeof easing === "function") {
12
+ return supportsLinearEasing()
13
+ ? generateLinearEasing(easing, duration)
14
+ : "ease-out";
13
15
  }
14
16
  else if (isBezierDefinition(easing)) {
15
17
  return cubicBezierAsString(easing);
@@ -2,7 +2,7 @@ import { activeAnimations } from '../../stats/animation-count.mjs';
2
2
  import { statsBuffer } from '../../stats/buffer.mjs';
3
3
  import { mapEasingToNativeEasing } from './easing/map-easing.mjs';
4
4
 
5
- function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeInOut", times, } = {}, pseudoElement = undefined) {
5
+ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duration = 300, repeat = 0, repeatType = "loop", ease = "easeOut", times, } = {}, pseudoElement = undefined) {
6
6
  const keyframeOptions = {
7
7
  [valueName]: keyframes,
8
8
  };
@@ -17,15 +17,17 @@ function startWaapiAnimation(element, valueName, keyframes, { delay = 0, duratio
17
17
  if (statsBuffer.value) {
18
18
  activeAnimations.waapi++;
19
19
  }
20
- const animation = element.animate(keyframeOptions, {
20
+ const options = {
21
21
  delay,
22
22
  duration,
23
23
  easing: !Array.isArray(easing) ? easing : "linear",
24
24
  fill: "both",
25
25
  iterations: repeat + 1,
26
26
  direction: repeatType === "reverse" ? "alternate" : "normal",
27
- pseudoElement,
28
- });
27
+ };
28
+ if (pseudoElement)
29
+ options.pseudoElement = pseudoElement;
30
+ const animation = element.animate(keyframeOptions, options);
29
31
  if (statsBuffer.value) {
30
32
  animation.finished.finally(() => {
31
33
  activeAnimations.waapi--;
@@ -0,0 +1,39 @@
1
+ import { memo } from 'motion-utils';
2
+
3
+ /**
4
+ * A list of values that can be hardware-accelerated.
5
+ */
6
+ const acceleratedValues = new Set([
7
+ "opacity",
8
+ "clipPath",
9
+ "filter",
10
+ "transform",
11
+ // TODO: Can be accelerated but currently disabled until https://issues.chromium.org/issues/41491098 is resolved
12
+ // or until we implement support for linear() easing.
13
+ // "background-color"
14
+ ]);
15
+ const supportsWaapi = /*@__PURE__*/ memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
16
+ function supportsBrowserAnimation(options) {
17
+ const { motionValue, name, repeatDelay, repeatType, damping, type } = options;
18
+ if (!motionValue ||
19
+ !motionValue.owner ||
20
+ !(motionValue.owner.current instanceof HTMLElement)) {
21
+ return false;
22
+ }
23
+ const { onUpdate, transformTemplate } = motionValue.owner.getProps();
24
+ return (supportsWaapi() &&
25
+ name &&
26
+ acceleratedValues.has(name) &&
27
+ (name !== "transform" || !transformTemplate) &&
28
+ /**
29
+ * If we're outputting values to onUpdate then we can't use WAAPI as there's
30
+ * no way to read the value from WAAPI every frame.
31
+ */
32
+ !onUpdate &&
33
+ !repeatDelay &&
34
+ repeatType !== "mirror" &&
35
+ damping !== 0 &&
36
+ type !== "inertia");
37
+ }
38
+
39
+ export { supportsBrowserAnimation };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A list of values that can be hardware-accelerated.
3
+ */
4
+ const acceleratedValues = new Set([
5
+ "opacity",
6
+ "clipPath",
7
+ "filter",
8
+ "transform",
9
+ // TODO: Can be accelerated but currently disabled until https://issues.chromium.org/issues/41491098 is resolved
10
+ // or until we implement support for linear() easing.
11
+ // "background-color"
12
+ ]);
13
+
14
+ export { acceleratedValues };
@@ -1,7 +1,8 @@
1
+ import { supportsLinearEasing } from '../../../utils/supports/linear-easing.mjs';
1
2
  import { isGenerator } from '../../generators/utils/is-generator.mjs';
2
3
 
3
4
  function applyGeneratorOptions({ type, ...options }) {
4
- if (isGenerator(type)) {
5
+ if (isGenerator(type) && supportsLinearEasing()) {
5
6
  return type.applyToOptions(options);
6
7
  }
7
8
  else {
@@ -0,0 +1,18 @@
1
+ import { anticipate, backInOut, circInOut } from 'motion-utils';
2
+
3
+ const unsupportedEasingFunctions = {
4
+ anticipate,
5
+ backInOut,
6
+ circInOut,
7
+ };
8
+ function isUnsupportedEase(key) {
9
+ return key in unsupportedEasingFunctions;
10
+ }
11
+ function replaceStringEasing(transition) {
12
+ if (typeof transition.ease === "string" &&
13
+ isUnsupportedEase(transition.ease)) {
14
+ transition.ease = unsupportedEasingFunctions[transition.ease];
15
+ }
16
+ }
17
+
18
+ export { replaceStringEasing };
@@ -16,7 +16,7 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
16
16
  acc[key] = createRenderStep(flagRunNextFrame, allowKeepAlive ? key : undefined);
17
17
  return acc;
18
18
  }, {});
19
- const { read, resolveKeyframes, update, preRender, render, postRender } = steps;
19
+ const { setup, read, resolveKeyframes, update, preRender, render, postRender, } = steps;
20
20
  const processBatch = () => {
21
21
  const timestamp = MotionGlobalConfig.useManualTiming
22
22
  ? state.timestamp
@@ -30,6 +30,7 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
30
30
  state.timestamp = timestamp;
31
31
  state.isProcessing = true;
32
32
  // Unrolled render loop for better per-frame performance
33
+ setup.process(state);
33
34
  read.process(state);
34
35
  resolveKeyframes.process(state);
35
36
  update.process(state);
@@ -1,4 +1,5 @@
1
1
  const stepsOrder = [
2
+ "setup", // Compute
2
3
  "read", // Read
3
4
  "resolveKeyframes", // Write/Read/Write/Read
4
5
  "update", // Compute
package/dist/es/index.mjs CHANGED
@@ -1,16 +1,35 @@
1
+ export { AsyncMotionValueAnimation } from './animation/AsyncMotionValueAnimation.mjs';
1
2
  export { GroupAnimation } from './animation/GroupAnimation.mjs';
2
3
  export { GroupAnimationWithThen } from './animation/GroupAnimationWithThen.mjs';
4
+ export { JSAnimation, animateValue } from './animation/JSAnimation.mjs';
3
5
  export { NativeAnimation } from './animation/NativeAnimation.mjs';
6
+ export { NativeAnimationExtended } from './animation/NativeAnimationExtended.mjs';
7
+ export { NativeAnimationWrapper } from './animation/NativeAnimationWrapper.mjs';
8
+ export { animationMapKey, getAnimationMap } from './animation/utils/active-animations.mjs';
9
+ export { getVariableValue, parseCSSVariable } from './animation/utils/css-variables-conversion.mjs';
4
10
  export { getValueTransition } from './animation/utils/get-value-transition.mjs';
11
+ export { isCSSVariableName, isCSSVariableToken } from './animation/utils/is-css-variable.mjs';
12
+ export { inertia } from './animation/generators/inertia.mjs';
13
+ export { defaultEasing, keyframes } from './animation/generators/keyframes.mjs';
14
+ export { spring } from './animation/generators/spring/index.mjs';
5
15
  export { calcGeneratorDuration, maxGeneratorDuration } from './animation/generators/utils/calc-duration.mjs';
6
16
  export { createGeneratorEasing } from './animation/generators/utils/create-generator-easing.mjs';
7
17
  export { isGenerator } from './animation/generators/utils/is-generator.mjs';
18
+ export { DOMKeyframesResolver } from './animation/keyframes/DOMKeyframesResolver.mjs';
19
+ export { KeyframeResolver, flushKeyframeResolvers } from './animation/keyframes/KeyframesResolver.mjs';
20
+ export { defaultOffset } from './animation/keyframes/offsets/default.mjs';
21
+ export { fillOffset } from './animation/keyframes/offsets/fill.mjs';
22
+ export { convertOffsetToTimes } from './animation/keyframes/offsets/time.mjs';
23
+ export { applyPxDefaults } from './animation/keyframes/utils/apply-px-defaults.mjs';
24
+ export { fillWildcards } from './animation/keyframes/utils/fill-wildcards.mjs';
8
25
  export { cubicBezierAsString } from './animation/waapi/easing/cubic-bezier.mjs';
9
26
  export { isWaapiSupportedEasing } from './animation/waapi/easing/is-supported.mjs';
10
27
  export { mapEasingToNativeEasing } from './animation/waapi/easing/map-easing.mjs';
11
28
  export { supportedWaapiEasing } from './animation/waapi/easing/supported.mjs';
12
29
  export { startWaapiAnimation } from './animation/waapi/start-waapi-animation.mjs';
13
- export { attachTimeline } from './animation/waapi/utils/attach-timeline.mjs';
30
+ export { supportsPartialKeyframes } from './animation/waapi/supports/partial-keyframes.mjs';
31
+ export { supportsBrowserAnimation } from './animation/waapi/supports/waapi.mjs';
32
+ export { acceleratedValues } from './animation/waapi/utils/accelerated-values.mjs';
14
33
  export { generateLinearEasing } from './animation/waapi/utils/linear.mjs';
15
34
  export { createRenderBatcher } from './frameloop/batcher.mjs';
16
35
  export { cancelMicrotask, microtask } from './frameloop/microtask.mjs';
@@ -21,15 +40,43 @@ export { hover } from './gestures/hover.mjs';
21
40
  export { press } from './gestures/press/index.mjs';
22
41
  export { isNodeOrChild } from './gestures/utils/is-node-or-child.mjs';
23
42
  export { isPrimaryPointer } from './gestures/utils/is-primary-pointer.mjs';
43
+ export { parseValueFromTransform, readTransformValue } from './render/dom/parse-transform.mjs';
44
+ export { getComputedStyle } from './render/dom/style-computed.mjs';
45
+ export { setStyle } from './render/dom/style-set.mjs';
46
+ export { positionalKeys } from './render/utils/keys-position.mjs';
47
+ export { transformPropOrder, transformProps } from './render/utils/keys-transform.mjs';
48
+ export { observeTimeline } from './scroll/observe.mjs';
24
49
  export { recordStats } from './stats/index.mjs';
25
50
  export { activeAnimations } from './stats/animation-count.mjs';
26
51
  export { statsBuffer } from './stats/buffer.mjs';
27
- export { isBezierDefinition } from './utils/is-bezier-definition.mjs';
52
+ export { interpolate } from './utils/interpolate.mjs';
53
+ export { mix } from './utils/mix/index.mjs';
54
+ export { mixColor, mixLinearColor } from './utils/mix/color.mjs';
55
+ export { getMixer, mixArray, mixComplex, mixObject } from './utils/mix/complex.mjs';
56
+ export { mixImmediate } from './utils/mix/immediate.mjs';
57
+ export { mixNumber } from './utils/mix/number.mjs';
58
+ export { invisibleValues, mixVisibility } from './utils/mix/visibility.mjs';
28
59
  export { resolveElements } from './utils/resolve-elements.mjs';
29
60
  export { supportsFlags } from './utils/supports/flags.mjs';
30
61
  export { supportsLinearEasing } from './utils/supports/linear-easing.mjs';
31
62
  export { supportsScrollTimeline } from './utils/supports/scroll-timeline.mjs';
32
63
  export { MotionValue, collectMotionValues, motionValue } from './value/index.mjs';
64
+ export { color } from './value/types/color/index.mjs';
65
+ export { hex } from './value/types/color/hex.mjs';
66
+ export { hsla } from './value/types/color/hsla.mjs';
67
+ export { hslaToRgba } from './value/types/color/hsla-to-rgba.mjs';
68
+ export { rgbUnit, rgba } from './value/types/color/rgba.mjs';
69
+ export { analyseComplexValue, complex } from './value/types/complex/index.mjs';
70
+ export { dimensionValueTypes, findDimensionValueType } from './value/types/dimensions.mjs';
71
+ export { defaultValueTypes, getDefaultValueType } from './value/types/maps/defaults.mjs';
72
+ export { numberValueTypes } from './value/types/maps/number.mjs';
73
+ export { transformValueTypes } from './value/types/maps/transform.mjs';
74
+ export { alpha, number, scale } from './value/types/numbers/index.mjs';
75
+ export { degrees, percent, progressPercentage, px, vh, vw } from './value/types/numbers/units.mjs';
76
+ export { testValueType } from './value/types/test.mjs';
77
+ export { getAnimatableNone } from './value/types/utils/animatable-none.mjs';
78
+ export { findValueType } from './value/types/utils/find.mjs';
79
+ export { getValueAsType } from './value/types/utils/get-as-type.mjs';
33
80
  export { ViewTransitionBuilder, animateView } from './view/index.mjs';
34
81
  export { cancelSync, sync } from './frameloop/index-legacy.mjs';
35
82
  export { cancelFrame, frame, frameData, frameSteps } from './frameloop/frame.mjs';
@@ -0,0 +1,3 @@
1
+ const isCSSVar = (name) => name.startsWith("--");
2
+
3
+ export { isCSSVar };
@@ -0,0 +1,83 @@
1
+ const radToDeg = (rad) => (rad * 180) / Math.PI;
2
+ const rotate = (v) => {
3
+ const angle = radToDeg(Math.atan2(v[1], v[0]));
4
+ return rebaseAngle(angle);
5
+ };
6
+ const matrix2dParsers = {
7
+ x: 4,
8
+ y: 5,
9
+ translateX: 4,
10
+ translateY: 5,
11
+ scaleX: 0,
12
+ scaleY: 3,
13
+ scale: (v) => (Math.abs(v[0]) + Math.abs(v[3])) / 2,
14
+ rotate,
15
+ rotateZ: rotate,
16
+ skewX: (v) => radToDeg(Math.atan(v[1])),
17
+ skewY: (v) => radToDeg(Math.atan(v[2])),
18
+ skew: (v) => (Math.abs(v[1]) + Math.abs(v[2])) / 2,
19
+ };
20
+ const rebaseAngle = (angle) => {
21
+ angle = angle % 360;
22
+ if (angle < 0)
23
+ angle += 360;
24
+ return angle;
25
+ };
26
+ const rotateZ = rotate;
27
+ const scaleX = (v) => Math.sqrt(v[0] * v[0] + v[1] * v[1]);
28
+ const scaleY = (v) => Math.sqrt(v[4] * v[4] + v[5] * v[5]);
29
+ const matrix3dParsers = {
30
+ x: 12,
31
+ y: 13,
32
+ z: 14,
33
+ translateX: 12,
34
+ translateY: 13,
35
+ translateZ: 14,
36
+ scaleX,
37
+ scaleY,
38
+ scale: (v) => (scaleX(v) + scaleY(v)) / 2,
39
+ rotateX: (v) => rebaseAngle(radToDeg(Math.atan2(v[6], v[5]))),
40
+ rotateY: (v) => rebaseAngle(radToDeg(Math.atan2(-v[2], v[0]))),
41
+ rotateZ,
42
+ rotate: rotateZ,
43
+ skewX: (v) => radToDeg(Math.atan(v[4])),
44
+ skewY: (v) => radToDeg(Math.atan(v[1])),
45
+ skew: (v) => (Math.abs(v[1]) + Math.abs(v[4])) / 2,
46
+ };
47
+ function defaultTransformValue(name) {
48
+ return name.includes("scale") ? 1 : 0;
49
+ }
50
+ function parseValueFromTransform(transform, name) {
51
+ if (!transform || transform === "none") {
52
+ return defaultTransformValue(name);
53
+ }
54
+ const matrix3dMatch = transform.match(/^matrix3d\(([-\d.e\s,]+)\)$/u);
55
+ let parsers;
56
+ let match;
57
+ if (matrix3dMatch) {
58
+ parsers = matrix3dParsers;
59
+ match = matrix3dMatch;
60
+ }
61
+ else {
62
+ const matrix2dMatch = transform.match(/^matrix\(([-\d.e\s,]+)\)$/u);
63
+ parsers = matrix2dParsers;
64
+ match = matrix2dMatch;
65
+ }
66
+ if (!match) {
67
+ return defaultTransformValue(name);
68
+ }
69
+ const valueParser = parsers[name];
70
+ const values = match[1].split(",").map(convertTransformToNumber);
71
+ return typeof valueParser === "function"
72
+ ? valueParser(values)
73
+ : values[valueParser];
74
+ }
75
+ const readTransformValue = (instance, name) => {
76
+ const { transform = "none" } = getComputedStyle(instance);
77
+ return parseValueFromTransform(transform, name);
78
+ };
79
+ function convertTransformToNumber(value) {
80
+ return parseFloat(value.trim());
81
+ }
82
+
83
+ export { parseValueFromTransform, readTransformValue };
@@ -0,0 +1,10 @@
1
+ import { isCSSVar } from './is-css-var.mjs';
2
+
3
+ function getComputedStyle(element, name) {
4
+ const computedStyle = window.getComputedStyle(element);
5
+ return isCSSVar(name)
6
+ ? computedStyle.getPropertyValue(name)
7
+ : computedStyle[name];
8
+ }
9
+
10
+ export { getComputedStyle };
@@ -0,0 +1,9 @@
1
+ import { isCSSVar } from './is-css-var.mjs';
2
+
3
+ function setStyle(element, name, value) {
4
+ isCSSVar(name)
5
+ ? element.style.setProperty(name, value)
6
+ : (element.style[name] = value);
7
+ }
8
+
9
+ export { setStyle };
@@ -0,0 +1,13 @@
1
+ import { transformPropOrder } from './keys-transform.mjs';
2
+
3
+ const positionalKeys = new Set([
4
+ "width",
5
+ "height",
6
+ "top",
7
+ "left",
8
+ "right",
9
+ "bottom",
10
+ ...transformPropOrder,
11
+ ]);
12
+
13
+ export { positionalKeys };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Generate a list of every possible transform key.
3
+ */
4
+ const transformPropOrder = [
5
+ "transformPerspective",
6
+ "x",
7
+ "y",
8
+ "z",
9
+ "translateX",
10
+ "translateY",
11
+ "translateZ",
12
+ "scale",
13
+ "scaleX",
14
+ "scaleY",
15
+ "rotate",
16
+ "rotateX",
17
+ "rotateY",
18
+ "rotateZ",
19
+ "skew",
20
+ "skewX",
21
+ "skewY",
22
+ ];
23
+ /**
24
+ * A quick lookup for transform props.
25
+ */
26
+ const transformProps = /*@__PURE__*/ (() => new Set(transformPropOrder))();
27
+
28
+ export { transformPropOrder, transformProps };
@@ -0,0 +1,18 @@
1
+ import { frame, cancelFrame } from '../frameloop/frame.mjs';
2
+
3
+ function observeTimeline(update, timeline) {
4
+ let prevProgress;
5
+ const onFrame = () => {
6
+ const { currentTime } = timeline;
7
+ const percentage = currentTime === null ? 0 : currentTime.value;
8
+ const progress = percentage / 100;
9
+ if (prevProgress !== progress) {
10
+ update(progress);
11
+ }
12
+ prevProgress = progress;
13
+ };
14
+ frame.update(onFrame, true);
15
+ return () => cancelFrame(onFrame);
16
+ }
17
+
18
+ export { observeTimeline };
@@ -44,6 +44,7 @@ function reportStats() {
44
44
  cancelFrame(record);
45
45
  const summary = {
46
46
  frameloop: {
47
+ setup: summarise(value.frameloop.setup),
47
48
  rate: summarise(value.frameloop.rate),
48
49
  read: summarise(value.frameloop.read),
49
50
  resolveKeyframes: summarise(value.frameloop.resolveKeyframes),
@@ -81,6 +82,7 @@ function recordStats() {
81
82
  const newStatsBuffer = statsBuffer;
82
83
  newStatsBuffer.value = {
83
84
  frameloop: {
85
+ setup: [],
84
86
  rate: [],
85
87
  read: [],
86
88
  resolveKeyframes: [],