@open-take/compositor 0.2.7 → 0.2.9

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,
@@ -565,14 +581,18 @@ function buildCameraSchedule(comp) {
565
581
  * lands. `null` for a beat the camera holds through (no anchor). Derived from
566
582
  * the same schedule the render uses, so a dwell-delayed pull-out (which
567
583
  * departs after the stored inAtMs and can land after its own tMs) is
568
- * 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. */
569
587
  function cameraRampSchedule(comp) {
570
- const { anchors, ramps, landTs } = buildCameraSchedule(comp);
588
+ const { anchors, targets, restR, ramps, landTs } = buildCameraSchedule(comp);
571
589
  const out = comp.events.map(() => null);
572
590
  anchors.forEach((a, i) => {
591
+ const from = i > 0 ? targets[i - 1] : restR;
573
592
  out[a.evIdx] = {
574
593
  startMs: ramps[i].start * 1e3,
575
- landMs: landTs[i] * 1e3
594
+ landMs: landTs[i] * 1e3,
595
+ pullOut: targets[i].w > from.w + 1e-6
576
596
  };
577
597
  });
578
598
  return out;
@@ -712,29 +732,107 @@ function stageCamera(comp) {
712
732
  at
713
733
  };
714
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
+ }
715
786
  function buildLegs(comp) {
716
787
  const legs = [];
717
788
  let cur = comp.start;
789
+ let freeAt = 0;
718
790
  const { travelWidthsPerSec, travelMinMs, travelMaxMs, travelMs } = comp.cursor;
719
- const speedPxPerMs = (travelWidthsPerSec || 0) * comp.source.videoWidth / 1e3;
720
- const travelDur = (a, b) => {
721
- 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 };
722
797
  const dist$1 = Math.hypot(b.x - a.x, b.y - a.y);
723
- 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 };
724
814
  };
725
- for (const e of comp.events) {
726
- 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
+ }
727
820
  const arrive = e.tMs / 1e3;
728
- const prevEnd = legs.length ? legs[legs.length - 1].t1 : 0;
729
- 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));
730
824
  legs.push({
731
825
  t0,
732
826
  t1: arrive,
733
827
  a: cur,
734
- b: e.point
828
+ b: e.point,
829
+ evIdx,
830
+ wantSec: d.sec,
831
+ ...d.clamped ? { clamped: d.clamped } : {}
735
832
  });
736
833
  cur = e.point;
