gatsby-plugin-image 3.15.0 → 3.17.0-react19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/components/gatsby-image.browser.js +8 -3
- package/dist/gatsby-image.browser.js +1 -1
- package/dist/gatsby-image.browser.modern.js +1 -1
- package/dist/{index.browser-006c3456.js → index.browser-25d2e62c.js} +2 -2
- package/dist/{index.browser-006c3456.js.map → index.browser-25d2e62c.js.map} +1 -1
- package/dist/{index.browser-395cc902.js → index.browser-93c7cf96.js} +2 -2
- package/dist/{index.browser-395cc902.js.map → index.browser-93c7cf96.js.map} +1 -1
- package/dist/lazy-hydrate-93db2ca8.js +2 -0
- package/dist/{lazy-hydrate-62277b8c.js.map → lazy-hydrate-93db2ca8.js.map} +1 -1
- package/dist/{lazy-hydrate-6ff2d17c.js → lazy-hydrate-e25ad5d4.js} +2 -2
- package/dist/{lazy-hydrate-6ff2d17c.js.map → lazy-hydrate-e25ad5d4.js.map} +1 -1
- package/dist/src/components/gatsby-image.browser.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/lazy-hydrate-62277b8c.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-hydrate-6ff2d17c.js","sources":["../src/components/intersection-observer.ts","../src/components/lazy-hydrate.tsx"],"sourcesContent":["let 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: 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<GatsbyImageProps, \"as\" | \"style\" | \"className\"> & {\n isLoading: boolean\n isLoaded: boolean\n}\n\nasync function applyPolyfill(element: HTMLImageElement): Promise<void> {\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<string>,\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<HTMLElement>(\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<string>,\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 <LayoutWrapper layout={layout} width={width} height={height}>\n <Placeholder\n {...getPlaceholderProps(\n placeholder,\n isLoaded,\n layout,\n width,\n height,\n wrapperBackgroundColor,\n objectFit,\n objectPosition\n )}\n />\n\n <MainImage\n {...(props as Omit<\n MainImageProps,\n \"images\" | \"fallback\" | \"onLoad\" | \"onError\"\n >)}\n width={width}\n height={height}\n className={imgClassName}\n {...getMainProps(isLoading, isLoaded, images, loading, imgStyle)}\n />\n </LayoutWrapper>\n )\n}\n"],"names":["intersectionObserver","ioEntryMap","WeakMap","connection","navigator","mozConnection","webkitConnection","_excluded","mainImage","placeholderImage","style","opacity","element","cacheKey","imageCache","onStartLoad","onLoad","onError","querySelector","isCached","has","onImageLoaded","e","_this","this","removeEventListener","target","currentTarget","img","src","currentSrc","decode","then","toggleLoaded","wasCached","addEventListener","Array","from","parentElement","children","forEach","child","getAttribute","srcSet","removeAttribute","setAttribute","add","complete","call","_ref","image","loading","_ref$loading","isLoading","isLoaded","imgClassName","_ref$imgStyle","imgStyle","objectPosition","backgroundColor","objectFit","props","_objectWithoutPropertiesLoose","width","height","layout","images","placeholder","wrapperBackgroundColor","_extends","React","createElement","LayoutWrapper","Placeholder","getPlaceholderProps","MainImage","className","getMainProps","swapPlaceholderImage","hasNativeLazyLoadSupport","callback","cleanup","startLoading","window","IntersectionObserver","entries","entry","isIntersecting","get","_ioEntryMap$get","rootMargin","effectiveType","saveData","set","observe","unobserve","io","document","documentElement","dataset","_style$objectFit","_style$objectPosition","_temp2","objectFitPolyfill","_temp","Promise","resolve","_interopNamespace","require","reject","applyPolyfill","createIntersectionObserver"],"mappings":"meAAIA,sBAIEC,EAAa,IAAIC,QAEjBC,EACHC,UAAkBD,YAClBC,UAAkBC,eAClBD,UAAkBE,iBCTrBC,EAAA,CAAA,QAAA,UAAA,YAAA,WAAA,eAAA,WAAA,iBAAA,kBAAA,aA6BA,WACEC,EACAC,GAEAD,EAAUE,MAAMC,QAAa,IAEzBF,IACFA,EAAiBC,MAAMC,QACxB,IACH,CAEA,WACEC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAkBL,EAAQM,cAAa,qBAGjCT,EAAmBG,EAAQM,cAAa,4BAGxCC,EAAWL,EAAWM,IAAIP,GAEhC,SAASQ,EAAcC,GAErB,IAAAC,EAAAC,KAAAA,KAAKC,oBAAmB,OAASJ,GAEjC,IAAYK,EAAGJ,EAAEK,gBACL,UACZC,EAAIC,IAAMH,EAAOI,WAE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A4F,EAAA,WAAA,KANrC,sBAAuBrB,QACrB,OAAAsB,QAAAC,QAAAD,QAAAC,UAAA1E,KAAA,wBAAA,OAAA2E,EAAAC,6BAGL,IAGL5E,KAAA,aAAA,CAD6C,GAC7C,OAAAyE,QAAAC,QAAAF,GAAAA,EAAAxE,KAAAwE,EAAAxE,KAAAsE,GAAAA,IAAA,CAAC,MAEDhF,GAAA,OAAAmF,QAAAI,OAAAvF,EAAA,CAAA,CA0HMwF,CAAclG,IAGT,WACDqE,GACFA,IAGFc,GACF,CACD,CDhJagB,IACd/B,ECiJA,SACEpE,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ"}
|
|
1
|
+
{"version":3,"file":"lazy-hydrate-e25ad5d4.js","sources":["../src/components/intersection-observer.ts","../src/components/lazy-hydrate.tsx"],"sourcesContent":["let 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: 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<GatsbyImageProps, \"as\" | \"style\" | \"className\"> & {\n isLoading: boolean\n isLoaded: boolean\n}\n\nasync function applyPolyfill(element: HTMLImageElement): Promise<void> {\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<string>,\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<HTMLElement>(\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<string>,\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 <LayoutWrapper layout={layout} width={width} height={height}>\n <Placeholder\n {...getPlaceholderProps(\n placeholder,\n isLoaded,\n layout,\n width,\n height,\n wrapperBackgroundColor,\n objectFit,\n objectPosition\n )}\n />\n\n <MainImage\n {...(props as Omit<\n MainImageProps,\n \"images\" | \"fallback\" | \"onLoad\" | \"onError\"\n >)}\n width={width}\n height={height}\n className={imgClassName}\n {...getMainProps(isLoading, isLoaded, images, loading, imgStyle)}\n />\n </LayoutWrapper>\n )\n}\n"],"names":["intersectionObserver","ioEntryMap","WeakMap","connection","navigator","mozConnection","webkitConnection","_excluded","mainImage","placeholderImage","style","opacity","element","cacheKey","imageCache","onStartLoad","onLoad","onError","querySelector","isCached","has","onImageLoaded","e","_this","this","removeEventListener","target","currentTarget","img","src","currentSrc","decode","then","toggleLoaded","wasCached","addEventListener","Array","from","parentElement","children","forEach","child","getAttribute","srcSet","removeAttribute","setAttribute","add","complete","call","_ref","image","loading","_ref$loading","isLoading","isLoaded","imgClassName","_ref$imgStyle","imgStyle","objectPosition","backgroundColor","objectFit","props","_objectWithoutPropertiesLoose","width","height","layout","images","placeholder","wrapperBackgroundColor","_extends","React","createElement","LayoutWrapper","Placeholder","getPlaceholderProps","MainImage","className","getMainProps","swapPlaceholderImage","hasNativeLazyLoadSupport","callback","cleanup","startLoading","window","IntersectionObserver","entries","entry","isIntersecting","get","_ioEntryMap$get","rootMargin","effectiveType","saveData","set","observe","unobserve","io","document","documentElement","dataset","_style$objectFit","_style$objectPosition","_temp2","objectFitPolyfill","_temp","Promise","resolve","_interopNamespace","require","reject","applyPolyfill","createIntersectionObserver"],"mappings":"meAAIA,sBAIEC,EAAa,IAAIC,QAEjBC,EACHC,UAAkBD,YAClBC,UAAkBC,eAClBD,UAAkBE,iBCTrBC,EAAA,CAAA,QAAA,UAAA,YAAA,WAAA,eAAA,WAAA,iBAAA,kBAAA,aA6BA,WACEC,EACAC,GAEAD,EAAUE,MAAMC,QAAa,IAEzBF,IACFA,EAAiBC,MAAMC,QACxB,IACH,CAEA,WACEC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAkBL,EAAQM,cAAa,qBAGjCT,EAAmBG,EAAQM,cAAa,4BAGxCC,EAAWL,EAAWM,IAAIP,GAEhC,SAASQ,EAAcC,GAErB,IAAAC,EAAAC,KAAAA,KAAKC,oBAAmB,OAASJ,GAEjC,IAAYK,EAAGJ,EAAEK,gBACL,UACZC,EAAIC,IAAMH,EAAOI,WAEbF,EAAIG,OAENH,EACGG,SACAC,KAAK,WAEJC,EAAaV,EAAMd,GACnBO,MAAAA,GAAAA,EAAS,CACPkB,UAAWf,GAEf,GACM,MAAC,SAAAG,GAELW,EAAaV,EAAMd,GACZ,MAAPQ,GAAAA,EAAUK,EACZ,IAGFW,EAAaT,KAAMf,GACnBO,MAAAA,GAAAA,EAAS,CACPkB,UAAWf,IAGjB,CA8BA,OA5BAX,EAAU2B,iBAAgB,OAASd,GAEnCN,MAAAA,GAAAA,EAAc,CACZmB,UAAWf,IAEbiB,MAAMC,KAAK7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ECiJA,SACEpE,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gatsby-image.browser.d.ts","sourceRoot":"","sources":["../../../src/components/gatsby-image.browser.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EAClB,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAO5C,MAAM,WAAW,gBACf,SAAQ,IAAI,CACV,iBAAiB,CAAC,gBAAgB,CAAC,EACnC,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CACjE;IACD,GAAG,EAAE,MAAM,CAAA;IACX,EAAE,CAAC,EAAE,WAAW,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,gBAAgB,CAAA;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAA;IACtC,cAAc,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAA;IAChD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAA;IAChD,OAAO,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAA;IAC7C,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,KAAK,IAA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CAAA;IAChD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAA;IAChD,OAAO,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAA;IAC7C,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAA;CACtD;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,UAAU,CAAC,CAAA;IACpD,WAAW,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,UAAU,CAAC,CAAA;CAC7D;AAiLD,eAAO,MAAM,WAAW,EAAE,iBAAiB,CAAC,gBAAgB,CAkB3D,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby-plugin-image",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.0-react19.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "npm-run-all --npm-path npm -s clean -p build:*",
|
|
6
6
|
"postbuild": "prepend-directive --files=dist/gatsby-image.browser.js,dist/gatsby-image.browser.modern.js --directive=\"use client\"",
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"gatsby": "^5.0.0-next",
|
|
71
71
|
"gatsby-plugin-sharp": "^5.0.0-next",
|
|
72
72
|
"gatsby-source-filesystem": "^5.0.0-next",
|
|
73
|
-
"react": "^18.0.0 || ^0.0.0",
|
|
74
|
-
"react-dom": "^18.0.0 || ^0.0.0"
|
|
73
|
+
"react": "^18.0.0 || ^19.0.0 || ^0.0.0",
|
|
74
|
+
"react-dom": "^18.0.0 || ^19.0.0 || ^0.0.0"
|
|
75
75
|
},
|
|
76
76
|
"peerDependenciesMeta": {
|
|
77
77
|
"gatsby-plugin-sharp": {
|
|
@@ -87,13 +87,13 @@
|
|
|
87
87
|
"@babel/runtime": "^7.20.13",
|
|
88
88
|
"@babel/traverse": "^7.20.13",
|
|
89
89
|
"babel-jsx-utils": "^1.1.0",
|
|
90
|
-
"babel-plugin-remove-graphql-queries": "^5.
|
|
90
|
+
"babel-plugin-remove-graphql-queries": "^5.16.0-next.0",
|
|
91
91
|
"camelcase": "^6.3.0",
|
|
92
92
|
"chokidar": "^3.6.0",
|
|
93
93
|
"common-tags": "^1.8.2",
|
|
94
94
|
"fs-extra": "^11.2.0",
|
|
95
|
-
"gatsby-core-utils": "^4.
|
|
96
|
-
"gatsby-plugin-utils": "^4.
|
|
95
|
+
"gatsby-core-utils": "^4.16.0-next.0",
|
|
96
|
+
"gatsby-plugin-utils": "^4.16.0-next.0",
|
|
97
97
|
"objectFitPolyfill": "^2.3.5",
|
|
98
98
|
"prop-types": "^15.8.1"
|
|
99
99
|
},
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
},
|
|
105
105
|
"author": "Matt Kane <matt@gatsbyjs.com>",
|
|
106
106
|
"license": "MIT",
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "820c2e8cc6695c740c2f52d172b88bbd9e01a1b8"
|
|
108
108
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{h as t,_ as e,a as o,L as n,P as r,g as a,M as i,b as c}from"./index.browser-006c3456.js";import s from"react";import{renderToStaticMarkup as l}from"react-dom/server";import"camelcase";import"prop-types";let d;const u=new WeakMap,m=navigator.connection||navigator.mozConnection||navigator.webkitConnection,g=["image","loading","isLoading","isLoaded","imgClassName","imgStyle","objectPosition","backgroundColor","objectFit"];function b(t,e){t.style.opacity="1",e&&(e.style.opacity="0")}function h(t,e,o,n,r,a){const i=t.querySelector("[data-main-image]"),c=t.querySelector("[data-placeholder-image]"),s=o.has(e);function l(t){this.removeEventListener("load",l);const e=t.currentTarget,o=new Image;o.src=e.currentSrc,o.decode?o.decode().then(()=>{b(this,c),null==r||r({wasCached:s})}).catch(t=>{b(this,c),null==a||a(t)}):(b(this,c),null==r||r({wasCached:s}))}return i.addEventListener("load",l),null==n||n({wasCached:s}),Array.from(i.parentElement.children).forEach(t=>{const e=t.getAttribute("data-src"),o=t.getAttribute("data-srcset");e&&(t.removeAttribute("data-src"),t.setAttribute("src",e)),o&&(t.removeAttribute("data-srcset"),t.setAttribute("srcset",o))}),o.add(e),i.complete&&l.call(i,{currentTarget:i}),()=>{i&&i.removeEventListener("load",l)}}function v(e,o,n,r,a,i,c){if(!t()){let t;const b=(g=()=>{t=h(e,o,n,a,i,c)},"IntersectionObserver"in window?(d||(d=new IntersectionObserver(t=>{t.forEach(t=>{var e;t.isIntersecting&&(null==(e=u.get(t.target))||e(),u.delete(t.target))})},{rootMargin:"4g"!==(null==m?void 0:m.effectiveType)||null!=m&&m.saveData?"2500px":"1250px"})),function(t){return u.set(t,g),d.observe(t),function(){d&&t&&(u.delete(t),d.unobserve(t))}}):function(){return g(),function(){}}),v=b(e);var s,l;return"objectFit"in document.documentElement.style||(e.dataset.objectFit=null!=(s=r.objectFit)?s:"cover",e.dataset.objectPosition=`${null!=(l=r.objectPosition)?l:"50% 50%"}`,async function(t){"objectFitPolyfill"in window||await import("objectFitPolyfill"),window.objectFitPolyfill(t)}(e)),()=>{t&&t(),v()}}var g;return h(e,o,n,a,i,c)}function f(t){let{image:d,loading:u="lazy",isLoading:m,isLoaded:b,imgClassName:h,imgStyle:v={},objectPosition:f,backgroundColor:p,objectFit:y="cover"}=t,w=e(t,g);const{width:j,height:C,layout:E,images:F,placeholder:P,backgroundColor:L}=d;return v=o({objectFit:y,objectPosition:f,backgroundColor:p},v),l(s.createElement(n,{layout:E,width:j,height:C},s.createElement(r,o({},a(P,b,E,j,C,L,y,f))),s.createElement(i,o({},w,{width:j,height:C,className:h},c(m,b,F,u,v)))))}export{f as renderImageToString,v as swapPlaceholderImage};
|
|
2
|
-
//# sourceMappingURL=lazy-hydrate-62277b8c.js.map
|