decklight 0.10.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 (117) hide show
  1. package/NOTICE +2 -0
  2. package/PLATFORM.md +17 -0
  3. package/README.md +53 -25
  4. package/SPEC.md +1239 -67
  5. package/cli/agents.mjs +139 -15
  6. package/cli/bundle.mjs +68 -2
  7. package/cli/cast.mjs +45 -14
  8. package/cli/check-fixes.mjs +12 -4
  9. package/cli/check-watch.mjs +151 -0
  10. package/cli/check.mjs +460 -71
  11. package/cli/code-editor.mjs +287 -0
  12. package/cli/commands.mjs +13 -2
  13. package/cli/commit-message.mjs +34 -7
  14. package/cli/commit-split.mjs +123 -23
  15. package/cli/decklight.mjs +11 -1
  16. package/cli/design-system-edit.mjs +37 -1
  17. package/cli/edit-address.mjs +184 -0
  18. package/cli/edit-git.mjs +21 -4
  19. package/cli/edit-handover.mjs +136 -25
  20. package/cli/edit-look.mjs +45 -1
  21. package/cli/edit-open.mjs +143 -0
  22. package/cli/edit-slides.mjs +1043 -67
  23. package/cli/edit-translate.mjs +243 -0
  24. package/cli/edit.mjs +3182 -267
  25. package/cli/editor-support.mjs +286 -0
  26. package/cli/enhance.mjs +148 -20
  27. package/cli/find-replace.mjs +142 -0
  28. package/cli/fix-review.mjs +368 -0
  29. package/cli/init.mjs +93 -19
  30. package/cli/keep-awake.mjs +68 -0
  31. package/cli/migrate-writing.mjs +214 -0
  32. package/cli/narrate.mjs +51 -10
  33. package/cli/open.mjs +29 -9
  34. package/cli/outside-edit.mjs +257 -0
  35. package/cli/paste.mjs +92 -0
  36. package/cli/pdf.mjs +61 -2
  37. package/cli/pptx-export.mjs +3 -1
  38. package/cli/publish.mjs +24 -3
  39. package/cli/record.mjs +19 -8
  40. package/cli/rewrite.mjs +265 -0
  41. package/cli/runtime-link.mjs +218 -17
  42. package/cli/serve.mjs +7 -4
  43. package/cli/setup.mjs +2 -2
  44. package/cli/skill-content.mjs +212 -8
  45. package/cli/skills/slide-writing.md +333 -0
  46. package/cli/skills/voiceover.md +423 -0
  47. package/cli/skills.mjs +36 -13
  48. package/cli/starter-full.mjs +353 -0
  49. package/cli/supervise.mjs +14 -0
  50. package/cli/theme.mjs +3 -2
  51. package/cli/translate-core.mjs +466 -0
  52. package/cli/translate-files.mjs +149 -0
  53. package/cli/translate.mjs +458 -0
  54. package/cli/util.mjs +25 -0
  55. package/cli/vocabulary-docs.mjs +138 -0
  56. package/dist/decklight.css +2087 -91
  57. package/dist/decklight.js +367 -203
  58. package/dist/decklight.js.map +4 -4
  59. package/docs/GLOSSARY.md +9 -2
  60. package/docs/WRITING_RESEARCH.md +327 -0
  61. package/package.json +5 -3
  62. package/themes/coastal.css +3 -0
  63. package/themes/metropolis.css +2 -0
  64. package/themes/reveal-blood.css +3 -0
  65. package/themes/reveal-league.css +2 -0
  66. package/themes/reveal-moon.css +2 -0
  67. package/themes/reveal-serif.css +1 -0
  68. package/themes/reveal-sky.css +1 -0
  69. package/themes/reveal-solarized.css +4 -0
  70. package/tools/brand-palette.mjs +6 -1
  71. package/tools/build-groups.mjs +28 -8
  72. package/tools/cdp.mjs +176 -0
  73. package/tools/chart-spec.mjs +242 -0
  74. package/tools/click-match.mjs +70 -0
  75. package/tools/code-options.mjs +174 -0
  76. package/tools/conversation.mjs +49 -0
  77. package/tools/deck-family.mjs +101 -0
  78. package/tools/deck-html.mjs +212 -15
  79. package/tools/design-system-format.mjs +15 -1
  80. package/tools/diagram-shapes.mjs +221 -0
  81. package/tools/elevenlabs-tts.mjs +62 -53
  82. package/tools/face-clip.mjs +96 -0
  83. package/tools/face-layout.mjs +94 -0
  84. package/tools/gemini-tts.mjs +1 -1
  85. package/tools/invisible-in-print.mjs +27 -0
  86. package/tools/lipsync-auto.mjs +197 -0
  87. package/tools/lipsync-config.mjs +16 -0
  88. package/tools/lipsync-engines.mjs +22 -4
  89. package/tools/lipsync-server.mjs +8 -5
  90. package/tools/lipsync.mjs +122 -30
  91. package/tools/local-voice.mjs +1 -1
  92. package/tools/mouth-file.mjs +26 -0
  93. package/tools/mouth.mjs +320 -0
  94. package/tools/narration-manifest.mjs +24 -4
  95. package/tools/narration-synth.mjs +96 -76
  96. package/tools/recording-impact.mjs +16 -1
  97. package/tools/sentences.mjs +7 -1
  98. package/tools/starters.mjs +402 -0
  99. package/tools/steps.mjs +118 -0
  100. package/tools/take-check.mjs +146 -0
  101. package/tools/template-theme.mjs +3 -1
  102. package/tools/test-impact.mjs +36 -12
  103. package/tools/theme-check.mjs +196 -1
  104. package/tools/tone-cue.mjs +108 -0
  105. package/tools/tts-cache.mjs +9 -3
  106. package/tools/tts-engines.mjs +100 -11
  107. package/tools/video-cache.mjs +93 -0
  108. package/tools/video-live.mjs +349 -0
  109. package/tools/video-options.mjs +11 -0
  110. package/tools/video.mjs +772 -127
  111. package/tools/viseme-fit.mjs +27 -0
  112. package/tools/viseme-match.mjs +77 -0
  113. package/tools/vocabulary.mjs +397 -0
  114. package/tools/voice-renumber.mjs +605 -0
  115. package/tools/voiceover-server.mjs +42 -11
  116. package/tools/voiceover.mjs +48 -20
  117. package/dist/build-info.json +0 -1
