@open-take/runtime 0.1.2 → 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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CaptureLog, CompositionIssue, PlanOpts, ReviewBadge, TakeComposition, formatIssues, validateComposition } from "@open-take/compositor";
1
+ import { BBox, CaptureLog, CompositionIssue, PlanOpts, ReviewBadge, TakeComposition, formatIssues, validateComposition } from "@open-take/compositor";
2
2
 
3
3
  //#region src/types.d.ts
4
4
  /** A point in viewport CSS px (the capture coordinate space). */
@@ -156,8 +156,50 @@ declare function inspectPage(url: string, opts?: InspectOpts): Promise<InspectRe
156
156
  declare function captureTakeCDP(plan: TakePlan, opts: CaptureOpts): Promise<CaptureLog>;
157
157
 
158
158
  //#endregion
159
- //#region src/cdp.d.ts
159
+ //#region src/frame-diff.d.ts
160
160
  //# sourceMappingURL=cdp-capture.d.ts.map
161
+ type FrameDiffResult = {
162
+ /** fraction of the frame's cells that changed (0..1) */
163
+ coverage: number;
164
+ /** bbox of the changed region in ANALYSIS-raster px, or undefined when
165
+ * nothing beyond isolated specks changed */
166
+ box?: BBox;
167
+ };
168
+ /**
169
+ * Pure diff of two grayscale frames (same w×h). Cell-based: a cell counts as
170
+ * changed when enough of its pixels moved. An isolated changed cell (no
171
+ * changed 8-neighbour) is kept only when it changed OVERWHELMINGLY (≥ half its
172
+ * pixels — a real single-cell payoff like a cart badge), else it's a speck
173
+ * (caret blink, cursor sliver) and is dropped.
174
+ *
175
+ * `ambient` (optional) is a THIRD frame sampled shortly after `after`: any
176
+ * cell still changing between `after` and `ambient` is ambient motion (hero
177
+ * video, carousel, streaming text) and is excluded — without this, one
178
+ * animating region would poison every event's effectBox with its union.
179
+ *
180
+ * `coverage` is the changed-CELL area fraction — the region the action
181
+ * affected — deliberately not the changed-PIXEL fraction: a nav swap between
182
+ * two white-ish pages repaints most of the frame while leaving most PIXELS
183
+ * white-on-white, and it's the affected region the director's pull-out
184
+ * threshold reasons about.
185
+ */
186
+ declare function diffFrames(before: Uint8Array, after: Uint8Array, w: number, h: number, ambient?: Uint8Array): FrameDiffResult;
187
+ type AnnotateOpts = {
188
+ /** explicit ffmpeg binary; resolved via the compositor's resolver if omitted */
189
+ ffmpegBin?: string;
190
+ logProgress?: boolean;
191
+ };
192
+ /**
193
+ * Annotate a capture log with per-event `effectBox` + `changeCoverage` by
194
+ * diffing the capture video around each action. Returns a NEW log (input
195
+ * untouched); events whose diff fails or whose sample window is degenerate are
196
+ * returned unchanged. Never throws.
197
+ */
198
+ declare function annotateCaptureLog(log: CaptureLog, videoPath: string, opts?: AnnotateOpts): Promise<CaptureLog>;
199
+
200
+ //#endregion
201
+ //#region src/cdp.d.ts
202
+ //# sourceMappingURL=frame-diff.d.ts.map
161
203
  declare function resolveChrome(explicit?: string): string | null;
162
204
  declare function ensureChrome(explicit?: string): Promise<string>;
163
205
 
@@ -287,6 +329,11 @@ type MakeTakeOpts = {
287
329
  /** tune the default composition (zoom fill/cap, framing, cursor) */
288
330
  planOpts?: PlanOpts;
289
331
  capture?: Omit<CaptureOpts, "videoPath">;
332
+ /** frame-diff the capture to annotate each event with what it actually
333
+ * changed on screen (effectBox/changeCoverage — the camera director's
334
+ * nav-vs-popover + payoff-framing inputs). Default true; annotation
335
+ * failures never fail the take. */
336
+ frameDiff?: boolean;
290
337
  logProgress?: boolean;
291
338
  };
