@webstudio-is/image 0.1.0 → 0.15.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.
Files changed (44) hide show
  1. package/lib/__generated__/image.props.json +573 -573
  2. package/lib/cjs/__generated__/image.props.json +573 -573
  3. package/lib/cjs/image-loaders.cjs +48 -33
  4. package/lib/cjs/image-optimize.cjs +101 -171
  5. package/lib/cjs/image.cjs +54 -22
  6. package/lib/cjs/index.cjs +31 -31
  7. package/lib/image-loaders.js +24 -27
  8. package/lib/image-optimize.js +83 -169
  9. package/lib/image.js +30 -15
  10. package/lib/index.js +8 -3
  11. package/package.json +9 -16
  12. package/src/__generated__/image.props.json +575 -0
  13. package/src/image-dev.stories.tsx +128 -0
  14. package/src/image-loaders.ts +47 -0
  15. package/{lib/image-optimize.test.js → src/image-optimize.test.ts} +122 -103
  16. package/{lib/cjs/image-optimize.d.ts → src/image-optimize.ts} +172 -19
  17. package/src/image.tsx +74 -0
  18. package/{lib/cjs/index.d.ts → src/index.ts} +0 -1
  19. package/lib/cjs/image-dev.stories.cjs +0 -77
  20. package/lib/cjs/image-dev.stories.d.ts +0 -35
  21. package/lib/cjs/image-dev.stories.d.ts.map +0 -1
  22. package/lib/cjs/image-loaders.d.ts +0 -14
  23. package/lib/cjs/image-loaders.d.ts.map +0 -1
  24. package/lib/cjs/image-optimize.d.ts.map +0 -1
  25. package/lib/cjs/image-optimize.test.cjs +0 -157
  26. package/lib/cjs/image-optimize.test.d.ts +0 -2
  27. package/lib/cjs/image-optimize.test.d.ts.map +0 -1
  28. package/lib/cjs/image.d.ts +0 -11
  29. package/lib/cjs/image.d.ts.map +0 -1
  30. package/lib/cjs/index.d.ts.map +0 -1
  31. package/lib/image-dev.stories.d.ts +0 -35
  32. package/lib/image-dev.stories.d.ts.map +0 -1
  33. package/lib/image-dev.stories.js +0 -65
  34. package/lib/image-loaders.d.ts +0 -14
  35. package/lib/image-loaders.d.ts.map +0 -1
  36. package/lib/image-optimize.d.ts +0 -107
  37. package/lib/image-optimize.d.ts.map +0 -1
  38. package/lib/image-optimize.test.d.ts +0 -2
  39. package/lib/image-optimize.test.d.ts.map +0 -1
  40. package/lib/image.d.ts +0 -11
  41. package/lib/image.d.ts.map +0 -1
  42. package/lib/index.d.ts +0 -5
  43. package/lib/index.d.ts.map +0 -1
  44. package/lib/tsconfig.tsbuildinfo +0 -1
@@ -1,39 +1,54 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.localImageLoader = exports.cloudflareImageLoader = void 0;
7
- const warn_once_1 = __importDefault(require("warn-once"));
8
- const image_optimize_1 = require("./image-optimize");
9
- /**
10
- * Default image loader in case of no loader provided
11
- * https://developers.cloudflare.com/images/image-resizing/url-format/
12
- **/
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var image_loaders_exports = {};
26
+ __export(image_loaders_exports, {
27
+ cloudflareImageLoader: () => cloudflareImageLoader,
28
+ localImageLoader: () => localImageLoader
29
+ });
30
+ module.exports = __toCommonJS(image_loaders_exports);
31
+ var import_warn_once = __toESM(require("warn-once"), 1);
32
+ var import_image_optimize = require("./image-optimize");
13
33
  const cloudflareImageLoader = (loaderOptions) => ({ width, src, quality }) => {
14
- if (process.env.NODE_ENV !== "production") {
15
- (0, warn_once_1.default)(image_optimize_1.allSizes.includes(width) === false, "Width must be only from allowed values");
16
- }
17
- const options = `width=${width},quality=${quality},format=auto`;
18
- // Cloudflare docs say that we don't need to urlencode the path params
19
- const pathname = `/cdn-cgi/image/${options}/${src}`;
20
- if (loaderOptions?.resizeOrigin != null) {
21
- const url = new URL(pathname, loaderOptions.resizeOrigin);
22
- return url.href;
23
- }
24
- else {
25
- return pathname;
26
- }
34
+ if (true) {
35
+ (0, import_warn_once.default)(
36
+ import_image_optimize.allSizes.includes(width) === false,
37
+ "Width must be only from allowed values"
38
+ );
39
+ }
40
+ const options = `width=${width},quality=${quality},format=auto`;
41
+ const pathname = `/cdn-cgi/image/${options}/${src}`;
42
+ if (loaderOptions?.resizeOrigin != null) {
43
+ const url = new URL(pathname, loaderOptions.resizeOrigin);
44
+ return url.href;
45
+ } else {
46
+ return pathname;
47
+ }
27
48
  };
