-
Notifications
You must be signed in to change notification settings - Fork 0
/
11-b264d2dca9f64daf0a84.js.map
1 lines (1 loc) · 3.21 KB
/
11-b264d2dca9f64daf0a84.js.map
1
{"version":3,"sources":["webpack:///../src/components/intersection-observer.ts"],"names":["intersectionObserver","ioEntryMap","WeakMap","connection","navigator","mozConnection","webkitConnection","createIntersectionObserver","callback","window","IntersectionObserver","entries","forEach","entry","isIntersecting","get","target","rootMargin","effectiveType","saveData","element","current","set","observe","unobserve"],"mappings":"8FAGA,sEAAIA,EAIEC,EAAa,IAAIC,QAEjBC,EACHC,UAAkBD,YAClBC,UAAkBC,eAClBD,UAAkBE,0BAQLC,EACdC,GAKA,MAAM,yBAA0BC,QAO3BT,IACHA,EAAuB,IAAIU,sBACzB,YACEC,EAAQC,SAAQ,kBACVC,EAAMC,0BAERb,EAAWc,IAAIF,EAAMG,cAErBf,SAAkBY,EAAMG,cAI9B,CACEC,WAAWA,QAAXA,MAvBiBd,WAAYe,sBAwBCf,KAAYgB,uCAQ9CC,GAQA,OANIA,EAAQC,UAEVpB,EAAWqB,IAAIF,EAAQC,QAASb,GAChCR,EAAqBuB,QAAQH,EAAQC,qBAIjCrB,GAAwBoB,EAAQC,UAClCpB,SAAkBmB,EAAQC,SAC1BrB,EAAqBwB,UAAUJ,EAAQC,wBArCzC,OADAb","file":"11-b264d2dca9f64daf0a84.js","sourcesContent":["/* eslint-disable no-unused-expressions */\nimport { RefObject } from \"react\"\n\nlet intersectionObserver: IntersectionObserver\n\nexport type Unobserver = () => void\n\nconst ioEntryMap = new WeakMap<HTMLElement, () => void>()\n/* eslint-disable @typescript-eslint/no-explicit-any */\nconst connection =\n (navigator as any).connection ||\n (navigator as any).mozConnection ||\n (navigator as any).webkitConnection\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\n// These match the thresholds used in Chrome's native lazy loading\n// @see https://web.dev/browser-level-image-lazy-loading/#distance-from-viewport-thresholds\nconst FAST_CONNECTION_THRESHOLD = `1250px`\nconst SLOW_CONNECTION_THRESHOLD = `2500px`\n\nexport function createIntersectionObserver(\n callback: () => void\n): (element: RefObject<HTMLElement | undefined>) => Unobserver {\n const connectionType = connection?.effectiveType\n\n // if we don't support intersectionObserver we don't lazy load (Sorry IE 11).\n if (!(`IntersectionObserver` in window)) {\n return function observe(): Unobserver {\n callback()\n return function unobserve(): void {}\n }\n }\n\n if (!intersectionObserver) {\n intersectionObserver = new IntersectionObserver(\n entries => {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n // Get the matching entry's callback and call it\n ioEntryMap.get(entry.target as HTMLElement)?.()\n // We only need to call it once\n ioEntryMap.delete(entry.target as HTMLElement)\n }\n })\n },\n {\n rootMargin:\n connectionType === `4g` && !connection?.saveData\n ? FAST_CONNECTION_THRESHOLD\n : SLOW_CONNECTION_THRESHOLD,\n }\n )\n }\n\n return function observe(\n element: RefObject<HTMLElement | undefined>\n ): Unobserver {\n if (element.current) {\n // Store a reference to the callback mapped to the element being watched\n ioEntryMap.set(element.current, callback)\n intersectionObserver.observe(element.current)\n }\n\n return function unobserve(): void {\n if (intersectionObserver && element.current) {\n ioEntryMap.delete(element.current)\n intersectionObserver.unobserve(element.current)\n }\n }\n }\n}\n"],"sourceRoot":""}