decklight 0.8.1 → 0.10.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/PLATFORM.md +707 -0
- package/README.md +226 -150
- package/SPEC.md +803 -888
- package/cli/agent-review.mjs +246 -0
- package/cli/agents.mjs +35 -9
- package/cli/associate.mjs +12 -12
- package/cli/audit.mjs +42 -10
- package/cli/banner.mjs +41 -17
- package/cli/bundle-audio.mjs +190 -0
- package/cli/bundle-module.mjs +95 -0
- package/cli/bundle.mjs +439 -35
- package/cli/cast.mjs +48 -12
- package/cli/check-fixes.mjs +186 -0
- package/cli/check.mjs +988 -0
- package/cli/clone-deck.mjs +179 -0
- package/cli/commands.mjs +345 -0
- package/cli/comments.mjs +64 -18
- package/cli/commit-flow.mjs +51 -22
- package/cli/commit-message.mjs +51 -74
- package/cli/commit-split.mjs +601 -0
- package/cli/deck-refs.mjs +64 -0
- package/cli/deck-routes.mjs +67 -0
- package/cli/deckfile.mjs +3 -5
- package/cli/decklight.mjs +68 -289
- package/cli/design-system-deps.mjs +209 -0
- package/cli/design-system-edit.mjs +194 -0
- package/cli/design-system-refs.mjs +666 -0
- package/cli/design-system.mjs +497 -0
- package/cli/doctor.mjs +115 -0
- package/cli/edit-git.mjs +353 -0
- package/cli/edit-handover.mjs +551 -0
- package/cli/edit-look.mjs +631 -0
- package/cli/edit-slides.mjs +683 -0
- package/cli/edit.mjs +2585 -855
- package/cli/enhance.mjs +485 -0
- package/cli/extension.mjs +10 -10
- package/cli/font-refs.mjs +273 -0
- package/cli/font.mjs +246 -0
- package/cli/git-tree.mjs +1 -1
- package/cli/git.mjs +78 -11
- package/cli/import.mjs +56 -10
- package/cli/init.mjs +407 -236
- package/cli/library.mjs +127 -0
- package/cli/loader.mjs +3 -1
- package/cli/marketplace-autocheck.mjs +200 -0
- package/cli/marketplace.mjs +460 -29
- package/cli/narrate.mjs +251 -0
- package/cli/open-browser.mjs +63 -0
- package/cli/open.mjs +961 -0
- package/cli/pdf.mjs +64 -17
- package/cli/pkg.mjs +44 -2
- package/cli/plugin.mjs +43 -41
- package/cli/port-conflict.mjs +53 -23
- package/cli/pptx-export.mjs +63 -27
- package/cli/publish.mjs +8 -4
- package/cli/qr.mjs +1 -1
- package/cli/record.mjs +85 -23
- package/cli/remote.mjs +43 -17
- package/cli/restore.mjs +11 -4
- package/cli/review-ref.mjs +125 -0
- package/cli/review-remote.mjs +92 -48
- package/cli/review-routes.mjs +254 -0
- package/cli/review-store.mjs +47 -7
- package/cli/review-submit.mjs +47 -57
- package/cli/runtime-link.mjs +560 -0
- package/cli/serve.mjs +236 -45
- package/cli/setup.mjs +112 -0
- package/cli/sign.mjs +1 -1
- package/cli/skill-content.mjs +229 -35
- package/cli/skills.mjs +353 -26
- package/cli/start.mjs +110 -0
- package/cli/supervise.mjs +6 -6
- package/cli/theme-refs.mjs +527 -0
- package/cli/theme.mjs +181 -137
- package/cli/trust.mjs +83 -0
- package/cli/units.mjs +112 -47
- package/cli/update-check.mjs +1 -5
- package/cli/upgrade.mjs +194 -28
- package/cli/upstream.mjs +4 -3
- package/cli/util.mjs +4 -4
- package/cli/wizard.mjs +6 -6
- package/dist/build-info.json +1 -1
- package/dist/decklight.css +1533 -59
- package/dist/decklight.js +258 -115
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +141 -0
- package/docs/architecture.svg +17 -17
- package/package.json +4 -2
- package/themes/README.md +9 -8
- package/themes/reveal-solarized.css +10 -0
- package/tools/args.mjs +20 -0
- package/tools/atomic-write.mjs +48 -0
- package/tools/brand-palette.mjs +717 -0
- package/tools/bridge.mjs +1 -1
- package/tools/build-groups.mjs +42 -0
- package/tools/color.mjs +48 -0
- package/tools/deck-html.mjs +396 -11
- package/tools/design-system-format.mjs +778 -0
- package/tools/design-system-migrations.mjs +207 -0
- package/tools/elevenlabs-tts.mjs +110 -17
- package/tools/exec.mjs +11 -3
- package/tools/extension-check.mjs +31 -7
- package/tools/font-format.mjs +190 -0
- package/tools/font-stacks.mjs +24 -0
- package/tools/gemini-tts.mjs +3 -0
- package/tools/lipsync-config.mjs +103 -0
- package/tools/lipsync-engines.mjs +205 -2
- package/tools/lipsync-server.mjs +264 -41
- package/tools/lipsync.mjs +37 -18
- package/tools/local-voice.mjs +32 -42
- package/tools/narration-manifest.mjs +270 -0
- package/tools/narration-synth.mjs +416 -0
- package/tools/pptx.mjs +776 -19
- package/tools/publish-targets.mjs +1 -1
- package/tools/publish-voices.mjs +3 -3
- package/tools/recording-impact.mjs +7 -3
- package/tools/render-theme.mjs +33 -0
- package/tools/review-anchor.mjs +28 -12
- package/tools/semver.mjs +40 -0
- package/tools/sentences.mjs +180 -0
- package/tools/shot.mjs +14 -7
- package/tools/site-clip.mjs +114 -0
- package/tools/site-voices.mjs +232 -0
- package/tools/template-theme.mjs +1 -1
- package/tools/test-impact.mjs +17 -10
- package/tools/theme-check.mjs +30 -3
- package/tools/tts-cache.mjs +4 -3
- package/tools/tts-engines.mjs +38 -20
- package/tools/tts-setup.mjs +7 -7
- package/tools/video-options.mjs +34 -0
- package/tools/video.mjs +530 -54
- package/tools/voiceover-server.mjs +185 -104
- package/tools/voiceover.mjs +119 -261
- package/tools/zip.mjs +1 -1
- package/cli/dev.mjs +0 -623
- package/cli/present.mjs +0 -853
- package/cli/review.mjs +0 -361
- package/tools/publish-site-voices.mjs +0 -75
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// A deck's added themes, as REFERENCES (SPEC THEME_DISTRIBUTION).
|
|
5
|
+
//
|
|
6
|
+
// A source deck is data (DECK_ANATOMY): slides and one configuration block.
|
|
7
|
+
// A theme from a marketplace used to break that — `theme add` pasted the whole
|
|
8
|
+
// stylesheet into the deck as a <style data-theme-added> block, kilobytes of
|
|
9
|
+
// somebody else's CSS in the file an author diffs and reviews. Now the deck
|
|
10
|
+
// records WHICH theme it uses, and nothing else:
|
|
11
|
+
//
|
|
12
|
+
// { "theme": "acme", "markedThemes": ["acme@acme-themes"] }
|
|
13
|
+
//
|
|
14
|
+
// A theme in that list is MARKED: it will be part of the deck's bundle. The servers link it
|
|
15
|
+
// from the marketplace already on this machine, the no-trust mode lists it, and
|
|
16
|
+
// `bundle` inlines it at hand-over, where the reference would mean nothing to
|
|
17
|
+
// whoever opens the file. A theme that is not marked is still listed while
|
|
18
|
+
// authoring (every registered marketplace's themes are), and can be looked at
|
|
19
|
+
// and applied — it simply does not go anywhere the deck goes.
|
|
20
|
+
//
|
|
21
|
+
// Everything here reads the catalog CACHE and the checkouts `marketplace
|
|
22
|
+
// add`/`update` left on disk. Nothing fetches: a deck on a plane links what
|
|
23
|
+
// this machine has and names what it has not (MARKETPLACES — registered, not
|
|
24
|
+
// fetched). The one exception is a catalog entry whose `source` is an https
|
|
25
|
+
// URL rather than a file in its repo: its bytes arrive when it is marked, or
|
|
26
|
+
// looked at while authoring, and are kept in `theme-cache/` from then on —
|
|
27
|
+
// see `themeCachePath`.
|
|
28
|
+
|
|
29
|
+
import { existsSync, readFileSync, readdirSync, mkdirSync, statSync } from 'node:fs';
|
|
30
|
+
import { join } from 'node:path';
|
|
31
|
+
import { escapeHtml } from '../tools/escape.mjs';
|
|
32
|
+
import { writeFileAtomic } from '../tools/atomic-write.mjs';
|
|
33
|
+
import { THEMES_DIR } from './pkg.mjs';
|
|
34
|
+
import { validateTheme } from '../tools/theme-check.mjs';
|
|
35
|
+
import { configBlock, isDeck } from './runtime-link.mjs';
|
|
36
|
+
import {
|
|
37
|
+
configHome, loadRegistry, saveRegistry, loadCatalog, writeCache, validateManifest,
|
|
38
|
+
classifySource, MarketplaceError, NAME_RE,
|
|
39
|
+
} from './marketplace.mjs';
|
|
40
|
+
import { resolveSource } from './theme.mjs';
|
|
41
|
+
|
|
42
|
+
/** The config key a deck lists its marked themes under. */
|
|
43
|
+
export const MARKED_KEY = 'markedThemes';
|
|
44
|
+
|
|
45
|
+
/** The config key a deck records where each of its marketplaces comes from. */
|
|
46
|
+
export const SOURCES_KEY = 'themeSources';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The config key a deck lists its design systems under (SPEC DESIGN_SYSTEMS).
|
|
50
|
+
* Here rather than in design-system-refs.mjs because the source sweep below
|
|
51
|
+
* has to count them: `themeSources` is keyed by MARKETPLACE, shared by both
|
|
52
|
+
* kinds of mark, and a source goes only with the last mark of either.
|
|
53
|
+
*/
|
|
54
|
+
export const DESIGN_SYSTEMS_KEY = 'designSystems';
|
|
55
|
+
/** …and the fonts it references (SPEC FONTS) — the third kind that shares `themeSources`. */
|
|
56
|
+
export const FONTS_KEY = 'fonts';
|
|
57
|
+
|
|
58
|
+
/** Every marketplace reference a deck holds, of any kind — what a recorded source is still needed for. */
|
|
59
|
+
export function referencedMarketplaces(html, keys = [MARKED_KEY, DESIGN_SYSTEMS_KEY, FONTS_KEY]) {
|
|
60
|
+
const config = configBlock(html)?.config ?? {};
|
|
61
|
+
const out = new Set();
|
|
62
|
+
for (const key of keys) {
|
|
63
|
+
for (const e of Array.isArray(config[key]) ? config[key] : []) {
|
|
64
|
+
const r = parseRef(e);
|
|
65
|
+
if (r) out.add(r.marketplace);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The personal marketplace `theme add <file|url>` copies into. */
|
|
72
|
+
export const LOCAL_MARKETPLACE = 'local';
|
|
73
|
+
|
|
74
|
+
/** `acme@acme-themes` → `{ name, marketplace }`, or null for anything else. */
|
|
75
|
+
export function parseRef(ref) {
|
|
76
|
+
const m = /^([^@\s]+)@([^@\s]+)$/.exec(String(ref ?? ''));
|
|
77
|
+
if (!m || !NAME_RE.test(m[1]) || !NAME_RE.test(m[2])) return null;
|
|
78
|
+
return { name: m[1], marketplace: m[2], ref: `${m[1]}@${m[2]}` };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A theme decklight SHIPS, marked by its bare name — `"ember"` — or null. It
|
|
83
|
+
* needs no reference: every install has it. Marking one says the deck carries
|
|
84
|
+
* it when it travels, since a bundle holds only the themes put in it.
|
|
85
|
+
*/
|
|
86
|
+
export function parseShipped(entry) {
|
|
87
|
+
if (typeof entry !== 'string' || !NAME_RE.test(entry) || !shippedThemes().includes(entry)) return null;
|
|
88
|
+
return { name: entry, marketplace: null, ref: entry, shipped: true };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Every theme the deck marks — shipped names and marketplace references — parsed; anything else dropped, not guessed at. */
|
|
92
|
+
export function markedEntries(html) {
|
|
93
|
+
const list = configBlock(html)?.config?.[MARKED_KEY];
|
|
94
|
+
return Array.isArray(list) ? list.map((e) => parseRef(e) ?? parseShipped(e)).filter(Boolean) : [];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The deck's marked MARKETPLACE references — what is resolved, linked and cached. */
|
|
98
|
+
export const markedRefs = (html) => markedEntries(html).filter((r) => !r.shipped);
|
|
99
|
+
|
|
100
|
+
/** The shipped themes the deck marks, by name. */
|
|
101
|
+
export const markedShipped = (html) => markedEntries(html).filter((r) => r.shipped).map((r) => r.name);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A marketplace's source as a deck records it — the form `marketplace add`
|
|
105
|
+
* takes, so it is also the command that brings it — or null when there is
|
|
106
|
+
* nothing portable to record.
|
|
107
|
+
*
|
|
108
|
+
* The name a marketplace is registered under is this machine's (`--name`
|
|
109
|
+
* renames it), so it cannot say which catalog a deck means: the same catalog
|
|
110
|
+
* can be `acme` here and `acme-themes` there, and two different catalogs can
|
|
111
|
+
* share a name. The source can. A LOCAL marketplace has none worth writing: its
|
|
112
|
+
* source is a path on the author's disk, meaningless anywhere else and a
|
|
113
|
+
* disclosure of their home directory — the personal one included. Credentials
|
|
114
|
+
* a URL carries (`https://user:token@host/…`) are removed before anything is
|
|
115
|
+
* written; a deck is a file that gets sent to people.
|
|
116
|
+
*/
|
|
117
|
+
export function portableSource(source) {
|
|
118
|
+
if (typeof source !== 'string' || !source) return null;
|
|
119
|
+
const bare = source.replace(/^(https?:\/\/|ssh:\/\/|git:\/\/)[^/@]*@/i, '$1');
|
|
120
|
+
// GitHub over SSH is the same repo as over https: one identity, or a deck
|
|
121
|
+
// marked where the catalog was added by SSH URL is "a different catalog"
|
|
122
|
+
// wherever it was added as owner/repo. Here only: `classifySource` also picks
|
|
123
|
+
// the clone transport, and an SSH user keeps cloning over SSH.
|
|
124
|
+
const ssh = /^(?:ssh:\/\/github\.com(?::22)?\/|git@github\.com:)([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/i.exec(bare);
|
|
125
|
+
if (ssh) return `${ssh[1]}/${ssh[2]}`;
|
|
126
|
+
const src = classifySource(bare, { exists: () => false });
|
|
127
|
+
if (src.kind === 'github') return `${src.owner}/${src.repo}`;
|
|
128
|
+
if (src.kind === 'git' && !/^file:\/\//i.test(bare)) return bare.replace(/\.git\/?$/, '').replace(/\/$/, '');
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The deck's recorded sources, by the marketplace name its references use. */
|
|
133
|
+
export function markedSources(html) {
|
|
134
|
+
const map = configBlock(html)?.config?.[SOURCES_KEY];
|
|
135
|
+
if (!map || typeof map !== 'object' || Array.isArray(map)) return {};
|
|
136
|
+
return Object.fromEntries(Object.entries(map).filter(([k, v]) => NAME_RE.test(k) && typeof v === 'string' && v));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The theme names shipped with this install. */
|
|
140
|
+
export const shippedThemes = () =>
|
|
141
|
+
readdirSync(THEMES_DIR).filter((f) => f.endsWith('.css')).map((f) => f.slice(0, -4));
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Where an https-sourced entry's bytes are kept once read.
|
|
145
|
+
*
|
|
146
|
+
* Every other entry is a file in a checkout, which is already on disk; this is
|
|
147
|
+
* the one kind that is not. Keeping it is what lets every server link it with
|
|
148
|
+
* no network — a marked theme must look the same on a plane as it did at the
|
|
149
|
+
* desk. Filled only by an explicit act (marking it, or looking at it while
|
|
150
|
+
* authoring), never by serving a deck.
|
|
151
|
+
*/
|
|
152
|
+
export const themeCachePath = (home, marketplace, name) => join(home, 'theme-cache', marketplace, `${name}.css`);
|
|
153
|
+
|
|
154
|
+
/** Keep an https-sourced entry's bytes for later offline serving. */
|
|
155
|
+
export function cacheThemeCss(home, marketplace, name, css) {
|
|
156
|
+
mkdirSync(join(home, 'theme-cache', marketplace), { recursive: true });
|
|
157
|
+
writeFileAtomic(themeCachePath(home, marketplace, name), css);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The catalog entry a reference means on THIS machine — the half of resolving
|
|
162
|
+
* every by-reference kind shares (a marked theme, a design system, SPEC
|
|
163
|
+
* DESIGN_SYSTEMS): which registered marketplace the reference names (with a
|
|
164
|
+
* recorded source, the source decides, not the name), and its entry in that
|
|
165
|
+
* marketplace's cached catalog. Registry and cache only; it never fetches.
|
|
166
|
+
*
|
|
167
|
+
* Returns `{ name, marketplace, ref, local, title, entry, registered, origin }`
|
|
168
|
+
* — `local` what this machine calls the catalog, `origin` its portable source
|
|
169
|
+
* — or `{ ...parsed, missing }` in words a presenter can act on. The kind is
|
|
170
|
+
* the caller's to check: the entry comes back whatever its type.
|
|
171
|
+
*/
|
|
172
|
+
export function resolveCatalogEntry(parsed, home = configHome(), { source = null } = {}) {
|
|
173
|
+
const { name } = parsed;
|
|
174
|
+
// Which marketplace HERE the reference means. With a recorded source, the
|
|
175
|
+
// source decides: whatever this machine calls that catalog is the one, and
|
|
176
|
+
// a marketplace that merely shares the name is not it.
|
|
177
|
+
const registry = loadRegistry(home).marketplaces ?? {};
|
|
178
|
+
let marketplace = parsed.marketplace;
|
|
179
|
+
if (source) {
|
|
180
|
+
// both sides: a deck that recorded the SSH form before it was normalised
|
|
181
|
+
// still resolves without being re-marked
|
|
182
|
+
const wanted = portableSource(source) ?? source;
|
|
183
|
+
const same = Object.entries(registry).find(([, m]) => portableSource(m.source) === wanted)?.[0];
|
|
184
|
+
if (same) marketplace = same;
|
|
185
|
+
else if (registry[marketplace]) {
|
|
186
|
+
return { ...parsed, missing: `"${marketplace}" here is a different catalog (${portableSource(registry[marketplace].source) ?? 'a local one'}) — the deck's comes from ${source}` };
|
|
187
|
+
} else {
|
|
188
|
+
return { ...parsed, missing: `its marketplace is not registered on this machine — decklight marketplace add ${source}` };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const registered = registry[marketplace];
|
|
192
|
+
if (!registered) {
|
|
193
|
+
return { ...parsed, missing: `marketplace "${marketplace}" is not registered on this machine`
|
|
194
|
+
+ ' — it was local to whoever marked it, or never recorded where it came from' };
|
|
195
|
+
}
|
|
196
|
+
const catalog = loadCatalog(marketplace, home);
|
|
197
|
+
if (!catalog?.ok) {
|
|
198
|
+
return { ...parsed, missing: `marketplace "${marketplace}" has never been fetched — decklight marketplace update ${marketplace}` };
|
|
199
|
+
}
|
|
200
|
+
const entry = (catalog.manifest.entries ?? []).find((e) => e.name === name);
|
|
201
|
+
if (!entry) return { ...parsed, missing: `"${name}" is not in ${marketplace} any more` };
|
|
202
|
+
return {
|
|
203
|
+
...parsed, local: marketplace, title: catalog.manifest.title?.trim() || null, entry, registered,
|
|
204
|
+
origin: portableSource(registered.source),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Resolve a reference to the file on disk that holds its CSS, reading only
|
|
210
|
+
* the registry, the catalog cache, the checkouts and the theme cache.
|
|
211
|
+
*
|
|
212
|
+
* Returns `{ name, marketplace, ref, title, entry, file }`, or
|
|
213
|
+
* `{ ...parsed, missing }` with `missing` saying, in words a presenter can act
|
|
214
|
+
* on, why this machine cannot show it. `remote` is set on an https-sourced
|
|
215
|
+
* entry that has not been read yet — the caller that is allowed to fetch
|
|
216
|
+
* (an explicit mark, an author looking at it) knows to.
|
|
217
|
+
*/
|
|
218
|
+
export function resolveThemeRef(ref, home = configHome(), { source = null } = {}) {
|
|
219
|
+
const parsed = typeof ref === 'string' ? parseRef(ref) : ref;
|
|
220
|
+
if (!parsed) return { ref: String(ref), missing: 'not a theme reference (name@marketplace)' };
|
|
221
|
+
const hit = resolveCatalogEntry(parsed, home, { source });
|
|
222
|
+
if (hit.missing) return hit;
|
|
223
|
+
const { name, local, title, entry, registered, origin } = hit;
|
|
224
|
+
const marketplace = local;
|
|
225
|
+
if (entry.type !== 'theme') return { ...parsed, entry, missing: `"${parsed.ref}" is a ${entry.type}, not a theme` };
|
|
226
|
+
if (/^https?:\/\//i.test(entry.source)) {
|
|
227
|
+
const cached = themeCachePath(home, marketplace, name);
|
|
228
|
+
if (existsSync(cached)) return { ...parsed, local, title, entry, file: cached, source: origin };
|
|
229
|
+
return { ...parsed, local, title, entry, remote: entry.source, missing: `${parsed.ref} lives at ${entry.source} and has not been read on this machine` };
|
|
230
|
+
}
|
|
231
|
+
let file;
|
|
232
|
+
try { file = resolveSource(entry.source, { name: marketplace, source: registered.source }, home); }
|
|
233
|
+
catch (e) {
|
|
234
|
+
if (e instanceof MarketplaceError) return { ...parsed, title, entry, missing: e.message.replace(/\n\s*/g, ' — ') };
|
|
235
|
+
throw e;
|
|
236
|
+
}
|
|
237
|
+
if (!existsSync(file)) return { ...parsed, title, entry, missing: `${parsed.ref}: ${entry.source} is not in the marketplace's files` };
|
|
238
|
+
return { ...parsed, local, title, entry, file, source: origin };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Does the file a marked theme resolves to STILL pass the THEMING contract?
|
|
243
|
+
*
|
|
244
|
+
* A marked theme follows its marketplace: `marketplace update` can change its
|
|
245
|
+
* bytes after it was marked and checked. A deck must never be made to show —
|
|
246
|
+
* or a bundle to carry — what the shipped set could not contain, so the
|
|
247
|
+
* contract is re-run wherever the file is used, not only when it was marked.
|
|
248
|
+
* Remembered by path, mtime and size, so a page load re-reads nothing that
|
|
249
|
+
* has not changed.
|
|
250
|
+
*/
|
|
251
|
+
const verdicts = new Map();
|
|
252
|
+
export function stillValid(file) {
|
|
253
|
+
let st;
|
|
254
|
+
try { st = statSync(file); } catch { return { ok: false, why: 'its file is gone' }; }
|
|
255
|
+
const hit = verdicts.get(file);
|
|
256
|
+
if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size) return hit.value;
|
|
257
|
+
const r = validateTheme(readFileSync(file, 'utf8'));
|
|
258
|
+
const value = r.ok ? { ok: true } : { ok: false, why: `it no longer passes the theme contract — ${r.errors[0] ?? 'see decklight theme gate'}` };
|
|
259
|
+
verdicts.set(file, { mtimeMs: st.mtimeMs, size: st.size, value });
|
|
260
|
+
return value;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Every theme every registered marketplace offers, from the cache — what the
|
|
265
|
+
* overlay lists while authoring — and the marketplaces it could not read.
|
|
266
|
+
*
|
|
267
|
+
* A marketplace that is registered but never fetched is the FIRST-RUN state
|
|
268
|
+
* (the first-party one is deliberately in it), so it is reported, by name, as
|
|
269
|
+
* something `marketplace update` fixes rather than as an empty list that looks
|
|
270
|
+
* like an empty marketplace.
|
|
271
|
+
*/
|
|
272
|
+
export function marketplaceThemes(home = configHome()) {
|
|
273
|
+
const themes = [];
|
|
274
|
+
const stale = [];
|
|
275
|
+
for (const market of Object.keys(loadRegistry(home).marketplaces ?? {})) {
|
|
276
|
+
const catalog = loadCatalog(market, home);
|
|
277
|
+
if (!catalog?.ok) { stale.push(market); continue; }
|
|
278
|
+
let readable = 0;
|
|
279
|
+
for (const entry of catalog.manifest.entries ?? []) {
|
|
280
|
+
if (entry.type !== 'theme') continue;
|
|
281
|
+
const r = resolveThemeRef({ name: entry.name, marketplace: market, ref: `${entry.name}@${market}` }, home);
|
|
282
|
+
// An entry whose files are not here — a remote marketplace never cloned —
|
|
283
|
+
// would only be a row that fails. An https entry not read yet is fine:
|
|
284
|
+
// looking at it is the explicit act that reads it.
|
|
285
|
+
if (r.missing && !r.remote) continue;
|
|
286
|
+
readable++;
|
|
287
|
+
themes.push({
|
|
288
|
+
name: entry.name, marketplace: market, qualified: r.ref,
|
|
289
|
+
title: r.title, description: entry.description ?? '',
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
if (!readable && (catalog.manifest.entries ?? []).some((e) => e.type === 'theme')) stale.push(market);
|
|
293
|
+
}
|
|
294
|
+
return { themes, stale };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Where a server answers a reference's CSS, relative to the deck. */
|
|
298
|
+
export const themeRefHref = (marketplace, name) => `decklight-theme/${marketplace}/${name}.css`;
|
|
299
|
+
|
|
300
|
+
const REF_ASSET = /(?:^|\/)decklight-theme\/([\w-]+)\/([\w-]+)\.css$/;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* `staticFiles`' answer for a reference's CSS — `{ file, type }`, or null.
|
|
304
|
+
* Matched on the path's tail like `packageAsset`, so a deck in `slides/`
|
|
305
|
+
* resolves too. Cache and checkout only: this is on every server's path,
|
|
306
|
+
* `--no-trust` included, and it never fetches.
|
|
307
|
+
*/
|
|
308
|
+
export function themeRefAsset(rel, home = configHome()) {
|
|
309
|
+
const m = REF_ASSET.exec(String(rel ?? '').split('\\').join('/'));
|
|
310
|
+
if (!m) return null;
|
|
311
|
+
const r = resolveThemeRef({ name: m[2], marketplace: m[1], ref: `${m[2]}@${m[1]}` }, home);
|
|
312
|
+
return r.file && stillValid(r.file).ok ? { file: r.file, type: 'text/css; charset=utf-8' } : null;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The element a resolved reference is linked as. The same attributes an
|
|
317
|
+
* inline added block has always carried, so the runtime lists, groups and
|
|
318
|
+
* applies it by the code it already had: `data-theme-added` keeps it apart
|
|
319
|
+
* from the deck's own themes, `media="not all"` keeps it off until chosen,
|
|
320
|
+
* and provenance names its marketplace heading. Both provenance values come
|
|
321
|
+
* from a manifest somebody else wrote and land in double-quoted attributes —
|
|
322
|
+
* escaped, never trusted.
|
|
323
|
+
*/
|
|
324
|
+
export function addedThemeLink({ name, marketplace, local = marketplace, title }) {
|
|
325
|
+
// `href` is where THIS server answers it (the catalog's name here); the
|
|
326
|
+
// marketplace attribute is the deck's own name for it, which is what the
|
|
327
|
+
// picker groups by and what a mark toggle writes back
|
|
328
|
+
const label = title ? ` data-theme-source="${escapeHtml(title)}"` : '';
|
|
329
|
+
return `<link rel="stylesheet" href="${themeRefHref(local, name)}" data-theme="${escapeHtml(name)}"`
|
|
330
|
+
+ ` data-theme-added data-theme-marketplace="${escapeHtml(marketplace)}"${label} media="not all">`;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* A marked theme as a bundle carries it: the same attributes as its link, so
|
|
335
|
+
* the picker in a file opened on a machine with no registry still draws the
|
|
336
|
+
* marketplace heading — provenance travels in the file or not at all. A
|
|
337
|
+
* `</style` inside the CSS would end the block early; it is somebody else's
|
|
338
|
+
* file, which is exactly when to check.
|
|
339
|
+
*/
|
|
340
|
+
export function addedThemeStyle({ name, marketplace, title }, css, { active = false } = {}) {
|
|
341
|
+
const label = title ? ` data-theme-source="${escapeHtml(title)}"` : '';
|
|
342
|
+
const safe = css.replace(/<\/(style)/gi, '<\\/$1');
|
|
343
|
+
return `<style data-theme="${escapeHtml(name)}" data-theme-added data-theme-marketplace="${escapeHtml(marketplace)}"`
|
|
344
|
+
+ `${label}${active ? '' : ' media="not all"'}>\n${safe.trim()}\n</style>`;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* The marked themes of a deck, linked into the page on its way out — what
|
|
349
|
+
* every server does after `linkRuntime`, never `bundle` (a hand-over carries
|
|
350
|
+
* the CSS itself, not a link to this machine's marketplaces).
|
|
351
|
+
*
|
|
352
|
+
* A reference this machine cannot resolve is not linked; the page carries a
|
|
353
|
+
* `<meta name="decklight-theme-missing">` instead, so the runtime can say which
|
|
354
|
+
* theme is absent and what brings it, rather than a list that is silently
|
|
355
|
+
* short by one. A theme the deck already carries a block for — a bundle's
|
|
356
|
+
* inlined copy — is left to that block.
|
|
357
|
+
*/
|
|
358
|
+
export function linkAddedThemes(html, home = configHome(), { log = null } = {}) {
|
|
359
|
+
if (!isDeck(html)) return html;
|
|
360
|
+
const refs = markedRefs(html);
|
|
361
|
+
if (!refs.length) return html;
|
|
362
|
+
const sources = markedSources(html);
|
|
363
|
+
const tags = [];
|
|
364
|
+
for (const ref of refs) {
|
|
365
|
+
const carried = new RegExp(`<(?:style|link)\\b[^>]*\\bdata-theme\\s*=\\s*["']${ref.name}["']`, 'i');
|
|
366
|
+
if (carried.test(html)) continue;
|
|
367
|
+
const r = resolveThemeRef(ref, home, { source: sources[ref.marketplace] ?? null });
|
|
368
|
+
const valid = r.file ? stillValid(r.file) : null;
|
|
369
|
+
if (r.file && !valid.ok) r.missing = valid.why;
|
|
370
|
+
if (r.file && valid.ok) tags.push(addedThemeLink(r));
|
|
371
|
+
else {
|
|
372
|
+
tags.push(`<meta name="decklight-theme-missing" content="${escapeHtml(`${ref.ref} — ${r.missing}`)}">`);
|
|
373
|
+
log?.(`theme ${ref.ref}: ${r.missing}`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (!tags.length) return html;
|
|
377
|
+
const masked = html.replace(/<!--[\s\S]*?-->/g, (m) => ' '.repeat(m.length));
|
|
378
|
+
const headEnd = masked.search(/<\/head>/i);
|
|
379
|
+
const at = headEnd !== -1 ? headEnd : Math.max(0, masked.search(/<body\b/i));
|
|
380
|
+
return `${html.slice(0, at)}${tags.join('\n')}\n${html.slice(at)}`;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Mark (`on`) or unmark a reference in the deck's configuration block, editing
|
|
385
|
+
* only the `markedThemes` value so the author's own formatting of the rest
|
|
386
|
+
* survives. Returns `{ html, changed }`, or throws a MarketplaceError a
|
|
387
|
+
* command prints as-is.
|
|
388
|
+
*
|
|
389
|
+
* The rules are the ones the overlay needs to stay unambiguous: a marked name
|
|
390
|
+
* is never a shipped theme's (the picker would show two `aurora`s and apply
|
|
391
|
+
* whichever it met first), never another marketplace's theme of the same name,
|
|
392
|
+
* and the theme the deck OPENS on cannot be unmarked out from under it.
|
|
393
|
+
*/
|
|
394
|
+
export function setMarked(html, ref, on, { source = null } = {}) {
|
|
395
|
+
const parsed = parseShipped(ref) ?? parseRef(ref);
|
|
396
|
+
if (!parsed) {
|
|
397
|
+
throw new MarketplaceError(`"${ref}" is neither a theme decklight ships nor a marketplace theme (name@marketplace)`);
|
|
398
|
+
}
|
|
399
|
+
const block = configBlock(html);
|
|
400
|
+
if (!block) {
|
|
401
|
+
throw new MarketplaceError('the deck has no configuration block to record its themes in'
|
|
402
|
+
+ ' — decklight upgrade --link <deck.html> gives it one');
|
|
403
|
+
}
|
|
404
|
+
if (block.error) throw new MarketplaceError(block.error);
|
|
405
|
+
const current = markedEntries(html);
|
|
406
|
+
const has = current.some((r) => r.ref === parsed.ref);
|
|
407
|
+
if (on) {
|
|
408
|
+
if (has) return { html, changed: false };
|
|
409
|
+
if (!parsed.shipped && shippedThemes().includes(parsed.name)) {
|
|
410
|
+
throw new MarketplaceError(`"${parsed.name}" is the name of a theme decklight ships — ${parsed.ref} cannot sit beside it`);
|
|
411
|
+
}
|
|
412
|
+
const clash = current.find((r) => r.name === parsed.name);
|
|
413
|
+
if (clash) throw new MarketplaceError(`the deck already marks ${clash.ref} — two themes called "${parsed.name}" cannot both be listed`);
|
|
414
|
+
} else {
|
|
415
|
+
if (!has) return { html, changed: false };
|
|
416
|
+
// A marketplace theme the deck opens on would leave it opening on nothing.
|
|
417
|
+
// A shipped one is never missing — every bundle carries the theme it opens
|
|
418
|
+
// on — so unmarking it only stops it travelling as an extra.
|
|
419
|
+
if (!parsed.shipped && block.config.theme === parsed.name) {
|
|
420
|
+
throw new MarketplaceError(`${parsed.ref} is the theme the deck opens on — set another "theme" first`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const next = on ? [...current.map((r) => r.ref), parsed.ref] : current.map((r) => r.ref).filter((r) => r !== parsed.ref);
|
|
424
|
+
// Where each marketplace comes from rides alongside, once per marketplace:
|
|
425
|
+
// written when its first theme is marked, gone with its last. A theme from a
|
|
426
|
+
// marketplace with nothing portable to record (a local one) records nothing.
|
|
427
|
+
const sources = markedSources(html);
|
|
428
|
+
if (on && source) sources[parsed.marketplace] = source;
|
|
429
|
+
// gone with the last reference of ANY kind — a design system or a font the
|
|
430
|
+
// deck still uses keeps its marketplace's source when a theme from it is unmarked
|
|
431
|
+
const others = referencedMarketplaces(html, [DESIGN_SYSTEMS_KEY, FONTS_KEY]);
|
|
432
|
+
for (const m of Object.keys(sources)) {
|
|
433
|
+
if (!next.some((r) => r.endsWith(`@${m}`)) && !others.has(m)) delete sources[m];
|
|
434
|
+
}
|
|
435
|
+
let inner = withKey(block.inner, MARKED_KEY, next.length ? next : null);
|
|
436
|
+
inner = withKey(inner, SOURCES_KEY, Object.keys(sources).length ? sources : null);
|
|
437
|
+
return { html: html.slice(0, block.innerStart) + inner + html.slice(block.innerEnd), changed: true };
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// The block's text with `key` set to `value` (an array of refs, or a flat map
|
|
441
|
+
// of names to sources) — the value swapped, the key appended last, or the key
|
|
442
|
+
// removed when `value` is null. Both are flat, so a bracket match finds the
|
|
443
|
+
// whole value; their strings are refs and sources, JSON-escaped, and a
|
|
444
|
+
// `</script` cannot survive `portableSource` or a ref's shape to reach here.
|
|
445
|
+
export function withKey(inner, key, value) {
|
|
446
|
+
const json = value === null ? null
|
|
447
|
+
: typeof value === 'string' ? JSON.stringify(value).replace(/<\//g, '<\\/')
|
|
448
|
+
: Array.isArray(value) ? `[${value.map((r) => JSON.stringify(r)).join(', ')}]`
|
|
449
|
+
: `{ ${Object.entries(value).map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v).replace(/<\//g, '<\\/')}`).join(', ')} }`;
|
|
450
|
+
// an array, an object, or a string (the deck's default `font`)
|
|
451
|
+
const val = '(?:\\[[^\\]]*\\]|\\{[^{}]*\\}|"(?:[^"\\\\]|\\\\.)*")';
|
|
452
|
+
const keyRe = new RegExp(`"${key}"\\s*:\\s*${val}`);
|
|
453
|
+
if (keyRe.test(inner)) {
|
|
454
|
+
if (json !== null) return inner.replace(keyRe, () => `"${key}": ${json}`);
|
|
455
|
+
const withComma = new RegExp(`\\s*,\\s*"${key}"\\s*:\\s*${val}|"${key}"\\s*:\\s*${val}\\s*,?\\s*`);
|
|
456
|
+
return inner.replace(withComma, '');
|
|
457
|
+
}
|
|
458
|
+
if (json === null) return inner;
|
|
459
|
+
const close = inner.lastIndexOf('}');
|
|
460
|
+
const before = inner.slice(0, close);
|
|
461
|
+
const empty = /\{\s*$/.test(before);
|
|
462
|
+
const trailing = before.match(/\s*$/)[0];
|
|
463
|
+
// a pretty-printed block gets the new key on a line of its own, at the
|
|
464
|
+
// indent its first key has; a one-line block stays on one line
|
|
465
|
+
const indent = /\{[ \t]*\n([ \t]*)"/.exec(before)?.[1];
|
|
466
|
+
const sep = empty ? ' ' : indent !== undefined ? `,\n${indent}` : ', ';
|
|
467
|
+
return `${before.slice(0, before.length - trailing.length)}${sep}"${key}": ${json}${trailing || (empty ? ' ' : '')}${inner.slice(close)}`;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* The reference a deck should record for `name` from the marketplace called
|
|
472
|
+
* `local` here. A deck that already records that marketplace's source under
|
|
473
|
+
* its own name keeps its name — the same catalog is one entry in the deck,
|
|
474
|
+
* whatever each machine that marks from it happens to call it.
|
|
475
|
+
*/
|
|
476
|
+
export function refForDeck(html, name, local, source) {
|
|
477
|
+
// by portable identity, as resolving does: a deck that recorded the SSH
|
|
478
|
+
// form still means the catalog this machine registered as owner/repo (#874)
|
|
479
|
+
const wanted = portableSource(source) ?? source;
|
|
480
|
+
const known = source ? Object.entries(markedSources(html)).find(([, v]) => (portableSource(v) ?? v) === wanted)?.[0] : null;
|
|
481
|
+
return `${name}@${known ?? local}`;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Copy a theme that came from a file or a URL into the personal marketplace,
|
|
486
|
+
* so it can be referenced like any other: `house@local`.
|
|
487
|
+
*
|
|
488
|
+
* The personal marketplace is an ordinary LOCAL marketplace, registered the
|
|
489
|
+
* first time it is needed: a directory with `.decklight/marketplace.json` and
|
|
490
|
+
* the themes beside it. It lives at `~/.decklight/local/`, deliberately NOT
|
|
491
|
+
* under `marketplaces/` — that is where `marketplace remove` deletes clones
|
|
492
|
+
* from, and removing the registration must never take somebody's themes with
|
|
493
|
+
* it. Re-adding a name replaces its file (there is no auto-update; re-adding
|
|
494
|
+
* IS the update).
|
|
495
|
+
*/
|
|
496
|
+
export function addToLocalMarketplace(css, name, from, home = configHome()) {
|
|
497
|
+
if (!NAME_RE.test(name)) throw new MarketplaceError(`"${name}" is not a usable theme name — letters, digits, - and _`);
|
|
498
|
+
const dir = join(home, LOCAL_MARKETPLACE);
|
|
499
|
+
const reg = loadRegistry(home);
|
|
500
|
+
const existing = reg.marketplaces?.[LOCAL_MARKETPLACE];
|
|
501
|
+
if (existing && existing.source !== dir) {
|
|
502
|
+
throw new MarketplaceError(`a marketplace called "${LOCAL_MARKETPLACE}" is already registered from ${existing.source}`
|
|
503
|
+
+ ` — the personal marketplace needs that name (decklight marketplace remove ${LOCAL_MARKETPLACE})`);
|
|
504
|
+
}
|
|
505
|
+
const manifestPath = join(dir, '.decklight', 'marketplace.json');
|
|
506
|
+
let manifest = { name: LOCAL_MARKETPLACE, title: 'Local', entries: [] };
|
|
507
|
+
if (existsSync(manifestPath)) {
|
|
508
|
+
const v = validateManifest(readFileSync(manifestPath, 'utf8'));
|
|
509
|
+
if (!v.ok) throw new MarketplaceError(`${manifestPath} does not validate — fix or delete it`);
|
|
510
|
+
manifest = v.manifest;
|
|
511
|
+
}
|
|
512
|
+
mkdirSync(join(dir, 'themes'), { recursive: true });
|
|
513
|
+
mkdirSync(join(dir, '.decklight'), { recursive: true });
|
|
514
|
+
writeFileAtomic(join(dir, 'themes', `${name}.css`), css);
|
|
515
|
+
const entry = { name, type: 'theme', source: `themes/${name}.css`, description: `added from ${from}` };
|
|
516
|
+
const at = manifest.entries.findIndex((e) => e.name === name);
|
|
517
|
+
const replaced = at !== -1;
|
|
518
|
+
if (replaced) manifest.entries[at] = entry; else manifest.entries.push(entry);
|
|
519
|
+
const raw = JSON.stringify(manifest, null, 2) + '\n';
|
|
520
|
+
writeFileAtomic(manifestPath, raw);
|
|
521
|
+
if (!existing) {
|
|
522
|
+
reg.marketplaces = { ...(reg.marketplaces ?? {}), [LOCAL_MARKETPLACE]: { source: dir } };
|
|
523
|
+
saveRegistry(reg, home);
|
|
524
|
+
}
|
|
525
|
+
writeCache(home, LOCAL_MARKETPLACE, raw);
|
|
526
|
+
return { ref: `${name}@${LOCAL_MARKETPLACE}`, replaced, registered: !existing, file: join(dir, 'themes', `${name}.css`) };
|
|
527
|
+
}
|