virtua 0.41.0 → 0.41.2
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/lib/solid/VList.d.ts +1 -1
- package/lib/solid/Virtualizer.d.ts +4 -0
- package/lib/solid/index.d.ts +1 -0
- package/lib/solid/index.js +1 -1
- package/lib/solid/index.js.map +1 -1
- package/lib/solid/index.jsx +81 -34
- package/lib/solid/index.jsx.map +1 -1
- package/lib/solid/index.mjs +1 -1
- package/lib/solid/index.mjs.map +1 -1
- package/lib/solid/types.d.ts +17 -1
- package/package.json +4 -4
package/lib/solid/VList.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface VListHandle extends VirtualizerHandle {
|
|
|
12
12
|
/**
|
|
13
13
|
* Props of {@link VList}.
|
|
14
14
|
*/
|
|
15
|
-
export interface VListProps<T> extends Pick<VirtualizerProps<T>, "ref" | "data" | "children" | "overscan" | "itemSize" | "shift" | "horizontal" | "cache" | "onScroll" | "onScrollEnd">, ViewportComponentAttributes {
|
|
15
|
+
export interface VListProps<T> extends Pick<VirtualizerProps<T>, "ref" | "data" | "children" | "overscan" | "itemSize" | "shift" | "horizontal" | "cache" | "item" | "onScroll" | "onScrollEnd" | "keepMounted">, ViewportComponentAttributes {
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Virtualized list component. See {@link VListProps} and {@link VListHandle}.
|
|
@@ -108,6 +108,10 @@ export interface VirtualizerProps<T> {
|
|
|
108
108
|
* If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.
|
|
109
109
|
*/
|
|
110
110
|
horizontal?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* List of indexes that should be always mounted, even when off screen.
|
|
113
|
+
*/
|
|
114
|
+
keepMounted?: number[];
|
|
111
115
|
/**
|
|
112
116
|
* You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VirtualizerHandle.cache}.
|
|
113
117
|
*
|
package/lib/solid/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export { Virtualizer } from "./Virtualizer";
|
|
|
7
7
|
export type { VirtualizerProps, VirtualizerHandle } from "./Virtualizer";
|
|
8
8
|
export { WindowVirtualizer } from "./WindowVirtualizer";
|
|
9
9
|
export type { WindowVirtualizerProps, WindowVirtualizerHandle, } from "./WindowVirtualizer";
|
|
10
|
+
export type * from "./types";
|
package/lib/solid/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("solid-js/web"),t=require("solid-js");const r=null,{min:n,max:o,abs:s,floor:i}=Math,c=(e,t,r)=>n(r,o(t,e)),l="function"==typeof queueMicrotask?queueMicrotask:e=>{Promise.resolve().then(e)},a=e=>{let t,r;return()=>(t||(t=!0,r=e()),r)},u=-1,f=(e,t,r)=>{const n=r?"unshift":"push";for(let r=0;r<t;r++)e[n](u);return e},d=(e,t)=>{const r=e.o[t];return r===u?e.i:r},h=(e,t,r)=>{const o=e.o[t]===u;return e.o[t]=r,e.l=n(t,e.l),o},v=(e,t)=>{if(!e.u)return 0;if(e.l>=t)return e.h[t];e.l<0&&(e.h[0]=0,e.l=0);let r=e.l,n=e.h[r];for(;r<t;)n+=d(e,r),e.h[++r]=n;return e.l=t,n},g=(e,t,r=0,n=e.u-1)=>{for(;r<=n;){const o=i((r+n)/2),s=v(e,o);if(s<=t){if(s+d(e,o)>t)return o;r=o+1}else n=o-1}return c(r,0,e.u-1)},p=(e,t,r)=>{const o=t-e.u;return e.l=r?-1:n(t-1,e.l),e.u=t,o>0?(f(e.h,o),f(e.o,o,r),e.i*o):(e.h.splice(o),(r?e.o.splice(0,-o):e.o.splice(o)).reduce(((t,r)=>t-(r===u?e.i:r)),0))},m="undefined"!=typeof window,$=()=>document.documentElement,w=e=>e.ownerDocument,S=e=>e.defaultView,x=/*#__PURE__*/a((()=>!!m&&"rtl"===getComputedStyle($()).direction)),b=/*#__PURE__*/a((()=>/iP(hone|od|ad)/.test(navigator.userAgent))),y=/*#__PURE__*/a((()=>"scrollBehavior"in $().style)),_=e=>!!e.v(),z=(e,t=40,i=4,c=0,l,a=!1)=>{let m=!!c,$=1,w=0,S=0,x=0,y=0,_=0,z=0,I=0,k=0,T=m?[0,o(c-1,0)]:r,E=[0,0],R=0;const M=((e,t,r)=>({i:r?r[1]:t,o:r&&r[0]?f(r[0].slice(0,n(e,r[0].length)),o(0,e-r[0].length)):f([],e),u:e,l:-1,h:f([],e)}))(e,t,l),O=new Set,q=()=>x-S,J=()=>q()+_+y,P=e=>((e,t,r,o)=>{if(o=n(o,e.u-1),v(e,o)<=t){const n=g(e,t+r,o);return[g(e,t,o,n),n]}{const n=g(e,t,void 0,o);return[n,g(e,t+r,n)]}})(M,e,w,E[0]),B=()=>(e=>e.u?v(e,e.u-1)+d(e,e.u-1):0)(M),H=e=>v(M,e)-_,L=e=>d(M,e),W=e=>{e&&(b()&&0!==I?_+=e:y+=e)};return{p:()=>$,m:()=>(e=>[e.o.slice(),e.i])(M),$:()=>{let e,t;return z?[e,t]=E:([e,t]=E=P(o(0,J())),T&&(e=n(e,T[0]),t=o(t,T[1]))),1!==I&&(e-=o(0,i)),2!==I&&(t+=o(0,i)),[o(e,0),n(t,M.u-1)]},S:()=>g(M,J()),_:()=>g(M,J()+w),I:e=>M.o[e]===u,k:()=>!!T&&M.o.slice(o(0,T[0]-1),n(M.u-1,T[1]+1)+1).includes(u),T:H,R:L,M:()=>M.u,O:()=>x,q:()=>0!==I,v:()=>w,J:()=>S,P:B,B:()=>(z=y,y=0,[z,2===k||q()+w>=B()]),H:(e,t)=>{const r=[e,t];return O.add(r),()=>{O.delete(r)}},L:(e,t)=>{let n,i,c=0;switch(e){case 1:{const e=z;z=0;const n=t-x,o=s(n);e&&o<s(e)+1||0!==k||(I=n<0?2:1),m&&(T=r,m=!1),x=t,c=4;const l=q();l>=-w&&l<=B()&&(c+=1,i=o>w);break}case 2:c=8,0!==I&&(n=!0,c+=1),I=0,k=0,T=r;break;case 3:{const e=t.filter((([e,t])=>M.o[e]!==t));if(!e.length)break;W(e.reduce(((e,[t,r])=>((2===k||(T?!m&&t<T[0]:H(t)+(0===I&&0===k?L(t):0)<q()))&&(e+=r-L(t)),e)),0));for(const[t,r]of e){const e=L(t),n=h(M,t,r);a&&(R+=n?r:r-e)}a&&w&&R>w&&(W(((e,t)=>{let r=0;const n=[];e.o.forEach(((e,o)=>{e!==u&&(n.push(e),o<t&&r++)})),e.l=-1;const s=(i=n,[...i].sort(((e,t)=>e-t)));var i;const c=s.length,l=c/2|0,a=c%2==0?(s[l-1]+s[l])/2:s[l],f=e.i;return((e.i=a)-f)*o(t-r,0)})(M,g(M,J()))),a=!1),c=3,i=!0;break}case 4:w!==t&&(w=t,c=3);break;case 5:t[1]?(W(p(M,t[0],!0)),k=2,c=1):(p(M,t[0]),c=1);break;case 6:S=t;break;case 7:k=1;break;case 8:T=P(t),c=1}c&&($=1+(2147483647&$),n&&_&&(y+=_,_=0),O.forEach((([e,t])=>{c&e&&t(i)})))}}},I=setTimeout,k=(e,t)=>t&&x()?-e:e,T=(e,t,n,o,s,i)=>{const c=Date.now;let l=0,a=!1,u=!1,f=!1,d=!1;const h=(()=>{let t;const n=()=>{t!=r&&clearTimeout(t)},o=()=>{n(),t=I((()=>{t=r,(()=>{if(a||u)return a=!1,void h();f=!1,e.L(2)})()}),150)};return o.W=n,o})(),v=()=>{l=c(),f&&(d=!0),i&&e.L(6,i()),e.L(1,o()),h()},g=t=>{if(a||!e.q()||t.ctrlKey)return;const r=c()-l;150>r&&50<r&&(n?t.deltaX:t.deltaY)&&(a=!0)},p=()=>{u=!0,f=d=!1},m=()=>{u=!1,b()&&(f=!0)};return t.addEventListener("scroll",v),t.addEventListener("wheel",g,{passive:!0}),t.addEventListener("touchstart",p,{passive:!0}),t.addEventListener("touchend",m,{passive:!0}),{j:()=>{t.removeEventListener("scroll",v),t.removeEventListener("wheel",g),t.removeEventListener("touchstart",p),t.removeEventListener("touchend",m),h.W()},C:()=>{const[t,r]=e.B();t&&(s(k(t,n),r,d),d=!1,r&&e.v()>e.P()&&e.L(1,o()))}}},E=e=>{let t;return{U(r){(t||(t=new(S(w(r)).ResizeObserver)(e))).observe(r)},V(e){t.unobserve(e)},j(){t&&t.disconnect()}}},R=r=>{let n;r=t.mergeProps({X:"div"},r),t.createEffect((()=>{n&&t.onCleanup(r.Y(n,r.D))}));const o=t.createMemo((()=>{const e=r.F,t={position:"absolute",[e?"height":"width"]:"100%",[e?"top":"left"]:"0px",[e?x()?"right":"left":"top"]:r.A+"px",visibility:r.G?"hidden":"visible"};return e&&(t.display="flex"),t}));return e.createComponent(e.Dynamic,{get component(){return r.X},ref(e){"function"==typeof n?n(e):n=e},get style(){return o()},get children(){return r.K}})},M=(e,t)=>e[0]===t[0]&&e[1]===t[1],O=n=>{let s;const{itemSize:i,horizontal:a=!1,overscan:u,cache:f}=n;n=t.mergeProps({as:"div"},n);const d=z(n.data.length,i,u,void 0,f,!i),h=((e,t)=>{let n;const o=t?"width":"height",s=new WeakMap,i=E((t=>{const i=[];for(const{target:c,contentRect:l}of t)if(c.offsetParent)if(c===n)e.L(4,l[o]);else{const e=s.get(c);e!=r&&i.push([e,l[o]])}i.length&&e.L(3,i)}));return{N(e){i.U(n=e)},Z:(e,t)=>(s.set(e,t),i.U(e),()=>{s.delete(e),i.V(e)}),ee:i.j}})(d,a),v=((e,t)=>{let r,n,o;const s=t?"scrollLeft":"scrollTop",i=t?"overflowX":"overflowY",a=async(n,i)=>{if(!r)return void l((()=>a(n,i)));o&&o();const c=()=>{let t;return[new Promise(((r,n)=>{t=r,o=n,_(e)&&I(n,150)})),e.H(2,(()=>{t&&t()}))]};if(i&&y()){for(;e.L(8,n()),e.k();){const[e,t]=c();try{await e}catch(e){return}finally{t()}}r.scrollTo({[t?"left":"top"]:k(n(),t),behavior:"smooth"})}else for(;;){const[o,i]=c();try{r[s]=k(n(),t),e.L(7),await o}catch(e){return}finally{i()}}};return{te(c){r=c,n=T(e,c,t,(()=>k(c[s],t)),((t,r,n)=>{if(n){const e=c.style,t=e[i];e[i]="hidden",I((()=>{e[i]=t}))}r?(c[s]=e.O()+t,o&&o()):c[s]+=t}))},ee(){n&&n.j()},re(e){a((()=>e))},ne(t){t+=e.O(),a((()=>t))},oe(t,{align:r,smooth:n,offset:o=0}={}){if(t=c(t,0,e.M()-1),"nearest"===r){const n=e.T(t),o=e.O();if(n<o)r="start";else{if(!(n+e.R(t)>o+e.v()))return;r="end"}}a((()=>o+e.J()+e.T(t)+("end"===r?e.R(t)-e.v():"center"===r?(e.R(t)-e.v())/2:0)),n)},se:()=>{n&&n.C()}}})(d,a),[g,p]=t.createSignal(d.p()),m=d.H(1,(()=>{p(d.p())})),$=d.H(4,(()=>{var e;null===(e=n.onScroll)||void 0===e||e.call(n,d.O())})),w=d.H(8,(()=>{var e;null===(e=n.onScrollEnd)||void 0===e||e.call(n)})),S=t.createMemo((e=>{g();const t=d.$();return e&&M(e,t)?e:t})),x=t.createMemo((()=>g()&&d.q())),b=t.createMemo((()=>g()&&d.P()));t.onMount((()=>{n.ref&&n.ref({get cache(){return d.m()},get scrollOffset(){return d.O()},get scrollSize(){return(e=>o(e.P(),e.v()))(d)},get viewportSize(){return d.v()},findStartIndex:d.S,findEndIndex:d._,getItemOffset:d.T,getItemSize:d.R,scrollToIndex:v.oe,scrollTo:v.re,scrollBy:v.ne});const e=n.scrollRef||s.parentElement;h.N(e),v.te(e),t.onCleanup((()=>{n.ref&&n.ref(),m(),$(),w(),h.ee(),v.ee()}))})),t.createComputed(t.on((()=>n.data.length),(e=>{e!==d.M()&&d.L(5,[e,n.shift])}))),t.createComputed(t.on((()=>n.startMargin||0),(e=>{e!==d.J()&&d.L(6,e)}))),t.createEffect(t.on(g,(()=>{v.se()})));const O=t.createMemo((()=>{const[e,t]=S();return t>=0?n.data.slice(e,t+1):[]}));return e.createComponent(e.Dynamic,{get component(){return n.as},ref(e){"function"==typeof s?s(e):s=e},get style(){return{"overflow-anchor":"none",flex:"none",position:"relative",visibility:"hidden",width:a?b()+"px":"100%",height:a?"100%":b()+"px","pointer-events":x()?"none":void 0}},get children(){return e.createComponent(t.For,{get each(){return O()},children:(r,o)=>{const s=t.createMemo((()=>S()[0]+o())),i=t.createMemo((()=>(g(),d.T(s())))),c=t.createMemo((()=>(g(),d.I(s())))),l=t.createMemo((()=>t.untrack((()=>n.children(r,s)))));return e.createComponent(R,{get X(){return n.item},get D(){return s()},get Y(){return h.Z},get A(){return i()},get G(){return c()},get K(){return l()},F:a})}})}})};var q=/*#__PURE__*/e.template("<div>"),J=/*#__PURE__*/e.template("<div>");exports.VList=t=>{const{ref:r,data:n,children:o,overscan:s,itemSize:i,shift:c,horizontal:l,cache:a,onScroll:u,onScrollEnd:f,style:d,...h}=t;return v=q(),e.spread(v,e.mergeProps(h,{get style(){return{display:l?"inline-block":"block",[l?"overflow-x":"overflow-y"]:"auto",contain:"strict",width:"100%",height:"100%",...t.style}}}),!1,!0),e.insert(v,e.createComponent(O,{ref(e){var r=t.ref;"function"==typeof r?r(e):t.ref=e},get data(){return t.data},get overscan(){return t.overscan},get itemSize(){return t.itemSize},get shift(){return t.shift},horizontal:l,cache:a,get onScroll(){return t.onScroll},get onScrollEnd(){return t.onScrollEnd},get children(){return t.children}})),v;var v},exports.Virtualizer=O,exports.WindowVirtualizer=n=>{let o;const{ref:s,data:i,children:a,overscan:u,itemSize:f,shift:d,horizontal:h=!1,cache:v,onScrollEnd:g}=n,p=z(n.data.length,f,u,void 0,v,!f),m=((e,t)=>{const n=t?"width":"height",o=t?"innerWidth":"innerHeight",s=new WeakMap,i=E((t=>{const o=[];for(const{target:e,contentRect:i}of t){if(!e.offsetParent)continue;const t=s.get(e);t!=r&&o.push([t,i[n]])}o.length&&e.L(3,o)}));let c;return{N(t){const r=S(w(t)),n=()=>{e.L(4,r[o])};r.addEventListener("resize",n),n(),c=()=>{r.removeEventListener("resize",n)}},Z:(e,t)=>(s.set(e,t),i.U(e),()=>{s.delete(e),i.V(e)}),ee(){c&&c(),i.j()}}})(p,h),$=((e,t)=>{let r,n,o;const s=(e,t,r,n,o=0)=>{const i=n?"offsetLeft":"offsetTop",c=o+(n&&x()?r.innerWidth-e[i]-e.offsetWidth:e[i]),l=e.offsetParent;return e!==t&&l?s(l,t,r,n,c):c},i=async(n,s)=>{if(!r)return void l((()=>i(n,s)));o&&o();const c=()=>{let t;return[new Promise(((r,n)=>{t=r,o=n,_(e)&&I(n,150)})),e.H(2,(()=>{t&&t()}))]},a=S(w(r));if(s&&y()){for(;e.L(8,n()),e.k();){const[e,t]=c();try{await e}catch(e){return}finally{t()}}a.scroll({[t?"left":"top"]:k(n(),t),behavior:"smooth"})}else for(;;){const[r,o]=c();try{a.scroll({[t?"left":"top"]:k(n(),t)}),e.L(7),await r}catch(e){return}finally{o()}}};return{te(o){r=o;const i=t?"scrollX":"scrollY",c=w(o),l=S(c),a=c.body;n=T(e,l,t,(()=>k(l[i],t)),((r,n)=>{n?l.scroll({[t?"left":"top"]:e.O()+r}):l.scrollBy(t?r:0,t?0:r)}),(()=>s(o,a,l,t)))},ee(){n&&n.j(),r=void 0},se:()=>{n&&n.C()},oe(n,{align:o,smooth:l,offset:a=0}={}){if(!r)return;if(n=c(n,0,e.M()-1),"nearest"===o){const t=e.T(n),r=e.O();if(t<r)o="start";else{if(!(t+e.R(n)>r+e.v()))return;o="end"}}const u=w(r),f=S(u),d=u.documentElement,h=()=>e.v()-(t?d.clientWidth:d.clientHeight);i((()=>a+s(r,u.body,f,t)+e.T(n)+("end"===o?e.R(n)-(e.v()-h()):"center"===o?(e.R(n)-(e.v()-h()))/2:0)),l)}}})(p,h),[b,O]=t.createSignal(p.p()),q=p.H(1,(()=>{O(p.p())})),P=p.H(4,(()=>{var e;null===(e=n.onScroll)||void 0===e||e.call(n)})),B=p.H(8,(()=>{var e;null===(e=n.onScrollEnd)||void 0===e||e.call(n)})),H=t.createMemo((e=>{b();const t=p.$();return e&&M(e,t)?e:t})),L=t.createMemo((()=>b()&&p.q())),W=t.createMemo((()=>b()&&p.P()));t.onMount((()=>{n.ref&&n.ref({get cache(){return p.m()},findStartIndex:p.S,findEndIndex:p._,scrollToIndex:$.oe}),m.N(o),$.te(o),t.onCleanup((()=>{n.ref&&n.ref(),q(),P(),B(),m.ee(),$.ee()}))})),t.createComputed(t.on((()=>n.data.length),(e=>{e!==p.M()&&p.L(5,[e,n.shift])}))),t.createEffect(t.on(b,(()=>{$.se()})));const j=t.createMemo((()=>{const[e,t]=H();return t>=0?n.data.slice(e,t+1):[]}));return C=J(),"function"==typeof(U=o)?e.use(U,C):o=C,C.style.setProperty("overflow-anchor","none"),C.style.setProperty("flex","none"),C.style.setProperty("position","relative"),C.style.setProperty("visibility","hidden"),e.insert(C,e.createComponent(t.For,{get each(){return j()},children:(r,o)=>{const s=t.createMemo((()=>H()[0]+o())),i=t.createMemo((()=>(b(),p.T(s())))),c=t.createMemo((()=>(b(),p.I(s())))),l=t.createMemo((()=>t.untrack((()=>n.children(r,s)))));return e.createComponent(R,{get D(){return s()},get Y(){return m.Z},get A(){return i()},get G(){return c()},get K(){return l()},F:h})}})),e.effect((e=>{var t=h?W()+"px":"100%",r=h?"100%":W()+"px",n=L()?"none":void 0;return t!==e.e&&(null!=(e.e=t)?C.style.setProperty("width",t):C.style.removeProperty("width")),r!==e.t&&(null!=(e.t=r)?C.style.setProperty("height",r):C.style.removeProperty("height")),n!==e.a&&(null!=(e.a=n)?C.style.setProperty("pointer-events",n):C.style.removeProperty("pointer-events")),e}),{e:void 0,t:void 0,a:void 0}),C;var C,U};
|
|
1
|
+
var e=require("solid-js/web"),t=require("solid-js");const r=null,{min:n,max:o,abs:s,floor:i}=Math,c=(e,t,r)=>n(r,o(t,e)),l=e=>[...e].sort(((e,t)=>e-t)),u="function"==typeof queueMicrotask?queueMicrotask:e=>{Promise.resolve().then(e)},a=e=>{let t,r;return()=>(t||(t=!0,r=e()),r)},f=-1,d=(e,t,r)=>{const n=r?"unshift":"push";for(let r=0;r<t;r++)e[n](f);return e},h=(e,t)=>{const r=e.o[t];return r===f?e.i:r},g=(e,t,r)=>{const o=e.o[t]===f;return e.o[t]=r,e.l=n(t,e.l),o},v=(e,t)=>{if(!e.u)return 0;if(e.l>=t)return e.h[t];e.l<0&&(e.h[0]=0,e.l=0);let r=e.l,n=e.h[r];for(;r<t;)n+=h(e,r),e.h[++r]=n;return e.l=t,n},p=(e,t,r=0,n=e.u-1)=>{for(;r<=n;){const o=i((r+n)/2),s=v(e,o);if(s<=t){if(s+h(e,o)>t)return o;r=o+1}else n=o-1}return c(r,0,e.u-1)},m=(e,t,r)=>{const o=t-e.u;return e.l=r?-1:n(t-1,e.l),e.u=t,o>0?(d(e.h,o),d(e.o,o,r),e.i*o):(e.h.splice(o),(r?e.o.splice(0,-o):e.o.splice(o)).reduce(((t,r)=>t-(r===f?e.i:r)),0))},x="undefined"!=typeof window,$=()=>document.documentElement,w=e=>e.ownerDocument,S=e=>e.defaultView,b=/*#__PURE__*/a((()=>!!x&&"rtl"===getComputedStyle($()).direction)),y=/*#__PURE__*/a((()=>/iP(hone|od|ad)/.test(navigator.userAgent))),_=/*#__PURE__*/a((()=>"scrollBehavior"in $().style)),z=e=>!!e.v(),I=(e,t=40,i=4,c=0,u,a=!1)=>{let x=!!c,$=1,w=0,S=0,b=0,_=0,z=0,I=0,k=0,T=0,M=x?[0,o(c-1,0)]:r,E=[0,0],R=0;const O=((e,t,r)=>({i:r?r[1]:t,o:r&&r[0]?d(r[0].slice(0,n(e,r[0].length)),o(0,e-r[0].length)):d([],e),u:e,l:-1,h:d([],e)}))(e,t,u),q=new Set,J=()=>b-S,P=()=>J()+z+_,B=e=>((e,t,r,o)=>{if(o=n(o,e.u-1),v(e,o)<=t){const n=p(e,t+r,o);return[p(e,t,o,n),n]}{const n=p(e,t,void 0,o);return[n,p(e,t+r,n)]}})(O,e,w,E[0]),H=()=>(e=>e.u?v(e,e.u-1)+h(e,e.u-1):0)(O),L=e=>v(O,e)-z,W=e=>h(O,e),j=e=>{e&&(y()&&0!==k?z+=e:_+=e)};return{p:()=>$,m:()=>(e=>[e.o.slice(),e.i])(O),$:()=>{let e,t;return I?[e,t]=E:([e,t]=E=B(o(0,P())),M&&(e=n(e,M[0]),t=o(t,M[1]))),1!==k&&(e-=o(0,i)),2!==k&&(t+=o(0,i)),[o(e,0),n(t,O.u-1)]},S:()=>p(O,P()),_:()=>p(O,P()+w),I:e=>O.o[e]===f,k:()=>!!M&&O.o.slice(o(0,M[0]-1),n(O.u-1,M[1]+1)+1).includes(f),T:L,M:W,R:()=>O.u,O:()=>b,q:()=>0!==k,v:()=>w,J:()=>S,P:H,B:()=>(I=_,_=0,[I,2===T||J()+w>=H()]),H:(e,t)=>{const r=[e,t];return q.add(r),()=>{q.delete(r)}},L:(e,t)=>{let n,i,c=0;switch(e){case 1:{const e=I;I=0;const n=t-b,o=s(n);e&&o<s(e)+1||0!==T||(k=n<0?2:1),x&&(M=r,x=!1),b=t,c=4;const l=J();l>=-w&&l<=H()&&(c+=1,i=o>w);break}case 2:c=8,0!==k&&(n=!0,c+=1),k=0,T=0,M=r;break;case 3:{const e=t.filter((([e,t])=>O.o[e]!==t));if(!e.length)break;j(e.reduce(((e,[t,r])=>((2===T||(M?!x&&t<M[0]:L(t)+(0===k&&0===T?W(t):0)<J()))&&(e+=r-W(t)),e)),0));for(const[t,r]of e){const e=W(t),n=g(O,t,r);a&&(R+=n?r:r-e)}a&&w&&R>w&&(j(((e,t)=>{let r=0;const n=[];e.o.forEach(((e,o)=>{e!==f&&(n.push(e),o<t&&r++)})),e.l=-1;const s=l(n),i=s.length,c=i/2|0,u=i%2==0?(s[c-1]+s[c])/2:s[c],a=e.i;return((e.i=u)-a)*o(t-r,0)})(O,p(O,P()))),a=!1),c=3,i=!0;break}case 4:w!==t&&(w=t,c=3);break;case 5:t[1]?(j(m(O,t[0],!0)),T=2,c=1):(m(O,t[0]),c=1);break;case 6:S=t;break;case 7:T=1;break;case 8:M=B(t),c=1}c&&($=1+(2147483647&$),n&&z&&(_+=z,z=0),q.forEach((([e,t])=>{c&e&&t(i)})))}}},k=setTimeout,T=(e,t)=>t&&b()?-e:e,M=(e,t,n,o,s,i)=>{const c=Date.now;let l=0,u=!1,a=!1,f=!1,d=!1;const h=(()=>{let t;const n=()=>{t!=r&&clearTimeout(t)},o=()=>{n(),t=k((()=>{t=r,(()=>{if(u||a)return u=!1,void h();f=!1,e.L(2)})()}),150)};return o.W=n,o})(),g=()=>{l=c(),f&&(d=!0),i&&e.L(6,i()),e.L(1,o()),h()},v=t=>{if(u||!e.q()||t.ctrlKey)return;const r=c()-l;150>r&&50<r&&(n?t.deltaX:t.deltaY)&&(u=!0)},p=()=>{a=!0,f=d=!1},m=()=>{a=!1,y()&&(f=!0)};return t.addEventListener("scroll",g),t.addEventListener("wheel",v,{passive:!0}),t.addEventListener("touchstart",p,{passive:!0}),t.addEventListener("touchend",m,{passive:!0}),{j:()=>{t.removeEventListener("scroll",g),t.removeEventListener("wheel",v),t.removeEventListener("touchstart",p),t.removeEventListener("touchend",m),h.W()},C:()=>{const[t,r]=e.B();t&&(s(T(t,n),r,d),d=!1,r&&e.v()>e.P()&&e.L(1,o()))}}},E=e=>{let t;return{U(r){(t||(t=new(S(w(r)).ResizeObserver)(e))).observe(r)},V(e){t.unobserve(e)},j(){t&&t.disconnect()}}},R=r=>{let n;r=t.mergeProps({X:"div"},r),t.createEffect((()=>{n&&t.onCleanup(r.Y(n,r.D))}));const o=t.createMemo((()=>{const e=r.F,t={position:"absolute",[e?"height":"width"]:"100%",[e?"top":"left"]:"0px",[e?b()?"right":"left":"top"]:r.A+"px",visibility:r.G?"hidden":"visible"};return e&&(t.display="flex"),t}));return e.createComponent(e.Dynamic,{get component(){return r.X},get index(){return r.D},ref(e){"function"==typeof n?n(e):n=e},get style(){return o()},get children(){return r.K}})},O=(e,t)=>e[0]===t[0]&&e[1]===t[1],q=n=>{let s;const{itemSize:i,horizontal:a=!1,overscan:f,cache:d}=n;n=t.mergeProps({as:"div"},n);const h=I(n.data.length,i,f,void 0,d,!i),g=((e,t)=>{let n;const o=t?"width":"height",s=new WeakMap,i=E((t=>{const i=[];for(const{target:c,contentRect:l}of t)if(c.offsetParent)if(c===n)e.L(4,l[o]);else{const e=s.get(c);e!=r&&i.push([e,l[o]])}i.length&&e.L(3,i)}));return{N(e){i.U(n=e)},Z:(e,t)=>(s.set(e,t),i.U(e),()=>{s.delete(e),i.V(e)}),ee:i.j}})(h,a),v=((e,t)=>{let r,n,o;const s=t?"scrollLeft":"scrollTop",i=t?"overflowX":"overflowY",l=async(n,i)=>{if(!r)return void u((()=>l(n,i)));o&&o();const c=()=>{let t;return[new Promise(((r,n)=>{t=r,o=n,z(e)&&k(n,150)})),e.H(2,(()=>{t&&t()}))]};if(i&&_()){for(;e.L(8,n()),e.k();){const[e,t]=c();try{await e}catch(e){return}finally{t()}}r.scrollTo({[t?"left":"top"]:T(n(),t),behavior:"smooth"})}else for(;;){const[o,i]=c();try{r[s]=T(n(),t),e.L(7),await o}catch(e){return}finally{i()}}};return{te(c){r=c,n=M(e,c,t,(()=>T(c[s],t)),((t,r,n)=>{if(n){const e=c.style,t=e[i];e[i]="hidden",k((()=>{e[i]=t}))}r?(c[s]=e.O()+t,o&&o()):c[s]+=t}))},ee(){n&&n.j()},re(e){l((()=>e))},ne(t){t+=e.O(),l((()=>t))},oe(t,{align:r,smooth:n,offset:o=0}={}){if(t=c(t,0,e.R()-1),"nearest"===r){const n=e.T(t),o=e.O();if(n<o)r="start";else{if(!(n+e.M(t)>o+e.v()))return;r="end"}}l((()=>o+e.J()+e.T(t)+("end"===r?e.M(t)-e.v():"center"===r?(e.M(t)-e.v())/2:0)),n)},se:()=>{n&&n.C()}}})(h,a),[p,m]=t.createSignal(h.p()),x=h.H(1,(()=>{m(h.p())})),$=h.H(4,(()=>{var e;null===(e=n.onScroll)||void 0===e||e.call(n,h.O())})),w=h.H(8,(()=>{var e;null===(e=n.onScrollEnd)||void 0===e||e.call(n)})),S=t.createMemo((e=>{p();const t=h.$();return e&&O(e,t)?e:t})),b=t.createMemo((()=>p()&&h.q())),y=t.createMemo((()=>p()&&h.P()));t.onMount((()=>{n.ref&&n.ref({get cache(){return h.m()},get scrollOffset(){return h.O()},get scrollSize(){return(e=>o(e.P(),e.v()))(h)},get viewportSize(){return h.v()},findStartIndex:h.S,findEndIndex:h._,getItemOffset:h.T,getItemSize:h.M,scrollToIndex:v.oe,scrollTo:v.re,scrollBy:v.ne});const e=n.scrollRef||s.parentElement;g.N(e),v.te(e),t.onCleanup((()=>{n.ref&&n.ref(),x(),$(),w(),g.ee(),v.ee()}))})),t.createComputed(t.on((()=>n.startMargin||0),(e=>{e!==h.J()&&h.L(6,e)}))),t.createEffect(t.on(p,(()=>{v.se()})));const q=t.createMemo((()=>{const e=n.data.length;t.untrack((()=>{e!==h.R()&&h.L(5,[e,n.shift])}));const[r,o]=S(),s=o>=0?n.data.slice(r,o+1):[],i=s.map(((e,t)=>r+t));if(n.keepMounted){const e=[],t=[],c=[],u=[];l(n.keepMounted).forEach((s=>{s<0||s>=n.data.length||(s<r&&(e.push(n.data[s]),t.push(s)),s>o&&(c.push(n.data[s]),u.push(s)))})),s.unshift(...e),i.unshift(...t),s.push(...c),i.push(...u)}return{ie:s,ce:i}}));return e.createComponent(e.Dynamic,{get component(){return n.as},ref(e){"function"==typeof s?s(e):s=e},get style(){return{"overflow-anchor":"none",flex:"none",position:"relative",visibility:"hidden",width:a?y()+"px":"100%",height:a?"100%":y()+"px","pointer-events":b()?"none":void 0}},get children(){return e.createComponent(t.For,{get each(){return q().ie},children:(r,o)=>((r,o)=>{const s=t.createMemo((()=>(p(),h.T(o())))),i=t.createMemo((()=>(p(),h.I(o())))),c=t.createMemo((()=>t.untrack((()=>n.children(r,o)))));return e.createComponent(R,{get X(){return n.item},get D(){return o()},get Y(){return g.Z},get A(){return s()},get G(){return i()},get K(){return c()},F:a})})(r,t.createMemo((()=>q().ce[o()])))})}})};var J=/*#__PURE__*/e.template("<div>"),P=/*#__PURE__*/e.template("<div>");exports.VList=r=>{const[n,o]=t.splitProps(r,["ref","data","children","overscan","itemSize","shift","horizontal","keepMounted","cache","item","onScroll","onScrollEnd","style"]);return s=J(),e.spread(s,e.mergeProps(o,{get style(){return{display:n.horizontal?"inline-block":"block",[n.horizontal?"overflow-x":"overflow-y"]:"auto",contain:"strict",width:"100%",height:"100%",...n.style}}}),!1,!0),e.insert(s,e.createComponent(q,{ref(e){var t=n.ref;"function"==typeof t?t(e):n.ref=e},get data(){return n.data},get overscan(){return n.overscan},get itemSize(){return n.itemSize},get shift(){return n.shift},get horizontal(){return n.horizontal},get keepMounted(){return n.keepMounted},get cache(){return n.cache},get item(){return n.item},get onScroll(){return n.onScroll},get onScrollEnd(){return n.onScrollEnd},get children(){return n.children}})),s;var s},exports.Virtualizer=q,exports.WindowVirtualizer=n=>{let o;const{ref:s,data:i,children:l,overscan:a,itemSize:f,shift:d,horizontal:h=!1,cache:g,onScrollEnd:v}=n,p=I(n.data.length,f,a,void 0,g,!f),m=((e,t)=>{const n=t?"width":"height",o=t?"innerWidth":"innerHeight",s=new WeakMap,i=E((t=>{const o=[];for(const{target:e,contentRect:i}of t){if(!e.offsetParent)continue;const t=s.get(e);t!=r&&o.push([t,i[n]])}o.length&&e.L(3,o)}));let c;return{N(t){const r=S(w(t)),n=()=>{e.L(4,r[o])};r.addEventListener("resize",n),n(),c=()=>{r.removeEventListener("resize",n)}},Z:(e,t)=>(s.set(e,t),i.U(e),()=>{s.delete(e),i.V(e)}),ee(){c&&c(),i.j()}}})(p,h),x=((e,t)=>{let r,n,o;const s=(e,t,r,n,o=0)=>{const i=n?"offsetLeft":"offsetTop",c=o+(n&&b()?r.innerWidth-e[i]-e.offsetWidth:e[i]),l=e.offsetParent;return e!==t&&l?s(l,t,r,n,c):c},i=async(n,s)=>{if(!r)return void u((()=>i(n,s)));o&&o();const c=()=>{let t;return[new Promise(((r,n)=>{t=r,o=n,z(e)&&k(n,150)})),e.H(2,(()=>{t&&t()}))]},l=S(w(r));if(s&&_()){for(;e.L(8,n()),e.k();){const[e,t]=c();try{await e}catch(e){return}finally{t()}}l.scroll({[t?"left":"top"]:T(n(),t),behavior:"smooth"})}else for(;;){const[r,o]=c();try{l.scroll({[t?"left":"top"]:T(n(),t)}),e.L(7),await r}catch(e){return}finally{o()}}};return{te(o){r=o;const i=t?"scrollX":"scrollY",c=w(o),l=S(c),u=c.body;n=M(e,l,t,(()=>T(l[i],t)),((r,n)=>{n?l.scroll({[t?"left":"top"]:e.O()+r}):l.scrollBy(t?r:0,t?0:r)}),(()=>s(o,u,l,t)))},ee(){n&&n.j(),r=void 0},se:()=>{n&&n.C()},oe(n,{align:o,smooth:l,offset:u=0}={}){if(!r)return;if(n=c(n,0,e.R()-1),"nearest"===o){const t=e.T(n),r=e.O();if(t<r)o="start";else{if(!(t+e.M(n)>r+e.v()))return;o="end"}}const a=w(r),f=S(a),d=a.documentElement,h=()=>e.v()-(t?d.clientWidth:d.clientHeight);i((()=>u+s(r,a.body,f,t)+e.T(n)+("end"===o?e.M(n)-(e.v()-h()):"center"===o?(e.M(n)-(e.v()-h()))/2:0)),l)}}})(p,h),[$,y]=t.createSignal(p.p()),q=p.H(1,(()=>{y(p.p())})),J=p.H(4,(()=>{var e;null===(e=n.onScroll)||void 0===e||e.call(n)})),B=p.H(8,(()=>{var e;null===(e=n.onScrollEnd)||void 0===e||e.call(n)})),H=t.createMemo((e=>{$();const t=p.$();return e&&O(e,t)?e:t})),L=t.createMemo((()=>$()&&p.q())),W=t.createMemo((()=>$()&&p.P()));t.onMount((()=>{n.ref&&n.ref({get cache(){return p.m()},findStartIndex:p.S,findEndIndex:p._,scrollToIndex:x.oe}),m.N(o),x.te(o),t.onCleanup((()=>{n.ref&&n.ref(),q(),J(),B(),m.ee(),x.ee()}))})),t.createEffect(t.on($,(()=>{x.se()})));const j=t.createMemo((()=>{const e=n.data.length;t.untrack((()=>{e!==p.R()&&p.L(5,[e,n.shift])}));const[r,o]=H();return o>=0?n.data.slice(r,o+1):[]}));return C=P(),"function"==typeof(U=o)?e.use(U,C):o=C,C.style.setProperty("overflow-anchor","none"),C.style.setProperty("flex","none"),C.style.setProperty("position","relative"),C.style.setProperty("visibility","hidden"),e.insert(C,e.createComponent(t.For,{get each(){return j()},children:(r,o)=>{const s=t.createMemo((()=>H()[0]+o())),i=t.createMemo((()=>($(),p.T(s())))),c=t.createMemo((()=>($(),p.I(s())))),l=t.createMemo((()=>t.untrack((()=>n.children(r,s)))));return e.createComponent(R,{get D(){return s()},get Y(){return m.Z},get A(){return i()},get G(){return c()},get K(){return l()},F:h})}})),e.effect((e=>{var t=h?W()+"px":"100%",r=h?"100%":W()+"px",n=L()?"none":void 0;return t!==e.e&&(null!=(e.e=t)?C.style.setProperty("width",t):C.style.removeProperty("width")),r!==e.t&&(null!=(e.t=r)?C.style.setProperty("height",r):C.style.removeProperty("height")),n!==e.a&&(null!=(e.a=n)?C.style.setProperty("pointer-events",n):C.style.removeProperty("pointer-events")),e}),{e:void 0,t:void 0,a:void 0}),C;var C,U};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/solid/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/src/core/utils.ts","../../src/src/core/cache.ts","../../src/src/core/environment.ts","../../src/src/core/store.ts","../../src/src/core/scroller.ts","../../src/src/core/resizer.ts","../../src/src/solid/ListItem.tsx","../../src/src/solid/utils.ts","../../src/src/solid/Virtualizer.tsx","../../src/src/solid/VList.tsx","../../src/src/solid/WindowVirtualizer.tsx"],"sourcesContent":["/** @internal */\nexport const NULL = null;\n\n/** @internal */\nexport const { min, max, abs, floor } = Math;\n\n/**\n * @internal\n */\nexport const clamp = (\n value: number,\n minValue: number,\n maxValue: number\n): number => min(maxValue, max(minValue, value));\n\n/**\n * @internal\n */\nexport const sort = <T extends number>(arr: readonly T[]): T[] => {\n return [...arr].sort((a, b) => a - b);\n};\n\n/**\n * @internal\n */\nexport const microtask: (fn: () => void) => void =\n typeof queueMicrotask === \"function\"\n ? queueMicrotask\n : (fn) => {\n Promise.resolve().then(fn);\n };\n\n/**\n * @internal\n */\nexport const once = <V>(fn: () => V): (() => V) => {\n let called: undefined | boolean;\n let cache: V;\n\n return () => {\n if (!called) {\n called = true;\n cache = fn();\n }\n return cache;\n };\n};\n","import { type InternalCacheSnapshot, type ItemsRange } from \"./types\";\nimport { clamp, floor, max, min, sort } from \"./utils\";\n\ntype Writeable<T> = {\n -readonly [key in keyof T]: Writeable<T[key]>;\n};\n\n/** @internal */\nexport const UNCACHED = -1;\n\n/**\n * @internal\n */\nexport type Cache = {\n readonly _length: number;\n // sizes\n readonly _sizes: number[];\n readonly _defaultItemSize: number;\n // offsets\n readonly _computedOffsetIndex: number;\n readonly _offsets: number[];\n};\n\nconst fill = (array: number[], length: number, prepend?: boolean): number[] => {\n const key = prepend ? \"unshift\" : \"push\";\n for (let i = 0; i < length; i++) {\n array[key](UNCACHED);\n }\n return array;\n};\n\n/**\n * @internal\n */\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\n/**\n * @internal\n */\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n): boolean => {\n const isInitialMeasurement = cache._sizes[index] === UNCACHED;\n cache._sizes[index] = size;\n // mark as dirty\n cache._computedOffsetIndex = min(index, cache._computedOffsetIndex);\n return isInitialMeasurement;\n};\n\n/**\n * @internal\n */\nexport const computeOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n if (!cache._length) return 0;\n if (cache._computedOffsetIndex >= index) {\n return cache._offsets[index]!;\n }\n\n if (cache._computedOffsetIndex < 0) {\n // first offset must be 0 to avoid returning NaN, which can cause infinite rerender.\n // https://github.com/inokawa/virtua/pull/160\n cache._offsets[0] = 0;\n cache._computedOffsetIndex = 0;\n }\n let i = cache._computedOffsetIndex;\n let top = cache._offsets[i]!;\n while (i < index) {\n top += getItemSize(cache, i);\n cache._offsets[++i] = top;\n }\n // mark as measured\n cache._computedOffsetIndex = index;\n return top;\n};\n\n/**\n * @internal\n */\nexport const computeTotalSize = (cache: Cache): number => {\n if (!cache._length) return 0;\n return (\n computeOffset(cache, cache._length - 1) +\n getItemSize(cache, cache._length - 1)\n );\n};\n\n/**\n * Finds the index of an item in the cache whose computed offset is closest to the specified offset.\n *\n * @internal\n */\nexport const findIndex = (\n cache: Cache,\n offset: number,\n low: number = 0,\n high: number = cache._length - 1\n): number => {\n // Find with binary search\n while (low <= high) {\n const mid = floor((low + high) / 2);\n const itemOffset = computeOffset(cache, mid);\n if (itemOffset <= offset) {\n if (itemOffset + getItemSize(cache, mid) > offset) {\n return mid;\n }\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n return clamp(low, 0, cache._length - 1);\n};\n\n/**\n * @internal\n */\nexport const computeRange = (\n cache: Cache,\n scrollOffset: number,\n viewportSize: number,\n prevStartIndex: number\n): ItemsRange => {\n // Clamp because prevStartIndex may exceed the limit when children decreased a lot after scrolling\n prevStartIndex = min(prevStartIndex, cache._length - 1);\n\n if (computeOffset(cache, prevStartIndex) <= scrollOffset) {\n // search forward\n // start <= end, prevStartIndex <= start\n const end = findIndex(cache, scrollOffset + viewportSize, prevStartIndex);\n return [findIndex(cache, scrollOffset, prevStartIndex, end), end];\n } else {\n // search backward\n // start <= end, start <= prevStartIndex\n const start = findIndex(cache, scrollOffset, undefined, prevStartIndex);\n return [start, findIndex(cache, scrollOffset + viewportSize, start)];\n }\n};\n\n/**\n * @internal\n */\nexport const estimateDefaultItemSize = (\n cache: Writeable<Cache>,\n startIndex: number\n): number => {\n let measuredCountBeforeStart = 0;\n // This function will be called after measurement so measured size array must be longer than 0\n const measuredSizes: number[] = [];\n cache._sizes.forEach((s, i) => {\n if (s !== UNCACHED) {\n measuredSizes.push(s);\n if (i < startIndex) {\n measuredCountBeforeStart++;\n }\n }\n });\n\n // Discard cache for now\n cache._computedOffsetIndex = -1;\n\n // Calculate median\n const sorted = sort(measuredSizes);\n const len = sorted.length;\n const mid = (len / 2) | 0;\n const median =\n len % 2 === 0 ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!;\n\n const prevDefaultItemSize = cache._defaultItemSize;\n\n // Calculate diff of unmeasured items before start\n return (\n ((cache._defaultItemSize = median) - prevDefaultItemSize) *\n max(startIndex - measuredCountBeforeStart, 0)\n );\n};\n\n/**\n * @internal\n */\nexport const initCache = (\n length: number,\n itemSize: number,\n snapshot?: InternalCacheSnapshot\n): Cache => {\n return {\n _defaultItemSize: snapshot ? snapshot[1] : itemSize,\n _sizes:\n snapshot && snapshot[0]\n ? // https://github.com/inokawa/virtua/issues/441\n fill(\n snapshot[0].slice(0, min(length, snapshot[0].length)),\n max(0, length - snapshot[0].length)\n )\n : fill([], length),\n _length: length,\n _computedOffsetIndex: -1,\n _offsets: fill([], length),\n };\n};\n\n/**\n * @internal\n */\nexport const takeCacheSnapshot = (cache: Cache): InternalCacheSnapshot => {\n return [cache._sizes.slice(), cache._defaultItemSize];\n};\n\n/**\n * @internal\n */\nexport const updateCacheLength = (\n cache: Writeable<Cache>,\n length: number,\n isShift?: boolean\n): number => {\n const diff = length - cache._length;\n\n cache._computedOffsetIndex = isShift\n ? // Discard cache for now\n -1\n : min(length - 1, cache._computedOffsetIndex);\n cache._length = length;\n\n if (diff > 0) {\n // Added\n fill(cache._offsets, diff);\n fill(cache._sizes, diff, isShift);\n return cache._defaultItemSize * diff;\n } else {\n // Removed\n cache._offsets.splice(diff);\n return (\n isShift ? cache._sizes.splice(0, -diff) : cache._sizes.splice(diff)\n ).reduce(\n (acc, removed) =>\n acc - (removed === UNCACHED ? cache._defaultItemSize : removed),\n 0\n );\n }\n};\n","import { once } from \"./utils\";\n\n/**\n * @internal\n */\nexport const isBrowser = typeof window !== \"undefined\";\n\nconst getDocumentElement = () => document.documentElement;\n\n/**\n * @internal\n */\nexport const getCurrentDocument = (node: HTMLElement): Document =>\n node.ownerDocument;\n\n/**\n * @internal\n */\nexport const getCurrentWindow = (doc: Document) => doc.defaultView!;\n\n/**\n * @internal\n */\nexport const isRTLDocument = /*#__PURE__*/ once((): boolean => {\n // TODO support SSR in rtl\n return isBrowser\n ? getComputedStyle(getDocumentElement()).direction === \"rtl\"\n : false;\n});\n\n/**\n * Currently, all browsers on iOS/iPadOS are WebKit, including WebView.\n * @internal\n */\nexport const isIOSWebKit = /*#__PURE__*/ once((): boolean => {\n return /iP(hone|od|ad)/.test(navigator.userAgent);\n});\n\n/**\n * @internal\n */\nexport const isSmoothScrollSupported = /*#__PURE__*/ once((): boolean => {\n return \"scrollBehavior\" in getDocumentElement().style;\n});\n","import {\n initCache,\n getItemSize as _getItemSize,\n computeTotalSize,\n computeOffset as computeStartOffset,\n UNCACHED,\n setItemSize,\n estimateDefaultItemSize,\n updateCacheLength,\n computeRange,\n takeCacheSnapshot,\n findIndex,\n} from \"./cache\";\nimport { isIOSWebKit } from \"./environment\";\nimport type {\n CacheSnapshot,\n InternalCacheSnapshot,\n ItemResize,\n ItemsRange,\n} from \"./types\";\nimport { abs, max, min, NULL } from \"./utils\";\n\nconst MAX_INT_32 = 0x7fffffff;\n\nconst SCROLL_IDLE = 0;\nconst SCROLL_DOWN = 1;\nconst SCROLL_UP = 2;\ntype ScrollDirection =\n | typeof SCROLL_IDLE\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP;\n\nconst SCROLL_BY_NATIVE = 0;\nconst SCROLL_BY_MANUAL_SCROLL = 1;\nconst SCROLL_BY_SHIFT = 2;\ntype ScrollMode =\n | typeof SCROLL_BY_NATIVE\n | typeof SCROLL_BY_MANUAL_SCROLL\n | typeof SCROLL_BY_SHIFT;\n\n/** @internal */\nexport const ACTION_SCROLL = 1;\n/** @internal */\nexport const ACTION_SCROLL_END = 2;\n/** @internal */\nexport const ACTION_ITEM_RESIZE = 3;\n/** @internal */\nexport const ACTION_VIEWPORT_RESIZE = 4;\n/** @internal */\nexport const ACTION_ITEMS_LENGTH_CHANGE = 5;\n/** @internal */\nexport const ACTION_START_OFFSET_CHANGE = 6;\n/** @internal */\nexport const ACTION_MANUAL_SCROLL = 7;\n/** @internal */\nexport const ACTION_BEFORE_MANUAL_SMOOTH_SCROLL = 8;\n\ntype Actions =\n | [type: typeof ACTION_SCROLL, offset: number]\n | [type: typeof ACTION_SCROLL_END, dummy?: void]\n | [type: typeof ACTION_ITEM_RESIZE, entries: ItemResize[]]\n | [type: typeof ACTION_VIEWPORT_RESIZE, size: number]\n | [\n type: typeof ACTION_ITEMS_LENGTH_CHANGE,\n arg: [length: number, isShift?: boolean | undefined],\n ]\n | [type: typeof ACTION_START_OFFSET_CHANGE, offset: number]\n | [type: typeof ACTION_MANUAL_SCROLL, dummy?: void]\n | [type: typeof ACTION_BEFORE_MANUAL_SMOOTH_SCROLL, offset: number];\n\n/** @internal */\nexport const UPDATE_VIRTUAL_STATE = 0b0001;\n/** @internal */\nexport const UPDATE_SIZE_EVENT = 0b0010;\n/** @internal */\nexport const UPDATE_SCROLL_EVENT = 0b0100;\n/** @internal */\nexport const UPDATE_SCROLL_END_EVENT = 0b1000;\n\n/**\n * @internal\n */\nexport const getScrollSize = (store: VirtualStore): number => {\n return max(store.$getTotalSize(), store.$getViewportSize());\n};\n\n/**\n * @internal\n */\nexport const isInitialMeasurementDone = (store: VirtualStore): boolean => {\n return !!store.$getViewportSize();\n};\n\ntype Subscriber = (sync?: boolean) => void;\n\n/** @internal */\nexport type StateVersion =\n number & {} /* hack for typescript to pretend as not falsy */;\n\n/**\n * @internal\n */\nexport type VirtualStore = {\n $getStateVersion(): StateVersion;\n $getCacheSnapshot(): CacheSnapshot;\n $getRange(): ItemsRange;\n $findStartIndex(): number;\n $findEndIndex(): number;\n $isUnmeasuredItem(index: number): boolean;\n $getItemOffset(index: number): number;\n $getItemSize(index: number): number;\n $getItemsLength(): number;\n $getScrollOffset(): number;\n $isScrolling(): boolean;\n $getViewportSize(): number;\n $getStartSpacerSize(): number;\n $getTotalSize(): number;\n _flushJump(): [number, boolean];\n $subscribe(target: number, cb: Subscriber): () => void;\n $update(...action: Actions): void;\n _hasUnmeasuredItemsInFrozenRange(): boolean;\n};\n\n/**\n * @internal\n */\nexport const createVirtualStore = (\n elementsCount: number,\n itemSize: number = 40,\n overscan: number = 4,\n ssrCount: number = 0,\n cacheSnapshot?: CacheSnapshot | undefined,\n shouldAutoEstimateItemSize: boolean = false\n): VirtualStore => {\n let isSSR = !!ssrCount;\n let stateVersion: StateVersion = 1;\n let viewportSize = 0;\n let startSpacerSize = 0;\n let scrollOffset = 0;\n let jump = 0;\n let pendingJump = 0;\n let _flushedJump = 0;\n let _scrollDirection: ScrollDirection = SCROLL_IDLE;\n let _scrollMode: ScrollMode = SCROLL_BY_NATIVE;\n let _frozenRange: ItemsRange | null = isSSR\n ? [0, max(ssrCount - 1, 0)]\n : NULL;\n let _prevRange: ItemsRange = [0, 0];\n let _totalMeasuredSize = 0;\n\n const cache = initCache(\n elementsCount,\n itemSize,\n cacheSnapshot as unknown as InternalCacheSnapshot | undefined\n );\n const subscribers = new Set<[number, Subscriber]>();\n const getRelativeScrollOffset = () => scrollOffset - startSpacerSize;\n const getVisibleOffset = () => getRelativeScrollOffset() + pendingJump + jump;\n const getRange = (offset: number) => {\n return computeRange(cache, offset, viewportSize, _prevRange[0]);\n };\n const getTotalSize = (): number => computeTotalSize(cache);\n const getItemOffset = (index: number): number => {\n return computeStartOffset(cache, index) - pendingJump;\n };\n const getItemSize = (index: number): number => {\n return _getItemSize(cache, index);\n };\n\n const applyJump = (j: number) => {\n if (j) {\n // In iOS WebKit browsers, updating scroll position will stop scrolling so it have to be deferred during scrolling.\n if (isIOSWebKit() && _scrollDirection !== SCROLL_IDLE) {\n pendingJump += j;\n } else {\n jump += j;\n }\n }\n };\n\n return {\n $getStateVersion: () => stateVersion,\n $getCacheSnapshot: () => {\n return takeCacheSnapshot(cache) as unknown as CacheSnapshot;\n },\n $getRange: () => {\n let startIndex: number;\n let endIndex: number;\n if (_flushedJump) {\n // Return previous range for consistent render until next scroll event comes in.\n // And it must be clamped. https://github.com/inokawa/virtua/issues/597\n [startIndex, endIndex] = _prevRange;\n } else {\n [startIndex, endIndex] = _prevRange = getRange(\n max(0, getVisibleOffset())\n );\n if (_frozenRange) {\n startIndex = min(startIndex, _frozenRange[0]);\n endIndex = max(endIndex, _frozenRange[1]);\n }\n }\n\n if (_scrollDirection !== SCROLL_DOWN) {\n startIndex -= max(0, overscan);\n }\n if (_scrollDirection !== SCROLL_UP) {\n endIndex += max(0, overscan);\n }\n return [max(startIndex, 0), min(endIndex, cache._length - 1)];\n },\n $findStartIndex: () => findIndex(cache, getVisibleOffset()),\n $findEndIndex: () => findIndex(cache, getVisibleOffset() + viewportSize),\n $isUnmeasuredItem: (index) => cache._sizes[index] === UNCACHED,\n _hasUnmeasuredItemsInFrozenRange: () => {\n if (!_frozenRange) return false;\n return cache._sizes\n .slice(\n max(0, _frozenRange[0] - 1),\n min(cache._length - 1, _frozenRange[1] + 1) + 1\n )\n .includes(UNCACHED);\n },\n $getItemOffset: getItemOffset,\n $getItemSize: getItemSize,\n $getItemsLength: () => cache._length,\n $getScrollOffset: () => scrollOffset,\n $isScrolling: () => _scrollDirection !== SCROLL_IDLE,\n $getViewportSize: () => viewportSize,\n $getStartSpacerSize: () => startSpacerSize,\n $getTotalSize: getTotalSize,\n _flushJump: () => {\n _flushedJump = jump;\n jump = 0;\n return [\n _flushedJump,\n // Use absolute position not to exceed scrollable bounds\n _scrollMode === SCROLL_BY_SHIFT ||\n // https://github.com/inokawa/virtua/discussions/475\n getRelativeScrollOffset() + viewportSize >= getTotalSize(),\n ];\n },\n $subscribe: (target, cb) => {\n const sub: [number, Subscriber] = [target, cb];\n subscribers.add(sub);\n return () => {\n subscribers.delete(sub);\n };\n },\n $update: (type, payload): void => {\n let shouldFlushPendingJump: boolean | undefined;\n let shouldSync: boolean | undefined;\n let mutated = 0;\n\n switch (type) {\n case ACTION_SCROLL: {\n const flushedJump = _flushedJump;\n _flushedJump = 0;\n\n const delta = payload - scrollOffset;\n const distance = abs(delta);\n\n // Scroll event after jump compensation is not reliable because it may result in the opposite direction.\n // The delta of artificial scroll may not be equal with the jump because it may be batched with other scrolls.\n // And at least in latest Chrome/Firefox/Safari in 2023, setting value to scrollTop/scrollLeft can lose subpixel because its integer (sometimes float probably depending on dpr).\n const isJustJumped = flushedJump && distance < abs(flushedJump) + 1;\n\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (\n !isJustJumped &&\n // Ignore until manual scrolling\n _scrollMode === SCROLL_BY_NATIVE\n ) {\n _scrollDirection = delta < 0 ? SCROLL_UP : SCROLL_DOWN;\n }\n\n // TODO This will cause glitch in reverse infinite scrolling. Disable this until better solution is found.\n // if (\n // pendingJump &&\n // ((_scrollDirection === SCROLL_UP &&\n // payload - max(pendingJump, 0) <= 0) ||\n // (_scrollDirection === SCROLL_DOWN &&\n // payload - min(pendingJump, 0) >= getScrollOffsetMax()))\n // ) {\n // // Flush if almost reached to start or end\n // shouldFlushPendingJump = true;\n // }\n\n if (isSSR) {\n _frozenRange = NULL;\n isSSR = false;\n }\n\n scrollOffset = payload;\n mutated = UPDATE_SCROLL_EVENT;\n\n // Skip if offset is not changed\n // Scroll offset may exceed min or max especially in Safari's elastic scrolling.\n const relativeOffset = getRelativeScrollOffset();\n if (\n relativeOffset >= -viewportSize &&\n relativeOffset <= getTotalSize()\n ) {\n mutated += UPDATE_VIRTUAL_STATE;\n\n // Update synchronously if scrolled a lot\n shouldSync = distance > viewportSize;\n }\n break;\n }\n case ACTION_SCROLL_END: {\n mutated = UPDATE_SCROLL_END_EVENT;\n if (_scrollDirection !== SCROLL_IDLE) {\n shouldFlushPendingJump = true;\n mutated += UPDATE_VIRTUAL_STATE;\n }\n _scrollDirection = SCROLL_IDLE;\n _scrollMode = SCROLL_BY_NATIVE;\n _frozenRange = NULL;\n break;\n }\n case ACTION_ITEM_RESIZE: {\n const updated = payload.filter(\n ([index, size]) => cache._sizes[index] !== size\n );\n\n // Skip if all items are cached and not updated\n if (!updated.length) {\n break;\n }\n\n // Calculate jump by resize to minimize junks in appearance\n applyJump(\n updated.reduce((acc, [index, size]) => {\n if (\n // Keep distance from end during shifting\n _scrollMode === SCROLL_BY_SHIFT ||\n (_frozenRange\n ? // https://github.com/inokawa/virtua/issues/380\n // https://github.com/inokawa/virtua/issues/590\n !isSSR && index < _frozenRange[0]\n : // Otherwise we should maintain visible position\n getItemOffset(index) +\n // https://github.com/inokawa/virtua/issues/385\n (_scrollDirection === SCROLL_IDLE &&\n _scrollMode === SCROLL_BY_NATIVE\n ? getItemSize(index)\n : 0) <\n getRelativeScrollOffset())\n ) {\n acc += size - getItemSize(index);\n }\n return acc;\n }, 0)\n );\n\n // Update item sizes\n for (const [index, size] of updated) {\n const prevSize = getItemSize(index);\n const isInitialMeasurement = setItemSize(cache, index, size);\n\n if (shouldAutoEstimateItemSize) {\n _totalMeasuredSize += isInitialMeasurement\n ? size\n : size - prevSize;\n }\n }\n\n // Estimate initial item size from measured sizes\n if (\n shouldAutoEstimateItemSize &&\n viewportSize &&\n // If the total size is lower than the viewport, the item may be a empty state\n _totalMeasuredSize > viewportSize\n ) {\n applyJump(\n estimateDefaultItemSize(\n cache,\n findIndex(cache, getVisibleOffset())\n )\n );\n shouldAutoEstimateItemSize = false;\n }\n\n mutated = UPDATE_VIRTUAL_STATE + UPDATE_SIZE_EVENT;\n\n // Synchronous update is necessary in current design to minimize visible glitch in concurrent rendering.\n // However this seems to be the main cause of the errors from ResizeObserver.\n // https://github.com/inokawa/virtua/issues/470\n //\n // And in React, synchronous update with flushSync after asynchronous update will overtake the asynchronous one.\n // If items resize happens just after scroll, race condition can occur depending on implementation.\n shouldSync = true;\n break;\n }\n case ACTION_VIEWPORT_RESIZE: {\n if (viewportSize !== payload) {\n viewportSize = payload;\n mutated = UPDATE_VIRTUAL_STATE + UPDATE_SIZE_EVENT;\n }\n break;\n }\n case ACTION_ITEMS_LENGTH_CHANGE: {\n if (payload[1]) {\n applyJump(updateCacheLength(cache, payload[0], true));\n _scrollMode = SCROLL_BY_SHIFT;\n mutated = UPDATE_VIRTUAL_STATE;\n } else {\n updateCacheLength(cache, payload[0]);\n // https://github.com/inokawa/virtua/issues/552\n // https://github.com/inokawa/virtua/issues/557\n mutated = UPDATE_VIRTUAL_STATE;\n }\n break;\n }\n case ACTION_START_OFFSET_CHANGE: {\n startSpacerSize = payload;\n break;\n }\n case ACTION_MANUAL_SCROLL: {\n _scrollMode = SCROLL_BY_MANUAL_SCROLL;\n break;\n }\n case ACTION_BEFORE_MANUAL_SMOOTH_SCROLL: {\n _frozenRange = getRange(payload);\n mutated = UPDATE_VIRTUAL_STATE;\n break;\n }\n }\n\n if (mutated) {\n stateVersion = (stateVersion & MAX_INT_32) + 1;\n\n if (shouldFlushPendingJump && pendingJump) {\n jump += pendingJump;\n pendingJump = 0;\n }\n\n subscribers.forEach(([target, cb]) => {\n // Early return to skip React's computation\n if (!(mutated & target)) {\n return;\n }\n // https://github.com/facebook/react/issues/25191\n // https://github.com/facebook/react/blob/a5fc797db14c6e05d4d5c4dbb22a0dd70d41f5d5/packages/react-reconciler/src/ReactFiberWorkLoop.js#L1443-L1447\n cb(shouldSync);\n });\n }\n },\n };\n};\n","import {\n getCurrentDocument,\n getCurrentWindow,\n isIOSWebKit,\n isRTLDocument,\n isSmoothScrollSupported,\n} from \"./environment\";\nimport {\n ACTION_SCROLL,\n type VirtualStore,\n ACTION_SCROLL_END,\n UPDATE_SIZE_EVENT,\n ACTION_MANUAL_SCROLL,\n ACTION_BEFORE_MANUAL_SMOOTH_SCROLL,\n ACTION_START_OFFSET_CHANGE,\n isInitialMeasurementDone,\n} from \"./store\";\nimport { type ScrollToIndexOpts } from \"./types\";\nimport { clamp, microtask, NULL } from \"./utils\";\n\nconst timeout = setTimeout;\n\nconst debounce = <T extends () => void>(fn: T, ms: number) => {\n let id: ReturnType<typeof setTimeout> | undefined | null;\n\n const cancel = () => {\n if (id != NULL) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = timeout(() => {\n id = NULL;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n\n/**\n * scrollLeft is negative value in rtl direction.\n *\n * left right\n * 0 100 spec compliant (ltr)\n * -100 0 spec compliant (rtl)\n * https://github.com/othree/jquery.rtl-scroll-type\n */\nconst normalizeOffset = (offset: number, isHorizontal: boolean): number => {\n if (isHorizontal && isRTLDocument()) {\n return -offset;\n } else {\n return offset;\n }\n};\n\nconst createScrollObserver = (\n store: VirtualStore,\n viewport: HTMLElement | Window,\n isHorizontal: boolean,\n getScrollOffset: () => number,\n updateScrollOffset: (\n value: number,\n shift: boolean,\n isMomentumScrolling: boolean\n ) => void,\n getStartOffset?: () => number\n) => {\n const now = Date.now;\n\n let lastScrollTime = 0;\n let wheeling = false;\n let touching = false;\n let justTouchEnded = false;\n let stillMomentumScrolling = false;\n\n const onScrollEnd = debounce(() => {\n if (wheeling || touching) {\n wheeling = false;\n\n // Wait while wheeling or touching\n onScrollEnd();\n return;\n }\n\n justTouchEnded = false;\n\n store.$update(ACTION_SCROLL_END);\n }, 150);\n\n const onScroll = () => {\n lastScrollTime = now();\n\n if (justTouchEnded) {\n stillMomentumScrolling = true;\n }\n\n if (getStartOffset) {\n store.$update(ACTION_START_OFFSET_CHANGE, getStartOffset());\n }\n store.$update(ACTION_SCROLL, getScrollOffset());\n\n onScrollEnd();\n };\n\n // Infer scroll state also from wheel events\n // Sometimes scroll events do not fire when frame dropped even if the visual have been already scrolled\n const onWheel = ((e: WheelEvent) => {\n if (\n wheeling ||\n // Scroll start should be detected with scroll event\n !store.$isScrolling() ||\n // Probably a pinch-to-zoom gesture\n e.ctrlKey\n ) {\n return;\n }\n\n const timeDelta = now() - lastScrollTime;\n if (\n // Check if wheel event occurs some time after scrolling\n 150 > timeDelta &&\n 50 < timeDelta &&\n // Get delta before checking deltaMode for firefox behavior\n // https://github.com/w3c/uievents/issues/181#issuecomment-392648065\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1392460#c34\n (isHorizontal ? e.deltaX : e.deltaY)\n ) {\n wheeling = true;\n }\n }) as (e: Event) => void; // FIXME type error. why only here?\n\n const onTouchStart = () => {\n touching = true;\n justTouchEnded = stillMomentumScrolling = false;\n };\n const onTouchEnd = () => {\n touching = false;\n if (isIOSWebKit()) {\n justTouchEnded = true;\n }\n };\n\n viewport.addEventListener(\"scroll\", onScroll);\n viewport.addEventListener(\"wheel\", onWheel, { passive: true });\n viewport.addEventListener(\"touchstart\", onTouchStart, { passive: true });\n viewport.addEventListener(\"touchend\", onTouchEnd, { passive: true });\n\n return {\n _dispose: () => {\n viewport.removeEventListener(\"scroll\", onScroll);\n viewport.removeEventListener(\"wheel\", onWheel);\n viewport.removeEventListener(\"touchstart\", onTouchStart);\n viewport.removeEventListener(\"touchend\", onTouchEnd);\n onScrollEnd._cancel();\n },\n _fixScrollJump: () => {\n const [jump, shift] = store._flushJump();\n if (!jump) return;\n updateScrollOffset(\n normalizeOffset(jump, isHorizontal),\n shift,\n stillMomentumScrolling\n );\n stillMomentumScrolling = false;\n\n if (shift && store.$getViewportSize() > store.$getTotalSize()) {\n // In this case applying jump may not cause scroll.\n // Current logic expects scroll event occurs after applying jump so we dispatch it manually.\n store.$update(ACTION_SCROLL, getScrollOffset());\n }\n },\n };\n};\n\ntype ScrollObserver = ReturnType<typeof createScrollObserver>;\n\n/**\n * @internal\n */\nexport type Scroller = {\n $observe: (viewportElement: HTMLElement) => void;\n $dispose(): void;\n $scrollTo: (offset: number) => void;\n $scrollBy: (offset: number) => void;\n $scrollToIndex: (index: number, opts?: ScrollToIndexOpts) => void;\n $fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createScroller = (\n store: VirtualStore,\n isHorizontal: boolean\n): Scroller => {\n let viewportElement: HTMLElement | undefined;\n let scrollObserver: ScrollObserver | undefined;\n let cancelScroll: (() => void) | undefined;\n const scrollOffsetKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const overflowKey = isHorizontal ? \"overflowX\" : \"overflowY\";\n\n // The given offset will be clamped by browser\n // https://drafts.csswg.org/cssom-view/#dom-element-scrolltop\n const scheduleImperativeScroll = async (\n getTargetOffset: () => number,\n smooth?: boolean\n ) => {\n if (!viewportElement) {\n // Wait for element assign. The element may be undefined if scrollRef prop is used and scroll is scheduled on mount.\n microtask(() => scheduleImperativeScroll(getTargetOffset, smooth));\n return;\n }\n\n if (cancelScroll) {\n // Cancel waiting scrollTo\n cancelScroll();\n }\n\n const waitForMeasurement = (): [Promise<void>, () => void] => {\n // Wait for the scroll destination items to be measured.\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n let queue: (() => void) | undefined;\n return [\n new Promise<void>((resolve, reject) => {\n queue = resolve;\n cancelScroll = reject;\n\n // Resize event may not happen when the window/tab is not visible, or during browser back in Safari.\n // We have to wait for the initial measurement to avoid failing imperative scroll on mount.\n // https://github.com/inokawa/virtua/issues/450\n if (isInitialMeasurementDone(store)) {\n // Reject when items around scroll destination completely measured\n timeout(reject, 150);\n }\n }),\n store.$subscribe(UPDATE_SIZE_EVENT, () => {\n queue && queue();\n }),\n ];\n };\n\n if (smooth && isSmoothScrollSupported()) {\n while (true) {\n store.$update(ACTION_BEFORE_MANUAL_SMOOTH_SCROLL, getTargetOffset());\n\n if (!store._hasUnmeasuredItemsInFrozenRange()) {\n break;\n }\n\n const [promise, unsubscribe] = waitForMeasurement();\n\n try {\n await promise;\n } catch (e) {\n // canceled\n return;\n } finally {\n unsubscribe();\n }\n }\n\n viewportElement.scrollTo({\n [isHorizontal ? \"left\" : \"top\"]: normalizeOffset(\n getTargetOffset(),\n isHorizontal\n ),\n behavior: \"smooth\",\n });\n } else {\n while (true) {\n const [promise, unsubscribe] = waitForMeasurement();\n\n try {\n viewportElement[scrollOffsetKey] = normalizeOffset(\n getTargetOffset(),\n isHorizontal\n );\n store.$update(ACTION_MANUAL_SCROLL);\n\n await promise;\n } catch (e) {\n // canceled or finished\n return;\n } finally {\n unsubscribe();\n }\n }\n }\n };\n\n return {\n $observe(viewport) {\n viewportElement = viewport;\n\n scrollObserver = createScrollObserver(\n store,\n viewport,\n isHorizontal,\n () => normalizeOffset(viewport[scrollOffsetKey], isHorizontal),\n (jump, shift, isMomentumScrolling) => {\n // If we update scroll position while touching on iOS, the position will be reverted.\n // However iOS WebKit fires touch events only once at the beginning of momentum scrolling.\n // That means we have no reliable way to confirm still touched or not if user touches more than once during momentum scrolling...\n // This is a hack for the suspectable situations, inspired by https://github.com/prud/ios-overflow-scroll-to-top\n if (isMomentumScrolling) {\n const style = viewport.style;\n const prev = style[overflowKey];\n style[overflowKey] = \"hidden\";\n timeout(() => {\n style[overflowKey] = prev;\n });\n }\n\n if (shift) {\n viewport[scrollOffsetKey] = store.$getScrollOffset() + jump;\n // https://github.com/inokawa/virtua/issues/357\n cancelScroll && cancelScroll();\n } else {\n viewport[scrollOffsetKey] += jump;\n }\n }\n );\n },\n $dispose() {\n scrollObserver && scrollObserver._dispose();\n },\n $scrollTo(offset) {\n scheduleImperativeScroll(() => offset);\n },\n $scrollBy(offset) {\n offset += store.$getScrollOffset();\n scheduleImperativeScroll(() => offset);\n },\n $scrollToIndex(index, { align, smooth, offset = 0 } = {}) {\n index = clamp(index, 0, store.$getItemsLength() - 1);\n\n if (align === \"nearest\") {\n const itemOffset = store.$getItemOffset(index);\n const scrollOffset = store.$getScrollOffset();\n\n if (itemOffset < scrollOffset) {\n align = \"start\";\n } else if (\n itemOffset + store.$getItemSize(index) >\n scrollOffset + store.$getViewportSize()\n ) {\n align = \"end\";\n } else {\n // already completely visible\n return;\n }\n }\n\n scheduleImperativeScroll(() => {\n return (\n offset +\n store.$getStartSpacerSize() +\n store.$getItemOffset(index) +\n (align === \"end\"\n ? store.$getItemSize(index) - store.$getViewportSize()\n : align === \"center\"\n ? (store.$getItemSize(index) - store.$getViewportSize()) / 2\n : 0)\n );\n }, smooth);\n },\n $fixScrollJump: () => {\n scrollObserver && scrollObserver._fixScrollJump();\n },\n };\n};\n\n/**\n * @internal\n */\nexport type WindowScroller = {\n $observe(containerElement: HTMLElement): void;\n $dispose(): void;\n $scrollToIndex: (index: number, opts?: ScrollToIndexOpts) => void;\n $fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createWindowScroller = (\n store: VirtualStore,\n isHorizontal: boolean\n): WindowScroller => {\n let containerElement: HTMLElement | undefined;\n let scrollObserver: ScrollObserver | undefined;\n let cancelScroll: (() => void) | undefined;\n\n const calcOffsetToViewport = (\n node: HTMLElement,\n viewport: HTMLElement,\n window: Window,\n isHorizontal: boolean,\n offset: number = 0\n ): number => {\n // TODO calc offset only when it changes (maybe impossible)\n const offsetKey = isHorizontal ? \"offsetLeft\" : \"offsetTop\";\n const offsetSum =\n offset +\n (isHorizontal && isRTLDocument()\n ? window.innerWidth - node[offsetKey] - node.offsetWidth\n : node[offsetKey]);\n\n const parent = node.offsetParent;\n if (node === viewport || !parent) {\n return offsetSum;\n }\n\n return calcOffsetToViewport(\n parent as HTMLElement,\n viewport,\n window,\n isHorizontal,\n offsetSum\n );\n };\n\n const scheduleImperativeScroll = async (\n getTargetOffset: () => number,\n smooth?: boolean\n ) => {\n if (!containerElement) {\n // Wait for element assign\n microtask(() => scheduleImperativeScroll(getTargetOffset, smooth));\n return;\n }\n\n if (cancelScroll) {\n cancelScroll();\n }\n\n const waitForMeasurement = (): [Promise<void>, () => void] => {\n let queue: (() => void) | undefined;\n return [\n new Promise<void>((resolve, reject) => {\n queue = resolve;\n cancelScroll = reject;\n\n if (isInitialMeasurementDone(store)) {\n timeout(reject, 150);\n }\n }),\n store.$subscribe(UPDATE_SIZE_EVENT, () => {\n queue && queue();\n }),\n ];\n };\n\n const window = getCurrentWindow(getCurrentDocument(containerElement));\n\n if (smooth && isSmoothScrollSupported()) {\n while (true) {\n store.$update(ACTION_BEFORE_MANUAL_SMOOTH_SCROLL, getTargetOffset());\n\n if (!store._hasUnmeasuredItemsInFrozenRange()) {\n break;\n }\n\n const [promise, unsubscribe] = waitForMeasurement();\n\n try {\n await promise;\n } catch (e) {\n return;\n } finally {\n unsubscribe();\n }\n }\n\n window.scroll({\n [isHorizontal ? \"left\" : \"top\"]: normalizeOffset(\n getTargetOffset(),\n isHorizontal\n ),\n behavior: \"smooth\",\n });\n } else {\n while (true) {\n const [promise, unsubscribe] = waitForMeasurement();\n\n try {\n window.scroll({\n [isHorizontal ? \"left\" : \"top\"]: normalizeOffset(\n getTargetOffset(),\n isHorizontal\n ),\n });\n store.$update(ACTION_MANUAL_SCROLL);\n\n await promise;\n } catch (e) {\n return;\n } finally {\n unsubscribe();\n }\n }\n }\n };\n\n return {\n $observe(container) {\n containerElement = container;\n const scrollOffsetKey = isHorizontal ? \"scrollX\" : \"scrollY\";\n\n const document = getCurrentDocument(container);\n const window = getCurrentWindow(document);\n const documentBody = document.body;\n\n scrollObserver = createScrollObserver(\n store,\n window,\n isHorizontal,\n () => normalizeOffset(window[scrollOffsetKey], isHorizontal),\n (jump, shift) => {\n // TODO support case two window scrollers exist in the same view\n if (shift) {\n window.scroll({\n [isHorizontal ? \"left\" : \"top\"]: store.$getScrollOffset() + jump,\n });\n } else {\n window.scrollBy(isHorizontal ? jump : 0, isHorizontal ? 0 : jump);\n }\n },\n () =>\n calcOffsetToViewport(container, documentBody, window, isHorizontal)\n );\n },\n $dispose() {\n scrollObserver && scrollObserver._dispose();\n containerElement = undefined;\n },\n $fixScrollJump: () => {\n scrollObserver && scrollObserver._fixScrollJump();\n },\n $scrollToIndex(index, { align, smooth, offset = 0 } = {}) {\n if (!containerElement) return;\n\n index = clamp(index, 0, store.$getItemsLength() - 1);\n\n if (align === \"nearest\") {\n const itemOffset = store.$getItemOffset(index);\n const scrollOffset = store.$getScrollOffset();\n\n if (itemOffset < scrollOffset) {\n align = \"start\";\n } else if (\n itemOffset + store.$getItemSize(index) >\n scrollOffset + store.$getViewportSize()\n ) {\n align = \"end\";\n } else {\n return;\n }\n }\n\n const document = getCurrentDocument(containerElement);\n const window = getCurrentWindow(document);\n const html = document.documentElement;\n const getScrollbarSize = () =>\n store.$getViewportSize() -\n (isHorizontal ? html.clientWidth : html.clientHeight);\n\n scheduleImperativeScroll(() => {\n return (\n offset +\n // Calculate target scroll position including container's offset from document\n calcOffsetToViewport(\n containerElement!,\n document.body,\n window,\n isHorizontal\n ) +\n // store._getStartSpacerSize() +\n store.$getItemOffset(index) +\n (align === \"end\"\n ? store.$getItemSize(index) -\n (store.$getViewportSize() - getScrollbarSize())\n : align === \"center\"\n ? (store.$getItemSize(index) -\n (store.$getViewportSize() - getScrollbarSize())) /\n 2\n : 0)\n );\n }, smooth);\n },\n };\n};\n\n/**\n * @internal\n */\nexport type GridScroller = {\n $observe: (viewportElement: HTMLElement) => void;\n $dispose(): void;\n $scrollTo: (offsetX: number, offsetY: number) => void;\n $scrollBy: (offsetX: number, offsetY: number) => void;\n $scrollToIndex: (indexX: number, indexY: number) => void;\n $fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createGridScroller = (\n vStore: VirtualStore,\n hStore: VirtualStore\n): GridScroller => {\n const vScroller = createScroller(vStore, false);\n const hScroller = createScroller(hStore, true);\n return {\n $observe(viewportElement) {\n vScroller.$observe(viewportElement);\n hScroller.$observe(viewportElement);\n },\n $dispose() {\n vScroller.$dispose();\n hScroller.$dispose();\n },\n $scrollTo(offsetX, offsetY) {\n vScroller.$scrollTo(offsetY);\n hScroller.$scrollTo(offsetX);\n },\n $scrollBy(offsetX, offsetY) {\n vScroller.$scrollBy(offsetY);\n hScroller.$scrollBy(offsetX);\n },\n $scrollToIndex(indexX, indexY) {\n vScroller.$scrollToIndex(indexY);\n hScroller.$scrollToIndex(indexX);\n },\n $fixScrollJump() {\n vScroller.$fixScrollJump();\n hScroller.$fixScrollJump();\n },\n };\n};\n","import { getCurrentDocument, getCurrentWindow } from \"./environment\";\nimport {\n ACTION_ITEM_RESIZE,\n ACTION_VIEWPORT_RESIZE,\n type VirtualStore,\n} from \"./store\";\nimport { type ItemResize } from \"./types\";\nimport { max, NULL } from \"./utils\";\n\nconst createResizeObserver = (cb: ResizeObserverCallback) => {\n let ro: ResizeObserver | undefined;\n\n return {\n _observe(e: HTMLElement) {\n // Initialize ResizeObserver lazily for SSR\n // https://www.w3.org/TR/resize-observer/#intro\n (\n ro ||\n // https://bugs.chromium.org/p/chromium/issues/detail?id=1491739\n (ro = new (getCurrentWindow(getCurrentDocument(e)).ResizeObserver)(cb))\n ).observe(e);\n },\n _unobserve(e: HTMLElement) {\n ro!.unobserve(e);\n },\n _dispose() {\n ro && ro.disconnect();\n },\n };\n};\n\n/**\n * @internal\n */\nexport type ItemResizeObserver = (el: HTMLElement, i: number) => () => void;\n\ninterface ListResizer {\n $observeRoot(viewportElement: HTMLElement): void;\n $observeItem: ItemResizeObserver;\n $dispose(): void;\n}\n\n/**\n * @internal\n */\nexport const createResizer = (\n store: VirtualStore,\n isHorizontal: boolean\n): ListResizer => {\n let viewportElement: HTMLElement | undefined;\n const sizeKey = isHorizontal ? \"width\" : \"height\";\n const mountedIndexes = new WeakMap<Element, number>();\n\n const resizeObserver = createResizeObserver((entries) => {\n const resizes: ItemResize[] = [];\n for (const { target, contentRect } of entries) {\n // Skip zero-sized rects that may be observed under `display: none` style\n if (!(target as HTMLElement).offsetParent) continue;\n\n if (target === viewportElement) {\n store.$update(ACTION_VIEWPORT_RESIZE, contentRect[sizeKey]);\n } else {\n const index = mountedIndexes.get(target);\n if (index != NULL) {\n resizes.push([index, contentRect[sizeKey]]);\n }\n }\n }\n\n if (resizes.length) {\n store.$update(ACTION_ITEM_RESIZE, resizes);\n }\n });\n\n return {\n $observeRoot(viewport: HTMLElement) {\n resizeObserver._observe((viewportElement = viewport));\n },\n $observeItem: (el: HTMLElement, i: number) => {\n mountedIndexes.set(el, i);\n resizeObserver._observe(el);\n return () => {\n mountedIndexes.delete(el);\n resizeObserver._unobserve(el);\n };\n },\n $dispose: resizeObserver._dispose,\n };\n};\n\ninterface WindowListResizer {\n $observeRoot(container: HTMLElement): void;\n $observeItem: ItemResizeObserver;\n $dispose(): void;\n}\n\n/**\n * @internal\n */\nexport const createWindowResizer = (\n store: VirtualStore,\n isHorizontal: boolean\n): WindowListResizer => {\n const sizeKey = isHorizontal ? \"width\" : \"height\";\n const windowSizeKey = isHorizontal ? \"innerWidth\" : \"innerHeight\";\n const mountedIndexes = new WeakMap<Element, number>();\n\n const resizeObserver = createResizeObserver((entries) => {\n const resizes: ItemResize[] = [];\n for (const { target, contentRect } of entries) {\n // Skip zero-sized rects that may be observed under `display: none` style\n if (!(target as HTMLElement).offsetParent) continue;\n\n const index = mountedIndexes.get(target);\n if (index != NULL) {\n resizes.push([index, contentRect[sizeKey]]);\n }\n }\n\n if (resizes.length) {\n store.$update(ACTION_ITEM_RESIZE, resizes);\n }\n });\n\n let cleanupOnWindowResize: (() => void) | undefined;\n\n return {\n $observeRoot(container) {\n const window = getCurrentWindow(getCurrentDocument(container));\n const onWindowResize = () => {\n store.$update(ACTION_VIEWPORT_RESIZE, window[windowSizeKey]);\n };\n window.addEventListener(\"resize\", onWindowResize);\n onWindowResize();\n\n cleanupOnWindowResize = () => {\n window.removeEventListener(\"resize\", onWindowResize);\n };\n },\n $observeItem: (el: HTMLElement, i: number) => {\n mountedIndexes.set(el, i);\n resizeObserver._observe(el);\n return () => {\n mountedIndexes.delete(el);\n resizeObserver._unobserve(el);\n };\n },\n $dispose() {\n cleanupOnWindowResize && cleanupOnWindowResize();\n resizeObserver._dispose();\n },\n };\n};\n\n/**\n * @internal\n */\nexport const createGridResizer = (\n vStore: VirtualStore,\n hStore: VirtualStore\n) => {\n let viewportElement: HTMLElement | undefined;\n\n const heightKey = \"height\";\n const widthKey = \"width\";\n const mountedIndexes = new WeakMap<\n Element,\n [rowIndex: number, colIndex: number]\n >();\n\n type CellSize = [height: number, width: number];\n const maybeCachedRowIndexes = new Set<number>();\n const maybeCachedColIndexes = new Set<number>();\n const sizeCache = new Map<string, CellSize>();\n const getKey = (rowIndex: number, colIndex: number): string =>\n `${rowIndex}-${colIndex}`;\n\n const resizeObserver = createResizeObserver((entries) => {\n const resizedRows = new Set<number>();\n const resizedCols = new Set<number>();\n for (const { target, contentRect } of entries) {\n // Skip zero-sized rects that may be observed under `display: none` style\n if (!(target as HTMLElement).offsetParent) continue;\n\n if (target === viewportElement) {\n vStore.$update(ACTION_VIEWPORT_RESIZE, contentRect[heightKey]);\n hStore.$update(ACTION_VIEWPORT_RESIZE, contentRect[widthKey]);\n } else {\n const cell = mountedIndexes.get(target);\n if (cell) {\n const [rowIndex, colIndex] = cell;\n const key = getKey(rowIndex, colIndex);\n const prevSize = sizeCache.get(key);\n const size: CellSize = [\n contentRect[heightKey],\n contentRect[widthKey],\n ];\n let rowResized: boolean | undefined;\n let colResized: boolean | undefined;\n if (!prevSize) {\n rowResized = colResized = true;\n } else {\n if (prevSize[0] !== size[0]) {\n rowResized = true;\n }\n if (prevSize[1] !== size[1]) {\n colResized = true;\n }\n }\n if (rowResized) {\n resizedRows.add(rowIndex);\n }\n if (colResized) {\n resizedCols.add(colIndex);\n }\n if (rowResized || colResized) {\n sizeCache.set(key, size);\n }\n }\n }\n }\n\n if (resizedRows.size) {\n const heightResizes: ItemResize[] = [];\n resizedRows.forEach((rowIndex) => {\n let maxHeight = 0;\n maybeCachedColIndexes.forEach((colIndex) => {\n const size = sizeCache.get(getKey(rowIndex, colIndex));\n if (size) {\n maxHeight = max(maxHeight, size[0]);\n }\n });\n if (maxHeight) {\n heightResizes.push([rowIndex, maxHeight]);\n }\n });\n vStore.$update(ACTION_ITEM_RESIZE, heightResizes);\n }\n if (resizedCols.size) {\n const widthResizes: ItemResize[] = [];\n resizedCols.forEach((colIndex) => {\n let maxWidth = 0;\n maybeCachedRowIndexes.forEach((rowIndex) => {\n const size = sizeCache.get(getKey(rowIndex, colIndex));\n if (size) {\n maxWidth = max(maxWidth, size[1]);\n }\n });\n if (maxWidth) {\n widthResizes.push([colIndex, maxWidth]);\n }\n });\n hStore.$update(ACTION_ITEM_RESIZE, widthResizes);\n }\n });\n\n return {\n $observeRoot(viewport: HTMLElement) {\n resizeObserver._observe((viewportElement = viewport));\n },\n $observeItem(el: HTMLElement, rowIndex: number, colIndex: number) {\n mountedIndexes.set(el, [rowIndex, colIndex]);\n maybeCachedRowIndexes.add(rowIndex);\n maybeCachedColIndexes.add(colIndex);\n resizeObserver._observe(el);\n return () => {\n mountedIndexes.delete(el);\n resizeObserver._unobserve(el);\n };\n },\n $dispose: resizeObserver._dispose,\n };\n};\n\n/**\n * @internal\n */\nexport type GridResizer = ReturnType<typeof createGridResizer>;\n","/**\n * @jsxImportSource solid-js\n */\nimport { ItemResizeObserver, isRTLDocument } from \"../core\";\nimport {\n Component,\n JSX,\n createEffect,\n createMemo,\n mergeProps,\n onCleanup,\n type ValidComponent,\n} from \"solid-js\";\nimport { Dynamic } from \"solid-js/web\";\n\ninterface ListItemProps {\n _children: JSX.Element;\n _resizer: ItemResizeObserver;\n _index: number;\n _offset: number;\n _hide: boolean;\n _isHorizontal: boolean;\n _as?: ValidComponent;\n}\n\n/**\n * @internal\n */\nexport const ListItem: Component<ListItemProps> = (props) => {\n let elementRef: HTMLDivElement | undefined;\n props = mergeProps<[Partial<ListItemProps>, ListItemProps]>(\n { _as: \"div\" },\n props\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n createEffect(() => {\n if (!elementRef) return;\n onCleanup(props._resizer(elementRef, props._index));\n });\n\n const style = createMemo(() => {\n const isHorizontal = props._isHorizontal;\n const style: JSX.CSSProperties = {\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : \"left\"]: \"0px\",\n [isHorizontal ? (isRTLDocument() ? \"right\" : \"left\") : \"top\"]:\n props._offset + \"px\",\n visibility: props._hide ? \"hidden\" : \"visible\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n return style;\n });\n\n return (\n <Dynamic component={props._as} ref={elementRef} style={style()}>\n {props._children}\n </Dynamic>\n );\n};\n","import { ItemsRange } from \"../core\";\n\n/**\n * @internal\n */\nexport const isSameRange = (prev: ItemsRange, next: ItemsRange): boolean => {\n return prev[0] === next[0] && prev[1] === next[1];\n};\n","/**\n * @jsxImportSource solid-js\n */\nimport {\n onMount,\n onCleanup,\n createEffect,\n createSignal,\n createMemo,\n JSX,\n on,\n createComputed,\n type ValidComponent,\n mergeProps,\n For,\n Accessor,\n untrack,\n} from \"solid-js\";\nimport { Dynamic } from \"solid-js/web\";\nimport {\n UPDATE_SCROLL_EVENT,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n getScrollSize,\n ACTION_START_OFFSET_CHANGE,\n createResizer,\n createScroller,\n ItemsRange,\n ScrollToIndexOpts,\n CacheSnapshot,\n} from \"../core\";\nimport { ListItem } from \"./ListItem\";\nimport { isSameRange } from \"./utils\";\n\n/**\n * Methods of {@link Virtualizer}.\n */\nexport interface VirtualizerHandle {\n /**\n * Get current {@link CacheSnapshot}.\n */\n readonly cache: CacheSnapshot;\n /**\n * Get current scrollTop, or scrollLeft if horizontal: true.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight, or scrollWidth if horizontal: true.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight, or offsetWidth if horizontal: true.\n */\n readonly viewportSize: number;\n /**\n * Find the start index of visible range of items.\n */\n findStartIndex: () => number;\n /**\n * Find the end index of visible range of items.\n */\n findEndIndex: () => number;\n /**\n * Get item offset from start.\n * @param index index of item\n */\n getItemOffset(index: number): number;\n /**\n * Get item size.\n * @param index index of item\n */\n getItemSize(index: number): number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n * @param opts options\n */\n scrollToIndex(index: number, opts?: ScrollToIndexOpts): void;\n /**\n * Scroll to the given offset.\n * @param offset offset from start\n */\n scrollTo(offset: number): void;\n /**\n * Scroll by the given offset.\n * @param offset offset from current position\n */\n scrollBy(offset: number): void;\n}\n\n/**\n * Props of {@link Virtualizer}.\n */\nexport interface VirtualizerProps<T> {\n /**\n * Get reference to {@link VirtualizerHandle}.\n */\n ref?: (handle?: VirtualizerHandle) => void;\n /**\n * The data items rendered by this component.\n */\n data: T[];\n /**\n * The elements renderer function.\n */\n children: (data: T, index: Accessor<number>) => JSX.Element;\n /**\n * Number of items to render above/below the visible bounds of the list. Lower value will give better performance but you can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan?: number;\n /**\n * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as?: ValidComponent;\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item?: ValidComponent;\n /**\n * Reference to the scrollable element. The default will get the direct parent element of virtualizer.\n */\n scrollRef?: HTMLElement;\n /**\n * Item size hint for unmeasured items. It will help to reduce scroll jump when items are measured if used properly.\n *\n * - If not set, initial item sizes will be automatically estimated from measured sizes. This is recommended for most cases.\n * - If set, you can opt out estimation and use the value as initial item size.\n */\n itemSize?: number;\n /**\n * While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.\n */\n shift?: boolean;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VirtualizerHandle.cache}.\n *\n * **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**\n */\n cache?: CacheSnapshot;\n /**\n * If you put an element before virtualizer, you have to define its height with this prop.\n */\n startMargin?: number;\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop, or scrollLeft if horizontal: true.\n */\n onScroll?: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollEnd?: () => void;\n}\n\n/**\n * Customizable list virtualizer for advanced usage. See {@link VirtualizerProps} and {@link VirtualizerHandle}.\n */\nexport const Virtualizer = <T,>(props: VirtualizerProps<T>): JSX.Element => {\n let containerRef: HTMLDivElement | undefined;\n const { itemSize, horizontal = false, overscan, cache } = props;\n props = mergeProps<[Partial<VirtualizerProps<T>>, VirtualizerProps<T>]>(\n { as: \"div\" },\n props\n );\n\n const store = createVirtualStore(\n props.data.length,\n itemSize,\n overscan,\n undefined,\n cache,\n !itemSize\n );\n const resizer = createResizer(store, horizontal);\n const scroller = createScroller(store, horizontal);\n\n const [stateVersion, setRerender] = createSignal(store.$getStateVersion());\n\n const unsubscribeStore = store.$subscribe(UPDATE_VIRTUAL_STATE, () => {\n setRerender(store.$getStateVersion());\n });\n\n const unsubscribeOnScroll = store.$subscribe(UPDATE_SCROLL_EVENT, () => {\n props.onScroll?.(store.$getScrollOffset());\n });\n const unsubscribeOnScrollEnd = store.$subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n props.onScrollEnd?.();\n }\n );\n\n const range = createMemo<ItemsRange>((prev) => {\n stateVersion();\n const next = store.$getRange();\n if (prev && isSameRange(prev, next)) {\n return prev;\n }\n return next;\n });\n const isScrolling = createMemo(() => stateVersion() && store.$isScrolling());\n const totalSize = createMemo(() => stateVersion() && store.$getTotalSize());\n\n onMount(() => {\n if (props.ref) {\n props.ref({\n get cache() {\n return store.$getCacheSnapshot();\n },\n get scrollOffset() {\n return store.$getScrollOffset();\n },\n get scrollSize() {\n return getScrollSize(store);\n },\n get viewportSize() {\n return store.$getViewportSize();\n },\n findStartIndex: store.$findStartIndex,\n findEndIndex: store.$findEndIndex,\n getItemOffset: store.$getItemOffset,\n getItemSize: store.$getItemSize,\n scrollToIndex: scroller.$scrollToIndex,\n scrollTo: scroller.$scrollTo,\n scrollBy: scroller.$scrollBy,\n });\n }\n\n const scrollable = props.scrollRef || containerRef!.parentElement!;\n resizer.$observeRoot(scrollable);\n scroller.$observe(scrollable);\n\n onCleanup(() => {\n if (props.ref) {\n props.ref();\n }\n\n unsubscribeStore();\n unsubscribeOnScroll();\n unsubscribeOnScrollEnd();\n resizer.$dispose();\n scroller.$dispose();\n });\n });\n\n createComputed(\n on(\n () => props.data.length,\n (count) => {\n if (count !== store.$getItemsLength()) {\n store.$update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n }\n )\n );\n\n createComputed(\n on(\n () => props.startMargin || 0,\n (value) => {\n if (value !== store.$getStartSpacerSize()) {\n store.$update(ACTION_START_OFFSET_CHANGE, value);\n }\n }\n )\n );\n\n createEffect(\n on(stateVersion, () => {\n scroller.$fixScrollJump();\n })\n );\n\n const dataSlice = createMemo<T[]>(() => {\n const [start, end] = range();\n return end >= 0 ? props.data.slice(start, end + 1) : [];\n });\n\n return (\n <Dynamic\n component={props.as}\n ref={containerRef}\n style={{\n // contain: \"content\",\n \"overflow-anchor\": \"none\", // opt out browser's scroll anchoring because it will conflict to scroll anchoring of virtualizer\n flex: \"none\", // flex style can break layout\n position: \"relative\",\n visibility: \"hidden\", // TODO replace with other optimization methods\n width: horizontal ? totalSize() + \"px\" : \"100%\",\n height: horizontal ? \"100%\" : totalSize() + \"px\",\n \"pointer-events\": isScrolling() ? \"none\" : undefined,\n }}\n >\n <For each={dataSlice()}>\n {(data, index) => {\n const itemIndex = createMemo(() => range()[0] + index());\n const offset = createMemo(() => {\n stateVersion();\n return store.$getItemOffset(itemIndex());\n });\n const hide = createMemo(() => {\n stateVersion();\n return store.$isUnmeasuredItem(itemIndex());\n });\n const children = createMemo(() => {\n return untrack(() => props.children(data, itemIndex));\n });\n\n return (\n <ListItem\n _as={props.item}\n _index={itemIndex()}\n _resizer={resizer.$observeItem}\n _offset={offset()}\n _hide={hide()}\n _children={children()}\n _isHorizontal={horizontal}\n />\n );\n }}\n </For>\n </Dynamic>\n );\n};\n","/**\n * @jsxImportSource solid-js\n */\nimport { JSX } from \"solid-js\";\nimport { ViewportComponentAttributes } from \"./types\";\nimport {\n Virtualizer,\n VirtualizerHandle,\n VirtualizerProps,\n} from \"./Virtualizer\";\n\n/**\n * Methods of {@link VList}.\n */\nexport interface VListHandle extends VirtualizerHandle {}\n\n/**\n * Props of {@link VList}.\n */\nexport interface VListProps<T>\n extends Pick<\n VirtualizerProps<T>,\n | \"ref\"\n | \"data\"\n | \"children\"\n | \"overscan\"\n | \"itemSize\"\n | \"shift\"\n | \"horizontal\"\n | \"cache\"\n | \"onScroll\"\n | \"onScrollEnd\"\n >,\n ViewportComponentAttributes {}\n\n/**\n * Virtualized list component. See {@link VListProps} and {@link VListHandle}.\n */\nexport const VList = <T,>(props: VListProps<T>): JSX.Element => {\n const {\n ref,\n data,\n children,\n overscan,\n itemSize,\n shift,\n horizontal,\n cache,\n onScroll,\n onScrollEnd,\n style,\n ...attrs\n } = props;\n\n return (\n <div\n {...attrs}\n style={{\n display: horizontal ? \"inline-block\" : \"block\",\n [horizontal ? \"overflow-x\" : \"overflow-y\"]: \"auto\",\n contain: \"strict\",\n width: \"100%\",\n height: \"100%\",\n ...props.style,\n }}\n >\n <Virtualizer\n ref={props.ref}\n data={props.data}\n overscan={props.overscan}\n itemSize={props.itemSize}\n shift={props.shift}\n horizontal={horizontal}\n cache={cache}\n onScroll={props.onScroll}\n onScrollEnd={props.onScrollEnd}\n >\n {props.children}\n </Virtualizer>\n </div>\n );\n};\n","/**\n * @jsxImportSource solid-js\n */\nimport {\n onMount,\n onCleanup,\n createEffect,\n createSignal,\n createMemo,\n JSX,\n Accessor,\n on,\n createComputed,\n For,\n untrack,\n} from \"solid-js\";\nimport {\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n UPDATE_SCROLL_EVENT,\n createWindowResizer,\n createWindowScroller,\n ItemsRange,\n ScrollToIndexOpts,\n CacheSnapshot,\n} from \"../core\";\nimport { ListItem } from \"./ListItem\";\nimport { isSameRange } from \"./utils\";\n\n/**\n * Methods of {@link WindowVirtualizer}.\n */\nexport interface WindowVirtualizerHandle {\n /**\n * Get current {@link CacheSnapshot}.\n */\n readonly cache: CacheSnapshot;\n /**\n * Find the start index of visible range of items.\n */\n findStartIndex: () => number;\n /**\n * Find the end index of visible range of items.\n */\n findEndIndex: () => number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n * @param opts options\n */\n scrollToIndex(index: number, opts?: ScrollToIndexOpts): void;\n}\n\n/**\n * Props of {@link WindowVirtualizer}.\n */\nexport interface WindowVirtualizerProps<T> {\n /**\n * Get reference to {@link WindowVirtualizerHandle}.\n */\n ref?: (handle?: WindowVirtualizerHandle) => void;\n /**\n * The data items rendered by this component.\n */\n data: T[];\n /**\n * The elements renderer function.\n */\n children: (data: T, index: Accessor<number>) => JSX.Element;\n /**\n * Number of items to render above/below the visible bounds of the list. Lower value will give better performance but you can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan?: number;\n /**\n * Item size hint for unmeasured items. It will help to reduce scroll jump when items are measured if used properly.\n *\n * - If not set, initial item sizes will be automatically estimated from measured sizes. This is recommended for most cases.\n * - If set, you can opt out estimation and use the value as initial item size.\n */\n itemSize?: number;\n /**\n * While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.\n */\n shift?: boolean;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link WindowVirtualizerHandle.cache}.\n *\n * **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**\n */\n cache?: CacheSnapshot;\n /**\n * Callback invoked whenever scroll offset changes.\n */\n onScroll?: () => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollEnd?: () => void;\n}\n\n/**\n * {@link Virtualizer} controlled by the window scrolling. See {@link WindowVirtualizerProps} and {@link WindowVirtualizerHandle}.\n */\nexport const WindowVirtualizer = <T,>(\n props: WindowVirtualizerProps<T>\n): JSX.Element => {\n let containerRef: HTMLDivElement | undefined;\n\n const {\n ref: _ref,\n data: _data,\n children: _children,\n overscan,\n itemSize,\n shift: _shift,\n horizontal = false,\n cache,\n onScrollEnd: _onScrollEnd,\n } = props;\n\n const store = createVirtualStore(\n props.data.length,\n itemSize,\n overscan,\n undefined,\n cache,\n !itemSize\n );\n const resizer = createWindowResizer(store, horizontal);\n const scroller = createWindowScroller(store, horizontal);\n\n const [stateVersion, setRerender] = createSignal(store.$getStateVersion());\n\n const unsubscribeStore = store.$subscribe(UPDATE_VIRTUAL_STATE, () => {\n setRerender(store.$getStateVersion());\n });\n\n const unsubscribeOnScroll = store.$subscribe(UPDATE_SCROLL_EVENT, () => {\n // https://github.com/inokawa/virtua/discussions/580\n props.onScroll?.();\n });\n const unsubscribeOnScrollEnd = store.$subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n props.onScrollEnd?.();\n }\n );\n\n const range = createMemo<ItemsRange>((prev) => {\n stateVersion();\n const next = store.$getRange();\n if (prev && isSameRange(prev, next)) {\n return prev;\n }\n return next;\n });\n const isScrolling = createMemo(() => stateVersion() && store.$isScrolling());\n const totalSize = createMemo(() => stateVersion() && store.$getTotalSize());\n\n onMount(() => {\n if (props.ref) {\n props.ref({\n get cache() {\n return store.$getCacheSnapshot();\n },\n findStartIndex: store.$findStartIndex,\n findEndIndex: store.$findEndIndex,\n scrollToIndex: scroller.$scrollToIndex,\n });\n }\n\n resizer.$observeRoot(containerRef!);\n scroller.$observe(containerRef!);\n\n onCleanup(() => {\n if (props.ref) {\n props.ref();\n }\n\n unsubscribeStore();\n unsubscribeOnScroll();\n unsubscribeOnScrollEnd();\n resizer.$dispose();\n scroller.$dispose();\n });\n });\n\n createComputed(\n on(\n () => props.data.length,\n (len) => {\n if (len !== store.$getItemsLength()) {\n store.$update(ACTION_ITEMS_LENGTH_CHANGE, [len, props.shift]);\n }\n }\n )\n );\n\n createEffect(\n on(stateVersion, () => {\n scroller.$fixScrollJump();\n })\n );\n\n const dataSlice = createMemo<T[]>(() => {\n const [start, end] = range();\n return end >= 0 ? props.data.slice(start, end + 1) : [];\n });\n\n return (\n <div\n ref={containerRef}\n style={{\n // contain: \"content\",\n \"overflow-anchor\": \"none\", // opt out browser's scroll anchoring because it will conflict to scroll anchoring of virtualizer\n flex: \"none\", // flex style can break layout\n position: \"relative\",\n visibility: \"hidden\", // TODO replace with other optimization methods\n width: horizontal ? totalSize() + \"px\" : \"100%\",\n height: horizontal ? \"100%\" : totalSize() + \"px\",\n \"pointer-events\": isScrolling() ? \"none\" : undefined,\n }}\n >\n <For each={dataSlice()}>\n {(data, index) => {\n const itemIndex = createMemo(() => range()[0] + index());\n const offset = createMemo(() => {\n stateVersion();\n return store.$getItemOffset(itemIndex());\n });\n const hide = createMemo(() => {\n stateVersion();\n return store.$isUnmeasuredItem(itemIndex());\n });\n const children = createMemo(() => {\n return untrack(() => props.children(data, itemIndex));\n });\n\n return (\n <ListItem\n _index={itemIndex()}\n _resizer={resizer.$observeItem}\n _offset={offset()}\n _hide={hide()}\n _children={children()}\n _isHorizontal={horizontal}\n />\n );\n }}\n </For>\n </div>\n );\n};\n"],"names":["NULL","min","max","abs","floor","Math","clamp","value","minValue","maxValue","microtask","queueMicrotask","fn","Promise","resolve","then","once","called","cache","UNCACHED","fill","array","length","prepend","key","i","getItemSize","index","size","_sizes","_defaultItemSize","setItemSize","isInitialMeasurement","_computedOffsetIndex","computeOffset","_length","_offsets","top","findIndex","offset","low","high","mid","itemOffset","updateCacheLength","isShift","diff","splice","reduce","acc","removed","isBrowser","window","getDocumentElement","document","documentElement","getCurrentDocument","node","ownerDocument","getCurrentWindow","doc","defaultView","isRTLDocument","getComputedStyle","direction","isIOSWebKit","test","navigator","userAgent","isSmoothScrollSupported","style","isInitialMeasurementDone","store","$getViewportSize","createVirtualStore","elementsCount","itemSize","overscan","ssrCount","cacheSnapshot","shouldAutoEstimateItemSize","isSSR","stateVersion","viewportSize","startSpacerSize","scrollOffset","jump","pendingJump","_flushedJump","_scrollDirection","_scrollMode","_frozenRange","_prevRange","_totalMeasuredSize","snapshot","slice","initCache","subscribers","Set","getRelativeScrollOffset","getVisibleOffset","getRange","prevStartIndex","end","start","undefined","computeRange","getTotalSize","computeTotalSize","getItemOffset","computeStartOffset","_getItemSize","applyJump","j","$getStateVersion","$getCacheSnapshot","takeCacheSnapshot","$getRange","startIndex","endIndex","$findStartIndex","$findEndIndex","$isUnmeasuredItem","_hasUnmeasuredItemsInFrozenRange","includes","$getItemOffset","$getItemSize","$getItemsLength","$getScrollOffset","$isScrolling","$getStartSpacerSize","$getTotalSize","_flushJump","$subscribe","target","cb","sub","add","delete","$update","type","payload","shouldFlushPendingJump","shouldSync","mutated","flushedJump","delta","distance","relativeOffset","updated","filter","prevSize","measuredCountBeforeStart","measuredSizes","forEach","s","push","sorted","arr","sort","a","b","len","median","prevDefaultItemSize","estimateDefaultItemSize","UPDATE_VIRTUAL_STATE","timeout","setTimeout","normalizeOffset","isHorizontal","createScrollObserver","viewport","getScrollOffset","updateScrollOffset","getStartOffset","now","Date","lastScrollTime","wheeling","touching","justTouchEnded","stillMomentumScrolling","onScrollEnd","id","cancel","clearTimeout","debouncedFn","_cancel","debounce","onScroll","onWheel","e","ctrlKey","timeDelta","deltaX","deltaY","onTouchStart","onTouchEnd","addEventListener","passive","_dispose","removeEventListener","_fixScrollJump","shift","createResizeObserver","ro","_observe","observe","_unobserve","unobserve","disconnect","ListItem","props","elementRef","mergeProps","_as","createEffect","onCleanup","_resizer","_index","createMemo","_isHorizontal","position","_offset","visibility","_hide","display","_$createComponent","Dynamic","component","ref","r$","children","_children","isSameRange","prev","next","Virtualizer","containerRef","horizontal","as","data","resizer","viewportElement","sizeKey","mountedIndexes","WeakMap","resizeObserver","entries","resizes","contentRect","offsetParent","get","$observeRoot","$observeItem","el","set","$dispose","createResizer","scroller","scrollObserver","cancelScroll","scrollOffsetKey","overflowKey","scheduleImperativeScroll","async","getTargetOffset","smooth","waitForMeasurement","queue","reject","promise","unsubscribe","scrollTo","behavior","$observe","isMomentumScrolling","$scrollTo","$scrollBy","$scrollToIndex","align","$fixScrollJump","createScroller","setRerender","createSignal","unsubscribeStore","unsubscribeOnScroll","_a","call","unsubscribeOnScrollEnd","range","isScrolling","totalSize","onMount","scrollSize","getScrollSize","findStartIndex","findEndIndex","scrollToIndex","scrollBy","scrollable","scrollRef","parentElement","createComputed","on","count","startMargin","dataSlice","flex","width","height","For","each","itemIndex","hide","untrack","item","attrs","_el$","_tmpl$","_$spread","_$mergeProps","contain","_$insert","createComponent","_ref$","_ref","_data","_shift","_onScrollEnd","windowSizeKey","cleanupOnWindowResize","container","onWindowResize","createWindowResizer","containerElement","calcOffsetToViewport","offsetKey","offsetSum","innerWidth","offsetWidth","parent","scroll","documentBody","body","html","getScrollbarSize","clientWidth","clientHeight","createWindowScroller","_$use","use","setProperty","_$effect","_p$","_v$","_v$2","_v$3","removeProperty","t"],"mappings":"oDACO,MAAMA,EAAO,MAGPC,IAAEA,EAAGC,IAAEA,EAAGC,IAAEA,EAAGC,MAAEA,GAAUC,KAK3BC,EAAQ,CACnBC,EACAC,EACAC,IACWR,EAAIQ,EAAUP,EAAIM,EAAUD,IAY5BG,EACe,mBAAnBC,eACHA,eACCC,IACCC,QAAQC,UAAUC,KAAKH,EAAG,EAMrBI,EAAWJ,IACtB,IAAIK,EACAC,EAEJ,MAAO,KACAD,IACHA,GAAS,EACTC,EAAQN,KAEHM,EACR,ECrCUC,GAAY,EAenBC,EAAO,CAACC,EAAiBC,EAAgBC,KAC7C,MAAMC,EAAMD,EAAU,UAAY,OAClC,IAAK,IAAIE,EAAI,EAAGA,EAAIH,EAAQG,IAC1BJ,EAAMG,GAAKL,GAEb,OAAOE,CAAK,EAMDK,EAAc,CAACR,EAAcS,KACxC,MAAMC,EAAOV,EAAMW,EAAOF,GAC1B,OAAOC,IAAST,EAAWD,EAAMY,EAAmBF,CAAI,EAM7CG,EAAc,CACzBb,EACAS,EACA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AF,IAAAF,EAAAK,IAAA,OAAAL,EAAAK,EAAAH,GAAAtC,EAAAzP,MAAA2R,YAAAI,SAAAA,GAAAtC,EAAAzP,MAAAiS,eAAA,WAAAD,IAAAH,EAAAnM,IAAA,OAAAmM,EAAAnM,EAAAsM,GAAAvC,EAAAzP,MAAA2R,YAAAK,iBAAAA,GAAAvC,EAAAzP,MAAAiS,eAAA,mBAAAJ,CAAA,GAAA,CAAAnK,OAAAvF,EAAA+P,OAAA/P,EAAAuD,OAAAvD,IAAAsN,EAX1D,IAAAA,EAAAO,CAW0D"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/src/core/utils.ts","../../src/src/core/cache.ts","../../src/src/core/environment.ts","../../src/src/core/store.ts","../../src/src/core/scroller.ts","../../src/src/core/resizer.ts","../../src/src/solid/ListItem.tsx","../../src/src/solid/utils.ts","../../src/src/solid/Virtualizer.tsx","../../src/src/solid/VList.tsx","../../src/src/solid/WindowVirtualizer.tsx"],"sourcesContent":["/** @internal */\nexport const NULL = null;\n\n/** @internal */\nexport const { min, max, abs, floor } = Math;\n\n/**\n * @internal\n */\nexport const clamp = (\n value: number,\n minValue: number,\n maxValue: number\n): number => min(maxValue, max(minValue, value));\n\n/**\n * @internal\n */\nexport const sort = <T extends number>(arr: readonly T[]): T[] => {\n return [...arr].sort((a, b) => a - b);\n};\n\n/**\n * @internal\n */\nexport const microtask: (fn: () => void) => void =\n typeof queueMicrotask === \"function\"\n ? queueMicrotask\n : (fn) => {\n Promise.resolve().then(fn);\n };\n\n/**\n * @internal\n */\nexport const once = <V>(fn: () => V): (() => V) => {\n let called: undefined | boolean;\n let cache: V;\n\n return () => {\n if (!called) {\n called = true;\n cache = fn();\n }\n return cache;\n };\n};\n","import { type InternalCacheSnapshot, type ItemsRange } from \"./types\";\nimport { clamp, floor, max, min, sort } from \"./utils\";\n\ntype Writeable<T> = {\n -readonly [key in keyof T]: Writeable<T[key]>;\n};\n\n/** @internal */\nexport const UNCACHED = -1;\n\n/**\n * @internal\n */\nexport type Cache = {\n readonly _length: number;\n // sizes\n readonly _sizes: number[];\n readonly _defaultItemSize: number;\n // offsets\n readonly _computedOffsetIndex: number;\n readonly _offsets: number[];\n};\n\nconst fill = (array: number[], length: number, prepend?: boolean): number[] => {\n const key = prepend ? \"unshift\" : \"push\";\n for (let i = 0; i < length; i++) {\n array[key](UNCACHED);\n }\n return array;\n};\n\n/**\n * @internal\n */\nexport const getItemSize = (cache: Cache, index: number): number => {\n const size = cache._sizes[index]!;\n return size === UNCACHED ? cache._defaultItemSize : size;\n};\n\n/**\n * @internal\n */\nexport const setItemSize = (\n cache: Writeable<Cache>,\n index: number,\n size: number\n): boolean => {\n const isInitialMeasurement = cache._sizes[index] === UNCACHED;\n cache._sizes[index] = size;\n // mark as dirty\n cache._computedOffsetIndex = min(index, cache._computedOffsetIndex);\n return isInitialMeasurement;\n};\n\n/**\n * @internal\n */\nexport const computeOffset = (\n cache: Writeable<Cache>,\n index: number\n): number => {\n if (!cache._length) return 0;\n if (cache._computedOffsetIndex >= index) {\n return cache._offsets[index]!;\n }\n\n if (cache._computedOffsetIndex < 0) {\n // first offset must be 0 to avoid returning NaN, which can cause infinite rerender.\n // https://github.com/inokawa/virtua/pull/160\n cache._offsets[0] = 0;\n cache._computedOffsetIndex = 0;\n }\n let i = cache._computedOffsetIndex;\n let top = cache._offsets[i]!;\n while (i < index) {\n top += getItemSize(cache, i);\n cache._offsets[++i] = top;\n }\n // mark as measured\n cache._computedOffsetIndex = index;\n return top;\n};\n\n/**\n * @internal\n */\nexport const computeTotalSize = (cache: Cache): number => {\n if (!cache._length) return 0;\n return (\n computeOffset(cache, cache._length - 1) +\n getItemSize(cache, cache._length - 1)\n );\n};\n\n/**\n * Finds the index of an item in the cache whose computed offset is closest to the specified offset.\n *\n * @internal\n */\nexport const findIndex = (\n cache: Cache,\n offset: number,\n low: number = 0,\n high: number = cache._length - 1\n): number => {\n // Find with binary search\n while (low <= high) {\n const mid = floor((low + high) / 2);\n const itemOffset = computeOffset(cache, mid);\n if (itemOffset <= offset) {\n if (itemOffset + getItemSize(cache, mid) > offset) {\n return mid;\n }\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n return clamp(low, 0, cache._length - 1);\n};\n\n/**\n * @internal\n */\nexport const computeRange = (\n cache: Cache,\n scrollOffset: number,\n viewportSize: number,\n prevStartIndex: number\n): ItemsRange => {\n // Clamp because prevStartIndex may exceed the limit when children decreased a lot after scrolling\n prevStartIndex = min(prevStartIndex, cache._length - 1);\n\n if (computeOffset(cache, prevStartIndex) <= scrollOffset) {\n // search forward\n // start <= end, prevStartIndex <= start\n const end = findIndex(cache, scrollOffset + viewportSize, prevStartIndex);\n return [findIndex(cache, scrollOffset, prevStartIndex, end), end];\n } else {\n // search backward\n // start <= end, start <= prevStartIndex\n const start = findIndex(cache, scrollOffset, undefined, prevStartIndex);\n return [start, findIndex(cache, scrollOffset + viewportSize, start)];\n }\n};\n\n/**\n * @internal\n */\nexport const estimateDefaultItemSize = (\n cache: Writeable<Cache>,\n startIndex: number\n): number => {\n let measuredCountBeforeStart = 0;\n // This function will be called after measurement so measured size array must be longer than 0\n const measuredSizes: number[] = [];\n cache._sizes.forEach((s, i) => {\n if (s !== UNCACHED) {\n measuredSizes.push(s);\n if (i < startIndex) {\n measuredCountBeforeStart++;\n }\n }\n });\n\n // Discard cache for now\n cache._computedOffsetIndex = -1;\n\n // Calculate median\n const sorted = sort(measuredSizes);\n const len = sorted.length;\n const mid = (len / 2) | 0;\n const median =\n len % 2 === 0 ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!;\n\n const prevDefaultItemSize = cache._defaultItemSize;\n\n // Calculate diff of unmeasured items before start\n return (\n ((cache._defaultItemSize = median) - prevDefaultItemSize) *\n max(startIndex - measuredCountBeforeStart, 0)\n );\n};\n\n/**\n * @internal\n */\nexport const initCache = (\n length: number,\n itemSize: number,\n snapshot?: InternalCacheSnapshot\n): Cache => {\n return {\n _defaultItemSize: snapshot ? snapshot[1] : itemSize,\n _sizes:\n snapshot && snapshot[0]\n ? // https://github.com/inokawa/virtua/issues/441\n fill(\n snapshot[0].slice(0, min(length, snapshot[0].length)),\n max(0, length - snapshot[0].length)\n )\n : fill([], length),\n _length: length,\n _computedOffsetIndex: -1,\n _offsets: fill([], length),\n };\n};\n\n/**\n * @internal\n */\nexport const takeCacheSnapshot = (cache: Cache): InternalCacheSnapshot => {\n return [cache._sizes.slice(), cache._defaultItemSize];\n};\n\n/**\n * @internal\n */\nexport const updateCacheLength = (\n cache: Writeable<Cache>,\n length: number,\n isShift?: boolean\n): number => {\n const diff = length - cache._length;\n\n cache._computedOffsetIndex = isShift\n ? // Discard cache for now\n -1\n : min(length - 1, cache._computedOffsetIndex);\n cache._length = length;\n\n if (diff > 0) {\n // Added\n fill(cache._offsets, diff);\n fill(cache._sizes, diff, isShift);\n return cache._defaultItemSize * diff;\n } else {\n // Removed\n cache._offsets.splice(diff);\n return (\n isShift ? cache._sizes.splice(0, -diff) : cache._sizes.splice(diff)\n ).reduce(\n (acc, removed) =>\n acc - (removed === UNCACHED ? cache._defaultItemSize : removed),\n 0\n );\n }\n};\n","import { once } from \"./utils\";\n\n/**\n * @internal\n */\nexport const isBrowser = typeof window !== \"undefined\";\n\nconst getDocumentElement = () => document.documentElement;\n\n/**\n * @internal\n */\nexport const getCurrentDocument = (node: HTMLElement): Document =>\n node.ownerDocument;\n\n/**\n * @internal\n */\nexport const getCurrentWindow = (doc: Document) => doc.defaultView!;\n\n/**\n * @internal\n */\nexport const isRTLDocument = /*#__PURE__*/ once((): boolean => {\n // TODO support SSR in rtl\n return isBrowser\n ? getComputedStyle(getDocumentElement()).direction === \"rtl\"\n : false;\n});\n\n/**\n * Currently, all browsers on iOS/iPadOS are WebKit, including WebView.\n * @internal\n */\nexport const isIOSWebKit = /*#__PURE__*/ once((): boolean => {\n return /iP(hone|od|ad)/.test(navigator.userAgent);\n});\n\n/**\n * @internal\n */\nexport const isSmoothScrollSupported = /*#__PURE__*/ once((): boolean => {\n return \"scrollBehavior\" in getDocumentElement().style;\n});\n","import {\n initCache,\n getItemSize as _getItemSize,\n computeTotalSize,\n computeOffset as computeStartOffset,\n UNCACHED,\n setItemSize,\n estimateDefaultItemSize,\n updateCacheLength,\n computeRange,\n takeCacheSnapshot,\n findIndex,\n} from \"./cache\";\nimport { isIOSWebKit } from \"./environment\";\nimport type {\n CacheSnapshot,\n InternalCacheSnapshot,\n ItemResize,\n ItemsRange,\n} from \"./types\";\nimport { abs, max, min, NULL } from \"./utils\";\n\nconst MAX_INT_32 = 0x7fffffff;\n\nconst SCROLL_IDLE = 0;\nconst SCROLL_DOWN = 1;\nconst SCROLL_UP = 2;\ntype ScrollDirection =\n | typeof SCROLL_IDLE\n | typeof SCROLL_DOWN\n | typeof SCROLL_UP;\n\nconst SCROLL_BY_NATIVE = 0;\nconst SCROLL_BY_MANUAL_SCROLL = 1;\nconst SCROLL_BY_SHIFT = 2;\ntype ScrollMode =\n | typeof SCROLL_BY_NATIVE\n | typeof SCROLL_BY_MANUAL_SCROLL\n | typeof SCROLL_BY_SHIFT;\n\n/** @internal */\nexport const ACTION_SCROLL = 1;\n/** @internal */\nexport const ACTION_SCROLL_END = 2;\n/** @internal */\nexport const ACTION_ITEM_RESIZE = 3;\n/** @internal */\nexport const ACTION_VIEWPORT_RESIZE = 4;\n/** @internal */\nexport const ACTION_ITEMS_LENGTH_CHANGE = 5;\n/** @internal */\nexport const ACTION_START_OFFSET_CHANGE = 6;\n/** @internal */\nexport const ACTION_MANUAL_SCROLL = 7;\n/** @internal */\nexport const ACTION_BEFORE_MANUAL_SMOOTH_SCROLL = 8;\n\ntype Actions =\n | [type: typeof ACTION_SCROLL, offset: number]\n | [type: typeof ACTION_SCROLL_END, dummy?: void]\n | [type: typeof ACTION_ITEM_RESIZE, entries: ItemResize[]]\n | [type: typeof ACTION_VIEWPORT_RESIZE, size: number]\n | [\n type: typeof ACTION_ITEMS_LENGTH_CHANGE,\n arg: [length: number, isShift?: boolean | undefined],\n ]\n | [type: typeof ACTION_START_OFFSET_CHANGE, offset: number]\n | [type: typeof ACTION_MANUAL_SCROLL, dummy?: void]\n | [type: typeof ACTION_BEFORE_MANUAL_SMOOTH_SCROLL, offset: number];\n\n/** @internal */\nexport const UPDATE_VIRTUAL_STATE = 0b0001;\n/** @internal */\nexport const UPDATE_SIZE_EVENT = 0b0010;\n/** @internal */\nexport const UPDATE_SCROLL_EVENT = 0b0100;\n/** @internal */\nexport const UPDATE_SCROLL_END_EVENT = 0b1000;\n\n/**\n * @internal\n */\nexport const getScrollSize = (store: VirtualStore): number => {\n return max(store.$getTotalSize(), store.$getViewportSize());\n};\n\n/**\n * @internal\n */\nexport const isInitialMeasurementDone = (store: VirtualStore): boolean => {\n return !!store.$getViewportSize();\n};\n\ntype Subscriber = (sync?: boolean) => void;\n\n/** @internal */\nexport type StateVersion =\n number & {} /* hack for typescript to pretend as not falsy */;\n\n/**\n * @internal\n */\nexport type VirtualStore = {\n $getStateVersion(): StateVersion;\n $getCacheSnapshot(): CacheSnapshot;\n $getRange(): ItemsRange;\n $findStartIndex(): number;\n $findEndIndex(): number;\n $isUnmeasuredItem(index: number): boolean;\n $getItemOffset(index: number): number;\n $getItemSize(index: number): number;\n $getItemsLength(): number;\n $getScrollOffset(): number;\n $isScrolling(): boolean;\n $getViewportSize(): number;\n $getStartSpacerSize(): number;\n $getTotalSize(): number;\n _flushJump(): [number, boolean];\n $subscribe(target: number, cb: Subscriber): () => void;\n $update(...action: Actions): void;\n _hasUnmeasuredItemsInFrozenRange(): boolean;\n};\n\n/**\n * @internal\n */\nexport const createVirtualStore = (\n elementsCount: number,\n itemSize: number = 40,\n overscan: number = 4,\n ssrCount: number = 0,\n cacheSnapshot?: CacheSnapshot | undefined,\n shouldAutoEstimateItemSize: boolean = false\n): VirtualStore => {\n let isSSR = !!ssrCount;\n let stateVersion: StateVersion = 1;\n let viewportSize = 0;\n let startSpacerSize = 0;\n let scrollOffset = 0;\n let jump = 0;\n let pendingJump = 0;\n let _flushedJump = 0;\n let _scrollDirection: ScrollDirection = SCROLL_IDLE;\n let _scrollMode: ScrollMode = SCROLL_BY_NATIVE;\n let _frozenRange: ItemsRange | null = isSSR\n ? [0, max(ssrCount - 1, 0)]\n : NULL;\n let _prevRange: ItemsRange = [0, 0];\n let _totalMeasuredSize = 0;\n\n const cache = initCache(\n elementsCount,\n itemSize,\n cacheSnapshot as unknown as InternalCacheSnapshot | undefined\n );\n const subscribers = new Set<[number, Subscriber]>();\n const getRelativeScrollOffset = () => scrollOffset - startSpacerSize;\n const getVisibleOffset = () => getRelativeScrollOffset() + pendingJump + jump;\n const getRange = (offset: number) => {\n return computeRange(cache, offset, viewportSize, _prevRange[0]);\n };\n const getTotalSize = (): number => computeTotalSize(cache);\n const getItemOffset = (index: number): number => {\n return computeStartOffset(cache, index) - pendingJump;\n };\n const getItemSize = (index: number): number => {\n return _getItemSize(cache, index);\n };\n\n const applyJump = (j: number) => {\n if (j) {\n // In iOS WebKit browsers, updating scroll position will stop scrolling so it have to be deferred during scrolling.\n if (isIOSWebKit() && _scrollDirection !== SCROLL_IDLE) {\n pendingJump += j;\n } else {\n jump += j;\n }\n }\n };\n\n return {\n $getStateVersion: () => stateVersion,\n $getCacheSnapshot: () => {\n return takeCacheSnapshot(cache) as unknown as CacheSnapshot;\n },\n $getRange: () => {\n let startIndex: number;\n let endIndex: number;\n if (_flushedJump) {\n // Return previous range for consistent render until next scroll event comes in.\n // And it must be clamped. https://github.com/inokawa/virtua/issues/597\n [startIndex, endIndex] = _prevRange;\n } else {\n [startIndex, endIndex] = _prevRange = getRange(\n max(0, getVisibleOffset())\n );\n if (_frozenRange) {\n startIndex = min(startIndex, _frozenRange[0]);\n endIndex = max(endIndex, _frozenRange[1]);\n }\n }\n\n if (_scrollDirection !== SCROLL_DOWN) {\n startIndex -= max(0, overscan);\n }\n if (_scrollDirection !== SCROLL_UP) {\n endIndex += max(0, overscan);\n }\n return [max(startIndex, 0), min(endIndex, cache._length - 1)];\n },\n $findStartIndex: () => findIndex(cache, getVisibleOffset()),\n $findEndIndex: () => findIndex(cache, getVisibleOffset() + viewportSize),\n $isUnmeasuredItem: (index) => cache._sizes[index] === UNCACHED,\n _hasUnmeasuredItemsInFrozenRange: () => {\n if (!_frozenRange) return false;\n return cache._sizes\n .slice(\n max(0, _frozenRange[0] - 1),\n min(cache._length - 1, _frozenRange[1] + 1) + 1\n )\n .includes(UNCACHED);\n },\n $getItemOffset: getItemOffset,\n $getItemSize: getItemSize,\n $getItemsLength: () => cache._length,\n $getScrollOffset: () => scrollOffset,\n $isScrolling: () => _scrollDirection !== SCROLL_IDLE,\n $getViewportSize: () => viewportSize,\n $getStartSpacerSize: () => startSpacerSize,\n $getTotalSize: getTotalSize,\n _flushJump: () => {\n _flushedJump = jump;\n jump = 0;\n return [\n _flushedJump,\n // Use absolute position not to exceed scrollable bounds\n _scrollMode === SCROLL_BY_SHIFT ||\n // https://github.com/inokawa/virtua/discussions/475\n getRelativeScrollOffset() + viewportSize >= getTotalSize(),\n ];\n },\n $subscribe: (target, cb) => {\n const sub: [number, Subscriber] = [target, cb];\n subscribers.add(sub);\n return () => {\n subscribers.delete(sub);\n };\n },\n $update: (type, payload): void => {\n let shouldFlushPendingJump: boolean | undefined;\n let shouldSync: boolean | undefined;\n let mutated = 0;\n\n switch (type) {\n case ACTION_SCROLL: {\n const flushedJump = _flushedJump;\n _flushedJump = 0;\n\n const delta = payload - scrollOffset;\n const distance = abs(delta);\n\n // Scroll event after jump compensation is not reliable because it may result in the opposite direction.\n // The delta of artificial scroll may not be equal with the jump because it may be batched with other scrolls.\n // And at least in latest Chrome/Firefox/Safari in 2023, setting value to scrollTop/scrollLeft can lose subpixel because its integer (sometimes float probably depending on dpr).\n const isJustJumped = flushedJump && distance < abs(flushedJump) + 1;\n\n // Scroll events are dispatched enough so it's ok to skip some of them.\n if (\n !isJustJumped &&\n // Ignore until manual scrolling\n _scrollMode === SCROLL_BY_NATIVE\n ) {\n _scrollDirection = delta < 0 ? SCROLL_UP : SCROLL_DOWN;\n }\n\n // TODO This will cause glitch in reverse infinite scrolling. Disable this until better solution is found.\n // if (\n // pendingJump &&\n // ((_scrollDirection === SCROLL_UP &&\n // payload - max(pendingJump, 0) <= 0) ||\n // (_scrollDirection === SCROLL_DOWN &&\n // payload - min(pendingJump, 0) >= getScrollOffsetMax()))\n // ) {\n // // Flush if almost reached to start or end\n // shouldFlushPendingJump = true;\n // }\n\n if (isSSR) {\n _frozenRange = NULL;\n isSSR = false;\n }\n\n scrollOffset = payload;\n mutated = UPDATE_SCROLL_EVENT;\n\n // Skip if offset is not changed\n // Scroll offset may exceed min or max especially in Safari's elastic scrolling.\n const relativeOffset = getRelativeScrollOffset();\n if (\n relativeOffset >= -viewportSize &&\n relativeOffset <= getTotalSize()\n ) {\n mutated += UPDATE_VIRTUAL_STATE;\n\n // Update synchronously if scrolled a lot\n shouldSync = distance > viewportSize;\n }\n break;\n }\n case ACTION_SCROLL_END: {\n mutated = UPDATE_SCROLL_END_EVENT;\n if (_scrollDirection !== SCROLL_IDLE) {\n shouldFlushPendingJump = true;\n mutated += UPDATE_VIRTUAL_STATE;\n }\n _scrollDirection = SCROLL_IDLE;\n _scrollMode = SCROLL_BY_NATIVE;\n _frozenRange = NULL;\n break;\n }\n case ACTION_ITEM_RESIZE: {\n const updated = payload.filter(\n ([index, size]) => cache._sizes[index] !== size\n );\n\n // Skip if all items are cached and not updated\n if (!updated.length) {\n break;\n }\n\n // Calculate jump by resize to minimize junks in appearance\n applyJump(\n updated.reduce((acc, [index, size]) => {\n if (\n // Keep distance from end during shifting\n _scrollMode === SCROLL_BY_SHIFT ||\n (_frozenRange\n ? // https://github.com/inokawa/virtua/issues/380\n // https://github.com/inokawa/virtua/issues/590\n !isSSR && index < _frozenRange[0]\n : // Otherwise we should maintain visible position\n getItemOffset(index) +\n // https://github.com/inokawa/virtua/issues/385\n (_scrollDirection === SCROLL_IDLE &&\n _scrollMode === SCROLL_BY_NATIVE\n ? getItemSize(index)\n : 0) <\n getRelativeScrollOffset())\n ) {\n acc += size - getItemSize(index);\n }\n return acc;\n }, 0)\n );\n\n // Update item sizes\n for (const [index, size] of updated) {\n const prevSize = getItemSize(index);\n const isInitialMeasurement = setItemSize(cache, index, size);\n\n if (shouldAutoEstimateItemSize) {\n _totalMeasuredSize += isInitialMeasurement\n ? size\n : size - prevSize;\n }\n }\n\n // Estimate initial item size from measured sizes\n if (\n shouldAutoEstimateItemSize &&\n viewportSize &&\n // If the total size is lower than the viewport, the item may be a empty state\n _totalMeasuredSize > viewportSize\n ) {\n applyJump(\n estimateDefaultItemSize(\n cache,\n findIndex(cache, getVisibleOffset())\n )\n );\n shouldAutoEstimateItemSize = false;\n }\n\n mutated = UPDATE_VIRTUAL_STATE + UPDATE_SIZE_EVENT;\n\n // Synchronous update is necessary in current design to minimize visible glitch in concurrent rendering.\n // However this seems to be the main cause of the errors from ResizeObserver.\n // https://github.com/inokawa/virtua/issues/470\n //\n // And in React, synchronous update with flushSync after asynchronous update will overtake the asynchronous one.\n // If items resize happens just after scroll, race condition can occur depending on implementation.\n shouldSync = true;\n break;\n }\n case ACTION_VIEWPORT_RESIZE: {\n if (viewportSize !== payload) {\n viewportSize = payload;\n mutated = UPDATE_VIRTUAL_STATE + UPDATE_SIZE_EVENT;\n }\n break;\n }\n case ACTION_ITEMS_LENGTH_CHANGE: {\n if (payload[1]) {\n applyJump(updateCacheLength(cache, payload[0], true));\n _scrollMode = SCROLL_BY_SHIFT;\n mutated = UPDATE_VIRTUAL_STATE;\n } else {\n updateCacheLength(cache, payload[0]);\n // https://github.com/inokawa/virtua/issues/552\n // https://github.com/inokawa/virtua/issues/557\n mutated = UPDATE_VIRTUAL_STATE;\n }\n break;\n }\n case ACTION_START_OFFSET_CHANGE: {\n startSpacerSize = payload;\n break;\n }\n case ACTION_MANUAL_SCROLL: {\n _scrollMode = SCROLL_BY_MANUAL_SCROLL;\n break;\n }\n case ACTION_BEFORE_MANUAL_SMOOTH_SCROLL: {\n _frozenRange = getRange(payload);\n mutated = UPDATE_VIRTUAL_STATE;\n break;\n }\n }\n\n if (mutated) {\n stateVersion = (stateVersion & MAX_INT_32) + 1;\n\n if (shouldFlushPendingJump && pendingJump) {\n jump += pendingJump;\n pendingJump = 0;\n }\n\n subscribers.forEach(([target, cb]) => {\n // Early return to skip React's computation\n if (!(mutated & target)) {\n return;\n }\n // https://github.com/facebook/react/issues/25191\n // https://github.com/facebook/react/blob/a5fc797db14c6e05d4d5c4dbb22a0dd70d41f5d5/packages/react-reconciler/src/ReactFiberWorkLoop.js#L1443-L1447\n cb(shouldSync);\n });\n }\n },\n };\n};\n","import {\n getCurrentDocument,\n getCurrentWindow,\n isIOSWebKit,\n isRTLDocument,\n isSmoothScrollSupported,\n} from \"./environment\";\nimport {\n ACTION_SCROLL,\n type VirtualStore,\n ACTION_SCROLL_END,\n UPDATE_SIZE_EVENT,\n ACTION_MANUAL_SCROLL,\n ACTION_BEFORE_MANUAL_SMOOTH_SCROLL,\n ACTION_START_OFFSET_CHANGE,\n isInitialMeasurementDone,\n} from \"./store\";\nimport { type ScrollToIndexOpts } from \"./types\";\nimport { clamp, microtask, NULL } from \"./utils\";\n\nconst timeout = setTimeout;\n\nconst debounce = <T extends () => void>(fn: T, ms: number) => {\n let id: ReturnType<typeof setTimeout> | undefined | null;\n\n const cancel = () => {\n if (id != NULL) {\n clearTimeout(id);\n }\n };\n const debouncedFn = () => {\n cancel();\n id = timeout(() => {\n id = NULL;\n fn();\n }, ms);\n };\n debouncedFn._cancel = cancel;\n return debouncedFn;\n};\n\n/**\n * scrollLeft is negative value in rtl direction.\n *\n * left right\n * 0 100 spec compliant (ltr)\n * -100 0 spec compliant (rtl)\n * https://github.com/othree/jquery.rtl-scroll-type\n */\nconst normalizeOffset = (offset: number, isHorizontal: boolean): number => {\n if (isHorizontal && isRTLDocument()) {\n return -offset;\n } else {\n return offset;\n }\n};\n\nconst createScrollObserver = (\n store: VirtualStore,\n viewport: HTMLElement | Window,\n isHorizontal: boolean,\n getScrollOffset: () => number,\n updateScrollOffset: (\n value: number,\n shift: boolean,\n isMomentumScrolling: boolean\n ) => void,\n getStartOffset?: () => number\n) => {\n const now = Date.now;\n\n let lastScrollTime = 0;\n let wheeling = false;\n let touching = false;\n let justTouchEnded = false;\n let stillMomentumScrolling = false;\n\n const onScrollEnd = debounce(() => {\n if (wheeling || touching) {\n wheeling = false;\n\n // Wait while wheeling or touching\n onScrollEnd();\n return;\n }\n\n justTouchEnded = false;\n\n store.$update(ACTION_SCROLL_END);\n }, 150);\n\n const onScroll = () => {\n lastScrollTime = now();\n\n if (justTouchEnded) {\n stillMomentumScrolling = true;\n }\n\n if (getStartOffset) {\n store.$update(ACTION_START_OFFSET_CHANGE, getStartOffset());\n }\n store.$update(ACTION_SCROLL, getScrollOffset());\n\n onScrollEnd();\n };\n\n // Infer scroll state also from wheel events\n // Sometimes scroll events do not fire when frame dropped even if the visual have been already scrolled\n const onWheel = ((e: WheelEvent) => {\n if (\n wheeling ||\n // Scroll start should be detected with scroll event\n !store.$isScrolling() ||\n // Probably a pinch-to-zoom gesture\n e.ctrlKey\n ) {\n return;\n }\n\n const timeDelta = now() - lastScrollTime;\n if (\n // Check if wheel event occurs some time after scrolling\n 150 > timeDelta &&\n 50 < timeDelta &&\n // Get delta before checking deltaMode for firefox behavior\n // https://github.com/w3c/uievents/issues/181#issuecomment-392648065\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1392460#c34\n (isHorizontal ? e.deltaX : e.deltaY)\n ) {\n wheeling = true;\n }\n }) as (e: Event) => void; // FIXME type error. why only here?\n\n const onTouchStart = () => {\n touching = true;\n justTouchEnded = stillMomentumScrolling = false;\n };\n const onTouchEnd = () => {\n touching = false;\n if (isIOSWebKit()) {\n justTouchEnded = true;\n }\n };\n\n viewport.addEventListener(\"scroll\", onScroll);\n viewport.addEventListener(\"wheel\", onWheel, { passive: true });\n viewport.addEventListener(\"touchstart\", onTouchStart, { passive: true });\n viewport.addEventListener(\"touchend\", onTouchEnd, { passive: true });\n\n return {\n _dispose: () => {\n viewport.removeEventListener(\"scroll\", onScroll);\n viewport.removeEventListener(\"wheel\", onWheel);\n viewport.removeEventListener(\"touchstart\", onTouchStart);\n viewport.removeEventListener(\"touchend\", onTouchEnd);\n onScrollEnd._cancel();\n },\n _fixScrollJump: () => {\n const [jump, shift] = store._flushJump();\n if (!jump) return;\n updateScrollOffset(\n normalizeOffset(jump, isHorizontal),\n shift,\n stillMomentumScrolling\n );\n stillMomentumScrolling = false;\n\n if (shift && store.$getViewportSize() > store.$getTotalSize()) {\n // In this case applying jump may not cause scroll.\n // Current logic expects scroll event occurs after applying jump so we dispatch it manually.\n store.$update(ACTION_SCROLL, getScrollOffset());\n }\n },\n };\n};\n\ntype ScrollObserver = ReturnType<typeof createScrollObserver>;\n\n/**\n * @internal\n */\nexport type Scroller = {\n $observe: (viewportElement: HTMLElement) => void;\n $dispose(): void;\n $scrollTo: (offset: number) => void;\n $scrollBy: (offset: number) => void;\n $scrollToIndex: (index: number, opts?: ScrollToIndexOpts) => void;\n $fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createScroller = (\n store: VirtualStore,\n isHorizontal: boolean\n): Scroller => {\n let viewportElement: HTMLElement | undefined;\n let scrollObserver: ScrollObserver | undefined;\n let cancelScroll: (() => void) | undefined;\n const scrollOffsetKey = isHorizontal ? \"scrollLeft\" : \"scrollTop\";\n const overflowKey = isHorizontal ? \"overflowX\" : \"overflowY\";\n\n // The given offset will be clamped by browser\n // https://drafts.csswg.org/cssom-view/#dom-element-scrolltop\n const scheduleImperativeScroll = async (\n getTargetOffset: () => number,\n smooth?: boolean\n ) => {\n if (!viewportElement) {\n // Wait for element assign. The element may be undefined if scrollRef prop is used and scroll is scheduled on mount.\n microtask(() => scheduleImperativeScroll(getTargetOffset, smooth));\n return;\n }\n\n if (cancelScroll) {\n // Cancel waiting scrollTo\n cancelScroll();\n }\n\n const waitForMeasurement = (): [Promise<void>, () => void] => {\n // Wait for the scroll destination items to be measured.\n // The measurement will be done asynchronously and the timing is not predictable so we use promise.\n let queue: (() => void) | undefined;\n return [\n new Promise<void>((resolve, reject) => {\n queue = resolve;\n cancelScroll = reject;\n\n // Resize event may not happen when the window/tab is not visible, or during browser back in Safari.\n // We have to wait for the initial measurement to avoid failing imperative scroll on mount.\n // https://github.com/inokawa/virtua/issues/450\n if (isInitialMeasurementDone(store)) {\n // Reject when items around scroll destination completely measured\n timeout(reject, 150);\n }\n }),\n store.$subscribe(UPDATE_SIZE_EVENT, () => {\n queue && queue();\n }),\n ];\n };\n\n if (smooth && isSmoothScrollSupported()) {\n while (true) {\n store.$update(ACTION_BEFORE_MANUAL_SMOOTH_SCROLL, getTargetOffset());\n\n if (!store._hasUnmeasuredItemsInFrozenRange()) {\n break;\n }\n\n const [promise, unsubscribe] = waitForMeasurement();\n\n try {\n await promise;\n } catch (e) {\n // canceled\n return;\n } finally {\n unsubscribe();\n }\n }\n\n viewportElement.scrollTo({\n [isHorizontal ? \"left\" : \"top\"]: normalizeOffset(\n getTargetOffset(),\n isHorizontal\n ),\n behavior: \"smooth\",\n });\n } else {\n while (true) {\n const [promise, unsubscribe] = waitForMeasurement();\n\n try {\n viewportElement[scrollOffsetKey] = normalizeOffset(\n getTargetOffset(),\n isHorizontal\n );\n store.$update(ACTION_MANUAL_SCROLL);\n\n await promise;\n } catch (e) {\n // canceled or finished\n return;\n } finally {\n unsubscribe();\n }\n }\n }\n };\n\n return {\n $observe(viewport) {\n viewportElement = viewport;\n\n scrollObserver = createScrollObserver(\n store,\n viewport,\n isHorizontal,\n () => normalizeOffset(viewport[scrollOffsetKey], isHorizontal),\n (jump, shift, isMomentumScrolling) => {\n // If we update scroll position while touching on iOS, the position will be reverted.\n // However iOS WebKit fires touch events only once at the beginning of momentum scrolling.\n // That means we have no reliable way to confirm still touched or not if user touches more than once during momentum scrolling...\n // This is a hack for the suspectable situations, inspired by https://github.com/prud/ios-overflow-scroll-to-top\n if (isMomentumScrolling) {\n const style = viewport.style;\n const prev = style[overflowKey];\n style[overflowKey] = \"hidden\";\n timeout(() => {\n style[overflowKey] = prev;\n });\n }\n\n if (shift) {\n viewport[scrollOffsetKey] = store.$getScrollOffset() + jump;\n // https://github.com/inokawa/virtua/issues/357\n cancelScroll && cancelScroll();\n } else {\n viewport[scrollOffsetKey] += jump;\n }\n }\n );\n },\n $dispose() {\n scrollObserver && scrollObserver._dispose();\n },\n $scrollTo(offset) {\n scheduleImperativeScroll(() => offset);\n },\n $scrollBy(offset) {\n offset += store.$getScrollOffset();\n scheduleImperativeScroll(() => offset);\n },\n $scrollToIndex(index, { align, smooth, offset = 0 } = {}) {\n index = clamp(index, 0, store.$getItemsLength() - 1);\n\n if (align === \"nearest\") {\n const itemOffset = store.$getItemOffset(index);\n const scrollOffset = store.$getScrollOffset();\n\n if (itemOffset < scrollOffset) {\n align = \"start\";\n } else if (\n itemOffset + store.$getItemSize(index) >\n scrollOffset + store.$getViewportSize()\n ) {\n align = \"end\";\n } else {\n // already completely visible\n return;\n }\n }\n\n scheduleImperativeScroll(() => {\n return (\n offset +\n store.$getStartSpacerSize() +\n store.$getItemOffset(index) +\n (align === \"end\"\n ? store.$getItemSize(index) - store.$getViewportSize()\n : align === \"center\"\n ? (store.$getItemSize(index) - store.$getViewportSize()) / 2\n : 0)\n );\n }, smooth);\n },\n $fixScrollJump: () => {\n scrollObserver && scrollObserver._fixScrollJump();\n },\n };\n};\n\n/**\n * @internal\n */\nexport type WindowScroller = {\n $observe(containerElement: HTMLElement): void;\n $dispose(): void;\n $scrollToIndex: (index: number, opts?: ScrollToIndexOpts) => void;\n $fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createWindowScroller = (\n store: VirtualStore,\n isHorizontal: boolean\n): WindowScroller => {\n let containerElement: HTMLElement | undefined;\n let scrollObserver: ScrollObserver | undefined;\n let cancelScroll: (() => void) | undefined;\n\n const calcOffsetToViewport = (\n node: HTMLElement,\n viewport: HTMLElement,\n window: Window,\n isHorizontal: boolean,\n offset: number = 0\n ): number => {\n // TODO calc offset only when it changes (maybe impossible)\n const offsetKey = isHorizontal ? \"offsetLeft\" : \"offsetTop\";\n const offsetSum =\n offset +\n (isHorizontal && isRTLDocument()\n ? window.innerWidth - node[offsetKey] - node.offsetWidth\n : node[offsetKey]);\n\n const parent = node.offsetParent;\n if (node === viewport || !parent) {\n return offsetSum;\n }\n\n return calcOffsetToViewport(\n parent as HTMLElement,\n viewport,\n window,\n isHorizontal,\n offsetSum\n );\n };\n\n const scheduleImperativeScroll = async (\n getTargetOffset: () => number,\n smooth?: boolean\n ) => {\n if (!containerElement) {\n // Wait for element assign\n microtask(() => scheduleImperativeScroll(getTargetOffset, smooth));\n return;\n }\n\n if (cancelScroll) {\n cancelScroll();\n }\n\n const waitForMeasurement = (): [Promise<void>, () => void] => {\n let queue: (() => void) | undefined;\n return [\n new Promise<void>((resolve, reject) => {\n queue = resolve;\n cancelScroll = reject;\n\n if (isInitialMeasurementDone(store)) {\n timeout(reject, 150);\n }\n }),\n store.$subscribe(UPDATE_SIZE_EVENT, () => {\n queue && queue();\n }),\n ];\n };\n\n const window = getCurrentWindow(getCurrentDocument(containerElement));\n\n if (smooth && isSmoothScrollSupported()) {\n while (true) {\n store.$update(ACTION_BEFORE_MANUAL_SMOOTH_SCROLL, getTargetOffset());\n\n if (!store._hasUnmeasuredItemsInFrozenRange()) {\n break;\n }\n\n const [promise, unsubscribe] = waitForMeasurement();\n\n try {\n await promise;\n } catch (e) {\n return;\n } finally {\n unsubscribe();\n }\n }\n\n window.scroll({\n [isHorizontal ? \"left\" : \"top\"]: normalizeOffset(\n getTargetOffset(),\n isHorizontal\n ),\n behavior: \"smooth\",\n });\n } else {\n while (true) {\n const [promise, unsubscribe] = waitForMeasurement();\n\n try {\n window.scroll({\n [isHorizontal ? \"left\" : \"top\"]: normalizeOffset(\n getTargetOffset(),\n isHorizontal\n ),\n });\n store.$update(ACTION_MANUAL_SCROLL);\n\n await promise;\n } catch (e) {\n return;\n } finally {\n unsubscribe();\n }\n }\n }\n };\n\n return {\n $observe(container) {\n containerElement = container;\n const scrollOffsetKey = isHorizontal ? \"scrollX\" : \"scrollY\";\n\n const document = getCurrentDocument(container);\n const window = getCurrentWindow(document);\n const documentBody = document.body;\n\n scrollObserver = createScrollObserver(\n store,\n window,\n isHorizontal,\n () => normalizeOffset(window[scrollOffsetKey], isHorizontal),\n (jump, shift) => {\n // TODO support case two window scrollers exist in the same view\n if (shift) {\n window.scroll({\n [isHorizontal ? \"left\" : \"top\"]: store.$getScrollOffset() + jump,\n });\n } else {\n window.scrollBy(isHorizontal ? jump : 0, isHorizontal ? 0 : jump);\n }\n },\n () =>\n calcOffsetToViewport(container, documentBody, window, isHorizontal)\n );\n },\n $dispose() {\n scrollObserver && scrollObserver._dispose();\n containerElement = undefined;\n },\n $fixScrollJump: () => {\n scrollObserver && scrollObserver._fixScrollJump();\n },\n $scrollToIndex(index, { align, smooth, offset = 0 } = {}) {\n if (!containerElement) return;\n\n index = clamp(index, 0, store.$getItemsLength() - 1);\n\n if (align === \"nearest\") {\n const itemOffset = store.$getItemOffset(index);\n const scrollOffset = store.$getScrollOffset();\n\n if (itemOffset < scrollOffset) {\n align = \"start\";\n } else if (\n itemOffset + store.$getItemSize(index) >\n scrollOffset + store.$getViewportSize()\n ) {\n align = \"end\";\n } else {\n return;\n }\n }\n\n const document = getCurrentDocument(containerElement);\n const window = getCurrentWindow(document);\n const html = document.documentElement;\n const getScrollbarSize = () =>\n store.$getViewportSize() -\n (isHorizontal ? html.clientWidth : html.clientHeight);\n\n scheduleImperativeScroll(() => {\n return (\n offset +\n // Calculate target scroll position including container's offset from document\n calcOffsetToViewport(\n containerElement!,\n document.body,\n window,\n isHorizontal\n ) +\n // store._getStartSpacerSize() +\n store.$getItemOffset(index) +\n (align === \"end\"\n ? store.$getItemSize(index) -\n (store.$getViewportSize() - getScrollbarSize())\n : align === \"center\"\n ? (store.$getItemSize(index) -\n (store.$getViewportSize() - getScrollbarSize())) /\n 2\n : 0)\n );\n }, smooth);\n },\n };\n};\n\n/**\n * @internal\n */\nexport type GridScroller = {\n $observe: (viewportElement: HTMLElement) => void;\n $dispose(): void;\n $scrollTo: (offsetX: number, offsetY: number) => void;\n $scrollBy: (offsetX: number, offsetY: number) => void;\n $scrollToIndex: (indexX: number, indexY: number) => void;\n $fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createGridScroller = (\n vStore: VirtualStore,\n hStore: VirtualStore\n): GridScroller => {\n const vScroller = createScroller(vStore, false);\n const hScroller = createScroller(hStore, true);\n return {\n $observe(viewportElement) {\n vScroller.$observe(viewportElement);\n hScroller.$observe(viewportElement);\n },\n $dispose() {\n vScroller.$dispose();\n hScroller.$dispose();\n },\n $scrollTo(offsetX, offsetY) {\n vScroller.$scrollTo(offsetY);\n hScroller.$scrollTo(offsetX);\n },\n $scrollBy(offsetX, offsetY) {\n vScroller.$scrollBy(offsetY);\n hScroller.$scrollBy(offsetX);\n },\n $scrollToIndex(indexX, indexY) {\n vScroller.$scrollToIndex(indexY);\n hScroller.$scrollToIndex(indexX);\n },\n $fixScrollJump() {\n vScroller.$fixScrollJump();\n hScroller.$fixScrollJump();\n },\n };\n};\n","import { getCurrentDocument, getCurrentWindow } from \"./environment\";\nimport {\n ACTION_ITEM_RESIZE,\n ACTION_VIEWPORT_RESIZE,\n type VirtualStore,\n} from \"./store\";\nimport { type ItemResize } from \"./types\";\nimport { max, NULL } from \"./utils\";\n\nconst createResizeObserver = (cb: ResizeObserverCallback) => {\n let ro: ResizeObserver | undefined;\n\n return {\n _observe(e: HTMLElement) {\n // Initialize ResizeObserver lazily for SSR\n // https://www.w3.org/TR/resize-observer/#intro\n (\n ro ||\n // https://bugs.chromium.org/p/chromium/issues/detail?id=1491739\n (ro = new (getCurrentWindow(getCurrentDocument(e)).ResizeObserver)(cb))\n ).observe(e);\n },\n _unobserve(e: HTMLElement) {\n ro!.unobserve(e);\n },\n _dispose() {\n ro && ro.disconnect();\n },\n };\n};\n\n/**\n * @internal\n */\nexport type ItemResizeObserver = (el: HTMLElement, i: number) => () => void;\n\ninterface ListResizer {\n $observeRoot(viewportElement: HTMLElement): void;\n $observeItem: ItemResizeObserver;\n $dispose(): void;\n}\n\n/**\n * @internal\n */\nexport const createResizer = (\n store: VirtualStore,\n isHorizontal: boolean\n): ListResizer => {\n let viewportElement: HTMLElement | undefined;\n const sizeKey = isHorizontal ? \"width\" : \"height\";\n const mountedIndexes = new WeakMap<Element, number>();\n\n const resizeObserver = createResizeObserver((entries) => {\n const resizes: ItemResize[] = [];\n for (const { target, contentRect } of entries) {\n // Skip zero-sized rects that may be observed under `display: none` style\n if (!(target as HTMLElement).offsetParent) continue;\n\n if (target === viewportElement) {\n store.$update(ACTION_VIEWPORT_RESIZE, contentRect[sizeKey]);\n } else {\n const index = mountedIndexes.get(target);\n if (index != NULL) {\n resizes.push([index, contentRect[sizeKey]]);\n }\n }\n }\n\n if (resizes.length) {\n store.$update(ACTION_ITEM_RESIZE, resizes);\n }\n });\n\n return {\n $observeRoot(viewport: HTMLElement) {\n resizeObserver._observe((viewportElement = viewport));\n },\n $observeItem: (el: HTMLElement, i: number) => {\n mountedIndexes.set(el, i);\n resizeObserver._observe(el);\n return () => {\n mountedIndexes.delete(el);\n resizeObserver._unobserve(el);\n };\n },\n $dispose: resizeObserver._dispose,\n };\n};\n\ninterface WindowListResizer {\n $observeRoot(container: HTMLElement): void;\n $observeItem: ItemResizeObserver;\n $dispose(): void;\n}\n\n/**\n * @internal\n */\nexport const createWindowResizer = (\n store: VirtualStore,\n isHorizontal: boolean\n): WindowListResizer => {\n const sizeKey = isHorizontal ? \"width\" : \"height\";\n const windowSizeKey = isHorizontal ? \"innerWidth\" : \"innerHeight\";\n const mountedIndexes = new WeakMap<Element, number>();\n\n const resizeObserver = createResizeObserver((entries) => {\n const resizes: ItemResize[] = [];\n for (const { target, contentRect } of entries) {\n // Skip zero-sized rects that may be observed under `display: none` style\n if (!(target as HTMLElement).offsetParent) continue;\n\n const index = mountedIndexes.get(target);\n if (index != NULL) {\n resizes.push([index, contentRect[sizeKey]]);\n }\n }\n\n if (resizes.length) {\n store.$update(ACTION_ITEM_RESIZE, resizes);\n }\n });\n\n let cleanupOnWindowResize: (() => void) | undefined;\n\n return {\n $observeRoot(container) {\n const window = getCurrentWindow(getCurrentDocument(container));\n const onWindowResize = () => {\n store.$update(ACTION_VIEWPORT_RESIZE, window[windowSizeKey]);\n };\n window.addEventListener(\"resize\", onWindowResize);\n onWindowResize();\n\n cleanupOnWindowResize = () => {\n window.removeEventListener(\"resize\", onWindowResize);\n };\n },\n $observeItem: (el: HTMLElement, i: number) => {\n mountedIndexes.set(el, i);\n resizeObserver._observe(el);\n return () => {\n mountedIndexes.delete(el);\n resizeObserver._unobserve(el);\n };\n },\n $dispose() {\n cleanupOnWindowResize && cleanupOnWindowResize();\n resizeObserver._dispose();\n },\n };\n};\n\n/**\n * @internal\n */\nexport const createGridResizer = (\n vStore: VirtualStore,\n hStore: VirtualStore\n) => {\n let viewportElement: HTMLElement | undefined;\n\n const heightKey = \"height\";\n const widthKey = \"width\";\n const mountedIndexes = new WeakMap<\n Element,\n [rowIndex: number, colIndex: number]\n >();\n\n type CellSize = [height: number, width: number];\n const maybeCachedRowIndexes = new Set<number>();\n const maybeCachedColIndexes = new Set<number>();\n const sizeCache = new Map<string, CellSize>();\n const getKey = (rowIndex: number, colIndex: number): string =>\n `${rowIndex}-${colIndex}`;\n\n const resizeObserver = createResizeObserver((entries) => {\n const resizedRows = new Set<number>();\n const resizedCols = new Set<number>();\n for (const { target, contentRect } of entries) {\n // Skip zero-sized rects that may be observed under `display: none` style\n if (!(target as HTMLElement).offsetParent) continue;\n\n if (target === viewportElement) {\n vStore.$update(ACTION_VIEWPORT_RESIZE, contentRect[heightKey]);\n hStore.$update(ACTION_VIEWPORT_RESIZE, contentRect[widthKey]);\n } else {\n const cell = mountedIndexes.get(target);\n if (cell) {\n const [rowIndex, colIndex] = cell;\n const key = getKey(rowIndex, colIndex);\n const prevSize = sizeCache.get(key);\n const size: CellSize = [\n contentRect[heightKey],\n contentRect[widthKey],\n ];\n let rowResized: boolean | undefined;\n let colResized: boolean | undefined;\n if (!prevSize) {\n rowResized = colResized = true;\n } else {\n if (prevSize[0] !== size[0]) {\n rowResized = true;\n }\n if (prevSize[1] !== size[1]) {\n colResized = true;\n }\n }\n if (rowResized) {\n resizedRows.add(rowIndex);\n }\n if (colResized) {\n resizedCols.add(colIndex);\n }\n if (rowResized || colResized) {\n sizeCache.set(key, size);\n }\n }\n }\n }\n\n if (resizedRows.size) {\n const heightResizes: ItemResize[] = [];\n resizedRows.forEach((rowIndex) => {\n let maxHeight = 0;\n maybeCachedColIndexes.forEach((colIndex) => {\n const size = sizeCache.get(getKey(rowIndex, colIndex));\n if (size) {\n maxHeight = max(maxHeight, size[0]);\n }\n });\n if (maxHeight) {\n heightResizes.push([rowIndex, maxHeight]);\n }\n });\n vStore.$update(ACTION_ITEM_RESIZE, heightResizes);\n }\n if (resizedCols.size) {\n const widthResizes: ItemResize[] = [];\n resizedCols.forEach((colIndex) => {\n let maxWidth = 0;\n maybeCachedRowIndexes.forEach((rowIndex) => {\n const size = sizeCache.get(getKey(rowIndex, colIndex));\n if (size) {\n maxWidth = max(maxWidth, size[1]);\n }\n });\n if (maxWidth) {\n widthResizes.push([colIndex, maxWidth]);\n }\n });\n hStore.$update(ACTION_ITEM_RESIZE, widthResizes);\n }\n });\n\n return {\n $observeRoot(viewport: HTMLElement) {\n resizeObserver._observe((viewportElement = viewport));\n },\n $observeItem(el: HTMLElement, rowIndex: number, colIndex: number) {\n mountedIndexes.set(el, [rowIndex, colIndex]);\n maybeCachedRowIndexes.add(rowIndex);\n maybeCachedColIndexes.add(colIndex);\n resizeObserver._observe(el);\n return () => {\n mountedIndexes.delete(el);\n resizeObserver._unobserve(el);\n };\n },\n $dispose: resizeObserver._dispose,\n };\n};\n\n/**\n * @internal\n */\nexport type GridResizer = ReturnType<typeof createGridResizer>;\n","/**\n * @jsxImportSource solid-js\n */\nimport { ItemResizeObserver, isRTLDocument } from \"../core\";\nimport {\n Component,\n JSX,\n createEffect,\n createMemo,\n mergeProps,\n onCleanup,\n type ValidComponent,\n} from \"solid-js\";\nimport { Dynamic } from \"solid-js/web\";\n\ninterface ListItemProps {\n _children: JSX.Element;\n _resizer: ItemResizeObserver;\n _index: number;\n _offset: number;\n _hide: boolean;\n _isHorizontal: boolean;\n _as?: ValidComponent;\n}\n\n/**\n * @internal\n */\nexport const ListItem: Component<ListItemProps> = (props) => {\n let elementRef: HTMLDivElement | undefined;\n props = mergeProps<[Partial<ListItemProps>, ListItemProps]>(\n { _as: \"div\" },\n props\n );\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n createEffect(() => {\n if (!elementRef) return;\n onCleanup(props._resizer(elementRef, props._index));\n });\n\n const style = createMemo(() => {\n const isHorizontal = props._isHorizontal;\n const style: JSX.CSSProperties = {\n position: \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : \"left\"]: \"0px\",\n [isHorizontal ? (isRTLDocument() ? \"right\" : \"left\") : \"top\"]:\n props._offset + \"px\",\n visibility: props._hide ? \"hidden\" : \"visible\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n return style;\n });\n\n return (\n <Dynamic component={props._as} index={props._index} ref={elementRef} style={style()}>\n {props._children}\n </Dynamic>\n );\n};\n","import { ItemsRange } from \"../core\";\n\n/**\n * @internal\n */\nexport const isSameRange = (prev: ItemsRange, next: ItemsRange): boolean => {\n return prev[0] === next[0] && prev[1] === next[1];\n};\n","/**\n * @jsxImportSource solid-js\n */\nimport {\n onMount,\n onCleanup,\n createEffect,\n createSignal,\n createMemo,\n JSX,\n on,\n createComputed,\n type ValidComponent,\n mergeProps,\n For,\n Accessor,\n untrack,\n} from \"solid-js\";\nimport { Dynamic } from \"solid-js/web\";\nimport {\n UPDATE_SCROLL_EVENT,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n getScrollSize,\n ACTION_START_OFFSET_CHANGE,\n createResizer,\n createScroller,\n ItemsRange,\n ScrollToIndexOpts,\n CacheSnapshot,\n sort,\n} from \"../core\";\nimport { ListItem } from \"./ListItem\";\nimport { isSameRange } from \"./utils\";\n\n/**\n * Methods of {@link Virtualizer}.\n */\nexport interface VirtualizerHandle {\n /**\n * Get current {@link CacheSnapshot}.\n */\n readonly cache: CacheSnapshot;\n /**\n * Get current scrollTop, or scrollLeft if horizontal: true.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight, or scrollWidth if horizontal: true.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight, or offsetWidth if horizontal: true.\n */\n readonly viewportSize: number;\n /**\n * Find the start index of visible range of items.\n */\n findStartIndex: () => number;\n /**\n * Find the end index of visible range of items.\n */\n findEndIndex: () => number;\n /**\n * Get item offset from start.\n * @param index index of item\n */\n getItemOffset(index: number): number;\n /**\n * Get item size.\n * @param index index of item\n */\n getItemSize(index: number): number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n * @param opts options\n */\n scrollToIndex(index: number, opts?: ScrollToIndexOpts): void;\n /**\n * Scroll to the given offset.\n * @param offset offset from start\n */\n scrollTo(offset: number): void;\n /**\n * Scroll by the given offset.\n * @param offset offset from current position\n */\n scrollBy(offset: number): void;\n}\n\n/**\n * Props of {@link Virtualizer}.\n */\nexport interface VirtualizerProps<T> {\n /**\n * Get reference to {@link VirtualizerHandle}.\n */\n ref?: (handle?: VirtualizerHandle) => void;\n /**\n * The data items rendered by this component.\n */\n data: T[];\n /**\n * The elements renderer function.\n */\n children: (data: T, index: Accessor<number>) => JSX.Element;\n /**\n * Number of items to render above/below the visible bounds of the list. Lower value will give better performance but you can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan?: number;\n /**\n * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as?: ValidComponent;\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item?: ValidComponent;\n /**\n * Reference to the scrollable element. The default will get the direct parent element of virtualizer.\n */\n scrollRef?: HTMLElement;\n /**\n * Item size hint for unmeasured items. It will help to reduce scroll jump when items are measured if used properly.\n *\n * - If not set, initial item sizes will be automatically estimated from measured sizes. This is recommended for most cases.\n * - If set, you can opt out estimation and use the value as initial item size.\n */\n itemSize?: number;\n /**\n * While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.\n */\n shift?: boolean;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * List of indexes that should be always mounted, even when off screen.\n */\n keepMounted?: number[];\n /**\n * You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VirtualizerHandle.cache}.\n *\n * **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**\n */\n cache?: CacheSnapshot;\n /**\n * If you put an element before virtualizer, you have to define its height with this prop.\n */\n startMargin?: number;\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop, or scrollLeft if horizontal: true.\n */\n onScroll?: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollEnd?: () => void;\n}\n\n/**\n * Customizable list virtualizer for advanced usage. See {@link VirtualizerProps} and {@link VirtualizerHandle}.\n */\nexport const Virtualizer = <T,>(props: VirtualizerProps<T>): JSX.Element => {\n let containerRef: HTMLDivElement | undefined;\n const { itemSize, horizontal = false, overscan, cache } = props;\n props = mergeProps<[Partial<VirtualizerProps<T>>, VirtualizerProps<T>]>(\n { as: \"div\" },\n props\n );\n\n const store = createVirtualStore(\n props.data.length,\n itemSize,\n overscan,\n undefined,\n cache,\n !itemSize\n );\n const resizer = createResizer(store, horizontal);\n const scroller = createScroller(store, horizontal);\n\n const [stateVersion, setRerender] = createSignal(store.$getStateVersion());\n\n const unsubscribeStore = store.$subscribe(UPDATE_VIRTUAL_STATE, () => {\n setRerender(store.$getStateVersion());\n });\n\n const unsubscribeOnScroll = store.$subscribe(UPDATE_SCROLL_EVENT, () => {\n props.onScroll?.(store.$getScrollOffset());\n });\n const unsubscribeOnScrollEnd = store.$subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n props.onScrollEnd?.();\n }\n );\n\n const range = createMemo<ItemsRange>((prev) => {\n stateVersion();\n const next = store.$getRange();\n if (prev && isSameRange(prev, next)) {\n return prev;\n }\n return next;\n });\n const isScrolling = createMemo(() => stateVersion() && store.$isScrolling());\n const totalSize = createMemo(() => stateVersion() && store.$getTotalSize());\n\n onMount(() => {\n if (props.ref) {\n props.ref({\n get cache() {\n return store.$getCacheSnapshot();\n },\n get scrollOffset() {\n return store.$getScrollOffset();\n },\n get scrollSize() {\n return getScrollSize(store);\n },\n get viewportSize() {\n return store.$getViewportSize();\n },\n findStartIndex: store.$findStartIndex,\n findEndIndex: store.$findEndIndex,\n getItemOffset: store.$getItemOffset,\n getItemSize: store.$getItemSize,\n scrollToIndex: scroller.$scrollToIndex,\n scrollTo: scroller.$scrollTo,\n scrollBy: scroller.$scrollBy,\n });\n }\n\n const scrollable = props.scrollRef || containerRef!.parentElement!;\n resizer.$observeRoot(scrollable);\n scroller.$observe(scrollable);\n\n onCleanup(() => {\n if (props.ref) {\n props.ref();\n }\n\n unsubscribeStore();\n unsubscribeOnScroll();\n unsubscribeOnScrollEnd();\n resizer.$dispose();\n scroller.$dispose();\n });\n });\n\n createComputed(\n on(\n () => props.startMargin || 0,\n (value) => {\n if (value !== store.$getStartSpacerSize()) {\n store.$update(ACTION_START_OFFSET_CHANGE, value);\n }\n }\n )\n );\n\n createEffect(\n on(stateVersion, () => {\n scroller.$fixScrollJump();\n })\n );\n\n const dataSlice = createMemo(() => {\n const count = props.data.length;\n untrack(() => {\n if (count !== store.$getItemsLength()) {\n store.$update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n });\n const [start, end] = range();\n const items = end >= 0 ? props.data.slice(start, end + 1) : [];\n const indexes = items.map((_, index) => start + index);\n\n if (props.keepMounted) {\n const startItems: T[] = [];\n const startIndexes: number[] = [];\n const endItems: T[] = [];\n const endIndexes: number[] = [];\n sort(props.keepMounted).forEach((index) => {\n if (index < 0 || index >= props.data.length) return;\n if (index < start) {\n startItems.push(props.data[index]!);\n startIndexes.push(index);\n }\n if (index > end) {\n endItems.push(props.data[index]!);\n endIndexes.push(index);\n }\n });\n items.unshift(...startItems);\n indexes.unshift(...startIndexes);\n items.push(...endItems);\n indexes.push(...endIndexes);\n }\n\n return { _items: items, _indexes: indexes };\n });\n\n const renderItem = (data: T, index: Accessor<number>) => {\n const offset = createMemo(() => {\n stateVersion();\n return store.$getItemOffset(index());\n });\n const hide = createMemo(() => {\n stateVersion();\n return store.$isUnmeasuredItem(index());\n });\n const children = createMemo(() => {\n return untrack(() => props.children(data, index));\n });\n\n return (\n <ListItem\n _as={props.item}\n _index={index()}\n _resizer={resizer.$observeItem}\n _offset={offset()}\n _hide={hide()}\n _children={children()}\n _isHorizontal={horizontal}\n />\n );\n };\n\n return (\n <Dynamic\n component={props.as}\n ref={containerRef}\n style={{\n // contain: \"content\",\n \"overflow-anchor\": \"none\", // opt out browser's scroll anchoring because it will conflict to scroll anchoring of virtualizer\n flex: \"none\", // flex style can break layout\n position: \"relative\",\n visibility: \"hidden\", // TODO replace with other optimization methods\n width: horizontal ? totalSize() + \"px\" : \"100%\",\n height: horizontal ? \"100%\" : totalSize() + \"px\",\n \"pointer-events\": isScrolling() ? \"none\" : undefined,\n }}\n >\n <For each={dataSlice()._items}>\n {(data, index) => {\n const itemIndex = createMemo(() => dataSlice()._indexes[index()]!);\n // eslint-disable-next-line solid/reactivity\n return renderItem(data, itemIndex);\n }}\n </For>\n </Dynamic>\n );\n};\n","/**\n * @jsxImportSource solid-js\n */\nimport { JSX, splitProps } from \"solid-js\";\nimport { ViewportComponentAttributes } from \"./types\";\nimport {\n Virtualizer,\n VirtualizerHandle,\n VirtualizerProps,\n} from \"./Virtualizer\";\n\n/**\n * Methods of {@link VList}.\n */\nexport interface VListHandle extends VirtualizerHandle {}\n\n/**\n * Props of {@link VList}.\n */\nexport interface VListProps<T>\n extends Pick<\n VirtualizerProps<T>,\n | \"ref\"\n | \"data\"\n | \"children\"\n | \"overscan\"\n | \"itemSize\"\n | \"shift\"\n | \"horizontal\"\n | \"cache\"\n | \"item\"\n | \"onScroll\"\n | \"onScrollEnd\"\n | \"keepMounted\"\n >,\n ViewportComponentAttributes {}\n\n/**\n * Virtualized list component. See {@link VListProps} and {@link VListHandle}.\n */\nexport const VList = <T,>(props: VListProps<T>): JSX.Element => {\n const [local, others] = splitProps(props, [\n \"ref\",\n \"data\",\n \"children\",\n \"overscan\",\n \"itemSize\",\n \"shift\",\n \"horizontal\",\n \"keepMounted\",\n \"cache\",\n \"item\",\n \"onScroll\",\n \"onScrollEnd\",\n \"style\",\n ]);\n\n return (\n <div\n {...others}\n style={{\n display: local.horizontal ? \"inline-block\" : \"block\",\n [local.horizontal ? \"overflow-x\" : \"overflow-y\"]: \"auto\",\n contain: \"strict\",\n width: \"100%\",\n height: \"100%\",\n ...local.style,\n }}\n >\n <Virtualizer\n ref={local.ref}\n data={local.data}\n overscan={local.overscan}\n itemSize={local.itemSize}\n shift={local.shift}\n horizontal={local.horizontal}\n keepMounted={local.keepMounted}\n cache={local.cache}\n item={local.item}\n onScroll={local.onScroll}\n onScrollEnd={local.onScrollEnd}\n >\n {local.children}\n </Virtualizer>\n </div>\n );\n};\n","/**\n * @jsxImportSource solid-js\n */\nimport {\n onMount,\n onCleanup,\n createEffect,\n createSignal,\n createMemo,\n JSX,\n Accessor,\n on,\n For,\n untrack,\n} from \"solid-js\";\nimport {\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n UPDATE_SCROLL_EVENT,\n createWindowResizer,\n createWindowScroller,\n ItemsRange,\n ScrollToIndexOpts,\n CacheSnapshot,\n} from \"../core\";\nimport { ListItem } from \"./ListItem\";\nimport { isSameRange } from \"./utils\";\n\n/**\n * Methods of {@link WindowVirtualizer}.\n */\nexport interface WindowVirtualizerHandle {\n /**\n * Get current {@link CacheSnapshot}.\n */\n readonly cache: CacheSnapshot;\n /**\n * Find the start index of visible range of items.\n */\n findStartIndex: () => number;\n /**\n * Find the end index of visible range of items.\n */\n findEndIndex: () => number;\n /**\n * Scroll to the item specified by index.\n * @param index index of item\n * @param opts options\n */\n scrollToIndex(index: number, opts?: ScrollToIndexOpts): void;\n}\n\n/**\n * Props of {@link WindowVirtualizer}.\n */\nexport interface WindowVirtualizerProps<T> {\n /**\n * Get reference to {@link WindowVirtualizerHandle}.\n */\n ref?: (handle?: WindowVirtualizerHandle) => void;\n /**\n * The data items rendered by this component.\n */\n data: T[];\n /**\n * The elements renderer function.\n */\n children: (data: T, index: Accessor<number>) => JSX.Element;\n /**\n * Number of items to render above/below the visible bounds of the list. Lower value will give better performance but you can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan?: number;\n /**\n * Item size hint for unmeasured items. It will help to reduce scroll jump when items are measured if used properly.\n *\n * - If not set, initial item sizes will be automatically estimated from measured sizes. This is recommended for most cases.\n * - If set, you can opt out estimation and use the value as initial item size.\n */\n itemSize?: number;\n /**\n * While true is set, scroll position will be maintained from the end not usual start when items are added to/removed from start. It's recommended to set false if you add to/remove from mid/end of the list because it can cause unexpected behavior. This prop is useful for reverse infinite scrolling.\n */\n shift?: boolean;\n /**\n * If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.\n */\n horizontal?: boolean;\n /**\n * You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link WindowVirtualizerHandle.cache}.\n *\n * **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**\n */\n cache?: CacheSnapshot;\n /**\n * Callback invoked whenever scroll offset changes.\n */\n onScroll?: () => void;\n /**\n * Callback invoked when scrolling stops.\n */\n onScrollEnd?: () => void;\n}\n\n/**\n * {@link Virtualizer} controlled by the window scrolling. See {@link WindowVirtualizerProps} and {@link WindowVirtualizerHandle}.\n */\nexport const WindowVirtualizer = <T,>(\n props: WindowVirtualizerProps<T>\n): JSX.Element => {\n let containerRef: HTMLDivElement | undefined;\n\n const {\n ref: _ref,\n data: _data,\n children: _children,\n overscan,\n itemSize,\n shift: _shift,\n horizontal = false,\n cache,\n onScrollEnd: _onScrollEnd,\n } = props;\n\n const store = createVirtualStore(\n props.data.length,\n itemSize,\n overscan,\n undefined,\n cache,\n !itemSize\n );\n const resizer = createWindowResizer(store, horizontal);\n const scroller = createWindowScroller(store, horizontal);\n\n const [stateVersion, setRerender] = createSignal(store.$getStateVersion());\n\n const unsubscribeStore = store.$subscribe(UPDATE_VIRTUAL_STATE, () => {\n setRerender(store.$getStateVersion());\n });\n\n const unsubscribeOnScroll = store.$subscribe(UPDATE_SCROLL_EVENT, () => {\n // https://github.com/inokawa/virtua/discussions/580\n props.onScroll?.();\n });\n const unsubscribeOnScrollEnd = store.$subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n props.onScrollEnd?.();\n }\n );\n\n const range = createMemo<ItemsRange>((prev) => {\n stateVersion();\n const next = store.$getRange();\n if (prev && isSameRange(prev, next)) {\n return prev;\n }\n return next;\n });\n const isScrolling = createMemo(() => stateVersion() && store.$isScrolling());\n const totalSize = createMemo(() => stateVersion() && store.$getTotalSize());\n\n onMount(() => {\n if (props.ref) {\n props.ref({\n get cache() {\n return store.$getCacheSnapshot();\n },\n findStartIndex: store.$findStartIndex,\n findEndIndex: store.$findEndIndex,\n scrollToIndex: scroller.$scrollToIndex,\n });\n }\n\n resizer.$observeRoot(containerRef!);\n scroller.$observe(containerRef!);\n\n onCleanup(() => {\n if (props.ref) {\n props.ref();\n }\n\n unsubscribeStore();\n unsubscribeOnScroll();\n unsubscribeOnScrollEnd();\n resizer.$dispose();\n scroller.$dispose();\n });\n });\n\n createEffect(\n on(stateVersion, () => {\n scroller.$fixScrollJump();\n })\n );\n\n const dataSlice = createMemo<T[]>(() => {\n const count = props.data.length;\n untrack(() => {\n if (count !== store.$getItemsLength()) {\n store.$update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n });\n const [start, end] = range();\n return end >= 0 ? props.data.slice(start, end + 1) : [];\n });\n\n return (\n <div\n ref={containerRef}\n style={{\n // contain: \"content\",\n \"overflow-anchor\": \"none\", // opt out browser's scroll anchoring because it will conflict to scroll anchoring of virtualizer\n flex: \"none\", // flex style can break layout\n position: \"relative\",\n visibility: \"hidden\", // TODO replace with other optimization methods\n width: horizontal ? totalSize() + \"px\" : \"100%\",\n height: horizontal ? \"100%\" : totalSize() + \"px\",\n \"pointer-events\": isScrolling() ? \"none\" : undefined,\n }}\n >\n <For each={dataSlice()}>\n {(data, index) => {\n const itemIndex = createMemo(() => range()[0] + index());\n const offset = createMemo(() => {\n stateVersion();\n return store.$getItemOffset(itemIndex());\n });\n const hide = createMemo(() => {\n stateVersion();\n return store.$isUnmeasuredItem(itemIndex());\n });\n const children = createMemo(() => {\n return untrack(() => props.children(data, itemIndex));\n });\n\n return (\n <ListItem\n _index={itemIndex()}\n _resizer={resizer.$observeItem}\n _offset={offset()}\n _hide={hide()}\n _children={children()}\n _isHorizontal={horizontal}\n />\n );\n }}\n </For>\n </div>\n );\n};\n"],"names":["NULL","min","max","abs","floor","Math","clamp","value","minValue","maxValue","sort","arr","a","b","microtask","queueMicrotask","fn","Promise","resolve","then","once","called","cache","UNCACHED","fill","array","length","prepend","key","i","getItemSize","index","size","_sizes","_defaultItemSize","setItemSize","isInitialMeasurement","_computedOffsetIndex","computeOffset","_length","_offsets","top","findIndex","offset","low","high","mid","itemOffset","updateCacheLength","isShift","diff","splice","reduce","acc","removed","isBrowser","window","getDocumentElement","document","documentElement","getCurrentDocument","node","ownerDocument","getCurrentWindow","doc","defaultView","isRTLDocument","getComputedStyle","direction","isIOSWebKit","test","navigator","userAgent","isSmoothScrollSupported","style","isInitialMeasurementDone","store","$getViewportSize","createVirtualStore","elementsCount","itemSize","overscan","ssrCount","cacheSnapshot","shouldAutoEstimateItemSize","isSSR","stateVersion","viewportSize","startSpacerSize","scrollOffset","jump","pendingJump","_flushedJump","_scrollDirection","_scrollMode","_frozenRange","_prevRange","_totalMeasuredSize","snapshot","slice","initCache","subscribers","Set","getRelativeScrollOffset","getVisibleOffset","getRange","prevStartIndex","end","start","undefined","computeRange","getTotalSize","computeTotalSize","getItemOffset","computeStartOffset","_getItemSize","applyJump","j","$getStateVersion","$getCacheSnapshot","takeCacheSnapshot","$getRange","startIndex","endIndex","$findStartIndex","$findEndIndex","$isUnmeasuredItem","_hasUnmeasuredItemsInFrozenRange","includes","$getItemOffset","$getItemSize","$getItemsLength","$getScrollOffset","$isScrolling","$getStartSpacerSize","$getTotalSize","_flushJump","$subscribe","target","cb","sub","add","delete","$update","type","payload","shouldFlushPendingJump","shouldSync","mutated","flushedJump","delta","distance","relativeOffset","updated","filter","prevSize","measuredCountBeforeStart","measuredSizes","forEach","s","push","sorted","len","median","prevDefaultItemSize","estimateDefaultItemSize","UPDATE_VIRTUAL_STATE","timeout","setTimeout","normalizeOffset","isHorizontal","createScrollObserver","viewport","getScrollOffset","updateScrollOffset","getStartOffset","now","Date","lastScrollTime","wheeling","touching","justTouchEnded","stillMomentumScrolling","onScrollEnd","id","cancel","clearTimeout","debouncedFn","_cancel","debounce","onScroll","onWheel","e","ctrlKey","timeDelta","deltaX","deltaY","onTouchStart","onTouchEnd","addEventListener","passive","_dispose","removeEventListener","_fixScrollJump","shift","createResizeObserver","ro","_observe","observe","_unobserve","unobserve","disconnect","ListItem","props","elementRef","mergeProps","_as","createEffect","onCleanup","_resizer","_index","createMemo","_isHorizontal","position","_offset","visibility","_hide","display","_$createComponent","Dynamic","component","ref","r$","children","_children","isSameRange","prev","next","Virtualizer","containerRef","horizontal","as","data","resizer","viewportElement","sizeKey","mountedIndexes","WeakMap","resizeObserver","entries","resizes","contentRect","offsetParent","get","$observeRoot","$observeItem","el","set","$dispose","createResizer","scroller","scrollObserver","cancelScroll","scrollOffsetKey","overflowKey","scheduleImperativeScroll","async","getTargetOffset","smooth","waitForMeasurement","queue","reject","promise","unsubscribe","scrollTo","behavior","$observe","isMomentumScrolling","$scrollTo","$scrollBy","$scrollToIndex","align","$fixScrollJump","createScroller","setRerender","createSignal","unsubscribeStore","unsubscribeOnScroll","_a","call","unsubscribeOnScrollEnd","range","isScrolling","totalSize","onMount","scrollSize","getScrollSize","findStartIndex","findEndIndex","scrollToIndex","scrollBy","scrollable","scrollRef","parentElement","createComputed","on","startMargin","dataSlice","count","untrack","items","indexes","map","_","keepMounted","startItems","startIndexes","endItems","endIndexes","unshift","_items","_indexes","flex","width","height","For","each","renderItem","hide","item","local","others","splitProps","_el$","_tmpl$","_$spread","_$mergeProps","contain","_$insert","createComponent","_ref$","_ref","_data","_shift","_onScrollEnd","windowSizeKey","cleanupOnWindowResize","container","onWindowResize","createWindowResizer","containerElement","calcOffsetToViewport","offsetKey","offsetSum","innerWidth","offsetWidth","parent","scroll","documentBody","body","html","getScrollbarSize","clientWidth","clientHeight","createWindowScroller","_$use","use","setProperty","itemIndex","_$effect","_p$","_v$","_v$2","_v$3","removeProperty","t"],"mappings":"oDACO,MAAMA,EAAO,MAGPC,IAAEA,EAAGC,IAAEA,EAAGC,IAAEA,EAAGC,MAAEA,GAAUC,KAK3BC,EAAQ,CACnBC,EACAC,EACAC,IACWR,EAAIQ,EAAUP,EAAIM,EAAUD,IAK5BG,EAA0BC,GAC9B,IAAIA,GAAKD,MAAK,CAACE,EAAGC,IAAMD,EAAIC,IAMxBC,EACe,mBAAnBC,eACHA,eACCC,IACCC,QAAQC,UAAUC,KAAKH,EAAG,EAMrBI,EAAWJ,IACtB,IAAIK,EACAC,EAEJ,MAAO,KACAD,IACHA,G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