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,221 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * The shapes and line styles the diagram editor writes (SPEC SVG_DIAGRAMS),
6
+ * pure, and here so the page (src/core/shapes.js) and the server
7
+ * (cli/edit.mjs) agree on every value: cli/ never imports src/, and src/ may
8
+ * import a tool.
9
+ */
10
+
11
+ /**
12
+ * Line ▸ (solid, dashed, dotted): the `stroke-dasharray` each one writes,
13
+ * inline on the stroke. A dot is a round cap on a dash of nothing, so dotted
14
+ * also writes `stroke-linecap: round`. Solid writes no dashes at all.
15
+ */
16
+ export const LINE_DASHES = Object.freeze({ dashed: '6 4', dotted: '0 4' });
17
+ export const LINES = Object.freeze(['solid', 'dashed', 'dotted']);
18
+
19
+ /** What a `stroke-dasharray` draws as: 'dotted' when its dashes are dots, 'dashed', or 'solid'. */
20
+ export function lineOf(dashes) {
21
+ const nums = String(dashes ?? '').match(/-?\d*\.?\d+/g)?.map(Number) ?? [];
22
+ if (!nums.some((n) => n > 0)) return 'solid';
23
+ return nums[0] < 1 ? 'dotted' : 'dashed';
24
+ }
25
+
26
+ /** Corners ▸ on a box: square (no `rx`), rounded, or a pill (`rx` half its short side, kept so on a resize). */
27
+ export const CORNERS = Object.freeze(['square', 'rounded', 'pill']);
28
+
29
+ /** The corners a box's attributes `{ width, height, rx, ry }` give it. */
30
+ export function cornersOf(b) {
31
+ const r = b.rx ?? b.ry ?? 0;
32
+ if (!(r > 0)) return 'square';
33
+ const short = Math.min(b.width ?? Infinity, b.height ?? Infinity);
34
+ return Number.isFinite(short) && 2 * r >= short - 0.5 ? 'pill' : 'rounded';
35
+ }
36
+
37
+ /** The `rx` (and `ry`) a box of `w` × `h` gets for `corners`: none, a modest curve, or half its short side. */
38
+ export function cornerRadius(corners, w, h) {
39
+ const short = Math.min(w, h);
40
+ if (corners === 'pill') { const r = Math.round(short * 5) / 10; return Object.is(r, -0) ? 0 : r; }
41
+ if (corners === 'rounded') return Math.max(2, Math.min(12, Math.round(short / 6)));
42
+ return null;
43
+ }
44
+
45
+ // ── more shapes than a box and an ellipse ──────────────────────────────────
46
+
47
+ /**
48
+ * The shapes Add a shape offers besides a box, an ellipse, a label and a line
49
+ * (SVG_DIAGRAMS). Each is ONE element marked `data-shape` with its kind, so a
50
+ * resize writes its geometry again for the new box and a wire stops at its
51
+ * outline: a `<polygon>` (diamond, hexagon) or a `<path>` in absolute
52
+ * M, L, C and Z (cylinder, document, note, cloud; the server's path data
53
+ * takes no arcs). Every number of the geometry lies inside its box and some
54
+ * number reaches each edge, so the box is read back from the numbers alone.
55
+ */
56
+ export const SHAPES = Object.freeze({
57
+ diamond: 'polygon', hexagon: 'polygon',
58
+ cylinder: 'path', document: 'path', note: 'path', cloud: 'path',
59
+ });
60
+ /** What a new one says until it is typed into. */
61
+ export const SHAPE_LABELS = Object.freeze({
62
+ diamond: 'Decision', hexagon: 'Step', cylinder: 'Store', document: 'Document', note: 'Note', cloud: 'Cloud',
63
+ });
64
+
65
+ /** A number as the file gets it: one decimal at most, never -0 (the server's formatCoord). */
66
+ const fmt = (n) => { const r = Math.round(n * 10) / 10; return String(Object.is(r, -0) ? 0 : r); };
67
+ /** A quarter ellipse's control-point factor. */
68
+ const K = 0.5523;
69
+
70
+ /**
71
+ * The geometry of a shape of `kind` filling box `{ x, y, w, h }`:
72
+ * `{ tag, attr, value }`, `points` on a polygon and `d` on a path, in the
73
+ * spelling the server writes back (`x,y x,y`; `M 1 2 L 3 4`), so the file
74
+ * and the page agree byte for byte. Null for a kind it does not know.
75
+ */
76
+ export function shapeGeometry(kind, box) {
77
+ const tag = SHAPES[kind];
78
+ if (!tag) return null;
79
+ const x = Number(fmt(box.x)); const y = Number(fmt(box.y));
80
+ const w = Math.max(0, Number(fmt(box.w))); const h = Math.max(0, Number(fmt(box.h)));
81
+ const r = x + w; const b = y + h; const cx = x + w / 2; const cy = y + h / 2;
82
+ const P = (pts) => pts.map(([px, py]) => `${fmt(px)},${fmt(py)}`).join(' ');
83
+ const D = (cmds) => cmds.map(([c, ...n]) => [c, ...n.map(fmt)].join(' ')).join(' ');
84
+ switch (kind) {
85
+ case 'diamond': return { tag, attr: 'points', value: P([[cx, y], [r, cy], [cx, b], [x, cy]]) };
86
+ case 'hexagon': {
87
+ const i = Math.min(w * 0.25, h * 0.5);
88
+ return { tag, attr: 'points', value: P([[x + i, y], [r - i, y], [r, cy], [r - i, b], [x + i, b], [x, cy]]) };
89
+ }
90
+ case 'cylinder': {
91
+ // the body and the back of the top rim, then the front of the rim on its own
92
+ const e = Math.min(h * 0.15, w * 0.25); const hx = w / 2;
93
+ const top = (yy) => [['C', x, yy - e * K, cx - hx * K, yy - e, cx, yy - e], ['C', cx + hx * K, yy - e, r, yy - e * K, r, yy]];
94
+ return { tag, attr: 'd', value: D([
95
+ ['M', x, y + e], ...top(y + e), ['L', r, b - e],
96
+ ['C', r, b - e + e * K, cx + hx * K, b, cx, b], ['C', cx - hx * K, b, x, b - e + e * K, x, b - e], ['Z'],
97
+ ['M', x, y + e], ['C', x, y + e + e * K, cx - hx * K, y + 2 * e, cx, y + 2 * e], ['C', cx + hx * K, y + 2 * e, r, y + e + e * K, r, y + e],
98
+ ]) };
99
+ }
100
+ case 'document': {
101
+ // a page whose foot is a wave
102
+ const d = h * 0.12;
103
+ return { tag, attr: 'd', value: D([['M', x, y], ['L', r, y], ['L', r, b - d], ['C', x + w * 0.7, b - 3 * d, x + w * 0.3, b, x, b - d], ['Z']]) };
104
+ }
105
+ case 'note': {
106
+ // a sheet with its top right corner folded down, and the fold
107
+ const f = Math.min(w, h) * 0.22;
108
+ return { tag, attr: 'd', value: D([['M', x, y], ['L', r - f, y], ['L', r, y + f], ['L', r, b], ['L', x, b], ['Z'], ['M', r - f, y], ['L', r - f, y + f], ['L', r, y + f]]) };
109
+ }
110
+ case 'cloud': {
111
+ // eight bumps between points on an inner ellipse, each bulging out to the box
112
+ const n = 8; const ix = w * 0.36; const iy = h * 0.34;
113
+ const at = (k) => { const a = (k / n) * 2 * Math.PI - Math.PI / 2; return [cx + ix * Math.cos(a), cy + iy * Math.sin(a)]; };
114
+ const clampX = (v) => Math.min(r, Math.max(x, v)); const clampY = (v) => Math.min(b, Math.max(y, v));
115
+ const out = (p, a) => [clampX(cx + (p[0] - cx) * a), clampY(cy + (p[1] - cy) * a)];
116
+ const cmds = [['M', ...at(0)]];
117
+ for (let k = 0; k < n; k++) {
118
+ const p = at(k); const q = at(k + 1);
119
+ cmds.push(['C', ...out(p, 1.9), ...out(q, 1.9), ...q]);
120
+ }
121
+ cmds.push(['Z']);
122
+ return { tag, attr: 'd', value: D(cmds) };
123
+ }
124
+ default: return null;
125
+ }
126
+ }
127
+
128
+ /** The numbers of a polygon's `points` or a path's `d`, as `[x, y]` pairs (absolute commands only: H and V read with the pen). */
129
+ function pairsOf(attr, value) {
130
+ const src = String(value ?? '');
131
+ if (attr === 'points') {
132
+ const n = src.trim().split(/[\s,]+/).filter(Boolean).map(Number);
133
+ const out = [];
134
+ for (let i = 0; i + 1 < n.length; i += 2) out.push([n[i], n[i + 1]]);
135
+ return out;
136
+ }
137
+ return flatten(src, { curves: false }).flat();
138
+ }
139
+
140
+ /**
141
+ * The box a shape's geometry fills, `{ x, y, w, h }`, read from its numbers
142
+ * (shapeGeometry keeps every one inside and reaches each edge): what a resize
143
+ * starts from. Null when there are none.
144
+ */
145
+ export function shapeBox(attr, value) {
146
+ const pts = pairsOf(attr, value).filter(([a, c]) => Number.isFinite(a) && Number.isFinite(c));
147
+ if (!pts.length) return null;
148
+ const xs = pts.map((p) => p[0]); const ys = pts.map((p) => p[1]);
149
+ const x = Math.min(...xs); const y = Math.min(...ys);
150
+ return { x, y, w: Math.max(...xs) - x, h: Math.max(...ys) - y };
151
+ }
152
+
153
+ /**
154
+ * Path data in absolute M, L, H, V, C, Q and Z as its subpaths, each a list
155
+ * of `[x, y]`: a curve sampled into `steps` points when `curves`, else its
156
+ * control points and its end as they are (the numbers, for shapeBox).
157
+ */
158
+ export function flatten(d, { curves = true, steps = 10 } = {}) {
159
+ const tokens = String(d ?? '').match(/[MLHVCQZ]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi) ?? [];
160
+ const subs = []; let cur = null; let pen = [0, 0]; let start = [0, 0]; let cmd = null; let args = [];
161
+ const need = { M: 2, L: 2, H: 1, V: 1, C: 6, Q: 4, Z: 0 };
162
+ const run = () => {
163
+ const c = cmd?.toUpperCase();
164
+ if (!c) return;
165
+ if (c === 'Z') { if (cur) cur.push([...start]); pen = [...start]; return; }
166
+ for (let i = 0; i + need[c] <= args.length && need[c]; i += need[c]) {
167
+ const a = args.slice(i, i + need[c]);
168
+ if (c === 'M' && i === 0) { cur = [[a[0], a[1]]]; subs.push(cur); pen = [a[0], a[1]]; start = [...pen]; continue; }
169
+ cur ??= (subs.push([[...pen]]), subs.at(-1));
170
+ if (c === 'M' || c === 'L') pen = [a[0], a[1]];
171
+ else if (c === 'H') pen = [a[0], pen[1]];
172
+ else if (c === 'V') pen = [pen[0], a[0]];
173
+ if (c === 'M' || c === 'L' || c === 'H' || c === 'V') { cur.push([...pen]); continue; }
174
+ const p0 = pen;
175
+ const ctl = c === 'C' ? [[a[0], a[1]], [a[2], a[3]]] : [[a[0], a[1]]];
176
+ const end = c === 'C' ? [a[4], a[5]] : [a[2], a[3]];
177
+ if (!curves) cur.push(...ctl, end);
178
+ else {
179
+ for (let s = 1; s <= steps; s++) {
180
+ const t = s / steps; const u = 1 - t;
181
+ cur.push(c === 'C'
182
+ ? [u ** 3 * p0[0] + 3 * u * u * t * ctl[0][0] + 3 * u * t * t * ctl[1][0] + t ** 3 * end[0], u ** 3 * p0[1] + 3 * u * u * t * ctl[0][1] + 3 * u * t * t * ctl[1][1] + t ** 3 * end[1]]
183
+ : [u * u * p0[0] + 2 * u * t * ctl[0][0] + t * t * end[0], u * u * p0[1] + 2 * u * t * ctl[0][1] + t * t * end[1]]);
184
+ }
185
+ }
186
+ pen = end;
187
+ }
188
+ };
189
+ for (const tk of tokens) {
190
+ if (/^[MLHVCQZ]$/i.test(tk)) { run(); cmd = tk; args = []; } else args.push(Number(tk));
191
+ }
192
+ run();
193
+ return subs;
194
+ }
195
+
196
+ /** A shape's outline as one closed list of points: its polygon, or the first subpath of its path, curves sampled. */
197
+ export function outlineOf(attr, value) {
198
+ if (attr === 'points') return pairsOf('points', value);
199
+ return flatten(value)[0] ?? [];
200
+ }
201
+
202
+ /**
203
+ * Where a ray from `c` toward `p` first leaves `outline` (points, closed):
204
+ * what a wire stops at on a shape that is not a box. Null when the ray
205
+ * meets no edge (c outside it, or an outline of no size).
206
+ */
207
+ export function outlineToward(outline, c, p) {
208
+ const dx = p.x - c.x; const dy = p.y - c.y;
209
+ if ((!dx && !dy) || outline.length < 2) return null;
210
+ let best = Infinity;
211
+ for (let i = 0; i < outline.length; i++) {
212
+ const [ax, ay] = outline[i]; const [bx, by] = outline[(i + 1) % outline.length];
213
+ const ex = bx - ax; const ey = by - ay;
214
+ const den = dx * ey - dy * ex;
215
+ if (Math.abs(den) < 1e-12) continue;
216
+ const t = ((ax - c.x) * ey - (ay - c.y) * ex) / den;
217
+ const s = ((ax - c.x) * dy - (ay - c.y) * dx) / den;
218
+ if (t > 1e-9 && s >= -1e-9 && s <= 1 + 1e-9 && t < best) best = t;
219
+ }
220
+ return Number.isFinite(best) ? { x: c.x + dx * best, y: c.y + dy * best } : null;
221
+ }
@@ -17,17 +17,18 @@
17
17
  // chose ElevenLabs and lets your environment remember the secret.
