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,103 +1,99 @@
1
- import { n as liveWaveform } from "../shared/waveform.js";
1
+ import { a as tell, i as ownerOf, n as fiberOf, r as named, t as componentOf } from "../shared/component.js";
2
+ import { c as sameAs, i as div, l as targetOf, o as place, s as reduced, t as ATTRIBUTE, u as toolButton } from "../shared/dom.js";
2
3
  import { n as defineClientPlugin } from "../shared/src.js";
3
- // src/plugins/tasks/client.ts
4
+ import { n as liveWaveform } from "../shared/waveform.js";
5
+ // src/plugins/tasks/composer.ts
4
6
  /**
5
- * The tasks panel: the tasks already about this element and their state, and a field to add one. Each
6
- * task's ID opens it on the board, where the board has a page; one no one has claimed yet can be edited
7
- * in place (its words) or deleted (canceled on the board), both changes the popup's undo takes back.
8
- * Beside the channel it says who watches it (`Model.watching`), or that no agent does.
9
- * Ctrl+Enter or Add sends it with the page's URL, the viewport and the element as it rendered, which
10
- * the source can't tell: the chain of source it rendered through, its HTML (a file attached), and where the
11
- * annotations plugin is loaded, what's marked on the page.
7
+ * The composer: a field as a chat has, shared by the Task tab (a new task) and a task's thread in the drawer (a
8
+ * reply). What's attached is chips over the words, and under them the buttons that attach, each an icon named by its
9
+ * tooltip, and the arrow that sends. Enter sends, and Shift+Enter starts a new line.
10
+ *
11
+ * Two buttons are on or off. With the screenshots plugin, a shot of the page goes as it's sent, the elements
12
+ * outlined in it (or the spot circled): nothing else says which of two rows alike was meant. And, for a task, the
13
+ * element's HTML as it rendered, as a file. The rest make something: Draw takes a shot and opens it to draw on, in the
14
+ * annotations plugin's editor; Record is the caller's (the Task tab leaves the popup to record the page); Voice
15
+ * records the mic here, its time and waveform beside it.
12
16
  *
13
- * Where the screenshots plugin is loaded, a shot of the page goes with it, unless that's unticked, the element
14
- * outlined in it as the task goes: nothing else says which of two rows alike was meant (a shot drawn on is
15
- * left as it was drawn). With
16
- * the annotations plugin too, Annotate takes the shot now and opens it to draw on: saved, it's a chip
17
- * under the field, which opens it again to change the marks, and Add another takes one more. Any chip
18
- * (a recording's too) takes the box's place; removing the last brings it back unticked, so a task goes
19
- * without a shot unless asked again.
17
+ * A task's elements are chips too: the one the popup is on to begin with, and any other the element button's next
18
+ * press on the page picks. A reply has none.
20
19
  *
21
- * The element's HTML as it rendered goes with it too, as a file, unless its box is unticked (or the server
22
- * half's `html` option is off, and then there's no box).
20
+ * A picture pasted in, or dropped on it, is a screenshot of its own, in the tray, to draw on as one drawn here is.
23
21
  *
24
- * Where the recordings plugin is loaded, Record leaves the popup (`away`) to record the page, keeping
25
- * what's typed and attached, and comes back with the recording as a chip too, which plays it back.
26
- * Where the voice plugin is, Voice records the mic here in the panel: stopped, it's a chip that plays it.
22
+ * What they make, and what the tool panel's tools made since (the tray), is this one's to attach. Each is a chip,
23
+ * which opens it; removing one takes it out of the tray. Once it's sent, they're gone from the tray, and the page's
24
+ * marks with them.
27
25
  */
