M0: WIT package, MoonBit components, JS host, docs, CI (#1)
CI / test (push) Successful in 19s

This commit was merged in pull request #1.
This commit is contained in:
nandi committed 2026-11-24 23:51:26 +00:00
1 parent e5548fc067
commit 880ecd4102
141 files changed
+9681 -1

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
// Theme files use kebab-case keys and #rrggbb[aa] colours; components see the
// WIT `theme.tokens` record (camelCase in jco).
const camel = (k) => k.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
export function parseColor(s) {
const m = /^#([0-9a-fA-F]{6})([0-9a-fA-F]{2})?$/.exec(s);
if (!m) throw new Error(`invalid colour "${s}" (expected #rrggbb or #rrggbbaa)`);
const n = parseInt(m[1], 16);
return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255, a: m[2] ? parseInt(m[2], 16) : 255 };
}
const PALETTE_KEYS = ['desktop-top', 'desktop-bottom', 'surface', 'surface-hover', 'surface-popup',
'foreground', 'foreground-muted', 'accent', 'accent-foreground', 'border'];
const NUM_KEYS = ['font-size', 'radius', 'spacing', 'panel-height'];
export function tokensFromJson(json) {
const palette = {};
for (const k of PALETTE_KEYS) {
if (!(k in (json.palette ?? {}))) throw new Error(`theme "${json.name}": missing palette.${k}`);
palette[camel(k)] = parseColor(json.palette[k]);
}
const out = { name: json.name, palette };
for (const k of NUM_KEYS) {
if (!Number.isInteger(json[k]) || json[k] < 0) throw new Error(`theme "${json.name}": ${k} must be a non-negative integer`);
out[camel(k)] = json[k];
}
return out;
}