@kud/cli-shot 0.2.1 → 0.3.1

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/dist/cli.js CHANGED
@@ -1,18 +1,87 @@
1
1
  #!/usr/bin/env node
2
- import { DEFAULT_FONT, listScreens, shootScreen, shootAll } from './chunk-TKCXCDP2.js';
2
+ import { FORMATS, DEFAULT_FONT, listScreens, shootScreens, shootAll } from './chunk-J6GAXRMG.js';
3
3
  import { Command } from 'commander';
4
4
 
5
+ // src/flags.ts
6
+ var number = (flag, value, check, rule) => {
7
+ const parsed = Number(value);
8
+ if (value.trim() === "" || !Number.isFinite(parsed) || !check(parsed)) {
9
+ throw new Error(`${flag} must be ${rule}, got ${JSON.stringify(value)}.`);
10
+ }
11
+ return parsed;
12
+ };
13
+ var movieFlags = ({
14
+ fps,
15
+ speed,
16
+ maxDuration,
17
+ loop,
18
+ scale
19
+ }) => ({
20
+ ...fps !== void 0 && {
21
+ fps: number(
22
+ "--fps",
23
+ fps,
24
+ (n) => n > 0 && n <= 50,
25
+ "a number above 0 and at most 50"
26
+ )
27
+ },
28
+ ...speed !== void 0 && {
29
+ speed: number("--speed", speed, (n) => n > 0, "a number above 0")
30
+ },
31
+ ...maxDuration !== void 0 && {
32
+ maxDuration: number(
33
+ "--max-duration",
34
+ maxDuration,
35
+ (n) => n > 0,
36
+ "a number of seconds above 0"
37
+ )
38
+ },
39
+ ...loop !== void 0 && {
40
+ loop: number(
41
+ "--loop",
42
+ loop,
43
+ (n) => Number.isInteger(n) && n >= 0,
44
+ "a whole number, 0 for forever"
45
+ )
46
+ },
47
+ ...scale !== void 0 && {
48
+ scale: number(
49
+ "--scale",
50
+ scale,
51
+ (n) => n > 0 && n <= 4,
52
+ "a number above 0 and at most 4"
53
+ )
54
+ }
55
+ });
56
+
57
+ // src/cli.ts
5
58
  var separator = process.argv.indexOf("--");
6
59
  var driven = separator === -1 ? [] : process.argv.slice(separator + 1);
7
60
  var own = separator === -1 ? process.argv : process.argv.slice(0, separator);
8
61
  var program = new Command();
9
62
  program.name("cli-shot").description(
10
63
  "Screenshot an interactive CLI, one image per screen.\n\nThe command to drive follows `--`:\n cli-shot --out assets/screenshots -- pcloud"
11
- ).requiredOption("-o, --out <dir>", "directory to write PNGs into").option("--only <screen>", "shoot one screen instead of every screen").option("--list", "print the screens the command offers, and stop").option("--cols <n>", "terminal columns", "110").option("--rows <n>", "terminal rows", "32").option("--settle <ms>", "how long the screen must hold still", "350").option("--keys <sequence>", "keystrokes to send once the screen has drawn").option(
64
+ ).requiredOption("-o, --out <dir>", "directory to write into").option(
65
+ "--format <list>",
66
+ `what to write per screen, comma-separated: ${FORMATS.join(", ")}`,
67
+ "png"
68
+ ).option("--only <screen>", "shoot one screen instead of every screen").option("--list", "print the screens the command offers, and stop").option("--cols <n>", "terminal columns", "110").option("--rows <n>", "terminal rows", "32").option("--settle <ms>", "how long the screen must hold still", "350").option("--keys <sequence>", "keystrokes to send once the screen has drawn").option(
12
69
  "--font <family>",
13
70
  "font to render with; needs Nerd Font coverage for TUI icons",
14
71
  DEFAULT_FONT
15
- ).option("--jobs <n>", "screens to shoot at once; defaults to core count").option("--no-mock", "drive real data instead of fixtures").parse(own);
72
+ ).option(
73
+ "--title <text>",
74
+ "page title for --format web, window title for gif/mp4"
75
+ ).option(
76
+ "--base <path>",
77
+ "path the web page is served under, when a site rewrites to it"
78
+ ).option("--fps <n>", "gif/mp4: frames per second (default 15)").option(
79
+ "--speed <n>",
80
+ "gif/mp4: playback speed, 2 is twice as fast (default 1)"
81
+ ).option(
82
+ "--max-duration <s>",
83
+ "gif/mp4: longest replay in seconds; longer ones are sped up to fit"
84
+ ).option("--loop <n>", "gif: times to play, 0 for forever (default 0)").option("--scale <n>", "gif/mp4: pixel density, 2 for retina (default 1)").option("--jobs <n>", "screens to shoot at once; defaults to core count").option("--no-mock", "drive real data instead of fixtures").parse(own);
16
85
  var options = program.opts();
