@kriya-ai/harness 0.2.5 → 2.0.0
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/RELEASE_NOTES.md +121 -0
- package/SAFETY.md +181 -0
- package/THIRD_PARTY_NOTICES.md +113 -0
- package/bin/kriya.js +188 -2
- package/bundle/cordis.patch.yml +49 -0
- package/contract/SOURCE.md +3 -3
- package/contract/contract.json +498 -3
- package/contract/schemas/api.json +64 -0
- package/contract/schemas/auth_matrix.json +44 -0
- package/contract/schemas/component_states.json +33 -0
- package/contract/schemas/design_tokens.json +34 -0
- package/contract/schemas/scene_direction.json +82 -0
- package/contract/schemas/threat_model.json +44 -0
- package/package.json +2 -1
- package/plugins/changes/client.js +5 -3
- package/plugins/deploy/index.js +215 -0
- package/plugins/deploy/package.json +13 -0
- package/plugins/grounding/index.js +81 -0
- package/plugins/grounding/lookup.js +373 -0
- package/plugins/grounding/package.json +13 -0
- package/plugins/kriya-tools/index.js +2 -1
- package/plugins/loop/index.js +376 -10
- package/plugins/mcp/index.js +79 -0
- package/plugins/mcp/package.json +13 -0
- package/plugins/mirror/index.js +17 -0
- package/plugins/overview/client.js +5 -2
- package/plugins/preview/client.js +12 -6
- package/plugins/progress/client.js +7 -4
- package/plugins/repo/index.js +230 -0
- package/plugins/repo/package.json +13 -0
- package/plugins/repo/repo.js +348 -0
- package/plugins/runstrip/client.js +426 -0
- package/plugins/runstrip/index.js +301 -0
- package/plugins/runstrip/package.json +23 -0
- package/src/cartridges.js +133 -0
- package/src/contracts.js +130 -0
- package/src/critic.js +78 -0
- package/src/daemon.js +7 -1
- package/src/doctor.js +67 -0
- package/src/edit/core/effects.js +185 -0
- package/src/edit/core/ffmpeg.js +65 -6
- package/src/edit/core/layout.js +46 -1
- package/src/edit/core/ops.js +169 -2
- package/src/edit/core/plan.js +65 -9
- package/src/edit/core/project.d.ts +24 -0
- package/src/edit/core/project.js +64 -0
- package/src/edit/core/solver.js +34 -6
- package/src/edit/core/style-brief.js +211 -0
- package/src/edit/core/style-packs.js +57 -0
- package/src/edit/core/type-kit.js +173 -0
- package/src/edit/director/ask.js +37 -3
- package/src/edit/director/assembly.js +829 -0
- package/src/edit/director/continuity.js +9 -1
- package/src/edit/director/custom-motion.js +88 -0
- package/src/edit/director/graphics.js +44 -10
- package/src/edit/director/intent.js +125 -0
- package/src/edit/director/mentions.js +52 -0
- package/src/edit/director/plan.js +43 -11
- package/src/edit/director/revise.js +132 -9
- package/src/edit/director/viewer.js +136 -0
- package/src/edit/director/watch-fix.js +119 -0
- package/src/edit/engine/captions.js +110 -5
- package/src/edit/engine/confine.js +81 -4
- package/src/edit/engine/custom.js +243 -0
- package/src/edit/engine/dna2.js +893 -0
- package/src/edit/engine/fonts.js +218 -0
- package/src/edit/engine/graphics.js +271 -10
- package/src/edit/engine/index.js +14 -5
- package/src/edit/engine/motion.js +148 -13
- package/src/edit/engine/music-bed.js +59 -1
- package/src/edit/engine/packs.js +11 -0
- package/src/edit/engine/reference2.js +26 -0
- package/src/edit/engine/sfx.js +56 -1
- package/src/edit/engine/tool.js +21 -5
- package/src/edit/gates/assembly.js +194 -0
- package/src/edit/gates/copy.js +7 -4
- package/src/edit/gates/index.js +72 -7
- package/src/edit/gates/reference.js +115 -0
- package/src/edit/gates/tile.js +96 -0
- package/src/edit/host/client.js +4 -3
- package/src/edit/host/clips.js +33 -0
- package/src/edit/host/jobs.js +9 -3
- package/src/edit/host/layers.js +134 -0
- package/src/edit/host/main.js +10 -3
- package/src/edit/host/paths.js +21 -3
- package/src/edit/host/preview.js +108 -0
- package/src/edit/host/projects.js +443 -34
- package/src/edit/host/server.js +235 -20
- package/src/edit/host/tavi.js +77 -0
- package/src/edit/loop/make.js +28 -3
- package/src/edit/recipes/assembly.js +352 -0
- package/src/edit/recipes/graphic-clips.js +4 -2
- package/src/edit/recipes/openings.js +36 -0
- package/src/edit/recipes/reel.js +104 -14
- package/src/edit/recipes/reference-look.js +29 -0
- package/src/edit/recipes/short-from-long.js +3 -3
- package/src/edit/recipes/sound.js +71 -0
- package/src/edit/runtime/cli.js +26 -5
- package/src/edit/runtime/fetch.js +4 -4
- package/src/edit/runtime/licences.js +7 -1
- package/src/explore.js +103 -0
- package/src/failure.js +1 -1
- package/src/gate-commands.js +114 -0
- package/src/gates/api.js +127 -0
- package/src/gates/commands.js +111 -0
- package/src/gates/detectors.js +370 -0
- package/src/gates/http.js +62 -0
- package/src/gates/index.js +196 -0
- package/src/gates/page.js +264 -0
- package/src/gates/sast.js +64 -0
- package/src/gates/stack.js +110 -0
- package/src/gates/tenant.js +162 -0
- package/src/gates/three.js +407 -0
- package/src/gates/ui.js +111 -0
- package/src/launch.js +15 -3
- package/src/loop.js +199 -7
- package/src/mcp.js +126 -0
- package/src/milestones.js +188 -0
- package/src/modes.js +32 -0
- package/src/orchestra.js +43 -0
- package/src/outcomes.js +88 -0
- package/src/profiles.js +5 -0
- package/src/receipts.js +238 -0
- package/src/release.js +356 -0
- package/src/runstrip.js +122 -0
- package/src/stack.js +120 -0
- package/src/verify.js +67 -20
- package/studio/dist/fonts/fraunces.woff2 +0 -0
- package/studio/dist/fonts/geist.woff2 +0 -0
- package/studio/dist/fonts/jetbrains-mono.woff2 +0 -0
- package/studio/dist/studio.css +449 -1
- package/studio/dist/studio.js +3 -3
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Fonts that ship (TP7, CRAFT_UPGRADE §5.1, EDD-67): the Media Runtime's pack-fonts, each
|
|
2
|
+
// file pinned by hash in the signed manifest and licensed OFL-1.1 (checked per item, EQ-18).
|
|
3
|
+
// A composition names a font by id only (`url("kriya-font:<id>")`); the renderer puts the
|
|
4
|
+
// file in as data, so the same tile draws the same on every computer and in the Studio, and
|
|
5
|
+
// a computer without the pack keeps the system stacks, with a note, never a failed make.
|
|
6
|
+
// Script picks the font: each run of a line goes to a family that has it (EQ-17).
|
|
7
|
+
|
|
8
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
9
|
+
import { join } from "node:path"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The fonts this client knows, by the manifest's artifact id. `family` is the CSS name
|
|
13
|
+
* Kriya gives it; `scripts` what it is chosen for; `line` the line height its box needs; `system` the stack that stands in
|
|
14
|
+
* when the pack isn't installed. Data only: no path, URL or price.
|
|
15
|
+
*/
|
|
16
|
+
export const FONTS = {
|
|
17
|
+
"font-inter": { family: "Kriya Inter", role: "sans", scripts: ["latin"], line: 1.22, system: "'Helvetica Neue',Helvetica,Arial,sans-serif" },
|
|
18
|
+
"font-oswald": { family: "Kriya Oswald", role: "condensed", scripts: ["latin"], line: 1.49, system: "'Avenir Next Condensed','Arial Narrow','Helvetica Neue',Arial,sans-serif" },
|
|
19
|
+
"font-montserrat": { family: "Kriya Montserrat", role: "geometric", scripts: ["latin"], line: 1.22, system: "'Avenir Next',Futura,'Helvetica Neue',Arial,sans-serif" },
|
|
20
|
+
"font-lora": { family: "Kriya Lora", role: "serif", scripts: ["latin"], line: 1.28, system: "Georgia,'Times New Roman',serif" },
|
|
21
|
+
"font-jetbrains-mono": { family: "Kriya JetBrains Mono", role: "mono", scripts: ["latin"], line: 1.32, system: "'SF Mono',Menlo,Consolas,'Courier New',monospace" },
|
|
22
|
+
"font-caveat": { family: "Kriya Caveat", role: "hand", scripts: ["latin"], line: 1.26, system: "'Bradley Hand','Segoe Print','Comic Sans MS',cursive" },
|
|
23
|
+
"font-noto-sans-devanagari": { family: "Kriya Noto Sans Devanagari", role: "script", scripts: ["devanagari"], line: 1.31, system: "'Kohinoor Devanagari','Noto Sans Devanagari','Nirmala UI',sans-serif" },
|
|
24
|
+
"font-noto-sans-telugu": { family: "Kriya Noto Sans Telugu", role: "script", scripts: ["telugu"], line: 1.36, system: "'Kohinoor Telugu','Noto Sans Telugu','Nirmala UI',sans-serif" },
|
|
25
|
+
"font-noto-sans-tamil": { family: "Kriya Noto Sans Tamil", role: "script", scripts: ["tamil"], line: 1.24, system: "'Tamil Sangam MN','Noto Sans Tamil','Nirmala UI',sans-serif" },
|
|
26
|
+
"font-noto-sans-kannada": { family: "Kriya Noto Sans Kannada", role: "script", scripts: ["kannada"], line: 1.35, system: "'Kannada Sangam MN','Noto Sans Kannada','Nirmala UI',sans-serif" },
|
|
27
|
+
"font-noto-sans-malayalam": { family: "Kriya Noto Sans Malayalam", role: "script", scripts: ["malayalam"], line: 1.25, system: "'Malayalam Sangam MN','Noto Sans Malayalam','Nirmala UI',sans-serif" },
|
|
28
|
+
"font-noto-sans-bengali": { family: "Kriya Noto Sans Bengali", role: "script", scripts: ["bengali"], line: 1.33, system: "'Kohinoor Bangla','Noto Sans Bengali','Nirmala UI',sans-serif" },
|
|
29
|
+
"font-noto-sans-gujarati": { family: "Kriya Noto Sans Gujarati", role: "script", scripts: ["gujarati"], line: 1.31, system: "'Kohinoor Gujarati','Noto Sans Gujarati','Nirmala UI',sans-serif" },
|
|
30
|
+
"font-noto-sans-gurmukhi": { family: "Kriya Noto Sans Gurmukhi", role: "script", scripts: ["gurmukhi"], line: 1.31, system: "'Gurmukhi MN','Noto Sans Gurmukhi','Nirmala UI',sans-serif" },
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The OFL-1.1 notice of each font, for THIRD_PARTY_NOTICES and the licence test (ET-LIC-01). */
|
|
34
|
+
export const FONT_LICENCES = {
|
|
35
|
+
"font-inter": "Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)",
|
|
36
|
+
"font-oswald": "Copyright 2016 The Oswald Project Authors (https://github.com/googlefonts/OswaldFont)",
|
|
37
|
+
"font-montserrat": "Copyright 2024 The Montserrat.Git Project Authors (https://github.com/JulietaUla/Montserrat.git)",
|
|
38
|
+
"font-lora": "Copyright 2011 The Lora Project Authors (https://github.com/cyrealtype/Lora-Cyrillic), with Reserved Font Name \"Lora\".",
|
|
39
|
+
"font-jetbrains-mono": "Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)",
|
|
40
|
+
"font-caveat": "Copyright 2014 The Caveat Project Authors (https://github.com/googlefonts/caveat)",
|
|
41
|
+
"font-noto-sans-devanagari": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/devanagari)",
|
|
42
|
+
"font-noto-sans-telugu": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/telugu)",
|
|
43
|
+
"font-noto-sans-tamil": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/tamil)",
|
|
44
|
+
"font-noto-sans-kannada": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/kannada)",
|
|
45
|
+
"font-noto-sans-malayalam": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/malayalam)",
|
|
46
|
+
"font-noto-sans-bengali": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/bengali)",
|
|
47
|
+
"font-noto-sans-gujarati": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/gujarati)",
|
|
48
|
+
"font-noto-sans-gurmukhi": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/gurmukhi)",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const FONT_PACK = "pack-fonts"
|
|
52
|
+
|
|
53
|
+
/** The scripts a font is shipped for, in the order a mixed line's chain tries them. */
|
|
54
|
+
export const SCRIPTS = ["latin", "devanagari", "telugu", "tamil", "kannada", "malayalam", "bengali", "gujarati", "gurmukhi"]
|
|
55
|
+
const SCRIPT_TEST = {
|
|
56
|
+
latin: /\p{Script=Latin}/u,
|
|
57
|
+
devanagari: /\p{Script=Devanagari}/u,
|
|
58
|
+
telugu: /\p{Script=Telugu}/u,
|
|
59
|
+
tamil: /\p{Script=Tamil}/u,
|
|
60
|
+
kannada: /\p{Script=Kannada}/u,
|
|
61
|
+
malayalam: /\p{Script=Malayalam}/u,
|
|
62
|
+
bengali: /\p{Script=Bengali}/u,
|
|
63
|
+
gujarati: /\p{Script=Gujarati}/u,
|
|
64
|
+
gurmukhi: /\p{Script=Gurmukhi}/u,
|
|
65
|
+
}
|
|
66
|
+
const SHARED = /[\p{Script=Common}\p{Script=Inherited}]/u
|
|
67
|
+
/** The shipped font for each Indic script. */
|
|
68
|
+
export const SCRIPT_FONTS = Object.fromEntries(Object.entries(FONTS).filter(([, f]) => f.role === "script").map(([id, f]) => [f.scripts[0], id]))
|
|
69
|
+
|
|
70
|
+
/** One character's script: a shipped one, "common" (spaces, digits, marks shared by all) or "other". */
|
|
71
|
+
export function scriptOfChar(char) {
|
|
72
|
+
if (SHARED.test(char)) return "common"
|
|
73
|
+
return SCRIPTS.find((script) => SCRIPT_TEST[script].test(char)) ?? "other"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* A line as runs of one script each; shared characters join the run they sit in.
|
|
78
|
+
* @returns {{ script: string, text: string }[]}
|
|
79
|
+
*/
|
|
80
|
+
export function scriptRuns(text) {
|
|
81
|
+
const runs = []
|
|
82
|
+
let pending = ""
|
|
83
|
+
for (const char of String(text)) {
|
|
84
|
+
const script = scriptOfChar(char)
|
|
85
|
+
if (script === "common") {
|
|
86
|
+
if (runs.length) runs.at(-1).text += char
|
|
87
|
+
else pending += char
|
|
88
|
+
} else if (runs.at(-1)?.script === script) runs.at(-1).text += char
|
|
89
|
+
else {
|
|
90
|
+
runs.push({ script, text: pending + char })
|
|
91
|
+
pending = ""
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (pending) runs.push({ script: "common", text: pending })
|
|
95
|
+
return runs
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The scripts a text needs, beyond the shared characters. */
|
|
99
|
+
export const scriptsIn = (text) => [...new Set(scriptRuns(text).map((run) => run.script).filter((s) => s !== "common"))]
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The font ids a text needs with `primary` as its face: the face, then a shipped font for
|
|
103
|
+
* each other script in it. A script with no shipped font ("other") adds none: the system
|
|
104
|
+
* stack draws it, and the glyph check says so.
|
|
105
|
+
*/
|
|
106
|
+
export function fontsFor(text, primary) {
|
|
107
|
+
const ids = [primary]
|
|
108
|
+
for (const script of scriptsIn(text)) {
|
|
109
|
+
const id = script === "latin" ? null : SCRIPT_FONTS[script]
|
|
110
|
+
if (id && !ids.includes(id)) ids.push(id)
|
|
111
|
+
}
|
|
112
|
+
return ids
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The line height a text needs (TP7): each shipped font's box (its hhea ascent and descent, measured
|
|
117
|
+
* from the pinned file and rounded up, SPIKES §6) is taller than a 1.18 line for most of them, and
|
|
118
|
+
* Chrome counts the box past the line as overflow. The look's own height when none is taller.
|
|
119
|
+
*/
|
|
120
|
+
export function lineFor(text, primary, base) {
|
|
121
|
+
return Math.max(base, ...fontsFor(text, primary).map((id) => FONTS[id]?.line ?? 0))
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The CSS font-family for a text: the shipped families it needs, in order, then the
|
|
126
|
+
* system stacks standing in for each, so a missing pack degrades to today's look.
|
|
127
|
+
* @param {string} text
|
|
128
|
+
* @param {string} primary a font id of FONTS
|
|
129
|
+
* @param {{ has(id: string): boolean } | null} installed the pack's fonts here; null: assume all
|
|
130
|
+
*/
|
|
131
|
+
export function fontStackFor(text, primary, installed = null) {
|
|
132
|
+
const ids = fontsFor(text, FONTS[primary] ? primary : "font-inter")
|
|
133
|
+
const shipped = ids.filter((id) => !installed || installed.has(id)).map((id) => `'${FONTS[id].family}'`)
|
|
134
|
+
return [...shipped, ...ids.map((id) => FONTS[id].system)].join(",")
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The family names a stack would draw with if no system font existed: what ET-TY-M1 renders the second time. */
|
|
138
|
+
export const shippedOnly = (stack) => stack.split(",").filter((name) => /^'Kriya /.test(name)).join(",") || "monospace"
|
|
139
|
+
|
|
140
|
+
/** @font-face rules naming each font by id; the renderer fills in the file (withFonts). */
|
|
141
|
+
export function fontFaces(ids) {
|
|
142
|
+
return [...new Set(ids)]
|
|
143
|
+
.filter((id) => FONTS[id])
|
|
144
|
+
.map((id) => `@font-face{font-family:'${FONTS[id].family}';src:url("kriya-font:${id}") format("truetype");font-weight:100 900;font-display:block}`)
|
|
145
|
+
.join("")
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const FACE = /@font-face\{font-family:'[^']+';src:url\("kriya-font:([a-z0-9-]+)"\)[^}]*\}/g
|
|
149
|
+
|
|
150
|
+
/** The font ids a composition asks for. */
|
|
151
|
+
export const fontsAsked = (html) => [...String(html).matchAll(FACE)].map((m) => m[1])
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* A composition with each asked font's file put in as data. A font this computer
|
|
155
|
+
* doesn't have is dropped from the page, so its system stack draws.
|
|
156
|
+
* @param {string} html
|
|
157
|
+
* @param {Map<string, string> | undefined} files font id → path, from installedFonts()
|
|
158
|
+
*/
|
|
159
|
+
export function withFonts(html, files) {
|
|
160
|
+
if (!html.includes("kriya-font:")) return html
|
|
161
|
+
return html.replace(FACE, (rule, id) => {
|
|
162
|
+
const path = files?.get(id)
|
|
163
|
+
if (!path) return ""
|
|
164
|
+
return rule.replace(`kriya-font:${id}`, `data:font/ttf;base64,${readFileSync(path).toString("base64")}`)
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The pack's fonts installed in a runtime: id → file. Only from a pack that finished
|
|
170
|
+
* installing, and only the files its signed manifest names.
|
|
171
|
+
* @param {{ dir: string, manifest: object } | null} runtime
|
|
172
|
+
* @returns {Map<string, string>}
|
|
173
|
+
*/
|
|
174
|
+
export function installedFonts(runtime, platform = `${process.platform}-${process.arch}`) {
|
|
175
|
+
const out = new Map()
|
|
176
|
+
const offered = runtime?.manifest?.platforms?.[platform]?.packs?.[FONT_PACK]?.artifacts ?? []
|
|
177
|
+
const dir = runtime && join(runtime.dir, "packs", FONT_PACK)
|
|
178
|
+
if (!dir || !existsSync(join(dir, ".complete"))) return out
|
|
179
|
+
for (const artifact of offered) {
|
|
180
|
+
const path = join(dir, artifact.id, artifact.entry)
|
|
181
|
+
if (FONTS[artifact.id] && existsSync(path)) out.set(artifact.id, path)
|
|
182
|
+
}
|
|
183
|
+
return out
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* ─────────────────────────────── the glyph check ─────────────────────────────── */
|
|
187
|
+
|
|
188
|
+
/** Scripts the OCR helper reads, and the language it reads each with (TPX-05, SPIKES §6). */
|
|
189
|
+
export const OCR_READS = { latin: "en-US", devanagari: "hi-IN" }
|
|
190
|
+
|
|
191
|
+
/** Grapheme clusters a text should show, spaces aside: what the shaped count is compared to. */
|
|
192
|
+
export function clusterCount(text) {
|
|
193
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" })
|
|
194
|
+
return [...segmenter.segment(String(text))].filter(({ segment }) => /\S/u.test(segment)).length
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* QG-10 where no reader reads the script (CRAFT §5.1): every glyph drawn by a font, none by
|
|
199
|
+
* the last-resort box font; with the pack installed, none by a system font either; and as
|
|
200
|
+
* many clusters drawn as the text has.
|
|
201
|
+
* @param {{ text: string, fonts: { family: string, custom: boolean, glyphs: number }[], drawn: number, missing?: number }} report from checkGlyphs, per text element
|
|
202
|
+
* @param {{ shipped: boolean }} expect shipped: the pack's fonts were installed for this render
|
|
203
|
+
* @returns {string[]} what is wrong; empty when it holds
|
|
204
|
+
*/
|
|
205
|
+
export function glyphProblems({ text, fonts, drawn, missing: boxes = 0 }, { shipped }) {
|
|
206
|
+
const problems = []
|
|
207
|
+
const missing = fonts.filter((f) => /last ?resort/i.test(f.family))
|
|
208
|
+
if (missing.length) problems.push(`${missing.reduce((n, f) => n + f.glyphs, 0)} missing glyph(s) in "${text}"`)
|
|
209
|
+
// A cluster drawn as its font's empty box (readClusters' canvas check): no font in the stack has it
|
|
210
|
+
else if (boxes > 0) problems.push(`${boxes} missing glyph(s) in "${text}", drawn as an empty box`)
|
|
211
|
+
if (shipped) {
|
|
212
|
+
const system = fonts.filter((f) => !f.custom && !/last ?resort/i.test(f.family))
|
|
213
|
+
if (system.length) problems.push(`"${text}" drew with ${system.map((f) => f.family).join(", ")}, not the shipped fonts`)
|
|
214
|
+
}
|
|
215
|
+
const expected = clusterCount(text)
|
|
216
|
+
if (drawn !== expected) problems.push(`"${text}" shows ${drawn} of its ${expected} clusters`)
|
|
217
|
+
return problems
|
|
218
|
+
}
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
// gives it, clear of the speaker's face and the captions, and its words are `text` and
|
|
6
6
|
// `subtitle`, so the copy and contrast gates read it as they read a title.
|
|
7
7
|
|
|
8
|
+
import { REGIONS } from "../core/layout.js"
|
|
9
|
+
import { regionOf } from "../core/effects.js"
|
|
10
|
+
import { against, readableColors } from "../core/type-kit.js"
|
|
11
|
+
import { fontFaces, fontsFor, fontStackFor, lineFor } from "./fonts.js"
|
|
8
12
|
import { EngineFailure } from "./tool.js"
|
|
9
13
|
|
|
10
14
|
const FLICKS = 705_600_000
|
|
@@ -24,6 +28,28 @@ export const GRAPHIC_KINDS = {
|
|
|
24
28
|
}
|
|
25
29
|
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
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Motion kit 2 (TP7, CRAFT_UPGRADE §5.4, EDD-67), offered only with editing.typeKit on. Drawn
|
|
33
|
+
* by code under MOTION_GRAPHICS §3.2's rules: the words are the speaker's or the person's own
|
|
34
|
+
* (`person`: typed by the person only), code places and times them. The progress and chapter
|
|
35
|
+
* bars and the logo bug span the cut, so they are FFmpeg overlays from the type kit, not kinds.
|
|
36
|
+
*/
|
|
37
|
+
export const KIT2_KINDS = {
|
|
38
|
+
card: { label: "Full-frame card", styles: ["title", "quote"], subtitle: true, when: "a few words of what is said, alone on the whole frame, to open a part or land a line" },
|
|
39
|
+
list: { label: "List", styles: ["steps", "bullets"], subtitle: false, steps: true, when: "steps or points the speaker lists, in `steps`, each arriving on its word; `text` is the list's heading" },
|
|
40
|
+
callout: { label: "Callout", styles: ["ring", "box", "arrow"], subtitle: false, point: true, optionalText: true, textMax: 24, when: "a mark at a point the person chose, or on the speaker's face, with an optional short label" },
|
|
41
|
+
count: { label: "Counting number", styles: ["count"], subtitle: true, number: true, when: "one number the speaker says, counted up to, as digits in `text`, and what it counts in `subtitle`" },
|
|
42
|
+
handle: { label: "Handle strap", styles: ["strap"], subtitle: false, person: true, textMax: 32, when: "the person's own handle, only as they typed it" },
|
|
43
|
+
cta: { label: "Call to action", styles: ["strap"], subtitle: true, person: true, when: "the person's own call to action, only as they typed it" },
|
|
44
|
+
frame: { label: "Screen frame", styles: ["plain"], subtitle: false, noText: true, when: "a plain frame round a screen recording; no device and no brand's shape" },
|
|
45
|
+
}
|
|
46
|
+
/** Four more name straps. */
|
|
47
|
+
export const LOWER_STYLES_2 = ["underline", "box", "split", "tag"]
|
|
48
|
+
export const ALL_GRAPHIC_KINDS = { ...GRAPHIC_KINDS, lower: { ...GRAPHIC_KINDS.lower, styles: [...GRAPHIC_KINDS.lower.styles, ...LOWER_STYLES_2] }, ...KIT2_KINDS }
|
|
49
|
+
export const STYLE_LABELS_2 = { title: "Title", quote: "Quote", steps: "Numbered", bullets: "Bullets", ring: "Ring", box: "Box", arrow: "Arrow", count: "Count up", strap: "Strap", plain: "Plain", underline: "Underline", split: "Split", tag: "Tag" }
|
|
50
|
+
export const STEPS_MAX = 5
|
|
51
|
+
export const STEP_MAX = 32
|
|
52
|
+
|
|
27
53
|
/** 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
54
|
export const GRAPHIC_ACCENTS = { teal: "#4fd1c5", yellow: "#ffd23f", amber: "#ffb347", pink: "#ff7ab6", white: "#ffffff" }
|
|
29
55
|
export const GRAPHIC_TONES = { dark: { plate: "#13292b", ink: "#f2eadf", chip: "#13292b" }, light: { plate: "#f6f1e7", ink: "#1c2530", chip: "#1c2530" } }
|
|
@@ -53,13 +79,21 @@ const pick = (table, value, fallback) => (Object.hasOwn(table, value ?? "") ? va
|
|
|
53
79
|
* project). Unknown fields go; text is cleaned. Whether its words may be shown is `graphicProblems`' job.
|
|
54
80
|
* @returns {object | null} null when it can't be a graphic
|
|
55
81
|
*/
|
|
56
|
-
export function cleanGraphic(raw) {
|
|
82
|
+
export function cleanGraphic(raw, kinds = GRAPHIC_KINDS) {
|
|
57
83
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null
|
|
58
|
-
const kind = pick(
|
|
84
|
+
const kind = pick(kinds, raw.kind, null)
|
|
59
85
|
if (!kind) return null
|
|
60
|
-
const shape =
|
|
61
|
-
const text = cleanText(raw.text)
|
|
62
|
-
if (!text || (shape.number && !NUMBER.test(text))) return null
|
|
86
|
+
const shape = kinds[kind]
|
|
87
|
+
const text = shape.noText ? "" : cleanText(raw.text, shape.textMax ?? TEXT_MAX)
|
|
88
|
+
if ((!text && !shape.noText && !shape.optionalText) || (shape.number && !NUMBER.test(text))) return null
|
|
89
|
+
// Kit 2's own fields (TP7), only on the kinds that have them
|
|
90
|
+
const steps = shape.steps && Array.isArray(raw.steps) ? raw.steps.map((step) => cleanText(step, STEP_MAX)).filter(Boolean).slice(0, STEPS_MAX) : null
|
|
91
|
+
if (shape.steps && (!steps || steps.length < 2)) return null
|
|
92
|
+
const stepAt = steps && Array.isArray(raw.stepAt) && raw.stepAt.length === steps.length && raw.stepAt.every((t) => Number.isSafeInteger(t) && t >= 0 && t <= 60_000) ? raw.stepAt : null
|
|
93
|
+
const point = shape.point && raw.point && Number.isSafeInteger(raw.point.x) && Number.isSafeInteger(raw.point.y) && raw.point.x >= 0 && raw.point.y >= 0 && raw.point.x <= 10_000 && raw.point.y <= 10_000 ? { x: raw.point.x, y: raw.point.y } : null
|
|
94
|
+
// TP9: the box the person drew on the frame, in thousandths of it; the callout is drawn round exactly that
|
|
95
|
+
const mark = shape.point ? cleanMarkBox(raw.mark) : null
|
|
96
|
+
const corner = kind === "handle" && ["tl", "tr", "bl", "br"].includes(raw.corner) ? raw.corner : null
|
|
63
97
|
const subtitle = shape.subtitle ? cleanText(raw.subtitle, SUBTITLE_MAX) : ""
|
|
64
98
|
const id = typeof raw.at === "string" && /^[A-Za-z0-9:_-]{1,64}$/.test(raw.at) ? raw.at : null
|
|
65
99
|
return {
|
|
@@ -71,13 +105,25 @@ export function cleanGraphic(raw) {
|
|
|
71
105
|
tone: pick(GRAPHIC_TONES, raw.tone, "dark"),
|
|
72
106
|
font: pick(GRAPHIC_FONTS, raw.font, "sans"),
|
|
73
107
|
...(id ? { at: id } : {}),
|
|
108
|
+
...(steps ? { steps } : {}),
|
|
109
|
+
...(stepAt ? { stepAt } : {}),
|
|
110
|
+
...(point ? { point } : {}),
|
|
111
|
+
...(mark ? { mark } : {}),
|
|
112
|
+
...(corner ? { corner } : {}),
|
|
74
113
|
// Set by the recipe on a graphic an approved plan asked for, so a remake replaces it
|
|
75
114
|
...(raw.plan === true ? { plan: true } : {}),
|
|
76
115
|
}
|
|
77
116
|
}
|
|
78
117
|
|
|
118
|
+
/**
|
|
119
|
+
* A box drawn on the frame (TP9, CRAFT_UPGRADE §7): whole thousandths of the frame, inside it,
|
|
120
|
+
* at least MARK_MIN on each side. @returns {{ x: number, y: number, w: number, h: number } | null}
|
|
121
|
+
*/
|
|
122
|
+
export const cleanMarkBox = regionOf
|
|
123
|
+
|
|
79
124
|
/** How long a graphic stays up: long enough to read, never long enough to bore. In flicks. */
|
|
80
125
|
export function graphicLength(graphic) {
|
|
126
|
+
if (KIT2_KINDS[graphic.kind]) return kit2Length(graphic)
|
|
81
127
|
const letters = graphic.text.length + (graphic.subtitle?.length ?? 0)
|
|
82
128
|
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
129
|
return Math.round(seconds * FLICKS)
|
|
@@ -93,13 +139,16 @@ const SPRING = { damping: 0.6, frequency: 12, ms: 620 }
|
|
|
93
139
|
* @param {(spring: object) => object[]} springKeyframes motion.js's, handed in so the two files don't import each other
|
|
94
140
|
* @returns {{ css: string, body: string, animations: object[], fit: object }}
|
|
95
141
|
*/
|
|
96
|
-
export function buildGraphic({ variables, area, output, duration }, springKeyframes) {
|
|
97
|
-
const graphic = cleanGraphic(variables)
|
|
142
|
+
export function buildGraphic({ variables, area, output, duration, type }, springKeyframes) {
|
|
143
|
+
const graphic = cleanGraphic(variables, ALL_GRAPHIC_KINDS)
|
|
98
144
|
if (!graphic) throw new EngineFailure("plan", "bad_graphic", "This graphic's variables don't describe a graphic.")
|
|
145
|
+
if (KIT2_KINDS[graphic.kind] || LOWER_STYLES_2.includes(graphic.style)) return buildKit2({ graphic, area, output, duration, type }, springKeyframes)
|
|
99
146
|
const { kind, style, text, subtitle } = graphic
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
const
|
|
147
|
+
// TP7: with a type kit, its faces and the person's colours, held readable; without one, as before
|
|
148
|
+
const kit = type ? kitLook(graphic, type, [text, subtitle].join(" ")) : null
|
|
149
|
+
const tone = kit?.tone ?? GRAPHIC_TONES[graphic.tone]
|
|
150
|
+
const accent = kit?.accent ?? GRAPHIC_ACCENTS[graphic.accent]
|
|
151
|
+
const font = kit?.font ?? GRAPHIC_FONTS[graphic.font]
|
|
103
152
|
const ms = (duration / FLICKS) * 1000
|
|
104
153
|
const floor = Math.ceil(output.height * 0.0205) // QG-09's smallest readable size
|
|
105
154
|
const two = !!subtitle
|
|
@@ -163,6 +212,7 @@ export function buildGraphic({ variables, area, output, duration }, springKeyfra
|
|
|
163
212
|
const chip = kind === "end" && two
|
|
164
213
|
// QG-09 reads a text's plate from the text's own element, so each line carries the plate's colour
|
|
165
214
|
const css = [
|
|
215
|
+
kit?.faces ?? "",
|
|
166
216
|
`#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
217
|
`#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
218
|
`#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;" : ""}}`,
|
|
@@ -176,3 +226,214 @@ export function buildGraphic({ variables, area, output, duration }, springKeyfra
|
|
|
176
226
|
// The main line wraps, then steps down until the plate fits its box, never under the readable floor
|
|
177
227
|
return { css, body, animations, fit: { id: "m", within: "a", min: floor, box: "t" } }
|
|
178
228
|
}
|
|
229
|
+
|
|
230
|
+
/* ─────────────────────────────── TP7: the kit and motion kit 2 ─────────────────────────────── */
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* A graphic's faces and colours from the project's type kit (CRAFT §5.2): the heading face,
|
|
234
|
+
* the person's colours made to hold 4.5:1 on the plate, and the fonts to ask the renderer for.
|
|
235
|
+
*/
|
|
236
|
+
function kitLook(graphic, type, text) {
|
|
237
|
+
const tone = GRAPHIC_TONES[graphic.tone]
|
|
238
|
+
const colors = readableColors({ text: type.colors?.text ?? tone.ink, accent: type.colors?.accent ?? GRAPHIC_ACCENTS[graphic.accent], plate: type.colors?.plate ?? tone.plate }, { plate: true })
|
|
239
|
+
const face = type.heading
|
|
240
|
+
return {
|
|
241
|
+
tone: { plate: colors.plate, ink: colors.text, chip: against(colors.accent) },
|
|
242
|
+
accent: colors.accent,
|
|
243
|
+
font: `${fontStackFor(text, face.font, type.shipped ? null : new Set())};${face.case === "upper" ? "text-transform:uppercase;" : ""}${face.tracking ? `letter-spacing:${face.tracking}em;` : ""}font-synthesis:none`,
|
|
244
|
+
// A script whose font needs a taller line gets it on every line of text, over the kind's own (SPIKES §6)
|
|
245
|
+
faces: `${type.shipped ? fontFaces(fontsFor(text, face.font)) : ""}${lineFor(text, face.font, 0) > 0 ? `#stage [data-text],#stage .i{line-height:${lineFor(text, face.font, 0)}}#stage #u{white-space:normal}` : ""}`,
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function kit2Length(graphic) {
|
|
250
|
+
if (graphic.kind === "frame") return Math.round(6 * FLICKS)
|
|
251
|
+
if (graphic.kind === "list") return Math.round(Math.min(10, Math.max(3.5, 1.2 + graphic.steps.length * 1.4)) * FLICKS)
|
|
252
|
+
if (graphic.kind === "card") return Math.round(Math.min(5, Math.max(2.4, (graphic.text.length + (graphic.subtitle?.length ?? 0)) / 14 + 1.2)) * FLICKS)
|
|
253
|
+
if (graphic.kind === "handle" || graphic.kind === "cta") return Math.round(3.5 * FLICKS)
|
|
254
|
+
return Math.round(Math.min(5, Math.max(2, (graphic.text.length + (graphic.subtitle?.length ?? 0)) / 15 + 1.4)) * FLICKS)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// A number's steps on the way up: the same digits, grouping and decimals as the said number, eased out
|
|
258
|
+
const COUNT = /^([₹$€£]?)(\d{1,3}(?:,\d{2,3})+|\d{1,9})(\.\d{1,3})?(\s?(?:%|[A-Za-z₹$€£]{1,8})?)$/
|
|
259
|
+
export function countSteps(text, steps = 10) {
|
|
260
|
+
const m = COUNT.exec(text)
|
|
261
|
+
if (!m) return null
|
|
262
|
+
const [, before, whole, decimals = "", after] = m
|
|
263
|
+
const target = Number(whole.replaceAll(",", ""))
|
|
264
|
+
const indian = /^\d{1,2}(?:,\d\d)+,\d{3}$/.test(whole)
|
|
265
|
+
const format = (n) => (whole.includes(",") ? n.toLocaleString(indian ? "en-IN" : "en-US") : String(n))
|
|
266
|
+
const out = []
|
|
267
|
+
for (let i = 0; i < steps; i++) out.push(`${before}${format(Math.round(target * (1 - (1 - i / steps) ** 3)))}${decimals ? `.${"0".repeat(decimals.length - 1)}` : ""}${after}`)
|
|
268
|
+
return [...out, text]
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Motion kit 2's drawing: same rules as buildGraphic (words escaped, WAAPI only, each line on
|
|
273
|
+
* the plate's colour so QG-09 reads it, a fit that never goes under the readable floor).
|
|
274
|
+
*/
|
|
275
|
+
function buildKit2({ graphic, area, output, duration, type }, springKeyframes) {
|
|
276
|
+
const { kind, style, text, subtitle } = graphic
|
|
277
|
+
const words = [text, subtitle, ...(graphic.steps ?? [])].filter(Boolean).join(" ")
|
|
278
|
+
const kit = type ? kitLook(graphic, type, words) : null
|
|
279
|
+
const tone = kit?.tone ?? GRAPHIC_TONES[graphic.tone]
|
|
280
|
+
const accent = kit?.accent ?? GRAPHIC_ACCENTS[graphic.accent]
|
|
281
|
+
const font = kit?.font ?? GRAPHIC_FONTS[graphic.font]
|
|
282
|
+
const ink = against(accent)
|
|
283
|
+
const ms = (duration / FLICKS) * 1000
|
|
284
|
+
const floor = Math.ceil(output.height * 0.0205)
|
|
285
|
+
const pad = Math.round(Math.min(area.h, area.w) * 0.08)
|
|
286
|
+
const bar = Math.max(4, Math.round(output.height * 0.006))
|
|
287
|
+
const animations = []
|
|
288
|
+
const animate = (id, keyframes, options) => animations.push({ id, keyframes, options: { fill: "both", ...options } })
|
|
289
|
+
const outMs = Math.min(220, ms * 0.12)
|
|
290
|
+
animate("a", [{ opacity: 1, offset: 0 }, { opacity: 1, offset: round(1 - outMs / ms) }, { opacity: 0, offset: 1 }], { duration: ms })
|
|
291
|
+
const spring = (id, from, delay = 0) => animate(id, springKeyframes({ ...SPRING, from, to: { y: 0, scale: 1, opacity: 1 } }), { duration: SPRING.ms, delay })
|
|
292
|
+
const fade = (id, delay, length = 300) => animate(id, [{ opacity: 0 }, { opacity: 1 }], { duration: length, delay, easing: "ease-out" })
|
|
293
|
+
const box = `#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:center}`
|
|
294
|
+
const line = (id, size, weight, extra = "") => `#${id}{display:block;padding:0 .08em;background:${tone.plate};font-size:${size}px;line-height:1.2;font-weight:${weight};${extra}}`
|
|
295
|
+
let css = []
|
|
296
|
+
let body = ""
|
|
297
|
+
let fit = null
|
|
298
|
+
|
|
299
|
+
if (kind === "card") {
|
|
300
|
+
// The whole frame: a plate behind, the words large in the content box
|
|
301
|
+
const main = Math.max(floor, Math.round(area.h * (subtitle ? 0.12 : 0.15)))
|
|
302
|
+
const small = Math.max(floor, Math.round(main * 0.42))
|
|
303
|
+
css = [
|
|
304
|
+
`#bg{position:absolute;inset:0;background:${tone.plate}}`,
|
|
305
|
+
box,
|
|
306
|
+
`#t{box-sizing:border-box;max-width:100%;display:flex;flex-direction:column;align-items:center;gap:${pad}px;padding:${pad}px;font-family:${font};color:${tone.ink};text-align:center;text-wrap:balance}`,
|
|
307
|
+
line("m", main, style === "quote" ? 600 : 800, style === "quote" ? "font-style:italic;" : ""),
|
|
308
|
+
line("u", small, 600, `color:${accent};`),
|
|
309
|
+
`#k{width:${Math.round(area.w * 0.18)}px;height:${bar}px;background:${accent};border-radius:${bar}px}`,
|
|
310
|
+
]
|
|
311
|
+
body = `<div id="bg"></div><div id="a"><div id="t">${style === "quote" ? `<span id="k"></span>` : ""}<span id="m" data-text>${escape(text)}</span>${style === "title" ? `<span id="k"></span>` : ""}${subtitle ? `<span id="u" data-text>${escape(subtitle)}</span>` : ""}</div></div>`
|
|
312
|
+
animate("bg", [{ opacity: 0 }, { opacity: 1 }], { duration: 200, easing: "ease-out" })
|
|
313
|
+
spring("t", { y: Math.round(main * 0.6), scale: 0.94, opacity: 0 }, 80)
|
|
314
|
+
animate("k", [{ transform: "scaleX(0)" }, { transform: "scaleX(1)" }], { duration: 420, delay: 260, easing: EASE })
|
|
315
|
+
if (subtitle) fade("u", 380)
|
|
316
|
+
fit = { id: "m", within: "a", min: floor, box: "t" }
|
|
317
|
+
} else if (kind === "list") {
|
|
318
|
+
// Each step arrives on its word (stepAt, from the plan), else evenly through the first half
|
|
319
|
+
const n = graphic.steps.length
|
|
320
|
+
const item = Math.max(floor, Math.round((area.h / (n + 2)) * 0.62))
|
|
321
|
+
css = [
|
|
322
|
+
box,
|
|
323
|
+
`#t{box-sizing:border-box;width:100%;display:flex;flex-direction:column;align-items:flex-start;gap:.3em;padding:${pad}px ${Math.round(pad * 1.6)}px;background:${tone.plate};border-radius:${Math.round(pad * 0.8)}px;font-family:${font};color:${tone.ink};font-size:${item}px}`,
|
|
324
|
+
`#m{display:block;padding:0 .08em;background:${tone.plate};font-size:1.28em;line-height:1.2;font-weight:800}`,
|
|
325
|
+
`.i{display:flex;align-items:baseline;gap:.4em;background:${tone.plate};font-size:1em;line-height:1.2;font-weight:600}`,
|
|
326
|
+
`.n{flex:none;min-width:1.3em;text-align:center;border-radius:.3em;background:${accent};color:${ink};font-weight:800}`,
|
|
327
|
+
]
|
|
328
|
+
const marker = (i) => (style === "steps" ? String(i + 1) : "•")
|
|
329
|
+
body = `<div id="a"><div id="t"><span id="m" data-text>${escape(text)}</span>${graphic.steps.map((step, i) => `<span class="i" id="i${i}"><span class="n">${marker(i)}</span><span data-text>${escape(step)}</span></span>`).join("")}</div></div>`
|
|
330
|
+
spring("t", { y: Math.round(item * 0.6), opacity: 0 })
|
|
331
|
+
graphic.steps.forEach((_, i) => {
|
|
332
|
+
const at = graphic.stepAt?.[i] ?? Math.round(((i + 1) * ms * 0.5) / (n + 1))
|
|
333
|
+
// In from the left: a transform toward the start never reads as overflow
|
|
334
|
+
animate(`i${i}`, [{ opacity: 0, transform: `translateX(-${Math.round(item)}px)` }, { opacity: 1, transform: "translateX(0px)" }], { duration: 320, delay: Math.max(0, Math.min(at - 320, ms - 900)), easing: EASE })
|
|
335
|
+
})
|
|
336
|
+
fit = { id: "t", within: "a", min: floor }
|
|
337
|
+
} else if (kind === "callout" && graphic.mark) {
|
|
338
|
+
// TP9: round the box the person drew, exactly: the solver gave its pixels as the area. A ring is an
|
|
339
|
+
// ellipse inside it, a box its edges, an arrow points down at its top from above (or up from below
|
|
340
|
+
// when there is no room); a label sits on the side away from the arrow
|
|
341
|
+
const side = Math.min(area.w, area.h)
|
|
342
|
+
const label = Math.max(floor, Math.round(Math.max(side, output.height * 0.12) * 0.13))
|
|
343
|
+
const head = Math.max(bar * 3, Math.round(output.height * 0.03))
|
|
344
|
+
const shaft = Math.round(head * 1.6)
|
|
345
|
+
const below = area.y < head + shaft + label * 2
|
|
346
|
+
const arrow = style === "arrow"
|
|
347
|
+
css = [
|
|
348
|
+
`#a{position:absolute;left:${area.x}px;top:${area.y}px;width:${area.w}px;height:${area.h}px}`,
|
|
349
|
+
arrow
|
|
350
|
+
? `#k{position:absolute;left:50%;${below ? `top:${area.h}px` : `bottom:${area.h}px`};width:${bar * 2}px;height:${shaft + head}px;margin-left:-${bar}px;transform-origin:50% ${below ? "0" : "100%"}}#k::after{content:"";position:absolute;left:50%;${below ? "top:0" : "bottom:0"};margin-left:-${head}px;border-left:${head}px solid transparent;border-right:${head}px solid transparent;${below ? `border-bottom:${head}px solid ${accent}` : `border-top:${head}px solid ${accent}`}}#k::before{content:"";position:absolute;left:0;right:0;${below ? `top:${head - 1}px` : `bottom:${head - 1}px`};height:${shaft}px;background:${accent}}`
|
|
351
|
+
: `#k{position:absolute;inset:0;${style === "ring" ? "border-radius:50%" : `border-radius:${Math.round(side * 0.06)}px`};border:${bar}px solid ${accent};box-sizing:border-box;box-shadow:0 0 0 ${Math.max(2, Math.round(bar / 2))}px #00000055}`,
|
|
352
|
+
`#m{position:absolute;left:50%;${arrow ? (below ? `top:${area.h + shaft + head + Math.round(label * 0.3)}px` : `bottom:${area.h + shaft + head + Math.round(label * 0.3)}px`) : area.y > label * 2 ? `bottom:${area.h + Math.round(label * 0.3)}px` : `top:${area.h + Math.round(label * 0.3)}px`};transform:translateX(-50%);width:max-content;max-width:${Math.round(output.width * 0.8)}px;text-align:center;font-family:${font};font-size:${label}px;font-weight:800;line-height:1.2;color:${ink};background:${accent};padding:${Math.round(label * 0.15)}px ${Math.round(label * 0.45)}px;border-radius:${Math.round(label * 0.3)}px}`,
|
|
353
|
+
]
|
|
354
|
+
body = `<div id="a"><span id="k"></span>${text ? `<span id="m" data-text>${escape(text)}</span>` : ""}</div>`
|
|
355
|
+
animate("k", arrow ? [{ transform: "scaleY(0)", opacity: 0 }, { transform: "scaleY(1)", opacity: 1 }] : [{ transform: "scale(1.15)", opacity: 0 }, { transform: "scale(1)", opacity: 1 }], { duration: 380, easing: EASE })
|
|
356
|
+
if (text) fade("m", 220)
|
|
357
|
+
} else if (kind === "callout") {
|
|
358
|
+
// A mark round the point: its size is the box the solver gave, the label above it when there is one
|
|
359
|
+
const side = Math.min(area.w, area.h)
|
|
360
|
+
const label = Math.max(floor, Math.round(side * 0.13))
|
|
361
|
+
const shape = style === "ring" ? `border-radius:50%;border:${bar}px solid ${accent}` : style === "box" ? `border-radius:${Math.round(side * 0.08)}px;border:${bar}px solid ${accent}` : ""
|
|
362
|
+
css = [
|
|
363
|
+
`#a{position:absolute;left:${area.x}px;top:${area.y}px;width:${side}px;height:${side}px}`,
|
|
364
|
+
style === "arrow"
|
|
365
|
+
? `#k{position:absolute;left:50%;top:${Math.round(side * 0.5)}px;width:0;height:0;margin-left:-${Math.round(side * 0.09)}px;border-left:${Math.round(side * 0.09)}px solid transparent;border-right:${Math.round(side * 0.09)}px solid transparent;border-top:${Math.round(side * 0.16)}px solid ${accent};transform-origin:50% 0}`
|
|
366
|
+
: `#k{position:absolute;inset:${Math.round(side * 0.06)}px;${shape};box-sizing:border-box;box-shadow:0 0 0 ${Math.max(2, Math.round(bar / 2))}px #00000055}`,
|
|
367
|
+
`#m{position:absolute;left:50%;bottom:${style === "arrow" ? Math.round(side * 0.52) : Math.round(side * 0.98)}px;transform:translateX(-50%);width:max-content;max-width:${Math.round(Math.min(output.width * 0.8, Math.max(side, output.width * 0.5)))}px;text-align:center;font-family:${font};font-size:${label}px;font-weight:800;line-height:1.2;color:${ink};background:${accent};padding:${Math.round(label * 0.15)}px ${Math.round(label * 0.45)}px;border-radius:${Math.round(label * 0.3)}px}`,
|
|
368
|
+
]
|
|
369
|
+
body = `<div id="a"><span id="k"></span>${text ? `<span id="m" data-text>${escape(text)}</span>` : ""}</div>`
|
|
370
|
+
animate("k", [{ transform: "scale(1.4)", opacity: 0 }, { transform: "scale(1)", opacity: 1 }], { duration: 380, easing: EASE })
|
|
371
|
+
if (text) fade("m", 220)
|
|
372
|
+
} else if (kind === "count") {
|
|
373
|
+
const main = Math.max(floor, Math.round(area.h * (subtitle ? 0.4 : 0.55)))
|
|
374
|
+
const ratio = 0.42 // the subtitle's size to the number's
|
|
375
|
+
const steps = countSteps(text)
|
|
376
|
+
css = [
|
|
377
|
+
box,
|
|
378
|
+
`#t{position:relative;box-sizing:border-box;max-width:100%;display:flex;flex-direction:column;align-items:center;gap:.12em;padding:${pad}px ${Math.round(pad * 2)}px;background:${tone.plate};border-radius:${Math.round(area.h * 0.1)}px;font-family:${font};color:${tone.ink};text-align:center;font-size:${main}px}`,
|
|
379
|
+
`#c{display:grid}#c>span{grid-area:1/1;font-size:1em;line-height:1.2;font-weight:800;font-variant-numeric:tabular-nums;background:${tone.plate};white-space:nowrap}`,
|
|
380
|
+
`#u{display:block;padding:0 .08em;background:${tone.plate};font-size:max(${floor}px,${ratio}em);line-height:1.25;font-weight:600}`,
|
|
381
|
+
`#k{height:${bar}px;width:100%;background:${accent};border-radius:${bar}px}`,
|
|
382
|
+
]
|
|
383
|
+
// The said number is the last step and the text QG-10 reads at rest; the steps before it are only shown, never measured
|
|
384
|
+
const shown = steps ?? [text]
|
|
385
|
+
body = `<div id="a"><div id="t"><span id="c">${shown.map((v, i) => `<span id="c${i}"${i === shown.length - 1 ? " data-text" : ""}>${escape(v)}</span>`).join("")}</span><span id="k"></span>${subtitle ? `<span id="u" data-text>${escape(subtitle)}</span>` : ""}</div></div>`
|
|
386
|
+
spring("t", { scale: 0.7, opacity: 0 })
|
|
387
|
+
const step = 70
|
|
388
|
+
shown.forEach((_, i) => {
|
|
389
|
+
const on = i * step
|
|
390
|
+
const off = i === shown.length - 1 ? ms : on + step
|
|
391
|
+
animate(`c${i}`, [{ opacity: 0, offset: 0 }, { opacity: 0, offset: round(on / ms) }, { opacity: 1, offset: round(Math.min(1, on / ms)) }, { opacity: 1, offset: round(Math.min(1, off / ms)) }, { opacity: i === shown.length - 1 ? 1 : 0, offset: round(Math.min(1, off / ms)) }, { opacity: i === shown.length - 1 ? 1 : 0, offset: 1 }], { duration: ms, easing: "linear" })
|
|
392
|
+
})
|
|
393
|
+
if (subtitle) fade("u", 320)
|
|
394
|
+
fit = { id: "t", within: "a", min: floor }
|
|
395
|
+
} else if (kind === "handle" || kind === "cta") {
|
|
396
|
+
const main = Math.max(floor, Math.round(area.h * (kind === "cta" && subtitle ? 0.36 : 0.5)))
|
|
397
|
+
const ratio = 0.6
|
|
398
|
+
css = [
|
|
399
|
+
box,
|
|
400
|
+
`#t{box-sizing:border-box;max-width:100%;display:flex;flex-direction:column;align-items:center;gap:.1em;padding:${Math.round(pad * 0.8)}px ${Math.round(pad * 1.8)}px;background:${accent};border-radius:${Math.round(area.h / 2)}px;font-family:${font};color:${ink};font-size:${main}px}`,
|
|
401
|
+
// A handle is a name: it may break anywhere rather than run out of its corner
|
|
402
|
+
`#m{display:block;background:${accent};font-size:1em;line-height:1.2;font-weight:800;text-align:center;text-wrap:balance${kind === "handle" ? ";overflow-wrap:anywhere" : ""}}`,
|
|
403
|
+
`#u{display:block;background:${accent};font-size:max(${floor}px,${ratio}em);line-height:1.2;font-weight:600;text-align:center}`,
|
|
404
|
+
]
|
|
405
|
+
body = `<div id="a"><div id="t"><span id="m" data-text>${escape(text)}</span>${subtitle ? `<span id="u" data-text>${escape(subtitle)}</span>` : ""}</div></div>`
|
|
406
|
+
animate("t", [{ transform: "translateY(40%)", opacity: 0 }, { transform: "translateY(0)", opacity: 1 }], { duration: 420, easing: EASE })
|
|
407
|
+
if (subtitle) fade("u", 260)
|
|
408
|
+
fit = { id: "t", within: "a", min: floor }
|
|
409
|
+
} else if (kind === "frame") {
|
|
410
|
+
// A plain drawn frame round the picture: a border and a soft shadow, nothing of any device
|
|
411
|
+
const inset = Math.round(Math.min(output.width, output.height) * 0.035)
|
|
412
|
+
css = [`#a{position:absolute;inset:0}`, `#k{position:absolute;inset:${inset}px;border:${Math.max(4, Math.round(bar * 1.4))}px solid ${accent};border-radius:${Math.round(inset * 0.6)}px;box-shadow:0 0 0 ${inset}px #00000033}`]
|
|
413
|
+
body = `<div id="a"><span id="k"></span></div>`
|
|
414
|
+
animate("k", [{ clipPath: "inset(0 100% 0 0)" }, { clipPath: "inset(0 0% 0 0)" }], { duration: 520, easing: EASE })
|
|
415
|
+
} else {
|
|
416
|
+
// The four more name straps (kind lower)
|
|
417
|
+
const main = Math.max(floor, Math.round(area.h * (subtitle ? 0.34 : 0.42)))
|
|
418
|
+
const ratio = 0.56
|
|
419
|
+
const radius = style === "box" ? 0 : Math.round(area.h * 0.1)
|
|
420
|
+
css = [
|
|
421
|
+
`#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:flex-start}`,
|
|
422
|
+
`#t{position:relative;box-sizing:border-box;max-width:100%;display:flex;flex-direction:column;align-items:flex-start;gap:.15em;padding:${pad}px ${Math.round(pad * 2.2)}px;background:${tone.plate};border-radius:${radius}px;font-family:${font};color:${tone.ink};font-size:${main}px;${style === "box" ? `border-left:${bar * 3}px solid ${accent};` : ""}}`,
|
|
423
|
+
`#m{display:block;padding:0 .08em;background:${tone.plate};font-size:1em;line-height:1.2;font-weight:800}`,
|
|
424
|
+
style === "split" ? `#u{display:block;white-space:nowrap;font-size:max(${floor}px,${ratio}em);line-height:1.25;font-weight:700;background:${accent};color:${ink};padding:.15em .45em;border-radius:.25em}` : `#u{display:block;padding:0 .08em;background:${tone.plate};font-size:max(${floor}px,${ratio}em);line-height:1.25;font-weight:600;white-space:nowrap}`,
|
|
425
|
+
style === "tag" ? `#g{display:block;width:1.6em;height:${bar * 2}px;background:${accent};border-radius:${bar}px}` : "",
|
|
426
|
+
style === "underline" ? `#k{height:${bar}px;width:100%;background:${accent};border-radius:${bar}px;transform-origin:left}` : "",
|
|
427
|
+
]
|
|
428
|
+
body = `<div id="a"><div id="t">${style === "tag" ? `<span id="g"></span>` : ""}<span id="m" data-text>${escape(text)}</span>${style === "underline" ? `<span id="k"></span>` : ""}${subtitle ? `<span id="u" data-text>${escape(subtitle)}</span>` : ""}</div></div>`
|
|
429
|
+
animate("t", [{ transform: `translateX(-${Math.round(area.w * 0.1)}px)`, opacity: 0 }, { transform: "translateX(0)", opacity: 1 }], { duration: 460, easing: EASE })
|
|
430
|
+
if (style === "underline") animate("k", [{ transform: "scaleX(0)" }, { transform: "scaleX(1)" }], { duration: 380, delay: 200, easing: EASE })
|
|
431
|
+
if (subtitle) fade("u", 300)
|
|
432
|
+
fit = { id: "t", within: "a", min: floor }
|
|
433
|
+
}
|
|
434
|
+
return { css: [kit?.faces ?? "", ...css].join(""), body, animations, ...(fit ? { fit } : {}) }
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Kit 2 kinds a make or chat may offer: the person's own words only where `person` (handle, cta). */
|
|
438
|
+
export const kindsFor = ({ typeKit }) => (typeKit === true ? ALL_GRAPHIC_KINDS : GRAPHIC_KINDS)
|
|
439
|
+
export { REGIONS }
|
package/src/edit/engine/index.js
CHANGED
|
@@ -87,7 +87,7 @@ async function onceMore(work) {
|
|
|
87
87
|
* motion: HyperFrames and Chrome for the motion layer, from the Media Runtime
|
|
88
88
|
* cacheBytes: the cache's cap (ES-17); KRIYA_EDIT_CACHE_BYTES, else 20 GB
|
|
89
89
|
*/
|
|
90
|
-
export function createEngine({ folder, roots, cache, exports: exportsDir, journal, toolVersion, capabilities, scheduler, free = defaultFree, run, onTool, motion = () => motionRuntime(activeRuntime()), cacheBytes = Number(process.env.KRIYA_EDIT_CACHE_BYTES) || 20 * GB }) {
|
|
90
|
+
export function createEngine({ folder, roots, cache, exports: exportsDir, journal, toolVersion, capabilities, scheduler, free = defaultFree, run, onTool, motion = () => motionRuntime(activeRuntime()), customMotion = () => false, cacheBytes = Number(process.env.KRIYA_EDIT_CACHE_BYTES) || 20 * GB }) {
|
|
91
91
|
const tool = (command, args, options) => {
|
|
92
92
|
onTool?.(command, args)
|
|
93
93
|
return (run ?? runTool)(command, args, options)
|
|
@@ -135,6 +135,8 @@ export function createEngine({ folder, roots, cache, exports: exportsDir, journa
|
|
|
135
135
|
const effects = node.picture.flatMap((item) => item.effects)
|
|
136
136
|
const luts = effects.filter((effect) => effect.type === "lut").map((effect) => effect.asset)
|
|
137
137
|
const paths = await inputsFor([...node.picture, ...node.overlays].map((item) => item.asset).concat(luts), useProxy, need)
|
|
138
|
+
// TP7: the type kit's logo, always its own file: a draft proxy would lose its transparency
|
|
139
|
+
if (node.brand?.bug) paths.set(node.brand.bug.asset, sourcePath(assetOf(node.brand.bug.asset)))
|
|
138
140
|
for (const key of new Set(effects.filter((effect) => effect.type === "grade" && effect.match).map((effect) => effect.match.key))) paths.set(key, (await need("match", key)).file)
|
|
139
141
|
return paths
|
|
140
142
|
}
|
|
@@ -420,12 +422,17 @@ export function createEngine({ folder, roots, cache, exports: exportsDir, journa
|
|
|
420
422
|
thumbs: async (id, options) => (await graph.demand("thumbs", id, options)).file,
|
|
421
423
|
|
|
422
424
|
/**
|
|
423
|
-
* @param {{ quality: "draft" | "master", deliverable?: string, job?: number, signal?: AbortSignal, onStep?: (done: number, total: number) => void, project?: object }} request
|
|
425
|
+
* @param {{ quality: "draft" | "master", deliverable?: string, job?: number, signal?: AbortSignal, onStep?: (done: number, total: number) => void, project?: object, partial?: boolean }} request
|
|
426
|
+
* partial (editing.livePreview, TP3): each draft segment's input names only the tiles it draws, so a
|
|
427
|
+
* change re-renders only the segments it touched. The picture only: the sound is always one mix of the
|
|
428
|
+
* whole film (QG-06) and a master one encode (ET-TR-M2), EH-66
|
|
424
429
|
* @returns {Promise<{ file: string, plan: object }>}
|
|
425
430
|
*/
|
|
426
|
-
async render({ quality, deliverable, job, signal, onStep = () => {}, project: candidate }) {
|
|
431
|
+
async render({ quality, deliverable, job, signal, onStep = () => {}, project: candidate, partial = false }) {
|
|
427
432
|
// A candidate version (the Edit Loop's attempt) renders without becoming the project
|
|
428
|
-
|
|
433
|
+
// TP7: which of the pack's fonts this computer has, so a type kit's tiles are keyed by what they draw with
|
|
434
|
+
const fonts = motion().fonts
|
|
435
|
+
const plan = compile(candidate ?? project, index, { engineVersion: ENGINE_VERSION, runtimeVersion: toolVersion, quality, deliverable, filters: capabilities.filters, ...(fonts ? { fonts: [...fonts.keys()] } : {}), ...(customMotion() === true ? { customMotion: true } : {}) })
|
|
429
436
|
if (!plan.duration) throw new EngineFailure("plan", "empty", "There's nothing on the timeline to render.")
|
|
430
437
|
preflight(plan)
|
|
431
438
|
const shared = { canvas: plan.canvas, output: plan.output, input: plan.input, tiles: plan.tiles }
|
|
@@ -449,7 +456,9 @@ export function createEngine({ folder, roots, cache, exports: exportsDir, journa
|
|
|
449
456
|
step(1)
|
|
450
457
|
} else {
|
|
451
458
|
const total = plan.segments.length + 1
|
|
452
|
-
|
|
459
|
+
// Off, every segment reads the whole plan's tiles, as before: a caption change re-renders them all
|
|
460
|
+
const tilesOf = (segment) => (partial === true ? plan.tiles.filter((tile) => segment.node.tiles.some((part) => part.key === tile.key)) : plan.tiles)
|
|
461
|
+
for (const segment of plan.segments) graph.set(`segment:${segment.key}`, { plan: { ...shared, tiles: tilesOf(segment) }, segment })
|
|
453
462
|
graph.set(`join:${key}`, { segments: plan.segments.map((s) => s.key), audio: plan.audio.key })
|
|
454
463
|
// Demanded here, not only by the join, so progress can be seen and slots shared
|
|
455
464
|
await Promise.all(plan.segments.map((segment) => graph.demand("segment", segment.key, options).then(() => step(total))))
|