@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
package/dist/parse.js ADDED
@@ -0,0 +1,313 @@
1
+ import { parse as parseYaml } from 'yaml';
2
+ export const LAYOUTS = ['content', 'title', 'section', 'columns'];
3
+ export class DeckError extends Error {
4
+ detail;
5
+ line;
6
+ file;
7
+ constructor(
8
+ /** The message without its location. */
9
+ detail, line,
10
+ /** A `parts:` file, relative to the deck's folder; absent for the deck file itself. */
11
+ file) {
12
+ super(line ? `${file ? `${file}:${line}` : `line ${line}`}: ${detail}` : detail);
13
+ this.detail = detail;
14
+ this.line = line;
15
+ this.file = file;
16
+ this.name = 'DeckError';
17
+ }
18
+ }
19
+ const FENCE = /^(\s{0,3})(`{3,}|~{3,})/;
20
+ const SLIDE_BREAK = /^---(?:\s+(.*))?$/;
21
+ /**
22
+ * A separator inside a slide: `=== col`, `=== col {.class}`, `=== row 2:1 {.class}`, `=== notes`. A bare `===` stays
23
+ * Markdown (a setext heading).
24
+ */
25
+ const SEPARATOR = /^===\s+([A-Za-z]\w*)(?:\s+(\d+(?::\d+)+))?\s*(?:\{(.*)\})?$/;
26
+ /** The bracketed keywords of earlier versions, e.g. `[col]`, `[notes]`. */
27
+ const OLD_KEYWORD = /^\[(col|notes)(?:\s+\{(.*)\})?\]$/;
28
+ /** Split frontmatter from the body. Returns the body's starting line (1-based). */
29
+ export function splitFrontmatter(source) {
30
+ const lines = source.split(/\r?\n/);
31
+ if (lines[0] !== '---')
32
+ return { meta: {}, body: source, bodyLine: 1 };
33
+ const end = lines.indexOf('---', 1);
34
+ if (end < 0)
35
+ throw new DeckError('frontmatter is not closed with ---', 1);
36
+ const meta = (parseYaml(lines.slice(1, end).join('\n')) ?? {});
37
+ return { meta, body: lines.slice(end + 1).join('\n'), bodyLine: end + 2 };
38
+ }
39
+ /**
40
+ * Split the body into slides on `---` lines outside fenced code. A forgiving split (`unclosed`) reads the opening
41
+ * line of a fence that is never closed as text, so the slides after it still split, and reports the slide it is in.
42
+ */
43
+ function splitSlides(body, bodyLine, file, unclosed) {
44
+ const slides = [];
45
+ let current = { line: bodyLine, file, lines: [] };
46
+ let fence;
47
+ let fenceLine = 0;
48
+ const lines = body.split(/\r?\n/);
49
+ // A final line break ends the last line; it doesn't start an empty one.
50
+ if (lines.length > 1 && lines[lines.length - 1] === '')
51
+ lines.pop();
52
+ lines.forEach((text, i) => {
53
+ const line = bodyLine + i;
54
+ const f = unclosed?.has(line) ? null : FENCE.exec(text);
55
+ if (fence) {
56
+ if (f && f[2][0] === fence[0] && f[2].length >= fence.length && text.trim() === f[2])
57
+ fence = undefined;
58
+ current.lines.push({ text, line });
59
+ return;
60
+ }
61
+ if (f) {
62
+ fence = f[2];
63
+ fenceLine = line;
64
+ current.lines.push({ text, line });
65
+ return;
66
+ }
67
+ const brk = SLIDE_BREAK.exec(text);
68
+ if (brk) {
69
+ const hasContent = current.lines.some((l) => l.text.trim() !== '');
70
+ // A header before any content configures the current (first) slide instead of opening an empty one.
71
+ if (hasContent || current.header !== undefined) {
72
+ slides.push(current);
73
+ current = { line, file, lines: [] };
74
+ }
75
+ current.line = line;
76
+ current.header = brk[1]?.trim() ?? '';
77
+ return;
78
+ }
79
+ current.lines.push({ text, line });
80
+ });
81
+ if (fence) {
82
+ if (!unclosed)
83
+ throw new DeckError('fenced code block is not closed', fenceLine, file);
84
+ unclosed.add(fenceLine);
85
+ return splitSlides(body, bodyLine, file, unclosed);
86
+ }
87
+ // A `---` always makes a slide, even an empty one at the end (a slide just started in the editor).
88
+ if (current.lines.some((l) => l.text.trim() !== '') || current.header !== undefined)
89
+ slides.push(current);
90
+ for (const l of unclosed ?? []) {
91
+ const at = slides.find((s) => s.lines.some((x) => x.line === l));
92
+ if (at && !at.error)
93
+ at.error = new DeckError('fenced code block is not closed', l, file);
94
+ }
95
+ return slides;
96
+ }
97
+ /** Parse `columns 3:2 {bg=x .dark}` into its parts. */
98
+ export function parseHeader(header, line) {
99
+ let attrs = '';
100
+ const brace = header.indexOf('{');
101
+ let head = header;
102
+ if (brace >= 0) {
103
+ if (!header.trimEnd().endsWith('}'))
104
+ throw new DeckError(`unclosed {…} in slide header: ${header}`, line);
105
+ attrs = header.slice(brace + 1, header.trimEnd().length - 1).trim();
106
+ head = header.slice(0, brace);
107
+ }
108
+ const [name, ...args] = head.trim().split(/\s+/).filter(Boolean);
109
+ if (name === undefined)
110
+ return { args, attrs };
111
+ if (!LAYOUTS.includes(name)) {
112
+ throw new DeckError(`unknown layout "${name}" (expected one of: ${LAYOUTS.join(', ')})`, line);
113
+ }
114
+ return { layout: name, args, attrs };
115
+ }
116
+ function parseRatio(args, line) {
117
+ if (args.length === 0)
118
+ return undefined;
119
+ if (args.length > 1 || !/^\d+(:\d+)+$/.test(args[0])) {
120
+ throw new DeckError(`columns takes one ratio like 3:2 or 1:1:1, got "${args.join(' ')}"`, line);
121
+ }
122
+ return args[0].split(':').map(Number);
123
+ }
124
+ /** The lines without blank lines around them, and the source line the result starts on. */
125
+ function trimBlank(lines) {
126
+ const first = lines.findIndex((l) => l.text.trim() !== '');
127
+ if (first < 0)
128
+ return { text: '', line: lines[0]?.line ?? 0 };
129
+ return { text: lines.slice(first).map((l) => l.text).join('\n').trimEnd(), line: lines[first].line };
130
+ }
131
+ function buildSlide(raw, number) {
132
+ const { layout: declared, args, attrs } = parseHeader(raw.header ?? '', raw.line);
133
+ const columns = [{ attrs: '', markdown: '', line: raw.line }];
134
+ const colLines = [[]];
135
+ // Each row's ratio as written, kept for the warning when it doesn't match the row's columns.
136
+ const rows = [{ start: 0, attrs: '', line: raw.line }];
137
+ const notes = [];
138
+ let inNotes = false;
139
+ let fence;
140
+ for (const source of raw.lines) {
141
+ const { text, line } = source;
142
+ const f = FENCE.exec(text);
143
+ if (fence) {
144
+ if (f && text.trim() === f[2] && f[2][0] === fence[0] && f[2].length >= fence.length)
145
+ fence = undefined;
146
+ }
147
+ else if (f) {
148
+ fence = f[2];
149
+ }
150
+ else if (OLD_KEYWORD.test(text.trim())) {
151
+ const [, word, colAttrs] = OLD_KEYWORD.exec(text.trim());
152
+ throw new DeckError(`[${word}] is now written === ${word}${colAttrs ? ` {${colAttrs}}` : ''}`, line);
153
+ }
154
+ else if (SEPARATOR.test(text.trim())) {
155
+ const [, word, sepRatio, sepAttrs] = SEPARATOR.exec(text.trim());
156
+ if (sepRatio !== undefined && word !== 'row') {
157
+ throw new DeckError(`=== ${word} takes no ratio${word === 'col' ? ' (widths go on the slide header, --- columns 3:2, or on === row 3:2)' : ''}`, line);
158
+ }
159
+ if (word === 'notes') {
160
+ if (inNotes)
161
+ throw new DeckError('=== notes appears twice in one slide', line);
162
+ if (sepAttrs !== undefined)
163
+ throw new DeckError('=== notes takes no attributes', line);
164
+ inNotes = true;
165
+ continue;
166
+ }
167
+ if (word === 'col' || word === 'row') {
168
+ if (inNotes)
169
+ throw new DeckError(`=== ${word} cannot follow === notes (notes run to the end of the slide)`, line);
170
+ columns.push({ attrs: word === 'col' ? sepAttrs?.trim() ?? '' : '', markdown: '', line });
171
+ colLines.push([]);
172
+ if (word === 'row') {
173
+ rows.push({ start: columns.length - 1, attrs: sepAttrs?.trim() ?? '', line, ratio: sepRatio?.split(':').map(Number), written: sepRatio });
174
+ }
175
+ continue;
176
+ }
177
+ const guess = word.startsWith('note') ? 'did you mean === notes?' : word.startsWith('col') ? 'did you mean === col?' : word.startsWith('row') ? 'did you mean === row?' : 'allowed: === col, === row, === notes';
178
+ throw new DeckError(`unknown separator === ${word} (${guess})`, line);
179
+ }
180
+ (inNotes ? notes : colLines[colLines.length - 1]).push(source);
181
+ }
182
+ colLines.forEach((lines, i) => {
183
+ const { text, line } = trimBlank(lines);
184
+ columns[i].markdown = text;
185
+ if (text)
186
+ columns[i].line = line;
187
+ });
188
+ const hasColumns = columns.length > 1;
189
+ const layout = declared ?? (hasColumns ? 'columns' : 'content');
190
+ if (hasColumns && layout !== 'columns') {
191
+ const word = rows.length > 1 ? 'row' : 'col';
192
+ throw new DeckError(`=== ${word} is only allowed in a columns slide (this slide is "${layout}")`, raw.line);
193
+ }
194
+ if (layout !== 'columns' && args.length > 0) {
195
+ throw new DeckError(`layout "${layout}" takes no arguments`, raw.line);
196
+ }
197
+ if (layout === 'columns')
198
+ rows[0].ratio = parseRatio(args, raw.line);
199
+ rows[0].written = args[0];
200
+ // Take out column i: the rows after it start one earlier, and a row it leaves empty goes (its ratio, if it is the
201
+ // first, passes to the next row that has none).
202
+ const dropColumn = (i) => {
203
+ columns.splice(i, 1);
204
+ const r = rows.findIndex((row, k) => row.start === i && (rows[k + 1]?.start ?? columns.length + 1) === i + 1);
205
+ if (r >= 0) {
206
+ const [gone] = rows.splice(r, 1);
207
+ if (r === 0 && rows.length && !rows[0].ratio)
208
+ Object.assign(rows[0], { ratio: gone.ratio, written: gone.written });
209
+ }
210
+ for (const row of rows)
211
+ if (row.start > i)
212
+ row.start--;
213
+ };
214
+ // A heading that opens a content or columns slide becomes the slide header (spanning all columns).
215
+ let header;
216
+ let headerLine;
217
+ if (layout === 'columns' || layout === 'content') {
218
+ const first = columns[0].markdown.split('\n');
219
+ if (/^#{1,2}\s/.test(first[0] ?? '')) {
220
+ header = first[0];
221
+ headerLine = columns[0].line;
222
+ const rest = trimBlank(first.slice(1).map((text, i) => ({ text, line: headerLine + 1 + i })));
223
+ columns[0].markdown = rest.text;
224
+ columns[0].line = rest.text ? rest.line : headerLine;
225
+ // `# Title` alone before the first === col is a header, not an empty column.
226
+ if (columns[0].markdown === '' && columns.length > 1)
227
+ dropColumn(0);
228
+ }
229
+ }
230
+ // An empty first row (`=== row` right after the header, or at the top) is not a row.
231
+ if (rows.length > 1 && rows[1].start === 1 && columns[0].markdown === '')
232
+ dropColumn(0);
233
+ const warnings = [];
234
+ // A ratio for another number of columns (a column just added or taken out) still lays out the columns there are:
235
+ // its first parts, then 1 for each column more.
236
+ rows.forEach((row, k) => {
237
+ const count = (rows[k + 1]?.start ?? columns.length) - row.start;
238
+ if (!row.ratio || row.ratio.length === count)
239
+ return;
240
+ const where = rows.length > 1 ? `row ${k + 1}` : 'the slide';
241
+ warnings.push(`ratio ${row.written} has ${row.ratio.length} parts but ${where} has ${count} column${count === 1 ? '' : 's'}`);
242
+ const ratio = row.ratio;
243
+ row.ratio = count > 1 ? Array.from({ length: count }, (_, i) => ratio[i] ?? 1) : undefined;
244
+ });
245
+ const ratio = rows[0].ratio;
246
+ const slideRows = rows.length > 1 ? rows.map(({ written: _, ...row }) => row) : undefined;
247
+ const note = trimBlank(notes);
248
+ const end = raw.lines.length ? raw.lines[raw.lines.length - 1].line : raw.line;
249
+ return {
250
+ number, line: raw.line, end, file: raw.file, layout, ratio, ...(slideRows ? { rows: slideRows } : {}), attrs, header, headerLine, columns,
251
+ notes: note.text || undefined, notesLine: note.text ? note.line : undefined,
252
+ ...(warnings.length ? { warnings } : {}),
253
+ };
254
+ }
255
+ /**
256
+ * A slide that shows `error` instead of its content: a content slide over the same lines, without a heading
257
+ * (so it opens no section and has no title in the table of contents).
258
+ */
259
+ export function errorSlide(slide, error) {
260
+ const { number, line, end, file } = slide;
261
+ return { number, line, end, file, layout: 'content', attrs: '', columns: [{ attrs: '', markdown: '', line }], error };
262
+ }
263
+ /** A DeckError from a `parts:` file, located in that file (errors carry only a line until then). */
264
+ export function inFile(e, file) {
265
+ return file && e instanceof DeckError && e.line && !e.file ? new DeckError(e.detail, e.line, file) : e;
266
+ }
267
+ /**
268
+ * Parse a deck. `parts` continue the slide stream after the deck's own slides, each from its own file with its own
269
+ * line numbers; a part that doesn't open with a slide break starts a new slide.
270
+ */
271
+ export function parseDeck(source, parts = [], options = {}) {
272
+ const { meta, body, bodyLine } = splitFrontmatter(source);
273
+ const theme = typeof meta.theme === 'string' ? meta.theme : 'default';
274
+ const mode = meta.mode;
275
+ if (mode !== undefined && mode !== 'light' && mode !== 'dark') {
276
+ throw new DeckError(`mode must be light or dark, got "${String(mode)}"`);
277
+ }
278
+ if (meta.section_slides !== undefined && typeof meta.section_slides !== 'boolean') {
279
+ throw new DeckError(`section_slides must be true or false, got "${String(meta.section_slides)}"`);
280
+ }
281
+ if (meta.toc !== undefined && meta.toc !== 'sidebar') {
282
+ throw new DeckError(`toc must be sidebar, got "${String(meta.toc)}"`);
283
+ }
284
+ const unclosed = () => (options.forgiving ? new Set() : undefined);
285
+ const raws = [splitSlides(body, bodyLine, undefined, unclosed()), ...parts.map((p) => splitSlides(p.text, 1, p.file, unclosed()))].flat();
286
+ const slides = raws.map((raw, i) => {
287
+ const end = raw.lines.length ? raw.lines[raw.lines.length - 1].line : raw.line;
288
+ if (raw.error)
289
+ return errorSlide({ number: i + 1, line: raw.line, end, file: raw.file }, raw.error);
290
+ try {
291
+ return buildSlide(raw, i + 1);
292
+ }
293
+ catch (e) {
294
+ const located = inFile(e, raw.file);
295
+ if (!options.forgiving || !(located instanceof DeckError))
296
+ throw located;
297
+ return errorSlide({ number: i + 1, line: raw.line, end, file: raw.file }, located);
298
+ }
299
+ });
300
+ if (slides.length === 0)
301
+ throw new DeckError('the deck has no slides');
302
+ return {
303
+ meta: {
304
+ ...meta,
305
+ theme,
306
+ mode,
307
+ title: meta.title,
308
+ date: meta.date instanceof Date ? meta.date.toISOString().slice(0, 10) : meta.date,
309
+ },
310
+ slides,
311
+ };
312
+ }
313
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAwE3E,MAAM,OAAO,SAAU,SAAQ,KAAK;IAGvB,MAAM;IACN,IAAI;IAEJ,IAAI;IALf;IACE,wCAAwC;IAC/B,MAAc,EACd,IAAa;IACtB,uFAAuF;IAC9E,IAAa;QAEtB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;sBALxE,MAAM;oBACN,IAAI;oBAEJ,IAAI;QAGb,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,KAAK,GAAG,yBAAyB,CAAC;AACxC,MAAM,WAAW,GAAG,mBAAmB,CAAC;AACxC;;;GAGG;AACH,MAAM,SAAS,GAAG,6DAA6D,CAAC;AAChF,2EAA2E;AAC3E,MAAM,WAAW,G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CAAC,IAA2B;SAC3G;QACD,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A visual edit as a change to a line range: replace lines `start..end` (1-based, inclusive) with `text`, but only
3
+ * while they still read `expected`. `end = start - 1` inserts before line `start`; `text: null` deletes the lines.
4
+ * Bytes outside the range are never touched, so the rest of the deck stays exactly as written.
5
+ */
6
+ export interface Patch {
7
+ file: string;
8
+ start: number;
9
+ end: number;
10
+ /** The current text of the lines, joined with `\n` (empty for an insert). */
11
+ expected: string;
12
+ /** Replacement lines joined with `\n`, written with the file's line endings; null deletes the lines. */
13
+ text: string | null;
14
+ }
15
+ export type PatchResult = {
16
+ ok: true;
17
+ source: string;
18
+ } | {
19
+ ok: false;
20
+ reason: string;
21
+ };
22
+ export declare function applyPatch(source: string, patch: Patch): PatchResult;
package/dist/patch.js ADDED
@@ -0,0 +1,53 @@
1
+ /** Offsets of each line's start, and of each line's end before its line break. A final line break ends the last line. */
2
+ function lineSpans(source) {
3
+ const spans = [];
4
+ const re = /\r?\n/g;
5
+ let start = 0;
6
+ for (let m = re.exec(source); m; m = re.exec(source)) {
7
+ spans.push({ start, end: m.index });
8
+ start = m.index + m[0].length;
9
+ }
10
+ if (start < source.length || spans.length === 0)
11
+ spans.push({ start, end: source.length });
12
+ return spans;
13
+ }
14
+ export function applyPatch(source, patch) {
15
+ const { start, end, expected, text } = patch;
16
+ const spans = lineSpans(source);
17
+ const count = source === '' ? 0 : spans.length;
18
+ const eol = /\r\n/.test(source) ? '\r\n' : '\n';
19
+ const endsWithEol = /\n$/.test(source);
20
+ if (!Number.isInteger(start) || !Number.isInteger(end) || start < 1 || end < start - 1 || end > count) {
21
+ return { ok: false, reason: `lines ${start}-${end} are outside the file (${count} lines)` };
22
+ }
23
+ const withEol = (t) => t.replace(/\r?\n/g, eol);
24
+ if (end === start - 1) {
25
+ if (expected !== '')
26
+ return { ok: false, reason: 'an insert expects no current text' };
27
+ if (text === null)
28
+ return { ok: false, reason: 'an insert needs text' };
29
+ if (start <= count) {
30
+ const at = spans[start - 1].start;
31
+ return { ok: true, source: source.slice(0, at) + withEol(text) + eol + source.slice(at) };
32
+ }
33
+ // After the last line: keep the file's final line break, or its lack of one.
34
+ if (source === '' || endsWithEol)
35
+ return { ok: true, source: source + withEol(text) + (endsWithEol ? eol : '') };
36
+ return { ok: true, source: source + eol + withEol(text) };
37
+ }
38
+ const from = spans[start - 1].start;
39
+ const to = spans[end - 1].end;
40
+ const current = source.slice(from, to).replace(/\r\n/g, '\n');
41
+ if (current !== expected)
42
+ return { ok: false, reason: `lines ${start}-${end} changed since the preview was built` };
43
+ if (text !== null)
44
+ return { ok: true, source: source.slice(0, from) + withEol(text) + source.slice(to) };
45
+ // Delete the lines with their line break: the one after them, or before them at the end of a file without one.
46
+ if (end < count)
47
+ return { ok: true, source: source.slice(0, from) + source.slice(spans[end].start) };
48
+ if (endsWithEol)
49
+ return { ok: true, source: source.slice(0, from) };
50
+ const cut = start > 1 ? spans[start - 2].end : from;
51
+ return { ok: true, source: source.slice(0, cut) + source.slice(to) };
52
+ }
53
+ //# sourceMappingURL=patch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch.js","sourceRoot":"","sources":["../src/patch.ts"],"names":[],"mappings":"AAiBA,yHAAyH;AACzH,SAAS,SAAS,CAAC,MAAc;IAC/B,MAAM,KAAK,GAAqC,EAAE,CAAC;IACnD,MAAM,EAAE,GAAG,QAAQ,CAAC;IACpB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACrD,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACpC,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,C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,EAAE,MAAM,EAAE,SAAS,KAAK,IAAI,GAAG,sCAAsC,EAAE,CAAC;IACpH,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;IACzG,+GAA+G;IAC/G,IAAI,GAAG,GAAG,KAAK;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;IACrG,IAAI,WAAW;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;IACpE,MAAM,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IACpD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;AACvE,CAAC"}
package/dist/pdf.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Print a built deck to PDF with headless Chrome: load the page, wait for `window.deckReady` (fonts and
3
+ * Mermaid diagrams rendered), then print with backgrounds at the CSS page size (one 1280×720 page per slide).
4
+ */
5
+ export interface PdfOptions {
6
+ timeoutMs?: number;
7
+ /** Capture each slide's background layer as an image (default true); false prints every layer as vectors. */
8
+ rasterBackground?: boolean;
9
+ }
10
+ export declare function printPdf(html: string, outFile: string, options?: PdfOptions): Promise<void>;
package/dist/pdf.js ADDED
@@ -0,0 +1,53 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import { evaluate, withDeckPage } from './chrome.js';
3
+ /**
4
+ * Photograph each slide's background layer (gradients, glass, ornaments; content hidden) at 2× and install it as
5
+ * the slide's print background. Large translucent gradients and blurs don't survive PDF faithfully (Apple's renderer
6
+ * bands them), so they ship as images while text, tables, code, and diagrams stay vector on top.
7
+ */
8
+ async function captureBackgrounds(cdp, sessionId) {
9
+ await cdp.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 720, deviceScaleFactor: 2, mobile: false }, sessionId);
10
+ const count = await evaluate(cdp, sessionId, `(() => { window.dispatchEvent(new Event('resize')); document.querySelector('.deck').classList.add('is-capture');
11
+ return document.querySelectorAll('.deck-stage > .slide').length; })()`);
12
+ const frame = 'new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))';
13
+ for (let i = 0; i < count; i++) {
14
+ await evaluate(cdp, sessionId, `(() => { document.querySelectorAll('.deck-stage > .slide').forEach((s, k) => s.classList.toggle('active', k === ${i}));
15
+ return ${frame}; })()`);
16
+ const { data } = await cdp.send('Page.captureScreenshot', { format: 'jpeg', quality: 88, clip: { x: 0, y: 0, width: 1280, height: 720, scale: 1 }, captureBeyondViewport: false }, sessionId);
17
+ await evaluate(cdp, sessionId, `document.querySelectorAll('.deck-stage > .slide')[${i}].style.setProperty('--print-bg', 'url("data:image/jpeg;base64,${data}")')`);
18
+ }
19
+ await evaluate(cdp, sessionId, `(() => { const d = document.querySelector('.deck'); d.classList.remove('is-capture'); d.classList.add('has-print-bg'); })()`);
20
+ await cdp.send('Emulation.clearDeviceMetricsOverride', {}, sessionId);
21
+ }
22
+ /**
23
+ * Load every video's first frame, which is what prints (a video loads only its metadata until it plays), with the
24
+ * video stopped there, and take its play bar off, which would print too.
25
+ */
26
+ async function firstFrames(cdp, sessionId) {
27
+ await evaluate(cdp, sessionId, `Promise.all([...document.querySelectorAll('.deck-stage video')].map(async (v) => {
28
+ // The runtime may have started an {autoplay} video on the first slide: stop it, and keep it from starting.
29
+ v.removeAttribute('data-autoplay');
30
+ await v.settling;
31
+ v.pause();
32
+ v.controls = false;
33
+ if (v.readyState >= 2 && v.currentTime === 0) return;
34
+ await new Promise((r) => {
35
+ v.addEventListener(v.readyState >= 2 ? 'seeked' : 'loadeddata', r, { once: true });
36
+ v.addEventListener('error', r, { once: true });
37
+ setTimeout(r, 5000);
38
+ if (v.readyState >= 2) v.currentTime = 0;
39
+ else { v.preload = 'auto'; v.load(); }
40
+ });
41
+ })).then(() => true)`);
42
+ }
43
+ export async function printPdf(html, outFile, options = {}) {
44
+ await withDeckPage(html, async (cdp, sessionId) => {
45
+ await firstFrames(cdp, sessionId);
46
+ if (options.rasterBackground !== false)
47
+ await captureBackgrounds(cdp, sessionId);
48
+ // The capture's 2× viewport override is cleared; printing lays out at the CSS page size either way.
49
+ const { data } = await cdp.send('Page.printToPDF', { printBackground: true, preferCSSPageSize: true, displayHeaderFooter: false, marginTop: 0, marginBottom: 0, marginLeft: 0, marginRight: 0 }, sessionId);
50
+ writeFileSync(outFile, Buffer.from(data, 'base64'));
51
+ }, { timeoutMs: options.timeoutMs });
52
+ }
53
+ //# sourceMappingURL=pdf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf.js","sourceRoot":"","sources":["../src/pdf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAY,MAAM,aAAa,CAAC;AAY/D;;;;GAIG;AACH,KAAK,UAAU,kBAAkB,CAAC,GAAQ,EAAE,SAAiB;IAC3D,MAAM,GAAG,CAAC,IAAI,CAAC,oCAAoC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,S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EAAE,EAAE;QACvB,MAAM,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAClC,IAAI,OAAO,CAAC,gBAAgB,KAAK,KAAK;YAAE,MAAM,kBAAkB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACjF,oGAAoG;QACpG,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,GAAG,CAAC,IAAI,CAC7B,iBAAiB,EACjB,EAAE,eAAe,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,EAC5I,SAAS,CACV,CAAC;QACF,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IACtD,CAAC,EACD,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CACjC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,101 @@
1
+ import { type Deck, type Slide } from './parse.js';
2
+ /** Semantic classes every theme styles. Decks may use only these, plus classes defined in a deck-local theme.css. */
3
+ export declare const SEMANTIC_CLASSES: readonly ['lead', 'small', 'muted', 'center', 'subtitle', 'meta', 'callout', 'note', 'warn', 'hl', 'badge', 'del'];
4
+ /** The content type of a local image or video file, by its extension. */
5
+ export declare function mediaType(file: string): string | undefined;
6
+ /** Whether an image path or URL names a video. */
7
+ export declare function isVideo(src: string): boolean;
8
+ /** The section a slide belongs to: the most recent `section` slide and its 1-based number. */
9
+ export interface SectionInfo {
10
+ number: number;
11
+ title: string;
12
+ }
13
+ /** The deck outline for `toc: sidebar`: every section, and the titled slides of each section (0 = before any section). */
14
+ export interface TocInfo {
15
+ /** `start` is the section's first visible slide (its divider when shown); absent when nothing of it is on screen. */
16
+ sections: (SectionInfo & {
17
+ start?: number;
18
+ })[];
19
+ slides: {
20
+ number: number;
21
+ section: number;
22
+ title: string;
23
+ }[];
24
+ }
25
+ export interface SlideImage {
26
+ src: string;
27
+ alt: string;
28
+ dim?: number;
29
+ blur?: number;
30
+ side?: 'left' | 'right';
31
+ width?: string;
32
+ }
33
+ interface Env {
34
+ slide: Slide;
35
+ bg?: SlideImage;
36
+ side?: SlideImage;
37
+ /** Source line of the first line of the fragment being rendered, for `data-src` (with a source map). */
38
+ line?: number;
39
+ }
40
+ export interface RenderOptions {
41
+ /** Directory that relative image paths resolve against. */
42
+ baseDir: string;
43
+ /** Extra classes allowed beyond SEMANTIC_CLASSES (from a deck-local theme.css). */
44
+ extraClasses?: Iterable<string>;
45
+ /**
46
+ * Mark slides and blocks with the source lines they come from (`data-src="talk.md:12-14"`), for the visual
47
+ * editor (`deck editor`). The value is the deck file's name; slides from `parts:` name their own file.
48
+ */
49
+ sourceMap?: string;
50
+ /**
51
+ * Link a local image or video by the URL this returns instead of inlining it as a data: URI (undefined: inline it).
52
+ * `deck dev` links every file, which it serves, so a rebuild doesn't read and re-encode them; `deck build
53
+ * --media-dir` links videos it copies next to the page. Given the file's absolute path.
54
+ */
55
+ mediaUrl?: (file: string, video: boolean) => string | undefined;
56
+ }
57
+ export declare function escapeHtml(s: string): string;
58
+ export declare class Renderer {
59
+ private readonly options;
60
+ private readonly md;
61
+ private readonly allowedClasses;
62
+ /** Each local image and video resolved so far, by absolute path: its data: URI, or its `mediaUrl`. */
63
+ private readonly resolved;
64
+ /** The local videos resolved so far, by absolute path, with their size in bytes (`deck build` warns about big ones). */
65
+ readonly videos: Map<string, number>;
66
+ /** The local images and videos inlined so far, by absolute path, with their size in bytes (before base64). */
67
+ readonly inlined: Map<string, number>;
68
+ constructor(options: RenderOptions);
69
+ /** `file:start-end` for `data-src`. */
70
+ private sourceRef;
71
+ /** Render a fragment that starts at source line `line`, marking its blocks with their lines under a source map. */
72
+ private markdownAt;
73
+ /** Resolve an image or video path to a data: URI (or the `mediaUrl` given), or pass remote URLs through. */
74
+ resolveSrc(src: string, slide: Slide): string;
75
+ /** resolveSrc for a slide background or side panel, which are images only for now. */
76
+ private resolveImageSrc;
77
+ private checkClasses;
78
+ private processTokens;
79
+ /** Validate image attributes. Returns true when the image is a slide background or side panel (removed from flow). */
80
+ private extractSlideImage;
81
+ private renderImage;
82
+ private renderFence;
83
+ /** Render one Markdown fragment in the context of a slide, collecting bg/side images into env. */
84
+ markdown(src: string, env: Env): string;
85
+ /**
86
+ * `shown`, from the build: the page number as presented (none for a hidden slide) and how many are presented, and
87
+ * for a hidden slide the editor keeps (`deck editor`), where the `{hide}` that hides it is (`file:line`).
88
+ */
89
+ renderSlide(slide: Slide, deck: Deck, total: number, section?: SectionInfo, toc?: TocInfo, shown?: {
90
+ page?: number;
91
+ pages: number;
92
+ hiddenBy?: string;
93
+ }): string;
94
+ /**
95
+ * A slide that couldn't be built (`deck dev`): its error and its source lines, in the slide's place and with its
96
+ * number, so the rest of the deck keeps its pages. In edit mode the box opens the slide's Markdown.
97
+ */
98
+ renderErrorSlide(slide: Slide, total: number, section: SectionInfo | undefined, source: string, deckFile: string): string;
99
+ private parseAttrsAt;
100
+ }
101
+ export {};