deictic 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/API.md +303 -0
  2. package/README.md +56 -104
  3. package/dist/annotations/index.d.ts +1 -1
  4. package/dist/astro.d.ts +1 -1
  5. package/dist/bun.d.ts +1 -1
  6. package/dist/bun.js +2 -2
  7. package/dist/client/index.d.ts +4 -2
  8. package/dist/client/index.d.ts.map +1 -1
  9. package/dist/client/index.js +130 -16
  10. package/dist/client/index.js.map +1 -1
  11. package/dist/index.d.ts +21 -218
  12. package/dist/index.js.map +1 -1
  13. package/dist/loader.js +1 -1
  14. package/dist/logs/client.d.ts +4 -0
  15. package/dist/logs/client.d.ts.map +1 -0
  16. package/dist/logs/client.js +16 -0
  17. package/dist/logs/client.js.map +1 -0
  18. package/dist/logs/index.d.ts +18 -0
  19. package/dist/logs/index.d.ts.map +1 -0
  20. package/dist/logs/index.js +21 -0
  21. package/dist/logs/index.js.map +1 -0
  22. package/dist/network/client.d.ts +4 -0
  23. package/dist/network/client.d.ts.map +1 -0
  24. package/dist/network/client.js +29 -0
  25. package/dist/network/client.js.map +1 -0
  26. package/dist/network/index.d.ts +2 -0
  27. package/dist/network/index.js +39 -0
  28. package/dist/network/index.js.map +1 -0
  29. package/dist/next.d.ts +1 -1
  30. package/dist/next.js +2 -2
  31. package/dist/recommended/index.d.ts +15 -5
  32. package/dist/recommended/index.d.ts.map +1 -1
  33. package/dist/recommended/index.js +10 -3
  34. package/dist/recommended/index.js.map +1 -1
  35. package/dist/recordings/client.d.ts +1 -1
  36. package/dist/recordings/client.d.ts.map +1 -1
  37. package/dist/recordings/client.js +177 -48
  38. package/dist/recordings/client.js.map +1 -1
  39. package/dist/recordings/index.d.ts +2 -2
  40. package/dist/recordings/index.js +3 -3
  41. package/dist/screenshots/client.d.ts +7 -1
  42. package/dist/screenshots/client.d.ts.map +1 -1
  43. package/dist/screenshots/client.js +36 -4
  44. package/dist/screenshots/client.js.map +1 -1
  45. package/dist/screenshots/dom.d.ts +1 -1
  46. package/dist/screenshots/dom.d.ts.map +1 -1
  47. package/dist/screenshots/dom.js +1 -28
  48. package/dist/screenshots/dom.js.map +1 -1
  49. package/dist/screenshots/index.d.ts +1 -1
  50. package/dist/screenshots/index.js +2 -2
  51. package/dist/screenshots/index.js.map +1 -1
  52. package/dist/screenshots/rrweb.d.ts +2 -2
  53. package/dist/screenshots/rrweb.js +5 -1
  54. package/dist/screenshots/rrweb.js.map +1 -1
  55. package/dist/{endpoints.js → shared/endpoints.js} +1 -1
  56. package/dist/shared/endpoints.js.map +1 -0
  57. package/dist/shared/index.d.ts +238 -0
  58. package/dist/shared/index.d.ts.map +1 -0
  59. package/dist/{index3.d.ts → shared/index2.d.ts} +3 -1
  60. package/dist/shared/index2.d.ts.map +1 -0
  61. package/dist/shared/index3.d.ts +112 -0
  62. package/dist/shared/index3.d.ts.map +1 -0
  63. package/dist/shared/index4.d.ts +64 -0
  64. package/dist/shared/index4.d.ts.map +1 -0
  65. package/dist/shared/index5.d.ts +220 -0
  66. package/dist/shared/index5.d.ts.map +1 -0
  67. package/dist/{index5.d.ts → shared/index6.d.ts} +2 -2
  68. package/dist/shared/index6.d.ts.map +1 -0
  69. package/dist/{integration.d.ts → shared/integration.d.ts} +4 -3
  70. package/dist/shared/integration.d.ts.map +1 -0
  71. package/dist/{integration.js → shared/integration.js} +5 -3
  72. package/dist/shared/integration.js.map +1 -0
  73. package/dist/{kept.js → shared/kept.js} +2 -2
  74. package/dist/shared/kept.js.map +1 -0
  75. package/dist/{marks.js → shared/marks.js} +6 -1
  76. package/dist/shared/marks.js.map +1 -0
  77. package/dist/shared/mask.js +107 -0
  78. package/dist/shared/mask.js.map +1 -0
  79. package/dist/{playwright.js → shared/playwright.js} +19 -4
  80. package/dist/shared/playwright.js.map +1 -0
  81. package/dist/shared/recordings.js +437 -0
  82. package/dist/shared/recordings.js.map +1 -0
  83. package/dist/shared/shortcut.js.map +1 -0
  84. package/dist/shared/tasks.js +632 -0
  85. package/dist/shared/tasks.js.map +1 -0
  86. package/dist/shared/waveform.js.map +1 -0
  87. package/dist/tailwind/client.d.ts +1 -1
  88. package/dist/tailwind/index.d.ts +1 -1
  89. package/dist/tasks/client.d.ts +1 -1
  90. package/dist/tasks/client.d.ts.map +1 -1
  91. package/dist/tasks/client.js +272 -57
  92. package/dist/tasks/client.js.map +1 -1
  93. package/dist/tasks/index.d.ts +2 -159
  94. package/dist/tasks/index.js +1 -348
  95. package/dist/vite.d.ts +11 -12
  96. package/dist/vite.d.ts.map +1 -1
  97. package/dist/vite.js +21 -4
  98. package/dist/vite.js.map +1 -1
  99. package/dist/voice/client.d.ts.map +1 -1
  100. package/dist/voice/client.js +36 -15
  101. package/dist/voice/client.js.map +1 -1
  102. package/dist/voice/index.d.ts +6 -1
  103. package/dist/voice/index.d.ts.map +1 -1
  104. package/dist/voice/index.js +13 -3
  105. package/dist/voice/index.js.map +1 -1
  106. package/dist/webpack.d.ts +1 -1
  107. package/dist/webpack.js +2 -2
  108. package/package.json +41 -2
  109. package/skills/deictic/SKILL.md +20 -14
  110. package/skills/deictic/references/install.md +32 -10
  111. package/skills/deictic/references/recordings.md +29 -0
  112. package/skills/deictic/references/tasks.md +49 -21
  113. package/skills/deictic/references/watch.md +38 -11
  114. package/skills/deictic/scripts/lib.mjs +88 -4
  115. package/skills/deictic/scripts/recording.mjs +84 -4
  116. package/skills/deictic/scripts/task.mjs +36 -7
  117. package/skills/deictic/scripts/vb.mjs +12 -0
  118. package/skills/deictic/scripts/watch.mjs +74 -10
  119. package/src/client/away.ts +105 -0
  120. package/src/client/index.ts +60 -16
  121. package/src/client/style.ts +1 -0
  122. package/src/index.ts +21 -2
  123. package/src/plugins/logs/client.ts +18 -0
  124. package/src/plugins/logs/index.ts +55 -0
  125. package/src/plugins/network/client.ts +30 -0
  126. package/src/plugins/network/index.ts +69 -0
  127. package/src/plugins/network/mask.ts +133 -0
  128. package/src/plugins/recommended/index.ts +14 -1
  129. package/src/plugins/recordings/client.ts +220 -40
  130. package/src/plugins/recordings/index.ts +111 -25
  131. package/src/plugins/recordings/marks.ts +6 -0
  132. package/src/plugins/recordings/replay.ts +159 -10
  133. package/src/plugins/screenshots/client.ts +38 -2
  134. package/src/plugins/screenshots/dom.ts +1 -32
  135. package/src/plugins/screenshots/index.ts +2 -0
  136. package/src/plugins/screenshots/playwright.ts +15 -4
  137. package/src/plugins/screenshots/rrweb.ts +2 -1
  138. package/src/plugins/tasks/client.ts +273 -41
  139. package/src/plugins/tasks/index.ts +207 -47
  140. package/src/plugins/tasks/local.ts +170 -0
  141. package/src/plugins/tasks/watchers.ts +36 -0
  142. package/src/plugins/voice/client.ts +33 -10
  143. package/src/plugins/voice/index.ts +21 -4
  144. package/src/tools/integration.ts +5 -3
  145. package/src/tools/kept.ts +2 -2
  146. package/src/vite.ts +23 -4
  147. package/dist/endpoints.js.map +0 -1
  148. package/dist/index.d.ts.map +0 -1
  149. package/dist/index2.d.ts +0 -23
  150. package/dist/index3.d.ts.map +0 -1
  151. package/dist/index4.d.ts +0 -74
  152. package/dist/index4.d.ts.map +0 -1
  153. package/dist/index5.d.ts.map +0 -1
  154. package/dist/integration.d.ts.map +0 -1
  155. package/dist/integration.js.map +0 -1
  156. package/dist/kept.js.map +0 -1
  157. package/dist/marks.js.map +0 -1
  158. package/dist/playwright.js.map +0 -1
  159. package/dist/recordings.js +0 -235
  160. package/dist/recordings.js.map +0 -1
  161. package/dist/shortcut.js.map +0 -1
  162. package/dist/tasks/index.d.ts.map +0 -1
  163. package/dist/tasks/index.js.map +0 -1
  164. package/dist/waveform.js.map +0 -1
  165. /package/dist/{shortcut.js → shared/shortcut.js} +0 -0
  166. /package/dist/{waveform.js → shared/waveform.js} +0 -0
