@hamur/adapter-preact 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 (68) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +35 -2
  3. package/dist/chunks/browser-index-89d71ade.js +118 -0
  4. package/dist/chunks/browser-index-ezte15pp.js +67 -0
  5. package/dist/chunks/browser-index-hsy7tnbg.js +21 -0
  6. package/dist/chunks/browser-index-k3m2axbw.js +274 -0
  7. package/dist/src/adapter.js +456 -0
  8. package/dist/src/error-page.js +391 -0
  9. package/dist/src/index.js +1506 -0
  10. package/dist/src/keepalive.js +6 -0
  11. package/dist/src/runtime/client.js +96 -0
  12. package/dist/src/runtime/island.js +33 -0
  13. package/dist/src/runtime/server.js +95 -0
  14. package/dist/types/src/activation.d.ts +15 -0
  15. package/dist/types/src/adapter.d.ts +2 -0
  16. package/dist/types/src/async-data.d.ts +13 -0
  17. package/dist/types/src/client-component.d.ts +11 -0
  18. package/dist/types/src/client-fallback.d.ts +2 -0
  19. package/dist/types/src/context.d.ts +81 -0
  20. package/dist/types/src/error-page.d.ts +1 -0
  21. package/dist/types/src/head.d.ts +5 -0
  22. package/dist/types/src/index.d.ts +429 -0
  23. package/dist/types/src/island-html.d.ts +13 -0
  24. package/dist/types/src/island.d.ts +19 -0
  25. package/dist/types/src/jsx-locator.d.ts +6 -0
  26. package/dist/types/src/keepalive.d.ts +26 -0
  27. package/dist/types/src/lazy-hydration.d.ts +12 -0
  28. package/dist/types/src/markdown-page.d.ts +9 -0
  29. package/dist/types/src/markdown.d.ts +12 -0
  30. package/dist/types/src/plugin.d.ts +36 -0
  31. package/dist/types/src/route-boundary.d.ts +41 -0
  32. package/dist/types/src/runtime/client.d.ts +10 -0
  33. package/dist/types/src/runtime/hmr.d.ts +31 -0
  34. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  35. package/dist/types/src/runtime/hydration.d.ts +8 -0
  36. package/dist/types/src/runtime/island.d.ts +8 -0
  37. package/dist/types/src/runtime/server.d.ts +11 -0
  38. package/dist/types/src/server-island.d.ts +10 -0
  39. package/dist/types/src/svg.d.ts +10 -0
  40. package/package.json +50 -4
  41. package/src/activation.ts +51 -0
  42. package/src/adapter.ts +35 -0
  43. package/src/async-data.ts +65 -0
  44. package/src/client-component.ts +23 -0
  45. package/src/client-fallback.ts +2 -0
  46. package/src/context.ts +372 -0
  47. package/src/env.d.ts +3 -0
  48. package/src/error-page.ts +1 -0
  49. package/src/head.ts +34 -0
  50. package/src/index.ts +1868 -0
  51. package/src/island-html.ts +58 -0
  52. package/src/island.ts +56 -0
  53. package/src/jsx-locator.ts +199 -0
  54. package/src/keepalive.ts +100 -0
  55. package/src/lazy-hydration.ts +101 -0
  56. package/src/markdown-page.ts +18 -0
  57. package/src/markdown.ts +58 -0
  58. package/src/plugin.ts +231 -0
  59. package/src/route-boundary.ts +51 -0
  60. package/src/runtime/client.ts +85 -0
  61. package/src/runtime/hmr.ts +141 -0
  62. package/src/runtime/hydration-dev.ts +8 -0
  63. package/src/runtime/hydration.ts +7 -0
  64. package/src/runtime/island.ts +37 -0
  65. package/src/runtime/server.ts +102 -0
  66. package/src/server-island.ts +35 -0
  67. package/src/svg.ts +27 -0
  68. package/src/webmcp.d.ts +18 -0
