framer-motion
Version:
A simple and powerful JavaScript animation library
1 lines • 3.77 kB
Source Map (JSON)
{"version":3,"file":"on-scroll-handler.mjs","sources":["../../../../../src/render/dom/scroll/on-scroll-handler.ts"],"sourcesContent":["import { warnOnce } from \"motion-utils\"\nimport { updateScrollInfo } from \"./info\"\nimport { resolveOffsets } from \"./offsets/index\"\nimport {\n OnScrollHandler,\n OnScrollInfo,\n ScrollInfo,\n ScrollInfoOptions,\n} from \"./types\"\n\nfunction measure(\n container: Element,\n target: Element = container,\n info: ScrollInfo\n) {\n /**\n * Find inset of target within scrollable container\n */\n info.x.targetOffset = 0\n info.y.targetOffset = 0\n if (target !== container) {\n let node = target as HTMLElement\n while (node && node !== container) {\n info.x.targetOffset += node.offsetLeft\n info.y.targetOffset += node.offsetTop\n node = node.offsetParent as HTMLElement\n }\n }\n\n info.x.targetLength =\n target === container ? target.scrollWidth : target.clientWidth\n info.y.targetLength =\n target === container ? target.scrollHeight : target.clientHeight\n info.x.containerLength = container.clientWidth\n info.y.containerLength = container.clientHeight\n\n /**\n * In development mode ensure scroll containers aren't position: static as this makes\n * it difficult to measure their relative positions.\n */\n if (process.env.NODE_ENV !== \"production\") {\n if (container && target && target !== container) {\n warnOnce(\n getComputedStyle(container).position !== \"static\",\n \"Please ensure that the container has a non-static position, like 'relative', 'fixed', or 'absolute' to ensure scroll offset is calculated correctly.\"\n )\n }\n }\n}\n\nexport function createOnScrollHandler(\n element: Element,\n onScroll: OnScrollInfo,\n info: ScrollInfo,\n options: ScrollInfoOptions = {}\n): OnScrollHandler {\n return {\n measure: (time) => {\n measure(element, options.target, info)\n updateScrollInfo(element, info, time)\n\n if (options.offset || options.target) {\n resolveOffsets(element, info, options)\n }\n },\n notify: () => onScroll(info),\n }\n}\n"],"names":[],"mappings":";;;;AAUA,SAAS,OAAO,CACZ,SAAkB,EAClB,MAAkB,GAAA,SAAS,EAC3B,IAAgB,EAAA;AAEhB;;AAEG;AACH,IAAA,IAAI,CAAC,CAAC,CAAC,YA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