@webstudio-is/image 0.193.0 → 0.194.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 +10 -11
- package/lib/types/image-loaders.d.ts +6 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -178,24 +178,21 @@ var joinPath = (...segments) => {
|
|
|
178
178
|
var encodePathFragment = (fragment) => {
|
|
179
179
|
return encodeURIComponent(fragment).replace(/%2F/g, "/");
|
|
180
180
|
};
|
|
181
|
-
var
|
|
181
|
+
var wsImageLoader = (props) => {
|
|
182
182
|
const width = props.format === "raw" ? 16 : props.width;
|
|
183
183
|
const quality = props.format === "raw" ? 100 : props.quality;
|
|
184
|
-
const { format, src } = props;
|
|
185
184
|
if (true) {
|
|
186
185
|
warnOnce(
|
|
187
186
|
allSizes.includes(width) === false,
|
|
188
187
|
"Width must be only from allowed values"
|
|
189
188
|
);
|
|
190
189
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
resultUrl = new URL(imageBaseUrl, NON_EXISTING_DOMAIN);
|
|
195
|
-
} catch {
|
|
196
|
-
return src;
|
|
190
|
+
let src = props.src;
|
|
191
|
+
if (src.startsWith("/cgi/asset")) {
|
|
192
|
+
src = src.slice("/cgi/asset".length);
|
|
197
193
|
}
|
|
198
|
-
|
|
194
|
+
const resultUrl = new URL("/cgi/image/", NON_EXISTING_DOMAIN);
|
|
195
|
+
if (props.format !== "raw") {
|
|
199
196
|
resultUrl.searchParams.set("width", width.toString());
|
|
200
197
|
resultUrl.searchParams.set("quality", quality.toString());
|
|
201
198
|
if (props.height != null) {
|
|
@@ -205,18 +202,20 @@ var createImageLoader = (loaderOptions) => (props) => {
|
|
|
205
202
|
resultUrl.searchParams.set("fit", props.fit);
|
|
206
203
|
}
|
|
207
204
|
}
|
|
208
|
-
resultUrl.searchParams.set("format", format ?? "auto");
|
|
205
|
+
resultUrl.searchParams.set("format", props.format ?? "auto");
|
|
209
206
|
resultUrl.pathname = joinPath(resultUrl.pathname, encodePathFragment(src));
|
|
210
207
|
if (resultUrl.href.startsWith(NON_EXISTING_DOMAIN)) {
|
|
211
208
|
return `${resultUrl.pathname}?${resultUrl.searchParams.toString()}`;
|
|
212
209
|
}
|
|
213
210
|
return resultUrl.href;
|
|
214
211
|
};
|
|
212
|
+
var createImageLoader = (_loaderOptions) => wsImageLoader;
|
|
215
213
|
export {
|
|
216
214
|
Image,
|
|
217
215
|
UrlCanParse,
|
|
218
216
|
allSizes,
|
|
219
217
|
createImageLoader,
|
|
220
218
|
getImageAttributes,
|
|
221
|
-
imagePlaceholderDataUrl
|
|
219
|
+
imagePlaceholderDataUrl,
|
|
220
|
+
wsImageLoader
|
|
222
221
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type ImageLoader } from "./image-optimize";
|
|
2
|
-
export type ImageLoaderOptions = {
|
|
3
|
-
imageBaseUrl: string;
|
|
4
|
-
};
|
|
5
2
|
/**
|
|
6
3
|
* Default image loader in case of no loader provided
|
|
7
4
|
* https://developers.cloudflare.com/images/image-resizing/url-format/
|
|
8
5
|
**/
|
|
9
|
-
export declare const
|
|
6
|
+
export declare const wsImageLoader: ImageLoader;
|
|
7
|
+
type ImageLoaderOptions = {
|
|
8
|
+
imageBaseUrl?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const createImageLoader: (_loaderOptions: ImageLoaderOptions) => ImageLoader;
|
|
11
|
+
export {};
|