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,376 @@
1
+ import { n as liveWaveform } from "../shared/waveform.js";
2
+ import { defineClientPlugin } from "../index.js";
3
+ import { n as MARKS, t as END } from "../shared/marks.js";
4
+ // src/plugins/recordings/ours.ts
5
+ /** rrweb's numbers: an incremental snapshot, and the sources whose data is a list of pointer positions. */
6
+ const INCREMENTAL = 3;
7
+ const MUTATION = 0;
8
+ const POSITIONS = /* @__PURE__ */ new Set([
9
+ 1,
10
+ 6,
11
+ 12
12
+ ]);
13
+ /** A filter for `emit`: the event without our nodes, or nothing when nothing else is left in it. */
14
+ function dropOurs(hostId, pageId) {
15
+ const ours = /* @__PURE__ */ new Set();
16
+ return (event) => {
17
+ if (ours.size === 0) {
18
+ const id = hostId();
19
+ if (id > 0) ours.add(id);
20
+ }
21
+ if (event.type !== INCREMENTAL || typeof event.data !== "object" || event.data === null) return event;
22
+ const data = event.data;
23
+ if (data.source === MUTATION) {
24
+ const m = data;
25
+ for (let grew = true; grew;) {
26
+ grew = false;
27
+ for (const add of m.adds) if (ours.has(add.parentId) && !ours.has(add.node.id)) {
28
+ ours.add(add.node.id);
29
+ grew = true;
30
+ }
31
+ }
32
+ const kept = {
33
+ ...m,
34
+ adds: m.adds.filter((a) => !ours.has(a.node.id)),
35
+ removes: m.removes.filter((r) => !ours.has(r.id) && !ours.has(r.parentId)),
36
+ texts: m.texts.filter((t) => !ours.has(t.id)),
37
+ attributes: m.attributes.filter((a) => !ours.has(a.id))
38
+ };
39
+ return kept.adds.length + kept.removes.length + kept.texts.length + kept.attributes.length === 0 ? void 0 : {
40
+ ...event,
41
+ data: kept
42
+ };
43
+ }
44
+ if (POSITIONS.has(data.source) && Array.isArray(data.positions)) {
45
+ const page = pageId();
46
+ const positions = data.positions.map((p) => ours.has(p.id) ? {
47
+ ...p,
48
+ id: page
49
+ } : p);
50
+ return {
51
+ ...event,
52
+ data: {
53
+ ...data,
54
+ positions
55
+ }
56
+ };
57
+ }
58
+ return data.id !== void 0 && ours.has(data.id) ? void 0 : event;
59
+ };
60
+ }
61
+ // src/plugins/recordings/client.ts
62
+ /**
63
+ * The recordings plugin's page half: `record()` starts rrweb (imported then) and shows the toolbar, a bar
64
+ * docked to an edge of the window that its grip drags to any other, kept between recordings. It holds the
65
+ * time, annotate mode's tools where that plugin is loaded, and Stop and Discard. Stop sends the events to
66
+ * the `add` route.
67
+ *
68
+ * Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom
69
+ * events: the page's annotations and the toolbar's own, which go when it does, as SVGs in page
70
+ * coordinates, at the start and at each change.
71
+ */
72
+ const DOCK = "deictic:recorder";
73
+ const MARGIN = 12;
74
+ const STYLE = `
75
+ .recorder { position: fixed; z-index: 2147483647; display: flex; align-items: center; gap: 6px; padding: 6px 8px;
76
+ border: 1px solid var(--deictic-line); border-radius: 10px; background: var(--deictic-bg); color: var(--deictic-fg);
77
+ box-shadow: 0 12px 32px rgb(0 0 0 / 0.35); font: 13px/1.4 system-ui, sans-serif; user-select: none; }
78
+ .recorder.vertical { flex-direction: column; }
79
+ .recorder.vertical .annotations-tools { flex-direction: column; }
80
+ .recorder.vertical .annotations-tools .gap { width: auto; height: 1px; margin: 4px 2px; }
81
+ .recorder .grip { display: inline-flex; padding: 2px; color: var(--deictic-muted); cursor: grab; touch-action: none; }
82
+ .recorder .grip:active { cursor: grabbing; }
83
+ .recorder .grip svg { width: 16px; height: 16px; }
84
+ .recorder .live { display: inline-flex; align-items: center; gap: 6px; font: 12px ui-monospace, monospace; }
85
+ .recorder .dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: deictic-blink 1.2s infinite; }
86
+ .recorder .sep { align-self: stretch; width: 1px; background: var(--deictic-line); }
87
+ .recorder.vertical .sep { width: auto; height: 1px; }
88
+ .recorder .icon { display: inline-flex; align-items: center; justify-content: center; padding: 3px 5px; }
89
+ .recorder .icon svg { width: 16px; height: 16px; }
90
+ .recorder .mic[aria-pressed='true'] { background: #ef4444; border-color: #ef4444; color: #fff; }
91
+ .recorder .wave { width: 44px; height: 18px; }
92
+ .recorder.vertical .wave { width: 28px; }
93
+ .recorder .wave[hidden] { display: none; }
94
+ .recorder .mic.problem { border-color: var(--deictic-problem); color: var(--deictic-problem); }
95
+ @keyframes deictic-blink { 50% { opacity: 0.3; } }
96
+ `;
97
+ const svg = (paths) => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${paths}</svg>`;
98
+ const GRIP = svg("<circle cx=\"9\" cy=\"6\" r=\"1\"/><circle cx=\"15\" cy=\"6\" r=\"1\"/><circle cx=\"9\" cy=\"12\" r=\"1\"/><circle cx=\"15\" cy=\"12\" r=\"1\"/><circle cx=\"9\" cy=\"18\" r=\"1\"/><circle cx=\"15\" cy=\"18\" r=\"1\"/>");
99
+ const STOP = svg("<rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"1\" fill=\"currentColor\"/>");
100
+ const DISCARD = svg("<path d=\"M6 6l12 12M18 6 6 18\"/>");
101
+ const MIC = svg("<rect x=\"9\" y=\"3\" width=\"6\" height=\"11\" rx=\"3\"/><path d=\"M5 11a7 7 0 0 0 14 0M12 18v3\"/>");
102
+ const clock = (ms) => {
103
+ const s = Math.floor(ms / 1e3);
104
+ return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
105
+ };
106
+ function storedDock() {
107
+ try {
108
+ const dock = JSON.parse(localStorage.getItem(DOCK) ?? "null");
109
+ if (dock !== null && [
110
+ "top",
111
+ "bottom",
112
+ "left",
113
+ "right"
114
+ ].includes(dock.edge) && dock.along >= 0 && dock.along <= 1) return dock;
115
+ } catch {}
116
+ return {
117
+ edge: "bottom",
118
+ along: .5
119
+ };
120
+ }
121
+ function iconButton(icon, name, run) {
122
+ const el = Object.assign(document.createElement("button"), {
123
+ type: "button",
124
+ className: "icon",
125
+ title: name,
126
+ innerHTML: icon
127
+ });
128
+ el.setAttribute("aria-label", name);
129
+ el.addEventListener("click", run);
130
+ return el;
131
+ }
132
+ /** Puts the bar on its edge, laid out along it, and how far along. */
133
+ function place(bar, { edge, along }) {
134
+ bar.classList.toggle("vertical", edge === "left" || edge === "right");
135
+ const { width, height } = bar.getBoundingClientRect();
136
+ const across = (room, size) => `${MARGIN + along * Math.max(0, room - size - 24)}px`;
137
+ Object.assign(bar.style, {
138
+ left: edge === "left" ? `${MARGIN}px` : edge === "right" ? `${innerWidth - width - MARGIN}px` : across(innerWidth, width),
139
+ top: edge === "top" ? `${MARGIN}px` : edge === "bottom" ? `${innerHeight - height - MARGIN}px` : across(innerHeight, height)
140
+ });
141
+ }
142
+ /** Dragging the bar by its grip, freely; let go, it docks to the nearest edge. */
143
+ function draggable(bar, grip, docked) {
144
+ grip.addEventListener("pointerdown", (e) => {
145
+ if (e.button !== 0) return;
146
+ e.preventDefault();
147
+ grip.setPointerCapture(e.pointerId);
148
+ const start = bar.getBoundingClientRect();
149
+ const dx = e.clientX - start.left;
150
+ const dy = e.clientY - start.top;
151
+ const move = (m) => {
152
+ bar.style.left = `${m.clientX - dx}px`;
153
+ bar.style.top = `${m.clientY - dy}px`;
154
+ };
155
+ const up = () => {
156
+ grip.removeEventListener("pointermove", move);
157
+ const r = bar.getBoundingClientRect();
158
+ const x = r.left + r.width / 2;
159
+ const y = r.top + r.height / 2;
160
+ const [edge] = [
161
+ ["left", x],
162
+ ["right", innerWidth - x],
163
+ ["top", y],
164
+ ["bottom", innerHeight - y]
165
+ ].reduce((a, b) => b[1] < a[1] ? b : a);
166
+ const ratio = (at, room) => Math.min(1, Math.max(0, at / room));
167
+ docked({
168
+ edge,
169
+ along: edge === "left" || edge === "right" ? ratio(y, innerHeight) : ratio(x, innerWidth)
170
+ });
171
+ };
172
+ grip.addEventListener("pointermove", move);
173
+ grip.addEventListener("pointerup", up, { once: true });
174
+ });
175
+ }
176
+ var client_default = defineClientPlugin({
177
+ name: "recordings",
178
+ setup: ({ base, root, options, use, request }) => {
179
+ const { masking } = options;
180
+ let going = false;
181
+ const record = async () => {
182
+ const rrweb = await import("rrweb").catch((e) => {
183
+ throw new Error("recordings need rrweb: add it to your devDependencies", { cause: e });
184
+ });
185
+ const events = [];
186
+ const startedAt = Date.now();
187
+ const viewport = {
188
+ width: document.documentElement.clientWidth,
189
+ height: document.documentElement.clientHeight
190
+ };
191
+ const colorScheme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
192
+ const host = root.host;
193
+ const keep = dropOurs(() => rrweb.record.mirror.getId(host), () => rrweb.record.mirror.getId(document.documentElement));
194
+ const stopRecording = rrweb.record({
195
+ emit: (event) => {
196
+ const kept = keep(event);
197
+ if (kept !== void 0) events.push(kept);
198
+ },
199
+ blockClass: masking.blockClass,
200
+ blockSelector: ["deictic-overlay", ...masking.blockSelector ? [masking.blockSelector] : []].join(", "),
201
+ maskTextClass: masking.maskTextClass,
202
+ ...masking.maskTextSelector ? { maskTextSelector: masking.maskTextSelector } : {},
203
+ maskAllInputs: masking.maskAllInputs,
204
+ maskInputOptions: { password: true },
205
+ inlineStylesheet: true
206
+ });
207
+ const marks = use("annotations");
208
+ const tools = marks?.tools();
209
+ const mark = () => {
210
+ const area = {
211
+ x: -scrollX,
212
+ y: -scrollY,
213
+ width: 1,
214
+ height: 1
215
+ };
216
+ rrweb.record.addCustomEvent(MARKS, {
217
+ svg: [marks?.svg(area), tools?.marks.svg(area)].filter(Boolean).join(""),
218
+ annotations: [...marks?.list() ?? [], ...tools?.marks.list() ?? []]
219
+ });
220
+ };
221
+ mark();
222
+ const unsubscribe = [marks?.subscribe(mark), tools?.marks.subscribe(mark)];
223
+ return new Promise((done, fail) => {
224
+ const bar = document.createElement("div");
225
+ bar.className = "recorder";
226
+ bar.setAttribute("role", "toolbar");
227
+ bar.setAttribute("aria-label", "Recording");
228
+ const grip = Object.assign(document.createElement("span"), {
229
+ className: "grip",
230
+ title: "Drag to any edge",
231
+ innerHTML: GRIP
232
+ });
233
+ const live = Object.assign(document.createElement("span"), { className: "live" });
234
+ const dot = Object.assign(document.createElement("span"), { className: "dot" });
235
+ const time = document.createElement("span");
236
+ live.append(dot, time);
237
+ const sep = () => Object.assign(document.createElement("span"), { className: "sep" });
238
+ const voice = use("voice");
239
+ const clips = [];
240
+ let take;
241
+ const wave = Object.assign(document.createElement("canvas"), {
242
+ className: "wave",
243
+ hidden: true
244
+ });
245
+ let stopWave;
246
+ const unwave = () => {
247
+ stopWave?.();
248
+ stopWave = void 0;
249
+ wave.hidden = true;
250
+ };
251
+ let busy = Promise.resolve();
252
+ const micOff = async () => {
253
+ const ending = take;
254
+ take = void 0;
255
+ unwave();
256
+ if (ending === void 0) return;
257
+ try {
258
+ const clip = await ending.stop();
259
+ clips.push({
260
+ id: clip.id,
261
+ at: ending.started - startedAt,
262
+ duration: clip.duration
263
+ });
264
+ } catch (e) {
265
+ console.warn("deictic: the voice clip was not kept", e);
266
+ }
267
+ };
268
+ const mic = voice === void 0 ? void 0 : iconButton(MIC, "Turn the mic on", () => toggle());
269
+ const toggle = () => {
270
+ busy = busy.then(async () => {
271
+ if (voice === void 0 || mic === void 0) return;
272
+ if (take !== void 0) await micOff();
273
+ else try {
274
+ take = await voice.start();
275
+ mic.classList.remove("problem");
276
+ wave.hidden = false;
277
+ stopWave = liveWaveform(wave, take.stream, {
278
+ played: "#ef4444",
279
+ rest: "#52525b"
280
+ });
281
+ } catch (e) {
282
+ mic.classList.add("problem");
283
+ mic.title = e instanceof Error ? e.message : String(e);
284
+ return;
285
+ }
286
+ const on = take !== void 0;
287
+ mic.setAttribute("aria-pressed", String(on));
288
+ mic.title = on ? "Turn the mic off" : "Turn the mic on";
289
+ mic.setAttribute("aria-label", mic.title);
290
+ });
291
+ };
292
+ mic?.classList.add("mic");
293
+ mic?.setAttribute("aria-pressed", "false");
294
+ const end = async (keep) => {
295
+ rrweb.record.addCustomEvent(END, {});
296
+ stopRecording?.();
297
+ for (const stop of unsubscribe) stop?.();
298
+ tools?.close();
299
+ clearInterval(ticking);
300
+ removeEventListener("resize", replace);
301
+ bar.remove();
302
+ await busy;
303
+ if (!keep) {
304
+ unwave();
305
+ take?.cancel();
306
+ return done(void 0);
307
+ }
308
+ await micOff();
309
+ const duration = Date.now() - startedAt;
310
+ const voiced = clips.length > 0 ? { voice: clips } : {};
311
+ const kept = {
312
+ page: location.href,
313
+ viewport,
314
+ colorScheme,
315
+ startedAt,
316
+ duration,
317
+ events,
318
+ ...voiced
319
+ };
320
+ try {
321
+ const res = await request("add", {
322
+ method: "POST",
323
+ headers: { "content-type": "application/json" },
324
+ body: JSON.stringify(kept)
325
+ });
326
+ const { id, url, problem } = await res.json();
327
+ if (id === void 0) throw new Error(`recordings: ${problem ?? res.statusText}`);
328
+ done({
329
+ id,
330
+ url: url ?? `${base}__deictic/plugins/recordings/replay/${id}`,
331
+ duration,
332
+ ...voiced
333
+ });
334
+ } catch (e) {
335
+ fail(e);
336
+ }
337
+ };
338
+ const stop = iconButton(STOP, "Stop, and keep the recording", () => void end(true));
339
+ const discard = iconButton(DISCARD, "Discard the recording", () => void end(false));
340
+ bar.append(grip, live, ...tools ? [sep(), tools.element] : [], sep(), ...mic ? [mic, wave] : [], stop, discard);
341
+ const style = Object.assign(document.createElement("style"), { textContent: STYLE });
342
+ bar.prepend(style);
343
+ root.append(bar);
344
+ const tick = () => time.textContent = clock(Date.now() - startedAt);
345
+ tick();
346
+ const ticking = setInterval(tick, 250);
347
+ let dock = storedDock();
348
+ const replace = () => place(bar, dock);
349
+ replace();
350
+ addEventListener("resize", replace);
351
+ draggable(bar, grip, (next) => {
352
+ dock = next;
353
+ replace();
354
+ try {
355
+ localStorage.setItem(DOCK, JSON.stringify(dock));
356
+ } catch {}
357
+ });
358
+ });
359
+ };
360
+ return {
361
+ recording: () => going,
362
+ record: async () => {
363
+ if (going) throw new Error("recordings: one is going already: stop it first");
364
+ going = true;
365
+ try {
366
+ return await record();
367
+ } finally {
368
+ going = false;
369
+ }
370
+ }
371
+ };
372
+ }
373
+ });
374
+ export { client_default as default };
375
+
376
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/recordings/ours.ts","../../src/plugins/recordings/client.ts"],"sourcesContent":["/**\n * Keeps deictic's own UI out of a recording. Blocking the overlay keeps it out of the first snapshot,\n * but rrweb watches a blocked host's shadow root all the same, so what's added there later (the toolbar,\n * a note's field) comes as mutations. This drops them, and clicks and input on those nodes, by the IDs\n * rrweb gave them: the host's, and every node added under one of ours.\n *\n * The pointer's moves over them stay, on the page's root instead: the replay moves its cursor only over a\n * node it has, and while a drawing tool is picked the pointer is over ours the whole time.\n */\n\n/** The parts of rrweb's events this reads; the rest passes as it is. */\ninterface Event {\n type: number;\n data?: unknown;\n}\n\ninterface Mutation {\n source: 0;\n adds: { parentId: number; node: { id: number } }[];\n removes: { parentId: number; id: number }[];\n texts: { id: number }[];\n attributes: { id: number }[];\n}\n\n/** rrweb's numbers: an incremental snapshot, and the sources whose data is a list of pointer positions. */\nconst INCREMENTAL = 3;\nconst MUTATION = 0;\nconst POSITIONS = new Set([1, 6, 12]);\n\n/** A filter for `emit`: the event without our nodes, or nothing when nothing else is left in it. */\nexport function dropOurs<E extends Event>(hostId: () => number, pageId: () => number): (event: E) => E | undefined {\n const ours = new Set<number>();\n return (event) => {\n if (ours.size === 0) {\n const id = hostId();\n if (id > 0) ours.add(id);\n }\n if (event.type !== INCREMENTAL || typeof event.data !== 'object' || event.data === null) return event;\n const data = event.data as { source: number; id?: number; positions?: { id: number }[] };\n\n if (data.source === MUTATION) {\n const m = data as Mutation;\n // Added parents and children come in any order: claim until nothing more is ours.\n for (let grew = true; grew;) {\n grew = false;\n for (const add of m.adds) {\n if (ours.has(add.parentId) && !ours.has(add.node.id)) {\n ours.add(add.node.id);\n grew = true;\n }\n }\n }\n const kept: Mutation = {\n ...m,\n adds: m.adds.filter((a) => !ours.has(a.node.id)),\n removes: m.removes.filter((r) => !ours.has(r.id) && !ours.has(r.parentId)),\n texts: m.texts.filter((t) => !ours.has(t.id)),\n attributes: m.attributes.filter((a) => !ours.has(a.id)),\n };\n const left = kept.adds.length + kept.removes.length + kept.texts.length + kept.attributes.length;\n return left === 0 ? undefined : { ...event, data: kept };\n }\n if (POSITIONS.has(data.source) && Array.isArray(data.positions)) {\n const page = pageId();\n const positions = data.positions.map((p) => (ours.has(p.id) ? { ...p, id: page } : p));\n return { ...event, data: { ...data, positions } };\n }\n return data.id !== undefined && ours.has(data.id) ? undefined : event;\n };\n}\n","/**\n * The recordings plugin's page half: `record()` starts rrweb (imported then) and shows the toolbar, a bar\n * docked to an edge of the window that its grip drags to any other, kept between recordings. It holds the\n * time, annotate mode's tools where that plugin is loaded, and Stop and Discard. Stop sends the events to\n * the `add` route.\n *\n * Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom\n * events: the page's annotations and the toolbar's own, which go when it does, as SVGs in page\n * coordinates, at the start and at each change.\n */\nimport { liveWaveform } from '#src/client/waveform.ts';\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { ResolvedMasking } from '#src/plugins/screenshots/index.ts';\n\nimport type { Take } from '#src/plugins/voice/index.ts';\n\nimport type { Kept, Recorder, Recording, VoiceClip } from './index.ts';\nimport { END, MARKS } from './marks.ts';\nimport { dropOurs } from './ours.ts';\n\ntype Edge = 'top' | 'bottom' | 'left' | 'right';\n/** Where the bar is: the edge it's docked to, and how far along it, from 0 to 1. */\ninterface Dock {\n edge: Edge;\n along: number;\n}\n\nconst DOCK = 'deictic:recorder';\nconst MARGIN = 12;\n\nconst STYLE = `\n.recorder { position: fixed; z-index: 2147483647; display: flex; align-items: center; gap: 6px; padding: 6px 8px;\n border: 1px solid var(--deictic-line); border-radius: 10px; background: var(--deictic-bg); color: var(--deictic-fg);\n box-shadow: 0 12px 32px rgb(0 0 0 / 0.35); font: 13px/1.4 system-ui, sans-serif; user-select: none; }\n.recorder.vertical { flex-direction: column; }\n.recorder.vertical .annotations-tools { flex-direction: column; }\n.recorder.vertical .annotations-tools .gap { width: auto; height: 1px; margin: 4px 2px; }\n.recorder .grip { display: inline-flex; padding: 2px; color: var(--deictic-muted); cursor: grab; touch-action: none; }\n.recorder .grip:active { cursor: grabbing; }\n.recorder .grip svg { width: 16px; height: 16px; }\n.recorder .live { display: inline-flex; align-items: center; gap: 6px; font: 12px ui-monospace, monospace; }\n.recorder .dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: deictic-blink 1.2s infinite; }\n.recorder .sep { align-self: stretch; width: 1px; background: var(--deictic-line); }\n.recorder.vertical .sep { width: auto; height: 1px; }\n.recorder .icon { display: inline-flex; align-items: center; justify-content: center; padding: 3px 5px; }\n.recorder .icon svg { width: 16px; height: 16px; }\n.recorder .mic[aria-pressed='true'] { background: #ef4444; border-color: #ef4444; color: #fff; }\n.recorder .wave { width: 44px; height: 18px; }\n.recorder.vertical .wave { width: 28px; }\n.recorder .wave[hidden] { display: none; }\n.recorder .mic.problem { border-color: var(--deictic-problem); color: var(--deictic-problem); }\n@keyframes deictic-blink { 50% { opacity: 0.3; } }\n`;\n\nconst svg = (paths: string) =>\n `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">${paths}</svg>`;\nconst GRIP = svg(\n '<circle cx=\"9\" cy=\"6\" r=\"1\"/><circle cx=\"15\" cy=\"6\" r=\"1\"/><circle cx=\"9\" cy=\"12\" r=\"1\"/><circle cx=\"15\" cy=\"12\" r=\"1\"/><circle cx=\"9\" cy=\"18\" r=\"1\"/><circle cx=\"15\" cy=\"18\" r=\"1\"/>',\n);\nconst STOP = svg('<rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"1\" fill=\"currentColor\"/>');\nconst DISCARD = svg('<path d=\"M6 6l12 12M18 6 6 18\"/>');\nconst MIC = svg('<rect x=\"9\" y=\"3\" width=\"6\" height=\"11\" rx=\"3\"/><path d=\"M5 11a7 7 0 0 0 14 0M12 18v3\"/>');\n\nconst clock = (ms: number) => {\n const s = Math.floor(ms / 1000);\n return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;\n};\n\nfunction storedDock(): Dock {\n try {\n const dock = JSON.parse(localStorage.getItem(DOCK) ?? 'null') as Dock | null;\n if (dock !== null && ['top', 'bottom', 'left', 'right'].includes(dock.edge) && dock.along >= 0 && dock.along <= 1) return dock;\n } catch {\n // Storage can be off, or hold something else: the default, then.\n }\n return { edge: 'bottom', along: 0.5 };\n}\n\nfunction iconButton(icon: string, name: string, run: () => void): HTMLButtonElement {\n const el = Object.assign(document.createElement('button'), { type: 'button', className: 'icon', title: name, innerHTML: icon });\n el.setAttribute('aria-label', name);\n el.addEventListener('click', run);\n return el;\n}\n\n/** Puts the bar on its edge, laid out along it, and how far along. */\nfunction place(bar: HTMLElement, { edge, along }: Dock): void {\n bar.classList.toggle('vertical', edge === 'left' || edge === 'right');\n const { width, height } = bar.getBoundingClientRect();\n const across = (room: number, size: number) => `${MARGIN + along * Math.max(0, room - size - MARGIN * 2)}px`;\n Object.assign(bar.style, {\n left: edge === 'left' ? `${MARGIN}px` : edge === 'right' ? `${innerWidth - width - MARGIN}px` : across(innerWidth, width),\n top: edge === 'top' ? `${MARGIN}px` : edge === 'bottom' ? `${innerHeight - height - MARGIN}px` : across(innerHeight, height),\n });\n}\n\n/** Dragging the bar by its grip, freely; let go, it docks to the nearest edge. */\nfunction draggable(bar: HTMLElement, grip: HTMLElement, docked: (dock: Dock) => void): void {\n grip.addEventListener('pointerdown', (e) => {\n if (e.button !== 0) return;\n e.preventDefault();\n grip.setPointerCapture(e.pointerId);\n const start = bar.getBoundingClientRect();\n const dx = e.clientX - start.left;\n const dy = e.clientY - start.top;\n const move = (m: PointerEvent) => {\n bar.style.left = `${m.clientX - dx}px`;\n bar.style.top = `${m.clientY - dy}px`;\n };\n const up = () => {\n grip.removeEventListener('pointermove', move);\n const r = bar.getBoundingClientRect();\n const x = r.left + r.width / 2;\n const y = r.top + r.height / 2;\n const away: [Edge, number][] = [\n ['left', x],\n ['right', innerWidth - x],\n ['top', y],\n ['bottom', innerHeight - y],\n ];\n const [edge] = away.reduce((a, b) => (b[1] < a[1] ? b : a));\n const ratio = (at: number, room: number) => Math.min(1, Math.max(0, at / room));\n docked({ edge, along: edge === 'left' || edge === 'right' ? ratio(y, innerHeight) : ratio(x, innerWidth) });\n };\n grip.addEventListener('pointermove', move);\n grip.addEventListener('pointerup', up, { once: true });\n });\n}\n\nexport default defineClientPlugin<never, never, Recorder>({\n name: 'recordings',\n setup: ({ base, root, options, use, request }) => {\n const { masking } = options as { masking: ResolvedMasking };\n let going = false;\n\n const record = async (): Promise<Recording | undefined> => {\n const rrweb = await import('rrweb').catch((e: unknown) => {\n throw new Error('recordings need rrweb: add it to your devDependencies', { cause: e });\n });\n const events: { type: number; data?: unknown }[] = [];\n const startedAt = Date.now();\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n const colorScheme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n const host = root.host;\n const keep = dropOurs<(typeof events)[number]>(\n () => rrweb.record.mirror.getId(host),\n () => rrweb.record.mirror.getId(document.documentElement),\n );\n const stopRecording = rrweb.record({\n emit: (event) => {\n const kept = keep(event);\n if (kept !== undefined) events.push(kept);\n },\n blockClass: masking.blockClass,\n // deictic's own UI, the overlay: a blocked element is kept as an empty box its size, and it has none.\n blockSelector: ['deictic-overlay', ...(masking.blockSelector ? [masking.blockSelector] : [])].join(', '),\n maskTextClass: masking.maskTextClass,\n ...(masking.maskTextSelector ? { maskTextSelector: masking.maskTextSelector } : {}),\n maskAllInputs: masking.maskAllInputs,\n maskInputOptions: { password: true },\n inlineStylesheet: true,\n });\n\n // The marks, now and at each change: an SVG whose view is the page from its top left, at 1:1.\n const marks = use('annotations');\n // The toolbar's own, drawn while recording: shown with the page's, gone when it ends.\n const tools = marks?.tools();\n const mark = () => {\n const area = { x: -scrollX, y: -scrollY, width: 1, height: 1 };\n rrweb.record.addCustomEvent(MARKS, {\n svg: [marks?.svg(area), tools?.marks.svg(area)].filter(Boolean).join(''),\n // The same marks as data, in page coordinates, for whatever reads the recording but doesn't draw it.\n annotations: [...(marks?.list() ?? []), ...(tools?.marks.list() ?? [])],\n });\n };\n mark();\n const unsubscribe = [marks?.subscribe(mark), tools?.marks.subscribe(mark)];\n\n return new Promise((done, fail) => {\n const bar = document.createElement('div');\n bar.className = 'recorder';\n bar.setAttribute('role', 'toolbar');\n bar.setAttribute('aria-label', 'Recording');\n const grip = Object.assign(document.createElement('span'), { className: 'grip', title: 'Drag to any edge', innerHTML: GRIP });\n const live = Object.assign(document.createElement('span'), { className: 'live' });\n const dot = Object.assign(document.createElement('span'), { className: 'dot' });\n const time = document.createElement('span');\n live.append(dot, time);\n const sep = () => Object.assign(document.createElement('span'), { className: 'sep' });\n\n // The mic, where the voice plugin is loaded: each stretch it's on is a clip, at its time in the recording.\n const voice = use('voice');\n const clips: VoiceClip[] = [];\n let take: Take | undefined;\n // The mic's live waveform beside it while it's on, so it's plain it hears.\n const wave = Object.assign(document.createElement('canvas'), { className: 'wave', hidden: true });\n let stopWave: (() => void) | undefined;\n const unwave = () => {\n stopWave?.();\n stopWave = undefined;\n wave.hidden = true;\n };\n // What the mic is doing (asking for it, keeping a take): the next toggle, and the end, wait for it.\n let busy: Promise<void> = Promise.resolve();\n const micOff = async () => {\n const ending = take;\n take = undefined;\n unwave();\n if (ending === undefined) return;\n try {\n const clip = await ending.stop();\n clips.push({ id: clip.id, at: ending.started - startedAt, duration: clip.duration });\n } catch (e) {\n // The recording is worth keeping without it.\n console.warn('deictic: the voice clip was not kept', e);\n }\n };\n const mic = voice === undefined ? undefined : iconButton(MIC, 'Turn the mic on', () => toggle());\n const toggle = () => {\n busy = busy.then(async () => {\n if (voice === undefined || mic === undefined) return;\n if (take !== undefined) {\n await micOff();\n } else {\n try {\n take = await voice.start();\n mic.classList.remove('problem');\n wave.hidden = false;\n stopWave = liveWaveform(wave, take.stream, { played: '#ef4444', rest: '#52525b' });\n } catch (e) {\n mic.classList.add('problem');\n mic.title = e instanceof Error ? e.message : String(e);\n return;\n }\n }\n const on = take !== undefined;\n mic.setAttribute('aria-pressed', String(on));\n mic.title = on ? 'Turn the mic off' : 'Turn the mic on';\n mic.setAttribute('aria-label', mic.title);\n });\n };\n mic?.classList.add('mic');\n mic?.setAttribute('aria-pressed', 'false');\n\n const end = async (keep: boolean) => {\n rrweb.record.addCustomEvent(END, {});\n stopRecording?.();\n for (const stop of unsubscribe) stop?.();\n tools?.close();\n clearInterval(ticking);\n removeEventListener('resize', replace);\n bar.remove();\n await busy;\n if (!keep) {\n unwave();\n take?.cancel();\n return done(undefined);\n }\n await micOff();\n const duration = Date.now() - startedAt;\n const voiced = clips.length > 0 ? { voice: clips } : {};\n const kept: Kept = { page: location.href, viewport, colorScheme, startedAt, duration, events, ...voiced };\n try {\n const res = await request('add', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(kept),\n });\n // `url`: where it replays, said by what keeps it with no server to serve it from (a `standalone` build).\n const { id, url, problem } = (await res.json()) as { id?: string; url?: string; problem?: string };\n if (id === undefined) throw new Error(`recordings: ${problem ?? res.statusText}`);\n done({ id, url: url ?? `${base}__deictic/plugins/recordings/replay/${id}`, duration, ...voiced });\n } catch (e) {\n fail(e);\n }\n };\n const stop = iconButton(STOP, 'Stop, and keep the recording', () => void end(true));\n const discard = iconButton(DISCARD, 'Discard the recording', () => void end(false));\n bar.append(grip, live, ...(tools ? [sep(), tools.element] : []), sep(), ...(mic ? [mic, wave] : []), stop, discard);\n const style = Object.assign(document.createElement('style'), { textContent: STYLE });\n bar.prepend(style);\n root.append(bar);\n\n const tick = () => (time.textContent = clock(Date.now() - startedAt));\n tick();\n const ticking = setInterval(tick, 250);\n let dock = storedDock();\n const replace = () => place(bar, dock);\n replace();\n addEventListener('resize', replace);\n draggable(bar, grip, (next) => {\n dock = next;\n replace();\n try {\n localStorage.setItem(DOCK, JSON.stringify(dock));\n } catch {\n // Not kept, then: the next recording starts at the bottom.\n }\n });\n });\n };\n\n return {\n recording: () => going,\n record: async () => {\n if (going) throw new Error('recordings: one is going already: stop it first');\n going = true;\n try {\n return await record();\n } finally {\n going = false;\n }\n },\n };\n },\n});\n"],"mappings":";;;;;AAyBA,MAAM,cAAc;AACpB,MAAM,WAAW;AACjB,MAAM,4BAAY,IAAI,IAAI;CAAC;CAAG;CAAG;AAAE,CAAC;;AAGpC,SAAgB,SAA0B,QAAsB,QAAmD;CACjH,MAAM,uBAAO,IAAI,IAAY;CAC7B,QAAQ,UAAU;EAChB,IAAI,KAAK,SAAS,GAAG;GACnB,MAAM,KAAK,OAAO;GAClB,IAAI,KAAK,GAAG,KAAK,IAAI,EAAE;EACzB;EACA,IAAI,MAAM,SAAS,eAAe,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,MAAM,OAAO;EAChG,MAAM,OAAO,MAAM;EAEnB,IAAI,KAAK,WAAW,UAAU;GAC5B,MAAM,IAAI;GAEV,KAAK,IAAI,OAAO,MAAM,OAAO;IAC3B,OAAO;IACP,KAAK,MAAM,OAAO,EAAE,MAClB,IAAI,KAAK,IAAI,IAAI,QAAQ,KAAK,CAAC,KAAK,IAAI,IAAI,KAAK,EAAE,GAAG;KACpD,KAAK,IAAI,IAAI,KAAK,EAAE;KACpB,OAAO;IACT;GAEJ;GACA,MAAM,OAAiB;IACrB,GAAG;IACH,MAAM,EAAE,KAAK,QAAQ,MAAM,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,CAAC;IAC/C,SAAS,EAAE,QAAQ,QAAQ,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE,QAAQ,CAAC;IACzE,OAAO,EAAE,MAAM,QAAQ,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC;IAC5C,YAAY,EAAE,WAAW,QAAQ,MAAM,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AAG;MACV,KAAK,CAAC;KACR;IACF;IACA,MAAM,OAAO,WAAW,MAAM,sCAAsC,KAAK,IAAI,IAAI,CAAC;IAClF,MAAM,UAAU,WAAW,SAAS,+BAA+B,KAAK,IAAI,KAAK,CAAC;IAClF,IAAI,OAAO,MAAM,MAAM,GAAI,QAAQ,CAAC,IAAI,GAAG,MAAM,OAAO,IAAI,CAAC,GAAI,IAAI,GAAG,GAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,GAAI,MAAM,OAAO;IAClH,MAAM,QAAQ,OAAO,OAAO,SAAS,cAAc,OAAO,GAAG,EAAE,aAAa,MAAM,CAAC;IACnF,IAAI,QAAQ,KAAK;IACjB,KAAK,OAAO,GAAG;IAEf,MAAM,aAAc,KAAK,cAAc,MAAM,KAAK,IAAI,IAAI,SAAS;IACnE,KAAK;IACL,MAAM,UAAU,YAAY,MAAM,GAAG;IACrC,IAAI,OAAO,WAAW;IACtB,MAAM,gBAAgB,MAAM,KAAK,IAAI;IACrC,QAAQ;IACR,iBAAiB,UAAU,OAAO;IAClC,UAAU,KAAK,OAAO,SAAS;KAC7B,OAAO;KACP,QAAQ;KACR,IAAI;MACF,aAAa,QAAQ,MAAM,KAAK,UAAU,IAAI,CAAC;KACjD,QAAQ,CAER;IACF,CAAC;GACH,CAAC;EACH;EAEA,OAAO;GACL,iBAAiB;GACjB,QAAQ,YAAY;IAClB,IAAI,OAAO,MAAM,IAAI,MAAM,iDAAiD;IAC5E,QAAQ;IACR,IAAI;KACF,OAAO,MAAM,OAAO;IACtB,UAAU;KACR,QAAQ;IACV;GACF;EACF;CACF;AACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { a as RecordingsOptions, c as ReplaySources, i as Recordings, l as replayPage, n as Recorder, o as VoiceClip, r as Recording, s as recordings, t as Kept, u as MARKS } from "../shared/index3.js";
2
+ export { Kept, MARKS, Recorder, Recording, Recordings, RecordingsOptions, type ReplaySources, VoiceClip, recordings as default, recordings, replayPage };
@@ -0,0 +1,3 @@
1
+ import { n as MARKS } from "../shared/marks.js";
2
+ import { n as replayPage, t as recordings } from "../shared/recordings.js";
3
+ export { MARKS, recordings as default, recordings, replayPage };
@@ -0,0 +1,23 @@
1
+ import { i as CaptureOptions, r as Capture, s as ResolvedMasking, t as Box } from "../shared/index2.js";
2
+ /**
3
+ * What a renderer's page half makes of the element: a body for `add`, its type, and where the element is
4
+ * in the shot. `overlay(area)` is what's drawn over the page in that part of the viewport, in viewport CSS
5
+ * pixels, as an SVG that size, or nothing: the annotations plugin's marks, where it's loaded. The renderer
6
+ * draws it over the shot, as deictic's own layers are left out.
7
+ */
8
+ export type PageCapture = (element: Element, options: {
9
+ area: NonNullable<CaptureOptions['area']>;
10
+ masking: ResolvedMasking;
11
+ renderer: unknown;
12
+ overlay: (area: Box) => string | undefined;
13
+ }) => Promise<{
14
+ body: Blob | string;
15
+ type: string;
16
+ box: Box;
17
+ }>;
18
+ /** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */
19
+ export declare const notOurs: (node: Node) => boolean;
20
+ /** The element's box, in CSS pixels from the viewport's top left, or from its own for a shot of it alone. */
21
+ export declare function boxOf(element: Element, area: NonNullable<CaptureOptions['area']>): Box;
22
+ export declare function screenshotsClient(capture: PageCapture): import("deictic").ClientPlugin<never, never, Capture>;
23
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../../src/plugins/screenshots/client.ts"],"mappings":";;;;;;;YAgBY,eACV,SAAS,SACT;EACE,MAAM,YAAY;EAClB,SAAS;EACT;EACA,UAAU,MAAM;MAEf;EAAU,MAAM;EAAe;EAAc,KAAK;;;qBAG1C,UAAO,MAAU;;wBAGd,MAAM,SAAS,SAAS,MAAM,YAAY,0BAA0B;wBAKpE,kBAAkB,SAAS,gCAAW,2BAAA"}
@@ -0,0 +1,76 @@
1
+ import { defineClientPlugin } from "../index.js";
2
+ // src/plugins/screenshots/client.ts
3
+ /**
4
+ * The screenshots plugin's page half, around a renderer's capture: the renderer makes the shot (a PNG,
5
+ * or what its server half makes one of), and this sends it to the plugin's `add` route and answers the
6
+ * `Shot`. A renderer's page module default-exports `screenshotsClient(itsCapture)`.
7
+ */
8
+ /** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */
9
+ const notOurs = (node) => !(node instanceof Element && node.localName === "deictic-overlay");
10
+ /** The element's box, in CSS pixels from the viewport's top left, or from its own for a shot of it alone. */
11
+ function boxOf(element, area) {
12
+ const { x, y, width, height } = element.getBoundingClientRect();
13
+ return area === "element" ? {
14
+ x: 0,
15
+ y: 0,
16
+ width,
17
+ height
18
+ } : {
19
+ x,
20
+ y,
21
+ width,
22
+ height
23
+ };
24
+ }
25
+ function screenshotsClient(capture) {
26
+ return defineClientPlugin({
27
+ name: "screenshots",
28
+ setup: ({ base, request, options, use }) => {
29
+ const { masking, renderer } = options;
30
+ const overlay = (area) => {
31
+ return use("annotations")?.svg(area);
32
+ };
33
+ const add = async (body, type, { box, size }) => {
34
+ const res = await request("add", {
35
+ method: "POST",
36
+ headers: { "content-type": type },
37
+ body
38
+ });
39
+ const { id, url, problem } = await res.json();
40
+ if (id === void 0) throw new Error(`screenshots: ${problem ?? res.statusText}`);
41
+ return {
42
+ id,
43
+ url: url ?? `${base}__deictic/plugins/screenshots/shot/${id}`,
44
+ box,
45
+ size
46
+ };
47
+ };
48
+ return {
49
+ capture: async (element, { area = "viewport" } = {}) => {
50
+ const { body, type, box } = await capture(element, {
51
+ area,
52
+ masking,
53
+ renderer,
54
+ overlay
55
+ });
56
+ const { clientWidth, clientHeight } = document.documentElement;
57
+ const size = area === "element" ? {
58
+ width: box.width,
59
+ height: box.height
60
+ } : {
61
+ width: clientWidth,
62
+ height: clientHeight
63
+ };
64
+ return add(body, type, {
65
+ box,
66
+ size
67
+ });
68
+ },
69
+ upload: (png, of) => add(png, "image/png", of)
70
+ };
71
+ }
72
+ });
73
+ }
74
+ export { boxOf, notOurs, screenshotsClient };
75
+
76
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/screenshots/client.ts"],"sourcesContent":["/**\n * The screenshots plugin's page half, around a renderer's capture: the renderer makes the shot (a PNG,\n * or what its server half makes one of), and this sends it to the plugin's `add` route and answers the\n * `Shot`. A renderer's page module default-exports `screenshotsClient(itsCapture)`.\n */\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { Annotations } from '#src/plugins/annotations/index.ts';\n\nimport type { Box, Capture, CaptureOptions, ResolvedMasking, Shot } from './index.ts';\n\n/**\n * What a renderer's page half makes of the element: a body for `add`, its type, and where the element is\n * in the shot. `overlay(area)` is what's drawn over the page in that part of the viewport, in viewport CSS\n * pixels, as an SVG that size, or nothing: the annotations plugin's marks, where it's loaded. The renderer\n * draws it over the shot, as deictic's own layers are left out.\n */\nexport type PageCapture = (\n element: Element,\n options: {\n area: NonNullable<CaptureOptions['area']>;\n masking: ResolvedMasking;\n renderer: unknown;\n overlay: (area: Box) => string | undefined;\n },\n) => Promise<{ body: Blob | string; type: string; box: Box }>;\n\n/** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */\nexport const notOurs = (node: Node) => !(node instanceof Element && node.localName === 'deictic-overlay');\n\n/** The element's box, in CSS pixels from the viewport's top left, or from its own for a shot of it alone. */\nexport function boxOf(element: Element, area: NonNullable<CaptureOptions['area']>): Box {\n const { x, y, width, height } = element.getBoundingClientRect();\n return area === 'element' ? { x: 0, y: 0, width, height } : { x, y, width, height };\n}\n\nexport function screenshotsClient(capture: PageCapture) {\n return defineClientPlugin<never, never, Capture>({\n name: 'screenshots',\n setup: ({ base, request, options, use }) => {\n const { masking, renderer } = options as { masking: ResolvedMasking; renderer: unknown };\n // Asked at each shot: the annotations plugin may be set up after this one.\n const overlay = (area: Box) => {\n const marks: Annotations | undefined = use('annotations');\n return marks?.svg(area);\n };\n const add = async (body: Blob | string, type: string, { box, size }: Pick<Shot, 'box' | 'size'>): Promise<Shot> => {\n const res = await request('add', { method: 'POST', headers: { 'content-type': type }, body });\n // `url`: where the shot is, said by what keeps it with no server to serve it from (a `standalone` build).\n const { id, url, problem } = (await res.json()) as { id?: string; url?: string; problem?: string };\n if (id === undefined) throw new Error(`screenshots: ${problem ?? res.statusText}`);\n return { id, url: url ?? `${base}__deictic/plugins/screenshots/shot/${id}`, box, size };\n };\n return {\n capture: async (element, { area = 'viewport' } = {}) => {\n const { body, type, box } = await capture(element, { area, masking, renderer, overlay });\n const { clientWidth, clientHeight } = document.documentElement;\n const size = area === 'element' ? { width: box.width, height: box.height } : { width: clientWidth, height: clientHeight };\n return add(body, type, { box, size });\n },\n upload: (png, of) => add(png, 'image/png', of),\n };\n },\n });\n}\n"],"mappings":";;;;;;;;AA2BA,MAAa,WAAW,SAAe,EAAE,gBAAgB,WAAW,KAAK,cAAc;;AAGvF,SAAgB,MAAM,SAAkB,MAAgD;CACtF,MAAM,EAAE,GAAG,GAAG,OAAO,WAAW,QAAQ,sBAAsB;CAC9D,OAAO,SAAS,YAAY;EAAE,GAAG;EAAG,GAAG;EAAG;EAAO;CAAO,IAAI;EAAE;EAAG;EAAG;EAAO;CAAO;AACpF;AAEA,SAAgB,kBAAkB,SAAsB;CACtD,OAAO,mBAA0C;EAC/C,MAAM;EACN,QAAQ,EAAE,MAAM,SAAS,SAAS,UAAU;GAC1C,MAAM,EAAE,SAAS,aAAa;GAE9B,MAAM,WAAW,SAAc;IAE7B,OADuC,IAAI,aAChC,CAAC,EAAE,IAAI,IAAI;GACxB;GACA,MAAM,MAAM,OAAO,MAAqB,MAAc,EAAE,KAAK,WAAsD;IACjH,MAAM,MAAM,MAAM,QAAQ,OAAO;KAAE,QAAQ;KAAQ,SAAS,EAAE,gBAAgB,KAAK;KAAG;IAAK,CAAC;IAE5F,MAAM,EAAE,IAAI,KAAK,YAAa,MAAM,IAAI,KAAK;IAC7C,IAAI,OAAO,KAAA,GAAW,MAAM,IAAI,MAAM,gBAAgB,WAAW,IAAI,YAAY;IACjF,OAAO;KAAE;KAAI,KAAK,OAAO,GAAG,KAAK,qCAAqC;KAAM;KAAK;IAAK;GACxF;GACA,OAAO;IACL,SAAS,OAAO,SAAS,EAAE,OAAO,eAAe,CAAC,MAAM;KACtD,MAAM,EAAE,MAAM,MAAM,QAAQ,MAAM,QAAQ,SAAS;MAAE;MAAM;MAAS;MAAU;KAAQ,CAAC;KACvF,MAAM,EAAE,aAAa,iBAAiB,SAAS;KAC/C,MAAM,OAAO,SAAS,YAAY;MAAE,OAAO,IAAI;MAAO,QAAQ,IAAI;KAAO,IAAI;MAAE,OAAO;MAAa,QAAQ;KAAa;KACxH,OAAO,IAAI,MAAM,MAAM;MAAE;MAAK;KAAK,CAAC;IACtC;IACA,SAAS,KAAK,OAAO,IAAI,KAAK,aAAa,EAAE;GAC/C;EACF;CACF,CAAC;AACH"}
@@ -0,0 +1,4 @@
1
+ import { r as Capture } from "../shared/index2.js";
2
+ declare const _default: import("deictic").ClientPlugin<never, never, Capture>;
3
+ export { _default as default };
4
+ //# sourceMappingURL=dom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.d.ts","names":["_$__index_ts0.Capture"],"sources":["../../src/plugins/screenshots/dom.ts"],"mappings":";cAgDA,4B,2BAAAA"}
@@ -0,0 +1,92 @@
1
+ import { boxOf, notOurs, screenshotsClient } from "./client.js";
2
+ // src/plugins/screenshots/dom.ts
3
+ /**
4
+ * The `dom()` renderer's page half: draws the page in the page from its DOM with `modern-screenshot`
5
+ * (imported on the first shot), so it needs no server, but text may lay out a little differently than
6
+ * the page's. Masking changes only the copy that's drawn, never the page.
7
+ */
8
+ const BLANK = "#d4d4d8";
9
+ const selector = (className, extra) => [`.${CSS.escape(className)}`, ...extra ? [extra] : []].join(", ");
10
+ /**
11
+ * Hides in the copy what rrweb would: blocked elements become a blank box their size (the copy keeps each
12
+ * element's size as its styles), masked text keeps its spaces but shows `*`, and so do passwords' values,
13
+ * or every field's.
14
+ */
15
+ function mask(copy, m) {
16
+ if (!(copy instanceof Element)) return;
17
+ const all = (sel) => [...copy.matches(sel) ? [copy] : [], ...copy.querySelectorAll(sel)];
18
+ const stars = (text) => text.replace(/\S/g, "*");
19
+ for (const el of all(selector(m.blockClass, m.blockSelector))) {
20
+ el.replaceChildren();
21
+ if (el instanceof HTMLElement || el instanceof SVGElement) el.style.background = BLANK;
22
+ }
23
+ for (const el of all(selector(m.maskTextClass, m.maskTextSelector))) {
24
+ const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
25
+ for (let text = walker.nextNode(); text !== null; text = walker.nextNode()) text.textContent = stars(text.textContent ?? "");
26
+ }
27
+ for (const field of all("input, textarea")) {
28
+ if (!(field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement)) continue;
29
+ if (!m.maskAllInputs && !(field instanceof HTMLInputElement && field.type === "password")) continue;
30
+ field.value = stars(field.value);
31
+ field.setAttribute("value", field.value);
32
+ if (field instanceof HTMLTextAreaElement) field.textContent = field.value;
33
+ }
34
+ }
35
+ /** Draws an SVG over the whole canvas, which is the area it was made for at the canvas's scale. */
36
+ async function drawOver(canvas, svg) {
37
+ if (svg === void 0) return canvas;
38
+ const image = new Image();
39
+ image.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
40
+ await image.decode();
41
+ canvas.getContext("2d")?.drawImage(image, 0, 0, canvas.width, canvas.height);
42
+ return canvas;
43
+ }
44
+ var dom_default = screenshotsClient(async (element, { area, masking, overlay }) => {
45
+ const { domToCanvas } = await import("modern-screenshot").catch((e) => {
46
+ throw new Error("the dom() renderer needs modern-screenshot: add it to your devDependencies", { cause: e });
47
+ });
48
+ const scale = Math.min(devicePixelRatio, 2);
49
+ const options = {
50
+ filter: notOurs,
51
+ scale,
52
+ onCloneNode: (copy) => mask(copy, masking)
53
+ };
54
+ const box = boxOf(element, area);
55
+ const toPng = (canvas) => new Promise((done, fail) => canvas.toBlob((blob) => blob === null ? fail(/* @__PURE__ */ new Error("screenshots: the page drew nothing")) : done(blob), "image/png"));
56
+ if (area === "element") {
57
+ const { x, y, width, height } = element.getBoundingClientRect();
58
+ return {
59
+ body: await toPng(await drawOver(await domToCanvas(element, options), overlay({
60
+ x,
61
+ y,
62
+ width,
63
+ height
64
+ }))),
65
+ type: "image/png",
66
+ box
67
+ };
68
+ }
69
+ const page = await domToCanvas(document.documentElement, options);
70
+ const { clientWidth: width, clientHeight: height } = document.documentElement;
71
+ const at = document.documentElement.getBoundingClientRect();
72
+ const canvas = document.createElement("canvas");
73
+ canvas.width = width * scale;
74
+ canvas.height = height * scale;
75
+ const ctx = canvas.getContext("2d");
76
+ if (ctx === null) throw new Error("screenshots: this browser won't draw to a canvas");
77
+ ctx.drawImage(page, -at.left * scale, -at.top * scale, canvas.width, canvas.height, 0, 0, canvas.width, canvas.height);
78
+ await drawOver(canvas, overlay({
79
+ x: 0,
80
+ y: 0,
81
+ width,
82
+ height
83
+ }));
84
+ return {
85
+ body: await toPng(canvas),
86
+ type: "image/png",
87
+ box
88
+ };
89
+ });
90
+ export { dom_default as default };
91
+
92
+ //# sourceMappingURL=dom.js.map