deictic 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/API.md +23 -3
  2. package/README.md +2 -1
  3. package/dist/bun.js +1 -1
  4. package/dist/client/index.d.ts +1 -1
  5. package/dist/client/index.d.ts.map +1 -1
  6. package/dist/client/index.js +77 -51
  7. package/dist/client/index.js.map +1 -1
  8. package/dist/index.d.ts +2 -2
  9. package/dist/next.js +1 -1
  10. package/dist/recommended/index.d.ts +1 -1
  11. package/dist/recordings/client.js +8 -2
  12. package/dist/recordings/client.js.map +1 -1
  13. package/dist/screenshots/rrweb.d.ts.map +1 -1
  14. package/dist/screenshots/rrweb.js +11 -2
  15. package/dist/screenshots/rrweb.js.map +1 -1
  16. package/dist/shared/canvas.js +30 -0
  17. package/dist/shared/canvas.js.map +1 -0
  18. package/dist/shared/endpoints.js +26 -6
  19. package/dist/shared/endpoints.js.map +1 -1
  20. package/dist/shared/find.js +6 -1
  21. package/dist/shared/find.js.map +1 -1
  22. package/dist/shared/frame.js +5 -2
  23. package/dist/shared/frame.js.map +1 -1
  24. package/dist/shared/index.d.ts +35 -3
  25. package/dist/shared/index.d.ts.map +1 -1
  26. package/dist/shared/index7.d.ts +22 -2
  27. package/dist/shared/index7.d.ts.map +1 -1
  28. package/dist/shared/index9.d.ts +1 -1
  29. package/dist/shared/integration.d.ts +1 -1
  30. package/dist/shared/integration.js +59 -5
  31. package/dist/shared/integration.js.map +1 -1
  32. package/dist/shared/package.js +23 -0
  33. package/dist/shared/package.js.map +1 -0
  34. package/dist/shared/packages.js +14 -23
  35. package/dist/shared/packages.js.map +1 -1
  36. package/dist/shared/playwright.js +32 -6
  37. package/dist/shared/playwright.js.map +1 -1
  38. package/dist/shared/src.js.map +1 -1
  39. package/dist/shared/task.js +12 -3
  40. package/dist/shared/task.js.map +1 -1
  41. package/dist/shared/tasks.js +52 -4
  42. package/dist/shared/tasks.js.map +1 -1
  43. package/dist/shared/watch.js +2 -1
  44. package/dist/shared/watch.js.map +1 -1
  45. package/dist/tailwind/index.js +7 -2
  46. package/dist/tailwind/index.js.map +1 -1
  47. package/dist/tasks/client.d.ts.map +1 -1
  48. package/dist/tasks/client.js +50 -9
  49. package/dist/tasks/client.js.map +1 -1
  50. package/dist/tasks/index.d.ts +2 -2
  51. package/dist/webpack.js +1 -1
  52. package/package.json +2 -1
  53. package/src/cli/find.ts +5 -1
  54. package/src/cli/frame.ts +6 -3
  55. package/src/cli/task.ts +20 -4
  56. package/src/cli/watch.ts +3 -1
  57. package/src/client/index.ts +76 -43
  58. package/src/index.ts +35 -2
  59. package/src/plugins/recordings/client.ts +8 -2
  60. package/src/plugins/screenshots/canvas.ts +27 -0
  61. package/src/plugins/screenshots/playwright.ts +34 -7
  62. package/src/plugins/screenshots/rrweb.ts +30 -9
  63. package/src/plugins/tailwind/index.ts +3 -2
  64. package/src/plugins/tasks/client.ts +13 -3
  65. package/src/plugins/tasks/composer.ts +1 -1
  66. package/src/plugins/tasks/drawer.ts +3 -3
  67. package/src/plugins/tasks/index.ts +81 -3
  68. package/src/plugins/tasks/pins.ts +12 -7
  69. package/src/plugins/tasks/which.ts +34 -0
  70. package/src/tools/endpoints.ts +31 -5
  71. package/src/tools/packages.ts +12 -4
  72. package/src/tools/plugins.ts +18 -4
  73. package/src/tools/problems.ts +60 -0
