excalideck 0.0.0-stage → 0.2.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/.claude-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +12 -0
- package/.claude-plugin/plugin.json +11 -0
- package/AGENTS.md +63 -0
- package/LICENSE +21 -0
- package/README.md +163 -2
- package/bin/excalideck +2 -0
- package/cli/doctor.mjs +130 -0
- package/cli/main.mjs +394 -0
- package/cli/media.mjs +118 -0
- package/cli/paths.mjs +24 -0
- package/cli/register.mjs +4 -0
- package/cli/resolve-hook.mjs +9 -0
- package/cli/serve.mjs +77 -0
- package/cli/server.mjs +68 -0
- package/examples/snapline/build.mjs +181 -0
- package/examples/snapline/snapline.excalidraw +13141 -0
- package/lib/excalideck.mjs +267 -0
- package/package.json +60 -4
- package/player/THIRD_PARTY.md +5 -0
- package/player/fonts/Excalifont-Latin.woff2 +0 -0
- package/player/fonts/Virgil.woff2 +0 -0
- package/player/index.html +63 -0
- package/player/player.js +617 -0
- package/player/vendor/LICENSE-roughjs +21 -0
- package/player/vendor/rough.js +1 -0
- package/skills/excalideck/SKILL.md +142 -0
- package/skills/excalideck/api.md +59 -0
- package/src/check.js +158 -0
- package/src/contract/busy-client.js +93 -0
- package/src/contract/exit-codes.js +28 -0
- package/src/contract/health.js +37 -0
- package/src/contract/install-method.js +83 -0
- package/src/contract/output.js +83 -0
- package/src/contract/runtime-file.js +59 -0
- package/src/contract/semver.js +101 -0
- package/src/metrics.js +4 -0
- package/src/scene.js +187 -0
package/cli/server.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// The local server behind `excalideck serve`, and behind `render` and `record`. It serves the player from this
|
|
2
|
+
// package, the deck being presented at /deck.excalidraw, and the two endpoints the CLI contract asks for
|
|
3
|
+
// (SPEC §8): /api/health and /api/busy. Loopback only — see AGENTS.md.
|
|
4
|
+
import http from "node:http";
|
|
5
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
6
|
+
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
7
|
+
|
|
8
|
+
const MIME = {
|
|
9
|
+
".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".mjs": "text/javascript; charset=utf-8",
|
|
10
|
+
".css": "text/css; charset=utf-8", ".json": "application/json", ".excalidraw": "application/json",
|
|
11
|
+
".woff2": "font/woff2", ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif",
|
|
12
|
+
".svg": "image/svg+xml", ".webp": "image/webp", ".webm": "video/webm", ".mp4": "video/mp4",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const HOST = "127.0.0.1";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} o
|
|
19
|
+
* @param {string} o.root this package's root, holding player/ and src/
|
|
20
|
+
* @param {string} o.version printed by /api/health and /api/busy
|
|
21
|
+
* @param {string} [o.deckFile] the deck to serve at /deck.excalidraw
|
|
22
|
+
* @param {string} [o.outDir] a folder to expose at /out/ (the render contact sheet)
|
|
23
|
+
*/
|
|
24
|
+
export function createServer(o) {
|
|
25
|
+
const deckDir = o.deckFile ? dirname(resolve(o.deckFile)) : undefined;
|
|
26
|
+
let inflight = 0;
|
|
27
|
+
const server = http.createServer((req, res) => {
|
|
28
|
+
inflight++;
|
|
29
|
+
res.on("close", () => inflight--);
|
|
30
|
+
const send = (code, type, body) => { res.writeHead(code, { "content-type": type, "cache-control": "no-store" }); res.end(body); };
|
|
31
|
+
const json = (code, doc) => send(code, "application/json", `${JSON.stringify(doc)}\n`);
|
|
32
|
+
let p;
|
|
33
|
+
try { p = decodeURIComponent(new URL(req.url, "http://localhost").pathname); } catch { return send(400, "text/plain", "bad request"); }
|
|
34
|
+
|
|
35
|
+
// SPEC §8. Both must answer without auth; /api/busy must be cheap and must not walk the disk.
|
|
36
|
+
if (p === "/api/health") return json(200, { ok: true, version: o.version });
|
|
37
|
+
if (p === "/api/busy") return json(200, { busy: false, version: o.version, counts: {} });
|
|
38
|
+
|
|
39
|
+
if (p === "/") { res.writeHead(302, { location: `/player/?file=/deck.excalidraw${o.watch ? "&watch" : ""}` }); return res.end(); }
|
|
40
|
+
|
|
41
|
+
let fsPath;
|
|
42
|
+
if (p === "/deck.excalidraw" && o.deckFile) fsPath = resolve(o.deckFile);
|
|
43
|
+
else if (o.outDir && p.startsWith("/out/")) fsPath = join(o.outDir, basename(p));
|
|
44
|
+
else if (deckDir && p.startsWith("/media/")) fsPath = join(deckDir, p.slice("/media/".length)); // images beside the deck
|
|
45
|
+
else fsPath = join(o.root, p);
|
|
46
|
+
|
|
47
|
+
const allowed = [o.root, o.outDir, deckDir].filter(Boolean);
|
|
48
|
+
const inside = allowed.some((dir) => fsPath === resolve(dir) || fsPath.startsWith(resolve(dir) + "/"));
|
|
49
|
+
if (!inside && fsPath !== (o.deckFile && resolve(o.deckFile))) return send(403, "text/plain", "forbidden");
|
|
50
|
+
if (existsSync(fsPath) && statSync(fsPath).isDirectory()) fsPath = join(fsPath, "index.html");
|
|
51
|
+
if (!existsSync(fsPath) || !statSync(fsPath).isFile()) return send(404, "text/plain", "not found");
|
|
52
|
+
send(200, MIME[extname(fsPath)] ?? "application/octet-stream", readFileSync(fsPath));
|
|
53
|
+
});
|
|
54
|
+
server.on("connection", (s) => s.unref()); // a kept-alive browser connection mustn't hold a stopping process open
|
|
55
|
+
return { server, get inflight() { return inflight; } };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Listens on loopback. `port` 0 picks a free one; a port in use rejects with EADDRINUSE. */
|
|
59
|
+
export function listen(server, port) {
|
|
60
|
+
return new Promise((res, rej) => {
|
|
61
|
+
server.once("error", rej);
|
|
62
|
+
server.listen(port, HOST, () => {
|
|
63
|
+
const actual = server.address().port;
|
|
64
|
+
res({ port: actual, base: `http://${HOST}:${actual}`, url: `http://${HOST}:${actual}/player/?file=/deck.excalidraw`,
|
|
65
|
+
close: () => new Promise((done) => server.close(done)) });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Snapline: a made-up photo-sharing app, explained outside-in.
|
|
2
|
+
// Run: node examples/snapline/build.mjs → examples/snapline/snapline.excalidraw
|
|
3
|
+
//
|
|
4
|
+
// Patterns worth copying:
|
|
5
|
+
// • A function draws the shared layout (`system`), so the same box sits in the same place on
|
|
6
|
+
// every slide that shows it. Only what changes moves — that's what makes morphs read well.
|
|
7
|
+
// • Drill-down: a box on one slide and a region with the SAME LABEL on the next.
|
|
8
|
+
// • Highlight: redraw the same layout with most things at low opacity and one path in red.
|
|
9
|
+
// • Clones: three boxes with the same label where there used to be one.
|
|
10
|
+
// • `camera`: a frame placed far away on the canvas.
|
|
11
|
+
// (Your own talk imports "excalideck"; this one lives inside the repo, so it points at lib/ directly.)
|
|
12
|
+
import { Deck, PALETTE } from "../../lib/excalideck.mjs";
|
|
13
|
+
|
|
14
|
+
const deck = new Deck();
|
|
15
|
+
const RED = PALETTE.red[0];
|
|
16
|
+
|
|
17
|
+
// ── 1 ── title ────────────────────────────────────────────────────────────────
|
|
18
|
+
{
|
|
19
|
+
const f = deck.frame("Title", { appear: "rise" });
|
|
20
|
+
f.text("How Snapline Works", { x: 800, y: 250, size: 96, align: "center" });
|
|
21
|
+
f.text("A photo-sharing app, from the outside in", { x: 800, y: 390, size: 36, align: "center", color: "#495057" });
|
|
22
|
+
f.box("Snapline", { x: 650, y: 520, w: 300, h: 150, size: 36 });
|
|
23
|
+
f.caption("rise — on load the first slide builds in; each frame's name picks its own transition");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ── 2 ── context ──────────────────────────────────────────────────────────────
|
|
27
|
+
{
|
|
28
|
+
const f = deck.frame("The big picture", { transition: "morph", appear: "draw" });
|
|
29
|
+
f.title("The big picture");
|
|
30
|
+
const ph = f.box("Photographer", { x: 100, y: 250, w: 200, h: 110, color: "orange", shape: "ellipse" });
|
|
31
|
+
const fr = f.box("Friends", { x: 100, y: 560, w: 200, h: 110, color: "orange", shape: "ellipse" });
|
|
32
|
+
const s = f.box("Snapline", { x: 610, y: 360, w: 380, h: 200, size: 40 });
|
|
33
|
+
const cs = f.box("Cloud Storage", { x: 1240, y: 220, w: 240, h: 110, color: "gray" });
|
|
34
|
+
const push = f.box("Push\nNotifications", { x: 1240, y: 590, w: 240, h: 110, color: "gray" });
|
|
35
|
+
f.arrow(ph, s, { label: "uploads photos" });
|
|
36
|
+
f.arrow(fr, s, { label: "browses feed" });
|
|
37
|
+
f.arrow(s, cs, { label: "stores originals" });
|
|
38
|
+
f.arrow(s, push, { label: "sends alerts" });
|
|
39
|
+
f.caption("morph + draw — shapes sketch themselves in; each arrow waits for both its boxes");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ── 3 ── open the box ─────────────────────────────────────────────────────────
|
|
43
|
+
{
|
|
44
|
+
const f = deck.frame("Opening the box", { transition: "morph" });
|
|
45
|
+
f.title("Opening the box");
|
|
46
|
+
f.region("Snapline", { x: 290, y: 120, w: 560, h: 690 }); // same label as the box on slide 2 → it grows into this
|
|
47
|
+
const ph = f.box("Photographer", { x: 40, y: 250, w: 190, h: 100, color: "orange", shape: "ellipse" });
|
|
48
|
+
const fr = f.box("Friends", { x: 40, y: 540, w: 190, h: 100, color: "orange", shape: "ellipse" });
|
|
49
|
+
const api = f.box("API Gateway", { x: 330, y: 360, w: 170, h: 90 });
|
|
50
|
+
const auth = f.box("Auth Service", { x: 580, y: 200, w: 180 });
|
|
51
|
+
const up = f.box("Upload Service", { x: 580, y: 360, w: 180, color: "green" });
|
|
52
|
+
const feed = f.box("Feed Service", { x: 580, y: 520, w: 180 });
|
|
53
|
+
const notif = f.box("Notification\nService", { x: 580, y: 680, w: 180 });
|
|
54
|
+
const cs = f.box("Cloud Storage", { x: 1040, y: 220, w: 240, h: 110, color: "gray" });
|
|
55
|
+
const push = f.box("Push\nNotifications", { x: 1040, y: 640, w: 240, h: 110, color: "gray" });
|
|
56
|
+
f.arrow(ph, api); f.arrow(fr, api);
|
|
57
|
+
f.arrow(api, auth); f.arrow(api, up); f.arrow(api, feed); f.arrow(api, notif);
|
|
58
|
+
f.arrow(up, cs); f.arrow(notif, push);
|
|
59
|
+
f.caption("morph — the box grows into a region; arrows re-attach to the parts inside");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The full system, drawn identically on slides 4, 5, 7 and 8.
|
|
63
|
+
// dim: true + hot: Set of names → everything not hot fades to 22%, hot arrows turn red
|
|
64
|
+
// scaled: true → three Image Resizers and an Autoscaler
|
|
65
|
+
function system(f, o = {}) {
|
|
66
|
+
const hot = o.hot ?? new Set();
|
|
67
|
+
const op = (k) => (o.dim && !hot.has(k) ? 22 : 100);
|
|
68
|
+
const hotArrow = (k) => (hot.has(k) ? { color: RED, strokeWidth: 4 } : {});
|
|
69
|
+
f.region("Snapline", { x: 290, y: 120, w: 1010, h: 690, opacity: o.dim ? 45 : 100 });
|
|
70
|
+
const b = {
|
|
71
|
+
ph: f.box("Photographer", { x: 40, y: 250, w: 190, h: 100, color: "orange", shape: "ellipse", opacity: op("ph") }),
|
|
72
|
+
fr: f.box("Friends", { x: 40, y: 540, w: 190, h: 100, color: "orange", shape: "ellipse", opacity: op("fr") }),
|
|
73
|
+
api: f.box("API Gateway", { x: 330, y: 360, w: 170, h: 90, opacity: op("api") }),
|
|
74
|
+
auth: f.box("Auth Service", { x: 580, y: 200, w: 180, opacity: op("auth") }),
|
|
75
|
+
up: f.box("Upload Service", { x: 580, y: 360, w: 180, color: "green", opacity: op("up") }),
|
|
76
|
+
feed: f.box("Feed Service", { x: 580, y: 520, w: 180, opacity: op("feed") }),
|
|
77
|
+
pg: f.box("Postgres", { x: 850, y: 180, w: 190, h: 100, color: "violet", shape: "ellipse", opacity: op("pg") }),
|
|
78
|
+
bus: f.box("Event Bus", { x: 860, y: 360, w: 170, color: "yellow", opacity: op("bus") }),
|
|
79
|
+
redis: f.box("Redis Cache", { x: 860, y: 520, w: 170, color: "red", opacity: op("redis") }),
|
|
80
|
+
notif: f.box("Notification\nService", { x: 1080, y: 520, w: 180, opacity: op("notif") }),
|
|
81
|
+
cs: f.box("Cloud Storage", { x: 1340, y: 150, w: 220, h: 100, color: "gray", opacity: op("cs") }),
|
|
82
|
+
push: f.box("Push\nNotifications", { x: 1340, y: 620, w: 220, h: 100, color: "gray", opacity: op("push") }),
|
|
83
|
+
};
|
|
84
|
+
const a = (from, to) => f.arrow(b[from], b[to], { opacity: op(`${from}-${to}`), ...hotArrow(`${from}-${to}`) });
|
|
85
|
+
a("ph", "api"); a("fr", "api"); a("api", "auth"); a("api", "up"); a("api", "feed");
|
|
86
|
+
a("auth", "pg"); a("up", "bus"); a("feed", "redis"); a("bus", "notif"); a("notif", "push");
|
|
87
|
+
if (o.scaled) {
|
|
88
|
+
const rs = [240, 320, 400].map((y) => f.box("Image Resizer", { x: 1080, y, w: 180, h: 60, color: "teal" }));
|
|
89
|
+
for (const r of rs) { f.arrow(b.bus, r); f.arrow(r, b.cs, { via: [[1300, r.cy]] }); } // bend so arrows don't cut through the stack
|
|
90
|
+
const auto = f.box("Autoscaler", { x: 1080, y: 130, w: 180, h: 60, color: "gray", dashed: true });
|
|
91
|
+
f.arrow(auto, rs[0], { dashed: true, color: "#868e96" });
|
|
92
|
+
} else {
|
|
93
|
+
b.rs = f.box("Image Resizer", { x: 1080, y: 360, w: 180, color: "teal", opacity: op("rs") });
|
|
94
|
+
a("bus", "rs"); a("rs", "cs");
|
|
95
|
+
}
|
|
96
|
+
return b;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ── 4 ── data ─────────────────────────────────────────────────────────────────
|
|
100
|
+
{
|
|
101
|
+
const f = deck.frame("Where data lives", { transition: "morph", appear: "pop" });
|
|
102
|
+
f.title("Where data lives");
|
|
103
|
+
system(f);
|
|
104
|
+
f.caption("morph + pop — new stores pop in left to right; the region stretches to fit");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ── 5 ── highlight a path ─────────────────────────────────────────────────────
|
|
108
|
+
{
|
|
109
|
+
const f = deck.frame("Following an upload", { transition: "morph" });
|
|
110
|
+
f.title("Following an upload");
|
|
111
|
+
system(f, { dim: true, hot: new Set(["ph", "api", "up", "bus", "rs", "cs", "ph-api", "api-up", "up-bus", "bus-rs", "rs-cs"]) });
|
|
112
|
+
[[262, 268], [515, 345], [790, 345], [1032, 345], [1282, 230]].forEach(([x, y], i) => f.badge(i + 1, { x, y }));
|
|
113
|
+
f.caption("morph — everything else dims, one path turns red; numbered badges pop in");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ── 6 ── drill into a service ─────────────────────────────────────────────────
|
|
117
|
+
{
|
|
118
|
+
const f = deck.frame("Inside Upload Service", { transition: "zoom" });
|
|
119
|
+
f.title("Inside Upload Service");
|
|
120
|
+
f.region("Upload Service", { x: 300, y: 140, w: 960, h: 680, color: "green" });
|
|
121
|
+
const api = f.box("API Gateway", { x: 60, y: 400, w: 170, h: 90 });
|
|
122
|
+
const val = f.box("Request Validator", { x: 350, y: 395, w: 200, h: 90, color: "green" });
|
|
123
|
+
const rl = f.box("Rate Limiter", { x: 350, y: 610, w: 200, color: "gray", dashed: true });
|
|
124
|
+
const sign = f.box("Presigned URL\nSigner", { x: 650, y: 200, w: 210, h: 90, color: "green" });
|
|
125
|
+
const meta = f.box("Metadata Writer", { x: 650, y: 395, w: 210, h: 90, color: "green" });
|
|
126
|
+
const pub = f.box("Event Publisher", { x: 970, y: 395, w: 210, h: 90, color: "green" });
|
|
127
|
+
const cs = f.box("Cloud Storage", { x: 1340, y: 190, w: 220, h: 100, color: "gray" });
|
|
128
|
+
const bus = f.box("Event Bus", { x: 1360, y: 400, w: 180, color: "yellow" });
|
|
129
|
+
const pg = f.box("Postgres", { x: 1340, y: 640, w: 200, h: 100, color: "violet", shape: "ellipse" });
|
|
130
|
+
f.arrow(api, val); f.arrow(rl, val, { dashed: true, color: "#868e96" });
|
|
131
|
+
f.arrow(val, sign); f.arrow(val, meta); f.arrow(meta, pub);
|
|
132
|
+
f.arrow(sign, cs); f.arrow(pub, bus); f.arrow(meta, pg);
|
|
133
|
+
f.caption("zoom — the camera dives into Upload Service; everything else flies past");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ── 7 ── back out ─────────────────────────────────────────────────────────────
|
|
137
|
+
{
|
|
138
|
+
const f = deck.frame("Back to the overview", { transition: "zoom" });
|
|
139
|
+
f.title("Back to the overview");
|
|
140
|
+
system(f);
|
|
141
|
+
f.caption("zoom (reversed) — the detail shrinks back into its box; the system flies back in around it");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ── 8 ── scale out ────────────────────────────────────────────────────────────
|
|
145
|
+
{
|
|
146
|
+
const f = deck.frame("Scaling the resizers", { transition: "morph", appear: "pop" });
|
|
147
|
+
f.title("Scaling the resizers");
|
|
148
|
+
system(f, { scaled: true });
|
|
149
|
+
f.caption("morph + pop — extra copies clone out of the original; the autoscaler pops in");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ── 9 ── deployment, far away on the canvas ───────────────────────────────────
|
|
153
|
+
{
|
|
154
|
+
const f = deck.frame("Where it runs", { transition: "camera", at: [3600, 2700] });
|
|
155
|
+
f.title("Where it runs");
|
|
156
|
+
const cdn = f.box("Global CDN", { x: 500, y: 140, w: 600, h: 80, color: "cyan", size: 24 });
|
|
157
|
+
f.region("us-east-1", { x: 70, y: 270, w: 700, h: 540, color: "gray" });
|
|
158
|
+
f.region("eu-west-1", { x: 830, y: 270, w: 700, h: 540, color: "gray" });
|
|
159
|
+
f.region("Kubernetes Cluster", { x: 100, y: 330, w: 430, h: 270, size: 20 });
|
|
160
|
+
f.region("Kubernetes Cluster", { x: 860, y: 330, w: 430, h: 270, size: 20 });
|
|
161
|
+
const [api1] = f.row(["API pods", "Worker pods"], { x: 130, y: 420, w: 170, gap: 30 });
|
|
162
|
+
const [api2] = f.row(["API pods", "Worker pods"], { x: 890, y: 420, w: 170, gap: 30 });
|
|
163
|
+
const p1 = f.box("Postgres Primary", { x: 540, y: 650, w: 200, h: 100, color: "violet", shape: "ellipse", size: 18 });
|
|
164
|
+
const p2 = f.box("Postgres Replica", { x: 860, y: 650, w: 200, h: 100, color: "violet", shape: "ellipse", size: 18 });
|
|
165
|
+
f.box("Object Storage", { x: 110, y: 660, w: 240, h: 90, color: "gray" });
|
|
166
|
+
f.box("Object Storage", { x: 1250, y: 660, w: 240, h: 90, color: "gray" });
|
|
167
|
+
f.arrow(cdn, api1); f.arrow(cdn, api2);
|
|
168
|
+
f.arrow(p1, p2, { dashed: true, label: "replication" });
|
|
169
|
+
f.caption("camera — flies across the board to a frame drawn somewhere else entirely");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ── 10 ── end ─────────────────────────────────────────────────────────────────
|
|
173
|
+
{
|
|
174
|
+
const f = deck.frame("Questions", { transition: "fade", at: [5400, 2700] });
|
|
175
|
+
f.text("Questions?", { x: 800, y: 320, size: 120, align: "center" });
|
|
176
|
+
f.text("Every slide in this talk is one frame in a single Excalidraw file", { x: 800, y: 500, size: 30, align: "center", color: "#495057" });
|
|
177
|
+
f.caption("fade");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const out = deck.save(new URL("./snapline.excalidraw", import.meta.url).pathname);
|
|
181
|
+
console.log(`wrote ${out}`);
|