brumate 0.0.0-stage → 0.1.0

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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +68 -2
  3. package/dist/boot-DN1ZU8Hg.d.ts +37 -0
  4. package/dist/cli.d.ts +1 -0
  5. package/dist/cli.js +68 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/client-DwJInP_a.d.ts +279 -0
  8. package/dist/client-routes-DakuM32C.js +94 -0
  9. package/dist/client-routes-DakuM32C.js.map +1 -0
  10. package/dist/context-BG8KCF3v.js +15 -0
  11. package/dist/context-BG8KCF3v.js.map +1 -0
  12. package/dist/context-aeo9esY9.d.ts +16 -0
  13. package/dist/cookies-Av5WFmcf.js +175 -0
  14. package/dist/cookies-Av5WFmcf.js.map +1 -0
  15. package/dist/devtools-BKjnHrnv.js +113 -0
  16. package/dist/devtools-BKjnHrnv.js.map +1 -0
  17. package/dist/devtools-panel-AWOn0VK2.js +434 -0
  18. package/dist/devtools-panel-AWOn0VK2.js.map +1 -0
  19. package/dist/files-BBLPU9JR.js +177 -0
  20. package/dist/files-BBLPU9JR.js.map +1 -0
  21. package/dist/html-DEeoepg3.js +152 -0
  22. package/dist/html-DEeoepg3.js.map +1 -0
  23. package/dist/html-Du8jY2Cc.d.ts +53 -0
  24. package/dist/index.d.ts +2088 -0
  25. package/dist/index.js +707 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/inspect-CRZlO11T.js +6926 -0
  28. package/dist/inspect-CRZlO11T.js.map +1 -0
  29. package/dist/loader-Dc9OwY5I.js +101 -0
  30. package/dist/loader-Dc9OwY5I.js.map +1 -0
  31. package/dist/navigate-CzLjnoPH.js +422 -0
  32. package/dist/navigate-CzLjnoPH.js.map +1 -0
  33. package/dist/produce-BRGHP7e0.js +126 -0
  34. package/dist/produce-BRGHP7e0.js.map +1 -0
  35. package/dist/produce-CtZ32UGG.d.ts +60 -0
  36. package/dist/rpc-9fSqL_YK.js +128 -0
  37. package/dist/rpc-9fSqL_YK.js.map +1 -0
  38. package/dist/runtime/client.d.ts +5 -0
  39. package/dist/runtime/client.js +1345 -0
  40. package/dist/runtime/client.js.map +1 -0
  41. package/dist/runtime/context.d.ts +2 -0
  42. package/dist/runtime/context.js +1 -0
  43. package/dist/runtime/devtools.d.ts +36 -0
  44. package/dist/runtime/devtools.js +1 -0
  45. package/dist/runtime/hot.d.ts +36 -0
  46. package/dist/runtime/hot.js +44 -0
  47. package/dist/runtime/hot.js.map +1 -0
  48. package/dist/runtime/html.d.ts +2 -0
  49. package/dist/runtime/html.js +1 -0
  50. package/dist/runtime/loader.d.ts +12 -0
  51. package/dist/runtime/loader.js +3 -0
  52. package/dist/runtime/routes.d.ts +21 -0
  53. package/dist/runtime/routes.js +18 -0
  54. package/dist/runtime/routes.js.map +1 -0
  55. package/dist/runtime/server.d.ts +5 -0
  56. package/dist/runtime/server.js +7 -0
  57. package/dist/runtime/signals.d.ts +46 -0
  58. package/dist/runtime/signals.js +74 -0
  59. package/dist/runtime/signals.js.map +1 -0
  60. package/dist/runtime/static-loader.d.ts +3 -0
  61. package/dist/runtime/static-loader.js +1 -0
  62. package/dist/runtime/testing.d.ts +55 -0
  63. package/dist/runtime/testing.js +172 -0
  64. package/dist/runtime/testing.js.map +1 -0
  65. package/dist/server-BxqjLUnV.d.ts +753 -0
  66. package/dist/server-DZsgnPKS.js +1615 -0
  67. package/dist/server-DZsgnPKS.js.map +1 -0
  68. package/dist/shared-CWYOd0H3.js +40 -0
  69. package/dist/shared-CWYOd0H3.js.map +1 -0
  70. package/dist/static-loader-BcFh4ebX.d.ts +11 -0
  71. package/dist/static-loader-ClNkHZGn.js +185 -0
  72. package/dist/static-loader-ClNkHZGn.js.map +1 -0
  73. package/dist/stream-bgNCMcaA.js +280 -0
  74. package/dist/stream-bgNCMcaA.js.map +1 -0
  75. package/dist/vite.d.ts +146 -0
  76. package/dist/vite.js +1397 -0
  77. package/dist/vite.js.map +1 -0
  78. package/package.json +122 -3
  79. package/types.d.ts +41 -0
