brumate 0.6.2 → 0.7.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.
- package/check.d.ts +3 -3
- package/dist/{boot-DkbcqdUz.d.ts → boot-CMy0f_iC.d.ts} +2 -2
- package/dist/cli.js +77 -6
- package/dist/cli.js.map +1 -1
- package/dist/{client-C3vRNuLi.js → client-Bm0XbjHr.js} +274 -113
- package/dist/client-Bm0XbjHr.js.map +1 -0
- package/dist/{client-CqGDbWd_.d.ts → client-DnFF9_lv.d.ts} +40 -14
- package/dist/{client-routes-BtGpYCef.js → client-routes-BmPvNr4s.js} +10 -1
- package/dist/client-routes-BmPvNr4s.js.map +1 -0
- package/dist/{context-btHuB01Z.d.ts → context-BNgBXVUQ.d.ts} +7 -5
- package/dist/{context-CTiSzQRc.js → context-CU4Fpn5a.js} +10 -13
- package/dist/context-CU4Fpn5a.js.map +1 -0
- package/dist/{defer-M18UKyfG.js → defer-BWwxv7Qf.js} +2 -2
- package/dist/{defer-M18UKyfG.js.map → defer-BWwxv7Qf.js.map} +1 -1
- package/dist/{devtools-D9Q7a41M.js → devtools-Cl6AhENB.js} +4 -4
- package/dist/{devtools-D9Q7a41M.js.map → devtools-Cl6AhENB.js.map} +1 -1
- package/dist/{devtools-panel-DTQtljeA.js → devtools-panel-DLIeWcAj.js} +32 -9
- package/dist/devtools-panel-DLIeWcAj.js.map +1 -0
- package/dist/events-LgLdp1R7.js.map +1 -1
- package/dist/{features-CbgII-o7.js → features-DwMYKBIC.js} +6 -2
- package/dist/features-DwMYKBIC.js.map +1 -0
- package/dist/{files-DtDH5AR4.js → files-BuQvpBwF.js} +94 -3
- package/dist/files-BuQvpBwF.js.map +1 -0
- package/dist/{html-t1JpkODI.js → html-Cf5uKhLs.js} +3 -3
- package/dist/html-Cf5uKhLs.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{inspect-Bonq6EJO.js → inspect-BSHv1_25.js} +2739 -2080
- package/dist/inspect-BSHv1_25.js.map +1 -0
- package/dist/{loader-C-S3yzep.js → loader-BPNSRA2A.js} +5 -5
- package/dist/{loader-C-S3yzep.js.map → loader-BPNSRA2A.js.map} +1 -1
- package/dist/{rpc-C_znDZ_w.js → rpc-DqfCaYgF.js} +3 -3
- package/dist/{rpc-C_znDZ_w.js.map → rpc-DqfCaYgF.js.map} +1 -1
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/bundles.js +2 -0
- package/dist/runtime/bundles.js.map +1 -1
- package/dist/runtime/client.d.ts +4 -4
- package/dist/runtime/client.js +5 -5
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.js +1 -1
- package/dist/runtime/devtools.d.ts +2 -2
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/events.d.ts +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/html.d.ts +1 -1
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/server.d.ts +4 -4
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +2 -2
- package/dist/runtime/signals.js +43 -5
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/store.d.ts +2 -0
- package/dist/runtime/store.js +1 -0
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/{search-params-CM1RWR2P.js → search-params-C64liRBj.js} +34 -9
- package/dist/search-params-C64liRBj.js.map +1 -0
- package/dist/{server-dP_ucRiJ.d.ts → server-0rS5vUW1.d.ts} +37 -10
- package/dist/{server-BcT9icQ4.js → server-BVObWh-w.js} +132 -16
- package/dist/server-BVObWh-w.js.map +1 -0
- package/dist/{shared-CzbnWkVA.d.ts → shared-CuJdWifz.d.ts} +16 -3
- package/dist/{signals-BwD4u22K.d.ts → signals-DBnq9QRW.d.ts} +46 -6
- package/dist/{static-loader-DysAET-w.d.ts → static-loader-BYbXVJDY.d.ts} +2 -2
- package/dist/{static-loader-Bt2WDkY1.js → static-loader-V4V1Oy6G.js} +13 -5
- package/dist/static-loader-V4V1Oy6G.js.map +1 -0
- package/dist/store-BIBAYZo-.js +293 -0
- package/dist/store-BIBAYZo-.js.map +1 -0
- package/dist/store-xlTzAM_r.d.ts +171 -0
- package/dist/{stream-DRjx0keF.js → stream-RXLadXx1.js} +90 -4
- package/dist/stream-RXLadXx1.js.map +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +128 -13
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +349 -79
- package/package.json +5 -1
- package/skills/brumate/SKILL.md +1 -1
- package/skills/brumate/references/errors.md +127 -9
- package/skills/brumate/references/signals.md +37 -30
- package/skills/brumate/references/state.md +3 -2
- package/dist/client-C3vRNuLi.js.map +0 -1
- package/dist/client-routes-BtGpYCef.js.map +0 -1
- package/dist/context-CTiSzQRc.js.map +0 -1
- package/dist/devtools-panel-DTQtljeA.js.map +0 -1
- package/dist/features-CbgII-o7.js.map +0 -1
- package/dist/files-DtDH5AR4.js.map +0 -1
- package/dist/html-t1JpkODI.js.map +0 -1
- package/dist/inspect-Bonq6EJO.js.map +0 -1
- package/dist/search-params-CM1RWR2P.js.map +0 -1
- package/dist/server-BcT9icQ4.js.map +0 -1
- package/dist/static-loader-Bt2WDkY1.js.map +0 -1
- package/dist/stream-DRjx0keF.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"files-DtDH5AR4.js","names":[],"sources":["../src/packages.ts","../src/server-files.ts","../src/files.ts"],"sourcesContent":["// Packages of components. A dependency of the app whose package.json has a\n// `brumate` field ships `.brm` files, `.brm.ts` modules and `'use server'`\n// files as source, and the plugin of the app compiles them with its own files.\n\nimport { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';\nimport path from 'node:path';\n\n/** A dependency of the app that ships `.brm` files. */\nexport interface BrumatePackage {\n /** The name of the package, such as `@acme/ui`. */\n name: string;\n version: string;\n /** The real path of the directory of the package, with forward slashes. */\n root: string;\n /** The directories to search for files, as absolute paths with forward slashes. */\n directories: string[];\n /**\n * The prefix of the names of its files, which their IDs come from: the\n * name of the package, and its version when the app has two versions.\n */\n prefix: string;\n /** True when the package is not inside `node_modules`, such as a workspace package. */\n linked: boolean;\n}\n\ninterface PackageJson {\n name?: string;\n version?: string;\n brumate?: unknown;\n exports?: unknown;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n}\n\nfunction toPosix(file: string): string {\n return file.split(path.sep).join('/');\n}\n\nfunction readJson(file: string): PackageJson | undefined {\n try {\n return JSON.parse(readFileSync(file, 'utf8')) as PackageJson;\n } catch {\n return undefined;\n }\n}\n\n/** The real directory of a package that code in `from` can import, or undefined. */\nexport function findPackageDirectory(name: string, from: string): string | undefined {\n for (let directory = from; ; directory = path.dirname(directory)) {\n const candidate = path.join(directory, 'node_modules', name);\n if (existsSync(path.join(candidate, 'package.json'))) {\n return toPosix(realpathSync(candidate));\n }\n if (path.dirname(directory) === directory) {\n return undefined;\n }\n }\n}\n\n/** The directory of the nearest package.json at or above a directory. */\nfunction packageRoot(directory: string): string | undefined {\n for (let current = directory; ; current = path.dirname(current)) {\n if (existsSync(path.join(current, 'package.json'))) {\n return current;\n }\n if (path.dirname(current) === current) {\n return undefined;\n }\n }\n}\n\n/** The version of the `brumate` field that this version of brumate reads. */\nexport const PACKAGE_FORMAT = 1;\n\n/** The directories that the `brumate` field names, or undefined when the package does not opt in. */\nfunction readDirectories(root: string, field: unknown, name: string): string[] | undefined {\n if (field === true) {\n return [root];\n }\n if (typeof field === 'object' && field !== null) {\n const { dir, version = PACKAGE_FORMAT } = field as {\n dir?: string | string[];\n version?: number;\n };\n if (version !== PACKAGE_FORMAT) {\n throw new Error(\n `The package ${name} has \"brumate\": { \"version\": ${version} }, but this version of brumate reads version ${PACKAGE_FORMAT}. Install a version of ${name} or of brumate that matches.`,\n );\n }\n if (dir === undefined) {\n return [root];\n }\n const directories: string[] = [];\n for (const item of Array.isArray(dir) ? dir : [dir]) {\n directories.push(toPosix(path.resolve(root, item)));\n }\n return directories;\n }\n return undefined;\n}\n\n/**\n * Finds the dependencies of the app at `root` that ship `.brm` files, and\n * theirs. The app's dependencies come from its package.json: `dependencies`,\n * `devDependencies`, `optionalDependencies` and `peerDependencies`. A package\n * opts in with `\"brumate\": true`, or `\"brumate\": { \"dir\": \"src\" }` to search\n * only that directory. Symbolic links, such as those of pnpm, resolve to the\n * real directory.\n */\nexport function findPackages(root: string): BrumatePackage[] {\n const app = packageRoot(path.resolve(root));\n if (!app) {\n return [];\n }\n const found = new Map<string, Omit<BrumatePackage, 'prefix'>>();\n function visit(directory: string, json: PackageJson, own: boolean): void {\n const names = new Set([\n ...Object.keys(json.dependencies ?? {}),\n ...Object.keys(json.optionalDependencies ?? {}),\n ...Object.keys(json.peerDependencies ?? {}),\n // The dev dependencies of a package are its own tools, not part of what it ships.\n ...(own ? Object.keys(json.devDependencies ?? {}) : []),\n ]);\n for (const name of [...names].toSorted()) {\n const real = findPackageDirectory(name, directory);\n if (!real || found.has(real)) {\n continue;\n }\n const dependency = readJson(`${real}/package.json`);\n const directories = dependency && readDirectories(real, dependency.brumate, name);\n if (!dependency || !directories) {\n continue;\n }\n found.set(real, {\n name: dependency.name ?? name,\n version: dependency.version ?? '0.0.0',\n root: real,\n directories,\n linked: !real.includes('/node_modules/'),\n });\n visit(real, dependency, false);\n }\n }\n visit(app, readJson(path.join(app, 'package.json')) ?? {}, true);\n const list = [...found.values()];\n // Two versions of one package get IDs apart. Copies of one version share theirs, as their files are the same.\n const versions = new Map<string, Set<string>>();\n for (const item of list) {\n versions.set(item.name, (versions.get(item.name) ?? new Set()).add(item.version));\n }\n const result: BrumatePackage[] = [];\n for (const item of list) {\n result.push(\n Object.assign(item, {\n prefix: versions.get(item.name)!.size > 1 ? `${item.name}@${item.version}` : item.name,\n }),\n );\n }\n return result;\n}\n\n/** The package that a file belongs to, or undefined for a file of the app. */\nexport function findPackage(packages: BrumatePackage[], file: string): BrumatePackage | undefined {\n for (const item of packages) {\n if (file.startsWith(`${item.root}/`)) {\n return item;\n }\n }\n return undefined;\n}\n\n/**\n * The name of a file of a package, which its IDs come from: the prefix of\n * the package and the path of the file in it, such as `@acme/ui/src/Button.brm`.\n * It is the same wherever the package is installed.\n */\nexport function packageFileName(item: BrumatePackage, file: string): string {\n return `${item.prefix}/${file.slice(item.root.length + 1)}`;\n}\n\n/** The name and the subpath of a bare specifier, such as `@acme/ui` and `./Button.brm`. */\nexport function splitSpecifier(specifier: string): { name: string; subpath: string } | undefined {\n if (specifier.startsWith('.') || specifier.startsWith('/') || /^[a-z]+:/i.test(specifier)) {\n return undefined;\n }\n const parts = specifier.split('/');\n const count = specifier.startsWith('@') ? 2 : 1;\n if (parts.length < count) {\n return undefined;\n }\n for (const part of parts.slice(0, count)) {\n if (part === '') {\n return undefined;\n }\n }\n const rest = parts.slice(count).join('/');\n return { name: parts.slice(0, count).join('/'), subpath: rest ? `./${rest}` : '.' };\n}\n\n/** The conditions of `exports` that a `.brm` file or a source module can be under. */\nconst CONDITIONS = new Set(['brumate', 'import', 'module', 'node', 'browser', 'default']);\n\nfunction resolveTarget(target: unknown, star: string): string | undefined {\n if (typeof target === 'string') {\n return target.replaceAll('*', star);\n }\n if (Array.isArray(target)) {\n for (const item of target) {\n const result = resolveTarget(item, star);\n if (result) {\n return result;\n }\n }\n return undefined;\n }\n if (typeof target === 'object' && target !== null) {\n for (const [condition, value] of Object.entries(target)) {\n if (CONDITIONS.has(condition)) {\n const result = resolveTarget(value, star);\n if (result) {\n return result;\n }\n }\n }\n }\n return undefined;\n}\n\n/** Resolves a subpath through the `exports` of a package.json, or undefined if it does not export it. */\nexport function resolveExports(exports: unknown, subpath: string): string | undefined {\n let hasSubpaths = false;\n if (typeof exports === 'object' && exports !== null && !Array.isArray(exports)) {\n for (const key of Object.keys(exports)) {\n if (key.startsWith('.')) {\n hasSubpaths = true;\n break;\n }\n }\n }\n const map = hasSubpaths ? (exports as Record<string, unknown>) : { '.': exports };\n if (subpath in map) {\n return resolveTarget(map[subpath], '');\n }\n // The pattern with the longest prefix wins, as in Node.\n let best: { key: string; star: string } | undefined;\n for (const key of Object.keys(map)) {\n const index = key.indexOf('*');\n if (index === -1) {\n continue;\n }\n const before = key.slice(0, index);\n const after = key.slice(index + 1);\n if (\n subpath.startsWith(before) &&\n subpath.endsWith(after) &&\n subpath.length >= key.length - 1 &&\n (!best || before.length > best.key.indexOf('*'))\n ) {\n best = { key, star: subpath.slice(before.length, subpath.length - after.length) };\n }\n }\n return best && resolveTarget(map[best.key], best.star);\n}\n\n/**\n * Resolves a bare specifier, such as `@acme/ui/Button.brm`, to the real path\n * of the file, through the `exports` of the package. Returns undefined when\n * it is not a bare specifier or names no file.\n */\nexport function resolvePackageImport(specifier: string, importer: string): string | undefined {\n const split = splitSpecifier(specifier);\n if (!split) {\n return undefined;\n }\n const directory = findPackageDirectory(split.name, path.dirname(importer));\n if (!directory) {\n return undefined;\n }\n const json = readJson(`${directory}/package.json`);\n const target =\n json?.exports === undefined ? split.subpath : resolveExports(json.exports, split.subpath);\n if (!target) {\n return undefined;\n }\n const file = path.resolve(directory, target);\n return existsSync(file) ? toPosix(realpathSync(file)) : undefined;\n}\n\n/**\n * Resolves a bare specifier like `resolvePackageImport`, but only for a\n * package of components in the list. Returns undefined for any other package.\n */\nexport function resolveComponentPackage(\n packages: BrumatePackage[],\n specifier: string,\n importer: string,\n): string | undefined {\n const name = splitSpecifier(specifier)?.name;\n for (const item of packages) {\n if (item.name === name) {\n return resolvePackageImport(specifier, importer);\n }\n }\n return undefined;\n}\n\n/** The specifiers that a file imports or exports from, found by a pattern, so it can only find more. */\nexport function importSpecifiers(source: string): string[] {\n const result: string[] = [];\n for (const match of source.matchAll(/(?:\\bfrom|\\bimport\\s*\\(?)\\s*(['\"])([^'\"\\n]+)\\1/g)) {\n result.push(match[2]!);\n }\n return result;\n}\n\n/** The extensions that an import without one can name. */\nconst EXTENSIONS = ['', '.ts', '.tsx', '.js', '.mjs', '/index.ts', '/index.js'];\n\n/**\n * The files of packages that the app reaches: the files of packages that\n * files of the app import, and the files of packages that those import, and\n * so on. Only these become server functions of the app.\n */\nexport function reachableFiles(\n packages: BrumatePackage[],\n appFiles: string[],\n read: (file: string) => string | undefined,\n): Set<string> {\n const reached = new Set<string>();\n const names = new Set<string>();\n for (const item of packages) {\n names.add(item.name);\n }\n const pending: string[] = [];\n function add(file: string | undefined): void {\n if (file && !reached.has(file) && findPackage(packages, file)) {\n reached.add(file);\n pending.push(file);\n }\n }\n function resolve(specifier: string, importer: string): string | undefined {\n if (specifier.startsWith('.')) {\n const stem = path.resolve(path.dirname(importer), specifier.split('?')[0]!);\n for (const extension of EXTENSIONS) {\n const candidate = stem + extension;\n if (statSync(candidate, { throwIfNoEntry: false })?.isFile()) {\n return toPosix(realpathSync(candidate));\n }\n }\n return undefined;\n }\n const name = splitSpecifier(specifier)?.name;\n return name && names.has(name)\n ? resolvePackageImport(specifier.split('?')[0]!, importer)\n : undefined;\n }\n function visit(file: string, own: boolean): void {\n const source = read(file);\n if (source === undefined) {\n return;\n }\n for (const specifier of importSpecifiers(source)) {\n // A file of the app reaches a package only by its name.\n if (own && specifier.startsWith('.')) {\n continue;\n }\n try {\n add(resolve(specifier, file));\n } catch {\n // A path that is not a file, such as a directory, reaches nothing.\n }\n }\n }\n for (const file of appFiles) {\n visit(file, true);\n }\n while (pending.length > 0) {\n visit(pending.pop()!, false);\n }\n return reached;\n}\n","// 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 { existsSync, readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { parseSync } from 'oxc-parser';\nimport type { BrumatePackage } from './packages.ts';\nimport { resolveComponentPackage } from './packages.ts';\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. */\ntype Program = ReturnType<typeof parseSync>['program'];\ntype Node = Program['body'][number] | { type: string; callee?: unknown } | null | undefined;\n\n/**\n * Tells a value that the file exports as a function: a function expression,\n * or a call of `cached` or `idempotent` of `brumate/server`, which return a function.\n */\nfunction functionTest(program: Program): (node: Node) => boolean {\n const wrappers = new Set<string>();\n for (const statement of program.body) {\n if (statement.type === 'ImportDeclaration' && statement.source.value === 'brumate/server') {\n for (const specifier of statement.specifiers) {\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.imported.type === 'Identifier' &&\n (specifier.imported.name === 'cached' || specifier.imported.name === 'idempotent')\n ) {\n wrappers.add(specifier.local.name);\n }\n }\n }\n }\n return (node) => {\n if (node?.type === 'ArrowFunctionExpression' || node?.type === 'FunctionExpression') {\n return true;\n }\n const callee =\n node?.type === 'CallExpression'\n ? (node.callee as { type: string; name?: string })\n : undefined;\n return callee?.type === 'Identifier' && wrappers.has(callee.name!);\n };\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 const isFunction = functionTest(program);\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 // The middleware of the file runs before its functions. The browser cannot call it.\n functions.delete(MIDDLEWARE);\n return [...functions];\n}\n\n/** The export of a file of server functions that runs before each of them. */\nexport const MIDDLEWARE = 'middleware';\n\n/** True if a file of server functions exports `middleware`. */\nexport function hasServerMiddleware(source: string, filename: string): boolean {\n const { program } = parseSync(filename, source, { lang: 'ts' });\n for (const statement of program.body) {\n if (statement.type !== 'ExportNamedDeclaration' || statement.exportKind === 'type') {\n continue;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id?.name === MIDDLEWARE) {\n return true;\n }\n if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier' && declarator.id.name === MIDDLEWARE) {\n return true;\n }\n }\n }\n for (const specifier of statement.specifiers) {\n const name =\n specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value;\n if (specifier.exportKind !== 'type' && name === MIDDLEWARE) {\n return true;\n }\n }\n }\n return false;\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 const isFunction = functionTest(program);\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 function makeLet(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 makeLet(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 makeLet(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\n/**\n * The file of a relative import that holds server functions, such as `./issues` for `issues.ts`\n * with `'use server'` first, or undefined. A package specifier is not looked up.\n */\nexport function findServerImport(importer: string, specifier: string): string | undefined {\n if (!specifier.startsWith('.')) {\n return undefined;\n }\n const stem = path.resolve(path.dirname(importer), specifier);\n const candidates = [stem];\n for (const extension of ['.ts', '.tsx', '.js', '.mjs']) {\n candidates.push(stem + extension);\n }\n for (const candidate of candidates) {\n if (\n isScriptFile(candidate) &&\n existsSync(candidate) &&\n hasUseServer(readFileSync(candidate, 'utf8'))\n ) {\n return candidate;\n }\n }\n return undefined;\n}\n\n/**\n * The file of server functions that a package of components exports under a\n * bare specifier, or undefined.\n */\nexport function findPackageServerFile(\n packages: BrumatePackage[],\n importer: string,\n specifier: string,\n): string | undefined {\n const file = resolveComponentPackage(packages, specifier, importer);\n return file && isScriptFile(file) && hasUseServer(readFileSync(file, 'utf8')) ? file : undefined;\n}\n","import { readFile, readdir, stat } 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 async function visit(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 async function visit(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 async function visit(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\n/**\n * Reads every `.brm` file under a root, and finds the files that the paths\n * name: a file, or the files under a directory. Without paths, the targets are\n * the whole project. A file outside the root is read too. A path that does not\n * exist throws.\n */\nexport async function collectSources(\n root: string,\n paths: string[],\n): Promise<{ sources: Map<string, string>; targets: string[] }> {\n const project = await findFiles(root, defaultExclude);\n const sources = new Map<string, string>();\n const reads: Promise<string>[] = [];\n for (const file of project) {\n reads.push(readFile(file, 'utf8'));\n }\n const texts = await Promise.all(reads);\n for (const [index, file] of project.entries()) {\n sources.set(file, texts[index]!);\n }\n\n const targets: string[] = paths.length === 0 ? [...project] : [];\n const lookups: Promise<string[]>[] = [];\n for (const target of paths) {\n const absolute = path.resolve(root, target);\n lookups.push(\n stat(absolute).then((info) =>\n info.isDirectory()\n ? findFiles(absolute, defaultExclude)\n : [absolute.split(path.sep).join('/')],\n ),\n );\n }\n for (const found of await Promise.all(lookups)) {\n targets.push(...found);\n }\n const extra: string[] = [];\n const extraReads: Promise<string>[] = [];\n for (const file of targets) {\n if (!sources.has(file)) {\n extra.push(file);\n extraReads.push(readFile(file, 'utf8'));\n }\n }\n const extraTexts = await Promise.all(extra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AAM,0BAAU,IAAI,IAAoB;CACxC,MAAM,QAA2B,CAAC;CAClC,KAAK,MAAM,QAAQ,SACjB,MAAM,KAAK,SAAS,MAAM,MAAM,CAAC;CAEnC,MAAM,QAAQ,MAAM,QAAQ,IAAI,KAAK;CACrC,KAAK,MAAM,CAAC,OAAO,SAAS,QAAQ,QAAQ,GAC1C,QAAQ,IAAI,MAAM,MAAM,MAAO;CAGjC,MAAM,UAAoB,MAAM,WAAW,IAAI,CAAC,GAAG,OAAO,IAAI,CAAC;CAC/D,MAAM,UAA+B,CAAC;CACtC,KAAK,MAAM,UAAU,OAAO;EAC1B,MAAM,WAAW,KAAK,QAAQ,MAAM,MAAM;EAC1C,QAAQ,KACN,KAAK,QAAQ,CAAC,CAAC,MAAM,SACnB,KAAK,YAAY,IACb,UAAU,UAAU,cAAc,IAClC,CAAC,SAAS,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CACzC,CACF;CACF;CACA,KAAK,MAAM,SAAS,MAAM,QAAQ,IAAI,OAAO,GAC3C,QAAQ,KAAK,GAAG,KAAK;CAEvB,MAAM,QAAkB,CAAC;CACzB,MAAM,aAAgC,CAAC;CACvC,KAAK,MAAM,QAAQ,SACjB,IAAI,CAAC,QAAQ,IAAI,IAAI,GAAG;EACtB,MAAM,KAAK,IAAI;EACf,WAAW,KAAK,SAAS,MAAM,MAAM,CAAC;CACxC;CAEF,MAAM,aAAa,MAAM,QAAQ,IAAI,UAAU;CAC/C,KAAK,MAAM,CAAC,OAAO,SAAS,MAAM,QAAQ,GACxC,QAAQ,IAAI,MAAM,WAAW,MAAO;CAEtC,OAAO;EAAE;EAAS;CAAQ;AAC5B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"html-t1JpkODI.js","names":[],"sources":["../src/runtime/html.ts"],"sourcesContent":["// HTML string helpers that the server and the client both use.\n\nimport type { ScopeId } from './shared.ts';\n\nconst RAW: unique symbol = Symbol.for('brumate.raw');\nconst INTERNAL: unique symbol = Symbol.for('brumate.internal');\n\n/** HTML that is inserted as it is, such as the output of a template. */\nexport interface Raw {\n [RAW]: string;\n /** For the output of a template, the ID of its scope, which the insert links to its call. */\n s?: ScopeId;\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 readonly s?: ScopeId;\n\n constructor(html: string, scope?: ScopeId) {\n this[RAW] = html;\n this.s = scope;\n }\n}\n\nexport function raw(html: string, scope?: ScopeId): Raw {\n return new RawHTML(html, scope);\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> = { '&': '&', '<': '<', '>': '>', '\"': '"' };\n\nfunction toEscape(char: string): string {\n return ESCAPES[char]!;\n}\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/** True for a promise, or any object with a `then` function, as the server awaits it. */\nfunction isThenable(value: unknown): boolean {\n return (\n value !== null &&\n (typeof value === 'object' || typeof value === 'function') &&\n typeof (value as PromiseLike<unknown>).then === 'function'\n );\n}\n\n/** Renders a value inserted in markup. A promise is not awaited: it renders empty. */\nexport function insertValue(value: unknown): string {\n if (isRaw(value)) {\n return value[RAW];\n }\n // A memo of a promise that is still loading: empty until its value lands.\n if (value === null || value === undefined || typeof value === 'boolean' || isThenable(value)) {\n return '';\n }\n if (Array.isArray(value)) {\n let result = '';\n for (const item of value) {\n result += insertValue(item);\n }\n return result;\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' || isThenable(value)) {\n return '';\n }\n if (Array.isArray(value)) {\n let result = '';\n for (const item of value) {\n result += textValue(item);\n }\n return result;\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 const declarations: string[] = [];\n for (const [name, item] of Object.entries(value)) {\n if (item !== null && item !== undefined && item !== false) {\n declarations.push(`${toKebabCase(name)}:${String(item)}`);\n }\n }\n return declarations.join(';');\n }\n return String(value);\n}\n\n/** The brand of a binding of `$bind`, under the key of the registry. See `Binding`. */\nconst BOUND = Symbol.for('brumate.binding');\n\n/** The words of an attribute that says `true` or `false` in its value. */\nconst TRUE_FALSE = ['true', 'false'] as const;\n\n/**\n * Attributes whose two states are words in the value, not whether the\n * attribute is there, by their words for `true` and `false`. A missing\n * attribute means a third state, such as the default of the element, so\n * `false` must not remove it. `aria-*` and `data-*` are such attributes too.\n */\nconst SWITCHES = new Map<string, readonly [string, string]>([\n ['contenteditable', TRUE_FALSE],\n ['draggable', TRUE_FALSE],\n ['spellcheck', TRUE_FALSE],\n ['writingsuggestions', TRUE_FALSE],\n // SVG.\n ['focusable', TRUE_FALSE],\n ['translate', ['yes', 'no']],\n ['autocomplete', ['on', 'off']],\n ['autocorrect', ['on', 'off']],\n]);\n\n/** The words of `true` and `false` for an attribute that says them in its value, or undefined. */\nfunction switchWords(name: string): readonly [string, string] | undefined {\n const lower = name.toLowerCase();\n if (lower.startsWith('aria-') || lower.startsWith('data-')) {\n return TRUE_FALSE;\n }\n return SWITCHES.get(lower);\n}\n\n/**\n * Returns the text of an attribute, or undefined if the attribute is not\n * rendered.\n *\n * - `null` and `undefined` leave the attribute out.\n * - For an attribute whose value says its state, such as `aria-expanded`,\n * `draggable` or `translate`, `true` and `false` render as its words:\n * `\"true\"` and `\"false\"`, or `\"yes\"` and `\"no\"`, or `\"on\"` and `\"off\"`.\n * - For other attributes, such as `disabled`, `true` renders the attribute\n * without a value, and `false` leaves it out.\n */\nexport function attributeText(name: string, value: unknown): string | undefined {\n // `value=$bind(name)` on an element renders the value of the name.\n if (typeof value === 'object' && value !== null && BOUND in value) {\n // A `ref` is no attribute: the element goes to its signal.\n if (name === 'ref') {\n return undefined;\n }\n value = (value as unknown as { value: unknown }).value;\n }\n // A promise is a memo that is still loading: the attribute is absent until its value lands.\n if (value === null || value === undefined || typeof value === 'function' || isThenable(value)) {\n return undefined;\n }\n if (typeof value === 'boolean') {\n const words = switchWords(name);\n if (words) {\n return value ? words[0] : words[1];\n }\n return value ? '' : undefined;\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/**\n * A name that HTML reads as one attribute. A spread takes its names from\n * data, so a name with a space, a quote, `>`, `/` or `=` could write other\n * attributes or markup.\n */\n// oxlint-disable-next-line no-control-regex -- HTML reads no control character in a name.\nconst ATTRIBUTE_NAME = /^[^\\s\"'>/=\\x00-\\x1f\\x7f]+$/;\n\n/** Renders one attribute, with a leading space. A name that is not one attribute renders nothing. */\nexport function attribute(name: string, value: unknown): string {\n const text = attributeText(name, value);\n if (text === undefined || !ATTRIBUTE_NAME.test(name)) {\n return '';\n }\n return value === true && text === '' ? ` ${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/**\n * Merges the attributes of an element that has spreads, in their order: a\n * later value wins, except `class`, whose values all apply.\n */\n/**\n * A value of an attribute that brumate writes, such as the `b-on` of a dynamic tag, which the\n * compiler wraps. An object of attributes, such as a spread, writes a `b-` attribute only with\n * one, so data from outside the app cannot name handlers or scopes.\n */\nexport class Internal {\n readonly value: unknown;\n\n constructor(value: unknown) {\n this.value = value;\n }\n}\n\n// The brand sits on the prototype, so an instance does not carry a field for it.\n(Internal.prototype as unknown as Record<symbol, boolean>)[INTERNAL] = true;\n\n/** True for an `Internal`, also one that another copy of the runtime made. */\nexport function isInternal(value: unknown): value is Internal {\n return typeof value === 'object' && value !== null && INTERNAL in value;\n}\n\n/** Wraps the value of an attribute that brumate writes. See `Internal`. */\nexport function internal(value: unknown): Internal {\n return new Internal(value);\n}\n\n/** The value of an attribute of an object, or undefined for a `b-` attribute from outside. */\nexport function ownValue(name: string, value: unknown): unknown {\n if (isInternal(value)) {\n return value.value;\n }\n return name.startsWith('b-') ? undefined : value;\n}\n\nexport function mergeAttributes(\n parts: Record<string, unknown>[],\n variables?: Record<string, unknown>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const part of parts) {\n for (const [name, value] of Object.entries(part ?? {})) {\n // A `b-` attribute from outside the app does not take the place of brumate's own.\n if (name.startsWith('b-') && !isInternal(value)) {\n continue;\n }\n result[name] =\n name === 'class' && result.class !== undefined && value !== undefined\n ? [result.class, value]\n : value;\n }\n }\n // The style variables of the component come before the style that won, whoever gave it.\n if (variables) {\n result.style = vars(variables, result.style);\n }\n return result;\n}\n\n/**\n * The `b-on` entry of a handler that a spread passes on, such as\n * `click:prevent=Parent#h1@3`: its event, the modifiers of its wrappers, its\n * client function and the scope it runs in. A handler that `$handler` made\n * has its arguments after another `@`, encoded so that they hold no space.\n */\nexport function handlerEntry(\n name: string,\n ref: string,\n scope: number | string,\n modifiers: readonly string[] = [],\n args?: unknown[],\n): string {\n const bound = args === undefined ? '' : `@${encodeURIComponent(JSON.stringify(args))}`;\n return `${[name.slice(2).toLowerCase(), ...modifiers].join(':')}=${ref}@${scope}${bound}`;\n}\n\n/**\n * The `b-on` entry of a binding that a spread puts on `value` or `checked`\n * of an element. It names the scope of the slot, or of the setter of\n * `$bind(name, fn)`, after `@`. A box writes on `change`.\n */\nexport function bindEntry(\n name: string,\n ref: { scope: number | string; slot: number },\n setter?: { ref: string; scope: number | string },\n): string {\n const event = name === 'checked' ? 'change' : 'input';\n return setter\n ? `${event}=$set:${setter.ref}@${setter.scope}`\n : `${event}=$bind#0.${ref.slot}@${ref.scope}`;\n}\n\n/**\n * The `b-on` attribute of an element with spreads: the bindings of its\n * spreads, so its handlers read the new value, then its own handlers, then\n * those of its spreads.\n */\nexport function onAttribute(on: string[], own: string): string {\n const value = onValue(on, own);\n return value ? ` b-on=\"${escapeAttribute(value)}\"` : '';\n}\n\n/** The value of `b-on`, in the order of `onAttribute`. */\nexport function onValue(on: string[], own: string): string {\n const bindings: string[] = [];\n const rest: string[] = [];\n for (const entry of on) {\n if (/=\\$(bind#|set:)/.test(entry)) {\n bindings.push(entry);\n } else {\n rest.push(entry);\n }\n }\n const parts: string[] = [];\n for (const part of [...bindings, own, ...rest]) {\n if (part) {\n parts.push(part);\n }\n }\n return parts.join(' ');\n}\n\n/** Renders an object of attributes. */\nexport function spread(attributes: Record<string, unknown>, names = false): string {\n let result = '';\n const written: string[] = [];\n for (const [name, value] of Object.entries(attributes)) {\n if (name !== 'children' && !/^on[A-Z]/.test(name)) {\n const text = attribute(name, ownValue(name, value));\n if (text) {\n result += text;\n written.push(name);\n }\n }\n }\n // `b-s` names the attributes of a spread that changes in the browser. Its first update there\n // removes only those, so a spread that wrote none still writes it, empty.\n return names ? `${result} b-s=\"${written.join(' ')}\"` : 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. `build` is the ID\n * of the build of the page, which the URL carries as `__build`, so the\n * server can tell a post from before a deploy without scripts.\n */\nexport function actionAttributes(\n prefix: string,\n name: string,\n id: string,\n method?: string,\n result?: string,\n build?: string,\n key?: string,\n): string {\n const methodText = method ? ` ${method}=\"post\"` : '';\n // The key of a form of a function that `idempotent` made, so a second post gets the first result.\n const params: string[] = [];\n if (build !== undefined) {\n params.push(`__build=${encodeURIComponent(build)}`);\n }\n if (key !== undefined) {\n params.push(`__key=${key}`);\n }\n const query = params.join('&');\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 const url = `?__action=${encodeURIComponent(id)}${query ? `&${query}` : ''}`;\n return ` ${name}=\"${escapeAttribute(url)}\"${methodText} b-action=\"${escapeAttribute(id)}\" b-result=\"${escapeAttribute(result)}\"`;\n }\n const url = `${prefix}/${encodeURIComponent(id)}${query ? `?${query}` : ''}`;\n return ` ${name}=\"${escapeAttribute(url)}\"${methodText}`;\n}\n"],"mappings":";AAIA,MAAM,MAAqB,OAAO,IAAI,aAAa;AACnD,MAAM,WAA0B,OAAO,IAAI,kBAAkB;AAU7D,IAAM,UAAN,MAA6B;CAC3B,CAAU;CACV;CAEA,YAAY,MAAc,OAAiB;EACzC,KAAK,OAAO;EACZ,KAAK,IAAI;CACX;AACF;AAEA,SAAgB,IAAI,MAAc,OAAsB;CACtD,OAAO,IAAI,QAAQ,MAAM,KAAK;AAChC;AAEA,SAAgB,MAAM,OAA8B;CAClD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO;AAC/D;AAEA,SAAgB,QAAQ,OAAoB;CAC1C,OAAO,MAAM;AACf;AAEA,MAAM,UAAkC;CAAE,KAAK;CAAS,KAAK;CAAQ,KAAK;CAAQ,MAAK;AAAS;AAEhG,SAAS,SAAS,MAAsB;CACtC,OAAO,QAAQ;AACjB;AAGA,SAAgB,OAAO,OAAuB;CAC5C,OAAO,QAAQ,KAAK,KAAK,IAAI,MAAM,QAAQ,UAAU,QAAQ,IAAI;AACnE;AAEA,SAAgB,gBAAgB,OAAuB;CACrD,OAAO,QAAQ,KAAK,KAAK,IAAI,MAAM,QAAQ,UAAU,QAAQ,IAAI;AACnE;;AAGA,SAAS,WAAW,OAAyB;CAC3C,OACE,UAAU,SACT,OAAO,UAAU,YAAY,OAAO,UAAU,eAC/C,OAAQ,MAA+B,SAAS;AAEpD;;AAGA,SAAgB,YAAY,OAAwB;CAClD,IAAI,MAAM,KAAK,GACb,OAAO,MAAM;CAGf,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,OAAO,UAAU,aAAa,WAAW,KAAK,GACzF,OAAO;CAET,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,IAAI,SAAS;E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