@@ -1,235 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
2
- import { createRequire } from "node:module";
3
- import { dirname, join, resolve } from "node:path";
4
- import { definePlugin } from "./index.js";
5
- import { t as keptIn } from "./kept.js";
6
- import { n as MARKS } from "./marks.js";
7
- // src/plugins/recordings/replay.ts
8
- /**
9
- * The replay page, `replay/<id>`: rrweb's own player (`rrweb-player`), its timeline, speeds, skipping idle
10
- * stretches and fullscreen, sized to the window, with what it doesn't do drawn over it:
11
- *
12
- * - The page shows in the colour scheme it was recorded in, whatever the viewer's: the replay's iframe
13
- * answers `prefers-color-scheme` as the viewer's browser does, so the recorded CSS's queries are rewritten
14
- * before it's replayed, the recorded scheme's to always match and the other's never.
15
- * - The marks drawn while recording come as custom events, an SVG in page coordinates each; they're drawn
16
- * over the replay in the player's own scaled wrapper, moved with its scroll, rather than into its document,
17
- * which the replayer rebuilds. Each is a marker on the timeline.
18
- * - The voice clips play in step, at the player's speed. A recording with voice starts paused, as a browser
19
- * plays sound only after a click.
20
- *
21
- * `?t=<seconds>` opens it paused there, and `&bare` without the controls at the recorded size, 1:1, for a
22
- * screenshot; `?embed` is it filling a frame, with no header of its own (the lightbox's); `body[data-ready]` says
23
- * it's in place.
24
- */
25
- const REPLAY = `<!doctype html>
26
- <html lang="en">
27
- <meta charset="utf-8">
28
- <meta name="viewport" content="width=device-width, initial-scale=1">
29
- <title>Recording · deictic</title>
30
- <link rel="stylesheet" href="../player.css">
31
- <style>
32
- :root { color-scheme: dark; --accent: #12b358; }
33
- body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; background: #18181b; color: #fafafa; font: 13px/1.4 system-ui, sans-serif; }
34
- header { display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid #3f3f46; }
35
- header a { color: #a1a1aa; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
36
- main { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 16px; }
37
- body.bare header { display: none; }
38
- body.bare main { padding: 0; }
39
- body.embed header { display: none; }
40
- body.embed main { padding: 0; }
41
- body.embed #main .rr-player { box-shadow: none; border-radius: 0; }
42
- #marks { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; }
43
- #marks svg { position: absolute; left: 0; top: 0; overflow: visible; }
44
- .problem { color: #f87171; padding: 16px; }
45
- /* rrweb-player, in the dark of the rest of deictic. Its rules repeat Svelte's scoping class, so these start
46
- from #main, which outweighs any number of classes. */
47
- #main .rr-player { background: #27272a; box-shadow: 0 12px 32px rgb(0 0 0 / 0.5); border-radius: 8px; overflow: hidden; }
48
- body.bare #main .rr-player { box-shadow: none; border-radius: 0; }
49
- #main .rr-player .rr-player__frame { background: #fff; }
50
- #main .rr-player .rr-controller { background: #18181b; border-top: 1px solid #3f3f46; border-radius: 0; }
51
- #main .rr-player .rr-timeline__time { color: #a1a1aa; font: 12px ui-monospace, monospace; }
52
- #main .rr-player .rr-progress { background: #3f3f46; border-color: #18181b; }
53
- #main .rr-player .rr-progress__step { background: color-mix(in srgb, var(--accent) 45%, transparent); }
54
- #main .rr-player .rr-progress__handler { background: var(--accent); }
55
- #main .rr-player .rr-controller__btns button { color: #e4e4e7; }
56
- #main .rr-player .rr-controller__btns button:disabled { color: #52525b; }
57
- #main .rr-player .rr-controller__btns button svg { fill: currentColor; }
58
- #main .rr-player .rr-controller__btns button.active { color: #04130b; background: var(--accent); }
59
- #main .rr-player .rr-controller__btns button:active { background: color-mix(in srgb, var(--accent) 60%, transparent); }
60
- #main .rr-player .switch .label { color: #e4e4e7; }
61
- #main .rr-player .switch.disabled .label { color: #52525b; }
62
- #main .rr-player .switch label:before { background: #52525b; }
63
- #main .rr-player .switch input:checked + label:before { background: var(--accent); }
64
- </style>
65
- <header>
66
- <strong>Recording</strong>
67
- <a id="page" target="_blank" rel="noreferrer"></a>
68
- </header>
69
- <main id="main"></main>
70
- <script src="../player.js"><\/script>
71
- <script>
72
- const params = new URLSearchParams(location.search);
73
- const bare = params.has('bare');
74
- const embed = params.has('embed');
75
- if (bare) document.body.classList.add('bare');
76
- if (embed) document.body.classList.add('embed');
77
- const id = location.pathname.split('/').at(-1);
78
- fetch('../recording/' + id).then((r) => (r.ok ? r.json() : r.text().then((t) => Promise.reject(new Error(t))))).then((kept) => {
79
- const scheme = kept.colorScheme ?? 'light';
80
- const events = JSON.parse(
81
- JSON.stringify(kept.events).replace(/\\(\\s*prefers-color-scheme\\s*:\\s*(light|dark)\\s*\\)/g, (_, s) =>
82
- s === scheme ? '(min-width: 0px)' : '(max-width: 0px) and (min-width: 1px)',
83
- ),
84
- );
85
- page.textContent = kept.page;
86
- page.href = kept.page;
87
-
88
- // A recording with the mic starts paused: a browser plays sound only after a click, which Play is.
89
- const clips = (kept.voice ?? []).map((c) => ({ ...c, audio: Object.assign(new Audio('../../voice/clip/' + c.id), { preload: 'auto' }) }));
90
- const t = Number.parseFloat(params.get('t') ?? '');
91
- // The player's frame, at most the window's room, the controls (80px) under it; 1:1 when bare.
92
- const size = () => bare
93
- ? { width: kept.viewport.width, height: kept.viewport.height }
94
- : embed
95
- ? { width: innerWidth, height: innerHeight - 80 }
96
- : { width: Math.min(kept.viewport.width, innerWidth - 32), height: Math.min(kept.viewport.height, innerHeight - 90 - 80 - 16) };
97
- const Player = rrwebPlayer.default ?? rrwebPlayer.Player ?? rrwebPlayer;
98
- const player = new Player({
99
- target: main,
100
- props: {
101
- events,
102
- ...size(),
103
- autoPlay: !Number.isFinite(t) && clips.length === 0,
104
- showController: !bare,
105
- speedOption: [1, 2, 4, 8],
106
- tags: { ${JSON.stringify(MARKS)}: '#12b358' },
107
- inactiveColor: '#3f3f46',
108
- mouseTail: false,
109
- },
110
- });
111
- addEventListener('resize', () => { player.$set(size()); player.triggerResize(); });
112
- const replayer = player.getReplayer();
113
- const total = player.getMetaData().totalTime;
114
-
115
- // The marks as they were at this point: the latest custom event's, in the player's scaled wrapper, moved with the replay's scroll.
116
- const marks = Object.assign(document.createElement('div'), { id: 'marks' });
117
- replayer.wrapper.append(marks);
118
- replayer.on('custom-event', (e) => { if (e.data.tag === ${JSON.stringify(MARKS)}) marks.innerHTML = e.data.payload.svg; });
119
-
120
- let playing = false;
121
- player.addEventListener('ui-update-player-state', (e) => { playing = e.payload === 'playing'; });
122
- const follow = () => {
123
- const win = replayer.iframe.contentWindow;
124
- if (win) marks.style.transform = 'translate(' + -win.scrollX + 'px,' + -win.scrollY + 'px)';
125
- const now = Math.min(replayer.getCurrentTime(), total);
126
- const speed = replayer.config.speed ?? 1;
127
- // Each clip plays while the replay is inside it, at its speed, kept within a few frames of the replay's time.
128
- for (const c of clips) {
129
- const into = now - c.at;
130
- if (!playing || into < 0 || into >= c.duration) { if (!c.audio.paused) c.audio.pause(); continue; }
131
- if (c.audio.playbackRate !== speed) c.audio.playbackRate = speed;
132
- if (Math.abs(c.audio.currentTime * 1000 - into) > 250 * speed) c.audio.currentTime = into / 1000;
133
- if (c.audio.paused) c.audio.play().catch(() => {});
134
- }
135
- requestAnimationFrame(follow);
136
- };
137
- follow();
138
-
139
- if (Number.isFinite(t)) player.goto(Math.min(Math.max(0, t * 1000), total), false);
140
- document.body.dataset.ready = '';
141
- }).catch((e) => { document.querySelector('main').innerHTML = '<p class="problem"></p>'; document.querySelector('.problem').textContent = e.message; });
142
- <\/script>
143
- </html>
144
- `;
145
- // src/plugins/recordings/index.ts
146
- /**
147
- * `deictic/recordings`: records the page with rrweb, for other plugins to attach (tasks does). No tab of
148
- * its own: `use('recordings').record()` shows a toolbar on the page (drag it to any edge) with annotate
149
- * mode's tools, where that plugin is loaded, a mic where the voice plugin is, and Stop and Discard. What's drawn while recording is in the
150
- * recording too, as custom events the replay draws.
151
- *
152
- * Recordings are kept under `.deictic/recordings`, the latest `keep`, as JSON: rrweb's
153
- * events, with the page, its viewport and how long it ran. `replay/<id>` plays one back in the browser.
154
- */
155
- const ID = /^[a-z0-9]+-[a-z0-9]+$/;
156
- /** What one recording may weigh: minutes of a busy page are a few MB. */
157
- const MAX = 52428800;
158
- /** rrweb's player (`rrweb-player`), served to the replay page: its build for a script tag, and its styles. */
159
- const player = (file) => {
160
- try {
161
- return join(dirname(createRequire(import.meta.url).resolve("rrweb-player")), file);
162
- } catch {
163
- return "";
164
- }
165
- };
166
- function recordings(options = {}) {
167
- const keep = options.keep ?? 20;
168
- let dir = "";
169
- let taken = 0;
170
- const pathOf = (id) => join(dir, `${id}.json`);
171
- const read = (id) => {
172
- if (!ID.test(id) || !existsSync(pathOf(id))) return void 0;
173
- return {
174
- data: new Uint8Array(readFileSync(pathOf(id))),
175
- name: `recording-${id}.json`,
176
- type: "application/json"
177
- };
178
- };
179
- const keepRecording = (data) => {
180
- const id = `${Date.now().toString(36).padStart(9, "0")}${(taken++ % 1296).toString(36).padStart(2, "0")}-${crypto.randomUUID().slice(0, 8)}`;
181
- mkdirSync(dir, { recursive: true });
182
- writeFileSync(pathOf(id), data);
183
- const kept = readdirSync(dir).filter((f) => f.endsWith(".json")).toSorted();
184
- for (const old of kept.slice(0, Math.max(0, kept.length - keep))) rmSync(join(dir, old));
185
- return id;
186
- };
187
- const file = (path, type) => {
188
- if (!existsSync(path)) return new Response("rrweb-player is missing: add it to your devDependencies", { status: 404 });
189
- return new Response(readFileSync(path), { headers: { "content-type": type } });
190
- };
191
- return definePlugin({
192
- name: "recordings",
193
- client: "deictic/recordings/client",
194
- clientOptions: { masking: {
195
- blockClass: options.blockClass ?? "rr-block",
196
- blockSelector: options.blockSelector,
197
- maskTextClass: options.maskTextClass ?? "rr-mask",
198
- maskTextSelector: options.maskTextSelector,
199
- maskAllInputs: options.maskAllInputs ?? false
200
- } },
201
- setup: ({ root }) => {
202
- dir = options.dir === void 0 ? keptIn(root, "recordings") : resolve(root, options.dir);
203
- return { read };
204
- },
205
- routes: {
206
- add: async (req) => {
207
- if (!(req.headers.get("content-type") ?? "").startsWith("application/json")) return Response.json({ problem: "send the recording as application/json" }, { status: 415 });
208
- const body = new Uint8Array(await req.arrayBuffer());
209
- if (body.byteLength > MAX) return Response.json({ problem: `a recording may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });
210
- let kept;
211
- try {
212
- kept = JSON.parse(new TextDecoder().decode(body));
213
- } catch {
214
- return Response.json({ problem: "the recording isn't JSON" }, { status: 400 });
215
- }
216
- if (!Array.isArray(kept.events) || kept.events.length === 0) return Response.json({ problem: "the recording has no events: record for a moment longer" }, { status: 400 });
217
- return Response.json({ id: keepRecording(body) });
218
- },
219
- recording: (req) => {
220
- const found = read(new URL(req.url).pathname.split("/").at(-1) ?? "");
221
- if (found === void 0) return new Response("no such recording, or not kept any more", { status: 404 });
222
- return new Response(found.data, { headers: {
223
- "content-type": found.type,
224
- "cache-control": "no-store"
225
- } });
226
- },
227
- replay: () => new Response(REPLAY, { headers: { "content-type": "text/html; charset=utf-8" } }),
228
- "player.js": () => file(player("rrweb-player.umd.min.cjs"), "text/javascript"),
229
- "player.css": () => file(player("style.css"), "text/css")
230
- }
231
- });
232
- }
233
- export { recordings as t };
234
-
235
- //# sourceMappingURL=recordings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"recordings.js","names":[],"sources":["../src/plugins/recordings/replay.ts","../src/plugins/recordings/index.ts"],"sourcesContent":["/**\n * The replay page, `replay/<id>`: rrweb's own player (`rrweb-player`), its timeline, speeds, skipping idle\n * stretches and fullscreen, sized to the window, with what it doesn't do drawn over it:\n *\n * - The page shows in the colour scheme it was recorded in, whatever the viewer's: the replay's iframe\n * answers `prefers-color-scheme` as the viewer's browser does, so the recorded CSS's queries are rewritten\n * before it's replayed, the recorded scheme's to always match and the other's never.\n * - The marks drawn while recording come as custom events, an SVG in page coordinates each; they're drawn\n * over the replay in the player's own scaled wrapper, moved with its scroll, rather than into its document,\n * which the replayer rebuilds. Each is a marker on the timeline.\n * - The voice clips play in step, at the player's speed. A recording with voice starts paused, as a browser\n * plays sound only after a click.\n *\n * `?t=<seconds>` opens it paused there, and `&bare` without the controls at the recorded size, 1:1, for a\n * screenshot; `?embed` is it filling a frame, with no header of its own (the lightbox's); `body[data-ready]` says\n * it's in place.\n */\nimport { MARKS } from './marks.ts';\n\nexport const REPLAY = `<!doctype html>\n<html lang=\"en\">\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Recording · deictic</title>\n<link rel=\"stylesheet\" href=\"../player.css\">\n<style>\n :root { color-scheme: dark; --accent: #12b358; }\n body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; background: #18181b; color: #fafafa; font: 13px/1.4 system-ui, sans-serif; }\n header { display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid #3f3f46; }\n header a { color: #a1a1aa; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n main { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 16px; }\n body.bare header { display: none; }\n body.bare main { padding: 0; }\n body.embed header { display: none; }\n body.embed main { padding: 0; }\n body.embed #main .rr-player { box-shadow: none; border-radius: 0; }\n #marks { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; }\n #marks svg { position: absolute; left: 0; top: 0; overflow: visible; }\n .problem { color: #f87171; padding: 16px; }\n /* rrweb-player, in the dark of the rest of deictic. Its rules repeat Svelte's scoping class, so these start\n from #main, which outweighs any number of classes. */\n #main .rr-player { background: #27272a; box-shadow: 0 12px 32px rgb(0 0 0 / 0.5); border-radius: 8px; overflow: hidden; }\n body.bare #main .rr-player { box-shadow: none; border-radius: 0; }\n #main .rr-player .rr-player__frame { background: #fff; }\n #main .rr-player .rr-controller { background: #18181b; border-top: 1px solid #3f3f46; border-radius: 0; }\n #main .rr-player .rr-timeline__time { color: #a1a1aa; font: 12px ui-monospace, monospace; }\n #main .rr-player .rr-progress { background: #3f3f46; border-color: #18181b; }\n #main .rr-player .rr-progress__step { background: color-mix(in srgb, var(--accent) 45%, transparent); }\n #main .rr-player .rr-progress__handler { background: var(--accent); }\n #main .rr-player .rr-controller__btns button { color: #e4e4e7; }\n #main .rr-player .rr-controller__btns button:disabled { color: #52525b; }\n #main .rr-player .rr-controller__btns button svg { fill: currentColor; }\n #main .rr-player .rr-controller__btns button.active { color: #04130b; background: var(--accent); }\n #main .rr-player .rr-controller__btns button:active { background: color-mix(in srgb, var(--accent) 60%, transparent); }\n #main .rr-player .switch .label { color: #e4e4e7; }\n #main .rr-player .switch.disabled .label { color: #52525b; }\n #main .rr-player .switch label:before { background: #52525b; }\n #main .rr-player .switch input:checked + label:before { background: var(--accent); }\n</style>\n<header>\n <strong>Recording</strong>\n <a id=\"page\" target=\"_blank\" rel=\"noreferrer\"></a>\n</header>\n<main id=\"main\"></main>\n<script src=\"../player.js\"></script>\n<script>\n const params = new URLSearchParams(location.search);\n const bare = params.has('bare');\n const embed = params.has('embed');\n if (bare) document.body.classList.add('bare');\n if (embed) document.body.classList.add('embed');\n const id = location.pathname.split('/').at(-1);\n fetch('../recording/' + id).then((r) => (r.ok ? r.json() : r.text().then((t) => Promise.reject(new Error(t))))).then((kept) => {\n const scheme = kept.colorScheme ?? 'light';\n const events = JSON.parse(\n JSON.stringify(kept.events).replace(/\\\\(\\\\s*prefers-color-scheme\\\\s*:\\\\s*(light|dark)\\\\s*\\\\)/g, (_, s) =>\n s === scheme ? '(min-width: 0px)' : '(max-width: 0px) and (min-width: 1px)',\n ),\n );\n page.textContent = kept.page;\n page.href = kept.page;\n\n // A recording with the mic starts paused: a browser plays sound only after a click, which Play is.\n const clips = (kept.voice ?? []).map((c) => ({ ...c, audio: Object.assign(new Audio('../../voice/clip/' + c.id), { preload: 'auto' }) }));\n const t = Number.parseFloat(params.get('t') ?? '');\n // The player's frame, at most the window's room, the controls (80px) under it; 1:1 when bare.\n const size = () => bare\n ? { width: kept.viewport.width, height: kept.viewport.height }\n : embed\n ? { width: innerWidth, height: innerHeight - 80 }\n : { width: Math.min(kept.viewport.width, innerWidth - 32), height: Math.min(kept.viewport.height, innerHeight - 90 - 80 - 16) };\n const Player = rrwebPlayer.default ?? rrwebPlayer.Player ?? rrwebPlayer;\n const player = new Player({\n target: main,\n props: {\n events,\n ...size(),\n autoPlay: !Number.isFinite(t) && clips.length === 0,\n showController: !bare,\n speedOption: [1, 2, 4, 8],\n tags: { ${JSON.stringify(MARKS)}: '#12b358' },\n inactiveColor: '#3f3f46',\n mouseTail: false,\n },\n });\n addEventListener('resize', () => { player.$set(size()); player.triggerResize(); });\n const replayer = player.getReplayer();\n const total = player.getMetaData().totalTime;\n\n // The marks as they were at this point: the latest custom event's, in the player's scaled wrapper, moved with the replay's scroll.\n const marks = Object.assign(document.createElement('div'), { id: 'marks' });\n replayer.wrapper.append(marks);\n replayer.on('custom-event', (e) => { if (e.data.tag === ${JSON.stringify(MARKS)}) marks.innerHTML = e.data.payload.svg; });\n\n let playing = false;\n player.addEventListener('ui-update-player-state', (e) => { playing = e.payload === 'playing'; });\n const follow = () => {\n const win = replayer.iframe.contentWindow;\n if (win) marks.style.transform = 'translate(' + -win.scrollX + 'px,' + -win.scrollY + 'px)';\n const now = Math.min(replayer.getCurrentTime(), total);\n const speed = replayer.config.speed ?? 1;\n // Each clip plays while the replay is inside it, at its speed, kept within a few frames of the replay's time.\n for (const c of clips) {\n const into = now - c.at;\n if (!playing || into < 0 || into >= c.duration) { if (!c.audio.paused) c.audio.pause(); continue; }\n if (c.audio.playbackRate !== speed) c.audio.playbackRate = speed;\n if (Math.abs(c.audio.currentTime * 1000 - into) > 250 * speed) c.audio.currentTime = into / 1000;\n if (c.audio.paused) c.audio.play().catch(() => {});\n }\n requestAnimationFrame(follow);\n };\n follow();\n\n if (Number.isFinite(t)) player.goto(Math.min(Math.max(0, t * 1000), total), false);\n document.body.dataset.ready = '';\n }).catch((e) => { document.querySelector('main').innerHTML = '<p class=\"problem\"></p>'; document.querySelector('.problem').textContent = e.message; });\n</script>\n</html>\n`;\n","/**\n * `deictic/recordings`: records the page with rrweb, for other plugins to attach (tasks does). No tab of\n * its own: `use('recordings').record()` shows a toolbar on the page (drag it to any edge) with annotate\n * mode's tools, where that plugin is loaded, a mic where the voice plugin is, and Stop and Discard. What's drawn while recording is in the\n * recording too, as custom events the replay draws.\n *\n * Recordings are kept under `.deictic/recordings`, the latest `keep`, as JSON: rrweb's\n * events, with the page, its viewport and how long it ran. `replay/<id>` plays one back in the browser.\n */\nimport { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, join, resolve } from 'node:path';\n\nimport { definePlugin } from '#src/index.ts';\nimport type { Masking, ResolvedMasking } from '#src/plugins/screenshots/index.ts';\nimport { keptIn } from '#src/tools/kept.ts';\n\nimport { REPLAY } from './replay.ts';\n\nexport { MARKS } from './marks.ts';\n\n/** A recording as the page knows it: its ID, where it plays back, and how long it ran, in milliseconds. */\nexport interface Recording {\n id: string;\n url: string;\n duration: number;\n /** What the mic took while it was on, where the voice plugin is loaded. */\n voice?: VoiceClip[];\n}\n\n/** A stretch of the mic in a recording: the voice plugin's clip, and when it starts in the recording, in milliseconds. */\nexport interface VoiceClip {\n id: string;\n at: number;\n duration: number;\n}\n\n/** The page's half, for other plugins' page halves. */\nexport interface Recorder {\n /**\n * Records the page, with the toolbar, until Stop: answers the recording, kept by the dev server, or\n * nothing when it's discarded. Rejects while another is going, or when it couldn't be kept.\n */\n record(): Promise<Recording | undefined>;\n /** Whether one is going. */\n recording(): boolean;\n}\n\n/** The server's half, for other plugins' server halves. */\nexport interface Recordings {\n /** A recording's JSON, or nothing for one not kept (any more). */\n read(id: string): { data: Uint8Array<ArrayBuffer>; name: string; type: 'application/json' } | undefined;\n}\n\n/** What the page sends, and what's kept: rrweb's events and what they can't say. */\nexport interface Kept {\n page: string;\n viewport: { width: number; height: number };\n /**\n * The colour scheme the page was in, which rrweb doesn't record: the replay shows it in the same, or a\n * page styled by `prefers-color-scheme` would take the replay's.\n */\n colorScheme?: 'light' | 'dark';\n startedAt: number;\n duration: number;\n events: unknown[];\n /** The mic's clips, played along with the replay. */\n voice?: VoiceClip[];\n}\n\ndeclare module 'deictic' {\n interface ServerApis {\n recordings: Recordings;\n }\n interface ClientApis {\n recordings: Recorder;\n }\n}\n\nexport interface RecordingsOptions extends Masking {\n /** How many recordings to keep, the latest: 20 by default. */\n keep?: number;\n /** Where they're kept, from the project's root: `.deictic/recordings` by default. */\n dir?: string;\n}\n\nconst ID = /^[a-z0-9]+-[a-z0-9]+$/;\n/** What one recording may weigh: minutes of a busy page are a few MB. */\nconst MAX = 50 * 1024 * 1024;\n\n/** rrweb's player (`rrweb-player`), served to the replay page: its build for a script tag, and its styles. */\nconst player = (file: string) => {\n try {\n return join(dirname(createRequire(import.meta.url).resolve('rrweb-player')), file);\n } catch {\n // Not installed: `file` answers what to add.\n return '';\n }\n};\n\nexport function recordings(options: RecordingsOptions = {}) {\n const keep = options.keep ?? 20;\n let dir = '';\n let taken = 0;\n const pathOf = (id: string) => join(dir, `${id}.json`);\n const read: Recordings['read'] = (id) => {\n if (!ID.test(id) || !existsSync(pathOf(id))) return undefined;\n return { data: new Uint8Array(readFileSync(pathOf(id))), name: `recording-${id}.json`, type: 'application/json' };\n };\n const keepRecording = (data: Uint8Array) => {\n // Sorts by when it was made, which is what pruning keeps by: the count orders two in one millisecond.\n const id = `${Date.now().toString(36).padStart(9, '0')}${(taken++ % 1296).toString(36).padStart(2, '0')}-${crypto.randomUUID().slice(0, 8)}`;\n mkdirSync(dir, { recursive: true });\n writeFileSync(pathOf(id), data);\n const kept = readdirSync(dir)\n .filter((f) => f.endsWith('.json'))\n .toSorted();\n for (const old of kept.slice(0, Math.max(0, kept.length - keep))) rmSync(join(dir, old));\n return id;\n };\n const file = (path: string, type: string) => {\n if (!existsSync(path)) return new Response('rrweb-player is missing: add it to your devDependencies', { status: 404 });\n return new Response(readFileSync(path), { headers: { 'content-type': type } });\n };\n\n return definePlugin<never, never, never, Recordings>({\n name: 'recordings',\n client: 'deictic/recordings/client',\n clientOptions: {\n masking: {\n blockClass: options.blockClass ?? 'rr-block',\n blockSelector: options.blockSelector,\n maskTextClass: options.maskTextClass ?? 'rr-mask',\n maskTextSelector: options.maskTextSelector,\n maskAllInputs: options.maskAllInputs ?? false,\n } satisfies ResolvedMasking,\n },\n setup: ({ root }) => {\n dir = options.dir === undefined ? keptIn(root, 'recordings') : resolve(root, options.dir);\n return { read };\n },\n routes: {\n // What the page recorded, as JSON.\n add: async (req) => {\n if (!(req.headers.get('content-type') ?? '').startsWith('application/json'))\n return Response.json({ problem: 'send the recording as application/json' }, { status: 415 });\n const body = new Uint8Array(await req.arrayBuffer());\n if (body.byteLength > MAX)\n return Response.json({ problem: `a recording may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });\n let kept: Partial<Kept>;\n try {\n kept = JSON.parse(new TextDecoder().decode(body)) as Partial<Kept>;\n } catch {\n return Response.json({ problem: \"the recording isn't JSON\" }, { status: 400 });\n }\n if (!Array.isArray(kept.events) || kept.events.length === 0)\n return Response.json({ problem: 'the recording has no events: record for a moment longer' }, { status: 400 });\n return Response.json({ id: keepRecording(body) });\n },\n // `recording/<id>`: the JSON, for the replay page.\n recording: (req) => {\n const found = read(new URL(req.url).pathname.split('/').at(-1) ?? '');\n if (found === undefined) return new Response('no such recording, or not kept any more', { status: 404 });\n return new Response(found.data, { headers: { 'content-type': found.type, 'cache-control': 'no-store' } });\n },\n // `replay/<id>`: a page that plays it back.\n replay: () => new Response(REPLAY, { headers: { 'content-type': 'text/html; charset=utf-8' } }),\n 'player.js': () => file(player('rrweb-player.umd.min.cjs'), 'text/javascript'),\n 'player.css': () => file(player('style.css'), 'text/css'),\n },\n });\n}\n\nexport default recordings;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAiFJ,KAAK,UAAU,KAAK,EAAE;;;;;;;;;;;;8DAYsB,KAAK,UAAU,KAAK,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC1BpF,MAAM,KAAK;;AAEX,MAAM,MAAM;;AAGZ,MAAM,UAAU,SAAiB;CAC/B,IAAI;EACF,OAAO,KAAK,QAAQ,cA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C,CAAC,GAAG,EAAE,KAAK,EAAE;IACpE,IAAI,UAAU,KAAA,GAAW,OAAO,IAAI,SAAS,2CAA2C,EAAE,QAAQ,IAAI,CAAC;IACvG,OAAO,IAAI,SAAS,MAAM,MAAM,EAAE,SAAS;KAAE,gBAAgB,MAAM;KAAM,iBAAiB;IAAW,EAAE,CAAC;GAC1G;GAEA,cAAc,IAAI,SAAS,QAAQ,EAAE,SAAS,EAAE,gBAAgB,2BAA2B,EAAE,CAAC;GAC9F,mBAAmB,KAAK,OAAO,0BAA0B,GAAG,iBAAiB;GAC7E,oBAAoB,KAAK,OAAO,WAAW,GAAG,UAAU;EAC1D;CACF,CAAC;AACH"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"shortcut.js","names":[],"sources":["../src/shortcut.ts"],"sourcesContent":["/**\n * A gesture: the keys held to outline the element under the pointer, and the button that, with them\n * held, opens the popup there. deictic's own (`MASTER` by default) opens the tab used last; a\n * plugin's, which it takes as its `shortcut` option and has none by default, opens its tab. The\n * bundler's plugin checks them all as it starts, so a wrong one, or two alike, fails the dev server,\n * not the page. Both halves import it: it must\n * stay dependency-free.\n */\n\n/** A modifier key, as `KeyboardEvent.key` names it. */\nexport type Modifier = 'Alt' | 'Control' | 'Meta' | 'Shift';\n\nexport interface Shortcut {\n /** Held, and no other, to outline elements. */\n modifiers?: Modifier[];\n /** Pressed with them to open the panel. `'left'` unset. */\n button?: 'left' | 'middle' | 'right';\n}\n\nconst FLAGS = { Alt: 'altKey', Control: 'ctrlKey', Meta: 'metaKey', Shift: 'shiftKey' } as const;\nconst BUTTONS = { left: 0, middle: 1, right: 2 } as const;\n\n/** deictic's own shortcut, unless `deictic({ shortcut })` names another or `false`. */\nexport const MASTER: Required<Shortcut> = { modifiers: ['Alt'], button: 'left' };\n\n/** The name deictic's own shortcut goes by in a problem. */\nexport const OWN = 'deictic';\n\n/** deictic's own shortcut as given, with its default, before it's checked. */\nexport const ownShortcut = (given: Shortcut | false | undefined) => (given === false ? undefined : (given ?? MASTER));\n\n/** The shortcut with its button's default and its modifiers in one order, or an error saying what to write instead. */\nexport function checkShortcut(plugin: string, shortcut: Shortcut): Required<Shortcut> {\n const { modifiers = [], button = 'left' } = shortcut;\n const named = Object.keys(FLAGS).join(\"', '\");\n if (!Array.isArray(modifiers) || modifiers.length === 0) {\n throw new Error(\n `deictic: ${plugin}'s shortcut.modifiers is empty: hold at least one of '${named}', or every click would open the popup`,\n );\n }\n for (const m of modifiers)\n if (!Object.hasOwn(FLAGS, m)) throw new Error(`deictic: ${plugin}'s shortcut.modifiers has '${m}': name one of '${named}'`);\n\n if (!Object.hasOwn(BUTTONS, button))\n throw new Error(`deictic: ${plugin}'s shortcut.button is '${button}': name one of '${Object.keys(BUTTONS).join(\"', '\")}'`);\n\n const order = Object.keys(FLAGS);\n return { modifiers: [...new Set(modifiers)].toSorted((a, b) => order.indexOf(a) - order.indexOf(b)), button };\n}\n\n/**\n * Each shortcut checked, in order, or nothing where there's none: none may be another's, or only the\n * first would ever open. deictic's own goes first, named `OWN`.\n */\nexport function checkShortcuts(plugins: readonly { name: string; shortcut?: Shortcut }[]): (Required<Shortcut> | undefined)[] {\n const taken = new Map<string, string>();\n return plugins.map(({ name, shortcut }) => {\n if (shortcut === undefined) return undefined;\n const checked = checkShortcut(name, shortcut);\n const key = nameOf(checked);\n const other = taken.get(key);\n if (other !== undefined) throw new Error(`deictic: ${name} and ${other} both open on ${key}: give one of them another \\`shortcut\\``);\n taken.set(key, name);\n return checked;\n });\n}\n\n/** How a shortcut reads, for a problem or a label: `Alt+Shift`, `Control+right-click`. */\nexport const nameOf = ({ modifiers = [], button = 'left' }: Shortcut) =>\n [...modifiers, ...(button === 'left' ? [] : [`${button}-click`])].join('+');\n\nexport interface Gesture {\n /** Whether exactly the shortcut's modifiers are down: AltGr, which is Control and Alt, isn't Alt. */\n held: (e: MouseEvent | KeyboardEvent) => boolean;\n /** The shortcut's button, as `MouseEvent.button` numbers it. */\n button: number;\n}\n\nexport function gestureOf(shortcut: Required<Shortcut>): Gesture {\n const on = new Set<string>(shortcut.modifiers);\n const flags = Object.entries(FLAGS);\n return { held: (e) => flags.every(([key, flag]) => e[flag] === on.has(key)), button: BUTTONS[shortcut.button] };\n}\n"],"mappings":";AAmBA,MAAM,QAAQ;CAAE,KAAK;CAAU,SAAS;CAAW,MAAM;CAAW,OAAO;AAAW;AACtF,MAAM,UAAU;CAAE,MAAM;CAAG,QAAQ;CAAG,OAAO;AAAE;;AAG/C,MAAa,SAA6B;CAAE,WAAW,CAAC,KAAK;CAAG,QAAQ;AAAO;;AAG/E,MAAa,MAAM;;AAGnB,MAAa,eAAe,UAAyC,UAAU,QAAQ,KAAA,IAAa,SAAS;;AAG7G,SAAgB,cAAc,QAAgB,UAAwC;CACpF,MAAM,EAAE,YAAY,CAAC,GAAG,SAAS,WAAW;CAC5C,MAAM,QAAQ,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,MAAM;CAC5C,IAAI,CAAC,MAAM,QAAQ,SAAS,KAAK,UAAU,WAAW,GACpD,MAAM,IAAI,MACR,YAAY,OAAO,wDAAwD,MAAM,uCACnF;CAEF,KAAK,MAAM,KAAK,WACd,IAAI,CAAC,OAAO,OAAO,OAAO,CAAC,GAAG,MAAM,IAAI,MAAM,YAAY,OAAO,6BAA6B,EAAE,kBAAkB,MAAM,EAAE;CAE5H,IAAI,CAAC,OAAO,OAAO,SAAS,MAAM,GAChC,MAAM,IAAI,MAAM,YAAY,OAAO,yBAAyB,OAAO,kBAAkB,OAAO,KAAK,OAAO,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE;CAE3H,MAAM,QAAQ,OAAO,KAAK,KAAK;CAC/B,OAAO;EAAE,WAAW,CAAC,GAAG,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,UAAU,GAAG,MAAM,MAAM,QAAQ,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC;EAAG;CAAO;AAC9G;;;;;AAMA,SAAgB,eAAe,SAA+F;CAC5H,MAAM,wB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IAAY;IAAkB;IAAgB;;;EAE7D;IAAU;IAAY;;;EAEtB,cAAc;;;;;;iBAOC;EACf;;EAEA;EACA;EACA;;EAEA,QAAQ;;EAER;;EAEA;IAAY;IAAqB;IAAoB;IAAe;;;;iBAIrD;EACf;EACA;;iBAGe;EACf;EACA;EACA;EACA,QAAQ;;EAER;;;iBAIe;EACf;EACA;EACA;EACA;;;;;;iBAOe,gBAAgB;EAC/B;;;YAIU,OAAO,QAAQ,SAAS;wBAOpB,MAAM,UAAS,iCAAiB,aAAA,OAAA,QAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/plugins/tasks/index.ts"],"sourcesContent":["/**\n * `deictic/tasks`: open its tab on an element to add a task about it to a Vercel Board\n * (`@vercel/board`). The task says what to change, in the words typed, and where: the element's file,\n * line and tag, the page and the project, all as labels beside the short facts (viewport, how many, where\n * it is in the shot). Whatever works the board's tasks (a person, or an agent of theirs claiming them) takes it\n * from there; deictic only adds them.\n *\n * Adding one is a change like any other: undo cancels the task, while no one has claimed it, and redo\n * adds it again, as a new task. Each task carries `deictic.at=<file:line:column>`, so the panel\n * lists the ones about the element clicked, until its line moves.\n */\nimport { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport type { Board } from '@vercel/board';\n\nimport { definePlugin, Refusal, type ServerContext, type Shortcut, type Source, type Target } from '#src/index.ts';\n// For `use('screenshots')`'s type: the plugin may not be loaded, and nothing of it runs here.\nimport type { Recordings } from '#src/plugins/recordings/index.ts';\nimport type { Box } from '#src/plugins/screenshots/index.ts';\nimport type { Clips } from '#src/plugins/voice/index.ts';\n\n/** What the plugin uses of a board: `board()` from `@vercel/board` is one. */\nexport type TaskBoard = Pick<Board, 'tasks' | 'thread' | 'discovery' | 'upload' | 'edit'>;\n\nexport interface TasksOptions {\n /**\n * The board, as `@vercel/board`'s `board()` answers it: by default the one `BOARD_URL` names (`npx vb serve`\n * runs one on this machine), or your team's default board, through `vercel login`.\n */\n board?: TaskBoard;\n /** The channel tasks go to: `deictic` by default. */\n channel?: string;\n /**\n * The project the tasks are about, as the `deictic.project` label, to tell them apart on a board several\n * projects share: by default the `name` in the root's `package.json`, and no label where it has none.\n */\n project?: string;\n /** Labels every task gets besides deictic's own, for whoever works them to filter by (`vb tail --label`). None by default. */\n labels?: Record<string, string>;\n /**\n * Where the panel links the channel to, for a person to see its tasks, and with `task`, where it links\n * that task's ID to. By default the board's own pages when it's one `vb serve` runs on this machine\n * (`http://127.0.0.1:4100/c/deictic`, and `?thread=<id>` on it), and none for another board, whose pages\n * deictic can't know.\n */\n link?: (channel: string, task?: string) => string | undefined;\n /** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */\n shortcut?: Shortcut;\n}\n\nexport interface Task {\n id: string;\n /** The first line of what was typed. */\n title: string;\n /** What was typed, whole: what an edit changes. */\n text: string;\n state: string;\n /** Whether it can still be edited or deleted: no one has claimed it. */\n open: boolean;\n /** Its page on the board, when there's one to link to. */\n link?: string;\n}\n\nexport interface Model {\n channel: string;\n /** The channel's page, when there's one to link to. */\n link?: string;\n /** Tasks about this element, oldest first, canceled ones left out. */\n tasks: Task[];\n}\n\n/**\n * What the Task tab asks for: a new task (an `Op`), other words for one it lists (`edit` is its ID), or\n * that one deleted (`remove` is its ID), which cancels it on the board.\n */\nexport type Change = Op | { edit: string; text: string } | { remove: string };\n\n/** A new task: what the page knows and the source doesn't. */\nexport interface Op {\n text: string;\n /** The page's URL. */\n page: string;\n viewport: { width: number; height: number };\n /**\n * What was under the pointer inside the element, where nothing marked it (a dependency's markup, or a\n * shadow root's): its path from the element, and its HTML, cut short.\n */\n pointed?: { path: string; html: string };\n /** How many elements on the page come from the same place in the source. */\n count: number;\n /**\n * Shots the screenshots plugin took of it, to attach, where that plugin is loaded: each with where the\n * element is in it, and the marks drawn on it in the panel, where there are any.\n */\n screenshots?: { id: string; box: Box; marks?: Marks }[];\n /**\n * Recordings the recordings plugin made, to attach, where that plugin is loaded: how long each ran,\n * where it plays back, and the voice plugin's clips of the mic in it, attached too.\n */\n recordings?: { id: string; duration: number; replay: string; voice?: string[] }[];\n /** Voice notes the voice plugin kept, to attach, where that plugin is loaded, and how long each runs. */\n voice?: { id: string; duration: number }[];\n /** The page's annotations, where that plugin is loaded and there are any: how many, and their notes' text. */\n annotations?: Marks;\n}\n\n/**\n * A task the Task tab just added, as the page hears of it: the `detail` of a `deictic:task` event on `window`, for a\n * page that shows its own tasks (deictic's playground lists them as a board does).\n */\nexport interface TaskAdded {\n id: string;\n /** The first line of what was typed. */\n title: string;\n state: string;\n channel: string;\n /** The element: its file, line and column, and its tag. */\n target: Target;\n /** The page's URL. */\n page: string;\n /** How many of each were attached; `marks` counts those drawn on shots and on the page. */\n attached: { screenshots: number; recordings: number; voice: number; marks: number };\n}\n\n/** Marks, as a task tells of them: how many, and what the notes among them say. */\nexport interface Marks {\n count: number;\n notes: string[];\n}\n\nexport interface Added {\n channel: string;\n id: string;\n text: string;\n labels: Record<string, string>;\n /** What's attached, by the board's IDs: kept, so a redo attaches the same without uploading it again. */\n attachments?: string[];\n}\n\n/** A task's words changed: its message's whole text before and after. */\nexport interface Edited {\n kind: 'edited';\n id: string;\n before: string;\n after: string;\n}\n\n/**\n * A task deleted in the panel: canceled on the board, for good, as a board has it. So it's kept whole, and\n * an undo adds it again, as a new task whose ID the record then has.\n */\nexport interface Removed extends Added {\n kind: 'removed';\n}\n\n/** What the history keeps of a change: a task added has no `kind`, as it had none before there were others. */\nexport type Kept = Added | Edited | Removed;\n\nconst AT = 'deictic.at';\n/** What parts what was typed from the rest of a task's text. */\nconst REST = '\\n---\\n';\nconst OPEN = new Set(['waiting', 'ready', 'blocked']);\n\nexport function tasks(options: TasksOptions = {}) {\n const channel = options.channel ?? 'deictic';\n let team: Promise<TaskBoard> | undefined;\n // Loaded when first used, so a project that doesn't add this plugin needn't install the SDK.\n const boardOf = () => (team ??= options.board ? Promise.resolve(options.board) : import('@vercel/board').then((m) => m.board()));\n let link: Promise<string | undefined> | undefined;\n // Asked once, unless asking failed: no link is no reason to keep the panel from showing the tasks.\n const linkOf = () =>\n (link ??= (options.link ? Promise.resolve(options.link(channel)) : boardOf().then((b) => localPage(b, channel))).catch(() => {\n link = undefined;\n return undefined;\n }));\n /** A task's page: what `link` says, or its thread on the channel's own page on this machine. */\n const taskLink = (page: string | undefined, id: string) =>\n options.link ? options.link(channel, id) : page === undefined ? undefined : `${page}?thread=${encodeURIComponent(id)}`;\n /**\n * One of this channel's tasks about an element, while it's still open: the page names it by ID, so\n * nothing else on the board is its to change, nor a task someone has taken up.\n */\n const openTask = async (team: TaskBoard, id: string, verb: string) => {\n const { message } = await team.thread(id);\n if (message.channel !== channel || message.labels[AT] === undefined)\n throw new Refusal(`#${id} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);\n\n const { task } = message;\n if (task !== undefined && !OPEN.has(task.state)) {\n throw new Refusal(\n `task ${id} is ${task.state}${task.claim ? ` by ${task.claim.actor}` : ''} now: ${verb} it on the board if you still mean to`,\n );\n }\n return message;\n };\n /** Cancels an open task of ours, and answers it as it was. */\n const cancel = async (id: string, reason: string) => {\n const team = await boardOf();\n const message = await openTask(team, id, 'cancel');\n await team.tasks.cancel(id, reason);\n return message;\n };\n /** Puts a task's text from one to the other, unless it reads as neither any more. */\n const rewrite = async (id: string, from: string, to: string) => {\n const team = await boardOf();\n const message = await openTask(team, id, 'edit');\n if (message.text === to) return;\n if (message.text !== from) throw new Refusal(`task ${id} has been edited since: change it on the board`);\n await team.edit(id, to, { revision: message.revision });\n };\n const create = async (record: Omit<Added, 'id'>): Promise<Added> => {\n const { task } = await (\n await boardOf()\n ).tasks.create(record.channel, {\n text: record.text,\n labels: record.labels,\n ...(record.attachments === undefined ? {} : { attachments: record.attachments }),\n });\n return { ...record, id: task.id };\n };\n\n // Kept from `setup`, to `use` another plugin when an op asks for it.\n let context: ServerContext | undefined;\n let project = options.project;\n /** The screenshots and recordings to attach, uploaded to the board, or nothing when there are none. */\n const attach = async (op: Op): Promise<string[] | undefined> => {\n // All read first, so one no longer kept uploads none.\n const files = [\n ...(op.screenshots ?? []).map(({ id }) => {\n const shot = context?.use('screenshots')?.read(id);\n if (shot === undefined) throw new Refusal(`screenshot ${id} isn't kept any more: take it again`);\n return shot;\n }),\n ...(op.recordings ?? []).map(({ id }) => {\n const recording: ReturnType<Recordings['read']> = context?.use('recordings')?.read(id);\n if (recording === undefined) throw new Refusal(`recording ${id} isn't kept any more: record it again`);\n return recording;\n }),\n ...[...(op.recordings ?? []).flatMap((r) => r.voice ?? []), ...(op.voice ?? []).map((v) => v.id)].map((id) => {\n const clip: ReturnType<Clips['read']> = context?.use('voice')?.read(id);\n if (clip === undefined) throw new Refusal(`voice clip ${id} isn't kept any more: record it again`);\n return clip;\n }),\n ];\n if (files.length === 0) return undefined;\n const team = await boardOf();\n return Promise.all(files.map(async (file) => (await team.upload(file)).id));\n };\n\n return definePlugin<Model, Change, Kept>({\n name: 'tasks',\n client: 'deictic/tasks/client',\n shortcut: options.shortcut,\n setup: (given) => {\n context = given;\n project ??= nameOf(given.root);\n },\n read: (_source, target) =>\n asked(async () => {\n const [{ tasks: found }, page] = await Promise.all([\n (await boardOf()).tasks.list({ channel, label: { [AT]: atOf(target) }, state: 'all' }),\n linkOf(),\n ]);\n return {\n channel,\n ...(page === undefined ? {} : { link: page }),\n tasks: found\n .map(({ message }) => {\n const text = message.text.split(REST, 1)[0]!;\n const state = message.task?.state ?? 'ready';\n const to = taskLink(page, message.id);\n return {\n id: message.id,\n title: text.split('\\n', 1)[0]!,\n text,\n state,\n open: OPEN.has(state),\n ...(to === undefined ? {} : { link: to }),\n };\n })\n .filter((t) => t.state !== 'canceled'),\n };\n }),\n apply: (source, target, op) => {\n if ('remove' in op) {\n return asked(async () => {\n const message = await cancel(op.remove, 'deleted in deictic');\n // The board's own labels (`board.task`) are its to set on the task an undo adds.\n const labels = Object.fromEntries(Object.entries(message.labels).filter(([key]) => !key.startsWith('board.')));\n const attachments = message.attachments.map((a) => a.id);\n const kept = { channel, id: op.remove, text: message.text, labels, ...(attachments.length === 0 ? {} : { attachments }) };\n return { done: { kind: 'removed' as const, ...kept } };\n });\n }\n // A new task may go without words where something attached says it; a task's words are never changed to none.\n if (op.text.trim() === '' && ('edit' in op || shown(op) === undefined)) throw new Refusal('say what should change first');\n if ('edit' in op) {\n return asked(async () => {\n const before = (await openTask(await boardOf(), op.edit, 'edit')).text;\n // What follows the words (what's attached, what was pointed at) stays as it was.\n const rest = before.includes(REST) ? before.slice(before.indexOf(REST)) : '';\n const after = clip(op.text.trim(), 10_000 - rest.length) + rest;\n await rewrite(op.edit, before, after);\n return { done: { kind: 'edited' as const, id: op.edit, before, after } };\n });\n }\n const labels = {\n ...options.labels,\n ...(project === undefined ? {} : { 'deictic.project': clip(project, LABEL) }),\n ...labelsOf(source, target, op),\n };\n return asked(async () => {\n const attachments = await attach(op);\n return {\n done: await create({ channel, text: textOf(op), labels, ...(attachments === undefined ? {} : { attachments }) }),\n };\n });\n },\n undo: (record) =>\n asked(async () => {\n if (!('kind' in record)) {\n await cancel(record.id, 'undone in deictic');\n return undefined;\n }\n if (record.kind === 'edited') {\n await rewrite(record.id, record.after, record.before);\n return undefined;\n }\n const { kind, id: _, ...task } = record;\n return { kind, ...(await create(task)) };\n }),\n redo: (record) =>\n asked(async () => {\n if (!('kind' in record)) {\n const { id: _, ...added } = record;\n return create(added);\n }\n if (record.kind === 'edited') {\n await rewrite(record.id, record.before, record.after);\n return record;\n }\n await cancel(record.id, 'deleted in deictic');\n return record;\n }),\n describe: (op, before) => {\n const named = (id: string) => `task \"${clip(before.tasks.find((t) => t.id === id)?.title ?? `#${id}`, 60)}\"`;\n if ('remove' in op) return `delete ${named(op.remove)}`;\n if ('edit' in op) return `edit ${named(op.edit)}`;\n return `task \"${clip(wordsOf(op).split('\\n', 1)[0]!, 60)}\"`;\n },\n });\n}\n\n/**\n * The channel's page on a board `vb serve` runs on this machine, which serves its pages beside its API:\n * `/api/board` there, `/c/<channel>` beside it. Nothing for any other board.\n */\nasync function localPage(team: TaskBoard, channel: string): Promise<string | undefined> {\n const url = new URL((await team.discovery()).url);\n if (!['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname) || !url.pathname.endsWith('/api/board')) return undefined;\n return `${url.origin}${url.pathname.slice(0, -'/api/board'.length)}/c/${channel.split('/').map(encodeURIComponent).join('/')}`;\n}\n\nconst plural = (count: number, word: string) => `${count} ${word}${count === 1 ? '' : 's'}`;\nconst said = (notes: string[]) => (notes.length === 0 ? '' : `; the notes say: ${notes.map((n) => JSON.stringify(n)).join(', ')}`);\n\n/** What was marked on the page: how many marks, and what the notes say. */\nfunction annotated({ count, notes }: Marks, shots: number, recordings: number): string {\n const where = [\n ...(shots === 0 ? [] : [shots === 1 ? 'the screenshot' : 'the screenshots']),\n ...(recordings === 0 ? [] : [recordings === 1 ? 'the recording' : 'the recordings']),\n ];\n const drawn = where.length === 0 ? '' : `, drawn in ${where.join(' and ')}`;\n return `${plural(count, 'mark')} on the page${drawn}${said(notes)}`;\n}\n\n/** How long each recording ran, and where it plays back, while the dev server keeps it. */\nfunction recordingsOf(recordings: NonNullable<Op['recordings']>): string[] {\n return recordings.map(({ duration, replay, voice }, i) => {\n const name = recordings.length === 1 ? 'A recording' : `Recording ${i + 1}`;\n const spoken = voice === undefined || voice.length === 0 ? '' : `, with the voice (${voice.map((id) => `voice-${id}`).join(', ')})`;\n return `${name}, ${clock(duration)} long, attached as rrweb events${spoken}; it replays at ${replay}`;\n });\n}\n\n/** How long each voice note runs, and the attachment it's in. */\nfunction voicesOf(voice: NonNullable<Op['voice']>): string[] {\n return voice.map(({ id, duration }, i) => {\n const name = voice.length === 1 ? 'A voice note' : `Voice note ${i + 1}`;\n return `${name}, ${clock(duration)} long, attached as voice-${id}`;\n });\n}\n\nconst clock = (ms: number) => {\n const s = Math.round(ms / 1000);\n return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;\n};\n\n/**\n * What was drawn on each shot, and with several, where the element is in each: nothing marks it there. One\n * shot's place is the `deictic.position` and `deictic.size` labels, so a shot with no marks has no line.\n */\nfunction shotsOf(shots: NonNullable<Op['screenshots']>): string[] {\n const [only] = shots;\n if (shots.length === 1 && only !== undefined) {\n const { marks } = only;\n return marks === undefined || marks.count === 0\n ? []\n : [`The screenshot has ${plural(marks.count, 'mark')} drawn on it${said(marks.notes)}`];\n }\n return shots.map(({ box, marks }, i) => {\n const drawn = marks === undefined || marks.count === 0 ? '' : `, with ${plural(marks.count, 'mark')} drawn on it${said(marks.notes)}`;\n const [x, y, width, height] = boxOf(box);\n return `In screenshot ${i + 1} at x ${x}, y ${y}, ${width}×${height}${drawn}`;\n });\n}\n\n/** A box as `x,y,width,height`, in whole CSS pixels from the shot's top left. */\nconst boxOf = ({ x, y, width, height }: Box) => [x, y, width, height].map(Math.round);\n\n/** A label's value: a board holds 256 characters. */\nconst LABEL = 256;\n\n/** The project's name: the `name` in the root's `package.json`, or nothing where it has none. */\nfunction nameOf(root: string): string | undefined {\n try {\n const { name } = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as { name?: unknown };\n return typeof name === 'string' && name !== '' ? name : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The facts about the element, as labels: short values a script reads without parsing the text, and a watch\n * filters by. `deictic.line` is the opening tag's first line as the task saw it, to tell later that it moved.\n * `deictic.url` is the page's whole URL, where a label holds it: `textOf` says a longer one.\n */\nfunction labelsOf({ code, element }: Source, target: Target, op: Op): Record<string, string> {\n const [shot] = op.screenshots ?? [];\n return {\n [AT]: atOf(target),\n 'deictic.tag': target.tag,\n 'deictic.line': clip(code.slice(element.start, element.end).split('\\n', 1)[0]!.trim(), LABEL),\n 'deictic.page': clip(new URL(op.page).pathname, LABEL),\n ...(op.page.length <= LABEL ? { 'deictic.url': op.page } : {}),\n 'deictic.viewport': `${op.viewport.width}x${op.viewport.height}`,\n 'deictic.count': String(op.count),\n ...(op.screenshots?.length === 1 && shot !== undefined ? placeOf(shot.box) : {}),\n };\n}\n\n/** Where the element is in the one shot, from its top left, and how big: `87,387` and `138x32`, as the viewport is written. */\nfunction placeOf(box: Box): Record<string, string> {\n const [x, y, width, height] = boxOf(box);\n return { 'deictic.position': `${x},${y}`, 'deictic.size': `${width}x${height}` };\n}\n\nconst atOf = ({ loc }: Target) => `${loc.file}:${loc.line}:${loc.column}`;\n\n/**\n * The task's text: what was typed, and after a `---` only what no label holds: what's attached and drawn, what\n * was pointed at inside the element, and a URL too long for one. A board holds 10,000 characters.\n */\nfunction textOf(op: Op): string {\n const more = [\n ...(op.page.length <= LABEL ? [] : [op.page]),\n ...shotsOf(op.screenshots ?? []),\n ...recordingsOf(op.recordings ?? []),\n ...voicesOf(op.voice ?? []),\n ...(op.annotations === undefined ? [] : [annotated(op.annotations, op.screenshots?.length ?? 0, op.recordings?.length ?? 0)]),\n ...(op.pointed === undefined ? [] : [`Pointed at, inside it: \\`${op.pointed.path}\\``, fence(op.pointed.html, 'html')]),\n ];\n const tail = more.length === 0 ? '' : REST + more.join('\\n');\n return clip(wordsOf(op), 10_000 - tail.length) + tail;\n}\n\n/** The task's words: what was typed, or where nothing was, a line that sends the reader to what's attached. */\nconst wordsOf = (op: Op) => (op.text.trim() === '' ? (shown(op) ?? '') : op.text.trim());\n\n/** `See the recording and the voice note`: what stands for the words of a task sent with none, where something is attached. */\nfunction shown(op: Op): string | undefined {\n const named = (count: number | undefined, word: string) =>\n count === undefined || count === 0 ? [] : [`the ${word}${count === 1 ? '' : 's'}`];\n const attached = [\n ...named(op.screenshots?.length, 'screenshot'),\n ...named(op.recordings?.length, 'recording'),\n ...named(op.voice?.length, 'voice note'),\n ];\n return attached.length === 0 ? undefined : `See ${new Intl.ListFormat('en', { type: 'conjunction' }).format(attached)}`;\n}\n\nconst fence = (text: string, lang: string) => `\\`\\`\\`\\`${lang}\\n${clip(text, 1500)}\\n\\`\\`\\`\\``;\n\nconst clip = (text: string, max: number) => (text.length <= max ? text : `${text.slice(0, max - 1)}…`);\n\n/** The board's answer, or a `Refusal` saying what to do when there's no board to ask or it said no. */\nasync function asked<T>(ask: () => Promise<T>): Promise<T> {\n try {\n return await ask();\n } catch (e) {\n if (e instanceof Refusal) throw e;\n const { code, message, hint } = e as { code?: unknown; message?: string; hint?: string };\n if (typeof code === 'string') throw new Refusal(`the board says: ${message}${hint === undefined ? '' : ` (${hint})`}`, { cause: e });\n throw new Refusal(\n `can't reach the board (${message ?? String(e)}): run \\`npx vb serve\\` and set BOARD_URL for the dev server, or \\`vercel login\\``,\n { cause: e },\n );\n }\n}\n\nexport default tasks;\n"],"mappings":";;;;;;;;;;;;;;;AA+JA,MAAM,KAAK;;AAEX,MAAM,OAAO;AACb,MAAM,uBAAO,IAAI,IAAI;CAAC;CAAW;CAAS;AAAS,CAAC;AAEpD,SAAgB,MAAM,UAAwB,CAAC,GAAG;CAChD,MAAM,UAAU,QAAQ,WAAW;CACnC,IAAI;CAEJ,MAAM,gBAAiB,SAAS,QAAQ,QAAQ,QAAQ,QAAQ,QAAQ,KAAK,IAAI,OAAO,gBAAgB,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC;CAC9H,IAAI;CAEJ,MAAM,eACH,UAAU,QAAQ,OAAO,QAAQ,QAAQ,QAAQ,KAAK,OAAO,CAAC,IAAI,QAAQ,CAAC,CAAC,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,EAAA,CAAG,YAAY;EAC3H,OAAO,KAAA;CAET,CAAC;;CAEH,MAAM,YAAY,MAA0B,OAC1C,QAAQ,OAAO,QAAQ,KAAK,SAAS,EAAE,IAAI,SAAS,KAAA,IAAY,KAAA,IAAY,GAAG,KAAK,UAAU,mBAAmB,EAAE;;;;;CAKrH,MAAM,WAAW,OAAO,MAAiB,IAAY,SAAiB;EACpE,MAAM,EAAE,YAAY,MAAM,KAAK,OAAO,EAAE;EACxC,IAAI,QAAQ,YAAY,WAAW,QAAQ,OAAO,QAAQ,KAAA,GACxD,MAAM,IAAI,QAAQ,IAAI,GAAG,iCAAiC,QAAQ,wC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AAE,MAAM,cAAc,CAAC,CAAC,CAAC,OAAO,QAAQ;AACtH;AAEA,MAAM,SAAS,MAAc,SAAiB,WAAW,KAAK,IAAI,KAAK,MAAM,IAAI,EAAE;AAEnF,MAAM,QAAQ,MAAc,QAAiB,KAAK,UAAU,MAAM,OAAO,GAAG,KAAK,MAAM,GAAG,MAAM,CAAC,EAAE;;AAGnG,eAAe,MAAS,KAAmC;CACzD,IAAI;EACF,OAAO,MAAM,IAAI;CACnB,SAAS,GAAG;EACV,IAAI,aAAa,SAAS,MAAM;EAChC,MAAM,EAAE,MAAM,SAAS,SAAS;EAChC,IAAI,OAAO,SAAS,UAAU,MAAM,IAAI,QAAQ,mBAAmB,UAAU,SAAS,KAAA,IAAY,KAAK,KAAK,KAAK,MAAM,EAAE,OAAO,EAAE,CAAC;EACnI,MAAM,IAAI,QACR,0BAA0B,WAAW,OAAO,CAAC,EAAE,oFAC/C,EAAE,OAAO,EAAE,CACb;CACF;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"waveform.js","names":[],"sources":["../src/client/waveform.ts"],"sourcesContent":["/**\n * Waveforms: a clip's, read off its audio, drawn as bars with what's played in the accent; and a mic's live,\n * a meter scrolling left as it hears. For the lightbox's player and whatever records the mic (the task\n * panel's Voice, the recording toolbar's mic). Bars, not a line: they read at any size, and at a glance.\n */\n\n/**\n * How loud each of `bars` stretches of the clip at `url` is, from 0 to 1, the loudest 1, and how long it is in\n * seconds: MediaRecorder's webm doesn't say until it's played through.\n */\nexport async function peaksOf(url: string, bars: number): Promise<{ peaks: number[]; duration: number }> {\n const data = await (await fetch(url)).arrayBuffer();\n const context = new AudioContext();\n try {\n const audio = await context.decodeAudioData(data);\n const samples = audio.getChannelData(0);\n const size = Math.max(1, Math.floor(samples.length / bars));\n const peaks: number[] = [];\n for (let b = 0; b < bars; b++) {\n // The stretch's loudness as its RMS: a peak would make every click a wall.\n let sum = 0;\n const from = b * size;\n for (let i = from; i < Math.min(samples.length, from + size); i++) sum += samples[i]! * samples[i]!;\n peaks.push(Math.sqrt(sum / size));\n }\n const top = Math.max(...peaks, 1e-6);\n return { peaks: peaks.map((p) => p / top), duration: audio.duration };\n } finally {\n void context.close();\n }\n}\n\nexport interface Colors {\n /** What's played. */\n played: string;\n /** What isn't, yet. */\n rest: string;\n}\n\n/** Draws `peaks` as bars across `canvas`, centred on its middle, the share `progress` (0–1) of them played. */\nexport function drawBars(canvas: HTMLCanvasElement, peaks: readonly number[], progress: number, colors: Colors): void {\n const { width, height } = fit(canvas);\n const g = canvas.getContext('2d');\n if (g === null) return;\n g.clearRect(0, 0, width, height);\n const step = width / Math.max(1, peaks.length);\n const bar = Math.max(1, step * 0.6);\n const dpr = devicePixelRatio;\n peaks.forEach((p, i) => {\n // Silence still shows as a sliver, so the clip's length reads from end to end.\n const h = Math.max(2 * dpr, p * height * 0.9);\n g.fillStyle = (i + 0.5) / peaks.length <= progress ? colors.played : colors.rest;\n g.fillRect(i * step + (step - bar) / 2, (height - h) / 2, bar, h);\n });\n}\n\n/**\n * The mic's level, live, as bars scrolling in from the right, drawn on `canvas` until the answer's called.\n * It listens to `stream` on its own; the recording goes on as it was.\n */\nexport function liveWaveform(canvas: HTMLCanvasElement, stream: MediaStream, colors: Colors): () => void {\n const context = new AudioContext();\n const analyser = context.createAnalyser();\n analyser.fftSize = 1024;\n context.createMediaStreamSource(stream).connect(analyser);\n const samples = new Float32Array(analyser.fftSize);\n const levels: number[] = [];\n let frame = 0;\n let last = 0;\n const tick = (now: number) => {\n frame = requestAnimationFrame(tick);\n // About 20 bars a second, whatever the display's rate.\n if (now - last < 50) return;\n last = now;\n analyser.getFloatTimeDomainData(samples);\n let sum = 0;\n for (const s of samples) sum += s * s;\n // Speech sits low in the range: lifted so a normal voice fills most of the height.\n levels.push(Math.min(1, Math.sqrt(sum / samples.length) * 4));\n const room = Math.max(8, Math.floor(canvas.clientWidth / 4));\n if (levels.length > room) levels.splice(0, levels.length - room);\n drawBars(canvas, [...Array<number>(room - levels.length).fill(0), ...levels], 1, colors);\n };\n frame = requestAnimationFrame(tick);\n return () => {\n cancelAnimationFrame(frame);\n void context.close();\n };\n}\n\n/** Sizes the canvas's pixels to its box, at the display's density: what it draws stays sharp. */\nfunction fit(canvas: HTMLCanvasElement): { width: number; height: number } {\n const width = Math.max(1, Math.round(canvas.clientWidth * devicePixelRatio));\n const height = Math.max(1, Math.round(canvas.clientHeight * devicePixelRatio));\n if (canvas.width !== width) canvas.width = width;\n if (canvas.height !== height) canvas.height = height;\n return { width, height };\n}\n"],"mappings":";;;;;;;;;;AAUA,eAAsB,QAAQ,KAAa,MAA8D;CACvG,MAAM,OAAO,OAAO,MAAM,MAAM,GAAG,EAAA,CAAG,YAAY;CAClD,MAAM,UAAU,IAAI,aAAa;CACjC,IAAI;EACF,MAAM,QAAQ,MAAM,QAAQ,gBAAgB,IAAI;EAChD,MAAM,UAAU,MAAM,eAAe,CAAC;EACtC,MAAM,OAAO,KAAK,IAAI,GAAG,KAAK,MAAM,QAAQ,SAAS,IAAI,CAAC;EAC1D,MAAM,QAAkB,CAAC;EACzB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,KAAK;GAE7B,IAAI,MAAM;GACV,MAAM,OAAO,IAAI;GACjB,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,QAAQ,QAAQ,OAAO,IAAI,GAAG,KAAK,OAAO,QAAQ,KAAM,QAAQ;GAChG,MAAM,KAAK,KAAK,KAAK,MAAM,IAAI,CAAC;EAClC;EACA,MAAM,MAAM,KAAK,IAAI,GAAG,OAAO,IAAI;EACnC,OAAO;GAAE,OAAO,MAAM,KAAK,MAAM,IAAI,GAAG;GAAG,UAAU,MAAM;EAAS;CACtE,UAAU;EACH,QAAQ,MAAM;CACrB;AACF;;AAUA,SAAgB,SAAS,QAA2B,OAA0B,UAAkB,QAAsB;CACpH,MAAM,EAAE,OAAO,WAAW,IAAI,MAAM;CACpC,MAAM,IAAI,OAAO,WAAW,IAAI;CAChC,IAAI,MAAM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