deictic 0.0.1 → 0.1.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 (173) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/dist/annotations/client.d.ts +4 -0
  4. package/dist/annotations/client.d.ts.map +1 -0
  5. package/dist/annotations/client.js +497 -0
  6. package/dist/annotations/client.js.map +1 -0
  7. package/dist/annotations/index.d.ts +110 -0
  8. package/dist/annotations/index.d.ts.map +1 -0
  9. package/dist/annotations/index.js +22 -0
  10. package/dist/annotations/index.js.map +1 -0
  11. package/dist/astro.d.ts +29 -0
  12. package/dist/astro.d.ts.map +1 -0
  13. package/dist/astro.js +24 -0
  14. package/dist/astro.js.map +1 -0
  15. package/dist/bun.d.ts +12 -0
  16. package/dist/bun.d.ts.map +1 -0
  17. package/dist/bun.js +67 -0
  18. package/dist/bun.js.map +1 -0
  19. package/dist/client/index.d.ts +93 -0
  20. package/dist/client/index.d.ts.map +1 -0
  21. package/dist/client/index.js +1329 -0
  22. package/dist/client/index.js.map +1 -0
  23. package/dist/endpoints.js +354 -0
  24. package/dist/endpoints.js.map +1 -0
  25. package/dist/index.d.ts +220 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +10 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/index2.d.ts +23 -0
  30. package/dist/index3.d.ts +98 -0
  31. package/dist/index3.d.ts.map +1 -0
  32. package/dist/index4.d.ts +74 -0
  33. package/dist/index4.d.ts.map +1 -0
  34. package/dist/index5.d.ts +70 -0
  35. package/dist/index5.d.ts.map +1 -0
  36. package/dist/integration.d.ts +19 -0
  37. package/dist/integration.d.ts.map +1 -0
  38. package/dist/integration.js +277 -0
  39. package/dist/integration.js.map +1 -0
  40. package/dist/kept.js +23 -0
  41. package/dist/kept.js.map +1 -0
  42. package/dist/loader.d.ts +15 -0
  43. package/dist/loader.d.ts.map +1 -0
  44. package/dist/loader.js +17 -0
  45. package/dist/loader.js.map +1 -0
  46. package/dist/marks.js +14 -0
  47. package/dist/marks.js.map +1 -0
  48. package/dist/next.d.ts +17 -0
  49. package/dist/next.d.ts.map +1 -0
  50. package/dist/next.js +150 -0
  51. package/dist/next.js.map +1 -0
  52. package/dist/playwright.js +105 -0
  53. package/dist/playwright.js.map +1 -0
  54. package/dist/recommended/index.d.ts +25 -0
  55. package/dist/recommended/index.d.ts.map +1 -0
  56. package/dist/recommended/index.js +19 -0
  57. package/dist/recommended/index.js.map +1 -0
  58. package/dist/recordings/client.d.ts +4 -0
  59. package/dist/recordings/client.d.ts.map +1 -0
  60. package/dist/recordings/client.js +376 -0
  61. package/dist/recordings/client.js.map +1 -0
  62. package/dist/recordings/index.d.ts +2 -0
  63. package/dist/recordings/index.js +3 -0
  64. package/dist/recordings.js +235 -0
  65. package/dist/recordings.js.map +1 -0
  66. package/dist/screenshots/client.d.ts +23 -0
  67. package/dist/screenshots/client.d.ts.map +1 -0
  68. package/dist/screenshots/client.js +76 -0
  69. package/dist/screenshots/client.js.map +1 -0
  70. package/dist/screenshots/dom.d.ts +4 -0
  71. package/dist/screenshots/dom.d.ts.map +1 -0
  72. package/dist/screenshots/dom.js +92 -0
  73. package/dist/screenshots/dom.js.map +1 -0
  74. package/dist/screenshots/index.d.ts +2 -0
  75. package/dist/screenshots/index.js +98 -0
  76. package/dist/screenshots/index.js.map +1 -0
  77. package/dist/screenshots/rrweb.d.ts +9 -0
  78. package/dist/screenshots/rrweb.d.ts.map +1 -0
  79. package/dist/screenshots/rrweb.js +60 -0
  80. package/dist/screenshots/rrweb.js.map +1 -0
  81. package/dist/shortcut.js +63 -0
  82. package/dist/shortcut.js.map +1 -0
  83. package/dist/tailwind/client.d.ts +4 -0
  84. package/dist/tailwind/client.d.ts.map +1 -0
  85. package/dist/tailwind/client.js +613 -0
  86. package/dist/tailwind/client.js.map +1 -0
  87. package/dist/tailwind/index.d.ts +2 -0
  88. package/dist/tailwind/index.js +557 -0
  89. package/dist/tailwind/index.js.map +1 -0
  90. package/dist/tasks/client.d.ts +6 -0
  91. package/dist/tasks/client.d.ts.map +1 -0
  92. package/dist/tasks/client.js +642 -0
  93. package/dist/tasks/client.js.map +1 -0
  94. package/dist/tasks/index.d.ts +159 -0
  95. package/dist/tasks/index.d.ts.map +1 -0
  96. package/dist/tasks/index.js +348 -0
  97. package/dist/tasks/index.js.map +1 -0
  98. package/dist/vite.d.ts +17 -0
  99. package/dist/vite.d.ts.map +1 -0
  100. package/dist/vite.js +44 -0
  101. package/dist/vite.js.map +1 -0
  102. package/dist/voice/client.d.ts +4 -0
  103. package/dist/voice/client.d.ts.map +1 -0
  104. package/dist/voice/client.js +66 -0
  105. package/dist/voice/client.js.map +1 -0
  106. package/dist/voice/index.d.ts +47 -0
  107. package/dist/voice/index.d.ts.map +1 -0
  108. package/dist/voice/index.js +74 -0
  109. package/dist/voice/index.js.map +1 -0
  110. package/dist/waveform.js +93 -0
  111. package/dist/waveform.js.map +1 -0
  112. package/dist/webpack.d.ts +50 -0
  113. package/dist/webpack.d.ts.map +1 -0
  114. package/dist/webpack.js +78 -0
  115. package/dist/webpack.js.map +1 -0
  116. package/package.json +307 -7
  117. package/skills/deictic/SKILL.md +47 -0
  118. package/skills/deictic/references/install.md +81 -0
  119. package/skills/deictic/references/recordings.md +83 -0
  120. package/skills/deictic/references/tasks.md +79 -0
  121. package/skills/deictic/references/watch.md +43 -0
  122. package/skills/deictic/scripts/frame.mjs +62 -0
  123. package/skills/deictic/scripts/lib.mjs +193 -0
  124. package/skills/deictic/scripts/recording.mjs +186 -0
  125. package/skills/deictic/scripts/task.mjs +84 -0
  126. package/skills/deictic/scripts/transcribe.mjs +93 -0
  127. package/skills/deictic/scripts/voice.mjs +50 -0
  128. package/skills/deictic/scripts/watch.mjs +51 -0
  129. package/src/astro.ts +34 -0
  130. package/src/bun.ts +79 -0
  131. package/src/client/index.ts +833 -0
  132. package/src/client/lightbox.ts +256 -0
  133. package/src/client/style.ts +243 -0
  134. package/src/client/tooltip.ts +78 -0
  135. package/src/client/waveform.ts +98 -0
  136. package/src/index.ts +240 -0
  137. package/src/loader.ts +28 -0
  138. package/src/next.ts +133 -0
  139. package/src/plugins/annotations/client.ts +301 -0
  140. package/src/plugins/annotations/draw.ts +169 -0
  141. package/src/plugins/annotations/index.ts +105 -0
  142. package/src/plugins/annotations/svg.ts +61 -0
  143. package/src/plugins/recommended/index.ts +35 -0
  144. package/src/plugins/recordings/client.ts +315 -0
  145. package/src/plugins/recordings/index.ts +174 -0
  146. package/src/plugins/recordings/marks.ts +11 -0
  147. package/src/plugins/recordings/ours.ts +70 -0
  148. package/src/plugins/recordings/replay.ts +139 -0
  149. package/src/plugins/screenshots/client.ts +63 -0
  150. package/src/plugins/screenshots/dom.ts +79 -0
  151. package/src/plugins/screenshots/index.ts +194 -0
  152. package/src/plugins/screenshots/playwright.ts +119 -0
  153. package/src/plugins/screenshots/rrweb.ts +45 -0
  154. package/src/plugins/tailwind/catalog.ts +396 -0
  155. package/src/plugins/tailwind/client.ts +669 -0
  156. package/src/plugins/tailwind/index.ts +267 -0
  157. package/src/plugins/tasks/client.ts +622 -0
  158. package/src/plugins/tasks/index.ts +513 -0
  159. package/src/plugins/voice/client.ts +57 -0
  160. package/src/plugins/voice/index.ts +114 -0
  161. package/src/shortcut.ts +83 -0
  162. package/src/tools/astro.ts +81 -0
  163. package/src/tools/editor.ts +22 -0
  164. package/src/tools/endpoints.ts +163 -0
  165. package/src/tools/history.ts +203 -0
  166. package/src/tools/integration.ts +106 -0
  167. package/src/tools/kept.ts +21 -0
  168. package/src/tools/locate.ts +94 -0
  169. package/src/tools/plugins.ts +41 -0
  170. package/src/tools/source.ts +72 -0
  171. package/src/vite.ts +62 -0
  172. package/src/webpack.ts +107 -0
  173. package/index.js +0 -1
