@treasure-ai/treasure-deck 0.0.0-stage → 2026.10.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 (110) hide show
  1. package/LICENSE.md +5 -0
  2. package/README.md +109 -2
  3. package/dist/analytics.d.ts +34 -0
  4. package/dist/analytics.js +93 -0
  5. package/dist/analytics.js.map +1 -0
  6. package/dist/attrs.d.ts +10 -0
  7. package/dist/attrs.js +22 -0
  8. package/dist/attrs.js.map +1 -0
  9. package/dist/build.d.ts +67 -0
  10. package/dist/build.js +247 -0
  11. package/dist/build.js.map +1 -0
  12. package/dist/check.d.ts +30 -0
  13. package/dist/check.js +142 -0
  14. package/dist/check.js.map +1 -0
  15. package/dist/chrome.d.ts +20 -0
  16. package/dist/chrome.js +162 -0
  17. package/dist/chrome.js.map +1 -0
  18. package/dist/cli.d.ts +2 -0
  19. package/dist/cli.js +246 -0
  20. package/dist/cli.js.map +1 -0
  21. package/dist/dev.d.ts +28 -0
  22. package/dist/dev.js +557 -0
  23. package/dist/dev.js.map +1 -0
  24. package/dist/diagrams.d.ts +18 -0
  25. package/dist/diagrams.js +57 -0
  26. package/dist/diagrams.js.map +1 -0
  27. package/dist/highlight.d.ts +7 -0
  28. package/dist/highlight.js +26 -0
  29. package/dist/highlight.js.map +1 -0
  30. package/dist/hot.d.ts +31 -0
  31. package/dist/hot.js +34 -0
  32. package/dist/hot.js.map +1 -0
  33. package/dist/media.d.ts +24 -0
  34. package/dist/media.js +82 -0
  35. package/dist/media.js.map +1 -0
  36. package/dist/parse.d.ts +109 -0
  37. package/dist/parse.js +313 -0
  38. package/dist/parse.js.map +1 -0
  39. package/dist/patch.d.ts +22 -0
  40. package/dist/patch.js +53 -0
  41. package/dist/patch.js.map +1 -0
  42. package/dist/pdf.d.ts +10 -0
  43. package/dist/pdf.js +53 -0
  44. package/dist/pdf.js.map +1 -0
  45. package/dist/render.d.ts +101 -0
  46. package/dist/render.js +513 -0
  47. package/dist/render.js.map +1 -0
  48. package/dist/scaffold.d.ts +27 -0
  49. package/dist/scaffold.js +83 -0
  50. package/dist/scaffold.js.map +1 -0
  51. package/dist/themecheck.d.ts +34 -0
  52. package/dist/themecheck.js +228 -0
  53. package/dist/themecheck.js.map +1 -0
  54. package/docs/adrs/2026-10-03-chrome-over-devtools.md +29 -0
  55. package/docs/adrs/2026-10-03-fixed-canvas.md +25 -0
  56. package/docs/adrs/2026-10-03-four-layouts-plus-attributes.md +25 -0
  57. package/docs/adrs/2026-10-03-hybrid-pdf-over-devtools.md +25 -0
  58. package/docs/adrs/2026-10-03-keyword-lines-and-one-attribute-syntax.md +36 -0
  59. package/docs/adrs/2026-10-03-one-behavior-instead-of-settings.md +30 -0
  60. package/docs/adrs/2026-10-03-overflow-is-reported-not-hidden.md +27 -0
  61. package/docs/adrs/2026-10-03-single-file-html.md +26 -0
  62. package/docs/adrs/2026-10-03-strict-build-forgiving-preview.md +31 -0
  63. package/docs/adrs/2026-10-04-edit-in-place-by-alignment.md +28 -0
  64. package/docs/adrs/2026-10-04-editor-in-the-deck-page.md +31 -0
  65. package/docs/adrs/2026-10-04-edits-are-line-range-patches.md +35 -0
  66. package/docs/adrs/2026-10-04-per-slide-hot-swap.md +33 -0
  67. package/docs/adrs/2026-10-04-theme-colors-derive-in-css.md +32 -0
  68. package/docs/adrs/2026-10-05-host-owns-undo.md +26 -0
  69. package/docs/adrs/2026-10-07-anonymous-access-metrics.md +38 -0
  70. package/docs/adrs/2026-10-14-dev-links-media-by-url.md +25 -0
  71. package/docs/adrs/2026-10-14-media-dir-for-the-publish-limit.md +28 -0
  72. package/docs/adrs/2026-10-14-videos-are-inlined-images.md +28 -0
  73. package/docs/adrs/2026-10-15-public-npm-under-labs-terms.md +37 -0
  74. package/docs/adrs/README.md +34 -0
  75. package/docs/commands.md +104 -0
  76. package/docs/editor.md +114 -0
  77. package/docs/syntax.md +157 -0
  78. package/docs/themes.md +134 -0
  79. package/package.json +68 -4
  80. package/runtime/base.css +354 -0
  81. package/runtime/edit-core.cjs +877 -0
  82. package/runtime/embed.js +5259 -0
  83. package/runtime/hot.js +136 -0
  84. package/runtime/runtime.js +729 -0
  85. package/skills/treasure-deck/SKILL.md +136 -0
  86. package/templates/deck.md +78 -0
  87. package/templates/specimen/specimen.md +104 -0
  88. package/templates/theme/assets/mark.svg +1 -0
  89. package/templates/theme/theme.css +97 -0
  90. package/templates/theme/theme.yaml +7 -0
  91. package/themes/default/theme.css +183 -0
  92. package/themes/default/theme.yaml +6 -0
  93. package/themes/editorial/theme.css +168 -0
  94. package/themes/editorial/theme.yaml +7 -0
  95. package/themes/gold/assets/gem.svg +130 -0
  96. package/themes/gold/theme.css +303 -0
  97. package/themes/gold/theme.yaml +7 -0
  98. package/themes/pastel/theme.css +187 -0
  99. package/themes/pastel/theme.yaml +6 -0
  100. package/themes/treasure-ai/assets/gem-line.svg +7 -0
  101. package/themes/treasure-ai/assets/gem.png +0 -0
  102. package/themes/treasure-ai/assets/gem.svg +25 -0
  103. package/themes/treasure-ai/assets/glass.svg +12 -0
  104. package/themes/treasure-ai/assets/logo-white.png +0 -0
  105. package/themes/treasure-ai/assets/logo.png +0 -0
  106. package/themes/treasure-ai/theme.css +239 -0
  107. package/themes/treasure-ai/theme.yaml +6 -0
  108. package/themes/wvlet/assets/wvlet-icon.svg +27 -0
  109. package/themes/wvlet/theme.css +238 -0
  110. package/themes/wvlet/theme.yaml +6 -0
