@onreza/adapter-astro 0.2.0 → 0.3.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/image/index.d.ts +28 -0
- package/dist/image/index.js +1 -0
- package/dist/image/service.d.ts +51 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/types.d.ts +14 -0
- package/package.json +5 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @onreza/adapter-astro/image
|
|
3
|
+
*
|
|
4
|
+
* Astro Image Service for ONREZA platform image optimization.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```js
|
|
8
|
+
* // astro.config.mjs
|
|
9
|
+
* import { defineConfig } from 'astro/config';
|
|
10
|
+
* import { onreza } from '@onreza/adapter-astro';
|
|
11
|
+
*
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* output: 'server',
|
|
14
|
+
* adapter: onreza(),
|
|
15
|
+
* image: {
|
|
16
|
+
* service: {
|
|
17
|
+
* entrypoint: '@onreza/adapter-astro/image',
|
|
18
|
+
* config: {
|
|
19
|
+
* sizes: [640, 750, 828, 1080, 1200, 1920],
|
|
20
|
+
* quality: 80,
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export type { OnrezaImageServiceConfig } from "./service.ts";
|
|
28
|
+
export { default } from "./service.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../chunk-934ybxvc.js";var $=[640,750,828,1080,1200,1920,2048,3840];function q(O){return typeof O==="object"&&O!==null&&"src"in O}function x(O){if(typeof O==="string")return O;if(q(O))return O.src;return String(O)}function M(O,J){if(O===void 0)return;if(J.length===0)return console.warn("[onreza:image] No allowed sizes configured, using width as-is"),O;return J.reduce((N,f)=>Math.abs(f-O)<Math.abs(N-O)?f:N)}var P={getHTMLAttributes(O,J){let{src:k,width:N,height:f,format:j,quality:B,...G}=O,K=N,V=f;if(typeof k==="object"&&k!==null&&"width"in k&&"height"in k){let X=k;if(X.width>0&&X.height>0){let Y=X.width/X.height;if(V&&!K)K=Math.round(V*Y);else if(K&&!V)V=Math.round(K/Y)}}return{...G,decoding:G.decoding??"async",loading:G.loading??"lazy",...K&&{width:K},...V&&{height:V}}},getSrcSet(O,J){let N=J.service.config?.sizes??$;if(O.width===void 0)return[];let f=O.width,j=N.indexOf(f);if(j===-1)return[];let B=[];if(B.push({descriptor:"1x",transform:{...O}}),j<N.length-1){let G=N[j+1];B.push({descriptor:"2x",transform:{...O,width:G}})}return B},getURL(O,J){let N=J.service.config?.quality??75,f=x(O.src);if(f.startsWith("http://")||f.startsWith("https://")||f.startsWith("//"))console.warn(`[onreza:image] External URL detected: "${f}". Platform will validate against allowed domains at runtime.`);let j=new URLSearchParams;if(j.set("url",f),O.width!==void 0)j.set("w",O.width.toString());if(O.height!==void 0)j.set("h",O.height.toString());let B=O.quality??N;if(j.set("q",B.toString()),O.format!==void 0)j.set("f",O.format);if(O.fit!==void 0)j.set("fit",O.fit);else if(O.position!==void 0){let K={bottom:"cover",center:"cover",entropy:"cover",left:"cover",right:"cover",top:"cover"}[O.position];if(K)j.set("fit",K)}if(O.blur!==void 0&&typeof O.blur==="number"){let G=Math.max(0,Math.min(250,O.blur));j.set("blur",G.toString())}if(O.dpr!==void 0&&typeof O.dpr==="number"){let G=Math.max(1,Math.min(5,O.dpr));j.set("dpr",G.toString())}return`/_onreza/image?${j.toString()}`},validateOptions(O,J){let k=J.service.config,N=k?.sizes??$,f=k?.quality??75,j={...O};if(j.width!==void 0){let B=j.width;if(j.width=M(j.width,N),j.width!==B)console.warn(`[onreza:image] Width ${B}px is not in allowed sizes. Using closest: ${j.width}px. Allowed sizes: ${N.join(", ")}`)}if(j.quality!==void 0&&typeof j.quality==="number"){if(j.quality<1||j.quality>100)console.warn(`[onreza:image] Quality ${j.quality} is out of range. Using default: ${f}`),j.quality=f}if(j.format!==void 0){if(!["webp","avif","jpg","jpeg","png","gif"].includes(j.format))console.warn(`[onreza:image] Format "${j.format}" may not be supported by platform.`)}if(j.blur!==void 0&&typeof j.blur==="number"){if(j.blur<0||j.blur>250)console.warn(`[onreza:image] Blur ${j.blur} is out of range (0-250). Clamping.`),j.blur=Math.max(0,Math.min(250,j.blur))}if(j.dpr!==void 0&&typeof j.dpr==="number"){if(j.dpr<1||j.dpr>5)console.warn(`[onreza:image] DPR ${j.dpr} is out of range (1-5). Clamping.`),j.dpr=Math.max(1,Math.min(5,j.dpr))}return j}},R=P;export{R as default};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONREZA Image Service for Astro
|
|
3
|
+
*
|
|
4
|
+
* External image service that uses platform image optimization.
|
|
5
|
+
* Images are optimized at runtime via /_onreza/image endpoint.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```js
|
|
9
|
+
* // astro.config.mjs
|
|
10
|
+
* import { defineConfig } from 'astro/config';
|
|
11
|
+
* import { onreza } from '@onreza/adapter-astro';
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* output: 'server',
|
|
15
|
+
* adapter: onreza(),
|
|
16
|
+
* image: {
|
|
17
|
+
* service: {
|
|
18
|
+
* entrypoint: '@onreza/adapter-astro/image',
|
|
19
|
+
* config: {
|
|
20
|
+
* // Optional: restrict sizes
|
|
21
|
+
* sizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
|
|
22
|
+
* // Optional: default quality
|
|
23
|
+
* quality: 75,
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import type { ExternalImageService } from "astro";
|
|
31
|
+
/**
|
|
32
|
+
* Configuration options for ONREZA image service
|
|
33
|
+
*/
|
|
34
|
+
export interface OnrezaImageServiceConfig {
|
|
35
|
+
/** Allowed image widths (defaults to platform preset) */
|
|
36
|
+
sizes?: number[];
|
|
37
|
+
/** Default quality (1-100, default: 75) */
|
|
38
|
+
quality?: number;
|
|
39
|
+
/** Default output format */
|
|
40
|
+
format?: "webp" | "avif";
|
|
41
|
+
/** Default fit mode */
|
|
42
|
+
fit?: "cover" | "contain" | "fill";
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* ONREZA External Image Service
|
|
46
|
+
*
|
|
47
|
+
* Generates URLs for platform image optimization endpoint.
|
|
48
|
+
* No local transformation - all processing happens at the edge.
|
|
49
|
+
*/
|
|
50
|
+
declare const service: ExternalImageService<OnrezaImageServiceConfig>;
|
|
51
|
+
export default service;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AstroIntegration } from "astro";
|
|
2
2
|
import type { OnrezaOptions } from "./types.ts";
|
|
3
|
-
export type { ApiRoute, IsrRoute, OnrezaManifest, Route, RoutePriority, RouteType, SsrRoute, StaticRoute, } from "@onreza/shared";
|
|
4
|
-
export type { IsrConfig, OnrezaOptions } from "./types.ts";
|
|
3
|
+
export type { ApiRoute, EdgeFunctionRoute, IsrRoute, OnrezaManifest, Route, RoutePriority, RouteType, SsrRoute, StaticRoute, } from "@onreza/shared";
|
|
4
|
+
export type { ImageOptimizationOptions, IsrConfig, OnrezaOptions } from "./types.ts";
|
|
5
5
|
export declare function onreza(options?: OnrezaOptions): AstroIntegration;
|