@kriya-ai/harness 0.2.4 → 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 +504 -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 +82 -5
- package/src/edit/core/layout.js +46 -1
- package/src/edit/core/ops.js +175 -3
- package/src/edit/core/plan.js +95 -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/transitions.js +17 -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 +137 -0
- package/src/edit/director/custom-motion.js +88 -0
- package/src/edit/director/graphics.js +186 -0
- package/src/edit/director/intent.js +125 -0
- package/src/edit/director/mentions.js +52 -0
- package/src/edit/director/plan.js +89 -12
- package/src/edit/director/revise.js +172 -7
- 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 +439 -0
- package/src/edit/engine/index.js +14 -5
- package/src/edit/engine/motion.js +153 -14
- 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 +76 -8
- package/src/edit/gates/picture.js +6 -3
- 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 +17 -7
- package/src/edit/host/paths.js +34 -3
- package/src/edit/host/preview.js +108 -0
- package/src/edit/host/projects.js +494 -29
- package/src/edit/host/server.js +263 -19
- package/src/edit/host/tavi.js +77 -0
- package/src/edit/loop/make.js +44 -3
- package/src/edit/recipes/assembly.js +352 -0
- package/src/edit/recipes/graphic-clips.js +59 -0
- package/src/edit/recipes/openings.js +36 -0
- package/src/edit/recipes/reel.js +138 -17
- 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 -3
- 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 +452 -3
- package/studio/dist/studio.js +3 -3
|
@@ -0,0 +1,439 @@
|
|
|
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 { 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"
|
|
12
|
+
import { EngineFailure } from "./tool.js"
|
|
13
|
+
|
|
14
|
+
const FLICKS = 705_600_000
|
|
15
|
+
|
|
16
|
+
export const GRAPHIC_BLOCK = "graphic"
|
|
17
|
+
export const GRAPHIC_VERSION = 1
|
|
18
|
+
|
|
19
|
+
/** The kinds: what each is for (the Director's prompt and the Plan Card read this), and its styles, the first the default. */
|
|
20
|
+
export const GRAPHIC_KINDS = {
|
|
21
|
+
title: { label: "Title", styles: ["rise", "slam", "words"], subtitle: false, when: "a few strong words of the line being said, to land its point" },
|
|
22
|
+
chapter: { label: "Chapter card", styles: ["wipe"], subtitle: false, when: "the name of a new part of the video, as the speaker starts it" },
|
|
23
|
+
quote: { label: "Quote", styles: ["line"], subtitle: false, when: "a short sentence the speaker says that is worth reading as well as hearing" },
|
|
24
|
+
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" },
|
|
25
|
+
intro: { label: "Opening title", styles: ["sweep"], subtitle: true, when: "the video's title over its first seconds, with an optional second line" },
|
|
26
|
+
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" },
|
|
27
|
+
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`" },
|
|
28
|
+
}
|
|
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" }
|
|
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
|
+
|
|
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). */
|
|
54
|
+
export const GRAPHIC_ACCENTS = { teal: "#4fd1c5", yellow: "#ffd23f", amber: "#ffb347", pink: "#ff7ab6", white: "#ffffff" }
|
|
55
|
+
export const GRAPHIC_TONES = { dark: { plate: "#13292b", ink: "#f2eadf", chip: "#13292b" }, light: { plate: "#f6f1e7", ink: "#1c2530", chip: "#1c2530" } }
|
|
56
|
+
// System fonts only: nothing is downloaded, and every stack ends in a family each platform has
|
|
57
|
+
export const GRAPHIC_FONTS = {
|
|
58
|
+
sans: "'Helvetica Neue',Helvetica,Arial,sans-serif",
|
|
59
|
+
serif: "Georgia,'Times New Roman',serif",
|
|
60
|
+
condensed: "'Avenir Next Condensed','Arial Narrow','Helvetica Neue',Arial,sans-serif",
|
|
61
|
+
mono: "'SF Mono',Menlo,Consolas,'Courier New',monospace",
|
|
62
|
+
}
|
|
63
|
+
export const TEXT_MAX = 48
|
|
64
|
+
export const SUBTITLE_MAX = 32 // one line under the main one, in the narrowest frame at the smallest readable size
|
|
65
|
+
const NUMBER = /^[₹$€£]?\d{1,7}(?:[.,]\d{1,3})*\s?(?:%|[A-Za-z₹$€£]{1,8})?$/
|
|
66
|
+
|
|
67
|
+
// Too long is cut at a word, never through one
|
|
68
|
+
const cleanText = (value, max = TEXT_MAX) => {
|
|
69
|
+
if (typeof value !== "string") return ""
|
|
70
|
+
const text = value.replace(/[\u0000-\u001f\u007f<>]/g, " ").replace(/\s+/g, " ").trim()
|
|
71
|
+
if (text.length <= max) return text
|
|
72
|
+
const cut = text.slice(0, max + 1)
|
|
73
|
+
return (cut.includes(" ") ? cut.slice(0, cut.lastIndexOf(" ")) : cut.slice(0, max)).trim()
|
|
74
|
+
}
|
|
75
|
+
const pick = (table, value, fallback) => (Object.hasOwn(table, value ?? "") ? value : fallback)
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A graphic's shape, at every trust boundary (a model's answer, a browser's request, a saved
|
|
79
|
+
* project). Unknown fields go; text is cleaned. Whether its words may be shown is `graphicProblems`' job.
|
|
80
|
+
* @returns {object | null} null when it can't be a graphic
|
|
81
|
+
*/
|
|
82
|
+
export function cleanGraphic(raw, kinds = GRAPHIC_KINDS) {
|
|
83
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null
|
|
84
|
+
const kind = pick(kinds, raw.kind, null)
|
|
85
|
+
if (!kind) 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
|
|
97
|
+
const subtitle = shape.subtitle ? cleanText(raw.subtitle, SUBTITLE_MAX) : ""
|
|
98
|
+
const id = typeof raw.at === "string" && /^[A-Za-z0-9:_-]{1,64}$/.test(raw.at) ? raw.at : null
|
|
99
|
+
return {
|
|
100
|
+
kind,
|
|
101
|
+
style: shape.styles.includes(raw.style) ? raw.style : shape.styles[0],
|
|
102
|
+
text,
|
|
103
|
+
...(subtitle ? { subtitle } : {}),
|
|
104
|
+
accent: pick(GRAPHIC_ACCENTS, raw.accent, "teal"),
|
|
105
|
+
tone: pick(GRAPHIC_TONES, raw.tone, "dark"),
|
|
106
|
+
font: pick(GRAPHIC_FONTS, raw.font, "sans"),
|
|
107
|
+
...(id ? { at: id } : {}),
|
|
108
|
+
...(steps ? { steps } : {}),
|
|
109
|
+
...(stepAt ? { stepAt } : {}),
|
|
110
|
+
...(point ? { point } : {}),
|
|
111
|
+
...(mark ? { mark } : {}),
|
|
112
|
+
...(corner ? { corner } : {}),
|
|
113
|
+
// Set by the recipe on a graphic an approved plan asked for, so a remake replaces it
|
|
114
|
+
...(raw.plan === true ? { plan: true } : {}),
|
|
115
|
+
}
|
|
116
|
+
}
|
|
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
|
+
|
|
124
|
+
/** How long a graphic stays up: long enough to read, never long enough to bore. In flicks. */
|
|
125
|
+
export function graphicLength(graphic) {
|
|
126
|
+
if (KIT2_KINDS[graphic.kind]) return kit2Length(graphic)
|
|
127
|
+
const letters = graphic.text.length + (graphic.subtitle?.length ?? 0)
|
|
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))
|
|
129
|
+
return Math.round(seconds * FLICKS)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const escape = (text) => String(text).replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c])
|
|
133
|
+
const round = (n) => Math.round(n * 10000) / 10000
|
|
134
|
+
const EASE = "cubic-bezier(.2,.8,.2,1)"
|
|
135
|
+
const SPRING = { damping: 0.6, frequency: 12, ms: 620 }
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {{ variables: object, area: { x: number, y: number, w: number, h: number }, output: { width: number, height: number }, duration: number }} input
|
|
139
|
+
* @param {(spring: object) => object[]} springKeyframes motion.js's, handed in so the two files don't import each other
|
|
140
|
+
* @returns {{ css: string, body: string, animations: object[], fit: object }}
|
|
141
|
+
*/
|
|
142
|
+
export function buildGraphic({ variables, area, output, duration, type }, springKeyframes) {
|
|
143
|
+
const graphic = cleanGraphic(variables, ALL_GRAPHIC_KINDS)
|
|
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)
|
|
146
|
+
const { kind, style, text, subtitle } = graphic
|
|
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]
|
|
152
|
+
const ms = (duration / FLICKS) * 1000
|
|
153
|
+
const floor = Math.ceil(output.height * 0.0205) // QG-09's smallest readable size
|
|
154
|
+
const two = !!subtitle
|
|
155
|
+
const pad = Math.round(area.h * 0.08)
|
|
156
|
+
const big = kind === "stat" || kind === "intro"
|
|
157
|
+
const main = Math.max(floor, Math.round(area.h * (two ? (big ? 0.4 : 0.34) : big ? 0.5 : 0.42)))
|
|
158
|
+
const small = Math.max(floor, Math.round(area.h * 0.19))
|
|
159
|
+
const left = kind === "lower" || kind === "chapter" || kind === "quote"
|
|
160
|
+
const radius = style === "pill" ? Math.round(area.h / 2) : Math.round(area.h * 0.1)
|
|
161
|
+
const bar = Math.max(4, Math.round(area.h * 0.05))
|
|
162
|
+
|
|
163
|
+
const animations = []
|
|
164
|
+
const animate = (id, keyframes, options) => animations.push({ id, keyframes, options: { fill: "both", ...options } })
|
|
165
|
+
// In and out with the whole graphic, so it never pops off on a cut
|
|
166
|
+
const out = Math.min(220, ms * 0.12)
|
|
167
|
+
animate("a", [{ opacity: 1, offset: 0 }, { opacity: 1, offset: round(1 - out / ms) }, { opacity: 0, offset: 1 }], { duration: ms })
|
|
168
|
+
const spring = (id, from, delay = 0) => animate(id, springKeyframes({ ...SPRING, from, to: { y: 0, scale: 1, opacity: 1 } }), { duration: SPRING.ms, delay })
|
|
169
|
+
const grow = (id, axis, delay = 0, length = 380) => animate(id, [{ transform: `scale${axis}(0)` }, { transform: `scale${axis}(1)` }], { duration: length, delay, easing: EASE })
|
|
170
|
+
const fade = (id, delay, length = 300) => animate(id, [{ opacity: 0 }, { opacity: 1 }], { duration: length, delay, easing: "ease-out" })
|
|
171
|
+
|
|
172
|
+
// Room on the left for what leads the text in: the bar or the dot
|
|
173
|
+
const lead = Math.round(pad * 2.2) + (kind === "lower" || kind === "chapter" || kind === "quote" ? bar * 4 : 0)
|
|
174
|
+
let words = escape(text)
|
|
175
|
+
let rule = ""
|
|
176
|
+
if (kind === "title" && style === "slam") {
|
|
177
|
+
spring("t", { scale: 1.6, opacity: 0 })
|
|
178
|
+
rule = "under"
|
|
179
|
+
grow("k", "X", 260)
|
|
180
|
+
} else if (kind === "title" && style === "words") {
|
|
181
|
+
// Each word lands in turn, all in within half a second so the line reads at once
|
|
182
|
+
const parts = text.split(" ")
|
|
183
|
+
const step = Math.min(90, 480 / parts.length)
|
|
184
|
+
words = parts.map((word, i) => `<span id="w${i}" class="w">${escape(word)}</span>`).join(" ")
|
|
185
|
+
fade("t", 0, 120)
|
|
186
|
+
parts.forEach((_, i) => spring(`w${i}`, { y: Math.round(main * 0.6), opacity: 0 }, Math.round(i * step)))
|
|
187
|
+
} else if (kind === "chapter") {
|
|
188
|
+
rule = "side"
|
|
189
|
+
grow("k", "Y", 0, 320)
|
|
190
|
+
animate("t", [{ clipPath: "inset(0 100% 0 0)" }, { clipPath: "inset(0 0 0 0)" }], { duration: 460, delay: 120, easing: EASE })
|
|
191
|
+
} else if (kind === "quote") {
|
|
192
|
+
// No quote-mark glyph: a reader takes one for "66" and the copy gate rightly fails it (found on a real make)
|
|
193
|
+
rule = "side"
|
|
194
|
+
grow("k", "Y", 0, 320)
|
|
195
|
+
spring("t", { y: Math.round(main * 0.5), opacity: 0 }, 90)
|
|
196
|
+
} else if (kind === "lower") {
|
|
197
|
+
rule = style === "pill" ? "dot" : "side"
|
|
198
|
+
animate("t", [{ transform: `translateX(-${Math.round(area.w * 0.12)}px)`, opacity: 0 }, { transform: "translateX(0)", opacity: 1 }], { duration: 480, easing: EASE })
|
|
199
|
+
grow("k", style === "pill" ? "" : "Y", 180, 320)
|
|
200
|
+
} else if (kind === "intro" || kind === "end") {
|
|
201
|
+
rule = "under"
|
|
202
|
+
spring("t", { y: Math.round(main * 0.8), scale: 0.92, opacity: 0 })
|
|
203
|
+
grow("k", "X", 220, 520)
|
|
204
|
+
} else if (kind === "stat") {
|
|
205
|
+
rule = "under"
|
|
206
|
+
spring("t", { scale: 0.5, opacity: 0 })
|
|
207
|
+
grow("k", "X", 200)
|
|
208
|
+
} else spring("t", { y: Math.round(main * 1.2), scale: 0.85, opacity: 0 })
|
|
209
|
+
if (two) fade("u", 320)
|
|
210
|
+
|
|
211
|
+
// The end card's second line is a chip in the accent colour, with the plate's dark ink on it
|
|
212
|
+
const chip = kind === "end" && two
|
|
213
|
+
// QG-09 reads a text's plate from the text's own element, so each line carries the plate's colour
|
|
214
|
+
const css = [
|
|
215
|
+
kit?.faces ?? "",
|
|
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"}}`,
|
|
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}`,
|
|
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;" : ""}}`,
|
|
219
|
+
`.w{display:inline-block}`,
|
|
220
|
+
`#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}`}}`,
|
|
221
|
+
rule === "under" ? `#k{height:${bar}px;width:100%;background:${accent};border-radius:${bar}px;transform-origin:${left ? "left" : "center"}}` : "",
|
|
222
|
+
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}` : "",
|
|
223
|
+
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%}` : "",
|
|
224
|
+
].join("")
|
|
225
|
+
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>`
|
|
226
|
+
// The main line wraps, then steps down until the plate fits its box, never under the readable floor
|
|
227
|
+
return { css, body, animations, fit: { id: "m", within: "a", min: floor, box: "t" } }
|
|
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))))
|