deictic 0.2.0 → 0.3.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.
- package/API.md +303 -0
- package/README.md +56 -127
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +117 -7
- package/dist/client/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/logs/client.d.ts +4 -0
- package/dist/logs/client.d.ts.map +1 -0
- package/dist/logs/client.js +16 -0
- package/dist/logs/client.js.map +1 -0
- package/dist/logs/index.d.ts +18 -0
- package/dist/logs/index.d.ts.map +1 -0
- package/dist/logs/index.js +21 -0
- package/dist/logs/index.js.map +1 -0
- package/dist/network/client.d.ts +4 -0
- package/dist/network/client.d.ts.map +1 -0
- package/dist/network/client.js +29 -0
- package/dist/network/client.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.js +39 -0
- package/dist/network/index.js.map +1 -0
- package/dist/recommended/index.d.ts +13 -3
- package/dist/recommended/index.d.ts.map +1 -1
- package/dist/recommended/index.js +8 -1
- package/dist/recommended/index.js.map +1 -1
- package/dist/recordings/client.d.ts +1 -1
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +175 -46
- package/dist/recordings/client.js.map +1 -1
- package/dist/recordings/index.d.ts +2 -2
- package/dist/screenshots/client.d.ts +6 -0
- package/dist/screenshots/client.d.ts.map +1 -1
- package/dist/screenshots/client.js +34 -2
- package/dist/screenshots/client.js.map +1 -1
- package/dist/screenshots/dom.d.ts.map +1 -1
- package/dist/screenshots/dom.js +1 -28
- package/dist/screenshots/dom.js.map +1 -1
- package/dist/screenshots/index.js.map +1 -1
- package/dist/screenshots/rrweb.d.ts +1 -1
- package/dist/screenshots/rrweb.js +5 -1
- package/dist/screenshots/rrweb.js.map +1 -1
- package/dist/shared/index.d.ts +14 -2
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index2.d.ts +2 -0
- package/dist/shared/index2.d.ts.map +1 -1
- package/dist/shared/index3.d.ts +29 -3
- package/dist/shared/index3.d.ts.map +1 -1
- package/dist/shared/index4.d.ts +52 -172
- package/dist/shared/index4.d.ts.map +1 -1
- package/dist/shared/index5.d.ts +208 -58
- package/dist/shared/index5.d.ts.map +1 -1
- package/dist/shared/index6.d.ts +70 -0
- package/dist/shared/index6.d.ts.map +1 -0
- package/dist/shared/marks.js +6 -1
- package/dist/shared/marks.js.map +1 -1
- package/dist/shared/mask.js +107 -0
- package/dist/shared/mask.js.map +1 -0
- package/dist/shared/playwright.js +19 -4
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/recordings.js +219 -28
- package/dist/shared/recordings.js.map +1 -1
- package/dist/shared/tasks.js +145 -34
- package/dist/shared/tasks.js.map +1 -1
- package/dist/tailwind/client.d.ts +1 -1
- package/dist/tailwind/index.d.ts +1 -1
- package/dist/tasks/client.d.ts +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +271 -56
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +2 -2
- package/dist/voice/client.d.ts.map +1 -1
- package/dist/voice/client.js +35 -14
- package/dist/voice/client.js.map +1 -1
- package/dist/voice/index.d.ts +6 -1
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +12 -2
- package/dist/voice/index.js.map +1 -1
- package/package.json +41 -2
- package/skills/deictic/SKILL.md +20 -14
- package/skills/deictic/references/install.md +18 -11
- package/skills/deictic/references/recordings.md +29 -0
- package/skills/deictic/references/tasks.md +49 -21
- package/skills/deictic/references/watch.md +38 -11
- package/skills/deictic/scripts/lib.mjs +69 -3
- package/skills/deictic/scripts/recording.mjs +84 -4
- package/skills/deictic/scripts/task.mjs +36 -7
- package/skills/deictic/scripts/vb.mjs +12 -0
- package/skills/deictic/scripts/watch.mjs +74 -10
- package/src/client/away.ts +105 -0
- package/src/client/index.ts +40 -9
- package/src/client/style.ts +1 -0
- package/src/index.ts +14 -2
- package/src/plugins/logs/client.ts +18 -0
- package/src/plugins/logs/index.ts +55 -0
- package/src/plugins/network/client.ts +30 -0
- package/src/plugins/network/index.ts +69 -0
- package/src/plugins/network/mask.ts +133 -0
- package/src/plugins/recommended/index.ts +14 -1
- package/src/plugins/recordings/client.ts +219 -40
- package/src/plugins/recordings/index.ts +108 -23
- package/src/plugins/recordings/marks.ts +6 -0
- package/src/plugins/recordings/replay.ts +127 -4
- package/src/plugins/screenshots/client.ts +35 -0
- package/src/plugins/screenshots/dom.ts +1 -32
- package/src/plugins/screenshots/index.ts +2 -0
- package/src/plugins/screenshots/playwright.ts +15 -4
- package/src/plugins/screenshots/rrweb.ts +2 -1
- package/src/plugins/tasks/client.ts +273 -41
- package/src/plugins/tasks/index.ts +155 -39
- package/src/plugins/tasks/watchers.ts +36 -0
- package/src/plugins/voice/client.ts +33 -11
- package/src/plugins/voice/index.ts +21 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as liveWaveform } from "../shared/waveform.js";
|
|
2
2
|
import { defineClientPlugin } from "../index.js";
|
|
3
|
-
import { n as MARKS, t as END } from "../shared/marks.js";
|
|
3
|
+
import { n as MARKS, r as PAGE, t as END } from "../shared/marks.js";
|
|
4
4
|
// src/plugins/recordings/ours.ts
|
|
5
5
|
/** rrweb's numbers: an incremental snapshot, and the sources whose data is a list of pointer positions. */
|
|
6
6
|
const INCREMENTAL = 3;
|
|
@@ -62,14 +62,36 @@ function dropOurs(hostId, pageId) {
|
|
|
62
62
|
/**
|
|
63
63
|
* The recordings plugin's page half: `record()` starts rrweb (imported then) and shows the toolbar, a bar
|
|
64
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.
|
|
66
|
-
*
|
|
65
|
+
* time, annotate mode's tools where that plugin is loaded, and Stop and Discard.
|
|
66
|
+
*
|
|
67
|
+
* The events go to the server as they happen (`begin`, a `part` each second, `end` on Stop), and what the next
|
|
68
|
+
* page needs to carry on is kept in the tab's session storage: a reload, or a link to another page of the site,
|
|
69
|
+
* leaves the recording going. The page that loads starts rrweb again under the same ID, which makes it a
|
|
70
|
+
* recording of several pages as rrweb has them (a `Meta` and a snapshot for each), puts the toolbar back with
|
|
71
|
+
* its time running, and turns the mic back on where it was.
|
|
67
72
|
*
|
|
68
73
|
* Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom
|
|
69
74
|
* events: the page's annotations and the toolbar's own, which go when it does, as SVGs in page
|
|
70
75
|
* coordinates, at the start and at each change.
|
|
71
76
|
*/
|
|
72
77
|
const DOCK = "deictic:recorder";
|
|
78
|
+
/** Where the recording going on is kept, for the tab's next page to carry on with. */
|
|
79
|
+
const GOING = "deictic:recording";
|
|
80
|
+
/** How often the events are sent, in milliseconds. */
|
|
81
|
+
const EVERY = 1e3;
|
|
82
|
+
function carried() {
|
|
83
|
+
try {
|
|
84
|
+
return JSON.parse(sessionStorage.getItem(GOING) ?? "null") ?? void 0;
|
|
85
|
+
} catch {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function carry(going) {
|
|
90
|
+
try {
|
|
91
|
+
if (going === void 0) sessionStorage.removeItem(GOING);
|
|
92
|
+
else sessionStorage.setItem(GOING, JSON.stringify(going));
|
|
93
|
+
} catch {}
|
|
94
|
+
}
|
|
73
95
|
const MARGIN = 12;
|
|
74
96
|
const STYLE = `
|
|
75
97
|
.recorder { position: fixed; z-index: 2147483647; display: flex; align-items: center; gap: 6px; padding: 6px 8px;
|
|
@@ -176,36 +198,86 @@ function draggable(bar, grip, docked) {
|
|
|
176
198
|
var client_default = defineClientPlugin({
|
|
177
199
|
name: "recordings",
|
|
178
200
|
setup: ({ base, root, options, use, request }) => {
|
|
179
|
-
const { masking } = options;
|
|
180
|
-
let going
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
|
|
201
|
+
const { masking, canvas } = options;
|
|
202
|
+
let going;
|
|
203
|
+
const post = async (route, body, keepalive = false) => {
|
|
204
|
+
const res = await request(route, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: { "content-type": "application/json" },
|
|
207
|
+
body: JSON.stringify(body),
|
|
208
|
+
...keepalive ? { keepalive } : {}
|
|
184
209
|
});
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
210
|
+
const answer = await res.json();
|
|
211
|
+
if (answer.id === void 0) throw new Error(`recordings: ${answer.problem ?? res.statusText}`);
|
|
212
|
+
return {
|
|
213
|
+
id: answer.id,
|
|
214
|
+
url: answer.url
|
|
190
215
|
};
|
|
191
|
-
|
|
216
|
+
};
|
|
217
|
+
/** Records until Stop or Discard: a new recording, or `from`, one a page before this started. */
|
|
218
|
+
const record = async (from) => {
|
|
219
|
+
const startedAt = from?.startedAt ?? Date.now();
|
|
220
|
+
const begin = async () => {
|
|
221
|
+
const viewport = {
|
|
222
|
+
width: document.documentElement.clientWidth,
|
|
223
|
+
height: document.documentElement.clientHeight
|
|
224
|
+
};
|
|
225
|
+
const colorScheme = matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
226
|
+
return (await post("begin", {
|
|
227
|
+
page: location.href,
|
|
228
|
+
viewport,
|
|
229
|
+
colorScheme,
|
|
230
|
+
startedAt
|
|
231
|
+
})).id;
|
|
232
|
+
};
|
|
233
|
+
const extra = (name) => use(name)?.plugin({ sinceLoad: from !== void 0 }).catch((e) => {
|
|
234
|
+
console.warn(`deictic: this recording has no ${name}`, e);
|
|
235
|
+
});
|
|
236
|
+
const [rrweb, id, ...extras] = await Promise.all([
|
|
237
|
+
import("rrweb").catch((e) => {
|
|
238
|
+
throw new Error("recordings need rrweb: add it to your devDependencies", { cause: e });
|
|
239
|
+
}),
|
|
240
|
+
from?.id ?? begin(),
|
|
241
|
+
extra("logs"),
|
|
242
|
+
extra("network")
|
|
243
|
+
]);
|
|
244
|
+
const clips = from?.clips ?? [];
|
|
245
|
+
let unsent = [];
|
|
246
|
+
let seq = from?.seq ?? 0;
|
|
192
247
|
const host = root.host;
|
|
193
248
|
const keep = dropOurs(() => rrweb.record.mirror.getId(host), () => rrweb.record.mirror.getId(document.documentElement));
|
|
249
|
+
let href = location.href;
|
|
250
|
+
const moved = () => {
|
|
251
|
+
if (location.href === href) return;
|
|
252
|
+
href = location.href;
|
|
253
|
+
rrweb.record.addCustomEvent(PAGE, { href });
|
|
254
|
+
};
|
|
194
255
|
const stopRecording = rrweb.record({
|
|
195
256
|
emit: (event) => {
|
|
257
|
+
moved();
|
|
196
258
|
const kept = keep(event);
|
|
197
|
-
if (kept !== void 0)
|
|
259
|
+
if (kept !== void 0) unsent.push(kept);
|
|
198
260
|
},
|
|
261
|
+
plugins: extras.filter((plugin) => plugin !== void 0),
|
|
199
262
|
blockClass: masking.blockClass,
|
|
200
263
|
blockSelector: ["deictic-overlay", ...masking.blockSelector ? [masking.blockSelector] : []].join(", "),
|
|
201
264
|
maskTextClass: masking.maskTextClass,
|
|
202
265
|
...masking.maskTextSelector ? { maskTextSelector: masking.maskTextSelector } : {},
|
|
203
266
|
maskAllInputs: masking.maskAllInputs,
|
|
204
267
|
maskInputOptions: { password: true },
|
|
205
|
-
inlineStylesheet: true
|
|
268
|
+
inlineStylesheet: true,
|
|
269
|
+
...canvas === false || canvas === void 0 ? {} : {
|
|
270
|
+
recordCanvas: true,
|
|
271
|
+
sampling: { canvas: canvas.fps },
|
|
272
|
+
dataURLOptions: {
|
|
273
|
+
type: "image/webp",
|
|
274
|
+
quality: .6
|
|
275
|
+
}
|
|
276
|
+
}
|
|
206
277
|
});
|
|
207
278
|
const marks = use("annotations");
|
|
208
279
|
const tools = marks?.tools();
|
|
280
|
+
if (from?.path === location.pathname) for (const shape of from.marks) tools?.marks.add(shape);
|
|
209
281
|
const mark = () => {
|
|
210
282
|
const area = {
|
|
211
283
|
x: -scrollX,
|
|
@@ -219,7 +291,43 @@ var client_default = defineClientPlugin({
|
|
|
219
291
|
});
|
|
220
292
|
};
|
|
221
293
|
mark();
|
|
222
|
-
const
|
|
294
|
+
const voice = use("voice");
|
|
295
|
+
let take;
|
|
296
|
+
/** What the next page carries on from, kept as it changes: a page that's going has no time to say it then. */
|
|
297
|
+
let over = false;
|
|
298
|
+
const save = () => over || carry({
|
|
299
|
+
id,
|
|
300
|
+
startedAt,
|
|
301
|
+
seq,
|
|
302
|
+
clips,
|
|
303
|
+
mic: take !== void 0,
|
|
304
|
+
path: location.pathname,
|
|
305
|
+
marks: tools?.marks.list().map((a) => a.shape) ?? []
|
|
306
|
+
});
|
|
307
|
+
const unsubscribe = [marks?.subscribe(mark), tools?.marks.subscribe(() => {
|
|
308
|
+
mark();
|
|
309
|
+
save();
|
|
310
|
+
})];
|
|
311
|
+
let sending = Promise.resolve();
|
|
312
|
+
const flush = () => {
|
|
313
|
+
const next = sending.catch(() => {}).then(async () => {
|
|
314
|
+
if (unsent.length === 0) return;
|
|
315
|
+
const part = unsent;
|
|
316
|
+
unsent = [];
|
|
317
|
+
const at = seq++;
|
|
318
|
+
save();
|
|
319
|
+
try {
|
|
320
|
+
await post(`part/${id}?seq=${at}`, part);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
unsent = [...part, ...unsent];
|
|
323
|
+
throw e;
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
sending = next;
|
|
327
|
+
return next;
|
|
328
|
+
};
|
|
329
|
+
const flushing = setInterval(() => void flush().catch(() => {}), EVERY);
|
|
330
|
+
save();
|
|
223
331
|
return new Promise((done, fail) => {
|
|
224
332
|
const bar = document.createElement("div");
|
|
225
333
|
bar.className = "recorder";
|
|
@@ -235,9 +343,6 @@ var client_default = defineClientPlugin({
|
|
|
235
343
|
const time = document.createElement("span");
|
|
236
344
|
live.append(dot, time);
|
|
237
345
|
const sep = () => Object.assign(document.createElement("span"), { className: "sep" });
|
|
238
|
-
const voice = use("voice");
|
|
239
|
-
const clips = [];
|
|
240
|
-
let take;
|
|
241
346
|
const wave = Object.assign(document.createElement("canvas"), {
|
|
242
347
|
className: "wave",
|
|
243
348
|
hidden: true
|
|
@@ -287,44 +392,54 @@ var client_default = defineClientPlugin({
|
|
|
287
392
|
mic.setAttribute("aria-pressed", String(on));
|
|
288
393
|
mic.title = on ? "Turn the mic off" : "Turn the mic on";
|
|
289
394
|
mic.setAttribute("aria-label", mic.title);
|
|
395
|
+
save();
|
|
290
396
|
});
|
|
291
397
|
};
|
|
292
398
|
mic?.classList.add("mic");
|
|
293
399
|
mic?.setAttribute("aria-pressed", "false");
|
|
294
|
-
|
|
400
|
+
if (from?.mic === true) toggle();
|
|
401
|
+
const leave = () => {
|
|
402
|
+
const spoken = take?.soFar();
|
|
403
|
+
if (take !== void 0 && spoken !== void 0) clips.push({
|
|
404
|
+
id: spoken.id,
|
|
405
|
+
at: take.started - startedAt,
|
|
406
|
+
duration: spoken.duration
|
|
407
|
+
});
|
|
408
|
+
const part = unsent;
|
|
409
|
+
unsent = [];
|
|
410
|
+
const at = seq++;
|
|
411
|
+
save();
|
|
412
|
+
if (part.length > 0) post(`part/${id}?seq=${at}`, part, true).catch(() => {});
|
|
413
|
+
};
|
|
414
|
+
addEventListener("pagehide", leave);
|
|
415
|
+
const end = async (kept) => {
|
|
295
416
|
rrweb.record.addCustomEvent(END, {});
|
|
296
417
|
stopRecording?.();
|
|
297
418
|
for (const stop of unsubscribe) stop?.();
|
|
298
419
|
tools?.close();
|
|
420
|
+
clearInterval(flushing);
|
|
299
421
|
clearInterval(ticking);
|
|
300
422
|
removeEventListener("resize", replace);
|
|
423
|
+
removeEventListener("pagehide", leave);
|
|
301
424
|
bar.remove();
|
|
425
|
+
over = true;
|
|
426
|
+
carry(void 0);
|
|
302
427
|
await busy;
|
|
303
|
-
if (!
|
|
428
|
+
if (!kept) {
|
|
304
429
|
unwave();
|
|
305
430
|
take?.cancel();
|
|
431
|
+
post(`discard/${id}`, {}).catch(() => {});
|
|
306
432
|
return done(void 0);
|
|
307
433
|
}
|
|
308
434
|
await micOff();
|
|
309
435
|
const duration = Date.now() - startedAt;
|
|
310
436
|
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
437
|
try {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
438
|
+
await flush();
|
|
439
|
+
const { url } = await post(`end/${id}`, {
|
|
440
|
+
duration,
|
|
441
|
+
...voiced
|
|
325
442
|
});
|
|
326
|
-
const { id, url, problem } = await res.json();
|
|
327
|
-
if (id === void 0) throw new Error(`recordings: ${problem ?? res.statusText}`);
|
|
328
443
|
done({
|
|
329
444
|
id,
|
|
330
445
|
url: url ?? `${base}__deictic/plugins/recordings/replay/${id}`,
|
|
@@ -341,7 +456,10 @@ var client_default = defineClientPlugin({
|
|
|
341
456
|
const style = Object.assign(document.createElement("style"), { textContent: STYLE });
|
|
342
457
|
bar.prepend(style);
|
|
343
458
|
root.append(bar);
|
|
344
|
-
const tick = () =>
|
|
459
|
+
const tick = () => {
|
|
460
|
+
moved();
|
|
461
|
+
time.textContent = clock(Date.now() - startedAt);
|
|
462
|
+
};
|
|
345
463
|
tick();
|
|
346
464
|
const ticking = setInterval(tick, 250);
|
|
347
465
|
let dock = storedDock();
|
|
@@ -357,16 +475,27 @@ var client_default = defineClientPlugin({
|
|
|
357
475
|
});
|
|
358
476
|
});
|
|
359
477
|
};
|
|
478
|
+
const run = (from) => {
|
|
479
|
+
const mine = record(from).finally(() => {
|
|
480
|
+
if (going === mine) going = void 0;
|
|
481
|
+
});
|
|
482
|
+
going = mine;
|
|
483
|
+
return mine;
|
|
484
|
+
};
|
|
485
|
+
const left = carried();
|
|
486
|
+
if (left !== void 0) run(left).catch((e) => {
|
|
487
|
+
carry(void 0);
|
|
488
|
+
console.warn("deictic: the recording did not carry on, or was not kept", e);
|
|
489
|
+
});
|
|
490
|
+
window.addEventListener("pageshow", (e) => {
|
|
491
|
+
if (e.persisted && (going !== void 0 || carried() !== void 0)) location.reload();
|
|
492
|
+
});
|
|
360
493
|
return {
|
|
361
|
-
recording: () => going,
|
|
494
|
+
recording: () => going !== void 0,
|
|
495
|
+
going: () => going,
|
|
362
496
|
record: async () => {
|
|
363
|
-
if (going) throw new Error("recordings: one is going already: stop it first");
|
|
364
|
-
|
|
365
|
-
try {
|
|
366
|
-
return await record();
|
|
367
|
-
} finally {
|
|
368
|
-
going = false;
|
|
369
|
-
}
|
|
497
|
+
if (going !== void 0) throw new Error("recordings: one is going already: stop it first");
|
|
498
|
+
return run();
|
|
370
499
|
}
|
|
371
500
|
};
|
|
372
501
|
}
|
|
@@ -1 +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,IA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EA,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"}
|
|
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.\n *\n * The events go to the server as they happen (`begin`, a `part` each second, `end` on Stop), and what the next\n * page needs to carry on is kept in the tab's session storage: a reload, or a link to another page of the site,\n * leaves the recording going. The page that loads starts rrweb again under the same ID, which makes it a\n * recording of several pages as rrweb has them (a `Meta` and a snapshot for each), puts the toolbar back with\n * its time running, and turns the mic back on where it was.\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 { Shape } from '#src/plugins/annotations/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, Meta, Recorder, Recording, RecordPlugin, VoiceClip } from './index.ts';\nimport { END, MARKS, PAGE } 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';\n/** Where the recording going on is kept, for the tab's next page to carry on with. */\nconst GOING = 'deictic:recording';\n/** How often the events are sent, in milliseconds. */\nconst EVERY = 1000;\n\n/** A recording going on, as the next page needs it. */\ninterface Carried {\n id: string;\n startedAt: number;\n /** The next part's place among the parts. */\n seq: number;\n /** The mic's clips so far, and whether it was on. */\n clips: VoiceClip[];\n mic: boolean;\n /** What was drawn from the toolbar, and on which page: it's about that page, so only a reload of it shows it again. */\n path: string;\n marks: Shape[];\n}\n\nfunction carried(): Carried | undefined {\n try {\n return (JSON.parse(sessionStorage.getItem(GOING) ?? 'null') as Carried | null) ?? undefined;\n } catch {\n // Storage can be off: nothing carries over, then.\n return undefined;\n }\n}\n\nfunction carry(going: Carried | undefined): void {\n try {\n if (going === undefined) sessionStorage.removeItem(GOING);\n else sessionStorage.setItem(GOING, JSON.stringify(going));\n } catch {\n // Not kept, then: a page load ends the recording.\n }\n}\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, canvas } = options as { masking: ResolvedMasking; canvas?: false | { fps: number } };\n let going: Promise<Recording | undefined> | undefined;\n\n const post = async (route: string, body: unknown, keepalive = false) => {\n const res = await request(route, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n ...(keepalive ? { keepalive } : {}),\n });\n // `url`: where it replays, said by what keeps it with no server to serve it from (a `standalone` build).\n const answer = (await res.json()) as { id?: string; url?: string; problem?: string };\n if (answer.id === undefined) throw new Error(`recordings: ${answer.problem ?? res.statusText}`);\n return { id: answer.id, url: answer.url };\n };\n\n /** Records until Stop or Discard: a new recording, or `from`, one a page before this started. */\n const record = async (from?: Carried): Promise<Recording | undefined> => {\n const startedAt = from?.startedAt ?? Date.now();\n const begin = async (): Promise<string> => {\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n const colorScheme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n return (await post('begin', { page: location.href, viewport, colorScheme, startedAt } satisfies Meta)).id;\n };\n // What else goes in the recording, where its plugin is loaded: the console's lines and the page's requests, each\n // rrweb's own plugin, which listens from when rrweb starts until it stops. One that can't be had (its package\n // isn't installed) is said, and the recording goes on without.\n const extra = (name: 'logs' | 'network'): Promise<RecordPlugin | undefined> | undefined =>\n use(name)\n // A page that carries a recording on made requests before this: those of its load are the recording's too.\n ?.plugin({ sinceLoad: from !== undefined })\n .catch((e: unknown) => {\n console.warn(`deictic: this recording has no ${name}`, e);\n return undefined;\n });\n const [rrweb, id, ...extras] = await Promise.all([\n import('rrweb').catch((e: unknown) => {\n throw new Error('recordings need rrweb: add it to your devDependencies', { cause: e });\n }),\n from?.id ?? begin(),\n extra('logs'),\n extra('network'),\n ]);\n const clips: VoiceClip[] = from?.clips ?? [];\n // What the server doesn't have yet, and the place of the next part sent.\n let unsent: { type: number; data?: unknown }[] = [];\n let seq = from?.seq ?? 0;\n const host = root.host;\n const keep = dropOurs<(typeof unsent)[number]>(\n () => rrweb.record.mirror.getId(host),\n () => rrweb.record.mirror.getId(document.documentElement),\n );\n // The page's address changing with no load (a router's `pushState`, Back within the app, a hash), which rrweb\n // doesn't record: a custom event, so the recording says where each stretch happened. Nothing tells of\n // `pushState`, so it's read as each event comes, and as the clock ticks for a route that draws nothing.\n let href = location.href;\n const moved = () => {\n if (location.href === href) return;\n href = location.href;\n rrweb.record.addCustomEvent(PAGE, { href });\n };\n const stopRecording = rrweb.record({\n emit: (event) => {\n // Before what the new route drew, which is what comes next.\n moved();\n const kept = keep(event);\n if (kept !== undefined) unsent.push(kept);\n },\n plugins: extras.filter((plugin) => plugin !== undefined),\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 // A canvas as pictures of it, a few a second and only when it changed: rrweb's other way keeps every call\n // drawn on it, for which it wraps each drawing method of every canvas.\n ...(canvas === false || canvas === undefined\n ? {}\n : { recordCanvas: true, sampling: { canvas: canvas.fps }, dataURLOptions: { type: 'image/webp', quality: 0.6 } }),\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 if (from?.path === location.pathname) for (const shape of from.marks) tools?.marks.add(shape);\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\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 let take: Take | undefined;\n /** What the next page carries on from, kept as it changes: a page that's going has no time to say it then. */\n let over = false;\n const save = () =>\n // Not once it's ended, as its last events go: the next page would carry on with one that's over.\n over ||\n carry({\n id,\n startedAt,\n seq,\n clips,\n mic: take !== undefined,\n path: location.pathname,\n marks: tools?.marks.list().map((a) => a.shape) ?? [],\n });\n const unsubscribe = [\n marks?.subscribe(mark),\n tools?.marks.subscribe(() => {\n mark();\n save();\n }),\n ];\n\n // One part at a time, each with its place. A part that didn't arrive goes again with the next, before it.\n let sending: Promise<void> = Promise.resolve();\n const flush = () => {\n const next = sending\n .catch(() => {})\n .then(async () => {\n if (unsent.length === 0) return;\n const part = unsent;\n unsent = [];\n const at = seq++;\n save();\n try {\n await post(`part/${id}?seq=${at}`, part);\n } catch (e) {\n unsent = [...part, ...unsent];\n throw e;\n }\n });\n sending = next;\n return next;\n };\n // A problem is heard at Stop, where it matters: a part that fails meanwhile goes again a second on.\n const flushing = setInterval(() => void flush().catch(() => {}), EVERY);\n save();\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'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 save();\n });\n };\n mic?.classList.add('mic');\n mic?.setAttribute('aria-pressed', 'false');\n // On, as the page before left it: a browser that was let use the mic gives it again without asking.\n if (from?.mic === true) toggle();\n\n // The page is going, for another or for good, with no time to wait for anything: what's sent of the mic's\n // take is its clip, the next page is told where things stand, and the last events go as the page does.\n const leave = () => {\n const spoken = take?.soFar();\n if (take !== undefined && spoken !== undefined)\n clips.push({ id: spoken.id, at: take.started - startedAt, duration: spoken.duration });\n const part = unsent;\n unsent = [];\n const at = seq++;\n save();\n // Not behind `sending`, which a page that's going never gets to: the server orders the parts by their place.\n // A browser sends 64 KB at most for a page that's gone, so a last second busier than that is lost.\n if (part.length > 0) void post(`part/${id}?seq=${at}`, part, true).catch(() => {});\n };\n addEventListener('pagehide', leave);\n\n const end = async (kept: boolean) => {\n rrweb.record.addCustomEvent(END, {});\n stopRecording?.();\n for (const stop of unsubscribe) stop?.();\n tools?.close();\n clearInterval(flushing);\n clearInterval(ticking);\n removeEventListener('resize', replace);\n removeEventListener('pagehide', leave);\n bar.remove();\n over = true;\n carry(undefined);\n await busy;\n if (!kept) {\n unwave();\n take?.cancel();\n void post(`discard/${id}`, {}).catch(() => {});\n return done(undefined);\n }\n await micOff();\n const duration = Date.now() - startedAt;\n const voiced = clips.length > 0 ? { voice: clips } : {};\n try {\n await flush();\n const { url } = await post(`end/${id}`, { duration, ...voiced } satisfies Pick<Kept, 'duration' | 'voice'>);\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 = () => {\n moved();\n time.textContent = clock(Date.now() - startedAt);\n };\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 const run = (from?: Carried) => {\n const mine = record(from).finally(() => {\n if (going === mine) going = undefined;\n });\n going = mine;\n return mine;\n };\n // One the page before this left going: carried on at once, whoever asks for it later (`going`), or no one.\n const left = carried();\n if (left !== undefined) {\n run(left).catch((e: unknown) => {\n // Not for the page after this to try again.\n carry(undefined);\n console.warn('deictic: the recording did not carry on, or was not kept', e);\n });\n }\n // A page shown again as it was left (Back, out of the browser's cache) knows nothing of what happened since:\n // loaded afresh, it carries on like any other.\n window.addEventListener('pageshow', (e) => {\n if (e.persisted && (going !== undefined || carried() !== undefined)) location.reload();\n });\n\n return {\n recording: () => going !== undefined,\n going: () => going,\n record: async () => {\n if (going !== undefined) throw new Error('recordings: one is going already: stop it first');\n return run();\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,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC;GACxD;GAEA,OADa,KAAK,KAAK,SAAS,KAAK,QAAQ,SAAS,KAAK,MAAM,SAAS,KAAK,WAAW,WAC1E,IAAI,KAAA,IAAY;I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C;EAIH,OAAO,iBAAiB,aAAa,MAAM;GACzC,IAAI,EAAE,cAAc,UAAU,KAAA,KAAa,QAAQ,MAAM,KAAA,IAAY,SAAS,OAAO;EACvF,CAAC;EAED,OAAO;GACL,iBAAiB,UAAU,KAAA;GAC3B,aAAa;GACb,QAAQ,YAAY;IAClB,IAAI,UAAU,KAAA,GAAW,MAAM,IAAI,MAAM,iDAAiD;IAC1F,OAAO,IAAI;GACb;EACF;CACF;AACF,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { Kept, MARKS, Recorder, Recording, Recordings, RecordingsOptions, type ReplaySources, VoiceClip, recordings as default, recordings, replayPage };
|
|
1
|
+
import { a as Recorder, c as RecordingsOptions, d as ReplaySources, f as replayPage, i as Recorded, l as VoiceClip, n as Meta, o as Recording, p as MARKS, r as RecordPlugin, s as Recordings, t as Kept, u as recordings } from "../shared/index3.js";
|
|
2
|
+
export { Kept, MARKS, Meta, RecordPlugin, Recorded, Recorder, Recording, Recordings, RecordingsOptions, type ReplaySources, VoiceClip, recordings as default, recordings, replayPage };
|
|
@@ -19,5 +19,11 @@ export type PageCapture = (element: Element, options: {
|
|
|
19
19
|
export declare const notOurs: (node: Node) => boolean;
|
|
20
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
21
|
export declare function boxOf(element: Element, area: NonNullable<CaptureOptions['area']>): Box;
|
|
22
|
+
/**
|
|
23
|
+
* Hides in a copy of the page's what rrweb would: blocked elements become a blank box their size (the copy keeps each
|
|
24
|
+
* element's size as its styles), masked text keeps its spaces but shows `*`, and so do passwords' values,
|
|
25
|
+
* or every field's.
|
|
26
|
+
*/
|
|
27
|
+
export declare function mask(copy: Node, m: ResolvedMasking): void;
|
|
22
28
|
export declare function screenshotsClient(capture: PageCapture): import("deictic").ClientPlugin<never, never, Capture>;
|
|
23
29
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +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;
|
|
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;;;;;;wBAcpE,KAAK,MAAM,MAAM,GAAG;wBAqBpB,kBAAkB,SAAS,gCAAW,2BAAA"}
|
|
@@ -22,6 +22,33 @@ function boxOf(element, area) {
|
|
|
22
22
|
height
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
+
const BLANK = "#d4d4d8";
|
|
26
|
+
const selector = (className, extra) => [`.${CSS.escape(className)}`, ...extra ? [extra] : []].join(", ");
|
|
27
|
+
/**
|
|
28
|
+
* Hides in a copy of the page's what rrweb would: blocked elements become a blank box their size (the copy keeps each
|
|
29
|
+
* element's size as its styles), masked text keeps its spaces but shows `*`, and so do passwords' values,
|
|
30
|
+
* or every field's.
|
|
31
|
+
*/
|
|
32
|
+
function mask(copy, m) {
|
|
33
|
+
if (!(copy instanceof Element)) return;
|
|
34
|
+
const all = (sel) => [...copy.matches(sel) ? [copy] : [], ...copy.querySelectorAll(sel)];
|
|
35
|
+
const stars = (text) => text.replace(/\S/g, "*");
|
|
36
|
+
for (const el of all(selector(m.blockClass, m.blockSelector))) {
|
|
37
|
+
el.replaceChildren();
|
|
38
|
+
if (el instanceof HTMLElement || el instanceof SVGElement) el.style.background = BLANK;
|
|
39
|
+
}
|
|
40
|
+
for (const el of all(selector(m.maskTextClass, m.maskTextSelector))) {
|
|
41
|
+
const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
|
|
42
|
+
for (let text = walker.nextNode(); text !== null; text = walker.nextNode()) text.textContent = stars(text.textContent ?? "");
|
|
43
|
+
}
|
|
44
|
+
for (const field of all("input, textarea")) {
|
|
45
|
+
if (!(field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement)) continue;
|
|
46
|
+
if (!m.maskAllInputs && !(field instanceof HTMLInputElement && field.type === "password")) continue;
|
|
47
|
+
field.value = stars(field.value);
|
|
48
|
+
field.setAttribute("value", field.value);
|
|
49
|
+
if (field instanceof HTMLTextAreaElement) field.textContent = field.value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
25
52
|
function screenshotsClient(capture) {
|
|
26
53
|
return defineClientPlugin({
|
|
27
54
|
name: "screenshots",
|
|
@@ -66,11 +93,16 @@ function screenshotsClient(capture) {
|
|
|
66
93
|
size
|
|
67
94
|
});
|
|
68
95
|
},
|
|
69
|
-
upload: (png, of) => add(png, "image/png", of)
|
|
96
|
+
upload: (png, of) => add(png, "image/png", of),
|
|
97
|
+
masked: (element) => {
|
|
98
|
+
const copy = element.cloneNode(true);
|
|
99
|
+
mask(copy, masking);
|
|
100
|
+
return copy;
|
|
101
|
+
}
|
|
70
102
|
};
|
|
71
103
|
}
|
|
72
104
|
});
|
|
73
105
|
}
|
|
74
|
-
export { boxOf, notOurs, screenshotsClient };
|
|
106
|
+
export { boxOf, mask, notOurs, screenshotsClient };
|
|
75
107
|
|
|
76
108
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +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;
|
|
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\nconst BLANK = '#d4d4d8';\n\nconst selector = (className: string, extra: string | undefined) => [`.${CSS.escape(className)}`, ...(extra ? [extra] : [])].join(', ');\n\n/**\n * Hides in a copy of the page's what rrweb would: blocked elements become a blank box their size (the copy keeps each\n * element's size as its styles), masked text keeps its spaces but shows `*`, and so do passwords' values,\n * or every field's.\n */\nexport function mask(copy: Node, m: ResolvedMasking): void {\n if (!(copy instanceof Element)) return;\n const all = (sel: string) => [...(copy.matches(sel) ? [copy] : []), ...copy.querySelectorAll(sel)];\n const stars = (text: string) => text.replace(/\\S/g, '*');\n for (const el of all(selector(m.blockClass, m.blockSelector))) {\n el.replaceChildren();\n if (el instanceof HTMLElement || el instanceof SVGElement) el.style.background = BLANK;\n }\n for (const el of all(selector(m.maskTextClass, m.maskTextSelector))) {\n const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);\n for (let text = walker.nextNode(); text !== null; text = walker.nextNode()) text.textContent = stars(text.textContent ?? '');\n }\n for (const field of all('input, textarea')) {\n if (!(field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement)) continue;\n if (!m.maskAllInputs && !(field instanceof HTMLInputElement && field.type === 'password')) continue;\n field.value = stars(field.value);\n field.setAttribute('value', field.value);\n if (field instanceof HTMLTextAreaElement) field.textContent = field.value;\n }\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 masked: (element) => {\n const copy = element.cloneNode(true) as Element;\n mask(copy, masking);\n return copy;\n },\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,MAAM,QAAQ;AAEd,MAAM,YAAY,WAAmB,UAA8B,CAAC,IAAI,IAAI,OAAO,SAAS,KAAK,GAAI,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAE,CAAC,CAAC,KAAK,IAAI;;;;;;AAOrI,SAAgB,KAAK,MAAY,GAA0B;CACzD,IAAI,EAAE,gBAAgB,UAAU;CAChC,MAAM,OAAO,QAAgB,CAAC,GAAI,KAAK,QAAQ,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,GAAI,GAAG,KAAK,iBAAiB,GAAG,CAAC;CACjG,MAAM,SAAS,SAAiB,KAAK,QAAQ,OAAO,GAAG;CACvD,KAAK,MAAM,MAAM,IAAI,SAAS,EAAE,YAAY,EAAE,aAAa,CAAC,GAAG;EAC7D,GAAG,gBAAgB;EACnB,IAAI,cAAc,eAAe,cAAc,YAAY,GAAG,MAAM,aAAa;CACnF;CACA,KAAK,MAAM,MAAM,IAAI,SAAS,EAAE,eAAe,EAAE,gBAAgB,CAAC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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;IAC7C,SAAS,YAAY;KACnB,MAAM,OAAO,QAAQ,UAAU,IAAI;KACnC,KAAK,MAAM,OAAO;KAClB,OAAO;IACT;GACF;EACF;CACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.d.ts","names":["_$__index_ts0.Capture"],"sources":["../../src/plugins/screenshots/dom.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"dom.d.ts","names":["_$__index_ts0.Capture"],"sources":["../../src/plugins/screenshots/dom.ts"],"mappings":";cAiBA,4B,2BAAAA"}
|
package/dist/screenshots/dom.js
CHANGED
|
@@ -1,37 +1,10 @@
|
|
|
1
|
-
import { boxOf, notOurs, screenshotsClient } from "./client.js";
|
|
1
|
+
import { boxOf, mask, notOurs, screenshotsClient } from "./client.js";
|
|
2
2
|
// src/plugins/screenshots/dom.ts
|
|
3
3
|
/**
|
|
4
4
|
* The `dom()` renderer's page half: draws the page in the page from its DOM with `modern-screenshot`
|
|
5
5
|
* (imported on the first shot), so it needs no server, but text may lay out a little differently than
|
|
6
6
|
* the page's. Masking changes only the copy that's drawn, never the page.
|
|
7
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
8
|
/** Draws an SVG over the whole canvas, which is the area it was made for at the canvas's scale. */
|
|
36
9
|
async function drawOver(canvas, svg) {
|
|
37
10
|
if (svg === void 0) return canvas;
|