deictic 0.6.0 → 0.7.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 (90) hide show
  1. package/API.md +136 -30
  2. package/README.md +4 -3
  3. package/dist/annotations/client.d.ts +1 -1
  4. package/dist/annotations/client.d.ts.map +1 -1
  5. package/dist/annotations/client.js +161 -176
  6. package/dist/annotations/client.js.map +1 -1
  7. package/dist/annotations/index.d.ts +2 -11
  8. package/dist/client/index.d.ts +7 -6
  9. package/dist/client/index.d.ts.map +1 -1
  10. package/dist/client/index.js +1007 -192
  11. package/dist/client/index.js.map +1 -1
  12. package/dist/index.d.ts +2 -2
  13. package/dist/recommended/index.d.ts +2 -2
  14. package/dist/recordings/client.d.ts.map +1 -1
  15. package/dist/recordings/client.js +82 -153
  16. package/dist/recordings/client.js.map +1 -1
  17. package/dist/screenshots/client.d.ts.map +1 -1
  18. package/dist/shared/annotations.js +3 -4
  19. package/dist/shared/annotations.js.map +1 -1
  20. package/dist/shared/board.js +1 -1
  21. package/dist/shared/client.js +45 -2
  22. package/dist/shared/client.js.map +1 -1
  23. package/dist/shared/component.js +62 -0
  24. package/dist/shared/component.js.map +1 -0
  25. package/dist/shared/dom.js +79 -0
  26. package/dist/shared/dom.js.map +1 -0
  27. package/dist/shared/drawer.js +217 -0
  28. package/dist/shared/drawer.js.map +1 -0
  29. package/dist/shared/index.d.ts +116 -7
  30. package/dist/shared/index.d.ts.map +1 -1
  31. package/dist/shared/index2.d.ts +9 -19
  32. package/dist/shared/index2.d.ts.map +1 -1
  33. package/dist/shared/index7.d.ts +103 -26
  34. package/dist/shared/index7.d.ts.map +1 -1
  35. package/dist/shared/index9.d.ts +1 -1
  36. package/dist/shared/integration.d.ts +1 -1
  37. package/dist/shared/packages.js +1 -1
  38. package/dist/shared/recording.js +31 -3
  39. package/dist/shared/recording.js.map +1 -1
  40. package/dist/shared/src.js.map +1 -1
  41. package/dist/shared/task.js +44 -29
  42. package/dist/shared/task.js.map +1 -1
  43. package/dist/shared/tasks.js +232 -62
  44. package/dist/shared/tasks.js.map +1 -1
  45. package/dist/shared/vb.js +1 -1
  46. package/dist/shared/voice2.js +6 -4
  47. package/dist/shared/voice2.js.map +1 -1
  48. package/dist/shared/watch.js +14 -14
  49. package/dist/shared/watch.js.map +1 -1
  50. package/dist/tasks/client.d.ts +2 -2
  51. package/dist/tasks/client.d.ts.map +1 -1
  52. package/dist/tasks/client.js +1829 -741
  53. package/dist/tasks/client.js.map +1 -1
  54. package/dist/tasks/index.d.ts +2 -2
  55. package/dist/voice/client.d.ts.map +1 -1
  56. package/dist/voice/client.js +154 -57
  57. package/dist/voice/client.js.map +1 -1
  58. package/package.json +1 -1
  59. package/skills/deictic/SKILL.md +22 -28
  60. package/src/cli/recording.ts +34 -3
  61. package/src/cli/task.ts +59 -30
  62. package/src/cli/voice.ts +9 -4
  63. package/src/cli/watch.ts +14 -13
  64. package/src/client/away.ts +3 -1
  65. package/src/client/component.ts +98 -0
  66. package/src/client/dom.ts +70 -0
  67. package/src/client/drawer.ts +258 -0
  68. package/src/client/index.ts +220 -128
  69. package/src/client/lightbox.ts +8 -8
  70. package/src/client/lighting.ts +279 -0
  71. package/src/client/style.ts +263 -44
  72. package/src/client/tools.ts +279 -0
  73. package/src/client/tooltip.ts +25 -5
  74. package/src/client/tray.ts +48 -0
  75. package/src/index.ts +113 -6
  76. package/src/plugins/annotations/client.ts +103 -129
  77. package/src/plugins/annotations/draw.ts +68 -72
  78. package/src/plugins/annotations/index.ts +12 -19
  79. package/src/plugins/recordings/client.ts +89 -167
  80. package/src/plugins/screenshots/client.ts +53 -2
  81. package/src/plugins/tasks/client.ts +219 -748
  82. package/src/plugins/tasks/composer.ts +797 -0
  83. package/src/plugins/tasks/drawer.ts +516 -0
  84. package/src/plugins/tasks/index.ts +360 -82
  85. package/src/plugins/tasks/pins.ts +275 -0
  86. package/src/plugins/tasks/store.ts +132 -0
  87. package/src/plugins/voice/client.ts +96 -5
  88. package/skills/deictic/references/recordings.md +0 -13
  89. package/skills/deictic/references/tasks.md +0 -22
  90. package/skills/deictic/references/watch.md +0 -17
