@open-take/compositor 0.2.1 → 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 +52 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +190 -26
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/camera.ts +25 -4
- package/src/math.ts +186 -25
- package/src/presets.ts +36 -8
- package/src/render.ts +12 -1
- package/src/types.ts +43 -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.2.
|
|
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
|
@@ -84,6 +84,15 @@ function growDown(box: BBox, video: { w: number; h: number }): BBox {
|
|
|
84
84
|
* field-anchored and height-capped (its reveal is open-ended); every other
|
|
85
85
|
* kind trusts the captured effect region, else shapes one from the bbox. */
|
|
86
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;
|
|
87
96
|
if (b.kind === "type" && b.box) {
|
|
88
97
|
// Bound the frame to "field + top of results": keep the effectBox's real
|
|
89
98
|
// reveal WIDTH, but cap the HEIGHT to growDown's result-sized window so an
|
|
@@ -163,17 +172,25 @@ export function directCamera(
|
|
|
163
172
|
boundary: true,
|
|
164
173
|
reason: "plan: zoom=never → full view",
|
|
165
174
|
};
|
|
166
|
-
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;
|
|
167
181
|
return {
|
|
168
182
|
roi,
|
|
169
|
-
scale,
|
|
183
|
+
scale: floored,
|
|
170
184
|
forceFull: false,
|
|
171
185
|
forcePunch: true,
|
|
172
186
|
boundary: true,
|
|
173
187
|
reason: roi
|
|
174
|
-
?
|
|
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)`
|
|
175
191
|
: "plan: zoom=always but no bbox to frame → full view",
|
|
176
192
|
};
|
|
193
|
+
}
|
|
177
194
|
|
|
178
195
|
// a scroll is a pan beat: content moves, the frame stays full-view.
|
|
179
196
|
if (b.kind === "scroll")
|
|
@@ -214,7 +231,11 @@ export function directCamera(
|
|
|
214
231
|
|
|
215
232
|
// the opening beat orients: open on the whole app (Q3 — falls out of "the
|
|
216
233
|
// camera opens full", no zoomFirst flag). A cold-open uses zoom=always.
|
|
217
|
-
|
|
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)
|
|
218
239
|
return {
|
|
219
240
|
roi,
|
|
220
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/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.
|
|
@@ -338,6 +365,14 @@ export type TakeComposition = {
|
|
|
338
365
|
start: Pt;
|
|
339
366
|
events: CompEvent[];
|
|
340
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;
|
|
341
376
|
/** render-time review decoration (badges/watermark/label); never persisted */
|
|
342
377
|
review?: ReviewDecor;
|
|
343
378
|
};
|
|
@@ -397,6 +432,14 @@ export const DEFAULT_CURSOR: CursorConfig = {
|
|
|
397
432
|
// critically-damped spring that IS the measured SS curve over these windows.
|
|
398
433
|
zoomOutMs: 1340,
|
|
399
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,
|
|
400
443
|
// The captured ink trails the pen by the screencast/encode pipeline latency τ;
|
|
401
444
|
// delay the cursor by τ so its tip rides the ink front. Set to τ EXACTLY and
|
|
402
445
|
// the cursor locks to the ink at ALL stroke speeds (both are the same time-
|
package/src/validate.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// action needs a re-capture, not a JSON edit. Pass the capture log to enforce
|
|
17
17
|
// this; without it the check is skipped (we can't know the ground truth).
|
|
18
18
|
|
|
19
|
-
import { restStageScale } from "./math";
|
|
19
|
+
import { buildStageKeyframes, restStageScale } from "./math";
|
|
20
20
|
import type { CaptureLog, TakeComposition } from "./types";
|
|
21
21
|
|
|
22
22
|
export type CompositionIssue = {
|
|
@@ -154,11 +154,13 @@ export function validateComposition(
|
|
|
154
154
|
`scale ${z.scale.toFixed(3)} is below rest ${rest.toFixed(3)} — that zooms OUT past the frame (dead space)`,
|
|
155
155
|
`raise to ≥ ${rest.toFixed(2)}, or set zoom.enabled=false for a full-view beat`,
|
|
156
156
|
);
|
|
157
|
-
else if (z.scale
|
|
157
|
+
else if (z.scale < rest * 1.2)
|
|
158
|
+
// the whole dead band, not just ≈rest exactly: a 1.03× "zoom" renders
|
|
159
|
+
// an enabled move the eye can't see (issue #1 — it shipped silently).
|
|
158
160
|
warn(
|
|
159
161
|
`${p}.zoom.scale`,
|
|
160
|
-
`scale ${z.scale.toFixed(3)}
|
|
161
|
-
"raise scale to actually zoom, or set enabled=false",
|
|
162
|
+
`scale ${z.scale.toFixed(3)} is within 20% of rest ${rest.toFixed(3)} — an imperceptible zoom (enabled but invisible)`,
|
|
163
|
+
"raise scale to ≥ ~1.25 to actually zoom, or set enabled=false",
|
|
162
164
|
);
|
|
163
165
|
if (z.scale > maxScale)
|
|
164
166
|
warn(
|
|
@@ -205,6 +207,30 @@ export function validateComposition(
|
|
|
205
207
|
);
|
|
206
208
|
}
|
|
207
209
|
|
|
210
|
+
// asymptotic settle: the residual left to creep out after the action instant.
|
|
211
|
+
// Beyond ~0.15 the camera visibly hasn't arrived when the action fires.
|
|
212
|
+
const settleFrac = comp.cursor.zoomSettleFrac;
|
|
213
|
+
if (settleFrac != null && !(settleFrac >= 0 && settleFrac <= 0.15))
|
|
214
|
+
err(
|
|
215
|
+
"cursor.zoomSettleFrac",
|
|
216
|
+
`zoomSettleFrac ${settleFrac} outside [0, 0.15]`,
|
|
217
|
+
"~0.04 = the reference-measured tail; 0 = legacy cut spring",
|
|
218
|
+
);
|
|
219
|
+
else if (settleFrac != null && settleFrac > 0 && (comp.cursor.zoomEase || spring != null))
|
|
220
|
+
warn(
|
|
221
|
+
"cursor.zoomSettleFrac",
|
|
222
|
+
`zoomSettleFrac is IGNORED while cursor.${comp.cursor.zoomEase ? "zoomEase" : "zoomSpring"} is set — the render is byte-identical to not setting it`,
|
|
223
|
+
"delete cursor.zoomEase / cursor.zoomSpring (a pace preset clears zoomEase) to activate the settle tail",
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const dwell = comp.cursor.pullOutDwellMs;
|
|
227
|
+
if (dwell != null && !(dwell >= 0 && dwell <= 5000))
|
|
228
|
+
err(
|
|
229
|
+
"cursor.pullOutDwellMs",
|
|
230
|
+
`pullOutDwellMs ${dwell} outside [0, 5000]`,
|
|
231
|
+
"600-1000 reads as a natural beat; 0 = legacy (depart as soon as the action ends)",
|
|
232
|
+
);
|
|
233
|
+
|
|
208
234
|
// tail: the composition must outlast the last action (+ a little settle)
|
|
209
235
|
if (comp.durationMs < lastEnd)
|
|
210
236
|
err(
|
|
@@ -219,6 +245,48 @@ export function validateComposition(
|
|
|
219
245
|
`allow ≥ ${comp.cursor.zoomOutMs}ms (cursor.zoomOutMs) of tail`,
|
|
220
246
|
);
|
|
221
247
|
|
|
248
|
+
// A dwell-delayed final pull-out can land LATER than the legacy tail math
|
|
249
|
+
// above assumes — check the actual schedule, not the formula. (Guarded: the
|
|
250
|
+
// schedule needs a structurally sound composition; earlier errors mean this
|
|
251
|
+
// check would throw, and its absence is already explained by them.)
|
|
252
|
+
if ((comp.cursor.pullOutDwellMs ?? 0) > 0 && issues.every((i) => i.severity !== "error")) {
|
|
253
|
+
try {
|
|
254
|
+
const kfs = buildStageKeyframes(comp).r;
|
|
255
|
+
let motionEndS = 0;
|
|
256
|
+
for (let i = 0; i < kfs.length - 1; i++) {
|
|
257
|
+
const [, a] = kfs[i]!;
|
|
258
|
+
const [t1, b] = kfs[i + 1]!;
|
|
259
|
+
if (a.cx !== b.cx || a.cy !== b.cy || a.w !== b.w) motionEndS = t1;
|
|
260
|
+
}
|
|
261
|
+
if (motionEndS * 1000 > comp.durationMs + 1)
|
|
262
|
+
warn(
|
|
263
|
+
"durationMs",
|
|
264
|
+
`the camera is still mid-motion at durationMs (dwell-delayed landing ends ~${Math.round(motionEndS * 1000)}ms)`,
|
|
265
|
+
`raise durationMs to ≥ ${Math.round(motionEndS * 1000)}`,
|
|
266
|
+
);
|
|
267
|
+
} catch {
|
|
268
|
+
/* never let a diagnostics pass throw */
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// head trim: cut dead pre-paint frames, never a beat. The trim only moves
|
|
273
|
+
// the delivered head — tMs values stay on the capture timeline.
|
|
274
|
+
const startMs = comp.startMs;
|
|
275
|
+
if (startMs != null) {
|
|
276
|
+
if (!(startMs >= 0) || startMs >= comp.durationMs)
|
|
277
|
+
err(
|
|
278
|
+
"startMs",
|
|
279
|
+
`startMs ${startMs} outside [0, durationMs ${comp.durationMs})`,
|
|
280
|
+
"the head trim must leave a video",
|
|
281
|
+
);
|
|
282
|
+
else if (comp.events[0] && startMs > comp.events[0].zoom.inAtMs)
|
|
283
|
+
warn(
|
|
284
|
+
"startMs",
|
|
285
|
+
`startMs ${startMs} cuts into the first beat (camera/cursor already moving at ${comp.events[0].zoom.inAtMs}ms)`,
|
|
286
|
+
`keep the trim ≤ ${comp.events[0].zoom.inAtMs} so the delivered video opens at rest`,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
222
290
|
// --- CAPTURE-LOCKED: action tMs must match the recording ---
|
|
223
291
|
// The video is temporal: a beat's tMs is WHEN it is visible in the capture.
|
|
224
292
|
// A render-only edit cannot move that, so a drifted tMs would fire the
|