@@ -0,0 +1,456 @@
1
+ // @bun
2
+ // packages/adapter-preact/src/adapter.ts
3
+ import { ADAPTER_CONTRACT, defineAdapter } from "hamur/adapter";
4
+ import { clientComponentModule, serverComponentModule } from "hamur/adapter/build";
5
+
6
+ // packages/adapter-preact/src/plugin.ts
7
+ import { realpathSync } from "fs";
8
+ import { join, relative } from "path";
9
+ import { dropDevOnly } from "hamur/adapter/build";
10
+
11
+ // packages/adapter-preact/src/jsx-locator.ts
12
+ var ATTRIBUTE = "data-hamur-src";
13
+ var CONTROL = new Set(["if", "for", "while", "switch", "catch", "with"]);
14
+ var HOST_TAG = /^[a-z][a-z0-9-]*$/;
15
+ var FUNCTION = /^(?:export\s+)?(default\s+)?(?:async\s+)?function\s*\*?\s*([A-Za-z_$][\w$]*)?\s*(?:<[^>(]*>)?\s*\(/gm;
16
+ var ARROW_DECLARATION = /^(?:export\s+)?(?:const|let|var)\s+[A-Z][\w$]*\s*(?::[^=\n]+)?=\s*(?:(?:React\.)?(?:memo|forwardRef)\s*\(\s*)?(?:async\s+)?/gm;
17
+ var DEFAULT_ARROW = /^export\s+default\s+(?:async\s+)?(?=\(|[A-Za-z_$][\w$]*\s*=>)/gm;
18
+ var FUNCTION_EXPRESSION = /function\s*\*?\s*[\w$]*\s*(?:<[^>(]*>)?\s*\(/y;
19
+ var BLOCK_AFTER_PARAMS = /\s*(?::[^{;]*?)?\s*\{/y;
20
+ var ARROW_AFTER_PARAMS = /\s*(?::[^=]*?)?=>\s*/y;
21
+ var BARE_ARROW = /[A-Za-z_$][\w$]*\s*=>\s*/y;
22
+ function skip(source, i) {
23
+ const char = source[i];
24
+ if (char === "/" && source[i + 1] === "/") {
25
+ const end = source.indexOf(`
26
+ `, i);
27
+ return end === -1 ? source.length : end;
28
+ }
29
+ if (char === "/" && source[i + 1] === "*") {
30
+ const end = source.indexOf("*/", i + 2);
31
+ return end === -1 ? source.length : end + 2;
32
+ }
33
+ if (char === '"' || char === "'") {
34
+ let j = i + 1;
35
+ while (j < source.length && source[j] !== char && source[j] !== `
36
+ `)
37
+ j += source[j] === "\\" ? 2 : 1;
38
+ return source[j] === char ? j + 1 : j;
39
+ }
40
+ if (char === "`") {
41
+ let j = i + 1;
42
+ while (j < source.length && source[j] !== "`") {
43
+ if (source[j] === "\\")
44
+ j += 2;
45
+ else if (source[j] === "$" && source[j + 1] === "{") {
46
+ const end = matching(source, j + 1);
47
+ j = end === -1 ? source.length : end + 1;
48
+ } else
49
+ j++;
50
+ }
51
+ return j + 1;
52
+ }
53
+ return i;
54
+ }
55
+ function matching(source, open) {
56
+ const up = source[open];
57
+ const down = up === "(" ? ")" : up === "{" ? "}" : "]";
58
+ let depth = 0;
59
+ for (let i = open;i < source.length; ) {
60
+ const next = skip(source, i);
61
+ if (next !== i) {
62
+ i = next;
63
+ continue;
64
+ }
65
+ if (source[i] === up)
66
+ depth++;
67
+ else if (source[i] === down && --depth === 0)
68
+ return i;
69
+ i++;
70
+ }
71
+ return -1;
72
+ }
73
+ function opensFunction(source, at) {
74
+ let j = at - 1;
75
+ while (j >= 0 && /\s/.test(source[j]))
76
+ j--;
77
+ if (source[j] === ">" && source[j - 1] === "=")
78
+ return true;
79
+ if (source[j] !== ")")
80
+ return false;
81
+ let depth = 0;
82
+ for (;j >= 0; j--) {
83
+ if (source[j] === ")")
84
+ depth++;
85
+ else if (source[j] === "(" && --depth === 0)
86
+ break;
87
+ }
88
+ const word = /([\w$]+)\s*$/.exec(source.slice(Math.max(0, j - 40), j))?.[1];
89
+ return word === undefined || !CONTROL.has(word);
90
+ }
91
+ function returnsOf(source, open, close) {
92
+ const found = [];
93
+ const nested = [];
94
+ let depth = 0;
95
+ for (let i = open + 1;i < close; ) {
96
+ const next = skip(source, i);
97
+ if (next !== i) {
98
+ i = next;
99
+ continue;
100
+ }
101
+ const char = source[i];
102
+ if (char === "{") {
103
+ const fn = opensFunction(source, i);
104
+ nested.push(fn);
105
+ if (fn)
106
+ depth++;
107
+ } else if (char === "}") {
108
+ if (nested.pop())
109
+ depth--;
110
+ } else if (depth === 0 && char === "r" && source.startsWith("return", i) && !/[\w$.]/.test(source[i - 1] ?? "") && !/[\w$]/.test(source[i + 6] ?? "")) {
111
+ found.push(i + 6);
112
+ i += 6;
113
+ continue;
114
+ }
115
+ i++;
116
+ }
117
+ return found;
118
+ }
119
+ function hostRoot(source, from) {
120
+ let i = from;
121
+ while (/[\s(]/.test(source[i] ?? ""))
122
+ i++;
123
+ if (source[i] !== "<")
124
+ return;
125
+ const name = /^<([A-Za-z][\w.:-]*)(?=[\s/>])/.exec(source.slice(i, i + 80))?.[1];
126
+ return name !== undefined && HOST_TAG.test(name) ? { start: i, nameEnd: i + 1 + name.length } : undefined;
127
+ }
128
+ function rootsFrom(source, at) {
129
+ const block = /\s*/y;
130
+ block.lastIndex = at;
131
+ block.exec(source);
132
+ const start = block.lastIndex;
133
+ if (source[start] !== "{") {
134
+ const root = hostRoot(source, start);
135
+ return root ? [root] : [];
136
+ }
137
+ const close = matching(source, start);
138
+ if (close === -1)
139
+ return [];
140
+ return returnsOf(source, start, close).flatMap((index) => hostRoot(source, index) ?? []);
141
+ }
142
+ function bodyAt(source, at) {
143
+ if (source.startsWith("function", at)) {
144
+ FUNCTION_EXPRESSION.lastIndex = at;
145
+ if (!FUNCTION_EXPRESSION.test(source))
146
+ return;
147
+ return afterParams(source, FUNCTION_EXPRESSION.lastIndex - 1, BLOCK_AFTER_PARAMS);
148
+ }
149
+ if (source[at] === "(")
150
+ return afterParams(source, at, ARROW_AFTER_PARAMS);
151
+ BARE_ARROW.lastIndex = at;
152
+ return BARE_ARROW.test(source) ? BARE_ARROW.lastIndex : undefined;
153
+ }
154
+ function afterParams(source, open, next) {
155
+ const close = matching(source, open);
156
+ if (close === -1)
157
+ return;
158
+ next.lastIndex = close + 1;
159
+ if (!next.test(source))
160
+ return;
161
+ return next === BLOCK_AFTER_PARAMS ? next.lastIndex - 1 : next.lastIndex;
162
+ }
163
+ function locateJsx(source, file) {
164
+ if (!source.includes("<"))
165
+ return source;
166
+ const starts = [];
167
+ for (const match of source.matchAll(FUNCTION)) {
168
+ if (match[1] === undefined && !/^[A-Z]/.test(match[2] ?? ""))
169
+ continue;
170
+ const body = afterParams(source, match.index + match[0].length - 1, BLOCK_AFTER_PARAMS);
171
+ if (body !== undefined)
172
+ starts.push(body);
173
+ }
174
+ for (const pattern of [ARROW_DECLARATION, DEFAULT_ARROW]) {
175
+ for (const match of source.matchAll(pattern)) {
176
+ const body = bodyAt(source, match.index + match[0].length);
177
+ if (body !== undefined)
178
+ starts.push(body);
179
+ }
180
+ }
181
+ const roots = new Map;
182
+ for (const start of starts)
183
+ for (const root of rootsFrom(source, start))
184
+ roots.set(root.start, root);
185
+ if (roots.size === 0)
186
+ return source;
187
+ const lineStarts = [0];
188
+ for (let i = source.indexOf(`
189
+ `);i !== -1; i = source.indexOf(`
190
+ `, i + 1))
191
+ lineStarts.push(i + 1);
192
+ let out = "";
193
+ let last = 0;
194
+ for (const { start, nameEnd } of [...roots.values()].sort((a, b) => a.start - b.start)) {
195
+ if (source.slice(nameEnd, nameEnd + 200).split(">", 1)[0].includes(ATTRIBUTE))
196
+ continue;
197
+ let low = 0;
198
+ let high = lineStarts.length - 1;
199
+ while (low < high) {
200
+ const mid = low + high + 1 >> 1;
201
+ if (lineStarts[mid] <= start)
202
+ low = mid;
203
+ else
204
+ high = mid - 1;
205
+ }
206
+ out += `${source.slice(last, nameEnd)} ${ATTRIBUTE}="${file}:${low + 1}:${start - lineStarts[low] + 1}"`;
207
+ last = nameEnd;
208
+ }
209
+ return out + source.slice(last);
210
+ }
211
+
212
+ // packages/adapter-preact/src/plugin.ts
213
+ var HMR_RUNTIME = join(import.meta.dir + "/../../src", "runtime/hmr.ts");
214
+ var CLIENT_RUNTIME = join(import.meta.dir + "/../../src", "runtime/client.ts");
215
+ var HYDRATION_DEV = join(import.meta.dir + "/../../src", "runtime/hydration-dev.ts");
216
+ var ROUTE_MODULE = /(^|\/)((pages|layouts)\/|app\.[jt]sx$)/;
217
+ var SIGNATURE_CALL = /\b(use[A-Z]\w*)\s*(?:<[^>]*>)?\s*\(/g;
218
+ var SIGNATURE_ARGUMENTS = new Set(["useState", "useReducer"]);
219
+ var ARROW = String.raw`(?:async\s*)?(?:\((?:[^()]|\([^()]*\))*\)|[A-Za-z_$][\w$]*)\s*(?::[^=]+)?=>`;
220
+ var DEFAULT_FUNCTION = /^export default (async )?function\b\s*([A-Za-z_$][\w$]*)?/m;
221
+ var DEFAULT_ARROW2 = new RegExp(String.raw`^export default (?=${ARROW})`, "m");
222
+ var DEFAULT_NAME = /^export default ([A-Z][\w$]*)\s*;?\s*$/m;
223
+ var DEFAULT_ANY = /^export default /m;
224
+ var NAMED_FUNCTION = /^export function ([A-Z][\w$]*)(?=\s*[<(])/gm;
225
+ var NAMED_CONST = new RegExp(String.raw`^export const ([A-Z][\w$]*)(?=(?:\s*:[^=]+)?\s*=\s*(?:function\b|${ARROW}))`, "gm");
226
+ var JSX = /(?<![\w$)\].])<(?:[A-Za-z][\w.:-]*(?=[\s/>])|>)/;
227
+ var TOP_LEVEL = /^(?:export|import|const|let|var|function|class|async\s+function|interface|type)\b/m;
228
+ var NOT_A_MODULE = /^#hamur\/|\.(?:css|scss|sass|less|styl|svg|png|jpe?g|gif|webp|avif|ico|json|txt|md|wasm|html)(?:\?.*)?$|\?/i;
229
+ var BINDING = /(?:const|let|var)\s+(\[[^\]]*\]|\{[^}]*\}|[\w$]+)\s*(?::[^=;]+)?=\s*$/;
230
+ function declaration(source, start) {
231
+ const line = source.indexOf(`
232
+ `, start);
233
+ if (line === -1)
234
+ return source.slice(start);
235
+ const next = source.slice(line + 1).search(TOP_LEVEL);
236
+ return source.slice(start, next === -1 ? source.length : line + 1 + next);
237
+ }
238
+ function argumentsAt(source, open) {
239
+ let depth = 0;
240
+ let quote = "";
241
+ for (let i = open;i < source.length; i++) {
242
+ const char = source[i];
243
+ if (quote) {
244
+ if (char === "\\")
245
+ i++;
246
+ else if (char === quote)
247
+ quote = "";
248
+ } else if (char === '"' || char === "'" || char === "`")
249
+ quote = char;
250
+ else if (char === "(")
251
+ depth++;
252
+ else if (char === ")" && --depth === 0)
253
+ return source.slice(open + 1, i);
254
+ }
255
+ return source.slice(open + 1);
256
+ }
257
+ function refreshSignature(source, calls, withArguments) {
258
+ const entries = [];
259
+ for (const match of source.matchAll(calls)) {
260
+ const name = match[1];
261
+ const binding = source.slice(Math.max(0, match.index - 200), match.index).match(BINDING)?.[1] ?? "";
262
+ const args = withArguments.has(name) ? `(${argumentsAt(source, match.index + match[0].length - 1)})` : "";
263
+ entries.push(`${binding}=${name}${args}`.replace(/\s+/g, " "));
264
+ }
265
+ return entries.join(";");
266
+ }
267
+ function refreshTransform(source, { id, route, runtime = HMR_RUNTIME }) {
268
+ const { exports, imports } = new Bun.Transpiler({ loader: "tsx" }).scan(source);
269
+ const dependencies = [
270
+ ...new Set(imports.filter(({ kind, path }) => kind === "import-statement" && !NOT_A_MODULE.test(path)).map(({ path }) => path))
271
+ ];
272
+ const signature = refreshSignature(source, SIGNATURE_CALL, SIGNATURE_ARGUMENTS);
273
+ const components = new Map;
274
+ const renders = (text, at) => JSX.test(declaration(text, at));
275
+ let body = source.replace(NAMED_FUNCTION, (match, name, at, text) => renders(text, at) ? (components.set(name, name), `function ${name}`) : match);
276
+ body = body.replace(NAMED_CONST, (match, name, at, text) => renders(text, at) ? (components.set(name, name), `let ${name}`) : match);
277
+ const fn = body.match(DEFAULT_FUNCTION);
278
+ const named = body.match(DEFAULT_NAME)?.[1];
279
+ const declared = (name) => {
280
+ const at = body.search(new RegExp(String.raw`^(?:async\s+)?function\s+${name}\b|^(?:const|let|var)\s+${name}\b`, "m"));
281
+ return at !== -1 && renders(body, at);
282
+ };
283
+ if (fn?.[2] && (route || renders(body, fn.index))) {
284
+ body = body.replace(DEFAULT_FUNCTION, `${fn[1] ?? ""}function ${fn[2]}`);
285
+ components.set("default", fn[2]);
286
+ } else if (route ? DEFAULT_ANY.test(body) : fn && renders(body, fn.index) || DEFAULT_ARROW2.test(body) && renders(body, body.search(DEFAULT_ARROW2)) || named !== undefined && declared(named)) {
287
+ body = body.replace(DEFAULT_ANY, "let __hamurDefault = ");
288
+ components.set("default", "__hamurDefault");
289
+ }
290
+ if (components.size === 0)
291
+ return { code: source, signature: "", accepted: false };
292
+ const accepted = route || exports.every((name) => components.has(name));
293
+ const names = [...components];
294
+ return {
295
+ signature,
296
+ accepted,
297
+ code: [
298
+ `${[`import { hotModule as __hamurHot } from ${JSON.stringify(runtime)};`, ...dependencies.map((path, index) => `import * as __hamurDep${index} from ${JSON.stringify(path)};`)].join(" ")} ${body}`,
299
+ `const __hamurMod = __hamurHot(import.meta.hot ? import.meta.hot.data.hamur : undefined, ${JSON.stringify(id)}, ${JSON.stringify(signature)}, ${JSON.stringify(String(Bun.hash(source)))}, [${dependencies.map((_, index) => `__hamurDep${index}`).join(", ")}]);`,
300
+ `if (import.meta.hot) import.meta.hot.data.hamur = __hamurMod;`,
301
+ ...names.map(([name, local]) => `${local} = __hamurMod.component(${JSON.stringify(name)}, ${local});`),
302
+ `export { ${names.map(([name, local]) => name === local ? name : `${local} as ${name}`).join(", ")} };`,
303
+ `__hamurMod.commit();`,
304
+ ...accepted ? [`if (import.meta.hot) import.meta.hot.accept();`] : []
305
+ ].join(`
306
+ `)
307
+ };
308
+ }
309
+ function appModuleId(rootDir, buildDir) {
310
+ let real = rootDir;
311
+ try {
312
+ real = realpathSync(rootDir);
313
+ } catch {}
314
+ const roots = [...new Set([rootDir, real])];
315
+ const build = relative(rootDir, buildDir);
316
+ const inBuild = (id) => build !== "" && !build.startsWith("..") && (id === build || id.startsWith(`${build}/`));
317
+ return (path) => {
318
+ if (path.includes("/node_modules/"))
319
+ return;
320
+ for (const root of roots) {
321
+ const id = relative(root, path);
322
+ if (!id.startsWith("..") && !id.startsWith("/"))
323
+ return inBuild(id) ? undefined : id;
324
+ }
325
+ return;
326
+ };
327
+ }
328
+ function preactPlugin(ctx) {
329
+ const appModule = appModuleId(ctx.rootDir, ctx.buildDir);
330
+ return {
331
+ name: `hamur-preact-${ctx.target}`,
332
+ filter: { id: /\.[jt]sx$/ },
333
+ transform(code, { id: path }) {
334
+ if (path.includes("/node_modules/"))
335
+ return;
336
+ let source = code;
337
+ const id = appModule(path);
338
+ const layerRoute = id === undefined ? relative(ctx.rootDir, path) : undefined;
339
+ if (ctx.hmr && id !== undefined)
340
+ source = refreshTransform(source, { id, route: ROUTE_MODULE.test(id) }).code;
341
+ else if (ctx.hmr && layerRoute !== undefined && ROUTE_MODULE.test(layerRoute))
342
+ source = refreshTransform(source, { id: layerRoute, route: true }).code;
343
+ return `/** @jsxImportSource preact */ ${source}`;
344
+ }
345
+ };
346
+ }
347
+ function preactLocatorPlugin(ctx) {
348
+ const appModule = appModuleId(ctx.rootDir, ctx.buildDir);
349
+ return {
350
+ name: `hamur-preact-locator-${ctx.target}`,
351
+ filter: { id: /\.[jt]sx$/ },
352
+ transform(code, { id }) {
353
+ const file = appModule(id);
354
+ if (file === undefined)
355
+ return;
356
+ const located = locateJsx(code, file);
357
+ return located === code ? undefined : located;
358
+ }
359
+ };
360
+ }
361
+ function preactProductionPlugin(ctx) {
362
+ return {
363
+ name: `hamur-preact-production-${ctx.target}`,
364
+ filter: { id: /\.[jt]sx$/ },
365
+ transform(code, { id }) {
366
+ if (id.includes("/node_modules/"))
367
+ return;
368
+ const contents = dropDevOnly(code, "@hamur/adapter-preact", "markup");
369
+ return contents === code ? undefined : contents;
370
+ }
371
+ };
372
+ }
373
+ function preactDebugPlugin() {
374
+ return {
375
+ name: "hamur-preact-debug",
376
+ filter: { id: new RegExp(`^${CLIENT_RUNTIME.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`) },
377
+ transform: (code) => `import "preact/debug"; ${code}`
378
+ };
379
+ }
380
+ function preactHydrationPlugin() {
381
+ return {
382
+ name: "hamur-preact-hydration",
383
+ filter: { id: new RegExp(`^${CLIENT_RUNTIME.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`) },
384
+ transform: (code) => `import ${JSON.stringify(HYDRATION_DEV)}; ${code}`
385
+ };
386
+ }
387
+
388
+ // packages/adapter-preact/src/svg.ts
389
+ import { svgCode } from "hamur/adapter";
390
+ function nodeCode(code, node) {
391
+ if (typeof node === "string" || Array.isArray(node))
392
+ return code.value(node);
393
+ const children = node.children.map((child) => nodeCode(code, child));
394
+ return `h(${JSON.stringify(node.tag)}, ${code.props(code.attrs(node))}${children.length ? `, ${children.join(", ")}` : ""})`;
395
+ }
396
+ function module(svg) {
397
+ const code = svgCode(svg, { title: "title", props: "props" });
398
+ const children = svg.children.map((child) => nodeCode(code, child));
399
+ const hidden = code.hidden ? `${code.hidden} ? { "aria-hidden": "true" } : {}` : "{}";
400
+ const contents = `import { h } from "preact";
401
+ import { useId } from "preact/hooks";
402
+
403
+ export default function SvgComponent({ title, ...props }) {
404
+ const uid = useId().replace(/[^\\w-]/g, "_");
405
+ return h("svg", { ...${code.props(svg.attrs)}, ...(${hidden}), ...props }, title == null ? null : h("title", null, title)${children.length ? `, ${children.join(", ")}` : ""});
406
+ }
407
+ `;
408
+ return { contents, extension: ".js" };
409
+ }
410
+ var svgComponent = {
411
+ types: `import("preact").FunctionComponent<import("preact").SVGAttributes<SVGSVGElement> & { title?: string }>`,
412
+ module
413
+ };
414
+
415
+ // packages/adapter-preact/src/markdown-page.ts
416
+ import { markdownPageCode } from "hamur/adapter/build";
417
+ function module2(source) {
418
+ const { imports, value, props, head } = markdownPageCode(source);
419
+ const contents = `${imports}import { h } from "preact";
420
+ import { MarkdownRenderer, useHead } from "@hamur/adapter-preact";
421
+
422
+ const value = ${value};
423
+
424
+ export default function MarkdownPage() {
425
+ ${head ? ` useHead(${head});
426
+ ` : ""} return h(MarkdownRenderer, ${props});
427
+ }
428
+ `;
429
+ return { contents, extension: ".js" };
430
+ }
431
+ var markdownComponent = { module: module2 };
432
+
433
+ // packages/adapter-preact/src/adapter.ts
434
+ var adapter_default = defineAdapter({
435
+ name: "preact",
436
+ contract: ADAPTER_CONTRACT,
437
+ extensions: [".tsx", ".jsx"],
438
+ clientEntry: "@hamur/adapter-preact/runtime/client",
439
+ serverEntry: "@hamur/adapter-preact/runtime/server",
440
+ keepAliveOutlet: "@hamur/adapter-preact/runtime/keepalive",
441
+ islandEntry: "@hamur/adapter-preact/runtime/island",
442
+ transforms: (ctx) => ctx.dev ? [
443
+ preactLocatorPlugin(ctx),
444
+ ...ctx.target === "client" ? [preactPlugin(ctx), preactHydrationPlugin(), preactDebugPlugin()] : []
445
+ ] : [preactProductionPlugin(ctx)],
446
+ jsx: { runtime: "automatic", importSource: "preact" },
447
+ errorPage: "@hamur/adapter-preact/error-page",
448
+ peers: ["preact", "preact-render-to-string"],
449
+ svgComponent,
450
+ markdownComponent,
451
+ serverComponent: { module: (component) => serverComponentModule(component, "@hamur/adapter-preact/runtime") },
452
+ clientComponent: { module: (component) => clientComponentModule(component, "@hamur/adapter-preact/runtime") }
453
+ });
454
+ export {
455
+ adapter_default as default
456
+ };