@hamur/adapter-solid 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 (72) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +35 -2
  3. package/dist/chunks/browser-index-8rhv2s58.js +14 -0
  4. package/dist/chunks/browser-index-b05qbzsh.js +165 -0
  5. package/dist/chunks/browser-index-n80jt19y.js +114 -0
  6. package/dist/chunks/browser-index-ncnkshd9.js +39 -0
  7. package/dist/chunks/browser-index-r4jwfgh7.js +407 -0
  8. package/dist/src/adapter.js +556 -0
  9. package/dist/src/error-page.js +466 -0
  10. package/dist/src/index.js +1535 -0
  11. package/dist/src/keepalive.js +6 -0
  12. package/dist/src/runtime/client.js +174 -0
  13. package/dist/src/runtime/island.js +58 -0
  14. package/dist/src/runtime/server.js +138 -0
  15. package/dist/types/src/activation.d.ts +15 -0
  16. package/dist/types/src/adapter.d.ts +4 -0
  17. package/dist/types/src/async-data.d.ts +21 -0
  18. package/dist/types/src/client-component.d.ts +10 -0
  19. package/dist/types/src/client-fallback.d.ts +2 -0
  20. package/dist/types/src/context.d.ts +89 -0
  21. package/dist/types/src/error-page.d.ts +1 -0
  22. package/dist/types/src/index.d.ts +392 -0
  23. package/dist/types/src/island-html.d.ts +13 -0
  24. package/dist/types/src/island.d.ts +20 -0
  25. package/dist/types/src/jsx-locator.d.ts +6 -0
  26. package/dist/types/src/keepalive.d.ts +30 -0
  27. package/dist/types/src/lazy-hydration.d.ts +13 -0
  28. package/dist/types/src/markdown-page.d.ts +9 -0
  29. package/dist/types/src/markdown.d.ts +13 -0
  30. package/dist/types/src/plugin.d.ts +44 -0
  31. package/dist/types/src/runtime/client.d.ts +13 -0
  32. package/dist/types/src/runtime/hmr-solid.d.ts +5 -0
  33. package/dist/types/src/runtime/hmr.d.ts +27 -0
  34. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  35. package/dist/types/src/runtime/hydration.d.ts +10 -0
  36. package/dist/types/src/runtime/island.d.ts +8 -0
  37. package/dist/types/src/runtime/portal.d.ts +13 -0
  38. package/dist/types/src/runtime/server.d.ts +14 -0
  39. package/dist/types/src/runtime/trusted.d.ts +2 -0
  40. package/dist/types/src/server-island.d.ts +10 -0
  41. package/dist/types/src/svg.d.ts +10 -0
  42. package/package.json +53 -4
  43. package/src/activation.ts +51 -0
  44. package/src/adapter.ts +42 -0
  45. package/src/async-data.ts +105 -0
  46. package/src/client-component.ts +40 -0
  47. package/src/client-fallback.ts +2 -0
  48. package/src/context.ts +495 -0
  49. package/src/env.d.ts +3 -0
  50. package/src/error-page.ts +1 -0
  51. package/src/index.ts +1900 -0
  52. package/src/island-html.ts +58 -0
  53. package/src/island.ts +55 -0
  54. package/src/jsx-locator.ts +199 -0
  55. package/src/keepalive.ts +147 -0
  56. package/src/lazy-hydration.ts +146 -0
  57. package/src/markdown-page.ts +18 -0
  58. package/src/markdown.ts +70 -0
  59. package/src/plugin.ts +310 -0
  60. package/src/runtime/client.ts +175 -0
  61. package/src/runtime/hmr-solid.ts +19 -0
  62. package/src/runtime/hmr.ts +231 -0
  63. package/src/runtime/hydration-dev.ts +41 -0
  64. package/src/runtime/hydration.ts +9 -0
  65. package/src/runtime/island.ts +66 -0
  66. package/src/runtime/portal.ts +64 -0
  67. package/src/runtime/server.ts +160 -0
  68. package/src/runtime/trusted.ts +16 -0
  69. package/src/server-island.ts +47 -0
  70. package/src/solid.d.ts +4 -0
  71. package/src/svg.ts +53 -0
  72. package/src/webmcp.d.ts +20 -0
