motion-dom 12.6.1 → 12.6.3

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 (36) hide show
  1. package/dist/cjs/index.js +381 -236
  2. package/dist/es/animation/{controls/BaseGroup.mjs → GroupAnimation.mjs} +4 -5
  3. package/dist/es/animation/GroupAnimationWithThen.mjs +9 -0
  4. package/dist/es/animation/NativeAnimation.mjs +159 -0
  5. package/dist/es/animation/generators/utils/is-generator.mjs +1 -1
  6. package/dist/es/animation/keyframes/get-final.mjs +12 -0
  7. package/dist/es/animation/keyframes/hydrate.mjs +26 -0
  8. package/dist/es/animation/utils/get-value-transition.mjs +3 -5
  9. package/dist/es/animation/waapi/easing/cubic-bezier.mjs +3 -0
  10. package/dist/es/animation/waapi/easing/is-supported.mjs +14 -0
  11. package/dist/es/animation/waapi/easing/map-easing.mjs +26 -0
  12. package/dist/es/animation/waapi/easing/supported.mjs +15 -0
  13. package/dist/es/animation/waapi/start-waapi-animation.mjs +37 -0
  14. package/dist/es/animation/waapi/supports/partial-keyframes.mjs +13 -0
  15. package/dist/es/animation/waapi/utils/apply-generator.mjs +14 -0
  16. package/dist/es/animation/waapi/utils/linear.mjs +1 -3
  17. package/dist/es/animation/waapi/utils/px-values.mjs +39 -0
  18. package/dist/es/gestures/press/index.mjs +1 -1
  19. package/dist/es/index.mjs +8 -3
  20. package/dist/es/render/dom/style.mjs +15 -0
  21. package/dist/es/utils/resolve-elements.mjs +2 -7
  22. package/dist/es/utils/supports/flags.mjs +1 -3
  23. package/dist/es/utils/supports/memo.mjs +1 -1
  24. package/dist/es/value/index.mjs +1 -1
  25. package/dist/es/view/queue.mjs +1 -2
  26. package/dist/es/view/start.mjs +22 -17
  27. package/dist/es/view/utils/get-view-animations.mjs +1 -2
  28. package/dist/index.d.ts +90 -43
  29. package/dist/motion-dom.dev.js +381 -236
  30. package/dist/motion-dom.js +1 -1
  31. package/package.json +3 -3
  32. package/dist/es/animation/controls/Group.mjs +0 -13
  33. package/dist/es/animation/waapi/NativeAnimationControls.mjs +0 -83
  34. package/dist/es/animation/waapi/PseudoAnimation.mjs +0 -15
  35. package/dist/es/animation/waapi/utils/convert-options.mjs +0 -55
  36. package/dist/es/animation/waapi/utils/easing.mjs +0 -44
@@ -1,10 +1,9 @@
1
1
  function filterViewAnimations(animation) {
2
- var _a;
3
2
  const { effect } = animation;
4
3
  if (!effect)
5
4
  return false;
6
5
  return (effect.target === document.documentElement &&
7
- ((_a = effect.pseudoElement) === null || _a === void 0 ? void 0 : _a.startsWith("::view-transition")));
6
+ effect.pseudoElement?.startsWith("::view-transition"));
8
7
  }
