@webstudio-is/image 0.192.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 +13 -12
- package/lib/types/image-loaders.d.ts +6 -4
- package/lib/types/image.d.ts +2 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/image.tsx
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
forwardRef
|
|
4
|
+
} from "react";
|
|
3
5
|
|
|
4
6
|
// src/image-optimize.ts
|
|
5
7
|
var imageSizes = [16, 32, 48, 64, 96, 128, 256, 384];
|
|
@@ -176,24 +178,21 @@ var joinPath = (...segments) => {
|
|
|
176
178
|
var encodePathFragment = (fragment) => {
|
|
177
179
|
return encodeURIComponent(fragment).replace(/%2F/g, "/");
|
|
178
180
|
};
|
|
179
|
-
var
|
|
181
|
+
var wsImageLoader = (props) => {
|
|
180
182
|
const width = props.format === "raw" ? 16 : props.width;
|
|
181
183
|
const quality = props.format === "raw" ? 100 : props.quality;
|
|
182
|
-
const { format, src } = props;
|
|
183
184
|
if (true) {
|
|
184
185
|
warnOnce(
|
|
185
186
|
allSizes.includes(width) === false,
|
|
186
187
|
"Width must be only from allowed values"
|
|
187
188
|
);
|
|
188
189
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
resultUrl = new URL(imageBaseUrl, NON_EXISTING_DOMAIN);
|
|
193
|
-
} catch {
|
|
194
|
-
return src;
|
|
190
|
+
let src = props.src;
|
|
191
|
+
if (src.startsWith("/cgi/asset")) {
|
|
192
|
+
src = src.slice("/cgi/asset".length);
|
|
195
193
|
}
|
|
196
|
-
|
|
194
|
+
const resultUrl = new URL("/cgi/image/", NON_EXISTING_DOMAIN);
|
|
195
|
+
if (props.format !== "raw") {
|
|
197
196
|
resultUrl.searchParams.set("width", width.toString());
|
|
198
197
|
resultUrl.searchParams.set("quality", quality.toString());
|
|
199
198
|
if (props.height != null) {
|
|
@@ -203,18 +202,20 @@ var createImageLoader = (loaderOptions) => (props) => {
|
|
|
203
202
|
resultUrl.searchParams.set("fit", props.fit);
|
|
204
203
|
}
|
|
205
204
|
}
|
|
206
|
-
resultUrl.searchParams.set("format", format ?? "auto");
|
|
205
|
+
resultUrl.searchParams.set("format", props.format ?? "auto");
|
|
207
206
|
resultUrl.pathname = joinPath(resultUrl.pathname, encodePathFragment(src));
|
|
208
207
|
if (resultUrl.href.startsWith(NON_EXISTING_DOMAIN)) {
|
|
209
208
|
return `${resultUrl.pathname}?${resultUrl.searchParams.toString()}`;
|
|
210
209
|
}
|
|
211
210
|
return resultUrl.href;
|
|
212
211
|
};
|
|
212
|
+
var createImageLoader = (_loaderOptions) => wsImageLoader;
|
|
213
213
|
export {
|
|
214
214
|
Image,
|
|
215
215
|
UrlCanParse,
|
|
216
216
|
allSizes,
|
|
217
217
|
createImageLoader,
|
|
218
218
|
getImageAttributes,
|
|
219
|
-
imagePlaceholderDataUrl
|
|
219
|
+
imagePlaceholderDataUrl,
|
|
220
|
+
wsImageLoader
|
|
220
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 {};
|
package/lib/types/image.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ComponentProps } from "react";
|
|
1
|
+
import { type ComponentProps, type ForwardRefExoticComponent } from "react";
|
|
2
2
|
import { type ImageLoader } from "./image-optimize";
|
|
3
3
|
declare const defaultTag = "img";
|
|
4
4
|
type ImageProps = ComponentProps<typeof defaultTag> & {
|
|
@@ -6,6 +6,6 @@ type ImageProps = ComponentProps<typeof defaultTag> & {
|
|
|
6
6
|
optimize?: boolean;
|
|
7
7
|
loader: ImageLoader;
|
|
8
8
|
};
|
|
9
|
-
export declare const Image:
|
|
9
|
+
export declare const Image: ForwardRefExoticComponent<ImageProps>;
|
|
10
10
|
export declare const imagePlaceholderDataUrl: string;
|
|
11
11
|
export {};
|