decklight 0.9.0 → 0.11.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 (133) hide show
  1. package/NOTICE +2 -0
  2. package/PLATFORM.md +61 -3
  3. package/README.md +58 -28
  4. package/SPEC.md +1326 -85
  5. package/cli/agent-review.mjs +5 -4
  6. package/cli/agents.mjs +148 -18
  7. package/cli/bundle-audio.mjs +10 -3
  8. package/cli/bundle-module.mjs +95 -0
  9. package/cli/bundle.mjs +125 -7
  10. package/cli/cast.mjs +86 -19
  11. package/cli/check-fixes.mjs +194 -0
  12. package/cli/check-watch.mjs +151 -0
  13. package/cli/check.mjs +491 -75
  14. package/cli/code-editor.mjs +287 -0
  15. package/cli/commands.mjs +13 -2
  16. package/cli/commit-flow.mjs +7 -3
  17. package/cli/commit-message.mjs +35 -8
  18. package/cli/commit-split.mjs +125 -25
  19. package/cli/deck-refs.mjs +8 -3
  20. package/cli/decklight.mjs +11 -1
  21. package/cli/design-system-edit.mjs +37 -1
  22. package/cli/design-system-refs.mjs +263 -6
  23. package/cli/design-system.mjs +82 -14
  24. package/cli/edit-address.mjs +184 -0
  25. package/cli/edit-git.mjs +23 -6
  26. package/cli/edit-handover.mjs +257 -40
  27. package/cli/edit-look.mjs +293 -6
  28. package/cli/edit-open.mjs +143 -0
  29. package/cli/edit-slides.mjs +1043 -67
  30. package/cli/edit-translate.mjs +243 -0
  31. package/cli/edit.mjs +3680 -319
  32. package/cli/editor-support.mjs +286 -0
  33. package/cli/enhance.mjs +157 -27
  34. package/cli/find-replace.mjs +142 -0
  35. package/cli/fix-review.mjs +368 -0
  36. package/cli/git.mjs +13 -0
  37. package/cli/init.mjs +101 -22
  38. package/cli/keep-awake.mjs +68 -0
  39. package/cli/marketplace-autocheck.mjs +200 -0
  40. package/cli/marketplace.mjs +250 -13
  41. package/cli/migrate-writing.mjs +214 -0
  42. package/cli/narrate.mjs +121 -5
  43. package/cli/open.mjs +53 -15
  44. package/cli/outside-edit.mjs +257 -0
  45. package/cli/paste.mjs +92 -0
  46. package/cli/pdf.mjs +88 -10
  47. package/cli/pptx-export.mjs +10 -5
  48. package/cli/publish.mjs +24 -3
  49. package/cli/record.mjs +86 -15
  50. package/cli/remote.mjs +32 -6
  51. package/cli/rewrite.mjs +265 -0
  52. package/cli/runtime-link.mjs +218 -17
  53. package/cli/serve.mjs +9 -6
  54. package/cli/setup.mjs +2 -2
  55. package/cli/skill-content.mjs +251 -10
  56. package/cli/skills/slide-writing.md +333 -0
  57. package/cli/skills/voiceover.md +423 -0
  58. package/cli/skills.mjs +282 -15
  59. package/cli/starter-full.mjs +353 -0
  60. package/cli/supervise.mjs +14 -0
  61. package/cli/theme-refs.mjs +14 -2
  62. package/cli/theme.mjs +3 -2
  63. package/cli/translate-core.mjs +466 -0
  64. package/cli/translate-files.mjs +149 -0
  65. package/cli/translate.mjs +458 -0
  66. package/cli/units.mjs +75 -7
  67. package/cli/util.mjs +25 -0
  68. package/cli/vocabulary-docs.mjs +138 -0
  69. package/dist/decklight.css +2506 -113
  70. package/dist/decklight.js +385 -175
  71. package/dist/decklight.js.map +4 -4
  72. package/docs/GLOSSARY.md +9 -2
  73. package/docs/WRITING_RESEARCH.md +327 -0
  74. package/package.json +5 -3
  75. package/themes/coastal.css +3 -0
  76. package/themes/metropolis.css +2 -0
  77. package/themes/reveal-blood.css +3 -0
  78. package/themes/reveal-league.css +2 -0
  79. package/themes/reveal-moon.css +2 -0
  80. package/themes/reveal-serif.css +1 -0
  81. package/themes/reveal-sky.css +1 -0
  82. package/themes/reveal-solarized.css +4 -0
  83. package/tools/brand-palette.mjs +6 -1
  84. package/tools/build-groups.mjs +28 -8
  85. package/tools/cdp.mjs +176 -0
  86. package/tools/chart-spec.mjs +242 -0
  87. package/tools/click-match.mjs +70 -0
  88. package/tools/code-options.mjs +174 -0
  89. package/tools/conversation.mjs +49 -0
  90. package/tools/deck-family.mjs +101 -0
  91. package/tools/deck-html.mjs +212 -15
  92. package/tools/design-system-format.mjs +40 -1
  93. package/tools/design-system-migrations.mjs +207 -0
  94. package/tools/diagram-shapes.mjs +221 -0
  95. package/tools/elevenlabs-tts.mjs +62 -53
  96. package/tools/exec.mjs +10 -2
  97. package/tools/face-clip.mjs +96 -0
  98. package/tools/face-layout.mjs +94 -0
  99. package/tools/gemini-tts.mjs +1 -1
  100. package/tools/invisible-in-print.mjs +27 -0
  101. package/tools/lipsync-auto.mjs +197 -0
  102. package/tools/lipsync-config.mjs +16 -0
  103. package/tools/lipsync-engines.mjs +22 -4
  104. package/tools/lipsync-server.mjs +8 -5
  105. package/tools/lipsync.mjs +122 -30
  106. package/tools/local-voice.mjs +1 -1
  107. package/tools/mouth-file.mjs +26 -0
  108. package/tools/mouth.mjs +320 -0
  109. package/tools/narration-manifest.mjs +100 -6
  110. package/tools/narration-synth.mjs +96 -76
  111. package/tools/recording-impact.mjs +16 -1
  112. package/tools/sentences.mjs +7 -1
  113. package/tools/site-clip.mjs +114 -0
  114. package/tools/starters.mjs +402 -0
  115. package/tools/steps.mjs +118 -0
  116. package/tools/take-check.mjs +146 -0
  117. package/tools/template-theme.mjs +3 -1
  118. package/tools/test-impact.mjs +36 -12
  119. package/tools/theme-check.mjs +196 -1
  120. package/tools/tone-cue.mjs +108 -0
  121. package/tools/tts-cache.mjs +9 -3
  122. package/tools/tts-engines.mjs +100 -11
  123. package/tools/video-cache.mjs +93 -0
  124. package/tools/video-live.mjs +349 -0
  125. package/tools/video-options.mjs +11 -0
  126. package/tools/video.mjs +825 -117
  127. package/tools/viseme-fit.mjs +27 -0
  128. package/tools/viseme-match.mjs +77 -0
  129. package/tools/vocabulary.mjs +397 -0
  130. package/tools/voice-renumber.mjs +605 -0
  131. package/tools/voiceover-server.mjs +42 -11
  132. package/tools/voiceover.mjs +48 -20
  133. package/dist/build-info.json +0 -1
