import{v as b,aA as h,G as m,H as T,aH as S,ay as x,aK as P,z as C,bO as O,cf as z,cg as E}from"./index.cf09daef.js";const{passive:p}=O,M=["both","horizontal","vertical"];var y=b({name:"QScrollObserver",props:{axis:{type:String,validator:e=>M.includes(e),default:"vertical"},debounce:[String,Number],scrollTarget:h},emits:["scroll"],setup(e,{emit:v}){const t={position:{top:0,left:0},direction:"down",directionChanged:!1,delta:{top:0,left:0},inflectionPoint:{top:0,left:0}};let n=null,l,u;m(()=>e.scrollTarget,()=>{d(),f()});function i(){n!==null&&n();const a=Math.max(0,z(l)),c=E(l),o={top:a-t.position.top,left:c-t.position.left};if(e.axis==="vertical"&&o.top===0||e.axis==="horizontal"&&o.left===0)return;const g=Math.abs(o.top)>=Math.abs(o.left)?o.top<0?"up":"down":o.left<0?"left":"right";t.position={top:a,left:c},t.directionChanged=t.direction!==g,t.delta=o,t.directionChanged===!0&&(t.direction=g,t.inflectionPoint=t.position),v("scroll",{...t})}function f(){l=P(u,e.scrollTarget),l.addEventListener("scroll",r,p),r(!0)}function d(){l!==void 0&&(l.removeEventListener("scroll",r,p),l=void 0)}function r(a){if(a===!0||e.debounce===0||e.debounce==="0")i();else if(n===null){const[c,o]=e.debounce?[setTimeout(i,e.debounce),clearTimeout]:[requestAnimationFrame(i),cancelAnimationFrame];n=()=>{o(c),n=null}}}const{proxy:s}=C();return m(()=>s.$q.lang.rtl,i),T(()=>{u=s.$el.parentNode,f()}),S(()=>{n!==null&&n(),d()}),Object.assign(s,{trigger:r,getPosition:()=>t}),x}});export{y as Q};