28
- const STYLE = `
29
- /* The column is no wider than the panel: an \`auto\` one grows to a long title, which then never truncates. */
30
- .tasks { list-style: none; margin: 0 0 8px; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
31
- /* Five rows, and the rest scrolled to: the field stays where it is however many there are. */
32
- .tasks { max-height: 112px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--deictic-line) transparent; }
33
- /* A task's words being changed need the room. */
34
- .tasks:has(.editing) { max-height: none; }
35
- .tasks li { position: relative; display: flex; gap: 6px; align-items: baseline; }
36
- .tasks .title { flex: 1; min-width: 0; padding: 0; border: 0; border-radius: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
37
- /* Clicked, a task reads whole, as it was typed. */
38
- .tasks li.whole .title { white-space: pre-wrap; overflow-wrap: anywhere; }
39
- /* The state is a dot, named by its tooltip: a ring while no one has it, filled once someone does or it's over. */
40
- .tasks .state { flex: none; align-self: center; box-sizing: border-box; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--deictic-muted); }
41
- /* Room for Edit and Delete, which would lie over the first line's end. */
42
- .tasks li.whole:has(.acts) .title { padding-right: 40px; }
43
- .tasks li.whole .state { align-self: baseline; }
44
- .tasks .state.waiting { border-style: dotted; }
45
- .tasks .state.claimed { border-color: #60a5fa; background: #60a5fa; }
46
- .tasks .state.blocked { border-color: #fbbf24; background: #fbbf24; }
47
- .tasks .state.completed { border-color: #4ade80; background: #4ade80; }
48
- .tasks .state.failed { border-color: var(--deictic-problem); background: var(--deictic-problem); }
49
- .tasks a { color: inherit; text-decoration: none; }
50
- .tasks a:hover { text-decoration: underline; }
51
- /* Over the row's end, and only while the row is pointed at or focused in: the title keeps the width. */
52
- .tasks .acts { position: absolute; inset: 0 0 auto auto; min-height: 18px; display: none; align-items: center; padding-left: 14px; background: linear-gradient(to right, transparent, var(--deictic-bg) 12px); }
53
- .tasks li:hover .acts, .tasks li:focus-within .acts { display: flex; }
54
- .tasks .act { display: inline-flex; padding: 2px; border: 0; color: var(--deictic-muted); }
55
- .tasks .act:hover { color: var(--deictic-fg); }
56
- .tasks .act svg { width: 12px; height: 12px; }
57
- .tasks .place { flex: none; padding: 0; border: 0; font: 11px ui-monospace, monospace; color: var(--deictic-muted); }
58
- .tasks button.place:hover { color: var(--deictic-fg); text-decoration: underline; }
59
- .more { margin: 0 0 8px; }
60
- .more[hidden] { display: none; }
61
- .more summary { cursor: pointer; font-size: 12px; color: var(--deictic-muted); }
62
- .more summary:hover { color: var(--deictic-fg); }
63
- .more .tasks { margin: 4px 0 0; }
64
- .tasks li.editing { display: grid; }
65
- .tasks li.editing .row { margin-top: 0; }
66
- .tasks li.editing .actions { display: flex; gap: 6px; }
67
- textarea { min-height: 64px; resize: vertical; font: 13px/1.4 system-ui, sans-serif; }
68
- .row { display: flex; gap: 6px; margin-top: 8px; justify-content: space-between; align-items: center; }
69
- /* Cut short before it pushes Add out: a channel's name and its watchers' may be long. */
70
- .hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--deictic-muted); font-size: 12px; }
71
- /* A dot as a task's state is: a ring while no one watches, green while someone does. */
72
- .watch::before { content: ''; display: inline-block; box-sizing: border-box; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; border: 1.5px solid var(--deictic-muted); }
73
- .watch.on::before { border-color: #4ade80; background: #4ade80; }
74
- .hint a { color: inherit; }
75
- .hint a:hover { color: var(--deictic-fg); }
76
- .shot { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--deictic-muted); }
77
- .shot label { display: flex; gap: 6px; align-items: center; }
78
- .shot input { width: auto; margin: 0; }
79
- .shot .actions { display: flex; gap: 6px; margin-left: auto; }
80
- .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; font-size: 12px; }
81
- .chip { display: inline-flex; align-items: center; border: 1px solid var(--deictic-line); border-radius: 6px; }
82
- .chip button { border: 0; }
83
- .chip .open { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 2px; }
84
- .chip img { display: block; height: 28px; border-radius: 4px; }
85
- .chip .play { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 4px; background: var(--deictic-line); }
26
+ /** Scoped to the composer: the drawer and the Task tab share the overlay's root, and a field of theirs is their own. */
27
+ const COMPOSER_STYLE = `
28
+ /* One box for what's attached, the words and the buttons, lit as a field is while it's typed in. */
29
+ .composer { border: 1px solid var(--deictic-line); border-radius: 12px; background: rgb(0 0 0 / 0.35); }
30
+ .composer:focus-within, .composer.dropping { border-color: var(--deictic-accent); box-shadow: 0 0 0 1px var(--deictic-accent); }
31
+ .composer textarea { display: block; box-sizing: border-box; width: 100%; min-height: 0; padding: 10px 12px 4px; border: 0; resize: none; background: none; font: 13px/1.45 system-ui, sans-serif; }
32
+ .composer textarea:focus { outline: none; }
33
+ .composer .chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; padding: 8px 8px 0; font-size: 12px; }
34
+ .composer .attach { display: flex; align-items: center; gap: 2px; padding: 4px 6px 6px; }
35
+ .composer .attach button.icon { width: 28px; height: 28px; border-radius: 8px; }
36
+ .composer .attach button.icon svg { width: 16px; height: 16px; }
37
+ .composer .attach button[aria-pressed='true'] { color: var(--deictic-accent); background: rgb(18 179 88 / 0.14); }
38
+ .composer .attach .gap { width: 1px; height: 16px; margin: 0 4px; background: var(--deictic-line); }
39
+ .composer .attach .mic[aria-pressed='true'], .composer .attach .mic[aria-pressed='true']:hover { color: #fff; background: #ef4444; }
40
+ .composer .hearing { display: inline-flex; align-items: center; gap: 6px; padding-left: 4px; font: 12px ui-monospace, monospace; color: var(--deictic-muted); }
41
+ .composer .hearing canvas { width: 56px; height: 18px; }
42
+ .composer .doing { margin-left: auto; padding-right: 6px; font-size: 12px; color: var(--deictic-muted); }
43
+ .composer .attach button.send { border-radius: 50%; color: var(--deictic-on-accent); }
44
+ .composer .attach button.send:hover:not(:disabled) { color: var(--deictic-on-accent); background: var(--deictic-accent); filter: brightness(1.1); }
45
+ .composer [hidden] { display: none; }
46
+ /* Every chip one height, and a picture's thumbnail one size whatever its shape or whether it has loaded yet: nothing
47
+ moves as one is attached, or as its picture comes. */
48
+ .chip { box-sizing: border-box; display: inline-flex; align-items: center; height: 30px; border: 1px solid var(--deictic-line); border-radius: 6px; }
49
+ .chip button { height: 100%; border: 0; }
50
+ .chip .open { display: inline-flex; align-items: center; gap: 6px; padding: 0 4px 0 2px; }
51
+ .chip img { display: block; width: 36px; height: 24px; object-fit: cover; border-radius: 4px; background: var(--deictic-line); }
52
+ .chip .play { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 4px; background: var(--deictic-line); }
86
53
  .chip .play svg { width: 12px; height: 12px; }
54
+ .chip .play.drawn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
87
55
  .chip .remove { padding: 0 6px; color: var(--deictic-muted); }
88
56
  .chip .remove:hover { color: var(--deictic-fg); }
89
- .voice-on { display: inline-flex; align-items: center; gap: 4px; color: #fff; background: #ef4444; border-color: #ef4444; font-variant-numeric: tabular-nums; }
90
- .voice-on .wave { width: 36px; height: 14px; }
91
- .shot-problem { margin-top: 4px; font-size: 12px; color: var(--deictic-problem); }
92
- .shot-problem:empty { display: none; }
93
- .shot[hidden], .chips[hidden], label[hidden] { display: none; }
57
+ /* An element the task is about: named as the caption names it, in the overlay's own green. */
58
+ .chip.about .open { padding: 0 4px 0 8px; font: 12px ui-monospace, monospace; color: var(--deictic-accent); }
59
+ .chip.about .open span { color: var(--deictic-muted); }
60
+ .compose .shot-problem { margin-top: 4px; font-size: 12px; color: var(--deictic-problem); }
61
+ .compose .shot-problem:empty { display: none; }
62
+ .compose .shot-note { margin-top: 4px; font-size: 12px; color: var(--deictic-muted); }
63
+ .compose .shot-note:empty { display: none; }
94
64
  `;
95
- const ICON = (path) => `<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="${path}"/></svg>`;
96
- const EDIT = ICON("M4 20h4L19 9l-4-4L4 16z");
97
- const DELETE = ICON("M4 7h16M10 7V4h4v3M6 7l1 13h10l1-13");
98
- /** The states of a task that's over, as a board names them: nothing more happens to it. */
99
- const OVER = /* @__PURE__ */ new Set(["completed", "failed"]);
100
65
  const PLAY = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M7 4v16l13-8z\" fill=\"currentColor\"/></svg>";
66
+ /** The composer's buttons, each its strokes on a 24-pixel grid. */
67
+ const CAMERA = "<path d=\"M4 8h3l2-3h6l2 3h3v11H4z\"/><circle cx=\"12\" cy=\"13\" r=\"3.5\"/>";
68
+ const CODE = "<path d=\"M8 7l-5 5 5 5M16 7l5 5-5 5M13.5 5l-3 14\"/>";
69
+ const PEN = "<path d=\"M4 20l1-4L16 5a2.1 2.1 0 0 1 3 3L8 19z\"/>";
70
+ const RECORD = "<circle cx=\"12\" cy=\"12\" r=\"8\"/><circle cx=\"12\" cy=\"12\" r=\"3\" fill=\"currentColor\"/>";
71
+ const MIC = "<rect x=\"9\" y=\"3\" width=\"6\" height=\"11\" rx=\"3\"/><path d=\"M5 11a7 7 0 0 0 14 0M12 18v3\"/>";
72
+ const SEND = "<path d=\"M12 19V5M6 11l6-6 6 6\"/>";
73
+ const TARGET = "<circle cx=\"12\" cy=\"12\" r=\"7\"/><path d=\"M12 2v4M12 18v4M2 12h4M18 12h4\"/>";
74
+ /** How tall the field grows with what's typed, in pixels, before it scrolls. */
75
+ const GROWN = 200;
76
+ /** The overlay's own green, as its ring on the element while the popup is open. */
77
+ const OUTLINE = "#12b358";
78
+ /** CSS pixels between the element and its outline, so the dashes are on nothing of the element's. */
79
+ const ROOM = 3;
80
+ /** How far around a spot its circle is drawn in a shot, in CSS pixels. */
81
+ const SPOT = 16;
82
+ /** The tray's kinds a composer attaches. */
83
+ const KINDS = [
84
+ "screenshots",
85
+ "recordings",
86
+ "voice"
87
+ ];
88
+ function element(tag, props = {}) {
89
+ return Object.assign(document.createElement(tag), props);
90
+ }
91
+ const atOf = ({ loc }) => `${loc.file}:${loc.line}:${loc.column}`;
92
+ const clock = (ms) => {
93
+ const s = Math.round(ms / 1e3);
94
+ return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
95
+ };
96
+ const messageOf = (e) => e instanceof Error ? e.message : String(e);
101
97
  /** Marks as a task tells of them: how many, and what the notes say. */
102
98
  function marksOf(list) {
103
99
  return {
@@ -105,16 +101,1603 @@ function marksOf(list) {
105
101
  notes: list.flatMap(({ shape }) => shape.kind === "note" ? [shape.text] : [])
106
102
  };
107
103
  }
108
- /** The page's annotations for the op, where there are any. */
104
+ /** The page's annotations, where there are any. */
109
105
  function annotationsOf(marks) {
110
106
  const list = marks?.list() ?? [];
111
- return list.length === 0 ? {} : { annotations: marksOf(list) };
107
+ return list.length === 0 ? void 0 : marksOf(list);
108
+ }
109
+ const onPage = (a) => a?.el?.isConnected === true ? a.el : void 0;
110
+ /** What's attached, as a task's op or a reply sends it: each shot, each recording with where it replays, each voice note, the marks. */
111
+ function attachedOf({ screenshots, recordings, voices, annotations }) {
112
+ return {
113
+ ...screenshots === void 0 ? {} : { screenshots: screenshots.map(({ url: _, ...shot }) => shot) },
114
+ ...recordings.length === 0 ? {} : { recordings: recordings.map(({ id, duration, url, voice: clips }) => ({
115
+ id,
116
+ duration,
117
+ replay: new URL(url, location.href).href,
118
+ ...clips === void 0 ? {} : { voice: clips.map((c) => c.id) }
119
+ })) },
120
+ ...voices.length === 0 ? {} : { voice: voices.map(({ id, duration }) => ({
121
+ id,
122
+ duration
123
+ })) },
124
+ ...annotations === void 0 ? {} : { annotations }
125
+ };
112
126
  }
113
- const clock = (ms) => {
114
- const s = Math.round(ms / 1e3);
115
- return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
116
- };
117
- const messageOf = (e) => e instanceof Error ? e.message : String(e);
127
+ /**
128
+ * A shot's PNG with what the task is about outlined in it: dashes around each box, with nothing between them, and a
129
+ * circle around `spot`. The shot may have more pixels than its size in CSS ones, which the boxes are in.
130
+ */
131
+ async function outlined(png, size, boxes, spot) {
132
+ const image = new Image();
133
+ image.src = png;
134
+ await image.decode();
135
+ const canvas = element("canvas", {
136
+ width: image.naturalWidth,
137
+ height: image.naturalHeight
138
+ });
139
+ const ctx = canvas.getContext("2d");
140
+ if (ctx === null) throw new Error("tasks: this browser won't draw to a canvas");
141
+ ctx.drawImage(image, 0, 0);
142
+ const k = image.naturalWidth / size.width;
143
+ ctx.lineWidth = 2 * k;
144
+ ctx.strokeStyle = OUTLINE;
145
+ ctx.setLineDash([6 * k, 4 * k]);
146
+ for (const box of boxes) ctx.strokeRect((box.x - ROOM) * k, (box.y - ROOM) * k, (box.width + 6) * k, (box.height + 6) * k);
147
+ if (spot !== void 0) {
148
+ ctx.beginPath();
149
+ ctx.arc(spot.x * k, spot.y * k, SPOT * k, 0, 2 * Math.PI);
150
+ ctx.stroke();
151
+ }
152
+ return await new Promise((done, fail) => canvas.toBlob((blob) => blob === null ? fail(/* @__PURE__ */ new Error("tasks: the screenshot drew nothing")) : done(blob), "image/png"));
153
+ }
154
+ /** A picture as a PNG, and its size: the screenshots plugin keeps PNGs, and a pasted one may be a JPEG or a GIF. */
155
+ async function pngOf(picture) {
156
+ const url = URL.createObjectURL(picture);
157
+ try {
158
+ const image = new Image();
159
+ image.src = url;
160
+ await image.decode();
161
+ const { naturalWidth: width, naturalHeight: height } = image;
162
+ if (picture.type === "image/png") return {
163
+ png: picture,
164
+ width,
165
+ height
166
+ };
167
+ const canvas = element("canvas", {
168
+ width,
169
+ height
170
+ });
171
+ const ctx = canvas.getContext("2d");
172
+ if (ctx === null) throw new Error("tasks: this browser won't draw to a canvas");
173
+ ctx.drawImage(image, 0, 0);
174
+ return {
175
+ png: await new Promise((done, fail) => canvas.toBlob((blob) => blob === null ? fail(/* @__PURE__ */ new Error("tasks: the picture drew nothing")) : done(blob), "image/png")),
176
+ width,
177
+ height
178
+ };
179
+ } finally {
180
+ URL.revokeObjectURL(url);
181
+ }
182
+ }
183
+ function composerIn(context, options) {
184
+ const shots = context.use("screenshots");
185
+ const notes = context.use("annotations");
186
+ const recorder = context.use("recordings");
187
+ const voice = context.use("voice");
188
+ const { tray } = context;
189
+ const here = options.here ?? true;
190
+ const withElements = options.about !== void 0;
191
+ let about = options.about?.() ?? [];
192
+ let wanted;
193
+ const shooting = () => shots !== void 0 && here && (wanted ?? (options.shoot === true && attachedCount() === 0));
194
+ let withHtml = true;
195
+ const text = element("textarea", {
196
+ placeholder: options.placeholder,
197
+ rows: 1
198
+ });
199
+ const chipsEl = element("div", { className: "chips" });
200
+ const camera = toolButton(CAMERA, `Attach a screenshot, taken as it's sent`, void 0, () => {
201
+ wanted = !shooting();
202
+ showChips();
203
+ });
204
+ camera.hidden = shots === void 0 || !here;
205
+ const code = toolButton(CODE, "Attach an HTML snapshot: the element as the page has it now, as a file", void 0, () => {
206
+ withHtml = !withHtml;
207
+ showChips();
208
+ });
209
+ code.hidden = !withElements || options.html === false;
210
+ const picker = toolButton(TARGET, "Attach another element: press it on the page", void 0, () => void pick());
211
+ picker.setAttribute("aria-pressed", "false");
212
+ picker.hidden = !withElements || !options.over;
213
+ const pen = toolButton(PEN, "Draw on a screenshot", void 0, () => void draw());
214
+ pen.hidden = shots === void 0 || notes === void 0 || !here;
215
+ const record = toolButton(RECORD, "Record the page", void 0, () => {
216
+ if (!sending) options.record?.();
217
+ });
218
+ record.hidden = recorder === void 0 || options.record === void 0;
219
+ const mic = toolButton(MIC, "Record your voice", void 0, () => void (take === void 0 ? speakOn() : speakOff()));
220
+ mic.classList.add("mic");
221
+ mic.hidden = voice === void 0;
222
+ const gap = element("span", {
223
+ className: "gap",
224
+ hidden: camera.hidden && code.hidden || picker.hidden && pen.hidden && record.hidden && mic.hidden
225
+ });
226
+ const time = element("span");
227
+ const wave = element("canvas");
228
+ const hearing = element("span", {
229
+ className: "hearing",
230
+ hidden: true
231
+ });
232
+ hearing.append(time, wave);
233
+ const doing = element("span", { className: "doing" });
234
+ const send = toolButton(SEND, options.sendLabel, "Enter", () => void sendIt());
235
+ send.classList.add("send", "primary");
236
+ const attach = element("div", { className: "attach" });
237
+ attach.append(camera, code, gap, picker, pen, record, mic, hearing, doing, send);
238
+ const box = element("div", { className: "composer" });
239
+ box.append(chipsEl, text, attach);
240
+ const problem = element("div", { className: "shot-problem" });
241
+ const note = element("div", { className: "shot-note" });
242
+ const el = element("div", { className: "compose" });
243
+ el.append(box, problem, note);
244
+ const grow = () => {
245
+ text.style.height = "auto";
246
+ text.style.height = `${Math.min(text.scrollHeight, GROWN)}px`;
247
+ };
248
+ const inTray = (plugin) => tray.list(plugin).map((item) => item.value);
249
+ const taken = () => ({
250
+ pictures: inTray("screenshots"),
251
+ recordings: inTray("recordings"),
252
+ voices: inTray("voice")
253
+ });
254
+ const attachedCount = () => KINDS.reduce((n, plugin) => n + tray.list(plugin).length, 0);
255
+ let sending = false;
256
+ let take;
257
+ const able = () => send.disabled = sending || text.value.trim() === "" && attachedCount() === 0 && take === void 0;
258
+ const changed = () => options.changed?.();
259
+ const chip = (content, title, at, remove, drop) => {
260
+ const opener = element("button", {
261
+ type: "button",
262
+ className: "open",
263
+ title
264
+ });
265
+ opener.append(...content);
266
+ opener.addEventListener("click", () => context.lightbox(viewed(), {
267
+ at,
268
+ from: it
269
+ }));
270
+ const remover = element("button", {
271
+ type: "button",
272
+ className: "remove",
273
+ textContent: "×",
274
+ title: remove
275
+ });
276
+ remover.addEventListener("click", drop);
277
+ const it = element("span", { className: "chip" });
278
+ it.append(opener, remover);
279
+ return it;
280
+ };
281
+ const numbered = (name, i, of) => of === 1 ? name : `${name} ${i + 1}`;
282
+ /** What's attached, as the lightbox shows it, in the chips' order. */
283
+ const viewed = () => {
284
+ const { pictures, recordings, voices } = taken();
285
+ return [
286
+ ...pictures.map((s, i) => ({
287
+ kind: "image",
288
+ url: s.url,
289
+ title: numbered("Screenshot", i, pictures.length),
290
+ ...s.drawn === void 0 ? {} : { actions: [s.drawn.marks.length === 0 ? {
291
+ label: "Draw on it",
292
+ title: "Draw boxes, arrows and notes on it",
293
+ run: () => void draw(s)
294
+ } : {
295
+ label: "Change marks",
296
+ title: "Draw on it again",
297
+ run: () => void draw(s)
298
+ }] }
299
+ })),
300
+ ...recordings.map((r, i) => ({
301
+ kind: "page",
302
+ url: `${r.url}${r.url.includes("?") ? "&" : "?"}embed`,
303
+ title: `${numbered("Recording", i, recordings.length)} · ${clock(r.duration)}`,
304
+ actions: [{
305
+ label: "New tab",
306
+ title: "Play it back in a tab of its own",
307
+ run: () => void window.open(r.url, "_blank", "noopener")
308
+ }]
309
+ })),
310
+ ...voices.map((v, i) => ({
311
+ kind: "audio",
312
+ url: v.url,
313
+ title: `${numbered("Voice", i, voices.length)} · ${clock(v.duration)}`
314
+ }))
315
+ ];
316
+ };
317
+ /** Takes one out of the tray. A shot that was the last thing attached leaves none asked for: taking it out said so. */
318
+ const drop = (plugin, id) => () => {
319
+ tray.remove(plugin, id);
320
+ if (plugin === "screenshots" && attachedCount() === 0) wanted = false;
321
+ showChips();
322
+ };
323
+ /** An element the task is about: named as the caption names it, with its place for a tip. Its chip shows it, and its × leaves it out. */
324
+ const aboutChip = (a) => {
325
+ const it = onPage(a);
326
+ const { file, line } = a.target.loc;
327
+ const { component, sole, tag } = it === void 0 ? {
328
+ component: void 0,
329
+ sole: false,
330
+ tag: a.target.tag
331
+ } : named(it);
332
+ const opener = element("button", {
333
+ type: "button",
334
+ className: "open",
335
+ title: `${file}:${line}`
336
+ });
337
+ opener.append(`<${component ?? tag}>`, ...component === void 0 || sole ? [] : [element("span", { textContent: ` <${tag}>` })]);
338
+ opener.addEventListener("click", () => it?.scrollIntoView({
339
+ block: "nearest",
340
+ behavior: "smooth"
341
+ }));
342
+ const remover = element("button", {
343
+ type: "button",
344
+ className: "remove",
345
+ textContent: "×",
346
+ title: `Leave ${it === void 0 ? `<${tag}>` : tell(named(it))} out`
347
+ });
348
+ remover.addEventListener("click", () => {
349
+ about = about.filter((x) => x !== a);
350
+ showChips();
351
+ });
352
+ const chipEl = element("span", { className: "chip about" });
353
+ chipEl.append(opener, remover);
354
+ return chipEl;
355
+ };
356
+ /** What's drawn on the page, which goes with it: its chip draws more, and its × clears it. */
357
+ const marksChip = (marked) => {
358
+ const opener = element("button", {
359
+ type: "button",
360
+ className: "open",
361
+ title: "Draw more on the page"
362
+ });
363
+ const icon = element("span", {
364
+ className: "play drawn",
365
+ innerHTML: `<svg viewBox="0 0 24 24" aria-hidden="true">${PEN}</svg>`
366
+ });
367
+ opener.append(icon, `${marked} mark${marked === 1 ? "" : "s"}`);
368
+ opener.addEventListener("click", () => notes?.draw());
369
+ const remover = element("button", {
370
+ type: "button",
371
+ className: "remove",
372
+ textContent: "×",
373
+ title: "Clear the marks"
374
+ });
375
+ remover.addEventListener("click", () => notes?.clear());
376
+ const it = element("span", { className: "chip" });
377
+ it.append(opener, remover);
378
+ return it;
379
+ };
380
+ const showChips = () => {
381
+ const { pictures, recordings, voices } = taken();
382
+ const marked = notes?.list().length ?? 0;
383
+ camera.setAttribute("aria-pressed", String(shooting()));
384
+ code.setAttribute("aria-pressed", String(withHtml));
385
+ chipsEl.hidden = about.length === 0 && attachedCount() === 0 && marked === 0;
386
+ chipsEl.replaceChildren(...about.map(aboutChip), ...pictures.map((s, i) => {
387
+ const name = numbered("Screenshot", i, pictures.length);
388
+ const thumb = element("img", {
389
+ src: s.url,
390
+ alt: ""
391
+ });
392
+ return chip([thumb, name], `Open ${name.toLowerCase()}`, i, `Remove ${name.toLowerCase()}`, drop("screenshots", s.id));
393
+ }), ...recordings.map((r, i) => {
394
+ const name = numbered("Recording", i, recordings.length);
395
+ const play = element("span", {
396
+ className: "play",
397
+ innerHTML: PLAY
398
+ });
399
+ return chip([play, `${name} ${clock(r.duration)}${r.voice === void 0 ? "" : " · voice"}`], `Play ${name.toLowerCase()} back`, pictures.length + i, `Remove ${name.toLowerCase()}`, drop("recordings", r.id));
400
+ }), ...voices.map((v, i) => {
401
+ const name = numbered("Voice", i, voices.length);
402
+ const play = element("span", {
403
+ className: "play",
404
+ innerHTML: PLAY
405
+ });
406
+ return chip([play, `${name} ${clock(v.duration)}`], `Play ${name.toLowerCase()}`, pictures.length + recordings.length + i, `Remove ${name.toLowerCase()}`, drop("voice", v.id));
407
+ }), ...marked === 0 ? [] : [marksChip(marked)]);
408
+ able();
409
+ };
410
+ const unsubscribe = [tray.subscribe(showChips), notes?.subscribe(showChips)];
411
+ let picking = false;
412
+ const pick = async () => {
413
+ if (picking) return;
414
+ picking = true;
415
+ picker.setAttribute("aria-pressed", "true");
416
+ const spot = await context.tools.pick();
417
+ picking = false;
418
+ picker.setAttribute("aria-pressed", "false");
419
+ const target = spot === void 0 ? void 0 : targetOf(spot.element);
420
+ if (spot === void 0 || target === void 0) return;
421
+ const r = spot.element.getBoundingClientRect();
422
+ if (spot.at.x < 0 || spot.at.y < 0 || spot.at.x > r.width || spot.at.y > r.height) return;
423
+ if (about.some((a) => a.el === spot.element)) return;
424
+ about = [...about, {
425
+ target,
426
+ own: false,
427
+ el: spot.element
428
+ }];
429
+ showChips();
430
+ };
431
+ const outlines = withElements && options.over ? element("div") : void 0;
432
+ if (outlines !== void 0) context.root.append(outlines);
433
+ let following = 0;
434
+ const follow = () => {
435
+ following = requestAnimationFrame(follow);
436
+ if (outlines === void 0) return;
437
+ const others = about.flatMap((a) => a.own || onPage(a) === void 0 ? [] : [onPage(a)]);
438
+ while (outlines.childElementCount > others.length) outlines.lastElementChild.remove();
439
+ while (outlines.childElementCount < others.length) outlines.append(element("div", { className: "task-about" }));
440
+ for (const [i, it] of others.entries()) place(outlines.children[i], it.getBoundingClientRect());
441
+ };
442
+ if (outlines !== void 0) follow();
443
+ const firstAt = () => about[0] === void 0 ? "" : atOf(about[0].target);
444
+ const aborts = new AbortController();
445
+ let drawing = false;
446
+ const draw = async (old) => {
447
+ if (shots === void 0 || notes === void 0 || drawing || sending) return;
448
+ drawing = true;
449
+ problem.textContent = "";
450
+ try {
451
+ if (old === void 0) doing.textContent = "Capturing…";
452
+ const shot = old?.drawn?.shot ?? await shots.capture(onPage(about[0]) ?? document.documentElement);
453
+ doing.textContent = "";
454
+ const picture = {
455
+ url: shot.url,
456
+ ...shot.size
457
+ };
458
+ const marks = await notes.edit(picture, old?.drawn?.marks ?? [], { signal: aborts.signal });
459
+ if (marks === void 0) return;
460
+ doing.textContent = "Saving…";
461
+ const kept = await shots.upload(await notes.flatten(picture, marks), shot);
462
+ if (old !== void 0) tray.remove("screenshots", old.id);
463
+ const pictured = {
464
+ ...kept,
465
+ drawn: {
466
+ shot,
467
+ marks,
468
+ about: old?.drawn?.about ?? firstAt()
469
+ }
470
+ };
471
+ tray.add("screenshots", kept.id, pictured);
472
+ } catch (e) {
473
+ problem.textContent = messageOf(e);
474
+ } finally {
475
+ doing.textContent = "";
476
+ drawing = false;
477
+ text.focus();
478
+ }
479
+ };
480
+ /**
481
+ * Pictures pasted in or dropped on it: each kept as a shot of its own (a PNG, as the screenshots plugin keeps them)
482
+ * and put in the tray, so it's a chip as any other is, to draw on. Anything else is said, not attached.
483
+ */
484
+ const paste = async (files) => {
485
+ const pictures = files.filter((file) => file.type.startsWith("image/"));
486
+ const others = files.length - pictures.length;
487
+ problem.textContent = "";
488
+ if (pictures.length > 0 && shots === void 0) problem.textContent = "Attaching a picture needs the screenshots plugin: add it to deictic";
489
+ else if (others > 0) problem.textContent = `Only pictures can be attached here: ${others === 1 ? "that file was" : `${others} files were`} left out`;
490
+ if (shots === void 0 || pictures.length === 0) return;
491
+ doing.textContent = "Attaching…";
492
+ try {
493
+ for (const picture of pictures) {
494
+ const { png, width, height } = await pngOf(picture);
495
+ const size = {
496
+ width,
497
+ height
498
+ };
499
+ const kept = await shots.upload(png, {
500
+ box: {
501
+ x: 0,
502
+ y: 0,
503
+ ...size
504
+ },
505
+ size
506
+ });
507
+ const pictured = {
508
+ ...kept,
509
+ drawn: {
510
+ shot: kept,
511
+ marks: [],
512
+ about: ""
513
+ }
514
+ };
515
+ tray.add("screenshots", kept.id, pictured);
516
+ }
517
+ } catch (e) {
518
+ problem.textContent = messageOf(e);
519
+ } finally {
520
+ doing.textContent = "";
521
+ }
522
+ };
523
+ box.addEventListener("paste", (e) => {
524
+ const files = [...e.clipboardData?.files ?? []];
525
+ if (files.length === 0) return;
526
+ e.preventDefault();
527
+ paste(files);
528
+ });
529
+ box.addEventListener("dragover", (e) => {
530
+ if (!e.dataTransfer?.types.includes("Files")) return;
531
+ e.preventDefault();
532
+ box.classList.add("dropping");
533
+ });
534
+ box.addEventListener("dragleave", () => box.classList.remove("dropping"));
535
+ box.addEventListener("drop", (e) => {
536
+ box.classList.remove("dropping");
537
+ const files = [...e.dataTransfer?.files ?? []];
538
+ if (files.length === 0) return;
539
+ e.preventDefault();
540
+ paste(files);
541
+ });
542
+ let ticking;
543
+ let stopWave;
544
+ const speakOn = async () => {
545
+ if (voice === void 0) return;
546
+ problem.textContent = "";
547
+ mic.disabled = true;
548
+ try {
549
+ take = await voice.start();
550
+ } catch (e) {
551
+ problem.textContent = messageOf(e);
552
+ return;
553
+ } finally {
554
+ mic.disabled = false;
555
+ }
556
+ const { started, stream } = take;
557
+ stopWave = liveWaveform(wave, stream, {
558
+ played: "#ef4444",
559
+ rest: "#52525b"
560
+ });
561
+ const tick = () => time.textContent = clock(Date.now() - started);
562
+ tick();
563
+ ticking = setInterval(tick, 250);
564
+ hearing.hidden = false;
565
+ mic.setAttribute("aria-pressed", "true");
566
+ mic.title = "Stop, and attach it";
567
+ able();
568
+ changed();
569
+ };
570
+ const speakOff = async () => {
571
+ const ending = take;
572
+ if (ending === void 0) return;
573
+ take = void 0;
574
+ clearInterval(ticking);
575
+ stopWave?.();
576
+ stopWave = void 0;
577
+ hearing.hidden = true;
578
+ mic.setAttribute("aria-pressed", "false");
579
+ mic.title = "Record your voice";
580
+ try {
581
+ const clip = await ending.stop();
582
+ tray.add("voice", clip.id, clip);
583
+ } catch (e) {
584
+ problem.textContent = messageOf(e);
585
+ }
586
+ able();
587
+ changed();
588
+ };
589
+ /**
590
+ * The shots to attach: one taken now, where that's on, and those in the tray, each the window as it was taken.
591
+ * Only the first has the elements outlined in it, and its spot circled (or is as it was taken, where that can't be
592
+ * drawn), so it's first: nothing else in a shot says what it's about.
593
+ */
594
+ const screenshotsOf = async () => {
595
+ if (shots === void 0) return void 0;
596
+ const kept = taken().pictures.map(({ id, url, drawn }) => ({
597
+ id,
598
+ url,
599
+ ...drawn !== void 0 && drawn.about !== "" && drawn.about === firstAt() ? { box: drawn.shot.box } : {},
600
+ ...drawn === void 0 || drawn.marks.length === 0 ? {} : { marks: marksOf(drawn.marks) }
601
+ }));
602
+ if (!shooting()) return kept.length === 0 ? void 0 : kept;
603
+ doing.textContent = "Capturing…";
604
+ const first = onPage(about[0]);
605
+ const of = first ?? document.documentElement;
606
+ const now = await shots.capture(of);
607
+ const where = first === void 0 ? {} : { box: now.box };
608
+ const live = of.getBoundingClientRect();
609
+ const boxes = about.flatMap((a) => {
610
+ const it = onPage(a);
611
+ if (it === void 0) return [];
612
+ if (it === first) return a.own && options.at !== void 0 ? [] : [now.box];
613
+ const r = it.getBoundingClientRect();
614
+ return [{
615
+ x: r.left + now.box.x - live.left,
616
+ y: r.top + now.box.y - live.top,
617
+ width: r.width,
618
+ height: r.height
619
+ }];
620
+ });
621
+ const spot = first !== void 0 && about[0]?.own === true ? options.at : void 0;
622
+ const circled = spot === void 0 ? void 0 : {
623
+ x: now.box.x + spot.x,
624
+ y: now.box.y + spot.y
625
+ };
626
+ if (boxes.length === 0 && circled === void 0) return [{
627
+ id: now.id,
628
+ url: now.url
629
+ }, ...kept];
630
+ try {
631
+ const { id, url } = await shots.upload(await outlined(now.url, now.size, boxes, circled), now);
632
+ return [{
633
+ id,
634
+ url,
635
+ ...where,
636
+ outlined: true
637
+ }, ...kept];
638
+ } catch {
639
+ return [{
640
+ id: now.id,
641
+ url: now.url,
642
+ ...where
643
+ }, ...kept];
644
+ }
645
+ };
646
+ const sendIt = async () => {
647
+ if (sending) return;
648
+ sending = true;
649
+ await speakOff();
650
+ if (text.value.trim() === "" && attachedCount() === 0) {
651
+ sending = false;
652
+ able();
653
+ return;
654
+ }
655
+ able();
656
+ problem.textContent = "";
657
+ note.textContent = "";
658
+ let screenshots;
659
+ try {
660
+ screenshots = await screenshotsOf();
661
+ } catch (e) {
662
+ problem.textContent = messageOf(e);
663
+ doing.textContent = "";
664
+ sending = false;
665
+ able();
666
+ return;
667
+ }
668
+ doing.textContent = "";
669
+ const { recordings, voices } = taken();
670
+ const annotations = annotationsOf(notes);
671
+ let done = false;
672
+ try {
673
+ done = await options.submit({
674
+ text: text.value,
675
+ about,
676
+ html: withHtml,
677
+ ...screenshots === void 0 ? {} : { screenshots },
678
+ recordings,
679
+ voices,
680
+ ...annotations === void 0 ? {} : { annotations }
681
+ });
682
+ } catch (e) {
683
+ problem.textContent = messageOf(e);
684
+ }
685
+ if (done) {
686
+ text.value = "";
687
+ grow();
688
+ for (const plugin of KINDS) tray.remove(plugin);
689
+ notes?.clear();
690
+ wanted = void 0;
691
+ about = options.about?.() ?? [];
692
+ showChips();
693
+ changed();
694
+ }
695
+ sending = false;
696
+ able();
697
+ };
698
+ text.addEventListener("input", () => {
699
+ grow();
700
+ able();
701
+ changed();
702
+ });
703
+ text.addEventListener("keydown", (e) => {
704
+ if (e.key !== "Enter" || e.shiftKey || e.isComposing) return;
705
+ e.preventDefault();
706
+ sendIt();
707
+ });
708
+ showChips();
709
+ requestAnimationFrame(grow);
710
+ return {
711
+ el,
712
+ send,
713
+ problem,
714
+ note,
715
+ pending: () => text.value.trim() !== "" || take !== void 0,
716
+ draft: () => ({
717
+ text: text.value,
718
+ ...wanted === void 0 ? {} : { shot: wanted },
719
+ html: withHtml,
720
+ about
721
+ }),
722
+ restore: (draft) => {
723
+ if (draft.text !== void 0) text.value = draft.text;
724
+ if (draft.shot !== void 0) wanted = draft.shot;
725
+ if (draft.html !== void 0) withHtml = draft.html;
726
+ if (draft.about !== void 0) about = draft.about;
727
+ showChips();
728
+ grow();
729
+ },
730
+ stopTake: speakOff,
731
+ focus: () => text.focus(),
732
+ destroy: () => {
733
+ for (const stop of unsubscribe) stop?.();
734
+ aborts.abort();
735
+ cancelAnimationFrame(following);
736
+ outlines?.remove();
737
+ speakOff();
738
+ }
739
+ };
740
+ }
741
+ // src/plugins/tasks/store.ts
742
+ /** How long the tasks read last are shown as they are, in ms: the keys are held again and again, and each is no reason to ask the board. */
743
+ const FRESH = 4e3;
744
+ /** Where what's been read is kept: each task's ID, and how its thread stood when it was last opened. */
745
+ const SEEN = "deictic:tasks:seen";
746
+ /** Where the finished tasks put away are kept: each one's ID, and how its thread stood then. */
747
+ const ARCHIVED = "deictic:tasks:archived";
748
+ /** The states of a finished task, as a board names them: nothing more happens to it. */
749
+ const OVER = /* @__PURE__ */ new Set(["completed", "failed"]);
750
+ /** The states whose coming is news in itself, whoever said nothing as it came. */
751
+ const NEWS = /* @__PURE__ */ new Set([
752
+ "blocked",
753
+ "completed",
754
+ "failed"
755
+ ]);
756
+ /** How a task's thread stands: its newest reply, and its state where that's news. */
757
+ const markOf = (task) => `${task.last ?? ""}|${NEWS.has(task.state) ? task.state : ""}`;
758
+ /** What's kept under `key` (what's been read, what's put away), or nothing where this browser has kept none yet. */
759
+ function kept(key = SEEN) {
760
+ try {
761
+ const seen = JSON.parse(localStorage.getItem(key) ?? "null");
762
+ return typeof seen === "object" && seen !== null ? seen : void 0;
763
+ } catch {
764
+ return;
765
+ }
766
+ }
767
+ const made$2 = /* @__PURE__ */ new WeakMap();
768
+ /** The tasks of the overlay `context` is of: one store, whoever asks. */
769
+ function storeOf(context) {
770
+ const known = made$2.get(context.root);
771
+ if (known !== void 0) return known;
772
+ let tasks = [];
773
+ let channel;
774
+ let read = 0;
775
+ let asked = 0;
776
+ let seen = kept();
777
+ const listeners = /* @__PURE__ */ new Set();
778
+ const tell = () => {
779
+ for (const listener of listeners) listener();
780
+ };
781
+ let away = kept(ARCHIVED) ?? {};
782
+ const keep = (key = SEEN, value = seen) => {
783
+ try {
784
+ localStorage.setItem(key, JSON.stringify(value));
785
+ } catch {}
786
+ };
787
+ const store = {
788
+ tasks: () => tasks,
789
+ channel: () => channel,
790
+ load: (again = false) => {
791
+ if (!again && Date.now() - read < FRESH) return;
792
+ const ask = ++asked;
793
+ read = Date.now();
794
+ context.request("page").then(async (res) => {
795
+ if (!res.ok || ask !== asked) return;
796
+ const answer = await res.json();
797
+ ({tasks} = answer);
798
+ if (seen === void 0) {
799
+ seen = Object.fromEntries(tasks.map((task) => [task.id, markOf(task)]));
800
+ keep();
801
+ }
802
+ if (answer.channel !== void 0) channel = {
803
+ name: answer.channel,
804
+ ...answer.link === void 0 ? {} : { link: answer.link }
805
+ };
806
+ tell();
807
+ }).catch(() => {});
808
+ },
809
+ subscribe: (listener) => {
810
+ listeners.add(listener);
811
+ return () => listeners.delete(listener);
812
+ },
813
+ unread: (task) => seen !== void 0 && markOf(task) !== "|" && seen[task.id] !== markOf(task),
814
+ read: (task) => seen?.[task.id]?.split("|", 1)[0] || void 0,
815
+ seen: (task) => {
816
+ if (seen?.[task.id] === markOf(task)) return;
817
+ seen = {
818
+ ...seen,
819
+ ...kept(),
820
+ [task.id]: markOf(task)
821
+ };
822
+ keep();
823
+ tell();
824
+ },
825
+ archived: (task) => OVER.has(task.state) && away[task.id] === markOf(task),
826
+ archive: (finished) => {
827
+ const marks = Object.fromEntries(finished.filter((task) => OVER.has(task.state)).map((task) => [task.id, markOf(task)]));
828
+ const listed = new Set(tasks.map((task) => task.id));
829
+ away = Object.fromEntries(Object.entries({
830
+ ...away,
831
+ ...kept(ARCHIVED),
832
+ ...marks
833
+ }).filter(([id]) => listed.has(id)));
834
+ keep(ARCHIVED, away);
835
+ seen = {
836
+ ...seen,
837
+ ...kept(),
838
+ ...marks
839
+ };
840
+ keep();
841
+ tell();
842
+ }
843
+ };
844
+ made$2.set(context.root, store);
845
+ return store;
846
+ }
847
+ // src/plugins/tasks/which.ts
848
+ /**
849
+ * Which element a task is about, where one place in the source renders several (a list's items, a `map`): the mark
850
+ * alone finds the first of them, so a task keeps its place among them and its text, and is found again by those.
851
+ */
852
+ /** As much of an element's text as tells it from its siblings, and as a label holds. */
853
+ const SAID = 120;
854
+ const textOf = (el) => (el.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, SAID);
855
+ /** Which of `alike` (the elements with its mark, in the page's order) `el` is; its text as `said` has it, which may be masked. */
856
+ function whichOf(el, alike, said = el) {
857
+ const text = textOf(said);
858
+ return {
859
+ nth: alike.indexOf(el) + 1,
860
+ ...text === "" ? {} : { text }
861
+ };
862
+ }
863
+ /**
864
+ * The element a task is about on this page: the only one with its mark, or the one of several with its text, else the
865
+ * one at its place among them. None where it was one of more than the page has now and its text is on none of them.
866
+ */
867
+ function elementOf(task) {
868
+ if (task.place === void 0) return null;
869
+ const alike = [...document.querySelectorAll(`[${ATTRIBUTE}="${CSS.escape(task.place)}"]`)];
870
+ const { which } = task;
871
+ if (which === void 0 || alike.length <= 1) return alike[0] ?? null;
872
+ const at = alike[which.nth - 1];
873
+ const said = which.text === void 0 ? [] : alike.filter((el) => textOf(el) === which.text);
874
+ if (said.length > 0) return at !== void 0 && said.includes(at) ? at : said[0];
875
+ return at ?? null;
876
+ }
877
+ // src/plugins/tasks/drawer.ts
878
+ /**
879
+ * The tasks' section of the drawer: the channel's tasks still to do, each with its state, and the latest finished
880
+ * folded under them, those put away (archived) left out. One with something unread (a reply since it was last opened
881
+ * here, or an end no one looked at) says so, and a row the pointer is on lights its element on the page. A task opens
882
+ * in the drawer: its words, to change while no one has it, what it has attached, its thread, read as it's opened and
883
+ * again every few seconds, a composer to answer in (as the Task tab's, with what a reply can attach), and Delete,
884
+ * which cancels it on the board.
885
+ */
886
+ const STYLE$2 = `
887
+ .tasks-drawer h3 .unread { padding: 0 6px; border-radius: 8px; font-weight: 700; letter-spacing: 0; color: var(--deictic-on-accent); background: var(--deictic-accent); }
888
+ .tasks-drawer h3 a { margin-left: auto; font-weight: 400; letter-spacing: 0; text-transform: none; color: inherit; }
889
+ .tasks-drawer h3 a:hover { color: var(--deictic-fg); }
890
+ .task-row { display: grid; grid-template: 'state title mark' auto 'state meta mark' auto / auto minmax(0, 1fr) auto; gap: 1px 8px; align-items: center;
891
+ width: 100%; padding: 6px 8px; border: 1px solid rgb(255 255 255 / 0.08); border-radius: 8px; text-align: left; font-size: 12px; background: rgb(255 255 255 / 0.04); }
892
+ .task-row:hover { border-color: rgb(255 255 255 / 0.16); background: rgb(255 255 255 / 0.06); }
893
+ .task-row .title { grid-area: title; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
894
+ .task-row .meta { grid-area: meta; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--deictic-muted); }
895
+ .task-row.unread .title { font-weight: 600; }
896
+ /* What's unread is a dot of the overlay's own green, where a read one has nothing. */
897
+ .task-row .mark { grid-area: mark; width: 7px; height: 7px; border-radius: 50%; }
898
+ .task-row.unread .mark { background: var(--deictic-accent); box-shadow: 0 0 8px var(--deictic-accent); }
899
+ /* The state is a dot, as a board's is: a ring while no one has it, filled once someone does or it's finished. */
900
+ .task-state { grid-area: state; flex: none; box-sizing: border-box; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--deictic-muted); }
901
+ .task-state.waiting { border-style: dotted; }
902
+ .task-state.claimed { border-color: #60a5fa; background: #60a5fa; }
903
+ .task-state.blocked { border-color: #fbbf24; background: #fbbf24; }
904
+ .task-state.completed { border-color: #4ade80; background: #4ade80; }
905
+ .task-state.failed { border-color: var(--deictic-problem); background: var(--deictic-problem); }
906
+ .tasks-drawer details { margin-top: 6px; }
907
+ .tasks-drawer summary { cursor: pointer; font-size: 12px; color: var(--deictic-muted); }
908
+ .tasks-drawer summary:hover { color: var(--deictic-fg); }
909
+ .tasks-drawer details .drawer-rows { margin-top: 6px; }
910
+ .tasks-drawer .put-away { justify-self: end; }
911
+ .tasks-drawer .act, .task-view .act { padding: 1px 6px; border: 0; font-size: 12px; color: var(--deictic-muted); }
912
+ .tasks-drawer .act:hover, .task-view .act:hover { color: var(--deictic-fg); }
913
+ .task-view { display: flex; flex-direction: column; gap: 8px; min-height: 0; font-size: 12px; }
914
+ .task-view .stands { display: flex; align-items: center; gap: 6px; color: var(--deictic-muted); }
915
+ .task-view .stands .says { flex: 1; }
916
+ .task-view .stands a { color: inherit; }
917
+ .task-view .stands a:hover { color: var(--deictic-fg); }
918
+ .task-view .act.sure { color: var(--deictic-problem); }
919
+ .task-view .where { align-self: start; max-width: 100%; padding: 0; border: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 11px ui-monospace, monospace; color: var(--deictic-accent); }
920
+ .task-view .where span { color: var(--deictic-muted); }
921
+ .task-view .words { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; }
922
+ .task-view .said { padding: 4px 8px; border-left: 2px solid var(--deictic-line); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--deictic-muted); }
923
+ .task-view .editing textarea { display: block; box-sizing: border-box; width: 100%; min-height: 56px; resize: vertical; font: 13px/1.45 system-ui, sans-serif; }
924
+ .task-view .buttons { display: flex; justify-content: end; gap: 6px; margin-top: 6px; }
925
+ /* What a task or a reply has attached: a chip each, which opens all of them in the lightbox. */
926
+ .task-files { display: flex; flex-wrap: wrap; gap: 4px; }
927
+ .task-files:empty { display: none; }
928
+ /* One height, and a thumbnail one size, as the composer's chips: nothing moves as the pictures load. */
929
+ .task-files button { box-sizing: border-box; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; height: 26px; padding: 0 6px 0 2px; border: 1px solid var(--deictic-line); border-radius: 6px; font-size: 11px; }
930
+ .task-files button span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
931
+ .task-files img { flex: none; display: block; width: 30px; height: 20px; object-fit: cover; border-radius: 4px; background: var(--deictic-line); }
932
+ .task-files .play { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 4px; background: var(--deictic-line); }
933
+ .task-files .play svg { width: 10px; height: 10px; }
934
+ .task-thread { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 0; padding: 8px 0 0; border-top: 1px solid rgb(255 255 255 / 0.08); list-style: none; }
935
+ .task-thread:empty { display: none; }
936
+ .task-thread li { display: grid; gap: 4px; padding: 6px 8px; border: 1px solid rgb(255 255 255 / 0.08); border-radius: 8px; background: rgb(255 255 255 / 0.04); }
937
+ .task-thread li.new { border-color: color-mix(in srgb, var(--deictic-accent) 55%, transparent); }
938
+ .task-thread .by { display: flex; gap: 6px; align-items: baseline; font-size: 11px; color: var(--deictic-muted); }
939
+ .task-thread .by b { font-weight: 600; color: var(--deictic-fg); }
940
+ .task-thread .by i { margin-left: auto; font-style: normal; }
941
+ .task-thread .text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
942
+ .task-view .problem { color: var(--deictic-problem); }
943
+ .task-view .problem:empty { display: none; }
944
+ /* On the page, around an element a task is about: the open task's, and each one attached in the Task tab. */
945
+ .task-about { position: fixed; z-index: 2147483646; box-sizing: border-box; pointer-events: none; border: 1.5px dashed var(--deictic-accent); border-radius: 6px; }
946
+ .task-about[hidden] { display: none; }
947
+ ${COMPOSER_STYLE}`;
948
+ /** How often an open task's thread is read again, in ms: an agent answers while it's looked at. */
949
+ const AGAIN = 5e3;
950
+ /** How long Delete waits to be pressed again, in ms, before it's only Delete once more. */
951
+ const SURE = 3e3;
952
+ /** Where what's typed in a reply is kept while its task isn't open: for the tab, over page loads. */
953
+ const DRAFTS = "deictic:tasks:drafts";
954
+ const FILE = "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M6 3h8l4 4v14H6zM14 3v4h4\"/></svg>";
955
+ /** `now`, `5m`, `2h`, `3d`: how long ago, as short as a thread's margin. */
956
+ function ago(at) {
957
+ const minutes = Math.round((Date.now() - Date.parse(at)) / 6e4);
958
+ if (!(minutes >= 1)) return "now";
959
+ if (minutes < 60) return `${minutes}m`;
960
+ return minutes < 1440 ? `${Math.round(minutes / 60)}h` : `${Math.round(minutes / 1440)}d`;
961
+ }
962
+ /** What's typed in each task's reply, by its ID. */
963
+ function drafts() {
964
+ try {
965
+ const kept = JSON.parse(sessionStorage.getItem(DRAFTS) ?? "{}");
966
+ return typeof kept === "object" && kept !== null ? kept : {};
967
+ } catch {
968
+ return {};
969
+ }
970
+ }
971
+ function keepDraft(id, text) {
972
+ const { [id]: _, ...rest } = drafts();
973
+ try {
974
+ sessionStorage.setItem(DRAFTS, JSON.stringify(text.trim() === "" ? rest : {
975
+ ...rest,
976
+ [id]: text
977
+ }));
978
+ } catch {}
979
+ }
980
+ /** A board's file as a person names it: what it is, not what deictic called it. */
981
+ function nameOf(file, i, all) {
982
+ const alike = all.filter((other) => kindOf(other) === kindOf(file));
983
+ const n = alike.length === 1 ? "" : ` ${alike.indexOf(file) + 1}`;
984
+ const kind = kindOf(file);
985
+ if (kind === "image") return `Screenshot${n}`;
986
+ if (kind === "recording") return `Recording${n}`;
987
+ if (kind === "audio") return `Voice note${n}`;
988
+ if (/^element(\.\d+)?\.html$/.test(file.name)) return `HTML${n}`;
989
+ return file.name || `File ${i + 1}`;
990
+ }
991
+ const kindOf = ({ type, name }) => type.startsWith("image/") ? "image" : name.startsWith("recording-") ? "recording" : type.startsWith("audio/") ? "audio" : "file";
992
+ const made$1 = /* @__PURE__ */ new WeakMap();
993
+ /** The tasks' section in the drawer of the overlay `context` is of: added the first time it's asked for. */
994
+ function drawerOf(context) {
995
+ const known = made$1.get(context.root);
996
+ if (known !== void 0) return known;
997
+ const store = storeOf(context);
998
+ const section = element("section", {
999
+ className: "tasks-drawer",
1000
+ hidden: true
1001
+ });
1002
+ const heading = element("h3");
1003
+ const rows = element("div", { className: "drawer-rows" });
1004
+ const finished = element("details");
1005
+ const finishedCount = element("summary");
1006
+ const finishedRows = element("div", { className: "drawer-rows" });
1007
+ const putAway = element("button", {
1008
+ type: "button",
1009
+ className: "act put-away",
1010
+ textContent: "Archive all",
1011
+ title: "Put the finished tasks away: one comes back when something happens to it"
1012
+ });
1013
+ putAway.addEventListener("click", () => store.archive(store.tasks().filter((task) => OVER.has(task.state))));
1014
+ finishedRows.append(putAway);
1015
+ finished.append(finishedCount, finishedRows);
1016
+ section.append(element("style", { textContent: STYLE$2 }), heading, rows, finished);
1017
+ /** What a task is about, as the caption says an element: by its component where the page has it, else its tag. */
1018
+ const about = (task) => {
1019
+ if (task.problem !== void 0) return task.problem === "setup" ? "deictic's setup" : "a bug in deictic";
1020
+ if (task.place === void 0) return "the page";
1021
+ const el = elementOf(task);
1022
+ if (el !== null) return tell(named(el));
1023
+ const on = task.page === void 0 || task.page === location.pathname ? "" : ` on ${task.page}`;
1024
+ return `${task.tag === void 0 ? "an element" : `<${task.tag}>`}${on}`;
1025
+ };
1026
+ /** Lights a task's element on the page while the pointer is on what stands for it here. */
1027
+ const lights = (on, task) => {
1028
+ on.addEventListener("pointerenter", () => context.light(elementOf(task()) ?? void 0));
1029
+ on.addEventListener("pointerleave", () => context.light());
1030
+ };
1031
+ const rowOf = (task) => {
1032
+ const row = element("button", {
1033
+ type: "button",
1034
+ className: `task-row${store.unread(task) ? " unread" : ""}`
1035
+ });
1036
+ const says = task.by === void 0 ? task.state : `${task.state} by ${task.by}`;
1037
+ const replies = task.replies === 0 ? "" : ` · ${task.replies} ${task.replies === 1 ? "reply" : "replies"}`;
1038
+ row.append(element("span", {
1039
+ className: `task-state ${task.state}`,
1040
+ ariaHidden: "true"
1041
+ }), element("span", {
1042
+ className: "title",
1043
+ textContent: task.title
1044
+ }), element("span", {
1045
+ className: "meta",
1046
+ textContent: `${says} · ${about(task)}${replies}`
1047
+ }), element("span", {
1048
+ className: "mark",
1049
+ ...store.unread(task) ? { title: "Unread" } : {}
1050
+ }));
1051
+ lights(row, () => task);
1052
+ row.addEventListener("click", () => {
1053
+ context.light();
1054
+ view(task);
1055
+ });
1056
+ return row;
1057
+ };
1058
+ const draw = () => {
1059
+ const tasks = store.tasks().filter((task) => !store.archived(task));
1060
+ const live = tasks.filter((task) => !OVER.has(task.state));
1061
+ const ended = tasks.filter((task) => OVER.has(task.state));
1062
+ section.hidden = tasks.length === 0;
1063
+ const unread = tasks.filter(store.unread).length;
1064
+ section.dataset.count = String(live.length);
1065
+ section.dataset.unread = String(unread);
1066
+ const channel = store.channel();
1067
+ heading.replaceChildren("Tasks", ...unread === 0 ? [] : [element("span", {
1068
+ className: "unread",
1069
+ textContent: String(unread),
1070
+ title: `${unread} unread`
1071
+ })], ...channel?.link === void 0 ? [] : [element("a", {
1072
+ href: channel.link,
1073
+ target: "_blank",
1074
+ rel: "noreferrer",
1075
+ textContent: `#${channel.name}`,
1076
+ title: "Open the channel on the board"
1077
+ })]);
1078
+ rows.replaceChildren(...live.map(rowOf));
1079
+ finished.hidden = ended.length === 0;
1080
+ const news = ended.filter(store.unread).length;
1081
+ finishedCount.textContent = `${ended.length} finished${news === 0 ? "" : `, ${news} unread`}`;
1082
+ finishedRows.replaceChildren(...ended.map(rowOf), putAway);
1083
+ };
1084
+ store.subscribe(draw);
1085
+ context.drawer.add(section, { first: true });
1086
+ const ask = async (route, body) => {
1087
+ const res = await context.request(route, body === void 0 ? void 0 : {
1088
+ method: "POST",
1089
+ headers: { "content-type": "application/json" },
1090
+ body: JSON.stringify(body)
1091
+ });
1092
+ const answer = await res.json();
1093
+ if (!res.ok) throw new Error(answer.problem ?? `the dev server answered ${res.status}`);
1094
+ return answer;
1095
+ };
1096
+ /** A message's files as chips, each opening them all in the lightbox at itself. */
1097
+ const filesOf = (task, files) => {
1098
+ const list = element("div", { className: "task-files" });
1099
+ const urlOf = (file) => file.url ?? `${context.base}__deictic/plugins/tasks/file/${encodeURIComponent(task)}/${encodeURIComponent(file.id)}`;
1100
+ const items = files.map((file, i) => {
1101
+ const title = nameOf(file, i, files);
1102
+ const kind = kindOf(file);
1103
+ if (kind === "image") return {
1104
+ kind: "image",
1105
+ url: urlOf(file),
1106
+ title
1107
+ };
1108
+ if (kind === "audio") return {
1109
+ kind: "audio",
1110
+ url: urlOf(file),
1111
+ title
1112
+ };
1113
+ const replay = kind === "recording" ? file.replay : void 0;
1114
+ const url = replay === void 0 ? urlOf(file) : `${replay}${replay.includes("?") ? "&" : "?"}embed`;
1115
+ const open = replay ?? urlOf(file);
1116
+ return {
1117
+ kind: "page",
1118
+ url,
1119
+ title,
1120
+ actions: [{
1121
+ label: "New tab",
1122
+ title: "Open it in a tab of its own",
1123
+ run: () => void window.open(open, "_blank", "noopener")
1124
+ }]
1125
+ };
1126
+ });
1127
+ list.append(...files.map((file, i) => {
1128
+ const name = nameOf(file, i, files);
1129
+ const chip = element("button", {
1130
+ type: "button",
1131
+ title: `Open ${/^[A-Z]{2}/.test(name) ? name : `${name[0].toLowerCase()}${name.slice(1)}`}`
1132
+ });
1133
+ const kind = kindOf(file);
1134
+ const icon = kind === "image" ? element("img", {
1135
+ src: urlOf(file),
1136
+ alt: "",
1137
+ loading: "lazy"
1138
+ }) : element("span", {
1139
+ className: "play",
1140
+ innerHTML: kind === "file" ? FILE : PLAY
1141
+ });
1142
+ chip.append(icon, element("span", { textContent: name }));
1143
+ chip.addEventListener("click", () => context.lightbox(items, {
1144
+ at: i,
1145
+ from: chip
1146
+ }));
1147
+ return chip;
1148
+ }));
1149
+ return list;
1150
+ };
1151
+ /** A task, open in the drawer: its words, what's attached, its thread, and what changes them. */
1152
+ function view(first) {
1153
+ let task = first;
1154
+ let editing = false;
1155
+ const readTo = store.read(first);
1156
+ const fresh = store.unread(first);
1157
+ const mine = /* @__PURE__ */ new Set();
1158
+ const recorder = context.use("recordings");
1159
+ const el = element("div", { className: "task-view" });
1160
+ const stands = element("div", { className: "stands" });
1161
+ const where = element("button", {
1162
+ type: "button",
1163
+ className: "where"
1164
+ });
1165
+ const words = element("div");
1166
+ const files = element("div");
1167
+ const said = element("div", { className: "said" });
1168
+ const thread = element("ol", { className: "task-thread" });
1169
+ const problem = element("div", { className: "problem" });
1170
+ lights(where, () => task);
1171
+ const composer = composerIn(context, {
1172
+ placeholder: "Reply…",
1173
+ sendLabel: "Reply",
1174
+ over: true,
1175
+ record: () => {
1176
+ if (recorder === void 0) return;
1177
+ if (recorder.recording()) {
1178
+ composer.problem.textContent = "A recording is going already: stop it in the tool panel, and it's attached here";
1179
+ return;
1180
+ }
1181
+ close();
1182
+ recorder.record();
1183
+ },
1184
+ submit: async (gathered) => {
1185
+ const answer = {
1186
+ text: gathered.text,
1187
+ ...attachedOf(gathered)
1188
+ };
1189
+ const after = await ask(`reply/${encodeURIComponent(task.id)}`, answer);
1190
+ const last = after.replies.at(-1);
1191
+ if (last !== void 0) mine.add(last.id);
1192
+ shown(after);
1193
+ keepDraft(task.id, "");
1194
+ store.load(true);
1195
+ return true;
1196
+ }
1197
+ });
1198
+ composer.restore({ text: drafts()[first.id] ?? "" });
1199
+ el.append(stands, where, words, files, said, thread, composer.el, problem);
1200
+ const outline = element("div", {
1201
+ className: "task-about",
1202
+ hidden: true
1203
+ });
1204
+ context.root.append(outline);
1205
+ let following = requestAnimationFrame(function follow() {
1206
+ following = requestAnimationFrame(follow);
1207
+ const it = elementOf(task);
1208
+ outline.hidden = it === null;
1209
+ if (it !== null) place(outline, it.getBoundingClientRect());
1210
+ });
1211
+ where.addEventListener("click", () => elementOf(task)?.scrollIntoView({
1212
+ block: "center",
1213
+ behavior: "smooth"
1214
+ }));
1215
+ const failed = (e) => problem.textContent = messageOf(e);
1216
+ let removing;
1217
+ const drawTask = () => {
1218
+ const state = element("span", {
1219
+ className: `task-state ${task.state}`,
1220
+ ariaHidden: "true"
1221
+ });
1222
+ const says = element("span", {
1223
+ className: "says",
1224
+ textContent: task.by === void 0 ? task.state : `${task.state} by ${task.by}`
1225
+ });
1226
+ const to = task.link === void 0 ? [] : [element("a", {
1227
+ href: task.link,
1228
+ target: "_blank",
1229
+ rel: "noreferrer",
1230
+ textContent: "on the board",
1231
+ title: "Open the task on the board"
1232
+ })];
1233
+ const edit = element("button", {
1234
+ type: "button",
1235
+ className: "act",
1236
+ textContent: "Edit",
1237
+ title: "Change its words"
1238
+ });
1239
+ edit.addEventListener("click", () => {
1240
+ editing = true;
1241
+ drawWords();
1242
+ });
1243
+ const remove = element("button", {
1244
+ type: "button",
1245
+ className: "act",
1246
+ textContent: "Delete",
1247
+ title: "Cancel it on the board"
1248
+ });
1249
+ remove.addEventListener("click", () => {
1250
+ if (!remove.classList.contains("sure")) {
1251
+ remove.classList.add("sure");
1252
+ remove.textContent = "Delete?";
1253
+ removing = setTimeout(() => {
1254
+ remove.classList.remove("sure");
1255
+ remove.textContent = "Delete";
1256
+ }, SURE);
1257
+ return;
1258
+ }
1259
+ remove.disabled = true;
1260
+ ask(`remove/${encodeURIComponent(task.id)}`, {}).then(() => {
1261
+ store.load(true);
1262
+ close();
1263
+ }, failed);
1264
+ });
1265
+ const archive = element("button", {
1266
+ type: "button",
1267
+ className: "act",
1268
+ textContent: "Archive",
1269
+ title: "Put it away: it comes back when something happens to it"
1270
+ });
1271
+ archive.addEventListener("click", () => {
1272
+ store.archive([task]);
1273
+ close();
1274
+ });
1275
+ stands.replaceChildren(state, says, ...to, ...task.open ? [edit, remove] : [], ...OVER.has(task.state) ? [archive] : []);
1276
+ const at = task.place?.replace(/:\d+$/, "");
1277
+ where.replaceChildren(about(task), ...at === void 0 ? [] : [element("span", { textContent: ` ${at}` })]);
1278
+ where.disabled = elementOf(task) === null;
1279
+ where.title = task.place === void 0 ? "No element was attached" : where.disabled ? "Not on this page now" : "Show it on the page";
1280
+ said.hidden = task.said === void 0;
1281
+ said.textContent = task.said ?? "";
1282
+ };
1283
+ const drawWords = () => {
1284
+ if (!editing) {
1285
+ words.className = "words";
1286
+ words.replaceChildren(task.text);
1287
+ return;
1288
+ }
1289
+ const text = element("textarea", { value: task.text });
1290
+ const save = element("button", {
1291
+ type: "button",
1292
+ className: "primary",
1293
+ textContent: "Save"
1294
+ });
1295
+ const leave = element("button", {
1296
+ type: "button",
1297
+ textContent: "Cancel"
1298
+ });
1299
+ const buttons = element("div", { className: "buttons" });
1300
+ buttons.append(leave, save);
1301
+ const done = () => {
1302
+ editing = false;
1303
+ drawWords();
1304
+ };
1305
+ const keep = () => {
1306
+ if (text.value.trim() === "") return;
1307
+ if (text.value.trim() === task.text) return done();
1308
+ save.disabled = true;
1309
+ ask(`edit/${encodeURIComponent(task.id)}`, { text: text.value }).then((answer) => {
1310
+ editing = false;
1311
+ shown(answer);
1312
+ store.load(true);
1313
+ }, (e) => {
1314
+ save.disabled = false;
1315
+ failed(e);
1316
+ });
1317
+ };
1318
+ text.addEventListener("keydown", (e) => {
1319
+ if (e.key === "Escape") {
1320
+ e.stopPropagation();
1321
+ done();
1322
+ }
1323
+ if (e.key !== "Enter" || e.shiftKey || e.isComposing) return;
1324
+ e.preventDefault();
1325
+ keep();
1326
+ });
1327
+ save.addEventListener("click", keep);
1328
+ leave.addEventListener("click", done);
1329
+ words.className = "editing";
1330
+ words.replaceChildren(text, buttons);
1331
+ text.focus();
1332
+ };
1333
+ let drawn = "";
1334
+ /** The task and its thread as just read: drawn, and read by whoever is looking. */
1335
+ const shown = (answer) => {
1336
+ task = answer.task;
1337
+ problem.textContent = "";
1338
+ drawTask();
1339
+ if (!editing) drawWords();
1340
+ const now = JSON.stringify([
1341
+ answer.files.map((f) => f.id),
1342
+ answer.replies.map((r) => [
1343
+ r.id,
1344
+ r.text,
1345
+ r.files.length
1346
+ ]),
1347
+ [...mine]
1348
+ ]);
1349
+ if (now !== drawn) {
1350
+ drawn = now;
1351
+ files.replaceChildren(filesOf(task.id, answer.files));
1352
+ const from = readTo === void 0 ? -1 : answer.replies.findIndex((r) => r.id === readTo);
1353
+ const grew = answer.replies.length !== thread.childElementCount;
1354
+ thread.replaceChildren(...answer.replies.map((r, i) => {
1355
+ const item = element("li", { className: fresh && i > from && !mine.has(r.id) ? "new" : "" });
1356
+ const by = element("div", { className: "by" });
1357
+ by.append(element("b", { textContent: r.by }), ...r.kind === "person" ? [] : ["agent"], element("i", {
1358
+ textContent: ago(r.at),
1359
+ title: new Date(r.at).toLocaleString()
1360
+ }));
1361
+ item.append(by, element("div", {
1362
+ className: "text",
1363
+ textContent: r.text
1364
+ }), filesOf(task.id, r.files));
1365
+ return item;
1366
+ }));
1367
+ if (grew) thread.lastElementChild?.scrollIntoView({ block: "nearest" });
1368
+ }
1369
+ store.seen(task);
1370
+ };
1371
+ const load = () => ask(`thread/${encodeURIComponent(task.id)}`).then(shown, failed);
1372
+ drawTask();
1373
+ drawWords();
1374
+ load();
1375
+ const again = setInterval(() => void load(), AGAIN);
1376
+ const close = context.drawer.show(el, {
1377
+ title: `#${task.id}`,
1378
+ closed: () => {
1379
+ keepDraft(task.id, composer.draft().text);
1380
+ composer.destroy();
1381
+ context.light();
1382
+ clearInterval(again);
1383
+ clearTimeout(removing);
1384
+ cancelAnimationFrame(following);
1385
+ outline.remove();
1386
+ }
1387
+ });
1388
+ }
1389
+ /** Several tasks of one place, to pick from. */
1390
+ const pick = (tasks) => {
1391
+ const el = element("div", { className: "drawer-rows" });
1392
+ el.append(...tasks.map(rowOf));
1393
+ context.drawer.show(el, {
1394
+ title: `${tasks.length} tasks on ${about(tasks[0])}`,
1395
+ closed: () => context.light()
1396
+ });
1397
+ };
1398
+ const drawer = { open: (tasks) => {
1399
+ if (tasks.length === 1) view(tasks[0]);
1400
+ else if (tasks.length > 1) pick(tasks);
1401
+ } };
1402
+ made$1.set(context.root, drawer);
1403
+ return drawer;
1404
+ }
1405
+ // src/plugins/tasks/pins.ts
1406
+ /**
1407
+ * The page's tasks, each pinned where its element is: what's shown of them on the page itself, beside the Task
1408
+ * tab's list of one element's. A pin is the element's outline, faint, and a badge on its corner with how many
1409
+ * tasks are still to do there, in the colour of the furthest along, and a dot where one has something unread. They
1410
+ * show while a shortcut's keys are held and while the Task tab is open: a pin under the pointer reads its tasks, and
1411
+ * a click opens them in the drawer.
1412
+ *
1413
+ * In a layer of the overlay's root, which the tab's own styles don't reach once it's closed: so its styles are its own.
1414
+ */
1415
+ const STYLE$1 = `
1416
+ /* No box of its own, which its pins would stack in: each is under the popup, and the one pointed at over it, with its card. */
1417
+ .pins { display: contents; font: 12px/1.4 system-ui, sans-serif; color: var(--deictic-fg); }
1418
+ .pin { --pin: var(--deictic-accent); position: fixed; z-index: 2147483646; box-sizing: border-box; pointer-events: none; border: 1px solid color-mix(in srgb, var(--pin) 45%, transparent); border-radius: 6px; transition: border-color 0.15s, box-shadow 0.15s; }
1419
+ .pin.claimed { --pin: #60a5fa; }
1420
+ .pin.blocked { --pin: #fbbf24; }
1421
+ .pin[hidden] { display: none; }
1422
+ .pin.spot, .pin.spot:has(.pin-badge:hover, .pin-badge:focus-visible) { border: 0; box-shadow: none; }
1423
+ .pin:has(.pin-badge:hover, .pin-badge:focus-visible) { z-index: 2147483647; border-color: var(--pin); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pin) 18%, transparent), 0 0 28px color-mix(in srgb, var(--pin) 45%, transparent); }
1424
+ /* A drop, its point on the element's corner. */
1425
+ .pin-badge {
1426
+ position: absolute;
1427
+ display: flex;
1428
+ align-items: center;
1429
+ justify-content: center;
1430
+ box-sizing: border-box;
1431
+ min-width: 22px;
1432
+ height: 22px;
1433
+ padding: 0 6px;
1434
+ border: 0;
1435
+ border-radius: 11px 11px 11px 3px;
1436
+ font: 700 12px/22px system-ui, sans-serif;
1437
+ font-variant-numeric: tabular-nums;
1438
+ color: #09090b;
1439
+ background: var(--pin);
1440
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--pin) 22%, transparent), 0 0 18px color-mix(in srgb, var(--pin) 60%, transparent), 0 4px 12px rgb(0 0 0 / 0.4);
1441
+ pointer-events: auto;
1442
+ cursor: pointer;
1443
+ }
1444
+ .pin-badge:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
1445
+ /* Something unread there: a dot on the badge's corner. */
1446
+ .pin.unread .pin-badge::after { content: ''; position: absolute; top: -3px; right: -3px; width: 8px; height: 8px; border: 2px solid #09090b; border-radius: 50%; background: #fff; }
1447
+ .pin-card {
1448
+ position: absolute;
1449
+ left: 0;
1450
+ top: calc(100% + 8px);
1451
+ display: none;
1452
+ flex-direction: column;
1453
+ gap: 4px;
1454
+ width: max-content;
1455
+ max-width: 300px;
1456
+ padding: 8px 10px;
1457
+ border: 1px solid rgb(255 255 255 / 0.12);
1458
+ border-radius: 10px;
1459
+ font: 12px/1.4 system-ui, sans-serif;
1460
+ text-align: left;
1461
+ color: var(--deictic-fg);
1462
+ background: rgb(24 24 27 / 0.9);
1463
+ backdrop-filter: blur(16px) saturate(1.6);
1464
+ box-shadow: 0 12px 32px rgb(0 0 0 / 0.45);
1465
+ cursor: pointer;
1466
+ }
1467
+ .pin.left .pin-card { left: auto; right: 0; }
1468
+ .pin.up .pin-card { top: auto; bottom: calc(100% + 8px); }
1469
+ .pin-badge:hover .pin-card, .pin-badge:focus-visible .pin-card { display: flex; }
1470
+ .pin-where { font: 11px ui-monospace, monospace; color: var(--deictic-muted); }
1471
+ .pin-where b { color: var(--pin); }
1472
+ .pin-task { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
1473
+ .pin-task span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1474
+ .pin-task i { flex: none; align-self: center; box-sizing: border-box; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--deictic-muted); }
1475
+ .pin-task i.claimed { border-color: #60a5fa; background: #60a5fa; }
1476
+ .pin-task i.blocked { border-color: #fbbf24; background: #fbbf24; }
1477
+ .pin-task i.waiting { border-style: dotted; }
1478
+ .pin-task em { flex: none; font-style: normal; color: var(--deictic-muted); }
1479
+ .pin-more { color: var(--deictic-muted); }
1480
+ @media (prefers-reduced-motion: no-preference) {
1481
+ .pin { animation: deictic-pin-area 0.3s ease-out backwards; }
1482
+ .pin-badge { animation: deictic-pin 0.34s cubic-bezier(0.2, 0.9, 0.25, 1.4) backwards; animation-delay: inherit; transform-origin: 0 100%; }
1483
+ }
1484
+ @keyframes deictic-pin-area {
1485
+ from { opacity: 0; }
1486
+ }
1487
+ @keyframes deictic-pin {
1488
+ from { opacity: 0; scale: 0.2; }
1489
+ }
1490
+ `;
1491
+ /** How long the pins outlast what showed them, in ms: the popup opens a moment after the pointing that led to it ends. */
1492
+ const LINGER = 200;
1493
+ /** A badge's size, and how far out of the element's corner it sits, in pixels. */
1494
+ const BADGE = 22;
1495
+ const OUT = 10;
1496
+ const EDGE = 4;
1497
+ /** The tasks a pin's card names, before it only counts them. */
1498
+ const NAMED = 4;
1499
+ /** The states by how far along, the furthest first: a pin is the colour of its furthest. */
1500
+ const ALONG = [
1501
+ "blocked",
1502
+ "claimed",
1503
+ "ready",
1504
+ "waiting"
1505
+ ];
1506
+ const made = /* @__PURE__ */ new WeakMap();
1507
+ /** The pins of the overlay `context` is of: one set, whoever shows it. */
1508
+ function pinsIn(context) {
1509
+ const kept = made.get(context.root);
1510
+ if (kept !== void 0) return kept;
1511
+ const store = storeOf(context);
1512
+ let glances = 0;
1513
+ let layer;
1514
+ let frame = 0;
1515
+ let leaving;
1516
+ const pins = /* @__PURE__ */ new Map();
1517
+ let frames = 0;
1518
+ const pinOf = (at, el, spot) => {
1519
+ const box = div("pin");
1520
+ const badge = Object.assign(document.createElement("button"), {
1521
+ type: "button",
1522
+ className: "pin-badge"
1523
+ });
1524
+ const count = document.createElement("span");
1525
+ const card = Object.assign(document.createElement("span"), { className: "pin-card" });
1526
+ badge.append(count, card);
1527
+ box.append(badge);
1528
+ if (!reduced()) box.style.animationDelay = `${Math.min(pins.size, 12) * 30}ms`;
1529
+ const pin = {
1530
+ place: at,
1531
+ ...spot === void 0 ? {} : { at: spot },
1532
+ el,
1533
+ box,
1534
+ badge,
1535
+ count,
1536
+ card,
1537
+ tasks: []
1538
+ };
1539
+ badge.addEventListener("click", () => drawerOf(context).open(pin.tasks));
1540
+ return pin;
1541
+ };
1542
+ /** A pin as its tasks are now: how many, the colour of the furthest along, and its card. */
1543
+ const fill = (pin, list) => {
1544
+ const state = ALONG.find((s) => list.some((t) => t.state === s)) ?? "ready";
1545
+ pin.tasks = list;
1546
+ pin.box.className = `pin ${state}${pin.at === void 0 ? "" : " spot"}${list.some(store.unread) ? " unread" : ""}`;
1547
+ pin.count.textContent = String(list.length);
1548
+ const [, file = "", line = ""] = /^(.*):(\d+):\d+$/.exec(pin.place) ?? [];
1549
+ const tag = tell(named(pin.el));
1550
+ pin.badge.setAttribute("aria-label", `${list.length} ${list.length === 1 ? "task" : "tasks"} on ${tag}, line ${line}: open`);
1551
+ const where = Object.assign(document.createElement("span"), { className: "pin-where" });
1552
+ where.append(Object.assign(document.createElement("b"), { textContent: tag }), ` ${file.split("/").at(-1)}:${line}`);
1553
+ const rows = list.slice(0, NAMED).map((t) => {
1554
+ const row = Object.assign(document.createElement("span"), { className: "pin-task" });
1555
+ const dot = Object.assign(document.createElement("i"), { className: t.state });
1556
+ const by = t.by === void 0 ? [] : [Object.assign(document.createElement("em"), { textContent: t.by })];
1557
+ row.append(dot, Object.assign(document.createElement("span"), { textContent: t.title }), ...by);
1558
+ return row;
1559
+ });
1560
+ const rest = list.length - rows.length;
1561
+ const more = rest === 0 ? [] : [Object.assign(document.createElement("span"), {
1562
+ className: "pin-more",
1563
+ textContent: `+${rest} more`
1564
+ })];
1565
+ pin.card.replaceChildren(where, ...rows, ...more);
1566
+ };
1567
+ /** The pins as the tasks read last have them: one per place with an element on the page, for those still to do. */
1568
+ const draw = () => {
1569
+ if (layer === void 0) return;
1570
+ const tasks = store.tasks().filter((t) => t.place !== void 0 && !OVER.has(t.state));
1571
+ const keyOf = (t) => {
1572
+ const el = elementOf(t);
1573
+ const of = el === null ? t.place : `${t.place}#${sameAs(el).indexOf(el)}`;
1574
+ return t.point === void 0 ? of : `${of}@${t.point.x},${t.point.y}`;
1575
+ };
1576
+ const byPlace = /* @__PURE__ */ new Map();
1577
+ for (const t of tasks) byPlace.set(keyOf(t), [...byPlace.get(keyOf(t)) ?? [], t]);
1578
+ for (const [at, pin] of pins) {
1579
+ if (byPlace.has(at)) continue;
1580
+ pin.box.remove();
1581
+ pins.delete(at);
1582
+ }
1583
+ for (const [at, list] of byPlace) {
1584
+ let pin = pins.get(at);
1585
+ if (pin === void 0) {
1586
+ const [first] = list;
1587
+ const { place: where, point } = first;
1588
+ const el = elementOf(first);
1589
+ if (el === null) continue;
1590
+ pin = pinOf(where, el, point);
1591
+ pins.set(at, pin);
1592
+ layer.append(pin.box);
1593
+ }
1594
+ fill(pin, list);
1595
+ }
1596
+ follow();
1597
+ };
1598
+ /** Each pin over its element as the page has it now: read each frame, as nothing tells of an element moving. */
1599
+ const follow = () => {
1600
+ const width = document.documentElement.clientWidth;
1601
+ const height = document.documentElement.clientHeight;
1602
+ const look = frames++ % 20 === 0;
1603
+ for (const pin of pins.values()) {
1604
+ if (!pin.el.isConnected && look && pin.tasks[0] !== void 0) pin.el = elementOf(pin.tasks[0]) ?? pin.el;
1605
+ const whole = pin.el.getBoundingClientRect();
1606
+ const r = pin.at === void 0 ? whole : new DOMRect(whole.left + pin.at.x, whole.top + pin.at.y, 0, 0);
1607
+ const seen = pin.el.isConnected && whole.width > 0 && whole.height > 0 && r.bottom > 0 && r.top < height && r.right > 0 && r.left < width;
1608
+ pin.box.hidden = !seen;
1609
+ if (!seen) continue;
1610
+ place(pin.box, r);
1611
+ const out = pin.at === void 0 ? OUT : 0;
1612
+ const x = Math.max(EDGE, Math.min(r.right - out, width - EDGE - pin.badge.offsetWidth));
1613
+ const y = Math.max(EDGE, Math.min(r.top - BADGE + out, height - EDGE - BADGE));
1614
+ const edge = pin.at === void 0 ? 1 : 0;
1615
+ Object.assign(pin.badge.style, {
1616
+ left: `${x - r.left - edge}px`,
1617
+ top: `${y - r.top - edge}px`
1618
+ });
1619
+ pin.box.classList.toggle("left", x > width / 2);
1620
+ pin.box.classList.toggle("up", y > height / 2);
1621
+ }
1622
+ };
1623
+ store.subscribe(draw);
1624
+ const sync = () => {
1625
+ clearTimeout(leaving);
1626
+ if (glances === 0) {
1627
+ leaving = setTimeout(() => {
1628
+ cancelAnimationFrame(frame);
1629
+ layer?.remove();
1630
+ layer = void 0;
1631
+ pins.clear();
1632
+ }, LINGER);
1633
+ return;
1634
+ }
1635
+ if (layer === void 0) {
1636
+ layer = div("pins");
1637
+ layer.append(Object.assign(document.createElement("style"), { textContent: STYLE$1 }));
1638
+ frame = requestAnimationFrame(function each() {
1639
+ frame = requestAnimationFrame(each);
1640
+ follow();
1641
+ });
1642
+ }
1643
+ context.root.append(layer);
1644
+ draw();
1645
+ store.load();
1646
+ };
1647
+ const shown = { glance: () => {
1648
+ glances++;
1649
+ sync();
1650
+ return () => {
1651
+ glances--;
1652
+ sync();
1653
+ };
1654
+ } };
1655
+ made.set(context.root, shown);
1656
+ return shown;
1657
+ }
1658
+ // src/plugins/tasks/client.ts
1659
+ /**
1660
+ * The Task tab: a composer to add a task about the element with (`composer.ts`). The tasks there already are the
1661
+ * drawer's to list and open (`drawer.ts`), and the pins' to show on the page. Beside the channel it says who watches
1662
+ * it (`Model.watching`), or that no agent does.
1663
+ * Enter or the arrow sends it with the page's URL, the viewport and the element as it rendered, which the source
1664
+ * can't tell: the chain of source it rendered through, its HTML (a file attached), and where the annotations plugin
1665
+ * is loaded, what's marked on the page. Record leaves the popup (`away`) to record the page, and comes back with
1666
+ * what was typed when it's stopped, wherever the page is by then.
1667
+ *
1668
+ * Its tool in the panel adds a task about a spot: picked, the next press on the page opens this tab on that point,
1669
+ * in the marked element under it or the nearest to it.
1670
+ */
1671
+ const STYLE = `
1672
+ .compose { flex: none; }
1673
+ .row { display: flex; gap: 6px; margin-top: 8px; justify-content: space-between; align-items: center; }
1674
+ /* Cut short: a channel's name and its watchers' may be long. */
1675
+ .hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--deictic-muted); font-size: 12px; }
1676
+ /* A dot as a task's state is: a ring while no one watches, green while someone does. */
1677
+ .watch::before { content: ''; display: inline-block; box-sizing: border-box; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; border: 1.5px solid var(--deictic-muted); }
1678
+ .watch.on::before { border-color: #4ade80; background: #4ade80; }
1679
+ .hint a { color: inherit; }
1680
+ .hint a:hover { color: var(--deictic-fg); }
1681
+ ${COMPOSER_STYLE}`;
1682
+ const TOOL_STYLE = `
1683
+ .task-tool button { position: relative; }
1684
+ .task-tool .count {
1685
+ position: absolute;
1686
+ top: -5px;
1687
+ right: -5px;
1688
+ box-sizing: border-box;
1689
+ min-width: 15px;
1690
+ height: 15px;
1691
+ padding: 0 4px;
1692
+ border-radius: 8px;
1693
+ font: 700 10px/15px system-ui, sans-serif;
1694
+ color: var(--deictic-on-accent);
1695
+ background: var(--deictic-accent);
1696
+ }
1697
+ .task-tool button[aria-pressed='true'] .count { color: var(--deictic-fg); background: #09090b; }
1698
+ `;
1699
+ /** A note with a plus: a task to add. */
1700
+ const TASK = "<path d=\"M4 5h16v11H9l-5 4zM12 8v5M9.5 10.5h5\"/>";
118
1701
  /**
119
1702
  * `#shadow-root > div.panel > div.head > button.tab:nth-of-type(2)`: where `inner` is inside `outer`, through
120
1703
  * shadow roots, by tag, classes and, among siblings alike, place, for whoever finds it in the code.
@@ -145,22 +1728,6 @@ const parentOf = (el) => {
145
1728
  };
146
1729
  /** How many places a chain names after the element's own: who uses it, and who uses that. Further out is the app's shell. */
