@kriya-ai/harness 0.2.3 → 0.2.5

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 (41) hide show
  1. package/contract/SOURCE.md +3 -3
  2. package/contract/contract.json +194 -0
  3. package/package.json +1 -1
  4. package/src/edit/core/ffmpeg.js +19 -1
  5. package/src/edit/core/layout.js +24 -1
  6. package/src/edit/core/ops.js +9 -3
  7. package/src/edit/core/plan.js +36 -5
  8. package/src/edit/core/solver.js +39 -3
  9. package/src/edit/core/transitions.js +17 -0
  10. package/src/edit/director/beats.js +335 -0
  11. package/src/edit/director/continuity.js +129 -0
  12. package/src/edit/director/graphics.js +152 -0
  13. package/src/edit/director/lookups.js +133 -0
  14. package/src/edit/director/plan.js +118 -6
  15. package/src/edit/director/playbooks.js +131 -0
  16. package/src/edit/director/revise.js +49 -5
  17. package/src/edit/engine/captions.js +32 -0
  18. package/src/edit/engine/found-media.js +64 -0
  19. package/src/edit/engine/graphics.js +178 -0
  20. package/src/edit/engine/motion.js +24 -3
  21. package/src/edit/engine/scenes.js +480 -0
  22. package/src/edit/gates/copy.js +25 -5
  23. package/src/edit/gates/index.js +16 -5
  24. package/src/edit/gates/picture.js +11 -3
  25. package/src/edit/gates/text.js +20 -4
  26. package/src/edit/graph/scheduler.js +1 -1
  27. package/src/edit/host/deliver.js +8 -1
  28. package/src/edit/host/main.js +8 -5
  29. package/src/edit/host/paths.js +15 -2
  30. package/src/edit/host/projects.js +229 -12
  31. package/src/edit/host/server.js +72 -3
  32. package/src/edit/index/views.js +9 -0
  33. package/src/edit/loop/make.js +25 -6
  34. package/src/edit/recipes/graphic-clips.js +57 -0
  35. package/src/edit/recipes/montage.js +74 -0
  36. package/src/edit/recipes/programme.js +24 -0
  37. package/src/edit/recipes/reel.js +65 -14
  38. package/src/edit/recipes/scene-clips.js +127 -0
  39. package/src/edit/runtime/fetch.js +33 -0
  40. package/studio/dist/studio.css +15 -0
  41. package/studio/dist/studio.js +3 -3