@@ -0,0 +1,256 @@
1
+ /**
2
+ * The lightbox: what a panel has attached (a capture, a recording's replay, a voice clip), big, over everything,
3
+ * one at a time, ← and → between them. It grows out of the element that opened it and shrinks back into it, or
4
+ * fades where motion is reduced. A sound plays in a player of its own: play, its waveform with what's played
5
+ * lit (click or drag it to seek), and the time. It's a modal (`data-deictic-modal`): Esc closes it, not the popup.
6
+ */
7
+ import type { LightboxItem, LightboxOptions } from '#src/index.ts';
8
+
9
+ import { type Colors, drawBars, peaksOf } from './waveform.ts';
10
+
11
+ const EASE = 'cubic-bezier(0.2, 0.8, 0.2, 1)';
12
+ const PLAY = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 4v16l13-8z" fill="currentColor"/></svg>';
13
+ const PAUSE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 4h4v16H6zM14 4h4v16h-4z" fill="currentColor"/></svg>';
14
+
15
+ const reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
16
+ const clock = (s: number) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, '0')}`;
17
+
18
+ /**
19
+ * Opens it in `root`. `pinned` draws it where `root` is in the page instead, with no backdrop, motion or keys, and
20
+ * actions that don't close it: for a page of deictic's own states (`lightboxIn`).
21
+ */
22
+ export function openLightbox(
23
+ root: ShadowRoot,
24
+ items: LightboxItem[],
25
+ { at = 0, from, pinned = false }: LightboxOptions & { pinned?: boolean } = {},
26
+ ): { close: () => void } {
27
+ const box = div(pinned ? 'lightbox pinned' : 'lightbox');
28
+ if (!pinned) {
29
+ box.dataset.deicticModal = '';
30
+ box.setAttribute('role', 'dialog');
31
+ box.setAttribute('aria-modal', 'true');
32
+ }
33
+ const backdrop = div('lb-backdrop');
34
+ const stage = div('lb-stage');
35
+ const head = div('lb-head');
36
+ const title = div('lb-title');
37
+ const count = div('lb-count');
38
+ const actions = div('lb-actions');
39
+ const close = button('×', 'Close (Esc)', 'lb-close');
40
+ head.append(title, count, actions, close);
41
+ const body = div('lb-body');
42
+ stage.append(head, body);
43
+ const prev = button('‹', 'Previous (←)', 'lb-prev');
44
+ const next = button('›', 'Next (→)', 'lb-next');
45
+ box.append(backdrop, stage, ...(items.length > 1 ? [prev, next] : []));
46
+ root.append(box);
47
+
48
+ let index = Math.min(Math.max(0, at), items.length - 1);
49
+ let leave: (() => void) | undefined;
50
+ let closing = false;
51
+
52
+ const show = (i: number, animate: boolean) => {
53
+ leave?.();
54
+ leave = undefined;
55
+ index = (i + items.length) % items.length;
56
+ const item = items[index]!;
57
+ box.setAttribute('aria-label', item.title);
58
+ title.textContent = item.title;
59
+ count.textContent = items.length > 1 ? `${index + 1} / ${items.length}` : '';
60
+ actions.replaceChildren(
61
+ ...(item.actions ?? []).map((a) => {
62
+ const b = button(a.label, a.title ?? '', '');
63
+ b.addEventListener('click', () => {
64
+ if (!pinned) done();
65
+ a.run();
66
+ });
67
+ return b;
68
+ }),
69
+ );
70
+ // A sound plays as it opens, but not on a page that only shows the lightbox.
71
+ const content = contentOf(item, !pinned);
72
+ body.replaceChildren(content.element);
73
+ leave = content.leave;
74
+ if (animate && !reduced()) body.animate({ opacity: [0, 1] }, { duration: 160, easing: 'ease-out' });
75
+ };
76
+
77
+ /** The transform that puts the stage where `from` is: what it grows from and shrinks back to. */
78
+ const fromRect = () => {
79
+ if (from === undefined || !from.isConnected) return undefined;
80
+ const f = from.getBoundingClientRect();
81
+ const s = stage.getBoundingClientRect();
82
+ if (f.width === 0 || s.width === 0) return undefined;
83
+ return `translate(${f.left - s.left}px, ${f.top - s.top}px) scale(${f.width / s.width}, ${f.height / s.height})`;
84
+ };
85
+
86
+ const onKey = (e: KeyboardEvent) => {
87
+ if (e.key === 'Escape') done();
88
+ else if (e.key === 'ArrowLeft' && items.length > 1) show(index - 1, true);
89
+ else if (e.key === 'ArrowRight' && items.length > 1) show(index + 1, true);
90
+ else return;
91
+ // The popup, under it, waits for its own Esc.
92
+ e.preventDefault();
93
+ e.stopImmediatePropagation();
94
+ };
95
+ if (!pinned) addEventListener('keydown', onKey, true);
96
+
97
+ function done() {
98
+ if (closing) return;
99
+ closing = true;
100
+ removeEventListener('keydown', onKey, true);
101
+ leave?.();
102
+ if (pinned) return box.remove();
103
+ const gone = () => {
104
+ box.remove();
105
+ if (from instanceof HTMLElement && from.isConnected) from.focus({ preventScroll: true });
106
+ };
107
+ if (reduced()) return gone();
108
+ const to = fromRect();
109
+ backdrop.animate({ opacity: [1, 0] }, { duration: 200, easing: 'ease-in', fill: 'forwards' });
110
+ stage
111
+ .animate(
112
+ to === undefined
113
+ ? { opacity: [1, 0], transform: ['none', 'scale(0.96)'] }
114
+ : { transform: ['none', to], opacity: [1, 1, 0], offset: [0, 0.8, 1] },
115
+ { duration: 220, easing: EASE, fill: 'forwards' },
116
+ )
117
+ .finished.then(gone, gone);
118
+ }
119
+
120
+ backdrop.addEventListener('click', done);
121
+ close.addEventListener('click', done);
122
+ prev.addEventListener('click', () => show(index - 1, true));
123
+ next.addEventListener('click', () => show(index + 1, true));
124
+
125
+ show(index, false);
126
+ if (pinned) {
127
+ close.hidden = true;
128
+ return { close: done };
129
+ }
130
+ close.focus({ preventScroll: true });
131
+ if (reduced()) {
132
+ box.animate({ opacity: [0, 1] }, { duration: 150 });
133
+ } else {
134
+ backdrop.animate({ opacity: [0, 1] }, { duration: 240, easing: 'ease-out' });
135
+ const grow = fromRect();
136
+ stage.animate(
137
+ grow === undefined
138
+ ? { opacity: [0, 1], transform: ['scale(0.96)', 'none'] }
139
+ : { transform: [grow, 'none'], opacity: [0, 1, 1], offset: [0, 0.2, 1] },
140
+ { duration: 280, easing: EASE },
141
+ );
142
+ }
143
+ return { close: done };
144
+ }
145
+
146
+ /** An item, drawn: what goes in the body, and what to stop when it's left (a sound playing). */
147
+ function contentOf(item: LightboxItem, autoplay: boolean): { element: HTMLElement; leave?: () => void } {
148
+ switch (item.kind) {
149
+ case 'image': {
150
+ const img = Object.assign(document.createElement('img'), { src: item.url, alt: item.title, className: 'lb-image', draggable: false });
151
+ return { element: img };
152
+ }
153
+ case 'page': {
154
+ const frame = Object.assign(document.createElement('iframe'), { src: item.url, title: item.title, className: 'lb-page' });
155
+ frame.allow = 'autoplay; fullscreen';
156
+ return { element: frame };
157
+ }
158
+ case 'audio':
159
+ return player(item.url, autoplay);
160
+ }
161
+ }
162
+
163
+ /** A sound: play and pause, its waveform with what's played lit, and the time. With `autoplay`, it starts playing. */
164
+ function player(url: string, autoplay: boolean): { element: HTMLElement; leave: () => void } {
165
+ const el = div('lb-audio');
166
+ const play = button('', 'Play (Space)', 'lb-play');
167
+ const wave = Object.assign(document.createElement('canvas'), { className: 'lb-wave' });
168
+ wave.setAttribute('role', 'slider');
169
+ wave.setAttribute('aria-label', 'Where in the clip');
170
+ wave.tabIndex = 0;
171
+ const time = div('lb-time');
172
+ el.append(play, wave, time);
173
+ const audio = new Audio(url);
174
+ const colors: Colors = { played: '#3ddc7c', rest: '#52525b' };
175
+ // Flat until the clip's read: the bars rise when its peaks are in.
176
+ let peaks: number[] = Array<number>(120).fill(0.05);
177
+ let frame = 0;
178
+ // MediaRecorder's webm says no length until it's played through; reading the peaks gives it sooner.
179
+ let length = 0;
180
+ const lengthOf = () => (Number.isFinite(audio.duration) && audio.duration > 0 ? audio.duration : length);
181
+ const draw = () => {
182
+ const total = lengthOf();
183
+ drawBars(wave, peaks, total > 0 ? audio.currentTime / total : 0, colors);
184
+ time.textContent = `${clock(audio.currentTime)} / ${total > 0 ? clock(total) : '–:––'}`;
185
+ wave.setAttribute('aria-valuenow', String(Math.round(audio.currentTime)));
186
+ };
187
+ const loop = () => {
188
+ draw();
189
+ frame = audio.paused ? 0 : requestAnimationFrame(loop);
190
+ };
191
+ const state = () => {
192
+ play.innerHTML = audio.paused ? PLAY : PAUSE;
193
+ play.title = audio.paused ? 'Play (Space)' : 'Pause (Space)';
194
+ if (!audio.paused && frame === 0) frame = requestAnimationFrame(loop);
195
+ draw();
196
+ };
197
+ audio.addEventListener('play', state);
198
+ audio.addEventListener('pause', state);
199
+ audio.addEventListener('ended', state);
200
+ audio.addEventListener('loadedmetadata', draw);
201
+ const toggle = () => void (audio.paused ? audio.play().catch(() => {}) : audio.pause());
202
+ play.addEventListener('click', toggle);
203
+ const seek = (e: PointerEvent) => {
204
+ const r = wave.getBoundingClientRect();
205
+ const total = lengthOf();
206
+ if (total > 0) audio.currentTime = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width)) * total;
207
+ draw();
208
+ };
209
+ wave.addEventListener('pointerdown', (e) => {
210
+ wave.setPointerCapture(e.pointerId);
211
+ seek(e);
212
+ });
213
+ wave.addEventListener('pointermove', (e) => {
214
+ if (wave.hasPointerCapture(e.pointerId)) seek(e);
215
+ });
216
+ el.addEventListener('keydown', (e) => {
217
+ if (e.key !== ' ') return;
218
+ e.preventDefault();
219
+ toggle();
220
+ });
221
+ void peaksOf(url, 120).then(
222
+ (read) => {
223
+ peaks = read.peaks;
224
+ length = read.duration;
225
+ draw();
226
+ },
227
+ // Undecodable here: the player still plays it, over flat bars.
228
+ () => {},
229
+ );
230
+ state();
231
+ if (autoplay) void audio.play().catch(() => state());
232
+ // The canvas has its size once it's in the page.
233
+ requestAnimationFrame(draw);
234
+ return {
235
+ element: el,
236
+ leave: () => {
237
+ audio.pause();
238
+ cancelAnimationFrame(frame);
239
+ },
240
+ };
241
+ }
242
+
243
+ function div(className: string): HTMLDivElement {
244
+ const el = document.createElement('div');
245
+ el.className = className;
246
+ return el;
247
+ }
248
+
249
+ function button(text: string, title: string, className: string): HTMLButtonElement {
250
+ const el = document.createElement('button');
251
+ el.type = 'button';
252
+ el.textContent = text;
253
+ el.title = title;
254
+ el.className = className;
255
+ return el;
256
+ }
@@ -0,0 +1,243 @@
1
+ /**
2
+ * The overlay's styles, in its shadow root. Panels style their bodies with the same custom
3
+ * properties, so a plugin's panel looks like the rest without styles of its own for the basics.
4
+ */
5
+ export const STYLE = `
6
+ :host {
7
+ --deictic-accent: #12b358;
8
+ --deictic-on-accent: #04130b;
9
+ --deictic-bg: #18181b;
10
+ --deictic-fg: #f4f4f5;
11
+ --deictic-muted: #a1a1aa;
12
+ --deictic-line: #3f3f46;
13
+ --deictic-problem: #f87171;
14
+ all: initial;
15
+ /* Inherited by everything in the root: a thumb and no track, on whatever the panel's background is. */
16
+ scrollbar-color: var(--deictic-line) transparent;
17
+ }
18
+ /* The host takes no room in the page: everything in it is fixed, so nothing of deictic's moves or scrolls it. */
19
+ :host(deictic-overlay) { display: contents; }
20
+ .box {
21
+ position: fixed;
22
+ display: none;
23
+ z-index: 2147483646;
24
+ pointer-events: none;
25
+ box-sizing: border-box;
26
+ outline: 2px solid var(--deictic-accent);
27
+ background: rgb(18 179 88 / 0.1);
28
+ }
29
+ .box.shown { display: block; }
30
+ .box.inner { outline: 1px dashed var(--deictic-accent); background: none; }
31
+ /* The element the popup is open on: dashed and off it a little, with no fill, so what's tried on it shows as it is. */
32
+ .box.on { outline: 1px dashed var(--deictic-accent); border-radius: 4px; background: none; }
33
+ .label {
34
+ position: absolute;
35
+ left: -2px;
36
+ bottom: 100%;
37
+ padding: 1px 6px;
38
+ font: 12px/1.5 ui-monospace, monospace;
39
+ white-space: nowrap;
40
+ color: var(--deictic-on-accent);
41
+ background: var(--deictic-accent);
42
+ }
43
+ .label.below { top: 100%; bottom: auto; }
44
+ .panel {
45
+ position: fixed;
46
+ z-index: 2147483647;
47
+ width: min(360px, calc(100vw - 16px));
48
+ max-height: 60vh;
49
+ display: flex;
50
+ flex-direction: column;
51
+ box-sizing: border-box;
52
+ border: 1px solid var(--deictic-line);
53
+ border-radius: 8px;
54
+ box-shadow: 0 12px 32px rgb(0 0 0 / 0.35);
55
+ font: 13px/1.4 system-ui, sans-serif;
56
+ color: var(--deictic-fg);
57
+ background: var(--deictic-bg);
58
+ }
59
+ .panel.pinned { position: relative; z-index: auto; max-height: none; }
60
+ @media (prefers-reduced-motion: no-preference) {
61
+ .panel:not(.pinned) { animation: deictic-in 0.12s ease-out; }
62
+ }
63
+ @keyframes deictic-in {
64
+ from { opacity: 0; translate: 0 4px; }
65
+ }
66
+ .head {
67
+ display: flex;
68
+ align-items: flex-end;
69
+ gap: 2px;
70
+ padding: 4px 8px 0;
71
+ }
72
+ /* Over the page the head is what the popup is dragged by; no touch scrolling starts there. */
73
+ .panel:not(.pinned) .head { cursor: grab; touch-action: none; user-select: none; }
74
+ .panel.dragging .head, .panel.dragging .head button { cursor: grabbing; }
75
+ .head .tab {
76
+ border: 0;
77
+ border-bottom: 2px solid transparent;
78
+ border-radius: 0;
79
+ padding: 4px 8px;
80
+ font-weight: 600;
81
+ color: var(--deictic-muted);
82
+ }
83
+ .head .tab:hover { color: var(--deictic-fg); }
84
+ .head .tab[aria-selected='true'] { color: var(--deictic-fg); border-bottom-color: var(--deictic-accent); }
85
+ .head .close { margin: 0 0 3px auto; }
86
+ .bar {
87
+ display: flex;
88
+ align-items: center;
89
+ gap: 2px;
90
+ padding: 4px 8px;
91
+ border-top: 1px solid var(--deictic-line);
92
+ border-bottom: 1px solid var(--deictic-line);
93
+ }
94
+ .bar .where {
95
+ display: inline-flex;
96
+ align-items: center;
97
+ gap: 4px;
98
+ min-width: 0;
99
+ margin-right: auto;
100
+ font: 12px ui-monospace, monospace;
101
+ color: var(--deictic-muted);
102
+ text-decoration: none;
103
+ }
104
+ .bar .where span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
105
+ .bar .where svg { flex: none; }
106
+ .bar .where:hover, .bar .where:focus-visible { color: var(--deictic-fg); }
107
+ .bar .where:hover span { text-decoration: underline; }
108
+ .lightbox {
109
+ position: fixed;
110
+ inset: 0;
111
+ z-index: 2147483647;
112
+ display: flex;
113
+ align-items: center;
114
+ justify-content: center;
115
+ font: 13px/1.4 system-ui, sans-serif;
116
+ color: var(--deictic-fg);
117
+ }
118
+ .lb-backdrop { position: absolute; inset: 0; background: rgb(9 9 11 / 0.72); backdrop-filter: blur(2px); }
119
+ .lb-stage {
120
+ position: relative;
121
+ display: flex;
122
+ flex-direction: column;
123
+ max-width: 92vw;
124
+ max-height: 90vh;
125
+ border: 1px solid var(--deictic-line);
126
+ border-radius: 10px;
127
+ background: var(--deictic-bg);
128
+ box-shadow: 0 24px 64px rgb(0 0 0 / 0.5);
129
+ transform-origin: 0 0;
130
+ overflow: hidden;
131
+ }
132
+ .lb-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--deictic-line); }
133
+ .lb-title { font-weight: 600; }
134
+ .lb-count { color: var(--deictic-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
135
+ .lb-actions { display: flex; gap: 6px; margin-left: auto; }
136
+ .lb-body { display: flex; justify-content: center; min-height: 0; background: #09090b; }
137
+ .lb-image { display: block; max-width: 92vw; max-height: calc(90vh - 48px); object-fit: contain; }
138
+ .lb-page { display: block; width: min(1280px, 92vw); height: min(860px, calc(90vh - 48px)); border: 0; background: #18181b; }
139
+ .lb-audio { display: flex; align-items: center; gap: 12px; width: min(640px, 86vw); padding: 20px 16px; }
140
+ .lb-play {
141
+ flex: none;
142
+ display: inline-flex;
143
+ align-items: center;
144
+ justify-content: center;
145
+ width: 40px;
146
+ height: 40px;
147
+ padding: 0;
148
+ border: 0;
149
+ border-radius: 50%;
150
+ color: var(--deictic-on-accent);
151
+ background: var(--deictic-accent);
152
+ }
153
+ .lb-play svg { width: 16px; height: 16px; }
154
+ .lb-wave { flex: 1; min-width: 0; height: 56px; cursor: pointer; border-radius: 4px; }
155
+ .lb-wave:focus-visible { outline: 1px solid var(--deictic-accent); outline-offset: 2px; }
156
+ .lb-time { flex: none; min-width: 9ch; text-align: right; font: 12px ui-monospace, monospace; color: var(--deictic-muted); }
157
+ .lb-prev, .lb-next {
158
+ position: absolute;
159
+ top: 50%;
160
+ translate: 0 -50%;
161
+ width: 40px;
162
+ height: 40px;
163
+ padding: 0;
164
+ border: 1px solid var(--deictic-line);
165
+ border-radius: 50%;
166
+ font-size: 22px;
167
+ line-height: 1;
168
+ background: var(--deictic-bg);
169
+ }
170
+ .lb-prev { left: 16px; }
171
+ .lb-next { right: 16px; }
172
+ .lightbox.pinned { position: relative; inset: auto; z-index: auto; display: block; padding: 0 64px; }
173
+ .lightbox.pinned .lb-stage { max-width: 100%; max-height: none; }
174
+ .lightbox.pinned .lb-page { width: 100%; height: 420px; }
175
+ .lightbox.pinned .lb-image { max-width: 100%; max-height: 420px; }
176
+ .lightbox.pinned .lb-backdrop { display: none; }
177
+ .lightbox.pinned .lb-audio { width: 100%; box-sizing: border-box; }
178
+ .lightbox.pinned .lb-close { display: none; }
179
+ .tip {
180
+ position: fixed;
181
+ left: 0;
182
+ top: 0;
183
+ z-index: 2147483647;
184
+ max-width: 280px;
185
+ padding: 3px 6px;
186
+ border: 1px solid var(--deictic-line);
187
+ border-radius: 4px;
188
+ font: 12px/1.4 system-ui, sans-serif;
189
+ color: var(--deictic-fg);
190
+ background: #09090b;
191
+ box-shadow: 0 4px 12px rgb(0 0 0 / 0.3);
192
+ pointer-events: none;
193
+ visibility: hidden;
194
+ opacity: 0;
195
+ transition: opacity 0.12s;
196
+ }
197
+ .tip.shown { visibility: visible; opacity: 1; }
198
+ button {
199
+ font: inherit;
200
+ color: inherit;
201
+ background: transparent;
202
+ border: 1px solid var(--deictic-line);
203
+ border-radius: 4px;
204
+ padding: 1px 7px;
205
+ cursor: pointer;
206
+ }
207
+ button:hover { border-color: var(--deictic-muted); }
208
+ button:disabled { opacity: 0.5; cursor: default; }
209
+ button:disabled:hover { border-color: var(--deictic-line); }
210
+ /* One ring for whatever the keyboard lands on, in place of each browser's own. */
211
+ button:focus-visible, a:focus-visible { outline: 1px solid var(--deictic-accent); outline-offset: 1px; }
212
+ button.icon {
213
+ flex: none;
214
+ display: inline-flex;
215
+ align-items: center;
216
+ justify-content: center;
217
+ width: 22px;
218
+ height: 22px;
219
+ padding: 0;
220
+ border: 0;
221
+ color: var(--deictic-muted);
222
+ }
223
+ button.icon svg { width: 14px; height: 14px; }
224
+ button.icon:hover:not(:disabled) { color: var(--deictic-fg); background: rgb(255 255 255 / 0.08); }
225
+ button.primary { background: var(--deictic-accent); border-color: var(--deictic-accent); color: var(--deictic-on-accent); }
226
+ input, textarea {
227
+ box-sizing: border-box;
228
+ width: 100%;
229
+ font: 12px ui-monospace, monospace;
230
+ color: inherit;
231
+ background: #09090b;
232
+ border: 1px solid var(--deictic-line);
233
+ border-radius: 4px;
234
+ padding: 4px 6px;
235
+ }
236
+ input:focus, textarea:focus { outline: 1px solid var(--deictic-accent); }
237
+ code { font: 12px ui-monospace, monospace; }
238
+ /* Border-box, as the popup holds the body's height by its whole box while a tab reads. */
239
+ .body { box-sizing: border-box; padding: 8px; overflow: auto; }
240
+ .status { padding: 0 8px 6px; font-size: 12px; color: var(--deictic-muted); }
241
+ .status:empty { display: none; }
242
+ .status.problem { color: var(--deictic-problem); }
243
+ `;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * One tooltip for everything deictic draws in a shadow root: whatever has a `title` (or `data-tip`) shows it
3
+ * in a box of ours, soon after the pointer rests or focus lands, instead of the browser's, which comes late
4
+ * and looks like nothing else here. Plugins only set `title`, as they would anywhere; the first hover moves
5
+ * it to `data-tip`, so the browser's own stays away, and gives a textless control the title as its name.
6
+ * The box is fixed in the root, so no panel's scrolling clips it.
7
+ */
8
+ const DELAY = 300;
9
+
10
+ export function tooltips(root: ShadowRoot): void {
11
+ const tip = document.createElement('div');
12
+ tip.className = 'tip';
13
+ tip.setAttribute('role', 'tooltip');
14
+ root.append(tip);
15
+ let timer = 0;
16
+ let over: Element | undefined;
17
+
18
+ const hide = () => {
19
+ clearTimeout(timer);
20
+ over = undefined;
21
+ tip.classList.remove('shown');
22
+ };
23
+ const show = (el: Element) => {
24
+ const text = el.getAttribute('data-tip');
25
+ if (text === null || text === '' || !el.isConnected) return hide();
26
+ tip.textContent = text;
27
+ // Last in the root, over a modal or toolbar added since at the same z-index.
28
+ if (tip !== root.lastElementChild) root.append(tip);
29
+ tip.classList.add('shown');
30
+ // Centred below it, kept on screen; above it where there's no room below.
31
+ const r = el.getBoundingClientRect();
32
+ const t = tip.getBoundingClientRect();
33
+ const left = Math.max(8, Math.min(r.left + r.width / 2 - t.width / 2, innerWidth - t.width - 8));
34
+ const top = r.bottom + 6 + t.height > innerHeight - 8 ? r.top - 6 - t.height : r.bottom + 6;
35
+ Object.assign(tip.style, { left: `${left}px`, top: `${top}px` });
36
+ };
37
+ /** The element with a tip around where the event happened, its `title` taken over the first time. */
38
+ const tipped = (e: Event) => {
39
+ for (const node of e.composedPath()) {
40
+ if (!(node instanceof Element)) continue;
41
+ if (node === tip) return undefined;
42
+ // A frame's title is its name for assistive tech, not a tip; what's in it has tips of its own.
43
+ if (node.localName === 'iframe') return undefined;
44
+ const title = node.getAttribute('title');
45
+ if (title !== null) {
46
+ node.removeAttribute('title');
47
+ if (title === '') continue;
48
+ node.setAttribute('data-tip', title);
49
+ // A control with no text of its own (an icon, ×, ↶) is known by its tip; one with text keeps its name.
50
+ if (!node.hasAttribute('aria-label') && (node.textContent ?? '').trim().length <= 1) node.setAttribute('aria-label', title);
51
+ else node.setAttribute('aria-description', title);
52
+ }
53
+ if (node.hasAttribute('data-tip')) return node;
54
+ }
55
+ return undefined;
56
+ };
57
+ const enter = (e: Event) => {
58
+ const el = tipped(e);
59
+ if (el === over) return;
60
+ hide();
61
+ if (el === undefined) return;
62
+ over = el;
63
+ timer = window.setTimeout(() => show(el), e.type === 'focusin' ? 0 : DELAY);
64
+ };
65
+ root.addEventListener('pointerover', enter);
66
+ root.addEventListener('focusin', (e) => {
67
+ // Focus from the keyboard only: a click focuses too, and its tip is the pointer's.
68
+ if ((e.target as Element).matches(':focus-visible')) enter(e);
69
+ });
70
+ root.addEventListener('pointerout', (e) => {
71
+ const to = (e as PointerEvent).relatedTarget;
72
+ if (over !== undefined && !(to instanceof Node && over.contains(to))) hide();
73
+ });
74
+ root.addEventListener('focusout', hide);
75
+ // A press acts, and what it changes (a mic turned on) may change the tip: the next hover shows the new one.
76
+ root.addEventListener('pointerdown', hide);
77
+ addEventListener('scroll', hide, { capture: true, passive: true });
78
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Waveforms: a clip's, read off its audio, drawn as bars with what's played in the accent; and a mic's live,
3
+ * a meter scrolling left as it hears. For the lightbox's player and whatever records the mic (the task
4
+ * panel's Voice, the recording toolbar's mic). Bars, not a line: they read at any size, and at a glance.
5
+ */
6
+
7
+ /**
8
+ * 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
9
+ * seconds: MediaRecorder's webm doesn't say until it's played through.
10
+ */
11
+ export async function peaksOf(url: string, bars: number): Promise<{ peaks: number[]; duration: number }> {
12
+ const data = await (await fetch(url)).arrayBuffer();
13
+ const context = new AudioContext();
14
+ try {
15
+ const audio = await context.decodeAudioData(data);
16
+ const samples = audio.getChannelData(0);
17
+ const size = Math.max(1, Math.floor(samples.length / bars));
18
+ const peaks: number[] = [];
19
+ for (let b = 0; b < bars; b++) {
20
+ // The stretch's loudness as its RMS: a peak would make every click a wall.
21
+ let sum = 0;
22
+ const from = b * size;
23
+ for (let i = from; i < Math.min(samples.length, from + size); i++) sum += samples[i]! * samples[i]!;
24
+ peaks.push(Math.sqrt(sum / size));
25
+ }
26
+ const top = Math.max(...peaks, 1e-6);
27
+ return { peaks: peaks.map((p) => p / top), duration: audio.duration };
28
+ } finally {
29
+ void context.close();
30
+ }
31
+ }
32
+
33
+ export interface Colors {
34
+ /** What's played. */
35
+ played: string;
36
+ /** What isn't, yet. */
37
+ rest: string;
38
+ }
39
+
40
+ /** Draws `peaks` as bars across `canvas`, centred on its middle, the share `progress` (0–1) of them played. */
41
+ export function drawBars(canvas: HTMLCanvasElement, peaks: readonly number[], progress: number, colors: Colors): void {
42
+ const { width, height } = fit(canvas);
43
+ const g = canvas.getContext('2d');
44
+ if (g === null) return;
45
+ g.clearRect(0, 0, width, height);
46
+ const step = width / Math.max(1, peaks.length);
47
+ const bar = Math.max(1, step * 0.6);
48
+ const dpr = devicePixelRatio;
49
+ peaks.forEach((p, i) => {
50
+ // Silence still shows as a sliver, so the clip's length reads from end to end.
51
+ const h = Math.max(2 * dpr, p * height * 0.9);
52
+ g.fillStyle = (i + 0.5) / peaks.length <= progress ? colors.played : colors.rest;
53
+ g.fillRect(i * step + (step - bar) / 2, (height - h) / 2, bar, h);
54
+ });
55
+ }
56
+
57
+ /**
58
+ * The mic's level, live, as bars scrolling in from the right, drawn on `canvas` until the answer's called.
59
+ * It listens to `stream` on its own; the recording goes on as it was.
60
+ */
61
+ export function liveWaveform(canvas: HTMLCanvasElement, stream: MediaStream, colors: Colors): () => void {
62
+ const context = new AudioContext();
63
+ const analyser = context.createAnalyser();
64
+ analyser.fftSize = 1024;
65
+ context.createMediaStreamSource(stream).connect(analyser);
66
+ const samples = new Float32Array(analyser.fftSize);
67
+ const levels: number[] = [];
68
+ let frame = 0;
69
+ let last = 0;
70
+ const tick = (now: number) => {
71
+ frame = requestAnimationFrame(tick);
72
+ // About 20 bars a second, whatever the display's rate.
73
+ if (now - last < 50) return;
74
+ last = now;
75
+ analyser.getFloatTimeDomainData(samples);
76
+ let sum = 0;
77
+ for (const s of samples) sum += s * s;
78
+ // Speech sits low in the range: lifted so a normal voice fills most of the height.
79
+ levels.push(Math.min(1, Math.sqrt(sum / samples.length) * 4));
80
+ const room = Math.max(8, Math.floor(canvas.clientWidth / 4));
81
+ if (levels.length > room) levels.splice(0, levels.length - room);
82
+ drawBars(canvas, [...Array<number>(room - levels.length).fill(0), ...levels], 1, colors);
83
+ };
84
+ frame = requestAnimationFrame(tick);
85
+ return () => {
86
+ cancelAnimationFrame(frame);
87
+ void context.close();
88
+ };
89
+ }
90
+
91
+ /** Sizes the canvas's pixels to its box, at the display's density: what it draws stays sharp. */
92
+ function fit(canvas: HTMLCanvasElement): { width: number; height: number } {
93
+ const width = Math.max(1, Math.round(canvas.clientWidth * devicePixelRatio));
94
+ const height = Math.max(1, Math.round(canvas.clientHeight * devicePixelRatio));
95
+ if (canvas.width !== width) canvas.width = width;
96
+ if (canvas.height !== height) canvas.height = height;
97
+ return { width, height };
98
+ }