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AAA,GAAC,UAClCC,EAAKC,QACLA,EAAgB,iBAChBC,EAASC,SACTA,EAAQC,aACRA,EAAYC,SACZA,EAAW,CAAC,EAACX,eACbA,EAAcY,gBACdA,EAAed,UACfA,EAAY,SAEKe,EADdC,GAEHC,EAAAA,EAAAA,GAAAA,EAAAA,GAAAA,MAAMC,MACJA,EAAKC,OACLA,EAAMC,OACNA,EAAMC,OACNA,EAAMC,YACNA,EACAR,gBAAiBS,GACff,EASJ,OAPAK,GAAAA,EAAAA,EAAAA,GAAAA,CACEb,UAAAA,EACAE,eAAAA,EACAY,gBAAAA,GACGD,IAAAA,EAAAA,EAAAA,sBAIHW,EAAAA,cAACC,EAAAA,EAAAA,CAAcL,OAAQA,EAAQF,MAAOA,EAAOC,OAAQA,GACnDK,EAAAA,cAACC,EAAAA,GAAAA,EAAAA,EAAAA,GAAAA,CAAAA,GACKC,EAAAA,EAAAA,GACFJ,EACAX,EACAS,EACAF,EACAC,EACAI,EACAvB,EACAE,KAIJsB,EAAAA,cAACG,EAAAA,GAAAA,EAAAA,EAAAA,GAAAA,CAAAA,EACMX,EAGH,CACFE,MAAOA,EACPC,OAAQA,EACRS,UAAWhB,IACPiB,EAAAA,EAAAA,GAAanB,EAAWC,EAAUU,EAAQZ,EAASI,MAI/D,C","sources":["webpack://medicine-and-the-military/../src/components/intersection-observer.ts","webpack://medicine-and-the-military/../src/components/lazy-hydrate.tsx"],"sourcesContent":["let intersectionObserver: IntersectionObserver\n\nexport type Unobserver = () => void\n\nconst ioEntryMap = new WeakMap 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: HTMLElement) => 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(element: HTMLElement): Unobserver {\n // Store a reference to the callback mapped to the element being watched\n ioEntryMap.set(element, callback)\n intersectionObserver.observe(element)\n\n return function unobserve(): void {\n if (intersectionObserver && element) {\n ioEntryMap.delete(element)\n intersectionObserver.unobserve(element)\n }\n }\n }\n}\n","import React from \"react\"\nimport { renderToStaticMarkup } from \"react-dom/server\"\nimport { LayoutWrapper } from \"./layout-wrapper\"\nimport { Placeholder } from \"./placeholder\"\nimport { MainImage } from \"./main-image\"\nimport {\n hasNativeLazyLoadSupport,\n getMainProps,\n getPlaceholderProps,\n} from \"./hooks\"\nimport { createIntersectionObserver } from \"./intersection-observer\"\nimport type { MainImageProps } from \"./main-image\"\nimport type { GatsbyImageProps } from \"./gatsby-image.browser\"\n\ntype LazyHydrateProps = Omit & {\n isLoading: boolean\n isLoaded: boolean\n}\n\nasync function applyPolyfill(element: HTMLImageElement): Promise {\n if (!(`objectFitPolyfill` in window)) {\n await import(\n // @ts-ignore typescript can't find the module for some reason ¯\\_(ツ)_/¯\n /* webpackChunkName: \"gatsby-plugin-image-objectfit-polyfill\" */ `objectFitPolyfill`\n )\n }\n ;(window as any).objectFitPolyfill(element)\n}\n\nfunction toggleLoaded(\n mainImage: HTMLElement,\n placeholderImage: HTMLElement\n): void {\n mainImage.style.opacity = `1`\n\n if (placeholderImage) {\n placeholderImage.style.opacity = `0`\n }\n}\n\nfunction startLoading(\n element: HTMLElement,\n cacheKey: string,\n imageCache: Set,\n onStartLoad: GatsbyImageProps[\"onStartLoad\"],\n onLoad: GatsbyImageProps[\"onLoad\"],\n onError: GatsbyImageProps[\"onError\"]\n): () => void {\n const mainImage = element.querySelector(\n `[data-main-image]`\n ) as HTMLImageElement\n const placeholderImage = element.querySelector(\n `[data-placeholder-image]`\n )\n const isCached = imageCache.has(cacheKey)\n\n function onImageLoaded(e): void {\n // eslint-disable-next-line @babel/no-invalid-this\n this.removeEventListener(`load`, onImageLoaded)\n\n const target = e.currentTarget\n const img = new Image()\n img.src = target.currentSrc\n\n if (img.decode) {\n // Decode the image through javascript to support our transition\n img\n .decode()\n .then(() => {\n // eslint-disable-next-line @babel/no-invalid-this\n toggleLoaded(this, placeholderImage)\n onLoad?.({\n wasCached: isCached,\n })\n })\n .catch(e => {\n // eslint-disable-next-line @babel/no-invalid-this\n toggleLoaded(this, placeholderImage)\n onError?.(e)\n })\n } else {\n // eslint-disable-next-line @babel/no-invalid-this\n toggleLoaded(this, placeholderImage)\n onLoad?.({\n wasCached: isCached,\n })\n }\n }\n\n mainImage.addEventListener(`load`, onImageLoaded)\n\n onStartLoad?.({\n wasCached: isCached,\n })\n Array.from(mainImage.parentElement.children).forEach(child => {\n const src = child.getAttribute(`data-src`)\n const srcSet = child.getAttribute(`data-srcset`)\n if (src) {\n child.removeAttribute(`data-src`)\n child.setAttribute(`src`, src)\n }\n if (srcSet) {\n child.removeAttribute(`data-srcset`)\n child.setAttribute(`srcset`, srcSet)\n }\n })\n\n imageCache.add(cacheKey)\n\n // Load times not always fires - mostly when it's a 304\n // We check if the image is already completed and if so we trigger onload.\n if (mainImage.complete) {\n onImageLoaded.call(mainImage, {\n currentTarget: mainImage,\n })\n }\n\n return (): void => {\n if (mainImage) {\n mainImage.removeEventListener(`load`, onImageLoaded)\n }\n }\n}\n\nexport function swapPlaceholderImage(\n element: HTMLElement,\n cacheKey: string,\n imageCache: Set,\n style: React.CSSProperties,\n onStartLoad: GatsbyImageProps[\"onStartLoad\"],\n onLoad: GatsbyImageProps[\"onLoad\"],\n onError: GatsbyImageProps[\"onError\"]\n): () => void {\n if (!hasNativeLazyLoadSupport()) {\n let cleanup\n const io = createIntersectionObserver(() => {\n cleanup = startLoading(\n element,\n cacheKey,\n imageCache,\n onStartLoad,\n onLoad,\n onError\n )\n })\n const unobserve = io(element)\n\n // Polyfill \"object-fit\" if unsupported (mostly IE)\n if (!(`objectFit` in document.documentElement.style)) {\n element.dataset.objectFit = style.objectFit ?? `cover`\n element.dataset.objectPosition = `${style.objectPosition ?? `50% 50%`}`\n applyPolyfill(element as HTMLImageElement)\n }\n\n return (): void => {\n if (cleanup) {\n cleanup()\n }\n\n unobserve()\n }\n }\n\n return startLoading(\n element,\n cacheKey,\n imageCache,\n onStartLoad,\n onLoad,\n onError\n )\n}\n\nexport function renderImageToString({\n image,\n loading = `lazy`,\n isLoading,\n isLoaded,\n imgClassName,\n imgStyle = {},\n objectPosition,\n backgroundColor,\n objectFit = `cover`,\n ...props\n}: LazyHydrateProps): string {\n const {\n width,\n height,\n layout,\n images,\n placeholder,\n backgroundColor: wrapperBackgroundColor,\n } = image\n\n imgStyle = {\n objectFit,\n objectPosition,\n backgroundColor,\n ...imgStyle,\n }\n\n return renderToStaticMarkup(\n \n \n\n )}\n width={width}\n height={height}\n className={imgClassName}\n {...getMainProps(isLoading, isLoaded, images, loading, imgStyle)}\n />\n \n )\n}\n"],"names":["intersectionObserver","ioEntryMap","WeakMap","connection","navigator","mozConnection","webkitConnection","_excluded","toggleLoaded","mainImage","placeholderImage","style","opacity","startLoading","element","cacheKey","imageCache","onStartLoad","onLoad","onError","querySelector","has","onImageLoaded","e","this","removeEventListener","currentTarget","img","Image","src","target","currentSrc","decode","then","wasCached","isCached","catch","addEventListener","Array","from","parentElement","children","forEach","child","getAttribute","srcSet","removeAttribute","setAttribute","add","complete","call","hasNativeLazyLoadSupport","cleanup","callback","IntersectionObserver","entries","entry","isIntersecting","get","_ioEntryMap$get","delete","rootMargin","effectiveType","saveData","set","observe","unobserve","io","document","documentElement","dataset","objectFit","_style$objectFit","objectPosition","async","window","import","objectFitPolyfill","renderImageToString","image","loading","isLoading","isLoaded","imgClassName","imgStyle","backgroundColor","_ref","props","_objectWithoutPropertiesLoose","width","height","layout","images","placeholder","wrapperBackgroundColor","React","createElement","getPlaceholderProps","MainImage","className","getMainProps"],"sourceRoot":""}