@@ -1,21 +1,21 @@
1
1
  /**
2
- * The recordings plugin's page half: `record()` starts rrweb (imported then) and shows the toolbar, a bar
3
- * docked to an edge of the window that its grip drags to any other, kept between recordings. It holds the
4
- * time, annotate mode's tools where that plugin is loaded, and Stop and Discard.
2
+ * The recordings plugin's page half. Its tool in the tool panel is Record: `record()` starts rrweb (imported
3
+ * then), and while one is going the panel stays, with the time, the mic where the voice plugin is loaded, and
4
+ * Stop and Discard in Record's place. A recording that's stopped goes in the tray, for the next task.
5
5
  *
6
6
  * The events go to the server as they happen (`begin`, a `part` each second, `end` on Stop), and what the next
7
7
  * page needs to carry on is kept in the tab's session storage: a reload, or a link to another page of the site,
8
8
  * leaves the recording going. The page that loads starts rrweb again under the same ID, which makes it a
9
- * recording of several pages as rrweb has them (a `Meta` and a snapshot for each), puts the toolbar back with
10
- * its time running, and turns the mic back on where it was.
9
+ * recording of several pages as rrweb has them (a `Meta` and a snapshot for each), puts its controls back with
10
+ * the time running, and turns the mic back on where it was.
11
11
  *
12
12
  * Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom
13
- * events: the page's annotations and the toolbar's own, which go when it does, as SVGs in page
14
- * coordinates, at the start and at each change.
13
+ * events: the page's annotations, as SVGs in page coordinates, at the start and at each change.
15
14
  */
15
+ import { toolButton } from '#src/client/dom.ts';
16
+ import { playMark, trayed } from '#src/client/drawer.ts';
16
17
  import { liveWaveform } from '#src/client/waveform.ts';
17
18
  import { defineClientPlugin } from '#src/index.ts';
18
- import type { Shape } from '#src/plugins/annotations/index.ts';
19
19
  import type { ResolvedMasking } from '#src/plugins/screenshots/index.ts';
20
20
 
21
21
  import type { Take } from '#src/plugins/voice/index.ts';
@@ -24,14 +24,6 @@ import type { Kept, Meta, Recorder, Recording, RecordPlugin, VoiceClip } from '.
24
24
  import { END, MARKS, PAGE } from './marks.ts';
25
25
  import { dropOurs } from './ours.ts';
26
26
 
27
- type Edge = 'top' | 'bottom' | 'left' | 'right';
28
- /** Where the bar is: the edge it's docked to, and how far along it, from 0 to 1. */
29
- interface Dock {
30
- edge: Edge;
31
- along: number;
32
- }
33
-
34
- const DOCK = 'deictic:recorder';
35
27
  /** Where the recording going on is kept, for the tab's next page to carry on with. */
