@onreza/runtime 0.2.1 → 0.2.2
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/image.d.ts +2 -2
- package/dist/image.js +14 -7
- package/package.json +1 -1
package/dist/image.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* // → '/_onreza/image?url=...&w=640 640w, /_onreza/image?url=...&w=1080 1080w, ...'
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
/** Default
|
|
27
|
+
/** Default image sizes for srcset generation */
|
|
28
28
|
export declare const DEFAULT_SIZES: readonly [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
|
|
29
29
|
/** Supported image formats */
|
|
30
30
|
export type ImageFormat = "webp" | "avif";
|
|
@@ -34,7 +34,7 @@ export type ImageFit = "cover" | "contain" | "fill";
|
|
|
34
34
|
* Image transformation options
|
|
35
35
|
*/
|
|
36
36
|
export interface ImageTransformOptions {
|
|
37
|
-
/** Target width in pixels (
|
|
37
|
+
/** Target width in pixels (1-8192) */
|
|
38
38
|
width?: number;
|
|
39
39
|
/** Target height in pixels (optional, maintains aspect ratio by default) */
|
|
40
40
|
height?: number;
|
package/dist/image.js
CHANGED
|
@@ -24,8 +24,10 @@
|
|
|
24
24
|
* // → '/_onreza/image?url=...&w=640 640w, /_onreza/image?url=...&w=1080 1080w, ...'
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
/** Default
|
|
27
|
+
/** Default image sizes for srcset generation */
|
|
28
28
|
export const DEFAULT_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
|
|
29
|
+
const MIN_DIMENSION = 1;
|
|
30
|
+
const MAX_DIMENSION = 8192;
|
|
29
31
|
/**
|
|
30
32
|
* Validate image source path
|
|
31
33
|
* @throws Error if path is invalid
|
|
@@ -51,6 +53,11 @@ function validateSrc(src) {
|
|
|
51
53
|
function clamp(value, min, max) {
|
|
52
54
|
return Math.min(Math.max(value, min), max);
|
|
53
55
|
}
|
|
56
|
+
function warnOutOfRange(value, name) {
|
|
57
|
+
if (value < MIN_DIMENSION || value > MAX_DIMENSION) {
|
|
58
|
+
console.warn(`[onreza:image] ${name} ${value} is out of range (${MIN_DIMENSION}-${MAX_DIMENSION}). Clamping.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
54
61
|
/**
|
|
55
62
|
* Build ONREZA image optimization URL
|
|
56
63
|
*
|
|
@@ -72,13 +79,13 @@ export function imageUrl(src, options = {}) {
|
|
|
72
79
|
validateSrc(src);
|
|
73
80
|
const params = new URLSearchParams();
|
|
74
81
|
params.set("url", src);
|
|
75
|
-
// Width (required)
|
|
76
82
|
if (options.width !== undefined) {
|
|
77
|
-
|
|
83
|
+
warnOutOfRange(options.width, "Width");
|
|
84
|
+
params.set("w", String(clamp(options.width, MIN_DIMENSION, MAX_DIMENSION)));
|
|
78
85
|
}
|
|
79
|
-
// Height (optional)
|
|
80
86
|
if (options.height !== undefined) {
|
|
81
|
-
|
|
87
|
+
warnOutOfRange(options.height, "Height");
|
|
88
|
+
params.set("h", String(clamp(options.height, MIN_DIMENSION, MAX_DIMENSION)));
|
|
82
89
|
}
|
|
83
90
|
// Quality (default: 75)
|
|
84
91
|
const quality = options.quality !== undefined ? clamp(options.quality, 1, 100) : 75;
|
|
@@ -119,9 +126,9 @@ export function validateImageOptions(options) {
|
|
|
119
126
|
dpr: clamp(options.dpr ?? 1, 1, 5),
|
|
120
127
|
fit: options.fit ?? "cover",
|
|
121
128
|
format: options.format,
|
|
122
|
-
height: options.height,
|
|
129
|
+
height: options.height !== undefined ? clamp(options.height, MIN_DIMENSION, MAX_DIMENSION) : undefined,
|
|
123
130
|
quality: clamp(options.quality ?? 75, 1, 100),
|
|
124
|
-
width: options.width !== undefined ?
|
|
131
|
+
width: options.width !== undefined ? clamp(options.width, MIN_DIMENSION, MAX_DIMENSION) : undefined,
|
|
125
132
|
};
|
|
126
133
|
}
|
|
127
134
|
/**
|