You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 lines
12 KiB

{"ast":null,"code":"import { isClient } from '@vueuse/core';\nimport { easeInOutCubic } from '../easings.mjs';\nimport { isWindow } from '../types.mjs';\nimport { rAF, cAF } from '../raf.mjs';\nimport { getStyle } from './style.mjs';\nimport { isFunction } from '@vue/shared';\nconst isScroll = (el, isVertical) => {\n if (!isClient) return false;\n const key = {\n undefined: \"overflow\",\n true: \"overflow-y\",\n false: \"overflow-x\"\n }[String(isVertical)];\n const overflow = getStyle(el, key);\n return [\"scroll\", \"auto\", \"overlay\"].some(s => overflow.includes(s));\n};\nconst getScrollContainer = (el, isVertical) => {\n if (!isClient) return;\n let parent = el;\n while (parent) {\n if ([window, document, document.documentElement].includes(parent)) return window;\n if (isScroll(parent, isVertical)) return parent;\n parent = parent.parentNode;\n }\n return parent;\n};\nlet scrollBarWidth;\nconst getScrollBarWidth = namespace => {\n var _a;\n if (!isClient) return 0;\n if (scrollBarWidth !== void 0) return scrollBarWidth;\n const outer = document.createElement(\"div\");\n outer.className = `${namespace}-scrollbar__wrap`;\n outer.style.visibility = \"hidden\";\n outer.style.width = \"100px\";\n outer.style.position = \"absolute\";\n outer.style.top = \"-9999px\";\n document.body.appendChild(outer);\n const widthNoScroll = outer.offsetWidth;\n outer.style.overflow = \"scroll\";\n const inner = document.createElement(\"div\");\n inner.style.width = \"100%\";\n outer.appendChild(inner);\n const widthWithScroll = inner.offsetWidth;\n (_a = outer.parentNode) == null ? void 0 : _a.removeChild(outer);\n scrollBarWidth = widthNoScroll - widthWithScroll;\n return scrollBarWidth;\n};\nfunction scrollIntoView(container, selected) {\n if (!isClient) return;\n if (!selected) {\n container.scrollTop = 0;\n return;\n }\n const offsetParents = [];\n let pointer = selected.offsetParent;\n while (pointer !== null && container !== pointer && container.contains(pointer)) {\n offsetParents.push(pointer);\n pointer = pointer.offsetParent;\n }\n const top = selected.offsetTop + offsetParents.reduce((prev, curr) => prev + curr.offsetTop, 0);\n const bottom = top + selected.offsetHeight;\n const viewRectTop = container.scrollTop;\n const viewRectBottom = viewRectTop + container.clientHeight;\n if (top < viewRectTop) {\n container.scrollTop = top;\n } else if (bottom > viewRectBottom) {\n container.scrollTop = bottom - container.clientHeight;\n }\n}\nfunction animateScrollTo(container, from, to, duration, callback) {\n const startTime = Date.now();\n let handle;\n const scroll = () => {\n const timestamp = Date.now();\n const time = timestamp - startTime;\n const nextScrollTop = easeInOutCubic(time > duration ? duration : time, from, to, duration);\n if (isWindow(container)) {\n container.scrollTo(window.pageXOffset, nextScrollTop);\n } else {\n container.scrollTop = nextScrollTop;\n }\n if (time < duration) {\n handle = rAF(scroll);\n } else if (isFunction(callback)) {\n callback();\n }\n };\n scroll();\n return () => {\n handle && cAF(handle);\n };\n}\nconst getScrollElement = (target, container) => {\n if (isWindow(container)) {\n return target.ownerDocument.documentElement;\n }\n return container;\n};\nconst getScrollTop = container => {\n if (isWindow(container)) {\n return window.scrollY;\n }\n return container.scrollTop;\n};\nexport { animateScrollTo, getScrollBarWidth, getScrollContainer, getScrollElement, getScrollTop, isScroll, scrollIntoView };","map":{"version":3,"names":["isScroll","el","isVertical","isClient","key","undefined","true","false","String","overflow","getStyle","some","s","includes","getScrollContainer","parent","window","document","documentElement","parentNode","scrollBarWidth","getScrollBarWidth","namespace","_a","outer","createElement","className","style","visibility","width","position","top","body","appendChild","widthNoScroll","offsetWidth","inner","widthWithScroll","removeChild","scrollIntoView","container","selected","scrollTop","offsetParents","pointer","offsetParent","contains","push","offsetTop","reduce","prev","curr","bottom","offsetHeight","viewRectTop","viewRectBottom","clientHeight","animateScrollTo","from","to","duration","callback","startTime","Date","now","handle","scroll","timestamp","time","nextScrollTop","easeInOutCubic","isWindow","scrollTo","pageXOffset","rAF","isFunction","cAF","getScrollElement","target","ownerDocument","getScrollTop","scrollY"],"sources":["../../../../../packages/utils/dom/scroll.ts"],"sourcesContent":["import { isClient } from '../browser'\nimport { easeInOutCubic } from '../easings'\nimport { isFunction, isWindow } from '../types'\nimport { cAF, rAF } from '../raf'\nimport { getStyle } from './style'\n\nexport const isScroll = (el: HTMLElement, isVertical?: boolean): boolean => {\n if (!isClient) return false\n\n const key = (\n {\n undefined: 'overflow',\n true: 'overflow-y',\n false: 'overflow-x',\n } as const\n )[String(isVertical)]!\n const overflow = getStyle(el, key)\n return ['scroll', 'auto', 'overlay'].some((s) => overflow.includes(s))\n}\n\nexport const getScrollContainer = (\n el: HTMLElement,\n isVertical?: boolean\n): Window | HTMLElement | undefined => {\n if (!isClient) return\n\n let parent: HTMLElement = el\n while (parent) {\n if ([window, document, document.documentElement].includes(parent))\n return window\n\n if (isScroll(parent, isVertical)) return parent\n\n parent = parent.parentNode as HTMLElement\n }\n\n return parent\n}\n\nlet scrollBarWidth: number\nexport const getScrollBarWidth = (namespace: string): number => {\n if (!isClient) return 0\n if (scrollBarWidth !== undefined) return scrollBarWidth\n\n const outer = document.createElement('div')\n outer.className = `${namespace}-scrollbar__wrap`\n outer.style.visibility = 'hidden'\n outer.style.width = '100px'\n outer.style.position = 'absolute'\n outer.style.top = '-9999px'\n document.body.appendChild(outer)\n\n const widthNoScroll = outer.offsetWidth\n outer.style.overflow = 'scroll'\n\n const inner = document.createElement('div')\n inner.style.width = '100%'\n outer.appendChild(inner)\n\n const widthWithScroll = inner.offsetWidth\n outer.parentNode?.removeChild(outer)\n scrollBarWidth = widthNoScroll - widthWithScroll\n\n return scrollBarWidth\n}\n\n/**\n * Scroll with in the container element, positioning the **selected** element at the top\n * of the container\n */\nexport function scrollIntoView(\n container: HTMLElement,\n selected: HTMLElement\n): void {\n if (!isClient) return\n\n if (!selected) {\n container.scrollTop = 0\n return\n }\n\n const offsetParents: HTMLElement[] = []\n let pointer = selected.offsetParent\n while (\n pointer !== null &&\n container !== pointer &&\n container.contains(pointer)\n ) {\n offsetParents.push(pointer as HTMLElement)\n pointer = (pointer as HTMLElement).offsetParent\n }\n const top =\n selected.offsetTop +\n offsetParents.reduce((prev, curr) => prev + curr.offsetTop, 0)\n const bottom = top + selected.offsetHeight\n const viewRectTop = container.scrollTop\n const viewRectBottom = viewRectTop + container.clientHeight\n\n if (top < viewRectTop) {\n container.scrollTop = top\n } else if (bottom > viewRectBottom) {\n container.scrollTop = bottom - container.clientHeight\n }\n}\n\nexport function animateScrollTo(\n container: HTMLElement | Window,\n from: number,\n to: number,\n duration: number,\n callback?: unknown\n) {\n const startTime = Date.now()\n\n let handle: number | undefined\n const scroll = () => {\n const timestamp = Date.now()\n const time = timestamp - startTime\n const nextScrollTop = easeInOutCubic(\n time > duration ? duration : time,\n from,\n to,\n duration\n )\n\n if (isWindow(container)) {\n container.scrollTo(window.pageXOffset, nextScrollTop)\n } else {\n container.scrollTop = nextScrollTop\n }\n if (time < duration) {\n handle = rAF(scroll)\n } else if (isFunction(callback)) {\n callback()\n }\n }\n\n scroll()\n\n return () => {\n handle && cAF(handle)\n }\n}\n\nexport const getScrollElement = (\n target: HTMLElement,\n container: HTMLElement | Window\n) => {\n if (isWindow(container)) {\n return target.ownerDocument.documentElement\n }\n return container\n}\n\nexport const getScrollTop = (container: HTMLElement | Window) => {\n if (isWindow(container)) {\n return window.scrollY\n }\n return container.scrollTop\n}\n"],"mappings":";;;;;;AAKY,MAACA,QAAQ,GAAGA,CAACC,EAAE,EAAEC,UAAU,KAAK;EAC1C,IAAI,CAACC,QAAQ,EACX,OAAO,KAAK;EACd,MAAMC,GAAG,GAAG;IACVC,SAAS,EAAE,UAAU;IACrBC,IAAI,EAAE,YAAY;IAClBC,KAAK,EAAE;EACX,CAAG,CAACC,MAAM,CAACN,UAAU,CAAC,CAAC;EACrB,MAAMO,QAAQ,GAAGC,QAAQ,CAACT,EAAE,EAAEG,GAAG,CAAC;EAClC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAACO,IAAI,CAAEC,CAAC,IAAKH,QAAQ,CAACI,QAAQ,CAACD,CAAC,CAAC,CAAC;AACxE;AACY,MAACE,kBAAkB,GAAGA,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