@open-take/compositor 0.2.0 → 0.2.2
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 +56 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +210 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/camera.ts +49 -9
- package/src/math.ts +186 -25
- package/src/plan.ts +12 -3
- package/src/presets.ts +36 -8
- package/src/render.ts +12 -1
- package/src/types.ts +47 -0
- package/src/validate.ts +72 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-take/compositor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Polish compositor (D3) — event log + captured frames -> polished mp4 + editable revideo composition.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@revideo/core": "0.11.0",
|
|
23
23
|
"@revideo/ui": "0.11.0",
|
|
24
24
|
"@revideo/vite-plugin": "0.11.0",
|
|
25
|
-
"@open-take/revideo-renderer": "0.
|
|
25
|
+
"@open-take/revideo-renderer": "0.2.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^22.10.1",
|
package/src/camera.ts
CHANGED
|
@@ -70,20 +70,48 @@ const union = (a: BBox, b: BBox): BBox => {
|
|
|
70
70
|
// grows DOWNWARD out of it. Framing the strip alone puts dead header above and
|
|
71
71
|
// crops the result below. Grow the ROI down (never up) so the frame sits over
|
|
72
72
|
// field + result: a taller ROI ⇒ lower scale AND a centre that drops below the
|
|
73
|
-
// field — both correct.
|
|
74
|
-
//
|
|
73
|
+
// field — both correct. For a type this also CAPS the effectBox height: a
|
|
74
|
+
// search/filter result list is open-ended, so the raw frame-diff region can
|
|
75
|
+
// span the whole viewport and flatten the punch to ~1× — growDown bounds how far
|
|
76
|
+
// down the frame reaches while the effectBox still supplies the real reveal width.
|
|
75
77
|
function growDown(box: BBox, video: { w: number; h: number }): BBox {
|
|
76
78
|
const grownH = Math.max(box.h, Math.min(video.h * 0.42, box.w * 0.55));
|
|
77
79
|
const h = Math.min(grownH, video.h - box.y); // never spill past the video edge
|
|
78
80
|
return { x: box.x, y: box.y, w: box.w, h };
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
/** The region a beat is "about" — what the camera should frame.
|
|
82
|
-
*
|
|
83
|
+
/** The region a beat is "about" — what the camera should frame. A type is
|
|
84
|
+
* field-anchored and height-capped (its reveal is open-ended); every other
|
|
85
|
+
* kind trusts the captured effect region, else shapes one from the bbox. */
|
|
83
86
|
function roiForBeat(b: Beat, video: { w: number; h: number }): BBox | undefined {
|
|
87
|
+
// A press with an EXPLICIT zoom=always + a located reveal element: the
|
|
88
|
+
// author named exactly what to frame — that box outranks the frame-diff
|
|
89
|
+
// effectBox. A press payoff behind a scrim (modal / command palette) diffs
|
|
90
|
+
// as a full-frame repaint, which would flatten the punch to ~1× (issue #3);
|
|
91
|
+
// and a tiny incidental effectBox (a save indicator) would yank the frame
|
|
92
|
+
// somewhere else entirely (issue #8). click/hover keep effectBox preference:
|
|
93
|
+
// there the payoff usually lands AWAY from the element, which is the whole
|
|
94
|
+
// point of the frame-diff seam.
|
|
95
|
+
if (b.kind === "press" && b.intent === "always" && b.box) return b.box;
|
|
96
|
+
if (b.kind === "type" && b.box) {
|
|
97
|
+
// Bound the frame to "field + top of results": keep the effectBox's real
|
|
98
|
+
// reveal WIDTH, but cap the HEIGHT to growDown's result-sized window so an
|
|
99
|
+
// open-ended result list can't flatten the punch to ~1× (see growDown).
|
|
100
|
+
const capH = growDown(b.box, video).h;
|
|
101
|
+
if (b.effectBox) {
|
|
102
|
+
const x = Math.min(b.box.x, b.effectBox.x);
|
|
103
|
+
const right = Math.max(b.box.x + b.box.w, b.effectBox.x + b.effectBox.w);
|
|
104
|
+
const bottom = b.effectBox.y + b.effectBox.h;
|
|
105
|
+
// Floor at the field height so a reveal that lands at/above the field top
|
|
106
|
+
// (a rare upward-opening autocomplete) can't yield a zero/negative ROI —
|
|
107
|
+
// we then simply frame the field, never punch into the vacated space above.
|
|
108
|
+
const h = Math.max(b.box.h, Math.min(capH, bottom - b.box.y));
|
|
109
|
+
return { x, y: b.box.y, w: right - x, h };
|
|
110
|
+
}
|
|
111
|
+
return growDown(b.box, video);
|
|
112
|
+
}
|
|
84
113
|
if (b.effectBox) return b.effectBox;
|
|
85
114
|
if (!b.box) return undefined;
|
|
86
|
-
if (b.kind === "type") return growDown(b.box, video);
|
|
87
115
|
return b.box;
|
|
88
116
|
}
|
|
89
117
|
|
|
@@ -144,17 +172,25 @@ export function directCamera(
|
|
|
144
172
|
boundary: true,
|
|
145
173
|
reason: "plan: zoom=never → full view",
|
|
146
174
|
};
|
|
147
|
-
if (b.intent === "always")
|
|
175
|
+
if (b.intent === "always") {
|
|
176
|
+
// An explicit "always" must never ship a no-op: a wide ROI can fit-scale
|
|
177
|
+
// into the imperceptible band (rest…~1.1×) and render an enabled zoom
|
|
178
|
+
// the eye can't see (issue #1). Floor at minZoomScale — the author asked
|
|
179
|
+
// for a punch, so give the smallest one that reads as one.
|
|
180
|
+
const floored = roi ? Math.max(scale, cam.minZoomScale) : scale;
|
|
148
181
|
return {
|
|
149
182
|
roi,
|
|
150
|
-
scale,
|
|
183
|
+
scale: floored,
|
|
151
184
|
forceFull: false,
|
|
152
185
|
forcePunch: true,
|
|
153
186
|
boundary: true,
|
|
154
187
|
reason: roi
|
|
155
|
-
?
|
|
188
|
+
? floored > scale
|
|
189
|
+
? `plan: zoom=always → ROI fit ${scale.toFixed(2)}× is imperceptible — floored to ${floored.toFixed(2)}×`
|
|
190
|
+
: `plan: zoom=always → ${floored.toFixed(2)}× (framing from ROI)`
|
|
156
191
|
: "plan: zoom=always but no bbox to frame → full view",
|
|
157
192
|
};
|
|
193
|
+
}
|
|
158
194
|
|
|
159
195
|
// a scroll is a pan beat: content moves, the frame stays full-view.
|
|
160
196
|
if (b.kind === "scroll")
|
|
@@ -195,7 +231,11 @@ export function directCamera(
|
|
|
195
231
|
|
|
196
232
|
// the opening beat orients: open on the whole app (Q3 — falls out of "the
|
|
197
233
|
// camera opens full", no zoomFirst flag). A cold-open uses zoom=always.
|
|
198
|
-
|
|
234
|
+
// Only when the beat actually opens the video, though: a first action ≥2s
|
|
235
|
+
// in (a leading `wait`, a slow warmup) already gave the viewer the full
|
|
236
|
+
// view — forcing it wide again just robs the hero moment (issue #2; the
|
|
237
|
+
// default warmup alone puts an immediate first action at ~1s).
|
|
238
|
+
if (i === 0 && b.tMs < 2000)
|
|
199
239
|
return {
|
|
200
240
|
roi,
|
|
201
241
|
scale,
|
package/src/math.ts
CHANGED
|
@@ -229,12 +229,35 @@ export function keyvalR(t: number, kfs: KF<CamRect>[], ease: (u: number) => numb
|
|
|
229
229
|
return kfs[kfs.length - 1]![1];
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
// The camera schedule shared by buildStageKeyframes (the render path) and
|
|
233
|
+
// cameraRampSchedule (the refine surfaces — A/B windows, review badges): which
|
|
234
|
+
// events anchor a camera move, when each ramp departs, and when it lands.
|
|
235
|
+
// One computation so the badge/window timing can never drift from the render.
|
|
236
|
+
type CameraSchedule = {
|
|
237
|
+
anchors: {
|
|
238
|
+
evIdx: number;
|
|
239
|
+
tMs: number;
|
|
240
|
+
durationMs: number;
|
|
241
|
+
inAtMs: number;
|
|
242
|
+
scale: number;
|
|
243
|
+
center: Pt;
|
|
244
|
+
glide?: Pt;
|
|
245
|
+
}[];
|
|
246
|
+
targets: CamRect[];
|
|
247
|
+
restR: CamRect;
|
|
248
|
+
/** per-anchor ramp window, SECONDS */
|
|
249
|
+
ramps: { start: number; end: number }[];
|
|
250
|
+
/** per-anchor landing time, SECONDS (≥ ramp start + a minimal real ramp;
|
|
251
|
+
* == tMs for every on-time ramp, later for a dwell-delayed pull-out) */
|
|
252
|
+
landTs: number[];
|
|
253
|
+
rectFor: (center: Pt, scale: number) => CamRect;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
function buildCameraSchedule(comp: TakeComposition): CameraSchedule {
|
|
233
257
|
const { videoWidth: vW, videoHeight: vH } = comp.source;
|
|
234
258
|
const { width: oW, height: oH } = comp.output;
|
|
235
259
|
const rest = restStageScale(vW, vH, oW, oH, comp.framing.insetFrac);
|
|
236
260
|
const restC: Pt = { x: vW / 2, y: vH / 2 };
|
|
237
|
-
const HOLD = comp.cursor.holdMs / 1000;
|
|
238
261
|
const ZOUT_MS = comp.cursor.zoomOutMs;
|
|
239
262
|
|
|
240
263
|
// A framing target is clamped ONCE, here at build time (the viewport crop
|
|
@@ -260,23 +283,15 @@ export function buildStageKeyframes(comp: TakeComposition): StageKeyframes {
|
|
|
260
283
|
// global) ramp back to REST so the frame is full-view through them — without
|
|
261
284
|
// these, a prior zoom would persist across the scroll/keypress. Other
|
|
262
285
|
// disabled beats (a "never" click) keep holding the prior framing, unchanged.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
durationMs:
|
|
266
|
-
inAtMs: number;
|
|
267
|
-
scale: number;
|
|
268
|
-
center: Pt;
|
|
269
|
-
glide?: Pt;
|
|
270
|
-
};
|
|
271
|
-
const anchors: Anchor[] = [];
|
|
272
|
-
for (const e of comp.events) {
|
|
273
|
-
const base = { tMs: e.tMs, durationMs: e.durationMs ?? 0, inAtMs: e.zoom.inAtMs };
|
|
286
|
+
const anchors: CameraSchedule["anchors"] = [];
|
|
287
|
+
comp.events.forEach((e, evIdx) => {
|
|
288
|
+
const base = { evIdx, tMs: e.tMs, durationMs: e.durationMs ?? 0, inAtMs: e.zoom.inAtMs };
|
|
274
289
|
if (e.kind === "scroll" || (e.kind === "press" && !e.zoom.enabled)) {
|
|
275
290
|
anchors.push({ ...base, scale: rest, center: restC });
|
|
276
291
|
} else if (e.zoom.enabled) {
|
|
277
292
|
anchors.push({ ...base, scale: e.zoom.scale, center: e.zoom.center, glide: e.zoom.glide });
|
|
278
293
|
}
|
|
279
|
-
}
|
|
294
|
+
});
|
|
280
295
|
|
|
281
296
|
const targets = anchors.map((e) => rectFor(e.center, e.scale));
|
|
282
297
|
|
|
@@ -291,17 +306,93 @@ export function buildStageKeyframes(comp: TakeComposition): StageKeyframes {
|
|
|
291
306
|
// ramp: a pull-out with no window is a jump cut, which is strictly worse
|
|
292
307
|
// than leaving a payoff a little early.
|
|
293
308
|
const ZIN_MS = comp.cursor.zoomInMs;
|
|
294
|
-
const
|
|
309
|
+
const DWELL_MS = comp.cursor.pullOutDwellMs ?? 0;
|
|
310
|
+
const ramps = anchors.map((e, i) => {
|
|
295
311
|
const from = i > 0 ? targets[i - 1]! : restR;
|
|
296
312
|
const pullOut = targets[i]!.w > from.w + 1e-6;
|
|
297
313
|
const isDefaultInAt = Math.abs(e.inAtMs - Math.max(0, e.tMs - ZIN_MS)) < 1;
|
|
298
|
-
if (!pullOut || !isDefaultInAt) return e.inAtMs / 1000;
|
|
314
|
+
if (!pullOut || !isDefaultInAt) return { start: e.inAtMs / 1000, end: e.tMs / 1000 };
|
|
299
315
|
const desired = e.tMs - ZOUT_MS;
|
|
300
316
|
const prevEndMs = i > 0 ? anchors[i - 1]!.tMs + anchors[i - 1]!.durationMs : 0;
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
317
|
+
const floor = prevEndMs + DWELL_MS;
|
|
318
|
+
if (desired >= floor) return { start: Math.max(desired, 0) / 1000, end: e.tMs / 1000 };
|
|
319
|
+
if (DWELL_MS > 0) {
|
|
320
|
+
// The dwell floor pushes the departure past the on-time window: keep the
|
|
321
|
+
// full pull-out ramp and LAND LATE (after the action instant) rather than
|
|
322
|
+
// flee a frame the viewer is still reading. The landing is capped at the
|
|
323
|
+
// next anchor's ramp start at push time.
|
|
324
|
+
return { start: floor / 1000, end: (floor + ZOUT_MS) / 1000 };
|
|
325
|
+
}
|
|
326
|
+
const start = Math.min(prevEndMs, e.tMs - Math.min(ZOUT_MS, ZIN_MS));
|
|
327
|
+
return { start: Math.max(start, 0) / 1000, end: e.tMs / 1000 };
|
|
304
328
|
});
|
|
329
|
+
// Second pass: a dwell-floored ramp must still FIT a real ramp before the
|
|
330
|
+
// next anchor departs — otherwise the landT cap would invert it into a
|
|
331
|
+
// 1ms jump cut (push()'s monotone clamp collapses it). Give up dwell time
|
|
332
|
+
// before ramp time: shrink the dwell so at least min(zoomOutMs, zoomInMs)
|
|
333
|
+
// of real ramp survives, and when even zero dwell has no room fall back to
|
|
334
|
+
// the exact legacy squeeze. (Anchor starts never depend on earlier ramps'
|
|
335
|
+
// ends, so one forward pass over pass-1 values is complete.)
|
|
336
|
+
if (DWELL_MS > 0) {
|
|
337
|
+
const minRamp = Math.min(ZOUT_MS, ZIN_MS);
|
|
338
|
+
for (let i = 0; i < ramps.length - 1; i++) {
|
|
339
|
+
const r = ramps[i]!;
|
|
340
|
+
const e = anchors[i]!;
|
|
341
|
+
if (r.end <= e.tMs / 1000 + 1e-9) continue; // on-time ramp — not dwell-late
|
|
342
|
+
const latestStart = ramps[i + 1]!.start - 0.01 - minRamp / 1000;
|
|
343
|
+
if (r.start <= latestStart) continue; // the late landing fits
|
|
344
|
+
const prevEndMs = i > 0 ? anchors[i - 1]!.tMs + anchors[i - 1]!.durationMs : 0;
|
|
345
|
+
if (latestStart * 1000 >= prevEndMs) {
|
|
346
|
+
r.start = latestStart;
|
|
347
|
+
r.end = Math.min(r.start + ZOUT_MS / 1000, ramps[i + 1]!.start - 0.01);
|
|
348
|
+
} else {
|
|
349
|
+
const start = Math.min(prevEndMs, e.tMs - minRamp);
|
|
350
|
+
r.start = Math.max(start, 0) / 1000;
|
|
351
|
+
r.end = e.tMs / 1000;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// A dwell-delayed pull-out lands after its own action instant; cap the
|
|
357
|
+
// landing so it can never run into the next anchor's ramp (floored at a
|
|
358
|
+
// minimal real ramp — the fits-check in the dwell pass guarantees room).
|
|
359
|
+
// An on-time ramp (end === tMs, every legacy entry) keeps the exact old
|
|
360
|
+
// landing; a pass-2-shrunk ramp may deliberately land BEFORE its tMs.
|
|
361
|
+
const landTs = anchors.map((e, i) => {
|
|
362
|
+
const nextStart = anchors[i + 1] ? ramps[i + 1]!.start : Number.POSITIVE_INFINITY;
|
|
363
|
+
const rampEnd = ramps[i]!.end;
|
|
364
|
+
return rampEnd === e.tMs / 1000
|
|
365
|
+
? rampEnd
|
|
366
|
+
: Math.max(
|
|
367
|
+
ramps[i]!.start + Math.min(ZOUT_MS, ZIN_MS) / 1000,
|
|
368
|
+
Math.min(rampEnd, nextStart - 0.01),
|
|
369
|
+
);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
return { anchors, targets, restR, ramps, landTs, rectFor };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Per-EVENT camera ramp timing (ms), for the refine surfaces (A/B windows,
|
|
376
|
+
* review badges): when the camera actually departs toward a beat and when it
|
|
377
|
+
* lands. `null` for a beat the camera holds through (no anchor). Derived from
|
|
378
|
+
* the same schedule the render uses, so a dwell-delayed pull-out (which
|
|
379
|
+
* departs after the stored inAtMs and can land after its own tMs) is
|
|
380
|
+
* reflected instead of approximated from inAtMs. */
|
|
381
|
+
export function cameraRampSchedule(
|
|
382
|
+
comp: TakeComposition,
|
|
383
|
+
): ({ startMs: number; landMs: number } | null)[] {
|
|
384
|
+
const { anchors, ramps, landTs } = buildCameraSchedule(comp);
|
|
385
|
+
const out: ({ startMs: number; landMs: number } | null)[] = comp.events.map(() => null);
|
|
386
|
+
anchors.forEach((a, i) => {
|
|
387
|
+
out[a.evIdx] = { startMs: ramps[i]!.start * 1000, landMs: landTs[i]! * 1000 };
|
|
388
|
+
});
|
|
389
|
+
return out;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export function buildStageKeyframes(comp: TakeComposition): StageKeyframes {
|
|
393
|
+
const { anchors, targets, restR, ramps, landTs, rectFor } = buildCameraSchedule(comp);
|
|
394
|
+
const HOLD = comp.cursor.holdMs / 1000;
|
|
395
|
+
const ZOUT_MS = comp.cursor.zoomOutMs;
|
|
305
396
|
|
|
306
397
|
const rf: { t: number; r: CamRect }[] = [{ t: 0, r: restR }];
|
|
307
398
|
const push = (t: number, r: CamRect) => {
|
|
@@ -310,21 +401,22 @@ export function buildStageKeyframes(comp: TakeComposition): StageKeyframes {
|
|
|
310
401
|
|
|
311
402
|
let cur = restR;
|
|
312
403
|
anchors.forEach((e, i) => {
|
|
313
|
-
const clickT = e.tMs / 1000;
|
|
314
404
|
// the action plays out (typing/drawing/scrolling) for durationMs after tMs
|
|
315
405
|
// — hold the target framing through it (a point click has duration 0).
|
|
316
406
|
const actionEnd = (e.tMs + e.durationMs) / 1000;
|
|
317
407
|
const next = anchors[i + 1];
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
408
|
+
const nextStart = next ? ramps[i + 1]!.start : Number.POSITIVE_INFINITY;
|
|
409
|
+
const landT = landTs[i]!;
|
|
410
|
+
const holdEndT = Math.max(next ? nextStart : actionEnd + HOLD, landT);
|
|
411
|
+
push(ramps[i]!.start, cur); // hold current until ramp begins
|
|
412
|
+
push(landT, targets[i]!); // ONE eased rect segment lands at the action
|
|
321
413
|
cur = targets[i]!;
|
|
322
414
|
// glide: drift the held centre across the hold window (velocity px/s ·
|
|
323
415
|
// holdSeconds), so a held zoom slowly pans instead of sitting dead-static.
|
|
324
416
|
// Clamped like any target so the drift can't leave the recording.
|
|
325
417
|
let holdR = cur;
|
|
326
418
|
if (e.glide && (e.glide.x !== 0 || e.glide.y !== 0)) {
|
|
327
|
-
const holdDur = Math.max(0, holdEndT -
|
|
419
|
+
const holdDur = Math.max(0, holdEndT - landT);
|
|
328
420
|
holdR = rectFor(
|
|
329
421
|
{ x: e.center.x + e.glide.x * holdDur, y: e.center.y + e.glide.y * holdDur },
|
|
330
422
|
e.scale,
|
|
@@ -345,6 +437,70 @@ export function buildStageKeyframes(comp: TakeComposition): StageKeyframes {
|
|
|
345
437
|
return { r: rf.map((f) => [f.t, f.r]), T };
|
|
346
438
|
}
|
|
347
439
|
|
|
440
|
+
// --- asymptotic settle (zoomSettleFrac) --------------------------------
|
|
441
|
+
|
|
442
|
+
/** Residual (1 − progress) of an overdamped spring's unit step response, on
|
|
443
|
+
* NORMALISED segment time u = (t − t0)/(t1 − t0). ω0 is solved so the
|
|
444
|
+
* residual at u=1 (the action instant) equals `frac`; past u=1 the same
|
|
445
|
+
* curve keeps decaying — the tail that replaces the legacy cut. ζ=1.2 gives
|
|
446
|
+
* the reference-measured shape: a fast main ramp (peak velocity ~14% in)
|
|
447
|
+
* plus a slow settle pole; at frac 0.04 the tail τ ≈ duration/3.6 (730ms →
|
|
448
|
+
* ~205ms, 1340ms → ~375ms — the frame-tracked reference tails; a different
|
|
449
|
+
* frac shifts ω0 and with it τ). */
|
|
450
|
+
function settleDecay(frac: number): (u: number) => number {
|
|
451
|
+
const zeta = 1.2;
|
|
452
|
+
const s = Math.sqrt(zeta * zeta - 1);
|
|
453
|
+
const l1 = zeta + s;
|
|
454
|
+
const l2 = zeta - s;
|
|
455
|
+
const resid = (x: number) => (l1 * Math.exp(-l2 * x) - l2 * Math.exp(-l1 * x)) / (l1 - l2);
|
|
456
|
+
let lo = 0.1;
|
|
457
|
+
let hi = 60;
|
|
458
|
+
for (let i = 0; i < 60; i++) {
|
|
459
|
+
const mid = (lo + hi) / 2;
|
|
460
|
+
if (resid(mid) > frac) lo = mid;
|
|
461
|
+
else hi = mid;
|
|
462
|
+
}
|
|
463
|
+
const w0T = (lo + hi) / 2;
|
|
464
|
+
return (u: number) => (u <= 0 ? 1 : resid(w0T * u));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/** Evaluate the rect track with moves that settle ASYMPTOTICALLY: each ramp
|
|
468
|
+
* covers 1−frac of its distance by its keyframe end, then keeps creeping
|
|
469
|
+
* toward the target through the following hold (never a velocity cliff). A
|
|
470
|
+
* ramp launches from wherever the previous tail actually is (position-
|
|
471
|
+
* continuous chaining); every emitted rect is a convex combination of
|
|
472
|
+
* build-time-clamped rects, and the valid-rect set is convex (linear
|
|
473
|
+
* half-plane bounds in cx,cy,w), so in-between rects stay valid exactly as
|
|
474
|
+
* in the lerped path. */
|
|
475
|
+
function settleRectAt(kfs: KF<CamRect>[], decay: (u: number) => number, t: number): CamRect {
|
|
476
|
+
let from = kfs[0]![1];
|
|
477
|
+
for (let i = 0; i < kfs.length - 1; i++) {
|
|
478
|
+
const [t0, r0] = kfs[i]!;
|
|
479
|
+
const [t1, r1] = kfs[i + 1]!;
|
|
480
|
+
if (r0.cx === r1.cx && r0.cy === r1.cy && r0.w === r1.w) continue; // hold — the active tail keeps running
|
|
481
|
+
if (t < t0) break;
|
|
482
|
+
// find when the NEXT move begins — this move's tail runs until then
|
|
483
|
+
let handoff = Number.POSITIVE_INFINITY;
|
|
484
|
+
for (let j = i + 1; j < kfs.length - 1; j++) {
|
|
485
|
+
const [ta, ra] = kfs[j]!;
|
|
486
|
+
const [, rb] = kfs[j + 1]!;
|
|
487
|
+
if (ra.cx !== rb.cx || ra.cy !== rb.cy || ra.w !== rb.w) {
|
|
488
|
+
handoff = ta;
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
const evalT = Math.min(t, handoff);
|
|
493
|
+
const d = decay((evalT - t0) / Math.max(t1 - t0, 1e-6));
|
|
494
|
+
from = {
|
|
495
|
+
cx: r1.cx + (from.cx - r1.cx) * d,
|
|
496
|
+
cy: r1.cy + (from.cy - r1.cy) * d,
|
|
497
|
+
w: r1.w + (from.w - r1.w) * d,
|
|
498
|
+
};
|
|
499
|
+
if (t < handoff) return from;
|
|
500
|
+
}
|
|
501
|
+
return from;
|
|
502
|
+
}
|
|
503
|
+
|
|
348
504
|
/** The one camera evaluator — scene.tsx (render) and the editor preview both
|
|
349
505
|
* consume THIS, so preview and export can never drift. */
|
|
350
506
|
export function stageCamera(comp: TakeComposition): {
|
|
@@ -363,8 +519,13 @@ export function stageCamera(comp: TakeComposition): {
|
|
|
363
519
|
comp.output.height,
|
|
364
520
|
comp.framing.insetFrac,
|
|
365
521
|
);
|
|
522
|
+
// zoomSettleFrac swaps the segment-lerped track for the asymptotic-settle
|
|
523
|
+
// evaluator; explicit zoomSpring/zoomEase keep their exact legacy curves.
|
|
524
|
+
const frac = comp.cursor.zoomSettleFrac ?? 0;
|
|
525
|
+
const useSettle = frac > 0 && comp.cursor.zoomSpring == null && !comp.cursor.zoomEase;
|
|
526
|
+
const decay = useSettle ? settleDecay(frac) : undefined;
|
|
366
527
|
const at = (t: number) => {
|
|
367
|
-
const r = keyvalR(t, stage.r, ease);
|
|
528
|
+
const r = decay ? settleRectAt(stage.r, decay, t) : keyvalR(t, stage.r, ease);
|
|
368
529
|
return { scale: oW / r.w, center: { x: r.cx, y: r.cy } };
|
|
369
530
|
};
|
|
370
531
|
// Peak by sampling (not just keyframe extremes): a spring ease overshoots
|
package/src/plan.ts
CHANGED
|
@@ -37,8 +37,16 @@ export type PlanOpts = {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export function planComposition(log: CaptureLog, opts: PlanOpts = {}): TakeComposition {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
// Stage space = the capture VIEWPORT (CSS px), NOT the video file's pixel
|
|
41
|
+
// size. A Retina capture (captureScale 2) records a 2×-dense bitmap of the
|
|
42
|
+
// same viewport; the scene draws it at viewport size, so the denser bitmap
|
|
43
|
+
// only sharpens sampling under zoom. Keying the stage to the viewport keeps
|
|
44
|
+
// every calibrated quantity — camera scales (rest/minZoomScale/maxScale),
|
|
45
|
+
// cursor/ripple sizes, framing radius/shadow — meaning the same thing at
|
|
46
|
+
// any capture density. (Pre-Retina logs have video == viewport, so this is
|
|
47
|
+
// byte-identical for them.)
|
|
48
|
+
const vW = log.viewport.w,
|
|
49
|
+
vH = log.viewport.h;
|
|
42
50
|
const oW = opts.output?.width ?? vW;
|
|
43
51
|
const oH = opts.output?.height ?? vH;
|
|
44
52
|
const fps = opts.output?.fps ?? 30;
|
|
@@ -47,7 +55,8 @@ export function planComposition(log: CaptureLog, opts: PlanOpts = {}): TakeCompo
|
|
|
47
55
|
const cursor: CursorConfig = { ...DEFAULT_CURSOR, ...opts.cursor };
|
|
48
56
|
const camera: CameraConfig = { ...DEFAULT_CAMERA, ...opts.camera };
|
|
49
57
|
|
|
50
|
-
// viewport CSS px ->
|
|
58
|
+
// log coords (viewport CSS px) -> stage px. Identity today (stage IS the
|
|
59
|
+
// viewport); kept as an explicit mapping seam.
|
|
51
60
|
const sx = vW / log.viewport.w;
|
|
52
61
|
const sy = vH / log.viewport.h;
|
|
53
62
|
const mapPt = (p: Pt): Pt => ({ x: p.x * sx, y: p.y * sy });
|
package/src/presets.ts
CHANGED
|
@@ -40,17 +40,41 @@ export function zoomLevelName(scale: number, tol = 0.07): ZoomLevelName | null {
|
|
|
40
40
|
// default state speakable.
|
|
41
41
|
export type MotionPreset = Pick<
|
|
42
42
|
CursorConfig,
|
|
43
|
-
"travelWidthsPerSec" | "holdMs" | "zoomInMs" | "zoomOutMs"
|
|
43
|
+
"travelWidthsPerSec" | "holdMs" | "zoomInMs" | "zoomOutMs" | "pullOutDwellMs"
|
|
44
44
|
> & { zoomEase?: undefined };
|
|
45
45
|
// zoomIn/zoomOut anchored to the measured reference springs (730/1340 —
|
|
46
46
|
// see DEFAULT_CURSOR); calm/brisk scale both while keeping out ≈ 1.8× in.
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
47
|
+
// pullOutDwellMs (the minimum stay on a payoff before a squeezed pull-out may
|
|
48
|
+
// flee) scales with the same feel: a calm cut breathes longer, a brisk one
|
|
49
|
+
// tolerates a shorter beat. Each preset also CLEARS a legacy zoomEase (spread
|
|
50
|
+
// leaves the key undefined; JSON drops it) so applying a pace migrates an old
|
|
51
|
+
// composition onto the default measured-SS spring curve instead of silently
|
|
52
|
+
// keeping the old bezier.
|
|
50
53
|
export const MOTION: Record<"calm" | "natural" | "brisk", MotionPreset> = {
|
|
51
|
-
calm: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
calm: {
|
|
55
|
+
travelWidthsPerSec: 0.28,
|
|
56
|
+
holdMs: 1500,
|
|
57
|
+
zoomInMs: 900,
|
|
58
|
+
zoomOutMs: 1650,
|
|
59
|
+
pullOutDwellMs: 1000,
|
|
60
|
+
zoomEase: undefined,
|
|
61
|
+
},
|
|
62
|
+
natural: {
|
|
63
|
+
travelWidthsPerSec: 0.35,
|
|
64
|
+
holdMs: 1100,
|
|
65
|
+
zoomInMs: 730,
|
|
66
|
+
zoomOutMs: 1340,
|
|
67
|
+
pullOutDwellMs: 800,
|
|
68
|
+
zoomEase: undefined,
|
|
69
|
+
},
|
|
70
|
+
brisk: {
|
|
71
|
+
travelWidthsPerSec: 0.45,
|
|
72
|
+
holdMs: 750,
|
|
73
|
+
zoomInMs: 550,
|
|
74
|
+
zoomOutMs: 1000,
|
|
75
|
+
pullOutDwellMs: 600,
|
|
76
|
+
zoomEase: undefined,
|
|
77
|
+
},
|
|
54
78
|
};
|
|
55
79
|
export type MotionName = keyof typeof MOTION;
|
|
56
80
|
|
|
@@ -60,7 +84,11 @@ export function motionName(cursor: CursorConfig): MotionName | null {
|
|
|
60
84
|
Math.abs(cursor.travelWidthsPerSec - m.travelWidthsPerSec) < 0.015 &&
|
|
61
85
|
Math.abs(cursor.holdMs - m.holdMs) < 60 &&
|
|
62
86
|
Math.abs(cursor.zoomInMs - m.zoomInMs) < 60 &&
|
|
63
|
-
Math.abs(cursor.zoomOutMs - m.zoomOutMs) < 60
|
|
87
|
+
Math.abs(cursor.zoomOutMs - m.zoomOutMs) < 60 &&
|
|
88
|
+
// absent = a pre-dwell composition — still nameable by its four legacy
|
|
89
|
+
// knobs; only an explicit different value makes the pace "custom".
|
|
90
|
+
(cursor.pullOutDwellMs == null ||
|
|
91
|
+
Math.abs(cursor.pullOutDwellMs - (m.pullOutDwellMs ?? 0)) < 60)
|
|
64
92
|
)
|
|
65
93
|
return name;
|
|
66
94
|
}
|
package/src/render.ts
CHANGED
|
@@ -286,6 +286,17 @@ async function renderTakeExclusive(
|
|
|
286
286
|
);
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
// Head trim (composition.startMs): deliver the timeline from startMs on,
|
|
290
|
+
// through the SAME range mechanism the A/B windows use — the composition
|
|
291
|
+
// timeline (tMs, badges, keyframes) is untouched; only the delivered head
|
|
292
|
+
// moves. An explicit rangeSec (an A/B clip window) wins: those windows are
|
|
293
|
+
// authored on the composition timeline and already judged as clips.
|
|
294
|
+
const rangeSec =
|
|
295
|
+
opts.rangeSec ??
|
|
296
|
+
(composition.startMs && composition.startMs > 0
|
|
297
|
+
? ([composition.startMs / 1000, composition.durationMs / 1000 + 120] as [number, number])
|
|
298
|
+
: undefined);
|
|
299
|
+
|
|
289
300
|
// Revideo spawns its bundled ffprobe directly. Repair installer permissions
|
|
290
301
|
// here so published consumers are protected even though they do not run the
|
|
291
302
|
// monorepo root's postinstall script.
|
|
@@ -309,7 +320,7 @@ async function renderTakeExclusive(
|
|
|
309
320
|
outFile: "take.mp4",
|
|
310
321
|
outDir: RENDER_OUT,
|
|
311
322
|
workers: 1,
|
|
312
|
-
...(
|
|
323
|
+
...(rangeSec ? { projectSettings: { range: rangeSec } } : {}),
|
|
313
324
|
logProgress: opts.logProgress ?? false,
|
|
314
325
|
...(opts.onProgress
|
|
315
326
|
? {
|
package/src/types.ts
CHANGED
|
@@ -117,6 +117,11 @@ export type CaptureLog = {
|
|
|
117
117
|
/** the ordered ground-truth actions (click / type / drag) */
|
|
118
118
|
events: CaptureEvent[];
|
|
119
119
|
tEndMs?: number;
|
|
120
|
+
/** Steps the capture DROPPED (target not found / endpoint unresolved) — the
|
|
121
|
+
* take still completes, but a missing beat must reach the end-of-run
|
|
122
|
+
* summary and (with --strict) the exit code, not just an early stderr line
|
|
123
|
+
* buried under render progress. `step` is the plan's 0-based step index. */
|
|
124
|
+
skipped?: { step: number; action: string; target?: string; reason: string }[];
|
|
120
125
|
};
|
|
121
126
|
|
|
122
127
|
// --- the composition (editable) ----------------------------------------
|
|
@@ -223,6 +228,28 @@ export type CursorConfig = {
|
|
|
223
228
|
* shapes the curve. Bounce > 0 overshoots the RECT (a touch past the target
|
|
224
229
|
* frame, then settle) — keep it small. */
|
|
225
230
|
zoomSpring?: number;
|
|
231
|
+
/** Fraction of a camera ramp still UNfinished at its keyframe end (the action
|
|
232
|
+
* instant), left to settle as an asymptotic overdamped tail that continues
|
|
233
|
+
* INTO the hold — so a move tapers out like a physical camera instead of
|
|
234
|
+
* stopping on a velocity cliff at the keyframe. Frame-tracked on the
|
|
235
|
+
* reference export: its moves keep sub-threshold motion ~0.5s past the
|
|
236
|
+
* visible end (tail τ ≈ 220ms in / ≈ 370ms out), while the cut spring's
|
|
237
|
+
* τ = duration/6.9 ends 2-3× harder. ~0.04 (the shipped default) reproduces
|
|
238
|
+
* the reference tails over the default zoomInMs/zoomOutMs. 0 = legacy
|
|
239
|
+
* cut+normalized spring (absent falls back to the default on NEW plans; an
|
|
240
|
+
* old composition without the field renders as it always did). Ignored when
|
|
241
|
+
* zoomSpring or zoomEase is set (those keep their exact legacy curves). */
|
|
242
|
+
zoomSettleFrac?: number;
|
|
243
|
+
/** Minimum stay (ms) after the previous action's visible end before a
|
|
244
|
+
* PULL-OUT ramp may begin. When the beat gap is too tight the pull-out now
|
|
245
|
+
* departs late and LANDS late (after its own action instant) instead of
|
|
246
|
+
* fleeing a frame the viewer is still reading — the reference recorder's
|
|
247
|
+
* reactive pattern (payoff plays while the camera is still arriving).
|
|
248
|
+
* ~800 (the shipped default) reads as a natural beat; pace presets scale it.
|
|
249
|
+
* 0/absent = legacy (a squeezed pull-out departs the instant the previous
|
|
250
|
+
* action ends and lands exactly on its action). Named pullOut- because
|
|
251
|
+
* holdMs already covers the ordinary post-action dwell. */
|
|
252
|
+
pullOutDwellMs?: number;
|
|
226
253
|
/** ms to delay the synthetic cursor along a DRAG stroke, compensating for the
|
|
227
254
|
* capture pipeline latency: the captured ink appears ~this long after the pen
|
|
228
255
|
* actually moved, so without the delay the (exact-time) cursor leads the ink.
|
|
@@ -322,6 +349,10 @@ export type TakeComposition = {
|
|
|
322
349
|
output: { width: number; height: number; fps: number };
|
|
323
350
|
source: {
|
|
324
351
|
videoUrl: string;
|
|
352
|
+
/** stage size the source video is DRAWN at (capture viewport CSS px) —
|
|
353
|
+
* the coordinate space of every event/bbox below. A Retina capture's
|
|
354
|
+
* file is denser (viewport × captureScale); the scene stretches it to
|
|
355
|
+
* this size, so the extra pixels only sharpen sampling under zoom. */
|
|
325
356
|
videoWidth: number;
|
|
326
357
|
videoHeight: number;
|
|
327
358
|
viewport: { w: number; h: number };
|
|
@@ -334,6 +365,14 @@ export type TakeComposition = {
|
|
|
334
365
|
start: Pt;
|
|
335
366
|
events: CompEvent[];
|
|
336
367
|
durationMs: number;
|
|
368
|
+
/** Head trim (ms of the composition timeline cut from the delivered mp4).
|
|
369
|
+
* Capture starts at navigation, so the first frames show the app before it
|
|
370
|
+
* painted (plus any cold-cache font swap) — trim them here instead of
|
|
371
|
+
* post-processing with ffmpeg, so the refine loop keeps applying to the file
|
|
372
|
+
* actually shipped. Event tMs values stay on the untrimmed timeline (the
|
|
373
|
+
* capture is the ground truth); only the delivered head moves. 0/absent =
|
|
374
|
+
* no trim. */
|
|
375
|
+
startMs?: number;
|
|
337
376
|
/** render-time review decoration (badges/watermark/label); never persisted */
|
|
338
377
|
review?: ReviewDecor;
|
|
339
378
|
};
|
|
@@ -393,6 +432,14 @@ export const DEFAULT_CURSOR: CursorConfig = {
|
|
|
393
432
|
// critically-damped spring that IS the measured SS curve over these windows.
|
|
394
433
|
zoomOutMs: 1340,
|
|
395
434
|
zoomInMs: 730,
|
|
435
|
+
// Asymptotic settle + pull-out dwell — the A/B "C variant" Pascal signed off
|
|
436
|
+
// (2026-07-26): each camera move keeps a ~4% residual settling INTO the hold
|
|
437
|
+
// (no velocity cliff at the keyframe — the frame-tracked reference tail), and
|
|
438
|
+
// a squeezed pull-out stays ≥800ms on the payoff, landing late instead of
|
|
439
|
+
// fleeing a frame the viewer is still reading. Old compositions without the
|
|
440
|
+
// fields keep the legacy cut/squeeze schedule byte-identically.
|
|
441
|
+
zoomSettleFrac: 0.04,
|
|
442
|
+
pullOutDwellMs: 800,
|
|
396
443
|
// The captured ink trails the pen by the screencast/encode pipeline latency τ;
|
|
397
444
|
// delay the cursor by τ so its tip rides the ink front. Set to τ EXACTLY and
|
|
398
445
|
// the cursor locks to the ink at ALL stroke speeds (both are the same time-
|