147
1730
  const CHAIN = 3;
148
- /** React's fiber of an element it rendered, which it keeps on the element under a key of its own. */
149
- const fiberOf = (el) => {
150
- const key = Object.keys(el).find((k) => k.startsWith("__reactFiber$"));
151
- return key === void 0 ? void 0 : el[key];
152
- };
153
- const ownerOf = (of) => of?._debugOwner ?? of?.owner ?? void 0;
154
- /** A component's name, through `memo` and `forwardRef`, or nothing for one written without. */
155
- function componentOf(owner) {
156
- if (typeof owner.name === "string") return owner.name === "" ? void 0 : owner.name;
157
- let type = owner.type;
158
- for (let depth = 0; depth < 4 && type !== null && type !== void 0; depth++) {
159
- const name = type.displayName ?? type.name;
160
- if (typeof name === "string" && name !== "") return name;
161
- type = type.render ?? type.type;
162
- }
163
- }
164
1731
  /**
165
1732
  * The source `el` rendered through, after its own place, nearest first: a shared component's own line is the same
166
1733
  * wherever it's used, and the change is most often in what uses it, or in what uses that.
@@ -203,53 +1770,12 @@ function chainOf(el, file) {
203
1770
  }
204
1771
  /** What's sent of the element's HTML at most, in characters: the server attaches it as a file. */
