deictic 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +26 -3
  2. package/dist/annotations/index.d.ts +1 -1
  3. package/dist/astro.d.ts +1 -1
  4. package/dist/bun.d.ts +1 -1
  5. package/dist/bun.js +2 -2
  6. package/dist/client/index.d.ts +4 -2
  7. package/dist/client/index.d.ts.map +1 -1
  8. package/dist/client/index.js +13 -9
  9. package/dist/client/index.js.map +1 -1
  10. package/dist/index.d.ts +21 -218
  11. package/dist/index.js.map +1 -1
  12. package/dist/loader.js +1 -1
  13. package/dist/next.d.ts +1 -1
  14. package/dist/next.js +2 -2
  15. package/dist/recommended/index.d.ts +4 -4
  16. package/dist/recommended/index.js +2 -2
  17. package/dist/recordings/client.d.ts +1 -1
  18. package/dist/recordings/client.js +4 -4
  19. package/dist/recordings/client.js.map +1 -1
  20. package/dist/recordings/index.d.ts +2 -2
  21. package/dist/recordings/index.js +3 -3
  22. package/dist/screenshots/client.d.ts +1 -1
  23. package/dist/screenshots/client.js +2 -2
  24. package/dist/screenshots/client.js.map +1 -1
  25. package/dist/screenshots/dom.d.ts +1 -1
  26. package/dist/screenshots/index.d.ts +1 -1
  27. package/dist/screenshots/index.js +2 -2
  28. package/dist/screenshots/index.js.map +1 -1
  29. package/dist/screenshots/rrweb.d.ts +1 -1
  30. package/dist/{endpoints.js → shared/endpoints.js} +1 -1
  31. package/dist/shared/endpoints.js.map +1 -0
  32. package/dist/shared/index.d.ts +226 -0
  33. package/dist/shared/index.d.ts.map +1 -0
  34. package/dist/{index3.d.ts → shared/index2.d.ts} +1 -1
  35. package/dist/shared/index2.d.ts.map +1 -0
  36. package/dist/{index4.d.ts → shared/index3.d.ts} +15 -3
  37. package/dist/shared/index3.d.ts.map +1 -0
  38. package/dist/shared/index4.d.ts +184 -0
  39. package/dist/shared/index4.d.ts.map +1 -0
  40. package/dist/{index5.d.ts → shared/index5.d.ts} +1 -1
  41. package/dist/shared/index5.d.ts.map +1 -0
  42. package/dist/{integration.d.ts → shared/integration.d.ts} +4 -3
  43. package/dist/shared/integration.d.ts.map +1 -0
  44. package/dist/{integration.js → shared/integration.js} +5 -3
  45. package/dist/shared/integration.js.map +1 -0
  46. package/dist/{kept.js → shared/kept.js} +2 -2
  47. package/dist/shared/kept.js.map +1 -0
  48. package/dist/shared/marks.js.map +1 -0
  49. package/dist/shared/playwright.js.map +1 -0
  50. package/dist/{recordings.js → shared/recordings.js} +20 -9
  51. package/dist/shared/recordings.js.map +1 -0
  52. package/dist/shared/shortcut.js.map +1 -0
  53. package/dist/shared/tasks.js +521 -0
  54. package/dist/shared/tasks.js.map +1 -0
  55. package/dist/shared/waveform.js.map +1 -0
  56. package/dist/tailwind/client.d.ts +1 -1
  57. package/dist/tailwind/index.d.ts +1 -1
  58. package/dist/tasks/client.d.ts +1 -1
  59. package/dist/tasks/client.js +1 -1
  60. package/dist/tasks/index.d.ts +2 -159
  61. package/dist/tasks/index.js +1 -348
  62. package/dist/vite.d.ts +11 -12
  63. package/dist/vite.d.ts.map +1 -1
  64. package/dist/vite.js +21 -4
  65. package/dist/vite.js.map +1 -1
  66. package/dist/voice/client.js +2 -2
  67. package/dist/voice/client.js.map +1 -1
  68. package/dist/voice/index.js +1 -1
  69. package/dist/webpack.d.ts +1 -1
  70. package/dist/webpack.js +2 -2
  71. package/package.json +1 -1
  72. package/skills/deictic/SKILL.md +1 -1
  73. package/skills/deictic/references/install.md +20 -5
  74. package/skills/deictic/scripts/lib.mjs +21 -3
  75. package/skills/deictic/scripts/watch.mjs +2 -2
  76. package/src/client/index.ts +20 -7
  77. package/src/index.ts +7 -0
  78. package/src/plugins/recordings/client.ts +3 -2
  79. package/src/plugins/recordings/index.ts +3 -2
  80. package/src/plugins/recordings/replay.ts +32 -6
  81. package/src/plugins/screenshots/client.ts +3 -2
  82. package/src/plugins/tasks/index.ts +52 -8
  83. package/src/plugins/tasks/local.ts +170 -0
  84. package/src/plugins/voice/client.ts +3 -2
  85. package/src/tools/integration.ts +5 -3
  86. package/src/tools/kept.ts +2 -2
  87. package/src/vite.ts +23 -4
  88. package/dist/endpoints.js.map +0 -1
  89. package/dist/index.d.ts.map +0 -1
  90. package/dist/index2.d.ts +0 -23
  91. package/dist/index3.d.ts.map +0 -1
  92. package/dist/index4.d.ts.map +0 -1
  93. package/dist/index5.d.ts.map +0 -1
  94. package/dist/integration.d.ts.map +0 -1
  95. package/dist/integration.js.map +0 -1
  96. package/dist/kept.js.map +0 -1
  97. package/dist/marks.js.map +0 -1
  98. package/dist/playwright.js.map +0 -1
  99. package/dist/recordings.js.map +0 -1
  100. package/dist/shortcut.js.map +0 -1
  101. package/dist/tasks/index.d.ts.map +0 -1
  102. package/dist/tasks/index.js.map +0 -1
  103. package/dist/waveform.js.map +0 -1
  104. /package/dist/{marks.js → shared/marks.js} +0 -0
  105. /package/dist/{playwright.js → shared/playwright.js} +0 -0
  106. /package/dist/{shortcut.js → shared/shortcut.js} +0 -0
  107. /package/dist/{waveform.js → shared/waveform.js} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index5.d.ts","names":[],"sources":["../../src/plugins/tailwind/catalog.ts","../../src/plugins/tailwind/index.ts"],"mappings":";;UAeiB;EACf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;EACA,OAAO;;EAEP;IAAW;IAAgB;IAAe;;;UCf3B;;EAEf;;EAEA;;;;;EAKA;;EAEA,WAAW;;KAGD;EAEN;EACA;;EAEA,SAAS;;EAET;EAAiB;;;UAGN;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;UAGe;EACf;;EAEA;;iBASc,SAAS,UAAS,oCAAoB,aAAA,OAAA"}