@@ -0,0 +1,27 @@
1
+ // Is a viseme timeline as long as the audio it is played beside? (#1244)
2
+ //
3
+ // Pure, and shared by the runtime (src/core/character.js, which can measure
4
+ // the playing audio and nothing else) and the export (tools/viseme-match.mjs,
5
+ // which checks the stronger things first). A take of a different length is a
6
+ // different take: its sidecar would have the mouth stop early, or keep moving
7
+ // after the voice has stopped.
8
+
9
+ /**
10
+ * How far a timeline's end may sit from its audio's before it is another
11
+ * recording's. Rhubarb's duration IS the audio's, and the deck's stitched
12
+ * timeline is built to equal its WAV; a second is far past any rounding.
13
+ */
14
+ export const DRIFT_S = 1;
15
+
16
+ /** Where a timeline says its audio ends, or null when it says nothing. */
17
+ export function timelineEnd(tl) {
18
+ if (Number.isFinite(tl?.duration) && tl.duration > 0) return tl.duration;
19
+ const cues = Array.isArray(tl?.cues) ? tl.cues : [];
20
+ return cues.length ? Math.max(...cues.map((c) => Number(c?.t) || 0)) : null;
21
+ }
22
+
23
+ /** False only when both lengths are known and they disagree by more than DRIFT_S. */
24
+ export function timelineFits(tl, duration) {
25
+ const end = timelineEnd(tl);
26
+ return !(Number.isFinite(duration) && duration > 0 && end != null && Math.abs(end - duration) > DRIFT_S);
27
+ }
@@ -0,0 +1,77 @@
1
+ // Does a viseme sidecar belong to the audio beside it? (#1244)
2
+ //
3
+ // A slide-NN.visemes.json is cut from ONE recording. Re-record the audio and
4
+ // leave the sidecar, and the character mouths the previous take: its mouth
5
+ // stops early, or moves out of time, with nothing to say so. Every writer of
6
+ // narration audio does not also write lip-sync (the deck's recorder skips it
7
+ // when the bridge is down; voiceover and the export's re-voicing never run
8
+ // it), so the sidecar has to carry what ties it to its audio, and the readers
9
+ // have to look.
10
+ //
11
+ // Three things can say a sidecar is not this audio's, strongest first:
12
+ // - `audio` inside the sidecar: the hash of the audio bytes it was cut from.
13
+ // tools/lipsync.mjs and the deck's record endpoint stamp it. When present
14
+ // it settles the question either way.
15
+ // - lipsync.json's per-stem `visemes` hash (text + audio bytes), which
16
+ // tools/lipsync.mjs has always kept — for a sidecar made before the stamp.
17
+ // - the timeline's own `duration` against the audio's, the floor: a take of
18
+ // different length is a different take.
19
+ //
20
+ // Node-only. The runtime makes the duration check alone (tools/viseme-fit.mjs).
21
+
22
+ import { createHash } from 'node:crypto';
23
+ import { timelineEnd, timelineFits } from './viseme-fit.mjs';
24
+
25
+ export { DRIFT_S, timelineEnd, timelineFits } from './viseme-fit.mjs';
26
+
27
+ const sha = (...parts) => {
28
+ const h = createHash('sha256');
29
+ for (const p of parts) h.update(p);
30
+ return h.digest('hex').slice(0, 16);
31
+ };
32
+
33
+ /** The `audio` stamp: which recording a sidecar was cut from. */
34
+ export const audioStamp = (audioBytes) => sha(audioBytes);
35
+
36
+ /** lipsync.json's `visemes` hash — the words Rhubarb was told and the audio. */
37
+ export const visemeHash = (text, audioBytes) => sha('visemes|', text, '|', audioBytes);
38
+
39
+ /** A PCM WAV's length in seconds from its header, or null when it is not one. */
40
+ export function wavDuration(bytes) {
41
+ if (!bytes || bytes.length < 12 || bytes.toString('latin1', 0, 4) !== 'RIFF' || bytes.toString('latin1', 8, 12) !== 'WAVE') return null;
42
+ let byteRate = 0;
43
+ for (let at = 12; at + 8 <= bytes.length;) {
44
+ const id = bytes.toString('latin1', at, at + 4);
45
+ const size = bytes.readUInt32LE(at + 4);
46
+ if (id === 'fmt ' && at + 20 <= bytes.length) byteRate = bytes.readUInt32LE(at + 16);
47
+ if (id === 'data') {
48
+ // a streamed WAV may say 0 or 0xFFFFFFFF here: what is on disk is the data
49
+ const data = size && size !== 0xffffffff ? Math.min(size, bytes.length - at - 8) : bytes.length - at - 8;
50
+ return byteRate ? data / byteRate : null;
51
+ }
52
+ at += 8 + size + (size & 1);
53
+ }
54
+ return null;
55
+ }
56
+
57
+ /**
58
+ * Why `tl` is not the lip-sync of this audio, or null when nothing says so.
59
+ * `rhubarb`: whether Rhubarb runs here. A sidecar read from the voice
60
+ * (tools/mouth.mjs, `source: 'builtin'`) stands in for Rhubarb's only while
61
+ * Rhubarb is missing: once it is here, every reader takes that sidecar as out
62
+ * of date, so the next lip-sync run or export replaces it with Rhubarb's.
63
+ * `audioBytes`: the audio file. `stateHash`/`text`: lipsync.json's entry for
64
+ * the stem and the script beside it. `duration`: the audio's, in seconds.
65
+ * Anything not given is not checked.
66
+ */
67
+ export function visemeMismatch(tl, { audioBytes = null, stateHash = null, text = '', duration = null, rhubarb = false } = {}) {
68
+ if (rhubarb && tl?.source === 'builtin') return 'it was read from the voice, and Rhubarb is here to make it';
69
+ if (typeof tl?.audio === 'string' && audioBytes) {
70
+ return tl.audio === audioStamp(audioBytes) ? null : 'it was made from another recording';
71
+ }
72
+ if (stateHash && audioBytes && stateHash !== visemeHash(text, audioBytes)) {
73
+ return 'its audio or script changed since it was made';
74
+ }
75
+ if (!timelineFits(tl, duration)) return `it lasts ${timelineEnd(tl).toFixed(1)}s and its audio ${duration.toFixed(1)}s`;
76
+ return null;
77
+ }
@@ -0,0 +1,397 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Decklight's authoring vocabulary: every `data-*` attribute an author writes
6
+ * that the runtime (or a command that reads the deck) acts on, and every key
7
+ * of the configuration block. ONE table, read by everything that needs to
8
+ * know what a word means:
9
+ *
10
+ * - `decklight check` (cli/check.mjs) and the Check deck… panel
11
+ * (src/core/deckcheck.js): a misspelled attribute, build effect or
12
+ * configuration key renders as if it were absent, and nothing said so.
13
+ * `data-buld` and `data-build="fade-upp"` are findings now, with what
14
+ * was meant.
15
+ *
16
+ * Here and not in src/ for the reason tools/click-match.mjs gives: cli/ never
17
+ * imports src/, src/ may import a tool. It ships in the runtime bundle, so it
18
+ * stays a table and a few small functions, zero dependencies.
19
+ *
20
+ * test/vocabulary.test.mjs keeps it honest: every `data-*` name in src/ is
21
+ * either here or in ENGINE_ATTRIBUTES, and every entry here is read somewhere.
22
+ */
23
+
24
+ /**
25
+ * The attributes an author writes: what the rules need and nothing else,
26
+ * since this ships in the runtime and so in every self-contained deck. Where
27
+ * each goes and what it does is cli/vocabulary-docs.mjs's, joined by name for
28
+ * the editor support files (cli/editor-support.mjs) and kept out of the
29
+ * bundle. `values` is the enumeration when the
30
+ * attribute takes one, `bare` means it may be written with no value, and
31
+ * `number` that a number is a value too. `open` marks values that are only
32
+ * suggestions (a CSS value may be anything else); `kind` names what a value
33
+ * is, for the sentence a finding says.
34
+ */
35
+ export const ATTRIBUTES = [
36
+ // ── a slide ───────────────────────────────────────────────────────────────
37
+ { name: 'data-layout', kind: 'layout', values: ['auto', 'centered', 'pinned', 'top', 'split', 'split-flip'] },
38
+ { name: 'data-template' },
39
+ { name: 'data-pin', kind: 'pin', values: ['none'], bare: true, number: true },
40
+ { name: 'data-subtitle', kind: 'subtitle setting', values: ['none'] },
41
+ { name: 'data-transition', kind: 'transition', values: ['none', 'fade', 'slide', 'scale', 'flip'] },
42
+ { name: 'data-auto-animate', bare: true },
43
+ { name: 'data-hidden', bare: true },
44
+ { name: 'data-module' },
45
+ { name: 'data-steps' },
46
+ { name: 'data-steps-count', bare: true },
47
+ { name: 'data-steps-end', bare: true },
48
+ { name: 'data-background-image' },
49
+ { name: 'data-background-video' },
50
+ { name: 'data-background-poster' },
51
+ { name: 'data-background-size', kind: 'background size', values: ['cover', 'contain'], open: true },
52
+ { name: 'data-background-position' },
53
+ { name: 'data-background-dim', number: true },
54
+ { name: 'data-logo', bare: true, number: true },
55
+ { name: 'data-math', bare: true },
56
+ { name: 'data-static-ok', bare: true },
57
+ { name: 'data-dense-ok', bare: true },
58
+ { name: 'data-timing', number: true },
59
+ { name: 'data-face' },
60
+ { name: 'data-face-keep', kind: 'full-screen narrator content', values: ['none'], bare: true },
61
+ { name: 'data-narration', kind: 'narration setting', values: ['hold'] },
62
+ { name: 'data-narration-pause', number: true },
63
+ { name: 'data-narration-beat-pause', number: true },
64
+ { name: 'data-narration-sentence-pause', number: true },
65
+ { name: 'data-video-hold', number: true },
66
+
67
+ // ── builds ────────────────────────────────────────────────────────────────
68
+ { name: 'data-build', kind: 'build effect', values: ['fade', 'fade-up', 'fade-down', 'zoom', 'pop', 'draw', 'highlight', 'travel', 'none'], bare: true },
69
+ { name: 'data-build-order', number: true },
70
+ { name: 'data-build-stay', bare: true },
71
+ { name: 'data-build-self', bare: true },
72
+ { name: 'data-build-with', bare: true },
73
+ { name: 'data-draw-stops' },
74
+ { name: 'data-draw-speed', number: true },
75
+ { name: 'data-along-wire' },
76
+ { name: 'data-label' },
77
+ { name: 'data-travel-ms', number: true },
78
+ { name: 'data-arrive', kind: 'arrival', values: ['fade', 'stay', 'pulse'] },
79
+ { name: 'data-travel-repeat', bare: true },
80
+
81
+ // ── diagrams ──────────────────────────────────────────────────────────────
82
+ { name: 'data-node' },
83
+ { name: 'data-from' },
84
+ { name: 'data-to' },
85
+ { name: 'data-route', kind: 'route', values: ['straight', 'elbow', 'curve'] },
86
+ { name: 'data-wire' },
87
+ { name: 'data-on-wire' },
88
+ { name: 'data-along', number: true },
89
+ { name: 'data-shape', kind: 'shape', values: ['diamond', 'hexagon', 'cylinder', 'document', 'note', 'cloud'] },
90
+ { name: 'data-group', bare: true },
91
+ { name: 'data-concept' },
92
+ { name: 'data-nest', kind: 'nesting setting', values: ['on', 'off'] },
93
+ { name: 'data-id' },
94
+ { name: 'data-animate', kind: 'animation', values: ['pulse', 'float', 'shake', 'spin', 'blink', 'bounce', 'swing', 'glow', 'breathe'] },
95
+ { name: 'data-write', kind: 'letter-by-letter animation', values: ['out', 'off'], bare: true },
96
+ { name: 'data-write-after', kind: 'letter-by-letter animation', bare: true },
97
+
98
+ // ── charts ────────────────────────────────────────────────────────────────
99
+ { name: 'data-chart', kind: 'chart type', values: ['bar', 'line', 'area', 'pie', 'donut', 'scatter'] },
100
+ { name: 'data-title' },
101
+ { name: 'data-aspect' },
102
+
103
+ // ── code ──────────────────────────────────────────────────────────────────
104
+ { name: 'data-lines' },
105
+ { name: 'data-lines-numbers', bare: true },
106
+ { name: 'data-lines-end', kind: 'line walk ending', values: ['all'] },
107
+ { name: 'data-lines-print', kind: 'printed line walk', values: ['all', 'last'] },
108
+ { name: 'data-callouts' },
109
+ { name: 'data-callouts-keep', bare: true },
110
+ { name: 'data-for' },
111
+ { name: 'data-step', number: true },
112
+ { name: 'data-fit', kind: 'fit', values: ['fill'], bare: true },
113
+
114
+ // ── figures ───────────────────────────────────────────────────────────────
115
+ { name: 'data-figure', bare: true },
116
+ { name: 'data-count', bare: true },
117
+ { name: 'data-count-from', number: true },
118
+
119
+ // ── conversations ─────────────────────────────────────────────────────────
120
+ { name: 'data-role' },
121
+ { name: 'data-kind', kind: 'turn kind', values: ['speech', 'thought', 'tool-call'] },
122
+ { name: 'data-name' },
123
+
124
+ // ── terminals ─────────────────────────────────────────────────────────────
125
+ { name: 'data-cast' },
126
+ { name: 'data-cast-inline' },
127
+ { name: 'data-mode', kind: 'terminal mode', values: ['step', 'play'] },
128
+ { name: 'data-rows', number: true },
129
+ { name: 'data-type-speed', number: true },
130
+ { name: 'data-max-step', number: true },
131
+ { name: 'data-speed', kind: 'playback speed', values: ['1', '2', '4'] },
132
+ { name: 'data-type-sound', kind: 'key sound', values: ['thocky', 'creamy', 'clacky', 'off'] },
133
+
134
+ // ── anything ──────────────────────────────────────────────────────────────
135
+ { name: 'data-scroll-ok', bare: true },
136
+ { name: 'data-invisible-ok', bare: true },
137
+ { name: 'data-no-advance', bare: true },
138
+
139
+ // ── design-system templates, and the slots a slide fills ──────────────────
140
+ { name: 'data-slot' },
141
+ { name: 'data-slot-hint' },
142
+ { name: 'data-slot-required', bare: true },
143
+ { name: 'data-slot-default', bare: true },
144
+ { name: 'data-ds-bleed', bare: true },
145
+
146
+ // ── the page ──────────────────────────────────────────────────────────────
147
+ { name: 'data-decklight-config', bare: true },
148
+ { name: 'data-theme' },
149
+ ];
150
+
151
+ /**
152
+ * Names the runtime, the servers and the CLI write themselves (state, marks,
153
+ * the chrome's own markup), and the few no longer authored. Never a typo for
154
+ * anything: a deck saved from a rendered page carries some of them, and a
155
+ * name close to an authored one (`data-builds`, `data-pinned`) is the engine's.
156
+ */
157
+ export const ENGINE_ATTRIBUTES = [
158
+ 'data-action', 'data-axis', 'data-beat', 'data-beat-of', 'data-beats', 'data-bled', 'data-bleed', 'data-build-container',
159
+ 'data-build-state', 'data-build-style', 'data-builds', 'data-canvas', 'data-chan', 'data-click-mismatch', 'data-col',
160
+ 'data-concept-hints', 'data-corner', 'data-custom', 'data-decklight-audio', 'data-decklight-runtime',
161
+ 'data-decklight-terminal', 'data-decklight-version', 'data-decklight-visemes', 'data-decklight-voices', 'data-dense',
162
+ 'data-design-system', 'data-design-system-meta', 'data-design-system-palette', 'data-design-system-templates',
163
+ 'data-design-system-theme', 'data-design-system-version', 'data-display-fill', 'data-dl-unsaved', 'data-dl-write-glyph', 'data-dock',
164
+ 'data-draw-marker-end', 'data-draw-marker-start', 'data-draw-masked', 'data-draw-orig', 'data-ds-expanded',
165
+ 'data-ds-injected', 'data-ds-missing', 'data-ds-required-empty', 'data-eyelid', 'data-filmed', 'data-fit-scale',
166
+ 'data-font', 'data-font-meta', 'data-font-preview', 'data-font-version', 'data-generated', 'data-go', 'data-how',
167
+ 'data-href', 'data-i', 'data-idle', 'data-invisible', 'data-invisible-more', 'data-key', 'data-link', 'data-markdown', 'data-markdown-removed', 'data-mouth',
168
+ 'data-n', 'data-nest-fill', 'data-noise', 'data-off', 'data-off-fix', 'data-off-undo', 'data-overflow',
169
+ 'data-overflow-by', 'data-part', 'data-phase', 'data-pinned', 'data-play', 'data-play-beat', 'data-plugin', 'data-point', 'data-pos',
170
+ 'data-poster', 'data-preview-kind', 'data-preview-label', 'data-rate', 'data-redo', 'data-redo-beat', 'data-ref', 'data-roles', 'data-row', 'data-rule',
171
+ 'data-scope', 'data-screen', 'data-series', 'data-side', 'data-sig', 'data-slide', 'data-slide-index', 'data-split-conflict', 'data-state',
172
+ 'data-tab', 'data-tag', 'data-takes', 'data-theme-added', 'data-theme-marketplace', 'data-theme-source',
173
+ 'data-token', 'data-tone', 'data-type', 'data-type-wpm', 'data-value', 'data-version', 'data-view', 'data-viseme', 'data-was',
174
+ ];
175
+
176
+ /**
177
+ * The configuration block's keys (SPEC DECK_ANATOMY): `<script
178
+ * type="application/json" data-decklight-config>`, with the JSON type each
179
+ * takes. `values` as above.
180
+ */
181
+ export const CONFIG_KEYS = [
182
+ { name: 'decklight', type: 'string' },
183
+ { name: 'theme', type: 'string' },
184
+ { name: 'transition', type: 'string', kind: 'transition', values: ['none', 'fade', 'slide', 'scale', 'flip'] },
185
+ { name: 'hash', type: 'boolean' },
186
+ { name: 'controls', type: 'boolean' },
187
+ { name: 'slideNumber', type: ['boolean', 'string'], kind: 'slide number style', values: ['n', 'n/N'] },
188
+ { name: 'width', type: 'number' },
189
+ { name: 'height', type: 'number' },
190
+ { name: 'pinTitles', type: ['boolean', 'number'] },
191
+ { name: 'themes', type: 'array' },
192
+ { name: 'markedThemes', type: 'array' },
193
+ { name: 'themeSources', type: 'object' },
194
+ { name: 'brandThemesOnly', type: 'boolean' },
195
+ { name: 'designSystems', type: 'array' },
196
+ { name: 'designSystemVersions', type: 'object' },
197
+ { name: 'fonts', type: 'array' },
198
+ { name: 'font', type: 'string' },
199
+ { name: 'concepts', type: 'object' },
200
+ { name: 'roleConcepts', type: 'object' },
201
+ { name: 'logo', type: 'object' },
202
+ { name: 'playlist', type: 'array' },
203
+ { name: 'narration', type: 'object' },
204
+ { name: 'bleed', type: 'boolean' },
205
+ { name: 'edit', type: 'object' },
206
+ { name: 'languages', type: 'array' },
207
+ { name: 'translationOf', type: 'string' },
208
+ ];
209
+
210
+ // ── lookups ──────────────────────────────────────────────────────────────────
211
+
212
+ const BY_NAME = new Map(ATTRIBUTES.map((a) => [a.name, a]));
213
+ const ENGINE = new Set(ENGINE_ATTRIBUTES);
214
+ const AUTHORED = ATTRIBUTES.map((a) => a.name);
215
+ const CONFIG_BY_NAME = new Map(CONFIG_KEYS.map((k) => [k.name, k]));
216
+
217
+ /** The table's entry for an attribute name, or undefined. */
218
+ export const attributeEntry = (name) => BY_NAME.get(String(name).toLowerCase());
219
+
220
+ /** Does Decklight know this `data-*` name, as authored or as its own? */
221
+ export const isKnownAttribute = (name) => {
222
+ const n = String(name).toLowerCase();
223
+ return BY_NAME.has(n) || ENGINE.has(n);
224
+ };
225
+
226
+ // ── did you mean ─────────────────────────────────────────────────────────────
227
+
228
+ /**
229
+ * Edit distance with a swap of two neighbours costing one (optimal string
230
+ * alignment): `bulid` is one slip from `build`, as a typist would count it.
231
+ */
232
+ export function editDistance(a, b) {
233
+ a = String(a); b = String(b);
234
+ const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
235
+ for (let j = 1; j <= b.length; j++) d[0][j] = j;
236
+ for (let i = 1; i <= a.length; i++) {
237
+ for (let j = 1; j <= b.length; j++) {
238
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
239
+ d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
240
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
241
+ }
242
+ }
243
+ return d[a.length][b.length];
244
+ }
245
+
246
+ /**
247
+ * How far a word may be from the one meant and still be a slip of it: none
248
+ * for a word of three letters or fewer (`to`, `id`: everything is close to
249
+ * those), one up to six, two beyond.
250
+ */
251
+ const reach = (word) => (word.length <= 3 ? 0 : word.length <= 6 ? 1 : 2);
252
+
253
+ /**
254
+ * The candidate `word` is most likely a slip of, or null when none is close.
255
+ * Case is no slip: `Fade-Up` means `fade-up`. A tie goes to the earlier
256
+ * candidate, so the order of a list is its preference.
257
+ */
258
+ export function didYouMean(word, candidates, { strip = '' } = {}) {
259
+ const w = String(word).toLowerCase().slice(strip.length);
260
+ let best = null, bestD = Infinity;
261
+ for (const c of candidates) {
262
+ const core = String(c).toLowerCase().slice(strip.length);
263
+ if (!core) continue;
264
+ const d = editDistance(w, core);
265
+ if (d <= reach(core) && d < bestD) { best = c; bestD = d; }
266
+ }
267
+ return best;
268
+ }
269
+
270
+ // ── the rules ────────────────────────────────────────────────────────────────
271
+
272
+ const finding = (level, rule, slide, title, message) => ({ level, rule, slide, title, message });
273
+
274
+ const an = (noun) => `${/^[aeiou]/.test(noun) ? 'an' : 'a'} ${noun}`;
275
+
276
+ /** `fade, fade-up or zoom`, with what else the entry takes after it. */
277
+ const takes = (entry) => {
278
+ const more = [...(entry.number ? ['a number'] : []), ...(entry.bare ? ['no value'] : [])];
279
+ const all = [...entry.values, ...more];
280
+ return all.length > 1 ? `${all.slice(0, -1).join(', ')} or ${all.at(-1)}` : all[0];
281
+ };
282
+
283
+ /** Is `value` one the entry takes? */
284
+ function valueAccepted(entry, value) {
285
+ const v = String(value).trim();
286
+ if (v === '') return !!entry.bare || !entry.values;
287
+ if (entry.number && v !== '' && Number.isFinite(Number(v))) return true;
288
+ return entry.values.includes(v);
289
+ }
290
+
291
+ /**
292
+ * The findings for a set of elements' attributes, one per distinct slip per
293
+ * slide. `elements` is `[{ slide, title, attrs }]` with `attrs` a plain
294
+ * `{ name: value }` (cli/check.mjs reads it off the file, deckcheck.js off
295
+ * the live page); `slide` is null outside any slide.
296
+ *
297
+ * unknown-attribute a `data-*` name one slip from one Decklight reads:
298
+ * the element behaves as if it had none. A name close to
299
+ * nothing is the author's own and is left alone.
300
+ * unknown-value a value an enumerated attribute does not take
301
+ */
302
+ export function attributeFindings(elements) {
303
+ const out = [];
304
+ const said = new Set();
305
+ for (const { slide = null, title = '', attrs = {} } of elements) {
306
+ for (const [rawName, value] of Object.entries(attrs)) {
307
+ const name = rawName.toLowerCase();
308
+ if (!name.startsWith('data-')) continue;
309
+ const entry = BY_NAME.get(name);
310
+ if (!entry) {
311
+ if (ENGINE.has(name)) continue;
312
+ const meant = didYouMean(name, AUTHORED, { strip: 'data-' });
313
+ if (!meant) continue;
314
+ const key = `a:${slide}:${name}`;
315
+ if (said.has(key)) continue;
316
+ said.add(key);
317
+ out.push(finding('warn', 'unknown-attribute', slide, title,
318
+ `${name} is not an attribute Decklight reads: did you mean ${meant}? As written it does nothing`));
319
+ continue;
320
+ }
321
+ if (!entry.values || entry.open || valueAccepted(entry, value)) continue;
322
+ // a slashed data-layout names a template: ds-layout-attr says that one
323
+ if (name === 'data-layout' && String(value).includes('/')) continue;
324
+ const key = `v:${slide}:${name}=${value}`;
325
+ if (said.has(key)) continue;
326
+ said.add(key);
327
+ const meant = didYouMean(String(value).trim(), entry.values);
328
+ const shown = String(value).trim() === '' ? `${name} with no value` : `${name}="${value}"`;
329
+ out.push(finding('warn', 'unknown-value', slide, title,
330
+ `${shown} is not ${an(entry.kind)}${meant ? `: did you mean ${meant}?` : '.'} It takes ${takes(entry)}`));
331
+ }
332
+ }
333
+ return out;
334
+ }
335
+
336
+ /**
337
+ * Where a JSON parser said it stopped, as `{ line, column }` in `text`, or
338
+ * null. V8 says `at position N` (and lately `(line L column C)`), Firefox
339
+ * `at line L column C`; Safari says neither.
340
+ */
341
+ export function jsonErrorAt(message, text) {
342
+ const p = /position (\d+)/.exec(message);
343
+ if (!p) {
344
+ const m = /line (\d+) column (\d+)/.exec(message);
345
+ return m ? { line: Number(m[1]), column: Number(m[2]), offset: null } : null;
346
+ }
347
+ const offset = Number(p[1]);
348
+ const before = String(text).slice(0, offset).split('\n');
349
+ return { line: before.length, column: before.at(-1).length + 1, offset };
350
+ }
351
+
352
+ /**
353
+ * The configuration block's findings. `text` is what the block holds (null:
354
+ * the deck has none, and nothing is said); `line` is the deck line its text
355
+ * starts on, when the caller knows it, so a position names a line of the file.
356
+ *
357
+ * config-json the block is not JSON, or not a JSON object: the deck boots
358
+ * with its defaults, ignoring everything in it (an error)
359
+ * config-key a key Decklight does not read, with the one meant
360
+ * config-value a key's value it does not take
361
+ */
362
+ export function configFindings(text, { line = null } = {}) {
363
+ if (text == null) return [];
364
+ const out = [];
365
+ const head = (level, rule, message) => out.push(finding(level, rule, null, 'head', message));
366
+ let parsed;
367
+ try {
368
+ parsed = JSON.parse(text);
369
+ } catch (err) {
370
+ const raw = String(err?.message ?? err);
371
+ const at = jsonErrorAt(raw, text);
372
+ const reason = raw.replace(/^JSON\.parse: /, '').replace(/\s*(?:in JSON )?at (?:position \d+|line \d+ column \d+).*$/s, '').replace(/\s*\(line \d+ column \d+\)/, '').trim();
373
+ const where = at ? (line != null ? `line ${line + at.line - 1}, column ${at.column}` : `line ${at.line} of the block, column ${at.column}`) : null;
374
+ // the slip a hand typist makes most: a comma after the last entry
375
+ const trailing = at?.offset != null && /,\s*$/.test(String(text).slice(0, at.offset)) && /^\s*[}\]]/.test(String(text).slice(at.offset));
376
+ head('error', 'config-json', `the configuration block is not valid JSON${where ? ` (${where})` : ''}: ${reason || 'it does not parse'}`
377
+ + `${trailing ? ' (a comma after the last entry?)' : ''}. The deck boots with its defaults, ignoring all of it`);
378
+ return out;
379
+ }
380
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
381
+ head('error', 'config-json', 'the configuration block is not a JSON object ({ … }): the deck boots with its defaults, ignoring it');
382
+ return out;
383
+ }
384
+ for (const [key, value] of Object.entries(parsed)) {
385
+ const entry = CONFIG_BY_NAME.get(key);
386
+ if (!entry) {
387
+ const meant = didYouMean(key, CONFIG_KEYS.map((k) => k.name));
388
+ head('warn', 'config-key', `"${key}" is not a configuration key Decklight reads${meant ? `: did you mean "${meant}"?` : '.'} As written it does nothing`);
389
+ continue;
390
+ }
391
+ if (entry.values && typeof value === 'string' && !entry.values.includes(value)) {
392
+ const meant = didYouMean(value, entry.values);
393
+ head('warn', 'config-value', `"${key}": "${value}" is not ${an(entry.kind)}${meant ? `: did you mean "${meant}"?` : '.'} It takes ${entry.values.map((v) => `"${v}"`).join(', ')}`);
394
+ }
395
+ }
396
+ return out;
397
+ }