205
1772
  const HTML = 1e5;
206
- /** The overlay's own green, as its outline of the element while the popup is open. */
207
- const OUTLINE = "#12b358";
208
- /** CSS pixels between the element and its outline, so the dashes are on nothing of the element's. */
209
- const ROOM = 3;
210
- /**
211
- * A shot's PNG with the element outlined in it: dashes around its box, with nothing between them, as the overlay
212
- * draws it. The shot may have more pixels than its size in CSS ones, which the box is in.
213
- */
214
- async function outlined(png, { box, size }) {
215
- const url = typeof png === "string" ? png : URL.createObjectURL(png);
216
- try {
217
- const image = new Image();
218
- image.src = url;
219
- await image.decode();
220
- const canvas = element("canvas", {
221
- width: image.naturalWidth,
222
- height: image.naturalHeight
223
- });
224
- const ctx = canvas.getContext("2d");
225
- if (ctx === null) throw new Error("tasks: this browser won't draw to a canvas");
226
- ctx.drawImage(image, 0, 0);
227
- const k = image.naturalWidth / size.width;
228
- const rect = [
229
- (box.x - ROOM) * k,
230
- (box.y - ROOM) * k,
231
- (box.width + 6) * k,
232
- (box.height + 6) * k
233
- ];
234
- ctx.lineWidth = 2 * k;
235
- ctx.strokeStyle = OUTLINE;
236
- ctx.setLineDash([6 * k, 4 * k]);
237
- ctx.strokeRect(...rect);
238
- return await new Promise((done, fail) => canvas.toBlob((blob) => blob === null ? fail(/* @__PURE__ */ new Error("tasks: the screenshot drew nothing")) : done(blob), "image/png"));
239
- } finally {
240
- if (typeof png !== "string") URL.revokeObjectURL(url);
241
- }
242
- }
243
- function element(tag, props = {}) {
244
- return Object.assign(document.createElement(tag), props);
245
- }
246
1773
  /** The event the page hears of each added task by, on `window`: its `detail` is a `TaskAdded`. */
