@lonik/oh-image 2.9.0 → 2.10.1
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/dist/client.d.ts +0 -2
- package/dist/cloudflare.d.ts +1 -1
- package/dist/contentful.d.ts +3 -3
- package/dist/imgproxy.d.ts +1 -1
- package/dist/{index-CP-wkNzk.d.ts → index-CaQSR67D.d.ts} +4 -4
- package/dist/kontent.d.ts +3 -3
- package/dist/netlify.d.ts +3 -3
- package/dist/plugin.d.ts +15 -6
- package/dist/plugin.js +165 -162
- package/dist/react.d.ts +1 -1
- package/dist/wordpress.d.ts +3 -3
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ declare module "*$oh" {
|
|
|
6
6
|
| "fetchPriority"
|
|
7
7
|
| "decoding"
|
|
8
8
|
| "loading"
|
|
9
|
-
| "srcSet"
|
|
10
9
|
| "className"
|
|
11
10
|
| "sizes"
|
|
12
11
|
| "style"
|
|
@@ -24,7 +23,6 @@ declare module "*$oh" {
|
|
|
24
23
|
*/
|
|
25
24
|
fill?: boolean;
|
|
26
25
|
|
|
27
|
-
breakpoints?: number[];
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
const component: React.FC<StaticImageProps>;
|
package/dist/cloudflare.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions } from "./types-BEgZ3W30.js";
|
|
2
|
-
import "./index-
|
|
2
|
+
import "./index-CaQSR67D.js";
|
|
3
3
|
import { n as BaseLoaderOptions, t as BaseGlobalLoaderOptions } from "./base-loader-options-DCLkYppY.js";
|
|
4
4
|
import * as react_jsx_runtime7 from "react/jsx-runtime";
|
|
5
5
|
|
package/dist/contentful.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions } from "./types-BEgZ3W30.js";
|
|
2
|
-
import "./index-
|
|
2
|
+
import "./index-CaQSR67D.js";
|
|
3
3
|
import { n as BaseLoaderOptions, t as BaseGlobalLoaderOptions } from "./base-loader-options-DCLkYppY.js";
|
|
4
|
-
import * as
|
|
4
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/loaders/contentful/contentful-options.d.ts
|
|
7
7
|
type ContentfulTransforms = Partial<{
|
|
@@ -39,6 +39,6 @@ declare const useContentfulContext: () => ContentfulGlobalOptions, ContentfulLoa
|
|
|
39
39
|
...props
|
|
40
40
|
}: {
|
|
41
41
|
children: React.ReactNode;
|
|
42
|
-
} & Partial<ContentfulGlobalOptions>) =>
|
|
42
|
+
} & Partial<ContentfulGlobalOptions>) => react_jsx_runtime0.JSX.Element, useContentfulLoader: (options?: ContentfulGlobalOptions | undefined) => (() => undefined) | ((imageOptions: ImageLoaderOptions) => string);
|
|
43
43
|
//#endregion
|
|
44
44
|
export { ContentfulGlobalOptions, ContentfulLoaderProvider, ContentfulOptions, ContentfulTransforms, useContentfulContext, useContentfulLoader };
|
package/dist/imgproxy.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions } from "./types-BEgZ3W30.js";
|
|
2
|
-
import "./index-
|
|
2
|
+
import "./index-CaQSR67D.js";
|
|
3
3
|
import { n as BaseLoaderOptions, t as BaseGlobalLoaderOptions } from "./base-loader-options-DCLkYppY.js";
|
|
4
4
|
import * as react_jsx_runtime6 from "react/jsx-runtime";
|
|
5
5
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { r as ImageProps, t as ImageLoader } from "./types-BEgZ3W30.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime3 from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/react/image.d.ts
|
|
5
|
-
declare function Image(props: ImageProps):
|
|
5
|
+
declare function Image(props: ImageProps): react_jsx_runtime3.JSX.Element;
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/react/image-factory.d.ts
|
|
8
|
-
declare function __imageFactory(defaultProps: any): (props: any) =>
|
|
8
|
+
declare function __imageFactory(defaultProps: any): (props: any) => react_jsx_runtime3.JSX.Element;
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/react/use-img-loaded.d.ts
|
|
11
11
|
/**
|
|
@@ -47,6 +47,6 @@ declare function ImageProvider({
|
|
|
47
47
|
...props
|
|
48
48
|
}: {
|
|
49
49
|
children: React.ReactNode;
|
|
50
|
-
} & Partial<ImageContextValue>):
|
|
50
|
+
} & Partial<ImageContextValue>): react_jsx_runtime3.JSX.Element;
|
|
51
51
|
//#endregion
|
|
52
52
|
export { Image as a, __imageFactory as i, useImageContext as n, useImgLoaded as r, ImageProvider as t };
|
package/dist/kontent.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions } from "./types-BEgZ3W30.js";
|
|
2
|
-
import "./index-
|
|
2
|
+
import "./index-CaQSR67D.js";
|
|
3
3
|
import { n as BaseLoaderOptions, t as BaseGlobalLoaderOptions } from "./base-loader-options-DCLkYppY.js";
|
|
4
|
-
import * as
|
|
4
|
+
import * as react_jsx_runtime2 from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/loaders/kontent/kontent-options.d.ts
|
|
7
7
|
type KontentTransforms = Partial<{
|
|
@@ -44,6 +44,6 @@ declare const useKontentContext: () => KontentGlobalOptions, KontentLoaderProvid
|
|
|
44
44
|
...props
|
|
45
45
|
}: {
|
|
46
46
|
children: React.ReactNode;
|
|
47
|
-
} & Partial<KontentGlobalOptions>) =>
|
|
47
|
+
} & Partial<KontentGlobalOptions>) => react_jsx_runtime2.JSX.Element, useKontentLoader: (options?: KontentGlobalOptions | undefined) => (() => undefined) | ((imageOptions: ImageLoaderOptions) => string);
|
|
48
48
|
//#endregion
|
|
49
49
|
export { KontentGlobalOptions, KontentLoaderProvider, KontentOptions, KontentTransforms, useKontentContext, useKontentLoader };
|
package/dist/netlify.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions } from "./types-BEgZ3W30.js";
|
|
2
|
-
import "./index-
|
|
2
|
+
import "./index-CaQSR67D.js";
|
|
3
3
|
import { n as BaseLoaderOptions, t as BaseGlobalLoaderOptions } from "./base-loader-options-DCLkYppY.js";
|
|
4
|
-
import * as
|
|
4
|
+
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/loaders/netlify/netlify-options.d.ts
|
|
7
7
|
type NetlifyTransforms = Partial<{
|
|
@@ -21,6 +21,6 @@ declare const useNetlifyContext: () => NetlifyGlobalOptions, NetlifyLoaderProvid
|
|
|
21
21
|
...props
|
|
22
22
|
}: {
|
|
23
23
|
children: React.ReactNode;
|
|
24
|
-
} & Partial<NetlifyGlobalOptions>) =>
|
|
24
|
+
} & Partial<NetlifyGlobalOptions>) => react_jsx_runtime1.JSX.Element, useNetlifyLoader: (options?: NetlifyGlobalOptions | undefined) => (() => undefined) | ((imageOptions: ImageLoaderOptions) => string);
|
|
25
25
|
//#endregion
|
|
26
26
|
export { NetlifyGlobalOptions, NetlifyLoaderProvider, NetlifyOptions, NetlifyTransforms, useNetlifyContext, useNetlifyLoader };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -2,11 +2,8 @@ import { FormatEnum } from "sharp";
|
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin/types.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
distDir: string;
|
|
8
|
-
}
|
|
9
|
-
interface ImageOptions {
|
|
5
|
+
|
|
6
|
+
type ImageTransforms = Partial<{
|
|
10
7
|
/** Target width for the processed image in pixels */
|
|
11
8
|
width?: number | null;
|
|
12
9
|
/** Target height for the processed image in pixels */
|
|
@@ -39,9 +36,21 @@ interface ImageOptions {
|
|
|
39
36
|
threshold?: number | null;
|
|
40
37
|
/** Apply quality */
|
|
41
38
|
quality?: number | null;
|
|
39
|
+
}>;
|
|
40
|
+
type PlaceholderTransforms = Omit<ImageTransforms, "placeholder" | "breakpoints"> & {
|
|
41
|
+
show?: boolean;
|
|
42
|
+
};
|
|
43
|
+
type PluginTransforms = Omit<ImageTransforms, "breakpoints">;
|
|
44
|
+
type PluginPlaceholderTransforms = Omit<PlaceholderTransforms, "pl_show">;
|
|
45
|
+
interface PluginConfig {
|
|
46
|
+
distDir: string;
|
|
47
|
+
transforms?: PluginTransforms;
|
|
48
|
+
placeholder?: PluginPlaceholderTransforms;
|
|
49
|
+
breakpoints?: number[];
|
|
50
|
+
pl_show?: boolean;
|
|
42
51
|
}
|
|
43
52
|
//#endregion
|
|
44
53
|
//#region src/plugin/plugin.d.ts
|
|
45
54
|
declare function ohImage(options?: Partial<PluginConfig>): Plugin;
|
|
46
55
|
//#endregion
|
|
47
|
-
export { type ImageOptions, type PluginConfig, ohImage };
|
|
56
|
+
export { type ImageTransforms as ImageOptions, type PluginConfig, ohImage };
|
package/dist/plugin.js
CHANGED
|
@@ -8,11 +8,7 @@ import sharp from "sharp";
|
|
|
8
8
|
//#region src/plugin/utils.ts
|
|
9
9
|
function queryToOptions(processKey, uri) {
|
|
10
10
|
const [path, query] = uri.split("?");
|
|
11
|
-
if (!query || !path) return {
|
|
12
|
-
shouldProcess: false,
|
|
13
|
-
path: "",
|
|
14
|
-
queryString: ""
|
|
15
|
-
};
|
|
11
|
+
if (!query || !path) return { shouldProcess: false };
|
|
16
12
|
const parsed = queryString.parse(query, {
|
|
17
13
|
parseBooleans: true,
|
|
18
14
|
parseNumbers: true,
|
|
@@ -33,21 +29,101 @@ function queryToOptions(processKey, uri) {
|
|
|
33
29
|
negate: "boolean",
|
|
34
30
|
normalize: "boolean",
|
|
35
31
|
threshold: "number",
|
|
36
|
-
quality: "number"
|
|
32
|
+
quality: "number",
|
|
33
|
+
pl_width: "number",
|
|
34
|
+
pl_height: "number",
|
|
35
|
+
pl_format: "string",
|
|
36
|
+
pl_blur: "number",
|
|
37
|
+
pl_flip: "boolean",
|
|
38
|
+
pl_flop: "boolean",
|
|
39
|
+
pl_rotate: "number",
|
|
40
|
+
pl_sharpen: "number",
|
|
41
|
+
pl_median: "number",
|
|
42
|
+
pl_gamma: "number",
|
|
43
|
+
pl_negate: "boolean",
|
|
44
|
+
pl_normalize: "boolean",
|
|
45
|
+
pl_threshold: "number",
|
|
46
|
+
pl_quality: "number",
|
|
47
|
+
pl_show: "boolean"
|
|
37
48
|
}
|
|
38
49
|
});
|
|
39
|
-
if (processKey in parsed)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
if (processKey in parsed) {
|
|
51
|
+
const transforms = {};
|
|
52
|
+
const placeholder = {};
|
|
53
|
+
Object.entries(parsed).forEach(([key, value]) => {
|
|
54
|
+
if (key.startsWith("pl_")) {
|
|
55
|
+
const cleanKey = key.replace("pl_", "");
|
|
56
|
+
placeholder[cleanKey] = value;
|
|
57
|
+
} else {
|
|
58
|
+
const transformKey = key;
|
|
59
|
+
transforms[transformKey] = value;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
shouldProcess: true,
|
|
64
|
+
transforms,
|
|
65
|
+
placeholder,
|
|
66
|
+
path,
|
|
67
|
+
queryString: query
|
|
68
|
+
};
|
|
69
|
+
} else return { shouldProcess: false };
|
|
70
|
+
}
|
|
71
|
+
/** returns ext of file. removes '.' */
|
|
72
|
+
function getCleanExt(filepath) {
|
|
73
|
+
const ext = extname(filepath);
|
|
74
|
+
return ext.startsWith(".") ? ext.slice(1) : ext;
|
|
75
|
+
}
|
|
76
|
+
function resolveTransforms(options, defaults, metadata, fileFormat) {
|
|
77
|
+
const resolved = {
|
|
78
|
+
...defaults,
|
|
79
|
+
...options
|
|
80
|
+
};
|
|
81
|
+
const width = options?.width ?? defaults?.width ?? metadata.width;
|
|
82
|
+
const height = options?.height ?? defaults?.height ?? metadata.height;
|
|
83
|
+
const format = options?.format ?? defaults?.format ?? fileFormat ?? "webp";
|
|
84
|
+
return {
|
|
85
|
+
...resolved,
|
|
86
|
+
width,
|
|
87
|
+
height,
|
|
88
|
+
format
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function resolveShowPlaceholder(parsed, config) {
|
|
92
|
+
if (parsed.show || config.pl_show) return true;
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
function resolvePlaceholderTransforms(options, defaults, metadata) {
|
|
96
|
+
const resolved = {
|
|
97
|
+
...defaults,
|
|
98
|
+
...options
|
|
99
|
+
};
|
|
100
|
+
const width = options?.width ?? defaults?.width ?? metadata.width;
|
|
101
|
+
const height = options?.height ?? defaults?.height ?? metadata.height;
|
|
102
|
+
const format = options?.format ?? defaults?.format ?? "webp";
|
|
103
|
+
return {
|
|
104
|
+
...resolved,
|
|
105
|
+
width,
|
|
106
|
+
height,
|
|
107
|
+
format
|
|
44
108
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
109
|
+
}
|
|
110
|
+
function resolveBreakpointTransforms(options, defaults, width) {
|
|
111
|
+
const resolved = {
|
|
112
|
+
...defaults,
|
|
113
|
+
...options
|
|
114
|
+
};
|
|
115
|
+
delete resolved["height"];
|
|
116
|
+
delete resolved["width"];
|
|
117
|
+
const format = "webp";
|
|
118
|
+
return {
|
|
119
|
+
...resolved,
|
|
120
|
+
width,
|
|
121
|
+
format
|
|
49
122
|
};
|
|
50
123
|
}
|
|
124
|
+
function resolveBreakpoints(options, config) {
|
|
125
|
+
return options?.breakpoints ?? config.breakpoints;
|
|
126
|
+
}
|
|
51
127
|
|
|
52
128
|
//#endregion
|
|
53
129
|
//#region src/plugin/file-utils.ts
|
|
@@ -97,8 +173,6 @@ function createImageIdentifier(name, hash, dirs) {
|
|
|
97
173
|
|
|
98
174
|
//#endregion
|
|
99
175
|
//#region src/plugin/image-entries.ts
|
|
100
|
-
const PLACEHOLDER_IMG_SIZE = 8;
|
|
101
|
-
const PLACEHOLDER_BLUR_QUALITY = 70;
|
|
102
176
|
function createImageEntries() {
|
|
103
177
|
const map = /* @__PURE__ */ new Map();
|
|
104
178
|
return {
|
|
@@ -112,52 +186,10 @@ function createImageEntries() {
|
|
|
112
186
|
return map.entries();
|
|
113
187
|
},
|
|
114
188
|
createMainEntry(identifier, entry) {
|
|
115
|
-
|
|
116
|
-
width: entry.width,
|
|
117
|
-
height: entry.height,
|
|
118
|
-
format: entry.format,
|
|
119
|
-
origin: entry.origin,
|
|
120
|
-
blur: entry.blur,
|
|
121
|
-
flip: entry.flip,
|
|
122
|
-
flop: entry.flop,
|
|
123
|
-
rotate: entry.rotate,
|
|
124
|
-
sharpen: entry.sharpen,
|
|
125
|
-
median: entry.median,
|
|
126
|
-
gamma: entry.gamma,
|
|
127
|
-
negate: entry.negate,
|
|
128
|
-
normalize: entry.normalize,
|
|
129
|
-
threshold: entry.threshold,
|
|
130
|
-
quality: entry.quality
|
|
131
|
-
};
|
|
132
|
-
this.set(identifier, mainEntry);
|
|
189
|
+
this.set(identifier, entry);
|
|
133
190
|
},
|
|
134
|
-
createPlaceholderEntry(identifier,
|
|
135
|
-
|
|
136
|
-
let placeholderWidth = 0;
|
|
137
|
-
if (main.width >= main.height) {
|
|
138
|
-
placeholderWidth = PLACEHOLDER_IMG_SIZE;
|
|
139
|
-
placeholderHeight = Math.max(Math.round(main.height / main.width * PLACEHOLDER_IMG_SIZE), 10);
|
|
140
|
-
} else {
|
|
141
|
-
placeholderWidth = Math.max(Math.round(main.width / main.height * PLACEHOLDER_IMG_SIZE), 10);
|
|
142
|
-
placeholderHeight = PLACEHOLDER_IMG_SIZE;
|
|
143
|
-
}
|
|
144
|
-
const placeholderEntry = {
|
|
145
|
-
width: placeholderWidth,
|
|
146
|
-
height: placeholderHeight,
|
|
147
|
-
format: main.format,
|
|
148
|
-
blur: PLACEHOLDER_BLUR_QUALITY,
|
|
149
|
-
origin: main.origin,
|
|
150
|
-
flip: main.flip,
|
|
151
|
-
flop: main.flop,
|
|
152
|
-
rotate: main.rotate,
|
|
153
|
-
sharpen: main.sharpen,
|
|
154
|
-
median: main.median,
|
|
155
|
-
gamma: main.gamma,
|
|
156
|
-
negate: main.negate,
|
|
157
|
-
normalize: main.normalize,
|
|
158
|
-
threshold: main.threshold
|
|
159
|
-
};
|
|
160
|
-
this.set(identifier, placeholderEntry);
|
|
191
|
+
createPlaceholderEntry(identifier, placeholder) {
|
|
192
|
+
this.set(identifier, placeholder);
|
|
161
193
|
},
|
|
162
194
|
createSrcSetEntry(identifier, entry) {
|
|
163
195
|
this.set(identifier, entry);
|
|
@@ -189,7 +221,6 @@ async function processImage(path, options) {
|
|
|
189
221
|
|
|
190
222
|
//#endregion
|
|
191
223
|
//#region src/plugin/plugin.ts
|
|
192
|
-
const DEFAULT_IMAGE_FORMAT = "webp";
|
|
193
224
|
const DEFAULT_CONFIGS = {
|
|
194
225
|
distDir: "oh-images",
|
|
195
226
|
breakpoints: [
|
|
@@ -205,8 +236,13 @@ const DEFAULT_CONFIGS = {
|
|
|
205
236
|
1200,
|
|
206
237
|
1920
|
|
207
238
|
],
|
|
208
|
-
format: "webp",
|
|
209
|
-
|
|
239
|
+
transforms: { format: "webp" },
|
|
240
|
+
pl_show: true,
|
|
241
|
+
placeholder: {
|
|
242
|
+
quality: 10,
|
|
243
|
+
blur: 50,
|
|
244
|
+
format: "webp"
|
|
245
|
+
}
|
|
210
246
|
};
|
|
211
247
|
const PROCESS_KEY = "$oh";
|
|
212
248
|
const SUPPORTED_IMAGE_FORMATS = /\.(jpe?g|png|webp|avif|gif|svg)(\?.*)?$/i;
|
|
@@ -254,109 +290,76 @@ function ohImage(options) {
|
|
|
254
290
|
res.end(processed);
|
|
255
291
|
});
|
|
256
292
|
},
|
|
257
|
-
load
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
293
|
+
async load(id) {
|
|
294
|
+
if (!SUPPORTED_IMAGE_FORMATS.test(id)) return null;
|
|
295
|
+
try {
|
|
296
|
+
const parsed = queryToOptions(PROCESS_KEY, id);
|
|
297
|
+
if (!parsed.shouldProcess) return null;
|
|
298
|
+
const origin = parsed.path;
|
|
299
|
+
const { name } = parse(parsed.path);
|
|
300
|
+
const metadata = await sharp(parsed.path).metadata();
|
|
301
|
+
const ext = getCleanExt(parsed.path);
|
|
302
|
+
const hash = await getFileHash(origin, parsed.queryString);
|
|
303
|
+
const transforms = resolveTransforms(parsed.transforms, config.transforms, metadata, ext);
|
|
304
|
+
const identifier = createImageIdentifier(name, hash, {
|
|
305
|
+
isBuild,
|
|
306
|
+
devDir: DEV_DIR,
|
|
307
|
+
assetsDir,
|
|
308
|
+
distDir: config.distDir
|
|
309
|
+
});
|
|
310
|
+
const mainIdentifier = identifier.main(transforms.format);
|
|
311
|
+
const mainEntry = {
|
|
312
|
+
...transforms,
|
|
313
|
+
origin
|
|
314
|
+
};
|
|
315
|
+
imageEntries.createMainEntry(mainIdentifier, mainEntry);
|
|
316
|
+
const src = {
|
|
317
|
+
width: transforms.width,
|
|
318
|
+
height: transforms.height,
|
|
319
|
+
src: mainIdentifier,
|
|
320
|
+
srcSet: ""
|
|
321
|
+
};
|
|
322
|
+
if (resolveShowPlaceholder(parsed.placeholder, config)) {
|
|
323
|
+
const placeholderTransforms = resolvePlaceholderTransforms(parsed.placeholder, config.placeholder, metadata);
|
|
324
|
+
const placeholderEntry = {
|
|
325
|
+
...placeholderTransforms,
|
|
326
|
+
origin
|
|
270
327
|
};
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
rotate: mergedOptions.rotate,
|
|
288
|
-
sharpen: mergedOptions.sharpen,
|
|
289
|
-
median: mergedOptions.median,
|
|
290
|
-
gamma: mergedOptions.gamma,
|
|
291
|
-
negate: mergedOptions.negate,
|
|
292
|
-
normalize: mergedOptions.normalize,
|
|
293
|
-
threshold: mergedOptions.threshold,
|
|
294
|
-
quality: mergedOptions.quality
|
|
295
|
-
});
|
|
296
|
-
const src = {
|
|
297
|
-
width: metadata.width,
|
|
298
|
-
height: metadata.height,
|
|
299
|
-
src: mainIdentifier,
|
|
300
|
-
srcSet: ""
|
|
301
|
-
};
|
|
302
|
-
if (mergedOptions.placeholder) {
|
|
303
|
-
const placeholderIdentifier = identifier.placeholder(DEFAULT_IMAGE_FORMAT);
|
|
304
|
-
imageEntries.createPlaceholderEntry(placeholderIdentifier, {
|
|
305
|
-
width: metadata.width,
|
|
306
|
-
height: metadata.height,
|
|
307
|
-
format: DEFAULT_IMAGE_FORMAT,
|
|
308
|
-
origin,
|
|
309
|
-
flip: mergedOptions.flip,
|
|
310
|
-
flop: mergedOptions.flop,
|
|
311
|
-
rotate: mergedOptions.rotate,
|
|
312
|
-
sharpen: mergedOptions.sharpen,
|
|
313
|
-
median: mergedOptions.median,
|
|
314
|
-
gamma: mergedOptions.gamma,
|
|
315
|
-
negate: mergedOptions.negate,
|
|
316
|
-
normalize: mergedOptions.normalize,
|
|
317
|
-
threshold: mergedOptions.threshold
|
|
318
|
-
});
|
|
319
|
-
src.placeholder = placeholderIdentifier;
|
|
320
|
-
}
|
|
321
|
-
if (mergedOptions.breakpoints) {
|
|
322
|
-
const srcSets = [];
|
|
323
|
-
for (const breakpoint of mergedOptions.breakpoints) {
|
|
324
|
-
const srcSetIdentifier = identifier.srcSet(DEFAULT_IMAGE_FORMAT, breakpoint);
|
|
325
|
-
imageEntries.createSrcSetEntry(srcSetIdentifier, {
|
|
326
|
-
width: breakpoint,
|
|
327
|
-
format: DEFAULT_IMAGE_FORMAT,
|
|
328
|
-
origin,
|
|
329
|
-
blur: mergedOptions.blur,
|
|
330
|
-
flip: mergedOptions.flip,
|
|
331
|
-
flop: mergedOptions.flop,
|
|
332
|
-
rotate: mergedOptions.rotate,
|
|
333
|
-
sharpen: mergedOptions.sharpen,
|
|
334
|
-
median: mergedOptions.median,
|
|
335
|
-
gamma: mergedOptions.gamma,
|
|
336
|
-
negate: mergedOptions.negate,
|
|
337
|
-
normalize: mergedOptions.normalize,
|
|
338
|
-
threshold: mergedOptions.threshold,
|
|
339
|
-
quality: mergedOptions.quality
|
|
340
|
-
});
|
|
341
|
-
srcSets.push(`${srcSetIdentifier} ${breakpoint}w`);
|
|
342
|
-
}
|
|
343
|
-
src.srcSet = srcSets.join(", ");
|
|
328
|
+
const placeholderIdentifier = identifier.placeholder(placeholderTransforms.format);
|
|
329
|
+
imageEntries.createPlaceholderEntry(placeholderIdentifier, placeholderEntry);
|
|
330
|
+
src.placeholder = placeholderIdentifier;
|
|
331
|
+
}
|
|
332
|
+
const breakpoints = resolveBreakpoints(transforms, config);
|
|
333
|
+
if (breakpoints) {
|
|
334
|
+
const srcSets = [];
|
|
335
|
+
for (const breakpoint of breakpoints) {
|
|
336
|
+
const breakpointTransforms = resolveBreakpointTransforms(parsed.transforms, config.transforms, breakpoint);
|
|
337
|
+
const srcSetIdentifier = identifier.srcSet(breakpointTransforms.format, breakpoint);
|
|
338
|
+
const breakpointEntry = {
|
|
339
|
+
...breakpointTransforms,
|
|
340
|
+
origin
|
|
341
|
+
};
|
|
342
|
+
imageEntries.createSrcSetEntry(srcSetIdentifier, breakpointEntry);
|
|
343
|
+
srcSets.push(`${srcSetIdentifier} ${breakpoint}w`);
|
|
344
344
|
}
|
|
345
|
-
|
|
345
|
+
src.srcSet = srcSets.join(", ");
|
|
346
|
+
}
|
|
347
|
+
return `
|
|
346
348
|
import { __imageFactory } from "@lonik/oh-image/react";
|
|
347
349
|
|
|
348
350
|
export default __imageFactory(${JSON.stringify({
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
351
|
+
width: src.width,
|
|
352
|
+
height: src.height,
|
|
353
|
+
src: src.src,
|
|
354
|
+
srcSet: src.srcSet,
|
|
355
|
+
placeholder: src.placeholder
|
|
356
|
+
})})
|
|
355
357
|
`;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
358
|
+
} catch (err) {
|
|
359
|
+
if (err instanceof Error) {
|
|
360
|
+
console.error(`Couldn't load image: ${id}. Error: ${err.message}`);
|
|
361
|
+
this.error(err.message);
|
|
362
|
+
} else this.error(String(err));
|
|
360
363
|
}
|
|
361
364
|
},
|
|
362
365
|
async writeBundle() {
|
package/dist/react.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions, r as ImageProps, t as ImageLoader } from "./types-BEgZ3W30.js";
|
|
2
|
-
import { a as Image, i as __imageFactory, n as useImageContext, r as useImgLoaded, t as ImageProvider } from "./index-
|
|
2
|
+
import { a as Image, i as __imageFactory, n as useImageContext, r as useImgLoaded, t as ImageProvider } from "./index-CaQSR67D.js";
|
|
3
3
|
export { Image, ImageLoader, ImageLoaderOptions, ImageProps, ImageProvider, __imageFactory, useImageContext, useImgLoaded };
|
package/dist/wordpress.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions } from "./types-BEgZ3W30.js";
|
|
2
|
-
import "./index-
|
|
2
|
+
import "./index-CaQSR67D.js";
|
|
3
3
|
import { n as BaseLoaderOptions, t as BaseGlobalLoaderOptions } from "./base-loader-options-DCLkYppY.js";
|
|
4
|
-
import * as
|
|
4
|
+
import * as react_jsx_runtime8 from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/loaders/wordpress/wordpress-options.d.ts
|
|
7
7
|
type WordpressTransforms = Partial<{
|
|
@@ -31,6 +31,6 @@ declare const useWordpressContext: () => WordpressGlobalOptions, WordpressLoader
|
|
|
31
31
|
...props
|
|
32
32
|
}: {
|
|
33
33
|
children: React.ReactNode;
|
|
34
|
-
} & Partial<WordpressGlobalOptions>) =>
|
|
34
|
+
} & Partial<WordpressGlobalOptions>) => react_jsx_runtime8.JSX.Element, useWordpressLoader: (options?: WordpressGlobalOptions | undefined) => (() => undefined) | ((imageOptions: ImageLoaderOptions) => string);
|
|
35
35
|
//#endregion
|
|
36
36
|
export { WordpressGlobalOptions, WordpressLoaderProvider, WordpressOptions, WordpressTransforms, useWordpressContext, useWordpressLoader };
|
package/package.json
CHANGED