@webstudio-is/image 0.53.0 → 0.54.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/cjs/image-loaders.js +3 -2
- package/lib/cjs/image-optimize.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/image-loaders.js +3 -2
- package/lib/image-optimize.js +1 -1
- package/lib/index.js +1 -1
- package/lib/types/image-loaders.d.ts +5 -1
- package/package.json +3 -3
- package/src/image-dev.stories.tsx +1 -1
- package/src/image-loaders.ts +8 -3
- package/src/image-optimize.ts +1 -1
- package/src/index.ts +1 -1
package/lib/cjs/image-loaders.js
CHANGED
|
@@ -50,9 +50,10 @@ const cloudflareImageLoader = (loaderOptions) => ({ width, src, quality }) => {
|
|
|
50
50
|
return pathname;
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
const localImageLoader = () => ({ width, src, quality }) => {
|
|
53
|
+
const localImageLoader = (options) => ({ width, src, quality }) => {
|
|
54
|
+
const { publicPath = "/" } = options;
|
|
54
55
|
const params = new URLSearchParams();
|
|
55
56
|
params.set("width", `${width}`);
|
|
56
57
|
params.set("quality", `${quality}`);
|
|
57
|
-
return `${src}?${params.toString()}`;
|
|
58
|
+
return `${publicPath}${src}?${params.toString()}`;
|
|
58
59
|
};
|
|
@@ -30,7 +30,7 @@ const getWidths = (width, sizes) => {
|
|
|
30
30
|
const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g;
|
|
31
31
|
const percentSizes = [];
|
|
32
32
|
for (let match; match = viewportWidthRe.exec(sizes); match) {
|
|
33
|
-
percentSizes.push(parseInt(match[2], 10));
|
|
33
|
+
percentSizes.push(Number.parseInt(match[2], 10));
|
|
34
34
|
}
|
|
35
35
|
if (percentSizes.length) {
|
|
36
36
|
const smallestRatio = Math.min(...percentSizes) * 0.01;
|
package/lib/cjs/index.js
CHANGED
package/lib/image-loaders.js
CHANGED
|
@@ -16,11 +16,12 @@ const cloudflareImageLoader = (loaderOptions) => ({ width, src, quality }) => {
|
|
|
16
16
|
return pathname;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
const localImageLoader = () => ({ width, src, quality }) => {
|
|
19
|
+
const localImageLoader = (options) => ({ width, src, quality }) => {
|
|
20
|
+
const { publicPath = "/" } = options;
|
|
20
21
|
const params = new URLSearchParams();
|
|
21
22
|
params.set("width", `${width}`);
|
|
22
23
|
params.set("quality", `${quality}`);
|
|
23
|
-
return `${src}?${params.toString()}`;
|
|
24
|
+
return `${publicPath}${src}?${params.toString()}`;
|
|
24
25
|
};
|
|
25
26
|
export {
|
|
26
27
|
cloudflareImageLoader,
|
package/lib/image-optimize.js
CHANGED
|
@@ -6,7 +6,7 @@ const getWidths = (width, sizes) => {
|
|
|
6
6
|
const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g;
|
|
7
7
|
const percentSizes = [];
|
|
8
8
|
for (let match; match = viewportWidthRe.exec(sizes); match) {
|
|
9
|
-
percentSizes.push(parseInt(match[2], 10));
|
|
9
|
+
percentSizes.push(Number.parseInt(match[2], 10));
|
|
10
10
|
}
|
|
11
11
|
if (percentSizes.length) {
|
|
12
12
|
const smallestRatio = Math.min(...percentSizes) * 0.01;
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,11 @@ export type CloudflareImageLoaderOptions = {
|
|
|
7
7
|
* https://developers.cloudflare.com/images/image-resizing/url-format/
|
|
8
8
|
**/
|
|
9
9
|
export declare const cloudflareImageLoader: (ops: CloudflareImageLoaderOptions | null) => ImageLoader;
|
|
10
|
+
type LocalImageLoaderOptions = {
|
|
11
|
+
publicPath?: string;
|
|
12
|
+
};
|
|
10
13
|
/**
|
|
11
14
|
* Fake pseudo loader for local testing purposes
|
|
12
15
|
**/
|
|
13
|
-
export declare const localImageLoader: () => ImageLoader;
|
|
16
|
+
export declare const localImageLoader: (options: LocalImageLoaderOptions) => ImageLoader;
|
|
17
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/image",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "Image optimization",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"react": "^17.0.2",
|
|
10
10
|
"warn-once": "^0.1.1",
|
|
11
|
-
"@webstudio-is/generate-arg-types": "^0.
|
|
11
|
+
"@webstudio-is/generate-arg-types": "^0.54.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@jest/globals": "^29.3.1",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@webstudio-is/jest-config": "^1.0.2",
|
|
20
20
|
"@webstudio-is/scripts": "^0.0.0",
|
|
21
21
|
"@webstudio-is/storybook-config": "^0.0.0",
|
|
22
|
-
"@webstudio-is/tsconfig": "^1.0.
|
|
22
|
+
"@webstudio-is/tsconfig": "^1.0.3"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": "^17.0.2",
|
|
@@ -30,7 +30,7 @@ const imageSrc = USE_CLOUDFLARE_IMAGE_TRANSFORM
|
|
|
30
30
|
|
|
31
31
|
const imageLoader = USE_CLOUDFLARE_IMAGE_TRANSFORM
|
|
32
32
|
? loaders.cloudflareImageLoader({ resizeOrigin: "https://webstudio.is" })
|
|
33
|
-
: loaders.localImageLoader();
|
|
33
|
+
: loaders.localImageLoader({ publicPath: "" });
|
|
34
34
|
|
|
35
35
|
const ImageBase: ComponentStory<
|
|
36
36
|
React.ForwardRefExoticComponent<
|
package/src/image-loaders.ts
CHANGED
|
@@ -33,15 +33,20 @@ export const cloudflareImageLoader: (
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
type LocalImageLoaderOptions = {
|
|
37
|
+
publicPath?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
36
40
|
/**
|
|
37
41
|
* Fake pseudo loader for local testing purposes
|
|
38
42
|
**/
|
|
39
|
-
export const localImageLoader
|
|
40
|
-
() =>
|
|
43
|
+
export const localImageLoader =
|
|
44
|
+
(options: LocalImageLoaderOptions): ImageLoader =>
|
|
41
45
|
({ width, src, quality }) => {
|
|
46
|
+
const { publicPath = "/" } = options;
|
|
42
47
|
// Just emulate like we really resize the image
|
|
43
48
|
const params = new URLSearchParams();
|
|
44
49
|
params.set("width", `${width}`);
|
|
45
50
|
params.set("quality", `${quality}`);
|
|
46
|
-
return `${src}?${params.toString()}`;
|
|
51
|
+
return `${publicPath}${src}?${params.toString()}`;
|
|
47
52
|
};
|
package/src/image-optimize.ts
CHANGED
|
@@ -112,7 +112,7 @@ const getWidths = (
|
|
|
112
112
|
const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g;
|
|
113
113
|
const percentSizes = [];
|
|
114
114
|
for (let match; (match = viewportWidthRe.exec(sizes)); match) {
|
|
115
|
-
percentSizes.push(parseInt(match[2], 10));
|
|
115
|
+
percentSizes.push(Number.parseInt(match[2], 10));
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
if (percentSizes.length) {
|