28
- exports.cloudflareImageLoader = cloudflareImageLoader;
29
- /**
30
- * Fake pseudo loader for local testing purposes
31
- **/
32
49
  const localImageLoader = () => ({ width, src, quality }) => {
33
- // Just emulate like we really resize the image
34
- const params = new URLSearchParams();
35
- params.set("width", `${width}`);
36
- params.set("quality", `${quality}`);
37
- return `${src}?${params.toString()}`;
50
+ const params = new URLSearchParams();
51
+ params.set("width", `${width}`);
52
+ params.set("quality", `${quality}`);
53
+ return `${src}?${params.toString()}`;
38
54
  };
39
- exports.localImageLoader = localImageLoader;
@@ -1,187 +1,117 @@
1
1
  "use strict";
2
- /**
3
- * # Responsive Image component helpers.
4
- *
5
- * ## Quick summary about img srcset and sizes attributes:
6
- *
7
- * There are 2 ways to define what image will be loaded in the img property srcset.
8
- *
9
- * 1. via pixel density descriptor 'x', like `srcset="photo-small.jpg 1x, photo-medium.jpg 1.5x, photo-huge.jpg 2x"`
10
- * src will be selected depending on `device-pixel-ratio`.
11
- *
12
- * 2. via viewport width descriptor 'w' and sizes property containing source size descriptors, like
13
- * `srcset="photo-small.jpg 320w, photo-medium.jpg 640w, photo-huge.jpg 1280w"`
14
- * `sizes="(max-width: 600px) 400px, (max-width: 1200px) 70vw, 50vw"`
15
- *
16
- * The browser finds the first matching media query from source size descriptors,
17
- * then use source size value to generate internally srcset
18
- * with pixel density descriptors dividing width descriptor value by source size value.
19
- *
20
- * Using the example above for viewport width 800px.
21
- * The first matching media query is (max-width: 1200px)
22
- * source size value is 70vw equal to 800px * 0,7 = 560px
23
- *
24
- * browser internal srcset will be (we divide `w` descriptor by source size value):
25
- * photo-small.jpg 320/560x, photo-medium.jpg 640/560x, photo-huge.jpg 1280/560x =>
26
- * photo-small.jpg 0.57x, photo-medium.jpg 1.14x, photo-huge.jpg 2.28x
27
- *
28
- * Finally same rules as for pixel density descriptor 'x' are applied.
29
- *
30
- * ## Algorithm (without optimizations):
31
- *
32
- * We have a predefined array of all supported image sizes allSizes, this is the real width of an image in pixels.
33
- * This is good for caching, as we can cache image with specific width and then use it for different devices.
34
- *
35
- * > allSizes array is a tradeoff between cache and the best possible image size you deliver to the user.
36
- * > If allSizes.length is too small, you will deliver too big images to the user,
37
- * > if allSizes.length is too big, you will have many caches misses.
38
- *
39
- * If img has a defined width property.
40
- * 1. find the first value from allSizes which is greater or equal to the width property
41
- * 2. use found value to generate srcset with pixel density descriptor 'x'
42
- *
43
- *
44
- * If img has no defined width property.
45
- * 1. Generate srcset = allSizes.map((w) => `${getImageSrcAtWidth(w)} ${w}w`)
46
- * 2. Use sizes property, or if it is not defined use opinionated DEFAULT_SIZES = "(min-width: 1280px) 50vw, 100vw";
47
- *
48
- * Optimizations applied now:
49
- *
50
- * - If the sizes property is defined, we can exclude from `srcsets` all images
51
- * which are smaller than the `smallestRatio * smallesDeviceSize`
52
- *
53
- * Future (not implemented) optimizations and improvements:
54
- *
55
- * - Knowing image size on different viewport widths we can provide nondefault sizes property
56
- * - Knowledge of Image aspect-ratio would allow cropping images serverside.
57
- * - Early hints for high priority images https://blog.cloudflare.com/early-hints/
58
- * - Slow networks optimizations
59
- * - 404 etc processing with CSS - https://bitsofco.de/styling-broken-images/ (has some opinionated issues) or js solution with custom user fallback.
60
- *
61
- * # Attributions
62
- *
63
- * The MIT License (MIT)
64
- *
65
- * applies to:
66
- *
67
- * - https://github.com/vercel/next.js, Copyright (c) 2022 Vercel, Inc.
68
- *
69
- * The MIT License (MIT)
70
- *
71
- * Copyright (c) 2022 Vercel, Inc.
72
- *
73
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
74
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
75
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
76
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
77
- * is furnished to do so, subject to the following conditions:
78
- *
79
- * The above copyright notice and this permission notice shall be included in all copies
80
- * or substantial portions of the Software.
81
- *
82
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
83
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
84
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
85
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
86
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
87
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88
- **/
89
- Object.defineProperty(exports, "__esModule", { value: true });
90
- exports.getImageAttributes = exports.allSizes = void 0;
91
- /**
92
- * max(...imageSizes) must be less then min(...deviceSizes)
93
- **/
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var image_optimize_exports = {};
20
+ __export(image_optimize_exports, {
21
+ allSizes: () => allSizes,
22
+ getImageAttributes: () => getImageAttributes
23
+ });
24
+ module.exports = __toCommonJS(image_optimize_exports);
94
25
  const imageSizes = [16, 32, 48, 64, 96, 128, 256, 384];
