vinojs 0.1.2 → 0.2.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 +23 -18
- package/dist/client.d.mts +74 -8
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +194 -53
- package/dist/client.mjs.map +1 -1
- package/dist/component-wrap.mjs +1 -1
- package/dist/config-CXHX9qZs.mjs +17 -0
- package/dist/config-CXHX9qZs.mjs.map +1 -0
- package/dist/{constants-BVT2bJEd.mjs → constants-DyXAsId-.mjs} +2 -3
- package/dist/constants-DyXAsId-.mjs.map +1 -0
- package/dist/definePage-DC6gJKwW.mjs +468 -0
- package/dist/definePage-DC6gJKwW.mjs.map +1 -0
- package/dist/{defineServerFn-H-bz7xBX.mjs → defineServerFn-DH6B99bH.mjs} +2 -17
- package/dist/defineServerFn-DH6B99bH.mjs.map +1 -0
- package/dist/factory-0LjmIY5F.mjs +123 -0
- package/dist/factory-0LjmIY5F.mjs.map +1 -0
- package/dist/factory.d.mts +38 -2
- package/dist/factory.d.mts.map +1 -0
- package/dist/factory.mjs +4 -153
- package/dist/hydration.d.mts +3 -0
- package/dist/hydration.mjs +2 -0
- package/dist/jsx-dev-runtime.client.d.mts +2 -0
- package/dist/jsx-dev-runtime.client.mjs +2 -0
- package/dist/jsx-dev-runtime.d.mts +2 -0
- package/dist/jsx-dev-runtime.mjs +2 -0
- package/dist/jsx-runtime-5OIvn_Qa.mjs +335 -0
- package/dist/jsx-runtime-5OIvn_Qa.mjs.map +1 -0
- package/dist/jsx-runtime-BLN--agM.d.mts +20 -0
- package/dist/jsx-runtime-BLN--agM.d.mts.map +1 -0
- package/dist/jsx-runtime.client.d.mts +2 -0
- package/dist/jsx-runtime.client.mjs +2 -0
- package/dist/jsx-runtime.d.mts +2 -0
- package/dist/jsx-runtime.mjs +2 -0
- package/dist/mount.d.mts +17 -0
- package/dist/mount.d.mts.map +1 -0
- package/dist/mount.mjs +107 -0
- package/dist/mount.mjs.map +1 -0
- package/dist/render-Cif1RZMC.d.mts +169 -0
- package/dist/render-Cif1RZMC.d.mts.map +1 -0
- package/dist/{types-CQITdkpF.d.mts → types-jfsZLl9U.d.mts} +10 -8
- package/dist/types-jfsZLl9U.d.mts.map +1 -0
- package/dist/vino.d.mts +1 -37
- package/dist/vino.d.mts.map +1 -1
- package/dist/vino.mjs +2 -201
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.mts.map +1 -1
- package/dist/vite.mjs +175 -40
- package/dist/vite.mjs.map +1 -1
- package/package.json +29 -5
- package/dist/compile-glNMkyyx.mjs +0 -111
- package/dist/compile-glNMkyyx.mjs.map +0 -1
- package/dist/constants-BVT2bJEd.mjs.map +0 -1
- package/dist/definePage--9Pz7rHs.mjs +0 -73
- package/dist/definePage--9Pz7rHs.mjs.map +0 -1
- package/dist/defineServerFn-H-bz7xBX.mjs.map +0 -1
- package/dist/factory-CVT0-OZw.d.mts +0 -187
- package/dist/factory-CVT0-OZw.d.mts.map +0 -1
- package/dist/factory.mjs.map +0 -1
- package/dist/types-CQITdkpF.d.mts.map +0 -1
- package/dist/vino.mjs.map +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { a as PageConfig, n as DataLoader, o as PageProps } from "./types-jfsZLl9U.mjs";
|
|
2
|
+
import { Context, Env, Hono, MiddlewareHandler, Next } from "hono";
|
|
3
|
+
import { jsxRenderer } from "hono/jsx-renderer";
|
|
4
|
+
import { Child, FC } from "hono/jsx";
|
|
5
|
+
//#region src/factory/defineServerFn.d.ts
|
|
6
|
+
declare const SERVER_FN_KIND: "vino:server-fn";
|
|
7
|
+
type ServerFnHandler<T = unknown, E extends Env = Env> = (c: Context<E, string>) => T | Promise<T>;
|
|
8
|
+
/**
|
|
9
|
+
* A server-only function. Callable as a `definePage({ data })` loader
|
|
10
|
+
*/
|
|
11
|
+
type ServerFn<T = unknown, E extends Env = Env> = ServerFnHandler<T, E> & {
|
|
12
|
+
readonly kind: typeof SERVER_FN_KIND;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* `defineServerFn` call signature, with `Env` fixed so `fn(c)` is typed without
|
|
16
|
+
* blocking inference of the return type.
|
|
17
|
+
*/
|
|
18
|
+
type DefineServerFnFn<E extends Env = Env> = <T>(fn: ServerFnHandler<T, E>) => ServerFn<T, E>;
|
|
19
|
+
declare function isServerFn(value: unknown): value is ServerFn;
|
|
20
|
+
declare function readServerFn(value: unknown): ServerFn | undefined;
|
|
21
|
+
/** True when source *calls* `defineServerFn(...)`. */
|
|
22
|
+
declare function usesDefineServerFn(code: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Mark a function as server-only.
|
|
25
|
+
*/
|
|
26
|
+
declare function defineServerFn<T, E extends Env = Env>(fn: ServerFnHandler<T, E>): ServerFn<T, E>;
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/factory/definePage.d.ts
|
|
29
|
+
declare const PAGE_KIND: "vino:page";
|
|
30
|
+
declare const SERVER_PAGE_KIND: "vino:server-page";
|
|
31
|
+
type PageRender<Data = unknown> = (props: PageProps<Data>) => Child;
|
|
32
|
+
type PageDataFn<E extends Env = Env> = DataLoader<E> | ServerFn<unknown, E>;
|
|
33
|
+
interface DefinePageOptions<Data = unknown, E extends Env = Env> {
|
|
34
|
+
/** JSX page component. Alias: `page`. */
|
|
35
|
+
render?: PageRender<Data>;
|
|
36
|
+
page?: PageRender<Data>;
|
|
37
|
+
/** Loader or `defineServerFn(...)` */
|
|
38
|
+
data?: DataLoader<E> | ServerFn<Data, E>;
|
|
39
|
+
config?: PageConfig;
|
|
40
|
+
/** Extra Hono middleware, composed before the page handler. */
|
|
41
|
+
use?: MiddlewareHandler<E>[];
|
|
42
|
+
}
|
|
43
|
+
/** Options object that infers `data` return type into `render` / `page`. */
|
|
44
|
+
type InferDefinePageOptions<D extends (...args: never[]) => unknown, E extends Env = Env, Data = Awaited<ReturnType<D>>> = {
|
|
45
|
+
data?: D;
|
|
46
|
+
config?: PageConfig;
|
|
47
|
+
use?: MiddlewareHandler<E>[];
|
|
48
|
+
} & ({
|
|
49
|
+
render: PageRender<Data>;
|
|
50
|
+
page?: PageRender<Data>;
|
|
51
|
+
} | {
|
|
52
|
+
page: PageRender<Data>;
|
|
53
|
+
render?: PageRender<Data>;
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* `definePage` / `defineServerPage` call signature, with `Env` fixed so `data(c)`
|
|
57
|
+
* is typed without blocking inference of the loader return type.
|
|
58
|
+
*/
|
|
59
|
+
interface DefinePageFn<E extends Env = Env> {
|
|
60
|
+
<Data = unknown>(page: PageRender<Data>): PageDefinition<Data, E>;
|
|
61
|
+
<D extends PageDataFn<E>>(options: InferDefinePageOptions<D, E>): PageDefinition<Awaited<ReturnType<D>>, E>;
|
|
62
|
+
<Data = unknown>(options: DefinePageOptions<Data, E>): PageDefinition<Data, E>;
|
|
63
|
+
<Data = unknown>(middleware: MiddlewareHandler<E>, page: PageRender<Data> | DefinePageOptions<Data, E>): PageDefinition<Data, E>;
|
|
64
|
+
}
|
|
65
|
+
interface PageDefinitionFields<Data = unknown, E extends Env = Env> {
|
|
66
|
+
readonly kind: typeof PAGE_KIND | typeof SERVER_PAGE_KIND;
|
|
67
|
+
readonly client: boolean;
|
|
68
|
+
readonly render: PageRender<Data>;
|
|
69
|
+
readonly data?: DataLoader<E> | ServerFn<Data, E>;
|
|
70
|
+
readonly config?: PageConfig;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Hono handler list plus page metadata (`kind`, `render`, `data`, `config`).
|
|
74
|
+
*/
|
|
75
|
+
type PageDefinition<Data = unknown, E extends Env = Env> = [MiddlewareHandler<E>, ...MiddlewareHandler<E>[]] & PageDefinitionFields<Data, E>;
|
|
76
|
+
/** Bind the filesystem-route renderer used by the terminal page handler. */
|
|
77
|
+
declare function bindPageRun(c: Context, run: () => Promise<Response>): void;
|
|
78
|
+
/**
|
|
79
|
+
* Strip page metadata so the list spreads onto `app.get(path, ...handlers)`.
|
|
80
|
+
*/
|
|
81
|
+
declare function asHandlers<Data, E extends Env>(page: PageDefinition<Data, E>): [MiddlewareHandler<E>, ...MiddlewareHandler<E>[]];
|
|
82
|
+
type DispatchHandler = (c: Context, next: Next) => unknown;
|
|
83
|
+
/**
|
|
84
|
+
* Run a `createHandlers`-style list on the current context.
|
|
85
|
+
*/
|
|
86
|
+
declare function dispatchHandlers(handlers: readonly DispatchHandler[], c: Context, next?: Next): Promise<Response>;
|
|
87
|
+
declare function isPageDefinition(value: unknown): value is PageDefinition;
|
|
88
|
+
declare function isClientPageDefinition(value: unknown): value is PageDefinition;
|
|
89
|
+
declare function isServerPageDefinition(value: unknown): value is PageDefinition;
|
|
90
|
+
declare function readPageDefinition(value: unknown): PageDefinition | undefined;
|
|
91
|
+
declare function resolvePageRender(value: unknown): PageRender | undefined;
|
|
92
|
+
/** True when source calls `definePage(...)` (hydratable pages). */
|
|
93
|
+
declare function usesDefinePage(code: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Declare a page that SSRs with `hono/jsx`, then hydrates `#vino-page`
|
|
96
|
+
* with the vino client signal runtime (`vinojs/client`).
|
|
97
|
+
*
|
|
98
|
+
* Returns a Hono handler list (same shape as `createHandlers`) with `render` /
|
|
99
|
+
* `data` / `config` attached.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* export default definePage(() => {
|
|
103
|
+
* const [n, setN] = createSignal(0)
|
|
104
|
+
* return <button onClick={() => setN(n() + 1)}>{n}</button>
|
|
105
|
+
* })
|
|
106
|
+
*/
|
|
107
|
+
declare const definePage: DefinePageFn;
|
|
108
|
+
/**
|
|
109
|
+
* Declare a page that SSRs only. The output is never hydrated.
|
|
110
|
+
*/
|
|
111
|
+
declare const defineServerPage: DefinePageFn;
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/hydration/hydrate.d.ts
|
|
114
|
+
/** Context flag: skip hydration middleware (`defineServerPage`). */
|
|
115
|
+
declare const SKIP_HYDRATION = "vino.skipHydration";
|
|
116
|
+
/** Mark this request so `hydration()` leaves the HTML alone. */
|
|
117
|
+
declare function skipHydration(c: Context): void;
|
|
118
|
+
interface PageHydration {
|
|
119
|
+
/** Passed to the client page as `{ data, params }`. */
|
|
120
|
+
data?: unknown;
|
|
121
|
+
/** Payload `clientPage` key. Defaults to the request path. Set `null` to skip page mount. */
|
|
122
|
+
clientPage?: string | null;
|
|
123
|
+
}
|
|
124
|
+
/** Attach data / client-page id for this request's hydration payload. */
|
|
125
|
+
declare function setPageHydration(c: Context, payload: PageHydration): void;
|
|
126
|
+
declare function readPageHydration(c: Context): PageHydration | undefined;
|
|
127
|
+
interface HydrationOptions {
|
|
128
|
+
/** Module URL for the client bundle. Set to `false` to skip the script tag. */
|
|
129
|
+
clientScript?: string | false;
|
|
130
|
+
isDev?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Enable content-only client navigations (`X-Vino-Nav`).
|
|
133
|
+
* When true, `createClient` intercepts same-origin links and swaps `#vino-page`.
|
|
134
|
+
*/
|
|
135
|
+
clientRouting?: boolean;
|
|
136
|
+
}
|
|
137
|
+
type JsxRendererComponent = Parameters<typeof jsxRenderer>[0];
|
|
138
|
+
/** Options for `vinoRenderer`: hydration + Hono `jsxRenderer`. */
|
|
139
|
+
interface VinoRendererOptions extends HydrationOptions {
|
|
140
|
+
docType?: boolean | string;
|
|
141
|
+
stream?: boolean | Record<string, string>;
|
|
142
|
+
component?: JsxRendererComponent;
|
|
143
|
+
}
|
|
144
|
+
/** App-wide defaults for standalone `definePage` hydration (no Vite). */
|
|
145
|
+
declare function setHydrationDefaults(options: HydrationOptions): void;
|
|
146
|
+
declare function readBoundHydration(value: unknown): HydrationOptions | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* After the handler, wrap `#vino-page` and inject payload + client script
|
|
149
|
+
* on `text/html` responses. Skips JSON, `defineServerPage`, and docs that
|
|
150
|
+
* already contain the payload script.
|
|
151
|
+
*/
|
|
152
|
+
declare function hydration(options?: HydrationOptions): MiddlewareHandler;
|
|
153
|
+
/**
|
|
154
|
+
* Combined `jsxRenderer` + `hydration`: enables `c.render` and post-processes
|
|
155
|
+
* HTML with `#vino-page`, payload, and optional client script.
|
|
156
|
+
*
|
|
157
|
+
* `hydrationRenderer(Layout, { clientScript })` or
|
|
158
|
+
* `hydrationRenderer({ component: Layout, clientScript })`.
|
|
159
|
+
*/
|
|
160
|
+
declare function hydrationRenderer(component: JsxRendererComponent, options?: HydrationOptions & Pick<VinoRendererOptions, "docType" | "stream">): MiddlewareHandler;
|
|
161
|
+
declare function hydrationRenderer(options: VinoRendererOptions): MiddlewareHandler;
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/hydration/render.d.ts
|
|
164
|
+
declare const VinoRoot: FC<{
|
|
165
|
+
children?: Child;
|
|
166
|
+
}>;
|
|
167
|
+
//#endregion
|
|
168
|
+
export { DefineServerFnFn as A, dispatchHandlers as C, readPageDefinition as D, isServerPageDefinition as E, isServerFn as F, readServerFn as I, usesDefineServerFn as L, ServerFn as M, ServerFnHandler as N, resolvePageRender as O, defineServerFn as P, defineServerPage as S, isPageDefinition as T, PageRender as _, VinoRendererOptions as a, bindPageRun as b, readBoundHydration as c, setPageHydration as d, skipHydration as f, PageDefinition as g, PAGE_KIND as h, SKIP_HYDRATION as i, SERVER_FN_KIND as j, usesDefinePage as k, readPageHydration as l, DefinePageOptions as m, HydrationOptions as n, hydration as o, DefinePageFn as p, PageHydration as r, hydrationRenderer as s, VinoRoot as t, setHydrationDefaults as u, SERVER_PAGE_KIND as v, isClientPageDefinition as w, definePage as x, asHandlers as y };
|
|
169
|
+
//# sourceMappingURL=render-Cif1RZMC.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-Cif1RZMC.d.mts","names":[],"sources":["../src/factory/defineServerFn.ts","../src/factory/definePage.ts","../src/hydration/hydrate.ts","../src/hydration/render.ts"],"mappings":";;;;;cAEa;KAED,gBAAgB,aAAa,UAAU,MAAM,QACvD,GAAG,QAAQ,eACR,IAAI,QAAQ;;;;KAKL,SAAS,aAAa,UAAU,MAAM,OAAO,gBAAgB,GAAG;WACjE,aAAa;;;;;;KAOZ,iBAAiB,UAAU,MAAM,QAAQ,GAAG,IAAI,gBAAgB,GAAG,OAAO,SAAS,GAAG;iBAElF,WAAW,iBAAiB,SAAS;iBAIrC,aAAa,iBAAiB;;iBAS9B,mBAAmB;;;;iBAQnB,eAAe,GAAG,UAAU,MAAM,KAAK,IAAI,gBAAgB,GAAG,KAAK,SAAS,GAAG;;;cCpClF;cACA;KAED,WAAW,mBAAmB,OAAO,UAAU,UAAU;KAEzD,WAAW,UAAU,MAAM,OAAO,WAAW,KAAK,kBAAkB;UAE/D,kBAAkB,gBAAgB,UAAU,MAAM;;EAEjE,SAAS,WAAW;EACpB,OAAO,WAAW;;EAElB,OAAO,WAAW,KAAK,SAAS,MAAM;EACtC,SAAS;;EAET,MAAM,kBAAkB;;;KAId,uBACV,cAAc,2BACd,UAAU,MAAM,KAChB,OAAO,QAAQ,WAAW;EAE1B,OAAO;EACP,SAAS;EACT,MAAM,kBAAkB;;EAEpB,QAAQ,WAAW;EAAO,OAAO,WAAW;;EAC5C,MAAM,WAAW;EAAO,SAAS,WAAW;;;;;;UAOjC,aAAa,UAAU,MAAM;GAC3C,gBAAgB,MAAM,WAAW,QAAQ,eAAe,MAAM;GAC9D,UAAU,WAAW,IAAI,SAAS,uBAAuB,GAAG,KAAK,eAAe,QAAQ,WAAW,KAAK;GACxG,gBAAgB,SAAS,kBAAkB,MAAM,KAAK,eAAe,MAAM;GAC3E,gBACC,YAAY,kBAAkB,IAC9B,MAAM,WAAW,QAAQ,kBAAkB,MAAM,KAChD,eAAe,MAAM;;UAGT,qBAAqB,gBAAgB,UAAU,MAAM;WAC3D,aAAa,mBAAmB;WAChC;WACA,QAAQ,WAAW;WACnB,OAAO,WAAW,KAAK,SAAS,MAAM;WACtC,SAAS;;;;;KAMR,eAAe,gBAAgB,UAAU,MAAM,QACzD,kBAAkB,OACf,kBAAkB,QAErB,qBAAqB,MAAM;;iBAKb,YAAY,GAAG,SAAS,WAAW,QAAQ;;;;iBAY3C,WAAW,MAAM,UAAU,KACzC,MAAM,eAAe,MAAM,MACzB,kBAAkB,OAAO,kBAAkB;KAmC1C,mBAAmB,GAAG,SAAS,MAAM;;;;iBAKpB,iBACpB,mBAAmB,mBACnB,GAAG,SACH,OAAO,OACN,QAAQ;iBAiBK,iBAAiB,iBAAiB,SAAS;iBAS3C,uBAAuB,iBAAiB,SAAS;iBAIjD,uBAAuB,iBAAiB,SAAS;iBAIjD,mBAAmB,iBAAiB;iBAIpC,kBAAkB,iBAAiB;;iBAOnC,eAAe;;;;;;;;;;;;;;cAkElB,YAAsF;;;;cAKtF,kBACoD;;;;cCnOpD;;iBAKG,cAAc,GAAG;UAIhB;;EAEf;;EAEA;;;iBAMc,iBAAiB,GAAG,SAAS,SAAS;iBAItC,kBAAkB,GAAG,UAAU;UAI9B;;EAEf;EACA;;;;;EAKA;;KAGG,uBAAuB,kBAAkB;;UAG7B,4BAA4B;EAC3C;EACA,mBAAmB;EACnB,YAAY;;;iBAYE,qBAAqB,SAAS;iBAW9B,mBAAmB,iBAAiB;;;;;;iBAoCpC,UAAU,UAAU,mBAAmB;;;;;;;;iBAmDvC,kBACd,WAAW,sBACX,UAAU,mBAAmB,KAAK,6CACjC;iBACa,kBAAkB,SAAS,sBAAsB;;;cCrHpD,UAAuB;EAAK,WAAW"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context, Env } from "hono";
|
|
2
2
|
import { Child } from "hono/jsx";
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/hydration/types.d.ts
|
|
4
4
|
type VinoHtml = Child;
|
|
5
5
|
interface PageProps<Data = unknown> {
|
|
6
6
|
data: Data;
|
|
@@ -14,9 +14,11 @@ interface LayoutProps<Data = unknown> {
|
|
|
14
14
|
type DataLoader<E extends Env = Env> = (c: Context<E, string>) => unknown;
|
|
15
15
|
type SsgParams = Record<string, string>;
|
|
16
16
|
type SsgParamsFn = () => SsgParams[] | Promise<SsgParams[]>;
|
|
17
|
-
type RenderMode = "full" | "
|
|
17
|
+
type RenderMode = "full" | "content";
|
|
18
18
|
interface PageConfig {
|
|
19
|
-
|
|
19
|
+
/** Include this page in SSG when the Vite plugin has `prerender: true`. */
|
|
20
|
+
prerender?: boolean;
|
|
21
|
+
/** Intercept same-origin links and fetch `#vino-page` content only (`X-Vino-Nav`). */
|
|
20
22
|
clientRouting?: boolean;
|
|
21
23
|
ssgParams?: SsgParamsFn;
|
|
22
24
|
}
|
|
@@ -56,8 +58,6 @@ interface VinoPayload {
|
|
|
56
58
|
data: unknown;
|
|
57
59
|
clientRouting: boolean;
|
|
58
60
|
clientPage: string | null;
|
|
59
|
-
/** True when the document is a layout shell; client should fetch page content. */
|
|
60
|
-
partial?: boolean;
|
|
61
61
|
title?: string;
|
|
62
62
|
}
|
|
63
63
|
interface CreateVinoOptions {
|
|
@@ -68,10 +68,12 @@ interface VinoViteOptions {
|
|
|
68
68
|
layoutsDir?: string;
|
|
69
69
|
componentsDir?: string;
|
|
70
70
|
entry?: string;
|
|
71
|
-
|
|
71
|
+
/** Write full HTML for static routes (and `ssgParams`) at build time. */
|
|
72
|
+
prerender?: boolean;
|
|
73
|
+
/** Default for page `config.clientRouting` (content-only navigations). */
|
|
72
74
|
clientRouting?: boolean;
|
|
73
75
|
client?: string;
|
|
74
76
|
}
|
|
75
77
|
//#endregion
|
|
76
|
-
export { PageConfig as a,
|
|
77
|
-
//# sourceMappingURL=types-
|
|
78
|
+
export { PageConfig as a, VinoManifest as c, ManifestPage as i, VinoPayload as l, DataLoader as n, PageProps as o, LayoutProps as r, RenderMode as s, CreateVinoOptions as t, VinoViteOptions as u };
|
|
79
|
+
//# sourceMappingURL=types-jfsZLl9U.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-jfsZLl9U.d.mts","names":[],"sources":["../src/hydration/types.ts"],"mappings":";;;KAGY,WAAW;UAEN,UAAU;EACzB,MAAM;EACN,QAAQ;;UAGO,YAAY;EAC3B,WAAW;EACX,MAAM;EACN,QAAQ;;KAGE,WAAW,UAAU,MAAM,QAAQ,GAAG,QAAQ;KAE9C,YAAY;KACZ,oBAAoB,cAAc,QAAQ;KAE1C;UAEK;;EAEf;;EAEA;EACA,YAAY;;UAGG;EACf;EACA,OAAO,GAAG;EACV,QAAQ,GAAG;EACX,OAAO,GAAG;EACV,SAAS,GAAG;EACZ,UAAU,GAAG;GACZ;;UAGc;EACf,UAAU,OAAO,gBAAgB;;KAGvB,eAAe,WAAW,QAAQ;UAE7B;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA,SAAS;EACT,UAAU,eAAe;EACzB,iBAAiB,eAAe;EAChC,aAAa,eAAe;;UAGb;EACf,OAAO;EACP,WAAW;;UAGI;EACf;EACA,QAAQ;EACR;EACA;EACA;EACA;;UAGe;EACf,WAAW;;UAGI;EACf;EACA;EACA;EACA;;EAEA;;EAEA;EACA"}
|
package/dist/vino.d.mts
CHANGED
|
@@ -1,45 +1,9 @@
|
|
|
1
|
-
import { a as PageConfig, d as VinoViteOptions, i as ManifestPage, l as VinoManifest, o as PageProps, r as LayoutProps, s as RenderMode, t as CreateVinoOptions, u as VinoPayload } from "./types-CQITdkpF.mjs";
|
|
2
1
|
import { wrapComponent, wrapModule } from "./component-wrap.mjs";
|
|
3
|
-
import { C as defineServerFn, S as ServerFnHandler, T as readServerFn, _ as isPageDefinition, a as createFactory, b as DefineServerFnFn, c as DefinePageFn, d as PageDataFn, f as PageDefinition, g as isClientPageDefinition, h as defineServerPage, l as DefinePageOptions, m as definePage, n as FactoryOptions, p as PageRender, r as InitApp, t as Factory, u as InferDefinePageOptions, v as isServerPageDefinition, w as isServerFn, x as ServerFn, y as resolvePageRender } from "./factory-CVT0-OZw.mjs";
|
|
4
|
-
import { Env, Hono, Schema } from "hono";
|
|
5
|
-
import { BlankSchema } from "hono/types";
|
|
6
|
-
//#region src/vino/createVino.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* Mount filesystem pages from the Vite-generated manifest onto a user-owned Hono app.
|
|
9
|
-
* Extra API routes should be registered on `app` before calling this.
|
|
10
|
-
*/
|
|
11
|
-
declare function mountVino<E extends Env, S extends Schema, BasePath extends string>(app: Hono<E, S, BasePath>, options?: CreateVinoOptions): Hono<E, S, BasePath>;
|
|
12
|
-
/**
|
|
13
|
-
* Create a new Vino app. Returns a Hono app with the Vino pages mounted.
|
|
14
|
-
* @param options - The options for the Vino app.
|
|
15
|
-
* @returns A Hono app with the Vino pages mounted.
|
|
16
|
-
*/
|
|
17
|
-
declare function createVino<E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = "/">(options?: CreateVinoOptions): Hono<E, S, BasePath>;
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/vino/compile.d.ts
|
|
20
|
-
interface CompiledRoute {
|
|
21
|
-
/** Filesystem-derived path using `:param` (no Hono regex). `/`, `/about`, `/blog/:slug`. */
|
|
22
|
-
path: string;
|
|
23
|
-
/** Hono route pattern (`:slug{.+}` for catch-all). */
|
|
24
|
-
pattern: string;
|
|
25
|
-
isCatchAll: boolean;
|
|
26
|
-
isStatic: boolean;
|
|
27
|
-
paramNames: string[];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Compile a pages-dir-relative file path to a Hono route.
|
|
31
|
-
* `(group)` dirs are omitted, `[param]` becomes `:param`, `[...slug]` becomes `:slug{.+}`,
|
|
32
|
-
* trailing `index` is dropped.
|
|
33
|
-
*/
|
|
34
|
-
declare function compileFilePath(relativePath: string): CompiledRoute;
|
|
35
|
-
declare function applyParams(path: string, params: Record<string, string>): string;
|
|
36
|
-
//#endregion
|
|
37
2
|
//#region src/vino/constants.d.ts
|
|
38
3
|
declare const PAGE_SLOT_ID = "vino-page";
|
|
39
4
|
declare const PAYLOAD_SCRIPT_ID = "__VINO__";
|
|
40
5
|
declare const COMPONENT_TAG = "vino-component";
|
|
41
6
|
declare const NAV_HEADER = "X-Vino-Nav";
|
|
42
|
-
declare const SHELL_HEADER = "X-Vino-Shell";
|
|
43
7
|
//#endregion
|
|
44
|
-
export { COMPONENT_TAG,
|
|
8
|
+
export { COMPONENT_TAG, NAV_HEADER, PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID, wrapComponent, wrapModule };
|
|
45
9
|
//# sourceMappingURL=vino.d.mts.map
|
package/dist/vino.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vino.d.mts","names":[],"sources":["../src/vino/
|
|
1
|
+
{"version":3,"file":"vino.d.mts","names":[],"sources":["../src/vino/constants.ts"],"mappings":";;cAAa;cACA;cACA;cAKA"}
|
package/dist/vino.mjs
CHANGED
|
@@ -1,202 +1,3 @@
|
|
|
1
|
-
import { c as PAGE_SLOT_ID, l as PAYLOAD_SCRIPT_ID, o as NAV_HEADER, t as COMPONENT_TAG
|
|
2
|
-
import { a as isServerPageDefinition, i as isPageDefinition, n as defineServerPage, r as isClientPageDefinition, s as resolvePageRender, t as definePage } from "./definePage--9Pz7rHs.mjs";
|
|
3
|
-
import { c as loadMergedData, r as compileFilePath, s as loadMergedConfig, t as applyParams } from "./compile-glNMkyyx.mjs";
|
|
4
|
-
import { a as readServerFn, i as isServerFn, r as defineServerFn } from "./defineServerFn-H-bz7xBX.mjs";
|
|
5
|
-
import { Factory, applyInitApp, createFactory, readPageModuleInitApp } from "./factory.mjs";
|
|
1
|
+
import { c as PAGE_SLOT_ID, l as PAYLOAD_SCRIPT_ID, o as NAV_HEADER, t as COMPONENT_TAG } from "./constants-DyXAsId-.mjs";
|
|
6
2
|
import { wrapComponent, wrapModule } from "./component-wrap.mjs";
|
|
7
|
-
|
|
8
|
-
import { jsxDEV } from "hono/jsx/jsx-dev-runtime";
|
|
9
|
-
import { manifest } from "virtual:vino/manifest";
|
|
10
|
-
import { clientScriptSrc, isDev } from "virtual:vino/assets";
|
|
11
|
-
import { jsxRenderer } from "hono/jsx-renderer";
|
|
12
|
-
//#region src/vino/render.ts
|
|
13
|
-
function DefaultLayout(props) {
|
|
14
|
-
return jsxDEV("html", { children: [jsxDEV("head", { children: [jsxDEV("meta", { charset: "utf-8" }), jsxDEV("meta", {
|
|
15
|
-
name: "viewport",
|
|
16
|
-
content: "width=device-width, initial-scale=1"
|
|
17
|
-
})] }), jsxDEV("body", { children: props.children })] });
|
|
18
|
-
}
|
|
19
|
-
function isHonoApp(value) {
|
|
20
|
-
return value instanceof Hono;
|
|
21
|
-
}
|
|
22
|
-
function payloadScript(payload) {
|
|
23
|
-
const json = JSON.stringify(payload).replaceAll("<", "\\u003c");
|
|
24
|
-
return `<script id="${PAYLOAD_SCRIPT_ID}" type="application/json">${json}<\/script>`;
|
|
25
|
-
}
|
|
26
|
-
function injectDocument(html, payload, isDev, scriptSrc) {
|
|
27
|
-
const vite = isDev ? `<script type="module" src="/@vite/client"><\/script>` : "";
|
|
28
|
-
const client = `<script type="module" src="${scriptSrc}"><\/script>`;
|
|
29
|
-
const inject = `${vite}${payloadScript(payload)}${client}`;
|
|
30
|
-
if (html.includes("</body>")) return html.replace("</body>", `${inject}</body>`);
|
|
31
|
-
if (html.includes("</html>")) return html.replace("</html>", `${inject}</html>`);
|
|
32
|
-
return `<!DOCTYPE html>${html}${inject}`;
|
|
33
|
-
}
|
|
34
|
-
async function ensureJsxRenderer(c) {
|
|
35
|
-
await jsxRenderer(void 0, { docType: true })(c, async () => {});
|
|
36
|
-
}
|
|
37
|
-
function needsPageSlot(page, config, mode) {
|
|
38
|
-
if (mode === "shell" || mode === "content") return true;
|
|
39
|
-
if (page.isClientPage) return true;
|
|
40
|
-
if (config.clientRouting === true) return true;
|
|
41
|
-
if (config.prerender === "partial") return true;
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
function emptySlot() {
|
|
45
|
-
return jsxDEV("div", { id: PAGE_SLOT_ID });
|
|
46
|
-
}
|
|
47
|
-
function wrapSlot(children) {
|
|
48
|
-
return jsxDEV("div", {
|
|
49
|
-
id: PAGE_SLOT_ID,
|
|
50
|
-
children
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function buildPayload(options) {
|
|
54
|
-
const { page, params, data, config, mode, requestPath, title } = options;
|
|
55
|
-
return {
|
|
56
|
-
path: requestPath ?? (page.path === "" ? "/" : page.path),
|
|
57
|
-
params,
|
|
58
|
-
data,
|
|
59
|
-
clientRouting: config.clientRouting === true,
|
|
60
|
-
clientPage: page.isClientPage ? page.path : null,
|
|
61
|
-
partial: mode === "shell",
|
|
62
|
-
title
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
async function renderPageHtml(options) {
|
|
66
|
-
const { c, page, pageNode = null, data, params, config, isDev, clientScriptSrc, mode = "full", title } = options;
|
|
67
|
-
const payload = buildPayload({
|
|
68
|
-
page,
|
|
69
|
-
params,
|
|
70
|
-
data,
|
|
71
|
-
config,
|
|
72
|
-
mode,
|
|
73
|
-
requestPath: c.req.path,
|
|
74
|
-
title
|
|
75
|
-
});
|
|
76
|
-
if (mode === "content") {
|
|
77
|
-
if (pageNode == null) throw new Error("content render requires pageNode");
|
|
78
|
-
const node = wrapSlot(pageNode);
|
|
79
|
-
await ensureJsxRenderer(c);
|
|
80
|
-
let html = await (await c.render(node)).text();
|
|
81
|
-
html = html.replace(/^<!DOCTYPE html>/i, "");
|
|
82
|
-
html = `${html}${payloadScript(payload)}`;
|
|
83
|
-
return {
|
|
84
|
-
html,
|
|
85
|
-
payload
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
let node = mode === "shell" ? emptySlot() : pageNode;
|
|
89
|
-
if (mode !== "shell" && needsPageSlot(page, config, mode)) node = wrapSlot(node);
|
|
90
|
-
const layouts = await Promise.all(page.loadLayouts.map((load) => load()));
|
|
91
|
-
for (const layout of [...layouts].reverse()) {
|
|
92
|
-
const Layout = layout.default;
|
|
93
|
-
node = jsxDEV(Layout, {
|
|
94
|
-
data,
|
|
95
|
-
params,
|
|
96
|
-
children: node
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (layouts.length === 0) node = jsxDEV(DefaultLayout, { children: node });
|
|
100
|
-
await ensureJsxRenderer(c);
|
|
101
|
-
let html = await (await c.render(node)).text();
|
|
102
|
-
html = injectDocument(html, payload, isDev, clientScriptSrc);
|
|
103
|
-
if (!html.startsWith("<!")) html = `<!DOCTYPE html>${html}`;
|
|
104
|
-
return {
|
|
105
|
-
html,
|
|
106
|
-
payload
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/vino/createVino.ts
|
|
111
|
-
function requestParams(c) {
|
|
112
|
-
try {
|
|
113
|
-
return c.req.param();
|
|
114
|
-
} catch {
|
|
115
|
-
return {};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function pageFromModule(pageMod, data, params) {
|
|
119
|
-
const Page = resolvePageRender(pageMod.default);
|
|
120
|
-
if (Page) return jsxDEV(Page, {
|
|
121
|
-
data,
|
|
122
|
-
params
|
|
123
|
-
});
|
|
124
|
-
return pageMod.default;
|
|
125
|
-
}
|
|
126
|
-
function resolveRenderMode(c) {
|
|
127
|
-
if (c.req.header("X-Vino-Shell")) return "shell";
|
|
128
|
-
if (c.req.header("X-Vino-Nav")) return "content";
|
|
129
|
-
return "full";
|
|
130
|
-
}
|
|
131
|
-
async function handlePage(c, page) {
|
|
132
|
-
const pageMod = await page.loadPage();
|
|
133
|
-
return applyInitApp(readPageModuleInitApp(pageMod.default), c, () => handlePageBody(c, page, pageMod));
|
|
134
|
-
}
|
|
135
|
-
async function handlePageBody(c, page, pageMod) {
|
|
136
|
-
if (isHonoApp(pageMod.default)) return pageMod.default.fetch(c.req.raw, c.env, c.executionCtx);
|
|
137
|
-
const method = c.req.method;
|
|
138
|
-
const named = pageMod[method];
|
|
139
|
-
const hasPage = Boolean(resolvePageRender(pageMod.default));
|
|
140
|
-
const mode = resolveRenderMode(c);
|
|
141
|
-
if (typeof named === "function" && (method !== "GET" || !hasPage)) {
|
|
142
|
-
const result = await named(c);
|
|
143
|
-
if (result instanceof Response) return result;
|
|
144
|
-
if (method === "GET" || method === "HEAD") {
|
|
145
|
-
const config = loadMergedConfig(page, pageMod);
|
|
146
|
-
const params = requestParams(c);
|
|
147
|
-
const data = mode === "shell" ? void 0 : await loadMergedData(page, c, pageMod);
|
|
148
|
-
const { html } = await renderPageHtml({
|
|
149
|
-
c,
|
|
150
|
-
page,
|
|
151
|
-
pageMod,
|
|
152
|
-
pageNode: mode === "shell" ? null : result,
|
|
153
|
-
data,
|
|
154
|
-
params,
|
|
155
|
-
config,
|
|
156
|
-
isDev,
|
|
157
|
-
clientScriptSrc,
|
|
158
|
-
mode
|
|
159
|
-
});
|
|
160
|
-
return c.html(html);
|
|
161
|
-
}
|
|
162
|
-
return c.json(result);
|
|
163
|
-
}
|
|
164
|
-
if (method !== "GET" && method !== "HEAD") return c.text("Method Not Allowed", 405);
|
|
165
|
-
const config = loadMergedConfig(page, pageMod);
|
|
166
|
-
const params = requestParams(c);
|
|
167
|
-
const data = mode === "shell" ? void 0 : await loadMergedData(page, c, pageMod);
|
|
168
|
-
const { html } = await renderPageHtml({
|
|
169
|
-
c,
|
|
170
|
-
page,
|
|
171
|
-
pageMod,
|
|
172
|
-
pageNode: mode === "shell" ? null : pageFromModule(pageMod, data, params),
|
|
173
|
-
data,
|
|
174
|
-
params,
|
|
175
|
-
config,
|
|
176
|
-
isDev,
|
|
177
|
-
clientScriptSrc,
|
|
178
|
-
mode
|
|
179
|
-
});
|
|
180
|
-
return c.html(html);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Mount filesystem pages from the Vite-generated manifest onto a user-owned Hono app.
|
|
184
|
-
* Extra API routes should be registered on `app` before calling this.
|
|
185
|
-
*/
|
|
186
|
-
function mountVino(app, options = {}) {
|
|
187
|
-
const manifest$1 = options.manifest ?? manifest;
|
|
188
|
-
for (const page of manifest$1.pages) app.get(page.pattern, (c) => handlePage(c, page));
|
|
189
|
-
return app;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Create a new Vino app. Returns a Hono app with the Vino pages mounted.
|
|
193
|
-
* @param options - The options for the Vino app.
|
|
194
|
-
* @returns A Hono app with the Vino pages mounted.
|
|
195
|
-
*/
|
|
196
|
-
function createVino(options = {}) {
|
|
197
|
-
return mountVino(new Hono(), options);
|
|
198
|
-
}
|
|
199
|
-
//#endregion
|
|
200
|
-
export { COMPONENT_TAG, Factory, NAV_HEADER, PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID, SHELL_HEADER, applyParams, compileFilePath, createFactory, createVino, definePage, defineServerFn, defineServerPage, isClientPageDefinition, isPageDefinition, isServerFn, isServerPageDefinition, mountVino, readServerFn, resolvePageRender, wrapComponent, wrapModule };
|
|
201
|
-
|
|
202
|
-
//# sourceMappingURL=vino.mjs.map
|
|
3
|
+
export { COMPONENT_TAG, NAV_HEADER, PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID, wrapComponent, wrapModule };
|
package/dist/vite.d.mts
CHANGED
package/dist/vite.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.d.mts","names":[],"sources":["../src/vite/plugin.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"vite.d.mts","names":[],"sources":["../src/vite/plugin.ts"],"mappings":";;;;;;iBAwOgB,KAAK,UAAS,kBAAuB"}
|