@cosmicdrift/kumiko-testing 0.419.0 → 0.421.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-testing",
3
- "version": "0.419.0",
3
+ "version": "0.421.0",
4
4
  "description": "Test template for Kumiko apps: per-flow seedTenant, app test stack, canonical test preloads, bunfig generator and integration runner.",
5
5
  "license": "MIT",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -107,9 +107,9 @@
107
107
  "kumiko-testing": "./bin/kumiko-testing.ts"
108
108
  },
109
109
  "dependencies": {
110
- "@cosmicdrift/kumiko-framework": "0.419.0",
111
- "@cosmicdrift/kumiko-guards": "0.419.0",
112
- "@cosmicdrift/kumiko-types": "0.419.0",
110
+ "@cosmicdrift/kumiko-framework": "0.421.0",
111
+ "@cosmicdrift/kumiko-guards": "0.421.0",
112
+ "@cosmicdrift/kumiko-types": "0.421.0",
113
113
  "zod": "^4.6.7"
114
114
  },
115
115
  "peerDependencies": {
@@ -133,8 +133,8 @@
133
133
  }
134
134
  },
135
135
  "devDependencies": {
136
- "@cosmicdrift/kumiko-bundled-features": "0.419.0",
137
- "@cosmicdrift/kumiko-dev-server": "0.419.0",
136
+ "@cosmicdrift/kumiko-bundled-features": "0.421.0",
137
+ "@cosmicdrift/kumiko-dev-server": "0.421.0",
138
138
  "@happy-dom/global-registrator": "^21.0.4",
139
139
  "@playwright/test": "^1.64.1",
140
140
  "@testing-library/dom": "^10.4.2",
package/src/changes.json CHANGED
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.420.0",
4
+ "type": "improvement",
5
+ "title": "Terminal and code editor stages for e2e videos",
6
+ "detail": "`terminalStage` and `editorStage` from `@cosmicdrift/kumiko-testing/e2e` return `{ html, durationMs }` for `tools.stage` and `tools.animate`. Typing rhythm is seeded, so the same options always produce the same video. The editor stage highlights TypeScript without extra dependencies."
7
+ },
2
8
  {
3
9
  "version": "0.418.0",
4
10
  "type": "fix",
package/src/e2e/index.ts CHANGED
@@ -97,5 +97,24 @@ export {
97
97
  type VideoTools,
98
98
  type VideoVoice,
99
99
  } from "./video/define-video";
100
+ export {
101
+ type EditorLine,
102
+ type EditorStageOptions,
103
+ editorStage,
104
+ } from "./video/editor-stage";
105
+ export type {
106
+ PreviewBox,
107
+ PreviewStage,
108
+ StagePreview,
109
+ StagePreviewCard,
110
+ } from "./video/preview-pane";
100
111
  export { type RunVideosOptions, runVideos } from "./video/run-videos";
112
+ export {
113
+ type StageOutputLine,
114
+ type StageTone,
115
+ type TerminalCommand,
116
+ type TerminalStageOptions,
117
+ type TypedStage,
118
+ terminalStage,
119
+ } from "./video/terminal-stage";
101
120
  export { findVideoTextGaps, loadVideoTexts } from "./video/video-texts";
@@ -28,6 +28,7 @@ export function installVideoOverlay(): void {
28
28
  const TOP = "2147483647";
29
29
 
30
30
  const layer = document.createElement("div");
31
+ layer.id = "kumiko-video-overlay";
31
32
  layer.style.cssText = `position:fixed;inset:0;pointer-events:none;z-index:${TOP};`;
32
33
 
33
34
  const cursor = document.createElementNS(SVG_NS, "svg");
@@ -50,8 +50,21 @@ export interface VideoMusic {
50
50
  readonly volume?: number;
51
51
  }
52
52
 
53
+ export const MIN_PLAYBACK_RATE = 0.5;
54
+ export const MAX_PLAYBACK_RATE = 2;
55
+
56
+ export function assertPlaybackRate(rate: number): void {
57
+ if (!(rate >= MIN_PLAYBACK_RATE && rate <= MAX_PLAYBACK_RATE)) {
58
+ throw new Error(
59
+ `playbackRate ${rate} must be between ${MIN_PLAYBACK_RATE} and ${MAX_PLAYBACK_RATE}`,
60
+ );
61
+ }
62
+ }
63
+
53
64
  export interface VideoDefinition {
54
65
  readonly music?: VideoMusic;
66
+ // Speeds picture, narration and subtitles up together, default 1; ffmpeg's atempo allows 0.5 to 2.
67
+ readonly playbackRate?: number;
55
68
  readonly voice: VideoVoice;
56
69
  readonly viewport?: { readonly width: number; readonly height: number };
57
70
  // Login/seed work; runs before recording starts.
@@ -70,6 +83,7 @@ export function defineVideo(definition: VideoDefinition): VideoDefinition {
70
83
  throw new Error(`defineVideo(): viewport ${width}x${height} must have even width and height`);
71
84
  }
72
85
  }
86
+ if (definition.playbackRate !== undefined) assertPlaybackRate(definition.playbackRate);
73
87
  const seen = new Set<string>();
74
88
  for (const scene of definition.scenes) {
75
89
  if (seen.has(scene.id)) throw new Error(`defineVideo(): duplicate scene id "${scene.id}"`);
@@ -0,0 +1,166 @@
1
+ import type { PreviewStage, StagePreview } from "./preview-pane";
2
+ import { FOCUS_SWITCH_DELAY_MS, previewParts } from "./preview-pane";
3
+ import {
4
+ blinkAnimationHtml,
5
+ escapeHtml,
6
+ STAGE_TEXT_COLOR,
7
+ STAGE_WINDOW_BACKGROUND,
8
+ stageCommonCss,
9
+ stageMsHtml,
10
+ visibleBetweenAnimationHtml,
11
+ windowFrameHtml,
12
+ } from "./stage-window";
13
+ import { seededRandom, typedWidthKeyframes, typingOffsetsMs } from "./typing";
14
+
15
+ export type EditorLine = string | { readonly typed: string };
16
+
17
+ export interface EditorStageOptions {
18
+ // tab label, e.g. "src/features/event/feature.ts"
19
+ readonly fileName: string;
20
+ readonly lines: readonly EditorLine[];
21
+ readonly firstLineNumber?: number;
22
+ readonly startDelayMs?: number;
23
+ readonly fontSizePx?: number;
24
+ readonly seed?: number;
25
+ readonly preview?: StagePreview;
26
+ }
27
+
28
+ const EDITOR_RHYTHM = { charMs: 28, jitterMs: 14, spaceExtraMs: 20 } as const;
29
+ const LINE_PAUSE_MS = 200;
30
+ const END_HOLD_MS = 1500;
31
+
32
+ type TokenKind = "comment" | "string" | "number" | "keyword" | "function" | "type" | "plain";
33
+
34
+ const TOKEN_COLORS = {
35
+ comment: "#6b7280",
36
+ string: "#a5d6a7",
37
+ number: "#f0b27a",
38
+ keyword: "#c792ea",
39
+ function: "#82aaff",
40
+ type: "#ffcb6b",
41
+ plain: STAGE_TEXT_COLOR,
42
+ } as const satisfies Record<TokenKind, string>;
43
+
44
+ const KEYWORDS = new Set([
45
+ "import",
46
+ "from",
47
+ "export",
48
+ "const",
49
+ "let",
50
+ "function",
51
+ "return",
52
+ "async",
53
+ "await",
54
+ "if",
55
+ "else",
56
+ "new",
57
+ "type",
58
+ "interface",
59
+ "true",
60
+ "false",
61
+ "null",
62
+ "undefined",
63
+ "as",
64
+ "satisfies",
65
+ "readonly",
66
+ "typeof",
67
+ "keyof",
68
+ "extends",
69
+ "void",
70
+ ]);
71
+
72
+ const TOKEN_PATTERN =
73
+ /(\/\/.*)|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*`)|(\b\d+(?:\.\d+)?\b)|([A-Za-z_$][\w$]*)|(\s+)|([\s\S])/gy;
74
+
75
+ function identifierKind(name: string, followedByParen: boolean): TokenKind {
76
+ if (KEYWORDS.has(name)) return "keyword";
77
+ if (followedByParen) return "function";
78
+ if (/^[A-Z]/.test(name)) return "type";
79
+ return "plain";
80
+ }
81
+
82
+ function highlightTypeScriptHtml(code: string): string {
83
+ const parts: string[] = [];
84
+ const emit = (kind: TokenKind, text: string): void => {
85
+ const escapedHtml = escapeHtml(text);
86
+ parts.push(
87
+ kind === "plain"
88
+ ? escapedHtml
89
+ : `<span style="color:${TOKEN_COLORS[kind]}">${escapedHtml}</span>`,
90
+ );
91
+ };
92
+ for (const match of code.matchAll(TOKEN_PATTERN)) {
93
+ const [text, comment, string, number, identifier] = match;
94
+ if (comment !== undefined) emit("comment", comment);
95
+ else if (string !== undefined) emit("string", string);
96
+ else if (number !== undefined) emit("number", number);
97
+ else if (identifier !== undefined) {
98
+ const next = code[(match.index ?? 0) + identifier.length];
99
+ emit(identifierKind(identifier, next === "(" || next === "<"), identifier);
100
+ } else emit("plain", text);
101
+ }
102
+ return parts.join("");
103
+ }
104
+
105
+ export function editorStage(options: EditorStageOptions): PreviewStage {
106
+ const fontSize = options.fontSizePx ?? 24;
107
+ const lineHeight = Math.round(fontSize * 1.6);
108
+ const firstNumber = options.firstLineNumber ?? 1;
109
+ const random = seededRandom(options.seed ?? 1);
110
+ const lastTypedIndex = options.lines.findLastIndex((line) => typeof line !== "string");
111
+ const gutterChars = String(firstNumber + options.lines.length - 1).length;
112
+ const keyframeCss: string[] = [];
113
+ let clock = options.startDelayMs ?? 600;
114
+ let typingEndMs = clock;
115
+
116
+ const rowsHtml = options.lines.map((line, index) => {
117
+ const number = `<span class="gutter">${firstNumber + index}</span>`;
118
+ if (typeof line === "string") {
119
+ return `<div class="line">${number}<span class="code">${highlightTypeScriptHtml(line)}</span></div>`;
120
+ }
121
+ const indent = line.typed.match(/^\s*/)?.[0] ?? "";
122
+ const rest = line.typed.slice(indent.length);
123
+ const offsets = typingOffsetsMs(rest, EDITOR_RHYTHM, random);
124
+ if (offsets.length === 0) {
125
+ return `<div class="line">${number}<span class="code">${escapeHtml(indent)}</span></div>`;
126
+ }
127
+ const keyframes = typedWidthKeyframes(`type-${index}`, offsets);
128
+ keyframeCss.push(keyframes.css);
129
+ const startMs = clock;
130
+ const endMs = startMs + keyframes.durationMs;
131
+ clock = endMs + LINE_PAUSE_MS;
132
+ typingEndMs = endMs;
133
+ const cursorAnimationHtml =
134
+ index === lastTypedIndex
135
+ ? `${visibleBetweenAnimationHtml(startMs)}, ${blinkAnimationHtml(endMs)}`
136
+ : visibleBetweenAnimationHtml(startMs, endMs);
137
+ const highlight = `<span class="active-line" style="animation: ${visibleBetweenAnimationHtml(startMs, endMs)}"></span>`;
138
+ const typed = `<span class="typed" style="animation: type-${index} ${stageMsHtml(keyframes.durationMs)} linear ${stageMsHtml(startMs)} forwards">${highlightTypeScriptHtml(rest)}</span>`;
139
+ const cursor = `<span class="caret" style="animation: ${cursorAnimationHtml}"></span>`;
140
+ return `<div class="line">${highlight}${number}<span class="code"><span class="indent">${escapeHtml(indent)}</span>${typed}${cursor}</span></div>`;
141
+ });
142
+
143
+ const styleHtml = `${stageCommonCss}
144
+ ${keyframeCss.join("\n")}
145
+ .tabs { flex: none; display: flex; background: #23252e; height: ${Math.round(fontSize * 1.9)}px; font-size: ${Math.round(fontSize * 0.7)}px; font-family: ui-sans-serif, system-ui, -apple-system, sans-serif; }
146
+ .tab { display: flex; align-items: center; padding: 0 ${Math.round(fontSize * 1.1)}px; background: ${STAGE_WINDOW_BACKGROUND}; color: ${STAGE_TEXT_COLOR}; border-top: 2px solid #5fd7e6; }
147
+ .editor { flex: 1 1 0; min-height: 0; overflow: hidden; padding: ${Math.round(fontSize * 0.7)}px 0; font-size: ${fontSize}px; line-height: ${lineHeight}px; }
148
+ .line { position: relative; display: flex; height: ${lineHeight}px; white-space: pre; }
149
+ .gutter { flex: none; width: ${gutterChars}ch; box-sizing: contentHtml-box; padding: 0 ${Math.round(fontSize * 1.2)}px; text-align: right; color: #4b5263; }
150
+ .code { position: relative; }
151
+ .active-line { position: absolute; inset: 0; background: rgba(255,255,255,0.05); opacity: 0; }
152
+ .typed { display: inline-block; overflow: hidden; vertical-align: bottom; width: 0; }
153
+ .caret { display: inline-block; width: 3px; height: ${Math.round(fontSize * 1.25)}px; vertical-align: bottom; background: ${STAGE_TEXT_COLOR}; opacity: 0; }
154
+ `;
155
+ const joinedRowsHtml = rowsHtml.join("");
156
+ const switchMs = typingEndMs + FOCUS_SWITCH_DELAY_MS;
157
+ const previewPart = options.preview ? previewParts(options.preview, switchMs) : undefined;
158
+ const titleBarPx = Math.round(fontSize * 1.8);
159
+ const html = `<!doctype html><html><head><meta charset="utf-8"><style>${styleHtml}${previewPart?.styleHtml ?? ""}</style></head><body>${windowFrameHtml(
160
+ "",
161
+ `<div class="tabs"><div class="tab">${escapeHtml(options.fileName)}</div></div><div class="editor">${joinedRowsHtml}</div>`,
162
+ titleBarPx,
163
+ )}${previewPart?.bodyHtml ?? ""}</body></html>`;
164
+ if (!previewPart) return { html, durationMs: typingEndMs + END_HOLD_MS };
165
+ return { html, durationMs: previewPart.durationMs, focusSwitchMs: switchMs };
166
+ }
@@ -94,7 +94,8 @@ export class FrameTimeline {
94
94
  type: async (target, text) => {
95
95
  await this.tools.click(target);
96
96
  for (const char of text) {
97
- await target.pressSequentially(char);
97
+ // pressSequentially refocuses the field per call, which resets segmented inputs like time to their first segment.
98
+ await this.page.keyboard.type(char);
98
99
  await this.capture(TYPE_FRAME_MS);
99
100
  }
100
101
  },
@@ -103,7 +104,11 @@ export class FrameTimeline {
103
104
  },
104
105
  snapshot: async () => {
105
106
  const png = await withPresentedIdentities(this.page, this.identities, () =>
106
- this.page.screenshot({ animations: "disabled" }),
107
+ this.page.screenshot({
108
+ animations: "disabled",
109
+ // The snapshot becomes stage content; a cursor baked into it would sit there frozen.
110
+ style: "#kumiko-video-overlay { display: none !important; }",
111
+ }),
107
112
  );
108
113
  return `data:image/png;base64,${png.toString("base64")}`;
109
114
  },
@@ -1,7 +1,7 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
  import { mkdirSync, renameSync, writeFileSync } from "node:fs";
3
3
  import { dirname, join } from "node:path";
4
- import type { VideoMusic } from "./define-video";
4
+ import { assertPlaybackRate, type VideoMusic } from "./define-video";
5
5
 
6
6
  export const VIDEO_FPS = 30;
7
7
 
@@ -63,10 +63,11 @@ function vttCueText(text: string): string {
63
63
  .replace(/\n\s*\n/g, "\n");
64
64
  }
65
65
 
66
- export function buildVtt(cues: readonly VttCue[]): string {
66
+ export function buildVtt(cues: readonly VttCue[], playbackRate = 1): string {
67
+ assertPlaybackRate(playbackRate);
67
68
  const blocks = cues.map(
68
69
  (cue) =>
69
- `${formatVttTimestamp(cue.startMs)} --> ${formatVttTimestamp(cue.endMs)}\n${vttCueText(cue.text)}`,
70
+ `${formatVttTimestamp(cue.startMs / playbackRate)} --> ${formatVttTimestamp(cue.endMs / playbackRate)}\n${vttCueText(cue.text)}`,
70
71
  );
71
72
  return `WEBVTT\n\n${blocks.join("\n\n")}\n`;
72
73
  }
@@ -110,15 +111,22 @@ export function buildMusicMixFilter(
110
111
  }
111
112
 
112
113
  // Video lives in filter_complex too: -vf cannot be mixed with -filter_complex.
113
- export function buildVideoFilter(brandInputIndex: number | undefined): string {
114
- if (brandInputIndex === undefined) return `[0:v]fps=${VIDEO_FPS}[vout]`;
115
- return `[0:v]fps=${VIDEO_FPS}[base];[base][${brandInputIndex}:v]overlay=W-w-40:H-h-40[vout]`;
114
+ export function buildVideoFilter(brandInputIndex: number | undefined, playbackRate = 1): string {
115
+ const speedUp = playbackRate === 1 ? "" : `setpts=PTS/${playbackRate},`;
116
+ if (brandInputIndex === undefined) return `[0:v]${speedUp}fps=${VIDEO_FPS}[vout]`;
117
+ return `[0:v]${speedUp}fps=${VIDEO_FPS}[base];[base][${brandInputIndex}:v]overlay=W-w-40:H-h-40[vout]`;
118
+ }
119
+
120
+ // Keeps the pitch; applied to the final mix so narration and music speed up together.
121
+ export function buildAudioSpeedFilter(playbackRate: number): string {
122
+ return `[aout]atempo=${playbackRate}[afast]`;
116
123
  }
117
124
 
118
125
  export interface MuxVideoOptions {
119
126
  readonly music?: VideoMusic;
120
127
  readonly metadataComment?: string;
121
128
  readonly brandPng?: string;
129
+ readonly playbackRate?: number;
122
130
  readonly frames: readonly MuxFrame[];
123
131
  readonly sceneAudio: readonly MuxSceneAudio[];
124
132
  readonly outMp4: string;
@@ -141,6 +149,9 @@ export function muxVideo(options: MuxVideoOptions): void {
141
149
 
142
150
  export function buildMuxArgs(options: MuxVideoOptions, listPath: string): string[] {
143
151
  const { frames, sceneAudio, outMp4, brandPng, music, metadataComment } = options;
152
+ const playbackRate = options.playbackRate ?? 1;
153
+ assertPlaybackRate(playbackRate);
154
+ const sped = playbackRate !== 1;
144
155
  const audioInputs = sceneAudio.flatMap((scene) => ["-i", scene.wavPath]);
145
156
  const musicInputIndex = music === undefined ? undefined : 1 + sceneAudio.length;
146
157
  const brandInputIndex =
@@ -165,11 +176,11 @@ export function buildMuxArgs(options: MuxVideoOptions, listPath: string): string
165
176
  ...(music === undefined ? [] : ["-i", music.file]),
166
177
  ...(brandPng === undefined ? [] : ["-i", brandPng]),
167
178
  "-filter_complex",
168
- `${buildVideoFilter(brandInputIndex)};${audioFilter}`,
179
+ `${buildVideoFilter(brandInputIndex, playbackRate)};${audioFilter}${sped ? `;${buildAudioSpeedFilter(playbackRate)}` : ""}`,
169
180
  "-map",
170
181
  "[vout]",
171
182
  "-map",
172
- "[aout]",
183
+ sped ? "[afast]" : "[aout]",
173
184
  "-c:v",
174
185
  "libx264",
175
186
  // CRF 28 halves the size of animated stages at no visible loss; faststart puts the
@@ -0,0 +1,114 @@
1
+ import {
2
+ escapeHtml,
3
+ STAGE_ACCENT_COLOR,
4
+ STAGE_MONO_FONT,
5
+ STAGE_TEXT_COLOR,
6
+ stageMsHtml,
7
+ } from "./stage-window";
8
+ import type { TypedStage } from "./terminal-stage";
9
+
10
+ export interface PreviewBox {
11
+ readonly x: number;
12
+ readonly y: number;
13
+ readonly width: number;
14
+ readonly height: number;
15
+ }
16
+
17
+ export interface StagePreviewCard {
18
+ readonly title: string;
19
+ readonly lines: readonly string[];
20
+ }
21
+
22
+ export interface StagePreview {
23
+ // data: or file URL of an app screenshot, typically tools.snapshot()
24
+ readonly imageUrl: string;
25
+ readonly imageWidthPx: number;
26
+ readonly imageHeightPx: number;
27
+ // App before the typed code, same pixel size as imageUrl. Shown while typing; imageUrl crossfades over it at the focus switch.
28
+ readonly beforeImageUrl?: string;
29
+ // in screenshot pixels, e.g. from locator.boundingBox() taken at the screenshot's viewport
30
+ readonly highlights?: readonly PreviewBox[];
31
+ readonly cards?: readonly StagePreviewCard[];
32
+ }
33
+
34
+ export type PreviewStage = TypedStage & { readonly focusSwitchMs?: number };
35
+
36
+ export const FOCUS_SWITCH_DELAY_MS = 300;
37
+ const FOCUS_TRANSITION_MS = 500;
38
+ const HIGHLIGHT_FADE_MS = 400;
39
+ const CARD_FIRST_DELAY_MS = 900;
40
+ const CARD_STAGGER_MS = 450;
41
+ const CARD_FLY_MS = 350;
42
+ const PREVIEW_HOLD_MS = 2500;
43
+
44
+ const HIGHLIGHT_PADDING_PX = 8;
45
+
46
+ // Elements below the fold report boxes past the screenshot edge.
47
+ function paddedWithinImage(box: PreviewBox, width: number, height: number): PreviewBox {
48
+ const x = Math.max(0, box.x - HIGHLIGHT_PADDING_PX);
49
+ const y = Math.max(0, box.y - HIGHLIGHT_PADDING_PX);
50
+ const right = Math.min(width, box.x + box.width + HIGHLIGHT_PADDING_PX);
51
+ const bottom = Math.min(height, box.y + box.height + HIGHLIGHT_PADDING_PX);
52
+ return { x, y, width: right - x, height: bottom - y };
53
+ }
54
+
55
+ const percentHtml = (value: number, total: number): string =>
56
+ `${+((value / total) * 100).toFixed(3)}%`;
57
+
58
+ interface PreviewParts {
59
+ readonly styleHtml: string;
60
+ readonly bodyHtml: string;
61
+ readonly durationMs: number;
62
+ }
63
+
64
+ export function previewParts(preview: StagePreview, switchMs: number): PreviewParts {
65
+ const { imageWidthPx: width, imageHeightPx: height } = preview;
66
+ const cards = preview.cards ?? [];
67
+ const focusAt = stageMsHtml(switchMs);
68
+ const highlightAt = switchMs + FOCUS_TRANSITION_MS;
69
+ const lastCardStartMs = switchMs + CARD_FIRST_DELAY_MS + (cards.length - 1) * CARD_STAGGER_MS;
70
+ const durationMs = Math.max(
71
+ highlightAt + PREVIEW_HOLD_MS,
72
+ cards.length > 0 ? lastCardStartMs + CARD_FLY_MS + PREVIEW_HOLD_MS : 0,
73
+ );
74
+ const styleHtml = `
75
+ .window { inset: 5vh 51vw 5vh 3vw; animation: focus-left ${FOCUS_TRANSITION_MS}ms ease-in-out ${focusAt} both; }
76
+ .preview { position: absolute; top: 5vh; bottom: 5vh; left: 51vw; right: 3vw; display: flex; align-items: center; justify-contentHtml: center; }
77
+ .shot { position: relative; width: min(100%, calc(90vh * ${width} / ${height})); aspect-ratio: ${width} / ${height}; opacity: .35; filter: saturate(.6); transform: scale(.97); animation: focus-right ${FOCUS_TRANSITION_MS}ms ease-in-out ${focusAt} both; }
78
+ .shot img { width: 100%; height: 100%; display: block; border-radius: 12px; box-shadow: 0 40px 120px rgba(0,0,0,0.65), 0 0 0 1px rgba(255,255,255,0.08); }
79
+ .shot img.after { position: absolute; inset: 0; opacity: 0; animation: crossfade-in ${FOCUS_TRANSITION_MS}ms ease-in-out ${focusAt} both; }
80
+ .highlight { position: absolute; box-sizing: border-box; border: 3px solid ${STAGE_ACCENT_COLOR}; border-radius: 8px; box-shadow: 0 0 24px rgba(95,215,230,0.55); opacity: 0; }
81
+ .cards { position: absolute; bottom: 6vh; left: 2vw; max-width: 60%; display: flex; flex-direction: column; gap: 14px; }
82
+ .card { padding: 16px 22px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.12); border-left: 4px solid ${STAGE_ACCENT_COLOR}; background: rgba(29,31,39,0.95); box-shadow: 0 16px 40px rgba(0,0,0,0.5); opacity: 0; }
83
+ .card-title { font: 700 22px ui-sans-serif, system-ui, -apple-system, sans-serif; color: ${STAGE_ACCENT_COLOR}; }
84
+ .card-line { margin-top: 6px; font: 18px ${STAGE_MONO_FONT}; color: ${STAGE_TEXT_COLOR}; }
85
+ @keyframes focus-left { from { opacity: 1; transform: scale(1); } to { opacity: .45; transform: scale(.97); } }
86
+ @keyframes focus-right { from { opacity: .35; filter: saturate(.6); transform: scale(.97); } to { opacity: 1; filter: saturate(1); transform: scale(1); } }
87
+ @keyframes crossfade-in { from { opacity: 0; } to { opacity: 1; } }
88
+ @keyframes highlight-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
89
+ @keyframes highlight-pulse { 0%, 100% { box-shadow: 0 0 24px rgba(95,215,230,0.55); } 50% { box-shadow: 0 0 44px rgba(95,215,230,0.95); } }
90
+ @keyframes card-in { from { opacity: 0; transform: translateX(-30px); } to { opacity: 1; transform: translateX(0); } }
91
+ `;
92
+ const highlightHtml = (preview.highlights ?? [])
93
+ .map((highlight) => paddedWithinImage(highlight, width, height))
94
+ .map(
95
+ (box) =>
96
+ `<div class="highlight" style="left:${percentHtml(box.x, width)};top:${percentHtml(box.y, height)};width:${percentHtml(box.width, width)};height:${percentHtml(box.height, height)};animation: highlight-in ${HIGHLIGHT_FADE_MS}ms ease-out ${stageMsHtml(highlightAt)} both, highlight-pulse 1200ms ease-in-out ${stageMsHtml(highlightAt + HIGHLIGHT_FADE_MS)} 1 both"></div>`,
97
+ )
98
+ .join("");
99
+ const afterUrlHtml = escapeHtml(preview.imageUrl);
100
+ const imagesHtml = preview.beforeImageUrl
101
+ ? `<img src="${escapeHtml(preview.beforeImageUrl)}" alt=""><img class="after" src="${afterUrlHtml}" alt="">`
102
+ : `<img src="${afterUrlHtml}" alt="">`;
103
+ const cardsHtml = cards
104
+ .map((card, index) => {
105
+ const startMs = switchMs + CARD_FIRST_DELAY_MS + index * CARD_STAGGER_MS;
106
+ const lines = card.lines
107
+ .map((line) => `<div class="card-line">${escapeHtml(line)}</div>`)
108
+ .join("");
109
+ return `<div class="card" style="animation: card-in ${CARD_FLY_MS}ms ease-out ${stageMsHtml(startMs)} both"><div class="card-title">${escapeHtml(card.title)}</div>${lines}</div>`;
110
+ })
111
+ .join("");
112
+ const bodyHtml = `<div class="preview"><div class="shot">${imagesHtml}${highlightHtml}</div>${cardsHtml ? `<div class="cards">${cardsHtml}</div>` : ""}</div>`;
113
+ return { styleHtml, bodyHtml, durationMs };
114
+ }
@@ -14,7 +14,11 @@ import { assertAiNoticeCoversLocales, SETUP_TOOLS, sceneExtensionMs } from "./sc
14
14
  import { synthesizeSpeech } from "./tts";
15
15
  import { loadVideoTexts } from "./video-texts";
16
16
 
17
- const INTRO_MS = 500;
17
+ // Silent lead-in held on the first scene frame; a frame from before the first scene shows whatever setup left on the page.
18
+ const LEAD_IN_MS = 500;
19
+
20
+ // A video walks through the app page by page on purpose; the default budget guards specs that should boot once.
21
+ const VIDEO_APP_BOOT_BUDGET = 60;
18
22
 
19
23
  export interface RunVideosOptions {
20
24
  readonly videos: Readonly<Record<string, VideoDefinition>>;
@@ -82,7 +86,10 @@ export function runVideos(options: RunVideosOptions): void {
82
86
  for (const locale of locales) {
83
87
  if (onlyLocales !== undefined && !onlyLocales.has(locale)) continue;
84
88
  test.describe(locale, () => {
85
- test.use({ locale: resolveLocaleTag(locale, undefined) });
89
+ test.use({
90
+ locale: resolveLocaleTag(locale, undefined),
91
+ maxAppBootsPerTest: VIDEO_APP_BOOT_BUDGET,
92
+ });
86
93
  test(`${id} [${locale}]`, async ({ page, seedTenant }, testInfo) => {
87
94
  const videoDir = join(videosDir, id);
88
95
  const texts = loadVideoTexts(videoDir, locale);
@@ -111,7 +118,6 @@ export function runVideos(options: RunVideosOptions): void {
111
118
  await video.setup?.(page, { ...ctx, tools: SETUP_TOOLS });
112
119
 
113
120
  await timeline.settle();
114
- await timeline.capture(INTRO_MS);
115
121
 
116
122
  const sceneAudio: MuxSceneAudio[] = [];
117
123
  const cues: VttCue[] = [];
@@ -127,7 +133,6 @@ export function runVideos(options: RunVideosOptions): void {
127
133
  apiKey: process.env["OPENROUTER_API_KEY"],
128
134
  });
129
135
 
130
- // Narration starts at the scene start, so the intro frame stays silent.
131
136
  const startMs = timeline.totalMs;
132
137
  await scene.do(page, { ...ctx, speechMs: speech.durationMs });
133
138
  const extensionMs = sceneExtensionMs(timeline.totalMs - startMs, speech.durationMs);
@@ -139,14 +144,17 @@ export function runVideos(options: RunVideosOptions): void {
139
144
  await showFocus(page, null);
140
145
 
141
146
  const sceneMs = timeline.totalMs - startMs;
147
+ const videoStartMs = LEAD_IN_MS + startMs;
142
148
  sceneAudio.push({
143
149
  wavPath: speech.wavPath,
144
- startMs,
150
+ startMs: videoStartMs,
145
151
  durationMs: speech.durationMs,
146
152
  sceneMs,
147
153
  });
148
- cues.push({ startMs, endMs: startMs + sceneMs, text });
154
+ cues.push({ startMs: videoStartMs, endMs: videoStartMs + sceneMs, text });
149
155
  }
156
+ const [firstFrame] = timeline.allFrames;
157
+ if (firstFrame !== undefined) firstFrame.durationMs += LEAD_IN_MS;
150
158
 
151
159
  const outDir = join(videoDir, "out");
152
160
  mkdirSync(outDir, { recursive: true });
@@ -163,12 +171,13 @@ export function runVideos(options: RunVideosOptions): void {
163
171
  ...(brandPng !== undefined && { brandPng }),
164
172
  ...(notice !== undefined && { metadataComment: notice }),
165
173
  ...(video.music !== undefined && { music: video.music }),
174
+ ...(video.playbackRate !== undefined && { playbackRate: video.playbackRate }),
166
175
  frames: timeline.allFrames,
167
176
  sceneAudio,
168
177
  outMp4,
169
178
  workDir: muxDir,
170
179
  });
171
- writeFileSync(join(outDir, `${locale}.vtt`), buildVtt(cues));
180
+ writeFileSync(join(outDir, `${locale}.vtt`), buildVtt(cues, video.playbackRate));
172
181
  });
173
182
  });
174
183
  }
@@ -0,0 +1,40 @@
1
+ export const STAGE_MONO_FONT = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
2
+ export const STAGE_TEXT_COLOR = "#d7dae0";
3
+ export const STAGE_WINDOW_BACKGROUND = "#1d1f27";
4
+ export const STAGE_ACCENT_COLOR = "#5fd7e6";
5
+ const BLINK_PERIOD_MS = 1060;
6
+
7
+ export const stageMsHtml = (value: number): string => `${Math.round(value)}ms`;
8
+
9
+ export const stageCommonCss = `
10
+ html, body { margin: 0; width: 100vw; height: 100vh; overflow: hidden; background: radial-gradient(ellipse at 30% 20%, #2b2f3d 0%, #14151b 70%); }
11
+ .window { position: absolute; inset: 5vh 5vw; display: flex; flex-direction: column; border-radius: 18px; overflow: hidden; background: ${STAGE_WINDOW_BACKGROUND}; box-shadow: 0 40px 120px rgba(0,0,0,0.65), 0 0 0 1px rgba(255,255,255,0.08); font-family: ${STAGE_MONO_FONT}; color: ${STAGE_TEXT_COLOR}; }
12
+ .titlebar { flex: none; position: relative; display: flex; align-items: center; background: #2a2d37; border-bottom: 1px solid rgba(0,0,0,0.4); }
13
+ .dots { position: absolute; left: 22px; display: flex; gap: 12px; }
14
+ .dot { width: 18px; height: 18px; border-radius: 50%; }
15
+ @keyframes on { from { opacity: 0; } to { opacity: 1; } }
16
+ @keyframes off { from { opacity: 1; } to { opacity: 0; } }
17
+ @keyframes blink { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; } }
18
+ `;
19
+
20
+ export function windowFrameHtml(
21
+ titlebarHtml: string,
22
+ bodyHtml: string,
23
+ titleBarPx: number,
24
+ ): string {
25
+ return `<div class="window"><div class="titlebar" style="height:${titleBarPx}px"><div class="dots"><span class="dot" style="background:#ff5f57"></span><span class="dot" style="background:#febc2e"></span><span class="dot" style="background:#28c840"></span></div>${titlebarHtml}</div>${bodyHtml}</div>`;
26
+ }
27
+
28
+ // Visible from fromMs until toMs (forever when omitted); both edges are 1ms steps.
29
+ export function visibleBetweenAnimationHtml(fromMs: number, toMs?: number): string {
30
+ const on = `on 1ms steps(1) ${stageMsHtml(fromMs)} both`;
31
+ return toMs === undefined ? on : `${on}, off 1ms steps(1) ${stageMsHtml(toMs)} forwards`;
32
+ }
33
+
34
+ export function blinkAnimationHtml(delayMs: number): string {
35
+ return `blink ${BLINK_PERIOD_MS}ms steps(1) ${stageMsHtml(delayMs)} infinite`;
36
+ }
37
+
38
+ export function escapeHtml(value: string): string {
39
+ return Bun.escapeHTML(value);
40
+ }
@@ -0,0 +1,230 @@
1
+ import {
2
+ FOCUS_SWITCH_DELAY_MS,
3
+ type PreviewStage,
4
+ previewParts,
5
+ type StagePreview,
6
+ } from "./preview-pane";
7
+ import {
8
+ blinkAnimationHtml,
9
+ escapeHtml,
10
+ stageCommonCss,
11
+ stageMsHtml,
12
+ visibleBetweenAnimationHtml,
13
+ windowFrameHtml,
14
+ } from "./stage-window";
15
+ import { seededRandom, typedWidthKeyframes, typingOffsetsMs } from "./typing";
16
+
17
+ export type StageTone = "plain" | "dim" | "success" | "error" | "accent";
18
+
19
+ export interface StageOutputLine {
20
+ readonly text: string;
21
+ readonly tone?: StageTone;
22
+ }
23
+
24
+ export interface TerminalCommand {
25
+ readonly command: string;
26
+ readonly output?: readonly (string | StageOutputLine)[];
27
+ // simulated work between Enter and the first output line, default 250
28
+ readonly busyMs?: number;
29
+ // displayed runtime, e.g. really measured; defaults to the animated duration
30
+ readonly elapsedMs?: number;
31
+ // the command never returns (e.g. a dev server): no meta, no new prompt; only allowed as the last command
32
+ readonly keepsRunning?: boolean;
33
+ // working directory for the lines after this command, e.g. after cd
34
+ readonly promptAfter?: string;
35
+ // pause after the last output line, default 700
36
+ readonly holdMs?: number;
37
+ }
38
+
39
+ export interface TerminalStageOptions {
40
+ readonly commands: readonly TerminalCommand[];
41
+ // working directory shown in the tab, the pane header and the prompt pill, default "~"
42
+ readonly prompt?: string;
43
+ readonly fontSizePx?: number;
44
+ readonly seed?: number;
45
+ // app screenshot on the right; the terminal moves left and focus switches after the last output line
46
+ readonly preview?: StagePreview;
47
+ }
48
+
49
+ export interface TypedStage {
50
+ readonly html: string;
51
+ readonly durationMs: number;
52
+ }
53
+
54
+ const TERMINAL_RHYTHM = { charMs: 70, jitterMs: 35, spaceExtraMs: 90 } as const;
55
+ const THINK_MS = 450;
56
+ const THINK_JITTER_MS = 150;
57
+ const ENTER_DELAY_MS = 250;
58
+ const OUTPUT_GAP_MS = 35;
59
+ const OUTPUT_GAP_JITTER_MS = 12;
60
+ const DEFAULT_BUSY_MS = 250;
61
+ const DEFAULT_HOLD_MS = 700;
62
+ const FINAL_BLINK_MS = 1200;
63
+
64
+ const WINDOW_BACKGROUND = "#0f1923";
65
+ const TABBAR_BACKGROUND = "#16202a";
66
+ const TAB_BACKGROUND = "#2a343e";
67
+ const TAB_BORDER = "#3a444e";
68
+ const TAB_TEXT_COLOR = "#c3ccd5";
69
+ const TAB_ICON_COLOR = "#9aa5b1";
70
+ const TABBAR_CONTROL_COLOR = "#6f7780";
71
+ const PATH_PILL_BACKGROUND = "#60b7f7";
72
+ const TEXT_COLOR = "#d5dde5";
73
+ const COMMAND_COLOR = "#f2f6fa";
74
+ const DIM_COLOR = "#7d8a97";
75
+ const SANS_FONT = "ui-sans-serif, system-ui, -apple-system, sans-serif";
76
+
77
+ const TONE_COLORS = {
78
+ plain: TEXT_COLOR,
79
+ dim: DIM_COLOR,
80
+ success: "#7bd88f",
81
+ error: "#ff6b6b",
82
+ accent: PATH_PILL_BACKGROUND,
83
+ } as const satisfies Record<StageTone, string>;
84
+
85
+ const ROBOT_ICON = `<svg class="tab-icon" viewBox="0 0 16 16" fill="none" stroke="${TAB_ICON_COLOR}" stroke-width="1.4" stroke-linecap="round"><rect x="2.5" y="5" width="11" height="8" rx="2"/><path d="M8 5V2.5"/><circle cx="5.8" cy="9" r="0.6" fill="${TAB_ICON_COLOR}"/><circle cx="10.2" cy="9" r="0.6" fill="${TAB_ICON_COLOR}"/></svg>`;
86
+
87
+ interface PathSegment {
88
+ readonly path: string;
89
+ readonly fromMs: number;
90
+ toMs?: number;
91
+ }
92
+
93
+ function jittered(base: number, spread: number, random: () => number): number {
94
+ return base + (random() * 2 - 1) * spread;
95
+ }
96
+
97
+ const normalizeOutputLine = (line: string | StageOutputLine): Required<StageOutputLine> =>
98
+ typeof line === "string"
99
+ ? { text: line, tone: "plain" }
100
+ : { text: line.text, tone: line.tone ?? "plain" };
101
+
102
+ const formatDurationHtml = (ms: number): string =>
103
+ ms < 1000 ? `${Math.round(ms)}ms` : `${(ms / 1000).toFixed(2)}s`;
104
+
105
+ // All paths share one grid cell; each is only visible during its segment.
106
+ const pathSwitcherHtml = (segments: readonly PathSegment[]): string =>
107
+ `<span class="paths">${segments
108
+ .map(
109
+ (segment) =>
110
+ `<span style="animation: ${visibleBetweenAnimationHtml(segment.fromMs, segment.toMs)}">${escapeHtml(segment.path)}</span>`,
111
+ )
112
+ .join("")}</span>`;
113
+
114
+ export function terminalStage(options: TerminalStageOptions): PreviewStage {
115
+ const fontSize = options.fontSizePx ?? 26;
116
+ const lineHeight = Math.round(fontSize * 1.5);
117
+ const titleBarPx = Math.round(fontSize * 1.8);
118
+ const random = seededRandom(options.seed ?? 1);
119
+ if (options.commands.slice(0, -1).some((entry) => entry.keepsRunning)) {
120
+ throw new Error("terminalStage: keepsRunning is only allowed on the last command");
121
+ }
122
+ const segments: PathSegment[] = [{ path: options.prompt ?? "~", fromMs: 0 }];
123
+ let clock = 0;
124
+ let lastOutputMs = 0;
125
+ const keyframeCss: string[] = [];
126
+ const rowsHtml: string[] = [];
127
+
128
+ const currentPath = (): string => segments[segments.length - 1]?.path ?? "";
129
+ const row = (appearAtMs: number, contentHtml: string): string =>
130
+ `<div class="row" style="animation: row-in 1ms steps(1, end) ${stageMsHtml(appearAtMs)} forwards">${contentHtml}</div>`;
131
+ const pathPillRow = (appearAtMs: number): string =>
132
+ row(appearAtMs, `<span class="pill">${escapeHtml(currentPath())}</span>`);
133
+
134
+ options.commands.forEach((entry, index) => {
135
+ const lineStart = clock;
136
+ const typeStart = lineStart + jittered(THINK_MS, THINK_JITTER_MS, random);
137
+ const offsets = typingOffsetsMs(entry.command, TERMINAL_RHYTHM, random);
138
+ const keyframes = typedWidthKeyframes(`type-${index}`, offsets);
139
+ keyframeCss.push(keyframes.css);
140
+ const enterAt = typeStart + (offsets.length > 0 ? keyframes.durationMs : 0) + ENTER_DELAY_MS;
141
+
142
+ // Wrapping rowsHtml reveal per character: a width-clipped box would show the whole text squeezed and re-wrap on every step.
143
+ const typed = options.preview
144
+ ? `<span class="typed-wrap">${Array.from(entry.command)
145
+ .map(
146
+ (char, charIndex) =>
147
+ `<span class="ch" style="animation: char-in 1ms steps(1, end) ${stageMsHtml(typeStart + (offsets[charIndex] ?? 0))} forwards">${escapeHtml(char)}</span>`,
148
+ )
149
+ .join("")}</span>`
150
+ : `<span class="typed" style="animation: type-${index} ${stageMsHtml(keyframes.durationMs)} linear ${stageMsHtml(typeStart)} forwards">${escapeHtml(entry.command)}</span>`;
151
+ const cursor = `<span class="cursor" style="animation: ${visibleBetweenAnimationHtml(lineStart, enterAt)}"></span>`;
152
+
153
+ let outputAt = enterAt + (entry.busyMs ?? DEFAULT_BUSY_MS);
154
+ const outputRows: string[] = [];
155
+ (entry.output ?? []).forEach((rawLine, lineIndex) => {
156
+ if (lineIndex > 0) outputAt += jittered(OUTPUT_GAP_MS, OUTPUT_GAP_JITTER_MS, random);
157
+ const line = normalizeOutputLine(rawLine);
158
+ outputRows.push(
159
+ row(
160
+ outputAt,
161
+ `<span style="color:${TONE_COLORS[line.tone]}">${escapeHtml(line.text)}</span>`,
162
+ ),
163
+ );
164
+ });
165
+ const meta = entry.keepsRunning
166
+ ? ""
167
+ : `<span class="meta" style="animation: ${visibleBetweenAnimationHtml(outputAt)}">${formatDurationHtml(entry.elapsedMs ?? outputAt - enterAt)} • exit 0</span>`;
168
+
169
+ rowsHtml.push(pathPillRow(lineStart));
170
+ rowsHtml.push(row(lineStart, `${typed}${cursor}${meta}`));
171
+ rowsHtml.push(...outputRows);
172
+
173
+ lastOutputMs = outputAt;
174
+ clock = outputAt + (entry.holdMs ?? DEFAULT_HOLD_MS);
175
+ if (entry.promptAfter !== undefined && entry.promptAfter !== currentPath()) {
176
+ const last = segments[segments.length - 1];
177
+ if (last) last.toMs = outputAt;
178
+ segments.push({ path: entry.promptAfter, fromMs: outputAt });
179
+ }
180
+ });
181
+
182
+ if (!options.commands[options.commands.length - 1]?.keepsRunning) {
183
+ rowsHtml.push(pathPillRow(clock));
184
+ rowsHtml.push(
185
+ row(clock, `<span class="cursor" style="animation: ${blinkAnimationHtml(clock)}"></span>`),
186
+ );
187
+ }
188
+
189
+ // Rows grow from height 0 instead of toggling display: animations never start on display:none elements.
190
+ const styleHtml = `${stageCommonCss}
191
+ .window { background: ${WINDOW_BACKGROUND}; color: ${TEXT_COLOR}; }
192
+ .titlebar { background: ${TABBAR_BACKGROUND}; border-bottom: none; }
193
+ .tabs { display: flex; align-items: center; gap: ${Math.round(fontSize * 0.5)}px; margin-left: 130px; height: 100%; font-family: ${SANS_FONT}; font-size: ${Math.round(titleBarPx * 0.38)}px; }
194
+ .tab { display: flex; align-items: center; gap: 10px; box-sizing: border-box; width: ${Math.round(fontSize * 12)}px; height: 72%; padding: 0 14px; border-radius: 9px; background: ${TAB_BACKGROUND}; border: 1px solid ${TAB_BORDER}; color: ${TAB_TEXT_COLOR}; overflow: hidden; white-space: nowrap; }
195
+ .tab-icon { flex: none; width: 1.2em; height: 1.2em; }
196
+ .tab .paths { flex: 1 1 0; min-width: 0; text-align: center; }
197
+ .tab-control { color: ${TABBAR_CONTROL_COLOR}; font-size: 1.3em; line-height: 1; }
198
+ .paths { display: grid; }
199
+ .paths > span { grid-area: 1 / 1; text-align: center; opacity: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
200
+ .pane-header { flex: none; display: flex; justify-contentHtml: center; padding-top: ${Math.round(fontSize * 0.3)}px; font-size: ${Math.round(fontSize * 0.7)}px; line-height: ${Math.round(fontSize * 1.1)}px; color: ${DIM_COLOR}; }
201
+ @keyframes row-in { from { height: 0; } to { height: ${lineHeight}px; } }
202
+ ${keyframeCss.join("\n")}
203
+ .body { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; justify-contentHtml: flex-end; overflow: hidden; }
204
+ .lines { min-height: 100%; flex-shrink: 0; box-sizing: border-box; padding: ${Math.round(fontSize * 0.6)}px ${Math.round(fontSize * 0.5)}px; font-size: ${fontSize}px; line-height: ${lineHeight}px; }
205
+ .row { height: 0; overflow: hidden; white-space: pre; }
206
+ .pill { display: inline-block; padding: 0 ${Math.round(fontSize * 0.3)}px; border-radius: 5px; background: ${PATH_PILL_BACKGROUND}; color: ${WINDOW_BACKGROUND}; line-height: ${Math.round(fontSize * 1.3)}px; }
207
+ .typed { display: inline-block; overflow: hidden; vertical-align: bottom; width: 0; color: ${COMMAND_COLOR}; font-weight: 700; }
208
+ .cursor { display: inline-block; width: 0.6em; height: ${Math.round(fontSize * 1.15)}px; vertical-align: bottom; background: ${COMMAND_COLOR}; opacity: 0; }
209
+ .meta { margin-left: 1.2em; font-size: 0.72em; color: ${DIM_COLOR}; opacity: 0; white-space: nowrap; }
210
+ `;
211
+ const joinedRowsHtml = rowsHtml.join("");
212
+ const switchMs = lastOutputMs + FOCUS_SWITCH_DELAY_MS;
213
+ const previewPart = options.preview ? previewParts(options.preview, switchMs) : undefined;
214
+ // The narrower window keeps the font size, so long lines wrap. Rows grow to their contentHtml up to a cap instead of a fixed height.
215
+ const wrapCss = previewPart
216
+ ? `
217
+ .row { height: auto; max-height: 0; white-space: pre-wrap; word-break: break-all; }
218
+ @keyframes row-in { from { max-height: 0; } to { max-height: ${lineHeight * 8}px; } }
219
+ @keyframes char-in { from { width: 0; } to { width: 1ch; } }
220
+ .typed-wrap { color: ${COMMAND_COLOR}; font-weight: 700; }
221
+ .ch { display: inline-block; width: 0; overflow: hidden; vertical-align: bottom; }
222
+ .meta { float: right; margin-left: 1.2em; }
223
+ `
224
+ : "";
225
+ const titlebar = `<div class="tabs"><div class="tab">${ROBOT_ICON}${pathSwitcherHtml(segments)}</div><span class="tab-control">+</span><span class="tab-control">⌄</span></div>`;
226
+ const body = `<div class="pane-header">${pathSwitcherHtml(segments)}</div><div class="body"><div class="lines">${joinedRowsHtml}</div></div>`;
227
+ const html = `<!doctype html><html><head><meta charset="utf-8"><style>${styleHtml}${wrapCss}${previewPart?.styleHtml ?? ""}</style></head><body>${windowFrameHtml(titlebar, body, titleBarPx)}${previewPart?.bodyHtml ?? ""}</body></html>`;
228
+ if (!previewPart) return { html, durationMs: clock + FINAL_BLINK_MS };
229
+ return { html, durationMs: previewPart.durationMs, focusSwitchMs: switchMs };
230
+ }
@@ -0,0 +1,54 @@
1
+ export interface TypingRhythm {
2
+ readonly charMs: number;
3
+ readonly jitterMs: number;
4
+ readonly spaceExtraMs: number;
5
+ }
6
+
7
+ const MIN_KEYSTROKE_MS = 25;
8
+
9
+ // mulberry32: tiny seeded PRNG so a video renders identically on every run.
10
+ export function seededRandom(seed: number): () => number {
11
+ let state = seed >>> 0;
12
+ return () => {
13
+ state = (state + 0x6d2b79f5) >>> 0;
14
+ let t = state;
15
+ t = Math.imul(t ^ (t >>> 15), t | 1);
16
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
17
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
18
+ };
19
+ }
20
+
21
+ export function typingOffsetsMs(
22
+ text: string,
23
+ rhythm: TypingRhythm,
24
+ random: () => number,
25
+ ): number[] {
26
+ const offsets: number[] = [];
27
+ let clock = 0;
28
+ for (const char of Array.from(text)) {
29
+ const jitter = (random() * 2 - 1) * rhythm.jitterMs;
30
+ clock += Math.max(MIN_KEYSTROKE_MS, rhythm.charMs + jitter);
31
+ offsets.push(clock);
32
+ if (char === " ") clock += rhythm.spaceExtraMs;
33
+ }
34
+ return offsets;
35
+ }
36
+
37
+ export function typedWidthKeyframes(
38
+ name: string,
39
+ offsetsMs: readonly number[],
40
+ ): { css: string; durationMs: number } {
41
+ const durationMs = offsetsMs[offsetsMs.length - 1];
42
+ if (durationMs === undefined) {
43
+ return { css: `@keyframes ${name} { from { width: 0ch; } to { width: 0ch; } }`, durationMs: 1 };
44
+ }
45
+ // steps(1, end) holds each width until the next keystroke instead of tweening between them.
46
+ const hold = "animation-timing-function: steps(1, end);";
47
+ const frames = [`0% { width: 0ch; ${hold} }`];
48
+ offsetsMs.forEach((offset, index) => {
49
+ const at =
50
+ index === offsetsMs.length - 1 ? "100%" : `${((offset / durationMs) * 100).toFixed(4)}%`;
51
+ frames.push(`${at} { width: ${index + 1}ch; ${hold} }`);
52
+ });
53
+ return { css: `@keyframes ${name} { ${frames.join(" ")} }`, durationMs };
54
+ }
@@ -78,9 +78,7 @@ async function syncExistingProjectionTable(
78
78
  const liveColumns = await columnNamesOf(ddlDbOf(stack), physical);
79
79
  const missingColumns = meta.columns.filter((c) => !liveColumns.has(c.name));
80
80
  if (missingColumns.length === 0) {
81
- logInfo(`[kumiko-stack] table ${physical} already exists — skipping create`);
82
81
  await addMissingIndexes(ddlDbOf(stack), physical, meta.indexes);
83
- // skip: table is already in sync, only indexes needed backfilling
84
82
  return;
85
83
  }
86
84