@open-take/compositor 0.2.6 → 0.2.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-take/compositor",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
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.6"
25
+ "@open-take/revideo-renderer": "0.2.8"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.10.1",
package/src/camera.ts CHANGED
@@ -28,7 +28,7 @@ import type { BBox, CameraConfig, Pt, ZoomIntent } from "./types";
28
28
 
29
29
  /** One action, already mapped into video-px, handed to the director. */
30
30
  export type Beat = {
31
- kind: "click" | "type" | "drag" | "scroll" | "hover" | "press";
31
+ kind: "click" | "type" | "drag" | "scroll" | "hover" | "press" | "dropFiles";
32
32
  tMs: number;
33
33
  durationMs: number;
34
34
  /** element bbox (for a drag: the path's bbox), video-px — or undefined for a
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@ export * from "./presets";
12
12
  export { resolveFfmpeg, resolveFfprobe } from "./ffmpeg";
13
13
  export { planComposition, type PlanOpts } from "./plan";
14
14
  export { directCamera, type Beat, type Framing } from "./camera";
15
- export { renderTake, type RenderTakeOpts } from "./render";
15
+ export { renderTake, type RenderTakeOpts, type RenderTakeResult } from "./render";
16
16
  export {
17
17
  validateComposition,
18
18
  formatIssues,
package/src/math.ts CHANGED
@@ -248,7 +248,8 @@ type CameraSchedule = {
248
248
  /** per-anchor ramp window, SECONDS */
249
249
  ramps: { start: number; end: number }[];
250
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) */
251
+ * == tMs for every on-time ramp, later for a dwell-delayed pull-out or a
252
+ * reveal-timed press whose ramp departs AT the action) */
252
253
  landTs: number[];
253
254
  rectFor: (center: Pt, scale: number) => CamRect;
254
255
  };
