@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/dist/index.js CHANGED
@@ -91,6 +91,8 @@ function zoomLevelName(scale, tol = .07) {
91
91
  const MOTION = {
92
92
  calm: {
93
93
  travelWidthsPerSec: .28,
94
+ travelMinMs: 375,
95
+ travelMaxMs: 1060,
94
96
  holdMs: 1500,
95
97
  zoomInMs: 900,
96
98
  zoomOutMs: 1650,
@@ -99,6 +101,8 @@ const MOTION = {
99
101
  },
100
102
  natural: {
101
103
  travelWidthsPerSec: .35,
104
+ travelMinMs: 300,
105
+ travelMaxMs: 850,
102
106
  holdMs: 1100,
103
107
  zoomInMs: 730,
104
108
  zoomOutMs: 1340,
@@ -107,6 +111,8 @@ const MOTION = {
107
111
  },
108
112
  brisk: {
109
113
  travelWidthsPerSec: .45,
114
+ travelMinMs: 235,
115
+ travelMaxMs: 660,
110
116
  holdMs: 750,
111
117
  zoomInMs: 550,
112
118
  zoomOutMs: 1e3,
@@ -114,8 +120,15 @@ const MOTION = {
114
120
  zoomEase: void 0
115
121
  }
116
122
  };
123
+ /** A clamp matches its preset — or the LEGACY value every composition carried
124
+ * before the clamps joined the presets. Without that second door, applying
125
+ * "brisk" to an old take and re-reading it would report "custom" purely
126
+ * because the take predates clamp-aware presets. Same escape hatch
127
+ * pullOutDwellMs already has. */
128
+ const CLAMP_TOL_MS = 20;
129
+ const clampMatches = (v, want, legacy) => v == null || Math.abs(v - want) < CLAMP_TOL_MS || Math.abs(v - legacy) < 1;
117
130
  function motionName(cursor) {
118
- for (const [name, m] of Object.entries(MOTION)) if (Math.abs(cursor.travelWidthsPerSec - m.travelWidthsPerSec) < .015 && Math.abs(cursor.holdMs - m.holdMs) < 60 && Math.abs(cursor.zoomInMs - m.zoomInMs) < 60 && Math.abs(cursor.zoomOutMs - m.zoomOutMs) < 60 && (cursor.pullOutDwellMs == null || Math.abs(cursor.pullOutDwellMs - (m.pullOutDwellMs ?? 0)) < 60)) return name;
131
+ for (const [name, m] of Object.entries(MOTION)) if (Math.abs(cursor.travelWidthsPerSec - m.travelWidthsPerSec) < .015 && Math.abs(cursor.holdMs - m.holdMs) < 60 && Math.abs(cursor.zoomInMs - m.zoomInMs) < 60 && Math.abs(cursor.zoomOutMs - m.zoomOutMs) < 60 && clampMatches(cursor.travelMinMs, m.travelMinMs, MOTION.natural.travelMinMs) && clampMatches(cursor.travelMaxMs, m.travelMaxMs, MOTION.natural.travelMaxMs) && (cursor.pullOutDwellMs == null || Math.abs(cursor.pullOutDwellMs - (m.pullOutDwellMs ?? 0)) < 60)) return name;
119
132
  return null;
120
133
  }
121
134
  const DARK_SHADOW = {
@@ -293,9 +306,12 @@ __export(math_exports, {
293
306
  buildLegs: () => buildLegs,
294
307
  buildStageKeyframes: () => buildStageKeyframes,
295
308
  cameraRampSchedule: () => cameraRampSchedule,
309
+ carryWindow: () => carryWindow,
296
310
  clampCenter: () => clampCenter,
297
311
  cubicBezier: () => cubicBezier,
298
312
  cursorPos: () => cursorPos,
313
+ fmtBytes: () => fmtBytes,
314
+ ghostCardLines: () => ghostCardLines,
299
315
  gradientEndpoints: () => gradientEndpoints,
300
316
  isDragging: () => isDragging,
301
317
  keyvalN: () => keyvalN,
@@ -488,9 +504,14 @@ function buildCameraSchedule(comp) {
488
504
  const targets = anchors.map((e) => rectFor(e.center, e.scale));
489
505
  const ZIN_MS = comp.cursor.zoomInMs;
490
506
  const DWELL_MS = comp.cursor.pullOutDwellMs ?? 0;
507
+ const revealTimed = (e) => e.inAtMs >= e.tMs;
491
508
  const ramps = anchors.map((e, i) => {
492
509
  const from = i > 0 ? targets[i - 1] : restR;
493
510
  const pullOut = targets[i].w > from.w + 1e-6;
511
+ if (revealTimed(e)) return {
512
+ start: e.inAtMs / 1e3,
513
+ end: (e.inAtMs + (pullOut ? ZOUT_MS : ZIN_MS)) / 1e3
514
+ };
494
515
  const isDefaultInAt = Math.abs(e.inAtMs - Math.max(0, e.tMs - ZIN_MS)) < 1;
495
516
  if (!pullOut || !isDefaultInAt) return {
496
517
  start: e.inAtMs / 1e3,
@@ -518,6 +539,7 @@ function buildCameraSchedule(comp) {
518
539
  for (let i = 0; i < ramps.length - 1; i++) {
519
540
  const r = ramps[i];
520
541
  const e = anchors[i];
542
+ if (revealTimed(e)) continue;
521
543
  if (r.end <= e.tMs / 1e3 + 1e-9) continue;
522
544
  const latestStart = ramps[i + 1].start - .01 - minRamp / 1e3;
523
545
  if (r.start <= latestStart) continue;
@@ -532,9 +554,17 @@ function buildCameraSchedule(comp) {
532
554
  }
533
555
  }
534
556
  }
557
+ const REVEAL_MIN_S = Math.min(ZOUT_MS, ZIN_MS) / 2e3;
558
+ for (let i = 0; i < ramps.length; i++) {
559
+ if (!revealTimed(anchors[i])) continue;
560
+ const r = ramps[i];
561
+ const nextStart = i + 1 < ramps.length ? ramps[i + 1].start : Number.POSITIVE_INFINITY;
562
+ r.end = Math.max(r.start + REVEAL_MIN_S, Math.min(r.end, nextStart - .01));
563
+ }
535
564
  const landTs = anchors.map((e, i) => {
536
565
  const nextStart = anchors[i + 1] ? ramps[i + 1].start : Number.POSITIVE_INFINITY;
537
566
  const rampEnd = ramps[i].end;
567
+ if (revealTimed(e)) return rampEnd;
538
568
  return rampEnd === e.tMs / 1e3 ? rampEnd : Math.max(ramps[i].start + Math.min(ZOUT_MS, ZIN_MS) / 1e3, Math.min(rampEnd, nextStart - .01));
539
569
  });
540
570
  return {
@@ -551,14 +581,18 @@ function buildCameraSchedule(comp) {
551
581
  * lands. `null` for a beat the camera holds through (no anchor). Derived from
552
582
  * the same schedule the render uses, so a dwell-delayed pull-out (which
553
583
  * departs after the stored inAtMs and can land after its own tMs) is
554
- * reflected instead of approximated from inAtMs. */
584
+ * reflected instead of approximated from inAtMs. `pullOut` says which pace
585
+ * knob the window belongs to (zoomOutMs vs zoomInMs) — the same test the
586
+ * schedule itself makes, so a reader can't drift from it. */
555
587
  function cameraRampSchedule(comp) {
556
- const { anchors, ramps, landTs } = buildCameraSchedule(comp);
588
+ const { anchors, targets, restR, ramps, landTs } = buildCameraSchedule(comp);
557
589
  const out = comp.events.map(() => null);
558
590
  anchors.forEach((a, i) => {
591
+ const from = i > 0 ? targets[i - 1] : restR;
559
592
  out[a.evIdx] = {
560
593
  startMs: ramps[i].start * 1e3,
561
- landMs: landTs[i] * 1e3
594
+ landMs: landTs[i] * 1e3,
595
+ pullOut: targets[i].w > from.w + 1e-6
562
596
  };
563
597
  });
564
598
  return out;
@@ -698,29 +732,107 @@ function stageCamera(comp) {
698
732
  at
699
733
  };
700
734
  }
735
+ /** Cumulative ∫ (rest / cameraScale) dt over the take, on a uniform grid.
736
+ *
737
+ * The integrand is how much of the DELIVERED frame one video-px of movement
738
+ * buys, normalised so a camera at rest integrates to 1 — so this converts a
739
+ * video-px path into the distance the VIEWER actually sees it cross, and
740
+ * INVERTING it answers "when must this move depart to hold a constant
741
+ * on-screen speed". Strictly increasing (the integrand is > 0), so the
742
+ * inverse is single-valued and a binary search finds it. Outside the sampled
743
+ * window the end value extrapolates linearly at the end slope.
744
+ *
745
+ * This is a function of the camera schedule alone (which reads comp.events /
746
+ * comp.cursor, never the legs), so pricing a leg with it introduces no cycle. */
747
+ function zoomFracTrack(cam) {
748
+ const STEP = .005;
749
+ const n = Math.max(2, Math.min(2e4, Math.ceil(cam.T / STEP) + 1));
750
+ const step = cam.T > 0 ? cam.T / (n - 1) : STEP;
751
+ const zf = (t) => cam.rest / Math.max(cam.at(t).scale, 1e-6);
752
+ const cum = new Float64Array(n);
753
+ const zf0 = zf(0);
754
+ let prev = zf0;
755
+ for (let i = 1; i < n; i++) {
756
+ const v = zf(i * step);
757
+ cum[i] = cum[i - 1] + (prev + v) / 2 * step;
758
+ prev = v;
759
+ }
760
+ const zfT = prev;
761
+ const tEnd = (n - 1) * step;
762
+ const last = cum[n - 1];
763
+ return {
764
+ at(t) {
765
+ if (t <= 0) return t * zf0;
766
+ if (t >= tEnd) return last + (t - tEnd) * zfT;
767
+ const i = Math.floor(t / step);
768
+ const f = t / step - i;
769
+ return cum[i] + (cum[i + 1] - cum[i]) * f;
770
+ },
771
+ invert(y) {
772
+ if (y <= 0) return zf0 > 0 ? y / zf0 : 0;
773
+ if (y >= last) return tEnd + (zfT > 0 ? (y - last) / zfT : 0);
774
+ let lo = 0;
775
+ let hi = n - 1;
776
+ while (hi - lo > 1) {
777
+ const mid = lo + hi >> 1;
778
+ if (cum[mid] <= y) lo = mid;
779
+ else hi = mid;
780
+ }
781
+ const span = cum[hi] - cum[lo];
782
+ return (lo + (span > 0 ? (y - cum[lo]) / span : 0)) * step;
783
+ }
784
+ };
785
+ }
701
786
  function buildLegs(comp) {
702
787
  const legs = [];
703
788
  let cur = comp.start;
789
+ let freeAt = 0;
704
790
  const { travelWidthsPerSec, travelMinMs, travelMaxMs, travelMs } = comp.cursor;
705
- const speedPxPerMs = (travelWidthsPerSec || 0) * comp.source.videoWidth / 1e3;
706
- const travelDur = (a, b) => {
707
- if (speedPxPerMs <= 0) return travelMs / 1e3;
791
+ let cam;
792
+ let track;
793
+ const travelDur = (a, b, arriveSec) => {
794
+ if (!travelWidthsPerSec) return { sec: travelMs / 1e3 };
795
+ const speedPxPerSec = travelWidthsPerSec * comp.source.videoWidth;
796
+ if (speedPxPerSec <= 0) return { sec: travelMs / 1e3 };
708
797
  const dist$1 = Math.hypot(b.x - a.x, b.y - a.y);
709
- return Math.min(travelMaxMs, Math.max(travelMinMs, dist$1 / speedPxPerMs)) / 1e3;
798
+ cam ??= stageCamera(comp);
799
+ let ms;
800
+ if (cam.peakScale <= cam.rest + 1e-9) ms = dist$1 / speedPxPerSec * 1e3;
801
+ else {
802
+ track ??= zoomFracTrack(cam);
803
+ ms = (arriveSec - track.invert(track.at(arriveSec) - dist$1 / speedPxPerSec)) * 1e3;
804
+ }
805
+ if (ms < travelMinMs) return {
806
+ sec: travelMinMs / 1e3,
807
+ clamped: "min"
808
+ };
809
+ if (ms > travelMaxMs) return {
810
+ sec: travelMaxMs / 1e3,
811
+ clamped: "max"
812
+ };
813
+ return { sec: ms / 1e3 };
710
814
  };
711
- for (const e of comp.events) {
712
- if (e.kind === "scroll" || e.kind === "press") continue;
815
+ for (const [evIdx, e] of comp.events.entries()) {
816
+ if (e.kind === "scroll" || e.kind === "press") {
817
+ freeAt = Math.max(freeAt, (e.tMs + (e.durationMs ?? 0)) / 1e3);
818
+ continue;
819
+ }
713
820
  const arrive = e.tMs / 1e3;
714
- const prevEnd = legs.length ? legs[legs.length - 1].t1 : 0;
715
- const t0 = Math.max(arrive - travelDur(cur, e.point), prevEnd, 0);
821
+ const prevEnd = Math.max(legs.length ? legs[legs.length - 1].t1 : 0, freeAt);
822
+ const d = travelDur(cur, e.point, arrive);
823
+ const t0 = Math.min(arrive, Math.max(arrive - d.sec, prevEnd, 0));
716
824
  legs.push({
717
825
  t0,
718
826
  t1: arrive,
719
827
  a: cur,
720
- b: e.point
828
+ b: e.point,
829
+ evIdx,
830
+ wantSec: d.sec,
831
+ ...d.clamped ? { clamped: d.clamped } : {}
721
832
  });
722
833
  cur = e.point;
723
- if (e.kind === "drag" && e.to) {
834
+ freeAt = Math.max(freeAt, (e.tMs + (e.durationMs ?? 0)) / 1e3);
835
+ if ((e.kind === "drag" || e.kind === "dropFiles") && e.to) {
724
836
  const lag = comp.cursor.dragLagMs / 1e3;
725
837
  const start = arrive + lag;
726
838
  const dEnd = (e.tMs + (e.durationMs ?? 0)) / 1e3 + lag;
@@ -765,7 +877,8 @@ function alongPath(path, u) {
765
877
  }
766
878
  function cursorPos(t, legs, comp) {
767
879
  for (const lg of legs) if (lg.t0 <= t && t <= lg.t1) {
768
- const raw = Math.max(0, Math.min(1, (t - lg.t0) / (lg.t1 - lg.t0)));
880
+ const span = lg.t1 - lg.t0;
881
+ const raw = span > 0 ? Math.max(0, Math.min(1, (t - lg.t0) / span)) : 1;
769
882
  if (lg.drag && lg.path) return alongPath(lg.path, lg.ease === "smooth" ? smoother(raw) : raw);
770
883
  const e = comp.cursor.travelEase;
771
884
  const p = e ? cubicBezier(e[0], e[1], e[2], e[3])(raw) : smoother(raw);
@@ -789,6 +902,38 @@ function cursorPos(t, legs, comp) {
789
902
  function isDragging(t, legs) {
790
903
  return legs.some((lg) => lg.drag === true && lg.t0 <= t && t <= lg.t1);
791
904
  }
905
+ /** A dropFiles carry's on-screen window [start, end] in SECONDS — when the
906
+ * ghost card rides the cursor. Same dragLagMs shift as the carry leg in
907
+ * buildLegs, so card and cursor cannot drift apart. Shared by the Revideo
908
+ * scene and the editor preview (the no-drift invariant). */
909
+ function carryWindow(e, comp) {
910
+ const lag = comp.cursor.dragLagMs / 1e3;
911
+ const t0 = e.tMs / 1e3 + lag;
912
+ return {
913
+ t0,
914
+ t1: t0 + (e.durationMs ?? 0) / 1e3
915
+ };
916
+ }
917
+ /** "1.2 MB" / "412 KB" — the ghost card's size caption (scene + preview). */
918
+ function fmtBytes(n) {
919
+ return n >= 1024 * 1024 ? `${(n / 1024 / 1024).toFixed(1)} MB` : `${Math.max(1, Math.round(n / 1024))} KB`;
920
+ }
921
+ /** The ghost card's two text lines for a dropFiles beat: the (first) filename,
922
+ * and a meta caption ("3 files · 1.8 MB" / "1.2 MB"). Shared scene/preview.
923
+ * Long filenames middle-ellipse (extension kept) so the card can't outgrow
924
+ * the frame — neither render surface clamps its width. */
925
+ function ghostCardLines(files) {
926
+ const raw = files[0]?.name ?? "file";
927
+ const MAX = 34;
928
+ const title = raw.length <= MAX ? raw : `${raw.slice(0, MAX - 12)}…${raw.slice(raw.length - 11)}`;
929
+ const total = files.reduce((s, f) => s + (f.size ?? 0), 0);
930
+ const size = total > 0 ? fmtBytes(total) : "";
931
+ const count = files.length > 1 ? `${files.length} files` : "";
932
+ return {
933
+ title,
934
+ meta: [count, size].filter(Boolean).join(" · ")
935
+ };
936
+ }
792
937
 
793
938
  //#endregion
794
939
  //#region src/camera.ts
@@ -1054,14 +1199,15 @@ function planComposition(log, opts = {}) {
1054
1199
  });
1055
1200
  const intent = c.zoom ?? "auto";
1056
1201
  const durationMs$1 = "durationMs" in c ? c.durationMs : 0;
1057
- const to = kind === "drag" ? mapPt(c.to) : void 0;
1058
- const rawPath = kind === "drag" ? c.path ?? [{
1202
+ const carries = kind === "drag" || kind === "dropFiles";
1203
+ const to = carries ? mapPt(c.to) : void 0;
1204
+ const rawPath = carries ? c.path ?? [{
1059
1205
  x: c.x,
1060
1206
  y: c.y
1061
1207
  }, c.to] : void 0;
1062
1208
  const path = rawPath?.map(mapPt);
1063
- const ease = kind === "drag" ? c.ease : void 0;
1064
- const bbox = kind === "drag" && path ? pathBBox(path) : c.box ? mapBox(c.box) : void 0;
1209
+ const ease = carries ? c.ease : void 0;
1210
+ const bbox = carries && path ? pathBBox(path) : c.box ? mapBox(c.box) : void 0;
1065
1211
  const effectBox = c.effectBox ? mapBox(c.effectBox) : void 0;
1066
1212
  const label = c.sel ?? c.note;
1067
1213
  const beat = {
@@ -1087,7 +1233,8 @@ function planComposition(log, opts = {}) {
1087
1233
  ...kind === "press" ? { keys: c.keys } : {},
1088
1234
  ...to ? { to } : {},
1089
1235
  ...path ? { path } : {},
1090
- ...ease ? { ease } : {}
1236
+ ...ease ? { ease } : {},
1237
+ ...kind === "dropFiles" ? { files: c.files } : {}
1091
1238
  };
1092
1239
  return {
1093
1240
  beat,
@@ -1111,7 +1258,7 @@ function planComposition(log, opts = {}) {
1111
1258
  enabled: f.enabled,
1112
1259
  scale: f.scale,
1113
1260
  center: f.center,
1114
- inAtMs: Math.max(0, s.beat.tMs - cursor.zoomInMs),
1261
+ inAtMs: f.enabled && s.beat.kind === "press" ? s.beat.tMs : Math.max(0, s.beat.tMs - cursor.zoomInMs),
1115
1262
  reason: f.reason
1116
1263
  };
1117
1264
  return {
@@ -1164,10 +1311,36 @@ function manualFraming(b, rest) {
1164
1311
 
1165
1312
  //#endregion
1166
1313
  //#region src/validate.ts
1314
+ /** Tail past the last beat's settle that still reads as "the shot breathing".
1315
+ * Beyond it the delivered mp4 is a frozen screen — the padded-to-25s failure. */
1316
+ const DEAD_TAIL_MS = 2500;
1317
+ /** A dwell-delayed pull-out lands a little after its own action BY DESIGN, and
1318
+ * a tail of a few frames is invisible (the spring has all but arrived). The
1319
+ * artifact is a camera that has barely LEFT when the action fires — so gate on
1320
+ * both an absolute floor and the fraction of the ramp still to run. */
1321
+ const MOVING_AT_ACTION_MS = 150;
1322
+ const MOVING_AT_ACTION_FRAC = .25;
1323
+ /** How far past the SLOWEST shipped pace a camera window may run before it is
1324
+ * worth a word. Anchored on the preset vocabulary rather than a number
1325
+ * invented here, so the ceiling tracks the presets if they are ever retuned. */
1326
+ const RAMP_SLACK = 2;
1327
+ /** A travel clamp binding on the odd short hop is the point of having clamps;
1328
+ * binding on more than this share of the legs means the speed law (and the
1329
+ * whole `pace` preset) is not what paces the take. Under CLAMPED_LEGS_MIN legs
1330
+ * the share says nothing — two clamped legs out of two is a fixture, not a
1331
+ * finding. */
1332
+ const CLAMPED_LEGS_FRAC = .5;
1333
+ const CLAMPED_LEGS_MIN = 3;
1334
+ /** A travel squeezed under this share of what the speed law asked for reads as
1335
+ * a dart rather than a glide. Paired with an absolute floor so a few-frame
1336
+ * shortfall on an already-short hop stays quiet. */
1337
+ const SQUEEZE_FRAC = .7;
1338
+ const SQUEEZE_MIN_MS = 200;
1167
1339
  const reqField = {
1168
1340
  type: "text",
1169
1341
  press: "keys",
1170
- drag: "to"
1342
+ drag: "to",
1343
+ dropFiles: "to"
1171
1344
  };
1172
1345
  function validateComposition(comp, opts = {}) {
1173
1346
  const issues = [];
@@ -1211,13 +1384,16 @@ function validateComposition(comp, opts = {}) {
1211
1384
  if (e.tMs > comp.durationMs) err(`${p}.tMs`, `tMs ${e.tMs} exceeds composition durationMs ${comp.durationMs}`, "raise durationMs or remove the beat");
1212
1385
  const need = reqField[e.kind];
1213
1386
  if (need && e[need] == null) err(`${p}.${need}`, `${e.kind} beat is missing "${need}"`, `restore ${need} from the capture`);
1387
+ if (e.kind === "dropFiles" && !e.files?.length) warn(`${p}.files`, `dropFiles beat has no files metadata — the ghost card will show a generic "file"`, "restore files [{name,size}] from the capture");
1388
+ if (e.kind === "dropFiles" && !dur) warn(`${p}.durationMs`, "dropFiles beat has no carry duration — the cursor teleports to the drop point and the ghost card only flashes", "restore durationMs from the capture");
1214
1389
  const z = e.zoom;
1215
1390
  if (!z) {
1216
1391
  err(`${p}.zoom`, "missing zoom decision", "every beat needs a zoom { enabled, scale, center, inAtMs }");
1217
1392
  continue;
1218
1393
  }
1219
1394
  if (z.inAtMs < 0) err(`${p}.zoom.inAtMs`, `negative inAtMs ${z.inAtMs}`, "clamp to 0");
1220
- if (z.inAtMs > e.tMs) err(`${p}.zoom.inAtMs`, `inAtMs ${z.inAtMs} is AFTER the action at tMs ${e.tMs} — the zoom would arrive late`, `set inAtMs = tMs − cursor.zoomInMs (= ${Math.max(0, e.tMs - comp.cursor.zoomInMs)})`);
1395
+ if (z.inAtMs > e.tMs && e.kind !== "press") err(`${p}.zoom.inAtMs`, `inAtMs ${z.inAtMs} is AFTER the action at tMs ${e.tMs} — the zoom would arrive late`, `set inAtMs = tMs − cursor.zoomInMs (= ${Math.max(0, e.tMs - comp.cursor.zoomInMs)})`);
1396
+ if (e.kind === "press" && z.enabled && z.inAtMs < e.tMs) warn(`${p}.zoom.inAtMs`, `press zoom departs ${e.tMs - z.inAtMs}ms BEFORE the keypress — its reveal doesn't exist yet, so the camera punches into empty space`, `set inAtMs = tMs (${e.tMs}) so the zoom rides the reveal in`);
1221
1397
  if (z.enabled) {
1222
1398
  if (z.scale < rest - 1e-6) err(`${p}.zoom.scale`, `scale ${z.scale.toFixed(3)} is below rest ${rest.toFixed(3)} — that zooms OUT past the frame (dead space)`, `raise to ≥ ${rest.toFixed(2)}, or set zoom.enabled=false for a full-view beat`);
1223
1399
  else if (z.scale < rest * 1.2) warn(`${p}.zoom.scale`, `scale ${z.scale.toFixed(3)} is within 20% of rest ${rest.toFixed(3)} — an imperceptible zoom (enabled but invisible)`, "raise scale to ≥ ~1.25 to actually zoom, or set enabled=false");
@@ -1226,6 +1402,26 @@ function validateComposition(comp, opts = {}) {
1226
1402
  if (!e.bbox) warn(`${p}.zoom`, "zoom enabled on a beat with no bbox — center/scale are hand-set, not bbox-fit", "double-check the center frames the intended region");
1227
1403
  }
1228
1404
  }
1405
+ const cur = comp.cursor;
1406
+ const knob = (k, positive, required) => {
1407
+ const v = cur[k];
1408
+ if (v == null) {
1409
+ if (required) err(`cursor.${k}`, `${k} is missing and the schedule has no fallback for it`, `set cursor.${k} to the shipped default (${DEFAULT_CURSOR[k]})`);
1410
+ return;
1411
+ }
1412
+ if (typeof v !== "number" || !Number.isFinite(v) || (positive ? v <= 0 : v < 0)) err(`cursor.${k}`, `${k} must be a ${positive ? "positive" : "non-negative"} number (got ${JSON.stringify(v)})`, `restore the shipped default (${DEFAULT_CURSOR[k]})`);
1413
+ };
1414
+ const speedLaw = typeof cur.travelWidthsPerSec === "number" && cur.travelWidthsPerSec > 0;
1415
+ knob("holdMs", false, true);
1416
+ knob("zoomOutMs", true, true);
1417
+ knob("zoomInMs", true, false);
1418
+ knob("travelWidthsPerSec", false, false);
1419
+ knob("travelMs", true, !speedLaw);
1420
+ knob("travelMinMs", false, speedLaw);
1421
+ knob("travelMaxMs", true, speedLaw);
1422
+ if (Number.isFinite(cur.travelMinMs) && Number.isFinite(cur.travelMaxMs) && cur.travelMaxMs < cur.travelMinMs) err("cursor.travelMaxMs", `travelMaxMs ${cur.travelMaxMs} is below travelMinMs ${cur.travelMinMs} — an inverted band, so every leg is pinned to one bound or the other and SHORT hops (${cur.travelMinMs}ms) end up slower than full-frame sweeps (${cur.travelMaxMs}ms)`, `raise travelMaxMs above travelMinMs (defaults ${DEFAULT_CURSOR.travelMinMs}/${DEFAULT_CURSOR.travelMaxMs})`);
1423
+ if (cur.zoomInMs > MOTION.calm.zoomInMs * RAMP_SLACK) warn("cursor.zoomInMs", `zoomInMs ${cur.zoomInMs} is over ${RAMP_SLACK}× the slowest shipped pace (calm = ${MOTION.calm.zoomInMs}) — a punch-in lands ON the action, so this departs that much earlier and creeps in`, `${DEFAULT_CURSOR.zoomInMs} is the frame-measured default; use pace "calm" (${MOTION.calm.zoomInMs}) for a gentler punch`);
1424
+ if (cur.zoomOutMs > MOTION.calm.zoomOutMs * RAMP_SLACK) warn("cursor.zoomOutMs", `zoomOutMs ${cur.zoomOutMs} is over ${RAMP_SLACK}× the slowest shipped pace (calm = ${MOTION.calm.zoomOutMs}) — every release drifts out for that long, and the tail must outlast it`, `${DEFAULT_CURSOR.zoomOutMs} is the frame-measured default; use pace "calm" (${MOTION.calm.zoomOutMs}) for a slower release`);
1229
1425
  const spring = comp.cursor.zoomSpring;
1230
1426
  if (spring != null) {
1231
1427
  if (!(spring >= 0 && spring < .6)) err("cursor.zoomSpring", `zoomSpring ${spring} outside [0, 0.6)`, "0 = critically damped (the default feel); keep bounce ≤ 0.3");
@@ -1236,8 +1432,55 @@ function validateComposition(comp, opts = {}) {
1236
1432
  else if (settleFrac != null && settleFrac > 0 && (comp.cursor.zoomEase || spring != null)) warn("cursor.zoomSettleFrac", `zoomSettleFrac is IGNORED while cursor.${comp.cursor.zoomEase ? "zoomEase" : "zoomSpring"} is set — the render is byte-identical to not setting it`, "delete cursor.zoomEase / cursor.zoomSpring (a pace preset clears zoomEase) to activate the settle tail");
1237
1433
  const dwell = comp.cursor.pullOutDwellMs;
1238
1434
  if (dwell != null && !(dwell >= 0 && dwell <= 5e3)) err("cursor.pullOutDwellMs", `pullOutDwellMs ${dwell} outside [0, 5000]`, "600-1000 reads as a natural beat; 0 = legacy (depart as soon as the action ends)");
1435
+ if (cur.travelWidthsPerSec > 0 && issues.every((i) => i.severity !== "error")) try {
1436
+ const travels = buildLegs(comp).filter((l) => !l.drag);
1437
+ const pace = motionName(cur);
1438
+ const shortfall = (l) => (l.wantSec ?? 0) - (l.t1 - l.t0);
1439
+ const squeezed = travels.filter((l) => l.wantSec != null && l.t1 - l.t0 < l.wantSec * SQUEEZE_FRAC && shortfall(l) > SQUEEZE_MIN_MS / 1e3).sort((a, b) => shortfall(b) - shortfall(a));
1440
+ const worst = squeezed[0];
1441
+ if (worst) {
1442
+ const got = Math.round((worst.t1 - worst.t0) * 1e3);
1443
+ const want = Math.round((worst.wantSec ?? 0) * 1e3);
1444
+ const prev = worst.evIdx != null ? events[worst.evIdx - 1] : void 0;
1445
+ warn(`events[${worst.evIdx}]`, `${squeezed.length === 1 ? "this beat's" : `${squeezed.length} beats' travel is rushed; the worst`} approach gets ${got}ms of the ${want}ms the speed law asks for — the cursor darts in${prev ? ` because events[${worst.evIdx - 1}] (${prev.kind}) is still running until ${prev.tMs + (prev.durationMs ?? 0)}ms` : " because the take starts too close to it"}`, prev ? `raise the previous step's settleMs by ≥ ${want - got}ms and re-\`make\` — the gap is in the CAPTURE, no cursor knob can widen it` : `add a leading \`wait\` (or move \`start\` closer) and re-\`make\` — the opening sweep has no room`);
1446
+ }
1447
+ for (const which of ["min", "max"]) {
1448
+ const n = travels.filter((l) => l.clamped === which).length;
1449
+ if (travels.length < CLAMPED_LEGS_MIN || n <= travels.length * CLAMPED_LEGS_FRAC) continue;
1450
+ const field = which === "min" ? "travelMinMs" : "travelMaxMs";
1451
+ const shipped = pace ? MOTION[pace] : DEFAULT_CURSOR;
1452
+ if (Math.abs(cur[field] - shipped[field]) < CLAMP_TOL_MS) continue;
1453
+ warn(`cursor.${field}`, `${n} of ${travels.length} travel legs are ${which === "min" ? "floored at" : "capped at"} a hand-set cursor.${field} of ${cur[field]}ms — on those the clamp sets the duration, not cursor.travelWidthsPerSec${pace ? `, so they no longer move with the "${pace}" pace (which ships ${shipped[field]}ms)` : ""}`, `restore cursor.${field} to ${shipped[field]}${pace ? ` (the "${pace}" pace's own value)` : " (the shipped default)"} to put those legs back under the speed law — or keep it, if they are meant to read as ${which === "min" ? "darts" : "one steady sweep"}`);
1454
+ }
1455
+ } catch {}
1239
1456
  if (comp.durationMs < lastEnd) err("durationMs", `durationMs ${comp.durationMs} ends before the last action (${lastEnd})`, `raise to ≥ ${Math.round(lastEnd + comp.cursor.holdMs + comp.cursor.zoomOutMs)}`);
1240
1457
  else if (comp.durationMs < lastEnd + comp.cursor.zoomOutMs) warn("durationMs", `only ${comp.durationMs - lastEnd}ms after the last action — the final zoom-out may be cut`, `allow ≥ ${comp.cursor.zoomOutMs}ms (cursor.zoomOutMs) of tail`);
1458
+ else if (events.length) {
1459
+ const settledEnd = lastEnd + comp.cursor.holdMs + comp.cursor.zoomOutMs;
1460
+ if (comp.durationMs > settledEnd + DEAD_TAIL_MS) warn("durationMs", `${((comp.durationMs - settledEnd) / 1e3).toFixed(1)}s of tail after the last beat settles — the delivered video ends on a frozen screen`, `trim durationMs to ≈ ${Math.round(settledEnd)}, or add a beat that earns the time`);
1461
+ }
1462
+ if (issues.every((i) => i.severity !== "error")) try {
1463
+ const sched = cameraRampSchedule(comp);
1464
+ const room = (comp.cursor.pullOutDwellMs ?? 0) + comp.cursor.zoomOutMs;
1465
+ for (let i = 0; i < events.length; i++) {
1466
+ const e = events[i];
1467
+ const r = sched[i];
1468
+ if (!r) continue;
1469
+ const rampMs = r.landMs - r.startMs;
1470
+ const nominal = r.pullOut ? comp.cursor.zoomOutMs : comp.cursor.zoomInMs;
1471
+ const handSet = Math.abs(e.zoom.inAtMs - Math.max(0, e.tMs - comp.cursor.zoomInMs)) >= 1;
1472
+ if (handSet && nominal > 0 && rampMs > nominal * RAMP_SLACK) warn(`events[${i}].zoom.inAtMs`, `this beat's camera window runs ${Math.round(rampMs)}ms — ${(rampMs / nominal).toFixed(1)}× cursor.${r.pullOut ? "zoomOutMs" : "zoomInMs"} (${nominal}ms) — so the camera departs at ${Math.round(r.startMs)}ms and creeps to the action instead of moving at the take's pace`, `set inAtMs = ${Math.max(0, e.tMs - comp.cursor.zoomInMs)} (tMs − cursor.zoomInMs) and change cursor.${r.pullOut ? "zoomOutMs" : "zoomInMs"} if the RAMP itself should be slower`);
1473
+ if (e.kind === "press") continue;
1474
+ const lateMs = Math.round(r.landMs - e.tMs);
1475
+ if (lateMs <= MOVING_AT_ACTION_MS) continue;
1476
+ if (!(rampMs > 0) || lateMs / rampMs <= MOVING_AT_ACTION_FRAC) continue;
1477
+ const prev = events[i - 1];
1478
+ const prevEnd = prev ? prev.tMs + (prev.durationMs ?? 0) : 0;
1479
+ const doneFrac = 1 - lateMs / rampMs;
1480
+ const progress = doneFrac > 0 ? `has only ${Math.round(doneFrac * 100)}% of its move done` : "has not even departed";
1481
+ warn(`events[${i}].zoom`, `the camera ${progress} when this beat's action fires (departs ${Math.round(r.startMs)}ms, lands ${Math.round(r.landMs)}ms, action ${e.tMs}ms) — the frame slides out from under it${prev ? `; the previous beat settles only ${Math.round(e.tMs - prevEnd)}ms earlier` : ""}`, prev ? `hold the frame — copy events[${i - 1}].zoom onto this beat so the camera never moves at the action; or re-capture with ≥ ${room}ms of settle on events[${i - 1}] (cursor.pullOutDwellMs + cursor.zoomOutMs)` : `re-capture with more lead-in before this beat, or set zoom.enabled=false`);
1482
+ }
1483
+ } catch {}
1241
1484
  if ((comp.cursor.pullOutDwellMs ?? 0) > 0 && issues.every((i) => i.severity !== "error")) try {
1242
1485
  const kfs = buildStageKeyframes(comp).r;
1243
1486
  let motionEndS = 0;
@@ -1420,11 +1663,12 @@ async function renderTakeExclusive(opts) {
1420
1663
  const composition = opts.composition ?? planComposition(opts.log ?? (() => {
1421
1664
  throw new Error("renderTake: provide `log` or `composition`");
1422
1665
  })(), opts.planOpts);
1666
+ const warnings = [];
1423
1667
  if (!opts.skipValidate) {
1424
1668
  const issues = validateComposition(composition, { captureLog: opts.captureLog ?? opts.log });
1425
1669
  const errors = issues.filter((i) => i.severity === "error");
1426
- const warns = issues.filter((i) => i.severity === "warn");
1427
- if (opts.logProgress && warns.length) process.stderr.write(`composition warnings:\n${formatIssues(warns)}\n`);
1670
+ warnings.push(...issues.filter((i) => i.severity === "warn"));
1671
+ if (opts.logProgress && warnings.length) process.stderr.write(`composition warnings:\n${formatIssues(warnings)}\n`);
1428
1672
  if (errors.length) throw new Error(`composition has ${errors.length} error(s) — refusing to render:\n${formatIssues(errors)}`);
1429
1673
  }
1430
1674
  const rangeSec = opts.rangeSec ?? (composition.startMs && composition.startMs > 0 ? [composition.startMs / 1e3, composition.durationMs / 1e3 + 120] : void 0);
@@ -1472,7 +1716,8 @@ async function renderTakeExclusive(opts) {
1472
1716
  }
1473
1717
  return {
1474
1718
  mp4Path: resolve(opts.outPath),
1475
- compositionPath
1719
+ compositionPath,
1720
+ warnings
1476
1721
  };
1477
1722
  } finally {
1478
1723
  await cleanupScratch(scratch);
@@ -1480,5 +1725,5 @@ async function renderTakeExclusive(opts) {
1480
1725
  }
1481
1726
 
1482
1727
  //#endregion
1483
- export { DEFAULT_CAMERA, DEFAULT_CURSOR, DEFAULT_FRAMING, DEFAULT_MOTION_BLUR, FINISH, LOOKS, MOTION, ZOOM_LEVELS, directCamera, finishName, formatIssues, lookName, math_exports as math, motionBlurActive, motionName, planComposition, renderTake, resolveFfmpeg, resolveFfprobe, validateComposition, zoomLevelName };
1728
+ export { CLAMP_TOL_MS, DEFAULT_CAMERA, DEFAULT_CURSOR, DEFAULT_FRAMING, DEFAULT_MOTION_BLUR, FINISH, LOOKS, MOTION, ZOOM_LEVELS, directCamera, finishName, formatIssues, lookName, math_exports as math, motionBlurActive, motionName, planComposition, renderTake, resolveFfmpeg, resolveFfprobe, validateComposition, zoomLevelName };
1484
1729
  //# sourceMappingURL=index.js.map