@hamur/adapter-html 0.0.0-stage → 0.0.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 (54) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +31 -2
  3. package/dist/chunks/browser-index-2h1699xv.js +148 -0
  4. package/dist/chunks/browser-index-n6x04zrf.js +28 -0
  5. package/dist/chunks/browser-index-naq02zzj.js +4 -0
  6. package/dist/chunks/browser-index-qx74bd1y.js +302 -0
  7. package/dist/src/adapter.js +141 -0
  8. package/dist/src/error-page.js +335 -0
  9. package/dist/src/index.js +1241 -0
  10. package/dist/src/runtime/client.js +330 -0
  11. package/dist/src/runtime/island.js +40 -0
  12. package/dist/src/runtime/server.js +59 -0
  13. package/dist/types/src/adapter.d.ts +2 -0
  14. package/dist/types/src/async-data.d.ts +13 -0
  15. package/dist/types/src/context.d.ts +109 -0
  16. package/dist/types/src/error-page.d.ts +1 -0
  17. package/dist/types/src/index.d.ts +343 -0
  18. package/dist/types/src/island-html.d.ts +13 -0
  19. package/dist/types/src/island.d.ts +40 -0
  20. package/dist/types/src/lazy-hydration.d.ts +11 -0
  21. package/dist/types/src/markdown-page.d.ts +9 -0
  22. package/dist/types/src/markdown.d.ts +11 -0
  23. package/dist/types/src/plugin.d.ts +11 -0
  24. package/dist/types/src/runtime/client.d.ts +15 -0
  25. package/dist/types/src/runtime/hmr.d.ts +8 -0
  26. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  27. package/dist/types/src/runtime/hydration.d.ts +10 -0
  28. package/dist/types/src/runtime/island.d.ts +8 -0
  29. package/dist/types/src/runtime/server.d.ts +8 -0
  30. package/dist/types/src/runtime/svg-id.d.ts +2 -0
  31. package/dist/types/src/server-component.d.ts +4 -0
  32. package/dist/types/src/svg.d.ts +10 -0
  33. package/package.json +62 -4
  34. package/src/adapter.ts +25 -0
  35. package/src/async-data.ts +65 -0
  36. package/src/context.ts +445 -0
  37. package/src/env.d.ts +3 -0
  38. package/src/error-page.ts +1 -0
  39. package/src/index.ts +1620 -0
  40. package/src/island-html.ts +58 -0
  41. package/src/island.ts +126 -0
  42. package/src/lazy-hydration.ts +56 -0
  43. package/src/markdown-page.ts +17 -0
  44. package/src/markdown.ts +29 -0
  45. package/src/plugin.ts +70 -0
  46. package/src/runtime/client.ts +363 -0
  47. package/src/runtime/hmr.ts +38 -0
  48. package/src/runtime/hydration-dev.ts +12 -0
  49. package/src/runtime/hydration.ts +11 -0
  50. package/src/runtime/island.ts +52 -0
  51. package/src/runtime/server.ts +56 -0
  52. package/src/runtime/svg-id.ts +12 -0
  53. package/src/server-component.ts +30 -0
  54. package/src/svg.ts +54 -0
