@steamfield/decks 1.0.0-rc.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/control-tray.css +80 -0
  3. package/dist/go-to-dialog.css +57 -0
  4. package/dist/{index-BURtH7IB.d.ts → index-D3Yj4yT6.d.ts} +11 -2
  5. package/dist/{index-BV_-6L5L.d.ts → index-DG8UcGQd.d.ts} +77 -1
  6. package/dist/{index-B2n69xrC.d.ts → index-zg-z6HTy.d.ts} +18 -2
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +2 -2
  9. package/dist/kit/term/live-term.module.css +36 -0
  10. package/dist/kit.d.ts +21 -6
  11. package/dist/kit.js +252 -8
  12. package/dist/live-term.module.css +36 -0
  13. package/dist/magic-move.css +30 -0
  14. package/dist/mark.css +34 -0
  15. package/dist/motion.d.ts +2 -2
  16. package/dist/motion.js +1 -1
  17. package/dist/node.d.ts +5 -1
  18. package/dist/node.js +1 -1
  19. package/dist/plugin/skills/building-a-deck/references/workflow.md +10 -0
  20. package/dist/plugin/skills/deck-design/references/layout.md +2 -0
  21. package/dist/plugin/skills/deck-motion/references/motion.md +38 -1
  22. package/dist/plugin/skills/working-with-decks/references/project.md +4 -0
  23. package/dist/{prose-patterns-DPqjGBFu.js → prose-patterns-D-tdt0Ab.js} +3 -1
  24. package/dist/{prose-scan-BrWZ7gxZ.js → prose-scan-ni8g6pc-.js} +2 -2
  25. package/dist/{src-DizFoqYt.js → src-BHlxNl0Z.js} +347 -42
  26. package/dist/{src-CmQgaG1b.js → src-BxuWgcUh.js} +581 -67
  27. package/dist/{src-C-OfT72W.js → src-CDNWEWZz.js} +212 -3
  28. package/dist/term/shell_pty.py +38 -0
  29. package/dist/term/zsh/.zshrc +4 -0
  30. package/dist/term-protocol-B_qHRDEp.js +11 -0
  31. package/dist/xterm-host-C6OjffSm.js +282 -0
  32. package/docs/README.md +1 -0
  33. package/docs/cli.md +1 -1
  34. package/docs/code-blocks.md +31 -0
  35. package/docs/config.md +1 -0
  36. package/docs/getting-started.md +2 -1
  37. package/docs/kit.md +7 -6
  38. package/docs/migrating-from-slidev.md +4 -0
  39. package/docs/motion.md +25 -1
  40. package/docs/presenting.md +16 -1
  41. package/docs/slides.md +20 -1
  42. package/docs/terminal.md +97 -0
  43. package/package.json +4 -1
@@ -1,33 +1,35 @@
1
- import { a as authorError, c as validationError, i as DeckError, n as loadPatterns, o as compileError, r as patternsFile, s as displayPath } from "./prose-patterns-DPqjGBFu.js";
1
+ import { a as authorError, c as displayPath, i as DeckError, l as validationError, n as loadPatterns, o as bugNotice, r as patternsFile, s as compileError } from "./prose-patterns-D-tdt0Ab.js";
2
+ import { a as TERM_POSITION, i as TERM_INPUT, n as TERM_DATA, o as TERM_READY, r as TERM_GONE, s as TERM_STATE, t as TERM_ATTACH } from "./term-protocol-B_qHRDEp.js";
2
3
  import { createRequire } from "node:module";
3
4
  import { parseArgs, stripVTControlCharacters } from "node:util";
4
5
  import { defineCommand, renderUsage, runCommand, showUsage } from "citty";
5
6
  import pc from "picocolors";
6
7
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
7
- import { constants, existsSync, readFileSync, statSync, writeSync } from "node:fs";
8
+ import { constants, existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeSync } from "node:fs";
8
9
  import { access, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rm, stat, writeFile } from "node:fs/promises";
9
10
  import getPort, { portNumbers } from "get-port";
10
11
  import { build as build$1, createLogger, createServer, defaultClientConditions, mergeConfig, normalizePath, preview } from "vite";
12
+ import { tmpdir } from "node:os";
13
+ import { fileURLToPath } from "node:url";
14
+ import { z } from "zod";
15
+ import { createJiti } from "jiti";
16
+ import { spawn, spawnSync } from "node:child_process";
11
17
  import { chromium, errors } from "playwright-core";
12
18
  import mdx from "@mdx-js/rollup";
13
19
  import react from "@vitejs/plugin-react";
14
20
  import remarkFrontmatter from "remark-frontmatter";
15
21
  import rehypeShiki from "@shikijs/rehype";
16
- import { bundledLanguages, createCssVariablesTheme, isSpecialLang } from "shiki";
22
+ import { bundledLanguages, createCssVariablesTheme, getSingletonHighlighter, isSpecialLang } from "shiki";
17
23
  import { unified } from "unified";
24
+ import { codeToKeyedTokens } from "@shikijs/magic-move/core";
25
+ import remarkParse from "remark-parse";
18
26
  import rehypeStringify from "rehype-stringify";
19
27
  import remarkMdx from "remark-mdx";
20
- import remarkParse from "remark-parse";
21
28
  import remarkRehype from "remark-rehype";
22
29
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
23
30
  import matter from "gray-matter";
24
31
  import { glob } from "tinyglobby";
25
- import { z } from "zod";
26
32
  import { parseSync } from "oxc-parser";
