decklight 0.8.0 → 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 +71 -26
- 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 +35 -2
- 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 +19 -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,409 @@
|
|
|
1
|
+
// Copyright 2026 Gilles Philippart
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// A deck's design systems, as REFERENCES (SPEC DESIGN_SYSTEMS) — the second
|
|
5
|
+
// instance of what THEME_DISTRIBUTION built for themes:
|
|
6
|
+
//
|
|
7
|
+
// "designSystems": ["acme@acme-mkt"],
|
|
8
|
+
// "themeSources": { "acme-mkt": "acme/decklight-marketplace" }
|
|
9
|
+
//
|
|
10
|
+
// The deck records WHICH design system it uses; the package stays in its
|
|
11
|
+
// marketplace. Every server — write mode, --no-trust, and the render server behind
|
|
12
|
+
// shot/pdf/pptx/video — links it into the page from the checkouts on this
|
|
13
|
+
// machine (`linkDesignSystems`) and answers its files under
|
|
14
|
+
// `decklight-design-system/<marketplace>/<name>/…` (`designSystemAsset`).
|
|
15
|
+
// Nothing here fetches: a deck on a plane serves what this machine has and
|
|
16
|
+
// names what it has not (MARKETPLACE_REGISTRY — registered, not fetched).
|
|
17
|
+
//
|
|
18
|
+
// What differs from a marked theme, on purpose:
|
|
19
|
+
// - the stylesheet is ALWAYS ON (no `media="not all"`): a design system is
|
|
20
|
+
// not an alternative to choose between, so `T` leaves it applied;
|
|
21
|
+
// - a package is a DIRECTORY of somebody else's files, so serving it is held
|
|
22
|
+
// tighter than the deck root — plain segments, the asset allowlist, real
|
|
23
|
+
// paths inside the package, fixed MIME, nosniff, a script-free SVG policy,
|
|
24
|
+
// and one indistinguishable 404 for every refusal;
|
|
25
|
+
// - the page also carries the package's meta (palette, templates and slots)
|
|
26
|
+
// and its templates, inline in a <template>, so the engine expands them
|
|
27
|
+
// synchronously, identically for a served deck and a bundled one;
|
|
28
|
+
// - an https `source` has no cache to land in (the theme cache holds one
|
|
29
|
+
// file; a package is many), so it resolves as missing.
|
|
30
|
+
//
|
|
31
|
+
// Every package is re-checked where it is used, not only when it was added —
|
|
32
|
+
// `marketplace update` can change its bytes afterwards — remembered by a
|
|
33
|
+
// stat signature so a page load re-reads nothing that has not changed.
|
|
34
|
+
|
|
35
|
+
import { readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
36
|
+
import { dirname, join, resolve, sep } from 'node:path';
|
|
37
|
+
import { escapeHtml } from '../tools/escape.mjs';
|
|
38
|
+
import { DESIGN_SYSTEM_API_VERSION, ASSET_EXTENSIONS } from '../tools/design-system-format.mjs';
|
|
39
|
+
import { configBlock, isDeck } from './runtime-link.mjs';
|
|
40
|
+
import { configHome, loadRegistry, loadCatalog, MarketplaceError, NAME_RE } from './marketplace.mjs';
|
|
41
|
+
import {
|
|
42
|
+
parseRef, resolveCatalogEntry, markedSources, withKey, referencedMarketplaces, DESIGN_SYSTEMS_KEY, FONTS_KEY, SOURCES_KEY, MARKED_KEY,
|
|
43
|
+
} from './theme-refs.mjs';
|
|
44
|
+
import { resolveSource } from './theme.mjs';
|
|
45
|
+
import { checkDir } from './design-system.mjs';
|
|
46
|
+
|
|
47
|
+
export { DESIGN_SYSTEMS_KEY };
|
|
48
|
+
|
|
49
|
+
/** The design systems a deck references, parsed; anything else dropped, not guessed at. */
|
|
50
|
+
export function designSystemRefs(html) {
|
|
51
|
+
const list = configBlock(html)?.config?.[DESIGN_SYSTEMS_KEY];
|
|
52
|
+
if (!Array.isArray(list)) return [];
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
return list.map((e) => parseRef(e)).filter((r) => r && !seen.has(r.ref) && seen.add(r.ref));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Resolve a reference to its package directory on this machine — registry,
|
|
59
|
+
* catalog cache and checkouts only — or `{ missing }` in words a presenter can
|
|
60
|
+
* act on. Returns `{ name, marketplace, ref, local, title, entry, dir, source }`.
|
|
61
|
+
*/
|
|
62
|
+
export function resolveDesignSystemRef(ref, home = configHome(), { source = null } = {}) {
|
|
63
|
+
const parsed = typeof ref === 'string' ? parseRef(ref) : ref;
|
|
64
|
+
if (!parsed) return { ref: String(ref), missing: 'not a design-system reference (name@marketplace)' };
|
|
65
|
+
const hit = resolveCatalogEntry(parsed, home, { source });
|
|
66
|
+
if (hit.missing) return hit;
|
|
67
|
+
const { local, title, entry, registered, origin } = hit;
|
|
68
|
+
if (entry.type !== 'design-system') return { ...parsed, entry, missing: `"${parsed.ref}" is a ${entry.type}, not a design system` };
|
|
69
|
+
if (Number.isInteger(entry.apiVersion) && entry.apiVersion > DESIGN_SYSTEM_API_VERSION) {
|
|
70
|
+
return { ...parsed, entry, missing: `${parsed.ref} needs a newer decklight — it is written for design-system format ${entry.apiVersion}, this one reads up to ${DESIGN_SYSTEM_API_VERSION}` };
|
|
71
|
+
}
|
|
72
|
+
if (typeof entry.source !== 'string' || /^[a-z][a-z0-9+.-]*:/i.test(entry.source)) {
|
|
73
|
+
return { ...parsed, entry, missing: `${parsed.ref} names a URL as its source — a design system is a directory of files in its marketplace, and there is no cache for one` };
|
|
74
|
+
}
|
|
75
|
+
let dir;
|
|
76
|
+
try { dir = resolveSource(entry.source, { name: local, source: registered.source }, home); }
|
|
77
|
+
catch (e) {
|
|
78
|
+
if (e instanceof MarketplaceError) return { ...parsed, title, entry, missing: e.message.replace(/\n\s*/g, ' — ') };
|
|
79
|
+
throw e;
|
|
80
|
+
}
|
|
81
|
+
let isDir = false;
|
|
82
|
+
try { isDir = statSync(dir).isDirectory(); } catch { /* not here */ }
|
|
83
|
+
if (!isDir) return { ...parsed, title, entry, missing: `${parsed.ref}: ${entry.source} is not in the marketplace's files` };
|
|
84
|
+
return { ...parsed, local, title, entry, dir: resolve(dir), source: origin };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A cheap fingerprint of a package's files — names, sizes and mtimes — so nothing unchanged is re-read. */
|
|
88
|
+
export function signature(dir) {
|
|
89
|
+
const parts = [];
|
|
90
|
+
const walk = (abs, rel) => {
|
|
91
|
+
for (const name of readdirSync(abs).sort()) {
|
|
92
|
+
if (name === '.git') continue;
|
|
93
|
+
const full = join(abs, name);
|
|
94
|
+
let st;
|
|
95
|
+
try { st = statSync(full); } catch { parts.push(`${rel}${name}!`); continue; }
|
|
96
|
+
if (st.isDirectory()) walk(full, `${rel}${name}/`);
|
|
97
|
+
else parts.push(`${rel}${name}:${st.size}:${st.mtimeMs}`);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
walk(dir, '');
|
|
101
|
+
return parts.join('|');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const verdicts = new Map();
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Does the package STILL pass `decklight design-system gate`? It follows its
|
|
108
|
+
* marketplace, so it is re-checked wherever it is used. `{ ok, why, summary,
|
|
109
|
+
* manifest }`, remembered by its stat signature.
|
|
110
|
+
*/
|
|
111
|
+
export function packageVerdict(dir) {
|
|
112
|
+
let sig;
|
|
113
|
+
try { sig = signature(dir); } catch { return { ok: false, why: 'its files are gone' }; }
|
|
114
|
+
const hit = verdicts.get(dir);
|
|
115
|
+
if (hit && hit.sig === sig) return hit.value;
|
|
116
|
+
const r = checkDir(dir);
|
|
117
|
+
const value = r.ok
|
|
118
|
+
? { ok: true, summary: r.summary, manifest: r.manifest, templatesHtml: r.templatesHtml }
|
|
119
|
+
: { ok: false, why: `it no longer passes the design-system check — ${r.problems[0].file}${r.problems[0].line ? ` line ${r.problems[0].line}` : ''}: ${r.problems[0].msg} (decklight design-system gate)` };
|
|
120
|
+
verdicts.set(dir, { sig, value });
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** What the page is told about a package: the facts the engine and the palette read. */
|
|
125
|
+
export function designSystemMeta(verdict) {
|
|
126
|
+
const m = verdict.manifest ?? {};
|
|
127
|
+
const brand = verdict.summary?.brand ?? null;
|
|
128
|
+
return {
|
|
129
|
+
name: m.name, version: m.version, title: m.title,
|
|
130
|
+
// a palette of scales (SPEC BRAND_PALETTE) is told as one entry per swatch, a colour's ten in a row
|
|
131
|
+
palette: brand ? brand.palette : Array.isArray(m.palette) ? m.palette : [],
|
|
132
|
+
...(brand ? { scales: true, themes: brand.themes.map(({ name, title, mode, refs, roleValues }) => ({ name, title, mode, refs, ...(roleValues ? { roles: roleValues } : {}) })) } : {}),
|
|
133
|
+
// its roles (SPEC DESIGN_SYSTEM_ROLES): what the Colors tab offers on a deck held to the brand, each theme's value above
|
|
134
|
+
// …and which contract tokens read which role: a fill role is that diagram slot (SVG_DIAGRAMS)
|
|
135
|
+
...(brand?.roles ? { roles: brand.roles, contract: brand.contract ?? {} } : {}),
|
|
136
|
+
// the themes it is made to sit on — the theme picker lists them first
|
|
137
|
+
recommendedThemes: Array.isArray(m.recommendedThemes) ? m.recommendedThemes.filter((t) => typeof t === 'string') : [],
|
|
138
|
+
// …and the fonts (SPEC FONTS) — the font picker lists them first
|
|
139
|
+
recommendedFonts: Array.isArray(m.recommendedFonts) ? m.recommendedFonts.filter((t) => typeof t === 'string') : [],
|
|
140
|
+
templates: (verdict.summary?.templates ?? []).map(({ id, title, slots }) => ({ id, title, slots })),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Where a server answers a package's files, relative to the deck. */
|
|
145
|
+
export const designSystemHref = (marketplace, name, path) => `decklight-design-system/${marketplace}/${name}/${path}`;
|
|
146
|
+
|
|
147
|
+
/** JSON safe inside a <script> — the manifest is somebody else's file. */
|
|
148
|
+
const scriptJson = (value) => JSON.stringify(value).replace(/</g, '\\u003c');
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A design system's palette of scales and its brand themes, as the page gets
|
|
152
|
+
* them (SPEC BRAND_PALETTE) — the same tags from every server and from
|
|
153
|
+
* `bundle`: the swatches as tokens, defined from the manifest, and each theme
|
|
154
|
+
* as an added theme (`<style data-theme data-theme-added media="not all">`,
|
|
155
|
+
* the shape a bundle's marked theme has), tagged with the design system it
|
|
156
|
+
* belongs to so the picker can hold a deck to its brand. Nothing for a
|
|
157
|
+
* package without a scale palette.
|
|
158
|
+
*/
|
|
159
|
+
export function brandTags(name, verdict) {
|
|
160
|
+
const brand = verdict.summary?.brand;
|
|
161
|
+
if (!brand) return [];
|
|
162
|
+
const sys = escapeHtml(name);
|
|
163
|
+
const title = escapeHtml(String(verdict.manifest?.title ?? name));
|
|
164
|
+
const lines = brand.palette.map((e) => ` ${e.token}: ${e.hex};`);
|
|
165
|
+
// every role at its value in the brand's first theme, always on (SPEC DESIGN_SYSTEM_ROLES):
|
|
166
|
+
// each theme block sets them again after this, so a role is never undefined
|
|
167
|
+
// while no brand theme is applied — an unlocked deck on another theme, a block gone
|
|
168
|
+
const first = brand.themes[0]?.css ?? '';
|
|
169
|
+
for (const r of brand.roles ?? []) {
|
|
170
|
+
const m = new RegExp(`^\\s*${r.token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}:\\s*([^;\\n]+);`, 'm').exec(first);
|
|
171
|
+
if (m) lines.push(` ${r.token}: ${m[1]};`);
|
|
172
|
+
}
|
|
173
|
+
const safe = (css) => css.replace(/<\/(style)/gi, '<\\/$1');
|
|
174
|
+
return [
|
|
175
|
+
`<style data-design-system-palette="${sys}">\n.decklight {\n${lines.join('\n')}\n}\n</style>`,
|
|
176
|
+
...brand.themes.map((t) => `<style data-theme="${escapeHtml(t.name)}" data-theme-added data-design-system-theme="${sys}" data-theme-source="${title}" media="not all">\n${safe(t.css)}</style>`),
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A deck's design systems, linked into the page on its way out — what every
|
|
182
|
+
* server does after `linkAddedThemes`, never `bundle`. Per reference, after
|
|
183
|
+
* the theme links and before `</head>`:
|
|
184
|
+
* <link rel="stylesheet" href="decklight-design-system/…/design-system.css" data-design-system="<name>">
|
|
185
|
+
* <script type="application/json" data-design-system-meta="<name>">{…}</script>
|
|
186
|
+
* <template data-design-system-templates="<name>">…templates.html…</template>
|
|
187
|
+
* Nothing when the page already carries `<style data-design-system="<name>">`
|
|
188
|
+
* (a bundle's own copy). An unresolvable reference, or a package that no
|
|
189
|
+
* longer passes the check, becomes `<meta name="decklight-design-system-missing">`
|
|
190
|
+
* naming it and why — never a silently short page.
|
|
191
|
+
*/
|
|
192
|
+
export function linkDesignSystems(html, home = configHome(), { log = null } = {}) {
|
|
193
|
+
if (!isDeck(html)) return html;
|
|
194
|
+
const refs = designSystemRefs(html);
|
|
195
|
+
if (!refs.length) return html;
|
|
196
|
+
const sources = markedSources(html);
|
|
197
|
+
const tags = [];
|
|
198
|
+
for (const ref of refs) {
|
|
199
|
+
// a bundle's own copy (<style>), or a link this page already got
|
|
200
|
+
const carried = new RegExp(`<(?:style|link)\\b[^>]*\\bdata-design-system\\s*=\\s*["']${ref.name}["']`, 'i');
|
|
201
|
+
if (carried.test(html)) continue;
|
|
202
|
+
const r = resolveDesignSystemRef(ref, home, { source: sources[ref.marketplace] ?? null });
|
|
203
|
+
const verdict = r.dir ? packageVerdict(r.dir) : null;
|
|
204
|
+
if (r.dir && !verdict.ok) r.missing = verdict.why;
|
|
205
|
+
if (r.dir && verdict.ok) {
|
|
206
|
+
const name = escapeHtml(ref.name);
|
|
207
|
+
tags.push(`<link rel="stylesheet" href="${designSystemHref(r.local, r.name, verdict.manifest.styles)}" data-design-system="${name}">`);
|
|
208
|
+
tags.push(`<script type="application/json" data-design-system-meta="${name}">${scriptJson(designSystemMeta(verdict))}</script>`);
|
|
209
|
+
tags.push(`<template data-design-system-templates="${name}">\n${verdict.templatesHtml.trim()}\n</template>`);
|
|
210
|
+
tags.push(...brandTags(ref.name, verdict));
|
|
211
|
+
} else {
|
|
212
|
+
tags.push(`<meta name="decklight-design-system-missing" content="${escapeHtml(`${ref.ref} — ${r.missing}`)}">`);
|
|
213
|
+
log?.(`design system ${ref.ref}: ${r.missing}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!tags.length) return html;
|
|
217
|
+
const masked = html.replace(/<!--[\s\S]*?-->/g, (m) => ' '.repeat(m.length));
|
|
218
|
+
const headEnd = masked.search(/<\/head>/i);
|
|
219
|
+
const at = headEnd !== -1 ? headEnd : Math.max(0, masked.search(/<body\b/i));
|
|
220
|
+
return `${html.slice(0, at)}${tags.join('\n')}\n${html.slice(at)}`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** A design system's `url()`s — quoted or not — and the address each names. */
|
|
224
|
+
const CSS_URL = /url\(\s*(?:"([^"]*)"|'([^']*)'|([^)"'\s]*))\s*\)/gi;
|
|
225
|
+
|
|
226
|
+
/** Bytes as a `data:` URI: an SVG as percent-encoded UTF-8 (readable, smaller), anything else base64. */
|
|
227
|
+
function dataUri(ext, bytes) {
|
|
228
|
+
if (ext === 'svg') {
|
|
229
|
+
const text = encodeURIComponent(bytes.toString('utf8')).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
230
|
+
return `data:image/svg+xml;charset=utf-8,${text}`;
|
|
231
|
+
}
|
|
232
|
+
return `data:${(DS_MIME[ext] ?? 'application/octet-stream').split(';')[0]};base64,${bytes.toString('base64')}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* A design system's stylesheet with every RELATIVE `url()` inlined as a
|
|
237
|
+
* `data:` URI, resolved against the stylesheet's own location — and nothing
|
|
238
|
+
* else touched, byte for byte, so a font's licence header travels with its
|
|
239
|
+
* face. `data:` and `#fragment` urls are left; an outside one (http(s), `//`)
|
|
240
|
+
* is left and listed, because it will not show offline. A relative url whose
|
|
241
|
+
* file is not in the package throws: half a design system is worse than none.
|
|
242
|
+
* Returns `{ css, assets, bytes, external }`.
|
|
243
|
+
*/
|
|
244
|
+
export function inlineDesignSystemCss(css, dir, stylesPath) {
|
|
245
|
+
const base = dirname(resolve(dir, stylesPath));
|
|
246
|
+
const root = resolve(dir);
|
|
247
|
+
const assets = new Set();
|
|
248
|
+
let bytes = 0;
|
|
249
|
+
const external = [];
|
|
250
|
+
const out = css.replace(CSS_URL, (whole, dq, sq, bare) => {
|
|
251
|
+
const url = (dq ?? sq ?? bare ?? '').trim();
|
|
252
|
+
if (!url || url.startsWith('#') || /^data:/i.test(url)) return whole;
|
|
253
|
+
if (/^([a-z][a-z0-9+.-]*:|\/\/)/i.test(url)) { external.push(url); return whole; }
|
|
254
|
+
const rel = url.replace(/[?#].*$/, '');
|
|
255
|
+
const file = resolve(base, rel);
|
|
256
|
+
let data;
|
|
257
|
+
try {
|
|
258
|
+
if (!file.startsWith(root + sep)) throw new Error('outside');
|
|
259
|
+
data = readFileSync(file);
|
|
260
|
+
} catch {
|
|
261
|
+
throw new MarketplaceError(`${stylesPath} names url(${url}), and the design system has no such file`);
|
|
262
|
+
}
|
|
263
|
+
assets.add(file);
|
|
264
|
+
bytes += data.length;
|
|
265
|
+
return `url("${dataUri(file.split('.').pop().toLowerCase(), data)}")`;
|
|
266
|
+
});
|
|
267
|
+
return { css: out, assets: assets.size, bytes, external: [...new Set(external)] };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* What a bundle carries for one resolved, still-valid design system: the
|
|
272
|
+
* stylesheet INLINE (`<style data-design-system data-design-system-version>`
|
|
273
|
+
* — the block every server's `linkDesignSystems` sees and links no second
|
|
274
|
+
* copy of), then the meta `<script>` and the templates `<template>` exactly as
|
|
275
|
+
* the servers inject them, so the runtime finds them by the same selectors.
|
|
276
|
+
* Returns `{ tags, assets, bytes, external, templates }`.
|
|
277
|
+
*/
|
|
278
|
+
export function bundleDesignSystem(r, verdict) {
|
|
279
|
+
const m = verdict.manifest;
|
|
280
|
+
const inlined = inlineDesignSystemCss(readFileSync(join(r.dir, m.styles), 'utf8'), r.dir, m.styles);
|
|
281
|
+
const name = escapeHtml(r.name);
|
|
282
|
+
const safe = inlined.css.replace(/<\/(style)/gi, '<\\/$1');
|
|
283
|
+
return {
|
|
284
|
+
tags: [
|
|
285
|
+
`<style data-design-system="${name}" data-design-system-version="${escapeHtml(String(m.version ?? ''))}">\n${safe}\n</style>`,
|
|
286
|
+
`<script type="application/json" data-design-system-meta="${name}">${scriptJson(designSystemMeta(verdict))}</script>`,
|
|
287
|
+
`<template data-design-system-templates="${name}">\n${verdict.templatesHtml.trim()}\n</template>`,
|
|
288
|
+
...brandTags(r.name, verdict),
|
|
289
|
+
],
|
|
290
|
+
assets: inlined.assets, bytes: inlined.bytes, external: inlined.external,
|
|
291
|
+
templates: verdict.summary?.templates?.length ?? 0,
|
|
292
|
+
// its own themes (SPEC BRAND_PALETTE): carried in `tags`, never looked up in themes/
|
|
293
|
+
brandThemes: (verdict.summary?.brand?.themes ?? []).map((t) => t.name),
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** The MIME a package file is answered as — fixed by extension, never sniffed. */
|
|
298
|
+
const DS_MIME = {
|
|
299
|
+
svg: 'image/svg+xml', png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp',
|
|
300
|
+
woff2: 'font/woff2', woff: 'font/woff', css: 'text/css; charset=utf-8',
|
|
301
|
+
};
|
|
302
|
+
const NAMESPACE = /(?:^|\/)decklight-design-system\/(.*)$/;
|
|
303
|
+
|
|
304
|
+
/** Is this request path in the design-system namespace at all? */
|
|
305
|
+
export const inDesignSystemNamespace = (rel) => NAMESPACE.test(String(rel ?? '').split('\\').join('/'));
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* `staticFiles`' answer for a file of a referenced package — `{ file, type,
|
|
309
|
+
* headers }`, or null, which the caller answers as a plain 404 whatever the
|
|
310
|
+
* reason (a probe learns nothing). The path must be plain segments ending in
|
|
311
|
+
* an allowlisted asset, or the package's own stylesheet; the package must
|
|
312
|
+
* resolve and still pass its check; and the real path must stay inside the
|
|
313
|
+
* package's real directory, so a symlink cannot reach out.
|
|
314
|
+
*/
|
|
315
|
+
export function designSystemAsset(rel, home = configHome()) {
|
|
316
|
+
const m = NAMESPACE.exec(String(rel ?? '').split('\\').join('/'));
|
|
317
|
+
if (!m) return null;
|
|
318
|
+
const segs = m[1].split('/');
|
|
319
|
+
if (segs.length < 3) return null;
|
|
320
|
+
const [marketplace, name, ...path] = segs;
|
|
321
|
+
if (!NAME_RE.test(marketplace) || !NAME_RE.test(name)) return null;
|
|
322
|
+
const last = path[path.length - 1];
|
|
323
|
+
if (!path.slice(0, -1).every((s) => /^[\w-]+$/.test(s))) return null;
|
|
324
|
+
const ext = /^[\w-]+\.([A-Za-z0-9]+)$/.exec(last)?.[1]?.toLowerCase();
|
|
325
|
+
if (!ext || !(ASSET_EXTENSIONS.includes(ext) || ext === 'css')) return null;
|
|
326
|
+
const r = resolveDesignSystemRef({ name, marketplace, ref: `${name}@${marketplace}` }, home);
|
|
327
|
+
if (!r.dir) return null;
|
|
328
|
+
const verdict = packageVerdict(r.dir);
|
|
329
|
+
if (!verdict.ok) return null;
|
|
330
|
+
const relPath = path.join('/');
|
|
331
|
+
// the one stylesheet is the package's own; any other .css is not served
|
|
332
|
+
if (ext === 'css' && relPath !== verdict.manifest.styles) return null;
|
|
333
|
+
let real, root;
|
|
334
|
+
try { real = realpathSync(join(r.dir, ...path)); root = realpathSync(r.dir); } catch { return null; }
|
|
335
|
+
if (!real.startsWith(root + sep)) return null;
|
|
336
|
+
try { if (!statSync(real).isFile()) return null; } catch { return null; }
|
|
337
|
+
const headers = { 'x-content-type-options': 'nosniff' };
|
|
338
|
+
// an SVG is a document; one served same-origin to the deck must not script
|
|
339
|
+
if (ext === 'svg') headers['content-security-policy'] = "default-src 'none'; style-src 'unsafe-inline'";
|
|
340
|
+
return { file: real, type: DS_MIME[ext], headers };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Reference (`on`) or drop a design system in the deck's configuration
|
|
345
|
+
* block, editing only its keys so the author's formatting survives. The
|
|
346
|
+
* source rides alongside in the shared `themeSources`, once per marketplace,
|
|
347
|
+
* and goes only with the last reference of EITHER kind. Returns `{ html,
|
|
348
|
+
* changed }`, or throws a MarketplaceError a command prints as-is.
|
|
349
|
+
*/
|
|
350
|
+
export function setDesignSystem(html, ref, on, { source = null } = {}) {
|
|
351
|
+
const parsed = parseRef(ref);
|
|
352
|
+
if (!parsed) throw new MarketplaceError(`"${ref}" is not a design-system reference — name@marketplace`);
|
|
353
|
+
const block = configBlock(html);
|
|
354
|
+
if (!block) {
|
|
355
|
+
throw new MarketplaceError('the deck has no configuration block to record its design systems in'
|
|
356
|
+
+ ' — decklight upgrade --link <deck.html> gives it one');
|
|
357
|
+
}
|
|
358
|
+
if (block.error) throw new MarketplaceError(block.error);
|
|
359
|
+
const current = designSystemRefs(html);
|
|
360
|
+
const has = current.some((r) => r.ref === parsed.ref);
|
|
361
|
+
if (on) {
|
|
362
|
+
if (has) return { html, changed: false };
|
|
363
|
+
// a slide names a design system by its name (data-template="acme/…"), so
|
|
364
|
+
// two of the same name from different catalogs would be ambiguous
|
|
365
|
+
const clash = current.find((r) => r.name === parsed.name);
|
|
366
|
+
if (clash) throw new MarketplaceError(`the deck already uses ${clash.ref} — two design systems called "${parsed.name}" cannot both be referenced`);
|
|
367
|
+
} else if (!has) return { html, changed: false };
|
|
368
|
+
const next = on ? [...current.map((r) => r.ref), parsed.ref] : current.map((r) => r.ref).filter((r) => r !== parsed.ref);
|
|
369
|
+
const sources = markedSources(html);
|
|
370
|
+
if (on && source) sources[parsed.marketplace] = source;
|
|
371
|
+
const others = referencedMarketplaces(html, [MARKED_KEY, FONTS_KEY]);
|
|
372
|
+
for (const m of Object.keys(sources)) {
|
|
373
|
+
if (!next.some((r) => r.endsWith(`@${m}`)) && !others.has(m)) delete sources[m];
|
|
374
|
+
}
|
|
375
|
+
let inner = withKey(block.inner, DESIGN_SYSTEMS_KEY, next.length ? next : null);
|
|
376
|
+
inner = withKey(inner, SOURCES_KEY, Object.keys(sources).length ? sources : null);
|
|
377
|
+
return { html: html.slice(0, block.innerStart) + inner + html.slice(block.innerEnd), changed: true };
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Every design system every registered marketplace offers, from the cache —
|
|
382
|
+
* what `design-system list` and the "Design systems…" palette show — and the
|
|
383
|
+
* marketplaces it could not list, named so `marketplace update` can be said:
|
|
384
|
+
* `unfetched`, registered but never fetched (the first-party one, on every
|
|
385
|
+
* install that has not asked — nothing is fetched unasked), and `stale`, a
|
|
386
|
+
* cached catalog that no longer reads. The two are told apart because "could
|
|
387
|
+
* not be read" about a catalog nobody has fetched yet sounds like a fault.
|
|
388
|
+
*/
|
|
389
|
+
export function marketplaceDesignSystems(home = configHome()) {
|
|
390
|
+
const systems = [];
|
|
391
|
+
const stale = [];
|
|
392
|
+
const unfetched = [];
|
|
393
|
+
for (const market of Object.keys(loadRegistry(home).marketplaces ?? {})) {
|
|
394
|
+
const catalog = loadCatalog(market, home);
|
|
395
|
+
if (!catalog) { unfetched.push(market); continue; }
|
|
396
|
+
if (!catalog.ok) { stale.push(market); continue; }
|
|
397
|
+
for (const entry of catalog.manifest.entries ?? []) {
|
|
398
|
+
if (entry.type !== 'design-system') continue;
|
|
399
|
+
const r = resolveDesignSystemRef({ name: entry.name, marketplace: market, ref: `${entry.name}@${market}` }, home);
|
|
400
|
+
systems.push({
|
|
401
|
+
name: entry.name, marketplace: market, qualified: `${entry.name}@${market}`,
|
|
402
|
+
group: catalog.manifest.title?.trim() || market,
|
|
403
|
+
description: entry.description ?? '', version: entry.version ?? null,
|
|
404
|
+
...(r.missing ? { missing: r.missing } : {}),
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return { systems, stale, unfetched };
|
|
409
|
+
}
|