@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.
- package/lib/__generated__/image.props.json +573 -573
- package/lib/cjs/__generated__/image.props.json +573 -573
- package/lib/cjs/image-loaders.cjs +48 -33
- package/lib/cjs/image-optimize.cjs +101 -171
- package/lib/cjs/image.cjs +54 -22
- package/lib/cjs/index.cjs +31 -31
- package/lib/image-loaders.js +24 -27
- package/lib/image-optimize.js +83 -169
- package/lib/image.js +30 -15
- package/lib/index.js +8 -3
- package/package.json +9 -16
- package/src/__generated__/image.props.json +575 -0
- package/src/image-dev.stories.tsx +128 -0
- package/src/image-loaders.ts +47 -0
- package/{lib/image-optimize.test.js → src/image-optimize.test.ts} +122 -103
- package/{lib/cjs/image-optimize.d.ts → src/image-optimize.ts} +172 -19
- package/src/image.tsx +74 -0
- package/{lib/cjs/index.d.ts → src/index.ts} +0 -1
- package/lib/cjs/image-dev.stories.cjs +0 -77
- package/lib/cjs/image-dev.stories.d.ts +0 -35
- package/lib/cjs/image-dev.stories.d.ts.map +0 -1
- package/lib/cjs/image-loaders.d.ts +0 -14
- package/lib/cjs/image-loaders.d.ts.map +0 -1
- package/lib/cjs/image-optimize.d.ts.map +0 -1
- package/lib/cjs/image-optimize.test.cjs +0 -157
- package/lib/cjs/image-optimize.test.d.ts +0 -2
- package/lib/cjs/image-optimize.test.d.ts.map +0 -1
- package/lib/cjs/image.d.ts +0 -11
- package/lib/cjs/image.d.ts.map +0 -1
- package/lib/cjs/index.d.ts.map +0 -1
- package/lib/image-dev.stories.d.ts +0 -35
- package/lib/image-dev.stories.d.ts.map +0 -1
- package/lib/image-dev.stories.js +0 -65
- package/lib/image-loaders.d.ts +0 -14
- package/lib/image-loaders.d.ts.map +0 -1
- package/lib/image-optimize.d.ts +0 -107
- package/lib/image-optimize.d.ts.map +0 -1
- package/lib/image-optimize.test.d.ts +0 -2
- package/lib/image-optimize.test.d.ts.map +0 -1
- package/lib/image.d.ts +0 -11
- package/lib/image.d.ts.map +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.d.ts.map +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
|
@@ -1,39 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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 (
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return { widths, kind: "
|
|
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 = ({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
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);
|
package/lib/image-loaders.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import warnOnce from "warn-once";
|
|
2
2
|
import { allSizes } from "./image-optimize";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
};
|