AI media harness for planning, generating, and editing locally
TypeScript
Give the cover caption its own plate and the guard three more shapes
Bitti51298d0c3ce8
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex b57378c..b148743 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -1938,9 +1938,42 @@ fn answer_app_close(window: tauri::Window, state: tauri::State<'_, ExitGuard>, c}}+/* The window's own ground — what the OS paints before the webview has anything+ * to show. A FIFTH copy of a colour that tokens.css already owns, after+ * tokens.css itself, theme.ts, public/theme-boot.js and the `backgroundColor`+ * in tauri.conf.json; src/lib/theme.test.ts now pins every one of them.+ *+ * Why Rust repaints it at all: tauri.conf.json holds ONE static value, and the+ * appearance preference has three states. Left at the dark ground, a+ * light-theme computer showed a black window for the moment before the webview+ * painted. The preference itself lives in the webview's localStorage — there is+ * nothing here that can read it — so this follows the OS instead, which is+ * exactly what the default "system" choice resolves to, and is right for an+ * explicit choice that agrees with the computer. The one case it still gets+ * wrong is an explicit choice that opposes the OS, and no value obtainable in+ * this process fixes that: it would need the preference duplicated into a+ * second store, which is precisely the drift this comment exists to record.+ * theme-boot.js corrects it on the first frame the webview draws either way. */+const GROUND_DARK: tauri::window::Color = tauri::window::Color(0x08, 0x0a, 0x0f, 0xff);+const GROUND_LIGHT: tauri::window::Color = tauri::window::Color(0xee, 0xf1, 0xf6, 0xff);+#[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default()+ .setup(|app| {+ use tauri::Manager as _;+ if let Some(window) = app.get_webview_window("main") {+ let ground = if matches!(window.theme(), Ok(tauri::Theme::Light)) {+ GROUND_LIGHT+ } else {+ GROUND_DARK+ };+ // A window that will not take a background colour is not a+ // reason to refuse to start: the webview repaints in a frame.+ let _ = window.set_background_color(Some(ground));+ }+ Ok(())+ }).manage(agent::AgentRuntime::default()).manage(vidfab::VidfabRuntime::default()).manage(ExitGuard::default())diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.jsonindex f87f722..2d86c9f 100644--- a/src-tauri/tauri.conf.json+++ b/src-tauri/tauri.conf.json@@ -20,7 +20,7 @@"center": true,"decorations": true,"resizable": true,- "backgroundColor": "#080A0F",+ "backgroundColor": "#080a0f","dragDropEnabled": false}],diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsxindex b0ee5e4..132ff96 100644--- a/src/components/workspace/GeneratorView.tsx+++ b/src/components/workspace/GeneratorView.tsx@@ -1,9 +1,10 @@import { listen } from "@tauri-apps/api/event";-import { AlertCircle, Ban, Check, ChevronRight, Clock3, Info, LoaderCircle, Play, Plus, RefreshCw, Sparkles, Square, WandSparkles, X } from "lucide-react";+import { AlertCircle, Ban, Check, ChevronRight, Clock3, FileText, Image as ImageIcon, Info, LoaderCircle, Play, Plus, RefreshCw, Sparkles, Square, WandSparkles, X } from "lucide-react";import { useEffect, useMemo, useRef, useState } from "react";import { isTauri } from "../../lib/persistence";import { actionReferenceIds, compileGenerationJobPrompt, compileGenerationJobSegments, compileMiniMaxH3PromptSegments, createDraftGenerationJob, danglingReferenceTokens, sceneDurationSeconds, sceneShots, STORY_TRACK_ID, isReferenceDescribed, isReferenceUsable, isVisualReference, projectItemPath, usableImageReferences, type GenerationJob, type ProjectAsset, type ProjectConfig, type ProjectReference, type PromptSegment, type TimelineClip, type TimelineTrack } from "../../lib/project";import { cancelVidfabGeneration, enqueueVidfabGeneration, resolveVidfabPlan, type VidfabGenerationRequest, type VidfabStatus } from "../../lib/runtime";+import { ReferenceImage } from "./ReferenceImage";import { SceneEditor } from "./SceneEditor";interface GeneratorViewProps {@@ -346,8 +347,9 @@ export function GeneratorView({ config, folderPath, runtime = null, onChange, onsent to the engine. A bound reference the prompt skips stayslisted with its reason — hiding it would leave the userwondering where it went. */}- {config.references.map((ref, index) => {+ {config.references.map((ref) => {const bound = selected.referenceIds.includes(ref.id);+ const picture = ref.kind === "image" && (ref.relativePath || ref.sourcePath);const skipped = skipReason(ref);return <label key={ref.id} className={`job-ref ${bound ? "job-ref--bound" : ""}`}><input@@ -356,7 +358,15 @@ export function GeneratorView({ config, folderPath, runtime = null, onChange, ondisabled={refsLocked}onChange={() => toggleReference(selected, ref.id)}/>- <i className={`ref-mini ref-mini--${index}`} />+ {/* The reference's real picture, not a stand-in. aria-hidden+ because the name it illustrates is the next node in this+ same <label>, and repeating it would say every reference+ twice when the checkbox announces itself. */}+ <span className="ref-mini" aria-hidden="true">+ {picture+ ? <ReferenceImage folderPath={folderPath} relativePath={ref.relativePath} sourcePath={ref.sourcePath} alt="" />+ : ref.kind === "image" ? <ImageIcon size={16} /> : <FileText size={16} />}+ </span><b>{ref.name}</b>{skipped? <p className="job-refs__reason">{skipped}</p>diff --git a/src/lib/theme.test.ts b/src/lib/theme.test.tsindex 685f051..19f3fc2 100644--- a/src/lib/theme.test.ts+++ b/src/lib/theme.test.ts@@ -183,6 +183,40 @@ describe("tokens.css", () => {expect(boot).toContain(`light: "${THEME_BACKGROUND.light}"`);expect(boot).toContain(THEME_KEY);});++ it("agrees with the three copies that live outside the bundle entirely", () => {+ /* The test above pins the copies JavaScript can reach. Three more exist+ where no stylesheet and no bundle has loaded yet, and they were unpinned+ until now — which is how a light-theme computer came to open a black+ window: tauri.conf.json's `backgroundColor` is a single static value and+ nothing checked it was even a colour the palette knows.++ It stays the DARK ground on purpose. It is what a window is created with+ before any of our code runs, and one static value cannot follow a+ three-state preference; src-tauri/src/lib.rs repaints it from the OS+ theme as soon as the app is up, and theme-boot.js corrects it again on+ the webview's first frame. See the comment above GROUND_DARK for the one+ case that still gets a wrong frame and why nothing here can fix it. */+ const conf = JSON.parse(read("src-tauri/tauri.conf.json"));+ expect(conf.app.windows[0].backgroundColor).toBe(THEME_BACKGROUND.dark);++ /* Written as Color(0x08, 0x0a, 0x0f, 0xff) so this comparison is exact+ rather than a decimal triple nobody could check by eye. */+ const asRustColor = (hex: string) =>+ `Color(${hex.slice(1).match(/../g)!.map((pair) => `0x${pair}`).join(", ")}, 0xff)`;+ const rust = read("src-tauri/src/lib.rs");+ expect(rust).toContain(asRustColor(THEME_BACKGROUND.dark));+ expect(rust).toContain(asRustColor(THEME_BACKGROUND.light));+ /* And that they are actually used for this. Two consts nothing calls would+ keep passing the two assertions above while the window stayed black. */+ expect(rust).toContain("set_background_color");+ expect(rust).toContain("tauri::Theme::Light");++ /* index.html's meta ships the dark ground and applyTheme rewrites it on+ every switch, so the static value only has to be a real palette entry. */+ expect(read("index.html")).toContain(`content="${THEME_BACKGROUND.dark}"`);+ expect(read("src/lib/theme.ts")).toContain('meta[name="theme-color"]');+ });});describe("every stylesheet resolves through the palette", () => {@@ -234,8 +268,17 @@ describe("every stylesheet resolves through the palette", () => {token that already existed. None of them touched a var(), so nothing failed.So: a stylesheet may not name a colour. Not `#hex`, not `rgb(`, `rgba(`,- `hsl(` or `hsla(`. tokens.css is the one file that spells colours out; every- other sheet in src/styles goes through it.+ `hsl(` or `hsla(`, not `oklch()`, `oklab()`, `lab()`, `lch()`, `hwb()` or+ `color()`, and not a NAMED colour either — `background: white` was the widest+ way through this guard, and `color-mix(in srgb, white 30%, var(--panel))` the+ likeliest, because color-mix is how nearly every derived shade in this+ codebase is written. tokens.css is the one file that spells colours out;+ every other sheet in src/styles goes through it.++ Two spellings deliberately stay legal, because neither names a colour:+ `transparent` (the absence of one) and `currentColor` (whatever the palette+ already put on the element). And `color-mix()` itself is not banned — only+ literals inside it, which the same two checks find wherever they sit.A handful of literals ARE right, because they are pictures and brand marksrather than surfaces, and they stay dark whatever the page does. Each one is@@ -244,7 +287,46 @@ describe("every stylesheet resolves through the palette", () => {and a listed rule that has gone away — or has stopped containing a literal —fails too. An allowlist nothing verifies is how the last two guards rotted. */-const COLOUR_LITERAL = /#[0-9a-fA-F]{3,8}\b|\b(?:rgba?|hsla?)\(/g;+const COLOUR_LITERAL = /#[0-9a-fA-F]{3,8}\b|\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\(/g;++/* Every named colour in CSS Color 4. `transparent` and `currentcolor` are+ deliberately absent — see above. The interpolation spaces color-mix() takes+ (`in srgb`, `in oklab`, `in hsl`) are not in here either, and the function+ list above only matches with an opening paren, so `color-mix(in oklab, …)`+ stays legal while `oklab(0.6 0.1 0.2)` does not. */+const NAMED_COLOURS = new Set(`+ aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet+ brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan+ darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen+ darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey+ darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite+ forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew+ hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue+ lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon+ lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime+ limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple+ mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue+ mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid+ palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum+ powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen+ seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal+ thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen+`.trim().split(/\s+/));++/** Every colour a chunk of CSS names, in the two shapes a name can take. */+function colourLiterals(css: string): string[] {+ const found = [...css.matchAll(COLOUR_LITERAL)].map((match) => match[0]);+ /* A named colour only counts inside a declaration VALUE. Quoted strings are+ blanked first: `content: "black"` names a word, not a colour, and+ `font-family: Silver` would otherwise read as one too. Selectors never+ reach here — this only ever sees rule bodies. */+ for (const [, value] of css.matchAll(/[-a-zA-Z]+\s*:\s*([^;{}]*)/g)) {+ for (const word of value.replace(/"[^"]*"|'[^']*'/g, " ").match(/[a-zA-Z]+/g) ?? []) {+ if (NAMED_COLOURS.has(word.toLowerCase())) found.push(word);+ }+ }+ return found;+}/** The index of the `}` that closes the `{` at `open`. */function closingBrace(css: string, open: number): number {@@ -305,15 +387,19 @@ const LITERALS_ALLOWED: Record<string, Record<string, string>> = {".project-card__art--chrome::before": "generated cover art",".project-card__art--chrome::after": "generated cover art",".project-card__art--ember": "generated cover art",+ /* These three sit ON the artwork, and each paints its OWN dark plate. That+ is the whole justification, and it is a fact about these rules rather+ than about the pictures: two of the four covers are pale (--paper is+ #cabca3, --chrome peaks at #dce7e7), so the note that used to stand here+ — "white on a dark picture in both themes, because the picture is dark in+ both" — was simply false, and the caption it excused measured 1.75:1. */".project-card__format, .project-card__quality":- "chrome ON the cover art: white on a dark picture in both themes, because the picture is dark in both",- ".project-card__play": "chrome ON the cover art",- ".project-card__art-copy": "chrome ON the cover art",- },- "generator.css": {- ".job-refs .ref-mini":- "stand-in artwork for a reference thumbnail — the same case as the library's cover art",- ".ref-mini--1": "stand-in artwork for a reference thumbnail",+ "white ink on the dark plate this rule paints for itself: 5.29:1 measured over the palest cover",+ ".project-card__play": "white ink on the dark disc this rule paints for itself",+ ".project-card__art-copy":+ "white ink on the strip this rule paints for itself, clearing 4.5:1 over any cover at all — recomputed from the two literals by the test below",+ ".project-card__art-copy::before":+ "the feathered top edge of that strip: decoration, with no text on it",},};@@ -333,7 +419,32 @@ describe("no stylesheet outside tokens.css names a colour", () => {it("proves it can see a literal at all, by finding tokens.css full of them", () => {/* The regex and the reader are shared with the assertions below. A typothat made them match nothing would turn every test here green. */- expect(readCss("src/styles/tokens.css").match(COLOUR_LITERAL)!.length).toBeGreaterThan(100);+ expect(colourLiterals(readCss("src/styles/tokens.css")).length).toBeGreaterThan(100);+ });++ it("catches the three shapes the hex-and-rgb regex alone walked straight past", () => {+ /* Each of these was tried against the previous guard and got through. The+ point of putting them here rather than trusting the regex to read right+ is that a rule nobody has ever seen bite is a rule nobody knows works. */+ expect(colourLiterals("a { background: white; }")).toEqual(["white"]);+ expect(colourLiterals("a { border-color: RebeccaPurple; }")).toEqual(["RebeccaPurple"]);+ expect(colourLiterals("a { background: color-mix(in srgb, white 30%, var(--panel)); }")).toEqual(["white"]);+ expect(colourLiterals("a { background: color-mix(in srgb, #fff 30%, var(--panel)); }")).toEqual(["#fff"]);+ expect(colourLiterals("a { color: oklch(62% 0.2 250); }")).toEqual(["oklch("]);+ expect(colourLiterals("a { color: lab(52% 40 59); }")).toEqual(["lab("]);+ expect(colourLiterals("a { color: lch(52% 72 55); }")).toEqual(["lch("]);+ expect(colourLiterals("a { color: hwb(194 0% 0%); }")).toEqual(["hwb("]);+ expect(colourLiterals("a { color: color(display-p3 1 0 0); }")).toEqual(["color("]);++ /* And the shapes that must NOT trip it. Banning any of these would ban the+ idiom the palette is actually derived with, and the next person would+ "fix" the guard by deleting it. */+ expect(colourLiterals("a { background: color-mix(in srgb, var(--accent) 20%, var(--panel-3)); }")).toEqual([]);+ expect(colourLiterals("a { background: color-mix(in oklab, var(--a), var(--b)); }")).toEqual([]);+ expect(colourLiterals("a { border-color: transparent; }")).toEqual([]);+ expect(colourLiterals("a { color: currentColor; }")).toEqual([]);+ expect(colourLiterals('a { content: "black"; filter: grayscale(1); }')).toEqual([]);+ expect(colourLiterals("a { --panel-3: var(--panel-2); border: 1px solid var(--line); }")).toEqual([]);});for (const sheet of sheets) {@@ -344,7 +455,7 @@ describe("no stylesheet outside tokens.css names a colour", () => {const offenders: string[] = [];for (const { selector, body } of blocks) {if (selector in allowed) continue;- for (const literal of body.match(COLOUR_LITERAL) ?? []) {+ for (const literal of colourLiterals(body)) {offenders.push(`${sheet} ${selector} { … ${literal} … }`);}}@@ -360,8 +471,62 @@ describe("no stylesheet outside tokens.css names a colour", () => {expect(rule, `exemption names a rule ${sheet} no longer has`).toBeTruthy();/* And it still needs the exemption. A rule that has been converted totokens must lose its entry, or the list drifts back into fiction. */- expect(rule!.body.match(COLOUR_LITERAL), "exemption is stale: the rule names no colour any more").toBeTruthy();+ expect(colourLiterals(rule!.body), "exemption is stale: the rule names no colour any more").not.toEqual([]);});}}});++/* --- The one caption that lands on a picture instead of a palette ---------- *++ Everywhere else, legibility is a property of two tokens and can be argued+ about by reading tokens.css. The library cover caption is the exception: it+ is the user's own project brief, printed over generated artwork, and it was+ exempted from the guard above with the note "white on a dark picture in both+ themes, because the picture is dark in both". Two of the four covers are not+ dark. It measured 1.75:1 on --paper in Chrome, with a text-shadow as the only+ thing standing between the user's words and a blank strip.++ The rule now paints its own strip, and this recomputes the ratio from the two+ literals in it against the worst backdrop that can physically exist — pure+ white — so it holds for the four covers today, for any cover added later, and+ for a real thumbnail dropped in through ProjectCard's inline background+ image, none of which this file can see. */++const linear = (channel: number) => {+ const value = channel / 255;+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;+};+const luminance = ([r, g, b]: number[]) => 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);+const contrastRatio = (a: number[], b: number[]) => {+ const [lighter, darker] = [luminance(a), luminance(b)].sort((x, y) => y - x);+ return (lighter + 0.05) / (darker + 0.05);+};++describe("the library cover caption", () => {+ const rule = block(readCss("src/styles/library.css"), "\n.project-card__art-copy {");++ it("is legible over the worst cover that could ever exist", () => {+ const ink = rule.match(/color:\s*#([0-9a-f]{3,6})\s*;/)!;+ const hex = ink[1].length === 3 ? [...ink[1]].map((digit) => digit + digit).join("") : ink[1];+ const inkRgb = [0, 2, 4].map((at) => parseInt(hex.slice(at, at + 2), 16));++ const plate = rule.match(/background:\s*rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\s*\)/)!;+ const alpha = Number(plate[4]);+ /* The strip over PURE WHITE. Any real cover is darker than white, so any+ real cover composites to something darker than this — a floor, not an+ average. It currently comes out at 14.59:1. */+ const worstBackdrop = [1, 2, 3].map((at) => alpha * Number(plate[at]) + (1 - alpha) * 255);++ expect(contrastRatio(inkRgb, worstBackdrop)).toBeGreaterThanOrEqual(4.5);+ });++ it("does not lean on a text-shadow to get there", () => {+ /* A shadow is what the old caption had instead of a plate, and it is part+ of why nobody noticed: it makes 1.75:1 look survivable in a screenshot+ while measuring the same 1.75:1. If one comes back it has to be+ decoration on top of a ratio that already passes, not the reason it+ passes. */+ expect(rule).not.toContain("text-shadow");+ });+});diff --git a/src/styles/generator.css b/src/styles/generator.cssindex ff1c708..cbfeee4 100644--- a/src/styles/generator.css+++ b/src/styles/generator.css@@ -1569,16 +1569,36 @@cursor: default;}+/* The reference's OWN picture at thumbnail size — the same file ReferencesView+ shows full size, through the same component. This used to be a hardcoded+ gradient, and since only --1 had a rule of its own, every reference but the+ second wore the identical fabricated image over a real one sitting on disk.+ A text definition, or an image file the project has lost, gets a marked tile:+ a labelled placeholder, never invented art. */.job-refs .ref-mini {grid-row: 1 / 3;+ display: grid;+ place-items: center;width: 40px;height: 40px;+ overflow: hidden;+ border: 1px solid var(--line);border-radius: var(--radius-sm);- background: linear-gradient(140deg, #304465, #a2755a);+ background: var(--panel-3);+ color: var(--text-muted);+}++.job-refs .ref-mini img {+ width: 100%;+ height: 100%;+ object-fit: cover;}-.ref-mini--1 {- background: linear-gradient(140deg, #392d40, #676b87) !important;+/* ReferenceImage says "Loading…" / "File not found" in words as well as an+ icon. At 40px there is room for the icon only; the states still differ, and+ the card in References spells both out in full. */+.job-refs .ref-mini .reference-image-fallback em {+ display: none;}.job-refs b,diff --git a/src/styles/library.css b/src/styles/library.cssindex 1ceaa30..b82adf6 100644--- a/src/styles/library.css+++ b/src/styles/library.css@@ -550,9 +550,21 @@THEME-INDEPENDENT ON PURPOSE. Everything from here to .project-card__body isa picture, not a surface: four generated cover illustrations and the badges,play button and caption that sit ON TOP of one. A cover does not become a- light-theme cover any more than a photograph does, and the chrome over it is- white-on-dark because the artwork underneath is dark in every theme. Running- these through --text-* would put dark ink on a dark picture. */+ light-theme cover any more than a photograph does, and running these through+ --text-* would put one theme's ink on a picture that is the same in both.++ The chrome over the picture is white, but NOT because the picture is dark.+ TWO OF THE FOUR ARE PALE — --paper is #cabca3 flat, and --chrome runs up to+ #dce7e7 in its highlight — so "white on a dark cover" was never true, and the+ caption sat at 1.75:1 on --paper with a text-shadow as its only defence.++ What is true, and what every rule below relies on instead: each piece of+ chrome carries its OWN dark plate and is legible against that plate alone,+ whatever the picture under it turns out to be. The badges and the play button+ always did; the caption now does too. Its plate is opaque enough to clear+ 14.5:1 over PURE WHITE, which is the only bound that survives a cover the+ code has not seen — including a real thumbnail set through+ ProjectCard's inline background-image. theme.test.ts recomputes it. */.project-card__art--aurora {background: linear-gradient(155deg, #101c38, #172d55 45%, #6e6d4d);}@@ -680,20 +692,41 @@transform: translate(-50%, -50%) scale(1);}+/* The user's own project brief, over artwork this file cannot predict. A strip+ rather than a fade, because a fade's alpha under the glyphs depends on where+ the line happens to land and no test could bound it: here every pixel behind+ the text is the same colour, so "white ink at 14.59:1 over the worst possible+ backdrop" is a fact about two numbers, not about the four covers that exist+ today. */.project-card__art-copy {position: absolute;z-index: 2;- inset: auto var(--space-3) var(--space-3);+ inset: auto 0 0;display: flex;gap: var(--space-2);align-items: center;- color: rgba(255, 255, 255, 0.88);- text-shadow: 0 1px 5px #000;+ padding: var(--space-2) var(--space-3);+ color: #fff;+ background: rgba(4, 6, 10, 0.86);font-size: var(--text-xs);line-height: var(--leading-snug);text-align: left;}+/* Feathers the top edge of that strip into the picture instead of cutting it+ with a hard line. Decoration only: no glyph sits on it, so nothing here has+ to hold a contrast ratio. */+.project-card__art-copy::before {+ content: "";+ position: absolute;+ left: 0;+ right: 0;+ bottom: 100%;+ height: var(--space-5);+ background: linear-gradient(to top, rgba(4, 6, 10, 0.86), rgba(4, 6, 10, 0));+ pointer-events: none;+}+.project-card__art-copy svg {flex: 0 0 auto;}