@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.
- package/README.md +817 -0
- package/dist/core/Animation.d.ts +230 -0
- package/dist/core/AnimationBuilder.d.ts +125 -0
- package/dist/core/Engine.d.ts +140 -0
- package/dist/core/Motion.d.ts +56 -0
- package/dist/core/PropTween.d.ts +81 -0
- package/dist/core/Ticker.d.ts +107 -0
- package/dist/core/Timeline.d.ts +294 -0
- package/dist/easing/index.d.ts +65 -0
- package/dist/fit/FitResolver.d.ts +12 -0
- package/dist/index.cjs +34 -0
- package/dist/index.cjs.map +52 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +52 -0
- package/dist/memory/AnimationPool.d.ts +14 -0
- package/dist/memory/ObjectPool.d.ts +37 -0
- package/dist/memory/PropTweenPool.d.ts +14 -0
- package/dist/registries/SDKRegistry.d.ts +69 -0
- package/dist/render/CSSRenderer.d.ts +33 -0
- package/dist/render/PathRenderer.d.ts +24 -0
- package/dist/render/RenderBatch.d.ts +27 -0
- package/dist/render/TransformCache.d.ts +54 -0
- package/dist/stagger/StaggerResolver.d.ts +28 -0
- package/dist/triggers/BaseTrigger.d.ts +61 -0
- package/dist/triggers/CursorTrigger.d.ts +86 -0
- package/dist/triggers/EventTrigger.d.ts +48 -0
- package/dist/triggers/GestureTrigger.d.ts +137 -0
- package/dist/triggers/MarkerManager.d.ts +42 -0
- package/dist/triggers/MouseMoveTrigger.d.ts +49 -0
- package/dist/triggers/PageExitTrigger.d.ts +74 -0
- package/dist/triggers/PageLoadTrigger.d.ts +37 -0
- package/dist/triggers/PinManager.d.ts +131 -0
- package/dist/triggers/ScrollTrigger.d.ts +103 -0
- package/dist/triggers/TriggerManager.d.ts +133 -0
- package/dist/types/index.d.ts +355 -0
- package/dist/types/public.d.ts +7 -0
- package/dist/utils/ColorParser.d.ts +23 -0
- package/dist/utils/DrawSVGParser.d.ts +62 -0
- package/dist/utils/FilterParser.d.ts +49 -0
- package/dist/utils/MotionUtils.d.ts +136 -0
- package/dist/utils/PathParser.d.ts +89 -0
- package/dist/utils/PositionParser.d.ts +24 -0
- package/dist/utils/PropertyParser.d.ts +159 -0
- package/dist/utils/QuickSetter.d.ts +16 -0
- package/dist/utils/ScrollPositionParser.d.ts +19 -0
- package/dist/utils/StyleReset.d.ts +73 -0
- package/dist/utils/TargetResolver.d.ts +23 -0
- package/dist/utils/TextSplitter.d.ts +90 -0
- package/dist/utils/executeTimelineAction.d.ts +18 -0
- package/dist/utils/getLayoutRect.d.ts +10 -0
- package/package.json +56 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MouseMoveTrigger
|
|
3
|
+
*
|
|
4
|
+
* Triggers timelines based on mouse movement:
|
|
5
|
+
* - distance: progress based on distance from center of viewport/target
|
|
6
|
+
* - axis: progress based on X/Y position within viewport/target
|
|
7
|
+
*
|
|
8
|
+
* Supports:
|
|
9
|
+
* - Viewport or custom target element tracking
|
|
10
|
+
* - Optional smoothing (lerp interpolation)
|
|
11
|
+
* - Custom start/leave progress values
|
|
12
|
+
* - Per-element triggers with "each" mode
|
|
13
|
+
*/
|
|
14
|
+
import type { MouseMoveConfig } from '../types';
|
|
15
|
+
import type { Timeline } from '../core/Timeline';
|
|
16
|
+
import { BaseTrigger } from './BaseTrigger';
|
|
17
|
+
export declare class MouseMoveTrigger extends BaseTrigger<MouseMoveConfig> {
|
|
18
|
+
private _targets;
|
|
19
|
+
private _listeners;
|
|
20
|
+
private _frozenRects;
|
|
21
|
+
private _state;
|
|
22
|
+
private _targetState;
|
|
23
|
+
private _tickerCallback?;
|
|
24
|
+
private readonly _defaultStartProgress;
|
|
25
|
+
private readonly _defaultLeaveProgress;
|
|
26
|
+
constructor(timeline: Timeline, config: MouseMoveConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Set up mouse event listeners once DOM is ready.
|
|
29
|
+
*/
|
|
30
|
+
protected _onEnable(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Remove all event listeners and stop the smoothing ticker.
|
|
33
|
+
*/
|
|
34
|
+
protected _onDisable(): void;
|
|
35
|
+
private _addViewportListeners;
|
|
36
|
+
/**
|
|
37
|
+
* Re-snapshot frozen rects after layout changes (e.g. window resize).
|
|
38
|
+
* Called by TriggerManager on resize.
|
|
39
|
+
*/
|
|
40
|
+
refresh(): void;
|
|
41
|
+
private _addTargetListeners;
|
|
42
|
+
private _handleViewportMouseMove;
|
|
43
|
+
private _handleTargetMouseMove;
|
|
44
|
+
private _handleMouseLeave;
|
|
45
|
+
private _applyProgress;
|
|
46
|
+
private _startSmoothingTicker;
|
|
47
|
+
private _lerp;
|
|
48
|
+
private _updateTimelineProgress;
|
|
49
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PageExitTrigger
|
|
3
|
+
*
|
|
4
|
+
* Triggers timeline playback when a user clicks a link that would navigate away
|
|
5
|
+
* from the current page. Intercepts the click, plays the exit animation, then
|
|
6
|
+
* navigates to the target URL after the timeline completes.
|
|
7
|
+
*
|
|
8
|
+
* Supports three link selection modes:
|
|
9
|
+
* - 'all': intercept all navigation links (default)
|
|
10
|
+
* - 'include': only intercept links matching specific selectors
|
|
11
|
+
* - 'exclude': intercept all links except those matching specific selectors
|
|
12
|
+
*
|
|
13
|
+
* Supports skipping certain href patterns:
|
|
14
|
+
* - 'anchor': skip # links (same-page anchors)
|
|
15
|
+
* - 'javascript': skip javascript: hrefs
|
|
16
|
+
* - 'mailto': skip mailto: and tel: hrefs
|
|
17
|
+
*
|
|
18
|
+
* Works on all websites — no server-side dependencies (PHP, Node, etc.).
|
|
19
|
+
*/
|
|
20
|
+
import type { Timeline } from '../core/Timeline';
|
|
21
|
+
import { BaseTrigger } from './BaseTrigger';
|
|
22
|
+
/** Configuration for PageExitTrigger */
|
|
23
|
+
export interface PageExitTriggerConfig {
|
|
24
|
+
/** Link selection mode: 'all' (default), 'include', or 'exclude' */
|
|
25
|
+
mode?: 'all' | 'include' | 'exclude';
|
|
26
|
+
/** CSS selector(s) for links — required for 'include'/'exclude' modes */
|
|
27
|
+
selectors?: string;
|
|
28
|
+
/** Href patterns to skip (never intercept) */
|
|
29
|
+
skipHref?: ('anchor' | 'javascript' | 'mailto')[];
|
|
30
|
+
}
|
|
31
|
+
export declare class PageExitTrigger extends BaseTrigger<PageExitTriggerConfig> {
|
|
32
|
+
private _links;
|
|
33
|
+
private _listeners;
|
|
34
|
+
private _isNavigating;
|
|
35
|
+
private _pendingUrl;
|
|
36
|
+
private _onCompleteHandler;
|
|
37
|
+
private _pollTimerId;
|
|
38
|
+
constructor(timeline: Timeline, config: PageExitTriggerConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Set up click listeners on qualifying links once DOM is ready.
|
|
41
|
+
*/
|
|
42
|
+
protected _onEnable(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Remove all click listeners and cancel pending navigation.
|
|
45
|
+
*/
|
|
46
|
+
protected _onDisable(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Detect if we're running inside the Motion.page builder iframe.
|
|
49
|
+
* Exit animations should not intercept clicks in the builder.
|
|
50
|
+
*/
|
|
51
|
+
private _isInsideBuilder;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve which <a> elements should be intercepted based on config mode.
|
|
54
|
+
*/
|
|
55
|
+
private _resolveLinks;
|
|
56
|
+
/**
|
|
57
|
+
* Determine if a link should be intercepted based on its href and skipHref config.
|
|
58
|
+
* Skips links that don't actually navigate away.
|
|
59
|
+
*/
|
|
60
|
+
private _shouldIntercept;
|
|
61
|
+
/**
|
|
62
|
+
* Attach click listeners to all resolved links.
|
|
63
|
+
*/
|
|
64
|
+
private _addClickListeners;
|
|
65
|
+
/**
|
|
66
|
+
* Wait for the timeline to complete, then navigate.
|
|
67
|
+
* Uses requestAnimationFrame polling to check timeline progress.
|
|
68
|
+
*/
|
|
69
|
+
private _waitForCompletion;
|
|
70
|
+
/**
|
|
71
|
+
* Navigate to the pending URL.
|
|
72
|
+
*/
|
|
73
|
+
private _navigate;
|
|
74
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PageLoadTrigger
|
|
3
|
+
*
|
|
4
|
+
* Triggers timelines based on page load events:
|
|
5
|
+
* - timing: 'before' - plays immediately (before DOMContentLoaded)
|
|
6
|
+
* - timing: 'during' - plays on DOMContentLoaded
|
|
7
|
+
* - timing: 'after' - plays on window load event
|
|
8
|
+
*/
|
|
9
|
+
import type { Timeline } from '../core/Timeline';
|
|
10
|
+
import type { PageLoadTriggerConfig } from './TriggerManager';
|
|
11
|
+
export declare class PageLoadTrigger {
|
|
12
|
+
private _registrations;
|
|
13
|
+
private _domContentLoaded;
|
|
14
|
+
private _windowLoaded;
|
|
15
|
+
private _initialized;
|
|
16
|
+
constructor();
|
|
17
|
+
private _initialize;
|
|
18
|
+
/**
|
|
19
|
+
* Register a timeline with pageLoad trigger
|
|
20
|
+
*/
|
|
21
|
+
register(timeline: Timeline, config: PageLoadTriggerConfig): void;
|
|
22
|
+
/**
|
|
23
|
+
* Unregister a timeline from page load trigger
|
|
24
|
+
*/
|
|
25
|
+
unregister(timeline: Timeline): void;
|
|
26
|
+
/**
|
|
27
|
+
* Clear all registrations
|
|
28
|
+
*/
|
|
29
|
+
clear(): void;
|
|
30
|
+
private _triggerDuring;
|
|
31
|
+
private _triggerAfter;
|
|
32
|
+
/**
|
|
33
|
+
* Reset for testing - DO NOT USE IN PRODUCTION
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
_reset(): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PinManager
|
|
3
|
+
*
|
|
4
|
+
* Handles element pinning during scroll animations.
|
|
5
|
+
* Extracted from ScrollTrigger for better separation of concerns.
|
|
6
|
+
*
|
|
7
|
+
* Two pinning strategies based on scroller type:
|
|
8
|
+
* 1. Window scroller: position:fixed (seamless, no jitter)
|
|
9
|
+
* 2. Custom scroller: translate3d (counters scroll movement)
|
|
10
|
+
*
|
|
11
|
+
* State machine: before → pinned → after
|
|
12
|
+
*/
|
|
13
|
+
export type PinState = 'before' | 'pinned' | 'after';
|
|
14
|
+
export declare class PinManager {
|
|
15
|
+
private static _registry;
|
|
16
|
+
private static _users;
|
|
17
|
+
/**
|
|
18
|
+
* Get or create a shared PinManager for the given element.
|
|
19
|
+
* If another ScrollTrigger already pinned this element, returns that same
|
|
20
|
+
* PinManager so no additional spacer is created. Tracks `id` as a user.
|
|
21
|
+
*/
|
|
22
|
+
static getOrCreate(id: number, element: HTMLElement): PinManager;
|
|
23
|
+
/**
|
|
24
|
+
* Release a ScrollTrigger's reference to a pinned element's PinManager.
|
|
25
|
+
* When the last user releases, cleanup() is called and registry entries removed.
|
|
26
|
+
*/
|
|
27
|
+
static release(id: number, element: HTMLElement): void;
|
|
28
|
+
private _id;
|
|
29
|
+
private _element;
|
|
30
|
+
private _originalStyles;
|
|
31
|
+
private _spacer;
|
|
32
|
+
private _currentState;
|
|
33
|
+
private _pinStart;
|
|
34
|
+
private _pinEnd;
|
|
35
|
+
private _pinDistance;
|
|
36
|
+
private _useFixedPin;
|
|
37
|
+
private _pinSpacing;
|
|
38
|
+
private _elementHeight;
|
|
39
|
+
private _fixedTop;
|
|
40
|
+
private _fixedLeft;
|
|
41
|
+
private _width;
|
|
42
|
+
constructor(id: number);
|
|
43
|
+
/**
|
|
44
|
+
* Setup pinning for an element
|
|
45
|
+
*
|
|
46
|
+
* @param element - The element to pin
|
|
47
|
+
* @param pinStart - Scroll position where pin starts
|
|
48
|
+
* @param pinEnd - Scroll position where pin ends
|
|
49
|
+
* @param scrollerStartOffset - Viewport offset for fixed positioning
|
|
50
|
+
* @param useFixedPin - true for window scroller (position:fixed), false for custom (transform)
|
|
51
|
+
*/
|
|
52
|
+
setup(element: HTMLElement, pinStart: number, pinEnd: number, scrollerStartOffset: number, useFixedPin: boolean, pinSpacing?: boolean | 'margin' | 'padding'): void;
|
|
53
|
+
/**
|
|
54
|
+
* Update pin state based on scroll position
|
|
55
|
+
*/
|
|
56
|
+
update(scrollTop: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Clean up pin - restore original styles and remove spacer
|
|
59
|
+
*/
|
|
60
|
+
cleanup(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Get the pinned element
|
|
63
|
+
*/
|
|
64
|
+
getElement(): HTMLElement | null;
|
|
65
|
+
/**
|
|
66
|
+
* Get the pin distance (scroll range over which element is pinned)
|
|
67
|
+
*/
|
|
68
|
+
getPinDistance(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Get current pin state
|
|
71
|
+
*/
|
|
72
|
+
getState(): PinState;
|
|
73
|
+
/**
|
|
74
|
+
* Get a layout rect for trigger-position calculations.
|
|
75
|
+
*
|
|
76
|
+
* Used by ScrollTrigger._calculateTriggerPositions() and refresh() to obtain the
|
|
77
|
+
* correct document-relative position of the pinned element when it is position:fixed
|
|
78
|
+
* — querying the element itself in that state returns viewport-relative coordinates,
|
|
79
|
+
* which produce incorrect trigger positions.
|
|
80
|
+
*
|
|
81
|
+
* Returns a synthetic rect that combines:
|
|
82
|
+
* - top/left/width from the spacer (document-flow position)
|
|
83
|
+
* - height from _elementHeight (the element's natural content height)
|
|
84
|
+
*
|
|
85
|
+
* The spacer's own BCR height is NOT used because it includes padding-bottom
|
|
86
|
+
* (= pinDistance, added for pin spacing), which would inflate callers' end-position
|
|
87
|
+
* calculations and grow the pinDistance on every refresh cycle.
|
|
88
|
+
*
|
|
89
|
+
* Returns `null` when the spacer is not in the DOM (transform-pin strategy or
|
|
90
|
+
* before first setup), signalling the caller to fall back to the element's own rect.
|
|
91
|
+
*/
|
|
92
|
+
getLayoutRect(): {
|
|
93
|
+
top: number;
|
|
94
|
+
left: number;
|
|
95
|
+
width: number;
|
|
96
|
+
height: number;
|
|
97
|
+
bottom: number;
|
|
98
|
+
right: number;
|
|
99
|
+
} | null;
|
|
100
|
+
/**
|
|
101
|
+
* Check if using fixed pin strategy
|
|
102
|
+
*/
|
|
103
|
+
isFixedPin(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Resolve pinSpacing config to a concrete value
|
|
106
|
+
*/
|
|
107
|
+
private _resolvePinSpacing;
|
|
108
|
+
/**
|
|
109
|
+
* Fixed positioning for window scroller (seamless pinning)
|
|
110
|
+
*
|
|
111
|
+
* Wrapper pattern: the spacer wraps the element at all times (created in
|
|
112
|
+
* setup, removed in cleanup). State changes only toggle styles on the
|
|
113
|
+
* element — no spacer insertion/removal between states.
|
|
114
|
+
*
|
|
115
|
+
* Layout math (wrapper):
|
|
116
|
+
* Spacer content-height = elementHeight
|
|
117
|
+
* Spacer padding-bottom = pinDistance (when pinSpacing enabled)
|
|
118
|
+
* Spacer total box = elementHeight + pinDistance
|
|
119
|
+
*
|
|
120
|
+
* 'before': element in flow inside spacer at top — no offset
|
|
121
|
+
* 'pinned': element position:fixed, spacer holds space
|
|
122
|
+
* 'after': element back in flow at spacer top, translateY(pinDistance)
|
|
123
|
+
* moves it visually to (originalPos + pinDistance) — seamless
|
|
124
|
+
* transition with the next section
|
|
125
|
+
*/
|
|
126
|
+
private _updateFixed;
|
|
127
|
+
/**
|
|
128
|
+
* Transform-based pinning for custom scroll containers
|
|
129
|
+
*/
|
|
130
|
+
private _updateTransform;
|
|
131
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScrollTrigger
|
|
3
|
+
*
|
|
4
|
+
* Triggers timelines based on scroll position:
|
|
5
|
+
* - start/end parameters define trigger zone (GSAP-style)
|
|
6
|
+
* - scrub links animation progress to scroll position
|
|
7
|
+
* - scrub: number adds smooth lag (in seconds)
|
|
8
|
+
* - scroller: custom scroll container (default: window)
|
|
9
|
+
* - pin: fix element in place during animation
|
|
10
|
+
* - markers shows debug markers (optional)
|
|
11
|
+
*
|
|
12
|
+
* Pin implementation:
|
|
13
|
+
* - Window scroller: uses position:fixed (seamless, no jitter)
|
|
14
|
+
* - Custom scroller: uses transform (slight lag unavoidable)
|
|
15
|
+
*
|
|
16
|
+
* Start/End format: "<element_position> <scroller_position>"
|
|
17
|
+
* - Keywords: top, center, bottom
|
|
18
|
+
* - Units: 100px, 50%, 20vh
|
|
19
|
+
* - Relative: +=500px (for end only)
|
|
20
|
+
*/
|
|
21
|
+
import type { ScrollConfig } from '../types';
|
|
22
|
+
import type { Timeline } from '../core/Timeline';
|
|
23
|
+
import { BaseTrigger } from './BaseTrigger';
|
|
24
|
+
export declare class ScrollTrigger extends BaseTrigger<ScrollConfig> {
|
|
25
|
+
private static _nextId;
|
|
26
|
+
private _id;
|
|
27
|
+
private static readonly _SCRUB_TICKER_PRIORITY;
|
|
28
|
+
private static _activeInstances;
|
|
29
|
+
private static _loadListenerAdded;
|
|
30
|
+
private _scrollListener?;
|
|
31
|
+
private _scrubTickListener;
|
|
32
|
+
private _currentProgress;
|
|
33
|
+
private _targetProgress;
|
|
34
|
+
private _scrubLag;
|
|
35
|
+
private _scroller;
|
|
36
|
+
private _triggerStart;
|
|
37
|
+
private _triggerEnd;
|
|
38
|
+
private _pinManager;
|
|
39
|
+
private _markerManager;
|
|
40
|
+
private _triggerState;
|
|
41
|
+
private _toggleActions;
|
|
42
|
+
private _initializing;
|
|
43
|
+
constructor(timeline: Timeline, config: ScrollConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Register the global window.load listener (once).
|
|
46
|
+
* After all resources finish loading, refresh every active ScrollTrigger
|
|
47
|
+
* so trigger positions account for layout shifts caused by images/fonts.
|
|
48
|
+
*/
|
|
49
|
+
private static _ensureLoadListener;
|
|
50
|
+
private _resolveScroller;
|
|
51
|
+
private _resolvePinElement;
|
|
52
|
+
/**
|
|
53
|
+
* Default start position — matches GSAP behavior:
|
|
54
|
+
* - With pin: 'top top' (element top hits viewport top)
|
|
55
|
+
* - Without pin: 'top bottom' (element top hits viewport bottom)
|
|
56
|
+
*/
|
|
57
|
+
private _defaultStart;
|
|
58
|
+
/**
|
|
59
|
+
* Default end position — matches GSAP behavior:
|
|
60
|
+
* 'bottom top' (element bottom hits viewport top)
|
|
61
|
+
*/
|
|
62
|
+
private _defaultEnd;
|
|
63
|
+
private _getFirstAnimatedElement;
|
|
64
|
+
/**
|
|
65
|
+
* Resolve the trigger element from config or first animation
|
|
66
|
+
*/
|
|
67
|
+
private _resolveTriggerElement;
|
|
68
|
+
/**
|
|
69
|
+
* Calculate trigger start/end scroll positions based on config.
|
|
70
|
+
*
|
|
71
|
+
* Pin distance equals the trigger range (triggerEnd - triggerStart).
|
|
72
|
+
* The PinManager spacer adds exactly that many pixels of scroll room to the
|
|
73
|
+
* page, so the animation always plays over the full configured distance while
|
|
74
|
+
* the element is pinned — no separate "extension" step is needed.
|
|
75
|
+
*
|
|
76
|
+
* When refresh() is called while the element is position:fixed (pinned), we
|
|
77
|
+
* use the spacer's rect instead of the element's rect. A position:fixed
|
|
78
|
+
* element returns viewport-relative coordinates from getBoundingClientRect(),
|
|
79
|
+
* which would produce incorrect document-relative trigger positions. The
|
|
80
|
+
* spacer sits in the element's original place in the document flow, so its
|
|
81
|
+
* rect always reflects the correct base for the calculation.
|
|
82
|
+
*/
|
|
83
|
+
private _calculateTriggerPositions;
|
|
84
|
+
protected _onEnable(): void;
|
|
85
|
+
protected _onDisable(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Refresh trigger positions (call after layout changes like resize)
|
|
88
|
+
*/
|
|
89
|
+
refresh(): void;
|
|
90
|
+
private _getViewportHeight;
|
|
91
|
+
private _getScrollTop;
|
|
92
|
+
private _getScrollHeight;
|
|
93
|
+
private _onScroll;
|
|
94
|
+
/**
|
|
95
|
+
* Apply snap to a raw progress value based on config.snap.
|
|
96
|
+
* - number: snap to evenly-spaced increments (e.g. 0.25 → 0, 0.25, 0.5, 0.75, 1)
|
|
97
|
+
* - number[]: snap to nearest value in array
|
|
98
|
+
* - function: custom snap function
|
|
99
|
+
*/
|
|
100
|
+
private _applySnap;
|
|
101
|
+
private _startSmoothScrollLoop;
|
|
102
|
+
private _stopSmoothScrollLoop;
|
|
103
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TriggerManager
|
|
3
|
+
*
|
|
4
|
+
* Coordinates all trigger types (pageLoad, pageExit, scroll, hover, click, mouseMove, gesture)
|
|
5
|
+
* and activates timelines based on trigger conditions.
|
|
6
|
+
*
|
|
7
|
+
* Uses a registry pattern for trigger classes to avoid importing them directly.
|
|
8
|
+
* Each trigger module registers itself via TriggerManager.registerTrigger() when loaded.
|
|
9
|
+
* This enables tree-shaking: only trigger types included in the bundle are available.
|
|
10
|
+
*/
|
|
11
|
+
import type { ScrollConfig, MouseMoveConfig, GestureConfig, HoverConfig, ClickConfig, CursorConfig, PageExitConfig } from '../types';
|
|
12
|
+
import type { Timeline } from '../core/Timeline';
|
|
13
|
+
/** Config for page load trigger */
|
|
14
|
+
export interface PageLoadTriggerConfig {
|
|
15
|
+
timing?: 'before' | 'during' | 'after';
|
|
16
|
+
}
|
|
17
|
+
/** Interface that trigger instances must satisfy for cleanup */
|
|
18
|
+
interface TriggerInstance {
|
|
19
|
+
enable(): void;
|
|
20
|
+
disable(): void;
|
|
21
|
+
}
|
|
22
|
+
/** Interface for PageLoadTrigger specifically */
|
|
23
|
+
interface PageLoadTriggerInstance {
|
|
24
|
+
register(timeline: Timeline, config: PageLoadTriggerConfig): void;
|
|
25
|
+
unregister(timeline: Timeline): void;
|
|
26
|
+
clear(): void;
|
|
27
|
+
_reset(): void;
|
|
28
|
+
}
|
|
29
|
+
/** Trigger class constructors stored in registry */
|
|
30
|
+
type TriggerFactory = new (...args: any[]) => TriggerInstance;
|
|
31
|
+
export declare class TriggerManager {
|
|
32
|
+
private static _instance;
|
|
33
|
+
/** Registry for trigger class constructors - populated by each trigger module on load */
|
|
34
|
+
private static _triggerRegistry;
|
|
35
|
+
/** PageLoadTrigger factory - separate because it has a different interface */
|
|
36
|
+
private static _pageLoadTriggerFactory;
|
|
37
|
+
/** Debounce delay (ms) for the window resize → refreshScrollTriggers handler */
|
|
38
|
+
private static readonly _RESIZE_DEBOUNCE_MS;
|
|
39
|
+
private _pageLoadTrigger;
|
|
40
|
+
private _scrollTriggers;
|
|
41
|
+
private _eventTriggers;
|
|
42
|
+
private _mouseMoveTriggers;
|
|
43
|
+
private _gestureTriggers;
|
|
44
|
+
private _cursorTriggers;
|
|
45
|
+
private _pageExitTriggers;
|
|
46
|
+
/** Bound resize handler (created once, reused for add/removeEventListener) */
|
|
47
|
+
private _resizeHandler;
|
|
48
|
+
/** Timer id for debounced resize */
|
|
49
|
+
private _resizeTimer;
|
|
50
|
+
/** All trigger maps — used by unregister() and killAll() for bulk iteration */
|
|
51
|
+
private get _allTriggerMaps();
|
|
52
|
+
private constructor();
|
|
53
|
+
static getInstance(): TriggerManager;
|
|
54
|
+
/**
|
|
55
|
+
* Register a trigger class. Called by each trigger module when it loads.
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
static registerTrigger(type: string, factory: TriggerFactory): void;
|
|
59
|
+
/**
|
|
60
|
+
* Register the PageLoadTrigger class. Called by PageLoadTrigger module when it loads.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
static registerPageLoadTrigger(factory: new () => PageLoadTriggerInstance): void;
|
|
64
|
+
/** Get or create the PageLoadTrigger instance */
|
|
65
|
+
private _getPageLoadTrigger;
|
|
66
|
+
/** Create a trigger instance from the registry */
|
|
67
|
+
private _createTrigger;
|
|
68
|
+
/**
|
|
69
|
+
* Register a pageLoad trigger
|
|
70
|
+
*/
|
|
71
|
+
registerPageLoad(timeline: Timeline, config: PageLoadTriggerConfig): void;
|
|
72
|
+
/**
|
|
73
|
+
* Attach a debounced window resize listener that refreshes all scroll triggers.
|
|
74
|
+
* Called lazily when the first scroll trigger is registered.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
private _attachResizeListener;
|
|
78
|
+
/**
|
|
79
|
+
* Detach the window resize listener.
|
|
80
|
+
* Called when the last scroll trigger is removed or killAll() is invoked.
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
private _detachResizeListener;
|
|
84
|
+
/**
|
|
85
|
+
* Register a scroll trigger
|
|
86
|
+
*/
|
|
87
|
+
registerScroll(timeline: Timeline, config: ScrollConfig): void;
|
|
88
|
+
/**
|
|
89
|
+
* Register a hover trigger
|
|
90
|
+
*/
|
|
91
|
+
registerHover(timeline: Timeline, config: HoverConfig): void;
|
|
92
|
+
/**
|
|
93
|
+
* Register a click trigger
|
|
94
|
+
*/
|
|
95
|
+
registerClick(timeline: Timeline, config: ClickConfig): void;
|
|
96
|
+
/**
|
|
97
|
+
* Register a mouseMove trigger
|
|
98
|
+
*/
|
|
99
|
+
registerMouseMove(timeline: Timeline, config: MouseMoveConfig): void;
|
|
100
|
+
/**
|
|
101
|
+
* Register a gesture trigger
|
|
102
|
+
*/
|
|
103
|
+
registerGesture(timeline: Timeline, config: GestureConfig): void;
|
|
104
|
+
/**
|
|
105
|
+
* Register a cursor trigger
|
|
106
|
+
*/
|
|
107
|
+
registerCursor(timeline: Timeline, config: CursorConfig): void;
|
|
108
|
+
/**
|
|
109
|
+
* Register a page exit trigger
|
|
110
|
+
*/
|
|
111
|
+
registerPageExit(timeline: Timeline, config: PageExitConfig): void;
|
|
112
|
+
/**
|
|
113
|
+
* Unregister a timeline
|
|
114
|
+
*/
|
|
115
|
+
unregister(timeline: Timeline): void;
|
|
116
|
+
/**
|
|
117
|
+
* Refresh all position-based triggers after layout changes (e.g. window resize).
|
|
118
|
+
* This includes scroll triggers, hover event triggers, gesture triggers, and
|
|
119
|
+
* mouseMove triggers — all of which cache element bounds at setup time.
|
|
120
|
+
*/
|
|
121
|
+
refreshScrollTriggers(): void;
|
|
122
|
+
/**
|
|
123
|
+
* Kill all triggers
|
|
124
|
+
*/
|
|
125
|
+
killAll(): void;
|
|
126
|
+
/**
|
|
127
|
+
* Reset for testing - DO NOT USE IN PRODUCTION
|
|
128
|
+
* Resets the singleton instance
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
static _reset(): void;
|
|
132
|
+
}
|
|
133
|
+
export {};
|