@@ -1 +1 @@
1
- {"version":3,"file":"packages.js","names":["name","manifest.name","manifest.version","manifest.peerDependencies"],"sources":["../../package.json","../../src/tools/packages.ts"],"sourcesContent":["","/**\n * The packages plugins import that the project installs itself (`ServerPlugin.packages`: deictic's optional peers,\n * or a plugin's own), and how to install them with the project's package manager. A missing one is said as the dev\n * server starts, with the command that installs it, not on the first shot or recording, where it would fail.\n */\nimport { existsSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\n\nimport manifest from '#package.json' with { type: 'json' };\nimport type { ServerPlugin } from '#src/index.ts';\n\nexport type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';\n\n/** Each package manager's lockfiles, in the order they're looked for in a folder. */\nconst LOCKS: [string, PackageManager][] = [\n ['bun.lock', 'bun'],\n ['bun.lockb', 'bun'],\n ['pnpm-lock.yaml', 'pnpm'],\n ['yarn.lock', 'yarn'],\n ['package-lock.json', 'npm'],\n];\nconst MANAGERS: PackageManager[] = ['npm', 'pnpm', 'yarn', 'bun'];\n\n/**\n * The project's package manager: its `packageManager` field, or the lockfile nearest the root (a workspace's is\n * above it), or the one running this (`npm_config_user_agent`), or npm. The lockfile wins over what runs this,\n * as `npx deictic init` runs under npm in a project of any manager's.\n */\nexport function packageManager(root: string, agent = process.env.npm_config_user_agent): PackageManager {\n for (let dir = root; ; dir = dirname(dir)) {\n const field = fieldOf(dir);\n if (field !== undefined) return field;\n const lock = LOCKS.find(([file]) => existsSync(join(dir, file)));\n if (lock !== undefined) return lock[1];\n if (dirname(dir) === dir) break;\n }\n const running = agent?.split('/')[0];\n return MANAGERS.find((m) => m === running) ?? 'npm';\n}\n\n/** A package.json's `packageManager` (`pnpm@9.1.0`), by its manager's name. */\nfunction fieldOf(dir: string): PackageManager | undefined {\n const field = readJson(join(dir, 'package.json'))?.packageManager;\n const name = typeof field === 'string' ? field.split('@')[0] : undefined;\n return MANAGERS.find((m) => m === name);\n}\n\nexport function readJson(path: string): Record<string, unknown> | undefined {\n try {\n return JSON.parse(readFileSync(path, 'utf8')) as Record<string, unknown>;\n } catch {\n return undefined;\n }\n}\n\n/**\n * A package as the install command names it: with deictic's range for it where it's one of deictic's peers (rrweb's\n * packages must agree), or deictic's own version for deictic. Quoted, as `>` and `^` are a shell's.\n */\nexport function specOf(name: string): string {\n const range = name === manifest.name ? `^${manifest.version}` : (manifest.peerDependencies as Record<string, string>)[name];\n return range === undefined ? name : `\"${name}@${range}\"`;\n}\n\n/** The command that adds `names` to the project's dev dependencies. A pnpm workspace's root takes them only with `-w`. */\nexport function installCommand(manager: PackageManager, names: readonly string[], root: string): string {\n const add = {\n npm: 'npm install -D',\n pnpm: existsSync(join(root, 'pnpm-workspace.yaml')) ? 'pnpm add -D -w' : 'pnpm add -D',\n yarn: 'yarn add -D',\n bun: 'bun add -d',\n }[manager];\n return [add, ...names.map(specOf)].join(' ');\n}\n\n/** What runs a package's CLI without installing it, for the manager: `npx`, `bunx`. */\nexport const runnerOf = (manager: PackageManager) => ({ npm: 'npx', pnpm: 'pnpm dlx', yarn: 'npx', bun: 'bunx' })[manager];\n\n/** What runs a CLI the project installed, for the manager: `npx`, `bunx`, each the project's own version. */\nexport const execOf = (manager: PackageManager) => ({ npm: 'npx', pnpm: 'pnpm exec', yarn: 'yarn', bun: 'bunx' })[manager];\n\n/** Whether the project can import `name`: it's found from the root, as the bundler and deictic's own imports find it. */\nexport function installed(root: string, name: string): boolean {\n try {\n createRequire(join(root, 'package.json')).resolve(`${name}/package.json`);\n return true;\n } catch (e) {\n // There, but its `exports` don't name its package.json: only \"not found\" means it's missing.\n return (e as { code?: string }).code !== 'MODULE_NOT_FOUND';\n }\n}\n\n/** Each plugin with the packages it imports that the project hasn't installed, where it has any. */\nexport function missing(root: string, plugins: readonly ServerPlugin[]): { plugin: string; packages: string[] }[] {\n return plugins.flatMap(({ name, packages = [] }) => {\n const gone = packages.filter((p) => !installed(root, p));\n return gone.length === 0 ? [] : [{ plugin: name, packages: gone }];\n });\n}\n\n/** What to say as the dev server starts when plugins' packages are missing: which, and the command that installs them. */\nexport function missingMessage(root: string, plugins: readonly ServerPlugin[]): string | undefined {\n const gone = missing(root, plugins);\n if (gone.length === 0) return undefined;\n const names = [...new Set(gone.flatMap((g) => g.packages))];\n const which = gone.map((g) => g.plugin);\n const who = which.length === 1 ? which[0] : `${which.slice(0, -1).join(', ')} and ${which.at(-1)}`;\n return `deictic: install what ${who} ${which.length === 1 ? 'needs' : 'need'}: ${installCommand(packageManager(root), names, root)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;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AI,GAAG,OAAO,IAAI;AACnI"}
1
+ {"version":3,"file":"packages.js","names":["name","manifest.name","manifest.version","manifest.peerDependencies"],"sources":["../../src/tools/packages.ts"],"sourcesContent":["/**\n * The packages plugins import that the project installs itself (`ServerPlugin.packages`: deictic's optional peers,\n * or a plugin's own), and how to install them with the project's package manager. A missing one is said as the dev\n * server starts, with the command that installs it, not on the first shot or recording, where it would fail.\n */\nimport { existsSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\n\nimport manifest from '#package.json' with { type: 'json' };\nimport type { Problem, ServerPlugin } from '#src/index.ts';\n\nexport type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';\n\n/** Each package manager's lockfiles, in the order they're looked for in a folder. */\nconst LOCKS: [string, PackageManager][] = [\n ['bun.lock', 'bun'],\n ['bun.lockb', 'bun'],\n ['pnpm-lock.yaml', 'pnpm'],\n ['yarn.lock', 'yarn'],\n ['package-lock.json', 'npm'],\n];\nconst MANAGERS: PackageManager[] = ['npm', 'pnpm', 'yarn', 'bun'];\n\n/**\n * The project's package manager: its `packageManager` field, or the lockfile nearest the root (a workspace's is\n * above it), or the one running this (`npm_config_user_agent`), or npm. The lockfile wins over what runs this,\n * as `npx deictic init` runs under npm in a project of any manager's.\n */\nexport function packageManager(root: string, agent = process.env.npm_config_user_agent): PackageManager {\n for (let dir = root; ; dir = dirname(dir)) {\n const field = fieldOf(dir);\n if (field !== undefined) return field;\n const lock = LOCKS.find(([file]) => existsSync(join(dir, file)));\n if (lock !== undefined) return lock[1];\n if (dirname(dir) === dir) break;\n }\n const running = agent?.split('/')[0];\n return MANAGERS.find((m) => m === running) ?? 'npm';\n}\n\n/** A package.json's `packageManager` (`pnpm@9.1.0`), by its manager's name. */\nfunction fieldOf(dir: string): PackageManager | undefined {\n const field = readJson(join(dir, 'package.json'))?.packageManager;\n const name = typeof field === 'string' ? field.split('@')[0] : undefined;\n return MANAGERS.find((m) => m === name);\n}\n\nexport function readJson(path: string): Record<string, unknown> | undefined {\n try {\n return JSON.parse(readFileSync(path, 'utf8')) as Record<string, unknown>;\n } catch {\n return undefined;\n }\n}\n\n/**\n * A package as the install command names it: with deictic's range for it where it's one of deictic's peers (rrweb's\n * packages must agree), or deictic's own version for deictic. Quoted, as `>` and `^` are a shell's.\n */\nexport function specOf(name: string): string {\n const range = name === manifest.name ? `^${manifest.version}` : (manifest.peerDependencies as Record<string, string>)[name];\n return range === undefined ? name : `\"${name}@${range}\"`;\n}\n\n/** The command that adds `names` to the project's dev dependencies. A pnpm workspace's root takes them only with `-w`. */\nexport function installCommand(manager: PackageManager, names: readonly string[], root: string): string {\n const add = {\n npm: 'npm install -D',\n pnpm: existsSync(join(root, 'pnpm-workspace.yaml')) ? 'pnpm add -D -w' : 'pnpm add -D',\n yarn: 'yarn add -D',\n bun: 'bun add -d',\n }[manager];\n return [add, ...names.map(specOf)].join(' ');\n}\n\n/** What runs a package's CLI without installing it, for the manager: `npx`, `bunx`. */\nexport const runnerOf = (manager: PackageManager) => ({ npm: 'npx', pnpm: 'pnpm dlx', yarn: 'npx', bun: 'bunx' })[manager];\n\n/** What runs a CLI the project installed, for the manager: `npx`, `bunx`, each the project's own version. */\nexport const execOf = (manager: PackageManager) => ({ npm: 'npx', pnpm: 'pnpm exec', yarn: 'yarn', bun: 'bunx' })[manager];\n\n/** Whether the project can import `name`: it's found from the root, as the bundler and deictic's own imports find it. */\nexport function installed(root: string, name: string): boolean {\n try {\n createRequire(join(root, 'package.json')).resolve(`${name}/package.json`);\n return true;\n } catch (e) {\n // There, but its `exports` don't name its package.json: only \"not found\" means it's missing.\n return (e as { code?: string }).code !== 'MODULE_NOT_FOUND';\n }\n}\n\n/** Each plugin with the packages it imports that the project hasn't installed, where it has any. */\nexport function missing(root: string, plugins: readonly ServerPlugin[]): { plugin: string; packages: string[] }[] {\n return plugins.flatMap(({ name, packages = [] }) => {\n const gone = packages.filter((p) => !installed(root, p));\n return gone.length === 0 ? [] : [{ plugin: name, packages: gone }];\n });\n}\n\n/**\n * What to report as the dev server starts when plugins' packages are missing: which, and the command that installs\n * them. Its key names them, so a problem fixed and then another missing is a new one.\n */\nexport function missingProblem(root: string, plugins: readonly ServerPlugin[]): Problem | undefined {\n const gone = missing(root, plugins);\n if (gone.length === 0) return undefined;\n const names = [...new Set(gone.flatMap((g) => g.packages))];\n const which = gone.map((g) => g.plugin);\n const who = which.length === 1 ? which[0] : `${which.slice(0, -1).join(', ')} and ${which.at(-1)}`;\n const need = which.length === 1 ? 'needs' : 'need';\n return {\n key: `packages:${[...names].sort().join(',')}`,\n kind: 'setup',\n message: `install what ${who} ${need}, then restart the dev server: ${installCommand(packageManager(root), names, root)}`,\n };\n}\n"],"mappings":";;;;;;;;;;;AAeA,MAAM,QAAoC;CACxC,CAAC,YAAY,KAAK;CAClB,CAAC,aAAa,KAAK;CACnB,CAAC,kBAAkB,MAAM;CACzB,CAAC,aAAa,MAAM;CACpB,CAAC,qBAAqB,KAAK;AAC7B;AACA,MAAM,WAA6B;CAAC;CAAO;CAAQ;CAAQ;AAAK;;;;;;AAOhE,SAAgB,eAAe,MAAc,QAAQ,QAAQ,IAAI,uBAAuC;CACtG,KAAK,IAAI,MAAM,OAAQ,MAAM,QAAQ,GAAG,GAAG;EACzC,MAAM,QAAQ,QAAQ,GAAG;EACzB,IAAI,UAAU,KAAA,GAAW,OAAO;EAChC,MAAM,OAAO,MAAM,MAAM,CAAC,UAAU,WAAW,KAAK,KAAK,IAAI,CAAC,CAAC;EAC/D,IAAI,SAAS,KAAA,GAAW,OAAO,KAAK;EACpC,IAAI,QAAQ,GAAG,MAAM,KAAK;CAC5B;CACA,MAAM,UAAU,OAAO,MAAM,GAAG,CAAC,CAAC;CAClC,OAAO,SAAS,MAAM,MAAM,MAAM,OAAO,KAAK;AAChD;;AAGA,SAAS,QAAQ,KAAyC;CACxD,MAAM,QAAQ,SAAS,KAAK,KAAK,cAAc,CAAC,CAAC,EAAE;CACnD,MAAM,OAAO,OAAO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E,CAAC;AACH;;;;;AAMA,SAAgB,eAAe,MAAc,SAAuD;CAClG,MAAM,OAAO,QAAQ,MAAM,OAAO;CAClC,IAAI,KAAK,WAAW,GAAG,OAAO,KAAA;CAC9B,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,KAAK,SAAS,MAAM,EAAE,QAAQ,CAAC,CAAC;CAC1D,MAAM,QAAQ,KAAK,KAAK,MAAM,EAAE,MAAM;CACtC,MAAM,MAAM,MAAM,WAAW,IAAI,MAAM,KAAK,GAAG,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,OAAO,MAAM,GAAG,EAAE;CAC/F,MAAM,OAAO,MAAM,WAAW,IAAI,UAAU;CAC5C,OAAO;EACL,KAAK,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG;EAC3C,MAAM;EACN,SAAS,gBAAgB,IAAI,GAAG,KAAK,iCAAiC,eAAe,eAAe,IAAI,GAAG,OAAO,IAAI;CACxH;AACF"}
@@ -1,4 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
+ import { t as CANVAS_SIZE } from "./canvas.js";
2
3
  // src/plugins/screenshots/playwright.ts
3
4
  /**
4
5
  * The `rrweb()` renderer's server half: rebuilds a page's snapshot in a browser beside the dev server and
@@ -75,7 +76,11 @@ async function render(input, options) {
75
76
  }));
76
77
  await page.goto(host);
77
78
  await page.addScriptTag({ path: bundle() });
78
- const found = await page.evaluate(async ({ snapshot, scroll, overlay, element }) => {
79
+ const given = {
80
+ ...shot,
81
+ size: CANVAS_SIZE
82
+ };
83
+ const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size }) => {
79
84
  const { rebuildIntoSandboxedIframe, createCache, createMirror } = globalThis.rrwebSnapshot;
80
85
  const mirror = createMirror();
81
86
  const { iframe } = rebuildIntoSandboxedIframe(snapshot, {
@@ -86,17 +91,38 @@ async function render(input, options) {
86
91
  });
87
92
  const doc = iframe.contentDocument;
88
93
  if (doc === null) throw new Error("screenshots: the snapshot was rebuilt where it cannot be read");
94
+ const isElement = (node) => node?.nodeType === 1;
95
+ const hidden = doc.createElement("style");
96
+ hidden.textContent = "noscript { display: none !important; }";
97
+ doc.head.append(hidden);
98
+ for (const canvas of doc.querySelectorAll(`canvas[${size}]`)) {
99
+ const meta = mirror.getMeta(canvas);
100
+ const [box, inline] = (canvas.getAttribute(size) ?? "").split(" ");
101
+ const [width, height] = (box ?? "").split("x");
102
+ if (meta === null || !("attributes" in meta) || typeof meta.attributes.rr_dataURL !== "string") continue;
103
+ const picture = doc.createElement("img");
104
+ picture.src = meta.attributes.rr_dataURL;
105
+ picture.style.cssText = `display:${inline === void 0 ? "block" : "inline"};width:${width}px;height:${height}px`;
106
+ canvas.replaceChildren(picture);
107
+ }
89
108
  await doc.fonts.ready;
90
109
  await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));
91
- iframe.contentWindow?.scrollTo(scroll.x, scroll.y);
92
- const isElement = (node) => node?.nodeType === 1;
110
+ iframe.contentWindow?.scrollTo({
111
+ left: scroll.x,
112
+ top: scroll.y,
113
+ behavior: "instant"
114
+ });
93
115
  for (const id of mirror.getIds()) {
94
116
  const node = mirror.getNode(id);
95
117
  const meta = node === null ? null : mirror.getMeta(node);
96
118
  if (!isElement(node) || meta === null || !("attributes" in meta)) continue;
97
119
  const { rr_scrollTop: top, rr_scrollLeft: left } = meta.attributes;
98
- if (typeof top === "number") node.scrollTop = top;
99
- if (typeof left === "number") node.scrollLeft = left;
120
+ if (typeof top !== "number" && typeof left !== "number") continue;
121
+ node.scrollTo({
122
+ top: typeof top === "number" ? top : node.scrollTop,
123
+ left: typeof left === "number" ? left : node.scrollLeft,
124
+ behavior: "instant"
125
+ });
100
126
  }
101
127
  const node = element === void 0 ? null : mirror.getNode(element);
102
128
  const rect = isElement(node) ? node.getBoundingClientRect() : void 0;
@@ -112,7 +138,7 @@ async function render(input, options) {
112
138
  marks.innerHTML = overlay;
113
139
  document.body.append(marks);
114
140
  return box;
115
- }, shot);
141
+ }, given);
116
142
  const clip = clamp(shot.clip === void 0 ? {
117
143
  x: 0,
118
144
  y: 0,
@@ -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 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 const found = await page.evaluate(async ({ snapshot, scroll, overlay, element }) => {\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 await doc.fonts.ready;\n await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));\n iframe.contentWindow?.scrollTo(scroll.x, scroll.y);\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 // 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 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') node.scrollTop = top;\n if (typeof left === 'number') node.scrollLeft = left;\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 }, shot);\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":";;;;;;;;;;;;;;;;AAyCA,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;;AAGA,MAAM,aAAa,EAAE,mBAAmB,CAAC,mBAAmB,EAAE;AAE9D,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;EAAS,GAAG;CAA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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}\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 ? { x, y, width, height } : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0CA,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;;AAGA,MAAM,aAAa,EAAE,mBA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AAM,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 +1 @@
1
- {"version":3,"file":"src.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * `deictic`: what a plugin is. Every plugin is optional: deictic itself is the glue (the\n * transform that ties elements to source, the dev server's endpoints, the history, shortcuts and the\n * overlay's panel), and each plugin adds what it does on top.\n *\n * A plugin has two halves, each optional that meet over the dev server's endpoints (`tools/endpoints.ts`). The\n * server half runs beside the bundler and is the only one that reads source: it turns the element\n * under the pointer into a model its panel can show, and an op from that panel into text edits. It\n * never writes files; deictic does, so every plugin's changes land in one history and undo the\n * same way. A change that isn't to a file (a task added to a board) the plugin makes itself and\n * answers with what it did (`Done`): the history keeps that beside the files' changes and hands it\n * back to the plugin's own `undo` and `redo`.\n * The client half is a module the page loads, named by the server half's `client`, which draws the\n * panel and previews an op on the page before it is applied.\n *\n * A plugin may have no panel at all, only an API for others (screenshots, a recording) and routes of\n * its own on the dev server. Each half's `setup` answers its API, and `use(name)` reaches another\n * plugin's, on the same side; `needs` names the plugins it can't do without.\n *\n * Both halves import from here, so the parser is imported for its types only: the browser must not load it.\n */\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport type { Shortcut } from './shortcut.ts';\n\nexport type { Modifier, Shortcut } from './shortcut.ts';\n\n/** A place in the source: the file from the project's root, with `/`, and the line and column, from 1. */\nexport interface Loc {\n file: string;\n line: number;\n column: number;\n}\n\n/** An element the pointer picked: where its opening tag starts, and the tag, which the server checks is still there. */\nexport interface Target {\n loc: Loc;\n tag: string;\n}\n\n/** Text in a file to replace, by UTF-16 offsets. `file` is the target's unless named, from the project's root. */\nexport interface TextEdit {\n file?: string;\n start: number;\n end: number;\n text: string;\n}\n\n/** What a server half reads: the target's file, parsed, and its element. */\nexport interface Source {\n /** The target's file, from the project's root. */\n file: string;\n code: string;\n /** The file's module; for an `.astro` component, its frontmatter's. */\n program: Program;\n /** The target's opening tag. */\n element: JSXOpeningElement;\n /** Another file under the project's root, for plugins whose edits go elsewhere (a locale's messages). */\n read(file: string): string;\n}\n\n/**\n * What answers the overlay's requests in a page with no dev server behind it (`deictic/vite`'s `standalone`): the\n * default export of a module of the page's. A request is one the endpoints would get, under `<base>__deictic/`;\n * the answer is theirs too (`{ model }`, `{ model, change }`, `{ problem }` with a status that isn't ok).\n */\nexport type Standalone = (request: Request) => Response | Promise<Response>;\n\n/** An op a plugin won't make. The message says why and what to do instead; the panel shows it. */\nexport class Refusal extends Error {\n override name = 'Refusal';\n}\n\n/**\n * A change the plugin made itself, not to a file: what its `undo` and `redo` need to take it back and\n * make it again. JSON, since the history keeps it on disk across restarts of the dev server.\n */\nexport interface Done<Record = unknown> {\n done: Record;\n}\n\ntype Maybe<T> = T | Promise<T>;\n\n/**\n * Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:\n * `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.\n */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ServerApis {}\n\n/** The same, in the page: `declare module 'deictic' { interface ClientApis { screenshots: Capture } }`. */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ClientApis {}\n\n/** A plugin's API, by its name: what its package declared, or `unknown` for one that declared none. */\nexport type ApiOf<Apis, Name extends string> = Name extends keyof Apis ? Apis[Name] : unknown;\n\nexport interface ServerContext {\n /** The project's root, as an absolute path. */\n root: string;\n /**\n * Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded. One the plugin\n * `needs` always is; any other may not be, so check.\n */\n use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;\n}\n\n/**\n * A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must\n * change nothing: anything else reaches it only from the page itself, which deictic checks.\n */\nexport type Route = (request: Request, context: ServerContext) => Maybe<Response>;\n\nexport interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = unknown> {\n /** Ties the halves together; also the label of its changes in the history, and its routes' path. Lowercase, with `-`. */\n name: string;\n /** The module the page loads for this plugin's half there, which default-exports its `ClientPlugin`. */\n client?: string;\n /** What the page half gets as `context.options`: the user's options it needs there, as JSON. */\n clientOptions?: unknown;\n /** What opens its panel: its own default, which its options let the user change. A plugin with no panel has none. */\n shortcut?: Shortcut;\n /** The plugins it can't do without, by name: the dev server won't start without them. */\n needs?: string[];\n /**\n * The packages it imports that the project installs itself (optional peers), by name: as the dev server starts,\n * it says how to install any that's missing, rather than failing when first used.\n */\n packages?: string[];\n /** Runs once, as the dev server starts and before it answers anything. Answers the plugin's API to the others. */\n setup?(context: ServerContext): Maybe<Api>;\n /** Routes of its own, by their first segment under `/__deictic/plugins/<name>/`. */\n routes?: { [route: string]: Route };\n /**\n * The model its panel shows for an element. Without it, the panel gets none. `source` is a `Refusal` where the\n * element isn't to be found in its file (it doesn't parse, or the page runs other code than it has): throw it where\n * the plugin needs the source, or go on without it, as a task does.\n */\n read?(source: Source | Refusal, target: Target): Maybe<Model>;\n /** Text edits for deictic to write, which it refuses without the source, or a change the plugin made itself. */\n apply?(source: Source | Refusal, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;\n /**\n * Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may\n * answer what the next redo needs, where that differs (what it put back has a new ID).\n */\n undo?(record: Record): Maybe<void | Record>;\n /** Makes it again after an undo, and answers what the next undo needs, which may differ (a new ID). */\n redo?(record: Record): Maybe<Record>;\n /** Says what an op does, for the history: `className: px-2 → px-4`. */\n describe?(op: Op, before: Model): string;\n}\n\nexport const definePlugin = <Model, Op, Record = unknown, Api = unknown>(\n plugin: ServerPlugin<Model, Op, Record, Api>,\n): ServerPlugin<Model, Op, Record, Api> => plugin;\n\n/** Where something is in an element, in CSS pixels from its top left. */\nexport interface Point {\n x: number;\n y: number;\n}\n\n/** A spot on the page: a marked element, and a point in it (or beside it, for the nearest to a point no marked element is under). */\nexport interface Spot {\n element: Element;\n at: Point;\n}\n\n/**\n * The tool panel: a bar docked to an edge of the window, which shows while a shortcut's keys are held and stays\n * while it's in use. A plugin adds its tools to it from its page half's `setup`.\n */\nexport interface ToolPanel {\n /**\n * Adds a plugin's controls, as one group, in the order plugins are loaded. Groups of one `section` sit together,\n * with no line between them, after the groups of none: the screenshots', recordings', voice's and tasks' are\n * `capture`. `last` puts a group at the end of its section, or after all the others for one of none. Each control is a button named by its `title`; its `aria-keyshortcuts`\n * (`B`, `Control+Z`) is the key the panel hears for it, alone or with the keys held to point, and what its tooltip\n * shows.\n */\n add: (group: HTMLElement, options?: { last?: boolean; section?: string }) => void;\n /**\n * Takes the page for a tool that works on it (drawing, picking a point): the tool that had it lets go first, and\n * the panel stays shown. `left` is called when another takes it, or Esc or the pointer tool gives the page back.\n * Answers what lets go of it, for the tool to call when it's done on its own.\n */\n hold: (left: () => void) => () => void;\n /** Keeps the panel shown while something goes on that its controls end (a recording). Answers what ends that. */\n keep: () => () => void;\n /**\n * Takes the page until a point of it is pressed, lighting what's under the pointer as pointing does: answers the\n * spot, the marked element there or the nearest to it, or nothing where the page was given back first.\n */\n pick: () => Promise<Spot | undefined>;\n}\n\n/**\n * The drawer: on the window's side, where what the plugins have for the page lands, a section each. It\n * shows while a shortcut's keys are held and a section has something, and stays while it's in use.\n */\nexport interface Drawer {\n /**\n * Adds a section, in the order added, or before the others with `first`. A section that has nothing to show sets\n * its own `hidden`: the drawer stays away while every one is. Folded away, the drawer counts what the sections\n * have: each says how many things it lists in `data-count`, and how many are unread in `data-unread`.\n */\n add: (section: HTMLElement, options?: { first?: boolean }) => void;\n /**\n * Opens one item in the drawer, in the sections' place, under `title` and a way back. The drawer stays while it's\n * open. `closed` is called when it's left, by the way back, Esc, or another item opening. Answers what closes it.\n */\n show: (view: HTMLElement, options?: { title?: string; closed?: () => void }) => () => void;\n /** Keeps the drawer up while something goes on in it; answers what lets it go. */\n keep: () => () => void;\n}\n\n/** Something a plugin made on the page that nothing has taken yet: a shot, a recording, a voice clip. */\nexport interface TrayItem {\n /** The plugin that made it. */\n plugin: string;\n /** Its ID, as that plugin has it. */\n id: string;\n /** What that plugin says of it, as JSON: the screenshots plugin's `Shot`, a `Recording`, a `Clip`. */\n value: unknown;\n}\n\n/**\n * What plugins made on the page from the tool panel, until something takes it: a task attaches what's there and\n * removes it. Kept for the tab's session, so it's there on the tab's next page too.\n */\nexport interface Tray {\n /** What's kept, oldest first: all of it, or one plugin's. */\n list: (plugin?: string) => TrayItem[];\n add: (plugin: string, id: string, value: unknown) => void;\n /** Takes one out, or all of a plugin's. */\n remove: (plugin: string, id?: string) => void;\n /** Hears every change from now on; answers what stops it. */\n subscribe: (listener: () => void) => () => void;\n}\n\nexport interface ClientContext {\n /** The dev server's base URL, ending in `/`. */\n base: string;\n /** deictic's shadow root, to draw in: neither the page's styles nor the overlay's cross over. */\n root: ShadowRoot;\n /** The server half's `clientOptions`, or nothing. */\n options: unknown;\n /** Another plugin's API in the page, as its `setup` answered it, or nothing when it isn't loaded. */\n use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;\n /** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */\n request: (route: string, init?: RequestInit) => Promise<Response>;\n /**\n * Opens the popup on an element at a plugin's tab, as its shortcut would, or with `at` on a spot in it: the\n * popup is then beside the spot, which is what's lit, and the tab's context has it. An element rendered again\n * since stands in for one no longer on the page. False when there's no such tab or no such element any more, and\n * while the open popup holds something unsaved, whose button then shakes. Not as `setup` runs, which is before the\n * popup can open.\n */\n open: (plugin: string, element: Element, at?: Point) => boolean;\n /** The tool panel, to add this plugin's tools to. */\n tools: ToolPanel;\n /** What was made from the tool panel and not taken yet. */\n tray: Tray;\n /** The drawer, to add this plugin's section to. */\n drawer: Drawer;\n /**\n * Lights an element on the page as pointing at it does, for something of the overlay's own that stands for it (a\n * task's row in the drawer, while the pointer is on it); none puts the light back as it was.\n */\n light: (element?: Element) => void;\n /**\n * Shows `items` in the lightbox over everything, at `at` (the first by default), stepping between them with\n * ← and →. With `from`, it grows out of that element (the chip clicked) and shrinks back into it on close.\n */\n lightbox: (items: LightboxItem[], options?: LightboxOptions) => { close: () => void };\n}\n\n/** What the lightbox shows: a picture, a page in a frame (a recording's replay), or a sound with its waveform. */\nexport type LightboxItem = {\n /** Its name, over it. */\n title: string;\n /** Buttons beside the name: each closes the lightbox and runs. */\n actions?: LightboxAction[];\n} & ({ kind: 'image'; url: string } | { kind: 'page'; url: string } | { kind: 'audio'; url: string });\n\nexport interface LightboxAction {\n label: string;\n title?: string;\n run: () => void;\n}\n\nexport interface LightboxOptions {\n /** The item it opens at. */\n at?: number;\n /** The element it grows out of, and goes back into. */\n from?: Element;\n}\n\nexport interface PanelContext<Model, Op> extends ClientContext {\n /**\n * The element clicked: the one the source marked, under the pointer or around what is. Back from `away`\n * it may be off the page (`isConnected` is false), where the page moved on without it: the element as it\n * was left, or after a page load an empty one of its tag and mark. `elements` is then empty.\n */\n element: Element;\n /**\n * What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a\n * dependency's, or in an open shadow root, as the popup's own on a page that shows it (`popupIn`).\n */\n pointed?: Element;\n /** The spot in `element` the popup was opened on, where it was (the tool panel's task tool), not the element as a whole. */\n at?: Point;\n /** Every element on the page from the same place in the source, the clicked one among them: the rows of a list. */\n elements: Element[];\n target: Target;\n model: Model;\n /**\n * Applies an op on disk, and reads the model again. Rejects with the server's reason, which the panel also shows.\n * On another element with `on`, whose model is then the one answered: for an op that's about that one.\n */\n apply(op: Op, on?: Target): Promise<Model>;\n close: () => void;\n /**\n * Says there's something here that leaving would lose (words typed, a change tried on the page), and the button\n * that keeps it: a click outside the popup then shakes that button, where it would have closed the popup.\n * `undefined` once there's nothing to lose. Forgotten as the panel unmounts.\n */\n unsaved: (action: HTMLElement | undefined) => void;\n /**\n * Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a\n * pick of another element), and opens it again at this tab on this element. The next mount gets\n * `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why\n * it failed. The state stays in the page, as it is: no need for JSON. It's also kept for the tab's next\n * page, as a structured clone, where it can be one: after a page load, the plugin's `resume` says whether\n * the task carries on, and the popup comes back there.\n */\n away: <T>(state: unknown, task: () => Promise<T>) => void;\n /** Set when this mount is the panel coming back from `away`. */\n resumed?: Resumed;\n}\n\n/** What a panel coming back from `away` gets: the state it kept, and the task's result or problem. */\nexport interface Resumed {\n state: unknown;\n result?: unknown;\n /** Why the task failed: its error's message. */\n problem?: string;\n}\n\nexport interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {\n /** The server half's `name`. */\n name: string;\n /** Shown over the element while its shortcut's keys are held, and atop the panel. */\n label?: string;\n /**\n * Runs once, as the page starts, before any panel opens (a recording starts here). Answers the\n * plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.\n */\n setup?(context: ClientContext): Api;\n /**\n * Asked as a page starts where the page before it left this plugin's panel `away`: the task it left for,\n * where that carries on in this page (a recording does), or nothing where it ended with the page. When it's\n * done the popup opens at this tab with `resumed`, on the element where this page has it and without where not.\n */\n resume?(context: ClientContext): Promise<unknown> | undefined;\n /**\n * What it shows on the page while a shortcut's keys are held, and the page is dimmed to point on: the tasks\n * plugin pins each task where its element is. Answers what takes it away.\n */\n pointing?(context: ClientContext): () => void;\n /** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */\n mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;\n}\n\nexport const defineClientPlugin = <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>): ClientPlugin<Model, Op, Api> => plugin;\n"],"mappings":";;AAqEA,IAAa,UAAb,cAA6B,MAAM;CACxB,OAAO;AAClB;AAiFA,MAAa,gBACX,WACyC;AA4N3C,MAAa,sBAAgD,WAAuE"}
1
+ {"version":3,"file":"src.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * `deictic`: what a plugin is. Every plugin is optional: deictic itself is the glue (the\n * transform that ties elements to source, the dev server's endpoints, the history, shortcuts and the\n * overlay's panel), and each plugin adds what it does on top.\n *\n * A plugin has two halves, each optional that meet over the dev server's endpoints (`tools/endpoints.ts`). The\n * server half runs beside the bundler and is the only one that reads source: it turns the element\n * under the pointer into a model its panel can show, and an op from that panel into text edits. It\n * never writes files; deictic does, so every plugin's changes land in one history and undo the\n * same way. A change that isn't to a file (a task added to a board) the plugin makes itself and\n * answers with what it did (`Done`): the history keeps that beside the files' changes and hands it\n * back to the plugin's own `undo` and `redo`.\n * The client half is a module the page loads, named by the server half's `client`, which draws the\n * panel and previews an op on the page before it is applied.\n *\n * A plugin may have no panel at all, only an API for others (screenshots, a recording) and routes of\n * its own on the dev server. Each half's `setup` answers its API, and `use(name)` reaches another\n * plugin's, on the same side; `needs` names the plugins it can't do without.\n *\n * Both halves import from here, so the parser is imported for its types only: the browser must not load it.\n */\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport type { Shortcut } from './shortcut.ts';\n\nexport type { Modifier, Shortcut } from './shortcut.ts';\n\n/** A place in the source: the file from the project's root, with `/`, and the line and column, from 1. */\nexport interface Loc {\n file: string;\n line: number;\n column: number;\n}\n\n/** An element the pointer picked: where its opening tag starts, and the tag, which the server checks is still there. */\nexport interface Target {\n loc: Loc;\n tag: string;\n}\n\n/** Text in a file to replace, by UTF-16 offsets. `file` is the target's unless named, from the project's root. */\nexport interface TextEdit {\n file?: string;\n start: number;\n end: number;\n text: string;\n}\n\n/** What a server half reads: the target's file, parsed, and its element. */\nexport interface Source {\n /** The target's file, from the project's root. */\n file: string;\n code: string;\n /** The file's module; for an `.astro` component, its frontmatter's. */\n program: Program;\n /** The target's opening tag. */\n element: JSXOpeningElement;\n /** Another file under the project's root, for plugins whose edits go elsewhere (a locale's messages). */\n read(file: string): string;\n}\n\n/**\n * What answers the overlay's requests in a page with no dev server behind it (`deictic/vite`'s `standalone`): the\n * default export of a module of the page's. A request is one the endpoints would get, under `<base>__deictic/`;\n * the answer is theirs too (`{ model }`, `{ model, change }`, `{ problem }` with a status that isn't ok).\n */\nexport type Standalone = (request: Request) => Response | Promise<Response>;\n\n/** An op a plugin won't make. The message says why and what to do instead; the panel shows it. */\nexport class Refusal extends Error {\n override name = 'Refusal';\n}\n\n/**\n * A change the plugin made itself, not to a file: what its `undo` and `redo` need to take it back and\n * make it again. JSON, since the history keeps it on disk across restarts of the dev server.\n */\nexport interface Done<Record = unknown> {\n done: Record;\n}\n\ntype Maybe<T> = T | Promise<T>;\n\n/**\n * Something of deictic's that went wrong, which nothing a person did in the page caused: a package the project\n * hasn't installed, a plugin that failed. The dev server says it, and hands it to each plugin with a `problem`\n * (tasks posts it to the board, for an agent to fix).\n */\nexport interface Problem {\n /**\n * What tells it apart, and the same problem again from a new one: `packages:rrweb`, `setup:tailwind`. Never a\n * time or an ID, so a problem that comes back is known.\n */\n key: string;\n /**\n * `setup`: the project's to fix, as `message` says (install a package, configure a plugin). `bug`: deictic's own, or\n * a plugin's, to report where it's made, not to patch where it's installed.\n */\n kind: 'setup' | 'bug';\n /** What went wrong, and the fix where there is one, as any problem message says it. */\n message: string;\n /** What more there is to look into: a stack. */\n details?: string;\n /** The plugin it's about, where it's one's: none for deictic's own. */\n plugin?: string;\n}\n\n/**\n * Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:\n * `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.\n */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ServerApis {}\n\n/** The same, in the page: `declare module 'deictic' { interface ClientApis { screenshots: Capture } }`. */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ClientApis {}\n\n/** A plugin's API, by its name: what its package declared, or `unknown` for one that declared none. */\nexport type ApiOf<Apis, Name extends string> = Name extends keyof Apis ? Apis[Name] : unknown;\n\nexport interface ServerContext {\n /** The project's root, as an absolute path. */\n root: string;\n /**\n * Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded (or its `setup` failed,\n * which is reported). One the plugin `needs` always is loaded; any other may not be, so check.\n */\n use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;\n /** Says a problem of the plugin's own, as deictic says its own: in the dev server's output, and to each plugin's `problem`. */\n report: (problem: Problem) => void;\n}\n\n/**\n * A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must\n * change nothing: anything else reaches it only from the page itself, which deictic checks.\n */\nexport type Route = (request: Request, context: ServerContext) => Maybe<Response>;\n\nexport interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = unknown> {\n /** Ties the halves together; also the label of its changes in the history, and its routes' path. Lowercase, with `-`. */\n name: string;\n /** The module the page loads for this plugin's half there, which default-exports its `ClientPlugin`. */\n client?: string;\n /** What the page half gets as `context.options`: the user's options it needs there, as JSON. */\n clientOptions?: unknown;\n /** What opens its panel: its own default, which its options let the user change. A plugin with no panel has none. */\n shortcut?: Shortcut;\n /** The plugins it can't do without, by name: the dev server won't start without them. */\n needs?: string[];\n /**\n * The packages it imports that the project installs itself (optional peers), by name: as the dev server starts,\n * it says how to install any that's missing, rather than failing when first used.\n */\n packages?: string[];\n /** Runs once, as the dev server starts and before it answers anything. Answers the plugin's API to the others. */\n setup?(context: ServerContext): Maybe<Api>;\n /** Routes of its own, by their first segment under `/__deictic/plugins/<name>/`. */\n routes?: { [route: string]: Route };\n /**\n * The model its panel shows for an element. Without it, the panel gets none. `source` is a `Refusal` where the\n * element isn't to be found in its file (it doesn't parse, or the page runs other code than it has): throw it where\n * the plugin needs the source, or go on without it, as a task does.\n */\n read?(source: Source | Refusal, target: Target): Maybe<Model>;\n /** Text edits for deictic to write, which it refuses without the source, or a change the plugin made itself. */\n apply?(source: Source | Refusal, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;\n /**\n * Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may\n * answer what the next redo needs, where that differs (what it put back has a new ID).\n */\n undo?(record: Record): Maybe<void | Record>;\n /** Makes it again after an undo, and answers what the next undo needs, which may differ (a new ID). */\n redo?(record: Record): Maybe<Record>;\n /** Says what an op does, for the history: `className: px-2 → px-4`. */\n describe?(op: Op, before: Model): string;\n /**\n * Hears each problem deictic or a plugin reports, on the server or in the page, after every `setup` has run: once\n * per `key` while the dev server runs. Its own failure is only said, never reported again.\n */\n problem?(problem: Problem): Maybe<void>;\n}\n\nexport const definePlugin = <Model, Op, Record = unknown, Api = unknown>(\n plugin: ServerPlugin<Model, Op, Record, Api>,\n): ServerPlugin<Model, Op, Record, Api> => plugin;\n\n/** Where something is in an element, in CSS pixels from its top left. */\nexport interface Point {\n x: number;\n y: number;\n}\n\n/** A spot on the page: a marked element, and a point in it (or beside it, for the nearest to a point no marked element is under). */\nexport interface Spot {\n element: Element;\n at: Point;\n}\n\n/**\n * The tool panel: a bar docked to an edge of the window, which shows while a shortcut's keys are held and stays\n * while it's in use. A plugin adds its tools to it from its page half's `setup`.\n */\nexport interface ToolPanel {\n /**\n * Adds a plugin's controls, as one group, in the order plugins are loaded. Groups of one `section` sit together,\n * with no line between them, after the groups of none: the screenshots', recordings', voice's and tasks' are\n * `capture`. `last` puts a group at the end of its section, or after all the others for one of none. Each control is a button named by its `title`; its `aria-keyshortcuts`\n * (`B`, `Control+Z`) is the key the panel hears for it, alone or with the keys held to point, and what its tooltip\n * shows.\n */\n add: (group: HTMLElement, options?: { last?: boolean; section?: string }) => void;\n /**\n * Takes the page for a tool that works on it (drawing, picking a point): the tool that had it lets go first, and\n * the panel stays shown. `left` is called when another takes it, or Esc or the pointer tool gives the page back.\n * Answers what lets go of it, for the tool to call when it's done on its own.\n */\n hold: (left: () => void) => () => void;\n /** Keeps the panel shown while something goes on that its controls end (a recording). Answers what ends that. */\n keep: () => () => void;\n /**\n * Takes the page until a point of it is pressed, lighting what's under the pointer as pointing does: answers the\n * spot, the marked element there or the nearest to it, or nothing where the page was given back first.\n */\n pick: () => Promise<Spot | undefined>;\n}\n\n/**\n * The drawer: on the window's side, where what the plugins have for the page lands, a section each. It\n * shows while a shortcut's keys are held and a section has something, and stays while it's in use.\n */\nexport interface Drawer {\n /**\n * Adds a section, in the order added, or before the others with `first`. A section that has nothing to show sets\n * its own `hidden`: the drawer stays away while every one is. Folded away, the drawer counts what the sections\n * have: each says how many things it lists in `data-count`, and how many are unread in `data-unread`.\n */\n add: (section: HTMLElement, options?: { first?: boolean }) => void;\n /**\n * Opens one item in the drawer, in the sections' place, under `title` and a way back. The drawer stays while it's\n * open. `closed` is called when it's left, by the way back, Esc, or another item opening. Answers what closes it.\n */\n show: (view: HTMLElement, options?: { title?: string; closed?: () => void }) => () => void;\n /** Keeps the drawer up while something goes on in it; answers what lets it go. */\n keep: () => () => void;\n}\n\n/** Something a plugin made on the page that nothing has taken yet: a shot, a recording, a voice clip. */\nexport interface TrayItem {\n /** The plugin that made it. */\n plugin: string;\n /** Its ID, as that plugin has it. */\n id: string;\n /** What that plugin says of it, as JSON: the screenshots plugin's `Shot`, a `Recording`, a `Clip`. */\n value: unknown;\n}\n\n/**\n * What plugins made on the page from the tool panel, until something takes it: a task attaches what's there and\n * removes it. Kept for the tab's session, so it's there on the tab's next page too.\n */\nexport interface Tray {\n /** What's kept, oldest first: all of it, or one plugin's. */\n list: (plugin?: string) => TrayItem[];\n add: (plugin: string, id: string, value: unknown) => void;\n /** Takes one out, or all of a plugin's. */\n remove: (plugin: string, id?: string) => void;\n /** Hears every change from now on; answers what stops it. */\n subscribe: (listener: () => void) => () => void;\n}\n\nexport interface ClientContext {\n /** The dev server's base URL, ending in `/`. */\n base: string;\n /** deictic's shadow root, to draw in: neither the page's styles nor the overlay's cross over. */\n root: ShadowRoot;\n /** The server half's `clientOptions`, or nothing. */\n options: unknown;\n /** Another plugin's API in the page, as its `setup` answered it, or nothing when it isn't loaded. */\n use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;\n /** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */\n request: (route: string, init?: RequestInit) => Promise<Response>;\n /** Says a problem of the plugin's own to the dev server, as the server half's `report` does: its `plugin` is this one. */\n report: (problem: Problem) => void;\n /**\n * Opens the popup on an element at a plugin's tab, as its shortcut would, or with `at` on a spot in it: the\n * popup is then beside the spot, which is what's lit, and the tab's context has it. An element rendered again\n * since stands in for one no longer on the page. False when there's no such tab or no such element any more, and\n * while the open popup holds something unsaved, whose button then shakes. Not as `setup` runs, which is before the\n * popup can open.\n */\n open: (plugin: string, element: Element, at?: Point) => boolean;\n /** The tool panel, to add this plugin's tools to. */\n tools: ToolPanel;\n /** What was made from the tool panel and not taken yet. */\n tray: Tray;\n /** The drawer, to add this plugin's section to. */\n drawer: Drawer;\n /**\n * Lights an element on the page as pointing at it does, for something of the overlay's own that stands for it (a\n * task's row in the drawer, while the pointer is on it); none puts the light back as it was.\n */\n light: (element?: Element) => void;\n /**\n * Shows `items` in the lightbox over everything, at `at` (the first by default), stepping between them with\n * ← and →. With `from`, it grows out of that element (the chip clicked) and shrinks back into it on close.\n */\n lightbox: (items: LightboxItem[], options?: LightboxOptions) => { close: () => void };\n}\n\n/** What the lightbox shows: a picture, a page in a frame (a recording's replay), or a sound with its waveform. */\nexport type LightboxItem = {\n /** Its name, over it. */\n title: string;\n /** Buttons beside the name: each closes the lightbox and runs. */\n actions?: LightboxAction[];\n} & ({ kind: 'image'; url: string } | { kind: 'page'; url: string } | { kind: 'audio'; url: string });\n\nexport interface LightboxAction {\n label: string;\n title?: string;\n run: () => void;\n}\n\nexport interface LightboxOptions {\n /** The item it opens at. */\n at?: number;\n /** The element it grows out of, and goes back into. */\n from?: Element;\n}\n\nexport interface PanelContext<Model, Op> extends ClientContext {\n /**\n * The element clicked: the one the source marked, under the pointer or around what is. Back from `away`\n * it may be off the page (`isConnected` is false), where the page moved on without it: the element as it\n * was left, or after a page load an empty one of its tag and mark. `elements` is then empty.\n */\n element: Element;\n /**\n * What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a\n * dependency's, or in an open shadow root, as the popup's own on a page that shows it (`popupIn`).\n */\n pointed?: Element;\n /** The spot in `element` the popup was opened on, where it was (the tool panel's task tool), not the element as a whole. */\n at?: Point;\n /** Every element on the page from the same place in the source, the clicked one among them: the rows of a list. */\n elements: Element[];\n target: Target;\n model: Model;\n /**\n * Applies an op on disk, and reads the model again. Rejects with the server's reason, which the panel also shows.\n * On another element with `on`, whose model is then the one answered: for an op that's about that one.\n */\n apply(op: Op, on?: Target): Promise<Model>;\n close: () => void;\n /**\n * Says there's something here that leaving would lose (words typed, a change tried on the page), and the button\n * that keeps it: a click outside the popup then shakes that button, where it would have closed the popup.\n * `undefined` once there's nothing to lose. Forgotten as the panel unmounts.\n */\n unsaved: (action: HTMLElement | undefined) => void;\n /**\n * Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a\n * pick of another element), and opens it again at this tab on this element. The next mount gets\n * `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why\n * it failed. The state stays in the page, as it is: no need for JSON. It's also kept for the tab's next\n * page, as a structured clone, where it can be one: after a page load, the plugin's `resume` says whether\n * the task carries on, and the popup comes back there.\n */\n away: <T>(state: unknown, task: () => Promise<T>) => void;\n /** Set when this mount is the panel coming back from `away`. */\n resumed?: Resumed;\n}\n\n/** What a panel coming back from `away` gets: the state it kept, and the task's result or problem. */\nexport interface Resumed {\n state: unknown;\n result?: unknown;\n /** Why the task failed: its error's message. */\n problem?: string;\n}\n\nexport interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {\n /** The server half's `name`. */\n name: string;\n /** Shown over the element while its shortcut's keys are held, and atop the panel. */\n label?: string;\n /**\n * Runs once, as the page starts, before any panel opens (a recording starts here). Answers the\n * plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.\n */\n setup?(context: ClientContext): Api;\n /**\n * Asked as a page starts where the page before it left this plugin's panel `away`: the task it left for,\n * where that carries on in this page (a recording does), or nothing where it ended with the page. When it's\n * done the popup opens at this tab with `resumed`, on the element where this page has it and without where not.\n */\n resume?(context: ClientContext): Promise<unknown> | undefined;\n /**\n * What it shows on the page while a shortcut's keys are held, and the page is dimmed to point on: the tasks\n * plugin pins each task where its element is. Answers what takes it away.\n */\n pointing?(context: ClientContext): () => void;\n /** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */\n mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;\n}\n\nexport const defineClientPlugin = <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>): ClientPlugin<Model, Op, Api> => plugin;\n"],"mappings":";;AAqEA,IAAa,UAAb,cAA6B,MAAM;CACxB,OAAO;AAClB;AAgHA,MAAa,gBACX,WACyC;AA8N3C,MAAa,sBAAgD,WAAuE"}
@@ -26,7 +26,12 @@ function run(id, values) {
26
26
  ["deictic.source", (v) => `Source: ${at?.replace(/:\d+$/, "") ?? "?"} ← ${v} (a shared component's change is usually at the next)`],
27
27
  ["deictic.url", (v) => v],
28
28
  ["deictic.viewport", (v) => `Viewport ${v}`],
29
- ["deictic.count", (v) => v === "1" ? void 0 : `${v} elements on the page come from that line`],
29
+ ["deictic.count", (v) => {
30
+ if (v === "1") return void 0;
31
+ const nth = label("deictic.nth");
32
+ const text = label("deictic.text");
33
+ return `${v} elements on the page come from that line${nth === void 0 ? "" : `: it's number ${nth}${text === void 0 ? "" : `, saying "${text}"`}`}`;
34
+ }],
30
35
  ["deictic.point", (v) => `About the spot at x,y ${v} in that element (CSS px from its top left): a screenshot taken as the task was added has it circled`],
31
36
  ["deictic.position", (v) => `In the screenshot at x,y ${v}, ${label("deictic.size") ?? "?"} (CSS px)`]
32
37
  ];