36
28
  const GOING = 'deictic:recording';
37
29
  /** How often the events are sent, in milliseconds. */
@@ -46,9 +38,6 @@ interface Carried {
46
38
  /** The mic's clips so far, and whether it was on. */
47
39
  clips: VoiceClip[];
48
40
  mic: boolean;
49
- /** What was drawn from the toolbar, and on which page: it's about that page, so only a reload of it shows it again. */
50
- path: string;
51
- marks: Shape[];
52
41
  }
53
42
 
54
43
  function carried(): Carried | undefined {
@@ -68,112 +57,65 @@ function carry(going: Carried | undefined): void {
68
57
  // Not kept, then: a page load ends the recording.
69
58
  }
70
59
  }
71
- const MARGIN = 12;
72
60
 
73
61
  const STYLE = `
74
- .recorder { position: fixed; z-index: 2147483647; display: flex; align-items: center; gap: 6px; padding: 6px 8px;
75
- border: 1px solid var(--deictic-line); border-radius: 10px; background: var(--deictic-bg); color: var(--deictic-fg);
76
- box-shadow: 0 12px 32px rgb(0 0 0 / 0.35); font: 13px/1.4 system-ui, sans-serif; user-select: none; }
77
- .recorder.vertical { flex-direction: column; }
78
- .recorder.vertical .annotations-tools { flex-direction: column; }
79
- .recorder.vertical .annotations-tools .gap { width: auto; height: 1px; margin: 4px 2px; }
80
- .recorder .grip { display: inline-flex; padding: 2px; color: var(--deictic-muted); cursor: grab; touch-action: none; }
81
- .recorder .grip:active { cursor: grabbing; }
82
- .recorder .grip svg { width: 16px; height: 16px; }
83
- .recorder .live { display: inline-flex; align-items: center; gap: 6px; font: 12px ui-monospace, monospace; }
62
+ .recorder .going { display: flex; align-items: center; gap: 4px; }
63
+ /* Away while nothing records: laid out empty, it would still count in the group's gap. */
64
+ .recorder .going[hidden] { display: none; }
65
+ /* While one goes, its controls are its section's alone: the other tools that capture (a shot, the mic, a task) wait. */
66
+ .tool-panel:has(.recorder.going) .tool-group[data-section='capture']:not(.recorder) { display: none; }
67
+ .tool-panel.vertical .recorder .going { flex-direction: column; }
68
+ .recorder .live { display: inline-flex; align-items: center; gap: 6px; padding: 0 4px; font: 12px ui-monospace, monospace; }
69
+ .tool-panel.vertical .recorder .live { flex-direction: column; gap: 2px; padding: 4px 0; }
84
70
  .recorder .dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: deictic-blink 1.2s infinite; }
85
- .recorder .sep { align-self: stretch; width: 1px; background: var(--deictic-line); }
86
- .recorder.vertical .sep { width: auto; height: 1px; }
87
- .recorder .icon { display: inline-flex; align-items: center; justify-content: center; padding: 3px 5px; }
88
- .recorder .icon svg { width: 16px; height: 16px; }
89
- .recorder .mic[aria-pressed='true'] { background: #ef4444; border-color: #ef4444; color: #fff; }
71
+ .recorder .mic[aria-pressed='true'], .recorder .mic[aria-pressed='true']:hover { background: #ef4444; color: #fff; }
90
72
  .recorder .wave { width: 44px; height: 18px; }
91
- .recorder.vertical .wave { width: 28px; }
92
- .recorder .wave[hidden] { display: none; }
93
- .recorder .mic.problem { border-color: var(--deictic-problem); color: var(--deictic-problem); }
73
+ .tool-panel.vertical .recorder .wave { width: 28px; }
94
74
  @keyframes deictic-blink { 50% { opacity: 0.3; } }
95
75
  `;
96
76
 