@@ -322,9 +323,17 @@ function buildCameraSchedule(comp: TakeComposition): CameraSchedule {
322
323
  // than leaving a payoff a little early.
323
324
  const ZIN_MS = comp.cursor.zoomInMs;
324
325
  const DWELL_MS = comp.cursor.pullOutDwellMs ?? 0;
326
+ // A ramp whose departure sits AT/after its own action is REVEAL-timed: the
327
+ // planner pins a zoom-enabled press there (its payoff exists only after the
328
+ // keypress — a lead-in would punch into empty space), and a hand-set late
329
+ // inAtMs means the same thing. Landing at tMs would make start === end (a
330
+ // jump cut), so these get a full ramp window AFTER the departure instead.
331
+ const revealTimed = (e: { inAtMs: number; tMs: number }): boolean => e.inAtMs >= e.tMs;
325
332
  const ramps = anchors.map((e, i) => {
326
333
  const from = i > 0 ? targets[i - 1]! : restR;
327
334
  const pullOut = targets[i]!.w > from.w + 1e-6;
335
+ if (revealTimed(e))
336
+ return { start: e.inAtMs / 1000, end: (e.inAtMs + (pullOut ? ZOUT_MS : ZIN_MS)) / 1000 };
328
337
  const isDefaultInAt = Math.abs(e.inAtMs - Math.max(0, e.tMs - ZIN_MS)) < 1;
329
338
  if (!pullOut || !isDefaultInAt) return { start: e.inAtMs / 1000, end: e.tMs / 1000 };
330
339
  const desired = e.tMs - ZOUT_MS;
@@ -353,6 +362,7 @@ function buildCameraSchedule(comp: TakeComposition): CameraSchedule {
353
362
  for (let i = 0; i < ramps.length - 1; i++) {
354
363
  const r = ramps[i]!;
355
364
  const e = anchors[i]!;
365
+ if (revealTimed(e)) continue; // fitted in the reveal pass below (departure is pinned)
356
366
  if (r.end <= e.tMs / 1000 + 1e-9) continue; // on-time ramp — not dwell-late
357
367
  const latestStart = ramps[i + 1]!.start - 0.01 - minRamp / 1000;
358
368
  if (r.start <= latestStart) continue; // the late landing fits
@@ -368,14 +378,30 @@ function buildCameraSchedule(comp: TakeComposition): CameraSchedule {
368
378
  }
369
379
  }
370
380
 
381
+ // Reveal fit pass: a reveal-timed ramp's departure is PINNED at the action —
382
+ // moving it earlier would re-create the exact artifact this timing removes
383
+ // (zooming into a reveal that doesn't exist yet). When the full window would
384
+ // run into the next anchor's departure, shrink the ramp (a faster punch)
385
+ // instead, floored at half a window so it still reads as a move; anything
386
+ // tighter falls to push()'s monotone clamp like any other crowding.
387
+ const REVEAL_MIN_S = Math.min(ZOUT_MS, ZIN_MS) / 2000;
388
+ for (let i = 0; i < ramps.length; i++) {
389
+ if (!revealTimed(anchors[i]!)) continue;
390
+ const r = ramps[i]!;
391
+ const nextStart = i + 1 < ramps.length ? ramps[i + 1]!.start : Number.POSITIVE_INFINITY;
392
+ r.end = Math.max(r.start + REVEAL_MIN_S, Math.min(r.end, nextStart - 0.01));
393
+ }
394
+
371
395
  // A dwell-delayed pull-out lands after its own action instant; cap the
372
396
  // landing so it can never run into the next anchor's ramp (floored at a
373
397
  // minimal real ramp — the fits-check in the dwell pass guarantees room).
374
398
  // An on-time ramp (end === tMs, every legacy entry) keeps the exact old
375
- // landing; a pass-2-shrunk ramp may deliberately land BEFORE its tMs.
399
+ // landing; a pass-2-shrunk ramp may deliberately land BEFORE its tMs. A
400
+ // reveal-timed ramp was already fitted above — it lands exactly at its end.
376
401
  const landTs = anchors.map((e, i) => {
377
402
  const nextStart = anchors[i + 1] ? ramps[i + 1]!.start : Number.POSITIVE_INFINITY;
378
403
  const rampEnd = ramps[i]!.end;
404
+ if (revealTimed(e)) return rampEnd;
379
405
  return rampEnd === e.tMs / 1000
380
406
  ? rampEnd
381
407
  : Math.max(
@@ -392,14 +418,23 @@ function buildCameraSchedule(comp: TakeComposition): CameraSchedule {
392
418
  * lands. `null` for a beat the camera holds through (no anchor). Derived from
393
419
  * the same schedule the render uses, so a dwell-delayed pull-out (which
394
420
  * departs after the stored inAtMs and can land after its own tMs) is
395
- * reflected instead of approximated from inAtMs. */
421
+ * reflected instead of approximated from inAtMs. `pullOut` says which pace
422
+ * knob the window belongs to (zoomOutMs vs zoomInMs) — the same test the
423
+ * schedule itself makes, so a reader can't drift from it. */
396
424
  export function cameraRampSchedule(
397
425
  comp: TakeComposition,
398
- ): ({ startMs: number; landMs: number } | null)[] {
399
- const { anchors, ramps, landTs } = buildCameraSchedule(comp);
400
- const out: ({ startMs: number; landMs: number } | null)[] = comp.events.map(() => null);
426
+ ): ({ startMs: number; landMs: number; pullOut: boolean } | null)[] {
427
+ const { anchors, targets, restR, ramps, landTs } = buildCameraSchedule(comp);
428
+ const out: ({ startMs: number; landMs: number; pullOut: boolean } | null)[] = comp.events.map(
429
+ () => null,
430
+ );
401
431
  anchors.forEach((a, i) => {
402
- out[a.evIdx] = { startMs: ramps[i]!.start * 1000, landMs: landTs[i]! * 1000 };
432
+ const from = i > 0 ? targets[i - 1]! : restR;
433
+ out[a.evIdx] = {
434
+ startMs: ramps[i]!.start * 1000,
435
+ landMs: landTs[i]! * 1000,
436
+ pullOut: targets[i]!.w > from.w + 1e-6,
437
+ };
403
438
  });
404
439
  return out;
405
440
  }
@@ -563,39 +598,165 @@ type Leg = {
563
598
  drag?: boolean;
564
599
  path?: Pt[];
565
600
  ease?: "linear" | "smooth";
601
+ /** Diagnostics only (never read by the render): which travel clamp, if
602
+ * either, set this leg's duration instead of the speed law. The clamps run
603
+ * AFTER the speed model, so a clamped leg is one where `travelWidthsPerSec`
604
+ * — and therefore the whole `pace` preset — has no say. validate.ts reports
605
+ * it when it stops being the exception and becomes the rule. */
606
+ clamped?: "min" | "max";
607
+ /** Diagnostics only: the duration (s) the clamped speed law asked for. When
608
+ * the delivered `t1 - t0` is shorter, the previous beat's action ran too
609
+ * late to leave room and the move is being rushed — a CAPTURE-side gap no
610
+ * cursor knob can fix. `evIdx` is the event this leg travels to. */
611
+ wantSec?: number;
612
+ evIdx?: number;
566
613
  };
567
614
 
615
+ /** Cumulative ∫ (rest / cameraScale) dt over the take, on a uniform grid.
616
+ *
617
+ * The integrand is how much of the DELIVERED frame one video-px of movement
618
+ * buys, normalised so a camera at rest integrates to 1 — so this converts a
619
+ * video-px path into the distance the VIEWER actually sees it cross, and
620
+ * INVERTING it answers "when must this move depart to hold a constant
621
+ * on-screen speed". Strictly increasing (the integrand is > 0), so the
622
+ * inverse is single-valued and a binary search finds it. Outside the sampled
623
+ * window the end value extrapolates linearly at the end slope.
624
+ *
625
+ * This is a function of the camera schedule alone (which reads comp.events /
626
+ * comp.cursor, never the legs), so pricing a leg with it introduces no cycle. */
627
+ function zoomFracTrack(cam: { T: number; rest: number; at: (t: number) => { scale: number } }) {
628
+ const STEP = 0.005; // 5ms — ~150× finer than the shortest shipped camera ramp
629
+ const n = Math.max(2, Math.min(20000, Math.ceil(cam.T / STEP) + 1));
630
+ const step = cam.T > 0 ? cam.T / (n - 1) : STEP;
631
+ const zf = (t: number) => cam.rest / Math.max(cam.at(t).scale, 1e-6);
632
+ const cum = new Float64Array(n);
633
+ const zf0 = zf(0);
634
+ let prev = zf0;
635
+ for (let i = 1; i < n; i++) {
636
+ const v = zf(i * step);
637
+ cum[i] = cum[i - 1]! + ((prev + v) / 2) * step; // trapezoid
638
+ prev = v;
639
+ }
640
+ const zfT = prev;
641
+ const tEnd = (n - 1) * step;
642
+ const last = cum[n - 1]!;
643
+ return {
644
+ at(t: number): number {
645
+ if (t <= 0) return t * zf0;
646
+ if (t >= tEnd) return last + (t - tEnd) * zfT;
647
+ const i = Math.floor(t / step);
648
+ const f = t / step - i;
649
+ return cum[i]! + (cum[i + 1]! - cum[i]!) * f;
650
+ },
651
+ /** the t at which the cumulative integral equals `y` */
652
+ invert(y: number): number {
653
+ if (y <= 0) return zf0 > 0 ? y / zf0 : 0;
654
+ if (y >= last) return tEnd + (zfT > 0 ? (y - last) / zfT : 0);
655
+ let lo = 0;
656
+ let hi = n - 1;
657
+ while (hi - lo > 1) {
658
+ const mid = (lo + hi) >> 1;
659
+ if (cum[mid]! <= y) lo = mid;
660
+ else hi = mid;
661
+ }
662
+ const span = cum[hi]! - cum[lo]!;
663
+ return (lo + (span > 0 ? (y - cum[lo]!) / span : 0)) * step;
664
+ },
665
+ };
666
+ }
667
+
568
668
  export function buildLegs(comp: TakeComposition): Leg[] {
569
669
  const legs: Leg[] = [];
570
670
  let cur: Pt = comp.start;
671
+ // When the previous beat's ACTION finishes (tMs + durationMs) — not when its
672
+ // travel leg landed. See the prevEnd comment below.
673
+ let freeAt = 0;
571
674
  // Distance-aware travel: hold a roughly constant on-screen speed (premium
572
675
  // feel) instead of a fixed duration (which makes short moves slow + long
573
676
  // moves fast). Falls back to the fixed travelMs when speed is unset/0.
574
677
  const { travelWidthsPerSec, travelMinMs, travelMaxMs, travelMs } = comp.cursor;
575
- const speedPxPerMs = ((travelWidthsPerSec || 0) * comp.source.videoWidth) / 1000;
576
- const travelDur = (a: Pt, b: Pt): number => {
577
- if (speedPxPerMs <= 0) return travelMs / 1000;
678
+ // ON-SCREEN means the DELIVERED frame, not the raw recording. While the
679
+ // camera is zoomed in, a video-px move covers proportionally more of the
680
+ // frame — so a zoom-blind duration makes every zoomed move read that many
681
+ // times too fast, precisely where the viewer is looking closest (a 2x punch
682
+ // -in doubles the apparent speed).
683
+ // The magnification is not constant ACROSS a leg, though: a travel typically
684
+ // departs while the camera is still wide and lands after it has closed in, so
685
+ // pricing the whole leg at the ARRIVAL magnification (the most punched-in
686
+ // instant it ever sees) over-slows the departure by as much as it was
687
+ // previously over-fast. Solve the honest thing instead — depart at the
688
+ // instant from which the INTEGRATED on-screen distance to the target equals
689
+ // one leg's worth of travel at the reference speed — which is exactly what
690
+ // inverting the zoomFrac track does. A camera that never leaves rest
691
+ // integrates to the identity, so a full-view take keeps its measured-by-eye
692
+ // calibration bit-for-bit (short-circuited below to keep that exact).
693
+ // Built lazily: only a composition that actually travels needs the camera,
694
+ // and a zoom-less take must not pay for the track.
695
+ let cam: ReturnType<typeof stageCamera> | undefined;
696
+ let track: ReturnType<typeof zoomFracTrack> | undefined;
697
+ const travelDur = (a: Pt, b: Pt, arriveSec: number): { sec: number; clamped?: "min" | "max" } => {
698
+ if (!travelWidthsPerSec) return { sec: travelMs / 1000 };
699
+ const speedPxPerSec = travelWidthsPerSec * comp.source.videoWidth;
700
+ if (speedPxPerSec <= 0) return { sec: travelMs / 1000 };
578
701
  const dist = Math.hypot(b.x - a.x, b.y - a.y);
579
- return Math.min(travelMaxMs, Math.max(travelMinMs, dist / speedPxPerMs)) / 1000;
702
+ cam ??= stageCamera(comp);
703
+ let ms: number;
704
+ if (cam.peakScale <= cam.rest + 1e-9) {
705
+ ms = (dist / speedPxPerSec) * 1000; // camera never leaves rest — closed form
706
+ } else {
707
+ track ??= zoomFracTrack(cam);
708
+ ms = (arriveSec - track.invert(track.at(arriveSec) - dist / speedPxPerSec)) * 1000;
709
+ }
710
+ if (ms < travelMinMs) return { sec: travelMinMs / 1000, clamped: "min" };
711
+ if (ms > travelMaxMs) return { sec: travelMaxMs / 1000, clamped: "max" };
712
+ return { sec: ms / 1000 };
580
713
  };
581
- for (const e of comp.events) {
714
+ for (const [evIdx, e] of comp.events.entries()) {
582
715
  // scroll/press are not pointer-driven — the cursor holds where it was
583
716
  // (the content pans / the keyboard acts). No travel leg; `cur` is untouched,
584
717
  // so the between-legs parking logic keeps the cursor at its last anchor.
585
- if (e.kind === "scroll" || e.kind === "press") continue;
718
+ // They still OCCUPY the frame for durationMs, though: a scroll's duration IS
719
+ // the pan, and a press's is the reveal animating in. A travel that departs
720
+ // into either puts two motions on screen at once — content sliding under a
721
+ // cursor crossing it — so they push `freeAt` exactly like a pointer beat
722
+ // even though they contribute no leg.
723
+ if (e.kind === "scroll" || e.kind === "press") {
724
+ freeAt = Math.max(freeAt, (e.tMs + (e.durationMs ?? 0)) / 1000);
725
+ continue;
726
+ }
586
727
  const arrive = e.tMs / 1000;
587
728
  // Start travelDur before arrival, but never before the previous leg ended
588
729
  // (a long glide into a quick succession would otherwise overlap it — then
589
- // the move just runs in the available window, a touch faster than target).
590
- const prevEnd = legs.length ? legs[legs.length - 1]!.t1 : 0;
591
- const t0 = Math.max(arrive - travelDur(cur, e.point), prevEnd, 0);
592
- legs.push({ t0, t1: arrive, a: cur, b: e.point }); // travel to anchor
730
+ // the move just runs in the available window, a touch faster than target)
731
+ // and never before the previous beat's ACTION finished. A travel leg ends
732
+ // at its tMs, but a `type` keeps emitting keystrokes for durationMs after
733
+ // that — so the leg end alone would let a long enough glide drag the
734
+ // pointer off the field mid-word.
735
+ // …and never AFTER the arrival: overlapping action windows (only reachable
736
+ // by hand — a capture always leaves a settle gap) would otherwise build an
737
+ // INVERTED leg, which matches no instant at all in cursorPos, so the cursor
738
+ // would silently jump-cut instead of degrading to a hard landing.
739
+ const prevEnd = Math.max(legs.length ? legs[legs.length - 1]!.t1 : 0, freeAt);
740
+ const d = travelDur(cur, e.point, arrive);
741
+ const t0 = Math.min(arrive, Math.max(arrive - d.sec, prevEnd, 0));
742
+ legs.push({
743
+ t0,
744
+ t1: arrive,
745
+ a: cur,
746
+ b: e.point,
747
+ evIdx,
748
+ wantSec: d.sec,
749
+ ...(d.clamped ? { clamped: d.clamped } : {}),
750
+ });
593
751
  cur = e.point;
594
- if (e.kind === "drag" && e.to) {
752
+ freeAt = Math.max(freeAt, (e.tMs + (e.durationMs ?? 0)) / 1000);
753
+ if ((e.kind === "drag" || e.kind === "dropFiles") && e.to) {
595
754
  // Delay the stroke by dragLagMs so the cursor rides the captured ink front
596
755
  // (the ink trails the pen by the capture-pipeline latency). The cursor
597
756
  // holds at the start point during the gap [arrive, arrive+lag], then traces
598
- // — matching when the ink actually appears on screen.
757
+ // — matching when the ink actually appears on screen. A dropFiles carry
758
+ // has no ink, but the page's dragover reaction rode the same capture
759
+ // pipeline, so the same lag keeps cursor and reaction in step.
599
760
  const lag = comp.cursor.dragLagMs / 1000;
600
761
  const start = arrive + lag;
601
762
  const dEnd = (e.tMs + (e.durationMs ?? 0)) / 1000 + lag;
@@ -636,7 +797,11 @@ function alongPath(path: Pt[], u: number): Pt {
636
797
  export function cursorPos(t: number, legs: Leg[], comp: TakeComposition): Pt {
637
798
  for (const lg of legs) {
638
799
  if (lg.t0 <= t && t <= lg.t1) {
639
- const raw = Math.max(0, Math.min(1, (t - lg.t0) / (lg.t1 - lg.t0)));
800
+ // A ZERO-span leg (a departure clamped all the way to its own arrival —
801
+ // see buildLegs) has landed by definition; without the guard the 0/0
802
+ // would put NaN through the ease and blank the cursor for that frame.
803
+ const span = lg.t1 - lg.t0;
804
+ const raw = span > 0 ? Math.max(0, Math.min(1, (t - lg.t0) / span)) : 1;
640
805
  // A drag replays the captured stroke's pacing so the cursor stays locked
641
806
  // to the ink: "smooth" (accel-in / decel-out — a natural hand-draw) or
642
807
  // "linear" (constant speed). The capture bakes the SAME curve into the ink
@@ -665,3 +830,42 @@ export function cursorPos(t: number, legs: Leg[], comp: TakeComposition): Pt {
665
830
  export function isDragging(t: number, legs: Leg[]): boolean {
666
831
  return legs.some((lg) => lg.drag === true && lg.t0 <= t && t <= lg.t1);
667
832
  }
833
+
834
+ // --- file ghost card (dropFiles) ----------------------------------------
835
+
836
+ /** A dropFiles carry's on-screen window [start, end] in SECONDS — when the
837
+ * ghost card rides the cursor. Same dragLagMs shift as the carry leg in
838
+ * buildLegs, so card and cursor cannot drift apart. Shared by the Revideo
839
+ * scene and the editor preview (the no-drift invariant). */
840
+ export function carryWindow(
841
+ e: { tMs: number; durationMs?: number },
842
+ comp: TakeComposition,
843
+ ): { t0: number; t1: number } {
844
+ const lag = comp.cursor.dragLagMs / 1000;
845
+ const t0 = e.tMs / 1000 + lag;
846
+ return { t0, t1: t0 + (e.durationMs ?? 0) / 1000 };
847
+ }
848
+
849
+ /** "1.2 MB" / "412 KB" — the ghost card's size caption (scene + preview). */
850
+ export function fmtBytes(n: number): string {
851
+ return n >= 1024 * 1024
852
+ ? `${(n / 1024 / 1024).toFixed(1)} MB`
853
+ : `${Math.max(1, Math.round(n / 1024))} KB`;
854
+ }
855
+
856
+ /** The ghost card's two text lines for a dropFiles beat: the (first) filename,
857
+ * and a meta caption ("3 files · 1.8 MB" / "1.2 MB"). Shared scene/preview.
858
+ * Long filenames middle-ellipse (extension kept) so the card can't outgrow
859
+ * the frame — neither render surface clamps its width. */
860
+ export function ghostCardLines(files: { name: string; size?: number }[]): {
861
+ title: string;
862
+ meta: string;
863
+ } {
864
+ const raw = files[0]?.name ?? "file";
865
+ const MAX = 34;
866
+ const title = raw.length <= MAX ? raw : `${raw.slice(0, MAX - 12)}…${raw.slice(raw.length - 11)}`;
867
+ const total = files.reduce((s, f) => s + (f.size ?? 0), 0);
868
+ const size = total > 0 ? fmtBytes(total) : "";
869
+ const count = files.length > 1 ? `${files.length} files` : "";
870
+ return { title, meta: [count, size].filter(Boolean).join(" · ") };
871
+ }
package/src/plan.ts CHANGED
@@ -86,17 +86,17 @@ export function planComposition(log: CaptureLog, opts: PlanOpts = {}): TakeCompo
86
86
  const intent = c.zoom ?? "auto";
87
87
  const durationMs = "durationMs" in c ? c.durationMs : 0;
88
88
 
89
- // drag: cursor path + the region we frame is the path's bbox
90
- const to = kind === "drag" ? mapPt((c as { to: Pt }).to) : undefined;
91
- const rawPath =
92
- kind === "drag"
93
- ? ((c as { path?: Pt[] }).path ?? [{ x: c.x, y: c.y }, (c as { to: Pt }).to])
94
- : undefined;
89
+ // drag / dropFiles: cursor path + the region we frame is the path's bbox
90
+ const carries = kind === "drag" || kind === "dropFiles";
91
+ const to = carries ? mapPt((c as { to: Pt }).to) : undefined;
92
+ const rawPath = carries
93
+ ? ((c as { path?: Pt[] }).path ?? [{ x: c.x, y: c.y }, (c as { to: Pt }).to])
94
+ : undefined;
95
95
  const path = rawPath?.map(mapPt);
96
- const ease = kind === "drag" ? (c as { ease?: "linear" | "smooth" }).ease : undefined;
96
+ const ease = carries ? (c as { ease?: "linear" | "smooth" }).ease : undefined;
97
97
 
98
- // the element bbox (ground truth): drag → path bbox, else the captured box
99
- const bbox = kind === "drag" && path ? pathBBox(path) : c.box ? mapBox(c.box) : undefined;
98
+ // the element bbox (ground truth): a carry → path bbox, else the captured box
99
+ const bbox = carries && path ? pathBBox(path) : c.box ? mapBox(c.box) : undefined;
100
100
  const effectBox = c.effectBox ? mapBox(c.effectBox) : undefined;
101
101
  const label = c.sel ?? c.note;
102
102
 
@@ -125,6 +125,9 @@ export function planComposition(log: CaptureLog, opts: PlanOpts = {}): TakeCompo
125
125
  ...(to ? { to } : {}),
126
126
  ...(path ? { path } : {}),
127
127
  ...(ease ? { ease } : {}),
128
+ ...(kind === "dropFiles"
129
+ ? { files: (c as { files: { name: string; size?: number }[] }).files }
130
+ : {}),
128
131
  };
129
132
  return { beat, ev };
130
133
  });
@@ -151,7 +154,16 @@ export function planComposition(log: CaptureLog, opts: PlanOpts = {}): TakeCompo
151
154
  center: f.center,
152
155
  // zoom-in ramp starts zoomInMs before the action (decoupled from cursor
153
156
  // travelMs so the zoom can be slower/gentler — a more cinematic feel).
154
- inAtMs: Math.max(0, s.beat.tMs - cursor.zoomInMs),
157
+ // EXCEPT a zoom-enabled press: its payoff (palette / modal / result)
158
+ // exists only AFTER the keypress, and a keypress has no on-screen
159
+ // antecedent to anticipate — a lead-in punches into empty space and the
160
+ // reveal then pops inside an already-committed frame. The camera departs
161
+ // AT the action and rides the reveal in (buildCameraSchedule gives a
162
+ // late-departing ramp its full window after the departure).
163
+ inAtMs:
164
+ f.enabled && s.beat.kind === "press"
165
+ ? s.beat.tMs
166
+ : Math.max(0, s.beat.tMs - cursor.zoomInMs),
155
167
  reason: f.reason,
156
168
  };
157
169
  return { ...s.ev, zoom };
package/src/presets.ts CHANGED
@@ -40,7 +40,13 @@ 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" | "pullOutDwellMs"
43
+ | "travelWidthsPerSec"
44
+ | "travelMinMs"
45
+ | "travelMaxMs"
46
+ | "holdMs"
47
+ | "zoomInMs"
48
+ | "zoomOutMs"
49
+ | "pullOutDwellMs"
44
50
  > & { zoomEase?: undefined };
45
51
  // zoomIn/zoomOut anchored to the measured reference springs (730/1340 —
46
52
  // see DEFAULT_CURSOR); calm/brisk scale both while keeping out ≈ 1.8× in.
@@ -50,9 +56,19 @@ export type MotionPreset = Pick<
50
56
  // leaves the key undefined; JSON drops it) so applying a pace migrates an old
51
57
  // composition onto the default measured-SS spring curve instead of silently
52
58
  // keeping the old bezier.
59
+ //
60
+ // The TRAVEL CLAMPS ride along too, and they have to. They are applied AFTER
61
+ // travelWidthsPerSec, so a preset that moved only the speed left every clamped
62
+ // leg exactly where it was: below ~202px and above ~571px of a 1920 frame,
63
+ // "calm" and "brisk" rendered IDENTICALLY and nothing said so. Each clamp
64
+ // scales by the pace's own speed ratio against natural (300·0.35/0.28 = 375,
65
+ // 850·0.35/0.45 = 661…), so a leg on a clamp keeps the same relationship to
66
+ // the legs that aren't.
53
67
  export const MOTION: Record<"calm" | "natural" | "brisk", MotionPreset> = {
54
68
  calm: {
55
69
  travelWidthsPerSec: 0.28,
70
+ travelMinMs: 375,
71
+ travelMaxMs: 1060,
56
72
  holdMs: 1500,
57
73
  zoomInMs: 900,
58
74
  zoomOutMs: 1650,
@@ -61,6 +77,8 @@ export const MOTION: Record<"calm" | "natural" | "brisk", MotionPreset> = {
61
77
  },
62
78
  natural: {
63
79
  travelWidthsPerSec: 0.35,
80
+ travelMinMs: 300,
81
+ travelMaxMs: 850,
64
82
  holdMs: 1100,
65
83
  zoomInMs: 730,
66
84
  zoomOutMs: 1340,
@@ -69,6 +87,8 @@ export const MOTION: Record<"calm" | "natural" | "brisk", MotionPreset> = {
69
87
  },
70
88
  brisk: {
71
89
  travelWidthsPerSec: 0.45,
90
+ travelMinMs: 235,
91
+ travelMaxMs: 660,
72
92
  holdMs: 750,
73
93
  zoomInMs: 550,
74
94
  zoomOutMs: 1000,
@@ -78,6 +98,15 @@ export const MOTION: Record<"calm" | "natural" | "brisk", MotionPreset> = {
78
98
  };
79
99
  export type MotionName = keyof typeof MOTION;
80
100
 
101
+ /** A clamp matches its preset — or the LEGACY value every composition carried
102
+ * before the clamps joined the presets. Without that second door, applying
103
+ * "brisk" to an old take and re-reading it would report "custom" purely
104
+ * because the take predates clamp-aware presets. Same escape hatch
105
+ * pullOutDwellMs already has. */
106
+ export const CLAMP_TOL_MS = 20;
107
+ const clampMatches = (v: number | undefined, want: number, legacy: number): boolean =>
108
+ v == null || Math.abs(v - want) < CLAMP_TOL_MS || Math.abs(v - legacy) < 1;
109
+
81
110
  export function motionName(cursor: CursorConfig): MotionName | null {
82
111
  for (const [name, m] of Object.entries(MOTION) as [MotionName, MotionPreset][]) {
83
112
  if (
@@ -85,6 +114,8 @@ export function motionName(cursor: CursorConfig): MotionName | null {
85
114
  Math.abs(cursor.holdMs - m.holdMs) < 60 &&
86
115
  Math.abs(cursor.zoomInMs - m.zoomInMs) < 60 &&
87
116
  Math.abs(cursor.zoomOutMs - m.zoomOutMs) < 60 &&
117
+ clampMatches(cursor.travelMinMs, m.travelMinMs, MOTION.natural.travelMinMs) &&
118
+ clampMatches(cursor.travelMaxMs, m.travelMaxMs, MOTION.natural.travelMaxMs) &&
88
119
  // absent = a pre-dwell composition — still nameable by its four legacy
89
120
  // knobs; only an explicit different value makes the pace "custom".
90
121
  (cursor.pullOutDwellMs == null ||
package/src/render.ts CHANGED
@@ -78,6 +78,16 @@ export type RenderTakeOpts = {
78
78
  writeCompositionSibling?: boolean;
79
79
  };
80
80
 
81
+ export type RenderTakeResult = {
82
+ mp4Path: string;
83
+ compositionPath: string;
84
+ /** non-fatal validator findings for this composition. The render went ahead,
85
+ * but each one is something the author has to look at — a zoom that punches
86
+ * into empty space, a press whose zoom departs before the keypress, a tail
87
+ * that delivers a frozen screen. Empty when `skipValidate` is set. */
88
+ warnings: CompositionIssue[];
89
+ };
90
+
81
91
  function run(cmd: string, args: string[]): Promise<void> {
82
92
  return new Promise((res, rej) => {
83
93
  const c = spawn(cmd, args, { stdio: ["ignore", "ignore", "pipe"] });
@@ -240,9 +250,7 @@ async function prepareScratch(composition: TakeComposition, videoPath: string):
240
250
  // needs the renderer off cwd, or one child process per render.)
241
251
  let renderQueue: Promise<unknown> = Promise.resolve();
242
252
 
243
- export async function renderTake(
244
- opts: RenderTakeOpts,
245
- ): Promise<{ mp4Path: string; compositionPath: string }> {
253
+ export async function renderTake(opts: RenderTakeOpts): Promise<RenderTakeResult> {
246
254
  const run = renderQueue.then(
247
255
  () => renderTakeExclusive(opts),
248
256
  () => renderTakeExclusive(opts),
@@ -251,9 +259,7 @@ export async function renderTake(
251
259
  return run;
252
260
  }
253
261
 
254
- async function renderTakeExclusive(
255
- opts: RenderTakeOpts,
256
- ): Promise<{ mp4Path: string; compositionPath: string }> {
262
+ async function renderTakeExclusive(opts: RenderTakeOpts): Promise<RenderTakeResult> {
257
263
  if (!opts.chromePath) {
258
264
  throw new Error(
259
265
  "renderTake: `chromePath` is required; use @open-take/runtime to resolve managed Chrome automatically",
@@ -272,14 +278,19 @@ async function renderTakeExclusive(
272
278
  // 0. validate BEFORE the expensive render. A hand-edited composition (the
273
279
  // refine loop) can carry a malformed zoom or a capture-locked tMs drift;
274
280
  // catch it in milliseconds rather than after a multi-second render.
281
+ // Warnings are RETURNED as well as printed: this stderr line lands minutes
282
+ // before the render finishes, so on its own it is scrolled past — the
283
+ // caller re-prints them in the end-of-run summary, exactly as it already
284
+ // does for skipped capture steps.
285
+ const warnings: CompositionIssue[] = [];
275
286
  if (!opts.skipValidate) {
276
287
  const issues: CompositionIssue[] = validateComposition(composition, {
277
288
  captureLog: opts.captureLog ?? opts.log,
278
289
  });
279
290
  const errors = issues.filter((i) => i.severity === "error");
280
- const warns = issues.filter((i) => i.severity === "warn");
281
- if (opts.logProgress && warns.length)
282
- process.stderr.write(`composition warnings:\n${formatIssues(warns)}\n`);
291
+ warnings.push(...issues.filter((i) => i.severity === "warn"));
292
+ if (opts.logProgress && warnings.length)
293
+ process.stderr.write(`composition warnings:\n${formatIssues(warnings)}\n`);
283
294
  if (errors.length)
284
295
  throw new Error(
285
296
  `composition has ${errors.length} error(s) — refusing to render:\n${formatIssues(errors)}`,
@@ -375,7 +386,7 @@ async function renderTakeExclusive(
375
386
  await writeFile(compositionPath, JSON.stringify(persisted, null, 2));
376
387
  }
377
388
 
378
- return { mp4Path: resolve(opts.outPath), compositionPath };
389
+ return { mp4Path: resolve(opts.outPath), compositionPath, warnings };
379
390
  } finally {
380
391
  await cleanupScratch(scratch);
381
392
  }