9
8
  function getViewAnimations() {
10
9
  return document.getAnimations().filter(filterViewAnimations);
package/dist/index.d.ts CHANGED
@@ -294,16 +294,12 @@ interface AnimationPlaybackControls {
294
294
  * Cancels the animation and applies the initial state.
295
295
  */
296
296
  cancel: () => void;
297
- /**
298
- * Allows the animation to be awaited.
299
- */
300
- then: (onResolve: VoidFunction, onReject?: VoidFunction) => Promise<void>;
301
297
  /**
302
298
  * Attaches a timeline to the animation, for instance the `ScrollTimeline`.
303
299
  *
304
300
  * This is currently for internal use only.
305
301
  */
306
- attachTimeline?: (timeline: ProgressTimeline, fallback?: (animation: AnimationPlaybackControls | AnimationPlaybackControlsWithFinished) => VoidFunction) => VoidFunction;
302
+ attachTimeline?: (timeline: ProgressTimeline, fallback?: (animation: AnimationPlaybackControls) => VoidFunction) => VoidFunction;
307
303
  /**
308
304
  * Flattens the animation's easing curve to linear.
309
305
  *
@@ -311,9 +307,10 @@ interface AnimationPlaybackControls {
311
307
  * ensure an animation is being scrubbed by progress rather than eased time.
312
308
  */
313
309
  flatten: () => void;
314
- }
315
- type AnimationPlaybackControlsWithFinished = Omit<AnimationPlaybackControls, "then"> & {
316
310
  finished: Promise<any>;
311
+ }
312
+ type AnimationPlaybackControlsWithThen = AnimationPlaybackControls & {
313
+ then: (onResolve: VoidFunction, onReject?: VoidFunction) => Promise<void>;
317
314
  };
318
315
  interface AnimationState<V> {
319
316
  value: V;
@@ -324,6 +321,14 @@ interface KeyframeGenerator<V> {
324
321
  next: (t: number) => AnimationState<V>;
325
322
  toString: () => string;
326
323
  }
324
+ interface DOMValueAnimationOptions<V extends string | number = number> {
325
+ element: HTMLElement | SVGElement;
326
+ keyframes: ValueKeyframesDefinition;
327
+ name: string;
328
+ pseudoElement?: string;
329
+ allowFlatten?: boolean;
330
+ transition: ValueAnimationTransition<V>;
331
+ }
327
332
  interface ValueAnimationOptions<V extends string | number = number> extends ValueAnimationTransition {
328
333
  keyframes: V[];
329
334
  name?: string;
@@ -331,7 +336,10 @@ interface ValueAnimationOptions<V extends string | number = number> extends Valu
331
336
  isGenerator?: boolean;
332
337
  allowFlatten?: boolean;
333
338
  }
334
- type GeneratorFactory = (options: ValueAnimationOptions<any>) => KeyframeGenerator<any>;
339
+ type GeneratorFactoryFunction = (options: ValueAnimationOptions<any>) => KeyframeGenerator<any>;
340
+ interface GeneratorFactory extends GeneratorFactoryFunction {
341
+ applyToOptions: (options: Transition) => Transition;
342
+ }
335
343
  type AnimationGeneratorType = GeneratorFactory | "decay" | "spring" | "keyframes" | "tween" | "inertia";
336
344
  interface AnimationPlaybackLifecycles<V> {
337
345
  onUpdate?: (latest: V) => void;
@@ -485,9 +493,9 @@ interface SVGPathProperties {
485
493
  pathSpacing?: number;
486
494
  }
487
495
 
488
- type AcceptedAnimations = AnimationPlaybackControls | AnimationPlaybackControlsWithFinished;
496
+ type AcceptedAnimations = AnimationPlaybackControls;
489
497
  type GroupedAnimations = AcceptedAnimations[];
490
- declare class BaseGroupPlaybackControls implements AnimationPlaybackControlsWithFinished {
498
+ declare class GroupAnimation implements AnimationPlaybackControls {
491
499
  animations: GroupedAnimations;
492
500
  constructor(animations: Array<AcceptedAnimations | undefined>);
493
501
  get finished(): Promise<any[]>;
@@ -496,7 +504,7 @@ declare class BaseGroupPlaybackControls implements AnimationPlaybackControlsWith
496
504
  */
497
505
  private getAll;
498
506
  private setAll;
499
- attachTimeline(timeline: any, fallback?: (animation: AnimationPlaybackControls | AnimationPlaybackControlsWithFinished) => VoidFunction): () => void;
507
+ attachTimeline(timeline: any, fallback?: (animation: AnimationPlaybackControls) => VoidFunction): () => void;
500
508
  get time(): number;
501
509
  set time(time: number);
502
510
  get speed(): number;
@@ -512,12 +520,67 @@ declare class BaseGroupPlaybackControls implements AnimationPlaybackControlsWith
512
520
  complete(): void;
513
521
  }
514
522
 
523
+ declare class GroupAnimationWithThen extends GroupAnimation implements AnimationPlaybackControlsWithThen {
524
+ then(onResolve: VoidFunction, _onReject?: VoidFunction): Promise<void>;
525
+ }
526
+
527
+ interface NativeAnimationOptions<V extends string | number = number> extends DOMValueAnimationOptions<V> {
528
+ pseudoElement?: string;
529
+ }
530
+ interface NativeControlsOptions {
531
+ animation: Animation;
532
+ }
515
533
  /**
516
- * TODO: This is a temporary class to support the legacy
517
- * thennable API
534
+ * NativeAnimation implements AnimationPlaybackControls for the browser's Web Animations API.
518
535
  */
519
- declare class GroupPlaybackControls extends BaseGroupPlaybackControls implements AnimationPlaybackControls {
520
- animations: AnimationPlaybackControls[];
536
+ declare class NativeAnimation implements AnimationPlaybackControls {
537
+ /**
538
+ * The interfaced Web Animation API animation
539
+ */
540
+ private animation;
541
+ private allowFlatten;
542
+ private removeAnimation;
543
+ constructor(options: NativeAnimationOptions | NativeControlsOptions);
544
+ play(): void;
545
+ pause(): void;
546
+ complete(): void;
547
+ cancel(): void;
548
+ stop(): void;
549
+ /**
550
+ * WAAPI doesn't natively have any interruption capabilities.
551
+ *
552
+ * In this method, we commit styles back to the DOM before cancelling
553
+ * the animation.
554
+ *
555
+ * This is designed to be overridden by NativeAnimationExtended, which
556
+ * will create a renderless JS animation and sample it twice to calculate
557
+ * its current value, "previous" value, and therefore allow
558
+ * Motion to also correctly calculate velocity for any subsequent animation
559
+ * while deferring the commit until the next animation frame.
560
+ */
561
+ private commitStyles;
562
+ get duration(): number;
563
+ get time(): number;
564
+ set time(newTime: number);
565
+ /**
566
+ * The playback speed of the animation.
567
+ * 1 = normal speed, 2 = double speed, 0.5 = half speed.
568
+ */
569
+ get speed(): number;
570
+ set speed(newSpeed: number);
571
+ get state(): AnimationPlayState;
572
+ get startTime(): number;
573
+ get finished(): Promise<Animation>;
574
+ flatten(): void;
575
+ /**
576
+ * Attaches a timeline to the animation, for instance the `ScrollTimeline`.
577
+ */
578
+ attachTimeline(timeline: ProgressTimeline): VoidFunction;
579
+ /**
580
+ * Allows the animation to be awaited.
581
+ *
582
+ * @deprecated Use `finished` instead.
583
+ */
521
584
  then(onResolve: VoidFunction, onReject?: VoidFunction): Promise<void>;
522
585
  }
523
586
 
@@ -541,31 +604,12 @@ declare function createGeneratorEasing(options: Transition, scale: number | unde
541
604
 
542
605
  declare function isGenerator(type?: AnimationGeneratorType): type is GeneratorFactory;
543
606
 
544
- declare class NativeAnimationControls implements Omit<AnimationPlaybackControlsWithFinished, "then"> {
545
- animation?: Animation;
546
- options?: ValueAnimationOptions;
547
- constructor(animation?: Animation);
548
- get duration(): number;
549
- get time(): number;
550
- set time(newTime: number);
551
- get speed(): number;
552
- set speed(newSpeed: number);
553
- get state(): AnimationPlayState;
554
- get startTime(): number | null;
555
- get finished(): Promise<void> | Promise<Animation>;
556
- play(): void;
557
- pause(): void;
558
- stop(): void;
559
- flatten(): void;
560
- attachTimeline(timeline: any): (any: void) => void;
561
- complete(): void;
562
- cancel(): void;
563
- }
564
-
565
- declare function attachTimeline(animation: Animation, timeline: any): void;
607
+ declare const cubicBezierAsString: ([a, b, c, d]: BezierDefinition) => string;
566
608
 
567
609
  declare function isWaapiSupportedEasing(easing?: Easing | Easing[]): boolean;
568
- declare const cubicBezierAsString: ([a, b, c, d]: BezierDefinition) => string;
610
+
611
+ declare function mapEasingToNativeEasing(easing: Easing | Easing[] | undefined, duration: number): undefined | string | string[];
612
+
569
613
  declare const supportedWaapiEasing: {
570
614
  linear: string;
571
615
  ease: string;
@@ -577,7 +621,10 @@ declare const supportedWaapiEasing: {
577
621
  backIn: string;
578
622
  backOut: string;
579
623
  };
580
- declare function mapEasingToNativeEasing(easing: Easing | Easing[] | undefined, duration: number): undefined | string | string[];
624
+
625
+ declare function startWaapiAnimation(element: Element, valueName: string, keyframes: ValueKeyframesDefinition, { delay, duration, repeat, repeatType, ease, times, }?: Transition, pseudoElement?: string | undefined): Animation;
626
+
627
+ declare function attachTimeline(animation: Animation, timeline: any): void;
581
628
 
582
629
  declare const generateLinearEasing: (easing: EasingFunction, duration: number, resolution?: number) => string;
583
630
 
@@ -822,7 +869,7 @@ type Subscriber<T> = (v: T) => void;
822
869
  * @public
823
870
  */
824
871
  type PassiveEffect<T> = (v: T, safeSetter: (v: T) => void) => void;
825
- type StartAnimation = (complete: () => void) => AnimationPlaybackControls | undefined;
872
+ type StartAnimation = (complete: () => void) => AnimationPlaybackControlsWithThen | undefined;
826
873
  interface MotionValueEventCallbacks<V> {
827
874
  animationStart: () => void;
828
875
  animationComplete: () => void;
@@ -886,7 +933,7 @@ declare class MotionValue<V = any> {
886
933
  /**
887
934
  * A reference to the currently-controlling animation.
888
935
  */
889
- animation?: AnimationPlaybackControls;
936
+ animation?: AnimationPlaybackControlsWithThen;
890
937
  /**
891
938
  * Tracks whether this value should be removed
892
939
  */
@@ -1053,7 +1100,7 @@ declare class ViewTransitionBuilder {
1053
1100
  targets: Map<Target, ViewTransitionTarget>;
1054
1101
  update: () => void | Promise<void>;
1055
1102
  options: ViewTransitionOptions;
1056
- notifyReady: (value: BaseGroupPlaybackControls) => void;
1103
+ notifyReady: (value: GroupAnimation) => void;
1057
1104
  private readyPromise;
1058
1105
  constructor(update: () => void | Promise<void>, options?: ViewTransitionOptions);
1059
1106
  get(selector: Target): this;
@@ -1068,4 +1115,4 @@ declare class ViewTransitionBuilder {
1068
1115
  }
1069
1116
  declare function animateView(update: () => void | Promise<void>, defaultOptions?: ViewTransitionOptions): ViewTransitionBuilder;
1070
1117
 
1071
- export { type ActiveStatsBuffer, type AnimationGeneratorType, type AnimationOptions, type AnimationOptionsWithValueOverrides, type AnimationPlaybackControls, type AnimationPlaybackControlsWithFinished, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type Batcher, type BezierDefinition, type CSSStyleDeclarationWithTransform, type CancelProcess, type DOMKeyframesDefinition, type DecayOptions, type Driver, type DriverControls, type DurationSpringOptions, type DynamicOption, type Easing, type EasingDefinition, type EasingFunction, type EasingModifier, type ElementOrSelector, type EventOptions, type FrameData, type FrameStats, type GeneratorFactory, GroupPlaybackControls, type InactiveStatsBuffer, type InertiaOptions, type KeyframeGenerator, type KeyframeOptions, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, NativeAnimationControls, type OnHoverEndEvent, type OnHoverStartEvent, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PassiveEffect, type PointerEventOptions, type PressGestureInfo, type Process, type ProgressTimeline, type RepeatType, type ResolvedValueKeyframe, type SVGAttributes, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type Schedule, type SelectorCache, type SpringOptions, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type Target, type TransformProperties, type Transformer, type Transition, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationTransition, type ValueKeyframe, type ValueKeyframesDefinition, type VariableKeyframesDefinition, type VariableTransitions, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type WithQuerySelectorAll, activeAnimations, animateView, attachTimeline, calcGeneratorDuration, cancelFrame, cancelMicrotask, collectMotionValues, createGeneratorEasing, createRenderBatcher, cubicBezierAsString, frame, frameData, frameSteps, generateLinearEasing, getValueTransition, hover, isBezierDefinition, isDragActive, isDragging, isGenerator, isNodeOrChild, isPrimaryPointer, isWaapiSupportedEasing, mapEasingToNativeEasing, maxGeneratorDuration, microtask, motionValue, press, recordStats, resolveElements, setDragLock, statsBuffer, supportedWaapiEasing, supportsFlags, supportsLinearEasing, supportsScrollTimeline, time };
1118
+ export { type AcceptedAnimations, type ActiveStatsBuffer, type AnimationGeneratorType, type AnimationOptions, type AnimationOptionsWithValueOverrides, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type Batcher, type BezierDefinition, type CSSStyleDeclarationWithTransform, type CancelProcess, type DOMKeyframesDefinition, type DOMValueAnimationOptions, type DecayOptions, type Driver, type DriverControls, type DurationSpringOptions, type DynamicOption, type Easing, type EasingDefinition, type EasingFunction, type EasingModifier, type ElementOrSelector, type EventOptions, type FrameData, type FrameStats, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type InactiveStatsBuffer, type InertiaOptions, type KeyframeGenerator, type KeyframeOptions, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, NativeAnimation, type NativeAnimationOptions, type NativeControlsOptions, type OnHoverEndEvent, type OnHoverStartEvent, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PassiveEffect, type PointerEventOptions, type PressGestureInfo, type Process, type ProgressTimeline, type RepeatType, type ResolvedValueKeyframe, type SVGAttributes, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type Schedule, type SelectorCache, type SpringOptions, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type Target, type TransformProperties, type Transformer, type Transition, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationTransition, type ValueKeyframe, type ValueKeyframesDefinition, type VariableKeyframesDefinition, type VariableTransitions, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type WithQuerySelectorAll, activeAnimations, animateView, attachTimeline, calcGeneratorDuration, cancelFrame, cancelMicrotask, collectMotionValues, createGeneratorEasing, createRenderBatcher, cubicBezierAsString, frame, frameData, frameSteps, generateLinearEasing, getValueTransition, hover, isBezierDefinition, isDragActive, isDragging, isGenerator, isNodeOrChild, isPrimaryPointer, isWaapiSupportedEasing, mapEasingToNativeEasing, maxGeneratorDuration, microtask, motionValue, press, recordStats, resolveElements, setDragLock, startWaapiAnimation, statsBuffer, supportedWaapiEasing, supportsFlags, supportsLinearEasing, supportsScrollTimeline, time };