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,497 @@
1
+ import { defineClientPlugin } from "../index.js";
2
+ const PAD = 6;
3
+ const guess = (text) => text.length * 14 * .6;
4
+ const escape = (text) => text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;");
5
+ const n = (value) => Math.round(value * 10) / 10;
6
+ /** An arrow's path: its line, then its head, two strokes back from the tip either side of the line. */
7
+ function arrow(from, to) {
8
+ const angle = Math.atan2(to.y - from.y, to.x - from.x);
9
+ const at = (p) => `${n(p.x)},${n(p.y)}`;
10
+ const side = (turn) => at({
11
+ x: to.x - 14 * Math.cos(angle + turn),
12
+ y: to.y - 14 * Math.sin(angle + turn)
13
+ });
14
+ return `M${at(from)} L${at(to)} M${side(.45)} L${at(to)} L${side(-.45)}`;
15
+ }
16
+ function shapeOf({ shape, color }, measure) {
17
+ const line = `fill="none" stroke="${escape(color)}" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"`;
18
+ switch (shape.kind) {
19
+ case "box": return `<rect x="${n(shape.x)}" y="${n(shape.y)}" width="${n(shape.width)}" height="${n(shape.height)}" rx="4" ${line}/>`;
20
+ case "arrow": return `<path d="${arrow(shape.from, shape.to)}" ${line}/>`;
21
+ case "pen": return `<polyline points="${shape.points.map((p) => `${n(p.x)},${n(p.y)}`).join(" ")}" ${line}/>`;
22
+ case "note": {
23
+ const lines = shape.text.split("\n");
24
+ const width = Math.max(...lines.map(measure)) + 12;
25
+ const height = lines.length * 14 * 1.3 + 12;
26
+ const text = lines.map((l, i) => `<tspan x="${n(shape.at.x + PAD)}" y="${n(shape.at.y + PAD + 14 * (i + 1) * 1.3 - 4.2)}">${escape(l)}</tspan>`).join("");
27
+ return `<rect x="${n(shape.at.x)}" y="${n(shape.at.y)}" width="${n(width)}" height="${n(height)}" rx="4" fill="${escape(color)}"/><text font-family="system-ui, sans-serif" font-size="14" fill="#fff">${text}</text>`;
28
+ }
29
+ }
30
+ }
31
+ /**
32
+ * The annotations over `area` of the viewport, the page scrolled by `scroll`: an SVG `area`'s size,
33
+ * whose view is that part of the page.
34
+ */
35
+ function toSvg(annotations, area, scroll, measure = guess) {
36
+ const view = `${n(area.x + scroll.x)} ${n(area.y + scroll.y)} ${n(area.width)} ${n(area.height)}`;
37
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${n(area.width)}" height="${n(area.height)}" viewBox="${view}">${annotations.map((a) => shapeOf(a, measure)).join("")}</svg>`;
38
+ }
39
+ // src/plugins/annotations/draw.ts
40
+ const TOOLS_STYLE = `
41
+ .annotations-tools { display: flex; flex-wrap: wrap; gap: 4px; }
42
+ .annotations-tools .icon { display: inline-flex; align-items: center; justify-content: center; padding: 3px 5px; }
43
+ .annotations-tools .icon svg { width: 16px; height: 16px; }
44
+ .annotations-tools .gap { width: 1px; align-self: stretch; margin: 2px 4px; background: var(--deictic-line); }
45
+ .annotations-tools button[aria-pressed='true'] { background: var(--deictic-accent); border-color: var(--deictic-accent); color: var(--deictic-on-accent); }
46
+ .annotations-tools .end { margin-left: auto; }
47
+ .annotations-hint { margin: 6px 0 0; font-size: 12px; color: var(--deictic-muted); }
48
+ `;
49
+ const TOOLS = [
50
+ "box",
51
+ "arrow",
52
+ "pen",
53
+ "note"
54
+ ];
55
+ const NAMES = {
56
+ pointer: "Use the page",
57
+ box: "Draw a box",
58
+ arrow: "Draw an arrow",
59
+ pen: "Draw freehand",
60
+ note: "Add a note"
61
+ };
62
+ /** Each icon's strokes, on a 24-pixel grid: drawn here, so the page half needs nothing to show them. */
63
+ const ICONS = {
64
+ pointer: "<path d=\"M5 3l14 7-6 2-2 6z\"/>",
65
+ box: "<rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"2\"/>",
66
+ arrow: "<path d=\"M6 18 18 6M9 6h9v9\"/>",
67
+ pen: "<path d=\"M4 20l1-4L16 5a2.1 2.1 0 0 1 3 3L8 19z\"/>",
68
+ note: "<path d=\"M4 5h16v11H9l-5 4zM8 9h8M8 12h5\"/>",
69
+ undo: "<path d=\"M9 14 4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3\"/>",
70
+ clear: "<path d=\"M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3\"/>"
71
+ };
72
+ /** A button that shows an icon, with its name as its tooltip and for a screen reader. */
73
+ function iconButton(icon, name, run) {
74
+ const el = button("", name, run);
75
+ el.className = "icon";
76
+ el.setAttribute("aria-label", name);
77
+ el.innerHTML = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS[icon]}</svg>`;
78
+ return el;
79
+ }
80
+ /** Text's width as the marks draw it, by a canvas's measure, which the guess stands in for without one. */
81
+ function measurer() {
82
+ const ctx = document.createElement("canvas").getContext("2d");
83
+ if (ctx === null) return guess;
84
+ ctx.font = `14px system-ui, sans-serif`;
85
+ return (text) => ctx.measureText(text).width;
86
+ }
87
+ function button(label, title, run) {
88
+ const el = Object.assign(document.createElement("button"), {
89
+ type: "button",
90
+ textContent: label,
91
+ title
92
+ });
93
+ el.addEventListener("click", run);
94
+ return el;
95
+ }
96
+ /**
97
+ * Draws on `surface` with the tool picked: answers the toolbar (the tools, then removing the last mark or all), for the
98
+ * caller to add its own buttons to, and a hint for the tool.
99
+ */
100
+ function drawing({ surface, at, preview, add, removeLast, clear, drawing: on }) {
101
+ const tools = document.createElement("div");
102
+ tools.className = "annotations-tools";
103
+ const hint = document.createElement("p");
104
+ hint.className = "annotations-hint";
105
+ let tool = on === void 0 ? "box" : "pointer";
106
+ const picks = (on === void 0 ? TOOLS : ["pointer", ...TOOLS]).map((t) => ({
107
+ t,
108
+ el: iconButton(t, NAMES[t], () => pick(t))
109
+ }));
110
+ const pick = (t) => {
111
+ tool = t;
112
+ for (const p of picks) p.el.setAttribute("aria-pressed", String(p.t === t));
113
+ on?.(t !== "pointer");
114
+ hint.textContent = t === "pointer" ? "Use the page; pick a tool to draw." : t === "note" ? "Click where the note goes, type it, Enter to place it." : "Drag to draw.";
115
+ };
116
+ const gap = document.createElement("span");
117
+ gap.className = "gap";
118
+ tools.append(...picks.map((p) => p.el), gap, iconButton("undo", "Remove the last mark", removeLast), iconButton("clear", "Remove every mark", clear));
119
+ pick(tool);
120
+ surface.style.cursor = "crosshair";
121
+ const shapeFrom = (from, to, points) => {
122
+ if (tool === "pen") return points.length > 1 ? {
123
+ kind: "pen",
124
+ points
125
+ } : void 0;
126
+ if (Math.hypot(to.x - from.x, to.y - from.y) < 4) return void 0;
127
+ if (tool === "arrow") return {
128
+ kind: "arrow",
129
+ from,
130
+ to
131
+ };
132
+ return {
133
+ kind: "box",
134
+ x: Math.min(from.x, to.x),
135
+ y: Math.min(from.y, to.y),
136
+ width: Math.abs(to.x - from.x),
137
+ height: Math.abs(to.y - from.y)
138
+ };
139
+ };
140
+ surface.addEventListener("pointerdown", (e) => {
141
+ if (e.button !== 0 || e.target instanceof HTMLInputElement) return;
142
+ e.preventDefault();
143
+ if (tool === "note") return note(at(e), e);
144
+ const from = at(e);
145
+ const points = [from];
146
+ surface.setPointerCapture(e.pointerId);
147
+ const move = (m) => {
148
+ points.push(at(m));
149
+ preview(shapeFrom(from, at(m), points));
150
+ };
151
+ const up = (u) => {
152
+ surface.removeEventListener("pointermove", move);
153
+ preview(void 0);
154
+ const shape = shapeFrom(from, at(u), points);
155
+ if (shape !== void 0) add(shape);
156
+ };
157
+ surface.addEventListener("pointermove", move);
158
+ surface.addEventListener("pointerup", up, { once: true });
159
+ });
160
+ /** A field where the note goes: Enter places what's typed, leaving it empty or blurring it places nothing. */
161
+ const note = (point, e) => {
162
+ const field = Object.assign(document.createElement("input"), { placeholder: "Note, then Enter" });
163
+ field.style.cssText = `position:fixed;left:${e.clientX}px;top:${e.clientY}px;width:220px;pointer-events:auto;cursor:text;color:var(--deictic-fg);background:var(--deictic-bg);border-color:var(--deictic-accent)`;
164
+ surface.append(field);
165
+ const place = () => {
166
+ const text = field.value.trim();
167
+ field.remove();
168
+ if (text !== "") add({
169
+ kind: "note",
170
+ at: point,
171
+ text
172
+ });
173
+ };
174
+ field.addEventListener("keydown", (k) => k.key === "Enter" && place());
175
+ field.addEventListener("blur", () => field.isConnected && place());
176
+ field.focus();
177
+ };
178
+ return {
179
+ tools,
180
+ hint
181
+ };
182
+ }
183
+ // src/plugins/annotations/client.ts
184
+ /**
185
+ * Annotations in the page. `setup` keeps them (in the tab's session storage, per page) and shows them in a
186
+ * layer of deictic's overlay that lets the pointer through; it answers the API other plugins `use`. The
187
+ * panel is annotate mode: a toolbar, and while it's open a surface over the page that takes the pointer, so
188
+ * drawing never clicks the page. Esc or Done leaves it; the marks stay.
189
+ *
190
+ * The layer is deictic's, so a screenshot leaves it out with the rest of the overlay and draws the marks
191
+ * itself from `svg(area)`: one way to draw them, wherever a shot is rendered. `edit` draws on a picture
192
+ * instead, a shot most often, in the same toolbar over everything, and `flatten` makes the PNG of it.
193
+ */
194
+ /** Under deictic's outline and panels, over the page. */
195
+ const LAYER = 0x7ffffffd;
196
+ /** Over everything of deictic's, the popup too. */
197
+ const TOP = 0x7fffffff;
198
+ const scroll = () => ({
199
+ x: scrollX,
200
+ y: scrollY
201
+ });
202
+ const viewport = () => ({
203
+ x: 0,
204
+ y: 0,
205
+ width: document.documentElement.clientWidth,
206
+ height: document.documentElement.clientHeight
207
+ });
208
+ const mark = (shape, color) => ({
209
+ id: crypto.randomUUID(),
210
+ color,
211
+ shape,
212
+ at: Date.now()
213
+ });
214
+ /** What's kept for this page in the tab's session, read as it can be. */
215
+ function stored(key) {
216
+ try {
217
+ const kept = JSON.parse(sessionStorage.getItem(key) ?? "[]");
218
+ return Array.isArray(kept) ? kept : [];
219
+ } catch {
220
+ return [];
221
+ }
222
+ }
223
+ function fixed(z) {
224
+ const el = document.createElement("div");
225
+ el.style.cssText = `position:fixed;inset:0;z-index:${z};pointer-events:none`;
226
+ return el;
227
+ }
228
+ const EDITOR_STYLE = `
229
+ .annotations-editor { position: fixed; inset: 0; z-index: ${TOP}; box-sizing: border-box; padding: 16px; display: flex;
230
+ flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgb(0 0 0 / 0.75);
231
+ font: 13px/1.4 system-ui, sans-serif; color: var(--deictic-fg); }
232
+ .annotations-editor .bar { box-sizing: border-box; width: min(100%, 720px); padding: 6px 8px; border: 1px solid var(--deictic-line);
233
+ border-radius: 8px; background: var(--deictic-bg); }
234
+ .annotations-editor .stage { position: relative; line-height: 0; box-shadow: 0 12px 32px rgb(0 0 0 / 0.5); touch-action: none; }
235
+ .annotations-editor img { display: block; max-width: calc(100vw - 32px); max-height: calc(100vh - 120px); user-select: none; }
236
+ .annotations-editor .marks { position: absolute; inset: 0; pointer-events: none; }
237
+ `;
238
+ /** Loads an image, decoded. */
239
+ async function image(src) {
240
+ const el = new Image();
241
+ el.src = src;
242
+ await el.decode();
243
+ return el;
244
+ }
245
+ /** The marks over a whole picture, as an SVG whose view is the picture's CSS pixels. */
246
+ const over = (picture, marks, measure) => toSvg(marks, {
247
+ x: 0,
248
+ y: 0,
249
+ width: picture.width,
250
+ height: picture.height
251
+ }, {
252
+ x: 0,
253
+ y: 0
254
+ }, measure);
255
+ /**
256
+ * The picture over everything, to draw on: the marks on Save, nothing on Cancel, Esc or `signal`. It holds
257
+ * Esc while it's open (`data-deictic-modal`), so Esc leaves it, not the popup under it.
258
+ */
259
+ function edit(root, picture, start, { color, measure, signal }) {
260
+ return new Promise((resolve) => {
261
+ let marks = [...start];
262
+ const backdrop = document.createElement("div");
263
+ backdrop.className = "annotations-editor";
264
+ backdrop.dataset.deicticModal = "";
265
+ const style = document.createElement("style");
266
+ style.textContent = TOOLS_STYLE + EDITOR_STYLE;
267
+ const bar = document.createElement("div");
268
+ bar.className = "bar";
269
+ const stage = document.createElement("div");
270
+ stage.className = "stage";
271
+ const img = Object.assign(document.createElement("img"), {
272
+ src: picture.url,
273
+ alt: "The screenshot",
274
+ draggable: false
275
+ });
276
+ const layer = document.createElement("div");
277
+ layer.className = "marks";
278
+ stage.append(img, layer);
279
+ const show = (preview) => {
280
+ layer.innerHTML = over(picture, preview === void 0 ? marks : [...marks, mark(preview, color)], measure);
281
+ const svg = layer.firstElementChild;
282
+ svg?.setAttribute("width", "100%");
283
+ svg?.setAttribute("height", "100%");
284
+ };
285
+ const { tools, hint } = drawing({
286
+ surface: stage,
287
+ at: (e) => {
288
+ const r = stage.getBoundingClientRect();
289
+ return {
290
+ x: (e.clientX - r.left) * picture.width / r.width,
291
+ y: (e.clientY - r.top) * picture.height / r.height
292
+ };
293
+ },
294
+ preview: (shape) => show(shape),
295
+ add: (shape) => {
296
+ marks = [...marks, mark(shape, color)];
297
+ show();
298
+ },
299
+ removeLast: () => {
300
+ marks = marks.slice(0, -1);
301
+ show();
302
+ },
303
+ clear: () => {
304
+ marks = [];
305
+ show();
306
+ }
307
+ });
308
+ const end = (result) => {
309
+ backdrop.remove();
310
+ window.removeEventListener("keydown", onKey, true);
311
+ signal?.removeEventListener("abort", cancel);
312
+ resolve(result);
313
+ };
314
+ const cancel = () => end(void 0);
315
+ const onKey = (e) => {
316
+ if (e.key !== "Escape") return;
317
+ e.stopPropagation();
318
+ cancel();
319
+ };
320
+ const save = button("Save", "Keep these marks", () => end(marks));
321
+ save.classList.add("primary");
322
+ const back = button("Cancel", "Leave it as it was (Esc)", cancel);
323
+ back.classList.add("end");
324
+ tools.append(back, save);
325
+ bar.append(tools, hint);
326
+ backdrop.append(style, bar, stage);
327
+ root.append(backdrop);
328
+ window.addEventListener("keydown", onKey, true);
329
+ signal?.addEventListener("abort", cancel);
330
+ show();
331
+ });
332
+ }
333
+ /**
334
+ * Marks shown on the page, in a layer of the overlay that lets the pointer through, redrawn as it
335
+ * scrolls. With a `key`, kept in the tab's session storage under it, per page; without, kept by nothing.
336
+ */
337
+ function marksOnPage(root, color, measure, key) {
338
+ let list = key === void 0 ? [] : stored(key);
339
+ const listeners = /* @__PURE__ */ new Set();
340
+ const layer = fixed(LAYER);
341
+ root.append(layer);
342
+ let frame = 0;
343
+ const draw = () => {
344
+ frame = 0;
345
+ layer.innerHTML = list.length === 0 ? "" : toSvg(list, viewport(), scroll(), measure);
346
+ };
347
+ const redraw = () => {
348
+ if (frame === 0) frame = requestAnimationFrame(draw);
349
+ };
350
+ window.addEventListener("scroll", redraw, {
351
+ capture: true,
352
+ passive: true
353
+ });
354
+ window.addEventListener("resize", redraw, { passive: true });
355
+ const changed = (event) => {
356
+ if (key !== void 0) try {
357
+ sessionStorage.setItem(key, JSON.stringify(list));
358
+ } catch {}
359
+ draw();
360
+ for (const listener of listeners) listener(event);
361
+ };
362
+ draw();
363
+ const marks = {
364
+ list: () => [...list],
365
+ add: (shape, given = color) => {
366
+ const annotation = mark(shape, given);
367
+ list = [...list, annotation];
368
+ changed({
369
+ type: "add",
370
+ annotation
371
+ });
372
+ return annotation;
373
+ },
374
+ remove: (id) => {
375
+ list = list.filter((a) => a.id !== id);
376
+ changed({
377
+ type: "remove",
378
+ id
379
+ });
380
+ },
381
+ clear: () => {
382
+ list = [];
383
+ changed({ type: "clear" });
384
+ },
385
+ subscribe: (listener) => {
386
+ listeners.add(listener);
387
+ return () => listeners.delete(listener);
388
+ },
389
+ svg: (area) => list.length === 0 ? void 0 : toSvg(list, area, scroll(), measure)
390
+ };
391
+ const remove = () => {
392
+ window.removeEventListener("scroll", redraw, { capture: true });
393
+ window.removeEventListener("resize", redraw);
394
+ cancelAnimationFrame(frame);
395
+ layer.remove();
396
+ listeners.clear();
397
+ };
398
+ return {
399
+ marks,
400
+ remove
401
+ };
402
+ }
403
+ /**
404
+ * Drawing on the page: a surface over it, under the popup, and the toolbar. Where the page stays usable
405
+ * (`usable`), the surface takes the pointer only while a drawing tool is picked.
406
+ */
407
+ function onPage(root, marks, color, usable) {
408
+ const surface = fixed(0x7ffffffe);
409
+ surface.style.pointerEvents = usable ? "none" : "auto";
410
+ const preview = fixed(0);
411
+ surface.append(preview);
412
+ root.append(surface);
413
+ const { tools, hint } = drawing({
414
+ surface,
415
+ at: (e) => ({
416
+ x: e.clientX + scrollX,
417
+ y: e.clientY + scrollY
418
+ }),
419
+ preview: (shape) => {
420
+ preview.innerHTML = shape === void 0 ? "" : toSvg([mark(shape, color)], viewport(), scroll());
421
+ },
422
+ add: (shape) => marks.add(shape),
423
+ removeLast: () => {
424
+ const last = marks.list().at(-1);
425
+ if (last !== void 0) marks.remove(last.id);
426
+ },
427
+ clear: () => marks.clear(),
428
+ ...usable ? { drawing: (on) => surface.style.pointerEvents = on ? "auto" : "none" } : {}
429
+ });
430
+ return {
431
+ tools,
432
+ hint,
433
+ surface
434
+ };
435
+ }
436
+ /** The picture with the marks drawn over it, as a PNG at the picture's own resolution. */
437
+ async function flatten(picture, marks, measure) {
438
+ const base = await image(picture.url);
439
+ const canvas = document.createElement("canvas");
440
+ canvas.width = base.naturalWidth;
441
+ canvas.height = base.naturalHeight;
442
+ const ctx = canvas.getContext("2d");
443
+ if (ctx === null) throw new Error("annotations: this browser won't draw to a canvas");
444
+ ctx.drawImage(base, 0, 0);
445
+ if (marks.length > 0) {
446
+ const svg = await image(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(over(picture, marks, measure))}`);
447
+ ctx.drawImage(svg, 0, 0, canvas.width, canvas.height);
448
+ }
449
+ return new Promise((done, fail) => canvas.toBlob((blob) => blob === null ? fail(/* @__PURE__ */ new Error("annotations: the picture drew nothing")) : done(blob), "image/png"));
450
+ }
451
+ var client_default = defineClientPlugin({
452
+ name: "annotations",
453
+ label: "Annotate",
454
+ setup: ({ root, options }) => {
455
+ const color = options.color;
456
+ const measure = measurer();
457
+ return {
458
+ ...marksOnPage(root, color, measure, `deictic:annotations:${location.pathname}`).marks,
459
+ edit: (picture, marks = [], { signal } = {}) => edit(root, picture, marks, {
460
+ color,
461
+ measure,
462
+ ...signal ? { signal } : {}
463
+ }),
464
+ flatten: (picture, marks) => flatten(picture, marks, measure),
465
+ tools: () => {
466
+ const own = marksOnPage(root, color, measure);
467
+ const { tools, surface } = onPage(root, own.marks, color, true);
468
+ const element = document.createElement("div");
469
+ element.append(Object.assign(document.createElement("style"), { textContent: TOOLS_STYLE }), tools);
470
+ return {
471
+ element,
472
+ marks: own.marks,
473
+ close: () => {
474
+ surface.remove();
475
+ own.remove();
476
+ }
477
+ };
478
+ }
479
+ };
480
+ },
481
+ mount: (panel, { root, use, close, options }) => {
482
+ const { color } = options;
483
+ const marks = use("annotations");
484
+ if (marks === void 0) return;
485
+ const style = document.createElement("style");
486
+ style.textContent = TOOLS_STYLE;
487
+ const { tools, hint, surface } = onPage(root, marks, color, false);
488
+ const done = button("Done", "Leave annotate mode (Esc)", close);
489
+ done.classList.add("primary", "end");
490
+ tools.append(done);
491
+ panel.append(style, tools, hint);
492
+ return () => surface.remove();
493
+ }
494
+ });
495
+ export { client_default as default };
496
+
497
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/annotations/svg.ts","../../src/plugins/annotations/draw.ts","../../src/plugins/annotations/client.ts"],"sourcesContent":["/**\n * Annotations as SVG: the layer the page shows them in, and what a screenshot draws over itself. Shapes\n * only, no `foreignObject`, so a canvas that draws the SVG isn't tainted, and a browser rendering it\n * elsewhere needs nothing of the page.\n */\nimport type { Annotation, Area, Point } from './index.ts';\n\nexport const STROKE = 3;\nexport const FONT = 14;\nconst PAD = 6;\n\n/** How wide text is, in CSS pixels: measured where there's a canvas, guessed where there isn't. */\nexport type Measure = (text: string) => number;\n\nexport const guess: Measure = (text) => text.length * FONT * 0.6;\n\nconst escape = (text: string) => text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('\"', '&quot;');\nconst n = (value: number) => Math.round(value * 10) / 10;\n\n/** An arrow's path: its line, then its head, two strokes back from the tip either side of the line. */\nfunction arrow(from: Point, to: Point): string {\n const angle = Math.atan2(to.y - from.y, to.x - from.x);\n const at = (p: Point) => `${n(p.x)},${n(p.y)}`;\n const side = (turn: number) => at({ x: to.x - 14 * Math.cos(angle + turn), y: to.y - 14 * Math.sin(angle + turn) });\n return `M${at(from)} L${at(to)} M${side(0.45)} L${at(to)} L${side(-0.45)}`;\n}\n\nfunction shapeOf({ shape, color }: Annotation, measure: Measure): string {\n const line = `fill=\"none\" stroke=\"${escape(color)}\" stroke-width=\"${STROKE}\" stroke-linecap=\"round\" stroke-linejoin=\"round\"`;\n switch (shape.kind) {\n case 'box':\n return `<rect x=\"${n(shape.x)}\" y=\"${n(shape.y)}\" width=\"${n(shape.width)}\" height=\"${n(shape.height)}\" rx=\"4\" ${line}/>`;\n case 'arrow':\n return `<path d=\"${arrow(shape.from, shape.to)}\" ${line}/>`;\n case 'pen':\n return `<polyline points=\"${shape.points.map((p) => `${n(p.x)},${n(p.y)}`).join(' ')}\" ${line}/>`;\n case 'note': {\n const lines = shape.text.split('\\n');\n const width = Math.max(...lines.map(measure)) + PAD * 2;\n const height = lines.length * FONT * 1.3 + PAD * 2;\n const text = lines\n .map(\n (l, i) => `<tspan x=\"${n(shape.at.x + PAD)}\" y=\"${n(shape.at.y + PAD + FONT * (i + 1) * 1.3 - FONT * 0.3)}\">${escape(l)}</tspan>`,\n )\n .join('');\n return (\n `<rect x=\"${n(shape.at.x)}\" y=\"${n(shape.at.y)}\" width=\"${n(width)}\" height=\"${n(height)}\" rx=\"4\" fill=\"${escape(color)}\"/>` +\n `<text font-family=\"system-ui, sans-serif\" font-size=\"${FONT}\" fill=\"#fff\">${text}</text>`\n );\n }\n }\n}\n\n/**\n * The annotations over `area` of the viewport, the page scrolled by `scroll`: an SVG `area`'s size,\n * whose view is that part of the page.\n */\nexport function toSvg(annotations: readonly Annotation[], area: Area, scroll: Point, measure: Measure = guess): string {\n const view = `${n(area.x + scroll.x)} ${n(area.y + scroll.y)} ${n(area.width)} ${n(area.height)}`;\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${n(area.width)}\" height=\"${n(area.height)}\" viewBox=\"${view}\">${annotations.map((a) => shapeOf(a, measure)).join('')}</svg>`;\n}\n","/**\n * Drawing with the pointer, wherever marks go: the page in annotate mode, or a picture in the editor.\n * Each says where an event is in its marks' coordinates; this is the toolbar and the gestures.\n */\nimport type { Point, Shape } from './index.ts';\nimport { FONT, guess, type Measure } from './svg.ts';\n\nexport const TOOLS_STYLE = `\n.annotations-tools { display: flex; flex-wrap: wrap; gap: 4px; }\n.annotations-tools .icon { display: inline-flex; align-items: center; justify-content: center; padding: 3px 5px; }\n.annotations-tools .icon svg { width: 16px; height: 16px; }\n.annotations-tools .gap { width: 1px; align-self: stretch; margin: 2px 4px; background: var(--deictic-line); }\n.annotations-tools button[aria-pressed='true'] { background: var(--deictic-accent); border-color: var(--deictic-accent); color: var(--deictic-on-accent); }\n.annotations-tools .end { margin-left: auto; }\n.annotations-hint { margin: 6px 0 0; font-size: 12px; color: var(--deictic-muted); }\n`;\n\ntype Tool = 'pointer' | 'box' | 'arrow' | 'pen' | 'note';\nconst TOOLS: Tool[] = ['box', 'arrow', 'pen', 'note'];\nconst NAMES: Record<Tool, string> = {\n pointer: 'Use the page',\n box: 'Draw a box',\n arrow: 'Draw an arrow',\n pen: 'Draw freehand',\n note: 'Add a note',\n};\n\n/** Each icon's strokes, on a 24-pixel grid: drawn here, so the page half needs nothing to show them. */\nconst ICONS = {\n pointer: '<path d=\"M5 3l14 7-6 2-2 6z\"/>',\n box: '<rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"2\"/>',\n arrow: '<path d=\"M6 18 18 6M9 6h9v9\"/>',\n pen: '<path d=\"M4 20l1-4L16 5a2.1 2.1 0 0 1 3 3L8 19z\"/>',\n note: '<path d=\"M4 5h16v11H9l-5 4zM8 9h8M8 12h5\"/>',\n undo: '<path d=\"M9 14 4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3\"/>',\n clear: '<path d=\"M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3\"/>',\n} as const;\n\n/** A button that shows an icon, with its name as its tooltip and for a screen reader. */\nexport function iconButton(icon: keyof typeof ICONS, name: string, run: () => void): HTMLButtonElement {\n const el = button('', name, run);\n el.className = 'icon';\n el.setAttribute('aria-label', name);\n el.innerHTML = `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">${ICONS[icon]}</svg>`;\n return el;\n}\n\n/** Text's width as the marks draw it, by a canvas's measure, which the guess stands in for without one. */\nexport function measurer(): Measure {\n const ctx = document.createElement('canvas').getContext('2d');\n if (ctx === null) return guess;\n ctx.font = `${FONT}px system-ui, sans-serif`;\n return (text) => ctx.measureText(text).width;\n}\n\nexport function button(label: string, title: string, run: () => void): HTMLButtonElement {\n const el = Object.assign(document.createElement('button'), { type: 'button', textContent: label, title });\n el.addEventListener('click', run);\n return el;\n}\n\nexport interface DrawingOptions {\n /** What takes the pointer to draw on. */\n surface: HTMLElement;\n /** Where an event is, in the coordinates the marks are kept in. */\n at: (e: PointerEvent) => Point;\n /** Shows the shape being drawn, or nothing once it's done. */\n preview: (shape: Shape | undefined) => void;\n add: (shape: Shape) => void;\n removeLast: () => void;\n clear: () => void;\n /**\n * Where the page stays usable between marks (a recording's toolbar): a pointer tool comes first and is\n * picked to start with, and this hears whether a drawing tool is picked, to let the surface take the\n * pointer only then.\n */\n drawing?: (on: boolean) => void;\n}\n\n/**\n * Draws on `surface` with the tool picked: answers the toolbar (the tools, then removing the last mark or all), for the\n * caller to add its own buttons to, and a hint for the tool.\n */\nexport function drawing({ surface, at, preview, add, removeLast, clear, drawing: on }: DrawingOptions) {\n const tools = document.createElement('div');\n tools.className = 'annotations-tools';\n const hint = document.createElement('p');\n hint.className = 'annotations-hint';\n\n let tool: Tool = on === undefined ? 'box' : 'pointer';\n const picks = (on === undefined ? TOOLS : (['pointer', ...TOOLS] as Tool[])).map((t) => ({\n t,\n el: iconButton(t, NAMES[t], () => pick(t)),\n }));\n const pick = (t: Tool) => {\n tool = t;\n for (const p of picks) p.el.setAttribute('aria-pressed', String(p.t === t));\n on?.(t !== 'pointer');\n hint.textContent =\n t === 'pointer'\n ? 'Use the page; pick a tool to draw.'\n : t === 'note'\n ? 'Click where the note goes, type it, Enter to place it.'\n : 'Drag to draw.';\n };\n const gap = document.createElement('span');\n gap.className = 'gap';\n tools.append(\n ...picks.map((p) => p.el),\n gap,\n iconButton('undo', 'Remove the last mark', removeLast),\n iconButton('clear', 'Remove every mark', clear),\n );\n pick(tool);\n\n surface.style.cursor = 'crosshair';\n const shapeFrom = (from: Point, to: Point, points: Point[]): Shape | undefined => {\n if (tool === 'pen') return points.length > 1 ? { kind: 'pen', points } : undefined;\n if (Math.hypot(to.x - from.x, to.y - from.y) < 4) return undefined;\n if (tool === 'arrow') return { kind: 'arrow', from, to };\n return {\n kind: 'box',\n x: Math.min(from.x, to.x),\n y: Math.min(from.y, to.y),\n width: Math.abs(to.x - from.x),\n height: Math.abs(to.y - from.y),\n };\n };\n\n surface.addEventListener('pointerdown', (e) => {\n if (e.button !== 0 || e.target instanceof HTMLInputElement) return;\n e.preventDefault();\n if (tool === 'note') return note(at(e), e);\n const from = at(e);\n const points = [from];\n surface.setPointerCapture(e.pointerId);\n const move = (m: PointerEvent) => {\n points.push(at(m));\n preview(shapeFrom(from, at(m), points));\n };\n const up = (u: PointerEvent) => {\n surface.removeEventListener('pointermove', move);\n preview(undefined);\n const shape = shapeFrom(from, at(u), points);\n if (shape !== undefined) add(shape);\n };\n surface.addEventListener('pointermove', move);\n surface.addEventListener('pointerup', up, { once: true });\n });\n\n /** A field where the note goes: Enter places what's typed, leaving it empty or blurring it places nothing. */\n const note = (point: Point, e: PointerEvent) => {\n const field = Object.assign(document.createElement('input'), { placeholder: 'Note, then Enter' });\n // Its own colours: on the page, outside the popup, it would take the page's text colour on deictic's dark field.\n field.style.cssText = `position:fixed;left:${e.clientX}px;top:${e.clientY}px;width:220px;pointer-events:auto;cursor:text;color:var(--deictic-fg);background:var(--deictic-bg);border-color:var(--deictic-accent)`;\n surface.append(field);\n const place = () => {\n const text = field.value.trim();\n field.remove();\n if (text !== '') add({ kind: 'note', at: point, text });\n };\n field.addEventListener('keydown', (k) => k.key === 'Enter' && place());\n field.addEventListener('blur', () => field.isConnected && place());\n // Now, not a frame later: the pointerdown's default is prevented, so no mousedown takes focus back.\n field.focus();\n };\n\n return { tools, hint };\n}\n","/**\n * Annotations in the page. `setup` keeps them (in the tab's session storage, per page) and shows them in a\n * layer of deictic's overlay that lets the pointer through; it answers the API other plugins `use`. The\n * panel is annotate mode: a toolbar, and while it's open a surface over the page that takes the pointer, so\n * drawing never clicks the page. Esc or Done leaves it; the marks stay.\n *\n * The layer is deictic's, so a screenshot leaves it out with the rest of the overlay and draws the marks\n * itself from `svg(area)`: one way to draw them, wherever a shot is rendered. `edit` draws on a picture\n * instead, a shot most often, in the same toolbar over everything, and `flatten` makes the PNG of it.\n */\nimport { defineClientPlugin } from '#src/index.ts';\n\nimport { button, drawing, measurer, TOOLS_STYLE } from './draw.ts';\nimport type { Annotation, AnnotationEvent, Annotations, Area, MarkSet, Picture, Point, Shape } from './index.ts';\nimport { type Measure, toSvg } from './svg.ts';\n\n/** Under deictic's outline and panels, over the page. */\nconst LAYER = 2147483645;\n/** Over everything of deictic's, the popup too. */\nconst TOP = 2147483647;\n\nconst scroll = (): Point => ({ x: scrollX, y: scrollY });\nconst viewport = (): Area => ({ x: 0, y: 0, width: document.documentElement.clientWidth, height: document.documentElement.clientHeight });\nconst mark = (shape: Shape, color: string): Annotation => ({ id: crypto.randomUUID(), color, shape, at: Date.now() });\n\n/** What's kept for this page in the tab's session, read as it can be. */\nfunction stored(key: string): Annotation[] {\n try {\n const kept: unknown = JSON.parse(sessionStorage.getItem(key) ?? '[]');\n return Array.isArray(kept) ? (kept as Annotation[]) : [];\n } catch {\n // Storage can be off, or hold something else: no marks is the page as it was.\n return [];\n }\n}\n\nfunction fixed(z: number): HTMLDivElement {\n const el = document.createElement('div');\n el.style.cssText = `position:fixed;inset:0;z-index:${z};pointer-events:none`;\n return el;\n}\n\nconst EDITOR_STYLE = `\n.annotations-editor { position: fixed; inset: 0; z-index: ${TOP}; box-sizing: border-box; padding: 16px; display: flex;\n flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgb(0 0 0 / 0.75);\n font: 13px/1.4 system-ui, sans-serif; color: var(--deictic-fg); }\n.annotations-editor .bar { box-sizing: border-box; width: min(100%, 720px); padding: 6px 8px; border: 1px solid var(--deictic-line);\n border-radius: 8px; background: var(--deictic-bg); }\n.annotations-editor .stage { position: relative; line-height: 0; box-shadow: 0 12px 32px rgb(0 0 0 / 0.5); touch-action: none; }\n.annotations-editor img { display: block; max-width: calc(100vw - 32px); max-height: calc(100vh - 120px); user-select: none; }\n.annotations-editor .marks { position: absolute; inset: 0; pointer-events: none; }\n`;\n\n/** Loads an image, decoded. */\nasync function image(src: string): Promise<HTMLImageElement> {\n const el = new Image();\n el.src = src;\n await el.decode();\n return el;\n}\n\n/** The marks over a whole picture, as an SVG whose view is the picture's CSS pixels. */\nconst over = (picture: Picture, marks: readonly Annotation[], measure?: Measure) =>\n toSvg(marks, { x: 0, y: 0, width: picture.width, height: picture.height }, { x: 0, y: 0 }, measure);\n\n/**\n * The picture over everything, to draw on: the marks on Save, nothing on Cancel, Esc or `signal`. It holds\n * Esc while it's open (`data-deictic-modal`), so Esc leaves it, not the popup under it.\n */\nfunction edit(\n root: ShadowRoot,\n picture: Picture,\n start: readonly Annotation[],\n { color, measure, signal }: { color: string; measure: Measure; signal?: AbortSignal },\n): Promise<Annotation[] | undefined> {\n return new Promise((resolve) => {\n let marks = [...start];\n const backdrop = document.createElement('div');\n backdrop.className = 'annotations-editor';\n backdrop.dataset.deicticModal = '';\n const style = document.createElement('style');\n style.textContent = TOOLS_STYLE + EDITOR_STYLE;\n const bar = document.createElement('div');\n bar.className = 'bar';\n const stage = document.createElement('div');\n stage.className = 'stage';\n const img = Object.assign(document.createElement('img'), { src: picture.url, alt: 'The screenshot', draggable: false });\n const layer = document.createElement('div');\n layer.className = 'marks';\n stage.append(img, layer);\n\n const show = (preview?: Shape) => {\n layer.innerHTML = over(picture, preview === undefined ? marks : [...marks, mark(preview, color)], measure);\n // Drawn at the size the picture shows at, whatever that is: the view is the picture's own pixels.\n const svg = layer.firstElementChild;\n svg?.setAttribute('width', '100%');\n svg?.setAttribute('height', '100%');\n };\n const { tools, hint } = drawing({\n surface: stage,\n at: (e) => {\n const r = stage.getBoundingClientRect();\n return { x: ((e.clientX - r.left) * picture.width) / r.width, y: ((e.clientY - r.top) * picture.height) / r.height };\n },\n preview: (shape) => show(shape),\n add: (shape) => {\n marks = [...marks, mark(shape, color)];\n show();\n },\n removeLast: () => {\n marks = marks.slice(0, -1);\n show();\n },\n clear: () => {\n marks = [];\n show();\n },\n });\n const end = (result: Annotation[] | undefined) => {\n backdrop.remove();\n window.removeEventListener('keydown', onKey, true);\n signal?.removeEventListener('abort', cancel);\n resolve(result);\n };\n const cancel = () => end(undefined);\n const onKey = (e: KeyboardEvent) => {\n if (e.key !== 'Escape') return;\n e.stopPropagation();\n cancel();\n };\n const save = button('Save', 'Keep these marks', () => end(marks));\n save.classList.add('primary');\n const back = button('Cancel', 'Leave it as it was (Esc)', cancel);\n back.classList.add('end');\n tools.append(back, save);\n bar.append(tools, hint);\n backdrop.append(style, bar, stage);\n root.append(backdrop);\n window.addEventListener('keydown', onKey, true);\n signal?.addEventListener('abort', cancel);\n show();\n });\n}\n\n/**\n * Marks shown on the page, in a layer of the overlay that lets the pointer through, redrawn as it\n * scrolls. With a `key`, kept in the tab's session storage under it, per page; without, kept by nothing.\n */\nfunction marksOnPage(root: ShadowRoot, color: string, measure: Measure, key?: string): { marks: MarkSet; remove: () => void } {\n let list = key === undefined ? [] : stored(key);\n const listeners = new Set<(event: AnnotationEvent) => void>();\n const layer = fixed(LAYER);\n root.append(layer);\n\n let frame = 0;\n const draw = () => {\n frame = 0;\n layer.innerHTML = list.length === 0 ? '' : toSvg(list, viewport(), scroll(), measure);\n };\n const redraw = () => {\n if (frame === 0) frame = requestAnimationFrame(draw);\n };\n window.addEventListener('scroll', redraw, { capture: true, passive: true });\n window.addEventListener('resize', redraw, { passive: true });\n const changed = (event: AnnotationEvent) => {\n if (key !== undefined) {\n try {\n sessionStorage.setItem(key, JSON.stringify(list));\n } catch {\n // Not kept past a reload, then; the page still shows them.\n }\n }\n draw();\n for (const listener of listeners) listener(event);\n };\n draw();\n\n const marks: MarkSet = {\n list: () => [...list],\n add: (shape, given = color) => {\n const annotation = mark(shape, given);\n list = [...list, annotation];\n changed({ type: 'add', annotation });\n return annotation;\n },\n remove: (id) => {\n list = list.filter((a) => a.id !== id);\n changed({ type: 'remove', id });\n },\n clear: () => {\n list = [];\n changed({ type: 'clear' });\n },\n subscribe: (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n svg: (area) => (list.length === 0 ? undefined : toSvg(list, area, scroll(), measure)),\n };\n const remove = () => {\n window.removeEventListener('scroll', redraw, { capture: true });\n window.removeEventListener('resize', redraw);\n cancelAnimationFrame(frame);\n layer.remove();\n listeners.clear();\n };\n return { marks, remove };\n}\n\n/**\n * Drawing on the page: a surface over it, under the popup, and the toolbar. Where the page stays usable\n * (`usable`), the surface takes the pointer only while a drawing tool is picked.\n */\nfunction onPage(root: ShadowRoot, marks: MarkSet, color: string, usable: boolean) {\n const surface = fixed(LAYER + 1);\n surface.style.pointerEvents = usable ? 'none' : 'auto';\n const preview = fixed(0);\n surface.append(preview);\n root.append(surface);\n const { tools, hint } = drawing({\n surface,\n at: (e) => ({ x: e.clientX + scrollX, y: e.clientY + scrollY }),\n preview: (shape) => {\n preview.innerHTML = shape === undefined ? '' : toSvg([mark(shape, color)], viewport(), scroll());\n },\n add: (shape) => marks.add(shape),\n removeLast: () => {\n const last = marks.list().at(-1);\n if (last !== undefined) marks.remove(last.id);\n },\n clear: () => marks.clear(),\n ...(usable ? { drawing: (on: boolean) => (surface.style.pointerEvents = on ? 'auto' : 'none') } : {}),\n });\n return { tools, hint, surface };\n}\n\n/** The picture with the marks drawn over it, as a PNG at the picture's own resolution. */\nasync function flatten(picture: Picture, marks: readonly Annotation[], measure: Measure): Promise<Blob> {\n const base = await image(picture.url);\n const canvas = document.createElement('canvas');\n canvas.width = base.naturalWidth;\n canvas.height = base.naturalHeight;\n const ctx = canvas.getContext('2d');\n if (ctx === null) throw new Error(\"annotations: this browser won't draw to a canvas\");\n ctx.drawImage(base, 0, 0);\n if (marks.length > 0) {\n // Shapes only, no `foreignObject`, so drawing the SVG leaves the canvas readable.\n const svg = await image(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(over(picture, marks, measure))}`);\n ctx.drawImage(svg, 0, 0, canvas.width, canvas.height);\n }\n return new Promise((done, fail) =>\n canvas.toBlob((blob) => (blob === null ? fail(new Error('annotations: the picture drew nothing')) : done(blob)), 'image/png'),\n );\n}\n\nexport default defineClientPlugin<null, never, Annotations>({\n name: 'annotations',\n label: 'Annotate',\n setup: ({ root, options }) => {\n const color = (options as { color: string }).color;\n const measure = measurer();\n const page = marksOnPage(root, color, measure, `deictic:annotations:${location.pathname}`);\n\n const api: Annotations = {\n ...page.marks,\n edit: (picture, marks = [], { signal } = {}) => edit(root, picture, marks, { color, measure, ...(signal ? { signal } : {}) }),\n flatten: (picture, marks) => flatten(picture, marks, measure),\n tools: () => {\n // Its own marks, kept by nothing: they show while it's open, and go with it.\n const own = marksOnPage(root, color, measure);\n const { tools, surface } = onPage(root, own.marks, color, true);\n const element = document.createElement('div');\n element.append(Object.assign(document.createElement('style'), { textContent: TOOLS_STYLE }), tools);\n return {\n element,\n marks: own.marks,\n close: () => {\n surface.remove();\n own.remove();\n },\n };\n },\n };\n return api;\n },\n\n mount: (panel, { root, use, close, options }) => {\n const { color } = options as { color: string };\n const marks = use('annotations');\n if (marks === undefined) return;\n const style = document.createElement('style');\n style.textContent = TOOLS_STYLE;\n // Over the page while annotate mode is open: it takes the pointer, so drawing never clicks the page.\n const { tools, hint, surface } = onPage(root, marks, color, false);\n const done = button('Done', 'Leave annotate mode (Esc)', close);\n done.classList.add('primary', 'end');\n tools.append(done);\n panel.append(style, tools, hint);\n return () => surface.remove();\n },\n});\n"],"mappings":";AASA,MAAM,MAAM;AAKZ,MAAa,SAAkB,SAAS,KAAK,SAAA,KAAgB;AAE7D,MAAM,UAAU,SAAiB,KAAK,WAAW,KAAK,OAAO,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,WAAW,MAAK,QAAQ;AACvI,MAAM,KAAK,UAAkB,KAAK,MAAM,QAAQ,EAAE,IAAI;;AAGtD,SAAS,MAAM,MAAa,IAAmB;CAC7C,MAAM,QAAQ,KAAK,MAAM,GAAG,IAAI,KAAK,GAAG,GAAG,IAAI,KAAK,CAAC;CACrD,MAAM,MAAM,MAAa,GAAG,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;CAC3C,MAAM,QAAQ,SAAiB,GAAG;EAAE,GAAG,GAAG,IAAI,KAAK,KAAK,IAAI,QAAQ,IAAI;EAAG,GAAG,GAAG,IAAI,KAAK,KAAK,IAAI,QAAQ,IAAI;CAAE,CAAC;CAClH,OAAO,IAAI,GAAG,IAAI,EAAE,IAAI,GAAG,EAAE,EAAE,IAAI,KAAK,GAAI,EAAE,IAAI,GAAG,EAAE,EAAE,IAAI,KAAK,IAAK;AACzE;AAEA,SAAS,QAAQ,EAAE,OAAO,SAAqB,SAA0B;CACvE,MAAM,OAAO,uBAAuB,OAAO,KAAK,EAAE;CAClD,QAAQ,MAAM,MAAd;EACE,KAAK,OACH,OAAO,YAAY,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,EAAE,WAAW,KAAK;EACxH,KAAK,SACH,OAAO,YAAY,MAAM,MAAM,MAAM,MAAM,EAAE,EAAE,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