@@ -0,0 +1,83 @@
1
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { builtinThemes, SKILLS_DIR, TEMPLATES_DIR, THEMES_DIR } from './build.js';
4
+ import { DeckError } from './parse.js';
5
+ function assertEmpty(dir) {
6
+ if (existsSync(dir) && readdirSync(dir).length > 0)
7
+ throw new DeckError(`${dir} already exists and is not empty`);
8
+ }
9
+ function rewrite(file, edit) {
10
+ writeFileSync(file, edit(readFileSync(file, 'utf8')));
11
+ }
12
+ /**
13
+ * Scaffold a theme folder (theme.yaml, theme.css, assets/) named after the folder. By default it starts from
14
+ * a small template that sets every token and styles every semantic class; `from` copies a built-in theme
15
+ * instead, rescoped to the new name. Returns the theme's name.
16
+ */
17
+ export function initTheme(dir, from) {
18
+ const name = path.basename(path.resolve(dir)).toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '');
19
+ if (!name)
20
+ throw new DeckError(`cannot derive a theme name from "${dir}"`);
21
+ if (from !== undefined && !builtinThemes().includes(from)) {
22
+ throw new DeckError(`--from takes a built-in theme (${builtinThemes().join(', ')}), got "${from}"`);
23
+ }
24
+ assertEmpty(dir);
25
+ cpSync(from ? path.join(THEMES_DIR, from) : path.join(TEMPLATES_DIR, 'theme'), dir, { recursive: true });
26
+ const css = path.join(dir, 'theme.css');
27
+ const yaml = path.join(dir, 'theme.yaml');
28
+ if (from) {
29
+ rewrite(css, (t) => t.replaceAll(`[data-theme="${from}"]`, `[data-theme="${name}"]`));
30
+ rewrite(yaml, (t) => t.replace(/^name:.*$/m, `name: ${name}`));
31
+ }
32
+ else {
33
+ for (const f of [css, yaml])
34
+ rewrite(f, (t) => t.replaceAll('__NAME__', name));
35
+ }
36
+ return name;
37
+ }
38
+ /** The deck file `deck new` writes for a target: the .md itself, or `<dir>/<dir>.md`. */
39
+ export function deckFileFor(target) {
40
+ return target.endsWith('.md') ? target : path.join(target, `${path.basename(path.resolve(target))}.md`);
41
+ }
42
+ /**
43
+ * Scaffold a deck: `talk.md` writes that file; a folder (`talks/q3-review`, or a path without .md) gets
44
+ * `<folder>/<folder>.md`. Either way an `images/` folder sits next to it. The starter deck shows the house
45
+ * style (title, a lead slide, sections, columns with a card, code, a table) and builds as is.
46
+ * Returns the deck file's path.
47
+ */
48
+ export function newDeck(target, options = {}) {
49
+ const file = deckFileFor(target);
50
+ if (existsSync(file))
51
+ throw new DeckError(`${file} already exists`);
52
+ const dir = path.dirname(file);
53
+ mkdirSync(path.join(dir, 'images'), { recursive: true });
54
+ const slug = path.basename(file, '.md');
55
+ const title = options.title ?? slug.replace(/[-_]+/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase());
56
+ const today = options.today ?? new Date();
57
+ const iso = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`;
58
+ const long = today.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
59
+ const vars = {
60
+ __TITLE__: title,
61
+ // Frontmatter values are quoted as JSON strings, which YAML reads as is.
62
+ __TITLE_YAML__: JSON.stringify(title),
63
+ __AUTHOR__: options.author ?? 'Your Name',
64
+ __AUTHOR_YAML__: JSON.stringify(options.author ?? 'Your Name'),
65
+ __DATE__: iso,
66
+ __DATE_LONG__: long,
67
+ __THEME__: options.theme ?? 'default',
68
+ };
69
+ const text = readFileSync(path.join(TEMPLATES_DIR, 'deck.md'), 'utf8').replace(/__[A-Z_]+__/g, (k) => vars[k] ?? k);
70
+ writeFileSync(file, text);
71
+ return file;
72
+ }
73
+ /**
74
+ * Install the bundled Claude skill (skills/treasure-deck) into a skills folder, `~/.claude/skills` by default,
75
+ * replacing an earlier copy. Returns the installed folder.
76
+ */
77
+ export function installSkill(skillsDir) {
78
+ const dest = path.join(skillsDir, 'treasure-deck');
79
+ rmSync(dest, { recursive: true, force: true });
80
+ cpSync(path.join(SKILLS_DIR, 'treasure-deck'), dest, { recursive: true });
81
+ return dest;
82
+ }
83
+ //# sourceMappingURL=scaffold.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1G,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,a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,GAAG;QACb,aAAa,EAAE,IAAI;QACnB,SAAS,EAAE,OAAO,CAAC,KAAK,IAAI,SAAS;KACtC,CAAC;IACF,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACpH,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1B,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACnD,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,34 @@
1
+ /** The deck `deck theme check` renders: every layout, semantic class, and standard element. */
2
+ export declare const SPECIMEN: string;
3
+ export type Mode = 'light' | 'dark';
4
+ export interface ThemeFinding {
5
+ mode: Mode;
6
+ /** 1-based slide number in the specimen; absent for findings about the theme as a whole. */
7
+ slide?: number;
8
+ /** Every slide a repeated finding (footer, eyebrow) appears on. */
9
+ slides?: number[];
10
+ title?: string;
11
+ severity: 'error' | 'warning';
12
+ message: string;
13
+ }
14
+ /** Tokens a theme must set: the seed colors (base.css derives the rest), fonts, and the corner radius. */
15
+ export declare const REQUIRED_TOKENS: string[];
16
+ /** Tokens base.css derives on .slide; a theme that sets one on .deck instead is silently overridden. */
17
+ export declare const DERIVED_TOKENS: string[];
18
+ /** Semantic classes every theme styles. Block classes are compared with a plain paragraph, inline ones with their parent. */
19
+ export declare const INLINE_CLASSES: readonly string[];
20
+ export declare const BLOCK_CLASSES: ("badge" | "callout" | "center" | "del" | "hl" | "lead" | "meta" | "muted" | "note" | "small" | "subtitle" | "warn")[];
21
+ /** WCAG AA: 4.5:1 for text, 3:1 for large text (24px, or 18.66px bold). */
22
+ export declare const AA_TEXT = 4.5;
23
+ export declare const AA_LARGE = 3;
24
+ export interface ThemeCheckOptions {
25
+ /** Write the specimen's slides as PNGs into this folder (`<mode>-slide-NN.png`). */
26
+ snapshots?: string;
27
+ }
28
+ /** Render the specimen with a theme in light and dark, and report contract and contrast problems. */
29
+ export declare function checkTheme(theme: string, options?: ThemeCheckOptions): Promise<{
30
+ theme: string;
31
+ findings: ThemeFinding[];
32
+ }>;
33
+ /** `theme gold (dark): error: slide 4 "Callouts and marks": contrast 3.10:1 is below 4.5:1 for p "…"` */
34
+ export declare function formatThemeFinding(theme: string, f: ThemeFinding): string;
@@ -0,0 +1,228 @@
1
+ import { mkdirSync, writeFileSync } from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { buildDeck, TEMPLATES_DIR } from './build.js';
4
+ import { titleOf } from './check.js';
5
+ import { evaluate, withDeckPage } from './chrome.js';
6
+ import { withMermaid } from './diagrams.js';
7
+ import { SEMANTIC_CLASSES } from './render.js';
8
+ /** The deck `deck theme check` renders: every layout, semantic class, and standard element. */
9
+ export const SPECIMEN = path.join(TEMPLATES_DIR, 'specimen', 'specimen.md');
10
+ /** Tokens a theme must set: the seed colors (base.css derives the rest), fonts, and the corner radius. */
11
+ export const REQUIRED_TOKENS = ['--deck-bg', '--deck-fg', '--deck-accent', '--deck-font-display', '--deck-font-body', '--deck-font-mono', '--deck-radius'];
12
+ const COLOR_TOKENS = new Set(['--deck-bg', '--deck-fg', '--deck-accent']);
13
+ /** Tokens base.css derives on .slide; a theme that sets one on .deck instead is silently overridden. */
14
+ export const DERIVED_TOKENS = [
15
+ '--deck-accent-2', '--deck-warn', '--deck-ok', '--deck-fg-muted', '--deck-strong', '--deck-line', '--deck-card', '--deck-on-accent',
16
+ '--deck-hl', '--deck-chip', ...[1, 2, 3, 4, 5, 6].map((n) => `--deck-series-${n}`), '--deck-diagram-fill', '--deck-diagram-fill-2',
17
+ '--deck-diagram-node-text', '--deck-diagram-line', '--deck-diagram-text', '--deck-diagram-alt', '--deck-diagram-shadow',
18
+ ];
19
+ /** Semantic classes every theme styles. Block classes are compared with a plain paragraph, inline ones with their parent. */
20
+ export const INLINE_CLASSES = ['hl', 'badge', 'del'];
21
+ export const BLOCK_CLASSES = SEMANTIC_CLASSES.filter((c) => !INLINE_CLASSES.includes(c));
22
+ /** WCAG AA: 4.5:1 for text, 3:1 for large text (24px, or 18.66px bold). */
23
+ export const AA_TEXT = 4.5;
24
+ export const AA_LARGE = 3;
25
+ /** Quiet tiers whose low contrast is reported as a warning rather than an error. */
26
+ const QUIET = '.muted, .meta, .slide-footer, .eyebrow, .section-num, .hljs-comment, .del, .img-caption';
27
+ /** Chrome repeated on every slide; named by class rather than text so a problem is reported once for all slides. */
28
+ const CHROME = '.slide-footer, .eyebrow';
29
+ /** Tokens and classes, measured on the open page. */
30
+ const INSPECT = `(() => {
31
+ const findings = [];
32
+ const probe = document.createElement('span');
33
+ document.body.appendChild(probe);
34
+ const isColor = (v) => { probe.style.color = ''; probe.style.color = v; return probe.style.color !== '' && getComputedStyle(probe).color !== ''; };
35
+ const content = document.querySelector('.deck-stage > .slide.layout-content');
36
+ const cs = getComputedStyle(content);
37
+ for (const t of ${JSON.stringify(REQUIRED_TOKENS)}) {
38
+ const v = cs.getPropertyValue(t).trim();
39
+ if (!v) findings.push({ severity: 'error', message: t + ' is not set' });
40
+ else if (${JSON.stringify([...COLOR_TOKENS])}.includes(t) && !isColor(v)) findings.push({ severity: 'error', message: t + ' is not a color: ' + v });
41
+ }
42
+ const deckCs = getComputedStyle(document.querySelector('.deck'));
43
+ for (const t of ${JSON.stringify(DERIVED_TOKENS)}) {
44
+ const onDeck = deckCs.getPropertyValue(t).trim();
45
+ if (onDeck && onDeck !== cs.getPropertyValue(t).trim()) findings.push({ severity: 'warning', message: t + ' is set on .deck, where base.css overrides it on every slide; set it on .slide' });
46
+ }
47
+ const PROPS = ['color', 'background-color', 'background-image', 'border-left-width', 'border-left-color', 'border-top-width', 'box-shadow',
48
+ 'font-size', 'font-weight', 'font-style', 'text-decoration-line', 'padding-left', 'padding-top', 'text-align', 'opacity', 'letter-spacing', 'text-transform'];
49
+ const look = (el) => { const s = getComputedStyle(el); return PROPS.map((p) => s.getPropertyValue(p)).join('|'); };
50
+ for (const c of ${JSON.stringify(BLOCK_CLASSES)}) {
51
+ const el = document.querySelector('.slide-body p.' + c);
52
+ if (!el) { findings.push({ severity: 'error', message: 'the specimen has no .' + c + ' paragraph' }); continue; }
53
+ const plain = el.closest('.slide').querySelector('.slide-body p:not([class])');
54
+ if (plain && look(el) === look(plain)) findings.push({ severity: 'error', message: '.' + c + ' looks the same as plain text (the theme does not style it)' });
55
+ }
56
+ for (const c of ${JSON.stringify(INLINE_CLASSES)}) {
57
+ const el = document.querySelector('.slide-body p span.' + c);
58
+ if (!el) { findings.push({ severity: 'error', message: 'the specimen has no .' + c + ' span' }); continue; }
59
+ if (look(el) === look(el.parentElement)) findings.push({ severity: 'error', message: '.' + c + ' looks the same as plain text (the theme does not style it)' });
60
+ }
61
+ probe.remove();
62
+ return findings;
63
+ })()`;
64
+ /**
65
+ * For one slide: lists its text runs (elements with their own text), with their text color, size, and the boxes of
66
+ * their text. Gradient-filled text (background-clip: text) reports its gradient's colors and is marked so the
67
+ * background sample can drop the gradient.
68
+ */
69
+ const TEXT_RUNS = (i) => `(() => {
70
+ const slide = document.querySelectorAll('.deck-stage > .slide')[${i}];
71
+ if (slide.classList.contains('has-bg')) return [];
72
+ const runs = [];
73
+ const describe = (el) => el.closest(${JSON.stringify(CHROME)})
74
+ ? (el.closest('.slide-footer') ? 'the footer' : 'the eyebrow') + ' ' + el.tagName.toLowerCase() + (el.className ? '.' + String(el.className).trim().split(/\\s+/).join('.') : '')
75
+ : el.tagName.toLowerCase() + ' "' + (el.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 40) + '"';
76
+ for (const el of slide.querySelectorAll('*')) {
77
+ if (el.closest('.notes, .slide-toc, .has-line-hl .line:not(.line-hl)')) continue;
78
+ // Diagram labels are SVG text, colored by fill and scaled with the diagram.
79
+ const svg = el.closest('svg');
80
+ if (svg && !el.matches('text, tspan')) continue;
81
+ const texts = Array.from(el.childNodes).filter((n) => n.nodeType === 3 && n.textContent.trim());
82
+ if (!texts.length) continue;
83
+ const s = getComputedStyle(el);
84
+ if (s.visibility !== 'visible' || s.display === 'none') continue;
85
+ let alpha = 1;
86
+ for (let a = el; a && a !== slide; a = a.parentElement) alpha *= parseFloat(getComputedStyle(a).opacity);
87
+ if (alpha < .05) continue;
88
+ const rects = [];
89
+ for (const t of texts) {
90
+ const r = document.createRange();
91
+ r.selectNodeContents(t);
92
+ for (const b of r.getClientRects()) if (b.width > 1 && b.height > 1) rects.push([b.left, b.top, b.width, b.height]);
93
+ }
94
+ if (!rects.length) continue;
95
+ const clip = s.webkitBackgroundClip === 'text' || s.backgroundClip === 'text';
96
+ if (clip) el.setAttribute('data-tc-clip', '');
97
+ const fill = s.webkitTextFillColor;
98
+ const color = svg ? s.fill : clip || /^rgba\\(.*,\\s*0\\)$|^transparent$/.test(fill) ? null : (fill && fill !== s.color ? fill : s.color);
99
+ const stops = clip ? (s.backgroundImage.match(/(rgba?|oklch|oklab|color)\\([^)]*\\)/g) || []) : [];
100
+ const vb = svg && svg.viewBox && svg.viewBox.baseVal;
101
+ const scale = vb && vb.width ? svg.getBoundingClientRect().width / vb.width : 1;
102
+ const size = parseFloat(s.fontSize) * scale, weight = parseInt(s.fontWeight, 10);
103
+ runs.push({ what: describe(el), color, stops, alpha, rects, large: size >= 24 || (size >= 18.66 && weight >= 700), quiet: !!el.closest(${JSON.stringify(QUIET)}) });
104
+ }
105
+ return runs;
106
+ })()`;
107
+ /** Hide all text (and gradient text's gradient) so a screenshot shows only what is behind the text. */
108
+ const HIDE_TEXT = `(() => {
109
+ const st = document.createElement('style');
110
+ st.id = 'tc-hide';
111
+ st.textContent = '.deck-stage *, .deck-stage *::before, .deck-stage *::after, .deck-stage *::marker { color: transparent !important; -webkit-text-fill-color: transparent !important; text-shadow: none !important; caret-color: transparent !important; }' +
112
+ ' .deck-stage svg :is(text, tspan) { fill: transparent !important; }' +
113
+ ' .deck-stage [data-tc-clip] { background: none !important; }';
114
+ document.head.appendChild(st);
115
+ })()`;
116
+ /** Contrast of each run against the pixels under it; returns the failures. */
117
+ const MEASURE_CONTRAST = (png, runs) => `(async () => {
118
+ const runs = ${JSON.stringify(runs)};
119
+ const img = new Image();
120
+ img.src = 'data:image/png;base64,${png}';
121
+ await img.decode();
122
+ const cv = document.createElement('canvas');
123
+ cv.width = img.width; cv.height = img.height;
124
+ const ctx = cv.getContext('2d', { willReadFrequently: true });
125
+ ctx.drawImage(img, 0, 0);
126
+ const px = ctx.getImageData(0, 0, cv.width, cv.height).data;
127
+ const one = document.createElement('canvas').getContext('2d', { willReadFrequently: true });
128
+ const rgba = (c) => { one.clearRect(0, 0, 1, 1); one.fillStyle = '#000'; one.fillStyle = c; one.fillRect(0, 0, 1, 1); const d = one.getImageData(0, 0, 1, 1).data; return [d[0], d[1], d[2], d[3] / 255]; };
129
+ const lin = (v) => { v /= 255; return v <= .04045 ? v / 12.92 : Math.pow((v + .055) / 1.055, 2.4); };
130
+ const lum = (r, g, b) => .2126 * lin(r) + .7152 * lin(g) + .0722 * lin(b);
131
+ const hex = (c) => '#' + c.slice(0, 3).map((v) => Math.round(v).toString(16).padStart(2, '0')).join('');
132
+ const out = [];
133
+ for (const run of runs) {
134
+ const colors = (run.color ? [run.color] : run.stops).map(rgba);
135
+ if (!colors.length) continue;
136
+ const ratios = [];
137
+ for (const [x, y, w, h] of run.rects) {
138
+ const step = Math.max(1, Math.floor(Math.min(w, h) / 6));
139
+ for (let yy = Math.max(0, Math.floor(y)); yy < Math.min(cv.height, y + h); yy += step) {
140
+ for (let xx = Math.max(0, Math.floor(x)); xx < Math.min(cv.width, x + w); xx += step) {
141
+ const k = (yy * cv.width + xx) * 4;
142
+ const bg = [px[k], px[k + 1], px[k + 2]];
143
+ // Gradient text is judged by its middle stop: the ends of a shimmer are accents, not the reading color.
144
+ const each = colors.map((c) => {
145
+ const a = c[3] * run.alpha;
146
+ const fg = [0, 1, 2].map((j) => c[j] * a + bg[j] * (1 - a));
147
+ const l1 = lum(fg[0], fg[1], fg[2]), l2 = lum(bg[0], bg[1], bg[2]);
148
+ return [(Math.max(l1, l2) + .05) / (Math.min(l1, l2) + .05), fg];
149
+ }).sort((a, b) => a[0] - b[0]);
150
+ const [ratio, fg] = each[Math.floor((each.length - 1) / 2)];
151
+ ratios.push([ratio, bg, fg]);
152
+ }
153
+ }
154
+ }
155
+ if (!ratios.length) continue;
156
+ // The 10th percentile: the text's harder-to-read part, ignoring a few specks of grain.
157
+ ratios.sort((a, b) => a[0] - b[0]);
158
+ const [ratio, bg, fg] = ratios[Math.floor(ratios.length * .1)];
159
+ const need = run.large ? ${AA_LARGE} : ${AA_TEXT};
160
+ if (ratio < need) out.push({ severity: run.quiet ? 'warning' : 'error',
161
+ message: 'contrast ' + ratio.toFixed(2) + ':1 is below ' + need + ':1 for ' + run.what + ' (' + hex(fg) + (colors.length > 1 ? ' in a gradient' : '') + ' on ' + hex(bg) + ')' });
162
+ }
163
+ return out;
164
+ })()`;
165
+ async function showSlide(cdp, sessionId, i) {
166
+ await evaluate(cdp, sessionId, `(() => { document.querySelectorAll('.deck-stage > .slide').forEach((s, k) => s.classList.toggle('active', k === ${i}));
167
+ return new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))); })()`);
168
+ }
169
+ async function screenshot(cdp, sessionId) {
170
+ return (await cdp.send('Page.captureScreenshot', { format: 'png' }, sessionId)).data;
171
+ }
172
+ /** Render the specimen with a theme in light and dark, and report contract and contrast problems. */
173
+ export async function checkTheme(theme, options = {}) {
174
+ const findings = [];
175
+ let name = theme;
176
+ for (const mode of ['light', 'dark']) {
177
+ const built = buildDeck(SPECIMEN, { theme, mode });
178
+ name = built.theme;
179
+ await withDeckPage(withMermaid(built.html), async (cdp, sessionId) => {
180
+ for (const f of await evaluate(cdp, sessionId, INSPECT))
181
+ findings.push({ mode, ...f });
182
+ const count = built.deck.slides.length;
183
+ if (options.snapshots)
184
+ mkdirSync(options.snapshots, { recursive: true });
185
+ for (let i = 0; i < count; i++) {
186
+ await showSlide(cdp, sessionId, i);
187
+ if (options.snapshots) {
188
+ writeFileSync(path.join(options.snapshots, `${mode}-slide-${String(i + 1).padStart(2, '0')}.png`), Buffer.from(await screenshot(cdp, sessionId), 'base64'));
189
+ }
190
+ const runs = await evaluate(cdp, sessionId, TEXT_RUNS(i));
191
+ if (!runs.length)
192
+ continue;
193
+ await evaluate(cdp, sessionId, HIDE_TEXT);
194
+ await evaluate(cdp, sessionId, `new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))`);
195
+ const png = await screenshot(cdp, sessionId);
196
+ await evaluate(cdp, sessionId, `document.getElementById('tc-hide').remove()`);
197
+ for (const f of await evaluate(cdp, sessionId, MEASURE_CONTRAST(png, runs))) {
198
+ findings.push({ mode, slide: i + 1, title: titleOf(built.deck, i), ...f });
199
+ }
200
+ }
201
+ });
202
+ }
203
+ return { theme: name, findings: merge(findings) };
204
+ }
205
+ const ratio = (f) => parseFloat(/^contrast ([\d.]+):1/.exec(f.message)?.[1] ?? 'Infinity');
206
+ /** One finding per mode and message, listing every slide it appears on. */
207
+ function merge(findings) {
208
+ const byKey = new Map();
209
+ for (const f of findings) {
210
+ // The same element on several slides (footer, eyebrow) over a slightly different background: keep the worst.
211
+ const key = `${f.mode}\0${f.severity}\0${f.message.replace(/^contrast [\d.]+:1 /, '').replace(/ \([^)]*\)$/, '')}`;
212
+ const seen = byKey.get(key);
213
+ if (seen) {
214
+ seen.slides.push(f.slide);
215
+ if (ratio(f) < ratio(seen))
216
+ seen.message = f.message;
217
+ }
218
+ else
219
+ byKey.set(key, { ...f, slides: f.slide ? [f.slide] : [] });
220
+ }
221
+ return [...byKey.values()].map(({ slides, ...f }) => (slides.length > 1 ? { ...f, slide: slides[0], slides, title: undefined } : f));
222
+ }
223
+ /** `theme gold (dark): error: slide 4 "Callouts and marks": contrast 3.10:1 is below 4.5:1 for p "…"` */
224
+ export function formatThemeFinding(theme, f) {
225
+ const where = f.slides ? `slides ${f.slides.join(', ')}: ` : f.slide ? `slide ${f.slide}${f.title ? ` "${f.title}"` : ''}: ` : '';
226
+ return `theme ${theme} (${f.mode}): ${f.severity}: ${where}${f.message}`;
227
+ }
228
+ //# sourceMappingURL=themecheck.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themecheck.js","sourceRoot":"","sources":["../src/themecheck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAY,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,+FAA+F;AAC/F,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;AAe5E,0GAA0G;AAC1G,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,eAAe,CAA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,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAClI,OAAO,SAAS,KAAK,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,QAAQ,KAAK,KAAK,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,29 @@
1
+ ---
2
+ status: accepted
3
+ date: 2026-10-03
4
+ ---
5
+
6
+ # Headless Chrome is the one renderer, driven over the DevTools protocol
7
+
8
+ ## Context
9
+
10
+ Several commands need a real browser: pre-rendering Mermaid diagrams at build time, `deck check`'s measurements, `deck pdf`, and `deck theme check`'s contrast sampling. Decks are viewed in Chromium-based browsers and Apps Script, and printed through Chrome.
11
+
12
+ ## Decision
13
+
14
+ - Chrome is the one renderer the design targets, so the CSS can use modern color functions, `zoom`, and `:has()`.
15
+ - `src/chrome.ts` finds a local Chrome (`CHROME_PATH` overrides), launches it headless, and drives it over the DevTools protocol with Node's built-in WebSocket: no Puppeteer or Playwright dependency.
16
+ - Pages signal readiness with `window.deckReady` (fonts loaded, diagrams rendered), and commands wait on it rather than on timeouts.
17
+ - When Chrome is missing, `deck build` still works and diagrams fall back to rendering in the browser from jsDelivr.
18
+
19
+ ## Consequences
20
+
21
+ - One small driver serves four commands; `withDeckPage` is also how the tests run the editor headlessly.
22
+ - Commands are deterministic: they wait for `deckReady`, not for a time budget.
23
+ - Commands should exit as soon as Chrome does, so agents waiting on `deck check` aren't held by a timer.
24
+
25
+ ## Alternatives considered
26
+
27
+ - **Puppeteer or Playwright:** a large dependency and a downloaded browser for what is a few protocol calls.
28
+ - **Chrome's `--print-to-pdf` / `--screenshot` flags:** see [hybrid PDF](2026-10-03-hybrid-pdf-over-devtools.md); without control over when to capture, they print before diagrams render or never exit.
29
+ - **Render CSS colors at build time in Node:** see [theme colors](2026-10-04-theme-colors-derive-in-css.md).
@@ -0,0 +1,25 @@
1
+ ---
2
+ status: accepted
3
+ date: 2026-10-03
4
+ ---
5
+
6
+ # A fixed 1280×720 canvas
7
+
8
+ ## Context
9
+
10
+ A slide has to look the same in the editor's preview, a browser window of any size, Apps Script's iframe, a phone, and a PDF. Layouts that reflow with the viewport look different on each.
11
+
12
+ ## Decision
13
+
14
+ Slides are always 16:9 and render on a fixed 1280×720 logical canvas, CSS-scaled to the viewport. There is no aspect option. Sizes in the syntax (`w=300`, `h=400`) are canvas px.
15
+
16
+ ## Consequences
17
+
18
+ - A layout looks identical everywhere, and `deck check` measures overflow at the real size.
19
+ - The editor writes canvas px when it resizes or moves images, converting from screen px by the slide's zoom.
20
+ - Portrait phones get a vertical scroll of slides instead of a reflow.
21
+
22
+ ## Alternatives considered
23
+
24
+ - **1920×1080:** 1280×720 matches Marp's default, so sizes in migrated decks mean the same thing; the canvas is scaled anyway, so resolution is unaffected.
25
+ - **An aspect-ratio setting:** every theme and layout would need checking at each ratio.
@@ -0,0 +1,25 @@
1
+ ---
2
+ status: accepted
3
+ date: 2026-10-03
4
+ ---
5
+
6
+ # Four layouts, and attributes for everything else
7
+
8
+ ## Context
9
+
10
+ An early draft had 18 layouts (stats, timeline, cards, agenda, grid, quote, code, …). Each layout is syntax to learn, an inference rule to predict, and styling work in every theme.
11
+
12
+ ## Decision
13
+
14
+ There are four layouts: `content`, `title`, `section`, and `columns [ratio]` (with `=== row` for bands of columns). Other kinds of slide come from attributes and plain Markdown: `{side=right}` on an image makes a split slide, `{bg}` a full-bleed image slide, `{.lead}` or `{.center}` a statement slide, and a column opening with `###` a card. Classes come from a fixed semantic vocabulary that every theme styles.
15
+
16
+ ## Consequences
17
+
18
+ - Every deck works under every theme, since a theme only has to style four layouts and a known set of classes. Themes compete on how they render the same layouts.
19
+ - Most of the dropped layouts were a Markdown element a theme can style directly (code, quotes, lists) or something an attribute already covers.
20
+ - A slide that needs a new arrangement asks for an attribute or class, which is reviewed once for all themes.
21
+
22
+ ## Alternatives considered
23
+
24
+ - **A rich layout catalog:** see Context. Four layouts plus attributes covered all the existing decks.
25
+ - **A `.takeaway` class pinned to the slide bottom** (replacing a Marp deck's custom div): it split attention between the title and the bottom of the slide, so the title carries the message instead. Using it is a build error.
@@ -0,0 +1,25 @@
1
+ ---
2
+ status: accepted
3
+ date: 2026-10-03
4
+ ---
5
+
6
+ # Hybrid PDF: backgrounds as images, content as vectors
7
+
8
+ ## Context
9
+
10
+ A PDF of a deck has to look like the HTML in every viewer, including Apple's (Preview, Quick Look), while text stays sharp and selectable.
11
+
12
+ ## Decision
13
+
14
+ `deck pdf` loads the built page in headless Chrome over the DevTools protocol, waits for `deckReady`, and for each slide screenshots the background layer at 2× with the content hidden (`.deck.is-capture`), installing it as that slide's print background. Text, tables, code, images, and diagrams then print as vectors on top with `Page.printToPDF`, one 1280×720 page per slide. Print CSS removes blurred shadows and filters, freezes animations, and paints table-header gradients as one strip. `--vector` skips the capture.
15
+
16
+ ## Consequences
17
+
18
+ - PDFs match the HTML in every viewer, text stays selectable, and files are roughly half the size of pure-vector output (1.4–5.5 MB for the 27-slide tour, down from 7.5–12 MB).
19
+ - A PDF takes a few seconds per deck, since every slide is captured.
20
+
21
+ ## Alternatives considered
22
+
23
+ - **Pure vector PDF:** looks right in Chrome's viewer but not in Apple's: blurred shadows become soft-mask images that Quartz draws as dark gray boxes, large translucent gradients band into tiles, and per-cell header gradients show seams.
24
+ - **Chrome `--print-to-pdf` from the command line:** with `--virtual-time-budget` (needed for Mermaid) headless Chrome never exits, because infinite CSS animations keep virtual time from settling; without it, it prints before diagrams render.
25
+ - **Printing from the browser:** kept as a convenience (share panel → Print), but gradients may band.
@@ -0,0 +1,36 @@
1
+ ---
2
+ status: accepted
3
+ date: 2026-10-03
4
+ ---
5
+
6
+ # Slides are divided by keyword lines, styled by one `{…}` syntax
7
+
8
+ ## Context
9
+
10
+ The Marp decks this project replaces needed raw HTML for anything beyond one column: one deck had 9 `<div class="columns">` blocks with 18 nested `<div>`s, `<center>` around images, and `<p class="subtitle">` for title styling. That HTML is also what broke Treasure Work's note editor round trip (treasure-work PR #1866). Slides, columns, notes, and styling need a syntax that reads as text, survives other Markdown tools, and can be validated.
11
+
12
+ ## Decision
13
+
14
+ - `---` divides the deck into slides; `--- <layout> <args> {attrs}` also sets the next slide's layout and attributes.
15
+ - `===` plus a keyword divides a slide: `=== col`, `=== row`, `=== notes`, with the same `{…}` attributes.
16
+ - Both are lines of their own, split off before Markdown parsing and outside fenced code.
17
+ - `{…}` after a block, image, or `[span]` (markdown-it-attrs) carries every class, `key=value`, and flag. There is no second syntax for images or slides.
18
+ - Configuration lives in the frontmatter; there is no separate manifest.
19
+
20
+ ## Consequences
21
+
22
+ - Each visual property is written in exactly one place in the source. This is what makes exact visual editing possible ([edits are line-range patches](2026-10-04-edits-are-line-range-patches.md)).
23
+ - In GitHub or editor previews the separators show as plain text, which keeps the structure visible.
24
+ - A bare `===` stays a setext underline and `=== col` inside a sentence is text, so ordinary Markdown is unaffected.
25
+ - One attribute syntax means one validator: unknown keys and classes are build errors.
26
+
27
+ ## Alternatives considered
28
+
29
+ - **Keep Marp:** layouts need `<div>` markup and per-slide classes are HTML comments; its theme model has no layout concept for themes to restyle.
30
+ - **Pandoc fenced divs (`:::: columns` / `::: column`):** div markup with other punctuation, colon counting for nesting, and four fence lines per two-column slide.
31
+ - **Bare symbol lines (`+++`, `===`, `???`, `Notes:`):** cryptic; a bare `===` is a setext H1 underline, and `+++` means TOML frontmatter in Hugo.
32
+ - **Bracketed keywords (`[col]`, `[notes]`, version 0.1):** read as link text, and `[col {.muted}]` looked like a `[span]{.hl}`. The old lines fail the build with the new spelling.
33
+ - **`##` headings as column breaks:** can't express a column without a heading, and would turn stacked subheadings into columns.
34
+ - **HTML comments for notes:** the markup this design avoids.
35
+ - **Marp alt-text keywords for images (`![w:200 bg]`):** only works for images, so blocks and slides would still need another syntax.
36
+ - **A `deck.yaml` manifest:** a second file to keep in sync, for nothing the frontmatter can't hold.
@@ -0,0 +1,30 @@
1
+ ---
2
+ status: accepted
3
+ date: 2026-10-03
4
+ ---
5
+
6
+ # One built-in behavior instead of settings
7
+
8
+ ## Context
9
+
10
+ Presentation tools accumulate settings: transitions, page-number visibility, language, aspect ratio, section dividers. Each one is a choice an author (or Claude) has to make and a combination themes have to support.
11
+
12
+ ## Decision
13
+
14
+ Where one behavior serves talks well, it is built in with no setting:
15
+
16
+ - Slides switch instantly. Themes used to animate changes (gold slid up, the others faded); the motion distracted from content, so themes no longer define transitions.
17
+ - Page numbers show on every slide except title and section slides.
18
+ - Slides containing Japanese get `lang="ja"` (Japanese line breaking and a fallback font), detected from the text.
19
+ - Section divider slides are hidden by default, as in Beamer, where `\section` names a part of the talk without adding a frame: the eyebrow above each title already names the section. `{show}`, `section_slides: true`, and `{nonum}` are the exceptions that proved necessary.
20
+
21
+ ## Consequences
22
+
23
+ - The frontmatter stays short, and a deck renders the same everywhere.
24
+ - Hidden dividers are dropped before numbering, so page numbers and deep links count only the slides on screen.
25
+ - A setting is added only when a real deck needs the other behavior.
26
+
27
+ ## Alternatives considered
28
+
29
+ - **Per-theme transitions:** removed; see above.
30
+ - **A section slide for every `--- section`:** mostly a title-only slide that repeats the eyebrow.
@@ -0,0 +1,27 @@
1
+ ---
2
+ status: accepted
3
+ date: 2026-10-03
4
+ ---
5
+
6
+ # Overflow is reported, not hidden
7
+
8
+ ## Context
9
+
10
+ Text that doesn't fit a slide has to go somewhere. Many tools shrink it automatically. Auto-shrunk slides make a deck uneven, small text fails at the back of the room, and nobody notices until the talk. Decks are also increasingly written by Claude, which can't see a slide unless something renders it.
11
+
12
+ ## Decision
13
+
14
+ - Text has one size per theme and never shrinks on its own.
15
+ - `deck check` renders every slide in headless Chrome at 1280×720 and reports, with source lines: content past the slide body, text wider than its box, clipped code, failed diagrams; and as warnings, code shrunk below 14px, diagram labels below 13px, and title-only slides. It exits 1 on errors.
16
+ - `--- {fit}` opts one slide in to shrinking: the runtime binary-searches the largest CSS `zoom` on the body (not the title) at which nothing overflows, never below 14px text, and `deck check` warns below 16px.
17
+ - The one automatic exception is code: a block wider than its panel shrinks down to 12px instead of clipping, since a clipped line loses content.
18
+
19
+ ## Consequences
20
+
21
+ - `deck check` (with `--snapshots` to look at the slides) is the verification loop the bundled skill requires before Claude calls a deck done.
22
+ - Dense slides are a visible, deliberate choice in the source.
23
+
24
+ ## Alternatives considered
25
+
26
+ - **Shrink to fit by default:** see Context.
27
+ - **Scrollable slides:** don't exist when presenting or in a PDF.
@@ -0,0 +1,26 @@
1
+ ---
2
+ status: accepted
3
+ date: 2026-10-03
4
+ ---
5
+
6
+ # A deck builds to one self-contained HTML file
7
+
8
+ ## Context
9
+
10
+ Decks are shared as links (Treasure Work publishes them as Apps Script web apps, which deploy a single `index.html`), opened from disk, embedded in Google Sites, and printed. Marp exported HTML and PDF separately, and the HTML had to be shared by hand.
11
+
12
+ ## Decision
13
+
14
+ `deck build` writes one HTML file with the CSS, the runtime (vanilla JS, no framework), the images, and pre-rendered Mermaid SVGs inlined. Fonts load from Google Fonts. The same file runs as a local file, in Treasure Work's preview, and under Apps Script, through a small `Host` adapter in the runtime (deep links use `google.script.history` there).
15
+
16
+ ## Consequences
17
+
18
+ - Publishing is one file; republishing keeps the URL.
19
+ - Image-heavy decks make large files; HtmlService's size limits still need measuring.
20
+ - The runtime handles everything a presenter needs (overview, notes, presenter window, share panel) without a server.
21
+
22
+ ## Alternatives considered
23
+
24
+ - **Slidev:** Vue components and a Vite SPA build, with multi-file output that doesn't fit a single-`index.html` deployment.
25
+ - **reveal.js Markdown:** attributes in `<!-- .element: … -->` comments, layouts still in HTML, and a heavier runtime.
26
+ - **Generate Google Slides:** loses generated backgrounds, live diagrams, and the pixel-exact canvas. It could come later as a secondary target.
@@ -0,0 +1,31 @@
1
+ ---
2
+ status: accepted
3
+ date: 2026-10-03
4
+ ---
5
+
6
+ # Strict build, forgiving preview
7
+
8
+ Amended 2026-10-04 (forgiving preview, `plans/2026-10-04-slide-errors.md`).
9
+
10
+ ## Context
11
+
12
+ A typo in a class or attribute that is silently ignored reaches the audience as a wrongly styled slide. But while a deck is being typed, it is broken most of the time: a half-typed header or a missing image would take the whole preview away.
13
+
14
+ ## Decision
15
+
16
+ - **Strict:** an unknown layout, attribute, class, separator, or a missing image is a build error with its line number. `deck build`, `deck pdf`, and `deck check` fail on the first one.
17
+ - **Forgiving in the preview:** `deck dev` and `deck editor` build with `forgiving: true`. A slide that can't be parsed or rendered becomes an error slide in its place, showing the message, its line, and its source, and every other slide builds as usual. An error outside the slides (frontmatter, theme) keeps the last good build on screen with the error in a bar.
18
+
19
+ ## Consequences
20
+
21
+ - Typos never reach a shared deck or a PDF.
22
+ - An error appears and goes away by swapping one slide, so a half-typed edit never takes the preview away, and the host can mark the line in its gutter (`build-error` with `slide`).
23
+ - An unclosed code fence is reported at its opening line, since it would otherwise swallow every later slide.
24
+
25
+ ## Alternatives considered
26
+
27
+ - **Ignore unknown attributes:** see Context.
28
+ - **Forgiving everywhere, with warnings:** a shared deck or PDF with an error slide in it is worse than a failed build.
29
+ - **Keep the last good version of the broken slide:** it would show content that isn't in the file, and edits on it would patch lines that no longer read that way.
30
+ - **Skip the broken slide:** renumbers the rest, and the error is easy to miss.
31
+ - **An error bar only:** the preview would freeze on the last good deck, so edits to other slides wouldn't show.