import{bY as D,l as b,U as Q,aZ as f,an as U,ar as k,ap as w,at as O,dw as V,ad as T,c0 as _,dx as j,dy as d,dz as S,dA as y,am as z,dB as x,dC as F,cS as R,aa as W}from"./index.69621fe4.js";const{passive:r}=j;var Z=D({name:"QInfiniteScroll",props:{offset:{type:Number,default:500},debounce:{type:[String,Number],default:100},scrollTarget:{default:void 0},initialIndex:Number,disable:Boolean,reverse:Boolean},emits:["load"],setup(l,{slots:E,emit:B}){const s=b(!1),i=b(!0),u=b(null);let c=l.initialIndex||0,e,a;const H=Q(()=>"q-infinite-scroll__loading"+(s.value===!0?"":" invisible"));function o(){if(l.disable===!0||s.value===!0||i.value===!1)return;const t=d(e),n=S(e),m=y(e);l.reverse===!1?Math.round(n+m+l.offset)>=Math.round(t)&&v():Math.round(n)<=l.offset&&v()}function v(){if(l.disable===!0||s.value===!0||i.value===!1)return;c++,s.value=!0;const t=d(e);B("load",c,n=>{i.value===!0&&(s.value=!1,z(()=>{if(l.reverse===!0){const m=d(e),A=S(e),C=m-t;x(e,A+C)}n===!0?g():u.value&&u.value.closest("body")&&a()}))})}function N(){c=0}function I(){i.value===!1&&(i.value=!0,e.addEventListener("scroll",a,r)),o()}function g(){i.value===!0&&(i.value=!1,s.value=!1,e.removeEventListener("scroll",a,r),a!==void 0&&a.cancel!==void 0&&a.cancel())}function L(){if(e&&i.value===!0&&e.removeEventListener("scroll",a,r),e=F(u.value,l.scrollTarget),i.value===!0){if(e.addEventListener("scroll",a,r),l.reverse===!0){const t=d(e),n=y(e);x(e,t-n)}o()}}function M(t){c=t}function P(t){t=parseInt(t,10);const n=a;a=t<=0?o:R(o,isNaN(t)===!0?100:t),e&&i.value===!0&&(n!==void 0&&e.removeEventListener("scroll",n,r),e.addEventListener("scroll",a,r))}f(()=>l.disable,t=>{t===!0?g():I()}),f(()=>l.reverse,t=>{s.value===!1&&i.value===!0&&o()}),f(()=>l.scrollTarget,L),f(()=>l.debounce,P);let h=!1;U(()=>{h!==!1&&e&&x(e,h)}),k(()=>{h=e?S(e):!1}),w(()=>{i.value===!0&&e.removeEventListener("scroll",a,r)}),O(()=>{P(l.debounce),L()});const q=W();return Object.assign(q.proxy,{poll:()=>{a!==void 0&&a()},trigger:v,stop:g,reset:N,resume:I,setIndex:M}),()=>{const t=V(E.default,[]);return l.disable!==!0&&i.value===!0&&t[l.reverse===!1?"push":"unshift"](T("div",{class:H.value},_(E.loading))),T("div",{class:"q-infinite-scroll",ref:u},t)}}});export{Z as Q};