97
- const svg = (paths: string) =>
98
- `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${paths}</svg>`;
99
- const GRIP = svg(
100
- '<circle cx="9" cy="6" r="1"/><circle cx="15" cy="6" r="1"/><circle cx="9" cy="12" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="9" cy="18" r="1"/><circle cx="15" cy="18" r="1"/>',
101
- );
102
- const STOP = svg('<rect x="6" y="6" width="12" height="12" rx="1" fill="currentColor"/>');
103
- const DISCARD = svg('<path d="M6 6l12 12M18 6 6 18"/>');
104
- const MIC = svg('<rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5 11a7 7 0 0 0 14 0M12 18v3"/>');
77
+ /** Each icon's strokes, on a 24-pixel grid. */
78
+ const RECORD = '<circle cx="12" cy="12" r="8"/><circle cx="12" cy="12" r="3" fill="currentColor"/>';
79
+ const STOP = '<rect x="6" y="6" width="12" height="12" rx="1" fill="currentColor"/>';
80
+ const DISCARD = '<path d="M6 6l12 12M18 6 6 18"/>';
81
+ const MIC = '<rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5 11a7 7 0 0 0 14 0M12 18v3"/>';
105
82
 
106
83
  const clock = (ms: number) => {
107
84
  const s = Math.floor(ms / 1000);
108
85
  return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;
109
86
  };
110
87
 
