framer-motion 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 (154) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/client.js +1 -1
  3. package/dist/cjs/{create-BErHrlzf.js → create-D5a67TOR.js} +99 -2828
  4. package/dist/cjs/dom-mini.js +82 -66
  5. package/dist/cjs/dom.js +276 -3011
  6. package/dist/cjs/index.js +149 -206
  7. package/dist/cjs/m.js +13 -170
  8. package/dist/cjs/mini.js +77 -9
  9. package/dist/dom-mini.js +1 -1
  10. package/dist/dom.d.ts +5 -94
  11. package/dist/dom.js +1 -1
  12. package/dist/es/animation/animate/sequence.mjs +1 -1
  13. package/dist/es/animation/animators/waapi/animate-elements.mjs +78 -10
  14. package/dist/es/animation/interfaces/motion-value.mjs +11 -30
  15. package/dist/es/animation/interfaces/visual-element-target.mjs +1 -2
  16. package/dist/es/animation/optimized-appear/store-id.mjs +1 -1
  17. package/dist/es/animation/sequence/create.mjs +2 -5
  18. package/dist/es/animation/sequence/utils/edit.mjs +2 -3
  19. package/dist/es/animation/utils/default-transitions.mjs +1 -1
  20. package/dist/es/animation/utils/stagger.mjs +1 -1
  21. package/dist/es/components/Reorder/utils/check-reorder.mjs +1 -1
  22. package/dist/es/dom.mjs +2 -18
  23. package/dist/es/gestures/drag/VisualElementDragControls.mjs +1 -3
  24. package/dist/es/gestures/drag/utils/constraints.mjs +2 -3
  25. package/dist/es/gestures/focus.mjs +1 -1
  26. package/dist/es/gestures/pan/PanSession.mjs +1 -2
  27. package/dist/es/index.mjs +3 -24
  28. package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -1
  29. package/dist/es/projection/animation/mix-values.mjs +2 -4
  30. package/dist/es/projection/geometry/delta-apply.mjs +1 -1
  31. package/dist/es/projection/geometry/delta-calc.mjs +1 -1
  32. package/dist/es/projection/geometry/delta-remove.mjs +1 -2
  33. package/dist/es/projection/node/create-projection-node.mjs +3 -7
  34. package/dist/es/projection/styles/scale-border-radius.mjs +1 -1
  35. package/dist/es/projection/styles/scale-box-shadow.mjs +1 -2
  36. package/dist/es/projection/styles/scale-correction.mjs +1 -1
  37. package/dist/es/projection.mjs +1 -3
  38. package/dist/es/render/VisualElement.mjs +2 -9
  39. package/dist/es/render/dom/DOMVisualElement.mjs +1 -1
  40. package/dist/es/render/dom/scroll/attach-animation.mjs +17 -0
  41. package/dist/es/render/dom/scroll/attach-function.mjs +23 -0
  42. package/dist/es/render/dom/scroll/index.mjs +6 -82
  43. package/dist/es/render/dom/scroll/offsets/index.mjs +2 -3
  44. package/dist/es/render/dom/scroll/utils/get-timeline.mjs +30 -0
  45. package/dist/es/render/html/HTMLVisualElement.mjs +1 -3
  46. package/dist/es/render/html/utils/build-styles.mjs +1 -4
  47. package/dist/es/render/html/utils/build-transform.mjs +1 -3
  48. package/dist/es/render/svg/SVGVisualElement.mjs +1 -3
  49. package/dist/es/render/svg/config-motion.mjs +1 -2
  50. package/dist/es/render/svg/utils/path.mjs +1 -1
  51. package/dist/es/render/svg/utils/scrape-motion-values.mjs +1 -1
  52. package/dist/es/render/svg/utils/transform-origin.mjs +1 -1
  53. package/dist/es/render/utils/motion-values.mjs +1 -1
  54. package/dist/es/utils/delay.mjs +1 -1
  55. package/dist/es/utils/transform.mjs +1 -1
  56. package/dist/es/utils/use-cycle.mjs +1 -1
  57. package/dist/es/utils/use-instant-transition.mjs +4 -4
  58. package/dist/es/value/use-spring.mjs +2 -3
  59. package/dist/es/value/use-will-change/get-will-change-name.mjs +1 -2
  60. package/dist/framer-motion.dev.js +3864 -3405
  61. package/dist/framer-motion.js +1 -1
  62. package/dist/m.d.ts +3 -50
  63. package/dist/mini.js +1 -1
  64. package/dist/size-rollup-animate.js +1 -1
  65. package/dist/size-rollup-dom-animation-assets.js +1 -1
  66. package/dist/size-rollup-dom-animation.js +1 -1
  67. package/dist/size-rollup-dom-max-assets.js +1 -1
  68. package/dist/size-rollup-dom-max.js +1 -1
  69. package/dist/size-rollup-m.js +1 -1
  70. package/dist/size-rollup-motion.js +1 -1
  71. package/dist/size-rollup-scroll.js +1 -1
  72. package/dist/size-rollup-waapi-animate.js +1 -1
  73. package/dist/types/client.d.ts +4 -3
  74. package/dist/types/index.d.ts +56 -351
  75. package/dist/{types.d-B50aGbjN.d.ts → types.d-B1Voffvi.d.ts} +3 -138
  76. package/package.json +9 -9
  77. package/dist/es/animation/animators/AcceleratedAnimation.mjs +0 -319
  78. package/dist/es/animation/animators/BaseAnimation.mjs +0 -120
  79. package/dist/es/animation/animators/MainThreadAnimation.mjs +0 -394
  80. package/dist/es/animation/animators/drivers/driver-frameloop.mjs +0 -16
  81. package/dist/es/animation/animators/utils/accelerated-values.mjs +0 -14
  82. package/dist/es/animation/animators/utils/can-animate.mjs +0 -42
  83. package/dist/es/animation/animators/waapi/utils/supports-waapi.mjs +0 -5
  84. package/dist/es/animation/generators/inertia.mjs +0 -87
  85. package/dist/es/animation/generators/keyframes.mjs +0 -51
  86. package/dist/es/animation/generators/spring/defaults.mjs +0 -27
  87. package/dist/es/animation/generators/spring/find.mjs +0 -85
  88. package/dist/es/animation/generators/spring/index.mjs +0 -174
  89. package/dist/es/animation/generators/utils/velocity.mjs +0 -9
  90. package/dist/es/animation/utils/is-animatable.mjs +0 -30
  91. package/dist/es/animation/utils/is-none.mjs +0 -15
  92. package/dist/es/easing/anticipate.mjs +0 -5
  93. package/dist/es/easing/back.mjs +0 -9
  94. package/dist/es/easing/circ.mjs +0 -8
  95. package/dist/es/easing/cubic-bezier.mjs +0 -51
  96. package/dist/es/easing/ease.mjs +0 -7
  97. package/dist/es/easing/modifiers/mirror.mjs +0 -5
  98. package/dist/es/easing/modifiers/reverse.mjs +0 -5
  99. package/dist/es/easing/steps.mjs +0 -15
  100. package/dist/es/easing/utils/get-easing-for-segment.mjs +0 -8
  101. package/dist/es/easing/utils/is-easing-array.mjs +0 -5
  102. package/dist/es/easing/utils/map.mjs +0 -37
  103. package/dist/es/render/dom/DOMKeyframesResolver.mjs +0 -130
  104. package/dist/es/render/dom/scroll/observe.mjs +0 -18
  105. package/dist/es/render/dom/utils/css-variables-conversion.mjs +0 -42
  106. package/dist/es/render/dom/utils/is-css-variable.mjs +0 -15
  107. package/dist/es/render/dom/utils/unit-conversion.mjs +0 -36
  108. package/dist/es/render/dom/value-types/animatable-none.mjs +0 -15
  109. package/dist/es/render/dom/value-types/defaults.mjs +0 -30
  110. package/dist/es/render/dom/value-types/dimensions.mjs +0 -15
  111. package/dist/es/render/dom/value-types/find.mjs +0 -15
  112. package/dist/es/render/dom/value-types/get-as-type.mjs +0 -10
  113. package/dist/es/render/dom/value-types/number-browser.mjs +0 -41
  114. package/dist/es/render/dom/value-types/number.mjs +0 -18
  115. package/dist/es/render/dom/value-types/test.mjs +0 -6
  116. package/dist/es/render/dom/value-types/transform.mjs +0 -31
  117. package/dist/es/render/dom/value-types/type-auto.mjs +0 -9
  118. package/dist/es/render/dom/value-types/type-int.mjs +0 -8
  119. package/dist/es/render/html/utils/keys-position.mjs +0 -13
  120. package/dist/es/render/html/utils/keys-transform.mjs +0 -28
  121. package/dist/es/render/html/utils/make-none-animatable.mjs +0 -30
  122. package/dist/es/render/html/utils/parse-transform.mjs +0 -83
  123. package/dist/es/render/utils/KeyframesResolver.mjs +0 -163
  124. package/dist/es/utils/clamp.mjs +0 -9
  125. package/dist/es/utils/hsla-to-rgba.mjs +0 -42
  126. package/dist/es/utils/interpolate.mjs +0 -76
  127. package/dist/es/utils/is-numerical-string.mjs +0 -6
  128. package/dist/es/utils/is-zero-value-string.mjs +0 -6
  129. package/dist/es/utils/mix/color.mjs +0 -47
  130. package/dist/es/utils/mix/complex.mjs +0 -93
  131. package/dist/es/utils/mix/immediate.mjs +0 -5
  132. package/dist/es/utils/mix/index.mjs +0 -14
  133. package/dist/es/utils/mix/number.mjs +0 -26
  134. package/dist/es/utils/mix/visibility.mjs +0 -16
  135. package/dist/es/utils/offsets/default.mjs +0 -9
  136. package/dist/es/utils/offsets/fill.mjs +0 -12
  137. package/dist/es/utils/offsets/time.mjs +0 -5
  138. package/dist/es/utils/pipe.mjs +0 -11
  139. package/dist/es/utils/use-instant-transition-state.mjs +0 -5
  140. package/dist/es/utils/wrap.mjs +0 -6
  141. package/dist/es/value/types/color/hex.mjs +0 -40
  142. package/dist/es/value/types/color/hsla.mjs +0 -22
  143. package/dist/es/value/types/color/index.mjs +0 -27
  144. package/dist/es/value/types/color/rgba.mjs +0 -25
  145. package/dist/es/value/types/color/utils.mjs +0 -29
  146. package/dist/es/value/types/complex/filter.mjs +0 -30
  147. package/dist/es/value/types/complex/index.mjs +0 -91
  148. package/dist/es/value/types/numbers/index.mjs +0 -17
  149. package/dist/es/value/types/numbers/units.mjs +0 -17
  150. package/dist/es/value/types/utils/color-regex.mjs +0 -3
  151. package/dist/es/value/types/utils/float-regex.mjs +0 -3
  152. package/dist/es/value/types/utils/is-nullish.mjs +0 -5
  153. package/dist/es/value/types/utils/sanitize.mjs +0 -5
  154. package/dist/es/value/types/utils/single-color-regex.mjs +0 -3
