decklight 0.1.0 → 0.3.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.
- package/LICENSE +202 -21
- package/README.md +105 -183
- package/SPEC.md +861 -74
- package/cli/agents.mjs +206 -0
- package/cli/associate.mjs +279 -0
- package/cli/audit.mjs +424 -0
- package/cli/bundle.mjs +210 -45
- package/cli/deckfile.mjs +233 -0
- package/cli/decklight.mjs +216 -5
- package/cli/dev.mjs +455 -0
- package/cli/edit.mjs +733 -63
- package/cli/extension.mjs +108 -0
- package/cli/git.mjs +141 -0
- package/cli/import.mjs +398 -0
- package/cli/init.mjs +465 -121
- package/cli/loader.mjs +263 -0
- package/cli/marketplace.mjs +730 -0
- package/cli/pdf.mjs +156 -0
- package/cli/pkg.mjs +69 -0
- package/cli/plugin.mjs +646 -0
- package/cli/port-conflict.mjs +94 -0
- package/cli/present.mjs +560 -0
- package/cli/publish.mjs +342 -0
- package/cli/qr.mjs +334 -0
- package/cli/rec.mjs +12 -8
- package/cli/remote.mjs +149 -0
- package/cli/report-bug.mjs +97 -0
- package/cli/restore.mjs +174 -0
- package/cli/serve.mjs +247 -0
- package/cli/sign.mjs +216 -0
- package/cli/skill-content.mjs +222 -0
- package/cli/skills.mjs +338 -0
- package/cli/supervise.mjs +57 -0
- package/cli/theme.mjs +201 -0
- package/cli/units.mjs +488 -0
- package/cli/upgrade.mjs +250 -0
- package/cli/util.mjs +90 -0
- package/cli/wizard.mjs +432 -0
- package/cli/zip.mjs +121 -0
- package/dist/decklight.css +949 -72
- package/dist/decklight.js +220 -103
- package/dist/decklight.js.map +4 -4
- package/docs/architecture.svg +1 -1
- package/package.json +9 -6
- package/themes/README.md +6 -4
- package/themes/aurora.css +4 -1
- package/themes/berry.css +4 -1
- package/themes/carbon.css +4 -1
- package/themes/citrus.css +4 -1
- package/themes/coastal.css +4 -1
- package/themes/cosmos.css +4 -1
- package/themes/dune.css +4 -1
- package/themes/eclipse.css +4 -1
- package/themes/ember.css +4 -1
- package/themes/fjord.css +4 -1
- package/themes/gallery.html +3 -11
- package/themes/glacier.css +4 -1
- package/themes/graphite.css +4 -1
- package/themes/harvest.css +4 -1
- package/themes/ibm-modern.css +4 -1
- package/themes/ink.css +4 -1
- package/themes/latte.css +4 -1
- package/themes/linen.css +4 -1
- package/themes/meadow.css +4 -1
- package/themes/metropolis.css +4 -1
- package/themes/midnight.css +4 -1
- package/themes/mint.css +4 -1
- package/themes/moss.css +4 -1
- package/themes/obsidian.css +4 -1
- package/themes/orchid.css +4 -1
- package/themes/packs.json +4 -31
- package/themes/paper.css +4 -1
- package/themes/peony.css +4 -1
- package/themes/porcelain.css +4 -1
- package/themes/reveal-beige.css +4 -1
- package/themes/reveal-black.css +4 -1
- package/themes/reveal-blood.css +4 -1
- package/themes/reveal-dracula.css +4 -1
- package/themes/reveal-league.css +4 -1
- package/themes/reveal-moon.css +4 -1
- package/themes/reveal-night.css +4 -1
- package/themes/reveal-serif.css +4 -1
- package/themes/reveal-simple.css +4 -1
- package/themes/reveal-sky.css +4 -1
- package/themes/reveal-solarized.css +4 -1
- package/themes/reveal-white.css +4 -1
- package/themes/sepia.css +4 -1
- package/themes/seriph.css +4 -1
- package/themes/slate.css +4 -1
- package/themes/storm.css +4 -1
- package/themes/synthwave.css +4 -1
- package/themes/velvet.css +4 -1
- package/themes/yamabuki.css +120 -0
- package/tools/args.mjs +32 -0
- package/tools/bridge.mjs +30 -0
- package/tools/chrome.mjs +52 -0
- package/tools/color.mjs +110 -0
- package/tools/deck-html.mjs +138 -0
- package/tools/elevenlabs-tts.mjs +248 -0
- package/tools/escape.mjs +40 -0
- package/tools/extension-check-runner.mjs +41 -0
- package/tools/extension-check.mjs +266 -0
- package/tools/gemini-tts.mjs +44 -4
- package/tools/lipsync-engines.mjs +81 -0
- package/tools/lipsync-server.mjs +290 -0
- package/tools/lipsync.mjs +181 -0
- package/tools/local-voice.mjs +209 -0
- package/tools/ooxml.mjs +151 -0
- package/tools/pptx.mjs +320 -0
- package/tools/publish-site-voices.mjs +5 -1
- package/tools/publish-targets.mjs +143 -0
- package/tools/publish-voices.mjs +230 -0
- package/tools/shot.mjs +129 -0
- package/tools/theme-check.mjs +139 -0
- package/tools/tts-engines.mjs +455 -0
- package/tools/tts-setup.mjs +257 -0
- package/tools/veo.mjs +204 -0
- package/tools/video.mjs +316 -0
- package/tools/visemes.mjs +26 -0
- package/tools/voiceover-server.mjs +0 -0
- package/tools/voiceover.mjs +73 -39
- package/tools/zip.mjs +143 -0
- package/docs/demo.svg +0 -124
- package/themes/aliens.css +0 -84
- package/themes/apple2.css +0 -126
- package/themes/blade-runner.css +0 -83
- package/themes/c64.css +0 -85
- package/themes/friends.css +0 -82
- package/themes/gameboy.css +0 -118
- package/themes/genesis.css +0 -84
- package/themes/godfather.css +0 -82
- package/themes/ibm-oldschool.css +0 -84
- package/themes/miami-vice.css +0 -84
- package/themes/pulp-fiction.css +0 -84
- package/themes/severance.css +0 -82
- package/themes/snes.css +0 -82
- package/themes/star-wars.css +0 -85
- package/themes/stranger-things.css +0 -84
- package/themes/terminator.css +0 -84
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// A deck is a flat list of top-level <section>s — they never nest — so a split
|
|
5
|
+
// on the open tag is exact. Five call sites across cli/ and tools/ each
|
|
6
|
+
// re-derived that shape; this is the one place that knows it, so the slide
|
|
7
|
+
// count video sees and the slide count voiceover's manifest is keyed on can
|
|
8
|
+
// never drift apart. Lives under tools/ because tools/shot.mjs is a consumer
|
|
9
|
+
// and the dependency only ever flows cli/ → tools/.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A section's `<aside class="notes">`. Capture group [1] is the inner HTML (what
|
|
13
|
+
* voiceover pulls); the whole match is what edit tests for and replaces.
|
|
14
|
+
*/
|
|
15
|
+
export const NOTES_ASIDE = /<aside class="notes">([\s\S]*?)<\/aside>/;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Read-only: each slide's `<section>` body, in order (the open tag is dropped).
|
|
19
|
+
* What video and voiceover walk to count slides and pull notes — they MUST see
|
|
20
|
+
* the same list, which is exactly why they share this.
|
|
21
|
+
*/
|
|
22
|
+
export const sectionBodies = (html) => html.split(/<section\b/).slice(1);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Locate slide `n` (1-based) for a round-trip rewrite. Returns the capturing
|
|
26
|
+
* split (`[preamble, '<section', body1, '<section', body2, …]`) and the index
|
|
27
|
+
* of slide n's body segment; throws with the deck's real slide count when n is
|
|
28
|
+
* out of range. The caller rewrites `parts[idx]` and `parts.join('')`s it back.
|
|
29
|
+
*/
|
|
30
|
+
export function locateSlide(html, n) {
|
|
31
|
+
const parts = html.split(/(<section\b)/);
|
|
32
|
+
const idx = 2 * n; // parts[0] preamble, then [tag, body] pairs
|
|
33
|
+
if (!parts[idx]) throw new Error(`no slide ${n} (deck has ${(parts.length - 1) / 2})`);
|
|
34
|
+
return { parts, idx };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Insert `fragment` right before the deck's LAST `</body>`. A bundled deck
|
|
39
|
+
* inlines decklight.js, whose speaker-view popup template carries a literal
|
|
40
|
+
* `</body>` that a first-match search would split mid-string, corrupting the
|
|
41
|
+
* runtime. Returns null when there is no `</body>`, so each caller picks its
|
|
42
|
+
* own fallback (bundle fails; shot appends).
|
|
43
|
+
*/
|
|
44
|
+
export function injectBeforeBodyEnd(html, fragment) {
|
|
45
|
+
const at = html.toLowerCase().lastIndexOf('</body>');
|
|
46
|
+
return at === -1 ? null : html.slice(0, at) + fragment + html.slice(at);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ── a raw section's top-level children (element edit mode, #112) ──────────
|
|
50
|
+
// Void/self-closing tags never open a nesting level, and <script>/<style>
|
|
51
|
+
// bodies are never tag-parsed (a chart's embedded JSON spec is not markup) —
|
|
52
|
+
// between those two, everything else nests by genuine recursion rather than a
|
|
53
|
+
// same-tag-name counter, so a <div> holding another <div>, or an <svg> full of
|
|
54
|
+
// self-closing children, still ends exactly where it should.
|
|
55
|
+
const VOID_ELEMENTS = new Set([
|
|
56
|
+
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
|
57
|
+
'link', 'meta', 'param', 'source', 'track', 'wbr',
|
|
58
|
+
]);
|
|
59
|
+
const OPAQUE_ELEMENTS = new Set(['script', 'style']);
|
|
60
|
+
|
|
61
|
+
function skipComment(html, at) {
|
|
62
|
+
const end = html.indexOf('-->', at + 4);
|
|
63
|
+
return end === -1 ? html.length : end + 3;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function readTagName(html, at) {
|
|
67
|
+
let j = at;
|
|
68
|
+
while (j < html.length && /[a-zA-Z0-9:_-]/.test(html[j])) j++;
|
|
69
|
+
return html.slice(at, j).toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Index of the '>' that closes the tag opening at `at` (html[at] === '<'), skipping quoted attribute values (a `>` inside `"..."` or `'...'` ends nothing). */
|
|
73
|
+
function findTagEnd(html, at) {
|
|
74
|
+
let quote = null;
|
|
75
|
+
for (let j = at + 1; j < html.length; j++) {
|
|
76
|
+
const c = html[j];
|
|
77
|
+
if (quote) { if (c === quote) quote = null; }
|
|
78
|
+
else if (c === '"' || c === "'") quote = c;
|
|
79
|
+
else if (c === '>') return j;
|
|
80
|
+
}
|
|
81
|
+
return html.length - 1;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* One element starting at `start` (html[start] === '<', an opening tag — never
|
|
86
|
+
* '</' or '<!--', which the caller has already stepped past). Recurses into
|
|
87
|
+
* children to find ITS OWN matching close, so nesting depth falls out of the
|
|
88
|
+
* recursion instead of a counter that would have to know every tag name
|
|
89
|
+
* involved. Malformed input (an unclosed tag) ends at the string's end rather
|
|
90
|
+
* than throwing: a best-effort range for a slide someone is mid-edit on.
|
|
91
|
+
*/
|
|
92
|
+
function consumeElement(html, start) {
|
|
93
|
+
const name = readTagName(html, start + 1);
|
|
94
|
+
const tagEnd = findTagEnd(html, start);
|
|
95
|
+
if (html[tagEnd - 1] === '/' || VOID_ELEMENTS.has(name)) {
|
|
96
|
+
return { tag: name, start, end: tagEnd + 1 };
|
|
97
|
+
}
|
|
98
|
+
if (OPAQUE_ELEMENTS.has(name)) {
|
|
99
|
+
const marker = `</${name}`;
|
|
100
|
+
const at = html.toLowerCase().indexOf(marker, tagEnd + 1);
|
|
101
|
+
const end = at === -1 ? html.length : findTagEnd(html, at) + 1;
|
|
102
|
+
return { tag: name, start, end };
|
|
103
|
+
}
|
|
104
|
+
let i = tagEnd + 1;
|
|
105
|
+
while (i < html.length) {
|
|
106
|
+
if (html[i] !== '<') { i++; continue; }
|
|
107
|
+
if (html.startsWith('<!--', i)) { i = skipComment(html, i); continue; }
|
|
108
|
+
if (html[i + 1] === '/') return { tag: name, start, end: findTagEnd(html, i) + 1 };
|
|
109
|
+
i = consumeElement(html, i).end; // a whole child, skipped over regardless of its own name
|
|
110
|
+
}
|
|
111
|
+
return { tag: name, start, end: html.length };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The top-level element children of slide `n`'s raw `<section>` segment (as
|
|
116
|
+
* `locateSlide` returns it in `parts[idx]`), by RAW POSITION — title included,
|
|
117
|
+
* not filtered as chrome the way the engine's own `splitContent()` filters a
|
|
118
|
+
* live, parsed DOM. `start`/`end` are offsets into `seg` itself, so a caller
|
|
119
|
+
* splices directly: `seg.slice(0, r.start) + replacement + seg.slice(r.end)`.
|
|
120
|
+
* Top-level text and comments are not children and never appear in the list.
|
|
121
|
+
*/
|
|
122
|
+
export function sectionChildRanges(seg) {
|
|
123
|
+
const gt = seg.indexOf('>');
|
|
124
|
+
if (gt < 0) throw new Error('malformed <section> tag');
|
|
125
|
+
const close = seg.indexOf('</section>', gt);
|
|
126
|
+
const body = close === -1 ? seg.slice(gt + 1) : seg.slice(gt + 1, close);
|
|
127
|
+
const ranges = [];
|
|
128
|
+
let i = 0;
|
|
129
|
+
while (i < body.length) {
|
|
130
|
+
if (body[i] !== '<') { i++; continue; }
|
|
131
|
+
if (body.startsWith('<!--', i)) { i = skipComment(body, i); continue; }
|
|
132
|
+
if (body[i + 1] === '/') break; // this section's own closing tag
|
|
133
|
+
const el = consumeElement(body, i);
|
|
134
|
+
ranges.push({ tag: el.tag, start: el.start + gt + 1, end: el.end + gt + 1 });
|
|
135
|
+
i = el.end;
|
|
136
|
+
}
|
|
137
|
+
return ranges;
|
|
138
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// ElevenLabs TTS — the engine you reach for when the voice should be YOURS.
|
|
5
|
+
//
|
|
6
|
+
// The other three engines offer a fixed roster: Google's thirty star names, or
|
|
7
|
+
// whichever piper model is on disk. ElevenLabs is the one whose roster is your
|
|
8
|
+
// account's, so a voice you cloned shows up in the deck's N picker beside the
|
|
9
|
+
// stock ones. That is the whole reason it is here, and it is why this engine
|
|
10
|
+
// alone fetches its voices instead of shipping them: they are not knowable
|
|
11
|
+
// until someone's key is in hand.
|
|
12
|
+
//
|
|
13
|
+
// The key is read from $ELEVENLABS_API_KEY and is NEVER written to
|
|
14
|
+
// ~/.config/decklight/tts.json. That file records choices (which engine, which
|
|
15
|
+
// project, which voice) in plain text and is meant to be boring enough to sit
|
|
16
|
+
// in a dotfiles repo. A key is not boring, so decklight remembers that you
|
|
17
|
+
// chose ElevenLabs and lets your environment remember the secret.
|
|
18
|
+
|
|
19
|
+
import { wavFromPcm } from './gemini-tts.mjs';
|
|
20
|
+
|
|
21
|
+
export const KEY_ENV = 'ELEVENLABS_API_KEY';
|
|
22
|
+
const API = 'https://api.elevenlabs.io/v1';
|
|
23
|
+
|
|
24
|
+
// eleven_multilingual_v2 is the quality default and speaks every voice a
|
|
25
|
+
// clone produces; --tts-model eleven_turbo_v2_5 trades a little of it for
|
|
26
|
+
// latency, which live narration may prefer on a long deck.
|
|
27
|
+
export const DEFAULT_MODEL = 'eleven_multilingual_v2';
|
|
28
|
+
|
|
29
|
+
// The only ElevenLabs model that reads bracketed audio tags ([excited],
|
|
30
|
+
// [whispers], …) as performance direction instead of words to pronounce — v3
|
|
31
|
+
// joins the same style channel gemini has always had, opt-in only, because
|
|
32
|
+
// every other model would read the brackets aloud (SPEC PRESENTING).
|
|
33
|
+
export const V3_MODEL = 'eleven_v3';
|
|
34
|
+
|
|
35
|
+
// v3's stability slider is not the continuous 0–1 knob older models expose —
|
|
36
|
+
// ElevenLabs documents exactly these three named positions. Creative follows
|
|
37
|
+
// a tag hardest and drifts most; Robust barely moves and mostly ignores tags;
|
|
38
|
+
// Natural is the middle ground. Unnamed values are refused rather than
|
|
39
|
+
// silently rounded to the nearest preset.
|
|
40
|
+
export const STABILITY_PRESETS = { creative: 0, natural: 0.5, robust: 1 };
|
|
41
|
+
|
|
42
|
+
// A tag this long stops being a short performance cue and starts being a
|
|
43
|
+
// second sentence — cut it back rather than let it run on. 40 chars covers
|
|
44
|
+
// every named ElevenLabs tag with room for a typed phrase like "on the verge
|
|
45
|
+
// of tears" and still reads as direction, not dialogue.
|
|
46
|
+
const MAX_TAG_LEN = 40;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A `style` string, or free-typed text, as a single ElevenLabs v3 audio tag —
|
|
50
|
+
* or '' if there is nothing to say.
|
|
51
|
+
*
|
|
52
|
+
* Someone who already knows v3 syntax can type `[whispers]` and get exactly
|
|
53
|
+
* that cue: the first well-formed bracketed group survives untouched (and
|
|
54
|
+
* only the first — a second `[…]` later in the string would be a second cue
|
|
55
|
+
* riding along uninvited, so everything after the first close-bracket is
|
|
56
|
+
* dropped). Anyone else just types a word or a short phrase, which is wrapped
|
|
57
|
+
* in brackets for them. Either way the result is capped to MAX_TAG_LEN so a
|
|
58
|
+
* persona too long to be a cue is cut back rather than spoken.
|
|
59
|
+
*/
|
|
60
|
+
export function styleTag(style, maxLen = MAX_TAG_LEN) {
|
|
61
|
+
const raw = String(style ?? '').trim();
|
|
62
|
+
if (!raw) return '';
|
|
63
|
+
const bracketed = raw.match(/^\[([^[\]]+)\]/);
|
|
64
|
+
const cue = (bracketed ? bracketed[1] : raw).trim().slice(0, maxLen).trim();
|
|
65
|
+
return cue ? `[${cue}]` : '';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// PCM is what the rest of decklight is built on: ⇧V stitches per-slide WAVs
|
|
69
|
+
// out of the sentence cache, and rhubarb reads WAV to find visemes. mp3 plays
|
|
70
|
+
// perfectly well in the deck but does neither, so it is opt-in rather than a
|
|
71
|
+
// silent downgrade. PCM output needs a paid ElevenLabs tier; see synthError.
|
|
72
|
+
export const FORMATS = ['pcm', 'mp3'];
|
|
73
|
+
const OUTPUT = { pcm: 'pcm_24000', mp3: 'mp3_44100_128' };
|
|
74
|
+
const PCM_RATE = 24000;
|
|
75
|
+
|
|
76
|
+
export const apiKey = (env = process.env) => env[KEY_ENV]?.trim() || null;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The account's voices as the picker wants them: `[[name, flavor], …]`.
|
|
80
|
+
*
|
|
81
|
+
* YOUR voices come first. The picker lists them in order and preselects the
|
|
82
|
+
* first, and someone who cloned a voice came here to use that voice — burying
|
|
83
|
+
* it under twenty stock ones would make the feature technically present and
|
|
84
|
+
* practically useless. Within a group the API's own order is kept.
|
|
85
|
+
*/
|
|
86
|
+
export function shapeVoices(json) {
|
|
87
|
+
const rank = { cloned: 0, professional: 1, generated: 2, premade: 3 };
|
|
88
|
+
return (json?.voices ?? [])
|
|
89
|
+
.map((v, i) => ({
|
|
90
|
+
name: String(v.name ?? '').trim() || v.voice_id,
|
|
91
|
+
id: v.voice_id,
|
|
92
|
+
// `category` is ElevenLabs' own word for where a voice came from, and
|
|
93
|
+
// "cloned" is exactly the label that makes yours findable at a glance
|
|
94
|
+
flavor: v.category === 'premade'
|
|
95
|
+
? (v.labels?.description || v.labels?.accent || 'premade')
|
|
96
|
+
: (v.category ?? 'voice'),
|
|
97
|
+
order: [rank[v.category] ?? 2, i],
|
|
98
|
+
}))
|
|
99
|
+
.filter((v) => v.id)
|
|
100
|
+
.sort((a, b) => a.order[0] - b.order[0] || a.order[1] - b.order[1]);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Which voice the player meant. It sends a NAME — that is what it persists per
|
|
105
|
+
* deck and what a human recognises — but a raw voice_id is accepted too, so an
|
|
106
|
+
* id pasted from the ElevenLabs dashboard works without a lookup. Matching is
|
|
107
|
+
* case- and space-insensitive because the name came from a text field.
|
|
108
|
+
*/
|
|
109
|
+
export function pickVoice(roster, requested) {
|
|
110
|
+
if (!roster.length) return null;
|
|
111
|
+
if (!requested) return roster[0];
|
|
112
|
+
const want = String(requested).trim().toLowerCase();
|
|
113
|
+
return roster.find((v) => v.id === requested)
|
|
114
|
+
?? roster.find((v) => v.name.toLowerCase() === want)
|
|
115
|
+
?? roster.find((v) => v.name.toLowerCase().replace(/\s+/g, '') === want.replace(/\s+/g, ''))
|
|
116
|
+
?? null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Turn an API failure into a sentence that names the way out. The two that
|
|
121
|
+
* actually happen are a key that isn't one (401) and PCM on a tier that does
|
|
122
|
+
* not include it (422) — and the second is worth catching by hand, because
|
|
123
|
+
* ElevenLabs phrases it as a validation error on a query parameter and nobody
|
|
124
|
+
* would guess that means "upgrade, or pass --tts-format mp3".
|
|
125
|
+
*/
|
|
126
|
+
export function synthError(status, body, { format = 'pcm' } = {}) {
|
|
127
|
+
const text = String(body ?? '').slice(0, 300);
|
|
128
|
+
if (status === 401 || status === 403) {
|
|
129
|
+
return `ElevenLabs rejected the key (${status}) — check $${KEY_ENV}`;
|
|
130
|
+
}
|
|
131
|
+
if (format === 'pcm' && /output_format|pcm|tier|subscription/i.test(text)) {
|
|
132
|
+
return 'ElevenLabs will not serve pcm_24000 on this plan (PCM output is a paid tier). '
|
|
133
|
+
+ 'Pass --tts-format mp3 to use mp3 instead — the deck plays it fine, but ⇧V offline '
|
|
134
|
+
+ 'recording and the lip-sync bridge both need WAV and will not work with it.';
|
|
135
|
+
}
|
|
136
|
+
if (status === 429) return 'ElevenLabs rate limit (429) — the lookahead buffer is bursty; try a smaller deck or wait';
|
|
137
|
+
return `${status} ${text}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Returns `{ listVoices, synth }`.
|
|
144
|
+
*
|
|
145
|
+
* `listVoices()` resolves the account roster once and caches the promise — the
|
|
146
|
+
* bridge's /ping, its /voices, and every synth share that one call. A failure
|
|
147
|
+
* evicts itself, so a key fixed in another terminal is picked up on the next
|
|
148
|
+
* probe rather than needing a restart.
|
|
149
|
+
*/
|
|
150
|
+
export function createSynth({
|
|
151
|
+
key, model = DEFAULT_MODEL, format = 'pcm', stability, fetchImpl = fetch,
|
|
152
|
+
} = {}) {
|
|
153
|
+
if (!key) {
|
|
154
|
+
throw new Error(`ElevenLabs needs an API key — set $${KEY_ENV} `
|
|
155
|
+
+ '(create one at https://elevenlabs.io/app/settings/api-keys)');
|
|
156
|
+
}
|
|
157
|
+
if (!FORMATS.includes(format)) throw new Error(`unknown --tts-format '${format}' — use ${FORMATS.join(' or ')}`);
|
|
158
|
+
// A stability preset means nothing to a model with no such slider — refused
|
|
159
|
+
// up front, at construction, rather than accepted and quietly doing nothing.
|
|
160
|
+
let stabilityValue;
|
|
161
|
+
if (stability != null) {
|
|
162
|
+
if (model !== V3_MODEL) {
|
|
163
|
+
throw new Error(`--tts-stability is a v3 feature — pass --tts-model ${V3_MODEL}, or drop --tts-stability`);
|
|
164
|
+
}
|
|
165
|
+
stabilityValue = STABILITY_PRESETS[stability];
|
|
166
|
+
if (stabilityValue == null) {
|
|
167
|
+
throw new Error(`unknown --tts-stability '${stability}' — use ${Object.keys(STABILITY_PRESETS).join(', ')}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const headers = { 'xi-api-key': key };
|
|
171
|
+
|
|
172
|
+
let roster = null;
|
|
173
|
+
function listVoices() {
|
|
174
|
+
roster ??= (async () => {
|
|
175
|
+
const res = await fetchImpl(`${API}/voices`, { headers });
|
|
176
|
+
if (!res.ok) throw new Error(synthError(res.status, await res.text(), { format }));
|
|
177
|
+
const shaped = shapeVoices(await res.json());
|
|
178
|
+
if (!shaped.length) throw new Error('ElevenLabs returned no voices for this key');
|
|
179
|
+
return shaped;
|
|
180
|
+
})();
|
|
181
|
+
roster.catch(() => { roster = null; });
|
|
182
|
+
return roster;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async function call(text, voice) {
|
|
186
|
+
const payload = { text, model_id: model };
|
|
187
|
+
// Unasked, the account's own voice settings are left alone — sending a
|
|
188
|
+
// voice_settings object at all overrides them, even to "no opinion".
|
|
189
|
+
if (stabilityValue != null) payload.voice_settings = { stability: stabilityValue };
|
|
190
|
+
const res = await fetchImpl(
|
|
191
|
+
`${API}/text-to-speech/${encodeURIComponent(voice.id)}?output_format=${OUTPUT[format]}`,
|
|
192
|
+
{
|
|
193
|
+
method: 'POST',
|
|
194
|
+
headers: { ...headers, 'content-type': 'application/json' },
|
|
195
|
+
body: JSON.stringify(payload),
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
if (!res.ok) {
|
|
199
|
+
const e = new Error(synthError(res.status, await res.text(), { format }));
|
|
200
|
+
e.status = res.status;
|
|
201
|
+
throw e;
|
|
202
|
+
}
|
|
203
|
+
const body = Buffer.from(await res.arrayBuffer());
|
|
204
|
+
// pcm_24000 is headerless 16-bit mono; mp3 is already a container
|
|
205
|
+
return format === 'pcm' ? wavFromPcm(body, PCM_RATE) : body;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function synth(text, { voice, style } = {}) {
|
|
209
|
+
const list = await listVoices();
|
|
210
|
+
const picked = pickVoice(list, voice);
|
|
211
|
+
if (!picked) {
|
|
212
|
+
throw new Error(`no ElevenLabs voice named ${JSON.stringify(voice)} on this key — have: `
|
|
213
|
+
+ list.map((v) => v.name).join(', '));
|
|
214
|
+
}
|
|
215
|
+
// Audio tags are a v3-only delivery channel (SPEC PRESENTING). Sent to any
|
|
216
|
+
// other model the brackets are read aloud as words, so a tone is NEVER
|
|
217
|
+
// attached unless this is the model that can act on it.
|
|
218
|
+
const tag = model === V3_MODEL ? styleTag(style) : '';
|
|
219
|
+
const sent = tag ? `${tag} ${text}` : text;
|
|
220
|
+
let lastErr;
|
|
221
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
222
|
+
try {
|
|
223
|
+
return {
|
|
224
|
+
wav: await call(sent, picked),
|
|
225
|
+
usage: {
|
|
226
|
+
model,
|
|
227
|
+
// Billed on what actually went out — the tag rides inside the same
|
|
228
|
+
// text field ElevenLabs meters, so a report that ignored it would
|
|
229
|
+
// undercount every styled sentence.
|
|
230
|
+
chars: sent.length,
|
|
231
|
+
// ElevenLabs meters CHARACTERS against a monthly plan allowance, and
|
|
232
|
+
// the per-character rate depends on a tier we cannot see. Reporting a
|
|
233
|
+
// dollar figure would be inventing one, so the bridge shows characters.
|
|
234
|
+
cost: 0,
|
|
235
|
+
note: tag ? `${sent.length} chars · ${picked.name} · ${tag}` : `${sent.length} chars · ${picked.name}`,
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
} catch (e) {
|
|
239
|
+
lastErr = e;
|
|
240
|
+
if (e.status === 429 || e.status >= 500) { await sleep(2000 * (attempt + 1)); continue; }
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
throw lastErr;
|
|
245
|
+
}
|
|
246
|
+
synth.mimeType = format === 'pcm' ? 'audio/wav' : 'audio/mpeg';
|
|
247
|
+
return { listVoices, synth };
|
|
248
|
+
}
|
package/tools/escape.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// The Node side's HTML escape. One function, deliberately.
|
|
5
|
+
//
|
|
6
|
+
// This file replaced four of them: `cli/serve.mjs` escaped `& < >`,
|
|
7
|
+
// `cli/bundle.mjs`'s escAttr escaped `& " <`, `tools/pptx.mjs` and
|
|
8
|
+
// `src/core/charts.js` escaped `& < > "` — two of them named `escapeHtml` and
|
|
9
|
+
// behaving differently. None of the call sites was wrong, which is exactly the
|
|
10
|
+
// problem: the next caller picks one by name, and the one whose name reads
|
|
11
|
+
// most general (`escapeHtml`, in serve.mjs) was the one that left quotes
|
|
12
|
+
// alone. `cli/init.mjs` already carried the comment "a prompt invites &, <
|
|
13
|
+
// and quotes" above a call that escaped two of those three.
|
|
14
|
+
//
|
|
15
|
+
// So the choice here is a single escape that is correct in BOTH places text
|
|
16
|
+
// can land — element content and a double-quoted attribute — rather than a
|
|
17
|
+
// pair the caller has to choose between correctly. Single quotes are left
|
|
18
|
+
// alone: every attribute decklight writes is double-quoted, and `'` in a
|
|
19
|
+
// title is churn with no reader.
|
|
20
|
+
//
|
|
21
|
+
// `<!--` and `</script` are a different problem with a different answer —
|
|
22
|
+
// they are about what a SCRIPT body may contain, not what text may, and
|
|
23
|
+
// `scriptSafe` in cli/util.mjs owns them.
|
|
24
|
+
//
|
|
25
|
+
// The runtime has its own copy in src/core/escape.js, because src/ is bundled
|
|
26
|
+
// into a zero-dependency artifact and cannot import from tools/. A test pins
|
|
27
|
+
// the two against each other so "its own copy" cannot become "its own
|
|
28
|
+
// behaviour" (test/deck-html.test.mjs).
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Escape `s` for HTML text or a double-quoted attribute value.
|
|
32
|
+
*
|
|
33
|
+
* Order matters: `&` first, or the ampersands introduced by the later
|
|
34
|
+
* replacements get escaped a second time.
|
|
35
|
+
*/
|
|
36
|
+
export const escapeHtml = (s) => String(s)
|
|
37
|
+
.replace(/&/g, '&')
|
|
38
|
+
.replace(/</g, '<')
|
|
39
|
+
.replace(/>/g, '>')
|
|
40
|
+
.replace(/"/g, '"');
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// The child half of `extension check`'s process boundary (SPEC
|
|
5
|
+
// EXTENSIONS_CHECK) — the ONLY process in which the checked submission ever
|
|
6
|
+
// executes. Spawned by tools/extension-check.mjs under Node's permission
|
|
7
|
+
// model (reads limited to decklight's package and the submission's own
|
|
8
|
+
// directory, no writes, no child processes, no workers), with a replaced
|
|
9
|
+
// environment, a temp cwd and a wall-clock kill. Never run by hand.
|
|
10
|
+
//
|
|
11
|
+
// Protocol: argv[2] is the transform file; the fixture arrives in
|
|
12
|
+
// $DECKLIGHT_CHECK_FIXTURE (env, not argv — spawnSync replaces the whole
|
|
13
|
+
// environment, so this is also what proves nothing else crossed); the
|
|
14
|
+
// verdict leaves on stdout as one JSON object after RESULT_DELIM. After,
|
|
15
|
+
// because the submission shares this stdout and whatever it prints must not
|
|
16
|
+
// be mistaken for the verdict: the parent reads past the LAST marker, so a
|
|
17
|
+
// forged one is overwritten by the real one, and a submission that kills the
|
|
18
|
+
// process before the marker becomes a refusal, not a pass.
|
|
19
|
+
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
import { runTransformAt, LoaderError } from '../cli/loader.mjs';
|
|
22
|
+
import { RESULT_DELIM } from './extension-check.mjs';
|
|
23
|
+
|
|
24
|
+
const report = (verdict) => process.stdout.write(`${RESULT_DELIM}${JSON.stringify(verdict)}\n`);
|
|
25
|
+
|
|
26
|
+
const file = process.argv[2];
|
|
27
|
+
const fixture = process.env.DECKLIGHT_CHECK_FIXTURE;
|
|
28
|
+
if (!file || typeof fixture !== 'string') {
|
|
29
|
+
report({ ok: false, error: 'extension-check-runner: spawned without a file and a fixture'
|
|
30
|
+
+ ' — this is tools/extension-check.mjs\'s child, not a command' });
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const html = await runTransformAt(path.resolve(file), fixture, path.basename(file));
|
|
36
|
+
report({ ok: true, html });
|
|
37
|
+
} catch (e) {
|
|
38
|
+
report({ ok: false, error: e instanceof LoaderError ? e.message
|
|
39
|
+
: `transform "${path.basename(file)}" failed: ${e.message}` });
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
}
|