virtua 0.33.7 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -202,23 +202,20 @@ export default async () => {
202
202
  import { VList } from "virtua/vue";
203
203
 
204
204
  const sizes = [20, 40, 180, 77];
205
- const data = Array.from({ length: 1000 }).map((_, i) => ({
206
- id: i,
207
- size: sizes[i % 4] + "px",
208
- }));
205
+ const data = Array.from({ length: 1000 }).map((_, i) => sizes[i % 4]);
209
206
  </script>
210
207
 
211
208
  <template>
212
- <VList :data="data" :style="{ height: '800px' }" #default="item">
209
+ <VList :data="data" :style="{ height: '800px' }" #default="{ item, index }">
213
210
  <div
214
- :key="item.id"
211
+ :key="index"
215
212
  :style="{
216
- height: item.size,
213
+ height: item + 'px',
217
214
  background: 'white',
218
215
  borderBottom: 'solid 1px #ccc',
219
216
  }"
220
217
  >
221
- {{ item.id }}
218
+ {{ index }}
222
219
  </div>
223
220
  </VList>
224
221
  </template>
@@ -266,7 +263,7 @@ export const App = () => {
266
263
  const data = Array.from({ length: 1000 }).map((_, i) => sizes[i % 4] );
267
264
  </script>
268
265
 
269
- <VList {data} let:item let:index style={`height: 100vh;`} getKey={(d) => d.id}>
266
+ <VList {data} let:item let:index style={`height: 100vh;`} getKey={(_,i) => i}>
270
267
  <div
271
268
  style={`
272
269
  height: ${item}px;
@@ -1,5 +1,5 @@
1
1
  /** @jsxImportSource vue */
2
- import { ComponentOptionsMixin, SlotsType } from "vue";
2
+ import { ComponentOptionsMixin, SlotsType, VNode } from "vue";
3
3
  import { VirtualizerHandle } from "./Virtualizer";
4
4
  interface VListHandle extends VirtualizerHandle {
5
5
  }
@@ -104,6 +104,9 @@ export declare const VList: import("vue").DefineComponent<{
104
104
  overscan: number;
105
105
  horizontal: boolean;
106
106
  }, SlotsType<{
107
- default: any;
107
+ default: (arg: {
108
+ item: any;
109
+ index: number;
110
+ }) => VNode[];
108
111
  }>>;
109
112
  export {};
@@ -1,5 +1,5 @@
1
1
  /** @jsxImportSource vue */
2
- import { ComponentOptionsMixin, SlotsType, PropType, NativeElements } from "vue";
2
+ import { VNode, ComponentOptionsMixin, SlotsType, PropType, NativeElements } from "vue";
3
3
  import { ScrollToIndexOpts } from "../core/types";
4
4
  export interface VirtualizerHandle {
5
5
  /**
@@ -194,5 +194,8 @@ export declare const Virtualizer: import("vue").DefineComponent<{
194
194
  as: keyof import("vue").IntrinsicElementAttributes;
195
195
  item: keyof import("vue").IntrinsicElementAttributes;
196
196
  }, SlotsType<{
197
- default: any;
197
+ default: (arg: {
198
+ item: any;
199
+ index: number;
200
+ }) => VNode[];
198
201
  }>>;
@@ -1,5 +1,5 @@
1
1
  /** @jsxImportSource vue */
2
- import { ComponentOptionsMixin, SlotsType, PropType, NativeElements } from "vue";
2
+ import { VNode, ComponentOptionsMixin, SlotsType, PropType, NativeElements } from "vue";
3
3
  export declare const WindowVirtualizer: import("vue").DefineComponent<{
4
4
  /**
5
5
  * The data items rendered by this component.
@@ -121,5 +121,8 @@ export declare const WindowVirtualizer: import("vue").DefineComponent<{
121
121
  as: keyof import("vue").IntrinsicElementAttributes;
122
122
  item: keyof import("vue").IntrinsicElementAttributes;
123
123
  }, SlotsType<{
124
- default: any;
124
+ default: (arg: {
125
+ item: any;
126
+ index: number;
127
+ }) => VNode[];
125
128
  }>>;
package/lib/vue/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("vue");const t=null,o=Math.min,r=Math.max,n=Math.abs,s=setTimeout,i=(e,t,n)=>o(n,r(t,e)),l="function"==typeof queueMicrotask?queueMicrotask:e=>{Promise.resolve().then(e)},c=e=>{let t,o;return(...r)=>(t||(t=!0,o=e(...r)),o)},a=-1,u=(e,t,o)=>{const r=o?"unshift":"push";for(let o=0;o<t;o++)e[r](a);return e},f=(e,t)=>{const o=e.t[t];return o===a?e.o:o},d=(e,t,r)=>{const n=e.t[t]===a;return e.t[t]=r,e.i=o(t,e.i),n},_=(e,t)=>{if(!e.l)return 0;if(e.i>=t)return e.u[t];e.i<0&&(e.u[0]=0,e.i=0);let o=e.i,r=e.u[o];for(;o<t;)r+=f(e,o),e.u[++o]=r;return e.i=t,r},p=(e,t,o)=>{for(;o>=0&&o<e.l;){const r=_(e,o);if(r<=t){if(r+f(e,o)>t)break;o++}else o--}return i(o,0,e.l-1)},h=(e,t,r)=>{const n=t-e.l;return e.i=r?-1:o(t-1,e.i),e.l=t,n>0?(u(e.u,n),u(e.t,n,r),e.o*n):(e.u.splice(n),(r?e.t.splice(0,-n):e.t.splice(n)).reduce(((t,o)=>t-(o===a?e.o:o)),0))},g="undefined"!=typeof window,m=()=>document.documentElement,v=e=>e.ownerDocument,b=e=>e.defaultView,y=/*#__PURE__*/c((()=>!!g&&"rtl"===getComputedStyle(m()).direction)),S=/*#__PURE__*/c((()=>/iP(hone|od|ad)/.test(navigator.userAgent))),z=/*#__PURE__*/c((()=>"scrollBehavior"in m().style)),w=(e,t,n,s,i)=>(1!==s&&(e-=r(0,n)),2!==s&&(t+=r(0,n)),[r(e,0),o(t,i-1)]),x=(e,s=40,i=0,l,c=!1)=>{let g=!!i,m=[],v=0,b=0,y=0,z=0,w=0,x=0,k=0,O=0,I=0,C=g?[0,r(i-1,0)]:t,j=[0,0],B=0;const R=((e,t)=>({o:t,t:u([],e),l:e,i:-1,u:u([],e)}))(e,s),q=new Set,N=()=>y-b,T=e=>((e,t,r,n)=>{const s=p(e,t,o(r,e.l-1));return[s,p(e,t+n,s)]})(R,e,j[0],v),E=()=>(e=>e.l?_(e,e.l-1)+f(e,e.l-1):0)(R),M=e=>_(R,e)-x,H=e=>f(R,e),A=e=>{e&&(S()&&0!==O?x+=e:(w+=e,z++))};return{p:()=>m,h:()=>(e=>[[...e.t],e.o])(R),m:()=>k?j:(j=T(r(0,N()+x+w)),C?[o(j[0],C[0]),r(j[1],C[1])]:j),v:e=>R.t[e]===a,S:()=>!!v,k:()=>!!C&&R.t.slice(r(0,C[0]-1),o(R.l-1,C[1]+1)+1).includes(a),O:M,I:H,C:()=>R.l,j:()=>y,B:()=>O,R:()=>v,q:()=>b,N:E,T:()=>z,M:()=>(k=w,w=0,[k,2===I||N()+v>=E()]),H(e,t){const o=[e,t];return q.add(o),()=>{q.delete(o)}},A(e,o){let s,i,l=0;switch(e){case 1:{const e=k;k=0;const r=o-y,s=n(r);e&&s<n(e)+1||0!==I||(O=r<0?2:1),g&&(C=t,g=!1),y=o,l=4;const c=N();c>=-v&&c<=E()&&(l+=1,i=s>v);break}case 2:l=8,0!==O&&(s=!0,l+=1),O=0,I=0,C=t;break;case 3:{const e=o.filter((([e,t])=>R.t[e]!==t));if(!e.length)break;A(e.reduce(((e,[t,o])=>((2===I||(C?t<C[0]:M(t)+(0===O&&0===I?H(t):0)<N()))&&(e+=o-H(t)),e)),0));for(const[t,o]of e){const e=H(t),r=d(R,t,o);c&&(B+=r?o:o-e)}c&&v&&B>v&&(A(((e,t)=>{let o=0;const n=e.t.filter(((e,r)=>{const n=e!==a;return n&&r<t&&o++,n})),s=e.o;return e.i=-1,((e.o=(e=>{const t=(e=>[...e].sort(((e,t)=>e-t)))(e),o=e.length/2|0;return t.length%2==0?(t[o-1]+t[o])/2:t[o]})(n))-s)*r(t-o,0)})(R,j[0])),c=!1),l=3,i=!0;break}case 4:v!==o&&(v=o,l=3);break;case 5:o[1]?(A(h(R,o[0],!0)),I=2,l=1):h(R,o[0]);break;case 6:b=o;break;case 7:I=1;break;case 8:C=T(o),l=1}l&&(m=[],s&&x&&(w+=x,x=0,z++),q.forEach((([e,t])=>{l&e&&t(i)})))}}},k=e=>{let t;return{J(o){(t||(t=new(b(v(o)).ResizeObserver)(e))).observe(o)},D(e){t.unobserve(e)},L(){t&&t.disconnect()}}},O=(e,t)=>t&&y()?-e:e,I=(e,o,r,n,i,l)=>{const c=Date.now;let a=0,u=!1,f=!1,d=!1,_=!1;const p=(()=>{let o;const r=()=>{o!=t&&clearTimeout(o)},n=()=>{r(),o=s((()=>{o=t,(()=>{if(u||f)return u=!1,void p();d=!1,e.A(2)})()}),150)};return n.P=r,n})(),h=()=>{a=c(),d&&(_=!0),l&&e.A(6,l()),e.A(1,n()),p()},g=t=>{if(u||0===e.B()||t.ctrlKey)return;const o=c()-a;150>o&&50<o&&(r?t.deltaX:t.deltaY)&&(u=!0)},m=()=>{f=!0,d=_=!1},v=()=>{f=!1,S()&&(d=!0)};return o.addEventListener("scroll",h),o.addEventListener("wheel",g,{passive:!0}),o.addEventListener("touchstart",m,{passive:!0}),o.addEventListener("touchend",v,{passive:!0}),{L:()=>{o.removeEventListener("scroll",h),o.removeEventListener("wheel",g),o.removeEventListener("touchstart",m),o.removeEventListener("touchend",v),p.P()},W:()=>{const[t,o]=e.M();t&&(i(O(t,r),o,_),_=!1,o&&e.R()>e.N()&&e.A(1,n()))}}},C=/*#__PURE__*/e.defineComponent({props:{X:{type:Object,required:!0},Y:{type:Function,required:!0},F:{type:Number,required:!0},U:{type:Number,required:!0},V:{type:Boolean},G:{type:Boolean},K:{type:Boolean},Z:{type:String,required:!0}},setup(t){const o=e.ref();return e.watch((()=>o.value&&t.F),((e,r,n)=>{n(t.Y(o.value,t.F))}),{flush:"post"}),()=>{const{X:r,U:n,V:s,G:i,K:l,Z:c}=t,a={margin:0,padding:0,position:s&&l?void 0:"absolute",[i?"height":"width"]:"100%",[i?"top":"left"]:"0px",[i?y()?"right":"left":"top"]:n+"px",visibility:!s||l?"visible":"hidden"};return i&&(a.display="flex"),e.createVNode(c,{ref:o,style:a},"function"==typeof(u=r)||"[object Object]"===Object.prototype.toString.call(u)&&!e.isVNode(u)?r:{default:()=>[r],_:2},8,["style"]);var u}}}),j=(e,o)=>{const r=e.key;return r!=t?r:"_"+o},B={data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,startMargin:{type:Number,default:0},ssrCount:Number,scrollRef:Object,as:{type:String,default:"div"},item:{type:String,default:"div"}},R=/*#__PURE__*/e.defineComponent({props:B,emits:["scroll","scrollEnd","rangeChange"],setup(o,{emit:n,expose:c,slots:a}){var u;let f=!!o.ssrCount;const d=o.horizontal,_=e.ref(),p=x(o.data.length,null!==(u=o.itemSize)&&void 0!==u?u:40,o.ssrCount,0,!o.itemSize),h=((e,o)=>{let r;const n=o?"width":"height",s=new WeakMap,i=k((o=>{const i=[];for(const{target:l,contentRect:c}of o)if(l.offsetParent)if(l===r)e.A(4,c[n]);else{const e=s.get(l);e!=t&&i.push([e,c[n]])}i.length&&e.A(3,i)}));return{$(e){i.J(r=e)},ee:(e,t)=>(s.set(e,t),i.J(e),()=>{s.delete(e),i.D(e)}),L:i.L}})(p,d),g=((e,t)=>{let o,r,n;const c=t?"scrollLeft":"scrollTop",a=t?"overflowX":"overflowY",u=async(r,i)=>{if(!o)return void l((()=>u(r,i)));n&&n();const a=()=>{let t;return[new Promise(((o,r)=>{t=o,n=r,e.S()&&s(r,150)})),e.H(2,(()=>{t&&t()}))]};if(i&&z()){for(;e.A(8,r()),e.k();){const[e,t]=a();try{await e}catch(e){return}finally{t()}}o.scrollTo({[t?"left":"top"]:O(r(),t),behavior:"smooth"})}else for(;;){const[n,s]=a();try{o[c]=O(r(),t),e.A(7),await n}catch(e){return}finally{s()}}};return{J(i){o=i,r=I(e,i,t,(()=>O(i[c],t)),((t,o,r)=>{if(r){const e=i.style,t=e[a];e[a]="hidden",s((()=>{e[a]=t}))}o?(i[c]=e.j()+t,n&&n()):i[c]+=t}))},L(){r&&r.L()},te(e){u((()=>e))},oe(t){t+=e.j(),u((()=>t))},re(t,{align:o,smooth:r,offset:n=0}={}){if(t=i(t,0,e.C()-1),"nearest"===o){const r=e.O(t),n=e.j();if(r<n)o="start";else{if(!(r+e.I(t)>n+e.R()))return;o="end"}}u((()=>n+e.q()+e.O(t)+("end"===o?e.I(t)-e.R():"center"===o?(e.I(t)-e.R())/2:0)),r)},W:()=>{r&&r.W()}}})(p,d),m=e.ref(p.p()),v=p.H(1,(()=>{m.value=p.p()})),b=p.H(4,(()=>{n("scroll",p.j())})),y=p.H(8,(()=>{n("scrollEnd")}));return e.onMounted((()=>{f=!1,l((()=>{const e=e=>{h.$(e),g.J(e)};o.scrollRef?e(o.scrollRef):e(_.value.parentElement)}))})),e.onUnmounted((()=>{v(),b(),y(),h.L(),g.L()})),e.watch((()=>o.data.length),(e=>{p.A(5,[e,o.shift])})),e.watch((()=>o.startMargin),(e=>{p.A(6,e)}),{immediate:!0}),e.watch([m,p.T],(([,e],[,t])=>{e!==t&&g.W()}),{flush:"post"}),e.watch([m,p.m],(([,[e,t]],[,[o,r]])=>{o===e&&r===t||n("rangeChange",e,t)}),{flush:"post"}),c({get scrollOffset(){return p.j()},get scrollSize(){return(e=>r(e.N(),e.R()))(p)},get viewportSize(){return p.R()},getItemOffset:p.O,scrollToIndex:g.re,scrollTo:g.te,scrollBy:g.oe}),()=>{m.value;const t=o.as,r=o.item,n=o.data.length,[s,i]=p.m(),l=p.B(),c=p.N(),u=[];for(let[t,c]=w(s,i,o.overscan,l,n);t<=c;t++){const n=a.default(o.data[t])[0];u.push(e.createVNode(C,{key:j(n,t),Y:h.ee,F:t,U:p.O(t),V:p.v(t),X:n,G:d,K:f,Z:r},null,8,["_resizer","_index","_offset","_hide","_children","_isHorizontal","_isSSR","_as"]))}return e.createVNode(t,{ref:_,style:{overflowAnchor:"none",flex:"none",position:"relative",visibility:"hidden",width:d?c+"px":"100%",height:d?"100%":c+"px",pointerEvents:0!==l?"none":"auto"}},"function"==typeof(g=u)||"[object Object]"===Object.prototype.toString.call(g)&&!e.isVNode(g)?u:{default:()=>[u],_:2},8,["style"]);var g}}}),q={data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,ssrCount:Number},N=/*#__PURE__*/e.defineComponent({props:q,emits:["scroll","scrollEnd","rangeChange"],setup(t,{emit:o,expose:r,slots:n}){const s=t.horizontal,i=e=>{o("scroll",e)},l=()=>{o("scrollEnd")},c=(e,t)=>{o("rangeChange",e,t)},a=e.ref();return r({get scrollOffset(){return a.value.scrollOffset},get scrollSize(){return a.value.scrollSize},get viewportSize(){return a.value.viewportSize},getItemOffset:(...e)=>a.value.getItemOffset(...e),scrollToIndex:(...e)=>a.value.scrollToIndex(...e),scrollTo:(...e)=>a.value.scrollTo(...e),scrollBy:(...e)=>a.value.scrollBy(...e)}),()=>{return e.createVNode("div",{style:{display:s?"inline-block":"block",[s?"overflowX":"overflowY"]:"auto",contain:"strict",width:"100%",height:"100%"}},[e.createVNode(R,{ref:a,data:t.data,overscan:t.overscan,itemSize:t.itemSize,shift:t.shift,ssrCount:t.ssrCount,horizontal:s,onScroll:i,onScrollEnd:l,onRangeChange:c},(o=n,"function"==typeof o||"[object Object]"===Object.prototype.toString.call(o)&&!e.isVNode(o)?n:{default:()=>[n],_:2}),8,["data","overscan","itemSize","shift","ssrCount","horizontal","onScroll","onScrollEnd","onRangeChange"])],4);var o}}}),T={data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,as:{type:String,default:"div"},item:{type:String,default:"div"}},E=/*#__PURE__*/e.defineComponent({props:T,emits:["scrollEnd","rangeChange"],setup(o,{emit:r,slots:n}){var s;const i=o.horizontal,l=e.ref(),c=x(o.data.length,null!==(s=o.itemSize)&&void 0!==s?s:40,void 0,0,!o.itemSize),a=((e,o)=>{const r=o?"width":"height",n=o?"innerWidth":"innerHeight",s=new WeakMap,i=k((o=>{const n=[];for(const{target:e,contentRect:i}of o){if(!e.offsetParent)continue;const o=s.get(e);o!=t&&n.push([o,i[r]])}n.length&&e.A(3,n)}));let l;return{$(t){const o=b(v(t)),r=()=>{e.A(4,o[n])};o.addEventListener("resize",r),r(),l=()=>{o.removeEventListener("resize",r)}},ee:(e,t)=>(s.set(e,t),i.J(e),()=>{s.delete(e),i.D(e)}),L(){l&&l(),i.L()}}})(c,i),u=((e,t)=>{let o;return{J(r){const n=t?"scrollX":"scrollY",s=v(r),i=b(s),l=s.body,c=(e,t,o,r=0)=>{const n=o?"offsetLeft":"offsetTop",s=r+(o&&y()?i.innerWidth-e[n]-e.offsetWidth:e[n]),l=e.offsetParent;return e!==t&&l?c(l,t,o,s):s};o=I(e,i,t,(()=>O(i[n],t)),((o,r)=>{r?i.scroll({[t?"left":"top"]:e.j()+o}):i.scrollBy(t?o:0,t?0:o)}),(()=>c(r,l,t)))},L(){o&&o.L()},W:()=>{o&&o.W()}}})(c,i),f=e.ref(c.p()),d=c.H(1,(()=>{f.value=c.p()})),_=c.H(8,(()=>{r("scrollEnd")}));return e.onMounted((()=>{const e=l.value;e&&(a.$(e),u.J(e))})),e.onUnmounted((()=>{d(),_(),a.L(),u.L()})),e.watch((()=>o.data.length),(e=>{c.A(5,[e,o.shift])})),e.watch([f,c.T],(([,e],[,t])=>{e!==t&&u.W()}),{flush:"post"}),e.watch([f,c.m],(([,[e,t]],[,[o,n]])=>{o===e&&n===t||r("rangeChange",e,t)}),{flush:"post"}),()=>{f.value;const t=o.as,r=o.item,s=o.data.length,[u,d]=c.m(),_=c.B(),p=c.N(),h=[];for(let[t,l]=w(u,d,o.overscan,_,s);t<=l;t++){const s=n.default(o.data[t])[0];h.push(e.createVNode(C,{key:j(s,t),Y:a.ee,F:t,U:c.O(t),V:c.v(t),X:s,G:i,Z:r},null,8,["_resizer","_index","_offset","_hide","_children","_isHorizontal","_as"]))}return e.createVNode(t,{ref:l,style:{overflowAnchor:"none",flex:"none",position:"relative",visibility:"hidden",width:i?p+"px":"100%",height:i?"100%":p+"px",pointerEvents:0!==_?"none":"auto"}},"function"==typeof(g=h)||"[object Object]"===Object.prototype.toString.call(g)&&!e.isVNode(g)?h:{default:()=>[h],_:2},8,["style"]);var g}}});exports.VList=N,exports.Virtualizer=R,exports.WindowVirtualizer=E;
1
+ var e=require("vue");const t=null,o=Math.min,r=Math.max,n=Math.abs,s=setTimeout,i=(e,t,n)=>o(n,r(t,e)),l="function"==typeof queueMicrotask?queueMicrotask:e=>{Promise.resolve().then(e)},c=e=>{let t,o;return(...r)=>(t||(t=!0,o=e(...r)),o)},a=-1,u=(e,t,o)=>{const r=o?"unshift":"push";for(let o=0;o<t;o++)e[r](a);return e},f=(e,t)=>{const o=e.t[t];return o===a?e.o:o},d=(e,t,r)=>{const n=e.t[t]===a;return e.t[t]=r,e.i=o(t,e.i),n},_=(e,t)=>{if(!e.l)return 0;if(e.i>=t)return e.u[t];e.i<0&&(e.u[0]=0,e.i=0);let o=e.i,r=e.u[o];for(;o<t;)r+=f(e,o),e.u[++o]=r;return e.i=t,r},p=(e,t,o)=>{for(;o>=0&&o<e.l;){const r=_(e,o);if(r<=t){if(r+f(e,o)>t)break;o++}else o--}return i(o,0,e.l-1)},h=(e,t,r)=>{const n=t-e.l;return e.i=r?-1:o(t-1,e.i),e.l=t,n>0?(u(e.u,n),u(e.t,n,r),e.o*n):(e.u.splice(n),(r?e.t.splice(0,-n):e.t.splice(n)).reduce(((t,o)=>t-(o===a?e.o:o)),0))},g="undefined"!=typeof window,m=()=>document.documentElement,v=e=>e.ownerDocument,b=e=>e.defaultView,y=/*#__PURE__*/c((()=>!!g&&"rtl"===getComputedStyle(m()).direction)),S=/*#__PURE__*/c((()=>/iP(hone|od|ad)/.test(navigator.userAgent))),z=/*#__PURE__*/c((()=>"scrollBehavior"in m().style)),x=(e,t,n,s,i)=>(1!==s&&(e-=r(0,n)),2!==s&&(t+=r(0,n)),[r(e,0),o(t,i-1)]),w=(e,s=40,i=0,l,c=!1)=>{let g=!!i,m=[],v=0,b=0,y=0,z=0,x=0,w=0,k=0,O=0,I=0,C=g?[0,r(i-1,0)]:t,j=[0,0],B=0;const R=((e,t)=>({o:t,t:u([],e),l:e,i:-1,u:u([],e)}))(e,s),q=new Set,N=()=>y-b,T=e=>((e,t,r,n)=>{const s=p(e,t,o(r,e.l-1));return[s,p(e,t+n,s)]})(R,e,j[0],v),E=()=>(e=>e.l?_(e,e.l-1)+f(e,e.l-1):0)(R),M=e=>_(R,e)-w,H=e=>f(R,e),A=e=>{e&&(S()&&0!==O?w+=e:(x+=e,z++))};return{p:()=>m,h:()=>(e=>[[...e.t],e.o])(R),m:()=>k?j:(j=T(r(0,N()+w+x)),C?[o(j[0],C[0]),r(j[1],C[1])]:j),v:e=>R.t[e]===a,S:()=>!!v,k:()=>!!C&&R.t.slice(r(0,C[0]-1),o(R.l-1,C[1]+1)+1).includes(a),O:M,I:H,C:()=>R.l,j:()=>y,B:()=>O,R:()=>v,q:()=>b,N:E,T:()=>z,M:()=>(k=x,x=0,[k,2===I||N()+v>=E()]),H(e,t){const o=[e,t];return q.add(o),()=>{q.delete(o)}},A(e,o){let s,i,l=0;switch(e){case 1:{const e=k;k=0;const r=o-y,s=n(r);e&&s<n(e)+1||0!==I||(O=r<0?2:1),g&&(C=t,g=!1),y=o,l=4;const c=N();c>=-v&&c<=E()&&(l+=1,i=s>v);break}case 2:l=8,0!==O&&(s=!0,l+=1),O=0,I=0,C=t;break;case 3:{const e=o.filter((([e,t])=>R.t[e]!==t));if(!e.length)break;A(e.reduce(((e,[t,o])=>((2===I||(C?t<C[0]:M(t)+(0===O&&0===I?H(t):0)<N()))&&(e+=o-H(t)),e)),0));for(const[t,o]of e){const e=H(t),r=d(R,t,o);c&&(B+=r?o:o-e)}c&&v&&B>v&&(A(((e,t)=>{let o=0;const n=e.t.filter(((e,r)=>{const n=e!==a;return n&&r<t&&o++,n})),s=e.o;return e.i=-1,((e.o=(e=>{const t=(e=>[...e].sort(((e,t)=>e-t)))(e),o=e.length/2|0;return t.length%2==0?(t[o-1]+t[o])/2:t[o]})(n))-s)*r(t-o,0)})(R,j[0])),c=!1),l=3,i=!0;break}case 4:v!==o&&(v=o,l=3);break;case 5:o[1]?(A(h(R,o[0],!0)),I=2,l=1):h(R,o[0]);break;case 6:b=o;break;case 7:I=1;break;case 8:C=T(o),l=1}l&&(m=[],s&&w&&(x+=w,w=0,z++),q.forEach((([e,t])=>{l&e&&t(i)})))}}},k=e=>{let t;return{J(o){(t||(t=new(b(v(o)).ResizeObserver)(e))).observe(o)},D(e){t.unobserve(e)},L(){t&&t.disconnect()}}},O=(e,t)=>t&&y()?-e:e,I=(e,o,r,n,i,l)=>{const c=Date.now;let a=0,u=!1,f=!1,d=!1,_=!1;const p=(()=>{let o;const r=()=>{o!=t&&clearTimeout(o)},n=()=>{r(),o=s((()=>{o=t,(()=>{if(u||f)return u=!1,void p();d=!1,e.A(2)})()}),150)};return n.P=r,n})(),h=()=>{a=c(),d&&(_=!0),l&&e.A(6,l()),e.A(1,n()),p()},g=t=>{if(u||0===e.B()||t.ctrlKey)return;const o=c()-a;150>o&&50<o&&(r?t.deltaX:t.deltaY)&&(u=!0)},m=()=>{f=!0,d=_=!1},v=()=>{f=!1,S()&&(d=!0)};return o.addEventListener("scroll",h),o.addEventListener("wheel",g,{passive:!0}),o.addEventListener("touchstart",m,{passive:!0}),o.addEventListener("touchend",v,{passive:!0}),{L:()=>{o.removeEventListener("scroll",h),o.removeEventListener("wheel",g),o.removeEventListener("touchstart",m),o.removeEventListener("touchend",v),p.P()},W:()=>{const[t,o]=e.M();t&&(i(O(t,r),o,_),_=!1,o&&e.R()>e.N()&&e.A(1,n()))}}},C=/*#__PURE__*/e.defineComponent({props:{X:{type:Object,required:!0},Y:{type:Function,required:!0},F:{type:Number,required:!0},U:{type:Number,required:!0},V:{type:Boolean},G:{type:Boolean},K:{type:Boolean},Z:{type:String,required:!0}},setup(t){const o=e.ref();return e.watch((()=>o.value&&t.F),((e,r,n)=>{n(t.Y(o.value,t.F))}),{flush:"post"}),()=>{const{X:r,U:n,V:s,G:i,K:l,Z:c}=t,a={margin:0,padding:0,position:s&&l?void 0:"absolute",[i?"height":"width"]:"100%",[i?"top":"left"]:"0px",[i?y()?"right":"left":"top"]:n+"px",visibility:!s||l?"visible":"hidden"};return i&&(a.display="flex"),e.createVNode(c,{ref:o,style:a},"function"==typeof(u=r)||"[object Object]"===Object.prototype.toString.call(u)&&!e.isVNode(u)?r:{default:()=>[r],_:2},8,["style"]);var u}}}),j=(e,o)=>{const r=e.key;return r!=t?r:"_"+o},B={data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,startMargin:{type:Number,default:0},ssrCount:Number,scrollRef:Object,as:{type:String,default:"div"},item:{type:String,default:"div"}},R=/*#__PURE__*/e.defineComponent({props:B,emits:["scroll","scrollEnd","rangeChange"],setup(o,{emit:n,expose:c,slots:a}){var u;let f=!!o.ssrCount;const d=o.horizontal,_=e.ref(),p=w(o.data.length,null!==(u=o.itemSize)&&void 0!==u?u:40,o.ssrCount,0,!o.itemSize),h=((e,o)=>{let r;const n=o?"width":"height",s=new WeakMap,i=k((o=>{const i=[];for(const{target:l,contentRect:c}of o)if(l.offsetParent)if(l===r)e.A(4,c[n]);else{const e=s.get(l);e!=t&&i.push([e,c[n]])}i.length&&e.A(3,i)}));return{$(e){i.J(r=e)},ee:(e,t)=>(s.set(e,t),i.J(e),()=>{s.delete(e),i.D(e)}),L:i.L}})(p,d),g=((e,t)=>{let o,r,n;const c=t?"scrollLeft":"scrollTop",a=t?"overflowX":"overflowY",u=async(r,i)=>{if(!o)return void l((()=>u(r,i)));n&&n();const a=()=>{let t;return[new Promise(((o,r)=>{t=o,n=r,e.S()&&s(r,150)})),e.H(2,(()=>{t&&t()}))]};if(i&&z()){for(;e.A(8,r()),e.k();){const[e,t]=a();try{await e}catch(e){return}finally{t()}}o.scrollTo({[t?"left":"top"]:O(r(),t),behavior:"smooth"})}else for(;;){const[n,s]=a();try{o[c]=O(r(),t),e.A(7),await n}catch(e){return}finally{s()}}};return{J(i){o=i,r=I(e,i,t,(()=>O(i[c],t)),((t,o,r)=>{if(r){const e=i.style,t=e[a];e[a]="hidden",s((()=>{e[a]=t}))}o?(i[c]=e.j()+t,n&&n()):i[c]+=t}))},L(){r&&r.L()},te(e){u((()=>e))},oe(t){t+=e.j(),u((()=>t))},re(t,{align:o,smooth:r,offset:n=0}={}){if(t=i(t,0,e.C()-1),"nearest"===o){const r=e.O(t),n=e.j();if(r<n)o="start";else{if(!(r+e.I(t)>n+e.R()))return;o="end"}}u((()=>n+e.q()+e.O(t)+("end"===o?e.I(t)-e.R():"center"===o?(e.I(t)-e.R())/2:0)),r)},W:()=>{r&&r.W()}}})(p,d),m=e.ref(p.p()),v=p.H(1,(()=>{m.value=p.p()})),b=p.H(4,(()=>{n("scroll",p.j())})),y=p.H(8,(()=>{n("scrollEnd")}));return e.onMounted((()=>{f=!1,l((()=>{const e=e=>{h.$(e),g.J(e)};o.scrollRef?e(o.scrollRef):e(_.value.parentElement)}))})),e.onUnmounted((()=>{v(),b(),y(),h.L(),g.L()})),e.watch((()=>o.data.length),(e=>{p.A(5,[e,o.shift])})),e.watch((()=>o.startMargin),(e=>{p.A(6,e)}),{immediate:!0}),e.watch([m,p.T],(([,e],[,t])=>{e!==t&&g.W()}),{flush:"post"}),e.watch([m,p.m],(([,[e,t]],[,[o,r]])=>{o===e&&r===t||n("rangeChange",e,t)}),{flush:"post"}),c({get scrollOffset(){return p.j()},get scrollSize(){return(e=>r(e.N(),e.R()))(p)},get viewportSize(){return p.R()},getItemOffset:p.O,scrollToIndex:g.re,scrollTo:g.te,scrollBy:g.oe}),()=>{m.value;const t=o.as,r=o.item,n=o.data.length,[s,i]=p.m(),l=p.B(),c=p.N(),u=[];for(let[t,c]=x(s,i,o.overscan,l,n);t<=c;t++){const n=a.default({item:o.data[t],index:t})[0];u.push(e.createVNode(C,{key:j(n,t),Y:h.ee,F:t,U:p.O(t),V:p.v(t),X:n,G:d,K:f,Z:r},null,8,["_resizer","_index","_offset","_hide","_children","_isHorizontal","_isSSR","_as"]))}return e.createVNode(t,{ref:_,style:{overflowAnchor:"none",flex:"none",position:"relative",visibility:"hidden",width:d?c+"px":"100%",height:d?"100%":c+"px",pointerEvents:0!==l?"none":"auto"}},"function"==typeof(g=u)||"[object Object]"===Object.prototype.toString.call(g)&&!e.isVNode(g)?u:{default:()=>[u],_:2},8,["style"]);var g}}}),q={data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,ssrCount:Number},N=/*#__PURE__*/e.defineComponent({props:q,emits:["scroll","scrollEnd","rangeChange"],setup(t,{emit:o,expose:r,slots:n}){const s=t.horizontal,i=e=>{o("scroll",e)},l=()=>{o("scrollEnd")},c=(e,t)=>{o("rangeChange",e,t)},a=e.ref();return r({get scrollOffset(){return a.value.scrollOffset},get scrollSize(){return a.value.scrollSize},get viewportSize(){return a.value.viewportSize},getItemOffset:(...e)=>a.value.getItemOffset(...e),scrollToIndex:(...e)=>a.value.scrollToIndex(...e),scrollTo:(...e)=>a.value.scrollTo(...e),scrollBy:(...e)=>a.value.scrollBy(...e)}),()=>{return e.createVNode("div",{style:{display:s?"inline-block":"block",[s?"overflowX":"overflowY"]:"auto",contain:"strict",width:"100%",height:"100%"}},[e.createVNode(R,{ref:a,data:t.data,overscan:t.overscan,itemSize:t.itemSize,shift:t.shift,ssrCount:t.ssrCount,horizontal:s,onScroll:i,onScrollEnd:l,onRangeChange:c},(o=n,"function"==typeof o||"[object Object]"===Object.prototype.toString.call(o)&&!e.isVNode(o)?n:{default:()=>[n],_:2}),8,["data","overscan","itemSize","shift","ssrCount","horizontal","onScroll","onScrollEnd","onRangeChange"])],4);var o}}}),T={data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,as:{type:String,default:"div"},item:{type:String,default:"div"}},E=/*#__PURE__*/e.defineComponent({props:T,emits:["scrollEnd","rangeChange"],setup(o,{emit:r,slots:n}){var s;const i=o.horizontal,l=e.ref(),c=w(o.data.length,null!==(s=o.itemSize)&&void 0!==s?s:40,void 0,0,!o.itemSize),a=((e,o)=>{const r=o?"width":"height",n=o?"innerWidth":"innerHeight",s=new WeakMap,i=k((o=>{const n=[];for(const{target:e,contentRect:i}of o){if(!e.offsetParent)continue;const o=s.get(e);o!=t&&n.push([o,i[r]])}n.length&&e.A(3,n)}));let l;return{$(t){const o=b(v(t)),r=()=>{e.A(4,o[n])};o.addEventListener("resize",r),r(),l=()=>{o.removeEventListener("resize",r)}},ee:(e,t)=>(s.set(e,t),i.J(e),()=>{s.delete(e),i.D(e)}),L(){l&&l(),i.L()}}})(c,i),u=((e,t)=>{let o;return{J(r){const n=t?"scrollX":"scrollY",s=v(r),i=b(s),l=s.body,c=(e,t,o,r=0)=>{const n=o?"offsetLeft":"offsetTop",s=r+(o&&y()?i.innerWidth-e[n]-e.offsetWidth:e[n]),l=e.offsetParent;return e!==t&&l?c(l,t,o,s):s};o=I(e,i,t,(()=>O(i[n],t)),((o,r)=>{r?i.scroll({[t?"left":"top"]:e.j()+o}):i.scrollBy(t?o:0,t?0:o)}),(()=>c(r,l,t)))},L(){o&&o.L()},W:()=>{o&&o.W()}}})(c,i),f=e.ref(c.p()),d=c.H(1,(()=>{f.value=c.p()})),_=c.H(8,(()=>{r("scrollEnd")}));return e.onMounted((()=>{const e=l.value;e&&(a.$(e),u.J(e))})),e.onUnmounted((()=>{d(),_(),a.L(),u.L()})),e.watch((()=>o.data.length),(e=>{c.A(5,[e,o.shift])})),e.watch([f,c.T],(([,e],[,t])=>{e!==t&&u.W()}),{flush:"post"}),e.watch([f,c.m],(([,[e,t]],[,[o,n]])=>{o===e&&n===t||r("rangeChange",e,t)}),{flush:"post"}),()=>{f.value;const t=o.as,r=o.item,s=o.data.length,[u,d]=c.m(),_=c.B(),p=c.N(),h=[];for(let[t,l]=x(u,d,o.overscan,_,s);t<=l;t++){const s=n.default({item:o.data[t],index:t})[0];h.push(e.createVNode(C,{key:j(s,t),Y:a.ee,F:t,U:c.O(t),V:c.v(t),X:s,G:i,Z:r},null,8,["_resizer","_index","_offset","_hide","_children","_isHorizontal","_as"]))}return e.createVNode(t,{ref:l,style:{overflowAnchor:"none",flex:"none",position:"relative",visibility:"hidden",width:i?p+"px":"100%",height:i?"100%":p+"px",pointerEvents:0!==_?"none":"auto"}},"function"==typeof(g=h)||"[object Object]"===Object.prototype.toString.call(g)&&!e.isVNode(g)?h:{default:()=>[h],_:2},8,["style"]);var g}}});exports.VList=N,exports.Virtualizer=R,exports.WindowVirtualizer=E;
2
2
  //# sourceMappingURL=index.js.map
@@ -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/resizer.ts","../../src/src/core/scroller.ts","../../src/src/vue/ListItem.tsx","../../src/src/vue/utils.ts","../../src/src/vue/Virtualizer.tsx","../../src/src/vue/VList.tsx","../../src/src/vue/WindowVirtualizer.tsx"],"sourcesContent":["/** @internal */\nexport const NULL = null;\n\n/** @internal */\nexport const min = Math.min;\n/** @internal */\nexport const max = Math.max;\n/** @internal */\nexport const abs = Math.abs;\n/** @internal */\nexport const values = Object.values;\n/** @internal */\nexport const isArray = Array.isArray;\n/** @internal */\nexport const timeout = setTimeout;\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 median = (arr: number[]): number => {\n const sorted = sort(arr);\n const mid = (arr.length / 2) | 0;\n return sorted.length % 2 === 0\n ? (sorted[mid - 1]! + sorted[mid]!) / 2\n : sorted[mid]!;\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 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 * @internal\n */\nexport const once = <F extends (...args: any[]) => any>(fn: F): F => {\n let called: undefined | boolean;\n let cache: ReturnType<F>;\n\n return ((...args) => {\n if (!called) {\n called = true;\n cache = fn(...args);\n }\n return cache;\n }) as F;\n};\n\n/**\n * @internal\n */\nexport const getStyleNumber = (v: string): number => {\n if (v) {\n return parseFloat(v);\n } else {\n return 0;\n }\n};\n","import { type InternalCacheSnapshot, type ItemsRange } from \"./types\";\nimport { clamp, max, median, min } 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 * @internal\n */\nexport const findIndex = (cache: Cache, offset: number, i: number): number => {\n while (i >= 0 && i < cache._length) {\n const itemOffset = computeOffset(cache, i);\n if (itemOffset <= offset) {\n if (itemOffset + getItemSize(cache, i) > offset) {\n break;\n } else {\n i++;\n }\n } else {\n i--;\n }\n }\n return clamp(i, 0, cache._length - 1);\n};\n\n/**\n * @internal\n */\nexport const computeRange = (\n cache: Cache,\n scrollOffset: number,\n prevStartIndex: number,\n viewportSize: number\n): ItemsRange => {\n const start = findIndex(\n cache,\n scrollOffset,\n // Clamp because prevStartIndex may exceed the limit when children decreased a lot after scrolling\n min(prevStartIndex, cache._length - 1)\n );\n return [start, findIndex(cache, scrollOffset + viewportSize, start)];\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 = cache._sizes.filter((s, i) => {\n const isMeasured = s !== UNCACHED;\n if (isMeasured && i < startIndex) {\n measuredCountBeforeStart++;\n }\n return isMeasured;\n });\n const prevDefaultItemSize = cache._defaultItemSize;\n\n // Discard cache for now\n cache._computedOffsetIndex = -1;\n\n // Calculate diff of unmeasured items before start\n return (\n ((cache._defaultItemSize = median(measuredSizes)) - 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], 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} 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\n/** @internal */\nexport const SCROLL_IDLE = 0;\n/** @internal */\nexport const SCROLL_DOWN = 1;\n/** @internal */\nexport const SCROLL_UP = 2;\n/** @internal */\nexport type 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 getOverscanedRange = (\n startIndex: number,\n endIndex: number,\n overscan: number,\n scrollDirection: ScrollDirection,\n count: number\n): ItemsRange => {\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, count - 1)];\n};\n\ntype Subscriber = (sync?: boolean) => void;\n\n/** @internal */\nexport type StateVersion = readonly [];\n\n/**\n * @internal\n */\nexport type VirtualStore = {\n _getStateVersion(): StateVersion;\n _getCacheSnapshot(): CacheSnapshot;\n _getRange(): ItemsRange;\n _isUnmeasuredItem(index: number): boolean;\n _isInitialMeasurementDone(): boolean;\n _hasUnmeasuredItemsInFrozenRange(): boolean;\n _getItemOffset(index: number): number;\n _getItemSize(index: number): number;\n _getItemsLength(): number;\n _getScrollOffset(): number;\n _getScrollDirection(): ScrollDirection;\n _getViewportSize(): number;\n _getStartSpacerSize(): number;\n _getTotalSize(): number;\n _getJumpCount(): number;\n _flushJump(): [number, boolean];\n _subscribe(target: number, cb: Subscriber): () => void;\n _update(...action: Actions): void;\n};\n\n/**\n * @internal\n */\nexport const createVirtualStore = (\n elementsCount: number,\n itemSize: number = 40,\n ssrCount: number = 0,\n cacheSnapshot?: CacheSnapshot | undefined,\n shouldAutoEstimateItemSize: boolean = false\n): VirtualStore => {\n let isSSR = !!ssrCount;\n let stateVersion: StateVersion = [];\n let viewportSize = 0;\n let startSpacerSize = 0;\n let scrollOffset = 0;\n let jumpCount = 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 getRange = (offset: number) => {\n return computeRange(cache, offset, _prevRange[0], viewportSize);\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 jumpCount++;\n }\n }\n };\n\n return {\n _getStateVersion() {\n return stateVersion;\n },\n _getCacheSnapshot() {\n return takeCacheSnapshot(cache) as unknown as CacheSnapshot;\n },\n _getRange() {\n // Return previous range for consistent render until next scroll event comes in.\n if (_flushedJump) {\n return _prevRange;\n }\n _prevRange = getRange(\n max(0, getRelativeScrollOffset() + pendingJump + jump)\n );\n\n if (_frozenRange) {\n return [\n min(_prevRange[0], _frozenRange[0]),\n max(_prevRange[1], _frozenRange[1]),\n ];\n }\n return _prevRange;\n },\n _isUnmeasuredItem(index) {\n return cache._sizes[index] === UNCACHED;\n },\n _isInitialMeasurementDone() {\n return !!viewportSize;\n },\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() {\n return cache._length;\n },\n _getScrollOffset() {\n return scrollOffset;\n },\n _getScrollDirection() {\n return _scrollDirection;\n },\n _getViewportSize() {\n return viewportSize;\n },\n _getStartSpacerSize() {\n return startSpacerSize;\n },\n _getTotalSize: getTotalSize,\n _getJumpCount() {\n return jumpCount;\n },\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 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(estimateDefaultItemSize(cache, _prevRange[0]));\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 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 }\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 = [];\n\n if (shouldFlushPendingJump && pendingJump) {\n jump += pendingJump;\n pendingJump = 0;\n jumpCount++;\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 { 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","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 SCROLL_IDLE,\n ACTION_BEFORE_MANUAL_SMOOTH_SCROLL,\n ACTION_START_OFFSET_CHANGE,\n} from \"./store\";\nimport { type ScrollToIndexOpts } from \"./types\";\nimport { debounce, timeout, clamp, microtask } from \"./utils\";\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._getScrollDirection() === SCROLL_IDLE ||\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 (store._isInitialMeasurementDone()) {\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 _fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createWindowScroller = (\n store: VirtualStore,\n isHorizontal: boolean\n): WindowScroller => {\n let scrollObserver: ScrollObserver | undefined;\n\n return {\n _observe(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 const calcOffsetToViewport = (\n node: HTMLElement,\n viewport: HTMLElement,\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 isHorizontal,\n offsetSum\n );\n };\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 () => calcOffsetToViewport(container, documentBody, isHorizontal)\n );\n },\n _dispose() {\n scrollObserver && scrollObserver._dispose();\n },\n _fixScrollJump: () => {\n scrollObserver && scrollObserver._fixScrollJump();\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","/** @jsxImportSource vue */\nimport {\n ref,\n defineComponent,\n watch,\n StyleValue,\n PropType,\n VNode,\n NativeElements,\n} from \"vue\";\nimport { ItemResizeObserver } from \"../core/resizer\";\nimport { isRTLDocument } from \"../core/environment\";\n\n/**\n * @internal\n */\nexport const ListItem = /*#__PURE__*/ defineComponent({\n props: {\n _children: { type: Object as PropType<VNode>, required: true },\n _resizer: {\n type: Function as PropType<ItemResizeObserver>,\n required: true,\n },\n _index: { type: Number, required: true },\n _offset: { type: Number, required: true },\n _hide: { type: Boolean },\n _isHorizontal: { type: Boolean },\n _isSSR: { type: Boolean },\n _as: { type: String as PropType<keyof NativeElements>, required: true },\n },\n setup(props) {\n const elementRef = ref<HTMLDivElement>();\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n watch(\n () => elementRef.value && props._index,\n (_, __, onCleanup) => {\n onCleanup(props._resizer(elementRef.value!, props._index));\n },\n {\n flush: \"post\",\n }\n );\n\n return () => {\n const {\n _children: children,\n _offset: offset,\n _hide: hide,\n _isHorizontal: isHorizontal,\n _isSSR: isSSR,\n _as: Element,\n } = props;\n\n const style: StyleValue = {\n margin: 0,\n padding: 0,\n position: hide && isSSR ? undefined : \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : \"left\"]: \"0px\",\n [isHorizontal ? (isRTLDocument() ? \"right\" : \"left\") : \"top\"]:\n offset + \"px\",\n visibility: !hide || isSSR ? \"visible\" : \"hidden\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n\n return (\n <Element ref={elementRef} style={style}>\n {children}\n </Element>\n );\n };\n },\n});\n","import { VNode } from \"vue\";\nimport { NULL } from \"../core/utils\";\n\n/**\n * @internal\n */\nexport const getKey = (e: VNode, i: number): Exclude<VNode[\"key\"], null> => {\n const key = e.key;\n return key != NULL ? key : \"_\" + i;\n};\n","/** @jsxImportSource vue */\nimport {\n ref,\n onMounted,\n defineComponent,\n onUnmounted,\n VNode,\n watch,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n PropType,\n NativeElements,\n} from \"vue\";\nimport {\n SCROLL_IDLE,\n UPDATE_SCROLL_EVENT,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n getOverscanedRange,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n getScrollSize,\n ACTION_START_OFFSET_CHANGE,\n} from \"../core/store\";\nimport { createResizer } from \"../core/resizer\";\nimport { createScroller } from \"../core/scroller\";\nimport { ScrollToIndexOpts } from \"../core/types\";\nimport { ListItem } from \"./ListItem\";\nimport { getKey } from \"./utils\";\nimport { microtask } from \"../core/utils\";\n\nexport interface VirtualizerHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight or offsetWidth.\n */\n readonly viewportSize: number;\n /**\n * Get item offset from start.\n * @param index index of item\n */\n getItemOffset(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\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * If you put an element before virtualizer, you have to define its height with this prop.\n */\n startMargin: { type: Number, default: 0 },\n /**\n * A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated.\n */\n ssrCount: Number,\n /**\n * Reference to the scrollable element. The default will get the parent element of virtualizer.\n */\n scrollRef: Object as PropType<HTMLElement>,\n /**\n * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n} satisfies ComponentObjectPropsOptions;\n\nexport const Virtualizer = /*#__PURE__*/ defineComponent({\n props: props,\n emits: [\"scroll\", \"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, expose, slots }) {\n let isSSR = !!props.ssrCount;\n\n const isHorizontal = props.horizontal;\n const containerRef = ref<HTMLDivElement>();\n const store = createVirtualStore(\n props.data.length,\n props.itemSize ?? 40,\n props.ssrCount,\n undefined,\n !props.itemSize\n );\n const resizer = createResizer(store, isHorizontal);\n const scroller = createScroller(store, isHorizontal);\n\n const rerender = ref(store._getStateVersion());\n const unsubscribeStore = store._subscribe(UPDATE_VIRTUAL_STATE, () => {\n rerender.value = store._getStateVersion();\n });\n\n const unsubscribeOnScroll = store._subscribe(UPDATE_SCROLL_EVENT, () => {\n emit(\"scroll\", store._getScrollOffset());\n });\n const unsubscribeOnScrollEnd = store._subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n emit(\"scrollEnd\");\n }\n );\n\n onMounted(() => {\n isSSR = false;\n\n microtask(() => {\n const assignScrollableElement = (e: HTMLElement) => {\n resizer._observeRoot(e);\n scroller._observe(e);\n };\n if (props.scrollRef) {\n // parent's ref doesn't exist when onMounted is called\n assignScrollableElement(props.scrollRef!);\n } else {\n assignScrollableElement(containerRef.value!.parentElement!);\n }\n });\n });\n onUnmounted(() => {\n unsubscribeStore();\n unsubscribeOnScroll();\n unsubscribeOnScrollEnd();\n resizer._dispose();\n scroller._dispose();\n });\n\n watch(\n () => props.data.length,\n (count) => {\n store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n );\n watch(\n () => props.startMargin,\n (value) => {\n store._update(ACTION_START_OFFSET_CHANGE, value);\n },\n { immediate: true }\n );\n\n watch(\n [rerender, store._getJumpCount],\n ([, count], [, prevCount]) => {\n if (count === prevCount) return;\n\n scroller._fixScrollJump();\n },\n { flush: \"post\" }\n );\n\n watch(\n [rerender, store._getRange],\n ([, [start, end]], [, [prevStart, prevEnd]]) => {\n if (prevStart === start && prevEnd === end) return;\n\n emit(\"rangeChange\", start, end);\n },\n { flush: \"post\" }\n );\n\n expose({\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 getItemOffset: store._getItemOffset,\n scrollToIndex: scroller._scrollToIndex,\n scrollTo: scroller._scrollTo,\n scrollBy: scroller._scrollBy,\n } satisfies VirtualizerHandle);\n\n return () => {\n rerender.value;\n\n const Element = props.as;\n const ItemElement = props.item;\n const count = props.data.length;\n\n const [startIndex, endIndex] = store._getRange();\n const scrollDirection = store._getScrollDirection();\n const totalSize = store._getTotalSize();\n\n const items: VNode[] = [];\n for (\n let [i, j] = getOverscanedRange(\n startIndex,\n endIndex,\n props.overscan,\n scrollDirection,\n count\n );\n i <= j;\n i++\n ) {\n const e = slots.default(props.data![i]!)[0]! as VNode;\n items.push(\n <ListItem\n key={getKey(e, i)}\n _resizer={resizer._observeItem}\n _index={i}\n _offset={store._getItemOffset(i)}\n _hide={store._isUnmeasuredItem(i)}\n _children={e}\n _isHorizontal={isHorizontal}\n _isSSR={isSSR}\n _as={ItemElement}\n />\n );\n }\n\n return (\n <Element\n ref={containerRef}\n style={{\n // contain: \"content\",\n overflowAnchor: \"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: isHorizontal ? totalSize + \"px\" : \"100%\",\n height: isHorizontal ? \"100%\" : totalSize + \"px\",\n pointerEvents: scrollDirection !== SCROLL_IDLE ? \"none\" : \"auto\",\n }}\n >\n {items}\n </Element>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n VirtualizerHandle,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n scroll: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: any }>\n>);\n","/** @jsxImportSource vue */\nimport {\n defineComponent,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n ref,\n} from \"vue\";\nimport { Virtualizer, VirtualizerHandle } from \"./Virtualizer\";\n\ninterface VListHandle extends VirtualizerHandle {}\n\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated.\n */\n ssrCount: Number,\n} satisfies ComponentObjectPropsOptions;\n\nexport const VList = /*#__PURE__*/ defineComponent({\n props: props,\n emits: [\"scroll\", \"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, expose, slots }) {\n const horizontal = props.horizontal;\n\n const onScroll = (offset: number) => {\n emit(\"scroll\", offset);\n };\n const onScrollEnd = () => {\n emit(\"scrollEnd\");\n };\n const onRangeChange = (start: number, end: number) => {\n emit(\"rangeChange\", start, end);\n };\n\n const handle = ref<InstanceType<typeof Virtualizer>>();\n\n expose({\n get scrollOffset() {\n return handle.value!.scrollOffset;\n },\n get scrollSize() {\n return handle.value!.scrollSize;\n },\n get viewportSize() {\n return handle.value!.viewportSize;\n },\n getItemOffset: (...args) => handle.value!.getItemOffset(...args),\n scrollToIndex: (...args) => handle.value!.scrollToIndex(...args),\n scrollTo: (...args) => handle.value!.scrollTo(...args),\n scrollBy: (...args) => handle.value!.scrollBy(...args),\n } satisfies VListHandle);\n\n return () => {\n return (\n <div\n style={{\n display: horizontal ? \"inline-block\" : \"block\",\n [horizontal ? \"overflowX\" : \"overflowY\"]: \"auto\",\n contain: \"strict\",\n width: \"100%\",\n height: \"100%\",\n }}\n >\n <Virtualizer\n ref={handle}\n data={props.data}\n overscan={props.overscan}\n itemSize={props.itemSize}\n shift={props.shift}\n ssrCount={props.ssrCount}\n horizontal={horizontal}\n onScroll={onScroll}\n onScrollEnd={onScrollEnd}\n onRangeChange={onRangeChange}\n >\n {slots}\n </Virtualizer>\n </div>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n VListHandle,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n scroll: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: any }>\n>);\n","/** @jsxImportSource vue */\nimport {\n ref,\n onMounted,\n defineComponent,\n onUnmounted,\n VNode,\n watch,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n PropType,\n NativeElements,\n} from \"vue\";\nimport {\n SCROLL_IDLE,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n getOverscanedRange,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n} from \"../core/store\";\nimport { createWindowResizer } from \"../core/resizer\";\nimport { createWindowScroller } from \"../core/scroller\";\nimport { ListItem } from \"./ListItem\";\nimport { getKey } from \"./utils\";\n\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n} satisfies ComponentObjectPropsOptions;\n\nexport const WindowVirtualizer = /*#__PURE__*/ defineComponent({\n props,\n emits: [\"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, slots }) {\n const isHorizontal = props.horizontal;\n const containerRef = ref<HTMLDivElement>();\n const store = createVirtualStore(\n props.data.length,\n props.itemSize ?? 40,\n undefined,\n undefined,\n !props.itemSize\n );\n const resizer = createWindowResizer(store, isHorizontal);\n const scroller = createWindowScroller(store, isHorizontal);\n\n const rerender = ref(store._getStateVersion());\n const unsubscribeStore = store._subscribe(UPDATE_VIRTUAL_STATE, () => {\n rerender.value = store._getStateVersion();\n });\n\n const unsubscribeOnScrollEnd = store._subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n emit(\"scrollEnd\");\n }\n );\n\n onMounted(() => {\n const el = containerRef.value;\n if (!el) return;\n resizer._observeRoot(el);\n scroller._observe(el);\n });\n onUnmounted(() => {\n unsubscribeStore();\n unsubscribeOnScrollEnd();\n resizer._dispose();\n scroller._dispose();\n });\n\n watch(\n () => props.data.length,\n (count) => {\n store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n );\n\n watch(\n [rerender, store._getJumpCount],\n ([, count], [, prevCount]) => {\n if (count === prevCount) return;\n\n scroller._fixScrollJump();\n },\n { flush: \"post\" }\n );\n\n watch(\n [rerender, store._getRange],\n ([, [start, end]], [, [prevStart, prevEnd]]) => {\n if (prevStart === start && prevEnd === end) return;\n\n emit(\"rangeChange\", start, end);\n },\n { flush: \"post\" }\n );\n\n return () => {\n rerender.value;\n \n const Element = props.as;\n const ItemElement = props.item;\n const count = props.data.length;\n\n const [startIndex, endIndex] = store._getRange();\n const scrollDirection = store._getScrollDirection();\n const totalSize = store._getTotalSize();\n\n const items: VNode[] = [];\n for (\n let [i, j] = getOverscanedRange(\n startIndex,\n endIndex,\n props.overscan,\n scrollDirection,\n count\n );\n i <= j;\n i++\n ) {\n const e = slots.default(props.data![i]!)[0]! as VNode;\n items.push(\n <ListItem\n key={getKey(e, i)}\n _resizer={resizer._observeItem}\n _index={i}\n _offset={store._getItemOffset(i)}\n _hide={store._isUnmeasuredItem(i)}\n _children={e}\n _isHorizontal={isHorizontal}\n _as={ItemElement}\n />\n );\n }\n\n return (\n <Element\n ref={containerRef}\n style={{\n // contain: \"content\",\n overflowAnchor: \"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: isHorizontal ? totalSize + \"px\" : \"100%\",\n height: isHorizontal ? \"100%\" : totalSize + \"px\",\n pointerEvents: scrollDirection !== SCROLL_IDLE ? \"none\" : \"auto\",\n }}\n >\n {items}\n </Element>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n void,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: any }>\n>);\n"],"names":["NULL","min","Math","max","abs","timeout","setTimeout","clamp","value","minValue","maxValue","microtask","queueMicrotask","fn","Promise","resolve","then","once","called","cache","args","UNCACHED","fill","array","length","prepend","key","i","getItemSize","index","size","_sizes","_defaultItemSize","setItemSize","isInitialMeasurement","_computedOffsetIndex","computeOffset","_length","_offsets","top","findIndex","offset","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","getOverscanedRange","startIndex","endIndex","overscan","scrollDirection","count","createVirtualStore","elementsCount","itemSize","ssrCount","cacheSnapshot","shouldAutoEstimateItemSize","isSSR","stateVersion","viewportSize","startSpacerSize","scrollOffset","jumpCount","jump","pendingJump","_flushedJump","_scrollDirection","_scrollMode","_frozenRange","_prevRange","_totalMeasuredSize","initCache","subscribers","Set","getRelativeScrollOffset","getRange","computeRange","prevStartIndex","start","getTotalSize","computeTotalSize","getItemOffset","computeStartOffset","_getItemSize","applyJump","j","_getStateVersion","_getCacheSnapshot","takeCacheSnapshot","_getRange","_isUnmeasuredItem","_isInitialMeasurementDone","_hasUnmeasuredItemsInFrozenRange","slice","includes","_getItemOffset","_getItemsLength","_getScrollOffset","_getScrollDirection","_getViewportSize","_getStartSpacerSize","_getTotalSize","_getJumpCount","_flushJump","_subscribe","target","cb","sub","add","delete","_update","type","payload","shouldFlushPendingJump","shouldSync","mutated","flushedJump","delta","distance","relativeOffset","updated","filter","prevSize","estimateDefaultItemSize","measuredCountBeforeStart","measuredSizes","s","isMeasured","prevDefaultItemSize","arr","sorted","sort","a","b","mid","median","UPDATE_VIRTUAL_STATE","forEach","createResizeObserver","ro","_observe","e","observe","_unobserve","unobserve","_dispose","disconnect","normalizeOffset","isHorizontal","createScrollObserver","store","viewport","getScrollOffset","updateScrollOffset","getStartOffset","now","Date","lastScrollTime","wheeling","touching","justTouchEnded","stillMomentumScrolling","onScrollEnd","debounce","id","cancel","clearTimeout","debouncedFn","_cancel","onScroll","onWheel","ctrlKey","timeDelta","deltaX","deltaY","onTouchStart","onTouchEnd","addEventListener","passive","removeEventListener","_fixScrollJump","shift","ListItem","defineComponent","props","_children","Object","required","_resizer","Function","_index","Number","_offset","_hide","Boolean","_isHorizontal","_isSSR","_as","String","setup","elementRef","ref","watch","_","__","onCleanup","flush","children","hide","Element","margin","padding","position","undefined","visibility","display","_createVNode","_isVNode","prototype","toString","call","isVNode","default","getKey","data","Array","horizontal","startMargin","scrollRef","as","item","Virtualizer","emits","emit","expose","slots","containerRef","_a","resizer","createResizer","viewportElement","sizeKey","mountedIndexes","WeakMap","resizeObserver","entries","resizes","contentRect","offsetParent","get","push","_observeRoot","_observeItem","el","set","scroller","createScroller","scrollObserver","cancelScroll","scrollOffsetKey","overflowKey","scheduleImperativeScroll","async","getTargetOffset","smooth","waitForMeasurement","queue","reject","promise","unsubscribe","scrollTo","behavior","isMomentumScrolling","prev","_scrollTo","_scrollBy","_scrollToIndex","align","rerender","unsubscribeStore","unsubscribeOnScroll","unsubscribeOnScrollEnd","onMounted","assignScrollableElement","parentElement","onUnmounted","immediate","prevCount","end","prevStart","prevEnd","scrollSize","getScrollSize","scrollToIndex","scrollBy","ItemElement","totalSize","items","createVNode","Y","F","U","V","X","G","K","Z","overflowAnchor","flex","width","height","pointerEvents","VList","onRangeChange","handle","contain","WindowVirtualizer","createWindowResizer","windowSizeKey","cleanupOnWindowResize","container","onWindowResize","createWindowScroller","documentBody","body","calcOffsetToViewport","offsetKey","offsetSum","innerWidth","offsetWidth","parent","scroll"],"mappings":"qBACO,MAAMA,EAAO,KAGPC,EAAMC,KAAKD,IAEXE,EAAMD,KAAKC,IAEXC,EAAMF,KAAKE,IAMXC,EAAUC,WAKVC,EAAQA,CACnBC,EACAC,EACAC,IACWT,EAAIS,EAAUP,EAAIM,EAAUD,IAuB5BG,EACe,mBAAnBC,eACHA,eACCC,IACCC,QAAQC,UAAUC,KAAKH,EAAG,EA4BrBI,EAA2CJ,IACtD,IAAIK,EACAC,EAEJ,MAAQ,IAAIC,KACLF,IACHA,GAAS,EACTC,EAAQN,KAAMO,IAETD,EACR,EChFUE,GAAY,EAenBC,EAAOA,CAACC,EAAiBC,EAAgBC,KAC7C,MAAMC,EAAMD,EAAU,UAAY,OAClC,IAAK,IAAIE,EAAI,EAAGA,EAAIH,EAAQG,IAC1BJ,EAAMG,GAAKL,GAEb,OAAOE,CAAK,EAMDK,EAAcA,CAACT,EAAcU,K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tBlK,EAACmK,EACG5J,EAAY8J,EACtBX,GAAW,KAAA,EAAA,CAAA,WAAA,SAAA,UAAA,QAAA,YAAA,gBAAA,QAGtB,CAEA,OAAA/E,EAAAA,YAAAP,EAAA,CAAAR,IAESmC,EAAYhM,MACV,CAELuQ,eAAgB,OAChBC,KAAM,OACNhG,SAAU,WACVE,WAAY,SACZ+F,MAAOjK,EAAeoJ,EAAY,KAAO,OACzCc,OAAQlK,EAAe,OAASoJ,EAAY,KAC5Ce,cPhKe,IOgKAtQ,EAAkC,OAAS,SA5JrC,mBAAA6E,EA+JtB2K,IA/JsBhF,oBAAA/B,OAAAgC,UAAAC,SAAAC,KAAA9F,KAAA2F,EAAAI,QAAA/F,GA+JtB2K,EAAK,CAAA3E,QAAAA,IAAA,CAAL2E,GAAK9F,EAAA,GAAA,EAAA,CAAA,UA/JiB,IAAA7E,CA+JjB,CAId"}
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/resizer.ts","../../src/src/core/scroller.ts","../../src/src/vue/ListItem.tsx","../../src/src/vue/utils.ts","../../src/src/vue/Virtualizer.tsx","../../src/src/vue/VList.tsx","../../src/src/vue/WindowVirtualizer.tsx"],"sourcesContent":["/** @internal */\nexport const NULL = null;\n\n/** @internal */\nexport const min = Math.min;\n/** @internal */\nexport const max = Math.max;\n/** @internal */\nexport const abs = Math.abs;\n/** @internal */\nexport const values = Object.values;\n/** @internal */\nexport const isArray = Array.isArray;\n/** @internal */\nexport const timeout = setTimeout;\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 median = (arr: number[]): number => {\n const sorted = sort(arr);\n const mid = (arr.length / 2) | 0;\n return sorted.length % 2 === 0\n ? (sorted[mid - 1]! + sorted[mid]!) / 2\n : sorted[mid]!;\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 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 * @internal\n */\nexport const once = <F extends (...args: any[]) => any>(fn: F): F => {\n let called: undefined | boolean;\n let cache: ReturnType<F>;\n\n return ((...args) => {\n if (!called) {\n called = true;\n cache = fn(...args);\n }\n return cache;\n }) as F;\n};\n\n/**\n * @internal\n */\nexport const getStyleNumber = (v: string): number => {\n if (v) {\n return parseFloat(v);\n } else {\n return 0;\n }\n};\n","import { type InternalCacheSnapshot, type ItemsRange } from \"./types\";\nimport { clamp, max, median, min } 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 * @internal\n */\nexport const findIndex = (cache: Cache, offset: number, i: number): number => {\n while (i >= 0 && i < cache._length) {\n const itemOffset = computeOffset(cache, i);\n if (itemOffset <= offset) {\n if (itemOffset + getItemSize(cache, i) > offset) {\n break;\n } else {\n i++;\n }\n } else {\n i--;\n }\n }\n return clamp(i, 0, cache._length - 1);\n};\n\n/**\n * @internal\n */\nexport const computeRange = (\n cache: Cache,\n scrollOffset: number,\n prevStartIndex: number,\n viewportSize: number\n): ItemsRange => {\n const start = findIndex(\n cache,\n scrollOffset,\n // Clamp because prevStartIndex may exceed the limit when children decreased a lot after scrolling\n min(prevStartIndex, cache._length - 1)\n );\n return [start, findIndex(cache, scrollOffset + viewportSize, start)];\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 = cache._sizes.filter((s, i) => {\n const isMeasured = s !== UNCACHED;\n if (isMeasured && i < startIndex) {\n measuredCountBeforeStart++;\n }\n return isMeasured;\n });\n const prevDefaultItemSize = cache._defaultItemSize;\n\n // Discard cache for now\n cache._computedOffsetIndex = -1;\n\n // Calculate diff of unmeasured items before start\n return (\n ((cache._defaultItemSize = median(measuredSizes)) - 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], 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} 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\n/** @internal */\nexport const SCROLL_IDLE = 0;\n/** @internal */\nexport const SCROLL_DOWN = 1;\n/** @internal */\nexport const SCROLL_UP = 2;\n/** @internal */\nexport type 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 getOverscanedRange = (\n startIndex: number,\n endIndex: number,\n overscan: number,\n scrollDirection: ScrollDirection,\n count: number\n): ItemsRange => {\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, count - 1)];\n};\n\ntype Subscriber = (sync?: boolean) => void;\n\n/** @internal */\nexport type StateVersion = readonly [];\n\n/**\n * @internal\n */\nexport type VirtualStore = {\n _getStateVersion(): StateVersion;\n _getCacheSnapshot(): CacheSnapshot;\n _getRange(): ItemsRange;\n _isUnmeasuredItem(index: number): boolean;\n _isInitialMeasurementDone(): boolean;\n _hasUnmeasuredItemsInFrozenRange(): boolean;\n _getItemOffset(index: number): number;\n _getItemSize(index: number): number;\n _getItemsLength(): number;\n _getScrollOffset(): number;\n _getScrollDirection(): ScrollDirection;\n _getViewportSize(): number;\n _getStartSpacerSize(): number;\n _getTotalSize(): number;\n _getJumpCount(): number;\n _flushJump(): [number, boolean];\n _subscribe(target: number, cb: Subscriber): () => void;\n _update(...action: Actions): void;\n};\n\n/**\n * @internal\n */\nexport const createVirtualStore = (\n elementsCount: number,\n itemSize: number = 40,\n ssrCount: number = 0,\n cacheSnapshot?: CacheSnapshot | undefined,\n shouldAutoEstimateItemSize: boolean = false\n): VirtualStore => {\n let isSSR = !!ssrCount;\n let stateVersion: StateVersion = [];\n let viewportSize = 0;\n let startSpacerSize = 0;\n let scrollOffset = 0;\n let jumpCount = 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 getRange = (offset: number) => {\n return computeRange(cache, offset, _prevRange[0], viewportSize);\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 jumpCount++;\n }\n }\n };\n\n return {\n _getStateVersion() {\n return stateVersion;\n },\n _getCacheSnapshot() {\n return takeCacheSnapshot(cache) as unknown as CacheSnapshot;\n },\n _getRange() {\n // Return previous range for consistent render until next scroll event comes in.\n if (_flushedJump) {\n return _prevRange;\n }\n _prevRange = getRange(\n max(0, getRelativeScrollOffset() + pendingJump + jump)\n );\n\n if (_frozenRange) {\n return [\n min(_prevRange[0], _frozenRange[0]),\n max(_prevRange[1], _frozenRange[1]),\n ];\n }\n return _prevRange;\n },\n _isUnmeasuredItem(index) {\n return cache._sizes[index] === UNCACHED;\n },\n _isInitialMeasurementDone() {\n return !!viewportSize;\n },\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() {\n return cache._length;\n },\n _getScrollOffset() {\n return scrollOffset;\n },\n _getScrollDirection() {\n return _scrollDirection;\n },\n _getViewportSize() {\n return viewportSize;\n },\n _getStartSpacerSize() {\n return startSpacerSize;\n },\n _getTotalSize: getTotalSize,\n _getJumpCount() {\n return jumpCount;\n },\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 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(estimateDefaultItemSize(cache, _prevRange[0]));\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 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 }\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 = [];\n\n if (shouldFlushPendingJump && pendingJump) {\n jump += pendingJump;\n pendingJump = 0;\n jumpCount++;\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 { 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","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 SCROLL_IDLE,\n ACTION_BEFORE_MANUAL_SMOOTH_SCROLL,\n ACTION_START_OFFSET_CHANGE,\n} from \"./store\";\nimport { type ScrollToIndexOpts } from \"./types\";\nimport { debounce, timeout, clamp, microtask } from \"./utils\";\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._getScrollDirection() === SCROLL_IDLE ||\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 (store._isInitialMeasurementDone()) {\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 _fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createWindowScroller = (\n store: VirtualStore,\n isHorizontal: boolean\n): WindowScroller => {\n let scrollObserver: ScrollObserver | undefined;\n\n return {\n _observe(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 const calcOffsetToViewport = (\n node: HTMLElement,\n viewport: HTMLElement,\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 isHorizontal,\n offsetSum\n );\n };\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 () => calcOffsetToViewport(container, documentBody, isHorizontal)\n );\n },\n _dispose() {\n scrollObserver && scrollObserver._dispose();\n },\n _fixScrollJump: () => {\n scrollObserver && scrollObserver._fixScrollJump();\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","/** @jsxImportSource vue */\nimport {\n ref,\n defineComponent,\n watch,\n StyleValue,\n PropType,\n VNode,\n NativeElements,\n} from \"vue\";\nimport { ItemResizeObserver } from \"../core/resizer\";\nimport { isRTLDocument } from \"../core/environment\";\n\n/**\n * @internal\n */\nexport const ListItem = /*#__PURE__*/ defineComponent({\n props: {\n _children: { type: Object as PropType<VNode>, required: true },\n _resizer: {\n type: Function as PropType<ItemResizeObserver>,\n required: true,\n },\n _index: { type: Number, required: true },\n _offset: { type: Number, required: true },\n _hide: { type: Boolean },\n _isHorizontal: { type: Boolean },\n _isSSR: { type: Boolean },\n _as: { type: String as PropType<keyof NativeElements>, required: true },\n },\n setup(props) {\n const elementRef = ref<HTMLDivElement>();\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n watch(\n () => elementRef.value && props._index,\n (_, __, onCleanup) => {\n onCleanup(props._resizer(elementRef.value!, props._index));\n },\n {\n flush: \"post\",\n }\n );\n\n return () => {\n const {\n _children: children,\n _offset: offset,\n _hide: hide,\n _isHorizontal: isHorizontal,\n _isSSR: isSSR,\n _as: Element,\n } = props;\n\n const style: StyleValue = {\n margin: 0,\n padding: 0,\n position: hide && isSSR ? undefined : \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : \"left\"]: \"0px\",\n [isHorizontal ? (isRTLDocument() ? \"right\" : \"left\") : \"top\"]:\n offset + \"px\",\n visibility: !hide || isSSR ? \"visible\" : \"hidden\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n\n return (\n <Element ref={elementRef} style={style}>\n {children}\n </Element>\n );\n };\n },\n});\n","import { VNode } from \"vue\";\nimport { NULL } from \"../core/utils\";\n\n/**\n * @internal\n */\nexport const getKey = (e: VNode, i: number): Exclude<VNode[\"key\"], null> => {\n const key = e.key;\n return key != NULL ? key : \"_\" + i;\n};\n","/** @jsxImportSource vue */\nimport {\n ref,\n onMounted,\n defineComponent,\n onUnmounted,\n VNode,\n watch,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n PropType,\n NativeElements,\n} from \"vue\";\nimport {\n SCROLL_IDLE,\n UPDATE_SCROLL_EVENT,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n getOverscanedRange,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n getScrollSize,\n ACTION_START_OFFSET_CHANGE,\n} from \"../core/store\";\nimport { createResizer } from \"../core/resizer\";\nimport { createScroller } from \"../core/scroller\";\nimport { ScrollToIndexOpts } from \"../core/types\";\nimport { ListItem } from \"./ListItem\";\nimport { getKey } from \"./utils\";\nimport { microtask } from \"../core/utils\";\n\nexport interface VirtualizerHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight or offsetWidth.\n */\n readonly viewportSize: number;\n /**\n * Get item offset from start.\n * @param index index of item\n */\n getItemOffset(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\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * If you put an element before virtualizer, you have to define its height with this prop.\n */\n startMargin: { type: Number, default: 0 },\n /**\n * A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated.\n */\n ssrCount: Number,\n /**\n * Reference to the scrollable element. The default will get the parent element of virtualizer.\n */\n scrollRef: Object as PropType<HTMLElement>,\n /**\n * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n} satisfies ComponentObjectPropsOptions;\n\nexport const Virtualizer = /*#__PURE__*/ defineComponent({\n props: props,\n emits: [\"scroll\", \"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, expose, slots }) {\n let isSSR = !!props.ssrCount;\n\n const isHorizontal = props.horizontal;\n const containerRef = ref<HTMLDivElement>();\n const store = createVirtualStore(\n props.data.length,\n props.itemSize ?? 40,\n props.ssrCount,\n undefined,\n !props.itemSize\n );\n const resizer = createResizer(store, isHorizontal);\n const scroller = createScroller(store, isHorizontal);\n\n const rerender = ref(store._getStateVersion());\n const unsubscribeStore = store._subscribe(UPDATE_VIRTUAL_STATE, () => {\n rerender.value = store._getStateVersion();\n });\n\n const unsubscribeOnScroll = store._subscribe(UPDATE_SCROLL_EVENT, () => {\n emit(\"scroll\", store._getScrollOffset());\n });\n const unsubscribeOnScrollEnd = store._subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n emit(\"scrollEnd\");\n }\n );\n\n onMounted(() => {\n isSSR = false;\n\n microtask(() => {\n const assignScrollableElement = (e: HTMLElement) => {\n resizer._observeRoot(e);\n scroller._observe(e);\n };\n if (props.scrollRef) {\n // parent's ref doesn't exist when onMounted is called\n assignScrollableElement(props.scrollRef!);\n } else {\n assignScrollableElement(containerRef.value!.parentElement!);\n }\n });\n });\n onUnmounted(() => {\n unsubscribeStore();\n unsubscribeOnScroll();\n unsubscribeOnScrollEnd();\n resizer._dispose();\n scroller._dispose();\n });\n\n watch(\n () => props.data.length,\n (count) => {\n store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n );\n watch(\n () => props.startMargin,\n (value) => {\n store._update(ACTION_START_OFFSET_CHANGE, value);\n },\n { immediate: true }\n );\n\n watch(\n [rerender, store._getJumpCount],\n ([, count], [, prevCount]) => {\n if (count === prevCount) return;\n\n scroller._fixScrollJump();\n },\n { flush: \"post\" }\n );\n\n watch(\n [rerender, store._getRange],\n ([, [start, end]], [, [prevStart, prevEnd]]) => {\n if (prevStart === start && prevEnd === end) return;\n\n emit(\"rangeChange\", start, end);\n },\n { flush: \"post\" }\n );\n\n expose({\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 getItemOffset: store._getItemOffset,\n scrollToIndex: scroller._scrollToIndex,\n scrollTo: scroller._scrollTo,\n scrollBy: scroller._scrollBy,\n } satisfies VirtualizerHandle);\n\n return () => {\n rerender.value;\n\n const Element = props.as;\n const ItemElement = props.item;\n const count = props.data.length;\n\n const [startIndex, endIndex] = store._getRange();\n const scrollDirection = store._getScrollDirection();\n const totalSize = store._getTotalSize();\n\n const items: VNode[] = [];\n for (\n let [i, j] = getOverscanedRange(\n startIndex,\n endIndex,\n props.overscan,\n scrollDirection,\n count\n );\n i <= j;\n i++\n ) {\n const e = slots.default({ item: props.data![i]!, index: i })[0]!;\n items.push(\n <ListItem\n key={getKey(e, i)}\n _resizer={resizer._observeItem}\n _index={i}\n _offset={store._getItemOffset(i)}\n _hide={store._isUnmeasuredItem(i)}\n _children={e}\n _isHorizontal={isHorizontal}\n _isSSR={isSSR}\n _as={ItemElement}\n />\n );\n }\n\n return (\n <Element\n ref={containerRef}\n style={{\n // contain: \"content\",\n overflowAnchor: \"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: isHorizontal ? totalSize + \"px\" : \"100%\",\n height: isHorizontal ? \"100%\" : totalSize + \"px\",\n pointerEvents: scrollDirection !== SCROLL_IDLE ? \"none\" : \"auto\",\n }}\n >\n {items}\n </Element>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n VirtualizerHandle,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n scroll: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: (arg: { item: any; index: number }) => VNode[] }>\n>);\n","/** @jsxImportSource vue */\nimport {\n defineComponent,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n ref,\n VNode,\n} from \"vue\";\nimport { Virtualizer, VirtualizerHandle } from \"./Virtualizer\";\n\ninterface VListHandle extends VirtualizerHandle {}\n\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated.\n */\n ssrCount: Number,\n} satisfies ComponentObjectPropsOptions;\n\nexport const VList = /*#__PURE__*/ defineComponent({\n props: props,\n emits: [\"scroll\", \"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, expose, slots }) {\n const horizontal = props.horizontal;\n\n const onScroll = (offset: number) => {\n emit(\"scroll\", offset);\n };\n const onScrollEnd = () => {\n emit(\"scrollEnd\");\n };\n const onRangeChange = (start: number, end: number) => {\n emit(\"rangeChange\", start, end);\n };\n\n const handle = ref<InstanceType<typeof Virtualizer>>();\n\n expose({\n get scrollOffset() {\n return handle.value!.scrollOffset;\n },\n get scrollSize() {\n return handle.value!.scrollSize;\n },\n get viewportSize() {\n return handle.value!.viewportSize;\n },\n getItemOffset: (...args) => handle.value!.getItemOffset(...args),\n scrollToIndex: (...args) => handle.value!.scrollToIndex(...args),\n scrollTo: (...args) => handle.value!.scrollTo(...args),\n scrollBy: (...args) => handle.value!.scrollBy(...args),\n } satisfies VListHandle);\n\n return () => {\n return (\n <div\n style={{\n display: horizontal ? \"inline-block\" : \"block\",\n [horizontal ? \"overflowX\" : \"overflowY\"]: \"auto\",\n contain: \"strict\",\n width: \"100%\",\n height: \"100%\",\n }}\n >\n <Virtualizer\n ref={handle}\n data={props.data}\n overscan={props.overscan}\n itemSize={props.itemSize}\n shift={props.shift}\n ssrCount={props.ssrCount}\n horizontal={horizontal}\n onScroll={onScroll}\n onScrollEnd={onScrollEnd}\n onRangeChange={onRangeChange}\n >\n {slots}\n </Virtualizer>\n </div>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n VListHandle,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n scroll: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: (arg: { item: any; index: number }) => VNode[] }>\n>);\n","/** @jsxImportSource vue */\nimport {\n ref,\n onMounted,\n defineComponent,\n onUnmounted,\n VNode,\n watch,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n PropType,\n NativeElements,\n} from \"vue\";\nimport {\n SCROLL_IDLE,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n getOverscanedRange,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n} from \"../core/store\";\nimport { createWindowResizer } from \"../core/resizer\";\nimport { createWindowScroller } from \"../core/scroller\";\nimport { ListItem } from \"./ListItem\";\nimport { getKey } from \"./utils\";\n\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n} satisfies ComponentObjectPropsOptions;\n\nexport const WindowVirtualizer = /*#__PURE__*/ defineComponent({\n props,\n emits: [\"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, slots }) {\n const isHorizontal = props.horizontal;\n const containerRef = ref<HTMLDivElement>();\n const store = createVirtualStore(\n props.data.length,\n props.itemSize ?? 40,\n undefined,\n undefined,\n !props.itemSize\n );\n const resizer = createWindowResizer(store, isHorizontal);\n const scroller = createWindowScroller(store, isHorizontal);\n\n const rerender = ref(store._getStateVersion());\n const unsubscribeStore = store._subscribe(UPDATE_VIRTUAL_STATE, () => {\n rerender.value = store._getStateVersion();\n });\n\n const unsubscribeOnScrollEnd = store._subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n emit(\"scrollEnd\");\n }\n );\n\n onMounted(() => {\n const el = containerRef.value;\n if (!el) return;\n resizer._observeRoot(el);\n scroller._observe(el);\n });\n onUnmounted(() => {\n unsubscribeStore();\n unsubscribeOnScrollEnd();\n resizer._dispose();\n scroller._dispose();\n });\n\n watch(\n () => props.data.length,\n (count) => {\n store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n );\n\n watch(\n [rerender, store._getJumpCount],\n ([, count], [, prevCount]) => {\n if (count === prevCount) return;\n\n scroller._fixScrollJump();\n },\n { flush: \"post\" }\n );\n\n watch(\n [rerender, store._getRange],\n ([, [start, end]], [, [prevStart, prevEnd]]) => {\n if (prevStart === start && prevEnd === end) return;\n\n emit(\"rangeChange\", start, end);\n },\n { flush: \"post\" }\n );\n\n return () => {\n rerender.value;\n\n const Element = props.as;\n const ItemElement = props.item;\n const count = props.data.length;\n\n const [startIndex, endIndex] = store._getRange();\n const scrollDirection = store._getScrollDirection();\n const totalSize = store._getTotalSize();\n\n const items: VNode[] = [];\n for (\n let [i, j] = getOverscanedRange(\n startIndex,\n endIndex,\n props.overscan,\n scrollDirection,\n count\n );\n i <= j;\n i++\n ) {\n const e = slots.default({ item: props.data![i]!, index: i })[0]!;\n items.push(\n <ListItem\n key={getKey(e, i)}\n _resizer={resizer._observeItem}\n _index={i}\n _offset={store._getItemOffset(i)}\n _hide={store._isUnmeasuredItem(i)}\n _children={e}\n _isHorizontal={isHorizontal}\n _as={ItemElement}\n />\n );\n }\n\n return (\n <Element\n ref={containerRef}\n style={{\n // contain: \"content\",\n overflowAnchor: \"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: isHorizontal ? totalSize + \"px\" : \"100%\",\n height: isHorizontal ? \"100%\" : totalSize + \"px\",\n pointerEvents: scrollDirection !== SCROLL_IDLE ? \"none\" : \"auto\",\n }}\n >\n {items}\n </Element>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n void,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: (arg: { item: any; index: number }) => VNode[] }>\n>);\n"],"names":["NULL","min","Math","max","abs","timeout","setTimeout","clamp","value","minValue","maxValue","microtask","queueMicrotask","fn","Promise","resolve","then","once","called","cache","args","UNCACHED","fill","array","length","prepend","key","i","getItemSize","index","size","_sizes","_defaultItemSize","setItemSize","isInitialMeasurement","_computedOffsetIndex","computeOffset","_length","_offsets","top","findIndex","offset","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","getOverscanedRange","startIndex","endIndex","overscan","scrollDirection","count","createVirtualStore","elementsCount","itemSize","ssrCount","cacheSnapshot","shouldAutoEstimateItemSize","isSSR","stateVersion","viewportSize","startSpacerSize","scrollOffset","jumpCount","jump","pendingJump","_flushedJump","_scrollDirection","_scrollMode","_frozenRange","_prevRange","_totalMeasuredSize","initCache","subscribers","Set","getRelativeScrollOffset","getRange","computeRange","prevStartIndex","start","getTotalSize","computeTotalSize","getItemOffset","computeStartOffset","_getItemSize","applyJump","j","_getStateVersion","_getCacheSnapshot","takeCacheSnapshot","_getRange","_isUnmeasuredItem","_isInitialMeasurementDone","_hasUnmeasuredItemsInFrozenRange","slice","includes","_getItemOffset","_getItemsLength","_getScrollOffset","_getScrollDirection","_getViewportSize","_getStartSpacerSize","_getTotalSize","_getJumpCount","_flushJump","_subscribe","target","cb","sub","add","delete","_update","type","payload","shouldFlushPendingJump","shouldSync","mutated","flushedJump","delta","distance","relativeOffset","updated","filter","prevSize","estimateDefaultItemSize","measuredCountBeforeStart","measuredSizes","s","isMeasured","prevDefaultItemSize","arr","sorted","sort","a","b","mid","median","UPDATE_VIRTUAL_STATE","forEach","createResizeObserver","ro","_observe","e","observe","_unobserve","unobserve","_dispose","disconnect","normalizeOffset","isHorizontal","createScrollObserver","store","viewport","getScrollOffset","updateScrollOffset","getStartOffset","now","Date","lastScrollTime","wheeling","touching","justTouchEnded","stillMomentumScrolling","onScrollEnd","debounce","id","cancel","clearTimeout","debouncedFn","_cancel","onScroll","onWheel","ctrlKey","timeDelta","deltaX","deltaY","onTouchStart","onTouchEnd","addEventListener","passive","removeEventListener","_fixScrollJump","shift","ListItem","defineComponent","props","_children","Object","required","_resizer","Function","_index","Number","_offset","_hide","Boolean","_isHorizontal","_isSSR","_as","String","setup","elementRef","ref","watch","_","__","onCleanup","flush","children","hide","Element","margin","padding","position","undefined","visibility","display","_createVNode","_isVNode","prototype","toString","call","isVNode","default","getKey","data","Array","horizontal","startMargin","scrollRef","as","item","Virtualizer","emits","emit","expose","slots","containerRef","_a","resizer","createResizer","viewportElement","sizeKey","mountedIndexes","WeakMap","resizeObserver","entries","resizes","contentRect","offsetParent","get","push","_observeRoot","_observeItem","el","set","scroller","createScroller","scrollObserver","cancelScroll","scrollOffsetKey","overflowKey","scheduleImperativeScroll","async","getTargetOffset","smooth","waitForMeasurement","queue","reject","promise","unsubscribe","scrollTo","behavior","isMomentumScrolling","prev","_scrollTo","_scrollBy","_scrollToIndex","align","rerender","unsubscribeStore","unsubscribeOnScroll","unsubscribeOnScrollEnd","onMounted","assignScrollableElement","parentElement","onUnmounted","immediate","prevCount","end","prevStart","prevEnd","scrollSize","getScrollSize","scrollToIndex","scrollBy","ItemElement","totalSize","items","createVNode","Y","F","U","V","X","G","K","Z","overflowAnchor","flex","width","height","pointerEvents","VList","onRangeChange","handle","contain","WindowVirtualizer","createWindowResizer","windowSizeKey","cleanupOnWindowResize","container","onWindowResize","createWindowScroller","documentBody","body","calcOffsetToViewport","offsetKey","offsetSum","innerWidth","offsetWidth","parent","scroll"],"mappings":"qBACO,MAAMA,E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Node as n,onMounted as s,onUnmounted as i}from"vue";const l=null,c=Math.min,a=Math.max,u=Math.abs,f=setTimeout,d=(e,t,o)=>c(o,a(t,e)),_="function"==typeof queueMicrotask?queueMicrotask:e=>{Promise.resolve().then(e)},p=e=>{let t,o;return(...r)=>(t||(t=!0,o=e(...r)),o)},h=-1,g=(e,t,o)=>{const r=o?"unshift":"push";for(let o=0;o<t;o++)e[r](h);return e},m=(e,t)=>{const o=e.t[t];return o===h?e.o:o},v=(e,t,o)=>{const r=e.t[t]===h;return e.t[t]=o,e.i=c(t,e.i),r},b=(e,t)=>{if(!e.l)return 0;if(e.i>=t)return e.u[t];e.i<0&&(e.u[0]=0,e.i=0);let o=e.i,r=e.u[o];for(;o<t;)r+=m(e,o),e.u[++o]=r;return e.i=t,r},y=(e,t,o)=>{for(;o>=0&&o<e.l;){const r=b(e,o);if(r<=t){if(r+m(e,o)>t)break;o++}else o--}return d(o,0,e.l-1)},S=(e,t,o)=>{const r=t-e.l;return e.i=o?-1:c(t-1,e.i),e.l=t,r>0?(g(e.u,r),g(e.t,r,o),e.o*r):(e.u.splice(r),(o?e.t.splice(0,-r):e.t.splice(r)).reduce(((t,o)=>t-(o===h?e.o:o)),0))},z="undefined"!=typeof window,w=()=>document.documentElement,x=e=>e.ownerDocument,k=e=>e.defaultView,O=/*#__PURE__*/p((()=>!!z&&"rtl"===getComputedStyle(w()).direction)),I=/*#__PURE__*/p((()=>/iP(hone|od|ad)/.test(navigator.userAgent))),C=/*#__PURE__*/p((()=>"scrollBehavior"in w().style)),j=(e,t,o,r,n)=>(1!==r&&(e-=a(0,o)),2!==r&&(t+=a(0,o)),[a(e,0),c(t,n-1)]),B=(e,t=40,o=0,r,n=!1)=>{let s=!!o,i=[],f=0,d=0,_=0,p=0,z=0,w=0,x=0,k=0,O=0,C=s?[0,a(o-1,0)]:l,j=[0,0],B=0;const R=((e,t)=>({o:t,t:g([],e),l:e,i:-1,u:g([],e)}))(e,t),N=new Set,T=()=>_-d,q=e=>((e,t,o,r)=>{const n=y(e,t,c(o,e.l-1));return[n,y(e,t+r,n)]})(R,e,j[0],f),E=()=>(e=>e.l?b(e,e.l-1)+m(e,e.l-1):0)(R),M=e=>b(R,e)-w,H=e=>m(R,e),A=e=>{e&&(I()&&0!==k?w+=e:(z+=e,p++))};return{p:()=>i,h:()=>(e=>[[...e.t],e.o])(R),m:()=>x?j:(j=q(a(0,T()+w+z)),C?[c(j[0],C[0]),a(j[1],C[1])]:j),v:e=>R.t[e]===h,S:()=>!!f,k:()=>!!C&&R.t.slice(a(0,C[0]-1),c(R.l-1,C[1]+1)+1).includes(h),O:M,I:H,C:()=>R.l,j:()=>_,B:()=>k,R:()=>f,N:()=>d,T:E,q:()=>p,M:()=>(x=z,z=0,[x,2===O||T()+f>=E()]),H(e,t){const o=[e,t];return N.add(o),()=>{N.delete(o)}},A(e,t){let o,r,c=0;switch(e){case 1:{const e=x;x=0;const o=t-_,n=u(o);e&&n<u(e)+1||0!==O||(k=o<0?2:1),s&&(C=l,s=!1),_=t,c=4;const i=T();i>=-f&&i<=E()&&(c+=1,r=n>f);break}case 2:c=8,0!==k&&(o=!0,c+=1),k=0,O=0,C=l;break;case 3:{const e=t.filter((([e,t])=>R.t[e]!==t));if(!e.length)break;A(e.reduce(((e,[t,o])=>((2===O||(C?t<C[0]:M(t)+(0===k&&0===O?H(t):0)<T()))&&(e+=o-H(t)),e)),0));for(const[t,o]of e){const e=H(t),r=v(R,t,o);n&&(B+=r?o:o-e)}n&&f&&B>f&&(A(((e,t)=>{let o=0;const r=e.t.filter(((e,r)=>{const n=e!==h;return n&&r<t&&o++,n})),n=e.o;return e.i=-1,((e.o=(e=>{const t=(e=>[...e].sort(((e,t)=>e-t)))(e),o=e.length/2|0;return t.length%2==0?(t[o-1]+t[o])/2:t[o]})(r))-n)*a(t-o,0)})(R,j[0])),n=!1),c=3,r=!0;break}case 4:f!==t&&(f=t,c=3);break;case 5:t[1]?(A(S(R,t[0],!0)),O=2,c=1):S(R,t[0]);break;case 6:d=t;break;case 7:O=1;break;case 8:C=q(t),c=1}c&&(i=[],o&&w&&(z+=w,w=0,p++),N.forEach((([e,t])=>{c&e&&t(r)})))}}},R=e=>{let t;return{J(o){(t||(t=new(k(x(o)).ResizeObserver)(e))).observe(o)},D(e){t.unobserve(e)},L(){t&&t.disconnect()}}},N=(e,t)=>t&&O()?-e:e,T=(e,t,o,r,n,s)=>{const i=Date.now;let c=0,a=!1,u=!1,d=!1,_=!1;const p=(()=>{let t;const o=()=>{t!=l&&clearTimeout(t)},r=()=>{o(),t=f((()=>{t=l,(()=>{if(a||u)return a=!1,void p();d=!1,e.A(2)})()}),150)};return r.P=o,r})(),h=()=>{c=i(),d&&(_=!0),s&&e.A(6,s()),e.A(1,r()),p()},g=t=>{if(a||0===e.B()||t.ctrlKey)return;const r=i()-c;150>r&&50<r&&(o?t.deltaX:t.deltaY)&&(a=!0)},m=()=>{u=!0,d=_=!1},v=()=>{u=!1,I()&&(d=!0)};return t.addEventListener("scroll",h),t.addEventListener("wheel",g,{passive:!0}),t.addEventListener("touchstart",m,{passive:!0}),t.addEventListener("touchend",v,{passive:!0}),{L:()=>{t.removeEventListener("scroll",h),t.removeEventListener("wheel",g),t.removeEventListener("touchstart",m),t.removeEventListener("touchend",v),p.P()},W:()=>{const[t,s]=e.M();t&&(n(N(t,o),s,_),_=!1,s&&e.R()>e.T()&&e.A(1,r()))}}},q=/*#__PURE__*/e({props:{X:{type:Object,required:!0},Y:{type:Function,required:!0},F:{type:Number,required:!0},U:{type:Number,required:!0},V:{type:Boolean},G:{type:Boolean},K:{type:Boolean},Z:{type:String,required:!0}},setup(e){const s=t();return o((()=>s.value&&e.F),((t,o,r)=>{r(e.Y(s.value,e.F))}),{flush:"post"}),()=>{const{X:t,U:o,V:i,G:l,K:c,Z:a}=e,u={margin:0,padding:0,position:i&&c?void 0:"absolute",[l?"height":"width"]:"100%",[l?"top":"left"]:"0px",[l?O()?"right":"left":"top"]:o+"px",visibility:!i||c?"visible":"hidden"};return l&&(u.display="flex"),r(a,{ref:s,style:u},"function"==typeof(f=t)||"[object Object]"===Object.prototype.toString.call(f)&&!n(f)?t:{default:()=>[t],_:2},8,["style"]);var f}}}),E=(e,t)=>{const o=e.key;return o!=l?o:"_"+t},M=/*#__PURE__*/e({props:{data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,startMargin:{type:Number,default:0},ssrCount:Number,scrollRef:Object,as:{type:String,default:"div"},item:{type:String,default:"div"}},emits:["scroll","scrollEnd","rangeChange"],setup(e,{emit:c,expose:u,slots:p}){var h;let g=!!e.ssrCount;const m=e.horizontal,v=t(),b=B(e.data.length,null!==(h=e.itemSize)&&void 0!==h?h:40,e.ssrCount,0,!e.itemSize),y=((e,t)=>{let o;const r=t?"width":"height",n=new WeakMap,s=R((t=>{const s=[];for(const{target:i,contentRect:c}of t)if(i.offsetParent)if(i===o)e.A(4,c[r]);else{const e=n.get(i);e!=l&&s.push([e,c[r]])}s.length&&e.A(3,s)}));return{$(e){s.J(o=e)},ee:(e,t)=>(n.set(e,t),s.J(e),()=>{n.delete(e),s.D(e)}),L:s.L}})(b,m),S=((e,t)=>{let o,r,n;const s=t?"scrollLeft":"scrollTop",i=t?"overflowX":"overflowY",l=async(r,i)=>{if(!o)return void _((()=>l(r,i)));n&&n();const c=()=>{let t;return[new Promise(((o,r)=>{t=o,n=r,e.S()&&f(r,150)})),e.H(2,(()=>{t&&t()}))]};if(i&&C()){for(;e.A(8,r()),e.k();){const[e,t]=c();try{await e}catch(e){return}finally{t()}}o.scrollTo({[t?"left":"top"]:N(r(),t),behavior:"smooth"})}else for(;;){const[n,i]=c();try{o[s]=N(r(),t),e.A(7),await n}catch(e){return}finally{i()}}};return{J(l){o=l,r=T(e,l,t,(()=>N(l[s],t)),((t,o,r)=>{if(r){const e=l.style,t=e[i];e[i]="hidden",f((()=>{e[i]=t}))}o?(l[s]=e.j()+t,n&&n()):l[s]+=t}))},L(){r&&r.L()},te(e){l((()=>e))},oe(t){t+=e.j(),l((()=>t))},re(t,{align:o,smooth:r,offset:n=0}={}){if(t=d(t,0,e.C()-1),"nearest"===o){const r=e.O(t),n=e.j();if(r<n)o="start";else{if(!(r+e.I(t)>n+e.R()))return;o="end"}}l((()=>n+e.N()+e.O(t)+("end"===o?e.I(t)-e.R():"center"===o?(e.I(t)-e.R())/2:0)),r)},W:()=>{r&&r.W()}}})(b,m),z=t(b.p()),w=b.H(1,(()=>{z.value=b.p()})),x=b.H(4,(()=>{c("scroll",b.j())})),k=b.H(8,(()=>{c("scrollEnd")}));return s((()=>{g=!1,_((()=>{const t=e=>{y.$(e),S.J(e)};e.scrollRef?t(e.scrollRef):t(v.value.parentElement)}))})),i((()=>{w(),x(),k(),y.L(),S.L()})),o((()=>e.data.length),(t=>{b.A(5,[t,e.shift])})),o((()=>e.startMargin),(e=>{b.A(6,e)}),{immediate:!0}),o([z,b.q],(([,e],[,t])=>{e!==t&&S.W()}),{flush:"post"}),o([z,b.m],(([,[e,t]],[,[o,r]])=>{o===e&&r===t||c("rangeChange",e,t)}),{flush:"post"}),u({get scrollOffset(){return b.j()},get scrollSize(){return(e=>a(e.T(),e.R()))(b)},get viewportSize(){return b.R()},getItemOffset:b.O,scrollToIndex:S.re,scrollTo:S.te,scrollBy:S.oe}),()=>{z.value;const t=e.as,o=e.item,s=e.data.length,[i,l]=b.m(),c=b.B(),a=b.T(),u=[];for(let[t,n]=j(i,l,e.overscan,c,s);t<=n;t++){const n=p.default(e.data[t])[0];u.push(r(q,{key:E(n,t),Y:y.ee,F:t,U:b.O(t),V:b.v(t),X:n,G:m,K:g,Z:o},null,8,["Y","F","U","V","X","G","K","Z"]))}return r(t,{ref:v,style:{overflowAnchor:"none",flex:"none",position:"relative",visibility:"hidden",width:m?a+"px":"100%",height:m?"100%":a+"px",pointerEvents:0!==c?"none":"auto"}},"function"==typeof(f=u)||"[object Object]"===Object.prototype.toString.call(f)&&!n(f)?u:{default:()=>[u],_:2},8,["style"]);var f}}}),H=/*#__PURE__*/e({props:{data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,ssrCount:Number},emits:["scroll","scrollEnd","rangeChange"],setup(e,{emit:o,expose:s,slots:i}){const l=e.horizontal,c=e=>{o("scroll",e)},a=()=>{o("scrollEnd")},u=(e,t)=>{o("rangeChange",e,t)},f=t();return s({get scrollOffset(){return f.value.scrollOffset},get scrollSize(){return f.value.scrollSize},get viewportSize(){return f.value.viewportSize},getItemOffset:(...e)=>f.value.getItemOffset(...e),scrollToIndex:(...e)=>f.value.scrollToIndex(...e),scrollTo:(...e)=>f.value.scrollTo(...e),scrollBy:(...e)=>f.value.scrollBy(...e)}),()=>{return r("div",{style:{display:l?"inline-block":"block",[l?"overflowX":"overflowY"]:"auto",contain:"strict",width:"100%",height:"100%"}},[r(M,{ref:f,data:e.data,overscan:e.overscan,itemSize:e.itemSize,shift:e.shift,ssrCount:e.ssrCount,horizontal:l,onScroll:c,onScrollEnd:a,onRangeChange:u},(t=i,"function"==typeof t||"[object Object]"===Object.prototype.toString.call(t)&&!n(t)?i:{default:()=>[i],_:2}),8,["data","overscan","itemSize","shift","ssrCount","horizontal","onScroll","onScrollEnd","onRangeChange"])],4);var t}}}),A=/*#__PURE__*/e({props:{data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,as:{type:String,default:"div"},item:{type:String,default:"div"}},emits:["scrollEnd","rangeChange"],setup(e,{emit:c,slots:a}){var u;const f=e.horizontal,d=t(),_=B(e.data.length,null!==(u=e.itemSize)&&void 0!==u?u:40,void 0,0,!e.itemSize),p=((e,t)=>{const o=t?"width":"height",r=t?"innerWidth":"innerHeight",n=new WeakMap,s=R((t=>{const r=[];for(const{target:e,contentRect:s}of t){if(!e.offsetParent)continue;const t=n.get(e);t!=l&&r.push([t,s[o]])}r.length&&e.A(3,r)}));let i;return{$(t){const o=k(x(t)),n=()=>{e.A(4,o[r])};o.addEventListener("resize",n),n(),i=()=>{o.removeEventListener("resize",n)}},ee:(e,t)=>(n.set(e,t),s.J(e),()=>{n.delete(e),s.D(e)}),L(){i&&i(),s.L()}}})(_,f),h=((e,t)=>{let o;return{J(r){const n=t?"scrollX":"scrollY",s=x(r),i=k(s),l=s.body,c=(e,t,o,r=0)=>{const n=o?"offsetLeft":"offsetTop",s=r+(o&&O()?i.innerWidth-e[n]-e.offsetWidth:e[n]),l=e.offsetParent;return e!==t&&l?c(l,t,o,s):s};o=T(e,i,t,(()=>N(i[n],t)),((o,r)=>{r?i.scroll({[t?"left":"top"]:e.j()+o}):i.scrollBy(t?o:0,t?0:o)}),(()=>c(r,l,t)))},L(){o&&o.L()},W:()=>{o&&o.W()}}})(_,f),g=t(_.p()),m=_.H(1,(()=>{g.value=_.p()})),v=_.H(8,(()=>{c("scrollEnd")}));return s((()=>{const e=d.value;e&&(p.$(e),h.J(e))})),i((()=>{m(),v(),p.L(),h.L()})),o((()=>e.data.length),(t=>{_.A(5,[t,e.shift])})),o([g,_.q],(([,e],[,t])=>{e!==t&&h.W()}),{flush:"post"}),o([g,_.m],(([,[e,t]],[,[o,r]])=>{o===e&&r===t||c("rangeChange",e,t)}),{flush:"post"}),()=>{g.value;const t=e.as,o=e.item,s=e.data.length,[i,l]=_.m(),c=_.B(),u=_.T(),h=[];for(let[t,n]=j(i,l,e.overscan,c,s);t<=n;t++){const n=a.default(e.data[t])[0];h.push(r(q,{key:E(n,t),Y:p.ee,F:t,U:_.O(t),V:_.v(t),X:n,G:f,Z:o},null,8,["Y","F","U","V","X","G","Z"]))}return r(t,{ref:d,style:{overflowAnchor:"none",flex:"none",position:"relative",visibility:"hidden",width:f?u+"px":"100%",height:f?"100%":u+"px",pointerEvents:0!==c?"none":"auto"}},"function"==typeof(m=h)||"[object Object]"===Object.prototype.toString.call(m)&&!n(m)?h:{default:()=>[h],_:2},8,["style"]);var m}}});export{H as VList,M as Virtualizer,A as WindowVirtualizer};
1
+ import{defineComponent as e,ref as t,watch as o,createVNode as r,isVNode as n,onMounted as s,onUnmounted as i}from"vue";const l=null,c=Math.min,a=Math.max,u=Math.abs,f=setTimeout,d=(e,t,o)=>c(o,a(t,e)),_="function"==typeof queueMicrotask?queueMicrotask:e=>{Promise.resolve().then(e)},p=e=>{let t,o;return(...r)=>(t||(t=!0,o=e(...r)),o)},h=-1,g=(e,t,o)=>{const r=o?"unshift":"push";for(let o=0;o<t;o++)e[r](h);return e},m=(e,t)=>{const o=e.t[t];return o===h?e.o:o},v=(e,t,o)=>{const r=e.t[t]===h;return e.t[t]=o,e.i=c(t,e.i),r},b=(e,t)=>{if(!e.l)return 0;if(e.i>=t)return e.u[t];e.i<0&&(e.u[0]=0,e.i=0);let o=e.i,r=e.u[o];for(;o<t;)r+=m(e,o),e.u[++o]=r;return e.i=t,r},y=(e,t,o)=>{for(;o>=0&&o<e.l;){const r=b(e,o);if(r<=t){if(r+m(e,o)>t)break;o++}else o--}return d(o,0,e.l-1)},S=(e,t,o)=>{const r=t-e.l;return e.i=o?-1:c(t-1,e.i),e.l=t,r>0?(g(e.u,r),g(e.t,r,o),e.o*r):(e.u.splice(r),(o?e.t.splice(0,-r):e.t.splice(r)).reduce(((t,o)=>t-(o===h?e.o:o)),0))},z="undefined"!=typeof window,w=()=>document.documentElement,x=e=>e.ownerDocument,k=e=>e.defaultView,O=/*#__PURE__*/p((()=>!!z&&"rtl"===getComputedStyle(w()).direction)),I=/*#__PURE__*/p((()=>/iP(hone|od|ad)/.test(navigator.userAgent))),C=/*#__PURE__*/p((()=>"scrollBehavior"in w().style)),j=(e,t,o,r,n)=>(1!==r&&(e-=a(0,o)),2!==r&&(t+=a(0,o)),[a(e,0),c(t,n-1)]),B=(e,t=40,o=0,r,n=!1)=>{let s=!!o,i=[],f=0,d=0,_=0,p=0,z=0,w=0,x=0,k=0,O=0,C=s?[0,a(o-1,0)]:l,j=[0,0],B=0;const R=((e,t)=>({o:t,t:g([],e),l:e,i:-1,u:g([],e)}))(e,t),N=new Set,T=()=>_-d,q=e=>((e,t,o,r)=>{const n=y(e,t,c(o,e.l-1));return[n,y(e,t+r,n)]})(R,e,j[0],f),E=()=>(e=>e.l?b(e,e.l-1)+m(e,e.l-1):0)(R),M=e=>b(R,e)-w,H=e=>m(R,e),A=e=>{e&&(I()&&0!==k?w+=e:(z+=e,p++))};return{p:()=>i,h:()=>(e=>[[...e.t],e.o])(R),m:()=>x?j:(j=q(a(0,T()+w+z)),C?[c(j[0],C[0]),a(j[1],C[1])]:j),v:e=>R.t[e]===h,S:()=>!!f,k:()=>!!C&&R.t.slice(a(0,C[0]-1),c(R.l-1,C[1]+1)+1).includes(h),O:M,I:H,C:()=>R.l,j:()=>_,B:()=>k,R:()=>f,N:()=>d,T:E,q:()=>p,M:()=>(x=z,z=0,[x,2===O||T()+f>=E()]),H(e,t){const o=[e,t];return N.add(o),()=>{N.delete(o)}},A(e,t){let o,r,c=0;switch(e){case 1:{const e=x;x=0;const o=t-_,n=u(o);e&&n<u(e)+1||0!==O||(k=o<0?2:1),s&&(C=l,s=!1),_=t,c=4;const i=T();i>=-f&&i<=E()&&(c+=1,r=n>f);break}case 2:c=8,0!==k&&(o=!0,c+=1),k=0,O=0,C=l;break;case 3:{const e=t.filter((([e,t])=>R.t[e]!==t));if(!e.length)break;A(e.reduce(((e,[t,o])=>((2===O||(C?t<C[0]:M(t)+(0===k&&0===O?H(t):0)<T()))&&(e+=o-H(t)),e)),0));for(const[t,o]of e){const e=H(t),r=v(R,t,o);n&&(B+=r?o:o-e)}n&&f&&B>f&&(A(((e,t)=>{let o=0;const r=e.t.filter(((e,r)=>{const n=e!==h;return n&&r<t&&o++,n})),n=e.o;return e.i=-1,((e.o=(e=>{const t=(e=>[...e].sort(((e,t)=>e-t)))(e),o=e.length/2|0;return t.length%2==0?(t[o-1]+t[o])/2:t[o]})(r))-n)*a(t-o,0)})(R,j[0])),n=!1),c=3,r=!0;break}case 4:f!==t&&(f=t,c=3);break;case 5:t[1]?(A(S(R,t[0],!0)),O=2,c=1):S(R,t[0]);break;case 6:d=t;break;case 7:O=1;break;case 8:C=q(t),c=1}c&&(i=[],o&&w&&(z+=w,w=0,p++),N.forEach((([e,t])=>{c&e&&t(r)})))}}},R=e=>{let t;return{J(o){(t||(t=new(k(x(o)).ResizeObserver)(e))).observe(o)},D(e){t.unobserve(e)},L(){t&&t.disconnect()}}},N=(e,t)=>t&&O()?-e:e,T=(e,t,o,r,n,s)=>{const i=Date.now;let c=0,a=!1,u=!1,d=!1,_=!1;const p=(()=>{let t;const o=()=>{t!=l&&clearTimeout(t)},r=()=>{o(),t=f((()=>{t=l,(()=>{if(a||u)return a=!1,void p();d=!1,e.A(2)})()}),150)};return r.P=o,r})(),h=()=>{c=i(),d&&(_=!0),s&&e.A(6,s()),e.A(1,r()),p()},g=t=>{if(a||0===e.B()||t.ctrlKey)return;const r=i()-c;150>r&&50<r&&(o?t.deltaX:t.deltaY)&&(a=!0)},m=()=>{u=!0,d=_=!1},v=()=>{u=!1,I()&&(d=!0)};return t.addEventListener("scroll",h),t.addEventListener("wheel",g,{passive:!0}),t.addEventListener("touchstart",m,{passive:!0}),t.addEventListener("touchend",v,{passive:!0}),{L:()=>{t.removeEventListener("scroll",h),t.removeEventListener("wheel",g),t.removeEventListener("touchstart",m),t.removeEventListener("touchend",v),p.P()},W:()=>{const[t,s]=e.M();t&&(n(N(t,o),s,_),_=!1,s&&e.R()>e.T()&&e.A(1,r()))}}},q=/*#__PURE__*/e({props:{X:{type:Object,required:!0},Y:{type:Function,required:!0},F:{type:Number,required:!0},U:{type:Number,required:!0},V:{type:Boolean},G:{type:Boolean},K:{type:Boolean},Z:{type:String,required:!0}},setup(e){const s=t();return o((()=>s.value&&e.F),((t,o,r)=>{r(e.Y(s.value,e.F))}),{flush:"post"}),()=>{const{X:t,U:o,V:i,G:l,K:c,Z:a}=e,u={margin:0,padding:0,position:i&&c?void 0:"absolute",[l?"height":"width"]:"100%",[l?"top":"left"]:"0px",[l?O()?"right":"left":"top"]:o+"px",visibility:!i||c?"visible":"hidden"};return l&&(u.display="flex"),r(a,{ref:s,style:u},"function"==typeof(f=t)||"[object Object]"===Object.prototype.toString.call(f)&&!n(f)?t:{default:()=>[t],_:2},8,["style"]);var f}}}),E=(e,t)=>{const o=e.key;return o!=l?o:"_"+t},M=/*#__PURE__*/e({props:{data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,startMargin:{type:Number,default:0},ssrCount:Number,scrollRef:Object,as:{type:String,default:"div"},item:{type:String,default:"div"}},emits:["scroll","scrollEnd","rangeChange"],setup(e,{emit:c,expose:u,slots:p}){var h;let g=!!e.ssrCount;const m=e.horizontal,v=t(),b=B(e.data.length,null!==(h=e.itemSize)&&void 0!==h?h:40,e.ssrCount,0,!e.itemSize),y=((e,t)=>{let o;const r=t?"width":"height",n=new WeakMap,s=R((t=>{const s=[];for(const{target:i,contentRect:c}of t)if(i.offsetParent)if(i===o)e.A(4,c[r]);else{const e=n.get(i);e!=l&&s.push([e,c[r]])}s.length&&e.A(3,s)}));return{$(e){s.J(o=e)},ee:(e,t)=>(n.set(e,t),s.J(e),()=>{n.delete(e),s.D(e)}),L:s.L}})(b,m),S=((e,t)=>{let o,r,n;const s=t?"scrollLeft":"scrollTop",i=t?"overflowX":"overflowY",l=async(r,i)=>{if(!o)return void _((()=>l(r,i)));n&&n();const c=()=>{let t;return[new Promise(((o,r)=>{t=o,n=r,e.S()&&f(r,150)})),e.H(2,(()=>{t&&t()}))]};if(i&&C()){for(;e.A(8,r()),e.k();){const[e,t]=c();try{await e}catch(e){return}finally{t()}}o.scrollTo({[t?"left":"top"]:N(r(),t),behavior:"smooth"})}else for(;;){const[n,i]=c();try{o[s]=N(r(),t),e.A(7),await n}catch(e){return}finally{i()}}};return{J(l){o=l,r=T(e,l,t,(()=>N(l[s],t)),((t,o,r)=>{if(r){const e=l.style,t=e[i];e[i]="hidden",f((()=>{e[i]=t}))}o?(l[s]=e.j()+t,n&&n()):l[s]+=t}))},L(){r&&r.L()},te(e){l((()=>e))},oe(t){t+=e.j(),l((()=>t))},re(t,{align:o,smooth:r,offset:n=0}={}){if(t=d(t,0,e.C()-1),"nearest"===o){const r=e.O(t),n=e.j();if(r<n)o="start";else{if(!(r+e.I(t)>n+e.R()))return;o="end"}}l((()=>n+e.N()+e.O(t)+("end"===o?e.I(t)-e.R():"center"===o?(e.I(t)-e.R())/2:0)),r)},W:()=>{r&&r.W()}}})(b,m),z=t(b.p()),w=b.H(1,(()=>{z.value=b.p()})),x=b.H(4,(()=>{c("scroll",b.j())})),k=b.H(8,(()=>{c("scrollEnd")}));return s((()=>{g=!1,_((()=>{const t=e=>{y.$(e),S.J(e)};e.scrollRef?t(e.scrollRef):t(v.value.parentElement)}))})),i((()=>{w(),x(),k(),y.L(),S.L()})),o((()=>e.data.length),(t=>{b.A(5,[t,e.shift])})),o((()=>e.startMargin),(e=>{b.A(6,e)}),{immediate:!0}),o([z,b.q],(([,e],[,t])=>{e!==t&&S.W()}),{flush:"post"}),o([z,b.m],(([,[e,t]],[,[o,r]])=>{o===e&&r===t||c("rangeChange",e,t)}),{flush:"post"}),u({get scrollOffset(){return b.j()},get scrollSize(){return(e=>a(e.T(),e.R()))(b)},get viewportSize(){return b.R()},getItemOffset:b.O,scrollToIndex:S.re,scrollTo:S.te,scrollBy:S.oe}),()=>{z.value;const t=e.as,o=e.item,s=e.data.length,[i,l]=b.m(),c=b.B(),a=b.T(),u=[];for(let[t,n]=j(i,l,e.overscan,c,s);t<=n;t++){const n=p.default({item:e.data[t],index:t})[0];u.push(r(q,{key:E(n,t),Y:y.ee,F:t,U:b.O(t),V:b.v(t),X:n,G:m,K:g,Z:o},null,8,["Y","F","U","V","X","G","K","Z"]))}return r(t,{ref:v,style:{overflowAnchor:"none",flex:"none",position:"relative",visibility:"hidden",width:m?a+"px":"100%",height:m?"100%":a+"px",pointerEvents:0!==c?"none":"auto"}},"function"==typeof(f=u)||"[object Object]"===Object.prototype.toString.call(f)&&!n(f)?u:{default:()=>[u],_:2},8,["style"]);var f}}}),H=/*#__PURE__*/e({props:{data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,ssrCount:Number},emits:["scroll","scrollEnd","rangeChange"],setup(e,{emit:o,expose:s,slots:i}){const l=e.horizontal,c=e=>{o("scroll",e)},a=()=>{o("scrollEnd")},u=(e,t)=>{o("rangeChange",e,t)},f=t();return s({get scrollOffset(){return f.value.scrollOffset},get scrollSize(){return f.value.scrollSize},get viewportSize(){return f.value.viewportSize},getItemOffset:(...e)=>f.value.getItemOffset(...e),scrollToIndex:(...e)=>f.value.scrollToIndex(...e),scrollTo:(...e)=>f.value.scrollTo(...e),scrollBy:(...e)=>f.value.scrollBy(...e)}),()=>{return r("div",{style:{display:l?"inline-block":"block",[l?"overflowX":"overflowY"]:"auto",contain:"strict",width:"100%",height:"100%"}},[r(M,{ref:f,data:e.data,overscan:e.overscan,itemSize:e.itemSize,shift:e.shift,ssrCount:e.ssrCount,horizontal:l,onScroll:c,onScrollEnd:a,onRangeChange:u},(t=i,"function"==typeof t||"[object Object]"===Object.prototype.toString.call(t)&&!n(t)?i:{default:()=>[i],_:2}),8,["data","overscan","itemSize","shift","ssrCount","horizontal","onScroll","onScrollEnd","onRangeChange"])],4);var t}}}),A=/*#__PURE__*/e({props:{data:{type:Array,required:!0},overscan:{type:Number,default:4},itemSize:Number,shift:Boolean,horizontal:Boolean,as:{type:String,default:"div"},item:{type:String,default:"div"}},emits:["scrollEnd","rangeChange"],setup(e,{emit:c,slots:a}){var u;const f=e.horizontal,d=t(),_=B(e.data.length,null!==(u=e.itemSize)&&void 0!==u?u:40,void 0,0,!e.itemSize),p=((e,t)=>{const o=t?"width":"height",r=t?"innerWidth":"innerHeight",n=new WeakMap,s=R((t=>{const r=[];for(const{target:e,contentRect:s}of t){if(!e.offsetParent)continue;const t=n.get(e);t!=l&&r.push([t,s[o]])}r.length&&e.A(3,r)}));let i;return{$(t){const o=k(x(t)),n=()=>{e.A(4,o[r])};o.addEventListener("resize",n),n(),i=()=>{o.removeEventListener("resize",n)}},ee:(e,t)=>(n.set(e,t),s.J(e),()=>{n.delete(e),s.D(e)}),L(){i&&i(),s.L()}}})(_,f),h=((e,t)=>{let o;return{J(r){const n=t?"scrollX":"scrollY",s=x(r),i=k(s),l=s.body,c=(e,t,o,r=0)=>{const n=o?"offsetLeft":"offsetTop",s=r+(o&&O()?i.innerWidth-e[n]-e.offsetWidth:e[n]),l=e.offsetParent;return e!==t&&l?c(l,t,o,s):s};o=T(e,i,t,(()=>N(i[n],t)),((o,r)=>{r?i.scroll({[t?"left":"top"]:e.j()+o}):i.scrollBy(t?o:0,t?0:o)}),(()=>c(r,l,t)))},L(){o&&o.L()},W:()=>{o&&o.W()}}})(_,f),g=t(_.p()),m=_.H(1,(()=>{g.value=_.p()})),v=_.H(8,(()=>{c("scrollEnd")}));return s((()=>{const e=d.value;e&&(p.$(e),h.J(e))})),i((()=>{m(),v(),p.L(),h.L()})),o((()=>e.data.length),(t=>{_.A(5,[t,e.shift])})),o([g,_.q],(([,e],[,t])=>{e!==t&&h.W()}),{flush:"post"}),o([g,_.m],(([,[e,t]],[,[o,r]])=>{o===e&&r===t||c("rangeChange",e,t)}),{flush:"post"}),()=>{g.value;const t=e.as,o=e.item,s=e.data.length,[i,l]=_.m(),c=_.B(),u=_.T(),h=[];for(let[t,n]=j(i,l,e.overscan,c,s);t<=n;t++){const n=a.default({item:e.data[t],index:t})[0];h.push(r(q,{key:E(n,t),Y:p.ee,F:t,U:_.O(t),V:_.v(t),X:n,G:f,Z:o},null,8,["Y","F","U","V","X","G","Z"]))}return r(t,{ref:d,style:{overflowAnchor:"none",flex:"none",position:"relative",visibility:"hidden",width:f?u+"px":"100%",height:f?"100%":u+"px",pointerEvents:0!==c?"none":"auto"}},"function"==typeof(m=h)||"[object Object]"===Object.prototype.toString.call(m)&&!n(m)?h:{default:()=>[h],_:2},8,["style"]);var m}}});export{H as VList,M as Virtualizer,A as WindowVirtualizer};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../src/src/core/utils.ts","../../src/src/core/cache.ts","../../src/src/core/environment.ts","../../src/src/core/store.ts","../../src/src/core/resizer.ts","../../src/src/core/scroller.ts","../../src/src/vue/ListItem.tsx","../../src/src/vue/utils.ts","../../src/src/vue/Virtualizer.tsx","../../src/src/vue/VList.tsx","../../src/src/vue/WindowVirtualizer.tsx"],"sourcesContent":["/** @internal */\nexport const NULL = null;\n\n/** @internal */\nexport const min = Math.min;\n/** @internal */\nexport const max = Math.max;\n/** @internal */\nexport const abs = Math.abs;\n/** @internal */\nexport const values = Object.values;\n/** @internal */\nexport const isArray = Array.isArray;\n/** @internal */\nexport const timeout = setTimeout;\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 median = (arr: number[]): number => {\n const sorted = sort(arr);\n const mid = (arr.length / 2) | 0;\n return sorted.length % 2 === 0\n ? (sorted[mid - 1]! + sorted[mid]!) / 2\n : sorted[mid]!;\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 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 * @internal\n */\nexport const once = <F extends (...args: any[]) => any>(fn: F): F => {\n let called: undefined | boolean;\n let cache: ReturnType<F>;\n\n return ((...args) => {\n if (!called) {\n called = true;\n cache = fn(...args);\n }\n return cache;\n }) as F;\n};\n\n/**\n * @internal\n */\nexport const getStyleNumber = (v: string): number => {\n if (v) {\n return parseFloat(v);\n } else {\n return 0;\n }\n};\n","import { type InternalCacheSnapshot, type ItemsRange } from \"./types\";\nimport { clamp, max, median, min } 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 * @internal\n */\nexport const findIndex = (cache: Cache, offset: number, i: number): number => {\n while (i >= 0 && i < cache._length) {\n const itemOffset = computeOffset(cache, i);\n if (itemOffset <= offset) {\n if (itemOffset + getItemSize(cache, i) > offset) {\n break;\n } else {\n i++;\n }\n } else {\n i--;\n }\n }\n return clamp(i, 0, cache._length - 1);\n};\n\n/**\n * @internal\n */\nexport const computeRange = (\n cache: Cache,\n scrollOffset: number,\n prevStartIndex: number,\n viewportSize: number\n): ItemsRange => {\n const start = findIndex(\n cache,\n scrollOffset,\n // Clamp because prevStartIndex may exceed the limit when children decreased a lot after scrolling\n min(prevStartIndex, cache._length - 1)\n );\n return [start, findIndex(cache, scrollOffset + viewportSize, start)];\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 = cache._sizes.filter((s, i) => {\n const isMeasured = s !== UNCACHED;\n if (isMeasured && i < startIndex) {\n measuredCountBeforeStart++;\n }\n return isMeasured;\n });\n const prevDefaultItemSize = cache._defaultItemSize;\n\n // Discard cache for now\n cache._computedOffsetIndex = -1;\n\n // Calculate diff of unmeasured items before start\n return (\n ((cache._defaultItemSize = median(measuredSizes)) - 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], 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} 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\n/** @internal */\nexport const SCROLL_IDLE = 0;\n/** @internal */\nexport const SCROLL_DOWN = 1;\n/** @internal */\nexport const SCROLL_UP = 2;\n/** @internal */\nexport type 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 getOverscanedRange = (\n startIndex: number,\n endIndex: number,\n overscan: number,\n scrollDirection: ScrollDirection,\n count: number\n): ItemsRange => {\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, count - 1)];\n};\n\ntype Subscriber = (sync?: boolean) => void;\n\n/** @internal */\nexport type StateVersion = readonly [];\n\n/**\n * @internal\n */\nexport type VirtualStore = {\n _getStateVersion(): StateVersion;\n _getCacheSnapshot(): CacheSnapshot;\n _getRange(): ItemsRange;\n _isUnmeasuredItem(index: number): boolean;\n _isInitialMeasurementDone(): boolean;\n _hasUnmeasuredItemsInFrozenRange(): boolean;\n _getItemOffset(index: number): number;\n _getItemSize(index: number): number;\n _getItemsLength(): number;\n _getScrollOffset(): number;\n _getScrollDirection(): ScrollDirection;\n _getViewportSize(): number;\n _getStartSpacerSize(): number;\n _getTotalSize(): number;\n _getJumpCount(): number;\n _flushJump(): [number, boolean];\n _subscribe(target: number, cb: Subscriber): () => void;\n _update(...action: Actions): void;\n};\n\n/**\n * @internal\n */\nexport const createVirtualStore = (\n elementsCount: number,\n itemSize: number = 40,\n ssrCount: number = 0,\n cacheSnapshot?: CacheSnapshot | undefined,\n shouldAutoEstimateItemSize: boolean = false\n): VirtualStore => {\n let isSSR = !!ssrCount;\n let stateVersion: StateVersion = [];\n let viewportSize = 0;\n let startSpacerSize = 0;\n let scrollOffset = 0;\n let jumpCount = 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 getRange = (offset: number) => {\n return computeRange(cache, offset, _prevRange[0], viewportSize);\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 jumpCount++;\n }\n }\n };\n\n return {\n _getStateVersion() {\n return stateVersion;\n },\n _getCacheSnapshot() {\n return takeCacheSnapshot(cache) as unknown as CacheSnapshot;\n },\n _getRange() {\n // Return previous range for consistent render until next scroll event comes in.\n if (_flushedJump) {\n return _prevRange;\n }\n _prevRange = getRange(\n max(0, getRelativeScrollOffset() + pendingJump + jump)\n );\n\n if (_frozenRange) {\n return [\n min(_prevRange[0], _frozenRange[0]),\n max(_prevRange[1], _frozenRange[1]),\n ];\n }\n return _prevRange;\n },\n _isUnmeasuredItem(index) {\n return cache._sizes[index] === UNCACHED;\n },\n _isInitialMeasurementDone() {\n return !!viewportSize;\n },\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() {\n return cache._length;\n },\n _getScrollOffset() {\n return scrollOffset;\n },\n _getScrollDirection() {\n return _scrollDirection;\n },\n _getViewportSize() {\n return viewportSize;\n },\n _getStartSpacerSize() {\n return startSpacerSize;\n },\n _getTotalSize: getTotalSize,\n _getJumpCount() {\n return jumpCount;\n },\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 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(estimateDefaultItemSize(cache, _prevRange[0]));\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 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 }\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 = [];\n\n if (shouldFlushPendingJump && pendingJump) {\n jump += pendingJump;\n pendingJump = 0;\n jumpCount++;\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 { 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","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 SCROLL_IDLE,\n ACTION_BEFORE_MANUAL_SMOOTH_SCROLL,\n ACTION_START_OFFSET_CHANGE,\n} from \"./store\";\nimport { type ScrollToIndexOpts } from \"./types\";\nimport { debounce, timeout, clamp, microtask } from \"./utils\";\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._getScrollDirection() === SCROLL_IDLE ||\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 (store._isInitialMeasurementDone()) {\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 _fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createWindowScroller = (\n store: VirtualStore,\n isHorizontal: boolean\n): WindowScroller => {\n let scrollObserver: ScrollObserver | undefined;\n\n return {\n _observe(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 const calcOffsetToViewport = (\n node: HTMLElement,\n viewport: HTMLElement,\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 isHorizontal,\n offsetSum\n );\n };\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 () => calcOffsetToViewport(container, documentBody, isHorizontal)\n );\n },\n _dispose() {\n scrollObserver && scrollObserver._dispose();\n },\n _fixScrollJump: () => {\n scrollObserver && scrollObserver._fixScrollJump();\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","/** @jsxImportSource vue */\nimport {\n ref,\n defineComponent,\n watch,\n StyleValue,\n PropType,\n VNode,\n NativeElements,\n} from \"vue\";\nimport { ItemResizeObserver } from \"../core/resizer\";\nimport { isRTLDocument } from \"../core/environment\";\n\n/**\n * @internal\n */\nexport const ListItem = /*#__PURE__*/ defineComponent({\n props: {\n _children: { type: Object as PropType<VNode>, required: true },\n _resizer: {\n type: Function as PropType<ItemResizeObserver>,\n required: true,\n },\n _index: { type: Number, required: true },\n _offset: { type: Number, required: true },\n _hide: { type: Boolean },\n _isHorizontal: { type: Boolean },\n _isSSR: { type: Boolean },\n _as: { type: String as PropType<keyof NativeElements>, required: true },\n },\n setup(props) {\n const elementRef = ref<HTMLDivElement>();\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n watch(\n () => elementRef.value && props._index,\n (_, __, onCleanup) => {\n onCleanup(props._resizer(elementRef.value!, props._index));\n },\n {\n flush: \"post\",\n }\n );\n\n return () => {\n const {\n _children: children,\n _offset: offset,\n _hide: hide,\n _isHorizontal: isHorizontal,\n _isSSR: isSSR,\n _as: Element,\n } = props;\n\n const style: StyleValue = {\n margin: 0,\n padding: 0,\n position: hide && isSSR ? undefined : \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : \"left\"]: \"0px\",\n [isHorizontal ? (isRTLDocument() ? \"right\" : \"left\") : \"top\"]:\n offset + \"px\",\n visibility: !hide || isSSR ? \"visible\" : \"hidden\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n\n return (\n <Element ref={elementRef} style={style}>\n {children}\n </Element>\n );\n };\n },\n});\n","import { VNode } from \"vue\";\nimport { NULL } from \"../core/utils\";\n\n/**\n * @internal\n */\nexport const getKey = (e: VNode, i: number): Exclude<VNode[\"key\"], null> => {\n const key = e.key;\n return key != NULL ? key : \"_\" + i;\n};\n","/** @jsxImportSource vue */\nimport {\n ref,\n onMounted,\n defineComponent,\n onUnmounted,\n VNode,\n watch,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n PropType,\n NativeElements,\n} from \"vue\";\nimport {\n SCROLL_IDLE,\n UPDATE_SCROLL_EVENT,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n getOverscanedRange,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n getScrollSize,\n ACTION_START_OFFSET_CHANGE,\n} from \"../core/store\";\nimport { createResizer } from \"../core/resizer\";\nimport { createScroller } from \"../core/scroller\";\nimport { ScrollToIndexOpts } from \"../core/types\";\nimport { ListItem } from \"./ListItem\";\nimport { getKey } from \"./utils\";\nimport { microtask } from \"../core/utils\";\n\nexport interface VirtualizerHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight or offsetWidth.\n */\n readonly viewportSize: number;\n /**\n * Get item offset from start.\n * @param index index of item\n */\n getItemOffset(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\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * If you put an element before virtualizer, you have to define its height with this prop.\n */\n startMargin: { type: Number, default: 0 },\n /**\n * A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated.\n */\n ssrCount: Number,\n /**\n * Reference to the scrollable element. The default will get the parent element of virtualizer.\n */\n scrollRef: Object as PropType<HTMLElement>,\n /**\n * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n} satisfies ComponentObjectPropsOptions;\n\nexport const Virtualizer = /*#__PURE__*/ defineComponent({\n props: props,\n emits: [\"scroll\", \"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, expose, slots }) {\n let isSSR = !!props.ssrCount;\n\n const isHorizontal = props.horizontal;\n const containerRef = ref<HTMLDivElement>();\n const store = createVirtualStore(\n props.data.length,\n props.itemSize ?? 40,\n props.ssrCount,\n undefined,\n !props.itemSize\n );\n const resizer = createResizer(store, isHorizontal);\n const scroller = createScroller(store, isHorizontal);\n\n const rerender = ref(store._getStateVersion());\n const unsubscribeStore = store._subscribe(UPDATE_VIRTUAL_STATE, () => {\n rerender.value = store._getStateVersion();\n });\n\n const unsubscribeOnScroll = store._subscribe(UPDATE_SCROLL_EVENT, () => {\n emit(\"scroll\", store._getScrollOffset());\n });\n const unsubscribeOnScrollEnd = store._subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n emit(\"scrollEnd\");\n }\n );\n\n onMounted(() => {\n isSSR = false;\n\n microtask(() => {\n const assignScrollableElement = (e: HTMLElement) => {\n resizer._observeRoot(e);\n scroller._observe(e);\n };\n if (props.scrollRef) {\n // parent's ref doesn't exist when onMounted is called\n assignScrollableElement(props.scrollRef!);\n } else {\n assignScrollableElement(containerRef.value!.parentElement!);\n }\n });\n });\n onUnmounted(() => {\n unsubscribeStore();\n unsubscribeOnScroll();\n unsubscribeOnScrollEnd();\n resizer._dispose();\n scroller._dispose();\n });\n\n watch(\n () => props.data.length,\n (count) => {\n store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n );\n watch(\n () => props.startMargin,\n (value) => {\n store._update(ACTION_START_OFFSET_CHANGE, value);\n },\n { immediate: true }\n );\n\n watch(\n [rerender, store._getJumpCount],\n ([, count], [, prevCount]) => {\n if (count === prevCount) return;\n\n scroller._fixScrollJump();\n },\n { flush: \"post\" }\n );\n\n watch(\n [rerender, store._getRange],\n ([, [start, end]], [, [prevStart, prevEnd]]) => {\n if (prevStart === start && prevEnd === end) return;\n\n emit(\"rangeChange\", start, end);\n },\n { flush: \"post\" }\n );\n\n expose({\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 getItemOffset: store._getItemOffset,\n scrollToIndex: scroller._scrollToIndex,\n scrollTo: scroller._scrollTo,\n scrollBy: scroller._scrollBy,\n } satisfies VirtualizerHandle);\n\n return () => {\n rerender.value;\n\n const Element = props.as;\n const ItemElement = props.item;\n const count = props.data.length;\n\n const [startIndex, endIndex] = store._getRange();\n const scrollDirection = store._getScrollDirection();\n const totalSize = store._getTotalSize();\n\n const items: VNode[] = [];\n for (\n let [i, j] = getOverscanedRange(\n startIndex,\n endIndex,\n props.overscan,\n scrollDirection,\n count\n );\n i <= j;\n i++\n ) {\n const e = slots.default(props.data![i]!)[0]! as VNode;\n items.push(\n <ListItem\n key={getKey(e, i)}\n _resizer={resizer._observeItem}\n _index={i}\n _offset={store._getItemOffset(i)}\n _hide={store._isUnmeasuredItem(i)}\n _children={e}\n _isHorizontal={isHorizontal}\n _isSSR={isSSR}\n _as={ItemElement}\n />\n );\n }\n\n return (\n <Element\n ref={containerRef}\n style={{\n // contain: \"content\",\n overflowAnchor: \"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: isHorizontal ? totalSize + \"px\" : \"100%\",\n height: isHorizontal ? \"100%\" : totalSize + \"px\",\n pointerEvents: scrollDirection !== SCROLL_IDLE ? \"none\" : \"auto\",\n }}\n >\n {items}\n </Element>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n VirtualizerHandle,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n scroll: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: any }>\n>);\n","/** @jsxImportSource vue */\nimport {\n defineComponent,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n ref,\n} from \"vue\";\nimport { Virtualizer, VirtualizerHandle } from \"./Virtualizer\";\n\ninterface VListHandle extends VirtualizerHandle {}\n\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated.\n */\n ssrCount: Number,\n} satisfies ComponentObjectPropsOptions;\n\nexport const VList = /*#__PURE__*/ defineComponent({\n props: props,\n emits: [\"scroll\", \"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, expose, slots }) {\n const horizontal = props.horizontal;\n\n const onScroll = (offset: number) => {\n emit(\"scroll\", offset);\n };\n const onScrollEnd = () => {\n emit(\"scrollEnd\");\n };\n const onRangeChange = (start: number, end: number) => {\n emit(\"rangeChange\", start, end);\n };\n\n const handle = ref<InstanceType<typeof Virtualizer>>();\n\n expose({\n get scrollOffset() {\n return handle.value!.scrollOffset;\n },\n get scrollSize() {\n return handle.value!.scrollSize;\n },\n get viewportSize() {\n return handle.value!.viewportSize;\n },\n getItemOffset: (...args) => handle.value!.getItemOffset(...args),\n scrollToIndex: (...args) => handle.value!.scrollToIndex(...args),\n scrollTo: (...args) => handle.value!.scrollTo(...args),\n scrollBy: (...args) => handle.value!.scrollBy(...args),\n } satisfies VListHandle);\n\n return () => {\n return (\n <div\n style={{\n display: horizontal ? \"inline-block\" : \"block\",\n [horizontal ? \"overflowX\" : \"overflowY\"]: \"auto\",\n contain: \"strict\",\n width: \"100%\",\n height: \"100%\",\n }}\n >\n <Virtualizer\n ref={handle}\n data={props.data}\n overscan={props.overscan}\n itemSize={props.itemSize}\n shift={props.shift}\n ssrCount={props.ssrCount}\n horizontal={horizontal}\n onScroll={onScroll}\n onScrollEnd={onScrollEnd}\n onRangeChange={onRangeChange}\n >\n {slots}\n </Virtualizer>\n </div>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n VListHandle,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n scroll: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: any }>\n>);\n","/** @jsxImportSource vue */\nimport {\n ref,\n onMounted,\n defineComponent,\n onUnmounted,\n VNode,\n watch,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n PropType,\n NativeElements,\n} from \"vue\";\nimport {\n SCROLL_IDLE,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n getOverscanedRange,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n} from \"../core/store\";\nimport { createWindowResizer } from \"../core/resizer\";\nimport { createWindowScroller } from \"../core/scroller\";\nimport { ListItem } from \"./ListItem\";\nimport { getKey } from \"./utils\";\n\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n} satisfies ComponentObjectPropsOptions;\n\nexport const WindowVirtualizer = /*#__PURE__*/ defineComponent({\n props,\n emits: [\"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, slots }) {\n const isHorizontal = props.horizontal;\n const containerRef = ref<HTMLDivElement>();\n const store = createVirtualStore(\n props.data.length,\n props.itemSize ?? 40,\n undefined,\n undefined,\n !props.itemSize\n );\n const resizer = createWindowResizer(store, isHorizontal);\n const scroller = createWindowScroller(store, isHorizontal);\n\n const rerender = ref(store._getStateVersion());\n const unsubscribeStore = store._subscribe(UPDATE_VIRTUAL_STATE, () => {\n rerender.value = store._getStateVersion();\n });\n\n const unsubscribeOnScrollEnd = store._subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n emit(\"scrollEnd\");\n }\n );\n\n onMounted(() => {\n const el = containerRef.value;\n if (!el) return;\n resizer._observeRoot(el);\n scroller._observe(el);\n });\n onUnmounted(() => {\n unsubscribeStore();\n unsubscribeOnScrollEnd();\n resizer._dispose();\n scroller._dispose();\n });\n\n watch(\n () => props.data.length,\n (count) => {\n store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n );\n\n watch(\n [rerender, store._getJumpCount],\n ([, count], [, prevCount]) => {\n if (count === prevCount) return;\n\n scroller._fixScrollJump();\n },\n { flush: \"post\" }\n );\n\n watch(\n [rerender, store._getRange],\n ([, [start, end]], [, [prevStart, prevEnd]]) => {\n if (prevStart === start && prevEnd === end) return;\n\n emit(\"rangeChange\", start, end);\n },\n { flush: \"post\" }\n );\n\n return () => {\n rerender.value;\n \n const Element = props.as;\n const ItemElement = props.item;\n const count = props.data.length;\n\n const [startIndex, endIndex] = store._getRange();\n const scrollDirection = store._getScrollDirection();\n const totalSize = store._getTotalSize();\n\n const items: VNode[] = [];\n for (\n let [i, j] = getOverscanedRange(\n startIndex,\n endIndex,\n props.overscan,\n scrollDirection,\n count\n );\n i <= j;\n i++\n ) {\n const e = slots.default(props.data![i]!)[0]! as VNode;\n items.push(\n <ListItem\n key={getKey(e, i)}\n _resizer={resizer._observeItem}\n _index={i}\n _offset={store._getItemOffset(i)}\n _hide={store._isUnmeasuredItem(i)}\n _children={e}\n _isHorizontal={isHorizontal}\n _as={ItemElement}\n />\n );\n }\n\n return (\n <Element\n ref={containerRef}\n style={{\n // contain: \"content\",\n overflowAnchor: \"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: isHorizontal ? totalSize + \"px\" : \"100%\",\n height: isHorizontal ? \"100%\" : totalSize + \"px\",\n pointerEvents: scrollDirection !== SCROLL_IDLE ? \"none\" : \"auto\",\n }}\n >\n {items}\n </Element>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n void,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: any }>\n>);\n"],"names":["NULL","min","Math","max","abs","timeout","setTimeout","clamp","value","minValue","maxValue","microtask","queueMicrotask","fn","Promise","resolve","then","once","called","cache","args","UNCACHED","fill","array","length","prepend","key","i","getItemSize","index","size","_sizes","_defaultItemSize","setItemSize","isInitialMeasurement","_computedOffsetIndex","computeOffset","_length","_offsets","top","findIndex","offset","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","getOverscanedRange","startIndex","endIndex","overscan","scrollDirection","count","createVirtualStore","elementsCount","itemSize","ssrCount","cacheSnapshot","shouldAutoEstimateItemSize","isSSR","stateVersion","viewportSize","startSpacerSize","scrollOffset","jumpCount","jump","pendingJump","_flushedJump","_scrollDirection","_scrollMode","_frozenRange","_prevRange","_totalMeasuredSize","initCache","subscribers","Set","getRelativeScrollOffset","getRange","computeRange","prevStartIndex","start","getTotalSize","computeTotalSize","getItemOffset","computeStartOffset","_getItemSize","applyJump","j","_getStateVersion","_getCacheSnapshot","takeCacheSnapshot","_getRange","_isUnmeasuredItem","_isInitialMeasurementDone","_hasUnmeasuredItemsInFrozenRange","slice","includes","_getItemOffset","_getItemsLength","_getScrollOffset","_getScrollDirection","_getViewportSize","_getStartSpacerSize","_getTotalSize","_getJumpCount","_flushJump","_subscribe","target","cb","sub","add","delete","_update","type","payload","shouldFlushPendingJump","shouldSync","mutated","flushedJump","delta","distance","relativeOffset","updated","filter","prevSize","estimateDefaultItemSize","measuredCountBeforeStart","measuredSizes","s","isMeasured","prevDefaultItemSize","arr","sorted","sort","a","b","mid","median","UPDATE_VIRTUAL_STATE","forEach","createResizeObserver","ro","_observe","e","observe","_unobserve","unobserve","_dispose","disconnect","normalizeOffset","isHorizontal","createScrollObserver","store","viewport","getScrollOffset","updateScrollOffset","getStartOffset","now","Date","lastScrollTime","wheeling","touching","justTouchEnded","stillMomentumScrolling","onScrollEnd","debounce","id","cancel","clearTimeout","debouncedFn","_cancel","onScroll","onWheel","ctrlKey","timeDelta","deltaX","deltaY","onTouchStart","onTouchEnd","addEventListener","passive","removeEventListener","_fixScrollJump","shift","ListItem","defineComponent","props","_children","Object","required","_resizer","Function","_index","Number","_offset","_hide","Boolean","_isHorizontal","_isSSR","_as","String","setup","elementRef","ref","watch","_","__","onCleanup","flush","children","hide","Element","margin","padding","position","undefined","visibility","display","_createVNode","_isVNode","prototype","toString","call","default","getKey","Virtualizer","data","Array","horizontal","startMargin","scrollRef","as","item","emits","emit","expose","slots","containerRef","_a","resizer","createResizer","viewportElement","sizeKey","mountedIndexes","WeakMap","resizeObserver","entries","resizes","contentRect","offsetParent","get","push","_observeRoot","_observeItem","el","set","scroller","createScroller","scrollObserver","cancelScroll","scrollOffsetKey","overflowKey","scheduleImperativeScroll","async","getTargetOffset","smooth","waitForMeasurement","queue","reject","promise","unsubscribe","scrollTo","behavior","isMomentumScrolling","prev","_scrollTo","_scrollBy","_scrollToIndex","align","rerender","unsubscribeStore","unsubscribeOnScroll","unsubscribeOnScrollEnd","onMounted","assignScrollableElement","parentElement","onUnmounted","immediate","prevCount","end","prevStart","prevEnd","scrollSize","getScrollSize","scrollToIndex","scrollBy","ItemElement","totalSize","items","Y","F","U","V","X","G","K","Z","overflowAnchor","flex","width","height","pointerEvents","VList","onRangeChange","handle","contain","WindowVirtualizer","createWindowResizer","windowSizeKey","cleanupOnWindowResize","container","onWindowResize","createWindowScroller","documentBody","body","calcOffsetToViewport","offsetKey","offsetSum","innerWidth","offsetWidth","parent","scroll"],"mappings":"wHACO,MAAMA,EAAO,KAGPC,EAAMC,KAAKD,IAEXE,EAAMD,KAAKC,IAEXC,EAAMF,KAAKE,IAMXC,EAAUC,WAKVC,EAAQA,CACnBC,EACAC,EACAC,IACWT,EAAIS,EAAUP,EAAIM,EAAUD,IAuB5BG,EACe,mBAAnBC,eACHA,eACCC,IACCC,QAAQC,UAAUC,KAAKH,EAAG,EA4BrBI,EAA2CJ,IACtD,IAAIK,EACAC,EAEJ,MAAQ,IAAIC,KACLF,IACHA,GAAS,EACTC,EAAQN,KAAMO,IAETD,EACR,EChFUE,GAAY,EAenBC,EAAOA,CAACC,EAAiBC,EAAgBC,KAC7C,MAAMC,EAAMD,EAAU,UAAY,OAClC,IAAK,IAAIE,EAAI,EAAGA,EAAIH,EAAQG,IAC1BJ,EAAMG,GAAKL,GAEb,OAAOE,CAAK,EAMDK,EAAcA,CAACT,EAAcU,KACxC,MAAMC,EAAOX,EAAMY,EAAOF,GAC1B,OAAOC,IA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Q,EAAkC,OAAS,SA5JrC,mBAAA6E,EA+JtB0K,IA/JsB/E,oBAAA/B,OAAAgC,UAAAC,SAAAC,KAAA9F,KAAA2F,EAAA3F,GA+JtB0K,EAAK,CAAA3E,QAAAA,IAAA,CAAL2E,GAAK7F,EAAA,GAAA,EAAA,CAAA,UA/JiB,IAAA7E,CA+JjB,CAId"}
1
+ {"version":3,"file":"index.mjs","sources":["../../src/src/core/utils.ts","../../src/src/core/cache.ts","../../src/src/core/environment.ts","../../src/src/core/store.ts","../../src/src/core/resizer.ts","../../src/src/core/scroller.ts","../../src/src/vue/ListItem.tsx","../../src/src/vue/utils.ts","../../src/src/vue/Virtualizer.tsx","../../src/src/vue/VList.tsx","../../src/src/vue/WindowVirtualizer.tsx"],"sourcesContent":["/** @internal */\nexport const NULL = null;\n\n/** @internal */\nexport const min = Math.min;\n/** @internal */\nexport const max = Math.max;\n/** @internal */\nexport const abs = Math.abs;\n/** @internal */\nexport const values = Object.values;\n/** @internal */\nexport const isArray = Array.isArray;\n/** @internal */\nexport const timeout = setTimeout;\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 median = (arr: number[]): number => {\n const sorted = sort(arr);\n const mid = (arr.length / 2) | 0;\n return sorted.length % 2 === 0\n ? (sorted[mid - 1]! + sorted[mid]!) / 2\n : sorted[mid]!;\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 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 * @internal\n */\nexport const once = <F extends (...args: any[]) => any>(fn: F): F => {\n let called: undefined | boolean;\n let cache: ReturnType<F>;\n\n return ((...args) => {\n if (!called) {\n called = true;\n cache = fn(...args);\n }\n return cache;\n }) as F;\n};\n\n/**\n * @internal\n */\nexport const getStyleNumber = (v: string): number => {\n if (v) {\n return parseFloat(v);\n } else {\n return 0;\n }\n};\n","import { type InternalCacheSnapshot, type ItemsRange } from \"./types\";\nimport { clamp, max, median, min } 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 * @internal\n */\nexport const findIndex = (cache: Cache, offset: number, i: number): number => {\n while (i >= 0 && i < cache._length) {\n const itemOffset = computeOffset(cache, i);\n if (itemOffset <= offset) {\n if (itemOffset + getItemSize(cache, i) > offset) {\n break;\n } else {\n i++;\n }\n } else {\n i--;\n }\n }\n return clamp(i, 0, cache._length - 1);\n};\n\n/**\n * @internal\n */\nexport const computeRange = (\n cache: Cache,\n scrollOffset: number,\n prevStartIndex: number,\n viewportSize: number\n): ItemsRange => {\n const start = findIndex(\n cache,\n scrollOffset,\n // Clamp because prevStartIndex may exceed the limit when children decreased a lot after scrolling\n min(prevStartIndex, cache._length - 1)\n );\n return [start, findIndex(cache, scrollOffset + viewportSize, start)];\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 = cache._sizes.filter((s, i) => {\n const isMeasured = s !== UNCACHED;\n if (isMeasured && i < startIndex) {\n measuredCountBeforeStart++;\n }\n return isMeasured;\n });\n const prevDefaultItemSize = cache._defaultItemSize;\n\n // Discard cache for now\n cache._computedOffsetIndex = -1;\n\n // Calculate diff of unmeasured items before start\n return (\n ((cache._defaultItemSize = median(measuredSizes)) - 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], 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} 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\n/** @internal */\nexport const SCROLL_IDLE = 0;\n/** @internal */\nexport const SCROLL_DOWN = 1;\n/** @internal */\nexport const SCROLL_UP = 2;\n/** @internal */\nexport type 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 getOverscanedRange = (\n startIndex: number,\n endIndex: number,\n overscan: number,\n scrollDirection: ScrollDirection,\n count: number\n): ItemsRange => {\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, count - 1)];\n};\n\ntype Subscriber = (sync?: boolean) => void;\n\n/** @internal */\nexport type StateVersion = readonly [];\n\n/**\n * @internal\n */\nexport type VirtualStore = {\n _getStateVersion(): StateVersion;\n _getCacheSnapshot(): CacheSnapshot;\n _getRange(): ItemsRange;\n _isUnmeasuredItem(index: number): boolean;\n _isInitialMeasurementDone(): boolean;\n _hasUnmeasuredItemsInFrozenRange(): boolean;\n _getItemOffset(index: number): number;\n _getItemSize(index: number): number;\n _getItemsLength(): number;\n _getScrollOffset(): number;\n _getScrollDirection(): ScrollDirection;\n _getViewportSize(): number;\n _getStartSpacerSize(): number;\n _getTotalSize(): number;\n _getJumpCount(): number;\n _flushJump(): [number, boolean];\n _subscribe(target: number, cb: Subscriber): () => void;\n _update(...action: Actions): void;\n};\n\n/**\n * @internal\n */\nexport const createVirtualStore = (\n elementsCount: number,\n itemSize: number = 40,\n ssrCount: number = 0,\n cacheSnapshot?: CacheSnapshot | undefined,\n shouldAutoEstimateItemSize: boolean = false\n): VirtualStore => {\n let isSSR = !!ssrCount;\n let stateVersion: StateVersion = [];\n let viewportSize = 0;\n let startSpacerSize = 0;\n let scrollOffset = 0;\n let jumpCount = 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 getRange = (offset: number) => {\n return computeRange(cache, offset, _prevRange[0], viewportSize);\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 jumpCount++;\n }\n }\n };\n\n return {\n _getStateVersion() {\n return stateVersion;\n },\n _getCacheSnapshot() {\n return takeCacheSnapshot(cache) as unknown as CacheSnapshot;\n },\n _getRange() {\n // Return previous range for consistent render until next scroll event comes in.\n if (_flushedJump) {\n return _prevRange;\n }\n _prevRange = getRange(\n max(0, getRelativeScrollOffset() + pendingJump + jump)\n );\n\n if (_frozenRange) {\n return [\n min(_prevRange[0], _frozenRange[0]),\n max(_prevRange[1], _frozenRange[1]),\n ];\n }\n return _prevRange;\n },\n _isUnmeasuredItem(index) {\n return cache._sizes[index] === UNCACHED;\n },\n _isInitialMeasurementDone() {\n return !!viewportSize;\n },\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() {\n return cache._length;\n },\n _getScrollOffset() {\n return scrollOffset;\n },\n _getScrollDirection() {\n return _scrollDirection;\n },\n _getViewportSize() {\n return viewportSize;\n },\n _getStartSpacerSize() {\n return startSpacerSize;\n },\n _getTotalSize: getTotalSize,\n _getJumpCount() {\n return jumpCount;\n },\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 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(estimateDefaultItemSize(cache, _prevRange[0]));\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 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 }\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 = [];\n\n if (shouldFlushPendingJump && pendingJump) {\n jump += pendingJump;\n pendingJump = 0;\n jumpCount++;\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 { 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","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 SCROLL_IDLE,\n ACTION_BEFORE_MANUAL_SMOOTH_SCROLL,\n ACTION_START_OFFSET_CHANGE,\n} from \"./store\";\nimport { type ScrollToIndexOpts } from \"./types\";\nimport { debounce, timeout, clamp, microtask } from \"./utils\";\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._getScrollDirection() === SCROLL_IDLE ||\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 (store._isInitialMeasurementDone()) {\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 _fixScrollJump: () => void;\n};\n\n/**\n * @internal\n */\nexport const createWindowScroller = (\n store: VirtualStore,\n isHorizontal: boolean\n): WindowScroller => {\n let scrollObserver: ScrollObserver | undefined;\n\n return {\n _observe(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 const calcOffsetToViewport = (\n node: HTMLElement,\n viewport: HTMLElement,\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 isHorizontal,\n offsetSum\n );\n };\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 () => calcOffsetToViewport(container, documentBody, isHorizontal)\n );\n },\n _dispose() {\n scrollObserver && scrollObserver._dispose();\n },\n _fixScrollJump: () => {\n scrollObserver && scrollObserver._fixScrollJump();\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","/** @jsxImportSource vue */\nimport {\n ref,\n defineComponent,\n watch,\n StyleValue,\n PropType,\n VNode,\n NativeElements,\n} from \"vue\";\nimport { ItemResizeObserver } from \"../core/resizer\";\nimport { isRTLDocument } from \"../core/environment\";\n\n/**\n * @internal\n */\nexport const ListItem = /*#__PURE__*/ defineComponent({\n props: {\n _children: { type: Object as PropType<VNode>, required: true },\n _resizer: {\n type: Function as PropType<ItemResizeObserver>,\n required: true,\n },\n _index: { type: Number, required: true },\n _offset: { type: Number, required: true },\n _hide: { type: Boolean },\n _isHorizontal: { type: Boolean },\n _isSSR: { type: Boolean },\n _as: { type: String as PropType<keyof NativeElements>, required: true },\n },\n setup(props) {\n const elementRef = ref<HTMLDivElement>();\n\n // The index may be changed if elements are inserted to or removed from the start of props.children\n watch(\n () => elementRef.value && props._index,\n (_, __, onCleanup) => {\n onCleanup(props._resizer(elementRef.value!, props._index));\n },\n {\n flush: \"post\",\n }\n );\n\n return () => {\n const {\n _children: children,\n _offset: offset,\n _hide: hide,\n _isHorizontal: isHorizontal,\n _isSSR: isSSR,\n _as: Element,\n } = props;\n\n const style: StyleValue = {\n margin: 0,\n padding: 0,\n position: hide && isSSR ? undefined : \"absolute\",\n [isHorizontal ? \"height\" : \"width\"]: \"100%\",\n [isHorizontal ? \"top\" : \"left\"]: \"0px\",\n [isHorizontal ? (isRTLDocument() ? \"right\" : \"left\") : \"top\"]:\n offset + \"px\",\n visibility: !hide || isSSR ? \"visible\" : \"hidden\",\n };\n if (isHorizontal) {\n style.display = \"flex\";\n }\n\n return (\n <Element ref={elementRef} style={style}>\n {children}\n </Element>\n );\n };\n },\n});\n","import { VNode } from \"vue\";\nimport { NULL } from \"../core/utils\";\n\n/**\n * @internal\n */\nexport const getKey = (e: VNode, i: number): Exclude<VNode[\"key\"], null> => {\n const key = e.key;\n return key != NULL ? key : \"_\" + i;\n};\n","/** @jsxImportSource vue */\nimport {\n ref,\n onMounted,\n defineComponent,\n onUnmounted,\n VNode,\n watch,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n PropType,\n NativeElements,\n} from \"vue\";\nimport {\n SCROLL_IDLE,\n UPDATE_SCROLL_EVENT,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n getOverscanedRange,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n getScrollSize,\n ACTION_START_OFFSET_CHANGE,\n} from \"../core/store\";\nimport { createResizer } from \"../core/resizer\";\nimport { createScroller } from \"../core/scroller\";\nimport { ScrollToIndexOpts } from \"../core/types\";\nimport { ListItem } from \"./ListItem\";\nimport { getKey } from \"./utils\";\nimport { microtask } from \"../core/utils\";\n\nexport interface VirtualizerHandle {\n /**\n * Get current scrollTop or scrollLeft.\n */\n readonly scrollOffset: number;\n /**\n * Get current scrollHeight or scrollWidth.\n */\n readonly scrollSize: number;\n /**\n * Get current offsetHeight or offsetWidth.\n */\n readonly viewportSize: number;\n /**\n * Get item offset from start.\n * @param index index of item\n */\n getItemOffset(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\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * If you put an element before virtualizer, you have to define its height with this prop.\n */\n startMargin: { type: Number, default: 0 },\n /**\n * A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated.\n */\n ssrCount: Number,\n /**\n * Reference to the scrollable element. The default will get the parent element of virtualizer.\n */\n scrollRef: Object as PropType<HTMLElement>,\n /**\n * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n} satisfies ComponentObjectPropsOptions;\n\nexport const Virtualizer = /*#__PURE__*/ defineComponent({\n props: props,\n emits: [\"scroll\", \"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, expose, slots }) {\n let isSSR = !!props.ssrCount;\n\n const isHorizontal = props.horizontal;\n const containerRef = ref<HTMLDivElement>();\n const store = createVirtualStore(\n props.data.length,\n props.itemSize ?? 40,\n props.ssrCount,\n undefined,\n !props.itemSize\n );\n const resizer = createResizer(store, isHorizontal);\n const scroller = createScroller(store, isHorizontal);\n\n const rerender = ref(store._getStateVersion());\n const unsubscribeStore = store._subscribe(UPDATE_VIRTUAL_STATE, () => {\n rerender.value = store._getStateVersion();\n });\n\n const unsubscribeOnScroll = store._subscribe(UPDATE_SCROLL_EVENT, () => {\n emit(\"scroll\", store._getScrollOffset());\n });\n const unsubscribeOnScrollEnd = store._subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n emit(\"scrollEnd\");\n }\n );\n\n onMounted(() => {\n isSSR = false;\n\n microtask(() => {\n const assignScrollableElement = (e: HTMLElement) => {\n resizer._observeRoot(e);\n scroller._observe(e);\n };\n if (props.scrollRef) {\n // parent's ref doesn't exist when onMounted is called\n assignScrollableElement(props.scrollRef!);\n } else {\n assignScrollableElement(containerRef.value!.parentElement!);\n }\n });\n });\n onUnmounted(() => {\n unsubscribeStore();\n unsubscribeOnScroll();\n unsubscribeOnScrollEnd();\n resizer._dispose();\n scroller._dispose();\n });\n\n watch(\n () => props.data.length,\n (count) => {\n store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n );\n watch(\n () => props.startMargin,\n (value) => {\n store._update(ACTION_START_OFFSET_CHANGE, value);\n },\n { immediate: true }\n );\n\n watch(\n [rerender, store._getJumpCount],\n ([, count], [, prevCount]) => {\n if (count === prevCount) return;\n\n scroller._fixScrollJump();\n },\n { flush: \"post\" }\n );\n\n watch(\n [rerender, store._getRange],\n ([, [start, end]], [, [prevStart, prevEnd]]) => {\n if (prevStart === start && prevEnd === end) return;\n\n emit(\"rangeChange\", start, end);\n },\n { flush: \"post\" }\n );\n\n expose({\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 getItemOffset: store._getItemOffset,\n scrollToIndex: scroller._scrollToIndex,\n scrollTo: scroller._scrollTo,\n scrollBy: scroller._scrollBy,\n } satisfies VirtualizerHandle);\n\n return () => {\n rerender.value;\n\n const Element = props.as;\n const ItemElement = props.item;\n const count = props.data.length;\n\n const [startIndex, endIndex] = store._getRange();\n const scrollDirection = store._getScrollDirection();\n const totalSize = store._getTotalSize();\n\n const items: VNode[] = [];\n for (\n let [i, j] = getOverscanedRange(\n startIndex,\n endIndex,\n props.overscan,\n scrollDirection,\n count\n );\n i <= j;\n i++\n ) {\n const e = slots.default({ item: props.data![i]!, index: i })[0]!;\n items.push(\n <ListItem\n key={getKey(e, i)}\n _resizer={resizer._observeItem}\n _index={i}\n _offset={store._getItemOffset(i)}\n _hide={store._isUnmeasuredItem(i)}\n _children={e}\n _isHorizontal={isHorizontal}\n _isSSR={isSSR}\n _as={ItemElement}\n />\n );\n }\n\n return (\n <Element\n ref={containerRef}\n style={{\n // contain: \"content\",\n overflowAnchor: \"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: isHorizontal ? totalSize + \"px\" : \"100%\",\n height: isHorizontal ? \"100%\" : totalSize + \"px\",\n pointerEvents: scrollDirection !== SCROLL_IDLE ? \"none\" : \"auto\",\n }}\n >\n {items}\n </Element>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n VirtualizerHandle,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n scroll: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: (arg: { item: any; index: number }) => VNode[] }>\n>);\n","/** @jsxImportSource vue */\nimport {\n defineComponent,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n ref,\n VNode,\n} from \"vue\";\nimport { Virtualizer, VirtualizerHandle } from \"./Virtualizer\";\n\ninterface VListHandle extends VirtualizerHandle {}\n\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * A prop for SSR. If set, the specified amount of items will be mounted in the initial rendering regardless of the container size until hydrated.\n */\n ssrCount: Number,\n} satisfies ComponentObjectPropsOptions;\n\nexport const VList = /*#__PURE__*/ defineComponent({\n props: props,\n emits: [\"scroll\", \"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, expose, slots }) {\n const horizontal = props.horizontal;\n\n const onScroll = (offset: number) => {\n emit(\"scroll\", offset);\n };\n const onScrollEnd = () => {\n emit(\"scrollEnd\");\n };\n const onRangeChange = (start: number, end: number) => {\n emit(\"rangeChange\", start, end);\n };\n\n const handle = ref<InstanceType<typeof Virtualizer>>();\n\n expose({\n get scrollOffset() {\n return handle.value!.scrollOffset;\n },\n get scrollSize() {\n return handle.value!.scrollSize;\n },\n get viewportSize() {\n return handle.value!.viewportSize;\n },\n getItemOffset: (...args) => handle.value!.getItemOffset(...args),\n scrollToIndex: (...args) => handle.value!.scrollToIndex(...args),\n scrollTo: (...args) => handle.value!.scrollTo(...args),\n scrollBy: (...args) => handle.value!.scrollBy(...args),\n } satisfies VListHandle);\n\n return () => {\n return (\n <div\n style={{\n display: horizontal ? \"inline-block\" : \"block\",\n [horizontal ? \"overflowX\" : \"overflowY\"]: \"auto\",\n contain: \"strict\",\n width: \"100%\",\n height: \"100%\",\n }}\n >\n <Virtualizer\n ref={handle}\n data={props.data}\n overscan={props.overscan}\n itemSize={props.itemSize}\n shift={props.shift}\n ssrCount={props.ssrCount}\n horizontal={horizontal}\n onScroll={onScroll}\n onScrollEnd={onScrollEnd}\n onRangeChange={onRangeChange}\n >\n {slots}\n </Virtualizer>\n </div>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n VListHandle,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked whenever scroll offset changes.\n * @param offset Current scrollTop or scrollLeft.\n */\n scroll: (offset: number) => void;\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: (arg: { item: any; index: number }) => VNode[] }>\n>);\n","/** @jsxImportSource vue */\nimport {\n ref,\n onMounted,\n defineComponent,\n onUnmounted,\n VNode,\n watch,\n ComponentOptionsMixin,\n SlotsType,\n ComponentOptionsWithObjectProps,\n ComponentObjectPropsOptions,\n PropType,\n NativeElements,\n} from \"vue\";\nimport {\n SCROLL_IDLE,\n UPDATE_SCROLL_END_EVENT,\n UPDATE_VIRTUAL_STATE,\n getOverscanedRange,\n createVirtualStore,\n ACTION_ITEMS_LENGTH_CHANGE,\n} from \"../core/store\";\nimport { createWindowResizer } from \"../core/resizer\";\nimport { createWindowScroller } from \"../core/scroller\";\nimport { ListItem } from \"./ListItem\";\nimport { getKey } from \"./utils\";\n\nconst props = {\n /**\n * The data items rendered by this component.\n */\n data: { type: Array, required: true },\n /**\n * Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.\n * @defaultValue 4\n */\n overscan: { type: Number, default: 4 },\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 * Component or element type for container element.\n * @defaultValue \"div\"\n */\n as: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n /**\n * Component or element type for item element.\n * @defaultValue \"div\"\n */\n item: { type: String as PropType<keyof NativeElements>, default: \"div\" },\n} satisfies ComponentObjectPropsOptions;\n\nexport const WindowVirtualizer = /*#__PURE__*/ defineComponent({\n props,\n emits: [\"scrollEnd\", \"rangeChange\"],\n setup(props, { emit, slots }) {\n const isHorizontal = props.horizontal;\n const containerRef = ref<HTMLDivElement>();\n const store = createVirtualStore(\n props.data.length,\n props.itemSize ?? 40,\n undefined,\n undefined,\n !props.itemSize\n );\n const resizer = createWindowResizer(store, isHorizontal);\n const scroller = createWindowScroller(store, isHorizontal);\n\n const rerender = ref(store._getStateVersion());\n const unsubscribeStore = store._subscribe(UPDATE_VIRTUAL_STATE, () => {\n rerender.value = store._getStateVersion();\n });\n\n const unsubscribeOnScrollEnd = store._subscribe(\n UPDATE_SCROLL_END_EVENT,\n () => {\n emit(\"scrollEnd\");\n }\n );\n\n onMounted(() => {\n const el = containerRef.value;\n if (!el) return;\n resizer._observeRoot(el);\n scroller._observe(el);\n });\n onUnmounted(() => {\n unsubscribeStore();\n unsubscribeOnScrollEnd();\n resizer._dispose();\n scroller._dispose();\n });\n\n watch(\n () => props.data.length,\n (count) => {\n store._update(ACTION_ITEMS_LENGTH_CHANGE, [count, props.shift]);\n }\n );\n\n watch(\n [rerender, store._getJumpCount],\n ([, count], [, prevCount]) => {\n if (count === prevCount) return;\n\n scroller._fixScrollJump();\n },\n { flush: \"post\" }\n );\n\n watch(\n [rerender, store._getRange],\n ([, [start, end]], [, [prevStart, prevEnd]]) => {\n if (prevStart === start && prevEnd === end) return;\n\n emit(\"rangeChange\", start, end);\n },\n { flush: \"post\" }\n );\n\n return () => {\n rerender.value;\n\n const Element = props.as;\n const ItemElement = props.item;\n const count = props.data.length;\n\n const [startIndex, endIndex] = store._getRange();\n const scrollDirection = store._getScrollDirection();\n const totalSize = store._getTotalSize();\n\n const items: VNode[] = [];\n for (\n let [i, j] = getOverscanedRange(\n startIndex,\n endIndex,\n props.overscan,\n scrollDirection,\n count\n );\n i <= j;\n i++\n ) {\n const e = slots.default({ item: props.data![i]!, index: i })[0]!;\n items.push(\n <ListItem\n key={getKey(e, i)}\n _resizer={resizer._observeItem}\n _index={i}\n _offset={store._getItemOffset(i)}\n _hide={store._isUnmeasuredItem(i)}\n _children={e}\n _isHorizontal={isHorizontal}\n _as={ItemElement}\n />\n );\n }\n\n return (\n <Element\n ref={containerRef}\n style={{\n // contain: \"content\",\n overflowAnchor: \"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: isHorizontal ? totalSize + \"px\" : \"100%\",\n height: isHorizontal ? \"100%\" : totalSize + \"px\",\n pointerEvents: scrollDirection !== SCROLL_IDLE ? \"none\" : \"auto\",\n }}\n >\n {items}\n </Element>\n );\n };\n },\n} as ComponentOptionsWithObjectProps<\n typeof props,\n void,\n {},\n {},\n {},\n ComponentOptionsMixin,\n ComponentOptionsMixin,\n {\n /**\n * Callback invoked when scrolling stops.\n */\n scrollEnd: () => void;\n /**\n * Callback invoked when visible items range changes.\n */\n rangeChange: (\n /**\n * The start index of viewable items.\n */\n startIndex: number,\n /**\n * The end index of viewable items.\n */\n endIndex: number\n ) => void;\n },\n string,\n {},\n string,\n SlotsType<{ default: (arg: { item: any; index: number }) => VNode[] }>\n>);\n"],"names":["NULL","min","Math","max","abs","timeout","setTimeout","clamp","value","minValue","maxValue","microtask","queueMicrotask","fn","Promise","resolve","then","once","called","cache","args","UNCACHED","fill","array","length","prepend","key","i","getItemSize","index","size","_sizes","_defaultItemSize","setItemSize","isInitialMeasurement","_computedOffsetIndex","computeOffset","_length","_offsets","top","findIndex","offset","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","getOverscanedRange","startIndex","endIndex","overscan","scrollDirection","count","createVirtualStore","elementsCount","itemSize","ssrCount","cacheSnapshot","shouldAutoEstimateItemSize","isSSR","stateVersion","viewportSize","startSpacerSize","scrollOffset","jumpCount","jump","pendingJump","_flushedJump","_scrollDirection","_scrollMode","_frozenRange","_prevRange","_totalMeasuredSize","initCache","subscribers","Set","getRelativeScrollOffset","getRange","computeRange","prevStartIndex","start","getTotalSize","computeTotalSize","getItemOffset","computeStartOffset","_getItemSize","applyJump","j","_getStateVersion","_getCacheSnapshot","takeCacheSnapshot","_getRange","_isUnmeasuredItem","_isInitialMeasurementDone","_hasUnmeasuredItemsInFrozenRange","slice","includes","_getItemOffset","_getItemsLength","_getScrollOffset","_getScrollDirection","_getViewportSize","_getStartSpacerSize","_getTotalSize","_getJumpCount","_flushJump","_subscribe","target","cb","sub","add","delete","_update","type","payload","shouldFlushPendingJump","shouldSync","mutated","flushedJump","delta","distance","relativeOffset","updated","filter","prevSize","estimateDefaultItemSize","measuredCountBeforeStart","measuredSizes","s","isMeasured","prevDefaultItemSize","arr","sorted","sort","a","b","mid","median","UPDATE_VIRTUAL_STATE","forEach","createResizeObserver","ro","_observe","e","observe","_unobserve","unobserve","_dispose","disconnect","normalizeOffset","isHorizontal","createScrollObserver","store","viewport","getScrollOffset","updateScrollOffset","getStartOffset","now","Date","lastScrollTime","wheeling","touching","justTouchEnded","stillMomentumScrolling","onScrollEnd","debounce","id","cancel","clearTimeout","debouncedFn","_cancel","onScroll","onWheel","ctrlKey","timeDelta","deltaX","deltaY","onTouchStart","onTouchEnd","addEventListener","passive","removeEventListener","_fixScrollJump","shift","ListItem","defineComponent","props","_children","Object","required","_resizer","Function","_index","Number","_offset","_hide","Boolean","_isHorizontal","_isSSR","_as","String","setup","elementRef","ref","watch","_","__","onCleanup","flush","children","hide","Element","margin","padding","position","undefined","visibility","display","_createVNode","_isVNode","prototype","toString","call","default","getKey","Virtualizer","data","Array","horizontal","startMargin","scrollRef","as","item","emits","emit","expose","slots","containerRef","_a","resizer","createResizer","viewportElement","sizeKey","mountedIndexes","WeakMap","resizeObserver","entries","resizes","contentRect","offsetParent","get","push","_observeRoot","_observeItem","el","set","scroller","createScroller","scrollObserver","cancelScroll","scrollOffsetKey","overflowKey","scheduleImperativeScroll","async","getTargetOffset","smooth","waitForMeasurement","queue","reject","promise","unsubscribe","scrollTo","behavior","isMomentumScrolling","prev","_scrollTo","_scrollBy","_scrollToIndex","align","rerender","unsubscribeStore","unsubscribeOnScroll","unsubscribeOnScrollEnd","onMounted","assignScrollableElement","parentElement","onUnmounted","immediate","prevCount","end","prevStart","prevEnd","scrollSize","getScrollSize","scrollToIndex","scrollBy","ItemElement","totalSize","items","Y","F","U","V","X","G","K","Z","overflowAnchor","flex","width","height","pointerEvents","VList","onRangeChange","handle","contain","WindowVirtualizer","createWindowResizer","windowSizeKey","cleanupOnWindowResize","container","onWindowResize","createWindowScroller","documentBody","body","calcOffsetToViewport","offsetKey","offsetSum","innerWidth","offsetWidth","parent","scroll"],"mappings":"wHACO,MAAMA,EAAO,KAGPC,EAAMC,KAAKD,IAEXE,EAAMD,KAAKC,IAEXC,EAAMF,KAAKE,IAMXC,EAAUC,WAKVC,EAAQA,CACnBC,EACAC,EACAC,IACWT,EAAIS,EAAUP,EAAIM,EAAUD,IAuB5BG,EACe,mBAAnBC,eACHA,eACCC,IACCC,QAAQC,UAAUC,KAAKH,EAAG,EA4BrBI,EAA2CJ,IACtD,IAAIK,EACAC,EAEJ,MAAQ,IAAIC,KACLF,IACHA,GAAS,EACTC,EAAQN,KAAMO,IAETD,EACR,EChFU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hK,EAACiK,EACG1J,EAAY4J,EACtBV,GAAW,KAAA,EAAA,CAAA,IAAA,IAAA,IAAA,IAAA,IAAA,IAAA,MAGtB,CAEA,OAAA9E,EAAAP,EAAA,CAAAR,IAESkC,EAAY/L,MACV,CAELqQ,eAAgB,OAChBC,KAAM,OACN9F,SAAU,WACVE,WAAY,SACZ6F,MAAO/J,EAAemJ,EAAY,KAAO,OACzCa,OAAQhK,EAAe,OAASmJ,EAAY,KAC5Cc,cPhKe,IOgKApQ,EAAkC,OAAS,SA5JrC,mBAAA6E,EA+JtB0K,IA/JsB/E,oBAAA/B,OAAAgC,UAAAC,SAAAC,KAAA9F,KAAA2F,EAAA3F,GA+JtB0K,EAAK,CAAA3E,QAAAA,IAAA,CAAL2E,GAAK7F,EAAA,GAAA,EAAA,CAAA,UA/JiB,IAAA7E,CA+JjB,CAId"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtua",
3
- "version": "0.33.7",
3
+ "version": "0.34.0",
4
4
  "description": "A zero-config, fast and small (~3kB) virtual list (and grid) component for React, Vue, Solid and Svelte.",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",