18
18
 
19
19
  import { wavFromPcm } from './gemini-tts.mjs';
20
+ import { styleTag } from './tone-cue.mjs';
20
21
 
21
22
  export const KEY_ENV = 'ELEVENLABS_API_KEY';
22
23
  const API = 'https://api.elevenlabs.io/v1';
23
24
 
24
- // eleven_v4 is the default: it reads the audio tags a script is written with
25
- // ([whispers], [laughs], [long pause]) as direction, follows them more
26
- // reliably than v3, and answers sooner. --tts-model eleven_v4_turbo trades a
27
- // little quality for latency; eleven_multilingual_v2 is the pre-tag voice.
25
+ // eleven_v4_turbo is the default: it reads the audio tags a script is written
26
+ // with ([whispers], [laughs], [long pause]) as direction, follows them more
27
+ // reliably than v3, and answers soonest. --tts-model eleven_v4 trades that
28
+ // latency for a little more quality; eleven_multilingual_v2 is the pre-tag voice.
28
29
  // A track already recorded keeps the model its manifest names — voiceover
29
30
  // reads it back — so changing this default re-voices nothing.
30
- export const DEFAULT_MODEL = 'eleven_v4';
31
+ export const DEFAULT_MODEL = 'eleven_v4_turbo';
31
32
 
