@webstudio-is/image 0.168.0 → 0.174.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/index.js +24 -13
- package/lib/types/image-loader.test.d.ts +1 -0
- package/package.json +2 -4
package/lib/index.js
CHANGED
|
@@ -140,7 +140,7 @@ var imagePlaceholderSvg = `data:image/svg+xml;base64,${btoa(`<svg
|
|
|
140
140
|
fill="none"
|
|
141
141
|
xmlns="http://www.w3.org/2000/svg"
|
|
142
142
|
>
|
|
143
|
-
<rect width="600" height="600" />
|
|
143
|
+
<rect width="600" height="600" fill="hsla(0, 0%, 80%, 0.2)" />
|
|
144
144
|
<path
|
|
145
145
|
fill-rule="evenodd"
|
|
146
146
|
clip-rule="evenodd"
|
|
@@ -159,15 +159,17 @@ var imagePlaceholderSvg = `data:image/svg+xml;base64,${btoa(`<svg
|
|
|
159
159
|
|
|
160
160
|
// src/image-loaders.ts
|
|
161
161
|
import warnOnce from "warn-once";
|
|
162
|
+
var NON_EXISTING_DOMAIN = "https://a3cbcbec-cdb1-4ea4-ad60-43c795308ddc.ddc";
|
|
163
|
+
var joinPath = (...segments) => {
|
|
164
|
+
return segments.filter((segment) => segment !== "").map((segment) => segment.replace(/(^\/+|\/+$)/g, "")).join("/");
|
|
165
|
+
};
|
|
166
|
+
var encodePathFragment = (fragment) => {
|
|
167
|
+
return encodeURIComponent(fragment).replace(/%2F/g, "/");
|
|
168
|
+
};
|
|
162
169
|
var createImageLoader = (loaderOptions) => (props) => {
|
|
163
170
|
const width = props.format === "raw" ? 16 : props.width;
|
|
164
171
|
const quality = props.format === "raw" ? 100 : props.quality;
|
|
165
172
|
const { format, src } = props;
|
|
166
|
-
try {
|
|
167
|
-
new URL(src);
|
|
168
|
-
return src;
|
|
169
|
-
} catch {
|
|
170
|
-
}
|
|
171
173
|
if (true) {
|
|
172
174
|
warnOnce(
|
|
173
175
|
allSizes.includes(width) === false,
|
|
@@ -175,17 +177,26 @@ var createImageLoader = (loaderOptions) => (props) => {
|
|
|
175
177
|
);
|
|
176
178
|
}
|
|
177
179
|
const { imageBaseUrl } = loaderOptions;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
let resultUrl;
|
|
181
|
+
try {
|
|
182
|
+
resultUrl = new URL(imageBaseUrl, NON_EXISTING_DOMAIN);
|
|
183
|
+
} catch {
|
|
184
|
+
return src;
|
|
185
|
+
}
|
|
186
|
+
resultUrl.searchParams.set("width", width.toString());
|
|
187
|
+
resultUrl.searchParams.set("quality", quality.toString());
|
|
188
|
+
resultUrl.searchParams.set("format", format ?? "auto");
|
|
182
189
|
if (props.format !== "raw" && props.height != null) {
|
|
183
|
-
searchParams.set("height", props.height.toString());
|
|
190
|
+
resultUrl.searchParams.set("height", props.height.toString());
|
|
184
191
|
}
|
|
185
192
|
if (props.format !== "raw" && props.fit != null) {
|
|
186
|
-
searchParams.set("fit", props.fit);
|
|
193
|
+
resultUrl.searchParams.set("fit", props.fit);
|
|
194
|
+
}
|
|
195
|
+
resultUrl.pathname = joinPath(resultUrl.pathname, encodePathFragment(src));
|
|
196
|
+
if (resultUrl.href.startsWith(NON_EXISTING_DOMAIN)) {
|
|
197
|
+
return `${resultUrl.pathname}?${resultUrl.searchParams.toString()}`;
|
|
187
198
|
}
|
|
188
|
-
return
|
|
199
|
+
return resultUrl.href;
|
|
189
200
|
};
|
|
190
201
|
export {
|
|
191
202
|
Image,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/image",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.174.0",
|
|
4
4
|
"description": "Image optimization",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@types/react-dom": "^18.2.25",
|
|
16
16
|
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
17
17
|
"react-dom": "18.3.0-canary-14898b6a9-20240318",
|
|
18
|
-
"typescript": "5.
|
|
18
|
+
"typescript": "5.5.2",
|
|
19
19
|
"@webstudio-is/jest-config": "1.0.7",
|
|
20
20
|
"@webstudio-is/tsconfig": "1.0.7"
|
|
21
21
|
},
|
|
@@ -38,8 +38,6 @@
|
|
|
38
38
|
"scripts": {
|
|
39
39
|
"typecheck": "tsc",
|
|
40
40
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
41
|
-
"checks": "pnpm typecheck && pnpm test",
|
|
42
|
-
"dev": "rm -rf lib && esbuild 'src/**/*.ts' 'src/**/*.tsx' --outdir=lib --watch",
|
|
43
41
|
"build": "rm -rf lib && esbuild src/index.ts --outdir=lib --bundle --format=esm --packages=external",
|
|
44
42
|
"dts": "tsc --project tsconfig.dts.json"
|
|
45
43
|
}
|