@@ -1,38 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { Easing, TransformProperties, SVGPathProperties, VariableKeyframesDefinition, MotionValue, AnimationPlaybackControls, ValueAnimationOptions, Transition as Transition$1, EasingFunction, ProgressTimeline, Batcher } from 'motion-dom';
3
2
  import * as React$1 from 'react';
4
3
  import { SVGAttributes, CSSProperties, PropsWithoutRef, RefAttributes, JSX } from 'react';
5
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
-
7
- interface Point {
8
- x: number;
9
- y: number;
10
- }
11
- interface Axis {
12
- min: number;
13
- max: number;
14
- }
15
- interface Box {
16
- x: Axis;
17
- y: Axis;
18
- }
19
- interface BoundingBox {
20
- top: number;
21
- right: number;
22
- bottom: number;
23
- left: number;
24
- }
25
- interface AxisDelta {
26
- translate: number;
27
- scale: number;
28
- origin: number;
29
- originPoint: number;
30
- }
31
- interface Delta {
32
- x: AxisDelta;
33
- y: AxisDelta;
34
- }
35
- type TransformPoint = (point: Point) => Point;
5
+ import { TransformProperties, SVGPathProperties, VariableKeyframesDefinition, MotionValue, AnimationPlaybackControls, KeyframeResolver, OnKeyframesResolved, Transition as Transition$1, Batcher } from 'motion-dom';
6
+ import { Easing, Point, TransformPoint, Box, Axis, Delta, BoundingBox } from 'motion-utils';
36
7
 
