react-anchorlist 0.3.7 → 0.3.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"useScrollAnchor.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollAnchor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C,UAAU,sBAAsB;IAC9B,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,qBAAqB,EAAE,MAAM,cAAc,GAAG,IAAI,CAAA;IAClD,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IACnF,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;CACxB;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE;IACtD,QAAQ,EAAE,cAAc,CAAA;IACxB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;CACpF,GAAG,MAAM,CAgBT;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG;IAAE,aAAa,EAAE,MAAM,IAAI,CAAA;CAAE,CAyF9F"}
1
+ {"version":3,"file":"useScrollAnchor.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollAnchor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C,UAAU,sBAAsB;IAC9B,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,qBAAqB,EAAE,MAAM,cAAc,GAAG,IAAI,CAAA;IAClD,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;IACnF,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;CACxB;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE;IACtD,QAAQ,EAAE,cAAc,CAAA;IACxB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;CACpF,GAAG,MAAM,CAgBT;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG;IAAE,aAAa,EAAE,MAAM,IAAI,CAAA;CAAE,CAsF9F"}
@@ -1 +1 @@
1
- {"version":3,"file":"useVirtualEngine.d.ts","sourceRoot":"","sources":["../../src/hooks/useVirtualEngine.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAkB,sBAAsB,EAAe,MAAM,UAAU,CAAA;AAEnF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE;IAC3C,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACnD,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,KAAK,GAAG,QAAQ,CAAA;CACnC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAqX5B"}
1
+ {"version":3,"file":"useVirtualEngine.d.ts","sourceRoot":"","sources":["../../src/hooks/useVirtualEngine.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAkB,sBAAsB,EAAe,MAAM,UAAU,CAAA;AAEnF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE;IAC3C,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAA;IACnD,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,KAAK,GAAG,QAAQ,CAAA;CACnC,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAoX5B"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),r=require("react");function he(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const te=he(r);class de{constructor(e,t){this.defaultSize=t,this.sizes=e>0?Array(e).fill(t):[],this.offsets=e>0?Array(e).fill(0):[],e>0&&this._recalcFrom(0)}_recalcFrom(e){for(let t=e;t<this.sizes.length;t++)this.offsets[t]=t===0?0:(this.offsets[t-1]??0)+(this.sizes[t-1]??this.defaultSize)}getOffset(e){return this.offsets[e]??0}getSize(e){return this.sizes[e]??this.defaultSize}setSize(e,t){return this.sizes[e]===t?!1:(this.sizes[e]=t,this._recalcFrom(e+1),!0)}prepend(e){const t=Array(e).fill(this.defaultSize);this.sizes=[...t,...this.sizes],this.offsets=Array(this.sizes.length).fill(0),this._recalcFrom(0)}append(e){const t=this.sizes.length;for(let s=0;s<e;s++)this.sizes.push(this.defaultSize),this.offsets.push(0);this._recalcFrom(t)}resize(e){const t=this.sizes.length;e>t?this.append(e-t):e<t&&(this.sizes=this.sizes.slice(0,e),this.offsets=this.offsets.slice(0,e))}totalSize(){if(this.sizes.length===0)return 0;const e=this.sizes.length-1;return(this.offsets[e]??0)+(this.sizes[e]??this.defaultSize)}get count(){return this.sizes.length}getOffsets(){return this.offsets}getSizes(){return this.sizes}}class me{constructor(){this.cache=new Map}get(e){return this.cache.get(e)}set(e,t){this.cache.set(e,t)}has(e){return this.cache.has(e)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}applyToOffsetMap(e,t){for(const[s,l]of this.cache){const o=t.get(s);o!==void 0&&e.setSize(o,l)}}}function oe(i,e){if(i.length===0)return 0;let t=0,s=i.length-1;for(;t<s;){const l=t+s>>1;(i[l]??0)<e?t=l+1:s=l}return Math.max(0,t>0&&(i[t]??0)>e?t-1:t)}function pe(i,e,t){if(i.length===0)return 0;let s=0,l=i.length-1,o=0;for(;s<=l;){const n=s+l>>1;(i[n]??0)<t?(o=n,s=n+1):l=n-1}return o}function ge(i){const{firstVisible:e,lastVisible:t,itemCount:s,overscan:l}=i;return s===0?{start:0,end:-1}:{start:Math.max(0,e-l),end:Math.min(s-1,t+l)}}function Re(i,e,t,s){const l=s==null?void 0:s.reconcile,o=r.useRef(null);return r.useCallback((n,y)=>{const u=i.current,d=e.current;if(!u||!d)return;o.current!==null&&(cancelAnimationFrame(o.current),o.current=null);let R,a;if(typeof n=="object"&&n!==null?(R=n.index,a={align:n.align,behavior:n.behavior,offset:n.offset}):(R=n,a=y),!Number.isFinite(R))return;const p=Math.max(0,Math.min(Math.floor(R),d.count-1));d.getOffset(p),d.getSize(p);const F=(a==null?void 0:a.align)??"start",E=(a==null?void 0:a.behavior)??"auto",I=(a==null?void 0:a.offset)??0,h=()=>{var P;const M=e.current,f=i.current;if(!M||!f)return 0;const S=((P=t==null?void 0:t.current)==null?void 0:P.offsetTop)??0,v=M.getOffset(p),k=M.getSize(p);return F==="start"?S+v+I:F==="center"?S+v-f.clientHeight/2+k/2+I:S+v-f.clientHeight+k+I},w=h();((M,f)=>{typeof u.scrollTo=="function"?u.scrollTo({top:M,behavior:f}):u.scrollTop=M})(Math.max(0,w),E);const H=performance.now();let T=0;const j=12,L=300,J=1,K=()=>{o.current=null;const M=i.current;if(!M)return;const f=Math.max(0,h()),S=Math.abs(M.scrollTop-f),v=performance.now()-H>=L,k=T>=j;S<=J||v||k||(typeof M.scrollTo=="function"?M.scrollTo({top:f,behavior:"auto"}):M.scrollTop=f,T+=1,o.current=requestAnimationFrame(K))};o.current=requestAnimationFrame(K)},[i,e,t,l])}function ce(i){var se;const{items:e,getKey:t,estimatedItemSize:s,overscan:l,initialAlignment:o}=i,n=r.useRef(null),y=r.useRef(null),u=r.useRef(null),d=r.useRef(new me),R=r.useRef([]),a=r.useRef(new Map),p=r.useRef(e.length),F=r.useRef(null),E=r.useRef(null),I=r.useRef(!1),h=r.useRef(0),w=r.useRef(0),g=r.useRef(null),H=r.useRef(!1),T=r.useRef(null),j=r.useRef(0),L=r.useRef(0),J=r.useRef(0),K=r.useRef(null),M=r.useRef(!1),f=r.useRef(!1),[,S]=r.useState(0),v=r.useCallback(()=>S(c=>c+1),[]);u.current||(u.current=new de(e.length,s));const k=e.length>0?t(e[0],0):null,P=e.length>0?t(e[e.length-1],e.length-1):null;if(e.length!==p.current||k!==F.current||P!==E.current){const c=u.current,m=e.map((O,_)=>t(O,_)),z=R.current,x=z.length,C=m.length;if(C===0)c.resize(0);else if(x===0)c.resize(C);else if(C>x){const O=C-x;z.length>0&&O>=0&&m[O]===z[0]?c.prepend(O):c.resize(C)}else C<x,c.resize(C);const b=new Map;m.forEach((O,_)=>b.set(O,_)),a.current=b,d.current.applyToOffsetMap(c,b),R.current=m,p.current=e.length,F.current=k,E.current=P}const A=r.useCallback(()=>{K.current===null&&(K.current=requestAnimationFrame(()=>{K.current=null;const c=n.current;if(!c)return;const m=j.current;Math.abs(m)<.01||(j.current=0,L.current+=m,J.current+=m,c.scrollTop+=m,h.current=c.scrollTop,M.current=!0,v())}))},[v]);r.useEffect(()=>{const c=n.current;if(!c)return;const m=()=>{g.current===null&&(g.current=requestAnimationFrame(()=>{g.current=null,h.current=c.scrollTop,w.current=c.clientHeight,M.current&&(M.current=!1,L.current=0,J.current=0),v()}))};return c.addEventListener("scroll",m,{passive:!0}),()=>{c.removeEventListener("scroll",m),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),K.current!==null&&(cancelAnimationFrame(K.current),K.current=null)}},[v]),r.useEffect(()=>{const c=n.current;if(!c)return;w.current=c.clientHeight,h.current=c.scrollTop;const m=new ResizeObserver(([z])=>{z&&(w.current=z.contentRect.height,v())});return m.observe(c),()=>m.disconnect()},[v]),r.useLayoutEffect(()=>{if(I.current||e.length===0)return;const c=n.current;if(c){if(o==="bottom"){c.scrollTop=c.scrollHeight,h.current=c.scrollTop,w.current=c.clientHeight,H.current=!0,T.current!==null&&cancelAnimationFrame(T.current);const m=performance.now();let z=0,x=c.scrollHeight;const C=()=>{if(!H.current){T.current=null;return}const b=c.scrollHeight,O=Math.abs(b-x);x=b,O<1?z+=1:z=0,c.scrollTop=c.scrollHeight,h.current=c.scrollTop;const _=performance.now()-m;if(z>=3||_>=500){H.current=!1,T.current=null;return}T.current=requestAnimationFrame(C)};T.current=requestAnimationFrame(C)}I.current=!0}},[o,e.length]),r.useEffect(()=>{e.length===0&&(I.current=!1,H.current=!1,T.current!==null&&(cancelAnimationFrame(T.current),T.current=null))},[e.length]);const B=r.useCallback((c,m)=>{var Y;const z=u.current;if(!z||d.current.get(c)===m)return;d.current.set(c,m);const C=a.current.get(c);if(C===void 0)return;const b=z.getSize(C),O=m-b,_=n.current;if(_&&!H.current&&!f.current&&O!==0){const X=z.getOffset(C)+b+(((Y=y.current)==null?void 0:Y.offsetTop)??0);X<_.scrollTop&&(console.log(`[JUMP] key=${c} idx=${C} delta=${O} itemBottom=${Math.round(X)} scrollTop=${Math.round(_.scrollTop)} suppressed=${f.current}`),j.current+=O,A())}z.setSize(C,m)&&v()},[A,v]),N=r.useCallback((c,m="auto")=>{var z;(z=n.current)==null||z.scrollTo({top:c,behavior:m})},[]),D=Re(n,u,y,{reconcile:!0}),V=r.useCallback(()=>{var ee;const c=n.current,m=u.current;if(!c||!m||m.count===0)return null;const z=((ee=y.current)==null?void 0:ee.offsetTop)??0,x=Math.max(0,c.scrollTop-z),C=m.getOffsets(),b=oe(C,x),O=R.current[b]??null,_=[];for(let Y=b;Y<Math.min(m.count,b+6);Y++){const X=R.current[Y]??null;X!==null&&_.push({key:X,offsetWithinItem:x-m.getOffset(Y)})}return{key:O,offsetWithinItem:x-m.getOffset(b),candidates:_,scrollTop:c.scrollTop,scrollHeight:c.scrollHeight}},[]),G=r.useCallback((c,m)=>{var b;const z=u.current;if(!z)return null;const x=a.current.get(c);return x===void 0?null:(((b=y.current)==null?void 0:b.offsetTop)??0)+z.getOffset(x)+m},[]),$=u.current,ue=$?$.totalSize():0,W=n.current,Q=(W==null?void 0:W.scrollTop)??h.current,re=(W==null?void 0:W.clientHeight)??w.current,ae=((se=y.current)==null?void 0:se.offsetTop)??0,ne=Math.max(0,Q-ae),Z=[];if($&&$.count>0&&re>0){const c=$.getOffsets(),m=$.getSizes(),z=oe(c,ne),x=pe(c,m,ne+re),C=ge({firstVisible:z,lastVisible:x,itemCount:$.count,overscan:l});for(let b=C.start;b<=C.end&&b<e.length;b++)Z.push({key:R.current[b]??t(e[b],b),index:b,start:$.getOffset(b),size:$.getSize(b),data:e[b]})}else if($&&$.count>0){const c=Math.min(e.length,l*2+1),m=o==="bottom"?Math.max(0,e.length-c):0,z=m+c-1;for(let x=m;x<=z;x++)Z.push({key:R.current[x]??t(e[x],x),index:x,start:$.getOffset(x),size:$.getSize(x),data:e[x]})}const fe=W?W.scrollHeight-W.scrollTop-W.clientHeight:1/0;return{scrollerRef:n,innerRef:y,virtualItems:Z,totalSize:ue,measureItem:B,scrollToIndex:D,scrollToOffset:N,captureAnchorSnapshot:V,resolveAnchorTop:G,isAtTop:Q<=1,isAtBottom:fe<=1,scrollTop:Q,jumpSuppressedRef:f}}function ve(i){var l;const{snapshot:e,currentScrollHeight:t,resolveAnchorTop:s}=i;if(e.key!==null){const o=s(e.key,e.offsetWithinItem);if(o!==null)return o}if((l=e.candidates)!=null&&l.length)for(const o of e.candidates){const n=s(o.key,o.offsetWithinItem);if(n!==null)return n}return e.scrollTop+(t-e.scrollHeight)}function ye(i){const{scrollerRef:e,itemCount:t,captureAnchorSnapshot:s,resolveAnchorTop:l,onRestored:o}=i,n=r.useRef(null),y=r.useRef(!1),u=r.useRef({first:null,second:null,timeout:null}),d=r.useCallback(()=>{const{first:a,second:p,timeout:F}=u.current;a&&cancelAnimationFrame(a),p&&cancelAnimationFrame(p),F&&clearTimeout(F),u.current={first:null,second:null,timeout:null}},[]),R=r.useCallback(()=>{const a=e.current;if(!a)return;const p=s();n.current=p??{key:null,offsetWithinItem:0,scrollTop:a.scrollTop,scrollHeight:a.scrollHeight},y.current=!0,console.log("[ANCHOR] prepareAnchor snapshot:",JSON.stringify(n.current,null,2))},[e,s]);return r.useLayoutEffect(()=>{if(!y.current)return;const a=e.current,p=n.current;if(!a||!p)return;y.current=!1;const F=E=>{const I=ve({snapshot:p,currentScrollHeight:a.scrollHeight,resolveAnchorTop:l});console.log(`[ANCHOR] restore(${E}): target=${Math.round(I)}, currentScrollTop=${Math.round(a.scrollTop)}, scrollHeight=${a.scrollHeight}, snapshotKey=${p.key}, delta=${Math.round(I-a.scrollTop)}`),Number.isFinite(I)&&Math.abs(a.scrollTop-I)>1&&(a.scrollTop=I)};return d(),F("layout"),o==null||o(),u.current.first=requestAnimationFrame(()=>{u.current.first=null,F("raf1"),u.current.second=requestAnimationFrame(()=>{u.current.second=null,F("raf2")})}),u.current.timeout=setTimeout(()=>{u.current.timeout=null,F("timeout")},90),()=>d()},[t,e,l,d,o]),{prepareAnchor:R}}function Te(i){const{previous:e,distanceFromBottom:t,threshold:s,hysteresis:l}=i;if(!l)return t<=s;const o=Math.max(0,l.enter),n=Math.max(o,l.leave);return e?t<=n:t<=o}function Se(i,e){const t=typeof e=="number"?e:e.threshold??200,s=typeof e=="number"?void 0:e.hysteresis,[l,o]=r.useState(!0),n=r.useRef(null),y=r.useRef(!0);return r.useEffect(()=>{const u=i.current;if(!u)return;const d=()=>{const a=u.scrollHeight-u.scrollTop-u.clientHeight,p=Te({previous:y.current,distanceFromBottom:a,threshold:t,hysteresis:s});y.current=p,o(p)},R=()=>{n.current!==null&&cancelAnimationFrame(n.current),n.current=requestAnimationFrame(d)};return u.addEventListener("scroll",R,{passive:!0}),d(),()=>{u.removeEventListener("scroll",R),n.current!==null&&cancelAnimationFrame(n.current)}},[i,t,s==null?void 0:s.enter,s==null?void 0:s.leave]),l}function Ae(i){const{itemCount:e,firstKey:t,lastKey:s,isAtBottom:l,scrollToIndex:o,mode:n}=i,y=r.useRef(e),u=r.useRef(t),d=r.useRef(s);r.useLayoutEffect(()=>{if(!n){y.current=e,u.current=t,d.current=s;return}const R=y.current,a=u.current,p=d.current;e>R&&t===a&&s!==p&&l&&e>0&&o(e-1,{align:"end",behavior:n==="smooth"?"smooth":"auto"}),y.current=e,u.current=t,d.current=s},[e,t,s,l,o,n])}function le(i){const{items:e,getKey:t,estimatedItemSize:s=80,overscan:l=20,atBottomThreshold:o=200,atBottomHysteresis:n,followOutput:y="auto",initialAlignment:u="bottom",scrollModifier:d=null,onStartReached:R,onEndReached:a,startReachedThreshold:p=300,endReachedThreshold:F=300,scrollToMessageKey:E,onScrollToMessageComplete:I}=i,h=ce({items:e,getKey:t,estimatedItemSize:s,overscan:l,initialAlignment:u}),w=Se(h.scrollerRef,{threshold:o,hysteresis:n??{enter:80,leave:160}}),[,g]=r.useState(0),H=r.useRef(null),T=r.useCallback(()=>{g(A=>A+1),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{h.jumpSuppressedRef.current=!1,H.current=null},200)},[h.jumpSuppressedRef]),{prepareAnchor:j}=ye({scrollerRef:h.scrollerRef,itemCount:e.length,captureAnchorSnapshot:h.captureAnchorSnapshot,resolveAnchorTop:h.resolveAnchorTop,onRestored:T}),L=r.useCallback(()=>{h.jumpSuppressedRef.current=!0,j()},[j,h.jumpSuppressedRef]),J=e.length>0?t(e[0],0):null,K=e.length>0?t(e[e.length-1],e.length-1):null;Ae({itemCount:e.length,firstKey:J,lastKey:K,isAtBottom:w,scrollToIndex:h.scrollToIndex,mode:y??!1});const M=r.useCallback((A="auto")=>{e.length!==0&&h.scrollToIndex(e.length-1,{align:"end",behavior:A})},[e.length,h]),f=r.useCallback((A,B)=>{const N=e.findIndex((D,V)=>t(D,V)===A);N!==-1&&h.scrollToIndex(N,B)},[e,t,h]),S=r.useRef(null);r.useLayoutEffect(()=>{if(d&&S.current!==d.id){if(S.current=d.id,d.type==="prepend"){L();return}if(d.type==="append"){if(d.ifAtBottomOnly&&!w)return;M(d.behavior??"auto");return}if(d.type==="items-change"){w&&M("auto");return}f(d.key,{align:d.align??"center",behavior:d.behavior??"auto"})}},[d,w,L,M,f]);const v=r.useRef(!1),k=r.useRef(u==="top");r.useEffect(()=>{const A=h.scrollerRef.current;if(!A||!R)return;const B=()=>{const N=A.scrollTop;k.current||(A.scrollHeight<=A.clientHeight+p||N>p)&&(k.current=!0),k.current&&N<=p&&!v.current&&(v.current=!0,Promise.resolve(R()).finally(()=>{v.current=!1}))};return A.addEventListener("scroll",B,{passive:!0}),B(),()=>A.removeEventListener("scroll",B)},[h.scrollerRef,R,p,u]);const P=r.useRef(!1);r.useEffect(()=>{const A=h.scrollerRef.current;if(!A||!a)return;const B=()=>{A.scrollHeight-A.scrollTop-A.clientHeight<=F&&!P.current&&(P.current=!0,Promise.resolve(a()).finally(()=>{P.current=!1}))};return A.addEventListener("scroll",B,{passive:!0}),()=>A.removeEventListener("scroll",B)},[h.scrollerRef,a,F]);const U=r.useRef(null);return r.useEffect(()=>{if(!E||U.current===E)return;const A=e.findIndex((B,N)=>t(B,N)===E);A!==-1&&(U.current=E,h.scrollToIndex(A,{align:"center",behavior:"auto"}),I==null||I())},[E,e,t,h,I]),{scrollerRef:h.scrollerRef,innerRef:h.innerRef,virtualItems:h.virtualItems,totalSize:h.totalSize,measureItem:h.measureItem,scrollToIndex:h.scrollToIndex,scrollToBottom:M,scrollToKey:f,isAtBottom:w,prepareAnchor:L}}function ie({virtualItem:i,measureItem:e,children:t}){const s=r.useRef(null),l=r.useRef(!1);return r.useEffect(()=>{const o=s.current;if(!o)return;l.current=!1;const n=new ResizeObserver(([y])=>{y&&(l.current=!0,e(i.key,y.contentRect.height))});return n.observe(o),()=>n.disconnect()},[i.key,e]),q.jsx("div",{ref:s,style:{position:"absolute",top:0,transform:`translateY(${i.start}px)`,width:"100%",minHeight:l.current?void 0:i.size},children:t})}function be(i,e){const{data:t,itemContent:s,computeItemKey:l,estimatedItemSize:o=80,overscan:n=20,followOutput:y="auto",atBottomThreshold:u=200,atBottomHysteresis:d,initialAlignment:R="bottom",scrollModifier:a,onStartReached:p,onEndReached:F,startReachedThreshold:E=300,endReachedThreshold:I=300,scrollToMessageKey:h,onScrollToMessageComplete:w,onAtBottomChange:g,components:H={},className:T,style:j}=i,{scrollerRef:L,innerRef:J,virtualItems:K,totalSize:M,measureItem:f,scrollToIndex:S,scrollToBottom:v,scrollToKey:k,isAtBottom:P,prepareAnchor:U}=le({items:t,getKey:(V,G)=>l(G,V),estimatedItemSize:o,overscan:n,atBottomThreshold:u,atBottomHysteresis:d,followOutput:y,initialAlignment:R,scrollModifier:a,onStartReached:p,onEndReached:F,startReachedThreshold:E,endReachedThreshold:I,scrollToMessageKey:h,onScrollToMessageComplete:w}),A=te.useRef(P);te.useEffect(()=>{A.current!==P&&(A.current=P,g==null||g(P))},[P,g]),r.useImperativeHandle(e,()=>({scrollToBottom:v,scrollToIndex:S,scrollToKey:k,getScrollTop:()=>{var V;return((V=L.current)==null?void 0:V.scrollTop)??0},isAtBottom:()=>P,prepareAnchor:U}),[v,S,k,L,P,U]);const{Header:B,Footer:N,EmptyPlaceholder:D}=H;return t.length===0&&D?q.jsx(D,{}):q.jsxs("div",{ref:L,className:T,style:{overflow:"auto",height:"100%",position:"relative",overflowAnchor:"none",overscrollBehaviorY:"contain",...j},children:[B&&q.jsx(B,{}),q.jsx("div",{ref:J,style:{height:M,position:"relative",width:"100%"},children:K.map(V=>q.jsx(ie,{virtualItem:V,measureItem:f,children:s(V.index,V.data)},V.key))}),N&&q.jsx(N,{})]})}const ze=r.forwardRef(be);function xe({data:i,itemContent:e,computeItemKey:t,estimatedItemSize:s=60,overscan:l=20,onEndReached:o,endReachedThreshold:n=300,components:y={},className:u,style:d}){const{scrollerRef:R,innerRef:a,virtualItems:p,totalSize:F,measureItem:E}=ce({items:i,getKey:(g,H)=>t(H,g),estimatedItemSize:s,overscan:l,initialAlignment:"top"});te.useEffect(()=>{const g=R.current;if(!g||!o)return;let H=!1;const T=()=>{g.scrollHeight-g.scrollTop-g.clientHeight<=n&&!H&&(H=!0,Promise.resolve(o()).finally(()=>{H=!1}))};return g.addEventListener("scroll",T,{passive:!0}),()=>g.removeEventListener("scroll",T)},[R,o,n]);const{Header:I,Footer:h,EmptyPlaceholder:w}=y;return i.length===0&&w?q.jsx(w,{}):q.jsxs("div",{ref:R,className:u,style:{overflow:"auto",height:"100%",position:"relative",overflowAnchor:"none",overscrollBehaviorY:"contain",...d},children:[I&&q.jsx(I,{}),q.jsx("div",{ref:a,style:{height:F,position:"relative",width:"100%"},children:p.map(g=>q.jsx(ie,{virtualItem:g,measureItem:E,children:e(g.index,g.data)},g.key))}),h&&q.jsx(h,{})]})}function Ie(i){const{fetcher:e,initialPage:t=1,direction:s="append",getKey:l,onPageLoaded:o,onError:n}=i,[y,u]=r.useState([]),[d,R]=r.useState(t),[a,p]=r.useState(!0),[F,E]=r.useState(!1),[I,h]=r.useState(!1),[w,g]=r.useState(!1),H=r.useRef(new Set),T=r.useRef(!1),j=r.useCallback(f=>l?f.filter(S=>{const v=l(S);return H.current.has(v)?!1:(H.current.add(v),!0)}):f,[l]),L=r.useCallback(async()=>{if(!(T.current||!a)){T.current=!0,g(!0);try{const f=d+1,S=await e(f),v=j(S.data);u(k=>s==="prepend"?[...v,...k]:[...k,...v]),R(f),p(S.hasNextPage),E(S.hasPrevPage),o==null||o(f,v)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{g(!1),T.current=!1}}},[d,a,e,j,s,o,n]),J=r.useCallback(async()=>{if(!(T.current||!F)){T.current=!0,g(!0);try{const f=d-1,S=await e(f),v=j(S.data);u(k=>[...v,...k]),R(f),E(S.hasPrevPage),p(S.hasNextPage),o==null||o(f,v)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{g(!1),T.current=!1}}},[d,F,e,j,o,n]),K=r.useCallback(async()=>{if(!T.current){T.current=!0,h(!0);try{const f=await e(t),S=f.data;if(l){const v=new Set(S.map(l));S.forEach(k=>H.current.add(l(k))),u(k=>{const P=k.filter(U=>!v.has(l(U)));return s==="prepend"?[...S,...P]:[...P,...S]})}else u(S);R(t),p(f.hasNextPage),E(f.hasPrevPage),o==null||o(t,S)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{h(!1),T.current=!1}}},[e,t,l,s,o,n]),M=r.useCallback(()=>{u([]),R(t),p(!0),E(!1),h(!1),g(!1),H.current.clear(),T.current=!1},[t]);return{items:y,loadNextPage:L,loadPrevPage:J,hasNextPage:a,hasPrevPage:F,loading:I,loadingMore:w,refresh:K,reset:M,currentPage:d}}exports.ChatVirtualList=ze;exports.VirtualList=xe;exports.useChatVirtualizer=le;exports.usePagination=Ie;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),r=require("react");function he(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const te=he(r);class de{constructor(e,t){this.defaultSize=t,this.sizes=e>0?Array(e).fill(t):[],this.offsets=e>0?Array(e).fill(0):[],e>0&&this._recalcFrom(0)}_recalcFrom(e){for(let t=e;t<this.sizes.length;t++)this.offsets[t]=t===0?0:(this.offsets[t-1]??0)+(this.sizes[t-1]??this.defaultSize)}getOffset(e){return this.offsets[e]??0}getSize(e){return this.sizes[e]??this.defaultSize}setSize(e,t){return this.sizes[e]===t?!1:(this.sizes[e]=t,this._recalcFrom(e+1),!0)}prepend(e){const t=Array(e).fill(this.defaultSize);this.sizes=[...t,...this.sizes],this.offsets=Array(this.sizes.length).fill(0),this._recalcFrom(0)}append(e){const t=this.sizes.length;for(let s=0;s<e;s++)this.sizes.push(this.defaultSize),this.offsets.push(0);this._recalcFrom(t)}resize(e){const t=this.sizes.length;e>t?this.append(e-t):e<t&&(this.sizes=this.sizes.slice(0,e),this.offsets=this.offsets.slice(0,e))}totalSize(){if(this.sizes.length===0)return 0;const e=this.sizes.length-1;return(this.offsets[e]??0)+(this.sizes[e]??this.defaultSize)}get count(){return this.sizes.length}getOffsets(){return this.offsets}getSizes(){return this.sizes}}class me{constructor(){this.cache=new Map}get(e){return this.cache.get(e)}set(e,t){this.cache.set(e,t)}has(e){return this.cache.has(e)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}applyToOffsetMap(e,t){for(const[s,l]of this.cache){const o=t.get(s);o!==void 0&&e.setSize(o,l)}}}function oe(i,e){if(i.length===0)return 0;let t=0,s=i.length-1;for(;t<s;){const l=t+s>>1;(i[l]??0)<e?t=l+1:s=l}return Math.max(0,t>0&&(i[t]??0)>e?t-1:t)}function pe(i,e,t){if(i.length===0)return 0;let s=0,l=i.length-1,o=0;for(;s<=l;){const n=s+l>>1;(i[n]??0)<t?(o=n,s=n+1):l=n-1}return o}function ge(i){const{firstVisible:e,lastVisible:t,itemCount:s,overscan:l}=i;return s===0?{start:0,end:-1}:{start:Math.max(0,e-l),end:Math.min(s-1,t+l)}}function Re(i,e,t,s){const l=s==null?void 0:s.reconcile,o=r.useRef(null);return r.useCallback((n,y)=>{const u=i.current,d=e.current;if(!u||!d)return;o.current!==null&&(cancelAnimationFrame(o.current),o.current=null);let R,h;if(typeof n=="object"&&n!==null?(R=n.index,h={align:n.align,behavior:n.behavior,offset:n.offset}):(R=n,h=y),!Number.isFinite(R))return;const p=Math.max(0,Math.min(Math.floor(R),d.count-1));d.getOffset(p),d.getSize(p);const I=(h==null?void 0:h.align)??"start",k=(h==null?void 0:h.behavior)??"auto",E=(h==null?void 0:h.offset)??0,a=()=>{var P;const H=e.current,f=i.current;if(!H||!f)return 0;const S=((P=t==null?void 0:t.current)==null?void 0:P.offsetTop)??0,v=H.getOffset(p),C=H.getSize(p);return I==="start"?S+v+E:I==="center"?S+v-f.clientHeight/2+C/2+E:S+v-f.clientHeight+C+E},w=a();((H,f)=>{typeof u.scrollTo=="function"?u.scrollTo({top:H,behavior:f}):u.scrollTop=H})(Math.max(0,w),k);const F=performance.now();let T=0;const j=12,L=300,D=1,K=()=>{o.current=null;const H=i.current;if(!H)return;const f=Math.max(0,a()),S=Math.abs(H.scrollTop-f),v=performance.now()-F>=L,C=T>=j;S<=D||v||C||(typeof H.scrollTo=="function"?H.scrollTo({top:f,behavior:"auto"}):H.scrollTop=f,T+=1,o.current=requestAnimationFrame(K))};o.current=requestAnimationFrame(K)},[i,e,t,l])}function ce(i){var se;const{items:e,getKey:t,estimatedItemSize:s,overscan:l,initialAlignment:o}=i,n=r.useRef(null),y=r.useRef(null),u=r.useRef(null),d=r.useRef(new me),R=r.useRef([]),h=r.useRef(new Map),p=r.useRef(e.length),I=r.useRef(null),k=r.useRef(null),E=r.useRef(!1),a=r.useRef(0),w=r.useRef(0),g=r.useRef(null),F=r.useRef(!1),T=r.useRef(null),j=r.useRef(0),L=r.useRef(0),D=r.useRef(0),K=r.useRef(null),H=r.useRef(!1),f=r.useRef(!1),[,S]=r.useState(0),v=r.useCallback(()=>S(c=>c+1),[]);u.current||(u.current=new de(e.length,s));const C=e.length>0?t(e[0],0):null,P=e.length>0?t(e[e.length-1],e.length-1):null;if(e.length!==p.current||C!==I.current||P!==k.current){const c=u.current,m=e.map((O,W)=>t(O,W)),z=R.current,x=z.length,M=m.length;if(M===0)c.resize(0);else if(x===0)c.resize(M);else if(M>x){const O=M-x;z.length>0&&O>=0&&m[O]===z[0]?c.prepend(O):c.resize(M)}else M<x,c.resize(M);const A=new Map;m.forEach((O,W)=>A.set(O,W)),h.current=A,d.current.applyToOffsetMap(c,A),R.current=m,p.current=e.length,I.current=C,k.current=P}const b=r.useCallback(()=>{K.current===null&&(K.current=requestAnimationFrame(()=>{K.current=null;const c=n.current;if(!c)return;const m=j.current;Math.abs(m)<.01||(j.current=0,L.current+=m,D.current+=m,c.scrollTop+=m,a.current=c.scrollTop,H.current=!0,v())}))},[v]);r.useEffect(()=>{const c=n.current;if(!c)return;const m=()=>{g.current===null&&(g.current=requestAnimationFrame(()=>{g.current=null,a.current=c.scrollTop,w.current=c.clientHeight,H.current&&(H.current=!1,L.current=0,D.current=0),v()}))};return c.addEventListener("scroll",m,{passive:!0}),()=>{c.removeEventListener("scroll",m),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),K.current!==null&&(cancelAnimationFrame(K.current),K.current=null)}},[v]),r.useEffect(()=>{const c=n.current;if(!c)return;w.current=c.clientHeight,a.current=c.scrollTop;const m=new ResizeObserver(([z])=>{z&&(w.current=z.contentRect.height,v())});return m.observe(c),()=>m.disconnect()},[v]),r.useLayoutEffect(()=>{if(E.current||e.length===0)return;const c=n.current;if(c){if(o==="bottom"){c.scrollTop=c.scrollHeight,a.current=c.scrollTop,w.current=c.clientHeight,F.current=!0,T.current!==null&&cancelAnimationFrame(T.current);const m=performance.now();let z=0,x=c.scrollHeight;const M=()=>{if(!F.current){T.current=null;return}const A=c.scrollHeight,O=Math.abs(A-x);x=A,O<1?z+=1:z=0,c.scrollTop=c.scrollHeight,a.current=c.scrollTop;const W=performance.now()-m;if(z>=3||W>=500){F.current=!1,T.current=null;return}T.current=requestAnimationFrame(M)};T.current=requestAnimationFrame(M)}E.current=!0}},[o,e.length]),r.useEffect(()=>{e.length===0&&(E.current=!1,F.current=!1,T.current!==null&&(cancelAnimationFrame(T.current),T.current=null))},[e.length]);const B=r.useCallback((c,m)=>{var X;const z=u.current;if(!z||d.current.get(c)===m)return;d.current.set(c,m);const M=h.current.get(c);if(M===void 0)return;const A=z.getSize(M),O=m-A,W=n.current;W&&!F.current&&!f.current&&O!==0&&z.getOffset(M)+A+(((X=y.current)==null?void 0:X.offsetTop)??0)<W.scrollTop&&(j.current+=O,b()),z.setSize(M,m)&&v()},[b,v]),V=r.useCallback((c,m="auto")=>{var z;(z=n.current)==null||z.scrollTo({top:c,behavior:m})},[]),Y=Re(n,u,y,{reconcile:!0}),N=r.useCallback(()=>{var Z;const c=n.current,m=u.current;if(!c||!m||m.count===0)return null;const z=((Z=y.current)==null?void 0:Z.offsetTop)??0,x=Math.max(0,c.scrollTop-z),M=m.getOffsets(),A=oe(M,x),O=R.current[A]??null,W=[];for(let X=A;X<Math.min(m.count,A+6);X++){const ee=R.current[X]??null;ee!==null&&W.push({key:ee,offsetWithinItem:x-m.getOffset(X)})}return{key:O,offsetWithinItem:x-m.getOffset(A),candidates:W,scrollTop:c.scrollTop,scrollHeight:c.scrollHeight}},[]),$=r.useCallback((c,m)=>{var A;const z=u.current;if(!z)return null;const x=h.current.get(c);return x===void 0?null:(((A=y.current)==null?void 0:A.offsetTop)??0)+z.getOffset(x)+m},[]),_=u.current,ue=_?_.totalSize():0,J=n.current,G=(J==null?void 0:J.scrollTop)??a.current,re=(J==null?void 0:J.clientHeight)??w.current,ae=((se=y.current)==null?void 0:se.offsetTop)??0,ne=Math.max(0,G-ae),Q=[];if(_&&_.count>0&&re>0){const c=_.getOffsets(),m=_.getSizes(),z=oe(c,ne),x=pe(c,m,ne+re),M=ge({firstVisible:z,lastVisible:x,itemCount:_.count,overscan:l});for(let A=M.start;A<=M.end&&A<e.length;A++)Q.push({key:R.current[A]??t(e[A],A),index:A,start:_.getOffset(A),size:_.getSize(A),data:e[A]})}else if(_&&_.count>0){const c=Math.min(e.length,l*2+1),m=o==="bottom"?Math.max(0,e.length-c):0,z=m+c-1;for(let x=m;x<=z;x++)Q.push({key:R.current[x]??t(e[x],x),index:x,start:_.getOffset(x),size:_.getSize(x),data:e[x]})}const fe=J?J.scrollHeight-J.scrollTop-J.clientHeight:1/0;return{scrollerRef:n,innerRef:y,virtualItems:Q,totalSize:ue,measureItem:B,scrollToIndex:Y,scrollToOffset:V,captureAnchorSnapshot:N,resolveAnchorTop:$,isAtTop:G<=1,isAtBottom:fe<=1,scrollTop:G,jumpSuppressedRef:f}}function ve(i){var l;const{snapshot:e,currentScrollHeight:t,resolveAnchorTop:s}=i;if(e.key!==null){const o=s(e.key,e.offsetWithinItem);if(o!==null)return o}if((l=e.candidates)!=null&&l.length)for(const o of e.candidates){const n=s(o.key,o.offsetWithinItem);if(n!==null)return n}return e.scrollTop+(t-e.scrollHeight)}function ye(i){const{scrollerRef:e,itemCount:t,captureAnchorSnapshot:s,resolveAnchorTop:l,onRestored:o}=i,n=r.useRef(null),y=r.useRef(!1),u=r.useRef({first:null,second:null,timeout:null}),d=r.useCallback(()=>{const{first:h,second:p,timeout:I}=u.current;h&&cancelAnimationFrame(h),p&&cancelAnimationFrame(p),I&&clearTimeout(I),u.current={first:null,second:null,timeout:null}},[]),R=r.useCallback(()=>{const h=e.current;if(!h)return;const p=s();n.current=p??{key:null,offsetWithinItem:0,scrollTop:h.scrollTop,scrollHeight:h.scrollHeight},y.current=!0},[e,s]);return r.useLayoutEffect(()=>{if(!y.current)return;const h=e.current,p=n.current;if(!h||!p)return;y.current=!1;const I=()=>{const k=ve({snapshot:p,currentScrollHeight:h.scrollHeight,resolveAnchorTop:l});Number.isFinite(k)&&Math.abs(h.scrollTop-k)>1&&(h.scrollTop=k)};return d(),I(),o==null||o(),u.current.first=requestAnimationFrame(()=>{u.current.first=null,I(),u.current.second=requestAnimationFrame(()=>{u.current.second=null,I()})}),u.current.timeout=setTimeout(()=>{u.current.timeout=null,I()},90),()=>d()},[t,e,l,d,o]),{prepareAnchor:R}}function Te(i){const{previous:e,distanceFromBottom:t,threshold:s,hysteresis:l}=i;if(!l)return t<=s;const o=Math.max(0,l.enter),n=Math.max(o,l.leave);return e?t<=n:t<=o}function Se(i,e){const t=typeof e=="number"?e:e.threshold??200,s=typeof e=="number"?void 0:e.hysteresis,[l,o]=r.useState(!0),n=r.useRef(null),y=r.useRef(!0);return r.useEffect(()=>{const u=i.current;if(!u)return;const d=()=>{const h=u.scrollHeight-u.scrollTop-u.clientHeight,p=Te({previous:y.current,distanceFromBottom:h,threshold:t,hysteresis:s});y.current=p,o(p)},R=()=>{n.current!==null&&cancelAnimationFrame(n.current),n.current=requestAnimationFrame(d)};return u.addEventListener("scroll",R,{passive:!0}),d(),()=>{u.removeEventListener("scroll",R),n.current!==null&&cancelAnimationFrame(n.current)}},[i,t,s==null?void 0:s.enter,s==null?void 0:s.leave]),l}function be(i){const{itemCount:e,firstKey:t,lastKey:s,isAtBottom:l,scrollToIndex:o,mode:n}=i,y=r.useRef(e),u=r.useRef(t),d=r.useRef(s);r.useLayoutEffect(()=>{if(!n){y.current=e,u.current=t,d.current=s;return}const R=y.current,h=u.current,p=d.current;e>R&&t===h&&s!==p&&l&&e>0&&o(e-1,{align:"end",behavior:n==="smooth"?"smooth":"auto"}),y.current=e,u.current=t,d.current=s},[e,t,s,l,o,n])}function le(i){const{items:e,getKey:t,estimatedItemSize:s=80,overscan:l=20,atBottomThreshold:o=200,atBottomHysteresis:n,followOutput:y="auto",initialAlignment:u="bottom",scrollModifier:d=null,onStartReached:R,onEndReached:h,startReachedThreshold:p=300,endReachedThreshold:I=300,scrollToMessageKey:k,onScrollToMessageComplete:E}=i,a=ce({items:e,getKey:t,estimatedItemSize:s,overscan:l,initialAlignment:u}),w=Se(a.scrollerRef,{threshold:o,hysteresis:n??{enter:80,leave:160}}),[,g]=r.useState(0),F=r.useRef(null),T=r.useCallback(()=>{g(b=>b+1),F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{a.jumpSuppressedRef.current=!1,F.current=null},200)},[a.jumpSuppressedRef]),{prepareAnchor:j}=ye({scrollerRef:a.scrollerRef,itemCount:e.length,captureAnchorSnapshot:a.captureAnchorSnapshot,resolveAnchorTop:a.resolveAnchorTop,onRestored:T}),L=r.useCallback(()=>{a.jumpSuppressedRef.current=!0,j()},[j,a.jumpSuppressedRef]),D=e.length>0?t(e[0],0):null,K=e.length>0?t(e[e.length-1],e.length-1):null;be({itemCount:e.length,firstKey:D,lastKey:K,isAtBottom:w,scrollToIndex:a.scrollToIndex,mode:y??!1});const H=r.useCallback((b="auto")=>{e.length!==0&&a.scrollToIndex(e.length-1,{align:"end",behavior:b})},[e.length,a]),f=r.useCallback((b,B)=>{const V=e.findIndex((Y,N)=>t(Y,N)===b);V!==-1&&a.scrollToIndex(V,B)},[e,t,a]),S=r.useRef(null);r.useLayoutEffect(()=>{if(d&&S.current!==d.id){if(S.current=d.id,d.type==="prepend"){L();return}if(d.type==="append"){if(d.ifAtBottomOnly&&!w)return;H(d.behavior??"auto");return}if(d.type==="items-change"){w&&H("auto");return}f(d.key,{align:d.align??"center",behavior:d.behavior??"auto"})}},[d,w,L,H,f]);const v=r.useRef(!1),C=r.useRef(u==="top");r.useEffect(()=>{const b=a.scrollerRef.current;if(!b||!R)return;const B=()=>{const V=b.scrollTop;C.current||(b.scrollHeight<=b.clientHeight+p||V>p)&&(C.current=!0),C.current&&V<=p&&!v.current&&(v.current=!0,Promise.resolve(R()).finally(()=>{v.current=!1}))};return b.addEventListener("scroll",B,{passive:!0}),B(),()=>b.removeEventListener("scroll",B)},[a.scrollerRef,R,p,u]);const P=r.useRef(!1);r.useEffect(()=>{const b=a.scrollerRef.current;if(!b||!h)return;const B=()=>{b.scrollHeight-b.scrollTop-b.clientHeight<=I&&!P.current&&(P.current=!0,Promise.resolve(h()).finally(()=>{P.current=!1}))};return b.addEventListener("scroll",B,{passive:!0}),()=>b.removeEventListener("scroll",B)},[a.scrollerRef,h,I]);const U=r.useRef(null);return r.useEffect(()=>{if(!k||U.current===k)return;const b=e.findIndex((B,V)=>t(B,V)===k);b!==-1&&(U.current=k,a.scrollToIndex(b,{align:"center",behavior:"auto"}),E==null||E())},[k,e,t,a,E]),{scrollerRef:a.scrollerRef,innerRef:a.innerRef,virtualItems:a.virtualItems,totalSize:a.totalSize,measureItem:a.measureItem,scrollToIndex:a.scrollToIndex,scrollToBottom:H,scrollToKey:f,isAtBottom:w,prepareAnchor:L}}function ie({virtualItem:i,measureItem:e,children:t}){const s=r.useRef(null),l=r.useRef(!1);return r.useEffect(()=>{const o=s.current;if(!o)return;l.current=!1;const n=new ResizeObserver(([y])=>{y&&(l.current=!0,e(i.key,y.contentRect.height))});return n.observe(o),()=>n.disconnect()},[i.key,e]),q.jsx("div",{ref:s,style:{position:"absolute",top:0,transform:`translateY(${i.start}px)`,width:"100%",minHeight:l.current?void 0:i.size},children:t})}function Ae(i,e){const{data:t,itemContent:s,computeItemKey:l,estimatedItemSize:o=80,overscan:n=20,followOutput:y="auto",atBottomThreshold:u=200,atBottomHysteresis:d,initialAlignment:R="bottom",scrollModifier:h,onStartReached:p,onEndReached:I,startReachedThreshold:k=300,endReachedThreshold:E=300,scrollToMessageKey:a,onScrollToMessageComplete:w,onAtBottomChange:g,components:F={},className:T,style:j}=i,{scrollerRef:L,innerRef:D,virtualItems:K,totalSize:H,measureItem:f,scrollToIndex:S,scrollToBottom:v,scrollToKey:C,isAtBottom:P,prepareAnchor:U}=le({items:t,getKey:(N,$)=>l($,N),estimatedItemSize:o,overscan:n,atBottomThreshold:u,atBottomHysteresis:d,followOutput:y,initialAlignment:R,scrollModifier:h,onStartReached:p,onEndReached:I,startReachedThreshold:k,endReachedThreshold:E,scrollToMessageKey:a,onScrollToMessageComplete:w}),b=te.useRef(P);te.useEffect(()=>{b.current!==P&&(b.current=P,g==null||g(P))},[P,g]),r.useImperativeHandle(e,()=>({scrollToBottom:v,scrollToIndex:S,scrollToKey:C,getScrollTop:()=>{var N;return((N=L.current)==null?void 0:N.scrollTop)??0},isAtBottom:()=>P,prepareAnchor:U}),[v,S,C,L,P,U]);const{Header:B,Footer:V,EmptyPlaceholder:Y}=F;return t.length===0&&Y?q.jsx(Y,{}):q.jsxs("div",{ref:L,className:T,style:{overflow:"auto",height:"100%",position:"relative",overflowAnchor:"none",overscrollBehaviorY:"contain",...j},children:[B&&q.jsx(B,{}),q.jsx("div",{ref:D,style:{height:H,position:"relative",width:"100%"},children:K.map(N=>q.jsx(ie,{virtualItem:N,measureItem:f,children:s(N.index,N.data)},N.key))}),V&&q.jsx(V,{})]})}const ze=r.forwardRef(Ae);function xe({data:i,itemContent:e,computeItemKey:t,estimatedItemSize:s=60,overscan:l=20,onEndReached:o,endReachedThreshold:n=300,components:y={},className:u,style:d}){const{scrollerRef:R,innerRef:h,virtualItems:p,totalSize:I,measureItem:k}=ce({items:i,getKey:(g,F)=>t(F,g),estimatedItemSize:s,overscan:l,initialAlignment:"top"});te.useEffect(()=>{const g=R.current;if(!g||!o)return;let F=!1;const T=()=>{g.scrollHeight-g.scrollTop-g.clientHeight<=n&&!F&&(F=!0,Promise.resolve(o()).finally(()=>{F=!1}))};return g.addEventListener("scroll",T,{passive:!0}),()=>g.removeEventListener("scroll",T)},[R,o,n]);const{Header:E,Footer:a,EmptyPlaceholder:w}=y;return i.length===0&&w?q.jsx(w,{}):q.jsxs("div",{ref:R,className:u,style:{overflow:"auto",height:"100%",position:"relative",overflowAnchor:"none",overscrollBehaviorY:"contain",...d},children:[E&&q.jsx(E,{}),q.jsx("div",{ref:h,style:{height:I,position:"relative",width:"100%"},children:p.map(g=>q.jsx(ie,{virtualItem:g,measureItem:k,children:e(g.index,g.data)},g.key))}),a&&q.jsx(a,{})]})}function Ie(i){const{fetcher:e,initialPage:t=1,direction:s="append",getKey:l,onPageLoaded:o,onError:n}=i,[y,u]=r.useState([]),[d,R]=r.useState(t),[h,p]=r.useState(!0),[I,k]=r.useState(!1),[E,a]=r.useState(!1),[w,g]=r.useState(!1),F=r.useRef(new Set),T=r.useRef(!1),j=r.useCallback(f=>l?f.filter(S=>{const v=l(S);return F.current.has(v)?!1:(F.current.add(v),!0)}):f,[l]),L=r.useCallback(async()=>{if(!(T.current||!h)){T.current=!0,g(!0);try{const f=d+1,S=await e(f),v=j(S.data);u(C=>s==="prepend"?[...v,...C]:[...C,...v]),R(f),p(S.hasNextPage),k(S.hasPrevPage),o==null||o(f,v)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{g(!1),T.current=!1}}},[d,h,e,j,s,o,n]),D=r.useCallback(async()=>{if(!(T.current||!I)){T.current=!0,g(!0);try{const f=d-1,S=await e(f),v=j(S.data);u(C=>[...v,...C]),R(f),k(S.hasPrevPage),p(S.hasNextPage),o==null||o(f,v)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{g(!1),T.current=!1}}},[d,I,e,j,o,n]),K=r.useCallback(async()=>{if(!T.current){T.current=!0,a(!0);try{const f=await e(t),S=f.data;if(l){const v=new Set(S.map(l));S.forEach(C=>F.current.add(l(C))),u(C=>{const P=C.filter(U=>!v.has(l(U)));return s==="prepend"?[...S,...P]:[...P,...S]})}else u(S);R(t),p(f.hasNextPage),k(f.hasPrevPage),o==null||o(t,S)}catch(f){n==null||n(f instanceof Error?f:new Error(String(f)))}finally{a(!1),T.current=!1}}},[e,t,l,s,o,n]),H=r.useCallback(()=>{u([]),R(t),p(!0),k(!1),a(!1),g(!1),F.current.clear(),T.current=!1},[t]);return{items:y,loadNextPage:L,loadPrevPage:D,hasNextPage:h,hasPrevPage:I,loading:E,loadingMore:w,refresh:K,reset:H,currentPage:d}}exports.ChatVirtualList=ze;exports.VirtualList=xe;exports.useChatVirtualizer=le;exports.usePagination=Ie;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as J, jsxs as ae } from "react/jsx-runtime";
2
2
  import * as oe from "react";
3
- import { useRef as d, useCallback as k, useState as Y, useEffect as D, useLayoutEffect as ee, forwardRef as ge, useImperativeHandle as ve } from "react";
3
+ import { useRef as m, useCallback as k, useState as X, useEffect as $, useLayoutEffect as Z, forwardRef as ge, useImperativeHandle as ve } from "react";
4
4
  class Te {
5
5
  constructor(e, t) {
6
6
  this.defaultSize = t, this.sizes = e > 0 ? Array(e).fill(t) : [], this.offsets = e > 0 ? Array(e).fill(0) : [], e > 0 && this._recalcFrom(0);
@@ -75,133 +75,133 @@ class ye {
75
75
  }
76
76
  }
77
77
  }
78
- function ue(f, e) {
79
- if (f.length === 0) return 0;
80
- let t = 0, s = f.length - 1;
78
+ function ue(a, e) {
79
+ if (a.length === 0) return 0;
80
+ let t = 0, s = a.length - 1;
81
81
  for (; t < s; ) {
82
82
  const c = t + s >> 1;
83
- (f[c] ?? 0) < e ? t = c + 1 : s = c;
83
+ (a[c] ?? 0) < e ? t = c + 1 : s = c;
84
84
  }
85
- return Math.max(0, t > 0 && (f[t] ?? 0) > e ? t - 1 : t);
85
+ return Math.max(0, t > 0 && (a[t] ?? 0) > e ? t - 1 : t);
86
86
  }
87
- function Se(f, e, t) {
88
- if (f.length === 0) return 0;
89
- let s = 0, c = f.length - 1, n = 0;
87
+ function Se(a, e, t) {
88
+ if (a.length === 0) return 0;
89
+ let s = 0, c = a.length - 1, n = 0;
90
90
  for (; s <= c; ) {
91
91
  const r = s + c >> 1;
92
- (f[r] ?? 0) < t ? (n = r, s = r + 1) : c = r - 1;
92
+ (a[r] ?? 0) < t ? (n = r, s = r + 1) : c = r - 1;
93
93
  }
94
94
  return n;
95
95
  }
96
- function Ae(f) {
97
- const { firstVisible: e, lastVisible: t, itemCount: s, overscan: c } = f;
96
+ function Ae(a) {
97
+ const { firstVisible: e, lastVisible: t, itemCount: s, overscan: c } = a;
98
98
  return s === 0 ? { start: 0, end: -1 } : {
99
99
  start: Math.max(0, e - c),
100
100
  end: Math.min(s - 1, t + c)
101
101
  };
102
102
  }
103
- function Re(f, e, t, s) {
104
- const c = s == null ? void 0 : s.reconcile, n = d(null);
103
+ function ze(a, e, t, s) {
104
+ const c = s == null ? void 0 : s.reconcile, n = m(null);
105
105
  return k(
106
106
  (r, y) => {
107
- const l = f.current, h = e.current;
107
+ const l = a.current, h = e.current;
108
108
  if (!l || !h) return;
109
109
  n.current !== null && (cancelAnimationFrame(n.current), n.current = null);
110
- let v, i;
111
- if (typeof r == "object" && r !== null ? (v = r.index, i = {
110
+ let v, f;
111
+ if (typeof r == "object" && r !== null ? (v = r.index, f = {
112
112
  align: r.align,
113
113
  behavior: r.behavior,
114
114
  offset: r.offset
115
- }) : (v = r, i = y), !Number.isFinite(v)) return;
115
+ }) : (v = r, f = y), !Number.isFinite(v)) return;
116
116
  const p = Math.max(0, Math.min(Math.floor(v), h.count - 1));
117
117
  h.getOffset(p), h.getSize(p);
118
- const H = (i == null ? void 0 : i.align) ?? "start", K = (i == null ? void 0 : i.behavior) ?? "auto", F = (i == null ? void 0 : i.offset) ?? 0, a = () => {
118
+ const F = (f == null ? void 0 : f.align) ?? "start", M = (f == null ? void 0 : f.behavior) ?? "auto", K = (f == null ? void 0 : f.offset) ?? 0, i = () => {
119
119
  var B;
120
- const M = e.current, u = f.current;
121
- if (!M || !u) return 0;
122
- const A = ((B = t == null ? void 0 : t.current) == null ? void 0 : B.offsetTop) ?? 0, T = M.getOffset(p), w = M.getSize(p);
123
- return H === "start" ? A + T + F : H === "center" ? A + T - u.clientHeight / 2 + w / 2 + F : A + T - u.clientHeight + w + F;
124
- }, E = a();
125
- ((M, u) => {
126
- typeof l.scrollTo == "function" ? l.scrollTo({ top: M, behavior: u }) : l.scrollTop = M;
127
- })(Math.max(0, E), K);
120
+ const H = e.current, u = a.current;
121
+ if (!H || !u) return 0;
122
+ const A = ((B = t == null ? void 0 : t.current) == null ? void 0 : B.offsetTop) ?? 0, T = H.getOffset(p), w = H.getSize(p);
123
+ return F === "start" ? A + T + K : F === "center" ? A + T - u.clientHeight / 2 + w / 2 + K : A + T - u.clientHeight + w + K;
124
+ }, E = i();
125
+ ((H, u) => {
126
+ typeof l.scrollTo == "function" ? l.scrollTo({ top: H, behavior: u }) : l.scrollTop = H;
127
+ })(Math.max(0, E), M);
128
128
  const b = performance.now();
129
129
  let S = 0;
130
- const C = 12, j = 300, W = 1, O = () => {
130
+ const C = 12, j = 300, U = 1, L = () => {
131
131
  n.current = null;
132
- const M = f.current;
133
- if (!M) return;
134
- const u = Math.max(0, a()), A = Math.abs(M.scrollTop - u), T = performance.now() - b >= j, w = S >= C;
135
- A <= W || T || w || (typeof M.scrollTo == "function" ? M.scrollTo({ top: u, behavior: "auto" }) : M.scrollTop = u, S += 1, n.current = requestAnimationFrame(O));
132
+ const H = a.current;
133
+ if (!H) return;
134
+ const u = Math.max(0, i()), A = Math.abs(H.scrollTop - u), T = performance.now() - b >= j, w = S >= C;
135
+ A <= U || T || w || (typeof H.scrollTo == "function" ? H.scrollTo({ top: u, behavior: "auto" }) : H.scrollTop = u, S += 1, n.current = requestAnimationFrame(L));
136
136
  };
137
- n.current = requestAnimationFrame(O);
137
+ n.current = requestAnimationFrame(L);
138
138
  },
139
- [f, e, t, c]
139
+ [a, e, t, c]
140
140
  );
141
141
  }
142
- function fe(f) {
142
+ function fe(a) {
143
143
  var ie;
144
- const { items: e, getKey: t, estimatedItemSize: s, overscan: c, initialAlignment: n } = f, r = d(null), y = d(null), l = d(null), h = d(new ye()), v = d([]), i = d(/* @__PURE__ */ new Map()), p = d(e.length), H = d(null), K = d(null), F = d(!1), a = d(0), E = d(0), g = d(null), b = d(!1), S = d(null), C = d(0), j = d(0), W = d(0), O = d(null), M = d(!1), u = d(!1), [, A] = Y(0), T = k(() => A((o) => o + 1), []);
144
+ const { items: e, getKey: t, estimatedItemSize: s, overscan: c, initialAlignment: n } = a, r = m(null), y = m(null), l = m(null), h = m(new ye()), v = m([]), f = m(/* @__PURE__ */ new Map()), p = m(e.length), F = m(null), M = m(null), K = m(!1), i = m(0), E = m(0), g = m(null), b = m(!1), S = m(null), C = m(0), j = m(0), U = m(0), L = m(null), H = m(!1), u = m(!1), [, A] = X(0), T = k(() => A((o) => o + 1), []);
145
145
  l.current || (l.current = new Te(e.length, s));
146
146
  const w = e.length > 0 ? t(e[0], 0) : null, B = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
147
- if (e.length !== p.current || w !== H.current || B !== K.current) {
148
- const o = l.current, m = e.map((N, _) => t(N, _)), x = v.current, I = x.length, P = m.length;
147
+ if (e.length !== p.current || w !== F.current || B !== M.current) {
148
+ const o = l.current, d = e.map((V, W) => t(V, W)), x = v.current, I = x.length, P = d.length;
149
149
  if (P === 0)
150
150
  o.resize(0);
151
151
  else if (I === 0)
152
152
  o.resize(P);
153
153
  else if (P > I) {
154
- const N = P - I;
155
- x.length > 0 && N >= 0 && m[N] === x[0] ? o.prepend(N) : o.resize(P);
154
+ const V = P - I;
155
+ x.length > 0 && V >= 0 && d[V] === x[0] ? o.prepend(V) : o.resize(P);
156
156
  } else P < I, o.resize(P);
157
- const z = /* @__PURE__ */ new Map();
158
- m.forEach((N, _) => z.set(N, _)), i.current = z, h.current.applyToOffsetMap(o, z), v.current = m, p.current = e.length, H.current = w, K.current = B;
157
+ const R = /* @__PURE__ */ new Map();
158
+ d.forEach((V, W) => R.set(V, W)), f.current = R, h.current.applyToOffsetMap(o, R), v.current = d, p.current = e.length, F.current = w, M.current = B;
159
159
  }
160
- const R = k(() => {
161
- O.current === null && (O.current = requestAnimationFrame(() => {
162
- O.current = null;
160
+ const z = k(() => {
161
+ L.current === null && (L.current = requestAnimationFrame(() => {
162
+ L.current = null;
163
163
  const o = r.current;
164
164
  if (!o) return;
165
- const m = C.current;
166
- Math.abs(m) < 0.01 || (C.current = 0, j.current += m, W.current += m, o.scrollTop += m, a.current = o.scrollTop, M.current = !0, T());
165
+ const d = C.current;
166
+ Math.abs(d) < 0.01 || (C.current = 0, j.current += d, U.current += d, o.scrollTop += d, i.current = o.scrollTop, H.current = !0, T());
167
167
  }));
168
168
  }, [T]);
169
- D(() => {
169
+ $(() => {
170
170
  const o = r.current;
171
171
  if (!o) return;
172
- const m = () => {
172
+ const d = () => {
173
173
  g.current === null && (g.current = requestAnimationFrame(() => {
174
- g.current = null, a.current = o.scrollTop, E.current = o.clientHeight, M.current && (M.current = !1, j.current = 0, W.current = 0), T();
174
+ g.current = null, i.current = o.scrollTop, E.current = o.clientHeight, H.current && (H.current = !1, j.current = 0, U.current = 0), T();
175
175
  }));
176
176
  };
177
- return o.addEventListener("scroll", m, { passive: !0 }), () => {
178
- o.removeEventListener("scroll", m), g.current !== null && (cancelAnimationFrame(g.current), g.current = null), O.current !== null && (cancelAnimationFrame(O.current), O.current = null);
177
+ return o.addEventListener("scroll", d, { passive: !0 }), () => {
178
+ o.removeEventListener("scroll", d), g.current !== null && (cancelAnimationFrame(g.current), g.current = null), L.current !== null && (cancelAnimationFrame(L.current), L.current = null);
179
179
  };
180
- }, [T]), D(() => {
180
+ }, [T]), $(() => {
181
181
  const o = r.current;
182
182
  if (!o) return;
183
- E.current = o.clientHeight, a.current = o.scrollTop;
184
- const m = new ResizeObserver(([x]) => {
183
+ E.current = o.clientHeight, i.current = o.scrollTop;
184
+ const d = new ResizeObserver(([x]) => {
185
185
  x && (E.current = x.contentRect.height, T());
186
186
  });
187
- return m.observe(o), () => m.disconnect();
188
- }, [T]), ee(() => {
189
- if (F.current || e.length === 0) return;
187
+ return d.observe(o), () => d.disconnect();
188
+ }, [T]), Z(() => {
189
+ if (K.current || e.length === 0) return;
190
190
  const o = r.current;
191
191
  if (o) {
192
192
  if (n === "bottom") {
193
- o.scrollTop = o.scrollHeight, a.current = o.scrollTop, E.current = o.clientHeight, b.current = !0, S.current !== null && cancelAnimationFrame(S.current);
194
- const m = performance.now();
193
+ o.scrollTop = o.scrollHeight, i.current = o.scrollTop, E.current = o.clientHeight, b.current = !0, S.current !== null && cancelAnimationFrame(S.current);
194
+ const d = performance.now();
195
195
  let x = 0, I = o.scrollHeight;
196
196
  const P = () => {
197
197
  if (!b.current) {
198
198
  S.current = null;
199
199
  return;
200
200
  }
201
- const z = o.scrollHeight, N = Math.abs(z - I);
202
- I = z, N < 1 ? x += 1 : x = 0, o.scrollTop = o.scrollHeight, a.current = o.scrollTop;
203
- const _ = performance.now() - m;
204
- if (x >= 3 || _ >= 500) {
201
+ const R = o.scrollHeight, V = Math.abs(R - I);
202
+ I = R, V < 1 ? x += 1 : x = 0, o.scrollTop = o.scrollHeight, i.current = o.scrollTop;
203
+ const W = performance.now() - d;
204
+ if (x >= 3 || W >= 500) {
205
205
  b.current = !1, S.current = null;
206
206
  return;
207
207
  }
@@ -209,111 +209,107 @@ function fe(f) {
209
209
  };
210
210
  S.current = requestAnimationFrame(P);
211
211
  }
212
- F.current = !0;
212
+ K.current = !0;
213
213
  }
214
- }, [n, e.length]), D(() => {
215
- e.length === 0 && (F.current = !1, b.current = !1, S.current !== null && (cancelAnimationFrame(S.current), S.current = null));
214
+ }, [n, e.length]), $(() => {
215
+ e.length === 0 && (K.current = !1, b.current = !1, S.current !== null && (cancelAnimationFrame(S.current), S.current = null));
216
216
  }, [e.length]);
217
- const L = k((o, m) => {
217
+ const O = k((o, d) => {
218
218
  var Q;
219
219
  const x = l.current;
220
- if (!x || h.current.get(o) === m) return;
221
- h.current.set(o, m);
222
- const P = i.current.get(o);
220
+ if (!x || h.current.get(o) === d) return;
221
+ h.current.set(o, d);
222
+ const P = f.current.get(o);
223
223
  if (P === void 0) return;
224
- const z = x.getSize(P), N = m - z, _ = r.current;
225
- if (_ && !b.current && !u.current && N !== 0) {
226
- const Z = x.getOffset(P) + z + (((Q = y.current) == null ? void 0 : Q.offsetTop) ?? 0);
227
- Z < _.scrollTop && (console.log(`[JUMP] key=${o} idx=${P} delta=${N} itemBottom=${Math.round(Z)} scrollTop=${Math.round(_.scrollTop)} suppressed=${u.current}`), C.current += N, R());
228
- }
229
- x.setSize(P, m) && T();
230
- }, [R, T]), V = k(
231
- (o, m = "auto") => {
224
+ const R = x.getSize(P), V = d - R, W = r.current;
225
+ W && !b.current && !u.current && V !== 0 && x.getOffset(P) + R + (((Q = y.current) == null ? void 0 : Q.offsetTop) ?? 0) < W.scrollTop && (C.current += V, z()), x.setSize(P, d) && T();
226
+ }, [z, T]), N = k(
227
+ (o, d = "auto") => {
232
228
  var x;
233
- (x = r.current) == null || x.scrollTo({ top: o, behavior: m });
229
+ (x = r.current) == null || x.scrollTo({ top: o, behavior: d });
234
230
  },
235
231
  []
236
- ), G = Re(r, l, y, {
232
+ ), G = ze(r, l, y, {
237
233
  reconcile: !0
238
- }), $ = k(() => {
239
- var se;
240
- const o = r.current, m = l.current;
241
- if (!o || !m || m.count === 0) return null;
242
- const x = ((se = y.current) == null ? void 0 : se.offsetTop) ?? 0, I = Math.max(0, o.scrollTop - x), P = m.getOffsets(), z = ue(P, I), N = v.current[z] ?? null, _ = [];
243
- for (let Q = z; Q < Math.min(m.count, z + 6); Q++) {
244
- const Z = v.current[Q] ?? null;
245
- Z !== null && _.push({
246
- key: Z,
247
- offsetWithinItem: I - m.getOffset(Q)
234
+ }), q = k(() => {
235
+ var ne;
236
+ const o = r.current, d = l.current;
237
+ if (!o || !d || d.count === 0) return null;
238
+ const x = ((ne = y.current) == null ? void 0 : ne.offsetTop) ?? 0, I = Math.max(0, o.scrollTop - x), P = d.getOffsets(), R = ue(P, I), V = v.current[R] ?? null, W = [];
239
+ for (let Q = R; Q < Math.min(d.count, R + 6); Q++) {
240
+ const se = v.current[Q] ?? null;
241
+ se !== null && W.push({
242
+ key: se,
243
+ offsetWithinItem: I - d.getOffset(Q)
248
244
  });
249
245
  }
250
246
  return {
251
- key: N,
252
- offsetWithinItem: I - m.getOffset(z),
253
- candidates: _,
247
+ key: V,
248
+ offsetWithinItem: I - d.getOffset(R),
249
+ candidates: W,
254
250
  scrollTop: o.scrollTop,
255
251
  scrollHeight: o.scrollHeight
256
252
  };
257
- }, []), te = k(
258
- (o, m) => {
259
- var z;
253
+ }, []), ee = k(
254
+ (o, d) => {
255
+ var R;
260
256
  const x = l.current;
261
257
  if (!x) return null;
262
- const I = i.current.get(o);
263
- return I === void 0 ? null : (((z = y.current) == null ? void 0 : z.offsetTop) ?? 0) + x.getOffset(I) + m;
258
+ const I = f.current.get(o);
259
+ return I === void 0 ? null : (((R = y.current) == null ? void 0 : R.offsetTop) ?? 0) + x.getOffset(I) + d;
264
260
  },
265
261
  []
266
- ), q = l.current, de = q ? q.totalSize() : 0, U = r.current, re = (U == null ? void 0 : U.scrollTop) ?? a.current, ce = (U == null ? void 0 : U.clientHeight) ?? E.current, me = ((ie = y.current) == null ? void 0 : ie.offsetTop) ?? 0, le = Math.max(0, re - me), ne = [];
267
- if (q && q.count > 0 && ce > 0) {
268
- const o = q.getOffsets(), m = q.getSizes(), x = ue(o, le), I = Se(
262
+ ), _ = l.current, me = _ ? _.totalSize() : 0, Y = r.current, te = (Y == null ? void 0 : Y.scrollTop) ?? i.current, ce = (Y == null ? void 0 : Y.clientHeight) ?? E.current, de = ((ie = y.current) == null ? void 0 : ie.offsetTop) ?? 0, le = Math.max(0, te - de), re = [];
263
+ if (_ && _.count > 0 && ce > 0) {
264
+ const o = _.getOffsets(), d = _.getSizes(), x = ue(o, le), I = Se(
269
265
  o,
270
- m,
266
+ d,
271
267
  le + ce
272
268
  ), P = Ae({
273
269
  firstVisible: x,
274
270
  lastVisible: I,
275
- itemCount: q.count,
271
+ itemCount: _.count,
276
272
  overscan: c
277
273
  });
278
- for (let z = P.start; z <= P.end && z < e.length; z++)
279
- ne.push({
280
- key: v.current[z] ?? t(e[z], z),
281
- index: z,
282
- start: q.getOffset(z),
283
- size: q.getSize(z),
284
- data: e[z]
274
+ for (let R = P.start; R <= P.end && R < e.length; R++)
275
+ re.push({
276
+ key: v.current[R] ?? t(e[R], R),
277
+ index: R,
278
+ start: _.getOffset(R),
279
+ size: _.getSize(R),
280
+ data: e[R]
285
281
  });
286
- } else if (q && q.count > 0) {
287
- const o = Math.min(e.length, c * 2 + 1), m = n === "bottom" ? Math.max(0, e.length - o) : 0, x = m + o - 1;
288
- for (let I = m; I <= x; I++)
289
- ne.push({
282
+ } else if (_ && _.count > 0) {
283
+ const o = Math.min(e.length, c * 2 + 1), d = n === "bottom" ? Math.max(0, e.length - o) : 0, x = d + o - 1;
284
+ for (let I = d; I <= x; I++)
285
+ re.push({
290
286
  key: v.current[I] ?? t(e[I], I),
291
287
  index: I,
292
- start: q.getOffset(I),
293
- size: q.getSize(I),
288
+ start: _.getOffset(I),
289
+ size: _.getSize(I),
294
290
  data: e[I]
295
291
  });
296
292
  }
297
- const pe = U ? U.scrollHeight - U.scrollTop - U.clientHeight : 1 / 0;
293
+ const pe = Y ? Y.scrollHeight - Y.scrollTop - Y.clientHeight : 1 / 0;
298
294
  return {
299
295
  scrollerRef: r,
300
296
  innerRef: y,
301
- virtualItems: ne,
302
- totalSize: de,
303
- measureItem: L,
297
+ virtualItems: re,
298
+ totalSize: me,
299
+ measureItem: O,
304
300
  scrollToIndex: G,
305
- scrollToOffset: V,
306
- captureAnchorSnapshot: $,
307
- resolveAnchorTop: te,
308
- isAtTop: re <= 1,
301
+ scrollToOffset: N,
302
+ captureAnchorSnapshot: q,
303
+ resolveAnchorTop: ee,
304
+ isAtTop: te <= 1,
309
305
  isAtBottom: pe <= 1,
310
- scrollTop: re,
306
+ scrollTop: te,
311
307
  jumpSuppressedRef: u
312
308
  };
313
309
  }
314
- function ze(f) {
310
+ function Re(a) {
315
311
  var c;
316
- const { snapshot: e, currentScrollHeight: t, resolveAnchorTop: s } = f;
312
+ const { snapshot: e, currentScrollHeight: t, resolveAnchorTop: s } = a;
317
313
  if (e.key !== null) {
318
314
  const n = s(e.key, e.offsetWithinItem);
319
315
  if (n !== null) return n;
@@ -325,68 +321,68 @@ function ze(f) {
325
321
  }
326
322
  return e.scrollTop + (t - e.scrollHeight);
327
323
  }
328
- function xe(f) {
324
+ function xe(a) {
329
325
  const {
330
326
  scrollerRef: e,
331
327
  itemCount: t,
332
328
  captureAnchorSnapshot: s,
333
329
  resolveAnchorTop: c,
334
330
  onRestored: n
335
- } = f, r = d(null), y = d(!1), l = d({
331
+ } = a, r = m(null), y = m(!1), l = m({
336
332
  first: null,
337
333
  second: null,
338
334
  timeout: null
339
335
  }), h = k(() => {
340
- const { first: i, second: p, timeout: H } = l.current;
341
- i && cancelAnimationFrame(i), p && cancelAnimationFrame(p), H && clearTimeout(H), l.current = { first: null, second: null, timeout: null };
336
+ const { first: f, second: p, timeout: F } = l.current;
337
+ f && cancelAnimationFrame(f), p && cancelAnimationFrame(p), F && clearTimeout(F), l.current = { first: null, second: null, timeout: null };
342
338
  }, []), v = k(() => {
343
- const i = e.current;
344
- if (!i) return;
339
+ const f = e.current;
340
+ if (!f) return;
345
341
  const p = s();
346
342
  r.current = p ?? {
347
343
  key: null,
348
344
  offsetWithinItem: 0,
349
- scrollTop: i.scrollTop,
350
- scrollHeight: i.scrollHeight
351
- }, y.current = !0, console.log("[ANCHOR] prepareAnchor snapshot:", JSON.stringify(r.current, null, 2));
345
+ scrollTop: f.scrollTop,
346
+ scrollHeight: f.scrollHeight
347
+ }, y.current = !0;
352
348
  }, [e, s]);
353
- return ee(() => {
349
+ return Z(() => {
354
350
  if (!y.current) return;
355
- const i = e.current, p = r.current;
356
- if (!i || !p) return;
351
+ const f = e.current, p = r.current;
352
+ if (!f || !p) return;
357
353
  y.current = !1;
358
- const H = (K) => {
359
- const F = ze({
354
+ const F = () => {
355
+ const M = Re({
360
356
  snapshot: p,
361
- currentScrollHeight: i.scrollHeight,
357
+ currentScrollHeight: f.scrollHeight,
362
358
  resolveAnchorTop: c
363
359
  });
364
- console.log(`[ANCHOR] restore(${K}): target=${Math.round(F)}, currentScrollTop=${Math.round(i.scrollTop)}, scrollHeight=${i.scrollHeight}, snapshotKey=${p.key}, delta=${Math.round(F - i.scrollTop)}`), Number.isFinite(F) && Math.abs(i.scrollTop - F) > 1 && (i.scrollTop = F);
360
+ Number.isFinite(M) && Math.abs(f.scrollTop - M) > 1 && (f.scrollTop = M);
365
361
  };
366
- return h(), H("layout"), n == null || n(), l.current.first = requestAnimationFrame(() => {
367
- l.current.first = null, H("raf1"), l.current.second = requestAnimationFrame(() => {
368
- l.current.second = null, H("raf2");
362
+ return h(), F(), n == null || n(), l.current.first = requestAnimationFrame(() => {
363
+ l.current.first = null, F(), l.current.second = requestAnimationFrame(() => {
364
+ l.current.second = null, F();
369
365
  });
370
366
  }), l.current.timeout = setTimeout(() => {
371
- l.current.timeout = null, H("timeout");
367
+ l.current.timeout = null, F();
372
368
  }, 90), () => h();
373
369
  }, [t, e, c, h, n]), { prepareAnchor: v };
374
370
  }
375
- function Ie(f) {
376
- const { previous: e, distanceFromBottom: t, threshold: s, hysteresis: c } = f;
371
+ function Ie(a) {
372
+ const { previous: e, distanceFromBottom: t, threshold: s, hysteresis: c } = a;
377
373
  if (!c) return t <= s;
378
374
  const n = Math.max(0, c.enter), r = Math.max(n, c.leave);
379
375
  return e ? t <= r : t <= n;
380
376
  }
381
- function Fe(f, e) {
382
- const t = typeof e == "number" ? e : e.threshold ?? 200, s = typeof e == "number" ? void 0 : e.hysteresis, [c, n] = Y(!0), r = d(null), y = d(!0);
383
- return D(() => {
384
- const l = f.current;
377
+ function Fe(a, e) {
378
+ const t = typeof e == "number" ? e : e.threshold ?? 200, s = typeof e == "number" ? void 0 : e.hysteresis, [c, n] = X(!0), r = m(null), y = m(!0);
379
+ return $(() => {
380
+ const l = a.current;
385
381
  if (!l) return;
386
382
  const h = () => {
387
- const i = l.scrollHeight - l.scrollTop - l.clientHeight, p = Ie({
383
+ const f = l.scrollHeight - l.scrollTop - l.clientHeight, p = Ie({
388
384
  previous: y.current,
389
- distanceFromBottom: i,
385
+ distanceFromBottom: f,
390
386
  threshold: t,
391
387
  hysteresis: s
392
388
  });
@@ -397,23 +393,23 @@ function Fe(f, e) {
397
393
  return l.addEventListener("scroll", v, { passive: !0 }), h(), () => {
398
394
  l.removeEventListener("scroll", v), r.current !== null && cancelAnimationFrame(r.current);
399
395
  };
400
- }, [f, t, s == null ? void 0 : s.enter, s == null ? void 0 : s.leave]), c;
396
+ }, [a, t, s == null ? void 0 : s.enter, s == null ? void 0 : s.leave]), c;
401
397
  }
402
- function He(f) {
403
- const { itemCount: e, firstKey: t, lastKey: s, isAtBottom: c, scrollToIndex: n, mode: r } = f, y = d(e), l = d(t), h = d(s);
404
- ee(() => {
398
+ function be(a) {
399
+ const { itemCount: e, firstKey: t, lastKey: s, isAtBottom: c, scrollToIndex: n, mode: r } = a, y = m(e), l = m(t), h = m(s);
400
+ Z(() => {
405
401
  if (!r) {
406
402
  y.current = e, l.current = t, h.current = s;
407
403
  return;
408
404
  }
409
- const v = y.current, i = l.current, p = h.current;
410
- e > v && t === i && s !== p && c && e > 0 && n(e - 1, {
405
+ const v = y.current, f = l.current, p = h.current;
406
+ e > v && t === f && s !== p && c && e > 0 && n(e - 1, {
411
407
  align: "end",
412
408
  behavior: r === "smooth" ? "smooth" : "auto"
413
409
  }), y.current = e, l.current = t, h.current = s;
414
410
  }, [e, t, s, c, n, r]);
415
411
  }
416
- function be(f) {
412
+ function He(a) {
417
413
  const {
418
414
  items: e,
419
415
  getKey: t,
@@ -425,54 +421,54 @@ function be(f) {
425
421
  initialAlignment: l = "bottom",
426
422
  scrollModifier: h = null,
427
423
  onStartReached: v,
428
- onEndReached: i,
424
+ onEndReached: f,
429
425
  startReachedThreshold: p = 300,
430
- endReachedThreshold: H = 300,
431
- scrollToMessageKey: K,
432
- onScrollToMessageComplete: F
433
- } = f, a = fe({
426
+ endReachedThreshold: F = 300,
427
+ scrollToMessageKey: M,
428
+ onScrollToMessageComplete: K
429
+ } = a, i = fe({
434
430
  items: e,
435
431
  getKey: t,
436
432
  estimatedItemSize: s,
437
433
  overscan: c,
438
434
  initialAlignment: l
439
- }), E = Fe(a.scrollerRef, {
435
+ }), E = Fe(i.scrollerRef, {
440
436
  threshold: n,
441
437
  hysteresis: r ?? { enter: 80, leave: 160 }
442
- }), [, g] = Y(0), b = d(null), S = k(() => {
443
- g((R) => R + 1), b.current && clearTimeout(b.current), b.current = setTimeout(() => {
444
- a.jumpSuppressedRef.current = !1, b.current = null;
438
+ }), [, g] = X(0), b = m(null), S = k(() => {
439
+ g((z) => z + 1), b.current && clearTimeout(b.current), b.current = setTimeout(() => {
440
+ i.jumpSuppressedRef.current = !1, b.current = null;
445
441
  }, 200);
446
- }, [a.jumpSuppressedRef]), { prepareAnchor: C } = xe({
447
- scrollerRef: a.scrollerRef,
442
+ }, [i.jumpSuppressedRef]), { prepareAnchor: C } = xe({
443
+ scrollerRef: i.scrollerRef,
448
444
  itemCount: e.length,
449
- captureAnchorSnapshot: a.captureAnchorSnapshot,
450
- resolveAnchorTop: a.resolveAnchorTop,
445
+ captureAnchorSnapshot: i.captureAnchorSnapshot,
446
+ resolveAnchorTop: i.resolveAnchorTop,
451
447
  onRestored: S
452
448
  }), j = k(() => {
453
- a.jumpSuppressedRef.current = !0, C();
454
- }, [C, a.jumpSuppressedRef]), W = e.length > 0 ? t(e[0], 0) : null, O = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
455
- He({
449
+ i.jumpSuppressedRef.current = !0, C();
450
+ }, [C, i.jumpSuppressedRef]), U = e.length > 0 ? t(e[0], 0) : null, L = e.length > 0 ? t(e[e.length - 1], e.length - 1) : null;
451
+ be({
456
452
  itemCount: e.length,
457
- firstKey: W,
458
- lastKey: O,
453
+ firstKey: U,
454
+ lastKey: L,
459
455
  isAtBottom: E,
460
- scrollToIndex: a.scrollToIndex,
456
+ scrollToIndex: i.scrollToIndex,
461
457
  mode: y ?? !1
462
458
  });
463
- const M = k(
464
- (R = "auto") => {
465
- e.length !== 0 && a.scrollToIndex(e.length - 1, { align: "end", behavior: R });
459
+ const H = k(
460
+ (z = "auto") => {
461
+ e.length !== 0 && i.scrollToIndex(e.length - 1, { align: "end", behavior: z });
466
462
  },
467
- [e.length, a]
463
+ [e.length, i]
468
464
  ), u = k(
469
- (R, L) => {
470
- const V = e.findIndex((G, $) => t(G, $) === R);
471
- V !== -1 && a.scrollToIndex(V, L);
465
+ (z, O) => {
466
+ const N = e.findIndex((G, q) => t(G, q) === z);
467
+ N !== -1 && i.scrollToIndex(N, O);
472
468
  },
473
- [e, t, a]
474
- ), A = d(null);
475
- ee(() => {
469
+ [e, t, i]
470
+ ), A = m(null);
471
+ Z(() => {
476
472
  if (h && A.current !== h.id) {
477
473
  if (A.current = h.id, h.type === "prepend") {
478
474
  j();
@@ -480,11 +476,11 @@ function be(f) {
480
476
  }
481
477
  if (h.type === "append") {
482
478
  if (h.ifAtBottomOnly && !E) return;
483
- M(h.behavior ?? "auto");
479
+ H(h.behavior ?? "auto");
484
480
  return;
485
481
  }
486
482
  if (h.type === "items-change") {
487
- E && M("auto");
483
+ E && H("auto");
488
484
  return;
489
485
  }
490
486
  u(h.key, {
@@ -492,63 +488,63 @@ function be(f) {
492
488
  behavior: h.behavior ?? "auto"
493
489
  });
494
490
  }
495
- }, [h, E, j, M, u]);
496
- const T = d(!1), w = d(l === "top");
497
- D(() => {
498
- const R = a.scrollerRef.current;
499
- if (!R || !v) return;
500
- const L = () => {
501
- const V = R.scrollTop;
502
- w.current || (R.scrollHeight <= R.clientHeight + p || V > p) && (w.current = !0), w.current && V <= p && !T.current && (T.current = !0, Promise.resolve(v()).finally(() => {
491
+ }, [h, E, j, H, u]);
492
+ const T = m(!1), w = m(l === "top");
493
+ $(() => {
494
+ const z = i.scrollerRef.current;
495
+ if (!z || !v) return;
496
+ const O = () => {
497
+ const N = z.scrollTop;
498
+ w.current || (z.scrollHeight <= z.clientHeight + p || N > p) && (w.current = !0), w.current && N <= p && !T.current && (T.current = !0, Promise.resolve(v()).finally(() => {
503
499
  T.current = !1;
504
500
  }));
505
501
  };
506
- return R.addEventListener("scroll", L, { passive: !0 }), L(), () => R.removeEventListener("scroll", L);
507
- }, [a.scrollerRef, v, p, l]);
508
- const B = d(!1);
509
- D(() => {
510
- const R = a.scrollerRef.current;
511
- if (!R || !i) return;
512
- const L = () => {
513
- R.scrollHeight - R.scrollTop - R.clientHeight <= H && !B.current && (B.current = !0, Promise.resolve(i()).finally(() => {
502
+ return z.addEventListener("scroll", O, { passive: !0 }), O(), () => z.removeEventListener("scroll", O);
503
+ }, [i.scrollerRef, v, p, l]);
504
+ const B = m(!1);
505
+ $(() => {
506
+ const z = i.scrollerRef.current;
507
+ if (!z || !f) return;
508
+ const O = () => {
509
+ z.scrollHeight - z.scrollTop - z.clientHeight <= F && !B.current && (B.current = !0, Promise.resolve(f()).finally(() => {
514
510
  B.current = !1;
515
511
  }));
516
512
  };
517
- return R.addEventListener("scroll", L, { passive: !0 }), () => R.removeEventListener("scroll", L);
518
- }, [a.scrollerRef, i, H]);
519
- const X = d(null);
520
- return D(() => {
521
- if (!K || X.current === K) return;
522
- const R = e.findIndex((L, V) => t(L, V) === K);
523
- R !== -1 && (X.current = K, a.scrollToIndex(R, { align: "center", behavior: "auto" }), F == null || F());
524
- }, [K, e, t, a, F]), {
525
- scrollerRef: a.scrollerRef,
526
- innerRef: a.innerRef,
527
- virtualItems: a.virtualItems,
528
- totalSize: a.totalSize,
529
- measureItem: a.measureItem,
530
- scrollToIndex: a.scrollToIndex,
531
- scrollToBottom: M,
513
+ return z.addEventListener("scroll", O, { passive: !0 }), () => z.removeEventListener("scroll", O);
514
+ }, [i.scrollerRef, f, F]);
515
+ const D = m(null);
516
+ return $(() => {
517
+ if (!M || D.current === M) return;
518
+ const z = e.findIndex((O, N) => t(O, N) === M);
519
+ z !== -1 && (D.current = M, i.scrollToIndex(z, { align: "center", behavior: "auto" }), K == null || K());
520
+ }, [M, e, t, i, K]), {
521
+ scrollerRef: i.scrollerRef,
522
+ innerRef: i.innerRef,
523
+ virtualItems: i.virtualItems,
524
+ totalSize: i.totalSize,
525
+ measureItem: i.measureItem,
526
+ scrollToIndex: i.scrollToIndex,
527
+ scrollToBottom: H,
532
528
  scrollToKey: u,
533
529
  isAtBottom: E,
534
530
  prepareAnchor: j
535
531
  };
536
532
  }
537
533
  function he({
538
- virtualItem: f,
534
+ virtualItem: a,
539
535
  measureItem: e,
540
536
  children: t
541
537
  }) {
542
- const s = d(null), c = d(!1);
543
- return D(() => {
538
+ const s = m(null), c = m(!1);
539
+ return $(() => {
544
540
  const n = s.current;
545
541
  if (!n) return;
546
542
  c.current = !1;
547
543
  const r = new ResizeObserver(([y]) => {
548
- y && (c.current = !0, e(f.key, y.contentRect.height));
544
+ y && (c.current = !0, e(a.key, y.contentRect.height));
549
545
  });
550
546
  return r.observe(n), () => r.disconnect();
551
- }, [f.key, e]), /* @__PURE__ */ J(
547
+ }, [a.key, e]), /* @__PURE__ */ J(
552
548
  "div",
553
549
  {
554
550
  ref: s,
@@ -556,20 +552,20 @@ function he({
556
552
  position: "absolute",
557
553
  top: 0,
558
554
  // transform instead of top: avoids reflow, uses GPU compositor layer
559
- transform: `translateY(${f.start}px)`,
555
+ transform: `translateY(${a.start}px)`,
560
556
  width: "100%",
561
557
  // Only reserve estimated height before first measurement.
562
558
  // After measurement, let the item take its natural height so
563
559
  // ResizeObserver can accurately report the real size.
564
560
  // Without this, items can never be smaller than estimatedItemSize,
565
561
  // which distorts offsets and total height.
566
- minHeight: c.current ? void 0 : f.size
562
+ minHeight: c.current ? void 0 : a.size
567
563
  },
568
564
  children: t
569
565
  }
570
566
  );
571
567
  }
572
- function Me(f, e) {
568
+ function Me(a, e) {
573
569
  const {
574
570
  data: t,
575
571
  itemContent: s,
@@ -580,47 +576,47 @@ function Me(f, e) {
580
576
  atBottomThreshold: l = 200,
581
577
  atBottomHysteresis: h,
582
578
  initialAlignment: v = "bottom",
583
- scrollModifier: i,
579
+ scrollModifier: f,
584
580
  onStartReached: p,
585
- onEndReached: H,
586
- startReachedThreshold: K = 300,
587
- endReachedThreshold: F = 300,
588
- scrollToMessageKey: a,
581
+ onEndReached: F,
582
+ startReachedThreshold: M = 300,
583
+ endReachedThreshold: K = 300,
584
+ scrollToMessageKey: i,
589
585
  onScrollToMessageComplete: E,
590
586
  onAtBottomChange: g,
591
587
  components: b = {},
592
588
  className: S,
593
589
  style: C
594
- } = f, {
590
+ } = a, {
595
591
  scrollerRef: j,
596
- innerRef: W,
597
- virtualItems: O,
598
- totalSize: M,
592
+ innerRef: U,
593
+ virtualItems: L,
594
+ totalSize: H,
599
595
  measureItem: u,
600
596
  scrollToIndex: A,
601
597
  scrollToBottom: T,
602
598
  scrollToKey: w,
603
599
  isAtBottom: B,
604
- prepareAnchor: X
605
- } = be({
600
+ prepareAnchor: D
601
+ } = He({
606
602
  items: t,
607
- getKey: ($, te) => c(te, $),
603
+ getKey: (q, ee) => c(ee, q),
608
604
  estimatedItemSize: n,
609
605
  overscan: r,
610
606
  atBottomThreshold: l,
611
607
  atBottomHysteresis: h,
612
608
  followOutput: y,
613
609
  initialAlignment: v,
614
- scrollModifier: i,
610
+ scrollModifier: f,
615
611
  onStartReached: p,
616
- onEndReached: H,
617
- startReachedThreshold: K,
618
- endReachedThreshold: F,
619
- scrollToMessageKey: a,
612
+ onEndReached: F,
613
+ startReachedThreshold: M,
614
+ endReachedThreshold: K,
615
+ scrollToMessageKey: i,
620
616
  onScrollToMessageComplete: E
621
- }), R = oe.useRef(B);
617
+ }), z = oe.useRef(B);
622
618
  oe.useEffect(() => {
623
- R.current !== B && (R.current = B, g == null || g(B));
619
+ z.current !== B && (z.current = B, g == null || g(B));
624
620
  }, [B, g]), ve(
625
621
  e,
626
622
  () => ({
@@ -628,15 +624,15 @@ function Me(f, e) {
628
624
  scrollToIndex: A,
629
625
  scrollToKey: w,
630
626
  getScrollTop: () => {
631
- var $;
632
- return (($ = j.current) == null ? void 0 : $.scrollTop) ?? 0;
627
+ var q;
628
+ return ((q = j.current) == null ? void 0 : q.scrollTop) ?? 0;
633
629
  },
634
630
  isAtBottom: () => B,
635
- prepareAnchor: X
631
+ prepareAnchor: D
636
632
  }),
637
- [T, A, w, j, B, X]
633
+ [T, A, w, j, B, D]
638
634
  );
639
- const { Header: L, Footer: V, EmptyPlaceholder: G } = b;
635
+ const { Header: O, Footer: N, EmptyPlaceholder: G } = b;
640
636
  return t.length === 0 && G ? /* @__PURE__ */ J(G, {}) : /* @__PURE__ */ ae(
641
637
  "div",
642
638
  {
@@ -653,24 +649,24 @@ function Me(f, e) {
653
649
  ...C
654
650
  },
655
651
  children: [
656
- L && /* @__PURE__ */ J(L, {}),
657
- /* @__PURE__ */ J("div", { ref: W, style: { height: M, position: "relative", width: "100%" }, children: O.map(($) => /* @__PURE__ */ J(
652
+ O && /* @__PURE__ */ J(O, {}),
653
+ /* @__PURE__ */ J("div", { ref: U, style: { height: H, position: "relative", width: "100%" }, children: L.map((q) => /* @__PURE__ */ J(
658
654
  he,
659
655
  {
660
- virtualItem: $,
656
+ virtualItem: q,
661
657
  measureItem: u,
662
- children: s($.index, $.data)
658
+ children: s(q.index, q.data)
663
659
  },
664
- $.key
660
+ q.key
665
661
  )) }),
666
- V && /* @__PURE__ */ J(V, {})
662
+ N && /* @__PURE__ */ J(N, {})
667
663
  ]
668
664
  }
669
665
  );
670
666
  }
671
667
  const Ke = ge(Me);
672
668
  function Ee({
673
- data: f,
669
+ data: a,
674
670
  itemContent: e,
675
671
  computeItemKey: t,
676
672
  estimatedItemSize: s = 60,
@@ -681,8 +677,8 @@ function Ee({
681
677
  className: l,
682
678
  style: h
683
679
  }) {
684
- const { scrollerRef: v, innerRef: i, virtualItems: p, totalSize: H, measureItem: K } = fe({
685
- items: f,
680
+ const { scrollerRef: v, innerRef: f, virtualItems: p, totalSize: F, measureItem: M } = fe({
681
+ items: a,
686
682
  getKey: (g, b) => t(b, g),
687
683
  estimatedItemSize: s,
688
684
  overscan: c,
@@ -699,8 +695,8 @@ function Ee({
699
695
  };
700
696
  return g.addEventListener("scroll", S, { passive: !0 }), () => g.removeEventListener("scroll", S);
701
697
  }, [v, n, r]);
702
- const { Header: F, Footer: a, EmptyPlaceholder: E } = y;
703
- return f.length === 0 && E ? /* @__PURE__ */ J(E, {}) : /* @__PURE__ */ ae(
698
+ const { Header: K, Footer: i, EmptyPlaceholder: E } = y;
699
+ return a.length === 0 && E ? /* @__PURE__ */ J(E, {}) : /* @__PURE__ */ ae(
704
700
  "div",
705
701
  {
706
702
  ref: v,
@@ -715,22 +711,22 @@ function Ee({
715
711
  ...h
716
712
  },
717
713
  children: [
718
- F && /* @__PURE__ */ J(F, {}),
719
- /* @__PURE__ */ J("div", { ref: i, style: { height: H, position: "relative", width: "100%" }, children: p.map((g) => /* @__PURE__ */ J(
714
+ K && /* @__PURE__ */ J(K, {}),
715
+ /* @__PURE__ */ J("div", { ref: f, style: { height: F, position: "relative", width: "100%" }, children: p.map((g) => /* @__PURE__ */ J(
720
716
  he,
721
717
  {
722
718
  virtualItem: g,
723
- measureItem: K,
719
+ measureItem: M,
724
720
  children: e(g.index, g.data)
725
721
  },
726
722
  g.key
727
723
  )) }),
728
- a && /* @__PURE__ */ J(a, {})
724
+ i && /* @__PURE__ */ J(i, {})
729
725
  ]
730
726
  }
731
727
  );
732
728
  }
733
- function Be(f) {
729
+ function Be(a) {
734
730
  const {
735
731
  fetcher: e,
736
732
  initialPage: t = 1,
@@ -738,77 +734,77 @@ function Be(f) {
738
734
  getKey: c,
739
735
  onPageLoaded: n,
740
736
  onError: r
741
- } = f, [y, l] = Y([]), [h, v] = Y(t), [i, p] = Y(!0), [H, K] = Y(!1), [F, a] = Y(!1), [E, g] = Y(!1), b = d(/* @__PURE__ */ new Set()), S = d(!1), C = k(
737
+ } = a, [y, l] = X([]), [h, v] = X(t), [f, p] = X(!0), [F, M] = X(!1), [K, i] = X(!1), [E, g] = X(!1), b = m(/* @__PURE__ */ new Set()), S = m(!1), C = k(
742
738
  (u) => c ? u.filter((A) => {
743
739
  const T = c(A);
744
740
  return b.current.has(T) ? !1 : (b.current.add(T), !0);
745
741
  }) : u,
746
742
  [c]
747
743
  ), j = k(async () => {
748
- if (!(S.current || !i)) {
744
+ if (!(S.current || !f)) {
749
745
  S.current = !0, g(!0);
750
746
  try {
751
747
  const u = h + 1, A = await e(u), T = C(A.data);
752
748
  l(
753
749
  (w) => s === "prepend" ? [...T, ...w] : [...w, ...T]
754
- ), v(u), p(A.hasNextPage), K(A.hasPrevPage), n == null || n(u, T);
750
+ ), v(u), p(A.hasNextPage), M(A.hasPrevPage), n == null || n(u, T);
755
751
  } catch (u) {
756
752
  r == null || r(u instanceof Error ? u : new Error(String(u)));
757
753
  } finally {
758
754
  g(!1), S.current = !1;
759
755
  }
760
756
  }
761
- }, [h, i, e, C, s, n, r]), W = k(async () => {
762
- if (!(S.current || !H)) {
757
+ }, [h, f, e, C, s, n, r]), U = k(async () => {
758
+ if (!(S.current || !F)) {
763
759
  S.current = !0, g(!0);
764
760
  try {
765
761
  const u = h - 1, A = await e(u), T = C(A.data);
766
- l((w) => [...T, ...w]), v(u), K(A.hasPrevPage), p(A.hasNextPage), n == null || n(u, T);
762
+ l((w) => [...T, ...w]), v(u), M(A.hasPrevPage), p(A.hasNextPage), n == null || n(u, T);
767
763
  } catch (u) {
768
764
  r == null || r(u instanceof Error ? u : new Error(String(u)));
769
765
  } finally {
770
766
  g(!1), S.current = !1;
771
767
  }
772
768
  }
773
- }, [h, H, e, C, n, r]), O = k(async () => {
769
+ }, [h, F, e, C, n, r]), L = k(async () => {
774
770
  if (!S.current) {
775
- S.current = !0, a(!0);
771
+ S.current = !0, i(!0);
776
772
  try {
777
773
  const u = await e(t), A = u.data;
778
774
  if (c) {
779
775
  const T = new Set(A.map(c));
780
776
  A.forEach((w) => b.current.add(c(w))), l((w) => {
781
- const B = w.filter((X) => !T.has(c(X)));
777
+ const B = w.filter((D) => !T.has(c(D)));
782
778
  return s === "prepend" ? [...A, ...B] : [...B, ...A];
783
779
  });
784
780
  } else
785
781
  l(A);
786
- v(t), p(u.hasNextPage), K(u.hasPrevPage), n == null || n(t, A);
782
+ v(t), p(u.hasNextPage), M(u.hasPrevPage), n == null || n(t, A);
787
783
  } catch (u) {
788
784
  r == null || r(u instanceof Error ? u : new Error(String(u)));
789
785
  } finally {
790
- a(!1), S.current = !1;
786
+ i(!1), S.current = !1;
791
787
  }
792
788
  }
793
- }, [e, t, c, s, n, r]), M = k(() => {
794
- l([]), v(t), p(!0), K(!1), a(!1), g(!1), b.current.clear(), S.current = !1;
789
+ }, [e, t, c, s, n, r]), H = k(() => {
790
+ l([]), v(t), p(!0), M(!1), i(!1), g(!1), b.current.clear(), S.current = !1;
795
791
  }, [t]);
796
792
  return {
797
793
  items: y,
798
794
  loadNextPage: j,
799
- loadPrevPage: W,
800
- hasNextPage: i,
801
- hasPrevPage: H,
802
- loading: F,
795
+ loadPrevPage: U,
796
+ hasNextPage: f,
797
+ hasPrevPage: F,
798
+ loading: K,
803
799
  loadingMore: E,
804
- refresh: O,
805
- reset: M,
800
+ refresh: L,
801
+ reset: H,
806
802
  currentPage: h
807
803
  };
808
804
  }
809
805
  export {
810
806
  Ke as ChatVirtualList,
811
807
  Ee as VirtualList,
812
- be as useChatVirtualizer,
808
+ He as useChatVirtualizer,
813
809
  Be as usePagination
814
810
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-anchorlist",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "High-performance chat virtualizer for React — no flicker, no hacks",
5
5
  "keywords": [
6
6
  "react",