111
- function storedDock(): Dock {
112
- try {
113
- const dock = JSON.parse(localStorage.getItem(DOCK) ?? 'null') as Dock | null;
114
- if (dock !== null && ['top', 'bottom', 'left', 'right'].includes(dock.edge) && dock.along >= 0 && dock.along <= 1) return dock;
115
- } catch {
116
- // Storage can be off, or hold something else: the default, then.
117
- }
118
- return { edge: 'bottom', along: 0.5 };
119
- }
120
-
121
- function iconButton(icon: string, name: string, run: () => void): HTMLButtonElement {
122
- const el = Object.assign(document.createElement('button'), { type: 'button', className: 'icon', title: name, innerHTML: icon });
123
- el.setAttribute('aria-label', name);
124
- el.addEventListener('click', run);
125
- return el;
126
- }
127
-
128
- /** Puts the bar on its edge, laid out along it, and how far along. */
129
- function place(bar: HTMLElement, { edge, along }: Dock): void {
130
- bar.classList.toggle('vertical', edge === 'left' || edge === 'right');
131
- const { width, height } = bar.getBoundingClientRect();
132
- const across = (room: number, size: number) => `${MARGIN + along * Math.max(0, room - size - MARGIN * 2)}px`;
133
- Object.assign(bar.style, {
134
- left: edge === 'left' ? `${MARGIN}px` : edge === 'right' ? `${innerWidth - width - MARGIN}px` : across(innerWidth, width),
135
- top: edge === 'top' ? `${MARGIN}px` : edge === 'bottom' ? `${innerHeight - height - MARGIN}px` : across(innerHeight, height),
136
- });
137
- }
138
-
139
- /** Dragging the bar by its grip, freely; let go, it docks to the nearest edge. */
140
- function draggable(bar: HTMLElement, grip: HTMLElement, docked: (dock: Dock) => void): void {
141
- grip.addEventListener('pointerdown', (e) => {
142
- if (e.button !== 0) return;
143
- e.preventDefault();
144
- grip.setPointerCapture(e.pointerId);
145
- const start = bar.getBoundingClientRect();
146
- const dx = e.clientX - start.left;
147
- const dy = e.clientY - start.top;
148
- const move = (m: PointerEvent) => {
149
- bar.style.left = `${m.clientX - dx}px`;
150
- bar.style.top = `${m.clientY - dy}px`;
151
- };
152
- const up = () => {
153
- grip.removeEventListener('pointermove', move);
154
- const r = bar.getBoundingClientRect();
155
- const x = r.left + r.width / 2;
156
- const y = r.top + r.height / 2;
157
- const away: [Edge, number][] = [
158
- ['left', x],
159
- ['right', innerWidth - x],
160
- ['top', y],
161
- ['bottom', innerHeight - y],
162
- ];
163
- const [edge] = away.reduce((a, b) => (b[1] < a[1] ? b : a));
164
- const ratio = (at: number, room: number) => Math.min(1, Math.max(0, at / room));
165
- docked({ edge, along: edge === 'left' || edge === 'right' ? ratio(y, innerHeight) : ratio(x, innerWidth) });
166
- };
167
- grip.addEventListener('pointermove', move);
168
- grip.addEventListener('pointerup', up, { once: true });
169
- });
170
- }
171
-
172
88
  export default defineClientPlugin<never, never, Recorder>({
173
89
  name: 'recordings',
174
- setup: ({ base, root, options, use, request }) => {
90
+ setup: ({ base, root, options, use, request, tools, tray, drawer, lightbox }) => {
175
91
  const { masking, canvas } = options as { masking: ResolvedMasking; canvas?: false | { fps: number } };
176
- let going: Promise<Recording | undefined> | undefined;
92
+ let running: Promise<Recording | undefined> | undefined;
93
+
94
+ // In the tool panel: Record, and in its place while one is going, what `record` puts there.
95
+ const group = Object.assign(document.createElement('div'), { className: 'tool-group recorder' });
96
+ const going = Object.assign(document.createElement('div'), { className: 'going', hidden: true });
97
+ const start = toolButton(RECORD, 'Record', 'R', () => {
98
+ run().catch((e: unknown) => {
99
+ // Said where it was asked for: its tooltip, which a missing package's fix fits in.
100
+ start.classList.add('problem');
101
+ start.title = e instanceof Error ? e.message : String(e);
102
+ });
103
+ });
104
+ group.append(Object.assign(document.createElement('style'), { textContent: STYLE }), start, going);
105
+ // Beside the other tools that capture the page: a shot, a recording, the mic.
106
+ tools.add(group, { section: 'capture' });
107
+ // In the drawer until a task takes them: each plays back in the lightbox.
108
+ drawer.add(
109
+ trayed({ tray }, 'recordings', 'Recordings', (item, i, all) => {
110
+ const { url, duration, voice } = item.value as Recording;
111
+ const name = `${all.length === 1 ? 'Recording' : `Recording ${i + 1}`} ${clock(duration)}`;
112
+ return {
113
+ label: [playMark(), `${name}${voice === undefined ? '' : ' · voice'}`],
114
+ // The replay filling the frame, without a header of its own: the lightbox names it.
115
+ open: (from) => lightbox([{ kind: 'page', url: `${url}${url.includes('?') ? '&' : '?'}embed`, title: name }], { from }),
116
+ };
117
+ }),
118
+ );
177
119
 
178
120
  const post = async (route: string, body: unknown, keepalive = false) => {
179
121
  const res = await request(route, {
@@ -258,15 +200,12 @@ export default defineClientPlugin<never, never, Recorder>({
258
200
 
259
201
  // The marks, now and at each change: an SVG whose view is the page from its top left, at 1:1.
260
202
  const marks = use('annotations');
261
- // The toolbar's own, drawn while recording: shown with the page's, gone when it ends.
262
- const tools = marks?.tools();
263
- if (from?.path === location.pathname) for (const shape of from.marks) tools?.marks.add(shape);
264
203
  const mark = () => {
265
204
  const area = { x: -scrollX, y: -scrollY, width: 1, height: 1 };
266
205
  rrweb.record.addCustomEvent(MARKS, {
267
- svg: [marks?.svg(area), tools?.marks.svg(area)].filter(Boolean).join(''),
206
+ svg: marks?.svg(area) ?? '',
268
207
  // The same marks as data, in page coordinates, for whatever reads the recording but doesn't draw it.
269
- annotations: [...(marks?.list() ?? []), ...(tools?.marks.list() ?? [])],
208
+ annotations: marks?.list() ?? [],
270
209
  });
271
210
  };
272
211
  mark();
@@ -278,23 +217,8 @@ export default defineClientPlugin<never, never, Recorder>({
278
217
  let over = false;
279
218
  const save = () =>
280
219
  // Not once it's ended, as its last events go: the next page would carry on with one that's over.
281
- over ||
282
- carry({
283
- id,
284
- startedAt,
285
- seq,
286
- clips,
287
- mic: take !== undefined,
288
- path: location.pathname,
289
- marks: tools?.marks.list().map((a) => a.shape) ?? [],
290
- });
291
- const unsubscribe = [
292
- marks?.subscribe(mark),
293
- tools?.marks.subscribe(() => {
294
- mark();
295
- save();
296
- }),
297
- ];
220
+ over || carry({ id, startedAt, seq, clips, mic: take !== undefined });
221
+ const unsubscribe = marks?.subscribe(mark);
298
222
 
299
223
  // One part at a time, each with its place. A part that didn't arrive goes again with the next, before it.
300
224
  let sending: Promise<void> = Promise.resolve();
@@ -322,16 +246,10 @@ export default defineClientPlugin<never, never, Recorder>({
322
246
  save();
323
247
 
324
248
  return new Promise((done, fail) => {
325
- const bar = document.createElement('div');
326
- bar.className = 'recorder';
327
- bar.setAttribute('role', 'toolbar');
328
- bar.setAttribute('aria-label', 'Recording');
329
- const grip = Object.assign(document.createElement('span'), { className: 'grip', title: 'Drag to any edge', innerHTML: GRIP });
330
249
  const live = Object.assign(document.createElement('span'), { className: 'live' });
331
250
  const dot = Object.assign(document.createElement('span'), { className: 'dot' });
332
251
  const time = document.createElement('span');
333
252
  live.append(dot, time);
334
- const sep = () => Object.assign(document.createElement('span'), { className: 'sep' });
335
253
 
336
254
  // The mic's live waveform beside it while it's on, so it's plain it hears.
337
255
  const wave = Object.assign(document.createElement('canvas'), { className: 'wave', hidden: true });
@@ -356,7 +274,7 @@ export default defineClientPlugin<never, never, Recorder>({
356
274
  console.warn('deictic: the voice clip was not kept', e);
357
275
  }
358
276
  };
359
- const mic = voice === undefined ? undefined : iconButton(MIC, 'Turn the mic on', () => toggle());
277
+ const mic = voice === undefined ? undefined : toolButton(MIC, 'Turn the mic on', 'K', () => toggle());
360
278
  const toggle = () => {
361
279
  busy = busy.then(async () => {
362
280
  if (voice === undefined || mic === undefined) return;
@@ -405,13 +323,11 @@ export default defineClientPlugin<never, never, Recorder>({
405
323
  const end = async (kept: boolean) => {
406
324
  rrweb.record.addCustomEvent(END, {});
407
325
  stopRecording?.();
408
- for (const stop of unsubscribe) stop?.();
409
- tools?.close();
326
+ unsubscribe?.();
410
327
  clearInterval(flushing);
411
328
  clearInterval(ticking);
412
- removeEventListener('resize', replace);
413
329
  removeEventListener('pagehide', leave);
414
- bar.remove();
330
+ idle();
415
331
  over = true;
416
332
  carry(undefined);
417
333
  await busy;
@@ -432,12 +348,22 @@ export default defineClientPlugin<never, never, Recorder>({
432
348
  fail(e);
433
349
  }
434
350
  };
435
- const stop = iconButton(STOP, 'Stop, and keep the recording', () => void end(true));
436
- const discard = iconButton(DISCARD, 'Discard the recording', () => void end(false));
437
- bar.append(grip, live, ...(tools ? [sep(), tools.element] : []), sep(), ...(mic ? [mic, wave] : []), stop, discard);
438
- const style = Object.assign(document.createElement('style'), { textContent: STYLE });
439
- bar.prepend(style);
440
- root.append(bar);
351
+ // Record's key again: it's Stop while one is going.
352
+ const stop = toolButton(STOP, 'Stop', 'R', () => void end(true));
353
+ const discard = toolButton(DISCARD, 'Discard', 'Shift+R', () => void end(false));
354
+ going.replaceChildren(live, ...(mic ? [mic, wave] : []), stop, discard);
355
+ // The panel stays while it goes: its controls are what ends it.
356
+ const unkeep = tools.keep();
357
+ start.hidden = true;
358
+ going.hidden = false;
359
+ group.classList.add('going');
360
+ const idle = () => {
361
+ unkeep();
362
+ going.replaceChildren();
363
+ going.hidden = true;
364
+ start.hidden = false;
365
+ group.classList.remove('going');
366
+ };
441
367
 
442
368
  const tick = () => {
443
369
  moved();
@@ -445,27 +371,23 @@ export default defineClientPlugin<never, never, Recorder>({
445
371
  };
446
372
  tick();
447
373
  const ticking = setInterval(tick, 250);
448
- let dock = storedDock();
449
- const replace = () => place(bar, dock);
450
- replace();
451
- addEventListener('resize', replace);
452
- draggable(bar, grip, (next) => {
453
- dock = next;
454
- replace();
455
- try {
456
- localStorage.setItem(DOCK, JSON.stringify(dock));
457
- } catch {
458
- // Not kept, then: the next recording starts at the bottom.
459
- }
460
- });
461
374
  });
462
375
  };
463
376
 
464
377
  const run = (from?: Carried) => {
378
+ start.disabled = true;
379
+ start.classList.remove('problem');
380
+ start.title = 'Record';
465
381
  const mine = record(from).finally(() => {
466
- if (going === mine) going = undefined;
382
+ if (running === mine) running = undefined;
383
+ start.disabled = false;
467
384
  });
468
- going = mine;
385
+ running = mine;
386
+ // One that's stopped and kept is the next task's, whoever started it.
387
+ mine.then(
388
+ (recording) => recording !== undefined && tray.add('recordings', recording.id, recording),
389
+ () => {},
390
+ );
469
391
  return mine;
470
392
  };
471
393
  // One the page before this left going: carried on at once, whoever asks for it later (`going`), or no one.
@@ -480,14 +402,14 @@ export default defineClientPlugin<never, never, Recorder>({
480
402
  // A page shown again as it was left (Back, out of the browser's cache) knows nothing of what happened since:
481
403
  // loaded afresh, it carries on like any other.
482
404
  window.addEventListener('pageshow', (e) => {
483
- if (e.persisted && (going !== undefined || carried() !== undefined)) location.reload();
405
+ if (e.persisted && (running !== undefined || carried() !== undefined)) location.reload();
484
406
  });
485
407
 
486
408
  return {
487
- recording: () => going !== undefined,
488
- going: () => going,
409
+ recording: () => running !== undefined,
410
+ going: () => running,
489
411
  record: async () => {
490
- if (going !== undefined) throw new Error('recordings: one is going already: stop it first');
412
+ if (running !== undefined) throw new Error('recordings: one is going already: stop it first');
491
413
  return run();
492
414
  },
493
415
  };
@@ -2,7 +2,12 @@
2
2
  * The screenshots plugin's page half, around a renderer's capture: the renderer makes the shot (a PNG,
3
3
  * or what its server half makes one of), and this sends it to the plugin's `add` route and answers the
4
4
  * `Shot`. A renderer's page module default-exports `screenshotsClient(itsCapture)`.
5
+ *
6
+ * Its tool in the tool panel takes the window as it is, with what's drawn on the page, and puts the shot in the
7
+ * tray, for the next task.
5
8
  */
9
+ import { toolButton } from '#src/client/dom.ts';
10
+ import { trayed } from '#src/client/drawer.ts';
6
11
  import { defineClientPlugin } from '#src/index.ts';
7
12
  import type { Annotations } from '#src/plugins/annotations/index.ts';
8
13
 
@@ -34,6 +39,8 @@ export function boxOf(element: Element, area: NonNullable<CaptureOptions['area']
34
39
  }
35
40
 
36
41
  const BLANK = '#d4d4d8';
42
+ /** A camera, on a 24-pixel grid. */
43
+ const CAMERA = '<path d="M4 8h3l2-3h6l2 3h3v11H4z"/><circle cx="12" cy="13" r="3.5"/>';
37
44
 
38
45
  const selector = (className: string, extra: string | undefined) => [`.${CSS.escape(className)}`, ...(extra ? [extra] : [])].join(', ');
39
46
 
@@ -66,7 +73,7 @@ export function mask(copy: Node, m: ResolvedMasking): void {
66
73
  export function screenshotsClient(capture: PageCapture) {
67
74
  return defineClientPlugin<never, never, Capture>({
68
75
  name: 'screenshots',
69
- setup: ({ base, request, options, use }) => {
76
+ setup: ({ base, request, options, use, tools, tray, drawer, lightbox }) => {
70
77
  const { masking, renderer } = options as { masking: ResolvedMasking; renderer: unknown };
71
78
  // Asked at each shot: the annotations plugin may be set up after this one.
72
79
  const overlay = (area: Box) => {
@@ -81,7 +88,7 @@ export function screenshotsClient(capture: PageCapture) {
81
88
  if (id === undefined) throw new Error(`screenshots: ${problem ?? res.statusText}`);
82
89
  return { id, url: url ?? `${base}__deictic/plugins/screenshots/shot/${id}`, box: drawn ?? box, size };
83
90
  };
84
- return {
91
+ const api: Capture = {
85
92
  capture: async (element, { area = 'viewport' } = {}) => {
86
93
  const { body, type, box } = await capture(element, { area, masking, renderer, overlay });
87
94
  const { clientWidth, clientHeight } = document.documentElement;
@@ -95,6 +102,50 @@ export function screenshotsClient(capture: PageCapture) {
95
102
  return copy;
96
103
  },
97
104
  };
105
+
106
+ const group = Object.assign(document.createElement('div'), { className: 'tool-group' });
107
+ const shoot = toolButton(CAMERA, 'Screenshot', 'S', () => {
108
+ shoot.disabled = true;
109
+ shoot.classList.remove('problem');
110
+ // The panel stays while the shot is made: it's in none, as nothing of deictic's is.
111
+ const done = tools.keep();
112
+ api
113
+ .capture(document.documentElement)
114
+ .then(
115
+ (shot) => {
116
+ tray.add('screenshots', shot.id, shot);
117
+ shoot.title = 'Screenshot';
118
+ },
119
+ (e: unknown) => {
120
+ // Said where it was asked for: its tooltip, which a missing renderer's fix fits in.
121
+ shoot.classList.add('problem');
122
+ shoot.title = e instanceof Error ? e.message : String(e);
123
+ },
124
+ )
125
+ .finally(() => {
126
+ shoot.disabled = false;
127
+ done();
128
+ });
129
+ });
130
+ group.append(shoot);
131
+ // Beside the other tools that capture the page: a shot, a recording, the mic.
132
+ tools.add(group, { section: 'capture' });
133
+ // In the drawer until a task takes them: each opens among the others.
134
+ drawer.add(
135
+ trayed({ tray }, 'screenshots', 'Screenshots', (item, i, all) => {
136
+ const name = (n: number) => (all.length === 1 ? 'Screenshot' : `Screenshot ${n + 1}`);
137
+ const thumb = Object.assign(document.createElement('img'), { src: (item.value as Shot).url, alt: '' });
138
+ return {
139
+ label: [thumb, name(i)],
140
+ open: (from) =>
141
+ lightbox(
142
+ all.map((each, n) => ({ kind: 'image' as const, url: (each.value as Shot).url, title: name(n) })),
143
+ { at: i, from },
144
+ ),
145
+ };
146
+ }),
147
+ );
148
+ return api;
98
149
  },
99
150
  });
100
151
  }