autokast 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +165 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +300 -0
  5. package/dist/index.d.ts +4 -0
  6. package/dist/index.js +4 -0
  7. package/dist/inspect.d.ts +26 -0
  8. package/dist/inspect.js +193 -0
  9. package/dist/record/animations.d.ts +7 -0
  10. package/dist/record/animations.js +34 -0
  11. package/dist/record/capture.d.ts +85 -0
  12. package/dist/record/capture.js +202 -0
  13. package/dist/record/cast.d.ts +142 -0
  14. package/dist/record/cast.js +680 -0
  15. package/dist/record/cursor-style.d.ts +33 -0
  16. package/dist/record/cursor-style.js +252 -0
  17. package/dist/record/defaults.d.ts +96 -0
  18. package/dist/record/defaults.js +125 -0
  19. package/dist/record/editor.d.ts +11 -0
  20. package/dist/record/editor.js +48 -0
  21. package/dist/record/frame-pump.d.ts +91 -0
  22. package/dist/record/frame-pump.js +306 -0
  23. package/dist/record/index.d.ts +11 -0
  24. package/dist/record/index.js +287 -0
  25. package/dist/record/motion.d.ts +48 -0
  26. package/dist/record/motion.js +112 -0
  27. package/dist/record/pace.d.ts +69 -0
  28. package/dist/record/pace.js +133 -0
  29. package/dist/record/random.d.ts +12 -0
  30. package/dist/record/random.js +24 -0
  31. package/dist/record/scroll.d.ts +71 -0
  32. package/dist/record/scroll.js +249 -0
  33. package/dist/record/timeline.d.ts +34 -0
  34. package/dist/record/timeline.js +44 -0
  35. package/dist/render/background.d.ts +12 -0
  36. package/dist/render/background.js +209 -0
  37. package/dist/render/browser.d.ts +46 -0
  38. package/dist/render/browser.js +223 -0
  39. package/dist/render/camera.d.ts +119 -0
  40. package/dist/render/camera.js +372 -0
  41. package/dist/render/captions.d.ts +114 -0
  42. package/dist/render/captions.js +254 -0
  43. package/dist/render/color.d.ts +23 -0
  44. package/dist/render/color.js +78 -0
  45. package/dist/render/compositor.d.ts +185 -0
  46. package/dist/render/compositor.js +656 -0
  47. package/dist/render/cursor.d.ts +85 -0
  48. package/dist/render/cursor.js +314 -0
  49. package/dist/render/cursors/shapes.d.ts +34 -0
  50. package/dist/render/cursors/shapes.js +268 -0
  51. package/dist/render/defaults.d.ts +91 -0
  52. package/dist/render/defaults.js +139 -0
  53. package/dist/render/easing.d.ts +13 -0
  54. package/dist/render/easing.js +40 -0
  55. package/dist/render/effects.d.ts +39 -0
  56. package/dist/render/effects.js +91 -0
  57. package/dist/render/encoder.d.ts +52 -0
  58. package/dist/render/encoder.js +226 -0
  59. package/dist/render/index.d.ts +19 -0
  60. package/dist/render/index.js +138 -0
  61. package/dist/render/keycaps.d.ts +67 -0
  62. package/dist/render/keycaps.js +270 -0
  63. package/dist/render/scene.d.ts +59 -0
  64. package/dist/render/scene.js +230 -0
  65. package/dist/render/source.d.ts +21 -0
  66. package/dist/render/source.js +57 -0
  67. package/dist/render/spring.d.ts +11 -0
  68. package/dist/render/spring.js +47 -0
  69. package/dist/render/stage.d.ts +59 -0
  70. package/dist/render/stage.js +91 -0
  71. package/dist/render/timeline.d.ts +70 -0
  72. package/dist/render/timeline.js +157 -0
  73. package/dist/session.d.ts +14 -0
  74. package/dist/session.js +33 -0
  75. package/dist/types.d.ts +708 -0
  76. package/dist/types.js +1 -0
  77. package/package.json +61 -3
  78. package/skills/autokast/SKILL.md +300 -0
  79. package/skills/autokast/reference/jupyterlab.md +100 -0
