decklight 0.8.1 → 0.9.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 +666 -0
- package/README.md +224 -150
- package/SPEC.md +732 -886
- package/cli/agent-review.mjs +245 -0
- package/cli/agents.mjs +25 -5
- package/cli/associate.mjs +12 -12
- package/cli/audit.mjs +42 -10
- package/cli/banner.mjs +41 -17
- package/cli/bundle-audio.mjs +183 -0
- package/cli/bundle.mjs +383 -31
- package/cli/cast.mjs +7 -7
- package/cli/check.mjs +961 -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 +44 -19
- package/cli/commit-message.mjs +51 -74
- package/cli/commit-split.mjs +601 -0
- package/cli/deck-refs.mjs +59 -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 +409 -0
- package/cli/design-system.mjs +429 -0
- package/cli/doctor.mjs +115 -0
- package/cli/edit-git.mjs +353 -0
- package/cli/edit-handover.mjs +445 -0
- package/cli/edit-look.mjs +388 -0
- package/cli/edit-slides.mjs +683 -0
- package/cli/edit.mjs +2126 -842
- package/cli/enhance.mjs +483 -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 +65 -11
- package/cli/import.mjs +56 -10
- package/cli/init.mjs +400 -234
- package/cli/library.mjs +127 -0
- package/cli/loader.mjs +3 -1
- package/cli/marketplace.mjs +215 -21
- package/cli/narrate.mjs +176 -0
- package/cli/open-browser.mjs +63 -0
- package/cli/open.mjs +943 -0
- package/cli/pdf.mjs +41 -13
- package/cli/pkg.mjs +44 -2
- package/cli/plugin.mjs +43 -41
- package/cli/port-conflict.mjs +53 -23
- package/cli/pptx-export.mjs +57 -24
- package/cli/publish.mjs +8 -4
- package/cli/qr.mjs +1 -1
- package/cli/record.mjs +14 -12
- package/cli/remote.mjs +11 -11
- 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 +235 -44
- package/cli/setup.mjs +112 -0
- package/cli/sign.mjs +1 -1
- package/cli/skill-content.mjs +190 -33
- package/cli/skills.mjs +107 -24
- package/cli/start.mjs +110 -0
- package/cli/supervise.mjs +6 -6
- package/cli/theme-refs.mjs +515 -0
- package/cli/theme.mjs +181 -137
- package/cli/trust.mjs +83 -0
- package/cli/units.mjs +39 -42
- 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 +1126 -49
- package/dist/decklight.js +212 -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 +753 -0
- package/tools/elevenlabs-tts.mjs +110 -17
- package/tools/exec.mjs +1 -1
- 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 +196 -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-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 +461 -48
- 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,273 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// A deck's fonts, as REFERENCES (SPEC FONTS) — the third instance of what
|
|
5
|
+
// THEME_DISTRIBUTION built for themes and DESIGN_SYSTEMS for design systems:
|
|
6
|
+
//
|
|
7
|
+
// "fonts": ["inter@type-mkt"],
|
|
8
|
+
// "themeSources": { "type-mkt": "acme/decklight-marketplace" }
|
|
9
|
+
//
|
|
10
|
+
// The deck records WHICH font it uses; the faces stay in the marketplace.
|
|
11
|
+
// Every server links them into the page from the checkouts on this machine
|
|
12
|
+
// (`linkFonts`: an @font-face per face, and a meta block the font picker
|
|
13
|
+
// reads) and answers the files under `decklight-font/<marketplace>/<name>/…`
|
|
14
|
+
// (`fontAsset`). `bundle` carries them as data: URIs. Nothing here fetches.
|
|
15
|
+
//
|
|
16
|
+
// A referenced font makes a FAMILY available; it does not apply it. A theme
|
|
17
|
+
// that names the family in --font-body gets it; the font picker offers it;
|
|
18
|
+
// the deck's `font` default (config) or the viewer's pick sets it.
|
|
19
|
+
|
|
20
|
+
import { readFileSync } from 'node:fs';
|
|
21
|
+
import { join, resolve, sep } from 'node:path';
|
|
22
|
+
import { realpathSync, statSync } from 'node:fs';
|
|
23
|
+
import { escapeHtml } from '../tools/escape.mjs';
|
|
24
|
+
import { FONT_API_VERSION, FACE_EXTENSIONS, fontFaceCss, fontStack } from '../tools/font-format.mjs';
|
|
25
|
+
import { configBlock, isDeck } from './runtime-link.mjs';
|
|
26
|
+
import { configHome, loadRegistry, loadCatalog, MarketplaceError, NAME_RE } from './marketplace.mjs';
|
|
27
|
+
import {
|
|
28
|
+
parseRef, resolveCatalogEntry, markedSources, withKey, referencedMarketplaces,
|
|
29
|
+
FONTS_KEY, SOURCES_KEY, MARKED_KEY, DESIGN_SYSTEMS_KEY,
|
|
30
|
+
} from './theme-refs.mjs';
|
|
31
|
+
import { resolveSource } from './theme.mjs';
|
|
32
|
+
import { signature } from './design-system-refs.mjs';
|
|
33
|
+
import { checkFontDir } from './font.mjs';
|
|
34
|
+
|
|
35
|
+
export { FONTS_KEY };
|
|
36
|
+
|
|
37
|
+
/** The config key a deck's DEFAULT font lives under: a referenced font's name, or a picker stack's label. */
|
|
38
|
+
export const FONT_DEFAULT_KEY = 'font';
|
|
39
|
+
|
|
40
|
+
/** The fonts a deck references, parsed; anything else dropped, not guessed at. */
|
|
41
|
+
export function fontRefs(html) {
|
|
42
|
+
const list = configBlock(html)?.config?.[FONTS_KEY];
|
|
43
|
+
if (!Array.isArray(list)) return [];
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
return list.map((e) => parseRef(e)).filter((r) => r && !seen.has(r.ref) && seen.add(r.ref));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Resolve a reference to its package directory on this machine — registry,
|
|
50
|
+
* catalog cache and checkouts only — or `{ missing }` in words a presenter can
|
|
51
|
+
* act on. `{ name, marketplace, ref, local, title, entry, dir, source }`.
|
|
52
|
+
*/
|
|
53
|
+
export function resolveFontRef(ref, home = configHome(), { source = null } = {}) {
|
|
54
|
+
const parsed = typeof ref === 'string' ? parseRef(ref) : ref;
|
|
55
|
+
if (!parsed) return { ref: String(ref), missing: 'not a font reference (name@marketplace)' };
|
|
56
|
+
const hit = resolveCatalogEntry(parsed, home, { source });
|
|
57
|
+
if (hit.missing) return hit;
|
|
58
|
+
const { local, title, entry, registered, origin } = hit;
|
|
59
|
+
if (entry.type !== 'font') return { ...parsed, entry, missing: `"${parsed.ref}" is a ${entry.type}, not a font` };
|
|
60
|
+
if (Number.isInteger(entry.apiVersion) && entry.apiVersion > FONT_API_VERSION) {
|
|
61
|
+
return { ...parsed, entry, missing: `${parsed.ref} needs a newer decklight — it is written for font format ${entry.apiVersion}, this one reads up to ${FONT_API_VERSION}` };
|
|
62
|
+
}
|
|
63
|
+
if (typeof entry.source !== 'string' || /^[a-z][a-z0-9+.-]*:/i.test(entry.source)) {
|
|
64
|
+
return { ...parsed, entry, missing: `${parsed.ref} names a URL as its source — a font is a directory of files in its marketplace` };
|
|
65
|
+
}
|
|
66
|
+
let dir;
|
|
67
|
+
try { dir = resolveSource(entry.source, { name: local, source: registered.source }, home); }
|
|
68
|
+
catch (e) {
|
|
69
|
+
if (e instanceof MarketplaceError) return { ...parsed, title, entry, missing: e.message.replace(/\n\s*/g, ' — ') };
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
let isDir = false;
|
|
73
|
+
try { isDir = statSync(dir).isDirectory(); } catch { /* not here */ }
|
|
74
|
+
if (!isDir) return { ...parsed, title, entry, missing: `${parsed.ref}: ${entry.source} is not in the marketplace's files` };
|
|
75
|
+
return { ...parsed, local, title, entry, dir: resolve(dir), source: origin };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const verdicts = new Map();
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Does the package STILL pass `decklight font gate`? It follows its
|
|
82
|
+
* marketplace, so it is re-checked wherever it is used, remembered by a stat
|
|
83
|
+
* signature. `{ ok, why, summary, manifest }`.
|
|
84
|
+
*/
|
|
85
|
+
export function fontVerdict(dir) {
|
|
86
|
+
let sig;
|
|
87
|
+
try { sig = signature(dir); } catch { return { ok: false, why: 'its files are gone' }; }
|
|
88
|
+
const hit = verdicts.get(dir);
|
|
89
|
+
if (hit && hit.sig === sig) return hit.value;
|
|
90
|
+
const r = checkFontDir(dir);
|
|
91
|
+
const value = r.ok
|
|
92
|
+
? { ok: true, summary: r.summary, manifest: r.manifest }
|
|
93
|
+
: { ok: false, why: `it no longer passes the font check — ${r.problems[0].file}${r.problems[0].line ? ` line ${r.problems[0].line}` : ''}: ${r.problems[0].msg} (decklight font gate)` };
|
|
94
|
+
verdicts.set(dir, { sig, value });
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** What the page is told about a font: the facts the font picker reads. */
|
|
99
|
+
export function fontMeta(verdict, name = verdict.manifest?.name) {
|
|
100
|
+
const m = verdict.manifest ?? {};
|
|
101
|
+
return { name, title: m.title, family: m.family, fallback: m.fallback, stack: fontStack(m), role: m.role ?? 'any', version: m.version };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Where a server answers a package's files, relative to the deck. */
|
|
105
|
+
export const fontHref = (marketplace, name, path) => `decklight-font/${marketplace}/${name}/${path}`;
|
|
106
|
+
|
|
107
|
+
/** JSON safe inside a <script> — the manifest is somebody else's file. */
|
|
108
|
+
const scriptJson = (value) => JSON.stringify(value).replace(/</g, '\\u003c');
|
|
109
|
+
|
|
110
|
+
/** The two blocks a page carries for one font: its @font-face rules, and its meta. */
|
|
111
|
+
function fontTags(name, verdict, urlFor) {
|
|
112
|
+
const n = escapeHtml(name);
|
|
113
|
+
return [
|
|
114
|
+
`<style data-font="${n}" data-font-version="${escapeHtml(String(verdict.manifest.version ?? ''))}">\n${fontFaceCss(verdict.manifest, urlFor).replace(/<\/(style)/gi, '<\\/$1')}\n</style>`,
|
|
115
|
+
`<script type="application/json" data-font-meta="${n}">${scriptJson(fontMeta(verdict, name))}</script>`,
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A deck's fonts, linked into the page on its way out — what every server
|
|
121
|
+
* does after `linkDesignSystems`, never `bundle`. Per reference, before
|
|
122
|
+
* `</head>`: a `<style data-font>` of @font-face rules whose `src` is the
|
|
123
|
+
* served file, and the meta. Nothing when the page already carries it (a
|
|
124
|
+
* bundle's own copy). One this machine cannot read becomes `<meta
|
|
125
|
+
* name="decklight-font-missing">` naming it and why: the theme's own stack
|
|
126
|
+
* shows, nothing breaks.
|
|
127
|
+
*/
|
|
128
|
+
export function linkFonts(html, home = configHome(), { log = null } = {}) {
|
|
129
|
+
if (!isDeck(html)) return html;
|
|
130
|
+
const refs = fontRefs(html);
|
|
131
|
+
if (!refs.length) return html;
|
|
132
|
+
const sources = markedSources(html);
|
|
133
|
+
const tags = [];
|
|
134
|
+
for (const ref of refs) {
|
|
135
|
+
if (new RegExp(`<style\\b[^>]*\\bdata-font\\s*=\\s*["']${ref.name}["']`, 'i').test(html)) continue;
|
|
136
|
+
const r = resolveFontRef(ref, home, { source: sources[ref.marketplace] ?? null });
|
|
137
|
+
const verdict = r.dir ? fontVerdict(r.dir) : null;
|
|
138
|
+
if (r.dir && !verdict.ok) r.missing = verdict.why;
|
|
139
|
+
if (r.dir && verdict.ok) tags.push(...fontTags(ref.name, verdict, (file) => fontHref(r.local, r.name, file)));
|
|
140
|
+
else {
|
|
141
|
+
tags.push(`<meta name="decklight-font-missing" content="${escapeHtml(`${ref.ref} — ${r.missing}`)}">`);
|
|
142
|
+
log?.(`font ${ref.ref}: ${r.missing}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (!tags.length) return html;
|
|
146
|
+
const masked = html.replace(/<!--[\s\S]*?-->/g, (m) => ' '.repeat(m.length));
|
|
147
|
+
const headEnd = masked.search(/<\/head>/i);
|
|
148
|
+
const at = headEnd !== -1 ? headEnd : Math.max(0, masked.search(/<body\b/i));
|
|
149
|
+
return `${html.slice(0, at)}${tags.join('\n')}\n${html.slice(at)}`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* What a bundle carries for one resolved, still-valid font: the same two
|
|
154
|
+
* blocks, every face a base64 data: URI — `{ tags, bytes, faces }`. A
|
|
155
|
+
* bundle opened offline has the face; a re-serve sees the <style data-font>
|
|
156
|
+
* and links no second copy.
|
|
157
|
+
*/
|
|
158
|
+
export function bundleFont(r, verdict) {
|
|
159
|
+
let bytes = 0;
|
|
160
|
+
const urlFor = (file) => {
|
|
161
|
+
const data = readFileSync(join(r.dir, file));
|
|
162
|
+
bytes += data.length;
|
|
163
|
+
const mime = file.toLowerCase().endsWith('.woff2') ? 'font/woff2' : 'font/woff';
|
|
164
|
+
return `data:${mime};base64,${data.toString('base64')}`;
|
|
165
|
+
};
|
|
166
|
+
const tags = fontTags(r.name, verdict, urlFor);
|
|
167
|
+
return { tags, bytes, faces: verdict.manifest.faces.length };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const NAMESPACE = /(?:^|\/)decklight-font\/(.*)$/;
|
|
171
|
+
|
|
172
|
+
/** Is this request path in the font namespace at all? */
|
|
173
|
+
export const inFontNamespace = (rel) => NAMESPACE.test(String(rel ?? '').split('\\').join('/'));
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* `staticFiles`' answer for a face of a registered font — `{ file, type,
|
|
177
|
+
* headers }`, or null, answered as one plain 404 whatever the reason. The
|
|
178
|
+
* path must name a face the manifest lists (never the licence, never a file
|
|
179
|
+
* it does not list); the package must resolve and still pass its check; the
|
|
180
|
+
* real path must stay inside the package's real directory.
|
|
181
|
+
*/
|
|
182
|
+
export function fontAsset(rel, home = configHome()) {
|
|
183
|
+
const m = NAMESPACE.exec(String(rel ?? '').split('\\').join('/'));
|
|
184
|
+
if (!m) return null;
|
|
185
|
+
const segs = m[1].split('/');
|
|
186
|
+
if (segs.length < 3) return null;
|
|
187
|
+
const [marketplace, name, ...path] = segs;
|
|
188
|
+
if (!NAME_RE.test(marketplace) || !NAME_RE.test(name)) return null;
|
|
189
|
+
if (!path.every((s) => /^[\w.-]+$/.test(s) && !s.startsWith('.'))) return null;
|
|
190
|
+
const relPath = path.join('/');
|
|
191
|
+
const ext = /\.([A-Za-z0-9]+)$/.exec(relPath)?.[1]?.toLowerCase();
|
|
192
|
+
if (!FACE_EXTENSIONS.includes(ext)) return null;
|
|
193
|
+
const r = resolveFontRef({ name, marketplace, ref: `${name}@${marketplace}` }, home);
|
|
194
|
+
if (!r.dir) return null;
|
|
195
|
+
const verdict = fontVerdict(r.dir);
|
|
196
|
+
if (!verdict.ok || !verdict.manifest.faces.some((f) => f.file === relPath)) return null;
|
|
197
|
+
let real, root;
|
|
198
|
+
try { real = realpathSync(join(r.dir, ...path)); root = realpathSync(r.dir); } catch { return null; }
|
|
199
|
+
if (!real.startsWith(root + sep)) return null;
|
|
200
|
+
try { if (!statSync(real).isFile()) return null; } catch { return null; }
|
|
201
|
+
return { file: real, type: ext === 'woff2' ? 'font/woff2' : 'font/woff', headers: { 'x-content-type-options': 'nosniff', 'access-control-allow-origin': '*' } };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Reference (`on`) or drop a font in the deck's configuration block, editing
|
|
206
|
+
* only its keys. The source rides in the shared `themeSources`, once per
|
|
207
|
+
* marketplace, and goes only with the last reference of ANY kind. `use`
|
|
208
|
+
* also makes it the deck's default (`"font"`); dropping the font the deck
|
|
209
|
+
* defaults to drops the default too. Returns `{ html, changed }`.
|
|
210
|
+
*/
|
|
211
|
+
export function setFont(html, ref, on, { source = null, use = false } = {}) {
|
|
212
|
+
const parsed = parseRef(ref);
|
|
213
|
+
if (!parsed) throw new MarketplaceError(`"${ref}" is not a font reference — name@marketplace`);
|
|
214
|
+
const block = configBlock(html);
|
|
215
|
+
if (!block) {
|
|
216
|
+
throw new MarketplaceError('the deck has no configuration block to record its fonts in'
|
|
217
|
+
+ ' — decklight upgrade --link <deck.html> gives it one');
|
|
218
|
+
}
|
|
219
|
+
if (block.error) throw new MarketplaceError(block.error);
|
|
220
|
+
const current = fontRefs(html);
|
|
221
|
+
const has = current.some((r) => r.ref === parsed.ref);
|
|
222
|
+
const isDefault = block.config[FONT_DEFAULT_KEY] === parsed.name;
|
|
223
|
+
if (on) {
|
|
224
|
+
if (has && (!use || isDefault)) return { html, changed: false };
|
|
225
|
+
const clash = current.find((r) => r.name === parsed.name && r.ref !== parsed.ref);
|
|
226
|
+
if (clash) throw new MarketplaceError(`the deck already uses ${clash.ref} — two fonts called "${parsed.name}" cannot both be referenced`);
|
|
227
|
+
} else if (!has) return { html, changed: false };
|
|
228
|
+
const next = on ? [...new Set([...current.map((r) => r.ref), parsed.ref])] : current.map((r) => r.ref).filter((r) => r !== parsed.ref);
|
|
229
|
+
const sources = markedSources(html);
|
|
230
|
+
if (on && source) sources[parsed.marketplace] = source;
|
|
231
|
+
const others = referencedMarketplaces(html, [MARKED_KEY, DESIGN_SYSTEMS_KEY]);
|
|
232
|
+
for (const m of Object.keys(sources)) {
|
|
233
|
+
if (!next.some((r) => r.endsWith(`@${m}`)) && !others.has(m)) delete sources[m];
|
|
234
|
+
}
|
|
235
|
+
let inner = withKey(block.inner, FONTS_KEY, next.length ? next : null);
|
|
236
|
+
inner = withKey(inner, SOURCES_KEY, Object.keys(sources).length ? sources : null);
|
|
237
|
+
if (on && use) inner = withKey(inner, FONT_DEFAULT_KEY, parsed.name);
|
|
238
|
+
if (!on && isDefault) inner = withKey(inner, FONT_DEFAULT_KEY, null);
|
|
239
|
+
return { html: html.slice(0, block.innerStart) + inner + html.slice(block.innerEnd), changed: true };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Every font every registered marketplace offers, from the cache — what
|
|
244
|
+
* `font list` and the font picker (authoring) show — with the faces a page
|
|
245
|
+
* needs to PREVIEW one it does not reference yet (the edit server answers
|
|
246
|
+
* them under decklight-font/), and the marketplaces it could not list.
|
|
247
|
+
*/
|
|
248
|
+
export function marketplaceFonts(home = configHome()) {
|
|
249
|
+
const fonts = [];
|
|
250
|
+
const stale = [];
|
|
251
|
+
const unfetched = [];
|
|
252
|
+
for (const market of Object.keys(loadRegistry(home).marketplaces ?? {})) {
|
|
253
|
+
const catalog = loadCatalog(market, home);
|
|
254
|
+
if (!catalog) { unfetched.push(market); continue; }
|
|
255
|
+
if (!catalog.ok) { stale.push(market); continue; }
|
|
256
|
+
for (const entry of catalog.manifest.entries ?? []) {
|
|
257
|
+
if (entry.type !== 'font') continue;
|
|
258
|
+
const r = resolveFontRef({ name: entry.name, marketplace: market, ref: `${entry.name}@${market}` }, home);
|
|
259
|
+
const verdict = r.dir ? fontVerdict(r.dir) : null;
|
|
260
|
+
const missing = r.missing ?? (verdict && !verdict.ok ? verdict.why : null);
|
|
261
|
+
fonts.push({
|
|
262
|
+
name: entry.name, marketplace: market, qualified: `${entry.name}@${market}`,
|
|
263
|
+
group: catalog.manifest.title?.trim() || market,
|
|
264
|
+
description: entry.description ?? '', version: entry.version ?? null,
|
|
265
|
+
...(missing ? { missing } : {
|
|
266
|
+
...fontMeta(verdict, entry.name),
|
|
267
|
+
faces: verdict.manifest.faces.map((f) => ({ url: fontHref(market, entry.name, f.file), weight: f.weight ?? 400, style: f.style ?? 'normal', format: f.file.endsWith('.woff2') ? 'woff2' : 'woff' })),
|
|
268
|
+
}),
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return { fonts, stale, unfetched };
|
|
273
|
+
}
|
package/cli/font.mjs
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright 2026 Gilles Philippart
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
// decklight font — the font unit (SPEC FONTS).
|
|
6
|
+
//
|
|
7
|
+
// decklight font gate <dir>
|
|
8
|
+
// decklight font add|remove <name@marketplace> <deck.html> [--use]
|
|
9
|
+
// decklight font list [<deck.html>]
|
|
10
|
+
//
|
|
11
|
+
// `check` is the admission gate a catalog's CI runs: a valid package prints
|
|
12
|
+
// what it holds and exits 0; anything else names the file and the rule and
|
|
13
|
+
// exits 1. Every rule lives in tools/font-format.mjs, which is pure — this file
|
|
14
|
+
// only reads a directory into the shape it takes.
|
|
15
|
+
//
|
|
16
|
+
// A deck depends on a font by REFERENCE (cli/font-refs.mjs): `add` writes
|
|
17
|
+
// `fonts` (and the shared `themeSources`) into its configuration block after
|
|
18
|
+
// the package passes `check`, and `--use` makes it the deck's default font.
|
|
19
|
+
// Every server serves the faces from the marketplace checkout; `bundle`
|
|
20
|
+
// carries them. Nothing is installed into ~/.decklight/.
|
|
21
|
+
|
|
22
|
+
import { existsSync, lstatSync, openSync, readSync, closeSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
23
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
24
|
+
import { argReader, isMain } from '../tools/args.mjs';
|
|
25
|
+
import { checkFontPackage, FONT_API_VERSION, FACE_EXTENSIONS, FACE_WARN_BYTES } from '../tools/font-format.mjs';
|
|
26
|
+
|
|
27
|
+
const USAGE = `usage: decklight font <add|remove|list|check> …
|
|
28
|
+
|
|
29
|
+
decklight font add <name@marketplace> <deck.html> [--use]
|
|
30
|
+
reference a font from a deck — after the package passes check; the deck
|
|
31
|
+
gains one entry in its configuration block, never the files. --use also
|
|
32
|
+
makes it the font the deck opens in (its "font" default)
|
|
33
|
+
EXAMPLE: decklight font add inter@type-mkt talk.html --use
|
|
34
|
+
|
|
35
|
+
decklight font remove <name@marketplace> <deck.html>
|
|
36
|
+
drop the reference (and the default, if it was the default)
|
|
37
|
+
|
|
38
|
+
decklight font list [<deck.html>]
|
|
39
|
+
what a deck references; with no deck, every font the registered
|
|
40
|
+
marketplaces offer — from the cache alone, works on a plane
|
|
41
|
+
|
|
42
|
+
decklight font gate <dir>
|
|
43
|
+
the marketplace admission gate for a font package (SPEC FONTS). Prints
|
|
44
|
+
what the package holds and exits 0, or names the file and the rule for
|
|
45
|
+
every problem and exits 1.
|
|
46
|
+
EXAMPLE: decklight font gate fonts/inter
|
|
47
|
+
|
|
48
|
+
A font is a directory:
|
|
49
|
+
font.json apiVersion (${FONT_API_VERSION}), name, version (semver), title,
|
|
50
|
+
family (the CSS name a theme writes), fallback ("system-ui, sans-serif"),
|
|
51
|
+
license ("OFL.txt"), faces [{ file, weight, style }]
|
|
52
|
+
+ description, role (body · heading · mono · any)
|
|
53
|
+
faces ${FACE_EXTENSIONS.join(' · ')} — over ${FACE_WARN_BYTES / 1024} KB a face is a warning
|
|
54
|
+
licence the file "license" names — required: a deck that carries a font redistributes it
|
|
55
|
+
|
|
56
|
+
A theme names a family in --font-body; a font package supplies its faces.`;
|
|
57
|
+
|
|
58
|
+
/** The first bytes of a file, as latin1 — enough for a font's magic. */
|
|
59
|
+
function head(path) {
|
|
60
|
+
const fd = openSync(path, 'r');
|
|
61
|
+
try {
|
|
62
|
+
const buf = Buffer.alloc(4);
|
|
63
|
+
const n = readSync(fd, buf, 0, 4, 0);
|
|
64
|
+
return buf.subarray(0, n).toString('latin1');
|
|
65
|
+
} finally { closeSync(fd); }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A package directory as `checkFontPackage` takes it: every file by its
|
|
70
|
+
* /-separated path, with its size and first bytes. A symlink that resolves
|
|
71
|
+
* outside the package is a problem of its own.
|
|
72
|
+
*/
|
|
73
|
+
export function readFontPackage(dir) {
|
|
74
|
+
const root = realpathSync(resolve(dir));
|
|
75
|
+
const files = new Map();
|
|
76
|
+
const escapes = [];
|
|
77
|
+
const walk = (abs) => {
|
|
78
|
+
for (const name of readdirSync(abs).sort()) {
|
|
79
|
+
if (name === '.git') continue;
|
|
80
|
+
const full = join(abs, name);
|
|
81
|
+
const rel = relative(root, full).split(sep).join('/');
|
|
82
|
+
let target = full;
|
|
83
|
+
if (lstatSync(full).isSymbolicLink()) {
|
|
84
|
+
try { target = realpathSync(full); } catch { escapes.push(rel); continue; }
|
|
85
|
+
if (target !== root && !target.startsWith(root + sep)) { escapes.push(rel); continue; }
|
|
86
|
+
}
|
|
87
|
+
const st = statSync(target);
|
|
88
|
+
if (st.isDirectory()) { walk(full); continue; }
|
|
89
|
+
files.set(rel, { size: st.size, head: head(target), ...(name === 'font.json' ? { text: readFileSync(target, 'utf8') } : {}) });
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
walk(root);
|
|
93
|
+
return { manifest: files.get('font.json')?.text ?? null, files, escapes };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A package, checked — the gate's whole verdict, with symlink escapes folded in and the manifest parsed. */
|
|
97
|
+
export function checkFontDir(dir) {
|
|
98
|
+
const { manifest, files, escapes } = readFontPackage(dir);
|
|
99
|
+
if (manifest === null) {
|
|
100
|
+
return { ok: false, problems: [{ file: 'font.json', rule: 'file-missing', msg: 'no font.json at the package root — this is not a font package' }], warnings: [], summary: {} };
|
|
101
|
+
}
|
|
102
|
+
const r = checkFontPackage({ manifest, files });
|
|
103
|
+
for (const rel of escapes) r.problems.push({ file: rel, rule: 'file-outside', msg: 'a symlink that resolves outside the package — a font reaches only its own files' });
|
|
104
|
+
r.ok = r.problems.length === 0;
|
|
105
|
+
try { r.manifest = JSON.parse(manifest); } catch { r.manifest = null; }
|
|
106
|
+
return r;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const where = (p) => `${p.file}${p.line ? ` line ${p.line}` : ''}`;
|
|
110
|
+
const kb = (n) => (n < 1024 * 1024 ? `${Math.max(1, Math.round(n / 1024))} KB` : `${(n / 1024 / 1024).toFixed(1)} MB`);
|
|
111
|
+
|
|
112
|
+
/** The report, as the lines to print. */
|
|
113
|
+
export function reportLines(dir, r) {
|
|
114
|
+
const s = r.summary ?? {};
|
|
115
|
+
const out = [];
|
|
116
|
+
if (!r.ok) {
|
|
117
|
+
out.push(`✘ ${s.name ?? dir} — ${r.problems.length} problem${r.problems.length === 1 ? '' : 's'}, not admitted`);
|
|
118
|
+
for (const p of r.problems) out.push(` ${where(p)}: ${p.msg} [${p.rule}]`);
|
|
119
|
+
} else {
|
|
120
|
+
out.push(`✔ ${s.name} — font ${s.version}, api ${s.apiVersion}`);
|
|
121
|
+
out.push(` family '${s.family}', ${s.fallback} (${s.role})`);
|
|
122
|
+
out.push(` faces ${s.faces.map((f) => `${f.weight}${f.style === 'italic' ? 'i' : ''}`).join(' · ')} — ${s.faces.length} file${s.faces.length === 1 ? '' : 's'}, ${kb(s.bytes)}`);
|
|
123
|
+
out.push(` licence ${s.license}`);
|
|
124
|
+
}
|
|
125
|
+
for (const w of r.warnings ?? []) out.push(` ⚠ ${where(w)}: ${w.msg}`);
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function checkMain(args) {
|
|
130
|
+
const [dir] = args.filter((a) => !a.startsWith('-'));
|
|
131
|
+
if (!dir) { console.error(`decklight font gate: needs a package directory\n\n${USAGE}`); return 1; }
|
|
132
|
+
if (!existsSync(dir)) { console.error(`decklight font gate: no such directory: ${dir}`); return 1; }
|
|
133
|
+
if (!statSync(dir).isDirectory()) { console.error(`decklight font gate: ${dir} is a file — a font is a directory holding font.json`); return 1; }
|
|
134
|
+
const r = checkFontDir(dir);
|
|
135
|
+
for (const line of reportLines(dir, r)) console.log(line);
|
|
136
|
+
return r.ok ? 0 : 1;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function readDeckArg(cmd, deck) {
|
|
140
|
+
if (!deck) { console.error(`decklight font ${cmd}: needs a deck\n\n${USAGE}`); return null; }
|
|
141
|
+
const path = resolve(deck);
|
|
142
|
+
if (!existsSync(path)) { console.error(`decklight font ${cmd}: no such deck: ${deck}`); return null; }
|
|
143
|
+
return { path, html: readFileSync(path, 'utf8') };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function catalogs() {
|
|
147
|
+
const { configHome, loadRegistry, loadCatalog } = await import('./marketplace.mjs');
|
|
148
|
+
const out = {};
|
|
149
|
+
for (const name of Object.keys(loadRegistry(configHome()).marketplaces ?? {})) {
|
|
150
|
+
const c = loadCatalog(name);
|
|
151
|
+
if (c?.ok) out[name] = c.manifest;
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function addMain(args, on) {
|
|
157
|
+
const cmd = on ? 'add' : 'remove';
|
|
158
|
+
const use = args.includes('--use');
|
|
159
|
+
const [ref, deck] = args.filter((a) => !a.startsWith('-'));
|
|
160
|
+
if (!ref) { console.error(`decklight font ${cmd}: needs a font and a deck\n\n${USAGE}`); return 1; }
|
|
161
|
+
const d = readDeckArg(cmd, deck);
|
|
162
|
+
if (!d) return 1;
|
|
163
|
+
const { MarketplaceError, resolveEntry, recordInstall, loadRegistry, configHome } = await import('./marketplace.mjs');
|
|
164
|
+
const { resolveFontRef, setFont, fontRefs } = await import('./font-refs.mjs');
|
|
165
|
+
const { refForDeck } = await import('./theme-refs.mjs');
|
|
166
|
+
const { writeFileAtomic } = await import('../tools/atomic-write.mjs');
|
|
167
|
+
try {
|
|
168
|
+
if (!on) {
|
|
169
|
+
const hit = fontRefs(d.html).find((r) => r.ref === ref || r.name === ref);
|
|
170
|
+
if (!hit) {
|
|
171
|
+
const has = fontRefs(d.html).map((r) => r.ref);
|
|
172
|
+
console.error(`decklight font remove: ${ref} is not referenced by ${deck}${has.length ? ` — it uses ${has.join(', ')}` : ' — it uses no font'}`);
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
175
|
+
const out = setFont(d.html, hit.ref, false);
|
|
176
|
+
if (out.changed) writeFileAtomic(d.path, out.html);
|
|
177
|
+
console.log(out.changed ? `dropped ${hit.ref} from ${deck} — the faces stay in their marketplace` : `${hit.ref} was not referenced by ${deck}`);
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
let qualified = ref;
|
|
181
|
+
try { qualified = resolveEntry(ref, await catalogs()).qualified; } catch (e) { if (!(e instanceof MarketplaceError)) throw e; console.error(`decklight font add: ${e.message}`); return 1; }
|
|
182
|
+
const r = resolveFontRef(qualified);
|
|
183
|
+
if (!r.dir) { console.error(`decklight font add: ${r.ref} — ${r.missing}`); return 1; }
|
|
184
|
+
const verdict = checkFontDir(r.dir);
|
|
185
|
+
if (!verdict.ok) {
|
|
186
|
+
for (const line of reportLines(r.dir, verdict)) console.error(line);
|
|
187
|
+
console.error(`\ndecklight font add: ${r.ref} was NOT referenced — the package fails the check above`);
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
const deckRef = refForDeck(d.html, r.name, r.local, r.source ?? null);
|
|
191
|
+
const out = setFont(d.html, deckRef, true, { source: r.source ?? null, use });
|
|
192
|
+
if (out.changed) writeFileAtomic(d.path, out.html);
|
|
193
|
+
const commit = loadRegistry(configHome()).marketplaces?.[r.local]?.commit ?? null;
|
|
194
|
+
recordInstall({ type: 'font', name: r.name, marketplace: r.local, version: r.entry.version ?? null, commit });
|
|
195
|
+
const s = verdict.summary;
|
|
196
|
+
console.log(out.changed
|
|
197
|
+
? `${deck} now uses ${deckRef} ${s.version} — '${s.family}', ${s.faces.length} face${s.faces.length === 1 ? '' : 's'}${use ? ', and opens in it' : '; pick it under / → Font…, or add --use to open in it'}`
|
|
198
|
+
: `${deck} already uses ${deckRef}`);
|
|
199
|
+
return 0;
|
|
200
|
+
} catch (e) {
|
|
201
|
+
if (e instanceof MarketplaceError) { console.error(`decklight font ${cmd}: ${e.message}`); return 1; }
|
|
202
|
+
throw e;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function listMain(args) {
|
|
207
|
+
const [deck] = args.filter((a) => !a.startsWith('-'));
|
|
208
|
+
const { marketplaceFonts, fontRefs, resolveFontRef } = await import('./font-refs.mjs');
|
|
209
|
+
const { markedSources } = await import('./theme-refs.mjs');
|
|
210
|
+
if (deck) {
|
|
211
|
+
const d = readDeckArg('list', deck);
|
|
212
|
+
if (!d) return 1;
|
|
213
|
+
const refs = fontRefs(d.html);
|
|
214
|
+
if (!refs.length) { console.log(`${deck} uses no font package — decklight font add <name@marketplace> ${deck}`); return 0; }
|
|
215
|
+
const sources = markedSources(d.html);
|
|
216
|
+
for (const ref of refs) {
|
|
217
|
+
const r = resolveFontRef(ref, undefined, { source: sources[ref.marketplace] ?? null });
|
|
218
|
+
console.log(`${ref.ref}${r.entry?.version ? ` ${r.entry.version}` : ''}${r.missing ? ` — missing: ${r.missing}` : r.title ? ` — ${r.title}` : ''}`);
|
|
219
|
+
}
|
|
220
|
+
return 0;
|
|
221
|
+
}
|
|
222
|
+
const { fonts, stale, unfetched } = marketplaceFonts();
|
|
223
|
+
if (!fonts.length) console.log('no registered marketplace offers a font');
|
|
224
|
+
for (const f of fonts) {
|
|
225
|
+
console.log(`${f.qualified}${f.version ? ` ${f.version}` : ''}${f.family ? ` '${f.family}'` : ''}${f.description ? ` — ${f.description}` : ''}${f.missing ? ` (${f.missing})` : ''}`);
|
|
226
|
+
}
|
|
227
|
+
for (const m of unfetched) console.log(` ${m} has not been fetched yet — decklight marketplace update ${m}`);
|
|
228
|
+
for (const m of stale) console.log(` ${m}'s cached catalog could not be read — decklight marketplace update ${m}`);
|
|
229
|
+
return 0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export async function fontMain(args = []) {
|
|
233
|
+
const sub = args[0];
|
|
234
|
+
if (!sub || sub === '--help' || sub === '-h' || sub === 'help') { console.log(USAGE); return sub ? 0 : 1; }
|
|
235
|
+
const rest = args.slice(1);
|
|
236
|
+
if (rest.includes('--help') || rest.includes('-h')) { console.log(USAGE); return 0; }
|
|
237
|
+
argReader(rest);
|
|
238
|
+
if (sub === 'gate' || sub === 'check') return checkMain(rest); // `check` still answers, unadvertised: a catalog's CI may run it
|
|
239
|
+
if (sub === 'add') return addMain(rest, true);
|
|
240
|
+
if (sub === 'remove') return addMain(rest, false);
|
|
241
|
+
if (sub === 'list') return listMain(rest);
|
|
242
|
+
console.error(`decklight font: unknown subcommand "${sub}" — add, remove, list, check\n\n${USAGE}`);
|
|
243
|
+
return 1;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (isMain(import.meta.url)) process.exit(await fontMain(process.argv.slice(2)));
|
package/cli/git-tree.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
// Building a git tree without touching the working tree.
|
|
5
5
|
//
|
|
6
|
-
// Lifted out of cli/publish.mjs, which invented this, when `
|
|
6
|
+
// Lifted out of cli/publish.mjs, which invented this, when `comments submit`
|
|
7
7
|
// turned out to need exactly the same thing. It is the mechanism behind every "push something without checking
|
|
8
8
|
// anything out" in decklight: objects land in the repository's database,
|
|
9
9
|
// nothing references them until the push, and neither the working tree, the
|