@takazudo/zfb-runtime 0.1.0-next.2

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +237 -0
  4. package/dist/client-router/cssesc.d.ts +9 -0
  5. package/dist/client-router/cssesc.d.ts.map +1 -0
  6. package/dist/client-router/cssesc.js +95 -0
  7. package/dist/client-router/cssesc.js.map +1 -0
  8. package/dist/client-router/events.d.ts +42 -0
  9. package/dist/client-router/events.d.ts.map +1 -0
  10. package/dist/client-router/events.js +114 -0
  11. package/dist/client-router/events.js.map +1 -0
  12. package/dist/client-router/index.d.ts +9 -0
  13. package/dist/client-router/index.d.ts.map +1 -0
  14. package/dist/client-router/index.js +18 -0
  15. package/dist/client-router/index.js.map +1 -0
  16. package/dist/client-router/prefetch.d.ts +29 -0
  17. package/dist/client-router/prefetch.d.ts.map +1 -0
  18. package/dist/client-router/prefetch.js +288 -0
  19. package/dist/client-router/prefetch.js.map +1 -0
  20. package/dist/client-router/router.d.ts +17 -0
  21. package/dist/client-router/router.d.ts.map +1 -0
  22. package/dist/client-router/router.js +739 -0
  23. package/dist/client-router/router.js.map +1 -0
  24. package/dist/client-router/swap-functions.d.ts +22 -0
  25. package/dist/client-router/swap-functions.d.ts.map +1 -0
  26. package/dist/client-router/swap-functions.js +252 -0
  27. package/dist/client-router/swap-functions.js.map +1 -0
  28. package/dist/client-router/types.d.ts +11 -0
  29. package/dist/client-router/types.d.ts.map +1 -0
  30. package/dist/client-router/types.js +3 -0
  31. package/dist/client-router/types.js.map +1 -0
  32. package/dist/client-router.d.ts +36 -0
  33. package/dist/client-router.d.ts.map +1 -0
  34. package/dist/client-router.js +117 -0
  35. package/dist/client-router.js.map +1 -0
  36. package/dist/framework.d.ts +17 -0
  37. package/dist/framework.d.ts.map +1 -0
  38. package/dist/framework.js +17 -0
  39. package/dist/framework.js.map +1 -0
  40. package/dist/index.d.ts +14 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +29 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/router.d.ts +97 -0
  45. package/dist/router.d.ts.map +1 -0
  46. package/dist/router.js +318 -0
  47. package/dist/router.js.map +1 -0
  48. package/dist/snapshot.d.ts +38 -0
  49. package/dist/snapshot.d.ts.map +1 -0
  50. package/dist/snapshot.js +16 -0
  51. package/dist/snapshot.js.map +1 -0
  52. package/dist/view-transitions.d.ts +34 -0
  53. package/dist/view-transitions.d.ts.map +1 -0
  54. package/dist/view-transitions.js +54 -0
  55. package/dist/view-transitions.js.map +1 -0
  56. package/package.json +78 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0-next.1
