@hamur/adapter-html 0.0.0-stage → 0.0.1

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 +44 -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
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 productdevbook
4
+ Copyright (c) 2019 Material-UI SAS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @hamur/adapter-html
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The plain HTML adapter for [Hamur](https://github.com/productdevbook/hamur), a full-stack web framework for Bun. A page is a function that returns a string; there is no client library. It gives you `useData`, `useHead`, `useState` and the other hooks. Routing, loaders, head, state and the server come from `hamur`.
4
+
5
+ One app uses one library. Set `framework: "html"` in `hamur.config.ts`, or install only this adapter and Hamur detects it.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ bun add hamur @hamur/adapter-html
11
+ ```
12
+
13
+ Or start from a template: `bunx hamur init my-app --framework html`.
14
+
15
+ ## Example
16
+
17
+ `app/pages/index.ts`. Escape every value you put in the string:
18
+
19
+ ```ts
20
+ import { useHead, useRoute } from "@hamur/adapter-html"
21
+
22
+ const escape = (value: unknown) => String(value).replace(/[&<>"']/g, (char) => `&#${char.charCodeAt(0)};`)
23
+
24
+ export default function Home(): string {
25
+ useHead({ title: "Home" })
26
+ return `<h1>Route: ${escape(useRoute().path)}</h1>`
27
+ }
28
+ ```
29
+
30
+ ## Docs
31
+
32
+ [Documentation](https://docs.productdevbook.com/) and the [adapters page](https://docs.productdevbook.com/adapters). MIT license.
@@ -0,0 +1,148 @@
1
+ import {
2
+ repaintPage,
3
+ currentState
4
+ } from "./browser-index-qx74bd1y.js";
5
+
6
+ // packages/adapter-html/src/lazy-hydration.ts
7
+ import { hydrateOnAttribute, hydrateWrapper, markWaiting } from "hamur/adapter";
8
+ var isServer = typeof document === "undefined";
9
+ var pending = new Set;
10
+ function lazyModules() {
11
+ return pending.size ? Promise.allSettled(pending) : undefined;
12
+ }
13
+ function defineLazyHydrationComponent2(on, loader, options) {
14
+ hydrateOnAttribute(on);
15
+ let resolved;
16
+ let failed;
17
+ let loading;
18
+ const load = () => {
19
+ if (loading)
20
+ return loading;
21
+ const current = loading = loader().then((loaded) => resolved = loaded, (error) => {
22
+ if (isServer)
23
+ failed = { error };
24
+ loading = undefined;
25
+ throw error;
26
+ });
27
+ if (isServer) {
28
+ pending.add(current);
29
+ current.then(() => pending.delete(current), () => pending.delete(current));
30
+ }
31
+ return current;
32
+ };
33
+ if (isServer)
34
+ load().catch(() => {});
35
+ return ({ onHydrated: _, ...props }) => {
36
+ if (resolved)
37
+ return hydrateWrapper(on, resolved.default(props));
38
+ if (failed)
39
+ throw failed.error;
40
+ const promise = load();
41
+ if (isServer) {
42
+ const app = currentState()?.app;
43
+ if (app)
44
+ markWaiting(app.asyncData);
45
+ promise.catch(() => {});
46
+ } else
47
+ promise.then(repaintPage, () => {});
48
+ return hydrateWrapper(on, "");
49
+ };
50
+ }
51
+
52
+ // packages/adapter-html/src/island.ts
53
+ import {
54
+ ISLAND_ELEMENT,
55
+ SERVER_ISLAND_ELEMENT,
56
+ renderIsland,
57
+ renderServerIsland,
58
+ serverIslandProps
59
+ } from "hamur/adapter";
60
+
61
+ // packages/adapter-html/src/island-html.ts
62
+ import { markWaiting as markWaiting2 } from "hamur/adapter";
63
+ var outcomes = new WeakMap;
64
+ var current;
65
+ function settledIsland(promise, pending = current) {
66
+ const outcome = outcomes.get(promise);
67
+ if (outcome) {
68
+ if ("error" in outcome)
69
+ throw outcome.error;
70
+ return outcome.value;
71
+ }
72
+ pending?.push(promise.then((value) => void outcomes.set(promise, { value }), (error) => void outcomes.set(promise, { error })));
73
+ return;
74
+ }
75
+ function collectingIslands(pending, render) {
76
+ const outer = current;
77
+ current = pending;
78
+ try {
79
+ return render();
80
+ } finally {
81
+ current = outer;
82
+ }
83
+ }
84
+ async function islandsSettled(app, pending) {
85
+ if (!pending.length)
86
+ return;
87
+ await Promise.all(pending);
88
+ markWaiting2(app.asyncData);
89
+ }
90
+ async function renderSettled(render) {
91
+ for (;; ) {
92
+ const pending = [];
93
+ const result = await collectingIslands(pending, () => render(pending));
94
+ if (!pending.length)
95
+ return result;
96
+ await Promise.all(pending);
97
+ }
98
+ }
99
+
100
+ // packages/adapter-html/src/island.ts
101
+ var ESCAPES = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" };
102
+ var counters = new WeakMap;
103
+ var scope;
104
+ function pageId(ids) {
105
+ const next = counters.get(ids) ?? 0;
106
+ counters.set(ids, next + 1);
107
+ return String(next);
108
+ }
109
+ function defineIsland2(island) {
110
+ return island;
111
+ }
112
+ function inIslandRoot(ctx, render) {
113
+ const outer = scope;
114
+ scope = ctx ? { app: ctx.app, prefix: ctx.idPrefix, next: 0 } : outer;
115
+ try {
116
+ return render();
117
+ } finally {
118
+ scope = outer;
119
+ }
120
+ }
121
+ function target(caller) {
122
+ const state = scope ? undefined : currentState();
123
+ const app = scope?.app ?? state?.app;
124
+ if (!app)
125
+ throw new Error(`${caller}() must be called inside a Hamur app`);
126
+ return { app, id: scope ? `${scope.prefix}.${scope.next++}` : pageId(state.ids) };
127
+ }
128
+ var attributesOf = (attributes) => Object.entries(attributes).map(([name, value]) => value === "" ? ` ${name}` : ` ${name}="${value.replace(/[&<>"]/g, (char) => ESCAPES[char])}"`).join("");
129
+ function island2(component, props, options = {}) {
130
+ const { app, id } = target("island");
131
+ const rendered = renderIsland(app, id, component, props ?? {}, options.on, undefined, options);
132
+ const body = rendered.html ? settledIsland(rendered.html) ?? "" : options.fallback ?? "";
133
+ return `<${ISLAND_ELEMENT}${attributesOf(rendered.attributes)}>${body}</${ISLAND_ELEMENT}>`;
134
+ }
135
+ function serverIsland2(name, props = {}, options = {}) {
136
+ const fallback = options.fallback ?? "";
137
+ if (typeof document !== "undefined") {
138
+ const attributes = { name };
139
+ if (Object.keys(props).length)
140
+ attributes.props = serverIslandProps(name, props);
141
+ return `<${SERVER_ISLAND_ELEMENT}${attributesOf(attributes)}>${fallback}</${SERVER_ISLAND_ELEMENT}>`;
142
+ }
143
+ const { app, id } = target("serverIsland");
144
+ const attributes = settledIsland(renderServerIsland(app, id, name, props).attributes) ?? {};
145
+ return `<${SERVER_ISLAND_ELEMENT}${attributesOf(attributes)}>${fallback}</${SERVER_ISLAND_ELEMENT}>`;
146
+ }
147
+
148
+ export { lazyModules, defineLazyHydrationComponent2, collectingIslands, islandsSettled, renderSettled, defineIsland2, inIslandRoot, island2, serverIsland2 };
@@ -0,0 +1,28 @@
1
+ import {
2
+ currentState
3
+ } from "./browser-index-qx74bd1y.js";
4
+
5
+ // packages/adapter-html/src/server-component.ts
6
+ import { serverComponentAttributes } from "hamur/adapter";
7
+ var counts = new WeakMap;
8
+ var outside = {};
9
+ var escape = (text) => text.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
10
+ function hashOf(text) {
11
+ let hash = 2166136261;
12
+ for (let i = 0;i < text.length; i++)
13
+ hash = Math.imul(hash ^ text.charCodeAt(i), 16777619);
14
+ return (hash >>> 0).toString(36);
15
+ }
16
+ function serverComponentId(name, text) {
17
+ const render = currentState() ?? outside;
18
+ const count = counts.get(render) ?? 0;
19
+ counts.set(render, count + 1);
20
+ return `c${count}-${hashOf(`${name}\x00${text}`)}`;
21
+ }
22
+ var isPage = (name) => name.startsWith("page:");
23
+ function serverComponentHTML(name, uid, html) {
24
+ const attributes = Object.entries(serverComponentAttributes(name)).map(([key, value]) => ` ${key}="${escape(value)}"`).join("");
25
+ return `<hamur-component name="${escape(name)}" uid="${uid}"${attributes}>${html}</hamur-component>`;
26
+ }
27
+
28
+ export { serverComponentId, isPage, serverComponentHTML };
@@ -0,0 +1,4 @@
1
+ // packages/adapter-html/src/runtime/hydration.ts
2
+ var devHydration = {};
3
+
4
+ export { devHydration };
@@ -0,0 +1,302 @@
1
+ // packages/adapter-html/src/context.ts
2
+ import { withBase } from "hamur/app";
3
+ import {
4
+ APP_ROOT_ID,
5
+ createLoadingIndicator,
6
+ createRouterApi,
7
+ routeBoundary
8
+ } from "hamur/adapter";
9
+ import { routeStateOf } from "hamur/adapter";
10
+ var RERUN_STATE_KEY = "hamur:rerun";
11
+ var LINK_STATE_ATTRIBUTE = "data-hamur-link";
12
+ var linkStateKey = (href, occurrence) => `${href} ${occurrence}`;
13
+ var PAGE_MARKERS = ["hamur-page", "/hamur-page"];
14
+ var LAYOUT_MARKERS = ["hamur-layout", "/hamur-layout"];
15
+ var CLIENT_MARKERS = ["hamur-client", "/hamur-client"];
16
+ var CLIENT_TEMPLATE = "template[data-hamur-client]";
17
+ var wrap = (markers, html) => `<!--${markers[0]}-->${html}<!--${markers[1]}-->`;
18
+ var isLayoutEntry = (id) => id === APP_ROOT_ID || id.startsWith("layout:");
19
+ function markedEntries(components) {
20
+ const layout = components.findIndex((entry) => entry.id.startsWith("layout:"));
21
+ return {
22
+ layout: layout >= 0 ? layout : components.findIndex((entry) => entry.id === APP_ROOT_ID),
23
+ page: components.findLastIndex((entry) => !isLayoutEntry(entry.id))
24
+ };
25
+ }
26
+ var current;
27
+ var repaint;
28
+ var paints = 0;
29
+ var keepingData = false;
30
+ function setRepaint(next) {
31
+ repaint = next;
32
+ paints++;
33
+ }
34
+ function repaintPage() {
35
+ repaint?.();
36
+ }
37
+ function paintCount() {
38
+ return paints;
39
+ }
40
+ function repaintWithData(count) {
41
+ if (count !== paints || !repaint)
42
+ return;
43
+ keepingData = true;
44
+ try {
45
+ repaint();
46
+ } finally {
47
+ keepingData = false;
48
+ }
49
+ }
50
+ function isRepaintingWithData() {
51
+ return keepingData;
52
+ }
53
+ function routerOf(navigator, baseURL = "/", page) {
54
+ return createRouterApi({
55
+ ...page,
56
+ navigator,
57
+ baseURL,
58
+ unavailable: () => new Error("useRouter() navigates only in the browser")
59
+ });
60
+ }
61
+ function currentOf(ctx) {
62
+ return {
63
+ route: routeValue(ctx),
64
+ data: ctx.payload?.data ?? {},
65
+ handlerState: ctx.payload?.handlerState,
66
+ tree: ctx.tree,
67
+ head: ctx.head,
68
+ app: ctx.app,
69
+ baseURL: ctx.baseURL ?? "/",
70
+ href: ctx.href,
71
+ ids: { next: 0 },
72
+ ...ctx.navigator ? { navigator: ctx.navigator } : {}
73
+ };
74
+ }
75
+ function detachedHref(to) {
76
+ if (typeof to !== "string")
77
+ throw new Error(`Link to the route "${to.name}" must be rendered inside a Hamur app`);
78
+ return withBase(to, "/");
79
+ }
80
+ var indicatorRendered = false;
81
+ function markIndicatorRendered() {
82
+ indicatorRendered = true;
83
+ }
84
+ function takeIndicatorRendered() {
85
+ const rendered = indicatorRendered;
86
+ indicatorRendered = false;
87
+ return rendered;
88
+ }
89
+ var announcerRendered = false;
90
+ function markAnnouncerRendered() {
91
+ announcerRendered = true;
92
+ }
93
+ function takeAnnouncerRendered() {
94
+ const rendered = announcerRendered;
95
+ announcerRendered = false;
96
+ return rendered;
97
+ }
98
+ var announcerClaims = [];
99
+ function keepAnnouncerClaim(release) {
100
+ announcerClaims.push(release);
101
+ }
102
+ function releaseAnnouncerClaims() {
103
+ const releases = announcerClaims;
104
+ announcerClaims = [];
105
+ for (const release of releases)
106
+ release();
107
+ }
108
+ var followed = new WeakSet;
109
+ function followNavigation(app, navigator) {
110
+ const source = navigator;
111
+ if (followed.has(app) || typeof source?.get !== "function" || typeof source.subscribe !== "function")
112
+ return;
113
+ followed.add(app);
114
+ createLoadingIndicator(app).follow(source);
115
+ }
116
+ function currentState() {
117
+ return current;
118
+ }
119
+ function currentRoute() {
120
+ return current?.route;
121
+ }
122
+ function setCurrent(ctx) {
123
+ current = ctx ? currentOf(ctx) : undefined;
124
+ }
125
+ function renderIn(state, render) {
126
+ const previous = current;
127
+ current = { ...state, deferred: undefined };
128
+ try {
129
+ return render();
130
+ } finally {
131
+ current = previous;
132
+ }
133
+ }
134
+ function routeValue(ctx) {
135
+ const { route } = ctx;
136
+ return {
137
+ path: route.path,
138
+ fullPath: route.fullPath,
139
+ params: route.params,
140
+ query: route.query,
141
+ search: route.search,
142
+ hash: route.hash,
143
+ name: route.name,
144
+ meta: route.meta,
145
+ matched: route.matched,
146
+ groups: route.groups ?? [],
147
+ ...routeStateOf(ctx)
148
+ };
149
+ }
150
+ var rethrown = new WeakSet;
151
+ var lazyStrings = new WeakSet;
152
+ function lazyString(render) {
153
+ const proxy = new Proxy(new String(""), {
154
+ get(_, key) {
155
+ if (key === Symbol.toPrimitive || key === "toJSON")
156
+ return () => render();
157
+ const text = render();
158
+ const value = Reflect.get(Object(text), key);
159
+ return typeof value === "function" ? value.bind(text) : value;
160
+ }
161
+ });
162
+ lazyStrings.add(proxy);
163
+ return proxy;
164
+ }
165
+ function settle(value) {
166
+ return lazyStrings.has(value) ? String(value) : value;
167
+ }
168
+ function renderTree(ctx, entries, completesNavigation = false, out) {
169
+ const previous = current;
170
+ const state = currentOf(ctx);
171
+ if (out?.linkStates)
172
+ state.linkStates = out.linkStates;
173
+ if (out?.scoped)
174
+ state.scoped = out.scoped;
175
+ if (out?.deferred)
176
+ state.deferred = out.deferred;
177
+ state.entries = entries;
178
+ if (completesNavigation)
179
+ state.completesNavigation = true;
180
+ current = state;
181
+ try {
182
+ const chains = [];
183
+ const once = (render) => {
184
+ let outcome;
185
+ return () => {
186
+ if (!outcome) {
187
+ try {
188
+ outcome = { value: render() };
189
+ } catch (error) {
190
+ outcome = { error };
191
+ }
192
+ }
193
+ if ("error" in outcome)
194
+ throw outcome.error;
195
+ return outcome.value;
196
+ };
197
+ };
198
+ const intercepted = (tree, render) => {
199
+ if (!tree.route)
200
+ return render();
201
+ const page = state.route;
202
+ const { state: entry, key, navigationType } = page;
203
+ state.route = routeValue({ ...ctx, route: { ...tree.route, state: entry, key, navigationType }, tree });
204
+ try {
205
+ return render();
206
+ } finally {
207
+ state.route = page;
208
+ }
209
+ };
210
+ const chain = (components, marked = false) => {
211
+ const markers = marked ? markedEntries(components) : undefined;
212
+ const perComponent = [];
213
+ chains.push(perComponent);
214
+ const renderEntry = (index, { id, component, props, caught, outlets }, leaf = false) => {
215
+ const input = { ...props, route: state.route };
216
+ let inner;
217
+ if (!leaf && index + 1 < components.length) {
218
+ inner = once(() => renderLevel(index + 1));
219
+ input.children = lazyString(inner);
220
+ }
221
+ if (ctx.tree.error)
222
+ input.error = ctx.tree.error;
223
+ const slots = outlets && Object.fromEntries(Object.entries(outlets).map(([name, tree]) => [
224
+ name,
225
+ once(() => intercepted(tree, () => tree.components.length ? chain(tree.components)(0) : ""))
226
+ ]));
227
+ const outer = {
228
+ id: state.id,
229
+ outlet: state.outlet,
230
+ slots: state.slots,
231
+ pending: state.pending,
232
+ boundaryError: state.boundaryError
233
+ };
234
+ state.id = id;
235
+ state.outlet = inner;
236
+ state.slots = slots;
237
+ state.pending = perComponent[index] = [];
238
+ if (caught)
239
+ state.boundaryError = props?.error;
240
+ try {
241
+ const output = settle(component(input));
242
+ if (typeof output !== "string")
243
+ throw new TypeError(`"${id}" must return a string`);
244
+ if (index === markers?.page)
245
+ return wrap(PAGE_MARKERS, output);
246
+ if (index === markers?.layout)
247
+ return wrap(LAYOUT_MARKERS, output);
248
+ return output;
249
+ } catch (error) {
250
+ for (let level = index;level < components.length; level++)
251
+ perComponent[level] = [];
252
+ if (caught && typeof error === "object" && error !== null)
253
+ rethrown.add(error);
254
+ throw error;
255
+ } finally {
256
+ state.id = outer.id;
257
+ state.outlet = outer.outlet;
258
+ state.slots = outer.slots;
259
+ state.pending = outer.pending;
260
+ state.boundaryError = outer.boundaryError;
261
+ }
262
+ };
263
+ const renderLevel = (index) => {
264
+ const entry = components[index];
265
+ if (!entry.boundary)
266
+ return renderEntry(index, entry);
267
+ try {
268
+ return renderEntry(index, entry);
269
+ } catch (error) {
270
+ if (typeof error === "object" && error !== null && rethrown.has(error))
271
+ throw error;
272
+ const caught = routeBoundary(ctx, entry, error);
273
+ if (!caught)
274
+ throw error;
275
+ const clearError = (options) => state.app.error?.clear(options) ?? Promise.resolve();
276
+ return renderEntry(index, {
277
+ id: caught.id,
278
+ caught: caught.caught,
279
+ component: caught.component,
280
+ props: { error: caught.error, clearError }
281
+ }, true);
282
+ }
283
+ };
284
+ return renderLevel;
285
+ };
286
+ const rendered = ctx.tree.components.length ? chain(ctx.tree.components, true)(0) : "";
287
+ state.pending = undefined;
288
+ for (const perComponent of chains) {
289
+ for (const inputs of perComponent) {
290
+ for (const { input, options } of inputs ?? []) {
291
+ const entry = state.head.push(input, options);
292
+ entries?.push(entry);
293
+ }
294
+ }
295
+ }
296
+ return rendered;
297
+ } finally {
298
+ current = previous;
299
+ }
300
+ }
301
+
302
+ export { RERUN_STATE_KEY, LINK_STATE_ATTRIBUTE, linkStateKey, PAGE_MARKERS, LAYOUT_MARKERS, CLIENT_MARKERS, CLIENT_TEMPLATE, setRepaint, repaintPage, paintCount, repaintWithData, isRepaintingWithData, routerOf, detachedHref, markIndicatorRendered, takeIndicatorRendered, markAnnouncerRendered, takeAnnouncerRendered, keepAnnouncerClaim, releaseAnnouncerClaims, followNavigation, currentState, currentRoute, setCurrent, renderIn, settle, renderTree };
@@ -0,0 +1,141 @@
1
+ // @bun
2
+ // packages/adapter-html/src/adapter.ts
3
+ import { ADAPTER_CONTRACT, defineAdapter } from "hamur/adapter";
4
+ import { serverComponentModule } from "hamur/adapter/build";
5
+
6
+ // packages/adapter-html/src/plugin.ts
7
+ import { join, relative } from "path";
8
+ import { dropDevOnly } from "hamur/adapter/build";
9
+ var HMR_RUNTIME = join(import.meta.dir + "/../../src", "runtime/hmr.ts");
10
+ var CLIENT_RUNTIME = join(import.meta.dir + "/../../src", "runtime/client.ts");
11
+ var HYDRATION_DEV = join(import.meta.dir + "/../../src", "runtime/hydration-dev.ts");
12
+ var ROUTE_MODULE = /(^|\/)((pages|layouts)\/|app\.[jt]s$)/;
13
+ var DEFAULT_FUNCTION = /^export default function\s+([A-Za-z_$][\w$]*)/m;
14
+ var DEFAULT_ANY = /^export default /m;
15
+ function hotTransform(source, id) {
16
+ if (!DEFAULT_ANY.test(source))
17
+ return source;
18
+ const named = source.match(DEFAULT_FUNCTION)?.[1];
19
+ const body = named ? source.replace(DEFAULT_FUNCTION, `function ${named}`) : source.replace(DEFAULT_ANY, "const __hamurImpl = ");
20
+ return [
21
+ body,
22
+ `import { hot as __hamurHot, rerender as __hamurRerender } from ${JSON.stringify(HMR_RUNTIME)};`,
23
+ `const __hamurDefault = __hamurHot(${JSON.stringify(id)}, ${named ?? "__hamurImpl"});`,
24
+ `export default __hamurDefault;`,
25
+ `if (import.meta.hot) import.meta.hot.accept(() => __hamurRerender());`
26
+ ].join(`
27
+ `);
28
+ }
29
+ function htmlPlugin(ctx) {
30
+ const build = relative(ctx.rootDir, ctx.buildDir);
31
+ return {
32
+ name: `hamur-html-${ctx.target}`,
33
+ filter: { id: /\.[jt]s$/ },
34
+ transform(code, { id: path }) {
35
+ const id = relative(ctx.rootDir, path);
36
+ if (path.includes("/node_modules/") || !ROUTE_MODULE.test(id) || build !== "" && !build.startsWith("..") && id.startsWith(`${build}/`))
37
+ return;
38
+ return hotTransform(code, id);
39
+ }
40
+ };
41
+ }
42
+ function htmlProductionPlugin(ctx) {
43
+ return {
44
+ name: `hamur-html-production-${ctx.target}`,
45
+ filter: { id: /\.[jt]s$/ },
46
+ transform(code, { id }) {
47
+ if (id.includes("/node_modules/"))
48
+ return;
49
+ const contents = dropDevOnly(code, "@hamur/adapter-html", "call");
50
+ return contents === code ? undefined : contents;
51
+ }
52
+ };
53
+ }
54
+ function htmlHydrationPlugin() {
55
+ return {
56
+ name: "hamur-html-hydration",
57
+ filter: { id: new RegExp(`^${CLIENT_RUNTIME.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`) },
58
+ transform: (code) => `import ${JSON.stringify(HYDRATION_DEV)}; ${code}`
59
+ };
60
+ }
61
+
62
+ // packages/adapter-html/src/svg.ts
63
+ import { join as join2 } from "path";
64
+ import { svgCode } from "hamur/adapter";
65
+ var SVG_ID = join2(import.meta.dir + "/../../src", "runtime/svg-id.ts");
66
+ var ESCAPES = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" };
67
+ var escape = (text) => text.replace(/[&<>"]/g, (char) => ESCAPES[char]);
68
+ var literal = (text) => text.replace(/[\\`]|\$\{/g, (found) => `\\${found}`);
69
+ var valueMarkup = (value) => typeof value === "string" ? literal(escape(value)) : value.map((part) => typeof part === "string" ? literal(escape(part)) : `\${uid}-${literal(escape(part.id))}`).join("");
70
+ function nodeMarkup(code, node) {
71
+ if (typeof node === "string" || Array.isArray(node))
72
+ return valueMarkup(node);
73
+ const attributes = Object.entries(code.attrs(node)).map(([name, value]) => ` ${name}="${valueMarkup(value)}"`).join("");
74
+ return `<${node.tag}${attributes}>${node.children.map((child) => nodeMarkup(code, child)).join("")}</${node.tag}>`;
75
+ }
76
+ function module(svg) {
77
+ const code = svgCode(svg, { title: "title", props: "rest" });
78
+ const hidden = code.hidden ? `${code.hidden} ? { "aria-hidden": "true" } : {}` : "{}";
79
+ const contents = `import { svgInstanceId } from ${JSON.stringify(SVG_ID)};
80
+
81
+ const ESCAPES = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" };
82
+ const escape = (value) => String(value).replace(/[&<>"]/g, (char) => ESCAPES[char]);
83
+
84
+ export default function SvgComponent(props = {}) {
85
+ const { title, ...rest } = props;
86
+ const uid = svgInstanceId();
87
+ const attributes = {
88
+ ...${code.props(svg.attrs)},
89
+ ...(${hidden}),
90
+ ...rest,
91
+ };
92
+ let out = "";
93
+ for (const [name, value] of Object.entries(attributes)) {
94
+ if (value === undefined || value === null || value === false) continue;
95
+ out += value === true ? \` \${name}\` : \` \${name}="\${escape(value)}"\`;
96
+ }
97
+ return \`<svg\${out}>\${title == null ? "" : \`<title>\${escape(title)}</title>\`}\` + \`${svg.children.map((child) => nodeMarkup(code, child)).join("")}\` + "</svg>";
98
+ }
99
+ `;
100
+ return { contents, extension: ".js" };
101
+ }
102
+ var svgComponent = {
103
+ types: `(props?: Record<string, string | number | boolean> & { title?: string }) => string`,
104
+ module
105
+ };
106
+
107
+ // packages/adapter-html/src/markdown-page.ts
108
+ import { markdownPageCode } from "hamur/adapter/build";
109
+ function module2(source) {
110
+ const { imports, value, props, head } = markdownPageCode(source);
111
+ const contents = `${imports}import { MarkdownRenderer, useHead } from "@hamur/adapter-html";
112
+
113
+ const value = ${value};
114
+
115
+ export default function MarkdownPage() {
116
+ ${head ? ` useHead(${head});
117
+ ` : ""} return MarkdownRenderer(${props});
118
+ }
119
+ `;
120
+ return { contents, extension: ".js" };
121
+ }
122
+ var markdownComponent = { module: module2 };
123
+
124
+ // packages/adapter-html/src/adapter.ts
125
+ var adapter_default = defineAdapter({
126
+ name: "html",
127
+ contract: ADAPTER_CONTRACT,
128
+ extensions: [".ts", ".js"],
129
+ clientEntry: "@hamur/adapter-html/runtime/client",
130
+ serverEntry: "@hamur/adapter-html/runtime/server",
131
+ islandEntry: "@hamur/adapter-html/runtime/island",
132
+ transforms: (ctx) => ctx.dev ? ctx.target === "client" ? [...ctx.hmr ? [htmlPlugin(ctx)] : [], htmlHydrationPlugin()] : [] : [htmlProductionPlugin(ctx)],
133
+ errorPage: "@hamur/adapter-html/error-page",
134
+ peers: [],
135
+ svgComponent,
136
+ markdownComponent,
137
+ serverComponent: { module: (component) => serverComponentModule(component, "@hamur/adapter-html/runtime") }
138
+ });
139
+ export {
140
+ adapter_default as default
141
+ };