phase 0.0.6 → 0.0.7
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 +86 -9
- package/dist/{index-tRHsbTE2.d.ts → index-BRyL_Inx.d.ts} +56 -2
- package/dist/index-BRyL_Inx.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/react.d.ts +41 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +101 -52
- package/dist/react.js.map +1 -1
- package/dist/{pointer-D5F7_Jjs.js → scroll-DZvWyPQE.js} +209 -2
- package/dist/scroll-DZvWyPQE.js.map +1 -0
- package/package.json +1 -1
- package/dist/index-tRHsbTE2.d.ts.map +0 -1
- package/dist/pointer-D5F7_Jjs.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { clamp01, easeOutCubic } from "./ease.js";
|
|
3
|
-
import {
|
|
3
|
+
import { a as REDUCED_MOTION_QUERY, c as readDpr, d as createScrollProgress, f as createLoop, g as createSight, h as subscribeMediaQuery, i as createMutation, l as subscribeDpr, m as readMediaQuery, n as observeResize, o as prefersReducedMotion, p as createLifecycle, r as createPointer, s as whenIdle, t as createScroll, u as createRenderState, x as missingContextError, y as invalidDurationError } from "./scroll-DZvWyPQE.js";
|
|
4
4
|
import { createContext, createElement, use, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/react/use-synced-ref/index.ts
|
|
@@ -53,7 +53,7 @@ function degradedConfig(degraded, degradedFps) {
|
|
|
53
53
|
}
|
|
54
54
|
//#endregion
|
|
55
55
|
//#region src/react/use-loop/index.ts
|
|
56
|
-
const INITIAL_STATE$
|
|
56
|
+
const INITIAL_STATE$6 = {
|
|
57
57
|
phase: "idle",
|
|
58
58
|
phaseReason: "initial",
|
|
59
59
|
quality: "full",
|
|
@@ -75,12 +75,12 @@ function useLoop(options) {
|
|
|
75
75
|
const onTickRef = useSyncedRef(options.onTick);
|
|
76
76
|
const internalRef = useRef(null);
|
|
77
77
|
const ref = options.ref ?? internalRef;
|
|
78
|
-
const [state, setState] = useState(INITIAL_STATE$
|
|
78
|
+
const [state, setState] = useState(INITIAL_STATE$6);
|
|
79
79
|
const loopRef = useRef(null);
|
|
80
80
|
useEffect(() => {
|
|
81
81
|
const element = ref.current;
|
|
82
82
|
if (!element || !enabled) {
|
|
83
|
-
setState(INITIAL_STATE$
|
|
83
|
+
setState(INITIAL_STATE$6);
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
const loop = createLoop({
|
|
@@ -119,7 +119,7 @@ function useLoop(options) {
|
|
|
119
119
|
}
|
|
120
120
|
//#endregion
|
|
121
121
|
//#region src/react/use-lifecycle/index.ts
|
|
122
|
-
const INITIAL_STATE$
|
|
122
|
+
const INITIAL_STATE$5 = {
|
|
123
123
|
phase: "idle",
|
|
124
124
|
phaseReason: "initial"
|
|
125
125
|
};
|
|
@@ -148,12 +148,12 @@ function useLifecycle(options) {
|
|
|
148
148
|
const onPhaseChangeRef = useSyncedRef(options?.onPhaseChange);
|
|
149
149
|
const internalRef = useRef(null);
|
|
150
150
|
const ref = options?.ref ?? internalRef;
|
|
151
|
-
const [state, setState] = useState(INITIAL_STATE$
|
|
151
|
+
const [state, setState] = useState(INITIAL_STATE$5);
|
|
152
152
|
const lifecycleRef = useRef(null);
|
|
153
153
|
useEffect(() => {
|
|
154
154
|
const element = ref.current;
|
|
155
155
|
if (!element || !enabled) {
|
|
156
|
-
setState(INITIAL_STATE$
|
|
156
|
+
setState(INITIAL_STATE$5);
|
|
157
157
|
return;
|
|
158
158
|
}
|
|
159
159
|
const lifecycle = createLifecycle({
|
|
@@ -235,12 +235,12 @@ function usePrefersReducedMotion() {
|
|
|
235
235
|
}
|
|
236
236
|
//#endregion
|
|
237
237
|
//#region src/react/use-sight/index.ts
|
|
238
|
-
const INITIAL_STATE$
|
|
238
|
+
const INITIAL_STATE$4 = {
|
|
239
239
|
phase: "unknown",
|
|
240
240
|
phaseReason: "initial"
|
|
241
241
|
};
|
|
242
242
|
function useSight(options) {
|
|
243
|
-
const [state, setState] = useState(INITIAL_STATE$
|
|
243
|
+
const [state, setState] = useState(INITIAL_STATE$4);
|
|
244
244
|
const observe = options?.observe ?? "continuous";
|
|
245
245
|
const phaseRef = useRef("unknown");
|
|
246
246
|
const phaseReasonRef = useRef("initial");
|
|
@@ -283,40 +283,6 @@ function useSight(options) {
|
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
285
|
//#endregion
|
|
286
|
-
//#region src/core/_internal/pool/ro-pool.ts
|
|
287
|
-
let observer = null;
|
|
288
|
-
const callbacks = /* @__PURE__ */ new Map();
|
|
289
|
-
/**
|
|
290
|
-
* Observe an element via a singleton ResizeObserver.
|
|
291
|
-
* One RO instance for the entire page. Per-element `box` options are
|
|
292
|
-
* forwarded to `ResizeObserver.observe()`.
|
|
293
|
-
*
|
|
294
|
-
* @returns Cleanup function that unobserves the element.
|
|
295
|
-
*/
|
|
296
|
-
function observeResize(element, callback, box) {
|
|
297
|
-
callbacks.set(element, callback);
|
|
298
|
-
getObserver().observe(element, box ? { box } : void 0);
|
|
299
|
-
let disposed = false;
|
|
300
|
-
return () => {
|
|
301
|
-
if (disposed) return;
|
|
302
|
-
disposed = true;
|
|
303
|
-
if (callbacks.get(element) === callback) {
|
|
304
|
-
callbacks.delete(element);
|
|
305
|
-
observer?.unobserve(element);
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
/** Lazy-created singleton. RO takes zero constructor options, so one instance can observe everything. */
|
|
310
|
-
function getObserver() {
|
|
311
|
-
if (!observer) observer = new ResizeObserver((entries) => {
|
|
312
|
-
for (const entry of entries) {
|
|
313
|
-
const cb = callbacks.get(entry.target);
|
|
314
|
-
if (cb) cb(entry);
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
return observer;
|
|
318
|
-
}
|
|
319
|
-
//#endregion
|
|
320
286
|
//#region src/react/use-size/index.ts
|
|
321
287
|
function useSize(options) {
|
|
322
288
|
const [size, setSize] = useState(null);
|
|
@@ -512,7 +478,7 @@ function useWhenIdle(callback, options) {
|
|
|
512
478
|
}
|
|
513
479
|
//#endregion
|
|
514
480
|
//#region src/react/use-canvas/index.ts
|
|
515
|
-
const INITIAL_STATE$
|
|
481
|
+
const INITIAL_STATE$3 = {
|
|
516
482
|
phase: "idle",
|
|
517
483
|
phaseReason: "initial",
|
|
518
484
|
quality: "full",
|
|
@@ -535,7 +501,7 @@ const INITIAL_STATE$2 = {
|
|
|
535
501
|
function useCanvas(options) {
|
|
536
502
|
const { containerRef, canvasRef, fps, enabled = true, reducedMotion, degraded, degradedFps } = options;
|
|
537
503
|
const drawRef = useSyncedRef(options.draw);
|
|
538
|
-
const [state, setState] = useState(INITIAL_STATE$
|
|
504
|
+
const [state, setState] = useState(INITIAL_STATE$3);
|
|
539
505
|
const [restartNonce, setRestartNonce] = useState(0);
|
|
540
506
|
const ctxRef = useRef(null);
|
|
541
507
|
const sizeRef = useRef({
|
|
@@ -647,7 +613,7 @@ function useCanvas(options) {
|
|
|
647
613
|
}
|
|
648
614
|
//#endregion
|
|
649
615
|
//#region src/react/use-mutation/index.ts
|
|
650
|
-
const INITIAL_STATE$
|
|
616
|
+
const INITIAL_STATE$2 = {
|
|
651
617
|
phase: "paused",
|
|
652
618
|
phaseReason: "initial"
|
|
653
619
|
};
|
|
@@ -662,7 +628,7 @@ const INITIAL_STATE$1 = {
|
|
|
662
628
|
* reactions, use the core `createMutation` primitive.
|
|
663
629
|
*/
|
|
664
630
|
function useMutation(options) {
|
|
665
|
-
const [state, setState] = useState(INITIAL_STATE$
|
|
631
|
+
const [state, setState] = useState(INITIAL_STATE$2);
|
|
666
632
|
const { mutation: mutationInit, visibility = "pause", enabled = true, intersectionOptions } = options;
|
|
667
633
|
const phaseRef = useRef("paused");
|
|
668
634
|
const phaseReasonRef = useRef("initial");
|
|
@@ -672,7 +638,7 @@ function useMutation(options) {
|
|
|
672
638
|
useEffect(() => {
|
|
673
639
|
const element = ref.current;
|
|
674
640
|
if (!element || !enabled) {
|
|
675
|
-
setState(INITIAL_STATE$
|
|
641
|
+
setState(INITIAL_STATE$2);
|
|
676
642
|
phaseRef.current = "paused";
|
|
677
643
|
phaseReasonRef.current = "initial";
|
|
678
644
|
return;
|
|
@@ -703,7 +669,7 @@ function useMutation(options) {
|
|
|
703
669
|
}
|
|
704
670
|
//#endregion
|
|
705
671
|
//#region src/react/use-pointer/index.ts
|
|
706
|
-
const INITIAL_STATE = {
|
|
672
|
+
const INITIAL_STATE$1 = {
|
|
707
673
|
phase: "idle",
|
|
708
674
|
phaseReason: "initial"
|
|
709
675
|
};
|
|
@@ -719,7 +685,7 @@ const INITIAL_STATE = {
|
|
|
719
685
|
* `createPointer` primitive.
|
|
720
686
|
*/
|
|
721
687
|
function usePointer(options) {
|
|
722
|
-
const [state, setState] = useState(INITIAL_STATE);
|
|
688
|
+
const [state, setState] = useState(INITIAL_STATE$1);
|
|
723
689
|
const { visibility = "pause", enabled = true, intersectionOptions } = options;
|
|
724
690
|
const phaseRef = useRef("idle");
|
|
725
691
|
const phaseReasonRef = useRef("initial");
|
|
@@ -734,7 +700,7 @@ function usePointer(options) {
|
|
|
734
700
|
useEffect(() => {
|
|
735
701
|
const element = ref.current;
|
|
736
702
|
if (!element || !enabled) {
|
|
737
|
-
setState(INITIAL_STATE);
|
|
703
|
+
setState(INITIAL_STATE$1);
|
|
738
704
|
phaseRef.current = "idle";
|
|
739
705
|
phaseReasonRef.current = "initial";
|
|
740
706
|
stateRef.current = {
|
|
@@ -772,6 +738,89 @@ function usePointer(options) {
|
|
|
772
738
|
};
|
|
773
739
|
}
|
|
774
740
|
//#endregion
|
|
741
|
+
//#region src/react/use-scroll/index.ts
|
|
742
|
+
const INITIAL_STATE = {
|
|
743
|
+
phase: "paused",
|
|
744
|
+
phaseReason: "initial"
|
|
745
|
+
};
|
|
746
|
+
function initialState() {
|
|
747
|
+
return {
|
|
748
|
+
x: 0,
|
|
749
|
+
y: 0,
|
|
750
|
+
maxX: 0,
|
|
751
|
+
maxY: 0,
|
|
752
|
+
progressX: 0,
|
|
753
|
+
progressY: 0,
|
|
754
|
+
visibleX: 1,
|
|
755
|
+
visibleY: 1
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Lifecycle-aware scroll tracker. Scroll position is delivered imperatively via
|
|
760
|
+
* `onScroll` (never state) and mirrored in `stateRef` for on-demand reads; only
|
|
761
|
+
* the phase (tracking/paused) is reactive, since it flips rarely. This mirrors
|
|
762
|
+
* `usePointer`. Auto-pauses off-screen and tears down on unmount.
|
|
763
|
+
*
|
|
764
|
+
* Reads `scrollLeft`/`scrollTop` once per rAF frame; the reflow-heavy geometry
|
|
765
|
+
* (`scrollWidth`/`clientWidth`) is read only on resize or via `measure()`, never
|
|
766
|
+
* on the scroll path. Call `measure()` after mutating scrollable content.
|
|
767
|
+
*/
|
|
768
|
+
function useScroll(options) {
|
|
769
|
+
const [state, setState] = useState(INITIAL_STATE);
|
|
770
|
+
const { visibility = "pause", enabled = true, intersectionOptions } = options;
|
|
771
|
+
const phaseRef = useRef("paused");
|
|
772
|
+
const phaseReasonRef = useRef("initial");
|
|
773
|
+
const stateRef = useRef(initialState());
|
|
774
|
+
const onScrollRef = useSyncedRef(options.onScroll);
|
|
775
|
+
const instanceRef = useRef(null);
|
|
776
|
+
const internalRef = useRef(null);
|
|
777
|
+
const ref = options.ref ?? internalRef;
|
|
778
|
+
const measure = useCallback(() => {
|
|
779
|
+
instanceRef.current?.measure();
|
|
780
|
+
}, []);
|
|
781
|
+
useEffect(() => {
|
|
782
|
+
const element = ref.current;
|
|
783
|
+
if (!element || !enabled) {
|
|
784
|
+
instanceRef.current = null;
|
|
785
|
+
setState(INITIAL_STATE);
|
|
786
|
+
phaseRef.current = "paused";
|
|
787
|
+
phaseReasonRef.current = "initial";
|
|
788
|
+
stateRef.current = initialState();
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
const instance = createScroll({
|
|
792
|
+
element,
|
|
793
|
+
onScroll: (scrollState) => {
|
|
794
|
+
stateRef.current = scrollState;
|
|
795
|
+
onScrollRef.current(scrollState);
|
|
796
|
+
},
|
|
797
|
+
onPhaseChange: (phase, reason) => {
|
|
798
|
+
phaseRef.current = phase;
|
|
799
|
+
phaseReasonRef.current = reason;
|
|
800
|
+
setState({
|
|
801
|
+
phase,
|
|
802
|
+
phaseReason: reason
|
|
803
|
+
});
|
|
804
|
+
},
|
|
805
|
+
visibility,
|
|
806
|
+
intersectionOptions
|
|
807
|
+
});
|
|
808
|
+
instanceRef.current = instance;
|
|
809
|
+
return () => {
|
|
810
|
+
instance.stop();
|
|
811
|
+
instanceRef.current = null;
|
|
812
|
+
};
|
|
813
|
+
}, [enabled, visibility]);
|
|
814
|
+
return {
|
|
815
|
+
ref,
|
|
816
|
+
...state,
|
|
817
|
+
phaseRef,
|
|
818
|
+
phaseReasonRef,
|
|
819
|
+
stateRef,
|
|
820
|
+
measure
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
//#endregion
|
|
775
824
|
//#region src/react/use-tween/index.ts
|
|
776
825
|
/**
|
|
777
826
|
* Animate a value from its current position to `target` over `duration`.
|
|
@@ -1171,6 +1220,6 @@ function SwapState({ id, ref: forwardedRef, children, ...divProps }) {
|
|
|
1171
1220
|
}
|
|
1172
1221
|
const Swap = Object.assign(SwapRoot, { State: SwapState });
|
|
1173
1222
|
//#endregion
|
|
1174
|
-
export { Defer, Presence, Swap, WhenIdle, WhenVisible, useCanvas, useContainerQuery, useDevicePixelRatio, useIdle, useLifecycle, useLoop, useMediaQuery, useMutation, usePointer, usePrefersReducedMotion, usePresence, useRenderState, useScrollProgress, useSight, useSize, useStableCallback, useSyncedRef, useTween, useWhenIdle };
|
|
1223
|
+
export { Defer, Presence, Swap, WhenIdle, WhenVisible, useCanvas, useContainerQuery, useDevicePixelRatio, useIdle, useLifecycle, useLoop, useMediaQuery, useMutation, usePointer, usePrefersReducedMotion, usePresence, useRenderState, useScroll, useScrollProgress, useSight, useSize, useStableCallback, useSyncedRef, useTween, useWhenIdle };
|
|
1175
1224
|
|
|
1176
1225
|
//# sourceMappingURL=react.js.map
|