Write decks as code
The builder library writes the .excalidraw file for you. Boxes size themselves to their labels using the real font
metrics, arrows are bound to their shapes, and frames are laid out and named. The output is deterministic, so a talk
lives happily in git.
// talk.mjs: build with `excalideck build talk.mjs`import { Deck } from "excalideck";
const deck = new Deck();
let f = deck.frame("Overview", { appear: "draw" });f.title("Overview");const user = f.box("Customer", { x: 140, y: 400, shape: "ellipse", color: "orange" });const shop = f.box("Shop", { x: 640, y: 380, w: 320, h: 140, size: 32 });f.arrow(user, shop, { label: "orders" });
f = deck.frame("Inside the shop", { transition: "zoom", appear: "pop" });f.title("Inside the shop");const user2 = f.box("Customer", { x: 40, y: 400, shape: "ellipse", color: "orange" });f.region("Shop", { x: 300, y: 160, w: 860, h: 600 }); // same label: the box opens into thisconst web = f.box("Storefront", { x: 360, y: 410 });const api = f.box("Orders API", { x: 640, y: 410, color: "green" });const db = f.box("Orders DB", { x: 640, y: 590, shape: "ellipse", color: "violet" });f.arrow(user2, web); f.arrow(web, api); f.arrow(api, db);
deck.save("talk.excalidraw");excalideck build talk.mjs # runs the script, then checks talk.excalidrawexcalideck dev talk.mjs # the same on every save, and presents it with live reloadRun talk scripts with excalideck build rather than plain node: it resolves import ... from "excalideck" for you,
wherever excalideck is installed. excalideck new <name> writes a starter script to copy from.
Patterns worth knowing
Section titled “Patterns worth knowing”Share the layout. A component that’s on several slides should stay where it is unless the move is the point. Put the layout in a function with options, and call it from each slide:
function system(f, { dim = false, hot = null } = {}) { const op = dim ? 20 : 100; const api = f.box("Orders API", { x: 640, y: 410, opacity: op, color: hot === "api" ? "green" : "blue" }); // ... return { api };}Drill down. A box on one slide, and a region with the same label on the next. With transition: "zoom" the
camera dives in; with morph the box grows in place. Neighbours that are on both slides stay, and their arrows
re-attach to the new parts inside.
Highlight a path. Repeat the layout with opacity: 20 on everything off the path, and
color: PALETTE.red[0], strokeWidth: 4 on the path’s arrows. f.badge(1, { x, y }) numbers the steps.
Scale out. Draw three boxes labelled “Worker” where there was one, and two of them clone out of the original.
Change of topic. Give a frame at: [x, y] far from the others (2000px or more) and transition: "camera".
The example deck’s script uses every one of these, and is written to be copied from. Every method and option is in the Builder API.
Layout rules that read well on a projector
Section titled “Layout rules that read well on a projector”- Frames are 1600×900. Keep content inside x 40–1560, y 120–840;
f.title()sits above that. - Four words or fewer per box. Split longer labels with
\n. Text is 20px by default; don’t go below 16px. - Twelve boxes or fewer per slide. More than that: split the slide, or drill down.
- Give boxes in the same row or column the same
w, so they line up. - Colour by role, and stay consistent: blue services, green the thing in focus, violet databases, yellow queues, orange people, gray external systems.