@ilha/router 0.6.6 → 0.6.8
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/codegen.d.ts +21 -0
- package/dist/hash.d.ts +44 -0
- package/dist/index.d.ts +341 -2
- package/dist/index.js +1 -1
- package/dist/plugin-DBB11WaX.js +6 -0
- package/dist/plugin.d.ts +56 -0
- package/dist/rolldown.d.ts +4 -8
- package/dist/rolldown.js +1 -1
- package/dist/rspack.d.ts +4 -7
- package/dist/rspack.js +1 -1
- package/dist/src-Cgv3m3sQ.js +4 -0
- package/dist/ssr.d.ts +93 -0
- package/dist/ssr.js +15 -0
- package/dist/vite.d.ts +5 -9952
- package/dist/vite.js +1 -1
- package/package.json +11 -4
- package/dist/index-DZA_1KrG.d.ts +0 -299
- package/dist/plugin-OpojKenS.js +0 -6
- package/dist/plugin-rauddckN.d.ts +0 -28
- package/dist/src-Cprpo919.js +0 -3
package/dist/ssr.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import "ilha:loaders";
|
|
2
|
+
import type { HeadInput, HydratableRenderOptions, SerializedHead } from "./index";
|
|
3
|
+
export interface AssetAttrs {
|
|
4
|
+
href: string;
|
|
5
|
+
"data-vite-dev-id"?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Manifest slice without `merge` — matches Nitro/Vite `?assets` raw shape. */
|
|
8
|
+
export interface AssetsRaw {
|
|
9
|
+
entry?: string;
|
|
10
|
+
js: AssetAttrs[];
|
|
11
|
+
css: AssetAttrs[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The asset descriptor produced by the `?assets=client` / `?assets=ssr`
|
|
15
|
+
* imports. `merge` combines several descriptors, de-duping by href.
|
|
16
|
+
*
|
|
17
|
+
* Structurally compatible with Nitro's `ImportAssetsResult`.
|
|
18
|
+
*/
|
|
19
|
+
export type Assets = AssetsRaw & {
|
|
20
|
+
merge(...others: AssetsRaw[]): Assets;
|
|
21
|
+
};
|
|
22
|
+
/** Client + SSR manifests from `?assets=client` / `?assets=ssr` imports. */
|
|
23
|
+
export interface IlhaAssetsPair {
|
|
24
|
+
client: Assets;
|
|
25
|
+
server: Assets;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Merge client and SSR asset manifests (same as `client.merge(server)` from Nitro).
|
|
29
|
+
*/
|
|
30
|
+
export declare function mergeAssets({ client, server }: IlhaAssetsPair): Assets;
|
|
31
|
+
/**
|
|
32
|
+
* App-wide `<head>` defaults for `IlhaHandler`. Same shape as route `head()`;
|
|
33
|
+
* use so entry files read clearly: `head: appHead({ title, script: [...] })`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function appHead(head: HeadInput): HeadInput;
|
|
36
|
+
export interface IlhaHandlerOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Merged asset manifest — use `mergeAssets({ client, server })` with imports
|
|
39
|
+
* from `?assets=client` and `?assets=ssr`.
|
|
40
|
+
*/
|
|
41
|
+
assets: Assets;
|
|
42
|
+
/** `<html lang>` value. Default: `"en"`. */
|
|
43
|
+
lang?: string;
|
|
44
|
+
/** Id of the hydration mount container. Default: `"app"`. */
|
|
45
|
+
appId?: string;
|
|
46
|
+
/** Fallback client entry used when the merged assets have no `entry`. */
|
|
47
|
+
clientEntry?: string;
|
|
48
|
+
/**
|
|
49
|
+
* App-wide `<head>` defaults — same shape as the `head()` API. Route-level
|
|
50
|
+
* head (from loaders/pages) is merged on top, so anything here acts as a
|
|
51
|
+
* base. Use it for the default `title`, app meta, and inline scripts.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* head: {
|
|
55
|
+
* title: "Ilha + Nitro",
|
|
56
|
+
* script: [{ children: themeScript }],
|
|
57
|
+
* }
|
|
58
|
+
*/
|
|
59
|
+
head?: HeadInput;
|
|
60
|
+
/** Options forwarded to `pageRouter.renderHydratable` / `renderResponse`. */
|
|
61
|
+
renderOptions?: HydratableRenderOptions;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* SSR host helper for Ilha apps. Wires the generated `pageRouter` /
|
|
65
|
+
* `registry` and the asset manifest into a single `fetch`-style handler so a
|
|
66
|
+
* host entry collapses to:
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { IlhaHandler } from "@ilha/router/ssr";
|
|
70
|
+
* import client from "./entry-client.ts?assets=client";
|
|
71
|
+
* import server from "./entry-server.ts?assets=ssr";
|
|
72
|
+
*
|
|
73
|
+
* const handler = new IlhaHandler({
|
|
74
|
+
* assets: mergeAssets({ client, server }),
|
|
75
|
+
* head: appHead({ title: "My app", script: [{ children: "..." }] }),
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* export default { fetch: (request: Request) => handler.handle(request) };
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare class IlhaHandler {
|
|
82
|
+
private readonly assets;
|
|
83
|
+
private readonly lang;
|
|
84
|
+
private readonly appId;
|
|
85
|
+
private readonly clientEntry;
|
|
86
|
+
private readonly head;
|
|
87
|
+
private readonly renderOptions;
|
|
88
|
+
constructor(options: IlhaHandlerOptions);
|
|
89
|
+
/** Render the document shell around an already-rendered island body. */
|
|
90
|
+
document(body: string, head?: SerializedHead): string;
|
|
91
|
+
/** Handle an incoming request and return a full HTML / redirect Response. */
|
|
92
|
+
handle(request: Request): Promise<Response>;
|
|
93
|
+
}
|
package/dist/ssr.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import"./src-Cgv3m3sQ.js";import{pageRouter as e,registry as t}from"ilha:pages/server";import"ilha:loaders";function n({client:e,server:t}){return e.merge(t)}function r(e){return e}function i(e){let t=e[`data-vite-dev-id`]?` data-vite-dev-id="${e[`data-vite-dev-id`]}"`:``;return`<link rel="stylesheet" href="${e.href}"${t} />`}var a=class{assets;lang;appId;clientEntry;head;renderOptions;constructor(e){this.assets=e.assets,this.lang=e.lang??`en`,this.appId=e.appId??`app`,this.clientEntry=e.clientEntry??`/entry-client.js`,this.head=e.head??{},this.renderOptions=e.renderOptions??{}}document(e,t){let n=this.assets.entry??this.clientEntry,r=this.assets.css.map(i).join(`
|
|
2
|
+
`),a=t?.headTags.includes(`<title`)?``:`<title>Ilha</title>
|
|
3
|
+
`,o=t?.headTags?`\n ${t.headTags}`:``,s=t?.htmlAttrs??``;return`<!doctype html>
|
|
4
|
+
<html lang="${s.match(/\blang="([^"]*)"/)?.[1]??this.lang}"${s.replace(/\s*lang="[^"]*"/,``)}>
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="UTF-8" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
+
${a}<link rel="icon" href="/favicon.svg" />
|
|
9
|
+
${r}${o}
|
|
10
|
+
</head>
|
|
11
|
+
<body${t?.bodyAttrs??``}>
|
|
12
|
+
<div id="${this.appId}">${e}</div>
|
|
13
|
+
<script type="module" src="${n}"><\/script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>`}async handle(n){let r=new URL(n.url);if(r.pathname===`/__ilha/loader`){let t=r.searchParams.get(`path`)??`/`,i=await e.runLoader(t,n),a=i.kind===`error`?i.status:i.kind===`not-found`?404:200;return new Response(JSON.stringify(i),{status:a,headers:{"content-type":`application/json;charset=utf-8`}})}let i=r.href.slice(r.origin.length),a={...this.renderOptions,baseHead:this.head},o=await e.renderResponse(i,t,a,n);if(o.kind===`redirect`)return new Response(null,{status:o.status,headers:{location:o.to}});let s=o.kind===`error`?o.status:o.status??200;return new Response(this.document(o.html,o.head),{status:s,headers:{"content-type":`text/html;charset=utf-8`}})}};export{a as IlhaHandler,r as appHead,n as mergeAssets};
|