A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(gates): the visual layer's drift is measured, not just its contrast
esengine6b8926a4b4af
diff --git a/tools/baselines/theme-drift.json b/tools/baselines/theme-drift.jsonnew file mode 100644index 000000000..eb7772287--- /dev/null+++ b/tools/baselines/theme-drift.json@@ -0,0 +1,102 @@+{+ "spacing": {+ "agent.css": 179,+ "app.css": 32,+ "chrome.css": 26,+ "content.css": 56,+ "controllers.css": 29,+ "controls.css": 17,+ "dockview-theme.css": 3,+ "events.css": 19,+ "flipbook.css": 29,+ "health.css": 11,+ "history.css": 13,+ "inspector.css": 120,+ "launcher.css": 38,+ "lighting.css": 10,+ "log.css": 7,+ "material.css": 6,+ "menus.css": 89,+ "nodegraph.css": 22,+ "outliner.css": 8,+ "plugins.css": 34,+ "profiler.css": 27,+ "sequencer.css": 20,+ "settings.css": 40,+ "tilemap.css": 30,+ "tileset.css": 60,+ "transport.css": 2,+ "ui-palette.css": 4,+ "viewport.css": 21,+ "world.css": 12+ },+ "colourLiterals": {+ "app.css": 26,+ "chrome.css": 7,+ "content.css": 7,+ "controllers.css": 7,+ "controls.css": 1,+ "events.css": 4,+ "flipbook.css": 3,+ "inspector.css": 40,+ "launcher.css": 3,+ "log.css": 1,+ "menus.css": 2,+ "nodegraph.css": 3,+ "outliner.css": 8,+ "plugins.css": 9,+ "profiler.css": 11,+ "sequencer.css": 2,+ "settings.css": 2,+ "tilemap.css": 1,+ "tileset.css": 13,+ "viewport.css": 15+ },+ "rawFontSize": {+ "app.css": 8,+ "controllers.css": 2,+ "controls.css": 1,+ "events.css": 1,+ "launcher.css": 2,+ "profiler.css": 6,+ "sequencer.css": 4,+ "tileset.css": 1,+ "viewport.css": 1+ },+ "iconScale": {+ "sizes": [+ "8",+ "9",+ "10",+ "11",+ "12",+ "13",+ "14",+ "15",+ "16",+ "17",+ "19",+ "20",+ "22",+ "30"+ ],+ "strokes": [+ "1.2",+ "1.4",+ "1.6",+ "1.7",+ "1.75",+ "1.8",+ "1.85",+ "1.9",+ "2",+ "2.2",+ "2.4",+ "2.5",+ "2.6",+ "3",+ "3.2",+ "3.5"+ ]+ }+}diff --git a/tools/baselines/theme-spacing.json b/tools/baselines/theme-spacing.jsondeleted file mode 100644index 0a64ab27c..000000000--- a/tools/baselines/theme-spacing.json+++ /dev/null@@ -1,31 +0,0 @@-{- "agent.css": 179,- "app.css": 32,- "chrome.css": 26,- "content.css": 56,- "controllers.css": 29,- "controls.css": 17,- "dockview-theme.css": 3,- "events.css": 19,- "flipbook.css": 29,- "health.css": 11,- "history.css": 13,- "inspector.css": 120,- "launcher.css": 38,- "lighting.css": 10,- "log.css": 7,- "material.css": 6,- "menus.css": 89,- "nodegraph.css": 22,- "outliner.css": 8,- "plugins.css": 34,- "profiler.css": 27,- "sequencer.css": 20,- "settings.css": 40,- "tilemap.css": 30,- "tileset.css": 60,- "transport.css": 2,- "ui-palette.css": 4,- "viewport.css": 21,- "world.css": 12-}diff --git a/tools/check-theme.mjs b/tools/check-theme.mjsindex 7b45e2d8f..0650b1132 100644--- a/tools/check-theme.mjs+++ b/tools/check-theme.mjs@@ -9,11 +9,14 @@* panel — under the floor for body text, as the colour of most labels in the* editor — and a chart series ran on a 100%-saturated viewport colour.*- * Three claims. Two are absolute, read off the token file: text stays readable- * on the surfaces it sits on, and a panel label stays quieter than the viewport.- * The third is a RATCHET, because spacing is 1450 declarations deep and a gate- * that reddens on all of them gets switched off: the off-grid ones are banked,- * and the count may fall but never rise.+ * Two claims are absolute, read off the token file: text stays readable on the+ * surfaces it sits on, and a panel label stays quieter than the viewport.+ *+ * Four are RATCHETS, because each is hundreds of declarations deep and a gate+ * that reddens on all of them gets switched off. Banked, may fall, never rise:+ * spacing off the 4px grid; colour literals where a token belongs; raw+ * font-size; and how many distinct icon sizes and stroke widths exist at all —+ * 14 and 16 today, including 1.8 / 1.85 / 1.9, which no one can tell apart.** node tools/check-theme.mjs # check* node tools/check-theme.mjs --update # bank the current state@@ -110,7 +113,7 @@ for (const { name, hex, sat } of content) {* cannot be spent on a regression in another.*/const THEME_DIR = path.join(ROOT, 'desktop', 'src', 'theme');-const BASELINE = path.join(ROOT, 'tools', 'baselines', 'theme-spacing.json');+const BASELINE = path.join(ROOT, 'tools', 'baselines', 'theme-drift.json');const GRID = 4;const offGridByFile = () => {@@ -129,26 +132,114 @@ const offGridByFile = () => {return out;};+/** Colour written where a token belongs. tokens.css is the one place they are+ * DEFINED, so it is the one file exempt. */+const colourLiteralsByFile = () => {+ const out = {};+ for (const f of readdirSync(THEME_DIR).filter((n) => n.endsWith('.css') && n !== 'tokens.css')) {+ const text = readFileSync(path.join(THEME_DIR, f), 'utf8');+ const n = (text.match(/#[0-9a-fA-F]{3,8}\b/g)?.length ?? 0)+ + (text.match(/\brgba?\(/g)?.length ?? 0);+ if (n > 0) out[f] = n;+ }+ return out;+};++/** A font-size given as a number rather than a step of the type scale. */+const rawFontSizeByFile = () => {+ const out = {};+ for (const f of readdirSync(THEME_DIR).filter((n) => n.endsWith('.css') && n !== 'tokens.css')) {+ const n = readFileSync(path.join(THEME_DIR, f), 'utf8').match(/font-size:\s*\d/g)?.length ?? 0;+ if (n > 0) out[f] = n;+ }+ return out;+};++/**+ * How many distinct sizes and stroke widths the icons use.+ *+ * Counted only for names the file itself imported from lucide: `size={44}` on an+ * asset thumbnail and `strokeWidth={12}` on an SVG hit area are not icons, and+ * counting them made the first measurement of this wrong.+ */+const iconScale = () => {+ const sizes = new Set();+ const strokes = new Set();+ const walk = (dir) => {+ for (const e of readdirSync(dir, { withFileTypes: true })) {+ const full = path.join(dir, e.name);+ if (e.isDirectory()) { walk(full); continue; }+ if (!/\.tsx?$/.test(e.name)) continue;+ const text = readFileSync(full, 'utf8');+ const names = new Set();+ for (const m of text.matchAll(/import\s*\{([^}]*)\}\s*from\s*'lucide-react'/g)) {+ for (const raw of m[1].split(',')) {+ const n = raw.trim().replace(/^type\s+/, '').split(/\s+as\s+/).pop().trim();+ if (n && /^[A-Z]/.test(n)) names.add(n);+ }+ }+ if (names.size === 0) continue;+ for (const m of text.matchAll(/<([A-Z][A-Za-z0-9]*)\b([^>]*)>/g)) {+ if (!names.has(m[1])) continue;+ const size = /\bsize=\{(\d+(?:\.\d+)?)\}/.exec(m[2]);+ const stroke = /\bstrokeWidth=\{(\d+(?:\.\d+)?)\}/.exec(m[2]);+ if (size) sizes.add(size[1]);+ if (stroke) strokes.add(stroke[1]);+ }+ }+ };+ walk(path.join(ROOT, 'desktop', 'src'));+ return { sizes: [...sizes].sort((a, b) => a - b), strokes: [...strokes].sort((a, b) => a - b) };+};+const current = offGridByFile();+const colours = colourLiteralsByFile();+const fontSizes = rawFontSizeByFile();+const icons = iconScale();const total = Object.values(current).reduce((a, b) => a + b, 0);+const byName = (o) => Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b)));+if (process.argv.includes('--update')) {mkdirSync(path.dirname(BASELINE), { recursive: true });- const sorted = Object.fromEntries(Object.entries(current).sort(([a], [b]) => a.localeCompare(b)));- writeFileSync(BASELINE, `${JSON.stringify(sorted, null, 2)}\n`);- console.log(`check-theme: banked ${total} off-grid spacing(s) in ${Object.keys(current).length} file(s).`);+ const state = {+ spacing: byName(current),+ colourLiterals: byName(colours),+ rawFontSize: byName(fontSizes),+ iconScale: icons,+ };+ writeFileSync(BASELINE, `${JSON.stringify(state, null, 2)}\n`);+ console.log(`check-theme: banked ${total} off-grid spacing(s), `+ + `${Object.values(colours).reduce((a, b) => a + b, 0)} colour literal(s), `+ + `${Object.values(fontSizes).reduce((a, b) => a + b, 0)} raw font-size(s), `+ + `${icons.sizes.length} icon size(s) and ${icons.strokes.length} stroke width(s).`);process.exit(0);}-let banked = {};+let banked = { spacing: {}, colourLiterals: {}, rawFontSize: {}, iconScale: { sizes: [], strokes: [] } };if (!existsSync(BASELINE)) {- problems.push(`no spacing baseline at ${BASELINE} — run with --update once to create it`);+ problems.push(`no drift baseline at ${BASELINE} — run with --update once to create it`);} else {banked = JSON.parse(readFileSync(BASELINE, 'utf8'));- for (const [file, n] of Object.entries(current)) {- const was = banked[file] ?? 0;- if (n > was) {- problems.push(`desktop/src/theme/${file}: ${n - was} new spacing value(s) off the ${GRID}px grid (${was} banked, ${n} now)`);+ /** Per file, so a fix in one place cannot pay for a regression in another. */+ const ratchet = (now, was, what) => {+ for (const [file, n] of Object.entries(now)) {+ const before = was?.[file] ?? 0;+ if (n > before) {+ problems.push(`desktop/src/theme/${file}: ${n - before} new ${what} (${before} banked, ${n} now)`);+ }+ }+ };+ ratchet(current, banked.spacing, `spacing value(s) off the ${GRID}px grid`);+ ratchet(colours, banked.colourLiterals, 'colour literal(s) where a token belongs');+ ratchet(fontSizes, banked.rawFontSize, 'raw font-size(s) — use a step of the scale');+ // Not per file: a new icon size anywhere is one more size the editor has.+ for (const [kind, now] of [['size', icons.sizes], ['stroke width', icons.strokes]]) {+ const was = new Set(kind === 'size' ? banked.iconScale?.sizes ?? [] : banked.iconScale?.strokes ?? []);+ const added = now.filter((v) => !was.has(v));+ if (added.length > 0) {+ problems.push(`desktop/src/: icon ${kind} ${added.join(', ')} is new — `+ + `${was.size} were already in use, and mixing them is what the ramp exists to stop`);}}}@@ -165,5 +256,8 @@ console.log(`check-theme: ${textTokens.length} text token(s) over ${READING_SURFACES.length} reading surface(s) — `+ `all >= ${FLOOR}:1, closest is ${worst.name} at ${worst.ratio.toFixed(2)}:1 on ${worst.surface}. `+ `${content.length} content label(s) under ${PANEL_CEILING}% saturation, loudest is ${loudest.name} at ${loudest.sat}%. `- + `${total} off-grid spacing(s) banked across ${Object.keys(banked).length} file(s) — the ratchet holds.`,+ + `Ratchets hold: ${total} off-grid spacing(s), `+ + `${Object.values(colours).reduce((a, b) => a + b, 0)} colour literal(s), `+ + `${Object.values(fontSizes).reduce((a, b) => a + b, 0)} raw font-size(s), `+ + `${icons.sizes.length} icon size(s) / ${icons.strokes.length} stroke width(s).`,);diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 33f199532..2ec29784c 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,9 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ "feat(gates): the visual layer's drift is measured, not just its contrast":+ { internal: "A repository gate over the editor's own stylesheets and icons; no creator runs it." },+"feat(runtime): a mini-game reports its boot through the host's indicator":{ note: 'A mini-game says how far along its boot is, not just that it is loading.' },