32
33
  // v3 was the first ElevenLabs model to read bracketed audio tags as
33
34
  // performance direction instead of words to pronounce; v4 follows them more
@@ -39,39 +40,40 @@ export const TAG_MODELS = ['eleven_v3', 'eleven_v4', 'eleven_v4_turbo'];
39
40
  /** Does this ElevenLabs model act on `[whispers]`-style audio tags? */
40
41
  export const readsAudioTags = (model) => TAG_MODELS.includes(model);
41
42
 
42
- // v3's stability slider is not the continuous 0–1 knob older models expose —
43
- // ElevenLabs documents exactly these three named positions. Creative follows
44
- // a tag hardest and drifts most; Robust barely moves and mostly ignores tags;
45
- // Natural is the middle ground. Unnamed values are refused rather than
46
- // silently rounded to the nearest preset.
47
- export const STABILITY_PRESETS = { creative: 0, natural: 0.5, robust: 1 };
48
-
49
- // A tag this long stops being a short performance cue and starts being a
50
- // second sentence — cut it back rather than let it run on. 40 chars covers
51
- // every named ElevenLabs tag with room for a typed phrase like "on the verge
52
- // of tears" and still reads as direction, not dialogue.
53
- const MAX_TAG_LEN = 40;
43
+ // The models that are sent `language_code`. Left to itself a model guesses the
44
+ // language from the text, and a beat that is a product name, a number or two
45
+ // words is exactly the text it guesses wrong. A model outside this list is
46
+ // sent none, as before: eleven_multilingual_v2 does not take the field.
47
+ export const LANGUAGE_MODELS = [...TAG_MODELS, 'eleven_turbo_v2_5', 'eleven_flash_v2_5'];
54
48
 
