phase 0.1.0 → 0.3.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 +52 -49
- package/dist/{debounce-BX3NrBak.js → debounce-BA-WszUy.js} +84 -21
- package/dist/debounce-BA-WszUy.js.map +1 -0
- package/dist/{index-DrG0DyLp.d.ts → index-BF6G-0ih.d.ts} +25 -6
- package/dist/index-BF6G-0ih.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/react.d.ts +38 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +38 -21
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/dist/debounce-BX3NrBak.js.map +0 -1
- package/dist/index-DrG0DyLp.d.ts.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 { S as invalidDurationError, _ as subscribeMediaQuery, a as createPointer, c as prefersReducedMotion, d as subscribeDpr, f as createRenderState, g as readMediaQuery, h as createLifecycle, i as observeResize, l as whenIdle, m as createLoop, n as createThrottle, o as createMutation, p as createScrollProgress, r as createScroll, s as REDUCED_MOTION_QUERY, t as createDebounce, u as readDpr, v as createSight, w as missingContextError, x as conflictingTargetError } from "./debounce-BA-WszUy.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
|
|
@@ -71,20 +71,21 @@ const INITIAL_STATE$6 = {
|
|
|
71
71
|
* return <div ref={ref} />;
|
|
72
72
|
*/
|
|
73
73
|
function useLoop(options) {
|
|
74
|
-
const { fps, enabled = true, reducedMotion, degraded, degradedFps, intersectionOptions } = options;
|
|
74
|
+
const { target, fps, enabled = true, reducedMotion, degraded, degradedFps, intersectionOptions } = options;
|
|
75
75
|
const onTickRef = useSyncedRef(options.onTick);
|
|
76
76
|
const internalRef = useRef(null);
|
|
77
77
|
const ref = options.ref ?? internalRef;
|
|
78
78
|
const [state, setState] = useState(INITIAL_STATE$6);
|
|
79
79
|
const loopRef = useRef(null);
|
|
80
80
|
useEffect(() => {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
if (target && options.ref) conflictingTargetError("useLoop");
|
|
82
|
+
const anchor = target === "page" ? document : ref.current;
|
|
83
|
+
if (!anchor || !enabled) {
|
|
83
84
|
setState(INITIAL_STATE$6);
|
|
84
85
|
return;
|
|
85
86
|
}
|
|
86
87
|
const loop = createLoop({
|
|
87
|
-
target:
|
|
88
|
+
target: anchor,
|
|
88
89
|
onTick: (frame) => onTickRef.current(frame),
|
|
89
90
|
fps,
|
|
90
91
|
reducedMotion,
|
|
@@ -110,7 +111,8 @@ function useLoop(options) {
|
|
|
110
111
|
fps,
|
|
111
112
|
reducedMotion,
|
|
112
113
|
degraded,
|
|
113
|
-
degradedFps
|
|
114
|
+
degradedFps,
|
|
115
|
+
target
|
|
114
116
|
]);
|
|
115
117
|
return {
|
|
116
118
|
ref,
|
|
@@ -143,7 +145,7 @@ const INITIAL_STATE$5 = {
|
|
|
143
145
|
* return <canvas ref={ref} />;
|
|
144
146
|
*/
|
|
145
147
|
function useLifecycle(options) {
|
|
146
|
-
const { reducedMotion, intersectionOptions, enabled = true } = options ?? {};
|
|
148
|
+
const { target, reducedMotion, intersectionOptions, enabled = true } = options ?? {};
|
|
147
149
|
const paused = options?.paused ?? false;
|
|
148
150
|
const onPhaseChangeRef = useSyncedRef(options?.onPhaseChange);
|
|
149
151
|
const internalRef = useRef(null);
|
|
@@ -151,13 +153,14 @@ function useLifecycle(options) {
|
|
|
151
153
|
const [state, setState] = useState(INITIAL_STATE$5);
|
|
152
154
|
const lifecycleRef = useRef(null);
|
|
153
155
|
useEffect(() => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
if (target && options?.ref) conflictingTargetError("useLifecycle");
|
|
157
|
+
const anchor = target === "page" ? document : ref.current;
|
|
158
|
+
if (!anchor || !enabled) {
|
|
156
159
|
setState(INITIAL_STATE$5);
|
|
157
160
|
return;
|
|
158
161
|
}
|
|
159
162
|
const lifecycle = createLifecycle({
|
|
160
|
-
target:
|
|
163
|
+
target: anchor,
|
|
161
164
|
reducedMotion,
|
|
162
165
|
intersectionOptions,
|
|
163
166
|
onPhaseChange: (phase, phaseReason) => {
|
|
@@ -174,7 +177,11 @@ function useLifecycle(options) {
|
|
|
174
177
|
lifecycle.stop();
|
|
175
178
|
lifecycleRef.current = null;
|
|
176
179
|
};
|
|
177
|
-
}, [
|
|
180
|
+
}, [
|
|
181
|
+
enabled,
|
|
182
|
+
reducedMotion,
|
|
183
|
+
target
|
|
184
|
+
]);
|
|
178
185
|
useEffect(() => {
|
|
179
186
|
const lifecycle = lifecycleRef.current;
|
|
180
187
|
if (!lifecycle) return;
|
|
@@ -245,14 +252,17 @@ function useSight(options) {
|
|
|
245
252
|
const phaseRef = useRef("unknown");
|
|
246
253
|
const phaseReasonRef = useRef("initial");
|
|
247
254
|
const onVisibilityChangeRef = useSyncedRef(options?.onVisibilityChange);
|
|
255
|
+
const target = options?.target;
|
|
248
256
|
const internalRef = useRef(null);
|
|
249
257
|
const ref = options?.ref ?? internalRef;
|
|
250
258
|
useEffect(() => {
|
|
251
|
-
|
|
252
|
-
|
|
259
|
+
if (target && options?.ref) conflictingTargetError("useSight");
|
|
260
|
+
const anchor = target === "page" ? document : ref.current;
|
|
261
|
+
if (!anchor) return;
|
|
253
262
|
let frozen = false;
|
|
263
|
+
let instance = null;
|
|
254
264
|
const sight = createSight({
|
|
255
|
-
target:
|
|
265
|
+
target: anchor,
|
|
256
266
|
intersectionOptions: {
|
|
257
267
|
root: options?.root,
|
|
258
268
|
rootMargin: options?.rootMargin,
|
|
@@ -269,12 +279,14 @@ function useSight(options) {
|
|
|
269
279
|
});
|
|
270
280
|
if (observe === "once" && phase === "visible") {
|
|
271
281
|
frozen = true;
|
|
272
|
-
|
|
282
|
+
instance?.stop();
|
|
273
283
|
}
|
|
274
284
|
}
|
|
275
285
|
});
|
|
286
|
+
instance = sight;
|
|
287
|
+
if (frozen) sight.stop();
|
|
276
288
|
return () => sight.stop();
|
|
277
|
-
}, [observe]);
|
|
289
|
+
}, [observe, target]);
|
|
278
290
|
return {
|
|
279
291
|
ref,
|
|
280
292
|
...state,
|
|
@@ -767,7 +779,7 @@ function initialState() {
|
|
|
767
779
|
*/
|
|
768
780
|
function useScroll(options) {
|
|
769
781
|
const [state, setState] = useState(INITIAL_STATE);
|
|
770
|
-
const { visibility = "pause", enabled = true, intersectionOptions } = options;
|
|
782
|
+
const { target, visibility = "pause", enabled = true, intersectionOptions } = options;
|
|
771
783
|
const phaseRef = useRef("paused");
|
|
772
784
|
const phaseReasonRef = useRef("initial");
|
|
773
785
|
const stateRef = useRef(initialState());
|
|
@@ -779,8 +791,9 @@ function useScroll(options) {
|
|
|
779
791
|
instanceRef.current?.measure();
|
|
780
792
|
}, []);
|
|
781
793
|
useEffect(() => {
|
|
782
|
-
|
|
783
|
-
|
|
794
|
+
if (target && options.ref) conflictingTargetError("useScroll");
|
|
795
|
+
const anchor = target === "page" ? document : ref.current;
|
|
796
|
+
if (!anchor || !enabled) {
|
|
784
797
|
instanceRef.current = null;
|
|
785
798
|
setState(INITIAL_STATE);
|
|
786
799
|
phaseRef.current = "paused";
|
|
@@ -789,7 +802,7 @@ function useScroll(options) {
|
|
|
789
802
|
return;
|
|
790
803
|
}
|
|
791
804
|
const instance = createScroll({
|
|
792
|
-
target:
|
|
805
|
+
target: anchor,
|
|
793
806
|
onScroll: (scrollState) => {
|
|
794
807
|
stateRef.current = scrollState;
|
|
795
808
|
onScrollRef.current(scrollState);
|
|
@@ -810,7 +823,11 @@ function useScroll(options) {
|
|
|
810
823
|
instance.stop();
|
|
811
824
|
instanceRef.current = null;
|
|
812
825
|
};
|
|
813
|
-
}, [
|
|
826
|
+
}, [
|
|
827
|
+
enabled,
|
|
828
|
+
visibility,
|
|
829
|
+
target
|
|
830
|
+
]);
|
|
814
831
|
return {
|
|
815
832
|
ref,
|
|
816
833
|
...state,
|