@@ -0,0 +1,177 @@
1
+ import { g as functionId } from "./inspect-CRZlO11T.js";
2
+ import { parseSync } from "oxc-parser";
3
+ import { readFile, readdir } from "node:fs/promises";
4
+ import path from "node:path";
5
+ //#region src/server-files.ts
6
+ /** The import of the stubs, which call server functions with `rpc` of the core. */
7
+ const CLIENT = "brumate/client";
8
+ /** True for a file whose first statement is `'use server'`, after comments. */
9
+ function hasUseServer(source) {
10
+ return /^(?:\s|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*(['"])use server\1/.test(source);
11
+ }
12
+ /** True for a path that can be a file of server functions. */
13
+ function isScriptFile(path) {
14
+ return /\.[cm]?[jt]sx?$/.test(path) && !path.endsWith(".d.ts") && !/\.brm\.[cm]?[jt]s$/.test(path);
15
+ }
16
+ /** True for a function expression or an arrow. */
17
+ function isFunction(node) {
18
+ return node?.type === "ArrowFunctionExpression" || node?.type === "FunctionExpression";
19
+ }
20
+ /**
21
+ * The names of the functions that a file of server functions exports.
22
+ * Throws for an export that is not a function, because the browser can only
23
+ * call a server function through its stub.
24
+ */
25
+ function serverExports(source, filename) {
26
+ const { program, errors } = parseSync(filename, source, { lang: "ts" });
27
+ if (errors[0]) throw new Error(`${errors[0].message} (${filename})`);
28
+ const functions = /* @__PURE__ */ new Set();
29
+ const values = /* @__PURE__ */ new Set();
30
+ const local = /* @__PURE__ */ new Map();
31
+ for (const statement of program.body) {
32
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
33
+ if (declaration?.type === "FunctionDeclaration" && declaration.id) local.set(declaration.id.name, "function");
34
+ else if (declaration?.type === "VariableDeclaration") {
35
+ for (const declarator of declaration.declarations) if (declarator.id.type === "Identifier") local.set(declarator.id.name, isFunction(declarator.init) ? "function" : "value");
36
+ }
37
+ }
38
+ for (const statement of program.body) if (statement.type === "ExportDefaultDeclaration") {
39
+ const value = statement.declaration;
40
+ if (value.type === "FunctionDeclaration" || isFunction(value)) functions.add("default");
41
+ else values.add("default");
42
+ } else if (statement.type === "ExportNamedDeclaration") {
43
+ if (statement.exportKind === "type") continue;
44
+ const declaration = statement.declaration;
45
+ if (declaration?.type === "FunctionDeclaration" && declaration.id) functions.add(declaration.id.name);
46
+ else if (declaration?.type === "VariableDeclaration") {
47
+ for (const declarator of declaration.declarations) if (declarator.id.type === "Identifier") (isFunction(declarator.init) ? functions : values).add(declarator.id.name);
48
+ } else if (declaration && !declaration.type.startsWith("TS")) values.add("a class");
49
+ for (const specifier of statement.specifiers) {
50
+ if (specifier.exportKind === "type") continue;
51
+ const name = specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value;
52
+ const from = specifier.local.type === "Identifier" ? specifier.local.name : "";
53
+ (local.get(from) === "function" && !statement.source ? functions : values).add(name);
54
+ }
55
+ } else if (statement.type === "ExportAllDeclaration") values.add("*");
56
+ if (values.size > 0) throw new Error(`A 'use server' file exports only functions, because the browser calls them on the server. ${[...values].join(", ")} of ${filename} is not one`);
57
+ return [...functions];
58
+ }
59
+ /** The module that the browser gets in place of a file of server functions. */
60
+ function serverStubs(source, filename, id, hideNames = false) {
61
+ const lines = [`import { rpc } from ${JSON.stringify(CLIENT)};`];
62
+ for (const name of serverExports(source, filename)) {
63
+ const call = `(...args) => rpc(${JSON.stringify(functionId(id, name, hideNames))}, args)`;
64
+ lines.push(name === "default" ? `export default ${call};` : `export const ${name} = ${call};`);
65
+ }
66
+ return `${lines.join("\n")}\n`;
67
+ }
68
+ /**
69
+ * The module that the server runs for a file of server functions: the file,
70
+ * with each exported function wrapped, so its calls while a page renders
71
+ * share a result when their arguments are the same. Offsets stay the same.
72
+ */
73
+ function serverModule(source, filename, id) {
74
+ const { program } = parseSync(filename, source, { lang: "ts" });
75
+ const wrapped = /* @__PURE__ */ new Map();
76
+ const declarations = /* @__PURE__ */ new Map();
77
+ let code = source;
78
+ for (const statement of program.body) {
79
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
80
+ if (declaration?.type === "FunctionDeclaration" && declaration.id) declarations.set(declaration.id.name, "function");
81
+ else if (declaration?.type === "VariableDeclaration") {
82
+ for (const declarator of declaration.declarations) if (declarator.id.type === "Identifier" && isFunction(declarator.init)) declarations.set(declarator.id.name, "const");
83
+ }
84
+ }
85
+ const letOf = (declaration) => {
86
+ if (declaration.kind === "const") code = `${code.slice(0, declaration.start)}let ${code.slice(declaration.start + 5)}`;
87
+ };
88
+ for (const statement of program.body) {
89
+ if (statement.type !== "ExportNamedDeclaration" || statement.source || statement.exportKind === "type") continue;
90
+ const declaration = statement.declaration;
91
+ if (declaration?.type === "FunctionDeclaration" && declaration.id) wrapped.set(declaration.id.name, declaration.id.name);
92
+ else if (declaration?.type === "VariableDeclaration") {
93
+ for (const declarator of declaration.declarations) if (declarator.id.type === "Identifier" && isFunction(declarator.init)) {
94
+ wrapped.set(declarator.id.name, declarator.id.name);
95
+ letOf(declaration);
96
+ }
97
+ }
98
+ for (const specifier of statement.specifiers) {
99
+ const local = specifier.local.type === "Identifier" ? specifier.local.name : "";
100
+ const exported = specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value;
101
+ if (declarations.has(local)) wrapped.set(local, exported);
102
+ }
103
+ }
104
+ for (const statement of program.body) if (statement.type === "VariableDeclaration") {
105
+ for (const declarator of statement.declarations) if (declarator.id.type === "Identifier" && wrapped.has(declarator.id.name)) letOf(statement);
106
+ }
107
+ if (wrapped.size === 0) return source;
108
+ const lines = ["import { dedupe as __brumateDedupe } from 'brumate/server';"];
109
+ for (const [local, exported] of wrapped) lines.push(`${local} = __brumateDedupe(${local}, ${JSON.stringify(`${id}#${exported}`)});`);
110
+ return `${code}\n${lines.join("\n")}\n`;
111
+ }
112
+ //#endregion
113
+ //#region src/files.ts
114
+ /** Skips `node_modules`, `dist` and hidden directories when looking for `.brm` files. */
115
+ function defaultExclude(directory) {
116
+ return directory === "node_modules" || directory === "dist" || directory.startsWith(".");
117
+ }
118
+ /** Finds every `.brm` file under a directory, as absolute paths with forward slashes. */
119
+ async function findFiles(root, exclude) {
120
+ const result = [];
121
+ const visit = async (directory) => {
122
+ const directories = [];
123
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
124
+ const file = path.join(directory, entry.name);
125
+ if (entry.isDirectory()) {
126
+ if (!exclude(entry.name)) directories.push(visit(file));
127
+ } else if (entry.name.endsWith(".brm")) result.push(file.split(path.sep).join("/"));
128
+ }
129
+ await Promise.all(directories);
130
+ };
131
+ await visit(root);
132
+ return result.toSorted();
133
+ }
134
+ /**
135
+ * Finds every file of server functions under a directory: a script whose
136
+ * first statement is `'use server'`.
137
+ */
138
+ async function findServerFiles(root, exclude) {
139
+ const result = [];
140
+ const visit = async (directory) => {
141
+ const pending = [];
142
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
143
+ const file = path.join(directory, entry.name);
144
+ if (entry.isDirectory()) {
145
+ if (!exclude(entry.name)) pending.push(visit(file));
146
+ } else if (isScriptFile(entry.name)) pending.push(readFile(file, "utf8").then((source) => {
147
+ if (hasUseServer(source)) result.push(file.split(path.sep).join("/"));
148
+ }));
149
+ }
150
+ await Promise.all(pending);
151
+ };
152
+ await visit(root);
153
+ return result.toSorted();
154
+ }
155
+ /**
156
+ * Finds every script under a directory, such as `.ts` and `.brm.ts` files, as
157
+ * absolute paths with forward slashes, without reading them.
158
+ */
159
+ async function findScripts(root, exclude) {
160
+ const result = [];
161
+ const visit = async (directory) => {
162
+ const directories = [];
163
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
164
+ const file = path.join(directory, entry.name);
165
+ if (entry.isDirectory()) {
166
+ if (!exclude(entry.name)) directories.push(visit(file));
167
+ } else if (/\.[cm]?[jt]sx?$/.test(entry.name) && !entry.name.endsWith(".d.ts")) result.push(file.split(path.sep).join("/"));
168
+ }
169
+ await Promise.all(directories);
170
+ };
171
+ await visit(root);
172
+ return result.toSorted();
173
+ }
174
+ //#endregion
175
+ export { hasUseServer as a, serverModule as c, findServerFiles as i, serverStubs as l, findFiles as n, isScriptFile as o, findScripts as r, serverExports as s, defaultExclude as t };
176
+
177
+ //# sourceMappingURL=files-BBLPU9JR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files-BBLPU9JR.js","names":[],"sources":["../src/server-files.ts","../src/files.ts"],"sourcesContent":["// Files of server functions. A `.ts` or `.js` file whose first statement is\n// `'use server'` holds functions that only run on the server. Its exports are\n// server functions: the browser gets a stub for each one, which calls the\n// server, and the code of the file never ships.\n\nimport { parseSync } from 'oxc-parser';\nimport { functionId } from './plan.ts';\n\n/** The import of the stubs, which call server functions with `rpc` of the core. */\nconst CLIENT = 'brumate/client';\n\n/** True for a file whose first statement is `'use server'`, after comments. */\nexport function hasUseServer(source: string): boolean {\n return /^(?:\\s|\\/\\/[^\\n]*\\n|\\/\\*[\\s\\S]*?\\*\\/)*(['\"])use server\\1/.test(source);\n}\n\n/** True for a path that can be a file of server functions. */\nexport function isScriptFile(path: string): boolean {\n return (\n /\\.[cm]?[jt]sx?$/.test(path) && !path.endsWith('.d.ts') && !/\\.brm\\.[cm]?[jt]s$/.test(path)\n );\n}\n\n/** True for a function expression or an arrow. */\nfunction isFunction(node: { type: string } | null | undefined): boolean {\n return node?.type === 'ArrowFunctionExpression' || node?.type === 'FunctionExpression';\n}\n\n/**\n * The names of the functions that a file of server functions exports.\n * Throws for an export that is not a function, because the browser can only\n * call a server function through its stub.\n */\nexport function serverExports(source: string, filename: string): string[] {\n const { program, errors } = parseSync(filename, source, { lang: 'ts' });\n if (errors[0]) {\n throw new Error(`${errors[0].message} (${filename})`);\n }\n const functions = new Set<string>();\n const values = new Set<string>();\n const local = new Map<string, 'function' | 'value'>();\n for (const statement of program.body) {\n const declaration =\n statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n local.set(declaration.id.name, 'function');\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier') {\n local.set(declarator.id.name, isFunction(declarator.init) ? 'function' : 'value');\n }\n }\n }\n }\n for (const statement of program.body) {\n if (statement.type === 'ExportDefaultDeclaration') {\n const value = statement.declaration;\n if (value.type === 'FunctionDeclaration' || isFunction(value)) {\n functions.add('default');\n } else {\n values.add('default');\n }\n } else if (statement.type === 'ExportNamedDeclaration') {\n if (statement.exportKind === 'type') {\n continue;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n functions.add(declaration.id.name);\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier') {\n (isFunction(declarator.init) ? functions : values).add(declarator.id.name);\n }\n }\n } else if (declaration && !declaration.type.startsWith('TS')) {\n values.add('a class');\n }\n for (const specifier of statement.specifiers) {\n if (specifier.exportKind === 'type') {\n continue;\n }\n const name =\n specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value;\n const from = specifier.local.type === 'Identifier' ? specifier.local.name : '';\n (local.get(from) === 'function' && !statement.source ? functions : values).add(name);\n }\n } else if (statement.type === 'ExportAllDeclaration') {\n values.add('*');\n }\n }\n if (values.size > 0) {\n throw new Error(\n `A 'use server' file exports only functions, because the browser calls them on the server. ${[...values].join(', ')} of ${filename} is not one`,\n );\n }\n return [...functions];\n}\n\n/** The module that the browser gets in place of a file of server functions. */\nexport function serverStubs(\n source: string,\n filename: string,\n id: string,\n hideNames = false,\n): string {\n const lines = [`import { rpc } from ${JSON.stringify(CLIENT)};`];\n for (const name of serverExports(source, filename)) {\n const call = `(...args) => rpc(${JSON.stringify(functionId(id, name, hideNames))}, args)`;\n lines.push(name === 'default' ? `export default ${call};` : `export const ${name} = ${call};`);\n }\n return `${lines.join('\\n')}\\n`;\n}\n\n/**\n * The module that the server runs for a file of server functions: the file,\n * with each exported function wrapped, so its calls while a page renders\n * share a result when their arguments are the same. Offsets stay the same.\n */\nexport function serverModule(source: string, filename: string, id: string): string {\n const { program } = parseSync(filename, source, { lang: 'ts' });\n // Local names of exported functions, with the name that each is exported as.\n const wrapped = new Map<string, string>();\n const declarations = new Map<string, 'function' | 'const'>();\n let code = source;\n for (const statement of program.body) {\n const declaration =\n statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n declarations.set(declaration.id.name, 'function');\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier' && isFunction(declarator.init)) {\n declarations.set(declarator.id.name, 'const');\n }\n }\n }\n }\n const letOf = (declaration: { start: number; kind: string }): void => {\n // `const` becomes `let `, so the function can be wrapped and offsets stay the same.\n if (declaration.kind === 'const') {\n code = `${code.slice(0, declaration.start)}let ${code.slice(declaration.start + 5)}`;\n }\n };\n for (const statement of program.body) {\n if (\n statement.type !== 'ExportNamedDeclaration' ||\n statement.source ||\n statement.exportKind === 'type'\n ) {\n continue;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n wrapped.set(declaration.id.name, declaration.id.name);\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier' && isFunction(declarator.init)) {\n wrapped.set(declarator.id.name, declarator.id.name);\n letOf(declaration);\n }\n }\n }\n for (const specifier of statement.specifiers) {\n const local = specifier.local.type === 'Identifier' ? specifier.local.name : '';\n const exported =\n specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value;\n if (declarations.has(local)) {\n wrapped.set(local, exported);\n }\n }\n }\n // A `const` arrow that `export { name }` exports is declared with `let` too.\n for (const statement of program.body) {\n if (statement.type === 'VariableDeclaration') {\n for (const declarator of statement.declarations) {\n if (declarator.id.type === 'Identifier' && wrapped.has(declarator.id.name)) {\n letOf(statement);\n }\n }\n }\n }\n if (wrapped.size === 0) {\n return source;\n }\n const lines = [\"import { dedupe as __brumateDedupe } from 'brumate/server';\"];\n for (const [local, exported] of wrapped) {\n lines.push(`${local} = __brumateDedupe(${local}, ${JSON.stringify(`${id}#${exported}`)});`);\n }\n return `${code}\\n${lines.join('\\n')}\\n`;\n}\n","import { readFile, readdir } from 'node:fs/promises';\nimport path from 'node:path';\nimport { hasUseServer, isScriptFile } from './server-files.ts';\n\n/** Skips `node_modules`, `dist` and hidden directories when looking for `.brm` files. */\nexport function defaultExclude(directory: string): boolean {\n return directory === 'node_modules' || directory === 'dist' || directory.startsWith('.');\n}\n\n/** Finds every `.brm` file under a directory, as absolute paths with forward slashes. */\nexport async function findFiles(\n root: string,\n exclude: (directory: string) => boolean,\n): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n const directories: Promise<void>[] = [];\n for (const entry of await readdir(directory, { withFileTypes: true })) {\n const file = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n if (!exclude(entry.name)) {\n directories.push(visit(file));\n }\n } else if (entry.name.endsWith('.brm')) {\n result.push(file.split(path.sep).join('/'));\n }\n }\n await Promise.all(directories);\n };\n await visit(root);\n return result.toSorted();\n}\n\n/**\n * Finds every file of server functions under a directory: a script whose\n * first statement is `'use server'`.\n */\nexport async function findServerFiles(\n root: string,\n exclude: (directory: string) => boolean,\n): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n const pending: Promise<void>[] = [];\n for (const entry of await readdir(directory, { withFileTypes: true })) {\n const file = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n if (!exclude(entry.name)) {\n pending.push(visit(file));\n }\n } else if (isScriptFile(entry.name)) {\n pending.push(\n readFile(file, 'utf8').then((source) => {\n if (hasUseServer(source)) {\n result.push(file.split(path.sep).join('/'));\n }\n }),\n );\n }\n }\n await Promise.all(pending);\n };\n await visit(root);\n return result.toSorted();\n}\n\n/**\n * Finds every script under a directory, such as `.ts` and `.brm.ts` files, as\n * absolute paths with forward slashes, without reading them.\n */\nexport async function findScripts(\n root: string,\n exclude: (directory: string) => boolean,\n): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n const directories: Promise<void>[] = [];\n for (const entry of await readdir(directory, { withFileTypes: true })) {\n const file = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n if (!exclude(entry.name)) {\n directories.push(visit(file));\n }\n } else if (/\\.[cm]?[jt]sx?$/.test(entry.name) && !entry.name.endsWith('.d.ts')) {\n result.push(file.split(path.sep).join('/'));\n }\n }\n await Promise.all(directories);\n };\n await visit(root);\n return result.toSorted();\n}\n"],"mappings":";;;;;;AASA,MAAM,SAAS;;AAGf,SAAgB,aAAa,QAAyB;CACpD,OAAO,2DAA2D,KAAK,MAAM;AAC/E;;AAGA,SAAgB,aAAa,MAAuB;CAClD,OACE,kBAAkB,KAAK,IAAI,KAAK,CAAC,KAAK,SAAS,OAAO,KAAK,CAAC,qBAAqB,KAAK,IAAI;AAE9F;;AAGA,SAAS,WAAW,MAAoD;CACtE,OAAO,MAAM,SAAS,6BAA6B,MAAM,SAAS;AACpE;;;;;;AAOA,SAAgB,cAAc,QAAgB,UAA4B;CACxE,MAAM,EAAE,SAAS,WAAW,UAAU,UAAU,QAAQ,EAAE,MAAM,KAAK,CAAC;CACtE,IAAI,OAAO,IACT,MAAM,IAAI,MAAM,GAAG,OAAO,EAAE,CAAC,QAAQ,IAAI,SAAS,EAAE;CAEtD,MAAM,4BAAY,IAAI,IAAY;CAClC,MAAM,yBAAS,IAAI,IAAY;CAC/B,MAAM,wBAAQ,IAAI,IAAkC;CACpD,KAAK,MAAM,aAAa,QAAQ,MAAM;EACpC,MAAM,cACJ,UAAU,SAAS,2BAA2B,UAAU,cAAc;EACxE,IAAI,aAAa,SAAS,yBAAyB,YAAY,IAC7D,MAAM,IAAI,YAAY,GAAG,MAAM,UAAU;OACpC,IAAI,aAAa,SAAS,uBAC1B;QAAA,MAAM,cAAc,YAAY,cACnC,IAAI,WAAW,GAAG,SAAS,cACzB,MAAM,IAAI,WAAW,GAAG,MAAM,WAAW,WAAW,IA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B,YAAY,KAAK,MAAM,IAAI,CAAC;GAAA,OAEzB,IAAI,kBAAkB,KAAK,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,OAAO,GAC3E,OAAO,KAAK,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;EAE9C;EACA,MAAM,QAAQ,IAAI,WAAW;CAC/B;CACA,MAAM,MAAM,IAAI;CAChB,OAAO,OAAO,SAAS;AACzB"}
@@ -0,0 +1,152 @@
1
+ //#region src/runtime/html.ts
2
+ const RAW = Symbol.for("brumate.raw");
3
+ var RawHTML = class {
4
+ [RAW];
5
+ constructor(html) {
6
+ this[RAW] = html;
7
+ }
8
+ };
9
+ function raw(html) {
10
+ return new RawHTML(html);
11
+ }
12
+ function isRaw(value) {
13
+ return typeof value === "object" && value !== null && RAW in value;
14
+ }
15
+ function rawHTML(value) {
16
+ return value[RAW];
17
+ }
18
+ const ESCAPES = {
19
+ "&": "&amp;",
20
+ "<": "&lt;",
21
+ ">": "&gt;",
22
+ "\"": "&quot;"
23
+ };
24
+ const toEscape = (char) => ESCAPES[char];
25
+ function escape(value) {
26
+ return /[&<>]/.test(value) ? value.replace(/[&<>]/g, toEscape) : value;
27
+ }
28
+ function escapeAttribute(value) {
29
+ return /[&<"]/.test(value) ? value.replace(/[&<"]/g, toEscape) : value;
30
+ }
31
+ /** Renders a value inserted in markup. Promises are not awaited. */
32
+ function insertValue(value) {
33
+ if (isRaw(value)) return value[RAW];
34
+ if (value === null || value === void 0 || typeof value === "boolean") return "";
35
+ if (Array.isArray(value)) return value.map(insertValue).join("");
36
+ return escape(String(value));
37
+ }
38
+ /**
39
+ * Renders a value as the text of an element whose content is text, such as
40
+ * a `<textarea>`, as `insertValue` does but without escaping.
41
+ */
42
+ function textValue(value) {
43
+ if (isRaw(value)) return value[RAW];
44
+ if (value === null || value === void 0 || typeof value === "boolean") return "";
45
+ if (Array.isArray(value)) return value.map(textValue).join("");
46
+ return String(value);
47
+ }
48
+ function toKebabCase(name) {
49
+ return name.startsWith("--") ? name : name.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
50
+ }
51
+ function classValue(value) {
52
+ if (typeof value !== "object" || value === null) return value ? String(value) : "";
53
+ let text = "";
54
+ if (Array.isArray(value)) {
55
+ for (const item of value) {
56
+ const part = classValue(item);
57
+ if (part !== "") text = text === "" ? part : `${text} ${part}`;
58
+ }
59
+ return text;
60
+ }
61
+ let first = true;
62
+ for (const name in value) if (Object.hasOwn(value, name) && value[name]) {
63
+ text = first ? name : `${text} ${name}`;
64
+ first = false;
65
+ }
66
+ return text;
67
+ }
68
+ /**
69
+ * Renders a `class` attribute from classes that each have a space before
70
+ * them, which the compiler builds from a literal class value. The classes
71
+ * are escaped already. No class renders nothing.
72
+ */
73
+ function classAttribute(classes) {
74
+ return classes === "" ? "" : ` class="${classes.slice(1)}"`;
75
+ }
76
+ function styleValue(value) {
77
+ if (typeof value === "object" && value !== null) return Object.entries(value).filter(([, item]) => item !== null && item !== void 0 && item !== false).map(([name, item]) => `${toKebabCase(name)}:${String(item)}`).join(";");
78
+ return String(value);
79
+ }
80
+ /**
81
+ * Returns the text of an attribute, or undefined if the attribute is not
82
+ * rendered. `true` renders as an empty value.
83
+ */
84
+ function attributeText(name, value) {
85
+ if (value === null || value === void 0 || value === false || typeof value === "function") return;
86
+ if (value === true) return "";
87
+ if (name === "class") {
88
+ const text = classValue(value);
89
+ return text === "" ? void 0 : text;
90
+ }
91
+ return name === "style" ? styleValue(value) : String(value);
92
+ }
93
+ /** Renders one attribute, with a leading space. */
94
+ function attribute(name, value) {
95
+ const text = attributeText(name, value);
96
+ if (text === void 0) return "";
97
+ return value === true ? ` ${name}` : ` ${name}="${escapeAttribute(text)}"`;
98
+ }
99
+ /**
100
+ * Returns the value of a style variable with text around it, such as `12px`
101
+ * for `${size}px`. A value that sets no variable stays as it is.
102
+ */
103
+ function affix(prefix, value, suffix) {
104
+ return value === null || value === void 0 || value === false ? value : `${prefix}${String(value)}${suffix}`;
105
+ }
106
+ /** Returns a style with custom properties before an element's own style. */
107
+ function vars(variables, own) {
108
+ const parts = [];
109
+ for (const [name, value] of Object.entries(variables)) if (value !== null && value !== void 0 && value !== false) parts.push(`${name}:${String(value)}`);
110
+ const rest = own === null || own === void 0 || own === false ? "" : styleValue(own);
111
+ if (rest) parts.push(rest);
112
+ return parts.join(";");
113
+ }
114
+ /** Returns a `<style>` element for a component's stylesheet. */
115
+ function styleElement(id, css) {
116
+ return `<style b-style="${escapeAttribute(id)}">${css.replace(/<\/style/gi, "<\\/style")}</style>`;
117
+ }
118
+ /** Renders an object of attributes. */
119
+ function spread(attributes) {
120
+ let result = "";
121
+ for (const [name, value] of Object.entries(attributes)) if (name !== "children" && !/^on[A-Z]/.test(name)) result += attribute(name, value);
122
+ return result;
123
+ }
124
+ const VOID_ELEMENTS = /* @__PURE__ */ new Set([
125
+ "area",
126
+ "base",
127
+ "br",
128
+ "col",
129
+ "embed",
130
+ "hr",
131
+ "img",
132
+ "input",
133
+ "link",
134
+ "meta",
135
+ "source",
136
+ "track",
137
+ "wbr"
138
+ ]);
139
+ /**
140
+ * Renders the attributes of a form that posts to a server function, such as
141
+ * ` action="/_brumate/App_1abc%23save" method="post"`. `method` is the name of
142
+ * the method attribute to add, if the element has none.
143
+ */
144
+ function actionAttributes(prefix, name, id, method, result) {
145
+ const methodText = method ? ` ${method}="post"` : "";
146
+ if (result !== void 0) return ` ${name}="?__action=${encodeURIComponent(id)}"${methodText} b-action="${escapeAttribute(id)}" b-result="${escapeAttribute(result)}"`;
147
+ return ` ${name}="${escapeAttribute(`${prefix}/${encodeURIComponent(id)}`)}"${methodText}`;
148
+ }
149
+ //#endregion
150
+ export { vars as _, attributeText as a, escape as c, isRaw as d, raw as f, textValue as g, styleElement as h, attribute as i, escapeAttribute as l, spread as m, actionAttributes as n, classAttribute as o, rawHTML as p, affix as r, classValue as s, VOID_ELEMENTS as t, insertValue as u };
151
+
152
+ //# sourceMappingURL=html-DEeoepg3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-DEeoepg3.js","names":[],"sources":["../src/runtime/html.ts"],"sourcesContent":["// HTML string helpers that the server and the client both use.\n\nconst RAW: unique symbol = Symbol.for('brumate.raw');\n\n/** HTML that is inserted as it is, such as the output of a template. */\nexport interface Raw {\n [RAW]: string;\n}\n\n// A class, not an object literal, so serializers can skip their test for raw HTML on plain objects.\nclass RawHTML implements Raw {\n readonly [RAW]: string;\n\n constructor(html: string) {\n this[RAW] = html;\n }\n}\n\nexport function raw(html: string): Raw {\n return new RawHTML(html);\n}\n\nexport function isRaw(value: unknown): value is Raw {\n return typeof value === 'object' && value !== null && RAW in value;\n}\n\nexport function rawHTML(value: Raw): string {\n return value[RAW];\n}\n\nconst ESCAPES: Record<string, string> = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;' };\n\nconst toEscape = (char: string): string => ESCAPES[char]!;\n\n// Most text has nothing to escape, so a test without the global flag skips the replace.\nexport function escape(value: string): string {\n return /[&<>]/.test(value) ? value.replace(/[&<>]/g, toEscape) : value;\n}\n\nexport function escapeAttribute(value: string): string {\n return /[&<\"]/.test(value) ? value.replace(/[&<\"]/g, toEscape) : value;\n}\n\n/** Renders a value inserted in markup. Promises are not awaited. */\nexport function insertValue(value: unknown): string {\n if (isRaw(value)) {\n return value[RAW];\n }\n if (value === null || value === undefined || typeof value === 'boolean') {\n return '';\n }\n if (Array.isArray(value)) {\n return value.map(insertValue).join('');\n }\n return escape(String(value));\n}\n\n/**\n * Renders a value as the text of an element whose content is text, such as\n * a `<textarea>`, as `insertValue` does but without escaping.\n */\nexport function textValue(value: unknown): string {\n if (isRaw(value)) {\n return value[RAW];\n }\n if (value === null || value === undefined || typeof value === 'boolean') {\n return '';\n }\n if (Array.isArray(value)) {\n return value.map(textValue).join('');\n }\n return String(value);\n}\n\nfunction toKebabCase(name: string): string {\n return name.startsWith('--') ? name : name.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);\n}\n\nexport function classValue(value: unknown): string {\n if (typeof value !== 'object' || value === null) {\n return value ? String(value) : '';\n }\n let text = '';\n if (Array.isArray(value)) {\n for (const item of value) {\n const part = classValue(item);\n if (part !== '') {\n text = text === '' ? part : `${text} ${part}`;\n }\n }\n return text;\n }\n // An empty name still adds a space between its neighbours, as in a join.\n let first = true;\n for (const name in value) {\n if (Object.hasOwn(value, name) && (value as Record<string, unknown>)[name]) {\n text = first ? name : `${text} ${name}`;\n first = false;\n }\n }\n return text;\n}\n\n/**\n * Renders a `class` attribute from classes that each have a space before\n * them, which the compiler builds from a literal class value. The classes\n * are escaped already. No class renders nothing.\n */\nexport function classAttribute(classes: string): string {\n return classes === '' ? '' : ` class=\"${classes.slice(1)}\"`;\n}\n\nfunction styleValue(value: unknown): string {\n if (typeof value === 'object' && value !== null) {\n return Object.entries(value)\n .filter(([, item]) => item !== null && item !== undefined && item !== false)\n .map(([name, item]) => `${toKebabCase(name)}:${String(item)}`)\n .join(';');\n }\n return String(value);\n}\n\n/**\n * Returns the text of an attribute, or undefined if the attribute is not\n * rendered. `true` renders as an empty value.\n */\nexport function attributeText(name: string, value: unknown): string | undefined {\n if (value === null || value === undefined || value === false || typeof value === 'function') {\n return undefined;\n }\n if (value === true) {\n return '';\n }\n if (name === 'class') {\n const text = classValue(value);\n return text === '' ? undefined : text;\n }\n return name === 'style' ? styleValue(value) : String(value);\n}\n\n/** Renders one attribute, with a leading space. */\nexport function attribute(name: string, value: unknown): string {\n const text = attributeText(name, value);\n if (text === undefined) {\n return '';\n }\n return value === true ? ` ${name}` : ` ${name}=\"${escapeAttribute(text)}\"`;\n}\n\n/**\n * Returns the value of a style variable with text around it, such as `12px`\n * for `${size}px`. A value that sets no variable stays as it is.\n */\nexport function affix(prefix: string, value: unknown, suffix: string): unknown {\n return value === null || value === undefined || value === false\n ? value\n : `${prefix}${String(value)}${suffix}`;\n}\n\n/** Returns a style with custom properties before an element's own style. */\nexport function vars(variables: Record<string, unknown>, own: unknown): string {\n const parts: string[] = [];\n for (const [name, value] of Object.entries(variables)) {\n if (value !== null && value !== undefined && value !== false) {\n parts.push(`${name}:${String(value)}`);\n }\n }\n const rest = own === null || own === undefined || own === false ? '' : styleValue(own);\n if (rest) {\n parts.push(rest);\n }\n return parts.join(';');\n}\n\n/** Returns a `<style>` element for a component's stylesheet. */\nexport function styleElement(id: string, css: string): string {\n return `<style b-style=\"${escapeAttribute(id)}\">${css.replace(/<\\/style/gi, '<\\\\/style')}</style>`;\n}\n\n/** Renders an object of attributes. */\nexport function spread(attributes: Record<string, unknown>): string {\n let result = '';\n for (const [name, value] of Object.entries(attributes)) {\n if (name !== 'children' && !/^on[A-Z]/.test(name)) {\n result += attribute(name, value);\n }\n }\n return result;\n}\n\nexport const VOID_ELEMENTS: Set<string> = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'source',\n 'track',\n 'wbr',\n]);\n\n/**\n * Renders the attributes of a form that posts to a server function, such as\n * ` action=\"/_brumate/App_1abc%23save\" method=\"post\"`. `method` is the name of\n * the method attribute to add, if the element has none.\n */\nexport function actionAttributes(\n prefix: string,\n name: string,\n id: string,\n method?: string,\n result?: string,\n): string {\n const methodText = method ? ` ${method}=\"post\"` : '';\n if (result !== undefined) {\n // The form posts to its page, which renders with the result. With the\n // loader, the result is written into the `$action` at `result` instead.\n return ` ${name}=\"?__action=${encodeURIComponent(id)}\"${methodText} b-action=\"${escapeAttribute(id)}\" b-result=\"${escapeAttribute(result)}\"`;\n }\n const url = `${prefix}/${encodeURIComponent(id)}`;\n return ` ${name}=\"${escapeAttribute(url)}\"${methodText}`;\n}\n"],"mappings":";AAEA,MAAM,MAAqB,OAAO,IAAI,aAAa;AAQnD,IAAM,UAAN,MAA6B;CAC3B,CAAU;CAEV,YAAY,MAAc;EACxB,KAAK,OAAO;CACd;AACF;AAEA,SAAgB,IAAI,MAAmB;CACrC,OAAO,IAAI,QAAQ,IAAI;AACzB;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ADrB,OAAO,GAAG,mBAAmB,EAAE,GACP,EAAE,GAAG;AAC9C"}
@@ -0,0 +1,53 @@
1
+ //#region src/runtime/html.d.ts
2
+ declare const RAW: unique symbol;
3
+ /** HTML that is inserted as it is, such as the output of a template. */
4
+ interface Raw {
5
+ [RAW]: string;
6
+ }
7
+ declare function raw(html: string): Raw;
8
+ declare function isRaw(value: unknown): value is Raw;
9
+ declare function rawHTML(value: Raw): string;
10
+ declare function escape(value: string): string;
11
+ declare function escapeAttribute(value: string): string;
12
+ /** Renders a value inserted in markup. Promises are not awaited. */
13
+ declare function insertValue(value: unknown): string;
14
+ /**
15
+ * Renders a value as the text of an element whose content is text, such as
16
+ * a `<textarea>`, as `insertValue` does but without escaping.
17
+ */
18
+ declare function textValue(value: unknown): string;
19
+ declare function classValue(value: unknown): string;
20
+ /**
21
+ * Renders a `class` attribute from classes that each have a space before
22
+ * them, which the compiler builds from a literal class value. The classes
23
+ * are escaped already. No class renders nothing.
24
+ */
25
+ declare function classAttribute(classes: string): string;
26
+ /**
27
+ * Returns the text of an attribute, or undefined if the attribute is not
28
+ * rendered. `true` renders as an empty value.
29
+ */
30
+ declare function attributeText(name: string, value: unknown): string | undefined;
31
+ /** Renders one attribute, with a leading space. */
32
+ declare function attribute(name: string, value: unknown): string;
33
+ /**
34
+ * Returns the value of a style variable with text around it, such as `12px`
35
+ * for `${size}px`. A value that sets no variable stays as it is.
36
+ */
37
+ declare function affix(prefix: string, value: unknown, suffix: string): unknown;
38
+ /** Returns a style with custom properties before an element's own style. */
39
+ declare function vars(variables: Record<string, unknown>, own: unknown): string;
40
+ /** Returns a `<style>` element for a component's stylesheet. */
41
+ declare function styleElement(id: string, css: string): string;
42
+ /** Renders an object of attributes. */
43
+ declare function spread(attributes: Record<string, unknown>): string;
44
+ declare const VOID_ELEMENTS: Set<string>;
45
+ /**
46
+ * Renders the attributes of a form that posts to a server function, such as
47
+ * ` action="/_brumate/App_1abc%23save" method="post"`. `method` is the name of
48
+ * the method attribute to add, if the element has none.
49
+ */
50
+ declare function actionAttributes(prefix: string, name: string, id: string, method?: string, result?: string): string;
51
+ //#endregion
52
+ export { textValue as _, attribute as a, classValue as c, insertValue as d, isRaw as f, styleElement as g, spread as h, affix as i, escape as l, rawHTML as m, VOID_ELEMENTS as n, attributeText as o, raw as p, actionAttributes as r, classAttribute as s, Raw as t, escapeAttribute as u, vars as v };
53
+ //# sourceMappingURL=html-Du8jY2Cc.d.ts.map