@webstudio-is/image 0.288.0 → 0.290.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 +51 -63
- package/lib/types/image-optimize.d.ts +23 -11
- package/lib/types/index.d.ts +0 -1
- package/package.json +4 -9
- package/lib/types/image.d.ts +0 -12
package/lib/index.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
|
-
// src/image.
|
|
2
|
-
import
|
|
3
|
-
forwardRef
|
|
4
|
-
} from "react";
|
|
1
|
+
// src/image-loaders.ts
|
|
2
|
+
import warnOnce from "warn-once";
|
|
5
3
|
|
|
6
4
|
// src/image-optimize.ts
|
|
5
|
+
var imagePlaceholderDataUrl = `data:image/svg+xml;base64,${btoa(`<svg
|
|
6
|
+
width="140"
|
|
7
|
+
height="140"
|
|
8
|
+
viewBox="0 0 600 600"
|
|
9
|
+
fill="none"
|
|
10
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
11
|
+
>
|
|
12
|
+
<rect width="600" height="600" fill="#DFE3E6" />
|
|
13
|
+
<path
|
|
14
|
+
fill-rule="evenodd"
|
|
15
|
+
clip-rule="evenodd"
|
|
16
|
+
d="M450 170H150C141.716 170 135 176.716 135 185V415C135 423.284 141.716 430 150 430H450C458.284 430 465 423.284 465 415V185C465 176.716 458.284 170 450 170ZM150 145C127.909 145 110 162.909 110 185V415C110 437.091 127.909 455 150 455H450C472.091 455 490 437.091 490 415V185C490 162.909 472.091 145 450 145H150Z"
|
|
17
|
+
fill="#C1C8CD"
|
|
18
|
+
/>
|
|
19
|
+
<path
|
|
20
|
+
d="M237.135 235.012C237.135 255.723 220.345 272.512 199.635 272.512C178.924 272.512 162.135 255.723 162.135 235.012C162.135 214.301 178.924 197.512 199.635 197.512C220.345 197.512 237.135 214.301 237.135 235.012Z"
|
|
21
|
+
fill="#C1C8CD"
|
|
22
|
+
/>
|
|
23
|
+
<path
|
|
24
|
+
d="M160 405V367.205L221.609 306.364L256.552 338.628L358.161 234L440 316.043V405H160Z"
|
|
25
|
+
fill="#C1C8CD"
|
|
26
|
+
/>
|
|
27
|
+
</svg>`)}`;
|
|
7
28
|
var imageSizes = [16, 32, 48, 64, 96, 128, 256, 384];
|
|
8
29
|
var deviceSizes = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
|
|
9
30
|
var allSizes = [...imageSizes, ...deviceSizes];
|
|
@@ -81,7 +102,7 @@ var UrlCanParse = (url) => {
|
|
|
81
102
|
return false;
|
|
82
103
|
}
|
|
83
104
|
};
|
|
84
|
-
var
|
|
105
|
+
var getOptimizedImageAttributes = (props) => {
|
|
85
106
|
const width = getInt(props.width);
|
|
86
107
|
const quality = Math.max(
|
|
87
108
|
Math.min(getInt(props.quality) ?? DEFAULT_QUALITY, 100),
|
|
@@ -113,67 +134,35 @@ var getImageAttributes = (props) => {
|
|
|
113
134
|
return resAttrs;
|
|
114
135
|
}
|
|
115
136
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
137
|
+
var getImageAttributes = ({
|
|
138
|
+
quality,
|
|
139
|
+
loader,
|
|
140
|
+
optimize = true,
|
|
141
|
+
loading = "lazy",
|
|
142
|
+
decoding = "async",
|
|
143
|
+
...attributes
|
|
144
|
+
}) => {
|
|
145
|
+
const optimizedAttributes = getOptimizedImageAttributes({
|
|
146
|
+
src: attributes.src,
|
|
147
|
+
srcSet: attributes.srcSet,
|
|
148
|
+
sizes: attributes.sizes,
|
|
149
|
+
width: attributes.width,
|
|
121
150
|
quality,
|
|
122
151
|
loader,
|
|
123
|
-
optimize
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
optimize
|
|
136
|
-
}) ?? { src: imagePlaceholderDataUrl };
|
|
137
|
-
return /* @__PURE__ */ jsx(
|
|
138
|
-
"img",
|
|
139
|
-
{
|
|
140
|
-
alt: "",
|
|
141
|
-
...imageProps,
|
|
142
|
-
...imageAttributes,
|
|
143
|
-
decoding,
|
|
144
|
-
loading,
|
|
145
|
-
ref
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
Image.displayName = "Image";
|
|
151
|
-
var imagePlaceholderDataUrl = `data:image/svg+xml;base64,${btoa(`<svg
|
|
152
|
-
width="140"
|
|
153
|
-
height="140"
|
|
154
|
-
viewBox="0 0 600 600"
|
|
155
|
-
fill="none"
|
|
156
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
157
|
-
>
|
|
158
|
-
<rect width="600" height="600" fill="#DFE3E6" />
|
|
159
|
-
<path
|
|
160
|
-
fill-rule="evenodd"
|
|
161
|
-
clip-rule="evenodd"
|
|
162
|
-
d="M450 170H150C141.716 170 135 176.716 135 185V415C135 423.284 141.716 430 150 430H450C458.284 430 465 423.284 465 415V185C465 176.716 458.284 170 450 170ZM150 145C127.909 145 110 162.909 110 185V415C110 437.091 127.909 455 150 455H450C472.091 455 490 437.091 490 415V185C490 162.909 472.091 145 450 145H150Z"
|
|
163
|
-
fill="#C1C8CD"
|
|
164
|
-
/>
|
|
165
|
-
<path
|
|
166
|
-
d="M237.135 235.012C237.135 255.723 220.345 272.512 199.635 272.512C178.924 272.512 162.135 255.723 162.135 235.012C162.135 214.301 178.924 197.512 199.635 197.512C220.345 197.512 237.135 214.301 237.135 235.012Z"
|
|
167
|
-
fill="#C1C8CD"
|
|
168
|
-
/>
|
|
169
|
-
<path
|
|
170
|
-
d="M160 405V367.205L221.609 306.364L256.552 338.628L358.161 234L440 316.043V405H160Z"
|
|
171
|
-
fill="#C1C8CD"
|
|
172
|
-
/>
|
|
173
|
-
</svg>`)}`;
|
|
152
|
+
optimize
|
|
153
|
+
}) ?? { src: imagePlaceholderDataUrl };
|
|
154
|
+
return {
|
|
155
|
+
alt: "",
|
|
156
|
+
...attributes.alt !== void 0 ? { alt: attributes.alt } : {},
|
|
157
|
+
...attributes.width !== void 0 ? { width: attributes.width } : {},
|
|
158
|
+
...attributes.height !== void 0 ? { height: attributes.height } : {},
|
|
159
|
+
...optimizedAttributes,
|
|
160
|
+
decoding,
|
|
161
|
+
loading
|
|
162
|
+
};
|
|
163
|
+
};
|
|
174
164
|
|
|
175
165
|
// src/image-loaders.ts
|
|
176
|
-
import warnOnce from "warn-once";
|
|
177
166
|
var NON_EXISTING_DOMAIN = "https://a3cbcbec-cdb1-4ea4-ad60-43c795308ddc.ddc";
|
|
178
167
|
var joinPath = (...segments) => {
|
|
179
168
|
return segments.filter((segment) => segment !== "").map((segment) => segment.replace(/(^\/+|\/+$)/g, "")).join("/");
|
|
@@ -225,7 +214,6 @@ var wsVideoLoader = ({ src }) => {
|
|
|
225
214
|
return `/cgi/video/${src}`;
|
|
226
215
|
};
|
|
227
216
|
export {
|
|
228
|
-
Image,
|
|
229
217
|
allSizes,
|
|
230
218
|
getImageAttributes,
|
|
231
219
|
imagePlaceholderDataUrl,
|
|
@@ -95,17 +95,29 @@ export type ImageLoader = (props: {
|
|
|
95
95
|
src: string;
|
|
96
96
|
format: "raw";
|
|
97
97
|
}) => string;
|
|
98
|
+
export declare const imagePlaceholderDataUrl: string;
|
|
98
99
|
export declare const allSizes: number[];
|
|
99
|
-
export
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
export type ImageAttributes = {
|
|
101
|
+
alt?: string;
|
|
102
|
+
decoding?: "async" | "auto" | "sync";
|
|
103
|
+
height?: number | string;
|
|
104
|
+
loading?: "eager" | "lazy";
|
|
105
|
+
sizes?: string;
|
|
106
|
+
src?: string;
|
|
107
|
+
srcSet?: string;
|
|
108
|
+
width?: number | string;
|
|
109
|
+
};
|
|
110
|
+
type ImageOptions = {
|
|
105
111
|
loader: ImageLoader;
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
/** Optimize the image for enhanced performance. */
|
|
113
|
+
optimize?: boolean;
|
|
114
|
+
quality?: number;
|
|
115
|
+
};
|
|
116
|
+
export type ResolvedImageAttributes = ImageAttributes & {
|
|
117
|
+
alt: string | undefined;
|
|
118
|
+
decoding: "async" | "auto" | "sync";
|
|
119
|
+
loading: "eager" | "lazy";
|
|
108
120
|
src: string;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
121
|
+
};
|
|
122
|
+
export declare const getImageAttributes: ({ quality, loader, optimize, loading, decoding, ...attributes }: ImageAttributes & ImageOptions) => ResolvedImageAttributes;
|
|
123
|
+
export {};
|
package/lib/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/image",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.290.0",
|
|
4
4
|
"description": "Image optimization",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
10
9
|
"warn-once": "^0.1.1",
|
|
11
|
-
"@webstudio-is/sdk": "0.
|
|
10
|
+
"@webstudio-is/sdk": "0.290.0"
|
|
12
11
|
},
|
|
13
12
|
"devDependencies": {
|
|
14
13
|
"@types/react": "^18.2.70",
|
|
@@ -16,12 +15,8 @@
|
|
|
16
15
|
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
17
16
|
"react-dom": "18.3.0-canary-14898b6a9-20240318",
|
|
18
17
|
"vitest": "^3.1.2",
|
|
19
|
-
"@webstudio-is/
|
|
20
|
-
"@webstudio-is/
|
|
21
|
-
},
|
|
22
|
-
"peerDependencies": {
|
|
23
|
-
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
24
|
-
"react-dom": "18.3.0-canary-14898b6a9-20240318"
|
|
18
|
+
"@webstudio-is/tsconfig": "1.0.7",
|
|
19
|
+
"@webstudio-is/design-system": "0.0.0"
|
|
25
20
|
},
|
|
26
21
|
"exports": {
|
|
27
22
|
"webstudio": "./src/index.ts",
|
package/lib/types/image.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type ComponentProps, type ForwardRefExoticComponent } from "react";
|
|
2
|
-
import { type ImageLoader } from "./image-optimize";
|
|
3
|
-
declare const defaultTag = "img";
|
|
4
|
-
type ImageProps = ComponentProps<typeof defaultTag> & {
|
|
5
|
-
quality?: number;
|
|
6
|
-
/** Optimize the image for enhanced performance. */
|
|
7
|
-
optimize?: boolean;
|
|
8
|
-
loader: ImageLoader;
|
|
9
|
-
};
|
|
10
|
-
export declare const Image: ForwardRefExoticComponent<ImageProps>;
|
|
11
|
-
export declare const imagePlaceholderDataUrl: string;
|
|
12
|
-
export {};
|