(function(e,h){typeof exports=="object"&&typeof module<"u"?module.exports=h(require("vue")):typeof define=="function"&&define.amd?define(["vue"],h):(e=typeof globalThis<"u"?globalThis:e||self,e.VuelScroller=h(e.Vue))})(this,function(e){"use strict";const h=async(l,r)=>{var f,m,i,p,d,y,g;const u=new URL(l.api.requestUrl);(((f=l.api)==null?void 0:f.requestStrategy)==="query"||!((m=l.api)!=null&&m.requestStrategy))&&(u.searchParams.append(((p=(i=l.api)==null?void 0:i.queryNames)==null?void 0:p.qty)??"qty",String(r.qty)),u.searchParams.append(((y=(d=l.api)==null?void 0:d.queryNames)==null?void 0:y.offset)??"offset",String(String(r.offset??l.loadedItems.value.length+1)))),((g=l.api)==null?void 0:g.requestStrategy)==="slash"&&(u.pathname+=`${r.qty}/${l.loadedItems.value.length}`);const a=await fetch(u.toString());if(!a.ok)return console.error("Network response was not ok"),null;const n=await a.json();return l.loadedItems.value.push(...n),n},w={key:0,style:{display:"flex",justifyContent:"center",width:"100%"}},v={xmlns:"http://www.w3.org/2000/svg",x:"0px",y:"0px",viewBox:"0 0 100 100","xml:space":"preserve",style:{width:"50px",height:"50px"}},_=e.createElementVNode("rect",{fill:"none",stroke:"#000","stroke-width":"4",x:"25",y:"25",width:"50",height:"50",rx:"8",ry:"8"},[e.createElementVNode("animateTransform",{attributeName:"transform",dur:"0.5s",from:"0 50 50",to:"180 50 50",type:"rotate",id:"strokeBox",attributeType:"XML",begin:"rectBox.end"})],-1),S=e.createElementVNode("rect",{x:"27",y:"27",fill:"#000",width:"46",height:"50",rx:"6",ry:"6"},[e.createElementVNode("animate",{attributeName:"height",dur:"1.3s",attributeType:"XML",from:"50",to:"0",id:"rectBox",fill:"freeze",begin:"0s;strokeBox.end"})],-1),B=e.createElementVNode("div",{style:{position:"absolute",bottom:"-30px",width:"100%",height:"10px",background:"transparent"}},null,-1);return e.defineComponent({__name:"VuelScroller",props:{renderOnly:{},settings:{},api:{}},setup(l){var x;const r=l,u=e.ref(0),a=e.ref(!1),n=e.ref(null),f=e.ref([]),m=e.ref(0),i=e.ref(1),p=e.ref(((x=r.renderOnly)==null?void 0:x.items)??[]),d=t=>{if(n.value)return t?n.value.scrollTop=0:n.value.scrollTop=g().scrollTop-1},y=()=>{e.nextTick(()=>{var o,c,s;if((o=r.settings)!=null&&o.initialQty)return i.value=(c=r.settings)==null?void 0:c.initialQty;if(!f.value[0]||!n.value)return;const t=f.value[0];m.value=t.clientHeight,i.value=Math.ceil(((s=n.value)==null?void 0:s.clientHeight)/m.value)+1})},g=()=>({scrollTop:n.value.scrollTop,scrollHeight:n.value.scrollHeight,clientHeight:n.value.clientHeight}),T=()=>{var s;if(!n.value)return;const{scrollTop:t,scrollHeight:o,clientHeight:c}=g();if(t=o-10)return q(((s=r.settings)==null?void 0:s.loadPerScroll)??1)},q=async t=>{var o,c,s;if(!((o=r.api)!=null&&o.requestUrl))return p.value.length=((s=r.api)==null?void 0:s.listLength)))return a.value=!0,await k(t),i.value+=t,a.value=!1,d()},k=async(t,o)=>await h({api:r.api,loadedItems:p},{qty:t,offset:o});return e.onMounted(async()=>{var t;if(d(!0),r.api){const o=((t=r.settings)==null?void 0:t.initialQty)??0;return a.value=!0,await k(o,0).then(()=>i.value+=o),a.value=!1}else y()}),(t,o)=>(e.openBlock(),e.createElementBlock("div",{style:{height:"100%",width:"100%",position:"relative","overflow-y":"scroll"},ref_key:"componentContainer",ref:n,onScroll:T},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.value.slice(0,i.value),(c,s)=>(e.openBlock(),e.createElementBlock("div",{key:`ev-${s}`,ref_for:!0,ref_key:"slotContainer",ref:f},[e.renderSlot(t.$slots,"default",{item:c})]))),128)),a.value?(e.openBlock(),e.createElementBlock("div",w,[e.renderSlot(t.$slots,"loading",{},()=>[(e.openBlock(),e.createElementBlock("svg",v,[_,e.createTextVNode(),S]))])])):e.createCommentVNode("",!0),B],544))}})});