292
339
  type MakeTakeResult = {
@@ -362,5 +409,5 @@ declare function renderCompositionFile(opts: {
362
409
  //#endregion
363
410
  //# sourceMappingURL=index.d.ts.map
364
411
 
365
- export { AbOpts, CaptureOpts, CompositionIssue, EditServerOpts, InspectElement, InspectOpts, InspectResult, MakeTakeOpts, MakeTakeResult, RenderCompositionOpts, ReviewOpts, SAY_IT_CARD, StagedPrev, TakePaths, TakePlan, TakeStep, buildBadges, buildBeatSheet, captureLogPathFor, captureTake, captureTakeCDP, ensureChrome, formatIssues, inspectPage, loadCaptureLogSibling, makeTake, openPath, renderAbReel, renderBeforeAfter, renderComposition, renderCompositionFile, renderReview, requireTakeFiles, resolveChrome, resolveTakePaths, revealPath, stagePrev, startEditServer, validateComposition };
412
+ export { AbOpts, AnnotateOpts, CaptureOpts, CompositionIssue, EditServerOpts, FrameDiffResult, InspectElement, InspectOpts, InspectResult, MakeTakeOpts, MakeTakeResult, RenderCompositionOpts, ReviewOpts, SAY_IT_CARD, StagedPrev, TakePaths, TakePlan, TakeStep, annotateCaptureLog, buildBadges, buildBeatSheet, captureLogPathFor, captureTake, captureTakeCDP, diffFrames, ensureChrome, formatIssues, inspectPage, loadCaptureLogSibling, makeTake, openPath, renderAbReel, renderBeforeAfter, renderComposition, renderCompositionFile, renderReview, requireTakeFiles, resolveChrome, resolveTakePaths, revealPath, stagePrev, startEditServer, validateComposition };
366
413
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/capture.ts","../src/cdp-capture.ts","../src/cdp.ts","../src/edit-server.ts","../src/take.ts","../src/review.ts","../src/index.ts"],"sourcesContent":null,"mappings":";;;;;KAcY,SAAA;;;AAAZ,CAAA;;;AAIY,KAAA,UAAA,GAAU,MAAA,GAAA,OAAA,GAAA,QAAA;AAMV,KAAA,QAAA,GAAQ;EAAA,MAAA,EAAA,OAAA;EAAA,QAOP,CAAA,EAAA,MAAA;EAAU,IAaV,CAAA,EAAA,MAAA;EAAU,IAYV,CAAA,EAAA,MAAA;EAAS,QAIX,CAAA,EAAA,MAAA;EAAS,IAEP,CAAA,EA/BA,UA+BA;CAAS,GAAA;EAKC,MA+BV,EAAA,MAAA;EAAU,QAqBV,CAAA,EAAA,MAAA;EAAU,IAAA,CAAA,EAAA,MAAA;EAIX;;;;EC0IA,IAAA,CAAA,EDzNC,UCyNU;;EAuBD,MAAA,EAAA,MAAW;EAAA,QAAA,CAAA,EAAA,MAAA;EAAA,IAAO,CAAA,EAAA,MAAA;EAAQ,IAAQ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B,OH3H0B,CAAA;EAAiB,OAEZ,EAAA,MAAA;EAAO,eAAA,EAAA,MAAA;AA2GzC,CAAA,CAAA;;;;;;AAGU,iBG8BY,qBAAA,CH9BZ,IAAA,EAAA;;;;EClKE;;;EAuBU,UAAA,CAAA,EAAA,MAAgB;EAAA,UAAA,CAAA,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,GAAA,IAAA;CAAA,CAAA,EEkLlC,OFlL2D,CAAA;EAAS,OAAjB,EAAA,MAAA;EAAO,eAAA,EAAA,MAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/capture.ts","../src/cdp-capture.ts","../src/frame-diff.ts","../src/cdp.ts","../src/edit-server.ts","../src/take.ts","../src/review.ts","../src/index.ts"],"sourcesContent":null,"mappings":";;;;;KAcY,SAAA;;;AAAZ,CAAA;;;AAIY,KAAA,UAAA,GAAU,MAAA,GAAA,OAAA,GAAA,QAAA;AAMV,KAAA,QAAA,GAAQ;EAAA,MAAA,EAAA,OAAA;EAAA,QAOP,CAAA,EAAA,MAAA;EAAU,IAaV,CAAA,EAAA,MAAA;EAAU,IAYV,CAAA,EAAA,MAAA;EAAS,QAIX,CAAA,EAAA,MAAA;EAAS,IAEP,CAAA,EA/BA,UA+BA;CAAS,GAAA;EAKC,MA+BV,EAAA,MAAA;EAAU,QAqBV,CAAA,EAAA,MAAA;EAAU,IAAA,CAAA,EAAA,MAAA;EAIX;;;;EC0IA,IAAA,CAAA,EDzNC,UCyNU;;EAuBD,MAAA,EAAA,MAAW;EAAA,QAAA,CAAA,EAAA,MAAA;EAAA,IAAO,CAAA,EAAA,MAAA;EAAQ,IAAQ,CAAA,EDpO3C,SCoO2C;EAAW,UAAW,CAAA,EAAA,MAAA;EAAU,MAAlB,CAAA,EAAA,MAAA;EAAO,EAAA,CAAA,EDhOlE,SCgOkE;EAOjE;EAYA,IAAA,CAAA,EDjPC,SCiPY,EAAA;EAsBb;;;;EAUU,IAAA,CAAA,ED5QT,UC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A;;IIgaT;;;;;;;;;;;;;AJjXS,iBIohBI,QAAA,CJphBJ,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;AACM;AA0FlB;;;iBIscgB,UAAA;;;;;APjlBH,KQeD,YAAA,GRfC;EAAS;EAIF,OAEP,EAAA,MAAA;EAAS;EAKC,QA+BV,CAAA,EQvBA,QRuBA;EAAU,OAqBV,CAAA,EQ3CD,IR2CC,CQ3CI,WR2CJ,EAAA,WAAA,CAAA;EAAU;AAIvB;;;;EC0IY,WAAA,CAAA,EAAW,OAAA;;AAuBD,KOvMV,cAAA,GPuMqB;EAAA,OAAA,EAAA,MAAA;EAAA,eAAO,EAAA,MAAA;EAAQ;;EAAwC,WAAlB,EAAA,MAAA;EAAO;AAO7E;AAYA;AAsBA;;eOrOe;;AP+Of;;;AAAgF,cOpOnE,iBPoOmE,EAAA,CAAA,WAAA,EAAA,MAAA,EAAA,GAAA,MAAA;;AAAD;;iBO9NzD,qBAAA,uBAA4C,QAAQ;iBASpD,QAAA,OAAe,gBAAgB,eAAe,QAAQ;KAoDhE,qBAAA;ENqCU;EAAc,WAAA,EMnCrB,eNmCqB;EAAA;EAAe,WAAQ,EAAA,MAAA;EAAW;EAAqB,OAAlB,EAAA,MAAA;EAAO;;eM5BjE;;EL9HH;;;;;;;;;;;;;;iBK+IU,iBAAA,OACd,wBACL;;;;;ALvGH;;;;AAKY,iBKqHU,qBAAA,CLrHV,IAAA,EAAA;EAAU,eACnB,EAAA,MAAA;EAAe,WAAA,EAAA,MAAA;EA0FN,OAAA,EAAA,MAAY;;;;;;IKmCpB;ELvBkB,OAAA,EAAA,MAAA;EAAkB,eAAA,EAAA,MAAA;CAAA,CAAA"}
package/dist/index.js CHANGED
@@ -8,6 +8,213 @@ import { createReadStream, statSync } from "node:fs";
8
8
  import { createServer } from "node:http";
9
9
  import { fileURLToPath } from "node:url";
10
10
 
11
+ //#region src/frame-diff.ts
12
+ const ANALYSIS_W = 960;
13
+ const CELL = 16;
14
+ /** min |gray delta| for a pixel to count as changed (h264 noise is ~2–6) */
15
+ const PIXEL_DELTA = 16;
16
+ /** a cell is "changed" when > this fraction of its pixels changed */
17
+ const CELL_FRAC = .08;
18
+ /** sample the "before" state this long before the action (ms). Kept TIGHT so
19
+ * everything that happens on the approach — the capture's own
20
+ * scrollIntoView, hover styles, the previous action's tail — is already
21
+ * painted and therefore NOT attributed to this action; a click's own effect
22
+ * can't land within one 60fps frame of the input, so this still precedes it.
23
+ * (Also < NEXT_CLEARANCE_MS, so adjacent events' windows can never overlap —
24
+ * no double attribution.) */
25
+ const BEFORE_MS = 30;
26
+ /** sample the "after" state this long after the action (+durationMs) settles —
27
+ * catches popover/reveal animations (ms; the capture itself sleeps ~1s
28
+ * between actions, so there is normally room). */
29
+ const SETTLE_MS = 500;
30
+ /** third sample this long after the "after" frame: cells STILL changing
31
+ * between the two are ambient motion (hero video, carousel, streaming text)
32
+ * — masked out of the action's diff so they can't poison effectBox (ms). */
33
+ const AMBIENT_MS = 250;
34
+ /** keep this much clearance before the NEXT action so its changes are never
35
+ * attributed to this one (ms). */
36
+ const NEXT_CLEARANCE_MS = 60;
37
+ /** a box-less event (bare press) only gets an effectBox when the change is at
38
+ * least this big — a blinking terminal cursor must not become a phantom
39
+ * punch target on an event that used to mean "full view". */
40
+ const MIN_NO_BOX_COVERAGE = .015;
41
+ /** per-cell changed-pixel counts of |before−after| > PIXEL_DELTA (symmetric —
42
+ * appearing light-on-dark content matters as much as dark-on-light). */
43
+ function cellCounts(a, b, w, h) {
44
+ const cw = Math.ceil(w / CELL);
45
+ const counts = new Uint16Array(cw * Math.ceil(h / CELL));
46
+ for (let y = 0; y < h; y++) {
47
+ const row = y * w;
48
+ const crow = Math.floor(y / CELL) * cw;
49
+ for (let x = 0; x < w; x++) {
50
+ const d = a[row + x] - b[row + x];
51
+ if (d > PIXEL_DELTA || d < -PIXEL_DELTA) counts[crow + Math.floor(x / CELL)]++;
52
+ }
53
+ }
54
+ return counts;
55
+ }
56
+ /**
57
+ * Pure diff of two grayscale frames (same w×h). Cell-based: a cell counts as
58
+ * changed when enough of its pixels moved. An isolated changed cell (no
59
+ * changed 8-neighbour) is kept only when it changed OVERWHELMINGLY (≥ half its
60
+ * pixels — a real single-cell payoff like a cart badge), else it's a speck
61
+ * (caret blink, cursor sliver) and is dropped.
62
+ *
63
+ * `ambient` (optional) is a THIRD frame sampled shortly after `after`: any
64
+ * cell still changing between `after` and `ambient` is ambient motion (hero
65
+ * video, carousel, streaming text) and is excluded — without this, one
66
+ * animating region would poison every event's effectBox with its union.
67
+ *
68
+ * `coverage` is the changed-CELL area fraction — the region the action
69
+ * affected — deliberately not the changed-PIXEL fraction: a nav swap between
70
+ * two white-ish pages repaints most of the frame while leaving most PIXELS
71
+ * white-on-white, and it's the affected region the director's pull-out
72
+ * threshold reasons about.
73
+ */
74
+ function diffFrames(before, after, w, h, ambient) {
75
+ const cw = Math.ceil(w / CELL);
76
+ const ch = Math.ceil(h / CELL);
77
+ const counts = cellCounts(before, after, w, h);
78
+ const minCount = Math.max(1, Math.floor(CELL * CELL * CELL_FRAC));
79
+ const strongCount = Math.floor(CELL * CELL * .5);
80
+ const ambientCounts = ambient ? cellCounts(after, ambient, w, h) : void 0;
81
+ const changed = (cx, cy) => cx >= 0 && cy >= 0 && cx < cw && cy < ch && counts[cy * cw + cx] >= minCount && (!ambientCounts || ambientCounts[cy * cw + cx] < minCount);
82
+ let kept = 0;
83
+ let x0 = cw;
84
+ let y0 = ch;
85
+ let x1 = -1;
86
+ let y1 = -1;
87
+ for (let cy = 0; cy < ch; cy++) for (let cx = 0; cx < cw; cx++) {
88
+ if (!changed(cx, cy)) continue;
89
+ let neighbour = counts[cy * cw + cx] >= strongCount;
90
+ for (let dy = -1; dy <= 1 && !neighbour; dy++) for (let dx = -1; dx <= 1; dx++) {
91
+ if (dx === 0 && dy === 0) continue;
92
+ if (changed(cx + dx, cy + dy)) {
93
+ neighbour = true;
94
+ break;
95
+ }
96
+ }
97
+ if (!neighbour) continue;
98
+ kept++;
99
+ if (cx < x0) x0 = cx;
100
+ if (cy < y0) y0 = cy;
101
+ if (cx > x1) x1 = cx;
102
+ if (cy > y1) y1 = cy;
103
+ }
104
+ if (kept === 0) return { coverage: 0 };
105
+ return {
106
+ coverage: kept / (cw * ch),
107
+ box: {
108
+ x: x0 * CELL,
109
+ y: y0 * CELL,
110
+ w: Math.min((x1 + 1) * CELL, w) - x0 * CELL,
111
+ h: Math.min((y1 + 1) * CELL, h) - y0 * CELL
112
+ }
113
+ };
114
+ }
115
+ /** Decode ONE grayscale frame at time `tSec` from `videoPath`, scaled to
116
+ * aw×ah. Resolves undefined on any failure (missing frame near EOF, etc.). */
117
+ function grabFrame(bin, videoPath, tSec, aw, ah) {
118
+ return new Promise((res) => {
119
+ const args = [
120
+ "-v",
121
+ "error",
122
+ "-ss",
123
+ tSec.toFixed(3),
124
+ "-i",
125
+ videoPath,
126
+ "-frames:v",
127
+ "1",
128
+ "-vf",
129
+ `scale=${aw}:${ah}`,
130
+ "-f",
131
+ "rawvideo",
132
+ "-pix_fmt",
133
+ "gray",
134
+ "-"
135
+ ];
136
+ const c = spawn(bin, args, { stdio: [
137
+ "ignore",
138
+ "pipe",
139
+ "ignore"
140
+ ] });
141
+ const chunks = [];
142
+ c.stdout.on("data", (b) => chunks.push(b));
143
+ c.on("error", () => res(void 0));
144
+ c.on("close", () => {
145
+ const buf = Buffer.concat(chunks);
146
+ res(buf.length === aw * ah ? new Uint8Array(buf) : void 0);
147
+ });
148
+ });
149
+ }
150
+ /**
151
+ * Annotate a capture log with per-event `effectBox` + `changeCoverage` by
152
+ * diffing the capture video around each action. Returns a NEW log (input
153
+ * untouched); events whose diff fails or whose sample window is degenerate are
154
+ * returned unchanged. Never throws.
155
+ */
156
+ async function annotateCaptureLog(log, videoPath, opts = {}) {
157
+ try {
158
+ const bin = opts.ffmpegBin ?? await resolveFfmpeg();
159
+ const vW = log.video.width;
160
+ const vH = log.video.height;
161
+ if (!(vW > 0) || !(vH > 0)) return log;
162
+ const aw = Math.min(ANALYSIS_W, vW);
163
+ const ah = Math.max(CELL, Math.round(vH * aw / vW));
164
+ const mx = log.viewport.w / aw;
165
+ const my = log.viewport.h / ah;
166
+ const durS = log.video.durationS ?? (log.tEndMs != null ? log.tEndMs / 1e3 : void 0);
167
+ const events = [...log.events];
168
+ for (let i = 0; i < events.length; i++) {
169
+ const e = events[i];
170
+ const durationMs = "durationMs" in e && e.durationMs != null ? e.durationMs : 0;
171
+ const before = Math.max(0, (e.tMs - BEFORE_MS) / 1e3);
172
+ let after = (e.tMs + durationMs + SETTLE_MS) / 1e3;
173
+ const next = events[i + 1];
174
+ const ceil = Math.min(
175
+ next ? (next.tMs - NEXT_CLEARANCE_MS) / 1e3 : Number.POSITIVE_INFINITY,
176
+ // never sample past the recording's end (the last frame would repeat —
177
+ // fine — but a seek past EOF returns nothing)
178
+ durS != null ? Math.max(0, durS - .05) : Number.POSITIVE_INFINITY
179
+ );
180
+ after = Math.min(after, ceil);
181
+ if (after <= before + .05) continue;
182
+ const ambientT = after + AMBIENT_MS / 1e3;
183
+ const wantAmbient = ambientT <= ceil;
184
+ const [fa, fb, fc] = await Promise.all([
185
+ grabFrame(bin, videoPath, before, aw, ah),
186
+ grabFrame(bin, videoPath, after, aw, ah),
187
+ wantAmbient ? grabFrame(bin, videoPath, ambientT, aw, ah) : Promise.resolve(void 0)
188
+ ]);
189
+ if (!fa || !fb) continue;
190
+ const d = diffFrames(fa, fb, aw, ah, fc);
191
+ const hasBox = "box" in e && e.box != null;
192
+ const attachBox = d.box && (hasBox || d.coverage >= MIN_NO_BOX_COVERAGE);
193
+ events[i] = {
194
+ ...e,
195
+ changeCoverage: Math.round(d.coverage * 1e3) / 1e3,
196
+ ...attachBox && d.box ? { effectBox: {
197
+ x: Math.round(d.box.x * mx),
198
+ y: Math.round(d.box.y * my),
199
+ w: Math.round(d.box.w * mx),
200
+ h: Math.round(d.box.h * my)
201
+ } } : {}
202
+ };
203
+ if (opts.logProgress) {
204
+ const eb = events[i].effectBox;
205
+ process.stderr.write(`frame-diff [${i}] ${e.kind ?? "click"}@${e.tMs}ms coverage=${events[i].changeCoverage}${eb ? ` effect=(${eb.x},${eb.y} ${eb.w}x${eb.h})` : ""}\n`);
206
+ }
207
+ }
208
+ return {
209
+ ...log,
210
+ events
211
+ };
212
+ } catch {
213
+ return log;
214
+ }
215
+ }
216
+
217
+ //#endregion
11
218
  //#region src/take.ts
12
219
  async function isFile(p) {
13
220
  return (await stat(p).catch(() => null))?.isFile() ?? false;
@@ -366,7 +573,8 @@ function abWindow(comps, beat, full) {
366
573
  for (const c of comps) {
367
574
  const e = c.events[i];
368
575
  if (!e) continue;
369
- from = Math.min(from, Math.max(0, e.zoom.inAtMs - 1200));
576
+ const rampFrom = Math.min(e.zoom.inAtMs, e.tMs - c.cursor.zoomOutMs);
577
+ from = Math.min(from, Math.max(0, rampFrom - 1200));
370
578
  const next = c.events[i + 1];
371
579
  const ownEnd = e.tMs + (e.durationMs ?? 0) + c.cursor.holdMs + c.cursor.zoomOutMs;
372
580
  to = Math.max(to, (next ? next.zoom.inAtMs : ownEnd) + 400);
@@ -1047,11 +1255,12 @@ async function makeTake(plan, opts) {
1047
1255
  const work = await mkdtemp(join(tmpdir(), "open-take-"));
1048
1256
  const tmpVideo = join(work, "capture.mp4");
1049
1257
  const chromePath = await ensureChrome(opts.capture?.chromePath);
1050
- const log = await captureTake(plan, {
1258
+ const raw = await captureTake(plan, {
1051
1259
  ...opts.capture,
1052
1260
  chromePath,
1053
1261
  videoPath: tmpVideo
1054
1262
  });
1263
+ const log = opts.frameDiff === false ? raw : await annotateCaptureLog(raw, tmpVideo, { logProgress: opts.logProgress });
1055
1264
  const capturePath = capturePathFor(opts.outPath);
1056
1265
  const captureLogPath = captureLogPathFor(capturePath);
1057
1266
  await mkdir(dirname(capturePath), { recursive: true });
@@ -1121,5 +1330,5 @@ async function renderCompositionFile(opts) {
1121
1330
  }
1122
1331
 
1123
1332
  //#endregion
1124
- export { SAY_IT_CARD, buildBadges, buildBeatSheet, captureLogPathFor, captureTake, captureTakeCDP, ensureChrome, formatIssues, inspectPage, loadCaptureLogSibling, makeTake, openPath, renderAbReel, renderBeforeAfter, renderComposition, renderCompositionFile, renderReview, requireTakeFiles, resolveChrome, resolveTakePaths, revealPath, stagePrev, startEditServer, validateComposition };
1333
+ export { SAY_IT_CARD, annotateCaptureLog, buildBadges, buildBeatSheet, captureLogPathFor, captureTake, captureTakeCDP, diffFrames, ensureChrome, formatIssues, inspectPage, loadCaptureLogSibling, makeTake, openPath, renderAbReel, renderBeforeAfter, renderComposition, renderCompositionFile, renderReview, requireTakeFiles, resolveChrome, resolveTakePaths, revealPath, stagePrev, startEditServer, validateComposition };
1125
1334
  //# sourceMappingURL=index.js.map