@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
@@ -0,0 +1,64 @@
1
+ // Licensed media the person approved on the Plan Card (EDD-52): downloaded by the Host, only over
2
+ // HTTPS, only from the hosts the server's search reads, with no redirects and a size limit. A still
3
+ // becomes a short clip with a slow move, so it goes through the same render as any B-roll.
4
+
5
+ import { createWriteStream, renameSync, rmSync } from "node:fs"
6
+ import { Readable } from "node:stream"
7
+ import { pipeline } from "node:stream/promises"
8
+
9
+ import { EngineFailure } from "./tool.js"
10
+
11
+ export const MEDIA_HOSTS = ["upload.wikimedia.org", "thumb.wikimedia.org", "images-assets.nasa.gov", "live.staticflickr.com"]
12
+ export const MEDIA_TYPES = { "image/jpeg": ".jpg", "image/png": ".png", "image/webp": ".webp", "video/webm": ".webm", "video/mp4": ".mp4", "video/ogg": ".ogv", "application/ogg": ".ogv" }
13
+ const MAX_BYTES = 100 * 1024 * 1024
14
+ const TIMEOUT_MS = 120_000
15
+
16
+ export function allowedMediaUrl(url) {
17
+ try {
18
+ const parsed = new URL(String(url))
19
+ return parsed.protocol === "https:" && !parsed.username && !parsed.password && !parsed.port && MEDIA_HOSTS.includes(parsed.hostname)
20
+ } catch {
21
+ return false
22
+ }
23
+ }
24
+
25
+ /**
26
+ * @param {string} url
27
+ * @param {string} base the file's path without its extension; the type the server states picks it
28
+ * @returns {Promise<{ file: string, type: string }>}
29
+ */
30
+ export async function downloadMedia(url, base, { signal, maxBytes = MAX_BYTES, get = fetch } = {}) {
31
+ if (!allowedMediaUrl(url)) throw new EngineFailure("input", "bad_media_url", "That picture isn't from a source Kriya may download from.")
32
+ const limit = AbortSignal.timeout(TIMEOUT_MS)
33
+ const response = await get(url, { redirect: "error", headers: { "user-agent": "KriyaEditingStudio/1.0 (https://github.com/zuko14/kriya-harness)" }, signal: signal ? AbortSignal.any([signal, limit]) : limit })
34
+ if (!response.ok) throw new EngineFailure("environment", "media_download", `The source answered ${response.status}.`)
35
+ const type = String(response.headers.get("content-type") ?? "").split(";")[0].trim().toLowerCase()
36
+ const extension = MEDIA_TYPES[type]
37
+ if (!extension) throw new EngineFailure("input", "bad_media_type", "That file isn't a picture or video Kriya can use.")
38
+ if (Number(response.headers.get("content-length") ?? 0) > maxBytes) throw new EngineFailure("input", "media_too_big", "That file is too big.")
39
+ const file = `${base}${extension}`
40
+ const part = `${file}.${process.pid}.part`
41
+ let seen = 0
42
+ const counted = async function* (source) {
43
+ for await (const chunk of source) {
44
+ seen += chunk.length
45
+ if (seen > maxBytes) throw new EngineFailure("input", "media_too_big", "That file is too big.")
46
+ yield chunk
47
+ }
48
+ }
49
+ try {
50
+ await pipeline(Readable.fromWeb(response.body), counted, createWriteStream(part))
51
+ renameSync(part, file)
52
+ } catch (error) {
53
+ rmSync(part, { force: true })
54
+ throw error
55
+ }
56
+ return { file, type }
57
+ }
58
+
59
+ /** FFmpeg's arguments for a still as a clip: filling the frame, moving slowly in or out. No sound. */
60
+ export function stillClipArgs({ image, output, width, height, seconds, fps = 30, inward = true }) {
61
+ const frames = Math.max(1, Math.round(seconds * fps))
62
+ const zoom = inward ? `1+0.1*on/${frames}` : `1.1-0.1*on/${frames}`
63
+ return ["-hide_banner", "-nostdin", "-loglevel", "error", "-protocol_whitelist", "file,pipe", "-i", image, "-vf", `scale=${width * 2}:${height * 2}:force_original_aspect_ratio=increase,crop=${width * 2}:${height * 2},zoompan=z='${zoom}':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=${frames}:s=${width}x${height}:fps=${fps},format=yuv420p`, "-frames:v", String(frames), "-c:v", "libx264", "-preset", "veryfast", "-crf", "18", "-an", "-y", output]
64
+ }
@@ -0,0 +1,178 @@
1
+ // The motion kit (MOTION_GRAPHICS.md, EDD-58): titles, name straps, opening and end cards,
2
+ // quotes and numbers over the footage, drawn by Kriya's own code from typed variables. No
3
+ // model writes code here. Web Animations only, so a graphic seeks and renders like every
4
+ // other tile: no clock, no randomness, no network. Each sits in the box the layout solver
5
+ // gives it, clear of the speaker's face and the captions, and its words are `text` and
6
+ // `subtitle`, so the copy and contrast gates read it as they read a title.
7
+
8
+ import { EngineFailure } from "./tool.js"
9
+
10
+ const FLICKS = 705_600_000
11
+
12
+ export const GRAPHIC_BLOCK = "graphic"
13
+ export const GRAPHIC_VERSION = 1
14
+
15
+ /** The kinds: what each is for (the Director's prompt and the Plan Card read this), and its styles, the first the default. */
16
+ export const GRAPHIC_KINDS = {
17
+ title: { label: "Title", styles: ["rise", "slam", "words"], subtitle: false, when: "a few strong words of the line being said, to land its point" },
18
+ chapter: { label: "Chapter card", styles: ["wipe"], subtitle: false, when: "the name of a new part of the video, as the speaker starts it" },
19
+ quote: { label: "Quote", styles: ["line"], subtitle: false, when: "a short sentence the speaker says that is worth reading as well as hearing" },
20
+ lower: { label: "Name strap", styles: ["bar", "pill"], subtitle: true, when: "who is speaking: the name in `text`, the role in `subtitle`; only when the person gave them" },
21
+ intro: { label: "Opening title", styles: ["sweep"], subtitle: true, when: "the video's title over its first seconds, with an optional second line" },
22
+ end: { label: "End card", styles: ["sweep"], subtitle: true, when: "the closing call to action over the last seconds, with an optional handle or second line" },
23
+ stat: { label: "Number", styles: ["pop"], subtitle: true, number: true, when: "one number the speaker says, as digits in `text` (with its unit if said), and what it counts in `subtitle`" },
24
+ }
25
+ export const STYLE_LABELS = { rise: "Rise", slam: "Slam", words: "Word by word", wipe: "Wipe", line: "Accent line", bar: "Bar", pill: "Pill", sweep: "Line sweep", pop: "Pop" }
26
+
27
+ /** The brand kit a project may choose from; hex and font stacks stay in code. Ink on plate holds WCAG 4.5:1 (tested). */
28
+ export const GRAPHIC_ACCENTS = { teal: "#4fd1c5", yellow: "#ffd23f", amber: "#ffb347", pink: "#ff7ab6", white: "#ffffff" }
29
+ export const GRAPHIC_TONES = { dark: { plate: "#13292b", ink: "#f2eadf", chip: "#13292b" }, light: { plate: "#f6f1e7", ink: "#1c2530", chip: "#1c2530" } }
30
+ // System fonts only: nothing is downloaded, and every stack ends in a family each platform has
31
+ export const GRAPHIC_FONTS = {
32
+ sans: "'Helvetica Neue',Helvetica,Arial,sans-serif",
33
+ serif: "Georgia,'Times New Roman',serif",
34
+ condensed: "'Avenir Next Condensed','Arial Narrow','Helvetica Neue',Arial,sans-serif",
35
+ mono: "'SF Mono',Menlo,Consolas,'Courier New',monospace",
36
+ }
37
+ export const TEXT_MAX = 48
38
+ export const SUBTITLE_MAX = 32 // one line under the main one, in the narrowest frame at the smallest readable size
39
+ const NUMBER = /^[₹$€£]?\d{1,7}(?:[.,]\d{1,3})*\s?(?:%|[A-Za-z₹$€£]{1,8})?$/
40
+
41
+ // Too long is cut at a word, never through one
42
+ const cleanText = (value, max = TEXT_MAX) => {
43
+ if (typeof value !== "string") return ""
44
+ const text = value.replace(/[\u0000-\u001f\u007f<>]/g, " ").replace(/\s+/g, " ").trim()
45
+ if (text.length <= max) return text
46
+ const cut = text.slice(0, max + 1)
47
+ return (cut.includes(" ") ? cut.slice(0, cut.lastIndexOf(" ")) : cut.slice(0, max)).trim()
48
+ }
49
+ const pick = (table, value, fallback) => (Object.hasOwn(table, value ?? "") ? value : fallback)
50
+
51
+ /**
52
+ * A graphic's shape, at every trust boundary (a model's answer, a browser's request, a saved
53
+ * project). Unknown fields go; text is cleaned. Whether its words may be shown is `graphicProblems`' job.
54
+ * @returns {object | null} null when it can't be a graphic
55
+ */
56
+ export function cleanGraphic(raw) {
57
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null
58
+ const kind = pick(GRAPHIC_KINDS, raw.kind, null)
59
+ if (!kind) return null
60
+ const shape = GRAPHIC_KINDS[kind]
61
+ const text = cleanText(raw.text)
62
+ if (!text || (shape.number && !NUMBER.test(text))) return null
63
+ const subtitle = shape.subtitle ? cleanText(raw.subtitle, SUBTITLE_MAX) : ""
64
+ const id = typeof raw.at === "string" && /^[A-Za-z0-9:_-]{1,64}$/.test(raw.at) ? raw.at : null
65
+ return {
66
+ kind,
67
+ style: shape.styles.includes(raw.style) ? raw.style : shape.styles[0],
68
+ text,
69
+ ...(subtitle ? { subtitle } : {}),
70
+ accent: pick(GRAPHIC_ACCENTS, raw.accent, "teal"),
71
+ tone: pick(GRAPHIC_TONES, raw.tone, "dark"),
72
+ font: pick(GRAPHIC_FONTS, raw.font, "sans"),
73
+ ...(id ? { at: id } : {}),
74
+ // Set by the recipe on a graphic an approved plan asked for, so a remake replaces it
75
+ ...(raw.plan === true ? { plan: true } : {}),
76
+ }
77
+ }
78
+
79
+ /** How long a graphic stays up: long enough to read, never long enough to bore. In flicks. */
80
+ export function graphicLength(graphic) {
81
+ const letters = graphic.text.length + (graphic.subtitle?.length ?? 0)
82
+ const seconds = graphic.kind === "intro" || graphic.kind === "end" ? 3.2 : graphic.kind === "lower" ? 4 : Math.min(5, Math.max(1.8, letters / 15 + 1.2))
83
+ return Math.round(seconds * FLICKS)
84
+ }
85
+
86
+ const escape = (text) => String(text).replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c])
87
+ const round = (n) => Math.round(n * 10000) / 10000
88
+ const EASE = "cubic-bezier(.2,.8,.2,1)"
89
+ const SPRING = { damping: 0.6, frequency: 12, ms: 620 }
90
+
91
+ /**
92
+ * @param {{ variables: object, area: { x: number, y: number, w: number, h: number }, output: { width: number, height: number }, duration: number }} input
93
+ * @param {(spring: object) => object[]} springKeyframes motion.js's, handed in so the two files don't import each other
94
+ * @returns {{ css: string, body: string, animations: object[], fit: object }}
95
+ */
96
+ export function buildGraphic({ variables, area, output, duration }, springKeyframes) {
97
+ const graphic = cleanGraphic(variables)
98
+ if (!graphic) throw new EngineFailure("plan", "bad_graphic", "This graphic's variables don't describe a graphic.")
99
+ const { kind, style, text, subtitle } = graphic
100
+ const tone = GRAPHIC_TONES[graphic.tone]
101
+ const accent = GRAPHIC_ACCENTS[graphic.accent]
102
+ const font = GRAPHIC_FONTS[graphic.font]
103
+ const ms = (duration / FLICKS) * 1000
104
+ const floor = Math.ceil(output.height * 0.0205) // QG-09's smallest readable size
105
+ const two = !!subtitle
106
+ const pad = Math.round(area.h * 0.08)
107
+ const big = kind === "stat" || kind === "intro"
108
+ const main = Math.max(floor, Math.round(area.h * (two ? (big ? 0.4 : 0.34) : big ? 0.5 : 0.42)))
109
+ const small = Math.max(floor, Math.round(area.h * 0.19))
110
+ const left = kind === "lower" || kind === "chapter" || kind === "quote"
111
+ const radius = style === "pill" ? Math.round(area.h / 2) : Math.round(area.h * 0.1)
112
+ const bar = Math.max(4, Math.round(area.h * 0.05))
113
+
114
+ const animations = []
115
+ const animate = (id, keyframes, options) => animations.push({ id, keyframes, options: { fill: "both", ...options } })
116
+ // In and out with the whole graphic, so it never pops off on a cut
117
+ const out = Math.min(220, ms * 0.12)
118
+ animate("a", [{ opacity: 1, offset: 0 }, { opacity: 1, offset: round(1 - out / ms) }, { opacity: 0, offset: 1 }], { duration: ms })
119
+ const spring = (id, from, delay = 0) => animate(id, springKeyframes({ ...SPRING, from, to: { y: 0, scale: 1, opacity: 1 } }), { duration: SPRING.ms, delay })
120
+ const grow = (id, axis, delay = 0, length = 380) => animate(id, [{ transform: `scale${axis}(0)` }, { transform: `scale${axis}(1)` }], { duration: length, delay, easing: EASE })
121
+ const fade = (id, delay, length = 300) => animate(id, [{ opacity: 0 }, { opacity: 1 }], { duration: length, delay, easing: "ease-out" })
122
+
123
+ // Room on the left for what leads the text in: the bar or the dot
124
+ const lead = Math.round(pad * 2.2) + (kind === "lower" || kind === "chapter" || kind === "quote" ? bar * 4 : 0)
125
+ let words = escape(text)
126
+ let rule = ""
127
+ if (kind === "title" && style === "slam") {
128
+ spring("t", { scale: 1.6, opacity: 0 })
129
+ rule = "under"
130
+ grow("k", "X", 260)
131
+ } else if (kind === "title" && style === "words") {
132
+ // Each word lands in turn, all in within half a second so the line reads at once
133
+ const parts = text.split(" ")
134
+ const step = Math.min(90, 480 / parts.length)
135
+ words = parts.map((word, i) => `<span id="w${i}" class="w">${escape(word)}</span>`).join(" ")
136
+ fade("t", 0, 120)
137
+ parts.forEach((_, i) => spring(`w${i}`, { y: Math.round(main * 0.6), opacity: 0 }, Math.round(i * step)))
138
+ } else if (kind === "chapter") {
139
+ rule = "side"
140
+ grow("k", "Y", 0, 320)
141
+ animate("t", [{ clipPath: "inset(0 100% 0 0)" }, { clipPath: "inset(0 0 0 0)" }], { duration: 460, delay: 120, easing: EASE })
142
+ } else if (kind === "quote") {
143
+ // No quote-mark glyph: a reader takes one for "66" and the copy gate rightly fails it (found on a real make)
144
+ rule = "side"
145
+ grow("k", "Y", 0, 320)
146
+ spring("t", { y: Math.round(main * 0.5), opacity: 0 }, 90)
147
+ } else if (kind === "lower") {
148
+ rule = style === "pill" ? "dot" : "side"
149
+ animate("t", [{ transform: `translateX(-${Math.round(area.w * 0.12)}px)`, opacity: 0 }, { transform: "translateX(0)", opacity: 1 }], { duration: 480, easing: EASE })
150
+ grow("k", style === "pill" ? "" : "Y", 180, 320)
151
+ } else if (kind === "intro" || kind === "end") {
152
+ rule = "under"
153
+ spring("t", { y: Math.round(main * 0.8), scale: 0.92, opacity: 0 })
154
+ grow("k", "X", 220, 520)
155
+ } else if (kind === "stat") {
156
+ rule = "under"
157
+ spring("t", { scale: 0.5, opacity: 0 })
158
+ grow("k", "X", 200)
159
+ } else spring("t", { y: Math.round(main * 1.2), scale: 0.85, opacity: 0 })
160
+ if (two) fade("u", 320)
161
+
162
+ // The end card's second line is a chip in the accent colour, with the plate's dark ink on it
163
+ const chip = kind === "end" && two
164
+ // QG-09 reads a text's plate from the text's own element, so each line carries the plate's colour
165
+ const css = [
166
+ `#a{position:absolute;left:${area.x}px;top:${area.y}px;width:${area.w}px;height:${area.h}px;display:flex;align-items:center;justify-content:${left ? "flex-start" : "center"}}`,
167
+ `#t{position:relative;box-sizing:border-box;max-width:100%;display:flex;flex-direction:column;align-items:${left ? "flex-start" : "center"};justify-content:center;gap:${Math.round(pad * 0.3)}px;padding:${pad}px ${Math.round(pad * 2.2)}px ${pad}px ${lead}px;background:${tone.plate};border-radius:${radius}px;font-family:${font};color:${tone.ink};text-align:${left ? "left" : "center"};text-wrap:balance;box-shadow:0 ${Math.round(pad * 0.3)}px ${pad * 2}px #00000040}`,
168
+ `#m{display:block;padding:0 .08em;background:${tone.plate};font-size:${main}px;line-height:1.2;font-weight:800;${kind === "quote" ? "font-style:italic;font-weight:600;" : ""}${kind === "stat" ? "font-variant-numeric:tabular-nums;" : ""}}`,
169
+ `.w{display:inline-block}`,
170
+ `#u{display:block;white-space:nowrap;font-size:${small}px;line-height:1.25;font-weight:600;${chip ? `background:${accent};color:${GRAPHIC_TONES.dark.chip};padding:${Math.round(small * 0.18)}px ${Math.round(small * 0.5)}px;border-radius:${Math.round(small * 0.3)}px` : `background:${tone.plate}`}}`,
171
+ rule === "under" ? `#k{height:${bar}px;width:100%;background:${accent};border-radius:${bar}px;transform-origin:${left ? "left" : "center"}}` : "",
172
+ rule === "side" ? `#k{position:absolute;left:0;top:0;bottom:0;width:${bar * 2}px;background:${accent};border-radius:${radius}px 0 0 ${radius}px;transform-origin:top}` : "",
173
+ rule === "dot" ? `#k{position:absolute;left:${Math.round(pad * 1.6)}px;top:50%;width:${bar * 2}px;height:${bar * 2}px;margin-top:-${bar}px;background:${accent};border-radius:50%}` : "",
174
+ ].join("")
175
+ const body = `<div id="a"><div id="t"><span id="m" data-text>${words}</span>${rule === "under" ? `<span id="k"></span>` : ""}${two ? `<span id="u" data-text>${escape(subtitle)}</span>` : ""}${rule === "side" || rule === "dot" ? `<span id="k"></span>` : ""}</div></div>`
176
+ // The main line wraps, then steps down until the plate fits its box, never under the readable floor
177
+ return { css, body, animations, fit: { id: "m", within: "a", min: floor, box: "t" } }
178
+ }
@@ -9,6 +9,8 @@ import { join } from "node:path"
9
9
 
