@kriya-ai/harness 0.2.2 → 0.2.4

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.
Files changed (45) hide show
  1. package/contract/SOURCE.md +3 -3
  2. package/contract/contract.json +188 -0
  3. package/package.json +1 -1
  4. package/src/edit/core/ffmpeg.js +5 -1
  5. package/src/edit/core/layout.js +26 -1
  6. package/src/edit/core/ops.js +74 -6
  7. package/src/edit/core/plan.js +2 -1
  8. package/src/edit/core/project.js +6 -1
  9. package/src/edit/core/solver.js +66 -15
  10. package/src/edit/director/ask.js +42 -27
  11. package/src/edit/director/beats.js +335 -0
  12. package/src/edit/director/lookups.js +133 -0
  13. package/src/edit/director/plan.js +365 -0
  14. package/src/edit/director/playbooks.js +131 -0
  15. package/src/edit/director/revise.js +171 -12
  16. package/src/edit/engine/captions.js +32 -0
  17. package/src/edit/engine/found-media.js +64 -0
  18. package/src/edit/engine/motion.js +78 -18
  19. package/src/edit/engine/music-bed.js +110 -0
  20. package/src/edit/engine/reference.js +134 -0
  21. package/src/edit/engine/scenes.js +480 -0
  22. package/src/edit/engine/sfx.js +63 -0
  23. package/src/edit/gates/copy.js +25 -5
  24. package/src/edit/gates/index.js +12 -4
  25. package/src/edit/gates/picture.js +5 -0
  26. package/src/edit/gates/text.js +20 -4
  27. package/src/edit/graph/scheduler.js +1 -1
  28. package/src/edit/host/client.js +28 -4
  29. package/src/edit/host/deliver.js +8 -1
  30. package/src/edit/host/jobs.js +43 -0
  31. package/src/edit/host/main.js +4 -2
  32. package/src/edit/host/paths.js +25 -0
  33. package/src/edit/host/projects.js +328 -38
  34. package/src/edit/host/server.js +106 -8
  35. package/src/edit/index/db.js +5 -0
  36. package/src/edit/index/layers/retakes.js +7 -1
  37. package/src/edit/index/views.js +9 -0
  38. package/src/edit/loop/make.js +9 -6
  39. package/src/edit/recipes/montage.js +74 -0
  40. package/src/edit/recipes/programme.js +24 -0
  41. package/src/edit/recipes/reel.js +149 -20
  42. package/src/edit/recipes/scene-clips.js +127 -0
  43. package/src/edit/runtime/fetch.js +32 -0
  44. package/studio/dist/studio.css +62 -4
  45. package/studio/dist/studio.js +4 -2
@@ -7,9 +7,9 @@ again from Kriya and update the hash below in the same change.
7
7
 
8
8
  | Field | Value |
9
9
  | --- | --- |
10
- | Copied | 2026-11-08 (again: decision cards, notes, new recordings; dispatch kind `edit`, the editing preview routes) |
11
- | From | Kriya repository `main` (uncommitted) on `d46bb0c` |
12
- | sha256 | `65e1614719f28861bc11b2368c97e90ddff81ac070591a48366ac846ededae88` |
10
+ | Copied | 2026-11-09 (again: `GET /editing/features`, for the visual scenes) |
11
+ | From | Kriya repository `main` (uncommitted) on `a2bb6ed` |
12
+ | sha256 | `8bf16886bc6b98bda3f261c9a762c7424324e9a893f5a50ff12f77c4b71ed754` |
13
13
 
14
14
  When the Kriya side commits the file, replace "From" with that commit.
15
15
  `tests/contract.test.js` checks the hash, so a hand edit fails.
@@ -785,6 +785,194 @@
785
785
  "additionalProperties": false
786
786
  }
787
787
  },