@@ -35,10 +40,14 @@ function run(id, values) {
35
40
  const line = value === void 0 ? void 0 : say(value);
36
41
  if (line !== void 0) console.log(line);
37
42
  }
38
- if (at === void 0) console.log("About the page as a whole: no element was attached, so find it from the words, the page's URL and the screenshot");
43
+ const problem = label("deictic.problem.kind");
44
+ if (problem !== void 0) {
45
+ const plugin = label("deictic.problem.plugin");
46
+ console.log(`A problem deictic ${label("deictic.version") ?? ""} reported${plugin === void 0 ? "" : ` in its ${plugin} plugin`}, not a person's ask`);
47
+ } else if (at === void 0) console.log("About the page as a whole: no element was attached, so find it from the words, the page's URL and the screenshot");
39
48
  for (const line of drawn(root)) console.log(line);
40
49
  const told = (pointed ? where.slice(0, pointed.index) : where).trim();
41
- if (told !== "") console.log(told);
50
+ if (told !== "") console.log(problem === void 0 ? told : `Details:\n${told}`);
42
51
  if (pointed) console.log(`\nPointed at, inside it: ${pointed[1]}\n ${pointed[2]}`);
43
52
  const path = label("deictic.pointed");
44
53
  if (path !== void 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"task.js","names":[],"sources":["../../src/cli/task.ts"],"sourcesContent":["/**\n * `deictic task`: a task, briefly: what was asked, where (and whether that place has moved in the source since), the\n * page, what's attached with the command to look at each, the replies, and the other open tasks about the same page.\n */\nimport { existsSync, mkdirSync, readFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\n\nimport { deicticDirs, download, ME, type Message, read, vbJson } from './board.ts';\n\n/** An actor by the profile its ID ends in (`…+claude`), or the ID of one that writes as itself. */\nconst nameOf = (actor: string) => (actor.includes('+') ? actor.slice(actor.lastIndexOf('+') + 1) : actor);\n\nexport function run(id: string, values: { out?: string }): void {\n const { message: root, replies } = read(id);\n const [asked = '', where = ''] = root.text.split(/\\n---\\n/);\n const label = (key: string) => root.labels[key];\n const at = label('deictic.at');\n\n // Who asked, said as that: the line's state is beside it, and a board's record names no one for a task's end.\n console.log(`#${root.id} ${root.task?.state ?? 'not a task'}, asked by ${root.author?.handle ?? root.by.actor}, ${root.createdAt}`);\n const claim = root.task?.claim;\n if (claim) console.log(`Claimed by ${nameOf(claim.actor)} until ${claim.until}`);\n // A task not over yet has them, as null.\n if (root.task?.result != null) console.log(`Result: ${root.task.result}`);\n if (root.task?.reason != null) console.log(`Reason: ${root.task.reason}`);\n console.log(`\\nAsked:\\n${asked.trim()}\\n`);\n // The part inside the element that was pointed at, where nothing marked it: what the person means.\n const pointed = /\\nPointed at, inside it: `([^`]*)`\\n`{3,}\\w*\\n([\\s\\S]*?)\\n`{3,}/.exec(where);\n // Where, from the labels: the place, the page, and the viewport to look at it in.\n const facts: [string, (v: string) => string | undefined][] = [\n ['deictic.project', (v) => `Project ${v}`],\n ['deictic.at', (v) => `${v} <${label('deictic.tag') ?? '?'}>`],\n // From its own line out: before the label, tasks said it in their text, which is printed below as it is.\n // The first is often a shared component (`ui/label.tsx`), which the task isn't about changing everywhere.\n ['deictic.source', (v) => `Source: ${at?.replace(/:\\d+$/, '') ?? '?'} ← ${v} (a shared component's change is usually at the next)`],\n ['deictic.url', (v) => v],\n ['deictic.viewport', (v) => `Viewport ${v}`],\n ['deictic.count', (v) => (v === '1' ? undefined : `${v} elements on the page come from that line`)],\n [\n 'deictic.point',\n // Circled only in a shot taken as the task went, which no label tells from one drawn on before.\n (v) =>\n `About the spot at x,y ${v} in that element (CSS px from its top left): a screenshot taken as the task was added has it circled`,\n ],\n // A task added before shots were numbered had its one shot's place here.\n ['deictic.position', (v) => `In the screenshot at x,y ${v}, ${label('deictic.size') ?? '?'} (CSS px)`],\n ];\n for (const [key, say] of facts) {\n const value = label(key);\n const line = value === undefined ? undefined : say(value);\n if (line !== undefined) console.log(line);\n }\n if (at === undefined)\n console.log(\"About the page as a whole: no element was attached, so find it from the words, the page's URL and the screenshot\");\n for (const line of drawn(root)) console.log(line);\n // A task added before these were labels says them after its words.\n const told = (pointed ? where.slice(0, pointed.index) : where).trim();\n if (told !== '') console.log(told);\n if (pointed) console.log(`\\nPointed at, inside it: ${pointed[1]}\\n ${pointed[2]}`);\n const path = label('deictic.pointed');\n if (path !== undefined) {\n const file = root.attachments.some((a) => a.name === 'pointed.html') ? 'pointed.html' : 'element.html';\n // Markup no line marks, a dependency's.\n console.log(\n `\\nPointed at, inside it: ${path} (its HTML is in ${file}): what they mean, though no line marks it; find it by its classes`,\n );\n }\n\n if (at !== undefined) placeOf(at, label('deictic.line'));\n const out = values.out === undefined ? undefined : resolve(values.out);\n if (root.attachments.length > 0) console.log('\\nAttached:');\n attachments(root, out, ' ', String(root.id));\n\n if (replies.length > 0) console.log('\\nReplies:');\n for (const r of replies) {\n console.log(` ${r.author?.handle ?? r.by.actor}: ${r.text}`);\n // A reply may attach what a task does: shots, a recording, a voice note.\n for (const line of drawn(r)) console.log(` ${line}`);\n attachments(r, out, ' ');\n }\n // Said once, not as a command per file: most tasks need their shots, and `--out` gets everything at once.\n if (out === undefined && [root, ...replies].some((m) => m.attachments.length > 0))\n console.log(`\\nTo download what's attached: ${ME} task ${root.id} --out <dir>`);\n others(root);\n}\n\n/**\n * What the attached files don't say, from the numbered labels: where the element is in each shot and the notes on it, the\n * notes drawn on the page, and what wasn't kept any more. Where a recording replays, `recording` says.\n */\nfunction drawn({ labels, attachments }: Message): string[] {\n const numbered = (prefix: string) => {\n const out: string[] = [];\n for (let n = 1; labels[`${prefix}.${n}`] !== undefined; n++) out.push(labels[`${prefix}.${n}`]!);\n return out;\n };\n const notes = (prefix: string) => numbered(`${prefix}.note`).map((note) => JSON.stringify(note));\n const lines: string[] = [];\n // `deictic.screenshot.N` is the Nth PNG attached, `deictic.recording.N` the Nth recording.\n for (const [i, { name }] of attachments.filter((a) => a.type === 'image/png').entries()) {\n const shot = `deictic.screenshot.${i + 1}`;\n const position = labels[`${shot}.position`];\n if (position === undefined) continue;\n const said = notes(shot);\n lines.push(\n `${name}: the element at x,y ${position}, ${labels[`${shot}.size`] ?? '?'} (CSS px)${said.length === 0 ? '' : `; notes drawn on it: ${said.join(', ')}`}`,\n );\n }\n // The others it's about, after the one it names first: the Nth element's HTML is `element.N.html`.\n for (const [i, other] of numbered('deictic.also').entries()) {\n const html = attachments.some((a) => a.name === `element.${i + 2}.html`) ? ` (its HTML is in element.${i + 2}.html)` : '';\n lines.push(`Also about ${other}${html}`);\n }\n const onPage = notes('deictic');\n if (onPage.length > 0) lines.push(`Notes drawn on the page: ${onPage.join(', ')}`);\n const dropped = numbered('deictic.dropped');\n if (dropped.length > 0) lines.push(`Not attached, as it wasn't kept any more: ${dropped.join(', ')}`);\n return lines;\n}\n\n/** The place as the task saw it, against the file now: the element's opening tag may have moved or changed. */\nfunction placeOf(at: string, first: string | undefined): void {\n const file = at.replace(/:\\d+:\\d+$/, '');\n const line = Number(at.split(':').at(-2));\n // Marks are from the dev server's root: here, above, or a folder with a .deictic/ of its own.\n const roots = [process.cwd(), ...deicticDirs().map(dirname)];\n const path = roots.map((r) => resolve(r, file)).find((p) => existsSync(p));\n if (path === undefined) {\n console.log(`\\n${file} isn't under ${roots.join(' or ')}: find the dev server's root.`);\n return;\n }\n const lines = readFileSync(path, 'utf8').split('\\n');\n const shown = relative(process.cwd(), path) || path;\n // The tag's first line may follow other code on its line: `const App = () => <h1>`.\n const now = lines[line - 1]?.trim();\n if (first === undefined || now?.includes(first.slice(0, 40))) {\n console.log(`\\nFile: ${shown}:${line}, as the task saw it.`);\n return;\n }\n const moved = lines.findIndex((l) => l.includes(first.slice(0, 40)));\n console.log(\n moved >= 0\n ? `\\nFile: moved to ${shown}:${moved + 1} (the task says line ${line}).`\n : `\\nFile: ${shown}:${line} no longer reads as the task saw it; it was:\\n ${first}`,\n );\n}\n\n/**\n * A message's files, with the command to read a recording or voice clip by, downloaded to `out` where it's given. The\n * task's own are read by its ID (all its voice clips at once); a reply's recording by where it replays, and its voice\n * note by the clip's ID.\n */\nfunction attachments(message: Message, out: string | undefined, indent: string, task?: string): void {\n if (out !== undefined && message.attachments.length > 0) mkdirSync(out, { recursive: true });\n const recordings = message.attachments.filter((a) => a.name.startsWith('recording-'));\n for (const a of message.attachments) {\n const kb = `${Math.round(a.size / 1024)} KB`;\n if (out !== undefined) download(a, join(out, a.name));\n const saved = out === undefined ? '' : ` → ${relative(process.cwd(), join(out, a.name))}`;\n if (a.name.startsWith('recording-')) {\n const n = recordings.indexOf(a) + 1;\n const ref = task === undefined ? message.labels[`deictic.recording.${n}.replay`] : `${task}${n > 1 ? ` --nth ${n}` : ''}`;\n console.log(`${indent}${a.name} (${kb})${saved}`);\n if (ref !== undefined) console.log(`${indent} ${ME} recording ${ref} (timeline), ${ME} frame ${ref} (frames)`);\n } else if (a.name.startsWith('voice-')) {\n console.log(`${indent}${a.name} (${kb}), a voice clip${saved}`);\n if (task === undefined) console.log(`${indent} ${ME} voice ${/^voice-(.+)\\.\\w+$/.exec(a.name)?.[1] ?? a.id} (speech)`);\n } else if (a.name === 'element.html') {\n console.log(`${indent}${a.name} (${kb}), the element's HTML as it rendered, if you need it${saved}`);\n } else {\n console.log(`${indent}${a.name} (${kb})${saved}`);\n }\n }\n if (task !== undefined && message.attachments.some((a) => a.name.startsWith('voice-')))\n console.log(`${indent}${ME} voice ${task} (speech in every clip), ${ME} transcribe ${task} (the words)`);\n}\n\n/** The other open tasks about the same page, of the same project: left a minute apart, they're often one change. */\nfunction others(root: Message): void {\n const page = root.labels['deictic.page'];\n if (page === undefined) return;\n const project = root.labels['deictic.project'];\n const labels = [`deictic.page=${page}`, ...(project === undefined ? [] : [`deictic.project=${project}`])];\n const { tasks } = vbJson<{ tasks: { message: Message }[] }>(['tasks', root.channel, ...labels.flatMap((l) => ['--label', l])]);\n const rest = tasks.map((t) => t.message).filter((m) => m.id !== root.id);\n if (rest.length === 0) return;\n console.log(\n `\\n${rest.length} other open task${rest.length === 1 ? '' : 's'} on ${page}: read them before you start, they may be one change.`,\n );\n for (const m of rest) {\n const title = (m.text.split(/\\n---\\n/)[0] ?? '').split('\\n')[0]?.slice(0, 100);\n console.log(` #${m.id} ${m.task?.state ?? ''}, ${m.labels['deictic.at'] ?? '?'}: ${title}`);\n }\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,UAAU,UAAmB,MAAM,SAAS,GAAG,IAAI,MAAM,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI;AAEnG,SAAgB,IAAI,IAAY,QAAgC;CAC9D,MAAM,EAAE,SAAS,MAAM,YAAY,KAAK,EAAE;CAC1C,MAAM,CAAC,QAAQ,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,SAAS;CAC1D,MAAM,SAAS,QAAgB,KAAK,OAAO;CAC3C,MAAM,KAAK,MAAM,YAAY;CAG7B,QAAQ,IAAI,IAAI,KAAK,GAAG,GAAG,KAAK,MAAM,SAAS,aAAa,aAAa,KAAK,QAAQ,UAAU,KAAK,GAAG,MAAM,IAAI,KAAK,WAAW;CAClI,MAAM,QAAQ,KAAK,MAAM;CACzB,IAAI,OAAO,QAAQ,IAAI,cAAc,OAAO,MAAM,KAAK,EAAE,SAAS,MAAM,OAAO;CAE/E,IAAI,KAAK,MAAM,UAAU,MAAM,QAAQ,IAAI,WAAW,KAAK,KAAK,QAAQ;CACxE,IAAI,KAAK,MAAM,UAAU,MAAM,QAAQ,IAAI,WAAW,KAAK,KAAK,QAAQ;CACxE,QAAQ,IAAI,aAAa,MAAM,KAAK,EAAE,GAAG;CAEzC,MAAM,UAAU,kEAAkE,KAAK,KAAK;CAE5F,MAAM,QAAuD;EAC3D,CAAC,oBAAoB,MAAM,WAAW,GAAG;EACzC,CAAC,eAAe,MAAM,GAAG,EAAE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C7E,QAAQ,IAAI,MAAM,EAAE,GAAG,GAAG,EAAE,MAAM,SAAS,GAAG,IAAI,EAAE,OAAO,iBAAiB,IAAI,IAAI,OAAO;CAC7F;AACF"}
1
+ {"version":3,"file":"task.js","names":[],"sources":["../../src/cli/task.ts"],"sourcesContent":["/**\n * `deictic task`: a task, briefly: what was asked, where (and whether that place has moved in the source since), the\n * page, what's attached with the command to look at each, the replies, and the other open tasks about the same page.\n */\nimport { existsSync, mkdirSync, readFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\n\nimport { deicticDirs, download, ME, type Message, read, vbJson } from './board.ts';\n\n/** An actor by the profile its ID ends in (`…+claude`), or the ID of one that writes as itself. */\nconst nameOf = (actor: string) => (actor.includes('+') ? actor.slice(actor.lastIndexOf('+') + 1) : actor);\n\nexport function run(id: string, values: { out?: string }): void {\n const { message: root, replies } = read(id);\n const [asked = '', where = ''] = root.text.split(/\\n---\\n/);\n const label = (key: string) => root.labels[key];\n const at = label('deictic.at');\n\n // Who asked, said as that: the line's state is beside it, and a board's record names no one for a task's end.\n console.log(`#${root.id} ${root.task?.state ?? 'not a task'}, asked by ${root.author?.handle ?? root.by.actor}, ${root.createdAt}`);\n const claim = root.task?.claim;\n if (claim) console.log(`Claimed by ${nameOf(claim.actor)} until ${claim.until}`);\n // A task not over yet has them, as null.\n if (root.task?.result != null) console.log(`Result: ${root.task.result}`);\n if (root.task?.reason != null) console.log(`Reason: ${root.task.reason}`);\n console.log(`\\nAsked:\\n${asked.trim()}\\n`);\n // The part inside the element that was pointed at, where nothing marked it: what the person means.\n const pointed = /\\nPointed at, inside it: `([^`]*)`\\n`{3,}\\w*\\n([\\s\\S]*?)\\n`{3,}/.exec(where);\n // Where, from the labels: the place, the page, and the viewport to look at it in.\n const facts: [string, (v: string) => string | undefined][] = [\n ['deictic.project', (v) => `Project ${v}`],\n ['deictic.at', (v) => `${v} <${label('deictic.tag') ?? '?'}>`],\n // From its own line out: before the label, tasks said it in their text, which is printed below as it is.\n // The first is often a shared component (`ui/label.tsx`), which the task isn't about changing everywhere.\n ['deictic.source', (v) => `Source: ${at?.replace(/:\\d+$/, '') ?? '?'} ← ${v} (a shared component's change is usually at the next)`],\n ['deictic.url', (v) => v],\n ['deictic.viewport', (v) => `Viewport ${v}`],\n [\n 'deictic.count',\n (v) => {\n if (v === '1') return undefined;\n const nth = label('deictic.nth');\n const text = label('deictic.text');\n const which = nth === undefined ? '' : `: it's number ${nth}${text === undefined ? '' : `, saying \"${text}\"`}`;\n return `${v} elements on the page come from that line${which}`;\n },\n ],\n [\n 'deictic.point',\n // Circled only in a shot taken as the task went, which no label tells from one drawn on before.\n (v) =>\n `About the spot at x,y ${v} in that element (CSS px from its top left): a screenshot taken as the task was added has it circled`,\n ],\n // A task added before shots were numbered had its one shot's place here.\n ['deictic.position', (v) => `In the screenshot at x,y ${v}, ${label('deictic.size') ?? '?'} (CSS px)`],\n ];\n for (const [key, say] of facts) {\n const value = label(key);\n const line = value === undefined ? undefined : say(value);\n if (line !== undefined) console.log(line);\n }\n const problem = label('deictic.problem.kind');\n if (problem !== undefined) {\n const plugin = label('deictic.problem.plugin');\n console.log(\n `A problem deictic ${label('deictic.version') ?? ''} reported${plugin === undefined ? '' : ` in its ${plugin} plugin`}, not a person's ask`,\n );\n } else if (at === undefined) {\n console.log(\"About the page as a whole: no element was attached, so find it from the words, the page's URL and the screenshot\");\n }\n for (const line of drawn(root)) console.log(line);\n // A task added before these were labels says them after its words; a problem, its details.\n const told = (pointed ? where.slice(0, pointed.index) : where).trim();\n if (told !== '') console.log(problem === undefined ? told : `Details:\\n${told}`);\n if (pointed) console.log(`\\nPointed at, inside it: ${pointed[1]}\\n ${pointed[2]}`);\n const path = label('deictic.pointed');\n if (path !== undefined) {\n const file = root.attachments.some((a) => a.name === 'pointed.html') ? 'pointed.html' : 'element.html';\n // Markup no line marks, a dependency's.\n console.log(\n `\\nPointed at, inside it: ${path} (its HTML is in ${file}): what they mean, though no line marks it; find it by its classes`,\n );\n }\n\n if (at !== undefined) placeOf(at, label('deictic.line'));\n const out = values.out === undefined ? undefined : resolve(values.out);\n if (root.attachments.length > 0) console.log('\\nAttached:');\n attachments(root, out, ' ', String(root.id));\n\n if (replies.length > 0) console.log('\\nReplies:');\n for (const r of replies) {\n console.log(` ${r.author?.handle ?? r.by.actor}: ${r.text}`);\n // A reply may attach what a task does: shots, a recording, a voice note.\n for (const line of drawn(r)) console.log(` ${line}`);\n attachments(r, out, ' ');\n }\n // Said once, not as a command per file: most tasks need their shots, and `--out` gets everything at once.\n if (out === undefined && [root, ...replies].some((m) => m.attachments.length > 0))\n console.log(`\\nTo download what's attached: ${ME} task ${root.id} --out <dir>`);\n others(root);\n}\n\n/**\n * What the attached files don't say, from the numbered labels: where the element is in each shot and the notes on it, the\n * notes drawn on the page, and what wasn't kept any more. Where a recording replays, `recording` says.\n */\nfunction drawn({ labels, attachments }: Message): string[] {\n const numbered = (prefix: string) => {\n const out: string[] = [];\n for (let n = 1; labels[`${prefix}.${n}`] !== undefined; n++) out.push(labels[`${prefix}.${n}`]!);\n return out;\n };\n const notes = (prefix: string) => numbered(`${prefix}.note`).map((note) => JSON.stringify(note));\n const lines: string[] = [];\n // `deictic.screenshot.N` is the Nth PNG attached, `deictic.recording.N` the Nth recording.\n for (const [i, { name }] of attachments.filter((a) => a.type === 'image/png').entries()) {\n const shot = `deictic.screenshot.${i + 1}`;\n const position = labels[`${shot}.position`];\n if (position === undefined) continue;\n const said = notes(shot);\n lines.push(\n `${name}: the element at x,y ${position}, ${labels[`${shot}.size`] ?? '?'} (CSS px)${said.length === 0 ? '' : `; notes drawn on it: ${said.join(', ')}`}`,\n );\n }\n // The others it's about, after the one it names first: the Nth element's HTML is `element.N.html`.\n for (const [i, other] of numbered('deictic.also').entries()) {\n const html = attachments.some((a) => a.name === `element.${i + 2}.html`) ? ` (its HTML is in element.${i + 2}.html)` : '';\n lines.push(`Also about ${other}${html}`);\n }\n const onPage = notes('deictic');\n if (onPage.length > 0) lines.push(`Notes drawn on the page: ${onPage.join(', ')}`);\n const dropped = numbered('deictic.dropped');\n if (dropped.length > 0) lines.push(`Not attached, as it wasn't kept any more: ${dropped.join(', ')}`);\n return lines;\n}\n\n/** The place as the task saw it, against the file now: the element's opening tag may have moved or changed. */\nfunction placeOf(at: string, first: string | undefined): void {\n const file = at.replace(/:\\d+:\\d+$/, '');\n const line = Number(at.split(':').at(-2));\n // Marks are from the dev server's root: here, above, or a folder with a .deictic/ of its own.\n const roots = [process.cwd(), ...deicticDirs().map(dirname)];\n const path = roots.map((r) => resolve(r, file)).find((p) => existsSync(p));\n if (path === undefined) {\n console.log(`\\n${file} isn't under ${roots.join(' or ')}: find the dev server's root.`);\n return;\n }\n const lines = readFileSync(path, 'utf8').split('\\n');\n const shown = relative(process.cwd(), path) || path;\n // The tag's first line may follow other code on its line: `const App = () => <h1>`.\n const now = lines[line - 1]?.trim();\n if (first === undefined || now?.includes(first.slice(0, 40))) {\n console.log(`\\nFile: ${shown}:${line}, as the task saw it.`);\n return;\n }\n const moved = lines.findIndex((l) => l.includes(first.slice(0, 40)));\n console.log(\n moved >= 0\n ? `\\nFile: moved to ${shown}:${moved + 1} (the task says line ${line}).`\n : `\\nFile: ${shown}:${line} no longer reads as the task saw it; it was:\\n ${first}`,\n );\n}\n\n/**\n * A message's files, with the command to read a recording or voice clip by, downloaded to `out` where it's given. The\n * task's own are read by its ID (all its voice clips at once); a reply's recording by where it replays, and its voice\n * note by the clip's ID.\n */\nfunction attachments(message: Message, out: string | undefined, indent: string, task?: string): void {\n if (out !== undefined && message.attachments.length > 0) mkdirSync(out, { recursive: true });\n const recordings = message.attachments.filter((a) => a.name.startsWith('recording-'));\n for (const a of message.attachments) {\n const kb = `${Math.round(a.size / 1024)} KB`;\n if (out !== undefined) download(a, join(out, a.name));\n const saved = out === undefined ? '' : ` → ${relative(process.cwd(), join(out, a.name))}`;\n if (a.name.startsWith('recording-')) {\n const n = recordings.indexOf(a) + 1;\n const ref = task === undefined ? message.labels[`deictic.recording.${n}.replay`] : `${task}${n > 1 ? ` --nth ${n}` : ''}`;\n console.log(`${indent}${a.name} (${kb})${saved}`);\n if (ref !== undefined) console.log(`${indent} ${ME} recording ${ref} (timeline), ${ME} frame ${ref} (frames)`);\n } else if (a.name.startsWith('voice-')) {\n console.log(`${indent}${a.name} (${kb}), a voice clip${saved}`);\n if (task === undefined) console.log(`${indent} ${ME} voice ${/^voice-(.+)\\.\\w+$/.exec(a.name)?.[1] ?? a.id} (speech)`);\n } else if (a.name === 'element.html') {\n console.log(`${indent}${a.name} (${kb}), the element's HTML as it rendered, if you need it${saved}`);\n } else {\n console.log(`${indent}${a.name} (${kb})${saved}`);\n }\n }\n if (task !== undefined && message.attachments.some((a) => a.name.startsWith('voice-')))\n console.log(`${indent}${ME} voice ${task} (speech in every clip), ${ME} transcribe ${task} (the words)`);\n}\n\n/** The other open tasks about the same page, of the same project: left a minute apart, they're often one change. */\nfunction others(root: Message): void {\n const page = root.labels['deictic.page'];\n if (page === undefined) return;\n const project = root.labels['deictic.project'];\n const labels = [`deictic.page=${page}`, ...(project === undefined ? [] : [`deictic.project=${project}`])];\n const { tasks } = vbJson<{ tasks: { message: Message }[] }>(['tasks', root.channel, ...labels.flatMap((l) => ['--label', l])]);\n const rest = tasks.map((t) => t.message).filter((m) => m.id !== root.id);\n if (rest.length === 0) return;\n console.log(\n `\\n${rest.length} other open task${rest.length === 1 ? '' : 's'} on ${page}: read them before you start, they may be one change.`,\n );\n for (const m of rest) {\n const title = (m.text.split(/\\n---\\n/)[0] ?? '').split('\\n')[0]?.slice(0, 100);\n console.log(` #${m.id} ${m.task?.state ?? ''}, ${m.labels['deictic.at'] ?? '?'}: ${title}`);\n }\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,UAAU,UAAmB,MAAM,SAAS,GAAG,IAAI,MAAM,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI;AAEnG,SAAgB,IAAI,IAAY,QAAgC;CAC9D,MAAM,EAAE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E,OAAO,iBAAiB,IAAI,IAAI,OAAO;CAC7F;AACF"}
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { join, relative } from "node:path";
3
+ import { i as version, t as bugs } from "./package.js";
3
4
  import { r as definePlugin, t as Refusal } from "./src.js";
4
5
  import { r as localBoard } from "./local.js";
5
6
  import { n as watchersOf } from "./watchers.js";
@@ -23,9 +24,14 @@ const OVER = 10;
23
24
  /** How many tasks a page is asked about at most: past that it has more pins than anyone reads. */
24
25
  const PINNED = 500;
25
26
  const AT = "deictic.at";
27
+ /** A problem's key, on the task that tells of it: one task per problem while it's open. */
28
+ const PROBLEM = "deictic.problem";
26
29
  const FILE = "deictic.file";
27
30
  /** `x,y`: the spot in the element a task is about, in CSS pixels from the element's top left. */
28
31
  const POINT = "deictic.point";
32
+ /** Which of several elements from one place it's about: `deictic.nth` from 1, `deictic.text` its text. */
33
+ const NTH = "deictic.nth";
34
+ const TEXT = "deictic.text";
29
35
  /** What parts what was typed from the rest of a task's text. */
30
36
  const REST = "\n---\n";
31
37
  const OPEN = /* @__PURE__ */ new Set([
@@ -72,7 +78,7 @@ function tasks(options = {}) {
72
78
  * nothing else on the board is its to change, nor a task someone has taken up.
73
79
  */
74
80
  /** One of deictic's: it has a place, or the page it's about where no element was attached. */
75
- const ours = (message) => message.labels[AT] !== void 0 || message.labels["deictic.page"] !== void 0;
81
+ const ours = (message) => message.labels[AT] !== void 0 || message.labels["deictic.page"] !== void 0 || message.labels[PROBLEM] !== void 0;
76
82
  const openTask = async (team, id, verb) => {
77
83
  const { message } = await team.thread(id);
78
84
  if (message.channel !== channel || !ours(message)) throw new Refusal(`#${id} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);
@@ -119,6 +125,12 @@ function tasks(options = {}) {
119
125
  x: Number(x),
120
126
  y: Number(y)
121
127
  };
128
+ const nth = Number(message.labels[NTH]);
129
+ const said = message.labels[TEXT];
130
+ const which = Number.isInteger(nth) && nth > 0 ? {
131
+ nth,
132
+ ...said === void 0 ? {} : { text: said }
133
+ } : void 0;
122
134
  return {
123
135
  id: message.id,
124
136
  title: text.split("\n", 1)[0],
@@ -128,12 +140,14 @@ function tasks(options = {}) {
128
140
  open: OPEN.has(state),
129
141
  ...to === void 0 ? {} : { link: to },
130
142
  ...dropped === void 0 ? {} : { dropped },
131
- ...point === void 0 ? {} : { point }
143
+ ...point === void 0 ? {} : { point },
144
+ ...which === void 0 ? {} : { which }
132
145
  };
133
146
  };
134
147
  const listedOf = ({ message, replies, last }, actors, page) => {
135
148
  const { task, labels } = message;
136
149
  const said = task?.blocked?.reason ?? task?.result ?? task?.reason ?? void 0;
150
+ const problem = labels[`${PROBLEM}.kind`];
137
151
  return {
138
152
  ...taskOf(message, actors, page),
139
153
  ...labels[AT] === void 0 ? {} : { place: labels[AT] },
@@ -141,7 +155,8 @@ function tasks(options = {}) {
141
155
  ...labels["deictic.page"] === void 0 ? {} : { page: labels["deictic.page"] },
142
156
  replies,
143
157
  ...last === null ? {} : { last: last.id },
144
- ...said === void 0 || said === "" ? {} : { said: clip(said, 2e3) }
158
+ ...said === void 0 || said === "" ? {} : { said: clip(said, 2e3) },
159
+ ...problem === "setup" || problem === "bug" ? { problem } : {}
145
160
  };
146
161
  };
147
162
  /**
@@ -445,10 +460,41 @@ function tasks(options = {}) {
445
460
  await cancel(record.id, "deleted in deictic");
446
461
  return record;
447
462
  }),
448
- describe: (op) => `task "${clip(wordsOf(op).split("\n", 1)[0], 60)}"`
463
+ describe: (op) => `task "${clip(wordsOf(op).split("\n", 1)[0], 60)}"`,
464
+ problem: async (problem) => {
465
+ if (options.problems === false) return;
466
+ const key = clip(problem.key, LABEL);
467
+ if ((await (await boardOf()).tasks.list({
468
+ channel,
469
+ label: { [PROBLEM]: key },
470
+ limit: 1
471
+ })).tasks.length > 0) return;
472
+ await create({
473
+ channel,
474
+ text: clip(problemText(problem), 1e4),
475
+ labels: {
476
+ ...options.labels,
477
+ ...project === void 0 ? {} : { "deictic.project": clip(project, LABEL) },
478
+ [PROBLEM]: key,
479
+ [`${PROBLEM}.kind`]: problem.kind,
480
+ ...problem.plugin === void 0 ? {} : { [`${PROBLEM}.plugin`]: clip(problem.plugin, LABEL) },
481
+ "deictic.version": version
482
+ }
483
+ });
484
+ }
449
485
  });
450
486
  }
451
487
  /**
488
+ * A problem as a task says it: what went wrong and what to do, and after the `---` its details, which `deictic task`
489
+ * prints and the drawer leaves out.
490
+ */
491
+ function problemText({ kind, message, details, plugin }) {
492
+ const whose = plugin === void 0 ? "deictic" : `deictic's ${plugin} plugin`;
493
+ const todo = kind === "setup" ? `Reported by ${whose}, about the project's setup: fix it as it says, then restart the dev server and check it's gone.` : `A bug in ${whose} (${version}), not in this project: don't change it where it's installed. Tell the person, with the details, so they can report it (deictic's own at ${bugs.url}), and complete the task.`;
494
+ const more = details === void 0 ? "" : `${REST}\`\`\`\n${details}\n\`\`\``;
495
+ return `${message[0].toUpperCase()}${message.slice(1)}\n\n${todo}${more}`;
496
+ }
497
+ /**
452
498
  * The channel's page on a board `vb serve` runs on this machine, which serves its pages beside its API:
453
499
  * `/api/board` there, `/c/<channel>` beside it. Nothing for any other board.
454
500
  */
@@ -567,6 +613,8 @@ function labelsOf(source, target, op) {
567
613
  ...page,
568
614
  "deictic.count": String(op.count),
569
615
  ...op.point === void 0 ? {} : { [POINT]: `${Math.round(op.point.x)},${Math.round(op.point.y)}` },
616
+ ...op.which === void 0 ? {} : { [NTH]: String(op.which.nth) },
617
+ ...op.which?.text === void 0 ? {} : { [TEXT]: clip(op.which.text, LABEL) },
570
618
  ...sourceOf(op.chain ?? [])
571
619
  };
572
620
  }