@takazudo/zfb-runtime 0.1.0-next.9 → 0.1.0-next.91
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/CHANGELOG.md +6 -0
- package/README.md +220 -15
- package/dist/client-router/events.d.ts +0 -1
- package/dist/client-router/events.js +2 -2
- package/dist/client-router/events.js.map +1 -1
- package/dist/client-router/index.d.ts +2 -3
- package/dist/client-router/index.js +2 -2
- package/dist/client-router/index.js.map +1 -1
- package/dist/client-router/prefetch.d.ts +0 -1
- package/dist/client-router/prefetch.js +126 -53
- package/dist/client-router/prefetch.js.map +1 -1
- package/dist/client-router/router.d.ts +28 -2
- package/dist/client-router/router.js +364 -30
- package/dist/client-router/router.js.map +1 -1
- package/dist/client-router/swap-functions.d.ts +0 -1
- package/dist/client-router/swap-functions.js +71 -11
- package/dist/client-router/swap-functions.js.map +1 -1
- package/dist/client-router/types.d.ts +4 -1
- package/dist/client-router/types.js.map +1 -1
- package/dist/client-router.d.ts +38 -2
- package/dist/client-router.js +56 -20
- package/dist/client-router.js.map +1 -1
- package/dist/framework.d.ts +0 -1
- package/dist/framework.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/router.d.ts +32 -2
- package/dist/router.js +163 -33
- package/dist/router.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.js +14 -0
- package/dist/server.js.map +1 -0
- package/dist/snapshot.d.ts +0 -1
- package/dist/snapshot.js +3 -2
- package/dist/snapshot.js.map +1 -1
- package/dist/view-transitions.d.ts +0 -1
- package/dist/view-transitions.js.map +1 -1
- package/package.json +26 -4
- package/dist/client-router/cssesc.d.ts +0 -9
- package/dist/client-router/cssesc.d.ts.map +0 -1
- package/dist/client-router/cssesc.js +0 -95
- package/dist/client-router/cssesc.js.map +0 -1
- package/dist/client-router/events.d.ts.map +0 -1
- package/dist/client-router/index.d.ts.map +0 -1
- package/dist/client-router/prefetch.d.ts.map +0 -1
- package/dist/client-router/router.d.ts.map +0 -1
- package/dist/client-router/swap-functions.d.ts.map +0 -1
- package/dist/client-router/types.d.ts.map +0 -1
- package/dist/client-router.d.ts.map +0 -1
- package/dist/framework.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/router.d.ts.map +0 -1
- package/dist/snapshot.d.ts.map +0 -1
- package/dist/view-transitions.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
> **Newer releases:** see https://takazudomodular.com/pj/zudo-front-builder/docs/changelog/ for v0.1.0-next.5 and later. Entries below are historical (kept for npm readers).
|
|
4
4
|
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
### Performance
|
|
8
|
+
|
|
9
|
+
- **paths() memo** — `createPageRouter` now evaluates each dynamic route's `paths()` export exactly once per router instance. Previously, both the `GET /__paths__/<route>` build-pipeline call and every subsequent page render request invoked `paths()` independently, producing O(N²) work for an N-page dynamic route. The memo is shared between the `/__paths__` handler and the per-page render handler; rejections are not cached so a transient paths() failure retries on the next request. Production SSR isolates evaluate `paths()` once per isolate, matching the build-time-enumerator contract; dev mode is safe because each file-save creates a fresh router instance with a clean memo. (#974)
|
|
10
|
+
|
|
5
11
|
## 0.1.0-next.4
|
|
6
12
|
|
|
7
13
|
Version bump for lockstep release. No API changes in `zfb-runtime` itself. Note: the content-snapshot flow fix (#442) touched `packages/zfb/src/content.ts`, which affects how the CLI calls `setContentSnapshot` — but the `zfb-runtime` API surface is unchanged.
|
package/README.md
CHANGED
|
@@ -39,7 +39,9 @@ user pages/ + content/ + layouts/ + components/
|
|
|
39
39
|
|
|
40
40
|
This package supplies the page-router factory the Worker entry calls. It
|
|
41
41
|
is built on [Hono][hono] but does not leak Hono types through the public
|
|
42
|
-
surface — consumers
|
|
42
|
+
surface — consumers import from `src/index.ts`, which re-exports the
|
|
43
|
+
page-router types, the client-router and prefetch API, lifecycle event
|
|
44
|
+
constants, and plugin types, none of which require Hono.
|
|
43
45
|
|
|
44
46
|
[hono]: https://hono.dev/
|
|
45
47
|
|
|
@@ -50,8 +52,14 @@ to the chosen JSX runtime; both `preact-render-to-string` and
|
|
|
50
52
|
|
|
51
53
|
## Public API
|
|
52
54
|
|
|
55
|
+
`createPageRouter` is **server-only** — it builds a Hono app, so it lives at
|
|
56
|
+
the `@takazudo/zfb-runtime/server` subpath. Keeping it out of the client-safe
|
|
57
|
+
`.` barrel means an island importing the bare `@takazudo/zfb-runtime` never
|
|
58
|
+
drags `hono` into a `--platform=browser` bundle (issue #1298). Its *types*
|
|
59
|
+
remain importable from the root barrel (they carry no runtime).
|
|
60
|
+
|
|
53
61
|
```ts
|
|
54
|
-
import { createPageRouter } from "@takazudo/zfb-runtime";
|
|
62
|
+
import { createPageRouter } from "@takazudo/zfb-runtime/server";
|
|
55
63
|
import type {
|
|
56
64
|
CreatePageRouterOptions,
|
|
57
65
|
PageDefinition,
|
|
@@ -64,6 +72,201 @@ import type {
|
|
|
64
72
|
} from "@takazudo/zfb-runtime";
|
|
65
73
|
```
|
|
66
74
|
|
|
75
|
+
### Client-router / view-transitions / prefetch
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import {
|
|
79
|
+
ClientRouter, // framework-agnostic <head> helper — enables view-transition intercepts
|
|
80
|
+
navigate, // imperative navigation
|
|
81
|
+
supportsViewTransitions, // browser capability check
|
|
82
|
+
transitionEnabledOnThisPage, // reads zfb-view-transitions-enabled meta
|
|
83
|
+
prefetch, // prefetch a URL on demand
|
|
84
|
+
prefetchInit, // bootstrap prefetch strategy (e.g. { prefetchAll: true })
|
|
85
|
+
TRANSITION_BEFORE_PREPARATION,
|
|
86
|
+
TRANSITION_AFTER_PREPARATION,
|
|
87
|
+
TRANSITION_BEFORE_SWAP,
|
|
88
|
+
TRANSITION_AFTER_SWAP,
|
|
89
|
+
TRANSITION_PAGE_LOAD,
|
|
90
|
+
TRANSITION_NAVIGATION_ABORTED,
|
|
91
|
+
swapFunctions, // swap step overrides for advanced consumers
|
|
92
|
+
swap,
|
|
93
|
+
} from "@takazudo/zfb-runtime";
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The `./snapshot` and `./client-router` subpath exports are also available for
|
|
97
|
+
consumers that only need part of the surface:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import type { ContentSnapshot } from "@takazudo/zfb-runtime/snapshot";
|
|
101
|
+
import { ClientRouter } from "@takazudo/zfb-runtime/client-router";
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Enabling SPA soft-navigation (the runtime ships automatically)
|
|
105
|
+
|
|
106
|
+
Mounting `<ClientRouter />` in your layout `<head>` is normally **all you need**.
|
|
107
|
+
The build detects the usage and automatically ships the client-router runtime to
|
|
108
|
+
the browser — you do **not** have to add a manual `"use client"` bootstrap
|
|
109
|
+
island.
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import { ClientRouter } from "@takazudo/zfb-runtime";
|
|
113
|
+
|
|
114
|
+
export default function Layout({ children }) {
|
|
115
|
+
return (
|
|
116
|
+
<html>
|
|
117
|
+
<head>
|
|
118
|
+
<ClientRouter fallback="animate" />
|
|
119
|
+
</head>
|
|
120
|
+
<body>{children}</body>
|
|
121
|
+
</html>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`ClientRouterProps`:
|
|
127
|
+
|
|
128
|
+
- `fallback?: "none" | "animate" | "swap"` controls the fallback strategy
|
|
129
|
+
when native View Transitions are unavailable. The default is `"animate"`.
|
|
130
|
+
- `prefetchAll?: boolean` bootstraps same-origin link prefetching with the
|
|
131
|
+
default hover strategy. Treat this as a site-wide router policy and mount
|
|
132
|
+
the same value on every page that participates in SPA navigation.
|
|
133
|
+
- `preserveHtmlAttrs?: string[]` emits
|
|
134
|
+
`<meta name="zfb-preserve-html-attrs">` so the swap step preserves
|
|
135
|
+
runtime-owned `<html>` attributes such as `data-theme`. Mount the same
|
|
136
|
+
list on every soft-navigable page: the router reads the outgoing page's
|
|
137
|
+
meta before each swap, so a page that omits a name can drop that
|
|
138
|
+
attribute when navigating away.
|
|
139
|
+
- `traverseRefetch?: boolean` emits
|
|
140
|
+
`<meta name="zfb-traverse-refetch" content="true">` to opt out of the
|
|
141
|
+
same-URL Back/Forward fast path for per-request SSR pages whose content
|
|
142
|
+
can change at the same URL. Mount the same value on every page in that
|
|
143
|
+
SPA navigation set so traversal behavior is deterministic.
|
|
144
|
+
|
|
145
|
+
**How the runtime reaches the browser.** `<ClientRouter />` itself only renders
|
|
146
|
+
SSR `<head>` tags. The click/form interception is registered by an `init()` call
|
|
147
|
+
that runs as a side effect when `@takazudo/zfb-runtime/client-router` is imported
|
|
148
|
+
in the browser, guarded so it never runs during SSR:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
// inside @takazudo/zfb-runtime — client-router.ts
|
|
152
|
+
if (typeof document !== "undefined") {
|
|
153
|
+
init();
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
To get that side-effect import into the client bundle, zfb's island scanner
|
|
158
|
+
detects when a page transitively reaches `<ClientRouter />` and injects
|
|
159
|
+
`import "@takazudo/zfb-runtime/client-router"` into the islands asset
|
|
160
|
+
(`assets/islands.js`) — **even when the project has no `"use client"` islands of
|
|
161
|
+
its own**. The asset is then loaded on the page, the import runs, and `init()`
|
|
162
|
+
fires on the client with zero boilerplate. (Auto-include added in zfb #289 /
|
|
163
|
+
#307; the runtime is byte-for-byte absent from projects that never reach
|
|
164
|
+
`<ClientRouter />`.)
|
|
165
|
+
|
|
166
|
+
**What counts as a `ClientRouter` usage the scanner detects:**
|
|
167
|
+
|
|
168
|
+
- a named `ClientRouter` import from the `@takazudo/zfb-runtime` barrel —
|
|
169
|
+
`import { ClientRouter } from "@takazudo/zfb-runtime"` (renamed forms like
|
|
170
|
+
`{ ClientRouter as CR }` match on the imported name), or
|
|
171
|
+
- any import or re-export of the `@takazudo/zfb-runtime/client-router` subpath
|
|
172
|
+
(e.g. when you only need `navigate` / `prefetch`), or
|
|
173
|
+
- a named `ClientRouter` imported from a *local* barrel that re-exports the
|
|
174
|
+
runtime via `export * from "@takazudo/zfb-runtime"`.
|
|
175
|
+
|
|
176
|
+
The importing module has to be reachable from a page in `pages/` — that is the
|
|
177
|
+
import graph the scanner walks.
|
|
178
|
+
|
|
179
|
+
**When you need a manual side-effect import.** Detection keys off the *import* of
|
|
180
|
+
`ClientRouter`, and a couple of shapes are deliberately **not** treated as a
|
|
181
|
+
trigger — firing on them would ship the runtime to projects that only reference
|
|
182
|
+
`ClientRouter` as a type or never call it:
|
|
183
|
+
|
|
184
|
+
- a namespace import — `import * as rt from "@takazudo/zfb-runtime"` used as
|
|
185
|
+
`rt.ClientRouter`, and
|
|
186
|
+
- a type-only import — `import type { ClientRouter }` (or `{ type ClientRouter }`).
|
|
187
|
+
|
|
188
|
+
If soft-navigation is not working because your reference takes one of these forms
|
|
189
|
+
(or the mounting module is otherwise not reachable from a page), force the
|
|
190
|
+
runtime in with an explicit side-effect import from a page-reachable
|
|
191
|
+
`"use client"` island. The island renders nothing; running its bundle in the
|
|
192
|
+
browser fires the same `typeof document !== "undefined"` guard (`init()` is
|
|
193
|
+
idempotent, so reaching it again is a no-op):
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
// src/components/client-router-bootstrap.tsx
|
|
197
|
+
"use client";
|
|
198
|
+
import "@takazudo/zfb-runtime/client-router";
|
|
199
|
+
|
|
200
|
+
export default function ClientRouterBootstrap() {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Stable marker name so the SSR marker, the scanner record, and the hydration
|
|
205
|
+
// manifest agree under production minification.
|
|
206
|
+
ClientRouterBootstrap.displayName = "ClientRouterBootstrap";
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
```tsx
|
|
210
|
+
import { Island } from "@takazudo/zfb";
|
|
211
|
+
import ClientRouterBootstrap from "@/components/client-router-bootstrap";
|
|
212
|
+
|
|
213
|
+
// Mount once near the end of <body>; when="load" registers the intercepts as
|
|
214
|
+
// soon as the islands runtime starts.
|
|
215
|
+
<Island when="load">
|
|
216
|
+
<ClientRouterBootstrap />
|
|
217
|
+
</Island>;
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
This is the escape hatch, not the default — prefer a plain
|
|
221
|
+
`import { ClientRouter } from "@takazudo/zfb-runtime"`, which the scanner detects
|
|
222
|
+
on its own. See the [Client-Side Routing concept
|
|
223
|
+
guide](https://takazudomodular.com/pj/zudo-front-builder/docs/concepts/client-side-routing/)
|
|
224
|
+
for the full API.
|
|
225
|
+
|
|
226
|
+
#### `navigate()` needs `<ClientRouter />` mounted on the current page
|
|
227
|
+
|
|
228
|
+
The root barrel exports `navigate` and `syncHistoryEntry`, but **not** `init`
|
|
229
|
+
— importing either of those two on their own is not enough to get soft
|
|
230
|
+
navigation. `navigate()` checks for the `<meta
|
|
231
|
+
name="zfb-view-transitions-enabled">` tag that `<ClientRouter />` renders into
|
|
232
|
+
`<head>` before it will do a soft swap; with that tag absent it silently falls
|
|
233
|
+
back to a full `location.href` load. Mount `<ClientRouter />` in the layout
|
|
234
|
+
`<head>` of every page that should be soft-navigable — it both renders that
|
|
235
|
+
meta tag and calls `init()` (click/form interception) as a side effect. `init`
|
|
236
|
+
itself is exported from the `@takazudo/zfb-runtime/client-router` subpath, not
|
|
237
|
+
the root barrel, for the rare case where you want to call it directly instead
|
|
238
|
+
of mounting the component.
|
|
239
|
+
|
|
240
|
+
#### Persisting elements and island state across navigations (`data-zfb-transition-persist`)
|
|
241
|
+
|
|
242
|
+
Add `data-zfb-transition-persist="<id>"` to an element (matched by the same
|
|
243
|
+
`id` on both the outgoing and incoming page) to keep it alive across a soft
|
|
244
|
+
navigation instead of letting it be discarded and re-created — the router
|
|
245
|
+
lifts it out of the old body and reattaches it into the new one. This works
|
|
246
|
+
on plain elements (`<video>`, `<canvas>`) and on island wrapper elements
|
|
247
|
+
(`[data-zfb-island]`) alike; for an island, the live component instance (and
|
|
248
|
+
its internal state) survives too, not just the DOM node.
|
|
249
|
+
|
|
250
|
+
```tsx
|
|
251
|
+
<div data-zfb-island="SidebarTree" data-zfb-transition-persist="sidebar-tree" data-props={props}>
|
|
252
|
+
<SidebarTree {...props} />
|
|
253
|
+
</div>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
By default, a persisted island still gets its `data-props` refreshed to match
|
|
257
|
+
the incoming page on every swap; if the refreshed props differ from what the
|
|
258
|
+
live instance currently holds, the island is unmounted and remounted fresh
|
|
259
|
+
with the new props (so it can't get stuck showing stale data), otherwise
|
|
260
|
+
nothing happens and the instance's state carries over untouched. Set
|
|
261
|
+
`data-zfb-transition-persist-props` to any value other than `"false"`
|
|
262
|
+
(conventionally `"true"`) to opt OUT of that props refresh and keep the
|
|
263
|
+
island's current props/state exactly as they are, regardless of what the
|
|
264
|
+
incoming page's props would have been — the attribute's absence, or the
|
|
265
|
+
literal string `"false"`, is what makes props refresh (mirrors Astro's
|
|
266
|
+
`data-astro-transition-persist-props`). See the [Client-Side Routing concept
|
|
267
|
+
guide](https://takazudomodular.com/pj/zudo-front-builder/docs/concepts/client-side-routing/)
|
|
268
|
+
for the full walkthrough, including when to reach for the opt-out.
|
|
269
|
+
|
|
67
270
|
### `createPageRouter(options) → PageRouter`
|
|
68
271
|
|
|
69
272
|
Build a fetch-handler that serves the supplied pages. The returned
|
|
@@ -86,7 +289,7 @@ export default { fetch: router };
|
|
|
86
289
|
from memory rather than the Node `fs` API. Workers have no `fs`,
|
|
87
290
|
so this branch is the production path. Idempotent; subsequent
|
|
88
291
|
calls overwrite (matches the dev-mode live-reload contract).
|
|
89
|
-
2. Constructs an internal Hono app and registers `app.
|
|
292
|
+
2. Constructs an internal Hono app and registers `app.all(page.route, …)`
|
|
90
293
|
for every entry in `pages`. The handler imports the page module,
|
|
91
294
|
calls `framework.renderToString(module.default({}))`, and returns
|
|
92
295
|
the string in a `Response`.
|
|
@@ -108,8 +311,10 @@ The shape every page module must export:
|
|
|
108
311
|
interface PageModule {
|
|
109
312
|
readonly default: (props: Record<string, unknown>) => unknown;
|
|
110
313
|
readonly prerender?: boolean; // literal `false` excludes from SSG
|
|
111
|
-
readonly
|
|
314
|
+
readonly contentType?: string; // overrides Content-Type (e.g. "application/xml")
|
|
112
315
|
readonly headings?: readonly PageHeading[]; // MDX-emitted TOC data
|
|
316
|
+
readonly paths?: () => unknown[] | Promise<unknown[]>; // enumerates concrete URLs for dynamic routes (SSG)
|
|
317
|
+
readonly getStaticProps?: () => Promise<{ props: Record<string, unknown> }>; // fetches props at build/render time; result spread into default()
|
|
113
318
|
}
|
|
114
319
|
|
|
115
320
|
interface PageHeading {
|
|
@@ -126,12 +331,9 @@ Default `Content-Type` is `text/html; charset=utf-8`.
|
|
|
126
331
|
```ts
|
|
127
332
|
interface FrameworkAdapter {
|
|
128
333
|
renderToString: (vnode: unknown) => string;
|
|
129
|
-
hydrate?: (...args: unknown[]) => unknown; // reserved for follow-up SSR-with-hydration
|
|
130
334
|
}
|
|
131
335
|
```
|
|
132
336
|
|
|
133
|
-
`hydrate` is reserved — the page router does not call it today.
|
|
134
|
-
|
|
135
337
|
### `ContentSnapshot` / `EntrySnapshot`
|
|
136
338
|
|
|
137
339
|
Direct TypeScript mirror of the Rust contract in
|
|
@@ -165,7 +367,7 @@ esbuild step. The bundle's entry point must look like this:
|
|
|
165
367
|
|
|
166
368
|
```ts
|
|
167
369
|
// dist/worker.mjs (shape — generated by the bundler, not committed)
|
|
168
|
-
import { createPageRouter } from "@takazudo/zfb-runtime";
|
|
370
|
+
import { createPageRouter } from "@takazudo/zfb-runtime/server";
|
|
169
371
|
import * as preactRender from "preact-render-to-string";
|
|
170
372
|
|
|
171
373
|
import HomePage from "./pages/index.tsx";
|
|
@@ -200,7 +402,7 @@ enumerated route and writing the response body to `dist/{route}/index.html`.
|
|
|
200
402
|
- The returned function is **always** `(request: Request) => Promise<Response>`,
|
|
201
403
|
even if the underlying Hono path returns synchronously.
|
|
202
404
|
- `Content-Type` defaults to `text/html; charset=utf-8`. Page modules
|
|
203
|
-
with a `
|
|
405
|
+
with a `contentType` field override it.
|
|
204
406
|
- Errors in page evaluation surface as 500 responses with a diagnostic
|
|
205
407
|
text body; the host's source-map plumbing projects those back to the
|
|
206
408
|
user's TSX line.
|
|
@@ -218,10 +420,12 @@ pnpm --filter @takazudo/zfb-runtime typecheck
|
|
|
218
420
|
```
|
|
219
421
|
|
|
220
422
|
Tests run in `vitest` under Node's `node` environment (no jsdom — the
|
|
221
|
-
|
|
222
|
-
natively).
|
|
223
|
-
|
|
224
|
-
|
|
423
|
+
server-side router targets the Workers `fetch` model, which Node
|
|
424
|
+
implements natively). Client-router DOM suites opt into
|
|
425
|
+
`@vitest-environment happy-dom` per test file. The framework adapter is
|
|
426
|
+
stubbed so tests do not pull in preact-render-to-string. Determinism is
|
|
427
|
+
asserted by rendering twice from independently-constructed routers and
|
|
428
|
+
comparing byte-equal.
|
|
225
429
|
|
|
226
430
|
The embedded V8 host is **not** booted from this package's tests — that
|
|
227
431
|
integration belongs to the Rust-side build host. The end-to-end
|
|
@@ -233,5 +437,6 @@ route") is exercised by the host crate's test suite, not here.
|
|
|
233
437
|
`createPageRouter` calls `setContentSnapshot` from `zfb/content`. The
|
|
234
438
|
two modules share module-level state, so they must resolve to the same
|
|
235
439
|
instance — pinning `zfb` as a peer dep makes that explicit and lets pnpm
|
|
236
|
-
hoist a single shared copy.
|
|
237
|
-
`
|
|
440
|
+
hoist a single shared copy. Install matching published versions of
|
|
441
|
+
`@takazudo/zfb-runtime` and `@takazudo/zfb` so that shared state remains
|
|
442
|
+
single-instanced.
|
|
@@ -39,4 +39,3 @@ export declare const updateScrollPosition: (positions: {
|
|
|
39
39
|
}) => void;
|
|
40
40
|
export declare function doSwap(afterPreparation: BeforeEvent, viewTransition: ViewTransition, afterDispatch?: () => Promise<void>): Promise<TransitionBeforeSwapEvent>;
|
|
41
41
|
export {};
|
|
42
|
-
//# sourceMappingURL=events.d.ts.map
|
|
@@ -46,7 +46,7 @@ class BeforeEvent extends Event {
|
|
|
46
46
|
* TransitionBeforePreparationEvent
|
|
47
47
|
|
|
48
48
|
*/
|
|
49
|
-
export const isTransitionBeforePreparationEvent = (value) => value.type === TRANSITION_BEFORE_PREPARATION;
|
|
49
|
+
export const isTransitionBeforePreparationEvent = (value) => typeof value === "object" && value !== null && value.type === TRANSITION_BEFORE_PREPARATION;
|
|
50
50
|
export class TransitionBeforePreparationEvent extends BeforeEvent {
|
|
51
51
|
formData;
|
|
52
52
|
loader;
|
|
@@ -63,7 +63,7 @@ export class TransitionBeforePreparationEvent extends BeforeEvent {
|
|
|
63
63
|
/*
|
|
64
64
|
* TransitionBeforeSwapEvent
|
|
65
65
|
*/
|
|
66
|
-
export const isTransitionBeforeSwapEvent = (value) => value.type === TRANSITION_BEFORE_SWAP;
|
|
66
|
+
export const isTransitionBeforeSwapEvent = (value) => typeof value === "object" && value !== null && value.type === TRANSITION_BEFORE_SWAP;
|
|
67
67
|
export class TransitionBeforeSwapEvent extends BeforeEvent {
|
|
68
68
|
direction;
|
|
69
69
|
viewTransition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/client-router/events.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAG3C,MAAM,CAAC,MAAM,6BAA6B,GAAG,wBAAwB,CAAC;AACtE,MAAM,CAAC,MAAM,4BAA4B,GAAG,uBAAuB,CAAC;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AACxD,MAAM,CAAC,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AACtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AACpD,MAAM,CAAC,MAAM,6BAA6B,GAAG,wBAAwB,CAAC;AAOtE,MAAM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C;AACf,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\nimport { swap } from \"./swap-functions.js\";\nimport type { Direction, NavigationTypeString } from \"./types.js\";\n\nexport const TRANSITION_BEFORE_PREPARATION = \"zfb:before-preparation\";\nexport const TRANSITION_AFTER_PREPARATION = \"zfb:after-preparation\";\nexport const TRANSITION_BEFORE_SWAP = \"zfb:before-swap\";\nexport const TRANSITION_AFTER_SWAP = \"zfb:after-swap\";\nexport const TRANSITION_PAGE_LOAD = \"zfb:page-load\";\nexport const TRANSITION_NAVIGATION_ABORTED = \"zfb:navigation-aborted\";\n\ntype Events =\n | \"zfb:after-preparation\"\n | \"zfb:after-swap\"\n | \"zfb:page-load\"\n | \"zfb:navigation-aborted\";\nexport const triggerEvent = (name: Events) => document.dispatchEvent(new Event(name));\nexport const onPageLoad = () => triggerEvent(\"zfb:page-load\");\n\n/*\n * Common stuff\n */\nclass BeforeEvent extends Event {\n readonly from: URL;\n to: URL;\n direction: Direction | string;\n readonly navigationType: NavigationTypeString;\n readonly sourceElement: Element | undefined;\n readonly info: any;\n newDocument: Document;\n readonly signal: AbortSignal;\n\n constructor(\n type: string,\n eventInitDict: EventInit | undefined,\n from: URL,\n to: URL,\n direction: Direction | string,\n navigationType: NavigationTypeString,\n sourceElement: Element | undefined,\n info: any,\n newDocument: Document,\n signal: AbortSignal,\n ) {\n super(type, eventInitDict);\n this.from = from;\n this.to = to;\n this.direction = direction;\n this.navigationType = navigationType;\n this.sourceElement = sourceElement;\n this.info = info;\n this.newDocument = newDocument;\n this.signal = signal;\n\n Object.defineProperties(this, {\n from: { enumerable: true },\n to: { enumerable: true, writable: true },\n direction: { enumerable: true, writable: true },\n navigationType: { enumerable: true },\n sourceElement: { enumerable: true },\n info: { enumerable: true },\n newDocument: { enumerable: true, writable: true },\n signal: { enumerable: true },\n });\n }\n}\n\n/*\n * TransitionBeforePreparationEvent\n\n */\nexport const isTransitionBeforePreparationEvent = (\n value: any,\n): value is TransitionBeforePreparationEvent =>\n typeof value === \"object\" && value !== null && value.type === TRANSITION_BEFORE_PREPARATION;\nexport class TransitionBeforePreparationEvent extends BeforeEvent {\n formData: FormData | undefined;\n loader: () => Promise<void>;\n constructor(\n from: URL,\n to: URL,\n direction: Direction | string,\n navigationType: NavigationTypeString,\n sourceElement: Element | undefined,\n info: any,\n newDocument: Document,\n signal: AbortSignal,\n formData: FormData | undefined,\n loader: (event: TransitionBeforePreparationEvent) => Promise<void>,\n ) {\n super(\n TRANSITION_BEFORE_PREPARATION,\n { cancelable: true },\n from,\n to,\n direction,\n navigationType,\n sourceElement,\n info,\n newDocument,\n signal,\n );\n this.formData = formData;\n this.loader = loader.bind(this, this);\n Object.defineProperties(this, {\n formData: { enumerable: true },\n loader: { enumerable: true, writable: true },\n });\n }\n}\n\n/*\n * TransitionBeforeSwapEvent\n */\nexport const isTransitionBeforeSwapEvent = (value: any): value is TransitionBeforeSwapEvent =>\n typeof value === \"object\" && value !== null && value.type === TRANSITION_BEFORE_SWAP;\nexport class TransitionBeforeSwapEvent extends BeforeEvent {\n override readonly direction: Direction | string;\n readonly viewTransition: ViewTransition;\n swap: () => void;\n\n constructor(afterPreparation: BeforeEvent, viewTransition: ViewTransition) {\n super(\n TRANSITION_BEFORE_SWAP,\n undefined,\n afterPreparation.from,\n afterPreparation.to,\n afterPreparation.direction,\n afterPreparation.navigationType,\n afterPreparation.sourceElement,\n afterPreparation.info,\n afterPreparation.newDocument,\n afterPreparation.signal,\n );\n this.direction = afterPreparation.direction;\n this.viewTransition = viewTransition;\n this.swap = () => swap(this.newDocument);\n\n Object.defineProperties(this, {\n direction: { enumerable: true },\n viewTransition: { enumerable: true },\n swap: { enumerable: true, writable: true },\n });\n }\n}\n\nexport async function doPreparation(\n from: URL,\n to: URL,\n direction: Direction | string,\n navigationType: NavigationTypeString,\n sourceElement: Element | undefined,\n info: any,\n signal: AbortSignal,\n formData: FormData | undefined,\n defaultLoader: (event: TransitionBeforePreparationEvent) => Promise<void>,\n) {\n const event = new TransitionBeforePreparationEvent(\n from,\n to,\n direction,\n navigationType,\n sourceElement,\n info,\n window.document,\n signal,\n formData,\n defaultLoader,\n );\n if (document.dispatchEvent(event)) {\n await event.loader();\n if (!event.defaultPrevented) {\n triggerEvent(\"zfb:after-preparation\");\n if (event.navigationType !== \"traverse\") {\n // save the current scroll position before we change the DOM and transition to the new page\n updateScrollPosition({ scrollX, scrollY });\n }\n }\n }\n return event;\n}\n\n// only update history entries that are managed by us\n// leave other entries alone and do not accidentally add state.\nexport const updateScrollPosition = (positions: { scrollX: number; scrollY: number }) => {\n if (history.state) {\n history.scrollRestoration = \"manual\";\n history.replaceState({ ...history.state, ...positions }, \"\");\n }\n};\n\nexport async function doSwap(\n afterPreparation: BeforeEvent,\n viewTransition: ViewTransition,\n afterDispatch?: () => Promise<void>,\n) {\n const event = new TransitionBeforeSwapEvent(afterPreparation, viewTransition);\n document.dispatchEvent(event);\n if (afterDispatch) {\n await afterDispatch();\n }\n event.swap();\n return event;\n}\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { ClientRouter, type ClientRouterProps } from "../client-router.js";
|
|
2
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";
|
|
3
|
+
export type { Direction, Fallback, NavigationTypeString, Options, SyncHistoryEntryOptions, } from "./types.js";
|
|
4
4
|
export { swapFunctions, swap } from "./swap-functions.js";
|
|
5
|
-
export { navigate, supportsViewTransitions, transitionEnabledOnThisPage, init } from "./router.js";
|
|
5
|
+
export { navigate, supportsViewTransitions, transitionEnabledOnThisPage, init, syncHistoryEntry, } from "./router.js";
|
|
6
6
|
export type { InitOptions } from "./router.js";
|
|
7
7
|
export { prefetch, init as prefetchInit } from "./prefetch.js";
|
|
8
8
|
export type { PrefetchStrategy, PrefetchInitOptions, PrefetchOptions } from "./prefetch.js";
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -9,10 +9,10 @@ export { swapFunctions, swap } from "./swap-functions.js";
|
|
|
9
9
|
// - W3C1: `supportsViewTransitions`, `transitionEnabledOnThisPage`.
|
|
10
10
|
// - W3C2: `navigate()` (public navigation entry).
|
|
11
11
|
// - W3C3: `init()` (idempotent bootstrap: registers click + form intercept listeners).
|
|
12
|
-
|
|
12
|
+
// - W2 (#1377): `syncHistoryEntry()` (history bookkeeping without navigation).
|
|
13
|
+
export { navigate, supportsViewTransitions, transitionEnabledOnThisPage, init, syncHistoryEntry, } from "./router.js";
|
|
13
14
|
// Prefetch public surface (#276).
|
|
14
15
|
// `init` from prefetch.ts is re-exported as `prefetchInit` to avoid colliding
|
|
15
16
|
// with the router's `init` above.
|
|
16
17
|
export { prefetch, init as prefetchInit } from "./prefetch.js";
|
|
17
|
-
// (cssesc is an internal helper, not part of the public surface — not re-exported.)
|
|
18
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +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;
|
|
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;AAUrB,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE1D,yBAAyB;AACzB,sEAAsE;AACtE,oDAAoD;AACpD,yFAAyF;AACzF,iFAAiF;AACjF,OAAO,EACL,QAAQ,EACR,uBAAuB,EACvB,2BAA2B,EAC3B,IAAI,EACJ,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAGrB,kCAAkC;AAClC,8EAA8E;AAC9E,kCAAkC;AAClC,OAAO,EAAE,QAAQ,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC","sourcesContent":["// Public API surface for the client-router module.\n// This file is the barrel for @takazudo/zfb-runtime's client-router export.\n// W3D adds the <ClientRouter /> component and ClientRouterProps re-exports.\n\n// Component (W3D).\nexport { ClientRouter, type ClientRouterProps } from \"../client-router.js\";\n\nexport {\n TRANSITION_BEFORE_PREPARATION,\n TRANSITION_AFTER_PREPARATION,\n TRANSITION_BEFORE_SWAP,\n TRANSITION_AFTER_SWAP,\n TRANSITION_PAGE_LOAD,\n TRANSITION_NAVIGATION_ABORTED,\n TransitionBeforePreparationEvent,\n TransitionBeforeSwapEvent,\n isTransitionBeforePreparationEvent,\n isTransitionBeforeSwapEvent,\n} from \"./events.js\";\n\nexport type {\n Direction,\n Fallback,\n NavigationTypeString,\n Options,\n SyncHistoryEntryOptions,\n} from \"./types.js\";\n\nexport { swapFunctions, swap } from \"./swap-functions.js\";\n\n// Router public surface.\n// - W3C1: `supportsViewTransitions`, `transitionEnabledOnThisPage`.\n// - W3C2: `navigate()` (public navigation entry).\n// - W3C3: `init()` (idempotent bootstrap: registers click + form intercept listeners).\n// - W2 (#1377): `syncHistoryEntry()` (history bookkeeping without navigation).\nexport {\n navigate,\n supportsViewTransitions,\n transitionEnabledOnThisPage,\n init,\n syncHistoryEntry,\n} from \"./router.js\";\nexport type { InitOptions } from \"./router.js\";\n\n// Prefetch public surface (#276).\n// `init` from prefetch.ts is re-exported as `prefetchInit` to avoid colliding\n// with the router's `init` above.\nexport { prefetch, init as prefetchInit } from \"./prefetch.js\";\nexport type { PrefetchStrategy, PrefetchInitOptions, PrefetchOptions } from \"./prefetch.js\";\n"]}
|