@@ -0,0 +1,257 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * The deck changed on disk under write mode, by a hand this server never saw:
6
+ * the author's editor, git, a tool (PRESENTING_EDITING, outside edits). What
7
+ * changed, said in a few words, and what the pages do about it.
8
+ *
9
+ * Every page used to reload for any change, and the hash kept the slide
10
+ * NUMBER: a change to slide 14 left the author on slide 3, a section put in
11
+ * above moved everyone onto the wrong content, and the reload flashed and
12
+ * remounted the docked panels. So the old and the new bytes are compared slide
13
+ * by slide:
14
+ *
15
+ * - only slides' own markup changed, the same slides in the same order and
16
+ * nothing around them touched: the pages are sent those slides' new markup
17
+ * and swap them in place (`patch`);
18
+ * - anything else reloads, and carries where each slide went (`land`), so a
19
+ * page lands on its content rather than on its number.
20
+ *
21
+ * Pure: the server (cli/edit.mjs) reads the bytes and sends the message.
22
+ */
23
+
24
+ import { slideOpsOf, slideRenumberOf } from './commit-split.mjs';
25
+ import { indexOfCI, sectionChildRanges, splitOpenTag, readAttrs } from '../tools/deck-html.mjs';
26
+
27
+ /** Past this many bytes of new slide markup, a patch is a reload: one message is no place for megabytes of data URIs. */
28
+ export const PATCH_MAX_BYTES = 1_000_000;
29
+
30
+ /**
31
+ * The deck's top-level `<section>`s, its slides, as `{ start, end }` offsets
32
+ * into `html` (end past `</section>`). Script, style and comment bodies are
33
+ * blanked first, offsets kept, so a runtime inlined in the page or a slide that
34
+ * SHOWS markup does not open or close a slide; a section inside a section is
35
+ * part of its slide, as the runtime counts them. Pure.
36
+ */
37
+ export function topSections(html) {
38
+ const src = String(html ?? '');
39
+ const blanked = src.replace(
40
+ /<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>|<!--[\s\S]*?-->/gi,
41
+ (m) => ' '.repeat(m.length),
42
+ );
43
+ const out = [];
44
+ let depth = 0;
45
+ let open = -1;
46
+ for (const m of blanked.matchAll(/<section\b|<\/section\s*>/gi)) {
47
+ if (m[0][1] !== '/') {
48
+ if (depth === 0) open = m.index;
49
+ depth += 1;
50
+ } else if (depth > 0) {
51
+ depth -= 1;
52
+ if (depth === 0) out.push({ start: open, end: m.index + m[0].length });
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+
58
+ /** The deck cut into its slides' markup and everything around them (`frame`, each slide a marker). */
59
+ function cut(html) {
60
+ const src = String(html ?? '');
61
+ const ranges = topSections(src);
62
+ const slides = ranges.map((r) => src.slice(r.start, r.end));
63
+ let frame = '';
64
+ let at = 0;
65
+ for (const r of ranges) { frame += `${src.slice(at, r.start)}\u0000`; at = r.end; }
66
+ frame += src.slice(at);
67
+ // the spacing between two slides is not the page's: a slide put in or taken out moves it
68
+ return { slides, frame: frame.replace(/\s*(?:\u0000\s*)+/g, '\u0000') };
69
+ }
70
+
71
+ /** A slide as the alignment compares it: whitespace at line ends ignored (as cli/commit-split.mjs reads slides). */
72
+ const source = (sec) => sec.split('\n').map((l) => l.trim()).join('\n');
73
+
74
+ // What a slide's part is called, by its tag (and a class for an aside or a
75
+ // chart): the definite name for a part that changed or went, the indefinite
76
+ // one for a part that was put in.
77
+ const PARTS = [
78
+ [/^h[12]$/, 'the title', 'a title'],
79
+ [/^h[3-6]$/, 'a heading', 'a heading'],
80
+ [/^ul$/, 'the bullet list', 'a bullet list'],
81
+ [/^ol$/, 'the numbered list', 'a numbered list'],
82
+ [/^(p|span)$/, 'the text', 'some text'],
83
+ [/^(img|picture)$/, 'the picture', 'a picture'],
84
+ [/^svg$/, 'the diagram', 'a diagram'],
85
+ [/^pre$/, 'the code', 'a code block'],
86
+ [/^table$/, 'the table', 'a table'],
87
+ [/^blockquote$/, 'the quote', 'a quote'],
88
+ [/^(video|audio)$/, 'the media', 'a video'],
89
+ [/^script$/, 'the script', 'a script'],
90
+ [/^style$/, 'the style', 'a style'],
91
+ ];
92
+ function partName(tag, markup) {
93
+ if (tag === 'aside') {
94
+ const cls = /^<aside\b[^>]*\bclass\s*=\s*["']([^"']*)["']/i.exec(markup)?.[1] ?? '';
95
+ if (/\bnotes\b/.test(cls)) return ['the notes', 'notes'];
96
+ if (/\bsources\b/.test(cls)) return ['the sources', 'sources'];
97
+ if (/\brehearse\b/.test(cls)) return ['the rehearsal notes', 'rehearsal notes'];
98
+ }
99
+ if (/^<\w+\b[^>]*(\bclass\s*=\s*["'][^"']*\bchart\b|\bdata-chart\b)/i.test(markup)) return ['the chart', 'a chart'];
100
+ if (tag === 'figure' && /<img\b/i.test(markup)) return ['the picture', 'a picture'];
101
+ for (const [re, the, a] of PARTS) if (re.test(tag)) return [the, a];
102
+ return ['the content', 'some content'];
103
+ }
104
+
105
+ /**
106
+ * What changed inside one slide, in a few words ("the bullet list", "the
107
+ * title and the notes", "a picture added"), or '' when it cannot be named (a
108
+ * change only of spacing, or of text between the elements). Each top-level
109
+ * element is matched by its markup: one gone and one come of the same kind is
110
+ * that part changed; the rest were added or removed. Pure.
111
+ */
112
+ export function slidePartsSaid(was, now) {
113
+ const parts = (sec) => {
114
+ try { return sectionChildRanges(sec).map((r) => ({ tag: r.tag, markup: sec.slice(r.start, r.end) })); } catch { return []; }
115
+ };
116
+ const a = parts(was), b = parts(now);
117
+ const said = [];
118
+ const say = (s) => { if (!said.includes(s)) said.push(s); };
119
+ const attrsOf = (sec) => readAttrs(splitOpenTag(sec.replace(/^<section\b/i, '')).attrs);
120
+ const oa = attrsOf(was), ob = attrsOf(now);
121
+ const keys = new Set([...Object.keys(oa), ...Object.keys(ob)]);
122
+ const differs = [...keys].filter((k) => oa[k] !== ob[k]);
123
+ if (differs.includes('data-layout')) say('the layout');
124
+ else if (differs.length) say("the slide's attributes");
125
+ const left = a.filter((p) => !b.some((q) => q.markup.trim() === p.markup.trim()));
126
+ const came = b.filter((q) => !a.some((p) => p.markup.trim() === q.markup.trim()));
127
+ for (const p of left) {
128
+ const [the] = partName(p.tag, p.markup);
129
+ const k = came.findIndex((q) => partName(q.tag, q.markup)[0] === the);
130
+ if (k !== -1) { came.splice(k, 1); say(the); } else say(`${the} removed`);
131
+ }
132
+ for (const q of came) say(`${partName(q.tag, q.markup)[1]} added`);
133
+ if (said.length > 2) return `${said.length} parts`;
134
+ return said.join(' and ');
135
+ }
136
+
137
+ /** "3", "3 and 9", "3, 5 and 9", or how many past four. */
138
+ function numbers(ns) {
139
+ const list = [...ns].sort((x, y) => x - y);
140
+ if (list.length > 4) return null;
141
+ return list.length === 1 ? String(list[0]) : `${list.slice(0, -1).join(', ')} and ${list.at(-1)}`;
142
+ }
143
+ function slidesPhrase(ns, verb) {
144
+ if (!ns.length) return null;
145
+ const listed = numbers(ns);
146
+ if (ns.length === 1) return `slide ${listed} ${verb}`;
147
+ return listed ? `slides ${listed} ${verb}` : `${ns.length} slides ${verb}`;
148
+ }
149
+ /** Clauses joined, at most three of them. */
150
+ function clauses(list) {
151
+ const c = list.filter(Boolean);
152
+ if (c.length > 3) return `${c.slice(0, 3).join(', ')} and more`;
153
+ return c.join(', ');
154
+ }
155
+
156
+ /** What changed around the slides: the head (styles, settings, the theme) or the rest of the page. */
157
+ function frameSaid(before, after) {
158
+ const head = (s) => {
159
+ const i = indexOfCI(s, '<head');
160
+ const j = indexOfCI(s, '</head>');
161
+ return i === -1 || j === -1 ? '' : s.slice(i, j);
162
+ };
163
+ return head(before) !== head(after) ? "the deck's head changed" : 'the deck changed outside its slides';
164
+ }
165
+
166
+ /**
167
+ * An outside edit, old bytes against new: null when nothing a page shows
168
+ * changed (the same bytes, or only the spacing between two slides); else
169
+ *
170
+ * { said, a few plain words: "slide 9 changed: the bullet list",
171
+ * "slide 4 added", "slides 7 and 8 swapped"
172
+ * patch?: { total, slides: [{ slide, html }] },
173
+ * present when the pages can swap the slides in place:
174
+ * the same slides in the same order, nothing around them
175
+ * changed, no script in a changed slide, not too big
176
+ * land: { go, moves, was, total } }
177
+ *
178
+ * `go` is the slide an author goes to (the first slide changed, added or
179
+ * moved, numbered in the new deck; after a removal only, the slide that now
180
+ * stands in the first one's place; null when no slide changed). `moves` is
181
+ * where each old slide went, `[[was, now | null]]` for every one whose number
182
+ * changed or that is gone (slideRenumber's pairs), so a page that is not
183
+ * following the change stays on its content. `was` and `total` are the two
184
+ * slide counts. Pure.
185
+ */
186
+ export function outsideEdit(before, after, { maxPatch = PATCH_MAX_BYTES } = {}) {
187
+ const old = String(before ?? ''), now = String(after ?? '');
188
+ if (old === now) return null;
189
+ const A = cut(old), B = cut(now);
190
+ const a = A.slides.map(source), b = B.slides.map(source);
191
+ const moves = slideRenumberOf(a, b);
192
+ const total = B.slides.length;
193
+ const land = { go: null, moves, was: A.slides.length, total };
194
+ const frameChanged = A.frame !== B.frame;
195
+
196
+ // the same slides, in the same order: each one that differs is that slide edited
197
+ if (!moves.length && A.slides.length === B.slides.length) {
198
+ const touched = [];
199
+ B.slides.forEach((sec, i) => { if (sec !== A.slides[i]) touched.push(i + 1); });
200
+ // only the spacing between slides moved: nothing a page shows changed
201
+ if (!touched.length && !frameChanged) return null;
202
+ land.go = touched[0] ?? null;
203
+ const detail = touched.length === 1 ? slidePartsSaid(A.slides[touched[0] - 1], B.slides[touched[0] - 1]) : '';
204
+ const slides = slidesPhrase(touched, 'changed');
205
+ const said = clauses([frameChanged && frameSaid(old, now), slides && (detail ? `${slides}: ${detail}` : slides)]);
206
+ const html = touched.map((n) => B.slides[n - 1]);
207
+ const inPlace = !frameChanged && touched.length > 0
208
+ && touched.every((n) => !/<script\b|\sdata-markdown\b/i.test(A.slides[n - 1] + B.slides[n - 1]))
209
+ && html.reduce((sum, h) => sum + h.length, 0) <= maxPatch;
210
+ return {
211
+ said: said || 'the deck changed on disk',
212
+ ...(inPlace ? { patch: { total, slides: touched.map((n, i) => ({ slide: n, html: html[i] })) } } : {}),
213
+ land,
214
+ };
215
+ }
216
+
217
+ // Slides went, came or moved: read off the alignment. A removed slide that
218
+ // reappears word for word was moved; one the renumbering still pairs with a
219
+ // slide of the new deck was rewritten in its place, so it changed.
220
+ const ops = slideOpsOf(a, b);
221
+ const to = new Map(moves);
222
+ const target = (was) => (to.has(was) ? to.get(was) : was);
223
+ const pairs = ops.filter((o) => o.kind === 'changed').map((o) => [o.was, o.slide]);
224
+ const moved = [];
225
+ const removed = [];
226
+ const taken = new Set();
227
+ for (const o of ops.filter((x) => x.kind === 'removed')) {
228
+ const n = target(o.was);
229
+ if (n === null) { removed.push(o.was); continue; }
230
+ taken.add(n);
231
+ if (a[o.was - 1] === b[n - 1]) moved.push([o.was, n]); else pairs.push([o.was, n]);
232
+ }
233
+ const changed = pairs.map(([, n]) => n);
234
+ const added = ops.filter((o) => o.kind === 'added' && !taken.has(o.slide)).map((o) => o.slide);
235
+ // a slide moved by one place swapped places with its neighbour
236
+ const movedSaid = moved.map(([w, n]) => (Math.abs(w - n) === 1 ? `slides ${Math.min(w, n)} and ${Math.max(w, n)} swapped` : `slide ${w} moved to ${n}`));
237
+ const detail = pairs.length === 1 && !added.length && !removed.length && !moved.length
238
+ ? slidePartsSaid(A.slides[pairs[0][0] - 1], B.slides[pairs[0][1] - 1]) : '';
239
+ const changedSaid = slidesPhrase(changed, 'changed');
240
+ const said = clauses([
241
+ frameChanged && frameSaid(old, now),
242
+ slidesPhrase(added, 'added'),
243
+ slidesPhrase(removed, 'removed'),
244
+ ...movedSaid,
245
+ changedSaid && (detail ? `${changedSaid}: ${detail}` : changedSaid),
246
+ ]);
247
+ // a swap touched both places; a longer move, the place the slide went to
248
+ const firsts = [...changed, ...added, ...moved.flatMap(([w, n]) => (Math.abs(w - n) === 1 ? [w, n] : [n]))];
249
+ if (firsts.length) land.go = Math.min(...firsts);
250
+ else if (removed.length) {
251
+ // the slide that now stands where the first removed one was
252
+ let n = null;
253
+ for (let k = Math.min(...removed) + 1; k <= A.slides.length && n === null; k++) n = target(k);
254
+ land.go = n ?? (total || null);
255
+ }
256
+ return { said: said || 'the deck changed on disk', land };
257
+ }
package/cli/paste.mjs ADDED
@@ -0,0 +1,92 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * What a paste may put in a deck (PRESENTING_EDITING, the clipboard).
6
+ *
7
+ * A paste is not an edit the author typed: any web page can put markup on
8
+ * the clipboard, a forged Decklight marker included, and markup that runs
9
+ * would run on the local origin that can write the deck. So everything
10
+ * pasted is cleaned here, on the server, before it reaches the file, and
11
+ * what was left out is named so the page can say it:
12
+ *
13
+ * - whole elements that run or embed: <script>, <style>, <iframe>, <frame>,
14
+ * <frameset>, <object>, <embed>, <applet>, <base>, <link>, <meta>, <form>;
15
+ * - every attribute `executableAttributes` (audit.mjs) finds: an `on*=`
16
+ * handler, a `javascript:` or `data:text/html` URL, a `srcdoc`;
17
+ * - a `style` attribute that reaches out (`url(javascript:`, `expression(`).
18
+ *
19
+ * Pictures by absolute http(s) URL stay: the author can already write them.
20
+ */
21
+
22
+ import { executableAttributes } from './audit.mjs';
23
+
24
+ /** The elements a paste never keeps, each with how the page says it was left out. */
25
+ const DROPPED_ELEMENTS = [
26
+ ['script', 'a script'], ['style', 'a style block'], ['iframe', 'a frame'], ['frame', 'a frame'], ['frameset', 'a frame'],
27
+ ['object', 'an embedded object'], ['embed', 'an embedded object'], ['applet', 'an embedded object'],
28
+ ['base', 'a base link'], ['link', 'a linked file'], ['meta', 'a meta tag'], ['form', 'a form'],
29
+ ];
30
+ const VOID = new Set(['embed', 'base', 'link', 'meta', 'frame']);
31
+
32
+ /**
33
+ * `html` with everything that would run taken out. Returns `{ html, dropped }`:
34
+ * `dropped` is what was left out, said once each ("a script", "an onclick
35
+ * handler", "a javascript: link").
36
+ */
37
+ export function sanitizePasted(html) {
38
+ let out = String(html ?? '');
39
+ const said = new Set();
40
+ // comments go first: one could hide a tag from the walk below, and none is content
41
+ out = out.replace(/<!--[\s\S]*?-->/g, '');
42
+ for (const [tag, what] of DROPPED_ELEMENTS) {
43
+ const whole = VOID.has(tag)
44
+ ? new RegExp(`<${tag}\\b[^>]*>`, 'gi')
45
+ : new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}\\s*>|<${tag}\\b[^>]*\\/?>`, 'gi');
46
+ out = out.replace(whole, () => { said.add(what); return ''; });
47
+ }
48
+ // a stray close tag of one of them, left by an element that never opened
49
+ out = out.replace(new RegExp(`<\\/(?:${DROPPED_ELEMENTS.map(([t]) => t).join('|')})\\s*>`, 'gi'), '');
50
+ // attributes that run, last to first so each offset still stands
51
+ const found = executableAttributes(out).sort((a, b) => b.start - a.start);
52
+ for (const f of found) {
53
+ out = out.slice(0, f.start).replace(/\s+$/, '') + out.slice(f.end);
54
+ said.add(f.kind === 'handler' ? `an ${f.attr} handler` : f.kind === 'executable URL' ? `a ${/data:/i.test(f.snippet) ? 'data:' : 'javascript:'} link` : 'an inline document');
55
+ }
56
+ // a style that reaches out of the page
57
+ out = out.replace(/\sstyle\s*=\s*("[^"]*"|'[^']*')/gi, (m, v) => {
58
+ if (!/url\s*\(\s*["']?\s*javascript:|expression\s*\(|-moz-binding|behavior\s*:/i.test(v)) return m;
59
+ said.add('a style that runs code');
60
+ return '';
61
+ });
62
+ return { html: out, dropped: [...said] };
63
+ }
64
+
65
+ /** The relative paths a paste points at (a picture, a background, a video), each once, in order. */
66
+ export function relativeAssets(html) {
67
+ const out = new Set();
68
+ const re = /\s(?:src|poster|href|data-background-image|data-background-video|data-background-poster)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>"']+))/gi;
69
+ for (const m of String(html ?? '').matchAll(re)) {
70
+ const v = (m[1] ?? m[2] ?? m[3] ?? '').trim();
71
+ if (!v || /^(?:[a-z][a-z0-9+.-]*:|\/\/|#|\/)/i.test(v)) continue;
72
+ out.add(v.split(/[?#]/)[0]);
73
+ }
74
+ return [...out];
75
+ }
76
+
77
+ /**
78
+ * A slide from the clipboard, as the deck will take it (PRESENTING_EDITING):
79
+ * exactly one `<section>…</section>`, cleaned the way an element is
80
+ * (sanitizePasted), its page ids left behind (`withoutPageIds`, handed in so
81
+ * this file stays free of the editor's). Returns `{ section, dropped }`, or
82
+ * throws a sentence (status 400) for anything else.
83
+ */
84
+ export function pasteSection(markup, withoutPageIds = (x) => x) {
85
+ const { html, dropped } = sanitizePasted(markup);
86
+ const t = html.trim();
87
+ const opens = t.match(/<section\b/gi) ?? [];
88
+ if (!/^<section\b[^>]*>[\s\S]*<\/section>$/i.test(t) || opens.length !== 1) {
89
+ throw Object.assign(new Error('a pasted slide is one <section>, and this is not one'), { status: 400 });
90
+ }
91
+ return { section: withoutPageIds(t), dropped };
92
+ }
package/cli/pdf.mjs CHANGED
@@ -26,6 +26,9 @@ import { argReader, isMain } from '../tools/args.mjs';
26
26
  import { renderThemeParams } from '../tools/render-theme.mjs';
27
27
  import { runAsync, CODEC_MS } from '../tools/exec.mjs';
28
28
  import { sectionBodies, isHiddenSection } from '../tools/deck-html.mjs';
29
+ import { INVISIBLE_ADVICE, invisibleSaidOf } from '../tools/invisible-in-print.mjs';
30
+
31
+ export { INVISIBLE_ADVICE };
29
32
 
30
33
  /**
31
34
  * How many slides the handout puts on a page — the runtime's own number,
@@ -128,6 +131,59 @@ function flaggedSlides(html, attr) {
128
131
  /** Slides the overflow guardrail flagged (SPEC PRESENTING). */
129
132
  export const overflowSlides = (html) => flaggedSlides(html, 'data-overflow');
130
133
 
134
+ /**
135
+ * What the guardrail said about a clipped slide's section tag: what is cut
136
+ * (`data-overflow="a diagram"`) and by how much (`data-overflow-by`), as the
137
+ * runtime measured it (#1183). An older runtime wrote a bare attribute: then
138
+ * only that the slide is clipped.
139
+ */
140
+ export function clipSaid(tag) {
141
+ const what = /\sdata-overflow="([^"]+)"/.exec(tag)?.[1]?.replace(/&amp;/g, '&');
142
+ const by = Number(/\sdata-overflow-by="(\d+)"/.exec(tag)?.[1]);
143
+ if (!what || !(by > 0)) return '';
144
+ return `${what} runs ${by}px past what the slide shows`;
145
+ }
146
+
147
+ /** Each flagged slide with what its guardrail said: `[{ n, said }]`. */
148
+ export function overflowReport(html) {
149
+ const out = [];
150
+ let n = 0;
151
+ for (const m of html.matchAll(/<section\b[^>]*>/g)) {
152
+ n += 1;
153
+ if (/\bdata-overflow\b/.test(m[0])) out.push({ n, said: clipSaid(m[0]) });
154
+ }
155
+ return out;
156
+ }
157
+
158
+ /** An attribute's value out of a dumped section tag, its entities undone. */
159
+ const attrOf = (tag, name) => new RegExp(`\\s${name}="([^"]*)"`).exec(tag)?.[1]
160
+ ?.replace(/&quot;/g, '"').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&nbsp;/g, ' ').replace(/&amp;/g, '&');
161
+
162
+ /**
163
+ * What a slide's section tag says it does not show in print (#1184): the
164
+ * runtime names the first element still at opacity 0 or visibility hidden once
165
+ * builds are complete and the deck's own animations finished
166
+ * (`data-invisible="a box “Batch” (opacity 0)"`) and counts the others
167
+ * (`data-invisible-more`). '' when it shows everything.
168
+ */
169
+ export function invisibleSaid(tag) {
170
+ return invisibleSaidOf(attrOf(tag, 'data-invisible'), attrOf(tag, 'data-invisible-more'));
171
+ }
172
+
173
+ /** Each slide with something invisible in print, and what: `[{ n, said }]`. */
174
+ export function invisibleReport(html) {
175
+ const out = [];
176
+ let n = 0;
177
+ for (const m of html.matchAll(/<section\b[^>]*>/g)) {
178
+ n += 1;
179
+ const said = invisibleSaid(m[0]);
180
+ if (said) out.push({ n, said });
181
+ }
182
+ return out;
183
+ }
184
+
185
+ // INVISIBLE_ADVICE, said by pdf, check and the Check deck… panel alike, is tools/invisible-in-print.mjs's
186
+
131
187
  /**
132
188
  * Slides mixing data-layout="split" with their own column flexbox (SPEC
133
189
  * COMPARISON_SLIDES) — the engine marks the cause the overflow guardrail
@@ -140,13 +196,21 @@ export const slideCount = (html) => sectionBodies(html).filter((b) => !isHiddenS
140
196
 
141
197
  const KB = (n) => (n < 1024 * 1024 ? `${Math.round(n / 1024)} KB` : `${(n / 1048576).toFixed(1)} MB`);
142
198
 
143
- export async function pdfMain(args = []) {
199
+ // `signal` stops Chrome mid-print (the edit server's stop route): it throws the
200
+ // AbortError, and leaves no half-written PDF behind.
201
+ export async function pdfMain(args = [], { signal = null } = {}) {
144
202
  if (args.includes('--help') || args.includes('-h')) { console.log(USAGE); return 0; }
145
203
  const { opt } = argReader(args);
146
204
  const deck = args.find((a) => !a.startsWith('-') && /\.html?$/i.test(a));
147
205
  if (!deck) { console.error(`decklight pdf: needs a deck\n\n${USAGE}`); return 1; }
148
206
  const src = resolve(deck);
149
207
  if (!existsSync(src)) { console.error(`decklight pdf: no such deck: ${deck}`); return 1; }
208
+ // The deck is served from its folder (below), and the render server never
209
+ // serves a dotfile: Chrome would print its 403 as one blank page
210
+ if (basename(src).startsWith('.')) {
211
+ console.error(`decklight pdf: ${basename(src)} is a dotfile, and a deck is rendered by serving it, which never serves a name that starts with a dot — copy or rename it without the dot`);
212
+ return 1;
213
+ }
150
214
 
151
215
  const variant = args.includes('--notes') ? 'notes' : args.includes('--handout') ? 'handout' : '';
152
216
  if (args.includes('--notes') && args.includes('--handout')) {
@@ -169,13 +233,13 @@ export async function pdfMain(args = []) {
169
233
  const url = printUrl(`${server.origin}/${relative(root, src).split(sep).join('/')}`, { theme, gen, variant });
170
234
  const shared = chromeArgs(`--virtual-time-budget=${wait}`);
171
235
  try {
172
- return await printDeck({ src, out, url, bin, shared, variant, theme });
236
+ return await printDeck({ src, out, url, bin, shared, variant, theme, signal });
173
237
  } finally {
174
238
  await server.close();
175
239
  }
176
240
  }
177
241
 
178
- async function printDeck({ src, out, url, bin, shared, variant, theme }) {
242
+ async function printDeck({ src, out, url, bin, shared, variant, theme, signal }) {
179
243
 
180
244
  // Chrome is AWAITED, never `run`: the in-process render server above has
181
245
  // to answer the browser it launched (the deadlock pptx documents), and the
@@ -189,8 +253,11 @@ async function printDeck({ src, out, url, bin, shared, variant, theme }) {
189
253
  let html = '';
190
254
  try {
191
255
  html = await runAsync(bin, [...shared, '--dump-dom', url],
192
- { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, timeout: CODEC_MS, why: 'Chrome did not finish rendering — a slide is probably waiting on a resource it cannot reach' });
193
- } catch { /* the print pass below is the one that must succeed */ }
256
+ { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, timeout: CODEC_MS, signal, why: 'Chrome did not finish rendering — a slide is probably waiting on a resource it cannot reach' });
257
+ } catch (e) {
258
+ if (e.name === 'AbortError') throw e;
259
+ // the print pass below is the one that must succeed
260
+ }
194
261
  const slides = slideCount(html);
195
262
  console.error(`pdf: rendering ${basename(src)}?print${variant ? `=${variant}` : ''}${theme ? ` · theme ${theme}` : ''}`
196
263
  + `${slides ? ` — ${slides} slides, builds complete, casts expanded` : ''}`);
@@ -198,8 +265,9 @@ async function printDeck({ src, out, url, bin, shared, variant, theme }) {
198
265
  rmSync(out, { force: true }); // never leave a stale PDF looking like a fresh one
199
266
  try {
200
267
  await runAsync(bin, [...shared, '--no-pdf-header-footer', `--print-to-pdf=${out}`, url],
201
- { maxBuffer: 32 * 1024 * 1024, timeout: CODEC_MS, why: 'Chrome did not finish rendering — a slide is probably waiting on a resource it cannot reach' });
268
+ { maxBuffer: 32 * 1024 * 1024, timeout: CODEC_MS, signal, why: 'Chrome did not finish rendering — a slide is probably waiting on a resource it cannot reach' });
202
269
  } catch (e) {
270
+ if (e.name === 'AbortError') { rmSync(out, { force: true }); throw e; }
203
271
  console.error(`decklight pdf: Chrome failed — ${String(e.message ?? e).split('\n')[0]}`);
204
272
  return 1;
205
273
  }
@@ -208,8 +276,11 @@ async function printDeck({ src, out, url, bin, shared, variant, theme }) {
208
276
  return 1;
209
277
  }
210
278
 
211
- for (const n of overflowSlides(html)) {
212
- console.error(`pdf: ⚠ slide ${n} overflows — it will be clipped in the PDF`);
279
+ for (const { n, said } of overflowReport(html)) {
280
+ console.error(`pdf: ⚠ slide ${n} overflows${said ? `: ${said}` : ''} — it will be clipped in the PDF`);
281
+ }
282
+ for (const { n, said } of invisibleReport(html)) {
283
+ console.error(`pdf: ⚠ slide ${n} prints with a hole: ${said} is invisible — ${INVISIBLE_ADVICE}`);
213
284
  }
214
285
  for (const n of splitConflictSlides(html)) {
215
286
  console.error(`pdf: ⚠ slide ${n} mixes data-layout="split" with its own column flexbox — `
@@ -217,11 +288,18 @@ async function printDeck({ src, out, url, bin, shared, variant, theme }) {
217
288
  }
218
289
  const buf = readFileSync(out);
219
290
  const pages = pdfPageCount(buf);
220
- const want = slides ? expectedPages(slides, variant) : 0;
291
+ // No slides in the rendered page is no deck at all (a refused or broken
292
+ // load): held to the file's own count, so the mismatch below is said
293
+ let written = 0;
294
+ if (!slides) {
295
+ try { written = slideCount(readFileSync(src, 'utf8')); } catch { written = 0; }
296
+ if (written) console.error(`pdf: ⚠ the rendered page had no slides, the file has ${written}: the deck did not load`);
297
+ }
298
+ const want = slides || written ? expectedPages(slides || written, variant) : 0;
221
299
  const geometry = variant === 'handout' ? 'portrait, 3 slides a page' : variant === 'notes' ? 'slide + notes per page' : '1280×720 (16:9)';
222
300
  console.log(`${out} · ${pages || '?'} pages · ${geometry} · ${KB(buf.length)}`);
223
301
  if (want && pages && pages !== want) {
224
- console.error(`pdf: ⚠ expected ${want} pages for ${slides} slides${variant ? ` (${variant})` : ''}, got ${pages}`);
302
+ console.error(`pdf: ⚠ expected ${want} pages for ${slides || written} slides${variant ? ` (${variant})` : ''}, got ${pages}`);
225
303
  }
226
304
  return 0;
227
305
  }
@@ -70,11 +70,13 @@ const titleOf = (html, file) => cleanNotes(/<title>([\s\S]*?)<\/title>/i.exec(ht
70
70
  * cause was one import. tools/shot.mjs carries the same warning above the same
71
71
  * call; test/pptx-render.mjs is what now notices.
72
72
  */
73
- export async function chromeShot(bin, argv, _ctx, { timeout = CODEC_MS } = {}) {
74
- await runAsync(bin, argv, { maxBuffer: 32 * 1024 * 1024, timeout, why: 'Chrome did not finish rendering a slide — it is probably waiting on a resource it cannot reach' });
73
+ export async function chromeShot(bin, argv, { signal } = {}, { timeout = CODEC_MS } = {}) {
74
+ await runAsync(bin, argv, { maxBuffer: 32 * 1024 * 1024, timeout, signal, why: 'Chrome did not finish rendering a slide — it is probably waiting on a resource it cannot reach' });
75
75
  }
76
76
 
77
- export async function pptxMain(args = [], { render = chromeShot, log = console.error, onSlide = null } = {}) {
77
+ // `signal` stops it between slides and mid-slide (the edit server's stop
78
+ // route): it throws the AbortError, and no file is written.
79
+ export async function pptxMain(args = [], { render = chromeShot, log = console.error, onSlide = null, signal = null } = {}) {
78
80
  if (args.includes('--help') || args.includes('-h')) { console.log(USAGE); return 0; }
79
81
  const { opt } = argReader(args);
80
82
  const deck = args.find((a) => !a.startsWith('-') && /\.html?$/i.test(a));
@@ -109,7 +111,9 @@ export async function pptxMain(args = [], { render = chromeShot, log = console.e
109
111
  // --theme rides the URL (`?theme=`), which the runtime applies to any kind
110
112
  // of theme the deck holds — a <link> to themes/<name>.css reached only file
111
113
  // themes, and missed a deck whose themes are inline blocks (#547).
112
- const renderQuery = `?${['capture', ...themeParams].join('&')}`;
114
+ // `capture=print`: each picture is the slide as it prints, so a stepped code
115
+ // block is whole unless it asks for its last step (CODE_AND_MATH)
116
+ const renderQuery = `?${['capture=print', ...themeParams].join('&')}`;
113
117
  const server = await serveForRender(root);
114
118
  const scratch = mkdtempSync(join(tmpdir(), 'decklight-pptx-'));
115
119
  const slides = [];
@@ -124,6 +128,7 @@ export async function pptxMain(args = [], { render = chromeShot, log = console.e
124
128
  log(`pptx: rendering ${basename(src)} — ${count} slides at 1280×720, builds complete`
125
129
  + (total > count ? ` · ${total - count} hidden, skipped` : ''));
126
130
  for (const [i, n] of shown.entries()) {
131
+ signal?.throwIfAborted();
127
132
  // Position in the FILE being written, not in the deck — a caller showing
128
133
  // "slide 3 of 5" means the third of five pictures, and a hidden slide in
129
134
  // between would make the deck's own numbering count past the end.
@@ -135,7 +140,7 @@ export async function pptxMain(args = [], { render = chromeShot, log = console.e
135
140
  await render(bin, chromeArgs(
136
141
  '--hide-scrollbars', '--window-size=1280,720', `--virtual-time-budget=${wait}`,
137
142
  `--screenshot=${png}`, `${server.origin}${deckPath}${renderQuery}#/${n}/999`,
138
- ), { n, png });
143
+ ), { n, png, signal });
139
144
  if (!existsSync(png) || statSync(png).size === 0) { log(`decklight pptx: slide ${n} did not render — try a longer --wait`); return 1; }
140
145
  slides.push({ png: readFileSync(png), notes: notes[n - 1] });
141
146
  }
package/cli/publish.mjs CHANGED
@@ -39,6 +39,7 @@ import { putBlob, remoteHead } from './git-tree.mjs';
39
39
  import { ownerRepo } from './git.mjs';
40
40
  import { TARGETS, schemaFor, envVarsFor, envAnswers, deploy } from '../tools/publish-targets.mjs';
41
41
  import { checkAnswers } from './wizard.mjs';
42
+ import { AUDIO_CHOICES } from './bundle-audio.mjs';
42
43
 
43
44
  const fail = makeFail('publish');
44
45
 
@@ -78,7 +79,8 @@ if (!argv.length || argv.includes('--help') || argv.includes('-h')) {
78
79
  Usage:
79
80
  decklight publish <deck.html> [--branch gh-pages] [--remote origin]
80
81
  [--no-bundle] [--no-sign] [--deck] [--path <subdir>]
81
- [--theme <name>] [--target gh-pages|netlify|vercel]
82
+ [--theme <name>] [--audio [original|aac|opus]] [--languages all|fr,es]
83
+ [--target gh-pages|netlify|vercel|folder]
82
84
 
83
85
  Options:
84
86
  --branch <name> branch to publish to (default: gh-pages; gh-pages target only)
@@ -87,6 +89,13 @@ Options:
87
89
  --no-sign publish without a Sigstore signature
88
90
  --theme <name> the theme the published page opens on — a shipped theme or
89
91
  one the deck marks (default: the deck's own "theme")
92
+ --audio [how] carry the narration's recorded audio inside the published
93
+ page, as \`bundle --audio\` does: original (the default), aac
94
+ (plays everywhere) or opus (the smallest). Without it the
95
+ clips stay beside the deck and the page plays no voice
96
+ --languages <sel> publish the deck's translations beside it (decklight
97
+ translate): all, or fr,es — each a page of its own,
98
+ index.fr.html beside index.html, switching to the others
90
99
  --deck also publish index.decklight — the signed container, which
91
100
  is the file a visitor downloads and forwards
92
101
  --path <subdir> publish under a subdirectory of the site (other content
@@ -114,7 +123,7 @@ orphan; later publishes append to its history.
114
123
  }
115
124
 
116
125
  let deck = null, branch = 'gh-pages', remote = 'origin', bundle = true, subdir = '', sign = true, deckFile = false,
117
- target = 'gh-pages', branchGiven = false, remoteGiven = false, theme = null;
126
+ target = 'gh-pages', branchGiven = false, remoteGiven = false, theme = null, audio = null, languages = null;
118
127
  for (let i = 0; i < argv.length; i++) {
119
128
  const a = argv[i];
120
129
  if (a === '--branch') { branch = argv[++i]; branchGiven = true; }
@@ -123,6 +132,11 @@ for (let i = 0; i < argv.length; i++) {
123
132
  else if (a === '--no-sign') sign = false;
124
133
  else if (a === '--deck') deckFile = true;
125
134
  else if (a === '--theme') theme = argv[++i];
135
+ // each language beside index.html as index.<lang>.html (TRANSLATION_SWITCH)
136
+ else if (a === '--languages') languages = argv[++i];
137
+ // `--audio` alone carries the files as recorded; a codec after it re-encodes
138
+ // them (bundle's own choices, read from the same list)
139
+ else if (a === '--audio') audio = AUDIO_CHOICES.includes(argv[i + 1]) ? argv[++i] : 'original';
126
140
  else if (a === '--path') subdir = argv[++i];
127
141
  else if (a === '--target') target = argv[++i];
128
142
  // the folder target's two answers, as flags — a directory is not a secret,
@@ -133,6 +147,7 @@ for (let i = 0; i < argv.length; i++) {
133
147
  else fail(`unknown argument: ${a}`);
134
148
  }
135
149
  if (!deck) fail('no deck given');
150
+ if (audio && !bundle) fail('--audio carries the narration inside the bundle, and --no-bundle publishes the deck as it is: use one or the other');
136
151
  // Checked here rather than at pack time: an argument that cannot work should
137
152
  // be refused before the command starts doing things.
138
153
  if (deckFile && !sign) fail('--deck packs the SIGNED deck — it cannot be combined with --no-sign');
@@ -196,8 +211,10 @@ if (bundle) {
196
211
  tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'decklight-publish-'));
197
212
  sitePage = path.join(tmpDir, 'index.html');
198
213
  const { bundleMain } = await import('./bundle.mjs');
199
- await bundleMain([deckPath, '-o', sitePage, ...(theme ? ['--theme', theme] : [])]);
214
+ await bundleMain([deckPath, '-o', sitePage, ...(theme ? ['--theme', theme] : []), ...(audio ? ['--audio', audio] : []), ...(languages ? ['--languages', languages] : [])]);
200
215
  }
216
+ // the languages bundled beside the page, published beside it
217
+ const languagePages = tmpDir ? fs.readdirSync(tmpDir).filter((n) => /^index\.[a-z]{2,3}(?:-[a-z0-9]{2,8})*\.html$/i.test(n)) : [];
201
218
 
202
219
  // --------------------------------------------------------------- plumbing
203
220
 
@@ -241,8 +258,10 @@ if (target !== 'gh-pages') {
241
258
  // tree, no history, and nothing else on the site to preserve or diff
242
259
  // against — the files below are simply what gets sent, in full, every time.
243
260
  const pageBytes = fs.readFileSync(sitePage);
261
+ const languageBytes = new Map(languagePages.map((n) => [n, fs.readFileSync(path.join(tmpDir, n))]));
244
262
  if (tmpDir) fs.rmSync(tmpDir, { recursive: true, force: true });
245
263
  const files = [{ path: [...parts, 'index.html'].join('/'), data: pageBytes }];
264
+ for (const n of languagePages) files.push({ path: [...parts, n].join('/'), data: languageBytes.get(n) });
246
265
  if (signature) files.push({ path: [...parts, 'index.html.sig'].join('/'), data: `${JSON.stringify(signature, null, 2)}\n` });
247
266
  if (deckBytes) files.push({ path: [...parts, 'index.decklight'].join('/'), data: deckBytes });
248
267
 
@@ -257,6 +276,7 @@ if (target !== 'gh-pages') {
257
276
  // Objects land in the repo's database; nothing references them until the
258
277
  // push, and neither the working tree nor the index ever hears about it.
259
278
  const pageBlob = git(['hash-object', '-w', '--', sitePage]);
279
+ const languageBlobs = languagePages.map((n) => [n, git(['hash-object', '-w', '--', path.join(tmpDir, n)])]);
260
280
  const nojekyllBlob = git(['hash-object', '-w', '--stdin'], '');
261
281
  const sigBlob = signature ? git(['hash-object', '-w', '--stdin'], `${JSON.stringify(signature, null, 2)}\n`) : null;
262
282
  const deckBlob = deckBytes
@@ -276,6 +296,7 @@ const put = (treeish, parts_, blob) => putBlob(git, treeish, parts_, blob);
276
296
 
277
297
  let tree = put(parent, ['.nojekyll'], nojekyllBlob);
278
298
  tree = put(tree, [...parts, 'index.html'], pageBlob);
299
+ for (const [n, blob] of languageBlobs) tree = put(tree, [...parts, n], blob);
279
300
  // Beside the page it covers, under the name a verifier will look for.
280
301
  if (sigBlob) tree = put(tree, [...parts, 'index.html.sig'], sigBlob);
281
302
  if (deckBlob) tree = put(tree, [...parts, 'index.decklight'], deckBlob);