decklight 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +2 -0
- package/PLATFORM.md +61 -3
- package/README.md +58 -28
- package/SPEC.md +1326 -85
- package/cli/agent-review.mjs +5 -4
- package/cli/agents.mjs +148 -18
- package/cli/bundle-audio.mjs +10 -3
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +125 -7
- package/cli/cast.mjs +86 -19
- package/cli/check-fixes.mjs +194 -0
- package/cli/check-watch.mjs +151 -0
- package/cli/check.mjs +491 -75
- package/cli/code-editor.mjs +287 -0
- package/cli/commands.mjs +13 -2
- package/cli/commit-flow.mjs +7 -3
- package/cli/commit-message.mjs +35 -8
- package/cli/commit-split.mjs +125 -25
- package/cli/deck-refs.mjs +8 -3
- package/cli/decklight.mjs +11 -1
- package/cli/design-system-edit.mjs +37 -1
- package/cli/design-system-refs.mjs +263 -6
- package/cli/design-system.mjs +82 -14
- package/cli/edit-address.mjs +184 -0
- package/cli/edit-git.mjs +23 -6
- package/cli/edit-handover.mjs +257 -40
- package/cli/edit-look.mjs +293 -6
- package/cli/edit-open.mjs +143 -0
- package/cli/edit-slides.mjs +1043 -67
- package/cli/edit-translate.mjs +243 -0
- package/cli/edit.mjs +3680 -319
- package/cli/editor-support.mjs +286 -0
- package/cli/enhance.mjs +157 -27
- package/cli/find-replace.mjs +142 -0
- package/cli/fix-review.mjs +368 -0
- package/cli/git.mjs +13 -0
- package/cli/init.mjs +101 -22
- package/cli/keep-awake.mjs +68 -0
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +250 -13
- package/cli/migrate-writing.mjs +214 -0
- package/cli/narrate.mjs +121 -5
- package/cli/open.mjs +53 -15
- package/cli/outside-edit.mjs +257 -0
- package/cli/paste.mjs +92 -0
- package/cli/pdf.mjs +88 -10
- package/cli/pptx-export.mjs +10 -5
- package/cli/publish.mjs +24 -3
- package/cli/record.mjs +86 -15
- package/cli/remote.mjs +32 -6
- package/cli/rewrite.mjs +265 -0
- package/cli/runtime-link.mjs +218 -17
- package/cli/serve.mjs +9 -6
- package/cli/setup.mjs +2 -2
- package/cli/skill-content.mjs +251 -10
- package/cli/skills/slide-writing.md +333 -0
- package/cli/skills/voiceover.md +423 -0
- package/cli/skills.mjs +282 -15
- package/cli/starter-full.mjs +353 -0
- package/cli/supervise.mjs +14 -0
- package/cli/theme-refs.mjs +14 -2
- package/cli/theme.mjs +3 -2
- package/cli/translate-core.mjs +466 -0
- package/cli/translate-files.mjs +149 -0
- package/cli/translate.mjs +458 -0
- package/cli/units.mjs +75 -7
- package/cli/util.mjs +25 -0
- package/cli/vocabulary-docs.mjs +138 -0
- package/dist/decklight.css +2506 -113
- package/dist/decklight.js +385 -175
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +9 -2
- package/docs/WRITING_RESEARCH.md +327 -0
- package/package.json +5 -3
- package/themes/coastal.css +3 -0
- package/themes/metropolis.css +2 -0
- package/themes/reveal-blood.css +3 -0
- package/themes/reveal-league.css +2 -0
- package/themes/reveal-moon.css +2 -0
- package/themes/reveal-serif.css +1 -0
- package/themes/reveal-sky.css +1 -0
- package/themes/reveal-solarized.css +4 -0
- package/tools/brand-palette.mjs +6 -1
- package/tools/build-groups.mjs +28 -8
- package/tools/cdp.mjs +176 -0
- package/tools/chart-spec.mjs +242 -0
- package/tools/click-match.mjs +70 -0
- package/tools/code-options.mjs +174 -0
- package/tools/conversation.mjs +49 -0
- package/tools/deck-family.mjs +101 -0
- package/tools/deck-html.mjs +212 -15
- package/tools/design-system-format.mjs +40 -1
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/diagram-shapes.mjs +221 -0
- package/tools/elevenlabs-tts.mjs +62 -53
- package/tools/exec.mjs +10 -2
- package/tools/face-clip.mjs +96 -0
- package/tools/face-layout.mjs +94 -0
- package/tools/gemini-tts.mjs +1 -1
- package/tools/invisible-in-print.mjs +27 -0
- package/tools/lipsync-auto.mjs +197 -0
- package/tools/lipsync-config.mjs +16 -0
- package/tools/lipsync-engines.mjs +22 -4
- package/tools/lipsync-server.mjs +8 -5
- package/tools/lipsync.mjs +122 -30
- package/tools/local-voice.mjs +1 -1
- package/tools/mouth-file.mjs +26 -0
- package/tools/mouth.mjs +320 -0
- package/tools/narration-manifest.mjs +100 -6
- package/tools/narration-synth.mjs +96 -76
- package/tools/recording-impact.mjs +16 -1
- package/tools/sentences.mjs +7 -1
- package/tools/site-clip.mjs +114 -0
- package/tools/starters.mjs +402 -0
- package/tools/steps.mjs +118 -0
- package/tools/take-check.mjs +146 -0
- package/tools/template-theme.mjs +3 -1
- package/tools/test-impact.mjs +36 -12
- package/tools/theme-check.mjs +196 -1
- package/tools/tone-cue.mjs +108 -0
- package/tools/tts-cache.mjs +9 -3
- package/tools/tts-engines.mjs +100 -11
- package/tools/video-cache.mjs +93 -0
- package/tools/video-live.mjs +349 -0
- package/tools/video-options.mjs +11 -0
- package/tools/video.mjs +825 -117
- package/tools/viseme-fit.mjs +27 -0
- package/tools/viseme-match.mjs +77 -0
- package/tools/vocabulary.mjs +397 -0
- package/tools/voice-renumber.mjs +605 -0
- package/tools/voiceover-server.mjs +42 -11
- package/tools/voiceover.mjs +48 -20
- package/dist/build-info.json +0 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The quick fixes Check deck… offers for what `decklight check` finds (SPEC
|
|
6
|
+
* PRESENTING_EDITING). Pure over the deck's text and the resolved design
|
|
7
|
+
* systems: nothing here writes, spawns or reads the clock. The edit server's
|
|
8
|
+
* `GET /deck/edit/check` runs `quickFixes` over the static findings so every
|
|
9
|
+
* row the panel shows carries what pressing its fix WOULD do, and its
|
|
10
|
+
* `POST /deck/edit/check/fix` applies the transforms below.
|
|
11
|
+
*
|
|
12
|
+
* Two kinds of fix (the issue's distinction, #889). A DETERMINISTIC one is a
|
|
13
|
+
* rename or a setting the server can apply itself, in one write:
|
|
14
|
+
*
|
|
15
|
+
* ds-behind migrate design-system migrate (DESIGN_SYSTEM_MIGRATIONS)
|
|
16
|
+
* theme-off-brand theme the theme the brand's migration renames it to,
|
|
17
|
+
* else the brand's first theme
|
|
18
|
+
* off-role rename a renamed role → its successor, on that slide
|
|
19
|
+
* (batchable: ⇧F does every slide at once)
|
|
20
|
+
* ds-unresolved update marketplace update <marketplace>
|
|
21
|
+
* ds-unknown-system add design-system add <name>@<marketplace>, when a
|
|
22
|
+
* registered marketplace offers one of that name
|
|
23
|
+
*
|
|
24
|
+
* Everything else — clipped and crowded slides, ⟨CLICK⟩s against builds, a
|
|
25
|
+
* literal off the palette, a slot left empty — is a JUDGEMENT fix: the panel
|
|
26
|
+
* hands it to the A agent as an ordinary ask (src/core/deckcheck.js writes
|
|
27
|
+
* that prompt, since the live page has findings of its own), and nothing
|
|
28
|
+
* here claims one.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { deckDesignSystems } from './check.mjs';
|
|
32
|
+
import { configBlock } from './runtime-link.mjs';
|
|
33
|
+
import { deckBehind, designSystemRefs, marketplaceDesignSystems, planMigration } from './design-system-refs.mjs';
|
|
34
|
+
import { configHome, loadRegistry } from './marketplace.mjs';
|
|
35
|
+
import { applyRenames, composeRenames, findRenamed, migrationsOf } from '../tools/design-system-migrations.mjs';
|
|
36
|
+
import { tokenPrefixOf } from '../tools/design-system-format.mjs';
|
|
37
|
+
import { locateSlide, sectionBodies, slideName } from '../tools/deck-html.mjs';
|
|
38
|
+
|
|
39
|
+
/** The rules whose fix is deterministic and safe to apply to every slide at once. */
|
|
40
|
+
export const BATCH_RULES = ['off-role'];
|
|
41
|
+
|
|
42
|
+
const readConfig = (html) => { try { return JSON.parse(configBlock(html)?.inner ?? 'null') ?? {}; } catch { return {}; } };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The role renames every design system the deck uses declares, composed
|
|
46
|
+
* across its migrations: `[{ prefix, roles }]`. ALL its migrations, not
|
|
47
|
+
* only the pending ones: an off-role that still meets a renamed role is a
|
|
48
|
+
* deck recorded at the current version with an old name left in it, which
|
|
49
|
+
* is exactly the case `ds-behind` does not cover (SPEC
|
|
50
|
+
* DESIGN_SYSTEM_MIGRATIONS).
|
|
51
|
+
*/
|
|
52
|
+
function roleRenames(systems) {
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const sys of systems.values()) {
|
|
55
|
+
const mm = sys.migrationManifest;
|
|
56
|
+
if (!mm) continue;
|
|
57
|
+
const roles = composeRenames(migrationsOf(mm)).roles;
|
|
58
|
+
if (Object.keys(roles).length) out.push({ prefix: tokenPrefixOf(mm), roles });
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The renamed roles slide `n` still uses, as `findRenamed` names them. */
|
|
64
|
+
function renamedRolesOn(html, n, systems) {
|
|
65
|
+
const body = sectionBodies(html)[n - 1];
|
|
66
|
+
if (!body) return [];
|
|
67
|
+
return roleRenames(systems).flatMap(({ prefix, roles }) => findRenamed([body], { roles }, prefix));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The theme a deck held to its brand should wear instead of the off-brand
|
|
72
|
+
* one its configuration names (SPEC BRAND_PALETTE): the one a design
|
|
73
|
+
* system's migration renames it to, when that is a brand theme, else the
|
|
74
|
+
* brand's first theme, which is what the runtime opens on. Null when the
|
|
75
|
+
* deck is not off its brand or the brand has no themes.
|
|
76
|
+
*/
|
|
77
|
+
export function offBrandTarget(html, systems = deckDesignSystems(html)) {
|
|
78
|
+
const config = readConfig(html);
|
|
79
|
+
if (config.brandThemesOnly === false || typeof config.theme !== 'string' || !config.theme) return null;
|
|
80
|
+
const brand = [...systems.values()].flatMap((sys) => sys.themeNames ?? []);
|
|
81
|
+
if (!brand.length || brand.includes(config.theme)) return null;
|
|
82
|
+
for (const sys of systems.values()) {
|
|
83
|
+
const mm = sys.migrationManifest;
|
|
84
|
+
const to = mm ? composeRenames(migrationsOf(mm)).themes[config.theme]?.to : null;
|
|
85
|
+
if (to && brand.includes(to)) return { from: config.theme, to, renamed: true };
|
|
86
|
+
}
|
|
87
|
+
return { from: config.theme, to: brand[0], renamed: false };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A renamed role moved to its successor on slide `n`, or on every slide
|
|
92
|
+
* (`n` null): `{ html, count, slides }`, the markup otherwise byte for byte.
|
|
93
|
+
* The head and the tail are never touched — a role a stylesheet writes is
|
|
94
|
+
* the migration's, not a slide's.
|
|
95
|
+
*/
|
|
96
|
+
export function renameRoles(html, n, systems = deckDesignSystems(html)) {
|
|
97
|
+
const renames = roleRenames(systems);
|
|
98
|
+
const total = sectionBodies(html).length;
|
|
99
|
+
const targets = n ? [n] : Array.from({ length: total }, (_, i) => i + 1);
|
|
100
|
+
let out = html;
|
|
101
|
+
let count = 0;
|
|
102
|
+
const slides = [];
|
|
103
|
+
for (const slide of targets) {
|
|
104
|
+
if (slide < 1 || slide > total) continue;
|
|
105
|
+
const { parts, idx } = locateSlide(out, slide);
|
|
106
|
+
let body = parts[idx];
|
|
107
|
+
let here = 0;
|
|
108
|
+
for (const { prefix, roles } of renames) {
|
|
109
|
+
const r = applyRenames(body, { roles }, prefix);
|
|
110
|
+
body = r.text;
|
|
111
|
+
here += r.count;
|
|
112
|
+
}
|
|
113
|
+
if (!here) continue;
|
|
114
|
+
parts[idx] = body;
|
|
115
|
+
out = parts.join('');
|
|
116
|
+
count += here;
|
|
117
|
+
slides.push(slide);
|
|
118
|
+
}
|
|
119
|
+
return { html: out, count, slides };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** `name@marketplace` → its marketplace, when the reference is spelled so. */
|
|
123
|
+
const marketplaceOf = (ref) => /^[^@\s]+@([\w-]+)$/.exec(String(ref ?? ''))?.[1] ?? null;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The static findings, each with the deterministic fix the server can apply
|
|
127
|
+
* for it (`fix: { kind, label, … }`) — or none, which the panel says in so
|
|
128
|
+
* many words. `label` is what the fix WILL do, written on the row (*Migrate
|
|
129
|
+
* to acme 3.0.0 · 3 renames*), never a verb alone.
|
|
130
|
+
*/
|
|
131
|
+
export function quickFixes(findings, html, dir, { home = configHome(), deck = 'deck.html', systems = null } = {}) {
|
|
132
|
+
const sys = systems ?? (designSystemRefs(html).length ? deckDesignSystems(html) : new Map());
|
|
133
|
+
let behind = null;
|
|
134
|
+
let offered = null;
|
|
135
|
+
const registered = () => { try { return Object.keys(loadRegistry(home).marketplaces ?? {}); } catch { return []; } };
|
|
136
|
+
const fixFor = (f) => {
|
|
137
|
+
switch (f.rule) {
|
|
138
|
+
case 'ds-behind': {
|
|
139
|
+
behind ??= deckBehind(html, dir, home, { deck });
|
|
140
|
+
const b = behind.find((x) => f.message.startsWith(`${x.ref} `)) ?? behind[0];
|
|
141
|
+
if (!b) return null;
|
|
142
|
+
const plan = planMigration(html, dir, b.ref, home);
|
|
143
|
+
if (plan.error || !plan.changed) return null;
|
|
144
|
+
return {
|
|
145
|
+
kind: 'migrate', ref: b.ref,
|
|
146
|
+
label: `Migrate to ${plan.name} ${plan.version}${plan.renamed ? ` · ${plan.renamed} rename${plan.renamed === 1 ? '' : 's'}` : ''}`,
|
|
147
|
+
...(b.skills.length ? { skills: b.skills } : {}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
case 'theme-off-brand': {
|
|
151
|
+
const t = offBrandTarget(html, sys);
|
|
152
|
+
return t ? { kind: 'theme', theme: t.to, label: `Switch to ${t.to}${t.renamed ? ` (${t.from} was renamed)` : ', the brand’s first theme'}` } : null;
|
|
153
|
+
}
|
|
154
|
+
case 'off-role': {
|
|
155
|
+
if (!f.slide) return null;
|
|
156
|
+
const found = renamedRolesOn(html, f.slide, sys);
|
|
157
|
+
if (!found.length) return null;
|
|
158
|
+
return {
|
|
159
|
+
kind: 'rename', slide: f.slide, batch: true,
|
|
160
|
+
label: `Rename ${found.length === 1 ? `${found[0].from} → ${found[0].to}` : `${found.length} roles to their successors`} on ${slideName(sectionBodies(html)[f.slide - 1])}`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
case 'ds-unresolved': {
|
|
164
|
+
const ref = /^design system (\S+) cannot be read/.exec(f.message)?.[1];
|
|
165
|
+
const name = marketplaceOf(ref);
|
|
166
|
+
if (!name || !registered().includes(name)) return null;
|
|
167
|
+
return { kind: 'marketplace-update', name, label: `Update the ${name} marketplace` };
|
|
168
|
+
}
|
|
169
|
+
case 'ds-unknown-system': {
|
|
170
|
+
const want = /no design system called "([^"]+)"/.exec(f.message)?.[1];
|
|
171
|
+
if (!want) return null;
|
|
172
|
+
offered ??= marketplaceDesignSystems(home).systems;
|
|
173
|
+
const hit = offered.find((s) => s.name === want && !s.missing);
|
|
174
|
+
return hit ? { kind: 'design-system-add', ref: hit.qualified, label: `Add ${hit.qualified} to the deck` } : null;
|
|
175
|
+
}
|
|
176
|
+
default: return null;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
return findings.map((f) => {
|
|
180
|
+
const fix = fixFor(f);
|
|
181
|
+
return fix ? { ...f, fix } : f;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* `fix: <rule> on "Slide Title"`, or `fix: <rule>` for the deck — the commit a
|
|
187
|
+
* quick fix makes. `slide` is the slide's number, named from `html` the way
|
|
188
|
+
* every subject decklight writes names one (`slideName`), never by the number.
|
|
189
|
+
*/
|
|
190
|
+
export const fixSubject = (rule, slide = null, html = '') => {
|
|
191
|
+
const body = slide ? sectionBodies(String(html ?? ''))[slide - 1] : undefined;
|
|
192
|
+
const name = body === undefined ? null : slideName(body);
|
|
193
|
+
return `fix: ${rule}${name ? ` on ${name}` : ''}`;
|
|
194
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `decklight check --watch`: the check again, every time the deck is saved.
|
|
6
|
+
*
|
|
7
|
+
* For an author who keeps a terminal beside the editor. Two pieces, both
|
|
8
|
+
* independent of what a check IS (cli/check.mjs owns that and drives these),
|
|
9
|
+
* so a test can run them with a counter in place of the lint:
|
|
10
|
+
*
|
|
11
|
+
* watchDeck hears the deck being saved, and runs `run` once per
|
|
12
|
+
* save, never two at a time
|
|
13
|
+
* persistentRenderer one headless Chrome held open across runs, where
|
|
14
|
+
* `check` alone starts and stops one per run
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { watch as fsWatch } from 'node:fs';
|
|
18
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
19
|
+
|
|
20
|
+
import { openPage } from '../tools/cdp.mjs';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Run `run` whenever `file` changes, and once at the start (`initial`).
|
|
24
|
+
*
|
|
25
|
+
* The DIRECTORY is watched, and the events filtered by name, never the file
|
|
26
|
+
* itself. A path watch follows the inode, and an atomic save (a temp file
|
|
27
|
+
* renamed over the deck, which is how most editors and every careful tool
|
|
28
|
+
* write) replaces the inode: the watch goes deaf on the old one and every
|
|
29
|
+
* later save is missed. The edit server learnt this in 0.7.0 (cli/edit.mjs,
|
|
30
|
+
* the deck watch). A directory watch names the entry that changed and
|
|
31
|
+
* survives any number of replacements. A platform that does not name it
|
|
32
|
+
* (`filename` null) counts as a change: one check too many beats one missed.
|
|
33
|
+
*
|
|
34
|
+
* A save is a burst (a truncate and a write, or a write and a rename, and an
|
|
35
|
+
* editor's swap files besides), so events are DEBOUNCED into one run. A save
|
|
36
|
+
* landing while a run is still going is not lost and not run beside it: one
|
|
37
|
+
* more run follows the current one.
|
|
38
|
+
*
|
|
39
|
+
* Returns `{ close, settled }`: `settled()` resolves once nothing is running
|
|
40
|
+
* or waiting to run (for a test, and for a clean stop).
|
|
41
|
+
*/
|
|
42
|
+
export function watchDeck({ file, run, debounceMs = 150, watch = fsWatch, initial = true, onError = () => {} }) {
|
|
43
|
+
const path = resolve(file);
|
|
44
|
+
const name = basename(path);
|
|
45
|
+
let timer = null;
|
|
46
|
+
let running = null;
|
|
47
|
+
let again = false;
|
|
48
|
+
let closed = false;
|
|
49
|
+
|
|
50
|
+
async function kick() {
|
|
51
|
+
timer = null;
|
|
52
|
+
if (closed) return;
|
|
53
|
+
if (running) { again = true; return; }
|
|
54
|
+
running = (async () => {
|
|
55
|
+
try { await run(); } catch (e) { onError(e); }
|
|
56
|
+
})();
|
|
57
|
+
await running;
|
|
58
|
+
running = null;
|
|
59
|
+
if (again && !closed) { again = false; await kick(); }
|
|
60
|
+
}
|
|
61
|
+
const schedule = () => {
|
|
62
|
+
if (closed) return;
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
timer = setTimeout(kick, debounceMs);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const watcher = watch(dirname(path), (_kind, filename) => {
|
|
68
|
+
if (filename != null && basename(String(filename)) !== name) return;
|
|
69
|
+
schedule();
|
|
70
|
+
});
|
|
71
|
+
watcher.on?.('error', onError);
|
|
72
|
+
if (initial) kick();
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
close() {
|
|
76
|
+
closed = true;
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
timer = null;
|
|
79
|
+
try { watcher.close(); } catch { /* already closed */ }
|
|
80
|
+
},
|
|
81
|
+
async settled() {
|
|
82
|
+
while (timer || running) {
|
|
83
|
+
if (running) await running;
|
|
84
|
+
else await new Promise((ok) => setTimeout(ok, debounceMs));
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* One headless Chrome for every run of a watch, the page reloaded each time.
|
|
92
|
+
*
|
|
93
|
+
* `render(url, wait)` answers what `chrome --dump-dom --virtual-time-budget`
|
|
94
|
+
* answers in a one-shot: the page loads, then its clock runs on virtual time
|
|
95
|
+
* until `wait` ms have passed with nothing left to fetch, and the DOM is read.
|
|
96
|
+
* The budget is set once the navigation is under way, not before: set on the
|
|
97
|
+
* blank page it is spent before the deck has asked for anything.
|
|
98
|
+
*
|
|
99
|
+
* A browser that dies or stops answering is dropped, and the next run starts
|
|
100
|
+
* a new one; `close()` stops it for good (Ctrl-C).
|
|
101
|
+
*/
|
|
102
|
+
export function persistentRenderer(bin, { open = openPage, timeoutMs = 60_000 } = {}) {
|
|
103
|
+
let page = null;
|
|
104
|
+
let opening = null;
|
|
105
|
+
const drop = async () => {
|
|
106
|
+
const p = page;
|
|
107
|
+
page = null;
|
|
108
|
+
await p?.close().catch(() => {});
|
|
109
|
+
};
|
|
110
|
+
const capped = (promise, what) => {
|
|
111
|
+
let t;
|
|
112
|
+
return Promise.race([
|
|
113
|
+
promise,
|
|
114
|
+
new Promise((_, no) => { t = setTimeout(() => no(new Error(`Chrome did not answer (${what}) in ${timeoutMs / 1000}s`)), timeoutMs); }),
|
|
115
|
+
]).finally(() => clearTimeout(t));
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
async render(url, wait) {
|
|
119
|
+
if (!page) {
|
|
120
|
+
// the viewport a one-shot headless Chrome has, so both measure the same slides
|
|
121
|
+
opening ??= open(bin, { w: 800, h: 600, args: ['--allow-file-access-from-files'] }).finally(() => { opening = null; });
|
|
122
|
+
page = await opening;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
return await capped((async () => {
|
|
126
|
+
await page.send('Emulation.setVirtualTimePolicy', { policy: 'advance' });
|
|
127
|
+
await page.navigate('about:blank');
|
|
128
|
+
await page.send('Page.navigate', { url });
|
|
129
|
+
const spent = page.once('Emulation.virtualTimeBudgetExpired');
|
|
130
|
+
await page.send('Emulation.setVirtualTimePolicy', { policy: 'pauseIfNetworkFetchesPending', budget: wait });
|
|
131
|
+
await spent;
|
|
132
|
+
return page.evaluate('document.documentElement ? document.documentElement.outerHTML : ""');
|
|
133
|
+
})(), 'rendering the deck');
|
|
134
|
+
} catch (e) {
|
|
135
|
+
await drop();
|
|
136
|
+
throw e;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
async close() {
|
|
140
|
+
if (opening) await opening.catch(() => {});
|
|
141
|
+
await drop();
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The line a watch prints over each fresh report: when, and how to stop. */
|
|
147
|
+
export function watchHeader(deckName, slides, at = new Date()) {
|
|
148
|
+
const hh = (n) => String(n).padStart(2, '0');
|
|
149
|
+
const time = `${hh(at.getHours())}:${hh(at.getMinutes())}:${hh(at.getSeconds())}`;
|
|
150
|
+
return `check: ${deckName} · ${slides} slide${slides === 1 ? '' : 's'} · ${time} · watching for saves, Ctrl-C stops`;
|
|
151
|
+
}
|