deictic 0.6.0 → 0.8.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 (111) hide show
  1. package/API.md +156 -31
  2. package/README.md +6 -4
  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/bun.js +1 -1
  9. package/dist/client/index.d.ts +7 -6
  10. package/dist/client/index.d.ts.map +1 -1
  11. package/dist/client/index.js +1077 -236
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/next.js +1 -1
  15. package/dist/recommended/index.d.ts +2 -2
  16. package/dist/recordings/client.d.ts.map +1 -1
  17. package/dist/recordings/client.js +89 -154
  18. package/dist/recordings/client.js.map +1 -1
  19. package/dist/screenshots/client.d.ts.map +1 -1
  20. package/dist/shared/annotations.js +3 -4
  21. package/dist/shared/annotations.js.map +1 -1
  22. package/dist/shared/board.js +1 -1
  23. package/dist/shared/client.js +45 -2
  24. package/dist/shared/client.js.map +1 -1
  25. package/dist/shared/component.js +62 -0
  26. package/dist/shared/component.js.map +1 -0
  27. package/dist/shared/dom.js +79 -0
  28. package/dist/shared/dom.js.map +1 -0
  29. package/dist/shared/drawer.js +217 -0
  30. package/dist/shared/drawer.js.map +1 -0
  31. package/dist/shared/endpoints.js +26 -6
  32. package/dist/shared/endpoints.js.map +1 -1
  33. package/dist/shared/index.d.ts +150 -9
  34. package/dist/shared/index.d.ts.map +1 -1
  35. package/dist/shared/index2.d.ts +9 -19
  36. package/dist/shared/index2.d.ts.map +1 -1
  37. package/dist/shared/index7.d.ts +123 -26
  38. package/dist/shared/index7.d.ts.map +1 -1
  39. package/dist/shared/index9.d.ts +1 -1
  40. package/dist/shared/integration.d.ts +1 -1
  41. package/dist/shared/integration.js +59 -5
  42. package/dist/shared/integration.js.map +1 -1
  43. package/dist/shared/package.js +23 -0
  44. package/dist/shared/package.js.map +1 -0
  45. package/dist/shared/packages.js +14 -23
  46. package/dist/shared/packages.js.map +1 -1
  47. package/dist/shared/playwright.js +11 -3
  48. package/dist/shared/playwright.js.map +1 -1
  49. package/dist/shared/recording.js +31 -3
  50. package/dist/shared/recording.js.map +1 -1
  51. package/dist/shared/src.js.map +1 -1
  52. package/dist/shared/task.js +55 -31
  53. package/dist/shared/task.js.map +1 -1
  54. package/dist/shared/tasks.js +279 -61
  55. package/dist/shared/tasks.js.map +1 -1
  56. package/dist/shared/vb.js +1 -1
  57. package/dist/shared/voice2.js +6 -4
  58. package/dist/shared/voice2.js.map +1 -1
  59. package/dist/shared/watch.js +15 -14
  60. package/dist/shared/watch.js.map +1 -1
  61. package/dist/tailwind/index.js +7 -2
  62. package/dist/tailwind/index.js.map +1 -1
  63. package/dist/tasks/client.d.ts +2 -2
  64. package/dist/tasks/client.d.ts.map +1 -1
  65. package/dist/tasks/client.js +1870 -741
  66. package/dist/tasks/client.js.map +1 -1
  67. package/dist/tasks/index.d.ts +2 -2
  68. package/dist/voice/client.d.ts.map +1 -1
  69. package/dist/voice/client.js +154 -57
  70. package/dist/voice/client.js.map +1 -1
  71. package/dist/webpack.js +1 -1
  72. package/package.json +2 -1
  73. package/skills/deictic/SKILL.md +22 -28
  74. package/src/cli/recording.ts +34 -3
  75. package/src/cli/task.ts +78 -33
  76. package/src/cli/voice.ts +9 -4
  77. package/src/cli/watch.ts +16 -13
  78. package/src/client/away.ts +3 -1
  79. package/src/client/component.ts +98 -0
  80. package/src/client/dom.ts +70 -0
  81. package/src/client/drawer.ts +258 -0
  82. package/src/client/index.ts +290 -165
  83. package/src/client/lightbox.ts +8 -8
  84. package/src/client/lighting.ts +279 -0
  85. package/src/client/style.ts +263 -44
  86. package/src/client/tools.ts +279 -0
  87. package/src/client/tooltip.ts +25 -5
  88. package/src/client/tray.ts +48 -0
  89. package/src/index.ts +148 -8
  90. package/src/plugins/annotations/client.ts +103 -129
  91. package/src/plugins/annotations/draw.ts +68 -72
  92. package/src/plugins/annotations/index.ts +12 -19
  93. package/src/plugins/recordings/client.ts +96 -168
  94. package/src/plugins/screenshots/client.ts +53 -2
  95. package/src/plugins/screenshots/playwright.ts +8 -3
  96. package/src/plugins/tailwind/index.ts +3 -2
  97. package/src/plugins/tasks/client.ts +229 -748
  98. package/src/plugins/tasks/composer.ts +797 -0
  99. package/src/plugins/tasks/drawer.ts +516 -0
  100. package/src/plugins/tasks/index.ts +436 -80
  101. package/src/plugins/tasks/pins.ts +280 -0
  102. package/src/plugins/tasks/store.ts +132 -0
  103. package/src/plugins/tasks/which.ts +34 -0
  104. package/src/plugins/voice/client.ts +96 -5
  105. package/src/tools/endpoints.ts +31 -5
  106. package/src/tools/packages.ts +12 -4
  107. package/src/tools/plugins.ts +18 -4
  108. package/src/tools/problems.ts +60 -0
  109. package/skills/deictic/references/recordings.md +0 -13
  110. package/skills/deictic/references/tasks.md +0 -22
  111. 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, report, 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, {
@@ -204,7 +146,13 @@ export default defineClientPlugin<never, never, Recorder>({
204
146
  // A page that carries a recording on made requests before this: those of its load are the recording's too.
205
147
  ?.plugin({ sinceLoad: from !== undefined })
206
148
  .catch((e: unknown) => {
207
- console.warn(`deictic: this recording has no ${name}`, e);
149
+ const why = e instanceof Error ? e.message : String(e);
150
+ report({
151
+ key: `page:recordings:${name}:${why.split('\n', 1)[0]!.slice(0, 200)}`,
152
+ kind: 'setup',
153
+ message: `recordings go without ${name}, as it couldn't be loaded: install what it needs (\`deictic init\` does), then load the page again: ${why}`,
154
+ ...(e instanceof Error && e.stack !== undefined ? { details: e.stack } : {}),
155
+ });
208
156
  return undefined;
209
157
  });
210
158
  const [rrweb, id, ...extras] = await Promise.all([
@@ -258,15 +206,12 @@ export default defineClientPlugin<never, never, Recorder>({
258
206
 
259
207
  // The marks, now and at each change: an SVG whose view is the page from its top left, at 1:1.
260
208
  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
209
  const mark = () => {
265
210
  const area = { x: -scrollX, y: -scrollY, width: 1, height: 1 };
266
211
  rrweb.record.addCustomEvent(MARKS, {
267
- svg: [marks?.svg(area), tools?.marks.svg(area)].filter(Boolean).join(''),
212
+ svg: marks?.svg(area) ?? '',
268
213
  // 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() ?? [])],
214
+ annotations: marks?.list() ?? [],
270
215
  });
271
216
  };
272
217
  mark();
@@ -278,23 +223,8 @@ export default defineClientPlugin<never, never, Recorder>({
278
223
  let over = false;
279
224
  const save = () =>
280
225
  // 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
- ];
226
+ over || carry({ id, startedAt, seq, clips, mic: take !== undefined });
227
+ const unsubscribe = marks?.subscribe(mark);
298
228
 
299
229
  // One part at a time, each with its place. A part that didn't arrive goes again with the next, before it.
300
230
  let sending: Promise<void> = Promise.resolve();
@@ -322,16 +252,10 @@ export default defineClientPlugin<never, never, Recorder>({
322
252
  save();
323
253
 
324
254
  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
255
  const live = Object.assign(document.createElement('span'), { className: 'live' });
331
256
  const dot = Object.assign(document.createElement('span'), { className: 'dot' });
332
257
  const time = document.createElement('span');
333
258
  live.append(dot, time);
334
- const sep = () => Object.assign(document.createElement('span'), { className: 'sep' });
335
259
 
336
260
  // The mic's live waveform beside it while it's on, so it's plain it hears.
337
261
  const wave = Object.assign(document.createElement('canvas'), { className: 'wave', hidden: true });
@@ -356,7 +280,7 @@ export default defineClientPlugin<never, never, Recorder>({
356
280
  console.warn('deictic: the voice clip was not kept', e);
357
281
  }
358
282
  };
359
- const mic = voice === undefined ? undefined : iconButton(MIC, 'Turn the mic on', () => toggle());
283
+ const mic = voice === undefined ? undefined : toolButton(MIC, 'Turn the mic on', 'K', () => toggle());
360
284
  const toggle = () => {
361
285
  busy = busy.then(async () => {
362
286
  if (voice === undefined || mic === undefined) return;
@@ -405,13 +329,11 @@ export default defineClientPlugin<never, never, Recorder>({
405
329
  const end = async (kept: boolean) => {
406
330
  rrweb.record.addCustomEvent(END, {});
407
331
  stopRecording?.();
408
- for (const stop of unsubscribe) stop?.();
409
- tools?.close();
332
+ unsubscribe?.();
410
333
  clearInterval(flushing);
411
334
  clearInterval(ticking);
412
- removeEventListener('resize', replace);
413
335
  removeEventListener('pagehide', leave);
414
- bar.remove();
336
+ idle();
415
337
  over = true;
416
338
  carry(undefined);
417
339
  await busy;
@@ -432,12 +354,22 @@ export default defineClientPlugin<never, never, Recorder>({
432
354
  fail(e);
433
355
  }
434
356
  };
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);
357
+ // Record's key again: it's Stop while one is going.
358
+ const stop = toolButton(STOP, 'Stop', 'R', () => void end(true));
359
+ const discard = toolButton(DISCARD, 'Discard', 'Shift+R', () => void end(false));
360
+ going.replaceChildren(live, ...(mic ? [mic, wave] : []), stop, discard);
361
+ // The panel stays while it goes: its controls are what ends it.
362
+ const unkeep = tools.keep();
363
+ start.hidden = true;
364
+ going.hidden = false;
365
+ group.classList.add('going');
366
+ const idle = () => {
367
+ unkeep();
368
+ going.replaceChildren();
369
+ going.hidden = true;
370
+ start.hidden = false;
371
+ group.classList.remove('going');
372
+ };
441
373
 
442
374
  const tick = () => {
443
375
  moved();
@@ -445,27 +377,23 @@ export default defineClientPlugin<never, never, Recorder>({
445
377
  };
446
378
  tick();
447
379
  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
380
  });
462
381
  };
463
382
 
464
383
  const run = (from?: Carried) => {
384
+ start.disabled = true;
385
+ start.classList.remove('problem');
386
+ start.title = 'Record';
465
387
  const mine = record(from).finally(() => {
466
- if (going === mine) going = undefined;
388
+ if (running === mine) running = undefined;
389
+ start.disabled = false;
467
390
  });
468
- going = mine;
391
+ running = mine;
392
+ // One that's stopped and kept is the next task's, whoever started it.
393
+ mine.then(
394
+ (recording) => recording !== undefined && tray.add('recordings', recording.id, recording),
395
+ () => {},
396
+ );
469
397
  return mine;
470
398
  };
471
399
  // One the page before this left going: carried on at once, whoever asks for it later (`going`), or no one.
@@ -480,14 +408,14 @@ export default defineClientPlugin<never, never, Recorder>({
480
408
  // A page shown again as it was left (Back, out of the browser's cache) knows nothing of what happened since:
481
409
  // loaded afresh, it carries on like any other.
482
410
  window.addEventListener('pageshow', (e) => {
483
- if (e.persisted && (going !== undefined || carried() !== undefined)) location.reload();
411
+ if (e.persisted && (running !== undefined || carried() !== undefined)) location.reload();
484
412
  });
485
413
 
486
414
  return {
487
- recording: () => going !== undefined,
488
- going: () => going,
415
+ recording: () => running !== undefined,
416
+ going: () => running,
489
417
  record: async () => {
490
- if (going !== undefined) throw new Error('recordings: one is going already: stop it first');
418
+ if (running !== undefined) throw new Error('recordings: one is going already: stop it first');
491
419
  return run();
492
420
  },
493
421
  };
@@ -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
  }
@@ -112,7 +112,8 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
112
112
  if (doc === null) throw new Error('screenshots: the snapshot was rebuilt where it cannot be read');
113
113
  await doc.fonts.ready;
114
114
  await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));
115
- iframe.contentWindow?.scrollTo(scroll.x, scroll.y);
115
+ // At once: a page with `scroll-behavior: smooth` would glide there, and be shot on its way.
116
+ iframe.contentWindow?.scrollTo({ left: scroll.x, top: scroll.y, behavior: 'instant' });
116
117
  // rrweb scrolled each element as it built it, before the fonts and images gave its content its height:
117
118
  // one that couldn't scroll that far yet is scrolled again now.
118
119
  // By its kind: the iframe's elements aren't instances of this page's `Element`.
@@ -122,8 +123,12 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
122
123
  const meta = node === null ? null : mirror.getMeta(node);
123
124
  if (!isElement(node) || meta === null || !('attributes' in meta)) continue;
124
125
  const { rr_scrollTop: top, rr_scrollLeft: left } = meta.attributes;
125
- if (typeof top === 'number') node.scrollTop = top;
126
- if (typeof left === 'number') node.scrollLeft = left;
126
+ if (typeof top !== 'number' && typeof left !== 'number') continue;
127
+ node.scrollTo({
128
+ top: typeof top === 'number' ? top : node.scrollTop,
129
+ left: typeof left === 'number' ? left : node.scrollLeft,
130
+ behavior: 'instant',
131
+ });
127
132
  }
128
133
  const node = element === undefined ? null : mirror.getNode(element);
129
134
  // The iframe fills the page from its top left, so a box in it is one in the shot.
@@ -72,9 +72,10 @@ export function tailwind(options: TailwindOptions = {}) {
72
72
  const attribute = options.attribute ?? 'className';
73
73
  // Loaded on the first ask, as it takes a moment, and once: a project without Tailwind v4 has none.
74
74
  let loading: Promise<Catalog | undefined> | undefined;
75
- const catalog = ({ root }: ServerContext) =>
75
+ const catalog = ({ root, report }: ServerContext) =>
76
76
  (loading ??= loadCatalog(root, options.css).catch((problem: unknown) => {
77
- console.warn(`deictic/tailwind: no completions or class details, as ${problem instanceof Error ? problem.message : String(problem)}`);
77
+ const message = problem instanceof Error ? problem.message : String(problem);
78
+ report({ key: 'setup:tailwind', kind: 'setup', plugin: 'tailwind', message: `no completions or class details, as ${message}` });
78
79
  return undefined;
79
80
  }));
80
81
  const asked = async (request: Request): Promise<string[]> => {