import{u as le,a as ae}from"./chunk-8e5kB75k.js";import{B as $,E as re,$ as oe,F as ie}from"./app-CPb3bToC.js";import{l as h,Z as F,w as H,m as X,O as ne,x as Y,g as v,a as i,z as ue,A as ce}from"./chunk-DhYw-kuD.js";import{Q as k}from"./chunk-DOJZQpJk.js";import{s as se,g as ve,k as fe,l as he,m as I,n as R}from"./chunk-DBKH8df9.js";import{b as T,T as p}from"./chunk-DIiNYqqq.js";import{h as be}from"./chunk-CusLMHK2.js";const de=$({props:["store","barStyle","verticalBarStyle","horizontalBarStyle"],setup(e){return()=>[h("div",{class:e.store.scroll.vertical.barClass.value,style:[e.barStyle,e.verticalBarStyle],"aria-hidden":"true",onMousedown:e.store.onVerticalMousedown}),h("div",{class:e.store.scroll.horizontal.barClass.value,style:[e.barStyle,e.horizontalBarStyle],"aria-hidden":"true",onMousedown:e.store.onHorizontalMousedown}),F(h("div",{ref:e.store.scroll.vertical.ref,class:e.store.scroll.vertical.thumbClass.value,style:e.store.scroll.vertical.style.value,"aria-hidden":"true"}),e.store.thumbVertDir),F(h("div",{ref:e.store.scroll.horizontal.ref,class:e.store.scroll.horizontal.thumbClass.value,style:e.store.scroll.horizontal.style.value,"aria-hidden":"true"}),e.store.thumbHorizDir)]}}),{passive:L}=oe,me=["both","horizontal","vertical"],ze=$({name:"QScrollObserver",props:{axis:{type:String,validator:e=>me.includes(e),default:"vertical"},debounce:[String,Number],scrollTarget:se},emits:["scroll"],setup(e,{emit:A}){const n={position:{top:0,left:0},direction:"down",directionChanged:!1,delta:{top:0,left:0},inflectionPoint:{top:0,left:0}};let c=null,u,m;H(()=>e.scrollTarget,()=>{b(),t()});function r(){c!==null&&c();const z=Math.max(0,fe(u)),s=he(u),f={top:z-n.position.top,left:s-n.position.left};if(e.axis==="vertical"&&f.top===0||e.axis==="horizontal"&&f.left===0)return;const _=Math.abs(f.top)>=Math.abs(f.left)?f.top<0?"up":"down":f.left<0?"left":"right";n.position={top:z,left:s},n.directionChanged=n.direction!==_,n.delta=f,n.directionChanged===!0&&(n.direction=_,n.inflectionPoint=n.position),A("scroll",{...n})}function t(){u=ve(m,e.scrollTarget),u.addEventListener("scroll",g,L),g(!0)}function b(){u!==void 0&&(u.removeEventListener("scroll",g,L),u=void 0)}function g(z){if(z===!0||e.debounce===0||e.debounce==="0")r();else if(c===null){const[s,f]=e.debounce?[setTimeout(r,e.debounce),clearTimeout]:[requestAnimationFrame(r),cancelAnimationFrame];c=()=>{f(s),c=null}}}const{proxy:d}=X();return H(()=>d.$q.lang.rtl,r),ne(()=>{m=d.$el.parentNode,t()}),Y(()=>{c!==null&&c(),b()}),Object.assign(d,{trigger:g,getPosition:()=>n}),re}}),N=["vertical","horizontal"],w={vertical:{offset:"offsetY",scroll:"scrollTop",dir:"down",dist:"y"},horizontal:{offset:"offsetX",scroll:"scrollLeft",dir:"right",dist:"x"}},x={prevent:!0,mouse:!0,mouseAllDir:!0},U=e=>e>=250?50:Math.ceil(e/5),qe=$({name:"QScrollArea",props:{...le,thumbStyle:Object,verticalThumbStyle:Object,horizontalThumbStyle:Object,barStyle:[Array,String,Object],verticalBarStyle:[Array,String,Object],horizontalBarStyle:[Array,String,Object],verticalOffset:{type:Array,default:[0,0]},horizontalOffset:{type:Array,default:[0,0]},contentStyle:[Array,String,Object],contentActiveStyle:[Array,String,Object],delay:{type:[String,Number],default:1e3},visible:{type:Boolean,default:null},tabindex:[String,Number],onScroll:Function},setup(e,{slots:A,emit:n}){const c=v(!1),u=v(!1),m=v(!1),r={vertical:v(0),horizontal:v(0)},t={vertical:{ref:v(null),position:v(0),size:v(0)},horizontal:{ref:v(null),position:v(0),size:v(0)}},{proxy:b}=X(),g=ae(e,b.$q);let d=null,z;const s=v(null),f=i(()=>"q-scrollarea"+(g.value===!0?" q-scrollarea--dark":""));Object.assign(r,{verticalInner:i(()=>r.vertical.value-e.verticalOffset[0]-e.verticalOffset[1]),horizontalInner:i(()=>r.horizontal.value-e.horizontalOffset[0]-e.horizontalOffset[1])}),t.vertical.percentage=i(()=>{const l=t.vertical.size.value-r.vertical.value;if(l<=0)return 0;const a=T(t.vertical.position.value/l,0,1);return Math.round(a*1e4)/1e4}),t.vertical.thumbHidden=i(()=>(e.visible===null?m.value:e.visible)!==!0&&c.value===!1&&u.value===!1||t.vertical.size.value<=r.vertical.value+1),t.vertical.thumbStart=i(()=>e.verticalOffset[0]+t.vertical.percentage.value*(r.verticalInner.value-t.vertical.thumbSize.value)),t.vertical.thumbSize=i(()=>Math.round(T(r.verticalInner.value*r.verticalInner.value/t.vertical.size.value,U(r.verticalInner.value),r.verticalInner.value))),t.vertical.style=i(()=>({...e.thumbStyle,...e.verticalThumbStyle,top:`${t.vertical.thumbStart.value}px`,height:`${t.vertical.thumbSize.value}px`,right:`${e.horizontalOffset[1]}px`})),t.vertical.thumbClass=i(()=>"q-scrollarea__thumb q-scrollarea__thumb--v absolute-right"+(t.vertical.thumbHidden.value===!0?" q-scrollarea__thumb--invisible":"")),t.vertical.barClass=i(()=>"q-scrollarea__bar q-scrollarea__bar--v absolute-right"+(t.vertical.thumbHidden.value===!0?" q-scrollarea__bar--invisible":"")),t.horizontal.percentage=i(()=>{const l=t.horizontal.size.value-r.horizontal.value;if(l<=0)return 0;const a=T(Math.abs(t.horizontal.position.value)/l,0,1);return Math.round(a*1e4)/1e4}),t.horizontal.thumbHidden=i(()=>(e.visible===null?m.value:e.visible)!==!0&&c.value===!1&&u.value===!1||t.horizontal.size.value<=r.horizontal.value+1),t.horizontal.thumbStart=i(()=>e.horizontalOffset[0]+t.horizontal.percentage.value*(r.horizontalInner.value-t.horizontal.thumbSize.value)),t.horizontal.thumbSize=i(()=>Math.round(T(r.horizontalInner.value*r.horizontalInner.value/t.horizontal.size.value,U(r.horizontalInner.value),r.horizontalInner.value))),t.horizontal.style=i(()=>({...e.thumbStyle,...e.horizontalThumbStyle,[b.$q.lang.rtl===!0?"right":"left"]:`${t.horizontal.thumbStart.value}px`,width:`${t.horizontal.thumbSize.value}px`,bottom:`${e.verticalOffset[1]}px`})),t.horizontal.thumbClass=i(()=>"q-scrollarea__thumb q-scrollarea__thumb--h absolute-bottom"+(t.horizontal.thumbHidden.value===!0?" q-scrollarea__thumb--invisible":"")),t.horizontal.barClass=i(()=>"q-scrollarea__bar q-scrollarea__bar--h absolute-bottom"+(t.horizontal.thumbHidden.value===!0?" q-scrollarea__bar--invisible":""));const _=i(()=>t.vertical.thumbHidden.value===!0&&t.horizontal.thumbHidden.value===!0?e.contentStyle:e.contentActiveStyle);function B(){const l={};return N.forEach(a=>{const o=t[a];Object.assign(l,{[a+"Position"]:o.position.value,[a+"Percentage"]:o.percentage.value,[a+"Size"]:o.size.value,[a+"ContainerSize"]:r[a].value,[a+"ContainerInnerSize"]:r[a+"Inner"].value})}),l}const j=ie(()=>{const l=B();l.ref=b,n("scroll",l)},0);function D(l,a,o){if(N.includes(l)===!1){console.error("[QScrollArea]: wrong first param of setScrollPosition (vertical/horizontal)");return}(l==="vertical"?R:I)(s.value,a,o)}function Z({height:l,width:a}){let o=!1;r.vertical.value!==l&&(r.vertical.value=l,o=!0),r.horizontal.value!==a&&(r.horizontal.value=a,o=!0),o===!0&&M()}function G({position:l}){let a=!1;t.vertical.position.value!==l.top&&(t.vertical.position.value=l.top,a=!0),t.horizontal.position.value!==l.left&&(t.horizontal.position.value=l.left,a=!0),a===!0&&M()}function J({height:l,width:a}){t.horizontal.size.value!==a&&(t.horizontal.size.value=a,M()),t.vertical.size.value!==l&&(t.vertical.size.value=l,M())}function E(l,a){const o=t[a];if(l.isFirst===!0){if(o.thumbHidden.value===!0)return;z=o.position.value,u.value=!0}else if(u.value!==!0)return;l.isFinal===!0&&(u.value=!1);const y=w[a],O=(o.size.value-r[a].value)/(r[a+"Inner"].value-o.thumbSize.value),P=l.distance[y.dist],C=z+(l.direction===y.dir?1:-1)*P*O;V(C,a)}function Q(l,a){const o=t[a];if(o.thumbHidden.value!==!0){const y=a==="vertical"?e.verticalOffset[0]:e.horizontalOffset[0],O=l[w[a].offset]-y,P=o.thumbStart.value-y;if(O
P+o.thumbSize.value){const C=O-o.thumbSize.value/2,te=T(C/(r[a+"Inner"].value-o.thumbSize.value),0,1);V(te*Math.max(0,o.size.value-r[a].value),a)}o.ref.value!==null&&o.ref.value.dispatchEvent(new MouseEvent(l.type,l))}}function M(){c.value=!0,d!==null&&clearTimeout(d),d=setTimeout(()=>{d=null,c.value=!1},e.delay),e.onScroll!==void 0&&j()}function V(l,a){s.value[w[a].scroll]=l}let S=null;function K(){S!==null&&clearTimeout(S),S=setTimeout(()=>{S=null,m.value=!0},b.$q.platform.is.ios?50:0)}function W(){S!==null&&(clearTimeout(S),S=null),m.value=!1}let q=null;H(()=>b.$q.lang.rtl,l=>{s.value!==null&&I(s.value,Math.abs(t.horizontal.position.value)*(l===!0?-1:1))}),ue(()=>{q={top:t.vertical.position.value,left:t.horizontal.position.value}}),ce(()=>{if(q===null)return;const l=s.value;l!==null&&(I(l,q.left),R(l,q.top))}),Y(j.cancel),Object.assign(b,{getScrollTarget:()=>s.value,getScroll:B,getScrollPosition:()=>({top:t.vertical.position.value,left:t.horizontal.position.value}),getScrollPercentage:()=>({top:t.vertical.percentage.value,left:t.horizontal.percentage.value}),setScrollPosition:D,setScrollPercentage(l,a,o){D(l,a*(t[l].size.value-r[l].value)*(l==="horizontal"&&b.$q.lang.rtl===!0?-1:1),o)}});const ee={scroll:t,thumbVertDir:[[p,l=>{E(l,"vertical")},void 0,{vertical:!0,...x}]],thumbHorizDir:[[p,l=>{E(l,"horizontal")},void 0,{horizontal:!0,...x}]],onVerticalMousedown(l){Q(l,"vertical")},onHorizontalMousedown(l){Q(l,"horizontal")}};return()=>h("div",{class:f.value,onMouseenter:K,onMouseleave:W},[h("div",{ref:s,class:"q-scrollarea__container scroll relative-position fit hide-scrollbar",tabindex:e.tabindex!==void 0?e.tabindex:void 0},[h("div",{class:"q-scrollarea__content absolute",style:_.value},be(A.default,[h(k,{debounce:0,onResize:J})])),h(ze,{axis:"both",onScroll:G})]),h(k,{debounce:0,onResize:Z}),h(de,{store:ee,barStyle:e.barStyle,verticalBarStyle:e.verticalBarStyle,horizontalBarStyle:e.horizontalBarStyle})])}});export{qe as Q};