10
10
  import { childEnv } from "../runtime/setup.js"
11
11
  import { confine, confinement, installOf } from "./confine.js"
12
+ import { buildScene, SCENE_VERSION } from "./scenes.js"
13
+ import { buildGraphic, GRAPHIC_VERSION } from "./graphics.js"
12
14
  import { EngineFailure, runTool } from "./tool.js"
13
15
 
14
16
  const FLICKS = 705_600_000
@@ -65,9 +67,10 @@ export function tileSeconds(flicks, fps) {
65
67
  * tile, Kriya's own animations. Non-GSAP, so `data-no-timeline` (EX-01).
66
68
  * @param {{ width: number, height: number, duration: number, css: string, body: string, animations: { id: string, keyframes: object[], options: object }[], fit?: { id: string, within: string, min: number } }} parts duration in flicks;
67
69
  * fit: shrink an element's font, a pixel at a time, until it fits its box (no clock, so every render agrees)
70
+ * fit.box: the element measured against the box, when it isn't the one whose font shrinks (a plate around the text)
68
71
  */
69
72
  export function tileDocument({ width, height, duration, css, body, animations, fit }) {
70
- const fitting = fit ? `{const t=document.getElementById(${scriptJson(fit.id)}),a=document.getElementById(${scriptJson(fit.within)});let s=parseFloat(getComputedStyle(t).fontSize);while((t.offsetHeight>a.clientHeight||t.scrollWidth>a.clientWidth)&&s>${Number(fit.min)}){s-=1;t.style.fontSize=s+"px"}}` : ""
73
+ const fitting = fit ? `{const t=document.getElementById(${scriptJson(fit.id)}),a=document.getElementById(${scriptJson(fit.within)}),b=document.getElementById(${scriptJson(fit.box ?? fit.id)});let s=parseFloat(getComputedStyle(t).fontSize);while((b.offsetHeight>a.clientHeight||b.scrollWidth>a.clientWidth)&&s>${Number(fit.min)}){s-=1;t.style.fontSize=s+"px"}}` : ""
71
74
  const seconds = (duration / FLICKS).toFixed(6)
72
75
  return [
73
76
  "<!doctype html>",
@@ -118,6 +121,24 @@ export const BLOCKS = {
118
121
  animations: [{ id: "t", keyframes: springKeyframes({ ...RISE, from: { y: Math.round(size * 6), scale: 0.8, opacity: 0 }, to: { y: 0, scale: 1, opacity: 1 } }), options: { duration: RISE.ms, fill: "both" } }],
119
122
  }),
120
123
  },
124
+ // A hard term, its definition quoted with its source (EDD-57). The words are never edited
125
+ term: {
126
+ version: 1,
127
+ build: ({ variables, area, size, output }) => {
128
+ const floor = Math.ceil(output.height * 0.0205)
129
+ const quote = Math.max(floor, Math.round(size * 0.72))
130
+ const cite = Math.max(floor, Math.round(size * 0.6))
131
+ return {
132
+ css: `#a{position:absolute;left:${area.x}px;top:${area.y}px;width:${area.w}px;height:${area.h}px;display:flex;align-items:flex-end}#t{width:100%;box-sizing:border-box;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;background:#13292b;color:#f2eadf;padding:${Math.round(size * 0.4)}px ${Math.round(size * 0.55)}px;border-left:${Math.round(size * 0.18)}px solid #ffb347;border-radius:${Math.round(size * 0.2)}px}#t b,#t q,#t small{display:block;background:#13292b}#t b{font-size:${Math.round(size * 1.05)}px;font-weight:800}#t q{font-size:${quote}px;line-height:1.2;margin:${Math.round(size * 0.15)}px 0;quotes:'“' '”'}#t small{font-size:${cite}px;color:#ffb347}`,
133
+ body: `<div id="a"><div id="t"><b data-text>${escapeText(textVar(variables, "text", 60))}</b><q data-text>${escapeText(textVar(variables, "quote", 120))}</q><small data-text>${escapeText(textVar(variables, "source", 40))}</small></div></div>`,
134
+ animations: [{ id: "t", keyframes: springKeyframes({ ...RISE, from: { y: Math.round(size * 2), opacity: 0 }, to: { y: 0, opacity: 1 } }), options: { duration: RISE.ms, fill: "both" } }],
135
+ }
136
+ },
137
+ },
138
+ // An explainer scene (VISUAL_SCENES.md): an opaque cutaway; `placement` is its content box
139
+ scene: { version: SCENE_VERSION, build: (parts) => buildScene(parts, springKeyframes) },
140
+ // The motion kit (MOTION_GRAPHICS.md): a title, strap or card in the box the layout gives it
141
+ graphic: { version: GRAPHIC_VERSION, build: (parts) => buildGraphic(parts, springKeyframes) },
121
142
  }
