deictic 0.7.0 → 0.8.1
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 +23 -3
- package/README.md +2 -1
- package/dist/bun.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +77 -51
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/next.js +1 -1
- package/dist/recommended/index.d.ts +1 -1
- package/dist/recordings/client.js +8 -2
- package/dist/recordings/client.js.map +1 -1
- package/dist/screenshots/rrweb.d.ts.map +1 -1
- package/dist/screenshots/rrweb.js +11 -2
- package/dist/screenshots/rrweb.js.map +1 -1
- package/dist/shared/canvas.js +30 -0
- package/dist/shared/canvas.js.map +1 -0
- package/dist/shared/endpoints.js +26 -6
- package/dist/shared/endpoints.js.map +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 +35 -3
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +22 -2
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/index9.d.ts +1 -1
- package/dist/shared/integration.d.ts +1 -1
- package/dist/shared/integration.js +59 -5
- package/dist/shared/integration.js.map +1 -1
- package/dist/shared/package.js +23 -0
- package/dist/shared/package.js.map +1 -0
- package/dist/shared/packages.js +14 -23
- package/dist/shared/packages.js.map +1 -1
- package/dist/shared/playwright.js +32 -6
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +12 -3
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +52 -4
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/watch.js +2 -1
- package/dist/shared/watch.js.map +1 -1
- package/dist/tailwind/index.js +7 -2
- package/dist/tailwind/index.js.map +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +50 -9
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +2 -2
- package/dist/webpack.js +1 -1
- package/package.json +2 -1
- package/src/cli/find.ts +5 -1
- package/src/cli/frame.ts +6 -3
- package/src/cli/task.ts +20 -4
- package/src/cli/watch.ts +3 -1
- package/src/client/index.ts +76 -43
- package/src/index.ts +35 -2
- package/src/plugins/recordings/client.ts +8 -2
- package/src/plugins/screenshots/canvas.ts +27 -0
- package/src/plugins/screenshots/playwright.ts +34 -7
- package/src/plugins/screenshots/rrweb.ts +30 -9
- package/src/plugins/tailwind/index.ts +3 -2
- package/src/plugins/tasks/client.ts +13 -3
- package/src/plugins/tasks/composer.ts +1 -1
- package/src/plugins/tasks/drawer.ts +3 -3
- package/src/plugins/tasks/index.ts +81 -3
- package/src/plugins/tasks/pins.ts +12 -7
- package/src/plugins/tasks/which.ts +34 -0
- package/src/tools/endpoints.ts +31 -5
- package/src/tools/packages.ts +12 -4
- package/src/tools/plugins.ts +18 -4
- package/src/tools/problems.ts +60 -0
package/dist/tasks/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Added, Answer, Attached, Edited, Kept, Listed, type LocalBoard, type LocalOptions, Marks, Model, Op, Place, Placed, Removed, Reply, Task, TaskAdded, TaskBoard, TasksOptions, Thread, tasks as default, tasks, local };
|
|
1
|
+
import { C as local, S as LocalOptions, _ as TasksOptions, a as Kept, b as tasks, c as Model, d as Placed, f as Removed, g as TaskBoard, h as TaskAdded, i as Edited, l as Op, m as Task, n as Answer, o as Listed, p as Reply, r as Attached, s as Marks, t as Added, u as Place, v as Thread, x as LocalBoard, y as Which } from "../shared/index7.js";
|
|
2
|
+
export { Added, Answer, Attached, Edited, Kept, Listed, type LocalBoard, type LocalOptions, Marks, Model, Op, Place, Placed, Removed, Reply, Task, TaskAdded, TaskBoard, TasksOptions, Thread, Which, tasks as default, tasks, local };
|
package/dist/webpack.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as nodeMiddleware, t as endpoints } from "./shared/endpoints.js";
|
|
2
|
-
import {
|
|
2
|
+
import { h as JSX, o as prepare, s as writeClient, t as beside } from "./shared/integration.js";
|
|
3
3
|
// src/tools/editor.ts
|
|
4
4
|
async function openInEditor(path, { line, column }) {
|
|
5
5
|
const launcher = await import("launch-editor").catch(() => void 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deictic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Point at an element in your running app and leave a task about it for your agent.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -250,6 +250,7 @@
|
|
|
250
250
|
"build": "tsdown",
|
|
251
251
|
"prepack": "tsdown --clean",
|
|
252
252
|
"example": "tsdown && bun run --cwd examples/vite dev",
|
|
253
|
+
"slop": "tsdown && bun run --cwd examples/slop dev",
|
|
253
254
|
"prepare": "git config core.hooksPath .githooks || true",
|
|
254
255
|
"staged": "bun scripts/staged.ts",
|
|
255
256
|
"tegami": "bun scripts/tegami.mts"
|
package/src/cli/find.ts
CHANGED
|
@@ -140,7 +140,11 @@ export async function fromProject<T>(...names: string[]): Promise<T> {
|
|
|
140
140
|
const project = createRequire(join(process.cwd(), 'package.json'));
|
|
141
141
|
for (const name of names) {
|
|
142
142
|
try {
|
|
143
|
-
|
|
143
|
+
const module = (await import(pathToFileURL(project.resolve(name)).href)) as Record<string, unknown>;
|
|
144
|
+
// A CommonJS package whose exports Node can't name, as playwright-core's `module.exports = require(…)`, has
|
|
145
|
+
// them on `default` alone.
|
|
146
|
+
const exported = module.default;
|
|
147
|
+
return (typeof exported === 'object' && exported !== null ? { ...exported, ...module } : module) as T;
|
|
144
148
|
} catch {
|
|
145
149
|
// Not this one: the next name.
|
|
146
150
|
}
|
package/src/cli/frame.ts
CHANGED
|
@@ -44,15 +44,18 @@ export async function run(ref: string, values: { nth: string; at?: string[]; eve
|
|
|
44
44
|
|
|
45
45
|
const playwright = await fromProject<{ chromium: typeof chromium }>('playwright-core', 'playwright');
|
|
46
46
|
let browser: Browser | undefined;
|
|
47
|
+
// Why each browser didn't launch, said where none did.
|
|
48
|
+
const tried: string[] = [];
|
|
47
49
|
for (const channel of [undefined, 'chrome', 'msedge']) {
|
|
48
50
|
try {
|
|
49
51
|
browser = await playwright.chromium.launch(channel === undefined ? {} : { channel });
|
|
50
52
|
break;
|
|
51
|
-
} catch {
|
|
52
|
-
|
|
53
|
+
} catch (e) {
|
|
54
|
+
tried.push(`${channel ?? "Playwright's Chromium"}: ${(e instanceof Error ? e.message : String(e)).split('\n', 1)[0]}`);
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
|
-
if (browser === undefined)
|
|
57
|
+
if (browser === undefined)
|
|
58
|
+
fail(`No Chromium to launch (${tried.join('; ')}): npx playwright install chromium, or install Chrome or Edge.`);
|
|
56
59
|
try {
|
|
57
60
|
// `bare`: the replay alone, at the recorded size, so a window that size shows it 1:1.
|
|
58
61
|
const view = await browser.newPage({ viewport: kept.viewport });
|
package/src/cli/task.ts
CHANGED
|
@@ -35,7 +35,16 @@ export function run(id: string, values: { out?: string }): void {
|
|
|
35
35
|
['deictic.source', (v) => `Source: ${at?.replace(/:\d+$/, '') ?? '?'} ← ${v} (a shared component's change is usually at the next)`],
|
|
36
36
|
['deictic.url', (v) => v],
|
|
37
37
|
['deictic.viewport', (v) => `Viewport ${v}`],
|
|
38
|
-
[
|
|
38
|
+
[
|
|
39
|
+
'deictic.count',
|
|
40
|
+
(v) => {
|
|
41
|
+
if (v === '1') return undefined;
|
|
42
|
+
const nth = label('deictic.nth');
|
|
43
|
+
const text = label('deictic.text');
|
|
44
|
+
const which = nth === undefined ? '' : `: it's number ${nth}${text === undefined ? '' : `, saying "${text}"`}`;
|
|
45
|
+
return `${v} elements on the page come from that line${which}`;
|
|
46
|
+
},
|
|
47
|
+
],
|
|
39
48
|
[
|
|
40
49
|
'deictic.point',
|
|
41
50
|
// Circled only in a shot taken as the task went, which no label tells from one drawn on before.
|
|
@@ -50,12 +59,19 @@ export function run(id: string, values: { out?: string }): void {
|
|
|
50
59
|
const line = value === undefined ? undefined : say(value);
|
|
51
60
|
if (line !== undefined) console.log(line);
|
|
52
61
|
}
|
|
53
|
-
|
|
62
|
+
const problem = label('deictic.problem.kind');
|
|
63
|
+
if (problem !== undefined) {
|
|
64
|
+
const plugin = label('deictic.problem.plugin');
|
|
65
|
+
console.log(
|
|
66
|
+
`A problem deictic ${label('deictic.version') ?? ''} reported${plugin === undefined ? '' : ` in its ${plugin} plugin`}, not a person's ask`,
|
|
67
|
+
);
|
|
68
|
+
} else if (at === undefined) {
|
|
54
69
|
console.log("About the page as a whole: no element was attached, so find it from the words, the page's URL and the screenshot");
|
|
70
|
+
}
|
|
55
71
|
for (const line of drawn(root)) console.log(line);
|
|
56
|
-
// A task added before these were labels says them after its words.
|
|
72
|
+
// A task added before these were labels says them after its words; a problem, its details.
|
|
57
73
|
const told = (pointed ? where.slice(0, pointed.index) : where).trim();
|
|
58
|
-
if (told !== '') console.log(told);
|
|
74
|
+
if (told !== '') console.log(problem === undefined ? told : `Details:\n${told}`);
|
|
59
75
|
if (pointed) console.log(`\nPointed at, inside it: ${pointed[1]}\n ${pointed[2]}`);
|
|
60
76
|
const path = label('deictic.pointed');
|
|
61
77
|
if (path !== undefined) {
|
package/src/cli/watch.ts
CHANGED
|
@@ -104,7 +104,9 @@ export function run(channel: string, values: { idle: string; once?: boolean; lab
|
|
|
104
104
|
const at = label('deictic.at');
|
|
105
105
|
const page = label('deictic.page');
|
|
106
106
|
const project = label('deictic.project');
|
|
107
|
-
|
|
107
|
+
const problem = label('deictic.problem.kind');
|
|
108
|
+
const what = problem === undefined ? '' : `deictic's own ${problem === 'bug' ? 'bug' : 'setup problem'}, `;
|
|
109
|
+
return `${what}"${first(text)}"${at ? ` at ${at}` : ''}${page ? ` on ${page}` : ''}${project ? ` in ${project}` : ''}`;
|
|
108
110
|
};
|
|
109
111
|
|
|
110
112
|
// A board nothing has posted to yet has no channel, and won't list or follow one it hasn't: made here, as the first
|
package/src/client/index.ts
CHANGED
|
@@ -8,7 +8,18 @@
|
|
|
8
8
|
* Everything drawn sits in one shadow root, so neither the page's styles nor ours cross over. A
|
|
9
9
|
* panel's undo and redo are its tab's on its element: the latest change that plugin made there.
|
|
10
10
|
*/
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
ClientContext,
|
|
13
|
+
ClientPlugin,
|
|
14
|
+
LightboxItem,
|
|
15
|
+
PanelContext,
|
|
16
|
+
Point,
|
|
17
|
+
Problem,
|
|
18
|
+
Resumed,
|
|
19
|
+
Spot,
|
|
20
|
+
Standalone,
|
|
21
|
+
Target,
|
|
22
|
+
} from '#src/index.ts';
|
|
12
23
|
import { gestureOf, type Shortcut } from '#src/shortcut.ts';
|
|
13
24
|
|
|
14
25
|
import { dropAway, keepAway, keptAway } from './away.ts';
|
|
@@ -216,6 +227,13 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
216
227
|
const apis = new Map<string, unknown>();
|
|
217
228
|
const send: Send =
|
|
218
229
|
server === undefined ? (url, init) => fetch(url, init) : async (url, init) => server(new Request(new URL(url, location.href), init));
|
|
230
|
+
// To the dev server, which says it and hands it on (to the board, with tasks). Whether it got there is no one's to
|
|
231
|
+
// know in the page: it's said in the console too.
|
|
232
|
+
const report = (problem: Problem) => {
|
|
233
|
+
console.error(`deictic${problem.plugin === undefined ? '' : `/${problem.plugin}`}: ${problem.message}`);
|
|
234
|
+
const init = { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(problem) };
|
|
235
|
+
send(`${base}__deictic/problem`, init).catch(() => {});
|
|
236
|
+
};
|
|
219
237
|
const optionsOf = new Map(given.map(({ plugin, options }) => [plugin.name, options]));
|
|
220
238
|
const contextOf = (name: string): ClientContext => ({
|
|
221
239
|
base,
|
|
@@ -223,6 +241,7 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
223
241
|
options: optionsOf.get(name),
|
|
224
242
|
use: (other) => apis.get(other) as never,
|
|
225
243
|
request: (route, init) => send(`${base}__deictic/plugins/${name}/${route}`, init),
|
|
244
|
+
report: (problem) => report({ ...problem, plugin: name }),
|
|
226
245
|
// Not from under something unsaved, which a press on the page wouldn't close either: its button shakes.
|
|
227
246
|
open: (plugin, element, at) => panel?.guard() !== true && openAt(plugin, element, at),
|
|
228
247
|
lightbox: (items, options) => openLightbox(root, items, options),
|
|
@@ -240,7 +259,7 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
240
259
|
apis.set(plugin.name, plugin.setup(contextOf(plugin.name)));
|
|
241
260
|
} catch (e) {
|
|
242
261
|
// One plugin's failure is no reason to take the others down with it.
|
|
243
|
-
|
|
262
|
+
report(failed(plugin.name, 'set up in the page, so it does nothing there until the page loads again', e));
|
|
244
263
|
}
|
|
245
264
|
}
|
|
246
265
|
const tabs: Tab[] = given.flatMap(({ plugin }) => (plugin.mount === undefined ? [] : [{ plugin, mount: plugin.mount }]));
|
|
@@ -317,7 +336,7 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
317
336
|
try {
|
|
318
337
|
return plugin.pointing === undefined ? [] : [plugin.pointing(contextOf(plugin.name))];
|
|
319
338
|
} catch (e) {
|
|
320
|
-
|
|
339
|
+
report(failed(plugin.name, 'show what it has on the page as it was pointed at', e));
|
|
321
340
|
return [];
|
|
322
341
|
}
|
|
323
342
|
});
|
|
@@ -735,46 +754,51 @@ function openPanel({
|
|
|
735
754
|
say('');
|
|
736
755
|
const back = current === first ? resumed : undefined;
|
|
737
756
|
resumed = undefined;
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
(
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
757
|
+
try {
|
|
758
|
+
cleanup = mount(body, {
|
|
759
|
+
...contextOf(plugin.name),
|
|
760
|
+
...(back === undefined ? {} : { resumed: back }),
|
|
761
|
+
away: (state, task) => {
|
|
762
|
+
const tab = current;
|
|
763
|
+
done(true);
|
|
764
|
+
// For the tab's next page too, should this one go before the task is done. Not one a page pinned: that's the page's own.
|
|
765
|
+
if (!pinned) keepAway({ tab: tab.plugin.name, target, state, ...(spot === undefined ? {} : { at: spot }) });
|
|
766
|
+
const back = (resumed: Resumed) => {
|
|
767
|
+
if (!pinned) dropAway();
|
|
768
|
+
reopen(tab, element, resumed);
|
|
769
|
+
};
|
|
770
|
+
void task().then(
|
|
771
|
+
(result) => back({ state, result }),
|
|
772
|
+
(e: unknown) => back({ state, problem: messageOf(e) }),
|
|
773
|
+
);
|
|
774
|
+
},
|
|
775
|
+
element,
|
|
776
|
+
...(pointed === undefined ? {} : { pointed }),
|
|
777
|
+
...(spot === undefined ? {} : { at: spot }),
|
|
778
|
+
elements: sameAs(element),
|
|
779
|
+
target,
|
|
780
|
+
model,
|
|
781
|
+
apply: async (op, on = target) => {
|
|
782
|
+
say('Writing…');
|
|
783
|
+
try {
|
|
784
|
+
const result = await post<{ model: unknown }>('apply', { plugin: plugin.name, target: on, op });
|
|
785
|
+
say('');
|
|
786
|
+
void steps();
|
|
787
|
+
return result.model;
|
|
788
|
+
} catch (e) {
|
|
789
|
+
say(messageOf(e), true);
|
|
790
|
+
throw e;
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
close: () => done(),
|
|
794
|
+
unsaved: (action) => {
|
|
795
|
+
if (read === reads) holding = action;
|
|
796
|
+
},
|
|
797
|
+
});
|
|
798
|
+
} catch (e) {
|
|
799
|
+
say(messageOf(e), true);
|
|
800
|
+
contextOf(plugin.name).report(failed(plugin.name, 'show its panel', e));
|
|
801
|
+
}
|
|
778
802
|
};
|
|
779
803
|
const show = (tab: Tab) => {
|
|
780
804
|
current = tab;
|
|
@@ -967,3 +991,12 @@ function button(text: string, title: string): HTMLButtonElement {
|
|
|
967
991
|
}
|
|
968
992
|
|
|
969
993
|
const messageOf = (e: unknown) => (e instanceof Error ? e.message : String(e));
|
|
994
|
+
|
|
995
|
+
/** A plugin's page half that threw: a bug of the plugin's, to report where it's made. Its key is the first line of what it threw. */
|
|
996
|
+
const failed = (plugin: string, what: string, e: unknown): Problem => ({
|
|
997
|
+
key: `page:${plugin}:${what.split(' ', 1)[0]}:${messageOf(e).split('\n', 1)[0]!.slice(0, 200)}`,
|
|
998
|
+
kind: 'bug',
|
|
999
|
+
plugin,
|
|
1000
|
+
message: `${plugin} failed to ${what}: ${messageOf(e)}`,
|
|
1001
|
+
...(e instanceof Error && e.stack !== undefined ? { details: e.stack } : {}),
|
|
1002
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -81,6 +81,30 @@ export interface Done<Record = unknown> {
|
|
|
81
81
|
|
|
82
82
|
type Maybe<T> = T | Promise<T>;
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Something of deictic's that went wrong, which nothing a person did in the page caused: a package the project
|
|
86
|
+
* hasn't installed, a plugin that failed. The dev server says it, and hands it to each plugin with a `problem`
|
|
87
|
+
* (tasks posts it to the board, for an agent to fix).
|
|
88
|
+
*/
|
|
89
|
+
export interface Problem {
|
|
90
|
+
/**
|
|
91
|
+
* What tells it apart, and the same problem again from a new one: `packages:rrweb`, `setup:tailwind`. Never a
|
|
92
|
+
* time or an ID, so a problem that comes back is known.
|
|
93
|
+
*/
|
|
94
|
+
key: string;
|
|
95
|
+
/**
|
|
96
|
+
* `setup`: the project's to fix, as `message` says (install a package, configure a plugin). `bug`: deictic's own, or
|
|
97
|
+
* a plugin's, to report where it's made, not to patch where it's installed.
|
|
98
|
+
*/
|
|
99
|
+
kind: 'setup' | 'bug';
|
|
100
|
+
/** What went wrong, and the fix where there is one, as any problem message says it. */
|
|
101
|
+
message: string;
|
|
102
|
+
/** What more there is to look into: a stack. */
|
|
103
|
+
details?: string;
|
|
104
|
+
/** The plugin it's about, where it's one's: none for deictic's own. */
|
|
105
|
+
plugin?: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
84
108
|
/**
|
|
85
109
|
* Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:
|
|
86
110
|
* `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.
|
|
@@ -99,10 +123,12 @@ export interface ServerContext {
|
|
|
99
123
|
/** The project's root, as an absolute path. */
|
|
100
124
|
root: string;
|
|
101
125
|
/**
|
|
102
|
-
* Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded
|
|
103
|
-
* `needs` always is; any other may not be, so check.
|
|
126
|
+
* Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded (or its `setup` failed,
|
|
127
|
+
* which is reported). One the plugin `needs` always is loaded; any other may not be, so check.
|
|
104
128
|
*/
|
|
105
129
|
use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;
|
|
130
|
+
/** Says a problem of the plugin's own, as deictic says its own: in the dev server's output, and to each plugin's `problem`. */
|
|
131
|
+
report: (problem: Problem) => void;
|
|
106
132
|
}
|
|
107
133
|
|
|
108
134
|
/**
|
|
@@ -148,6 +174,11 @@ export interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, A
|
|
|
148
174
|
redo?(record: Record): Maybe<Record>;
|
|
149
175
|
/** Says what an op does, for the history: `className: px-2 → px-4`. */
|
|
150
176
|
describe?(op: Op, before: Model): string;
|
|
177
|
+
/**
|
|
178
|
+
* Hears each problem deictic or a plugin reports, on the server or in the page, after every `setup` has run: once
|
|
179
|
+
* per `key` while the dev server runs. Its own failure is only said, never reported again.
|
|
180
|
+
*/
|
|
181
|
+
problem?(problem: Problem): Maybe<void>;
|
|
151
182
|
}
|
|
152
183
|
|
|
153
184
|
export const definePlugin = <Model, Op, Record = unknown, Api = unknown>(
|
|
@@ -249,6 +280,8 @@ export interface ClientContext {
|
|
|
249
280
|
use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;
|
|
250
281
|
/** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */
|
|
251
282
|
request: (route: string, init?: RequestInit) => Promise<Response>;
|
|
283
|
+
/** Says a problem of the plugin's own to the dev server, as the server half's `report` does: its `plugin` is this one. */
|
|
284
|
+
report: (problem: Problem) => void;
|
|
252
285
|
/**
|
|
253
286
|
* Opens the popup on an element at a plugin's tab, as its shortcut would, or with `at` on a spot in it: the
|
|
254
287
|
* popup is then beside the spot, which is what's lit, and the tab's context has it. An element rendered again
|
|
@@ -87,7 +87,7 @@ const clock = (ms: number) => {
|
|
|
87
87
|
|
|
88
88
|
export default defineClientPlugin<never, never, Recorder>({
|
|
89
89
|
name: 'recordings',
|
|
90
|
-
setup: ({ base, root, options, use, request, tools, tray, drawer, lightbox }) => {
|
|
90
|
+
setup: ({ base, root, options, use, request, report, tools, tray, drawer, lightbox }) => {
|
|
91
91
|
const { masking, canvas } = options as { masking: ResolvedMasking; canvas?: false | { fps: number } };
|
|
92
92
|
let running: Promise<Recording | undefined> | undefined;
|
|
93
93
|
|
|
@@ -146,7 +146,13 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
146
146
|
// A page that carries a recording on made requests before this: those of its load are the recording's too.
|
|
147
147
|
?.plugin({ sinceLoad: from !== undefined })
|
|
148
148
|
.catch((e: unknown) => {
|
|
149
|
-
|
|
149
|
+
const why = e instanceof Error ? e.message : String(e);
|
|
150
|
+
report({
|
|
151
|
+
key: `page:recordings:${name}:${why.split('\n', 1)[0]!.slice(0, 200)}`,
|
|
152
|
+
kind: 'setup',
|
|
153
|
+
message: `recordings go without ${name}, as it couldn't be loaded: install what it needs (\`deictic init\` does), then load the page again: ${why}`,
|
|
154
|
+
...(e instanceof Error && e.stack !== undefined ? { details: e.stack } : {}),
|
|
155
|
+
});
|
|
150
156
|
return undefined;
|
|
151
157
|
});
|
|
152
158
|
const [rrweb, id, ...extras] = await Promise.all([
|
|
@@ -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
|
+
}
|
|
@@ -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. */
|
|
@@ -98,7 +99,9 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
|
|
|
98
99
|
await page.route(host, (route) => route.fulfill({ contentType: 'text/html', body: HOST }));
|
|
99
100
|
await page.goto(host);
|
|
100
101
|
await page.addScriptTag({ path: bundle() });
|
|
101
|
-
|
|
102
|
+
// The shot, and the attribute that sizes each canvas's picture, which the page's code can't import.
|
|
103
|
+
const given = { ...shot, size: CANVAS_SIZE };
|
|
104
|
+
const found = await page.evaluate(async ({ snapshot, scroll, overlay, element, size }) => {
|
|
102
105
|
const { rebuildIntoSandboxedIframe, createCache, createMirror } = (globalThis as unknown as { rrwebSnapshot: typeof Rrweb })
|
|
103
106
|
.rrwebSnapshot;
|
|
104
107
|
const mirror = createMirror();
|
|
@@ -110,20 +113,44 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
|
|
|
110
113
|
});
|
|
111
114
|
const doc = iframe.contentDocument;
|
|
112
115
|
if (doc === null) throw new Error('screenshots: the snapshot was rebuilt where it cannot be read');
|
|
116
|
+
// By its kind: the iframe's elements aren't instances of this page's `Element`.
|
|
117
|
+
const isElement = (node: Node | null): node is Element => node?.nodeType === 1;
|
|
118
|
+
// rrweb rebuilds a script as a `noscript` holding SCRIPT_PLACEHOLDER, which the sandbox, running no scripts,
|
|
119
|
+
// shows: hidden, as rrweb's own replayer hides it.
|
|
120
|
+
const hidden = doc.createElement('style');
|
|
121
|
+
hidden.textContent = 'noscript { display: none !important; }';
|
|
122
|
+
doc.head.append(hidden);
|
|
123
|
+
// The sandbox runs no scripts, and where scripts don't run, a canvas shows what's inside the canvas instead of
|
|
124
|
+
// what was drawn on the canvas: so each canvas's picture goes inside the canvas, at the size the page laid the
|
|
125
|
+
// canvas out at. rrweb's own drawing of the picture on the canvas never shows.
|
|
126
|
+
for (const canvas of doc.querySelectorAll(`canvas[${size}]`)) {
|
|
127
|
+
const meta = mirror.getMeta(canvas);
|
|
128
|
+
const [box, inline] = (canvas.getAttribute(size) ?? '').split(' ');
|
|
129
|
+
const [width, height] = (box ?? '').split('x');
|
|
130
|
+
if (meta === null || !('attributes' in meta) || typeof meta.attributes.rr_dataURL !== 'string') continue;
|
|
131
|
+
const picture = doc.createElement('img');
|
|
132
|
+
picture.src = meta.attributes.rr_dataURL;
|
|
133
|
+
// In a line as the canvas was, else the whole of the canvas's box.
|
|
134
|
+
picture.style.cssText = `display:${inline === undefined ? 'block' : 'inline'};width:${width}px;height:${height}px`;
|
|
135
|
+
canvas.replaceChildren(picture);
|
|
136
|
+
}
|
|
113
137
|
await doc.fonts.ready;
|
|
114
138
|
await Promise.all([...doc.images].map((img) => img.decode().catch(() => {})));
|
|
115
|
-
|
|
139
|
+
// At once: a page with `scroll-behavior: smooth` would glide there, and be shot on its way.
|
|
140
|
+
iframe.contentWindow?.scrollTo({ left: scroll.x, top: scroll.y, behavior: 'instant' });
|
|
116
141
|
// rrweb scrolled each element as it built it, before the fonts and images gave its content its height:
|
|
117
142
|
// one that couldn't scroll that far yet is scrolled again now.
|
|
118
|
-
// By its kind: the iframe's elements aren't instances of this page's `Element`.
|
|
119
|
-
const isElement = (node: Node | null): node is Element => node?.nodeType === 1;
|
|
120
143
|
for (const id of mirror.getIds()) {
|
|
121
144
|
const node = mirror.getNode(id);
|
|
122
145
|
const meta = node === null ? null : mirror.getMeta(node);
|
|
123
146
|
if (!isElement(node) || meta === null || !('attributes' in meta)) continue;
|
|
124
147
|
const { rr_scrollTop: top, rr_scrollLeft: left } = meta.attributes;
|
|
125
|
-
if (typeof top
|
|
126
|
-
|
|
148
|
+
if (typeof top !== 'number' && typeof left !== 'number') continue;
|
|
149
|
+
node.scrollTo({
|
|
150
|
+
top: typeof top === 'number' ? top : node.scrollTop,
|
|
151
|
+
left: typeof left === 'number' ? left : node.scrollLeft,
|
|
152
|
+
behavior: 'instant',
|
|
153
|
+
});
|
|
127
154
|
}
|
|
128
155
|
const node = element === undefined ? null : mirror.getNode(element);
|
|
129
156
|
// The iframe fills the page from its top left, so a box in it is one in the shot.
|
|
@@ -136,7 +163,7 @@ export async function render(input: unknown, options: BrowserOptions): Promise<{
|
|
|
136
163
|
marks.innerHTML = overlay;
|
|
137
164
|
document.body.append(marks);
|
|
138
165
|
return box;
|
|
139
|
-
},
|
|
166
|
+
}, given);
|
|
140
167
|
// Without the scrollbars: a shot is what the page is drawn in, which is what an element's box is from.
|
|
141
168
|
// A shot of the element alone is cut where the element is here.
|
|
142
169
|
const clip = clamp(shot.clip === undefined ? { x: 0, y: 0, ...shot.viewport } : (found ?? shot.clip), shot.viewport);
|
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
* And which node of the snapshot the element is, so the server says where it is in what it drew.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { CANVAS_SIZE, keepWebGLDrawing } from './canvas.ts';
|
|
8
9
|
import { boxOf, screenshotsClient } from './client.ts';
|
|
9
10
|
import type { Snapshot, SnapshotNode } from './playwright.ts';
|
|
10
11
|
|
|
12
|
+
// As the page loads, before the page makes its canvases.
|
|
13
|
+
keepWebGLDrawing();
|
|
14
|
+
|
|
11
15
|
/** The snapshot without deictic's overlay, which rrweb has no option to leave out. */
|
|
12
16
|
function withoutOurs(node: SnapshotNode): SnapshotNode {
|
|
13
17
|
if (!('childNodes' in node)) return node;
|
|
@@ -20,16 +24,33 @@ export default screenshotsClient(async (element, { area, masking, overlay }) =>
|
|
|
20
24
|
throw new Error('the rrweb() renderer needs rrweb-snapshot: add it to your devDependencies', { cause: e });
|
|
21
25
|
});
|
|
22
26
|
const mirror = createMirror();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
// In a frame, after the page drew in it: a WebGL canvas reads back blank once its frame is shown, unless the page
|
|
28
|
+
// keeps its drawing buffer, and the page's own callbacks for the frame were asked for before this one.
|
|
29
|
+
const taken = await new Promise<ReturnType<typeof snapshot>>((done) =>
|
|
30
|
+
requestAnimationFrame(() =>
|
|
31
|
+
done(
|
|
32
|
+
snapshot(document, {
|
|
33
|
+
mirror,
|
|
34
|
+
inlineStylesheet: true,
|
|
35
|
+
// A canvas as a picture of what it shows, which the server draws on the canvas it rebuilds.
|
|
36
|
+
recordCanvas: true,
|
|
37
|
+
blockClass: masking.blockClass,
|
|
38
|
+
blockSelector: masking.blockSelector ?? null,
|
|
39
|
+
maskTextClass: masking.maskTextClass,
|
|
40
|
+
maskTextSelector: masking.maskTextSelector ?? null,
|
|
41
|
+
maskAllInputs: masking.maskAllInputs,
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
);
|
|
32
46
|
if (taken === null) throw new Error('screenshots: rrweb took no snapshot of this page');
|
|
47
|
+
// Each canvas's size as the page lays it out, and whether in a line, as which the server shows the canvas's picture.
|
|
48
|
+
for (const canvas of document.querySelectorAll('canvas')) {
|
|
49
|
+
const node = mirror.getMeta(canvas);
|
|
50
|
+
if (node === null || !('attributes' in node) || typeof node.attributes.rr_dataURL !== 'string') continue;
|
|
51
|
+
const inline = getComputedStyle(canvas).display === 'inline';
|
|
52
|
+
node.attributes[CANVAS_SIZE] = `${canvas.offsetWidth}x${canvas.offsetHeight}${inline ? ' inline' : ''}`;
|
|
53
|
+
}
|
|
33
54
|
const box = boxOf(element, area);
|
|
34
55
|
const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };
|
|
35
56
|
// Over the viewport, which the server renders before cutting out an element's part.
|
|
@@ -72,9 +72,10 @@ export function tailwind(options: TailwindOptions = {}) {
|
|
|
72
72
|
const attribute = options.attribute ?? 'className';
|
|
73
73
|
// Loaded on the first ask, as it takes a moment, and once: a project without Tailwind v4 has none.
|
|
74
74
|
let loading: Promise<Catalog | undefined> | undefined;
|
|
75
|
-
const catalog = ({ root }: ServerContext) =>
|
|
75
|
+
const catalog = ({ root, report }: ServerContext) =>
|
|
76
76
|
(loading ??= loadCatalog(root, options.css).catch((problem: unknown) => {
|
|
77
|
-
|
|
77
|
+
const message = problem instanceof Error ? problem.message : String(problem);
|
|
78
|
+
report({ key: 'setup:tailwind', kind: 'setup', plugin: 'tailwind', message: `no completions or class details, as ${message}` });
|
|
78
79
|
return undefined;
|
|
79
80
|
}));
|
|
80
81
|
const asked = async (request: Request): Promise<string[]> => {
|
|
@@ -19,6 +19,7 @@ import { drawerOf } from './drawer.ts';
|
|
|
19
19
|
import type { Model, Op, TaskAdded } from './index.ts';
|
|
20
20
|
import { pinsIn } from './pins.ts';
|
|
21
21
|
import { storeOf } from './store.ts';
|
|
22
|
+
import { whichOf } from './which.ts';
|
|
22
23
|
|
|
23
24
|
const STYLE = `
|
|
24
25
|
.compose { flex: none; }
|
|
@@ -235,13 +236,16 @@ export default defineClientPlugin<Model, Op>({
|
|
|
235
236
|
if (el === undefined) return a.seen;
|
|
236
237
|
const chain = chainOf(el, a.target.loc.file);
|
|
237
238
|
const { pointed, at } = context;
|
|
239
|
+
const masked = shots?.masked(el) ?? el;
|
|
240
|
+
const alike = sameAs(el);
|
|
238
241
|
return {
|
|
239
242
|
// What was pointed at, and the spot, are the popup's own element's.
|
|
240
243
|
...(a.own && at !== undefined ? { point: at } : {}),
|
|
241
244
|
...(a.own && pointed !== undefined ? { pointed: { path: pathTo(pointed, el), html: pointed.outerHTML.slice(0, 4000) } } : {}),
|
|
242
|
-
count:
|
|
245
|
+
count: alike.length,
|
|
246
|
+
...(alike.length > 1 ? { which: whichOf(el, alike, masked) } : {}),
|
|
243
247
|
...(chain.length === 0 ? {} : { chain }),
|
|
244
|
-
html:
|
|
248
|
+
html: masked.outerHTML.slice(0, HTML),
|
|
245
249
|
};
|
|
246
250
|
};
|
|
247
251
|
/** The page the task is about: this one, or the one the panel left where none of its elements is on this one. */
|
|
@@ -326,7 +330,13 @@ export default defineClientPlugin<Model, Op>({
|
|
|
326
330
|
first === undefined
|
|
327
331
|
? 'Added, about the page: it is in the drawer'
|
|
328
332
|
: `Added${added === undefined ? '' : ` #${added.id}`}: it is in the drawer`;
|
|
329
|
-
if (added?.dropped !== undefined)
|
|
333
|
+
if (added?.dropped !== undefined) {
|
|
334
|
+
// Open, to say so: the task went without something that was attached.
|
|
335
|
+
composer.problem.textContent = `Sent without ${added.dropped}: it wasn't kept any more`;
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
// Its pin and the drawer have it now. Once the composer has emptied (the tray, the page's marks), which it does as this answers.
|
|
339
|
+
setTimeout(context.close);
|
|
330
340
|
return true;
|
|
331
341
|
},
|
|
332
342
|
});
|
|
@@ -131,7 +131,7 @@ type Pictured = Shot & { drawn?: { shot: Shot; marks: Annotation[]; about: strin
|
|
|
131
131
|
export type Sent = NonNullable<Op['screenshots']>[number] & { url: string };
|
|
132
132
|
|
|
133
133
|
/** What a task says of an element that only the page with it on knows. */
|
|
134
|
-
export interface Seen extends Pick<Op, 'point' | 'pointed' | 'count' | 'chain'> {
|
|
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
137
|
}
|
|
@@ -7,12 +7,13 @@
|
|
|
7
7
|
* which cancels it on the board.
|
|
8
8
|
*/
|
|
9
9
|
import { named, tell } from '#src/client/component.ts';
|
|
10
|
-
import {
|
|
10
|
+
import { place } from '#src/client/dom.ts';
|
|
11
11
|
import type { ClientContext, LightboxItem } from '#src/index.ts';
|
|
12
12
|
|
|
13
13
|
import { attachedOf, type Composer, COMPOSER_STYLE, composerIn, element, messageOf, PLAY } from './composer.ts';
|
|
14
14
|
import type { Answer, Attached, Listed, Thread } from './index.ts';
|
|
15
15
|
import { OVER, storeOf } from './store.ts';
|
|
16
|
+
import { elementOf } from './which.ts';
|
|
16
17
|
|
|
17
18
|
const STYLE = `
|
|
18
19
|
.tasks-drawer h3 .unread { padding: 0 6px; border-radius: 8px; font-weight: 700; letter-spacing: 0; color: var(--deictic-on-accent); background: var(--deictic-accent); }
|
|
@@ -159,10 +160,9 @@ export function drawerOf(context: ClientContext): TasksDrawer {
|
|
|
159
160
|
finished.append(finishedCount, finishedRows);
|
|
160
161
|
section.append(element('style', { textContent: STYLE }), heading, rows, finished);
|
|
161
162
|
|
|
162
|
-
const elementOf = (task: Listed) =>
|
|
163
|
-
task.place === undefined ? null : document.querySelector(`[${ATTRIBUTE}="${CSS.escape(task.place)}"]`);
|
|
164
163
|
/** What a task is about, as the caption says an element: by its component where the page has it, else its tag. */
|
|
165
164
|
const about = (task: Listed) => {
|
|
165
|
+
if (task.problem !== undefined) return task.problem === 'setup' ? "deictic's setup" : 'a bug in deictic';
|
|
166
166
|
if (task.place === undefined) return 'the page';
|
|
167
167
|
const el = elementOf(task);
|
|
168
168
|
if (el !== null) return tell(named(el));
|