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,7 +1,10 @@
1
1
  import { r as gestureOf } from "../shared/shortcut.js";
2
+ import { a as tell, r as named } from "../shared/component.js";
3
+ import { a as nameOf, c as sameAs, i as div, l as targetOf, o as place$1, r as controlFor, s as reduced, t as ATTRIBUTE } from "../shared/dom.js";
4
+ import { t as drawerIn } from "../shared/drawer.js";
2
5
  import { n as liveWaveform, r as peaksOf, t as drawBars } from "../shared/waveform.js";
3
6
  // src/client/away.ts
4
- const KEY = "deictic:away";
7
+ const KEY$1 = "deictic:away";
5
8
  const STORE = "away";
6
9
  /** How long one nobody came back to is kept, in milliseconds: its tab was closed. */
7
10
  const STALE = 864e5;
@@ -31,7 +34,7 @@ function store(mode, work) {
31
34
  }
32
35
  const keyOf = () => {
33
36
  try {
34
- return sessionStorage.getItem(KEY) ?? void 0;
37
+ return sessionStorage.getItem(KEY$1) ?? void 0;
35
38
  } catch {
36
39
  return;
37
40
  }
@@ -40,7 +43,7 @@ const keyOf = () => {
40
43
  function keepAway(away) {
41
44
  try {
42
45
  const key = keyOf() ?? crypto.randomUUID();
43
- sessionStorage.setItem(KEY, key);
46
+ sessionStorage.setItem(KEY$1, key);
44
47
  store("readwrite", (s) => {
45
48
  const walk = s.openCursor();
46
49
  walk.addEventListener("success", () => {
@@ -71,7 +74,7 @@ function dropAway() {
71
74
  const key = keyOf();
72
75
  if (key === void 0) return;
73
76
  try {
74
- sessionStorage.removeItem(KEY);
77
+ sessionStorage.removeItem(KEY$1);
75
78
  } catch {}
76
79
  store("readwrite", (s) => s.delete(key)).catch(() => {});
77
80
  }
@@ -79,31 +82,32 @@ function dropAway() {
79
82
  const EASE = "cubic-bezier(0.2, 0.8, 0.2, 1)";
80
83
  const PLAY = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M7 4v16l13-8z\" fill=\"currentColor\"/></svg>";
81
84
  const PAUSE = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M6 4h4v16H6zM14 4h4v16h-4z\" fill=\"currentColor\"/></svg>";
82
- const reduced = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
83
85
  const clock = (s) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, "0")}`;
84
86
  /**
85
87
  * Opens it in `root`. `pinned` draws it where `root` is in the page instead, with no backdrop, motion or keys, and
86
88
  * actions that don't close it: for a page of deictic's own states (`lightboxIn`).
87
89
  */
88
90
  function openLightbox(root, items, { at = 0, from, pinned = false } = {}) {
89
- const box = div$1(pinned ? "lightbox pinned" : "lightbox");
91
+ const box = div(pinned ? "lightbox pinned" : "lightbox");
90
92
  if (!pinned) {
91
93
  box.dataset.deicticModal = "";
92
94
  box.setAttribute("role", "dialog");
93
95
  box.setAttribute("aria-modal", "true");
94
96
  }
95
- const backdrop = div$1("lb-backdrop");
96
- const stage = div$1("lb-stage");
97
- const head = div$1("lb-head");
98
- const title = div$1("lb-title");
99
- const count = div$1("lb-count");
100
- const actions = div$1("lb-actions");
97
+ const backdrop = div("lb-backdrop");
98
+ const stage = div("lb-stage");
99
+ const head = div("lb-head");
100
+ const title = div("lb-title");
101
+ const count = div("lb-count");
102
+ const actions = div("lb-actions");
101
103
  const close = button$1("×", "Close (Esc)", "lb-close");
102
104
  head.append(title, count, actions, close);
103
- const body = div$1("lb-body");
105
+ const body = div("lb-body");
104
106
  stage.append(head, body);
105
- const prev = button$1("‹", "Previous (←)", "lb-prev");
106
- const next = button$1("›", "Next (→)", "lb-next");
107
+ const prev = button$1("", "Previous (←)", "lb-prev");
108
+ prev.innerHTML = chevron("M15 6l-6 6 6 6");
109
+ const next = button$1("", "Next (→)", "lb-next");
110
+ next.innerHTML = chevron("M9 6l6 6-6 6");
107
111
  box.append(backdrop, stage, ...items.length > 1 ? [prev, next] : []);
108
112
  root.append(box);
109
113
  let index = Math.min(Math.max(0, at), items.length - 1);
@@ -250,13 +254,13 @@ function contentOf(item, autoplay) {
250
254
  }
251
255
  /** A sound: play and pause, its waveform with what's played lit, and the time. With `autoplay`, it starts playing. */
252
256
  function player(url, autoplay) {
253
- const el = div$1("lb-audio");
257
+ const el = div("lb-audio");
254
258
  const play = button$1("", "Play (Space)", "lb-play");
255
259
  const wave = Object.assign(document.createElement("canvas"), { className: "lb-wave" });
256
260
  wave.setAttribute("role", "slider");
257
261
  wave.setAttribute("aria-label", "Where in the clip");
258
262
  wave.tabIndex = 0;
259
- const time = div$1("lb-time");
263
+ const time = div("lb-time");
260
264
  el.append(play, wave, time);
261
265
  const audio = new Audio(url);
262
266
  const colors = {
@@ -323,11 +327,7 @@ function player(url, autoplay) {
323
327
  }
324
328
  };
325
329
  }
326
- function div$1(className) {
327
- const el = document.createElement("div");
328
- el.className = className;
329
- return el;
330
- }
330
+ const chevron = (d) => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`;
331
331
  function button$1(text, title, className) {
332
332
  const el = document.createElement("button");
333
333
  el.type = "button";
@@ -336,6 +336,237 @@ function button$1(text, title, className) {
336
336
  el.className = className;
337
337
  return el;
338
338
  }
339
+ const grown = (r) => new DOMRect(r.left - 8, r.top - 8, r.width + 16, r.height + 16);
340
+ /** How far around a spot its light reaches, in pixels: a circle that shows what's under the point. */
341
+ const SPOT = 16;
342
+ /** A spot in an element, as the box its light fills. */
343
+ function spotOf(element, at) {
344
+ const r = element.getBoundingClientRect();
345
+ return new DOMRect(r.left + at.x - SPOT, r.top + at.y - SPOT, 32, 32);
346
+ }
347
+ /** How long the pointer is out on the page, in milliseconds, before the page gets its light back. */
348
+ const LINGER$1 = 700;
349
+ /** How long the light takes from one element to the next, in milliseconds: as the styles have it. */
350
+ const GLIDE = 240;
351
+ /** How far from a corner the line to the popup starts and ends, in pixels. */
352
+ const INSET = 22;
353
+ const LIT = `<svg aria-hidden="true">
354
+ <rect class="halo"/><rect class="lock"/>
355
+ <path class="halo" pathLength="1"/><path class="tether" pathLength="1"/><path class="flow" pathLength="1"/>
356
+ <circle r="3"/><circle r="3"/></svg>`;
357
+ const clamp = (n, low, high) => Math.max(low, Math.min(n, high));
358
+ /** The light's corner for an element, as far out as the light is: a pill stays a pill, a square corner is eased a little. */
359
+ function radiusOf(el, r) {
360
+ const [first = "0px"] = getComputedStyle(el).borderTopLeftRadius.split(" ");
361
+ const n = Number.parseFloat(first);
362
+ const least = Math.min(r.width, r.height);
363
+ return Math.min(first.endsWith("%") ? n / 100 * least : n + 8, least / 2);
364
+ }
365
+ /**
366
+ * The line from the lit box to the popup: an S from side to side where the popup is beside it, else down or up to
367
+ * it, and none where they overlap. It ends on the popup level with the box's middle, as near as the popup reaches.
368
+ */
369
+ function tetherOf(e, p) {
370
+ for (const [near, far, low, high] of [[
371
+ "left",
372
+ "right",
373
+ "top",
374
+ "bottom"
375
+ ], [
376
+ "top",
377
+ "bottom",
378
+ "left",
379
+ "right"
380
+ ]]) {
381
+ const way = p[near] >= e[far] ? 1 : p[far] <= e[near] ? -1 : 0;
382
+ if (way === 0) continue;
383
+ const a1 = way > 0 ? e[far] : e[near];
384
+ const a2 = way > 0 ? p[near] : p[far];
385
+ const inset = (r) => Math.min(INSET, (r[high] - r[low]) / 2);
386
+ const b2 = clamp((e[low] + e[high]) / 2, p[low] + inset(p), p[high] - inset(p));
387
+ const b1 = clamp(b2, e[low] + inset(e), e[high] - inset(e));
388
+ const bend = (a2 - a1) / 2;
389
+ const at = (a, b) => near === "left" ? [a, b] : [b, a];
390
+ const points = [
391
+ at(a1, b1),
392
+ at(a1 + bend, b1),
393
+ at(a2 - bend, b2),
394
+ at(a2, b2)
395
+ ].map(([x, y]) => `${x} ${y}`);
396
+ return {
397
+ d: `M${points[0]}C${points.slice(1).join(" ")}`,
398
+ ends: [at(a1, b1), at(a2, b2)]
399
+ };
400
+ }
401
+ }
402
+ function spotlight(root) {
403
+ const veil = div("veil");
404
+ const aim = div("aim");
405
+ const ring = div("ring");
406
+ const caption = div("caption");
407
+ ring.append(caption);
408
+ const guides = {
409
+ left: div("guide gx"),
410
+ right: div("guide gx"),
411
+ top: div("guide gy"),
412
+ bottom: div("guide gy")
413
+ };
414
+ const inner = div("inner");
415
+ aim.append(...Object.values(guides), ring);
416
+ root.append(veil, aim, inner);
417
+ let pointing = false;
418
+ let held = false;
419
+ let said = "";
420
+ const dark = () => queueMicrotask(() => {
421
+ if (!pointing && !held) veil.classList.remove("shown");
422
+ });
423
+ const light = (r, radius, glide) => {
424
+ veil.classList.toggle("glide", glide && veil.classList.contains("shown"));
425
+ place$1(veil, r);
426
+ veil.style.borderRadius = `${radius}px`;
427
+ veil.classList.add("shown");
428
+ };
429
+ const part = (className, text) => Object.assign(document.createElement("span"), {
430
+ className,
431
+ textContent: text
432
+ });
433
+ return {
434
+ point({ el, pointed, target, names, count }, glide = true) {
435
+ pointing = true;
436
+ const box = el.getBoundingClientRect();
437
+ const r = grown(box);
438
+ const radius = radiusOf(el, r);
439
+ aim.classList.toggle("glide", glide && aim.classList.contains("shown"));
440
+ place$1(ring, r);
441
+ ring.style.borderRadius = `${radius}px`;
442
+ guides.left.style.translate = `${r.left}px`;
443
+ guides.right.style.translate = `${r.right - 1}px`;
444
+ guides.top.style.translate = `0 ${r.top}px`;
445
+ guides.bottom.style.translate = `0 ${r.bottom - 1}px`;
446
+ if (!held) light(r, radius, glide);
447
+ inner.classList.toggle("shown", pointed !== void 0);
448
+ if (pointed !== void 0) place$1(inner, pointed.getBoundingClientRect());
449
+ const dim = [
450
+ `${Math.round(box.width)}×${Math.round(box.height)}`,
451
+ ...count > 1 ? [`×${count}`] : [],
452
+ ...pointed === void 0 ? [] : [`› ${nameOf(pointed)}`]
453
+ ];
454
+ const { component, sole } = named(el);
455
+ const texts = {
456
+ tag: `<${component ?? target.tag}>`,
457
+ inside: component === void 0 || sole ? "" : `<${target.tag}>`,
458
+ from: `${target.loc.file}:${target.loc.line}`,
459
+ opens: names.join(" / ")
460
+ };
461
+ const saying = JSON.stringify([texts, dim]);
462
+ if (saying !== said) {
463
+ said = saying;
464
+ caption.replaceChildren(part("tag", texts.tag), ...texts.inside === "" ? [] : [part("dim", texts.inside)], part("", texts.from), ...dim.map((text) => part("dim", text)), ...names.length === 0 ? [] : [part("opens", texts.opens)]);
465
+ }
466
+ caption.classList.toggle("below", r.top < 40);
467
+ caption.style.translate = `${Math.min(0, document.documentElement.clientWidth - 8 - r.left - caption.offsetWidth)}px`;
468
+ aim.classList.add("shown");
469
+ },
470
+ hide() {
471
+ pointing = false;
472
+ aim.classList.remove("shown");
473
+ inner.classList.remove("shown");
474
+ dark();
475
+ },
476
+ hold(element, panel, at) {
477
+ held = true;
478
+ const lit = div("lit");
479
+ lit.innerHTML = LIT;
480
+ root.append(lit);
481
+ const rects = [...lit.querySelectorAll("rect")];
482
+ const paths = [...lit.querySelectorAll("path")];
483
+ const dots = [...lit.querySelectorAll("circle")];
484
+ const pulse = reduced() ? void 0 : div("pulse");
485
+ if (pulse !== void 0) {
486
+ root.append(pulse);
487
+ pulse.addEventListener("animationend", () => pulse.remove());
488
+ }
489
+ let frame = 0;
490
+ let was;
491
+ let first = true;
492
+ const settled = setTimeout(() => veil.classList.remove("glide"), GLIDE);
493
+ const follow = () => {
494
+ frame = requestAnimationFrame(follow);
495
+ const on = element.isConnected;
496
+ const e = at === void 0 ? grown(element.getBoundingClientRect()) : spotOf(element, at);
497
+ const p = panel.getBoundingClientRect();
498
+ const now = on ? [
499
+ e.left,
500
+ e.top,
501
+ e.width,
502
+ e.height,
503
+ p.left,
504
+ p.top,
505
+ p.width,
506
+ p.height
507
+ ].join() : "";
508
+ if (now === was) return;
509
+ was = now;
510
+ lit.classList.toggle("shown", on);
511
+ if (!on) return veil.classList.remove("shown");
512
+ const radius = at === void 0 ? radiusOf(element, e) : SPOT;
513
+ if (first) light(e, radius, true);
514
+ else place$1(veil, e);
515
+ veil.style.borderRadius = `${radius}px`;
516
+ if (first && pulse !== void 0) {
517
+ place$1(pulse, e);
518
+ pulse.style.borderRadius = `${radius}px`;
519
+ }
520
+ first = false;
521
+ for (const rect of rects) for (const [name, value] of Object.entries({
522
+ x: e.left,
523
+ y: e.top,
524
+ width: e.width,
525
+ height: e.height,
526
+ rx: radius
527
+ })) rect.setAttribute(name, String(value));
528
+ const width = document.documentElement.clientWidth;
529
+ const height = document.documentElement.clientHeight;
530
+ const [left, right] = [clamp(e.left, 0, width), clamp(e.right, 0, width)];
531
+ const [top, bottom] = [clamp(e.top, 0, height), clamp(e.bottom, 0, height)];
532
+ const tie = tetherOf(new DOMRect(left, top, right - left, bottom - top), p);
533
+ lit.classList.toggle("tied", tie !== void 0);
534
+ if (tie === void 0) return;
535
+ for (const path of paths) path.setAttribute("d", tie.d);
536
+ for (const [i, dot] of dots.entries()) {
537
+ dot.setAttribute("cx", String(tie.ends[i][0]));
538
+ dot.setAttribute("cy", String(tie.ends[i][1]));
539
+ }
540
+ };
541
+ follow();
542
+ let lift;
543
+ const moved = (e) => {
544
+ if (!e.composedPath().includes(root.host)) {
545
+ lift ??= setTimeout(() => veil.classList.add("lifted"), LINGER$1);
546
+ return;
547
+ }
548
+ clearTimeout(lift);
549
+ lift = void 0;
550
+ veil.classList.remove("lifted");
551
+ };
552
+ window.addEventListener("pointermove", moved, {
553
+ capture: true,
554
+ passive: true
555
+ });
556
+ return () => {
557
+ held = false;
558
+ cancelAnimationFrame(frame);
559
+ clearTimeout(settled);
560
+ clearTimeout(lift);
561
+ window.removeEventListener("pointermove", moved, true);
562
+ lit.remove();
563
+ pulse?.remove();
564
+ veil.classList.remove("lifted");
565
+ dark();
566
+ };
567
+ }
568
+ };
569
+ }
339
570
  // src/client/style.ts
340
571
  /**
341
572
  * The overlay's styles, in its shadow root. Panels style their bodies with the same custom
@@ -356,79 +587,77 @@ const STYLE = `
356
587
  }
357
588
  /* The host takes no room in the page: everything in it is fixed, so nothing of deictic's moves or scrolls it. */
358
589
  :host(deictic-overlay) { display: contents; }
359
- .box {
590
+ /* What's under the pointer inside the lit element, where that differs. */
591
+ .inner {
360
592
  position: fixed;
361
593
  display: none;
362
594
  z-index: 2147483646;
363
595
  pointer-events: none;
364
596
  box-sizing: border-box;
365
- outline: 2px solid var(--deictic-accent);
366
- background: rgb(18 179 88 / 0.1);
597
+ outline: 1px dashed var(--deictic-accent);
367
598
  }
368
- .box.shown { display: block; }
369
- .box.inner { outline: 1px dashed var(--deictic-accent); background: none; }
370
- /* 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. */
371
- .box.on { outline: 1px dashed var(--deictic-accent); border-radius: 4px; background: none; }
372
- .label {
373
- position: absolute;
374
- left: -2px;
375
- bottom: 100%;
376
- padding: 1px 6px;
377
- font: 12px/1.5 ui-monospace, monospace;
378
- white-space: nowrap;
379
- color: var(--deictic-on-accent);
380
- background: var(--deictic-accent);
381
- }
382
- .label.below { top: 100%; bottom: auto; }
599
+ .inner.shown { display: block; }
600
+ /* Glass, over a page that's dimmed around what it's about. */
383
601
  .panel {
602
+ --deictic-line: rgb(255 255 255 / 0.14);
384
603
  position: fixed;
385
604
  z-index: 2147483647;
386
- width: min(360px, calc(100vw - 16px));
605
+ width: min(440px, calc(100vw - 16px));
387
606
  max-height: 60vh;
388
607
  display: flex;
389
608
  flex-direction: column;
390
609
  box-sizing: border-box;
391
- border: 1px solid var(--deictic-line);
392
- border-radius: 8px;
393
- box-shadow: 0 12px 32px rgb(0 0 0 / 0.35);
610
+ border: 1px solid rgb(255 255 255 / 0.1);
611
+ border-radius: 14px;
612
+ box-shadow: 0 0 0 1px rgb(0 0 0 / 0.4), 0 24px 64px -12px rgb(0 0 0 / 0.55), 0 0 56px -12px rgb(18 179 88 / 0.35),
613
+ inset 0 1px 0 rgb(255 255 255 / 0.08);
394
614
  font: 13px/1.4 system-ui, sans-serif;
395
615
  color: var(--deictic-fg);
396
- background: var(--deictic-bg);
397
- }
398
- .panel.pinned { position: relative; z-index: auto; max-height: none; }
399
- @media (prefers-reduced-motion: no-preference) {
400
- .panel:not(.pinned) { animation: deictic-in 0.12s ease-out; }
616
+ background: linear-gradient(rgb(39 39 42 / 0.9), rgb(24 24 27 / 0.94));
617
+ backdrop-filter: blur(24px) saturate(1.8);
401
618
  }
619
+ .panel.pinned { position: relative; z-index: auto; width: min(440px, 100%); max-height: none; }
402
620
  @keyframes deictic-in {
403
621
  from { opacity: 0; translate: 0 4px; }
404
622
  }
405
623
  .head {
624
+ position: relative;
406
625
  display: flex;
407
- align-items: flex-end;
626
+ align-items: center;
408
627
  gap: 2px;
409
- padding: 4px 8px 0;
628
+ padding: 8px 8px 6px;
410
629
  }
411
630
  /* Over the page the head is what the popup is dragged by; no touch scrolling starts there. */
412
631
  .panel:not(.pinned) .head { cursor: grab; touch-action: none; user-select: none; }
413
632
  .panel.dragging .head, .panel.dragging .head button { cursor: grabbing; }
414
633
  .head .tab {
634
+ position: relative;
415
635
  border: 0;
416
- border-bottom: 2px solid transparent;
417
- border-radius: 0;
418
- padding: 4px 8px;
636
+ border-radius: 8px;
637
+ padding: 4px 10px;
419
638
  font-weight: 600;
420
639
  color: var(--deictic-muted);
421
640
  }
422
641
  .head .tab:hover { color: var(--deictic-fg); }
423
- .head .tab[aria-selected='true'] { color: var(--deictic-fg); border-bottom-color: var(--deictic-accent); }
424
- .head .close { margin: 0 0 3px auto; }
642
+ .head .tab[aria-selected='true'] { color: var(--deictic-fg); }
643
+ /* A pill behind the shown tab, slid to the next one shown. */
644
+ .head .thumb {
645
+ position: absolute;
646
+ left: 0;
647
+ top: 8px;
648
+ bottom: 6px;
649
+ border-radius: 8px;
650
+ background: rgb(255 255 255 / 0.1);
651
+ box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.06);
652
+ pointer-events: none;
653
+ }
654
+ .head .end { margin-left: auto; }
425
655
  .bar {
426
656
  display: flex;
427
657
  align-items: center;
428
658
  gap: 2px;
429
- padding: 4px 8px;
430
- border-top: 1px solid var(--deictic-line);
431
- border-bottom: 1px solid var(--deictic-line);
659
+ padding: 0 10px 8px 12px;
660
+ border-bottom: 1px solid rgb(255 255 255 / 0.08);
432
661
  }
433
662
  .bar .where {
434
663
  display: inline-flex;
@@ -441,10 +670,208 @@ const STYLE = `
441
670
  text-decoration: none;
442
671
  }
443
672
  .bar .where span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
673
+ .bar .where .tag { flex: none; color: var(--deictic-accent); }
444
674
  .bar .where svg { flex: none; }
445
675
  .bar .where:hover, .bar .where:focus-visible { color: var(--deictic-fg); }
446
676
  .bar .where:hover span { text-decoration: underline; }
447
677
  .bar .absent { flex: none; margin-right: 6px; font-size: 12px; color: var(--deictic-muted); }
678
+ /* The page dims around the element (lighting.ts), by a shadow far wider than any window. */
679
+ .veil {
680
+ position: fixed;
681
+ z-index: 2147483644;
682
+ box-sizing: border-box;
683
+ pointer-events: none;
684
+ box-shadow: 0 0 0 200vmax rgb(9 9 11 / 0.5);
685
+ opacity: 0;
686
+ visibility: hidden;
687
+ transition: opacity 0.2s, visibility 0s 0.2s;
688
+ }
689
+ /* A moment late: Alt is pressed for much else, and a page that dimmed with every press would flicker. */
690
+ .veil.shown { opacity: 1; visibility: visible; transition: opacity 0.3s 0.08s; }
691
+ .veil.shown.lifted { opacity: 0; transition: opacity 0.6s; }
692
+ .aim {
693
+ position: fixed;
694
+ inset: 0;
695
+ z-index: 2147483646;
696
+ pointer-events: none;
697
+ opacity: 0;
698
+ visibility: hidden;
699
+ transition: opacity 0.12s, visibility 0s 0.12s;
700
+ }
701
+ .aim.shown { opacity: 1; visibility: visible; transition: opacity 0.12s; }
702
+ .ring {
703
+ position: absolute;
704
+ box-sizing: border-box;
705
+ border: 1.5px solid var(--deictic-accent);
706
+ box-shadow: 0 0 0 4px rgb(18 179 88 / 0.14), 0 0 32px rgb(18 179 88 / 0.5), inset 0 0 24px rgb(18 179 88 / 0.1);
707
+ }
708
+ /* From the element's edges across the window: what it lines up with, anywhere on the page. */
709
+ .guide { position: absolute; left: 0; top: 0; opacity: 0.35; }
710
+ .guide.gx { width: 1px; height: 100%; background: linear-gradient(transparent, var(--deictic-accent) 20% 80%, transparent); }
711
+ .guide.gy { width: 100%; height: 1px; background: linear-gradient(90deg, transparent, var(--deictic-accent) 20% 80%, transparent); }
712
+ .caption {
713
+ position: absolute;
714
+ left: -1.5px;
715
+ bottom: calc(100% + 8px);
716
+ display: flex;
717
+ align-items: center;
718
+ gap: 8px;
719
+ padding: 3px 10px 3px 3px;
720
+ border: 1px solid rgb(255 255 255 / 0.12);
721
+ border-radius: 999px;
722
+ font: 12px/20px ui-monospace, monospace;
723
+ white-space: nowrap;
724
+ color: var(--deictic-fg);
725
+ background: rgb(24 24 27 / 0.86);
726
+ backdrop-filter: blur(12px) saturate(1.6);
727
+ box-shadow: 0 8px 24px rgb(0 0 0 / 0.35);
728
+ }
729
+ .caption.below { top: calc(100% + 8px); bottom: auto; }
730
+ .caption .tag { padding: 0 8px; border-radius: 999px; font-weight: 600; color: var(--deictic-on-accent); background: var(--deictic-accent); }
731
+ .caption .dim { color: var(--deictic-muted); }
732
+ .caption .opens { padding-left: 8px; border-left: 1px solid rgb(255 255 255 / 0.16); font: 600 12px/20px system-ui, sans-serif; color: var(--deictic-accent); }
733
+ .lit { position: fixed; inset: 0; z-index: 2147483646; display: none; pointer-events: none; }
734
+ .lit.shown { display: block; }
735
+ .lit svg { display: block; width: 100%; height: 100%; fill: none; stroke: var(--deictic-accent); stroke-linecap: round; }
736
+ .lit .halo { stroke-width: 7; opacity: 0.16; }
737
+ .lit .lock, .lit .tether { stroke-width: 1.5; }
738
+ .lit .flow { stroke: #eafff3; stroke-width: 2; opacity: 0; }
739
+ .lit circle { fill: var(--deictic-accent); stroke: none; }
740
+ .lit:not(.tied) path, .lit:not(.tied) circle { display: none; }
741
+ .pulse {
742
+ position: fixed;
743
+ z-index: 2147483646;
744
+ box-sizing: border-box;
745
+ pointer-events: none;
746
+ outline: 2px solid var(--deictic-accent);
747
+ animation: deictic-pulse 0.5s ease-out forwards;
748
+ }
749
+ @media (prefers-reduced-motion: no-preference) {
750
+ .head .thumb.moves { transition: left 0.22s cubic-bezier(0.3, 0.7, 0.2, 1), width 0.22s cubic-bezier(0.3, 0.7, 0.2, 1); }
751
+ /* The light goes from one element to the next, not out and on again. */
752
+ .veil.shown.glide {
753
+ transition: opacity 0.3s, left 0.24s cubic-bezier(0.3, 0.7, 0.2, 1), top 0.24s cubic-bezier(0.3, 0.7, 0.2, 1),
754
+ width 0.24s cubic-bezier(0.3, 0.7, 0.2, 1), height 0.24s cubic-bezier(0.3, 0.7, 0.2, 1), border-radius 0.24s;
755
+ }
756
+ .aim.glide .ring {
757
+ transition: left 0.24s cubic-bezier(0.3, 0.7, 0.2, 1), top 0.24s cubic-bezier(0.3, 0.7, 0.2, 1),
758
+ width 0.24s cubic-bezier(0.3, 0.7, 0.2, 1), height 0.24s cubic-bezier(0.3, 0.7, 0.2, 1), border-radius 0.24s;
759
+ }
760
+ .aim.glide .guide { transition: translate 0.24s cubic-bezier(0.3, 0.7, 0.2, 1); }
761
+ .panel:not(.pinned) { animation: deictic-rise 0.32s cubic-bezier(0.2, 0.9, 0.25, 1.1) backwards; }
762
+ /* Once, as the popup opens: the line drawn out to the popup, with a light along it. */
763
+ .lit .tether, .lit path.halo { stroke-dasharray: 1; animation: deictic-draw 0.4s 0.1s ease-out backwards; }
764
+ .lit .flow { stroke-dasharray: 0.14 1; animation: deictic-flow 0.8s 0.45s ease-out; }
765
+ .lit circle:last-of-type { animation: deictic-in 0.2s 0.45s backwards; }
766
+ }
767
+ @keyframes deictic-rise {
768
+ from { opacity: 0; scale: 0.94; filter: blur(6px); }
769
+ }
770
+ @keyframes deictic-draw {
771
+ from { stroke-dashoffset: 1; }
772
+ }
773
+ @keyframes deictic-flow {
774
+ from { stroke-dashoffset: 0.14; opacity: 1; }
775
+ to { stroke-dashoffset: -1; opacity: 0; }
776
+ }
777
+ @keyframes deictic-pulse {
778
+ to { outline-offset: 14px; outline-color: transparent; }
779
+ }
780
+ /* The tool panel (tools.ts): the plugins' tools in a bar on an edge of the window, there while it's of use. */
781
+ .tool-panel {
782
+ position: fixed;
783
+ z-index: 2147483647;
784
+ display: flex;
785
+ align-items: center;
786
+ gap: 6px;
787
+ padding: 6px 8px;
788
+ border: 1px solid rgb(255 255 255 / 0.1);
789
+ border-radius: 12px;
790
+ font: 13px/1.4 system-ui, sans-serif;
791
+ color: var(--deictic-fg);
792
+ background: linear-gradient(rgb(39 39 42 / 0.92), rgb(24 24 27 / 0.96));
793
+ backdrop-filter: blur(24px) saturate(1.8);
794
+ box-shadow: 0 0 0 1px rgb(0 0 0 / 0.4), 0 16px 40px -8px rgb(0 0 0 / 0.55), inset 0 1px 0 rgb(255 255 255 / 0.08);
795
+ user-select: none;
796
+ opacity: 0;
797
+ visibility: hidden;
798
+ transition: opacity 0.15s, visibility 0s 0.15s;
799
+ }
800
+ .tool-panel.shown { opacity: 1; visibility: visible; transition: opacity 0.15s; }
801
+ .tool-panel.vertical, .tool-panel.vertical .tool-group { flex-direction: column; }
802
+ .tool-panel .tool-group { display: flex; align-items: center; gap: 4px; }
803
+ /* Groups of one section side by side, as close as the tools in a group are: the bar's gap is for between sections. */
804
+ .tool-panel .tool-group + .tool-group { margin-left: -2px; }
805
+ .tool-panel.vertical .tool-group + .tool-group { margin: -2px 0 0; }
806
+ .tool-panel .grip { display: inline-flex; padding: 2px; color: var(--deictic-muted); cursor: grab; touch-action: none; }
807
+ .tool-panel .grip:active { cursor: grabbing; }
808
+ .tool-panel .grip svg { width: 16px; height: 16px; }
809
+ .tool-panel .sep { align-self: stretch; width: 1px; background: rgb(255 255 255 / 0.12); }
810
+ .tool-panel.vertical .sep { width: auto; height: 1px; }
811
+ /* A group with nothing to show now (a plugin's, hidden) has no line of its own either. */
812
+ .tool-panel .sep:has(+ [hidden]) { display: none; }
813
+ .tool-panel [hidden] { display: none; }
814
+ .tool-panel button.icon { width: 28px; height: 26px; border-radius: 6px; color: var(--deictic-fg); }
815
+ .tool-panel button.icon svg { width: 16px; height: 16px; }
816
+ .tool-panel button[aria-pressed='true'], .tool-panel button[aria-pressed='true']:hover {
817
+ color: var(--deictic-on-accent);
818
+ background: var(--deictic-accent);
819
+ }
820
+ .tool-panel button.problem { color: var(--deictic-problem); }
821
+ /*
822
+ * The drawer (drawer.ts): on the window's side, as tall as what's in it, there while it's of use. Its
823
+ * sections are the plugins', each with its own styles; these are what they share.
824
+ */
825
+ .drawer {
826
+ position: fixed;
827
+ top: 12px;
828
+ right: 12px;
829
+ z-index: 2147483646;
830
+ display: flex;
831
+ flex-direction: column;
832
+ box-sizing: border-box;
833
+ width: 296px;
834
+ max-width: calc(100vw - 24px);
835
+ max-height: calc(100vh - 24px);
836
+ border: 1px solid rgb(255 255 255 / 0.1);
837
+ border-radius: 12px;
838
+ font: 12px/1.4 system-ui, sans-serif;
839
+ color: var(--deictic-fg);
840
+ background: linear-gradient(rgb(39 39 42 / 0.92), rgb(24 24 27 / 0.96));
841
+ backdrop-filter: blur(24px) saturate(1.8);
842
+ box-shadow: 0 0 0 1px rgb(0 0 0 / 0.4), 0 16px 40px -8px rgb(0 0 0 / 0.55), inset 0 1px 0 rgb(255 255 255 / 0.08);
843
+ opacity: 0;
844
+ visibility: hidden;
845
+ transition: opacity 0.15s, visibility 0s 0.15s;
846
+ }
847
+ .drawer.left { right: auto; left: 12px; }
848
+ .drawer.shown { opacity: 1; visibility: visible; transition: opacity 0.15s; }
849
+ .drawer.emptied { transition: none; }
850
+ .drawer [hidden] { display: none; }
851
+ .drawer-sections, .drawer-view { display: flex; flex-direction: column; gap: 12px; min-height: 0; padding: 10px; overflow-y: auto; scrollbar-width: thin; }
852
+ .drawer-view { gap: 8px; }
853
+ .drawer-section h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; font: 600 10px/1.4 system-ui, sans-serif; letter-spacing: 0.06em; text-transform: uppercase; color: var(--deictic-muted); }
854
+ .drawer-rows { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
855
+ .drawer-row { display: flex; align-items: center; gap: 2px; padding-right: 4px; border: 1px solid rgb(255 255 255 / 0.08); border-radius: 8px; background: rgb(255 255 255 / 0.04); }
856
+ .drawer-row:hover { border-color: rgb(255 255 255 / 0.16); }
857
+ /* A row one height whether it has a picture, and the picture one size, loaded or not: nothing moves as one comes. */
858
+ .drawer-open { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; height: 32px; padding: 0 6px; border: 0; text-align: left; font-size: 12px; }
859
+ .drawer-open img { flex: none; display: block; width: 36px; height: 24px; object-fit: cover; border-radius: 4px; background: rgb(255 255 255 / 0.08); }
860
+ .drawer-open svg { flex: none; width: 12px; height: 12px; }
861
+ .drawer-head { display: flex; align-items: center; gap: 6px; margin: -4px 24px 0 -4px; }
862
+ /* Folding it away: the button in its corner, and the pill it folds to, which counts what's in it. */
863
+ .drawer-fold { position: absolute; top: 6px; right: 6px; z-index: 1; width: 22px; height: 22px; border-radius: 6px; color: var(--deictic-muted); }
864
+ .drawer-fold svg { width: 14px; height: 14px; }
865
+ .drawer-sections > .drawer-section:first-child h3 { margin-right: 22px; }
866
+ .drawer-pill { display: none; align-items: center; gap: 6px; padding: 6px 10px; border: 0; border-radius: inherit; font: 600 12px/1 system-ui, sans-serif; color: var(--deictic-fg); }
867
+ .drawer-pill svg { width: 16px; height: 16px; }
868
+ .drawer-pill.news span { padding: 2px 6px; border-radius: 8px; color: var(--deictic-on-accent); background: var(--deictic-accent); }
869
+ .drawer.folded { width: auto; }
870
+ .drawer.folded > :not(.drawer-pill) { display: none; }
871
+ .drawer.folded .drawer-pill { display: inline-flex; }
872
+ .drawer-title { font-weight: 600; }
873
+ /* What a tool that picks a point takes the pointer with, over the page and under the popup. */
874
+ .tool-surface { position: fixed; inset: 0; z-index: 2147483645; cursor: crosshair; }
448
875
  .lightbox {
449
876
  position: fixed;
450
877
  inset: 0;
@@ -503,10 +930,11 @@ const STYLE = `
503
930
  padding: 0;
504
931
  border: 1px solid var(--deictic-line);
505
932
  border-radius: 50%;
506
- font-size: 22px;
507
- line-height: 1;
933
+ display: grid;
934
+ place-items: center;
508
935
  background: var(--deictic-bg);
509
936
  }
937
+ .lb-prev svg, .lb-next svg { width: 20px; height: 20px; }
510
938
  .lb-prev { left: 16px; }
511
939
  .lb-next { right: 16px; }
512
940
  .lightbox.pinned { position: relative; inset: auto; z-index: auto; display: block; padding: 0 64px; }
@@ -535,6 +963,23 @@ const STYLE = `
535
963
  transition: opacity 0.12s;
536
964
  }
537
965
  .tip.shown { visibility: visible; opacity: 1; }
966
+ /* A control's keys, after its name: caps, as on a keyboard. */
967
+ .tip kbd {
968
+ display: inline-block;
969
+ box-sizing: border-box;
970
+ min-width: 18px;
971
+ margin-left: 3px;
972
+ padding: 0 4px;
973
+ border: 1px solid var(--deictic-line);
974
+ border-bottom-width: 2px;
975
+ border-radius: 4px;
976
+ font: 11px/15px ui-monospace, monospace;
977
+ text-align: center;
978
+ color: var(--deictic-fg);
979
+ background: rgb(255 255 255 / 0.08);
980
+ }
981
+ .tip kbd:first-of-type { margin-left: 6px; }
982
+ .tip kbd:first-child { margin-left: 0; }
538
983
  button {
539
984
  font: inherit;
540
985
  color: inherit;
@@ -562,25 +1007,256 @@ button.icon {
562
1007
  }
563
1008
  button.icon svg { width: 14px; height: 14px; }
564
1009
  button.icon:hover:not(:disabled) { color: var(--deictic-fg); background: rgb(255 255 255 / 0.08); }
565
- button.primary { background: var(--deictic-accent); border-color: var(--deictic-accent); color: var(--deictic-on-accent); }
1010
+ button.primary {
1011
+ background: var(--deictic-accent);
1012
+ border-color: var(--deictic-accent);
1013
+ color: var(--deictic-on-accent);
1014
+ box-shadow: 0 4px 16px -4px rgb(18 179 88 / 0.6);
1015
+ }
566
1016
  input, textarea {
567
1017
  box-sizing: border-box;
568
1018
  width: 100%;
569
1019
  font: 12px ui-monospace, monospace;
570
1020
  color: inherit;
571
- background: #09090b;
1021
+ background: rgb(0 0 0 / 0.35);
572
1022
  border: 1px solid var(--deictic-line);
573
- border-radius: 4px;
1023
+ border-radius: 6px;
574
1024
  padding: 4px 6px;
575
1025
  }
576
1026
  input:focus, textarea:focus { outline: 1px solid var(--deictic-accent); }
577
1027
  code { font: 12px ui-monospace, monospace; }
578
1028
  /* Border-box, as the popup holds the body's height by its whole box while a tab reads. */
579
- .body { box-sizing: border-box; padding: 8px; overflow: auto; }
580
- .status { padding: 0 8px 6px; font-size: 12px; color: var(--deictic-muted); }
1029
+ .body { box-sizing: border-box; padding: 12px; overflow: auto; }
1030
+ .status { padding: 0 12px 10px; font-size: 12px; color: var(--deictic-muted); }
581
1031
  .status:empty { display: none; }
582
1032
  .status.problem { color: var(--deictic-problem); }
583
1033
  `;
1034
+ // src/client/tools.ts
1035
+ const DOCK = "deictic:tools";
1036
+ const MARGIN$1 = 12;
1037
+ /** How long the panel outlasts the keys, in milliseconds: time to get the pointer to it. */
1038
+ const LINGER = 600;
1039
+ const svg = (paths) => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${paths}</svg>`;
1040
+ const GRIP = svg("<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\"/>");
1041
+ const POINTER = svg("<path d=\"M5 3l14 7-6 2-2 6z\"/>");
1042
+ function storedDock() {
1043
+ try {
1044
+ const dock = JSON.parse(localStorage.getItem(DOCK) ?? "null");
1045
+ if (dock !== null && [
1046
+ "top",
1047
+ "bottom",
1048
+ "left",
1049
+ "right"
1050
+ ].includes(dock.edge) && dock.along >= 0 && dock.along <= 1) return dock;
1051
+ } catch {}
1052
+ return {
1053
+ edge: "bottom",
1054
+ along: .5
1055
+ };
1056
+ }
1057
+ /** Puts the bar on its edge, laid out along it, and how far along. */
1058
+ function place(bar, { edge, along }) {
1059
+ const vertical = edge === "left" || edge === "right";
1060
+ bar.classList.toggle("vertical", vertical);
1061
+ bar.setAttribute("aria-orientation", vertical ? "vertical" : "horizontal");
1062
+ const { width, height } = bar.getBoundingClientRect();
1063
+ const across = (room, size) => `${MARGIN$1 + along * Math.max(0, room - size - 24)}px`;
1064
+ Object.assign(bar.style, {
1065
+ left: edge === "left" ? `${MARGIN$1}px` : edge === "right" ? `${innerWidth - width - MARGIN$1}px` : across(innerWidth, width),
1066
+ top: edge === "top" ? `${MARGIN$1}px` : edge === "bottom" ? `${innerHeight - height - MARGIN$1}px` : across(innerHeight, height)
1067
+ });
1068
+ }
1069
+ /** Dragging the bar by its grip, freely; let go, it docks to the nearest edge. */
1070
+ function draggable(bar, grip, docked) {
1071
+ grip.addEventListener("pointerdown", (e) => {
1072
+ if (e.button !== 0) return;
1073
+ e.preventDefault();
1074
+ grip.setPointerCapture(e.pointerId);
1075
+ const start = bar.getBoundingClientRect();
1076
+ const dx = e.clientX - start.left;
1077
+ const dy = e.clientY - start.top;
1078
+ const move = (m) => {
1079
+ bar.style.left = `${m.clientX - dx}px`;
1080
+ bar.style.top = `${m.clientY - dy}px`;
1081
+ };
1082
+ const up = () => {
1083
+ grip.removeEventListener("pointermove", move);
1084
+ const r = bar.getBoundingClientRect();
1085
+ const x = r.left + r.width / 2;
1086
+ const y = r.top + r.height / 2;
1087
+ const [edge] = [
1088
+ ["left", x],
1089
+ ["right", innerWidth - x],
1090
+ ["top", y],
1091
+ ["bottom", innerHeight - y]
1092
+ ].reduce((a, b) => b[1] < a[1] ? b : a);
1093
+ const ratio = (at, room) => Math.min(1, Math.max(0, at / room));
1094
+ docked({
1095
+ edge,
1096
+ along: edge === "left" || edge === "right" ? ratio(y, innerHeight) : ratio(x, innerWidth)
1097
+ });
1098
+ };
1099
+ grip.addEventListener("pointermove", move);
1100
+ grip.addEventListener("pointerup", up, { once: true });
1101
+ });
1102
+ }
1103
+ function toolPanel(root, { spotAt, aim }) {
1104
+ const bar = div("tool-panel");
1105
+ bar.setAttribute("role", "toolbar");
1106
+ bar.setAttribute("aria-label", "deictic tools");
1107
+ const grip = Object.assign(document.createElement("span"), {
1108
+ className: "grip",
1109
+ title: "Drag to any edge",
1110
+ innerHTML: GRIP
1111
+ });
1112
+ const pointer = Object.assign(document.createElement("button"), {
1113
+ type: "button",
1114
+ className: "icon",
1115
+ title: "Pointer",
1116
+ innerHTML: POINTER
1117
+ });
1118
+ pointer.setAttribute("aria-label", "Pointer");
1119
+ pointer.setAttribute("aria-keyshortcuts", "V");
1120
+ bar.append(grip, pointer);
1121
+ const added = [];
1122
+ /**
1123
+ * The groups in their places: those of no section, then each section (in the order its first group came, its groups
1124
+ * side by side), then those of none that asked to be `last`. Within a section, its `last` ones are at its end. A
1125
+ * line between each.
1126
+ */
1127
+ const order = () => {
1128
+ const plain = added.filter((a) => a.section === void 0);
1129
+ const sections = [...new Set(added.flatMap((a) => a.section ?? []))].map((name) => {
1130
+ const of = added.filter((a) => a.section === name);
1131
+ for (const a of of) a.group.dataset.section = name;
1132
+ return [...of.filter((a) => !a.last), ...of.filter((a) => a.last)].map((a) => a.group);
1133
+ });
1134
+ const blocks = [
1135
+ ...plain.filter((a) => !a.last).map((a) => [a.group]),
1136
+ ...sections,
1137
+ ...plain.filter((a) => a.last).map((a) => [a.group])
1138
+ ];
1139
+ for (const sep of bar.querySelectorAll(":scope > .sep")) sep.remove();
1140
+ for (const block of blocks) bar.append(Object.assign(document.createElement("span"), { className: "sep" }), ...block);
1141
+ };
1142
+ root.append(bar);
1143
+ let dock = storedDock();
1144
+ const replace = () => place(bar, dock);
1145
+ addEventListener("resize", replace);
1146
+ draggable(bar, grip, (next) => {
1147
+ dock = next;
1148
+ replace();
1149
+ try {
1150
+ localStorage.setItem(DOCK, JSON.stringify(dock));
1151
+ } catch {}
1152
+ });
1153
+ let pointing = false;
1154
+ let over = false;
1155
+ let keeps = 0;
1156
+ let holder;
1157
+ let leaving;
1158
+ const shown = () => bar.classList.contains("shown");
1159
+ const show = () => {
1160
+ clearTimeout(leaving);
1161
+ leaving = void 0;
1162
+ pointer.setAttribute("aria-pressed", String(holder === void 0));
1163
+ const on = pointing || over || keeps > 0 || holder !== void 0;
1164
+ if (on === shown()) return;
1165
+ if (!on) {
1166
+ leaving = setTimeout(() => bar.classList.remove("shown"), LINGER);
1167
+ return;
1168
+ }
1169
+ bar.classList.add("shown");
1170
+ replace();
1171
+ };
1172
+ bar.addEventListener("pointerenter", () => {
1173
+ over = true;
1174
+ show();
1175
+ });
1176
+ bar.addEventListener("pointerleave", () => {
1177
+ over = false;
1178
+ show();
1179
+ });
1180
+ new ResizeObserver(() => shown() && replace()).observe(bar);
1181
+ const letGo = () => {
1182
+ const left = holder;
1183
+ holder = void 0;
1184
+ left?.();
1185
+ show();
1186
+ };
1187
+ pointer.addEventListener("click", letGo);
1188
+ window.addEventListener("keydown", (e) => {
1189
+ if (e.repeat || !(pointing || holder !== void 0)) return;
1190
+ if (root.querySelector("[data-deictic-modal]") !== null) return;
1191
+ const [target] = e.composedPath();
1192
+ const typing = target instanceof HTMLElement && target.matches("input, textarea, select, [contenteditable]");
1193
+ if (e.key === "Escape" && holder !== void 0) {
1194
+ e.preventDefault();
1195
+ e.stopImmediatePropagation();
1196
+ return letGo();
1197
+ }
1198
+ if (typing && (holder === void 0 || target.getRootNode() === root)) return;
1199
+ const control = controlFor(bar, e, pointing);
1200
+ if (control === void 0) return;
1201
+ e.preventDefault();
1202
+ e.stopImmediatePropagation();
1203
+ control.click();
1204
+ }, true);
1205
+ const hold = (left) => {
1206
+ letGo();
1207
+ holder = left;
1208
+ show();
1209
+ return () => {
1210
+ if (holder !== left) return;
1211
+ holder = void 0;
1212
+ show();
1213
+ };
1214
+ };
1215
+ return {
1216
+ add: (group, options) => {
1217
+ added.push({
1218
+ group,
1219
+ ...options?.section === void 0 ? {} : { section: options.section },
1220
+ last: options?.last === true
1221
+ });
1222
+ order();
1223
+ },
1224
+ hold,
1225
+ keep: () => {
1226
+ keeps++;
1227
+ show();
1228
+ let kept = true;
1229
+ return () => {
1230
+ if (!kept) return;
1231
+ kept = false;
1232
+ keeps--;
1233
+ show();
1234
+ };
1235
+ },
1236
+ pick: () => new Promise((done) => {
1237
+ const surface = div("tool-surface");
1238
+ root.append(surface);
1239
+ const end = (spot) => {
1240
+ surface.remove();
1241
+ aim(false);
1242
+ done(spot);
1243
+ };
1244
+ const release = hold(() => end(void 0));
1245
+ aim(true);
1246
+ surface.addEventListener("pointerdown", (e) => {
1247
+ if (e.button !== 0) return;
1248
+ e.preventDefault();
1249
+ release();
1250
+ end(spotAt(e.clientX, e.clientY));
1251
+ });
1252
+ }),
1253
+ point: (on) => {
1254
+ pointing = on;
1255
+ show();
1256
+ },
1257
+ edge: () => dock.edge
1258
+ };
1259
+ }
584
1260
  // src/client/tooltip.ts
585
1261
  /**
586
1262
  * One tooltip for everything deictic draws in a shadow root: whatever has a `title` (or `data-tip`) shows it
@@ -588,8 +1264,25 @@ code { font: 12px ui-monospace, monospace; }
588
1264
  * and looks like nothing else here. Plugins only set `title`, as they would anywhere; the first hover moves
589
1265
  * it to `data-tip`, so the browser's own stays away, and gives a textless control the title as its name.
590
1266
  * The box is fixed in the root, so no panel's scrolling clips it.
1267
+ *
1268
+ * A control's keys (`aria-keyshortcuts`, as `Control+Z`) are in its tip too, each a keycap after the words, and a
1269
+ * tip of their own for a control whose text already names it.
591
1270
  */
592
1271
  const DELAY = 300;
1272
+ const KEYS = "aria-keyshortcuts";
1273
+ /** A key as its cap reads, where that isn't its name. */
1274
+ const CAPS = {
1275
+ Control: "Ctrl",
1276
+ Meta: "⌘",
1277
+ Escape: "Esc",
1278
+ Backspace: "⌫",
1279
+ Enter: "↵"
1280
+ };
1281
+ /** The first of a control's shortcuts, a cap for each key held together. */
1282
+ function capsOf(el) {
1283
+ const [first = ""] = (el.getAttribute(KEYS) ?? "").split(" ");
1284
+ return first === "" ? [] : first.split("+").map((key) => Object.assign(document.createElement("kbd"), { textContent: CAPS[key] ?? key }));
1285
+ }
593
1286
  function tooltips(root) {
594
1287
  const tip = document.createElement("div");
595
1288
  tip.className = "tip";
@@ -603,13 +1296,23 @@ function tooltips(root) {
603
1296
  tip.classList.remove("shown");
604
1297
  };
605
1298
  const show = (el) => {
606
- const text = el.getAttribute("data-tip");
607
- if (text === null || text === "" || !el.isConnected) return hide();
608
- tip.textContent = text;
1299
+ const text = el.getAttribute("data-tip") ?? "";
1300
+ const caps = capsOf(el);
1301
+ if (text === "" && caps.length === 0 || !el.isConnected) return hide();
1302
+ tip.replaceChildren(text, ...caps);
609
1303
  if (tip !== root.lastElementChild) root.append(tip);
610
1304
  tip.classList.add("shown");
611
1305
  const r = el.getBoundingClientRect();
612
1306
  const t = tip.getBoundingClientRect();
1307
+ if (el.closest("[aria-orientation=\"vertical\"]") !== null) {
1308
+ const left = r.right + 6 + t.width > innerWidth - 8 ? r.left - 6 - t.width : r.right + 6;
1309
+ const top = Math.max(8, Math.min(r.top + r.height / 2 - t.height / 2, innerHeight - t.height - 8));
1310
+ Object.assign(tip.style, {
1311
+ left: `${left}px`,
1312
+ top: `${top}px`
1313
+ });
1314
+ return;
1315
+ }
613
1316
  const left = Math.max(8, Math.min(r.left + r.width / 2 - t.width / 2, innerWidth - t.width - 8));
614
1317
  const top = r.bottom + 6 + t.height > innerHeight - 8 ? r.top - 6 - t.height : r.bottom + 6;
615
1318
  Object.assign(tip.style, {
@@ -631,7 +1334,7 @@ function tooltips(root) {
631
1334
  if (!node.hasAttribute("aria-label") && (node.textContent ?? "").trim().length <= 1) node.setAttribute("aria-label", title);
632
1335
  else node.setAttribute("aria-description", title);
633
1336
  }
634
- if (node.hasAttribute("data-tip")) return node;
1337
+ if (node.hasAttribute("data-tip") || node.hasAttribute(KEYS)) return node;
635
1338
  }
636
1339
  };
637
1340
  const enter = (e) => {
@@ -657,8 +1360,48 @@ function tooltips(root) {
657
1360
  passive: true
658
1361
  });
659
1362
  }
1363
+ // src/client/tray.ts
1364
+ const KEY = "deictic:tray";
1365
+ function stored() {
1366
+ try {
1367
+ const kept = JSON.parse(sessionStorage.getItem(KEY) ?? "[]");
1368
+ return Array.isArray(kept) ? kept : [];
1369
+ } catch {
1370
+ return [];
1371
+ }
1372
+ }
1373
+ function tray() {
1374
+ let items = stored();
1375
+ const listeners = /* @__PURE__ */ new Set();
1376
+ const changed = () => {
1377
+ try {
1378
+ sessionStorage.setItem(KEY, JSON.stringify(items));
1379
+ } catch {}
1380
+ for (const listener of listeners) listener();
1381
+ };
1382
+ return {
1383
+ list: (plugin) => items.filter((item) => plugin === void 0 || item.plugin === plugin),
1384
+ add: (plugin, id, value) => {
1385
+ items = [...items.filter((item) => item.plugin !== plugin || item.id !== id), {
1386
+ plugin,
1387
+ id,
1388
+ value
1389
+ }];
1390
+ changed();
1391
+ },
1392
+ remove: (plugin, id) => {
1393
+ const left = items.filter((item) => item.plugin !== plugin || id !== void 0 && item.id !== id);
1394
+ if (left.length === items.length) return;
1395
+ items = left;
1396
+ changed();
1397
+ },
1398
+ subscribe: (listener) => {
1399
+ listeners.add(listener);
1400
+ return () => listeners.delete(listener);
1401
+ }
1402
+ };
1403
+ }
660
1404
  // src/client/index.ts
661
- const ATTRIBUTE = "data-deictic";
662
1405
  /** An arrow pointing up and out: the link leaves the page for the editor. */
663
1406
  const OUT = icon("M7 17 17 7M8 7h9v9", 2.25);
664
1407
  const UNDO = icon("M9 14 4 9l5-5M4 9h10.5a5.5 5.5 0 0 1 0 11H11");
@@ -669,20 +1412,6 @@ const LAST = "deictic:tab";
669
1412
  /** How long a read may take, in milliseconds, before the popup says it's reading. */
670
1413
  const SLOW = 200;
671
1414
  const STARTED = Symbol.for("deictic");
672
- function targetOf(el) {
673
- const at = el.getAttribute(ATTRIBUTE);
674
- const match = at === null ? null : /^(.*):(\d+):(\d+)$/.exec(at);
675
- if (match === null) return void 0;
676
- return {
677
- loc: {
678
- file: match[1],
679
- line: Number(match[2]),
680
- column: Number(match[3])
681
- },
682
- tag: el.localName
683
- };
684
- }
685
- const sameAs = (el) => [...document.querySelectorAll(`[${ATTRIBUTE}="${CSS.escape(el.getAttribute(ATTRIBUTE) ?? "")}"]`)];
686
1415
  /** The nearest marked element around `el`, out through shadow roots to their hosts. */
687
1416
  function markedAround(el) {
688
1417
  for (let at = el; at !== void 0;) {
@@ -692,11 +1421,9 @@ function markedAround(el) {
692
1421
  at = root instanceof ShadowRoot ? root.host : void 0;
693
1422
  }
694
1423
  }
695
- /** `div.panel > button.tab`: the element as a selector, the deepest classes only, for a person to tell it by. */
696
1424
  function icon(path, width = 2) {
697
1425
  return `<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="${width}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${path}"/></svg>`;
698
1426
  }
699
- const nameOf = (el) => `${el.localName}${[...el.classList].map((c) => `.${c}`).join("")}`;
700
1427
  let started;
701
1428
  /**
702
1429
  * What the page hears on `window` as the popup opens over it on an element (its `detail` a `PopupOpened`) and as
@@ -746,7 +1473,6 @@ function popupIn(container, { tab: name, element }) {
746
1473
  remember,
747
1474
  element,
748
1475
  target,
749
- pinned: true,
750
1476
  onClose: (shown, leaving) => {
751
1477
  panel = void 0;
752
1478
  if (!gone && !leaving) open(shown);
@@ -791,12 +1517,20 @@ function start({ base, shortcut: own, plugins: given, server }) {
791
1517
  const root = host.attachShadow({ mode: "open" });
792
1518
  const style = document.createElement("style");
793
1519
  style.textContent = STYLE;
794
- const box = div("box");
795
- const label = div("label");
796
- box.append(label);
797
- const inner = div("box inner");
798
- root.append(style, box, inner);
1520
+ root.append(style);
799
1521
  tooltips(root);
1522
+ const lighting = spotlight(root);
1523
+ const kept = tray();
1524
+ let picking = false;
1525
+ const tools = toolPanel(root, {
1526
+ spotAt: (x, y) => spotAt(x, y),
1527
+ aim: (on) => {
1528
+ picking = on;
1529
+ if (on) glance(true);
1530
+ else if (held.length === 0) hide();
1531
+ }
1532
+ });
1533
+ const drawer = drawerIn(root, { crowded: () => tools.edge() === "right" });
800
1534
  for (const type of [
801
1535
  "keydown",
802
1536
  "keypress",
@@ -805,6 +1539,15 @@ function start({ base, shortcut: own, plugins: given, server }) {
805
1539
  document.documentElement.append(host);
806
1540
  const apis = /* @__PURE__ */ new Map();
807
1541
  const send = server === void 0 ? (url, init) => fetch(url, init) : async (url, init) => server(new Request(new URL(url, location.href), init));
1542
+ const report = (problem) => {
1543
+ console.error(`deictic${problem.plugin === void 0 ? "" : `/${problem.plugin}`}: ${problem.message}`);
1544
+ const init = {
1545
+ method: "POST",
1546
+ headers: { "content-type": "application/json" },
1547
+ body: JSON.stringify(problem)
1548
+ };
1549
+ send(`${base}__deictic/problem`, init).catch(() => {});
1550
+ };
808
1551
  const optionsOf = new Map(given.map(({ plugin, options }) => [plugin.name, options]));
809
1552
  const contextOf = (name) => ({
810
1553
  base,
@@ -812,15 +1555,26 @@ function start({ base, shortcut: own, plugins: given, server }) {
812
1555
  options: optionsOf.get(name),
813
1556
  use: (other) => apis.get(other),
814
1557
  request: (route, init) => send(`${base}__deictic/plugins/${name}/${route}`, init),
815
- open: (plugin, element) => openAt(plugin, element),
816
- lightbox: (items, options) => openLightbox(root, items, options)
1558
+ report: (problem) => report({
1559
+ ...problem,
1560
+ plugin: name
1561
+ }),
1562
+ open: (plugin, element, at) => panel?.guard() !== true && openAt(plugin, element, at),
1563
+ lightbox: (items, options) => openLightbox(root, items, options),
1564
+ drawer,
1565
+ light: (element) => {
1566
+ lit = element?.isConnected === true ? element : void 0;
1567
+ relight();
1568
+ },
1569
+ tools,
1570
+ tray: kept
817
1571
  });
818
1572
  for (const { plugin } of given) {
819
1573
  if (plugin.setup === void 0) continue;
820
1574
  try {
821
1575
  apis.set(plugin.name, plugin.setup(contextOf(plugin.name)));
822
1576
  } catch (e) {
823
- console.error(`deictic: ${plugin.name} failed to set up`, e);
1577
+ report(failed(plugin.name, "set up in the page, so it does nothing there until the page loads again", e));
824
1578
  }
825
1579
  }
826
1580
  const tabs = given.flatMap(({ plugin }) => plugin.mount === void 0 ? [] : [{
@@ -849,14 +1603,16 @@ function start({ base, shortcut: own, plugins: given, server }) {
849
1603
  const plugins = [...own === void 0 || tabs.length === 0 ? [] : [{
850
1604
  shortcut: own,
851
1605
  gesture: gestureOf(own),
852
- tab: last
1606
+ tab: last,
1607
+ named: false
853
1608
  }], ...given.flatMap(({ plugin, shortcut }) => {
854
1609
  if (shortcut === void 0) return [];
855
1610
  const tab = tabs.find((t) => t.plugin === plugin);
856
1611
  if (tab !== void 0) return [{
857
1612
  shortcut,
858
1613
  gesture: gestureOf(shortcut),
859
- tab: () => tab
1614
+ tab: () => tab,
1615
+ named: true
860
1616
  }];
861
1617
  console.error(`deictic: ${plugin.name} has a shortcut, but its page half has no \`mount\` to draw a tab with`);
862
1618
  return [];
@@ -870,10 +1626,11 @@ function start({ base, shortcut: own, plugins: given, server }) {
870
1626
  const pressedBy = (e) => plugins.find((p) => p.gesture.held(e) && e.button === p.gesture.button);
871
1627
  /**
872
1628
  * The marked element at a point, and what's under the pointer inside it where that differs: down through
873
- * open shadow roots but the overlay's own, as a page showing the popup (`popupIn`) has it in one.
1629
+ * open shadow roots but the overlay's own, as a page showing the popup (`popupIn`) has it in one. `through` the
1630
+ * overlay, where it's the overlay that has the pointer: a tool's surface, while a point is picked.
874
1631
  */
875
- const hitAt = (x, y) => {
876
- let under = document.elementFromPoint(x, y) ?? void 0;
1632
+ const hitAt = (x, y, through = false) => {
1633
+ let under = (through ? document.elementsFromPoint(x, y).find((el) => el !== host) : document.elementFromPoint(x, y)) ?? void 0;
877
1634
  while (under !== void 0 && under !== host && under.shadowRoot !== null) {
878
1635
  const inside = under.shadowRoot.elementFromPoint(x, y);
879
1636
  if (inside === null || inside === under) break;
@@ -885,37 +1642,98 @@ function start({ base, shortcut: own, plugins: given, server }) {
885
1642
  pointed: under === el ? void 0 : under
886
1643
  };
887
1644
  };
1645
+ let held = [];
1646
+ let glanced;
1647
+ const glance = (on) => {
1648
+ if (on === (glanced !== void 0)) return;
1649
+ for (const end of glanced ?? []) end();
1650
+ glanced = !on ? void 0 : given.flatMap(({ plugin }) => {
1651
+ try {
1652
+ return plugin.pointing === void 0 ? [] : [plugin.pointing(contextOf(plugin.name))];
1653
+ } catch (e) {
1654
+ report(failed(plugin.name, "show what it has on the page as it was pointed at", e));
1655
+ return [];
1656
+ }
1657
+ });
1658
+ };
1659
+ let lit;
1660
+ const relight = () => {
1661
+ const target = lit === void 0 ? void 0 : targetOf(lit);
1662
+ if (lit !== void 0 && target !== void 0) return lighting.point({
1663
+ el: lit,
1664
+ target,
1665
+ names: [],
1666
+ count: sameAs(lit).length
1667
+ });
1668
+ if (held.length > 0 || picking) return show(false);
1669
+ lighting.hide();
1670
+ };
888
1671
  const hide = () => {
889
- box.classList.remove("shown");
890
- inner.classList.remove("shown");
1672
+ held = [];
1673
+ tools.point(false);
1674
+ drawer.point(false);
1675
+ glance(false);
1676
+ relight();
1677
+ };
1678
+ /** The marked element at a point of the window, or the nearest to it where none is under it, and the point in it. */
1679
+ const spotAt = (x, y) => {
1680
+ const away = (el) => {
1681
+ const r = el.getBoundingClientRect();
1682
+ return r.width === 0 || r.height === 0 ? 1e400 : Math.hypot(Math.max(r.left - x, 0, x - r.right), Math.max(r.top - y, 0, y - r.bottom));
1683
+ };
1684
+ const nearest = () => {
1685
+ let found;
1686
+ for (const el of document.querySelectorAll(`[${ATTRIBUTE}]`)) {
1687
+ const far = away(el);
1688
+ if (far !== 1e400 && (found === void 0 || far <= found.far)) found = {
1689
+ el,
1690
+ far
1691
+ };
1692
+ }
1693
+ return found?.el;
1694
+ };
1695
+ const element = hitAt(x, y, true)?.el ?? nearest();
1696
+ if (element === void 0) return void 0;
1697
+ const r = element.getBoundingClientRect();
1698
+ return {
1699
+ element,
1700
+ at: {
1701
+ x: Math.round(x - r.left),
1702
+ y: Math.round(y - r.top)
1703
+ }
1704
+ };
891
1705
  };
892
- const show = (held) => {
1706
+ const show = (glide) => {
893
1707
  frame = 0;
894
- const hit = pointer === void 0 ? void 0 : hitAt(pointer.x, pointer.y);
1708
+ if (pointer !== void 0 && !picking && held.length > 0 && document.elementFromPoint(pointer.x, pointer.y) === host) {
1709
+ if (lit !== void 0) relight();
1710
+ return;
1711
+ }
1712
+ const hit = pointer === void 0 || held.length === 0 && !picking ? void 0 : hitAt(pointer.x, pointer.y, picking);
895
1713
  const el = hit?.el;
896
1714
  const target = el === void 0 ? void 0 : targetOf(el);
897
- if (el === void 0 || target === void 0) return hide();
898
- place(box, el.getBoundingClientRect());
899
- if (hit?.pointed === void 0) inner.classList.remove("shown");
900
- else {
901
- place(inner, hit.pointed.getBoundingClientRect());
902
- inner.classList.add("shown");
903
- }
904
- const count = sameAs(el).length;
905
- const names = held.map(({ tab, shortcut }) => {
1715
+ if (el === void 0 || target === void 0) return lighting.hide();
1716
+ const names = held.flatMap(({ tab, shortcut, named }) => {
1717
+ if (!named) return [];
906
1718
  const { plugin } = tab();
907
1719
  const name = plugin.label ?? plugin.name;
908
- return shortcut.button === "left" ? name : `${name} (${shortcut.button})`;
1720
+ return [shortcut.button === "left" ? name : `${name} (${shortcut.button})`];
909
1721
  });
910
- const within = hit?.pointed === void 0 ? "" : ` › ${nameOf(hit.pointed)}`;
911
- label.textContent = `${names.join(" / ")} · <${target.tag}> ${target.loc.file}:${target.loc.line}${count > 1 ? ` · ×${count}` : ""}${within}`;
912
- label.classList.toggle("below", el.getBoundingClientRect().top < 24);
913
- box.classList.add("shown");
1722
+ lighting.point({
1723
+ el,
1724
+ ...hit?.pointed === void 0 ? {} : { pointed: hit.pointed },
1725
+ target,
1726
+ names,
1727
+ count: sameAs(el).length
1728
+ }, glide);
914
1729
  };
915
1730
  const update = (e) => {
916
- const held = heldBy(e);
917
- if (held.length === 0) return hide();
918
- if (frame === 0) frame = requestAnimationFrame(() => show(held));
1731
+ held = heldBy(e);
1732
+ if (held.length === 0 && !picking) return hide();
1733
+ tools.point(held.length > 0);
1734
+ drawer.point(held.length > 0);
1735
+ glance(true);
1736
+ if (frame === 0) frame = requestAnimationFrame(() => show(true));
919
1737
  };
920
1738
  window.addEventListener("mousemove", (e) => {
921
1739
  pointer = {
@@ -930,6 +1748,12 @@ function start({ base, shortcut: own, plugins: given, server }) {
930
1748
  window.addEventListener("keydown", update, true);
931
1749
  window.addEventListener("keyup", update, true);
932
1750
  window.addEventListener("blur", hide);
1751
+ window.addEventListener("scroll", () => {
1752
+ if ((held.length > 0 || picking) && frame === 0) frame = requestAnimationFrame(() => show(false));
1753
+ }, {
1754
+ capture: true,
1755
+ passive: true
1756
+ });
933
1757
  let press = {};
934
1758
  let opened;
935
1759
  window.addEventListener("mousedown", (e) => {
@@ -950,7 +1774,7 @@ function start({ base, shortcut: own, plugins: given, server }) {
950
1774
  if (panel?.unsaved() === true) return;
951
1775
  openTab(found.tab(), hit.el, target, void 0, hit.pointed);
952
1776
  };
953
- const openTab = (tab, el, target, resumed, pointed) => {
1777
+ const openTab = (tab, el, target, resumed, pointed, at) => {
954
1778
  hide();
955
1779
  panel?.close();
956
1780
  panel = openPanel({
@@ -963,12 +1787,14 @@ function start({ base, shortcut: own, plugins: given, server }) {
963
1787
  remember,
964
1788
  element: el,
965
1789
  ...pointed === void 0 ? {} : { pointed },
1790
+ ...at === void 0 ? {} : { at },
966
1791
  target,
1792
+ lighting,
967
1793
  onClose: () => panel = void 0,
968
1794
  ...resumed === void 0 ? {} : { resumed },
969
1795
  reopen: (again, element, kept) => {
970
1796
  const found = element.isConnected ? element : sameAs(element)[0] ?? element;
971
- openTab(again, found, targetOf(found) ?? target, kept, pointed?.isConnected === true && found === element ? pointed : void 0);
1797
+ openTab(again, found, targetOf(found) ?? target, kept, pointed?.isConnected === true && found === element ? pointed : void 0, at);
972
1798
  }
973
1799
  });
974
1800
  };
@@ -982,7 +1808,8 @@ function start({ base, shortcut: own, plugins: given, server }) {
982
1808
  const { loc, tag } = away.target;
983
1809
  const absent = document.createElement(tag);
984
1810
  absent.setAttribute(ATTRIBUTE, `${loc.file}:${loc.line}:${loc.column}`);
985
- openTab(tab, sameAs(absent).find((el) => el.localName === tag) ?? absent, away.target, resumed);
1811
+ const found = sameAs(absent).find((el) => el.localName === tag);
1812
+ openTab(tab, found ?? absent, away.target, resumed, void 0, found === void 0 ? void 0 : away.at);
986
1813
  };
987
1814
  task.then((result) => back({
988
1815
  state: away.state,
@@ -992,12 +1819,12 @@ function start({ base, shortcut: own, plugins: given, server }) {
992
1819
  problem: messageOf(e)
993
1820
  }));
994
1821
  });
995
- function openAt(name, given) {
1822
+ function openAt(name, given, at) {
996
1823
  const tab = tabs.find((t) => t.plugin.name === name);
997
1824
  const el = given.isConnected ? given : sameAs(given)[0] ?? void 0;
998
1825
  const target = el === void 0 ? void 0 : targetOf(el);
999
1826
  if (tab === void 0 || el === void 0 || target === void 0) return false;
1000
- openTab(tab, el, target);
1827
+ openTab(tab, el, target, void 0, void 0, at);
1001
1828
  return true;
1002
1829
  }
1003
1830
  for (const type of [
@@ -1006,7 +1833,8 @@ function start({ base, shortcut: own, plugins: given, server }) {
1006
1833
  "contextmenu"
1007
1834
  ]) window.addEventListener(type, pressed, true);
1008
1835
  }
1009
- function openPanel({ base, send, root, contextOf, tabs, tab: first, remember, element, pointed, target, pinned = false, onClose, resumed: coming, reopen }) {
1836
+ function openPanel({ base, send, root, contextOf, tabs, tab: first, remember, element, pointed, at: spot, target, lighting, onClose, resumed: coming, reopen }) {
1837
+ const pinned = lighting === void 0;
1010
1838
  let resumed = coming;
1011
1839
  const panel = div("panel");
1012
1840
  const head = div("head");
@@ -1016,7 +1844,11 @@ function openPanel({ base, send, root, contextOf, tabs, tab: first, remember, el
1016
1844
  where.className = "where";
1017
1845
  const file = document.createElement("span");
1018
1846
  file.textContent = `${target.loc.file}:${target.loc.line}`;
1019
- where.append(file);
1847
+ const tag = Object.assign(document.createElement("span"), {
1848
+ className: "tag",
1849
+ textContent: tell(named(element))
1850
+ });
1851
+ where.append(tag, file);
1020
1852
  where.insertAdjacentHTML("beforeend", OUT);
1021
1853
  where.title = "Open in editor";
1022
1854
  where.setAttribute("aria-label", `Open ${file.textContent} in the editor`);
@@ -1044,8 +1876,17 @@ function openPanel({ base, send, root, contextOf, tabs, tab: first, remember, el
1044
1876
  el
1045
1877
  };
1046
1878
  });
1047
- close.classList.add("close");
1048
- head.append(...buttons.map((b) => b.el), close);
1879
+ const thumb = div("thumb");
1880
+ const slide = (to) => {
1881
+ Object.assign(thumb.style, {
1882
+ left: `${to.offsetLeft}px`,
1883
+ width: `${to.offsetWidth}px`
1884
+ });
1885
+ thumb.offsetWidth;
1886
+ thumb.classList.add("moves");
1887
+ };
1888
+ close.classList.add("end");
1889
+ head.append(thumb, ...buttons.map((b) => b.el), close);
1049
1890
  bar.append(where, undo, redo);
1050
1891
  if (!element.isConnected) where.after(Object.assign(document.createElement("span"), {
1051
1892
  className: "absent",
@@ -1057,8 +1898,8 @@ function openPanel({ base, send, root, contextOf, tabs, tab: first, remember, el
1057
1898
  panel.append(head, bar, body, status);
1058
1899
  root.append(panel);
1059
1900
  if (pinned) panel.classList.add("pinned");
1060
- const release = pinned ? void 0 : keepInView(panel, body, head, element);
1061
- const unmark = pinned ? void 0 : outline(root, element);
1901
+ const release = pinned ? void 0 : keepInView(panel, body, head, element, spot);
1902
+ const unmark = lighting?.hold(element, panel, spot);
1062
1903
  if (!pinned) window.dispatchEvent(new CustomEvent(POPUP_OPENED, { detail: {
1063
1904
  element,
1064
1905
  tab: first.plugin.name
@@ -1170,73 +2011,88 @@ function openPanel({ base, send, root, contextOf, tabs, tab: first, remember, el
1170
2011
  say("");
1171
2012
  const back = current === first ? resumed : void 0;
1172
2013
  resumed = void 0;
1173
- cleanup = mount(body, {
1174
- ...contextOf(plugin.name),
1175
- ...back === void 0 ? {} : { resumed: back },
1176
- away: (state, task) => {
1177
- const tab = current;
1178
- done(true);
1179
- if (!pinned) keepAway({
1180
- tab: tab.plugin.name,
1181
- target,
1182
- state
1183
- });
1184
- const back = (resumed) => {
1185
- if (!pinned) dropAway();
1186
- reopen(tab, element, resumed);
1187
- };
1188
- task().then((result) => back({
1189
- state,
1190
- result
1191
- }), (e) => back({
1192
- state,
1193
- problem: messageOf(e)
1194
- }));
1195
- },
1196
- element,
1197
- ...pointed === void 0 ? {} : { pointed },
1198
- elements: sameAs(element),
1199
- target,
1200
- model,
1201
- apply: async (op) => {
1202
- say("Writing…");
1203
- try {
1204
- const result = await post("apply", {
1205
- plugin: plugin.name,
2014
+ try {
2015
+ cleanup = mount(body, {
2016
+ ...contextOf(plugin.name),
2017
+ ...back === void 0 ? {} : { resumed: back },
2018
+ away: (state, task) => {
2019
+ const tab = current;
2020
+ done(true);
2021
+ if (!pinned) keepAway({
2022
+ tab: tab.plugin.name,
1206
2023
  target,
1207
- op
2024
+ state,
2025
+ ...spot === void 0 ? {} : { at: spot }
1208
2026
  });
1209
- say("");
1210
- steps();
1211
- return result.model;
1212
- } catch (e) {
1213
- say(messageOf(e), true);
1214
- throw e;
2027
+ const back = (resumed) => {
2028
+ if (!pinned) dropAway();
2029
+ reopen(tab, element, resumed);
2030
+ };
2031
+ task().then((result) => back({
2032
+ state,
2033
+ result
2034
+ }), (e) => back({
2035
+ state,
2036
+ problem: messageOf(e)
2037
+ }));
2038
+ },
2039
+ element,
2040
+ ...pointed === void 0 ? {} : { pointed },
2041
+ ...spot === void 0 ? {} : { at: spot },
2042
+ elements: sameAs(element),
2043
+ target,
2044
+ model,
2045
+ apply: async (op, on = target) => {
2046
+ say("Writing…");
2047
+ try {
2048
+ const result = await post("apply", {
2049
+ plugin: plugin.name,
2050
+ target: on,
2051
+ op
2052
+ });
2053
+ say("");
2054
+ steps();
2055
+ return result.model;
2056
+ } catch (e) {
2057
+ say(messageOf(e), true);
2058
+ throw e;
2059
+ }
2060
+ },
2061
+ close: () => done(),
2062
+ unsaved: (action) => {
2063
+ if (read === reads) holding = action;
1215
2064
  }
1216
- },
1217
- close: () => done(),
1218
- unsaved: (action) => {
1219
- if (read === reads) holding = action;
1220
- }
1221
- });
2065
+ });
2066
+ } catch (e) {
2067
+ say(messageOf(e), true);
2068
+ contextOf(plugin.name).report(failed(plugin.name, "show its panel", e));
2069
+ }
1222
2070
  };
1223
2071
  const show = (tab) => {
1224
2072
  current = tab;
1225
- for (const b of buttons) b.el.setAttribute("aria-selected", String(b.tab === tab));
2073
+ for (const b of buttons) {
2074
+ b.el.setAttribute("aria-selected", String(b.tab === tab));
2075
+ if (b.tab === tab) slide(b.el);
2076
+ }
1226
2077
  remember(tab);
1227
2078
  steps();
1228
2079
  load();
1229
2080
  };
1230
2081
  show(first);
2082
+ const guard = () => {
2083
+ if (holding !== void 0) shake(holding);
2084
+ return holding !== void 0;
2085
+ };
1231
2086
  return {
1232
2087
  close: done,
1233
- unsaved: () => holding !== void 0
2088
+ unsaved: () => holding !== void 0,
2089
+ guard
1234
2090
  };
1235
2091
  }
1236
2092
  /** Shakes a panel's button, in view: what a press outside does where closing would lose something. A blink where motion is reduced. */
1237
2093
  function shake(el) {
1238
2094
  el.scrollIntoView({ block: "nearest" });
1239
- if (matchMedia("(prefers-reduced-motion: reduce)").matches) return void el.animate({ opacity: [
2095
+ if (reduced()) return void el.animate({ opacity: [
1240
2096
  1,
1241
2097
  .3,
1242
2098
  1,
@@ -1256,57 +2112,25 @@ function shake(el) {
1256
2112
  easing: "ease-out"
1257
2113
  });
1258
2114
  }
1259
- /** Puts an outline over `r`. */
1260
- function place(el, r) {
1261
- Object.assign(el.style, {
1262
- left: `${r.left}px`,
1263
- top: `${r.top}px`,
1264
- width: `${r.width}px`,
1265
- height: `${r.height}px`
1266
- });
1267
- }
1268
- /** How far from the element the popup's outline is drawn, in pixels. */
1269
- const ROOM = 4;
1270
- /**
1271
- * Outlines the element the popup is open on, for as long as it is: which one it's about, where several look alike
1272
- * or the popup covers it. Dashed, with no fill and a little room around the element, so nothing of it is drawn on:
1273
- * a border, a ring or a colour tried on it shows as it is. Read each frame, as the element moves with the page's
1274
- * scrolling, its layout and what a panel previews on it. Answers what removes it.
1275
- */
1276
- function outline(root, element) {
1277
- const box = div("box on");
1278
- root.append(box);
1279
- let frame = 0;
1280
- let was = "";
1281
- const follow = () => {
1282
- frame = requestAnimationFrame(follow);
1283
- const r = element.getBoundingClientRect();
1284
- const now = element.isConnected ? `${r.left},${r.top},${r.width},${r.height}` : "";
1285
- if (now === was) return;
1286
- was = now;
1287
- box.classList.toggle("shown", now !== "");
1288
- place(box, new DOMRect(r.left - ROOM, r.top - ROOM, r.width + 8, r.height + 8));
1289
- };
1290
- follow();
1291
- return () => {
1292
- cancelAnimationFrame(frame);
1293
- box.remove();
1294
- };
1295
- }
1296
2115
  const MARGIN = 8;
1297
2116
  const LEAST = 160;
2117
+ /** How far from the element the popup is, in pixels: room for the line between them. */
2118
+ const APART = 32;
1298
2119
  /** How far a press on the head moves, in pixels, before it's a drag: a click there leaves the popup following. */
1299
2120
  const SLACK = 3;
1300
2121
  /**
1301
2122
  * Keeps a panel beside `element` and inside the viewport, as its tabs fill it, the window resizes and the element
1302
- * moves with the page: below, or above where it fits better, its height capped to the room there, so the body
1303
- * scrolls rather than the panel leaving the window. Dragged by `handle`, it stays where it's put, in the window,
1304
- * and follows the element no more. Fixed, so it never changes the page's own scrolling. Answers a release.
2123
+ * moves with the page: to its right, or its left, where there's the room, level with its top and as tall as the
2124
+ * window lets it be; else below, or above where it fits better, its height capped to the room there, so the body
2125
+ * scrolls rather than the panel leaving the window. Off the element either way (`APART`): it's what's lit, with
2126
+ * room for the line between them. Dragged by `handle`, it stays where it's put, in the window, and follows the
2127
+ * element no more. Fixed, so it never changes the page's own scrolling. Answers a release.
1305
2128
  */
1306
- function keepInView(panel, body, handle, element) {
2129
+ function keepInView(panel, body, handle, element, at) {
1307
2130
  let frame = 0;
1308
2131
  let timer;
1309
- let r = element.getBoundingClientRect();
2132
+ const boxOf = () => at === void 0 ? element.getBoundingClientRect() : spotOf(element, at);
2133
+ let r = boxOf();
1310
2134
  let moved = element.isConnected ? void 0 : {
1311
2135
  left: (document.documentElement.clientWidth - panel.offsetWidth) / 2,
1312
2136
  top: document.documentElement.clientHeight / 5
@@ -1330,26 +2154,40 @@ function keepInView(panel, body, handle, element) {
1330
2154
  }
1331
2155
  const top = Math.min(Math.max(r.top, 0), height);
1332
2156
  const bottom = Math.min(Math.max(r.bottom, 0), height);
1333
- const below = height - bottom - 16;
1334
- const above = top - 16;
2157
+ const gap = APART;
2158
+ const right = width - MARGIN - panel.offsetWidth - (r.right + gap);
2159
+ const left = r.left - gap - panel.offsetWidth - MARGIN;
2160
+ if (right >= 0 || left >= 0) {
2161
+ const room = Math.max(0, height - 16);
2162
+ Object.assign(panel.style, {
2163
+ left: `${right >= 0 ? r.right + gap : r.left - gap - panel.offsetWidth}px`,
2164
+ top: `${Math.max(MARGIN, Math.min(r.top - 8, height - MARGIN - Math.min(wanted, room)))}px`,
2165
+ maxHeight: `${room}px`,
2166
+ transformOrigin: right >= 0 ? "0 24px" : "100% 24px"
2167
+ });
2168
+ return;
2169
+ }
2170
+ const below = height - bottom - gap - MARGIN;
2171
+ const above = top - gap - MARGIN;
1335
2172
  const cap = Math.max(0, Math.min(height * .6, height - 16));
1336
2173
  let at;
1337
2174
  let room;
1338
2175
  if (Math.max(below, above) < LEAST) {
1339
2176
  room = height - 16;
1340
- at = Math.min(Math.max(bottom + MARGIN, MARGIN), height - MARGIN - Math.min(wanted, room));
2177
+ at = Math.min(Math.max(bottom + gap, MARGIN), height - MARGIN - Math.min(wanted, room));
1341
2178
  } else if (wanted <= below || below >= above) {
1342
2179
  room = Math.min(below, cap);
1343
- at = bottom + MARGIN;
2180
+ at = bottom + gap;
1344
2181
  } else {
1345
2182
  room = Math.min(above, cap);
1346
- at = top - MARGIN - Math.min(wanted, room);
2183
+ at = top - gap - Math.min(wanted, room);
1347
2184
  }
1348
2185
  Object.assign(panel.style, {
1349
2186
  left: `${Math.max(MARGIN, Math.min(r.left, width - MARGIN - panel.offsetWidth))}px`,
1350
2187
  top: `${at}px`,
1351
2188
  bottom: "",
1352
- maxHeight: `${room}px`
2189
+ maxHeight: `${room}px`,
2190
+ transformOrigin: at < top ? "24px 100%" : "24px 0"
1353
2191
  });
1354
2192
  };
1355
2193
  const later = () => {
@@ -1361,7 +2199,7 @@ function keepInView(panel, body, handle, element) {
1361
2199
  if (moved !== void 0) return;
1362
2200
  watching = requestAnimationFrame(watch);
1363
2201
  if (!element.isConnected) return;
1364
- const now = element.getBoundingClientRect();
2202
+ const now = boxOf();
1365
2203
  if (now.left === r.left && now.top === r.top && now.width === r.width && now.height === r.height) return;
1366
2204
  r = now;
1367
2205
  fit();
@@ -1417,11 +2255,6 @@ function keepInView(panel, body, handle, element) {
1417
2255
  window.removeEventListener("resize", later);
1418
2256
  };
1419
2257
  }
1420
- function div(className) {
1421
- const el = document.createElement("div");
1422
- el.className = className;
1423
- return el;
1424
- }
1425
2258
  /** A button that is a drawing: named for what it does, as its title, the tooltip, changes with what it would do. */
1426
2259
  function iconButton(svg, name, title) {
1427
2260
  const el = button("", title);
@@ -1438,6 +2271,14 @@ function button(text, title) {
1438
2271
  return el;
1439
2272
  }
1440
2273
  const messageOf = (e) => e instanceof Error ? e.message : String(e);
2274
+ /** A plugin's page half that threw: a bug of the plugin's, to report where it's made. Its key is the first line of what it threw. */
2275
+ const failed = (plugin, what, e) => ({
2276
+ key: `page:${plugin}:${what.split(" ", 1)[0]}:${messageOf(e).split("\n", 1)[0].slice(0, 200)}`,
2277
+ kind: "bug",
2278
+ plugin,
2279
+ message: `${plugin} failed to ${what}: ${messageOf(e)}`,
2280
+ ...e instanceof Error && e.stack !== void 0 ? { details: e.stack } : {}
2281
+ });
1441
2282
  export { POPUP_CLOSED, POPUP_OPENED, drawBars, lightboxIn, liveWaveform, openPopup, peaksOf, popupIn, start, targetOf };
1442
2283
 
1443
2284
  //# sourceMappingURL=index.js.map