deictic 0.8.0 → 0.9.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 +73 -18
- package/README.md +1 -1
- package/dist/annotations/client.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/client/index.d.ts +13 -13
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +11 -7
- package/dist/client/index.js.map +1 -1
- package/dist/react/client.d.ts +19 -0
- package/dist/react/client.d.ts.map +1 -0
- package/dist/react/client.js +504 -0
- package/dist/react/client.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +1 -0
- package/dist/recommended/index.d.ts +15 -7
- package/dist/recommended/index.d.ts.map +1 -1
- package/dist/recommended/index.js +1 -1
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +48 -5
- package/dist/recordings/client.js.map +1 -1
- package/dist/screenshots/client.d.ts +9 -1
- package/dist/screenshots/client.d.ts.map +1 -1
- package/dist/screenshots/rrweb.d.ts +0 -6
- package/dist/screenshots/rrweb.d.ts.map +1 -1
- package/dist/screenshots/rrweb.js +53 -10
- package/dist/screenshots/rrweb.js.map +1 -1
- package/dist/shared/board.js +1 -1
- package/dist/shared/canvas.js +30 -0
- package/dist/shared/canvas.js.map +1 -0
- package/dist/shared/client.js +44 -2
- package/dist/shared/client.js.map +1 -1
- package/dist/shared/dom.js +7 -1
- package/dist/shared/dom.js.map +1 -1
- package/dist/shared/drawer.js +1 -1
- package/dist/shared/endpoints.js +1 -1
- package/dist/shared/find.js +6 -1
- package/dist/shared/find.js.map +1 -1
- package/dist/shared/frame.js +5 -2
- package/dist/shared/frame.js.map +1 -1
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index10.d.ts +70 -0
- package/dist/shared/index10.d.ts.map +1 -0
- package/dist/shared/index3.d.ts +11 -0
- package/dist/shared/index3.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +92 -312
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/index8.d.ts +324 -47
- package/dist/shared/index8.d.ts.map +1 -1
- package/dist/shared/index9.d.ts +45 -63
- package/dist/shared/index9.d.ts.map +1 -1
- package/dist/shared/init.js +15 -11
- package/dist/shared/init.js.map +1 -1
- package/dist/shared/marks.js +7 -1
- package/dist/shared/marks.js.map +1 -1
- package/dist/shared/package.js +3 -1
- package/dist/shared/packages.js +1 -1
- package/dist/shared/playwright.js +59 -3
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/react.js +25 -0
- package/dist/shared/react.js.map +1 -0
- package/dist/shared/recommended.js +6 -3
- package/dist/shared/recommended.js.map +1 -1
- package/dist/shared/recording.js +80 -3
- package/dist/shared/recording.js.map +1 -1
- package/dist/shared/recordings.js +30 -2
- package/dist/shared/recordings.js.map +1 -1
- package/dist/shared/screenshots.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +1 -0
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +11 -0
- 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.js +45 -19
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/voice/client.d.ts +1 -1
- package/dist/voice/client.js +1 -1
- package/dist/voice/index.d.ts +1 -1
- package/package.json +25 -1
- package/src/cli/bun.ts +2 -2
- package/src/cli/find.ts +5 -1
- package/src/cli/frame.ts +6 -3
- package/src/cli/init.ts +14 -9
- package/src/cli/recording.ts +90 -4
- package/src/cli/task.ts +4 -0
- package/src/cli.ts +13 -6
- package/src/client/dom.ts +14 -0
- package/src/client/index.ts +21 -14
- package/src/index.ts +6 -0
- package/src/plugins/react/client.ts +162 -0
- package/src/plugins/react/index.ts +130 -0
- package/src/plugins/react/renders.ts +219 -0
- package/src/plugins/react/serialize.ts +139 -0
- package/src/plugins/react/timeline.ts +143 -0
- package/src/plugins/recommended/index.ts +17 -5
- package/src/plugins/recordings/client.ts +64 -4
- package/src/plugins/recordings/marks.ts +7 -0
- package/src/plugins/recordings/replay.ts +30 -2
- package/src/plugins/screenshots/canvas.ts +27 -0
- package/src/plugins/screenshots/client.ts +42 -2
- package/src/plugins/screenshots/index.ts +11 -0
- package/src/plugins/screenshots/playwright.ts +90 -4
- package/src/plugins/screenshots/rrweb.ts +57 -9
- package/src/plugins/screenshots/states.ts +26 -0
- package/src/plugins/tasks/client.ts +41 -6
- package/src/plugins/tasks/composer.ts +24 -7
- package/src/plugins/tasks/index.ts +16 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React's commits as a timeline, for a recording: what DevTools' profiler shows of each commit, cut to what reads in
|
|
3
|
+
* a list. Commits a frame apart are one entry (an animation commits each frame), each names the components that
|
|
4
|
+
* rendered in it, the slowest first. Past `RATE` entries in a second, the rest of that second's commits are one entry
|
|
5
|
+
* at its end, which says how long it spans and its slowest commit: a recording is kept as it goes, and a page that
|
|
6
|
+
* renders without stop would fill it. So it's `RATE + 1` entries a second at most, whatever the page does.
|
|
7
|
+
*/
|
|
8
|
+
import { componentOf } from '#src/client/component.ts';
|
|
9
|
+
|
|
10
|
+
import type { Commit, Rendered } from './index.ts';
|
|
11
|
+
import type { Fiber, Rendering } from './renders.ts';
|
|
12
|
+
|
|
13
|
+
/** Commits closer than this are one entry, in milliseconds: a frame. */
|
|
14
|
+
export const FRAME = 16;
|
|
15
|
+
/** How many components an entry names, the slowest first. */
|
|
16
|
+
const NAMED = 20;
|
|
17
|
+
/** How many entries a second go in as they come; past that, the rest of the second is one. */
|
|
18
|
+
export const RATE = 10;
|
|
19
|
+
/** The span entries are counted in, in milliseconds. */
|
|
20
|
+
const SECOND = 1000;
|
|
21
|
+
/** How far down a component a host element it wrote is looked for, in fibers. */
|
|
22
|
+
const LOOKED = 200;
|
|
23
|
+
|
|
24
|
+
/** React's scheduler priorities, as `onCommitFiberRoot` is given them. */
|
|
25
|
+
const PRIORITIES: Record<number, string> = { 1: 'immediate', 2: 'user-blocking', 3: 'normal', 4: 'low', 5: 'idle' };
|
|
26
|
+
|
|
27
|
+
/** `src/Plan.tsx:12`: the first host element under `fiber` that it wrote, where the page marks it. */
|
|
28
|
+
function placeOf(fiber: Fiber): string | undefined {
|
|
29
|
+
const its = (by: Fiber | null | undefined) => by != null && (by === fiber || by === fiber.alternate);
|
|
30
|
+
const stack: Fiber[] = fiber.child === null ? [] : [fiber.child];
|
|
31
|
+
for (let looked = 0; stack.length > 0 && looked < LOOKED; looked++) {
|
|
32
|
+
const at = stack.pop()!;
|
|
33
|
+
if (at.sibling !== null) stack.push(at.sibling);
|
|
34
|
+
if (typeof at.type === 'string' && its(at._debugOwner)) {
|
|
35
|
+
const mark = (at.stateNode as Element | null)?.getAttribute?.('data-deictic');
|
|
36
|
+
if (typeof mark === 'string') return mark.replace(/:\d+$/, '');
|
|
37
|
+
}
|
|
38
|
+
if (at.child !== null) stack.push(at.child);
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const round = (ms: number) => Math.round(ms * 100) / 100;
|
|
44
|
+
|
|
45
|
+
/** One entry of commits: the components that rendered, each once with how often, the slowest first. */
|
|
46
|
+
export function summarize(commits: Rendering[]): Commit {
|
|
47
|
+
const by = new Map<string, Rendered & { order: number }>();
|
|
48
|
+
for (const { rendered } of commits) {
|
|
49
|
+
for (const { fiber, why, ms, selfMs } of rendered) {
|
|
50
|
+
const name = componentOf(fiber) ?? 'Anonymous';
|
|
51
|
+
const at = placeOf(fiber);
|
|
52
|
+
const key = `${name} ${at ?? ''}`;
|
|
53
|
+
const seen = by.get(key);
|
|
54
|
+
const entry = seen ?? { name, ...(at === undefined ? {} : { at }), count: 0, why, order: by.size };
|
|
55
|
+
entry.count = (entry.count ?? 0) + 1;
|
|
56
|
+
entry.why = why;
|
|
57
|
+
if (ms !== undefined) entry.ms = round((entry.ms ?? 0) + ms);
|
|
58
|
+
if (selfMs !== undefined) entry.selfMs = round((entry.selfMs ?? 0) + selfMs);
|
|
59
|
+
by.set(key, entry);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// The slowest first, and those alike in the order they rendered.
|
|
63
|
+
const all = [...by.values()].sort((a, b) =>
|
|
64
|
+
(b.selfMs ?? 0) - (a.selfMs ?? 0) !== 0 ? (b.selfMs ?? 0) - (a.selfMs ?? 0) : a.order - b.order,
|
|
65
|
+
);
|
|
66
|
+
const kept = all.slice(0, NAMED);
|
|
67
|
+
const timed = commits.flatMap((c) => (c.ms === undefined ? [] : [c.ms]));
|
|
68
|
+
const ms = timed.length === 0 ? undefined : timed.reduce((sum, n) => sum + n, 0);
|
|
69
|
+
const priority = commits.at(-1)?.priority;
|
|
70
|
+
return {
|
|
71
|
+
commits: commits.length,
|
|
72
|
+
...(ms === undefined ? {} : { ms: round(ms) }),
|
|
73
|
+
// Of several: what makes a page stutter is one slow commit, not many quick ones.
|
|
74
|
+
...(commits.length > 1 && timed.length > 0 ? { slowest: round(Math.max(...timed)) } : {}),
|
|
75
|
+
...(priority === undefined || PRIORITIES[priority] === undefined ? {} : { priority: PRIORITIES[priority] }),
|
|
76
|
+
components: kept.map(({ order: _, count, ...rest }) => ({ ...rest, ...(count !== undefined && count > 1 ? { count } : {}) })),
|
|
77
|
+
...(all.length > kept.length ? { more: all.length - kept.length } : {}),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Listens to the commits `subscribe` gives, and answers each frame's as one entry, `RATE` a second, then the rest of
|
|
83
|
+
* that second as one: `emit` hears them, until what's answered stops it (what's waiting goes first).
|
|
84
|
+
*/
|
|
85
|
+
export function timeline(
|
|
86
|
+
subscribe: (listen: (commit: Rendering) => void) => () => void,
|
|
87
|
+
emit: (commit: Commit) => void,
|
|
88
|
+
clock: { now: () => number; later: (run: () => void, ms: number) => unknown } = {
|
|
89
|
+
now: () => performance.now(),
|
|
90
|
+
later: (run, ms) => setTimeout(run, ms),
|
|
91
|
+
},
|
|
92
|
+
): () => void {
|
|
93
|
+
let waiting: Rendering[] = [];
|
|
94
|
+
// The second being counted: when it started, and its entries so far.
|
|
95
|
+
let second = Number.NEGATIVE_INFINITY;
|
|
96
|
+
let inSecond = 0;
|
|
97
|
+
// Its commits past `RATE` entries, and since when.
|
|
98
|
+
let over: Rendering[] = [];
|
|
99
|
+
let overFrom = 0;
|
|
100
|
+
const flushOver = () => {
|
|
101
|
+
if (over.length === 0) return;
|
|
102
|
+
const commits = over;
|
|
103
|
+
over = [];
|
|
104
|
+
emit({ ...summarize(commits), over: Math.round(clock.now() - overFrom) });
|
|
105
|
+
};
|
|
106
|
+
const flush = () => {
|
|
107
|
+
const commits = waiting;
|
|
108
|
+
waiting = [];
|
|
109
|
+
if (commits.length === 0) return;
|
|
110
|
+
const now = clock.now();
|
|
111
|
+
if (now - second >= SECOND) {
|
|
112
|
+
flushOver();
|
|
113
|
+
second = now;
|
|
114
|
+
inSecond = 0;
|
|
115
|
+
}
|
|
116
|
+
if (inSecond < RATE) {
|
|
117
|
+
inSecond++;
|
|
118
|
+
emit(summarize(commits));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (over.length === 0) {
|
|
122
|
+
overFrom = now;
|
|
123
|
+
// At the second's end, unless the next second's first entry has said it by then.
|
|
124
|
+
const counting = second;
|
|
125
|
+
clock.later(
|
|
126
|
+
() => {
|
|
127
|
+
if (second === counting) flushOver();
|
|
128
|
+
},
|
|
129
|
+
second + SECOND - now,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
over.push(...commits);
|
|
133
|
+
};
|
|
134
|
+
const unsubscribe = subscribe((commit) => {
|
|
135
|
+
if (waiting.length === 0) clock.later(flush, FRAME);
|
|
136
|
+
waiting.push(commit);
|
|
137
|
+
});
|
|
138
|
+
return () => {
|
|
139
|
+
unsubscribe();
|
|
140
|
+
flush();
|
|
141
|
+
flushOver();
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `deictic/recommended`: the plugins for describing a change rather than making it. Alt-click an element, say what
|
|
3
3
|
* should change, attach a screenshot to draw on, a screen recording or your voice, and it goes to a Vercel Board.
|
|
4
|
-
* A recording has the page's console and its requests in it too
|
|
4
|
+
* A recording has the page's console and its requests in it too, and in a React project a task has the props and
|
|
5
|
+
* state of the components that wrote its element.
|
|
5
6
|
*
|
|
6
7
|
* Only the server halves, as every factory is: each names its page half, which the integration imports. A plugin
|
|
7
|
-
* outside the preset (Tailwind, your own) goes beside it: `plugins: [...
|
|
8
|
+
* outside the preset (Tailwind, your own) goes beside it: `plugins: [...deicticRecommended(), tailwind()]`. Named for
|
|
9
|
+
* deictic, as a config imports other presets called `recommended`.
|
|
8
10
|
*/
|
|
9
11
|
import type { ServerPlugin } from '#src/index.ts';
|
|
10
12
|
import { annotations, type AnnotationsOptions } from '#src/plugins/annotations/index.ts';
|
|
11
13
|
import { logs, type LogsOptions } from '#src/plugins/logs/index.ts';
|
|
12
14
|
import { network, type NetworkOptions } from '#src/plugins/network/index.ts';
|
|
15
|
+
import { type ReactOptions, reactState } from '#src/plugins/react/index.ts';
|
|
13
16
|
import { recordings, type RecordingsOptions } from '#src/plugins/recordings/index.ts';
|
|
14
17
|
import { screenshots, type ScreenshotsOptions } from '#src/plugins/screenshots/index.ts';
|
|
15
18
|
import { tasks, type TasksOptions } from '#src/plugins/tasks/index.ts';
|
|
16
19
|
import { voice, type VoiceOptions } from '#src/plugins/voice/index.ts';
|
|
20
|
+
import { installed } from '#src/tools/packages.ts';
|
|
17
21
|
|
|
18
22
|
/** Each plugin's options, by its name, or `false` to leave it out. */
|
|
19
23
|
export interface RecommendedOptions {
|
|
@@ -26,13 +30,18 @@ export interface RecommendedOptions {
|
|
|
26
30
|
logs?: LogsOptions | false;
|
|
27
31
|
/** The page's requests in a recording, masked. */
|
|
28
32
|
network?: NetworkOptions | false;
|
|
33
|
+
/**
|
|
34
|
+
* The props, state and hooks of the components that wrote a task's element: where the project has React (found from
|
|
35
|
+
* the working directory, where the dev server starts), unless it's `false`.
|
|
36
|
+
*/
|
|
37
|
+
react?: ReactOptions | false;
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
/**
|
|
32
41
|
* Tasks, screenshots, annotations, recordings and voice, in that order, the order of their tabs, then what a
|
|
33
|
-
* recording has besides the page: logs and network.
|
|
42
|
+
* recording has besides the page: logs and network, and React's state where the project has React.
|
|
34
43
|
*/
|
|
35
|
-
export function
|
|
44
|
+
export function deicticRecommended(options: RecommendedOptions = {}): ServerPlugin[] {
|
|
36
45
|
const plugins: ServerPlugin[] = [];
|
|
37
46
|
if (options.tasks !== false) plugins.push(tasks(options.tasks));
|
|
38
47
|
if (options.screenshots !== false) plugins.push(screenshots(options.screenshots));
|
|
@@ -42,7 +51,10 @@ export function recommended(options: RecommendedOptions = {}): ServerPlugin[] {
|
|
|
42
51
|
// Nothing without recordings to be in.
|
|
43
52
|
if (options.recordings !== false && options.logs !== false) plugins.push(logs(options.logs));
|
|
44
53
|
if (options.recordings !== false && options.network !== false) plugins.push(network(options.network));
|
|
54
|
+
// Its page half reads React's fibers: nothing to read without React, and bippy to install for nothing.
|
|
55
|
+
if (options.react !== false && (options.react !== undefined || installed(process.cwd(), 'react')))
|
|
56
|
+
plugins.push(reactState(options.react));
|
|
45
57
|
return plugins;
|
|
46
58
|
}
|
|
47
59
|
|
|
48
|
-
export default
|
|
60
|
+
export default deicticRecommended;
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* the time running, and turns the mic back on where it was.
|
|
11
11
|
*
|
|
12
12
|
* Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom
|
|
13
|
-
* events: the page's annotations, as SVGs in page coordinates, at the start and at each change.
|
|
13
|
+
* events: the page's annotations, as SVGs in page coordinates, at the start and at each change. So are React's
|
|
14
|
+
* commits, where the react plugin is loaded, while its button is on (P): off by default, and as it was last left.
|
|
14
15
|
*/
|
|
15
16
|
import { toolButton } from '#src/client/dom.ts';
|
|
16
17
|
import { playMark, trayed } from '#src/client/drawer.ts';
|
|
@@ -21,7 +22,7 @@ import type { ResolvedMasking } from '#src/plugins/screenshots/index.ts';
|
|
|
21
22
|
import type { Take } from '#src/plugins/voice/index.ts';
|
|
22
23
|
|
|
23
24
|
import type { Kept, Meta, Recorder, Recording, RecordPlugin, VoiceClip } from './index.ts';
|
|
24
|
-
import { END, MARKS, PAGE } from './marks.ts';
|
|
25
|
+
import { END, MARKS, PAGE, REACT } from './marks.ts';
|
|
25
26
|
import { dropOurs } from './ours.ts';
|
|
26
27
|
|
|
27
28
|
/** Where the recording going on is kept, for the tab's next page to carry on with. */
|
|
@@ -38,8 +39,29 @@ interface Carried {
|
|
|
38
39
|
/** The mic's clips so far, and whether it was on. */
|
|
39
40
|
clips: VoiceClip[];
|
|
40
41
|
mic: boolean;
|
|
42
|
+
/** Whether React's commits were going in. */
|
|
43
|
+
react?: boolean;
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
/** Whether the last recording had React's commits going in when it ended, for the next to start as it was left. */
|
|
47
|
+
const REACT_ON = 'deictic:recording:react';
|
|
48
|
+
|
|
49
|
+
const reactWanted = () => {
|
|
50
|
+
try {
|
|
51
|
+
return localStorage.getItem(REACT_ON) === 'true';
|
|
52
|
+
} catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const wantReact = (on: boolean) => {
|
|
58
|
+
try {
|
|
59
|
+
localStorage.setItem(REACT_ON, String(on));
|
|
60
|
+
} catch {
|
|
61
|
+
// Not remembered, then: the next recording starts without.
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
43
65
|
function carried(): Carried | undefined {
|
|
44
66
|
try {
|
|
45
67
|
return (JSON.parse(sessionStorage.getItem(GOING) ?? 'null') as Carried | null) ?? undefined;
|
|
@@ -69,6 +91,7 @@ const STYLE = `
|
|
|
69
91
|
.tool-panel.vertical .recorder .live { flex-direction: column; gap: 2px; padding: 4px 0; }
|
|
70
92
|
.recorder .dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: deictic-blink 1.2s infinite; }
|
|
71
93
|
.recorder .mic[aria-pressed='true'], .recorder .mic[aria-pressed='true']:hover { background: #ef4444; color: #fff; }
|
|
94
|
+
.recorder .react[aria-pressed='true'], .recorder .react[aria-pressed='true']:hover { background: #087ea4; color: #fff; }
|
|
72
95
|
.recorder .wave { width: 44px; height: 18px; }
|
|
73
96
|
.tool-panel.vertical .recorder .wave { width: 28px; }
|
|
74
97
|
@keyframes deictic-blink { 50% { opacity: 0.3; } }
|
|
@@ -79,6 +102,9 @@ const RECORD = '<circle cx="12" cy="12" r="8"/><circle cx="12" cy="12" r="3" fil
|
|
|
79
102
|
const STOP = '<rect x="6" y="6" width="12" height="12" rx="1" fill="currentColor"/>';
|
|
80
103
|
const DISCARD = '<path d="M6 6l12 12M18 6 6 18"/>';
|
|
81
104
|
const MIC = '<rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5 11a7 7 0 0 0 14 0M12 18v3"/>';
|
|
105
|
+
/** An atom, as React's own mark is drawn. */
|
|
106
|
+
const ATOM =
|
|
107
|
+
'<circle cx="12" cy="12" r="1.6" fill="currentColor"/><ellipse cx="12" cy="12" rx="10" ry="4"/><ellipse cx="12" cy="12" rx="10" ry="4" transform="rotate(60 12 12)"/><ellipse cx="12" cy="12" rx="10" ry="4" transform="rotate(120 12 12)"/>';
|
|
82
108
|
|
|
83
109
|
const clock = (ms: number) => {
|
|
84
110
|
const s = Math.floor(ms / 1000);
|
|
@@ -219,11 +245,14 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
219
245
|
// The mic, where the voice plugin is loaded: each stretch it's on is a clip, at its time in the recording.
|
|
220
246
|
const voice = use('voice');
|
|
221
247
|
let take: Take | undefined;
|
|
248
|
+
// React's commits, where the react plugin counts them: what stops them going in while they do.
|
|
249
|
+
const commits = use('react')?.commits;
|
|
250
|
+
let unreact: (() => void) | undefined;
|
|
222
251
|
/** What the next page carries on from, kept as it changes: a page that's going has no time to say it then. */
|
|
223
252
|
let over = false;
|
|
224
253
|
const save = () =>
|
|
225
254
|
// Not once it's ended, as its last events go: the next page would carry on with one that's over.
|
|
226
|
-
over || carry({ id, startedAt, seq, clips, mic: take !== undefined });
|
|
255
|
+
over || carry({ id, startedAt, seq, clips, mic: take !== undefined, react: unreact !== undefined });
|
|
227
256
|
const unsubscribe = marks?.subscribe(mark);
|
|
228
257
|
|
|
229
258
|
// One part at a time, each with its place. A part that didn't arrive goes again with the next, before it.
|
|
@@ -310,6 +339,34 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
310
339
|
// On, as the page before left it: a browser that was let use the mic gives it again without asking.
|
|
311
340
|
if (from?.mic === true) toggle();
|
|
312
341
|
|
|
342
|
+
const react =
|
|
343
|
+
commits === undefined
|
|
344
|
+
? undefined
|
|
345
|
+
: toolButton(ATOM, "Record React's commits: what rendered, how long it took, and why", 'P', () =>
|
|
346
|
+
reactOn(unreact === undefined),
|
|
347
|
+
);
|
|
348
|
+
react?.classList.add('react');
|
|
349
|
+
const reactOn = (on: boolean) => {
|
|
350
|
+
if (commits === undefined || react === undefined || on === (unreact !== undefined)) return;
|
|
351
|
+
if (on) {
|
|
352
|
+
rrweb.record.addCustomEvent(REACT, { on: true });
|
|
353
|
+
unreact = commits((commit) => rrweb.record.addCustomEvent(REACT, commit));
|
|
354
|
+
} else {
|
|
355
|
+
// What's waiting goes first, then where it stops.
|
|
356
|
+
unreact?.();
|
|
357
|
+
unreact = undefined;
|
|
358
|
+
rrweb.record.addCustomEvent(REACT, { on: false });
|
|
359
|
+
}
|
|
360
|
+
react.setAttribute('aria-pressed', String(on));
|
|
361
|
+
react.title = on ? "Stop recording React's commits" : "Record React's commits: what rendered, how long it took, and why";
|
|
362
|
+
react.setAttribute('aria-label', react.title);
|
|
363
|
+
wantReact(on);
|
|
364
|
+
save();
|
|
365
|
+
};
|
|
366
|
+
react?.setAttribute('aria-pressed', 'false');
|
|
367
|
+
// As the page before left it, or a new one as the last was left.
|
|
368
|
+
if (from?.react ?? reactWanted()) reactOn(true);
|
|
369
|
+
|
|
313
370
|
// The page is going, for another or for good, with no time to wait for anything: what's sent of the mic's
|
|
314
371
|
// take is its clip, the next page is told where things stand, and the last events go as the page does.
|
|
315
372
|
const leave = () => {
|
|
@@ -327,6 +384,9 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
327
384
|
addEventListener('pagehide', leave);
|
|
328
385
|
|
|
329
386
|
const end = async (kept: boolean) => {
|
|
387
|
+
// What's waiting of React's commits goes in before the end, and the next recording starts as this one ends.
|
|
388
|
+
unreact?.();
|
|
389
|
+
unreact = undefined;
|
|
330
390
|
rrweb.record.addCustomEvent(END, {});
|
|
331
391
|
stopRecording?.();
|
|
332
392
|
unsubscribe?.();
|
|
@@ -357,7 +417,7 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
357
417
|
// Record's key again: it's Stop while one is going.
|
|
358
418
|
const stop = toolButton(STOP, 'Stop', 'R', () => void end(true));
|
|
359
419
|
const discard = toolButton(DISCARD, 'Discard', 'Shift+R', () => void end(false));
|
|
360
|
-
going.replaceChildren(live, ...(mic ? [mic, wave] : []), stop, discard);
|
|
420
|
+
going.replaceChildren(live, ...(mic ? [mic, wave] : []), ...(react ? [react] : []), stop, discard);
|
|
361
421
|
// The panel stays while it goes: its controls are what ends it.
|
|
362
422
|
const unkeep = tools.keep();
|
|
363
423
|
start.hidden = true;
|
|
@@ -15,3 +15,10 @@ export const PAGE = 'deictic.page';
|
|
|
15
15
|
* recording of a still page (a voice-over, say) would replay as a moment, and its voice never play.
|
|
16
16
|
*/
|
|
17
17
|
export const END = 'deictic.end';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The custom event for React's commits, where the react plugin is loaded and they're asked for (the recording's React
|
|
21
|
+
* button): a `Commit` each (`deictic/react`'s), and `{ on }` where the recording starts and stops having them, so a
|
|
22
|
+
* stretch without them isn't read as one where nothing rendered.
|
|
23
|
+
*/
|
|
24
|
+
export const REACT = 'deictic.react';
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* publishes it as a file instead, `replayPage(sources)`: which recording is `?id=`, and a script of its own says
|
|
25
25
|
* where one is.
|
|
26
26
|
*/
|
|
27
|
-
import { MARKS } from './marks.ts';
|
|
27
|
+
import { MARKS, REACT } from './marks.ts';
|
|
28
28
|
|
|
29
29
|
/** Where the replay page finds what the plugin's routes would serve it, for a page published as a file. */
|
|
30
30
|
export interface ReplaySources {
|
|
@@ -76,7 +76,10 @@ export const replayPage = ({ player = '..', source }: ReplaySources = {}) => `<!
|
|
|
76
76
|
#log .text { min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
|
|
77
77
|
#log li.open .text { display: block; white-space: pre-wrap; }
|
|
78
78
|
#log pre { margin: 0; padding: 2px 8px 8px calc(8px + 6ch + 8px); color: #a1a1aa; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
79
|
-
#log.no-console li.console, #log.no-network li.network, #log.only-bad li:not(.bad) { display: none; }
|
|
79
|
+
#log.no-console li.console, #log.no-network li.network, #log.no-react li.react, #log.only-bad li:not(.bad) { display: none; }
|
|
80
|
+
#log li.react .label { color: #58c4dc; }
|
|
81
|
+
#log li.react.warn .label { color: #fbbf24; }
|
|
82
|
+
#main .rr-player .rr-progress .slow-mark { position: absolute; top: -3px; width: 3px; height: 10px; margin-left: -1px; border-radius: 1px; background: #fbbf24; pointer-events: none; }
|
|
80
83
|
#main .rr-player .rr-progress .bad-mark { position: absolute; top: -3px; width: 3px; height: 10px; margin-left: -1px; border-radius: 1px; background: #f87171; pointer-events: none; }
|
|
81
84
|
body.embed #main .rr-player { box-shadow: none; border-radius: 0; }
|
|
82
85
|
#marks { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; }
|
|
@@ -112,6 +115,7 @@ export const replayPage = ({ player = '..', source }: ReplaySources = {}) => `<!
|
|
|
112
115
|
<div class="filters">
|
|
113
116
|
<button type="button" data-hides="no-console" aria-pressed="true">Console</button>
|
|
114
117
|
<button type="button" data-hides="no-network" aria-pressed="true">Network</button>
|
|
118
|
+
<button type="button" data-hides="no-react" aria-pressed="true" hidden title="React's commits: what rendered, how long it took, and why">React</button>
|
|
115
119
|
<button type="button" data-shows="only-bad" aria-pressed="false" title="Errors, and requests that failed">Problems</button>
|
|
116
120
|
</div>
|
|
117
121
|
<ol></ol>
|
|
@@ -154,6 +158,27 @@ export const replayPage = ({ player = '..', source }: ReplaySources = {}) => `<!
|
|
|
154
158
|
const origin = (() => { try { return new URL(kept.page).origin; } catch { return ''; } })();
|
|
155
159
|
const fields = (title, held) => (held && Object.keys(held).length > 0 ? [title, ...Object.entries(held).map(([k, v]) => ' ' + k + ': ' + v)] : []);
|
|
156
160
|
const rows = [];
|
|
161
|
+
// React's commits, where the recording had them on: a row an entry, slow ones (past a frame) marked.
|
|
162
|
+
const ms = (n) => (n === undefined ? '' : (n < 10 ? n.toFixed(1) : Math.round(n)) + ' ms');
|
|
163
|
+
for (const e of events) {
|
|
164
|
+
if (e.type !== 5 || bare || e.data.tag !== ${JSON.stringify(REACT)}) continue;
|
|
165
|
+
const at = e.timestamp - t0;
|
|
166
|
+
const c = e.data.payload;
|
|
167
|
+
if (c.on !== undefined) {
|
|
168
|
+
rows.push({ at, kind: 'react', label: 'React', text: c.on ? 'commits recorded from here' : 'commits no longer recorded', more: [] });
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const named = (c.components ?? []).map((r) => r.name + (r.count > 1 ? ' ×' + r.count : '') + ' (' + r.why + ')');
|
|
172
|
+
const text = (named.length > 0 ? named.slice(0, 3).join(', ') : (c.more ?? 0) + ' components') + (named.length > 3 || (c.more && named.length > 0) ? ', …' : '');
|
|
173
|
+
const more = [
|
|
174
|
+
[c.commits > 1 ? c.commits + ' commits' + (c.over === undefined ? '' : ' over ' + (c.over / 1000).toFixed(1) + ' s') : '1 commit', c.priority, ms(c.ms), c.slowest === undefined ? '' : 'slowest ' + ms(c.slowest)].filter(Boolean).join(' · '),
|
|
175
|
+
...(c.components ?? []).map((r) => [r.name + (r.count > 1 ? ' ×' + r.count : ''), r.at, ms(r.ms), r.selfMs === undefined ? '' : ms(r.selfMs) + ' own', r.why].filter(Boolean).join(' · ')),
|
|
176
|
+
...(c.more ? ['and ' + c.more + ' more'] : []),
|
|
177
|
+
];
|
|
178
|
+
// One slow commit is what makes a page stutter, not many quick ones.
|
|
179
|
+
const slow = (c.slowest ?? c.ms) > 16;
|
|
180
|
+
rows.push({ at, kind: 'react', label: c.ms === undefined ? 'React' : ms(c.ms), warn: slow, slow, text: (c.over === undefined ? '' : c.commits + ' commits: ') + text, more });
|
|
181
|
+
}
|
|
157
182
|
for (const e of events) {
|
|
158
183
|
if (e.type !== 6 || bare) continue;
|
|
159
184
|
const at = e.timestamp - t0;
|
|
@@ -179,8 +204,10 @@ export const replayPage = ({ player = '..', source }: ReplaySources = {}) => `<!
|
|
|
179
204
|
}
|
|
180
205
|
}
|
|
181
206
|
}
|
|
207
|
+
rows.sort((a, b) => a.at - b.at);
|
|
182
208
|
const logged = rows.length > 0;
|
|
183
209
|
const log = document.getElementById('log');
|
|
210
|
+
if (rows.some((r) => r.kind === 'react')) log.querySelector('[data-hides="no-react"]').hidden = false;
|
|
184
211
|
if (logged) document.body.classList.add('logged');
|
|
185
212
|
// The panel's room, where the window is wide enough to show it (as the stylesheet has it).
|
|
186
213
|
const side = () => (logged && innerWidth >= 900 ? 340 : 0);
|
|
@@ -241,6 +268,7 @@ export const replayPage = ({ player = '..', source }: ReplaySources = {}) => `<!
|
|
|
241
268
|
row.el.append(go, more);
|
|
242
269
|
list.append(row.el);
|
|
243
270
|
// An error, or a request that failed, is a mark on the timeline too.
|
|
271
|
+
if (row.slow && bar) bar.append(Object.assign(cell('i', 'slow-mark', ''), { title: row.label + ': ' + row.text.slice(0, 200), style: 'left:' + (total > 0 ? (row.at / total) * 100 : 0) + '%' }));
|
|
244
272
|
if (row.bad && bar) bar.append(Object.assign(cell('i', 'bad-mark', ''), { title: row.text.slice(0, 200), style: 'left:' + (total > 0 ? (row.at / total) * 100 : 0) + '%' }));
|
|
245
273
|
}
|
|
246
274
|
for (const button of log.querySelectorAll('.filters button')) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** What the rrweb() renderer's two halves share about canvases, with no imports, as the page half runs in the page. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The attribute the page half gives each canvas with a picture: the canvas's size as the page lays it out, `WxH` in
|
|
5
|
+
* CSS pixels, then ` inline` where the canvas sits in a line of text, as which the server shows the picture.
|
|
6
|
+
*/
|
|
7
|
+
export const CANVAS_SIZE = 'data-deictic-canvas-size';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Has each WebGL canvas the page makes from here on keep what the canvas drew, where the page doesn't say: a WebGL
|
|
11
|
+
* canvas otherwise reads back cleared once the canvas's frame shows, so a shot of a page that drew and went still
|
|
12
|
+
* would have the canvas blank. rrweb's recorder does the same while the recorder records canvases. A page that clears
|
|
13
|
+
* each frame draws the same either way. Self-contained, as the rrweb() renderer's test runs the function in a page as it is.
|
|
14
|
+
*/
|
|
15
|
+
export function keepWebGLDrawing(): void {
|
|
16
|
+
if (typeof HTMLCanvasElement === 'undefined') return;
|
|
17
|
+
const proto = HTMLCanvasElement.prototype;
|
|
18
|
+
// The page's own `getContext`, called on each canvas as the canvas's own.
|
|
19
|
+
const original: unknown = Object.getOwnPropertyDescriptor(proto, 'getContext')?.value;
|
|
20
|
+
if (typeof original !== 'function') return;
|
|
21
|
+
proto.getContext = function (this: HTMLCanvasElement, type: string, options?: unknown) {
|
|
22
|
+
const given = typeof options === 'object' && options !== null ? (options as Record<string, unknown>) : {};
|
|
23
|
+
const webgl = type === 'webgl' || type === 'webgl2' || type === 'experimental-webgl';
|
|
24
|
+
const kept = webgl && given.preserveDrawingBuffer === undefined ? { ...given, preserveDrawingBuffer: true } : options;
|
|
25
|
+
return Reflect.apply(original, this, [type, kept]) as RenderingContext | null;
|
|
26
|
+
} as typeof HTMLCanvasElement.prototype.getContext;
|
|
27
|
+
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Its tool in the tool panel takes the window as it is, with what's drawn on the page, and puts the shot in the
|
|
7
7
|
* tray, for the next task.
|
|
8
8
|
*/
|
|
9
|
-
import { toolButton } from '#src/client/dom.ts';
|
|
9
|
+
import { POPUP_CLOSED, POPUP_OPENED, type PopupOpened, toolButton } from '#src/client/dom.ts';
|
|
10
10
|
import { trayed } from '#src/client/drawer.ts';
|
|
11
11
|
import { defineClientPlugin } from '#src/index.ts';
|
|
12
12
|
import type { Annotations } from '#src/plugins/annotations/index.ts';
|
|
@@ -29,6 +29,15 @@ export type PageCapture = (
|
|
|
29
29
|
},
|
|
30
30
|
) => Promise<{ body: Blob | string; type: string; box: Box }>;
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* What a renderer that can take the page at once makes of it, synchronously: as `PageCapture` answers, or nothing
|
|
34
|
+
* where it isn't ready (what it imports hasn't loaded). `prepare` loads it, once the page has started.
|
|
35
|
+
*/
|
|
36
|
+
export interface PageFreeze {
|
|
37
|
+
freeze: (element: Element, options: Parameters<PageCapture>[1]) => Awaited<ReturnType<PageCapture>> | undefined;
|
|
38
|
+
prepare: () => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
/** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */
|
|
33
42
|
export const notOurs = (node: Node) => !(node instanceof Element && node.localName === 'deictic-overlay');
|
|
34
43
|
|
|
@@ -39,6 +48,8 @@ export function boxOf(element: Element, area: NonNullable<CaptureOptions['area']
|
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
const BLANK = '#d4d4d8';
|
|
51
|
+
/** How long after its press a popup may first ask for the shot it froze, in milliseconds: later, it's another's. */
|
|
52
|
+
const ASKED = 60_000;
|
|
42
53
|
/** A camera, on a 24-pixel grid. */
|
|
43
54
|
const CAMERA = '<path d="M4 8h3l2-3h6l2 3h3v11H4z"/><circle cx="12" cy="13" r="3.5"/>';
|
|
44
55
|
|
|
@@ -70,11 +81,17 @@ export function mask(copy: Node, m: ResolvedMasking): void {
|
|
|
70
81
|
}
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
export function screenshotsClient(capture: PageCapture) {
|
|
84
|
+
export function screenshotsClient(capture: PageCapture, freezer?: PageFreeze) {
|
|
74
85
|
return defineClientPlugin<never, never, Capture>({
|
|
75
86
|
name: 'screenshots',
|
|
87
|
+
...(freezer === undefined ? {} : { pressed: ({ use }, element) => use('screenshots')?.freeze(element) }),
|
|
76
88
|
setup: ({ base, request, options, use, tools, tray, drawer, lightbox }) => {
|
|
77
89
|
const { masking, renderer } = options as { masking: ResolvedMasking; renderer: unknown };
|
|
90
|
+
// Ready for a press, which can't wait for an import: once the page has started, while the browser is idle.
|
|
91
|
+
if (freezer !== undefined) {
|
|
92
|
+
if (typeof requestIdleCallback === 'function') requestIdleCallback(freezer.prepare, { timeout: 5000 });
|
|
93
|
+
else setTimeout(freezer.prepare, 1000);
|
|
94
|
+
}
|
|
78
95
|
// Asked at each shot: the annotations plugin may be set up after this one.
|
|
79
96
|
const overlay = (area: Box) => {
|
|
80
97
|
const marks: Annotations | undefined = use('annotations');
|
|
@@ -88,7 +105,30 @@ export function screenshotsClient(capture: PageCapture) {
|
|
|
88
105
|
if (id === undefined) throw new Error(`screenshots: ${problem ?? res.statusText}`);
|
|
89
106
|
return { id, url: url ?? `${base}__deictic/plugins/screenshots/shot/${id}`, box: drawn ?? box, size };
|
|
90
107
|
};
|
|
108
|
+
// The last press's page, and its shot once it's asked for: the popup that press opened has it while it's open,
|
|
109
|
+
// whichever of its tabs asks. Not a popup opened on another element, nor one long after the press.
|
|
110
|
+
let last:
|
|
111
|
+
{ element: Element; at: number; made: Awaited<ReturnType<PageCapture>>; size: Shot['size']; shot?: Promise<Shot> } | undefined;
|
|
112
|
+
window.addEventListener(POPUP_CLOSED, () => (last = undefined));
|
|
113
|
+
window.addEventListener(POPUP_OPENED, (e) => {
|
|
114
|
+
if (last !== undefined && (e as CustomEvent<PopupOpened>).detail.element !== last.element) last = undefined;
|
|
115
|
+
});
|
|
91
116
|
const api: Capture = {
|
|
117
|
+
freeze: (element) => {
|
|
118
|
+
const { clientWidth: width, clientHeight: height } = document.documentElement;
|
|
119
|
+
const made = freezer?.freeze(element, { area: 'viewport', masking, renderer, overlay });
|
|
120
|
+
last = made === undefined ? undefined : { element, at: performance.now(), made, size: { width, height } };
|
|
121
|
+
},
|
|
122
|
+
frozen: (element) => {
|
|
123
|
+
if (last?.element !== element || (last.shot === undefined && performance.now() - last.at > ASKED)) return undefined;
|
|
124
|
+
const { made, size } = last;
|
|
125
|
+
if (last.shot === undefined) {
|
|
126
|
+
last.shot = add(made.body, made.type, { box: made.box, size });
|
|
127
|
+
// Asked for while the popup opens, and maybe never used: a failure is said where it's awaited.
|
|
128
|
+
last.shot.catch(() => {});
|
|
129
|
+
}
|
|
130
|
+
return last.shot;
|
|
131
|
+
},
|
|
92
132
|
capture: async (element, { area = 'viewport' } = {}) => {
|
|
93
133
|
const { body, type, box } = await capture(element, { area, masking, renderer, overlay });
|
|
94
134
|
const { clientWidth, clientHeight } = document.documentElement;
|
|
@@ -48,6 +48,17 @@ export interface Capture {
|
|
|
48
48
|
upload(png: Blob, of: Pick<Shot, 'box' | 'size'>): Promise<Shot>;
|
|
49
49
|
/** A copy of an element with what a shot hides hidden in it too: for a plugin that sends its HTML somewhere. */
|
|
50
50
|
masked(element: Element): Element;
|
|
51
|
+
/**
|
|
52
|
+
* Keeps what a shot of the page now needs, to render later: the overlay calls it (through the plugin's
|
|
53
|
+
* `pressed`) as a shortcut's press goes down, so a tooltip, a hover's styles or a focused menu are still there.
|
|
54
|
+
* Only a renderer that can take the page at once does (`rrweb()`, once it has loaded); the last press's is kept.
|
|
55
|
+
*/
|
|
56
|
+
freeze(element: Element): void;
|
|
57
|
+
/**
|
|
58
|
+
* The shot of the page as the last press on `element` froze it, rendered on the first ask, or nothing where the
|
|
59
|
+
* last press was on another element or nothing was frozen: then `capture` takes the page as it is now.
|
|
60
|
+
*/
|
|
61
|
+
frozen(element: Element): Promise<Shot> | undefined;
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
/** The server's half, for other plugins' server halves. */
|