@lonik/oh-image 2.9.0 → 2.10.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/dist/client.d.ts +0 -2
- package/dist/cloudflare.d.ts +3 -3
- package/dist/cloudinary.d.ts +2 -2
- package/dist/contentful.d.ts +3 -3
- package/dist/imgproxy.d.ts +3 -3
- package/dist/{index-CP-wkNzk.d.ts → index-5MpToMnk.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 +166 -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,7 +1,7 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions } from "./types-BEgZ3W30.js";
|
|
2
|
-
import "./index-
|
|
2
|
+
import "./index-5MpToMnk.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/cloudflare/cloudflare-options.d.ts
|
|
7
7
|
type CloudflareTransforms = Partial<{
|
|
@@ -40,6 +40,6 @@ declare const useCloudflareContext: () => CloudflareGlobalOptions, CloudflareLoa
|
|
|
40
40
|
...props
|
|
41
41
|
}: {
|
|
42
42
|
children: React.ReactNode;
|
|
43
|
-
} & Partial<CloudflareGlobalOptions>) =>
|
|
43
|
+
} & Partial<CloudflareGlobalOptions>) => react_jsx_runtime8.JSX.Element, useCloudflareLoader: (options?: CloudflareGlobalOptions | undefined) => (() => undefined) | ((imageOptions: ImageLoaderOptions) => string);
|
|
44
44
|
//#endregion
|
|
45
45
|
export { CloudflareGlobalOptions, CloudflareLoaderProvider, CloudflareOptions, CloudflareTransforms, useCloudflareContext, useCloudflareLoader };
|
package/dist/cloudinary.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions } from "./types-BEgZ3W30.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime6 from "react/jsx-runtime";
|
|
3
3
|
import { Cloudinary, CloudinaryImage } from "@cloudinary/url-gen";
|
|
4
4
|
|
|
5
5
|
//#region src/loaders/cloudinary/cloudinary-options.d.ts
|
|
@@ -34,7 +34,7 @@ declare function CloudinaryLoaderProvider({
|
|
|
34
34
|
children: React.ReactNode;
|
|
35
35
|
transforms?: CloudinaryTransforms;
|
|
36
36
|
placeholder?: CloudinaryTransforms;
|
|
37
|
-
}):
|
|
37
|
+
}): react_jsx_runtime6.JSX.Element;
|
|
38
38
|
declare function useCloudinaryLoader(options?: CloudinaryLoaderHookOptions | CloudinaryTransforms): (imageOptions: ImageLoaderOptions) => string;
|
|
39
39
|
declare const useCloudinaryContext: () => CloudinaryLoaderContext;
|
|
40
40
|
//#endregion
|
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-5MpToMnk.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,7 +1,7 @@
|
|
|
1
1
|
import { n as ImageLoaderOptions } from "./types-BEgZ3W30.js";
|
|
2
|
-
import "./index-
|
|
2
|
+
import "./index-5MpToMnk.js";
|
|
3
3
|
import { n as BaseLoaderOptions, t as BaseGlobalLoaderOptions } from "./base-loader-options-DCLkYppY.js";
|
|
4
|
-
import * as
|
|
4
|
+
import * as react_jsx_runtime7 from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/loaders/imgproxy/imgproxy-options.d.ts
|
|
7
7
|
type ResizeType = "fit" | "fill" | "fill-down" | "force" | "auto";
|
|
@@ -384,6 +384,6 @@ declare const useImgproxyContext: () => ImgproxyGlobalOptions, ImgproxyLoaderPro
|
|
|
384
384
|
...props
|
|
385
385
|
}: {
|
|
386
386
|
children: React.ReactNode;
|
|
387
|
-
} & Partial<ImgproxyGlobalOptions>) =>
|
|
387
|
+
} & Partial<ImgproxyGlobalOptions>) => react_jsx_runtime7.JSX.Element, useImgproxyLoader: (options?: ImgproxyGlobalOptions | undefined) => (() => undefined) | ((imageOptions: ImageLoaderOptions) => string);
|
|
388
388
|
//#endregion
|
|
389
389
|
export { ImgproxyGlobalOptions, ImgproxyLoaderProvider, ImgproxyOptions, ImgproxyTransforms, useImgproxyContext, useImgproxyLoader };
|
|
@@ -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_runtime4 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_runtime4.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_runtime4.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_runtime4.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-5MpToMnk.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/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_runtime0.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-5MpToMnk.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/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_runtime2.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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { basename, dirname, extname, join, parse } from "node:path";
|
|
2
2
|
import queryString from "query-string";
|
|
3
|
+
import { extname as extname$1 } from "path";
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
4
5
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
5
6
|
import pLimit from "p-limit";
|
|
@@ -8,11 +9,7 @@ import sharp from "sharp";
|
|
|
8
9
|
//#region src/plugin/utils.ts
|
|
9
10
|
function queryToOptions(processKey, uri) {
|
|
10
11
|
const [path, query] = uri.split("?");
|
|
11
|
-
if (!query || !path) return {
|
|
12
|
-
shouldProcess: false,
|
|
13
|
-
path: "",
|
|
14
|
-
queryString: ""
|
|
15
|
-
};
|
|
12
|
+
if (!query || !path) return { shouldProcess: false };
|
|
16
13
|
const parsed = queryString.parse(query, {
|
|
17
14
|
parseBooleans: true,
|
|
18
15
|
parseNumbers: true,
|
|
@@ -33,21 +30,101 @@ function queryToOptions(processKey, uri) {
|
|
|
33
30
|
negate: "boolean",
|
|
34
31
|
normalize: "boolean",
|
|
35
32
|
threshold: "number",
|
|
36
|
-
quality: "number"
|
|
33
|
+
quality: "number",
|
|
34
|
+
pl_width: "number",
|
|
35
|
+
pl_height: "number",
|
|
36
|
+
pl_format: "string",
|
|
37
|
+
pl_blur: "number",
|
|
38
|
+
pl_flip: "boolean",
|
|
39
|
+
pl_flop: "boolean",
|
|
40
|
+
pl_rotate: "number",
|
|
41
|
+
pl_sharpen: "number",
|
|
42
|
+
pl_median: "number",
|
|
43
|
+
pl_gamma: "number",
|
|
44
|
+
pl_negate: "boolean",
|
|
45
|
+
pl_normalize: "boolean",
|
|
46
|
+
pl_threshold: "number",
|
|
47
|
+
pl_quality: "number",
|
|
48
|
+
pl_show: "boolean"
|
|
37
49
|
}
|
|
38
50
|
});
|
|
39
|
-
if (processKey in parsed)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
if (processKey in parsed) {
|
|
52
|
+
const transforms = {};
|
|
53
|
+
const placeholder = {};
|
|
54
|
+
Object.entries(parsed).forEach(([key, value]) => {
|
|
55
|
+
if (key.startsWith("pl_")) {
|
|
56
|
+
const cleanKey = key.replace("pl_", "");
|
|
57
|
+
placeholder[cleanKey] = value;
|
|
58
|
+
} else {
|
|
59
|
+
const transformKey = key;
|
|
60
|
+
transforms[transformKey] = value;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
shouldProcess: true,
|
|
65
|
+
transforms,
|
|
66
|
+
placeholder,
|
|
67
|
+
path,
|
|
68
|
+
queryString: query
|
|
69
|
+
};
|
|
70
|
+
} else return { shouldProcess: false };
|
|
71
|
+
}
|
|
72
|
+
/** returns ext of file. removes '.' */
|
|
73
|
+
function getCleanExt(filepath) {
|
|
74
|
+
const ext = extname$1(filepath);
|
|
75
|
+
return ext.startsWith(".") ? ext.slice(1) : ext;
|
|
76
|
+
}
|
|
77
|
+
function resolveTransforms(options, defaults, metadata, fileFormat) {
|
|
78
|
+
const resolved = {
|
|
79
|
+
...defaults,
|
|
80
|
+
...options
|
|
81
|
+
};
|
|
82
|
+
const width = options?.width ?? defaults?.width ?? metadata.width;
|
|
83
|
+
const height = options?.height ?? defaults?.height ?? metadata.height;
|
|
84
|
+
const format = options?.format ?? defaults?.format ?? fileFormat ?? "webp";
|
|
85
|
+
return {
|
|
86
|
+
...resolved,
|
|
87
|
+
width,
|
|
88
|
+
height,
|
|
89
|
+
format
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function resolveShowPlaceholder(parsed, config) {
|
|
93
|
+
if (parsed.show || config.pl_show) return true;
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
function resolvePlaceholderTransforms(options, defaults, metadata) {
|
|
97
|
+
const resolved = {
|
|
98
|
+
...defaults,
|
|
99
|
+
...options
|
|
100
|
+
};
|
|
101
|
+
const width = options?.width ?? defaults?.width ?? metadata.width;
|
|
102
|
+
const height = options?.height ?? defaults?.height ?? metadata.height;
|
|
103
|
+
const format = options?.format ?? defaults?.format ?? "webp";
|
|
104
|
+
return {
|
|
105
|
+
...resolved,
|
|
106
|
+
width,
|
|
107
|
+
height,
|
|
108
|
+
format
|
|
44
109
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
110
|
+
}
|
|
111
|
+
function resolveBreakpointTransforms(options, defaults, width) {
|
|
112
|
+
const resolved = {
|
|
113
|
+
...defaults,
|
|
114
|
+
...options
|
|
115
|
+
};
|
|
116
|
+
delete resolved["height"];
|
|
117
|
+
delete resolved["width"];
|
|
118
|
+
const format = "webp";
|
|
119
|
+
return {
|
|
120
|
+
...resolved,
|
|
121
|
+
width,
|
|
122
|
+
format
|
|
49
123
|
};
|
|
50
124
|
}
|
|
125
|
+
function resolveBreakpoints(options, config) {
|
|
126
|
+
return options?.breakpoints ?? config.breakpoints;
|
|
127
|
+
}
|
|
51
128
|
|
|
52
129
|
//#endregion
|
|
53
130
|
//#region src/plugin/file-utils.ts
|
|
@@ -97,8 +174,6 @@ function createImageIdentifier(name, hash, dirs) {
|
|
|
97
174
|
|
|
98
175
|
//#endregion
|
|
99
176
|
//#region src/plugin/image-entries.ts
|
|
100
|
-
const PLACEHOLDER_IMG_SIZE = 8;
|
|
101
|
-
const PLACEHOLDER_BLUR_QUALITY = 70;
|
|
102
177
|
function createImageEntries() {
|
|
103
178
|
const map = /* @__PURE__ */ new Map();
|
|
104
179
|
return {
|
|
@@ -112,52 +187,10 @@ function createImageEntries() {
|
|
|
112
187
|
return map.entries();
|
|
113
188
|
},
|
|
114
189
|
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);
|
|
190
|
+
this.set(identifier, entry);
|
|
133
191
|
},
|
|
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);
|
|
192
|
+
createPlaceholderEntry(identifier, placeholder) {
|
|
193
|
+
this.set(identifier, placeholder);
|
|
161
194
|
},
|
|
162
195
|
createSrcSetEntry(identifier, entry) {
|
|
163
196
|
this.set(identifier, entry);
|
|
@@ -189,7 +222,6 @@ async function processImage(path, options) {
|
|
|
189
222
|
|
|
190
223
|
//#endregion
|
|
191
224
|
//#region src/plugin/plugin.ts
|
|
192
|
-
const DEFAULT_IMAGE_FORMAT = "webp";
|
|
193
225
|
const DEFAULT_CONFIGS = {
|
|
194
226
|
distDir: "oh-images",
|
|
195
227
|
breakpoints: [
|
|
@@ -205,8 +237,13 @@ const DEFAULT_CONFIGS = {
|
|
|
205
237
|
1200,
|
|
206
238
|
1920
|
|
207
239
|
],
|
|
208
|
-
format: "webp",
|
|
209
|
-
|
|
240
|
+
transforms: { format: "webp" },
|
|
241
|
+
pl_show: true,
|
|
242
|
+
placeholder: {
|
|
243
|
+
quality: 10,
|
|
244
|
+
blur: 50,
|
|
245
|
+
format: "webp"
|
|
246
|
+
}
|
|
210
247
|
};
|
|
211
248
|
const PROCESS_KEY = "$oh";
|
|
212
249
|
const SUPPORTED_IMAGE_FORMATS = /\.(jpe?g|png|webp|avif|gif|svg)(\?.*)?$/i;
|
|
@@ -254,109 +291,76 @@ function ohImage(options) {
|
|
|
254
291
|
res.end(processed);
|
|
255
292
|
});
|
|
256
293
|
},
|
|
257
|
-
load
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
294
|
+
async load(id) {
|
|
295
|
+
if (!SUPPORTED_IMAGE_FORMATS.test(id)) return null;
|
|
296
|
+
try {
|
|
297
|
+
const parsed = queryToOptions(PROCESS_KEY, id);
|
|
298
|
+
if (!parsed.shouldProcess) return null;
|
|
299
|
+
const origin = parsed.path;
|
|
300
|
+
const { name } = parse(parsed.path);
|
|
301
|
+
const metadata = await sharp(parsed.path).metadata();
|
|
302
|
+
const ext = getCleanExt(parsed.path);
|
|
303
|
+
const hash = await getFileHash(origin, parsed.queryString);
|
|
304
|
+
const transforms = resolveTransforms(parsed.transforms, config.transforms, metadata, ext);
|
|
305
|
+
const identifier = createImageIdentifier(name, hash, {
|
|
306
|
+
isBuild,
|
|
307
|
+
devDir: DEV_DIR,
|
|
308
|
+
assetsDir,
|
|
309
|
+
distDir: config.distDir
|
|
310
|
+
});
|
|
311
|
+
const mainIdentifier = identifier.main(transforms.format);
|
|
312
|
+
const mainEntry = {
|
|
313
|
+
...transforms,
|
|
314
|
+
origin
|
|
315
|
+
};
|
|
316
|
+
imageEntries.createMainEntry(mainIdentifier, mainEntry);
|
|
317
|
+
const src = {
|
|
318
|
+
width: transforms.width,
|
|
319
|
+
height: transforms.height,
|
|
320
|
+
src: mainIdentifier,
|
|
321
|
+
srcSet: ""
|
|
322
|
+
};
|
|
323
|
+
if (resolveShowPlaceholder(parsed.placeholder, config)) {
|
|
324
|
+
const placeholderTransforms = resolvePlaceholderTransforms(parsed.placeholder, config.placeholder, metadata);
|
|
325
|
+
const placeholderEntry = {
|
|
326
|
+
...placeholderTransforms,
|
|
327
|
+
origin
|
|
270
328
|
};
|
|
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(", ");
|
|
329
|
+
const placeholderIdentifier = identifier.placeholder(placeholderTransforms.format);
|
|
330
|
+
imageEntries.createPlaceholderEntry(placeholderIdentifier, placeholderEntry);
|
|
331
|
+
src.placeholder = placeholderIdentifier;
|
|
332
|
+
}
|
|
333
|
+
const breakpoints = resolveBreakpoints(transforms, config);
|
|
334
|
+
if (breakpoints) {
|
|
335
|
+
const srcSets = [];
|
|
336
|
+
for (const breakpoint of breakpoints) {
|
|
337
|
+
const breakpointTransforms = resolveBreakpointTransforms(parsed.transforms, config.transforms, breakpoint);
|
|
338
|
+
const srcSetIdentifier = identifier.srcSet(breakpointTransforms.format, breakpoint);
|
|
339
|
+
const breakpointEntry = {
|
|
340
|
+
...breakpointTransforms,
|
|
341
|
+
origin
|
|
342
|
+
};
|
|
343
|
+
imageEntries.createSrcSetEntry(srcSetIdentifier, breakpointEntry);
|
|
344
|
+
srcSets.push(`${srcSetIdentifier} ${breakpoint}w`);
|
|
344
345
|
}
|
|
345
|
-
|
|
346
|
+
src.srcSet = srcSets.join(", ");
|
|
347
|
+
}
|
|
348
|
+
return `
|
|
346
349
|
import { __imageFactory } from "@lonik/oh-image/react";
|
|
347
350
|
|
|
348
351
|
export default __imageFactory(${JSON.stringify({
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
352
|
+
width: src.width,
|
|
353
|
+
height: src.height,
|
|
354
|
+
src: src.src,
|
|
355
|
+
srcSet: src.srcSet,
|
|
356
|
+
placeholder: src.placeholder
|
|
357
|
+
})})
|
|
355
358
|
`;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
359
|
+
} catch (err) {
|
|
360
|
+
if (err instanceof Error) {
|
|
361
|
+
console.error(`Couldn't load image: ${id}. Error: ${err.message}`);
|
|
362
|
+
this.error(err.message);
|
|
363
|
+
} else this.error(String(err));
|
|
360
364
|
}
|
|
361
365
|
},
|
|
362
366
|
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-5MpToMnk.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-5MpToMnk.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/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_runtime1.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