55
49
  /**
56
- * A `style` string, or free-typed text, as a single ElevenLabs v3 audio tag —
57
- * or '' if there is nothing to say.
58
- *
59
- * Someone who already knows v3 syntax can type `[whispers]` and get exactly
60
- * that cue: the first well-formed bracketed group survives untouched (and
61
- * only the first — a second `[…]` later in the string would be a second cue
62
- * riding along uninvited, so everything after the first close-bracket is
63
- * dropped). Anyone else just types a word or a short phrase, which is wrapped
64
- * in brackets for them. Either way the result is capped to MAX_TAG_LEN so a
65
- * persona too long to be a cue is cut back rather than spoken.
50
+ * The `language_code` a deck's language asks of `model`, or undefined: the
51
+ * two-letter code of a deck that is not in English, on a model that takes one.
52
+ * English is sent nothing, which is what every deck was sent before the
53
+ * language reached the voice: an English take recorded then is still the take.
66
54
  */
67
- export function styleTag(style, maxLen = MAX_TAG_LEN) {
68
- const raw = String(style ?? '').trim();
69
- if (!raw) return '';
70
- const bracketed = raw.match(/^\[([^[\]]+)\]/);
71
- const cue = (bracketed ? bracketed[1] : raw).trim().slice(0, maxLen).trim();
72
- return cue ? `[${cue}]` : '';
55
+ export function languageCode(model, lang) {
56
+ const code = String(lang ?? '').trim().split(/[-_]/)[0].toLowerCase();
57
+ return /^[a-z]{2}$/.test(code) && code !== 'en' && LANGUAGE_MODELS.includes(model) ? code : undefined;
73
58
  }
74
59
 
60
+ // The tag models' stability slider is not the continuous 0–1 knob older
61
+ // models expose: ElevenLabs documents exactly these three named positions.
62
+ // Creative follows a tag hardest and drifts most; Robust barely moves and
63
+ // mostly ignores tags; Natural is the middle ground. Unnamed values are
64
+ // refused rather than silently rounded to the nearest preset.
65
+ export const STABILITY_PRESETS = { creative: 0, natural: 0.5, robust: 1 };
66
+
67
+ // A very short input is where a tag model is least stable: ElevenLabs' own
68
+ // guidance, and how "You ask, it answers." came back as "You ask, you ask, it
69
+ // answers" (#1005). Below this many characters a sentence goes at Robust,
70
+ // unless --tts-stability chose a position for every sentence.
71
+ export const SHORT_TEXT = 60;
72
+
73
+ // The tag a tone becomes, and where it is cut, live with the built-in tones:
74
+ // the deck's tone picker needs both too (tools/tone-cue.mjs).
75
+ export { styleTag, cutTag, cueFor, MAX_TAG_LEN } from './tone-cue.mjs';
76
+
75
77
  // PCM is what the rest of decklight is built on: the deck's recorder stitches per-slide WAVs
76
78
  // out of the sentence cache, and rhubarb reads WAV to find visemes. mp3 plays
77
79
  // perfectly well in the deck but does neither, so it is opt-in rather than a
@@ -159,10 +161,12 @@ export function pickVoice(roster, requested) {
159
161
  if (!requested) return roster[0];
160
162
  const squash = (t) => String(t).trim().toLowerCase().replace(/\s+/g, '');
161
163
  const want = String(requested).trim().toLowerCase();
162
- const exact = roster.find((v) => v.id === requested)
163
- ?? roster.find((v) => v.name.toLowerCase() === want)
164
- ?? roster.find((v) => squash(v.name) === squash(want));
165
- if (exact) return exact;
164
+ const byId = roster.find((v) => v.id === requested);
165
+ if (byId) return byId;
166
+ const exact = roster.filter((v) => v.name.toLowerCase() === want);
167
+ if (exact.length) return exact.length === 1 ? exact[0] : null;
168
+ const normalized = roster.filter((v) => squash(v.name) === squash(want));
169
+ if (normalized.length) return normalized.length === 1 ? normalized[0] : null;
166
170
  const byShortName = roster.filter((v) => squash(shortName(v.name)) === squash(want));
167
171
  return byShortName.length === 1 ? byShortName[0] : null;
168
172
  }
@@ -184,8 +188,8 @@ export function synthError(status, body, { format = 'pcm' } = {}) {
184
188
  }
185
189
  if (format === 'pcm' && /output_format|pcm|tier|subscription/i.test(text)) {
186
190
  return 'ElevenLabs will not serve pcm_24000 on this plan (PCM output is a paid tier). '
187
- + 'Pass --tts-format mp3 to use mp3 instead — the deck plays it fine, but the panel\'s Record this deck… offline '
188
- + 'recording and the lip-sync bridge both need WAV and will not work with it.';
191
+ + 'Pass --tts-format mp3 to use mp3 instead — the deck plays it fine, but the panel\'s Save with the deck '
192
+ + 'and the lip-sync bridge both need WAV and will not work with it.';
189
193
  }
190
194
  if (status === 429) return 'ElevenLabs rate limit (429) — the lookahead buffer is bursty; try a smaller deck or wait';
191
195
  return `${status} ${text}`;
@@ -202,8 +206,9 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
202
206
  * probe rather than needing a restart.
203
207
  */
204
208
  export function createSynth({
205
- key, model = DEFAULT_MODEL, format = 'pcm', stability, fetchImpl = fetch,
209
+ key, model = DEFAULT_MODEL, format = 'pcm', stability, lang, fetchImpl = fetch,
206
210
  } = {}) {
211
+ const language = languageCode(model, lang);
207
212
  if (!key) {
208
213
  throw new Error(`ElevenLabs needs an API key — set $${KEY_ENV} `
209
214
  + '(create one at https://elevenlabs.io/app/settings/api-keys)');
@@ -213,8 +218,8 @@ export function createSynth({
213
218
  // up front, at construction, rather than accepted and quietly doing nothing.
214
219
  let stabilityValue;
215
220
  if (stability != null) {
216
- if (model !== V3_MODEL) {
217
- throw new Error(`--tts-stability is a v3 feature — pass --tts-model ${V3_MODEL}, or drop --tts-stability`);
221
+ if (!readsAudioTags(model)) {
222
+ throw new Error(`--tts-stability is a v3/v4 feature — pass --tts-model ${DEFAULT_MODEL}, or drop --tts-stability`);
218
223
  }
219
224
  stabilityValue = STABILITY_PRESETS[stability];
220
225
  if (stabilityValue == null) {
@@ -224,16 +229,16 @@ export function createSynth({
224
229
  const headers = { 'xi-api-key': key };
225
230
 
226
231
  let roster = null;
227
- function listVoices() {
232
+ function listVoices({ refresh = false } = {}) {
233
+ if (refresh) roster = null;
228
234
  roster ??= (async () => {
229
235
  const res = await fetchImpl(`${API}/voices`, { headers });
230
236
  if (!res.ok) throw new Error(synthError(res.status, await res.text(), { format }));
231
- const shaped = shapeVoices(await res.json());
232
- if (!shaped.length) throw new Error('ElevenLabs returned no voices for this key');
233
- return shaped;
237
+ return shapeVoices(await res.json());
234
238
  })();
235
- roster.catch(() => { roster = null; });
236
- return roster;
239
+ const pending = roster;
240
+ pending.catch(() => { if (roster === pending) roster = null; });
241
+ return pending;
237
242
  }
238
243
 
239
244
  /**
@@ -275,11 +280,13 @@ export function createSynth({
275
280
  return { id: j.voice_id ?? id, name };
276
281
  }
277
282
 
278
- async function call(text, voice) {
279
- const payload = { text, model_id: model };
283
+ async function call(text, voice, short) {
284
+ const payload = { text, model_id: model, ...(language ? { language_code: language } : {}) };
280
285
  // Unasked, the account's own voice settings are left alone — sending a
281
286
  // voice_settings object at all overrides them, even to "no opinion".
282
- if (stabilityValue != null) payload.voice_settings = { stability: stabilityValue };
287
+ // The one exception is a short sentence on a tag model, held at Robust.
288
+ const stable = stabilityValue ?? (short ? STABILITY_PRESETS.robust : null);
289
+ if (stable != null) payload.voice_settings = { stability: stable };
283
290
  const res = await fetchImpl(
284
291
  `${API}/text-to-speech/${encodeURIComponent(voice.id)}?output_format=${OUTPUT[format]}`,
285
292
  {
@@ -310,11 +317,12 @@ export function createSynth({
310
317
  // is NEVER attached unless this is a model that can act on it.
311
318
  const tag = readsAudioTags(model) ? styleTag(style) : '';
312
319
  const sent = tag ? `${tag} ${text}` : text;
320
+ const short = readsAudioTags(model) && String(text).trim().length < SHORT_TEXT;
313
321
  let lastErr;
314
322
  for (let attempt = 0; attempt < 3; attempt++) {
315
323
  try {
316
324
  return {
317
- wav: await call(sent, picked),
325
+ wav: await call(sent, picked, short),
318
326
  usage: {
319
327
  model,
320
328
  // Billed on what actually went out — the tag rides inside the same
@@ -325,7 +333,8 @@ export function createSynth({
325
333
  // the per-character rate depends on a tier we cannot see. Reporting a
326
334
  // dollar figure would be inventing one, so the bridge shows characters.
327
335
  cost: 0,
328
- note: tag ? `${sent.length} chars · ${picked.name} · ${tag}` : `${sent.length} chars · ${picked.name}`,
336
+ note: [`${sent.length} chars`, picked.name, tag, short && stabilityValue == null ? 'robust (short)' : '']
337
+ .filter(Boolean).join(' · '),
329
338
  },
330
339
  };
331
340
  } catch (e) {
@@ -0,0 +1,96 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Your face, filmed while you recorded the deck (PRESENTING, the your-voice
5
+ // recorder), made into the clips the character plays and `decklight video`
6
+ // composes: slide-NN-KK.mp4 beside each beat's slide-NN-KK.wav, and
7
+ // slide-NN.mp4 joined from them beside the whole-slide file.
8
+ //
9
+ // The browser films with MediaRecorder: webm in Chrome, mp4 in Safari, a
10
+ // variable frame rate in both, and a start that lands a few frames after the
11
+ // audio's. So every clip is made the same thing here: H.264, 25 fps, no sound
12
+ // (the voice is the WAV's), and exactly as long as the beat's WAV, cut or held
13
+ // on its last frame. A clip a tenth of a second long or short is invisible on
14
+ // one beat and a visible drift by the end of a slide of eight; the WAV is the
15
+ // clock both players already follow.
16
+
17
+ import { existsSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
18
+ import { runAsync, CODEC_MS, PROBE_MS } from './exec.mjs';
19
+
20
+ export const FACE_FPS = 25;
21
+
22
+ /** The seconds a 16-bit PCM WAV runs, from its own header; null when it is not one. */
23
+ export function wavSeconds(buf) {
24
+ if (!buf || buf.length < 12 || buf.toString('ascii', 0, 4) !== 'RIFF' || buf.toString('ascii', 8, 12) !== 'WAVE') return null;
25
+ let byteRate = 0;
26
+ for (let at = 12; at + 8 <= buf.length;) {
27
+ const id = buf.toString('ascii', at, at + 4);
28
+ const size = buf.readUInt32LE(at + 4);
29
+ if (id === 'fmt ' && at + 16 <= buf.length) byteRate = buf.readUInt32LE(at + 16);
30
+ if (id === 'data') return byteRate ? Math.min(size, buf.length - at - 8) / byteRate : null;
31
+ at += 8 + size + (size % 2);
32
+ }
33
+ return null;
34
+ }
35
+
36
+ /**
37
+ * ffmpeg argv: one filmed take → a clip of exactly `seconds`. `tpad` holds the
38
+ * last frame long enough for a take that came in short, and `-t` cuts one
39
+ * that came in long. Even dimensions, because yuv420p refuses odd ones.
40
+ */
41
+ export function faceClipArgs({ input, out, seconds }) {
42
+ const t = Math.max(0.04, Number(seconds) || 0).toFixed(3);
43
+ return ['-y', '-loglevel', 'error', '-i', input, '-an',
44
+ '-vf', `fps=${FACE_FPS},scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=1,tpad=stop_mode=clone:stop_duration=${t}`,
45
+ '-t', t, '-c:v', 'libx264', '-preset', 'veryfast', '-crf', '20', '-pix_fmt', 'yuv420p',
46
+ '-movflags', '+faststart', out];
47
+ }
48
+
49
+ /** ffmpeg argv: the beats' clips, made alike by faceClipArgs, joined without re-encoding. */
50
+ export function faceJoinArgs({ list, out }) {
51
+ return ['-y', '-loglevel', 'error', '-f', 'concat', '-safe', '0', '-i', list, '-c', 'copy', '-movflags', '+faststart', out];
52
+ }
53
+
54
+ /** Is there an ffmpeg to make clips with? */
55
+ export async function hasFfmpeg({ env = process.env } = {}) {
56
+ try { await runAsync('ffmpeg', ['-version'], { timeout: PROBE_MS, env }); return true; } catch { return false; }
57
+ }
58
+
59
+ /**
60
+ * Write `out` from the filmed `bytes`, as long as the WAV at `wav` (or as
61
+ * filmed, when there is no WAV to measure). The take goes through a scratch
62
+ * file beside `out`, since ffmpeg reads a webm's duration by seeking in it.
63
+ */
64
+ export async function writeFaceClip({ bytes, out, wav = null, env = process.env }) {
65
+ let seconds = null;
66
+ if (wav && existsSync(wav)) seconds = wavSeconds(readFileSync(wav));
67
+ const raw = `${out}.take`;
68
+ const tmp = out.replace(/\.mp4$/, '.tmp.mp4');
69
+ writeFileSync(raw, bytes);
70
+ try {
71
+ const args = seconds == null
72
+ ? ['-y', '-loglevel', 'error', '-i', raw, '-an', '-vf', `fps=${FACE_FPS},scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=1`,
73
+ '-c:v', 'libx264', '-preset', 'veryfast', '-crf', '20', '-pix_fmt', 'yuv420p', '-movflags', '+faststart', tmp]
74
+ : faceClipArgs({ input: raw, out: tmp, seconds });
75
+ await runAsync('ffmpeg', args, { timeout: CODEC_MS, env, why: 'making a filmed beat into a clip' });
76
+ renameSync(tmp, out);
77
+ } finally {
78
+ rmSync(raw, { force: true });
79
+ rmSync(tmp, { force: true });
80
+ }
81
+ return { seconds };
82
+ }
83
+
84
+ /** Join `parts` (paths, in order) into `out`. */
85
+ export async function joinFaceClips({ parts, out, env = process.env }) {
86
+ const list = `${out}.list.txt`;
87
+ const tmp = out.replace(/\.mp4$/, '.tmp.mp4');
88
+ writeFileSync(list, parts.map((p) => `file '${p.replaceAll("'", "'\\''")}'`).join('\n') + '\n');
89
+ try {
90
+ await runAsync('ffmpeg', faceJoinArgs({ list, out: tmp }), { timeout: CODEC_MS, env, why: 'joining the filmed beats of a slide' });
91
+ renameSync(tmp, out);
92
+ } finally {
93
+ rmSync(list, { force: true });
94
+ rmSync(tmp, { force: true });
95
+ }
96
+ }
@@ -0,0 +1,94 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Where a filmed face shows on a slide, and from which beat (FACE_LAYOUT):
5
+ // the `data-face` attribute on a <section>. ONE reader, for the two places
6
+ // that place the face: the deck's character overlay (src/core/character.js,
7
+ // which bundles this the way src/core/review.js bundles review-anchor.mjs)
8
+ // and `decklight video`, which composes it into the frames. Written twice,
9
+ // a slide would be full screen in the deck and in the corner of its video.
10
+ //
11
+ // data-face="full" your face fills the screen, the slide steps aside
12
+ // data-face="full 1.4" …zoomed in 1.4×, on the face
13
+ // data-face="hide" no face on this slide; the voice still plays
14
+ // data-face="top-right" the medallion, in that corner for this slide
15
+ // (top-left, top-right, bottom-left, bottom-right)
16
+ // data-face="hide 3:full 1.5 4:corner"
17
+ // hidden for beats 1-2, full screen at 1.5× from
18
+ // beat 3, the medallion again from beat 4
19
+ //
20
+ // A beat is a [click] beat of the slide's notes, counted the way the recorder
21
+ // counts them ("beat 3 of 4") and numbered like its files (slide-NN-03.wav).
22
+ // A value holds until the next one. No attribute, or one that says nothing
23
+ // this understands, is the corner: the medallion, as the deck has always
24
+ // shown it.
25
+ //
26
+ // No imports and no DOM.
27
+
28
+ export const FACE_KINDS = ['corner', 'hide', 'full'];
29
+ export const FACE_ZOOM_MAX = 4;
30
+
31
+ /** `corner`, the default, at no zoom. */
32
+ export const FACE_CORNER = Object.freeze({ kind: 'corner', zoom: 1 });
33
+
34
+ /**
35
+ * The medallion's four named corners, and the short form the character's
36
+ * `pos-*` classes use. A named corner is `corner` in a place of its own; a
37
+ * bare `corner` is wherever the deck puts the character.
38
+ */
39
+ export const FACE_CORNERS = Object.freeze({ 'top-left': 'tl', 'top-right': 'tr', 'bottom-left': 'bl', 'bottom-right': 'br' });
40
+
41
+ /**
42
+ * `data-face` → its rules, earliest beat first: `[{ from, kind, zoom }]`, and
43
+ * the tokens it could not read (for a check that wants to say so).
44
+ */
45
+ export function parseFaceLayout(attr) {
46
+ const rules = [];
47
+ const bad = [];
48
+ let from = 1;
49
+ for (const raw of String(attr ?? '').trim().split(/\s+/).filter(Boolean)) {
50
+ const tok = raw.toLowerCase();
51
+ const at = /^(\d+):(.*)$/.exec(tok);
52
+ const word = at ? at[2] : tok;
53
+ if (at) from = Math.max(1, Number(at[1]));
54
+ // a zoom belongs to the `full` before it: `full 1.4`, `full 1.4x`, `full ×1.4`
55
+ const zoom = /^[x×]?(\d+(?:\.\d+)?)[x×]?$/.exec(word);
56
+ if (zoom && !at) {
57
+ const last = rules[rules.length - 1];
58
+ if (last?.kind === 'full') { last.zoom = Math.min(FACE_ZOOM_MAX, Math.max(1, Number(zoom[1]))); continue; }
59
+ bad.push(raw);
60
+ continue;
61
+ }
62
+ const named = FACE_CORNERS[word];
63
+ if (!named && !FACE_KINDS.includes(word)) { bad.push(raw); continue; }
64
+ const rule = named ? { from, kind: 'corner', zoom: 1, at: named } : { from, kind: word, zoom: 1 };
65
+ // a later rule for the same beat replaces the earlier one
66
+ const same = rules.findIndex((r) => r.from === from);
67
+ if (same >= 0) rules[same] = rule; else rules.push(rule);
68
+ }
69
+ rules.sort((a, b) => a.from - b.from);
70
+ return { rules, bad };
71
+ }
72
+
73
+ /** How the face shows on `beat` (1-based) of a slide whose section says `attr`. */
74
+ export function faceLayout(attr, beat = 1) {
75
+ const { rules } = parseFaceLayout(attr);
76
+ let at = FACE_CORNER;
77
+ for (const r of rules) if (r.from <= (beat ?? 1)) at = { kind: r.kind, zoom: r.zoom, ...(r.at ? { at: r.at } : {}) };
78
+ return at;
79
+ }
80
+
81
+ /**
82
+ * One placement for a whole slide, written back as `data-face` (the V panel's
83
+ * the panel's Where…): '' for the default corner, which is no attribute at all.
84
+ * The inverse of faceLayout for a slide-wide value.
85
+ */
86
+ export function faceValue({ kind, zoom = 1, at } = {}) {
87
+ if (kind === 'hide') return 'hide';
88
+ if (kind === 'full') {
89
+ const z = Math.min(FACE_ZOOM_MAX, Math.max(1, Number(zoom) || 1));
90
+ return z === 1 ? 'full' : `full ${z}`;
91
+ }
92
+ const name = Object.keys(FACE_CORNERS).find((k) => FACE_CORNERS[k] === at);
93
+ return name ?? '';
94
+ }
@@ -69,7 +69,7 @@ function estimateCost(model, usage) {
69
69
  /**
70
70
  * Wrap headerless 16-bit mono PCM in a RIFF/WAVE header. Every engine that
71
71
  * gets raw samples back lands here (Gemini's audio/L16, ElevenLabs' pcm_24000)
72
- * — WAV is what the deck's recorder (V → Record this deck…) stitching and the lip-sync bridge both read.
72
+ * — WAV is what the deck's recorder (V → Save with the deck) stitching and the lip-sync bridge both read.
73
73
  */
74
74
  export function wavFromPcm(pcm, rate) {
75
75
  const h = Buffer.alloc(44);
@@ -0,0 +1,27 @@
1
+ // Copyright 2026 Gilles Philippart
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * What `invisible-in-print` says (#1184): one sentence for `decklight pdf`,
6
+ * `decklight check` and the Check deck… panel, so the three read alike. Pure,
7
+ * and here rather than in src/ for the reason tools/click-match.mjs gives:
8
+ * cli/ never imports src/, src/ may import a tool.
9
+ */
10
+
11
+ /** What usually makes such a hole, and the way out of it. */
12
+ export const INVISIBLE_ADVICE = 'print shows an entrance the deck animates with its own CSS as it ends, '
13
+ + 'and this one does not end visible: make it a build (SPEC BUILDS), or mark it data-invisible-ok if it is meant';
14
+
15
+ /**
16
+ * The element a slide does not show and how many more: `a box “Batch”
17
+ * (opacity 0), and 1 more element`. `what` is the runtime's naming
18
+ * (`data-invisible`), '' for nothing.
19
+ */
20
+ export function invisibleSaidOf(what, more = 0) {
21
+ if (!what) return '';
22
+ const n = Number(more);
23
+ return `${what}${n > 0 ? `, and ${n} more element${n === 1 ? '' : 's'}` : ''}`;
24
+ }
25
+
26
+ /** The finding's message, as `check` prints it. */
27
+ export const invisibleMessage = (said) => `invisible in print: ${said} — ${INVISIBLE_ADVICE}`;