788
+ {
789
+ "method": "GET",
790
+ "path": "/editing/features",
791
+ "auth": true,
792
+ "request": null,
793
+ "response": {
794
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
795
+ "type": "object",
796
+ "properties": {
797
+ "visuals": {
798
+ "type": "boolean"
799
+ },
800
+ "playbooks": {
801
+ "type": "boolean"
802
+ },
803
+ "mediaSearch": {
804
+ "type": "boolean"
805
+ }
806
+ },
807
+ "required": ["visuals", "playbooks", "mediaSearch"],
808
+ "additionalProperties": false
809
+ }
810
+ },
811
+ {
812
+ "method": "POST",
813
+ "path": "/editing/media",
814
+ "auth": true,
815
+ "request": {
816
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
817
+ "type": "object",
818
+ "properties": {
819
+ "queries": {
820
+ "minItems": 1,
821
+ "maxItems": 6,
822
+ "type": "array",
823
+ "items": {
824
+ "type": "string",
825
+ "minLength": 2,
826
+ "maxLength": 80
827
+ }
828
+ }
829
+ },
830
+ "required": ["queries"],
831
+ "additionalProperties": false
832
+ },
833
+ "response": {
834
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
835
+ "type": "object",
836
+ "properties": {
837
+ "results": {
838
+ "type": "array",
839
+ "items": {
840
+ "type": "object",
841
+ "properties": {
842
+ "query": {
843
+ "type": "string"
844
+ },
845
+ "items": {
846
+ "type": "array",
847
+ "items": {
848
+ "type": "object",
849
+ "properties": {
850
+ "id": {
851
+ "type": "string"
852
+ },
853
+ "source": {
854
+ "type": "string",
855
+ "enum": ["wikimedia", "nasa", "openverse"]
856
+ },
857
+ "kind": {
858
+ "type": "string",
859
+ "enum": ["image", "video"]
860
+ },
861
+ "title": {
862
+ "type": "string"
863
+ },
864
+ "url": {
865
+ "type": "string"
866
+ },
867
+ "thumb": {
868
+ "type": "string"
869
+ },
870
+ "width": {
871
+ "type": ["number", "null"]
872
+ },
873
+ "height": {
874
+ "type": ["number", "null"]
875
+ },
876
+ "licence": {
877
+ "type": "string"
878
+ },
879
+ "rights": {
880
+ "type": "string",
881
+ "enum": ["public_domain", "licensed"]
882
+ },
883
+ "creator": {
884
+ "type": "string"
885
+ },
886
+ "page": {
887
+ "type": "string"
888
+ }
889
+ },
890
+ "required": [
891
+ "id",
892
+ "source",
893
+ "kind",
894
+ "title",
895
+ "url",
896
+ "thumb",
897
+ "width",
898
+ "height",
899
+ "licence",
900
+ "rights",
901
+ "creator",
902
+ "page"
903
+ ],
904
+ "additionalProperties": false
905
+ }
906
+ }
907
+ },
908
+ "required": ["query", "items"],
909
+ "additionalProperties": false
910
+ }
911
+ }
912
+ },
913
+ "required": ["results"],
914
+ "additionalProperties": false
915
+ }
916
+ },
917
+ {
918
+ "method": "POST",
919
+ "path": "/editing/define",
920
+ "auth": true,
921
+ "request": {
922
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
923
+ "type": "object",
924
+ "properties": {
925
+ "terms": {
926
+ "minItems": 1,
927
+ "maxItems": 6,
928
+ "type": "array",
929
+ "items": {
930
+ "type": "string",
931
+ "minLength": 2,
932
+ "maxLength": 80
933
+ }
934
+ }
935
+ },
936
+ "required": ["terms"],
937
+ "additionalProperties": false
938
+ },
939
+ "response": {
940
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
941
+ "type": "object",
942
+ "properties": {
943
+ "definitions": {
944
+ "type": "array",
945
+ "items": {
946
+ "type": "object",
947
+ "properties": {
948
+ "term": {
949
+ "type": "string"
950
+ },
951
+ "title": {
952
+ "type": "string"
953
+ },
954
+ "quote": {
955
+ "type": "string"
956
+ },
957
+ "source": {
958
+ "type": "string"
959
+ },
960
+ "page": {
961
+ "type": "string"
962
+ },
963
+ "licence": {
964
+ "type": "string"
965
+ }
966
+ },
967
+ "required": ["term", "title", "quote", "source", "page", "licence"],
968
+ "additionalProperties": false
969
+ }
970
+ }
971
+ },
972
+ "required": ["definitions"],
973
+ "additionalProperties": false
974
+ }
975
+ },
788
976
  {
789
977
  "method": "POST",
790
978
  "path": "/editing/jobs/{id}/previews",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kriya-ai/harness",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Kriya Harness (beta): a Kriya agent on your machine, built on DeepSeek Harness",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -60,11 +60,15 @@ export const animatedZoom = (zoom) => zoom !== undefined && (zoom.x !== undefine
60
60
 
61
61
  // A colour match (ED13) is its baked .cube, measured by the Engine; then the person's own values.
62
62
  // shortcut: eq only approximates lift, gain and ev; a full lift/gamma/gain grade isn't built
63
- function gradeSteps({ gamma, saturation, lift, gain, ev, match }, input) {
63
+ function gradeSteps({ gamma, saturation, lift, gain, ev, match, temperature, vibrance, vignette }, input) {
64
64
  const steps = match ? [filter("lut3d", { file: input(match.key) })] : []
65
+ if (temperature !== undefined) steps.push(filter("colortemperature", { temperature: Math.round(temperature) }))
65
66
  const brightness = (lift ?? 0) + (ev ?? 0) / 8
66
67
  const options = Object.fromEntries(Object.entries({ gamma, saturation, brightness: brightness || undefined, contrast: gain }).filter(([, value]) => value !== undefined))
67
68
  if (Object.keys(options).length) steps.push(filter("eq", options))
69
+ if (vibrance !== undefined) steps.push(filter("vibrance", { intensity: vibrance.toFixed(3) }))
70
+ // A lens-like darkening at the edges: the angle grows with the strength
71
+ if (vignette) steps.push(filter("vignette", { angle: (0.25 + 0.45 * vignette).toFixed(3) }))
68
72
  return steps
69
73
  }
70
74
 
@@ -20,6 +20,8 @@ export function safeZoneFor(project) {
20
20
  const { width, height } = project.canvas
21
21
  const zone = {}
22
22
  for (const deliverable of project.deliverables ?? []) {
23
+ // Only exports in this frame's shape: an earlier 9:16 export's margins don't squeeze a 16:9 cut (found in use)
24
+ if (deliverable.size && deliverable.size.width * height !== deliverable.size.height * width) continue
23
25
  const share = SAFE_ZONES[deliverable.preset]
24
26
  if (!share) continue
25
27
  for (const [side, value] of Object.entries(share)) zone[side] = Math.max(zone[side] ?? 0, Math.ceil(value * (side === "top" || side === "bottom" ? height : width)))
@@ -27,7 +29,30 @@ export function safeZoneFor(project) {
27
29
  return zone
28
30
  }
29
31
 
30
- const overlaps = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h
32
+ /** A cutaway scene's block (VISUAL_SCENES.md): it covers the frame, so the speaker's face isn't in the picture under it. */
33
+ export const isSceneBlock = (block) => block?.blockId === "scene"
34
+
35
+ /**
36
+ * A scene's two regions, in canvas pixels: its content box, inside the safe zones, and the
37
+ * caption row under it, so a caption over a scene never lands on the diagram.
38
+ * @param {{ width: number, height: number }} canvas
39
+ * @param {{ top?: number, right?: number, bottom?: number, left?: number }} safe
40
+ * @param {{ w: number, h: number }} caption the caption box's size
41
+ */
42
+ export function sceneFrame(canvas, safe, caption) {
43
+ const margin = Math.round(Math.min(canvas.width, canvas.height) * 0.05)
44
+ // A little inside the safe zone: a spring's overshoot on entry mustn't cross it (found on real footage)
45
+ const inset = Math.round(margin / 4)
46
+ const left = Math.max(safe.left ?? 0, margin) + inset
47
+ const right = Math.max(safe.right ?? 0, margin) + inset
48
+ const top = Math.max(safe.top ?? 0, margin) + inset
49
+ const bottom = Math.max(safe.bottom ?? 0, Math.round(margin / 2))
50
+ const w = Math.min(caption.w, canvas.width - (safe.left ?? 0) - (safe.right ?? 0))
51
+ const row = { x: (safe.left ?? 0) + Math.floor((canvas.width - (safe.left ?? 0) - (safe.right ?? 0) - w) / 2), y: canvas.height - bottom - caption.h, w, h: caption.h }
52
+ return { row, content: { x: left, y: top, w: canvas.width - left - right, h: row.y - Math.round(margin / 2) - top } }
53
+ }
54
+
55
+ const overlaps =(a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h
31
56
 
32
57
  function candidates(item, { canvas, safe, prefer }) {
33
58
  if (item.fixed) return [{ box: item.fixed, cost: 0 }]
@@ -4,6 +4,7 @@
4
4
 
5
5
  import { anchorSource, openIndex, wordAfter, wordAt, wordBefore } from "./anchors.js"
6
6
  import { check, EFFECTS, SHAPES, validateProject } from "./project.js"
7
+ import { snapToFrame } from "./time.js"
7
8
 
8
9
  class Refused extends Error {
9
10
  constructor(code, message) {
@@ -175,17 +176,33 @@ function removeFrom(s, op, asset, from, to) {
175
176
  const OPS = {
176
177
  // Selection
177
178
  keep_range: {
178
- fields: { asset: "id", from: "ref", to: "ref", "after?": { nullable: "id" } },
179
+ // exact: cut where it's asked, not moved off a word or padded (a montage's cuts stay on the beat)
180
+ fields: { asset: "id", from: "ref", to: "ref", "after?": { nullable: "id" }, "exact?": "bool" },
179
181
  run(op, s) {
180
182
  const asset = assetOf(s, op.asset, SEQUENCED)
181
183
  checkRange(s, asset, sourceEdge(s, op.from, asset.id, "start"), sourceEdge(s, op.to, asset.id, "end"))
182
- const clip = addClip(s, "base", { source: { asset: asset.id, in: op.from, out: op.to } })
184
+ const clip = addClip(s, "base", { source: { asset: asset.id, in: op.from, out: op.to }, ...(op.exact ? { seamIn: true, seamOut: true } : {}) })
183
185
  if (op.after === undefined) return
184
186
  const clips = sequenceOf(s).clips
185
187
  clips.pop()
186
188
  clips.splice(op.after === null ? 0 : clips.indexOf(clipOf(s, op.after)) + 1, 0, clip)
187
189
  },
188
190
  },
191
+ // A cold open (ED story): a moment from later plays first, then the story starts. The
192
+ // clip is marked an echo, so captions and anchors stay on the moment itself; mono puts it
193
+ // in black and white, the classic teaser
194
+ cold_open: {
195
+ fields: { asset: "id", from: "ref", to: "ref", "mono?": "bool" },
196
+ run(op, s) {
197
+ const asset = assetOf(s, op.asset, SEQUENCED)
198
+ checkRange(s, asset, sourceEdge(s, op.from, asset.id, "start"), sourceEdge(s, op.to, asset.id, "end"))
199
+ const clip = addClip(s, "base", { source: { asset: asset.id, in: op.from, out: op.to }, echo: true })
200
+ const clips = sequenceOf(s).clips
201
+ clips.pop()
202
+ clips.splice(0, 0, clip)
203
+ if (op.mono) setEffect(clip, { type: "grade", saturation: 0, gain: 1.12, vignette: 0.4 })
204
+ },
205
+ },
189
206
  remove_range: {
190
207
  fields: { "asset?": "id", from: "ref", to: "ref" },
191
208
  run(op, s) {
@@ -288,6 +305,53 @@ const OPS = {
288
305
  writable(s, op.clip).speed = op.rate
289
306
  },
290
307
  },
308
+ // A speed ramp: the stretch from..to eases up to `peak` and back, in five steps, so a 2×
309
+ // whoosh through a moment or an eased slow motion (peak 1/2) reads as one movement.
310
+ // The sound goes with it, pitch kept (atempo)
311
+ speed_ramp: {
312
+ fields: { clip: "id", from: "ref", to: "ref", peak: "rate" },
313
+ run(op, s) {
314
+ const clip = writable(s, op.clip)
315
+ if (!clip.source) refuse("no_source", `clip "${op.clip}" has no picture to ramp`)
316
+ const ratio = op.peak.n / op.peak.d
317
+ if (!(ratio >= 0.25 && ratio <= 4) || ratio === 1) refuse("bad_value", "a ramp's peak is between 1/4 and 4 times, and not 1")
318
+ const asset = clip.source.asset
319
+ // Joins on frames, so neither side of a step drops or repeats one
320
+ const rate = assetOf(s, asset, SEQUENCED).facts.fps ?? s.project.canvas.fps
321
+ const onFrame = (t) => snapToFrame(t, rate, "nearest")
322
+ const t0 = onFrame(sourceEdge(s, op.from, asset, "start"))
323
+ const t1 = onFrame(sourceEdge(s, op.to, asset, "end"))
324
+ const [start, end] = clipRange(s, clip)
325
+ if (!(t0 >= start && t1 <= end && t1 > t0)) refuse("outside_clip", `that stretch isn't inside clip "${op.clip}"`)
326
+ let region = clip
327
+ if (t0 > start) {
328
+ region = splitClip(s, clip, { out: t0, in: t0 }, t0)
329
+ clip.seamOut = true
330
+ region.seamIn = true
331
+ }
332
+ if (t1 < end) {
333
+ const after = splitClip(s, region, { out: t1, in: t1 }, t1)
334
+ region.seamOut = true
335
+ after.seamIn = true
336
+ }
337
+ // Five equal steps of source: up, up, the peak, down, down
338
+ const shape = [0.4, 0.8, 1, 0.8, 0.4]
339
+ const gcd = (a, b) => (b ? gcd(b, a % b) : a)
340
+ const rateOf = (f) => {
341
+ const n = Math.round((1 + (ratio - 1) * f) * 100)
342
+ const g = gcd(n, 100)
343
+ return { n: n / g, d: 100 / g }
344
+ }
345
+ let piece = region
346
+ for (let i = 0; i < shape.length; i++) {
347
+ const cut = onFrame(t0 + ((t1 - t0) * (i + 1)) / shape.length)
348
+ const next = i < shape.length - 1 ? splitClip(s, piece, { out: cut, in: cut }, cut) : null
349
+ if (next) ((piece.seamOut = true), (next.seamIn = true))
350
+ piece.speed = rateOf(shape[i])
351
+ piece = next
352
+ }
353
+ },
354
+ },
291
355
  freeze: {
292
356
  fields: { clip: "id", at: "ref", duration: "flicks" },
293
357
  run(op, s) {
@@ -463,10 +527,14 @@ const OPS = {
463
527
 
464
528
  // Colour
465
529
  grade: {
466
- fields: { clip: "id", "lift?": "num", "gamma?": "num", "gain?": "num", "saturation?": "num" },
467
- run(op, s) {
468
- const values = given(op, ["lift", "gamma", "gain", "saturation"])
469
- if (Object.keys(values).length === 0) refuse("needs_a_value", "give at least one of lift, gamma, gain or saturation")
530
+ // temperature in kelvin (6500 neutral, lower is warmer), vibrance -2 to 2, vignette 0 to 1
531
+ fields: { clip: "id", "lift?": "num", "gamma?": "num", "gain?": "num", "saturation?": "num", "temperature?": "num", "vibrance?": "num", "vignette?": "num" },
532
+ run(op, s) {
533
+ const values = given(op, ["lift", "gamma", "gain", "saturation", "temperature", "vibrance", "vignette"])
534
+ if (Object.keys(values).length === 0) refuse("needs_a_value", "give at least one of lift, gamma, gain, saturation, temperature, vibrance or vignette")
535
+ if (values.temperature !== undefined && (values.temperature < 2000 || values.temperature > 12000)) refuse("bad_value", "temperature is between 2000 and 12000 kelvin")
536
+ if (values.vibrance !== undefined && Math.abs(values.vibrance) > 2) refuse("bad_value", "vibrance is between -2 and 2")
537
+ if (values.vignette !== undefined && (values.vignette < 0 || values.vignette > 1)) refuse("bad_value", "vignette is between 0 and 1")
470
538
  setEffect(writable(s, op.clip), { type: "grade", ...values })
471
539
  },
472
540
  },
@@ -157,7 +157,8 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
157
157
  })
158
158
  : []
159
159
  const blockTiles = timeline.overlays
160
- .filter((overlay) => overlay.block)
160
+ // A definition with no clear place stays out (the solver has said why), rather than land on a face
161
+ .filter((overlay) => overlay.block && !(overlay.block.blockId === "term" && !overlay.placement))
161
162
  .map((overlay) => {
162
163
  const node = { kind: "block", ...overlay.block, placement: overlay.placement, duration: overlay.end - overlay.at, ...(overlay.behind ? { behind: true } : {}) }
163
164
  return { key: key(node, []), kind: "block", at: overlay.at, end: overlay.end, node }
@@ -25,7 +25,7 @@ export const EFFECTS = {
25
25
  reframe: { mode: { enum: ["subject", "fixed"] }, "x?": "int", "y?": "int" },
26
26
  zoom: { scale: "num", "ease?": "str", "x?": "int", "y?": "int" },
27
27
  matte: { "model?": "str" },
28
- grade: { "lift?": "num", "gamma?": "num", "gain?": "num", "saturation?": "num", "ev?": "num", "match?": "id" },
28
+ grade: { "lift?": "num", "gamma?": "num", "gain?": "num", "saturation?": "num", "ev?": "num", "match?": "id", "temperature?": "num", "vibrance?": "num", "vignette?": "num" },
29
29
  lut: { asset: "id" },
30
30
  stabilize: { "strength?": "num" },
31
31
  fade: { "in?": "flicks", "out?": "flicks" },
@@ -96,6 +96,11 @@ export const SHAPES = {
96
96
  effects: { list: "effect" },
97
97
  speed: "rate",
98
98
  "linkGroup?": "str",
99
+ // A cold open's teaser: the same words again, before the story. Anchors skip it
100
+ "echo?": "bool",
101
+ // A join, not a cut: this edge continues the clip beside it exactly (a speed ramp's steps)
102
+ "seamIn?": "bool",
103
+ "seamOut?": "bool",
99
104
  "audioLead?": "flicks",
100
105
  "audioLag?": "flicks",
101
106
  createdBy: AUTHOR,
@@ -3,7 +3,8 @@
3
3
  // satisfy and never silently drops a request.
4
4
 
5
5
  import { anchorSource, openIndex, wordAfter, wordAt, wordBefore } from "./anchors.js"
6
- import { safeZoneFor, solveLayout } from "./layout.js"
6
+ import { mapBox } from "./faces.js"
7
+ import { isSceneBlock, safeZoneFor, sceneFrame, solveLayout } from "./layout.js"
7
8
  import { flicksToFrames, frameAtTimestamp, framesToFlicks, scaleFlicks, snapToFrame } from "./time.js"
8
9
 
9
10
  const ms = (n) => n * 705_600
@@ -74,9 +75,11 @@ function cutPoints(s, clip, asset) {
74
75
  s.issue("cut_moved_off_word", { clip: clip.id, word: word.id, message: "a cut would have landed inside a word, so it moved to the word's edge" })
75
76
  return t
76
77
  }
77
- const inStart = wordAt(words, start)
78
+ // A seam is a join inside one continuous take (a speed ramp's step): it stays exactly where it is
79
+ if (clip.seamIn && clip.seamOut) return { pictureIn: start, pictureOut: end, soundIn: start, soundOut: end }
80
+ const inStart = clip.seamIn ? null : wordAt(words, start)
78
81
  if (inStart) start = moved(inStart, inStart.start)
79
- const inEnd = wordAt(words, end)
82
+ const inEnd = clip.seamOut ? null : wordAt(words, end)
80
83
  if (inEnd) end = moved(inEnd, inEnd.end)
81
84
 
82
85
  const floor = wordBefore(words, start)?.end ?? 0
@@ -114,7 +117,7 @@ function cutPoints(s, clip, asset) {
114
117
  }
115
118
  soundIn = Math.max(0, soundIn - lead)
116
119
  soundOut = Math.min(duration, soundOut + lag)
117
- return { pictureIn, pictureOut, soundIn, soundOut }
120
+ return clip.seamIn ? (clip.seamOut ? { pictureIn: start, pictureOut: end, soundIn: start, soundOut: end } : { pictureIn: start, pictureOut, soundIn: start, soundOut }) : clip.seamOut ? { pictureIn, pictureOut: end, soundIn, soundOut: end } : { pictureIn, pictureOut, soundIn, soundOut }
118
121
  }
119
122
 
120
123
  const framesFor = (span, fps) => (span <= 0 ? 0 : flicksToFrames(span - 1, fps) + 1)
@@ -135,7 +138,7 @@ function layBase(s, clips) {
135
138
  const piece = (from, to, length, hold) => {
136
139
  const frames = framesFor(length, s.fps)
137
140
  if (frames === 0) return
138
- const item = { clip: clip.id, asset: asset.id, in: from, out: to, at: framesToFlicks(frame, s.fps), end: framesToFlicks(frame + frames, s.fps), speed: clip.speed, effects, ...(hold ? { hold } : {}) }
141
+ const item = { clip: clip.id, asset: asset.id, in: from, out: to, at: framesToFlicks(frame, s.fps), end: framesToFlicks(frame + frames, s.fps), speed: clip.speed, effects, ...(hold ? { hold } : {}), ...(clip.echo ? { echo: true } : {}) }
139
142
  frame += frames
140
143
  s.picture.push(item)
141
144
  return item
@@ -169,7 +172,8 @@ function layBase(s, clips) {
169
172
  /** Where a time in an asset sits on the timeline, or null if it was cut. */
170
173
  function mapSource(s, place, anchor, spot) {
171
174
  const edge = anchor.edge ?? "start"
172
- const hit = s.picture.find(({ asset, in: from, out, hold }) => !hold && asset === spot.asset && (edge === "start" ? from <= spot.t && spot.t < out : from < spot.t && spot.t <= out))
175
+ // A word lives where the story says it: never in a hold, never in a cold open's echo of it
176
+ const hit = s.picture.find(({ asset, in: from, out, hold, echo }) => !hold && !echo && asset === spot.asset && (edge === "start" ? from <= spot.t && spot.t < out : from < spot.t && spot.t <= out))
173
177
  if (hit) return hit.at + scaleFlicks(spot.t - hit.in, inverse(hit.speed))
174
178
  for (const clip of s.rest) {
175
179
  if (clip.source?.asset !== spot.asset || s.tracks.get(clip.track).role === "ambience") continue
@@ -329,35 +333,82 @@ function placeRest(s) {
329
333
  }
330
334
  }
331
335
 
332
- // shortcut: scales face boxes by frame size and ignores any crop path, ED11's reframe recipes must map them through it
336
+ // Faces under a caption, on the output, mapped as the render draws the frame (faces.js's mapBox:
337
+ // one scale that covers the frame, centred). Found in use: scaling width and height apart put
338
+ // faces in the wrong place whenever the take's shape differs from the frame, so captions sat on them.
339
+ // shortcut: a reframe's crop path isn't known yet here (plan.js makes it after the solver), so x is
340
+ // the centred crop's; a caption is a full-width row, so its y, which this gets exactly, is what matters
341
+ const FACE_REACH = 705_600_000 // faces are sampled once a second (L8), so look a second either side
333
342
  function facesDuring(s, at, end) {
334
- const { width, height } = s.project.canvas
343
+ const canvas = s.project.canvas
335
344
  const boxes = []
345
+ const zooms = s.zooms.filter((z) => z.at < end && at < z.end)
336
346
  for (const piece of s.picture) {
337
347
  if (piece.end <= at || piece.at >= end) continue
338
348
  const facts = s.assets.get(piece.asset).facts
339
- const scaleX = width / (facts.width ?? width)
340
- const scaleY = height / (facts.height ?? height)
341
- const from = piece.in + scaleFlicks(Math.max(0, at - piece.at), piece.speed)
342
- const to = piece.in + scaleFlicks(Math.min(piece.end, end) - piece.at, piece.speed)
349
+ const size = { width: facts.width ?? canvas.width, height: facts.height ?? canvas.height }
350
+ const from = piece.in + scaleFlicks(Math.max(0, at - piece.at), piece.speed) - FACE_REACH
351
+ const to = piece.in + scaleFlicks(Math.min(piece.end, end) - piece.at, piece.speed) + FACE_REACH
343
352
  for (const face of s.raw.faces ?? []) {
344
- if (face.asset === piece.asset && face.t >= from && face.t <= to) boxes.push({ x: Math.floor(face.box.x * scaleX), y: Math.floor(face.box.y * scaleY), w: Math.ceil(face.box.w * scaleX), h: Math.ceil(face.box.h * scaleY) })
353
+ if (face.asset !== piece.asset || face.t < from || face.t > to) continue
354
+ // Clear the face both as shot and inside any punch-in over the caption
355
+ for (const zoom of [undefined, ...zooms]) {
356
+ const box = mapBox(face.box, { zoom }, size, canvas, canvas, face.t)
357
+ // A little room around the face: a caption touching the chin still reads as on it
358
+ if (box) boxes.push({ x: box.x - Math.round(box.w * 0.1), y: box.y - Math.round(box.h * 0.1), w: Math.round(box.w * 1.2), h: Math.round(box.h * 1.25) })
359
+ }
345
360
  }
346
361
  }
347
362
  return boxes
348
363
  }
349
364
 
365
+ // A page a fast speaker says in a blink stays up long enough to read, until the next one starts (found on real footage)
366
+ const MIN_CAPTION = 1.2 * 705_600_000
367
+ function holdCaptions(s) {
368
+ // Only where a playbook asked for it (DP3): off, every existing project solves exactly as before
369
+ if (s.project.look?.caption?.hold !== true) return
370
+ const list = [...s.captions].sort((a, b) => a.at - b.at)
371
+ list.forEach((caption, i) => {
372
+ const next = list[i + 1]?.at ?? s.duration
373
+ // Text behind the speaker keeps its matte's window exactly
374
+ if (!caption.behind && caption.end - caption.at < MIN_CAPTION) caption.end = Math.max(caption.end, Math.min(caption.at + MIN_CAPTION, next, s.duration))
375
+ })
376
+ }
377
+
350
378
  /** Step 6: every caption and card gets a place, or a report. */
351
379
  function layOut(s) {
380
+ holdCaptions(s)
352
381
  const { rules } = s
353
382
  const { width, height } = s.project.canvas
354
383
  const safe = rules.safe ?? safeZoneFor(s.project)
355
384
  // Narrower than the look's width when the safe zone is (found in ED8: else no row fits)
356
385
  const w = Math.min(Math.floor((width * rules.boxWidth) / 100), width - (safe.left ?? 0) - (safe.right ?? 0))
357
386
  const h = Math.floor((height * rules.boxHeight) / 100)
358
- const placeable = [...s.captions, ...s.overlays.filter((o) => o.block)]
387
+ // A scene takes its content box; what plays over it sits on the row below that, with no face to clear
388
+ const scenes = s.overlays.filter((o) => isSceneBlock(o.block))
389
+ const frame = sceneFrame({ width, height }, safe, { w, h })
390
+ for (const scene of scenes) scene.placement = frame.content
391
+ // A definition has its own place, above the caption row or at the top, wherever no face is; with none free
392
+ // it stays out. Captions under it keep to their row, so the two never meet
393
+ const terms = s.overlays.filter((o) => o.block?.blockId === "term")
394
+ for (const term of terms) {
395
+ const tall = Math.floor(height * 0.18)
396
+ const gap = Math.round(height * 0.012)
397
+ const clash = (box) => facesDuring(s, term.at, term.end).some((f) => box.x < f.x + f.w && f.x < box.x + box.w && box.y < f.y + f.h && f.y < box.y + box.h)
398
+ const options = [{ ...frame.row, y: frame.row.y - gap - tall, h: tall }, { ...frame.row, y: frame.content.y, h: tall }]
399
+ term.placement = options.find((box) => !clash(box)) ?? null
400
+ if (!term.placement) s.issue("no_placement", { clip: term.clip, message: "there's no place for this definition clear of the speaker's face, so it isn't shown" })
401
+ }
402
+ const onScene = (item) => [...scenes, ...terms].some((scene) => scene.at < item.end && item.at < scene.end)
403
+ // Footage over the whole frame hides the speaker, so a caption there has no face to clear
404
+ const footage = s.overlays.filter((o) => !o.block)
405
+ const hidden = (item) => footage.some((o) => o.at <= item.at && item.end <= o.end)
406
+ const placeable = [...s.captions, ...s.overlays.filter((o) => o.block && !isSceneBlock(o.block) && o.block.blockId !== "term")]
359
407
  // Text behind the speaker may sit on the face: the matte puts the speaker in front of it
360
- const items = placeable.map((item) => ({ id: item.clip, at: item.at, end: item.end, w, h, faces: item.behind ? [] : facesDuring(s, item.at, item.end), ...(item.placement ? { fixed: item.placement } : {}) }))
408
+ const items = placeable.map((item) => {
409
+ const covered = onScene(item)
410
+ return { id: item.clip, at: item.at, end: item.end, w, h, faces: item.behind || covered || hidden(item) ? [] : facesDuring(s, item.at, item.end), ...(item.placement ? { fixed: item.placement } : covered ? { fixed: frame.row } : {}) }
411
+ })
361
412
  const { placements, issues } = solveLayout(items, { canvas: { width, height }, safe, prefer: rules.prefer })
362
413
  for (const item of placeable) item.placement = placements[item.clip]
363
414
  for (const issue of issues) s.issue(issue.code, issue)