@@ -0,0 +1,33 @@
1
+ import type { BrowserContext, Page } from 'playwright';
2
+ import type { CursorStyle, Point } from '../types.ts';
3
+ /**
4
+ * Maps a computed CSS `cursor` value to a cursor style the renderer can draw.
5
+ * Custom `url()` cursors use their keyword fallback. `auto` gives `default` here: the page
6
+ * probe resolves it first. This function runs in the page too, so it is self-contained.
7
+ */
8
+ export declare function mapCssCursor(value: string): CursorStyle;
9
+ /**
10
+ * Tracks the cursor style that the page shows under the pointer.
11
+ * `pointer` must follow the mouse so that a new document can probe before any mouse move.
12
+ */
13
+ export declare class CursorStyleProbe {
14
+ style: CursorStyle;
15
+ pointer: Point;
16
+ onChange?: (style: CursorStyle) => void;
17
+ private mainStyle;
18
+ private childStyle;
19
+ /**
20
+ * Installs the bindings and the init script. Call before the page is created.
21
+ */
22
+ install(context: BrowserContext): Promise<void>;
23
+ /**
24
+ * Probes the main frame now, at the current pointer position.
25
+ */
26
+ refresh(page: Page): Promise<void>;
27
+ /**
28
+ * Takes a report from a frame. Reports from frames can arrive in any order, so the style
29
+ * comes from the last report of the main frame, or of a child frame when the main frame
30
+ * says that the pointer is over a frame.
31
+ */
32
+ private report;
33
+ }
@@ -0,0 +1,252 @@
1
+ const REPORT_BINDING = '__autokastCursorStyle';
2
+ const POINTER_BINDING = '__autokastPointer';
3
+ const PROBE_FUNCTION = '__autokastProbe';
4
+ /**
5
+ * Reported by a frame when the pointer is over a child frame, which reports for itself.
6
+ */
7
+ const OVER_FRAME = 'frame';
8
+ /**
9
+ * Maps a computed CSS `cursor` value to a cursor style the renderer can draw.
10
+ * Custom `url()` cursors use their keyword fallback. `auto` gives `default` here: the page
11
+ * probe resolves it first. This function runs in the page too, so it is self-contained.
12
+ */
13
+ export function mapCssCursor(value) {
14
+ const aliases = {
15
+ 'col-resize': 'ew-resize',
16
+ 'e-resize': 'ew-resize',
17
+ 'w-resize': 'ew-resize',
18
+ 'row-resize': 'ns-resize',
19
+ 'n-resize': 'ns-resize',
20
+ 's-resize': 'ns-resize',
21
+ 'ne-resize': 'nesw-resize',
22
+ 'sw-resize': 'nesw-resize',
23
+ 'nw-resize': 'nwse-resize',
24
+ 'se-resize': 'nwse-resize',
25
+ 'all-scroll': 'move',
26
+ 'vertical-text': 'text',
27
+ 'no-drop': 'not-allowed',
28
+ '-webkit-grab': 'grab',
29
+ '-webkit-grabbing': 'grabbing',
30
+ };
31
+ const known = [
32
+ 'default',
33
+ 'pointer',
34
+ 'text',
35
+ 'grab',
36
+ 'grabbing',
37
+ 'crosshair',
38
+ 'move',
39
+ 'ew-resize',
40
+ 'ns-resize',
41
+ 'nesw-resize',
42
+ 'nwse-resize',
43
+ 'not-allowed',
44
+ 'none',
45
+ ];
46
+ const keyword = (value.split(',').pop() ?? '').trim().toLowerCase();
47
+ if (keyword in aliases) {
48
+ return aliases[keyword];
49
+ }
50
+ return known.includes(keyword) ? keyword : 'default';
51
+ }
52
+ /**
53
+ * In-page probe that reports the effective cursor under the pointer when it changes.
54
+ * Serialized into an init script: it must not use anything from the outer scope.
55
+ */
56
+ function cursorProbe(config, toStyle) {
57
+ const win = window;
58
+ if (win[config.probe]) {
59
+ return;
60
+ }
61
+ const isTop = window === window.top;
62
+ const textInputs = new Set(['text', 'search', 'email', 'url', 'tel', 'password', 'number']);
63
+ let pointer = null;
64
+ let last = '';
65
+ const send = (style) => {
66
+ const report = win[config.report];
67
+ if (typeof report === 'function') {
68
+ Promise.resolve(report(style)).catch(() => { });
69
+ }
70
+ };
71
+ const elementAt = (x, y) => {
72
+ const roots = [];
73
+ let element = document.elementFromPoint(x, y);
74
+ while (element?.shadowRoot) {
75
+ const inner = element.shadowRoot.elementFromPoint(x, y);
76
+ if (!inner || inner === element) {
77
+ break;
78
+ }
79
+ roots.push(element.shadowRoot);
80
+ element = inner;
81
+ }
82
+ return { element, roots };
83
+ };
84
+ const isEditable = (element) => {
85
+ if (element.isContentEditable) {
86
+ return true;
87
+ }
88
+ if (element instanceof HTMLTextAreaElement) {
89
+ return !element.disabled;
90
+ }
91
+ return element instanceof HTMLInputElement && !element.disabled && textInputs.has(element.type);
92
+ };
93
+ const isOverText = (element, roots, x, y) => {
94
+ let node = null;
95
+ if (document.caretPositionFromPoint) {
96
+ node = document.caretPositionFromPoint(x, y, { shadowRoots: roots })?.offsetNode ?? null;
97
+ }
98
+ else {
99
+ node = document.caretRangeFromPoint?.(x, y)?.startContainer ?? null;
100
+ }
101
+ if (!node || node.nodeType !== Node.TEXT_NODE || !element.contains(node)) {
102
+ return false;
103
+ }
104
+ const parent = node.parentElement;
105
+ if (!parent || getComputedStyle(parent).userSelect === 'none') {
106
+ return false;
107
+ }
108
+ const range = document.createRange();
109
+ range.selectNodeContents(node);
110
+ return Array.from(range.getClientRects()).some((rect) => x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom);
111
+ };
112
+ const styleAt = (x, y) => {
113
+ const { element, roots } = elementAt(x, y);
114
+ if (!element) {
115
+ return 'default';
116
+ }
117
+ if (/^(IFRAME|FRAME|EMBED|OBJECT)$/.test(element.tagName)) {
118
+ return config.overFrame;
119
+ }
120
+ const value = getComputedStyle(element).cursor;
121
+ if ((value.split(',').pop() ?? '').trim() !== 'auto') {
122
+ return toStyle(value);
123
+ }
124
+ return isEditable(element) || isOverText(element, roots, x, y) ? 'text' : 'default';
125
+ };
126
+ const probe = (force = false) => {
127
+ if (!pointer || !document.documentElement) {
128
+ return null;
129
+ }
130
+ let style = 'default';
131
+ try {
132
+ style = styleAt(pointer.x, pointer.y);
133
+ }
134
+ catch {
135
+ // Keep the default style when the document is in a transient state.
136
+ }
137
+ if (style !== last || force) {
138
+ last = style;
139
+ send(style);
140
+ }
141
+ return style;
142
+ };
143
+ const later = () => {
144
+ requestAnimationFrame(() => probe());
145
+ setTimeout(() => probe(), 150);
146
+ };
147
+ Object.defineProperty(window, config.probe, {
148
+ value: (point) => {
149
+ if (point) {
150
+ pointer = point;
151
+ }
152
+ return probe(true);
153
+ },
154
+ });
155
+ const options = { capture: true, passive: true };
156
+ // The top document gets no mousemove while the pointer is over a child frame, but it gets
157
+ // mouseover on the frame element. A child frame reports on entry, even without a change.
158
+ const track = (event) => {
159
+ const entering = !pointer;
160
+ pointer = { x: event.clientX, y: event.clientY };
161
+ probe(entering && !isTop);
162
+ };
163
+ addEventListener('mousemove', track, options);
164
+ addEventListener('mouseover', track, options);
165
+ addEventListener('mouseout', (event) => {
166
+ if (!isTop && !event.relatedTarget) {
167
+ pointer = null;
168
+ }
169
+ }, options);
170
+ for (const type of ['mousedown', 'mouseup', 'click', 'keydown', 'keyup', 'wheel', 'scroll']) {
171
+ addEventListener(type, later, options);
172
+ }
173
+ addEventListener('DOMContentLoaded', later);
174
+ addEventListener('load', later);
175
+ setInterval(() => probe(), 250);
176
+ const getPointer = win[config.pointer];
177
+ if (isTop && typeof getPointer === 'function') {
178
+ Promise.resolve(getPointer())
179
+ .then((point) => {
180
+ if (point && !pointer) {
181
+ pointer = point;
182
+ probe();
183
+ }
184
+ })
185
+ .catch(() => { });
186
+ }
187
+ }
188
+ /**
189
+ * Tracks the cursor style that the page shows under the pointer.
190
+ * `pointer` must follow the mouse so that a new document can probe before any mouse move.
191
+ */
192
+ export class CursorStyleProbe {
193
+ style = 'default';
194
+ pointer = { x: 0, y: 0 };
195
+ onChange;
196
+ mainStyle = 'default';
197
+ childStyle = 'default';
198
+ /**
199
+ * Installs the bindings and the init script. Call before the page is created.
200
+ */
201
+ async install(context) {
202
+ await context.exposeBinding(REPORT_BINDING, (source, style) => {
203
+ this.report(source.frame, source.page, style);
204
+ });
205
+ await context.exposeBinding(POINTER_BINDING, (source) => source.frame === source.page.mainFrame() ? this.pointer : null);
206
+ const config = {
207
+ report: REPORT_BINDING,
208
+ pointer: POINTER_BINDING,
209
+ probe: PROBE_FUNCTION,
210
+ overFrame: OVER_FRAME,
211
+ };
212
+ await context.addInitScript({
213
+ content: `(${cursorProbe.toString()})(${JSON.stringify(config)}, ${mapCssCursor.toString()});`,
214
+ });
215
+ }
216
+ /**
217
+ * Probes the main frame now, at the current pointer position.
218
+ */
219
+ async refresh(page) {
220
+ const style = await page
221
+ .evaluate(([name, point]) => {
222
+ const probe = window[name];
223
+ return typeof probe === 'function' ? probe(point) : null;
224
+ }, [PROBE_FUNCTION, this.pointer])
225
+ .catch(() => null);
226
+ if (style) {
227
+ this.report(page.mainFrame(), page, style);
228
+ }
229
+ }
230
+ /**
231
+ * Takes a report from a frame. Reports from frames can arrive in any order, so the style
232
+ * comes from the last report of the main frame, or of a child frame when the main frame
233
+ * says that the pointer is over a frame.
234
+ */
235
+ report(frame, page, style) {
236
+ if (typeof style !== 'string') {
237
+ return;
238
+ }
239
+ if (frame === page.mainFrame()) {
240
+ this.mainStyle = style;
241
+ }
242
+ else {
243
+ this.childStyle = style;
244
+ }
245
+ const effective = this.mainStyle === OVER_FRAME ? this.childStyle : this.mainStyle;
246
+ if (mapCssCursor(effective) !== effective || effective === this.style) {
247
+ return;
248
+ }
249
+ this.style = effective;
250
+ this.onChange?.(this.style);
251
+ }
252
+ }
@@ -0,0 +1,96 @@
1
+ import type { BrowserOptions, CaptureOptions, CursorMotionOptions, PacingOptions, RecordOptions, RenderOptions, Size, TypingOptions } from '../types.ts';
2
+ /**
3
+ * Default record options.
4
+ */
5
+ export declare const DEFAULTS: {
6
+ readonly name: "screencast";
7
+ readonly viewport: {
8
+ readonly width: 1280;
9
+ readonly height: 720;
10
+ };
11
+ readonly deviceScaleFactor: 2;
12
+ readonly capture: {
13
+ readonly mode: "realtime";
14
+ readonly fps: 60;
15
+ readonly clockLead: 600000;
16
+ readonly format: "jpeg";
17
+ readonly quality: 92;
18
+ };
19
+ readonly cursor: {
20
+ readonly speed: 1;
21
+ readonly curvature: 0.2;
22
+ readonly minDuration: 220;
23
+ readonly maxDuration: 1000;
24
+ };
25
+ readonly typing: {
26
+ readonly delay: 45;
27
+ readonly variance: 0.35;
28
+ };
29
+ readonly pacing: {
30
+ readonly startDelay: 400;
31
+ readonly endDelay: 900;
32
+ readonly beforeClick: 60;
33
+ readonly afterClick: 180;
34
+ readonly afterType: 120;
35
+ readonly pressDuration: 90;
36
+ };
37
+ readonly scrollBehavior: "smooth";
38
+ readonly timeout: 10000;
39
+ };
40
+ /**
41
+ * Defaults of the Cast calls, in milliseconds.
42
+ */
43
+ export declare const CAST_DEFAULTS: {
44
+ hoverHold: number;
45
+ zoomDuration: number;
46
+ /**
47
+ * By default a camera move blocks only for this part of its duration, at most
48
+ * `zoomWaitMax` ms: the next action overlaps the rest of the move.
49
+ */
50
+ zoomWaitPart: number;
51
+ zoomWaitMax: number;
52
+ spotlightDuration: number;
53
+ captionBase: number;
54
+ captionPerChar: number;
55
+ /**
56
+ * Typing of a URL in the address bar: time for each character, the longest time for
57
+ * the whole URL, and the pause between the last character and the page change.
58
+ */
59
+ addressPerChar: number;
60
+ addressMax: number;
61
+ addressEnter: number;
62
+ addressShow: number;
63
+ dragHold: number;
64
+ dragSlowdown: number;
65
+ dragMinDuration: number;
66
+ doubleClickGap: number;
67
+ };
68
+ /**
69
+ * Record options with every default applied.
70
+ */
71
+ export interface ResolvedOptions {
72
+ name: string;
73
+ url?: string;
74
+ viewport: Size;
75
+ deviceScaleFactor: number;
76
+ colorScheme?: 'light' | 'dark';
77
+ sessionDir: string;
78
+ browser: BrowserOptions;
79
+ capture: Required<CaptureOptions>;
80
+ cursor: Required<CursorMotionOptions>;
81
+ typing: Required<TypingOptions>;
82
+ pacing: Required<PacingOptions>;
83
+ scrollBehavior: 'smooth' | 'instant';
84
+ timeout: number;
85
+ seed: number;
86
+ render?: RenderOptions;
87
+ }
88
+ /**
89
+ * Applies the defaults to record options and validates them.
90
+ */
91
+ export declare function resolveOptions(options?: RecordOptions): ResolvedOptions;
92
+ /**
93
+ * Deep-merges `overrides` into `base`. Plain objects merge; other values replace.
94
+ * Undefined values in `overrides` are ignored.
95
+ */
96
+ export declare function mergeOptions<T extends object>(base: T, overrides?: Partial<T>): T;
@@ -0,0 +1,125 @@
1
+ import path from 'node:path';
2
+ import { hashString } from "./random.js";
3
+ /**
4
+ * Default record options.
5
+ */
6
+ export const DEFAULTS = {
7
+ name: 'screencast',
8
+ viewport: { width: 1280, height: 720 },
9
+ deviceScaleFactor: 2,
10
+ capture: { mode: 'realtime', fps: 60, clockLead: 600_000, format: 'jpeg', quality: 92 },
11
+ cursor: { speed: 1, curvature: 0.2, minDuration: 220, maxDuration: 1000 },
12
+ typing: { delay: 45, variance: 0.35 },
13
+ pacing: {
14
+ startDelay: 400,
15
+ endDelay: 900,
16
+ beforeClick: 60,
17
+ afterClick: 180,
18
+ afterType: 120,
19
+ pressDuration: 90,
20
+ },
21
+ scrollBehavior: 'smooth',
22
+ timeout: 10_000,
23
+ };
24
+ /**
25
+ * Defaults of the Cast calls, in milliseconds.
26
+ */
27
+ export const CAST_DEFAULTS = {
28
+ hoverHold: 450,
29
+ zoomDuration: 900,
30
+ /**
31
+ * By default a camera move blocks only for this part of its duration, at most
32
+ * `zoomWaitMax` ms: the next action overlaps the rest of the move.
33
+ */
34
+ zoomWaitPart: 0.35,
35
+ zoomWaitMax: 320,
36
+ spotlightDuration: 2000,
37
+ captionBase: 1500,
38
+ captionPerChar: 55,
39
+ /**
40
+ * Typing of a URL in the address bar: time for each character, the longest time for
41
+ * the whole URL, and the pause between the last character and the page change.
42
+ */
43
+ addressPerChar: 32,
44
+ addressMax: 1500,
45
+ addressEnter: 380,
46
+ addressShow: 2000,
47
+ dragHold: 110,
48
+ dragSlowdown: 1.6,
49
+ dragMinDuration: 700,
50
+ doubleClickGap: 70,
51
+ };
52
+ function check(condition, message) {
53
+ if (!condition) {
54
+ throw new Error(`Invalid record options: ${message}`);
55
+ }
56
+ }
57
+ /**
58
+ * Applies the defaults to record options and validates them.
59
+ */
60
+ export function resolveOptions(options = {}) {
61
+ const name = options.name ?? DEFAULTS.name;
62
+ const viewport = { ...DEFAULTS.viewport, ...options.viewport };
63
+ const deviceScaleFactor = options.deviceScaleFactor ?? DEFAULTS.deviceScaleFactor;
64
+ const capture = { ...DEFAULTS.capture, ...options.capture };
65
+ const cursor = {
66
+ start: { x: viewport.width / 2, y: viewport.height / 2 },
67
+ ...DEFAULTS.cursor,
68
+ ...options.cursor,
69
+ };
70
+ const typing = { ...DEFAULTS.typing, ...options.typing };
71
+ const pacing = { ...DEFAULTS.pacing, ...options.pacing };
72
+ const timeout = options.timeout ?? DEFAULTS.timeout;
73
+ const safeName = name.replace(/[^\w.-]+/g, '-').replace(/^\.+/, '') || DEFAULTS.name;
74
+ check(Number.isInteger(viewport.width) && Number.isInteger(viewport.height), `viewport must have integer width and height, got ${JSON.stringify(options.viewport)}`);
75
+ check(viewport.width > 0 && viewport.height > 0, 'viewport width and height must be above 0');
76
+ check(deviceScaleFactor > 0, `deviceScaleFactor must be above 0, got ${deviceScaleFactor}`);
77
+ check(capture.quality >= 0 && capture.quality <= 100, 'capture.quality must be 0-100');
78
+ check(capture.mode === 'realtime' || capture.mode === 'frame-perfect', `capture.mode must be "realtime" or "frame-perfect", got ${JSON.stringify(capture.mode)}`);
79
+ check(capture.fps > 0 && capture.fps <= 240, `capture.fps must be 1-240, got ${capture.fps}`);
80
+ check(Number.isFinite(capture.clockLead) && capture.clockLead >= 0, `capture.clockLead must be 0 or more milliseconds, got ${capture.clockLead}`);
81
+ check(cursor.speed > 0, `cursor.speed must be above 0, got ${cursor.speed}`);
82
+ check(cursor.minDuration <= cursor.maxDuration, 'cursor.minDuration > cursor.maxDuration');
83
+ check(typing.delay >= 0, 'typing.delay must not be negative');
84
+ check(timeout > 0, `timeout must be above 0 ms, got ${timeout}`);
85
+ return {
86
+ name,
87
+ url: options.url,
88
+ viewport,
89
+ deviceScaleFactor,
90
+ colorScheme: options.colorScheme,
91
+ sessionDir: path.resolve(options.sessionDir ?? path.join('.autokast', safeName)),
92
+ browser: options.browser ?? {},
93
+ capture,
94
+ cursor,
95
+ typing,
96
+ pacing,
97
+ scrollBehavior: options.scrollBehavior ?? DEFAULTS.scrollBehavior,
98
+ timeout,
99
+ seed: options.seed ?? hashString(name),
100
+ render: options.render,
101
+ };
102
+ }
103
+ function isPlainObject(value) {
104
+ if (typeof value !== 'object' || value === null) {
105
+ return false;
106
+ }
107
+ const proto = Object.getPrototypeOf(value);
108
+ return proto === Object.prototype || proto === null;
109
+ }
110
+ /**
111
+ * Deep-merges `overrides` into `base`. Plain objects merge; other values replace.
112
+ * Undefined values in `overrides` are ignored.
113
+ */
114
+ export function mergeOptions(base, overrides) {
115
+ const result = { ...base };
116
+ for (const [key, value] of Object.entries(overrides ?? {})) {
117
+ if (value === undefined) {
118
+ continue;
119
+ }
120
+ const current = result[key];
121
+ result[key] =
122
+ isPlainObject(current) && isPlainObject(value) ? mergeOptions(current, value) : value;
123
+ }
124
+ return result;
125
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * In-page: the text between the start of the caret's line and the caret, in the focused
3
+ * editable element. Works for text inputs, textareas and contenteditable editors such as
4
+ * CodeMirror (`.cm-line`). Null when no editable element has the focus.
5
+ * Playwright serializes this function into the page: it must be self-contained.
6
+ */
7
+ export declare function caretLinePrefix(): string | null;
8
+ /**
9
+ * The spaces and tabs at the start of a line.
10
+ */
11
+ export declare function leadingWhitespace(line: string): string;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * In-page: the text between the start of the caret's line and the caret, in the focused
3
+ * editable element. Works for text inputs, textareas and contenteditable editors such as
4
+ * CodeMirror (`.cm-line`). Null when no editable element has the focus.
5
+ * Playwright serializes this function into the page: it must be self-contained.
6
+ */
7
+ export function caretLinePrefix() {
8
+ let active = document.activeElement;
9
+ while (active?.shadowRoot?.activeElement) {
10
+ active = active.shadowRoot.activeElement;
11
+ }
12
+ if (active instanceof HTMLTextAreaElement || active instanceof HTMLInputElement) {
13
+ const end = active.selectionStart;
14
+ if (end === null) {
15
+ return null;
16
+ }
17
+ return active.value.slice(active.value.lastIndexOf('\n', end - 1) + 1, end);
18
+ }
19
+ if (!(active instanceof HTMLElement) || !active.isContentEditable) {
20
+ return null;
21
+ }
22
+ const root = active.getRootNode();
23
+ const selection = ('getSelection' in root && typeof root.getSelection === 'function'
24
+ ? root.getSelection()
25
+ : null) ?? document.getSelection();
26
+ const caret = selection?.focusNode;
27
+ if (!selection || !caret || !active.contains(caret)) {
28
+ return null;
29
+ }
30
+ let line = caret instanceof Element ? caret : caret.parentElement;
31
+ while (line && line !== active) {
32
+ if (line.classList.contains('cm-line') || !/^inline/.test(getComputedStyle(line).display)) {
33
+ break;
34
+ }
35
+ line = line.parentElement;
36
+ }
37
+ const range = document.createRange();
38
+ range.setStart(line ?? active, 0);
39
+ range.setEnd(caret, selection.focusOffset);
40
+ const text = range.toString().replace(/ /g, ' ');
41
+ return text.slice(text.lastIndexOf('\n') + 1);
42
+ }
43
+ /**
44
+ * The spaces and tabs at the start of a line.
45
+ */
46
+ export function leadingWhitespace(line) {
47
+ return /^[ \t]*/.exec(line)[0];
48
+ }
@@ -0,0 +1,91 @@
1
+ import type { BrowserContext, Page } from 'playwright';
2
+ import type { FrameRef, Size } from '../types.ts';
3
+ import { type Capture } from './capture.ts';
4
+ /**
5
+ * Chromium flags for frame-perfect capture: the page paints only on BeginFrame, and all
6
+ * animation and scrolling runs on the main thread, on the page clock.
7
+ */
8
+ export declare const FRAME_PERFECT_ARGS: string[];
9
+ /**
10
+ * Page script for frame-perfect capture. Under the page clock, Chromium can hold idle
11
+ * callbacks after input until the end of the recording: run them on timers, which follow
12
+ * the page clock. The JupyterLab cell toolbar, for example, shows from an idle callback.
13
+ */
14
+ export declare function idleCallbacksOnTimers(): void;
15
+ export interface PumpSettings {
16
+ fps: number;
17
+ /**
18
+ * How far the page's wall clock starts ahead of the real clock, in ms.
19
+ */
20
+ clockLead: number;
21
+ format: 'jpeg' | 'png';
22
+ quality: number;
23
+ }
24
+ /**
25
+ * Drives the page clock for frame-perfect capture. Before the recording, a free-running loop
26
+ * sends frames in real time, so that the page loads and Playwright works. During the
27
+ * recording, each step advances virtual time by one frame, sends the queued input, and
28
+ * captures the frame. Record time is `frame * frameMs`.
29
+ */
30
+ export declare class FramePump implements Capture {
31
+ readonly frameMs: number;
32
+ private readonly cdp;
33
+ private readonly settings;
34
+ private readonly writer;
35
+ private frame;
36
+ private virtual;
37
+ private base;
38
+ private baseVirtual;
39
+ private running;
40
+ private freeRunning;
41
+ private loop;
42
+ private freeLoop;
43
+ private capturing;
44
+ private lastImage?;
45
+ private end;
46
+ private inputs;
47
+ private readonly unsettled;
48
+ private waiters;
49
+ private error?;
50
+ private constructor();
51
+ static create(context: BrowserContext, page: Page, dir: string, settings: PumpSettings): Promise<FramePump>;
52
+ get frames(): FrameRef[];
53
+ get frameSize(): Size | undefined;
54
+ /**
55
+ * Record time in ms: the time of the last frame.
56
+ */
57
+ now(): number;
58
+ /**
59
+ * Sends frames in real time, without the page clock, until `start()`.
60
+ */
61
+ startFreeRun(): void;
62
+ /**
63
+ * Pauses the page clock and starts the recording. Resolves once frame 0 is captured.
64
+ */
65
+ start(): Promise<void>;
66
+ /**
67
+ * Stops at record time `end`, after the frame in progress, and waits for the writes.
68
+ * The page then gets no more frames.
69
+ */
70
+ stop(end?: number): Promise<FrameRef[]>;
71
+ /**
72
+ * Resolves once `ms` of page time has passed, rounded to whole frames.
73
+ */
74
+ wait(ms: number): Promise<void>;
75
+ /**
76
+ * Sends input right before the next frame. `send` gets the record time of that frame.
77
+ * Resolves with that time once the input is sent, without waiting for its acknowledgement.
78
+ */
79
+ input(send: (t: number) => unknown): Promise<number>;
80
+ /**
81
+ * Turns screenshots off (inside cut regions) or on. Without screenshots, page time runs
82
+ * as fast as the page can render.
83
+ */
84
+ capture(on: boolean): void;
85
+ private waitFrame;
86
+ private fail;
87
+ private run;
88
+ private sendInputs;
89
+ private advance;
90
+ private beginFrame;
91
+ }