@stefan.inc/feedback-engine 0.0.0-stage → 1.0.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 (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/package.json +57 -5
  4. package/src/core/annotations.ts +104 -0
  5. package/src/core/cardLayout.ts +82 -0
  6. package/src/core/describe.ts +143 -0
  7. package/src/core/index.ts +9 -0
  8. package/src/core/model.ts +133 -0
  9. package/src/core/problem.ts +51 -0
  10. package/src/core/report.ts +74 -0
  11. package/src/core/session.ts +184 -0
  12. package/src/core/taskTitle.ts +35 -0
  13. package/src/core/tree.ts +117 -0
  14. package/src/dom/capture.ts +78 -0
  15. package/src/dom/image.ts +316 -0
  16. package/src/dom/procrastimate.ts +205 -0
  17. package/src/dom/scene.ts +286 -0
  18. package/src/dom/screenshot.ts +118 -0
  19. package/src/dom/share.ts +71 -0
  20. package/src/dom/tags.ts +21 -0
  21. package/src/dom/webhook.ts +89 -0
  22. package/src/dom/zip.ts +52 -0
  23. package/src/editor/Button.svelte +125 -0
  24. package/src/editor/Editor.svelte +1078 -0
  25. package/src/editor/Host.svelte +31 -0
  26. package/src/editor/ItemsSheet.svelte +233 -0
  27. package/src/editor/Pill.svelte +65 -0
  28. package/src/editor/ProblemCard.svelte +67 -0
  29. package/src/editor/ProcrastimateSheet.svelte +304 -0
  30. package/src/editor/WebhookSheet.svelte +132 -0
  31. package/src/editor/engine.ts +154 -0
  32. package/src/editor/setup.ts +106 -0
  33. package/src/next/index.d.ts +13 -0
  34. package/src/next/index.js +69 -0
  35. package/src/next/loader.js +23 -0
  36. package/src/react/components.ts +101 -0
  37. package/src/react/index.ts +44 -0
  38. package/src/react/public.d.ts +107 -0
  39. package/src/svelte/index.ts +32 -0
  40. package/src/vite/index.d.ts +44 -0
  41. package/src/vite/index.js +207 -0
  42. package/src/vite/react.js +172 -0
@@ -0,0 +1,1078 @@
1
+ <svelte:options css="injected" />
2
+
3
+ <script lang="ts">
4
+ import {
5
+ hitTest,
6
+ nearestComponent,
7
+ nearestSource,
8
+ paletteColor,
9
+ Session,
10
+ tag,
11
+ title,
12
+ type Frame,
13
+ } from '../core/index.ts';
14
+ import type { Screen } from '../dom/capture.ts';
15
+ import {
16
+ buildExport,
17
+ canShare,
18
+ copyExport,
19
+ exportTitles,
20
+ saveExport,
21
+ shareExport,
22
+ type Export,
23
+ type ExportFormat,
24
+ } from '../dom/share.ts';
25
+ import type { Webhook } from '../dom/webhook.ts';
26
+ import type { Engine } from './engine.ts';
27
+ import ItemsSheet from './ItemsSheet.svelte';
28
+ import ProcrastimateSheet from './ProcrastimateSheet.svelte';
29
+ import WebhookSheet from './WebhookSheet.svelte';
30
+
31
+ let { engine, screen }: { engine: Engine; screen: Screen } = $props();
32
+
33
+ // The host makes a new editor for each capture, so the first value is the only one.
34
+ // svelte-ignore state_referenced_locally
35
+ const { capture } = screen;
36
+ const session = new Session(capture);
37
+ // svelte-ignore state_referenced_locally
38
+ if (engine.pointed) session.pick(engine.pointed);
39
+ const maxZoom = 4;
40
+
41
+ /** `Session` is plain TypeScript, so every change to it goes through `act`, and everything drawn reads `view`. */
42
+ let version = $state(0);
43
+ const act = (change: () => void) => {
44
+ change();
45
+ version += 1;
46
+ };
47
+ const view = $derived.by(() => {
48
+ void version;
49
+ const path = session.path;
50
+ const level = Math.min(session.level, path.length - 1);
51
+ const target = session.target;
52
+ const referencePath = session.referencePath;
53
+ const referenceLevel = Math.min(session.referenceLevel, referencePath.length - 1);
54
+ return {
55
+ path,
56
+ level,
57
+ target,
58
+ parent: path[level + 1],
59
+ child: level > 0 ? path[level - 1] : undefined,
60
+ source: nearestSource(capture, target.id),
61
+ data: target.data ?? nearestComponent(capture, target.id)?.data,
62
+ similar: session.similar,
63
+ items: session.items.map(item => ({
64
+ ...item,
65
+ number: session.annotations.number(item.target),
66
+ color: paletteColor(session.colorIndex(item.target)),
67
+ })),
68
+ references: session.visibleReferences.map(reference => ({
69
+ ...reference,
70
+ color: paletteColor(session.colorIndex(reference.target)),
71
+ })),
72
+ editing: session.editing,
73
+ text: session.text,
74
+ canSubmit: session.canSubmit,
75
+ isReferencing: session.isReferencing,
76
+ referenceTarget: session.referenceTarget,
77
+ referenceParent: referencePath[referenceLevel + 1],
78
+ referenceLevel,
79
+ toast: session.toast,
80
+ };
81
+ });
82
+
83
+ let dialog = $state<HTMLDialogElement>();
84
+ let pane = $state<HTMLElement>();
85
+ let field = $state<HTMLTextAreaElement>();
86
+ let paneSize = $state({ width: 0, height: 0 });
87
+ let zoom = $state(1);
88
+ let hover = $state<number>();
89
+ let showsInfo = $state(false);
90
+ let showsList = $state(false);
91
+ let showsShare = $state(false);
92
+ let showsProcrastimate = $state(false);
93
+ let posting = $state<Webhook>();
94
+ let confirmsClose = $state(false);
95
+ let pending = $state<{ format: ExportFormat; ready: Export }>();
96
+ let busy = $state(false);
97
+
98
+ /** Fits the part that was on screen, and never goes below half the width, where targets get too small to tap. */
99
+ const fit = $derived.by(() => {
100
+ if (!paneSize.width) return 1;
101
+ const widthFit = (paneSize.width - 24) / capture.size.width;
102
+ return Math.min(
103
+ 1,
104
+ Math.max(Math.min(widthFit, (paneSize.height - 16) / capture.visible.height), widthFit / 2, 0.05),
105
+ );
106
+ });
107
+ const scale = $derived(fit * zoom);
108
+
109
+ const box = (frame: Frame) =>
110
+ `left:${frame.x * scale}px;top:${frame.y * scale}px;width:${Math.max(frame.width * scale, 4)}px;height:${Math.max(frame.height * scale, 4)}px`;
111
+
112
+ $effect(() => {
113
+ dialog?.showModal();
114
+ // On a touch screen, focus would raise the keyboard over the screenshot before anything is picked.
115
+ if (matchMedia('(pointer: fine)').matches) field?.focus();
116
+ else dialog?.focus();
117
+ });
118
+
119
+ /**
120
+ * The screenshot's scale comes from the pane's first size and changes only with the window, so the picture does not
121
+ * jump as the panel grows with a selection or a longer draft.
122
+ */
123
+ $effect(() => {
124
+ if (!pane) return;
125
+ const node = pane;
126
+ const measure = () => {
127
+ const style = getComputedStyle(node);
128
+ paneSize = {
129
+ width: node.clientWidth - Number.parseFloat(style.paddingLeft) - Number.parseFloat(style.paddingRight),
130
+ height: node.clientHeight - Number.parseFloat(style.paddingTop) - Number.parseFloat(style.paddingBottom),
131
+ };
132
+ };
133
+ measure();
134
+ queueMicrotask(() => node.scrollTo({ top: capture.visible.y * fit }));
135
+ addEventListener('resize', measure);
136
+ return () => removeEventListener('resize', measure);
137
+ });
138
+
139
+ $effect(() => {
140
+ const toast = view.toast;
141
+ if (!toast) return;
142
+ const timer = setTimeout(() => act(() => (session.toast = undefined)), toast.link ? 5000 : 3000);
143
+ return () => clearTimeout(timer);
144
+ });
145
+
146
+ const pointAt = (event: MouseEvent) => {
147
+ const rect = (event.currentTarget as HTMLElement).getBoundingClientRect();
148
+ return { x: (event.clientX - rect.left) / scale, y: (event.clientY - rect.top) / scale };
149
+ };
150
+
151
+ function zoomTo(next: number, center: { x: number; y: number }) {
152
+ if (!pane) return;
153
+ const clamped = Math.min(maxZoom, Math.max(1, next));
154
+ const rect = pane.getBoundingClientRect();
155
+ const x = (pane.scrollLeft + center.x - rect.left) / zoom;
156
+ const y = (pane.scrollTop + center.y - rect.top) / zoom;
157
+ zoom = clamped;
158
+ queueMicrotask(() =>
159
+ pane?.scrollTo({ left: x * clamped - (center.x - rect.left), top: y * clamped - (center.y - rect.top) }),
160
+ );
161
+ }
162
+
163
+ function wheel(event: WheelEvent) {
164
+ if (!event.ctrlKey && !event.metaKey) return;
165
+ event.preventDefault();
166
+ zoomTo(zoom * Math.exp(-event.deltaY / 100), { x: event.clientX, y: event.clientY });
167
+ }
168
+
169
+ const touches = new Map<number, { x: number; y: number }>();
170
+ let pinch: { distance: number; zoom: number } | undefined;
171
+ const spread = () => {
172
+ const [a, b] = [...touches.values()];
173
+ return { distance: Math.hypot(a!.x - b!.x, a!.y - b!.y), center: { x: (a!.x + b!.x) / 2, y: (a!.y + b!.y) / 2 } };
174
+ };
175
+ function pointer(event: PointerEvent) {
176
+ if (event.pointerType !== 'touch') return;
177
+ if (event.type === 'pointerup' || event.type === 'pointercancel') {
178
+ touches.delete(event.pointerId);
179
+ pinch = undefined;
180
+ return;
181
+ }
182
+ touches.set(event.pointerId, { x: event.clientX, y: event.clientY });
183
+ if (touches.size !== 2) return;
184
+ const { distance, center } = spread();
185
+ pinch ??= { distance, zoom };
186
+ zoomTo(pinch.zoom * (distance / pinch.distance), center);
187
+ }
188
+
189
+ function submit() {
190
+ act(() => session.submit());
191
+ }
192
+
193
+ function keydown(event: KeyboardEvent) {
194
+ if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
195
+ event.preventDefault();
196
+ if (view.isReferencing && view.referenceTarget) act(() => session.insertReference());
197
+ else if (view.canSubmit) submit();
198
+ }
199
+ }
200
+
201
+ function requestClose() {
202
+ if (showsInfo || showsList || showsShare || showsProcrastimate || posting || pending) {
203
+ showsInfo = showsList = showsShare = showsProcrastimate = false;
204
+ posting = pending = undefined;
205
+ } else if (session.isTyping || session.unshared.length) {
206
+ confirmsClose = true;
207
+ } else {
208
+ engine.close();
209
+ }
210
+ }
211
+
212
+ async function choose(format: ExportFormat) {
213
+ showsShare = false;
214
+ busy = true;
215
+ try {
216
+ const ready = await buildExport(screen, session.annotations, format);
217
+ engine.lastExport = [{ name: ready.file.name, blob: ready.file }];
218
+ pending = { format, ready };
219
+ } finally {
220
+ busy = false;
221
+ }
222
+ }
223
+
224
+ async function finish(action: 'copy' | 'save' | 'share') {
225
+ if (!pending) return;
226
+ const { ready } = pending;
227
+ const items = [...session.items];
228
+ try {
229
+ if (action === 'copy') await copyExport(ready);
230
+ else if (action === 'save') saveExport(ready);
231
+ else if (!(await shareExport(ready))) return;
232
+ } catch (error) {
233
+ act(() => (session.toast = { text: `Could not ${action}: ${(error as Error).message}` }));
234
+ return;
235
+ }
236
+ pending = undefined;
237
+ act(() => {
238
+ session.markShared(items);
239
+ session.toast = {
240
+ text: action === 'copy' ? 'Copied' : action === 'save' ? `Saved ${ready.file.name}` : 'Shared',
241
+ };
242
+ });
243
+ }
244
+
245
+ const count = (items: number) => (items === 1 ? '1 item' : `${items} items`);
246
+ </script>
247
+
248
+ <dialog
249
+ bind:this={dialog}
250
+ class="editor"
251
+ aria-label="Feedback"
252
+ onpointerdown={event => {
253
+ if (showsInfo && !(event.target as Element).closest('.title')) showsInfo = false;
254
+ }}
255
+ oncancel={event => {
256
+ event.preventDefault();
257
+ requestClose();
258
+ }}
259
+ >
260
+ <header>
261
+ <button type="button" class="round" aria-label="Close" onclick={requestClose}>
262
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18" /></svg>
263
+ </button>
264
+ <h1>Feedback</h1>
265
+ <button
266
+ type="button"
267
+ class="round"
268
+ aria-label="Feedback list, {count(view.items.length)}"
269
+ onclick={() => (showsList = true)}
270
+ >
271
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6h11M9 12h11M9 18h11M4 6h.01M4 12h.01M4 18h.01" /></svg>
272
+ {#if view.items.length}<span class="count" aria-hidden="true">{view.items.length}</span>{/if}
273
+ </button>
274
+ <div class="menu">
275
+ <button
276
+ type="button"
277
+ class="round"
278
+ aria-label="Share"
279
+ aria-haspopup="menu"
280
+ aria-expanded={showsShare}
281
+ disabled={!view.items.length || busy}
282
+ onclick={() => (showsShare = !showsShare)}
283
+ >
284
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 15V4M8 8l4-4 4 4M5 12v7h14v-7" /></svg>
285
+ </button>
286
+ {#if showsShare}
287
+ <div class="popup" role="menu">
288
+ {#each Object.entries(exportTitles) as [format, name] (format)}
289
+ <button type="button" role="menuitem" onclick={() => void choose(format as ExportFormat)}>{name}</button>
290
+ {/each}
291
+ {#if engine.options.procrastimate}
292
+ <button
293
+ type="button"
294
+ role="menuitem"
295
+ onclick={() => {
296
+ showsShare = false;
297
+ showsProcrastimate = true;
298
+ }}>ProcrastiMate</button
299
+ >
300
+ {/if}
301
+ {#each engine.options.webhooks ?? [] as webhook, index (index)}
302
+ <button
303
+ type="button"
304
+ role="menuitem"
305
+ class="webhook"
306
+ onclick={() => {
307
+ showsShare = false;
308
+ posting = webhook;
309
+ }}
310
+ >
311
+ {#if webhook.image}<img src={webhook.image} alt="" />{/if}
312
+ {webhook.name}
313
+ </button>
314
+ {/each}
315
+ </div>
316
+ {/if}
317
+ </div>
318
+ </header>
319
+
320
+ <div class="body">
321
+ <div
322
+ class="pane"
323
+ role="group"
324
+ aria-label="Screenshot"
325
+ bind:this={pane}
326
+ onwheel={wheel}
327
+ onpointerdown={pointer}
328
+ onpointermove={pointer}
329
+ onpointerup={pointer}
330
+ onpointercancel={pointer}
331
+ >
332
+ <!-- A screenshot has no keyboard equivalent for pointing at a pixel. The chain buttons reach every node from the keyboard. -->
333
+ <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_noninteractive_element_interactions -->
334
+ <div
335
+ class="canvas"
336
+ role="img"
337
+ aria-label="Screenshot. Click a component to give it feedback."
338
+ style="width:{capture.size.width * scale}px;height:{capture.size.height * scale}px"
339
+ onclick={event => act(() => session.pick(pointAt(event)))}
340
+ onmousemove={event => (hover = hitTest(capture, pointAt(event)))}
341
+ onmouseleave={() => (hover = undefined)}
342
+ {@attach node => {
343
+ node.prepend(screen.image);
344
+ }}
345
+ >
346
+ {#each view.similar as id (id)}
347
+ <span class="box similar" style={box(capture.nodes[id]!.frame)}></span>
348
+ {/each}
349
+ {#each view.items as item (item.id)}
350
+ <span class="box item" style="{box(capture.nodes[item.target]!.frame)};--color:{item.color}">
351
+ <span class="number">{item.number}</span>
352
+ </span>
353
+ {/each}
354
+ {#each view.references as reference (reference.number)}
355
+ <span class="box item" style="{box(capture.nodes[reference.target]!.frame)};--color:{reference.color}">
356
+ <span class="tag">{tag(reference)}</span>
357
+ </span>
358
+ {/each}
359
+ {#if hover !== undefined && hover !== view.target.id && capture.nodes[hover]!.kind !== 'screen'}
360
+ <span class="box hover" style={box(capture.nodes[hover]!.frame)}></span>
361
+ {/if}
362
+ {#if view.target.kind !== 'screen'}
363
+ <span class="box target" style={box(view.target.frame)}></span>
364
+ {/if}
365
+ {#if view.referenceTarget}
366
+ <span class="box reference" style={box(view.referenceTarget.frame)}></span>
367
+ {/if}
368
+ </div>
369
+ </div>
370
+
371
+ <section class="panel" aria-label="Selection">
372
+ {#if view.path.length > 1}
373
+ <div class="chain">
374
+ <span class="side">
375
+ {#if view.parent}
376
+ <button
377
+ type="button"
378
+ class="neighbor"
379
+ aria-label="Select parent, {title(view.parent)}"
380
+ onclick={() => act(() => session.step(view.level + 1))}
381
+ >
382
+ ‹ {view.parent.name}
383
+ </button>
384
+ {/if}
385
+ </span>
386
+ <span class="title">
387
+ <button
388
+ type="button"
389
+ class="selected"
390
+ aria-expanded={showsInfo}
391
+ aria-controls="target-info"
392
+ onclick={() => (showsInfo = !showsInfo)}>{title(view.target)}</button
393
+ >
394
+ {#if showsInfo}
395
+ <div class="info" id="target-info" role="tooltip">
396
+ {#if view.source || view.similar.length}
397
+ <div class="meta">
398
+ <span class="source">{view.source ?? ''}</span>
399
+ {#if view.similar.length}<span class="similar-count">{view.similar.length} similar</span>{/if}
400
+ </div>
401
+ {/if}
402
+ {#if view.data}<pre class="data">{view.data}</pre>{/if}
403
+ {#if !view.source && !view.similar.length && !view.data}<span class="empty">No source or data</span
404
+ >{/if}
405
+ </div>
406
+ {/if}
407
+ </span>
408
+ <span class="side end">
409
+ {#if view.child}
410
+ <button
411
+ type="button"
412
+ class="neighbor"
413
+ aria-label="Select child, {title(view.child)}"
414
+ onclick={() => act(() => session.step(view.level - 1))}
415
+ >
416
+ {view.child.name} ›
417
+ </button>
418
+ {/if}
419
+ </span>
420
+ </div>
421
+ {:else}
422
+ <p class="hint">Click the screenshot to pick a component.</p>
423
+ {/if}
424
+ {#if view.isReferencing}
425
+ <div class="picker">
426
+ {#if view.referenceTarget}
427
+ <button
428
+ type="button"
429
+ class="round small"
430
+ aria-label="Select parent"
431
+ disabled={!view.referenceParent}
432
+ onclick={() => act(() => session.stepReference(view.referenceLevel + 1))}
433
+ >
434
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 15l6-6 6 6" /></svg>
435
+ </button>
436
+ <button
437
+ type="button"
438
+ class="round small"
439
+ aria-label="Select child"
440
+ disabled={view.referenceLevel === 0}
441
+ onclick={() => act(() => session.stepReference(view.referenceLevel - 1))}
442
+ >
443
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6" /></svg>
444
+ </button>
445
+ <strong class="picked">{title(view.referenceTarget)}</strong>
446
+ <button type="button" class="insert" onclick={() => act(() => session.insertReference())}>Insert</button>
447
+ {:else}
448
+ <span class="picked">@ Click an element to reference it</span>
449
+ {/if}
450
+ </div>
451
+ {/if}
452
+ <div class="compose">
453
+ {#if view.editing}
454
+ {@const item = view.items.find(candidate => candidate.id === view.editing!.id)!}
455
+ <span class="number static" style="--color:{item.color}" aria-label="Editing item {item.number}"
456
+ >{item.number}</span
457
+ >
458
+ {/if}
459
+ <textarea
460
+ bind:this={field}
461
+ rows="1"
462
+ aria-label="Feedback text"
463
+ placeholder="Feedback on {view.target.name}…"
464
+ value={view.text}
465
+ oninput={event => act(() => (session.text = event.currentTarget.value))}
466
+ onkeydown={keydown}></textarea>
467
+ <button
468
+ type="button"
469
+ class="send"
470
+ aria-label={view.editing ? 'Save feedback' : 'Add feedback'}
471
+ disabled={!view.canSubmit}
472
+ onclick={submit}
473
+ >
474
+ <svg viewBox="0 0 24 24" aria-hidden="true">
475
+ {#if view.editing}<path d="M6 12l4 4 8-8" />{:else}<path d="M12 18V7M7 11l5-5 5 5" />{/if}
476
+ </svg>
477
+ </button>
478
+ </div>
479
+ </section>
480
+ </div>
481
+
482
+ {#if view.toast}
483
+ <div class="toast" role="status">
484
+ <button
485
+ type="button"
486
+ onclick={() => {
487
+ if (view.toast?.link) open(view.toast.link, '_blank', 'noopener');
488
+ act(() => (session.toast = undefined));
489
+ }}
490
+ >
491
+ ✓ {view.toast.text}{view.toast.link ? ' ↗' : ''}
492
+ </button>
493
+ </div>
494
+ {/if}
495
+
496
+ {#if showsList}
497
+ <ItemsSheet
498
+ {session}
499
+ {version}
500
+ onclose={() => (showsList = false)}
501
+ onselect={id => {
502
+ act(() => session.select(id));
503
+ showsList = false;
504
+ }}
505
+ onremove={id => act(() => session.remove(id))}
506
+ />
507
+ {/if}
508
+
509
+ {#if showsProcrastimate && engine.options.procrastimate}
510
+ <ProcrastimateSheet
511
+ {screen}
512
+ {session}
513
+ config={engine.options.procrastimate}
514
+ onclose={() => (showsProcrastimate = false)}
515
+ onposted={(items, toast) => {
516
+ showsProcrastimate = false;
517
+ act(() => {
518
+ session.markShared(items);
519
+ session.toast = toast;
520
+ });
521
+ }}
522
+ />
523
+ {/if}
524
+
525
+ {#if posting}
526
+ <WebhookSheet
527
+ {screen}
528
+ {session}
529
+ webhook={posting}
530
+ onclose={() => (posting = undefined)}
531
+ onposted={(items, toast) => {
532
+ posting = undefined;
533
+ act(() => {
534
+ session.markShared(items);
535
+ session.toast = toast;
536
+ });
537
+ }}
538
+ />
539
+ {/if}
540
+
541
+ {#if pending}
542
+ <div
543
+ class="scrim"
544
+ role="presentation"
545
+ onclick={event => event.target === event.currentTarget && (pending = undefined)}
546
+ >
547
+ <div class="sheet actions" role="dialog" tabindex="-1" aria-label="Share {exportTitles[pending.format]}">
548
+ <h2>{pending.ready.file.name}</h2>
549
+ <button type="button" onclick={() => void finish('copy')}>Copy Feedback</button>
550
+ <button type="button" onclick={() => void finish('save')}>Save File</button>
551
+ {#if canShare(pending.ready)}
552
+ <button type="button" onclick={() => void finish('share')}>Share…</button>
553
+ {/if}
554
+ <button type="button" class="quiet" onclick={() => (pending = undefined)}>Cancel</button>
555
+ </div>
556
+ </div>
557
+ {/if}
558
+
559
+ {#if confirmsClose}
560
+ <div class="scrim" role="presentation">
561
+ <div class="sheet actions" role="alertdialog" tabindex="-1" aria-label="Discard feedback?">
562
+ <h2>Discard feedback?</h2>
563
+ <p>
564
+ {session.unshared.length
565
+ ? `Closing discards ${count(session.unshared.length)} you haven't shared.`
566
+ : "Closing discards the feedback you're typing."}
567
+ </p>
568
+ <button type="button" class="danger" onclick={() => engine.close()}>Discard</button>
569
+ <button type="button" class="quiet" onclick={() => (confirmsClose = false)}>Keep Editing</button>
570
+ </div>
571
+ </div>
572
+ {/if}
573
+ </dialog>
574
+
575
+ <style>
576
+ .editor {
577
+ position: fixed;
578
+ inset: 0;
579
+ display: flex;
580
+ flex-direction: column;
581
+ width: 100vw;
582
+ height: 100dvh;
583
+ max-width: none;
584
+ max-height: none;
585
+ margin: 0;
586
+ border: 0;
587
+ padding: 0;
588
+ background: #141414;
589
+ color: white;
590
+ color-scheme: dark;
591
+ font:
592
+ 15px/1.35 system-ui,
593
+ -apple-system,
594
+ 'Segoe UI',
595
+ sans-serif;
596
+ overflow: hidden;
597
+ }
598
+
599
+ .editor::backdrop {
600
+ background: #141414;
601
+ }
602
+
603
+ button,
604
+ textarea {
605
+ font: inherit;
606
+ color: inherit;
607
+ }
608
+
609
+ button {
610
+ cursor: pointer;
611
+ }
612
+
613
+ button:disabled {
614
+ cursor: default;
615
+ opacity: 0.4;
616
+ }
617
+
618
+ header {
619
+ display: flex;
620
+ align-items: center;
621
+ gap: 12px;
622
+ padding: 8px 16px;
623
+ }
624
+
625
+ h1 {
626
+ flex: 1;
627
+ margin: 0;
628
+ font-size: 17px;
629
+ font-weight: 600;
630
+ text-align: center;
631
+ }
632
+
633
+ .round {
634
+ position: relative;
635
+ display: grid;
636
+ place-items: center;
637
+ width: 36px;
638
+ height: 36px;
639
+ border: 0;
640
+ border-radius: 50%;
641
+ background: #2c2c2e;
642
+ }
643
+
644
+ .round.small {
645
+ width: 30px;
646
+ height: 30px;
647
+ }
648
+
649
+ svg {
650
+ width: 18px;
651
+ height: 18px;
652
+ fill: none;
653
+ stroke: currentColor;
654
+ stroke-width: 2.2;
655
+ stroke-linecap: round;
656
+ stroke-linejoin: round;
657
+ }
658
+
659
+ .count {
660
+ position: absolute;
661
+ top: -4px;
662
+ right: -4px;
663
+ min-width: 18px;
664
+ border-radius: 9px;
665
+ padding: 0 4px;
666
+ background: #ff3b30;
667
+ font-size: 11px;
668
+ font-weight: 700;
669
+ line-height: 18px;
670
+ }
671
+
672
+ .menu {
673
+ position: relative;
674
+ }
675
+
676
+ .popup {
677
+ position: absolute;
678
+ top: 42px;
679
+ right: 0;
680
+ z-index: 3;
681
+ display: grid;
682
+ min-width: 220px;
683
+ border-radius: 12px;
684
+ background: #2c2c2e;
685
+ box-shadow: 0 12px 40px rgb(0 0 0 / 0.5);
686
+ overflow: hidden;
687
+ }
688
+
689
+ .popup button {
690
+ border: 0;
691
+ border-bottom: 1px solid rgb(255 255 255 / 0.08);
692
+ padding: 12px 16px;
693
+ background: none;
694
+ text-align: left;
695
+ }
696
+
697
+ .popup button:hover {
698
+ background: rgb(255 255 255 / 0.08);
699
+ }
700
+
701
+ .popup .webhook {
702
+ display: flex;
703
+ align-items: center;
704
+ gap: 10px;
705
+ }
706
+
707
+ .popup img {
708
+ width: 18px;
709
+ height: 18px;
710
+ object-fit: contain;
711
+ }
712
+
713
+ .body {
714
+ display: flex;
715
+ flex: 1;
716
+ flex-direction: column;
717
+ min-height: 0;
718
+ }
719
+
720
+ .pane {
721
+ flex: 1;
722
+ min-height: 0;
723
+ padding: 8px 12px;
724
+ overflow: auto;
725
+ overscroll-behavior: contain;
726
+ touch-action: pan-x pan-y;
727
+ }
728
+
729
+ .canvas {
730
+ position: relative;
731
+ margin: 0 auto;
732
+ cursor: crosshair;
733
+ }
734
+
735
+ /* The picture is clipped, not the boxes over it, so a number badge on a box at the edge stays whole. */
736
+ .canvas :global(canvas) {
737
+ display: block;
738
+ width: 100%;
739
+ height: 100%;
740
+ border-radius: 10px;
741
+ }
742
+
743
+ .box {
744
+ position: absolute;
745
+ box-sizing: border-box;
746
+ border-radius: 3px;
747
+ pointer-events: none;
748
+ }
749
+
750
+ .box.similar {
751
+ border: 1px dashed rgb(255 214 10 / 0.5);
752
+ background: rgb(255 214 10 / 0.08);
753
+ }
754
+
755
+ .box.item {
756
+ border: 1.5px dashed var(--color);
757
+ }
758
+
759
+ .box.target {
760
+ border: 2px dashed #ffd60a;
761
+ }
762
+
763
+ .box.hover {
764
+ border: 1px solid rgb(255 255 255 / 0.7);
765
+ background: rgb(255 255 255 / 0.06);
766
+ }
767
+
768
+ .box.reference {
769
+ border: 2px dashed #32ade6;
770
+ background: rgb(50 173 230 / 0.12);
771
+ }
772
+
773
+ .number,
774
+ .tag {
775
+ position: absolute;
776
+ top: -7px;
777
+ display: grid;
778
+ place-items: center;
779
+ min-width: 16px;
780
+ height: 16px;
781
+ padding: 0 3px;
782
+ box-sizing: border-box;
783
+ background: var(--color);
784
+ color: white;
785
+ font-size: 11px;
786
+ font-weight: 700;
787
+ line-height: 1;
788
+ }
789
+
790
+ .number {
791
+ left: -7px;
792
+ border-radius: 8px;
793
+ }
794
+
795
+ .tag {
796
+ right: -7px;
797
+ border-radius: 3px;
798
+ }
799
+
800
+ .number.static {
801
+ position: static;
802
+ width: 22px;
803
+ height: 22px;
804
+ border-radius: 11px;
805
+ margin-bottom: 8px;
806
+ font-size: 12px;
807
+ }
808
+
809
+ .panel {
810
+ display: grid;
811
+ gap: 10px;
812
+ padding: 16px;
813
+ padding-bottom: max(16px, env(safe-area-inset-bottom));
814
+ background: #1f1f1f;
815
+ }
816
+
817
+ .chain {
818
+ display: flex;
819
+ align-items: center;
820
+ gap: 8px;
821
+ }
822
+
823
+ .side {
824
+ display: flex;
825
+ flex: 1;
826
+ min-width: 0;
827
+ }
828
+
829
+ .side.end {
830
+ justify-content: flex-end;
831
+ }
832
+
833
+ .neighbor {
834
+ max-width: 100%;
835
+ border: 0;
836
+ border-radius: 999px;
837
+ padding: 6px 10px;
838
+ background: #333336;
839
+ color: #aeaeb2;
840
+ font-size: 14px;
841
+ overflow: hidden;
842
+ text-overflow: ellipsis;
843
+ white-space: nowrap;
844
+ }
845
+
846
+ .title {
847
+ position: relative;
848
+ display: flex;
849
+ min-width: 0;
850
+ }
851
+
852
+ .selected {
853
+ min-width: 0;
854
+ border: 0;
855
+ padding: 0;
856
+ background: none;
857
+ color: #ffd60a;
858
+ font-size: 16px;
859
+ font-weight: 700;
860
+ overflow: hidden;
861
+ text-overflow: ellipsis;
862
+ white-space: nowrap;
863
+ }
864
+
865
+ /* Above the title, so on a phone it covers the screenshot and not the field being typed in. */
866
+ .info {
867
+ position: absolute;
868
+ bottom: calc(100% + 10px);
869
+ left: 50%;
870
+ z-index: 3;
871
+ display: grid;
872
+ gap: 8px;
873
+ width: max-content;
874
+ max-width: min(420px, calc(100vw - 32px));
875
+ border-radius: 12px;
876
+ padding: 10px 12px;
877
+ box-sizing: border-box;
878
+ background: #2c2c2e;
879
+ box-shadow: 0 12px 40px rgb(0 0 0 / 0.5);
880
+ translate: -50% 0;
881
+ }
882
+
883
+ .empty {
884
+ color: #aeaeb2;
885
+ font-size: 13px;
886
+ }
887
+
888
+ .hint {
889
+ margin: 0;
890
+ color: #aeaeb2;
891
+ }
892
+
893
+ .meta {
894
+ display: flex;
895
+ justify-content: space-between;
896
+ gap: 16px;
897
+ color: #aeaeb2;
898
+ font:
899
+ 12px ui-monospace,
900
+ 'SF Mono',
901
+ Menlo,
902
+ monospace;
903
+ }
904
+
905
+ .source {
906
+ overflow-wrap: anywhere;
907
+ }
908
+
909
+ .similar-count {
910
+ flex: none;
911
+ color: rgb(255 214 10 / 0.7);
912
+ }
913
+
914
+ .data {
915
+ max-height: 40vh;
916
+ margin: 0;
917
+ color: #aeaeb2;
918
+ font:
919
+ 11px/1.3 ui-monospace,
920
+ 'SF Mono',
921
+ Menlo,
922
+ monospace;
923
+ overflow: auto;
924
+ white-space: pre-wrap;
925
+ }
926
+
927
+ .picker {
928
+ display: flex;
929
+ align-items: center;
930
+ gap: 8px;
931
+ min-height: 34px;
932
+ }
933
+
934
+ .picked {
935
+ flex: 1;
936
+ color: #32ade6;
937
+ overflow: hidden;
938
+ text-overflow: ellipsis;
939
+ white-space: nowrap;
940
+ }
941
+
942
+ .insert {
943
+ border: 0;
944
+ border-radius: 999px;
945
+ padding: 6px 14px;
946
+ background: #32ade6;
947
+ font-weight: 600;
948
+ }
949
+
950
+ .compose {
951
+ display: flex;
952
+ align-items: flex-end;
953
+ gap: 8px;
954
+ }
955
+
956
+ textarea {
957
+ flex: 1;
958
+ min-height: 38px;
959
+ max-height: 60dvh;
960
+ border: 0;
961
+ border-radius: 18px;
962
+ padding: 8px 12px;
963
+ box-sizing: border-box;
964
+ background: #2e2e30;
965
+ field-sizing: content;
966
+ resize: none;
967
+ }
968
+
969
+ textarea:focus-visible,
970
+ button:focus-visible {
971
+ outline: 2px solid #0a84ff;
972
+ outline-offset: 1px;
973
+ }
974
+
975
+ .send {
976
+ display: grid;
977
+ place-items: center;
978
+ width: 36px;
979
+ height: 36px;
980
+ border: 0;
981
+ border-radius: 50%;
982
+ background: #0a84ff;
983
+ }
984
+
985
+ .toast {
986
+ position: absolute;
987
+ top: 60px;
988
+ left: 50%;
989
+ z-index: 4;
990
+ translate: -50% 0;
991
+ }
992
+
993
+ .toast button {
994
+ border: 0;
995
+ border-radius: 999px;
996
+ padding: 10px 16px;
997
+ background: rgb(52 199 89 / 0.92);
998
+ font-weight: 600;
999
+ }
1000
+
1001
+ .scrim {
1002
+ position: absolute;
1003
+ inset: 0;
1004
+ z-index: 5;
1005
+ display: grid;
1006
+ place-items: end center;
1007
+ background: rgb(0 0 0 / 0.5);
1008
+ }
1009
+
1010
+ .sheet {
1011
+ width: min(100%, 420px);
1012
+ border-radius: 16px 16px 0 0;
1013
+ padding: 16px;
1014
+ padding-bottom: max(16px, env(safe-area-inset-bottom));
1015
+ box-sizing: border-box;
1016
+ background: #1f1f1f;
1017
+ }
1018
+
1019
+ .actions {
1020
+ display: grid;
1021
+ gap: 8px;
1022
+ }
1023
+
1024
+ .actions h2 {
1025
+ margin: 0 0 4px;
1026
+ font-size: 16px;
1027
+ text-align: center;
1028
+ }
1029
+
1030
+ .actions p {
1031
+ margin: 0 0 4px;
1032
+ color: #aeaeb2;
1033
+ text-align: center;
1034
+ }
1035
+
1036
+ .actions button {
1037
+ border: 0;
1038
+ border-radius: 12px;
1039
+ padding: 12px;
1040
+ background: #2c2c2e;
1041
+ font-weight: 600;
1042
+ }
1043
+
1044
+ .actions .danger {
1045
+ color: #ff453a;
1046
+ }
1047
+
1048
+ .actions .quiet {
1049
+ background: none;
1050
+ color: #aeaeb2;
1051
+ }
1052
+
1053
+ @media (min-width: 900px) {
1054
+ .body {
1055
+ flex-direction: row;
1056
+ }
1057
+
1058
+ .panel {
1059
+ align-content: start;
1060
+ width: 380px;
1061
+ box-sizing: border-box;
1062
+ border-left: 1px solid rgb(255 255 255 / 0.08);
1063
+ }
1064
+
1065
+ .info {
1066
+ top: calc(100% + 10px);
1067
+ bottom: auto;
1068
+ }
1069
+
1070
+ .scrim {
1071
+ place-items: center;
1072
+ }
1073
+
1074
+ .sheet {
1075
+ border-radius: 16px;
1076
+ }
1077
+ }
1078
+ </style>