swipefeed 1.1.1 → 1.1.3
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 +6 -0
- package/dist/components/SwipeDeck.d.ts +1 -1
- package/dist/constants.d.ts +83 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -13
- package/dist/stories/SwipeDeck.stories.d.ts +2 -1
- package/package.json +1 -1
- package/dist/__tests__/useScrollTo.test.d.ts +0 -1
- package/dist/hooks/useScrollTo.d.ts +0 -9
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/banner.png" alt="swipefeed: headless React primitives for swipe feeds" width="320">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# swipefeed
|
|
2
6
|
|
|
3
7
|

|
|
@@ -8,6 +12,8 @@
|
|
|
8
12
|
|
|
9
13
|
Headless React primitives for building TikTok/Reels-style swipe feeds. Ships a render-prop component (`SwipeDeck`) and a hook (`useSwipeDeck`) that wire up native scroll-snap, TanStack virtualization, gesture/wheel/keyboard inputs, accessibility, and programmatic controls.
|
|
10
14
|
|
|
15
|
+

|
|
16
|
+
|
|
11
17
|
## Highlights
|
|
12
18
|
|
|
13
19
|
- Headless: bring your own markup/styles; spread provided props for behavior.
|
|
@@ -2,4 +2,4 @@ import type React from "react";
|
|
|
2
2
|
import type { SwipeDeckHandle, SwipeDeckProps } from "../types";
|
|
3
3
|
export declare function SwipeDeck<T>(props: SwipeDeckProps<T> & {
|
|
4
4
|
ref?: React.Ref<SwipeDeckHandle>;
|
|
5
|
-
}):
|
|
5
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimum time between successive navigations to prevent multi-swipe.
|
|
3
|
+
* Programmatic and snap navigations bypass this cooldown.
|
|
4
|
+
*/
|
|
5
|
+
export declare const NAVIGATION_COOLDOWN_MS = 250;
|
|
6
|
+
/**
|
|
7
|
+
* Fallback timeout for scrollend event. If the browser's native scrollend
|
|
8
|
+
* event never fires (e.g., due to interrupted scroll), this ensures the
|
|
9
|
+
* navigation lock is released and scroll-snap is restored.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SCROLLEND_FALLBACK_TIMEOUT_MS = 400;
|
|
12
|
+
/**
|
|
13
|
+
* Safety timeout to clear a stuck isNavigatingRef flag. If a navigation
|
|
14
|
+
* has been in progress for longer than this, the lock is force-released
|
|
15
|
+
* to prevent permanently blocking subsequent navigations.
|
|
16
|
+
*/
|
|
17
|
+
export declare const STUCK_NAVIGATION_TIMEOUT_MS = 600;
|
|
18
|
+
/**
|
|
19
|
+
* Safety timeout for handleScroll. If the navigation lock has been held
|
|
20
|
+
* for longer than this, force-unlock so scroll events can update the index.
|
|
21
|
+
* Longer than STUCK_NAVIGATION_TIMEOUT_MS since it's a last-resort check.
|
|
22
|
+
*/
|
|
23
|
+
export declare const NAVIGATION_LOCK_TIMEOUT_MS = 1500;
|
|
24
|
+
/**
|
|
25
|
+
* Debounce delay for snap-correction after scroll stops. After this idle
|
|
26
|
+
* period, the viewport checks alignment and snaps to the current index
|
|
27
|
+
* if misaligned.
|
|
28
|
+
*/
|
|
29
|
+
export declare const SNAP_CORRECTION_DEBOUNCE_MS = 150;
|
|
30
|
+
/**
|
|
31
|
+
* Debounce delay for resize-based scroll correction. After viewport resize
|
|
32
|
+
* settles, correct scroll position to maintain the current index.
|
|
33
|
+
*/
|
|
34
|
+
export declare const RESIZE_CORRECTION_DEBOUNCE_MS = 50;
|
|
35
|
+
/**
|
|
36
|
+
* Debounce delay for the useWindowSize hook resize handler.
|
|
37
|
+
*/
|
|
38
|
+
export declare const WINDOW_RESIZE_DEBOUNCE_MS = 100;
|
|
39
|
+
/**
|
|
40
|
+
* Base pixel tolerance for snap alignment checks. Scaled by devicePixelRatio
|
|
41
|
+
* at runtime to handle high-DPI displays correctly.
|
|
42
|
+
*/
|
|
43
|
+
export declare const SNAP_ALIGNMENT_TOLERANCE_PX = 5;
|
|
44
|
+
/**
|
|
45
|
+
* Minimum fraction of item size that scroll must be off by before resize
|
|
46
|
+
* correction triggers. Prevents fighting with CSS scroll-snap.
|
|
47
|
+
*/
|
|
48
|
+
export declare const RESIZE_MISALIGNMENT_THRESHOLD = 0.1;
|
|
49
|
+
/**
|
|
50
|
+
* Maximum delta accumulated from a single wheel event for threshold checking.
|
|
51
|
+
* Allows reasonable fast scrolls while dampening extreme values from
|
|
52
|
+
* high-resolution or accelerated scroll wheels.
|
|
53
|
+
*/
|
|
54
|
+
export declare const WHEEL_MAX_DELTA_ACCUMULATION = 120;
|
|
55
|
+
/**
|
|
56
|
+
* Maximum visual delta per wheel event. Clamps the visual drag so that
|
|
57
|
+
* large mouse wheel jumps (e.g., 100px) appear as smooth nudges (~40px)
|
|
58
|
+
* while continuous trackpad events (usually < 20px) pass through unaffected.
|
|
59
|
+
*/
|
|
60
|
+
export declare const WHEEL_MAX_VISUAL_DELTA = 40;
|
|
61
|
+
/**
|
|
62
|
+
* Velocity threshold (px/ms) for flick detection on wheel input.
|
|
63
|
+
* When the smoothed velocity exceeds this value, a navigation is triggered
|
|
64
|
+
* even if the accumulated delta hasn't reached the full threshold.
|
|
65
|
+
*/
|
|
66
|
+
export declare const WHEEL_FLICK_VELOCITY_THRESHOLD = 1.2;
|
|
67
|
+
/**
|
|
68
|
+
* Minimum accumulated delta (px) for a flick to trigger navigation.
|
|
69
|
+
* Prevents accidental flick detection from tiny high-velocity events.
|
|
70
|
+
*/
|
|
71
|
+
export declare const WHEEL_FLICK_DISTANCE_THRESHOLD = 20;
|
|
72
|
+
/**
|
|
73
|
+
* Exponential moving average weight for velocity smoothing.
|
|
74
|
+
* Higher values (closer to 1) weight historical velocity more.
|
|
75
|
+
* Current: 80% previous + 20% instantaneous.
|
|
76
|
+
*/
|
|
77
|
+
export declare const WHEEL_VELOCITY_SMOOTHING_WEIGHT = 0.8;
|
|
78
|
+
/**
|
|
79
|
+
* Fallback item size in pixels when viewport cannot be measured and no
|
|
80
|
+
* explicit estimatedSize is provided. Only used during SSR or before
|
|
81
|
+
* the scroll element is available.
|
|
82
|
+
*/
|
|
83
|
+
export declare const VIRTUALIZER_FALLBACK_SIZE_PX = 800;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{useCallback as g,useEffect as K0,useMemo as i,useRef as u,useState as M0}from"react";function s(X,Y,q){if(Number.isNaN(X))return Y;return Math.min(Math.max(X,Y),q)}var X0=null;function G0(){if(X0!==null)return X0;if(typeof window>"u"||typeof window.matchMedia!=="function")return X0=!1,X0;return X0=window.matchMedia("(prefers-reduced-motion: reduce)").matches,X0}import{useCallback as a,useRef as m0,useState as p0,useMemo as v0}from"react";function T0(X,Y){return Y==="vertical"?X.clientY:X.clientX}function C0(X){let{orientation:Y,direction:q,threshold:F,flickVelocity:K,lockAxis:w,ignoreWhileAnimating:E,loop:W,getIndex:L,maxIndex:z,onRequestIndexChange:A,setAnimating:k,isAnimating:_,onDragStart:$,onDrag:B,onDragEnd:H}=X,[b,O]=p0(!1),Z=m0({isDragging:!1,start:0,last:0,delta:0,startTime:0}),N=a((j)=>{j.currentTarget.setPointerCapture?.(j.pointerId);let D=T0(j,Y);Z.current={isDragging:!0,start:D,last:D,delta:0,startTime:performance.now()},O(!0),$?.(j)},[Y,$]),h=a((j)=>{if(!Z.current.isDragging)return;let D=T0(j,Y),R=D-Z.current.start;Z.current.delta=R,Z.current.last=D,B?.(R,j)},[Y,B]),V=a(()=>{if(!Z.current.isDragging)return;let j=performance.now(),D=Math.max(j-Z.current.startTime,1),R=Math.abs(Z.current.delta),S=R/D,M=(()=>{let o=Z.current.delta;if(Y==="vertical")return o<0;return(q==="rtl"?o*-1:o)<0})(),l=L(),y=M?1:-1,t=S>K,e=R>F,p=l;if(t||e)p=l+y;if(W)p=(p+(z+1))%(z+1);else p=s(p,0,z);k(!0),A(p),Z.current.isDragging=!1,Z.current.delta=0,O(!1),H?.()},[q,K,L,z,A,Y,W,k,F,H]),n=a(()=>{Z.current.isDragging=!1,Z.current.delta=0,O(!1)},[]),x=a((j)=>{if(E&&_)return;if(j.button!==0)return;N(j)},[E,_,N]),c=a((j)=>{if(!w&&!Z.current.isDragging)return;if(Z.current.isDragging)h(j)},[w,h]),G=a(()=>{V()},[V]),P=a(()=>{n()},[n]);return v0(()=>({isDragging:b,handlers:{onPointerDown:x,onPointerMove:c,onPointerUp:G,onPointerCancel:P}}),[b,x,c,G,P])}import{useCallback as D0,useRef as r,useEffect as u0}from"react";function k0(X){let{orientation:Y,direction:q,discretePaging:F,threshold:K,debounce:w,cooldown:E=500,onRequestIndexChange:W,viewport:L,onDragStart:z,onDrag:A,onDragEnd:k}=X,_=r(0),$=r(null),B=r(0),H=r(!1),b=r(0),O=r(null),Z=r(0),N=r(!1),h=r(0),V=120,n=40,x=D0(()=>{N.current=!1,_.current=0,O.current=null,Z.current=0,h.current=0,k?.()},[k]),c=D0(()=>{if($.current)clearTimeout($.current);$.current=setTimeout(()=>{x()},w)},[w,x]);u0(()=>{let G=L;if(!G)return;let P=(j)=>{if(!F)return;j.preventDefault(),j.stopPropagation();let D=performance.now();if(H.current){if(D-B.current<E){if(N.current)console.log("[useWheel] Ignoring wheel event during cooldown"),N.current=!1,_.current=0,O.current=null,Z.current=0,h.current=0;return}H.current=!1}let R=Y==="vertical"?j.deltaY:j.deltaX,S=Y==="horizontal"&&q==="rtl"?-R:R,M=S>0?1:-1;if(O.current!==null&&O.current!==M)_.current=0,Z.current=0;if(O.current=M,!N.current)N.current=!0,z?.();let l=D-b.current;b.current=D,Z.current++;let y=Math.sign(S)*Math.min(Math.abs(S),120),t=Math.sign(S)*Math.min(Math.abs(S),40),e=l>0&&l<100?Math.abs(y/l):0;h.current=h.current*0.8+e*0.2,_.current+=y,A?.(-t),c();let p=Math.abs(_.current)>=K,o=h.current>1.2&&Math.abs(_.current)>20;if(p||o){let J0=_.current>0?1:-1;if(console.log("[useWheel] Navigation triggered",{navDelta:J0,accumulated:_.current,threshold:K,matchesThreshold:p,isFlick:o,velocity:h.current}),N.current=!1,_.current=0,O.current=null,Z.current=0,h.current=0,B.current=D,H.current=!0,$.current)clearTimeout($.current);W(J0)}};return G.addEventListener("wheel",P,{passive:!1}),()=>{if(G.removeEventListener("wheel",P),$.current)clearTimeout($.current)}},[Y,q,F,K,E,W,c,L,z,A])}import{useCallback as c0,useEffect as d0}from"react";var l0={prev:["ArrowUp"],next:["ArrowDown"],first:["Home"],last:["End"],altPrev:["PageUp"],altNext:["PageDown"]},s0={prev:["ArrowLeft"],next:["ArrowRight"],first:["Home"],last:["End"],altPrev:["PageUp"],altNext:["PageDown"]};function S0(X){let{orientation:Y,direction:q,config:F,onPrev:K,onNext:w,onFirst:E,onLast:W}=X,L=F?.enabled??!0,z=F?.global??!1,A=F?.bindings??(Y==="vertical"?l0:s0),k=c0((_)=>{if(!L)return;let $=_.key,B=[...A.prev??[],...A.altPrev??[]],H=[...A.next??[],...A.altNext??[]],b=Y==="horizontal",O=q==="rtl";if(B.includes($)){if(_.preventDefault(),b&&O)w();else K();return}if(H.includes($)){if(_.preventDefault(),b&&O)K();else w();return}if(A.first?.includes($)){_.preventDefault(),E?.();return}if(A.last?.includes($)){_.preventDefault(),W?.();return}},[A,q,L,E,W,w,K,Y]);return d0(()=>{if(!L||!z)return;return window.addEventListener("keydown",k),()=>{window.removeEventListener("keydown",k)}},[L,z,k]),{onKeyDown:k}}import{useEffect as r0,useLayoutEffect as a0,useState as n0,useMemo as w0,useCallback as o0}from"react";import{useVirtualizer as i0}from"@tanstack/react-virtual";var t0=typeof window<"u"?a0:r0;function R0(X){let{items:Y,virtual:q,getScrollElement:F,orientation:K="vertical"}=X,w=Y.length,[E,W]=n0(()=>{return{size:typeof window<"u"?K==="vertical"?window.innerHeight:window.innerWidth:800,measured:!1}});t0(()=>{let $=F();if(!$)return;let B=()=>{let b=K==="vertical"?$.clientHeight:$.clientWidth;if(b>0)W((O)=>{if(O.size!==b||!O.measured)return{size:b,measured:!0};return O})};B();let H=new ResizeObserver(B);return H.observe($),()=>{H.disconnect()}},[F,K]);let L=E.size,z=o0(($)=>{let B=q?.estimatedSize;if(typeof B==="function")return B(Y[$],$);if(L>0)return L;return typeof B==="number"?B:800},[q?.estimatedSize,Y,L]),A=w0(()=>{if(typeof window>"u")return{width:800,height:800};return{width:window.innerWidth,height:window.innerHeight}},[]),k=w0(()=>{if(!q?.getItemKey)return;return($)=>q.getItemKey?.(Y[$],$)??$},[q?.getItemKey,Y]),_=i0({count:w,getScrollElement:F,estimateSize:z,overscan:q?.overscan??5,horizontal:K==="horizontal",getItemKey:k,initialRect:A});return{virtualItems:_.getVirtualItems().map(($)=>({index:$.index,key:$.key,offset:$.start,size:$.size,measureElement:_.measureElement})),totalSize:_.getTotalSize(),getItemOffset:($)=>{let B=_.getVirtualItems().find((H)=>H.index===$);return B?B.start:0},getItemSize:($)=>{let B=_.getVirtualItems().find((H)=>H.index===$);return B?B.size:0},scrollToIndex:($,B)=>{_.scrollToIndex($,{align:B?.align,behavior:B?.behavior})},containerSize:L}}var d={orientation:"vertical",direction:"ltr",loop:!1,defaultIndex:0,gesture:{threshold:10,flickVelocity:0.1,lockAxis:!0,ignoreWhileAnimating:!0},wheel:{discretePaging:!0,threshold:100,debounce:120,cooldown:800},keyboard:{enabled:!0},visibility:{strategy:"position",intersectionRatio:0.6,debounce:100},virtual:{overscan:5},endReachedThreshold:3,ariaLabel:"Swipe feed",keyboardNavigation:!0};function O0(X){let Y=X.items??[],q=X.orientation??d.orientation,F=X.direction??d.direction,K=X.loop??d.loop,w=X.defaultIndex??d.defaultIndex,E=X.preload??0,W=X.preloadPrevious??0,L=i(()=>({...d.gesture,...X.gesture??{}}),[X.gesture]),z=i(()=>({...d.wheel,...X.wheel??{}}),[X.wheel]),A=i(()=>({...d.keyboard,...X.keyboard??{}}),[X.keyboard]),k=i(()=>{let J={...d.virtual,...X.virtual??{}},Q=Math.max(E,W);return{...J,overscan:Math.max(J.overscan??0,Q)}},[X.virtual,E,W]),_=X.endReachedThreshold??d.endReachedThreshold,$=X.ariaLabel??d.ariaLabel,B=X.keyboardNavigation??!0,H=typeof X.index==="number",[b,O]=M0(()=>s(w,0,Math.max(Y.length-1,0))),Z=H?s(X.index??0,0,Math.max(Y.length-1,0)):b,[N,h]=M0(!1),[V,n]=M0(null),x=u("snap"),c=u(0),G=u(!1),P=u(null),j=u(0),D=u(-1),R=u(0);K0(()=>{let J=s(Z,0,Math.max(Y.length-1,0));if(!H)O(J)},[Z,H,Y.length]);let S=R0({items:Y,virtual:k,getScrollElement:g(()=>V,[V]),orientation:q}),M=u({index:Z,items:Y,isControlled:H,options:X,virtualizer:S,loop:K,orientation:q,setInternalIndex:O,setIsAnimating:h,viewport:V});M.current={index:Z,items:Y,isControlled:H,options:X,virtualizer:S,loop:K,orientation:q,setInternalIndex:O,setIsAnimating:h,viewport:V};let l=g((J)=>{let{index:Q,isControlled:U,options:T,setInternalIndex:f,setIsAnimating:C}=M.current;if(J===Q)return;if(console.log("[SwipeDeck] applyIndexChange (from scroll)",{from:Q,to:J,source:x.current}),!U)f(J);T.onIndexChange?.(J,x.current??"snap"),C(!1),x.current="snap"},[]),y=g((J,Q,U)=>{let{items:T,loop:f,index:C,isControlled:v,options:B0,orientation:b0,virtualizer:h0,setInternalIndex:I0,viewport:m}=M.current;if(T.length===0)return;let x0=T.length-1,I=J;if(f)I=(I+T.length)%T.length;else I=s(I,0,x0);if(I===C&&Q!=="snap")return;let q0=Date.now();if(G.current&&q0-j.current>600)console.warn("[SwipeDeck] Clearing stuck navigation state"),G.current=!1;if(G.current&&Q!=="snap"&&Q!=="programmatic"){console.log("[SwipeDeck] navigateTo blocked: isNavigating",{source:Q,targetIndex:I});return}let g0=250;if(q0-R.current<g0&&Q!=="snap"&&Q!=="programmatic"){console.log("[SwipeDeck] navigateTo blocked: cooldown",{source:Q,targetIndex:I,timeSinceLastNav:q0-R.current});return}if(console.log("[SwipeDeck] navigateTo executing",{source:Q,from:C,to:I}),D.current=I,R.current=q0,x.current=Q,G.current=!0,!v)I0(I);if(console.log("[SwipeDeck] calling onIndexChange",{next:I,source:Q}),B0.onIndexChange?.(I,Q),!m){console.warn("[SwipeDeck] No viewport, skipping scroll");return}if(P.current)clearTimeout(P.current),P.current=null;m.style.scrollSnapType="none",m.style.scrollBehavior="auto";let Q0=U??(Q==="user:wheel"||Q==="programmatic"||G0()?"instant":"smooth"),$0=I*h0.containerSize;if(console.log("[SwipeDeck] scrolling to",{targetScroll:$0,containerSize:h0.containerSize,next:I,behavior:Q0}),j.current=Date.now(),b0==="vertical"){if(m.scrollTo({top:$0,behavior:Q0}),Q0==="instant")console.log("[SwipeDeck] after scrollTo",{targetScroll:$0,actualScroll:m.scrollTop})}else if(m.scrollTo({left:$0,behavior:Q0}),Q0==="instant")console.log("[SwipeDeck] after scrollTo",{targetScroll:$0,actualScroll:m.scrollLeft});let j0=()=>{if(console.log("[SwipeDeck] handleScrollEnd - clearing navigation lock"),G.current=!1,P.current)clearTimeout(P.current),P.current=null;if(m)m.style.scrollSnapType=b0==="vertical"?"y mandatory":"x mandatory"};if("onscrollend"in window){let Z0=()=>{j0(),m.removeEventListener("scrollend",Z0)};m.addEventListener("scrollend",Z0,{once:!0}),P.current=setTimeout(()=>{m.removeEventListener("scrollend",Z0),j0()},400)}else{let Z0=Q0==="smooth"?500:50;P.current=setTimeout(j0,Z0)}},[]),t=g(()=>{let{viewport:J,orientation:Q}=M.current;if(J)J.style.scrollBehavior="auto",c.current=Q==="vertical"?J.scrollTop:J.scrollLeft},[]),e=g((J)=>{let{viewport:Q,orientation:U}=M.current;if(Q){let T=c.current-J;if(U==="vertical")Q.scrollTop=T;else Q.scrollLeft=T}},[]),p=g(()=>{let{viewport:J,orientation:Q,items:U,virtualizer:T}=M.current;if(!J||U.length===0)return M.current.index;let f=Q==="vertical"?J.scrollTop:J.scrollLeft,C=T.containerSize||J.clientHeight;if(C<=0)return M.current.index;let v=Math.round(f/C);return s(v,0,U.length-1)},[]),o=k0({orientation:q,direction:F,discretePaging:z.discretePaging??!0,threshold:z.threshold??80,debounce:z.debounce??120,cooldown:z.cooldown??400,onRequestIndexChange:(J)=>y(M.current.index+J,"user:wheel"),viewport:V,onDragStart:t,onDrag:e,onDragEnd:()=>{let J=p();y(J,"snap")}}),J0=C0({orientation:q,direction:F,threshold:L.threshold??50,flickVelocity:L.flickVelocity??0.5,lockAxis:L.lockAxis??!0,ignoreWhileAnimating:L.ignoreWhileAnimating??!0,loop:K,getIndex:()=>M.current.index,maxIndex:Math.max(Y.length-1,0),onRequestIndexChange:(J)=>y(J,"user:gesture"),setAnimating:h,isAnimating:N,onDragStart:t,onDrag:e}),F0=S0({orientation:q,direction:F,config:B?A:{enabled:!1},onPrev:()=>y(M.current.index-1,"user:keyboard"),onNext:()=>y(M.current.index+1,"user:keyboard"),onFirst:()=>y(0,"user:keyboard"),onLast:()=>y(Y.length-1,"user:keyboard")}),W0=u(null),_0=u(null),V0=g(()=>{if(G.current&&Date.now()-j.current>1500)G.current=!1,console.warn("[SwipeDeck] Navigation lock timeout - forcing unlock");if(G.current)return;if(_0.current)clearTimeout(_0.current);if(_0.current=setTimeout(()=>{if(G.current)return;let{viewport:J,orientation:Q,index:U}=M.current;if(!J)return;let T=Q==="vertical"?J.scrollTop:J.scrollLeft,f=Q==="vertical"?J.clientHeight:J.clientWidth,C=U*f,v=typeof window<"u"?window.devicePixelRatio:1,B0=Math.max(5,Math.ceil(5*v));if(Math.abs(T-C)>B0)J.scrollTo({top:Q==="vertical"?C:0,left:Q==="horizontal"?C:0,behavior:"smooth"})},150),W0.current!==null)return;W0.current=requestAnimationFrame(()=>{if(W0.current=null,G.current)return;let{viewport:J,orientation:Q,items:U}=M.current;if(!J)return;let T=Q==="vertical"?J.scrollTop:J.scrollLeft,f=Q==="vertical"?J.clientHeight:J.clientWidth;if(f>0&&U.length>0){let C=Math.round(T/f),v=s(C,0,U.length-1);if(v!==M.current.index)console.log("[SwipeDeck] handleScroll calculated index",{scrollOffset:T,viewportSize:f,estimatedIndex:C,newIndex:v,currentIndex:M.current.index});l(v)}})},[l]);K0(()=>{if(Y.length===0)return;let Q=Y.length-1-Z;if(Q<=_)X.onEndReached?.({distanceFromEnd:Q,direction:"forward"});if(Z<=_)X.onEndReached?.({distanceFromEnd:Z,direction:"backward"})},[_,Z,Y.length,X]);let U0=i(()=>G0()?"instant":"smooth",[]),H1=g((J,Q)=>{y(J,"programmatic",Q?.behavior??U0)},[y,U0]),N0=i(()=>({index:Z,isAnimating:N,canPrev:K||Z>0,canNext:K||Z<Y.length-1}),[Z,N,Y.length,K]),Y0=u(null);K0(()=>{if(!V)return;let Q=new ResizeObserver(()=>{if(Y0.current)clearTimeout(Y0.current);Y0.current=setTimeout(()=>{let{orientation:U,index:T}=M.current;if(!V)return;let f=U==="vertical"?V.clientHeight:V.clientWidth,C=T*f,v=U==="vertical"?V.scrollTop:V.scrollLeft;if(Math.abs(v-C)>f*0.1)if(U==="vertical")V.scrollTop=C;else V.scrollLeft=C},50)});return Q.observe(V),()=>{if(Q.disconnect(),Y0.current)clearTimeout(Y0.current)}},[V]);let P0=g(()=>{let{viewport:J,orientation:Q}=M.current;if(J)J.style.scrollSnapType=Q==="vertical"?"y mandatory":"x mandatory"},[]),A0=g(()=>{let J={position:"relative",overflow:"auto",scrollSnapType:q==="vertical"?"y mandatory":"x mandatory",touchAction:q==="vertical"?"pan-y":"pan-x",willChange:"scroll-position"};return{ref:n,role:"feed","aria-label":$,"aria-busy":N,tabIndex:0,onScroll:V0,onKeyDown:F0.onKeyDown,onTouchStart:P0,...J0.handlers,style:J}},[$,V0,P0,N,F0.onKeyDown,q,J0.handlers]),y0=g((J)=>{let Q=Z===J,U=q==="vertical"?"100dvh":"100dvw";return{ref:void 0,"data-index":J,"data-active":Q,style:{position:"absolute",top:0,left:0,transform:q==="vertical"?`translateY(calc(${J} * ${U}))`:`translateX(calc(${J} * ${U}))`,height:q==="vertical"?U:"100%",width:q==="horizontal"?U:"100%",willChange:"transform",scrollSnapAlign:"start",scrollSnapStop:"always"}}},[Z,q]),E0=g(()=>y(M.current.index-1,"programmatic"),[y]),z0=g(()=>y(M.current.index+1,"programmatic"),[y]);return i(()=>({...N0,prev:E0,next:z0,scrollTo:(J,Q)=>y(J,"programmatic",Q?.behavior),getViewportProps:A0,getItemProps:y0,virtualItems:S.virtualItems,totalSize:S.totalSize,items:Y,orientation:q,viewport:V}),[N0,E0,z0,y,A0,y0,S.virtualItems,S.totalSize,Y,q,V])}import{useState as e0,useEffect as J1}from"react";function Q1(){let[X,Y]=e0({width:typeof window<"u"?window.innerWidth:0,height:typeof window<"u"?window.innerHeight:0});return J1(()=>{if(typeof window>"u")return;let q,F=()=>{clearTimeout(q),q=setTimeout(()=>{Y({width:window.innerWidth,height:window.innerHeight})},100)};return window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F),clearTimeout(q)}},[]),X}import{createContext as X1,useContext as Y1}from"react";var L0=X1(void 0);function $1(){let X=Y1(L0);if(!X)throw Error("useSwipeItem must be used within a SwipeDeck item");return X}import{useImperativeHandle as Z1,useMemo as f0}from"react";import{jsx as H0}from"react/jsx-runtime";function q1(X){let{as:Y="div",children:q,className:F,style:K,ref:w,...E}=X,W=O0(E);Z1(w,()=>({prev:W.prev,next:W.next,scrollTo:W.scrollTo,getState:()=>({index:W.index,isAnimating:W.isAnimating,canPrev:W.canPrev,canNext:W.canNext}),viewport:W.viewport}),[W]);let{style:L,...z}=W.getViewportProps(),A=X.fullscreen?{height:"100dvh",width:"100%",position:"absolute",top:0,left:0}:{},k=f0(()=>({...L,...A,...K}),[L,A,K]),_=f0(()=>({height:W.orientation==="vertical"?`calc(${W.items.length} * 100dvh)`:"100%",width:W.orientation==="horizontal"?`calc(${W.items.length} * 100dvw)`:"100%",position:"relative"}),[W.orientation,W.items.length]);return H0(Y,{...z,className:F,style:k,children:H0("div",{style:_,children:W.virtualItems.map((B)=>{let H=B.index,b=W.items[H];if(!b)return null;let O=W.getItemProps(H),Z=E.preload??0,N=E.preloadPrevious??0,h=!1;if(Z>0||N>0){let G=W.index;if(H<=G+Z+1&&H>=G-N-1)console.log("[SwipeDeck] preload check",{itemIndex:H,currentIndex:G,preload:Z,preloadPrevious:N});if(!E.loop){let P=H>G&&H<=G+Z,j=H<G&&H>=G-N;h=P||j}else{let P=W.items.length,j=(H-G+P)%P,D=(G-H+P)%P,R=j>0&&j<=Z,S=D>0&&D<=N;h=R||S}}let{style:V,...n}=O,x={item:b,index:H,isActive:W.index===H,shouldPreload:h,props:n},c=B.key??(E.virtual?.getItemKey?.(b,H)??H);return H0("article",{...O,"aria-label":`Item ${H+1} of ${W.items.length}`,children:H0(L0.Provider,{value:x,children:q(x)})},c)})})})}export{Q1 as useWindowSize,$1 as useSwipeItem,O0 as useSwipeDeck,q1 as SwipeDeck};
|
|
1
|
+
export{t as useWindowSize,S as useSwipeItem,o as useSwipeDeck,w as SwipeDeck};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=B78098051D0BEAB864756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
3
|
+
"sources": [],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type React from \"react\";\nimport { clamp } from \"../utils/clamp\";\nimport { prefersReducedMotion } from \"../utils/prefersReducedMotion\";\nimport { useGestures } from \"./useGestures\";\nimport { useWheel } from \"./useWheel\";\nimport { useKeyboard } from \"./useKeyboard\";\nimport { useVirtualizer } from \"./useVirtualizer\";\nimport type {\n Direction,\n IndexChangeSource,\n Orientation,\n ScrollBehavior,\n SwipeDeckAPI,\n SwipeDeckOptions,\n SwipeDeckState,\n} from \"../types\";\n\nconst DEFAULTS = {\n orientation: \"vertical\" as Orientation,\n direction: \"ltr\" as Direction,\n loop: false,\n defaultIndex: 0,\n gesture: {\n threshold: 10,\n flickVelocity: 0.1,\n lockAxis: true,\n ignoreWhileAnimating: true,\n },\n wheel: {\n discretePaging: true,\n threshold: 100,\n debounce: 120,\n cooldown: 800,\n },\n keyboard: {\n enabled: true,\n },\n visibility: {\n strategy: \"position\" as const,\n intersectionRatio: 0.6,\n debounce: 100,\n },\n virtual: {\n overscan: 5,\n },\n endReachedThreshold: 3,\n ariaLabel: \"Swipe feed\",\n keyboardNavigation: true,\n};\n\nexport function useSwipeDeck<T>(options: SwipeDeckOptions<T>): SwipeDeckAPI<T> {\n const items = options.items ?? [];\n const orientation = options.orientation ?? DEFAULTS.orientation;\n const direction = options.direction ?? DEFAULTS.direction;\n const loop = options.loop ?? DEFAULTS.loop;\n const defaultIndex = options.defaultIndex ?? DEFAULTS.defaultIndex;\n const preload = options.preload ?? 0;\n const preloadPrevious = options.preloadPrevious ?? 0;\n\n const gestureCfg = useMemo(() => ({ ...DEFAULTS.gesture, ...(options.gesture ?? {}) }), [options.gesture]);\n const wheelCfg = useMemo(() => ({ ...DEFAULTS.wheel, ...(options.wheel ?? {}) }), [options.wheel]);\n const keyboardCfg = useMemo(() => ({ ...DEFAULTS.keyboard, ...(options.keyboard ?? {}) }), [options.keyboard]);\n const virtualCfg = useMemo(() => {\n const base = { ...DEFAULTS.virtual, ...(options.virtual ?? {}) };\n // Ensure overscan is at least as large as preload + preloadPrevious to ensure all preloaded items are rendered\n const minOverscan = Math.max(preload, preloadPrevious);\n return {\n ...base,\n overscan: Math.max(base.overscan ?? 0, minOverscan),\n };\n }, [options.virtual, preload, preloadPrevious]);\n const endReachedThreshold = options.endReachedThreshold ?? DEFAULTS.endReachedThreshold;\n const ariaLabel = options.ariaLabel ?? DEFAULTS.ariaLabel;\n const keyboardNavigation = options.keyboardNavigation ?? true;\n\n const isControlled = typeof options.index === \"number\";\n const [internalIndex, setInternalIndex] = useState(() => clamp(defaultIndex, 0, Math.max(items.length - 1, 0)));\n const index = isControlled ? clamp(options.index ?? 0, 0, Math.max(items.length - 1, 0)) : internalIndex;\n\n const [isAnimating, setIsAnimating] = useState(false);\n\n // Use state for viewport to ensure hooks like useVirtualizer/useWheel know when it's ready\n const [viewport, setViewport] = useState<HTMLElement | null>(null);\n\n const sourceRef = useRef<IndexChangeSource>(\"snap\");\n const dragStartScrollRef = useRef<number>(0);\n const isNavigatingRef = useRef(false); // Track programmatic navigation to prevent scroll handler interference\n const snapRestoreTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null); // Track snap restore timeout\n const navigationStartRef = useRef<number>(0); // Track when navigation started for safety timeout\n const lastNavigationIndexRef = useRef<number>(-1); // Prevent duplicate navigations to same index\n const lastNavigationTimeRef = useRef<number>(0); // Cooldown between navigations\n\n useEffect(() => {\n // Clamp index when items change\n const clamped = clamp(index, 0, Math.max(items.length - 1, 0));\n if (!isControlled) setInternalIndex(clamped);\n }, [index, isControlled, items.length]);\n\n const virtualizer = useVirtualizer({\n items,\n virtual: virtualCfg,\n getScrollElement: useCallback(() => viewport, [viewport]),\n orientation,\n });\n\n // Stabilize callbacks using a ref for latest state\n const latest = useRef({\n index,\n items,\n isControlled,\n options,\n virtualizer,\n loop,\n orientation,\n setInternalIndex,\n setIsAnimating,\n viewport, // Add viewport to latest ref\n });\n\n // Update ref on every render\n latest.current = {\n index,\n items,\n isControlled,\n options,\n virtualizer,\n loop,\n orientation,\n setInternalIndex,\n setIsAnimating,\n viewport,\n };\n\n const applyIndexChange = useCallback(\n (nextIndex: number) => {\n const { index, isControlled, options, setInternalIndex, setIsAnimating } = latest.current;\n if (nextIndex === index) {\n // Already at this index, no need to update\n return;\n }\n console.log('[SwipeDeck] applyIndexChange (from scroll)', { from: index, to: nextIndex, source: sourceRef.current });\n if (!isControlled) setInternalIndex(nextIndex);\n options.onIndexChange?.(nextIndex, sourceRef.current ?? \"snap\");\n setIsAnimating(false);\n sourceRef.current = \"snap\";\n },\n []\n );\n\n\n const navigateTo = useCallback(\n (targetIndex: number, source: IndexChangeSource, behavior?: ScrollBehavior) => {\n const { items, loop, index, isControlled, options, orientation, virtualizer, setInternalIndex, viewport } = latest.current;\n\n if (items.length === 0) return;\n const maxIndex = items.length - 1;\n let next = targetIndex;\n if (loop) {\n next = (next + items.length) % items.length;\n } else {\n next = clamp(next, 0, maxIndex);\n }\n\n // Don't navigate to same index unless it's a snap/correction\n if (next === index && source !== \"snap\") return;\n\n const now = Date.now();\n\n // Safety reset: Clear stuck navigation state if it's been too long (600ms)\n // This prevents isNavigatingRef from permanently blocking navigation\n if (isNavigatingRef.current && now - navigationStartRef.current > 600) {\n console.warn('[SwipeDeck] Clearing stuck navigation state');\n isNavigatingRef.current = false;\n }\n\n // Block ALL navigation while one is in progress (except snap corrections and programmatic)\n if (isNavigatingRef.current && source !== \"snap\" && source !== \"programmatic\") {\n console.log('[SwipeDeck] navigateTo blocked: isNavigating', { source, targetIndex: next });\n return;\n }\n\n // Minimum cooldown between ANY navigations (prevents multi-swipe)\n // Programmatic navigation bypasses cooldown since it's explicit API usage\n const MIN_NAVIGATION_COOLDOWN = 250;\n if (now - lastNavigationTimeRef.current < MIN_NAVIGATION_COOLDOWN && source !== \"snap\" && source !== \"programmatic\") {\n console.log('[SwipeDeck] navigateTo blocked: cooldown', { source, targetIndex: next, timeSinceLastNav: now - lastNavigationTimeRef.current });\n return;\n }\n\n console.log('[SwipeDeck] navigateTo executing', { source, from: index, to: next });\n\n lastNavigationIndexRef.current = next;\n lastNavigationTimeRef.current = now;\n\n sourceRef.current = source;\n\n // Mark as navigating to prevent handleScroll from interfering\n isNavigatingRef.current = true;\n\n // Update index immediately\n if (!isControlled) setInternalIndex(next);\n console.log('[SwipeDeck] calling onIndexChange', { next, source });\n options.onIndexChange?.(next, source);\n\n if (!viewport) {\n console.warn('[SwipeDeck] No viewport, skipping scroll');\n return;\n }\n\n // Clear any pending snap restore timeout\n if (snapRestoreTimeoutRef.current) {\n clearTimeout(snapRestoreTimeoutRef.current);\n snapRestoreTimeoutRef.current = null;\n }\n\n // CRITICAL: Temporarily disable scroll-snap during programmatic navigation\n // This prevents CSS from fighting with our scroll position\n viewport.style.scrollSnapType = 'none';\n viewport.style.scrollBehavior = 'auto';\n\n // Use instant scroll for wheel and programmatic navigation to avoid timing issues\n // Smooth scroll can cause scrollend to fire late, keeping isNavigatingRef stuck\n // Only gestures get smooth scroll since they have visual drag feedback\n const targetBehavior = behavior ?? (\n source === \"user:wheel\" || source === \"programmatic\" || prefersReducedMotion() ? \"instant\" : \"smooth\"\n );\n\n // Manual scroll calculation\n const targetScroll = next * virtualizer.containerSize;\n console.log('[SwipeDeck] scrolling to', { targetScroll, containerSize: virtualizer.containerSize, next, behavior: targetBehavior });\n\n // Track navigation start time for safety timeout\n navigationStartRef.current = Date.now();\n\n if (orientation === 'vertical') {\n viewport.scrollTo({ top: targetScroll, behavior: targetBehavior });\n // For instant scroll, verify scroll position immediately\n if (targetBehavior === 'instant') {\n console.log('[SwipeDeck] after scrollTo', { targetScroll, actualScroll: viewport.scrollTop });\n }\n } else {\n viewport.scrollTo({ left: targetScroll, behavior: targetBehavior });\n if (targetBehavior === 'instant') {\n console.log('[SwipeDeck] after scrollTo', { targetScroll, actualScroll: viewport.scrollLeft });\n }\n }\n\n // Handler to restore scroll-snap after navigation completes\n const handleScrollEnd = () => {\n console.log('[SwipeDeck] handleScrollEnd - clearing navigation lock');\n isNavigatingRef.current = false;\n if (snapRestoreTimeoutRef.current) {\n clearTimeout(snapRestoreTimeoutRef.current);\n snapRestoreTimeoutRef.current = null;\n }\n if (viewport) {\n viewport.style.scrollSnapType = orientation === 'vertical' ? 'y mandatory' : 'x mandatory';\n }\n };\n\n // Use scrollend event if available (modern browsers), with fallback timeout\n if ('onscrollend' in window) {\n const scrollEndHandler = () => {\n handleScrollEnd();\n viewport.removeEventListener('scrollend', scrollEndHandler);\n };\n viewport.addEventListener('scrollend', scrollEndHandler, { once: true });\n // Safety fallback in case scrollend never fires (reduced from 800ms to 400ms)\n snapRestoreTimeoutRef.current = setTimeout(() => {\n viewport.removeEventListener('scrollend', scrollEndHandler);\n handleScrollEnd();\n }, 400);\n } else {\n // Fallback for browsers without scrollend support\n const restoreDelay = targetBehavior === 'smooth' ? 500 : 50;\n snapRestoreTimeoutRef.current = setTimeout(handleScrollEnd, restoreDelay);\n }\n },\n []\n );\n\n const onDragStart = useCallback(() => {\n const { viewport, orientation } = latest.current;\n if (viewport) {\n // Optimization: Force auto behavior immediately on drag start\n viewport.style.scrollBehavior = 'auto';\n dragStartScrollRef.current = orientation === \"vertical\" ? viewport.scrollTop : viewport.scrollLeft;\n }\n }, []);\n\n const onDrag = useCallback((delta: number) => {\n const { viewport, orientation } = latest.current;\n if (viewport) {\n const newScroll = dragStartScrollRef.current - delta;\n if (orientation === \"vertical\") {\n viewport.scrollTop = newScroll;\n } else {\n viewport.scrollLeft = newScroll;\n }\n }\n }, []);\n\n // Calculate target index from current scroll position (for snap correction)\n const getSnapTargetIndex = useCallback(() => {\n const { viewport, orientation, items, virtualizer } = latest.current;\n if (!viewport || items.length === 0) return latest.current.index;\n\n const scrollOffset = orientation === \"vertical\" ? viewport.scrollTop : viewport.scrollLeft;\n const itemSize = virtualizer.containerSize || viewport.clientHeight;\n\n if (itemSize <= 0) return latest.current.index;\n\n const targetIndex = Math.round(scrollOffset / itemSize);\n return clamp(targetIndex, 0, items.length - 1);\n }, []);\n\n const wheel = useWheel({\n orientation,\n direction,\n discretePaging: wheelCfg.discretePaging ?? true,\n threshold: wheelCfg.threshold ?? 80,\n debounce: wheelCfg.debounce ?? 120,\n cooldown: wheelCfg.cooldown ?? 400,\n onRequestIndexChange: delta => navigateTo(latest.current.index + delta, \"user:wheel\"),\n viewport,\n onDragStart,\n onDrag,\n onDragEnd: () => {\n // Calculate correct target from scroll position, not from state\n const targetIndex = getSnapTargetIndex();\n navigateTo(targetIndex, \"snap\");\n },\n });\n\n const gestures = useGestures({\n orientation,\n direction,\n threshold: gestureCfg.threshold ?? 50,\n flickVelocity: gestureCfg.flickVelocity ?? 0.5,\n lockAxis: gestureCfg.lockAxis ?? true,\n ignoreWhileAnimating: gestureCfg.ignoreWhileAnimating ?? true,\n loop,\n getIndex: () => latest.current.index,\n maxIndex: Math.max(items.length - 1, 0),\n onRequestIndexChange: next => navigateTo(next, \"user:gesture\"),\n setAnimating: setIsAnimating,\n isAnimating,\n onDragStart,\n onDrag,\n });\n\n const keyboard = useKeyboard({\n orientation,\n direction,\n config: keyboardNavigation ? keyboardCfg : { enabled: false },\n onPrev: () => navigateTo(latest.current.index - 1, \"user:keyboard\"),\n onNext: () => navigateTo(latest.current.index + 1, \"user:keyboard\"),\n onFirst: () => navigateTo(0, \"user:keyboard\"),\n onLast: () => navigateTo(items.length - 1, \"user:keyboard\"),\n });\n\n // Calculate visibility based on scroll\n const rafId = useRef<number | null>(null);\n const scrollEndTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const handleScroll = useCallback(() => {\n // Safety: Force unlock if navigation has been stuck for too long (1.5 seconds)\n if (isNavigatingRef.current && Date.now() - navigationStartRef.current > 1500) {\n isNavigatingRef.current = false;\n console.warn('[SwipeDeck] Navigation lock timeout - forcing unlock');\n }\n\n // Skip scroll-based index calculation during programmatic navigation\n if (isNavigatingRef.current) return;\n\n // Safety Snap: If scrolling stops and we are misaligned, snap to current index\n if (scrollEndTimeoutRef.current) clearTimeout(scrollEndTimeoutRef.current);\n scrollEndTimeoutRef.current = setTimeout(() => {\n if (isNavigatingRef.current) return;\n const { viewport, orientation, index } = latest.current;\n if (!viewport) return;\n\n const scrollOffset = orientation === \"vertical\" ? viewport.scrollTop : viewport.scrollLeft;\n const computedSize = orientation === \"vertical\" ? viewport.clientHeight : viewport.clientWidth;\n const idealOffset = index * computedSize;\n\n // Use device pixel ratio for tolerance to handle high-DPI displays\n const dpr = typeof window !== 'undefined' ? window.devicePixelRatio : 1;\n const tolerance = Math.max(5, Math.ceil(5 * dpr));\n if (Math.abs(scrollOffset - idealOffset) > tolerance) {\n // We are stuck between frames. Snap to the current detected index.\n viewport.scrollTo({\n top: orientation === \"vertical\" ? idealOffset : 0,\n left: orientation === \"horizontal\" ? idealOffset : 0,\n behavior: 'smooth'\n });\n }\n }, 150); // 150ms debounce for \"scroll end\"\n\n if (rafId.current !== null) return;\n\n rafId.current = requestAnimationFrame(() => {\n rafId.current = null;\n\n // Double-check we're not navigating\n if (isNavigatingRef.current) return;\n\n const { viewport, orientation, items } = latest.current;\n if (!viewport) return;\n\n const scrollOffset = orientation === \"vertical\" ? viewport.scrollTop : viewport.scrollLeft;\n const viewportSize = orientation === \"vertical\" ? viewport.clientHeight : viewport.clientWidth;\n\n // Simple geometric calculation - works with CSS viewport units\n // Each item is 100dvh tall, so index = scrollOffset / viewportSize\n if (viewportSize > 0 && items.length > 0) {\n const estimatedIndex = Math.round(scrollOffset / viewportSize);\n const newIndex = clamp(estimatedIndex, 0, items.length - 1);\n // Only log if index would change\n if (newIndex !== latest.current.index) {\n console.log('[SwipeDeck] handleScroll calculated index', { scrollOffset, viewportSize, estimatedIndex, newIndex, currentIndex: latest.current.index });\n }\n applyIndexChange(newIndex);\n }\n });\n }, [applyIndexChange]); // applyIndexChange is stable now\n\n // onEndReached\n useEffect(() => {\n if (items.length === 0) return;\n const maxIndex = items.length - 1;\n const distanceFromEnd = maxIndex - index;\n if (distanceFromEnd <= endReachedThreshold) {\n options.onEndReached?.({ distanceFromEnd, direction: \"forward\" });\n }\n if (index <= endReachedThreshold) {\n options.onEndReached?.({ distanceFromEnd: index, direction: \"backward\" });\n }\n }, [endReachedThreshold, index, items.length, options]);\n\n const scrollBehavior = useMemo(\n () => (prefersReducedMotion() ? \"instant\" : \"smooth\"),\n [],\n );\n\n const scrollTo = useCallback(\n (target: number, opts?: { behavior?: ScrollBehavior }) => {\n navigateTo(target, \"programmatic\", opts?.behavior ?? scrollBehavior);\n },\n [navigateTo, scrollBehavior],\n );\n\n const apiState: SwipeDeckState = useMemo(\n () => ({\n index,\n isAnimating,\n canPrev: loop || index > 0,\n canNext: loop || index < items.length - 1,\n }),\n [index, isAnimating, items.length, loop],\n );\n\n // ═══════════════════════════════════════════════════════════════════════════\n // RESIZE HANDLING: Scroll Position Correction\n // ═══════════════════════════════════════════════════════════════════════════\n // CSS viewport units handle item sizing automatically.\n // But scroll position (in pixels) becomes invalid on resize.\n // We use the current index state to correct scroll position after resize settles.\n const resizeTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n useEffect(() => {\n if (!viewport) return;\n\n const handleResize = () => {\n // Clear any pending correction\n if (resizeTimeoutRef.current) {\n clearTimeout(resizeTimeoutRef.current);\n }\n\n // After resize settles, snap scroll to current index\n resizeTimeoutRef.current = setTimeout(() => {\n const { orientation, index: currentIndex } = latest.current;\n if (!viewport) return;\n\n const size = orientation === 'vertical' ? viewport.clientHeight : viewport.clientWidth;\n const targetScroll = currentIndex * size;\n\n // Only correct if significantly off (avoid fighting with scroll-snap)\n const currentScroll = orientation === 'vertical' ? viewport.scrollTop : viewport.scrollLeft;\n if (Math.abs(currentScroll - targetScroll) > size * 0.1) {\n if (orientation === 'vertical') {\n viewport.scrollTop = targetScroll;\n } else {\n viewport.scrollLeft = targetScroll;\n }\n }\n }, 50);\n };\n\n const resizeObserver = new ResizeObserver(handleResize);\n resizeObserver.observe(viewport);\n\n return () => {\n resizeObserver.disconnect();\n if (resizeTimeoutRef.current) {\n clearTimeout(resizeTimeoutRef.current);\n }\n };\n }, [viewport]);\n\n // Re-enable scroll-snap when user touches the screen\n const handleTouchStart = useCallback(() => {\n const { viewport, orientation } = latest.current;\n if (viewport) {\n viewport.style.scrollSnapType = orientation === 'vertical' ? 'y mandatory' : 'x mandatory';\n }\n }, []);\n\n const getViewportProps = useCallback(() => {\n const virtualStyles: React.CSSProperties = {\n position: \"relative\",\n overflow: \"auto\",\n // Native Scroll Snap - handles touch swipe automatically\n scrollSnapType: orientation === \"vertical\" ? \"y mandatory\" : \"x mandatory\",\n // Allow native touch scrolling - this works with scroll-snap for smooth swipe experience\n touchAction: orientation === \"vertical\" ? \"pan-y\" : \"pan-x\",\n willChange: \"scroll-position\",\n };\n\n return {\n ref: setViewport,\n role: \"feed\",\n \"aria-label\": ariaLabel,\n \"aria-busy\": isAnimating,\n tabIndex: 0,\n onScroll: handleScroll,\n // onWheel: wheel.onWheel, // REMOVED: Managed internally by useWheel\n onKeyDown: keyboard.onKeyDown,\n onTouchStart: handleTouchStart,\n ...gestures.handlers,\n style: virtualStyles,\n } satisfies React.HTMLAttributes<HTMLElement> & { ref: React.RefCallback<HTMLElement> };\n }, [ariaLabel, handleScroll, handleTouchStart, isAnimating, keyboard.onKeyDown, orientation, gestures.handlers]);\n\n const getItemProps = useCallback(\n (itemIndex: number) => {\n const isActive = index === itemIndex;\n\n // Use CSS viewport units for positioning - these automatically update on rotation!\n // This is much simpler and more reliable than trying to correct pixel offsets.\n const sizeUnit = orientation === 'vertical' ? '100dvh' : '100dvw';\n\n return {\n ref: undefined,\n \"data-index\": itemIndex,\n \"data-active\": isActive,\n style: {\n position: \"absolute\" as const,\n top: 0,\n left: 0,\n // Use CSS calc with viewport units - browser handles rotation automatically!\n transform: orientation === 'vertical'\n ? `translateY(calc(${itemIndex} * ${sizeUnit}))`\n : `translateX(calc(${itemIndex} * ${sizeUnit}))`,\n height: orientation === 'vertical' ? sizeUnit : '100%',\n width: orientation === 'horizontal' ? sizeUnit : '100%',\n willChange: \"transform\",\n // Native Snap Item Styles\n scrollSnapAlign: \"start\",\n scrollSnapStop: \"always\" satisfies React.CSSProperties[\"scrollSnapStop\"],\n } satisfies React.CSSProperties,\n };\n },\n [index, orientation],\n );\n\n const prev = useCallback(() => navigateTo(latest.current.index - 1, \"programmatic\"), [navigateTo]);\n const next = useCallback(() => navigateTo(latest.current.index + 1, \"programmatic\"), [navigateTo]);\n\n const api: SwipeDeckAPI<T> = useMemo(() => ({\n ...apiState,\n prev,\n next,\n scrollTo: (target, opts) => navigateTo(target, \"programmatic\", opts?.behavior),\n getViewportProps,\n getItemProps,\n virtualItems: virtualizer.virtualItems,\n totalSize: virtualizer.totalSize,\n items,\n orientation,\n viewport,\n }), [apiState, prev, next, navigateTo, getViewportProps, getItemProps, virtualizer.virtualItems, virtualizer.totalSize, items, orientation, viewport]);\n\n return api;\n}\n",
|
|
6
|
-
"export function clamp(value: number, min: number, max: number): number {\n if (Number.isNaN(value)) return min;\n return Math.min(Math.max(value, min), max);\n}\n\n",
|
|
7
|
-
"let cached: boolean | null = null;\n\nexport function prefersReducedMotion(): boolean {\n if (cached !== null) return cached;\n if (typeof window === \"undefined\" || typeof window.matchMedia !== \"function\") {\n cached = false;\n return cached;\n }\n cached = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n return cached;\n}\n\n",
|
|
8
|
-
"import { useCallback, useRef, useState, useMemo } from \"react\";\nimport { clamp } from \"../utils/clamp\";\nimport type { Direction, Orientation } from \"../types\";\n\ntype GestureState = {\n isDragging: boolean;\n start: number;\n last: number;\n delta: number;\n startTime: number;\n};\n\ntype UseGesturesParams = {\n orientation: Orientation;\n direction: Direction;\n threshold: number;\n flickVelocity: number;\n lockAxis: boolean;\n ignoreWhileAnimating: boolean;\n loop: boolean;\n getIndex: () => number;\n maxIndex: number;\n onRequestIndexChange: (nextIndex: number) => void;\n setAnimating: (value: boolean) => void;\n isAnimating: boolean;\n onDragStart?: (evt: React.PointerEvent) => void;\n onDrag?: (delta: number, evt: React.PointerEvent) => void;\n onDragEnd?: () => void;\n};\n\nfunction primaryCoord(evt: PointerEvent | React.PointerEvent, orientation: Orientation) {\n return orientation === \"vertical\" ? evt.clientY : evt.clientX;\n}\n\n/**\n * Pointer/touch gestures (drag + flick). Mirrors the spec:\n * IDLE -> DRAGGING -> SETTLING with threshold + velocity decision.\n */\nexport function useGestures(params: UseGesturesParams) {\n const {\n orientation,\n direction,\n threshold,\n flickVelocity,\n lockAxis,\n ignoreWhileAnimating,\n loop,\n getIndex,\n maxIndex,\n onRequestIndexChange,\n setAnimating,\n isAnimating,\n onDragStart,\n onDrag,\n onDragEnd,\n } = params;\n\n const [isDragging, setIsDragging] = useState(false);\n const state = useRef<GestureState>({\n isDragging: false,\n start: 0,\n last: 0,\n delta: 0,\n startTime: 0,\n });\n\n const startDrag = useCallback((evt: React.PointerEvent) => {\n evt.currentTarget.setPointerCapture?.(evt.pointerId);\n const coord = primaryCoord(evt, orientation);\n state.current = {\n isDragging: true,\n start: coord,\n last: coord,\n delta: 0,\n startTime: performance.now(),\n };\n setIsDragging(true);\n onDragStart?.(evt);\n }, [orientation, onDragStart]);\n\n const updateDrag = useCallback((evt: React.PointerEvent) => {\n if (!state.current.isDragging) return;\n\n const coord = primaryCoord(evt, orientation);\n const delta = coord - state.current.start;\n state.current.delta = delta;\n state.current.last = coord;\n onDrag?.(delta, evt);\n }, [orientation, onDrag]);\n\n const endDrag = useCallback(() => {\n if (!state.current.isDragging) return;\n\n const now = performance.now();\n const duration = Math.max(now - state.current.startTime, 1);\n const distance = Math.abs(state.current.delta);\n const velocity = distance / duration; // px/ms\n\n const isForward = (() => {\n const raw = state.current.delta;\n if (orientation === \"vertical\") return raw < 0;\n // horizontal respects text direction\n const normalized = direction === \"rtl\" ? raw * -1 : raw;\n return normalized < 0;\n })();\n\n const current = getIndex();\n const deltaSign = isForward ? 1 : -1;\n const meetsFlick = velocity > flickVelocity;\n const meetsDistance = distance > threshold;\n\n let next = current;\n if (meetsFlick || meetsDistance) {\n next = current + deltaSign;\n }\n\n if (loop) {\n next = (next + (maxIndex + 1)) % (maxIndex + 1);\n } else {\n next = clamp(next, 0, maxIndex);\n }\n\n setAnimating(true);\n onRequestIndexChange(next);\n\n state.current.isDragging = false;\n state.current.delta = 0;\n setIsDragging(false);\n onDragEnd?.();\n }, [direction, flickVelocity, getIndex, maxIndex, onRequestIndexChange, orientation, loop, setAnimating, threshold, onDragEnd]);\n\n const cancelDrag = useCallback(() => {\n state.current.isDragging = false;\n state.current.delta = 0;\n setIsDragging(false);\n }, []);\n\n const onPointerDown = useCallback((evt: React.PointerEvent) => {\n if (ignoreWhileAnimating && isAnimating) return;\n if (evt.button !== 0) return;\n startDrag(evt);\n }, [ignoreWhileAnimating, isAnimating, startDrag]);\n\n const onPointerMove = useCallback((evt: React.PointerEvent) => {\n if (!lockAxis && !state.current.isDragging) return;\n if (state.current.isDragging) {\n updateDrag(evt);\n }\n }, [lockAxis, updateDrag]);\n\n const onPointerUp = useCallback(() => {\n endDrag();\n }, [endDrag]);\n\n const onPointerCancel = useCallback(() => {\n cancelDrag();\n }, [cancelDrag]);\n\n return useMemo(() => ({\n isDragging,\n handlers: { onPointerDown, onPointerMove, onPointerUp, onPointerCancel },\n }), [isDragging, onPointerDown, onPointerMove, onPointerUp, onPointerCancel]);\n}\n\n",
|
|
9
|
-
"import { useCallback, useRef, useEffect } from \"react\";\nimport type { Direction, Orientation } from \"../types\";\n\nexport type UseWheelParams = {\n orientation: Orientation;\n direction: Direction;\n discretePaging: boolean;\n threshold: number;\n debounce: number;\n cooldown?: number; // Cooldown period after navigation (ms)\n onRequestIndexChange: (delta: 1 | -1) => void;\n viewport: HTMLElement | null;\n onDragStart?: () => void;\n onDrag?: (delta: number) => void;\n onDragEnd?: () => void;\n};\n\n/**\n * Wheel handler supporting discrete paging (TikTok-like) or continuous tracking.\n * \n * Aggressively prevents multi-video scrolling:\n * - Long cooldown period after each navigation\n * - Capped delta per event to prevent large jumps (smooths jerky mouse wheels)\n * - Direction locking during a scroll gesture\n */\nexport function useWheel(params: UseWheelParams) {\n const {\n orientation,\n direction,\n discretePaging,\n threshold,\n debounce,\n cooldown = 500,\n onRequestIndexChange,\n viewport,\n onDragStart,\n onDrag,\n onDragEnd,\n } = params;\n\n const accumulated = useRef(0);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const lastNavigationTime = useRef(0);\n const isInCooldown = useRef(false);\n const lastEventTime = useRef(0);\n const gestureDirection = useRef<1 | -1 | null>(null);\n const eventCount = useRef(0);\n const isTracking = useRef(false);\n const velocityRef = useRef(0);\n\n // Maximum delta per single wheel event for ACCUMULATION (triggering the swap)\n // We allow a reasonable amount so fast scrolls work, but dampen insane values\n const MAX_DELTA_ACCUMULATION = 120;\n\n // Maximum delta per single wheel event for VISUAL DRAG\n // This is the key to fixing \"jerky\" mouse wheel.\n // If we receive a 100px mouse wheel event, we clamp the visual drag to ~30px\n // so it looks like a smooth nudge rather than a teleport.\n // Continuous trackpad events (usually < 20px) pass through untouched.\n const MAX_VISUAL_DELTA = 40;\n\n const endGesture = useCallback(() => {\n isTracking.current = false;\n accumulated.current = 0;\n gestureDirection.current = null;\n eventCount.current = 0;\n velocityRef.current = 0;\n onDragEnd?.();\n }, [onDragEnd]);\n\n const resetAccumulated = useCallback(() => {\n if (timeoutRef.current) clearTimeout(timeoutRef.current);\n timeoutRef.current = setTimeout(() => {\n endGesture();\n }, debounce);\n }, [debounce, endGesture]);\n\n useEffect(() => {\n const element = viewport;\n if (!element) return;\n\n const onWheel = (evt: WheelEvent) => {\n if (!discretePaging) return;\n\n evt.preventDefault();\n evt.stopPropagation();\n\n const now = performance.now();\n\n // Strict cooldown check - during cooldown, ignore events WITHOUT triggering snap\n if (isInCooldown.current) {\n if (now - lastNavigationTime.current < cooldown) {\n // Reset tracking state WITHOUT calling onDragEnd (which triggers snap navigation)\n // We don't want snap to fight with the navigation that just happened\n if (isTracking.current) {\n console.log('[useWheel] Ignoring wheel event during cooldown');\n isTracking.current = false;\n accumulated.current = 0;\n gestureDirection.current = null;\n eventCount.current = 0;\n velocityRef.current = 0;\n // NOTE: NOT calling onDragEnd here to avoid triggering snap\n }\n return;\n }\n isInCooldown.current = false;\n }\n\n const rawDelta = orientation === \"vertical\" ? evt.deltaY : evt.deltaX;\n // RTL flips horizontal direction\n const adjusted = orientation === \"horizontal\" && direction === \"rtl\" ? -rawDelta : rawDelta;\n\n // Determine scroll direction\n const currentDirection: 1 | -1 = adjusted > 0 ? 1 : -1;\n\n // Direction locking: reset if direction changes\n if (gestureDirection.current !== null && gestureDirection.current !== currentDirection) {\n accumulated.current = 0;\n eventCount.current = 0;\n }\n gestureDirection.current = currentDirection;\n\n if (!isTracking.current) {\n isTracking.current = true;\n onDragStart?.();\n }\n\n // Calculate time since last event\n const timeDelta = now - lastEventTime.current;\n lastEventTime.current = now;\n eventCount.current++;\n\n // 1. Calculate delta for ACCUMULATION (Threshold Check)\n // Allow fairly large steps so mouse wheel (100) triggers threshold quickly if repeated\n const accumDelta = Math.sign(adjusted) * Math.min(Math.abs(adjusted), MAX_DELTA_ACCUMULATION);\n\n // 2. Calculate delta for VISUAL DRAG (Smoothing)\n // Cap at MAX_VISUAL_DELTA so 100px jumps become 40px nudges\n const visualDelta = Math.sign(adjusted) * Math.min(Math.abs(adjusted), MAX_VISUAL_DELTA);\n\n // Flick detection velocity\n const instantVelocity = (timeDelta > 0 && timeDelta < 100) ? Math.abs(accumDelta / timeDelta) : 0;\n velocityRef.current = velocityRef.current * 0.8 + instantVelocity * 0.2;\n\n accumulated.current += accumDelta;\n\n // Visual Tracking: Move the slide, but smoothed\n onDrag?.(-visualDelta);\n\n resetAccumulated();\n\n const matchesThreshold = Math.abs(accumulated.current) >= threshold;\n const isFlick = velocityRef.current > 1.2 && Math.abs(accumulated.current) > 20;\n\n if (matchesThreshold || isFlick) {\n const navDelta: 1 | -1 = accumulated.current > 0 ? 1 : -1;\n\n console.log('[useWheel] Navigation triggered', {\n navDelta,\n accumulated: accumulated.current,\n threshold,\n matchesThreshold,\n isFlick,\n velocity: velocityRef.current,\n });\n\n // Reset tracking state without calling onDragEnd\n // onDragEnd is for when gesture ends WITHOUT navigation (snap back)\n // Here we ARE navigating, so we skip onDragEnd to avoid a competing snap navigation\n isTracking.current = false;\n accumulated.current = 0;\n gestureDirection.current = null;\n eventCount.current = 0;\n velocityRef.current = 0;\n\n lastNavigationTime.current = now;\n isInCooldown.current = true;\n if (timeoutRef.current) clearTimeout(timeoutRef.current);\n\n onRequestIndexChange(navDelta);\n }\n };\n\n element.addEventListener(\"wheel\", onWheel, { passive: false });\n\n return () => {\n element.removeEventListener(\"wheel\", onWheel);\n if (timeoutRef.current) clearTimeout(timeoutRef.current);\n };\n }, [\n orientation,\n direction,\n discretePaging,\n threshold,\n // debounce, // REMOVED: Used in resetAccumulated, not here directly\n cooldown,\n onRequestIndexChange,\n resetAccumulated,\n viewport,\n onDragStart,\n onDrag\n ]);\n}\n",
|
|
10
|
-
"import type React from \"react\";\nimport { useCallback, useEffect } from \"react\";\nimport type { Direction, KeyboardConfig, Orientation } from \"../types\";\n\ntype UseKeyboardParams = {\n orientation: Orientation;\n direction: Direction;\n config?: KeyboardConfig;\n onPrev: () => void;\n onNext: () => void;\n onFirst?: () => void;\n onLast?: () => void;\n};\n\nconst DEFAULT_BINDINGS_VERTICAL = {\n prev: [\"ArrowUp\"],\n next: [\"ArrowDown\"],\n first: [\"Home\"],\n last: [\"End\"],\n altPrev: [\"PageUp\"],\n altNext: [\"PageDown\"],\n};\n\nconst DEFAULT_BINDINGS_HORIZONTAL = {\n prev: [\"ArrowLeft\"],\n next: [\"ArrowRight\"],\n first: [\"Home\"],\n last: [\"End\"],\n altPrev: [\"PageUp\"],\n altNext: [\"PageDown\"],\n};\n\n/**\n * Keyboard navigation: arrow keys, Home/End, PageUp/PageDown.\n */\nexport function useKeyboard(params: UseKeyboardParams) {\n const { orientation, direction, config, onPrev, onNext, onFirst, onLast } = params;\n\n const enabled = config?.enabled ?? true;\n const isGlobal = config?.global ?? false;\n const bindings = config?.bindings ?? (orientation === \"vertical\" ? DEFAULT_BINDINGS_VERTICAL : DEFAULT_BINDINGS_HORIZONTAL);\n\n const handleKeyDown = useCallback(\n (evt: KeyboardEvent | React.KeyboardEvent) => {\n if (!enabled) return;\n\n const key = evt.key;\n\n const prevKeys = [...(bindings.prev ?? []), ...(bindings.altPrev ?? [])];\n const nextKeys = [...(bindings.next ?? []), ...(bindings.altNext ?? [])];\n\n const isHorizontal = orientation === \"horizontal\";\n const rtl = direction === \"rtl\";\n\n if (prevKeys.includes(key)) {\n evt.preventDefault();\n if (isHorizontal && rtl) onNext();\n else onPrev();\n return;\n }\n\n if (nextKeys.includes(key)) {\n evt.preventDefault();\n if (isHorizontal && rtl) onPrev();\n else onNext();\n return;\n }\n\n if (bindings.first?.includes(key)) {\n evt.preventDefault();\n onFirst?.();\n return;\n }\n\n if (bindings.last?.includes(key)) {\n evt.preventDefault();\n onLast?.();\n return;\n }\n },\n [bindings, direction, enabled, onFirst, onLast, onNext, onPrev, orientation],\n );\n\n // Global listener support\n useEffect(() => {\n if (!enabled || !isGlobal) return;\n\n window.addEventListener(\"keydown\", handleKeyDown);\n return () => {\n window.removeEventListener(\"keydown\", handleKeyDown);\n };\n }, [enabled, isGlobal, handleKeyDown]);\n\n return { onKeyDown: handleKeyDown };\n}\n\n",
|
|
11
|
-
"import { useEffect, useLayoutEffect, useState, useMemo, useCallback } from \"react\";\nimport { useVirtualizer as useTanStackVirtualizer } from \"@tanstack/react-virtual\";\nimport type { VirtualConfig, SwipeDeckVirtualItem, Orientation } from \"../types\";\n\n// Use useLayoutEffect on client, useEffect on server (SSR safety)\nconst useIsomorphicLayoutEffect = typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\ntype UseVirtualizerParams<T> = {\n items: readonly T[];\n virtual: VirtualConfig | undefined;\n getScrollElement: () => HTMLElement | null;\n orientation?: Orientation;\n};\n\ntype VirtualizerResult = {\n virtualItems: SwipeDeckVirtualItem[];\n totalSize: number;\n getItemOffset: (index: number) => number;\n getItemSize: (index: number) => number;\n scrollToIndex: (index: number, options?: { align?: 'start' | 'center' | 'end' | 'auto', behavior?: 'auto' | 'smooth' }) => void;\n containerSize: number;\n};\n\n/**\n * Simplified adapter using @tanstack/react-virtual\n * Auto-detects viewport size when estimatedSize is not provided.\n */\nexport function useVirtualizer<T>(params: UseVirtualizerParams<T>): VirtualizerResult {\n const { items, virtual, getScrollElement, orientation = \"vertical\" } = params;\n const count = items.length;\n\n // Auto-detect viewport size when estimatedSize is not provided\n // Use state with a \"generation\" counter to force re-render when element is measured\n const [sizeState, setSizeState] = useState<{ size: number; measured: boolean }>(() => {\n // Initial fallback: use window size if available, else 800\n const fallback = typeof window !== \"undefined\"\n ? (orientation === \"vertical\" ? window.innerHeight : window.innerWidth)\n : 800;\n return { size: fallback, measured: false };\n });\n\n // Use useLayoutEffect to measure BEFORE paint - this fixes the black screen on initial load\n useIsomorphicLayoutEffect(() => {\n const scrollElement = getScrollElement();\n if (!scrollElement) return;\n\n const updateSize = () => {\n const size = orientation === \"vertical\"\n ? scrollElement.clientHeight\n : scrollElement.clientWidth;\n\n if (size > 0) {\n setSizeState(prev => {\n // Only update if size changed or first measurement\n if (prev.size !== size || !prev.measured) {\n return { size, measured: true };\n }\n return prev;\n });\n }\n };\n\n // Measure immediately (synchronously before paint)\n updateSize();\n\n // Watch for resizes\n const resizeObserver = new ResizeObserver(updateSize);\n resizeObserver.observe(scrollElement);\n\n return () => {\n resizeObserver.disconnect();\n };\n }, [getScrollElement, orientation]);\n\n const measuredSize = sizeState.size;\n\n // Always prioritize measured size for consistency - explicit estimatedSize is only used\n // if it's a function (for dynamic item sizes) or if we haven't measured yet\n const getEstimatedSize = useCallback((i: number): number => {\n const explicitSize = virtual?.estimatedSize;\n\n // If explicit size is a function, use it (supports dynamic item sizing)\n if (typeof explicitSize === 'function') {\n return explicitSize(items[i], i);\n }\n\n // Use measured size if available and valid, otherwise fall back to explicit or default\n if (measuredSize > 0) {\n return measuredSize;\n }\n\n // Fall back to explicit size or default\n return typeof explicitSize === 'number' ? explicitSize : 800;\n }, [virtual?.estimatedSize, items, measuredSize]);\n\n // Compute initialRect from window size for first render (before scroll element is available)\n const initialRect = useMemo(() => {\n if (typeof window === \"undefined\") {\n return { width: 800, height: 800 };\n }\n return {\n width: window.innerWidth,\n height: window.innerHeight,\n };\n }, []);\n\n // Memoize getItemKey wrapper to prevent infinite re-renders\n const getItemKey = useMemo(() => {\n if (!virtual?.getItemKey) return undefined;\n return (index: number) => virtual.getItemKey?.(items[index], index) ?? index;\n }, [virtual?.getItemKey, items]);\n\n const rowVirtualizer = useTanStackVirtualizer({\n count,\n getScrollElement,\n estimateSize: getEstimatedSize,\n overscan: virtual?.overscan ?? 5,\n horizontal: orientation === \"horizontal\",\n getItemKey,\n // CRITICAL: Provide initialRect so virtualizer can calculate items on first render\n // even when getScrollElement() returns null\n initialRect,\n });\n\n // NOTE: Do NOT wrap this in useMemo! The rowVirtualizer object is stable,\n // but getVirtualItems() returns different results on each scroll event.\n // Wrapping in useMemo causes stale virtualItems that don't update on scroll.\n return {\n virtualItems: rowVirtualizer.getVirtualItems().map(item => ({\n index: item.index,\n key: item.key as string | number,\n offset: item.start,\n size: item.size,\n measureElement: rowVirtualizer.measureElement,\n })),\n totalSize: rowVirtualizer.getTotalSize(),\n getItemOffset: (index: number) => {\n const found = rowVirtualizer.getVirtualItems().find(v => v.index === index);\n return found ? found.start : 0;\n },\n getItemSize: (index: number) => {\n const found = rowVirtualizer.getVirtualItems().find(v => v.index === index);\n return found ? found.size : 0;\n },\n scrollToIndex: (index: number, options?: { align?: 'start' | 'center' | 'end' | 'auto', behavior?: 'auto' | 'smooth' }) => {\n rowVirtualizer.scrollToIndex(index, {\n align: options?.align,\n behavior: options?.behavior,\n });\n },\n containerSize: measuredSize,\n };\n}\n",
|
|
12
|
-
"import { useState, useEffect } from \"react\";\n\nexport function useWindowSize() {\n const [size, setSize] = useState<{ width: number; height: number }>({\n width: typeof window !== \"undefined\" ? window.innerWidth : 0,\n height: typeof window !== \"undefined\" ? window.innerHeight : 0,\n });\n\n useEffect(() => {\n if (typeof window === \"undefined\") return;\n\n let timeoutId: ReturnType<typeof setTimeout>;\n\n const handleResize = () => {\n clearTimeout(timeoutId);\n timeoutId = setTimeout(() => {\n setSize({ width: window.innerWidth, height: window.innerHeight });\n }, 100);\n };\n\n window.addEventListener(\"resize\", handleResize);\n return () => {\n window.removeEventListener(\"resize\", handleResize);\n clearTimeout(timeoutId);\n };\n }, []);\n\n return size;\n}\n",
|
|
13
|
-
"import { createContext, useContext } from 'react';\nimport type { SwipeDeckRenderContext } from '../types';\n\n// biome-ignore lint/suspicious/noExplicitAny: Context defaults to any\nexport const SwipeItemContext = createContext<SwipeDeckRenderContext<any> | undefined>(undefined);\n\n// biome-ignore lint/suspicious/noExplicitAny: Generic defaults to any\nexport function useSwipeItem<T = any>(): SwipeDeckRenderContext<T> {\n const context = useContext(SwipeItemContext);\n if (!context) {\n throw new Error(\"useSwipeItem must be used within a SwipeDeck item\");\n }\n return context;\n}\n",
|
|
14
|
-
"\nimport type React from \"react\";\nimport { useImperativeHandle, useMemo } from \"react\";\nimport { useSwipeDeck } from \"../hooks/useSwipeDeck\";\nimport { SwipeItemContext } from \"../hooks/useSwipeItem\";\nimport type { SwipeDeckHandle, SwipeDeckProps } from \"../types\";\n\nexport function SwipeDeck<T>(\n props: SwipeDeckProps<T> & { ref?: React.Ref<SwipeDeckHandle> },\n) {\n const {\n as: As = \"div\",\n children,\n className,\n style,\n ref,\n ...options\n } = props;\n\n const deck = useSwipeDeck(options);\n\n useImperativeHandle(\n ref,\n () => ({\n prev: deck.prev,\n next: deck.next,\n scrollTo: deck.scrollTo,\n getState: () => ({\n index: deck.index,\n isAnimating: deck.isAnimating,\n canPrev: deck.canPrev,\n canNext: deck.canNext,\n }),\n viewport: deck.viewport,\n }),\n [deck],\n );\n\n const { style: virtualStyle, ...restViewportProps } = deck.getViewportProps();\n\n /* Fullscreen styles if enabled */\n const fullscreenStyle: React.CSSProperties = props.fullscreen\n ? {\n height: \"100dvh\",\n width: \"100%\",\n position: \"absolute\",\n top: 0,\n left: 0,\n }\n : {};\n\n const viewportStyle = useMemo(\n () => ({ ...virtualStyle, ...fullscreenStyle, ...style }),\n [virtualStyle, fullscreenStyle, style],\n );\n\n const contentStyle = useMemo<React.CSSProperties>(\n () => ({\n // Use CSS viewport units for total size - automatically updates on rotation!\n height: deck.orientation === \"vertical\"\n ? `calc(${deck.items.length} * 100dvh)`\n : \"100%\",\n width: deck.orientation === \"horizontal\"\n ? `calc(${deck.items.length} * 100dvw)`\n : \"100%\",\n position: \"relative\",\n }),\n [deck.orientation, deck.items.length],\n );\n\n // Cast As to ElementType to avoid TS issues with polymorphic string/component\n const Comp = As as React.ElementType;\n\n return (\n <Comp\n {...restViewportProps}\n className={className}\n style={viewportStyle}\n >\n <div style={contentStyle}>\n {/* Use virtualItems for windowed rendering - only renders visible + overscan items */}\n {deck.virtualItems.map((virtualItem) => {\n const itemIndex = virtualItem.index;\n const item = deck.items[itemIndex];\n if (!item) return null;\n\n const itemProps = deck.getItemProps(itemIndex);\n const preload = options.preload ?? 0;\n const preloadPrevious = options.preloadPrevious ?? 0;\n\n let shouldPreload = false;\n // Check if we should preload (either next items or previous items)\n if (preload > 0 || preloadPrevious > 0) {\n const currentIndex = deck.index;\n // Log preload calculation for debugging\n if (itemIndex <= currentIndex + preload + 1 && itemIndex >= currentIndex - preloadPrevious - 1) {\n console.log('[SwipeDeck] preload check', { itemIndex, currentIndex, preload, preloadPrevious });\n }\n\n if (!options.loop) {\n // Non-loop: simple index comparison\n const isNext = itemIndex > currentIndex && itemIndex <= currentIndex + preload;\n const isPrev = itemIndex < currentIndex && itemIndex >= currentIndex - preloadPrevious;\n shouldPreload = isNext || isPrev;\n } else {\n // Loop: calculate distance in both directions\n const len = deck.items.length;\n // Forward distance (0 to len-1)\n const forwardDist = (itemIndex - currentIndex + len) % len;\n // Backward distance (0 to len-1)\n const backwardDist = (currentIndex - itemIndex + len) % len;\n\n const isNext = forwardDist > 0 && forwardDist <= preload;\n const isPrev = backwardDist > 0 && backwardDist <= preloadPrevious;\n shouldPreload = isNext || isPrev;\n }\n }\n\n // Don't pass style to children - the article wrapper already handles positioning\n // Children should use inset: 0 to fill the parent\n const { style: _positioningStyle, ...propsWithoutStyle } = itemProps;\n\n const contextValue = {\n item,\n index: itemIndex,\n isActive: deck.index === itemIndex,\n shouldPreload,\n props: propsWithoutStyle,\n };\n\n // Use virtualItem.key for stable keys\n const itemKey = virtualItem.key ?? (options.virtual?.getItemKey?.(item, itemIndex) ?? itemIndex);\n\n return (\n <article\n key={itemKey}\n {...itemProps}\n aria-label={`Item ${itemIndex + 1} of ${deck.items.length}`}\n >\n <SwipeItemContext.Provider value={contextValue}>\n {children(contextValue)}\n </SwipeItemContext.Provider>\n </article>\n );\n })}\n </div>\n </Comp>\n );\n}\n\n"
|
|
15
5
|
],
|
|
16
|
-
"mappings": "AAAA,sBAAS,eAAa,cAAW,YAAS,cAAQ,eCA3C,SAAS,CAAK,CAAC,EAAe,EAAa,EAAqB,CACrE,GAAI,OAAO,MAAM,CAAK,EAAG,OAAO,EAChC,OAAO,KAAK,IAAI,KAAK,IAAI,EAAO,CAAG,EAAG,CAAG,ECF3C,IAAI,GAAyB,KAEtB,SAAS,EAAoB,EAAY,CAC9C,GAAI,KAAW,KAAM,OAAO,GAC5B,GAAI,OAAO,OAAW,KAAe,OAAO,OAAO,aAAe,WAEhE,OADA,GAAS,GACF,GAGT,OADA,GAAS,OAAO,WAAW,kCAAkC,EAAE,QACxD,GCTT,sBAAS,YAAa,eAAQ,cAAU,eA8BxC,SAAS,EAAY,CAAC,EAAwC,EAA0B,CACtF,OAAO,IAAgB,WAAa,EAAI,QAAU,EAAI,QAOjD,SAAS,EAAW,CAAC,EAA2B,CACrD,IACE,cACA,YACA,YACA,gBACA,WACA,uBACA,OACA,WACA,WACA,uBACA,eACA,cACA,cACA,SACA,aACE,GAEG,EAAY,GAAiB,GAAS,EAAK,EAC5C,EAAQ,GAAqB,CACjC,WAAY,GACZ,MAAO,EACP,KAAM,EACN,MAAO,EACP,UAAW,CACb,CAAC,EAEK,EAAY,EAAY,CAAC,IAA4B,CACzD,EAAI,cAAc,oBAAoB,EAAI,SAAS,EACnD,IAAM,EAAQ,GAAa,EAAK,CAAW,EAC3C,EAAM,QAAU,CACd,WAAY,GACZ,MAAO,EACP,KAAM,EACN,MAAO,EACP,UAAW,YAAY,IAAI,CAC7B,EACA,EAAc,EAAI,EAClB,IAAc,CAAG,GAChB,CAAC,EAAa,CA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AAmB,EAE/C,EAAgB,GAEpB,GAAI,EAAU,GAAK,EAAkB,EAAG,CACtC,IAAM,EAAe,EAAK,MAE1B,GAAI,GAAa,EAAe,EAAU,GAAK,GAAa,EAAe,EAAkB,EAC3F,QAAQ,IAAI,4BAA6B,CAAE,YAAW,eAAc,UAAS,iBAAgB,CAAC,EAGhG,GAAI,CAAC,EAAQ,KAAM,CAEjB,IAAM,EAAS,EAAY,GAAgB,GAAa,EAAe,EACjE,EAAS,EAAY,GAAgB,GAAa,EAAe,EACvE,EAAgB,GAAU,EACrB,KAEL,IAAM,EAAM,EAAK,MAAM,OAEjB,GAAe,EAAY,EAAe,GAAO,EAEjD,GAAgB,EAAe,EAAY,GAAO,EAElD,EAAS,EAAc,GAAK,GAAe,EAC3C,EAAS,EAAe,GAAK,GAAgB,EACnD,EAAgB,GAAU,GAM9B,IAAQ,MAAO,KAAsB,GAAsB,EAErD,EAAe,CACnB,OACA,MAAO,EACP,SAAU,EAAK,QAAU,EACzB,gBACA,MAAO,CACT,EAGM,EAAU,EAAY,MAAQ,EAAQ,SAAS,aAAa,EAAM,CAAS,GAAK,GAEtF,OACE,GAQE,UARF,IAEM,EACJ,aAAY,QAAQ,EAAY,QAAQ,EAAK,MAAM,SAHrD,SAKE,GAEE,GAAiB,SAFnB,CAA2B,MAAO,EAAlC,SACG,EAAS,CAAY,EACtB,GANG,CAOL,EAEL,EACD,EACF",
|
|
17
|
-
"debugId": "
|
|
6
|
+
"mappings": "",
|
|
7
|
+
"debugId": "B78098051D0BEAB864756E2164756E21",
|
|
18
8
|
"names": []
|
|
19
9
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { StoryObj } from "@storybook/react";
|
|
2
2
|
import React from "react";
|
|
3
|
+
import type { SwipeDeckProps } from "../types";
|
|
3
4
|
type DemoItem = {
|
|
4
5
|
id: string;
|
|
5
6
|
title: string;
|
|
6
7
|
};
|
|
7
8
|
declare const meta: {
|
|
8
9
|
title: string;
|
|
9
|
-
component: React.ComponentType<
|
|
10
|
+
component: React.ComponentType<SwipeDeckProps<DemoItem>>;
|
|
10
11
|
parameters: {
|
|
11
12
|
layout: string;
|
|
12
13
|
};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ScrollBehavior } from "../types";
|
|
2
|
-
type UseScrollToParams = {
|
|
3
|
-
getViewport: () => HTMLElement | null;
|
|
4
|
-
setAnimating?: (value: boolean) => void;
|
|
5
|
-
};
|
|
6
|
-
export declare function useScrollTo({ getViewport, setAnimating }: UseScrollToParams): {
|
|
7
|
-
scrollToIndex: (offset: number, behavior?: ScrollBehavior) => void;
|
|
8
|
-
};
|
|
9
|
-
export {};
|