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