@onreza/adapter-nitro 0.2.2 → 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/README.md +44 -5
- 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 +2 -2
- package/dist/index.js +1 -1
- package/dist/preset/preset.js +1 -1
- package/dist/routes.d.ts +4 -4
- package/dist/types.d.ts +0 -19
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -102,17 +102,56 @@ export default defineNuxtConfig({
|
|
|
102
102
|
|
|
103
103
|
## Build output
|
|
104
104
|
|
|
105
|
-
После сборки адаптер
|
|
105
|
+
После сборки адаптер генерирует структуру, совместимую с [ONREZA Build Output Specification](https://github.com/onreza/platform/blob/main/docs/architecture/BUILD_OUTPUT_SPEC.md):
|
|
106
106
|
|
|
107
107
|
```
|
|
108
108
|
.output/
|
|
109
109
|
├── .onreza/
|
|
110
|
-
│ └── manifest.json # Метаданные билда
|
|
110
|
+
│ └── manifest.json # Метаданные билда (версия 1)
|
|
111
111
|
├── server/
|
|
112
|
-
│ └── entry.mjs # Server handler (fetch контракт)
|
|
113
|
-
├── client/ # Static assets
|
|
114
|
-
│ └── _nuxt/
|
|
112
|
+
│ └── entry.mjs # Server handler (Web fetch контракт)
|
|
113
|
+
├── client/ # Static assets
|
|
114
|
+
│ └── _nuxt/ # Nuxt assets (или _assets/ для Nitro)
|
|
115
115
|
└── prerender/ # Prerendered HTML (опционально)
|
|
116
|
+
└── about/
|
|
117
|
+
└── index.html
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Формат manifest.json
|
|
121
|
+
|
|
122
|
+
Адаптер генерирует манифест версии 1:
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"version": 1,
|
|
127
|
+
"adapter": {
|
|
128
|
+
"name": "@onreza/adapter-nitro",
|
|
129
|
+
"version": "0.2.1"
|
|
130
|
+
},
|
|
131
|
+
"framework": {
|
|
132
|
+
"name": "nuxt",
|
|
133
|
+
"version": "3.17.0"
|
|
134
|
+
},
|
|
135
|
+
"server": {
|
|
136
|
+
"entry": "server/entry.mjs",
|
|
137
|
+
"export": "fetch"
|
|
138
|
+
},
|
|
139
|
+
"assets": {
|
|
140
|
+
"directory": "client",
|
|
141
|
+
"prefix": "/_nuxt/"
|
|
142
|
+
},
|
|
143
|
+
"routes": [
|
|
144
|
+
{ "pattern": "^/_nuxt/.*$", "type": "static", "priority": 100 },
|
|
145
|
+
{ "pattern": "^/api/.*$", "type": "api", "priority": 20 },
|
|
146
|
+
{ "pattern": "^/.*$", "type": "ssr", "priority": 0 }
|
|
147
|
+
],
|
|
148
|
+
"prerender": {
|
|
149
|
+
"directory": "prerender",
|
|
150
|
+
"pages": {
|
|
151
|
+
"/about": { "html": "about/index.html" }
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
116
155
|
```
|
|
117
156
|
|
|
118
157
|
## Ограничения
|
|
@@ -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
|
-
export type {
|
|
4
|
+
export type { OnrezaRoute } from "./types.ts";
|