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
|
@@ -17,6 +17,7 @@ import { createRequire } from 'node:module';
|
|
|
17
17
|
import type { Browser } from 'playwright-core';
|
|
18
18
|
import type * as Rrweb from 'rrweb-snapshot';
|
|
19
19
|
|
|
20
|
+
import { CANVAS_SIZE } from './canvas.ts';
|
|
20
21
|
import type { Box, BrowserOptions } from './index.ts';
|
|
21
22
|
|
|
22
23
|
/** What the page sends: its snapshot and what's needed to show it as the page does. */
|
|
@@ -37,6 +38,16 @@ export interface Snapshot {
|
|
|
37
38
|
clip?: Box;
|
|
38
39
|
/** An SVG the viewport's size, drawn over the page: the annotations, where there are any. */
|
|
39
40
|
overlay?: string;
|
|
41
|
+
/** The nodes in each interactive state as the shot was taken, which a copy of the DOM can't be in itself. */
|
|
42
|
+
states?: States;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The snapshot's nodes that matched each pseudo-class: what was hovered, focused, and around the focus. */
|
|
46
|
+
export interface States {
|
|
47
|
+
hover?: number[];
|
|
48
|
+
focus?: number[];
|
|
49
|
+
focusVisible?: number[];
|
|
50
|
+
focusWithin?: number[];
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
const HOST = '<!doctype html><html><body style="margin:0"></body></html>';
|
|
@@ -98,7 +109,9 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
|
|
|
98
109
|
await page.route(host, (route) => route.fulfill({ contentType: 'text/html', body: HOST }));
|
|
99
110
|
await page.goto(host);
|
|
100
111
|
await page.addScriptTag({ path: bundle() });
|
|
101
|
-
|
|
112
|
+
// The shot, and the attribute that sizes each canvas's picture, which the page's code can't import.
|
|
113
|
+
const given = { ...shot, size: CANVAS_SIZE };
|
|
114
|
+
const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size, states }) => {
|
|
102
115
|
const { rebuildIntoSandboxedIframe, createCache, createMirror } = (globalThis as unknown as { rrwebSnapshot: typeof Rrweb })
|
|
103
116
|
.rrwebSnapshot;
|
|
104
117
|
const mirror = createMirror();
|
|
@@ -110,14 +123,87 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
|
|
|
110
123
|
});
|
|
111
124
|
const doc = iframe.contentDocument;
|
|
112
125
|
if (doc === null) throw new Error('screenshots: the snapshot was rebuilt where it cannot be read');
|
|
126
|
+
// By its kind: the iframe's elements aren't instances of this page's `Element`.
|
|
127
|
+
const isElement = (node: Node | null): node is Element => node?.nodeType === 1;
|
|
128
|
+
// rrweb rebuilds a script as a `noscript` holding SCRIPT_PLACEHOLDER, which the sandbox, running no scripts,
|
|
129
|
+
// shows: hidden, as rrweb's own replayer hides it.
|
|
130
|
+
const hidden = doc.createElement('style');
|
|
131
|
+
hidden.textContent = 'noscript { display: none !important; }';
|
|
132
|
+
doc.head.append(hidden);
|
|
133
|
+
// What was hovered and focused: a copy of the DOM is in no state, so each rule of those pseudo-classes is
|
|
134
|
+
// copied under a class of its own, and the nodes that were in it get the class. Nested rules and grouping ones
|
|
135
|
+
// (a Tailwind `hover:` class is `&:hover { @media (hover: hover) { … } }`) are copied whole.
|
|
136
|
+
if (states !== undefined) {
|
|
137
|
+
const pseudo: [string, string][] = [
|
|
138
|
+
[':focus-visible', 'deictic-focus-visible'],
|
|
139
|
+
[':focus-within', 'deictic-focus-within'],
|
|
140
|
+
[':focus', 'deictic-focus'],
|
|
141
|
+
[':hover', 'deictic-hover'],
|
|
142
|
+
];
|
|
143
|
+
type Rules = { cssRules: CSSRuleList; insertRule: (rule: string, index: number) => number };
|
|
144
|
+
const copy = (into: Rules) => {
|
|
145
|
+
const list = into.cssRules;
|
|
146
|
+
for (let i = 0; i < list.length; i++) {
|
|
147
|
+
const rule = list[i] as CSSRule & Partial<Rules> & { selectorText?: string };
|
|
148
|
+
if (rule.cssRules !== undefined && rule.insertRule !== undefined) copy(rule as Rules);
|
|
149
|
+
const selector = rule.selectorText;
|
|
150
|
+
if (selector === undefined || !rule.cssText.startsWith(selector)) continue;
|
|
151
|
+
let stated = selector;
|
|
152
|
+
for (const [name, className] of pseudo) stated = stated.split(name).join(`.${className}`);
|
|
153
|
+
if (stated === selector) continue;
|
|
154
|
+
try {
|
|
155
|
+
into.insertRule(stated + rule.cssText.slice(selector.length), i + 1);
|
|
156
|
+
i++;
|
|
157
|
+
} catch {
|
|
158
|
+
// A selector this browser won't take back: that state goes unshown.
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const roots: (Document | ShadowRoot)[] = [doc];
|
|
163
|
+
for (let i = 0; i < roots.length; i++)
|
|
164
|
+
for (const el of roots[i]!.querySelectorAll('*')) if (el.shadowRoot !== null) roots.push(el.shadowRoot);
|
|
165
|
+
for (const root of roots) {
|
|
166
|
+
for (const sheet of [...root.styleSheets, ...root.adoptedStyleSheets]) {
|
|
167
|
+
try {
|
|
168
|
+
copy(sheet);
|
|
169
|
+
} catch {
|
|
170
|
+
// Another origin's, which can't be read: rrweb inlines what it can.
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const classes = {
|
|
175
|
+
hover: 'deictic-hover',
|
|
176
|
+
focus: 'deictic-focus',
|
|
177
|
+
focusVisible: 'deictic-focus-visible',
|
|
178
|
+
focusWithin: 'deictic-focus-within',
|
|
179
|
+
};
|
|
180
|
+
for (const [name, className] of Object.entries(classes)) {
|
|
181
|
+
for (const id of states[name as keyof typeof classes] ?? []) {
|
|
182
|
+
const node = mirror.getNode(id);
|
|
183
|
+
if (isElement(node)) node.classList.add(className);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// The sandbox runs no scripts, and where scripts don't run, a canvas shows what's inside the canvas instead of
|
|
188
|
+
// what was drawn on the canvas: so each canvas's picture goes inside the canvas, at the size the page laid the
|
|
189
|
+
// canvas out at. rrweb's own drawing of the picture on the canvas never shows.
|
|
190
|
+
for (const canvas of doc.querySelectorAll(`canvas[${size}]`)) {
|
|
191
|
+
const meta = mirror.getMeta(canvas);
|
|
192
|
+
const [box, inline] = (canvas.getAttribute(size) ?? '').split(' ');
|
|
193
|
+
const [width, height] = (box ?? '').split('x');
|
|
194
|
+
if (meta === null || !('attributes' in meta) || typeof meta.attributes.rr_dataURL !== 'string') continue;
|
|
195
|
+
const picture = doc.createElement('img');
|
|
196
|
+
picture.src = meta.attributes.rr_dataURL;
|
|
197
|
+
// In a line as the canvas was, else the whole of the canvas's box.
|
|
198
|
+
picture.style.cssText = `display:${inline === undefined ? 'block' : 'inline'};width:${width}px;height:${height}px`;
|
|
199
|
+
canvas.replaceChildren(picture);
|
|
200
|
+
}
|
|
113
201
|
await doc.fonts.ready;
|
|
114
202
|
await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));
|
|
115
203
|
// At once: a page with `scroll-behavior: smooth` would glide there, and be shot on its way.
|
|
116
204
|
iframe.contentWindow?.scrollTo({ left: scroll.x, top: scroll.y, behavior: 'instant' });
|
|
117
205
|
// rrweb scrolled each element as it built it, before the fonts and images gave its content its height:
|
|
118
206
|
// one that couldn't scroll that far yet is scrolled again now.
|
|
119
|
-
// By its kind: the iframe's elements aren't instances of this page's `Element`.
|
|
120
|
-
const isElement = (node: Node | null): node is Element => node?.nodeType === 1;
|
|
121
207
|
for (const id of mirror.getIds()) {
|
|
122
208
|
const node = mirror.getNode(id);
|
|
123
209
|
const meta = node === null ? null : mirror.getMeta(node);
|
|
@@ -141,7 +227,7 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
|
|
|
141
227
|
marks.innerHTML = overlay;
|
|
142
228
|
document.body.append(marks);
|
|
143
229
|
return box;
|
|
144
|
-
},
|
|
230
|
+
}, given);
|
|
145
231
|
// Without the scrollbars: a shot is what the page is drawn in, which is what an element's box is from.
|
|
146
232
|
// A shot of the element alone is cut where the element is here.
|
|
147
233
|
const clip = clamp(shot.clip === undefined ? { x: 0, y: 0, ...shot.viewport } : (found ?? shot.clip), shot.viewport);
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `rrweb()` renderer's page half: a snapshot of the page's DOM with `rrweb-snapshot` (imported
|
|
3
|
-
*
|
|
2
|
+
* The `rrweb()` renderer's page half: a snapshot of the page's DOM with `rrweb-snapshot` (imported as the page
|
|
3
|
+
* starts), masked as rrweb masks, without deictic's overlay, sent with what the server's browser needs
|
|
4
4
|
* to show it as the page does: the viewport and the window around it, where it's scrolled to, the pixel density, the page's URL.
|
|
5
|
-
* And which node of the snapshot the element is, so the server says where it is in what it drew
|
|
5
|
+
* And which node of the snapshot the element is, so the server says where it is in what it drew, and which match
|
|
6
|
+
* `:hover` and `:focus` and the like, which a copy of the DOM has no state for and the server gives them again.
|
|
7
|
+
*
|
|
8
|
+
* It takes the page at once, so a press can freeze it (`PageFreeze`): rrweb-snapshot is imported once the page has
|
|
9
|
+
* started, while the browser is idle, and a press before it has loaded is taken as the task goes, as without.
|
|
6
10
|
*/
|
|
11
|
+
import type * as RrwebSnapshot from 'rrweb-snapshot';
|
|
7
12
|
|
|
8
|
-
import {
|
|
13
|
+
import { CANVAS_SIZE, keepWebGLDrawing } from './canvas.ts';
|
|
14
|
+
import { boxOf, type PageCapture, type PageFreeze, screenshotsClient } from './client.ts';
|
|
9
15
|
import type { Snapshot, SnapshotNode } from './playwright.ts';
|
|
16
|
+
import { statesOf } from './states.ts';
|
|
17
|
+
|
|
18
|
+
type Rrweb = typeof RrwebSnapshot;
|
|
19
|
+
|
|
20
|
+
// As the page loads, before the page makes its canvases.
|
|
21
|
+
keepWebGLDrawing();
|
|
10
22
|
|
|
11
23
|
/** The snapshot without deictic's overlay, which rrweb has no option to leave out. */
|
|
12
24
|
function withoutOurs(node: SnapshotNode): SnapshotNode {
|
|
@@ -15,14 +27,26 @@ function withoutOurs(node: SnapshotNode): SnapshotNode {
|
|
|
15
27
|
return { ...node, childNodes };
|
|
16
28
|
}
|
|
17
29
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
let loading: Promise<Rrweb> | undefined;
|
|
31
|
+
let loaded: Rrweb | undefined;
|
|
32
|
+
const load = () =>
|
|
33
|
+
(loading ??= import('rrweb-snapshot').then(
|
|
34
|
+
(module) => (loaded = module),
|
|
35
|
+
(e: unknown) => {
|
|
36
|
+
loading = undefined;
|
|
37
|
+
throw new Error('the rrweb() renderer needs rrweb-snapshot: add it to your devDependencies', { cause: e });
|
|
38
|
+
},
|
|
39
|
+
));
|
|
40
|
+
|
|
41
|
+
/** The page now, at once: what the server renders. */
|
|
42
|
+
function take(rrweb: Rrweb, element: Element, { area, masking, overlay }: Parameters<PageCapture>[1]) {
|
|
43
|
+
const { snapshot, createMirror } = rrweb;
|
|
22
44
|
const mirror = createMirror();
|
|
23
45
|
const taken = snapshot(document, {
|
|
24
46
|
mirror,
|
|
25
47
|
inlineStylesheet: true,
|
|
48
|
+
// A canvas as a picture of what it shows, which the server draws on the canvas it rebuilds.
|
|
49
|
+
recordCanvas: true,
|
|
26
50
|
blockClass: masking.blockClass,
|
|
27
51
|
blockSelector: masking.blockSelector ?? null,
|
|
28
52
|
maskTextClass: masking.maskTextClass,
|
|
@@ -30,10 +54,18 @@ export default screenshotsClient(async (element, { area, masking, overlay }) =>
|
|
|
30
54
|
maskAllInputs: masking.maskAllInputs,
|
|
31
55
|
});
|
|
32
56
|
if (taken === null) throw new Error('screenshots: rrweb took no snapshot of this page');
|
|
57
|
+
// Each canvas's size as the page lays it out, and whether in a line, as which the server shows the canvas's picture.
|
|
58
|
+
for (const canvas of document.querySelectorAll('canvas')) {
|
|
59
|
+
const node = mirror.getMeta(canvas);
|
|
60
|
+
if (node === null || !('attributes' in node) || typeof node.attributes.rr_dataURL !== 'string') continue;
|
|
61
|
+
const inline = getComputedStyle(canvas).display === 'inline';
|
|
62
|
+
node.attributes[CANVAS_SIZE] = `${canvas.offsetWidth}x${canvas.offsetHeight}${inline ? ' inline' : ''}`;
|
|
63
|
+
}
|
|
33
64
|
const box = boxOf(element, area);
|
|
34
65
|
const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };
|
|
35
66
|
// Over the viewport, which the server renders before cutting out an element's part.
|
|
36
67
|
const marks = overlay({ x: 0, y: 0, ...viewport });
|
|
68
|
+
const states = statesOf((el) => mirror.getId(el));
|
|
37
69
|
const body: Snapshot = {
|
|
38
70
|
snapshot: withoutOurs(taken),
|
|
39
71
|
...(mirror.getId(element) === -1 ? {} : { element: mirror.getId(element) }),
|
|
@@ -41,10 +73,26 @@ export default screenshotsClient(async (element, { area, masking, overlay }) =>
|
|
|
41
73
|
viewport,
|
|
42
74
|
window: { width: innerWidth, height: innerHeight },
|
|
43
75
|
...(marks === undefined ? {} : { overlay: marks }),
|
|
76
|
+
...(Object.keys(states).length === 0 ? {} : { states }),
|
|
44
77
|
scroll: { x: scrollX, y: scrollY },
|
|
45
78
|
scale: Math.min(devicePixelRatio, 2),
|
|
46
79
|
// A shot of the element alone is the part of the viewport it fills.
|
|
47
80
|
...(area === 'element' ? { clip: element.getBoundingClientRect().toJSON() as Snapshot['clip'] } : {}),
|
|
48
81
|
};
|
|
49
82
|
return { body: JSON.stringify(body), type: 'application/json', box };
|
|
50
|
-
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const freezer: PageFreeze = {
|
|
86
|
+
// Not in a frame: a press is now, before the page's own handlers change it. A WebGL canvas shows what it drew,
|
|
87
|
+
// as `keepWebGLDrawing` has it keep its buffer.
|
|
88
|
+
freeze: (element, options) => (loaded === undefined ? undefined : take(loaded, element, options)),
|
|
89
|
+
prepare: () => void load().catch(() => {}),
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export default screenshotsClient(async (element, options) => {
|
|
93
|
+
const rrweb = await load();
|
|
94
|
+
// In a frame, after the page drew in it: a WebGL canvas reads back blank once its frame is shown, unless the page
|
|
95
|
+
// keeps its drawing buffer, and the page's own callbacks for the frame were asked for before this one.
|
|
96
|
+
await new Promise((done) => requestAnimationFrame(done));
|
|
97
|
+
return take(rrweb, element, options);
|
|
98
|
+
}, freezer);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a copy of the DOM loses: which elements are hovered and focused. The `rrweb()` renderer reads it as it takes
|
|
3
|
+
* the page, and its server half gives the rebuilt page those states again (`playwright.ts`). Self-contained, with
|
|
4
|
+
* nothing from outside it, so a test can run this very function in a browser.
|
|
5
|
+
*/
|
|
6
|
+
import type { States } from './playwright.ts';
|
|
7
|
+
|
|
8
|
+
/** Which nodes match each state now, by the snapshot's IDs (`id`), through open shadow roots, deictic's overlay left out. */
|
|
9
|
+
export function statesOf(id: (el: Element) => number, root: Document = document): States {
|
|
10
|
+
const pseudo = { hover: ':hover', focus: ':focus', focusVisible: ':focus-visible', focusWithin: ':focus-within' } as const;
|
|
11
|
+
const states: States = {};
|
|
12
|
+
for (const [name, selector] of Object.entries(pseudo) as [keyof States, string][]) {
|
|
13
|
+
const ids: number[] = [];
|
|
14
|
+
const within = (inside: Document | ShadowRoot) => {
|
|
15
|
+
for (const el of inside.querySelectorAll(selector)) {
|
|
16
|
+
if (el.localName === 'deictic-overlay') continue;
|
|
17
|
+
const known = id(el);
|
|
18
|
+
if (known !== -1) ids.push(known);
|
|
19
|
+
if (el.shadowRoot !== null) within(el.shadowRoot);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
within(root);
|
|
23
|
+
if (ids.length > 0) states[name] = ids;
|
|
24
|
+
}
|
|
25
|
+
return states;
|
|
26
|
+
}
|
|
@@ -221,11 +221,27 @@ export default defineClientPlugin<Model, Op>({
|
|
|
221
221
|
const unpin = over ? pinsIn(context).glance() : undefined;
|
|
222
222
|
|
|
223
223
|
const shots = context.use('screenshots');
|
|
224
|
+
// The page as the press that opened the popup froze it, rendered meanwhile: a shot taken as it's sent may have
|
|
225
|
+
// missed a tooltip or a menu, which the popup's own pointer and focus close.
|
|
226
|
+
const frozen = shots?.frozen(context.element);
|
|
224
227
|
const recorder = context.use('recordings');
|
|
225
228
|
const back = context.resumed;
|
|
226
229
|
// The server half's `html` option, which takes the button away; a page half with no options (a `standalone` server's) has it.
|
|
227
230
|
const sendsHtml = (context.options as { html?: boolean } | undefined)?.html !== false;
|
|
228
231
|
const own = (): About[] => [{ target: context.target, own: true, el: context.element }];
|
|
232
|
+
const inspector = context.use('react');
|
|
233
|
+
/**
|
|
234
|
+
* What React's DevTools would show of an element, where the react plugin is loaded: read now, while the page has
|
|
235
|
+
* it, or as the panel left it. A read that fails leaves it out, not the task.
|
|
236
|
+
*/
|
|
237
|
+
const reactOf = async (a: About): Promise<string | undefined> => {
|
|
238
|
+
const el = onPage(a);
|
|
239
|
+
if (el === undefined) return a.seen?.react;
|
|
240
|
+
return inspector?.snapshot(el).catch((e: unknown) => {
|
|
241
|
+
console.warn('deictic: the task goes without react.json', e);
|
|
242
|
+
return undefined;
|
|
243
|
+
});
|
|
244
|
+
};
|
|
229
245
|
|
|
230
246
|
/**
|
|
231
247
|
* What the page says of an element: read now, while the page has it, and as the panel left it where the page
|
|
@@ -273,10 +289,16 @@ export default defineClientPlugin<Model, Op>({
|
|
|
273
289
|
...(shot === undefined ? {} : { shot }),
|
|
274
290
|
html,
|
|
275
291
|
...wherever(about),
|
|
276
|
-
about:
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
292
|
+
about: (
|
|
293
|
+
await Promise.all(
|
|
294
|
+
about.map(async (a) => {
|
|
295
|
+
const seen = seenOf(a);
|
|
296
|
+
if (seen === undefined) return [];
|
|
297
|
+
const react = sendsHtml && html ? await reactOf(a) : undefined;
|
|
298
|
+
return [{ target: a.target, own: a.own, seen: { ...seen, ...(react === undefined ? {} : { react }) } }];
|
|
299
|
+
}),
|
|
300
|
+
)
|
|
301
|
+
).flat(),
|
|
280
302
|
};
|
|
281
303
|
context.away(kept, () => recorder.record());
|
|
282
304
|
};
|
|
@@ -288,6 +310,7 @@ export default defineClientPlugin<Model, Op>({
|
|
|
288
310
|
html: sendsHtml,
|
|
289
311
|
...(context.at === undefined ? {} : { at: context.at }),
|
|
290
312
|
shoot: true,
|
|
313
|
+
...(frozen === undefined ? {} : { frozen }),
|
|
291
314
|
// Back from a recording on a page without the element: nothing of it to shoot or draw on here.
|
|
292
315
|
here: context.element.isConnected,
|
|
293
316
|
over,
|
|
@@ -297,15 +320,27 @@ export default defineClientPlugin<Model, Op>({
|
|
|
297
320
|
const { text, about, html: withHtml, screenshots } = gathered;
|
|
298
321
|
// The first element is the task's place; the rest are named beside it; with none, it's the page's.
|
|
299
322
|
const [first, ...rest] = about;
|
|
300
|
-
const { html, ...said } = (first === undefined ? undefined : seenOf(first)) ?? { html: undefined, count: 0 };
|
|
323
|
+
const { html, react: _, ...said } = (first === undefined ? undefined : seenOf(first)) ?? { html: undefined, count: 0 };
|
|
301
324
|
const htmlOf = (of: string | undefined) => (sendsHtml && withHtml && of !== undefined ? { html: of } : {});
|
|
325
|
+
// Its components' props and state go with its HTML, as what the page had.
|
|
326
|
+
const reactWith = async (a: About) => {
|
|
327
|
+
const react = sendsHtml && withHtml ? await reactOf(a) : undefined;
|
|
328
|
+
return react === undefined ? {} : { react };
|
|
329
|
+
};
|
|
302
330
|
const op: Op = {
|
|
303
331
|
text,
|
|
304
332
|
...wherever(about),
|
|
305
333
|
...said,
|
|
306
334
|
...(first === undefined ? { detached: true } : {}),
|
|
307
335
|
...htmlOf(html),
|
|
308
|
-
...(
|
|
336
|
+
...(first === undefined ? {} : await reactWith(first)),
|
|
337
|
+
...(rest.length === 0
|
|
338
|
+
? {}
|
|
339
|
+
: {
|
|
340
|
+
also: await Promise.all(
|
|
341
|
+
rest.map(async (a) => ({ at: atOf(a.target), tag: a.target.tag, ...htmlOf(seenOf(a)?.html), ...(await reactWith(a)) })),
|
|
342
|
+
),
|
|
343
|
+
}),
|
|
309
344
|
...attachedOf(gathered),
|
|
310
345
|
};
|
|
311
346
|
// Sent on its first element, which may not be the popup's.
|
|
@@ -26,7 +26,7 @@ import type { ClientContext, LightboxItem, Point, Target } from '#src/index.ts';
|
|
|
26
26
|
// For `use()`'s types: the plugins may not be loaded, and nothing of them runs here.
|
|
27
27
|
import type { Annotation, Annotations, Picture } from '#src/plugins/annotations/index.ts';
|
|
28
28
|
import type { Recording } from '#src/plugins/recordings/index.ts';
|
|
29
|
-
import type { Shot } from '#src/plugins/screenshots/index.ts';
|
|
29
|
+
import type { Capture, Shot } from '#src/plugins/screenshots/index.ts';
|
|
30
30
|
import type { Clip, Take } from '#src/plugins/voice/index.ts';
|
|
31
31
|
|
|
32
32
|
import type { Marks, Op } from './index.ts';
|
|
@@ -134,6 +134,8 @@ export type Sent = NonNullable<Op['screenshots']>[number] & { url: string };
|
|
|
134
134
|
export interface Seen extends Pick<Op, 'point' | 'pointed' | 'count' | 'which' | 'chain'> {
|
|
135
135
|
/** The element's HTML, as it would be attached. */
|
|
136
136
|
html: string;
|
|
137
|
+
/** What React's DevTools would show of it, `react.json`, where the react plugin is loaded and React wrote it. */
|
|
138
|
+
react?: string;
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
/**
|
|
@@ -211,6 +213,11 @@ export interface ComposerOptions {
|
|
|
211
213
|
at?: Point;
|
|
212
214
|
/** Whether a shot is taken as it's sent, while nothing else is attached and none was asked for or not: a task's. */
|
|
213
215
|
shoot?: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* The popup's own element as the press that opened it froze the page (`screenshots.frozen`): what a shot of it is,
|
|
218
|
+
* rather than the page as it is when it's sent, by which time a tooltip or a menu may have closed.
|
|
219
|
+
*/
|
|
220
|
+
frozen?: Promise<Shot>;
|
|
214
221
|
/** Whether this page has what's shot and drawn on: not for a task back from a recording on a page without it. */
|
|
215
222
|
here?: boolean;
|
|
216
223
|
/** Whether it's over the page, in the overlay's root: a press on the page picks an element, and attached ones are outlined. */
|
|
@@ -309,10 +316,20 @@ export function composerIn(context: ClientContext, options: ComposerOptions): Co
|
|
|
309
316
|
|
|
310
317
|
const text = element('textarea', { placeholder: options.placeholder, rows: 1 });
|
|
311
318
|
const chipsEl = element('div', { className: 'chips' });
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
319
|
+
/** A shot of `of`: as the press froze it, where it's the popup's own element still first, else as the page is now. */
|
|
320
|
+
const shotOf = (s: Capture, of: Element) => {
|
|
321
|
+
const frozen = about[0]?.own === true && onPage(about[0]) === of ? options.frozen : undefined;
|
|
322
|
+
return frozen === undefined ? s.capture(of) : frozen.catch(() => s.capture(of));
|
|
323
|
+
};
|
|
324
|
+
const camera = toolButton(
|
|
325
|
+
CAMERA,
|
|
326
|
+
options.frozen === undefined ? `Attach a screenshot, taken as it's sent` : 'Attach a screenshot of the page as it was when you pressed',
|
|
327
|
+
undefined,
|
|
328
|
+
() => {
|
|
329
|
+
wanted = !shooting();
|
|
330
|
+
showChips();
|
|
331
|
+
},
|
|
332
|
+
);
|
|
316
333
|
camera.hidden = shots === undefined || !here;
|
|
317
334
|
const code = toolButton(CODE, 'Attach an HTML snapshot: the element as the page has it now, as a file', undefined, () => {
|
|
318
335
|
withHtml = !withHtml;
|
|
@@ -541,7 +558,7 @@ export function composerIn(context: ClientContext, options: ComposerOptions): Co
|
|
|
541
558
|
problem.textContent = '';
|
|
542
559
|
try {
|
|
543
560
|
if (old === undefined) doing.textContent = 'Capturing…';
|
|
544
|
-
const shot = old?.drawn?.shot ?? (await shots
|
|
561
|
+
const shot = old?.drawn?.shot ?? (await shotOf(shots, onPage(about[0]) ?? document.documentElement));
|
|
545
562
|
doing.textContent = '';
|
|
546
563
|
const picture: Picture = { url: shot.url, ...shot.size };
|
|
547
564
|
const marks = await notes.edit(picture, old?.drawn?.marks ?? [], { signal: aborts.signal });
|
|
@@ -676,7 +693,7 @@ export function composerIn(context: ClientContext, options: ComposerOptions): Co
|
|
|
676
693
|
// Of the first element, which the shot then says the place of; of the page, with none on it.
|
|
677
694
|
const first = onPage(about[0]);
|
|
678
695
|
const of = first ?? document.documentElement;
|
|
679
|
-
const now = await shots
|
|
696
|
+
const now = await shotOf(shots, of);
|
|
680
697
|
const where = first === undefined ? {} : { box: now.box };
|
|
681
698
|
// The others as the page has them, moved by as much as the shot has the first off where the page has it.
|
|
682
699
|
const live = of.getBoundingClientRect();
|
|
@@ -229,7 +229,7 @@ export interface Op {
|
|
|
229
229
|
* The other elements it's about, after the one it's sent on, in the order they were attached: each one's place,
|
|
230
230
|
* its tag, and its HTML as it rendered, where that's attached.
|
|
231
231
|
*/
|
|
232
|
-
also?: { at: string; tag: string; html?: string }[];
|
|
232
|
+
also?: { at: string; tag: string; html?: string; react?: string }[];
|
|
233
233
|
/**
|
|
234
234
|
* No element is attached: it's about the page, and the element it's sent on is only where the popup was. It has
|
|
235
235
|
* no place then, so no element's tab lists it and nothing pins it.
|
|
@@ -244,6 +244,11 @@ export interface Op {
|
|
|
244
244
|
chain?: string[];
|
|
245
245
|
/** The element's HTML as it rendered, to attach: cut short, and masked where the screenshots plugin is loaded. */
|
|
246
246
|
html?: string;
|
|
247
|
+
/**
|
|
248
|
+
* What React's DevTools would show of the components that wrote it, as JSON, to attach as `react.json`: where the
|
|
249
|
+
* react plugin is loaded, and sent with the HTML.
|
|
250
|
+
*/
|
|
251
|
+
react?: string;
|
|
247
252
|
/**
|
|
248
253
|
* Shots the screenshots plugin took, to attach, where that plugin is loaded: each with where the element is in
|
|
249
254
|
* it (`box`, for one taken of the element; one taken of the window from the tool panel has none), whether
|
|
@@ -607,8 +612,14 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
607
612
|
if (html !== undefined) files.push({ data: new TextEncoder().encode(html.slice(0, HTML)), name: 'element.html', type: 'text/html' });
|
|
608
613
|
else if (op.pointed !== undefined)
|
|
609
614
|
files.push({ data: new TextEncoder().encode(op.pointed.html.slice(0, HTML)), name: 'pointed.html', type: 'text/html' });
|
|
615
|
+
const json = (of: unknown, name: string) => {
|
|
616
|
+
if (typeof of === 'string' && of !== '')
|
|
617
|
+
files.push({ data: new TextEncoder().encode(of.slice(0, REACT)), name, type: 'application/json' });
|
|
618
|
+
};
|
|
619
|
+
json(op.react, 'react.json');
|
|
610
620
|
// The others': the Nth element's is `element.N.html`, the first being the one it's sent on.
|
|
611
621
|
for (const [i, other] of (op.also ?? []).entries()) {
|
|
622
|
+
json(other.react, `react.${i + 2}.json`);
|
|
612
623
|
if (typeof other.html !== 'string' || other.html === '') continue;
|
|
613
624
|
files.push({ data: new TextEncoder().encode(other.html.slice(0, HTML)), name: `element.${i + 2}.html`, type: 'text/html' });
|
|
614
625
|
}
|
|
@@ -845,7 +856,7 @@ function textPage(name: string, text: string): string {
|
|
|
845
856
|
type Kind = 'screenshot' | 'recording' | 'voice clip' | 'voice note';
|
|
846
857
|
|
|
847
858
|
/** What a task or a reply attaches: files, and what the labels say of them. */
|
|
848
|
-
type Attaching = Partial<Pick<Op, 'screenshots' | 'recordings' | 'voice' | 'annotations' | 'html' | 'pointed' | 'also'>>;
|
|
859
|
+
type Attaching = Partial<Pick<Op, 'screenshots' | 'recordings' | 'voice' | 'annotations' | 'html' | 'react' | 'pointed' | 'also'>>;
|
|
849
860
|
|
|
850
861
|
/**
|
|
851
862
|
* A message's files, as the drawer shows them: each recording with where it replays, which its
|
|
@@ -913,6 +924,9 @@ const boxOf = ({ x, y, width, height }: Box) => [x, y, width, height].map(Math.r
|
|
|
913
924
|
/** What `element.html` holds of an element at most, in characters: a table's rows, not a whole page. */
|
|
914
925
|
const HTML = 100_000;
|
|
915
926
|
|
|
927
|
+
/** What `react.json` holds at most, in characters: the page half cuts it to less. */
|
|
928
|
+
const REACT = 250_000;
|
|
929
|
+
|
|
916
930
|
/** A label's value: a board holds 256 characters. */
|
|
917
931
|
const LABEL = 256;
|
|
918
932
|
|