@@ -1,4 +1,4 @@
1
- import { C as Shortcut, g as ServerPlugin } from "./index.js";
1
+ import { g as ServerPlugin, w as Shortcut } from "./index.js";
2
2
  import "magic-string";
3
3
  import "oxc-parser";
4
4
  interface DeicticOptions {
@@ -12,8 +12,9 @@ interface DeicticOptions {
12
12
  }
13
13
  /**
14
14
  * The client module: the overlay, started with deictic's own shortcut and each plugin that has a half
15
- * in the page, with its shortcut, checked.
15
+ * in the page, with its shortcut, checked; and with `server`, a module of the page's that answers its requests
16
+ * where no dev server does.
16
17
  */
17
- declare const clientModule: (plugins: ServerPlugin[], base: string, own?: Shortcut | false) => string;
18
+ declare const clientModule: (plugins: ServerPlugin[], base: string, own?: Shortcut | false, server?: string) => string;
18
19
  export { clientModule as n, DeicticOptions as t };
19
20
  //# sourceMappingURL=integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.d.ts","names":[],"sources":["../../src/tools/integration.ts"],"mappings":";;;UAmBiB;;EAEf,UAAU;;;;;EAKV,WAAW;;;;;;;cAeA,eAAY,SAAa,gBAAc,cAAc,MAAQ,kBAAgB"}
@@ -204,9 +204,10 @@ function prepare(options) {
204
204
  }
205
205
  /**
206
206
  * The client module: the overlay, started with deictic's own shortcut and each plugin that has a half
207
- * in the page, with its shortcut, checked.
207
+ * in the page, with its shortcut, checked; and with `server`, a module of the page's that answers its requests
208
+ * where no dev server does.
208
209
  */
209
- const clientModule = (plugins, base, own) => {
210
+ const clientModule = (plugins, base, own, server) => {
210
211
  const [shortcut, ...shortcuts] = checkShortcuts([{
211
212
  name: OWN$1,
212
213
  shortcut: ownShortcut(own)
@@ -221,7 +222,8 @@ const clientModule = (plugins, base, own) => {
221
222
  return [
222
223
  `import { start } from 'deictic/client';`,
223
224
  ...paged.map((p, i) => `import p${i} from ${JSON.stringify(p.client)};`),
224
- `start({ base: ${JSON.stringify(base)}, shortcut: ${JSON.stringify(shortcut) ?? "undefined"}, plugins: [${paged.map((p, i) => `{ plugin: p${i}, ...${JSON.stringify(p.rest)} }`).join(", ")}] });`
225
+ ...server === void 0 ? [] : [`import server from ${JSON.stringify(server)};`],
226
+ `start({ base: ${JSON.stringify(base)}, shortcut: ${JSON.stringify(shortcut) ?? "undefined"}, plugins: [${paged.map((p, i) => `{ plugin: p${i}, ...${JSON.stringify(p.rest)} }`).join(", ")}]${server === void 0 ? "" : ", server"} });`
225
227
  ].join("\n");
226
228
  };
227
229
  /**
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.js","names":["OWN","OWN"],"sources":["../../src/tools/locate.ts","../../src/tools/astro.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 * 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\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.\n */\nexport async function setUp(root: string, plugins: readonly ServerPlugin[]): Promise<ServerContext> {\n const apis = new Map<string, unknown>();\n const context: ServerContext = { root, use: (name) => apis.get(name) as never };\n await Promise.all(\n plugins.map(async (p) => {\n if (p.setup !== undefined) apis.set(p.name, await p.setup(context));\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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ACvF,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"}
@@ -3,8 +3,8 @@ import { join } from "node:path";
3
3
  // src/tools/kept.ts
4
4
  /**
5
5
  * Where deictic keeps what it makes for a project: `.deictic/` at its root, beside `.board/` and the like,
6
- * rather than in `node_modules`, which an install may clear. The history is there, and the shots,
7
- * recordings and voice clips plugins keep. It ignores itself in git: the history holds whole files, and
6
+ * rather than in `node_modules`, which an install may clear. The history is there, the shots,
7
+ * recordings and voice clips plugins keep, and the tasks plugin's own board. It ignores itself in git: the history holds whole files, and
8
8
  * the rest is the page as it looked, neither of which belongs in a commit.
9
9
  */
10
10
  const IGNORE = "# deictic's own: the history, and the shots, recordings and voice clips it keeps.\n*\n";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kept.js","names":[],"sources":["../../src/tools/kept.ts"],"sourcesContent":["/**\n * Where deictic keeps what it makes for a project: `.deictic/` at its root, beside `.board/` and the like,\n * rather than in `node_modules`, which an install may clear. The history is there, the shots,\n * recordings and voice clips plugins keep, and the tasks plugin's own board. It ignores itself in git: the history holds whole files, and\n * the rest is the page as it looked, neither of which belongs in a commit.\n */\nimport { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nconst IGNORE = \"# deictic's own: the history, and the shots, recordings and voice clips it keeps.\\n*\\n\";\n\n/** A path under the project's `.deictic/`, made with its `.gitignore` the first time. */\nexport function keptIn(root: string, ...parts: string[]): string {\n const dir = join(root, '.deictic');\n const ignore = join(dir, '.gitignore');\n if (!existsSync(ignore)) {\n mkdirSync(dir, { recursive: true });\n writeFileSync(ignore, IGNORE);\n }\n return join(dir, ...parts);\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,SAAS;;AAGf,SAAgB,OAAO,MAAc,GAAG,OAAyB;CAC/D,MAAM,MAAM,KAAK,MAAM,UAAU;CACjC,MAAM,SAAS,KAAK,KAAK,YAAY;CACrC,IAAI,CAAC,WAAW,MAAM,GAAG;EACvB,UAAU,KAAK,EAAE,WAAW,KAAK,CAAC;EAClC,cAAc,QAAQ,MAAM;CAC9B;CACA,OAAO,KAAK,KAAK,GAAG,KAAK;AAC3B"}
@@ -0,0 +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 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,MAAM"}
@@ -0,0 +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 */\nimport { createRequire } from 'node:module';\n\nimport type { Browser } from 'playwright-core';\nimport type * as Rrweb from 'rrweb-snapshot';\n\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 scroll: { x: number; y: number };\n scale: number;\n /** The part of the viewport to keep, for a shot of an element alone. */\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\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 });\n const tried: string[] = [];\n for (const attempt of [{}, { channel: 'chrome' }, { channel: 'msedge' }]) {\n try {\n return await chromium.launch(attempt);\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\nexport async function render(input: unknown, options: BrowserOptions): Promise<Uint8Array> {\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.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 await page.evaluate(async ({ snapshot, scroll, overlay }) => {\n const { rebuildIntoSandboxedIframe, createCache, createMirror } = (globalThis as unknown as { rrwebSnapshot: typeof Rrweb })\n .rrwebSnapshot;\n const { iframe } = rebuildIntoSandboxedIframe(snapshot, {\n root: document.body,\n cache: createCache(),\n mirror: createMirror(),\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 await doc.fonts.ready;\n await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));\n iframe.contentWindow?.scrollTo(scroll.x, scroll.y);\n if (overlay === undefined) return;\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 }, shot);\n const clip = shot.clip === undefined ? undefined : clamp(shot.clip, shot.viewport);\n return new Uint8Array(await page.screenshot({ type: 'png', ...(clip === undefined ? {} : { clip }) }));\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":";;;;;;;;;;;AAgCA,MAAM,OAAO;AAEb,MAAM,2BAAW,IAAI,IAA8B;;AAGnD,SAAgB,UAAU,SAA2C;CACnE,MAAM,MAAM,KAAK,UAAU,OAAO;CAClC,MAAM,QAAQ,SAAS,IAAI,GAAG;CAC9B,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,WAAW,OAAO,OAAO;CAC/B,SAAS,IAAI,KAAK,QAAQ;CAE1B,SAAS,YAAY,SAAS,OAAO,GAAG,CAAC;CACzC,OAAO;AACT;AAEA,eAAe,OAAO,EAAE,gBAAgB,WAA6C;CACnF,MAAM,EAAE,aAAa,MAAM,OAAO,kBAAkB,CAAC,OAAO,MAAe;EACzE,MAAM,IAAI,MAAM,8EAA8E,EAAE,OAAO,EAAE,CAAC;CAC5G,CAAC;CACD,IAAI,mBAAmB,KAAA,KAAa,YAAY,KAAA,GAAW,OAAO,SAAS,OAAO;EAAE;EAAgB;CAAQ,CAAC;CAC7G,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,WAAW;EAAC,CAAC;EAAG,EAAE,SAAS,SAAS;EAAG,EAAE,SAAS,SAAS;CAAC,GACrE,IAAI;EACF,OAAO,MAAM,SAAS,OAAO,OAAO;CACtC,SAAS,GAAG;EACV,MAAM,KACJ,GAAG,aAAa,UAAU,QAAQ,UAAU,wBAAwB,KAAK,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,EAAA,CAAG,MAAM,MAAM,CAAC,CAAC,CAAC,IACtI;CACF;CAEF,MAAM,IAAI,MACR,uDAAuD,MAAM,KAAK,IAAI,EAAE,8EAC1E;AACF;;AAGA,MAAM,eAAe,cAAc,YAAY,GAAG,CAAC,CAAC,QAAQ,gBAAgB;AAE5E,eAAsB,OAAO,OAAgB,SAA8C;CACzF,MAAM,OAAO;CACb,IAAI,OAAO,MA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M,KAAK,MAAM,KAAK,QAAQ;EACjF,OAAO,IAAI,WAAW,MAAM,KAAK,WAAW;GAAE,MAAM;GAAO,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;EAAG,CAAC,CAAC;CACvG,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,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { createRequire } from "node:module";
3
3
  import { dirname, join, resolve } from "node:path";
4
- import { definePlugin } from "./index.js";
4
+ import { definePlugin } from "../index.js";
5
5
  import { t as keptIn } from "./kept.js";
6
6
  import { n as MARKS } from "./marks.js";
7
7
  // src/plugins/recordings/replay.ts
@@ -21,13 +21,18 @@ import { n as MARKS } from "./marks.js";
21
21
  * `?t=<seconds>` opens it paused there, and `&bare` without the controls at the recorded size, 1:1, for a
22
22
  * screenshot; `?embed` is it filling a frame, with no header of its own (the lightbox's); `body[data-ready]` says
23
23
  * it's in place.
24
+ *
25
+ * The plugin's routes serve it, the player and what it plays. A page with no server behind it (a `standalone` build)
26
+ * publishes it as a file instead, `replayPage(sources)`: which recording is `?id=`, and a script of its own says
27
+ * where one is.
24
28
  */
25
- const REPLAY = `<!doctype html>
29
+ /** The replay page's HTML: the routes' as it is, or one for a page published as a file. */
30
+ const replayPage = ({ player = "..", source } = {}) => `<!doctype html>
26
31
  <html lang="en">
27
32
  <meta charset="utf-8">
28
33
  <meta name="viewport" content="width=device-width, initial-scale=1">
29
34
  <title>Recording · deictic</title>
30
- <link rel="stylesheet" href="../player.css">
35
+ <link rel="stylesheet" href="${player}/player.css">
31
36
  <style>
32
37
  :root { color-scheme: dark; --accent: #12b358; }
33
38
  body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; background: #18181b; color: #fafafa; font: 13px/1.4 system-ui, sans-serif; }
@@ -67,15 +72,21 @@ const REPLAY = `<!doctype html>
67
72
  <a id="page" target="_blank" rel="noreferrer"></a>
68
73
  </header>
69
74
  <main id="main"></main>
70
- <script src="../player.js"><\/script>
75
+ <script src="${player}/player.js"><\/script>${source === void 0 ? "" : `
76
+ <script src="${source}"><\/script>`}
71
77
  <script>
72
78
  const params = new URLSearchParams(location.search);
73
79
  const bare = params.has('bare');
74
80
  const embed = params.has('embed');
75
81
  if (bare) document.body.classList.add('bare');
76
82
  if (embed) document.body.classList.add('embed');
77
- const id = location.pathname.split('/').at(-1);
78
- fetch('../recording/' + id).then((r) => (r.ok ? r.json() : r.text().then((t) => Promise.reject(new Error(t))))).then((kept) => {
83
+ const id = params.get('id') ?? location.pathname.split('/').at(-1);
84
+ // The plugin's routes, unless the page was given a source of its own (\`replayPage\`).
85
+ const from = globalThis.deicticReplay ?? {
86
+ recording: (id) => fetch('../recording/' + id).then((r) => (r.ok ? r.json() : r.text().then((t) => Promise.reject(new Error(t))))),
87
+ clip: (id) => '../../voice/clip/' + id,
88
+ };
89
+ Promise.resolve(from.recording(id)).then(async (kept) => {
79
90
  const scheme = kept.colorScheme ?? 'light';
80
91
  const events = JSON.parse(
81
92
  JSON.stringify(kept.events).replace(/\\(\\s*prefers-color-scheme\\s*:\\s*(light|dark)\\s*\\)/g, (_, s) =>
@@ -86,7 +97,7 @@ const REPLAY = `<!doctype html>
86
97
  page.href = kept.page;
87
98
 
88
99
  // A recording with the mic starts paused: a browser plays sound only after a click, which Play is.
89
- const clips = (kept.voice ?? []).map((c) => ({ ...c, audio: Object.assign(new Audio('../../voice/clip/' + c.id), { preload: 'auto' }) }));
100
+ const clips = await Promise.all((kept.voice ?? []).map(async (c) => ({ ...c, audio: Object.assign(new Audio(await from.clip(c.id)), { preload: 'auto' }) })));
90
101
  const t = Number.parseFloat(params.get('t') ?? '');
91
102
  // The player's frame, at most the window's room, the controls (80px) under it; 1:1 when bare.
92
103
  const size = () => bare
@@ -224,12 +235,12 @@ function recordings(options = {}) {
224
235
  "cache-control": "no-store"
225
236
  } });
226
237
  },
227
- replay: () => new Response(REPLAY, { headers: { "content-type": "text/html; charset=utf-8" } }),
238
+ replay: () => new Response(replayPage(), { headers: { "content-type": "text/html; charset=utf-8" } }),
228
239
  "player.js": () => file(player("rrweb-player.umd.min.cjs"), "text/javascript"),
229
240
  "player.css": () => file(player("style.css"), "text/css")
230
241
  }
231
242
  });
232
243
  }
233
- export { recordings as t };
244
+ export { replayPage as n, recordings as t };
234
245
 
235
246
  //# sourceMappingURL=recordings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recordings.js","names":[],"sources":["../../src/plugins/recordings/replay.ts","../../src/plugins/recordings/index.ts"],"sourcesContent":["/**\n * The replay page, `replay/<id>`: rrweb's own player (`rrweb-player`), its timeline, speeds, skipping idle\n * stretches and fullscreen, sized to the window, with what it doesn't do drawn over it:\n *\n * - The page shows in the colour scheme it was recorded in, whatever the viewer's: the replay's iframe\n * answers `prefers-color-scheme` as the viewer's browser does, so the recorded CSS's queries are rewritten\n * before it's replayed, the recorded scheme's to always match and the other's never.\n * - The marks drawn while recording come as custom events, an SVG in page coordinates each; they're drawn\n * over the replay in the player's own scaled wrapper, moved with its scroll, rather than into its document,\n * which the replayer rebuilds. Each is a marker on the timeline.\n * - The voice clips play in step, at the player's speed. A recording with voice starts paused, as a browser\n * plays sound only after a click.\n *\n * `?t=<seconds>` opens it paused there, and `&bare` without the controls at the recorded size, 1:1, for a\n * screenshot; `?embed` is it filling a frame, with no header of its own (the lightbox's); `body[data-ready]` says\n * it's in place.\n *\n * The plugin's routes serve it, the player and what it plays. A page with no server behind it (a `standalone` build)\n * publishes it as a file instead, `replayPage(sources)`: which recording is `?id=`, and a script of its own says\n * where one is.\n */\nimport { MARKS } from './marks.ts';\n\n/** Where the replay page finds what the plugin's routes would serve it, for a page published as a file. */\nexport interface ReplaySources {\n /** The folder `player.js` and `player.css` are in (`rrweb-player`'s `rrweb-player.umd.min.cjs` and `style.css`), from the page: `..`, the routes', by default. */\n player?: string;\n /**\n * A script, from the page, that sets `globalThis.deicticReplay` before the page asks: `recording(id)` answers the\n * recording (a `Kept`) and `clip(id)` a voice clip's URL, either as a promise. The routes by default.\n */\n source?: string;\n}\n\n/** The replay page's HTML: the routes' as it is, or one for a page published as a file. */\nexport const replayPage = ({ player = '..', source }: ReplaySources = {}) => `<!doctype html>\n<html lang=\"en\">\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Recording · deictic</title>\n<link rel=\"stylesheet\" href=\"${player}/player.css\">\n<style>\n :root { color-scheme: dark; --accent: #12b358; }\n body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; background: #18181b; color: #fafafa; font: 13px/1.4 system-ui, sans-serif; }\n header { display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid #3f3f46; }\n header a { color: #a1a1aa; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n main { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 16px; }\n body.bare header { display: none; }\n body.bare main { padding: 0; }\n body.embed header { display: none; }\n body.embed main { padding: 0; }\n body.embed #main .rr-player { box-shadow: none; border-radius: 0; }\n #marks { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; }\n #marks svg { position: absolute; left: 0; top: 0; overflow: visible; }\n .problem { color: #f87171; padding: 16px; }\n /* rrweb-player, in the dark of the rest of deictic. Its rules repeat Svelte's scoping class, so these start\n from #main, which outweighs any number of classes. */\n #main .rr-player { background: #27272a; box-shadow: 0 12px 32px rgb(0 0 0 / 0.5); border-radius: 8px; overflow: hidden; }\n body.bare #main .rr-player { box-shadow: none; border-radius: 0; }\n #main .rr-player .rr-player__frame { background: #fff; }\n #main .rr-player .rr-controller { background: #18181b; border-top: 1px solid #3f3f46; border-radius: 0; }\n #main .rr-player .rr-timeline__time { color: #a1a1aa; font: 12px ui-monospace, monospace; }\n #main .rr-player .rr-progress { background: #3f3f46; border-color: #18181b; }\n #main .rr-player .rr-progress__step { background: color-mix(in srgb, var(--accent) 45%, transparent); }\n #main .rr-player .rr-progress__handler { background: var(--accent); }\n #main .rr-player .rr-controller__btns button { color: #e4e4e7; }\n #main .rr-player .rr-controller__btns button:disabled { color: #52525b; }\n #main .rr-player .rr-controller__btns button svg { fill: currentColor; }\n #main .rr-player .rr-controller__btns button.active { color: #04130b; background: var(--accent); }\n #main .rr-player .rr-controller__btns button:active { background: color-mix(in srgb, var(--accent) 60%, transparent); }\n #main .rr-player .switch .label { color: #e4e4e7; }\n #main .rr-player .switch.disabled .label { color: #52525b; }\n #main .rr-player .switch label:before { background: #52525b; }\n #main .rr-player .switch input:checked + label:before { background: var(--accent); }\n</style>\n<header>\n <strong>Recording</strong>\n <a id=\"page\" target=\"_blank\" rel=\"noreferrer\"></a>\n</header>\n<main id=\"main\"></main>\n<script src=\"${player}/player.js\"></script>${\n source === undefined\n ? ''\n : `\n<script src=\"${source}\"></script>`\n}\n<script>\n const params = new URLSearchParams(location.search);\n const bare = params.has('bare');\n const embed = params.has('embed');\n if (bare) document.body.classList.add('bare');\n if (embed) document.body.classList.add('embed');\n const id = params.get('id') ?? location.pathname.split('/').at(-1);\n // The plugin's routes, unless the page was given a source of its own (\\`replayPage\\`).\n const from = globalThis.deicticReplay ?? {\n recording: (id) => fetch('../recording/' + id).then((r) => (r.ok ? r.json() : r.text().then((t) => Promise.reject(new Error(t))))),\n clip: (id) => '../../voice/clip/' + id,\n };\n Promise.resolve(from.recording(id)).then(async (kept) => {\n const scheme = kept.colorScheme ?? 'light';\n const events = JSON.parse(\n JSON.stringify(kept.events).replace(/\\\\(\\\\s*prefers-color-scheme\\\\s*:\\\\s*(light|dark)\\\\s*\\\\)/g, (_, s) =>\n s === scheme ? '(min-width: 0px)' : '(max-width: 0px) and (min-width: 1px)',\n ),\n );\n page.textContent = kept.page;\n page.href = kept.page;\n\n // A recording with the mic starts paused: a browser plays sound only after a click, which Play is.\n const clips = await Promise.all((kept.voice ?? []).map(async (c) => ({ ...c, audio: Object.assign(new Audio(await from.clip(c.id)), { preload: 'auto' }) })));\n const t = Number.parseFloat(params.get('t') ?? '');\n // The player's frame, at most the window's room, the controls (80px) under it; 1:1 when bare.\n const size = () => bare\n ? { width: kept.viewport.width, height: kept.viewport.height }\n : embed\n ? { width: innerWidth, height: innerHeight - 80 }\n : { width: Math.min(kept.viewport.width, innerWidth - 32), height: Math.min(kept.viewport.height, innerHeight - 90 - 80 - 16) };\n const Player = rrwebPlayer.default ?? rrwebPlayer.Player ?? rrwebPlayer;\n const player = new Player({\n target: main,\n props: {\n events,\n ...size(),\n autoPlay: !Number.isFinite(t) && clips.length === 0,\n showController: !bare,\n speedOption: [1, 2, 4, 8],\n tags: { ${JSON.stringify(MARKS)}: '#12b358' },\n inactiveColor: '#3f3f46',\n mouseTail: false,\n },\n });\n addEventListener('resize', () => { player.$set(size()); player.triggerResize(); });\n const replayer = player.getReplayer();\n const total = player.getMetaData().totalTime;\n\n // The marks as they were at this point: the latest custom event's, in the player's scaled wrapper, moved with the replay's scroll.\n const marks = Object.assign(document.createElement('div'), { id: 'marks' });\n replayer.wrapper.append(marks);\n replayer.on('custom-event', (e) => { if (e.data.tag === ${JSON.stringify(MARKS)}) marks.innerHTML = e.data.payload.svg; });\n\n let playing = false;\n player.addEventListener('ui-update-player-state', (e) => { playing = e.payload === 'playing'; });\n const follow = () => {\n const win = replayer.iframe.contentWindow;\n if (win) marks.style.transform = 'translate(' + -win.scrollX + 'px,' + -win.scrollY + 'px)';\n const now = Math.min(replayer.getCurrentTime(), total);\n const speed = replayer.config.speed ?? 1;\n // Each clip plays while the replay is inside it, at its speed, kept within a few frames of the replay's time.\n for (const c of clips) {\n const into = now - c.at;\n if (!playing || into < 0 || into >= c.duration) { if (!c.audio.paused) c.audio.pause(); continue; }\n if (c.audio.playbackRate !== speed) c.audio.playbackRate = speed;\n if (Math.abs(c.audio.currentTime * 1000 - into) > 250 * speed) c.audio.currentTime = into / 1000;\n if (c.audio.paused) c.audio.play().catch(() => {});\n }\n requestAnimationFrame(follow);\n };\n follow();\n\n if (Number.isFinite(t)) player.goto(Math.min(Math.max(0, t * 1000), total), false);\n document.body.dataset.ready = '';\n }).catch((e) => { document.querySelector('main').innerHTML = '<p class=\"problem\"></p>'; document.querySelector('.problem').textContent = e.message; });\n</script>\n</html>\n`;\n","/**\n * `deictic/recordings`: records the page with rrweb, for other plugins to attach (tasks does). No tab of\n * its own: `use('recordings').record()` shows a toolbar on the page (drag it to any edge) with annotate\n * mode's tools, where that plugin is loaded, a mic where the voice plugin is, and Stop and Discard. What's drawn while recording is in the\n * recording too, as custom events the replay draws.\n *\n * Recordings are kept under `.deictic/recordings`, the latest `keep`, as JSON: rrweb's\n * events, with the page, its viewport and how long it ran. `replay/<id>` plays one back in the browser.\n */\nimport { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, join, resolve } from 'node:path';\n\nimport { definePlugin } from '#src/index.ts';\nimport type { Masking, ResolvedMasking } from '#src/plugins/screenshots/index.ts';\nimport { keptIn } from '#src/tools/kept.ts';\n\nimport { replayPage } from './replay.ts';\n\nexport { MARKS } from './marks.ts';\nexport { replayPage, type ReplaySources } from './replay.ts';\n\n/** A recording as the page knows it: its ID, where it plays back, and how long it ran, in milliseconds. */\nexport interface Recording {\n id: string;\n url: string;\n duration: number;\n /** What the mic took while it was on, where the voice plugin is loaded. */\n voice?: VoiceClip[];\n}\n\n/** A stretch of the mic in a recording: the voice plugin's clip, and when it starts in the recording, in milliseconds. */\nexport interface VoiceClip {\n id: string;\n at: number;\n duration: number;\n}\n\n/** The page's half, for other plugins' page halves. */\nexport interface Recorder {\n /**\n * Records the page, with the toolbar, until Stop: answers the recording, kept by the dev server, or\n * nothing when it's discarded. Rejects while another is going, or when it couldn't be kept.\n */\n record(): Promise<Recording | undefined>;\n /** Whether one is going. */\n recording(): boolean;\n}\n\n/** The server's half, for other plugins' server halves. */\nexport interface Recordings {\n /** A recording's JSON, or nothing for one not kept (any more). */\n read(id: string): { data: Uint8Array<ArrayBuffer>; name: string; type: 'application/json' } | undefined;\n}\n\n/** What the page sends, and what's kept: rrweb's events and what they can't say. */\nexport interface Kept {\n page: string;\n viewport: { width: number; height: number };\n /**\n * The colour scheme the page was in, which rrweb doesn't record: the replay shows it in the same, or a\n * page styled by `prefers-color-scheme` would take the replay's.\n */\n colorScheme?: 'light' | 'dark';\n startedAt: number;\n duration: number;\n events: unknown[];\n /** The mic's clips, played along with the replay. */\n voice?: VoiceClip[];\n}\n\ndeclare module 'deictic' {\n interface ServerApis {\n recordings: Recordings;\n }\n interface ClientApis {\n recordings: Recorder;\n }\n}\n\nexport interface RecordingsOptions extends Masking {\n /** How many recordings to keep, the latest: 20 by default. */\n keep?: number;\n /** Where they're kept, from the project's root: `.deictic/recordings` by default. */\n dir?: string;\n}\n\nconst ID = /^[a-z0-9]+-[a-z0-9]+$/;\n/** What one recording may weigh: minutes of a busy page are a few MB. */\nconst MAX = 50 * 1024 * 1024;\n\n/** rrweb's player (`rrweb-player`), served to the replay page: its build for a script tag, and its styles. */\nconst player = (file: string) => {\n try {\n return join(dirname(createRequire(import.meta.url).resolve('rrweb-player')), file);\n } catch {\n // Not installed: `file` answers what to add.\n return '';\n }\n};\n\nexport function recordings(options: RecordingsOptions = {}) {\n const keep = options.keep ?? 20;\n let dir = '';\n let taken = 0;\n const pathOf = (id: string) => join(dir, `${id}.json`);\n const read: Recordings['read'] = (id) => {\n if (!ID.test(id) || !existsSync(pathOf(id))) return undefined;\n return { data: new Uint8Array(readFileSync(pathOf(id))), name: `recording-${id}.json`, type: 'application/json' };\n };\n const keepRecording = (data: Uint8Array) => {\n // Sorts by when it was made, which is what pruning keeps by: the count orders two in one millisecond.\n const id = `${Date.now().toString(36).padStart(9, '0')}${(taken++ % 1296).toString(36).padStart(2, '0')}-${crypto.randomUUID().slice(0, 8)}`;\n mkdirSync(dir, { recursive: true });\n writeFileSync(pathOf(id), data);\n const kept = readdirSync(dir)\n .filter((f) => f.endsWith('.json'))\n .toSorted();\n for (const old of kept.slice(0, Math.max(0, kept.length - keep))) rmSync(join(dir, old));\n return id;\n };\n const file = (path: string, type: string) => {\n if (!existsSync(path)) return new Response('rrweb-player is missing: add it to your devDependencies', { status: 404 });\n return new Response(readFileSync(path), { headers: { 'content-type': type } });\n };\n\n return definePlugin<never, never, never, Recordings>({\n name: 'recordings',\n client: 'deictic/recordings/client',\n clientOptions: {\n masking: {\n blockClass: options.blockClass ?? 'rr-block',\n blockSelector: options.blockSelector,\n maskTextClass: options.maskTextClass ?? 'rr-mask',\n maskTextSelector: options.maskTextSelector,\n maskAllInputs: options.maskAllInputs ?? false,\n } satisfies ResolvedMasking,\n },\n setup: ({ root }) => {\n dir = options.dir === undefined ? keptIn(root, 'recordings') : resolve(root, options.dir);\n return { read };\n },\n routes: {\n // What the page recorded, as JSON.\n add: async (req) => {\n if (!(req.headers.get('content-type') ?? '').startsWith('application/json'))\n return Response.json({ problem: 'send the recording as application/json' }, { status: 415 });\n const body = new Uint8Array(await req.arrayBuffer());\n if (body.byteLength > MAX)\n return Response.json({ problem: `a recording may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });\n let kept: Partial<Kept>;\n try {\n kept = JSON.parse(new TextDecoder().decode(body)) as Partial<Kept>;\n } catch {\n return Response.json({ problem: \"the recording isn't JSON\" }, { status: 400 });\n }\n if (!Array.isArray(kept.events) || kept.events.length === 0)\n return Response.json({ problem: 'the recording has no events: record for a moment longer' }, { status: 400 });\n return Response.json({ id: keepRecording(body) });\n },\n // `recording/<id>`: the JSON, for the replay page.\n recording: (req) => {\n const found = read(new URL(req.url).pathname.split('/').at(-1) ?? '');\n if (found === undefined) return new Response('no such recording, or not kept any more', { status: 404 });\n return new Response(found.data, { headers: { 'content-type': found.type, 'cache-control': 'no-store' } });\n },\n // `replay/<id>`: a page that plays it back.\n replay: () => new Response(replayPage(), { headers: { 'content-type': 'text/html; charset=utf-8' } }),\n 'player.js': () => file(player('rrweb-player.umd.min.cjs'), 'text/javascript'),\n 'player.css': () => file(player('style.css'), 'text/css'),\n },\n });\n}\n\nexport default recordings;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,cAAc,EAAE,SAAS,MAAM,WAA0B,CAAC,MAAM;;;;;+BAK9C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAwCvB,OAAO,wBACpB,WAAW,KAAA,IACP,KACA;eACS,OAAO,cACrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAyCiB,KAAK,UAAU,KAAK,EAAE;;;;;;;;;;;;8DAYsB,KAAK,UAAU,KAAK,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACnDpF,MAAM,KAAK;;AAEX,MAAM,MAAM;;AAGZ,MAAM,UAAU,SAAiB;CAC/B,IAAI;EACF,OAAO,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC,CAAC,QAAQ,cAAc,CAAC,GAAG,IAAI;CACnF,QAAQ;EAEN,OAAO;CACT;AACF;AAEA,SAAgB,WAAW,UAA6B,CAAC,GAAG;CAC1D,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI,MAAM;CACV,IAAI,QAAQ;CACZ,MAAM,UAAU,OAAe,KAAK,KAAK,GAAG,GAAG,MAAM;CACrD,MAAM,QAA4B,OAAO;EACvC,IAAI,CAAC,GAAG,KAAK,EAAE,KAAK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K,OAAO,0BAA0B,GAAG,iBAAiB;GAC7E,oBAAoB,KAAK,OAAO,WAAW,GAAG,UAAU;EAC1D;CACF,CAAC;AACH"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shortcut.js","names":[],"sources":["../../src/shortcut.ts"],"sourcesContent":["/**\n * A gesture: the keys held to outline the element under the pointer, and the button that, with them\n * held, opens the popup there. deictic's own (`MASTER` by default) opens the tab used last; a\n * plugin's, which it takes as its `shortcut` option and has none by default, opens its tab. The\n * bundler's plugin checks them all as it starts, so a wrong one, or two alike, fails the dev server,\n * not the page. Both halves import it: it must\n * stay dependency-free.\n */\n\n/** A modifier key, as `KeyboardEvent.key` names it. */\nexport type Modifier = 'Alt' | 'Control' | 'Meta' | 'Shift';\n\nexport interface Shortcut {\n /** Held, and no other, to outline elements. */\n modifiers?: Modifier[];\n /** Pressed with them to open the panel. `'left'` unset. */\n button?: 'left' | 'middle' | 'right';\n}\n\nconst FLAGS = { Alt: 'altKey', Control: 'ctrlKey', Meta: 'metaKey', Shift: 'shiftKey' } as const;\nconst BUTTONS = { left: 0, middle: 1, right: 2 } as const;\n\n/** deictic's own shortcut, unless `deictic({ shortcut })` names another or `false`. */\nexport const MASTER: Required<Shortcut> = { modifiers: ['Alt'], button: 'left' };\n\n/** The name deictic's own shortcut goes by in a problem. */\nexport const OWN = 'deictic';\n\n/** deictic's own shortcut as given, with its default, before it's checked. */\nexport const ownShortcut = (given: Shortcut | false | undefined) => (given === false ? undefined : (given ?? MASTER));\n\n/** The shortcut with its button's default and its modifiers in one order, or an error saying what to write instead. */\nexport function checkShortcut(plugin: string, shortcut: Shortcut): Required<Shortcut> {\n const { modifiers = [], button = 'left' } = shortcut;\n const named = Object.keys(FLAGS).join(\"', '\");\n if (!Array.isArray(modifiers) || modifiers.length === 0) {\n throw new Error(\n `deictic: ${plugin}'s shortcut.modifiers is empty: hold at least one of '${named}', or every click would open the popup`,\n );\n }\n for (const m of modifiers)\n if (!Object.hasOwn(FLAGS, m)) throw new Error(`deictic: ${plugin}'s shortcut.modifiers has '${m}': name one of '${named}'`);\n\n if (!Object.hasOwn(BUTTONS, button))\n throw new Error(`deictic: ${plugin}'s shortcut.button is '${button}': name one of '${Object.keys(BUTTONS).join(\"', '\")}'`);\n\n const order = Object.keys(FLAGS);\n return { modifiers: [...new Set(modifiers)].toSorted((a, b) => order.indexOf(a) - order.indexOf(b)), button };\n}\n\n/**\n * Each shortcut checked, in order, or nothing where there's none: none may be another's, or only the\n * first would ever open. deictic's own goes first, named `OWN`.\n */\nexport function checkShortcuts(plugins: readonly { name: string; shortcut?: Shortcut }[]): (Required<Shortcut> | undefined)[] {\n const taken = new Map<string, string>();\n return plugins.map(({ name, shortcut }) => {\n if (shortcut === undefined) return undefined;\n const checked = checkShortcut(name, shortcut);\n const key = nameOf(checked);\n const other = taken.get(key);\n if (other !== undefined) throw new Error(`deictic: ${name} and ${other} both open on ${key}: give one of them another \\`shortcut\\``);\n taken.set(key, name);\n return checked;\n });\n}\n\n/** How a shortcut reads, for a problem or a label: `Alt+Shift`, `Control+right-click`. */\nexport const nameOf = ({ modifiers = [], button = 'left' }: Shortcut) =>\n [...modifiers, ...(button === 'left' ? [] : [`${button}-click`])].join('+');\n\nexport interface Gesture {\n /** Whether exactly the shortcut's modifiers are down: AltGr, which is Control and Alt, isn't Alt. */\n held: (e: MouseEvent | KeyboardEvent) => boolean;\n /** The shortcut's button, as `MouseEvent.button` numbers it. */\n button: number;\n}\n\nexport function gestureOf(shortcut: Required<Shortcut>): Gesture {\n const on = new Set<string>(shortcut.modifiers);\n const flags = Object.entries(FLAGS);\n return { held: (e) => flags.every(([key, flag]) => e[flag] === on.has(key)), button: BUTTONS[shortcut.button] };\n}\n"],"mappings":";AAmBA,MAAM,QAAQ;CAAE,KAAK;CAAU,SAAS;CAAW,MAAM;CAAW,OAAO;AAAW;AACtF,MAAM,UAAU;CAAE,MAAM;CAAG,QAAQ;CAAG,OAAO;AAAE;;AAG/C,MAAa,SAA6B;CAAE,W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