{"version":3,"file":"DfRGvVWi.js","sources":["../../../../node_modules/quasar/src/components/scroll-observer/QScrollObserver.js"],"sourcesContent":["import { watch, onMounted, onBeforeUnmount, getCurrentInstance } from 'vue'\n\nimport { createComponent } from '../../utils/private.create/create.js'\nimport { getScrollTarget, getVerticalScrollPosition, getHorizontalScrollPosition, scrollTargetProp } from '../../utils/scroll/scroll.js'\nimport { listenOpts, noop } from '../../utils/event/event.js'\n\nconst { passive } = listenOpts\nconst axisValues = [ 'both', 'horizontal', 'vertical' ]\n\nexport default createComponent({\n name: 'QScrollObserver',\n\n props: {\n axis: {\n type: String,\n validator: v => axisValues.includes(v),\n default: 'vertical'\n },\n\n debounce: [ String, Number ],\n\n scrollTarget: scrollTargetProp\n },\n\n emits: [ 'scroll' ],\n\n setup (props, { emit }) {\n const scroll = {\n position: {\n top: 0,\n left: 0\n },\n\n direction: 'down',\n directionChanged: false,\n\n delta: {\n top: 0,\n left: 0\n },\n\n inflectionPoint: {\n top: 0,\n left: 0\n }\n }\n\n let clearTimer = null, localScrollTarget, parentEl\n\n watch(() => props.scrollTarget, () => {\n unconfigureScrollTarget()\n configureScrollTarget()\n })\n\n function emitEvent () {\n clearTimer !== null && clearTimer()\n\n const top = Math.max(0, getVerticalScrollPosition(localScrollTarget))\n const left = getHorizontalScrollPosition(localScrollTarget)\n\n const delta = {\n top: top - scroll.position.top,\n left: left - scroll.position.left\n }\n\n if (\n (props.axis === 'vertical' && delta.top === 0)\n || (props.axis === 'horizontal' && delta.left === 0)\n ) {\n return\n }\n\n const curDir = Math.abs(delta.top) >= Math.abs(delta.left)\n ? (delta.top < 0 ? 'up' : 'down')\n : (delta.left < 0 ? 'left' : 'right')\n\n scroll.position = { top, left }\n scroll.directionChanged = scroll.direction !== curDir\n scroll.delta = delta\n\n if (scroll.directionChanged === true) {\n scroll.direction = curDir\n scroll.inflectionPoint = scroll.position\n }\n\n emit('scroll', { ...scroll })\n }\n\n function configureScrollTarget () {\n localScrollTarget = getScrollTarget(parentEl, props.scrollTarget)\n localScrollTarget.addEventListener('scroll', trigger, passive)\n trigger(true)\n }\n\n function unconfigureScrollTarget () {\n if (localScrollTarget !== void 0) {\n localScrollTarget.removeEventListener('scroll', trigger, passive)\n localScrollTarget = void 0\n }\n }\n\n function trigger (immediately) {\n if (immediately === true || props.debounce === 0 || props.debounce === '0') {\n emitEvent()\n }\n else if (clearTimer === null) {\n const [ timer, fn ] = props.debounce\n ? [ setTimeout(emitEvent, props.debounce), clearTimeout ]\n : [ requestAnimationFrame(emitEvent), cancelAnimationFrame ]\n\n clearTimer = () => {\n fn(timer)\n clearTimer = null\n }\n }\n }\n\n const { proxy } = getCurrentInstance()\n\n watch(() => proxy.$q.lang.rtl, emitEvent)\n\n onMounted(() => {\n parentEl = proxy.$el.parentNode\n configureScrollTarget()\n })\n\n onBeforeUnmount(() => {\n clearTimer !== null && clearTimer()\n unconfigureScrollTarget()\n })\n\n // expose public methods\n Object.assign(proxy, {\n trigger,\n getPosition: () => scroll\n })\n\n return noop\n }\n})\n"],"names":["passive","listenOpts","axisValues","QScrollObserver","createComponent","v","scrollTargetProp","props","emit","scroll","clearTimer","localScrollTarget","parentEl","watch","unconfigureScrollTarget","configureScrollTarget","emitEvent","top","getVerticalScrollPosition","left","getHorizontalScrollPosition","delta","curDir","getScrollTarget","trigger","immediately","timer","fn","proxy","getCurrentInstance","onMounted","onBeforeUnmount","noop"],"mappings":"+GAMA,KAAM,CAAE,QAAAA,CAAS,EAAGC,EACdC,EAAa,CAAE,OAAQ,aAAc,UAAY,EAEvDC,EAAeC,EAAgB,CAC7B,KAAM,kBAEN,MAAO,CACL,KAAM,CACJ,KAAM,OACN,UAAWC,GAAKH,EAAW,SAASG,CAAC,EACrC,QAAS,UACV,EAED,SAAU,CAAE,OAAQ,MAAQ,EAE5B,aAAcC,CACf,EAED,MAAO,CAAE,QAAU,EAEnB,MAAOC,EAAO,CAAE,KAAAC,GAAQ,CACtB,MAAMC,EAAS,CACb,SAAU,CACR,IAAK,E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