phase 0.0.12 → 0.2.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 +44 -41
- package/dist/{debounce-C0SgiTfm.js → debounce-V_5xqZSY.js} +83 -44
- package/dist/debounce-V_5xqZSY.js.map +1 -0
- package/dist/{index-BoQBL4QY.d.ts → index-MqCTTujG.d.ts} +22 -13
- package/dist/{index-BoQBL4QY.d.ts.map → index-MqCTTujG.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/react.d.ts +15 -6
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +35 -30
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/dist/debounce-C0SgiTfm.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 { 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-V_5xqZSY.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
|
|
@@ -84,7 +84,7 @@ function useLoop(options) {
|
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
const loop = createLoop({
|
|
87
|
-
element,
|
|
87
|
+
target: element,
|
|
88
88
|
onTick: (frame) => onTickRef.current(frame),
|
|
89
89
|
fps,
|
|
90
90
|
reducedMotion,
|
|
@@ -157,7 +157,7 @@ function useLifecycle(options) {
|
|
|
157
157
|
return;
|
|
158
158
|
}
|
|
159
159
|
const lifecycle = createLifecycle({
|
|
160
|
-
element,
|
|
160
|
+
target: element,
|
|
161
161
|
reducedMotion,
|
|
162
162
|
intersectionOptions,
|
|
163
163
|
onPhaseChange: (phase, phaseReason) => {
|
|
@@ -252,7 +252,7 @@ function useSight(options) {
|
|
|
252
252
|
if (!element) return;
|
|
253
253
|
let frozen = false;
|
|
254
254
|
const sight = createSight({
|
|
255
|
-
element,
|
|
255
|
+
target: element,
|
|
256
256
|
intersectionOptions: {
|
|
257
257
|
root: options?.root,
|
|
258
258
|
rootMargin: options?.rootMargin,
|
|
@@ -384,7 +384,7 @@ function useScrollProgress(options) {
|
|
|
384
384
|
const element = ref.current;
|
|
385
385
|
if (!element) return;
|
|
386
386
|
const scrollProgress = createScrollProgress({
|
|
387
|
-
element,
|
|
387
|
+
target: element,
|
|
388
388
|
onProgress: (ratio) => {
|
|
389
389
|
progressRef.current = ratio;
|
|
390
390
|
if (onProgressRef.current) onProgressRef.current(ratio);
|
|
@@ -428,7 +428,7 @@ function useRenderState(ref) {
|
|
|
428
428
|
const element = ref.current;
|
|
429
429
|
if (!element) return;
|
|
430
430
|
const render = createRenderState({
|
|
431
|
-
element,
|
|
431
|
+
target: element,
|
|
432
432
|
onPhaseChange: setPhase
|
|
433
433
|
});
|
|
434
434
|
return () => render.stop();
|
|
@@ -569,7 +569,7 @@ function useCanvas(options) {
|
|
|
569
569
|
canvas.addEventListener("contextrestored", onContextRestored);
|
|
570
570
|
let loopInstance = null;
|
|
571
571
|
const loop = createLoop({
|
|
572
|
-
|
|
572
|
+
target: container,
|
|
573
573
|
fps,
|
|
574
574
|
reducedMotion,
|
|
575
575
|
...degradedConfig(degraded, degradedFps),
|
|
@@ -644,7 +644,7 @@ function useMutation(options) {
|
|
|
644
644
|
return;
|
|
645
645
|
}
|
|
646
646
|
const instance = createMutation({
|
|
647
|
-
element,
|
|
647
|
+
target: element,
|
|
648
648
|
mutation: mutationInit,
|
|
649
649
|
onMutations: (records) => onMutationsRef.current(records),
|
|
650
650
|
onPhaseChange: (phase, reason) => {
|
|
@@ -711,7 +711,7 @@ function usePointer(options) {
|
|
|
711
711
|
return;
|
|
712
712
|
}
|
|
713
713
|
const instance = createPointer({
|
|
714
|
-
element,
|
|
714
|
+
target: element,
|
|
715
715
|
onPointer: (pointerState) => {
|
|
716
716
|
stateRef.current = pointerState;
|
|
717
717
|
onPointerRef.current(pointerState);
|
|
@@ -767,7 +767,7 @@ function initialState() {
|
|
|
767
767
|
*/
|
|
768
768
|
function useScroll(options) {
|
|
769
769
|
const [state, setState] = useState(INITIAL_STATE);
|
|
770
|
-
const { visibility = "pause", enabled = true, intersectionOptions } = options;
|
|
770
|
+
const { target, visibility = "pause", enabled = true, intersectionOptions } = options;
|
|
771
771
|
const phaseRef = useRef("paused");
|
|
772
772
|
const phaseReasonRef = useRef("initial");
|
|
773
773
|
const stateRef = useRef(initialState());
|
|
@@ -779,8 +779,9 @@ function useScroll(options) {
|
|
|
779
779
|
instanceRef.current?.measure();
|
|
780
780
|
}, []);
|
|
781
781
|
useEffect(() => {
|
|
782
|
-
|
|
783
|
-
|
|
782
|
+
if (target && options.ref) conflictingTargetError("useScroll");
|
|
783
|
+
const anchor = target === "page" ? document : ref.current;
|
|
784
|
+
if (!anchor || !enabled) {
|
|
784
785
|
instanceRef.current = null;
|
|
785
786
|
setState(INITIAL_STATE);
|
|
786
787
|
phaseRef.current = "paused";
|
|
@@ -789,7 +790,7 @@ function useScroll(options) {
|
|
|
789
790
|
return;
|
|
790
791
|
}
|
|
791
792
|
const instance = createScroll({
|
|
792
|
-
|
|
793
|
+
target: anchor,
|
|
793
794
|
onScroll: (scrollState) => {
|
|
794
795
|
stateRef.current = scrollState;
|
|
795
796
|
onScrollRef.current(scrollState);
|
|
@@ -810,7 +811,11 @@ function useScroll(options) {
|
|
|
810
811
|
instance.stop();
|
|
811
812
|
instanceRef.current = null;
|
|
812
813
|
};
|
|
813
|
-
}, [
|
|
814
|
+
}, [
|
|
815
|
+
enabled,
|
|
816
|
+
visibility,
|
|
817
|
+
target
|
|
818
|
+
]);
|
|
814
819
|
return {
|
|
815
820
|
ref,
|
|
816
821
|
...state,
|
|
@@ -913,7 +918,7 @@ function useDebouncedCallback(callback, options) {
|
|
|
913
918
|
//#endregion
|
|
914
919
|
//#region src/react/use-tween/index.ts
|
|
915
920
|
/**
|
|
916
|
-
* Animate a value from its current position
|
|
921
|
+
* Animate a value from its current position toward `to` over `duration`.
|
|
917
922
|
*
|
|
918
923
|
* Uses `useState` per frame. Appropriate for cheap renders (counters, opacity,
|
|
919
924
|
* progress bars). For batch animations, use `useLoop` with ref-based DOM writes.
|
|
@@ -926,21 +931,21 @@ function useDebouncedCallback(callback, options) {
|
|
|
926
931
|
* weight for no benefit.
|
|
927
932
|
*
|
|
928
933
|
* @example
|
|
929
|
-
* const value = useTween({
|
|
934
|
+
* const value = useTween({ to: 100, duration: 500 });
|
|
930
935
|
*/
|
|
931
936
|
function useTween(options) {
|
|
932
|
-
const {
|
|
933
|
-
const [value, setValue] = useState(
|
|
937
|
+
const { to, duration = 300, delay = 0, easing = easeOutCubic, enabled = true, reducedMotion = "complete" } = options;
|
|
938
|
+
const [value, setValue] = useState(to);
|
|
934
939
|
const easingRef = useSyncedRef(easing);
|
|
935
|
-
const fromRef = useRef(
|
|
936
|
-
const currentRef = useRef(
|
|
940
|
+
const fromRef = useRef(to);
|
|
941
|
+
const currentRef = useRef(to);
|
|
937
942
|
const isFirstRender = useRef(true);
|
|
938
943
|
useEffect(() => {
|
|
939
944
|
if (!Number.isFinite(duration) || duration <= 0) invalidDurationError("useTween", duration);
|
|
940
945
|
if (isFirstRender.current) {
|
|
941
946
|
isFirstRender.current = false;
|
|
942
947
|
jumpToTarget({
|
|
943
|
-
|
|
948
|
+
to,
|
|
944
949
|
fromRef,
|
|
945
950
|
currentRef,
|
|
946
951
|
setValue
|
|
@@ -949,7 +954,7 @@ function useTween(options) {
|
|
|
949
954
|
}
|
|
950
955
|
if (!enabled || reducedMotion !== "ignore" && prefersReducedMotion()) {
|
|
951
956
|
jumpToTarget({
|
|
952
|
-
|
|
957
|
+
to,
|
|
953
958
|
fromRef,
|
|
954
959
|
currentRef,
|
|
955
960
|
setValue
|
|
@@ -957,7 +962,7 @@ function useTween(options) {
|
|
|
957
962
|
return;
|
|
958
963
|
}
|
|
959
964
|
const from = currentRef.current;
|
|
960
|
-
if (from ===
|
|
965
|
+
if (from === to) return;
|
|
961
966
|
let rafId;
|
|
962
967
|
let startTime = null;
|
|
963
968
|
function tick(now) {
|
|
@@ -968,11 +973,11 @@ function useTween(options) {
|
|
|
968
973
|
return;
|
|
969
974
|
}
|
|
970
975
|
const progress = clamp01(elapsed / duration);
|
|
971
|
-
const current = progress === 1 ?
|
|
976
|
+
const current = progress === 1 ? to : from + (to - from) * easingRef.current(progress);
|
|
972
977
|
currentRef.current = current;
|
|
973
978
|
setValue(current);
|
|
974
979
|
if (progress < 1) rafId = requestAnimationFrame(tick);
|
|
975
|
-
else fromRef.current =
|
|
980
|
+
else fromRef.current = to;
|
|
976
981
|
}
|
|
977
982
|
rafId = requestAnimationFrame(tick);
|
|
978
983
|
return () => {
|
|
@@ -980,7 +985,7 @@ function useTween(options) {
|
|
|
980
985
|
fromRef.current = currentRef.current;
|
|
981
986
|
};
|
|
982
987
|
}, [
|
|
983
|
-
|
|
988
|
+
to,
|
|
984
989
|
duration,
|
|
985
990
|
delay,
|
|
986
991
|
enabled,
|
|
@@ -989,10 +994,10 @@ function useTween(options) {
|
|
|
989
994
|
return value;
|
|
990
995
|
}
|
|
991
996
|
function jumpToTarget(options) {
|
|
992
|
-
const {
|
|
993
|
-
fromRef.current =
|
|
994
|
-
currentRef.current =
|
|
995
|
-
setValue(
|
|
997
|
+
const { to, fromRef, currentRef, setValue } = options;
|
|
998
|
+
fromRef.current = to;
|
|
999
|
+
currentRef.current = to;
|
|
1000
|
+
setValue(to);
|
|
996
1001
|
}
|
|
997
1002
|
//#endregion
|
|
998
1003
|
//#region src/react/_internal/use-update-effect/index.ts
|