@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.
- package/dist/cli.js +1 -1
- package/dist/control-tray.css +80 -0
- package/dist/go-to-dialog.css +57 -0
- package/dist/{index-BURtH7IB.d.ts → index-D3Yj4yT6.d.ts} +11 -2
- package/dist/{index-BV_-6L5L.d.ts → index-DG8UcGQd.d.ts} +77 -1
- package/dist/{index-B2n69xrC.d.ts → index-zg-z6HTy.d.ts} +18 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/kit/term/live-term.module.css +36 -0
- package/dist/kit.d.ts +21 -6
- package/dist/kit.js +252 -8
- package/dist/live-term.module.css +36 -0
- package/dist/magic-move.css +30 -0
- package/dist/mark.css +34 -0
- package/dist/motion.d.ts +2 -2
- package/dist/motion.js +1 -1
- package/dist/node.d.ts +5 -1
- package/dist/node.js +1 -1
- package/dist/plugin/skills/building-a-deck/references/workflow.md +10 -0
- package/dist/plugin/skills/deck-design/references/layout.md +2 -0
- package/dist/plugin/skills/deck-motion/references/motion.md +38 -1
- package/dist/plugin/skills/working-with-decks/references/project.md +4 -0
- package/dist/{prose-patterns-DPqjGBFu.js → prose-patterns-D-tdt0Ab.js} +3 -1
- package/dist/{prose-scan-BrWZ7gxZ.js → prose-scan-ni8g6pc-.js} +2 -2
- package/dist/{src-DizFoqYt.js → src-BHlxNl0Z.js} +347 -42
- package/dist/{src-CmQgaG1b.js → src-BxuWgcUh.js} +581 -67
- package/dist/{src-C-OfT72W.js → src-CDNWEWZz.js} +212 -3
- package/dist/term/shell_pty.py +38 -0
- package/dist/term/zsh/.zshrc +4 -0
- package/dist/term-protocol-B_qHRDEp.js +11 -0
- package/dist/xterm-host-C6OjffSm.js +282 -0
- package/docs/README.md +1 -0
- package/docs/cli.md +1 -1
- package/docs/code-blocks.md +31 -0
- package/docs/config.md +1 -0
- package/docs/getting-started.md +2 -1
- package/docs/kit.md +7 -6
- package/docs/migrating-from-slidev.md +4 -0
- package/docs/motion.md +25 -1
- package/docs/presenting.md +16 -1
- package/docs/slides.md +20 -1
- package/docs/terminal.md +97 -0
- package/package.json +4 -1
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Children, cloneElement, isValidElement, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
1
|
+
import { C as stepState, S as useSlideScale, v as registerSettleProbe, x as useSlide } from "./src-BHlxNl0Z.js";
|
|
2
|
+
import { Children, cloneElement, isValidElement, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { flushSync } from "react-dom";
|
|
5
5
|
import "./motion.css";
|
|
6
6
|
import { gsap, gsap as gsap$1 } from "gsap";
|
|
7
7
|
import { CustomEase } from "gsap/CustomEase";
|
|
8
|
+
import { ShikiMagicMovePrecompiled } from "@shikijs/magic-move/react";
|
|
9
|
+
import "./magic-move.css";
|
|
10
|
+
import rough from "roughjs";
|
|
11
|
+
import "./mark.css";
|
|
8
12
|
// ../motion/src/settle.ts
|
|
9
13
|
let pending = 0;
|
|
10
14
|
function pendingTweenNotification(change) {
|
|
@@ -322,6 +326,211 @@ function CountUp({ at, from = 0, to, format = defaultFormat }) {
|
|
|
322
326
|
})]
|
|
323
327
|
});
|
|
324
328
|
}
|
|
329
|
+
// ../motion/src/magic-move.tsx
|
|
330
|
+
/** Compiled fence output; authors write a magic-move fence rather than this component. */
|
|
331
|
+
function MagicMove(props) {
|
|
332
|
+
const { clicks, isActive, renderContext } = useSlide();
|
|
333
|
+
const scale = useSlideScale();
|
|
334
|
+
const steps = useMemo(() => JSON.parse(props.steps), [props.steps]);
|
|
335
|
+
const ranges = useMemo(() => JSON.parse(props.ranges), [props.ranges]);
|
|
336
|
+
const at = Number(props.at);
|
|
337
|
+
let remaining = clicks - at;
|
|
338
|
+
let index = 0;
|
|
339
|
+
while (index < steps.length - 1 && remaining >= Math.max(1, ranges[index]?.length ?? 0)) {
|
|
340
|
+
remaining -= Math.max(1, ranges[index]?.length ?? 0);
|
|
341
|
+
index++;
|
|
342
|
+
}
|
|
343
|
+
const range = clicks < at ? void 0 : ranges[index]?.[Math.max(0, Math.min(remaining, (ranges[index]?.length ?? 0) - 1))];
|
|
344
|
+
const previous = useRef({
|
|
345
|
+
clicks,
|
|
346
|
+
index,
|
|
347
|
+
isActive
|
|
348
|
+
});
|
|
349
|
+
const primed = useRef(false);
|
|
350
|
+
const [rendered, setRendered] = useState({
|
|
351
|
+
index,
|
|
352
|
+
animate: false
|
|
353
|
+
});
|
|
354
|
+
const rendererSteps = useMemo(() => rendered.next === void 0 ? steps : steps.map((step) => ({ ...step })), [steps, rendered.next]);
|
|
355
|
+
const container = useRef(null);
|
|
356
|
+
const options = useMemo(() => ({
|
|
357
|
+
duration: rendered.next === void 0 ? duration.slow * 1e3 : 0,
|
|
358
|
+
globalScale: scale,
|
|
359
|
+
animateContainer: false
|
|
360
|
+
}), [scale, rendered.next]);
|
|
361
|
+
useLayoutEffect(() => {
|
|
362
|
+
const animate = previous.current.clicks + 1 === clicks && previous.current.index + 1 === index && previous.current.isActive && isActive && renderContext === "slide" && motionMode() === "live";
|
|
363
|
+
const from = previous.current.index;
|
|
364
|
+
previous.current = {
|
|
365
|
+
clicks,
|
|
366
|
+
index,
|
|
367
|
+
isActive
|
|
368
|
+
};
|
|
369
|
+
if (animate && !primed.current) {
|
|
370
|
+
primed.current = true;
|
|
371
|
+
setRendered({
|
|
372
|
+
index: from,
|
|
373
|
+
animate: true,
|
|
374
|
+
next: index
|
|
375
|
+
});
|
|
376
|
+
} else setRendered((current) => current.index === index && current.animate === animate && current.next === void 0 ? current : {
|
|
377
|
+
index,
|
|
378
|
+
animate
|
|
379
|
+
});
|
|
380
|
+
}, [
|
|
381
|
+
clicks,
|
|
382
|
+
index,
|
|
383
|
+
isActive,
|
|
384
|
+
renderContext
|
|
385
|
+
]);
|
|
386
|
+
useEffect(() => {
|
|
387
|
+
const pre = container.current?.querySelector("pre");
|
|
388
|
+
if (!pre) return;
|
|
389
|
+
const mark = () => {
|
|
390
|
+
let line = 1;
|
|
391
|
+
for (const token of pre.children) {
|
|
392
|
+
if (!(token instanceof HTMLElement) || token.style.position === "absolute") continue;
|
|
393
|
+
if (token.tagName === "BR") {
|
|
394
|
+
line++;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
token.dataset.line = String(line);
|
|
398
|
+
if (range === void 0) delete token.dataset.lineState;
|
|
399
|
+
else token.dataset.lineState = range === "all" || Array.isArray(range) && range.includes(line) ? "active" : "dim";
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
mark();
|
|
403
|
+
const observer = new MutationObserver(mark);
|
|
404
|
+
observer.observe(pre, { childList: true });
|
|
405
|
+
return () => observer.disconnect();
|
|
406
|
+
}, [range]);
|
|
407
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
408
|
+
className: "rd-code rd-magic-move",
|
|
409
|
+
ref: container,
|
|
410
|
+
children: [props.title !== void 0 && /* @__PURE__ */ jsx("figcaption", { children: props.title }), /* @__PURE__ */ jsx(ShikiMagicMovePrecompiled, {
|
|
411
|
+
steps: rendererSteps,
|
|
412
|
+
step: rendered.index,
|
|
413
|
+
animate: rendered.animate,
|
|
414
|
+
options,
|
|
415
|
+
onEnd: () => setRendered((current) => current.next === void 0 ? current : {
|
|
416
|
+
index: current.next,
|
|
417
|
+
animate: true
|
|
418
|
+
})
|
|
419
|
+
})]
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
// ../motion/src/mark.tsx
|
|
423
|
+
const kinds = /* @__PURE__ */ new Set([
|
|
424
|
+
"underline",
|
|
425
|
+
"circle",
|
|
426
|
+
"box",
|
|
427
|
+
"strike",
|
|
428
|
+
"cross",
|
|
429
|
+
"bracket"
|
|
430
|
+
]);
|
|
431
|
+
/** A hand-drawn mark around its children, drawn on a click (architecture section 5.3). */
|
|
432
|
+
function Mark({ kind = "underline", at, until, color = "currentColor", children }) {
|
|
433
|
+
const state = useStepState(at, until);
|
|
434
|
+
const ref = useRef(null);
|
|
435
|
+
const [{ width, height }, setSize] = useState({
|
|
436
|
+
width: 0,
|
|
437
|
+
height: 0
|
|
438
|
+
});
|
|
439
|
+
useLayoutEffect(() => {
|
|
440
|
+
const root = ref.current;
|
|
441
|
+
if (!root) return;
|
|
442
|
+
const measure = () => {
|
|
443
|
+
const width = root.offsetWidth;
|
|
444
|
+
const height = root.offsetHeight;
|
|
445
|
+
setSize((previous) => previous.width === width && previous.height === height ? previous : {
|
|
446
|
+
width,
|
|
447
|
+
height
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
measure();
|
|
451
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
452
|
+
const observer = new ResizeObserver(measure);
|
|
453
|
+
observer.observe(root);
|
|
454
|
+
return () => observer.disconnect();
|
|
455
|
+
}, []);
|
|
456
|
+
const outset = kind === "circle" || kind === "box" || kind === "bracket" ? height * .1 : 0;
|
|
457
|
+
const paths = useMemo(() => {
|
|
458
|
+
if (!kinds.has(kind)) throw new Error(`Unknown Mark kind "${kind}"`);
|
|
459
|
+
if (!width || !height) return [];
|
|
460
|
+
const generator = rough.generator({ options: {
|
|
461
|
+
seed: 53,
|
|
462
|
+
roughness: .7,
|
|
463
|
+
bowing: 1
|
|
464
|
+
} });
|
|
465
|
+
let shapes;
|
|
466
|
+
switch (kind) {
|
|
467
|
+
case "underline":
|
|
468
|
+
shapes = { stroke: generator.line(0, height * .95, width, height * .95) };
|
|
469
|
+
break;
|
|
470
|
+
case "circle":
|
|
471
|
+
shapes = { stroke: generator.ellipse(width / 2, height / 2, width + outset * 2, height + outset * 2) };
|
|
472
|
+
break;
|
|
473
|
+
case "box":
|
|
474
|
+
shapes = { stroke: generator.rectangle(-outset, -outset, width + outset * 2, height + outset * 2) };
|
|
475
|
+
break;
|
|
476
|
+
case "strike":
|
|
477
|
+
shapes = { stroke: generator.line(0, height / 2, width, height / 2) };
|
|
478
|
+
break;
|
|
479
|
+
case "cross":
|
|
480
|
+
shapes = {
|
|
481
|
+
descending: generator.line(0, 0, width, height),
|
|
482
|
+
ascending: generator.line(0, height, width, 0)
|
|
483
|
+
};
|
|
484
|
+
break;
|
|
485
|
+
case "bracket": shapes = {
|
|
486
|
+
left: generator.linearPath([
|
|
487
|
+
[0, -outset],
|
|
488
|
+
[-outset, -outset],
|
|
489
|
+
[-outset, height + outset],
|
|
490
|
+
[0, height + outset]
|
|
491
|
+
]),
|
|
492
|
+
right: generator.linearPath([
|
|
493
|
+
[width, -outset],
|
|
494
|
+
[width + outset, -outset],
|
|
495
|
+
[width + outset, height + outset],
|
|
496
|
+
[width, height + outset]
|
|
497
|
+
])
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
return Object.entries(shapes).map(([id, shape]) => ({
|
|
501
|
+
id,
|
|
502
|
+
d: generator.toPaths(shape).map(({ d }) => d).join(" ")
|
|
503
|
+
}));
|
|
504
|
+
}, [
|
|
505
|
+
kind,
|
|
506
|
+
width,
|
|
507
|
+
height,
|
|
508
|
+
outset
|
|
509
|
+
]);
|
|
510
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
511
|
+
ref,
|
|
512
|
+
className: "rd-mark",
|
|
513
|
+
"data-step-state": state,
|
|
514
|
+
"data-step-enter": "fade",
|
|
515
|
+
"data-step-exit": "fade",
|
|
516
|
+
children: [children, width > 0 && height > 0 && /* @__PURE__ */ jsx("svg", {
|
|
517
|
+
"aria-hidden": "true",
|
|
518
|
+
viewBox: `${-outset} ${-outset} ${width + outset * 2} ${height + outset * 2}`,
|
|
519
|
+
style: {
|
|
520
|
+
left: -outset,
|
|
521
|
+
top: -outset,
|
|
522
|
+
width: width + outset * 2,
|
|
523
|
+
height: height + outset * 2
|
|
524
|
+
},
|
|
525
|
+
children: paths.map(({ id, d }) => /* @__PURE__ */ jsx("path", {
|
|
526
|
+
d,
|
|
527
|
+
pathLength: "1",
|
|
528
|
+
fill: "none",
|
|
529
|
+
stroke: color
|
|
530
|
+
}, `${kind}:${id}`))
|
|
531
|
+
})]
|
|
532
|
+
});
|
|
533
|
+
}
|
|
325
534
|
// ../motion/src/morph.tsx
|
|
326
535
|
function Morph({ name, as: Element = "div", className, children }) {
|
|
327
536
|
const { isActive, renderContext } = useSlide();
|
|
@@ -393,4 +602,4 @@ function useTimeline(build, deps = []) {
|
|
|
393
602
|
...deps
|
|
394
603
|
]);
|
|
395
604
|
}
|
|
396
|
-
export {
|
|
605
|
+
export { TextReveal as _, CountUp as a, ease as c, stagger as d, Draw as f, Steps as g, Step as h, MagicMove as i, gsap as l, Stagger as m, Morph as n, useTween as o, Highlight as p, Mark as r, duration as s, useTimeline as t, motionMode as u, useStepState as v, CodeBlock as y };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Run a command on a pseudo-terminal of a set size, relaying stdin and stdout over pipes.
|
|
2
|
+
|
|
3
|
+
usage: shell_pty.py ROWS COLS COMMAND [ARG...]
|
|
4
|
+
The dev-server terminal plugin spawns this, because Node has no pty of its own and macOS
|
|
5
|
+
script(1) refuses a piped stdin. When stdin closes, the terminal is hung up, so the command
|
|
6
|
+
does not outlive the dev server. Exits with the command's exit status.
|
|
7
|
+
"""
|
|
8
|
+
import fcntl
|
|
9
|
+
import os
|
|
10
|
+
import pty
|
|
11
|
+
import select
|
|
12
|
+
import struct
|
|
13
|
+
import sys
|
|
14
|
+
import termios
|
|
15
|
+
|
|
16
|
+
rows, cols = int(sys.argv[1]), int(sys.argv[2])
|
|
17
|
+
pid, fd = pty.fork()
|
|
18
|
+
if pid == 0:
|
|
19
|
+
os.execvp(sys.argv[3], sys.argv[3:])
|
|
20
|
+
fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", rows, cols, 0, 0))
|
|
21
|
+
while True:
|
|
22
|
+
readable, _, _ = select.select([fd, 0], [], [])
|
|
23
|
+
try:
|
|
24
|
+
if fd in readable:
|
|
25
|
+
data = os.read(fd, 65536)
|
|
26
|
+
if not data:
|
|
27
|
+
break
|
|
28
|
+
os.write(1, data)
|
|
29
|
+
if 0 in readable:
|
|
30
|
+
data = os.read(0, 65536)
|
|
31
|
+
if not data:
|
|
32
|
+
break
|
|
33
|
+
os.write(fd, data)
|
|
34
|
+
except OSError:
|
|
35
|
+
break
|
|
36
|
+
os.close(fd)
|
|
37
|
+
_, status = os.waitpid(pid, 0)
|
|
38
|
+
sys.exit(os.waitstatus_to_exitcode(status) if os.WIFEXITED(status) else 1)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// ../core/src/term-protocol.ts
|
|
2
|
+
/** Browser to server. */
|
|
3
|
+
const TERM_ATTACH = "deck-term:attach";
|
|
4
|
+
const TERM_POSITION = "deck-term:position";
|
|
5
|
+
const TERM_INPUT = "deck-term:input";
|
|
6
|
+
/** Server to browser. */
|
|
7
|
+
const TERM_READY = "deck-term:ready";
|
|
8
|
+
const TERM_DATA = "deck-term:data";
|
|
9
|
+
const TERM_STATE = "deck-term:state";
|
|
10
|
+
const TERM_GONE = "deck-term:gone";
|
|
11
|
+
export { TERM_POSITION as a, TERM_INPUT as i, TERM_DATA as n, TERM_READY as o, TERM_GONE as r, TERM_STATE as s, TERM_ATTACH as t };
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import styles from "./live-term.module.css";
|
|
4
|
+
import { Terminal } from "@xterm/xterm";
|
|
5
|
+
import "@xterm/xterm/css/xterm.css";
|
|
6
|
+
// ../kit/src/term/output-pacer.ts
|
|
7
|
+
/** Pace bursts without delaying keystrokes, short replies or session replays. */
|
|
8
|
+
function createOutputPacer(write) {
|
|
9
|
+
let pending = "";
|
|
10
|
+
let deadline = 0;
|
|
11
|
+
let recentLines = 0;
|
|
12
|
+
let windowStarted = 0;
|
|
13
|
+
let timer;
|
|
14
|
+
const interval = 1e3 / 30;
|
|
15
|
+
const clear = () => {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
timer = void 0;
|
|
18
|
+
pending = "";
|
|
19
|
+
recentLines = 0;
|
|
20
|
+
windowStarted = Date.now();
|
|
21
|
+
};
|
|
22
|
+
const flush = () => {
|
|
23
|
+
const chunk = pending;
|
|
24
|
+
clear();
|
|
25
|
+
if (chunk) write(chunk, false);
|
|
26
|
+
};
|
|
27
|
+
const drain = () => {
|
|
28
|
+
timer = void 0;
|
|
29
|
+
const lines = pending.split("\n");
|
|
30
|
+
const ticks = Math.max(1, Math.floor((deadline - Date.now()) / interval));
|
|
31
|
+
const count = Math.max(1, Math.ceil(lines.length / ticks));
|
|
32
|
+
write(lines.splice(0, count).join("\n") + (lines.length ? "\n" : ""), false);
|
|
33
|
+
pending = lines.join("\n");
|
|
34
|
+
if (pending) timer = setTimeout(drain, interval);
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
push(chunk, replay = false, immediate = false) {
|
|
38
|
+
if (replay) {
|
|
39
|
+
clear();
|
|
40
|
+
write(chunk, true);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (immediate) {
|
|
44
|
+
flush();
|
|
45
|
+
write(chunk, false);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (Date.now() - windowStarted >= interval) {
|
|
49
|
+
windowStarted = Date.now();
|
|
50
|
+
recentLines = 0;
|
|
51
|
+
}
|
|
52
|
+
const lines = chunk.split("\n").length - 1;
|
|
53
|
+
if (timer === void 0 && recentLines + lines <= 3) {
|
|
54
|
+
recentLines += lines;
|
|
55
|
+
write(chunk, false);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
pending += chunk;
|
|
59
|
+
if (timer === void 0) {
|
|
60
|
+
deadline = Date.now() + 1500;
|
|
61
|
+
timer = setTimeout(drain, interval);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
flush,
|
|
65
|
+
dispose: clear
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// ../kit/src/term/terminal-face.ts
|
|
69
|
+
/** Fit xterm's measured grid at a whole device-pixel advance, without scaling it. */
|
|
70
|
+
function terminalFace(terminal, fontFamily, width, height, devicePixelRatio) {
|
|
71
|
+
const ruler = document.createElement("canvas").getContext("2d");
|
|
72
|
+
if (!ruler) throw new Error("no 2d canvas to measure the terminal font");
|
|
73
|
+
ruler.font = `1000px ${fontFamily}`;
|
|
74
|
+
const advance = ruler.measureText("W").width / 1e3;
|
|
75
|
+
const screen = terminal.element?.querySelector(".xterm-screen");
|
|
76
|
+
if (!screen) throw new Error("no xterm screen to measure");
|
|
77
|
+
const scrollbar = 6;
|
|
78
|
+
let cell = Math.floor((width - scrollbar) * devicePixelRatio / terminal.cols);
|
|
79
|
+
for (; cell >= 1; cell--) {
|
|
80
|
+
terminal.options.fontSize = cell / (advance * devicePixelRatio);
|
|
81
|
+
const gridWidth = screen.offsetWidth;
|
|
82
|
+
const gridHeight = screen.offsetHeight;
|
|
83
|
+
if (Number.isInteger(gridWidth * devicePixelRatio / terminal.cols) && gridWidth + scrollbar <= width && gridHeight <= height) return {
|
|
84
|
+
gridWidth,
|
|
85
|
+
gridHeight,
|
|
86
|
+
rowHeight: gridHeight / terminal.rows,
|
|
87
|
+
scrollbar,
|
|
88
|
+
left: (width - gridWidth - scrollbar) / 2,
|
|
89
|
+
top: (height - gridHeight) / 2
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
throw new Error(`terminal grid ${terminal.cols} by ${terminal.rows} cannot fit ${width} by ${height}`);
|
|
93
|
+
}
|
|
94
|
+
// ../kit/src/term/xterm-host.tsx
|
|
95
|
+
function XtermHost({ connection, rows, cols, scale, onReady }) {
|
|
96
|
+
const host = useRef(null);
|
|
97
|
+
useLayoutEffect(() => {
|
|
98
|
+
const target = host.current;
|
|
99
|
+
if (!target || scale <= 0) return;
|
|
100
|
+
let term;
|
|
101
|
+
let unsubscribe;
|
|
102
|
+
let cleanupOutput;
|
|
103
|
+
let cleanupWheel;
|
|
104
|
+
let cleanupFit;
|
|
105
|
+
let disposed = false;
|
|
106
|
+
const css = getComputedStyle(target.parentElement ?? target);
|
|
107
|
+
const fontFamily = css.fontFamily;
|
|
108
|
+
const fontSize = Number.parseFloat(css.fontSize);
|
|
109
|
+
const foreground = css.color;
|
|
110
|
+
const color = (name) => css.getPropertyValue(`--deck-term-${name}`).trim() || foreground;
|
|
111
|
+
const colors = {
|
|
112
|
+
foreground,
|
|
113
|
+
background: css.backgroundColor,
|
|
114
|
+
cursor: color("cursor"),
|
|
115
|
+
selectionBackground: color("selection"),
|
|
116
|
+
black: color("black"),
|
|
117
|
+
red: color("red"),
|
|
118
|
+
green: color("green"),
|
|
119
|
+
yellow: color("yellow"),
|
|
120
|
+
blue: color("blue"),
|
|
121
|
+
magenta: color("magenta"),
|
|
122
|
+
cyan: color("cyan"),
|
|
123
|
+
white: color("white"),
|
|
124
|
+
brightBlack: color("bright-black"),
|
|
125
|
+
brightRed: color("bright-red"),
|
|
126
|
+
brightGreen: color("bright-green"),
|
|
127
|
+
brightYellow: color("bright-yellow"),
|
|
128
|
+
brightBlue: color("bright-blue"),
|
|
129
|
+
brightMagenta: color("bright-magenta"),
|
|
130
|
+
brightCyan: color("bright-cyan"),
|
|
131
|
+
brightWhite: color("bright-white")
|
|
132
|
+
};
|
|
133
|
+
Promise.all([document.fonts.load(`${fontSize}px ${fontFamily}`), document.fonts.ready]).then(() => {
|
|
134
|
+
if (disposed) return;
|
|
135
|
+
try {
|
|
136
|
+
const frame = target.parentElement;
|
|
137
|
+
if (!frame) throw new Error("no terminal frame to measure");
|
|
138
|
+
term = new Terminal({
|
|
139
|
+
rows,
|
|
140
|
+
cols,
|
|
141
|
+
fontFamily,
|
|
142
|
+
fontSize: fontSize * scale,
|
|
143
|
+
letterSpacing: 0,
|
|
144
|
+
lineHeight: 1.12,
|
|
145
|
+
theme: colors,
|
|
146
|
+
allowTransparency: true,
|
|
147
|
+
drawBoldTextInBrightColors: false,
|
|
148
|
+
cursorBlink: false,
|
|
149
|
+
scrollback: 2e3,
|
|
150
|
+
overviewRuler: {
|
|
151
|
+
width: 6,
|
|
152
|
+
showTopBorder: false,
|
|
153
|
+
showBottomBorder: false
|
|
154
|
+
},
|
|
155
|
+
logLevel: "off"
|
|
156
|
+
});
|
|
157
|
+
term.attachCustomKeyEventHandler((event) => {
|
|
158
|
+
if (event.key !== "Escape") return true;
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
event.stopPropagation();
|
|
161
|
+
term?.blur();
|
|
162
|
+
return false;
|
|
163
|
+
});
|
|
164
|
+
term.open(target);
|
|
165
|
+
const terminal = term;
|
|
166
|
+
const fit = () => {
|
|
167
|
+
const bounds = frame.getBoundingClientRect();
|
|
168
|
+
const face = terminalFace(terminal, fontFamily, bounds.width, bounds.height, window.devicePixelRatio);
|
|
169
|
+
target.style.width = `${face.gridWidth + face.scrollbar}px`;
|
|
170
|
+
target.style.height = `${face.gridHeight}px`;
|
|
171
|
+
target.style.marginLeft = `${face.left / scale}px`;
|
|
172
|
+
target.style.marginTop = `${face.top / scale}px`;
|
|
173
|
+
target.style.transform = `scale(${1 / scale})`;
|
|
174
|
+
return face;
|
|
175
|
+
};
|
|
176
|
+
let face = fit();
|
|
177
|
+
const refit = () => {
|
|
178
|
+
if (disposed) return;
|
|
179
|
+
try {
|
|
180
|
+
face = fit();
|
|
181
|
+
} catch (error) {
|
|
182
|
+
connection.unavailable(`terminal could not fit: ${error instanceof Error ? error.message : String(error)}`);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const observer = new ResizeObserver(refit);
|
|
186
|
+
observer.observe(frame);
|
|
187
|
+
let resolution = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
|
|
188
|
+
const changedDpr = () => {
|
|
189
|
+
if (disposed) return;
|
|
190
|
+
resolution.removeEventListener("change", changedDpr);
|
|
191
|
+
refit();
|
|
192
|
+
resolution = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
|
|
193
|
+
resolution.addEventListener("change", changedDpr);
|
|
194
|
+
};
|
|
195
|
+
resolution.addEventListener("change", changedDpr);
|
|
196
|
+
cleanupFit = () => {
|
|
197
|
+
observer.disconnect();
|
|
198
|
+
resolution.removeEventListener("change", changedDpr);
|
|
199
|
+
};
|
|
200
|
+
const rendered = terminal.onRender(() => {
|
|
201
|
+
if (disposed || !target.querySelector(".xterm-rows")?.textContent?.trim()) return;
|
|
202
|
+
onReady(true);
|
|
203
|
+
rendered.dispose();
|
|
204
|
+
});
|
|
205
|
+
let replays = 0;
|
|
206
|
+
const paced = createOutputPacer((chunk, replay) => {
|
|
207
|
+
if (replay) {
|
|
208
|
+
replays++;
|
|
209
|
+
terminal.options.disableStdin = true;
|
|
210
|
+
}
|
|
211
|
+
terminal.write(chunk, () => {
|
|
212
|
+
if (disposed) return;
|
|
213
|
+
if (replay) {
|
|
214
|
+
replays--;
|
|
215
|
+
terminal.options.disableStdin = replays > 0;
|
|
216
|
+
}
|
|
217
|
+
terminal.scrollToBottom();
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
term.onData((data) => {
|
|
221
|
+
paced.flush();
|
|
222
|
+
connection.input(data);
|
|
223
|
+
});
|
|
224
|
+
cleanupOutput = paced.dispose;
|
|
225
|
+
unsubscribe = connection.subscribeOutput(paced.push);
|
|
226
|
+
let remainder = 0;
|
|
227
|
+
const wheel = (event) => {
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
event.stopPropagation();
|
|
230
|
+
const lineHeight = face.rowHeight;
|
|
231
|
+
const pixels = event.deltaY * (event.deltaMode === 1 ? lineHeight : event.deltaMode === 2 ? rows * lineHeight : 1);
|
|
232
|
+
remainder += pixels / lineHeight;
|
|
233
|
+
const lines = Math.trunc(remainder);
|
|
234
|
+
remainder -= lines;
|
|
235
|
+
if (lines) terminal.scrollLines(lines);
|
|
236
|
+
};
|
|
237
|
+
frame.addEventListener("wheel", wheel, {
|
|
238
|
+
passive: false,
|
|
239
|
+
capture: true
|
|
240
|
+
});
|
|
241
|
+
cleanupWheel = () => frame.removeEventListener("wheel", wheel, true);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
connection.unavailable(`terminal could not open: ${error instanceof Error ? error.message : String(error)}`);
|
|
244
|
+
}
|
|
245
|
+
}).catch((error) => {
|
|
246
|
+
if (!disposed) connection.unavailable(`terminal font could not load: ${error instanceof Error ? error.message : String(error)}`);
|
|
247
|
+
});
|
|
248
|
+
return () => {
|
|
249
|
+
disposed = true;
|
|
250
|
+
onReady(false);
|
|
251
|
+
unsubscribe?.();
|
|
252
|
+
cleanupOutput?.();
|
|
253
|
+
cleanupWheel?.();
|
|
254
|
+
cleanupFit?.();
|
|
255
|
+
term?.dispose();
|
|
256
|
+
};
|
|
257
|
+
}, [
|
|
258
|
+
connection,
|
|
259
|
+
rows,
|
|
260
|
+
cols,
|
|
261
|
+
scale,
|
|
262
|
+
onReady
|
|
263
|
+
]);
|
|
264
|
+
return /* @__PURE__ */ jsx("div", {
|
|
265
|
+
className: styles.viewport,
|
|
266
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
267
|
+
ref: host,
|
|
268
|
+
className: styles.host,
|
|
269
|
+
role: "application",
|
|
270
|
+
"aria-label": "Live terminal",
|
|
271
|
+
onKeyDown: (event) => event.stopPropagation(),
|
|
272
|
+
onKeyUp: (event) => event.stopPropagation(),
|
|
273
|
+
style: {
|
|
274
|
+
fontVariantLigatures: "none",
|
|
275
|
+
width: `${scale * 100}%`,
|
|
276
|
+
height: `${scale * 100}%`,
|
|
277
|
+
transform: `scale(${1 / scale})`
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
export { XtermHost };
|
package/docs/README.md
CHANGED
|
@@ -15,6 +15,7 @@ Each page stands alone. Read the one that answers your question.
|
|
|
15
15
|
| [cli.md](cli.md) | What do `decks new`, `check`, `lint`, `hook`, `export`, `shot` and `init` do? |
|
|
16
16
|
| [migrating-from-slidev.md](migrating-from-slidev.md) | How do I move a deck from `slidev-addon-decks`? |
|
|
17
17
|
| [presenting.md](presenting.md) | Which keys do what, and how do the presenter window, overview, sync and text sizing behave? |
|
|
18
|
+
| [terminal.md](terminal.md) | How do I run real commands in a terminal pane on a slide, and what does the deck show when it can't? |
|
|
18
19
|
| [kit.md](kit.md) | What does `@steamfield/decks/kit` provide: theme, story stages, `OpenChart`, the `story` transition? |
|
|
19
20
|
|
|
20
21
|
## Not built yet
|
package/docs/cli.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# The decks command
|
|
2
2
|
|
|
3
|
-
`decks dev` and `decks build` are in [getting-started.md](getting-started.md). This page covers the rest. Every command that takes a deck accepts an alias from `decks.json` or a directory, and a bare name that is neither resolves under `_config.decksDir` (default `decks/`).
|
|
3
|
+
`decks dev` and `decks build` are in [getting-started.md](getting-started.md); `decks dev --live-term` is in [terminal.md](terminal.md). This page covers the rest. Every command that takes a deck accepts an alias from `decks.json` or a directory, and a bare name that is neither resolves under `_config.decksDir` (default `decks/`).
|
|
4
4
|
|
|
5
5
|
## `decks new <alias> [dir] [--story] [--author "Name"] [--url example.com]`
|
|
6
6
|
|
package/docs/code-blocks.md
CHANGED
|
@@ -71,6 +71,37 @@ At click 0 line 2 is emphasized, at click 1 lines 4 and 5, at click 2 every line
|
|
|
71
71
|
|
|
72
72
|
A block with `k` steps adds `at + k - 1` to the slide's click total, so the slide above has two clicks with no `clicks:` in its frontmatter. A block without braces uses no clicks. See [motion.md](motion.md) for how the total is counted.
|
|
73
73
|
|
|
74
|
+
## Magic move
|
|
75
|
+
|
|
76
|
+
A magic-move fence morphs one code block into the next on a click: tokens that stay move to their new place, removed ones fade out and new ones fade in. The syntax is Slidev's, so a Slidev fence pastes in unchanged. Open with four backticks, the language `md` (or `markdown`) and `magic-move`, then put ordinary code fences inside, one per version.
|
|
77
|
+
|
|
78
|
+
`examples/motion/slides/32-magic-move.mdx`:
|
|
79
|
+
|
|
80
|
+
`````mdx
|
|
81
|
+
````md magic-move "greet.ts" {lines: true}
|
|
82
|
+
```ts {1}
|
|
83
|
+
const greeting = "Hello";
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```ts {1|2}
|
|
87
|
+
const greet = (name: string) => `Hello, ${name}`;
|
|
88
|
+
greet("Ada");
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```ts {all}
|
|
92
|
+
export function greet(name: string) {
|
|
93
|
+
return `Hello, ${name}!`;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
````
|
|
97
|
+
`````
|
|
98
|
+
|
|
99
|
+
After `magic-move` come an optional title, either quoted (`"greet.ts"`) or in brackets (`[greet.ts]`), and an optional options object: `at` (the click of the first version, default 0) and `lines` (line numbers, default off). Each inner fence can have its own `{...}` line emphasis, as in a plain block, and its own `lines`.
|
|
100
|
+
|
|
101
|
+
Each version holds for as many clicks as it has emphasis steps, at least one, and the next click morphs to the next version. The slide above shows version 1 at click 0, version 2 with line 1 then line 2 emphasized at clicks 1 and 2, and version 3 at click 3: `at` plus every version's step count, minus 1, so 3 clicks with no `clicks:` in the frontmatter.
|
|
102
|
+
|
|
103
|
+
The morph plays only on a forward step in the play view with live motion. Going back, jumping, reloading, the presenter window, the overview and print show the version for the click at once, and each printed click page shows its own version. Slidev's `{*}` emphasis is not supported; use `{all}`. A fence that does not parse is a compile error naming the slide and the line.
|
|
104
|
+
|
|
74
105
|
## Languages
|
|
75
106
|
|
|
76
107
|
The language is the first word on the fence. Any language Shiki bundles works. A block with no language is plain text. An unknown language is rendered as plain text and logs a warning naming the file.
|
package/docs/config.md
CHANGED
|
@@ -28,6 +28,7 @@ Only `title` is required. An unknown key is an error that lists the known ones.
|
|
|
28
28
|
| `credit` | `boolean` | `true` | The "Created with Decks" credit on every slide. `false` removes it. |
|
|
29
29
|
| `vite` | Vite `UserConfig` | none | Merged into the framework's Vite config. `vite.plugins` are added after the framework's. |
|
|
30
30
|
| `mdx` | `{ remarkPlugins?: PluggableList; rehypePlugins?: PluggableList }` | none | Plugins added to the slide compiler. Each key, when present, must be an array. |
|
|
31
|
+
| `term` | `{ dirs?: Record<string, string> }` | none | Working directories a `LiveTerm` pane can start in, by key, relative to the deck. Each must exist when `decks dev --live-term` starts. See [terminal.md](terminal.md). |
|
|
31
32
|
|
|
32
33
|
Examples of each:
|
|
33
34
|
|
package/docs/getting-started.md
CHANGED
|
@@ -58,7 +58,7 @@ npx -p @steamfield/decks decks build hello
|
|
|
58
58
|
|
|
59
59
|
Or add scripts to `package.json` (`"dev": "decks dev hello"`, `"build": "decks build hello"`), which run the installed bin, and use `bun run dev` or `npm run dev`. The rest of the guide writes the command as `decks` for short.
|
|
60
60
|
|
|
61
|
-
### `decks dev <deck> [--port <n>] [--open]`
|
|
61
|
+
### `decks dev <deck> [--port <n>] [--open] [--live-term]`
|
|
62
62
|
|
|
63
63
|
Serves the deck with live updates and prints its URL.
|
|
64
64
|
|
|
@@ -66,6 +66,7 @@ Serves the deck with live updates and prints its URL.
|
|
|
66
66
|
| --- | --- | --- |
|
|
67
67
|
| `--port <n>` | first free port from 3030 up | A whole number from 0 to 65535. An explicit port is strict: if it is taken the command fails instead of moving to another. `0` lets the OS pick. |
|
|
68
68
|
| `--open` | off | Open the deck in a browser. |
|
|
69
|
+
| `--live-term` | off | Run real shells in the deck's `LiveTerm` panes, on macOS and Linux. See [terminal.md](terminal.md). `decks build` and the other commands reject it. |
|
|
69
70
|
|
|
70
71
|
What an edit does while `dev` runs:
|
|
71
72
|
|