cloudflare-next-intl 0.9.1 → 0.9.3

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.
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ export interface ImgWithFallbackProps extends React.ImgHTMLAttributes<HTMLImageElement> {
3
+ originalSrc?: string;
4
+ }
5
+ export declare function ImgWithFallback({ originalSrc, ...imgProps }: ImgWithFallbackProps): React.JSX.Element;
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export function ImgWithFallback({ originalSrc, ...imgProps }) {
4
+ const onError = (event) => {
5
+ const img = event.currentTarget;
6
+ if (originalSrc && img.src !== originalSrc && !img.src.endsWith(originalSrc)) {
7
+ img.srcset = "";
8
+ img.src = originalSrc;
9
+ }
10
+ };
11
+ return _jsx("img", { ...imgProps, onError: onError });
12
+ }
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import NextImage, { getImageProps as nextGetImageProps } from "next/image";
3
3
  import { getImageBlurSvg } from "./blur_svg.js";
4
+ import { ImgWithFallback } from "./img_with_fallback.js";
4
5
  function pickVariant(entry, requestedWidth) {
5
6
  if (!requestedWidth || !entry.variants || entry.variants.length === 0) {
6
7
  return entry;
@@ -48,14 +49,35 @@ function findEntry(srcVal) {
48
49
  }
49
50
  return undefined;
50
51
  }
51
- function retargetSrcSet(srcSet, fromSrc, toSrc) {
52
- if (!srcSet)
53
- return srcSet;
54
- const fromEncoded = encodeURIComponent(fromSrc);
55
- const toEncoded = encodeURIComponent(toSrc);
56
- return srcSet
57
- .split(fromEncoded).join(toEncoded)
58
- .split(fromSrc).join(toSrc);
52
+ function toPlainImgAttrs(resolved, src) {
53
+ const { src: _src, alt, width, height, fill: _fill, loader: _loader, quality: _quality, preload: _preload, priority, placeholder: _placeholder, blurDataURL: _blurDataURL, unoptimized: _unoptimized, overrideSrc: _overrideSrc, onLoadingComplete: _onLoadingComplete, layout: _layout, objectFit: _objectFit, objectPosition: _objectPosition, lazyBoundary: _lazyBoundary, lazyRoot: _lazyRoot, loading, style, className, sizes, ...rest } = resolved;
54
+ void _src;
55
+ void _fill;
56
+ void _loader;
57
+ void _quality;
58
+ void _preload;
59
+ void _placeholder;
60
+ void _blurDataURL;
61
+ void _unoptimized;
62
+ void _overrideSrc;
63
+ void _onLoadingComplete;
64
+ void _layout;
65
+ void _objectFit;
66
+ void _objectPosition;
67
+ void _lazyBoundary;
68
+ void _lazyRoot;
69
+ return {
70
+ ...rest,
71
+ src,
72
+ alt: alt ?? "",
73
+ width: width,
74
+ height: height,
75
+ className: className,
76
+ style: style,
77
+ sizes: sizes,
78
+ loading: priority ? "eager" : (loading ?? "lazy"),
79
+ fetchPriority: priority ? "high" : "auto",
80
+ };
59
81
  }
60
82
  function resolveProps(props) {
61
83
  let src = props.src;
@@ -107,19 +129,10 @@ export default function Image(props) {
107
129
  if (alternates.length === 0) {
108
130
  return _jsx(NextImage, { ...resolved });
109
131
  }
110
- const { props: imgProps } = nextGetImageProps(resolved);
111
- const primarySrc = variant?.src ?? String(imgProps.src);
132
+ const primarySrc = variant?.src ?? String(resolved.src);
112
133
  const originalSrc = entry?.originalSrc;
113
- const onError = (event) => {
114
- const img = event.currentTarget;
115
- if (originalSrc && img.src !== originalSrc && !img.src.endsWith(originalSrc)) {
116
- img.srcset = "";
117
- img.src = originalSrc;
118
- }
119
- };
120
- return (_jsxs("picture", { children: [alternates.map((source) => (_jsx("source", { type: source.type, sizes: imgProps.sizes, srcSet: imgProps.srcSet
121
- ? retargetSrcSet(imgProps.srcSet, primarySrc, source.src)
122
- : source.src }, source.src))), _jsx("img", { ...imgProps, alt: imgProps.alt ?? "", onError: onError })] }));
134
+ const imgProps = toPlainImgAttrs(resolved, primarySrc);
135
+ return (_jsxs("picture", { children: [alternates.map((source) => (_jsx("source", { type: source.type, sizes: imgProps.sizes, srcSet: source.src }, source.src))), _jsx(ImgWithFallback, { ...imgProps, originalSrc: originalSrc })] }));
123
136
  }
124
137
  export function getImageProps(props) {
125
138
  const resolved = resolveProps(props);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "Optimized Next Intl Package Special for App Router and Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",