@octane-xplat/motion 0.7.3 → 0.10.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 (43) hide show
  1. package/README.md +31 -2
  2. package/UPSTREAM.md +295 -27
  3. package/dist/native/index.js +980 -112
  4. package/dist/native/octane-client-build.json +1 -1
  5. package/dist/web/index.js +1104 -166
  6. package/dist/web/octane-client-build.json +1 -1
  7. package/package.json +25 -16
  8. package/src/clock.ts +13 -1
  9. package/src/components.mobile.test.tsrx +58 -1
  10. package/src/components.tsrx +185 -39
  11. package/src/components.web.test.tsrx +236 -3
  12. package/src/controller.ts +122 -10
  13. package/src/delegation.test.ts +269 -0
  14. package/src/delegation.ts +29 -0
  15. package/src/delegation.web.test.ts +270 -0
  16. package/src/drag.mobile.test.ts +81 -0
  17. package/src/drag.test.ts +167 -0
  18. package/src/drag.ts +157 -0
  19. package/src/driver.ts +249 -0
  20. package/src/driver.web.ts +180 -0
  21. package/src/engine.test.ts +99 -0
  22. package/src/engine.ts +140 -18
  23. package/src/hooks.tsrx +53 -2
  24. package/src/host-types.ts +44 -1
  25. package/src/host.ts +39 -2
  26. package/src/host.web.ts +51 -10
  27. package/src/index.ts +18 -4
  28. package/src/index.web.ts +18 -4
  29. package/src/pan.ts +92 -0
  30. package/src/pan.web.ts +116 -0
  31. package/src/presence-input.ts +11 -4
  32. package/src/presence-input.web.ts +13 -4
  33. package/src/presence-state.ts +27 -7
  34. package/src/presence.tsrx +6 -7
  35. package/src/reduced-motion.ts +23 -4
  36. package/src/types.ts +100 -11
  37. package/src/value.ts +18 -8
  38. package/src/variants.test.ts +197 -0
  39. package/src/variants.ts +226 -0
  40. package/types/engine.d.ts +8 -2
  41. package/types/index.d.ts +34 -6
  42. package/types/types.d.ts +94 -11
  43. package/types/value.d.ts +7 -4
package/types/index.d.ts CHANGED
@@ -1,18 +1,29 @@
1
1
  import type { UniversalComponent } from 'octane/universal'
2
2
  import type {
3
+ MotionProps,
3
4
  MotionViewProps,
4
5
  MotionRowProps,
5
6
  MotionPressableProps,
6
7
  MotionConfigProps,
8
+ Target,
7
9
  Transition,
8
- } from './types'
9
- import type { MotionValue, MotionValueEvents } from './value'
10
- /** Bounded motion hosts for shared xplat UI primitives. */
10
+ TransitionInput,
11
+ } from './types.js'
12
+
13
+ import type { MotionValue, MotionValueEvents } from './value.js'
14
+ import type { AnimationControls, AnimationResult } from './engine.js'
15
+ /** Bounded motion hosts for shared xplat UI primitives; `motion.create` wraps
16
+ * any component that accepts `ref`/`style`/`children`. All hosts support
17
+ * numeric variants and root-local initial/animate label inheritance. */
11
18
  export declare const motion: {
12
19
  View: UniversalComponent<MotionViewProps>
13
20
  Row: UniversalComponent<MotionRowProps>
14
21
  Pressable: UniversalComponent<MotionPressableProps>
22
+ create: <P extends Record<string, unknown>>(
23
+ component: (props: P) => any,
24
+ ) => UniversalComponent<P & MotionProps>
15
25
  }
26
+
16
27
  /** Inherit transition and reduced-motion defaults within this root. */
17
28
  export declare const MotionConfig: UniversalComponent<MotionConfigProps>
18
29
  /** Observe the live system reduced-motion preference. */
@@ -25,6 +36,7 @@ export declare function useMotionValueEvent<K extends keyof MotionValueEvents>(
25
36
  event: K,
26
37
  callback: MotionValueEvents[K],
27
38
  ): void
39
+
28
40
  /** Derive a numeric value by mapping ranges or transforming source samples. */
