deictic 0.0.1 → 0.2.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 (176) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -0
  3. package/dist/annotations/client.d.ts +4 -0
  4. package/dist/annotations/client.d.ts.map +1 -0
  5. package/dist/annotations/client.js +497 -0
  6. package/dist/annotations/client.js.map +1 -0
  7. package/dist/annotations/index.d.ts +110 -0
  8. package/dist/annotations/index.d.ts.map +1 -0
  9. package/dist/annotations/index.js +22 -0
  10. package/dist/annotations/index.js.map +1 -0
  11. package/dist/astro.d.ts +29 -0
  12. package/dist/astro.d.ts.map +1 -0
  13. package/dist/astro.js +24 -0
  14. package/dist/astro.js.map +1 -0
  15. package/dist/bun.d.ts +12 -0
  16. package/dist/bun.d.ts.map +1 -0
  17. package/dist/bun.js +67 -0
  18. package/dist/bun.js.map +1 -0
  19. package/dist/client/index.d.ts +95 -0
  20. package/dist/client/index.d.ts.map +1 -0
  21. package/dist/client/index.js +1333 -0
  22. package/dist/client/index.js.map +1 -0
  23. package/dist/index.d.ts +23 -0
  24. package/dist/index.js +10 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/loader.d.ts +15 -0
  27. package/dist/loader.d.ts.map +1 -0
  28. package/dist/loader.js +17 -0
  29. package/dist/loader.js.map +1 -0
  30. package/dist/next.d.ts +17 -0
  31. package/dist/next.d.ts.map +1 -0
  32. package/dist/next.js +150 -0
  33. package/dist/next.js.map +1 -0
  34. package/dist/recommended/index.d.ts +25 -0
  35. package/dist/recommended/index.d.ts.map +1 -0
  36. package/dist/recommended/index.js +19 -0
  37. package/dist/recommended/index.js.map +1 -0
  38. package/dist/recordings/client.d.ts +4 -0
  39. package/dist/recordings/client.d.ts.map +1 -0
  40. package/dist/recordings/client.js +376 -0
  41. package/dist/recordings/client.js.map +1 -0
  42. package/dist/recordings/index.d.ts +2 -0
  43. package/dist/recordings/index.js +3 -0
  44. package/dist/screenshots/client.d.ts +23 -0
  45. package/dist/screenshots/client.d.ts.map +1 -0
  46. package/dist/screenshots/client.js +76 -0
  47. package/dist/screenshots/client.js.map +1 -0
  48. package/dist/screenshots/dom.d.ts +4 -0
  49. package/dist/screenshots/dom.d.ts.map +1 -0
  50. package/dist/screenshots/dom.js +92 -0
  51. package/dist/screenshots/dom.js.map +1 -0
  52. package/dist/screenshots/index.d.ts +2 -0
  53. package/dist/screenshots/index.js +98 -0
  54. package/dist/screenshots/index.js.map +1 -0
  55. package/dist/screenshots/rrweb.d.ts +9 -0
  56. package/dist/screenshots/rrweb.d.ts.map +1 -0
  57. package/dist/screenshots/rrweb.js +60 -0
  58. package/dist/screenshots/rrweb.js.map +1 -0
  59. package/dist/shared/endpoints.js +354 -0
  60. package/dist/shared/endpoints.js.map +1 -0
  61. package/dist/shared/index.d.ts +226 -0
  62. package/dist/shared/index.d.ts.map +1 -0
  63. package/dist/shared/index2.d.ts +98 -0
  64. package/dist/shared/index2.d.ts.map +1 -0
  65. package/dist/shared/index3.d.ts +86 -0
  66. package/dist/shared/index3.d.ts.map +1 -0
  67. package/dist/shared/index4.d.ts +184 -0
  68. package/dist/shared/index4.d.ts.map +1 -0
  69. package/dist/shared/index5.d.ts +70 -0
  70. package/dist/shared/index5.d.ts.map +1 -0
  71. package/dist/shared/integration.d.ts +20 -0
  72. package/dist/shared/integration.d.ts.map +1 -0
  73. package/dist/shared/integration.js +279 -0
  74. package/dist/shared/integration.js.map +1 -0
  75. package/dist/shared/kept.js +23 -0
  76. package/dist/shared/kept.js.map +1 -0
  77. package/dist/shared/marks.js +14 -0
  78. package/dist/shared/marks.js.map +1 -0
  79. package/dist/shared/playwright.js +105 -0
  80. package/dist/shared/playwright.js.map +1 -0
  81. package/dist/shared/recordings.js +246 -0
  82. package/dist/shared/recordings.js.map +1 -0
  83. package/dist/shared/shortcut.js +63 -0
  84. package/dist/shared/shortcut.js.map +1 -0
  85. package/dist/shared/tasks.js +521 -0
  86. package/dist/shared/tasks.js.map +1 -0
  87. package/dist/shared/waveform.js +93 -0
  88. package/dist/shared/waveform.js.map +1 -0
  89. package/dist/tailwind/client.d.ts +4 -0
  90. package/dist/tailwind/client.d.ts.map +1 -0
  91. package/dist/tailwind/client.js +613 -0
  92. package/dist/tailwind/client.js.map +1 -0
  93. package/dist/tailwind/index.d.ts +2 -0
  94. package/dist/tailwind/index.js +557 -0
  95. package/dist/tailwind/index.js.map +1 -0
  96. package/dist/tasks/client.d.ts +6 -0
  97. package/dist/tasks/client.d.ts.map +1 -0
  98. package/dist/tasks/client.js +642 -0
  99. package/dist/tasks/client.js.map +1 -0
  100. package/dist/tasks/index.d.ts +2 -0
  101. package/dist/tasks/index.js +1 -0
  102. package/dist/vite.d.ts +16 -0
  103. package/dist/vite.d.ts.map +1 -0
  104. package/dist/vite.js +61 -0
  105. package/dist/vite.js.map +1 -0
  106. package/dist/voice/client.d.ts +4 -0
  107. package/dist/voice/client.d.ts.map +1 -0
  108. package/dist/voice/client.js +66 -0
  109. package/dist/voice/client.js.map +1 -0
  110. package/dist/voice/index.d.ts +47 -0
  111. package/dist/voice/index.d.ts.map +1 -0
  112. package/dist/voice/index.js +74 -0
  113. package/dist/voice/index.js.map +1 -0
  114. package/dist/webpack.d.ts +50 -0
  115. package/dist/webpack.d.ts.map +1 -0
  116. package/dist/webpack.js +78 -0
  117. package/dist/webpack.js.map +1 -0
  118. package/package.json +307 -7
  119. package/skills/deictic/SKILL.md +47 -0
  120. package/skills/deictic/references/install.md +96 -0
  121. package/skills/deictic/references/recordings.md +83 -0
  122. package/skills/deictic/references/tasks.md +79 -0
  123. package/skills/deictic/references/watch.md +43 -0
  124. package/skills/deictic/scripts/frame.mjs +62 -0
  125. package/skills/deictic/scripts/lib.mjs +211 -0
  126. package/skills/deictic/scripts/recording.mjs +186 -0
  127. package/skills/deictic/scripts/task.mjs +84 -0
  128. package/skills/deictic/scripts/transcribe.mjs +93 -0
  129. package/skills/deictic/scripts/voice.mjs +50 -0
  130. package/skills/deictic/scripts/watch.mjs +51 -0
  131. package/src/astro.ts +34 -0
  132. package/src/bun.ts +79 -0
  133. package/src/client/index.ts +846 -0
  134. package/src/client/lightbox.ts +256 -0
  135. package/src/client/style.ts +243 -0
  136. package/src/client/tooltip.ts +78 -0
  137. package/src/client/waveform.ts +98 -0
  138. package/src/index.ts +247 -0
  139. package/src/loader.ts +28 -0
  140. package/src/next.ts +133 -0
  141. package/src/plugins/annotations/client.ts +301 -0
  142. package/src/plugins/annotations/draw.ts +169 -0
  143. package/src/plugins/annotations/index.ts +105 -0
  144. package/src/plugins/annotations/svg.ts +61 -0
  145. package/src/plugins/recommended/index.ts +35 -0
  146. package/src/plugins/recordings/client.ts +316 -0
  147. package/src/plugins/recordings/index.ts +175 -0
  148. package/src/plugins/recordings/marks.ts +11 -0
  149. package/src/plugins/recordings/ours.ts +70 -0
  150. package/src/plugins/recordings/replay.ts +165 -0
  151. package/src/plugins/screenshots/client.ts +64 -0
  152. package/src/plugins/screenshots/dom.ts +79 -0
  153. package/src/plugins/screenshots/index.ts +194 -0
  154. package/src/plugins/screenshots/playwright.ts +119 -0
  155. package/src/plugins/screenshots/rrweb.ts +45 -0
  156. package/src/plugins/tailwind/catalog.ts +396 -0
  157. package/src/plugins/tailwind/client.ts +669 -0
  158. package/src/plugins/tailwind/index.ts +267 -0
  159. package/src/plugins/tasks/client.ts +622 -0
  160. package/src/plugins/tasks/index.ts +557 -0
  161. package/src/plugins/tasks/local.ts +170 -0
  162. package/src/plugins/voice/client.ts +58 -0
  163. package/src/plugins/voice/index.ts +114 -0
  164. package/src/shortcut.ts +83 -0
  165. package/src/tools/astro.ts +81 -0
  166. package/src/tools/editor.ts +22 -0
  167. package/src/tools/endpoints.ts +163 -0
  168. package/src/tools/history.ts +203 -0
  169. package/src/tools/integration.ts +108 -0
  170. package/src/tools/kept.ts +21 -0
  171. package/src/tools/locate.ts +94 -0
  172. package/src/tools/plugins.ts +41 -0
  173. package/src/tools/source.ts +72 -0
  174. package/src/vite.ts +81 -0
  175. package/src/webpack.ts +107 -0
  176. package/index.js +0 -1
