@lonik/oh-image 2.0.3 → 2.0.5
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/react.d.ts +3 -1
- package/dist/react.js +14 -14
- package/package.json +6 -6
package/dist/react.d.ts
CHANGED
|
@@ -13,8 +13,10 @@ type ImageSrcType = string | ImageSrc;
|
|
|
13
13
|
interface ImageProps extends Partial<Pick<ImgHTMLAttributes<HTMLImageElement>, "fetchPriority" | "decoding" | "loading" | "srcSet" | "className" | "sizes" | "style">> {
|
|
14
14
|
/** Alternative text for the image, required for accessibility. Use an empty string for decorative images. */
|
|
15
15
|
alt: string;
|
|
16
|
-
/**
|
|
16
|
+
/** @deprecated Use `priority` instead. */
|
|
17
17
|
asap?: boolean;
|
|
18
|
+
/** Configures the Image component to load the image immediately. */
|
|
19
|
+
priority?: boolean;
|
|
18
20
|
/** */
|
|
19
21
|
src: ImageSrcType;
|
|
20
22
|
/** The URL of the placeholder image to display while loading. */
|
package/dist/react.js
CHANGED
|
@@ -102,10 +102,10 @@ function resolveOptions(prop, defaultOptions) {
|
|
|
102
102
|
return resolved;
|
|
103
103
|
}
|
|
104
104
|
function resolveDecoding(prop) {
|
|
105
|
-
return prop.asap ? "async" : prop.decoding;
|
|
105
|
+
return prop.priority || prop.asap ? "async" : prop.decoding;
|
|
106
106
|
}
|
|
107
107
|
function resolveFetchPriority(prop) {
|
|
108
|
-
if (prop.asap) return "high";
|
|
108
|
+
if (prop.priority || prop.asap) return "high";
|
|
109
109
|
return prop.fetchPriority ?? "auto";
|
|
110
110
|
}
|
|
111
111
|
function resolveSrcSet(prop) {
|
|
@@ -124,8 +124,9 @@ function resolveSrcSet(prop) {
|
|
|
124
124
|
return entries.join(", ");
|
|
125
125
|
}
|
|
126
126
|
function resolveLoading(prop) {
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
const priority = prop.priority || prop.asap;
|
|
128
|
+
if (!priority && prop.loading !== void 0) return prop.loading;
|
|
129
|
+
return priority ? "eager" : "lazy";
|
|
129
130
|
}
|
|
130
131
|
function resolveSizes(prop, resolvedSrcSet, resolvedLoading) {
|
|
131
132
|
const loading = resolvedLoading ?? resolveLoading(prop);
|
|
@@ -169,6 +170,7 @@ function resolvePlaceholderURL(prop) {
|
|
|
169
170
|
//#region src/react/prop-asserts.ts
|
|
170
171
|
function assertProps(prop) {
|
|
171
172
|
try {
|
|
173
|
+
if (prop.asap !== void 0) console.warn("The `asap` prop is deprecated and will be removed in a future version. Please use `priority` instead.");
|
|
172
174
|
assertLoadingProp(prop);
|
|
173
175
|
assertDecodingProp(prop);
|
|
174
176
|
assertFetchPriorityProp(prop);
|
|
@@ -181,28 +183,26 @@ function assertProps(prop) {
|
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
185
|
function assert(assertion, message) {
|
|
184
|
-
if (
|
|
185
|
-
if (assertion()) throw new Error(message || void 0);
|
|
186
|
-
}
|
|
186
|
+
if (assertion()) throw new Error(message || void 0);
|
|
187
187
|
}
|
|
188
188
|
function assertLoadingProp(prop) {
|
|
189
|
-
assert(() => prop.loading && prop.asap,
|
|
189
|
+
assert(() => prop.loading && (prop.priority || prop.asap), `Do not use \`loading\` on a priority image — priority images are always eagerly loaded.`);
|
|
190
190
|
}
|
|
191
191
|
function assertDecodingProp(prop) {
|
|
192
|
-
assert(() => prop.decoding && prop.asap,
|
|
192
|
+
assert(() => prop.decoding && (prop.priority || prop.asap), `Do not use \`decoding\` on a priority image — priority images always use async decoding.`);
|
|
193
193
|
}
|
|
194
194
|
function assertFetchPriorityProp(prop) {
|
|
195
|
-
assert(() => prop.fetchPriority && prop.asap,
|
|
195
|
+
assert(() => prop.fetchPriority && (prop.priority || prop.asap), `Do not use \`fetchPriority\` on a priority image — priority images always use high fetch priority.`);
|
|
196
196
|
}
|
|
197
197
|
function assertBreakpointsProp(prop) {
|
|
198
|
-
assert(() => prop.breakpoints && typeof prop.src === "object",
|
|
199
|
-
assert(() => prop.breakpoints && typeof prop.src === "string" && !prop.loader,
|
|
198
|
+
assert(() => prop.breakpoints && typeof prop.src === "object", `Do not use \`breakpoints\` when \`src\` is an imported image — the image's built-in srcSets are used instead.`);
|
|
199
|
+
assert(() => prop.breakpoints && typeof prop.src === "string" && !prop.loader, `Do not use \`breakpoints\` without a \`loader\` — breakpoints require a loader to generate srcSet entries.`);
|
|
200
200
|
}
|
|
201
201
|
function assertFillProp(prop) {
|
|
202
|
-
assert(() => prop.fill && (prop.width !== void 0 || prop.height !== void 0),
|
|
202
|
+
assert(() => prop.fill && (prop.width !== void 0 || prop.height !== void 0), `Do not use \`width\` or \`height\` with \`fill\` — fill mode makes the image fill its container.`);
|
|
203
203
|
}
|
|
204
204
|
function assertDimensionsProp(prop) {
|
|
205
|
-
assert(() => typeof prop.src === "string" && !prop.fill && prop.width === void 0 && prop.height === void 0,
|
|
205
|
+
assert(() => typeof prop.src === "string" && !prop.fill && prop.width === void 0 && prop.height === void 0, `Image is missing \`width\` and \`height\` props. Either provide dimensions, use \`fill\`, or use an imported image source.`);
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lonik/oh-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.5",
|
|
5
5
|
"description": "A React component library for optimized image handling.",
|
|
6
6
|
"author": "Luka Onikadze <lukonik@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -74,15 +74,15 @@
|
|
|
74
74
|
"typescript": "^5.9.3",
|
|
75
75
|
"typescript-eslint": "^8.54.0",
|
|
76
76
|
"vite": "^7.3.0",
|
|
77
|
-
"vitest": "^4.0.16"
|
|
78
|
-
},
|
|
79
|
-
"dependencies": {
|
|
77
|
+
"vitest": "^4.0.16",
|
|
80
78
|
"@types/supertest": "^6.0.3",
|
|
81
79
|
"memfs": "^4.56.10",
|
|
82
|
-
"p-limit": "^7.3.0",
|
|
83
|
-
"query-string": "^9.3.1",
|
|
84
80
|
"supertest": "^7.2.2"
|
|
85
81
|
},
|
|
82
|
+
"dependencies": {
|
|
83
|
+
"p-limit": "^7.3.0",
|
|
84
|
+
"query-string": "^9.3.1"
|
|
85
|
+
},
|
|
86
86
|
"keywords": [
|
|
87
87
|
"react",
|
|
88
88
|
"reactjs",
|