27
- import { createJiti } from "jiti";
28
- import { fileURLToPath } from "node:url";
29
- import { tmpdir } from "node:os";
30
- import { spawnSync } from "node:child_process";
31
33
  import { isUtf8 } from "node:buffer";
32
34
  import { createHash } from "node:crypto";
33
35
  // ../core/src/manifest.ts
@@ -72,6 +74,430 @@ function segmentNotes(markdown) {
72
74
  });
73
75
  return segments;
74
76
  }
77
+ // ../node/src/dev/config.ts
78
+ function defineDeck(config) {
79
+ return config;
80
+ }
81
+ const schema = z.strictObject({
82
+ title: z.string(),
83
+ author: z.string().optional(),
84
+ info: z.string().optional(),
85
+ url: z.url().optional(),
86
+ canvas: z.strictObject({
87
+ width: z.number().positive(),
88
+ height: z.number().positive()
89
+ }).default({
90
+ width: 1920,
91
+ height: 1080
92
+ }),
93
+ transition: z.string().min(1).optional(),
94
+ htmlAttrs: z.record(z.string(), z.string()).optional(),
95
+ credit: z.boolean().default(true),
96
+ term: z.strictObject({ dirs: z.record(z.string(), z.string()).optional() }).optional(),
97
+ vite: z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value)).optional(),
98
+ mdx: z.strictObject({
99
+ remarkPlugins: z.custom(Array.isArray, "mdx.remarkPlugins must be an array").optional(),
100
+ rehypePlugins: z.custom(Array.isArray, "mdx.rehypePlugins must be an array").optional()
101
+ }).optional()
102
+ });
103
+ async function loadDeck(dir, name) {
104
+ const absolute = resolve(dir);
105
+ const file = resolve(absolute, "deck.config.ts");
106
+ if (!existsSync(file)) throw new DeckError(`no deck.config.ts in ${displayPath(absolute)}. A deck directory holds deck.config.ts and slides/.`, file, void 0, { prefix: false });
107
+ const module = await createJiti(import.meta.url, {
108
+ moduleCache: false,
109
+ fsCache: false
110
+ }).import(file).catch((cause) => {
111
+ throw new DeckError(`cannot load config: ${cause instanceof Error ? cause.message : String(cause)}`, file, void 0, { cause });
112
+ });
113
+ if (!Object.hasOwn(module, "default")) throw new DeckError(`${displayPath(file)} has no default export. Write: export default defineDeck({ title: "..." })`, file, void 0, { prefix: false });
114
+ const parsed = schema.safeParse(module.default);
115
+ if (!parsed.success) throw validationError(file, parsed.error.issues, module.default, Object.keys(schema.shape));
116
+ const config = parsed.data;
117
+ for (const [key, path] of Object.entries(config.term?.dirs ?? {})) {
118
+ const directory = resolve(absolute, path);
119
+ if (config.term?.dirs) config.term.dirs[key] = directory;
120
+ }
121
+ for (const key of Object.keys(config.htmlAttrs ?? {})) if (!/^[A-Za-z_:][-A-Za-z0-9_:.]*$/.test(key)) throw new DeckError(`htmlAttrs key ${key} is not a valid HTML attribute name.`, file);
122
+ return {
123
+ name: name ?? basename(absolute),
124
+ dir: absolute,
125
+ config
126
+ };
127
+ }
128
+ // ../node/src/term/environment.ts
129
+ /** Remove package-runner state while preserving the user's own tools and settings. */
130
+ function shellEnvironment(env) {
131
+ const clean = Object.fromEntries(Object.entries(env).filter(([key]) => !key.startsWith("npm_") && ![
132
+ "NODE",
133
+ "NODE_OPTIONS",
134
+ "INIT_CWD"
135
+ ].includes(key)));
136
+ if (clean.PATH !== void 0) clean.PATH = clean.PATH.split(":").filter((entry) => !entry.replace(/\/+$/, "").endsWith("node_modules/.bin")).join(":");
137
+ return clean;
138
+ }
139
+ // ../node/src/term/sessions.ts
140
+ const promptMarker = "\x1B]133;A\x07";
141
+ function createSessions(options) {
142
+ const sessions = /* @__PURE__ */ new Map();
143
+ const replay = (s) => {
144
+ const bytes = Buffer.concat(s.buffer, s.bytes);
145
+ let from = Math.max(0, bytes.length - 204800);
146
+ while (from < bytes.length && ((bytes[from] ?? 0) & 192) === 128) from++;
147
+ return bytes.toString("utf8", from);
148
+ };
149
+ const state = (s) => ({
150
+ id: s.pane.id,
151
+ click: s.click,
152
+ busy: s.busy,
153
+ ran: [...s.ran],
154
+ queued: [...s.queued]
155
+ });
156
+ const broadcast = (s, event, data) => {
157
+ for (const client of s.clients) client.send(event, data);
158
+ };
159
+ const stop = (s) => {
160
+ sessions.delete(s.pane.id);
161
+ s.queued = [];
162
+ s.cancel?.();
163
+ s.pty?.kill();
164
+ };
165
+ const gone = (s, detail) => {
166
+ if (sessions.get(s.pane.id) !== s) return;
167
+ const reason = detail.replace(/[\r\n]+/g, " ");
168
+ stop(s);
169
+ broadcast(s, TERM_GONE, {
170
+ id: s.pane.id,
171
+ reason
172
+ });
173
+ options.log(`${s.pane.id}: ${reason}`);
174
+ };
175
+ const run = (s, click) => {
176
+ const command = s.pane.commands[click - 1];
177
+ if (!s.pty || command === void 0) return;
178
+ s.busy = true;
179
+ s.pty.write(command);
180
+ s.ran.add(click);
181
+ broadcast(s, TERM_STATE, state(s));
182
+ s.cancel = options.clock.later(() => {
183
+ s.cancel = void 0;
184
+ if (sessions.get(s.pane.id) === s) s.pty?.write("\r");
185
+ }, 600);
186
+ };
187
+ const start = (pane, clients, stamp) => {
188
+ const s = {
189
+ pane,
190
+ clients,
191
+ ready: false,
192
+ click: 0,
193
+ busy: true,
194
+ inputReceived: false,
195
+ ran: /* @__PURE__ */ new Set(),
196
+ queued: [],
197
+ stamp,
198
+ buffer: [],
199
+ bytes: 0,
200
+ tail: ""
201
+ };
202
+ sessions.set(pane.id, s);
203
+ let temporary;
204
+ const cleanup = () => {
205
+ if (temporary === void 0) return;
206
+ const path = temporary;
207
+ temporary = void 0;
208
+ try {
209
+ rmSync(path, {
210
+ recursive: true,
211
+ force: true
212
+ });
213
+ } catch (error) {
214
+ options.log(`${pane.id}: could not remove temporary directory "${path}": ${error instanceof Error ? error.message : String(error)}`);
215
+ }
216
+ };
217
+ try {
218
+ if (pane.cwd === "temp") temporary = options.tempDir();
219
+ const cwd = pane.cwd === "temp" ? temporary : Object.hasOwn(options.dirs, pane.cwd) ? options.dirs[pane.cwd] : void 0;
220
+ if (!cwd) throw new Error(`Pane "${pane.id}" has unknown terminal directory "${pane.cwd}"`);
221
+ s.pty = options.spawn({
222
+ rows: pane.rows,
223
+ cols: pane.cols,
224
+ cwd,
225
+ env: options.env
226
+ });
227
+ s.pty.onExit((reason) => {
228
+ cleanup();
229
+ gone(s, reason);
230
+ });
231
+ s.pty.onData((chunk) => {
232
+ if (sessions.get(pane.id) !== s) return;
233
+ const text = s.tail + chunk;
234
+ const prompted = text.includes(promptMarker);
235
+ s.tail = text.slice(-7);
236
+ const bytes = Buffer.from(chunk);
237
+ s.buffer.push(bytes);
238
+ s.bytes += bytes.length;
239
+ while (s.buffer[0] && s.bytes - s.buffer[0].length >= 204800) s.bytes -= s.buffer.shift()?.length ?? 0;
240
+ if (!s.ready && !prompted) return;
241
+ let printed = chunk;
242
+ if (!s.ready) {
243
+ s.ready = true;
244
+ broadcast(s, TERM_READY, {
245
+ id: pane.id,
246
+ buffer: ""
247
+ });
248
+ printed = replay(s);
249
+ }
250
+ broadcast(s, TERM_DATA, {
251
+ id: pane.id,
252
+ chunk: printed,
253
+ ...s.cancel ? { immediate: true } : {}
254
+ });
255
+ if (prompted && !s.cancel) {
256
+ s.busy = false;
257
+ const next = s.queued.shift();
258
+ if (next !== void 0) run(s, next);
259
+ else broadcast(s, TERM_STATE, state(s));
260
+ }
261
+ });
262
+ } catch (error) {
263
+ if (!s.pty) cleanup();
264
+ gone(s, `Shell could not start: ${error instanceof Error ? error.message : String(error)}`);
265
+ }
266
+ };
267
+ const find = (id, client) => {
268
+ const s = sessions.get(id);
269
+ if (!s) client.send(TERM_GONE, {
270
+ id,
271
+ reason: `Unknown terminal pane "${id}"`
272
+ });
273
+ return s;
274
+ };
275
+ return {
276
+ attach(pane, client) {
277
+ const s = sessions.get(pane.id);
278
+ if (!s) return start(pane, /* @__PURE__ */ new Set([client]));
279
+ s.clients.add(client);
280
+ if (s.pane.rows !== pane.rows || s.pane.cols !== pane.cols || s.pane.cwd !== pane.cwd || s.pane.commands.length !== pane.commands.length || s.pane.commands.some((command, index) => command !== pane.commands[index])) {
281
+ stop(s);
282
+ start(pane, s.clients, s.stamp);
283
+ const fresh = sessions.get(pane.id);
284
+ if (fresh) broadcast(fresh, TERM_STATE, state(fresh));
285
+ return;
286
+ }
287
+ if (s.ready) client.send(TERM_READY, {
288
+ id: pane.id,
289
+ buffer: replay(s)
290
+ });
291
+ if (s.ready || s.queued.length > 0) client.send(TERM_STATE, state(s));
292
+ },
293
+ position(id, click, entered, client, stamp) {
294
+ const s = find(id, client);
295
+ if (!s) return;
296
+ if (s.stamp && (stamp.seq < s.stamp.seq || stamp.seq === s.stamp.seq && (stamp.started > s.stamp.started || stamp.started === s.stamp.started && stamp.origin < s.stamp.origin))) return;
297
+ s.stamp = stamp;
298
+ const previous = s.click;
299
+ s.click = click;
300
+ if (click === 0) {
301
+ s.queued = [];
302
+ if ((previous > 0 || entered) && (s.ran.size > 0 || s.inputReceived)) {
303
+ stop(s);
304
+ start(s.pane, s.clients, s.stamp);
305
+ const fresh = sessions.get(id);
306
+ if (fresh) broadcast(fresh, TERM_STATE, state(fresh));
307
+ return;
308
+ }
309
+ }
310
+ if (click <= 0 || s.pane.commands[click - 1] === void 0 || s.ran.has(click) || s.queued.includes(click) || !s.pane.commands.slice(0, click - 1).every((_, index) => s.ran.has(index + 1) || s.queued.includes(index + 1))) {
311
+ broadcast(s, TERM_STATE, state(s));
312
+ return;
313
+ }
314
+ if (s.busy || !s.ready || s.queued.length > 0) {
315
+ s.queued.push(click);
316
+ broadcast(s, TERM_STATE, state(s));
317
+ } else run(s, click);
318
+ },
319
+ input(id, data, client) {
320
+ const s = find(id, client);
321
+ if (!s) return;
322
+ s.inputReceived = true;
323
+ if (/[\r\n]/.test(data)) {
324
+ s.busy = true;
325
+ broadcast(s, TERM_STATE, state(s));
326
+ }
327
+ s.pty?.write(data);
328
+ },
329
+ detach(client) {
330
+ for (const s of sessions.values()) {
331
+ s.clients.delete(client);
332
+ if (s.clients.size === 0) s.stamp = void 0;
333
+ }
334
+ },
335
+ close() {
336
+ for (const s of sessions.values()) stop(s);
337
+ }
338
+ };
339
+ }
340
+ // ../node/src/term/shell.ts
341
+ function shellSpawn() {
342
+ return ({ rows, cols, cwd, env }) => {
343
+ const child = spawn("python3", [
344
+ fileURLToPath(new URL(`${import.meta.url.endsWith(".ts") ? "../../term/" : "./term/"}shell_pty.py`, import.meta.url)),
345
+ String(rows),
346
+ String(cols),
347
+ "zsh",
348
+ "-d"
349
+ ], {
350
+ cwd,
351
+ env,
352
+ stdio: [
353
+ "pipe",
354
+ "pipe",
355
+ "pipe"
356
+ ]
357
+ });
358
+ let failure = "";
359
+ let ended;
360
+ let receiveExit;
361
+ const exit = (reason) => {
362
+ if (ended !== void 0) return;
363
+ ended = reason;
364
+ receiveExit?.(reason);
365
+ };
366
+ child.stdout.setEncoding("utf8");
367
+ child.stderr.setEncoding("utf8");
368
+ child.stderr.on("data", (chunk) => {
369
+ failure = (failure + chunk).slice(-1024);
370
+ });
371
+ child.on("error", (error) => {
372
+ failure = `Shell could not start: ${error.message}`;
373
+ });
374
+ child.stdin.on("error", (error) => {
375
+ failure = `Shell input failed: ${error.message}`;
376
+ });
377
+ child.on("close", (code, signal) => exit(failure.trim() || `Shell exited (${signal ?? code ?? "unknown status"})`));
378
+ return {
379
+ write(data) {
380
+ child.stdin.write(data);
381
+ },
382
+ kill() {
383
+ child.stdin.end();
384
+ },
385
+ onData(receive) {
386
+ child.stdout.on("data", receive);
387
+ },
388
+ onExit(receive) {
389
+ receiveExit = receive;
390
+ if (ended !== void 0) receive(ended);
391
+ }
392
+ };
393
+ };
394
+ }
395
+ // ../node/src/term/plugin.ts
396
+ const attachMessage = z.object({ pane: z.object({
397
+ id: z.string(),
398
+ cwd: z.string(),
399
+ rows: z.int().min(1).max(65535),
400
+ cols: z.int().min(1).max(65535),
401
+ commands: z.array(z.string())
402
+ }) });
403
+ const positionMessage = z.object({
404
+ id: z.string(),
405
+ click: z.int().min(0),
406
+ entered: z.boolean(),
407
+ stamp: z.object({
408
+ seq: z.int().min(0),
409
+ started: z.number(),
410
+ origin: z.string()
411
+ })
412
+ });
413
+ const inputMessage = z.object({
414
+ id: z.string(),
415
+ data: z.string()
416
+ });
417
+ function liveTerm(deckDir, platform = process.platform) {
418
+ return {
419
+ name: "deck-live-term",
420
+ apply: "serve",
421
+ async configureServer(server) {
422
+ const dirs = (await loadDeck(deckDir)).config.term?.dirs ?? {};
423
+ for (const [key, path] of Object.entries(dirs)) {
424
+ let isDirectory;
425
+ try {
426
+ isDirectory = statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
427
+ } catch (cause) {
428
+ throw new DeckError(`cannot inspect term.dirs key "${key}" at "${displayPath(path)}". Check that the directory is accessible.`, join(deckDir, "deck.config.ts"), void 0, { cause });
429
+ }
430
+ if (!isDirectory) throw new DeckError(`term.dirs key "${key}" points at "${displayPath(path)}", which is not a directory.`, join(deckDir, "deck.config.ts"));
431
+ }
432
+ const bind = () => {
433
+ if (platform === "win32") {
434
+ server.config.logger.warn("Live terminal disabled: Windows is not supported");
435
+ return;
436
+ }
437
+ if (server.config.legacy?.skipWebSocketTokenCheck === true) {
438
+ server.config.logger.warn("Live terminal disabled: legacy.skipWebSocketTokenCheck disables WebSocket authentication");
439
+ return;
440
+ }
441
+ if (server.config.server.allowedHosts === true) {
442
+ server.config.logger.warn("Live terminal disabled: server.allowedHosts allows any Host");
443
+ return;
444
+ }
445
+ const ws = server.config.server.ws;
446
+ if (ws && (ws.server && ws.server !== server.httpServer || ws.port && ws.port !== server.config.server.port)) {
447
+ server.config.logger.warn("Live terminal disabled: a separate HMR WebSocket transport is not supported");
448
+ return;
449
+ }
450
+ const address = server.httpServer?.address();
451
+ const host = address && typeof address !== "string" ? address.address : String(address);
452
+ if (!(host === "::1" || /^127\./.test(host) || /^::ffff:127\./.test(host))) {
453
+ server.config.logger.warn(`Live terminal disabled: host "${host}" is not loopback`);
454
+ return;
455
+ }
456
+ const sessions = createSessions({
457
+ spawn: shellSpawn(),
458
+ clock: { later(run, ms) {
459
+ const timer = setTimeout(run, ms);
460
+ return () => clearTimeout(timer);
461
+ } },
462
+ tempDir: () => mkdtempSync(join(tmpdir(), "deck-term-")),
463
+ dirs,
464
+ env: {
465
+ ...shellEnvironment(process.env),
466
+ TERM: "xterm-256color",
467
+ ZDOTDIR: fileURLToPath(new URL(`${import.meta.url.endsWith(".ts") ? "../../term/" : "./term/"}zsh`, import.meta.url))
468
+ },
469
+ log: (reason) => server.config.logger.warn(`Live terminal: ${reason}`)
470
+ });
471
+ const malformed = (event, error) => server.config.logger.warn(`Live terminal: malformed ${event}: ${error.issues.map((issue) => `${issue.path.join(".") || "message"}: ${issue.message}`).join("; ")}`);
472
+ const sockets = /* @__PURE__ */ new WeakSet();
473
+ server.ws.on(TERM_ATTACH, (message, client) => {
474
+ const parsed = attachMessage.safeParse(message);
475
+ if (!parsed.success) return malformed(TERM_ATTACH, parsed.error);
476
+ const { pane } = parsed.data;
477
+ if (!sockets.has(client.socket)) {
478
+ sockets.add(client.socket);
479
+ client.socket.once("close", () => sessions.detach(client));
480
+ }
481
+ sessions.attach(pane, client);
482
+ });
483
+ server.ws.on(TERM_POSITION, (message, client) => {
484
+ const parsed = positionMessage.safeParse(message);
485
+ if (!parsed.success) return malformed(TERM_POSITION, parsed.error);
486
+ const { id, click, entered, stamp } = parsed.data;
487
+ sessions.position(id, click, entered, client, stamp);
488
+ });
489
+ server.ws.on(TERM_INPUT, (message, client) => {
490
+ const parsed = inputMessage.safeParse(message);
491
+ if (!parsed.success) return malformed(TERM_INPUT, parsed.error);
492
+ const { id, data } = parsed.data;
493
+ sessions.input(id, data, client);
494
+ });
495
+ server.httpServer?.once("close", () => sessions.close());
496
+ };
497
+ server.httpServer?.once("listening", bind);
498
+ }
499
+ };
500
+ }
75
501
  // ../node/src/dev/browser.ts
