Explainer videos and product demos made by your AI agent. Free and open source: a local voice (Kokoro), word timing (Whisper) and a canvas renderer turn a script into a narrated MP4.
JavaScript ai-agentsanimationcanvasclaude-codecodexexplainer-videoffmpegjavascriptkokoroproduct-demotext-to-speechvideo-generationwhisper
UI kit (s.ui) for product demos: brand colors, video fonts, Instrument Serif, Unspar example
Vincent Schmalbachdd578eddb7e8
diff --git a/AGENTS.md b/AGENTS.mdindex 619573c..622cff6 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -245,6 +245,119 @@ Keep text out of images. Put words on screen with `s.text` instead. Useimages for things icons cannot show, and keep one style through the wholevideo.+## Product demos++A product demo shows an app being used, like the launch videos software+companies make. The app's screens are drawn again with `s.ui`: cards, fields,+buttons, dropdowns, toggles and status pills that look like the real app. A+cursor moves, clicks and types. The camera zooms in on what the voice talks+about, and big headlines blur in word by word. See `examples/unspar-demo` for+a full one.++**Keep it true.** A demo is advertising, so everything in it has to be right.++- Take the wording from the app itself: its templates and language files+ (for example `lang/en/*.php`, `locales/`, or the components). Copy labels,+ buttons and status names exactly.+- Show only features that exist and that customers can use. Leave out admin+ screens, debug views and plans that are not built yet.+- Example data must look like example data: `example.com`, a made up project,+ a made up article title. Never invent customers, numbers or results.+- Claims in the narration come from the product's live website. Show prices+ only if the website shows them.+- Ask the user if the website and the app say different things.++**Set up the brand** in `video.json`. Use the `clean` look.++```json+{+ "theme": "clean",+ "brand": {+ "accent": "#245cff",+ "background": "#f8f6f1",+ "font": "Figtree",+ "headline": "Instrument Serif",+ "logo": "assets/logo.svg"+ },+ "fonts": [+ { "family": "Figtree", "src": "assets/fonts/Figtree-600.woff2", "weight": 600 }+ ]+}+```++- `accent` is the main button color. Find it in the app's Tailwind config or+ CSS. `background` is the color behind the screens, `ink` the color of text+ drawn right on it.+- `font` is the app's font. Inter is built in; other fonts go in+ `assets/fonts/` and in `fonts` (`.woff2`, `.woff`, `.ttf` or `.otf`, one+ entry per weight, or `"weight": "100 900"` for a variable font, and+ `"style": "italic"`). Copy the font's license file next to it.+- `headline` is the font for big headlines. Instrument Serif is built in. If+ the brand has no serif, use its own font and pass `{ weight: 700,+ italic: false }` to `u.headline()`.+- `logo` is the product's logo from the app or website, best as SVG.++**Build a scene** in this order: background, camera, headline, screens,+cursor last so it stays on top.++```js+hook(s) {+ const u = s.ui;+ u.backdrop();+ u.floaters();+ s.camera([{ at: '#site', x: 900, y: 600, zoom: 1.3 }]);+ u.headline('Tell it what to *write about*', s.W / 2, 178, { size: 84, at: 0.15 });+ u.panel(410, 270, 1100, 600, { at: 0.3 }, (x, y, w, h) => {+ u.input(x + 56, y + 296, 560, 62, { label: 'Website URL', value: u.typed('https://example.com', '#site', 24), focus: 1, caret: true });+ u.button('Get ideas', x + 760, y + 516, 280, 60, { press: u.press('#go') });+ });+ u.cursor([+ { at: 0.5, x: 1500, y: 900 },+ { at: s.time('#site') - 0.7, x: 740, y: 596 },+ { at: '#site', click: true },+ ]);+}+```++Draw the headline after `s.camera()`, or the zoomed screens slide under it.+Time every click to a `[#mark]` in the script, so it happens when the voice+says it. Move the cursor about 0.7 seconds before the click.++**`s.ui` reference.** Positions are in the frame (1920 wide for 16:9). Times+take seconds, spoken words or `"#marks"`, like everywhere else.++| Call | What it draws |+|---|---|+| `u.backdrop(color?)`, `u.floaters({ alpha, tint })` | the brand background, and faint cards drifting around the edges (`tint: 'white'` on a colored background) |+| `u.panel(x, y, w, h, { at, out, from, rise, sfx, fill, border, lift }, fn)` | a card that pops in at `at`; `fn(x, y, w, h)` draws inside it |+| `u.card(x, y, w, h, o)` | a card without an entrance |+| `u.browser(x, y, w, h, { url, at }, fn)` | a panel with a browser bar; `fn` gets the page area |+| `u.modal(x, y, w, h, { at, out }, fn)` | a dialog over a dimmed frame |+| `u.toast(text, { at, out, icon, tone })` | a message that slides up, with a chime |+| `u.headline(text, x, y, { size, at, out, align, weight, italic })` | big text that blurs in word by word; `*stars*` mark words in the accent color |+| `u.text(text, x, y, { size, weight, color, align, font, maxW })`, `u.para(text, x, y, maxW, o)`, `u.eyebrow(text, x, y)` | text, wrapped text, and a small uppercase label |+| `u.button(label, x, y, w, h, { variant, press, icon, loading, color, caps })` | `primary`, `secondary` or `ghost` |+| `u.input(x, y, w, h, { label, value, placeholder, focus, caret, icon })` | a text field |+| `u.select(x, y, w, h, { label, value, open, options, hover, selected })` | a dropdown; returns the y of each option row |+| `u.toggle(x, y, on)`, `u.checkbox(x, y, on)`, `u.radio(x, y, on)` | `on` goes from 0 to 1, so it can animate |+| `u.chip(label, x, y, { selected })`, `u.chipWidth(label, o, selected)` | option chips; a selected chip grows by its check mark, so leave room |+| `u.pill(label, x, y, tone, { align, dot, pulse })` | a status badge: `gray`, `blue`, `yellow`, `green`, `red`, `purple` or `accent` |+| `u.spinner(x, y, r)`, `u.progress(x, y, w, p)`, `u.avatar(x, y, r, initials, { image })`, `u.icon(name, x, y, size, color)`, `u.lines(x, y, w, n)`, `u.logo(x, y, w)` | small parts; `lines` draws grey bars in place of body text |+| `u.pop(at, cx, cy, fn, { sfx })` | pops anything in around a point |+| `u.wipe(at, { color })` | the accent color spreads out until it fills the frame |+| `u.cursor(keys, { out })` | the mouse; each key `{ at, x, y }` moves it, `{ at, click: true }` clicks with a sound |+| `u.press(at)`, `u.typed(text, at, cps)`, `u.count(to, at, dur)` | a button press (0 to 1 and back), text typed so far with typing sounds, a number counting up |+| `u.colors` | `accent`, `accentDark`, `accentTint`, `background`, `ink`, `text`, `muted`, `faint`, `line`, `surface` |++`check` sees the text of `s.ui` too. It reports text that runs off the frame+(not while the camera zooms in), text that is too small and text that+overlaps. A dropdown or dialog may cover what is under it. Look at stills at+the moments the camera is zoomed in, and check the cursor does not hide the+word it points at.++A blur filter on every frame makes rendering slow. The kit blurs things once+and reuses them. Do the same if you add your own blur.+## Sizes for each platformSet `size` to the place the video goes. `explainroo formats` lists the sizes.@@ -345,6 +458,8 @@ videos/<name>/| `boil` | 0 | redraws per second of hand-drawn lines; 0 keeps them still || `watermark` | `"explainroo.com"` | small text in a corner, or `false` || `images` | none | `{ "model": "best" or "cheap", "style": "..." }` |+| `brand` | none | colors, fonts and logo for `s.ui`, see [Product demos](#product-demos) |+| `fonts` | none | the video's own font files, see [Product demos](#product-demos) |The looks:@@ -607,6 +722,9 @@ to fit the video, and it gets quieter while the voice speaks.### Colors and fonts+For product demos in a brand's own colors and fonts, see+[Product demos](#product-demos).+Color names: `accent`, `ink`, `muted`, `bg`, `surface`, `red`, `orange`,`yellow`, `green`, `teal`, `blue`, `purple`, `pink`, `gray`. Each look has itsown version of each color, so scenes keep working when you change the look.diff --git a/README.md b/README.mdindex 9d6c80e..36f0718 100644--- a/README.md+++ b/README.md@@ -83,6 +83,22 @@ agent is a separate service with its own terms and costs. For how-to topicsthe agent can also make illustrations with an AI image model throughOpenRouter. That is optional, and you pay per image.+## Product demos++explainroo can also make launch videos for software. The agent draws the+app's screens again, in the product's own colors, fonts and wording. A cursor+clicks and types through them while the voice explains what is happening.+Tell your agent which product it is and where its code or website is.++<p align="center">+ <a href="https://www.explainroo.com/videos/">+ <img src="docs/media/product-demo.webp" alt="A frame from the Unspar product demo: a form with a website field and an open dropdown" width="820">+ </a>+</p>++The files for the Unspar demo are in+[examples/unspar-demo](examples/unspar-demo).+## LooksThere are five looks: paper, clean, chalk, blueprint and midnight. These are@@ -139,7 +155,7 @@ node bin/explainroo.js doctor --fetchThen start your agent in the `explainroo` folder and ask for a video, forexample "Make a 60 second video about how HTTPS keeps a password secret."Everything the agent needs is in [AGENTS.md](AGENTS.md). The finished video-ends up in `videos/<name>/out/video.mp4`. The files for three example videos+ends up in `videos/<name>/out/video.mp4`. The files for the example videosare in [examples/](examples/). The full documentation is on[explainroo.com](https://www.explainroo.com/docs/).diff --git a/docs/media/product-demo.webp b/docs/media/product-demo.webpnew file mode 100644index 0000000..e4d355bBinary files /dev/null and b/docs/media/product-demo.webp differdiff --git a/engine/runtime.js b/engine/runtime.jsindex ce53275..725cd54 100644--- a/engine/runtime.js+++ b/engine/runtime.js@@ -8,6 +8,9 @@ import { drawTransition } from './transitions.js';import { buildPhrases, drawCaptions } from './captions.js';import { hashStr, mulberry32, suggest, contrast, opaque, withAlpha } from './util.js';import { layoutAreas } from './layout.js';+import { UI } from './ui.js';++Stage.UI = UI;const AUTO_TRANSITION = { paper: 'brush', clean: 'slide', chalk: 'brush', blueprint: 'wipe', midnight: 'zoom' };@@ -17,17 +20,23 @@ export async function fetchState() {return res.json();}-async function loadFonts(theme) {+async function loadFonts(theme, config) {const manifest = await (await fetch('/fonts/fonts.json')).json();const wanted = new Set(Object.values(theme.fonts).map((f) => f.family));+ // The UI kit (s.ui) draws app screens in Inter and headlines in Instrument Serif.wanted.add('Inter');+ wanted.add('Instrument Serif');const faces = [];- for (const f of manifest) {- if (!wanted.has(f.family)) continue;- const face = new FontFace(f.family, `url(/fonts/${f.file})`, { weight: String(f.weight), unicodeRange: f.unicodeRange, display: 'block' });+ const add = (family, url, o) => {+ const face = new FontFace(family, `url(${url})`, { weight: String(o.weight ?? 400), style: o.style ?? 'normal', unicodeRange: o.unicodeRange, display: 'block' });document.fonts.add(face);- faces.push(face.load());- }+ faces.push(face.load().catch(() => {+ throw new Error(`font "${family}" from ${url} could not be loaded`);+ }));+ };+ for (const f of manifest) if (wanted.has(f.family)) add(f.family, `/fonts/${f.file}`, f);+ // A video's own fonts, from "fonts" in video.json.+ for (const f of config.fonts || []) add(f.family, '/project/' + f.src.split('/').map(encodeURIComponent).join('/'), f);await Promise.all(faces);// Make sure every weight used by the theme is ready before the first frame.await Promise.all(Object.values(theme.fonts).map((f) => document.fonts.load(`${f.weight} 40px "${f.family}"`)));@@ -287,6 +296,7 @@ export class Engine {const { W, H } = this;const margin = Math.round(Math.min(W, H) * 0.035);const minSize = Math.round(Math.min(W, H) * 0.022);+ const uiMinSize = Math.round(Math.min(W, H) * 0.015);const reported = new Set();const once = (key, fn) => {if (reported.has(key)) return;@@ -311,21 +321,25 @@ export class Engine {const texts = this.textLog.filter((x) => !x.problem && x.alpha > 0.5);for (const tx of texts) {const label = tx.text.length > 40 ? tx.text.slice(0, 37) + '...' : tx.text;+ // UI kit text (s.ui) may leave the frame on purpose while the+ // camera zooms or pans; app screens use smaller text than slides.+ const framed = !(tx.ui && tx.zoomed);if (tx.x0 < -1 || tx.y0 < -1 || tx.x1 > W + 1 || tx.y1 > H + 1) {- once(`off:${sc.id}:${tx.text}`, () => add('error', sc.id, t, `"${label}" runs off the frame (${Math.round(tx.x0)},${Math.round(tx.y0)} to ${Math.round(tx.x1)},${Math.round(tx.y1)} in a ${W}x${H} frame)`));+ if (framed) once(`off:${sc.id}:${tx.text}`, () => add('error', sc.id, t, `"${label}" runs off the frame (${Math.round(tx.x0)},${Math.round(tx.y0)} to ${Math.round(tx.x1)},${Math.round(tx.y1)} in a ${W}x${H} frame)`));} else if (this.appArea) {const a = this.appArea;- if (tx.x0 < a.left - 2 || tx.y0 < a.top - 2 || tx.x1 > a.right + 2 || tx.y1 > a.bottom + 2) {+ if (framed && (tx.x0 < a.left - 2 || tx.y0 < a.top - 2 || tx.x1 > a.right + 2 || tx.y1 > a.bottom + 2)) {once(`app:${sc.id}:${tx.text}`, () => add('warn', sc.id, t, `"${label}" is outside the ${this.config.format} safe area (${a.left},${a.top} to ${a.right},${a.bottom}), where the app's buttons, name or caption can cover it`));}- } else if (tx.x0 < margin || tx.y0 < margin || tx.x1 > W - margin || tx.y1 > H - margin) {+ } else if (framed && (tx.x0 < margin || tx.y0 < margin || tx.x1 > W - margin || tx.y1 > H - margin)) {once(`edge:${sc.id}:${tx.text}`, () => add('warn', sc.id, t, `"${label}" sits closer than ${margin}px to the edge`));}const b = this.captionBand;if (b && tx.y1 > b.top + 2 && tx.y0 < b.bottom - 2 && tx.x1 > b.left && tx.x0 < b.right) {once(`cap:${sc.id}:${tx.text}`, () => add('warn', sc.id, t, `"${label}" is in the caption band (y ${Math.round(b.top)} to ${Math.round(b.bottom)}), where captions can cover it; keep content above s.safe.bottom (${Math.round(this.safeArea.bottom)})`));}- if (!tx.block && tx.size < minSize) once(`small:${sc.id}:${tx.text}`, () => add('warn', sc.id, t, `"${label}" is ${Math.round(tx.size)}px, hard to read (use at least ${minSize}px)`));+ const least = tx.ui ? uiMinSize : minSize;+ if (!tx.block && Math.round(tx.size) < least) once(`small:${sc.id}:${tx.text}`, () => add('warn', sc.id, t, `"${label}" is ${Math.round(tx.size)}px, hard to read (use at least ${least}px)`));const bg = opaque(tx.bg || this.theme.bg, this.theme.bg);if (typeof tx.fg === 'string' && contrast(tx.fg, bg) < 3) once(`contrast:${sc.id}:${tx.text}`, () => add('warn', sc.id, t, `"${label}" has low contrast against its background`));}@@ -336,6 +350,8 @@ export class Engine {const A = solid[a];const B = solid[b];if (A.block && B.block) continue;+ // A dropdown or dialog (s.ui) covers what is under it.+ if ((A.ui || 1) !== (B.ui || 1)) continue;const ix = Math.min(A.x1, B.x1) - Math.max(A.x0, B.x0);const iy = Math.min(A.y1, B.y1) - Math.max(A.y0, B.y0);if (ix <= 4 || iy <= 4) continue;@@ -386,7 +402,7 @@ export async function boot({ canvas, scale = 1, version = '' }) {import(`/project/scenes.js?v=${encodeURIComponent(version || state.version)}`),import('/engine/audio/soundtrack.js').catch((e) => ({ SFX: {}, loadError: e })),fetch('/engine/icons/lucide-tags.json').then((r) => r.json()),- loadFonts(theme),+ loadFonts(theme, state.config),]);const scenes = scenesMod.default;if (!scenes || typeof scenes !== 'object') throw new Error('scenes.js must "export default { sceneId(s) { ... } }"');diff --git a/engine/stage.js b/engine/stage.jsindex 9a7f2a5..5b1e3e4 100644--- a/engine/stage.js+++ b/engine/stage.js@@ -54,6 +54,17 @@ export class Stage {this._ids = new Map();this._kindSeq = Object.create(null);this._suppress = 0;+ this._camMoved = false;+ }++ // The UI kit for product demos (engine/ui.js): app cards, fields, buttons,+ // a clicking cursor and serif headlines, in the colors from "brand".+ get ui() {+ if (!this._ui) {+ if (!Stage.UI) throw new SceneError('the UI kit is not loaded');+ this._ui = new Stage.UI(this);+ }+ return this._ui;}// ---------- time ----------@@ -346,6 +357,8 @@ export class Stage {fg: entry.fg,bg: entry.bg,block: !!entry.block,+ ui: entry.ui || 0,+ zoomed: !!entry.zoomed,});}@@ -395,6 +408,7 @@ export class Stage {cur = { x: lerp(prev.x, k.x, p), y: lerp(prev.y, k.y, p), zoom: lerp(prev.zoom, k.zoom, p), rotate: lerp(prev.rotate || 0, k.rotate || 0, p) };}const ctx = this.ctx;+ this._camMoved = cur.zoom !== 1 || cur.x !== this.cx || cur.y !== this.cy || Boolean(cur.rotate) || Boolean(o.shake);ctx.translate(this.cx, this.cy);if (cur.rotate) ctx.rotate((cur.rotate * Math.PI) / 180);ctx.scale(cur.zoom, cur.zoom);diff --git a/engine/ui.js b/engine/ui.jsnew file mode 100644index 0000000..28e0a86--- /dev/null+++ b/engine/ui.js@@ -0,0 +1,926 @@+// The UI kit behind s.ui: crisp app screens for product demos. Cards,+// buttons, fields, dropdowns, toggles, status pills, a mouse cursor that+// clicks and types, and serif headlines that blur in word by word.+//+// Everything is drawn in the frame's design space, so s.camera() can zoom+// into it. Times are scene seconds, spoken words or "#marks", and pace+// applies, like everywhere else. Colors, fonts and the logo come from+// "brand" in video.json.++import { SceneError } from './stage.js';++const clamp = (v, a = 0, b = 1) => Math.max(a, Math.min(b, v));+const lerp = (a, b, p) => a + (b - a) * p;+const outCubic = (p) => 1 - Math.pow(1 - p, 3);+const inOutCubic = (p) => (p < 0.5 ? 4 * p * p * p : 1 - Math.pow(-2 * p + 2, 3) / 2);+const outBack = (p) => 1 + 2.70158 * Math.pow(p - 1, 3) + 1.70158 * Math.pow(p - 1, 2);+// 0 -> 1 -> 0 over p in 0..1, for a press.+const bell = (p) => (p <= 0 || p >= 1 ? 0 : Math.sin(Math.PI * p));++function rgb(hex) {+ const n = parseInt(hex.slice(1), 16);+ return [(n >> 16) & 255, (n >> 8) & 255, n & 255];+}++function mix(a, b, p) {+ const A = rgb(a);+ const B = rgb(b);+ const h = (i) => Math.round(lerp(A[i], B[i], p)).toString(16).padStart(2, '0');+ return `#${h(0)}${h(1)}${h(2)}`;+}++const TONES = {+ gray: { bg: '#f2f4f7', fg: '#344054', ring: '#d0d5dd' },+ blue: { bg: '#eff8ff', fg: '#175cd3', ring: '#b2ddff' },+ yellow: { bg: '#fffaeb', fg: '#b54708', ring: '#fedf89' },+ green: { bg: '#ecfdf3', fg: '#067647', ring: '#abefc6' },+ red: { bg: '#fef3f2', fg: '#b42318', ring: '#fecdca' },+ purple: { bg: '#f4f3ff', fg: '#5925dc', ring: '#d9d6fe' },+};++// Faint cards scattered around the edges, for depth behind the UI.+const FLOATERS = [+ { x: 0.078, y: 0.157, r: -7 }, { x: 0.917, y: 0.139, r: 6 }, { x: 0.057, y: 0.519, r: 4 },+ { x: 0.943, y: 0.556, r: -5 }, { x: 0.12, y: 0.87, r: 8 }, { x: 0.88, y: 0.889, r: -8 },+ { x: 0.365, y: 0.954, r: 3 }, { x: 0.635, y: 0.037, r: -3 },+];++export class UI {+ constructor(s) {+ this.s = s;+ this.c = s.ctx;+ const th = s.theme;+ const b = s.engine.config.brand || {};+ const accent = b.accent ?? th.colors[th.accent];+ this.font = b.font ?? 'Inter';+ this.headlineFont = b.headline ?? 'Instrument Serif';+ this.logoSrc = b.logo ?? null;+ // App screens are light; `ink` is for text drawn straight on the background.+ this.colors = {+ accent,+ accentDark: mix(accent, '#000000', 0.16),+ accentTint: mix(accent, '#ffffff', 0.91),+ accentRing: mix(accent, '#ffffff', 0.55),+ background: b.background ?? th.bg,+ ink: b.ink ?? th.ink,+ text: '#18202c',+ soft: '#526071',+ muted: '#667085',+ faint: '#98a2b3',+ line: '#e4e7ec',+ field: '#d0d5dd',+ surface: '#ffffff',+ panel: '#f5f7fb',+ };+ this._layer = 0;+ }++ // Scale of the current transform. Canvas shadows and blur filters work in+ // device pixels, so they are multiplied by this to zoom with the camera.+ get k() {+ const m = this.c.getTransform();+ return Math.hypot(m.a, m.b);+ }++ at(v) {+ return this.s.time(v);+ }++ _p(at, dur, easing = 'out') {+ return this.s.p(at, dur, easing);+ }++ fontString(size, weight = 400, family = this.font, italic = false) {+ return `${italic ? 'italic ' : ''}${weight} ${size}px "${family}", Inter, sans-serif`;+ }++ _family(f) {+ if (!f || f === 'ui') return this.font;+ if (f === 'headline') return this.headlineFont;+ return f;+ }++ // An entrance, so `check` knows something new appears and a sound can play.+ _enter(at, dur, sfx) {+ this.s._record('ui', at, dur, { sfx: sfx ?? null });+ }++ // ---------- surfaces ----------++ backdrop(color = this.colors.background) {+ const c = this.c;+ c.save();+ c.setTransform(this.s.engine.scale, 0, 0, this.s.engine.scale, 0, 0);+ c.fillStyle = color;+ c.fillRect(0, 0, this.s.W, this.s.H);+ c.restore();+ }++ // Faint app cards drifting around the edges, out of focus. Each card is+ // blurred once and reused, because a blur filter on every frame is slow.+ floaters(o = {}) {+ const s = this.s;+ const c = this.c;+ const tint = o.tint ?? 'card';+ const cache = (s.engine._uiSprites ??= new Map());+ FLOATERS.forEach((f, i) => {+ const key = `${i % 3}|${tint}`;+ if (!cache.has(key)) cache.set(key, this._floaterSprite(i, tint));+ const dx = Math.sin(s.T * 0.25 + i * 1.7) * 14;+ const dy = Math.cos(s.T * 0.3 + i * 2.1) * 12;+ c.save();+ c.globalAlpha *= o.alpha ?? 0.55;+ c.translate(f.x * s.W + dx, f.y * s.H + dy);+ c.rotate((f.r * Math.PI) / 180);+ c.drawImage(cache.get(key), -210, -140, 420, 280);+ c.restore();+ });+ }++ _floaterSprite(i, tint) {+ const k = 2;+ const cv = new OffscreenCanvas(420 * k, 280 * k);+ const c = cv.getContext('2d');+ c.scale(k, k);+ c.translate(210, 140);+ c.scale(0.62, 0.62);+ const bar = (x, y, w) => {+ c.beginPath();+ c.roundRect(x, y, w, 10, 5);+ c.fill();+ };+ if (tint === 'white') {+ c.fillStyle = 'rgba(255, 255, 255, 0.9)';+ c.beginPath();+ c.roundRect(-150, -80, 300, 160, 16);+ c.fill();+ c.fillStyle = 'rgba(255, 255, 255, 0.55)';+ } else {+ c.shadowColor = 'rgba(16, 24, 40, 0.08)';+ c.shadowBlur = 24 * k;+ c.shadowOffsetY = 8 * k;+ c.fillStyle = '#ffffff';+ c.beginPath();+ c.roundRect(-150, -80, 300, 160, 16);+ c.fill();+ c.shadowColor = 'transparent';+ c.strokeStyle = this.colors.line;+ c.lineWidth = 1.5;+ c.stroke();+ c.fillStyle = ['#dbe7ff', '#fde7d9', '#dcfae6'][i % 3];+ c.beginPath();+ c.arc(-112, -44, 16, 0, Math.PI * 2);+ c.fill();+ c.fillStyle = '#e4e8ef';+ }+ bar(-84, -52, 170);+ [0, 1, 2].forEach((j) => bar(-122, -4 + j * 22, [240, 220, 150][j]));+ const out = new OffscreenCanvas(420 * k, 280 * k);+ const oc = out.getContext('2d');+ oc.filter = `blur(${1.6 * k}px)`;+ oc.drawImage(cv, 0, 0);+ return out;+ }++ card(x, y, w, h, o = {}) {+ const c = this.c;+ const r = o.r ?? 18;+ const k = this.k;+ c.save();+ c.globalAlpha *= o.alpha ?? 1;+ c.beginPath();+ c.roundRect(x, y, w, h, r);+ c.fillStyle = o.fill ?? this.colors.surface;+ if (o.shadow !== false) {+ const lift = o.lift ?? 1;+ c.shadowColor = `rgba(16, 24, 40, ${0.05 * lift})`;+ c.shadowBlur = 3 * k;+ c.shadowOffsetY = 1 * k;+ c.fill();+ c.shadowColor = `rgba(16, 24, 40, ${0.09 * lift})`;+ c.shadowBlur = 48 * lift * k;+ c.shadowOffsetY = 18 * lift * k;+ }+ c.fill();+ c.shadowColor = 'transparent';+ if (o.border !== false) {+ c.strokeStyle = o.border ?? this.colors.line;+ c.lineWidth = o.borderWidth ?? 1.5;+ c.stroke();+ }+ c.restore();+ }++ // A card that pops up at `at`, then fn(x, y, w, h) draws inside it.+ // Returns the entrance progress (0 before `at`).+ panel(x, y, w, h, o = {}, fn) {+ if (typeof o === 'function') [o, fn] = [{}, o];+ const s = this.s;+ const a = this.at(o.at ?? 0);+ const dur = o.dur ?? 0.6;+ this._enter(a, dur, o.sfx);+ if (s.t < a) return 0;+ const p = clamp((s.t - a) / (dur / s.pace));+ const q = o.out !== undefined ? this._p(o.out, o.outDur ?? 0.35, 'in') : 0;+ if (q >= 1) return p;+ const c = this.c;+ const sc = lerp(o.from ?? 0.94, 1, outBack(p)) * (1 - 0.03 * q);+ c.save();+ c.globalAlpha *= clamp(p * 2.5) * (1 - q);+ c.translate(x + w / 2, y + h / 2 + (1 - outCubic(p)) * (o.rise ?? 30));+ c.scale(sc, sc);+ c.translate(-(x + w / 2), -(y + h / 2));+ this.card(x, y, w, h, o);+ if (fn) fn(x, y, w, h);+ c.restore();+ return p;+ }++ // A panel with a browser bar and an address. fn gets the page area.+ browser(x, y, w, h, o = {}, fn) {+ if (typeof o === 'function') [o, fn] = [{}, o];+ const bar = o.bar ?? 50;+ return this.panel(x, y, w, h, o, () => {+ const c = this.c;+ c.save();+ c.beginPath();+ c.roundRect(x, y, w, bar, [o.r ?? 18, o.r ?? 18, 0, 0]);+ c.fillStyle = '#f2f4f7';+ c.fill();+ ['#f97066', '#fdb022', '#32d583'].forEach((col, i) => {+ c.beginPath();+ c.arc(x + 28 + i * 22, y + bar / 2, 7, 0, Math.PI * 2);+ c.fillStyle = col;+ c.fill();+ });+ c.beginPath();+ c.roundRect(x + 110, y + 11, w - 140, bar - 22, (bar - 22) / 2);+ c.fillStyle = '#ffffff';+ c.fill();+ c.restore();+ if (o.url) this.text(o.url, x + 128, y + bar / 2 + 1, { size: 16, color: this.colors.muted, maxW: w - 170 });+ if (fn) fn(x, y + bar, w, h - bar);+ });+ }++ // A dialog over a dimmed frame. Everything drawn in fn sits on top of+ // what is below, so `check` does not report it as overlapping.+ modal(x, y, w, h, o = {}, fn) {+ if (typeof o === 'function') [o, fn] = [{}, o];+ const s = this.s;+ const a = this.at(o.at ?? 0);+ if (s.t < a) return 0;+ const q = o.out !== undefined ? this._p(o.out, 0.3, 'in') : 0;+ if (q >= 1) return 1;+ const p = this._p(a, 0.35);+ const c = this.c;+ if (o.dim !== false) {+ c.save();+ c.setTransform(s.engine.scale, 0, 0, s.engine.scale, 0, 0);+ c.fillStyle = `rgba(16, 24, 40, ${(o.dim ?? 0.28) * p * (1 - q)})`;+ c.fillRect(0, 0, s.W, s.H);+ c.restore();+ }+ return this.over(() => this.panel(x, y, w, h, { r: 20, lift: 1.4, ...o, at: a, dur: 0.45 }, fn));+ }++ // A short message card that slides up, like "Saved" or "Sent".+ toast(label, o = {}) {+ const a = this.at(o.at ?? 0);+ const s = this.s;+ if (s.t < a) return;+ if (o.out !== undefined && s.t >= this.at(o.out) + 0.4) return;+ const size = o.size ?? 22;+ const w = this.measure(label, size, 600) + (o.icon === false ? 64 : 100);+ const x = (o.x ?? s.W / 2) - w / 2;+ const y = o.y ?? s.H - 150;+ const tone = TONES[o.tone ?? 'green'] || TONES.green;+ this.over(() => {+ this.panel(x, y, w, 72, { at: a, out: o.out, r: 16, lift: 0.9, rise: 40, from: 0.9, sfx: o.sfx === undefined ? 'chime' : o.sfx }, () => {+ let tx = x + 32;+ if (o.icon !== false) {+ this.icon(o.icon ?? 'circle-check', x + 40, y + 36, 30, tone.fg, 2.2);+ tx = x + 70;+ }+ this.text(label, tx, y + 37, { size, weight: 600 });+ });+ });+ }++ // Brand color spreading from a point until it fills the frame.+ wipe(at, o = {}) {+ const s = this.s;+ const a = this.at(at);+ if (s.t < a) return 0;+ if (o.sfx !== null) s.sfx(o.sfx ?? 'swipe', a);+ const p = this._p(a, o.dur ?? 0.7, 'inOut');+ const x = o.x ?? s.W / 2;+ const y = o.y ?? s.H / 2;+ const c = this.c;+ c.save();+ c.beginPath();+ c.arc(x, y, lerp(0, Math.hypot(Math.max(x, s.W - x), Math.max(y, s.H - y)) + 20, p), 0, Math.PI * 2);+ c.fillStyle = o.color ?? this.colors.accent;+ c.fill();+ c.restore();+ return p;+ }++ // Scales something in around (cx, cy) with a little overshoot at `at`.+ pop(at, cx, cy, fn, o = {}) {+ const s = this.s;+ const a = this.at(at);+ this._enter(a, o.dur ?? 0.45, o.sfx);+ if (s.t < a) return 0;+ const p = this._p(a, o.dur ?? 0.45, 'outBack');+ const c = this.c;+ c.save();+ c.globalAlpha *= clamp(p * 2);+ c.translate(cx, cy);+ const sc = lerp(o.from ?? 0.7, 1, p);+ c.scale(sc, sc);+ c.translate(-cx, -cy);+ fn(p);+ c.restore();+ return p;+ }++ // Draws fn as a layer on top of what is already there (menus, dialogs).+ over(fn) {+ this._layer++;+ try {+ return fn();+ } finally {+ this._layer--;+ }+ }++ // ---------- text ----------++ _log(str, x, y, w, size, align, base) {+ if (!str.trim()) return;+ const x0 = align === 'center' ? x - w / 2 : align === 'right' ? x - w : x;+ const [t, b] = base === 'top' ? [0, 1.2] : base === 'alphabetic' ? [-0.8, 0.22] : [-0.6, 0.6];+ this.s._logText({ text: str, x0, y0: y + t * size, x1: x0 + w, y1: y + b * size, size, fg: null, bg: null, ui: this._layer + 1, zoomed: this.s._camMoved });+ }++ text(str, x, y, o = {}) {+ const c = this.c;+ const size = o.size ?? 22;+ c.save();+ c.font = this.fontString(size, o.weight ?? 400, this._family(o.font), o.italic);+ c.fillStyle = o.color ?? this.colors.text;+ const align = o.align ?? 'left';+ const base = o.base ?? 'middle';+ c.textAlign = align;+ c.textBaseline = base;+ c.letterSpacing = `${o.tracking ?? 0}px`;+ c.globalAlpha *= o.alpha ?? 1;+ let t = String(str);+ if (o.maxW && c.measureText(t).width > o.maxW) {+ while (t.length > 1 && c.measureText(t + '…').width > o.maxW) t = t.slice(0, -1);+ t = t.trimEnd() + '…';+ }+ c.fillText(t, x, y);+ const w = c.measureText(t).width;+ if (o.check !== false) this._log(t, x, y, w, size, align, base);+ c.restore();+ return w;+ }++ measure(str, size, weight = 400, font, italic = false, tracking = 0) {+ const c = this.c;+ c.save();+ c.font = this.fontString(size, weight, this._family(font), italic);+ c.letterSpacing = `${tracking}px`;+ const w = c.measureText(String(str)).width;+ c.restore();+ return w;+ }++ // Wraps text to maxW and draws it from the top. Returns the height.+ para(str, x, y, maxW, o = {}) {+ const size = o.size ?? 22;+ const lh = o.lh ?? size * 1.45;+ const lines = [];+ let cur = '';+ for (const w of String(str).split(/\s+/)) {+ const next = cur ? cur + ' ' + w : w;+ if (cur && this.measure(next, size, o.weight ?? 400, o.font) > maxW) {+ lines.push(cur);+ cur = w;+ } else cur = next;+ }+ if (cur) lines.push(cur);+ lines.forEach((l, i) => this.text(l, x, y + i * lh, { ...o, base: 'top' }));+ return lines.length * lh;+ }++ // Small uppercase label above a heading.+ eyebrow(str, x, y, o = {}) {+ return this.text(String(str).toUpperCase(), x, y, { size: 17, weight: 700, color: this.colors.accent, tracking: 2.2, ...o });+ }++ // A headline that blurs in word by word, in the headline font. Wrap words+ // in *stars* to set them in the accent color, in italic unless+ // italic: false (for a brand font without an italic).+ headline(str, x, y, o = {}) {+ const s = this.s;+ const c = this.c;+ const size = o.size ?? 96;+ const family = this._family(o.font ?? 'headline');+ const tracking = o.tracking ?? -1;+ const tokens = [];+ let italic = false;+ for (const raw of String(str).split(' ')) {+ let w = raw;+ const starts = w.startsWith('*');+ if (starts) w = w.slice(1);+ const ends = w.endsWith('*');+ if (ends) w = w.slice(0, -1);+ if (starts) italic = true;+ tokens.push({ w, italic, accent: italic });+ if (ends) italic = false;+ }+ if (o.italic === false) tokens.forEach((t) => (t.italic = false));+ const widths = tokens.map((t) => this.measure(t.w, size, o.weight ?? 400, family, t.italic, tracking));+ const space = this.measure(' ', size, 400, family) * 0.9;+ const total = widths.reduce((a, b) => a + b, 0) + space * (tokens.length - 1);+ let cx = o.align === 'left' ? x : o.align === 'right' ? x - total : x - total / 2;+ const a = this.at(o.at ?? 0);+ const stagger = (o.stagger ?? 0.07) / s.pace;+ const dur = (o.dur ?? 0.7) / s.pace;+ this._enter(a, dur + stagger * tokens.length, o.sfx);+ const k = this.k;+ tokens.forEach((t, i) => {+ const e = outCubic(clamp((s.t - (a + i * stagger)) / dur));+ const q = o.out !== undefined ? this._p(this.at(o.out) + i * stagger * 0.4, 0.35, 'in') : 0;+ const alpha = e * (1 - q);+ if (alpha > 0.002) {+ const blur = (1 - e) * 14 + q * 10;+ c.save();+ if (blur > 0.3) c.filter = `blur(${(blur * k).toFixed(2)}px)`;+ this.text(t.w, cx, y + (1 - e) * 22 - q * 14, {+ size,+ font: family,+ italic: t.italic,+ weight: o.weight ?? 400,+ color: t.accent ? o.accent ?? this.colors.accent : o.color ?? this.colors.ink,+ alpha,+ tracking,+ base: 'alphabetic',+ });+ c.restore();+ }+ cx += widths[i] + space;+ });+ return total;+ }++ // ---------- controls ----------++ // tone: gray, blue, yellow, green, red, purple or accent.+ pill(label, x, y, tone = 'gray', o = {}) {+ const T = tone === 'accent' ? { bg: this.colors.accentTint, fg: this.colors.accentDark, ring: this.colors.accentRing } : TONES[tone];+ if (!T) throw new SceneError(`pill tone must be one of ${Object.keys(TONES).join(', ')} or accent, not "${tone}"`);+ const size = o.size ?? 17;+ const dot = o.dot ?? false;+ const padX = size * 0.75;+ const h = size * 1.75;+ const w = this.measure(label, size, 600) + padX * 2 + (dot ? size * 0.85 : 0);+ const c = this.c;+ const left = o.align === 'right' ? x - w : o.align === 'center' ? x - w / 2 : x;+ c.save();+ c.globalAlpha *= o.alpha ?? 1;+ c.beginPath();+ c.roundRect(left, y - h / 2, w, h, h / 2);+ c.fillStyle = T.bg;+ c.fill();+ c.strokeStyle = T.ring;+ c.lineWidth = 1.5;+ c.stroke();+ let tx = left + padX;+ if (dot) {+ const pulse = o.pulse ? 0.5 + 0.5 * Math.sin(this.s.t * 6) : 1;+ c.save();+ c.beginPath();+ c.arc(tx + size * 0.25, y, size * 0.25, 0, Math.PI * 2);+ c.fillStyle = T.fg;+ c.globalAlpha *= 0.45 + 0.55 * pulse;+ c.fill();+ c.restore();+ tx += size * 0.85;+ }+ this.text(label, tx, y + 0.5, { size, weight: 600, color: T.fg });+ c.restore();+ return w;+ }++ // variant: primary, secondary or ghost. press: 0..1, from u.press(at).+ // color: another fill for a primary button. caps: uppercase label.+ button(label, x, y, w, h, o = {}) {+ const c = this.c;+ const v = o.variant ?? 'primary';+ const press = o.press ?? 0;+ const hover = o.hover ?? 0;+ const C = this.colors;+ const fill = o.color ?? C.accent;+ if (o.caps) label = String(label).toUpperCase();+ c.save();+ c.globalAlpha *= o.alpha ?? 1;+ c.translate(x + w / 2, y + h / 2);+ c.scale(1 - 0.04 * press, 1 - 0.04 * press);+ c.translate(-(x + w / 2), -(y + h / 2));+ c.beginPath();+ c.roundRect(x, y, w, h, o.r ?? 12);+ if (v === 'primary') {+ const k = this.k;+ const [r, g, b] = rgb(fill);+ c.shadowColor = `rgba(${r}, ${g}, ${b}, ${0.28 * (1 - press)})`;+ c.shadowBlur = 16 * k;+ c.shadowOffsetY = 6 * k;+ c.fillStyle = mix(fill, '#000000', 0.16 * clamp(hover + press));+ c.fill();+ } else if (v === 'secondary') {+ c.fillStyle = mix('#ffffff', '#f2f4f7', clamp(hover + press));+ c.fill();+ c.strokeStyle = C.field;+ c.lineWidth = 1.5;+ c.stroke();+ } else if (hover + press > 0) {+ c.fillStyle = `rgba(16, 24, 40, ${0.05 * clamp(hover + press)})`;+ c.fill();+ }+ c.shadowColor = 'transparent';+ const size = o.size ?? (o.caps ? 18 : 21);+ const tracking = o.caps ? 1.6 : 0;+ const color = v === 'primary' ? '#ffffff' : v === 'ghost' ? C.accent : C.text;+ const labelW = this.measure(label, size, 600, undefined, false, tracking);+ const iconSize = size * 1.05;+ const gap = o.icon || o.loading ? iconSize + 10 : 0;+ let lx = x + w / 2 - (labelW + gap) / 2;+ if (o.loading) {+ this.spinner(lx + iconSize / 2, y + h / 2, iconSize / 2.4, color);+ lx += gap;+ } else if (o.icon) {+ this.icon(o.icon, lx + iconSize / 2, y + h / 2, iconSize, color, 2.2);+ lx += gap;+ }+ this.text(label, lx, y + h / 2 + 0.5, { size, weight: 600, color, tracking });+ c.restore();+ }++ input(x, y, w, h, o = {}) {+ const c = this.c;+ const C = this.colors;+ const focus = o.focus ?? 0;+ const size = o.size ?? 21;+ c.save();+ c.globalAlpha *= o.alpha ?? 1;+ if (o.label) this.text(o.label, x, y - 24, { size: 19, weight: 600 });+ if (focus > 0) {+ const [r, g, b] = rgb(C.accent);+ c.beginPath();+ c.roundRect(x - 4, y - 4, w + 8, h + 8, 14);+ c.fillStyle = `rgba(${r}, ${g}, ${b}, ${0.16 * focus})`;+ c.fill();+ }+ c.beginPath();+ c.roundRect(x, y, w, h, 11);+ c.fillStyle = '#ffffff';+ c.fill();+ c.strokeStyle = mix(C.field, C.accent, focus);+ c.lineWidth = 1.5;+ c.stroke();+ const pad = 18;+ let tx = x + pad;+ if (o.icon) {+ this.icon(o.icon, tx + 11, y + h / 2, 22, C.faint, 2);+ tx += 34;+ }+ const room = w - (tx - x) - pad - (o.room ?? 0);+ const value = o.value ?? '';+ if (value) this.text(value, tx, y + h / 2 + 0.5, { size, maxW: room });+ else if (o.placeholder) this.text(o.placeholder, tx, y + h / 2 + 0.5, { size, color: C.faint, maxW: room });+ if (o.caret && focus > 0.5 && Math.floor(this.s.t * 2.2) % 2 === 0) {+ const cx = tx + (value ? Math.min(this.measure(value, size), room) : 0) + 2;+ c.fillStyle = C.text;+ c.fillRect(cx, y + h / 2 - size * 0.6, 2, size * 1.2);+ }+ c.restore();+ }++ // A dropdown. open 0..1 shows the menu below it, hover is the index of the+ // highlighted option, selected gets a check. Returns each option row's+ // center y, for pointing the cursor at it.+ select(x, y, w, h, o = {}) {+ const C = this.colors;+ const open = o.open ?? 0;+ this.input(x, y, w, h, { label: o.label, value: o.value, placeholder: o.placeholder, focus: o.focus ?? open, alpha: o.alpha, size: o.size, room: 30 });+ this.icon('chevron-down', x + w - 30, y + h / 2, 24, C.muted, 2);+ const rowH = o.rowH ?? 54;+ const opts = o.options ?? [];+ const my = y + h + 12;+ const rows = opts.map((_, i) => my + 8 + i * rowH + rowH / 2);+ if (open <= 0.001) return rows;+ const c = this.c;+ this.over(() => {+ c.save();+ c.globalAlpha *= clamp(open * 1.6) * (o.alpha ?? 1);+ c.translate(x + w / 2, my);+ c.scale(1, lerp(0.92, 1, outCubic(open)));+ c.translate(-(x + w / 2), -my);+ this.card(x, my, w, opts.length * rowH + 16, { r: 14, lift: 0.8 });+ opts.forEach((label, i) => {+ const ry = my + 8 + i * rowH;+ if (o.hover === i) {+ c.beginPath();+ c.roundRect(x + 8, ry, w - 16, rowH, 9);+ c.fillStyle = C.accentTint;+ c.fill();+ }+ const chosen = o.selected === i;+ this.text(label, x + 24, ry + rowH / 2 + 0.5, { size: o.size ?? 21, weight: chosen ? 600 : 400, color: chosen ? C.accent : C.text, maxW: w - 80 });+ if (chosen) this.icon('check', x + w - 34, ry + rowH / 2, 22, C.accent, 2.4);+ });+ c.restore();+ });+ return rows;+ }++ toggle(x, y, on, o = {}) {+ const c = this.c;+ const w = o.w ?? 64;+ const h = o.h ?? 36;+ const p = clamp(on);+ c.save();+ c.globalAlpha *= o.alpha ?? 1;+ c.beginPath();+ c.roundRect(x, y - h / 2, w, h, h / 2);+ c.fillStyle = mix('#e4e7ec', this.colors.accent, p);+ c.fill();+ const r = h / 2 - 4;+ const kx = lerp(x + 4 + r, x + w - 4 - r, outBack(p));+ const k = this.k;+ c.shadowColor = 'rgba(16, 24, 40, 0.18)';+ c.shadowBlur = 6 * k;+ c.shadowOffsetY = 2 * k;+ c.beginPath();+ c.arc(kx, y, r, 0, Math.PI * 2);+ c.fillStyle = '#ffffff';+ c.fill();+ c.restore();+ }++ checkbox(x, y, on, o = {}) {+ const c = this.c;+ const size = o.size ?? 26;+ const p = clamp(on);+ c.save();+ c.globalAlpha *= o.alpha ?? 1;+ c.beginPath();+ c.roundRect(x - size / 2, y - size / 2, size, size, 7);+ c.fillStyle = mix('#ffffff', this.colors.accent, p);+ c.fill();+ c.strokeStyle = mix(this.colors.field, this.colors.accent, p);+ c.lineWidth = 1.5;+ c.stroke();+ if (p > 0.05) {+ c.globalAlpha *= clamp(p * 2);+ this.icon('check', x, y, size * 0.72, '#ffffff', 3.2);+ }+ c.restore();+ }++ radio(x, y, on, o = {}) {+ const c = this.c;+ const r = (o.size ?? 26) / 2;+ const p = clamp(on);+ c.save();+ c.globalAlpha *= o.alpha ?? 1;+ c.beginPath();+ c.arc(x, y, r, 0, Math.PI * 2);+ c.fillStyle = '#ffffff';+ c.fill();+ c.strokeStyle = mix(this.colors.field, this.colors.accent, p);+ c.lineWidth = 2;+ c.stroke();+ if (p > 0) {+ c.beginPath();+ c.arc(x, y, r * 0.55 * outBack(p), 0, Math.PI * 2);+ c.fillStyle = this.colors.accent;+ c.fill();+ }+ c.restore();+ }++ // A selectable option chip. It grows by its check mark when selected, so+ // leave that room (u.chipWidth(label, o, true)) next to it.+ chip(label, x, y, o = {}) {+ const c = this.c;+ const C = this.colors;+ const size = o.size ?? 20;+ const sel = clamp(o.selected ?? 0);+ const h = size * 2.2;+ const w = this.measure(label, size, 500) + size * 1.6 + sel * size * 1.1;+ c.save();+ c.globalAlpha *= o.alpha ?? 1;+ c.beginPath();+ c.roundRect(x, y - h / 2, w, h, h / 2);+ c.fillStyle = mix('#ffffff', C.accentTint, sel);+ c.fill();+ c.strokeStyle = mix(C.field, C.accent, sel);+ c.lineWidth = 1.5 + sel;+ c.stroke();+ let tx = x + size * 0.8;+ if (sel > 0.05) {+ c.save();+ c.globalAlpha *= sel;+ this.icon('check', tx + size * 0.4, y, size * 0.85, C.accent, 2.6);+ c.restore();+ tx += sel * size * 1.1;+ }+ this.text(label, tx, y + 0.5, { size, weight: sel > 0.5 ? 600 : 500, color: mix(C.text, C.accent, sel) });+ c.restore();+ return w;+ }++ chipWidth(label, o = {}, selected = false) {+ const size = o.size ?? 20;+ return this.measure(label, size, selected ? 600 : 500) + size * 1.6 + (selected ? size * 1.1 : 0);+ }++ spinner(x, y, r, color = this.colors.accent) {+ const c = this.c;+ const a = this.s.t * 7;+ c.save();+ c.lineWidth = Math.max(2, r * 0.32);+ c.lineCap = 'round';+ c.strokeStyle = color;+ c.globalAlpha *= 0.25;+ c.beginPath();+ c.arc(x, y, r, 0, Math.PI * 2);+ c.stroke();+ c.globalAlpha /= 0.25;+ c.beginPath();+ c.arc(x, y, r, a, a + Math.PI * 0.6);+ c.stroke();+ c.restore();+ }++ progress(x, y, w, p, o = {}) {+ const c = this.c;+ const h = o.h ?? 10;+ c.save();+ c.beginPath();+ c.roundRect(x, y - h / 2, w, h, h / 2);+ c.fillStyle = '#eaecf0';+ c.fill();+ if (p > 0) {+ c.beginPath();+ c.roundRect(x, y - h / 2, Math.max(h, w * clamp(p)), h, h / 2);+ c.fillStyle = o.color ?? this.colors.accent;+ c.fill();+ }+ c.restore();+ }++ avatar(x, y, r, initials = '', o = {}) {+ const c = this.c;+ c.save();+ c.beginPath();+ c.arc(x, y, r, 0, Math.PI * 2);+ c.fillStyle = o.bg ?? this.colors.accentTint;+ c.fill();+ if (o.image) {+ const img = this.s.engine.image(o.image);+ c.clip();+ const side = Math.min(img.naturalWidth, img.naturalHeight);+ c.drawImage(img, (img.naturalWidth - side) / 2, (img.naturalHeight - side) / 2, side, side, x - r, y - r, r * 2, r * 2);+ }+ c.restore();+ if (initials && !o.image) this.text(initials, x, y + 1, { size: r * 0.8, weight: 600, color: o.color ?? this.colors.accent, align: 'center' });+ }++ icon(name, x, y, size, color = this.colors.text, weight = 2) {+ this.s._iconAt(name, x, y, size, color, 1, 1, weight);+ }++ // Grey bars standing in for text, for article bodies and backgrounds.+ lines(x, y, w, n, o = {}) {+ const c = this.c;+ const gap = o.gap ?? 22;+ c.save();+ c.fillStyle = o.color ?? '#e9edf3';+ for (let i = 0; i < n; i++) {+ const lw = i === n - 1 ? w * (o.last ?? 0.6) : w * (0.88 + 0.12 * Math.abs(Math.sin(i * 7.3 + (o.seed ?? 0))));+ c.beginPath();+ c.roundRect(x, y + i * gap, lw, o.h ?? 9, (o.h ?? 9) / 2);+ c.fill();+ }+ c.restore();+ }++ // The brand logo (brand.logo in video.json, or o.src), w wide, centered on+ // (x, y) unless align is "left". Returns its height.+ logo(x, y, w, o = {}) {+ const src = o.src ?? this.logoSrc;+ if (!src) throw new SceneError('u.logo() needs a logo: set "brand": { "logo": "assets/logo.svg" } in video.json or pass { src }');+ const img = this.s.engine.image(src);+ const h = (w * img.naturalHeight) / img.naturalWidth;+ const c = this.c;+ c.save();+ c.globalAlpha *= o.alpha ?? 1;+ c.drawImage(img, o.align === 'left' ? x : x - w / 2, y - h / 2, w, h);+ c.restore();+ return h;+ }++ // ---------- the cursor ----------++ // keys: [{ at, x, y }, ...]. The first key places the cursor; each later+ // one with x, y glides it there starting at `at` (dur, default 0.7 s). A+ // key with click: true presses at `at` and plays a click. Draw the cursor+ // last so it sits on top. Returns { x, y, press } or null before it shows.+ cursor(keys, o = {}) {+ const s = this.s;+ const first = keys[0];+ const start = this.at(first.at ?? 0);+ let x = first.x;+ let y = first.y;+ let press = 0;+ const ripples = [];+ for (let i = 1; i < keys.length; i++) {+ const k = keys[i];+ const a = this.at(k.at);+ if (k.click) s.sfx('click', a, { gain: 0.9 });+ if (s.t < a) continue;+ if (k.x !== undefined) {+ const p = inOutCubic(clamp((s.t - a) / ((k.dur ?? 0.7) / s.pace)));+ // A slight arc looks like a hand moved it.+ const dx = k.x - x;+ const dy = k.y - y;+ const arc = Math.sin(Math.PI * p) * (k.arc ?? 0.08);+ const nx = lerp(x, k.x, p) - dy * arc;+ y = lerp(y, k.y, p) + dx * arc;+ x = nx;+ }+ if (k.click) {+ const since = s.t - a;+ press = Math.max(press, bell(since / (0.26 / s.pace)));+ if (since < 0.6 / s.pace) ripples.push({ x, y, p: since / (0.6 / s.pace) });+ }+ }+ if (s.t < start) return null;+ const c = this.c;+ const [r, g, b] = rgb(this.colors.accent);+ for (const rp of ripples) {+ c.save();+ c.beginPath();+ c.arc(rp.x, rp.y, lerp(6, 38, outCubic(rp.p)), 0, Math.PI * 2);+ c.fillStyle = `rgba(${r}, ${g}, ${b}, ${0.22 * (1 - rp.p)})`;+ c.fill();+ c.restore();+ }+ let alpha = clamp((s.t - start) / 0.25);+ if (o.out !== undefined) alpha *= 1 - this._p(o.out, 0.3, 'in');+ if (alpha <= 0) return { x, y, press };+ const size = (o.size ?? 34) * (1 - 0.14 * press);+ c.save();+ c.globalAlpha *= alpha;+ c.translate(x, y);+ c.scale(size / 24, size / 24);+ const k = this.k;+ c.shadowColor = 'rgba(0, 0, 0, 0.28)';+ c.shadowBlur = 5 * k;+ c.shadowOffsetY = 2 * k;+ const arrow = new Path2D('M1 1 L1 19.5 L5.6 15.3 L8.7 22.4 L11.9 21 L8.9 14.1 L15 14.1 Z');+ c.lineJoin = 'round';+ c.strokeStyle = '#ffffff';+ c.lineWidth = 3;+ c.stroke(arrow);+ c.shadowColor = 'transparent';+ c.fillStyle = '#101828';+ c.fill(arrow);+ c.restore();+ return { x, y, press };+ }++ // How far a click at `at` presses a button right now (0..1..0).+ press(at) {+ return bell((this.s.t - this.at(at)) / (0.26 / this.s.pace));+ }++ // The part of `str` typed by now, starting at `at`, with typing sounds.+ typed(str, at, cps = 17) {+ const a = this.at(at);+ const dur = str.length / cps / this.s.pace;+ this.s.sfx('type', a, { dur, gain: 0.55 });+ return str.slice(0, Math.floor(clamp((this.s.t - a) / dur) * str.length));+ }++ // A number counting from `from` to `to`, starting at `at`.+ count(to, at, dur = 1, from = 0) {+ return Math.round(lerp(from, to, outCubic(this._p(at, dur, 'linear'))));+ }+}diff --git a/examples/unspar-demo/assets/fonts/Figtree-400.woff2 b/examples/unspar-demo/assets/fonts/Figtree-400.woff2new file mode 100644index 0000000..9181aedBinary files /dev/null and b/examples/unspar-demo/assets/fonts/Figtree-400.woff2 differdiff --git a/examples/unspar-demo/assets/fonts/Figtree-500.woff2 b/examples/unspar-demo/assets/fonts/Figtree-500.woff2new file mode 100644index 0000000..6ab5588Binary files /dev/null and b/examples/unspar-demo/assets/fonts/Figtree-500.woff2 differdiff --git a/examples/unspar-demo/assets/fonts/Figtree-600.woff2 b/examples/unspar-demo/assets/fonts/Figtree-600.woff2new file mode 100644index 0000000..d641b95Binary files /dev/null and b/examples/unspar-demo/assets/fonts/Figtree-600.woff2 differdiff --git a/examples/unspar-demo/assets/fonts/Figtree-700.woff2 b/examples/unspar-demo/assets/fonts/Figtree-700.woff2new file mode 100644index 0000000..36473fdBinary files /dev/null and b/examples/unspar-demo/assets/fonts/Figtree-700.woff2 differdiff --git a/examples/unspar-demo/assets/fonts/Figtree-OFL.txt b/examples/unspar-demo/assets/fonts/Figtree-OFL.txtnew file mode 100644index 0000000..80b12bb--- /dev/null+++ b/examples/unspar-demo/assets/fonts/Figtree-OFL.txt@@ -0,0 +1,93 @@+Copyright 2022 The Figtree Project Authors (https://github.com/erikdkennedy/figtree)++This Font Software is licensed under the SIL Open Font License, Version 1.1.+This license is copied below, and is also available with a FAQ at:+http://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/examples/unspar-demo/assets/unspar-logo.svg b/examples/unspar-demo/assets/unspar-logo.svgnew file mode 100644index 0000000..f034b60--- /dev/null+++ b/examples/unspar-demo/assets/unspar-logo.svg@@ -0,0 +1,23 @@+<?xml version="1.0" encoding="UTF-8"?>+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1264 343" width="1264" height="343" role="img" aria-label="Unspar logo">+ <g>+ <defs>+ <linearGradient id="iconBg" x1="0" y1="0" x2="360" y2="343" gradientUnits="userSpaceOnUse">+ <stop offset="0" stop-color="#3B73F4"/>+ <stop offset="1" stop-color="#2F64E6"/>+ </linearGradient>+ <clipPath id="iconClip">+ <rect width="360" height="343" rx="59" ry="59"/>+ </clipPath>+ </defs>+ <g clip-path="url(#iconClip)">+ <rect width="360" height="343" rx="59" ry="59" fill="url(#iconBg)"/>+ <path d="M360 201v142H220z" fill="#6B96EC" opacity="0.92"/>+ </g>+ <path d="M102 99v97a78 78 0 0 0 156 0V99" fill="none" stroke="#FCFDFE" stroke-width="48" stroke-linecap="round" stroke-linejoin="round"/>++ </g>+ <g transform="translate(354 48) scale(0.3333333333)">+ <path d="M 332 136.689 C 322.239 137.426, 304.912 140.259, 293.500 142.983 C 286.900 144.559, 275.660 147.925, 268.521 150.463 C 240.219 160.525, 217.688 172.831, 196 190.072 C 191.325 193.789, 182.283 202.155, 175.906 208.665 C 163.694 221.130, 153.823 233.648, 144.608 248.356 C 137.902 259.058, 129.652 275.775, 126.316 285.421 C 120.466 302.338, 117.082 316.753, 114.516 335.682 L 113 346.864 113 475.185 L 113 603.506 114.881 610.003 C 115.916 613.576, 117.357 617.850, 118.083 619.500 C 120.629 625.285, 127.146 633.765, 132.299 637.998 C 135.159 640.348, 141.325 644.122, 146 646.385 L 154.500 650.500 175.273 650.823 L 196.046 651.145 201.273 649.460 C 204.148 648.532, 209.200 646.288, 212.500 644.473 L 218.500 641.172 224.336 635.257 C 227.546 632.003, 231.484 627.127, 233.086 624.421 C 234.689 621.714, 236.894 616.546, 237.987 612.935 L 239.975 606.369 240.271 479.935 L 240.568 353.500 242.272 345.500 C 244.028 337.254, 246.536 328.011, 247.970 324.500 C 248.419 323.400, 250.944 318.028, 253.580 312.563 C 256.217 307.098, 260.972 299.179, 264.147 294.965 C 267.322 290.752, 272.816 284.595, 276.355 281.284 C 283.825 274.297, 297.248 265.209, 306.263 261.037 C 315.617 256.707, 327.333 253.117, 337.477 251.471 C 342.440 250.667, 350.887 250.006, 356.250 250.004 L 365.999 250 375.210 251.590 C 386.127 253.474, 399.597 257.831, 408.327 262.303 C 417.788 267.150, 430.354 276.588, 437.840 284.469 C 441.513 288.336, 446.450 294.425, 448.811 298 C 453.973 305.816, 460.397 318.735, 462.507 325.543 C 463.352 328.270, 464.934 334.921, 466.022 340.324 L 468 350.147 468.008 477.824 L 468.015 605.500 469.920 611.762 C 472.066 618.821, 475.860 625.821, 480.346 631 C 482.014 632.925, 485.655 636.346, 488.439 638.602 C 494.082 643.175, 501.282 647.208, 507.876 649.487 L 512.251 651 531.969 651 L 551.687 651 557.584 648.971 C 560.827 647.855, 566.625 645.074, 570.468 642.791 C 574.311 640.508, 579.525 636.570, 582.056 634.039 C 587.208 628.887, 592.854 619.278, 595.594 611 L 597.414 605.500 597.414 469.500 L 597.414 333.500 595.610 323.500 C 593.300 310.692, 590.562 299.070, 587.936 290.934 C 584.207 279.381, 575.762 260.707, 569.651 250.500 C 566.358 245, 559.970 235.550, 555.454 229.500 C 550.939 223.450, 543.296 214.309, 538.469 209.187 C 533.643 204.065, 524.926 196.043, 519.097 191.361 C 513.269 186.678, 504.123 179.933, 498.773 176.371 C 493.423 172.809, 483.748 167.254, 477.273 164.027 C 448.087 149.482, 420.455 141.198, 389 137.563 L 375.500 136.002 356 136.176 C 345.275 136.271, 334.475 136.502, 332 136.689 M 861 137.133 C 838.021 139.002, 811.129 145.008, 791.954 152.554 C 778.319 157.919, 761.941 166.316, 751.765 173.158 C 746.905 176.426, 739.233 182.241, 734.715 186.082 C 730.197 189.922, 723.708 196.252, 720.295 200.148 C 712.630 208.898, 705.571 219.101, 700.202 229.187 C 697.952 233.415, 694.708 241.062, 692.993 246.180 C 691.278 251.299, 689.023 259.808, 687.982 265.089 C 686.941 270.370, 685.792 280.498, 685.427 287.596 L 684.764 300.500 685.845 311 C 686.810 320.373, 688.710 329.447, 691.918 340 C 693.571 345.439, 701.053 359.778, 706.387 367.728 C 709.043 371.686, 714.205 377.930, 717.858 381.604 C 724.760 388.545, 735.536 397.098, 745 403.147 C 753.328 408.470, 763.832 414.390, 770.288 417.398 C 778.086 421.031, 792.054 426.230, 800 428.457 C 803.575 429.459, 810.100 431.329, 814.500 432.614 C 822.912 435.069, 850.635 442.346, 860 444.556 C 873.435 447.727, 879.969 449.184, 886.500 450.467 C 904.920 454.084, 926.383 459.564, 941.374 464.479 C 945.705 465.899, 952.511 468.652, 956.498 470.596 L 963.748 474.131 969.190 478.982 L 974.632 483.832 977.910 489.983 L 981.189 496.134 980.815 505.317 L 980.442 514.500 977.683 520.177 C 976.166 523.299, 972.918 527.888, 970.466 530.376 C 965.518 535.395, 956.386 540.864, 948 543.829 C 940.884 546.346, 930.656 548.622, 920 550.060 L 911.500 551.206 893 550.745 C 882.825 550.491, 871.155 549.735, 867.067 549.064 C 854.750 547.044, 838.480 542.539, 829 538.522 C 818.206 533.950, 809.883 529.453, 802.290 524.093 C 798.324 521.294, 790.853 514.963, 785.686 510.024 L 776.293 501.043 770.202 498.022 L 764.112 495 753.178 495 L 742.244 495 738.372 496.564 C 728.897 500.390, 725.799 502.398, 714.500 512.040 C 707.900 517.671, 700.250 523.964, 697.500 526.023 C 689.431 532.067, 684.571 538.259, 681.431 546.500 L 679.526 551.500 679.585 559.100 L 679.644 566.699 682.012 573.033 L 684.381 579.366 690.940 586.329 C 698.731 594.599, 713.012 606.312, 725.550 614.716 C 746.324 628.641, 778.654 642.145, 809.860 649.930 C 824.954 653.696, 834.633 655.572, 850 657.711 L 862.500 659.451 894 659.445 L 925.500 659.438 939 657.712 C 946.425 656.763, 956.775 655.114, 962 654.047 C 993.148 647.686, 1020.529 637.597, 1039.500 625.490 C 1050.472 618.488, 1060.650 610.203, 1069.999 600.661 C 1075.086 595.469, 1081.262 588.359, 1083.723 584.861 C 1086.185 581.362, 1090.351 574.161, 1092.981 568.857 C 1095.612 563.553, 1099.137 555.003, 1100.815 549.857 C 1102.493 544.711, 1104.683 536.450, 1105.682 531.500 L 1107.498 522.500 1107.476 503 L 1107.454 483.500 1105.166 473 C 1103.908 467.225, 1101.729 459.125, 1100.324 455 C 1097.174 445.747, 1091.216 433.704, 1085.786 425.612 C 1083.530 422.250, 1076.693 414.521, 1070.592 408.437 L 1059.500 397.373 1049.499 390.764 C 1043.999 387.128, 1034.774 381.925, 1028.999 379.201 C 1015.480 372.822, 997.359 365.681, 985.143 361.917 C 979.839 360.283, 974.150 358.524, 972.500 358.007 C 969.794 357.159, 947.420 351.386, 926.500 346.138 C 922.100 345.034, 911.075 342.251, 902 339.954 C 892.925 337.657, 883.925 335.402, 882 334.943 C 878.130 334.021, 869.669 331.758, 863.500 329.995 C 853.802 327.224, 839.503 321.480, 833.968 318.133 C 830.656 316.131, 825.943 312.518, 823.494 310.105 C 821.045 307.691, 818.026 303.642, 816.786 301.108 L 814.531 296.500 814.178 289 L 813.825 281.500 816.072 275.500 L 818.319 269.500 824.036 263.896 L 829.753 258.292 837.626 254.321 L 845.500 250.350 854.500 248.220 C 859.450 247.049, 866.771 245.620, 870.769 245.045 C 880.704 243.617, 897.554 243.785, 909.037 245.428 C 918.778 246.821, 922.209 247.595, 934.500 251.173 C 945.530 254.383, 949.915 256.095, 958.747 260.637 C 966.817 264.787, 973.095 269.188, 985.820 279.616 C 989.296 282.464, 994.976 286.190, 998.443 287.897 L 1004.745 291 1014.935 291 L 1025.124 291 1030.619 288.400 C 1033.642 286.970, 1039.127 283.345, 1042.807 280.344 C 1046.488 277.343, 1055.800 269.795, 1063.500 263.571 C 1071.200 257.346, 1078.491 251.178, 1079.701 249.864 C 1080.912 248.550, 1082.899 245.231, 1084.116 242.488 L 1086.330 237.500 1086.253 229.798 L 1086.177 222.095 1083.340 216.883 C 1081.779 214.016, 1077.423 208.372, 1073.659 204.342 C 1069.895 200.311, 1063.369 194.235, 1059.158 190.838 C 1038.409 174.107, 1012.845 160.248, 986.500 151.451 C 967.714 145.178, 944.979 140.113, 924.030 137.535 L 911.560 136 891.530 136.139 C 880.513 136.216, 866.775 136.663, 861 137.133 M 1445.500 136.580 C 1443.850 136.802, 1438.450 137.480, 1433.500 138.087 C 1422.273 139.463, 1410.220 142.183, 1398.328 146.024 C 1385.307 150.230, 1366.293 158.934, 1354.219 166.217 C 1338.958 175.421, 1325.440 186.607, 1315.552 198.212 C 1312.875 201.353, 1310.306 203.689, 1309.842 203.403 C 1309.379 203.116, 1309 199.595, 1309 195.577 C 1309 191.560, 1308.548 185.849, 1307.995 182.886 C 1306.802 176.497, 1302.110 166.697, 1298.234 162.500 C 1293.147 156.992, 1286.453 152.107, 1279.443 148.788 L 1272.500 145.500 1249.251 145.169 L 1226.001 144.839 1220.751 146.525 C 1217.863 147.452, 1212.575 149.917, 1209 152.002 L 1202.500 155.793 1196.860 161.707 L 1191.220 167.620 1188.097 173.808 C 1186.379 177.211, 1184.380 183.034, 1183.654 186.748 L 1182.335 193.500 1182.076 471.750 L 1181.818 750 1244.909 750 L 1308 750 1308 672.167 C 1308 629.358, 1308.273 594.060, 1308.608 593.726 C 1308.942 593.392, 1311.754 595.868, 1314.858 599.228 C 1323.337 608.411, 1336.337 619.451, 1347.137 626.640 C 1352.442 630.172, 1360.544 634.999, 1365.141 637.366 C 1369.738 639.734, 1379.125 643.724, 1386 646.232 C 1392.875 648.740, 1404.125 652.171, 1411 653.855 C 1417.875 655.540, 1428.578 657.611, 1434.784 658.459 L 1446.069 660 1469.996 660 L 1493.924 660 1509.212 658.032 C 1524.405 656.076, 1540.563 652.792, 1553 649.132 C 1564.792 645.662, 1583.680 638.177, 1595.113 632.444 C 1601.302 629.339, 1609.322 624.956, 1612.933 622.704 C 1624.964 615.200, 1642.374 601.264, 1653.651 590.113 C 1659.785 584.048, 1668.388 574.454, 1672.771 568.793 C 1677.153 563.132, 1683.783 553.807, 1687.504 548.072 C 1694.024 538.022, 1703.594 519.896, 1707.870 509.500 C 1710.305 503.579, 1718.142 479.037, 1720.323 470.500 C 1722.772 460.915, 1724.817 449.439, 1726.469 436 L 1728.005 423.500 1728.003 400.726 L 1728 377.953 1726.496 365.226 C 1724.446 347.878, 1723.321 341.245, 1720.382 329.192 C 1717.625 317.880, 1711.929 300.050, 1708.821 293 C 1702.564 278.805, 1691.545 258.099, 1685.148 248.515 C 1681.105 242.457, 1673.542 232.227, 1668.341 225.782 C 1663.141 219.337, 1654.524 209.955, 1649.193 204.932 C 1638.959 195.291, 1622.497 182.506, 1610.026 174.515 C 1605.916 171.881, 1598.266 167.590, 1593.026 164.978 C 1566.082 151.549, 1540.467 143.320, 1510.442 138.446 L 1500.500 136.832 1474.500 136.505 C 1460.200 136.325, 1447.150 136.359, 1445.500 136.580 M 2024.500 136.593 C 2022.850 136.816, 2017.225 137.485, 2012 138.080 C 1996.712 139.819, 1979.679 143.756, 1962 149.636 L 1945.500 155.124 1930.500 162.467 C 1916.003 169.563, 1897.079 181.238, 1884.552 190.814 C 1875.240 197.932, 1858.706 214.311, 1848.459 226.569 C 1843.370 232.657, 1835.416 243.232, 1830.782 250.069 C 1826.148 256.906, 1819.618 267.914, 1816.271 274.531 C 1809.674 287.570, 1800.398 310.597, 1797.553 321 C 1796.575 324.575, 1795.393 328.625, 1794.927 330 C 1793.936 332.925, 1792.537 339.961, 1790.453 352.500 C 1787.963 367.489, 1787.183 374.842, 1786.478 390 L 1785.803 404.500 1786.916 420.500 C 1787.528 429.300, 1788.453 438.750, 1788.971 441.500 C 1791.669 455.816, 1792.291 458.986, 1793.484 464.500 C 1796.389 477.923, 1801.937 495.187, 1806.981 506.500 C 1807.472 507.600, 1809.252 511.569, 1810.937 515.320 C 1812.621 519.071, 1814 522.343, 1814 522.593 C 1814 522.842, 1816.128 526.748, 1818.729 531.273 C 1822.881 538.497, 1825.522 542.569, 1834.435 555.494 C 1838.922 561.998, 1848.887 573.915, 1856.495 581.874 C 1865.689 591.492, 1882.856 606.107, 1894.500 614.229 C 1916.152 629.332, 1942.855 642.040, 1969.500 649.923 C 1981.323 653.421, 1997.856 656.785, 2011.880 658.546 L 2025.260 660.225 2052.380 659.713 L 2079.500 659.201 2089 657.544 C 2100.756 655.493, 2115.118 651.877, 2125 648.480 C 2129.125 647.062, 2133.863 645.481, 2135.528 644.965 C 2137.194 644.450, 2144.479 641.103, 2151.718 637.527 L 2164.880 631.026 2175.190 623.331 C 2180.861 619.099, 2190.536 610.543, 2196.692 604.318 C 2202.847 598.093, 2208.135 593, 2208.442 593 C 2208.749 593, 2209 596.785, 2209 601.411 L 2209 609.822 2210.884 615.875 C 2211.920 619.204, 2213.899 623.857, 2215.280 626.214 C 2216.662 628.571, 2220.427 633.007, 2223.646 636.070 C 2226.866 639.134, 2231.707 642.929, 2234.403 644.505 C 2237.100 646.081, 2241.783 648.187, 2244.809 649.185 L 2250.310 651 2271.466 651 L 2292.621 651 2298.802 648.578 C 2302.201 647.246, 2307.574 644.575, 2310.741 642.642 C 2313.909 640.710, 2318.373 637.188, 2320.663 634.815 C 2322.952 632.442, 2326.147 628.233, 2327.762 625.461 C 2329.377 622.690, 2331.554 617.965, 2332.599 614.961 L 2334.500 609.500 2334.500 398 L 2334.500 186.500 2332.175 180.500 C 2330.896 177.200, 2328.543 172.212, 2326.946 169.415 C 2325.349 166.618, 2321.670 162.089, 2318.771 159.350 C 2315.872 156.611, 2311.439 153.164, 2308.920 151.690 C 2306.401 150.215, 2301.718 148.107, 2298.514 147.005 L 2292.687 145 2271.593 145.021 L 2250.500 145.042 2243.757 147.422 C 2240.048 148.731, 2235.098 150.930, 2232.757 152.307 C 2230.416 153.685, 2225.894 157.442, 2222.708 160.656 L 2216.916 166.500 2214.484 171.500 C 2211.422 177.793, 2209.129 186.818, 2208.710 194.224 C 2208.531 197.372, 2208.113 200.220, 2207.780 200.554 C 2207.446 200.887, 2203.718 197.542, 2199.494 193.121 C 2191.010 184.241, 2176.831 173.121, 2164.517 165.690 C 2160.108 163.029, 2152.450 158.917, 2147.500 156.553 C 2129.113 147.769, 2111.249 142.143, 2089.929 138.420 L 2080.500 136.773 2054 136.480 C 2039.425 136.319, 2026.150 136.370, 2024.500 136.593 M 2668 142.983 C 2647.222 145.301, 2626.378 152.539, 2606 164.510 C 2601.875 166.933, 2594.888 171.811, 2590.473 175.350 C 2586.058 178.889, 2579.533 184.874, 2575.973 188.652 C 2572.413 192.429, 2567.788 198.103, 2565.697 201.260 C 2563.605 204.417, 2561.467 207, 2560.947 207 L 2560 207 2560 196.605 L 2560 186.211 2558.024 179.813 C 2556.937 176.294, 2554.660 171.321, 2552.965 168.760 C 2551.269 166.200, 2547.106 161.536, 2543.714 158.396 L 2537.547 152.686 2530.024 149.093 L 2522.500 145.500 2499.786 145.169 L 2477.072 144.837 2471.286 146.507 C 2468.104 147.426, 2462.904 149.555, 2459.732 151.238 L 2453.964 154.298 2448.419 159.887 C 2445.369 162.961, 2441.589 167.732, 2440.018 170.488 C 2438.447 173.245, 2436.226 177.975, 2435.082 181 L 2433.001 186.500 2433.001 396.846 L 2433 607.192 2434.542 612.496 C 2435.390 615.412, 2437.449 620.321, 2439.119 623.403 C 2440.788 626.486, 2444.319 631.369, 2446.964 634.254 L 2451.774 639.500 2458.637 643.581 C 2462.412 645.825, 2467.718 648.412, 2470.428 649.331 L 2475.356 651 2495.928 650.922 L 2516.500 650.845 2521 649.164 C 2523.475 648.239, 2528.245 646.052, 2531.601 644.302 L 2537.702 641.122 2543.674 635.241 C 2546.959 632.007, 2551.033 626.917, 2552.728 623.930 C 2554.422 620.944, 2556.751 615.415, 2557.904 611.645 L 2560 604.789 2560 489.461 L 2560 374.133 2561.930 362.816 C 2562.992 356.592, 2564.602 348.652, 2565.508 345.172 C 2567.518 337.453, 2571.667 327.551, 2576.400 319.176 C 2581.385 310.357, 2590.915 298.316, 2597.182 292.919 C 2604.224 286.853, 2613.235 280.773, 2620.552 277.148 C 2627.181 273.865, 2647.226 267, 2650.184 267 C 2651.232 267, 2654.881 266.337, 2658.294 265.526 C 2661.708 264.715, 2671.250 263.684, 2679.500 263.234 L 2694.500 262.416 2700.374 259.458 L 2706.248 256.500 2711.505 251.260 C 2714.397 248.378, 2717.573 244.328, 2718.562 242.260 L 2720.362 238.500 2721.125 228.500 C 2722.173 214.760, 2722.149 181.809, 2721.086 174.465 C 2720.606 171.146, 2719.198 166.272, 2717.958 163.633 C 2716.717 160.995, 2713.538 156.467, 2710.893 153.573 L 2706.083 148.310 2700.118 145.633 L 2694.153 142.956 2684.826 142.551 C 2679.697 142.328, 2672.125 142.522, 2668 142.983 M 1442 249.639 C 1440.625 249.841, 1436.125 250.497, 1432 251.097 C 1420.007 252.842, 1404.058 256.943, 1397.500 259.968 C 1396.400 260.476, 1393.442 261.791, 1390.926 262.890 C 1385.034 265.466, 1372.451 272.898, 1363.341 279.184 C 1359.403 281.901, 1351.889 288.548, 1346.644 293.954 L 1337.106 303.783 1330.942 313.141 C 1327.552 318.289, 1323.066 326.142, 1320.972 330.593 C 1314.552 344.241, 1310.618 357.226, 1307.519 375 L 1306.037 383.500 1306.018 399.440 L 1306 415.380 1307.091 421.440 C 1310.171 438.556, 1316.043 457.364, 1321.952 469.040 C 1325.691 476.427, 1331.216 485.076, 1337.258 493 C 1344.302 502.238, 1358.601 515.898, 1367.062 521.472 C 1382.029 531.332, 1399.381 539.083, 1416.427 543.523 C 1419.609 544.352, 1426.777 545.749, 1432.356 546.627 L 1442.500 548.225 1456.500 548.183 L 1470.500 548.142 1480 546.636 C 1485.225 545.809, 1492.280 544.409, 1495.678 543.526 C 1508.815 540.113, 1526.800 531.888, 1539.347 523.556 C 1547.051 518.440, 1558.725 508.134, 1565.601 500.380 C 1568.956 496.596, 1573.812 490.351, 1576.391 486.503 C 1582.704 477.086, 1591.153 460.285, 1594.497 450.500 C 1596.001 446.100, 1598.316 437.550, 1599.642 431.500 L 1602.052 420.500 1602.674 404.793 L 1603.296 389.086 1602.053 379.793 C 1600.288 366.604, 1597.554 355.394, 1593.369 344.198 C 1588.284 330.595, 1579.038 314.004, 1570.411 303 C 1558.065 287.253, 1545.298 276.621, 1526.500 266.431 C 1522.100 264.046, 1515.350 260.895, 1511.500 259.430 C 1495.090 253.186, 1471.227 248.898, 1454.216 249.136 C 1448.872 249.211, 1443.375 249.438, 1442 249.639 M 2046 250.111 C 2026.453 253.229, 2013.104 257.048, 2000 263.269 C 1995.325 265.489, 1987 270.269, 1981.500 273.891 L 1971.500 280.478 1962.137 289.489 C 1952.864 298.414, 1942.093 311.833, 1936.433 321.516 C 1931.193 330.478, 1927.482 338.794, 1923.720 350 C 1919.819 361.623, 1918.287 367.746, 1916.837 377.500 L 1915.500 386.500 1915.525 400 L 1915.550 413.500 1917.256 423.500 C 1919.963 439.359, 1922.565 448.306, 1928.416 461.868 C 1936.215 479.948, 1942.878 489.895, 1956.699 504.093 C 1962.370 509.919, 1970.571 517.250, 1974.922 520.382 C 1979.273 523.515, 1987.499 528.423, 1993.202 531.289 C 2007.061 538.254, 2011.644 540.115, 2022.500 543.185 C 2033.725 546.359, 2044.604 548.040, 2058.103 548.686 L 2070.706 549.289 2083.103 547.559 C 2089.921 546.607, 2098.706 545.004, 2102.625 543.996 C 2110.187 542.052, 2118.195 539.535, 2121.500 538.065 C 2137.635 530.885, 2149.371 523.874, 2160.916 514.516 C 2164.977 511.226, 2171.395 504.956, 2175.179 500.584 C 2186.573 487.421, 2194.656 474.042, 2201.209 457.500 C 2203.170 452.550, 2205.704 445.125, 2206.840 441 C 2209.781 430.327, 2211.795 417.302, 2212.562 404 L 2213.225 392.500 2212.069 383 C 2211.434 377.775, 2210.031 369.225, 2208.951 364 C 2205.287 346.268, 2198.058 328.965, 2187.721 313.189 L 2181.362 303.483 2172.431 294.097 C 2167.519 288.935, 2160.125 282.145, 2156 279.010 C 2151.875 275.874, 2144.900 271.310, 2140.500 268.868 C 2132.558 264.460, 2130.731 263.545, 2124 260.608 C 2114.373 256.407, 2100.218 252.698, 2085.720 250.577 L 2074.939 249 2063.220 249.117 C 2056.774 249.181, 2049.025 249.629, 2046 250.111" fill="#0A1B40" fill-rule="evenodd"/>+ </g>+</svg>diff --git a/examples/unspar-demo/scenes.js b/examples/unspar-demo/scenes.jsnew file mode 100644index 0000000..5cdfc21--- /dev/null+++ b/examples/unspar-demo/scenes.js@@ -0,0 +1,367 @@+// A product demo for Unspar, drawn with the UI kit (s.ui). The screens are+// rebuilt from the real app's wording and look; brand colors, fonts and the+// logo come from "brand" and "fonts" in video.json.++// Background and drifting cards, then the camera, then the scene's headline,+// so the headline moves with the camera like everything else.+function stage(s, title, o = {}) {+ const u = s.ui;+ u.backdrop();+ u.floaters();+ if (o.camera) s.camera(o.camera);+ if (title) u.headline(title, s.W / 2, 178, { size: 84, at: o.at ?? 0.15 });+ return u;+}++export default {+ hook(s) {+ const u = stage(s, null, { camera: [{ at: 0.2, zoom: 1.05, dur: s.dur, ease: 'linear' }] });+ // The logo starts big in the middle and moves up when the voice goes on.+ const up = s.p('#writes', 0.9, 'inOut');+ const grow = s.p(0.1, 0.9, 'outBack');+ s.ctx.save();+ s.ctx.globalAlpha = s.clamp(s.p(0.1, 0.45, 'out'));+ u.logo(960, s.lerp(540, 300, up), s.lerp(620, 380, up) * s.lerp(0.86, 1, grow));+ s.ctx.restore();+ u.headline("*Content that doesn't* read like AI.", 960, 610, { size: 116, at: s.time('#writes') + 0.35 });+ const chips = [+ { label: 'Blog posts', icon: 'newspaper', at: '#blog', x: 770, w: 210 },+ { label: 'Guides', icon: 'book-open', at: '#guides', x: 1000, w: 170 },+ ];+ for (const ch of chips) {+ u.pop(ch.at, ch.x + ch.w / 2, 735, () => {+ u.card(ch.x, 705, ch.w, 60, { r: 30, lift: 0.5 });+ u.icon(ch.icon, ch.x + 36, 735, 26, u.colors.accent, 2.2);+ u.text(ch.label, ch.x + 60, 736, { size: 23, weight: 600 });+ }, { sfx: 'pop' });+ }+ },++ brief(s) {+ const px = 410;+ const py = 270;+ const site = s.time('#site');+ const pick = s.time('#pick');+ const topic = s.time('#topic');+ const ideas = s.time('#ideas');+ const chosen = pick + 1.0;+ const u = stage(s, 'Tell it what to write about', {+ camera: [+ { at: site - 0.9, x: px + 470, y: py + 330, zoom: 1.3, dur: 0.9 },+ { at: pick - 0.65, x: px + 700, y: py + 390, zoom: 1.3, dur: 0.7 },+ { at: topic - 0.6, x: px + 560, y: py + 440, zoom: 1.24, dur: 0.7 },+ { at: ideas - 0.7, x: px + 760, y: py + 500, zoom: 1.32, dur: 0.7 },+ { at: ideas + 1.2, x: 960, y: 540, zoom: 1, dur: 1 },+ ],+ });+ let rows = [];+ u.panel(px, py, 1100, 600, { at: 0.3 }, () => {+ u.icon('sparkles', px + 66, py + 62, 24, u.colors.accent, 2);+ u.eyebrow('First article', px + 88, py + 63);+ u.text('Tell us what you have', px + 56, py + 118, { size: 38, weight: 700 });+ u.para('Share a site, a goal, or both. We will suggest a first article and queue it with the normal generation workflow.', px + 56, py + 150, 980, { size: 21, color: u.colors.muted });+ u.input(px + 56, py + 296, 560, 62, {+ label: 'Website URL',+ placeholder: 'https://example.com',+ value: u.typed('https://example.com', site + 0.15, 26),+ focus: s.t >= site ? 1 - s.p(pick, 0.2) : 0,+ caret: true,+ });+ u.input(px + 56, py + 430, 988, 62, {+ label: 'Topic or goal',+ placeholder: 'e.g. teach small SaaS teams how to write a launch plan',+ value: u.typed('home baking for beginners', topic + 0.15, 24),+ focus: s.t >= topic ? 1 - s.p(ideas, 0.2) : 0,+ caret: true,+ });+ const loading = s.t >= ideas + 0.12;+ const label = !loading ? 'Get article ideas' : s.t < ideas + 1.5 ? 'Looking at your site...' : 'Drafting first ideas...';+ const bw = loading ? 340 : 280;+ u.button(label, px + 1044 - bw, py + 516, bw, 60, { press: u.press(ideas), loading, icon: loading ? null : 'sparkles' });+ // The dropdown goes last, so its open menu covers the fields below.+ rows = u.select(px + 640, py + 296, 404, 62, {+ label: 'What do you want to create?',+ value: s.t >= chosen ? 'Website articles or blog posts' : '',+ placeholder: 'Choose one',+ open: s.t < pick ? 0 : s.t < chosen + 0.1 ? s.p(pick, 0.3) : 1 - s.p(chosen + 0.1, 0.25),+ options: ['Website articles or blog posts', 'Social media content', 'Email newsletters', 'Something else'],+ hover: s.t >= pick + 0.55 && s.t < chosen + 0.1 ? 0 : -1,+ selected: s.t >= chosen ? 0 : -1,+ size: 20,+ });+ });+ u.cursor([+ { at: '#tell', x: 1560, y: 960 },+ { at: site - 0.75, x: px + 330, y: py + 330 },+ { at: site, click: true },+ { at: pick - 0.6, x: px + 870, y: py + 330 },+ { at: pick, click: true },+ // Point past the end of the option's text, not on it.+ { at: pick + 0.35, x: px + 1016, y: (rows[0] ?? py + 405) + 6, dur: 0.5 },+ { at: chosen, click: true },+ { at: topic - 0.6, x: px + 420, y: py + 462 },+ { at: topic, click: true },+ { at: ideas - 0.7, x: px + 900, y: py + 548 },+ { at: ideas, click: true },+ ]);+ },++ ideas(s) {+ const px = 430;+ const py = 250;+ const choose = s.time('#choose');+ const u = stage(s, 'Pick one of its ideas', { at: 0.1, camera: [{ at: choose - 0.8, x: 960, y: 560, zoom: 1.08, dur: 1.2 }] });+ const ideas = [+ ['Your first sourdough loaf, step by step', 'A beginner guide with a simple timeline'],+ ['Why bread goes stale and how to slow it down', 'The science, explained in plain words'],+ ['Five easy bakes for your first weekend', 'One short recipe for each bake'],+ ];+ u.panel(px, py, 1060, 660, { at: 0.05, from: 0.98 }, () => {+ u.icon('sparkles', px + 66, py + 62, 24, u.colors.accent, 2);+ u.eyebrow('First article', px + 88, py + 63);+ u.text('Tell us what you have', px + 56, py + 116, { size: 36, weight: 700 });+ ideas.forEach(([title, sub], i) => {+ const y = py + 170 + i * 118;+ const sel = i === 0 ? s.p(choose, 0.3) : 0;+ u.panel(px + 56, y, 948, 100, { at: s.time('#list') + i * 0.18, r: 14, shadow: false, lift: 0, from: 1, rise: 24, fill: sel > 0 ? u.colors.accentTint : '#ffffff', border: sel > 0.5 ? u.colors.accent : u.colors.line, borderWidth: 1.5 + sel, sfx: i === 0 ? 'blip' : null }, () => {+ u.radio(px + 100, y + 50, sel);+ u.text(title, px + 136, y + 36, { size: 25, weight: 600 });+ u.text(sub, px + 136, y + 70, { size: 20, color: u.colors.muted });+ });+ });+ s.ctx.save();+ s.ctx.globalAlpha *= s.p(s.time('#list') + 0.7, 0.4, 'out');+ u.button('Try a different topic', px + 480, py + 560, 260, 60, { variant: 'secondary' });+ u.button('Queue first article', px + 754, py + 560, 250, 60);+ s.ctx.restore();+ });+ u.cursor([+ { at: 0.3, x: 1350, y: 900 },+ { at: choose - 0.7, x: px + 900, y: py + 226 },+ { at: choose, click: true },+ ]);+ },++ price(s) {+ const u = stage(s, 'You see the price first', { at: 0.1, camera: [{ at: 0.1, zoom: 1.04, dur: 3, ease: 'out' }] });+ const px = 560;+ const py = 250;+ const price = s.time('#price');+ const queue = s.time('#queue');+ u.panel(px, py, 800, 640, { at: price }, () => {+ u.text('Estimated credits', px + 56, py + 70, { size: 34, weight: 700 });+ u.text('Credits are reserved before generation starts.', px + 56, py + 114, { size: 21, color: u.colors.muted });+ u.text('Run tier', px + 56, py + 178, { size: 20, weight: 600 });+ // The tier comes from the job; this one is Standard.+ const on = s.p(price + 0.7, 0.35, 'out');+ [['Quick', 1], ['Standard', 5], ['Advanced', 15], ['Flagship', 40]].forEach(([name, credits], i) => {+ const x = px + 56 + i * 176;+ const sel = i === 1 ? on : 0;+ u.card(x, py + 206, 160, 104, { r: 14, shadow: false, fill: sel > 0 ? u.colors.accentTint : '#ffffff', border: sel > 0.5 ? u.colors.accent : u.colors.line, borderWidth: 1.5 + sel * 1.5 });+ u.text(name, x + 22, py + 242, { size: 22, weight: 600, color: sel > 0.5 ? u.colors.accent : u.colors.text });+ u.text(`${credits} credit${credits === 1 ? '' : 's'}`, x + 22, py + 278, { size: 19, color: u.colors.muted });+ });+ s.ctx.fillStyle = u.colors.line;+ s.ctx.fillRect(px + 56, py + 350, 688, 1.5);+ u.text('Credit charge', px + 56, py + 398, { size: 22, color: u.colors.soft });+ u.text(`${u.count(5, price + 0.8, 0.8)} credits`, px + 744, py + 398, { size: 26, weight: 700, align: 'right' });+ u.text('Available Credits', px + 56, py + 452, { size: 22, color: u.colors.soft });+ u.text('120', px + 744, py + 452, { size: 26, weight: 700, align: 'right' });+ u.button('Queue first article', px + 56, py + 530, 688, 64, { press: u.press(queue) });+ });+ u.toast('Your first article is queued.', { at: queue + 0.35, y: 930 });+ u.cursor([+ { at: price + 0.4, x: 1500, y: 900 },+ { at: queue - 0.75, x: 960, y: py + 562 },+ { at: queue, click: true },+ ], { out: queue + 1.2 });+ },++ agents(s) {+ const u = stage(s, 'Its agents do the work', { at: 0.1, camera: [{ at: 0.2, zoom: 1.05, dur: s.dur, ease: 'linear' }] });+ const agents = s.time('#agents');+ const done = s.voice.end + 0.15;+ u.panel(410, 250, 1100, 130, { at: 0.2 }, () => {+ u.card(446, 279, 72, 72, { r: 16, shadow: false, border: false, fill: u.colors.accentTint });+ u.icon('file-text', 482, 315, 34, u.colors.accent, 2);+ u.text('Your first sourdough loaf, step by step', 548, 300, { size: 27, weight: 600 });+ u.text('My First Project · Standard', 548, 336, { size: 20, color: u.colors.muted });+ if (s.t < agents) u.pill('Queued for Generation', 1474, 315, 'blue', { align: 'right' });+ else if (s.t < done) u.pill('Generating', 1474, 315, 'yellow', { align: 'right', dot: true, pulse: true });+ else u.pop(done, 1404, 315, () => u.pill('Completed', 1474, 315, 'green', { align: 'right', dot: true }), { from: 0.8, sfx: 'chime' });+ });+ // Research, writing and fact check light up as the voice names them.+ const steps = [+ { title: 'Research', sub: 'Looks up the topic', icon: 'search', at: '#research' },+ { title: 'Writing', sub: 'Writes in your voice', icon: 'pen-line', at: '#write' },+ { title: 'Fact check', sub: 'Checks the facts', icon: 'shield-check', at: '#check' },+ ];+ const W = 330;+ const gap = 55;+ const x0 = 960 - (W * 3 + gap * 2) / 2;+ const y = 470;+ const fill = s.t < s.time('#write') ? 0 : s.t < s.time('#check') ? 0.5 * s.p('#write', 0.6) : 0.5 + 0.5 * s.p('#check', 0.6);+ s.ctx.fillStyle = u.colors.line;+ s.ctx.fillRect(x0 + W / 2, y + 90, W * 2 + gap * 2, 4);+ s.ctx.fillStyle = u.colors.accent;+ s.ctx.fillRect(x0 + W / 2, y + 90, (W * 2 + gap * 2) * fill, 4);+ steps.forEach((st, i) => {+ const x = x0 + i * (W + gap);+ const start = s.time(st.at);+ const end = i < 2 ? s.time(steps[i + 1].at) : done;+ const active = s.t >= start ? s.p(start, 0.35, 'out') : 0;+ const finished = s.t >= end;+ u.panel(x, y, W, 330, { at: agents + 0.1 + i * 0.12, lift: 0.7 + active * 0.5, border: active > 0.5 ? u.colors.accent : u.colors.line, borderWidth: 1.5 + active * 1.5, sfx: i === 0 ? 'pop' : null }, () => {+ s.ctx.beginPath();+ s.ctx.arc(x + W / 2, y + 92, 44, 0, Math.PI * 2);+ s.ctx.fillStyle = active > 0.5 ? u.colors.accent : u.colors.accentTint;+ s.ctx.fill();+ u.icon(finished ? 'check' : st.icon, x + W / 2, y + 92, 40, active > 0.5 ? '#ffffff' : u.colors.accent, 2.2);+ u.text(st.title, x + W / 2, y + 176, { size: 28, weight: 700, align: 'center' });+ u.text(st.sub, x + W / 2, y + 214, { size: 21, color: u.colors.muted, align: 'center' });+ if (finished) u.pill('Done', x + W / 2, y + 276, 'green', { align: 'center' });+ else if (active > 0) {+ u.spinner(x + W / 2 - 60, y + 276, 11);+ u.text('Working', x + W / 2 - 38, y + 277, { size: 19, weight: 600, color: u.colors.accent });+ }+ });+ if (s.t >= start) s.sfx('pop', start);+ });+ },++ voice(s) {+ const px = 410;+ const py = 250;+ const formal = s.time('#formal');+ const rhythm = s.time('#rhythm');+ const create = s.voice.end - 0.1;+ const u = stage(s, 'In your voice', {+ at: 0.1,+ camera: [+ { at: formal - 0.7, x: 900, y: 520, zoom: 1.12, dur: 0.8 },+ { at: rhythm - 0.6, x: 960, y: 580, zoom: 1.12, dur: 0.7 },+ { at: s.voice.end - 0.9, x: 1080, y: 560, zoom: 1.08, dur: 0.8 },+ ],+ });+ // Lay the chips out with room for the check mark of the one that gets picked.+ const row = (labels, y, pick) => {+ let x = px + 56;+ return labels.map((label, i) => {+ const r = { label, x, y, w: u.chipWidth(label, { size: 21 }, i === pick) };+ x += r.w + 14;+ return r;+ });+ };+ const f = row(['Casual', 'Conversational', 'Professional', 'Formal', 'Academic'], py + 262, 1);+ const r = row(['Short and Punchy', 'Mixed', 'Measured', 'Long and Layered'], py + 420, 1);+ u.panel(px, py, 1100, 610, { at: '#voice' }, () => {+ u.eyebrow('Voice profile', px + 56, py + 62);+ u.text('Friendly and clear', px + 56, py + 114, { size: 38, weight: 700 });+ u.text('Formality', px + 56, py + 200, { size: 23, weight: 600 });+ f.forEach((ch, i) => u.chip(ch.label, ch.x, ch.y, { size: 21, selected: i === 1 ? s.p(formal, 0.3) : 0 }));+ u.text('Sentence rhythm', px + 56, py + 358, { size: 23, weight: 600 });+ r.forEach((ch, i) => u.chip(ch.label, ch.x, ch.y, { size: 21, selected: i === 1 ? s.p(rhythm, 0.3) : 0 }));+ u.button('Create voice', px + 824, py + 520, 220, 60, { press: u.press(create) });+ });+ u.cursor([+ { at: s.time('#voice') + 0.3, x: 1500, y: 900 },+ { at: formal - 0.65, x: f[1].x + f[1].w / 2, y: f[1].y + 4 },+ { at: formal, click: true },+ { at: rhythm - 0.6, x: r[1].x + r[1].w / 2, y: r[1].y + 4 },+ { at: rhythm, click: true },+ { at: create - 0.7, x: px + 934, y: py + 552 },+ { at: create, click: true },+ ]);+ },++ publish(s) {+ const pub = s.time('#publish');+ const live = s.time('#live');+ const send = pub + 1.25;+ const u = stage(s, 'You read it, Unspar publishes it', {+ at: 0.1,+ camera: [+ { at: 0, x: 900, y: 560, zoom: 1.02 },+ { at: live - 0.5, x: 1020, y: 560, zoom: 1.04, dur: 1 },+ ],+ });+ // The finished article.+ const ax = 220;+ const ay = 260;+ u.panel(ax, ay, 860, 640, { at: 0.2 }, () => {+ u.text('Preview', ax + 48, ay + 52, { size: 20, weight: 600, color: u.colors.accent });+ s.ctx.fillStyle = u.colors.accent;+ s.ctx.fillRect(ax + 48, ay + 72, 74, 3);+ u.text('Markdown', ax + 146, ay + 52, { size: 20, weight: 500, color: u.colors.muted });+ s.ctx.fillStyle = u.colors.line;+ s.ctx.fillRect(ax + 32, ay + 75, 796, 1.5);+ u.pill('Completed', ax + 600, ay + 50, 'green', { align: 'right', dot: true });+ u.button('Publish', ax + 640, ay + 22, 180, 56, { press: u.press(pub), icon: 'send' });+ u.text('Your first sourdough loaf,', ax + 48, ay + 140, { size: 40, weight: 700 });+ u.text('step by step', ax + 48, ay + 190, { size: 40, weight: 700 });+ u.lines(ax + 48, ay + 240, 760, 5, { gap: 26, h: 11 });+ u.text('What you need', ax + 48, ay + 400, { size: 26, weight: 700 });+ u.lines(ax + 48, ay + 436, 760, 5, { gap: 26, h: 11, seed: 3 });+ });+ // The publish dialog, closed again after "Publish now".+ const mx = 330;+ const my = 380;+ u.modal(mx, my, 640, 350, { at: pub + 0.15, out: send + 0.2 }, () => {+ u.text('Publish', mx + 40, my + 52, { size: 30, weight: 700 });+ u.select(mx + 40, my + 130, 560, 60, { label: 'Outlet', value: 'Bakery blog · WordPress', size: 20 });+ u.text('Publish timing', mx + 40, my + 226, { size: 19, weight: 600 });+ u.chip('Now', mx + 40, my + 270, { size: 19, selected: 1 });+ u.chip('Tomorrow morning, 08:00', mx + 160, my + 270, { size: 19 });+ u.button('Publish now', mx + 420, my + 284, 180, 52, { press: u.press(send), size: 20 });+ });+ // The post on the site.+ const bx = 1130;+ const by = 300;+ u.browser(bx, by, 620, 560, { at: send + 0.35, rise: 60, url: 'example.com/blog/first-sourdough-loaf' }, (x, y) => {+ u.text('BAKERY BLOG', x + 40, y + 46, { size: 16, weight: 700, color: u.colors.faint, tracking: 2 });+ const tp = s.p(send + 0.7, 0.6, 'out');+ s.ctx.save();+ s.ctx.globalAlpha *= tp;+ s.ctx.translate(0, (1 - tp) * 16);+ u.text('Your first sourdough', x + 40, y + 100, { size: 36, font: 'headline' });+ u.text('loaf, step by step', x + 40, y + 144, { size: 36, font: 'headline' });+ u.lines(x + 40, y + 190, 540, 8, { gap: 26, h: 10, seed: 5 });+ s.ctx.restore();+ });+ if (s.t >= send + 0.7) s.sfx('sparkle', send + 0.7, { gain: 0.6 });+ // WordPress and Ghost.+ [['WordPress', 1290], ['Ghost', 1470]].forEach(([name, x], i) => {+ const w = u.measure(name, 21, 600) + 40;+ u.pop(live + 0.15 + i * 0.35, x + w / 2, 925, () => {+ u.card(x, 900, w, 50, { r: 25, lift: 0.5 });+ u.text(name, x + 20, 926, { size: 21, weight: 600 });+ }, { sfx: 'pop' });+ });+ u.cursor([+ { at: 0.4, x: 1300, y: 860 },+ { at: pub - 0.7, x: ax + 740, y: ay + 50 },+ { at: pub, click: true },+ { at: pub + 0.4, x: mx + 578, y: my + 318, dur: 0.75 },+ { at: send, click: true },+ ], { out: send + 0.6 });+ },++ outro(s) {+ const u = s.ui;+ u.backdrop();+ // Brand color fills the frame, with white cards drifting on it.+ const p = u.wipe(0);+ s.ctx.save();+ s.ctx.globalAlpha = p;+ u.floaters({ tint: 'white', alpha: 0.35 });+ s.ctx.restore();+ const x = 510;+ const y = 250;+ u.panel(x, y, 900, 560, { at: 0.45, r: 32, lift: 2, border: false, from: 0.9 }, () => {+ u.logo(960, y + 120, 330);+ u.headline("*Content that doesn't* read like AI.", 960, y + 285, { size: 72, at: '#brand' });+ u.pop('#try', 960, y + 383, () => u.button('Try it for free', 810, y + 350, 300, 66, { size: 23 }), { from: 0.8 });+ if (s.t >= s.time('#try')) u.text('unspar.com', 960, y + 470, { size: 24, weight: 500, color: u.colors.muted, align: 'center', alpha: s.p('#try', 0.4, 'out') });+ });+ },+};diff --git a/examples/unspar-demo/script.md b/examples/unspar-demo/script.mdnew file mode 100644index 0000000..a0d5901--- /dev/null+++ b/examples/unspar-demo/script.md@@ -0,0 +1,25 @@+# Unspar++## hook+[#logo] This is Unspar. [#writes] It writes articles for your website, like [#blog] blog posts and [#guides] guides.++## brief+First, [#tell] you tell it what to write about. Paste your [#site] website, [#pick] choose what you want to make and [#topic] add a topic. [#ideas] Unspar looks at your site and drafts a few ideas.++## ideas+A moment later, [#list] you have ideas to choose from. You [#choose] pick the one you like.++## price+[#price] Before anything runs, you see what it costs. [#queue] When you {queue|cue} it, the credits are set aside and the work starts.++## agents+Then [#agents] its AI agents get to work. They [#research] look up the topic, [#write] write the article in your voice and [#check] check the facts.++## voice+[#voice] You decide what that voice sounds like. Pick how [#formal] formal it is and [#rhythm] how the sentences flow.++## publish+When you're happy with it, [#publish] Unspar puts it on your site. [#live] It works with WordPress and Ghost.++## outro {hold=1}+[#brand] Unspar. Content that doesn't read like AI. [#try] Try it for free at {unspar.com|unspar dot com}.diff --git a/examples/unspar-demo/video.json b/examples/unspar-demo/video.jsonnew file mode 100644index 0000000..012dd90--- /dev/null+++ b/examples/unspar-demo/video.json@@ -0,0 +1,21 @@+{+ "title": "Unspar",+ "theme": "clean",+ "size": "youtube",+ "voice": "af_heart",+ "music": true,+ "captions": "auto",+ "brand": {+ "accent": "#245cff",+ "background": "#f8f6f1",+ "font": "Figtree",+ "headline": "Instrument Serif",+ "logo": "assets/unspar-logo.svg"+ },+ "fonts": [+ { "family": "Figtree", "src": "assets/fonts/Figtree-400.woff2", "weight": 400 },+ { "family": "Figtree", "src": "assets/fonts/Figtree-500.woff2", "weight": 500 },+ { "family": "Figtree", "src": "assets/fonts/Figtree-600.woff2", "weight": 600 },+ { "family": "Figtree", "src": "assets/fonts/Figtree-700.woff2", "weight": 700 }+ ]+}diff --git a/fonts/InstrumentSerif-400-italic-latin-ext.woff2 b/fonts/InstrumentSerif-400-italic-latin-ext.woff2new file mode 100644index 0000000..1f71909Binary files /dev/null and b/fonts/InstrumentSerif-400-italic-latin-ext.woff2 differdiff --git a/fonts/InstrumentSerif-400-italic-latin.woff2 b/fonts/InstrumentSerif-400-italic-latin.woff2new file mode 100644index 0000000..197abcaBinary files /dev/null and b/fonts/InstrumentSerif-400-italic-latin.woff2 differdiff --git a/fonts/InstrumentSerif-400-normal-latin-ext.woff2 b/fonts/InstrumentSerif-400-normal-latin-ext.woff2new file mode 100644index 0000000..0caad58Binary files /dev/null and b/fonts/InstrumentSerif-400-normal-latin-ext.woff2 differdiff --git a/fonts/InstrumentSerif-400-normal-latin.woff2 b/fonts/InstrumentSerif-400-normal-latin.woff2new file mode 100644index 0000000..0ad6971Binary files /dev/null and b/fonts/InstrumentSerif-400-normal-latin.woff2 differdiff --git a/fonts/fonts.json b/fonts/fonts.jsonindex 8ea329a..88c62c6 100644--- a/fonts/fonts.json+++ b/fonts/fonts.json@@ -69,48 +69,6 @@"file": "ArchitectsDaughter-400-latin.woff2","unicodeRange": "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"},- {- "family": "Inter",- "weight": 400,- "subset": "latin-ext",- "file": "Inter-400-latin-ext.woff2",- "unicodeRange": "U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF"- },- {- "family": "Inter",- "weight": 400,- "subset": "latin",- "file": "Inter-400-latin.woff2",- "unicodeRange": "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"- },- {- "family": "Inter",- "weight": 600,- "subset": "latin-ext",- "file": "Inter-400-latin-ext.woff2",- "unicodeRange": "U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF"- },- {- "family": "Inter",- "weight": 600,- "subset": "latin",- "file": "Inter-400-latin.woff2",- "unicodeRange": "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"- },- {- "family": "Inter",- "weight": 800,- "subset": "latin-ext",- "file": "Inter-400-latin-ext.woff2",- "unicodeRange": "U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF"- },- {- "family": "Inter",- "weight": 800,- "subset": "latin",- "file": "Inter-400-latin.woff2",- "unicodeRange": "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"- },{"family": "Plus Jakarta Sans","weight": 600,@@ -194,5 +152,51 @@"subset": "latin","file": "JetBrainsMono-400-latin.woff2","unicodeRange": "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"+ },+ {+ "family": "Inter",+ "weight": "100 900",+ "subset": "latin-ext",+ "file": "Inter-400-latin-ext.woff2",+ "unicodeRange": "U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF"+ },+ {+ "family": "Inter",+ "weight": "100 900",+ "subset": "latin",+ "file": "Inter-400-latin.woff2",+ "unicodeRange": "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"+ },+ {+ "family": "Instrument Serif",+ "weight": 400,+ "style": "normal",+ "subset": "latin-ext",+ "file": "InstrumentSerif-400-normal-latin-ext.woff2",+ "unicodeRange": "U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF"+ },+ {+ "family": "Instrument Serif",+ "weight": 400,+ "style": "normal",+ "subset": "latin",+ "file": "InstrumentSerif-400-normal-latin.woff2",+ "unicodeRange": "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"+ },+ {+ "family": "Instrument Serif",+ "weight": 400,+ "style": "italic",+ "subset": "latin-ext",+ "file": "InstrumentSerif-400-italic-latin-ext.woff2",+ "unicodeRange": "U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF"+ },+ {+ "family": "Instrument Serif",+ "weight": 400,+ "style": "italic",+ "subset": "latin",+ "file": "InstrumentSerif-400-italic-latin.woff2",+ "unicodeRange": "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD"}]diff --git a/fonts/licenses/InstrumentSerif-OFL.txt b/fonts/licenses/InstrumentSerif-OFL.txtnew file mode 100644index 0000000..669ce79--- /dev/null+++ b/fonts/licenses/InstrumentSerif-OFL.txt@@ -0,0 +1,93 @@+Copyright 2022 The Instrument Serif Project Authors (https://github.com/Instrument/instrument-serif)++This Font Software is licensed under the SIL Open Font License, Version 1.1.+This license is copied below, and is also available with a FAQ at:+https://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/src/project.js b/src/project.jsindex 17705a6..ab8a8ce 100644--- a/src/project.js+++ b/src/project.js@@ -51,8 +51,15 @@ export const DEFAULTS = {boil: 0,watermark: 'explainroo.com',images: null,+ brand: null,+ fonts: [],};+// Settings for the UI kit (s.ui), for product demos in a brand's own look.+export const BRAND_KEYS = ['accent', 'background', 'ink', 'font', 'headline', 'logo'];+const FONT_FILE = /\.(woff2?|ttf|otf)$/i;+const HEX = /^#[0-9a-f]{6}$/i;+export class ProjectError extends Error {}function fail(msg) {@@ -97,6 +104,36 @@ export function normalizeConfig(raw) {if (extra.length) fail(`images has unknown setting(s): ${extra.join(', ')}. Known: model, style`);}+ if (cfg.brand !== null) {+ if (typeof cfg.brand !== 'object' || Array.isArray(cfg.brand)) fail('brand must be an object like { "accent": "#2563eb", "logo": "assets/logo.svg" }');+ const extra = Object.keys(cfg.brand).filter((k) => !BRAND_KEYS.includes(k));+ if (extra.length) fail(`brand has unknown setting(s): ${extra.join(', ')}. Known: ${BRAND_KEYS.join(', ')}`);+ for (const k of ['accent', 'background', 'ink']) {+ if (cfg.brand[k] !== undefined && !HEX.test(cfg.brand[k])) fail(`brand.${k} must be a color like "#2563eb", not ${JSON.stringify(cfg.brand[k])}`);+ }+ for (const k of ['font', 'headline']) {+ if (cfg.brand[k] !== undefined && !(typeof cfg.brand[k] === 'string' && cfg.brand[k].trim())) fail(`brand.${k} must be a font family name, like "Inter"`);+ }+ if (cfg.brand.logo !== undefined && !(typeof cfg.brand.logo === 'string' && /^assets\/.+\.(svg|png|webp|jpe?g)$/i.test(cfg.brand.logo))) {+ fail('brand.logo must be an image in the assets/ folder, like "assets/logo.svg"');+ }+ }+ if (!Array.isArray(cfg.fonts)) fail('fonts must be a list like [{ "family": "Figtree", "src": "assets/fonts/figtree-600.woff2", "weight": 600 }]');+ cfg.fonts.forEach((f, i) => {+ const where = `fonts[${i}]`;+ if (!f || typeof f !== 'object' || Array.isArray(f)) fail(`${where} must be an object with family and src`);+ const extra = Object.keys(f).filter((k) => !['family', 'src', 'weight', 'style'].includes(k));+ if (extra.length) fail(`${where} has unknown setting(s): ${extra.join(', ')}. Known: family, src, weight, style`);+ if (!(typeof f.family === 'string' && f.family.trim())) fail(`${where}.family must be a font family name`);+ if (!(typeof f.src === 'string' && f.src.startsWith('assets/') && FONT_FILE.test(f.src) && !f.src.split('/').includes('..'))) {+ fail(`${where}.src must be a font file in the assets/ folder (.woff2, .woff, .ttf or .otf), like "assets/fonts/figtree-600.woff2"`);+ }+ const w = f.weight ?? 400;+ const range = typeof w === 'string' ? w.split(/\s+/).map(Number) : [w];+ if (!(range.length <= 2 && range.every((x) => Number.isInteger(x) && x >= 1 && x <= 1000))) fail(`${where}.weight must be a number like 600, or a range like "100 900" for a variable font`);+ if (f.style !== undefined && !['normal', 'italic'].includes(f.style)) fail(`${where}.style must be "normal" or "italic"`);+ });+let music = cfg.music;if (music === true) music = { style: THEME_MUSIC[cfg.theme] };else if (typeof music === 'string') music = { style: music };@@ -133,6 +170,9 @@ export function loadProject(arg) {fail(`video.json is not valid JSON: ${e.message}`);}const config = normalizeConfig(raw);+ for (const f of [...config.fonts.map((x) => x.src), ...(config.brand?.logo ? [config.brand.logo] : [])]) {+ if (!fs.existsSync(path.join(dir, f))) fail(`${f} is listed in video.json but the file is missing`);+ }const scriptPath = path.join(dir, 'script.md');if (!fs.existsSync(scriptPath)) fail(`${scriptPath} is missing`);const script = parseScript(fs.readFileSync(scriptPath, 'utf8'));diff --git a/src/server.js b/src/server.jsindex c2a1dfe..9eb97d6 100644--- a/src/server.js+++ b/src/server.js@@ -16,6 +16,9 @@ const TYPES = {'.wav': 'audio/wav','.mp3': 'audio/mpeg','.woff2': 'font/woff2',+ '.woff': 'font/woff',+ '.ttf': 'font/ttf',+ '.otf': 'font/otf','.png': 'image/png','.jpg': 'image/jpeg','.jpeg': 'image/jpeg',@@ -37,9 +40,9 @@ function safeJoin(base, rel) {}// Project files the engine page may read: scenes.js and the modules it-// imports, images, audio and video. Never dotfiles such as .env, and no-// JSON, Markdown or text files, which can hold keys or private notes.-const PROJECT_FILES = /\.(m?js|png|jpe?g|webp|gif|svg|wav|mp3|mp4)$/i;+// imports, images, fonts, audio and video. Never dotfiles such as .env, and+// no JSON, Markdown or text files, which can hold keys or private notes.+const PROJECT_FILES = /\.(m?js|png|jpe?g|webp|gif|svg|wav|mp3|mp4|woff2?|ttf|otf)$/i;function allowedName(rel) {const parts = rel.split(/[\\/]+/);diff --git a/test/brand.test.js b/test/brand.test.jsnew file mode 100644index 0000000..a79affe--- /dev/null+++ b/test/brand.test.js@@ -0,0 +1,38 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import { normalizeConfig, loadProject, ProjectError } from '../src/project.js';++test('brand settings for the UI kit are checked', () => {+ const cfg = normalizeConfig({ brand: { accent: '#245cff', background: '#f8f6f1', font: 'Figtree', headline: 'Instrument Serif', logo: 'assets/logo.svg' } });+ assert.equal(cfg.brand.accent, '#245cff');+ assert.equal(normalizeConfig({}).brand, null);+ assert.throws(() => normalizeConfig({ brand: { color: '#245cff' } }), /unknown setting\(s\): color/);+ assert.throws(() => normalizeConfig({ brand: { accent: 'blue' } }), /brand.accent must be a color/);+ assert.throws(() => normalizeConfig({ brand: { logo: '../logo.svg' } }), /assets\/ folder/);+ assert.throws(() => normalizeConfig({ brand: [] }), ProjectError);+});++test('a video can bring its own fonts', () => {+ const ok = normalizeConfig({ fonts: [{ family: 'Figtree', src: 'assets/fonts/Figtree-600.woff2', weight: 600 }, { family: 'Inter', src: 'assets/fonts/Inter.woff2', weight: '100 900', style: 'italic' }] });+ assert.equal(ok.fonts.length, 2);+ assert.throws(() => normalizeConfig({ fonts: {} }), /fonts must be a list/);+ assert.throws(() => normalizeConfig({ fonts: [{ family: 'X', src: 'fonts/x.woff2' }] }), /assets\/ folder/);+ assert.throws(() => normalizeConfig({ fonts: [{ family: 'X', src: 'assets/x.png' }] }), /assets\/ folder/);+ assert.throws(() => normalizeConfig({ fonts: [{ family: 'X', src: 'assets/../x.woff2' }] }), ProjectError);+ assert.throws(() => normalizeConfig({ fonts: [{ family: 'X', src: 'assets/x.woff2', weight: 'bold' }] }), /weight/);+ assert.throws(() => normalizeConfig({ fonts: [{ family: 'X', src: 'assets/x.woff2', style: 'oblique' }] }), /style/);+});++test('listed font and logo files must exist', () => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-brand-'));+ fs.writeFileSync(path.join(dir, 'script.md'), '# T\n\n## a\nHello.\n');+ fs.writeFileSync(path.join(dir, 'scenes.js'), 'export default { a() {} };');+ fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ brand: { logo: 'assets/logo.svg' } }));+ assert.throws(() => loadProject(dir), /assets\/logo.svg is listed in video.json but the file is missing/);+ fs.mkdirSync(path.join(dir, 'assets'));+ fs.writeFileSync(path.join(dir, 'assets', 'logo.svg'), '<svg/>');+ assert.equal(loadProject(dir).config.brand.logo, 'assets/logo.svg');+});diff --git a/test/server.test.js b/test/server.test.jsindex 2cf67fb..caa0c59 100644--- a/test/server.test.js+++ b/test/server.test.js@@ -27,11 +27,16 @@ test('the preview server keeps secrets and sources safe', async () => {fs.writeFileSync(path.join(dir, 'scenes.js'), 'export default {};');fs.mkdirSync(path.join(dir, 'assets'));fs.writeFileSync(path.join(dir, 'assets', 'logo.png'), 'png');+ fs.mkdirSync(path.join(dir, 'assets', 'fonts'));+ fs.writeFileSync(path.join(dir, 'assets', 'fonts', 'Brand-600.woff2'), 'font');+ fs.writeFileSync(path.join(dir, 'assets', 'fonts', 'OFL.txt'), 'license');const server = await startServer({ projectDir: dir, getState: () => ({}) });try {const port = server.port;assert.equal((await request(port, { path: '/project/scenes.js' })).status, 200);assert.equal((await request(port, { path: '/project/assets/logo.png' })).status, 200);+ assert.equal((await request(port, { path: '/project/assets/fonts/Brand-600.woff2' })).status, 200);+ assert.equal((await request(port, { path: '/project/assets/fonts/OFL.txt' })).status, 404);assert.equal((await request(port, { path: '/project/.env' })).status, 404);assert.equal((await request(port, { path: '/project/notes.md' })).status, 404);assert.equal((await request(port, { path: '/project/assets/../.env' })).status, 404);