phase 0.0.1-alpha.1 → 0.0.2
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 +917 -0
- package/dist/ease.d.ts +34 -0
- package/dist/ease.d.ts.map +1 -0
- package/dist/ease.js +56 -0
- package/dist/ease.js.map +1 -0
- package/dist/index-D3epuj2x.d.ts +249 -0
- package/dist/index-D3epuj2x.d.ts.map +1 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +702 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +1066 -0
- package/dist/react.js.map +1 -0
- package/dist/reduced-motion-CEJtegNG.js +948 -0
- package/dist/reduced-motion-CEJtegNG.js.map +1 -0
- package/package.json +78 -17
- package/index.js +0 -24
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
import { D as FrameState, T as SightReason, b as LifecycleReducedMotion, c as DegradedReason, d as LoopPhase, f as LoopReason, m as ReducedMotionBehavior, p as Quality, r as RenderPhase, s as DegradedBehavior, t as IdleOptions, v as LifecyclePhase, w as SightPhase, y as LifecycleReason } from "./index-D3epuj2x.js";
|
|
2
|
+
import { ComponentProps, JSX, ReactNode, Ref, RefObject } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/react/use-synced-ref/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Ref whose `.current` is always the latest value, updated synchronously on
|
|
7
|
+
* every render. Readable from any callback or effect without triggering re-render.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const propsRef = useSyncedRef(props);
|
|
11
|
+
* useEffect(() => {
|
|
12
|
+
* // propsRef.current is always fresh
|
|
13
|
+
* }, []);
|
|
14
|
+
*/
|
|
15
|
+
declare function useSyncedRef<T>(value: T): RefObject<T>;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/react/use-stable-callback/index.d.ts
|
|
18
|
+
/**
|
|
19
|
+
* Returns a function with **stable identity** that always calls the latest
|
|
20
|
+
* version of `callback`. Safe in deps arrays and as a prop to `memo()`'d children.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const handleClick = useStableCallback((e: MouseEvent) => {
|
|
24
|
+
* console.log(latestValue); // always fresh
|
|
25
|
+
* });
|
|
26
|
+
*/
|
|
27
|
+
declare function useStableCallback<Args extends unknown[], R>(callback: (...args: Args) => R): (...args: Args) => R;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/react/use-loop/index.d.ts
|
|
30
|
+
/**
|
|
31
|
+
* Per-frame loop callback. Receives the current frame state. Write to refs or
|
|
32
|
+
* DOM directly. Never call React `setState` here (60 calls/sec = 60
|
|
33
|
+
* re-renders/sec).
|
|
34
|
+
*/
|
|
35
|
+
type LoopTickFn = (frame: FrameState) => void;
|
|
36
|
+
interface UseLoopOptions<T extends Element = HTMLDivElement> {
|
|
37
|
+
/**
|
|
38
|
+
* Element to observe. Optional. When omitted, attach the returned `ref`.
|
|
39
|
+
* Pass your own ref to share it or attach it elsewhere.
|
|
40
|
+
*/
|
|
41
|
+
ref?: RefObject<T | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Called every frame. Write to refs or DOM directly. Never call React
|
|
44
|
+
* `setState` here (60 calls/sec = 60 re-renders/sec).
|
|
45
|
+
*/
|
|
46
|
+
onTick: LoopTickFn;
|
|
47
|
+
fps?: number;
|
|
48
|
+
enabled?: boolean;
|
|
49
|
+
reducedMotion?: ReducedMotionBehavior;
|
|
50
|
+
/** Behavior when quality degrades (window blur, frame-budget). Default `'throttle'`. */
|
|
51
|
+
degraded?: DegradedBehavior;
|
|
52
|
+
/** FPS cap when `degraded` is `'throttle'`. Default `30`. */
|
|
53
|
+
degradedFps?: number;
|
|
54
|
+
intersectionOptions?: IntersectionObserverInit;
|
|
55
|
+
}
|
|
56
|
+
interface UseLoopResult<T extends Element = HTMLDivElement> {
|
|
57
|
+
/** Attach to the element you want to animate. */
|
|
58
|
+
ref: RefObject<T | null>;
|
|
59
|
+
phase: LoopPhase;
|
|
60
|
+
phaseReason: LoopReason;
|
|
61
|
+
quality: Quality;
|
|
62
|
+
qualityReason: DegradedReason | undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Ref-based animation loop that never triggers re-renders from the frame loop.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const { ref, phase } = useLoop({
|
|
69
|
+
* onTick: (frame) => {
|
|
70
|
+
* ref.current.style.transform = `translateX(${frame.elapsed * 0.1}px)`;
|
|
71
|
+
* },
|
|
72
|
+
* });
|
|
73
|
+
* return <div ref={ref} />;
|
|
74
|
+
*/
|
|
75
|
+
declare function useLoop<T extends Element = HTMLDivElement>(options: UseLoopOptions<T>): UseLoopResult<T>;
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/react/use-lifecycle/index.d.ts
|
|
78
|
+
interface UseLifecycleOptions<T extends Element = HTMLDivElement> {
|
|
79
|
+
/**
|
|
80
|
+
* Element whose visibility gates the lifecycle. Optional. When omitted, attach
|
|
81
|
+
* the returned `ref`.
|
|
82
|
+
*/
|
|
83
|
+
ref?: RefObject<T | null>;
|
|
84
|
+
/** Whether reduced motion pauses the lifecycle. Default `'pause'`. */
|
|
85
|
+
reducedMotion?: LifecycleReducedMotion;
|
|
86
|
+
/** Manually pause regardless of visibility (e.g. a panel opened over the animation). */
|
|
87
|
+
paused?: boolean;
|
|
88
|
+
/** When `false`, the lifecycle is torn down and reports `idle`. Default `true`. */
|
|
89
|
+
enabled?: boolean;
|
|
90
|
+
intersectionOptions?: IntersectionObserverInit;
|
|
91
|
+
/**
|
|
92
|
+
* Synchronous callback fired in the observer/MQL callback, before React
|
|
93
|
+
* schedules a render. Use to post messages to a worker or update a ref
|
|
94
|
+
* without waiting for the React commit.
|
|
95
|
+
*/
|
|
96
|
+
onPhaseChange?: (phase: LifecyclePhase, reason: LifecycleReason) => void;
|
|
97
|
+
}
|
|
98
|
+
interface UseLifecycleResult<T extends Element = HTMLDivElement> {
|
|
99
|
+
/** Attach to the element whose visibility should gate your loop. */
|
|
100
|
+
ref: RefObject<T | null>;
|
|
101
|
+
phase: LifecyclePhase;
|
|
102
|
+
phaseReason: LifecycleReason;
|
|
103
|
+
/** Convenience: `phase === 'active'`. Drive your own render loop off this. */
|
|
104
|
+
isActive: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* React binding for `createLifecycle`. The activation signal for loops you own.
|
|
108
|
+
*
|
|
109
|
+
* Returns `active` / `paused` so a consumer-owned render loop (WebGL, three.js, a
|
|
110
|
+
* Web Worker) can pause when off-screen or under reduced motion. When `phase`
|
|
111
|
+
* should drive the loop for you, use `useLoop` or `useCanvas` instead.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const { ref, isActive } = useLifecycle();
|
|
115
|
+
* useEffect(() => {
|
|
116
|
+
* if (!isActive) return;
|
|
117
|
+
* const id = requestAnimationFrame(function render() {
|
|
118
|
+
* renderer.render();
|
|
119
|
+
* requestAnimationFrame(render);
|
|
120
|
+
* });
|
|
121
|
+
* return () => cancelAnimationFrame(id);
|
|
122
|
+
* }, [isActive]);
|
|
123
|
+
* return <canvas ref={ref} />;
|
|
124
|
+
*/
|
|
125
|
+
declare function useLifecycle<T extends Element = HTMLDivElement>(options?: UseLifecycleOptions<T>): UseLifecycleResult<T>;
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/react/use-device-pixel-ratio/index.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* Reactive devicePixelRatio that updates when the user moves the window
|
|
130
|
+
* between monitors with different DPR values.
|
|
131
|
+
*
|
|
132
|
+
* Returns `1` during SSR and initial hydration, then the live value.
|
|
133
|
+
*/
|
|
134
|
+
declare function useDevicePixelRatio(): number;
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/react/use-media/index.d.ts
|
|
137
|
+
/**
|
|
138
|
+
* Subscribe to a media query via the shared MQL pool.
|
|
139
|
+
*
|
|
140
|
+
* Returns `false` during SSR and initial hydration render,
|
|
141
|
+
* then the live value from the first `useEffect`.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const isNarrow = useMediaQuery('(max-width: 600px)');
|
|
145
|
+
*/
|
|
146
|
+
declare function useMediaQuery(query: string): boolean;
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/react/use-reduced-motion/index.d.ts
|
|
149
|
+
/**
|
|
150
|
+
* Reactive boolean that tracks the user's `prefers-reduced-motion` OS setting.
|
|
151
|
+
*
|
|
152
|
+
* Returns `false` during SSR and initial hydration, then the live value.
|
|
153
|
+
* Re-renders only when the preference changes.
|
|
154
|
+
*/
|
|
155
|
+
declare function usePrefersReducedMotion(): boolean;
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/react/use-sight/index.d.ts
|
|
158
|
+
type SightCallback = (phase: SightPhase, phaseReason: SightReason) => void;
|
|
159
|
+
interface UseSightOptions<T extends Element = HTMLDivElement> extends IntersectionObserverInit {
|
|
160
|
+
/**
|
|
161
|
+
* Element to observe. Optional. When omitted, attach the returned `ref`.
|
|
162
|
+
*/
|
|
163
|
+
ref?: RefObject<T | null>;
|
|
164
|
+
/** `'continuous'` keeps observing. `'once'` freezes at `'visible'` after first intersection. */
|
|
165
|
+
observe?: 'continuous' | 'once';
|
|
166
|
+
/**
|
|
167
|
+
* Called on every visibility transition. When provided, `phase` and
|
|
168
|
+
* `phaseReason` stay at initial values and no re-renders occur.
|
|
169
|
+
*/
|
|
170
|
+
onVisibilityChange?: SightCallback;
|
|
171
|
+
}
|
|
172
|
+
interface UseSightReactiveResult<T extends Element = HTMLDivElement> {
|
|
173
|
+
ref: RefObject<T | null>;
|
|
174
|
+
phase: SightPhase;
|
|
175
|
+
phaseReason: SightReason;
|
|
176
|
+
/** Visibility phase via ref. Always current, never triggers re-render. */
|
|
177
|
+
phaseRef: RefObject<SightPhase>;
|
|
178
|
+
/** Phase reason via ref. Always current, never triggers re-render. */
|
|
179
|
+
phaseReasonRef: RefObject<SightReason>;
|
|
180
|
+
}
|
|
181
|
+
interface UseSightTransientResult<T extends Element = HTMLDivElement> {
|
|
182
|
+
ref: RefObject<T | null>;
|
|
183
|
+
/** Visibility phase via ref. Always current, never triggers re-render. */
|
|
184
|
+
phaseRef: RefObject<SightPhase>;
|
|
185
|
+
/** Phase reason via ref. Always current, never triggers re-render. */
|
|
186
|
+
phaseReasonRef: RefObject<SightReason>;
|
|
187
|
+
}
|
|
188
|
+
/** @deprecated Use `UseSightReactiveResult` or `UseSightTransientResult`. */
|
|
189
|
+
type UseSightResult<T extends Element = HTMLDivElement> = UseSightReactiveResult<T>;
|
|
190
|
+
/**
|
|
191
|
+
* Intersection + document visibility as a phase.
|
|
192
|
+
*
|
|
193
|
+
* Pass `onVisibilityChange` for zero-re-render mode (animation gating,
|
|
194
|
+
* many-element observation). Without it, `phase` and `phaseReason` update
|
|
195
|
+
* via state on every transition. `phaseRef`/`phaseReasonRef` are always current.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* // Reactive
|
|
199
|
+
* const { ref, phase } = useSight();
|
|
200
|
+
*
|
|
201
|
+
* // Transient (no re-renders)
|
|
202
|
+
* const { ref, phaseRef } = useSight({
|
|
203
|
+
* onVisibilityChange: (phase) => { worker.postMessage({ visible: phase === 'visible' }); },
|
|
204
|
+
* });
|
|
205
|
+
*/
|
|
206
|
+
declare function useSight<T extends Element = HTMLDivElement>(options: UseSightOptions<T> & {
|
|
207
|
+
onVisibilityChange: SightCallback;
|
|
208
|
+
}): UseSightTransientResult<T>;
|
|
209
|
+
declare function useSight<T extends Element = HTMLDivElement>(options?: UseSightOptions<T>): UseSightReactiveResult<T>;
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/react/use-size/index.d.ts
|
|
212
|
+
type SizeCallback = (size: Size) => void;
|
|
213
|
+
interface Size {
|
|
214
|
+
width: number;
|
|
215
|
+
height: number;
|
|
216
|
+
}
|
|
217
|
+
interface UseSizeOptions<T extends Element = HTMLDivElement> {
|
|
218
|
+
/**
|
|
219
|
+
* Element to measure. Optional. When omitted, attach the returned `ref`.
|
|
220
|
+
*/
|
|
221
|
+
ref?: RefObject<T | null>;
|
|
222
|
+
/**
|
|
223
|
+
* Called on every resize. When provided, `size` is omitted from the return
|
|
224
|
+
* type and no re-renders occur, the right path for canvas and animation
|
|
225
|
+
* consumers that read dimensions imperatively.
|
|
226
|
+
*/
|
|
227
|
+
onResize?: SizeCallback;
|
|
228
|
+
}
|
|
229
|
+
interface UseSizeReactiveResult<T extends Element = HTMLDivElement> {
|
|
230
|
+
ref: RefObject<T | null>;
|
|
231
|
+
/** Element dimensions via state, or `null` until first observation. */
|
|
232
|
+
size: Size | null;
|
|
233
|
+
/** Element dimensions via ref. Always current, never triggers re-render. */
|
|
234
|
+
sizeRef: RefObject<Size | null>;
|
|
235
|
+
}
|
|
236
|
+
interface UseSizeTransientResult<T extends Element = HTMLDivElement> {
|
|
237
|
+
ref: RefObject<T | null>;
|
|
238
|
+
/** Element dimensions via ref. Always current, never triggers re-render. */
|
|
239
|
+
sizeRef: RefObject<Size | null>;
|
|
240
|
+
}
|
|
241
|
+
/** @deprecated Use `UseSizeReactiveResult` or `UseSizeTransientResult`. */
|
|
242
|
+
type UseSizeResult<T extends Element = HTMLDivElement> = UseSizeReactiveResult<T>;
|
|
243
|
+
/**
|
|
244
|
+
* Element dimensions via the shared ResizeObserver singleton.
|
|
245
|
+
*
|
|
246
|
+
* Pass `onResize` for zero-re-render mode (canvas, animation loops).
|
|
247
|
+
* Without it, `size` updates via state on every dimension change.
|
|
248
|
+
* `sizeRef` is always current in both modes.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* // Reactive (re-renders on resize)
|
|
252
|
+
* const { ref, size } = useSize();
|
|
253
|
+
*
|
|
254
|
+
* // Transient (no re-renders — read sizeRef in onTick/draw)
|
|
255
|
+
* const { ref, sizeRef } = useSize({ onResize: (s) => applySize(s) });
|
|
256
|
+
*/
|
|
257
|
+
declare function useSize<T extends Element = HTMLDivElement>(options: UseSizeOptions<T> & {
|
|
258
|
+
onResize: SizeCallback;
|
|
259
|
+
}): UseSizeTransientResult<T>;
|
|
260
|
+
declare function useSize<T extends Element = HTMLDivElement>(options?: UseSizeOptions<T>): UseSizeReactiveResult<T>;
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/react/use-container-query/index.d.ts
|
|
263
|
+
interface ContainerBreakpoint {
|
|
264
|
+
minWidth?: number;
|
|
265
|
+
maxWidth?: number;
|
|
266
|
+
minHeight?: number;
|
|
267
|
+
maxHeight?: number;
|
|
268
|
+
}
|
|
269
|
+
interface UseContainerQueryOptions<T extends Element = HTMLDivElement> {
|
|
270
|
+
/**
|
|
271
|
+
* Element to measure. Optional. When omitted, attach the returned `ref`.
|
|
272
|
+
*/
|
|
273
|
+
ref?: RefObject<T | null>;
|
|
274
|
+
}
|
|
275
|
+
interface UseContainerQueryResult<T extends Element = HTMLDivElement> {
|
|
276
|
+
/** Attach to the element you want to match against the breakpoint. */
|
|
277
|
+
ref: RefObject<T | null>;
|
|
278
|
+
/** Whether the element currently matches the breakpoint. */
|
|
279
|
+
matches: boolean;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Returns whether an element matches a size-based container breakpoint.
|
|
283
|
+
*
|
|
284
|
+
* Unlike `useSize` (which re-renders on every pixel of resize), this hook only
|
|
285
|
+
* re-renders when the match result changes, i.e. when the element crosses a
|
|
286
|
+
* breakpoint boundary. Uses the shared ResizeObserver singleton.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* const { ref, matches } = useContainerQuery({ minWidth: 600 });
|
|
290
|
+
* return <div ref={ref}>{matches ? 'wide' : 'narrow'}</div>;
|
|
291
|
+
*/
|
|
292
|
+
declare function useContainerQuery<T extends Element = HTMLDivElement>(breakpoint: ContainerBreakpoint, options?: UseContainerQueryOptions<T>): UseContainerQueryResult<T>;
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/react/use-scroll-progress/index.d.ts
|
|
295
|
+
type ScrollProgressCallback = (progress: number) => void;
|
|
296
|
+
interface UseScrollProgressOptions<T extends Element = HTMLDivElement> {
|
|
297
|
+
/**
|
|
298
|
+
* Element to observe. Optional. When omitted, attach the returned `ref`.
|
|
299
|
+
*/
|
|
300
|
+
ref?: RefObject<T | null>;
|
|
301
|
+
/** Number of evenly-spaced thresholds. Default 20 (~5% granularity). */
|
|
302
|
+
steps?: number;
|
|
303
|
+
root?: Element | null;
|
|
304
|
+
rootMargin?: string;
|
|
305
|
+
/**
|
|
306
|
+
* Called on every threshold crossing. When provided, `progress` stays `0`
|
|
307
|
+
* and no re-renders occur, the right path for scroll-driven animation
|
|
308
|
+
* consumers that read progress imperatively.
|
|
309
|
+
*/
|
|
310
|
+
onProgress?: ScrollProgressCallback;
|
|
311
|
+
}
|
|
312
|
+
interface UseScrollProgressReactiveResult<T extends Element = HTMLDivElement> {
|
|
313
|
+
ref: RefObject<T | null>;
|
|
314
|
+
/** Fraction of the element currently visible (0–1). */
|
|
315
|
+
progress: number;
|
|
316
|
+
/** Fraction visible via ref. Always current, never triggers re-render. */
|
|
317
|
+
progressRef: RefObject<number>;
|
|
318
|
+
}
|
|
319
|
+
interface UseScrollProgressTransientResult<T extends Element = HTMLDivElement> {
|
|
320
|
+
ref: RefObject<T | null>;
|
|
321
|
+
/** Fraction visible via ref. Always current, never triggers re-render. */
|
|
322
|
+
progressRef: RefObject<number>;
|
|
323
|
+
}
|
|
324
|
+
/** @deprecated Use `UseScrollProgressReactiveResult` or `UseScrollProgressTransientResult`. */
|
|
325
|
+
type UseScrollProgressResult<T extends Element = HTMLDivElement> = UseScrollProgressReactiveResult<T>;
|
|
326
|
+
/**
|
|
327
|
+
* Element visibility ratio (0–1) via the shared IntersectionObserver pool.
|
|
328
|
+
*
|
|
329
|
+
* Pass `onProgress` for zero-re-render mode (scroll-driven animation).
|
|
330
|
+
* Without it, `progress` updates via state at each threshold crossing.
|
|
331
|
+
* `progressRef` is always current in both modes.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* // Reactive (re-renders at threshold crossings)
|
|
335
|
+
* const { ref, progress } = useScrollProgress();
|
|
336
|
+
*
|
|
337
|
+
* // Transient (no re-renders — read progressRef in onTick)
|
|
338
|
+
* const { ref, progressRef } = useScrollProgress({
|
|
339
|
+
* onProgress: (p) => { el.style.opacity = String(p); },
|
|
340
|
+
* });
|
|
341
|
+
*/
|
|
342
|
+
declare function useScrollProgress<T extends Element = HTMLDivElement>(options: UseScrollProgressOptions<T> & {
|
|
343
|
+
onProgress: ScrollProgressCallback;
|
|
344
|
+
}): UseScrollProgressTransientResult<T>;
|
|
345
|
+
declare function useScrollProgress<T extends Element = HTMLDivElement>(options?: UseScrollProgressOptions<T>): UseScrollProgressReactiveResult<T>;
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/react/use-render-state/index.d.ts
|
|
348
|
+
/**
|
|
349
|
+
* Track whether the browser is rendering an element or skipping it under
|
|
350
|
+
* `content-visibility` (e.g. a `Defer` subtree). Returns `'rendered'` until the
|
|
351
|
+
* browser reports otherwise.
|
|
352
|
+
*
|
|
353
|
+
* Use it to pause raw, non-phase work (a hand-written rAF loop, `setInterval`)
|
|
354
|
+
* when the subtree stops painting. phase loops self-pause off-screen already.
|
|
355
|
+
* Has no layout effect. Safe for CLS.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* const ref = useRef<HTMLDivElement>(null);
|
|
359
|
+
* const phase = useRenderState(ref);
|
|
360
|
+
* useEffect(() => {
|
|
361
|
+
* if (phase === 'skipped') clock.pause();
|
|
362
|
+
* else clock.resume();
|
|
363
|
+
* }, [phase]);
|
|
364
|
+
* return <Defer ref={ref}><Heavy /></Defer>;
|
|
365
|
+
*/
|
|
366
|
+
declare function useRenderState<T extends Element = HTMLDivElement>(ref: RefObject<T | null>): RenderPhase;
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/react/use-idle/index.d.ts
|
|
369
|
+
/**
|
|
370
|
+
* Returns `false`, then `true` once the browser is idle after mount. Use it to
|
|
371
|
+
* defer non-critical work or mounting until the main thread is free.
|
|
372
|
+
*
|
|
373
|
+
* SSR-safe: returns `false` on the server and during the first client render.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* const idle = useIdle();
|
|
377
|
+
* return idle ? <Analytics /> : null;
|
|
378
|
+
*/
|
|
379
|
+
declare function useIdle(options?: IdleOptions): boolean;
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/react/use-when-idle/index.d.ts
|
|
382
|
+
/**
|
|
383
|
+
* Run a callback once, when the browser is idle after mount. The effect-shaped
|
|
384
|
+
* counterpart to `useIdle`. Use it for side effects (prefetching a chunk,
|
|
385
|
+
* warming a cache, `import()`) rather than rendering.
|
|
386
|
+
*
|
|
387
|
+
* Cancels automatically on unmount, and always calls the latest `callback`
|
|
388
|
+
* without re-subscribing. SSR-safe: nothing runs on the server.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* // Prefetch a heavy panel during idle time so it opens instantly later.
|
|
392
|
+
* useWhenIdle(() => void import('./chat-panel'));
|
|
393
|
+
*/
|
|
394
|
+
declare function useWhenIdle(callback: () => void, options?: IdleOptions): void;
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region src/react/use-canvas/index.d.ts
|
|
397
|
+
interface Size$1 {
|
|
398
|
+
width: number;
|
|
399
|
+
height: number;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Per-frame canvas draw callback. Receives the 2D context, frame state, and
|
|
403
|
+
* current element size. Draw directly to the canvas. Never call React
|
|
404
|
+
* `setState` here.
|
|
405
|
+
*/
|
|
406
|
+
type CanvasDrawFn = (ctx: CanvasRenderingContext2D, frame: FrameState, size: Size$1) => void;
|
|
407
|
+
interface UseCanvasOptions {
|
|
408
|
+
containerRef: RefObject<Element | null>;
|
|
409
|
+
canvasRef: RefObject<HTMLCanvasElement | null>;
|
|
410
|
+
/**
|
|
411
|
+
* Called every frame with the 2D context, frame state, and current element size.
|
|
412
|
+
* Draw directly to the canvas. Never call React `setState` here.
|
|
413
|
+
*/
|
|
414
|
+
draw: CanvasDrawFn;
|
|
415
|
+
fps?: number;
|
|
416
|
+
enabled?: boolean;
|
|
417
|
+
reducedMotion?: ReducedMotionBehavior;
|
|
418
|
+
/** Behavior when quality degrades. Default `'throttle'`. For heavy GPU work, `'pause'` is often the right call. */
|
|
419
|
+
degraded?: DegradedBehavior;
|
|
420
|
+
/** FPS cap when `degraded` is `'throttle'`. Default `30`. */
|
|
421
|
+
degradedFps?: number;
|
|
422
|
+
}
|
|
423
|
+
interface UseCanvasResult {
|
|
424
|
+
restart: () => void;
|
|
425
|
+
phase: LoopPhase;
|
|
426
|
+
phaseReason: LoopReason;
|
|
427
|
+
quality: Quality;
|
|
428
|
+
qualityReason: DegradedReason | undefined;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Canvas-specific animation with DPR-aware sizing, ResizeObserver coalescing,
|
|
432
|
+
* context management, and GPU context loss recovery.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* useCanvas({
|
|
436
|
+
* containerRef,
|
|
437
|
+
* canvasRef,
|
|
438
|
+
* draw: (ctx, frame, size) => {
|
|
439
|
+
* ctx.clearRect(0, 0, size.width, size.height);
|
|
440
|
+
* // render...
|
|
441
|
+
* },
|
|
442
|
+
* });
|
|
443
|
+
*/
|
|
444
|
+
declare function useCanvas(options: UseCanvasOptions): UseCanvasResult;
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region src/react/use-tween/index.d.ts
|
|
447
|
+
interface UseTweenOptions {
|
|
448
|
+
target: number;
|
|
449
|
+
duration?: number;
|
|
450
|
+
delay?: number;
|
|
451
|
+
easing?: (progress: number) => number;
|
|
452
|
+
enabled?: boolean;
|
|
453
|
+
/** Default: `'complete'`. Tweens jump to target under reduced motion. */
|
|
454
|
+
reducedMotion?: ReducedMotionBehavior;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Animate a value from its current position to `target` over `duration`.
|
|
458
|
+
*
|
|
459
|
+
* Uses `useState` per frame. Appropriate for cheap renders (counters, opacity,
|
|
460
|
+
* progress bars). For batch animations, use `useLoop` with ref-based DOM writes.
|
|
461
|
+
*
|
|
462
|
+
* @remarks
|
|
463
|
+
* Unlike `createTicker`/`createLoop`, `useTween` drives its own rAF rather than
|
|
464
|
+
* the shared frame-locked clock. It's a finite, self-completing tween whose value
|
|
465
|
+
* must land in React state, so it doesn't need cross-loop visual sync, strong
|
|
466
|
+
* pause, or delta clamping. Routing it through the shared clock would add bundle
|
|
467
|
+
* weight for no benefit.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* const value = useTween({ target: 100, duration: 500 });
|
|
471
|
+
*/
|
|
472
|
+
declare function useTween(options: UseTweenOptions): number;
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/react/use-presence/index.d.ts
|
|
475
|
+
type PresencePhase = 'idle' | 'entered' | 'exiting' | 'exited';
|
|
476
|
+
type PresenceReason = 'initial' | 'show' | 'hide' | 'animation-end' | 'interrupted';
|
|
477
|
+
type PresenceMode = 'mount' | 'reveal';
|
|
478
|
+
interface UsePresenceOptions {
|
|
479
|
+
show: boolean;
|
|
480
|
+
mode?: PresenceMode;
|
|
481
|
+
/** Controls first-mount behavior. `'animate'` (default): enter animation plays. `'instant'`: appears immediately. */
|
|
482
|
+
enter?: 'animate' | 'instant';
|
|
483
|
+
/** Safety-net timeout in ms if transitionend/animationend doesn't fire during exit. Default 5000. */
|
|
484
|
+
exitDuration?: number;
|
|
485
|
+
/** Whether to respect the user's reduced motion preference. Default `'respect'`. */
|
|
486
|
+
reducedMotion?: 'respect' | 'ignore';
|
|
487
|
+
}
|
|
488
|
+
interface UsePresenceResult {
|
|
489
|
+
phase: PresencePhase;
|
|
490
|
+
phaseReason: PresenceReason;
|
|
491
|
+
/** Convenience: `phase !== 'idle' && phase !== 'exited'` for conditional rendering in mount mode. */
|
|
492
|
+
mounted: boolean;
|
|
493
|
+
ref: RefObject<Element | null>;
|
|
494
|
+
/** Whether the component should stamp `data-enter="animate"`. Accounts for enter option + reduced motion. */
|
|
495
|
+
enter: 'animate' | 'instant';
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Composable presence primitive for mount/unmount lifecycle with CSS transitions.
|
|
499
|
+
*
|
|
500
|
+
* Enter animations use CSS `@starting-style`, gated by `data-enter="animate"`.
|
|
501
|
+
* Exit animations are JS-coordinated: waits for `transitionend`/`animationend`
|
|
502
|
+
* before unmounting.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* const { phase, ref, mounted, enter } = usePresence({ show: isOpen });
|
|
506
|
+
* if (!mounted) return null;
|
|
507
|
+
* return (
|
|
508
|
+
* <div ref={ref} data-phase={phase} data-enter={enter === 'animate' ? 'animate' : undefined}
|
|
509
|
+
* className="transition-opacity data-[enter=animate]:starting:opacity-0 data-[phase=exiting]:opacity-0" />
|
|
510
|
+
* );
|
|
511
|
+
*/
|
|
512
|
+
declare function usePresence(options: UsePresenceOptions): UsePresenceResult;
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/react/presence/index.d.ts
|
|
515
|
+
interface PresenceProps extends ComponentProps<'div'> {
|
|
516
|
+
show: boolean;
|
|
517
|
+
mode?: PresenceMode;
|
|
518
|
+
/** Controls first-mount behavior. `'animate'` (default): enter animation plays. `'instant'`: appears immediately. */
|
|
519
|
+
enter?: 'animate' | 'instant';
|
|
520
|
+
/** Safety-net timeout in ms if transitionend/animationend doesn't fire during exit. Default 5000. */
|
|
521
|
+
exitDuration?: number;
|
|
522
|
+
/** Whether to respect the user's reduced motion preference. Default `'respect'`. */
|
|
523
|
+
reducedMotion?: 'respect' | 'ignore';
|
|
524
|
+
ref?: Ref<HTMLDivElement>;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Renders a `div` that manages its own mounting lifecycle.
|
|
528
|
+
*
|
|
529
|
+
* Stamps `data-phase` for exit animations and `data-enter="animate"` to gate
|
|
530
|
+
* CSS `@starting-style` enter animations. Reduced motion is handled automatically.
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* <Presence
|
|
534
|
+
* show={isOpen}
|
|
535
|
+
* className="transition-opacity data-[enter=animate]:starting:opacity-0 data-[phase=exiting]:opacity-0"
|
|
536
|
+
* >
|
|
537
|
+
* Modal content
|
|
538
|
+
* </Presence>
|
|
539
|
+
*/
|
|
540
|
+
declare function Presence({
|
|
541
|
+
show,
|
|
542
|
+
mode,
|
|
543
|
+
enter: enterOption,
|
|
544
|
+
exitDuration,
|
|
545
|
+
reducedMotion,
|
|
546
|
+
ref: forwardedRef,
|
|
547
|
+
children,
|
|
548
|
+
...divProps
|
|
549
|
+
}: PresenceProps): JSX.Element | null;
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/react/when-visible/index.d.ts
|
|
552
|
+
interface WhenVisibleProps extends ComponentProps<'div'> {
|
|
553
|
+
/** IntersectionObserver rootMargin. Default `'200px'` (generous headroom for preloading). */
|
|
554
|
+
rootMargin?: string;
|
|
555
|
+
/** IntersectionObserver threshold. */
|
|
556
|
+
threshold?: number | number[];
|
|
557
|
+
/** IntersectionObserver root element. */
|
|
558
|
+
root?: Element | null;
|
|
559
|
+
/** Content shown while awaiting intersection. Sentinel div is always rendered for IO. */
|
|
560
|
+
fallback?: ReactNode;
|
|
561
|
+
/** Forwarded to the rendered div in both states (the sentinel before visible, the entered div after). Populated at mount. */
|
|
562
|
+
ref?: Ref<HTMLDivElement>;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Mounts children when the element enters the viewport. One-shot (once
|
|
566
|
+
* triggered, stays mounted).
|
|
567
|
+
*
|
|
568
|
+
* Enter animation uses CSS `@starting-style`, gated by `data-enter="animate"`.
|
|
569
|
+
* Reduced motion is automatic: the attribute is not stamped when the user
|
|
570
|
+
* prefers reduced motion.
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
* <WhenVisible rootMargin="200px" className="transition-opacity data-[enter=animate]:starting:opacity-0">
|
|
574
|
+
* <HeavyChart />
|
|
575
|
+
* </WhenVisible>
|
|
576
|
+
*/
|
|
577
|
+
declare function WhenVisible({
|
|
578
|
+
rootMargin,
|
|
579
|
+
threshold,
|
|
580
|
+
root,
|
|
581
|
+
fallback,
|
|
582
|
+
children,
|
|
583
|
+
ref: forwardedRef,
|
|
584
|
+
...divProps
|
|
585
|
+
}: WhenVisibleProps): JSX.Element;
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region src/react/when-idle/index.d.ts
|
|
588
|
+
interface WhenIdleProps extends ComponentProps<'div'> {
|
|
589
|
+
/** Max ms to wait before mounting even if no idle period occurs. */
|
|
590
|
+
timeout?: number;
|
|
591
|
+
/** Content shown until the browser is idle. */
|
|
592
|
+
fallback?: ReactNode;
|
|
593
|
+
ref?: Ref<HTMLDivElement>;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Mounts children once the browser is idle after first paint. One-shot (once
|
|
597
|
+
* mounted, stays mounted). Use it to defer non-critical UI off the critical path.
|
|
598
|
+
*
|
|
599
|
+
* Children are not server-rendered (idle never fires during SSR), so reserve
|
|
600
|
+
* this for non-critical content. For viewport-gated mounting use `WhenVisible`;
|
|
601
|
+
* to keep content in the DOM but skip painting use `Defer`.
|
|
602
|
+
*
|
|
603
|
+
* Enter animation uses CSS `@starting-style`, gated by `data-enter="animate"`.
|
|
604
|
+
* Reduced motion is automatic: the attribute is not stamped when the user
|
|
605
|
+
* prefers reduced motion.
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* <WhenIdle fallback={<Skeleton />}>
|
|
609
|
+
* <SecondaryPanel />
|
|
610
|
+
* </WhenIdle>
|
|
611
|
+
*/
|
|
612
|
+
declare function WhenIdle({
|
|
613
|
+
timeout,
|
|
614
|
+
fallback,
|
|
615
|
+
children,
|
|
616
|
+
ref: forwardedRef,
|
|
617
|
+
...divProps
|
|
618
|
+
}: WhenIdleProps): JSX.Element;
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region src/react/defer/index.d.ts
|
|
621
|
+
interface DeferProps extends Omit<ComponentProps<'div'>, 'style'> {
|
|
622
|
+
/**
|
|
623
|
+
* Approximate size reserved before first paint (any CSS length, e.g. `'800px'`).
|
|
624
|
+
* After the first render the browser remembers the real size. Default `'1000px'`.
|
|
625
|
+
*/
|
|
626
|
+
estimatedHeight?: string;
|
|
627
|
+
ref?: Ref<HTMLDivElement>;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Skip the browser's rendering work (style, layout, paint) for off-screen
|
|
631
|
+
* content via `content-visibility: auto`. Pure CSS, no JS, no observer.
|
|
632
|
+
*
|
|
633
|
+
* Children stay in the DOM and are server-rendered (SEO- and CLS-safe).
|
|
634
|
+
* `contain-intrinsic-size: auto <estimatedHeight>` reserves space so the
|
|
635
|
+
* scrollbar does not jump. Defers rendering only, not hydration or mounting.
|
|
636
|
+
*
|
|
637
|
+
* The render-skip styles are encapsulated and cannot be overridden. There is
|
|
638
|
+
* no `style` prop. Style the wrapper with `className`; this keeps the
|
|
639
|
+
* no-layout-shift guarantee intact.
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* <Defer estimatedHeight="600px" className="my-section">
|
|
643
|
+
* <ArticleSection />
|
|
644
|
+
* </Defer>
|
|
645
|
+
*
|
|
646
|
+
* @remarks
|
|
647
|
+
* Animations inside a `Defer` keep running while paint is skipped. phase loops
|
|
648
|
+
* self-pause off-screen on their own; for raw rAF/interval work, gate it with
|
|
649
|
+
* `useRenderState`.
|
|
650
|
+
*/
|
|
651
|
+
declare function Defer({
|
|
652
|
+
estimatedHeight,
|
|
653
|
+
children,
|
|
654
|
+
ref,
|
|
655
|
+
...divProps
|
|
656
|
+
}: DeferProps): JSX.Element;
|
|
657
|
+
//#endregion
|
|
658
|
+
//#region src/react/swap/index.d.ts
|
|
659
|
+
interface SwapProps extends ComponentProps<'div'> {
|
|
660
|
+
active: string;
|
|
661
|
+
exitDuration?: number;
|
|
662
|
+
children: ReactNode;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Coordinated exit-then-enter transitions for N states.
|
|
666
|
+
* Only one state is entering or exiting at a time (no overlap).
|
|
667
|
+
*
|
|
668
|
+
* The current state fully exits before the new state enters. Rapid changes
|
|
669
|
+
* (A->B->C during A's exit) skip intermediate states and jump to the latest.
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* <Swap active={success ? 'success' : 'form'}>
|
|
673
|
+
* <Swap.State id="form" className="transition-all data-[phase=exiting]:opacity-0">
|
|
674
|
+
* <Form />
|
|
675
|
+
* </Swap.State>
|
|
676
|
+
* <Swap.State id="success" className="transition-all data-[enter=animate]:starting:opacity-0">
|
|
677
|
+
* <SuccessMessage />
|
|
678
|
+
* </Swap.State>
|
|
679
|
+
* </Swap>
|
|
680
|
+
*/
|
|
681
|
+
declare function SwapRoot({
|
|
682
|
+
active,
|
|
683
|
+
exitDuration,
|
|
684
|
+
children,
|
|
685
|
+
...divProps
|
|
686
|
+
}: SwapProps): JSX.Element;
|
|
687
|
+
interface SwapStateProps extends ComponentProps<'div'> {
|
|
688
|
+
id: string;
|
|
689
|
+
ref?: Ref<HTMLDivElement>;
|
|
690
|
+
}
|
|
691
|
+
declare function SwapState({
|
|
692
|
+
id,
|
|
693
|
+
ref: forwardedRef,
|
|
694
|
+
children,
|
|
695
|
+
...divProps
|
|
696
|
+
}: SwapStateProps): JSX.Element | null;
|
|
697
|
+
declare const Swap: typeof SwapRoot & {
|
|
698
|
+
State: typeof SwapState;
|
|
699
|
+
};
|
|
700
|
+
//#endregion
|
|
701
|
+
export { type CanvasDrawFn, type ContainerBreakpoint, Defer, type DeferProps, type IdleOptions, type LifecyclePhase, type LifecycleReason, type LifecycleReducedMotion, type LoopTickFn, Presence, type PresenceMode, type PresencePhase, type PresenceProps, type PresenceReason, type RenderPhase, type ScrollProgressCallback, type SightCallback, type Size, type SizeCallback, Swap, type SwapProps, type SwapStateProps, type UseCanvasOptions, type UseCanvasResult, type UseContainerQueryOptions, type UseContainerQueryResult, type UseLifecycleOptions, type UseLifecycleResult, type UseLoopOptions, type UseLoopResult, type UsePresenceOptions, type UsePresenceResult, type UseScrollProgressOptions, type UseScrollProgressReactiveResult, type UseScrollProgressResult, type UseScrollProgressTransientResult, type UseSightOptions, type UseSightReactiveResult, type UseSightResult, type UseSightTransientResult, type UseSizeOptions, type UseSizeReactiveResult, type UseSizeResult, type UseSizeTransientResult, type UseTweenOptions, WhenIdle, type WhenIdleProps, WhenVisible, type WhenVisibleProps, useCanvas, useContainerQuery, useDevicePixelRatio, useIdle, useLifecycle, useLoop, useMediaQuery, usePrefersReducedMotion, usePresence, useRenderState, useScrollProgress, useSight, useSize, useStableCallback, useSyncedRef, useTween, useWhenIdle };
|
|
702
|
+
//# sourceMappingURL=react.d.ts.map
|