76
502
  var MissingChromiumError = class extends DeckError {
77
503
  constructor(cause) {
@@ -205,8 +631,122 @@ function parseCodeOptions(meta, lineCount, file) {
205
631
  }
206
632
  return options;
207
633
  }
634
+ // ../node/src/mdx/magic-move.ts
635
+ const parser$2 = unified().use(remarkParse);
636
+ const isBundledLanguage = (lang) => lang in bundledLanguages;
637
+ function isMagicMove(lang, meta) {
638
+ return /^(?:md|markdown)$/.test(lang ?? "") && /^magic-move(?:\s|$)/.test(meta ?? "");
639
+ }
640
+ function parseMagicMove(value, meta, file, line) {
641
+ const fail = (option, at = line) => {
642
+ throw new DeckError(`invalid magic-move ${option}`, file, {
643
+ line: at,
644
+ column: 1
645
+ });
646
+ };
647
+ const object = (text, outer, at) => {
648
+ const result = {};
649
+ if (!text.trim()) return result;
650
+ if (!/^\{[^{}]*\}$/.test(text.trim())) return fail(`options ${text}`, at);
651
+ const entries = text.trim().slice(1, -1).split(",");
652
+ if (!entries.at(-1)?.trim()) entries.pop();
653
+ for (const entry of entries) {
654
+ const match = /^\s*(at|lines)\s*:\s*(\d+|true|false)\s*$/.exec(entry);
655
+ const key = match?.[1];
656
+ const value = match?.[2];
657
+ if (!key || !value || key in result) return fail(`option ${entry}`, at);
658
+ if (key === "lines" && (value === "true" || value === "false")) result.lines = value === "true";
659
+ else if (key === "at" && outer && /^\d+$/.test(value) && Number.isSafeInteger(Number(value))) result.at = Number(value);
660
+ else return fail(`option ${entry}`, at);
661
+ }
662
+ return result;
663
+ };
664
+ const header = /^magic-move\s*(?:"([^"]*)"|'([^']*)'|\[([^\]]*)\])?\s*(.*)$/.exec(meta);
665
+ if (!header) return fail(`header ${meta}`);
666
+ const options = object(header[4] ?? "", true, line);
667
+ const steps = parser$2.parse(value).children.flatMap((node) => {
668
+ if (node.type !== "code") return [];
669
+ const at = line + (node.position?.start.line ?? 1);
670
+ const start = value.slice(node.position?.start.offset ?? 0);
671
+ if (!/^(`{3,}|~{3,})/.test(start)) return [];
672
+ const inner = node.meta ?? "";
673
+ const ranges = /^\s*(\{[^}:]*\})(?:\s|$)/.exec(inner);
674
+ let parsed;
675
+ try {
676
+ parsed = parseCodeOptions(ranges?.[1] ?? "", node.value.split("\n").length, file);
677
+ } catch (cause) {
678
+ if (cause instanceof DeckError) return fail(`range ${ranges?.[1]}`, at);
679
+ throw cause;
680
+ }
681
+ const stepOptions = object(inner.slice(ranges?.[0].length ?? 0), false, at);
682
+ return [{
683
+ code: node.value,
684
+ lang: node.lang ?? "text",
685
+ ranges: parsed.steps ?? [],
686
+ lines: stepOptions.lines ?? options.lines ?? false
687
+ }];
688
+ });
689
+ if (!steps.length) return fail("fence: expected an inner code fence");
690
+ return {
691
+ at: options.at ?? 0,
692
+ title: header[1] ?? header[2] ?? header[3],
693
+ steps
694
+ };
695
+ }
696
+ async function compileMagicMoves(tree, file) {
697
+ const walk = async (parent) => {
698
+ for (const [index, node] of parent.children.entries()) {
699
+ if (node.type !== "element") {
700
+ if ("children" in node) await walk(node);
701
+ continue;
702
+ }
703
+ const code = node.tagName === "pre" ? node.children[0] : void 0;
704
+ const classes = code?.type === "element" ? code.properties.className : void 0;
705
+ const meta = code?.type === "element" ? code.data?.meta : void 0;
706
+ if (code?.type === "element" && Array.isArray(classes) && classes.some((name) => typeof name === "string" && /^language-(?:md|markdown)$/.test(name)) && typeof meta === "string" && isMagicMove("md", meta)) {
707
+ const line = node.position?.start.line ?? 1;
708
+ const source = String(file.value).slice(node.position?.start.offset ?? 0);
709
+ if (!/^`{4,}/.test(source)) throw new DeckError("magic-move needs four or more backticks", file.path, {
710
+ line,
711
+ column: 1
712
+ });
713
+ const parsed = parseMagicMove(code.children.map((child) => child.type === "text" ? child.value : "").join("").replace(/\n$/, ""), meta, file.path, line);
714
+ const theme = createCssVariablesTheme();
715
+ const highlighter = await getSingletonHighlighter({
716
+ themes: [theme],
717
+ langs: Object.keys(bundledLanguages)
718
+ });
719
+ const steps = parsed.steps.map((step) => {
720
+ const lang = isBundledLanguage(step.lang) || isSpecialLang(step.lang) ? step.lang : "text";
721
+ if (lang !== step.lang) console.warn(`${file.path}: unknown code language ${step.lang}; using plain text`);
722
+ return codeToKeyedTokens(highlighter, step.code, {
723
+ lang,
724
+ theme
725
+ }, step.lines);
726
+ });
727
+ parent.children[index] = {
728
+ type: "mdxJsxFlowElement",
729
+ name: "MagicMove",
730
+ attributes: Object.entries({
731
+ steps: JSON.stringify(steps),
732
+ at: String(parsed.at),
733
+ ranges: JSON.stringify(parsed.steps.map((step) => step.ranges)),
734
+ ...parsed.title === void 0 ? {} : { title: parsed.title }
735
+ }).map(([name, value]) => ({
736
+ type: "mdxJsxAttribute",
737
+ name,
738
+ value
739
+ })),
740
+ children: []
741
+ };
742
+ } else await walk(node);
743
+ }
744
+ };
745
+ await walk(tree);
746
+ }
208
747
  // ../node/src/mdx/code-blocks.ts