737
- 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) {
738
836
  const lag = comp.cursor.dragLagMs / 1e3;
739
837
  const start = arrive + lag;
740
838
  const dEnd = (e.tMs + (e.durationMs ?? 0)) / 1e3 + lag;
@@ -779,7 +877,8 @@ function alongPath(path, u) {
779
877
  }
780
878
  function cursorPos(t, legs, comp) {
781
879
  for (const lg of legs) if (lg.t0 <= t && t <= lg.t1) {
782
- 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;
783
882
  if (lg.drag && lg.path) return alongPath(lg.path, lg.ease === "smooth" ? smoother(raw) : raw);
784
883
  const e = comp.cursor.travelEase;
785
884
  const p = e ? cubicBezier(e[0], e[1], e[2], e[3])(raw) : smoother(raw);
@@ -803,6 +902,38 @@ function cursorPos(t, legs, comp) {
803
902
  function isDragging(t, legs) {
804
903
  return legs.some((lg) => lg.drag === true && lg.t0 <= t && t <= lg.t1);
805
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
+ }
806
937
 
807
938
  //#endregion
808
939
  //#region src/camera.ts
@@ -1068,14 +1199,15 @@ function planComposition(log, opts = {}) {
1068
1199
  });
1069
1200
  const intent = c.zoom ?? "auto";
1070
1201
  const durationMs$1 = "durationMs" in c ? c.durationMs : 0;
1071
- const to = kind === "drag" ? mapPt(c.to) : void 0;
1072
- 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 ?? [{
1073
1205
  x: c.x,
1074
1206
  y: c.y
1075
1207
  }, c.to] : void 0;
1076
1208
  const path = rawPath?.map(mapPt);
1077
- const ease = kind === "drag" ? c.ease : void 0;
1078
- 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;
1079
1211
  const effectBox = c.effectBox ? mapBox(c.effectBox) : void 0;
1080
1212
  const label = c.sel ?? c.note;
1081
1213
  const beat = {
@@ -1101,7 +1233,8 @@ function planComposition(log, opts = {}) {
1101
1233
  ...kind === "press" ? { keys: c.keys } : {},
1102
1234
  ...to ? { to } : {},
1103
1235
  ...path ? { path } : {},
1104
- ...ease ? { ease } : {}
1236
+ ...ease ? { ease } : {},
1237
+ ...kind === "dropFiles" ? { files: c.files } : {}
1105
1238
  };
1106
1239
  return {
1107
1240
  beat,
@@ -1178,10 +1311,36 @@ function manualFraming(b, rest) {
1178
1311
 
1179
1312
  //#endregion
1180
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;
1181
1339
  const reqField = {
1182
1340
  type: "text",
1183
1341
  press: "keys",
1184
- drag: "to"
1342
+ drag: "to",
1343
+ dropFiles: "to"
1185
1344
  };
1186
1345
  function validateComposition(comp, opts = {}) {
1187
1346
  const issues = [];
@@ -1225,6 +1384,8 @@ function validateComposition(comp, opts = {}) {
1225
1384
  if (e.tMs > comp.durationMs) err(`${p}.tMs`, `tMs ${e.tMs} exceeds composition durationMs ${comp.durationMs}`, "raise durationMs or remove the beat");
1226
1385
  const need = reqField[e.kind];
1227
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");
1228
1389
  const z = e.zoom;
1229
1390
  if (!z) {
1230
1391
  err(`${p}.zoom`, "missing zoom decision", "every beat needs a zoom { enabled, scale, center, inAtMs }");
@@ -1241,6 +1402,26 @@ function validateComposition(comp, opts = {}) {
1241
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");
1242
1403
  }
1243
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`);
1244
1425
  const spring = comp.cursor.zoomSpring;
1245
1426
  if (spring != null) {
1246
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");
@@ -1251,8 +1432,55 @@ function validateComposition(comp, opts = {}) {
1251
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");
1252
1433
  const dwell = comp.cursor.pullOutDwellMs;
1253
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 {}
1254
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)}`);
1255
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 {}
1256
1484
  if ((comp.cursor.pullOutDwellMs ?? 0) > 0 && issues.every((i) => i.severity !== "error")) try {
1257
1485
  const kfs = buildStageKeyframes(comp).r;
1258
1486
  let motionEndS = 0;
@@ -1435,11 +1663,12 @@ async function renderTakeExclusive(opts) {
1435
1663
  const composition = opts.composition ?? planComposition(opts.log ?? (() => {
1436
1664
  throw new Error("renderTake: provide `log` or `composition`");
1437
1665
  })(), opts.planOpts);
1666
+ const warnings = [];
1438
1667
  if (!opts.skipValidate) {
1439
1668
  const issues = validateComposition(composition, { captureLog: opts.captureLog ?? opts.log });
1440
1669
  const errors = issues.filter((i) => i.severity === "error");
1441
- const warns = issues.filter((i) => i.severity === "warn");
1442
- 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`);
1443
1672
  if (errors.length) throw new Error(`composition has ${errors.length} error(s) — refusing to render:\n${formatIssues(errors)}`);
1444
1673
  }
1445
1674
  const rangeSec = opts.rangeSec ?? (composition.startMs && composition.startMs > 0 ? [composition.startMs / 1e3, composition.durationMs / 1e3 + 120] : void 0);
@@ -1480,14 +1709,16 @@ async function renderTakeExclusive(opts) {
1480
1709
  const producedAbs = resolve(scratch, produced);
1481
1710
  if (motionBlurActive(composition.motionBlur)) await motionBlurMp4(producedAbs, resolve(opts.outPath), composition.output.fps, composition.motionBlur.samples, composition.motionBlur.shutter);
1482
1711
  else await copyFile(producedAbs, resolve(opts.outPath));
1483
- const compositionPath = resolve(opts.outPath).replace(/\.mp4$/i, "") + ".composition.json";
1712
+ const compositionPath = opts.compositionPath ? resolve(opts.compositionPath) : `${resolve(opts.outPath).replace(/\.mp4$/i, "")}.composition.json`;
1484
1713
  if (opts.writeCompositionSibling !== false) {
1485
1714
  const { review: _review,...persisted } = composition;
1715
+ await mkdir(dirname(compositionPath), { recursive: true });
1486
1716
  await writeFile(compositionPath, JSON.stringify(persisted, null, 2));
1487
1717
  }
1488
1718
  return {
1489
1719
  mp4Path: resolve(opts.outPath),
1490
- compositionPath
1720
+ compositionPath,
1721
+ warnings
1491
1722
  };
1492
1723
  } finally {
1493
1724
  await cleanupScratch(scratch);
@@ -1495,5 +1726,5 @@ async function renderTakeExclusive(opts) {
1495
1726
  }
1496
1727
 
1497
1728
  //#endregion
1498
- 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 };
1729
+ 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 };
1499
1730
  //# sourceMappingURL=index.js.map