import{A as e,D as t,U as n,_ as r}from"./runtime-core.esm-bundler-Babufkcf.js";import{t as i}from"./create-CGAkPJkS.js";import{c as a,l as o}from"./dom-BXiDqs7-.js";import{_ as s,b as c,g as l,y as u}from"./index-uCtpzrM3.js";var{passive:d}=a,f=[`both`,`horizontal`,`vertical`],p=i({name:`QScrollObserver`,props:{axis:{type:String,validator:e=>f.includes(e),default:`vertical`},debounce:[String,Number],scrollTarget:c},emits:[`scroll`],setup(i,{emit:a}){let c={position:{top:0,left:0},direction:`down`,directionChanged:!1,delta:{top:0,left:0},inflectionPoint:{top:0,left:0}},f=null,p,m;n(()=>i.scrollTarget,()=>{_(),g()});function h(){f?.();let e=Math.max(0,u(p)),t=l(p),n={top:e-c.position.top,left:t-c.position.left};if(i.axis===`vertical`&&n.top===0||i.axis===`horizontal`&&n.left===0)return;let r=Math.abs(n.top)>=Math.abs(n.left)?n.top<0?`up`:`down`:n.left<0?`left`:`right`;c.position={top:e,left:t},c.directionChanged=c.direction!==r,c.delta=n,c.directionChanged&&(c.direction=r,c.inflectionPoint=c.position),a(`scroll`,{...c})}function g(){p=s(m,i.scrollTarget),p.addEventListener(`scroll`,v,d),v(!0)}function _(){p!==void 0&&(p.removeEventListener(`scroll`,v,d),p=void 0)}function v(e){if(e===!0||i.debounce===0||i.debounce===`0`)h();else if(f===null){let[e,t]=i.debounce?[setTimeout(h,i.debounce),clearTimeout]:[requestAnimationFrame(h),cancelAnimationFrame];f=()=>{t(e),f=null}}}let{proxy:y}=r();return n(()=>y.$q.lang.rtl,h),e(()=>{m=y.$el.parentNode,g()}),t(()=>{f?.(),_()}),Object.assign(y,{trigger:v,getPosition:()=>c}),o}});export{p as t};