247
1774
  const TASK_ADDED = "deictic:task";
248
1775
  /** Tells the page of a task just added: the newest of the element's tasks, as the board answered them. */
249
- function announce(model, op, target) {
1776
+ function announce(model, op, target, shots) {
250
1777
  const task = model.tasks.at(-1);
251
1778
  if (task === void 0) return;
252
- const marks = (op.annotations?.count ?? 0) + (op.screenshots ?? []).reduce((n, shot) => n + (shot.marks?.count ?? 0), 0);
253
1779
  const detail = {
254
1780
  id: task.id,
255
1781
  title: task.title,
@@ -261,630 +1787,233 @@ function announce(model, op, target) {
261
1787
  screenshots: op.screenshots?.length ?? 0,
262
1788
  recordings: op.recordings?.length ?? 0,
263
1789
  voice: op.voice?.length ?? 0,
264
- marks
265
- }
1790
+ marks: (op.annotations?.count ?? 0) + (op.screenshots ?? []).reduce((n, shot) => n + (shot.marks?.count ?? 0), 0)
1791
+ },
1792
+ screenshots: shots
266
1793
  };
267
1794
  window.dispatchEvent(new CustomEvent(TASK_ADDED, { detail }));
268
1795
  }
269
1796
  var client_default = defineClientPlugin({
270
1797
  name: "tasks",
271
1798
  label: "Task",
1799
+ setup: (context) => {
1800
+ const { tools, tray } = context;
1801
+ drawerOf(context);
1802
+ const group = element("div", { className: "tool-group task-tool" });
1803
+ let picking = false;
1804
+ const button = toolButton(TASK, "Task", "T", () => {
1805
+ if (picking) return;
1806
+ picking = true;
1807
+ button.setAttribute("aria-pressed", "true");
1808
+ tools.pick().then((spot) => {
1809
+ picking = false;
1810
+ button.setAttribute("aria-pressed", "false");
1811
+ if (spot !== void 0) context.open("tasks", spot.element, spot.at);
1812
+ });
1813
+ });
1814
+ button.setAttribute("aria-pressed", "false");
1815
+ const count = element("span", { className: "count" });
1816
+ const counted = () => {
1817
+ const held = tray.list().length;
1818
+ count.textContent = String(held);
1819
+ count.hidden = held === 0;
1820
+ };
1821
+ tray.subscribe(counted);
1822
+ counted();
1823
+ button.append(count);
1824
+ group.append(element("style", { textContent: TOOL_STYLE }), button);
1825
+ tools.add(group, {
1826
+ section: "capture",
1827
+ last: true
1828
+ });
1829
+ },
272
1830
  resume: ({ use }) => use("recordings")?.going(),
1831
+ pointing: (context) => pinsIn(context).glance(),
273
1832
  mount: (panel, context) => {
274
1833
  const style = element("style", { textContent: STYLE });
275
- const list = element("ul", { className: "tasks" });
276
- const text = element("textarea", { placeholder: "What should change here?" });
277
- const add = element("button", {
278
- type: "button",
279
- className: "primary",
280
- textContent: "Add task"
281
- });
282
1834
  const hint = element("span", { className: "hint" });
283
1835
  const row = element("div", { className: "row" });
284
- row.append(hint, add);
285
- const fold = element("details", { className: "more" });
286
- const count = element("summary");
287
- const others = element("ul", { className: "tasks" });
288
- fold.append(count, others);
289
- const closed = element("details", { className: "more" });
290
- const closedCount = element("summary");
291
- const ended = element("ul", { className: "tasks" });
292
- closed.append(closedCount, ended);
293
- panel.append(style, list, closed, fold, text);
1836
+ row.append(hint);
1837
+ const over = panel.getRootNode() === context.root;
1838
+ const unpin = over ? pinsIn(context).glance() : void 0;
294
1839
  const shots = context.use("screenshots");
295
- const here = context.element.isConnected;
296
- const notes = context.use("annotations");
297
1840
  const recorder = context.use("recordings");
298
- const voice = context.use("voice");
1841
+ const back = context.resumed;
299
1842
  const sendsHtml = context.options?.html !== false;
300
- const aborts = new AbortController();
301
- const attach = element("input", {
302
- type: "checkbox",
303
- checked: true
304
- });
305
- const toggle = element("label", { hidden: shots === void 0 || !here });
306
- toggle.append(attach, "Attach a screenshot");
307
- const annotate = element("button", {
308
- type: "button",
309
- textContent: "Annotate",
310
- title: "Take the screenshot now and draw on it"
311
- });
312
- const record = element("button", {
313
- type: "button",
314
- textContent: "Record",
315
- title: "Record the page, with a toolbar to draw on it, then come back here"
316
- });
317
- const speak = element("button", {
318
- type: "button",
319
- textContent: "Voice",
320
- title: "Record your voice, here"
321
- });
322
- const actions = element("span", { className: "actions" });
323
- actions.append(...shots !== void 0 && notes !== void 0 && here ? [annotate] : []);
324
- const shot = element("div", { className: "shot" });
325
- shot.append(toggle, actions);
326
- const chipsEl = element("div", { className: "chips" });
327
- const another = element("button", {
328
- type: "button",
329
- textContent: "Add another",
330
- title: "Take another screenshot and draw on it"
331
- });
332
- const problem = element("div", { className: "shot-problem" });
333
- if (shots !== void 0 || recorder !== void 0 || voice !== void 0) panel.append(shot, chipsEl, problem);
334
- const withHtml = element("input", {
335
- type: "checkbox",
336
- checked: true
337
- });
338
- const htmlToggle = element("label", { title: "The element as the page has it now, as a file: element.html" });
339
- htmlToggle.append(withHtml, "Attach HTML snapshot");
340
- const htmlRow = element("div", { className: "shot" });
341
- htmlRow.append(htmlToggle);
342
- if (sendsHtml) panel.append(htmlRow);
343
- panel.append(row);
344
- let chips = [];
345
- let recordings = [];
346
- let voices = [];
347
- let busy = false;
348
- const attachedCount = () => chips.length + recordings.length + voices.length;
349
- let sending = false;
350
- const able = () => add.disabled = sending || text.value.trim() === "" && attachedCount() === 0;
351
- const more = () => [...recorder !== void 0 ? [record] : [], ...voice !== void 0 ? [speak] : []];
352
- const chip = (content, title, at, remove, drop) => {
353
- const opener = element("button", {
354
- type: "button",
355
- className: "open",
356
- title
357
- });
358
- opener.append(...content);
359
- opener.addEventListener("click", () => context.lightbox(viewed(), {
360
- at,
361
- from: el
362
- }));
363
- const remover = element("button", {
364
- type: "button",
365
- className: "remove",
366
- textContent: "×",
367
- title: remove
368
- });
369
- remover.addEventListener("click", drop);
370
- const el = element("span", { className: "chip" });
371
- el.append(opener, remover);
372
- return el;
373
- };
374
- const shotName = (i) => `Screenshot ${i + 1}`;
375
- const recordingName = (i) => recordings.length === 1 ? "Recording" : `Recording ${i + 1}`;
376
- const voiceName = (i) => voices.length === 1 ? "Voice" : `Voice ${i + 1}`;
377
- /** What's attached, as the lightbox shows it, in the chips' order. */
378
- const viewed = () => [
379
- ...chips.map((c, i) => ({
380
- kind: "image",
381
- url: c.url,
382
- title: shotName(i),
383
- actions: [{
384
- label: "Change marks",
385
- title: "Draw on it again",
386
- run: () => void draw(c)
387
- }]
388
- })),
389
- ...recordings.map((r, i) => ({
390
- kind: "page",
391
- url: `${r.url}${r.url.includes("?") ? "&" : "?"}embed`,
392
- title: `${recordingName(i)} · ${clock(r.duration)}`,
393
- actions: [{
394
- label: "New tab",
395
- title: "Play it back in a tab of its own",
396
- run: () => void window.open(r.url, "_blank", "noopener")
397
- }]
398
- })),
399
- ...voices.map((v, i) => ({
400
- kind: "audio",
401
- url: v.url,
402
- title: `${voiceName(i)} · ${clock(v.duration)}`
403
- }))
404
- ];
405
- const showChips = () => {
406
- const attached = attachedCount() > 0;
407
- shot.hidden = attached;
408
- chipsEl.hidden = !attached;
409
- if (!busy) another.textContent = chips.length > 0 ? "Add another" : "Annotate";
410
- if (!attached) actions.append(...more());
411
- chipsEl.replaceChildren(...chips.map((c, i) => {
412
- const thumb = element("img", {
413
- src: c.url,
414
- alt: ""
415
- });
416
- return chip([thumb, shotName(i)], `Open ${shotName(i).toLowerCase()}`, i, `Remove ${shotName(i).toLowerCase()}`, () => dropShot(c));
417
- }), ...recordings.map((r, i) => {
418
- const play = element("span", {
419
- className: "play",
420
- innerHTML: PLAY
421
- });
422
- return chip([play, `${recordingName(i)} ${clock(r.duration)}${r.voice === void 0 ? "" : " · voice"}`], `Play ${recordingName(i).toLowerCase()} back`, chips.length + i, `Remove ${recordingName(i).toLowerCase()}`, () => {
423
- recordings = recordings.filter((x) => x !== r);
424
- dropped();
425
- });
426
- }), ...voices.map((v, i) => {
427
- const play = element("span", {
428
- className: "play",
429
- innerHTML: PLAY
430
- });
431
- return chip([play, `${voiceName(i)} ${clock(v.duration)}`], `Play ${voiceName(i).toLowerCase()}`, chips.length + recordings.length + i, `Remove ${voiceName(i).toLowerCase()}`, () => {
432
- voices = voices.filter((x) => x !== v);
433
- dropped();
434
- });
435
- }), ...attached && shots !== void 0 && notes !== void 0 && here ? [another] : [], ...attached ? more() : []);
436
- able();
437
- mark();
438
- };
439
- const dropShot = (c) => {
440
- URL.revokeObjectURL(c.url);
441
- chips = chips.filter((x) => x !== c);
442
- dropped();
443
- };
444
- const dropped = () => {
445
- if (attachedCount() === 0) attach.checked = false;
446
- showChips();
447
- };
448
- const toChip = (drawn) => ({
449
- ...drawn,
450
- url: URL.createObjectURL(drawn.png)
451
- });
452
- const reset = () => {
453
- for (const c of chips) URL.revokeObjectURL(c.url);
454
- chips = [];
455
- recordings = [];
456
- voices = [];
457
- attach.checked = true;
458
- showChips();
459
- };
460
- /** Takes a shot and opens it to draw on, or opens a chip's again: saved, it's a chip. */
461
- const draw = async (old) => {
462
- if (shots === void 0 || notes === void 0 || busy) return;
463
- busy = true;
464
- const was = {
465
- annotate: annotate.textContent,
466
- another: another.textContent
1843
+ const own = () => [{
1844
+ target: context.target,
1845
+ own: true,
1846
+ el: context.element
1847
+ }];
1848
+ /**
1849
+ * What the page says of an element: read now, while the page has it, and as the panel left it where the page
1850
+ * has moved on without it (a recording that went on to another), which is the page the task is about.
1851
+ */
1852
+ const seenOf = (a) => {
1853
+ const el = onPage(a);
1854
+ if (el === void 0) return a.seen;
1855
+ const chain = chainOf(el, a.target.loc.file);
1856
+ const { pointed, at } = context;
1857
+ const masked = shots?.masked(el) ?? el;
1858
+ const alike = sameAs(el);
1859
+ return {
1860
+ ...a.own && at !== void 0 ? { point: at } : {},
1861
+ ...a.own && pointed !== void 0 ? { pointed: {
1862
+ path: pathTo(pointed, el),
1863
+ html: pointed.outerHTML.slice(0, 4e3)
1864
+ } } : {},
1865
+ count: alike.length,
1866
+ ...alike.length > 1 ? { which: whichOf(el, alike, masked) } : {},
1867
+ ...chain.length === 0 ? {} : { chain },
1868
+ html: masked.outerHTML.slice(0, HTML)
467
1869
  };
468
- annotate.textContent = another.textContent = old === void 0 ? "Capturing…" : was.another;
469
- problem.textContent = "";
470
- try {
471
- const taken = old?.shot ?? await shots.capture(context.element);
472
- annotate.textContent = was.annotate;
473
- another.textContent = was.another;
474
- const picture = {
475
- url: taken.url,
476
- ...taken.size
477
- };
478
- const marks = await notes.edit(picture, old?.marks ?? [], { signal: aborts.signal });
479
- if (marks === void 0) return;
480
- const next = toChip({
481
- shot: taken,
482
- marks,
483
- png: await notes.flatten(picture, marks)
484
- });
485
- if (old === void 0) chips = [...chips, next];
486
- else {
487
- URL.revokeObjectURL(old.url);
488
- chips = chips.map((c) => c === old ? next : c);
489
- }
490
- showChips();
491
- } catch (e) {
492
- problem.textContent = messageOf(e);
493
- } finally {
494
- annotate.textContent = was.annotate;
495
- another.textContent = was.another;
496
- busy = false;
497
- showChips();
498
- }
499
1870
  };
500
- annotate.addEventListener("click", () => void draw());
501
- another.addEventListener("click", () => void draw());
502
- record.addEventListener("click", () => {
503
- if (recorder === void 0 || busy) return;
504
- speakOff().then(() => {
505
- const drawn = chips.map(({ url: _, ...d }) => d);
506
- const kept = {
507
- text: text.value,
508
- attach: attach.checked,
509
- html: withHtml.checked,
510
- drawn,
511
- recordings,
512
- voices,
513
- facts: facts()
1871
+ /** The page the task is about: this one, or the one the panel left where none of its elements is on this one. */
1872
+ const wherever = (about) => {
1873
+ if (back !== void 0 && about.length > 0 && !about.some((a) => onPage(a) !== void 0)) {
1874
+ const { page, viewport } = back.state;
1875
+ return {
1876
+ page,
1877
+ viewport
514
1878
  };
515
- context.away(kept, () => recorder.record());
516
- });
517
- });
518
- let take;
519
- let ticking;
520
- let stopWave;
521
- const speakOn = async () => {
522
- if (voice === void 0) return;
523
- problem.textContent = "";
524
- speak.disabled = true;
525
- try {
526
- take = await voice.start();
527
- } catch (e) {
528
- problem.textContent = messageOf(e);
529
- return;
530
- } finally {
531
- speak.disabled = false;
532
- }
533
- const started = take.started;
534
- const time = element("span", { className: "time" });
535
- const wave = element("canvas", { className: "wave" });
536
- speak.replaceChildren("● ", time, wave, "Stop");
537
- stopWave = liveWaveform(wave, take.stream, {
538
- played: "#fff",
539
- rest: "rgb(255 255 255 / 0.4)"
540
- });
541
- const tick = () => time.textContent = clock(Date.now() - started);
542
- speak.classList.add("voice-on");
543
- speak.title = "Stop, and attach it";
544
- tick();
545
- ticking = setInterval(tick, 250);
546
- mark();
547
- };
548
- const speakOff = async () => {
549
- const ending = take;
550
- if (ending === void 0) return;
551
- take = void 0;
552
- clearInterval(ticking);
553
- stopWave?.();
554
- stopWave = void 0;
555
- speak.classList.remove("voice-on");
556
- speak.textContent = "Saving…";
557
- try {
558
- voices = [...voices, await ending.stop()];
559
- } catch (e) {
560
- problem.textContent = messageOf(e);
561
- } finally {
562
- speak.textContent = "Voice";
563
- speak.title = "Record your voice, here";
564
- showChips();
565
1879
  }
566
- };
567
- speak.addEventListener("click", () => void (take === void 0 ? speakOn() : speakOff()));
568
- let editing;
569
- const whole = /* @__PURE__ */ new Set();
570
- let edited;
571
- /** Tells the popup what leaving now would lose: a listed task's changed words, or a new one's, typed, attached or being spoken. */
572
- const mark = () => context.unsaved(edited ?? (text.value.trim() !== "" || attachedCount() > 0 || take !== void 0 ? add : void 0));
573
- let shown = context.model;
574
- /** Asks for a change to a listed task and shows the tasks as they are after; the panel's status says why not. */
575
- const change = async (op) => {
576
- try {
577
- editing = void 0;
578
- render(await context.apply(op));
579
- } catch {
580
- render(shown);
581
- }
582
- };
583
- /** A task's words in a field of their own: Save or Ctrl+Enter keeps them, Cancel or Esc leaves them. */
584
- const editor = (t) => {
585
- const item = element("li", { className: "editing" });
586
- item.dataset["deicticModal"] = "";
587
- const field = element("textarea", { value: t.text });
588
- const save = element("button", {
589
- type: "button",
590
- className: "primary",
591
- textContent: "Save"
592
- });
593
- const leave = element("button", {
594
- type: "button",
595
- textContent: "Cancel"
596
- });
597
- const buttons = element("div", { className: "row" });
598
- const right = element("span", { className: "actions" });
599
- right.append(leave, save);
600
- buttons.append(element("code", { textContent: `#${t.id}` }), right);
601
- item.append(field, buttons);
602
- const done = () => {
603
- editing = void 0;
604
- render(shown);
605
- };
606
- const keep = () => {
607
- if (field.value.trim() === "") return;
608
- if (field.value.trim() === t.text) return done();
609
- save.disabled = true;
610
- change({
611
- edit: t.id,
612
- text: field.value
613
- });
614
- };
615
- field.addEventListener("input", () => {
616
- save.disabled = field.value.trim() === "";
617
- edited = field.value.trim() === t.text ? void 0 : save;
618
- mark();
619
- });
620
- field.addEventListener("keydown", (e) => {
621
- if (e.key === "Escape") {
622
- e.stopPropagation();
623
- done();
624
- }
625
- if (e.key !== "Enter" || !(e.ctrlKey || e.metaKey)) return;
626
- e.preventDefault();
627
- keep();
628
- });
629
- save.addEventListener("click", keep);
630
- leave.addEventListener("click", done);
631
- queueMicrotask(() => field.focus());
632
- return item;
633
- };
634
- const render = (model) => {
635
- shown = model;
636
- edited = void 0;
637
- const { channel, link, tasks, elsewhere, watching } = model;
638
- const name = link === void 0 ? element("span") : element("a", {
639
- href: link,
640
- target: "_blank",
641
- rel: "noreferrer",
642
- title: "Open the channel on the board"
643
- });
644
- name.textContent = `#${channel}`;
645
- hint.replaceChildren("to ", name);
646
- if (watching !== void 0) {
647
- const names = new Intl.ListFormat("en", { type: "conjunction" }).format(watching);
648
- const on = watching.length > 0;
649
- const who = element("span", {
650
- className: on ? "watch on" : "watch",
651
- textContent: on ? `${names} watching` : "no agent watching",
652
- title: on ? `${names} ${watching.length === 1 ? "is" : "are"} watching #${channel}, and take${watching.length === 1 ? "s" : ""} each task as it's added` : `A task waits on the board until an agent watches #${channel}: ask yours to watch deictic's tasks`
653
- });
654
- hint.append(" · ", who);
655
- }
656
- /** A task's row: its state, its ID, a link where it has a page, its title, and where it's from when that's said. */
657
- const rowOf = (t, from) => {
658
- const item = element("li");
659
- const state = element("span", {
660
- className: `state ${t.state}`,
661
- title: t.by === void 0 ? t.state : `${t.state} by ${t.by}`
662
- });
663
- state.role = "img";
664
- const id = element("code", { textContent: `#${t.id}` });
665
- const title = element("button", {
666
- type: "button",
667
- className: "title"
668
- });
669
- const show = () => {
670
- const all = whole.has(t.id);
671
- item.classList.toggle("whole", all);
672
- title.textContent = all ? t.text : t.title;
673
- title.title = all ? "Show its first line only" : "Show all of it";
674
- title.ariaExpanded = String(all);
675
- };
676
- title.addEventListener("click", () => {
677
- if (!whole.delete(t.id)) whole.add(t.id);
678
- show();
679
- });
680
- show();
681
- const to = t.link === void 0 ? id : element("a", {
682
- href: t.link,
683
- target: "_blank",
684
- rel: "noreferrer",
685
- title: "Open the task on the board"
686
- });
687
- if (to !== id) to.append(id);
688
- item.append(state, to, title, ...from === void 0 ? [] : [from]);
689
- return item;
690
- };
691
- const { file } = context.target.loc;
692
- fold.hidden = elsewhere.length === 0;
693
- count.textContent = `${elsewhere.length} elsewhere in ${file.split("/").at(-1)}`;
694
- others.replaceChildren(...elsewhere.map((t) => {
695
- if (t.at === void 0) return rowOf(t);
696
- const { line, column, tag } = t.at;
697
- const name = `<${tag}> :${line}`;
698
- const there = document.querySelector(`[data-deictic="${CSS.escape(`${file}:${line}:${column}`)}"]`);
699
- if (there === null) return rowOf(t, element("span", {
700
- className: "place",
701
- textContent: name,
702
- title: `Line ${line}, not on this page now`
703
- }));
704
- const go = element("button", {
705
- type: "button",
706
- className: "place",
707
- textContent: name,
708
- title: `Open the tasks of line ${line}`
709
- });
710
- go.addEventListener("click", () => void context.open("tasks", there));
711
- return rowOf(t, go);
712
- }));
713
- const over = tasks.filter((t) => OVER.has(t.state));
714
- closed.hidden = over.length === 0;
715
- closedCount.textContent = `${over.length} closed`;
716
- ended.replaceChildren(...over.map((t) => rowOf(t)));
717
- const live = tasks.filter((t) => !OVER.has(t.state));
718
- const grew = live.length > list.childElementCount;
719
- list.replaceChildren(...live.map((t) => {
720
- if (t.id === editing && t.open) return editor(t);
721
- const item = rowOf(t, t.at === void 0 ? void 0 : element("span", {
722
- className: "place",
723
- textContent: `was :${t.at.line}`,
724
- title: `Added when this was on line ${t.at.line}: it has moved since`
725
- }));
726
- if (!t.open) return item;
727
- const edit = element("button", {
728
- type: "button",
729
- className: "act",
730
- innerHTML: EDIT,
731
- title: "Edit the task"
732
- });
733
- edit.addEventListener("click", () => {
734
- editing = t.id;
735
- render(shown);
736
- });
737
- const remove = element("button", {
738
- type: "button",
739
- className: "act",
740
- innerHTML: DELETE,
741
- title: "Delete the task"
742
- });
743
- remove.addEventListener("click", () => {
744
- remove.disabled = true;
745
- change({ remove: t.id });
746
- });
747
- const acts = element("span", { className: "acts" });
748
- acts.append(edit, remove);
749
- item.append(acts);
750
- return item;
751
- }));
752
- if (grew) list.scrollTop = list.scrollHeight;
753
- able();
754
- mark();
755
- };
756
- const back = context.resumed;
757
- /**
758
- * What the page says of the element: read now, while the page has it, and as the panel left it where the
759
- * page has moved on without it (a recording that went on to another), which is the page the task is about.
760
- */
761
- const facts = () => {
762
- const { element: el, elements } = context;
763
- if (!here && back !== void 0) return back.state.facts;
764
- const chain = chainOf(el, context.target.loc.file);
765
1880
  return {
766
1881
  page: location.href,
767
1882
  viewport: {
768
1883
  width: innerWidth,
769
1884
  height: innerHeight
770
- },
771
- ...context.pointed === void 0 ? {} : { pointed: {
772
- path: pathTo(context.pointed, el),
773
- html: context.pointed.outerHTML.slice(0, 4e3)
774
- } },
775
- count: elements.length,
776
- ...chain.length === 0 ? {} : { chain },
777
- html: (shots?.masked(el) ?? el).outerHTML.slice(0, HTML)
1885
+ }
778
1886
  };
779
1887
  };
780
- /**
781
- * The shots to attach: each chip's PNG, kept as a shot, as the person drew it, or a shot taken now where the
782
- * box is ticked. Only that one has the element outlined in it (or is as it was taken, where that can't be
783
- * drawn): nothing else in it says what it's about, while a shot someone annotated says what they marked.
784
- */
785
- const screenshotsOf = async () => {
786
- if (shots === void 0) return void 0;
787
- if (chips.length > 0) {
788
- add.textContent = "Uploading…";
789
- return Promise.all(chips.map(async ({ shot: taken, marks, png }) => ({
790
- id: (await shots.upload(png, taken)).id,
791
- box: taken.box,
792
- ...marks.length === 0 ? {} : { marks: marksOf(marks) }
793
- })));
794
- }
795
- if (!attach.checked || recordings.length > 0 || !here) return void 0;
796
- add.textContent = "Capturing…";
797
- const taken = await shots.capture(context.element);
798
- try {
799
- return [{
800
- id: (await shots.upload(await outlined(taken.url, taken), taken)).id,
801
- box: taken.box,
802
- outlined: true
803
- }];
804
- } catch {
805
- return [{
806
- id: taken.id,
807
- box: taken.box
808
- }];
809
- }
810
- };
811
- const send = async () => {
812
- if (busy || sending) return;
813
- await speakOff();
814
- if (able()) return;
815
- sending = true;
816
- able();
817
- problem.textContent = "";
818
- let screenshots;
819
- try {
820
- screenshots = await screenshotsOf();
821
- } catch (e) {
822
- problem.textContent = messageOf(e);
823
- add.textContent = "Add task";
824
- sending = false;
825
- able();
1888
+ const leave = async () => {
1889
+ if (recorder === void 0) return;
1890
+ composer.problem.textContent = "";
1891
+ if (recorder.recording()) {
1892
+ composer.problem.textContent = "A recording is going already: stop it in the tool panel, and it's attached here";
826
1893
  return;
827
1894
  }
828
- add.textContent = "Add task";
829
- try {
830
- const { html, ...said } = facts();
1895
+ await composer.stopTake();
1896
+ const { text, shot, html, about } = composer.draft();
1897
+ const kept = {
1898
+ text,
1899
+ ...shot === void 0 ? {} : { shot },
1900
+ html,
1901
+ ...wherever(about),
1902
+ about: about.flatMap(({ target, own: mine, ...a }) => {
1903
+ const seen = seenOf({
1904
+ target,
1905
+ own: mine,
1906
+ ...a
1907
+ });
1908
+ return seen === void 0 ? [] : [{
1909
+ target,
1910
+ own: mine,
1911
+ seen
1912
+ }];
1913
+ })
1914
+ };
1915
+ context.away(kept, () => recorder.record());
1916
+ };
1917
+ const composer = composerIn(context, {
1918
+ placeholder: "What should change here?",
1919
+ sendLabel: "Add task",
1920
+ about: own,
1921
+ html: sendsHtml,
1922
+ ...context.at === void 0 ? {} : { at: context.at },
1923
+ shoot: true,
1924
+ here: context.element.isConnected,
1925
+ over,
1926
+ record: () => void leave(),
1927
+ changed: () => mark(),
1928
+ submit: async (gathered) => {
1929
+ const { text, about, html: withHtml, screenshots } = gathered;
1930
+ const [first, ...rest] = about;
1931
+ const { html, ...said } = (first === void 0 ? void 0 : seenOf(first)) ?? {
1932
+ html: void 0,
1933
+ count: 0
1934
+ };
1935
+ const htmlOf = (of) => sendsHtml && withHtml && of !== void 0 ? { html: of } : {};
831
1936
  const op = {
832
- text: text.value,
1937
+ text,
1938
+ ...wherever(about),
833
1939
  ...said,
834
- ...sendsHtml && withHtml.checked ? { html } : {},
835
- ...screenshots === void 0 ? {} : { screenshots },
836
- ...recordings.length === 0 ? {} : { recordings: recordings.map(({ id, duration, url, voice: clips }) => ({
837
- id,
838
- duration,
839
- replay: new URL(url, location.href).href,
840
- ...clips === void 0 ? {} : { voice: clips.map((c) => c.id) }
1940
+ ...first === void 0 ? { detached: true } : {},
1941
+ ...htmlOf(html),
1942
+ ...rest.length === 0 ? {} : { also: rest.map((a) => ({
1943
+ at: atOf(a.target),
1944
+ tag: a.target.tag,
1945
+ ...htmlOf(seenOf(a)?.html)
841
1946
  })) },
842
- ...voices.length === 0 ? {} : { voice: voices.map(({ id, duration }) => ({
843
- id,
844
- duration
845
- })) },
846
- ...annotationsOf(notes)
1947
+ ...attachedOf(gathered)
847
1948
  };
848
- const model = await context.apply(op);
849
- render(model);
850
- announce(model, op, context.target);
851
- text.value = "";
852
- reset();
853
- const dropped = model.tasks.at(-1)?.dropped;
854
- if (dropped !== void 0) problem.textContent = `Sent without ${dropped}: it wasn't kept any more`;
855
- } catch {}
856
- sending = false;
857
- able();
1949
+ const on = first?.target ?? context.target;
1950
+ let model;
1951
+ try {
1952
+ model = await context.apply(op, on);
1953
+ } catch {
1954
+ return false;
1955
+ }
1956
+ storeOf(context).load(true);
1957
+ announce(model, op, on, (screenshots ?? []).map((shot) => shot.url));
1958
+ const added = model.tasks.at(-1);
1959
+ composer.note.textContent = first === void 0 ? "Added, about the page: it is in the drawer" : `Added${added === void 0 ? "" : ` #${added.id}`}: it is in the drawer`;
1960
+ if (added?.dropped !== void 0) {
1961
+ composer.problem.textContent = `Sent without ${added.dropped}: it wasn't kept any more`;
1962
+ return true;
1963
+ }
1964
+ setTimeout(context.close);
1965
+ return true;
1966
+ }
1967
+ });
1968
+ panel.append(style, composer.el);
1969
+ composer.el.append(row);
1970
+ /** Tells the popup what leaving now would lose: the words of a new task, or a take. What's attached is the tray's, and stays. */
1971
+ const mark = () => context.unsaved(composer.pending() ? composer.send : void 0);
1972
+ /** Where a task goes, and whether it's taken up: the channel, and who watches it, or that no one does, where that's known. */
1973
+ const render = ({ channel, link, watching }) => {
1974
+ const name = link === void 0 ? element("span") : element("a", {
1975
+ href: link,
1976
+ target: "_blank",
1977
+ rel: "noreferrer",
1978
+ title: "Open the channel on the board"
1979
+ });
1980
+ name.textContent = `#${channel}`;
1981
+ hint.replaceChildren("to ", name);
1982
+ if (watching === void 0) return;
1983
+ const names = new Intl.ListFormat("en", { type: "conjunction" }).format(watching);
1984
+ const on = watching.length > 0;
1985
+ const who = element("span", {
1986
+ className: on ? "watch on" : "watch",
1987
+ textContent: on ? `${names} watching` : "no agent watching",
1988
+ title: on ? `${names} ${watching.length === 1 ? "is" : "are"} watching #${channel}, and take${watching.length === 1 ? "s" : ""} each task as it's added` : `A task waits on the board until an agent watches #${channel}: ask yours to watch deictic's tasks`
1989
+ });
1990
+ hint.append(" · ", who);
858
1991
  };
859
1992
  if (back !== void 0) {
860
1993
  const kept = back.state;
861
- text.value = kept.text;
862
- attach.checked = kept.attach;
863
- withHtml.checked = kept.html;
864
- chips = kept.drawn.map(toChip);
865
- recordings = [...kept.recordings, ...back.result === void 0 ? [] : [back.result]];
866
- voices = kept.voices;
867
- if (back.problem !== void 0) problem.textContent = back.problem;
1994
+ const about = kept.about.map(({ target, own: mine, seen }) => {
1995
+ const el = mine ? context.element : document.querySelector(`[data-deictic="${CSS.escape(atOf(target))}"]`) ?? void 0;
1996
+ return {
1997
+ target,
1998
+ own: mine,
1999
+ seen,
2000
+ ...el === void 0 ? {} : { el }
2001
+ };
2002
+ });
2003
+ const draft = {
2004
+ text: kept.text,
2005
+ html: kept.html,
2006
+ about,
2007
+ ...kept.shot === void 0 ? {} : { shot: kept.shot }
2008
+ };
2009
+ composer.restore(draft);
2010
+ if (back.problem !== void 0) composer.problem.textContent = back.problem;
868
2011
  }
869
- text.addEventListener("input", () => {
870
- able();
871
- mark();
872
- });
873
- text.addEventListener("keydown", (e) => {
874
- if (e.key !== "Enter" || !(e.ctrlKey || e.metaKey)) return;
875
- e.preventDefault();
876
- send();
877
- });
878
- add.addEventListener("click", () => void send());
879
- showChips();
880
2012
  render(context.model);
881
- text.focus();
2013
+ composer.focus();
882
2014
  return () => {
883
- aborts.abort();
884
- take?.cancel();
885
- clearInterval(ticking);
886
- stopWave?.();
887
- for (const c of chips) URL.revokeObjectURL(c.url);
2015
+ unpin?.();
2016
+ composer.destroy();
888
2017
  };
889
2018
  }
890
2019
  });