decklight 0.6.0 → 0.8.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/README.md +23 -11
- package/SPEC.md +187 -23
- package/cli/agents.mjs +52 -2
- package/cli/associate.mjs +2 -2
- package/cli/banner.mjs +125 -0
- package/cli/bundle.mjs +15 -5
- package/cli/{rec.mjs → cast.mjs} +25 -8
- package/cli/comments.mjs +389 -0
- package/cli/commit-flow.mjs +157 -0
- package/cli/commit-message.mjs +125 -0
- package/cli/decklight.mjs +96 -25
- package/cli/dev.mjs +159 -13
- package/cli/edit.mjs +981 -40
- package/cli/git-tree.mjs +87 -0
- package/cli/git.mjs +22 -0
- package/cli/import.mjs +41 -11
- package/cli/init.mjs +37 -5
- package/cli/pdf.mjs +59 -14
- package/cli/port-conflict.mjs +187 -16
- package/cli/pptx-export.mjs +107 -0
- package/cli/present.mjs +8 -4
- package/cli/publish.mjs +25 -42
- package/cli/record.mjs +154 -0
- package/cli/review-remote.mjs +330 -0
- package/cli/review-store.mjs +107 -0
- package/cli/review-submit.mjs +292 -0
- package/cli/review.mjs +361 -0
- package/cli/serve.mjs +36 -1
- package/cli/skill-content.mjs +4 -1
- package/cli/units.mjs +2 -2
- package/cli/util.mjs +59 -0
- package/dist/build-info.json +1 -0
- package/dist/decklight.css +254 -1
- package/dist/decklight.js +153 -79
- package/dist/decklight.js.map +4 -4
- package/docs/architecture.svg +10 -3
- package/package.json +3 -1
- package/tools/args.mjs +20 -0
- package/tools/bridge.mjs +25 -2
- package/tools/deck-html.mjs +59 -0
- package/tools/elevenlabs-tts.mjs +3 -3
- package/tools/exec.mjs +54 -0
- package/tools/gemini-tts.mjs +4 -4
- package/tools/lipsync-server.mjs +70 -2
- package/tools/lipsync.mjs +46 -30
- package/tools/local-voice.mjs +243 -19
- package/tools/pptx-write.mjs +151 -0
- package/tools/pptx.mjs +82 -2
- package/tools/publish-site-voices.mjs +2 -2
- package/tools/publish-targets.mjs +39 -2
- package/tools/publish-voices.mjs +80 -20
- package/tools/recording-impact.mjs +110 -0
- package/tools/review-anchor.mjs +180 -0
- package/tools/template-theme.mjs +154 -0
- package/tools/test-impact.mjs +266 -0
- package/tools/tts-cache.mjs +191 -0
- package/tools/tts-engines.mjs +85 -8
- package/tools/tts-setup.mjs +4 -3
- package/tools/video.mjs +21 -6
- package/tools/voiceover-server.mjs +163 -17
- package/tools/voiceover.mjs +124 -16
package/tools/local-voice.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Copyright 2026 Gilles Philippart
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { execFileSync } from 'node:child_process';
|
|
5
4
|
import { existsSync } from 'node:fs';
|
|
6
5
|
import { delimiter, join } from 'node:path';
|
|
6
|
+
import { run, PROBE_MS } from './exec.mjs';
|
|
7
7
|
|
|
8
8
|
// What can this machine say out loud, without a credential and without a
|
|
9
9
|
// download?
|
|
@@ -40,51 +40,244 @@ export const SAPI_LIST = [
|
|
|
40
40
|
+ '| ForEach-Object { $_.VoiceInfo.Name }',
|
|
41
41
|
];
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* The novelty and 1990s-formant roster — the voices everybody calls "the
|
|
45
|
+
* robots". They ship on every Mac, they sort ALPHABETICALLY FIRST (Albert,
|
|
46
|
+
* Agnes, Bad News…), and modern `say -v '?'` no longer prints the (Premium)/
|
|
47
|
+
* (Enhanced) markers the old ranking leaned on — which is how Albert became
|
|
48
|
+
* the default narrator on a machine with a hundred better voices. Named
|
|
49
|
+
* explicitly so they land in "average" no matter what the listing says.
|
|
50
|
+
*/
|
|
51
|
+
export const SAY_ROBOTS = new Set([
|
|
52
|
+
'Agnes', 'Albert', 'Bad News', 'Bahh', 'Bells', 'Boing', 'Bubbles', 'Cellos',
|
|
53
|
+
// both spellings: modern macOS lists 'Trinoids', older docs say 'Trinoid' —
|
|
54
|
+
// the singular alone let the plural rank as a plain voice
|
|
55
|
+
'Deranged', 'Fred', 'Good News', 'Hysterical', 'Jester', 'Junior', 'Kathy',
|
|
56
|
+
'Organ', 'Pipe Organ', 'Princess', 'Ralph', 'Superstar', 'Trinoid', 'Trinoids',
|
|
57
|
+
'Victoria', 'Whisper', 'Wobble', 'Zarvox',
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The 2022-era character voices — two locales each, mediocre by design, and
|
|
62
|
+
* alphabetically ahead of every classic. They read as personas, not
|
|
63
|
+
* narrators, so they shelve with the novelty voices: on a real Mac they are
|
|
64
|
+
* most of what an alphabetical list shows first, which is how "which voice
|
|
65
|
+
* is good here" became unanswerable.
|
|
66
|
+
*/
|
|
67
|
+
export const SAY_PERSONAS = new Set([
|
|
68
|
+
'Eddy', 'Flo', 'Grandma', 'Grandpa', 'Reed', 'Rocko', 'Sandy', 'Shelley',
|
|
69
|
+
]);
|
|
70
|
+
|
|
43
71
|
/**
|
|
44
72
|
* Rank a macOS voice by how good it is likely to sound.
|
|
45
73
|
*
|
|
46
74
|
* The roster mixes twenty years of engines — 1990s formant voices sit in the
|
|
47
|
-
* same list as this year's neural ones
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
75
|
+
* same list as this year's neural ones. Siri voices are the best `say` can do
|
|
76
|
+
* and rank with a Personal Voice (the one the user recorded themselves); on
|
|
77
|
+
* current macOS they are recognisable only by their SAMPLE sentence
|
|
78
|
+
* ("Hi, I'm Siri!"), the name markers having disappeared from the listing.
|
|
79
|
+
* The robots are pinned to "average" by name — see SAY_ROBOTS.
|
|
51
80
|
*/
|
|
52
|
-
export function sayTier(name) {
|
|
81
|
+
export function sayTier(name, sample = '') {
|
|
53
82
|
if (/\(Personal Voice\)/i.test(name)) return 0;
|
|
54
|
-
if (
|
|
55
|
-
if (/\(
|
|
83
|
+
if (/^Siri\b|\(Siri\)/i.test(name) || /I[’']m Siri/i.test(sample)) return 0;
|
|
84
|
+
if (/\(Premium\)|\(Neural\)/i.test(name)) return 1;
|
|
56
85
|
if (/\(Enhanced\)/i.test(name)) return 2;
|
|
86
|
+
const bare = name.replace(/\s*\(.*\)$/, '').trim();
|
|
87
|
+
if (SAY_ROBOTS.has(bare) || SAY_PERSONAS.has(bare)) return 4;
|
|
57
88
|
return 3;
|
|
58
89
|
}
|
|
59
90
|
|
|
60
|
-
|
|
91
|
+
/**
|
|
92
|
+
* What each tier is CALLED where a person is choosing: the categories, not
|
|
93
|
+
* the engine trivia. Two tiers share "good" and two share "average" — the
|
|
94
|
+
* ranking stays finer than the vocabulary so the sort still puts an Enhanced
|
|
95
|
+
* voice above a plain one and a plain one above a robot.
|
|
96
|
+
*/
|
|
97
|
+
export const TIER_LABEL = ['best', 'good', 'good', 'average', 'novelty'];
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The `average` shelf — the plain compact voice every locale ships.
|
|
101
|
+
*
|
|
102
|
+
* Derived from TIER_LABEL rather than written as 3, so inserting a shelf moves
|
|
103
|
+
* this with it instead of silently re-pointing it at the wrong one.
|
|
104
|
+
*/
|
|
105
|
+
export const PLAIN_TIER = TIER_LABEL.indexOf('average');
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The quality suffix Apple appends to a voice that has a better build.
|
|
109
|
+
*
|
|
110
|
+
* Deliberately an ALLOW-LIST of the four markers sayTier scores on, not "a
|
|
111
|
+
* trailing parenthetical": plenty of voices carry one that says nothing about
|
|
112
|
+
* quality — `Eddy (English (UK))`, `Aman (English (India))` — and stripping
|
|
113
|
+
* those would have `Aman` superseded by a novelty voice of the same name.
|
|
114
|
+
*/
|
|
115
|
+
const QUALITY_SUFFIX = /\s*\((?:Personal Voice|Siri[^)]*|Premium|Neural|Enhanced)\)\s*$/i;
|
|
116
|
+
|
|
117
|
+
/** `Daniel (Enhanced)` → `Daniel`; `Eddy (English (UK))` → unchanged. */
|
|
118
|
+
export const plainName = (name) => String(name ?? '').replace(QUALITY_SUFFIX, '').trim();
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Drop a plain voice that is the SAME VOICE as a better one beside it.
|
|
122
|
+
*
|
|
123
|
+
* A real Mac lists both `Daniel` and `Daniel (Enhanced)` in en_GB, and both
|
|
124
|
+
* `Audrey` and `Audrey (Premium)` in fr_FR. That is one voice offered twice at
|
|
125
|
+
* two build qualities, and the worse row is not a choice — nobody browsing a
|
|
126
|
+
* picker means "the compact Daniel, specifically". Twelve of this machine's
|
|
127
|
+
* 201 rows are that.
|
|
128
|
+
*
|
|
129
|
+
* The story of what this is NOT is the design.
|
|
130
|
+
*
|
|
131
|
+
* The first cut kept only `best` and `good`, took the roster to 59 rows, and
|
|
132
|
+
* read as a far bigger win — until you notice it deletes the novelty shelf
|
|
133
|
+
* entirely (130 of the 201) and leaves src/core/narration.js holding
|
|
134
|
+
* expand/collapse machinery (`COLLAPSIBLE`) for a shelf that can no longer
|
|
135
|
+
* exist. The picker already folds `novelty` and `other languages` to one
|
|
136
|
+
* expandable row each, which is the same noise handled where it is
|
|
137
|
+
* REVERSIBLE — a fold you can open, rather than a roster that never mentions
|
|
138
|
+
* Zarvox again. Somebody who wants the robot is entitled to the robot.
|
|
139
|
+
*
|
|
140
|
+
* The second cut dropped a locale's plain voices whenever the LOCALE held
|
|
141
|
+
* anything better. That is one step too far, and the names say why: it takes
|
|
142
|
+
* `Daniel` (fine — `Daniel (Enhanced)` is right there) but it also takes
|
|
143
|
+
* `Samantha`, `Rishi`, `Aman`, `Tara` and `Jacques`, which have no
|
|
144
|
+
* better-quality namesake at all. They are distinct voices, deleted because
|
|
145
|
+
* some OTHER voice in their language happens to be Premium. Samantha is the
|
|
146
|
+
* most recognisable voice macOS has ever shipped.
|
|
147
|
+
*
|
|
148
|
+
* So the rule is a NAME match inside one locale, which is exactly the
|
|
149
|
+
* duplicate and nothing else. `keep` spares the voice the bridge booted with,
|
|
150
|
+
* which may have been named on the command line, and an untiered roster (SAPI,
|
|
151
|
+
* WinRT) passes through whole: this ranks, it does not invent.
|
|
152
|
+
*/
|
|
153
|
+
export function withoutSupersededPlain(voices = [], { keep } = {}) {
|
|
154
|
+
// `locale\u0000name` of every voice that is a BETTER build of that name — the
|
|
155
|
+
// set a plain row has to be absent from to survive.
|
|
156
|
+
const better = new Set();
|
|
157
|
+
for (const v of voices) {
|
|
158
|
+
if (!Number.isInteger(v?.tier) || v.tier >= PLAIN_TIER) continue;
|
|
159
|
+
const bare = plainName(v.name);
|
|
160
|
+
if (bare && bare !== v.name) better.add(`${(v.locale || '').toLowerCase()}\u0000${bare}`);
|
|
161
|
+
}
|
|
162
|
+
return voices.filter((v) => {
|
|
163
|
+
if (!Number.isInteger(v?.tier) || v.tier !== PLAIN_TIER) return true;
|
|
164
|
+
if (keep && v.name === keep) return true;
|
|
165
|
+
return !better.has(`${(v.locale || '').toLowerCase()}\u0000${v.name}`);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
61
168
|
|
|
62
169
|
/**
|
|
63
170
|
* Parse `say -v '?'`.
|
|
64
171
|
*
|
|
65
172
|
* A voice NAME may contain spaces and a parenthesised tier, so the locale — the
|
|
66
173
|
* one token that always looks like `en_US` and always precedes the `#` — is the
|
|
67
|
-
* anchor, not a column position.
|
|
174
|
+
* anchor, not a column position. The sample sentence after the `#` rides along:
|
|
175
|
+
* on current macOS it is the only place a Siri voice says what it is.
|
|
176
|
+
*
|
|
177
|
+
* A Siri row that shares its display NAME with a non-Siri row is DROPPED:
|
|
178
|
+
* `say -v` addresses voices by name, so the Siri variant behind a duplicate
|
|
179
|
+
* name cannot actually be selected, and a picker row that plays a different
|
|
180
|
+
* voice than it names would be a lie. A Siri voice under its own name
|
|
181
|
+
* ("Siri Voice 4") is kept, and is the best thing in the list.
|
|
68
182
|
*/
|
|
69
183
|
export function parseSayVoices(stdout, { lang } = {}) {
|
|
70
184
|
const out = [];
|
|
71
185
|
for (const line of String(stdout ?? '').split('\n')) {
|
|
72
|
-
const m = /^(.*?)\s{2,}([a-z]{2}(?:[-_][A-Za-z0-9]{2,8})*)\s
|
|
73
|
-
?? /^(.*?)\s+([a-z]{2}[-_][A-Z]{2})\s
|
|
186
|
+
const m = /^(.*?)\s{2,}([a-z]{2}(?:[-_][A-Za-z0-9]{2,8})*)\s*#\s*(.*)$/.exec(line)
|
|
187
|
+
?? /^(.*?)\s+([a-z]{2}[-_][A-Z]{2})\s+#\s*(.*)$/.exec(line);
|
|
74
188
|
if (!m) continue;
|
|
75
189
|
const name = m[1].trim();
|
|
76
190
|
if (!name) continue;
|
|
77
|
-
|
|
191
|
+
const sample = (m[3] ?? '').trim();
|
|
192
|
+
out.push({ name, locale: m[2].replace('-', '_'), tier: sayTier(name, sample), sample });
|
|
78
193
|
}
|
|
194
|
+
// the unaddressable Siri duplicates (see above), and the `((null))`
|
|
195
|
+
// artifacts an undownloaded Siri stub can leave in the listing — both are
|
|
196
|
+
// rows `say -v` cannot actually select, so neither may be offered
|
|
197
|
+
const names = new Map();
|
|
198
|
+
for (const v of out) names.set(v.name, (names.get(v.name) ?? 0) + 1);
|
|
199
|
+
const kept = out.filter((v) => !v.name.includes('((null))')
|
|
200
|
+
&& !(names.get(v.name) > 1 && /I[’']m Siri/i.test(v.sample)));
|
|
79
201
|
const want = (lang ?? 'en').slice(0, 2).toLowerCase();
|
|
80
202
|
// English (or the asked-for language) first, then by tier: a machine whose
|
|
81
203
|
// best voice speaks Italian should not narrate an English deck with it
|
|
82
|
-
return
|
|
204
|
+
return kept.sort((a, b) =>
|
|
83
205
|
(a.locale.startsWith(want) ? 0 : 1) - (b.locale.startsWith(want) ? 0 : 1)
|
|
84
206
|
|| a.tier - b.tier
|
|
85
207
|
|| a.name.localeCompare(b.name));
|
|
86
208
|
}
|
|
87
209
|
|
|
210
|
+
/**
|
|
211
|
+
* The WinRT speech stack — where Windows' NATURAL voices live.
|
|
212
|
+
*
|
|
213
|
+
* `System.Speech` (SAPI_LIST above) is the 2006 API: it sees David, Zira and
|
|
214
|
+
* Mark, and it cannot see the neural voices Narrator and Edge use (Aria,
|
|
215
|
+
* Jenny, Guy — the ones that sound like a person). Those are exposed through
|
|
216
|
+
* `Windows.Media.SpeechSynthesis`, which Windows PowerShell 5.1 can reach by
|
|
217
|
+
* projecting the WinRT type. So the roster is asked for HERE first, and
|
|
218
|
+
* System.Speech is the fallback for a PowerShell that cannot project (pwsh 7
|
|
219
|
+
* without the SDK assemblies, or an old Windows).
|
|
220
|
+
*
|
|
221
|
+
* One voice per line: DisplayName, Language, Id — tab-separated, because a
|
|
222
|
+
* display name has spaces and parentheses in it.
|
|
223
|
+
*/
|
|
224
|
+
export const WINRT_LIST = [
|
|
225
|
+
'-NoProfile', '-NonInteractive', '-Command',
|
|
226
|
+
'$null = [Windows.Media.SpeechSynthesis.SpeechSynthesizer, Windows.Media.SpeechSynthesis, ContentType=WindowsRuntime]; '
|
|
227
|
+
+ '[Windows.Media.SpeechSynthesis.SpeechSynthesizer]::AllVoices '
|
|
228
|
+
+ '| ForEach-Object { $_.DisplayName + "`t" + $_.Language + "`t" + $_.Id }',
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
/** Rank a WinRT voice: the neural ones are the best Windows can do. */
|
|
232
|
+
export function winrtTier(name, id = '') {
|
|
233
|
+
return /\bNatural\b/i.test(name) || /Natural|Neural/i.test(id) ? 0 : 3;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Parse WINRT_LIST's output — `name<TAB>lang<TAB>id` per line. */
|
|
237
|
+
export function parseWinrtVoices(stdout, { lang } = {}) {
|
|
238
|
+
const out = [];
|
|
239
|
+
for (const line of String(stdout ?? '').split('\n')) {
|
|
240
|
+
const [name, language, id] = line.split('\t').map((x) => (x ?? '').trim());
|
|
241
|
+
if (!name || !language) continue;
|
|
242
|
+
out.push({ name, locale: language.replace('-', '_'), id: id || null, tier: winrtTier(name, id) });
|
|
243
|
+
}
|
|
244
|
+
const want = (lang ?? 'en').slice(0, 2).toLowerCase();
|
|
245
|
+
return out.sort((a, b) =>
|
|
246
|
+
(a.locale.toLowerCase().startsWith(want) ? 0 : 1) - (b.locale.toLowerCase().startsWith(want) ? 0 : 1)
|
|
247
|
+
|| a.tier - b.tier
|
|
248
|
+
|| a.name.localeCompare(b.name));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The PowerShell that makes the WinRT stack speak a line into a WAV file.
|
|
253
|
+
*
|
|
254
|
+
* `SynthesizeTextToStreamAsync` answers a WinRT stream that IS a RIFF/WAVE;
|
|
255
|
+
* it is bridged to a .NET stream and copied to the file whole. The one
|
|
256
|
+
* async hop is awaited through `AsTask` looked up by reflection — the
|
|
257
|
+
* projection has no `await` in PowerShell 5.1 — and a voice name this
|
|
258
|
+
* machine does not have THROWS rather than falling back to the default
|
|
259
|
+
* voice, the same rule `say` needed enforcing by hand.
|
|
260
|
+
*/
|
|
261
|
+
export function winrtArgs(text, voice, file) {
|
|
262
|
+
const q = (s) => `'${String(s).replace(/'/g, "''")}'`; // PowerShell escaping
|
|
263
|
+
return ['-NoProfile', '-NonInteractive', '-Command',
|
|
264
|
+
'$null = [Windows.Media.SpeechSynthesis.SpeechSynthesizer, Windows.Media.SpeechSynthesis, ContentType=WindowsRuntime]; '
|
|
265
|
+
+ 'Add-Type -AssemblyName System.Runtime.WindowsRuntime; '
|
|
266
|
+
+ '$asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | Where-Object { '
|
|
267
|
+
+ "$_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and "
|
|
268
|
+
+ "$_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]; "
|
|
269
|
+
+ '$s = New-Object Windows.Media.SpeechSynthesis.SpeechSynthesizer; '
|
|
270
|
+
+ (voice
|
|
271
|
+
? `$v = [Windows.Media.SpeechSynthesis.SpeechSynthesizer]::AllVoices | Where-Object { $_.DisplayName -eq ${q(voice)} } | Select-Object -First 1; `
|
|
272
|
+
+ `if (-not $v) { throw ('no voice named ' + ${q(voice)}) }; $s.Voice = $v; `
|
|
273
|
+
: '')
|
|
274
|
+
+ `$op = $s.SynthesizeTextToStreamAsync(${q(text)}); `
|
|
275
|
+
+ '$task = $asTask.MakeGenericMethod([Windows.Media.SpeechSynthesis.SpeechSynthesisStream]).Invoke($null, @($op)); '
|
|
276
|
+
+ '$task.Wait(); $stream = $task.Result; '
|
|
277
|
+
+ '$in = [System.IO.WindowsRuntimeStreamExtensions]::AsStreamForRead($stream.GetInputStreamAt(0)); '
|
|
278
|
+
+ `$out = [IO.File]::Create(${q(file)}); $in.CopyTo($out); $out.Dispose(); $in.Dispose(); $s.Dispose()`];
|
|
279
|
+
}
|
|
280
|
+
|
|
88
281
|
/** Parse the PowerShell voice list — one name per line. */
|
|
89
282
|
export function parseSapiVoices(stdout) {
|
|
90
283
|
return String(stdout ?? '').split('\n').map((l) => l.trim()).filter(Boolean)
|
|
@@ -147,7 +340,7 @@ export function onPath(bin, env = process.env) {
|
|
|
147
340
|
|
|
148
341
|
/** Run a probe and return its stdout; anything at all going wrong is ''. */
|
|
149
342
|
export const probe = (bin, args) => {
|
|
150
|
-
try { return
|
|
343
|
+
try { return run(bin, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: PROBE_MS, why: "macOS's speech synthesizer is not answering; restart it: killall speechsynthesisd" }); }
|
|
151
344
|
catch { return ''; }
|
|
152
345
|
};
|
|
153
346
|
|
|
@@ -162,7 +355,7 @@ export function detectLocalVoice({
|
|
|
162
355
|
engine: null,
|
|
163
356
|
why: 'Android has a system voice, but only as an in-app Java API — there is no '
|
|
164
357
|
+ 'command line behind it, so nothing here can drive it',
|
|
165
|
-
suggest: 'record the narration on a desktop (decklight tts, then
|
|
358
|
+
suggest: 'record the narration on a desktop (decklight tts, then V → Record this deck…) and ship the '
|
|
166
359
|
+ 'audio with the deck — a recorded track needs no bridge at all',
|
|
167
360
|
};
|
|
168
361
|
}
|
|
@@ -173,20 +366,51 @@ export function detectLocalVoice({
|
|
|
173
366
|
if (voices.length) {
|
|
174
367
|
return {
|
|
175
368
|
engine: 'say', voices,
|
|
176
|
-
label: `macOS ${TIER_LABEL[voices[0].tier]}: ${voices[0].name}`,
|
|
369
|
+
label: `macOS ${TIER_LABEL[voices[0].tier]} voice: ${voices[0].name}`,
|
|
370
|
+
// The one upgrade worth suggesting: Siri voices are the best thing
|
|
371
|
+
// `say` can produce and a free download away — but only a person can
|
|
372
|
+
// click through to them, so this rides the caveat channel (the
|
|
373
|
+
// bridge's startup line, the picker's toast) rather than pretending
|
|
374
|
+
// to be automatable.
|
|
375
|
+
...(voices.some((v) => v.tier === 0) ? {} : {
|
|
376
|
+
caveat: 'the best voices here are Siri’s, a free download: System Settings '
|
|
377
|
+
+ '→ Accessibility → Spoken Content → System Voice → Manage Voices… '
|
|
378
|
+
+ '(open it with: open "x-apple.systempreferences:com.apple.preference.universalaccess") '
|
|
379
|
+
+ '— then restart decklight tts',
|
|
380
|
+
}),
|
|
177
381
|
};
|
|
178
382
|
}
|
|
179
383
|
return { engine: null, why: 'macOS `say` is installed but reported no voices', suggest: PIPER_SUGGEST };
|
|
180
384
|
}
|
|
181
385
|
|
|
182
386
|
if (platform === 'win32') {
|
|
183
|
-
|
|
387
|
+
// Windows PowerShell first: it is the one that projects WinRT types, and
|
|
388
|
+
// WinRT is where the natural voices are. pwsh (7+) cannot without the SDK
|
|
389
|
+
// assemblies, so it is the fallback shell — and System.Speech, which sees
|
|
390
|
+
// only the 2006 voices, the fallback API.
|
|
391
|
+
const shells = ['powershell.exe', 'pwsh.exe'].filter((b) => hasBin(b));
|
|
392
|
+
for (const shell of shells) {
|
|
393
|
+
let voices = [];
|
|
394
|
+
try { voices = parseWinrtVoices(exec(shell, WINRT_LIST), { lang }); } catch { /* not projectable here */ }
|
|
395
|
+
if (voices.length) {
|
|
396
|
+
return {
|
|
397
|
+
engine: 'sapi', api: 'winrt', shell, voices,
|
|
398
|
+
label: `Windows ${TIER_LABEL[voices[0].tier]} voice: ${voices[0].name}`,
|
|
399
|
+
...(voices.some((v) => v.tier === 0) ? {} : {
|
|
400
|
+
caveat: 'the best voices here are Windows’ natural ones, a free download: Settings '
|
|
401
|
+
+ '→ Accessibility → Narrator → Add natural voices '
|
|
402
|
+
+ '(open it with: start ms-settings:easeofaccess-narrator) — then restart decklight tts',
|
|
403
|
+
}),
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
const shell = shells[0];
|
|
184
408
|
if (shell) {
|
|
185
409
|
let voices = [];
|
|
186
410
|
try { voices = parseSapiVoices(exec(shell, SAPI_LIST)); } catch { /* treated as none */ }
|
|
187
411
|
if (voices.length) {
|
|
188
412
|
return {
|
|
189
|
-
engine: 'sapi', shell, voices,
|
|
413
|
+
engine: 'sapi', api: 'sapi', shell, voices,
|
|
190
414
|
label: `Windows ${voices[0].tier === 1 ? 'natural' : 'built-in'} voice: ${voices[0].name}`,
|
|
191
415
|
};
|
|
192
416
|
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* decklight → PowerPoint, lossy on purpose.
|
|
6
|
+
*
|
|
7
|
+
* PPTX export was a v1 non-goal, and the reason has not changed: a decklight
|
|
8
|
+
* deck is HTML, builds, casts and a live voice, and none of that has a
|
|
9
|
+
* PowerPoint shape. What changed is who asks. Decklight is a replacement for
|
|
10
|
+
* people who never liked PowerPoint — and every one of them still has a
|
|
11
|
+
* boss, a legal team or a conference organiser who says "just send the
|
|
12
|
+
* pptx". They do not want to EDIT it there. They want a file that opens.
|
|
13
|
+
*
|
|
14
|
+
* So each slide is a picture — the slide rendered at its own 1280×720, every
|
|
15
|
+
* build complete — filling a 16:9 page, and its speaker notes ride along as
|
|
16
|
+
* real notes, because notes are the one part of a deck that survives the
|
|
17
|
+
* trip as text and is worth having in PowerPoint's notes pane. Nothing here
|
|
18
|
+
* pretends to round-trip: import this file and you get pictures.
|
|
19
|
+
*
|
|
20
|
+
* The package is the smallest one PowerPoint opens without complaint: a
|
|
21
|
+
* presentation, one master, one layout, one theme, one notes master, and per
|
|
22
|
+
* slide a slide part, a notes part and a PNG. Every part is a template string
|
|
23
|
+
* here rather than a library, because the runtime has zero dependencies and
|
|
24
|
+
* the writer lives beside the reader (tools/ooxml.mjs) that will be asked to
|
|
25
|
+
* read it back in tests.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { zipSync } from '../cli/zip.mjs';
|
|
29
|
+
import { escapeHtml as esc } from './escape.mjs';
|
|
30
|
+
|
|
31
|
+
const NS = {
|
|
32
|
+
p: 'http://schemas.openxmlformats.org/presentationml/2006/main',
|
|
33
|
+
a: 'http://schemas.openxmlformats.org/drawingml/2006/main',
|
|
34
|
+
r: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
|
|
35
|
+
};
|
|
36
|
+
const REL = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';
|
|
37
|
+
const CT = 'application/vnd.openxmlformats-officedocument.presentationml';
|
|
38
|
+
/** 16:9 in EMU — PowerPoint's own default for a widescreen deck. */
|
|
39
|
+
export const SLIDE_W = 12192000;
|
|
40
|
+
export const SLIDE_H = 6858000;
|
|
41
|
+
|
|
42
|
+
const xml = (s) => `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n${s}`;
|
|
43
|
+
const rels = (list) => xml(`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`
|
|
44
|
+
+ list.map(({ id, type, target }) => `<Relationship Id="${id}" Type="${REL}/${type}" Target="${target}"/>`).join('') + '</Relationships>');
|
|
45
|
+
|
|
46
|
+
const emptyShapeTree = `<p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>`;
|
|
47
|
+
|
|
48
|
+
/** A slide: one picture, the whole page. */
|
|
49
|
+
function slideXml(n) {
|
|
50
|
+
return xml(`<p:sld xmlns:p="${NS.p}" xmlns:a="${NS.a}" xmlns:r="${NS.r}"><p:cSld>${emptyShapeTree}`
|
|
51
|
+
+ `<p:pic><p:nvPicPr><p:cNvPr id="2" name="Slide ${n}"/><p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr><p:nvPr/></p:nvPicPr>`
|
|
52
|
+
+ `<p:blipFill><a:blip r:embed="rId2"/><a:stretch><a:fillRect/></a:stretch></p:blipFill>`
|
|
53
|
+
+ `<p:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${SLIDE_W}" cy="${SLIDE_H}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr></p:pic>`
|
|
54
|
+
+ `</p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sld>`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The notes part: the slide's thumbnail placeholder and the text, one paragraph per line. */
|
|
58
|
+
function notesXml(lines) {
|
|
59
|
+
const paras = (lines.length ? lines : ['']).map((l) => `<a:p><a:r><a:rPr lang="en-US" dirty="0"/><a:t>${esc(l)}</a:t></a:r></a:p>`).join('');
|
|
60
|
+
return xml(`<p:notes xmlns:p="${NS.p}" xmlns:a="${NS.a}" xmlns:r="${NS.r}"><p:cSld>${emptyShapeTree}`
|
|
61
|
+
+ `<p:sp><p:nvSpPr><p:cNvPr id="2" name="Slide Image Placeholder 1"/><p:cNvSpPr><a:spLocks noGrp="1" noRot="1" noChangeAspect="1"/></p:cNvSpPr><p:nvPr><p:ph type="sldImg"/></p:nvPr></p:nvSpPr><p:spPr/></p:sp>`
|
|
62
|
+
+ `<p:sp><p:nvSpPr><p:cNvPr id="3" name="Notes Placeholder 2"/><p:cNvSpPr><a:spLocks noGrp="1"/></p:cNvSpPr><p:nvPr><p:ph type="body" idx="1"/></p:nvPr></p:nvSpPr><p:spPr/><p:txBody><a:bodyPr/><a:lstStyle/>${paras}</p:txBody></p:sp>`
|
|
63
|
+
+ `</p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:notes>`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const masterXml = xml(`<p:sldMaster xmlns:p="${NS.p}" xmlns:a="${NS.a}" xmlns:r="${NS.r}"><p:cSld><p:bg><p:bgPr><a:solidFill><a:schemeClr val="bg1"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>${emptyShapeTree}</p:spTree></p:cSld>`
|
|
67
|
+
+ `<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>`
|
|
68
|
+
+ `<p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst><p:txStyles><p:titleStyle><a:lvl1pPr/></p:titleStyle><p:bodyStyle><a:lvl1pPr/></p:bodyStyle><p:otherStyle><a:lvl1pPr/></p:otherStyle></p:txStyles></p:sldMaster>`);
|
|
69
|
+
const layoutXml = xml(`<p:sldLayout xmlns:p="${NS.p}" xmlns:a="${NS.a}" xmlns:r="${NS.r}" type="blank" preserve="1"><p:cSld name="Blank">${emptyShapeTree}</p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sldLayout>`);
|
|
70
|
+
const notesMasterXml = xml(`<p:notesMaster xmlns:p="${NS.p}" xmlns:a="${NS.a}" xmlns:r="${NS.r}"><p:cSld>${emptyShapeTree}</p:spTree></p:cSld>`
|
|
71
|
+
+ `<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/><p:notesStyle><a:lvl1pPr/></p:notesStyle></p:notesMaster>`);
|
|
72
|
+
const themeXml = xml(`<a:theme xmlns:a="${NS.a}" name="Decklight"><a:themeElements><a:clrScheme name="Decklight">`
|
|
73
|
+
+ `<a:dk1><a:srgbClr val="1F2937"/></a:dk1><a:lt1><a:srgbClr val="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="374151"/></a:dk2><a:lt2><a:srgbClr val="F3F4F6"/></a:lt2>`
|
|
74
|
+
+ `<a:accent1><a:srgbClr val="0F6E6E"/></a:accent1><a:accent2><a:srgbClr val="B4541A"/></a:accent2><a:accent3><a:srgbClr val="2C7A4B"/></a:accent3><a:accent4><a:srgbClr val="7B1FA2"/></a:accent4><a:accent5><a:srgbClr val="0B57D0"/></a:accent5><a:accent6><a:srgbClr val="D93025"/></a:accent6>`
|
|
75
|
+
+ `<a:hlink><a:srgbClr val="0B57D0"/></a:hlink><a:folHlink><a:srgbClr val="7B1FA2"/></a:folHlink></a:clrScheme>`
|
|
76
|
+
+ `<a:fontScheme name="Decklight"><a:majorFont><a:latin typeface="Helvetica"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Helvetica"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme>`
|
|
77
|
+
+ `<a:fmtScheme name="Decklight"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:fillStyleLst>`
|
|
78
|
+
+ `<a:lnStyleLst><a:ln w="6350"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="12700"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="19050"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln></a:lnStyleLst>`
|
|
79
|
+
+ `<a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst>`
|
|
80
|
+
+ `<a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>`);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The package, as bytes.
|
|
84
|
+
*
|
|
85
|
+
* `slides` is `[{ png, notes }]` in deck order — `png` the rendered slide as
|
|
86
|
+
* a Buffer, `notes` the speaker notes as lines of plain text (empty for a
|
|
87
|
+
* silent slide). `title` becomes the document title.
|
|
88
|
+
*/
|
|
89
|
+
export function buildPptx(slides, { title = 'Deck' } = {}) {
|
|
90
|
+
if (!slides.length) throw new Error('a presentation needs at least one slide');
|
|
91
|
+
const entries = [];
|
|
92
|
+
const put = (name, data) => entries.push({ name, data: Buffer.isBuffer(data) ? data : Buffer.from(data, 'utf8') });
|
|
93
|
+
const n = slides.length;
|
|
94
|
+
|
|
95
|
+
put('[Content_Types].xml', xml(`<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">`
|
|
96
|
+
+ `<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Default Extension="png" ContentType="image/png"/>`
|
|
97
|
+
+ `<Override PartName="/ppt/presentation.xml" ContentType="${CT}.presentation.main+xml"/>`
|
|
98
|
+
+ `<Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="${CT}.slideMaster+xml"/>`
|
|
99
|
+
+ `<Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="${CT}.slideLayout+xml"/>`
|
|
100
|
+
+ `<Override PartName="/ppt/notesMasters/notesMaster1.xml" ContentType="${CT}.notesMaster+xml"/>`
|
|
101
|
+
+ `<Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>`
|
|
102
|
+
+ slides.map((_, i) => `<Override PartName="/ppt/slides/slide${i + 1}.xml" ContentType="${CT}.slide+xml"/>`
|
|
103
|
+
+ `<Override PartName="/ppt/notesSlides/notesSlide${i + 1}.xml" ContentType="${CT}.notesSlide+xml"/>`).join('')
|
|
104
|
+
+ `<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>`
|
|
105
|
+
+ `<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/></Types>`));
|
|
106
|
+
put('_rels/.rels', rels([
|
|
107
|
+
{ id: 'rId1', type: 'officeDocument', target: 'ppt/presentation.xml' },
|
|
108
|
+
{ id: 'rId2', type: 'metadata/core-properties', target: 'docProps/core.xml' },
|
|
109
|
+
{ id: 'rId3', type: 'extended-properties', target: 'docProps/app.xml' },
|
|
110
|
+
]));
|
|
111
|
+
const now = new Date().toISOString().replace(/\.\d+Z$/, 'Z');
|
|
112
|
+
put('docProps/core.xml', xml(`<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>${esc(title)}</dc:title><dc:creator>decklight</dc:creator><dcterms:created xsi:type="dcterms:W3CDTF">${now}</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">${now}</dcterms:modified></cp:coreProperties>`));
|
|
113
|
+
put('docProps/app.xml', xml(`<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"><Application>decklight</Application><Slides>${n}</Slides><Notes>${n}</Notes></Properties>`));
|
|
114
|
+
|
|
115
|
+
put('ppt/presentation.xml', xml(`<p:presentation xmlns:p="${NS.p}" xmlns:a="${NS.a}" xmlns:r="${NS.r}" saveSubsetFonts="1">`
|
|
116
|
+
+ `<p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst>`
|
|
117
|
+
+ `<p:notesMasterIdLst><p:notesMasterId r:id="rId2"/></p:notesMasterIdLst>`
|
|
118
|
+
+ `<p:sldIdLst>${slides.map((_, i) => `<p:sldId id="${256 + i}" r:id="rId${10 + i}"/>`).join('')}</p:sldIdLst>`
|
|
119
|
+
+ `<p:sldSz cx="${SLIDE_W}" cy="${SLIDE_H}"/><p:notesSz cx="6858000" cy="9144000"/></p:presentation>`));
|
|
120
|
+
put('ppt/_rels/presentation.xml.rels', rels([
|
|
121
|
+
{ id: 'rId1', type: 'slideMaster', target: 'slideMasters/slideMaster1.xml' },
|
|
122
|
+
{ id: 'rId2', type: 'notesMaster', target: 'notesMasters/notesMaster1.xml' },
|
|
123
|
+
{ id: 'rId3', type: 'theme', target: 'theme/theme1.xml' },
|
|
124
|
+
...slides.map((_, i) => ({ id: `rId${10 + i}`, type: 'slide', target: `slides/slide${i + 1}.xml` })),
|
|
125
|
+
]));
|
|
126
|
+
put('ppt/slideMasters/slideMaster1.xml', masterXml);
|
|
127
|
+
put('ppt/slideMasters/_rels/slideMaster1.xml.rels', rels([{ id: 'rId1', type: 'slideLayout', target: '../slideLayouts/slideLayout1.xml' }, { id: 'rId2', type: 'theme', target: '../theme/theme1.xml' }]));
|
|
128
|
+
put('ppt/slideLayouts/slideLayout1.xml', layoutXml);
|
|
129
|
+
put('ppt/slideLayouts/_rels/slideLayout1.xml.rels', rels([{ id: 'rId1', type: 'slideMaster', target: '../slideMasters/slideMaster1.xml' }]));
|
|
130
|
+
put('ppt/notesMasters/notesMaster1.xml', notesMasterXml);
|
|
131
|
+
put('ppt/notesMasters/_rels/notesMaster1.xml.rels', rels([{ id: 'rId1', type: 'theme', target: '../theme/theme1.xml' }]));
|
|
132
|
+
put('ppt/theme/theme1.xml', themeXml);
|
|
133
|
+
|
|
134
|
+
slides.forEach(({ png, notes = [] }, i) => {
|
|
135
|
+
const k = i + 1;
|
|
136
|
+
if (!Buffer.isBuffer(png) || !png.length) throw new Error(`slide ${k}: no rendered image`);
|
|
137
|
+
put(`ppt/slides/slide${k}.xml`, slideXml(k));
|
|
138
|
+
put(`ppt/slides/_rels/slide${k}.xml.rels`, rels([
|
|
139
|
+
{ id: 'rId1', type: 'slideLayout', target: '../slideLayouts/slideLayout1.xml' },
|
|
140
|
+
{ id: 'rId2', type: 'image', target: `../media/slide${k}.png` },
|
|
141
|
+
{ id: 'rId3', type: 'notesSlide', target: `../notesSlides/notesSlide${k}.xml` },
|
|
142
|
+
]));
|
|
143
|
+
put(`ppt/media/slide${k}.png`, png);
|
|
144
|
+
put(`ppt/notesSlides/notesSlide${k}.xml`, notesXml(notes));
|
|
145
|
+
put(`ppt/notesSlides/_rels/notesSlide${k}.xml.rels`, rels([
|
|
146
|
+
{ id: 'rId1', type: 'notesMaster', target: '../notesMasters/notesMaster1.xml' },
|
|
147
|
+
{ id: 'rId2', type: 'slide', target: `../slides/slide${k}.xml` },
|
|
148
|
+
]));
|
|
149
|
+
});
|
|
150
|
+
return zipSync(entries);
|
|
151
|
+
}
|
package/tools/pptx.mjs
CHANGED
|
@@ -170,6 +170,67 @@ const GRAPHIC = {
|
|
|
170
170
|
diagram: 'SmartArt dropped — rebuild as an SVG diagram (SPEC SVG_DIAGRAMS)',
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
+
/** OOXML chart element → data-chart type. Anything else is still a drop. */
|
|
174
|
+
const CHART_TYPES = {
|
|
175
|
+
'c:barChart': 'bar', 'c:bar3DChart': 'bar',
|
|
176
|
+
'c:lineChart': 'line', 'c:line3DChart': 'line',
|
|
177
|
+
'c:areaChart': 'area', 'c:area3DChart': 'area',
|
|
178
|
+
'c:pieChart': 'pie', 'c:pie3DChart': 'pie',
|
|
179
|
+
'c:doughnutChart': 'donut',
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/** The `c:pt` values of a cache, in index order; numbers where they parse. */
|
|
183
|
+
function cachePoints(node, numeric) {
|
|
184
|
+
const pts = findAll(node, 'c:pt').map((pt) => [Number(pt.attrs.idx ?? 0), textOf(find(pt, 'c:v') ?? pt).trim()]);
|
|
185
|
+
pts.sort((a, b) => a[0] - b[0]);
|
|
186
|
+
return pts.map(([, v]) => (numeric ? Number(v) : v));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* A PowerPoint chart, as data-chart's JSON.
|
|
191
|
+
*
|
|
192
|
+
* The chart part carries the data in caches — `c:numCache` and `c:strCache`
|
|
193
|
+
* are the values as last calculated, so nothing here needs the workbook the
|
|
194
|
+
* chart was drawn from. This was the single most common rebuild in a business
|
|
195
|
+
* deck, and every byte it needed was already in the file.
|
|
196
|
+
*
|
|
197
|
+
* Returns null for a chart kind decklight has no native answer for (scatter,
|
|
198
|
+
* radar, stock…); the caller then drops it by name, as before.
|
|
199
|
+
*/
|
|
200
|
+
export function parseChart(xml) {
|
|
201
|
+
const doc = parseXml(xml ?? '');
|
|
202
|
+
const plot = find(doc, 'c:plotArea');
|
|
203
|
+
if (!plot) return null;
|
|
204
|
+
// `children(node, name)` filters by ONE name; the plot area's first chart
|
|
205
|
+
// element is whichever of the known kinds is there, so walk its kids directly
|
|
206
|
+
const kindNode = (plot.children ?? []).find((n) => CHART_TYPES[n.name]);
|
|
207
|
+
if (!kindNode) return null;
|
|
208
|
+
const type = CHART_TYPES[kindNode.name];
|
|
209
|
+
const series = findAll(kindNode, 'c:ser').map((ser, i) => {
|
|
210
|
+
const tx = find(ser, 'c:tx');
|
|
211
|
+
const name = tx ? textOf(tx).trim() : `series ${i + 1}`;
|
|
212
|
+
const cat = find(ser, 'c:cat');
|
|
213
|
+
const val = find(ser, 'c:val');
|
|
214
|
+
return {
|
|
215
|
+
name: name || `series ${i + 1}`,
|
|
216
|
+
labels: cat ? cachePoints(cat, false) : [],
|
|
217
|
+
data: val ? cachePoints(val, true).map((n) => (Number.isFinite(n) ? n : 0)) : [],
|
|
218
|
+
};
|
|
219
|
+
}).filter((sr) => sr.data.length);
|
|
220
|
+
if (!series.length) return null;
|
|
221
|
+
const labels = series.find((sr) => sr.labels.length)?.labels ?? series[0].data.map((_, i) => String(i + 1));
|
|
222
|
+
const titleNode = find(doc, 'c:title');
|
|
223
|
+
const title = titleNode ? findAll(titleNode, 'a:t').map((t) => textOf(t)).join('').trim() : '';
|
|
224
|
+
return {
|
|
225
|
+
type,
|
|
226
|
+
title,
|
|
227
|
+
labels,
|
|
228
|
+
// a pie is one series in decklight; PowerPoint allows more but draws one
|
|
229
|
+
series: (type === 'pie' || type === 'donut' ? series.slice(0, 1) : series)
|
|
230
|
+
.map(({ name, data }) => ({ name, data })),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
173
234
|
/**
|
|
174
235
|
* One slide, as the pieces a `<section>` needs.
|
|
175
236
|
*
|
|
@@ -177,7 +238,7 @@ const GRAPHIC = {
|
|
|
177
238
|
* order the slide did. Groups are walked into: a shape inside a group is still
|
|
178
239
|
* content, and skipping groups loses whole slides' worth of text.
|
|
179
240
|
*/
|
|
180
|
-
export function parseSlide(xml, { rels, mediaOf, slideNo = 0 } = {}) {
|
|
241
|
+
export function parseSlide(xml, { rels, mediaOf, chartOf, slideNo = 0 } = {}) {
|
|
181
242
|
const doc = parseXml(xml);
|
|
182
243
|
const sld = find(doc, 'p:sld');
|
|
183
244
|
const hidden = sld?.attrs.show === '0';
|
|
@@ -250,6 +311,15 @@ export function parseSlide(xml, { rels, mediaOf, slideNo = 0 } = {}) {
|
|
|
250
311
|
if (tbl) blocks.push({ kind: 'table', node: tbl });
|
|
251
312
|
continue;
|
|
252
313
|
}
|
|
314
|
+
if (kind === 'chart') {
|
|
315
|
+
// the frame holds only a relationship; the data is in its own part
|
|
316
|
+
const rid = find(node, 'c:chart')?.attrs['r:id'];
|
|
317
|
+
const rel = rid && rels?.get(rid);
|
|
318
|
+
const chart = rel && chartOf ? parseChart(chartOf(rel.target)) : null;
|
|
319
|
+
if (chart) { blocks.push({ kind: 'chart', ...chart }); continue; }
|
|
320
|
+
drop(GRAPHIC.chart);
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
253
323
|
drop(GRAPHIC[kind] ?? `an embedded ${kind || 'object'} was dropped`);
|
|
254
324
|
continue;
|
|
255
325
|
}
|
|
@@ -280,6 +350,13 @@ export function notesText(xml, { rels } = {}) {
|
|
|
280
350
|
}
|
|
281
351
|
|
|
282
352
|
/** A parsed slide as the `<section>` markup, plus what its report line says. */
|
|
353
|
+
/** A chart block as SPEC CHARTS markup — JSON in a script tag, so `</` must not end it early. */
|
|
354
|
+
export function chartHtml({ type, title, labels, series }) {
|
|
355
|
+
const json = JSON.stringify({ labels, series }).replace(/<\//g, '<\\/');
|
|
356
|
+
const attrs = [`class="chart"`, `data-chart="${type}"`, title ? `data-title="${escapeHtml(title)}"` : null].filter(Boolean);
|
|
357
|
+
return `<div ${attrs.join(' ')}>\n <script type="application/json">${json}</script>\n </div>`;
|
|
358
|
+
}
|
|
359
|
+
|
|
283
360
|
export function slideSection(slide, notes = [], { build = 'auto' } = {}) {
|
|
284
361
|
const parts = [];
|
|
285
362
|
const did = [];
|
|
@@ -303,6 +380,9 @@ export function slideSection(slide, notes = [], { build = 'auto' } = {}) {
|
|
|
303
380
|
const cols = rows.length ? children(rows[0], 'a:tc').length : 0;
|
|
304
381
|
did.push(`table ${rows.length}×${cols}`);
|
|
305
382
|
parts.push(` ${tableHtml(b.node)}`);
|
|
383
|
+
} else if (b.kind === 'chart') {
|
|
384
|
+
did.push(`chart (${b.type}, ${b.series.length} series × ${b.labels.length})`);
|
|
385
|
+
parts.push(` ${chartHtml(b)}`);
|
|
306
386
|
} else if (b.kind === 'image') {
|
|
307
387
|
did.push(`image inlined (${Math.round(b.bytes.length / 1024)} KB)`);
|
|
308
388
|
parts.push(` <img src="data:${b.mime};base64,${b.bytes.toString('base64')}"`
|
|
@@ -316,5 +396,5 @@ export function slideSection(slide, notes = [], { build = 'auto' } = {}) {
|
|
|
316
396
|
for (const line of notes) parts.push(` <p>${line}</p>`);
|
|
317
397
|
parts.push(' </aside>');
|
|
318
398
|
}
|
|
319
|
-
return { html: ` <section>\n${parts.join('\n')}\n </section>`, did };
|
|
399
|
+
return { html: ` <section${slide.hidden ? ' data-hidden' : ''}>\n${parts.join('\n')}\n </section>`, did };
|
|
320
400
|
}
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
// Requires gh (authenticated) on PATH.
|
|
15
15
|
|
|
16
16
|
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
17
|
-
import { execFileSync } from 'node:child_process';
|
|
18
17
|
import { join } from 'node:path';
|
|
19
18
|
import { createHash } from 'node:crypto';
|
|
20
19
|
import { argReader } from './args.mjs';
|
|
20
|
+
import { run, NETWORK_MS } from './exec.mjs';
|
|
21
21
|
|
|
22
22
|
const args = process.argv.slice(2);
|
|
23
23
|
const { opt } = argReader(args);
|
|
@@ -25,7 +25,7 @@ const REPO = opt('--repo', 'decklight/decklight.github.io');
|
|
|
25
25
|
const STAGING = 'demo/voiceover-site';
|
|
26
26
|
|
|
27
27
|
const gh = (argv, input) =>
|
|
28
|
-
JSON.parse(
|
|
28
|
+
JSON.parse(run('gh', ['api', ...argv], { encoding: 'utf8', input, maxBuffer: 1 << 28, timeout: NETWORK_MS, why: 'gh is waiting on the network or a login — run: gh auth status' }));
|
|
29
29
|
|
|
30
30
|
// git blob sha1: sha1("blob <len>\0" + content)
|
|
31
31
|
const blobSha = (buf) =>
|