vinojs 0.0.1 → 0.1.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 +172 -0
- package/dist/client.d.mts +41 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +287 -0
- package/dist/client.mjs.map +1 -0
- package/dist/compile-Lxl_tdxL.mjs +155 -0
- package/dist/compile-Lxl_tdxL.mjs.map +1 -0
- package/dist/component-wrap.d.mts +10 -0
- package/dist/component-wrap.d.mts.map +1 -0
- package/dist/component-wrap.mjs +33 -0
- package/dist/component-wrap.mjs.map +1 -0
- package/dist/constants-BVT2bJEd.mjs +27 -0
- package/dist/constants-BVT2bJEd.mjs.map +1 -0
- package/dist/definePage-Ba4r-TFh.mjs +51 -0
- package/dist/definePage-Ba4r-TFh.mjs.map +1 -0
- package/dist/types-CQITdkpF.d.mts +77 -0
- package/dist/types-CQITdkpF.d.mts.map +1 -0
- package/dist/vino.d.mts +144 -0
- package/dist/vino.d.mts.map +1 -0
- package/dist/vino.mjs +197 -0
- package/dist/vino.mjs.map +1 -0
- package/dist/vite.d.mts +10 -0
- package/dist/vite.d.mts.map +1 -0
- package/dist/vite.mjs +729 -0
- package/dist/vite.mjs.map +1 -0
- package/examples/basic/dist/client/.assetsignore +2 -0
- package/examples/basic/dist/client/about.html +1 -0
- package/examples/basic/dist/client/admin.html +1 -0
- package/examples/basic/dist/client/assets/Counter-BvqMZKON.js +1 -0
- package/examples/basic/dist/client/assets/_slug_-CYpOSbrn.js +1 -0
- package/examples/basic/dist/client/assets/about-BZXRzUyv.js +1 -0
- package/examples/basic/dist/client/assets/admin-DRE7uh2s.js +1 -0
- package/examples/basic/dist/client/assets/client-B6nFkut5.js +1 -0
- package/examples/basic/dist/client/assets/client-pages-Bc6cNZAm.js +2 -0
- package/examples/basic/dist/client/assets/components-DX9r6vHn.js +1 -0
- package/examples/basic/dist/client/assets/components-DsWJ6F73.js +2 -0
- package/examples/basic/dist/client/assets/counter-DBpvln_F.js +1 -0
- package/examples/basic/dist/client/assets/dom-B5sHIJ1E.js +1 -0
- package/examples/basic/dist/client/assets/honoto-9UtdLp4J.js +33 -0
- package/examples/basic/dist/client/assets/honoto-client-DEh86_WZ.css +1 -0
- package/examples/basic/dist/client/assets/honoto-client.js +2 -0
- package/examples/basic/dist/client/assets/hooks-Cz6AT21d.js +1 -0
- package/examples/basic/dist/client/assets/jsx-dev-runtime-92VDsVyo.js +1 -0
- package/examples/basic/dist/client/counter.html +1 -0
- package/examples/basic/dist/client/index.html +1 -0
- package/examples/basic/dist/client/jobs.html +1 -0
- package/examples/basic/dist/ssr/.vite/manifest.json +140 -0
- package/examples/basic/dist/ssr/assets/_slug_-CY3-kffX.js +46 -0
- package/examples/basic/dist/ssr/assets/about-CTDjNhkO.js +15 -0
- package/examples/basic/dist/ssr/assets/admin-DvS-UGJx.js +26 -0
- package/examples/basic/dist/ssr/assets/constants-UoriGYcX-CUecBFMT.js +6 -0
- package/examples/basic/dist/ssr/assets/counter-DfIbc9Sp.js +30 -0
- package/examples/basic/dist/ssr/assets/honoto-CA313cVy.js +2129 -0
- package/examples/basic/dist/ssr/assets/jobs-D9hh-UO9.js +42 -0
- package/examples/basic/dist/ssr/assets/jsx-CgYLQazd.js +1080 -0
- package/examples/basic/dist/ssr/assets/jsx-dev-runtime-BlUda7H8.js +742 -0
- package/examples/basic/dist/ssr/assets/jsx-renderer-CzZcZPnS.js +65 -0
- package/examples/basic/dist/ssr/assets/layout-DYvLwr2u.js +53 -0
- package/examples/basic/dist/ssr/assets/pages-DB6jeyrt.js +53 -0
- package/examples/basic/dist/ssr/assets/rolldown-runtime-D7D4PA-g.js +13 -0
- package/examples/basic/dist/ssr/assets/ssr-hooks-CBQr0cdH.js +7 -0
- package/examples/basic/dist/ssr/index.js +22 -0
- package/examples/basic/dist/ssr/wrangler.json +1 -0
- package/examples/full/dist/client/.assetsignore +2 -0
- package/examples/full/dist/client/assets/BookmarkButton-py0xGxgl.js +1 -0
- package/examples/full/dist/client/assets/_slug_-DZUFsE9O.js +1 -0
- package/examples/full/dist/client/assets/auth-client-D2Wtuobe.js +1 -0
- package/examples/full/dist/client/assets/bun-sqlite-dialect-C7ftEUSI-CsHdUKBY.js +1 -0
- package/examples/full/dist/client/assets/client-B6nFkut5.js +1 -0
- package/examples/full/dist/client/assets/client-pages-fshKs747.js +2 -0
- package/examples/full/dist/client/assets/components-DX9r6vHn.js +1 -0
- package/examples/full/dist/client/assets/components-S_-rWrKi.js +2 -0
- package/examples/full/dist/client/assets/d1-sqlite-dialect-BZmaVTp8-FPCaMZqX.js +1 -0
- package/examples/full/dist/client/assets/default-query-compiler-CUdqIu1h.js +1 -0
- package/examples/full/dist/client/assets/dist-BoGTNvkC.js +1 -0
- package/examples/full/dist/client/assets/dom-DCd3wYW7.js +1 -0
- package/examples/full/dist/client/assets/factory-Bgf4EtLx.js +8 -0
- package/examples/full/dist/client/assets/honoto-client-BSvNAnxN.css +1 -0
- package/examples/full/dist/client/assets/honoto-client.js +2 -0
- package/examples/full/dist/client/assets/hooks-Cz6AT21d.js +1 -0
- package/examples/full/dist/client/assets/jsx-dev-runtime-92VDsVyo.js +1 -0
- package/examples/full/dist/client/assets/kysely-adapter-BHhasAnc.js +1 -0
- package/examples/full/dist/client/assets/kysely-migration-tables-DFfmKhq--U5ujlMwE.js +1 -0
- package/examples/full/dist/client/assets/node-sqlite-dialect-DJDXH5Ot.js +1 -0
- package/examples/full/dist/client/assets/pages-CUQx6Eus.js +1 -0
- package/examples/full/dist/client/assets/saved-jIi74ncJ.js +1 -0
- package/examples/full/dist/client/assets/session-B-accyM3.js +611 -0
- package/examples/full/dist/client/assets/sign-in-BelI3gSs.js +1 -0
- package/examples/full/dist/client/assets/sign-up-pR94lfdu.js +1 -0
- package/examples/full/dist/client/index.html +1 -0
- package/examples/full/dist/client/saved.html +1 -0
- package/examples/full/dist/client/sign-in.html +1 -0
- package/examples/full/dist/client/sign-up.html +1 -0
- package/examples/full/dist/ssr/.dev.vars +1 -0
- package/examples/full/dist/ssr/.vite/manifest.json +219 -0
- package/examples/full/dist/ssr/assets/BookmarkButton-KS7z5_vi.js +298 -0
- package/examples/full/dist/ssr/assets/_slug_-rRStRaAN.js +89 -0
- package/examples/full/dist/ssr/assets/auth-DSFZ4iak.js +31434 -0
- package/examples/full/dist/ssr/assets/auth-client-BFSBVoML.js +894 -0
- package/examples/full/dist/ssr/assets/bun-sqlite-dialect-C7ftEUSI-BeXpIqKl.js +162 -0
- package/examples/full/dist/ssr/assets/compiled-query-DmoyCh28.js +8410 -0
- package/examples/full/dist/ssr/assets/d1-sqlite-dialect-BZmaVTp8-CjJdvL94.js +114 -0
- package/examples/full/dist/ssr/assets/default-query-compiler-D7xOzCCJ.js +1727 -0
- package/examples/full/dist/ssr/assets/dist-LmmDoNdk.js +6832 -0
- package/examples/full/dist/ssr/assets/dist-kFDN1l4Z.js +342 -0
- package/examples/full/dist/ssr/assets/factory-AD6s9SIW.js +2079 -0
- package/examples/full/dist/ssr/assets/jsx-renderer-mMLf5XLN.js +1926 -0
- package/examples/full/dist/ssr/assets/kysely-adapter-BCLenpM8.js +2 -0
- package/examples/full/dist/ssr/assets/kysely-migration-tables-DFfmKhq--BtVr6hRe.js +17 -0
- package/examples/full/dist/ssr/assets/layout-mVA7qP4j.js +44 -0
- package/examples/full/dist/ssr/assets/node-sqlite-dialect-D-wtYAD7.js +162 -0
- package/examples/full/dist/ssr/assets/pages-Do5kR_Ia.js +147 -0
- package/examples/full/dist/ssr/assets/saved-Dr4pP6B5.js +111 -0
- package/examples/full/dist/ssr/assets/session-BvIpX7tr.js +13 -0
- package/examples/full/dist/ssr/assets/sign-in-22pzTnJE.js +115 -0
- package/examples/full/dist/ssr/assets/sign-up-CN4j8Qg1.js +117 -0
- package/examples/full/dist/ssr/assets/sqlite-adapter-DVlms5wO.js +79 -0
- package/examples/full/dist/ssr/index.js +97 -0
- package/examples/full/dist/ssr/wrangler.json +1 -0
- package/package.json +62 -6
- package/index.js +0 -1
package/dist/vino.mjs
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { c as PAGE_SLOT_ID, l as PAYLOAD_SCRIPT_ID, o as NAV_HEADER, t as COMPONENT_TAG, u as SHELL_HEADER } from "./constants-BVT2bJEd.mjs";
|
|
2
|
+
import { a as isServerPageDefinition, i as isPageDefinition, n as defineServerPage, r as isClientPageDefinition, s as resolvePageRender, t as definePage } from "./definePage-Ba4r-TFh.mjs";
|
|
3
|
+
import { d as readServerFn, l as defineServerFn, m as loadMergedData, p as loadMergedConfig, r as compileFilePath, t as applyParams, u as isServerFn } from "./compile-Lxl_tdxL.mjs";
|
|
4
|
+
import { wrapComponent, wrapModule } from "./component-wrap.mjs";
|
|
5
|
+
import { Hono } from "hono";
|
|
6
|
+
import { jsxDEV } from "hono/jsx/jsx-dev-runtime";
|
|
7
|
+
import { manifest } from "virtual:vino/manifest";
|
|
8
|
+
import { clientScriptSrc, isDev } from "virtual:vino/assets";
|
|
9
|
+
import { jsxRenderer } from "hono/jsx-renderer";
|
|
10
|
+
//#region src/vino/render.ts
|
|
11
|
+
function DefaultLayout(props) {
|
|
12
|
+
return jsxDEV("html", { children: [jsxDEV("head", { children: [jsxDEV("meta", { charset: "utf-8" }), jsxDEV("meta", {
|
|
13
|
+
name: "viewport",
|
|
14
|
+
content: "width=device-width, initial-scale=1"
|
|
15
|
+
})] }), jsxDEV("body", { children: props.children })] });
|
|
16
|
+
}
|
|
17
|
+
function isHonoApp(value) {
|
|
18
|
+
return value instanceof Hono;
|
|
19
|
+
}
|
|
20
|
+
function payloadScript(payload) {
|
|
21
|
+
const json = JSON.stringify(payload).replaceAll("<", "\\u003c");
|
|
22
|
+
return `<script id="${PAYLOAD_SCRIPT_ID}" type="application/json">${json}<\/script>`;
|
|
23
|
+
}
|
|
24
|
+
function injectDocument(html, payload, isDev, scriptSrc) {
|
|
25
|
+
const vite = isDev ? `<script type="module" src="/@vite/client"><\/script>` : "";
|
|
26
|
+
const client = `<script type="module" src="${scriptSrc}"><\/script>`;
|
|
27
|
+
const inject = `${vite}${payloadScript(payload)}${client}`;
|
|
28
|
+
if (html.includes("</body>")) return html.replace("</body>", `${inject}</body>`);
|
|
29
|
+
if (html.includes("</html>")) return html.replace("</html>", `${inject}</html>`);
|
|
30
|
+
return `<!DOCTYPE html>${html}${inject}`;
|
|
31
|
+
}
|
|
32
|
+
async function ensureJsxRenderer(c) {
|
|
33
|
+
await jsxRenderer(void 0, { docType: true })(c, async () => {});
|
|
34
|
+
}
|
|
35
|
+
function needsPageSlot(page, config, mode) {
|
|
36
|
+
if (mode === "shell" || mode === "content") return true;
|
|
37
|
+
if (page.isClientPage) return true;
|
|
38
|
+
if (config.clientRouting === true) return true;
|
|
39
|
+
if (config.prerender === "partial") return true;
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
function emptySlot() {
|
|
43
|
+
return jsxDEV("div", { id: PAGE_SLOT_ID });
|
|
44
|
+
}
|
|
45
|
+
function wrapSlot(children) {
|
|
46
|
+
return jsxDEV("div", {
|
|
47
|
+
id: PAGE_SLOT_ID,
|
|
48
|
+
children
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function buildPayload(options) {
|
|
52
|
+
const { page, params, data, config, mode, requestPath, title } = options;
|
|
53
|
+
return {
|
|
54
|
+
path: requestPath ?? (page.path === "" ? "/" : page.path),
|
|
55
|
+
params,
|
|
56
|
+
data,
|
|
57
|
+
clientRouting: config.clientRouting === true,
|
|
58
|
+
clientPage: page.isClientPage ? page.path : null,
|
|
59
|
+
partial: mode === "shell",
|
|
60
|
+
title
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async function renderPageHtml(options) {
|
|
64
|
+
const { c, page, pageNode = null, data, params, config, isDev, clientScriptSrc, mode = "full", title } = options;
|
|
65
|
+
const payload = buildPayload({
|
|
66
|
+
page,
|
|
67
|
+
params,
|
|
68
|
+
data,
|
|
69
|
+
config,
|
|
70
|
+
mode,
|
|
71
|
+
requestPath: c.req.path,
|
|
72
|
+
title
|
|
73
|
+
});
|
|
74
|
+
if (mode === "content") {
|
|
75
|
+
if (pageNode == null) throw new Error("content render requires pageNode");
|
|
76
|
+
const node = wrapSlot(pageNode);
|
|
77
|
+
await ensureJsxRenderer(c);
|
|
78
|
+
let html = await (await c.render(node)).text();
|
|
79
|
+
html = html.replace(/^<!DOCTYPE html>/i, "");
|
|
80
|
+
html = `${html}${payloadScript(payload)}`;
|
|
81
|
+
return {
|
|
82
|
+
html,
|
|
83
|
+
payload
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
let node = mode === "shell" ? emptySlot() : pageNode;
|
|
87
|
+
if (mode !== "shell" && needsPageSlot(page, config, mode)) node = wrapSlot(node);
|
|
88
|
+
const layouts = await Promise.all(page.loadLayouts.map((load) => load()));
|
|
89
|
+
for (const layout of [...layouts].reverse()) {
|
|
90
|
+
const Layout = layout.default;
|
|
91
|
+
node = jsxDEV(Layout, {
|
|
92
|
+
data,
|
|
93
|
+
params,
|
|
94
|
+
children: node
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (layouts.length === 0) node = jsxDEV(DefaultLayout, { children: node });
|
|
98
|
+
await ensureJsxRenderer(c);
|
|
99
|
+
let html = await (await c.render(node)).text();
|
|
100
|
+
html = injectDocument(html, payload, isDev, clientScriptSrc);
|
|
101
|
+
if (!html.startsWith("<!")) html = `<!DOCTYPE html>${html}`;
|
|
102
|
+
return {
|
|
103
|
+
html,
|
|
104
|
+
payload
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/vino/createVino.ts
|
|
109
|
+
function requestParams(c) {
|
|
110
|
+
try {
|
|
111
|
+
return c.req.param();
|
|
112
|
+
} catch {
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function pageFromModule(pageMod, data, params) {
|
|
117
|
+
const Page = resolvePageRender(pageMod.default);
|
|
118
|
+
if (Page) return jsxDEV(Page, {
|
|
119
|
+
data,
|
|
120
|
+
params
|
|
121
|
+
});
|
|
122
|
+
return pageMod.default;
|
|
123
|
+
}
|
|
124
|
+
function resolveRenderMode(c) {
|
|
125
|
+
if (c.req.header("X-Vino-Shell")) return "shell";
|
|
126
|
+
if (c.req.header("X-Vino-Nav")) return "content";
|
|
127
|
+
return "full";
|
|
128
|
+
}
|
|
129
|
+
async function handlePage(c, page) {
|
|
130
|
+
const pageMod = await page.loadPage();
|
|
131
|
+
if (isHonoApp(pageMod.default)) return pageMod.default.fetch(c.req.raw, c.env, c.executionCtx);
|
|
132
|
+
const method = c.req.method;
|
|
133
|
+
const named = pageMod[method];
|
|
134
|
+
const hasPage = Boolean(resolvePageRender(pageMod.default));
|
|
135
|
+
const mode = resolveRenderMode(c);
|
|
136
|
+
if (typeof named === "function" && (method !== "GET" || !hasPage)) {
|
|
137
|
+
const result = await named(c);
|
|
138
|
+
if (result instanceof Response) return result;
|
|
139
|
+
if (method === "GET" || method === "HEAD") {
|
|
140
|
+
const config = loadMergedConfig(page, pageMod);
|
|
141
|
+
const params = requestParams(c);
|
|
142
|
+
const data = mode === "shell" ? void 0 : await loadMergedData(page, c, pageMod);
|
|
143
|
+
const { html } = await renderPageHtml({
|
|
144
|
+
c,
|
|
145
|
+
page,
|
|
146
|
+
pageMod,
|
|
147
|
+
pageNode: mode === "shell" ? null : result,
|
|
148
|
+
data,
|
|
149
|
+
params,
|
|
150
|
+
config,
|
|
151
|
+
isDev,
|
|
152
|
+
clientScriptSrc,
|
|
153
|
+
mode
|
|
154
|
+
});
|
|
155
|
+
return c.html(html);
|
|
156
|
+
}
|
|
157
|
+
return c.json(result);
|
|
158
|
+
}
|
|
159
|
+
if (method !== "GET" && method !== "HEAD") return c.text("Method Not Allowed", 405);
|
|
160
|
+
const config = loadMergedConfig(page, pageMod);
|
|
161
|
+
const params = requestParams(c);
|
|
162
|
+
const data = mode === "shell" ? void 0 : await loadMergedData(page, c, pageMod);
|
|
163
|
+
const { html } = await renderPageHtml({
|
|
164
|
+
c,
|
|
165
|
+
page,
|
|
166
|
+
pageMod,
|
|
167
|
+
pageNode: mode === "shell" ? null : pageFromModule(pageMod, data, params),
|
|
168
|
+
data,
|
|
169
|
+
params,
|
|
170
|
+
config,
|
|
171
|
+
isDev,
|
|
172
|
+
clientScriptSrc,
|
|
173
|
+
mode
|
|
174
|
+
});
|
|
175
|
+
return c.html(html);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Mount filesystem pages from the Vite-generated manifest onto a user-owned Hono app.
|
|
179
|
+
* Extra API routes should be registered on `app` before calling this.
|
|
180
|
+
*/
|
|
181
|
+
function mountVino(app, options = {}) {
|
|
182
|
+
const manifest$1 = options.manifest ?? manifest;
|
|
183
|
+
for (const page of manifest$1.pages) app.get(page.pattern, (c) => handlePage(c, page));
|
|
184
|
+
return app;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Create a new Vino app. Returns a Hono app with the Vino pages mounted.
|
|
188
|
+
* @param options - The options for the Vino app.
|
|
189
|
+
* @returns A Hono app with the Vino pages mounted.
|
|
190
|
+
*/
|
|
191
|
+
function createVino(options = {}) {
|
|
192
|
+
return mountVino(new Hono(), options);
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { COMPONENT_TAG, NAV_HEADER, PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID, SHELL_HEADER, applyParams, compileFilePath, createVino, definePage, defineServerFn, defineServerPage, isClientPageDefinition, isPageDefinition, isServerFn, isServerPageDefinition, mountVino, readServerFn, resolvePageRender, wrapComponent, wrapModule };
|
|
196
|
+
|
|
197
|
+
//# sourceMappingURL=vino.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vino.mjs","names":["jsx","jsx","assetsIsDev","manifest","virtualManifest"],"sources":["../src/vino/render.ts","../src/vino/createVino.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { Context } from \"hono\";\nimport type { Child } from \"hono/jsx\";\nimport { jsxDEV as jsx } from \"hono/jsx/jsx-dev-runtime\";\nimport { jsxRenderer } from \"hono/jsx-renderer\";\nimport { PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID } from \"./constants.ts\";\nimport type { ManifestPage, PageConfig, PageModule, RenderMode, VinoPayload } from \"./types.ts\";\n\nfunction DefaultLayout(props: { children?: Child }) {\n return jsx(\"html\", {\n children: [\n jsx(\"head\", {\n children: [\n jsx(\"meta\", { charset: \"utf-8\" }),\n jsx(\"meta\", { name: \"viewport\", content: \"width=device-width, initial-scale=1\" }),\n ],\n }),\n jsx(\"body\", { children: props.children }),\n ],\n });\n}\n\nexport function isHonoApp(value: unknown): value is Hono {\n return value instanceof Hono;\n}\n\nfunction payloadScript(payload: VinoPayload): string {\n const json = JSON.stringify(payload).replaceAll(\"<\", \"\\\\u003c\");\n return `<script id=\"${PAYLOAD_SCRIPT_ID}\" type=\"application/json\">${json}</script>`;\n}\n\nexport function injectDocument(\n html: string,\n payload: VinoPayload,\n isDev: boolean,\n scriptSrc: string,\n): string {\n const vite = isDev ? `<script type=\"module\" src=\"/@vite/client\"></script>` : \"\";\n const client = `<script type=\"module\" src=\"${scriptSrc}\"></script>`;\n const inject = `${vite}${payloadScript(payload)}${client}`;\n if (html.includes(\"</body>\")) return html.replace(\"</body>\", `${inject}</body>`);\n if (html.includes(\"</html>\")) return html.replace(\"</html>\", `${inject}</html>`);\n return `<!DOCTYPE html>${html}${inject}`;\n}\n\nasync function ensureJsxRenderer(c: Context): Promise<void> {\n await jsxRenderer(undefined, { docType: true })(c, async () => {});\n}\n\nfunction needsPageSlot(page: ManifestPage, config: PageConfig, mode: RenderMode): boolean {\n if (mode === \"shell\" || mode === \"content\") return true;\n if (page.isClientPage) return true;\n if (config.clientRouting === true) return true;\n if (config.prerender === \"partial\") return true;\n return false;\n}\n\nfunction emptySlot(): Child {\n return jsx(\"div\", { id: PAGE_SLOT_ID });\n}\n\nfunction wrapSlot(children: Child): Child {\n return jsx(\"div\", { id: PAGE_SLOT_ID, children });\n}\n\nfunction buildPayload(options: {\n page: ManifestPage;\n params: Record<string, string>;\n data: unknown;\n config: PageConfig;\n mode: RenderMode;\n requestPath?: string;\n title?: string;\n}): VinoPayload {\n const { page, params, data, config, mode, requestPath, title } = options;\n const path = requestPath ?? (page.path === \"\" ? \"/\" : page.path);\n return {\n path,\n params,\n data,\n clientRouting: config.clientRouting === true,\n clientPage: page.isClientPage ? page.path : null,\n partial: mode === \"shell\",\n title,\n };\n}\n\nexport async function renderPageHtml(options: {\n c: Context;\n page: ManifestPage;\n pageMod: PageModule;\n pageNode?: Child | null;\n data: unknown;\n params: Record<string, string>;\n config: PageConfig;\n isDev: boolean;\n clientScriptSrc: string;\n mode?: RenderMode;\n title?: string;\n}): Promise<{ html: string; payload: VinoPayload }> {\n const {\n c,\n page,\n pageNode = null,\n data,\n params,\n config,\n isDev,\n clientScriptSrc,\n mode = \"full\",\n title,\n } = options;\n\n const payload = buildPayload({\n page,\n params,\n data,\n config,\n mode,\n requestPath: c.req.path,\n title,\n });\n\n if (mode === \"content\") {\n if (pageNode == null) throw new Error(\"content render requires pageNode\");\n const node = wrapSlot(pageNode);\n await ensureJsxRenderer(c);\n const rendered = await c.render(node as never);\n let html = await rendered.text();\n html = html.replace(/^<!DOCTYPE html>/i, \"\");\n html = `${html}${payloadScript(payload)}`;\n return { html, payload };\n }\n\n let node: Child = mode === \"shell\" ? emptySlot() : (pageNode as Child);\n if (mode !== \"shell\" && needsPageSlot(page, config, mode)) {\n node = wrapSlot(node);\n }\n\n const layouts = await Promise.all(page.loadLayouts.map((load) => load()));\n for (const layout of [...layouts].reverse()) {\n const Layout = layout.default;\n node = jsx(Layout, { data, params, children: node });\n }\n if (layouts.length === 0) {\n node = jsx(DefaultLayout, { children: node });\n }\n\n await ensureJsxRenderer(c);\n const rendered = await c.render(node as never);\n let html = await rendered.text();\n\n html = injectDocument(html, payload, isDev, clientScriptSrc);\n if (!html.startsWith(\"<!\")) html = `<!DOCTYPE html>${html}`;\n return { html, payload };\n}\n","import { Hono } from \"hono\";\nimport type { Context, Env, Schema } from \"hono\";\nimport type { BlankSchema } from \"hono/types\";\nimport { jsxDEV as jsx } from \"hono/jsx/jsx-dev-runtime\";\nimport { manifest as virtualManifest } from \"virtual:vino/manifest\";\nimport { isDev as assetsIsDev, clientScriptSrc } from \"virtual:vino/assets\";\nimport { NAV_HEADER, SHELL_HEADER } from \"./constants.ts\";\nimport { loadMergedConfig, loadMergedData } from \"./config.ts\";\nimport { resolvePageRender } from \"./definePage.ts\";\nimport { isHonoApp, renderPageHtml } from \"./render.ts\";\nimport type { CreateVinoOptions, ManifestPage, PageModule, RenderMode } from \"./types.ts\";\n\ntype AppContext = Context;\n\nfunction requestParams(c: AppContext): Record<string, string> {\n try {\n return c.req.param();\n } catch {\n return {};\n }\n}\n\nfunction pageFromModule(pageMod: PageModule, data: unknown, params: Record<string, string>) {\n const Page = resolvePageRender(pageMod.default);\n if (Page) return jsx(Page, { data, params });\n return pageMod.default as never;\n}\n\nfunction resolveRenderMode(c: AppContext): RenderMode {\n if (c.req.header(SHELL_HEADER)) return \"shell\";\n if (c.req.header(NAV_HEADER)) return \"content\";\n return \"full\";\n}\n\nasync function handlePage(c: AppContext, page: ManifestPage): Promise<Response> {\n const pageMod = await page.loadPage();\n if (isHonoApp(pageMod.default)) {\n return pageMod.default.fetch(c.req.raw, c.env, c.executionCtx);\n }\n\n const method = c.req.method;\n const named = pageMod[method];\n const hasPage = Boolean(resolvePageRender(pageMod.default));\n const mode = resolveRenderMode(c);\n\n if (typeof named === \"function\" && (method !== \"GET\" || !hasPage)) {\n const result: unknown = await (named as (ctx: AppContext) => unknown)(c);\n if (result instanceof Response) return result;\n if (method === \"GET\" || method === \"HEAD\") {\n const config = loadMergedConfig(page, pageMod);\n const params = requestParams(c);\n const data = mode === \"shell\" ? undefined : await loadMergedData(page, c, pageMod);\n const { html } = await renderPageHtml({\n c,\n page,\n pageMod,\n pageNode: mode === \"shell\" ? null : (result as never),\n data,\n params,\n config,\n isDev: assetsIsDev,\n clientScriptSrc,\n mode,\n });\n return c.html(html);\n }\n return c.json(result as never);\n }\n\n if (method !== \"GET\" && method !== \"HEAD\") {\n return c.text(\"Method Not Allowed\", 405);\n }\n\n const config = loadMergedConfig(page, pageMod);\n const params = requestParams(c);\n const data = mode === \"shell\" ? undefined : await loadMergedData(page, c, pageMod);\n const pageNode = mode === \"shell\" ? null : pageFromModule(pageMod, data, params);\n const { html } = await renderPageHtml({\n c,\n page,\n pageMod,\n pageNode: pageNode,\n data,\n params,\n config,\n isDev: assetsIsDev,\n clientScriptSrc,\n mode,\n });\n return c.html(html);\n}\n\n/**\n * Mount filesystem pages from the Vite-generated manifest onto a user-owned Hono app.\n * Extra API routes should be registered on `app` before calling this.\n */\nexport function mountVino<E extends Env, S extends Schema, BasePath extends string>(app: Hono<E, S, BasePath>, options: CreateVinoOptions = {}): Hono<E, S, BasePath> {\n const manifest = options.manifest ?? virtualManifest;\n for (const page of manifest.pages) {\n app.get(page.pattern, (c) => handlePage(c as AppContext, page));\n }\n\n return app;\n}\n\n/**\n * Create a new Vino app. Returns a Hono app with the Vino pages mounted.\n * @param options - The options for the Vino app.\n * @returns A Hono app with the Vino pages mounted.\n */\nexport function createVino<E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = \"/\">(options: CreateVinoOptions = {}): Hono<E, S, BasePath> {\n const app = new Hono<E, S, BasePath>();\n return mountVino(app, options);\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAS,cAAc,OAA6B;CAClD,OAAOA,OAAI,QAAQ,EACjB,UAAU,CACRA,OAAI,QAAQ,EACV,UAAU,CACRA,OAAI,QAAQ,EAAE,SAAS,QAAQ,CAAC,GAChCA,OAAI,QAAQ;EAAE,MAAM;EAAY,SAAS;CAAsC,CAAC,CAClF,EACF,CAAC,GACDA,OAAI,QAAQ,EAAE,UAAU,MAAM,SAAS,CAAC,CAC1C,EACF,CAAC;AACH;AAEA,SAAgB,UA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;CAEA,IAAI,WAAW,SAAS,WAAW,QACjC,OAAO,EAAE,KAAK,sBAAsB,GAAG;CAGzC,MAAM,SAAS,iBAAiB,MAAM,OAAO;CAC7C,MAAM,SAAS,cAAc,CAAC;CAC9B,MAAM,OAAO,SAAS,UAAU,KAAA,IAAY,MAAM,eAAe,MAAM,GAAG,OAAO;CAEjF,MAAM,EAAE,SAAS,MAAM,eAAe;EACpC;EACA;EACA;EACU,UALK,SAAS,UAAU,OAAO,eAAe,SAAS,MAAM,MAAM;EAM7E;EACA;EACA;EACOA;EACP;EACA;CACF,CAAC;CACD,OAAO,EAAE,KAAK,IAAI;AACpB;;;;;AAMA,SAAgB,UAAoE,KAA2B,UAA6B,CAAC,GAAyB;CACpK,MAAMC,aAAW,QAAQ,YAAYC;CACrC,KAAK,MAAM,QAAQD,WAAS,OAC1B,IAAI,IAAI,KAAK,UAAU,MAAM,WAAW,GAAiB,IAAI,CAAC;CAGhE,OAAO;AACT;;;;;;AAOA,SAAgB,WAA+F,UAA6B,CAAC,GAAyB;CAEpK,OAAO,UAAU,IADD,KACG,GAAG,OAAO;AAC/B"}
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { d as VinoViteOptions } from "./types-CQITdkpF.mjs";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
//#region src/vite/plugin.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Vite plugin: filesystem routes, hydratable components, client entry, and SSG.
|
|
6
|
+
*/
|
|
7
|
+
declare function vino(options?: VinoViteOptions): Plugin[];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { type VinoViteOptions, vino };
|
|
10
|
+
//# sourceMappingURL=vite.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.d.mts","names":[],"sources":["../src/vite/plugin.ts"],"mappings":";;;;;;iBAwNgB,KAAK,UAAS,kBAAuB"}
|