@@ -0,0 +1,642 @@
1
+ import { n as liveWaveform } from "../shared/waveform.js";
2
+ import { defineClientPlugin } from "../index.js";
3
+ // src/plugins/tasks/client.ts
4
+ /**
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
+ * Ctrl+Enter or Add sends it with the page's URL, the viewport and the element as it rendered, which
9
+ * the source can't tell; and where the annotations plugin is loaded, what's marked on the page.
10
+ *
11
+ * Where the screenshots plugin is loaded, a shot of the page goes with it, unless that's unticked. With
12
+ * the annotations plugin too, Annotate takes the shot now and opens it to draw on: saved, it's a chip
13
+ * under the field, which opens it again to change the marks, and Add another takes one more. Any chip
14
+ * (a recording's too) takes the box's place; removing the last brings it back unticked, so a task goes
15
+ * without a shot unless asked again.
16
+ *
17
+ * Where the recordings plugin is loaded, Record leaves the popup (`away`) to record the page, keeping
18
+ * what's typed and attached, and comes back with the recording as a chip too, which plays it back.
19
+ * Where the voice plugin is, Voice records the mic here in the panel: stopped, it's a chip that plays it.
20
+ */
21
+ const STYLE = `
22
+ .tasks { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
23
+ .tasks li { display: flex; gap: 6px; align-items: baseline; }
24
+ .tasks .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
25
+ .tasks .state { font: 11px ui-monospace, monospace; color: var(--deictic-muted); }
26
+ .tasks .state.completed { color: #4ade80; }
27
+ .tasks .state.failed { color: var(--deictic-problem); }
28
+ .tasks a { color: inherit; text-decoration: none; }
29
+ .tasks a:hover { text-decoration: underline; }
30
+ .tasks .act { align-self: center; display: inline-flex; padding: 2px; border: 0; color: var(--deictic-muted); }
31
+ .tasks .act:hover { color: var(--deictic-fg); }
32
+ .tasks .act svg { width: 12px; height: 12px; }
33
+ .tasks li.editing { display: grid; }
34
+ .tasks li.editing .row { margin-top: 0; }
35
+ .tasks li.editing .actions { display: flex; gap: 6px; }
36
+ textarea { min-height: 64px; resize: vertical; font: 13px/1.4 system-ui, sans-serif; }
37
+ .row { display: flex; gap: 6px; margin-top: 8px; justify-content: space-between; align-items: center; }
38
+ .hint { color: var(--deictic-muted); font-size: 12px; }
39
+ .hint a { color: inherit; }
40
+ .hint a:hover { color: var(--deictic-fg); }
41
+ .shot { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--deictic-muted); }
42
+ .shot label { display: flex; gap: 6px; align-items: center; }
43
+ .shot input { width: auto; margin: 0; }
44
+ .shot .actions { display: flex; gap: 6px; margin-left: auto; }
45
+ .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; font-size: 12px; }
46
+ .chip { display: inline-flex; align-items: center; border: 1px solid var(--deictic-line); border-radius: 6px; }
47
+ .chip button { border: 0; }
48
+ .chip .open { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 2px; }
49
+ .chip img { display: block; height: 28px; border-radius: 4px; }
50
+ .chip .play { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 4px; background: var(--deictic-line); }
51
+ .chip .play svg { width: 12px; height: 12px; }
52
+ .chip .remove { padding: 0 6px; color: var(--deictic-muted); }
53
+ .chip .remove:hover { color: var(--deictic-fg); }
54
+ .voice-on { display: inline-flex; align-items: center; gap: 4px; color: #fff; background: #ef4444; border-color: #ef4444; font-variant-numeric: tabular-nums; }
55
+ .voice-on .wave { width: 36px; height: 14px; }
56
+ .shot-problem { margin-top: 4px; font-size: 12px; color: var(--deictic-problem); }
57
+ .shot-problem:empty { display: none; }
58
+ .shot[hidden], .chips[hidden], label[hidden] { display: none; }
59
+ `;
60
+ 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>`;
61
+ const EDIT = ICON("M4 20h4L19 9l-4-4L4 16z");
62
+ const DELETE = ICON("M4 7h16M10 7V4h4v3M6 7l1 13h10l1-13");
63
+ const PLAY = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M7 4v16l13-8z\" fill=\"currentColor\"/></svg>";
64
+ /** Marks as a task tells of them: how many, and what the notes say. */
65
+ function marksOf(list) {
66
+ return {
67
+ count: list.length,
68
+ notes: list.flatMap(({ shape }) => shape.kind === "note" ? [shape.text] : [])
69
+ };
70
+ }
71
+ /** The page's annotations for the op, where there are any. */
72
+ function annotationsOf(marks) {
73
+ const list = marks?.list() ?? [];
74
+ return list.length === 0 ? {} : { annotations: marksOf(list) };
75
+ }
76
+ const clock = (ms) => {
77
+ const s = Math.round(ms / 1e3);
78
+ return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
79
+ };
80
+ const messageOf = (e) => e instanceof Error ? e.message : String(e);
81
+ /**
82
+ * `#shadow-root > div.panel > div.head > button.tab:nth-of-type(2)`: where `inner` is inside `outer`, through
83
+ * shadow roots, by tag, classes and, among siblings alike, place, for whoever finds it in the code.
84
+ */
85
+ function pathTo(inner, outer) {
86
+ const steps = [];
87
+ for (let at = inner; at !== void 0 && at !== outer;) {
88
+ const nameOf = (el) => `${el.localName}${[...el.classList].map((c) => `.${c}`).join("")}`;
89
+ const name = nameOf(at);
90
+ const siblings = at.parentElement === null ? [] : [...at.parentElement.children];
91
+ const same = siblings.filter((c) => nameOf(c) === name).length > 1;
92
+ const alike = siblings.filter((c) => c.localName === at.localName);
93
+ steps.unshift(same ? `${name}:nth-of-type(${alike.indexOf(at) + 1})` : name);
94
+ if (at.parentElement !== null) at = at.parentElement;
95
+ else {
96
+ const root = at.getRootNode();
97
+ if (!(root instanceof ShadowRoot)) break;
98
+ steps.unshift("#shadow-root");
99
+ at = root.host;
100
+ }
101
+ }
102
+ return steps.join(" > ");
103
+ }
104
+ function element(tag, props = {}) {
105
+ return Object.assign(document.createElement(tag), props);
106
+ }
107
+ /** The event the page hears of each added task by, on `window`: its `detail` is a `TaskAdded`. */
108
+ const TASK_ADDED = "deictic:task";
109
+ /** Tells the page of a task just added: the newest of the element's tasks, as the board answered them. */
110
+ function announce(model, op, target) {
111
+ const task = model.tasks.at(-1);
112
+ if (task === void 0) return;
113
+ const marks = (op.annotations?.count ?? 0) + (op.screenshots ?? []).reduce((n, shot) => n + (shot.marks?.count ?? 0), 0);
114
+ const detail = {
115
+ id: task.id,
116
+ title: task.title,
117
+ state: task.state,
118
+ channel: model.channel,
119
+ target,
120
+ page: op.page,
121
+ attached: {
122
+ screenshots: op.screenshots?.length ?? 0,
123
+ recordings: op.recordings?.length ?? 0,
124
+ voice: op.voice?.length ?? 0,
125
+ marks
126
+ }
127
+ };
128
+ window.dispatchEvent(new CustomEvent(TASK_ADDED, { detail }));
129
+ }
130
+ var client_default = defineClientPlugin({
131
+ name: "tasks",
132
+ label: "Task",
133
+ mount: (panel, context) => {
134
+ const style = element("style", { textContent: STYLE });
135
+ const list = element("ul", { className: "tasks" });
136
+ const text = element("textarea", { placeholder: "What should change here?" });
137
+ const add = element("button", {
138
+ type: "button",
139
+ className: "primary",
140
+ textContent: "Add task"
141
+ });
142
+ const hint = element("span", { className: "hint" });
143
+ const row = element("div", { className: "row" });
144
+ row.append(hint, add);
145
+ panel.append(style, list, text);
146
+ const shots = context.use("screenshots");
147
+ const notes = context.use("annotations");
148
+ const recorder = context.use("recordings");
149
+ const voice = context.use("voice");
150
+ const aborts = new AbortController();
151
+ const attach = element("input", {
152
+ type: "checkbox",
153
+ checked: true
154
+ });
155
+ const toggle = element("label", { hidden: shots === void 0 });
156
+ toggle.append(attach, "Attach a screenshot");
157
+ const annotate = element("button", {
158
+ type: "button",
159
+ textContent: "Annotate",
160
+ title: "Take the screenshot now and draw on it"
161
+ });
162
+ const record = element("button", {
163
+ type: "button",
164
+ textContent: "Record",
165
+ title: "Record the page, with a toolbar to draw on it, then come back here"
166
+ });
167
+ const speak = element("button", {
168
+ type: "button",
169
+ textContent: "Voice",
170
+ title: "Record your voice, here"
171
+ });
172
+ const actions = element("span", { className: "actions" });
173
+ actions.append(...shots !== void 0 && notes !== void 0 ? [annotate] : []);
174
+ const shot = element("div", { className: "shot" });
175
+ shot.append(toggle, actions);
176
+ const chipsEl = element("div", { className: "chips" });
177
+ const another = element("button", {
178
+ type: "button",
179
+ textContent: "Add another",
180
+ title: "Take another screenshot and draw on it"
181
+ });
182
+ const problem = element("div", { className: "shot-problem" });
183
+ if (shots !== void 0 || recorder !== void 0 || voice !== void 0) panel.append(shot, chipsEl, problem);
184
+ panel.append(row);
185
+ let chips = [];
186
+ let recordings = [];
187
+ let voices = [];
188
+ let busy = false;
189
+ const attachedCount = () => chips.length + recordings.length + voices.length;
190
+ let sending = false;
191
+ const able = () => add.disabled = sending || text.value.trim() === "" && attachedCount() === 0;
192
+ const more = () => [...recorder !== void 0 ? [record] : [], ...voice !== void 0 ? [speak] : []];
193
+ const chip = (content, title, at, remove, drop) => {
194
+ const opener = element("button", {
195
+ type: "button",
196
+ className: "open",
197
+ title
198
+ });
199
+ opener.append(...content);
200
+ opener.addEventListener("click", () => context.lightbox(viewed(), {
201
+ at,
202
+ from: el
203
+ }));
204
+ const remover = element("button", {
205
+ type: "button",
206
+ className: "remove",
207
+ textContent: "×",
208
+ title: remove
209
+ });
210
+ remover.addEventListener("click", drop);
211
+ const el = element("span", { className: "chip" });
212
+ el.append(opener, remover);
213
+ return el;
214
+ };
215
+ const shotName = (i) => `Screenshot ${i + 1}`;
216
+ const recordingName = (i) => recordings.length === 1 ? "Recording" : `Recording ${i + 1}`;
217
+ const voiceName = (i) => voices.length === 1 ? "Voice" : `Voice ${i + 1}`;
218
+ /** What's attached, as the lightbox shows it, in the chips' order. */
219
+ const viewed = () => [
220
+ ...chips.map((c, i) => ({
221
+ kind: "image",
222
+ url: c.url,
223
+ title: shotName(i),
224
+ actions: [{
225
+ label: "Change marks",
226
+ title: "Draw on it again",
227
+ run: () => void draw(c)
228
+ }]
229
+ })),
230
+ ...recordings.map((r, i) => ({
231
+ kind: "page",
232
+ url: `${r.url}${r.url.includes("?") ? "&" : "?"}embed`,
233
+ title: `${recordingName(i)} · ${clock(r.duration)}`,
234
+ actions: [{
235
+ label: "New tab",
236
+ title: "Play it back in a tab of its own",
237
+ run: () => void window.open(r.url, "_blank", "noopener")
238
+ }]
239
+ })),
240
+ ...voices.map((v, i) => ({
241
+ kind: "audio",
242
+ url: v.url,
243
+ title: `${voiceName(i)} · ${clock(v.duration)}`
244
+ }))
245
+ ];
246
+ const showChips = () => {
247
+ const attached = attachedCount() > 0;
248
+ shot.hidden = attached;
249
+ chipsEl.hidden = !attached;
250
+ if (!busy) another.textContent = chips.length > 0 ? "Add another" : "Annotate";
251
+ if (!attached) actions.append(...more());
252
+ chipsEl.replaceChildren(...chips.map((c, i) => {
253
+ const thumb = element("img", {
254
+ src: c.url,
255
+ alt: ""
256
+ });
257
+ return chip([thumb, shotName(i)], `Open ${shotName(i).toLowerCase()}`, i, `Remove ${shotName(i).toLowerCase()}`, () => dropShot(c));
258
+ }), ...recordings.map((r, i) => {
259
+ const play = element("span", {
260
+ className: "play",
261
+ innerHTML: PLAY
262
+ });
263
+ 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()}`, () => {
264
+ recordings = recordings.filter((x) => x !== r);
265
+ dropped();
266
+ });
267
+ }), ...voices.map((v, i) => {
268
+ const play = element("span", {
269
+ className: "play",
270
+ innerHTML: PLAY
271
+ });
272
+ return chip([play, `${voiceName(i)} ${clock(v.duration)}`], `Play ${voiceName(i).toLowerCase()}`, chips.length + recordings.length + i, `Remove ${voiceName(i).toLowerCase()}`, () => {
273
+ voices = voices.filter((x) => x !== v);
274
+ dropped();
275
+ });
276
+ }), ...attached && shots !== void 0 && notes !== void 0 ? [another] : [], ...attached ? more() : []);
277
+ able();
278
+ mark();
279
+ };
280
+ const dropShot = (c) => {
281
+ URL.revokeObjectURL(c.url);
282
+ chips = chips.filter((x) => x !== c);
283
+ dropped();
284
+ };
285
+ const dropped = () => {
286
+ if (attachedCount() === 0) attach.checked = false;
287
+ showChips();
288
+ };
289
+ const toChip = (drawn) => ({
290
+ ...drawn,
291
+ url: URL.createObjectURL(drawn.png)
292
+ });
293
+ const reset = () => {
294
+ for (const c of chips) URL.revokeObjectURL(c.url);
295
+ chips = [];
296
+ recordings = [];
297
+ voices = [];
298
+ attach.checked = true;
299
+ showChips();
300
+ };
301
+ /** Takes a shot and opens it to draw on, or opens a chip's again: saved, it's a chip. */
302
+ const draw = async (old) => {
303
+ if (shots === void 0 || notes === void 0 || busy) return;
304
+ busy = true;
305
+ const was = {
306
+ annotate: annotate.textContent,
307
+ another: another.textContent
308
+ };
309
+ annotate.textContent = another.textContent = old === void 0 ? "Capturing…" : was.another;
310
+ problem.textContent = "";
311
+ try {
312
+ const taken = old?.shot ?? await shots.capture(context.element);
313
+ annotate.textContent = was.annotate;
314
+ another.textContent = was.another;
315
+ const picture = {
316
+ url: taken.url,
317
+ ...taken.size
318
+ };
319
+ const marks = await notes.edit(picture, old?.marks ?? [], { signal: aborts.signal });
320
+ if (marks === void 0) return;
321
+ const next = toChip({
322
+ shot: taken,
323
+ marks,
324
+ png: await notes.flatten(picture, marks)
325
+ });
326
+ if (old === void 0) chips = [...chips, next];
327
+ else {
328
+ URL.revokeObjectURL(old.url);
329
+ chips = chips.map((c) => c === old ? next : c);
330
+ }
331
+ showChips();
332
+ } catch (e) {
333
+ problem.textContent = messageOf(e);
334
+ } finally {
335
+ annotate.textContent = was.annotate;
336
+ another.textContent = was.another;
337
+ busy = false;
338
+ showChips();
339
+ }
340
+ };
341
+ annotate.addEventListener("click", () => void draw());
342
+ another.addEventListener("click", () => void draw());
343
+ record.addEventListener("click", () => {
344
+ if (recorder === void 0 || busy) return;
345
+ speakOff().then(() => {
346
+ const drawn = chips.map(({ url: _, ...d }) => d);
347
+ const kept = {
348
+ text: text.value,
349
+ attach: attach.checked,
350
+ drawn,
351
+ recordings,
352
+ voices
353
+ };
354
+ context.away(kept, () => recorder.record());
355
+ });
356
+ });
357
+ let take;
358
+ let ticking;
359
+ let stopWave;
360
+ const speakOn = async () => {
361
+ if (voice === void 0) return;
362
+ problem.textContent = "";
363
+ speak.disabled = true;
364
+ try {
365
+ take = await voice.start();
366
+ } catch (e) {
367
+ problem.textContent = messageOf(e);
368
+ return;
369
+ } finally {
370
+ speak.disabled = false;
371
+ }
372
+ const started = take.started;
373
+ const time = element("span", { className: "time" });
374
+ const wave = element("canvas", { className: "wave" });
375
+ speak.replaceChildren("● ", time, wave, "Stop");
376
+ stopWave = liveWaveform(wave, take.stream, {
377
+ played: "#fff",
378
+ rest: "rgb(255 255 255 / 0.4)"
379
+ });
380
+ const tick = () => time.textContent = clock(Date.now() - started);
381
+ speak.classList.add("voice-on");
382
+ speak.title = "Stop, and attach it";
383
+ tick();
384
+ ticking = setInterval(tick, 250);
385
+ mark();
386
+ };
387
+ const speakOff = async () => {
388
+ const ending = take;
389
+ if (ending === void 0) return;
390
+ take = void 0;
391
+ clearInterval(ticking);
392
+ stopWave?.();
393
+ stopWave = void 0;
394
+ speak.classList.remove("voice-on");
395
+ speak.textContent = "Saving…";
396
+ try {
397
+ voices = [...voices, await ending.stop()];
398
+ } catch (e) {
399
+ problem.textContent = messageOf(e);
400
+ } finally {
401
+ speak.textContent = "Voice";
402
+ speak.title = "Record your voice, here";
403
+ showChips();
404
+ }
405
+ };
406
+ speak.addEventListener("click", () => void (take === void 0 ? speakOn() : speakOff()));
407
+ let editing;
408
+ let edited;
409
+ /** Tells the popup what leaving now would lose: a listed task's changed words, or a new one's, typed, attached or being spoken. */
410
+ const mark = () => context.unsaved(edited ?? (text.value.trim() !== "" || attachedCount() > 0 || take !== void 0 ? add : void 0));
411
+ let shown = context.model;
412
+ /** Asks for a change to a listed task and shows the tasks as they are after; the panel's status says why not. */
413
+ const change = async (op) => {
414
+ try {
415
+ editing = void 0;
416
+ render(await context.apply(op));
417
+ } catch {
418
+ render(shown);
419
+ }
420
+ };
421
+ /** A task's words in a field of their own: Save or Ctrl+Enter keeps them, Cancel or Esc leaves them. */
422
+ const editor = (t) => {
423
+ const item = element("li", { className: "editing" });
424
+ item.dataset["deicticModal"] = "";
425
+ const field = element("textarea", { value: t.text });
426
+ const save = element("button", {
427
+ type: "button",
428
+ className: "primary",
429
+ textContent: "Save"
430
+ });
431
+ const leave = element("button", {
432
+ type: "button",
433
+ textContent: "Cancel"
434
+ });
435
+ const buttons = element("div", { className: "row" });
436
+ const right = element("span", { className: "actions" });
437
+ right.append(leave, save);
438
+ buttons.append(element("code", { textContent: `#${t.id}` }), right);
439
+ item.append(field, buttons);
440
+ const done = () => {
441
+ editing = void 0;
442
+ render(shown);
443
+ };
444
+ const keep = () => {
445
+ if (field.value.trim() === "") return;
446
+ if (field.value.trim() === t.text) return done();
447
+ save.disabled = true;
448
+ change({
449
+ edit: t.id,
450
+ text: field.value
451
+ });
452
+ };
453
+ field.addEventListener("input", () => {
454
+ save.disabled = field.value.trim() === "";
455
+ edited = field.value.trim() === t.text ? void 0 : save;
456
+ mark();
457
+ });
458
+ field.addEventListener("keydown", (e) => {
459
+ if (e.key === "Escape") {
460
+ e.stopPropagation();
461
+ done();
462
+ }
463
+ if (e.key !== "Enter" || !(e.ctrlKey || e.metaKey)) return;
464
+ e.preventDefault();
465
+ keep();
466
+ });
467
+ save.addEventListener("click", keep);
468
+ leave.addEventListener("click", done);
469
+ queueMicrotask(() => field.focus());
470
+ return item;
471
+ };
472
+ const render = (model) => {
473
+ shown = model;
474
+ edited = void 0;
475
+ const { channel, link, tasks } = model;
476
+ const name = link === void 0 ? element("span") : element("a", {
477
+ href: link,
478
+ target: "_blank",
479
+ rel: "noreferrer",
480
+ title: "Open the channel on the board"
481
+ });
482
+ name.textContent = `#${channel}`;
483
+ hint.replaceChildren("to ", name);
484
+ list.replaceChildren(...tasks.map((t) => {
485
+ if (t.id === editing && t.open) return editor(t);
486
+ const item = element("li");
487
+ const id = element("code", { textContent: `#${t.id}` });
488
+ const title = element("span", {
489
+ className: "title",
490
+ textContent: t.title,
491
+ title: t.title
492
+ });
493
+ const state = element("span", {
494
+ className: `state ${t.state}`,
495
+ textContent: t.state
496
+ });
497
+ if (t.link === void 0) item.append(id, title, state);
498
+ else {
499
+ const to = element("a", {
500
+ href: t.link,
501
+ target: "_blank",
502
+ rel: "noreferrer",
503
+ title: "Open the task on the board"
504
+ });
505
+ to.append(id);
506
+ item.append(to, title, state);
507
+ }
508
+ if (!t.open) return item;
509
+ const edit = element("button", {
510
+ type: "button",
511
+ className: "act",
512
+ innerHTML: EDIT,
513
+ title: "Edit the task"
514
+ });
515
+ edit.addEventListener("click", () => {
516
+ editing = t.id;
517
+ render(shown);
518
+ });
519
+ const remove = element("button", {
520
+ type: "button",
521
+ className: "act",
522
+ innerHTML: DELETE,
523
+ title: "Delete the task"
524
+ });
525
+ remove.addEventListener("click", () => {
526
+ remove.disabled = true;
527
+ change({ remove: t.id });
528
+ });
529
+ item.append(edit, remove);
530
+ return item;
531
+ }));
532
+ able();
533
+ mark();
534
+ };
535
+ /** The shots to attach: each chip's PNG, kept as a shot, or a shot taken now where the box is ticked. */
536
+ const screenshotsOf = async () => {
537
+ if (shots === void 0) return void 0;
538
+ if (chips.length > 0) {
539
+ add.textContent = "Uploading…";
540
+ return Promise.all(chips.map(async ({ shot: taken, marks, png }) => ({
541
+ id: (await shots.upload(png, taken)).id,
542
+ box: taken.box,
543
+ ...marks.length === 0 ? {} : { marks: marksOf(marks) }
544
+ })));
545
+ }
546
+ if (!attach.checked || recordings.length > 0) return void 0;
547
+ add.textContent = "Capturing…";
548
+ const { id, box } = await shots.capture(context.element);
549
+ return [{
550
+ id,
551
+ box
552
+ }];
553
+ };
554
+ const send = async () => {
555
+ if (busy || sending) return;
556
+ await speakOff();
557
+ if (able()) return;
558
+ sending = true;
559
+ able();
560
+ problem.textContent = "";
561
+ let screenshots;
562
+ try {
563
+ screenshots = await screenshotsOf();
564
+ } catch (e) {
565
+ problem.textContent = messageOf(e);
566
+ add.textContent = "Add task";
567
+ sending = false;
568
+ able();
569
+ return;
570
+ }
571
+ add.textContent = "Add task";
572
+ const { element: el, elements } = context;
573
+ try {
574
+ const op = {
575
+ text: text.value,
576
+ page: location.href,
577
+ viewport: {
578
+ width: innerWidth,
579
+ height: innerHeight
580
+ },
581
+ ...context.pointed === void 0 ? {} : { pointed: {
582
+ path: pathTo(context.pointed, el),
583
+ html: context.pointed.outerHTML.slice(0, 4e3)
584
+ } },
585
+ count: elements.length,
586
+ ...screenshots === void 0 ? {} : { screenshots },
587
+ ...recordings.length === 0 ? {} : { recordings: recordings.map(({ id, duration, url, voice: clips }) => ({
588
+ id,
589
+ duration,
590
+ replay: new URL(url, location.href).href,
591
+ ...clips === void 0 ? {} : { voice: clips.map((c) => c.id) }
592
+ })) },
593
+ ...voices.length === 0 ? {} : { voice: voices.map(({ id, duration }) => ({
594
+ id,
595
+ duration
596
+ })) },
597
+ ...annotationsOf(notes)
598
+ };
599
+ const model = await context.apply(op);
600
+ render(model);
601
+ announce(model, op, context.target);
602
+ text.value = "";
603
+ reset();
604
+ } catch {}
605
+ sending = false;
606
+ able();
607
+ };
608
+ const back = context.resumed;
609
+ if (back !== void 0) {
610
+ const kept = back.state;
611
+ text.value = kept.text;
612
+ attach.checked = kept.attach;
613
+ chips = kept.drawn.map(toChip);
614
+ recordings = [...kept.recordings, ...back.result === void 0 ? [] : [back.result]];
615
+ voices = kept.voices;
616
+ if (back.problem !== void 0) problem.textContent = back.problem;
617
+ }
618
+ text.addEventListener("input", () => {
619
+ able();
620
+ mark();
621
+ });
622
+ text.addEventListener("keydown", (e) => {
623
+ if (e.key !== "Enter" || !(e.ctrlKey || e.metaKey)) return;
624
+ e.preventDefault();
625
+ send();
626
+ });
627
+ add.addEventListener("click", () => void send());
628
+ showChips();
629
+ render(context.model);
630
+ text.focus();
631
+ return () => {
632
+ aborts.abort();
633
+ take?.cancel();
634
+ clearInterval(ticking);
635
+ stopWave?.();
636
+ for (const c of chips) URL.revokeObjectURL(c.url);
637
+ };
638
+ }
639
+ });
640
+ export { TASK_ADDED, client_default as default };
641
+
642
+ //# sourceMappingURL=client.js.map