209
748
  const codeBlocks = () => async (tree, file) => {
749
+ await compileMagicMoves(tree, file);
210
750
  const warn = (node) => {
211
751
  if (node.type === "element" && node.tagName === "code") {
212
752
  const classes = node.properties.className;
@@ -251,11 +791,15 @@ const provided = [
251
791
  "CountUp",
252
792
  "Draw",
253
793
  "Morph",
794
+ "Mark",
795
+ "MagicMove",
254
796
  "Center",
255
797
  "Cover",
256
798
  "Section",
257
799
  "TwoCol",
258
800
  "ImageSide",
801
+ "Toc",
802
+ "Link",
259
803
  "Notes"
260
804
  ];
261
805
  /** MDX's own tree keeps code fences out of the JSX name check. */
@@ -378,7 +922,8 @@ const stepNames = /* @__PURE__ */ new Set([
378
922
  "TextReveal",
379
923
  "Highlight",
380
924
  "CountUp",
381
- "Draw"
925
+ "Draw",
926
+ "Mark"
382
927
  ]);
383
928
  const parser = unified().use(remarkParse).use(remarkMdx);
384
929
  function elementChildren(node) {
@@ -446,6 +991,11 @@ function countClicks(source, file, previous = 0, motionNames = new Map(Array.fro
446
991
  const walk = (node) => {
447
992
  if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === "Notes") return;
448
993
  if (node.type === "code" && typeof node.value === "string") {
994
+ if (isMagicMove(node.lang, node.meta)) {
995
+ const move = parseMagicMove(node.value, node.meta ?? "", file, node.position?.start.line ?? 1);
996
+ total = Math.max(total, move.at + move.steps.reduce((sum, step) => sum + Math.max(1, step.ranges.length), 0) - 1);
997
+ return;
998
+ }
449
999
  const { steps, at } = parseCodeOptions(node.meta ?? "", node.value.split("\n").length, file);
450
1000
  if (steps) total = Math.max(total, at + steps.length - 1);
451
1001
  }
@@ -470,7 +1020,8 @@ function countClicks(source, file, previous = 0, motionNames = new Map(Array.fro
470
1020
  "Step",
471
1021
  "Stagger",
472
1022
  "Highlight",
473
- "Draw"
1023
+ "Draw",
1024
+ "Mark"
474
1025
  ].includes(motion) ? integerAttribute(node, "until", file) : void 0;
475
1026
  if (until !== void 0 && until <= at) throw new DeckError(`<${node.name}> until must be greater than at. To compute it, set clicks: in the frontmatter.`, file, node.position?.start);
476
1027
  total = Math.max(total, until ?? at);
@@ -611,56 +1162,10 @@ function buildManifest(deck, slides) {
611
1162
  slides: slides.map(({ meta }) => meta)
612
1163
  });
613
1164
  }
614
- // ../node/src/dev/config.ts
615
- function defineDeck(config) {
616
- return config;
617
- }
618
- const schema = z.strictObject({
619
- title: z.string(),
620
- author: z.string().optional(),
621
- info: z.string().optional(),
622
- url: z.url().optional(),
623
- canvas: z.strictObject({
624
- width: z.number().positive(),
625
- height: z.number().positive()
626
- }).default({
627
- width: 1920,
628
- height: 1080
629
- }),
630
- transition: z.string().min(1).optional(),
631
- htmlAttrs: z.record(z.string(), z.string()).optional(),
632
- credit: z.boolean().default(true),
633
- vite: z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value)).optional(),
634
- mdx: z.strictObject({
635
- remarkPlugins: z.custom(Array.isArray, "mdx.remarkPlugins must be an array").optional(),
636
- rehypePlugins: z.custom(Array.isArray, "mdx.rehypePlugins must be an array").optional()
637
- }).optional()
638
- });
639
- async function loadDeck(dir, name) {
640
- const absolute = resolve(dir);
641
- const file = resolve(absolute, "deck.config.ts");
642
- if (!existsSync(file)) throw new DeckError(`no deck.config.ts in ${displayPath(absolute)}. A deck directory holds deck.config.ts and slides/.`, file, void 0, { prefix: false });
643
- const module = await createJiti(import.meta.url, {
644
- moduleCache: false,
645
- fsCache: false
646
- }).import(file).catch((cause) => {
647
- throw new DeckError(`cannot load config: ${cause instanceof Error ? cause.message : String(cause)}`, file, void 0, { cause });
648
- });
649
- if (!Object.hasOwn(module, "default")) throw new DeckError(`${displayPath(file)} has no default export. Write: export default defineDeck({ title: "..." })`, file, void 0, { prefix: false });
650
- const parsed = schema.safeParse(module.default);
651
- if (!parsed.success) throw validationError(file, parsed.error.issues, module.default, Object.keys(schema.shape));
652
- const config = parsed.data;
653
- for (const key of Object.keys(config.htmlAttrs ?? {})) if (!/^[A-Za-z_:][-A-Za-z0-9_:.]*$/.test(key)) throw new DeckError(`htmlAttrs key ${key} is not a valid HTML attribute name.`, file);
654
- return {
655
- name: name ?? basename(absolute),
656
- dir: absolute,
657
- config
658
- };
659
- }
660
1165
  // ../node/src/dev/entry.ts
661
1166
  function entryModule(deck) {
662
- return `${existsSync(join(deck.dir, "setup.ts")) ? "import \"/setup.ts\";\n" : ""}import { mountDeck, Center, Cover, Section, TwoCol, ImageSide } from "${PUBLIC_SPECIFIERS.runtime}";
663
- import { Step, Steps, Stagger, TextReveal, Highlight, CountUp, Draw, Morph, CodeBlock } from "${PUBLIC_SPECIFIERS.motion}";
1167
+ return `${existsSync(join(deck.dir, "setup.ts")) ? "import \"/setup.ts\";\n" : ""}import { mountDeck, Center, Cover, Section, TwoCol, ImageSide, Toc, Link } from "${PUBLIC_SPECIFIERS.runtime}";
1168
+ import { Step, Steps, Stagger, TextReveal, Highlight, CountUp, Draw, Morph, CodeBlock, Mark, MagicMove } from "${PUBLIC_SPECIFIERS.motion}";
664
1169
  ${existsSync(join(deck.dir, "styles/index.css")) ? "import \"/styles/index.css\";" : ""}
665
1170
  Promise.all([
666
1171
  import("virtual:react-decks/manifest"),
@@ -668,7 +1173,7 @@ Promise.all([
668
1173
  import("virtual:react-decks/layers")
669
1174
  ]).then(([{ manifest, slides, frontmatter }, { components }, { layers }]) => {
670
1175
  mountDeck({ manifest, slides, frontmatter, layers,
671
- components: { Step, Steps, Stagger, TextReveal, Highlight, CountUp, Draw, Morph, pre: CodeBlock, Center, Cover, Section, TwoCol, ImageSide, ...components },
1176
+ components: { Step, Steps, Stagger, TextReveal, Highlight, CountUp, Draw, Morph, Mark, MagicMove, pre: CodeBlock, Center, Cover, Section, TwoCol, ImageSide, Toc, Link, ...components },
672
1177
  loadNotes: () => import("virtual:react-decks/notes").then(module => module.notes)
673
1178
  });
674
1179
  }).catch(error => {
@@ -727,7 +1232,7 @@ function errorReporting(base = createLogger(), deckDir = process.cwd()) {
727
1232
  if (Array.from(reported.values()).some((reported) => message.includes(reported))) return;
728
1233
  const origin = (diagnostic?.stack ?? message).split("\n").find((line) => /^\s+(at |>[ ])/.test(line)) ?? "";
729
1234
  const ownCode = sources.some((source) => origin.includes(source) || [" ", "("].some((prefix) => origin.includes(`${prefix}${normalizePath(relative(deckDir, source))}/`))) || diagnostic && "plugin" in diagnostic && typeof diagnostic.plugin === "string" && diagnostic.plugin.startsWith("react-decks");
730
- logError(ownCode ? `${message}\nThis is a bug in react-decks.` : message, options);
1235
+ logError(ownCode ? `${message}\n${bugNotice}` : message, options);
731
1236
  }
732
1237
  };
733
1238
  return {
@@ -1178,6 +1683,7 @@ function config(deck, plugins = reactDecks(deck)) {
1178
1683
  async function dev(deck, options) {
1179
1684
  const port = options?.port ?? await getPort({ port: portNumbers(3030, 65535) });
1180
1685
  const lifecycle = createDeckPlugins(deck);
1686
+ if (options?.liveTerm) lifecycle.plugins.push(liveTerm(deck.dir));
1181
1687
  let server;
1182
1688
  try {
1183
1689
  server = await createServer({
@@ -1417,7 +1923,7 @@ const lint = defineCommand({
1417
1923
  throw new DeckError(cause instanceof Error ? cause.message : String(cause));
1418
1924
  }
1419
1925
  let hits;
1420
- const { scanSource, formatHit } = await import("./prose-scan-BrWZ7gxZ.js");
1926
+ const { scanSource, formatHit } = await import("./prose-scan-ni8g6pc-.js");
1421
1927
  let patterns;
1422
1928
  try {
1423
1929
  patterns = loadPatterns();
@@ -1453,7 +1959,7 @@ const lint = defineCommand({
1453
1959
  });
1454
1960
  async function lintDecks(decks, options) {
1455
1961
  const patterns = loadPatterns();
1456
- const { scanSource } = await import("./prose-scan-BrWZ7gxZ.js");
1962
+ const { scanSource } = await import("./prose-scan-ni8g6pc-.js");
1457
1963
  const files = /* @__PURE__ */ new Map();
1458
1964
  for (const deck of decks) {
1459
1965
  const resolved = await loadDeck(deck.dir, deck.alias);
@@ -1822,7 +2328,7 @@ async function lintPayload(payload, project) {
1822
2328
  const deckDir = inScope(call.file, project);
1823
2329
  if (!deckDir || call.toolName === "Write" && !call.content) continue;
1824
2330
  const deck = await loadDeck(deckDir);
1825
- const { scanSource, formatHit } = await import("./prose-scan-BrWZ7gxZ.js");
2331
+ const { scanSource, formatHit } = await import("./prose-scan-ni8g6pc-.js");
1826
2332
  patterns ??= loadPatterns();
1827
2333
  const absolute = resolve(project, call.file);
1828
2334
  const after = replay(call, resolve(project, call.source ?? call.file));
@@ -2336,6 +2842,11 @@ const commands = {
2336
2842
  type: "boolean",
2337
2843
  default: false,
2338
2844
  description: "Open the deck in a browser"
2845
+ },
2846
+ "live-term": {
2847
+ type: "boolean",
2848
+ default: false,
2849
+ description: "Enable live terminal panes"
2339
2850
  }
2340
2851
  },
2341
2852
  async run({ args }) {
@@ -2343,7 +2854,8 @@ const commands = {
2343
2854
  if (args.port !== void 0 && (!/^\d+$/.test(args.port) || Number(args.port) > 65535)) throw new DeckError(`Invalid --port "${args.port}". Use a whole number from 0 to 65535.`);
2344
2855
  const server = await dev(deck, {
2345
2856
  port: args.port === void 0 ? void 0 : Number(args.port),
2346
- open: args.open
2857
+ open: args.open,
2858
+ liveTerm: args["live-term"]
2347
2859
  });
2348
2860
  console.log(pc.green(server.url));
2349
2861
  }
@@ -2412,6 +2924,7 @@ async function argumentError(command, cause) {
2412
2924
  async function runCli(rawArgs = process.argv.slice(2)) {
2413
2925
  const command = rawArgs[0];
2414
2926
  try {
2927
+ if (command !== "dev" && rawArgs.slice(1).some((arg) => /^--(?:no-)?live-term(?:=|$)/.test(arg))) throw new DeckError("--live-term is only available on decks dev.");
2415
2928
  if (command !== void 0 && Object.hasOwn(tools, command)) try {
2416
2929
  await runCommand(main, { rawArgs });
2417
2930
  } catch (cause) {
@@ -2432,7 +2945,8 @@ async function runCli(rawArgs = process.argv.slice(2)) {
2432
2945
  base: { type: "string" }
2433
2946
  } : {
2434
2947
  port: { type: "string" },
2435
- open: { type: "boolean" }
2948
+ open: { type: "boolean" },
2949
+ "live-term": { type: "boolean" }
2436
2950
  };
2437
2951
  try {
2438
2952
  const { positionals } = parseArgs({
@@ -2466,4 +2980,4 @@ async function runCli(rawArgs = process.argv.slice(2)) {
2466
2980
  process.exitCode = 1;
2467
2981
  }
2468
2982
  }
2469
- export { defineDeck as a, scanSlides as c, reactDecks as i, build as n, loadDeck as o, dev as r, buildManifest as s, runCli as t };
2983
+ export { buildManifest as a, loadDeck as c, reactDecks as i, build as n, scanSlides as o, dev as r, defineDeck as s, runCli as t };