phase 0.0.11 → 0.1.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/dist/react.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { clamp01, easeOutCubic } from "./ease.js";
3
- import { C as missingContextError, _ 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, x as invalidDurationError } from "./debounce-BD9K4TW4.js";
3
+ import { C as missingContextError, _ 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, x as invalidDurationError } from "./debounce-BX3NrBak.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
- element: container,
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);
@@ -789,7 +789,7 @@ function useScroll(options) {
789
789
  return;
790
790
  }
791
791
  const instance = createScroll({
792
- element,
792
+ target: element,
793
793
  onScroll: (scrollState) => {
794
794
  stateRef.current = scrollState;
795
795
  onScrollRef.current(scrollState);
@@ -913,7 +913,7 @@ function useDebouncedCallback(callback, options) {
913
913
  //#endregion
914
914
  //#region src/react/use-tween/index.ts
915
915
  /**
916
- * Animate a value from its current position to `target` over `duration`.
916
+ * Animate a value from its current position toward `to` over `duration`.
917
917
  *
918
918
  * Uses `useState` per frame. Appropriate for cheap renders (counters, opacity,
919
919
  * progress bars). For batch animations, use `useLoop` with ref-based DOM writes.
@@ -926,21 +926,21 @@ function useDebouncedCallback(callback, options) {
926
926
  * weight for no benefit.
927
927
  *
928
928
  * @example
929
- * const value = useTween({ target: 100, duration: 500 });
929
+ * const value = useTween({ to: 100, duration: 500 });
930
930
  */
931
931
  function useTween(options) {
932
- const { target, duration = 300, delay = 0, easing = easeOutCubic, enabled = true, reducedMotion = "complete" } = options;
933
- const [value, setValue] = useState(target);
932
+ const { to, duration = 300, delay = 0, easing = easeOutCubic, enabled = true, reducedMotion = "complete" } = options;
933
+ const [value, setValue] = useState(to);
934
934
  const easingRef = useSyncedRef(easing);
935
- const fromRef = useRef(target);
936
- const currentRef = useRef(target);
935
+ const fromRef = useRef(to);
936
+ const currentRef = useRef(to);
937
937
  const isFirstRender = useRef(true);
938
938
  useEffect(() => {
939
939
  if (!Number.isFinite(duration) || duration <= 0) invalidDurationError("useTween", duration);
940
940
  if (isFirstRender.current) {
941
941
  isFirstRender.current = false;
942
942
  jumpToTarget({
943
- target,
943
+ to,
944
944
  fromRef,
945
945
  currentRef,
946
946
  setValue
@@ -949,7 +949,7 @@ function useTween(options) {
949
949
  }
950
950
  if (!enabled || reducedMotion !== "ignore" && prefersReducedMotion()) {
951
951
  jumpToTarget({
952
- target,
952
+ to,
953
953
  fromRef,
954
954
  currentRef,
955
955
  setValue
@@ -957,7 +957,7 @@ function useTween(options) {
957
957
  return;
958
958
  }
959
959
  const from = currentRef.current;
960
- if (from === target) return;
960
+ if (from === to) return;
961
961
  let rafId;
962
962
  let startTime = null;
963
963
  function tick(now) {
@@ -968,11 +968,11 @@ function useTween(options) {
968
968
  return;
969
969
  }
970
970
  const progress = clamp01(elapsed / duration);
971
- const current = progress === 1 ? target : from + (target - from) * easingRef.current(progress);
971
+ const current = progress === 1 ? to : from + (to - from) * easingRef.current(progress);
972
972
  currentRef.current = current;
973
973
  setValue(current);
974
974
  if (progress < 1) rafId = requestAnimationFrame(tick);
975
- else fromRef.current = target;
975
+ else fromRef.current = to;
976
976
  }
977
977
  rafId = requestAnimationFrame(tick);
978
978
  return () => {
@@ -980,7 +980,7 @@ function useTween(options) {
980
980
  fromRef.current = currentRef.current;
981
981
  };
982
982
  }, [
983
- target,
983
+ to,
984
984
  duration,
985
985
  delay,
986
986
  enabled,
@@ -989,10 +989,10 @@ function useTween(options) {
989
989
  return value;
990
990
  }
991
991
  function jumpToTarget(options) {
992
- const { target, fromRef, currentRef, setValue } = options;
993
- fromRef.current = target;
994
- currentRef.current = target;
995
- setValue(target);
992
+ const { to, fromRef, currentRef, setValue } = options;
993
+ fromRef.current = to;
994
+ currentRef.current = to;
995
+ setValue(to);
996
996
  }
997
997
  //#endregion
998
998
  //#region src/react/_internal/use-update-effect/index.ts