deictic 0.8.1 → 0.10.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.
- package/API.md +81 -17
- package/README.md +1 -1
- package/dist/annotations/client.js +1 -1
- package/dist/bun.d.ts.map +1 -1
- package/dist/bun.js +26 -8
- package/dist/bun.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/client/index.d.ts +13 -13
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +19 -7
- package/dist/client/index.js.map +1 -1
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +45 -25
- package/dist/next.js.map +1 -1
- package/dist/react/client.d.ts +19 -0
- package/dist/react/client.d.ts.map +1 -0
- package/dist/react/client.js +504 -0
- package/dist/react/client.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +1 -0
- package/dist/recommended/index.d.ts +15 -7
- package/dist/recommended/index.d.ts.map +1 -1
- package/dist/recommended/index.js +1 -1
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +48 -5
- package/dist/recordings/client.js.map +1 -1
- package/dist/screenshots/client.d.ts +9 -1
- package/dist/screenshots/client.d.ts.map +1 -1
- package/dist/screenshots/rrweb.d.ts +0 -6
- package/dist/screenshots/rrweb.d.ts.map +1 -1
- package/dist/screenshots/rrweb.js +46 -12
- package/dist/screenshots/rrweb.js.map +1 -1
- package/dist/shared/board.js +1 -1
- package/dist/shared/client.js +44 -2
- package/dist/shared/client.js.map +1 -1
- package/dist/shared/dom.js +7 -1
- package/dist/shared/dom.js.map +1 -1
- package/dist/shared/drawer.js +1 -1
- package/dist/shared/endpoints.js +15 -4
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/index.d.ts +11 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index10.d.ts +70 -0
- package/dist/shared/index10.d.ts.map +1 -0
- package/dist/shared/index3.d.ts +11 -0
- package/dist/shared/index3.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +92 -312
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/index8.d.ts +324 -47
- package/dist/shared/index8.d.ts.map +1 -1
- package/dist/shared/index9.d.ts +45 -63
- package/dist/shared/index9.d.ts.map +1 -1
- package/dist/shared/init.js +15 -11
- package/dist/shared/init.js.map +1 -1
- package/dist/shared/integration.d.ts +6 -0
- package/dist/shared/integration.d.ts.map +1 -1
- package/dist/shared/integration.js +28 -1
- package/dist/shared/integration.js.map +1 -1
- package/dist/shared/marks.js +7 -1
- package/dist/shared/marks.js.map +1 -1
- package/dist/shared/package.js +3 -1
- package/dist/shared/packages.js +1 -1
- package/dist/shared/playwright.js +39 -1
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/react.js +25 -0
- package/dist/shared/react.js.map +1 -0
- package/dist/shared/recommended.js +6 -3
- package/dist/shared/recommended.js.map +1 -1
- package/dist/shared/recording.js +80 -3
- package/dist/shared/recording.js.map +1 -1
- package/dist/shared/recordings.js +30 -2
- package/dist/shared/recordings.js.map +1 -1
- package/dist/shared/screenshots.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +1 -0
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +11 -0
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/vite.d.ts +1 -1
- package/dist/shared/vite.d.ts.map +1 -1
- package/dist/shared/vite.js +28 -10
- package/dist/shared/vite.js.map +1 -1
- package/dist/tailwind/client.d.ts +1 -1
- package/dist/tailwind/index.d.ts +1 -1
- package/dist/tasks/client.d.ts +1 -1
- package/dist/tasks/client.js +45 -19
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/voice/client.d.ts +1 -1
- package/dist/voice/client.js +1 -1
- package/dist/voice/index.d.ts +1 -1
- package/dist/webpack.d.ts +4 -0
- package/dist/webpack.d.ts.map +1 -1
- package/dist/webpack.js +37 -15
- package/dist/webpack.js.map +1 -1
- package/package.json +25 -1
- package/src/bun.ts +32 -8
- package/src/cli/bun.ts +2 -2
- package/src/cli/init.ts +14 -9
- package/src/cli/recording.ts +90 -4
- package/src/cli/task.ts +4 -0
- package/src/cli.ts +13 -6
- package/src/client/dom.ts +14 -0
- package/src/client/index.ts +25 -14
- package/src/index.ts +11 -0
- package/src/next.ts +34 -15
- package/src/plugins/react/client.ts +162 -0
- package/src/plugins/react/index.ts +130 -0
- package/src/plugins/react/renders.ts +219 -0
- package/src/plugins/react/serialize.ts +139 -0
- package/src/plugins/react/timeline.ts +143 -0
- package/src/plugins/recommended/index.ts +17 -5
- package/src/plugins/recordings/client.ts +64 -4
- package/src/plugins/recordings/marks.ts +7 -0
- package/src/plugins/recordings/replay.ts +30 -2
- package/src/plugins/screenshots/client.ts +42 -2
- package/src/plugins/screenshots/index.ts +11 -0
- package/src/plugins/screenshots/playwright.ts +65 -1
- package/src/plugins/screenshots/rrweb.ts +55 -28
- package/src/plugins/screenshots/states.ts +26 -0
- package/src/plugins/tasks/client.ts +41 -6
- package/src/plugins/tasks/composer.ts +24 -7
- package/src/plugins/tasks/index.ts +16 -2
- package/src/tools/integration.ts +33 -0
- package/src/tools/source.ts +14 -2
- package/src/vite.ts +31 -10
- package/src/webpack.ts +48 -16
package/dist/shared/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","names":[],"sources":["../../src/cli/edit.ts","../../src/cli/bun.ts","../../src/cli/init.ts"],"sourcesContent":["/**\n * Editing a project's own source the way it's written: its quotes, semicolons, line endings and indentation. What\n * `init` adds to a bundler's config and to a Bun server goes through here.\n */\nimport type MagicString from 'magic-string';\nimport type { Program } from 'oxc-parser';\n\n/** The file's line ending. */\nexport const eolOf = (code: string) => (code.includes('\\r\\n') ? '\\r\\n' : '\\n');\n\n/** The whitespace a line starts with, for the line `offset` is on. */\nexport function indentAt(code: string, offset: number): string {\n const start = code.lastIndexOf('\\n', offset - 1) + 1;\n return /^[ \\t]*/.exec(code.slice(start))![0];\n}\n\n/**\n * Adds import lines after the module's last import (or `require`, in CommonJS), or at its top: written in the quotes\n * and semicolons of its first import. Each line is `[what, from]`: `import ${what} from '${from}'`, or as a `require`.\n */\nexport function addImports(out: MagicString, program: Program, code: string, lines: [string, string][], commonjs = false): void {\n const eol = eolOf(code);\n const imports = program.body.filter((s) => s.type === 'ImportDeclaration');\n const first = imports[0];\n const quote = first === undefined ? \"'\" : code[first.source.start]!;\n const semi = first === undefined || code.slice(first.start, first.end).trimEnd().endsWith(';') ? ';' : '';\n const q = (s: string) => `${quote}${s}${quote}`;\n const text = lines\n .map(([what, from]) => (commonjs ? `const ${what} = require(${q(from)})${semi}` : `import ${what} from ${q(from)}${semi}`))\n .join(eol);\n const after = imports.at(-1) ?? requiresOf(program).at(-1);\n if (after === undefined) out.prepend(`${text}${eol}${eol}`);\n else out.appendLeft(after.end, `${eol}${text}`);\n}\n\n/** The top-level `const … = require(…)` statements of a CommonJS module, to put new ones after. */\nfunction requiresOf(program: Program) {\n return program.body.filter(\n (s) =>\n s.type === 'VariableDeclaration' &&\n s.declarations.some(\n (d) => d.init?.type === 'CallExpression' && d.init.callee.type === 'Identifier' && d.init.callee.name === 'require',\n ),\n );\n}\n\n/** Inserts `text` as the first property of the object literal that starts at `open` (its `{`), as the object is laid out. */\nexport function addFirst(out: MagicString, code: string, open: number, first: { start: number } | undefined, text: string): void {\n const eol = eolOf(code);\n if (first === undefined) {\n out.appendLeft(open + 1, ` ${text} `);\n return;\n }\n const multiline = code.slice(open, first.start).includes('\\n');\n out.appendLeft(first.start, multiline ? `${text},${eol}${indentAt(code, first.start)}` : `${text}, `);\n}\n","/**\n * `init` for Bun's own dev server: `Bun.serve` with HTML imports, which bundles the page with the plugins bunfig.toml\n * names. Only that: a Bun project that runs Vite, Next.js or another bundler is that bundler's, and one with no HTML\n * imports has no page of Bun's for deictic to be in. Three steps, as the API has them: the plugin's module, bunfig's\n * `[serve.static] plugins`, and its routes spread into `Bun.serve`'s.\n */\nimport { readdirSync, readFileSync } from 'node:fs';\nimport { dirname, join, relative } from 'node:path';\n\nimport MagicString from 'magic-string';\nimport { type CallExpression, parseSync, Visitor } from 'oxc-parser';\n\nimport { addFirst, addImports, eolOf } from './edit.ts';\n\n/** The plugin's module, from the root, which bunfig names and the server imports. */\nexport const MODULE = 'deictic.plugin.ts';\n\nexport const PLUGIN = `import { deictic } from 'deictic/bun';\nimport { recommended } from 'deictic/recommended';\n\n// One module for both: bunfig.toml names it as the dev server's bundler plugin, and the server spreads its routes,\n// deictic's endpoints, into its own.\nexport default deictic({ plugins: recommended() });\n`;\n\nconst SOURCE = /\\.[cm]?[jt]sx?$/;\nconst SKIP = new Set(['node_modules', 'dist', 'build', 'out']);\nconst SERVE = /\\bBun\\.serve\\s*\\(/;\nconst HTML = /\\bfrom\\s*['\"][^'\"]+\\.html['\"]/;\n\n/**\n * The module that serves the page with Bun's bundler: it calls `Bun.serve` and imports an HTML file. Looked for under\n * the root, not in dependencies, builds or dot folders, a few folders deep.\n */\nexport function serverOf(root: string): string | undefined {\n const walk = (dir: string, depth: number): string | undefined => {\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return undefined;\n }\n for (const e of entries) {\n if (!e.isFile() || !SOURCE.test(e.name)) continue;\n const path = join(dir, e.name);\n const code = readFileSync(path, 'utf8');\n if (SERVE.test(code) && HTML.test(code)) return path;\n }\n if (depth === 0) return undefined;\n for (const e of entries) {\n if (!e.isDirectory() || e.name.startsWith('.') || SKIP.has(e.name)) continue;\n const found = walk(join(dir, e.name), depth - 1);\n if (found !== undefined) return found;\n }\n return undefined;\n };\n return walk(root, 3);\n}\n\n/**\n * bunfig.toml with the plugin's module first in `[serve.static] plugins` (first, so it sees the source as written),\n * made where there's none; unchanged where it's there already, and nothing where bunfig says it another way (a dotted\n * key, an inline table) and it can't tell where.\n */\nexport function addToBunfig(text: string | undefined, entry = `./${MODULE}`): string | undefined {\n const quoted = JSON.stringify(entry);\n if (text === undefined) return `[serve.static]\\nplugins = [${quoted}]\\n`;\n if (text.includes(entry)) return text;\n if (/serve\\.static\\.|static\\s*=\\s*\\{/.test(text)) return undefined;\n const eol = eolOf(text);\n const header = /^[ \\t]*\\[serve\\.static\\][ \\t]*(#.*)?$/m.exec(text);\n if (header === null)\n return `${text}${text === '' || text.endsWith('\\n') ? '' : eol}${eol}[serve.static]${eol}plugins = [${quoted}]${eol}`;\n const bodyStart = header.index + header[0].length;\n const next = /^[ \\t]*\\[/m.exec(text.slice(bodyStart));\n const body = text.slice(bodyStart, next === null ? text.length : bodyStart + next.index);\n const list = /^[ \\t]*plugins[ \\t]*=[ \\t]*\\[/m.exec(body);\n if (list === null) return `${text.slice(0, bodyStart)}${eol}plugins = [${quoted}]${text.slice(bodyStart)}`;\n const open = bodyStart + list.index + list[0].length;\n const rest = text.slice(open);\n const empty = /^\\s*\\]/.test(rest);\n const lineBreak = /^[ \\t]*\\r?\\n([ \\t]*)/.exec(rest);\n if (empty) return `${text.slice(0, open)}${quoted}${rest.trimStart()}`;\n if (lineBreak !== null) return `${text.slice(0, open)}${eol}${lineBreak[1]}${quoted},${rest}`;\n return `${text.slice(0, open)}${quoted}, ${rest.trimStart()}`;\n}\n\n/**\n * The server with the plugin's routes first in `Bun.serve`'s `routes`, or `routes` with them where it has none, and\n * the module imported: nothing where `Bun.serve` isn't given an object it can see, or its routes aren't one.\n */\nexport function addToServer(file: string, code: string, root: string): string | undefined {\n const { program, errors } = parseSync(file, code, { preserveParens: false });\n if (errors.length > 0) return undefined;\n const calls: CallExpression[] = [];\n new Visitor({\n CallExpression(node) {\n const { callee } = node;\n if (\n callee.type === 'MemberExpression' &&\n callee.object.type === 'Identifier' &&\n callee.object.name === 'Bun' &&\n callee.property.type === 'Identifier' &&\n callee.property.name === 'serve'\n )\n calls.push(node);\n },\n }).visit(program);\n const options = calls.length === 1 ? calls[0]!.arguments[0] : undefined;\n if (options?.type !== 'ObjectExpression') return undefined;\n\n // `tools`, as the API names it, unless the module has a `tools` of its own.\n const name = /\\btools\\b/.test(code) ? 'deicticTools' : 'tools';\n const out = new MagicString(code);\n const routes = options.properties.find(\n (p) => p.type === 'Property' && !p.computed && p.key.type === 'Identifier' && p.key.name === 'routes',\n );\n if (routes === undefined) {\n addFirst(out, code, options.start, options.properties[0], `routes: { ...${name}.routes }`);\n } else {\n if (routes.type !== 'Property' || routes.value.type !== 'ObjectExpression') return undefined;\n addFirst(out, code, routes.value.start, routes.value.properties[0], `...${name}.routes`);\n }\n const from = relative(dirname(file), join(root, MODULE)).replaceAll('\\\\', '/');\n addImports(out, program, code, [[name, from.startsWith('.') ? from : `./${from}`]]);\n return out.toString();\n}\n\n/** What to add by hand, for a server or a bunfig it can't edit. */\nexport const BY_HAND = {\n bunfig: `[serve.static]\\nplugins = [\"./${MODULE}\"]`,\n server: `import tools from './${MODULE}';\\nBun.serve({ routes: { ...tools.routes, '/*': index } });`,\n};\n","/**\n * `deictic init`: the recommended setup in a project, in one step. It installs deictic and what the recommended\n * plugins import, with the project's package manager and as the project's own dev dependencies (deictic, the\n * page's bundle and the skill all find them from the project, so they can't come in through another package), adds\n * deictic to the bundler's config where it can find the place, and offers the agent skill.\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative } from 'node:path';\nimport { createInterface } from 'node:readline/promises';\n\nimport MagicString from 'magic-string';\nimport { type Expression, type ObjectExpression, parseSync, type Program } from 'oxc-parser';\n\nimport { recommended } from '#src/plugins/recommended/index.ts';\n\nimport { installCommand, packageManager, readJson, runnerOf } from '#src/tools/packages.ts';\n\nimport { fail } from './board.ts';\nimport { addToBunfig, addToServer, BY_HAND, MODULE, PLUGIN, serverOf } from './bun.ts';\nimport { addFirst, addImports } from './edit.ts';\n\nexport type Bundler = 'next' | 'astro' | 'vite' | 'rspack' | 'webpack' | 'bun';\n\ninterface Setup {\n /** The config files it looks for, in order. */\n files: string[];\n /** The module deictic's integration comes from, and its name there. */\n from: string;\n name: string;\n /** What goes in the config: in its `list`, or wrapped around the whole of it with `wrap`. */\n list?: string;\n value: string;\n wrap?: boolean;\n /** The snippet for a config it can't edit. */\n snippet: string;\n}\n\nconst extensions = (base: string) => ['ts', 'mts', 'js', 'mjs', 'cts', 'cjs'].map((e) => `${base}.${e}`);\nconst PLUGINS = '{ plugins: recommended() }';\n\nconst SETUPS: Record<Exclude<Bundler, 'bun'>, Setup> = {\n next: {\n files: extensions('next.config'),\n from: 'deictic/next',\n name: 'withDeictic',\n value: PLUGINS,\n wrap: true,\n snippet: `export default withDeictic(nextConfig, ${PLUGINS});`,\n },\n astro: {\n files: extensions('astro.config'),\n from: 'deictic/astro',\n name: 'deictic',\n list: 'integrations',\n value: `deictic(${PLUGINS})`,\n snippet: `export default defineConfig({ integrations: [deictic(${PLUGINS})] });`,\n },\n vite: {\n files: extensions('vite.config'),\n from: 'deictic/vite',\n name: 'deictic',\n list: 'plugins',\n value: `deictic(${PLUGINS})`,\n snippet: `export default defineConfig({ plugins: [deictic(${PLUGINS}), react()] });`,\n },\n rspack: {\n files: extensions('rspack.config'),\n from: 'deictic/webpack',\n name: 'DeicticPlugin',\n list: 'plugins',\n value: `new DeicticPlugin(${PLUGINS})`,\n snippet: `export default { plugins: [new DeicticPlugin(${PLUGINS})] };`,\n },\n webpack: {\n files: extensions('webpack.config'),\n from: 'deictic/webpack',\n name: 'DeicticPlugin',\n list: 'plugins',\n value: `new DeicticPlugin(${PLUGINS})`,\n snippet: `export default { plugins: [new DeicticPlugin(${PLUGINS})] };`,\n },\n};\n\n/** The project's root: the nearest folder with a package.json, from `dir` up. */\nexport function rootOf(dir: string): string | undefined {\n for (let at = dir; ; at = dirname(at)) {\n if (existsSync(join(at, 'package.json'))) return at;\n if (dirname(at) === at) return undefined;\n }\n}\n\n/** The project's dependencies and dev dependencies, by name. */\nfunction dependenciesOf(root: string): Set<string> {\n const manifest = readJson(join(root, 'package.json')) ?? {};\n return new Set([manifest.dependencies, manifest.devDependencies].flatMap((d) => Object.keys((d as object | undefined) ?? {})));\n}\n\n/** The bundler the project runs its dev server with, from its dependencies, or none deictic knows. */\nexport function bundlerOf(root: string): Bundler | undefined {\n const has = dependenciesOf(root);\n if (has.has('next')) return 'next';\n if (has.has('astro')) return 'astro';\n if (has.has('vite') || SETUPS.vite.files.some((f) => existsSync(join(root, f)))) return 'vite';\n if (has.has('@rspack/core') || has.has('@rspack/cli')) return 'rspack';\n if (has.has('webpack')) return 'webpack';\n // Bun's own bundler only where a server of the project's has it bundle a page: not every project Bun runs.\n if (serverOf(root) !== undefined) return 'bun';\n return undefined;\n}\n\n/** What the recommended setup imports, for the bundler: launch-editor opens files under webpack, which has no launcher. */\nexport function packagesFor(bundler: Bundler | undefined): string[] {\n const plugins = recommended().flatMap((p) => p.packages ?? []);\n return ['deictic', ...plugins, ...(bundler === 'webpack' || bundler === 'rspack' ? ['launch-editor'] : [])];\n}\n\ntype Node = Expression | ObjectExpression;\n\n/**\n * The object an expression comes to: through `defineConfig(…)`, `(…)`, `satisfies`, a function's return and a top-level\n * `const`. Not through another call: in `mergeConfig(base, {…})` or webpack-merge's `merge(common, {…})` the first\n * argument is a base the project may build with too, and the plugin isn't the base's.\n */\nfunction objectOf(node: Node | null | undefined, program: Program, depth = 0): ObjectExpression | undefined {\n if (node == null || depth > 8) return undefined;\n const next = (n: Node | null | undefined) => objectOf(n, program, depth + 1);\n if (node.type === 'ObjectExpression') return node;\n if (node.type === 'ParenthesizedExpression' || node.type === 'TSAsExpression' || node.type === 'TSSatisfiesExpression')\n return next(node.expression);\n if (node.type === 'CallExpression') {\n const { callee } = node;\n const named = (callee.type === 'Identifier' ? callee : callee.type === 'MemberExpression' ? callee.property : undefined) as\n { type: string; name?: string } | undefined;\n const [first] = node.arguments;\n if (named?.name !== 'defineConfig' || first === undefined || first.type === 'SpreadElement') return undefined;\n return next(first);\n }\n if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {\n const body = node.body;\n if (body === null) return undefined;\n if (body.type !== 'BlockStatement') return next(body);\n const returned = body.body.findLast((s) => s.type === 'ReturnStatement');\n return returned?.type === 'ReturnStatement' ? next(returned.argument) : undefined;\n }\n if (node.type !== 'Identifier') return undefined;\n for (const statement of program.body) {\n const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type !== 'VariableDeclaration') continue;\n const found = declaration.declarations.find((d) => d.id.type === 'Identifier' && d.id.name === node.name);\n if (found !== undefined) return next(found.init);\n }\n return undefined;\n}\n\n/** The config's exported value: `export default …` or `module.exports = …`, and whether it's CommonJS. */\nfunction exportedOf(program: Program): { value: Expression; commonjs: boolean } | undefined {\n for (const statement of program.body) {\n if (statement.type === 'ExportDefaultDeclaration') {\n const value = statement.declaration;\n return value.type.endsWith('Declaration') && value.type !== 'FunctionDeclaration'\n ? undefined\n : { value: value as Expression, commonjs: false };\n }\n if (statement.type !== 'ExpressionStatement' || statement.expression.type !== 'AssignmentExpression') continue;\n const { left, right } = statement.expression;\n const exports =\n left.type === 'MemberExpression' &&\n left.object.type === 'Identifier' &&\n left.object.name === 'module' &&\n left.property.type === 'Identifier' &&\n left.property.name === 'exports';\n if (exports) return { value: right, commonjs: true };\n }\n return undefined;\n}\n\n/**\n * The config with deictic added, or nothing where it can't tell where: deictic's import beside the config's, and its\n * plugin first in the list (`plugins`, `integrations`), as its marks count lines and columns in the code it's given, or the config wrapped (Next's). Written in the config's quotes,\n * semicolons and line endings.\n */\nexport function addToConfig(bundler: Exclude<Bundler, 'bun'>, file: string, code: string): string | undefined {\n const setup = SETUPS[bundler];\n const { program, errors } = parseSync(file, code, { preserveParens: false });\n if (errors.length > 0) return undefined;\n const exported = exportedOf(program);\n if (exported === undefined) return undefined;\n const out = new MagicString(code);\n\n if (setup.wrap) {\n out.appendLeft(exported.value.start, `${setup.name}(`);\n out.appendRight(exported.value.end, `, ${setup.value})`);\n } else {\n const object = objectOf(exported.value, program);\n if (object === undefined || !addTo(out, code, object, setup.list!, setup.value)) return undefined;\n }\n\n const lines: [string, string][] = [\n ['{ recommended }', 'deictic/recommended'],\n [`{ ${setup.name} }`, setup.from],\n ];\n addImports(out, program, code, lines, exported.commonjs);\n return out.toString();\n}\n\n/**\n * Adds `value` first in the object's array `list`, or the list with it, as the object is laid out. False where `list`\n * isn't an array. First, since a plugin before deictic's that changes a module (both `pre` under Vite) leaves the\n * page's marks pointing at its code, not the file.\n */\nfunction addTo(out: MagicString, code: string, object: ObjectExpression, list: string, value: string): boolean {\n const property = object.properties.find(\n (p) =>\n p.type === 'Property' &&\n !p.computed &&\n ((p.key.type === 'Identifier' && p.key.name === list) || (p.key.type === 'Literal' && p.key.value === list)),\n );\n if (property !== undefined) {\n if (property.type !== 'Property') return false;\n let array = property.value;\n while (array.type === 'TSAsExpression' || array.type === 'TSSatisfiesExpression') array = array.expression;\n if (array.type !== 'ArrayExpression') return false;\n const first = array.elements.find((e) => e !== null);\n if (first == null) {\n out.appendLeft(array.start + 1, value);\n return true;\n }\n addFirst(out, code, array.start, first, value);\n return true;\n }\n addFirst(out, code, object.start, object.properties[0], `${list}: [${value}]`);\n return true;\n}\n\nexport interface InitOptions {\n /** Where it runs: the project is the nearest folder with a package.json. */\n cwd: string;\n /** Installs the packages; false only says the command. */\n install?: boolean;\n /** Adds the skill (true), says how (false), or asks (undefined, on a terminal; says how elsewhere). */\n skill?: boolean;\n /** Says what it would do, and does none of it. */\n dryRun?: boolean;\n log?: (line: string) => void;\n /** Runs a command in the project, and answers whether it succeeded. */\n run?: (command: string, cwd: string) => boolean;\n ask?: (question: string) => Promise<boolean>;\n}\n\nconst runIn = (command: string, cwd: string) => spawnSync(command, { cwd, stdio: 'inherit', shell: true }).status === 0;\n\n/** Sets the project up; throws what to do where it can't. */\nexport async function init(options: InitOptions): Promise<void> {\n const { install = true, dryRun = false, log = console.log, run = runIn } = options;\n const root = rootOf(options.cwd);\n if (root === undefined) throw new Error('deictic: no package.json here or above: run it in your project');\n const manager = packageManager(root);\n const bundler = bundlerOf(root);\n const has = dependenciesOf(root);\n\n const wanted = packagesFor(bundler).filter((p) => !has.has(p));\n const command = installCommand(manager, wanted, root);\n if (wanted.length === 0) {\n log('deictic: its packages are installed');\n } else if (!install || dryRun) {\n log(`deictic: install them with ${command}`);\n } else {\n log(`deictic: ${command}`);\n if (!run(command, root)) throw new Error(`deictic: the install failed: run ${command} yourself, then this again`);\n }\n\n configure(root, bundler, dryRun, log);\n\n const skill = `${runnerOf(manager)} skills add ${existsSync(join(root, 'node_modules', 'deictic')) ? './node_modules/deictic' : 'gkurt/deictic'}`;\n const add =\n options.skill ?? (options.ask === undefined ? false : await options.ask('deictic: add the skill, so your agent works the tasks?'));\n if (!add || dryRun) {\n log(`deictic: to have your agent work the tasks, add the skill: ${skill}`);\n } else {\n log(`deictic: ${skill}`);\n if (!run(skill, root)) log(`deictic: adding the skill failed: run ${skill} yourself`);\n }\n\n log(`deictic: screenshots render in Playwright's Chromium (${runnerOf(manager)} playwright install chromium), else Chrome or Edge`);\n log('deictic: start your dev server and Alt-click an element');\n}\n\n/** Adds deictic to the bundler's config, or says what to add where it can't. */\nfunction configure(root: string, bundler: Bundler | undefined, dryRun: boolean, log: (line: string) => void): void {\n if (bundler === undefined) {\n log('deictic: no bundler it knows in package.json (Vite, Next.js, Astro, webpack, Rspack, Bun): see API.md#bundlers to add it');\n return;\n }\n if (bundler === 'bun') {\n configureBun(root, dryRun, log);\n return;\n }\n const setup = SETUPS[bundler];\n const file = setup.files.map((f) => join(root, f)).find((f) => existsSync(f));\n const imports = `import { recommended } from 'deictic/recommended';\\nimport { ${setup.name} } from '${setup.from}';`;\n if (file === undefined) {\n log(`deictic: no ${setup.files[0]} here: add deictic to your ${bundler} config:\\n\\n${imports}\\n${setup.snippet}\\n`);\n return;\n }\n const name = relative(root, file).replaceAll('\\\\', '/');\n const code = readFileSync(file, 'utf8');\n if (/['\"]deictic\\//.test(code)) {\n log(`deictic: ${name} has it already`);\n return;\n }\n const added = addToConfig(bundler, file, code);\n if (added === undefined) {\n log(`deictic: couldn't tell where it goes in ${name}: add it yourself:\\n\\n${imports}\\n${setup.snippet}\\n`);\n return;\n }\n if (!dryRun) writeFileSync(file, added);\n log(`deictic: ${dryRun ? 'would add' : 'added'} it to ${name}`);\n}\n\n/** Bun's three steps: the plugin's module, bunfig.toml, and its routes in the server. Each says what to add where it can't. */\nfunction configureBun(root: string, dryRun: boolean, log: (line: string) => void): void {\n const write = (file: string, text: string) => !dryRun && writeFileSync(file, text);\n const did = dryRun ? 'would add' : 'added';\n const plugin = join(root, MODULE);\n if (!existsSync(plugin)) {\n write(plugin, PLUGIN);\n log(`deictic: ${dryRun ? 'would write' : 'wrote'} ${MODULE}`);\n } else if (!readFileSync(plugin, 'utf8').includes('deictic/bun')) {\n log(`deictic: ${MODULE} is a module of yours: add deictic by hand, as API.md#bundlers says for Bun`);\n return;\n }\n\n const bunfig = join(root, 'bunfig.toml');\n const before = existsSync(bunfig) ? readFileSync(bunfig, 'utf8') : undefined;\n const after = addToBunfig(before);\n if (after === undefined) {\n log(`deictic: couldn't tell where it goes in bunfig.toml: add it yourself:\\n\\n${BY_HAND.bunfig}\\n`);\n } else if (after === before) {\n log('deictic: bunfig.toml has it already');\n } else {\n write(bunfig, after);\n log(`deictic: ${did} it to bunfig.toml`);\n }\n\n const server = serverOf(root)!;\n const name = relative(root, server).replaceAll('\\\\', '/');\n const code = readFileSync(server, 'utf8');\n if (code.includes(MODULE.replace(/\\.ts$/, ''))) {\n log(`deictic: ${name} has its routes already`);\n return;\n }\n const added = addToServer(server, code, root);\n if (added === undefined) {\n log(`deictic: couldn't tell where its routes go in ${name}: add them yourself:\\n\\n${BY_HAND.server}\\n`);\n return;\n }\n write(server, added);\n log(`deictic: ${did} its routes to ${name}`);\n}\n\n/** Asks a yes-or-no question on the terminal, yes by default. */\nasync function ask(question: string): Promise<boolean> {\n const lines = createInterface({ input: process.stdin, output: process.stdout });\n try {\n return !/^n/i.test((await lines.question(`${question} (Y/n) `)).trim());\n } finally {\n lines.close();\n }\n}\n\nexport async function run(values: { dryRun?: boolean; install: boolean; skill?: boolean }): Promise<void> {\n try {\n await init({\n cwd: process.cwd(),\n install: values.install,\n skill: values.skill,\n dryRun: values.dryRun,\n ask: process.stdin.isTTY && process.stdout.isTTY ? ask : undefined,\n });\n } catch (e) {\n fail(e instanceof Error ? e.message : String(e));\n }\n}\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,SAAS,SAAkB,KAAK,SAAS,MAAM,IAAI,SAAS;;AAGzE,SAAgB,SAAS,MAAc,QAAwB;CAC7D,MAAM,QAAQ,KAAK,YAAY,MAAM,SAAS,CAAC,IAAI;CACnD,OAAO,UAAU,KAAK,KAAK,MAAM,KAAK,CAAC,CAAC,CAAE;AAC5C;;;;;AAMA,SAAgB,WAAW,KAAkB,SAAkB,MAAc,OAA2B,WAAW,OAAa;CAC9H,MAAM,MAAM,MAAM,IAAI;CACtB,MAAM,UAAU,QAAQ,KAAK,QAAQ,MAAM,EAAE,SAAS,mBAAmB;CACzE,MAAM,QAAQ,QAAQ;CACtB,MAAM,QAAQ,UAAU,KAAA,IAAY,MAAM,KAAK,MAAM,OAAO;CAC5D,MAAM,OAAO,UAAU,KAAA,KAAa,KAAK,MAAM,MAAM,OAAO,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,SAAS,GAAG,IAAI,MAAM;CACvG,MAAM,KAAK,MAAc,GAAG,QAAQ,IAAI;CACxC,MAAM,OAAO,MACV,KAAK,CAAC,MAAM,UAAW,WAAW,SAAS,KAAK,aAAa,EAAE,IAAI,EAAE,GAAG,SAAS,UAAU,KAAK,QAAQ,EAAE,IAAI,IAAI,MAAO,CAAC,CAC1H,KAAK,GAAG;CACX,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK,WAAW,OAAO,CAAC,CAAC,GAAG,EAAE;CACzD,IAAI,UAAU,KAAA,GAAW,IAAI,QAAQ,GAAG,OAAO,MAAM,KAAK;MACrD,IAAI,WAAW,MAAM,KAA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I,iBAAiB,MAAM;AAC7C;;AAGA,eAAe,IAAI,UAAoC;CACrD,MAAM,QAAQ,gBAAgB;EAAE,OAAO,QAAQ;EAAO,QAAQ,QAAQ;CAAO,CAAC;CAC9E,IAAI;EACF,OAAO,CAAC,MAAM,MAAM,MAAM,MAAM,SAAS,GAAG,SAAS,QAAQ,EAAA,CAAG,KAAK,CAAC;CACxE,UAAU;EACR,MAAM,MAAM;CACd;AACF;AAEA,eAAsB,IAAI,QAAgF;CACxG,IAAI;EACF,MAAM,KAAK;GACT,KAAK,QAAQ,IAAI;GACjB,SAAS,OAAO;GAChB,OAAO,OAAO;GACd,QAAQ,OAAO;GACf,KAAK,QAAQ,MAAM,SAAS,QAAQ,OAAO,QAAQ,MAAM,KAAA;EAC3D,CAAC;CACH,SAAS,GAAG;EACV,KAAK,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;CACjD;AACF"}
|
|
1
|
+
{"version":3,"file":"init.js","names":[],"sources":["../../src/cli/edit.ts","../../src/cli/bun.ts","../../src/cli/init.ts"],"sourcesContent":["/**\n * Editing a project's own source the way it's written: its quotes, semicolons, line endings and indentation. What\n * `init` adds to a bundler's config and to a Bun server goes through here.\n */\nimport type MagicString from 'magic-string';\nimport type { Program } from 'oxc-parser';\n\n/** The file's line ending. */\nexport const eolOf = (code: string) => (code.includes('\\r\\n') ? '\\r\\n' : '\\n');\n\n/** The whitespace a line starts with, for the line `offset` is on. */\nexport function indentAt(code: string, offset: number): string {\n const start = code.lastIndexOf('\\n', offset - 1) + 1;\n return /^[ \\t]*/.exec(code.slice(start))![0];\n}\n\n/**\n * Adds import lines after the module's last import (or `require`, in CommonJS), or at its top: written in the quotes\n * and semicolons of its first import. Each line is `[what, from]`: `import ${what} from '${from}'`, or as a `require`.\n */\nexport function addImports(out: MagicString, program: Program, code: string, lines: [string, string][], commonjs = false): void {\n const eol = eolOf(code);\n const imports = program.body.filter((s) => s.type === 'ImportDeclaration');\n const first = imports[0];\n const quote = first === undefined ? \"'\" : code[first.source.start]!;\n const semi = first === undefined || code.slice(first.start, first.end).trimEnd().endsWith(';') ? ';' : '';\n const q = (s: string) => `${quote}${s}${quote}`;\n const text = lines\n .map(([what, from]) => (commonjs ? `const ${what} = require(${q(from)})${semi}` : `import ${what} from ${q(from)}${semi}`))\n .join(eol);\n const after = imports.at(-1) ?? requiresOf(program).at(-1);\n if (after === undefined) out.prepend(`${text}${eol}${eol}`);\n else out.appendLeft(after.end, `${eol}${text}`);\n}\n\n/** The top-level `const … = require(…)` statements of a CommonJS module, to put new ones after. */\nfunction requiresOf(program: Program) {\n return program.body.filter(\n (s) =>\n s.type === 'VariableDeclaration' &&\n s.declarations.some(\n (d) => d.init?.type === 'CallExpression' && d.init.callee.type === 'Identifier' && d.init.callee.name === 'require',\n ),\n );\n}\n\n/** Inserts `text` as the first property of the object literal that starts at `open` (its `{`), as the object is laid out. */\nexport function addFirst(out: MagicString, code: string, open: number, first: { start: number } | undefined, text: string): void {\n const eol = eolOf(code);\n if (first === undefined) {\n out.appendLeft(open + 1, ` ${text} `);\n return;\n }\n const multiline = code.slice(open, first.start).includes('\\n');\n out.appendLeft(first.start, multiline ? `${text},${eol}${indentAt(code, first.start)}` : `${text}, `);\n}\n","/**\n * `init` for Bun's own dev server: `Bun.serve` with HTML imports, which bundles the page with the plugins bunfig.toml\n * names. Only that: a Bun project that runs Vite, Next.js or another bundler is that bundler's, and one with no HTML\n * imports has no page of Bun's for deictic to be in. Three steps, as the API has them: the plugin's module, bunfig's\n * `[serve.static] plugins`, and its routes spread into `Bun.serve`'s.\n */\nimport { readdirSync, readFileSync } from 'node:fs';\nimport { dirname, join, relative } from 'node:path';\n\nimport MagicString from 'magic-string';\nimport { type CallExpression, parseSync, Visitor } from 'oxc-parser';\n\nimport { addFirst, addImports, eolOf } from './edit.ts';\n\n/** The plugin's module, from the root, which bunfig names and the server imports. */\nexport const MODULE = 'deictic.plugin.ts';\n\nexport const PLUGIN = `import { deictic } from 'deictic/bun';\nimport { deicticRecommended } from 'deictic/recommended';\n\n// One module for both: bunfig.toml names it as the dev server's bundler plugin, and the server spreads its routes,\n// deictic's endpoints, into its own.\nexport default deictic({ plugins: deicticRecommended() });\n`;\n\nconst SOURCE = /\\.[cm]?[jt]sx?$/;\nconst SKIP = new Set(['node_modules', 'dist', 'build', 'out']);\nconst SERVE = /\\bBun\\.serve\\s*\\(/;\nconst HTML = /\\bfrom\\s*['\"][^'\"]+\\.html['\"]/;\n\n/**\n * The module that serves the page with Bun's bundler: it calls `Bun.serve` and imports an HTML file. Looked for under\n * the root, not in dependencies, builds or dot folders, a few folders deep.\n */\nexport function serverOf(root: string): string | undefined {\n const walk = (dir: string, depth: number): string | undefined => {\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return undefined;\n }\n for (const e of entries) {\n if (!e.isFile() || !SOURCE.test(e.name)) continue;\n const path = join(dir, e.name);\n const code = readFileSync(path, 'utf8');\n if (SERVE.test(code) && HTML.test(code)) return path;\n }\n if (depth === 0) return undefined;\n for (const e of entries) {\n if (!e.isDirectory() || e.name.startsWith('.') || SKIP.has(e.name)) continue;\n const found = walk(join(dir, e.name), depth - 1);\n if (found !== undefined) return found;\n }\n return undefined;\n };\n return walk(root, 3);\n}\n\n/**\n * bunfig.toml with the plugin's module first in `[serve.static] plugins` (first, so it sees the source as written),\n * made where there's none; unchanged where it's there already, and nothing where bunfig says it another way (a dotted\n * key, an inline table) and it can't tell where.\n */\nexport function addToBunfig(text: string | undefined, entry = `./${MODULE}`): string | undefined {\n const quoted = JSON.stringify(entry);\n if (text === undefined) return `[serve.static]\\nplugins = [${quoted}]\\n`;\n if (text.includes(entry)) return text;\n if (/serve\\.static\\.|static\\s*=\\s*\\{/.test(text)) return undefined;\n const eol = eolOf(text);\n const header = /^[ \\t]*\\[serve\\.static\\][ \\t]*(#.*)?$/m.exec(text);\n if (header === null)\n return `${text}${text === '' || text.endsWith('\\n') ? '' : eol}${eol}[serve.static]${eol}plugins = [${quoted}]${eol}`;\n const bodyStart = header.index + header[0].length;\n const next = /^[ \\t]*\\[/m.exec(text.slice(bodyStart));\n const body = text.slice(bodyStart, next === null ? text.length : bodyStart + next.index);\n const list = /^[ \\t]*plugins[ \\t]*=[ \\t]*\\[/m.exec(body);\n if (list === null) return `${text.slice(0, bodyStart)}${eol}plugins = [${quoted}]${text.slice(bodyStart)}`;\n const open = bodyStart + list.index + list[0].length;\n const rest = text.slice(open);\n const empty = /^\\s*\\]/.test(rest);\n const lineBreak = /^[ \\t]*\\r?\\n([ \\t]*)/.exec(rest);\n if (empty) return `${text.slice(0, open)}${quoted}${rest.trimStart()}`;\n if (lineBreak !== null) return `${text.slice(0, open)}${eol}${lineBreak[1]}${quoted},${rest}`;\n return `${text.slice(0, open)}${quoted}, ${rest.trimStart()}`;\n}\n\n/**\n * The server with the plugin's routes first in `Bun.serve`'s `routes`, or `routes` with them where it has none, and\n * the module imported: nothing where `Bun.serve` isn't given an object it can see, or its routes aren't one.\n */\nexport function addToServer(file: string, code: string, root: string): string | undefined {\n const { program, errors } = parseSync(file, code, { preserveParens: false });\n if (errors.length > 0) return undefined;\n const calls: CallExpression[] = [];\n new Visitor({\n CallExpression(node) {\n const { callee } = node;\n if (\n callee.type === 'MemberExpression' &&\n callee.object.type === 'Identifier' &&\n callee.object.name === 'Bun' &&\n callee.property.type === 'Identifier' &&\n callee.property.name === 'serve'\n )\n calls.push(node);\n },\n }).visit(program);\n const options = calls.length === 1 ? calls[0]!.arguments[0] : undefined;\n if (options?.type !== 'ObjectExpression') return undefined;\n\n // `tools`, as the API names it, unless the module has a `tools` of its own.\n const name = /\\btools\\b/.test(code) ? 'deicticTools' : 'tools';\n const out = new MagicString(code);\n const routes = options.properties.find(\n (p) => p.type === 'Property' && !p.computed && p.key.type === 'Identifier' && p.key.name === 'routes',\n );\n if (routes === undefined) {\n addFirst(out, code, options.start, options.properties[0], `routes: { ...${name}.routes }`);\n } else {\n if (routes.type !== 'Property' || routes.value.type !== 'ObjectExpression') return undefined;\n addFirst(out, code, routes.value.start, routes.value.properties[0], `...${name}.routes`);\n }\n const from = relative(dirname(file), join(root, MODULE)).replaceAll('\\\\', '/');\n addImports(out, program, code, [[name, from.startsWith('.') ? from : `./${from}`]]);\n return out.toString();\n}\n\n/** What to add by hand, for a server or a bunfig it can't edit. */\nexport const BY_HAND = {\n bunfig: `[serve.static]\\nplugins = [\"./${MODULE}\"]`,\n server: `import tools from './${MODULE}';\\nBun.serve({ routes: { ...tools.routes, '/*': index } });`,\n};\n","/**\n * `deictic init`: the recommended setup in a project, in one step. It installs deictic and what the recommended\n * plugins import, with the project's package manager and as the project's own dev dependencies (deictic, the\n * page's bundle and the skill all find them from the project, so they can't come in through another package), adds\n * deictic to the bundler's config where it can find the place, and offers the agent skill.\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative } from 'node:path';\nimport { createInterface } from 'node:readline/promises';\n\nimport MagicString from 'magic-string';\nimport { type Expression, type ObjectExpression, parseSync, type Program } from 'oxc-parser';\n\nimport { deicticRecommended } from '#src/plugins/recommended/index.ts';\n\nimport { installCommand, installed, packageManager, readJson, runnerOf } from '#src/tools/packages.ts';\n\nimport { fail } from './board.ts';\nimport { addToBunfig, addToServer, BY_HAND, MODULE, PLUGIN, serverOf } from './bun.ts';\nimport { addFirst, addImports } from './edit.ts';\n\nexport type Bundler = 'next' | 'astro' | 'vite' | 'rspack' | 'webpack' | 'bun';\n\ninterface Setup {\n /** The config files it looks for, in order. */\n files: string[];\n /** The module deictic's integration comes from, and its name there. */\n from: string;\n name: string;\n /** What goes in the config: in its `list`, or wrapped around the whole of it with `wrap`. */\n list?: string;\n value: string;\n wrap?: boolean;\n /** The snippet for a config it can't edit. */\n snippet: string;\n}\n\nconst extensions = (base: string) => ['ts', 'mts', 'js', 'mjs', 'cts', 'cjs'].map((e) => `${base}.${e}`);\nconst PLUGINS = '{ plugins: deicticRecommended() }';\n\nconst SETUPS: Record<Exclude<Bundler, 'bun'>, Setup> = {\n next: {\n files: extensions('next.config'),\n from: 'deictic/next',\n name: 'withDeictic',\n value: PLUGINS,\n wrap: true,\n snippet: `export default withDeictic(nextConfig, ${PLUGINS});`,\n },\n astro: {\n files: extensions('astro.config'),\n from: 'deictic/astro',\n name: 'deictic',\n list: 'integrations',\n value: `deictic(${PLUGINS})`,\n snippet: `export default defineConfig({ integrations: [deictic(${PLUGINS})] });`,\n },\n vite: {\n files: extensions('vite.config'),\n from: 'deictic/vite',\n name: 'deictic',\n list: 'plugins',\n value: `deictic(${PLUGINS})`,\n snippet: `export default defineConfig({ plugins: [deictic(${PLUGINS}), react()] });`,\n },\n rspack: {\n files: extensions('rspack.config'),\n from: 'deictic/webpack',\n name: 'DeicticPlugin',\n list: 'plugins',\n value: `new DeicticPlugin(${PLUGINS})`,\n snippet: `export default { plugins: [new DeicticPlugin(${PLUGINS})] };`,\n },\n webpack: {\n files: extensions('webpack.config'),\n from: 'deictic/webpack',\n name: 'DeicticPlugin',\n list: 'plugins',\n value: `new DeicticPlugin(${PLUGINS})`,\n snippet: `export default { plugins: [new DeicticPlugin(${PLUGINS})] };`,\n },\n};\n\n/** The project's root: the nearest folder with a package.json, from `dir` up. */\nexport function rootOf(dir: string): string | undefined {\n for (let at = dir; ; at = dirname(at)) {\n if (existsSync(join(at, 'package.json'))) return at;\n if (dirname(at) === at) return undefined;\n }\n}\n\n/** The project's dependencies and dev dependencies, by name. */\nfunction dependenciesOf(root: string): Set<string> {\n const manifest = readJson(join(root, 'package.json')) ?? {};\n return new Set([manifest.dependencies, manifest.devDependencies].flatMap((d) => Object.keys((d as object | undefined) ?? {})));\n}\n\n/** The bundler the project runs its dev server with, from its dependencies, or none deictic knows. */\nexport function bundlerOf(root: string): Bundler | undefined {\n const has = dependenciesOf(root);\n if (has.has('next')) return 'next';\n if (has.has('astro')) return 'astro';\n if (has.has('vite') || SETUPS.vite.files.some((f) => existsSync(join(root, f)))) return 'vite';\n if (has.has('@rspack/core') || has.has('@rspack/cli')) return 'rspack';\n if (has.has('webpack')) return 'webpack';\n // Bun's own bundler only where a server of the project's has it bundle a page: not every project Bun runs.\n if (serverOf(root) !== undefined) return 'bun';\n return undefined;\n}\n\n/**\n * What the recommended setup imports, for the bundler and the project: launch-editor opens files under webpack, which\n * has no launcher, and React's state is read only where it has React.\n */\nexport function packagesFor(bundler: Bundler | undefined, root: string): string[] {\n // Named in package.json and not installed yet, in a fresh checkout, or installed from a workspace's.\n const react = dependenciesOf(root).has('react') || installed(root, 'react');\n const plugins = deicticRecommended({ react: react ? {} : false }).flatMap((p) => p.packages ?? []);\n return ['deictic', ...plugins, ...(bundler === 'webpack' || bundler === 'rspack' ? ['launch-editor'] : [])];\n}\n\ntype Node = Expression | ObjectExpression;\n\n/**\n * The object an expression comes to: through `defineConfig(…)`, `(…)`, `satisfies`, a function's return and a top-level\n * `const`. Not through another call: in `mergeConfig(base, {…})` or webpack-merge's `merge(common, {…})` the first\n * argument is a base the project may build with too, and the plugin isn't the base's.\n */\nfunction objectOf(node: Node | null | undefined, program: Program, depth = 0): ObjectExpression | undefined {\n if (node == null || depth > 8) return undefined;\n const next = (n: Node | null | undefined) => objectOf(n, program, depth + 1);\n if (node.type === 'ObjectExpression') return node;\n if (node.type === 'ParenthesizedExpression' || node.type === 'TSAsExpression' || node.type === 'TSSatisfiesExpression')\n return next(node.expression);\n if (node.type === 'CallExpression') {\n const { callee } = node;\n const named = (callee.type === 'Identifier' ? callee : callee.type === 'MemberExpression' ? callee.property : undefined) as\n { type: string; name?: string } | undefined;\n const [first] = node.arguments;\n if (named?.name !== 'defineConfig' || first === undefined || first.type === 'SpreadElement') return undefined;\n return next(first);\n }\n if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {\n const body = node.body;\n if (body === null) return undefined;\n if (body.type !== 'BlockStatement') return next(body);\n const returned = body.body.findLast((s) => s.type === 'ReturnStatement');\n return returned?.type === 'ReturnStatement' ? next(returned.argument) : undefined;\n }\n if (node.type !== 'Identifier') return undefined;\n for (const statement of program.body) {\n const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type !== 'VariableDeclaration') continue;\n const found = declaration.declarations.find((d) => d.id.type === 'Identifier' && d.id.name === node.name);\n if (found !== undefined) return next(found.init);\n }\n return undefined;\n}\n\n/** The config's exported value: `export default …` or `module.exports = …`, and whether it's CommonJS. */\nfunction exportedOf(program: Program): { value: Expression; commonjs: boolean } | undefined {\n for (const statement of program.body) {\n if (statement.type === 'ExportDefaultDeclaration') {\n const value = statement.declaration;\n return value.type.endsWith('Declaration') && value.type !== 'FunctionDeclaration'\n ? undefined\n : { value: value as Expression, commonjs: false };\n }\n if (statement.type !== 'ExpressionStatement' || statement.expression.type !== 'AssignmentExpression') continue;\n const { left, right } = statement.expression;\n const exports =\n left.type === 'MemberExpression' &&\n left.object.type === 'Identifier' &&\n left.object.name === 'module' &&\n left.property.type === 'Identifier' &&\n left.property.name === 'exports';\n if (exports) return { value: right, commonjs: true };\n }\n return undefined;\n}\n\n/**\n * The config with deictic added, or nothing where it can't tell where: deictic's import beside the config's, and its\n * plugin first in the list (`plugins`, `integrations`), as its marks count lines and columns in the code it's given, or the config wrapped (Next's). Written in the config's quotes,\n * semicolons and line endings.\n */\nexport function addToConfig(bundler: Exclude<Bundler, 'bun'>, file: string, code: string): string | undefined {\n const setup = SETUPS[bundler];\n const { program, errors } = parseSync(file, code, { preserveParens: false });\n if (errors.length > 0) return undefined;\n const exported = exportedOf(program);\n if (exported === undefined) return undefined;\n const out = new MagicString(code);\n\n if (setup.wrap) {\n out.appendLeft(exported.value.start, `${setup.name}(`);\n out.appendRight(exported.value.end, `, ${setup.value})`);\n } else {\n const object = objectOf(exported.value, program);\n if (object === undefined || !addTo(out, code, object, setup.list!, setup.value)) return undefined;\n }\n\n const lines: [string, string][] = [\n ['{ deicticRecommended }', 'deictic/recommended'],\n [`{ ${setup.name} }`, setup.from],\n ];\n addImports(out, program, code, lines, exported.commonjs);\n return out.toString();\n}\n\n/**\n * Adds `value` first in the object's array `list`, or the list with it, as the object is laid out. False where `list`\n * isn't an array. First, since a plugin before deictic's that changes a module (both `pre` under Vite) leaves the\n * page's marks pointing at its code, not the file.\n */\nfunction addTo(out: MagicString, code: string, object: ObjectExpression, list: string, value: string): boolean {\n const property = object.properties.find(\n (p) =>\n p.type === 'Property' &&\n !p.computed &&\n ((p.key.type === 'Identifier' && p.key.name === list) || (p.key.type === 'Literal' && p.key.value === list)),\n );\n if (property !== undefined) {\n if (property.type !== 'Property') return false;\n let array = property.value;\n while (array.type === 'TSAsExpression' || array.type === 'TSSatisfiesExpression') array = array.expression;\n if (array.type !== 'ArrayExpression') return false;\n const first = array.elements.find((e) => e !== null);\n if (first == null) {\n out.appendLeft(array.start + 1, value);\n return true;\n }\n addFirst(out, code, array.start, first, value);\n return true;\n }\n addFirst(out, code, object.start, object.properties[0], `${list}: [${value}]`);\n return true;\n}\n\nexport interface InitOptions {\n /** Where it runs: the project is the nearest folder with a package.json. */\n cwd: string;\n /** Installs the packages; false only says the command. */\n install?: boolean;\n /** Adds the skill (true), says how (false), or asks (undefined, on a terminal; says how elsewhere). */\n skill?: boolean;\n /** Says what it would do, and does none of it. */\n dryRun?: boolean;\n log?: (line: string) => void;\n /** Runs a command in the project, and answers whether it succeeded. */\n run?: (command: string, cwd: string) => boolean;\n ask?: (question: string) => Promise<boolean>;\n}\n\nconst runIn = (command: string, cwd: string) => spawnSync(command, { cwd, stdio: 'inherit', shell: true }).status === 0;\n\n/** Sets the project up; throws what to do where it can't. */\nexport async function init(options: InitOptions): Promise<void> {\n const { install = true, dryRun = false, log = console.log, run = runIn } = options;\n const root = rootOf(options.cwd);\n if (root === undefined) throw new Error('deictic: no package.json here or above: run it in your project');\n const manager = packageManager(root);\n const bundler = bundlerOf(root);\n const has = dependenciesOf(root);\n\n const wanted = packagesFor(bundler, root).filter((p) => !has.has(p));\n const command = installCommand(manager, wanted, root);\n if (wanted.length === 0) {\n log('deictic: its packages are installed');\n } else if (!install || dryRun) {\n log(`deictic: install them with ${command}`);\n } else {\n log(`deictic: ${command}`);\n if (!run(command, root)) throw new Error(`deictic: the install failed: run ${command} yourself, then this again`);\n }\n\n configure(root, bundler, dryRun, log);\n\n const skill = `${runnerOf(manager)} skills add ${existsSync(join(root, 'node_modules', 'deictic')) ? './node_modules/deictic' : 'gkurt/deictic'}`;\n const add =\n options.skill ?? (options.ask === undefined ? false : await options.ask('deictic: add the skill, so your agent works the tasks?'));\n if (!add || dryRun) {\n log(`deictic: to have your agent work the tasks, add the skill: ${skill}`);\n } else {\n log(`deictic: ${skill}`);\n if (!run(skill, root)) log(`deictic: adding the skill failed: run ${skill} yourself`);\n }\n\n log(`deictic: screenshots render in Playwright's Chromium (${runnerOf(manager)} playwright install chromium), else Chrome or Edge`);\n log('deictic: start your dev server and Alt-click an element');\n}\n\n/** Adds deictic to the bundler's config, or says what to add where it can't. */\nfunction configure(root: string, bundler: Bundler | undefined, dryRun: boolean, log: (line: string) => void): void {\n if (bundler === undefined) {\n log('deictic: no bundler it knows in package.json (Vite, Next.js, Astro, webpack, Rspack, Bun): see API.md#bundlers to add it');\n return;\n }\n if (bundler === 'bun') {\n configureBun(root, dryRun, log);\n return;\n }\n const setup = SETUPS[bundler];\n const file = setup.files.map((f) => join(root, f)).find((f) => existsSync(f));\n const imports = `import { deicticRecommended } from 'deictic/recommended';\\nimport { ${setup.name} } from '${setup.from}';`;\n if (file === undefined) {\n log(`deictic: no ${setup.files[0]} here: add deictic to your ${bundler} config:\\n\\n${imports}\\n${setup.snippet}\\n`);\n return;\n }\n const name = relative(root, file).replaceAll('\\\\', '/');\n const code = readFileSync(file, 'utf8');\n if (/['\"]deictic\\//.test(code)) {\n log(`deictic: ${name} has it already`);\n return;\n }\n const added = addToConfig(bundler, file, code);\n if (added === undefined) {\n log(`deictic: couldn't tell where it goes in ${name}: add it yourself:\\n\\n${imports}\\n${setup.snippet}\\n`);\n return;\n }\n if (!dryRun) writeFileSync(file, added);\n log(`deictic: ${dryRun ? 'would add' : 'added'} it to ${name}`);\n}\n\n/** Bun's three steps: the plugin's module, bunfig.toml, and its routes in the server. Each says what to add where it can't. */\nfunction configureBun(root: string, dryRun: boolean, log: (line: string) => void): void {\n const write = (file: string, text: string) => !dryRun && writeFileSync(file, text);\n const did = dryRun ? 'would add' : 'added';\n const plugin = join(root, MODULE);\n if (!existsSync(plugin)) {\n write(plugin, PLUGIN);\n log(`deictic: ${dryRun ? 'would write' : 'wrote'} ${MODULE}`);\n } else if (!readFileSync(plugin, 'utf8').includes('deictic/bun')) {\n log(`deictic: ${MODULE} is a module of yours: add deictic by hand, as API.md#bundlers says for Bun`);\n return;\n }\n\n const bunfig = join(root, 'bunfig.toml');\n const before = existsSync(bunfig) ? readFileSync(bunfig, 'utf8') : undefined;\n const after = addToBunfig(before);\n if (after === undefined) {\n log(`deictic: couldn't tell where it goes in bunfig.toml: add it yourself:\\n\\n${BY_HAND.bunfig}\\n`);\n } else if (after === before) {\n log('deictic: bunfig.toml has it already');\n } else {\n write(bunfig, after);\n log(`deictic: ${did} it to bunfig.toml`);\n }\n\n const server = serverOf(root)!;\n const name = relative(root, server).replaceAll('\\\\', '/');\n const code = readFileSync(server, 'utf8');\n if (code.includes(MODULE.replace(/\\.ts$/, ''))) {\n log(`deictic: ${name} has its routes already`);\n return;\n }\n const added = addToServer(server, code, root);\n if (added === undefined) {\n log(`deictic: couldn't tell where its routes go in ${name}: add them yourself:\\n\\n${BY_HAND.server}\\n`);\n return;\n }\n write(server, added);\n log(`deictic: ${did} its routes to ${name}`);\n}\n\n/** Asks a yes-or-no question on the terminal, yes by default. */\nasync function ask(question: string): Promise<boolean> {\n const lines = createInterface({ input: process.stdin, output: process.stdout });\n try {\n return !/^n/i.test((await lines.question(`${question} (Y/n) `)).trim());\n } finally {\n lines.close();\n }\n}\n\nexport async function run(values: { dryRun?: boolean; install: boolean; skill?: boolean }): Promise<void> {\n try {\n await init({\n cwd: process.cwd(),\n install: values.install,\n skill: values.skill,\n dryRun: values.dryRun,\n ask: process.stdin.isTTY && process.stdout.isTTY ? ask : undefined,\n });\n } catch (e) {\n fail(e instanceof Error ? e.message : String(e));\n }\n}\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,SAAS,SAAkB,KAAK,SAAS,MAAM,IAAI,SAAS;;AAGzE,SAAgB,SAAS,MAAc,QAAwB;CAC7D,MAAM,QAAQ,KAAK,YAAY,MAAM,SAAS,CAAC,IAAI;CACnD,OAAO,UAAU,KAAK,KAAK,MAAM,KAAK,CAAC,CAAC,CAAE;AAC5C;;;;;AAMA,SAAgB,WAAW,KAAkB,SAAkB,MAAc,OAA2B,WAAW,OAAa;CAC9H,MAAM,MAAM,MAAM,IAAI;CACtB,MAAM,UAAU,QAAQ,KAAK,QAAQ,MAAM,EAAE,SAAS,mBAAmB;CACzE,MAAM,QAAQ,QAAQ;CACtB,MAAM,QAAQ,UAAU,KAAA,IAAY,MAAM,KAAK,MAAM,OAAO;CAC5D,MAAM,OAAO,UAAU,KAAA,KAAa,KAAK,MAAM,MAAM,OAAO,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,SAAS,GAAG,IAAI,MAAM;CACvG,MAAM,KAAK,MAAc,GAAG,QAAQ,IAAI;CACxC,MAAM,OAAO,MACV,KAAK,CAAC,MAAM,UAAW,WAAW,SAAS,KAAK,aAAa,EAAE,IAAI,EAAE,GAAG,SAAS,UAAU,KAAK,QAAQ,EAAE,IAAI,IAAI,MAAO,CAAC,CAC1H,KAAK,GAAG;CACX,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK,WAAW,OAAO,CAAC,CAAC,GAAG,EAAE;CACzD,IAAI,UAAU,KAAA,GAAW,IAAI,QAAQ,GAAG,OAAO,MAAM,KAAK;MACrD,IAAI,WAAW,MAAM,KAAK,GAAG,MAAM,MAAM;AAChD;;AAGA,SAAS,WAAW,SAAkB;CACpC,OAAO,QAAQ,KAAK,QACjB,MACC,EAAE,SAAS,yBACX,EAAE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Q,KAAK;CACnB,IAAI,YAAY,IAAI,iBAAiB,MAAM;AAC7C;;AAGA,eAAe,IAAI,UAAoC;CACrD,MAAM,QAAQ,gBAAgB;EAAE,OAAO,QAAQ;EAAO,QAAQ,QAAQ;CAAO,CAAC;CAC9E,IAAI;EACF,OAAO,CAAC,MAAM,MAAM,MAAM,MAAM,SAAS,GAAG,SAAS,QAAQ,EAAA,CAAG,KAAK,CAAC;CACxE,UAAU;EACR,MAAM,MAAM;CACd;AACF;AAEA,eAAsB,IAAI,QAAgF;CACxG,IAAI;EACF,MAAM,KAAK;GACT,KAAK,QAAQ,IAAI;GACjB,SAAS,OAAO;GAChB,OAAO,OAAO;GACd,QAAQ,OAAO;GACf,KAAK,QAAQ,MAAM,SAAS,QAAQ,OAAO,QAAQ,MAAM,KAAA;EAC3D,CAAC;CACH,SAAS,GAAG;EACV,KAAK,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;CACjD;AACF"}
|
|
@@ -9,6 +9,12 @@ interface DeicticOptions {
|
|
|
9
9
|
* `false` for none, leaving only plugins' own shortcuts.
|
|
10
10
|
*/
|
|
11
11
|
shortcut?: Shortcut | false;
|
|
12
|
+
/**
|
|
13
|
+
* For a package that adds its own plugin to the bundler with deictic (prosebook does): these options give way to
|
|
14
|
+
* those of any other deictic in the same build, which merges them in, so the app's own `deictic()` decides the
|
|
15
|
+
* shortcut and its plugin of the same name is the one loaded.
|
|
16
|
+
*/
|
|
17
|
+
defaults?: boolean;
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
20
|
* The client module: the overlay, started with deictic's own shortcut and each plugin that has a half
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.ts","names":[],"sources":["../../src/tools/integration.ts"],"mappings":";;;UAmBiB;;EAEf,UAAU;;;;;EAKV,WAAW;;;;;;;
|
|
1
|
+
{"version":3,"file":"integration.d.ts","names":[],"sources":["../../src/tools/integration.ts"],"mappings":";;;UAmBiB;;EAEf,UAAU;;;;;EAKV,WAAW;;;;;;EAMX;;;;;;;cA0CW,eAAY,SAAa,gBAAc,cAAc,MAAQ,kBAAgB"}
|
|
@@ -247,6 +247,33 @@ async function setUp(root, plugins, report) {
|
|
|
247
247
|
* under Vite, a file in `.deictic/` elsewhere, as webpack, Turbopack and Bun have none), where the
|
|
248
248
|
* endpoints are served, and what opens the editor.
|
|
249
249
|
*/
|
|
250
|
+
/**
|
|
251
|
+
* Every deictic one build was given, as one: the app's and those packages added (`defaults`). The plugins of all of
|
|
252
|
+
* them, each name once, the first given winning, those of an instance with `defaults` after the rest's; any other
|
|
253
|
+
* option from the first that sets it, the same way. Two that aren't `defaults` setting one differently is an error,
|
|
254
|
+
* as neither can be the one meant.
|
|
255
|
+
*/
|
|
256
|
+
function merge(instances) {
|
|
257
|
+
const ordered = [...instances.filter((o) => o.defaults !== true), ...instances.filter((o) => o.defaults === true)];
|
|
258
|
+
const plugins = /* @__PURE__ */ new Map();
|
|
259
|
+
const merged = {};
|
|
260
|
+
const setBy = {};
|
|
261
|
+
for (const options of ordered) {
|
|
262
|
+
for (const plugin of options.plugins ?? []) if (!plugins.has(plugin.name)) plugins.set(plugin.name, plugin);
|
|
263
|
+
for (const [key, value] of Object.entries(options)) {
|
|
264
|
+
if (key === "plugins" || key === "defaults" || value === void 0) continue;
|
|
265
|
+
const first = setBy[key];
|
|
266
|
+
if (first === void 0) {
|
|
267
|
+
merged[key] = value;
|
|
268
|
+
setBy[key] = options;
|
|
269
|
+
} else if (first.defaults !== true && options.defaults !== true && JSON.stringify(merged[key]) !== JSON.stringify(value)) throw new Error(`deictic: the build has deictic twice, with ${key} set two ways: set it in one of them only`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
...merged,
|
|
274
|
+
plugins: [...plugins.values()]
|
|
275
|
+
};
|
|
276
|
+
}
|
|
250
277
|
/** The options with their defaults, checked now, so a wrong set stops the dev server as it starts, not the page. */
|
|
251
278
|
function prepare(options) {
|
|
252
279
|
const plugins = options.plugins ?? [];
|
|
@@ -328,6 +355,6 @@ function fileIn(path, root) {
|
|
|
328
355
|
const file = relative(root, path).replaceAll("\\", "/");
|
|
329
356
|
return file.startsWith("..") || isAbsolute(file) ? void 0 : file;
|
|
330
357
|
}
|
|
331
|
-
export {
|
|
358
|
+
export { isHost as _, markAstro as a, openingsIn as b, writeClient as c, problemIn as d, reporter as f, JSX as g, parseAstro as h, mark as i, setUp as l, ASTRO as m, clientModule as n, merge as o, stackOf as p, importOf as r, prepare as s, beside as t, messageOf as u, lineStarts as v, parse as x, offsetOf as y };
|
|
332
359
|
|
|
333
360
|
//# sourceMappingURL=integration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.js","names":["OWN","OWN"],"sources":["../../src/tools/locate.ts","../../src/tools/astro.ts","../../src/tools/problems.ts","../../src/tools/plugins.ts","../../src/tools/integration.ts"],"sourcesContent":["/**\n * Marks each host element in a JSX module with where its opening tag starts:\n * `<div data-deictic=\"src/App.tsx:12:5\">`. The page reads it back to know what was clicked.\n *\n * At build time and not from React's fibers at runtime: it works for any framework that compiles JSX,\n * for server components (which have no fiber in the browser), and it names the element's own tag\n * rather than the component that rendered it. Only host elements (`div`, `button`) are marked, since a\n * component may not pass the attribute on; a component's call site is reached from its elements.\n *\n * The transform must run on the source as written (`enforce: 'pre'` under Vite), so lines and columns\n * are the file's. It runs alike on the server and in the browser, so a hydrated page matches its HTML.\n */\nimport MagicString from 'magic-string';\nimport { type JSXOpeningElement, parseSync, type Program, Visitor } from 'oxc-parser';\n\nexport const ATTRIBUTE = 'data-deictic';\n/** Modules that may hold JSX: `.jsx` and `.tsx`, and plain `.js`, as many React projects write theirs. */\nexport const JSX = /\\.[cm]?(?:[jt]sx|js)$/;\n\n/** A module parsed, with JSX read in a `.js` file too, which the parser reads there only when told. */\nexport const parse = (file: string, code: string) => parseSync(file, code, /\\.[cm]?js$/.test(file) ? { lang: 'jsx' } : undefined);\n\nexport interface Located {\n code: string;\n map: ReturnType<MagicString['generateMap']>;\n}\n\n/** Whether an opening tag is a host element's, `<div>` or `<svg>`, not a component's or a namespaced one. */\nexport const isHost = (el: JSXOpeningElement) => el.name.type === 'JSXIdentifier' && /^[a-z]/.test(el.name.name);\n\n/**\n * `code` with every host element marked, `file` being its path from the project's root, and `append`\n * after it (the client's import, in the browser); nothing when there is nothing to mark, or the module\n * doesn't parse, which the framework's own transform reports better.\n */\nexport function locate(code: string, file: string, append = ''): Located | undefined {\n // No tag, no parse: most `.js` modules have none, and every one of the project's comes through here.\n if (!/<[a-z]/.test(code)) return undefined;\n const { program, errors } = parse(file, code);\n if (errors.length > 0) return undefined;\n return marked(code, file, openingsIn(program), append);\n}\n\n/** Every opening tag in a module, in its order. */\nexport function openingsIn(program: Program): JSXOpeningElement[] {\n const elements: JSXOpeningElement[] = [];\n new Visitor({ JSXOpeningElement: (el) => void elements.push(el) }).visit(program);\n return elements;\n}\n\n/**\n * `code` with a mark in each of `elements` that is a host element's and has none yet, and `append` after\n * it; nothing with none to mark.\n */\nexport function marked(code: string, file: string, elements: JSXOpeningElement[], append = ''): Located | undefined {\n const lines = lineStarts(code);\n const s = new MagicString(code);\n for (const el of elements) {\n if (!isHost(el) || el.attributes.some((a) => a.type === 'JSXAttribute' && nameOf(a.name) === ATTRIBUTE)) continue;\n const { line, column } = position(lines, el.start);\n s.appendLeft(el.name.end, ` ${ATTRIBUTE}=\"${file}:${line}:${column}\"`);\n }\n if (!s.hasChanged()) return undefined;\n if (append !== '') s.append(append);\n // A map's source is read from the module's own folder, so it's the file's name, not its path from the root.\n return { code: s.toString(), map: s.generateMap({ source: file.slice(file.lastIndexOf('/') + 1), hires: 'boundary' }) };\n}\n\nconst nameOf = (name: { type: string; name?: unknown }) => (name.type === 'JSXIdentifier' ? name.name : undefined);\n\n/** Where each line starts, by offset. */\nexport function lineStarts(code: string): number[] {\n const starts = [0];\n for (let i = code.indexOf('\\n'); i !== -1; i = code.indexOf('\\n', i + 1)) starts.push(i + 1);\n return starts;\n}\n\n/** An offset's line and column, from 1. */\nexport function position(lines: number[], offset: number): { line: number; column: number } {\n let lo = 0;\n let hi = lines.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (lines[mid]! <= offset) lo = mid;\n else hi = mid - 1;\n }\n return { line: lo + 1, column: offset - lines[lo]! + 1 };\n}\n\n/** A line and column's offset, or nothing past the file's end. */\nexport function offsetOf(lines: number[], line: number, column: number): number | undefined {\n const start = lines[line - 1];\n return start === undefined ? undefined : start + column - 1;\n}\n","/**\n * `.astro` components. They aren't JSX modules, but Astro 7's own parser reads a template as JSX, into the\n * tree oxc makes (offsets in UTF-16, as ours are), so its host elements are marked as a JSX module's are,\n * before Astro compiles the file. The parser is the project's own Astro's (`@astrojs/compiler-rs`, found\n * through `astro`), so it reads a file exactly as the compiler will; an Astro before 7 has none like it,\n * and its `.astro` files are left unmarked.\n */\nimport { createRequire } from 'node:module';\nimport { join } from 'node:path';\n\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport { type Located, marked } from './locate.ts';\n\nexport const ASTRO = /\\.astro$/;\n\n/** A file parsed: its module (an `.astro` file's frontmatter), and each opening tag in it, in the file's order. */\nexport interface Parsed {\n program: Program;\n elements: JSXOpeningElement[];\n}\n\ninterface Tree {\n ast: { frontmatter: { program: Program }; body: unknown };\n diagnostics: { severity: string; text: string }[];\n}\ntype Parse = (code: string) => Tree;\n\nconst parsers = new Map<string, Parse | undefined>();\n\n/** The parser of the Astro installed for the project at `root`, loaded once; nothing without Astro 7. */\nfunction parserOf(root: string): Parse | undefined {\n if (!parsers.has(root)) parsers.set(root, load(root));\n return parsers.get(root);\n}\n\nfunction load(root: string): Parse | undefined {\n try {\n // Astro's own dependency, which a strict package manager doesn't put where the project could import it.\n const astro = createRequire(createRequire(join(root, 'package.json')).resolve('astro/package.json'));\n // An ES module, required: every Node that runs Astro 7 can, and reading a source stays synchronous.\n const compiler: { parse?: Parse } = astro('@astrojs/compiler-rs');\n return compiler.parse;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Astro gives a `<script>` or `<style>` with an attribute it doesn't know to the page as it is, unbundled and\n * unscoped, and a `<slot>` isn't an element at all: none of them can be pointed at, so none is marked.\n */\nconst OWN = new Set(['script', 'style', 'slot']);\n\nconst isOpening = (node: object): node is JSXOpeningElement => 'type' in node && node.type === 'JSXOpeningElement';\n\n/** An `.astro` file's text parsed, or the `problem` with it: no parser (an older Astro), or text that doesn't parse. */\nexport function parseAstro(root: string, code: string): Parsed | { problem: string } {\n const parse = parserOf(root);\n if (parse === undefined) return { problem: 'reading an .astro file takes Astro 7 or later, so update astro' };\n const { ast, diagnostics } = parse(code);\n const error = diagnostics.find((d) => d.severity === 'error');\n if (error !== undefined) return { problem: `fix it first (${error.text})` };\n const elements: JSXOpeningElement[] = [];\n const walk = (node: unknown): void => {\n if (Array.isArray(node)) return node.forEach(walk);\n if (node === null || typeof node !== 'object') return;\n if (isOpening(node) && !(node.name.type === 'JSXIdentifier' && OWN.has(node.name.name))) elements.push(node);\n Object.values(node).forEach(walk);\n };\n walk(ast.body);\n return { program: ast.frontmatter.program, elements };\n}\n\n/** An `.astro` file's text with every host element marked, as `locate` marks a JSX module; nothing where it can't be read. */\nexport function locateAstro(code: string, file: string, root: string): Located | undefined {\n // No tag, no parse.\n if (!/<[a-z]/.test(code)) return undefined;\n const parsed = parseAstro(root, code);\n return 'problem' in parsed ? undefined : marked(code, file, parsed.elements);\n}\n","/**\n * deictic's problems on the server, and those the page sends (`/__deictic/problem`): each said once in the dev server's\n * output, and handed to every plugin with a `problem` once they're all set up, which the tasks plugin posts to the\n * board. Once per key while the dev server runs: a request that fails on every try is still one problem.\n */\nimport type { Problem, ServerPlugin } from '#src/index.ts';\n\n/** How much of a problem is kept: its words, and its details (a stack is shorter). */\nconst WORDS = 2000;\nconst DETAILS = 20_000;\n\nexport type Report = (problem: Problem) => void;\n\n/** What reports a problem: `ready` is when the plugins that hear of them are set up to. */\nexport function reporter(plugins: readonly ServerPlugin[], ready: () => Promise<unknown>): Report {\n const said = new Set<string>();\n return (problem) => {\n if (said.has(problem.key)) return;\n said.add(problem.key);\n console.warn(`deictic${problem.plugin === undefined ? '' : `/${problem.plugin}`}: ${problem.message}`);\n const hearing = plugins.filter((p) => p.problem !== undefined);\n if (hearing.length === 0) return;\n // Its own failure is said, not reported: a board that can't be reached would report itself for ever.\n const tell = async (plugin: ServerPlugin) => {\n try {\n await plugin.problem?.(problem);\n } catch (e) {\n console.warn(`deictic: ${plugin.name} couldn't take that problem, as ${messageOf(e)}`);\n }\n };\n // Later, never now: a setup that fails at once reports before what it's part of is ready to be waited for.\n void Promise.resolve()\n .then(ready)\n .then(\n () => Promise.all(hearing.map(tell)),\n () => {},\n );\n };\n}\n\n/** What went wrong, as a problem's words say it: an error's message. */\nexport const messageOf = (e: unknown) => (e instanceof Error ? e.message : String(e));\n\n/** An error's stack, where it has one, for a problem's details. */\nexport const stackOf = (e: unknown) => (e instanceof Error && e.stack !== undefined ? { details: e.stack } : {});\n\n/** A problem as the page sent it, checked and cut short, or nothing where it isn't one. */\nexport function problemIn(value: unknown): Problem | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const { key, kind, message, details, plugin } = value as Record<string, unknown>;\n if (typeof key !== 'string' || key === '' || typeof message !== 'string' || message === '') return undefined;\n if (kind !== 'setup' && kind !== 'bug') return undefined;\n return {\n key: key.slice(0, WORDS),\n kind,\n message: message.slice(0, WORDS),\n ...(typeof details === 'string' && details !== '' ? { details: details.slice(0, DETAILS) } : {}),\n ...(typeof plugin === 'string' && plugin !== '' ? { plugin: plugin.slice(0, 100) } : {}),\n };\n}\n","/**\n * The plugins an integration was given: checked as it starts, so a wrong set fails the dev server with\n * what to write instead, and set up once before the endpoints answer anything.\n */\nimport type { ServerContext, ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nimport { messageOf, type Report, stackOf } from './problems.ts';\n\nconst NAME = /^[a-z][a-z0-9-]*$/;\n\n/** Throws what to fix in a set of plugins: names, what they need, and their shortcuts, beside deictic's own. */\nexport function checkPlugins(plugins: readonly ServerPlugin[], own?: Shortcut | false): void {\n const names = new Set<string>();\n for (const { name, client, shortcut } of plugins) {\n if (!NAME.test(name)) throw new Error(`deictic: a plugin is named \"${name}\": name it in lowercase letters, digits and -`);\n if (names.has(name)) throw new Error(`deictic: two plugins are named ${name}: load each once`);\n if (shortcut !== undefined && client === undefined)\n throw new Error(`deictic: ${name} has a shortcut but no \\`client\\` to draw its panel: give it one, or leave out its shortcut`);\n names.add(name);\n }\n for (const { name, needs = [] } of plugins) {\n const missing = needs.find((other) => !names.has(other));\n if (missing !== undefined) throw new Error(`deictic: ${name} needs the ${missing} plugin: add it to \\`plugins\\``);\n }\n checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n}\n\n/**\n * Runs every plugin's `setup`, all at once, and answers the context they share: `use` reads an API\n * when it's asked for, so setups may `use` each other's only after they've all run, from a route or an\n * op, never in `setup` itself. One that fails is reported and has no API: the others go on, so one of them\n * can tell of it (tasks, on the board).\n */\nexport async function setUp(root: string, plugins: readonly ServerPlugin[], report: Report): Promise<ServerContext> {\n const apis = new Map<string, unknown>();\n const context: ServerContext = { root, use: (name) => apis.get(name) as never, report };\n await Promise.all(\n plugins.map(async (p) => {\n if (p.setup === undefined) return;\n try {\n apis.set(p.name, await p.setup(context));\n } catch (e) {\n report({\n key: `setup:${p.name}`,\n kind: 'bug',\n plugin: p.name,\n message: `${p.name} failed to set up, so it does nothing until the dev server restarts: ${messageOf(e)}`,\n ...stackOf(e),\n });\n }\n }),\n );\n return context;\n}\n","/**\n * What every bundler's integration shares: the options, the client module that starts the overlay, and\n * the transform that marks a JSX module. Each integration adds what its bundler does its own way: how a\n * module is transformed (a hook, a loader, `onLoad`), how the page loads the client (a virtual module\n * under Vite, a file in `.deictic/` elsewhere, as webpack, Turbopack and Bun have none), where the\n * endpoints are served, and what opens the editor.\n */\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, isAbsolute, relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nimport { ASTRO, locateAstro } from './astro.ts';\nimport { keptIn } from './kept.ts';\nimport { JSX, locate, type Located } from './locate.ts';\nimport { checkPlugins } from './plugins.ts';\n\nexport interface DeicticOptions {\n /** The plugins to load, server halves: `tailwind()`, `tasks()`, your own. None by default. */\n plugins?: ServerPlugin[];\n /**\n * What opens the popup on any plugin, at the tab used last: Alt and the left button by default, or\n * `false` for none, leaving only plugins' own shortcuts.\n */\n shortcut?: Shortcut | false;\n}\n\n/** The options with their defaults, checked now, so a wrong set stops the dev server as it starts, not the page. */\nexport function prepare(options: DeicticOptions): { plugins: ServerPlugin[]; shortcut: Shortcut | false | undefined } {\n const plugins = options.plugins ?? [];\n checkPlugins(plugins, options.shortcut);\n return { plugins, shortcut: options.shortcut };\n}\n\n/**\n * The client module: the overlay, started with deictic's own shortcut and each plugin that has a half\n * in the page, with its shortcut, checked; and with `server`, a module of the page's that answers its requests\n * where no dev server does.\n */\nexport const clientModule = (plugins: ServerPlugin[], base: string, own?: Shortcut | false, server?: string) => {\n const [shortcut, ...shortcuts] = checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n const paged = plugins.flatMap((p, i) =>\n p.client === undefined ? [] : [{ client: p.client, rest: { shortcut: shortcuts[i], options: p.clientOptions } }],\n );\n return [\n `import { start } from 'deictic/client';`,\n ...paged.map((p, i) => `import p${i} from ${JSON.stringify(p.client)};`),\n ...(server === undefined ? [] : [`import server from ${JSON.stringify(server)};`]),\n // Its shortcut and options as JSON, where it has them: `JSON.stringify` leaves out what's undefined.\n `start({ base: ${JSON.stringify(base)}, shortcut: ${JSON.stringify(shortcut) ?? 'undefined'}, plugins: [${paged.map((p, i) => `{ plugin: p${i}, ...${JSON.stringify(p.rest)} }`).join(', ')}]${server === undefined ? '' : ', server'} });`,\n ].join('\\n');\n};\n\n/**\n * Writes the client module to `.deictic/client.js` for a bundler without virtual modules, and answers\n * its path. Its imports are bare (`deictic/client`, each plugin's), found from the project as its own\n * are. Written only when it changed, so a watching bundler doesn't rebuild for nothing.\n */\nexport function writeClient(root: string, plugins: ServerPlugin[], base: string, own?: Shortcut | false): string {\n const code = `// Written by deictic as the dev server starts: it starts the overlay in the page.\\n${clientModule(plugins, base, own)}\\n`;\n // Its own package: an ES module that runs for its effect. An app whose package.json says\n // `\"sideEffects\": false` would otherwise have webpack drop the import, which is only for its effect.\n const manifest = `${JSON.stringify({ private: true, type: 'module', sideEffects: true }, null, 2)}\\n`;\n writeIfChanged(keptIn(root, 'package.json'), manifest);\n return writeIfChanged(keptIn(root, 'client.js'), code);\n}\n\nfunction writeIfChanged(path: string, text: string): string {\n if (!existsSync(path) || readFileSync(path, 'utf8') !== text) writeFileSync(path, text);\n return path;\n}\n\n/** A module beside `url`, by its name: `.ts` from the source, `.js` from `dist`, as `url` is. */\nexport const beside = (url: string, name: string) =>\n fileURLToPath(new URL(`./${name}${url.endsWith('.ts') ? '.ts' : '.js'}`, url)).replaceAll('\\\\', '/');\n\n/**\n * The import of the written client module in the module at `from`, by a relative path with forward\n * slashes: Turbopack can't import a Windows path, and every bundler takes a relative one.\n */\nexport function importOf(path: string, from: string): string {\n const to = relative(dirname(from), path).replaceAll('\\\\', '/');\n return `\\nimport ${JSON.stringify(to.startsWith('.') ? to : `./${to}`)};\\n`;\n}\n\n/**\n * A module marked, by its absolute path: its host elements, and `append` after it (the client's import,\n * in the browser). Nothing for a file that isn't JSX, is a dependency's, or is outside the project.\n */\nexport function mark(code: string, path: string, root: string, append = ''): Located | undefined {\n const file = JSX.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locate(code, file, append);\n}\n\n/** An `.astro` component marked, by its absolute path, as `mark` does a module. It's no module of the browser's, so nothing is appended. */\nexport function markAstro(code: string, path: string, root: string): Located | undefined {\n const file = ASTRO.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locateAstro(code, file, root);\n}\n\n/** A project file's path from the root, as a mark has it; nothing for a dependency's or one outside the project. */\nfunction fileIn(path: string, root: string): string | undefined {\n if (/[\\\\/]node_modules[\\\\/]/.test(path) || !isAbsolute(path)) return undefined;\n const file = relative(root, path).replaceAll('\\\\', '/');\n return file.startsWith('..') || isAbsolute(file) ? undefined : file;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,YAAY;;AAEzB,MAAa,MAAM;;AAGnB,MAAa,SAAS,MAAc,SAAiB,UAAU,MAAM,MAAM,aAAa,KAAK,IAAI,IAAI,EAAE,MAAM,MAAM,IAAI,KAAA,CAAS;;AAQhI,MAAa,UAAU,OAA0B,GAAG,KAAK,SAAS,mBAAmB,SAAS,KAAK,GAAG,KAAK,IAAI;;;;;;AAO/G,SAAgB,OAAO,MAAc,MAAc,SAAS,IAAyB;CAEnF,IAAI,CAAC,SAAS,KAAK,IAAI,GAAG,OAAO,KAAA;CACjC,MAAM,EAAE,SAAS,WAAW,MAAM,MAAM,IAAI;CAC5C,IAAI,OAAO,SAAS,GAAG,OAAO,KAAA;CAC9B,OAAO,OAAO,MAAM,MAAM,WAAW,OAAO,GAAG,MAAM;AACvD;;AAGA,SAAgB,WAAW,SAAuC;CAChE,MAAM,WAAgC,CAAC;CACvC,IAAI,QAAQ,EAAE,oBAAoB,OAAO,KAAK,SAAS,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,OAAO;CAChF,OAAO;AACT;;;;;AAMA,SAAgB,OAAO,MAAc,MAAc,UAA+B,SAAS,IAAyB;CAClH,MAAM,QAAQ,WAAW,IAAI;CAC7B,MAAM,IAAI,IAAI,YAAY,IAAI;CAC9B,KAAK,MAAM,MAAM,UAAU;EACzB,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,WAAW,MAAM,M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AI,yBAAyB,KAAK,IAAI,KAAK,CAAC,WAAW,IAAI,GAAG,OAAO,KAAA;CACrE,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC,CAAC,WAAW,MAAM,GAAG;CACtD,OAAO,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,IAAI,KAAA,IAAY;AACjE"}
|
|
1
|
+
{"version":3,"file":"integration.js","names":["OWN","OWN"],"sources":["../../src/tools/locate.ts","../../src/tools/astro.ts","../../src/tools/problems.ts","../../src/tools/plugins.ts","../../src/tools/integration.ts"],"sourcesContent":["/**\n * Marks each host element in a JSX module with where its opening tag starts:\n * `<div data-deictic=\"src/App.tsx:12:5\">`. The page reads it back to know what was clicked.\n *\n * At build time and not from React's fibers at runtime: it works for any framework that compiles JSX,\n * for server components (which have no fiber in the browser), and it names the element's own tag\n * rather than the component that rendered it. Only host elements (`div`, `button`) are marked, since a\n * component may not pass the attribute on; a component's call site is reached from its elements.\n *\n * The transform must run on the source as written (`enforce: 'pre'` under Vite), so lines and columns\n * are the file's. It runs alike on the server and in the browser, so a hydrated page matches its HTML.\n */\nimport MagicString from 'magic-string';\nimport { type JSXOpeningElement, parseSync, type Program, Visitor } from 'oxc-parser';\n\nexport const ATTRIBUTE = 'data-deictic';\n/** Modules that may hold JSX: `.jsx` and `.tsx`, and plain `.js`, as many React projects write theirs. */\nexport const JSX = /\\.[cm]?(?:[jt]sx|js)$/;\n\n/** A module parsed, with JSX read in a `.js` file too, which the parser reads there only when told. */\nexport const parse = (file: string, code: string) => parseSync(file, code, /\\.[cm]?js$/.test(file) ? { lang: 'jsx' } : undefined);\n\nexport interface Located {\n code: string;\n map: ReturnType<MagicString['generateMap']>;\n}\n\n/** Whether an opening tag is a host element's, `<div>` or `<svg>`, not a component's or a namespaced one. */\nexport const isHost = (el: JSXOpeningElement) => el.name.type === 'JSXIdentifier' && /^[a-z]/.test(el.name.name);\n\n/**\n * `code` with every host element marked, `file` being its path from the project's root, and `append`\n * after it (the client's import, in the browser); nothing when there is nothing to mark, or the module\n * doesn't parse, which the framework's own transform reports better.\n */\nexport function locate(code: string, file: string, append = ''): Located | undefined {\n // No tag, no parse: most `.js` modules have none, and every one of the project's comes through here.\n if (!/<[a-z]/.test(code)) return undefined;\n const { program, errors } = parse(file, code);\n if (errors.length > 0) return undefined;\n return marked(code, file, openingsIn(program), append);\n}\n\n/** Every opening tag in a module, in its order. */\nexport function openingsIn(program: Program): JSXOpeningElement[] {\n const elements: JSXOpeningElement[] = [];\n new Visitor({ JSXOpeningElement: (el) => void elements.push(el) }).visit(program);\n return elements;\n}\n\n/**\n * `code` with a mark in each of `elements` that is a host element's and has none yet, and `append` after\n * it; nothing with none to mark.\n */\nexport function marked(code: string, file: string, elements: JSXOpeningElement[], append = ''): Located | undefined {\n const lines = lineStarts(code);\n const s = new MagicString(code);\n for (const el of elements) {\n if (!isHost(el) || el.attributes.some((a) => a.type === 'JSXAttribute' && nameOf(a.name) === ATTRIBUTE)) continue;\n const { line, column } = position(lines, el.start);\n s.appendLeft(el.name.end, ` ${ATTRIBUTE}=\"${file}:${line}:${column}\"`);\n }\n if (!s.hasChanged()) return undefined;\n if (append !== '') s.append(append);\n // A map's source is read from the module's own folder, so it's the file's name, not its path from the root.\n return { code: s.toString(), map: s.generateMap({ source: file.slice(file.lastIndexOf('/') + 1), hires: 'boundary' }) };\n}\n\nconst nameOf = (name: { type: string; name?: unknown }) => (name.type === 'JSXIdentifier' ? name.name : undefined);\n\n/** Where each line starts, by offset. */\nexport function lineStarts(code: string): number[] {\n const starts = [0];\n for (let i = code.indexOf('\\n'); i !== -1; i = code.indexOf('\\n', i + 1)) starts.push(i + 1);\n return starts;\n}\n\n/** An offset's line and column, from 1. */\nexport function position(lines: number[], offset: number): { line: number; column: number } {\n let lo = 0;\n let hi = lines.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (lines[mid]! <= offset) lo = mid;\n else hi = mid - 1;\n }\n return { line: lo + 1, column: offset - lines[lo]! + 1 };\n}\n\n/** A line and column's offset, or nothing past the file's end. */\nexport function offsetOf(lines: number[], line: number, column: number): number | undefined {\n const start = lines[line - 1];\n return start === undefined ? undefined : start + column - 1;\n}\n","/**\n * `.astro` components. They aren't JSX modules, but Astro 7's own parser reads a template as JSX, into the\n * tree oxc makes (offsets in UTF-16, as ours are), so its host elements are marked as a JSX module's are,\n * before Astro compiles the file. The parser is the project's own Astro's (`@astrojs/compiler-rs`, found\n * through `astro`), so it reads a file exactly as the compiler will; an Astro before 7 has none like it,\n * and its `.astro` files are left unmarked.\n */\nimport { createRequire } from 'node:module';\nimport { join } from 'node:path';\n\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport { type Located, marked } from './locate.ts';\n\nexport const ASTRO = /\\.astro$/;\n\n/** A file parsed: its module (an `.astro` file's frontmatter), and each opening tag in it, in the file's order. */\nexport interface Parsed {\n program: Program;\n elements: JSXOpeningElement[];\n}\n\ninterface Tree {\n ast: { frontmatter: { program: Program }; body: unknown };\n diagnostics: { severity: string; text: string }[];\n}\ntype Parse = (code: string) => Tree;\n\nconst parsers = new Map<string, Parse | undefined>();\n\n/** The parser of the Astro installed for the project at `root`, loaded once; nothing without Astro 7. */\nfunction parserOf(root: string): Parse | undefined {\n if (!parsers.has(root)) parsers.set(root, load(root));\n return parsers.get(root);\n}\n\nfunction load(root: string): Parse | undefined {\n try {\n // Astro's own dependency, which a strict package manager doesn't put where the project could import it.\n const astro = createRequire(createRequire(join(root, 'package.json')).resolve('astro/package.json'));\n // An ES module, required: every Node that runs Astro 7 can, and reading a source stays synchronous.\n const compiler: { parse?: Parse } = astro('@astrojs/compiler-rs');\n return compiler.parse;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Astro gives a `<script>` or `<style>` with an attribute it doesn't know to the page as it is, unbundled and\n * unscoped, and a `<slot>` isn't an element at all: none of them can be pointed at, so none is marked.\n */\nconst OWN = new Set(['script', 'style', 'slot']);\n\nconst isOpening = (node: object): node is JSXOpeningElement => 'type' in node && node.type === 'JSXOpeningElement';\n\n/** An `.astro` file's text parsed, or the `problem` with it: no parser (an older Astro), or text that doesn't parse. */\nexport function parseAstro(root: string, code: string): Parsed | { problem: string } {\n const parse = parserOf(root);\n if (parse === undefined) return { problem: 'reading an .astro file takes Astro 7 or later, so update astro' };\n const { ast, diagnostics } = parse(code);\n const error = diagnostics.find((d) => d.severity === 'error');\n if (error !== undefined) return { problem: `fix it first (${error.text})` };\n const elements: JSXOpeningElement[] = [];\n const walk = (node: unknown): void => {\n if (Array.isArray(node)) return node.forEach(walk);\n if (node === null || typeof node !== 'object') return;\n if (isOpening(node) && !(node.name.type === 'JSXIdentifier' && OWN.has(node.name.name))) elements.push(node);\n Object.values(node).forEach(walk);\n };\n walk(ast.body);\n return { program: ast.frontmatter.program, elements };\n}\n\n/** An `.astro` file's text with every host element marked, as `locate` marks a JSX module; nothing where it can't be read. */\nexport function locateAstro(code: string, file: string, root: string): Located | undefined {\n // No tag, no parse.\n if (!/<[a-z]/.test(code)) return undefined;\n const parsed = parseAstro(root, code);\n return 'problem' in parsed ? undefined : marked(code, file, parsed.elements);\n}\n","/**\n * deictic's problems on the server, and those the page sends (`/__deictic/problem`): each said once in the dev server's\n * output, and handed to every plugin with a `problem` once they're all set up, which the tasks plugin posts to the\n * board. Once per key while the dev server runs: a request that fails on every try is still one problem.\n */\nimport type { Problem, ServerPlugin } from '#src/index.ts';\n\n/** How much of a problem is kept: its words, and its details (a stack is shorter). */\nconst WORDS = 2000;\nconst DETAILS = 20_000;\n\nexport type Report = (problem: Problem) => void;\n\n/** What reports a problem: `ready` is when the plugins that hear of them are set up to. */\nexport function reporter(plugins: readonly ServerPlugin[], ready: () => Promise<unknown>): Report {\n const said = new Set<string>();\n return (problem) => {\n if (said.has(problem.key)) return;\n said.add(problem.key);\n console.warn(`deictic${problem.plugin === undefined ? '' : `/${problem.plugin}`}: ${problem.message}`);\n const hearing = plugins.filter((p) => p.problem !== undefined);\n if (hearing.length === 0) return;\n // Its own failure is said, not reported: a board that can't be reached would report itself for ever.\n const tell = async (plugin: ServerPlugin) => {\n try {\n await plugin.problem?.(problem);\n } catch (e) {\n console.warn(`deictic: ${plugin.name} couldn't take that problem, as ${messageOf(e)}`);\n }\n };\n // Later, never now: a setup that fails at once reports before what it's part of is ready to be waited for.\n void Promise.resolve()\n .then(ready)\n .then(\n () => Promise.all(hearing.map(tell)),\n () => {},\n );\n };\n}\n\n/** What went wrong, as a problem's words say it: an error's message. */\nexport const messageOf = (e: unknown) => (e instanceof Error ? e.message : String(e));\n\n/** An error's stack, where it has one, for a problem's details. */\nexport const stackOf = (e: unknown) => (e instanceof Error && e.stack !== undefined ? { details: e.stack } : {});\n\n/** A problem as the page sent it, checked and cut short, or nothing where it isn't one. */\nexport function problemIn(value: unknown): Problem | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const { key, kind, message, details, plugin } = value as Record<string, unknown>;\n if (typeof key !== 'string' || key === '' || typeof message !== 'string' || message === '') return undefined;\n if (kind !== 'setup' && kind !== 'bug') return undefined;\n return {\n key: key.slice(0, WORDS),\n kind,\n message: message.slice(0, WORDS),\n ...(typeof details === 'string' && details !== '' ? { details: details.slice(0, DETAILS) } : {}),\n ...(typeof plugin === 'string' && plugin !== '' ? { plugin: plugin.slice(0, 100) } : {}),\n };\n}\n","/**\n * The plugins an integration was given: checked as it starts, so a wrong set fails the dev server with\n * what to write instead, and set up once before the endpoints answer anything.\n */\nimport type { ServerContext, ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nimport { messageOf, type Report, stackOf } from './problems.ts';\n\nconst NAME = /^[a-z][a-z0-9-]*$/;\n\n/** Throws what to fix in a set of plugins: names, what they need, and their shortcuts, beside deictic's own. */\nexport function checkPlugins(plugins: readonly ServerPlugin[], own?: Shortcut | false): void {\n const names = new Set<string>();\n for (const { name, client, shortcut } of plugins) {\n if (!NAME.test(name)) throw new Error(`deictic: a plugin is named \"${name}\": name it in lowercase letters, digits and -`);\n if (names.has(name)) throw new Error(`deictic: two plugins are named ${name}: load each once`);\n if (shortcut !== undefined && client === undefined)\n throw new Error(`deictic: ${name} has a shortcut but no \\`client\\` to draw its panel: give it one, or leave out its shortcut`);\n names.add(name);\n }\n for (const { name, needs = [] } of plugins) {\n const missing = needs.find((other) => !names.has(other));\n if (missing !== undefined) throw new Error(`deictic: ${name} needs the ${missing} plugin: add it to \\`plugins\\``);\n }\n checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n}\n\n/**\n * Runs every plugin's `setup`, all at once, and answers the context they share: `use` reads an API\n * when it's asked for, so setups may `use` each other's only after they've all run, from a route or an\n * op, never in `setup` itself. One that fails is reported and has no API: the others go on, so one of them\n * can tell of it (tasks, on the board).\n */\nexport async function setUp(root: string, plugins: readonly ServerPlugin[], report: Report): Promise<ServerContext> {\n const apis = new Map<string, unknown>();\n const context: ServerContext = { root, use: (name) => apis.get(name) as never, report };\n await Promise.all(\n plugins.map(async (p) => {\n if (p.setup === undefined) return;\n try {\n apis.set(p.name, await p.setup(context));\n } catch (e) {\n report({\n key: `setup:${p.name}`,\n kind: 'bug',\n plugin: p.name,\n message: `${p.name} failed to set up, so it does nothing until the dev server restarts: ${messageOf(e)}`,\n ...stackOf(e),\n });\n }\n }),\n );\n return context;\n}\n","/**\n * What every bundler's integration shares: the options, the client module that starts the overlay, and\n * the transform that marks a JSX module. Each integration adds what its bundler does its own way: how a\n * module is transformed (a hook, a loader, `onLoad`), how the page loads the client (a virtual module\n * under Vite, a file in `.deictic/` elsewhere, as webpack, Turbopack and Bun have none), where the\n * endpoints are served, and what opens the editor.\n */\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, isAbsolute, relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nimport { ASTRO, locateAstro } from './astro.ts';\nimport { keptIn } from './kept.ts';\nimport { JSX, locate, type Located } from './locate.ts';\nimport { checkPlugins } from './plugins.ts';\n\nexport interface DeicticOptions {\n /** The plugins to load, server halves: `tailwind()`, `tasks()`, your own. None by default. */\n plugins?: ServerPlugin[];\n /**\n * What opens the popup on any plugin, at the tab used last: Alt and the left button by default, or\n * `false` for none, leaving only plugins' own shortcuts.\n */\n shortcut?: Shortcut | false;\n /**\n * For a package that adds its own plugin to the bundler with deictic (prosebook does): these options give way to\n * those of any other deictic in the same build, which merges them in, so the app's own `deictic()` decides the\n * shortcut and its plugin of the same name is the one loaded.\n */\n defaults?: boolean;\n}\n\n/**\n * Every deictic one build was given, as one: the app's and those packages added (`defaults`). The plugins of all of\n * them, each name once, the first given winning, those of an instance with `defaults` after the rest's; any other\n * option from the first that sets it, the same way. Two that aren't `defaults` setting one differently is an error,\n * as neither can be the one meant.\n */\nexport function merge<O extends DeicticOptions>(instances: readonly O[]): O {\n const ordered = [...instances.filter((o) => o.defaults !== true), ...instances.filter((o) => o.defaults === true)];\n const plugins = new Map<string, ServerPlugin>();\n const merged: Record<string, unknown> = {};\n const setBy: Record<string, O> = {};\n for (const options of ordered) {\n for (const plugin of options.plugins ?? []) if (!plugins.has(plugin.name)) plugins.set(plugin.name, plugin);\n for (const [key, value] of Object.entries(options)) {\n if (key === 'plugins' || key === 'defaults' || value === undefined) continue;\n const first = setBy[key];\n if (first === undefined) {\n merged[key] = value;\n setBy[key] = options;\n } else if (first.defaults !== true && options.defaults !== true && JSON.stringify(merged[key]) !== JSON.stringify(value)) {\n throw new Error(`deictic: the build has deictic twice, with ${key} set two ways: set it in one of them only`);\n }\n }\n }\n return { ...merged, plugins: [...plugins.values()] } as O;\n}\n\n/** The options with their defaults, checked now, so a wrong set stops the dev server as it starts, not the page. */\nexport function prepare(options: DeicticOptions): { plugins: ServerPlugin[]; shortcut: Shortcut | false | undefined } {\n const plugins = options.plugins ?? [];\n checkPlugins(plugins, options.shortcut);\n return { plugins, shortcut: options.shortcut };\n}\n\n/**\n * The client module: the overlay, started with deictic's own shortcut and each plugin that has a half\n * in the page, with its shortcut, checked; and with `server`, a module of the page's that answers its requests\n * where no dev server does.\n */\nexport const clientModule = (plugins: ServerPlugin[], base: string, own?: Shortcut | false, server?: string) => {\n const [shortcut, ...shortcuts] = checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n const paged = plugins.flatMap((p, i) =>\n p.client === undefined ? [] : [{ client: p.client, rest: { shortcut: shortcuts[i], options: p.clientOptions } }],\n );\n return [\n `import { start } from 'deictic/client';`,\n ...paged.map((p, i) => `import p${i} from ${JSON.stringify(p.client)};`),\n ...(server === undefined ? [] : [`import server from ${JSON.stringify(server)};`]),\n // Its shortcut and options as JSON, where it has them: `JSON.stringify` leaves out what's undefined.\n `start({ base: ${JSON.stringify(base)}, shortcut: ${JSON.stringify(shortcut) ?? 'undefined'}, plugins: [${paged.map((p, i) => `{ plugin: p${i}, ...${JSON.stringify(p.rest)} }`).join(', ')}]${server === undefined ? '' : ', server'} });`,\n ].join('\\n');\n};\n\n/**\n * Writes the client module to `.deictic/client.js` for a bundler without virtual modules, and answers\n * its path. Its imports are bare (`deictic/client`, each plugin's), found from the project as its own\n * are. Written only when it changed, so a watching bundler doesn't rebuild for nothing.\n */\nexport function writeClient(root: string, plugins: ServerPlugin[], base: string, own?: Shortcut | false): string {\n const code = `// Written by deictic as the dev server starts: it starts the overlay in the page.\\n${clientModule(plugins, base, own)}\\n`;\n // Its own package: an ES module that runs for its effect. An app whose package.json says\n // `\"sideEffects\": false` would otherwise have webpack drop the import, which is only for its effect.\n const manifest = `${JSON.stringify({ private: true, type: 'module', sideEffects: true }, null, 2)}\\n`;\n writeIfChanged(keptIn(root, 'package.json'), manifest);\n return writeIfChanged(keptIn(root, 'client.js'), code);\n}\n\nfunction writeIfChanged(path: string, text: string): string {\n if (!existsSync(path) || readFileSync(path, 'utf8') !== text) writeFileSync(path, text);\n return path;\n}\n\n/** A module beside `url`, by its name: `.ts` from the source, `.js` from `dist`, as `url` is. */\nexport const beside = (url: string, name: string) =>\n fileURLToPath(new URL(`./${name}${url.endsWith('.ts') ? '.ts' : '.js'}`, url)).replaceAll('\\\\', '/');\n\n/**\n * The import of the written client module in the module at `from`, by a relative path with forward\n * slashes: Turbopack can't import a Windows path, and every bundler takes a relative one.\n */\nexport function importOf(path: string, from: string): string {\n const to = relative(dirname(from), path).replaceAll('\\\\', '/');\n return `\\nimport ${JSON.stringify(to.startsWith('.') ? to : `./${to}`)};\\n`;\n}\n\n/**\n * A module marked, by its absolute path: its host elements, and `append` after it (the client's import,\n * in the browser). Nothing for a file that isn't JSX, is a dependency's, or is outside the project.\n */\nexport function mark(code: string, path: string, root: string, append = ''): Located | undefined {\n const file = JSX.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locate(code, file, append);\n}\n\n/** An `.astro` component marked, by its absolute path, as `mark` does a module. It's no module of the browser's, so nothing is appended. */\nexport function markAstro(code: string, path: string, root: string): Located | undefined {\n const file = ASTRO.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locateAstro(code, file, root);\n}\n\n/** A project file's path from the root, as a mark has it; nothing for a dependency's or one outside the project. */\nfunction fileIn(path: string, root: string): string | undefined {\n if (/[\\\\/]node_modules[\\\\/]/.test(path) || !isAbsolute(path)) return undefined;\n const file = relative(root, path).replaceAll('\\\\', '/');\n return file.startsWith('..') || isAbsolute(file) ? undefined : file;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,YAAY;;AAEzB,MAAa,MAAM;;AAGnB,MAAa,SAAS,MAAc,SAAiB,UAAU,MAAM,MAAM,aAAa,KAAK,IAAI,IAAI,EAAE,MAAM,MAAM,IAAI,KAAA,CAAS;;AAQhI,MAAa,UAAU,OAA0B,GAAG,KAAK,SAAS,mBAAmB,SAAS,KAAK,GAAG,KAAK,IAAI;;;;;;AAO/G,SAAgB,OAAO,MAAc,MAAc,SAAS,IAAyB;CAEnF,IAAI,CA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AmC;CACvF,MAAM,OAAO,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,IAAI,IAAI,KAAA;CACrD,OAAO,SAAS,KAAA,IAAY,KAAA,IAAY,YAAY,MAAM,MAAM,IAAI;AACtE;;AAGA,SAAS,OAAO,MAAc,MAAkC;CAC9D,IAAI,yBAAyB,KAAK,IAAI,KAAK,CAAC,WAAW,IAAI,GAAG,OAAO,KAAA;CACrE,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC,CAAC,WAAW,MAAM,GAAG;CACtD,OAAO,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,IAAI,KAAA,IAAY;AACjE"}
|
package/dist/shared/marks.js
CHANGED
|
@@ -14,6 +14,12 @@ const PAGE = "deictic.page";
|
|
|
14
14
|
* recording of a still page (a voice-over, say) would replay as a moment, and its voice never play.
|
|
15
15
|
*/
|
|
16
16
|
const END = "deictic.end";
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The custom event for React's commits, where the react plugin is loaded and they're asked for (the recording's React
|
|
19
|
+
* button): a `Commit` each (`deictic/react`'s), and `{ on }` where the recording starts and stops having them, so a
|
|
20
|
+
* stretch without them isn't read as one where nothing rendered.
|
|
21
|
+
*/
|
|
22
|
+
const REACT = "deictic.react";
|
|
23
|
+
export { REACT as i, MARKS as n, PAGE as r, END as t };
|
|
18
24
|
|
|
19
25
|
//# sourceMappingURL=marks.js.map
|
package/dist/shared/marks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marks.js","names":[],"sources":["../../src/plugins/recordings/marks.ts"],"sourcesContent":["/**\n * The custom event's tag the marks go in: the page's annotations, as an SVG in page coordinates (`svg`),\n * and as the annotations themselves (`annotations`, absent from recordings made before it was added).\n */\nexport const MARKS = 'deictic.annotations';\n\n/**\n * The custom event for the page's address changing with no load, as a router does it (`href`, the new one): rrweb\n * records what the route drew, not that the address changed. A page that loads has rrweb's own `Meta` instead.\n */\nexport const PAGE = 'deictic.page';\n\n/**\n * The custom event a recording ends with: rrweb's timeline lasts as long as its events, so without it a\n * recording of a still page (a voice-over, say) would replay as a moment, and its voice never play.\n */\nexport const END = 'deictic.end';\n"],"mappings":";;;;;AAIA,MAAa,QAAQ;;;;;AAMrB,MAAa,OAAO;;;;;AAMpB,MAAa,MAAM"}
|
|
1
|
+
{"version":3,"file":"marks.js","names":[],"sources":["../../src/plugins/recordings/marks.ts"],"sourcesContent":["/**\n * The custom event's tag the marks go in: the page's annotations, as an SVG in page coordinates (`svg`),\n * and as the annotations themselves (`annotations`, absent from recordings made before it was added).\n */\nexport const MARKS = 'deictic.annotations';\n\n/**\n * The custom event for the page's address changing with no load, as a router does it (`href`, the new one): rrweb\n * records what the route drew, not that the address changed. A page that loads has rrweb's own `Meta` instead.\n */\nexport const PAGE = 'deictic.page';\n\n/**\n * The custom event a recording ends with: rrweb's timeline lasts as long as its events, so without it a\n * recording of a still page (a voice-over, say) would replay as a moment, and its voice never play.\n */\nexport const END = 'deictic.end';\n\n/**\n * The custom event for React's commits, where the react plugin is loaded and they're asked for (the recording's React\n * button): a `Commit` each (`deictic/react`'s), and `{ on }` where the recording starts and stops having them, so a\n * stretch without them isn't read as one where nothing rendered.\n */\nexport const REACT = 'deictic.react';\n"],"mappings":";;;;;AAIA,MAAa,QAAQ;;;;;AAMrB,MAAa,OAAO;;;;;AAMpB,MAAa,MAAM;;;;;;AAOnB,MAAa,QAAQ"}
|
package/dist/shared/package.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var name = "deictic";
|
|
3
|
-
var version = "0.
|
|
3
|
+
var version = "0.10.0";
|
|
4
4
|
var bugs = { "url": "https://github.com/gkurt/deictic/issues" };
|
|
5
5
|
var peerDependencies = {
|
|
6
6
|
"@rrweb/rrweb-plugin-console-record": "^2.2.2",
|
|
@@ -8,10 +8,12 @@ var peerDependencies = {
|
|
|
8
8
|
"@rspack/core": ">=1",
|
|
9
9
|
"@vercel/board": ">=0.53.0",
|
|
10
10
|
"astro": ">=5",
|
|
11
|
+
"bippy": "^0.7.3",
|
|
11
12
|
"launch-editor": "^2.9.0",
|
|
12
13
|
"modern-screenshot": "^4.7.0",
|
|
13
14
|
"next": ">=16",
|
|
14
15
|
"playwright-core": "^1.50.0",
|
|
16
|
+
"react": ">=18",
|
|
15
17
|
"rrweb": "^2.2.2",
|
|
16
18
|
"rrweb-player": "^2.2.2",
|
|
17
19
|
"rrweb-snapshot": "^2.2.2",
|
package/dist/shared/packages.js
CHANGED
|
@@ -118,6 +118,6 @@ function missingProblem(root, plugins) {
|
|
|
118
118
|
message: `install what ${who} ${need}, then restart the dev server: ${installCommand(packageManager(root), names, root)}`
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
export {
|
|
121
|
+
export { packageManager as a, missingProblem as i, installCommand as n, readJson as o, installed as r, runnerOf as s, execOf as t };
|
|
122
122
|
|
|
123
123
|
//# sourceMappingURL=packages.js.map
|
|
@@ -80,7 +80,7 @@ async function render(input, options) {
|
|
|
80
80
|
...shot,
|
|
81
81
|
size: CANVAS_SIZE
|
|
82
82
|
};
|
|
83
|
-
const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size }) => {
|
|
83
|
+
const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size, states }) => {
|
|
84
84
|
const { rebuildIntoSandboxedIframe, createCache, createMirror } = globalThis.rrwebSnapshot;
|
|
85
85
|
const mirror = createMirror();
|
|
86
86
|
const { iframe } = rebuildIntoSandboxedIframe(snapshot, {
|
|
@@ -95,6 +95,44 @@ async function render(input, options) {
|
|
|
95
95
|
const hidden = doc.createElement("style");
|
|
96
96
|
hidden.textContent = "noscript { display: none !important; }";
|
|
97
97
|
doc.head.append(hidden);
|
|
98
|
+
if (states !== void 0) {
|
|
99
|
+
const pseudo = [
|
|
100
|
+
[":focus-visible", "deictic-focus-visible"],
|
|
101
|
+
[":focus-within", "deictic-focus-within"],
|
|
102
|
+
[":focus", "deictic-focus"],
|
|
103
|
+
[":hover", "deictic-hover"]
|
|
104
|
+
];
|
|
105
|
+
const copy = (into) => {
|
|
106
|
+
const list = into.cssRules;
|
|
107
|
+
for (let i = 0; i < list.length; i++) {
|
|
108
|
+
const rule = list[i];
|
|
109
|
+
if (rule.cssRules !== void 0 && rule.insertRule !== void 0) copy(rule);
|
|
110
|
+
const selector = rule.selectorText;
|
|
111
|
+
if (selector === void 0 || !rule.cssText.startsWith(selector)) continue;
|
|
112
|
+
let stated = selector;
|
|
113
|
+
for (const [name, className] of pseudo) stated = stated.split(name).join(`.${className}`);
|
|
114
|
+
if (stated === selector) continue;
|
|
115
|
+
try {
|
|
116
|
+
into.insertRule(stated + rule.cssText.slice(selector.length), i + 1);
|
|
117
|
+
i++;
|
|
118
|
+
} catch {}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const roots = [doc];
|
|
122
|
+
for (let i = 0; i < roots.length; i++) for (const el of roots[i].querySelectorAll("*")) if (el.shadowRoot !== null) roots.push(el.shadowRoot);
|
|
123
|
+
for (const root of roots) for (const sheet of [...root.styleSheets, ...root.adoptedStyleSheets]) try {
|
|
124
|
+
copy(sheet);
|
|
125
|
+
} catch {}
|
|
126
|
+
for (const [name, className] of Object.entries({
|
|
127
|
+
hover: "deictic-hover",
|
|
128
|
+
focus: "deictic-focus",
|
|
129
|
+
focusVisible: "deictic-focus-visible",
|
|
130
|
+
focusWithin: "deictic-focus-within"
|
|
131
|
+
})) for (const id of states[name] ?? []) {
|
|
132
|
+
const node = mirror.getNode(id);
|
|
133
|
+
if (isElement(node)) node.classList.add(className);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
98
136
|
for (const canvas of doc.querySelectorAll(`canvas[${size}]`)) {
|
|
99
137
|
const meta = mirror.getMeta(canvas);
|
|
100
138
|
const [box, inline] = (canvas.getAttribute(size) ?? "").split(" ");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright.js","names":[],"sources":["../../src/plugins/screenshots/playwright.ts"],"sourcesContent":["/**\n * The `rrweb()` renderer's server half: rebuilds a page's snapshot in a browser beside the dev server and\n * screenshots it at the page's viewport, scroll and pixel density, so text lays out as the page's does. The\n * browser is launched on the first shot and kept for the next; Playwright closes it with the process.\n *\n * The snapshot is rebuilt into a sandboxed iframe filling a blank page on the page's own origin, which\n * Playwright answers itself, so nothing asks the dev server for it: rrweb has made the snapshot's URLs\n * whole, and its stylesheets' fonts and images load from the dev server as the page's did.\n *\n * The browser is as big as the page's window, scrollbars and all, and shows its own: a media query asks the\n * window's width, and the page is laid out in what the scrollbar leaves. At the width without it, a window\n * right on a breakpoint (1024 wide, 1009 to lay out in) would render as the narrower layout. The shot is then\n * cut to the part the page is in.\n */\nimport { createRequire } from 'node:module';\n\nimport type { Browser } from 'playwright-core';\nimport type * as Rrweb from 'rrweb-snapshot';\n\nimport { CANVAS_SIZE } from './canvas.ts';\nimport type { Box, BrowserOptions } from './index.ts';\n\n/** What the page sends: its snapshot and what's needed to show it as the page does. */\n/** A node of an rrweb snapshot, as `snapshot()` answers it. */\nexport type SnapshotNode = NonNullable<ReturnType<typeof Rrweb.snapshot>>;\n\nexport interface Snapshot {\n snapshot: SnapshotNode;\n url: string;\n viewport: { width: number; height: number };\n /** The window's size, scrollbars included, where it has any: what the page's media queries ask. */\n window?: { width: number; height: number };\n scroll: { x: number; y: number };\n scale: number;\n /** The element the shot is of, as the snapshot numbers its nodes: found again in the rebuilt page, for where it is there. */\n element?: number;\n /** The part of the viewport to keep, for a shot of an element alone: where the element was in the page. */\n clip?: Box;\n /** An SVG the viewport's size, drawn over the page: the annotations, where there are any. */\n overlay?: string;\n}\n\nconst HOST = '<!doctype html><html><body style=\"margin:0\"></body></html>';\n\nconst browsers = new Map<string, Promise<Browser>>();\n\n/** A browser by the options, launched once: the one named, or Playwright's own Chromium, then Chrome, then Edge. */\nexport function browserOf(options: BrowserOptions): Promise<Browser> {\n const key = JSON.stringify(options);\n const known = browsers.get(key);\n if (known !== undefined) return known;\n const launched = launch(options);\n browsers.set(key, launched);\n // A launch that failed is tried again on the next shot, after the user installs what it said to.\n launched.catch(() => browsers.delete(key));\n return launched;\n}\n\n/** Playwright hides a headless browser's scrollbars, and with them the room they take in the page. */\nconst SCROLLBARS = { ignoreDefaultArgs: ['--hide-scrollbars'] };\n\nasync function launch({ executablePath, channel }: BrowserOptions): Promise<Browser> {\n const { chromium } = await import('playwright-core').catch((e: unknown) => {\n throw new Error('the rrweb() renderer needs playwright-core: add it to your devDependencies', { cause: e });\n });\n if (executablePath !== undefined || channel !== undefined) return chromium.launch({ executablePath, channel, ...SCROLLBARS });\n const tried: string[] = [];\n for (const attempt of [{}, { channel: 'chrome' }, { channel: 'msedge' }]) {\n try {\n return await chromium.launch({ ...attempt, ...SCROLLBARS });\n } catch (e) {\n tried.push(\n `${'channel' in attempt ? attempt.channel : \"Playwright's Chromium\"}: ${(e instanceof Error ? e.message : String(e)).split('\\n', 1)[0]}`,\n );\n }\n }\n throw new Error(\n `the rrweb() renderer found no browser to render in (${tried.join('; ')}): run \\`npx playwright install chromium\\`, or pass rrweb({ executablePath })`,\n );\n}\n\n/** The rrweb-snapshot bundle that defines `rrwebSnapshot` in a page: its CommonJS entry is that bundle. */\nconst bundle = () => createRequire(import.meta.url).resolve('rrweb-snapshot');\n\n/**\n * The PNG, and where the element is in it. That's measured in the rebuilt page, not taken from the live one: the\n * two can lay out a few pixels apart (a font that loaded differently, a panel's own scroll), and an outline drawn\n * at the live page's box would then cross the element.\n */\nexport async function render(input: unknown, options: BrowserOptions): Promise<{ png: Uint8Array; box?: Box }> {\n const shot = input as Snapshot;\n if (typeof shot?.url !== 'string' || typeof shot.snapshot !== 'object' || typeof shot.viewport?.width !== 'number')\n throw new Error('screenshots: that is not a snapshot the rrweb() renderer took');\n const browser = await browserOf(options);\n const context = await browser.newContext({ viewport: shot.window ?? shot.viewport, deviceScaleFactor: shot.scale });\n try {\n const page = await context.newPage();\n const host = new URL('/__deictic/plugins/screenshots/host', shot.url).href;\n await page.route(host, (route) => route.fulfill({ contentType: 'text/html', body: HOST }));\n await page.goto(host);\n await page.addScriptTag({ path: bundle() });\n // The shot, and the attribute that sizes each canvas's picture, which the page's code can't import.\n const given = { ...shot, size: CANVAS_SIZE };\n const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size }) => {\n const { rebuildIntoSandboxedIframe, createCache, createMirror } = (globalThis as unknown as { rrwebSnapshot: typeof Rrweb })\n .rrwebSnapshot;\n const mirror = createMirror();\n const { iframe } = rebuildIntoSandboxedIframe(snapshot, {\n root: document.body,\n cache: createCache(),\n mirror,\n iframeAttributes: { style: 'border:0;position:fixed;inset:0;width:100vw;height:100vh' },\n });\n const doc = iframe.contentDocument;\n if (doc === null) throw new Error('screenshots: the snapshot was rebuilt where it cannot be read');\n // By its kind: the iframe's elements aren't instances of this page's `Element`.\n const isElement = (node: Node | null): node is Element => node?.nodeType === 1;\n // rrweb rebuilds a script as a `noscript` holding SCRIPT_PLACEHOLDER, which the sandbox, running no scripts,\n // shows: hidden, as rrweb's own replayer hides it.\n const hidden = doc.createElement('style');\n hidden.textContent = 'noscript { display: none !important; }';\n doc.head.append(hidden);\n // The sandbox runs no scripts, and where scripts don't run, a canvas shows what's inside the canvas instead of\n // what was drawn on the canvas: so each canvas's picture goes inside the canvas, at the size the page laid the\n // canvas out at. rrweb's own drawing of the picture on the canvas never shows.\n for (const canvas of doc.querySelectorAll(`canvas[${size}]`)) {\n const meta = mirror.getMeta(canvas);\n const [box, inline] = (canvas.getAttribute(size) ?? '').split(' ');\n const [width, height] = (box ?? '').split('x');\n if (meta === null || !('attributes' in meta) || typeof meta.attributes.rr_dataURL !== 'string') continue;\n const picture = doc.createElement('img');\n picture.src = meta.attributes.rr_dataURL;\n // In a line as the canvas was, else the whole of the canvas's box.\n picture.style.cssText = `display:${inline === undefined ? 'block' : 'inline'};width:${width}px;height:${height}px`;\n canvas.replaceChildren(picture);\n }\n await doc.fonts.ready;\n await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));\n // At once: a page with `scroll-behavior: smooth` would glide there, and be shot on its way.\n iframe.contentWindow?.scrollTo({ left: scroll.x, top: scroll.y, behavior: 'instant' });\n // rrweb scrolled each element as it built it, before the fonts and images gave its content its height:\n // one that couldn't scroll that far yet is scrolled again now.\n for (const id of mirror.getIds()) {\n const node = mirror.getNode(id);\n const meta = node === null ? null : mirror.getMeta(node);\n if (!isElement(node) || meta === null || !('attributes' in meta)) continue;\n const { rr_scrollTop: top, rr_scrollLeft: left } = meta.attributes;\n if (typeof top !== 'number' && typeof left !== 'number') continue;\n node.scrollTo({\n top: typeof top === 'number' ? top : node.scrollTop,\n left: typeof left === 'number' ? left : node.scrollLeft,\n behavior: 'instant',\n });\n }\n const node = element === undefined ? null : mirror.getNode(element);\n // The iframe fills the page from its top left, so a box in it is one in the shot.\n const rect = isElement(node) ? node.getBoundingClientRect() : undefined;\n const box = rect === undefined ? undefined : { x: rect.x, y: rect.y, width: rect.width, height: rect.height };\n if (overlay === undefined) return box;\n // Over the page and its scroll: the SVG is the viewport's, already where it scrolled to.\n const marks = document.createElement('div');\n marks.style.cssText = 'position:fixed;inset:0;z-index:1;pointer-events:none';\n marks.innerHTML = overlay;\n document.body.append(marks);\n return box;\n }, given);\n // Without the scrollbars: a shot is what the page is drawn in, which is what an element's box is from.\n // A shot of the element alone is cut where the element is here.\n const clip = clamp(shot.clip === undefined ? { x: 0, y: 0, ...shot.viewport } : (found ?? shot.clip), shot.viewport);\n const png = new Uint8Array(await page.screenshot({ type: 'png', ...(clip === undefined ? {} : { clip }) }));\n return { png, ...(found === undefined || shot.clip !== undefined ? {} : { box: found }) };\n } finally {\n await context.close();\n }\n}\n\n/** A box kept within the viewport: an element partly scrolled out of it shows only the part that's in. */\nfunction clamp(box: Box, viewport: { width: number; height: number }): Box | undefined {\n const x = Math.max(0, box.x);\n const y = Math.max(0, box.y);\n const width = Math.min(viewport.width, box.x + box.width) - x;\n const height = Math.min(viewport.height, box.y + box.height) - y;\n return width > 0 && height > 0 ?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K;IAAG,OAAO,KAAK;IAAO,QAAQ,KAAK;GAAO;GAC5G,IAAI,YAAY,KAAA,GAAW,OAAO;GAElC,MAAM,QAAQ,SAAS,cAAc,KAAK;GAC1C,MAAM,MAAM,UAAU;GACtB,MAAM,YAAY;GAClB,SAAS,KAAK,OAAO,KAAK;GAC1B,OAAO;EACT,GAAG,KAAK;EAGR,MAAM,OAAO,MAAM,KAAK,SAAS,KAAA,IAAY;GAAE,GAAG;GAAG,GAAG;GAAG,GAAG,KAAK;EAAS,IAAK,SAAS,KAAK,MAAO,KAAK,QAAQ;EAEnH,OAAO;GAAE,KAAA,IADO,WAAW,MAAM,KAAK,WAAW;IAAE,MAAM;IAAO,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;GAAG,CAAC,CAC9F;GAAG,GAAI,UAAU,KAAA,KAAa,KAAK,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK,MAAM;EAAG;CAC1F,UAAU;EACR,MAAM,QAAQ,MAAM;CACtB;AACF;;AAGA,SAAS,MAAM,KAAU,UAA8D;CACrF,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,CAAC;CAC3B,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,CAAC;CAC3B,MAAM,QAAQ,KAAK,IAAI,SAAS,OAAO,IAAI,IAAI,IAAI,KAAK,IAAI;CAC5D,MAAM,SAAS,KAAK,IAAI,SAAS,QAAQ,IAAI,IAAI,IAAI,MAAM,IAAI;CAC/D,OAAO,QAAQ,KAAK,SAAS,IAAI;EAAE;EAAG;EAAG;EAAO;CAAO,IAAI,KAAA;AAC7D"}
|
|
1
|
+
{"version":3,"file":"playwright.js","names":[],"sources":["../../src/plugins/screenshots/playwright.ts"],"sourcesContent":["/**\n * The `rrweb()` renderer's server half: rebuilds a page's snapshot in a browser beside the dev server and\n * screenshots it at the page's viewport, scroll and pixel density, so text lays out as the page's does. The\n * browser is launched on the first shot and kept for the next; Playwright closes it with the process.\n *\n * The snapshot is rebuilt into a sandboxed iframe filling a blank page on the page's own origin, which\n * Playwright answers itself, so nothing asks the dev server for it: rrweb has made the snapshot's URLs\n * whole, and its stylesheets' fonts and images load from the dev server as the page's did.\n *\n * The browser is as big as the page's window, scrollbars and all, and shows its own: a media query asks the\n * window's width, and the page is laid out in what the scrollbar leaves. At the width without it, a window\n * right on a breakpoint (1024 wide, 1009 to lay out in) would render as the narrower layout. The shot is then\n * cut to the part the page is in.\n */\nimport { createRequire } from 'node:module';\n\nimport type { Browser } from 'playwright-core';\nimport type * as Rrweb from 'rrweb-snapshot';\n\nimport { CANVAS_SIZE } from './canvas.ts';\nimport type { Box, BrowserOptions } from './index.ts';\n\n/** What the page sends: its snapshot and what's needed to show it as the page does. */\n/** A node of an rrweb snapshot, as `snapshot()` answers it. */\nexport type SnapshotNode = NonNullable<ReturnType<typeof Rrweb.snapshot>>;\n\nexport interface Snapshot {\n snapshot: SnapshotNode;\n url: string;\n viewport: { width: number; height: number };\n /** The window's size, scrollbars included, where it has any: what the page's media queries ask. */\n window?: { width: number; height: number };\n scroll: { x: number; y: number };\n scale: number;\n /** The element the shot is of, as the snapshot numbers its nodes: found again in the rebuilt page, for where it is there. */\n element?: number;\n /** The part of the viewport to keep, for a shot of an element alone: where the element was in the page. */\n clip?: Box;\n /** An SVG the viewport's size, drawn over the page: the annotations, where there are any. */\n overlay?: string;\n /** The nodes in each interactive state as the shot was taken, which a copy of the DOM can't be in itself. */\n states?: States;\n}\n\n/** The snapshot's nodes that matched each pseudo-class: what was hovered, focused, and around the focus. */\nexport interface States {\n hover?: number[];\n focus?: number[];\n focusVisible?: number[];\n focusWithin?: number[];\n}\n\nconst HOST = '<!doctype html><html><body style=\"margin:0\"></body></html>';\n\nconst browsers = new Map<string, Promise<Browser>>();\n\n/** A browser by the options, launched once: the one named, or Playwright's own Chromium, then Chrome, then Edge. */\nexport function browserOf(options: BrowserOptions): Promise<Browser> {\n const key = JSON.stringify(options);\n const known = browsers.get(key);\n if (known !== undefined) return known;\n const launched = launch(options);\n browsers.set(key, launched);\n // A launch that failed is tried again on the next shot, after the user installs what it said to.\n launched.catch(() => browsers.delete(key));\n return launched;\n}\n\n/** Playwright hides a headless browser's scrollbars, and with them the room they take in the page. */\nconst SCROLLBARS = { ignoreDefaultArgs: ['--hide-scrollbars'] };\n\nasync function launch({ executablePath, channel }: BrowserOptions): Promise<Browser> {\n const { chromium } = await import('playwright-core').catch((e: unknown) => {\n throw new Error('the rrweb() renderer needs playwright-core: add it to your devDependencies', { cause: e });\n });\n if (executablePath !== undefined || channel !== undefined) return chromium.launch({ executablePath, channel, ...SCROLLBARS });\n const tried: string[] = [];\n for (const attempt of [{}, { channel: 'chrome' }, { channel: 'msedge' }]) {\n try {\n return await chromium.launch({ ...attempt, ...SCROLLBARS });\n } catch (e) {\n tried.push(\n `${'channel' in attempt ? attempt.channel : \"Playwright's Chromium\"}: ${(e instanceof Error ? e.message : String(e)).split('\\n', 1)[0]}`,\n );\n }\n }\n throw new Error(\n `the rrweb() renderer found no browser to render in (${tried.join('; ')}): run \\`npx playwright install chromium\\`, or pass rrweb({ executablePath })`,\n );\n}\n\n/** The rrweb-snapshot bundle that defines `rrwebSnapshot` in a page: its CommonJS entry is that bundle. */\nconst bundle = () => createRequire(import.meta.url).resolve('rrweb-snapshot');\n\n/**\n * The PNG, and where the element is in it. That's measured in the rebuilt page, not taken from the live one: the\n * two can lay out a few pixels apart (a font that loaded differently, a panel's own scroll), and an outline drawn\n * at the live page's box would then cross the element.\n */\nexport async function render(input: unknown, options: BrowserOptions): Promise<{ png: Uint8Array; box?: Box }> {\n const shot = input as Snapshot;\n if (typeof shot?.url !== 'string' || typeof shot.snapshot !== 'object' || typeof shot.viewport?.width !== 'number')\n throw new Error('screenshots: that is not a snapshot the rrweb() renderer took');\n const browser = await browserOf(options);\n const context = await browser.newContext({ viewport: shot.window ?? shot.viewport, deviceScaleFactor: shot.scale });\n try {\n const page = await context.newPage();\n const host = new URL('/__deictic/plugins/screenshots/host', shot.url).href;\n await page.route(host, (route) => route.fulfill({ contentType: 'text/html', body: HOST }));\n await page.goto(host);\n await page.addScriptTag({ path: bundle() });\n // The shot, and the attribute that sizes each canvas's picture, which the page's code can't import.\n const given = { ...shot, size: CANVAS_SIZE };\n const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size, states }) => {\n const { rebuildIntoSandboxedIframe, createCache, createMirror } = (globalThis as unknown as { rrwebSnapshot: typeof Rrweb })\n .rrwebSnapshot;\n const mirror = createMirror();\n const { iframe } = rebuildIntoSandboxedIframe(snapshot, {\n root: document.body,\n cache: createCache(),\n mirror,\n iframeAttributes: { style: 'border:0;position:fixed;inset:0;width:100vw;height:100vh' },\n });\n const doc = iframe.contentDocument;\n if (doc === null) throw new Error('screenshots: the snapshot was rebuilt where it cannot be read');\n // By its kind: the iframe's elements aren't instances of this page's `Element`.\n const isElement = (node: Node | null): node is Element => node?.nodeType === 1;\n // rrweb rebuilds a script as a `noscript` holding SCRIPT_PLACEHOLDER, which the sandbox, running no scripts,\n // shows: hidden, as rrweb's own replayer hides it.\n const hidden = doc.createElement('style');\n hidden.textContent = 'noscript { display: none !important; }';\n doc.head.append(hidden);\n // What was hovered and focused: a copy of the DOM is in no state, so each rule of those pseudo-classes is\n // copied under a class of its own, and the nodes that were in it get the class. Nested rules and grouping ones\n // (a Tailwind `hover:` class is `&:hover { @media (hover: hover) { … } }`) are copied whole.\n if (states !== undefined) {\n const pseudo: [string, string][] = [\n [':focus-visible', 'deictic-focus-visible'],\n [':focus-within', 'deictic-focus-within'],\n [':focus', 'deictic-focus'],\n [':hover', 'deictic-hover'],\n ];\n type Rules = { cssRules: CSSRuleList; insertRule: (rule: string, index: number) => number };\n const copy = (into: Rules) => {\n const list = into.cssRules;\n for (let i = 0; i < list.length; i++) {\n const rule = list[i] as CSSRule & Partial<Rules> & { selectorText?: string };\n if (rule.cssRules !== undefined && rule.insertRule !== undefined) copy(rule as Rules);\n const selector = rule.selectorText;\n if (selector === undefined || !rule.cssText.startsWith(selector)) continue;\n let stated = selector;\n for (const [name, className] of pseudo) stated = stated.split(name).join(`.${className}`);\n if (stated === selector) continue;\n try {\n into.insertRule(stated + rule.cssText.slice(selector.length), i + 1);\n i++;\n } catch {\n // A selector this browser won't take back: that state goes unshown.\n }\n }\n };\n const roots: (Document | ShadowRoot)[] = [doc];\n for (let i = 0; i < roots.length; i++)\n for (const el of roots[i]!.querySelectorAll('*')) if (el.shadowRoot !== null) roots.push(el.shadowRoot);\n for (const root of roots) {\n for (const sheet of [...root.styleSheets, ...root.adoptedStyleSheets]) {\n try {\n copy(sheet);\n } catch {\n // Another origin's, which can't be read: rrweb inlines what it can.\n }\n }\n }\n const classes = {\n hover: 'deictic-hover',\n focus: 'deictic-focus',\n focusVisible: 'deictic-focus-visible',\n focusWithin: 'deictic-focus-within',\n };\n for (const [name, className] of Object.entries(classes)) {\n for (const id of states[name as keyof typeof classes] ?? []) {\n const node = mirror.getNode(id);\n if (isElement(node)) node.classList.add(className);\n }\n }\n }\n // The sandbox runs no scripts, and where scripts don't run, a canvas shows what's inside the canvas instead of\n // what was drawn on the canvas: so each canvas's picture goes inside the canvas, at the size the page laid the\n // canvas out at. rrweb's own drawing of the picture on the canvas never shows.\n for (const canvas of doc.querySelectorAll(`canvas[${size}]`)) {\n const meta = mirror.getMeta(canvas);\n const [box, inline] = (canvas.getAttribute(size) ?? '').split(' ');\n const [width, height] = (box ?? '').split('x');\n if (meta === null || !('attributes' in meta) || typeof meta.attributes.rr_dataURL !== 'string') continue;\n const picture = doc.createElement('img');\n picture.src = meta.attributes.rr_dataURL;\n // In a line as the canvas was, else the whole of the canvas's box.\n picture.style.cssText = `display:${inline === undefined ? 'block' : 'inline'};width:${width}px;height:${height}px`;\n canvas.replaceChildren(picture);\n }\n await doc.fonts.ready;\n await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));\n // At once: a page with `scroll-behavior: smooth` would glide there, and be shot on its way.\n iframe.contentWindow?.scrollTo({ left: scroll.x, top: scroll.y, behavior: 'instant' });\n // rrweb scrolled each element as it built it, before the fonts and images gave its content its height:\n // one that couldn't scroll that far yet is scrolled again now.\n for (const id of mirror.getIds()) {\n const node = mirror.getNode(id);\n const meta = node === null ? null : mirror.getMeta(node);\n if (!isElement(node) || meta === null || !('attributes' in meta)) continue;\n const { rr_scrollTop: top, rr_scrollLeft: left } = meta.attributes;\n if (typeof top !== 'number' && typeof left !== 'number') continue;\n node.scrollTo({\n top: typeof top === 'number' ? top : node.scrollTop,\n left: typeof left === 'number' ? left : node.scrollLeft,\n behavior: 'instant',\n });\n }\n const node = element === undefined ? null : mirror.getNode(element);\n // The iframe fills the page from its top left, so a box in it is one in the shot.\n const rect = isElement(node) ? node.getBoundingClientRect() : undefined;\n const box = rect === undefined ? undefined : { x: rect.x, y: rect.y, width: rect.width, height: rect.height };\n if (overlay === undefined) return box;\n // Over the page and its scroll: the SVG is the viewport's, already where it scrolled to.\n const marks = document.createElement('div');\n marks.style.cssText = 'position:fixed;inset:0;z-index:1;pointer-events:none';\n marks.innerHTML = overlay;\n document.body.append(marks);\n return box;\n }, given);\n // Without the scrollbars: a shot is what the page is drawn in, which is what an element's box is from.\n // A shot of the element alone is cut where the element is here.\n const clip = clamp(shot.clip === undefined ? { x: 0, y: 0, ...shot.viewport } : (found ?? shot.clip), shot.viewport);\n const png = new Uint8Array(await page.screenshot({ type: 'png', ...(clip === undefined ? {} : { clip }) }));\n return { png, ...(found === undefined || shot.clip !== undefined ? {} : { box: found }) };\n } finally {\n await context.close();\n }\n}\n\n/** A box kept within the viewport: an element partly scrolled out of it shows only the part that's in. */\nfunction clamp(box: Box, viewport: { width: number; height: number }): Box | undefined {\n const x = Math.max(0, box.x);\n const y = Math.max(0, box.y);\n const width = Math.min(viewport.width, box.x + box.width) - x;\n const height = Math.min(viewport.height, box.y + box.height) - y;\n return width > 0 && height > 0 ? { x, y, width, height } : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoDA,MAAM,OAAO;AAEb,MAAM,2BAAW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