@onreza/adapter-nitro 0.2.3 → 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 +30 -0
- package/dist/image/index.js +1 -0
- package/dist/image/provider.d.ts +107 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/preset/preset.js +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @onreza/adapter-nitro/image
|
|
3
|
+
*
|
|
4
|
+
* Nuxt Image Provider for ONREZA platform image optimization.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* // nuxt.config.ts
|
|
9
|
+
* export default defineNuxtConfig({
|
|
10
|
+
* modules: ['@nuxt/image'],
|
|
11
|
+
* image: {
|
|
12
|
+
* provider: 'onreza',
|
|
13
|
+
* providers: {
|
|
14
|
+
* onreza: {
|
|
15
|
+
* provider: '@onreza/adapter-nitro/image',
|
|
16
|
+
* options: {
|
|
17
|
+
* sizes: [640, 750, 828, 1080, 1200, 1920],
|
|
18
|
+
* quality: 80,
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* },
|
|
23
|
+
* nitro: {
|
|
24
|
+
* preset: '@onreza/adapter-nitro'
|
|
25
|
+
* }
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export type { ImageModifiers, OnrezaImageProviderOptions } from "./provider.ts";
|
|
30
|
+
export { createOnrezaImageProvider, default, generateOnrezaImageURL } from "./provider.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var J=Object.defineProperty;var X=(x,N)=>{for(var g in N)J(x,g,{get:N[g],enumerable:!0,configurable:!0,set:(R)=>N[g]=()=>R})};var K=[640,750,828,1080,1200,1920,2048,3840];function P(x,N){if(x===void 0)return;if(N.length===0)return console.warn("[onreza:image] No allowed sizes configured, using width as-is"),x;return N.reduce((R,j)=>Math.abs(j-x)<Math.abs(R-x)?j:R)}function V(x){if(!x)return;return{contain:"contain",cover:"cover",fill:"fill",inside:"contain",outside:"cover"}[x]}function G(x,N,g){let R=N.sizes??K,j=N.quality??75;if(x.startsWith("http://")||x.startsWith("https://")||x.startsWith("//"))console.warn(`[onreza:image] External URL detected: "${x}". Platform will validate against allowed domains at runtime.`);if(x.includes("..")||x.includes("%2e")||x.includes("%2E"))throw Error(`[onreza:image] Path traversal detected in src: "${x}"`);let M=new URLSearchParams;if(M.set("url",x),g.width!==void 0){let C=P(g.width,R);if(C!==void 0){if(M.set("w",C.toString()),C!==g.width)console.warn(`[onreza:image] Width ${g.width}px is not in allowed sizes. Using closest: ${C}px.`)}}if(g.height!==void 0)M.set("h",g.height.toString());let k=g.quality??j;if(k<1||k>100)console.warn(`[onreza:image] Quality ${k} is out of range (1-100). Using default: ${j}`),k=j;if(M.set("q",k.toString()),g.format!==void 0){if(!["webp","avif","jpg","jpeg","png","gif"].includes(g.format))console.warn(`[onreza:image] Format "${g.format}" may not be supported. Using as-is.`);M.set("f",g.format)}let n=V(g.fit);if(n!==void 0)M.set("fit",n);if(g.position!==void 0&&!g.fit){let B={bottom:"cover",center:"cover",entropy:"cover",left:"cover",right:"cover",top:"cover"}[g.position];if(B)M.set("fit",B)}if(g.blur!==void 0){let C=Math.max(0,Math.min(250,g.blur));if(C>0)M.set("blur",C.toString())}if(g.dpr!==void 0&&typeof g.dpr==="number"){let C=Math.max(1,Math.min(5,g.dpr));M.set("dpr",C.toString())}return`/_onreza/image?${M.toString()}`}function H(x={}){return{getImage:(N,g)=>{return{url:G(N,x,g)}},name:"onreza"}}function I(x={}){return H(x)}export{G as generateOnrezaImageURL,I as default,H as createOnrezaImageProvider};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONREZA Image Provider for Nuxt/Nitro
|
|
3
|
+
*
|
|
4
|
+
* Integration with @nuxt/image for platform image optimization.
|
|
5
|
+
* Images are optimized at runtime via /_onreza/image endpoint.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // nuxt.config.ts
|
|
10
|
+
* export default defineNuxtConfig({
|
|
11
|
+
* modules: ['@nuxt/image'],
|
|
12
|
+
* image: {
|
|
13
|
+
* provider: 'onreza',
|
|
14
|
+
* providers: {
|
|
15
|
+
* onreza: {
|
|
16
|
+
* provider: '@onreza/adapter-nitro/image',
|
|
17
|
+
* options: {
|
|
18
|
+
* // Optional: restrict sizes
|
|
19
|
+
* sizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
|
|
20
|
+
* // Optional: default quality
|
|
21
|
+
* quality: 75,
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* },
|
|
26
|
+
* nitro: {
|
|
27
|
+
* preset: '@onreza/adapter-nitro'
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Provider configuration options
|
|
34
|
+
*/
|
|
35
|
+
export interface OnrezaImageProviderOptions {
|
|
36
|
+
/** Allowed image widths (defaults to platform preset) */
|
|
37
|
+
sizes?: number[];
|
|
38
|
+
/** Default quality (1-100, default: 75) */
|
|
39
|
+
quality?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Image modifiers from @nuxt/image
|
|
43
|
+
*/
|
|
44
|
+
export interface ImageModifiers {
|
|
45
|
+
width?: number;
|
|
46
|
+
height?: number;
|
|
47
|
+
quality?: number;
|
|
48
|
+
format?: string;
|
|
49
|
+
fit?: "cover" | "contain" | "fill" | "inside" | "outside";
|
|
50
|
+
position?: string;
|
|
51
|
+
blur?: number;
|
|
52
|
+
[q: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Generate optimized image URL for ONREZA platform
|
|
56
|
+
*
|
|
57
|
+
* @param src - Source image path
|
|
58
|
+
* @param options - Provider options
|
|
59
|
+
* @param modifiers - Image transformation modifiers
|
|
60
|
+
* @returns Optimized image URL
|
|
61
|
+
*/
|
|
62
|
+
export declare function generateOnrezaImageURL(src: string, options: OnrezaImageProviderOptions, modifiers: ImageModifiers): string;
|
|
63
|
+
/**
|
|
64
|
+
* Nuxt Image Provider for ONREZA
|
|
65
|
+
*
|
|
66
|
+
* @param providerOptions - Provider configuration from nuxt.config
|
|
67
|
+
* @returns Provider object with getImage method
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* // Usage in Nuxt component
|
|
72
|
+
* <NuxtImg
|
|
73
|
+
* src="/images/hero.jpg"
|
|
74
|
+
* width="1080"
|
|
75
|
+
* quality="80"
|
|
76
|
+
* format="webp"
|
|
77
|
+
* />
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function createOnrezaImageProvider(providerOptions?: OnrezaImageProviderOptions): {
|
|
81
|
+
getImage: (src: string, modifiers: ImageModifiers) => {
|
|
82
|
+
url: string;
|
|
83
|
+
};
|
|
84
|
+
name: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Default provider export for @nuxt/image
|
|
88
|
+
*
|
|
89
|
+
* Usage in nuxt.config.ts:
|
|
90
|
+
* ```ts
|
|
91
|
+
* image: {
|
|
92
|
+
* provider: 'onreza',
|
|
93
|
+
* providers: {
|
|
94
|
+
* onreza: {
|
|
95
|
+
* provider: '@onreza/adapter-nitro/image',
|
|
96
|
+
* options: { quality: 80 }
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export default function onrezaProvider(providerOptions?: OnrezaImageProviderOptions): {
|
|
103
|
+
getImage: (src: string, modifiers: ImageModifiers) => {
|
|
104
|
+
url: string;
|
|
105
|
+
};
|
|
106
|
+
name: string;
|
|
107
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ApiRoute, IsrRoute, OnrezaManifest, Route, RoutePriority, RouteType, SsrRoute, StaticRoute, } from "@onreza/shared";
|
|
1
|
+
export type { ApiRoute, EdgeFunctionRoute, FrameworkFeatures, ImageOptimizationConfig, IsrRoute, OnrezaManifest, PlatformBindings, Route, RoutePriority, RouteType, SessionConfig, SkewProtectionConfig, SsrRoute, StaticRoute, } from "@onreza/shared";
|
|
2
2
|
export { default } from "./preset/preset.ts";
|
|
3
3
|
export { collectRoutes, routeToRegex } from "./routes.ts";
|
|
4
4
|
export type { OnrezaRoute } from "./types.ts";
|