@phil65/demoreel 0.1.0 → 0.4.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 +52 -8
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/args.js +34 -0
- package/dist/cli.js +223 -5
- package/dist/compose.d.ts +4 -0
- package/dist/compose.js +4 -0
- package/dist/gif.d.ts +16 -0
- package/dist/gif.js +19 -0
- package/dist/idle.d.ts +8 -2
- package/dist/idle.js +12 -10
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -4
- package/dist/marks.js +5 -4
- package/dist/motion.d.ts +1 -1
- package/dist/motion.js +3 -3
- package/dist/openscreen/project.js +3 -3
- package/dist/project.d.ts +51 -1
- package/dist/project.js +89 -1
- package/dist/record.d.ts +45 -3
- package/dist/record.js +110 -31
- package/dist/recorder.d.ts +1 -0
- package/dist/recorder.js +8 -0
- package/dist/renderer/assets/CanvasPool-PBu3bHFZ.js +1 -0
- package/dist/renderer/assets/CanvasRenderer-HmF-4gyW.js +1 -0
- package/dist/renderer/assets/RenderTargetSystem-Dk1U4wDJ.js +184 -0
- package/dist/renderer/assets/WebGLRenderer-C0v9HBel.js +149 -0
- package/dist/renderer/assets/WebGPURenderer-Ce0-U9Q1.js +95 -0
- package/dist/renderer/assets/{browserAll-aHn2isHo.js → browserAll-DhvWQ7nM.js} +2 -2
- package/dist/renderer/assets/canvasUtils-KRroregW.js +1 -0
- package/dist/renderer/assets/{getTexelRangeRects-yD6MQ0xy.js → getTexelRangeRects-D3pwCyRt.js} +3 -3
- package/dist/renderer/assets/index-CE-lli1m.js +556 -0
- package/dist/renderer/assets/init-DfmWKarH.js +83 -0
- package/dist/renderer/assets/webworkerAll-B41hok0-.js +1 -0
- package/dist/renderer/index.html +1 -6
- package/dist/scene.d.ts +85 -9
- package/dist/scene.js +310 -48
- package/dist/types.d.ts +6 -1
- package/dist/zoom.d.ts +2 -0
- package/dist/zoom.js +10 -4
- package/package.json +2 -2
- package/dist/renderer/assets/CanvasPool-CHSHS1-v.js +0 -23
- package/dist/renderer/assets/RenderTargetSystem-EAUH9iQk.js +0 -404
- package/dist/renderer/assets/canvasUtils-n5g2f3_X.js +0 -1
- package/dist/renderer/assets/getTextureBatchBindGroup-Bwvgbco6.js +0 -1
- package/dist/renderer/assets/index-BwP6rH7I.js +0 -556
- package/dist/renderer/assets/init-C2Za5NQh.js +0 -83
- package/dist/renderer/assets/webworkerAll-JSSmbaR2.js +0 -1
package/dist/scene.js
CHANGED
|
@@ -1,13 +1,96 @@
|
|
|
1
1
|
import { easeAimed, makePath, mulberry32, sleep, travelDuration } from "./motion.js";
|
|
2
|
+
function isLocator(target) {
|
|
3
|
+
return typeof target === "object" && target !== null && typeof target.filter === "function";
|
|
4
|
+
}
|
|
5
|
+
function isPoint(target) {
|
|
6
|
+
return (typeof target === "object" &&
|
|
7
|
+
target !== null &&
|
|
8
|
+
!isLocator(target) &&
|
|
9
|
+
"x" in target &&
|
|
10
|
+
"y" in target &&
|
|
11
|
+
typeof target.x === "number" &&
|
|
12
|
+
typeof target.y === "number");
|
|
13
|
+
}
|
|
14
|
+
function isScrollDelta(target) {
|
|
15
|
+
return typeof target === "object" && target !== null && !isLocator(target) && "by" in target && typeof target.by === "number";
|
|
16
|
+
}
|
|
17
|
+
function formatMatch(v) {
|
|
18
|
+
return typeof v === "string" ? JSON.stringify(v) : String(v);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a Target to a Playwright Locator filtered to visible matches.
|
|
22
|
+
* Uses `.nth(nth)` when `nth` is specified on a TargetSpec, otherwise `.first()`.
|
|
23
|
+
*/
|
|
24
|
+
export function resolveTarget(page, target) {
|
|
25
|
+
if (typeof target === "string") {
|
|
26
|
+
return page.locator(target).filter({ visible: true }).first();
|
|
27
|
+
}
|
|
28
|
+
if (isLocator(target)) {
|
|
29
|
+
return target.filter({ visible: true }).first();
|
|
30
|
+
}
|
|
31
|
+
let loc;
|
|
32
|
+
if ("role" in target) {
|
|
33
|
+
const opts = {};
|
|
34
|
+
if (target.name !== undefined)
|
|
35
|
+
opts.name = target.name;
|
|
36
|
+
if (target.exact !== undefined)
|
|
37
|
+
opts.exact = target.exact;
|
|
38
|
+
loc = Object.keys(opts).length > 0 ? page.getByRole(target.role, opts) : page.getByRole(target.role);
|
|
39
|
+
}
|
|
40
|
+
else if ("label" in target) {
|
|
41
|
+
loc = target.exact !== undefined ? page.getByLabel(target.label, { exact: target.exact }) : page.getByLabel(target.label);
|
|
42
|
+
}
|
|
43
|
+
else if ("placeholder" in target) {
|
|
44
|
+
loc = target.exact !== undefined ? page.getByPlaceholder(target.placeholder, { exact: target.exact }) : page.getByPlaceholder(target.placeholder);
|
|
45
|
+
}
|
|
46
|
+
else if ("text" in target) {
|
|
47
|
+
loc = target.exact !== undefined ? page.getByText(target.text, { exact: target.exact }) : page.getByText(target.text);
|
|
48
|
+
}
|
|
49
|
+
else if ("testId" in target) {
|
|
50
|
+
loc = page.getByTestId(target.testId);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
loc = page.locator(target.css);
|
|
54
|
+
}
|
|
55
|
+
const visible = loc.filter({ visible: true });
|
|
56
|
+
return target.nth !== undefined ? visible.nth(target.nth) : visible.first();
|
|
57
|
+
}
|
|
58
|
+
/** Readable default label for a Target, used in timeline.json, marks.json and error messages. */
|
|
59
|
+
export function describeTarget(target) {
|
|
60
|
+
if (typeof target === "string")
|
|
61
|
+
return target;
|
|
62
|
+
if (isLocator(target))
|
|
63
|
+
return String(target);
|
|
64
|
+
let base;
|
|
65
|
+
if ("role" in target) {
|
|
66
|
+
base = target.name !== undefined ? `${target.role} ${formatMatch(target.name)}` : target.role;
|
|
67
|
+
}
|
|
68
|
+
else if ("label" in target) {
|
|
69
|
+
base = `label ${formatMatch(target.label)}`;
|
|
70
|
+
}
|
|
71
|
+
else if ("placeholder" in target) {
|
|
72
|
+
base = `placeholder ${formatMatch(target.placeholder)}`;
|
|
73
|
+
}
|
|
74
|
+
else if ("text" in target) {
|
|
75
|
+
base = `text ${formatMatch(target.text)}`;
|
|
76
|
+
}
|
|
77
|
+
else if ("testId" in target) {
|
|
78
|
+
base = `testId ${formatMatch(target.testId)}`;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
base = `css ${target.css}`;
|
|
82
|
+
}
|
|
83
|
+
return target.nth !== undefined ? `${base} [${target.nth}]` : base;
|
|
84
|
+
}
|
|
2
85
|
/** Attribute that marks a zoom anchor: actions inside it zoom onto the anchor's box. */
|
|
3
86
|
export const ZOOM_ATTRIBUTE = "data-demoreel-zoom";
|
|
4
87
|
export const DEFAULT_PACING = {
|
|
5
88
|
speed: 1,
|
|
6
|
-
beforeAction:
|
|
7
|
-
afterClick:
|
|
8
|
-
afterType:
|
|
9
|
-
typeDelay:
|
|
10
|
-
aimDwell:
|
|
89
|
+
beforeAction: 160,
|
|
90
|
+
afterClick: 360,
|
|
91
|
+
afterType: 450,
|
|
92
|
+
typeDelay: 42,
|
|
93
|
+
aimDwell: 95,
|
|
11
94
|
};
|
|
12
95
|
/** Applies a `data-demoreel-zoom` value to an action's zoom setting. */
|
|
13
96
|
export function applyZoomAnchor(zoom, anchor) {
|
|
@@ -33,6 +116,8 @@ export class Scene {
|
|
|
33
116
|
rand;
|
|
34
117
|
recorder = null;
|
|
35
118
|
startRecording;
|
|
119
|
+
fast;
|
|
120
|
+
clickRipple;
|
|
36
121
|
pacing;
|
|
37
122
|
/** The underlying Playwright page, for anything the Scene API does not cover. */
|
|
38
123
|
page;
|
|
@@ -41,9 +126,17 @@ export class Scene {
|
|
|
41
126
|
this.page = page;
|
|
42
127
|
this.viewport = viewport;
|
|
43
128
|
this.startRecording = startRecording;
|
|
129
|
+
this.fast = Boolean(opts.fast);
|
|
44
130
|
this.rand = mulberry32(opts.seed ?? 42);
|
|
45
131
|
this.pacing = { ...DEFAULT_PACING, ...opts.pacing };
|
|
46
132
|
this.cursor = { x: viewport.width * 0.62, y: viewport.height * 0.72 };
|
|
133
|
+
this.clickRipple = opts.clickRipple
|
|
134
|
+
? {
|
|
135
|
+
color: (typeof opts.clickRipple === "object" ? opts.clickRipple.color : undefined) ?? "rgba(96, 165, 250, 0.9)",
|
|
136
|
+
size: (typeof opts.clickRipple === "object" ? opts.clickRipple.size : undefined) ?? 36,
|
|
137
|
+
durationMs: (typeof opts.clickRipple === "object" ? opts.clickRipple.durationMs : undefined) ?? 380,
|
|
138
|
+
}
|
|
139
|
+
: null;
|
|
47
140
|
}
|
|
48
141
|
// ---- clock / telemetry -------------------------------------------------------------------
|
|
49
142
|
async ensureRecording() {
|
|
@@ -69,20 +162,20 @@ export class Scene {
|
|
|
69
162
|
});
|
|
70
163
|
}
|
|
71
164
|
ms(v) {
|
|
72
|
-
return v / this.pacing.speed;
|
|
165
|
+
return this.fast ? 0 : v / this.pacing.speed;
|
|
73
166
|
}
|
|
74
167
|
// ---- helpers ------------------------------------------------------------------------------
|
|
75
168
|
locate(target) {
|
|
76
169
|
// Prefer the first *visible* match (docs sites often duplicate nav for mobile drawers).
|
|
77
|
-
|
|
78
|
-
return loc.filter({ visible: true }).first();
|
|
170
|
+
return resolveTarget(this.page, target);
|
|
79
171
|
}
|
|
80
|
-
async inspect(loc) {
|
|
172
|
+
async inspect(loc, target) {
|
|
81
173
|
try {
|
|
82
174
|
await loc.waitFor({ state: "visible", timeout: 10_000 });
|
|
83
175
|
}
|
|
84
176
|
catch (e) {
|
|
85
|
-
|
|
177
|
+
const name = target !== undefined ? describeTarget(target) : String(loc);
|
|
178
|
+
throw new Error(`target not visible on ${this.page.url()}: ${name} (${e.message.split("\n")[0]})`);
|
|
86
179
|
}
|
|
87
180
|
const info = await loc.evaluate((el, attr) => {
|
|
88
181
|
const r = el.getBoundingClientRect();
|
|
@@ -108,10 +201,10 @@ export class Scene {
|
|
|
108
201
|
/** Scrolls the target into view (animated, recorded) if needed and returns its box. */
|
|
109
202
|
async prepare(target) {
|
|
110
203
|
const loc = this.locate(target);
|
|
111
|
-
let info = await this.inspect(loc);
|
|
204
|
+
let info = await this.inspect(loc, target);
|
|
112
205
|
if (!this.inViewport(info.box)) {
|
|
113
206
|
await this.scrollTo(loc);
|
|
114
|
-
info = await this.inspect(loc);
|
|
207
|
+
info = await this.inspect(loc, target);
|
|
115
208
|
}
|
|
116
209
|
return { loc, ...info };
|
|
117
210
|
}
|
|
@@ -134,7 +227,7 @@ export class Scene {
|
|
|
134
227
|
await this.ensureRecording();
|
|
135
228
|
const from = { ...this.cursor };
|
|
136
229
|
const dist = Math.hypot(to.x - from.x, to.y - from.y);
|
|
137
|
-
const duration = travelDuration(dist, target ? Math.min(target.width, target.height) : 40, this.pacing.speed);
|
|
230
|
+
const duration = this.fast ? 0 : travelDuration(dist, target ? Math.min(target.width, target.height) : 40, this.pacing.speed);
|
|
138
231
|
if (duration > 0) {
|
|
139
232
|
const path = makePath(from, to, this.rand);
|
|
140
233
|
const t0 = performance.now();
|
|
@@ -159,7 +252,38 @@ export class Scene {
|
|
|
159
252
|
await this.page.mouse.move(to.x, to.y);
|
|
160
253
|
this.sample("move");
|
|
161
254
|
}
|
|
255
|
+
async showClickRipple(at) {
|
|
256
|
+
if (!this.clickRipple || this.fast)
|
|
257
|
+
return;
|
|
258
|
+
const cfg = this.clickRipple;
|
|
259
|
+
await this.page
|
|
260
|
+
.evaluate((o) => {
|
|
261
|
+
const d = document.createElement("div");
|
|
262
|
+
d.setAttribute("data-demoreel-ripple", "");
|
|
263
|
+
d.style.cssText = [
|
|
264
|
+
"position:fixed",
|
|
265
|
+
`left:${o.x}px`,
|
|
266
|
+
`top:${o.y}px`,
|
|
267
|
+
`width:${o.size}px`,
|
|
268
|
+
`height:${o.size}px`,
|
|
269
|
+
"border-radius:9999px",
|
|
270
|
+
`border:3px solid ${o.color}`,
|
|
271
|
+
`box-shadow:0 0 12px color-mix(in srgb, ${o.color} 50%, transparent)`,
|
|
272
|
+
"pointer-events:none",
|
|
273
|
+
"z-index:2147483647",
|
|
274
|
+
"transform:translate(-50%,-50%) scale(0.35)",
|
|
275
|
+
].join(";");
|
|
276
|
+
document.documentElement.appendChild(d);
|
|
277
|
+
const anim = d.animate([
|
|
278
|
+
{ transform: "translate(-50%,-50%) scale(0.35)", opacity: 0.95 },
|
|
279
|
+
{ transform: "translate(-50%,-50%) scale(1.75)", opacity: 0 },
|
|
280
|
+
], { duration: o.durationMs, easing: "cubic-bezier(0.22, 1, 0.36, 1)", fill: "forwards" });
|
|
281
|
+
anim.onfinish = () => d.remove();
|
|
282
|
+
}, { x: at.x, y: at.y, ...cfg })
|
|
283
|
+
.catch(() => { });
|
|
284
|
+
}
|
|
162
285
|
async clickHere() {
|
|
286
|
+
await this.showClickRipple(this.cursor);
|
|
163
287
|
await this.page.mouse.down();
|
|
164
288
|
this.sample("click");
|
|
165
289
|
await sleep(this.ms(70 + this.rand() * 40));
|
|
@@ -206,7 +330,7 @@ export class Scene {
|
|
|
206
330
|
zoomBox: anchor?.box,
|
|
207
331
|
zoom: applyZoomAnchor(opts.zoom ?? true, anchor),
|
|
208
332
|
point: { ...this.cursor },
|
|
209
|
-
label: opts.label ??
|
|
333
|
+
label: opts.label ?? describeTarget(target),
|
|
210
334
|
});
|
|
211
335
|
await sleep(this.ms(this.pacing.afterClick));
|
|
212
336
|
if (opts.navigates || this.page.url() !== urlBefore) {
|
|
@@ -214,6 +338,108 @@ export class Scene {
|
|
|
214
338
|
this.cursorBox = null;
|
|
215
339
|
}
|
|
216
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Moves to a `<select>` element and picks an option via Playwright's `selectOption`.
|
|
343
|
+
*/
|
|
344
|
+
async select(target, value, opts = {}) {
|
|
345
|
+
await this.ensureRecording();
|
|
346
|
+
await sleep(this.ms(this.pacing.beforeAction));
|
|
347
|
+
const { loc, box, kind, anchor } = await this.prepare(target);
|
|
348
|
+
const startMs = this.now();
|
|
349
|
+
await this.travel(this.aimPoint(box), box, kind);
|
|
350
|
+
const arriveMs = this.now();
|
|
351
|
+
await sleep(this.ms(this.pacing.aimDwell));
|
|
352
|
+
await this.showClickRipple(this.cursor);
|
|
353
|
+
this.sample("click");
|
|
354
|
+
await loc.selectOption(value);
|
|
355
|
+
await sleep(this.ms(70));
|
|
356
|
+
this.sample("mouseup");
|
|
357
|
+
this.record({
|
|
358
|
+
kind: "select",
|
|
359
|
+
startMs,
|
|
360
|
+
arriveMs,
|
|
361
|
+
box,
|
|
362
|
+
zoomBox: anchor?.box,
|
|
363
|
+
zoom: applyZoomAnchor(opts.zoom ?? true, anchor),
|
|
364
|
+
point: { ...this.cursor },
|
|
365
|
+
label: opts.label ?? describeTarget(target),
|
|
366
|
+
text: typeof value === "string" ? value : (value.label ?? value.value ?? String(value.index ?? "")),
|
|
367
|
+
});
|
|
368
|
+
await sleep(this.ms(this.pacing.afterClick));
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Drags from a target or viewport point to another target, point, or relative offset `{ dx, dy }`.
|
|
372
|
+
* Records continuous cursor telemetry so OpenScreen renders the cursor tracking the drag
|
|
373
|
+
* (useful for 3D canvases, sliders, and drag-and-drop).
|
|
374
|
+
*/
|
|
375
|
+
async drag(from, to, opts = {}) {
|
|
376
|
+
await this.ensureRecording();
|
|
377
|
+
await sleep(this.ms(this.pacing.beforeAction));
|
|
378
|
+
let fromPoint;
|
|
379
|
+
let box;
|
|
380
|
+
let kind = "arrow";
|
|
381
|
+
let anchor;
|
|
382
|
+
if (isPoint(from)) {
|
|
383
|
+
fromPoint = from;
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
const info = await this.prepare(from);
|
|
387
|
+
box = info.box;
|
|
388
|
+
kind = info.kind;
|
|
389
|
+
anchor = info.anchor;
|
|
390
|
+
fromPoint = { x: box.x + box.width / 2, y: box.y + box.height / 2 };
|
|
391
|
+
}
|
|
392
|
+
let toPoint;
|
|
393
|
+
if (typeof to === "object" && to !== null && "dx" in to && "dy" in to) {
|
|
394
|
+
toPoint = { x: fromPoint.x + to.dx, y: fromPoint.y + to.dy };
|
|
395
|
+
}
|
|
396
|
+
else if (isPoint(to)) {
|
|
397
|
+
toPoint = to;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
const info = await this.prepare(to);
|
|
401
|
+
toPoint = this.aimPoint(info.box);
|
|
402
|
+
}
|
|
403
|
+
const startMs = this.now();
|
|
404
|
+
await this.travel(fromPoint, box ?? null, kind);
|
|
405
|
+
const arriveMs = this.now();
|
|
406
|
+
await sleep(this.ms(this.pacing.aimDwell));
|
|
407
|
+
await this.page.mouse.down();
|
|
408
|
+
this.sample("click");
|
|
409
|
+
const dist = Math.hypot(toPoint.x - fromPoint.x, toPoint.y - fromPoint.y);
|
|
410
|
+
const dur = this.ms(opts.duration ?? Math.min(1200, Math.max(350, dist * 2.5)));
|
|
411
|
+
if (dur > 0) {
|
|
412
|
+
const ease = (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);
|
|
413
|
+
const t0 = performance.now();
|
|
414
|
+
for (;;) {
|
|
415
|
+
const t = Math.min(1, (performance.now() - t0) / dur);
|
|
416
|
+
const k = ease(t);
|
|
417
|
+
const p = { x: fromPoint.x + (toPoint.x - fromPoint.x) * k, y: fromPoint.y + (toPoint.y - fromPoint.y) * k };
|
|
418
|
+
this.cursor = p;
|
|
419
|
+
await this.page.mouse.move(p.x, p.y);
|
|
420
|
+
this.sample("move");
|
|
421
|
+
if (t >= 1)
|
|
422
|
+
break;
|
|
423
|
+
await sleep(16 - ((performance.now() - t0) % 16));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
this.cursor = toPoint;
|
|
427
|
+
await this.page.mouse.move(toPoint.x, toPoint.y);
|
|
428
|
+
this.sample("move");
|
|
429
|
+
await this.page.mouse.up();
|
|
430
|
+
this.sample("mouseup");
|
|
431
|
+
this.record({
|
|
432
|
+
kind: "drag",
|
|
433
|
+
startMs,
|
|
434
|
+
arriveMs,
|
|
435
|
+
box,
|
|
436
|
+
zoomBox: anchor?.box,
|
|
437
|
+
zoom: applyZoomAnchor(opts.zoom ?? false, anchor),
|
|
438
|
+
point: fromPoint,
|
|
439
|
+
label: opts.label ?? (isPoint(from) ? undefined : describeTarget(from)),
|
|
440
|
+
});
|
|
441
|
+
await sleep(this.ms(this.pacing.afterClick));
|
|
442
|
+
}
|
|
217
443
|
async type(target, text, opts = {}) {
|
|
218
444
|
await this.ensureRecording();
|
|
219
445
|
await sleep(this.ms(this.pacing.beforeAction));
|
|
@@ -227,10 +453,15 @@ export class Scene {
|
|
|
227
453
|
if (opts.clear)
|
|
228
454
|
await loc.fill("");
|
|
229
455
|
await sleep(this.ms(180));
|
|
230
|
-
|
|
231
|
-
await this.page.keyboard.type(
|
|
232
|
-
|
|
233
|
-
|
|
456
|
+
if (this.fast) {
|
|
457
|
+
await this.page.keyboard.type(text);
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
for (const ch of text) {
|
|
461
|
+
await this.page.keyboard.type(ch);
|
|
462
|
+
const base = this.pacing.typeDelay * (0.55 + this.rand() * 0.9);
|
|
463
|
+
await sleep(this.ms(ch === " " ? base * 1.6 : base));
|
|
464
|
+
}
|
|
234
465
|
}
|
|
235
466
|
this.record({
|
|
236
467
|
kind: "type",
|
|
@@ -240,7 +471,7 @@ export class Scene {
|
|
|
240
471
|
zoomBox: anchor?.box,
|
|
241
472
|
zoom: applyZoomAnchor(opts.zoom ?? true, anchor),
|
|
242
473
|
point,
|
|
243
|
-
label: opts.label ??
|
|
474
|
+
label: opts.label ?? describeTarget(target),
|
|
244
475
|
text,
|
|
245
476
|
});
|
|
246
477
|
await sleep(this.ms(this.pacing.afterType));
|
|
@@ -250,8 +481,16 @@ export class Scene {
|
|
|
250
481
|
await this.ensureRecording();
|
|
251
482
|
const startMs = this.now();
|
|
252
483
|
await this.page.keyboard.press(key);
|
|
253
|
-
this.record({
|
|
254
|
-
|
|
484
|
+
this.record({
|
|
485
|
+
kind: "press",
|
|
486
|
+
startMs,
|
|
487
|
+
arriveMs: startMs,
|
|
488
|
+
label: opts.label ?? key,
|
|
489
|
+
text: key,
|
|
490
|
+
...(opts.show !== undefined ? { showKey: opts.show } : {}),
|
|
491
|
+
...(opts.duration !== undefined ? { keyDurationMs: opts.duration } : {}),
|
|
492
|
+
});
|
|
493
|
+
await sleep(this.ms(260));
|
|
255
494
|
}
|
|
256
495
|
async hover(target, opts = {}) {
|
|
257
496
|
await this.ensureRecording();
|
|
@@ -268,7 +507,7 @@ export class Scene {
|
|
|
268
507
|
box,
|
|
269
508
|
zoomBox: anchor?.box,
|
|
270
509
|
zoom: applyZoomAnchor(opts.zoom ?? false, anchor),
|
|
271
|
-
label: opts.label ??
|
|
510
|
+
label: opts.label ?? describeTarget(target),
|
|
272
511
|
});
|
|
273
512
|
}
|
|
274
513
|
/**
|
|
@@ -278,7 +517,7 @@ export class Scene {
|
|
|
278
517
|
async scroll(target, opts = {}) {
|
|
279
518
|
await this.ensureRecording();
|
|
280
519
|
await sleep(this.ms(this.pacing.beforeAction));
|
|
281
|
-
if (
|
|
520
|
+
if (isScrollDelta(target)) {
|
|
282
521
|
await this.animateScroll(null, target.by, opts.duration);
|
|
283
522
|
}
|
|
284
523
|
else {
|
|
@@ -313,18 +552,23 @@ export class Scene {
|
|
|
313
552
|
const max = scroller.scrollHeight - scroller.clientHeight;
|
|
314
553
|
const to = Math.max(0, Math.min(max, from + args.delta));
|
|
315
554
|
const ease = (t) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
555
|
+
if (args.dur <= 0) {
|
|
556
|
+
scroller.scrollTop = to;
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
await new Promise((resolve) => {
|
|
560
|
+
const t0 = performance.now();
|
|
561
|
+
const step = () => {
|
|
562
|
+
const t = Math.min(1, (performance.now() - t0) / args.dur);
|
|
563
|
+
scroller.scrollTop = from + (to - from) * ease(t);
|
|
564
|
+
if (t < 1)
|
|
565
|
+
requestAnimationFrame(step);
|
|
566
|
+
else
|
|
567
|
+
resolve();
|
|
568
|
+
};
|
|
569
|
+
requestAnimationFrame(step);
|
|
570
|
+
});
|
|
571
|
+
}
|
|
328
572
|
html.style.scrollBehavior = prevBehavior;
|
|
329
573
|
};
|
|
330
574
|
// <html> has no scrollable parent, so it resolves to the document scroller.
|
|
@@ -339,14 +583,14 @@ export class Scene {
|
|
|
339
583
|
async moveTo(target, opts = {}) {
|
|
340
584
|
await this.ensureRecording();
|
|
341
585
|
const startMs = this.now();
|
|
342
|
-
if (
|
|
586
|
+
if (isPoint(target)) {
|
|
343
587
|
await this.travel({ x: target.x, y: target.y });
|
|
344
588
|
this.record({ kind: "move", startMs, arriveMs: this.now(), label: opts.label });
|
|
345
589
|
return;
|
|
346
590
|
}
|
|
347
591
|
const { box, kind } = await this.prepare(target);
|
|
348
592
|
await this.travel(this.aimPoint(box), box, kind);
|
|
349
|
-
this.record({ kind: "move", startMs, arriveMs: this.now(), box, zoom: false, label: opts.label ??
|
|
593
|
+
this.record({ kind: "move", startMs, arriveMs: this.now(), box, zoom: false, label: opts.label ?? describeTarget(target) });
|
|
350
594
|
}
|
|
351
595
|
/**
|
|
352
596
|
* Explicit zoom onto an element for `duration` ms, overriding automatic zooms in that window.
|
|
@@ -365,21 +609,24 @@ export class Scene {
|
|
|
365
609
|
endMs: startMs + duration,
|
|
366
610
|
box,
|
|
367
611
|
zoom: Object.keys(hint).length ? hint : true,
|
|
368
|
-
label: opts.label ??
|
|
612
|
+
label: opts.label ?? describeTarget(target),
|
|
369
613
|
});
|
|
370
|
-
if (opts.wait)
|
|
614
|
+
if (opts.wait && !this.fast)
|
|
371
615
|
await sleep(duration);
|
|
372
616
|
}
|
|
373
|
-
/** Draws an outline
|
|
617
|
+
/** Draws an outline (and optional spotlight dim / badge) around an element in the page. */
|
|
374
618
|
async highlight(target, opts = {}) {
|
|
375
619
|
await this.ensureRecording();
|
|
376
620
|
const { loc, box, anchor } = await this.prepare(target);
|
|
377
621
|
const startMs = this.now();
|
|
378
622
|
const duration = this.ms(opts.duration ?? 1800);
|
|
623
|
+
const dimAlpha = opts.dim === true ? 0.55 : typeof opts.dim === "number" ? Math.min(0.95, Math.max(0, opts.dim)) : 0;
|
|
379
624
|
await loc.evaluate((el, o) => {
|
|
380
625
|
const r = el.getBoundingClientRect();
|
|
381
626
|
const d = document.createElement("div");
|
|
382
627
|
d.setAttribute("data-demoreel-highlight", "");
|
|
628
|
+
const glow = `0 0 0 4px color-mix(in srgb, ${o.color} 30%, transparent), 0 0 24px 4px color-mix(in srgb, ${o.color} 45%, transparent)`;
|
|
629
|
+
const shadow = o.dimAlpha > 0 ? `${glow}, 0 0 0 9999px rgba(6, 9, 20, ${o.dimAlpha})` : glow;
|
|
383
630
|
d.style.cssText = [
|
|
384
631
|
"position:fixed",
|
|
385
632
|
`left:${r.left - o.padding}px`,
|
|
@@ -388,12 +635,30 @@ export class Scene {
|
|
|
388
635
|
`height:${r.height + 2 * o.padding}px`,
|
|
389
636
|
`border:3px solid ${o.color}`,
|
|
390
637
|
"border-radius:10px",
|
|
391
|
-
`box-shadow
|
|
638
|
+
`box-shadow:${shadow}`,
|
|
392
639
|
"pointer-events:none",
|
|
393
640
|
"z-index:2147483647",
|
|
394
641
|
"opacity:0",
|
|
395
642
|
"transition:opacity 220ms ease-out",
|
|
396
643
|
].join(";");
|
|
644
|
+
if (o.badge) {
|
|
645
|
+
const b = document.createElement("div");
|
|
646
|
+
b.textContent = o.badge;
|
|
647
|
+
const above = r.top - o.padding > 44;
|
|
648
|
+
b.style.cssText = [
|
|
649
|
+
"position:absolute",
|
|
650
|
+
"left:0",
|
|
651
|
+
above ? "bottom:calc(100% + 10px)" : "top:calc(100% + 10px)",
|
|
652
|
+
`background:${o.color}`,
|
|
653
|
+
"color:#0b1020",
|
|
654
|
+
"font:700 13px/1.2 Inter,system-ui,-apple-system,sans-serif",
|
|
655
|
+
"padding:5px 10px",
|
|
656
|
+
"border-radius:7px",
|
|
657
|
+
"white-space:nowrap",
|
|
658
|
+
"box-shadow:0 4px 16px rgba(0,0,0,0.35)",
|
|
659
|
+
].join(";");
|
|
660
|
+
d.appendChild(b);
|
|
661
|
+
}
|
|
397
662
|
document.documentElement.appendChild(d);
|
|
398
663
|
requestAnimationFrame(() => {
|
|
399
664
|
d.style.opacity = "1";
|
|
@@ -402,7 +667,7 @@ export class Scene {
|
|
|
402
667
|
d.style.opacity = "0";
|
|
403
668
|
setTimeout(() => d.remove(), 260);
|
|
404
669
|
}, Math.max(0, o.duration - 260));
|
|
405
|
-
}, { duration, color: opts.color ?? "#ffcc00", padding: opts.padding ?? 6 });
|
|
670
|
+
}, { duration, color: opts.color ?? "#ffcc00", padding: opts.padding ?? 6, dimAlpha, badge: opts.badge ?? "" });
|
|
406
671
|
this.record({
|
|
407
672
|
kind: "highlight",
|
|
408
673
|
startMs,
|
|
@@ -411,9 +676,9 @@ export class Scene {
|
|
|
411
676
|
box,
|
|
412
677
|
zoomBox: anchor?.box,
|
|
413
678
|
zoom: applyZoomAnchor(opts.zoom ?? false, anchor),
|
|
414
|
-
label: opts.label ??
|
|
679
|
+
label: opts.label ?? describeTarget(target),
|
|
415
680
|
});
|
|
416
|
-
if (opts.wait)
|
|
681
|
+
if (opts.wait && !this.fast)
|
|
417
682
|
await sleep(duration);
|
|
418
683
|
}
|
|
419
684
|
async pause(ms) {
|
|
@@ -432,10 +697,7 @@ export class Scene {
|
|
|
432
697
|
const duration = this.ms(opts.duration ?? 2600);
|
|
433
698
|
const startMs = this.now();
|
|
434
699
|
this.captions.push({ text, startMs, endMs: startMs + duration });
|
|
435
|
-
if (opts.wait)
|
|
700
|
+
if (opts.wait && !this.fast)
|
|
436
701
|
await sleep(duration);
|
|
437
702
|
}
|
|
438
703
|
}
|
|
439
|
-
function labelOf(target) {
|
|
440
|
-
return typeof target === "string" ? target : undefined;
|
|
441
|
-
}
|
package/dist/types.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface Box {
|
|
|
9
9
|
width: number;
|
|
10
10
|
height: number;
|
|
11
11
|
}
|
|
12
|
+
/** OpenScreen zoom depth tier: 1=1.25x, 2=1.5x, 3=1.8x, 4=2.2x, 5=3x, 6=5x. */
|
|
12
13
|
export type Depth = 1 | 2 | 3 | 4 | 5 | 6;
|
|
13
14
|
/** Mirrors OpenScreen's `CursorRecordingSample` (src/native/contracts.ts). */
|
|
14
15
|
export interface CursorSample {
|
|
@@ -20,7 +21,7 @@ export interface CursorSample {
|
|
|
20
21
|
interactionType?: "move" | "click" | "mouseup";
|
|
21
22
|
assetId?: string | null;
|
|
22
23
|
}
|
|
23
|
-
export type ActionKind = "goto" | "click" | "type" | "hover" | "scroll" | "pause" | "caption" | "press" | "move" | "zoom" | "highlight";
|
|
24
|
+
export type ActionKind = "goto" | "click" | "select" | "drag" | "type" | "hover" | "scroll" | "pause" | "caption" | "press" | "move" | "zoom" | "highlight";
|
|
24
25
|
/** One scripted step, as it actually happened during recording. */
|
|
25
26
|
export interface ActionRecord {
|
|
26
27
|
kind: ActionKind;
|
|
@@ -46,6 +47,10 @@ export interface ActionRecord {
|
|
|
46
47
|
};
|
|
47
48
|
label?: string;
|
|
48
49
|
text?: string;
|
|
50
|
+
/** For `press` actions: override whether a keycap HUD overlay is shown for this key. */
|
|
51
|
+
showKey?: boolean;
|
|
52
|
+
/** For `press` actions: how long the keycap HUD stays visible (ms). */
|
|
53
|
+
keyDurationMs?: number;
|
|
49
54
|
}
|
|
50
55
|
export interface ZoomHint {
|
|
51
56
|
/** Force a depth (1..6) instead of deriving it from the element size. */
|
package/dist/zoom.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface ZoomOptions {
|
|
|
31
31
|
clampToVideo: boolean;
|
|
32
32
|
}
|
|
33
33
|
export declare const DEFAULT_ZOOM_OPTIONS: ZoomOptions;
|
|
34
|
+
/** Clamps and rounds any numeric depth to a valid OpenScreen integer tier (1..6). */
|
|
35
|
+
export declare function normalizeDepth(depth: number): Depth;
|
|
34
36
|
/**
|
|
35
37
|
* Moves a stage-normalised focus so that the view at `depth` stays inside the recording's
|
|
36
38
|
* rectangle (OpenScreen itself only keeps it inside the stage, which shows wallpaper).
|
package/dist/zoom.js
CHANGED
|
@@ -22,12 +22,18 @@ export const DEFAULT_ZOOM_OPTIONS = {
|
|
|
22
22
|
auto: true,
|
|
23
23
|
clampToVideo: true,
|
|
24
24
|
};
|
|
25
|
+
/** Clamps and rounds any numeric depth to a valid OpenScreen integer tier (1..6). */
|
|
26
|
+
export function normalizeDepth(depth) {
|
|
27
|
+
if (!Number.isFinite(depth))
|
|
28
|
+
return 2;
|
|
29
|
+
return Math.min(6, Math.max(1, Math.round(depth)));
|
|
30
|
+
}
|
|
25
31
|
/**
|
|
26
32
|
* Moves a stage-normalised focus so that the view at `depth` stays inside the recording's
|
|
27
33
|
* rectangle (OpenScreen itself only keeps it inside the stage, which shows wallpaper).
|
|
28
34
|
*/
|
|
29
35
|
export function clampFocusToVideo(focus, depth, layout) {
|
|
30
|
-
const half = 0.5 / DEPTH_SCALES[depth];
|
|
36
|
+
const half = 0.5 / DEPTH_SCALES[normalizeDepth(depth)];
|
|
31
37
|
const v = layout.video;
|
|
32
38
|
const c = (val, start, size) => size <= 2 * half ? start + size / 2 : Math.min(start + size - half, Math.max(start + half, val));
|
|
33
39
|
return { cx: c(focus.cx, v.x, v.w), cy: c(focus.cy, v.y, v.h) };
|
|
@@ -38,12 +44,12 @@ export function clampFocusToVideo(focus, depth, layout) {
|
|
|
38
44
|
* `videoFraction` is the share of the stage the recording covers (padding shrinks it).
|
|
39
45
|
*/
|
|
40
46
|
export function depthForBox(box, vp, opts = DEFAULT_ZOOM_OPTIONS, hint, videoFraction = { w: 1, h: 1 }) {
|
|
41
|
-
if (hint?.depth)
|
|
42
|
-
return hint.depth;
|
|
47
|
+
if (hint?.depth !== undefined)
|
|
48
|
+
return normalizeDepth(hint.depth);
|
|
43
49
|
const ctx = hint?.context ?? 1;
|
|
44
50
|
const fitW = (vp.width * opts.fillWidth) / Math.max(1, box.width * ctx * videoFraction.w);
|
|
45
51
|
const fitH = (vp.height * opts.fillHeight) / Math.max(1, box.height * ctx * videoFraction.h);
|
|
46
|
-
const maxScale = Math.min(fitW, fitH, DEPTH_SCALES[opts.maxDepth]);
|
|
52
|
+
const maxScale = Math.min(fitW, fitH, DEPTH_SCALES[normalizeDepth(opts.maxDepth)]);
|
|
47
53
|
let best = null;
|
|
48
54
|
for (const d of [1, 2, 3, 4, 5, 6]) {
|
|
49
55
|
if (DEPTH_SCALES[d] <= maxScale + 1e-6)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phil65/demoreel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Scripted product demo videos (videos as code): Playwright scenarios with auto cursor + auto zoom, rendered headless by OpenScreen's exporter.",
|
|
6
6
|
"keywords": [
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"prepack": "npm run build"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"playwright": ">=1.
|
|
60
|
+
"playwright": ">=1.49.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/node": "^26.6.6",
|