deictic 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -3
- package/dist/annotations/index.d.ts +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/bun.d.ts +1 -1
- package/dist/bun.js +2 -2
- package/dist/client/index.d.ts +4 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +13 -9
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +21 -218
- package/dist/index.js.map +1 -1
- package/dist/loader.js +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +2 -2
- package/dist/recommended/index.d.ts +4 -4
- package/dist/recommended/index.js +2 -2
- package/dist/recordings/client.d.ts +1 -1
- package/dist/recordings/client.js +4 -4
- package/dist/recordings/client.js.map +1 -1
- package/dist/recordings/index.d.ts +2 -2
- package/dist/recordings/index.js +3 -3
- package/dist/screenshots/client.d.ts +1 -1
- package/dist/screenshots/client.js +2 -2
- package/dist/screenshots/client.js.map +1 -1
- package/dist/screenshots/dom.d.ts +1 -1
- package/dist/screenshots/index.d.ts +1 -1
- package/dist/screenshots/index.js +2 -2
- package/dist/screenshots/index.js.map +1 -1
- package/dist/screenshots/rrweb.d.ts +1 -1
- package/dist/{endpoints.js → shared/endpoints.js} +1 -1
- package/dist/shared/endpoints.js.map +1 -0
- package/dist/shared/index.d.ts +226 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/{index3.d.ts → shared/index2.d.ts} +1 -1
- package/dist/shared/index2.d.ts.map +1 -0
- package/dist/{index4.d.ts → shared/index3.d.ts} +15 -3
- package/dist/shared/index3.d.ts.map +1 -0
- package/dist/shared/index4.d.ts +184 -0
- package/dist/shared/index4.d.ts.map +1 -0
- package/dist/{index5.d.ts → shared/index5.d.ts} +1 -1
- package/dist/shared/index5.d.ts.map +1 -0
- package/dist/{integration.d.ts → shared/integration.d.ts} +4 -3
- package/dist/shared/integration.d.ts.map +1 -0
- package/dist/{integration.js → shared/integration.js} +5 -3
- package/dist/shared/integration.js.map +1 -0
- package/dist/{kept.js → shared/kept.js} +2 -2
- package/dist/shared/kept.js.map +1 -0
- package/dist/shared/marks.js.map +1 -0
- package/dist/shared/playwright.js.map +1 -0
- package/dist/{recordings.js → shared/recordings.js} +20 -9
- package/dist/shared/recordings.js.map +1 -0
- package/dist/shared/shortcut.js.map +1 -0
- package/dist/shared/tasks.js +521 -0
- package/dist/shared/tasks.js.map +1 -0
- package/dist/shared/waveform.js.map +1 -0
- 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 +1 -1
- package/dist/tasks/index.d.ts +2 -159
- package/dist/tasks/index.js +1 -348
- package/dist/vite.d.ts +11 -12
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +21 -4
- package/dist/vite.js.map +1 -1
- package/dist/voice/client.js +2 -2
- package/dist/voice/client.js.map +1 -1
- package/dist/voice/index.js +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
- package/skills/deictic/SKILL.md +1 -1
- package/skills/deictic/references/install.md +20 -5
- package/skills/deictic/scripts/lib.mjs +21 -3
- package/skills/deictic/scripts/watch.mjs +2 -2
- package/src/client/index.ts +20 -7
- package/src/index.ts +7 -0
- package/src/plugins/recordings/client.ts +3 -2
- package/src/plugins/recordings/index.ts +3 -2
- package/src/plugins/recordings/replay.ts +32 -6
- package/src/plugins/screenshots/client.ts +3 -2
- package/src/plugins/tasks/index.ts +52 -8
- package/src/plugins/tasks/local.ts +170 -0
- package/src/plugins/voice/client.ts +3 -2
- package/src/tools/integration.ts +5 -3
- package/src/tools/kept.ts +2 -2
- package/src/vite.ts +23 -4
- package/dist/endpoints.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index2.d.ts +0 -23
- package/dist/index3.d.ts.map +0 -1
- package/dist/index4.d.ts.map +0 -1
- package/dist/index5.d.ts.map +0 -1
- package/dist/integration.d.ts.map +0 -1
- package/dist/integration.js.map +0 -1
- package/dist/kept.js.map +0 -1
- package/dist/marks.js.map +0 -1
- package/dist/playwright.js.map +0 -1
- package/dist/recordings.js.map +0 -1
- package/dist/shortcut.js.map +0 -1
- package/dist/tasks/index.d.ts.map +0 -1
- package/dist/tasks/index.js.map +0 -1
- package/dist/waveform.js.map +0 -1
- /package/dist/{marks.js → shared/marks.js} +0 -0
- /package/dist/{playwright.js → shared/playwright.js} +0 -0
- /package/dist/{shortcut.js → shared/shortcut.js} +0 -0
- /package/dist/{waveform.js → shared/waveform.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,220 +1,23 @@
|
|
|
1
|
-
import { JSXOpeningElement, Program } from "oxc-parser";
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* `deictic`: what a plugin is. Every plugin is optional: deictic itself is the glue (the
|
|
3
|
+
* transform that ties elements to source, the dev server's endpoints, the history, shortcuts and the
|
|
4
|
+
* overlay's panel), and each plugin adds what it does on top.
|
|
5
|
+
*
|
|
6
|
+
* A plugin has two halves, each optional that meet over the dev server's endpoints (`tools/endpoints.ts`). The
|
|
7
|
+
* server half runs beside the bundler and is the only one that reads source: it turns the element
|
|
8
|
+
* under the pointer into a model its panel can show, and an op from that panel into text edits. It
|
|
9
|
+
* never writes files; deictic does, so every plugin's changes land in one history and undo the
|
|
10
|
+
* same way. A change that isn't to a file (a task added to a board) the plugin makes itself and
|
|
11
|
+
* answers with what it did (`Done`): the history keeps that beside the files' changes and hands it
|
|
12
|
+
* back to the plugin's own `undo` and `redo`.
|
|
13
|
+
* The client half is a module the page loads, named by the server half's `client`, which draws the
|
|
14
|
+
* panel and previews an op on the page before it is applied.
|
|
15
|
+
*
|
|
16
|
+
* A plugin may have no panel at all, only an API for others (screenshots, a recording) and routes of
|
|
17
|
+
* its own on the dev server. Each half's `setup` answers its API, and `use(name)` reaches another
|
|
18
|
+
* plugin's, on the same side; `needs` names the plugins it can't do without.
|
|
19
|
+
*
|
|
20
|
+
* Both halves import from here, so the parser is imported for its types only: the browser must not load it.
|
|
9
21
|
*/
|
|
10
|
-
|
|
11
|
-
type Modifier
|
|
12
|
-
interface Shortcut {
|
|
13
|
-
/** Held, and no other, to outline elements. */
|
|
14
|
-
modifiers?: Modifier[];
|
|
15
|
-
/** Pressed with them to open the panel. `'left'` unset. */
|
|
16
|
-
button?: 'left' | 'middle' | 'right';
|
|
17
|
-
}
|
|
18
|
-
/** A place in the source: the file from the project's root, with `/`, and the line and column, from 1. */
|
|
19
|
-
interface Loc {
|
|
20
|
-
file: string;
|
|
21
|
-
line: number;
|
|
22
|
-
column: number;
|
|
23
|
-
}
|
|
24
|
-
/** An element the pointer picked: where its opening tag starts, and the tag, which the server checks is still there. */
|
|
25
|
-
interface Target {
|
|
26
|
-
loc: Loc;
|
|
27
|
-
tag: string;
|
|
28
|
-
}
|
|
29
|
-
/** Text in a file to replace, by UTF-16 offsets. `file` is the target's unless named, from the project's root. */
|
|
30
|
-
interface TextEdit {
|
|
31
|
-
file?: string;
|
|
32
|
-
start: number;
|
|
33
|
-
end: number;
|
|
34
|
-
text: string;
|
|
35
|
-
}
|
|
36
|
-
/** What a server half reads: the target's file, parsed, and its element. */
|
|
37
|
-
interface Source {
|
|
38
|
-
/** The target's file, from the project's root. */
|
|
39
|
-
file: string;
|
|
40
|
-
code: string;
|
|
41
|
-
/** The file's module; for an `.astro` component, its frontmatter's. */
|
|
42
|
-
program: Program;
|
|
43
|
-
/** The target's opening tag. */
|
|
44
|
-
element: JSXOpeningElement;
|
|
45
|
-
/** Another file under the project's root, for plugins whose edits go elsewhere (a locale's messages). */
|
|
46
|
-
read(file: string): string;
|
|
47
|
-
}
|
|
48
|
-
/** An op a plugin won't make. The message says why and what to do instead; the panel shows it. */
|
|
49
|
-
declare class Refusal extends Error {
|
|
50
|
-
name: string;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* A change the plugin made itself, not to a file: what its `undo` and `redo` need to take it back and
|
|
54
|
-
* make it again. JSON, since the history keeps it on disk across restarts of the dev server.
|
|
55
|
-
*/
|
|
56
|
-
interface Done<Record = unknown> {
|
|
57
|
-
done: Record;
|
|
58
|
-
}
|
|
59
|
-
type Maybe<T> = T | Promise<T>;
|
|
60
|
-
/**
|
|
61
|
-
* Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:
|
|
62
|
-
* `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.
|
|
63
|
-
*/
|
|
64
|
-
interface ServerApis {}
|
|
65
|
-
/** The same, in the page: `declare module 'deictic' { interface ClientApis { screenshots: Capture } }`. */
|
|
66
|
-
interface ClientApis {}
|
|
67
|
-
/** A plugin's API, by its name: what its package declared, or `unknown` for one that declared none. */
|
|
68
|
-
type ApiOf<Apis, Name extends string> = Name extends keyof Apis ? Apis[Name] : unknown;
|
|
69
|
-
interface ServerContext {
|
|
70
|
-
/** The project's root, as an absolute path. */
|
|
71
|
-
root: string;
|
|
72
|
-
/**
|
|
73
|
-
* Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded. One the plugin
|
|
74
|
-
* `needs` always is; any other may not be, so check.
|
|
75
|
-
*/
|
|
76
|
-
use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must
|
|
80
|
-
* change nothing: anything else reaches it only from the page itself, which deictic checks.
|
|
81
|
-
*/
|
|
82
|
-
type Route = (request: Request, context: ServerContext) => Maybe<Response>;
|
|
83
|
-
interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = unknown> {
|
|
84
|
-
/** Ties the halves together; also the label of its changes in the history, and its routes' path. Lowercase, with `-`. */
|
|
85
|
-
name: string;
|
|
86
|
-
/** The module the page loads for this plugin's half there, which default-exports its `ClientPlugin`. */
|
|
87
|
-
client?: string;
|
|
88
|
-
/** What the page half gets as `context.options`: the user's options it needs there, as JSON. */
|
|
89
|
-
clientOptions?: unknown;
|
|
90
|
-
/** What opens its panel: its own default, which its options let the user change. A plugin with no panel has none. */
|
|
91
|
-
shortcut?: Shortcut;
|
|
92
|
-
/** The plugins it can't do without, by name: the dev server won't start without them. */
|
|
93
|
-
needs?: string[];
|
|
94
|
-
/** Runs once, as the dev server starts and before it answers anything. Answers the plugin's API to the others. */
|
|
95
|
-
setup?(context: ServerContext): Maybe<Api>;
|
|
96
|
-
/** Routes of its own, by their first segment under `/__deictic/plugins/<name>/`. */
|
|
97
|
-
routes?: {
|
|
98
|
-
[route: string]: Route;
|
|
99
|
-
};
|
|
100
|
-
/** The model its panel shows for an element. Without it, the panel gets none. */
|
|
101
|
-
read?(source: Source, target: Target): Maybe<Model>;
|
|
102
|
-
/** Text edits for deictic to write, or a change the plugin made itself. */
|
|
103
|
-
apply?(source: Source, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;
|
|
104
|
-
/**
|
|
105
|
-
* Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may
|
|
106
|
-
* answer what the next redo needs, where that differs (what it put back has a new ID).
|
|
107
|
-
*/
|
|
108
|
-
undo?(record: Record): Maybe<void | Record>;
|
|
109
|
-
/** Makes it again after an undo, and answers what the next undo needs, which may differ (a new ID). */
|
|
110
|
-
redo?(record: Record): Maybe<Record>;
|
|
111
|
-
/** Says what an op does, for the history: `className: px-2 → px-4`. */
|
|
112
|
-
describe?(op: Op, before: Model): string;
|
|
113
|
-
}
|
|
114
|
-
declare const definePlugin: <Model, Op, Record = unknown, Api = unknown>(plugin: ServerPlugin<Model, Op, Record, Api>) => ServerPlugin<Model, Op, Record, Api>;
|
|
115
|
-
interface ClientContext {
|
|
116
|
-
/** The dev server's base URL, ending in `/`. */
|
|
117
|
-
base: string;
|
|
118
|
-
/** deictic's shadow root, to draw in: neither the page's styles nor the overlay's cross over. */
|
|
119
|
-
root: ShadowRoot;
|
|
120
|
-
/** The server half's `clientOptions`, or nothing. */
|
|
121
|
-
options: unknown;
|
|
122
|
-
/** Another plugin's API in the page, as its `setup` answered it, or nothing when it isn't loaded. */
|
|
123
|
-
use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;
|
|
124
|
-
/** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */
|
|
125
|
-
request: (route: string, init?: RequestInit) => Promise<Response>;
|
|
126
|
-
/**
|
|
127
|
-
* Opens the popup on an element at a plugin's tab, as its shortcut would: after a recording, say. An
|
|
128
|
-
* element rendered again since stands in for one no longer on the page. False when there's no such tab
|
|
129
|
-
* or no such element any more. Not from `setup`, which runs before the popup can open.
|
|
130
|
-
*/
|
|
131
|
-
open: (plugin: string, element: Element) => boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Shows `items` in the lightbox over everything, at `at` (the first by default), stepping between them with
|
|
134
|
-
* ← and →. With `from`, it grows out of that element (the chip clicked) and shrinks back into it on close.
|
|
135
|
-
*/
|
|
136
|
-
lightbox: (items: LightboxItem[], options?: LightboxOptions) => {
|
|
137
|
-
close: () => void;
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
/** What the lightbox shows: a picture, a page in a frame (a recording's replay), or a sound with its waveform. */
|
|
141
|
-
type LightboxItem = {
|
|
142
|
-
/** Its name, over it. */
|
|
143
|
-
title: string;
|
|
144
|
-
/** Buttons beside the name: each closes the lightbox and runs. */
|
|
145
|
-
actions?: LightboxAction[];
|
|
146
|
-
} & ({
|
|
147
|
-
kind: 'image';
|
|
148
|
-
url: string;
|
|
149
|
-
} | {
|
|
150
|
-
kind: 'page';
|
|
151
|
-
url: string;
|
|
152
|
-
} | {
|
|
153
|
-
kind: 'audio';
|
|
154
|
-
url: string;
|
|
155
|
-
});
|
|
156
|
-
interface LightboxAction {
|
|
157
|
-
label: string;
|
|
158
|
-
title?: string;
|
|
159
|
-
run: () => void;
|
|
160
|
-
}
|
|
161
|
-
interface LightboxOptions {
|
|
162
|
-
/** The item it opens at. */
|
|
163
|
-
at?: number;
|
|
164
|
-
/** The element it grows out of, and goes back into. */
|
|
165
|
-
from?: Element;
|
|
166
|
-
}
|
|
167
|
-
interface PanelContext<Model, Op> extends ClientContext {
|
|
168
|
-
/** The element clicked: the one the source marked, under the pointer or around what is. */
|
|
169
|
-
element: Element;
|
|
170
|
-
/**
|
|
171
|
-
* What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a
|
|
172
|
-
* dependency's, or in an open shadow root, as the popup's own on a page that shows it (`popupIn`).
|
|
173
|
-
*/
|
|
174
|
-
pointed?: Element;
|
|
175
|
-
/** Every element on the page from the same place in the source, the clicked one among them: the rows of a list. */
|
|
176
|
-
elements: Element[];
|
|
177
|
-
target: Target;
|
|
178
|
-
model: Model;
|
|
179
|
-
/** Applies an op on disk, and reads the model again. Rejects with the server's reason, which the panel also shows. */
|
|
180
|
-
apply(op: Op): Promise<Model>;
|
|
181
|
-
close: () => void;
|
|
182
|
-
/**
|
|
183
|
-
* Says there's something here that leaving would lose (words typed, a change tried on the page), and the button
|
|
184
|
-
* that keeps it: a click outside the popup then shakes that button, where it would have closed the popup.
|
|
185
|
-
* `undefined` once there's nothing to lose. Forgotten as the panel unmounts.
|
|
186
|
-
*/
|
|
187
|
-
unsaved: (action: HTMLElement | undefined) => void;
|
|
188
|
-
/**
|
|
189
|
-
* Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a
|
|
190
|
-
* pick of another element), and opens it again at this tab on this element. The next mount gets
|
|
191
|
-
* `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why
|
|
192
|
-
* it failed. The state stays in the page, as it is: no need for JSON.
|
|
193
|
-
*/
|
|
194
|
-
away: <T>(state: unknown, task: () => Promise<T>) => void;
|
|
195
|
-
/** Set when this mount is the panel coming back from `away`. */
|
|
196
|
-
resumed?: Resumed;
|
|
197
|
-
}
|
|
198
|
-
/** What a panel coming back from `away` gets: the state it kept, and the task's result or problem. */
|
|
199
|
-
interface Resumed {
|
|
200
|
-
state: unknown;
|
|
201
|
-
result?: unknown;
|
|
202
|
-
/** Why the task failed: its error's message. */
|
|
203
|
-
problem?: string;
|
|
204
|
-
}
|
|
205
|
-
interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {
|
|
206
|
-
/** The server half's `name`. */
|
|
207
|
-
name: string;
|
|
208
|
-
/** Shown over the element while its shortcut's keys are held, and atop the panel. */
|
|
209
|
-
label?: string;
|
|
210
|
-
/**
|
|
211
|
-
* Runs once, as the page starts, before any panel opens (a recording starts here). Answers the
|
|
212
|
-
* plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.
|
|
213
|
-
*/
|
|
214
|
-
setup?(context: ClientContext): Api;
|
|
215
|
-
/** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */
|
|
216
|
-
mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;
|
|
217
|
-
}
|
|
218
|
-
declare const defineClientPlugin: <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>) => ClientPlugin<Model, Op, Api>;
|
|
219
|
-
export { Shortcut as C, Modifier as S, Source as _, Done as a, defineClientPlugin as b, LightboxOptions as c, Refusal as d, Resumed as f, ServerPlugin as g, ServerContext as h, ClientPlugin as i, Loc as l, ServerApis as m, ClientApis as n, LightboxAction as o, Route as p, ClientContext as r, LightboxItem as s, ApiOf as t, PanelContext as u, Target as v, definePlugin as x, TextEdit as y };
|
|
220
|
-
//# sourceMappingURL=index.d.ts.map
|
|
22
|
+
import { C as Modifier, S as definePlugin, _ as Source, a as Done, b as TextEdit, c as LightboxOptions, d as Refusal, f as Resumed, g as ServerPlugin, h as ServerContext, i as ClientPlugin, l as Loc, m as ServerApis, n as ClientApis, o as LightboxAction, p as Route, r as ClientContext, s as LightboxItem, t as ApiOf, u as PanelContext, v as Standalone, w as Shortcut, x as defineClientPlugin, y as Target } from "./shared/index.js";
|
|
23
|
+
export { ApiOf, ClientApis, ClientContext, ClientPlugin, Done, LightboxAction, LightboxItem, LightboxOptions, Loc, type Modifier, PanelContext, Refusal, Resumed, Route, ServerApis, ServerContext, ServerPlugin, type Shortcut, Source, Standalone, Target, TextEdit, defineClientPlugin, definePlugin };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `deictic`: what a plugin is. Every plugin is optional: deictic itself is the glue (the\n * transform that ties elements to source, the dev server's endpoints, the history, shortcuts and the\n * overlay's panel), and each plugin adds what it does on top.\n *\n * A plugin has two halves, each optional that meet over the dev server's endpoints (`tools/endpoints.ts`). The\n * server half runs beside the bundler and is the only one that reads source: it turns the element\n * under the pointer into a model its panel can show, and an op from that panel into text edits. It\n * never writes files; deictic does, so every plugin's changes land in one history and undo the\n * same way. A change that isn't to a file (a task added to a board) the plugin makes itself and\n * answers with what it did (`Done`): the history keeps that beside the files' changes and hands it\n * back to the plugin's own `undo` and `redo`.\n * The client half is a module the page loads, named by the server half's `client`, which draws the\n * panel and previews an op on the page before it is applied.\n *\n * A plugin may have no panel at all, only an API for others (screenshots, a recording) and routes of\n * its own on the dev server. Each half's `setup` answers its API, and `use(name)` reaches another\n * plugin's, on the same side; `needs` names the plugins it can't do without.\n *\n * Both halves import from here, so the parser is imported for its types only: the browser must not load it.\n */\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport type { Shortcut } from './shortcut.ts';\n\nexport type { Modifier, Shortcut } from './shortcut.ts';\n\n/** A place in the source: the file from the project's root, with `/`, and the line and column, from 1. */\nexport interface Loc {\n file: string;\n line: number;\n column: number;\n}\n\n/** An element the pointer picked: where its opening tag starts, and the tag, which the server checks is still there. */\nexport interface Target {\n loc: Loc;\n tag: string;\n}\n\n/** Text in a file to replace, by UTF-16 offsets. `file` is the target's unless named, from the project's root. */\nexport interface TextEdit {\n file?: string;\n start: number;\n end: number;\n text: string;\n}\n\n/** What a server half reads: the target's file, parsed, and its element. */\nexport interface Source {\n /** The target's file, from the project's root. */\n file: string;\n code: string;\n /** The file's module; for an `.astro` component, its frontmatter's. */\n program: Program;\n /** The target's opening tag. */\n element: JSXOpeningElement;\n /** Another file under the project's root, for plugins whose edits go elsewhere (a locale's messages). */\n read(file: string): string;\n}\n\n/** An op a plugin won't make. The message says why and what to do instead; the panel shows it. */\nexport class Refusal extends Error {\n override name = 'Refusal';\n}\n\n/**\n * A change the plugin made itself, not to a file: what its `undo` and `redo` need to take it back and\n * make it again. JSON, since the history keeps it on disk across restarts of the dev server.\n */\nexport interface Done<Record = unknown> {\n done: Record;\n}\n\ntype Maybe<T> = T | Promise<T>;\n\n/**\n * Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:\n * `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.\n */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ServerApis {}\n\n/** The same, in the page: `declare module 'deictic' { interface ClientApis { screenshots: Capture } }`. */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ClientApis {}\n\n/** A plugin's API, by its name: what its package declared, or `unknown` for one that declared none. */\nexport type ApiOf<Apis, Name extends string> = Name extends keyof Apis ? Apis[Name] : unknown;\n\nexport interface ServerContext {\n /** The project's root, as an absolute path. */\n root: string;\n /**\n * Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded. One the plugin\n * `needs` always is; any other may not be, so check.\n */\n use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;\n}\n\n/**\n * A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must\n * change nothing: anything else reaches it only from the page itself, which deictic checks.\n */\nexport type Route = (request: Request, context: ServerContext) => Maybe<Response>;\n\nexport interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = unknown> {\n /** Ties the halves together; also the label of its changes in the history, and its routes' path. Lowercase, with `-`. */\n name: string;\n /** The module the page loads for this plugin's half there, which default-exports its `ClientPlugin`. */\n client?: string;\n /** What the page half gets as `context.options`: the user's options it needs there, as JSON. */\n clientOptions?: unknown;\n /** What opens its panel: its own default, which its options let the user change. A plugin with no panel has none. */\n shortcut?: Shortcut;\n /** The plugins it can't do without, by name: the dev server won't start without them. */\n needs?: string[];\n /** Runs once, as the dev server starts and before it answers anything. Answers the plugin's API to the others. */\n setup?(context: ServerContext): Maybe<Api>;\n /** Routes of its own, by their first segment under `/__deictic/plugins/<name>/`. */\n routes?: { [route: string]: Route };\n /** The model its panel shows for an element. Without it, the panel gets none. */\n read?(source: Source, target: Target): Maybe<Model>;\n /** Text edits for deictic to write, or a change the plugin made itself. */\n apply?(source: Source, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;\n /**\n * Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may\n * answer what the next redo needs, where that differs (what it put back has a new ID).\n */\n undo?(record: Record): Maybe<void | Record>;\n /** Makes it again after an undo, and answers what the next undo needs, which may differ (a new ID). */\n redo?(record: Record): Maybe<Record>;\n /** Says what an op does, for the history: `className: px-2 → px-4`. */\n describe?(op: Op, before: Model): string;\n}\n\nexport const definePlugin = <Model, Op, Record = unknown, Api = unknown>(\n plugin: ServerPlugin<Model, Op, Record, Api>,\n): ServerPlugin<Model, Op, Record, Api> => plugin;\n\nexport interface ClientContext {\n /** The dev server's base URL, ending in `/`. */\n base: string;\n /** deictic's shadow root, to draw in: neither the page's styles nor the overlay's cross over. */\n root: ShadowRoot;\n /** The server half's `clientOptions`, or nothing. */\n options: unknown;\n /** Another plugin's API in the page, as its `setup` answered it, or nothing when it isn't loaded. */\n use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;\n /** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */\n request: (route: string, init?: RequestInit) => Promise<Response>;\n /**\n * Opens the popup on an element at a plugin's tab, as its shortcut would: after a recording, say. An\n * element rendered again since stands in for one no longer on the page. False when there's no such tab\n * or no such element any more. Not from `setup`, which runs before the popup can open.\n */\n open: (plugin: string, element: Element) => boolean;\n /**\n * Shows `items` in the lightbox over everything, at `at` (the first by default), stepping between them with\n * ← and →. With `from`, it grows out of that element (the chip clicked) and shrinks back into it on close.\n */\n lightbox: (items: LightboxItem[], options?: LightboxOptions) => { close: () => void };\n}\n\n/** What the lightbox shows: a picture, a page in a frame (a recording's replay), or a sound with its waveform. */\nexport type LightboxItem = {\n /** Its name, over it. */\n title: string;\n /** Buttons beside the name: each closes the lightbox and runs. */\n actions?: LightboxAction[];\n} & ({ kind: 'image'; url: string } | { kind: 'page'; url: string } | { kind: 'audio'; url: string });\n\nexport interface LightboxAction {\n label: string;\n title?: string;\n run: () => void;\n}\n\nexport interface LightboxOptions {\n /** The item it opens at. */\n at?: number;\n /** The element it grows out of, and goes back into. */\n from?: Element;\n}\n\nexport interface PanelContext<Model, Op> extends ClientContext {\n /** The element clicked: the one the source marked, under the pointer or around what is. */\n element: Element;\n /**\n * What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a\n * dependency's, or in an open shadow root, as the popup's own on a page that shows it (`popupIn`).\n */\n pointed?: Element;\n /** Every element on the page from the same place in the source, the clicked one among them: the rows of a list. */\n elements: Element[];\n target: Target;\n model: Model;\n /** Applies an op on disk, and reads the model again. Rejects with the server's reason, which the panel also shows. */\n apply(op: Op): Promise<Model>;\n close: () => void;\n /**\n * Says there's something here that leaving would lose (words typed, a change tried on the page), and the button\n * that keeps it: a click outside the popup then shakes that button, where it would have closed the popup.\n * `undefined` once there's nothing to lose. Forgotten as the panel unmounts.\n */\n unsaved: (action: HTMLElement | undefined) => void;\n /**\n * Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a\n * pick of another element), and opens it again at this tab on this element. The next mount gets\n * `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why\n * it failed. The state stays in the page, as it is: no need for JSON.\n */\n away: <T>(state: unknown, task: () => Promise<T>) => void;\n /** Set when this mount is the panel coming back from `away`. */\n resumed?: Resumed;\n}\n\n/** What a panel coming back from `away` gets: the state it kept, and the task's result or problem. */\nexport interface Resumed {\n state: unknown;\n result?: unknown;\n /** Why the task failed: its error's message. */\n problem?: string;\n}\n\nexport interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {\n /** The server half's `name`. */\n name: string;\n /** Shown over the element while its shortcut's keys are held, and atop the panel. */\n label?: string;\n /**\n * Runs once, as the page starts, before any panel opens (a recording starts here). Answers the\n * plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.\n */\n setup?(context: ClientContext): Api;\n /** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */\n mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;\n}\n\nexport const defineClientPlugin = <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>): ClientPlugin<Model, Op, Api> => plugin;\n"],"mappings":";;AA8DA,IAAa,UAAb,cAA6B,MAAM;CACxB,OAAO;AAClB;AAwEA,MAAa,gBACX,WACyC;AAqG3C,MAAa,sBAAgD,WAAuE"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `deictic`: what a plugin is. Every plugin is optional: deictic itself is the glue (the\n * transform that ties elements to source, the dev server's endpoints, the history, shortcuts and the\n * overlay's panel), and each plugin adds what it does on top.\n *\n * A plugin has two halves, each optional that meet over the dev server's endpoints (`tools/endpoints.ts`). The\n * server half runs beside the bundler and is the only one that reads source: it turns the element\n * under the pointer into a model its panel can show, and an op from that panel into text edits. It\n * never writes files; deictic does, so every plugin's changes land in one history and undo the\n * same way. A change that isn't to a file (a task added to a board) the plugin makes itself and\n * answers with what it did (`Done`): the history keeps that beside the files' changes and hands it\n * back to the plugin's own `undo` and `redo`.\n * The client half is a module the page loads, named by the server half's `client`, which draws the\n * panel and previews an op on the page before it is applied.\n *\n * A plugin may have no panel at all, only an API for others (screenshots, a recording) and routes of\n * its own on the dev server. Each half's `setup` answers its API, and `use(name)` reaches another\n * plugin's, on the same side; `needs` names the plugins it can't do without.\n *\n * Both halves import from here, so the parser is imported for its types only: the browser must not load it.\n */\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport type { Shortcut } from './shortcut.ts';\n\nexport type { Modifier, Shortcut } from './shortcut.ts';\n\n/** A place in the source: the file from the project's root, with `/`, and the line and column, from 1. */\nexport interface Loc {\n file: string;\n line: number;\n column: number;\n}\n\n/** An element the pointer picked: where its opening tag starts, and the tag, which the server checks is still there. */\nexport interface Target {\n loc: Loc;\n tag: string;\n}\n\n/** Text in a file to replace, by UTF-16 offsets. `file` is the target's unless named, from the project's root. */\nexport interface TextEdit {\n file?: string;\n start: number;\n end: number;\n text: string;\n}\n\n/** What a server half reads: the target's file, parsed, and its element. */\nexport interface Source {\n /** The target's file, from the project's root. */\n file: string;\n code: string;\n /** The file's module; for an `.astro` component, its frontmatter's. */\n program: Program;\n /** The target's opening tag. */\n element: JSXOpeningElement;\n /** Another file under the project's root, for plugins whose edits go elsewhere (a locale's messages). */\n read(file: string): string;\n}\n\n/**\n * What answers the overlay's requests in a page with no dev server behind it (`deictic/vite`'s `standalone`): the\n * default export of a module of the page's. A request is one the endpoints would get, under `<base>__deictic/`;\n * the answer is theirs too (`{ model }`, `{ model, change }`, `{ problem }` with a status that isn't ok).\n */\nexport type Standalone = (request: Request) => Response | Promise<Response>;\n\n/** An op a plugin won't make. The message says why and what to do instead; the panel shows it. */\nexport class Refusal extends Error {\n override name = 'Refusal';\n}\n\n/**\n * A change the plugin made itself, not to a file: what its `undo` and `redo` need to take it back and\n * make it again. JSON, since the history keeps it on disk across restarts of the dev server.\n */\nexport interface Done<Record = unknown> {\n done: Record;\n}\n\ntype Maybe<T> = T | Promise<T>;\n\n/**\n * Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:\n * `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.\n */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ServerApis {}\n\n/** The same, in the page: `declare module 'deictic' { interface ClientApis { screenshots: Capture } }`. */\n// oxlint-disable-next-line typescript/no-empty-interface -- filled by declaration merging\nexport interface ClientApis {}\n\n/** A plugin's API, by its name: what its package declared, or `unknown` for one that declared none. */\nexport type ApiOf<Apis, Name extends string> = Name extends keyof Apis ? Apis[Name] : unknown;\n\nexport interface ServerContext {\n /** The project's root, as an absolute path. */\n root: string;\n /**\n * Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded. One the plugin\n * `needs` always is; any other may not be, so check.\n */\n use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;\n}\n\n/**\n * A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must\n * change nothing: anything else reaches it only from the page itself, which deictic checks.\n */\nexport type Route = (request: Request, context: ServerContext) => Maybe<Response>;\n\nexport interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = unknown> {\n /** Ties the halves together; also the label of its changes in the history, and its routes' path. Lowercase, with `-`. */\n name: string;\n /** The module the page loads for this plugin's half there, which default-exports its `ClientPlugin`. */\n client?: string;\n /** What the page half gets as `context.options`: the user's options it needs there, as JSON. */\n clientOptions?: unknown;\n /** What opens its panel: its own default, which its options let the user change. A plugin with no panel has none. */\n shortcut?: Shortcut;\n /** The plugins it can't do without, by name: the dev server won't start without them. */\n needs?: string[];\n /** Runs once, as the dev server starts and before it answers anything. Answers the plugin's API to the others. */\n setup?(context: ServerContext): Maybe<Api>;\n /** Routes of its own, by their first segment under `/__deictic/plugins/<name>/`. */\n routes?: { [route: string]: Route };\n /** The model its panel shows for an element. Without it, the panel gets none. */\n read?(source: Source, target: Target): Maybe<Model>;\n /** Text edits for deictic to write, or a change the plugin made itself. */\n apply?(source: Source, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;\n /**\n * Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may\n * answer what the next redo needs, where that differs (what it put back has a new ID).\n */\n undo?(record: Record): Maybe<void | Record>;\n /** Makes it again after an undo, and answers what the next undo needs, which may differ (a new ID). */\n redo?(record: Record): Maybe<Record>;\n /** Says what an op does, for the history: `className: px-2 → px-4`. */\n describe?(op: Op, before: Model): string;\n}\n\nexport const definePlugin = <Model, Op, Record = unknown, Api = unknown>(\n plugin: ServerPlugin<Model, Op, Record, Api>,\n): ServerPlugin<Model, Op, Record, Api> => plugin;\n\nexport interface ClientContext {\n /** The dev server's base URL, ending in `/`. */\n base: string;\n /** deictic's shadow root, to draw in: neither the page's styles nor the overlay's cross over. */\n root: ShadowRoot;\n /** The server half's `clientOptions`, or nothing. */\n options: unknown;\n /** Another plugin's API in the page, as its `setup` answered it, or nothing when it isn't loaded. */\n use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;\n /** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */\n request: (route: string, init?: RequestInit) => Promise<Response>;\n /**\n * Opens the popup on an element at a plugin's tab, as its shortcut would: after a recording, say. An\n * element rendered again since stands in for one no longer on the page. False when there's no such tab\n * or no such element any more. Not from `setup`, which runs before the popup can open.\n */\n open: (plugin: string, element: Element) => boolean;\n /**\n * Shows `items` in the lightbox over everything, at `at` (the first by default), stepping between them with\n * ← and →. With `from`, it grows out of that element (the chip clicked) and shrinks back into it on close.\n */\n lightbox: (items: LightboxItem[], options?: LightboxOptions) => { close: () => void };\n}\n\n/** What the lightbox shows: a picture, a page in a frame (a recording's replay), or a sound with its waveform. */\nexport type LightboxItem = {\n /** Its name, over it. */\n title: string;\n /** Buttons beside the name: each closes the lightbox and runs. */\n actions?: LightboxAction[];\n} & ({ kind: 'image'; url: string } | { kind: 'page'; url: string } | { kind: 'audio'; url: string });\n\nexport interface LightboxAction {\n label: string;\n title?: string;\n run: () => void;\n}\n\nexport interface LightboxOptions {\n /** The item it opens at. */\n at?: number;\n /** The element it grows out of, and goes back into. */\n from?: Element;\n}\n\nexport interface PanelContext<Model, Op> extends ClientContext {\n /** The element clicked: the one the source marked, under the pointer or around what is. */\n element: Element;\n /**\n * What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a\n * dependency's, or in an open shadow root, as the popup's own on a page that shows it (`popupIn`).\n */\n pointed?: Element;\n /** Every element on the page from the same place in the source, the clicked one among them: the rows of a list. */\n elements: Element[];\n target: Target;\n model: Model;\n /** Applies an op on disk, and reads the model again. Rejects with the server's reason, which the panel also shows. */\n apply(op: Op): Promise<Model>;\n close: () => void;\n /**\n * Says there's something here that leaving would lose (words typed, a change tried on the page), and the button\n * that keeps it: a click outside the popup then shakes that button, where it would have closed the popup.\n * `undefined` once there's nothing to lose. Forgotten as the panel unmounts.\n */\n unsaved: (action: HTMLElement | undefined) => void;\n /**\n * Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a\n * pick of another element), and opens it again at this tab on this element. The next mount gets\n * `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why\n * it failed. The state stays in the page, as it is: no need for JSON.\n */\n away: <T>(state: unknown, task: () => Promise<T>) => void;\n /** Set when this mount is the panel coming back from `away`. */\n resumed?: Resumed;\n}\n\n/** What a panel coming back from `away` gets: the state it kept, and the task's result or problem. */\nexport interface Resumed {\n state: unknown;\n result?: unknown;\n /** Why the task failed: its error's message. */\n problem?: string;\n}\n\nexport interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {\n /** The server half's `name`. */\n name: string;\n /** Shown over the element while its shortcut's keys are held, and atop the panel. */\n label?: string;\n /**\n * Runs once, as the page starts, before any panel opens (a recording starts here). Answers the\n * plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.\n */\n setup?(context: ClientContext): Api;\n /** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */\n mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;\n}\n\nexport const defineClientPlugin = <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>): ClientPlugin<Model, Op, Api> => plugin;\n"],"mappings":";;AAqEA,IAAa,UAAb,cAA6B,MAAM;CACxB,OAAO;AAClB;AAwEA,MAAa,gBACX,WACyC;AAqG3C,MAAa,sBAAgD,WAAuE"}
|
package/dist/loader.js
CHANGED
package/dist/next.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as DeicticOptions } from "./integration.js";
|
|
1
|
+
import { t as DeicticOptions } from "./shared/integration.js";
|
|
2
2
|
export interface DeicticNextOptions extends DeicticOptions {
|
|
3
3
|
/** The project's root, which marks and edits are from: the working directory `next dev` runs in by default. */
|
|
4
4
|
root?: string;
|
package/dist/next.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import { n as nodeMiddleware, r as redirect, t as endpoints } from "./endpoints.js";
|
|
4
|
-
import { d as JSX, o as prepare, s as writeClient, t as beside } from "./integration.js";
|
|
3
|
+
import { n as nodeMiddleware, r as redirect, t as endpoints } from "./shared/endpoints.js";
|
|
4
|
+
import { d as JSX, o as prepare, s as writeClient, t as beside } from "./shared/integration.js";
|
|
5
5
|
// src/next.ts
|
|
6
6
|
/**
|
|
7
7
|
* `deictic/next`: deictic in `next dev`, on Turbopack or webpack (`--webpack`). Nothing runs in `next build`.
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* Only the server halves, as every factory is: each names its page half, which the integration imports. A plugin
|
|
6
6
|
* outside the preset (Tailwind, your own) goes beside it: `plugins: [...recommended(), tailwind()]`.
|
|
7
7
|
*/
|
|
8
|
-
import { g as ServerPlugin } from "../index.js";
|
|
8
|
+
import { g as ServerPlugin } from "../shared/index.js";
|
|
9
9
|
import { AnnotationsOptions } from "../annotations/index.js";
|
|
10
|
-
import { a as RecordingsOptions } from "../
|
|
11
|
-
import { l as ScreenshotsOptions } from "../
|
|
12
|
-
import { TasksOptions } from "../
|
|
10
|
+
import { a as RecordingsOptions } from "../shared/index3.js";
|
|
11
|
+
import { l as ScreenshotsOptions } from "../shared/index2.js";
|
|
12
|
+
import { f as TasksOptions } from "../shared/index4.js";
|
|
13
13
|
import { VoiceOptions } from "../voice/index.js";
|
|
14
14
|
/** Each plugin's options, by its name, or `false` to leave it out. */
|
|
15
15
|
export interface RecommendedOptions {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { annotations } from "../annotations/index.js";
|
|
2
|
-
import { t as recordings } from "../recordings.js";
|
|
2
|
+
import { t as recordings } from "../shared/recordings.js";
|
|
3
3
|
import screenshots from "../screenshots/index.js";
|
|
4
|
-
import tasks from "../tasks
|
|
4
|
+
import { t as tasks } from "../shared/tasks.js";
|
|
5
5
|
import voice from "../voice/index.js";
|
|
6
6
|
// src/plugins/recommended/index.ts
|
|
7
7
|
/** Tasks, screenshots, annotations, recordings and voice, in that order: the order of their tabs. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as liveWaveform } from "../waveform.js";
|
|
1
|
+
import { n as liveWaveform } from "../shared/waveform.js";
|
|
2
2
|
import { defineClientPlugin } from "../index.js";
|
|
3
|
-
import { n as MARKS, t as END } from "../marks.js";
|
|
3
|
+
import { n as MARKS, t as END } from "../shared/marks.js";
|
|
4
4
|
// src/plugins/recordings/ours.ts
|
|
5
5
|
/** rrweb's numbers: an incremental snapshot, and the sources whose data is a list of pointer positions. */
|
|
6
6
|
const INCREMENTAL = 3;
|
|
@@ -323,11 +323,11 @@ var client_default = defineClientPlugin({
|
|
|
323
323
|
headers: { "content-type": "application/json" },
|
|
324
324
|
body: JSON.stringify(kept)
|
|
325
325
|
});
|
|
326
|
-
const { id, problem } = await res.json();
|
|
326
|
+
const { id, url, problem } = await res.json();
|
|
327
327
|
if (id === void 0) throw new Error(`recordings: ${problem ?? res.statusText}`);
|
|
328
328
|
done({
|
|
329
329
|
id,
|
|
330
|
-
url: `${base}__deictic/plugins/recordings/replay/${id}`,
|
|
330
|
+
url: url ?? `${base}__deictic/plugins/recordings/replay/${id}`,
|
|
331
331
|
duration,
|
|
332
332
|
...voiced
|
|
333
333
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/recordings/ours.ts","../../src/plugins/recordings/client.ts"],"sourcesContent":["/**\n * Keeps deictic's own UI out of a recording. Blocking the overlay keeps it out of the first snapshot,\n * but rrweb watches a blocked host's shadow root all the same, so what's added there later (the toolbar,\n * a note's field) comes as mutations. This drops them, and clicks and input on those nodes, by the IDs\n * rrweb gave them: the host's, and every node added under one of ours.\n *\n * The pointer's moves over them stay, on the page's root instead: the replay moves its cursor only over a\n * node it has, and while a drawing tool is picked the pointer is over ours the whole time.\n */\n\n/** The parts of rrweb's events this reads; the rest passes as it is. */\ninterface Event {\n type: number;\n data?: unknown;\n}\n\ninterface Mutation {\n source: 0;\n adds: { parentId: number; node: { id: number } }[];\n removes: { parentId: number; id: number }[];\n texts: { id: number }[];\n attributes: { id: number }[];\n}\n\n/** rrweb's numbers: an incremental snapshot, and the sources whose data is a list of pointer positions. */\nconst INCREMENTAL = 3;\nconst MUTATION = 0;\nconst POSITIONS = new Set([1, 6, 12]);\n\n/** A filter for `emit`: the event without our nodes, or nothing when nothing else is left in it. */\nexport function dropOurs<E extends Event>(hostId: () => number, pageId: () => number): (event: E) => E | undefined {\n const ours = new Set<number>();\n return (event) => {\n if (ours.size === 0) {\n const id = hostId();\n if (id > 0) ours.add(id);\n }\n if (event.type !== INCREMENTAL || typeof event.data !== 'object' || event.data === null) return event;\n const data = event.data as { source: number; id?: number; positions?: { id: number }[] };\n\n if (data.source === MUTATION) {\n const m = data as Mutation;\n // Added parents and children come in any order: claim until nothing more is ours.\n for (let grew = true; grew;) {\n grew = false;\n for (const add of m.adds) {\n if (ours.has(add.parentId) && !ours.has(add.node.id)) {\n ours.add(add.node.id);\n grew = true;\n }\n }\n }\n const kept: Mutation = {\n ...m,\n adds: m.adds.filter((a) => !ours.has(a.node.id)),\n removes: m.removes.filter((r) => !ours.has(r.id) && !ours.has(r.parentId)),\n texts: m.texts.filter((t) => !ours.has(t.id)),\n attributes: m.attributes.filter((a) => !ours.has(a.id)),\n };\n const left = kept.adds.length + kept.removes.length + kept.texts.length + kept.attributes.length;\n return left === 0 ? undefined : { ...event, data: kept };\n }\n if (POSITIONS.has(data.source) && Array.isArray(data.positions)) {\n const page = pageId();\n const positions = data.positions.map((p) => (ours.has(p.id) ? { ...p, id: page } : p));\n return { ...event, data: { ...data, positions } };\n }\n return data.id !== undefined && ours.has(data.id) ? undefined : event;\n };\n}\n","/**\n * The recordings plugin's page half: `record()` starts rrweb (imported then) and shows the toolbar, a bar\n * docked to an edge of the window that its grip drags to any other, kept between recordings. It holds the\n * time, annotate mode's tools where that plugin is loaded, and Stop and Discard. Stop sends the events to\n * the `add` route.\n *\n * Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom\n * events: the page's annotations and the toolbar's own, which go when it does, as SVGs in page\n * coordinates, at the start and at each change.\n */\nimport { liveWaveform } from '#src/client/waveform.ts';\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { ResolvedMasking } from '#src/plugins/screenshots/index.ts';\n\nimport type { Take } from '#src/plugins/voice/index.ts';\n\nimport type { Kept, Recorder, Recording, VoiceClip } from './index.ts';\nimport { END, MARKS } from './marks.ts';\nimport { dropOurs } from './ours.ts';\n\ntype Edge = 'top' | 'bottom' | 'left' | 'right';\n/** Where the bar is: the edge it's docked to, and how far along it, from 0 to 1. */\ninterface Dock {\n edge: Edge;\n along: number;\n}\n\nconst DOCK = 'deictic:recorder';\nconst MARGIN = 12;\n\nconst STYLE = `\n.recorder { position: fixed; z-index: 2147483647; display: flex; align-items: center; gap: 6px; padding: 6px 8px;\n border: 1px solid var(--deictic-line); border-radius: 10px; background: var(--deictic-bg); color: var(--deictic-fg);\n box-shadow: 0 12px 32px rgb(0 0 0 / 0.35); font: 13px/1.4 system-ui, sans-serif; user-select: none; }\n.recorder.vertical { flex-direction: column; }\n.recorder.vertical .annotations-tools { flex-direction: column; }\n.recorder.vertical .annotations-tools .gap { width: auto; height: 1px; margin: 4px 2px; }\n.recorder .grip { display: inline-flex; padding: 2px; color: var(--deictic-muted); cursor: grab; touch-action: none; }\n.recorder .grip:active { cursor: grabbing; }\n.recorder .grip svg { width: 16px; height: 16px; }\n.recorder .live { display: inline-flex; align-items: center; gap: 6px; font: 12px ui-monospace, monospace; }\n.recorder .dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: deictic-blink 1.2s infinite; }\n.recorder .sep { align-self: stretch; width: 1px; background: var(--deictic-line); }\n.recorder.vertical .sep { width: auto; height: 1px; }\n.recorder .icon { display: inline-flex; align-items: center; justify-content: center; padding: 3px 5px; }\n.recorder .icon svg { width: 16px; height: 16px; }\n.recorder .mic[aria-pressed='true'] { background: #ef4444; border-color: #ef4444; color: #fff; }\n.recorder .wave { width: 44px; height: 18px; }\n.recorder.vertical .wave { width: 28px; }\n.recorder .wave[hidden] { display: none; }\n.recorder .mic.problem { border-color: var(--deictic-problem); color: var(--deictic-problem); }\n@keyframes deictic-blink { 50% { opacity: 0.3; } }\n`;\n\nconst svg = (paths: string) =>\n `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">${paths}</svg>`;\nconst GRIP = svg(\n '<circle cx=\"9\" cy=\"6\" r=\"1\"/><circle cx=\"15\" cy=\"6\" r=\"1\"/><circle cx=\"9\" cy=\"12\" r=\"1\"/><circle cx=\"15\" cy=\"12\" r=\"1\"/><circle cx=\"9\" cy=\"18\" r=\"1\"/><circle cx=\"15\" cy=\"18\" r=\"1\"/>',\n);\nconst STOP = svg('<rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"1\" fill=\"currentColor\"/>');\nconst DISCARD = svg('<path d=\"M6 6l12 12M18 6 6 18\"/>');\nconst MIC = svg('<rect x=\"9\" y=\"3\" width=\"6\" height=\"11\" rx=\"3\"/><path d=\"M5 11a7 7 0 0 0 14 0M12 18v3\"/>');\n\nconst clock = (ms: number) => {\n const s = Math.floor(ms / 1000);\n return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;\n};\n\nfunction storedDock(): Dock {\n try {\n const dock = JSON.parse(localStorage.getItem(DOCK) ?? 'null') as Dock | null;\n if (dock !== null && ['top', 'bottom', 'left', 'right'].includes(dock.edge) && dock.along >= 0 && dock.along <= 1) return dock;\n } catch {\n // Storage can be off, or hold something else: the default, then.\n }\n return { edge: 'bottom', along: 0.5 };\n}\n\nfunction iconButton(icon: string, name: string, run: () => void): HTMLButtonElement {\n const el = Object.assign(document.createElement('button'), { type: 'button', className: 'icon', title: name, innerHTML: icon });\n el.setAttribute('aria-label', name);\n el.addEventListener('click', run);\n return el;\n}\n\n/** Puts the bar on its edge, laid out along it, and how far along. */\nfunction place(bar: HTMLElement, { edge, along }: Dock): void {\n bar.classList.toggle('vertical', edge === 'left' || edge === 'right');\n const { width, height } = bar.getBoundingClientRect();\n const across = (room: number, size: number) => `${MARGIN + along * Math.max(0, room - size - MARGIN * 2)}px`;\n Object.assign(bar.style, {\n left: edge === 'left' ? `${MARGIN}px` : edge === 'right' ? `${innerWidth - width - MARGIN}px` : across(innerWidth, width),\n top: edge === 'top' ? `${MARGIN}px` : edge === 'bottom' ? `${innerHeight - height - MARGIN}px` : across(innerHeight, height),\n });\n}\n\n/** Dragging the bar by its grip, freely; let go, it docks to the nearest edge. */\nfunction draggable(bar: HTMLElement, grip: HTMLElement, docked: (dock: Dock) => void): void {\n grip.addEventListener('pointerdown', (e) => {\n if (e.button !== 0) return;\n e.preventDefault();\n grip.setPointerCapture(e.pointerId);\n const start = bar.getBoundingClientRect();\n const dx = e.clientX - start.left;\n const dy = e.clientY - start.top;\n const move = (m: PointerEvent) => {\n bar.style.left = `${m.clientX - dx}px`;\n bar.style.top = `${m.clientY - dy}px`;\n };\n const up = () => {\n grip.removeEventListener('pointermove', move);\n const r = bar.getBoundingClientRect();\n const x = r.left + r.width / 2;\n const y = r.top + r.height / 2;\n const away: [Edge, number][] = [\n ['left', x],\n ['right', innerWidth - x],\n ['top', y],\n ['bottom', innerHeight - y],\n ];\n const [edge] = away.reduce((a, b) => (b[1] < a[1] ? b : a));\n const ratio = (at: number, room: number) => Math.min(1, Math.max(0, at / room));\n docked({ edge, along: edge === 'left' || edge === 'right' ? ratio(y, innerHeight) : ratio(x, innerWidth) });\n };\n grip.addEventListener('pointermove', move);\n grip.addEventListener('pointerup', up, { once: true });\n });\n}\n\nexport default defineClientPlugin<never, never, Recorder>({\n name: 'recordings',\n setup: ({ base, root, options, use, request }) => {\n const { masking } = options as { masking: ResolvedMasking };\n let going = false;\n\n const record = async (): Promise<Recording | undefined> => {\n const rrweb = await import('rrweb').catch((e: unknown) => {\n throw new Error('recordings need rrweb: add it to your devDependencies', { cause: e });\n });\n const events: { type: number; data?: unknown }[] = [];\n const startedAt = Date.now();\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n const colorScheme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n const host = root.host;\n const keep = dropOurs<(typeof events)[number]>(\n () => rrweb.record.mirror.getId(host),\n () => rrweb.record.mirror.getId(document.documentElement),\n );\n const stopRecording = rrweb.record({\n emit: (event) => {\n const kept = keep(event);\n if (kept !== undefined) events.push(kept);\n },\n blockClass: masking.blockClass,\n // deictic's own UI, the overlay: a blocked element is kept as an empty box its size, and it has none.\n blockSelector: ['deictic-overlay', ...(masking.blockSelector ? [masking.blockSelector] : [])].join(', '),\n maskTextClass: masking.maskTextClass,\n ...(masking.maskTextSelector ? { maskTextSelector: masking.maskTextSelector } : {}),\n maskAllInputs: masking.maskAllInputs,\n maskInputOptions: { password: true },\n inlineStylesheet: true,\n });\n\n // The marks, now and at each change: an SVG whose view is the page from its top left, at 1:1.\n const marks = use('annotations');\n // The toolbar's own, drawn while recording: shown with the page's, gone when it ends.\n const tools = marks?.tools();\n const mark = () => {\n const area = { x: -scrollX, y: -scrollY, width: 1, height: 1 };\n rrweb.record.addCustomEvent(MARKS, {\n svg: [marks?.svg(area), tools?.marks.svg(area)].filter(Boolean).join(''),\n // The same marks as data, in page coordinates, for whatever reads the recording but doesn't draw it.\n annotations: [...(marks?.list() ?? []), ...(tools?.marks.list() ?? [])],\n });\n };\n mark();\n const unsubscribe = [marks?.subscribe(mark), tools?.marks.subscribe(mark)];\n\n return new Promise((done, fail) => {\n const bar = document.createElement('div');\n bar.className = 'recorder';\n bar.setAttribute('role', 'toolbar');\n bar.setAttribute('aria-label', 'Recording');\n const grip = Object.assign(document.createElement('span'), { className: 'grip', title: 'Drag to any edge', innerHTML: GRIP });\n const live = Object.assign(document.createElement('span'), { className: 'live' });\n const dot = Object.assign(document.createElement('span'), { className: 'dot' });\n const time = document.createElement('span');\n live.append(dot, time);\n const sep = () => Object.assign(document.createElement('span'), { className: 'sep' });\n\n // The mic, where the voice plugin is loaded: each stretch it's on is a clip, at its time in the recording.\n const voice = use('voice');\n const clips: VoiceClip[] = [];\n let take: Take | undefined;\n // The mic's live waveform beside it while it's on, so it's plain it hears.\n const wave = Object.assign(document.createElement('canvas'), { className: 'wave', hidden: true });\n let stopWave: (() => void) | undefined;\n const unwave = () => {\n stopWave?.();\n stopWave = undefined;\n wave.hidden = true;\n };\n // What the mic is doing (asking for it, keeping a take): the next toggle, and the end, wait for it.\n let busy: Promise<void> = Promise.resolve();\n const micOff = async () => {\n const ending = take;\n take = undefined;\n unwave();\n if (ending === undefined) return;\n try {\n const clip = await ending.stop();\n clips.push({ id: clip.id, at: ending.started - startedAt, duration: clip.duration });\n } catch (e) {\n // The recording is worth keeping without it.\n console.warn('deictic: the voice clip was not kept', e);\n }\n };\n const mic = voice === undefined ? undefined : iconButton(MIC, 'Turn the mic on', () => toggle());\n const toggle = () => {\n busy = busy.then(async () => {\n if (voice === undefined || mic === undefined) return;\n if (take !== undefined) {\n await micOff();\n } else {\n try {\n take = await voice.start();\n mic.classList.remove('problem');\n wave.hidden = false;\n stopWave = liveWaveform(wave, take.stream, { played: '#ef4444', rest: '#52525b' });\n } catch (e) {\n mic.classList.add('problem');\n mic.title = e instanceof Error ? e.message : String(e);\n return;\n }\n }\n const on = take !== undefined;\n mic.setAttribute('aria-pressed', String(on));\n mic.title = on ? 'Turn the mic off' : 'Turn the mic on';\n mic.setAttribute('aria-label', mic.title);\n });\n };\n mic?.classList.add('mic');\n mic?.setAttribute('aria-pressed', 'false');\n\n const end = async (keep: boolean) => {\n rrweb.record.addCustomEvent(END, {});\n stopRecording?.();\n for (const stop of unsubscribe) stop?.();\n tools?.close();\n clearInterval(ticking);\n removeEventListener('resize', replace);\n bar.remove();\n await busy;\n if (!keep) {\n unwave();\n take?.cancel();\n return done(undefined);\n }\n await micOff();\n const duration = Date.now() - startedAt;\n const voiced = clips.length > 0 ? { voice: clips } : {};\n const kept: Kept = { page: location.href, viewport, colorScheme, startedAt, duration, events, ...voiced };\n try {\n const res = await request('add', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(kept),\n });\n const { id, problem } = (await res.json()) as { id?: string; problem?: string };\n if (id === undefined) throw new Error(`recordings: ${problem ?? res.statusText}`);\n done({ id, url: `${base}__deictic/plugins/recordings/replay/${id}`, duration, ...voiced });\n } catch (e) {\n fail(e);\n }\n };\n const stop = iconButton(STOP, 'Stop, and keep the recording', () => void end(true));\n const discard = iconButton(DISCARD, 'Discard the recording', () => void end(false));\n bar.append(grip, live, ...(tools ? [sep(), tools.element] : []), sep(), ...(mic ? [mic, wave] : []), stop, discard);\n const style = Object.assign(document.createElement('style'), { textContent: STYLE });\n bar.prepend(style);\n root.append(bar);\n\n const tick = () => (time.textContent = clock(Date.now() - startedAt));\n tick();\n const ticking = setInterval(tick, 250);\n let dock = storedDock();\n const replace = () => place(bar, dock);\n replace();\n addEventListener('resize', replace);\n draggable(bar, grip, (next) => {\n dock = next;\n replace();\n try {\n localStorage.setItem(DOCK, JSON.stringify(dock));\n } catch {\n // Not kept, then: the next recording starts at the bottom.\n }\n });\n });\n };\n\n return {\n recording: () => going,\n record: async () => {\n if (going) throw new Error('recordings: one is going already: stop it first');\n going = true;\n try {\n return await record();\n } finally {\n going = false;\n }\n },\n };\n },\n});\n"],"mappings":";;;;;AAyBA,MAAM,cAAc;AACpB,MAAM,WAAW;AACjB,MAAM,4BAAY,IAAI,IAAI;CAAC;CAAG;CAAG;AAAE,CAAC;;AAGpC,SAAgB,SAA0B,QAAsB,QAAmD;CACjH,MAAM,uBAAO,IAAI,IAAY;CAC7B,QAAQ,UAAU;EAChB,IAAI,KAAK,SAAS,GAAG;GACnB,MAAM,KAAK,OAAO;GAClB,IAAI,KAAK,GAAG,KAAK,IAAI,EAAE;EACzB;EACA,IAAI,MAAM,SAAS,eAAe,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,MAAM,OAAO;EAChG,MAAM,OAAO,MAAM;EAEnB,IAAI,KAAK,WAAW,UAAU;GAC5B,MAAM,IAAI;GAEV,KAAK,IAAI,OAAO,MAAM,OAAO;IAC3B,OAAO;IACP,KAAK,MAAM,OAAO,EAAE,MAClB,IAAI,KAAK,IAAI,IAAI,QAAQ,KAAK,CAAC,KAAK,IAAI,IAAI,KAAK,EAAE,GAAG;KACpD,KAAK,IAAI,IAAI,KAAK,EAAE;KACpB,OAAO;IACT;GAEJ;GACA,MAAM,OAAiB;IACrB,GAAG;IACH,MAAM,EAAE,KAAK,QAAQ,MAAM,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,CAAC;IAC/C,SAAS,EAAE,QAAQ,QAAQ,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE,QAAQ,CAAC;IACzE,OAAO,EAAE,MAAM,QAAQ,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC;IAC5C,YAAY,EAAE,WAAW,QAAQ,MAAM,CAAC,KAAK,IAAI,EAA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A,MAAM,OAAO,WAAW,MAAM,sCAAsC,KAAK,IAAI,IAAI,CAAC;IAClF,MAAM,UAAU,WAAW,SAAS,+BAA+B,KAAK,IAAI,KAAK,CAAC;IAClF,IAAI,OAAO,MAAM,MAAM,GAAI,QAAQ,CAAC,IAAI,GAAG,MAAM,OAAO,IAAI,CAAC,GAAI,IAAI,GAAG,GAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,GAAI,MAAM,OAAO;IAClH,MAAM,QAAQ,OAAO,OAAO,SAAS,cAAc,OAAO,GAAG,EAAE,aAAa,MAAM,CAAC;IACnF,IAAI,QAAQ,KAAK;IACjB,KAAK,OAAO,GAAG;IAEf,MAAM,aAAc,KAAK,cAAc,MAAM,KAAK,IAAI,IAAI,SAAS;IACnE,KAAK;IACL,MAAM,UAAU,YAAY,MAAM,GAAG;IACrC,IAAI,OAAO,WAAW;IACtB,MAAM,gBAAgB,MAAM,KAAK,IAAI;IACrC,QAAQ;IACR,iBAAiB,UAAU,OAAO;IAClC,UAAU,KAAK,OAAO,SAAS;KAC7B,OAAO;KACP,QAAQ;KACR,IAAI;MACF,aAAa,QAAQ,MAAM,KAAK,UAAU,IAAI,CAAC;KACjD,QAAQ,CAER;IACF,CAAC;GACH,CAAC;EACH;EAEA,OAAO;GACL,iBAAiB;GACjB,QAAQ,YAAY;IAClB,IAAI,OAAO,MAAM,IAAI,MAAM,iDAAiD;IAC5E,QAAQ;IACR,IAAI;KACF,OAAO,MAAM,OAAO;IACtB,UAAU;KACR,QAAQ;IACV;GACF;EACF;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/recordings/ours.ts","../../src/plugins/recordings/client.ts"],"sourcesContent":["/**\n * Keeps deictic's own UI out of a recording. Blocking the overlay keeps it out of the first snapshot,\n * but rrweb watches a blocked host's shadow root all the same, so what's added there later (the toolbar,\n * a note's field) comes as mutations. This drops them, and clicks and input on those nodes, by the IDs\n * rrweb gave them: the host's, and every node added under one of ours.\n *\n * The pointer's moves over them stay, on the page's root instead: the replay moves its cursor only over a\n * node it has, and while a drawing tool is picked the pointer is over ours the whole time.\n */\n\n/** The parts of rrweb's events this reads; the rest passes as it is. */\ninterface Event {\n type: number;\n data?: unknown;\n}\n\ninterface Mutation {\n source: 0;\n adds: { parentId: number; node: { id: number } }[];\n removes: { parentId: number; id: number }[];\n texts: { id: number }[];\n attributes: { id: number }[];\n}\n\n/** rrweb's numbers: an incremental snapshot, and the sources whose data is a list of pointer positions. */\nconst INCREMENTAL = 3;\nconst MUTATION = 0;\nconst POSITIONS = new Set([1, 6, 12]);\n\n/** A filter for `emit`: the event without our nodes, or nothing when nothing else is left in it. */\nexport function dropOurs<E extends Event>(hostId: () => number, pageId: () => number): (event: E) => E | undefined {\n const ours = new Set<number>();\n return (event) => {\n if (ours.size === 0) {\n const id = hostId();\n if (id > 0) ours.add(id);\n }\n if (event.type !== INCREMENTAL || typeof event.data !== 'object' || event.data === null) return event;\n const data = event.data as { source: number; id?: number; positions?: { id: number }[] };\n\n if (data.source === MUTATION) {\n const m = data as Mutation;\n // Added parents and children come in any order: claim until nothing more is ours.\n for (let grew = true; grew;) {\n grew = false;\n for (const add of m.adds) {\n if (ours.has(add.parentId) && !ours.has(add.node.id)) {\n ours.add(add.node.id);\n grew = true;\n }\n }\n }\n const kept: Mutation = {\n ...m,\n adds: m.adds.filter((a) => !ours.has(a.node.id)),\n removes: m.removes.filter((r) => !ours.has(r.id) && !ours.has(r.parentId)),\n texts: m.texts.filter((t) => !ours.has(t.id)),\n attributes: m.attributes.filter((a) => !ours.has(a.id)),\n };\n const left = kept.adds.length + kept.removes.length + kept.texts.length + kept.attributes.length;\n return left === 0 ? undefined : { ...event, data: kept };\n }\n if (POSITIONS.has(data.source) && Array.isArray(data.positions)) {\n const page = pageId();\n const positions = data.positions.map((p) => (ours.has(p.id) ? { ...p, id: page } : p));\n return { ...event, data: { ...data, positions } };\n }\n return data.id !== undefined && ours.has(data.id) ? undefined : event;\n };\n}\n","/**\n * The recordings plugin's page half: `record()` starts rrweb (imported then) and shows the toolbar, a bar\n * docked to an edge of the window that its grip drags to any other, kept between recordings. It holds the\n * time, annotate mode's tools where that plugin is loaded, and Stop and Discard. Stop sends the events to\n * the `add` route.\n *\n * Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom\n * events: the page's annotations and the toolbar's own, which go when it does, as SVGs in page\n * coordinates, at the start and at each change.\n */\nimport { liveWaveform } from '#src/client/waveform.ts';\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { ResolvedMasking } from '#src/plugins/screenshots/index.ts';\n\nimport type { Take } from '#src/plugins/voice/index.ts';\n\nimport type { Kept, Recorder, Recording, VoiceClip } from './index.ts';\nimport { END, MARKS } from './marks.ts';\nimport { dropOurs } from './ours.ts';\n\ntype Edge = 'top' | 'bottom' | 'left' | 'right';\n/** Where the bar is: the edge it's docked to, and how far along it, from 0 to 1. */\ninterface Dock {\n edge: Edge;\n along: number;\n}\n\nconst DOCK = 'deictic:recorder';\nconst MARGIN = 12;\n\nconst STYLE = `\n.recorder { position: fixed; z-index: 2147483647; display: flex; align-items: center; gap: 6px; padding: 6px 8px;\n border: 1px solid var(--deictic-line); border-radius: 10px; background: var(--deictic-bg); color: var(--deictic-fg);\n box-shadow: 0 12px 32px rgb(0 0 0 / 0.35); font: 13px/1.4 system-ui, sans-serif; user-select: none; }\n.recorder.vertical { flex-direction: column; }\n.recorder.vertical .annotations-tools { flex-direction: column; }\n.recorder.vertical .annotations-tools .gap { width: auto; height: 1px; margin: 4px 2px; }\n.recorder .grip { display: inline-flex; padding: 2px; color: var(--deictic-muted); cursor: grab; touch-action: none; }\n.recorder .grip:active { cursor: grabbing; }\n.recorder .grip svg { width: 16px; height: 16px; }\n.recorder .live { display: inline-flex; align-items: center; gap: 6px; font: 12px ui-monospace, monospace; }\n.recorder .dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; animation: deictic-blink 1.2s infinite; }\n.recorder .sep { align-self: stretch; width: 1px; background: var(--deictic-line); }\n.recorder.vertical .sep { width: auto; height: 1px; }\n.recorder .icon { display: inline-flex; align-items: center; justify-content: center; padding: 3px 5px; }\n.recorder .icon svg { width: 16px; height: 16px; }\n.recorder .mic[aria-pressed='true'] { background: #ef4444; border-color: #ef4444; color: #fff; }\n.recorder .wave { width: 44px; height: 18px; }\n.recorder.vertical .wave { width: 28px; }\n.recorder .wave[hidden] { display: none; }\n.recorder .mic.problem { border-color: var(--deictic-problem); color: var(--deictic-problem); }\n@keyframes deictic-blink { 50% { opacity: 0.3; } }\n`;\n\nconst svg = (paths: string) =>\n `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">${paths}</svg>`;\nconst GRIP = svg(\n '<circle cx=\"9\" cy=\"6\" r=\"1\"/><circle cx=\"15\" cy=\"6\" r=\"1\"/><circle cx=\"9\" cy=\"12\" r=\"1\"/><circle cx=\"15\" cy=\"12\" r=\"1\"/><circle cx=\"9\" cy=\"18\" r=\"1\"/><circle cx=\"15\" cy=\"18\" r=\"1\"/>',\n);\nconst STOP = svg('<rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"1\" fill=\"currentColor\"/>');\nconst DISCARD = svg('<path d=\"M6 6l12 12M18 6 6 18\"/>');\nconst MIC = svg('<rect x=\"9\" y=\"3\" width=\"6\" height=\"11\" rx=\"3\"/><path d=\"M5 11a7 7 0 0 0 14 0M12 18v3\"/>');\n\nconst clock = (ms: number) => {\n const s = Math.floor(ms / 1000);\n return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;\n};\n\nfunction storedDock(): Dock {\n try {\n const dock = JSON.parse(localStorage.getItem(DOCK) ?? 'null') as Dock | null;\n if (dock !== null && ['top', 'bottom', 'left', 'right'].includes(dock.edge) && dock.along >= 0 && dock.along <= 1) return dock;\n } catch {\n // Storage can be off, or hold something else: the default, then.\n }\n return { edge: 'bottom', along: 0.5 };\n}\n\nfunction iconButton(icon: string, name: string, run: () => void): HTMLButtonElement {\n const el = Object.assign(document.createElement('button'), { type: 'button', className: 'icon', title: name, innerHTML: icon });\n el.setAttribute('aria-label', name);\n el.addEventListener('click', run);\n return el;\n}\n\n/** Puts the bar on its edge, laid out along it, and how far along. */\nfunction place(bar: HTMLElement, { edge, along }: Dock): void {\n bar.classList.toggle('vertical', edge === 'left' || edge === 'right');\n const { width, height } = bar.getBoundingClientRect();\n const across = (room: number, size: number) => `${MARGIN + along * Math.max(0, room - size - MARGIN * 2)}px`;\n Object.assign(bar.style, {\n left: edge === 'left' ? `${MARGIN}px` : edge === 'right' ? `${innerWidth - width - MARGIN}px` : across(innerWidth, width),\n top: edge === 'top' ? `${MARGIN}px` : edge === 'bottom' ? `${innerHeight - height - MARGIN}px` : across(innerHeight, height),\n });\n}\n\n/** Dragging the bar by its grip, freely; let go, it docks to the nearest edge. */\nfunction draggable(bar: HTMLElement, grip: HTMLElement, docked: (dock: Dock) => void): void {\n grip.addEventListener('pointerdown', (e) => {\n if (e.button !== 0) return;\n e.preventDefault();\n grip.setPointerCapture(e.pointerId);\n const start = bar.getBoundingClientRect();\n const dx = e.clientX - start.left;\n const dy = e.clientY - start.top;\n const move = (m: PointerEvent) => {\n bar.style.left = `${m.clientX - dx}px`;\n bar.style.top = `${m.clientY - dy}px`;\n };\n const up = () => {\n grip.removeEventListener('pointermove', move);\n const r = bar.getBoundingClientRect();\n const x = r.left + r.width / 2;\n const y = r.top + r.height / 2;\n const away: [Edge, number][] = [\n ['left', x],\n ['right', innerWidth - x],\n ['top', y],\n ['bottom', innerHeight - y],\n ];\n const [edge] = away.reduce((a, b) => (b[1] < a[1] ? b : a));\n const ratio = (at: number, room: number) => Math.min(1, Math.max(0, at / room));\n docked({ edge, along: edge === 'left' || edge === 'right' ? ratio(y, innerHeight) : ratio(x, innerWidth) });\n };\n grip.addEventListener('pointermove', move);\n grip.addEventListener('pointerup', up, { once: true });\n });\n}\n\nexport default defineClientPlugin<never, never, Recorder>({\n name: 'recordings',\n setup: ({ base, root, options, use, request }) => {\n const { masking } = options as { masking: ResolvedMasking };\n let going = false;\n\n const record = async (): Promise<Recording | undefined> => {\n const rrweb = await import('rrweb').catch((e: unknown) => {\n throw new Error('recordings need rrweb: add it to your devDependencies', { cause: e });\n });\n const events: { type: number; data?: unknown }[] = [];\n const startedAt = Date.now();\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n const colorScheme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n const host = root.host;\n const keep = dropOurs<(typeof events)[number]>(\n () => rrweb.record.mirror.getId(host),\n () => rrweb.record.mirror.getId(document.documentElement),\n );\n const stopRecording = rrweb.record({\n emit: (event) => {\n const kept = keep(event);\n if (kept !== undefined) events.push(kept);\n },\n blockClass: masking.blockClass,\n // deictic's own UI, the overlay: a blocked element is kept as an empty box its size, and it has none.\n blockSelector: ['deictic-overlay', ...(masking.blockSelector ? [masking.blockSelector] : [])].join(', '),\n maskTextClass: masking.maskTextClass,\n ...(masking.maskTextSelector ? { maskTextSelector: masking.maskTextSelector } : {}),\n maskAllInputs: masking.maskAllInputs,\n maskInputOptions: { password: true },\n inlineStylesheet: true,\n });\n\n // The marks, now and at each change: an SVG whose view is the page from its top left, at 1:1.\n const marks = use('annotations');\n // The toolbar's own, drawn while recording: shown with the page's, gone when it ends.\n const tools = marks?.tools();\n const mark = () => {\n const area = { x: -scrollX, y: -scrollY, width: 1, height: 1 };\n rrweb.record.addCustomEvent(MARKS, {\n svg: [marks?.svg(area), tools?.marks.svg(area)].filter(Boolean).join(''),\n // The same marks as data, in page coordinates, for whatever reads the recording but doesn't draw it.\n annotations: [...(marks?.list() ?? []), ...(tools?.marks.list() ?? [])],\n });\n };\n mark();\n const unsubscribe = [marks?.subscribe(mark), tools?.marks.subscribe(mark)];\n\n return new Promise((done, fail) => {\n const bar = document.createElement('div');\n bar.className = 'recorder';\n bar.setAttribute('role', 'toolbar');\n bar.setAttribute('aria-label', 'Recording');\n const grip = Object.assign(document.createElement('span'), { className: 'grip', title: 'Drag to any edge', innerHTML: GRIP });\n const live = Object.assign(document.createElement('span'), { className: 'live' });\n const dot = Object.assign(document.createElement('span'), { className: 'dot' });\n const time = document.createElement('span');\n live.append(dot, time);\n const sep = () => Object.assign(document.createElement('span'), { className: 'sep' });\n\n // The mic, where the voice plugin is loaded: each stretch it's on is a clip, at its time in the recording.\n const voice = use('voice');\n const clips: VoiceClip[] = [];\n let take: Take | undefined;\n // The mic's live waveform beside it while it's on, so it's plain it hears.\n const wave = Object.assign(document.createElement('canvas'), { className: 'wave', hidden: true });\n let stopWave: (() => void) | undefined;\n const unwave = () => {\n stopWave?.();\n stopWave = undefined;\n wave.hidden = true;\n };\n // What the mic is doing (asking for it, keeping a take): the next toggle, and the end, wait for it.\n let busy: Promise<void> = Promise.resolve();\n const micOff = async () => {\n const ending = take;\n take = undefined;\n unwave();\n if (ending === undefined) return;\n try {\n const clip = await ending.stop();\n clips.push({ id: clip.id, at: ending.started - startedAt, duration: clip.duration });\n } catch (e) {\n // The recording is worth keeping without it.\n console.warn('deictic: the voice clip was not kept', e);\n }\n };\n const mic = voice === undefined ? undefined : iconButton(MIC, 'Turn the mic on', () => toggle());\n const toggle = () => {\n busy = busy.then(async () => {\n if (voice === undefined || mic === undefined) return;\n if (take !== undefined) {\n await micOff();\n } else {\n try {\n take = await voice.start();\n mic.classList.remove('problem');\n wave.hidden = false;\n stopWave = liveWaveform(wave, take.stream, { played: '#ef4444', rest: '#52525b' });\n } catch (e) {\n mic.classList.add('problem');\n mic.title = e instanceof Error ? e.message : String(e);\n return;\n }\n }\n const on = take !== undefined;\n mic.setAttribute('aria-pressed', String(on));\n mic.title = on ? 'Turn the mic off' : 'Turn the mic on';\n mic.setAttribute('aria-label', mic.title);\n });\n };\n mic?.classList.add('mic');\n mic?.setAttribute('aria-pressed', 'false');\n\n const end = async (keep: boolean) => {\n rrweb.record.addCustomEvent(END, {});\n stopRecording?.();\n for (const stop of unsubscribe) stop?.();\n tools?.close();\n clearInterval(ticking);\n removeEventListener('resize', replace);\n bar.remove();\n await busy;\n if (!keep) {\n unwave();\n take?.cancel();\n return done(undefined);\n }\n await micOff();\n const duration = Date.now() - startedAt;\n const voiced = clips.length > 0 ? { voice: clips } : {};\n const kept: Kept = { page: location.href, viewport, colorScheme, startedAt, duration, events, ...voiced };\n try {\n const res = await request('add', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(kept),\n });\n // `url`: where it replays, said by what keeps it with no server to serve it from (a `standalone` build).\n const { id, url, problem } = (await res.json()) as { id?: string; url?: string; problem?: string };\n if (id === undefined) throw new Error(`recordings: ${problem ?? res.statusText}`);\n done({ id, url: url ?? `${base}__deictic/plugins/recordings/replay/${id}`, duration, ...voiced });\n } catch (e) {\n fail(e);\n }\n };\n const stop = iconButton(STOP, 'Stop, and keep the recording', () => void end(true));\n const discard = iconButton(DISCARD, 'Discard the recording', () => void end(false));\n bar.append(grip, live, ...(tools ? [sep(), tools.element] : []), sep(), ...(mic ? [mic, wave] : []), stop, discard);\n const style = Object.assign(document.createElement('style'), { textContent: STYLE });\n bar.prepend(style);\n root.append(bar);\n\n const tick = () => (time.textContent = clock(Date.now() - startedAt));\n tick();\n const ticking = setInterval(tick, 250);\n let dock = storedDock();\n const replace = () => place(bar, dock);\n replace();\n addEventListener('resize', replace);\n draggable(bar, grip, (next) => {\n dock = next;\n replace();\n try {\n localStorage.setItem(DOCK, JSON.stringify(dock));\n } catch {\n // Not kept, then: the next recording starts at the bottom.\n }\n });\n });\n };\n\n return {\n recording: () => going,\n record: async () => {\n if (going) throw new Error('recordings: one is going already: stop it first');\n going = true;\n try {\n return await record();\n } finally {\n going = false;\n }\n },\n };\n },\n});\n"],"mappings":";;;;;AAyBA,MAAM,cAAc;AACpB,MAAM,WAAW;AACjB,MAAM,4BAAY,IAAI,IAAI;CAAC;CAAG;CAAG;AAAE,CAAC;;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AQ,OAAO,OAAO,SAAS,cAAc,OAAO,GAAG,EAAE,aAAa,MAAM,CAAC;IACnF,IAAI,QAAQ,KAAK;IACjB,KAAK,OAAO,GAAG;IAEf,MAAM,aAAc,KAAK,cAAc,MAAM,KAAK,IAAI,IAAI,SAAS;IACnE,KAAK;IACL,MAAM,UAAU,YAAY,MAAM,GAAG;IACrC,IAAI,OAAO,WAAW;IACtB,MAAM,gBAAgB,MAAM,KAAK,IAAI;IACrC,QAAQ;IACR,iBAAiB,UAAU,OAAO;IAClC,UAAU,KAAK,OAAO,SAAS;KAC7B,OAAO;KACP,QAAQ;KACR,IAAI;MACF,aAAa,QAAQ,MAAM,KAAK,UAAU,IAAI,CAAC;KACjD,QAAQ,CAER;IACF,CAAC;GACH,CAAC;EACH;EAEA,OAAO;GACL,iBAAiB;GACjB,QAAQ,YAAY;IAClB,IAAI,OAAO,MAAM,IAAI,MAAM,iDAAiD;IAC5E,QAAQ;IACR,IAAI;KACF,OAAO,MAAM,OAAO;IACtB,UAAU;KACR,QAAQ;IACV;GACF;EACF;CACF;AACF,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RecordingsOptions, c as
|
|
2
|
-
export { Kept, MARKS, Recorder, Recording, Recordings, RecordingsOptions, VoiceClip, recordings as default, recordings };
|
|
1
|
+
import { a as RecordingsOptions, c as ReplaySources, i as Recordings, l as replayPage, n as Recorder, o as VoiceClip, r as Recording, s as recordings, t as Kept, u as MARKS } from "../shared/index3.js";
|
|
2
|
+
export { Kept, MARKS, Recorder, Recording, Recordings, RecordingsOptions, type ReplaySources, VoiceClip, recordings as default, recordings, replayPage };
|
package/dist/recordings/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as MARKS } from "../marks.js";
|
|
2
|
-
import { t as recordings } from "../recordings.js";
|
|
3
|
-
export { MARKS, recordings as default, recordings };
|
|
1
|
+
import { n as MARKS } from "../shared/marks.js";
|
|
2
|
+
import { n as replayPage, t as recordings } from "../shared/recordings.js";
|
|
3
|
+
export { MARKS, recordings as default, recordings, replayPage };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as CaptureOptions, r as Capture, s as ResolvedMasking, t as Box } from "../
|
|
1
|
+
import { i as CaptureOptions, r as Capture, s as ResolvedMasking, t as Box } from "../shared/index2.js";
|
|
2
2
|
/**
|
|
3
3
|
* What a renderer's page half makes of the element: a body for `add`, its type, and where the element is
|
|
4
4
|
* in the shot. `overlay(area)` is what's drawn over the page in that part of the viewport, in viewport CSS
|
|
@@ -36,11 +36,11 @@ function screenshotsClient(capture) {
|
|
|
36
36
|
headers: { "content-type": type },
|
|
37
37
|
body
|
|
38
38
|
});
|
|
39
|
-
const { id, problem } = await res.json();
|
|
39
|
+
const { id, url, problem } = await res.json();
|
|
40
40
|
if (id === void 0) throw new Error(`screenshots: ${problem ?? res.statusText}`);
|
|
41
41
|
return {
|
|
42
42
|
id,
|
|
43
|
-
url: `${base}__deictic/plugins/screenshots/shot/${id}`,
|
|
43
|
+
url: url ?? `${base}__deictic/plugins/screenshots/shot/${id}`,
|
|
44
44
|
box,
|
|
45
45
|
size
|
|
46
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/screenshots/client.ts"],"sourcesContent":["/**\n * The screenshots plugin's page half, around a renderer's capture: the renderer makes the shot (a PNG,\n * or what its server half makes one of), and this sends it to the plugin's `add` route and answers the\n * `Shot`. A renderer's page module default-exports `screenshotsClient(itsCapture)`.\n */\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { Annotations } from '#src/plugins/annotations/index.ts';\n\nimport type { Box, Capture, CaptureOptions, ResolvedMasking, Shot } from './index.ts';\n\n/**\n * What a renderer's page half makes of the element: a body for `add`, its type, and where the element is\n * in the shot. `overlay(area)` is what's drawn over the page in that part of the viewport, in viewport CSS\n * pixels, as an SVG that size, or nothing: the annotations plugin's marks, where it's loaded. The renderer\n * draws it over the shot, as deictic's own layers are left out.\n */\nexport type PageCapture = (\n element: Element,\n options: {\n area: NonNullable<CaptureOptions['area']>;\n masking: ResolvedMasking;\n renderer: unknown;\n overlay: (area: Box) => string | undefined;\n },\n) => Promise<{ body: Blob | string; type: string; box: Box }>;\n\n/** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */\nexport const notOurs = (node: Node) => !(node instanceof Element && node.localName === 'deictic-overlay');\n\n/** The element's box, in CSS pixels from the viewport's top left, or from its own for a shot of it alone. */\nexport function boxOf(element: Element, area: NonNullable<CaptureOptions['area']>): Box {\n const { x, y, width, height } = element.getBoundingClientRect();\n return area === 'element' ? { x: 0, y: 0, width, height } : { x, y, width, height };\n}\n\nexport function screenshotsClient(capture: PageCapture) {\n return defineClientPlugin<never, never, Capture>({\n name: 'screenshots',\n setup: ({ base, request, options, use }) => {\n const { masking, renderer } = options as { masking: ResolvedMasking; renderer: unknown };\n // Asked at each shot: the annotations plugin may be set up after this one.\n const overlay = (area: Box) => {\n const marks: Annotations | undefined = use('annotations');\n return marks?.svg(area);\n };\n const add = async (body: Blob | string, type: string, { box, size }: Pick<Shot, 'box' | 'size'>): Promise<Shot> => {\n const res = await request('add', { method: 'POST', headers: { 'content-type': type }, body });\n const { id, problem } = (await res.json()) as { id?: string; problem?: string };\n if (id === undefined) throw new Error(`screenshots: ${problem ?? res.statusText}`);\n return { id, url: `${base}__deictic/plugins/screenshots/shot/${id}`, box, size };\n };\n return {\n capture: async (element, { area = 'viewport' } = {}) => {\n const { body, type, box } = await capture(element, { area, masking, renderer, overlay });\n const { clientWidth, clientHeight } = document.documentElement;\n const size = area === 'element' ? { width: box.width, height: box.height } : { width: clientWidth, height: clientHeight };\n return add(body, type, { box, size });\n },\n upload: (png, of) => add(png, 'image/png', of),\n };\n },\n });\n}\n"],"mappings":";;;;;;;;AA2BA,MAAa,WAAW,SAAe,EAAE,gBAAgB,WAAW,KAAK,cAAc;;AAGvF,SAAgB,MAAM,SAAkB,MAAgD;CACtF,MAAM,EAAE,GAAG,GAAG,OAAO,WAAW,QAAQ,sBAAsB;CAC9D,OAAO,SAAS,YAAY;EAAE,GAAG;EAAG,GAAG;EAAG;EAAO;CAAO,IAAI;EAAE;EAAG;EAAG;EAAO;CAAO;AACpF;AAEA,SAAgB,kBAAkB,SAAsB;CACtD,OAAO,mBAA0C;EAC/C,MAAM;EACN,QAAQ,EAAE,MAAM,SAAS,SAAS,UAAU;GAC1C,MAAM,EAAE,SAAS,aAAa;GAE9B,MAAM,WAAW,SAAc;IAE7B,OADuC,IAAI,aAChC,CAAC,EAAE,IAAI,IAAI;GACxB;GACA,MAAM,MAAM,OAAO,MAAqB,MAAc,EAAE,KAAK,WAAsD;IACjH,MAAM,MAAM,MAAM,QAAQ,OAAO;KAAE,QAAQ;KAAQ,SAAS,EAAE,gBAAgB,KAAK;KAAG;IAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/screenshots/client.ts"],"sourcesContent":["/**\n * The screenshots plugin's page half, around a renderer's capture: the renderer makes the shot (a PNG,\n * or what its server half makes one of), and this sends it to the plugin's `add` route and answers the\n * `Shot`. A renderer's page module default-exports `screenshotsClient(itsCapture)`.\n */\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { Annotations } from '#src/plugins/annotations/index.ts';\n\nimport type { Box, Capture, CaptureOptions, ResolvedMasking, Shot } from './index.ts';\n\n/**\n * What a renderer's page half makes of the element: a body for `add`, its type, and where the element is\n * in the shot. `overlay(area)` is what's drawn over the page in that part of the viewport, in viewport CSS\n * pixels, as an SVG that size, or nothing: the annotations plugin's marks, where it's loaded. The renderer\n * draws it over the shot, as deictic's own layers are left out.\n */\nexport type PageCapture = (\n element: Element,\n options: {\n area: NonNullable<CaptureOptions['area']>;\n masking: ResolvedMasking;\n renderer: unknown;\n overlay: (area: Box) => string | undefined;\n },\n) => Promise<{ body: Blob | string; type: string; box: Box }>;\n\n/** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */\nexport const notOurs = (node: Node) => !(node instanceof Element && node.localName === 'deictic-overlay');\n\n/** The element's box, in CSS pixels from the viewport's top left, or from its own for a shot of it alone. */\nexport function boxOf(element: Element, area: NonNullable<CaptureOptions['area']>): Box {\n const { x, y, width, height } = element.getBoundingClientRect();\n return area === 'element' ? { x: 0, y: 0, width, height } : { x, y, width, height };\n}\n\nexport function screenshotsClient(capture: PageCapture) {\n return defineClientPlugin<never, never, Capture>({\n name: 'screenshots',\n setup: ({ base, request, options, use }) => {\n const { masking, renderer } = options as { masking: ResolvedMasking; renderer: unknown };\n // Asked at each shot: the annotations plugin may be set up after this one.\n const overlay = (area: Box) => {\n const marks: Annotations | undefined = use('annotations');\n return marks?.svg(area);\n };\n const add = async (body: Blob | string, type: string, { box, size }: Pick<Shot, 'box' | 'size'>): Promise<Shot> => {\n const res = await request('add', { method: 'POST', headers: { 'content-type': type }, body });\n // `url`: where the shot is, said by what keeps it with no server to serve it from (a `standalone` build).\n const { id, url, problem } = (await res.json()) as { id?: string; url?: string; problem?: string };\n if (id === undefined) throw new Error(`screenshots: ${problem ?? res.statusText}`);\n return { id, url: url ?? `${base}__deictic/plugins/screenshots/shot/${id}`, box, size };\n };\n return {\n capture: async (element, { area = 'viewport' } = {}) => {\n const { body, type, box } = await capture(element, { area, masking, renderer, overlay });\n const { clientWidth, clientHeight } = document.documentElement;\n const size = area === 'element' ? { width: box.width, height: box.height } : { width: clientWidth, height: clientHeight };\n return add(body, type, { box, size });\n },\n upload: (png, of) => add(png, 'image/png', of),\n };\n },\n });\n}\n"],"mappings":";;;;;;;;AA2BA,MAAa,WAAW,SAAe,EAAE,gBAAgB,WAAW,KAAK,cAAc;;AAGvF,SAAgB,MAAM,SAAkB,MAAgD;CACtF,MAAM,EAAE,GAAG,GAAG,OAAO,WAAW,QAAQ,sBAAsB;CAC9D,OAAO,SAAS,YAAY;EAAE,GAAG;EAAG,GAAG;EAAG;EAAO;CAAO,IAAI;EAAE;EAAG;EAAG;EAAO;CAAO;AACpF;AAEA,SAAgB,kBAAkB,SAAsB;CACtD,OAAO,mBAA0C;EAC/C,MAAM;EACN,QAAQ,EAAE,MAAM,SAAS,SAAS,UAAU;GAC1C,MAAM,EAAE,SAAS,aAAa;GAE9B,MAAM,WAAW,SAAc;IAE7B,OADuC,IAAI,aAChC,CAAC,EAAE,IAAI,IAAI;GACxB;GACA,MAAM,MAAM,OAAO,MAAqB,MAAc,EAAE,KAAK,WAAsD;IACjH,MAAM,MAAM,MAAM,QAAQ,OAAO;KAAE,QAAQ;KAAQ,SAAS,EAAE,gBAAgB,KAAK;KAAG;IAAK,CAAC;IAE5F,MAAM,EAAE,IAAI,KAAK,YAAa,MAAM,IAAI,KAAK;IAC7C,IAAI,OAAO,KAAA,GAAW,MAAM,IAAI,MAAM,gBAAgB,WAAW,IAAI,YAAY;IACjF,OAAO;KAAE;KAAI,KAAK,OAAO,GAAG,KAAK,qCAAqC;KAAM;KAAK;IAAK;GACxF;GACA,OAAO;IACL,SAAS,OAAO,SAAS,EAAE,OAAO,eAAe,CAAC,MAAM;KACtD,MAAM,EAAE,MAAM,MAAM,QAAQ,MAAM,QAAQ,SAAS;MAAE;MAAM;MAAS;MAAU;KAAQ,CAAC;KACvF,MAAM,EAAE,aAAa,iBAAiB,SAAS;KAC/C,MAAM,OAAO,SAAS,YAAY;MAAE,OAAO,IAAI;MAAO,QAAQ,IAAI;KAAO,IAAI;MAAE,OAAO;MAAa,QAAQ;KAAa;KACxH,OAAO,IAAI,MAAM,MAAM;MAAE;MAAK;KAAK,CAAC;IACtC;IACA,SAAS,KAAK,OAAO,IAAI,KAAK,aAAa,EAAE;GAC/C;EACF;CACF,CAAC;AACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as Masking, c as Screenshots, d as dom, f as rrweb, i as CaptureOptions, l as ScreenshotsOptions, n as BrowserOptions, o as Renderer, p as screenshots, r as Capture, s as ResolvedMasking, t as Box, u as Shot } from "../
|
|
1
|
+
import { a as Masking, c as Screenshots, d as dom, f as rrweb, i as CaptureOptions, l as ScreenshotsOptions, n as BrowserOptions, o as Renderer, p as screenshots, r as Capture, s as ResolvedMasking, t as Box, u as Shot } from "../shared/index2.js";
|
|
2
2
|
export { Box, BrowserOptions, Capture, CaptureOptions, Masking, Renderer, ResolvedMasking, Screenshots, ScreenshotsOptions, Shot, screenshots as default, screenshots, dom, rrweb };
|