17
86
  if (driven.length === 0) {
18
87
  console.error(
@@ -21,7 +90,25 @@ if (driven.length === 0) {
21
90
  process.exit(1);
22
91
  }
23
92
  var [command, ...args] = driven;
93
+ var formats = String(options.format).split(",").map((format) => format.trim()).filter(Boolean);
94
+ var unknown = formats.filter(
95
+ (format) => !FORMATS.includes(format)
96
+ );
97
+ if (unknown.length > 0 || formats.length === 0) {
98
+ console.error(
99
+ `Unknown format ${unknown.join(", ") || "(none)"}. Choose from: ${FORMATS.join(", ")}.`
100
+ );
101
+ process.exit(1);
102
+ }
103
+ var movie;
104
+ try {
105
+ movie = movieFlags(options);
106
+ } catch (error) {
107
+ console.error(error.message);
108
+ process.exit(1);
109
+ }
24
110
  var shoot = {
111
+ ...movie,
25
112
  command,
26
113
  args,
27
114
  out: options.out,
@@ -31,14 +118,17 @@ var shoot = {
31
118
  settle: Number(options.settle),
32
119
  keys: options.keys,
33
120
  font: options.font,
34
- concurrency: options.jobs ? Number(options.jobs) : void 0
121
+ concurrency: options.jobs ? Number(options.jobs) : void 0,
122
+ formats,
123
+ title: options.title,
124
+ base: options.base
35
125
  };
36
126
  if (options.list) {
37
127
  console.log(listScreens(command, args).join("\n"));
38
128
  process.exit(0);
39
129
  }
40
130
  try {
41
- const written = options.only ? [await shootScreen(options.only, shoot)] : await shootAll(shoot);
131
+ const written = options.only ? await shootScreens([options.only], shoot) : await shootAll(shoot);
42
132
  for (const path of written) console.log(path);
43
133
  } catch (error) {
44
134
  console.error(error instanceof Error ? error.message : String(error));
package/dist/index.d.ts CHANGED
@@ -8,8 +8,14 @@ type CaptureOptions = {
8
8
  env?: NodeJS.ProcessEnv;
9
9
  /** Keystrokes sent once the first draw has settled, for state a flag cannot name. */
10
10
  keys?: string;
11
+ /**
12
+ * Every chunk the pty produced, in order, with milliseconds since spawn —
13
+ * the raw stream before the emulator resolves it, which is what a recording
14
+ * replays. Stops at the moment the capture does.
15
+ */
16
+ onOutput?: (data: string, elapsed: number) => void;
11
17
  };
12
- declare const capture: (command: string, args?: readonly string[], { cols, rows, settle, timeout, env, keys, }?: CaptureOptions) => Promise<string>;
18
+ declare const capture: (command: string, args?: readonly string[], { cols, rows, settle, timeout, env, keys, onOutput, }?: CaptureOptions) => Promise<string>;
13
19
 
14
20
  declare const DEFAULT_FONT = "JetBrainsMono Nerd Font Mono";
15
21
  type RenderOptions = {
@@ -20,9 +26,173 @@ type RenderOptions = {
20
26
  };
21
27
  declare const toImage: (ansi: string, output: string, { font, freezeArgs }?: RenderOptions) => string;
22
28
 
29
+ declare const MOVIE_FORMATS: readonly ["gif", "mp4"];
30
+ type MovieFormat = (typeof MOVIE_FORMATS)[number];
31
+ type MovieOptions = {
32
+ /** Frames per second the replay is sampled at. Defaults to 15. */
33
+ fps?: number;
34
+ /** Playback speed: 2 plays twice as fast. Defaults to 1. */
35
+ speed?: number;
36
+ /**
37
+ * Longest the replay may run, in seconds, before the final hold. A longer
38
+ * recording is sped up to fit rather than cut, so it still ends on the
39
+ * settled frame — the one the PNG shows.
40
+ */
41
+ maxDuration?: number;
42
+ /** How long the final frame stays up, in seconds. Defaults to 2. */
43
+ hold?: number;
44
+ /** GIF only: times to play, 0 for forever. Defaults to 0. */
45
+ loop?: number;
46
+ /** Device pixels per CSS pixel. 2 is sharper and roughly three times larger. Defaults to 1. */
47
+ scale?: number;
48
+ };
49
+ type MovieInput = MovieOptions & {
50
+ /** The asciicast v2 text to replay. */
51
+ cast: string;
52
+ /** Screen name, shown in the window's title bar. */
53
+ screen: string;
54
+ /** Command name, shown before the screen in the title bar. */
55
+ title?: string;
56
+ /** File to write: `.gif` or `.mp4`. */
57
+ output: string;
58
+ format: MovieFormat;
59
+ /** A browser to reuse across several movies; one is launched and closed otherwise. */
60
+ browser?: MovieBrowser;
61
+ };
62
+ /** One still: how many events it shows, and for how long, in seconds. */
63
+ type MovieFrame = {
64
+ count: number;
65
+ duration: number;
66
+ };
67
+ declare const DEFAULT_FPS = 15;
68
+ declare const DEFAULT_HOLD = 2;
69
+ /**
70
+ * Sample a recording at `fps`, keeping only the ticks where something changed.
71
+ * A terminal is still most of the time, so a frame per tick would mostly
72
+ * repeat itself; one still held for the gap is the same picture, and far less
73
+ * to screenshot and encode. The last frame always shows every event.
74
+ */
75
+ declare const movieFrames: (times: readonly number[], { fps, speed, maxDuration, hold, }?: MovieOptions) => MovieFrame[];
76
+ type Route = {
77
+ request(): {
78
+ url(): string;
79
+ };
80
+ fulfill(response: {
81
+ path: string;
82
+ contentType: string;
83
+ }): Promise<void>;
84
+ abort(): Promise<void>;
85
+ };
86
+ type Box = {
87
+ x: number;
88
+ y: number;
89
+ width: number;
90
+ height: number;
91
+ };
92
+ type Page = {
93
+ route(url: string, handler: (route: Route) => unknown): Promise<void>;
94
+ goto(url: string): Promise<unknown>;
95
+ waitForSelector(selector: string): Promise<unknown>;
96
+ evaluate<T, A>(fn: (arg: A) => T | Promise<T>, arg: A): Promise<T>;
97
+ locator(selector: string): {
98
+ boundingBox(): Promise<Box | null>;
99
+ };
100
+ screenshot(options: {
101
+ path: string;
102
+ clip: Box;
103
+ }): Promise<unknown>;
104
+ close(): Promise<void>;
105
+ };
106
+ type MovieBrowser = {
107
+ newPage(options: {
108
+ viewport: {
109
+ width: number;
110
+ height: number;
111
+ };
112
+ deviceScaleFactor: number;
113
+ }): Promise<Page>;
114
+ close(): Promise<void>;
115
+ };
116
+ /** Launch the headless Chromium movies are filmed in. Needs `playwright` installed. */
117
+ declare const launchBrowser: () => Promise<MovieBrowser>;
118
+ /** Whether ffmpeg is on PATH; movies are encoded with it. */
119
+ declare const hasFfmpeg: () => boolean;
120
+ /**
121
+ * Film a recording in the web player's window and encode it as a GIF or MP4.
122
+ * The frames are the player's own rendering, stepped on the recording's clock
123
+ * rather than played in real time, so a slow machine films the same thing a
124
+ * fast one does. Returns the path written.
125
+ */
126
+ declare const toMovie: ({ cast, screen, title, output, format, browser, ...options }: MovieInput) => Promise<string>;
127
+
128
+ /** `o` output, `i` input, `r` resize ("COLSxROWS"), `m` marker. */
129
+ type CastEventCode = "o" | "i" | "r" | "m";
130
+ /** Seconds since the recording started, the event code, and its data. */
131
+ type CastEvent = readonly [time: number, code: CastEventCode, data: string];
132
+ type CastHeader = {
133
+ /** Terminal columns. */
134
+ width: number;
135
+ /** Terminal rows. */
136
+ height: number;
137
+ /** Unix time, in seconds, the recording started. */
138
+ timestamp?: number;
139
+ /** Gaps longer than this are shortened to it on replay, in seconds. */
140
+ idleTimeLimit?: number;
141
+ title?: string;
142
+ /** Only TERM and SHELL are meaningful to players. */
143
+ env?: Record<string, string>;
144
+ };
145
+ declare const castHeader: ({ width, height, timestamp, idleTimeLimit, title, env, }: CastHeader) => string;
146
+ declare const castEvent: ([time, code, data]: CastEvent) => string;
147
+ declare const toCast: (header: CastHeader, events: readonly CastEvent[]) => string;
148
+ type ParsedCast = {
149
+ header: {
150
+ version: 2;
151
+ width: number;
152
+ height: number;
153
+ } & Record<string, unknown>;
154
+ events: CastEvent[];
155
+ };
156
+ declare const parseCast: (text: string) => ParsedCast;
157
+
23
158
  declare const listScreens: (command: string, args?: readonly string[]) => string[];
24
159
 
25
- type ShootOptions = CaptureOptions & RenderOptions & {
160
+ type PlayerOptions = {
161
+ /** Directory holding the .cast files; the player is written alongside them. */
162
+ out: string;
163
+ /** Screens to show, in order, by name (`<name>.cast`). Defaults to every cast in `out`. */
164
+ screens?: readonly string[];
165
+ /** Page title. */
166
+ title?: string;
167
+ /**
168
+ * The path the page is served under, when that differs from where its files
169
+ * sit — e.g. `/projects/tidepool/demo/` when a site rewrites that path to
170
+ * this deployment. Becomes the page's `<base href>`; omit when served as is.
171
+ */
172
+ base?: string;
173
+ };
174
+ declare const VERCEL_CONFIG: {
175
+ $schema: string;
176
+ framework: null;
177
+ buildCommand: null;
178
+ installCommand: null;
179
+ trailingSlash: boolean;
180
+ headers: {
181
+ source: string;
182
+ headers: {
183
+ key: string;
184
+ value: string;
185
+ }[];
186
+ }[];
187
+ };
188
+ /**
189
+ * Write a static replay page for the casts in `out`: `index.html`, its assets
190
+ * (player, chrome, xterm.js, the Symbols Nerd Font) and a `vercel.json`. The
191
+ * folder deploys as it stands. Returns the paths written.
192
+ */
193
+ declare const buildPlayer: ({ out, screens, title, base, }: PlayerOptions) => string[];
194
+
195
+ type ShootOptions = CaptureOptions & RenderOptions & MovieOptions & {
26
196
  /** The CLI to drive. */
27
197
  command: string;
28
198
  /** Arguments before the ones this adds. */
@@ -37,9 +207,28 @@ type ShootOptions = CaptureOptions & RenderOptions & {
37
207
  mock?: boolean;
38
208
  /** How many screens to shoot at once. Defaults to the core count. */
39
209
  concurrency?: number;
210
+ /**
211
+ * What to write: `png` (rendered through freeze), `cast` (an asciicast v2
212
+ * recording of the same capture), `web` (the casts plus a static replay
213
+ * page, deployable as is), and/or `gif` / `mp4` (that page's window,
214
+ * filmed). Defaults to `["png"]`.
215
+ */
216
+ formats?: readonly Format[];
217
+ /** Title of the `web` page, and of the gif/mp4 window. Defaults to the command's name. */
218
+ title?: string;
219
+ /** Browser to film gif/mp4 in, shared across screens; launched per screen otherwise. */
220
+ browser?: MovieBrowser;
221
+ /** `<base href>` for the `web` page, when served under another path. */
222
+ base?: string;
40
223
  };
224
+ declare const FORMATS: readonly ["png", "cast", "web", "gif", "mp4"];
225
+ type Format = (typeof FORMATS)[number];
41
226
  declare const drivenScreen: (args: readonly string[]) => string | undefined;
42
- declare const shootScreen: (screen: string, { command, args, out, mock, ...rest }: ShootOptions) => Promise<string>;
227
+ declare const shootFormats: (screen: string, { command, args, out, mock, formats, title, browser, ...rest }: ShootOptions) => Promise<string[]>;
228
+ /** Shoot one screen to a PNG. See {@link shootFormats} for other formats. */
229
+ declare const shootScreen: (screen: string, options: ShootOptions) => Promise<string>;
43
230
  declare const shootAll: (options: ShootOptions) => Promise<string[]>;
231
+ /** Shoot the named screens in every requested format, and build the page if asked. */
232
+ declare const shootScreens: (screens: readonly string[], options: ShootOptions) => Promise<string[]>;
44
233
 
45
- export { type CaptureOptions, DEFAULT_FONT, type RenderOptions, type ShootOptions, capture, drivenScreen, listScreens, shootAll, shootScreen, toImage };
234
+ export { type CaptureOptions, type CastEvent, type CastEventCode, type CastHeader, DEFAULT_FONT, DEFAULT_FPS, DEFAULT_HOLD, FORMATS, type Format, MOVIE_FORMATS, type MovieBrowser, type MovieFormat, type MovieFrame, type MovieInput, type MovieOptions, type ParsedCast, type PlayerOptions, type RenderOptions, type ShootOptions, VERCEL_CONFIG, buildPlayer, capture, castEvent, castHeader, drivenScreen, hasFfmpeg, launchBrowser, listScreens, movieFrames, parseCast, shootAll, shootFormats, shootScreen, shootScreens, toCast, toImage, toMovie };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { DEFAULT_FONT, capture, drivenScreen, listScreens, shootAll, shootScreen, toImage } from './chunk-TKCXCDP2.js';
1
+ export { DEFAULT_FONT, DEFAULT_FPS, DEFAULT_HOLD, FORMATS, MOVIE_FORMATS, VERCEL_CONFIG, buildPlayer, capture, castEvent, castHeader, drivenScreen, hasFfmpeg, launchBrowser, listScreens, movieFrames, parseCast, shootAll, shootFormats, shootScreen, shootScreens, toCast, toImage, toMovie } from './chunk-J6GAXRMG.js';
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@kud/cli-shot",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
- "description": "Automatic screenshots of interactive CLIs — pty capture, terminal emulation, PNG out",
5
+ "description": "Automatic screenshots and recordings of interactive CLIs — pty capture, terminal emulation, PNG, asciicast, a web player, GIF or MP4 out",
6
6
  "license": "MIT",
7
7
  "homepage": "https://kud.io/projects/cli-shot",
8
8
  "repository": {
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "files": [
19
19
  "dist",
20
+ "player",
20
21
  "README.md",
21
22
  "LICENSE"
22
23
  ],
@@ -28,14 +29,26 @@
28
29
  "dev": "tsup --watch",
29
30
  "typecheck": "tsc --noEmit",
30
31
  "test": "vitest run",
31
- "test:watch": "vitest"
32
+ "test:watch": "vitest",
33
+ "example:casts": "node dist/cli.js --out examples/casts --format cast -- node examples/harbour.mjs",
34
+ "example:web": "node dist/cli.js --out examples/web --format web --title harbour -- node examples/harbour.mjs",
35
+ "example:gif": "node dist/cli.js --out examples/gif --format gif --title harbour -- node examples/harbour.mjs"
32
36
  },
33
37
  "dependencies": {
34
38
  "@xterm/addon-serialize": "0.14.0",
35
39
  "@xterm/headless": "6.0.0",
40
+ "@xterm/xterm": "6.0.0",
36
41
  "commander": "15.0.0",
37
42
  "node-pty": "1.1.0"
38
43
  },
44
+ "peerDependencies": {
45
+ "playwright": ">=1.40"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "playwright": {
49
+ "optional": true
50
+ }
51
+ },
39
52
  "devDependencies": {
40
53
  "@types/node": "22.20.1",
41
54
  "tsup": "8.5.1",
@@ -0,0 +1,273 @@
1
+ /*
2
+ * The whole look of the player lives here: page, window frame and terminal
3
+ * palette. player.js reads the --term-* tokens to theme xterm.js, so a new
4
+ * palette is a change to this file and nothing else.
5
+ *
6
+ * The window is a dark macOS terminal in both page themes: only the page
7
+ * around it follows light or dark. Light is the default; dark follows the
8
+ * system, and ?theme=light|dark on the page URL pins either one (it sets
9
+ * data-theme on <html>).
10
+ */
11
+
12
+ @font-face {
13
+ font-family: "Symbols Nerd Font Mono";
14
+ src: url("fonts/SymbolsNerdFontMono-Regular.woff2") format("woff2");
15
+ font-display: block;
16
+ /* Only the icon ranges, so it can sit first in the stack without taking
17
+ letters, digits or box drawing from the text font. */
18
+ unicode-range:
19
+ U+23FB-23FE, U+2665, U+26A1, U+2B58, U+E000-F8FF, U+F0000-FFFFD;
20
+ }
21
+
22
+ /* The window and its terminal: dark whatever the page does. */
23
+ :root {
24
+ color-scheme: light;
25
+
26
+ --page-bg: #f4f4f2;
27
+ --page-fg: #2b2b2b;
28
+
29
+ --frame-bg: #1c1c1e;
30
+ --frame-border: rgb(255 255 255 / 0.08);
31
+ --frame-radius: 10px;
32
+ --frame-shadow: 0 10px 30px rgb(0 0 0 / 0.25);
33
+ --frame-pad: 14px;
34
+ --frame-gap: 32px;
35
+ --bar-bg: #2a2a2c;
36
+ --bar-height: 32px;
37
+ --bar-fg: #9a9a9e;
38
+ --bar-fg-hover: #e4e4e4;
39
+ --bar-font: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas,
40
+ "DejaVu Sans Mono", monospace;
41
+ --dot-size: 11px;
42
+ --dot-gap: 7px;
43
+ --dot-close: #ff5f57;
44
+ --dot-min: #febc2e;
45
+ --dot-max: #28c840;
46
+ --focus-ring: #6aa0ff;
47
+
48
+ --term-font:
49
+ "Symbols Nerd Font Mono", ui-monospace, "SF Mono", "JetBrains Mono",
50
+ Menlo, Consolas, "DejaVu Sans Mono", monospace;
51
+ --term-font-size: 14;
52
+ --term-line-height: 1.15;
53
+
54
+ --term-bg: #1c1c1e;
55
+ --term-fg: #e4e4e4;
56
+ --term-cursor: #e4e4e4;
57
+ --term-selection: rgb(255 255 255 / 0.2);
58
+ --term-ansi-0: #1c1c1e;
59
+ --term-ansi-1: #ff6b63;
60
+ --term-ansi-2: #5fd06e;
61
+ --term-ansi-3: #f2c14e;
62
+ --term-ansi-4: #6aa0ff;
63
+ --term-ansi-5: #d68cf0;
64
+ --term-ansi-6: #4fd1d1;
65
+ --term-ansi-7: #d0d0d0;
66
+ --term-ansi-8: #6e6e6e;
67
+ --term-ansi-9: #ff8a84;
68
+ --term-ansi-10: #7fe08c;
69
+ --term-ansi-11: #ffd479;
70
+ --term-ansi-12: #8cb6ff;
71
+ --term-ansi-13: #e4a8f7;
72
+ --term-ansi-14: #74e3e3;
73
+ --term-ansi-15: #ffffff;
74
+ }
75
+
76
+ /* Dark, twice: once for the system preference, once for ?theme=dark. Only the
77
+ page changes; the window is already dark. */
78
+ @media (prefers-color-scheme: dark) {
79
+ :root:not([data-theme="light"]) {
80
+ color-scheme: dark;
81
+ --page-bg: #151515;
82
+ --page-fg: #e4e4e4;
83
+ --frame-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
84
+ }
85
+ }
86
+
87
+ :root[data-theme="dark"] {
88
+ color-scheme: dark;
89
+ --page-bg: #151515;
90
+ --page-fg: #e4e4e4;
91
+ --frame-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
92
+ }
93
+
94
+ *,
95
+ *::before,
96
+ *::after {
97
+ box-sizing: border-box;
98
+ }
99
+
100
+ body {
101
+ margin: 0;
102
+ background: var(--page-bg);
103
+ color: var(--page-fg);
104
+ font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
105
+ }
106
+
107
+ .demo {
108
+ display: flex;
109
+ flex-direction: column;
110
+ align-items: center;
111
+ gap: var(--frame-gap);
112
+ padding: 32px 16px;
113
+ }
114
+
115
+ .visually-hidden {
116
+ position: absolute;
117
+ width: 1px;
118
+ height: 1px;
119
+ overflow: hidden;
120
+ clip-path: inset(50%);
121
+ white-space: nowrap;
122
+ }
123
+
124
+ /* The frame shrink-wraps the terminal, and never exceeds the page: on a phone
125
+ the terminal is scaled down to fit rather than scrolled sideways. */
126
+ .window {
127
+ width: fit-content;
128
+ max-width: 100%;
129
+ margin: 0;
130
+ background: var(--frame-bg);
131
+ border: 1px solid var(--frame-border);
132
+ border-radius: var(--frame-radius);
133
+ box-shadow: var(--frame-shadow);
134
+ overflow: hidden;
135
+ }
136
+
137
+ .window-bar {
138
+ position: relative;
139
+ display: flex;
140
+ align-items: center;
141
+ justify-content: center;
142
+ height: var(--bar-height);
143
+ padding: 0 72px;
144
+ background: var(--bar-bg);
145
+ color: var(--bar-fg);
146
+ font: 12px/1 var(--bar-font);
147
+ user-select: none;
148
+ }
149
+
150
+ .window-dots {
151
+ position: absolute;
152
+ left: 12px;
153
+ display: flex;
154
+ gap: var(--dot-gap);
155
+ }
156
+
157
+ .window-dots i {
158
+ width: var(--dot-size);
159
+ height: var(--dot-size);
160
+ border-radius: 50%;
161
+ background: var(--dot-close);
162
+ }
163
+
164
+ .window-dots i:nth-child(2) {
165
+ background: var(--dot-min);
166
+ }
167
+
168
+ .window-dots i:nth-child(3) {
169
+ background: var(--dot-max);
170
+ }
171
+
172
+ .window-title {
173
+ overflow: hidden;
174
+ text-overflow: ellipsis;
175
+ white-space: nowrap;
176
+ }
177
+
178
+ .window-screen {
179
+ padding: var(--frame-pad);
180
+ background: var(--term-bg);
181
+ overflow: hidden;
182
+ }
183
+
184
+ /* player.js sets --term-width to the terminal's natural width and scales the
185
+ terminal down when that does not fit, setting this box's height to match so
186
+ the frame follows the scaled size rather than the natural one. */
187
+ .window-term {
188
+ width: var(--term-width, 80ch);
189
+ max-width: 100%;
190
+ overflow: hidden;
191
+ }
192
+
193
+ .window-term .xterm {
194
+ width: max-content;
195
+ transform-origin: top left;
196
+ }
197
+
198
+ .window-screen .xterm-viewport {
199
+ overflow: hidden !important;
200
+ }
201
+
202
+ /* A slim footer under the screen, in the bar's colour. */
203
+ .window-controls {
204
+ display: flex;
205
+ align-items: center;
206
+ gap: 2px;
207
+ height: var(--bar-height);
208
+ padding: 0 8px;
209
+ background: var(--bar-bg);
210
+ }
211
+
212
+ .control {
213
+ display: inline-grid;
214
+ place-items: center;
215
+ min-width: 28px;
216
+ height: 24px;
217
+ padding: 0 6px;
218
+ border: 0;
219
+ border-radius: 5px;
220
+ background: transparent;
221
+ color: var(--bar-fg);
222
+ font: 12px/1 var(--bar-font);
223
+ cursor: pointer;
224
+ }
225
+
226
+ .control:hover {
227
+ color: var(--bar-fg-hover);
228
+ background: rgb(255 255 255 / 0.06);
229
+ }
230
+
231
+ .control:focus-visible {
232
+ outline: 2px solid var(--focus-ring);
233
+ outline-offset: 1px;
234
+ }
235
+
236
+ .control svg {
237
+ grid-area: 1 / 1;
238
+ width: 13px;
239
+ height: 13px;
240
+ fill: currentColor;
241
+ }
242
+
243
+ .control-speed {
244
+ margin-left: auto;
245
+ }
246
+
247
+ /* The toggle shows what pressing it does: play while paused, pause while
248
+ playing. */
249
+ .window .icon-pause,
250
+ .window[data-state="playing"] .icon-play {
251
+ visibility: hidden;
252
+ }
253
+
254
+ .window[data-state="playing"] .icon-pause {
255
+ visibility: visible;
256
+ }
257
+
258
+ /* Filmed for --format gif or mp4: the controls would be a picture of buttons
259
+ nobody can press. */
260
+ :root[data-capture] .window-controls {
261
+ display: none;
262
+ }
263
+
264
+ @media (max-width: 520px) {
265
+ :root {
266
+ --frame-pad: 8px;
267
+ --bar-height: 28px;
268
+ }
269
+
270
+ .demo {
271
+ padding: 16px;
272
+ }
273
+ }