@@ -0,0 +1,556 @@
1
+ // @bun
2
+ // packages/adapter-solid/src/adapter.ts
3
+ import { readFileSync as readFileSync2 } from "fs";
4
+ import { ADAPTER_CONTRACT, defineAdapter } from "hamur/adapter";
5
+ import { clientComponentModule, serverComponentModule } from "hamur/adapter/build";
6
+
7
+ // packages/adapter-solid/src/plugin.ts
8
+ import { transformAsync } from "@babel/core";
9
+ import presetTypescript from "@babel/preset-typescript";
10
+ import solidBabel from "@solidjs/babel-plugin";
11
+ import { readFileSync, realpathSync } from "fs";
12
+ import { dirname, join, relative } from "path";
13
+ import { dropDevOnly } from "hamur/adapter/build";
14
+
15
+ // packages/adapter-solid/src/jsx-locator.ts
16
+ var ATTRIBUTE = "data-hamur-src";
17
+ var CONTROL = new Set(["if", "for", "while", "switch", "catch", "with"]);
18
+ var HOST_TAG = /^[a-z][a-z0-9-]*$/;
19
+ var FUNCTION = /^(?:export\s+)?(default\s+)?(?:async\s+)?function\s*\*?\s*([A-Za-z_$][\w$]*)?\s*(?:<[^>(]*>)?\s*\(/gm;
20
+ var ARROW_DECLARATION = /^(?:export\s+)?(?:const|let|var)\s+[A-Z][\w$]*\s*(?::[^=\n]+)?=\s*(?:(?:React\.)?(?:memo|forwardRef)\s*\(\s*)?(?:async\s+)?/gm;
21
+ var DEFAULT_ARROW = /^export\s+default\s+(?:async\s+)?(?=\(|[A-Za-z_$][\w$]*\s*=>)/gm;
22
+ var FUNCTION_EXPRESSION = /function\s*\*?\s*[\w$]*\s*(?:<[^>(]*>)?\s*\(/y;
23
+ var BLOCK_AFTER_PARAMS = /\s*(?::[^{;]*?)?\s*\{/y;
24
+ var ARROW_AFTER_PARAMS = /\s*(?::[^=]*?)?=>\s*/y;
25
+ var BARE_ARROW = /[A-Za-z_$][\w$]*\s*=>\s*/y;
26
+ function skip(source, i) {
27
+ const char = source[i];
28
+ if (char === "/" && source[i + 1] === "/") {
29
+ const end = source.indexOf(`
30
+ `, i);
31
+ return end === -1 ? source.length : end;
32
+ }
33
+ if (char === "/" && source[i + 1] === "*") {
34
+ const end = source.indexOf("*/", i + 2);
35
+ return end === -1 ? source.length : end + 2;
36
+ }
37
+ if (char === '"' || char === "'") {
38
+ let j = i + 1;
39
+ while (j < source.length && source[j] !== char && source[j] !== `
40
+ `)
41
+ j += source[j] === "\\" ? 2 : 1;
42
+ return source[j] === char ? j + 1 : j;
43
+ }
44
+ if (char === "`") {
45
+ let j = i + 1;
46
+ while (j < source.length && source[j] !== "`") {
47
+ if (source[j] === "\\")
48
+ j += 2;
49
+ else if (source[j] === "$" && source[j + 1] === "{") {
50
+ const end = matching(source, j + 1);
51
+ j = end === -1 ? source.length : end + 1;
52
+ } else
53
+ j++;
54
+ }
55
+ return j + 1;
56
+ }
57
+ return i;
58
+ }
59
+ function matching(source, open) {
60
+ const up = source[open];
61
+ const down = up === "(" ? ")" : up === "{" ? "}" : "]";
62
+ let depth = 0;
63
+ for (let i = open;i < source.length; ) {
64
+ const next = skip(source, i);
65
+ if (next !== i) {
66
+ i = next;
67
+ continue;
68
+ }
69
+ if (source[i] === up)
70
+ depth++;
71
+ else if (source[i] === down && --depth === 0)
72
+ return i;
73
+ i++;
74
+ }
75
+ return -1;
76
+ }
77
+ function opensFunction(source, at) {
78
+ let j = at - 1;
79
+ while (j >= 0 && /\s/.test(source[j]))
80
+ j--;
81
+ if (source[j] === ">" && source[j - 1] === "=")
82
+ return true;
83
+ if (source[j] !== ")")
84
+ return false;
85
+ let depth = 0;
86
+ for (;j >= 0; j--) {
87
+ if (source[j] === ")")
88
+ depth++;
89
+ else if (source[j] === "(" && --depth === 0)
90
+ break;
91
+ }
92
+ const word = /([\w$]+)\s*$/.exec(source.slice(Math.max(0, j - 40), j))?.[1];
93
+ return word === undefined || !CONTROL.has(word);
94
+ }
95
+ function returnsOf(source, open, close) {
96
+ const found = [];
97
+ const nested = [];
98
+ let depth = 0;
99
+ for (let i = open + 1;i < close; ) {
100
+ const next = skip(source, i);
101
+ if (next !== i) {
102
+ i = next;
103
+ continue;
104
+ }
105
+ const char = source[i];
106
+ if (char === "{") {
107
+ const fn = opensFunction(source, i);
108
+ nested.push(fn);
109
+ if (fn)
110
+ depth++;
111
+ } else if (char === "}") {
112
+ if (nested.pop())
113
+ depth--;
114
+ } else if (depth === 0 && char === "r" && source.startsWith("return", i) && !/[\w$.]/.test(source[i - 1] ?? "") && !/[\w$]/.test(source[i + 6] ?? "")) {
115
+ found.push(i + 6);
116
+ i += 6;
117
+ continue;
118
+ }
119
+ i++;
120
+ }
121
+ return found;
122
+ }
123
+ function hostRoot(source, from) {
124
+ let i = from;
125
+ while (/[\s(]/.test(source[i] ?? ""))
126
+ i++;
127
+ if (source[i] !== "<")
128
+ return;
129
+ const name = /^<([A-Za-z][\w.:-]*)(?=[\s/>])/.exec(source.slice(i, i + 80))?.[1];
130
+ return name !== undefined && HOST_TAG.test(name) ? { start: i, nameEnd: i + 1 + name.length } : undefined;
131
+ }
132
+ function rootsFrom(source, at) {
133
+ const block = /\s*/y;
134
+ block.lastIndex = at;
135
+ block.exec(source);
136
+ const start = block.lastIndex;
137
+ if (source[start] !== "{") {
138
+ const root = hostRoot(source, start);
139
+ return root ? [root] : [];
140
+ }
141
+ const close = matching(source, start);
142
+ if (close === -1)
143
+ return [];
144
+ return returnsOf(source, start, close).flatMap((index) => hostRoot(source, index) ?? []);
145
+ }
146
+ function bodyAt(source, at) {
147
+ if (source.startsWith("function", at)) {
148
+ FUNCTION_EXPRESSION.lastIndex = at;
149
+ if (!FUNCTION_EXPRESSION.test(source))
150
+ return;
151
+ return afterParams(source, FUNCTION_EXPRESSION.lastIndex - 1, BLOCK_AFTER_PARAMS);
152
+ }
153
+ if (source[at] === "(")
154
+ return afterParams(source, at, ARROW_AFTER_PARAMS);
155
+ BARE_ARROW.lastIndex = at;
156
+ return BARE_ARROW.test(source) ? BARE_ARROW.lastIndex : undefined;
157
+ }
158
+ function afterParams(source, open, next) {
159
+ const close = matching(source, open);
160
+ if (close === -1)
161
+ return;
162
+ next.lastIndex = close + 1;
163
+ if (!next.test(source))
164
+ return;
165
+ return next === BLOCK_AFTER_PARAMS ? next.lastIndex - 1 : next.lastIndex;
166
+ }
167
+ function locateJsx(source, file) {
168
+ if (!source.includes("<"))
169
+ return source;
170
+ const starts = [];
171
+ for (const match of source.matchAll(FUNCTION)) {
172
+ if (match[1] === undefined && !/^[A-Z]/.test(match[2] ?? ""))
173
+ continue;
174
+ const body = afterParams(source, match.index + match[0].length - 1, BLOCK_AFTER_PARAMS);
175
+ if (body !== undefined)
176
+ starts.push(body);
177
+ }
178
+ for (const pattern of [ARROW_DECLARATION, DEFAULT_ARROW]) {
179
+ for (const match of source.matchAll(pattern)) {
180
+ const body = bodyAt(source, match.index + match[0].length);
181
+ if (body !== undefined)
182
+ starts.push(body);
183
+ }
184
+ }
185
+ const roots = new Map;
186
+ for (const start of starts)
187
+ for (const root of rootsFrom(source, start))
188
+ roots.set(root.start, root);
189
+ if (roots.size === 0)
190
+ return source;
191
+ const lineStarts = [0];
192
+ for (let i = source.indexOf(`
193
+ `);i !== -1; i = source.indexOf(`
194
+ `, i + 1))
195
+ lineStarts.push(i + 1);
196
+ let out = "";
197
+ let last = 0;
198
+ for (const { start, nameEnd } of [...roots.values()].sort((a, b) => a.start - b.start)) {
199
+ if (source.slice(nameEnd, nameEnd + 200).split(">", 1)[0].includes(ATTRIBUTE))
200
+ continue;
201
+ let low = 0;
202
+ let high = lineStarts.length - 1;
203
+ while (low < high) {
204
+ const mid = low + high + 1 >> 1;
205
+ if (lineStarts[mid] <= start)
206
+ low = mid;
207
+ else
208
+ high = mid - 1;
209
+ }
210
+ out += `${source.slice(last, nameEnd)} ${ATTRIBUTE}="${file}:${low + 1}:${start - lineStarts[low] + 1}"`;
211
+ last = nameEnd;
212
+ }
213
+ return out + source.slice(last);
214
+ }
215
+
216
+ // packages/adapter-solid/src/plugin.ts
217
+ var HMR_RUNTIME = join(import.meta.dir + "/../../src", "runtime/hmr.ts");
218
+ var PORTAL_RUNTIME = join(import.meta.dir + "/../../src", "runtime/portal.ts");
219
+ var CLIENT_RUNTIME = join(import.meta.dir + "/../../src", "runtime/client.ts");
220
+ var HYDRATION_DEV = join(import.meta.dir + "/../../src", "runtime/hydration-dev.ts");
221
+ var WEB_IMPORT = /^import\s*\{([^}]*)\}\s*from\s*(["'])@solidjs\/web\2;?/gm;
222
+ var PORTAL_SPECIFIER = /^Portal(?:\s+as\s+[\w$]+)?$/;
223
+ var SHIMS = {
224
+ "solid-js": join(import.meta.dir + "/../../src", "runtime/hmr-solid.ts")
225
+ };
226
+ var ROUTE_MODULE = /(^|\/)((pages|layouts)\/|app\.[jt]sx$)/;
227
+ var SIGNATURE_CALL = /\b(createSignal|createStore)\s*(?:<[^>]*>)?\s*\(/g;
228
+ var SIGNATURE_ARGUMENTS = new Set(["createSignal", "createStore"]);
229
+ var ARROW = String.raw`(?:async\s*)?(?:\((?:[^()]|\([^()]*\))*\)|[A-Za-z_$][\w$]*)\s*(?::[^=]+)?=>`;
230
+ var DEFAULT_FUNCTION = /^export default (async )?function\b\s*([A-Za-z_$][\w$]*)?/m;
231
+ var DEFAULT_ARROW2 = new RegExp(String.raw`^export default (?=${ARROW})`, "m");
232
+ var DEFAULT_NAME = /^export default ([A-Z][\w$]*)\s*;?\s*$/m;
233
+ var DEFAULT_ANY = /^export default /m;
234
+ var NAMED_FUNCTION = /^export function ([A-Z][\w$]*)(?=\s*[<(])/gm;
235
+ var NAMED_CONST = new RegExp(String.raw`^export const ([A-Z][\w$]*)(?=(?:\s*:[^=]+)?\s*=\s*(?:function\b|${ARROW}))`, "gm");
236
+ var JSX = /(?<![\w$)\].])<(?:[A-Za-z][\w.:-]*(?=[\s/>])|>)/;
237
+ var TOP_LEVEL = /^(?:export|import|const|let|var|function|class|async\s+function|interface|type)\b/m;
238
+ var NOT_A_MODULE = /^#hamur\/|\.(?:css|scss|sass|less|styl|svg|png|jpe?g|gif|webp|avif|ico|json|txt|md|wasm|html)(?:\?.*)?$|\?/i;
239
+ var BINDING = /(?:const|let|var)\s+(\[[^\]]*\]|\{[^}]*\}|[\w$]+)\s*(?::[^=;]+)?=\s*$/;
240
+ function declaration(source, start) {
241
+ const line = source.indexOf(`
242
+ `, start);
243
+ if (line === -1)
244
+ return source.slice(start);
245
+ const next = source.slice(line + 1).search(TOP_LEVEL);
246
+ return source.slice(start, next === -1 ? source.length : line + 1 + next);
247
+ }
248
+ function argumentsAt(source, open) {
249
+ let depth = 0;
250
+ let quote = "";
251
+ for (let i = open;i < source.length; i++) {
252
+ const char = source[i];
253
+ if (quote) {
254
+ if (char === "\\")
255
+ i++;
256
+ else if (char === quote)
257
+ quote = "";
258
+ } else if (char === '"' || char === "'" || char === "`")
259
+ quote = char;
260
+ else if (char === "(")
261
+ depth++;
262
+ else if (char === ")" && --depth === 0)
263
+ return source.slice(open + 1, i);
264
+ }
265
+ return source.slice(open + 1);
266
+ }
267
+ function refreshSignature(source, calls, withArguments) {
268
+ const entries = [];
269
+ for (const match of source.matchAll(calls)) {
270
+ const name = match[1];
271
+ const binding = source.slice(Math.max(0, match.index - 200), match.index).match(BINDING)?.[1] ?? "";
272
+ const args = withArguments.has(name) ? `(${argumentsAt(source, match.index + match[0].length - 1)})` : "";
273
+ entries.push(`${binding}=${name}${args}`.replace(/\s+/g, " "));
274
+ }
275
+ return entries.join(";");
276
+ }
277
+ function refreshTransform(source, { id, route, runtime = HMR_RUNTIME }) {
278
+ const { exports, imports } = new Bun.Transpiler({ loader: "tsx" }).scan(source);
279
+ const dependencies = [
280
+ ...new Set(imports.filter(({ kind, path }) => kind === "import-statement" && !NOT_A_MODULE.test(path)).map(({ path }) => path))
281
+ ];
282
+ const signature = refreshSignature(source, SIGNATURE_CALL, SIGNATURE_ARGUMENTS);
283
+ const components = new Map;
284
+ const renders = (text, at) => JSX.test(declaration(text, at));
285
+ let body = source.replace(NAMED_FUNCTION, (match, name, at, text) => renders(text, at) ? (components.set(name, name), `function ${name}`) : match);
286
+ body = body.replace(NAMED_CONST, (match, name, at, text) => renders(text, at) ? (components.set(name, name), `let ${name}`) : match);
287
+ const fn = body.match(DEFAULT_FUNCTION);
288
+ const named = body.match(DEFAULT_NAME)?.[1];
289
+ const declared = (name) => {
290
+ const at = body.search(new RegExp(String.raw`^(?:async\s+)?function\s+${name}\b|^(?:const|let|var)\s+${name}\b`, "m"));
291
+ return at !== -1 && renders(body, at);
292
+ };
293
+ if (fn?.[2] && (route || renders(body, fn.index))) {
294
+ body = body.replace(DEFAULT_FUNCTION, `${fn[1] ?? ""}function ${fn[2]}`);
295
+ components.set("default", fn[2]);
296
+ } 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)) {
297
+ body = body.replace(DEFAULT_ANY, "let __hamurDefault = ");
298
+ components.set("default", "__hamurDefault");
299
+ }
300
+ if (components.size === 0)
301
+ return { code: source, signature: "", accepted: false };
302
+ const accepted = route || exports.every((name) => components.has(name));
303
+ const names = [...components];
304
+ return {
305
+ signature,
306
+ accepted,
307
+ code: [
308
+ `import { hotModule as __hamurHot } from ${JSON.stringify(runtime)};`,
309
+ ...dependencies.map((path, index) => `import * as __hamurDep${index} from ${JSON.stringify(path)};`),
310
+ body,
311
+ `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(", ")}]);`,
312
+ `if (import.meta.hot) import.meta.hot.data.hamur = __hamurMod;`,
313
+ ...names.map(([name, local]) => `${local} = __hamurMod.component(${JSON.stringify(name)}, ${local});`),
314
+ `export { ${names.map(([name, local]) => name === local ? name : `${local} as ${name}`).join(", ")} };`,
315
+ `__hamurMod.commit();`,
316
+ ...accepted ? [`if (import.meta.hot) import.meta.hot.accept();`] : []
317
+ ].join(`
318
+ `)
319
+ };
320
+ }
321
+ function appModuleId(rootDir, buildDir) {
322
+ let real = rootDir;
323
+ try {
324
+ real = realpathSync(rootDir);
325
+ } catch {}
326
+ const roots = [...new Set([rootDir, real])];
327
+ const build = relative(rootDir, buildDir);
328
+ const inBuild = (id) => build !== "" && !build.startsWith("..") && (id === build || id.startsWith(`${build}/`));
329
+ return (path) => {
330
+ if (path.includes("/node_modules/"))
331
+ return;
332
+ for (const root of roots) {
333
+ const id = relative(root, path);
334
+ if (!id.startsWith("..") && !id.startsWith("/"))
335
+ return inBuild(id) ? undefined : id;
336
+ }
337
+ return;
338
+ };
339
+ }
340
+ function shimImports(source) {
341
+ return source.replace(/^(\s*(?:(?:import|export)\b[^;'"`]*?\bfrom\s*|import\s*))(["'])(solid-js)\2/gm, (_, statement, quote, specifier) => `${statement}${quote}${SHIMS[specifier]}${quote}`);
342
+ }
343
+ function serverPortal(code) {
344
+ return code.replace(WEB_IMPORT, (statement, list) => {
345
+ const specifiers = list.split(",").map((part) => part.trim()).filter(Boolean);
346
+ const portal = specifiers.find((part) => PORTAL_SPECIFIER.test(part));
347
+ if (!portal)
348
+ return statement;
349
+ const rest = specifiers.filter((part) => part !== portal);
350
+ const own = `import { ${portal} } from ${JSON.stringify(PORTAL_RUNTIME)};`;
351
+ return rest.length ? `import { ${rest.join(", ")} } from "@solidjs/web";
352
+ ${own}` : own;
353
+ });
354
+ }
355
+ async function compileSolid(path, source, target) {
356
+ const result = await transformAsync(source, {
357
+ filename: path,
358
+ babelrc: false,
359
+ configFile: false,
360
+ plugins: [
361
+ [solidBabel, { moduleName: "@solidjs/web", generate: target === "server" ? "ssr" : "dom", hydratable: true }]
362
+ ],
363
+ presets: [presetTypescript]
364
+ });
365
+ if (!result?.code)
366
+ throw new Error(`Babel produced no output for ${path}`);
367
+ return target === "server" ? serverPortal(result.code) : result.code;
368
+ }
369
+ function solidPlugin({ target, dev, hmr, rootDir, buildDir }) {
370
+ const hot = hmr && target === "client";
371
+ const appModule = appModuleId(rootDir, buildDir);
372
+ return {
373
+ name: `hamur-solid-${target}`,
374
+ filter: { id: /\.[jt]sx$/ },
375
+ async transform(code, { id: path }) {
376
+ if (path.includes("/node_modules/"))
377
+ return;
378
+ let source = code;
379
+ if (!dev)
380
+ source = dropDevOnly(source, "@hamur/adapter-solid", "markup");
381
+ else {
382
+ const file = appModule(path);
383
+ if (file !== undefined)
384
+ source = locateJsx(source, file);
385
+ }
386
+ if (hot) {
387
+ const id = appModule(path);
388
+ const layerRoute = id === undefined ? relative(rootDir, path) : undefined;
389
+ if (id !== undefined)
390
+ source = shimImports(refreshTransform(source, { id, route: ROUTE_MODULE.test(id) }).code);
391
+ else if (ROUTE_MODULE.test(layerRoute))
392
+ source = shimImports(refreshTransform(source, { id: layerRoute, route: true }).code);
393
+ }
394
+ return { code: await compileSolid(path, source, target), loader: "js" };
395
+ }
396
+ };
397
+ }
398
+ var DEV_CONDITIONS = new Set(["browser", "development", "import", "default"]);
399
+ var SOLID_IMPORT = /(\bfrom\s*|\bimport\s*\(?\s*)(["'])(solid-js(?:\/internal)?|@solidjs\/(?:web|signals))\2/g;
400
+ function exportTarget(target) {
401
+ if (typeof target === "string")
402
+ return target;
403
+ if (target === null || typeof target !== "object")
404
+ return;
405
+ for (const [condition, value] of Object.entries(target)) {
406
+ if (!DEV_CONDITIONS.has(condition))
407
+ continue;
408
+ const found = exportTarget(value);
409
+ if (found !== undefined)
410
+ return found;
411
+ }
412
+ return;
413
+ }
414
+ function solidDevFiles(rootDir) {
415
+ const solid = Bun.resolveSync("solid-js/package.json", rootDir);
416
+ const manifests = {
417
+ "solid-js": solid,
418
+ "@solidjs/web": Bun.resolveSync("@solidjs/web/package.json", rootDir),
419
+ "@solidjs/signals": Bun.resolveSync("@solidjs/signals/package.json", dirname(solid))
420
+ };
421
+ const files = {};
422
+ for (const [specifier, name, subpath] of [
423
+ ["solid-js", "solid-js", "."],
424
+ ["solid-js/internal", "solid-js", "./internal"],
425
+ ["@solidjs/web", "@solidjs/web", "."],
426
+ ["@solidjs/signals", "@solidjs/signals", "."]
427
+ ]) {
428
+ const manifest = manifests[name];
429
+ const { exports } = JSON.parse(readFileSync(manifest, "utf8"));
430
+ const target = exportTarget(exports[subpath]);
431
+ if (target === undefined)
432
+ throw new Error(`${name} has no development build for ${specifier}`);
433
+ files[specifier] = join(dirname(manifest), target);
434
+ }
435
+ return files;
436
+ }
437
+ function solidDevBuild({ rootDir }) {
438
+ let files;
439
+ return {
440
+ name: "hamur-solid-development",
441
+ filter: { id: /\.[cm]?[jt]sx?$/ },
442
+ transform(code) {
443
+ if (!code.includes("solid-js") && !code.includes("@solidjs/"))
444
+ return;
445
+ files ??= solidDevFiles(rootDir);
446
+ const found = files;
447
+ const contents = code.replace(SOLID_IMPORT, (_, head, quote, specifier) => `${head}${quote}${found[specifier]}${quote}`);
448
+ return contents === code ? undefined : contents;
449
+ }
450
+ };
451
+ }
452
+ function solidHydrationPlugin() {
453
+ return {
454
+ name: "hamur-solid-hydration",
455
+ filter: { id: new RegExp(`^${CLIENT_RUNTIME.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`) },
456
+ transform: (code) => `import ${JSON.stringify(HYDRATION_DEV)}; ${code}`
457
+ };
458
+ }
459
+
460
+ // packages/adapter-solid/src/svg.ts
461
+ import { svgCode } from "hamur/adapter";
462
+ var attributesCode = (code, attrs) => Object.entries(attrs).map(([name, value]) => name === "style" ? ` style={isServer ? ${code.value(value)} : undefined} ref={(element) => element.setAttribute("style", ${code.value(value)})}` : ` ${name}={${code.value(value)}}`).join("");
463
+ function nodeCode(code, node) {
464
+ if (typeof node === "string" || Array.isArray(node))
465
+ return `{${code.value(node)}}`;
466
+ return `<${node.tag}${attributesCode(code, code.attrs(node))}>${node.children.map((child) => nodeCode(code, child)).join("")}</${node.tag}>`;
467
+ }
468
+ function module(svg) {
469
+ const code = svgCode(svg, { title: "props.title", props: "rest" });
470
+ const hidden = code.hidden ? ` aria-hidden={${code.hidden} ? "true" : undefined}` : "";
471
+ const contents = `import { createRenderEffect, createUniqueId, isHydrating, omit } from "solid-js";
472
+ import { dynamic, isServer } from "@solidjs/web";
473
+
474
+ const Title = dynamic(() => "title", { static: true });
475
+
476
+ // Solid compiles a title element outside the root template as an HTML element; a client render makes it in the SVG namespace.
477
+ function SvgTitle(props) {
478
+ if (isServer || isHydrating()) return <Title>{props.text}</Title>;
479
+ const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
480
+ createRenderEffect(() => props.text, (text) => {
481
+ title.textContent = text;
482
+ });
483
+ return title;
484
+ }
485
+
486
+ export default function SvgComponent(props) {
487
+ const rest = omit(props, "title");
488
+ const uid = createUniqueId().replace(/[^\\w-]/g, "_");
489
+ return (
490
+ <svg${attributesCode(code, svg.attrs)}${hidden} {...rest}>
491
+ {props.title != null && <SvgTitle text={props.title} />}
492
+ ${svg.children.map((child) => nodeCode(code, child)).join("")}
493
+ </svg>
494
+ );
495
+ }
496
+ `;
497
+ return { contents, extension: ".jsx" };
498
+ }
499
+ var svgComponent = {
500
+ types: `import("solid-js").Component<import("@solidjs/web").JSX.SvgSVGAttributes<SVGSVGElement> & { title?: string }>`,
501
+ module
502
+ };
503
+
504
+ // packages/adapter-solid/src/markdown-page.ts
505
+ import { markdownPageCode } from "hamur/adapter/build";
506
+ function module2(source) {
507
+ const { imports, value, props, head } = markdownPageCode(source);
508
+ const contents = `${imports}import { createComponent } from "solid-js";
509
+ import { MarkdownRenderer, useHead } from "@hamur/adapter-solid";
510
+
511
+ const value = ${value};
512
+
513
+ export default function MarkdownPage() {
514
+ ${head ? ` useHead(${head});
515
+ ` : ""} return createComponent(MarkdownRenderer, ${props});
516
+ }
517
+ `;
518
+ return { contents, extension: ".js" };
519
+ }
520
+ var markdownComponent = { module: module2 };
521
+
522
+ // packages/adapter-solid/src/adapter.ts
523
+ function assertSolid2(rootDir) {
524
+ const { version } = JSON.parse(readFileSync2(Bun.resolveSync("solid-js/package.json", rootDir), "utf8"));
525
+ if (version.split(".")[0] === "2")
526
+ return;
527
+ throw new Error(`@hamur/adapter-solid supports Solid 2 only: solid-js ${version} is installed in ${rootDir}. Install it with: bun add solid-js@latest @solidjs/web@latest @solidjs/babel-plugin@latest`);
528
+ }
529
+ var adapter_default = defineAdapter({
530
+ name: "solid",
531
+ contract: ADAPTER_CONTRACT,
532
+ extensions: [".tsx", ".jsx"],
533
+ clientEntry: "@hamur/adapter-solid/runtime/client",
534
+ serverEntry: "@hamur/adapter-solid/runtime/server",
535
+ keepAliveOutlet: "@hamur/adapter-solid/runtime/keepalive",
536
+ islandEntry: "@hamur/adapter-solid/runtime/island",
537
+ errorPage: "@hamur/adapter-solid/error-page",
538
+ plugins: (ctx) => {
539
+ assertSolid2(ctx.rootDir);
540
+ return [];
541
+ },
542
+ transforms: (ctx) => [
543
+ solidPlugin(ctx),
544
+ ...ctx.dev && ctx.target === "client" ? [solidDevBuild(ctx), solidHydrationPlugin()] : []
545
+ ],
546
+ peers: ["solid-js", "@solidjs/web", "@solidjs/babel-plugin", "@babel/core", "@babel/preset-typescript"],
547
+ trustedTypesPolicies: ["solid-trusted-html"],
548
+ svgComponent,
549
+ markdownComponent,
550
+ serverComponent: { module: (component) => serverComponentModule(component, "@hamur/adapter-solid/runtime") },
551
+ clientComponent: { module: (component) => clientComponentModule(component, "@hamur/adapter-solid/runtime") }
552
+ });
553
+ export {
554
+ assertSolid2,
555
+ adapter_default as default
556
+ };