122
143
 
123
144
  /** A block tile's composition. An unknown block or version is refused, never drawn as something else. */
@@ -129,7 +150,7 @@ export function blockComposition(node, { output, canvas }) {
129
150
  const box = node.placement ?? { x: Math.round(canvas.width * 0.1), y: Math.round(canvas.height * 0.4), w: Math.round(canvas.width * 0.8), h: Math.round(canvas.height * 0.12) }
130
151
  const area = { x: Math.round(box.x * sx), y: Math.round(box.y * sy), w: Math.round(box.w * sx), h: Math.round(box.h * sy) }
131
152
  const size = Math.round(output.height * 0.03)
132
- return tileDocument({ width: output.width, height: output.height, duration: node.duration, ...block.build({ variables: node.variables, area, size }) })
153
+ return tileDocument({ width: output.width, height: output.height, duration: node.duration, ...block.build({ variables: node.variables, area, size, output, duration: node.duration }) })
133
154
  }
134
155
 
135
156
  /* ─────────────────────────────── model-written code ─────────────────────────────── */
@@ -293,7 +314,7 @@ function readBoxes(times) {
293
314
  const r = el.getBoundingClientRect()
294
315
  const style = getComputedStyle(el)
295
316
  const colours = new Set([style.color, ...[...el.querySelectorAll("span")].map((span) => getComputedStyle(span).color)])
296
- return { x: r.x, y: r.y, w: r.width, h: r.height, text: el.textContent, size: parseFloat(style.fontSize), colours: [...colours], plate: style.backgroundColor, clipped: el.scrollWidth > el.clientWidth + 1 || el.scrollHeight > el.clientHeight + 1 }
317
+ return { x: r.x, y: r.y, w: r.width, h: r.height, text: el.textContent, size: parseFloat(style.fontSize), colours: [...colours], plate: style.backgroundColor, stroke: style.webkitTextStrokeColor, strokeWidth: parseFloat(style.webkitTextStrokeWidth) || 0, clipped: el.scrollWidth > el.clientWidth + 1 || el.scrollHeight > el.clientHeight + 1 }
297
318
  })
298
319
  })
299
320
  }