4
+
5
+ Initial public prerelease on npm.
6
+
7
+ - JavaScript runtime for zfb static sites: Hono-backed page router, content snapshots, client-side hydration.
8
+ - Subpath exports: `snapshot`, `client-router`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Takeshi Takatsudo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # @takazudo/zfb-runtime
2
+
3
+ > Rust-built static-site engine for Astro and Next.js users — millisecond rebuilds, single binary.
4
+
5
+ The JS-side runtime for [zfb][zfb-site]'s SSG-first build pipeline. It
6
+ exposes `createPageRouter`, a Hono-backed page router whose returned
7
+ fetch handler is shape-compatible with the Cloudflare Workers
8
+ `(request) => Promise<Response>` model. The Rust build host drives this
9
+ router at build time to emit static HTML; the same handler also serves
10
+ SSR requests at the edge.
11
+
12
+ Full documentation: <https://takazudomodular.com/pj/zudo-front-builder/>.
13
+ Source: <https://github.com/Takazudo/zudo-front-builder>.
14
+
15
+ [zfb-site]: https://takazudomodular.com/pj/zudo-front-builder/
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ npm install @takazudo/zfb-runtime @takazudo/zfb
21
+ # or: pnpm add @takazudo/zfb-runtime @takazudo/zfb
22
+ ```
23
+
24
+ `@takazudo/zfb` is a peer dependency — `createPageRouter` shares
25
+ module-level state (`ContentSnapshot`) with `@takazudo/zfb/content`, so
26
+ both packages must resolve to the same instance.
27
+
28
+ ## What this package does
29
+
30
+ zfb's render pipeline goes:
31
+
32
+ ```
33
+ user pages/ + content/ + layouts/ + components/
34
+ → esbuild bundle // single ESM file, Worker entry
35
+ → embedded V8 host // same WinterCG surface as CF Workers
36
+ → @takazudo/zfb-runtime // <-- this package
37
+ → (request) => Promise<Response> // Worker fetch handler
38
+ ```
39
+
40
+ This package supplies the page-router factory the Worker entry calls. It
41
+ is built on [Hono][hono] but does not leak Hono types through the public
42
+ surface — consumers only see the four types in `src/index.ts`.
43
+
44
+ [hono]: https://hono.dev/
45
+
46
+ The runtime is **JSX-runtime-agnostic**. It never imports preact or
47
+ react. The caller passes a `FrameworkAdapter` that pins `renderToString`
48
+ to the chosen JSX runtime; both `preact-render-to-string` and
49
+ `react-dom/server` slot in.
50
+
51
+ ## Public API
52
+
53
+ ```ts
54
+ import { createPageRouter } from "@takazudo/zfb-runtime";
55
+ import type {
56
+ CreatePageRouterOptions,
57
+ PageDefinition,
58
+ PageModule,
59
+ PageHeading,
60
+ PageRouter,
61
+ FrameworkAdapter,
62
+ ContentSnapshot,
63
+ EntrySnapshot,
64
+ } from "@takazudo/zfb-runtime";
65
+ ```
66
+
67
+ ### `createPageRouter(options) → PageRouter`
68
+
69
+ Build a fetch-handler that serves the supplied pages. The returned
70
+ function is shape-compatible with a Worker `default.fetch`.
71
+
72
+ ```ts
73
+ const router = createPageRouter({
74
+ pages, // PageDefinition[]
75
+ contentSnapshot, // ContentSnapshot embedded by the bundler
76
+ framework, // FrameworkAdapter
77
+ });
78
+
79
+ export default { fetch: router };
80
+ ```
81
+
82
+ **Side effects.**
83
+
84
+ 1. Calls `setContentSnapshot(contentSnapshot)` on the `zfb/content`
85
+ module so any user page importing `getCollection(name)` resolves
86
+ from memory rather than the Node `fs` API. Workers have no `fs`,
87
+ so this branch is the production path. Idempotent; subsequent
88
+ calls overwrite (matches the dev-mode live-reload contract).
89
+ 2. Constructs an internal Hono app and registers `app.get(page.route, …)`
90
+ for every entry in `pages`. The handler imports the page module,
91
+ calls `framework.renderToString(module.default({}))`, and returns
92
+ the string in a `Response`.
93
+
94
+ ### `PageDefinition`
95
+
96
+ ```ts
97
+ interface PageDefinition {
98
+ readonly route: string; // Hono path pattern
99
+ readonly module: () => Promise<PageModule>; // thunk for code-split friendliness
100
+ }
101
+ ```
102
+
103
+ ### `PageModule`
104
+
105
+ The shape every page module must export:
106
+
107
+ ```ts
108
+ interface PageModule {
109
+ readonly default: (props: Record<string, unknown>) => unknown;
110
+ readonly prerender?: boolean; // literal `false` excludes from SSG
111
+ readonly content_type?: string; // overrides Content-Type (e.g. "application/xml")
112
+ readonly headings?: readonly PageHeading[]; // MDX-emitted TOC data
113
+ }
114
+
115
+ interface PageHeading {
116
+ readonly depth: number;
117
+ readonly slug: string;
118
+ readonly text: string;
119
+ }
120
+ ```
121
+
122
+ Default `Content-Type` is `text/html; charset=utf-8`.
123
+
124
+ ### `FrameworkAdapter`
125
+
126
+ ```ts
127
+ interface FrameworkAdapter {
128
+ renderToString: (vnode: unknown) => string;
129
+ hydrate?: (...args: unknown[]) => unknown; // reserved for follow-up SSR-with-hydration
130
+ }
131
+ ```
132
+
133
+ `hydrate` is reserved — the page router does not call it today.
134
+
135
+ ### `ContentSnapshot` / `EntrySnapshot`
136
+
137
+ Direct TypeScript mirror of the Rust contract in
138
+ `crates/zfb-content/src/content_bridge.rs`. Field names are snake_case
139
+ (`module_specifier`, `rel_path`) to match the JSON serialization.
140
+
141
+ ```ts
142
+ interface EntrySnapshot {
143
+ readonly slug: string;
144
+ readonly frontmatter: unknown; // null when source had none; getCollection normalises to {}
145
+ readonly body: string; // empty for .tsx entries
146
+ readonly module_specifier: string;
147
+ readonly rel_path: string;
148
+ }
149
+
150
+ interface ContentSnapshot {
151
+ readonly collections: Readonly<Record<string, readonly EntrySnapshot[]>>;
152
+ }
153
+ ```
154
+
155
+ The Rust side guarantees deterministic order (collections sorted by
156
+ name, entries sorted by slug). The TS side does **not** re-sort — it
157
+ preserves the order the bundle delivers, so the determinism story is
158
+ "identical Rust input → identical bundle bytes → identical render
159
+ output" without an extra sort step.
160
+
161
+ ## Bundle shape consumed by the embedded V8 host
162
+
163
+ zfb's embedded V8 host loads a single ESM Worker bundle produced by the
164
+ esbuild step. The bundle's entry point must look like this:
165
+
166
+ ```ts
167
+ // dist/worker.mjs (shape — generated by the bundler, not committed)
168
+ import { createPageRouter } from "@takazudo/zfb-runtime";
169
+ import * as preactRender from "preact-render-to-string";
170
+
171
+ import HomePage from "./pages/index.tsx";
172
+ import BlogPost from "./pages/blog/[slug].tsx";
173
+ // ... user content + layouts + components, bundled flat
174
+
175
+ const router = createPageRouter({
176
+ pages: [
177
+ { route: "/", module: () => Promise.resolve({ default: HomePage }) },
178
+ { route: "/blog/:slug", module: () => Promise.resolve({ default: BlogPost }) },
179
+ // ... one entry per route, expanded from `paths()` static evaluation
180
+ ],
181
+ contentSnapshot: {
182
+ // Embedded JSON literal — the Rust bundler injects the snapshot via
183
+ // an `import.meta.env`-style replacement or a top-level inline.
184
+ collections: { /* ... */ },
185
+ },
186
+ framework: {
187
+ renderToString: (vnode) => preactRender.renderToString(vnode as unknown as preactRender.ComponentChild),
188
+ },
189
+ });
190
+
191
+ export default { fetch: router };
192
+ ```
193
+
194
+ The host then drives the Worker by sending `GET` requests for each
195
+ enumerated route and writing the response body to `dist/{route}/index.html`.
196
+
197
+ ### Contract this package commits to
198
+
199
+ - `createPageRouter` is the single export the build host wires to.
200
+ - The returned function is **always** `(request: Request) => Promise<Response>`,
201
+ even if the underlying Hono path returns synchronously.
202
+ - `Content-Type` defaults to `text/html; charset=utf-8`. Page modules
203
+ with a `content_type` field override it.
204
+ - Errors in page evaluation surface as 500 responses with a diagnostic
205
+ text body; the host's source-map plumbing projects those back to the
206
+ user's TSX line.
207
+ - The `ContentSnapshot` registration is idempotent and observable via
208
+ `getContentSnapshot()` re-exported from `zfb/content`. Dev-mode hosts
209
+ can call `setContentSnapshot(undefined)` to clear between rebuilds if
210
+ needed (today the runtime overwrites on each `createPageRouter` call,
211
+ which is the documented happy path).
212
+
213
+ ## Local development
214
+
215
+ ```sh
216
+ pnpm --filter @takazudo/zfb-runtime test
217
+ pnpm --filter @takazudo/zfb-runtime typecheck
218
+ ```
219
+
220
+ Tests run in `vitest` under Node's `node` environment (no jsdom — the
221
+ runtime targets the Workers `fetch` model, which Node implements
222
+ natively). The framework adapter is stubbed so tests do not pull in
223
+ preact-render-to-string. Determinism is asserted by rendering twice
224
+ from independently-constructed routers and comparing byte-equal.
225
+
226
+ The embedded V8 host is **not** booted from this package's tests — that
227
+ integration belongs to the Rust-side build host. The end-to-end
228
+ acceptance criterion ("Worker bundle returns correct HTML for each
229
+ route") is exercised by the host crate's test suite, not here.
230
+
231
+ ## Why a peer dependency on `zfb`
232
+
233
+ `createPageRouter` calls `setContentSnapshot` from `zfb/content`. The
234
+ two modules share module-level state, so they must resolve to the same
235
+ instance — pinning `zfb` as a peer dep makes that explicit and lets pnpm
236
+ hoist a single shared copy. Workspace-internal usage today resolves via
237
+ `workspace:*`; an external publish would change to a SemVer range.
@@ -0,0 +1,9 @@
1
+ interface Options {
2
+ escapeEverything: boolean;
3
+ isIdentifier: boolean;
4
+ quotes: "single" | "double";
5
+ wrap: boolean;
6
+ }
7
+ export default function cssesc(string: string, options?: Partial<Options>): string;
8
+ export {};
9
+ //# sourceMappingURL=cssesc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cssesc.d.ts","sourceRoot":"","sources":["../../src/client-router/cssesc.ts"],"names":[],"mappings":"AAYA,UAAU,OAAO;IACf,gBAAgB,EAAE,OAAO,CAAC;IAC1B,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,IAAI,EAAE,OAAO,CAAC;CACf;AASD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,OAAO,CAAC,OAAO,CAAM,UA4E5E"}
@@ -0,0 +1,95 @@
1
+ /* eslint-disable regexp/control-character-escape */
2
+ /* eslint-disable no-control-regex */
3
+ /* eslint-disable regexp/no-optional-assertion */
4
+ /* eslint-disable regexp/no-useless-escape */
5
+ /* eslint-disable regexp/no-obscure-range */
6
+ // ESM vendored version of cssesc: https://github.com/mathiasbynens/cssesc/blob/cb894eb42f27c8d3cd793f16afe35b3ab38000a1/cssesc.js
7
+ // See https://github.com/withastro/astro/pull/15669
8
+ const regexAnySingleEscape = /[ -,\.\/:-@\[-\^`\{-~]/;
9
+ const regexSingleEscape = /[ -,\.\/:-@\[\]\^`\{-~]/;
10
+ const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
11
+ const DEFAULT_OPTIONS = {
12
+ escapeEverything: false,
13
+ isIdentifier: false,
14
+ quotes: "single",
15
+ wrap: false,
16
+ };
17
+ export default function cssesc(string, options = {}) {
18
+ options = { ...DEFAULT_OPTIONS, ...options };
19
+ const quote = options.quotes === "double" ? '"' : "'";
20
+ const { isIdentifier } = options;
21
+ const firstChar = string.charAt(0);
22
+ let output = "";
23
+ let counter = 0;
24
+ const length = string.length;
25
+ while (counter < length) {
26
+ const character = string.charAt(counter++);
27
+ let codePoint = character.charCodeAt(0);
28
+ let value;
29
+ // If it's not a printable ASCII character…
30
+ if (codePoint < 0x20 || codePoint > 0x7e) {
31
+ if (codePoint >= 0xd800 && codePoint <= 0xdbff && counter < length) {
32
+ // It's a high surrogate, and there is a next character.
33
+ const extra = string.charCodeAt(counter++);
34
+ if ((extra & 0xfc00) === 0xdc00) {
35
+ // next character is low surrogate
36
+ codePoint = ((codePoint & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
37
+ }
38
+ else {
39
+ // It's an unmatched surrogate; only append this code unit, in case
40
+ // the next code unit is the high surrogate of a surrogate pair.
41
+ counter--;
42
+ }
43
+ }
44
+ value = "\\" + codePoint.toString(16).toUpperCase() + " ";
45
+ }
46
+ else {
47
+ if (options.escapeEverything) {
48
+ if (regexAnySingleEscape.test(character)) {
49
+ value = "\\" + character;
50
+ }
51
+ else {
52
+ value = "\\" + codePoint.toString(16).toUpperCase() + " ";
53
+ }
54
+ }
55
+ else if (/[\t\n\f\r\x0B]/.test(character)) {
56
+ value = "\\" + codePoint.toString(16).toUpperCase() + " ";
57
+ }
58
+ else if (character === "\\" ||
59
+ (!isIdentifier &&
60
+ ((character === '"' && quote === character) ||
61
+ (character === "'" && quote === character))) ||
62
+ (isIdentifier && regexSingleEscape.test(character))) {
63
+ value = "\\" + character;
64
+ }
65
+ else {
66
+ value = character;
67
+ }
68
+ }
69
+ output += value;
70
+ }
71
+ if (isIdentifier) {
72
+ if (/^-[-\d]/.test(output)) {
73
+ output = "\\-" + output.slice(1);
74
+ }
75
+ else if (/\d/.test(firstChar)) {
76
+ output = "\\3" + firstChar + " " + output.slice(1);
77
+ }
78
+ }
79
+ // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
80
+ // since they're redundant. Note that this is only possible if the escape
81
+ // sequence isn't preceded by an odd number of backslashes.
82
+ output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
83
+ if ($1 && $1.length % 2) {
84
+ // It's not safe to remove the space, so don't.
85
+ return $0;
86
+ }
87
+ // Strip the space.
88
+ return ($1 || "") + $2;
89
+ });
90
+ if (!isIdentifier && options.wrap) {
91
+ return quote + output + quote;
92
+ }
93
+ return output;
94
+ }
95
+ //# sourceMappingURL=cssesc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cssesc.js","sourceRoot":"","sources":["../../src/client-router/cssesc.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,qCAAqC;AACrC,iDAAiD;AACjD,6CAA6C;AAC7C,4CAA4C;AAC5C,kIAAkI;AAClI,oDAAoD;AAEpD,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AACtD,MAAM,iBAAiB,GAAG,yBAAyB,CAAC;AACpD,MAAM,oBAAoB,GAAG,mDAAmD,CAAC;AASjF,MAAM,eAAe,GAAY;IAC/B,gBAAgB,EAAE,KAAK;IACvB,YAAY,EAAE,KAAK;IACnB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,KAAK;CACZ,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,MAAc,EAAE,UAA4B,EAAE;IAC3E,OAAO,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACtD,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC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C,oBAAoB,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,EAAE;QAChE,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,+CAA+C;YAC/C,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,mBAAmB;QACnB,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QAClC,OAAO,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;IAChC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { Direction, NavigationTypeString } from "./types.js";
2
+ export declare const TRANSITION_BEFORE_PREPARATION = "zfb:before-preparation";
3
+ export declare const TRANSITION_AFTER_PREPARATION = "zfb:after-preparation";
4
+ export declare const TRANSITION_BEFORE_SWAP = "zfb:before-swap";
5
+ export declare const TRANSITION_AFTER_SWAP = "zfb:after-swap";
6
+ export declare const TRANSITION_PAGE_LOAD = "zfb:page-load";
7
+ export declare const TRANSITION_NAVIGATION_ABORTED = "zfb:navigation-aborted";
8
+ type Events = "zfb:after-preparation" | "zfb:after-swap" | "zfb:page-load" | "zfb:navigation-aborted";
9
+ export declare const triggerEvent: (name: Events) => boolean;
10
+ export declare const onPageLoad: () => boolean;
11
+ declare class BeforeEvent extends Event {
12
+ readonly from: URL;
13
+ to: URL;
14
+ direction: Direction | string;
15
+ readonly navigationType: NavigationTypeString;
16
+ readonly sourceElement: Element | undefined;
17
+ readonly info: any;
18
+ newDocument: Document;
19
+ readonly signal: AbortSignal;
20
+ constructor(type: string, eventInitDict: EventInit | undefined, from: URL, to: URL, direction: Direction | string, navigationType: NavigationTypeString, sourceElement: Element | undefined, info: any, newDocument: Document, signal: AbortSignal);
21
+ }
22
+ export declare const isTransitionBeforePreparationEvent: (value: any) => value is TransitionBeforePreparationEvent;
23
+ export declare class TransitionBeforePreparationEvent extends BeforeEvent {
24
+ formData: FormData | undefined;
25
+ loader: () => Promise<void>;
26
+ constructor(from: URL, to: URL, direction: Direction | string, navigationType: NavigationTypeString, sourceElement: Element | undefined, info: any, newDocument: Document, signal: AbortSignal, formData: FormData | undefined, loader: (event: TransitionBeforePreparationEvent) => Promise<void>);
27
+ }
28
+ export declare const isTransitionBeforeSwapEvent: (value: any) => value is TransitionBeforeSwapEvent;
29
+ export declare class TransitionBeforeSwapEvent extends BeforeEvent {
30
+ readonly direction: Direction | string;
31
+ readonly viewTransition: ViewTransition;
32
+ swap: () => void;
33
+ constructor(afterPreparation: BeforeEvent, viewTransition: ViewTransition);
34
+ }
35
+ export declare function doPreparation(from: URL, to: URL, direction: Direction | string, navigationType: NavigationTypeString, sourceElement: Element | undefined, info: any, signal: AbortSignal, formData: FormData | undefined, defaultLoader: (event: TransitionBeforePreparationEvent) => Promise<void>): Promise<TransitionBeforePreparationEvent>;
36
+ export declare const updateScrollPosition: (positions: {
37
+ scrollX: number;
38
+ scrollY: number;
39
+ }) => void;
40
+ export declare function doSwap(afterPreparation: BeforeEvent, viewTransition: ViewTransition, afterDispatch?: () => Promise<void>): Promise<TransitionBeforeSwapEvent>;
41
+ export {};
42
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/client-router/events.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElE,eAAO,MAAM,6BAA6B,2BAA2B,CAAC;AACtE,eAAO,MAAM,4BAA4B,0BAA0B,CAAC;AACpE,eAAO,MAAM,sBAAsB,oBAAoB,CAAC;AACxD,eAAO,MAAM,qBAAqB,mBAAmB,CAAC;AACtD,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AACpD,eAAO,MAAM,6BAA6B,2BAA2B,CAAC;AAEtE,KAAK,MAAM,GAC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EAAE,WAAW,EACnB,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,MAAM,EAAE,CAAC,KAAK,EAAE,gCAAgC,KAAK,OAAO,CAAC,IAAI,CAAC;CAqBrE;AAKD,eAAO,MAAM,2BAA2B,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,yBAC3B,CAAC;AACxC,qBAAa,yBAA0B,SAAQ,WAAW;IACxD,SAAkB,SAAS,EAAE,SAAS,GAAG,MAAM,CAAC;IAChD,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,IAAI,EAAE,MAAM,IAAI,CAAC;gBAEL,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc;CAuB1E;AAED,wBAAsB,aAAa,CACjC,IAAI,EAAE,GAAG,EACT,EAAE,EAAE,GAAG,EACP,SAAS,EAAE,SAAS,GAAG,MAAM,EAC7B,cAAc,EAAE,oBAAoB,EACpC,aAAa,EAAE,OAAO,GAAG,SAAS,EAClC,IAAI,EAAE,GAAG,EACT,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,aAAa,EAAE,CAAC,KAAK,EAAE,gCAAgC,KAAK,OAAO,CAAC,IAAI,CAAC,6CAyB1E;AAID,eAAO,MAAM,oBAAoB,GAAI,WAAW;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,SAKnF,CAAC;AAEF,wBAAsB,MAAM,CAC1B,gBAAgB,EAAE,WAAW,EAC7B,cAAc,EAAE,cAAc,EAC9B,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,sCASpC"}
@@ -0,0 +1,114 @@
1
+ /// <reference lib="dom" />
2
+ import { swap } from "./swap-functions.js";
3
+ export const TRANSITION_BEFORE_PREPARATION = "zfb:before-preparation";
4
+ export const TRANSITION_AFTER_PREPARATION = "zfb:after-preparation";
5
+ export const TRANSITION_BEFORE_SWAP = "zfb:before-swap";
6
+ export const TRANSITION_AFTER_SWAP = "zfb:after-swap";
7
+ export const TRANSITION_PAGE_LOAD = "zfb:page-load";
8
+ export const TRANSITION_NAVIGATION_ABORTED = "zfb:navigation-aborted";
9
+ export const triggerEvent = (name) => document.dispatchEvent(new Event(name));
10
+ export const onPageLoad = () => triggerEvent("zfb:page-load");
11
+ /*
12
+ * Common stuff
13
+ */
14
+ class BeforeEvent extends Event {
15
+ from;
16
+ to;
17
+ direction;
18
+ navigationType;
19
+ sourceElement;
20
+ info;
21
+ newDocument;
22
+ signal;
23
+ constructor(type, eventInitDict, from, to, direction, navigationType, sourceElement, info, newDocument, signal) {
24
+ super(type, eventInitDict);
25
+ this.from = from;
26
+ this.to = to;
27
+ this.direction = direction;
28
+ this.navigationType = navigationType;
29
+ this.sourceElement = sourceElement;
30
+ this.info = info;
31
+ this.newDocument = newDocument;
32
+ this.signal = signal;
33
+ Object.defineProperties(this, {
34
+ from: { enumerable: true },
35
+ to: { enumerable: true, writable: true },
36
+ direction: { enumerable: true, writable: true },
37
+ navigationType: { enumerable: true },
38
+ sourceElement: { enumerable: true },
39
+ info: { enumerable: true },
40
+ newDocument: { enumerable: true, writable: true },
41
+ signal: { enumerable: true },
42
+ });
43
+ }
44
+ }
45
+ /*
46
+ * TransitionBeforePreparationEvent
47
+
48
+ */
49
+ export const isTransitionBeforePreparationEvent = (value) => value.type === TRANSITION_BEFORE_PREPARATION;
50
+ export class TransitionBeforePreparationEvent extends BeforeEvent {
51
+ formData;
52
+ loader;
53
+ constructor(from, to, direction, navigationType, sourceElement, info, newDocument, signal, formData, loader) {
54
+ super(TRANSITION_BEFORE_PREPARATION, { cancelable: true }, from, to, direction, navigationType, sourceElement, info, newDocument, signal);
55
+ this.formData = formData;
56
+ this.loader = loader.bind(this, this);
57
+ Object.defineProperties(this, {
58
+ formData: { enumerable: true },
59
+ loader: { enumerable: true, writable: true },
60
+ });
61
+ }
62
+ }
63
+ /*
64
+ * TransitionBeforeSwapEvent
65
+ */
66
+ export const isTransitionBeforeSwapEvent = (value) => value.type === TRANSITION_BEFORE_SWAP;
67
+ export class TransitionBeforeSwapEvent extends BeforeEvent {
68
+ direction;
69
+ viewTransition;
70
+ swap;
71
+ constructor(afterPreparation, viewTransition) {
72
+ super(TRANSITION_BEFORE_SWAP, undefined, afterPreparation.from, afterPreparation.to, afterPreparation.direction, afterPreparation.navigationType, afterPreparation.sourceElement, afterPreparation.info, afterPreparation.newDocument, afterPreparation.signal);
73
+ this.direction = afterPreparation.direction;
74
+ this.viewTransition = viewTransition;
75
+ this.swap = () => swap(this.newDocument);
76
+ Object.defineProperties(this, {
77
+ direction: { enumerable: true },
78
+ viewTransition: { enumerable: true },
79
+ swap: { enumerable: true, writable: true },
80
+ });
81
+ }
82
+ }
83
+ export async function doPreparation(from, to, direction, navigationType, sourceElement, info, signal, formData, defaultLoader) {
84
+ const event = new TransitionBeforePreparationEvent(from, to, direction, navigationType, sourceElement, info, window.document, signal, formData, defaultLoader);
85
+ if (document.dispatchEvent(event)) {
86
+ await event.loader();
87
+ if (!event.defaultPrevented) {
88
+ triggerEvent("zfb:after-preparation");
89
+ if (event.navigationType !== "traverse") {
90
+ // save the current scroll position before we change the DOM and transition to the new page
91
+ updateScrollPosition({ scrollX, scrollY });
92
+ }
93
+ }
94
+ }
95
+ return event;
96
+ }
97
+ // only update history entries that are managed by us
98
+ // leave other entries alone and do not accidentally add state.
99
+ export const updateScrollPosition = (positions) => {
100
+ if (history.state) {
101
+ history.scrollRestoration = "manual";
102
+ history.replaceState({ ...history.state, ...positions }, "");
103
+ }
104
+ };
105
+ export async function doSwap(afterPreparation, viewTransition, afterDispatch) {
106
+ const event = new TransitionBeforeSwapEvent(afterPreparation, viewTransition);
107
+ document.dispatchEvent(event);
108
+ if (afterDispatch) {
109
+ await afterDispatch();
110
+ }
111
+ event.swap();
112
+ return event;
113
+ }
114
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/client-router/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,aAAa,EAAE,CAAC;QAClB,MAAM,aAAa,EAAE,CAAC;IACxB,CAAC;IACD,KAAK,CAAC,IAAI,EAAE,CAAC;IACb,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { ClientRouter, type ClientRouterProps } from "../client-router.js";
2
+ export { TRANSITION_BEFORE_PREPARATION, TRANSITION_AFTER_PREPARATION, TRANSITION_BEFORE_SWAP, TRANSITION_AFTER_SWAP, TRANSITION_PAGE_LOAD, TRANSITION_NAVIGATION_ABORTED, TransitionBeforePreparationEvent, TransitionBeforeSwapEvent, isTransitionBeforePreparationEvent, isTransitionBeforeSwapEvent, } from "./events.js";
3
+ export type { Direction, Fallback, NavigationTypeString, Options } from "./types.js";
4
+ export { swapFunctions, swap } from "./swap-functions.js";
5
+ export { navigate, supportsViewTransitions, transitionEnabledOnThisPage, init } from "./router.js";
6
+ export type { InitOptions } from "./router.js";
7
+ export { prefetch, init as prefetchInit } from "./prefetch.js";
8
+ export type { PrefetchStrategy, PrefetchInitOptions, PrefetchOptions } from "./prefetch.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client-router/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE3E,OAAO,EACL,6BAA6B,EAC7B,4BAA4B,EAC5B,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,6BAA6B,EAC7B,gCAAgC,EAChC,yBAAyB,EACzB,kCAAkC,EAClC,2BAA2B,GAC5B,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAM1D,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnG,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK/C,OAAO,EAAE,QAAQ,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,18 @@
1
+ // Public API surface for the client-router module.
2
+ // This file is the barrel for @takazudo/zfb-runtime's client-router export.
3
+ // W3D adds the <ClientRouter /> component and ClientRouterProps re-exports.
4
+ // Component (W3D).
5
+ export { ClientRouter } from "../client-router.js";
6
+ export { TRANSITION_BEFORE_PREPARATION, TRANSITION_AFTER_PREPARATION, TRANSITION_BEFORE_SWAP, TRANSITION_AFTER_SWAP, TRANSITION_PAGE_LOAD, TRANSITION_NAVIGATION_ABORTED, TransitionBeforePreparationEvent, TransitionBeforeSwapEvent, isTransitionBeforePreparationEvent, isTransitionBeforeSwapEvent, } from "./events.js";
7
+ export { swapFunctions, swap } from "./swap-functions.js";
8
+ // Router public surface.
9
+ // - W3C1: `supportsViewTransitions`, `transitionEnabledOnThisPage`.
10
+ // - W3C2: `navigate()` (public navigation entry).
11
+ // - W3C3: `init()` (idempotent bootstrap: registers click + form intercept listeners).
12
+ export { navigate, supportsViewTransitions, transitionEnabledOnThisPage, init } from "./router.js";
13
+ // Prefetch public surface (#276).
14
+ // `init` from prefetch.ts is re-exported as `prefetchInit` to avoid colliding
15
+ // with the router's `init` above.
16
+ export { prefetch, init as prefetchInit } from "./prefetch.js";
17
+ // (cssesc is an internal helper, not part of the public surface — not re-exported.)
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client-router/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,4EAA4E;AAC5E,4EAA4E;AAE5E,mBAAmB;AACnB,OAAO,EAAE,YAAY,EAA0B,MAAM,qBAAqB,CAAC;AAE3E,OAAO,EACL,6BAA6B,EAC7B,4BAA4B,EAC5B,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,6BAA6B,EAC7B,gCAAgC,EAChC,yBAAyB,EACzB,kCAAkC,EAClC,2BAA2B,GAC5B,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE1D,yBAAyB;AACzB,sEAAsE;AACtE,oDAAoD;AACpD,yFAAyF;AACzF,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGnG,kCAAkC;AAClC,8EAA8E;AAC9E,kCAAkC;AAClC,OAAO,EAAE,QAAQ,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC;AAG/D,oFAAoF"}
@@ -0,0 +1,29 @@
1
+ export type PrefetchStrategy = "hover" | "viewport" | "load" | "tap";
2
+ export interface PrefetchInitOptions {
3
+ prefetchAll?: boolean;
4
+ defaultStrategy?: PrefetchStrategy;
5
+ }
6
+ export interface PrefetchOptions {
7
+ ignoreSlowConnection?: boolean;
8
+ with?: "link" | "fetch";
9
+ }
10
+ /**
11
+ * Reset all module-level state. Exported for test isolation only — not part of
12
+ * the public API and not re-exported from any barrel.
13
+ */
14
+ export declare function __resetForTests(): void;
15
+ /**
16
+ * Public prefetch function. Idempotent per href.
17
+ */
18
+ export declare function prefetch(url: string, opts?: PrefetchOptions): void;
19
+ /**
20
+ * Initialize the prefetch module.
21
+ *
22
+ * Idempotent — multiple calls are safe. The module-level `initialized` flag
23
+ * ensures listeners are registered exactly once.
24
+ *
25
+ * DISABLED-FLAG CONTRACT: if `<meta name="zfb-prefetch-disabled" content="true">`
26
+ * is present in the document at init() time, this function is a no-op.
27
+ */
28
+ export declare function init(options?: PrefetchInitOptions): void;
29
+ //# sourceMappingURL=prefetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefetch.d.ts","sourceRoot":"","sources":["../../src/client-router/prefetch.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC;AAErE,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,gBAAgB,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAoBD;;;GAGG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAWtC;AAqED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,eAAoB,GAAG,IAAI,CAStE;AAyJD;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAgCxD"}