@webstudio-is/image 0.289.0 → 0.291.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 CHANGED
@@ -1,9 +1,30 @@
1
- // src/image.tsx
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 getImageAttributes = (props) => {
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
- // src/image.tsx
118
- import { jsx } from "react/jsx-runtime";
119
- var Image = forwardRef(
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 = true,
124
- loading = "lazy",
125
- decoding = "async",
126
- ...imageProps
127
- }, ref) => {
128
- const imageAttributes = getImageAttributes({
129
- src: imageProps.src,
130
- srcSet: imageProps.srcSet,
131
- sizes: imageProps.sizes,
132
- width: imageProps.width,
133
- quality,
134
- loader,
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 declare const getImageAttributes: (props: {
100
- src: string | undefined;
101
- srcSet: string | undefined;
102
- sizes: string | undefined;
103
- width: string | number | undefined;
104
- quality: string | number | undefined;
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
- optimize: boolean;
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
- srcSet?: string;
110
- sizes?: string;
111
- } | undefined;
121
+ };
122
+ export declare const getImageAttributes: ({ quality, loader, optimize, loading, decoding, ...attributes }: ImageAttributes & ImageOptions) => ResolvedImageAttributes;
123
+ export {};
@@ -1,4 +1,3 @@
1
- export { Image, imagePlaceholderDataUrl } from "./image";
2
1
  export type { ImageLoader } from "./image-optimize";
3
2
  export * from "./image-loaders";
4
3
  export * from "./image-optimize";
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "@webstudio-is/image",
3
- "version": "0.289.0",
3
+ "version": "0.291.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.289.0"
10
+ "@webstudio-is/sdk": "0.291.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/tsconfig": "1.0.7",
20
- "@webstudio-is/design-system": "0.0.0"
21
- },
22
- "peerDependencies": {
23
- "react": "18.3.0-canary-14898b6a9-20240318",
24
- "react-dom": "18.3.0-canary-14898b6a9-20240318"
18
+ "@webstudio-is/design-system": "0.0.0",
19
+ "@webstudio-is/tsconfig": "1.0.7"
25
20
  },
26
21
  "exports": {
27
22
  "webstudio": "./src/index.ts",
@@ -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 {};