@@ -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-10 (again: `motion` and `customMotion` in `GET /editing/features`, for the motion kit) |
11
+ | From | Kriya repository `main` (uncommitted) on `3a0c769` |
12
+ | sha256 | `b6fa9d2424249e8fd9e8b3ab806f7178ef5977bbd4b9d11f12ef85b385f0d6fb` |
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,200 @@
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
+ "motion": {
807
+ "type": "boolean"
808
+ },
809
+ "customMotion": {
810
+ "type": "boolean"
811
+ }
812
+ },
813
+ "required": ["visuals", "playbooks", "mediaSearch", "motion", "customMotion"],
814
+ "additionalProperties": false
815
+ }
816
+ },
817
+ {
818
+ "method": "POST",
819
+ "path": "/editing/media",
820
+ "auth": true,
821
+ "request": {
822
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
823
+ "type": "object",
824
+ "properties": {
825
+ "queries": {
826
+ "minItems": 1,
827
+ "maxItems": 6,
828
+ "type": "array",
829
+ "items": {
830
+ "type": "string",
831
+ "minLength": 2,
832
+ "maxLength": 80
833
+ }
834
+ }
835
+ },
836
+ "required": ["queries"],
837
+ "additionalProperties": false
838
+ },
839
+ "response": {
840
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
841
+ "type": "object",
842
+ "properties": {
843
+ "results": {
844
+ "type": "array",
845
+ "items": {
846
+ "type": "object",
847
+ "properties": {
848
+ "query": {
849
+ "type": "string"
850
+ },
851
+ "items": {
852
+ "type": "array",
853
+ "items": {
854
+ "type": "object",
855
+ "properties": {
856
+ "id": {
857
+ "type": "string"
858
+ },
859
+ "source": {
860
+ "type": "string",
861
+ "enum": ["wikimedia", "nasa", "openverse"]
862
+ },
863
+ "kind": {
864
+ "type": "string",
865
+ "enum": ["image", "video"]
866
+ },
867
+ "title": {
868
+ "type": "string"
869
+ },
870
+ "url": {
871
+ "type": "string"
872
+ },
873
+ "thumb": {
874
+ "type": "string"
875
+ },
876
+ "width": {
877
+ "type": ["number", "null"]
878
+ },
879
+ "height": {
880
+ "type": ["number", "null"]
881
+ },
882
+ "licence": {
883
+ "type": "string"
884
+ },
885
+ "rights": {
886
+ "type": "string",
887
+ "enum": ["public_domain", "licensed"]
888
+ },
889
+ "creator": {
890
+ "type": "string"
891
+ },
892
+ "page": {
893
+ "type": "string"
894
+ }
895
+ },
896
+ "required": [
897
+ "id",
898
+ "source",
899
+ "kind",
900
+ "title",
901
+ "url",
902
+ "thumb",
903
+ "width",
904
+ "height",
905
+ "licence",
906
+ "rights",
907
+ "creator",
908
+ "page"
909
+ ],
910
+ "additionalProperties": false
911
+ }
912
+ }
913
+ },
914
+ "required": ["query", "items"],
915
+ "additionalProperties": false
916
+ }
917
+ }
918
+ },
919
+ "required": ["results"],
920
+ "additionalProperties": false
921
+ }
922
+ },
923
+ {
924
+ "method": "POST",
925
+ "path": "/editing/define",
926
+ "auth": true,
927
+ "request": {
928
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
929
+ "type": "object",
930
+ "properties": {
931
+ "terms": {
932
+ "minItems": 1,
933
+ "maxItems": 6,
934
+ "type": "array",
935
+ "items": {
936
+ "type": "string",
937
+ "minLength": 2,
938
+ "maxLength": 80
939
+ }
940
+ }
941
+ },
942
+ "required": ["terms"],
943
+ "additionalProperties": false
944
+ },
945
+ "response": {
946
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
947
+ "type": "object",
948
+ "properties": {
949
+ "definitions": {
950
+ "type": "array",
951
+ "items": {
952
+ "type": "object",
953
+ "properties": {
954
+ "term": {
955
+ "type": "string"
956
+ },
957
+ "title": {
958
+ "type": "string"
959
+ },
960
+ "quote": {
961
+ "type": "string"
962
+ },
963
+ "source": {
964
+ "type": "string"
965
+ },
966
+ "page": {
967
+ "type": "string"
968
+ },
969
+ "licence": {
970
+ "type": "string"
971
+ }
972
+ },
973
+ "required": ["term", "title", "quote", "source", "page", "licence"],
974
+ "additionalProperties": false
975
+ }
976
+ }
977
+ },
978
+ "required": ["definitions"],
979
+ "additionalProperties": false
980
+ }
981
+ },
788
982
  {
789
983
  "method": "POST",
790
984
  "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.3",
3
+ "version": "0.2.5",
4
4
  "description": "Kriya Harness (beta): a Kriya agent on your machine, built on DeepSeek Harness",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -2,6 +2,7 @@
2
2
  // for spawn, never a shell string. Text passes through one tested escape.
3
3
 
4
4
  import { secondsArg } from "./time.js"
5
+ import { TRANSITIONS } from "./transitions.js"
5
6
 
6
7
  const BT709 = ["-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709", "-color_range", "tv"]
7
8
  // On the frames too: FFmpeg can drop the output flags alone when it converts a format
@@ -145,7 +146,24 @@ export function segmentArgs(plan, segment, { input, tile, output, encoder, toneM
145
146
  const chains = []
146
147
 
147
148
  const labels = node.picture.map((item, i) => {
148
- chains.push(`[${inputFor(input(item.asset), item.in)}:v]${pictureChain(item, width, height, plan, { input, toneMap })}[p${i}]`)
149
+ const chain = `[${inputFor(input(item.asset), item.in)}:v]${pictureChain(item, width, height, plan, { input, toneMap })}`
150
+ if (!item.enter) {
151
+ chains.push(`${chain}[p${i}]`)
152
+ return `[p${i}]`
153
+ }
154
+ // A transition in (transitions.js): the piece before, held on its last frame, under this
155
+ // piece's first moments; then the rest of the piece. Its length is the piece's own, so the cut doesn't move
156
+ const { kind, duration, from } = item.enter
157
+ if (!Object.hasOwn(TRANSITIONS, kind)) throw new RangeError(`this render can't do a "${kind}" transition`)
158
+ const length = secondsArg(duration)
159
+ // xfade needs both sides alike: one frame rate, one pixel format, one time base
160
+ const alike = `${filter("fps", { fps: `${plan.output.fps.n}/${plan.output.fps.d}` })},format=yuv420p,settb=AVTB`
161
+ chains.push(`${chain},${alike},split[ph${i}][pt${i}]`)
162
+ chains.push(`[${inputFor(input(from.asset), from.in)}:v]${pictureChain(from, width, height, plan, { input, toneMap })},${alike}[pf${i}]`)
163
+ chains.push(`[ph${i}]${filter("trim", { end: length })},setpts=PTS-STARTPTS[pa${i}]`)
164
+ chains.push(`[pf${i}][pa${i}]${filter("xfade", { transition: TRANSITIONS[kind], duration: length, offset: 0 })}[px${i}]`)
165
+ chains.push(`[pt${i}]${filter("trim", { start: length })},setpts=PTS-STARTPTS[pb${i}]`)
166
+ chains.push(`[px${i}][pb${i}]concat=n=2:v=1:a=0,setsar=1,${TAG_BT709}[p${i}]`)
149
167
  return `[p${i}]`
150
168
  })
151
169
  let current = labels[0]
@@ -29,7 +29,30 @@ export function safeZoneFor(project) {
29
29
  return zone
30
30
  }
31
31
 
32
- 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
33
56
 
34
57
  function candidates(item, { canvas, safe, prefer }) {
35
58
  if (item.fixed) return [{ box: item.fixed, cost: 0 }]
@@ -3,6 +3,7 @@
3
3
  // no inverse per operation: history moves HEAD and replays (history.js).
4
4
 
5
5
  import { anchorSource, openIndex, wordAfter, wordAt, wordBefore } from "./anchors.js"
6
+ import { TRANSITION_MAX, TRANSITION_MIN, TRANSITIONS } from "./transitions.js"
6
7
  import { check, EFFECTS, SHAPES, validateProject } from "./project.js"
7
8
  import { snapToFrame } from "./time.js"
8
9
 
@@ -176,11 +177,12 @@ function removeFrom(s, op, asset, from, to) {
176
177
  const OPS = {
177
178
  // Selection
178
179
  keep_range: {
179
- fields: { asset: "id", from: "ref", to: "ref", "after?": { nullable: "id" } },
180
+ // exact: cut where it's asked, not moved off a word or padded (a montage's cuts stay on the beat)
181
+ fields: { asset: "id", from: "ref", to: "ref", "after?": { nullable: "id" }, "exact?": "bool" },
180
182
  run(op, s) {
181
183
  const asset = assetOf(s, op.asset, SEQUENCED)
182
184
  checkRange(s, asset, sourceEdge(s, op.from, asset.id, "start"), sourceEdge(s, op.to, asset.id, "end"))
183
- const clip = addClip(s, "base", { source: { asset: asset.id, in: op.from, out: op.to } })
185
+ const clip = addClip(s, "base", { source: { asset: asset.id, in: op.from, out: op.to }, ...(op.exact ? { seamIn: true, seamOut: true } : {}) })
184
186
  if (op.after === undefined) return
185
187
  const clips = sequenceOf(s).clips
186
188
  clips.pop()
@@ -365,7 +367,11 @@ const OPS = {
365
367
  transition: {
366
368
  fields: { clip: "id", kind: "str", duration: "flicks" },
367
369
  run(op, s) {
368
- setEffect(writable(s, op.clip), { type: "transition", kind: op.kind, duration: op.duration })
370
+ if (!Object.hasOwn(TRANSITIONS, op.kind)) refuse("unknown_transition", `there is no "${op.kind}" transition: ${Object.keys(TRANSITIONS).join(", ")}`)
371
+ if (op.duration < TRANSITION_MIN || op.duration > TRANSITION_MAX) refuse("bad_duration", "a transition lasts 0.2 to 0.8 seconds")
372
+ const clip = writable(s, op.clip)
373
+ if (!clip.source) refuse("not_footage", `clip "${op.clip}" isn't footage, so nothing can transition into it`)
374
+ setEffect(clip, { type: "transition", kind: op.kind, duration: op.duration })
369
375
  },
370
376
  },
371
377
  stabilize: {
@@ -7,11 +7,12 @@ import { outputFaces, unionBox } from "./faces.js"
7
7
  import { canonical, sha256 } from "./project.js"
8
8
  import { solveReframe } from "./reframe.js"
9
9
  import { solve } from "./solver.js"
10
- import { flicksToFrames, FLICKS, framesToFlicks, scaleFlicks, snapToFrame } from "./time.js"
10
+ import { flicksToFrames, FLICKS, frameFlicks, framesToFlicks, scaleFlicks, snapToFrame } from "./time.js"
11
11
 
12
12
  const MAX_SEGMENT = 6 * FLICKS
13
13
  const DRAFT_SHORT_SIDE = 720
14
- const PICTURE_EFFECTS = new Set(["reframe", "grade", "lut", "stabilize", "transition", "fade"])
14
+ // A transition isn't an effect on the piece's own frames: it becomes the piece's `enter` below
15
+ const PICTURE_EFFECTS = new Set(["reframe", "grade", "lut", "stabilize", "fade"])
15
16
  const AUDIO_EFFECTS = new Set(["level", "eq", "duck", "fade", "fit"])
16
17
 
17
18
  const even = (value) => Math.round(value / 2) * 2
@@ -72,6 +73,14 @@ function zoomNode(zoom, start) {
72
73
  return node
73
74
  }
74
75
 
76
+ // The crop's x at one moment of a path: the same straight lines ffmpeg.js draws between its points
77
+ function cropAt(path, t) {
78
+ const after = path.findIndex((point) => point.t >= t)
79
+ if (after <= 0) return path[after === 0 ? 0 : path.length - 1].x
80
+ const [a, b] = [path[after - 1], path[after]]
81
+ return Math.round(a.x + ((b.x - a.x) * (t - a.t)) / (b.t - a.t))
82
+ }
83
+
75
84
  function boundaries(timeline, rawIndex, fps) {
76
85
  const cuts = new Set([0, timeline.duration])
77
86
  for (const piece of timeline.picture) {
@@ -157,7 +166,8 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
157
166
  })
158
167
  : []
159
168
  const blockTiles = timeline.overlays
160
- .filter((overlay) => overlay.block)
169
+ // A definition with no clear place stays out (the solver has said why), rather than land on a face
170
+ .filter((overlay) => overlay.block && !(overlay.block.blockId === "term" && !overlay.placement))
161
171
  .map((overlay) => {
162
172
  const node = { kind: "block", ...overlay.block, placement: overlay.placement, duration: overlay.end - overlay.at, ...(overlay.behind ? { behind: true } : {}) }
163
173
  return { key: key(node, []), kind: "block", at: overlay.at, end: overlay.end, node }
@@ -206,6 +216,26 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
206
216
  const hidden = (tile) => tile.node.behind === true && mattes.some((m) => m.at <= tile.at && tile.end <= m.end)
207
217
  for (const tile of tiles) if (tile.node.behind && !hidden(tile)) tile.front = true
208
218
 
219
+ // A transition into a piece (transitions.js): the piece before it, frozen on its last frame and
220
+ // dressed as it was, for the incoming piece to arrive over. Only in the segment the piece starts
221
+ // in, never longer than half the piece or than that segment less two frames, so the cut stays put
222
+ const frame = frameFlicks(project.canvas.fps)
223
+ const enterOf = (piece, start, end) => {
224
+ const asked = piece.effects.find((e) => e.type === "transition")
225
+ if (!asked || piece.hold || piece.at !== start) return null
226
+ const before = timeline.picture.find((p) => p !== piece && p.end === piece.at)
227
+ if (!before) return null
228
+ const duration = snapToFrame(Math.min(asked.duration, Math.floor((piece.end - piece.at) / 2), end - start - 2 * frame), project.canvas.fps, "floor")
229
+ if (duration < 2 * frame) return null
230
+ const last = before.hold ? before.in : Math.max(before.in, before.out - scaleFlicks(frame, before.speed))
231
+ const path = crops.get(before.clip)
232
+ const color = sourceColor(before.asset)
233
+ // shortcut: a punch-in still on at the cut is kept only when it's a plain centred one; an eased or focused zoom is left off the held frame
234
+ const zoom = timeline.zooms.find((z) => z.at < piece.at && piece.at <= z.end && z.x === undefined && z.ease !== "smooth")
235
+ const from = { asset: before.asset, in: last, out: before.out, at: 0, end: duration, speed: { n: 1, d: 1 }, hold: true, effects: only(resolved(before), PICTURE_EFFECTS), ...(path ? { crop: [{ t: last, x: cropAt(path, last) }] } : {}), ...(zoom ? { zoom: zoomNode(zoom, start) } : {}), ...(color ? { color } : {}) }
236
+ return { kind: asked.kind, duration, from }
237
+ }
238
+
209
239
  const segments = boundaries(timeline, rawIndex, project.canvas.fps).map(([start, end], i) => {
210
240
  const picture = timeline.picture.filter(during(start, end)).map((piece) => {
211
241
  const part = clipped(piece, start, end)
@@ -213,7 +243,8 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
213
243
  const path = crops.get(piece.clip)
214
244
  const crop = path ? cropFor(path, part, (rawIndex.shots ?? []).filter((s) => s.asset === piece.asset).map((s) => s.start)) : undefined
215
245
  const zoom = timeline.zooms.find(during(start, end))
216
- return { ...part, ...(piece.hold ? { hold: true } : {}), effects: only(resolved(piece), PICTURE_EFFECTS), ...(crop ? { crop } : {}), ...(zoom ? { zoom: zoomNode(zoom, start) } : {}), ...(color ? { color } : {}) }
246
+ const enter = enterOf(piece, start, end)
247
+ return { ...part, ...(piece.hold ? { hold: true } : {}), effects: only(resolved(piece), PICTURE_EFFECTS), ...(crop ? { crop } : {}), ...(zoom ? { zoom: zoomNode(zoom, start) } : {}), ...(color ? { color } : {}), ...(enter ? { enter } : {}) }
217
248
  })
218
249
  const overlays = footage.filter(during(start, end)).map((overlay) => ({ ...clipped(overlay, start, end), effects: only(overlay.effects, PICTURE_EFFECTS) }))
219
250
  const node = {
@@ -223,7 +254,7 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
223
254
  ...(mattes.some(during(start, end)) ? { mattes: mattes.filter(during(start, end)).map((m) => ({ at: m.at - start, end: m.end - start, box: m.box })) } : {}),
224
255
  }
225
256
  const luts = picture.flatMap((item) => item.effects.filter((e) => e.type === "lut").map((e) => e.asset))
226
- return { id: `s${i}`, start, end, key: key(node, [...picture.map((item) => item.asset), ...overlays.map((item) => item.asset), ...luts]), node }
257
+ return { id: `s${i}`, start, end, key: key(node, [...picture.flatMap((item) => [item.asset, ...(item.enter ? [item.enter.from.asset] : [])]), ...overlays.map((item) => item.asset), ...luts]), node }
227
258
  })
228
259
 
229
260
  issues.push(...crowdedEffects(timeline.audio))
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { anchorSource, openIndex, wordAfter, wordAt, wordBefore } from "./anchors.js"
6
6
  import { mapBox } from "./faces.js"
7
- import { safeZoneFor, solveLayout } from "./layout.js"
7
+ import { isSceneBlock, safeZoneFor, sceneFrame, solveLayout } from "./layout.js"
8
8
  import { flicksToFrames, frameAtTimestamp, framesToFlicks, scaleFlicks, snapToFrame } from "./time.js"
9
9
 
10
10
  const ms = (n) => n * 705_600
@@ -362,17 +362,53 @@ function facesDuring(s, at, end) {
362
362
  return boxes
363
363
  }
364
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
+
365
378
  /** Step 6: every caption and card gets a place, or a report. */
366
379
  function layOut(s) {
380
+ holdCaptions(s)
367
381
  const { rules } = s
368
382
  const { width, height } = s.project.canvas
369
383
  const safe = rules.safe ?? safeZoneFor(s.project)
370
384
  // Narrower than the look's width when the safe zone is (found in ED8: else no row fits)
371
385
  const w = Math.min(Math.floor((width * rules.boxWidth) / 100), width - (safe.left ?? 0) - (safe.right ?? 0))
372
386
  const h = Math.floor((height * rules.boxHeight) / 100)
373
- 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")]
374
407
  // Text behind the speaker may sit on the face: the matte puts the speaker in front of it
375
- 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
+ })
376
412
  const { placements, issues } = solveLayout(items, { canvas: { width, height }, safe, prefer: rules.prefer })
377
413
  for (const item of placeable) item.placement = placements[item.clip]
378
414
  for (const issue of issues) s.issue(issue.code, issue)
@@ -0,0 +1,17 @@
1
+ // Transitions (MOTION_GRAPHICS.md §6): how one clip arrives over the last frame of the one
2
+ // before it. The cut never moves: the outgoing clip's last frame is held underneath while the
3
+ // incoming clip comes in over its own first moments, so the sound, the captions and every
4
+ // word anchor stay where they were. The kinds are a fixed list; code names the FFmpeg
5
+ // transition, a model never does.
6
+
7
+ const FLICKS = 705_600_000
8
+
9
+ /** What a person or the Director may ask for → FFmpeg's xfade transition. */
10
+ export const TRANSITIONS = { fade: "fade", dip: "fadeblack", flash: "fadewhite", wipe: "wipeleft", slide: "slideleft", zoom: "zoomin" }
11
+ export const TRANSITION_LABELS = { fade: "Fade", dip: "Dip to black", flash: "Flash", wipe: "Wipe", slide: "Slide", zoom: "Zoom" }
12
+ export const TRANSITION_MIN = Math.round(0.2 * FLICKS)
13
+ export const TRANSITION_MAX = Math.round(0.8 * FLICKS)
14
+ export const TRANSITION_DEFAULT = Math.round(0.3 * FLICKS)
15
+
16
+ /** A length inside the allowed range; anything else is the default. */
17
+ export const transitionLength = (duration) => (Number.isSafeInteger(duration) ? Math.min(TRANSITION_MAX, Math.max(TRANSITION_MIN, duration)) : TRANSITION_DEFAULT)