react-scroll-media 1.0.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/LICENSE +21 -0
- package/README.md +404 -0
- package/dist/index.d.mts +249 -0
- package/dist/index.d.ts +249 -0
- package/dist/index.js +843 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +799 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Public type definitions for react-scroll-media
|
|
7
|
+
*/
|
|
8
|
+
type SequenceSource = {
|
|
9
|
+
type: 'manual';
|
|
10
|
+
frames: string[];
|
|
11
|
+
} | {
|
|
12
|
+
type: 'pattern';
|
|
13
|
+
url: string;
|
|
14
|
+
start?: number;
|
|
15
|
+
end: number;
|
|
16
|
+
pad?: number;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'manifest';
|
|
19
|
+
url: string;
|
|
20
|
+
};
|
|
21
|
+
interface ScrollSequenceProps {
|
|
22
|
+
/**
|
|
23
|
+
* Source configuration for the image sequence.
|
|
24
|
+
* Can be 'manual', 'pattern', or 'manifest'.
|
|
25
|
+
*/
|
|
26
|
+
source: SequenceSource;
|
|
27
|
+
/** If true, shows a debug overlay with progress and frame info. */
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Memory management strategy.
|
|
31
|
+
* 'eager' (default): Preloads all images on mount. Smooth playback, higher memory.
|
|
32
|
+
* 'lazy': Loads images only when needed (curren frame ±3). Saves memory, may stutter on slow networks.
|
|
33
|
+
*/
|
|
34
|
+
memoryStrategy?: 'eager' | 'lazy';
|
|
35
|
+
/**
|
|
36
|
+
* Buffer size for lazy loading (default 10).
|
|
37
|
+
* Number of frames to keep loaded around the current frame.
|
|
38
|
+
*/
|
|
39
|
+
lazyBuffer?: number;
|
|
40
|
+
/** CSS height for the scroll container. Defines the total scroll distance. */
|
|
41
|
+
scrollLength?: string;
|
|
42
|
+
/** CSS class name for the container div. */
|
|
43
|
+
className?: string;
|
|
44
|
+
/** Optional children to render inside the sticky container (e.g. ScrollText). */
|
|
45
|
+
children?: React.ReactNode;
|
|
46
|
+
/** Component to render while the sequence is loading. */
|
|
47
|
+
fallback?: React.ReactNode;
|
|
48
|
+
/** Accessibility label for the canvas (role="img"). Defaults to "Scroll sequence". */
|
|
49
|
+
accessibilityLabel?: string;
|
|
50
|
+
/** Callback fired when an error occurs (e.g. image load failure). */
|
|
51
|
+
onError?: (error: Error) => void;
|
|
52
|
+
}
|
|
53
|
+
interface ResolvedSequence {
|
|
54
|
+
/** Sorted array of frame URLs (sorted numerically by filename). */
|
|
55
|
+
frames: string[];
|
|
56
|
+
/** Total number of frames. */
|
|
57
|
+
frameCount: number;
|
|
58
|
+
}
|
|
59
|
+
interface ScrollProgress {
|
|
60
|
+
/** Progress value between 0 and 1. */
|
|
61
|
+
progress: number;
|
|
62
|
+
/** Current scroll position in pixels. */
|
|
63
|
+
scrollTop: number;
|
|
64
|
+
/** Total scrollable height in pixels. */
|
|
65
|
+
scrollHeight: number;
|
|
66
|
+
/** Viewport height in pixels. */
|
|
67
|
+
viewportHeight: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare const ScrollSequence: React__default.ForwardRefExoticComponent<ScrollSequenceProps & React__default.RefAttributes<HTMLDivElement>>;
|
|
71
|
+
|
|
72
|
+
interface UseScrollSequenceParams {
|
|
73
|
+
source: ScrollSequenceProps['source'];
|
|
74
|
+
debugRef?: React.MutableRefObject<HTMLDivElement | null>;
|
|
75
|
+
memoryStrategy?: 'eager' | 'lazy';
|
|
76
|
+
lazyBuffer?: number;
|
|
77
|
+
onError?: (error: Error) => void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Hook to manage image sequence in a timeline context.
|
|
81
|
+
* MUST be used inside ScrollTimelineProvider.
|
|
82
|
+
*/
|
|
83
|
+
declare function useScrollSequence({ source, debugRef, memoryStrategy, lazyBuffer, onError, }: UseScrollSequenceParams): {
|
|
84
|
+
canvasRef: React$1.RefObject<HTMLCanvasElement>;
|
|
85
|
+
isLoaded: boolean;
|
|
86
|
+
error: Error | null;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
interface ScrollTimelineProviderProps {
|
|
90
|
+
children: React__default.ReactNode;
|
|
91
|
+
/** CSS height for the scroll container (e.g., "300vh"). */
|
|
92
|
+
scrollLength?: string;
|
|
93
|
+
className?: string;
|
|
94
|
+
style?: React__default.CSSProperties;
|
|
95
|
+
}
|
|
96
|
+
declare function ScrollTimelineProvider({ children, scrollLength, className, style, }: ScrollTimelineProviderProps): react_jsx_runtime.JSX.Element;
|
|
97
|
+
|
|
98
|
+
interface ScrollTextProps {
|
|
99
|
+
children: React__default.ReactNode;
|
|
100
|
+
/** Progress start (0-1) where ENTRANCE animation begins */
|
|
101
|
+
start?: number;
|
|
102
|
+
/** Progress end (0-1) where ENTRANCE animation ends */
|
|
103
|
+
end?: number;
|
|
104
|
+
/** Progress start (0-1) where EXIT animation begins. If omitted, element stays visible. */
|
|
105
|
+
exitStart?: number;
|
|
106
|
+
/** Progress end (0-1) where EXIT animation ends */
|
|
107
|
+
exitEnd?: number;
|
|
108
|
+
/** Initial opacity */
|
|
109
|
+
initialOpacity?: number;
|
|
110
|
+
/** Target opacity (when entered) */
|
|
111
|
+
targetOpacity?: number;
|
|
112
|
+
/** Final opacity (after exit) */
|
|
113
|
+
finalOpacity?: number;
|
|
114
|
+
/** Y-axis translation range in pixels (e.g., 50 means move down 50px) */
|
|
115
|
+
translateY?: number;
|
|
116
|
+
style?: React__default.CSSProperties;
|
|
117
|
+
className?: string;
|
|
118
|
+
}
|
|
119
|
+
declare function ScrollText({ children, start, end, exitStart, exitEnd, initialOpacity, targetOpacity, finalOpacity, translateY, style, className, }: ScrollTextProps): react_jsx_runtime.JSX.Element;
|
|
120
|
+
|
|
121
|
+
interface ScrollWordRevealProps {
|
|
122
|
+
text: string;
|
|
123
|
+
/** Progress start (0-1) */
|
|
124
|
+
start?: number;
|
|
125
|
+
/** Progress end (0-1) */
|
|
126
|
+
end?: number;
|
|
127
|
+
className?: string;
|
|
128
|
+
style?: React__default.CSSProperties;
|
|
129
|
+
}
|
|
130
|
+
declare function ScrollWordReveal({ text, start, end, className, style }: ScrollWordRevealProps): react_jsx_runtime.JSX.Element;
|
|
131
|
+
|
|
132
|
+
type TimelineCallback = (progress: number) => void;
|
|
133
|
+
declare class ScrollTimeline {
|
|
134
|
+
private container;
|
|
135
|
+
private subscribers;
|
|
136
|
+
private currentProgress;
|
|
137
|
+
private cachedRect;
|
|
138
|
+
private cachedScrollParent;
|
|
139
|
+
private cachedScrollParentRect;
|
|
140
|
+
private cachedViewportHeight;
|
|
141
|
+
private cachedOffsetTop;
|
|
142
|
+
private isLayoutDirty;
|
|
143
|
+
private resizeObserver;
|
|
144
|
+
readonly id: string;
|
|
145
|
+
constructor(container: Element);
|
|
146
|
+
private onWindowResize;
|
|
147
|
+
/**
|
|
148
|
+
* Subscribe to progress updates.
|
|
149
|
+
* Returns an unsubscribe function.
|
|
150
|
+
*/
|
|
151
|
+
subscribe(callback: TimelineCallback): () => void;
|
|
152
|
+
unsubscribe(callback: TimelineCallback): void;
|
|
153
|
+
/**
|
|
154
|
+
* Start is now handled by LoopManager via subscriptions
|
|
155
|
+
* Deprecated but kept for API stability if needed.
|
|
156
|
+
*/
|
|
157
|
+
start(): void;
|
|
158
|
+
stop(): void;
|
|
159
|
+
private tick;
|
|
160
|
+
private notify;
|
|
161
|
+
private updateCache;
|
|
162
|
+
private calculateProgress;
|
|
163
|
+
private getScrollParent;
|
|
164
|
+
destroy(): void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
interface UseScrollTimelineResult {
|
|
168
|
+
/**
|
|
169
|
+
* Manual subscription to the timeline.
|
|
170
|
+
* Useful for low-level DOM updates (refs) without re-rendering.
|
|
171
|
+
*/
|
|
172
|
+
subscribe: (callback: TimelineCallback) => () => void;
|
|
173
|
+
/** The raw timeline instance (for advanced usage) */
|
|
174
|
+
timeline: ScrollTimeline | null;
|
|
175
|
+
}
|
|
176
|
+
declare function useScrollTimeline(): UseScrollTimelineResult;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Clamps a value between a minimum and maximum.
|
|
180
|
+
* Default range is [0, 1], suitable for progress values.
|
|
181
|
+
*
|
|
182
|
+
* @param value - The value to clamp
|
|
183
|
+
* @param min - Minimum value (default: 0)
|
|
184
|
+
* @param max - Maximum value (default: 1)
|
|
185
|
+
* @returns The clamped value
|
|
186
|
+
*/
|
|
187
|
+
declare function clamp(value: number, min?: number, max?: number): number;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* SequenceResolver
|
|
191
|
+
* Handles intelligent frame resolution from multiple input sources:
|
|
192
|
+
* - Manual frame list (frames[])
|
|
193
|
+
* - Pattern generation (pattern, start, end, pad)
|
|
194
|
+
* - Remote manifest (manifest URL)
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Resolves frame sequence from props.
|
|
199
|
+
* Prioritizes: frames > pattern > manifest
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* Resolves frame sequence from props.
|
|
203
|
+
* Handles 'manual', 'pattern', and 'manifest' sources.
|
|
204
|
+
*/
|
|
205
|
+
declare function resolveSequence(source: ScrollSequenceProps['source']): Promise<ResolvedSequence>;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* ImageController
|
|
209
|
+
* Manages canvas rendering, image loading, and frame-by-frame drawing.
|
|
210
|
+
* Handles preloading and caching to minimize redraws.
|
|
211
|
+
*/
|
|
212
|
+
interface ImageControllerConfig {
|
|
213
|
+
/** HTMLCanvasElement to draw on */
|
|
214
|
+
canvas: HTMLCanvasElement;
|
|
215
|
+
/** Array of sorted frame URLs */
|
|
216
|
+
frames: string[];
|
|
217
|
+
/** Memory management strategy */
|
|
218
|
+
strategy?: 'eager' | 'lazy';
|
|
219
|
+
/** Lazy load buffer size (default 10) */
|
|
220
|
+
bufferSize?: number;
|
|
221
|
+
}
|
|
222
|
+
declare class ImageController {
|
|
223
|
+
private canvas;
|
|
224
|
+
private ctx;
|
|
225
|
+
private frames;
|
|
226
|
+
private imageCache;
|
|
227
|
+
private loadingPromises;
|
|
228
|
+
private currentFrameIndex;
|
|
229
|
+
private strategy;
|
|
230
|
+
private bufferSize;
|
|
231
|
+
/**
|
|
232
|
+
* Create a new ImageController instance.
|
|
233
|
+
*
|
|
234
|
+
* @param config - Configuration object
|
|
235
|
+
* @throws If canvas doesn't support 2D context
|
|
236
|
+
*/
|
|
237
|
+
private isDestroyed;
|
|
238
|
+
constructor(config: ImageControllerConfig);
|
|
239
|
+
private preloadAll;
|
|
240
|
+
private ensureFrameWindow;
|
|
241
|
+
preloadFrame(index: number): Promise<void>;
|
|
242
|
+
private loadImage;
|
|
243
|
+
update(progress: number): void;
|
|
244
|
+
private drawFrame;
|
|
245
|
+
setCanvasSize(width: number, height: number): void;
|
|
246
|
+
destroy(): void;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export { ImageController, type ImageControllerConfig, type ResolvedSequence, type ScrollProgress, ScrollSequence, type ScrollSequenceProps, ScrollText, ScrollTimeline, ScrollTimelineProvider, ScrollWordReveal, clamp, resolveSequence, useScrollSequence, useScrollTimeline };
|