@@ -0,0 +1,330 @@
1
+ import {
2
+ RERUN_STATE_KEY,
3
+ LINK_STATE_ATTRIBUTE,
4
+ linkStateKey,
5
+ PAGE_MARKERS,
6
+ LAYOUT_MARKERS,
7
+ CLIENT_MARKERS,
8
+ CLIENT_TEMPLATE,
9
+ setRepaint,
10
+ repaintPage,
11
+ takeIndicatorRendered,
12
+ takeAnnouncerRendered,
13
+ releaseAnnouncerClaims,
14
+ followNavigation,
15
+ currentState,
16
+ setCurrent,
17
+ renderTree
18
+ } from "../../chunks/browser-index-qx74bd1y.js";
19
+ import {
20
+ serverComponentId,
21
+ isPage,
22
+ serverComponentHTML
23
+ } from "../../chunks/browser-index-n6x04zrf.js";
24
+ import {
25
+ devHydration
26
+ } from "../../chunks/browser-index-naq02zzj.js";
27
+
28
+ // packages/adapter-html/src/runtime/client.ts
29
+ import {
30
+ createAnnouncer,
31
+ createLoadingIndicator,
32
+ createRouteAnnouncer,
33
+ fetchServerComponent,
34
+ hideAnnouncer,
35
+ paintLoadingIndicator,
36
+ serverComponentProps,
37
+ setAdapterInstance,
38
+ setLinkState,
39
+ takeServerHTML,
40
+ writeRouteAnnouncer
41
+ } from "hamur/adapter";
42
+ var entries = [];
43
+ var scoped = [];
44
+ function keepLinkStates(root, states) {
45
+ for (const anchor of root.querySelectorAll(`a[${LINK_STATE_ATTRIBUTE}]`)) {
46
+ const entry = states.get(linkStateKey(anchor.getAttribute("href") ?? "", anchor.getAttribute(LINK_STATE_ATTRIBUTE)));
47
+ anchor.removeAttribute(LINK_STATE_ATTRIBUTE);
48
+ if (entry)
49
+ setLinkState(anchor, entry.state, entry.onBeforeNavigate);
50
+ }
51
+ }
52
+ function renderOut() {
53
+ for (const remove of scoped)
54
+ remove();
55
+ scoped = [];
56
+ return { linkStates: new Map, scoped };
57
+ }
58
+ var COMMENT = 8;
59
+ var ELEMENT = 1;
60
+ var isDev = import.meta.dev === true;
61
+ var warnedKeepAlive = new Set;
62
+ function warnKeepAlive(ctx) {
63
+ if (!isDev || ctx.route.meta.keepalive !== true)
64
+ return;
65
+ const route = ctx.route.matched.at(-1)?.path ?? ctx.route.path;
66
+ if (warnedKeepAlive.has(route))
67
+ return;
68
+ warnedKeepAlive.add(route);
69
+ console.warn(`meta.keepalive of ${route} has no effect in html apps (no component state)`);
70
+ }
71
+ function holdFocus(root) {
72
+ if (typeof document === "undefined" || typeof HTMLInputElement === "undefined" || typeof HTMLTextAreaElement === "undefined")
73
+ return;
74
+ const active = document.activeElement;
75
+ if (!(active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement) || !active.id || typeof root.contains !== "function" || !root.contains(active))
76
+ return;
77
+ return { id: active.id, value: active.value, start: active.selectionStart, end: active.selectionEnd };
78
+ }
79
+ function restoreFocus(root, held) {
80
+ if (typeof root.querySelectorAll !== "function")
81
+ return;
82
+ const next = [...root.querySelectorAll("input, textarea")].find((element) => element.id === held.id);
83
+ if (!next)
84
+ return;
85
+ next.value = held.value;
86
+ next.focus?.({ preventScroll: true });
87
+ if (held.start !== null && held.end !== null)
88
+ next.setSelectionRange?.(held.start, held.end);
89
+ }
90
+ function paint(ctx, completesNavigation = false) {
91
+ setRepaint(() => paint(ctx));
92
+ if (undefined)
93
+ ;
94
+ for (const entry of entries)
95
+ entry.dispose();
96
+ entries = [];
97
+ takeIndicatorRendered();
98
+ takeAnnouncerRendered();
99
+ releaseAnnouncerClaims();
100
+ const out = renderOut();
101
+ const held = holdFocus(ctx.root);
102
+ ctx.setRootHTML(renderTree(ctx, entries, completesNavigation, out));
103
+ if (held)
104
+ restoreFocus(ctx.root, held);
105
+ if (out.linkStates.size)
106
+ keepLinkStates(ctx.root, out.linkStates);
107
+ ctx.head.apply();
108
+ if (takeIndicatorRendered())
109
+ driveLoadingIndicators(ctx);
110
+ if (takeAnnouncerRendered())
111
+ driveAnnouncers(ctx);
112
+ else
113
+ stopAnnouncers();
114
+ }
115
+ var INDICATOR = "[data-hamur-loading-indicator]";
116
+ var driven;
117
+ function numberOf(value) {
118
+ return value === undefined ? undefined : Number(value);
119
+ }
120
+ function lookOf({ dataset }) {
121
+ const look = {};
122
+ if (dataset.hamurColor !== undefined)
123
+ look.color = dataset.hamurColor;
124
+ if (dataset.hamurErrorColor !== undefined)
125
+ look.errorColor = dataset.hamurErrorColor;
126
+ if (dataset.hamurHeight !== undefined)
127
+ look.height = Number(dataset.hamurHeight);
128
+ return look;
129
+ }
130
+ function driveLoadingIndicators(ctx) {
131
+ const elements = ctx.root.querySelectorAll(INDICATOR);
132
+ const first = elements[0];
133
+ if (!first)
134
+ return;
135
+ const options = {};
136
+ const duration = numberOf(first.dataset.hamurDuration);
137
+ const throttle = numberOf(first.dataset.hamurThrottle);
138
+ if (duration !== undefined)
139
+ options.duration = duration;
140
+ if (throttle !== undefined)
141
+ options.throttle = throttle;
142
+ const store = createLoadingIndicator(ctx.app, options);
143
+ followNavigation(ctx.app, ctx.navigator);
144
+ const render = () => {
145
+ for (const element of ctx.root.querySelectorAll(INDICATOR))
146
+ paintLoadingIndicator(element, store.get(), lookOf(element));
147
+ };
148
+ render();
149
+ if (driven?.app === ctx.app)
150
+ return;
151
+ driven?.stop();
152
+ driven = { app: ctx.app, stop: store.subscribe(render) };
153
+ }
154
+ var ANNOUNCER = "[data-hamur-announcer]";
155
+ var announcing;
156
+ function stopAnnouncers() {
157
+ announcing?.stop?.();
158
+ announcing?.route?.();
159
+ announcing?.page?.();
160
+ announcing = undefined;
161
+ }
162
+ function announcerElements(root) {
163
+ const found = {};
164
+ for (const element of root.querySelectorAll(ANNOUNCER)) {
165
+ const kind = element.dataset.hamurAnnouncer;
166
+ if (kind === "route" || kind === "polite" || kind === "assertive")
167
+ found[kind] ??= element;
168
+ }
169
+ return found;
170
+ }
171
+ function driveAnnouncers(ctx) {
172
+ if (announcing && announcing.app !== ctx.app)
173
+ stopAnnouncers();
174
+ const found = announcerElements(ctx.root);
175
+ const routeStore = createRouteAnnouncer(ctx.app);
176
+ const pageStore = createAnnouncer(ctx.app);
177
+ const driven = announcing ??= { app: ctx.app };
178
+ if (found.route && !driven.route)
179
+ driven.route = routeStore.mount();
180
+ if (!found.route && driven.route) {
181
+ driven.route();
182
+ driven.route = undefined;
183
+ }
184
+ const paged = !!(found.polite || found.assertive);
185
+ if (paged && !driven.page)
186
+ driven.page = pageStore.mount();
187
+ if (!paged && driven.page) {
188
+ driven.page();
189
+ driven.page = undefined;
190
+ }
191
+ if (found.route && !found.route.hasAttribute("class") && !found.route.hasAttribute("style"))
192
+ hideAnnouncer(found.route);
193
+ if (found.polite)
194
+ hideAnnouncer(found.polite);
195
+ if (found.assertive)
196
+ hideAnnouncer(found.assertive);
197
+ const render = () => {
198
+ const now = announcerElements(ctx.root);
199
+ if (now.route)
200
+ writeRouteAnnouncer(now.route, {
201
+ ...routeStore.get(),
202
+ ...now.route.dataset.hamurPoliteness ? { politeness: now.route.dataset.hamurPoliteness } : {}
203
+ });
204
+ if (now.polite)
205
+ now.polite.textContent = pageStore.get().regions.polite;
206
+ if (now.assertive)
207
+ now.assertive.textContent = pageStore.get().regions.assertive;
208
+ };
209
+ render();
210
+ if (driven.stop)
211
+ return;
212
+ const stops = [routeStore.subscribe(render), pageStore.subscribe(render)];
213
+ driven.stop = () => stops.forEach((stop) => stop());
214
+ }
215
+ function swapClientOnly(root) {
216
+ for (let templates = root.querySelectorAll(CLIENT_TEMPLATE);templates.length; templates = root.querySelectorAll(CLIENT_TEMPLATE)) {
217
+ for (const template of templates) {
218
+ for (let node = template.previousSibling;node; node = template.previousSibling) {
219
+ const marker = node.nodeType === COMMENT;
220
+ const data = marker ? node.data : "";
221
+ node.remove();
222
+ if (marker && data === CLIENT_MARKERS[0])
223
+ break;
224
+ }
225
+ template.replaceWith(template.content);
226
+ }
227
+ }
228
+ }
229
+ async function hydrate(ctx) {
230
+ await setAdapterInstance(ctx.app, null);
231
+ const watch = devHydration.watch?.(ctx.root, swapClientOnly);
232
+ ctx.app?.hooks?.hookOnce("app:mounted", () => swapClientOnly(ctx.root));
233
+ warnKeepAlive(ctx);
234
+ setRepaint(() => paint(ctx));
235
+ if (undefined)
236
+ ;
237
+ const data = ctx.payload.data;
238
+ const rendered = data?.$deferred === true || Object.keys(data?.$async ?? {}).length > 0 || ctx.app?.state?.get(RERUN_STATE_KEY) === true || ctx.root.querySelector(`a[${LINK_STATE_ATTRIBUTE}]`);
239
+ takeIndicatorRendered();
240
+ takeAnnouncerRendered();
241
+ releaseAnnouncerClaims();
242
+ if (rendered || watch) {
243
+ const out = renderOut();
244
+ const html = renderTree(ctx, entries, false, out);
245
+ if (data?.$deferred !== true)
246
+ watch?.done(html);
247
+ if (out.linkStates.size)
248
+ keepLinkStates(ctx.root, out.linkStates);
249
+ }
250
+ setCurrent(ctx);
251
+ if (takeIndicatorRendered() || !rendered && ctx.root.querySelector(INDICATOR))
252
+ driveLoadingIndicators(ctx);
253
+ if (takeAnnouncerRendered() || !rendered && ctx.root.querySelector(ANNOUNCER))
254
+ driveAnnouncers(ctx);
255
+ }
256
+ async function mount(ctx) {
257
+ await setAdapterInstance(ctx.app, null);
258
+ warnKeepAlive(ctx);
259
+ paint(ctx);
260
+ setCurrent(ctx);
261
+ }
262
+ function update(ctx) {
263
+ warnKeepAlive(ctx);
264
+ paint(ctx, ctx.tree.components.at(-1)?.pending !== true);
265
+ setCurrent(ctx);
266
+ }
267
+ function findComment(parent, data) {
268
+ for (const node of Array.from(parent.childNodes)) {
269
+ if (node.nodeType === COMMENT && node.data === data)
270
+ return node;
271
+ const inner = node.nodeType === ELEMENT ? findComment(node, data) : undefined;
272
+ if (inner)
273
+ return inner;
274
+ }
275
+ return;
276
+ }
277
+ function between(root, [open, close]) {
278
+ const start = findComment(root, open);
279
+ const found = [];
280
+ for (let node = start?.nextSibling ?? null;node; node = node.nextSibling) {
281
+ if (node.nodeType === COMMENT && node.data === close)
282
+ return found;
283
+ if (node.nodeType === ELEMENT)
284
+ found.push(node);
285
+ }
286
+ return [];
287
+ }
288
+ function transitionTargets(ctx) {
289
+ return { page: between(ctx.root, PAGE_MARKERS), layout: between(ctx.root, LAYOUT_MARKERS) };
290
+ }
291
+ var shown = new WeakMap;
292
+ function serverComponent(name) {
293
+ return (props = {}) => {
294
+ const state = currentState();
295
+ if (!state)
296
+ throw new Error(`${name}.server must be rendered inside a Hamur app`);
297
+ const { app } = state;
298
+ const text = isPage(name) ? "" : serverComponentProps(name, props);
299
+ const uid = serverComponentId(name, text);
300
+ let kept = shown.get(app);
301
+ if (!kept)
302
+ shown.set(app, kept = new Map);
303
+ const key = `${name}\x00${text}`;
304
+ let entry = kept.get(key);
305
+ if (!entry || isPage(name)) {
306
+ const html = takeServerHTML(app, uid, name);
307
+ if (html !== undefined)
308
+ kept.set(key, entry = { view: { html } });
309
+ }
310
+ if (!entry) {
311
+ kept.set(key, "loading");
312
+ fetchServerComponent(app, name, text).then((view) => kept.set(key, { view }), (error) => kept.set(key, { error })).then(repaintPage);
313
+ return serverComponentHTML(name, uid, "");
314
+ }
315
+ if (entry === "loading")
316
+ return serverComponentHTML(name, uid, "");
317
+ if ("error" in entry)
318
+ throw entry.error;
319
+ if (entry.view.head)
320
+ state.entries?.push(state.head.push(entry.view.head));
321
+ return serverComponentHTML(name, uid, String(entry.view.html));
322
+ };
323
+ }
324
+ export {
325
+ hydrate,
326
+ mount,
327
+ serverComponent,
328
+ transitionTargets,
329
+ update
330
+ };
@@ -0,0 +1,40 @@
1
+ // packages/adapter-html/src/runtime/island.ts
2
+ import { setServerHTML } from "hamur/adapter";
3
+ var cleanups = new WeakMap;
4
+ var components = new WeakMap;
5
+ function start(el, component, props) {
6
+ components.set(el, component);
7
+ const cleanup = component.hydrate(el, props);
8
+ if (typeof cleanup === "function")
9
+ cleanups.set(el, cleanup);
10
+ }
11
+ function hydrateIsland(el, component, props, _ctx) {
12
+ start(el, component, props);
13
+ }
14
+ function mountIsland(el, component, props, _ctx) {
15
+ el.replaceChildren();
16
+ setServerHTML(el, component.render(props));
17
+ start(el, component, props);
18
+ }
19
+ function unmountIsland(el) {
20
+ cleanups.get(el)?.();
21
+ cleanups.delete(el);
22
+ components.delete(el);
23
+ }
24
+ function updateIsland(el, props) {
25
+ const component = components.get(el);
26
+ if (!component)
27
+ return;
28
+ if (component.update)
29
+ return component.update(el, props);
30
+ cleanups.get(el)?.();
31
+ cleanups.delete(el);
32
+ setServerHTML(el, component.render(props));
33
+ start(el, component, props);
34
+ }
35
+ export {
36
+ hydrateIsland,
37
+ mountIsland,
38
+ unmountIsland,
39
+ updateIsland
40
+ };
@@ -0,0 +1,59 @@
1
+ import {
2
+ renderTree
3
+ } from "../../chunks/browser-index-qx74bd1y.js";
4
+ import {
5
+ lazyModules,
6
+ collectingIslands,
7
+ islandsSettled,
8
+ renderSettled,
9
+ inIslandRoot
10
+ } from "../../chunks/browser-index-2h1699xv.js";
11
+ import {
12
+ serverComponentId,
13
+ isPage,
14
+ serverComponentHTML
15
+ } from "../../chunks/browser-index-n6x04zrf.js";
16
+
17
+ // packages/adapter-html/src/runtime/server.ts
18
+ import { renderInPasses, serverComponentProps, setAdapterInstance } from "hamur/adapter";
19
+ async function render(ctx) {
20
+ await setAdapterInstance(ctx.app, null);
21
+ return renderInPasses({
22
+ app: ctx.app,
23
+ head: ctx.head,
24
+ render: async (head) => {
25
+ await lazyModules();
26
+ const deferred = [];
27
+ const pending = [];
28
+ const body = collectingIslands(pending, () => renderTree({ ...ctx, head }, undefined, false, { deferred }));
29
+ await islandsSettled(ctx.app, pending);
30
+ return deferred.length ? { body, deferred } : { body };
31
+ }
32
+ });
33
+ }
34
+ async function renderComponent(component, props, ctx) {
35
+ const render = typeof component === "function" ? component : component?.render;
36
+ if (typeof render !== "function")
37
+ throw new TypeError("renderComponent of the html adapter takes a function returning a string, or an object with a render function");
38
+ const html = await renderSettled(() => {
39
+ const out = inIslandRoot(ctx, () => render.call(component, props));
40
+ if (typeof out !== "string")
41
+ throw new TypeError("renderComponent of the html adapter: the component must return a string");
42
+ return out;
43
+ });
44
+ return { html };
45
+ }
46
+ function serverComponent(name, component) {
47
+ return (props = {}) => {
48
+ const text = isPage(name) ? "" : serverComponentProps(name, props);
49
+ const output = component(props);
50
+ if (typeof output !== "string")
51
+ throw new TypeError(`"${name}" must return a string`);
52
+ return serverComponentHTML(name, serverComponentId(name, text), output);
53
+ };
54
+ }
55
+ export {
56
+ render,
57
+ renderComponent,
58
+ serverComponent
59
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("hamur/adapter").Adapter;
2
+ export default _default;
@@ -0,0 +1,13 @@
1
+ import type { AppContext, AsyncDataOptions, FetchOptions } from "hamur/app";
2
+ import type { AsyncDataHandler, FetchRequest, GetCachedData, GetCachedDataCause, HandlerReference } from "hamur/adapter";
3
+ export declare const valueOf: <T>(value: T | (() => T)) => T;
4
+ export declare function requestOf({ query, body, ...rest }: FetchRequest): FetchOptions;
5
+ /** The restored payload entry's data while the app hydrates, else `undefined`. */
6
+ export declare function defaultGetCachedData<T>(key: string, app: AppContext): T | undefined;
7
+ /** `refresh()`, `execute()` and a `watch` change: ask `getCachedData` with their cause, run `handler` when it has nothing. */
8
+ export declare function refreshCached<T, R>(app: AppContext, key: string, handler: AsyncDataHandler<R>, options: AsyncDataOptions<T, R>, getCachedData: GetCachedData<T>, cause: GetCachedDataCause): Promise<void>;
9
+ export declare function keepCached<T>(app: AppContext, key: string, getCachedData: GetCachedData<T>): void;
10
+ /** The run's signal, combined with a `signal` the caller gave to `useFetch`. */
11
+ export declare const signalOf: (own: AbortSignal | undefined, run: AbortSignal) => AbortSignal;
12
+ /** The call of `useAsyncData(fn, input)`: in process with the request's event on the server, through the stub in the browser. */
13
+ export declare const callHandler: <R>(app: AppContext, fn: HandlerReference, input: unknown) => AsyncDataHandler<R>;
@@ -0,0 +1,109 @@
1
+ import type { AppContext, ErrorPageProps, Head, HeadEntry, HeadInput, RouteLocation } from "hamur/app";
2
+ import type { ClientContext, Navigation, NavigationState, RenderContext, RenderResult, RenderTree, RouteValue, RouterApi } from "hamur/adapter";
3
+ import { type RouterSource } from "hamur/adapter";
4
+ /** The app state key a server render sets to ask `hydrate` to run the page again: a composable that must act in the browser (`useSyncedState` opens its socket, `usePwa` attaches its listener) sets it. */
5
+ export declare const RERUN_STATE_KEY = "hamur:rerun";
6
+ /** The inner level of a layout. It renders when it is turned into text: use `${children}` or `String(children)` before you compare it or test it for emptiness. */
7
+ export interface HtmlChildren {
8
+ toString(): string;
9
+ valueOf(): string;
10
+ toJSON(): string;
11
+ }
12
+ export interface HtmlProps extends Record<string, unknown> {
13
+ route: RouteValue;
14
+ children?: string | HtmlChildren;
15
+ error?: RenderTree["error"];
16
+ }
17
+ export type HtmlComponent = (props: HtmlProps) => string;
18
+ type TreeContext = Pick<RenderContext | ClientContext, "route" | "tree"> & Pick<RenderContext | ClientContext, "app" | "head"> & Partial<Pick<RenderContext | ClientContext, "payload" | "baseURL">> & Pick<RenderContext | ClientContext, "href"> & {
19
+ navigator?: object;
20
+ };
21
+ /** A component's head input, pushed once its level rendered; `server` for `useServerHead`. */
22
+ export interface HeadPending {
23
+ input: HeadInput;
24
+ options?: {
25
+ server: true;
26
+ };
27
+ }
28
+ interface Current {
29
+ route: RouteValue;
30
+ data: Record<string, unknown>;
31
+ handlerState?: unknown;
32
+ tree: RenderTree;
33
+ head: Head;
34
+ entries?: HeadEntry[];
35
+ completesNavigation?: boolean;
36
+ pending?: HeadPending[];
37
+ navigator?: {
38
+ get?(): NavigationState;
39
+ } & Partial<RouterApi>;
40
+ baseURL: string;
41
+ href: RenderContext["href"];
42
+ app: AppContext;
43
+ id?: string;
44
+ /** The error of the route boundary being rendered, read by `useError()`. */
45
+ boundaryError?: ErrorPageProps;
46
+ outlet?: () => string;
47
+ /** The slots of the entry being rendered, each rendered once when its `Outlet({ name })` asks. */
48
+ slots?: Record<string, () => string>;
49
+ /** The `context` of the nearest `Outlet({ context })` being rendered, read by `useOutletContext()`. */
50
+ outletValue?: unknown;
51
+ /** The `state` of each `Link` this render wrote, by `linkStateKey`. */
52
+ linkStates?: Map<string, LinkEntry>;
53
+ /** The removers of what this client render registered (guards, blockers, snapshots); they run before the next paint. */
54
+ scoped?: Array<() => void>;
55
+ /** The placeholders of a streamed server render, whose values the core renders when they settle. */
56
+ deferred?: DeferredPart[];
57
+ /** Shared by the copies `renderIn` makes, so a deferred part continues the ids of the page. */
58
+ ids: {
59
+ next: number;
60
+ };
61
+ }
62
+ export type DeferredPart = NonNullable<RenderResult["deferred"]>[number];
63
+ /** What a render collects: a client render for the paint that follows it, a streamed server render its deferred parts. */
64
+ export interface RenderOut {
65
+ linkStates?: Map<string, LinkEntry>;
66
+ scoped?: Array<() => void>;
67
+ deferred?: DeferredPart[];
68
+ }
69
+ /** What a `Link` keeps for its anchor: its history `state` and its `onBeforeNavigate` handler. */
70
+ export interface LinkEntry {
71
+ state?: Record<string, unknown>;
72
+ onBeforeNavigate?: (nav: Navigation) => void;
73
+ }
74
+ /** The occurrence of a `Link`'s `href` among the links with a `state` or an `onBeforeNavigate` of the render that wrote it; the client entry hands the state to `setLinkState` and removes the attribute. */
75
+ export declare const LINK_STATE_ATTRIBUTE = "data-hamur-link";
76
+ export declare const linkStateKey: (href: string, occurrence: string | number) => string;
77
+ export declare const PAGE_MARKERS: readonly ["hamur-page", "/hamur-page"];
78
+ export declare const LAYOUT_MARKERS: readonly ["hamur-layout", "/hamur-layout"];
79
+ export declare const CLIENT_MARKERS: readonly ["hamur-client", "/hamur-client"];
80
+ export declare const CLIENT_TEMPLATE = "template[data-hamur-client]";
81
+ export declare function setRepaint(next: (() => void) | undefined): void;
82
+ export declare function repaintPage(): void;
83
+ export declare function paintCount(): number;
84
+ /** Paints again for data that settled after paint `count` unless another paint came since; its composables reuse their entries. */
85
+ export declare function repaintWithData(count: number): void;
86
+ export declare function isRepaintingWithData(): boolean;
87
+ export declare function routerOf(navigator: unknown, baseURL?: string, page?: Omit<RouterSource, "navigator" | "baseURL">): RouterApi;
88
+ export declare function detachedHref(to: string | RouteLocation): string;
89
+ /** Set by `LoadingIndicator()`; the runtime paints indicators only after a render that wrote one. */
90
+ export declare function markIndicatorRendered(): void;
91
+ export declare function takeIndicatorRendered(): boolean;
92
+ /** Set by `RouteAnnouncer()` and `Announcer()`; the runtime binds the regions only after a render that wrote one. */
93
+ export declare function markAnnouncerRendered(): void;
94
+ export declare function takeAnnouncerRendered(): boolean;
95
+ /** html has no unmount: every paint starts by releasing the `RouteAnnouncer` claims of the one before. */
96
+ export declare function keepAnnouncerClaim(release: () => void): void;
97
+ export declare function releaseAnnouncerClaims(): void;
98
+ /** Binds the loading indicator of `app` to `navigator` for the life of the app; html has no component lifecycle to remove it from. */
99
+ export declare function followNavigation(app: AppContext, navigator: unknown): void;
100
+ export declare function currentState(): Current | undefined;
101
+ export declare function currentRoute(): RouteValue | undefined;
102
+ export declare function setCurrent(ctx: TreeContext | undefined): void;
103
+ /** Runs `render` in a copy of `state` taken during a render that has ended; it collects no deferred parts of its own. */
104
+ export declare function renderIn<T>(state: Current, render: () => T): T;
105
+ export declare function routeValue(ctx: Pick<RenderContext, "route"> & Partial<Pick<RenderContext, "app" | "payload" | "tree">>): RouteValue;
106
+ /** Renders a lazy `children` into its string; any other value comes back as given. */
107
+ export declare function settle(value: string | HtmlChildren): string;
108
+ export declare function renderTree(ctx: TreeContext, entries?: HeadEntry[], completesNavigation?: boolean, out?: RenderOut): string;
109
+ export {};
@@ -0,0 +1 @@
1
+ export { DefaultErrorPage as default } from "./index.ts";