29
41
  export declare function useTransform(
30
42
  source: MotionValue,
@@ -32,22 +44,38 @@ export declare function useTransform(
32
44
  output: number[],
33
45
  options?: { clamp?: boolean },
34
46
  ): MotionValue
47
+
35
48
  export declare function useTransform(
36
49
  source: MotionValue,
37
50
  transform: (value: number) => number,
38
51
  ): MotionValue
52
+
39
53
  export declare function useTransform(
40
54
  source: MotionValue[],
41
55
  transform: (values: number[]) => number,
42
56
  ): MotionValue
57
+
43
58
  /** Spring toward set targets or a source MotionValue; jump snaps. */
44
59
  export declare function useSpring(
45
60
  source: number | MotionValue,
46
61
  options?: Omit<Transition, 'type' | 'duration' | 'ease' | 'delay'>,
47
62
  ): MotionValue
63
+
64
+ /** Scoped imperative animation: `const [scope, animate] = useAnimate()` then
65
+ * `ref={scope}` on a motion host. */
66
+ export declare function useAnimate(): [
67
+ { current: any },
68
+ (
69
+ target: Target | MotionValue | object,
70
+ transitionOrTo?: TransitionInput | number,
71
+ transition?: Transition,
72
+ ) => Promise<AnimationResult> | AnimationControls,
73
+ ]
74
+
48
75
  export type { MotionValue, MotionValueEvents }
49
- export type { AnimationControls, AnimationResult } from './engine'
50
- export type * from './types'
76
+ export type { AnimationControls, AnimationResult } from './engine.js'
77
+ /** Includes bounded drag props and DragInfo callback payloads on both targets. */
78
+ export type * from './types.js'
51
79
 
52
80
  /** Retain live children through exit; removing the boundary disposes immediately. */
53
- export declare const Presence: UniversalComponent<import('./types').PresenceProps>
81
+ export declare const Presence: UniversalComponent<import('./types.js').PresenceProps>
package/types/types.d.ts CHANGED
@@ -1,20 +1,36 @@
1
- import type { View, Row, Pressable } from '@octane-xplat/ui';
2
- import type { MotionValue } from './value';
1
+ import type { View, HStack, Pressable } from '@octane-xplat/ui';
2
+ import type { MotionValue } from './value.js';
3
3
  type ViewProps = Parameters<typeof View>[0];
4
- type RowProps = Parameters<typeof Row>[0];
4
+ type HStackProps = Parameters<typeof HStack>[0];
5
5
  type PressableProps = Parameters<typeof Pressable>[0];
6
6
  /** Supported channels. Translation is CSS pixels/DIP; rotation is degrees. */
7
7
  export type MotionKey = 'opacity' | 'x' | 'y' | 'scale' | 'scaleX' | 'scaleY' | 'rotate';
8
8
  /** Absolute numeric destinations; omitted channels retain their current values. */
9
9
  export type Target = Partial<Record<MotionKey, number>>;
10
10
  /** Tween easing, including a CSS-compatible cubic Bezier tuple. */
11
- export type Ease = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | [number, number, number, number];
11
+ export type Ease = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'circIn' | 'circOut' | 'circInOut' | 'backIn' | 'backOut' | 'backInOut' | 'anticipate' | [number, number, number, number];
12
+ /** How repeated legs play: restart, alternate direction, or alternate
13
+ * direction with inverted easing (identical to reverse for two keyframes). */
14
+ export type RepeatType = 'loop' | 'reverse' | 'mirror';
15
+ /** Numeric tree timing in seconds, applied to inherited animate labels. */
16
+ export interface ChildOrchestration {
17
+ staggerChildren?: number;
18
+ delayChildren?: number;
19
+ when?: 'beforeChildren' | 'afterChildren';
20
+ }
12
21
  /** Timing is seconds. Spring velocity is units per second. */
13
- export interface Transition {
22
+ export interface Transition extends ChildOrchestration {
14
23
  type?: 'tween' | 'spring';
24
+ /** Tween duration; on springs this is the visual duration (combine with bounce). */
15
25
  duration?: number;
16
26
  delay?: number;
17
27
  ease?: Ease;
28
+ /** Additional iterations after the first leg; Infinity loops forever. */
29
+ repeat?: number;
30
+ repeatType?: RepeatType;
31
+ repeatDelay?: number;
32
+ /** Spring bounciness 0–1; pairs with duration instead of stiffness/damping. */
33
+ bounce?: number;
18
34
  stiffness?: number;
19
35
  damping?: number;
20
36
  mass?: number;
@@ -22,27 +38,94 @@ export interface Transition {
22
38
  restSpeed?: number;
23
39
  restDelta?: number;
24
40
  }
41
+ /** Per-channel transition overrides, upstream form: `{x: {…}, default: {…}}`. */
42
+ export type TransitionOrchestration = ChildOrchestration & {
43
+ default?: Transition;
44
+ } & Partial<Record<MotionKey, Transition>>;
45
+ /** A flat transition or per-channel overrides. */
46
+ export type TransitionInput = Transition | TransitionOrchestration;
47
+ /** Labels resolve against this host's variants, in array order. */
48
+ export type VariantLabels = string | string[];
49
+ /** An inline numeric target or labels resolved by the host. */
50
+ export type AnimationDefinition = Target | VariantLabels;
51
+ /** A numeric variant destination with an optional run transition override. */
52
+ export type VariantTarget = Target & {
53
+ transition?: TransitionInput;
54
+ };
55
+ /** Host-local definitions; pure resolvers receive this host's custom value. */
56
+ export type Variants = Record<string, VariantTarget | ((custom: any) => VariantTarget)>;
25
57
  /** Static platform styles plus numeric motion-value bindings. */
26
58
  export type MotionStyle = Record<string, unknown> & Partial<Record<MotionKey, number | MotionValue>>;
59
+ /** Translation limits in CSS pixels/DIP. Omitted edges are unbounded. */
60
+ export interface DragConstraints {
61
+ left?: number;
62
+ right?: number;
63
+ top?: number;
64
+ bottom?: number;
65
+ }
66
+ export interface DragInfo {
67
+ point: {
68
+ x: number;
69
+ y: number;
70
+ };
71
+ delta: {
72
+ x: number;
73
+ y: number;
74
+ };
75
+ offset: {
76
+ x: number;
77
+ y: number;
78
+ };
79
+ /** CSS pixels/DIP per second. */
80
+ velocity: {
81
+ x: number;
82
+ y: number;
83
+ };
84
+ cancelled: boolean;
85
+ }
86
+ export type DragCallback = (event: any, info: DragInfo) => void;
27
87
  /** Supported declarative motion controls. */
28
88
  export interface MotionProps {
29
- initial?: Target | false;
89
+ drag?: boolean | 'x' | 'y';
90
+ /** Numeric translation bounds; measured ref constraints are deferred. */
91
+ dragConstraints?: DragConstraints;
92
+ /** Project release velocity into a spring destination (default true). */
93
+ dragMomentum?: boolean;
94
+ /** Resistance beyond bounds, 0–1 (default 0.35); false = 0, true = 0.35. */
95
+ dragElastic?: boolean | number;
96
+ onDragStart?: DragCallback;
97
+ onDrag?: DragCallback;
98
+ onDragEnd?: DragCallback;
99
+ /** Named numeric targets; array labels merge left to right. */
100
+ variants?: Variants;
101
+ /** Passed to this host's variant resolvers; not inherited. */
102
+ custom?: any;
103
+ initial?: AnimationDefinition | false;
30
104
  /** Destination while the nearest Presence boundary retains this host for exit. */
31
- exit?: Target;
32
- animate?: Target;
33
- transition?: Transition;
105
+ exit?: AnimationDefinition;
106
+ animate?: AnimationDefinition;
107
+ transition?: TransitionInput;
34
108
  style?: MotionStyle;
109
+ /** Target while the pointer is down (web: pointerdown; native: touch down). */
110
+ whileTap?: AnimationDefinition;
111
+ whileTapTransition?: Transition;
112
+ /** Target while the host holds focus. */
113
+ whileFocus?: AnimationDefinition;
114
+ whileFocusTransition?: Transition;
115
+ onAnimationStart?: (definition: AnimationDefinition) => void;
35
116
  onAnimationComplete?: () => void;
117
+ /** Per-frame snapshot while any channel animates. */
118
+ onUpdate?: (latest: Target) => void;
36
119
  }
37
120
  /** View layout and accessibility props with motion controls. */
38
121
  export type MotionViewProps = Omit<ViewProps, 'style'> & MotionProps;
39
122
  /** Row layout and accessibility props with motion controls. */
40
- export type MotionRowProps = Omit<RowProps, 'style'> & MotionProps;
123
+ export type MotionRowProps = Omit<HStackProps, 'style'> & MotionProps;
41
124
  /** Pressable interaction props with motion controls. */
42
125
  export type MotionPressableProps = Omit<PressableProps, 'style'> & MotionProps;
43
126
  /** Inherited defaults; `user` observes the live system preference. */
44
127
  export interface MotionConfigProps {
45
- transition?: Transition;
128
+ transition?: TransitionInput;
46
129
  reducedMotion?: 'always' | 'never' | 'user';
47
130
  children?: any;
48
131
  }
package/types/value.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { Clock } from './clock-types';
2
- import type { Transition } from './types';
3
- import { type AnimationControls } from './engine';
1
+ import type { Clock } from './clock-types.js';
2
+ import type { Transition } from './types.js';
3
+ import { type AnimationControls } from './engine.js';
4
4
  /** Events supported by numeric motion values. */
5
5
  export interface MotionValueEvents {
6
6
  change: (value: number) => void;
@@ -37,8 +37,11 @@ export declare class MotionValue {
37
37
  on<K extends keyof MotionValueEvents>(event: K, callback: MotionValueEvents[K]): () => void;
38
38
  private emit;
39
39
  private write;
40
+ /** Update position bookkeeping without emitting — platform-delegated runs
41
+ * track presentation state so interruption reads fresh value/velocity. */
42
+ track(value: number): void;
40
43
  /** Animate to a destination. New playback replaces old playback. */
41
- animate(target: number, transition?: Transition): AnimationControls;
44
+ animate(target: number, transition?: Transition, clampSample?: (value: number) => number): AnimationControls;
42
45
  /** Stop playback at its current value. */
43
46
  stop(reason?: 'cancelled' | 'replaced'): void;
44
47
  /** Release playback and listeners when the owning component unmounts. */