@motion.page/sdk 0.1.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 (52) hide show
  1. package/README.md +817 -0
  2. package/dist/core/Animation.d.ts +230 -0
  3. package/dist/core/AnimationBuilder.d.ts +125 -0
  4. package/dist/core/Engine.d.ts +140 -0
  5. package/dist/core/Motion.d.ts +56 -0
  6. package/dist/core/PropTween.d.ts +81 -0
  7. package/dist/core/Ticker.d.ts +107 -0
  8. package/dist/core/Timeline.d.ts +294 -0
  9. package/dist/easing/index.d.ts +65 -0
  10. package/dist/fit/FitResolver.d.ts +12 -0
  11. package/dist/index.cjs +34 -0
  12. package/dist/index.cjs.map +52 -0
  13. package/dist/index.d.ts +25 -0
  14. package/dist/index.js +34 -0
  15. package/dist/index.js.map +52 -0
  16. package/dist/memory/AnimationPool.d.ts +14 -0
  17. package/dist/memory/ObjectPool.d.ts +37 -0
  18. package/dist/memory/PropTweenPool.d.ts +14 -0
  19. package/dist/registries/SDKRegistry.d.ts +69 -0
  20. package/dist/render/CSSRenderer.d.ts +33 -0
  21. package/dist/render/PathRenderer.d.ts +24 -0
  22. package/dist/render/RenderBatch.d.ts +27 -0
  23. package/dist/render/TransformCache.d.ts +54 -0
  24. package/dist/stagger/StaggerResolver.d.ts +28 -0
  25. package/dist/triggers/BaseTrigger.d.ts +61 -0
  26. package/dist/triggers/CursorTrigger.d.ts +86 -0
  27. package/dist/triggers/EventTrigger.d.ts +48 -0
  28. package/dist/triggers/GestureTrigger.d.ts +137 -0
  29. package/dist/triggers/MarkerManager.d.ts +42 -0
  30. package/dist/triggers/MouseMoveTrigger.d.ts +49 -0
  31. package/dist/triggers/PageExitTrigger.d.ts +74 -0
  32. package/dist/triggers/PageLoadTrigger.d.ts +37 -0
  33. package/dist/triggers/PinManager.d.ts +131 -0
  34. package/dist/triggers/ScrollTrigger.d.ts +103 -0
  35. package/dist/triggers/TriggerManager.d.ts +133 -0
  36. package/dist/types/index.d.ts +355 -0
  37. package/dist/types/public.d.ts +7 -0
  38. package/dist/utils/ColorParser.d.ts +23 -0
  39. package/dist/utils/DrawSVGParser.d.ts +62 -0
  40. package/dist/utils/FilterParser.d.ts +49 -0
  41. package/dist/utils/MotionUtils.d.ts +136 -0
  42. package/dist/utils/PathParser.d.ts +89 -0
  43. package/dist/utils/PositionParser.d.ts +24 -0
  44. package/dist/utils/PropertyParser.d.ts +159 -0
  45. package/dist/utils/QuickSetter.d.ts +16 -0
  46. package/dist/utils/ScrollPositionParser.d.ts +19 -0
  47. package/dist/utils/StyleReset.d.ts +73 -0
  48. package/dist/utils/TargetResolver.d.ts +23 -0
  49. package/dist/utils/TextSplitter.d.ts +90 -0
  50. package/dist/utils/executeTimelineAction.d.ts +18 -0
  51. package/dist/utils/getLayoutRect.d.ts +10 -0
  52. package/package.json +56 -0
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Ticker Singleton - Single RAF loop for all animations
3
+ *
4
+ * Manages the requestAnimationFrame loop with:
5
+ * - Lag smoothing (cap delta when tab backgrounded)
6
+ * - Priority-based listener ordering
7
+ * - Automatic start/stop based on listener count
8
+ * - Batched DOM writes at end of frame via RenderBatch
9
+ */
10
+ /**
11
+ * Fast check if we're inside a tick (exported for hot path performance)
12
+ * Use this instead of Ticker.getInstance().isInTick() in render code
13
+ */
14
+ export declare function isInTick(): boolean;
15
+ /**
16
+ * Run a callback in "tick mode" — writes are batched, then flushed at the end.
17
+ *
18
+ * Use this when updating timeline progress from outside the RAF loop
19
+ * (e.g. scroll event handlers) to avoid layout thrashing from immediate
20
+ * per-property DOM writes. The callback's DOM mutations are queued via
21
+ * RenderBatch and flushed in a single pass after the callback returns.
22
+ */
23
+ export declare function runBatched(callback: () => void): void;
24
+ type TickerListener = (deltaTime: number, elapsedTime: number) => void;
25
+ export declare class Ticker {
26
+ private static instance;
27
+ private listeners;
28
+ private _listenersDirty;
29
+ private _listenersSnapshot;
30
+ private _isRunning;
31
+ private rafId;
32
+ private lastTime;
33
+ private elapsedTime;
34
+ private lagThreshold;
35
+ private maxDelta;
36
+ private fpsFrames;
37
+ private fpsTime;
38
+ private currentFPS;
39
+ private lastFrameTime;
40
+ private constructor();
41
+ /**
42
+ * Get the singleton Ticker instance
43
+ */
44
+ static getInstance(): Ticker;
45
+ /**
46
+ * Add a listener to the ticker
47
+ * @param callback Function to call on each tick
48
+ * @param priority Higher priority callbacks execute first (default: 0)
49
+ */
50
+ add(callback: TickerListener, priority?: number): void;
51
+ /**
52
+ * Remove a listener from the ticker
53
+ * @param callback Function to remove
54
+ */
55
+ remove(callback: TickerListener): void;
56
+ /**
57
+ * Start the RAF loop
58
+ */
59
+ private start;
60
+ /**
61
+ * Stop the RAF loop
62
+ */
63
+ private stop;
64
+ /**
65
+ * Pause the ticker (for debug purposes)
66
+ */
67
+ pause(): void;
68
+ /**
69
+ * Resume the ticker (for debug purposes)
70
+ */
71
+ resume(): void;
72
+ /**
73
+ * Main tick function called by RAF
74
+ */
75
+ private tick;
76
+ /**
77
+ * Update FPS calculation
78
+ */
79
+ private updateFPS;
80
+ /**
81
+ * Get current FPS
82
+ */
83
+ getFPS(): number;
84
+ /**
85
+ * Get last frame delta time in ms
86
+ */
87
+ getLastDelta(): number;
88
+ /**
89
+ * Check if ticker is running
90
+ */
91
+ isRunning(): boolean;
92
+ /**
93
+ * Check if we're currently inside a tick
94
+ * Used by render system to decide: queue (in tick) or write immediately (outside tick)
95
+ * Note: For hot path performance, use the exported isInTick() function instead
96
+ */
97
+ isInTick(): boolean;
98
+ /**
99
+ * Get listener count
100
+ */
101
+ getListenerCount(): number;
102
+ /**
103
+ * Remove all listeners (for testing)
104
+ */
105
+ removeAll(): void;
106
+ }
107
+ export {};
@@ -0,0 +1,294 @@
1
+ /**
2
+ * Timeline for sequencing animations
3
+ *
4
+ * Features:
5
+ * - Named timeline registry (create/retrieve by name)
6
+ * - Position parameter support (absolute, +=, -=, <, >)
7
+ * - Nested timelines
8
+ * - Callback scheduling
9
+ * - Control methods (play, pause, reverse, seek, etc.)
10
+ * - Trigger system integration
11
+ */
12
+ import type { HoverConfig, ClickConfig, ScrollConfig, MouseMoveConfig, GestureConfig, CursorConfig, PageExitConfig, TargetInput, AnimationConfig } from '../types';
13
+ import { Animation } from './Animation';
14
+ export declare class Timeline {
15
+ /** Monotonic counter for generating unique each-mode instance names */
16
+ private static _eachCounter;
17
+ /**
18
+ * Static callback for registering named timelines with Engine.
19
+ * Set by Engine.getInstance() to break circular dependency.
20
+ * @internal
21
+ */
22
+ private static _registerWithEngine;
23
+ /**
24
+ * Set the engine registration callback. Called once by Engine during initialization.
25
+ * @internal
26
+ */
27
+ static setEngineRegisterCallback(callback: (name: string, timeline: Timeline) => void): void;
28
+ private _name?;
29
+ private _children;
30
+ private _duration;
31
+ private _time;
32
+ private _progress;
33
+ private _timeScale;
34
+ private _isActive;
35
+ private _isReversed;
36
+ private _killed;
37
+ private _onStart?;
38
+ private _onUpdate?;
39
+ private _onComplete?;
40
+ private _startFired;
41
+ /**
42
+ * Reference to attached trigger (for cleanup in kill()).
43
+ * @internal
44
+ */
45
+ _trigger?: {
46
+ disable(): void;
47
+ };
48
+ /** @internal */
49
+ private _unregisterCallback?;
50
+ /**
51
+ * Set unregister callback for cleanup. Called by Engine after registration.
52
+ * @internal
53
+ */
54
+ setUnregisterCallback(callback: () => void): void;
55
+ private _previousStart;
56
+ private _previousEnd;
57
+ private _eachInstances?;
58
+ private _eachDuration?;
59
+ private _initialValues;
60
+ private _initialTransforms;
61
+ private _transformElements;
62
+ private _savedTransitions;
63
+ private _transitionsDisabled;
64
+ private _savedWillChange;
65
+ constructor(name?: string);
66
+ /**
67
+ * Get timeline duration
68
+ */
69
+ duration(): number;
70
+ /**
71
+ * Clear timeline state for rebuild (used for re-triggerable animations)
72
+ * Kills existing animations, clears children, resets state
73
+ */
74
+ clear(): this;
75
+ /**
76
+ * Capture initial values for an animation's properties (called once per property per element)
77
+ */
78
+ private _captureInitialValues;
79
+ /**
80
+ * Restore all elements to their initial property values (used when seeking to position 0)
81
+ */
82
+ private _restoreInitialValues;
83
+ /**
84
+ * Disable CSS transitions on all animated elements.
85
+ * Called when the timeline starts playing to prevent CSS transitions
86
+ * from fighting frame-by-frame SDK rendering.
87
+ */
88
+ private _disableTransitions;
89
+ /**
90
+ * Restore original CSS transition values on all animated elements.
91
+ * Called on timeline completion and kill to re-enable CSS hover/focus
92
+ * transitions after the SDK animation is done.
93
+ */
94
+ private _restoreTransitions;
95
+ /**
96
+ * Clear all saved transition data (for kill/clear).
97
+ */
98
+ private _clearTransitionData;
99
+ /**
100
+ * Restore original will-change values on elements promoted for transforms.
101
+ */
102
+ private _restoreWillChange;
103
+ /**
104
+ * Internal: Add animation entry (used by Motion function)
105
+ * @internal
106
+ */
107
+ _addEntry(target: TargetInput, config: AnimationConfig, position?: string | number): this;
108
+ /**
109
+ * Internal method to add an AnimationBuilder directly
110
+ */
111
+ private _addBuilder;
112
+ /**
113
+ * Call function at position
114
+ */
115
+ call(callback: (...args: unknown[]) => void, params?: unknown[], position?: string | number): this;
116
+ /**
117
+ * Get the first animation's target element for trigger inference
118
+ * Note: Returns only DOM Elements, not plain objects
119
+ */
120
+ private _getFirstAnimationTarget;
121
+ /**
122
+ * Get all target elements from the first animation (for each mode)
123
+ * Note: Returns only DOM Elements, not plain objects
124
+ *
125
+ * When the builder uses text splitting (split: 'words' etc.), the animation's
126
+ * targets are the split fragments — but for each-mode we need the ORIGINAL
127
+ * pre-split elements so each gets its own ScrollTrigger. The cloned builder
128
+ * will re-split inside that element independently.
129
+ */
130
+ private _getAllAnimationTargets;
131
+ /**
132
+ * Create a timeline instance for a single element (for each mode)
133
+ * This clones the timeline structure but only targets the specific element.
134
+ */
135
+ private _createInstanceForElement;
136
+ /**
137
+ * Create a timeline instance for multiple elements (for each mode with explicit container target).
138
+ * This is a sibling of _createInstanceForElement — the only difference is that it accepts an
139
+ * Element[] and passes the array directly to AnimationBuilder instead of a single element.
140
+ */
141
+ private _createInstanceForElements;
142
+ /**
143
+ * Resolve a CSS selector string or Element into an array of DOM elements.
144
+ */
145
+ private _resolveTargetElements;
146
+ /**
147
+ * Generic helper for each-mode setup: resolve targets, create instances, register triggers.
148
+ * The setupTrigger callback receives each (instance, element) pair for trigger-specific registration.
149
+ */
150
+ private _setupEachModeGeneric;
151
+ /**
152
+ * Set up each-mode: create independent timeline instances for each target element
153
+ */
154
+ private _setupEachMode;
155
+ /**
156
+ * Trigger timeline on hover (mouseenter plays, mouseleave configurable)
157
+ */
158
+ onHover(config?: HoverConfig): this;
159
+ /**
160
+ * Trigger timeline on click
161
+ */
162
+ onClick(config?: ClickConfig): this;
163
+ /**
164
+ * Trigger timeline on scroll
165
+ */
166
+ onScroll(config?: ScrollConfig): this;
167
+ /**
168
+ * Trigger timeline on mouse movement
169
+ * Drives animation progress based on mouse position (axis mode) or distance from center (distance mode)
170
+ */
171
+ onMouseMove(config?: MouseMoveConfig): this;
172
+ /**
173
+ * Set up each-mode for mouse movement: create independent timeline instances for each target element
174
+ */
175
+ private _setupMouseMoveEachMode;
176
+ /**
177
+ * Trigger timeline on page load
178
+ */
179
+ onPageLoad(): this;
180
+ /**
181
+ * Trigger timeline when user navigates away from the page (clicks a link).
182
+ * Intercepts the click, plays the exit animation, then navigates to the target URL.
183
+ */
184
+ onPageExit(config?: PageExitConfig): this;
185
+ /**
186
+ * Trigger timeline based on user gestures (pointer, touch, wheel, scroll)
187
+ * Maps directional callbacks to timeline actions
188
+ */
189
+ onGesture(config: GestureConfig): this;
190
+ /**
191
+ * Set up each-mode for gesture: create independent instances for each target element
192
+ */
193
+ private _setupGestureEachMode;
194
+ /**
195
+ * Attach cursor behavior to this timeline's target element
196
+ * Creates a custom cursor that follows mouse with smooth tracking and state-based animations
197
+ */
198
+ onCursor(config: CursorConfig): this;
199
+ /**
200
+ * Update a callback child: fire when time crosses its position
201
+ */
202
+ private _updateCallbackChild;
203
+ /**
204
+ * Update an animation child: seek/activate/deactivate based on parent time
205
+ */
206
+ private _updateAnimationChild;
207
+ /**
208
+ * Update a nested timeline child: seek/activate/deactivate based on parent time
209
+ */
210
+ private _updateTimelineChild;
211
+ /**
212
+ * Update timeline by delta time
213
+ */
214
+ update(deltaTime: number): void;
215
+ /**
216
+ * Play timeline from position.
217
+ * If already playing forward, continues from current position.
218
+ */
219
+ play(from?: number): this;
220
+ /**
221
+ * Pause timeline at time
222
+ */
223
+ pause(atTime?: number): this;
224
+ /**
225
+ * Reverse timeline from position.
226
+ * If already reversing, continues from current position.
227
+ */
228
+ reverse(from?: number): this;
229
+ /**
230
+ * Restart timeline
231
+ */
232
+ restart(): this;
233
+ /**
234
+ * Render only position-0 (non-lazy) animations at their start state
235
+ */
236
+ private _renderPositionZeroAnimations;
237
+ /**
238
+ * Seek to position
239
+ */
240
+ seek(position: number): this;
241
+ /**
242
+ * Set progress for animations bound to a specific axis (for mouse movement trigger)
243
+ * Only affects animations that have .axis() set to the specified axis.
244
+ * @param axis - 'x' or 'y'
245
+ * @param value - Progress value (0-1)
246
+ */
247
+ setAxisProgress(axis: 'x' | 'y', value: number): this;
248
+ /**
249
+ * Set callback for when timeline starts playing
250
+ */
251
+ onStart(callback: () => void): this;
252
+ /**
253
+ * Set callback for progress updates (called every frame while active)
254
+ * @param callback - Receives (progress: 0-1, time: seconds)
255
+ */
256
+ onUpdate(callback: (progress: number, time: number) => void): this;
257
+ /**
258
+ * Set callback for when timeline completes
259
+ */
260
+ onComplete(callback: () => void): this;
261
+ /**
262
+ * Get or set progress (0-1)
263
+ */
264
+ progress(): number;
265
+ progress(value: number): this;
266
+ /**
267
+ * Get or set time in seconds
268
+ */
269
+ time(): number;
270
+ time(value: number): this;
271
+ /**
272
+ * Get or set time scale (speed multiplier)
273
+ */
274
+ timeScale(): number;
275
+ timeScale(value: number): this;
276
+ /**
277
+ * Kill timeline and all children, reset all state
278
+ * @param clearProps - If true (default), restore elements to their initial CSS values
279
+ */
280
+ kill(clearProps?: boolean): void;
281
+ /**
282
+ * Check if timeline is currently active
283
+ */
284
+ isActive(): boolean;
285
+ /**
286
+ * Get timeline name
287
+ */
288
+ getName(): string | undefined;
289
+ /**
290
+ * Get first child animation (for trigger target resolution).
291
+ * @internal
292
+ */
293
+ getFirstChildAnimation(): Animation | null;
294
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Easing Functions
3
+ *
4
+ * All easings are based on Robert Penner's easing equations
5
+ * and normalized to accept/return values in the 0-1 range
6
+ */
7
+ import type { EasingFunction } from '../types';
8
+ export declare const linear: (t: number) => number;
9
+ export declare const none: (t: number) => number;
10
+ export declare const power1: {
11
+ in: (t: number) => number;
12
+ out: (t: number) => number;
13
+ inOut: (t: number) => number;
14
+ };
15
+ export declare const power2: {
16
+ in: (t: number) => number;
17
+ out: (t: number) => number;
18
+ inOut: (t: number) => number;
19
+ };
20
+ export declare const power3: {
21
+ in: (t: number) => number;
22
+ out: (t: number) => number;
23
+ inOut: (t: number) => number;
24
+ };
25
+ export declare const power4: {
26
+ in: (t: number) => number;
27
+ out: (t: number) => number;
28
+ inOut: (t: number) => number;
29
+ };
30
+ export declare const sine: {
31
+ in: (t: number) => number;
32
+ out: (t: number) => number;
33
+ inOut: (t: number) => number;
34
+ };
35
+ export declare const expo: {
36
+ in: (t: number) => number;
37
+ out: (t: number) => number;
38
+ inOut: (t: number) => number;
39
+ };
40
+ export declare const circ: {
41
+ in: (t: number) => number;
42
+ out: (t: number) => number;
43
+ inOut: (t: number) => number;
44
+ };
45
+ export declare const back: {
46
+ in: (t: number) => number;
47
+ out: (t: number) => number;
48
+ inOut: (t: number) => number;
49
+ };
50
+ export declare const elastic: {
51
+ in: (t: number) => number;
52
+ out: (t: number) => number;
53
+ inOut: (t: number) => number;
54
+ };
55
+ export declare const bounce: {
56
+ in: (t: number) => number;
57
+ out: (t: number) => number;
58
+ inOut: (t: number) => number;
59
+ };
60
+ /**
61
+ * Get an easing function by string name
62
+ * @param name Easing name (case insensitive)
63
+ * @returns Easing function, or power1.out if not found
64
+ */
65
+ export declare function getEasing(name: string): EasingFunction;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * FitResolver — SDK-native Fit animation geometry resolution
3
+ *
4
+ * Captures source and target element bounding rects at play time,
5
+ * computes position and scale deltas, and creates PropTweens that
6
+ * animate the source element toward the target's geometry.
7
+ *
8
+ * Non-absolute mode (default): animates CSS transforms (x, y, scaleX, scaleY)
9
+ * Resize mode: animates CSS transforms (x, y) + width/height properties (no content distortion)
10
+ * Absolute mode: animates CSS left/top/width/height properties
11
+ */
12
+ export {};