95
26
  const deviceSizes = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
96
- exports.allSizes = [...imageSizes, ...deviceSizes];
97
- /**
98
- * https://github.com/vercel/next.js/blob/canary/packages/next/client/image.tsx
99
- **/
27
+ const allSizes = [...imageSizes, ...deviceSizes];
100
28
  const getWidths = (width, sizes) => {
101
- if (sizes) {
102
- // Find all the "vw" percent sizes used in the sizes prop
103
- const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g;
104
- const percentSizes = [];
105
- for (let match; (match = viewportWidthRe.exec(sizes)); match) {
106
- percentSizes.push(parseInt(match[2], 10));
107
- }
108
- if (percentSizes.length) {
109
- // we can exclude from srcSets all images which are smaller than the smallestRatio * smallesDeviceSize
110
- const smallestRatio = Math.min(...percentSizes) * 0.01;
111
- return {
112
- widths: exports.allSizes.filter((s) => s >= deviceSizes[0] * smallestRatio),
113
- kind: "w",
114
- };
115
- }
116
- return { widths: exports.allSizes, kind: "w" };
29
+ if (sizes) {
30
+ const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g;
31
+ const percentSizes = [];
32
+ for (let match; match = viewportWidthRe.exec(sizes); match) {
33
+ percentSizes.push(parseInt(match[2], 10));
117
34
  }
118
- if (width == null) {
119
- return { widths: deviceSizes, kind: "w" };
35
+ if (percentSizes.length) {
36
+ const smallestRatio = Math.min(...percentSizes) * 0.01;
37
+ return {
38
+ widths: allSizes.filter((s) => s >= deviceSizes[0] * smallestRatio),
39
+ kind: "w"
40
+ };
120
41
  }
121
- const widths = [
122
- ...new Set([width, width * 2].map((w) => exports.allSizes.find((p) => p >= w) || exports.allSizes[exports.allSizes.length - 1])),
123
- ];
124
- return { widths, kind: "x" };
42
+ return { widths: allSizes, kind: "w" };
43
+ }
44
+ if (width == null) {
45
+ return { widths: deviceSizes, kind: "w" };
46
+ }
47
+ const widths = [
48
+ ...new Set(
49
+ [width, width * 2].map(
50
+ (w) => allSizes.find((p) => p >= w) || allSizes[allSizes.length - 1]
51
+ )
52
+ )
53
+ ];
54
+ return { widths, kind: "x" };
125
55
  };
126
- const generateImgAttrs = ({ src, width, quality, sizes, loader, }) => {
127
- const { widths, kind } = getWidths(width, sizes);
128
- return {
129
- sizes: !sizes && kind === "w" ? "100vw" : sizes,
130
- srcSet: widths
131
- .map((w, i) => `${loader({ src, quality, width: w })} ${kind === "w" ? w : i + 1}${kind}`)
132
- .join(", "),
133
- // Must be last, to prevent Safari to load images twice
134
- src: loader({
135
- src,
136
- quality,
137
- width: widths[widths.length - 1],
138
- }),
139
- };
56
+ const generateImgAttrs = ({
57
+ src,
58
+ width,
59
+ quality,
60
+ sizes,
61
+ loader
62
+ }) => {
63
+ const { widths, kind } = getWidths(width, sizes);
64
+ return {
65
+ sizes: !sizes && kind === "w" ? "100vw" : sizes,
66
+ srcSet: widths.map(
67
+ (w, i) => `${loader({ src, quality, width: w })} ${kind === "w" ? w : i + 1}${kind}`
68
+ ).join(", "),
69
+ src: loader({
70
+ src,
71
+ quality,
72
+ width: widths[widths.length - 1]
73
+ })
74
+ };
140
75
  };
141
76
  const getInt = (value) => {
142
- if (typeof value === "number") {
143
- return Math.round(value);
144
- }
145
- if (typeof value === "string") {
146
- const vNum = Number.parseFloat(value);
147
- if (!Number.isNaN(vNum)) {
148
- return Math.round(vNum);
149
- }
77
+ if (typeof value === "number") {
78
+ return Math.round(value);
79
+ }
80
+ if (typeof value === "string") {
81
+ const vNum = Number.parseFloat(value);
82
+ if (!Number.isNaN(vNum)) {
83
+ return Math.round(vNum);
150
84
  }
151
- return undefined;
85
+ }
86
+ return void 0;
152
87
  };
153
- /**
154
- * DEFAULT_SIZES Just an assumption that most images (except hero and icons) are 100% wide on mobile and 50% on desktop.
155
- * For icons width are usually set explicitly so DEFAULT_SIZES is not applied.
156
- * For hero images, we can allow in UI to select sizes=100vw explicitly.
157
- * Anyway, the best would be to calculate this based on canvas data from different breakpoints.
158
- * See ../component-utils/image for detailed description
159
- **/
160
88
  const DEFAULT_SIZES = "(min-width: 1280px) 50vw, 100vw";
161
89
  const DEFAULT_QUALITY = 80;
162
90
  const getImageAttributes = (props) => {
163
- const width = getInt(props.width);
164
- const quality = Math.max(Math.min(getInt(props.quality) ?? DEFAULT_QUALITY, 100), 0);
165
- if (props.src != null && props.src != "") {
166
- if (props.srcSet == null && props.optimize) {
167
- const sizes = props.sizes ?? (props.width == null ? DEFAULT_SIZES : undefined);
168
- return generateImgAttrs({
169
- src: props.src,
170
- width,
171
- quality,
172
- sizes,
173
- loader: props.loader,
174
- });
175
- }
176
- const resAttrs = { src: props.src };
177
- if (props.srcSet != null) {
178
- resAttrs.srcSet = props.srcSet;
179
- }
180
- if (props.sizes != null) {
181
- resAttrs.sizes = props.sizes;
182
- }
183
- return resAttrs;
91
+ const width = getInt(props.width);
92
+ const quality = Math.max(
93
+ Math.min(getInt(props.quality) ?? DEFAULT_QUALITY, 100),
94
+ 0
95
+ );
96
+ if (props.src != null && props.src !== "") {
97
+ if (props.srcSet == null && props.optimize) {
98
+ const sizes = props.sizes ?? (props.width == null ? DEFAULT_SIZES : void 0);
99
+ return generateImgAttrs({
100
+ src: props.src,
101
+ width,
102
+ quality,
103
+ sizes,
104
+ loader: props.loader
105
+ });
106
+ }
107
+ const resAttrs = { src: props.src };
108
+ if (props.srcSet != null) {
109
+ resAttrs.srcSet = props.srcSet;
110
+ }
111
+ if (props.sizes != null) {
112
+ resAttrs.sizes = props.sizes;
184
113
  }
185
- return null;
114
+ return resAttrs;
115
+ }
116
+ return null;
186
117
  };
187
- exports.getImageAttributes = getImageAttributes;
package/lib/cjs/image.cjs CHANGED
@@ -1,29 +1,61 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Image = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const image_optimize_1 = require("./image-optimize");
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var image_exports = {};
20
+ __export(image_exports, {
21
+ Image: () => Image
22
+ });
23
+ module.exports = __toCommonJS(image_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_react = require("react");
26
+ var import_image_optimize = require("./image-optimize");
7
27
  const defaultTag = "img";
8
- exports.Image = (0, react_1.forwardRef)(({ quality, loader, optimize, ...imageProps }, ref) => {
9
- // Temporary set to false, to support previous image behaviour
10
- const DEFAULT_OPTIMIZE = false;
11
- const imageAttributes = (0, image_optimize_1.getImageAttributes)({
12
- src: imageProps.src,
13
- srcSet: imageProps.srcSet,
14
- sizes: imageProps.sizes,
15
- width: imageProps.width,
16
- quality,
17
- loader,
18
- optimize: optimize ?? DEFAULT_OPTIMIZE,
28
+ const Image = (0, import_react.forwardRef)(
29
+ ({
30
+ quality,
31
+ loader,
32
+ optimize = true,
33
+ loading = "lazy",
34
+ decoding = "async",
35
+ ...imageProps
36
+ }, ref) => {
37
+ const imageAttributes = (0, import_image_optimize.getImageAttributes)({
38
+ src: imageProps.src,
39
+ srcSet: imageProps.srcSet,
40
+ sizes: imageProps.sizes,
41
+ width: imageProps.width,
42
+ quality,
43
+ loader,
44
+ optimize
19
45
  }) ?? { src: imagePlaceholderSvg };
20
- return ((0, jsx_runtime_1.jsx)("img", { ...imageProps, ...imageAttributes, decoding: "async", ref: ref }));
21
- });
22
- exports.Image.defaultProps = {
23
- src: "",
24
- loading: "lazy",
46
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
47
+ ...imageProps,
48
+ ...imageAttributes,
49
+ decoding,
50
+ loading,
51
+ ref
52
+ });
53
+ }
54
+ );
55
+ Image.defaultProps = {
56
+ src: ""
25
57
  };
26
- exports.Image.displayName = "Image";
58
+ Image.displayName = "Image";
27
59
  const imagePlaceholderSvg = `data:image/svg+xml;base64,${btoa(`<svg
28
60
  width="140"
29
61
  height="140"
package/lib/cjs/index.cjs CHANGED
@@ -1,34 +1,34 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
24
11
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
27
19
  };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.imageProps = exports.loaders = exports.Image = void 0;
30
- var image_1 = require("./image");
31
- Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return image_1.Image; } });
32
- exports.loaders = __importStar(require("./image-loaders"));
33
- var image_props_json_1 = require("./__generated__/image.props.json");
34
- Object.defineProperty(exports, "imageProps", { enumerable: true, get: function () { return __importDefault(image_props_json_1).default; } });
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var src_exports = {};
26
+ __export(src_exports, {
27
+ Image: () => import_image.Image,
28
+ imageProps: () => import_image_props.default,
29
+ loaders: () => loaders
30
+ });
31
+ module.exports = __toCommonJS(src_exports);
32
+ var import_image = require("./image");
33
+ var loaders = __toESM(require("./image-loaders"), 1);
34
+ var import_image_props = __toESM(require("./__generated__/image.props.json"), 1);
@@ -1,31 +1,28 @@
1
1
  import warnOnce from "warn-once";
2
2
  import { allSizes } from "./image-optimize";
3
- /**
4
- * Default image loader in case of no loader provided
5
- * https://developers.cloudflare.com/images/image-resizing/url-format/
6
- **/
7
- export const cloudflareImageLoader = (loaderOptions) => ({ width, src, quality }) => {
8
- if (process.env.NODE_ENV !== "production") {
9
- warnOnce(allSizes.includes(width) === false, "Width must be only from allowed values");
10
- }
11
- const options = `width=${width},quality=${quality},format=auto`;
12
- // Cloudflare docs say that we don't need to urlencode the path params
13
- const pathname = `/cdn-cgi/image/${options}/${src}`;
14
- if (loaderOptions?.resizeOrigin != null) {
15
- const url = new URL(pathname, loaderOptions.resizeOrigin);
16
- return url.href;
17
- }
18
- else {
19
- return pathname;
20
- }
3
+ const cloudflareImageLoader = (loaderOptions) => ({ width, src, quality }) => {
4
+ if (true) {
5
+ warnOnce(
6
+ allSizes.includes(width) === false,
7
+ "Width must be only from allowed values"
8
+ );
9
+ }
10
+ const options = `width=${width},quality=${quality},format=auto`;
11
+ const pathname = `/cdn-cgi/image/${options}/${src}`;
12
+ if (loaderOptions?.resizeOrigin != null) {
13
+ const url = new URL(pathname, loaderOptions.resizeOrigin);
14
+ return url.href;
15
+ } else {
16
+ return pathname;
17
+ }
21
18
  };
22
- /**
23
- * Fake pseudo loader for local testing purposes
24
- **/
25
- export const localImageLoader = () => ({ width, src, quality }) => {
26
- // Just emulate like we really resize the image
27
- const params = new URLSearchParams();
28
- params.set("width", `${width}`);
29
- params.set("quality", `${quality}`);
30
- return `${src}?${params.toString()}`;
19
+ const localImageLoader = () => ({ width, src, quality }) => {
20
+ const params = new URLSearchParams();
21
+ params.set("width", `${width}`);
22
+ params.set("quality", `${quality}`);
23
+ return `${src}?${params.toString()}`;
24
+ };
25
+ export {
26
+ cloudflareImageLoader,
27
+ localImageLoader
31
28
  };