deictic 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/annotations/client.d.ts +4 -0
- package/dist/annotations/client.d.ts.map +1 -0
- package/dist/annotations/client.js +497 -0
- package/dist/annotations/client.js.map +1 -0
- package/dist/annotations/index.d.ts +110 -0
- package/dist/annotations/index.d.ts.map +1 -0
- package/dist/annotations/index.js +22 -0
- package/dist/annotations/index.js.map +1 -0
- package/dist/astro.d.ts +29 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +24 -0
- package/dist/astro.js.map +1 -0
- package/dist/bun.d.ts +12 -0
- package/dist/bun.d.ts.map +1 -0
- package/dist/bun.js +67 -0
- package/dist/bun.js.map +1 -0
- package/dist/client/index.d.ts +95 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1333 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +15 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +17 -0
- package/dist/loader.js.map +1 -0
- package/dist/next.d.ts +17 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +150 -0
- package/dist/next.js.map +1 -0
- package/dist/recommended/index.d.ts +25 -0
- package/dist/recommended/index.d.ts.map +1 -0
- package/dist/recommended/index.js +19 -0
- package/dist/recommended/index.js.map +1 -0
- package/dist/recordings/client.d.ts +4 -0
- package/dist/recordings/client.d.ts.map +1 -0
- package/dist/recordings/client.js +376 -0
- package/dist/recordings/client.js.map +1 -0
- package/dist/recordings/index.d.ts +2 -0
- package/dist/recordings/index.js +3 -0
- package/dist/screenshots/client.d.ts +23 -0
- package/dist/screenshots/client.d.ts.map +1 -0
- package/dist/screenshots/client.js +76 -0
- package/dist/screenshots/client.js.map +1 -0
- package/dist/screenshots/dom.d.ts +4 -0
- package/dist/screenshots/dom.d.ts.map +1 -0
- package/dist/screenshots/dom.js +92 -0
- package/dist/screenshots/dom.js.map +1 -0
- package/dist/screenshots/index.d.ts +2 -0
- package/dist/screenshots/index.js +98 -0
- package/dist/screenshots/index.js.map +1 -0
- package/dist/screenshots/rrweb.d.ts +9 -0
- package/dist/screenshots/rrweb.d.ts.map +1 -0
- package/dist/screenshots/rrweb.js +60 -0
- package/dist/screenshots/rrweb.js.map +1 -0
- package/dist/shared/endpoints.js +354 -0
- package/dist/shared/endpoints.js.map +1 -0
- package/dist/shared/index.d.ts +226 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index2.d.ts +98 -0
- package/dist/shared/index2.d.ts.map +1 -0
- package/dist/shared/index3.d.ts +86 -0
- package/dist/shared/index3.d.ts.map +1 -0
- package/dist/shared/index4.d.ts +184 -0
- package/dist/shared/index4.d.ts.map +1 -0
- package/dist/shared/index5.d.ts +70 -0
- package/dist/shared/index5.d.ts.map +1 -0
- package/dist/shared/integration.d.ts +20 -0
- package/dist/shared/integration.d.ts.map +1 -0
- package/dist/shared/integration.js +279 -0
- package/dist/shared/integration.js.map +1 -0
- package/dist/shared/kept.js +23 -0
- package/dist/shared/kept.js.map +1 -0
- package/dist/shared/marks.js +14 -0
- package/dist/shared/marks.js.map +1 -0
- package/dist/shared/playwright.js +105 -0
- package/dist/shared/playwright.js.map +1 -0
- package/dist/shared/recordings.js +246 -0
- package/dist/shared/recordings.js.map +1 -0
- package/dist/shared/shortcut.js +63 -0
- package/dist/shared/shortcut.js.map +1 -0
- package/dist/shared/tasks.js +521 -0
- package/dist/shared/tasks.js.map +1 -0
- package/dist/shared/waveform.js +93 -0
- package/dist/shared/waveform.js.map +1 -0
- package/dist/tailwind/client.d.ts +4 -0
- package/dist/tailwind/client.d.ts.map +1 -0
- package/dist/tailwind/client.js +613 -0
- package/dist/tailwind/client.js.map +1 -0
- package/dist/tailwind/index.d.ts +2 -0
- package/dist/tailwind/index.js +557 -0
- package/dist/tailwind/index.js.map +1 -0
- package/dist/tasks/client.d.ts +6 -0
- package/dist/tasks/client.d.ts.map +1 -0
- package/dist/tasks/client.js +642 -0
- package/dist/tasks/client.js.map +1 -0
- package/dist/tasks/index.d.ts +2 -0
- package/dist/tasks/index.js +1 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +61 -0
- package/dist/vite.js.map +1 -0
- package/dist/voice/client.d.ts +4 -0
- package/dist/voice/client.d.ts.map +1 -0
- package/dist/voice/client.js +66 -0
- package/dist/voice/client.js.map +1 -0
- package/dist/voice/index.d.ts +47 -0
- package/dist/voice/index.d.ts.map +1 -0
- package/dist/voice/index.js +74 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/webpack.d.ts +50 -0
- package/dist/webpack.d.ts.map +1 -0
- package/dist/webpack.js +78 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +307 -7
- package/skills/deictic/SKILL.md +47 -0
- package/skills/deictic/references/install.md +96 -0
- package/skills/deictic/references/recordings.md +83 -0
- package/skills/deictic/references/tasks.md +79 -0
- package/skills/deictic/references/watch.md +43 -0
- package/skills/deictic/scripts/frame.mjs +62 -0
- package/skills/deictic/scripts/lib.mjs +211 -0
- package/skills/deictic/scripts/recording.mjs +186 -0
- package/skills/deictic/scripts/task.mjs +84 -0
- package/skills/deictic/scripts/transcribe.mjs +93 -0
- package/skills/deictic/scripts/voice.mjs +50 -0
- package/skills/deictic/scripts/watch.mjs +51 -0
- package/src/astro.ts +34 -0
- package/src/bun.ts +79 -0
- package/src/client/index.ts +846 -0
- package/src/client/lightbox.ts +256 -0
- package/src/client/style.ts +243 -0
- package/src/client/tooltip.ts +78 -0
- package/src/client/waveform.ts +98 -0
- package/src/index.ts +247 -0
- package/src/loader.ts +28 -0
- package/src/next.ts +133 -0
- package/src/plugins/annotations/client.ts +301 -0
- package/src/plugins/annotations/draw.ts +169 -0
- package/src/plugins/annotations/index.ts +105 -0
- package/src/plugins/annotations/svg.ts +61 -0
- package/src/plugins/recommended/index.ts +35 -0
- package/src/plugins/recordings/client.ts +316 -0
- package/src/plugins/recordings/index.ts +175 -0
- package/src/plugins/recordings/marks.ts +11 -0
- package/src/plugins/recordings/ours.ts +70 -0
- package/src/plugins/recordings/replay.ts +165 -0
- package/src/plugins/screenshots/client.ts +64 -0
- package/src/plugins/screenshots/dom.ts +79 -0
- package/src/plugins/screenshots/index.ts +194 -0
- package/src/plugins/screenshots/playwright.ts +119 -0
- package/src/plugins/screenshots/rrweb.ts +45 -0
- package/src/plugins/tailwind/catalog.ts +396 -0
- package/src/plugins/tailwind/client.ts +669 -0
- package/src/plugins/tailwind/index.ts +267 -0
- package/src/plugins/tasks/client.ts +622 -0
- package/src/plugins/tasks/index.ts +557 -0
- package/src/plugins/tasks/local.ts +170 -0
- package/src/plugins/voice/client.ts +58 -0
- package/src/plugins/voice/index.ts +114 -0
- package/src/shortcut.ts +83 -0
- package/src/tools/astro.ts +81 -0
- package/src/tools/editor.ts +22 -0
- package/src/tools/endpoints.ts +163 -0
- package/src/tools/history.ts +203 -0
- package/src/tools/integration.ts +108 -0
- package/src/tools/kept.ts +21 -0
- package/src/tools/locate.ts +94 -0
- package/src/tools/plugins.ts +41 -0
- package/src/tools/source.ts +72 -0
- package/src/vite.ts +81 -0
- package/src/webpack.ts +107 -0
- package/index.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.js","names":[],"sources":["../../src/tools/source.ts","../../src/tools/history.ts","../../src/tools/endpoints.ts"],"sourcesContent":["/**\n * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute\n * points at. Files are only ever read and written under the project's root, outside `node_modules`.\n */\nimport { readFileSync } from 'node:fs';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nimport { Refusal, type Source, type Target, type TextEdit } from '#src/index.ts';\n\nimport { ASTRO, parseAstro, type Parsed } from './astro.ts';\nimport { isHost, lineStarts, offsetOf, openingsIn, parse } from './locate.ts';\n\n/** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */\nexport function resolveFile(root: string, file: string): string {\n const path = resolve(root, file);\n const from = relative(root, path);\n // `relative` gives an absolute path for another drive.\n if (from === '' || from.startsWith('..') || isAbsolute(from) || from.split(sep).includes('node_modules'))\n throw new Refusal(`${file} is not a file of this project's own`);\n return path;\n}\n\nexport function readSource(root: string, file: string): string {\n try {\n return readFileSync(resolveFile(root, file), 'utf8');\n } catch (e) {\n if (e instanceof Refusal) throw e;\n throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });\n }\n}\n\n/** The target's file and element, as they are on disk now. */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const offset = offsetOf(lineStarts(code), line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const element = elements.find((el) => el.start === offset && isHost(el));\n if (element === undefined || (element.name.type === 'JSXIdentifier' && element.name.name !== target.tag))\n throw new Refusal(`no <${target.tag}> at ${file}:${line}:${column} any more: the file changed since the page loaded, so reload it`);\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\nfunction jsx(file: string, code: string): Parsed {\n const { program, errors } = parse(file, code);\n if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);\n return { program, elements: openingsIn(program) };\n}\n\nfunction astro(root: string, file: string, code: string): Parsed {\n const parsed = parseAstro(root, code);\n if ('problem' in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);\n return parsed;\n}\n\n/** Each file's text after its edits, which must not overlap. */\nexport function applyEdits(source: Source, edits: TextEdit[]): Map<string, string> {\n const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);\n const out = new Map<string, string>();\n for (const [file, list] of byFile) {\n const sorted = list.toSorted((a, b) => b.start - a.start);\n let code = file === source.file ? source.code : source.read(file);\n let floor = Infinity;\n for (const edit of sorted) {\n if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);\n code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);\n floor = edit.start;\n }\n out.set(file, code);\n }\n return out;\n}\n","/**\n * Every change deictic made, to undo and redo. A change to files holds each file's whole text\n * before and after: source files are small, and the texts make undo exact without a diff to go stale.\n * A change a plugin made itself (`Done`) holds the plugin's name and its record, and undoing it is the\n * plugin's `undo`.\n *\n * Each change has a scope, the plugin and the element it was made on, and the popup undoes and redoes\n * within its own: the latest change of this tab on this element, not the latest of all. So a change\n * is taken back out of order, with later ones to the same file still in it. Then only the lines the\n * change wrote go back to what they were, where they're still in the file as it wrote them, once.\n *\n * Anything else is refused, not merged: a file whose lines were edited since has the editor's own undo\n * for it; and a redo likewise. A plugin's undo refuses on its own terms. Kept under `.deictic`, so it\n * outlives a restart of the dev server and stays out of git.\n */\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { Refusal, type ServerPlugin } from '#src/index.ts';\n\nimport { keptIn } from './kept.ts';\nimport { resolveFile } from './source.ts';\n\nexport interface FileChange {\n file: string;\n /** The text before, or nothing for a file the change made. */\n before: string | null;\n after: string;\n}\n\n/** Whose a change is: the plugin whose tab made it, and the element it was open on, as `file:line:column`. */\nexport interface Scope {\n plugin: string;\n target: string;\n}\n\ninterface Base {\n id: number;\n at: string;\n label: string;\n /** None on a change made without one, which only an undo of the whole history reaches. */\n scope?: Scope;\n}\n\nexport type Change = Base & ({ files: FileChange[] } | { plugin: string; record: unknown });\n\n/** A change as the page lists it. `files` is empty for one a plugin made itself. */\nexport interface Summary {\n id: number;\n at: string;\n label: string;\n files: string[];\n}\n\nexport interface HistoryOptions {\n /** Whose `undo` and `redo` take back the changes they made themselves. */\n plugins?: ServerPlugin[];\n store?: string;\n}\n\nconst LIMIT = 200;\n\n/** Whether a change is in a scope: any is in none. */\nconst within = (scope: Scope | undefined) => (c: Change) =>\n scope === undefined || (c.scope?.plugin === scope.plugin && c.scope.target === scope.target);\n\nconst summary = (c: Change): Summary => ({ id: c.id, at: c.at, label: c.label, files: 'files' in c ? c.files.map((f) => f.file) : [] });\n\nexport class History {\n #done: Change[] = [];\n #undone: Change[] = [];\n readonly #root: string;\n readonly #store: string;\n readonly #plugins: Map<string, ServerPlugin>;\n\n constructor(root: string, { plugins = [], store = keptIn(root, 'history.json') }: HistoryOptions = {}) {\n this.#root = root;\n this.#store = store;\n this.#plugins = new Map(plugins.map((p) => [p.name, p]));\n if (!existsSync(store)) return;\n try {\n ({ done: this.#done, undone: this.#undone } = JSON.parse(readFileSync(store, 'utf8')) as { done: Change[]; undone: Change[] });\n } catch {\n // A history that doesn't read is one we start over, not one to stop the dev server for.\n }\n }\n\n /** Writes each file's new text and records it as one change. A redo after it, in its scope, is gone, as in any editor. */\n commit(label: string, texts: Map<string, string>, scope?: Scope): Summary {\n const files: FileChange[] = [];\n for (const [file, after] of texts) {\n const path = resolveFile(this.#root, file);\n const before = existsSync(path) ? readFileSync(path, 'utf8') : null;\n if (before !== after) files.push({ file, before, after });\n }\n if (files.length === 0) throw new Refusal('nothing to change: the source already says that');\n for (const f of files) write(resolveFile(this.#root, f.file), f.after);\n return this.#push({ label, files }, scope);\n }\n\n /** Records a change `plugin` made itself, with what its `undo` needs. */\n record(label: string, plugin: string, record: unknown, scope?: Scope): Summary {\n return this.#push({ label, plugin, record }, scope);\n }\n\n /** Takes back the latest change, of a scope where one is given. */\n async undo(scope?: Scope): Promise<Summary> {\n const change = this.#done.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to undo' : 'nothing to undo here');\n if ('files' in change) this.#put(change, 'after', 'before');\n else change.record = (await this.#pluginOf(change, 'undo').undo!(change.record)) ?? change.record;\n this.#done = this.#done.filter((c) => c !== change);\n this.#undone.push(change);\n this.#save();\n return summary(change);\n }\n\n /** Makes the change last undone again, of a scope where one is given. */\n async redo(scope?: Scope): Promise<Summary> {\n const change = this.#undone.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to redo' : 'nothing to redo here');\n if ('files' in change) this.#put(change, 'before', 'after');\n else change.record = await this.#pluginOf(change, 'redo').redo!(change.record);\n this.#undone = this.#undone.filter((c) => c !== change);\n this.#done.push(change);\n this.#save();\n return summary(change);\n }\n\n list(scope?: Scope): { done: Summary[]; undone: Summary[] } {\n return { done: this.#done.filter(within(scope)).map(summary), undone: this.#undone.filter(within(scope)).map(summary) };\n }\n\n #push(change: Omit<Base, 'id' | 'at'> & ({ files: FileChange[] } | { plugin: string; record: unknown }), scope?: Scope): Summary {\n const id = Math.max(0, ...[...this.#done, ...this.#undone].map((c) => c.id)) + 1;\n const made = { id, at: new Date().toISOString(), ...change, ...(scope === undefined ? {} : { scope }) };\n this.#done = [...this.#done, made].slice(-LIMIT);\n // What was undone in this scope can't be redone over the new change; another scope's still can.\n this.#undone = this.#undone.filter((c) => !within(scope)(c));\n this.#save();\n return summary(made);\n }\n\n #pluginOf(change: { label: string; plugin: string }, step: 'undo' | 'redo'): ServerPlugin {\n const plugin = this.#plugins.get(change.plugin);\n if (plugin?.[step] === undefined) {\n throw new Refusal(\n `can't ${step} \"${change.label}\": the ${change.plugin} plugin that made it isn't loaded, so add it back to \\`plugins\\``,\n );\n }\n return plugin;\n }\n\n /**\n * Puts each file's `to` text back, once every one of them still reads as its `from`, or still has the\n * lines that differ as `from` has them: then those lines alone change, and the rest stays as it is now.\n */\n #put(change: Base & { files: FileChange[] }, from: 'before' | 'after', to: 'before' | 'after'): void {\n const paths = change.files.map((f) => resolveFile(this.#root, f.file));\n const texts = change.files.map((f, i) => {\n const now = existsSync(paths[i]!) ? readFileSync(paths[i]!, 'utf8') : null;\n if (now === f[from]) return f[to];\n const text = now === null || f[from] === null || f[to] === null ? undefined : swapped(now, f[from], f[to]);\n if (text === undefined) {\n throw new Refusal(\n `${f.file} changed since \"${change.label}\" ${from === 'after' ? 'was made' : 'was undone'}: use the editor's undo there`,\n );\n }\n return text;\n });\n texts.forEach((text, i) => {\n if (text === null) rmSync(paths[i]!);\n else write(paths[i]!, text);\n });\n }\n\n #save(): void {\n write(this.#store, JSON.stringify({ done: this.#done, undone: this.#undone }));\n }\n}\n\n/**\n * `now` with the lines that differ between `from` and `to` put as `to` has them, where `now` has them as\n * `from` does, in one place only. Nothing where it doesn't (they were edited, or there are two of them), or\n * where `from` has no such lines to find (the change only removed some).\n */\nfunction swapped(now: string, from: string, to: string): string | undefined {\n const [a, b, lines] = [from.split('\\n'), to.split('\\n'), now.split('\\n')];\n let head = 0;\n while (head < a.length && head < b.length && a[head] === b[head]) head++;\n let tail = 0;\n while (tail < a.length - head && tail < b.length - head && a.at(-1 - tail) === b.at(-1 - tail)) tail++;\n const theirs = a.slice(head, a.length - tail);\n if (theirs.length === 0) return undefined;\n const found = lines.flatMap((_, i) => (theirs.every((line, j) => lines[i + j] === line) ? [i] : []));\n if (found.length !== 1) return undefined;\n return [...lines.slice(0, found[0]), ...b.slice(head, b.length - tail), ...lines.slice(found[0]! + theirs.length)].join('\\n');\n}\n\nfunction write(path: string, text: string): void {\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, text);\n}\n","/**\n * The dev server's half of deictic, under `/__deictic/`: `read` and `apply` an op through a\n * plugin, `undo`, `redo` and `history`, and `open`, which opens a place in the editor. Written over\n * `Request` and `Response`, so each integration mounts them its own way (Vite as middleware), and\n * served from the page's own origin, so no token travels to the page. `undo`, `redo` and `history` are a\n * plugin's on an element where the request names them (as the popup does: its tab, its element), and\n * the whole history's where it doesn't.\n *\n * Everything but `open` and `history` writes or may, so only the page itself may send it: a POST of\n * JSON from the same origin, which a form or a script on another site can't send without asking first.\n *\n * Each plugin's own `routes` are under `plugins/<name>/`. A `GET` there reaches the plugin as it\n * comes; anything else only from the page's own origin, in whatever type it sends (an image, say).\n * Nothing is answered before every plugin's `setup` has run.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\n\nimport { type Loc, Refusal, type ServerPlugin, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { setUp } from './plugins.ts';\nimport { applyEdits, resolveFile, sourceAt } from './source.ts';\n\nexport interface EndpointOptions {\n root: string;\n plugins: ServerPlugin[];\n /** The path the endpoints sit under, ending in `/`: `/` by default. */\n base?: string;\n /** Opens a place in the editor: a redirect to the dev server's own launcher. */\n open: (path: string, loc: Loc) => Response | Promise<Response>;\n history?: History;\n}\n\ninterface Body {\n plugin: string;\n target: Target;\n op?: unknown;\n}\n\nconst scopeOf = (plugin: string, { file, line, column }: Loc): Scope => ({ plugin, target: `${file}:${line}:${column}` });\n/** The scope an undo or a redo names, or none for the whole history. */\nconst scopeIn = ({ plugin, target }: Partial<Body>) =>\n plugin === undefined || target === undefined ? undefined : scopeOf(plugin, target.loc);\n\n/** Answers deictic's requests, and nothing for any other path. */\nexport function endpoints({ root, plugins, base = '/', open, history = new History(root, { plugins }) }: EndpointOptions) {\n const byName = new Map(plugins.map((p) => [p.name, p]));\n const prefix = `${base}__deictic/`;\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins);\n\n const pluginOf = (name: string) => {\n const plugin = byName.get(name);\n if (plugin === undefined) throw new Refusal(`no plugin \"${name}\" on the server: is it in the bundler plugin's \\`plugins\\`?`);\n return plugin;\n };\n\n const routes: Record<string, (body: Body) => Promise<unknown>> = {\n read: async ({ plugin, target }) => ({ model: await readOf(pluginOf(plugin), target) }),\n apply: async ({ plugin: name, target, op }) => {\n const plugin = pluginOf(name);\n if (plugin.apply === undefined) throw new Refusal(`${name} changes nothing from its panel: it has no \\`apply\\``);\n const source = sourceAt(root, target);\n const before = await readOf(plugin, target);\n const { file, line } = target.loc;\n const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? 'edit'}`;\n const result = await plugin.apply(source, target, op);\n const scope = scopeOf(name, target.loc);\n const change = Array.isArray(result)\n ? history.commit(label, applyEdits(source, result), scope)\n : history.record(label, name, result.done, scope);\n return { model: await readOf(plugin, target), change };\n },\n undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),\n redo: async (body) => ({ change: await history.redo(scopeIn(body)) }),\n };\n // A plugin without `read` has no model, and no need for its element to be where the page says.\n const readOf = (plugin: ServerPlugin, target: Target) => (plugin.read === undefined ? null : plugin.read(sourceAt(root, target), target));\n // One write at a time: a plugin's change may wait on the network, and an undo sent meanwhile must\n // take back that change, not the one before it.\n let queue: Promise<unknown> = Promise.resolve();\n const serially = <T>(run: () => Promise<T>): Promise<T> => {\n const next = queue.then(run, run);\n queue = next.catch(() => {});\n return next;\n };\n\n return async (req: Request): Promise<Response | undefined> => {\n const url = new URL(req.url);\n if (!url.pathname.startsWith(prefix)) return undefined;\n const route = url.pathname.slice(prefix.length);\n const origin = req.headers.get('origin');\n const sameOrigin = origin !== null && new URL(origin).host === url.host;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n const handle = byName.get(name)?.routes?.[first];\n if (handle === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'GET' && req.method !== 'HEAD' && !sameOrigin)\n return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });\n return await handle(req, context);\n }\n const loc = {\n file: url.searchParams.get('file') ?? '',\n line: Number(url.searchParams.get('line')),\n column: Number(url.searchParams.get('column')),\n };\n if (route === 'history') {\n const plugin = url.searchParams.get('plugin');\n return Response.json(history.list(plugin === null ? undefined : scopeOf(plugin, loc)));\n }\n if (route === 'open') return await open(resolveFile(root, loc.file), loc);\n const handler = routes[route];\n if (handler === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'POST' || !sameOrigin || req.headers.get('content-type')?.startsWith('application/json') !== true)\n return Response.json({ problem: 'edits come from the page, as JSON' }, { status: 403 });\n const body = (await req.json()) as Body;\n return Response.json(await (route === 'read' ? handler(body) : serially(() => handler(body))));\n } catch (e) {\n if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });\n return Response.json({ problem: e instanceof Error ? (e.stack ?? e.message) : String(e) }, { status: 500 });\n }\n };\n}\n\n/** A redirect within the page's origin, to a launcher the dev server answers itself. */\nexport const redirect = (path: string) => new Response(null, { status: 307, headers: { Location: path } });\n\n/**\n * The endpoints as Node middleware, for Vite's server. The request's host is the one the page was\n * served from: a proxy's `x-forwarded-host` before its own.\n */\nexport function nodeMiddleware(\n handle: (req: Request) => Promise<Response | undefined>,\n): (req: IncomingMessage, res: ServerResponse, next: () => void) => void {\n return (req, res, next) => {\n // Before reading the body, which a request for anything else leaves to whoever answers it.\n if (req.url?.includes('/__deictic/') !== true) return next();\n const forwarded = req.headers['x-forwarded-host'];\n const host = (Array.isArray(forwarded) ? forwarded[0] : forwarded) ?? req.headers.host ?? 'localhost';\n const headers = new Headers();\n for (const [name, value] of Object.entries(req.headers))\n for (const v of Array.isArray(value) ? value : value === undefined ? [] : [value]) headers.append(name, v);\n\n const chunks: Buffer[] = [];\n req.on('data', (chunk: Buffer) => chunks.push(chunk));\n req.on('end', () => {\n const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : Buffer.concat(chunks);\n handle(new Request(`http://${host}${req.url}`, { method: req.method, headers, body }))\n .then(async (response) => {\n if (response === undefined) return next();\n res.statusCode = response.status;\n response.headers.forEach((value, name) => res.setHeader(name, value));\n res.end(Buffer.from(await response.arrayBuffer()));\n })\n .catch((e: unknown) => {\n res.statusCode = 500;\n res.end(e instanceof Error ? e.message : String(e));\n });\n });\n };\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,MAAM,OAAO,QAAQ,MAAM,IAAI;CAC/B,MAAM,OAAO,SAAS,MAAM,IAAI;CAEhC,IAAI,SAAS,MAAM,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,GACrG,MAAM,IAAI,QAAQ,GAAG,KAAK,qCAAqC;CACjE,OAAO;AACT;AAEA,SAAgB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,aAAa;GAClB,MAAM,OAAO,IAAI,WAAW,SAAS,IAAI,WAAW,SAAS,KAAA,IAAY,OAAO,OAAO,MAAM;GAC7F,OAAO,IAAI,QAAQ,UAAU,OAAO,IAAI,OAAO;IAAE,QAAQ,IAAI;IAAQ;IAAS;GAAK,CAAC,CAAC,CAAC,CACnF,KAAK,OAAO,aAAa;IACxB,IAAI,aAAa,KAAA,GAAW,OAAO,KAAK;IACxC,IAAI,aAAa,SAAS;IAC1B,SAAS,QAAQ,SAAS,OAAO,SAAS,IAAI,UAAU,MAAM,KAAK,CAAC;IACpE,IAAI,IAAI,OAAO,KAAK,MAAM,SAAS,YAAY,CAAC,CAAC;GACnD,CAAC,CAAC,CACD,OAAO,MAAe;IACrB,IAAI,aAAa;IACjB,IAAI,IAAI,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;GACpD,CAAC;EACL,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { JSXOpeningElement, Program } from "oxc-parser";
|
|
2
|
+
/**
|
|
3
|
+
* A gesture: the keys held to outline the element under the pointer, and the button that, with them
|
|
4
|
+
* held, opens the popup there. deictic's own (`MASTER` by default) opens the tab used last; a
|
|
5
|
+
* plugin's, which it takes as its `shortcut` option and has none by default, opens its tab. The
|
|
6
|
+
* bundler's plugin checks them all as it starts, so a wrong one, or two alike, fails the dev server,
|
|
7
|
+
* not the page. Both halves import it: it must
|
|
8
|
+
* stay dependency-free.
|
|
9
|
+
*/
|
|
10
|
+
/** A modifier key, as `KeyboardEvent.key` names it. */
|
|
11
|
+
type Modifier = 'Alt' | 'Control' | 'Meta' | 'Shift';
|
|
12
|
+
interface Shortcut {
|
|
13
|
+
/** Held, and no other, to outline elements. */
|
|
14
|
+
modifiers?: Modifier[];
|
|
15
|
+
/** Pressed with them to open the panel. `'left'` unset. */
|
|
16
|
+
button?: 'left' | 'middle' | 'right';
|
|
17
|
+
}
|
|
18
|
+
/** A place in the source: the file from the project's root, with `/`, and the line and column, from 1. */
|
|
19
|
+
interface Loc {
|
|
20
|
+
file: string;
|
|
21
|
+
line: number;
|
|
22
|
+
column: number;
|
|
23
|
+
}
|
|
24
|
+
/** An element the pointer picked: where its opening tag starts, and the tag, which the server checks is still there. */
|
|
25
|
+
interface Target {
|
|
26
|
+
loc: Loc;
|
|
27
|
+
tag: string;
|
|
28
|
+
}
|
|
29
|
+
/** Text in a file to replace, by UTF-16 offsets. `file` is the target's unless named, from the project's root. */
|
|
30
|
+
interface TextEdit {
|
|
31
|
+
file?: string;
|
|
32
|
+
start: number;
|
|
33
|
+
end: number;
|
|
34
|
+
text: string;
|
|
35
|
+
}
|
|
36
|
+
/** What a server half reads: the target's file, parsed, and its element. */
|
|
37
|
+
interface Source {
|
|
38
|
+
/** The target's file, from the project's root. */
|
|
39
|
+
file: string;
|
|
40
|
+
code: string;
|
|
41
|
+
/** The file's module; for an `.astro` component, its frontmatter's. */
|
|
42
|
+
program: Program;
|
|
43
|
+
/** The target's opening tag. */
|
|
44
|
+
element: JSXOpeningElement;
|
|
45
|
+
/** Another file under the project's root, for plugins whose edits go elsewhere (a locale's messages). */
|
|
46
|
+
read(file: string): string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* What answers the overlay's requests in a page with no dev server behind it (`deictic/vite`'s `standalone`): the
|
|
50
|
+
* default export of a module of the page's. A request is one the endpoints would get, under `<base>__deictic/`;
|
|
51
|
+
* the answer is theirs too (`{ model }`, `{ model, change }`, `{ problem }` with a status that isn't ok).
|
|
52
|
+
*/
|
|
53
|
+
type Standalone = (request: Request) => Response | Promise<Response>;
|
|
54
|
+
/** An op a plugin won't make. The message says why and what to do instead; the panel shows it. */
|
|
55
|
+
declare class Refusal extends Error {
|
|
56
|
+
name: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A change the plugin made itself, not to a file: what its `undo` and `redo` need to take it back and
|
|
60
|
+
* make it again. JSON, since the history keeps it on disk across restarts of the dev server.
|
|
61
|
+
*/
|
|
62
|
+
interface Done<Record = unknown> {
|
|
63
|
+
done: Record;
|
|
64
|
+
}
|
|
65
|
+
type Maybe<T> = T | Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:
|
|
68
|
+
* `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.
|
|
69
|
+
*/
|
|
70
|
+
interface ServerApis {}
|
|
71
|
+
/** The same, in the page: `declare module 'deictic' { interface ClientApis { screenshots: Capture } }`. */
|
|
72
|
+
interface ClientApis {}
|
|
73
|
+
/** A plugin's API, by its name: what its package declared, or `unknown` for one that declared none. */
|
|
74
|
+
type ApiOf<Apis, Name extends string> = Name extends keyof Apis ? Apis[Name] : unknown;
|
|
75
|
+
interface ServerContext {
|
|
76
|
+
/** The project's root, as an absolute path. */
|
|
77
|
+
root: string;
|
|
78
|
+
/**
|
|
79
|
+
* Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded. One the plugin
|
|
80
|
+
* `needs` always is; any other may not be, so check.
|
|
81
|
+
*/
|
|
82
|
+
use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must
|
|
86
|
+
* change nothing: anything else reaches it only from the page itself, which deictic checks.
|
|
87
|
+
*/
|
|
88
|
+
type Route = (request: Request, context: ServerContext) => Maybe<Response>;
|
|
89
|
+
interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = unknown> {
|
|
90
|
+
/** Ties the halves together; also the label of its changes in the history, and its routes' path. Lowercase, with `-`. */
|
|
91
|
+
name: string;
|
|
92
|
+
/** The module the page loads for this plugin's half there, which default-exports its `ClientPlugin`. */
|
|
93
|
+
client?: string;
|
|
94
|
+
/** What the page half gets as `context.options`: the user's options it needs there, as JSON. */
|
|
95
|
+
clientOptions?: unknown;
|
|
96
|
+
/** What opens its panel: its own default, which its options let the user change. A plugin with no panel has none. */
|
|
97
|
+
shortcut?: Shortcut;
|
|
98
|
+
/** The plugins it can't do without, by name: the dev server won't start without them. */
|
|
99
|
+
needs?: string[];
|
|
100
|
+
/** Runs once, as the dev server starts and before it answers anything. Answers the plugin's API to the others. */
|
|
101
|
+
setup?(context: ServerContext): Maybe<Api>;
|
|
102
|
+
/** Routes of its own, by their first segment under `/__deictic/plugins/<name>/`. */
|
|
103
|
+
routes?: {
|
|
104
|
+
[route: string]: Route;
|
|
105
|
+
};
|
|
106
|
+
/** The model its panel shows for an element. Without it, the panel gets none. */
|
|
107
|
+
read?(source: Source, target: Target): Maybe<Model>;
|
|
108
|
+
/** Text edits for deictic to write, or a change the plugin made itself. */
|
|
109
|
+
apply?(source: Source, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;
|
|
110
|
+
/**
|
|
111
|
+
* Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may
|
|
112
|
+
* answer what the next redo needs, where that differs (what it put back has a new ID).
|
|
113
|
+
*/
|
|
114
|
+
undo?(record: Record): Maybe<void | Record>;
|
|
115
|
+
/** Makes it again after an undo, and answers what the next undo needs, which may differ (a new ID). */
|
|
116
|
+
redo?(record: Record): Maybe<Record>;
|
|
117
|
+
/** Says what an op does, for the history: `className: px-2 → px-4`. */
|
|
118
|
+
describe?(op: Op, before: Model): string;
|
|
119
|
+
}
|
|
120
|
+
declare const definePlugin: <Model, Op, Record = unknown, Api = unknown>(plugin: ServerPlugin<Model, Op, Record, Api>) => ServerPlugin<Model, Op, Record, Api>;
|
|
121
|
+
interface ClientContext {
|
|
122
|
+
/** The dev server's base URL, ending in `/`. */
|
|
123
|
+
base: string;
|
|
124
|
+
/** deictic's shadow root, to draw in: neither the page's styles nor the overlay's cross over. */
|
|
125
|
+
root: ShadowRoot;
|
|
126
|
+
/** The server half's `clientOptions`, or nothing. */
|
|
127
|
+
options: unknown;
|
|
128
|
+
/** Another plugin's API in the page, as its `setup` answered it, or nothing when it isn't loaded. */
|
|
129
|
+
use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;
|
|
130
|
+
/** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */
|
|
131
|
+
request: (route: string, init?: RequestInit) => Promise<Response>;
|
|
132
|
+
/**
|
|
133
|
+
* Opens the popup on an element at a plugin's tab, as its shortcut would: after a recording, say. An
|
|
134
|
+
* element rendered again since stands in for one no longer on the page. False when there's no such tab
|
|
135
|
+
* or no such element any more. Not from `setup`, which runs before the popup can open.
|
|
136
|
+
*/
|
|
137
|
+
open: (plugin: string, element: Element) => boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Shows `items` in the lightbox over everything, at `at` (the first by default), stepping between them with
|
|
140
|
+
* ← and →. With `from`, it grows out of that element (the chip clicked) and shrinks back into it on close.
|
|
141
|
+
*/
|
|
142
|
+
lightbox: (items: LightboxItem[], options?: LightboxOptions) => {
|
|
143
|
+
close: () => void;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** What the lightbox shows: a picture, a page in a frame (a recording's replay), or a sound with its waveform. */
|
|
147
|
+
type LightboxItem = {
|
|
148
|
+
/** Its name, over it. */
|
|
149
|
+
title: string;
|
|
150
|
+
/** Buttons beside the name: each closes the lightbox and runs. */
|
|
151
|
+
actions?: LightboxAction[];
|
|
152
|
+
} & ({
|
|
153
|
+
kind: 'image';
|
|
154
|
+
url: string;
|
|
155
|
+
} | {
|
|
156
|
+
kind: 'page';
|
|
157
|
+
url: string;
|
|
158
|
+
} | {
|
|
159
|
+
kind: 'audio';
|
|
160
|
+
url: string;
|
|
161
|
+
});
|
|
162
|
+
interface LightboxAction {
|
|
163
|
+
label: string;
|
|
164
|
+
title?: string;
|
|
165
|
+
run: () => void;
|
|
166
|
+
}
|
|
167
|
+
interface LightboxOptions {
|
|
168
|
+
/** The item it opens at. */
|
|
169
|
+
at?: number;
|
|
170
|
+
/** The element it grows out of, and goes back into. */
|
|
171
|
+
from?: Element;
|
|
172
|
+
}
|
|
173
|
+
interface PanelContext<Model, Op> extends ClientContext {
|
|
174
|
+
/** The element clicked: the one the source marked, under the pointer or around what is. */
|
|
175
|
+
element: Element;
|
|
176
|
+
/**
|
|
177
|
+
* What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a
|
|
178
|
+
* dependency's, or in an open shadow root, as the popup's own on a page that shows it (`popupIn`).
|
|
179
|
+
*/
|
|
180
|
+
pointed?: Element;
|
|
181
|
+
/** Every element on the page from the same place in the source, the clicked one among them: the rows of a list. */
|
|
182
|
+
elements: Element[];
|
|
183
|
+
target: Target;
|
|
184
|
+
model: Model;
|
|
185
|
+
/** Applies an op on disk, and reads the model again. Rejects with the server's reason, which the panel also shows. */
|
|
186
|
+
apply(op: Op): Promise<Model>;
|
|
187
|
+
close: () => void;
|
|
188
|
+
/**
|
|
189
|
+
* Says there's something here that leaving would lose (words typed, a change tried on the page), and the button
|
|
190
|
+
* that keeps it: a click outside the popup then shakes that button, where it would have closed the popup.
|
|
191
|
+
* `undefined` once there's nothing to lose. Forgotten as the panel unmounts.
|
|
192
|
+
*/
|
|
193
|
+
unsaved: (action: HTMLElement | undefined) => void;
|
|
194
|
+
/**
|
|
195
|
+
* Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a
|
|
196
|
+
* pick of another element), and opens it again at this tab on this element. The next mount gets
|
|
197
|
+
* `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why
|
|
198
|
+
* it failed. The state stays in the page, as it is: no need for JSON.
|
|
199
|
+
*/
|
|
200
|
+
away: <T>(state: unknown, task: () => Promise<T>) => void;
|
|
201
|
+
/** Set when this mount is the panel coming back from `away`. */
|
|
202
|
+
resumed?: Resumed;
|
|
203
|
+
}
|
|
204
|
+
/** What a panel coming back from `away` gets: the state it kept, and the task's result or problem. */
|
|
205
|
+
interface Resumed {
|
|
206
|
+
state: unknown;
|
|
207
|
+
result?: unknown;
|
|
208
|
+
/** Why the task failed: its error's message. */
|
|
209
|
+
problem?: string;
|
|
210
|
+
}
|
|
211
|
+
interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {
|
|
212
|
+
/** The server half's `name`. */
|
|
213
|
+
name: string;
|
|
214
|
+
/** Shown over the element while its shortcut's keys are held, and atop the panel. */
|
|
215
|
+
label?: string;
|
|
216
|
+
/**
|
|
217
|
+
* Runs once, as the page starts, before any panel opens (a recording starts here). Answers the
|
|
218
|
+
* plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.
|
|
219
|
+
*/
|
|
220
|
+
setup?(context: ClientContext): Api;
|
|
221
|
+
/** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */
|
|
222
|
+
mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;
|
|
223
|
+
}
|
|
224
|
+
declare const defineClientPlugin: <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>) => ClientPlugin<Model, Op, Api>;
|
|
225
|
+
export { Modifier as C, definePlugin as S, Source as _, Done as a, TextEdit as b, LightboxOptions as c, Refusal as d, Resumed as f, ServerPlugin as g, ServerContext as h, ClientPlugin as i, Loc as l, ServerApis as m, ClientApis as n, LightboxAction as o, Route as p, ClientContext as r, LightboxItem as s, ApiOf as t, PanelContext as u, Standalone as v, Shortcut as w, defineClientPlugin as x, Target as y };
|
|
226
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/shortcut.ts","../../src/index.ts"],"mappings":";;;;;;;;;;KAUY;UAEK;;EAEf,YAAY;;EAEZ;;;UCYe;EACf;EACA;EACA;;;UAIe;EACf,KAAK;EACL;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;;EAEf;EACA;;EAEA,SAAS;;EAET,SAAS;;EAET,KAAK;;;;;;;KAQK,cAAc,SAAS,YAAY,WAAW,QAAQ;;cAGrD,gBAAgB;EAClB;;;;;;UAOM,KAA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C,UAAU;;;UAIK;EACf;EACA;;EAEA;;UAGe,aAAa,iBAAiB,cAAc;;EAE3D;;EAEA;;;;;EAKA,OAAO,SAAS,gBAAgB;;EAEhC,SAAS,OAAO,aAAa,SAAS,aAAa,OAAO;;cAG/C,qBAAsB,OAAO,IAAI,eAAa,QAAU,aAAa,OAAO,IAAI,SAAO,aAAa,OAAO,IAAI"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** A rectangle in CSS pixels, from the shot's top left. */
|
|
2
|
+
interface Box {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
/** A shot as the page knows it: its ID, where the dev server serves its PNG, and where the element is in it. */
|
|
9
|
+
interface Shot {
|
|
10
|
+
id: string;
|
|
11
|
+
url: string;
|
|
12
|
+
/** The element, in the shot: nothing marks it there, as nothing of deictic's is drawn. */
|
|
13
|
+
box: Box;
|
|
14
|
+
/** The shot's size in CSS pixels; its PNG may have more, on a high-density screen. */
|
|
15
|
+
size: {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
interface CaptureOptions {
|
|
21
|
+
/** `viewport`, what the page shows, by default; or `element`, the element alone. */
|
|
22
|
+
area?: 'viewport' | 'element';
|
|
23
|
+
}
|
|
24
|
+
/** The page's half, for other plugins' page halves. */
|
|
25
|
+
interface Capture {
|
|
26
|
+
capture(element: Element, options?: CaptureOptions): Promise<Shot>;
|
|
27
|
+
/** Keeps a PNG made of a shot (the same one with marks drawn over it, say) as a shot of its own. */
|
|
28
|
+
upload(png: Blob, of: Pick<Shot, 'box' | 'size'>): Promise<Shot>;
|
|
29
|
+
}
|
|
30
|
+
/** The server's half, for other plugins' server halves. */
|
|
31
|
+
interface Screenshots {
|
|
32
|
+
/** A shot's PNG, or nothing for one not kept (any more). */
|
|
33
|
+
read(id: string): {
|
|
34
|
+
data: Uint8Array<ArrayBuffer>;
|
|
35
|
+
name: string;
|
|
36
|
+
type: 'image/png';
|
|
37
|
+
} | undefined;
|
|
38
|
+
}
|
|
39
|
+
declare module 'deictic' {
|
|
40
|
+
interface ServerApis {
|
|
41
|
+
screenshots: Screenshots;
|
|
42
|
+
}
|
|
43
|
+
interface ClientApis {
|
|
44
|
+
screenshots: Capture;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* What a shot hides, as rrweb names it and by its defaults, so one marking in the app hides the same
|
|
49
|
+
* things from a screenshot as from an rrweb recording or snapshot.
|
|
50
|
+
*/
|
|
51
|
+
interface Masking {
|
|
52
|
+
/** Elements drawn as a blank box their size: `rr-block` by default. */
|
|
53
|
+
blockClass?: string;
|
|
54
|
+
blockSelector?: string;
|
|
55
|
+
/** Elements whose text is drawn as `*`: `rr-mask` by default. */
|
|
56
|
+
maskTextClass?: string;
|
|
57
|
+
maskTextSelector?: string;
|
|
58
|
+
/** Every field's value as `*`, not only passwords': false by default. */
|
|
59
|
+
maskAllInputs?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** Masking with its defaults, as a renderer's page half gets it. */
|
|
62
|
+
type ResolvedMasking = Required<Pick<Masking, 'blockClass' | 'maskTextClass' | 'maskAllInputs'>> & Masking;
|
|
63
|
+
/**
|
|
64
|
+
* How shots are made. `client` is the page module that captures, default-exporting `screenshotsClient(…)`
|
|
65
|
+
* from `deictic/screenshots/client`. A page half that sends a PNG needs nothing here; one that sends
|
|
66
|
+
* something else, as JSON (a DOM snapshot), needs `render` to make the PNG of it.
|
|
67
|
+
*/
|
|
68
|
+
interface Renderer {
|
|
69
|
+
client: string;
|
|
70
|
+
/** What the page half gets, besides the masking. */
|
|
71
|
+
clientOptions?: unknown;
|
|
72
|
+
render?(input: unknown): Promise<Uint8Array>;
|
|
73
|
+
}
|
|
74
|
+
/** Where `rrweb()` finds a browser: any Chromium renders the snapshot as the page's own would. */
|
|
75
|
+
interface BrowserOptions {
|
|
76
|
+
/** A Chromium-based browser's executable. */
|
|
77
|
+
executablePath?: string;
|
|
78
|
+
/** An installed browser by Playwright's name: `chrome`, `msedge`. By default Playwright's own Chromium, then Chrome, then Edge. */
|
|
79
|
+
channel?: string;
|
|
80
|
+
}
|
|
81
|
+
/** Draws the page in the page, from its DOM (`modern-screenshot`): no server needed, but text may lay out a little differently. */
|
|
82
|
+
declare const dom: () => Renderer;
|
|
83
|
+
/**
|
|
84
|
+
* Snapshots the page's DOM in the page (`rrweb-snapshot`, masking as rrweb does) and renders it in a
|
|
85
|
+
* browser beside the dev server (`playwright-core`), so text lays out as the page's does.
|
|
86
|
+
*/
|
|
87
|
+
declare const rrweb: (options?: BrowserOptions) => Renderer;
|
|
88
|
+
interface ScreenshotsOptions extends Masking {
|
|
89
|
+
/** How shots are made: `rrweb()` by default, or `dom()` where there's no server to render on. */
|
|
90
|
+
renderer?: Renderer;
|
|
91
|
+
/** How many shots to keep, the latest: 100 by default. */
|
|
92
|
+
keep?: number;
|
|
93
|
+
/** Where they're kept, from the project's root: `.deictic/screenshots` by default. */
|
|
94
|
+
dir?: string;
|
|
95
|
+
}
|
|
96
|
+
declare function screenshots(options?: ScreenshotsOptions): import("deictic").ServerPlugin<never, never, never, Screenshots>;
|
|
97
|
+
export { Masking as a, Screenshots as c, dom as d, rrweb as f, CaptureOptions as i, ScreenshotsOptions as l, BrowserOptions as n, Renderer as o, screenshots as p, Capture as r, ResolvedMasking as s, Box as t, Shot as u };
|
|
98
|
+
//# sourceMappingURL=index2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index2.d.ts","names":[],"sources":["../../src/plugins/screenshots/index.ts"],"mappings":";UAqBiB;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;;EAEA,KAAK;;EAEL;IAAQ;IAAe;;;UAGR;;EAEf;;;UAIe;EACf,QAAQ,SAAS,SAAS,UAAU,iBAAiB,QAAQ;;EAE7D,OAAO,KAAK,MAAM,IAAI,KAAK,wBAAwB,QAAQ;;;UAI5C;;EAEf,KAAK;IAAe,MAAM,WAAW;IAAc;IAAc;;;;YAIvD;IACR,aAAa;;YAEL;IACR,aAAa;;;;;;;UAQA;;EAEf;EACA;;EAEA;EACA;;EAEA;;;KAIU,kBAAkB,SAAS,KAAK,8DAA8D;;;;;;UAOzF;EACf;;EAEA;EACA,QAAQ,iBAAiB,QAAQ;;;UAIlB;;EAEf;;EAEA;;;cAIW,WAAU;;;;;cAMV,QAAK,UAAa,mBAAsB;UAMpC,2BAA2B;;EAE1C,WAAW;;EAEX;;EAEA;;iBAOc,YAAY,UAAS,uCAAuB,kCAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { a as Masking } from "./index2.js";
|
|
2
|
+
/**
|
|
3
|
+
* The custom event's tag the marks go in: the page's annotations, as an SVG in page coordinates (`svg`),
|
|
4
|
+
* and as the annotations themselves (`annotations`, absent from recordings made before it was added).
|
|
5
|
+
*/
|
|
6
|
+
declare const MARKS = "deictic.annotations";
|
|
7
|
+
/** Where the replay page finds what the plugin's routes would serve it, for a page published as a file. */
|
|
8
|
+
interface ReplaySources {
|
|
9
|
+
/** The folder `player.js` and `player.css` are in (`rrweb-player`'s `rrweb-player.umd.min.cjs` and `style.css`), from the page: `..`, the routes', by default. */
|
|
10
|
+
player?: string;
|
|
11
|
+
/**
|
|
12
|
+
* A script, from the page, that sets `globalThis.deicticReplay` before the page asks: `recording(id)` answers the
|
|
13
|
+
* recording (a `Kept`) and `clip(id)` a voice clip's URL, either as a promise. The routes by default.
|
|
14
|
+
*/
|
|
15
|
+
source?: string;
|
|
16
|
+
}
|
|
17
|
+
/** The replay page's HTML: the routes' as it is, or one for a page published as a file. */
|
|
18
|
+
declare const replayPage: ({ player, source }?: ReplaySources) => string;
|
|
19
|
+
/** A recording as the page knows it: its ID, where it plays back, and how long it ran, in milliseconds. */
|
|
20
|
+
interface Recording {
|
|
21
|
+
id: string;
|
|
22
|
+
url: string;
|
|
23
|
+
duration: number;
|
|
24
|
+
/** What the mic took while it was on, where the voice plugin is loaded. */
|
|
25
|
+
voice?: VoiceClip[];
|
|
26
|
+
}
|
|
27
|
+
/** A stretch of the mic in a recording: the voice plugin's clip, and when it starts in the recording, in milliseconds. */
|
|
28
|
+
interface VoiceClip {
|
|
29
|
+
id: string;
|
|
30
|
+
at: number;
|
|
31
|
+
duration: number;
|
|
32
|
+
}
|
|
33
|
+
/** The page's half, for other plugins' page halves. */
|
|
34
|
+
interface Recorder {
|
|
35
|
+
/**
|
|
36
|
+
* Records the page, with the toolbar, until Stop: answers the recording, kept by the dev server, or
|
|
37
|
+
* nothing when it's discarded. Rejects while another is going, or when it couldn't be kept.
|
|
38
|
+
*/
|
|
39
|
+
record(): Promise<Recording | undefined>;
|
|
40
|
+
/** Whether one is going. */
|
|
41
|
+
recording(): boolean;
|
|
42
|
+
}
|
|
43
|
+
/** The server's half, for other plugins' server halves. */
|
|
44
|
+
interface Recordings {
|
|
45
|
+
/** A recording's JSON, or nothing for one not kept (any more). */
|
|
46
|
+
read(id: string): {
|
|
47
|
+
data: Uint8Array<ArrayBuffer>;
|
|
48
|
+
name: string;
|
|
49
|
+
type: 'application/json';
|
|
50
|
+
} | undefined;
|
|
51
|
+
}
|
|
52
|
+
/** What the page sends, and what's kept: rrweb's events and what they can't say. */
|
|
53
|
+
interface Kept {
|
|
54
|
+
page: string;
|
|
55
|
+
viewport: {
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The colour scheme the page was in, which rrweb doesn't record: the replay shows it in the same, or a
|
|
61
|
+
* page styled by `prefers-color-scheme` would take the replay's.
|
|
62
|
+
*/
|
|
63
|
+
colorScheme?: 'light' | 'dark';
|
|
64
|
+
startedAt: number;
|
|
65
|
+
duration: number;
|
|
66
|
+
events: unknown[];
|
|
67
|
+
/** The mic's clips, played along with the replay. */
|
|
68
|
+
voice?: VoiceClip[];
|
|
69
|
+
}
|
|
70
|
+
declare module 'deictic' {
|
|
71
|
+
interface ServerApis {
|
|
72
|
+
recordings: Recordings;
|
|
73
|
+
}
|
|
74
|
+
interface ClientApis {
|
|
75
|
+
recordings: Recorder;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
interface RecordingsOptions extends Masking {
|
|
79
|
+
/** How many recordings to keep, the latest: 20 by default. */
|
|
80
|
+
keep?: number;
|
|
81
|
+
/** Where they're kept, from the project's root: `.deictic/recordings` by default. */
|
|
82
|
+
dir?: string;
|
|
83
|
+
}
|
|
84
|
+
declare function recordings(options?: RecordingsOptions): import("deictic").ServerPlugin<never, never, never, Recordings>;
|
|
85
|
+
export { RecordingsOptions as a, ReplaySources as c, Recordings as i, replayPage as l, Recorder as n, VoiceClip as o, Recording as r, recordings as s, Kept as t, MARKS as u };
|
|
86
|
+
//# sourceMappingURL=index3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index3.d.ts","names":[],"sources":["../../src/plugins/recordings/marks.ts","../../src/plugins/recordings/replay.ts","../../src/plugins/recordings/index.ts"],"mappings":";;;;;cAIa;;UCoBI;;EAEf;;;;;EAKA;;;cAIW,eAAU,QAAA,WAA+B;;UCZrC;EACf;EACA;EACA;;EAEA,QAAQ;;;UAIO;EACf;EACA;EACA;;;UAIe;;;;;EAKf,UAAU,QAAQ;;EAElB;;;UAIe;;EAEf,KAAK;IAAe,MAAM,WAAW;IAAc;IAAc;;;;UAIlD;EACf;EACA;IAAY;IAAe;;;;;;EAK3B;EACA;EACA;EACA;;EAEA,QAAQ;;;YAIE;IACR,YAAY;;YAEJ;IACR,YAAY;;;UAIC,0BAA0B;;EAEzC;;EAEA;;iBAiBc,WAAW,UAAS,sCAAsB,kCAAA"}
|