37
8
  type GenericKeyframesTarget<V> = V[] | Array<null | V>;
38
9
  /**
@@ -1368,50 +1339,6 @@ interface AnimationTypeState {
1368
1339
  prevProp?: VariantLabels | TargetAndTransition;
1369
1340
  }
1370
1341
 
1371
- type UnresolvedKeyframes<T extends string | number> = Array<T | null>;
1372
- type ResolvedKeyframes<T extends string | number> = Array<T>;
1373
- type OnKeyframesResolved<T extends string | number> = (resolvedKeyframes: ResolvedKeyframes<T>, finalKeyframe: T) => void;
1374
- declare class KeyframeResolver<T extends string | number = any> {
1375
- name?: string;
1376
- element?: VisualElement<any>;
1377
- finalKeyframe?: T;
1378
- suspendedScrollY?: number;
1379
- protected unresolvedKeyframes: UnresolvedKeyframes<string | number>;
1380
- private motionValue?;
1381
- private onComplete;
1382
- /**
1383
- * Track whether this resolver has completed. Once complete, it never
1384
- * needs to attempt keyframe resolution again.
1385
- */
1386
- private isComplete;
1387
- /**
1388
- * Track whether this resolver is async. If it is, it'll be added to the
1389
- * resolver queue and flushed in the next frame. Resolvers that aren't going
1390
- * to trigger read/write thrashing don't need to be async.
1391
- */
1392
- private isAsync;
1393
- /**
1394
- * Track whether this resolver needs to perform a measurement
1395
- * to resolve its keyframes.
1396
- */
1397
- needsMeasurement: boolean;
1398
- /**
1399
- * Track whether this resolver is currently scheduled to resolve
1400
- * to allow it to be cancelled and resumed externally.
1401
- */
1402
- isScheduled: boolean;
1403
- constructor(unresolvedKeyframes: UnresolvedKeyframes<string | number>, onComplete: OnKeyframesResolved<T>, name?: string, motionValue?: MotionValue<T>, element?: VisualElement<any>, isAsync?: boolean);
1404
- scheduleResolve(): void;
1405
- readKeyframes(): void;
1406
- setFinalKeyframe(): void;
1407
- measureInitialState(): void;
1408
- renderEndStyles(): void;
1409
- measureEndState(): void;
1410
- complete(): void;
1411
- cancel(): void;
1412
- resume(): void;
1413
- }
1414
-
1415
1342
  /**
1416
1343
  * A VisualElement is an imperative abstraction around UI elements such as
1417
1344
  * HTMLElement, SVGElement, Three.Object3D etc.
@@ -2586,11 +2513,6 @@ interface MotionProps extends AnimationProps, EventProps, PanHandlers, TapHandle
2586
2513
  }
2587
2514
 
2588
2515
  type ResolveKeyframes<V extends string | number> = (keyframes: V[], onComplete: OnKeyframesResolved<V>, name?: string, motionValue?: any) => KeyframeResolver<V>;
2589
- interface ValueAnimationOptionsWithRenderContext<V extends string | number = number> extends ValueAnimationOptions<V> {
2590
- KeyframeResolver?: typeof KeyframeResolver;
2591
- motionValue?: MotionValue<V>;
2592
- element?: VisualElement;
2593
- }
2594
2516
  type AnimationDefinition = VariantLabels | TargetAndTransition | TargetResolver;
2595
2517
  /**
2596
2518
  * @public
@@ -2877,63 +2799,6 @@ type HTMLMotionComponents = {
2877
2799
  [K in keyof HTMLElements]: ForwardRefComponent<HTMLElements[K], HTMLMotionProps<K>>;
2878
2800
  };
2879
2801
 
2880
- interface ScrollOptions {
2881
- source?: HTMLElement;
2882
- container?: HTMLElement;
2883
- target?: Element;
2884
- axis?: "x" | "y";
2885
- offset?: ScrollOffset;
2886
- }
2887
- type OnScrollProgress = (progress: number) => void;
2888
- type OnScrollWithInfo = (progress: number, info: ScrollInfo) => void;
2889
- type OnScroll = OnScrollProgress | OnScrollWithInfo;
2890
- interface AxisScrollInfo {
2891
- current: number;
2892
- offset: number[];
2893
- progress: number;
2894
- scrollLength: number;
2895
- velocity: number;
2896
- targetOffset: number;
2897
- targetLength: number;
2898
- containerLength: number;
2899
- interpolatorOffsets?: number[];
2900
- interpolate?: EasingFunction;
2901
- }
2902
- interface ScrollInfo {
2903
- time: number;
2904
- x: AxisScrollInfo;
2905
- y: AxisScrollInfo;
2906
- }
2907
- type OnScrollInfo = (info: ScrollInfo) => void;
2908
- type SupportedEdgeUnit = "px" | "vw" | "vh" | "%";
2909
- type EdgeUnit = `${number}${SupportedEdgeUnit}`;
2910
- type NamedEdges = "start" | "end" | "center";
2911
- type EdgeString = NamedEdges | EdgeUnit | `${number}`;
2912
- type Edge = EdgeString | number;
2913
- type ProgressIntersection = [number, number];
2914
- type Intersection = `${Edge} ${Edge}`;
2915
- type ScrollOffset = Array<Edge | Intersection | ProgressIntersection>;
2916
- interface ScrollInfoOptions {
2917
- container?: HTMLElement;
2918
- target?: Element;
2919
- axis?: "x" | "y";
2920
- offset?: ScrollOffset;
2921
- }
2922
-
2923
- declare global {
2924
- interface Window {
2925
- ScrollTimeline: ScrollTimeline;
2926
- }
2927
- }
2928
- declare class ScrollTimeline implements ProgressTimeline {
2929
- constructor(options: ScrollOptions);
2930
- currentTime: null | {
2931
- value: number;
2932
- };
2933
- cancel?: VoidFunction;
2934
- }
2935
- declare function scroll(onScroll: OnScroll | AnimationPlaybackControls, { axis, ...options }?: ScrollOptions): VoidFunction;
2936
-
2937
2802
  type UnionStringArray<T extends Readonly<string[]>> = T[number];
2938
2803
  declare const svgElements: readonly ["animate", "circle", "defs", "desc", "ellipse", "g", "image", "line", "filter", "marker", "mask", "metadata", "path", "pattern", "polygon", "polyline", "rect", "stop", "svg", "switch", "symbol", "text", "tspan", "use", "view", "clipPath", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "foreignObject", "linearGradient", "radialGradient", "textPath"];
2939
2804
  type SVGElements = UnionStringArray<typeof svgElements>;
@@ -3014,4 +2879,4 @@ declare global {
3014
2879
 
3015
2880
  type DOMMotionComponents = HTMLMotionComponents & SVGMotionComponents;
3016
2881
 
3017
- export { type ForwardRefComponent as $, type Axis as A, type Box as B, type CustomValueType as C, type DOMMotionComponents as D, type EventInfo as E, type FeatureBundle as F, type GenericKeyframesTarget as G, type HTMLMotionProps as H, type IProjectionNode as I, SwitchLayoutGroupContext as J, KeyframeResolver as K, type DragElastic as L, type MotionProps as M, type DraggableProps as N, type OnScrollInfo as O, type Point as P, type DragHandlers as Q, type ResolvedKeyframes as R, type ScrollInfoOptions as S, type TapHandlers as T, type LayoutProps as U, type ValueAnimationOptionsWithRenderContext as V, type AnimationProps as W, type MotionAdvancedProps as X, type MotionStyle as Y, type MotionTransform as Z, type VariantLabels as _, MotionConfigContext as a, type SVGAttributesAsMotionValues as a0, type SVGMotionProps as a1, type AnimationLifecycles as a2, type CreateVisualElement as a3, FlatTree as a4, type Inertia as a5, type Keyframes as a6, type KeyframesTarget as a7, type None as a8, type Orchestration as a9, type Repeat as aa, type ResolvedKeyframesTarget as ab, type ResolvedSingleTarget as ac, type ResolvedValueTarget as ad, type SingleTarget as ae, type Spring as af, type Target as ag, type TargetAndTransition as ah, type Transition as ai, type Tween as aj, type ValueTarget as ak, type Variant as al, type Variants as am, type ResolveKeyframes as an, scroll as ao, type HydratedFeatureDefinition as ap, type HydratedFeatureDefinitions as aq, type FeatureDefinition as ar, type FeatureDefinitions as as, type FeaturePackage as at, type LazyFeatureBundle as au, type RenderComponent as av, type BoundingBox as aw, type AxisDelta as ax, type Delta as ay, type TransformPoint as az, type HTMLElements as b, type MotionComponentProps as c, type HTMLMotionComponents as d, type SVGMotionComponents as e, type FeaturePackages as f, type AnimationControls as g, VisualElement as h, type AnimationDefinition as i, type VisualElementAnimationOptions as j, type ResolvedValues as k, type HTMLRenderState as l, type ScrapeMotionValuesFromProps as m, makeUseVisualState as n, type VisualState as o, type AnimationType as p, DragControls as q, type PanInfo as r, type FocusHandlers as s, type HoverHandlers as t, useDragControls as u, type PanHandlers as v, type TapInfo as w, createRendererMotionComponent as x, optimizedAppearDataAttribute as y, PresenceContext as z };
2882
+ export { type KeyframesTarget as $, type AnimationControls as A, type MotionAdvancedProps as B, type CustomValueType as C, type DOMMotionComponents as D, type EventInfo as E, type FeatureBundle as F, type GenericKeyframesTarget as G, type HTMLMotionProps as H, type IProjectionNode as I, type MotionStyle as J, type MotionTransform as K, type LayoutProps as L, type MotionProps as M, type VariantLabels as N, type ForwardRefComponent as O, type PanInfo as P, type SVGAttributesAsMotionValues as Q, type ResolvedValues as R, type SVGMotionComponents as S, type TapHandlers as T, type SVGMotionProps as U, VisualElement as V, type AnimationLifecycles as W, type CreateVisualElement as X, FlatTree as Y, type Inertia as Z, type Keyframes as _, MotionConfigContext as a, type None as a0, type Orchestration as a1, type Repeat as a2, type ResolvedKeyframesTarget as a3, type ResolvedSingleTarget as a4, type ResolvedValueTarget as a5, type SingleTarget as a6, type Spring as a7, type Target as a8, type TargetAndTransition as a9, type Transition as aa, type Tween as ab, type ValueTarget as ac, type Variant as ad, type Variants as ae, type ResolveKeyframes as af, type HydratedFeatureDefinition as ag, type HydratedFeatureDefinitions as ah, type FeatureDefinition as ai, type FeatureDefinitions as aj, type FeaturePackage as ak, type LazyFeatureBundle as al, type RenderComponent as am, type HTMLElements as b, type MotionComponentProps as c, type HTMLMotionComponents as d, type FeaturePackages as e, type AnimationDefinition as f, type VisualElementAnimationOptions as g, type HTMLRenderState as h, type ScrapeMotionValuesFromProps as i, type VisualState as j, type AnimationType as k, DragControls as l, makeUseVisualState as m, type FocusHandlers as n, type HoverHandlers as o, type PanHandlers as p, type TapInfo as q, createRendererMotionComponent as r, optimizedAppearDataAttribute as s, PresenceContext as t, useDragControls as u, SwitchLayoutGroupContext as v, type DragElastic as w, type DraggableProps as x, type DragHandlers as y, type AnimationProps as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framer-motion",
3
- "version": "12.7.4",
3
+ "version": "12.7.5-alpha.1",
4
4
  "description": "A simple and powerful JavaScript animation library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/es/index.mjs",
@@ -87,8 +87,8 @@
87
87
  "measure": "rollup -c ./rollup.size.config.mjs"
88
88
  },
89
89
  "dependencies": {
90
- "motion-dom": "^12.7.4",
91
- "motion-utils": "^12.7.2",
90
+ "motion-dom": "^12.7.5-alpha.1",
91
+ "motion-utils": "^12.7.5-alpha.1",
92
92
  "tslib": "^2.4.0"
93
93
  },
94
94
  "devDependencies": {
@@ -115,7 +115,7 @@
115
115
  "bundlesize": [
116
116
  {
117
117
  "path": "./dist/size-rollup-motion.js",
118
- "maxSize": "35.1 kB"
118
+ "maxSize": "34.9 kB"
119
119
  },
120
120
  {
121
121
  "path": "./dist/size-rollup-m.js",
@@ -123,7 +123,7 @@
123
123
  },
124
124
  {
125
125
  "path": "./dist/size-rollup-dom-animation.js",
126
- "maxSize": "17.9 kB"
126
+ "maxSize": "17.85 kB"
127
127
  },
128
128
  {
129
129
  "path": "./dist/size-rollup-dom-max.js",
@@ -131,16 +131,16 @@
131
131
  },
132
132
  {
133
133
  "path": "./dist/size-rollup-animate.js",
134
- "maxSize": "18.7 kB"
134
+ "maxSize": "19.1 kB"
135
135
  },
136
136
  {
137
137
  "path": "./dist/size-rollup-scroll.js",
138
- "maxSize": "5.3 kB"
138
+ "maxSize": "5.2 kB"
139
139
  },
140
140
  {
141
141
  "path": "./dist/size-rollup-waapi-animate.js",
142
- "maxSize": "2.7 kB"
142
+ "maxSize": "2.26 kB"
143
143
  }
144
144
  ],
145
- "gitHead": "2e0e2412223bbaa7442e0ffcefb523bf9657807e"
145
+ "gitHead": "48258e74be4cc496da5cfaf4763f523c937226eb"
146
146
  }
@@ -1,319 +0,0 @@
1
- import { supportsLinearEasing, startWaapiAnimation, attachTimeline, isGenerator, isWaapiSupportedEasing } from 'motion-dom';
2
- import { millisecondsToSeconds, secondsToMilliseconds, noop } from 'motion-utils';
3
- import { anticipate } from '../../easing/anticipate.mjs';
4
- import { backInOut } from '../../easing/back.mjs';
5
- import { circInOut } from '../../easing/circ.mjs';
6
- import { DOMKeyframesResolver } from '../../render/dom/DOMKeyframesResolver.mjs';
7
- import { BaseAnimation } from './BaseAnimation.mjs';
8
- import { MainThreadAnimation } from './MainThreadAnimation.mjs';
9
- import { acceleratedValues } from './utils/accelerated-values.mjs';
10
- import { getFinalKeyframe } from './waapi/utils/get-final-keyframe.mjs';
11
- import { supportsWaapi } from './waapi/utils/supports-waapi.mjs';
12
-
13
- /**
14
- * 10ms is chosen here as it strikes a balance between smooth
15
- * results (more than one keyframe per frame at 60fps) and
16
- * keyframe quantity.
17
- */
18
- const sampleDelta = 10; //ms
19
- /**
20
- * Implement a practical max duration for keyframe generation
21
- * to prevent infinite loops
22
- */
23
- const maxDuration = 20000;
24
- /**
25
- * Check if an animation can run natively via WAAPI or requires pregenerated keyframes.
26
- * WAAPI doesn't support spring or function easings so we run these as JS animation before
27
- * handing off.
28
- */
29
- function requiresPregeneratedKeyframes(options) {
30
- return (isGenerator(options.type) ||
31
- options.type === "spring" ||
32
- !isWaapiSupportedEasing(options.ease));
33
- }
34
- function pregenerateKeyframes(keyframes, options) {
35
- /**
36
- * Create a main-thread animation to pregenerate keyframes.
37
- * We sample this at regular intervals to generate keyframes that we then
38
- * linearly interpolate between.
39
- */
40
- const sampleAnimation = new MainThreadAnimation({
41
- ...options,
42
- keyframes,
43
- repeat: 0,
44
- delay: 0,
45
- isGenerator: true,
46
- });
47
- let state = { done: false, value: keyframes[0] };
48
- const pregeneratedKeyframes = [];
49
- /**
50
- * Bail after 20 seconds of pre-generated keyframes as it's likely
51
- * we're heading for an infinite loop.
52
- */
53
- let t = 0;
54
- while (!state.done && t < maxDuration) {
55
- state = sampleAnimation.sample(t);
56
- pregeneratedKeyframes.push(state.value);
57
- t += sampleDelta;
58
- }
59
- return {
60
- times: undefined,
61
- keyframes: pregeneratedKeyframes,
62
- duration: t - sampleDelta,
63
- ease: "linear",
64
- };
65
- }
66
- const unsupportedEasingFunctions = {
67
- anticipate,
68
- backInOut,
69
- circInOut,
70
- };
71
- function isUnsupportedEase(key) {
72
- return key in unsupportedEasingFunctions;
73
- }
74
- class AcceleratedAnimation extends BaseAnimation {
75
- constructor(options) {
76
- super(options);
77
- const { name, motionValue, element, keyframes } = this.options;
78
- this.resolver = new DOMKeyframesResolver(keyframes, (resolvedKeyframes, finalKeyframe) => this.onKeyframesResolved(resolvedKeyframes, finalKeyframe), name, motionValue, element);
79
- this.resolver.scheduleResolve();
80
- }
81
- initPlayback(keyframes, finalKeyframe) {
82
- let { duration = 300, times, ease, type, motionValue, name, startTime, } = this.options;
83
- /**
84
- * If element has since been unmounted, return false to indicate
85
- * the animation failed to initialised.
86
- */
87
- if (!motionValue.owner || !motionValue.owner.current) {
88
- return false;
89
- }
90
- /**
91
- * If the user has provided an easing function name that isn't supported
92
- * by WAAPI (like "anticipate"), we need to provide the corressponding
93
- * function. This will later get converted to a linear() easing function.
94
- */
95
- if (typeof ease === "string" &&
96
- supportsLinearEasing() &&
97
- isUnsupportedEase(ease)) {
98
- ease = unsupportedEasingFunctions[ease];
99
- }
100
- /**
101
- * If this animation needs pre-generated keyframes then generate.
102
- */
103
- if (requiresPregeneratedKeyframes(this.options)) {
104
- const { onComplete, onUpdate, motionValue, element, ...options } = this.options;
105
- const pregeneratedAnimation = pregenerateKeyframes(keyframes, options);
106
- keyframes = pregeneratedAnimation.keyframes;
107
- // If this is a very short animation, ensure we have
108
- // at least two keyframes to animate between as older browsers
109
- // can't animate between a single keyframe.
110
- if (keyframes.length === 1) {
111
- keyframes[1] = keyframes[0];
112
- }
113
- duration = pregeneratedAnimation.duration;
114
- times = pregeneratedAnimation.times;
115
- ease = pregeneratedAnimation.ease;
116
- type = "keyframes";
117
- }
118
- const animation = startWaapiAnimation(motionValue.owner.current, name, keyframes, { ...this.options, duration, times, ease });
119
- // Override the browser calculated startTime with one synchronised to other JS
120
- // and WAAPI animations starting this event loop.
121
- animation.startTime = startTime ?? this.calcStartTime();
122
- if (this.pendingTimeline) {
123
- attachTimeline(animation, this.pendingTimeline);
124
- this.pendingTimeline = undefined;
125
- }
126
- else {
127
- /**
128
- * Prefer the `onfinish` prop as it's more widely supported than
129
- * the `finished` promise.
130
- *
131
- * Here, we synchronously set the provided MotionValue to the end
132
- * keyframe. If we didn't, when the WAAPI animation is finished it would
133
- * be removed from the element which would then revert to its old styles.
134
- */
135
- animation.onfinish = () => {
136
- const { onComplete } = this.options;
137
- motionValue.set(getFinalKeyframe(keyframes, this.options, finalKeyframe));
138
- onComplete && onComplete();
139
- this.cancel();
140
- this.resolveFinishedPromise();
141
- };
142
- }
143
- return {
144
- animation,
145
- duration,
146
- times,
147
- type,
148
- ease,
149
- keyframes: keyframes,
150
- };
151
- }
152
- get duration() {
153
- const { resolved } = this;
154
- if (!resolved)
155
- return 0;
156
- const { duration } = resolved;
157
- return millisecondsToSeconds(duration);
158
- }
159
- get time() {
160
- const { resolved } = this;
161
- if (!resolved)
162
- return 0;
163
- const { animation } = resolved;
164
- return millisecondsToSeconds(animation.currentTime || 0);
165
- }
166
- set time(newTime) {
167
- const { resolved } = this;
168
- if (!resolved)
169
- return;
170
- const { animation } = resolved;
171
- animation.currentTime = secondsToMilliseconds(newTime);
172
- }
173
- get speed() {
174
- const { resolved } = this;
175
- if (!resolved)
176
- return 1;
177
- const { animation } = resolved;
178
- return animation.playbackRate;
179
- }
180
- get finished() {
181
- return this.resolved.animation.finished;
182
- }
183
- set speed(newSpeed) {
184
- const { resolved } = this;
185
- if (!resolved)
186
- return;
187
- const { animation } = resolved;
188
- animation.playbackRate = newSpeed;
189
- }
190
- get state() {
191
- const { resolved } = this;
192
- if (!resolved)
193
- return "idle";
194
- const { animation } = resolved;
195
- return animation.playState;
196
- }
197
- get startTime() {
198
- const { resolved } = this;
199
- if (!resolved)
200
- return null;
201
- const { animation } = resolved;
202
- // Coerce to number as TypeScript incorrectly types this
203
- // as CSSNumberish
204
- return animation.startTime;
205
- }
206
- /**
207
- * Replace the default DocumentTimeline with another AnimationTimeline.
208
- * Currently used for scroll animations.
209
- */
210
- attachTimeline(timeline) {
211
- if (!this._resolved) {
212
- this.pendingTimeline = timeline;
213
- }
214
- else {
215
- const { resolved } = this;
216
- if (!resolved)
217
- return noop;
218
- const { animation } = resolved;
219
- attachTimeline(animation, timeline);
220
- }
221
- return noop;
222
- }
223
- play() {
224
- if (this.isStopped)
225
- return;
226
- const { resolved } = this;
227
- if (!resolved)
228
- return;
229
- const { animation } = resolved;
230
- if (animation.playState === "finished") {
231
- this.updateFinishedPromise();
232
- }
233
- animation.play();
234
- }
235
- pause() {
236
- const { resolved } = this;
237
- if (!resolved)
238
- return;
239
- const { animation } = resolved;
240
- animation.pause();
241
- }
242
- stop() {
243
- this.resolver.cancel();
244
- this.isStopped = true;
245
- if (this.state === "idle")
246
- return;
247
- this.resolveFinishedPromise();
248
- this.updateFinishedPromise();
249
- const { resolved } = this;
250
- if (!resolved)
251
- return;
252
- const { animation, keyframes, duration, type, ease, times } = resolved;
253
- if (animation.playState === "idle" ||
254
- animation.playState === "finished") {
255
- return;
256
- }
257
- /**
258
- * WAAPI doesn't natively have any interruption capabilities.
259
- *
260
- * Rather than read commited styles back out of the DOM, we can
261
- * create a renderless JS animation and sample it twice to calculate
262
- * its current value, "previous" value, and therefore allow
263
- * Motion to calculate velocity for any subsequent animation.
264
- */
265
- if (this.time) {
266
- const { motionValue, onUpdate, onComplete, element, ...options } = this.options;
267
- const sampleAnimation = new MainThreadAnimation({
268
- ...options,
269
- keyframes,
270
- duration,
271
- type,
272
- ease,
273
- times,
274
- isGenerator: true,
275
- });
276
- const sampleTime = secondsToMilliseconds(this.time);
277
- motionValue.setWithVelocity(sampleAnimation.sample(sampleTime - sampleDelta).value, sampleAnimation.sample(sampleTime).value, sampleDelta);
278
- }
279
- const { onStop } = this.options;
280
- onStop && onStop();
281
- this.cancel();
282
- }
283
- complete() {
284
- const { resolved } = this;
285
- if (!resolved)
286
- return;
287
- resolved.animation.finish();
288
- }
289
- cancel() {
290
- const { resolved } = this;
291
- if (!resolved)
292
- return;
293
- resolved.animation.cancel();
294
- }
295
- static supports(options) {
296
- const { motionValue, name, repeatDelay, repeatType, damping, type } = options;
297
- if (!motionValue ||
298
- !motionValue.owner ||
299
- !(motionValue.owner.current instanceof HTMLElement)) {
300
- return false;
301
- }
302
- const { onUpdate, transformTemplate } = motionValue.owner.getProps();
303
- return (supportsWaapi() &&
304
- name &&
305
- acceleratedValues.has(name) &&
306
- (name !== "transform" || !transformTemplate) &&
307
- /**
308
- * If we're outputting values to onUpdate then we can't use WAAPI as there's
309
- * no way to read the value from WAAPI every frame.
310
- */
311
- !onUpdate &&
312
- !repeatDelay &&
313
- repeatType !== "mirror" &&
314
- damping !== 0 &&
315
- type !== "inertia");
316
- }
317
- }
318
-
319
- export { AcceleratedAnimation };
@@ -1,120 +0,0 @@
1
- import { time } from 'motion-dom';
2
- import { flushKeyframeResolvers } from '../../render/utils/KeyframesResolver.mjs';
3
- import { instantAnimationState } from '../../utils/use-instant-transition-state.mjs';
4
- import { canAnimate } from './utils/can-animate.mjs';
5
- import { getFinalKeyframe } from './waapi/utils/get-final-keyframe.mjs';
6
-
7
- /**
8
- * Maximum time allowed between an animation being created and it being
9
- * resolved for us to use the latter as the start time.
10
- *
11
- * This is to ensure that while we prefer to "start" an animation as soon
12
- * as it's triggered, we also want to avoid a visual jump if there's a big delay
13
- * between these two moments.
14
- */
15
- const MAX_RESOLVE_DELAY = 40;
16
- class BaseAnimation {
17
- constructor({ autoplay = true, delay = 0, type = "keyframes", repeat = 0, repeatDelay = 0, repeatType = "loop", ...options }) {
18
- // Track whether the animation has been stopped. Stopped animations won't restart.
19
- this.isStopped = false;
20
- this.hasAttemptedResolve = false;
21
- this.createdAt = time.now();
22
- this.options = {
23
- autoplay,
24
- delay,
25
- type,
26
- repeat,
27
- repeatDelay,
28
- repeatType,
29
- ...options,
30
- };
31
- this.updateFinishedPromise();
32
- }
33
- /**
34
- * This method uses the createdAt and resolvedAt to calculate the
35
- * animation startTime. *Ideally*, we would use the createdAt time as t=0
36
- * as the following frame would then be the first frame of the animation in
37
- * progress, which would feel snappier.
38
- *
39
- * However, if there's a delay (main thread work) between the creation of
40
- * the animation and the first commited frame, we prefer to use resolvedAt
41
- * to avoid a sudden jump into the animation.
42
- */
43
- calcStartTime() {
44
- if (!this.resolvedAt)
45
- return this.createdAt;
46
- return this.resolvedAt - this.createdAt > MAX_RESOLVE_DELAY
47
- ? this.resolvedAt
48
- : this.createdAt;
49
- }
50
- /**
51
- * A getter for resolved data. If keyframes are not yet resolved, accessing
52
- * this.resolved will synchronously flush all pending keyframe resolvers.
53
- * This is a deoptimisation, but at its worst still batches read/writes.
54
- */
55
- get resolved() {
56
- if (!this._resolved && !this.hasAttemptedResolve) {
57
- flushKeyframeResolvers();
58
- }
59
- return this._resolved;
60
- }
61
- /**
62
- * A method to be called when the keyframes resolver completes. This method
63
- * will check if its possible to run the animation and, if not, skip it.
64
- * Otherwise, it will call initPlayback on the implementing class.
65
- */
66
- onKeyframesResolved(keyframes, finalKeyframe) {
67
- this.resolvedAt = time.now();
68
- this.hasAttemptedResolve = true;
69
- const { name, type, velocity, delay, onComplete, onUpdate, isGenerator, } = this.options;
70
- /**
71
- * If we can't animate this value with the resolved keyframes
72
- * then we should complete it immediately.
73
- */
74
- if (!isGenerator && !canAnimate(keyframes, name, type, velocity)) {
75
- // Finish immediately
76
- if (instantAnimationState.current || !delay) {
77
- onUpdate &&
78
- onUpdate(getFinalKeyframe(keyframes, this.options, finalKeyframe));
79
- onComplete && onComplete();
80
- this.resolveFinishedPromise();
81
- return;
82
- }
83
- // Finish after a delay
84
- else {
85
- this.options.duration = 0;
86
- }
87
- }
88
- const resolvedAnimation = this.initPlayback(keyframes, finalKeyframe);
89
- if (resolvedAnimation === false)
90
- return;
91
- this._resolved = {
92
- keyframes,
93
- finalKeyframe,
94
- ...resolvedAnimation,
95
- };
96
- this.onPostResolved();
97
- }
98
- onPostResolved() { }
99
- /**
100
- * Allows the returned animation to be awaited or promise-chained. Currently
101
- * resolves when the animation finishes at all but in a future update could/should
102
- * reject if its cancels.
103
- */
104
- then(resolve, reject) {
105
- return this.currentFinishedPromise.then(resolve, reject);
106
- }
107
- flatten() {
108
- if (!this.options.allowFlatten)
109
- return;
110
- this.options.type = "keyframes";
111
- this.options.ease = "linear";
112
- }
113
- updateFinishedPromise() {
114
- this.currentFinishedPromise = new Promise((resolve) => {
115
- this.resolveFinishedPromise = resolve;
116
- });
117
- }
118
- }
119
-
120
- export { BaseAnimation };