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
fix(docs): the plugin manual named two CSS variables the editor does not have
esengine7d4317732fe4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5e5f36034..6db8b2c0c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -33,6 +33,12 @@ published separately; it ships inside the editor.and every published entry declares itself side-effectful so a game's own bundler cannotrepeat it with `esengine/physics3d`.+- **A plugin styled from the manual gets the editor's real colours instead of none.** The+ plugin guide told authors to style against `--bg` and `--accent`; the editor has neither,+ so a panel written to the manual got no background and its overlay example drew a black+ circle on a dark viewport. It names the tokens that exist, and a gate refuses the next+ `var()` — in a stylesheet, a plugin or the docs — whose variable nothing defines.+- **The Inspector's effect stack draws its toggle, its rows and its Add button again.**Ten declarations named six CSS variables this editor does not have — `--accent` where thetoken is `--acc`, `--bg-inset` where it is `--inset`, and four more. CSS has nodiff --git a/docs/astro/src/content/docs/extending/editor-plugins.mdx b/docs/astro/src/content/docs/extending/editor-plugins.mdxindex 728006003..1a06b8cf5 100644--- a/docs/astro/src/content/docs/extending/editor-plugins.mdx+++ b/docs/astro/src/content/docs/extending/editor-plugins.mdx@@ -221,9 +221,11 @@ ctx.commands.register({### Panels`mount` gets a plain host element and returns its teardown. The editor owns the-tab, the error boundary and pop-out. Style against the editor's CSS variables-(`--bg`, `--text`, `--text-dim`, `--accent`, …) and the panel matches the-surrounding chrome in both light and dark.+tab, the error boundary and pop-out. Style against the editor's CSS variables —+`--srf-2` for the panel body, `--text` / `--text-dim` for copy, `--acc` for the+accent, `--border` for edges, `--fs-sm` for body size — and the panel matches the+surrounding chrome. Use a variable that exists: CSS has no unknown-variable+error, so a misspelled one simply does not draw.```tsctx.panels.register({@@ -300,7 +302,7 @@ ctx.overlays.register({if (id == null) return;const p = ctx.scene.getFieldValue(id, 'Transform', 'position');if (!Array.isArray(p)) return;- g.circle({ x: p[0], y: p[1] }, 120, { color: 'var(--accent)', dashed: true });+ g.circle({ x: p[0], y: p[1] }, 120, { color: 'var(--acc)', dashed: true });},});```diff --git a/docs/astro/src/content/docs/zh-cn/extending/editor-plugins.mdx b/docs/astro/src/content/docs/zh-cn/extending/editor-plugins.mdxindex 35a290241..b5dea7f0a 100644--- a/docs/astro/src/content/docs/zh-cn/extending/editor-plugins.mdx+++ b/docs/astro/src/content/docs/zh-cn/extending/editor-plugins.mdx@@ -200,8 +200,10 @@ ctx.commands.register({### 面板`mount` 拿到一个普通的宿主元素,返回它的拆卸函数。标签页、错误边界和弹出窗口由-编辑器负责。用编辑器的 CSS 变量(`--bg`、`--text`、`--text-dim`、`--accent` …)-写样式,面板在明暗两种主题下都与周围的界面一致。+编辑器负责。用编辑器的 CSS 变量写样式——面板底色 `--srf-2`、正文 `--text` /+`--text-dim`、强调色 `--acc`、描边 `--border`、正文字号 `--fs-sm`——面板就与周围+的界面一致。**要用真实存在的变量**:CSS 没有「未知变量」这种错误,名字写错的那条+声明不会报错,只是什么都不画。```tsctx.panels.register({@@ -276,7 +278,7 @@ ctx.overlays.register({if (id == null) return;const p = ctx.scene.getFieldValue(id, 'Transform', 'position');if (!Array.isArray(p)) return;- g.circle({ x: p[0], y: p[1] }, 120, { color: 'var(--accent)', dashed: true });+ g.circle({ x: p[0], y: p[1] }, 120, { color: 'var(--acc)', dashed: true });},});```diff --git a/tools/check-css-vars.mjs b/tools/check-css-vars.mjsnew file mode 100644index 000000000..da10ed2d6--- /dev/null+++ b/tools/check-css-vars.mjs@@ -0,0 +1,92 @@+#!/usr/bin/env node+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file Every `var(--x)` names an `--x` that something defines.+ *+ * CSS has no unknown-variable error. A misspelled name resolves to nothing, the+ * property is simply not set, and the pixel that was meant to be filled is not —+ * so a checked toggle loses its fill and a dashed border is never drawn. Ten+ * such declarations were live in the editor, naming six variables from a+ * vocabulary it does not have.+ *+ * Three readers, one rule: the editor's own stylesheets, the plugins that style+ * against them, and the docs that teach them. The docs had it worst — they named+ * `--accent` and `--bg`, neither of which exists, so a plugin written to the+ * manual drew a black circle on a dark viewport.+ *+ * A `var()` WITH a fallback is not counted: it has an answer either way.+ *+ * node tools/check-css-vars.mjs+ */+import { readFileSync, readdirSync, existsSync } from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';++const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');++/** Where a variable may be DEFINED, and where one may be USED. */+const DEFINES = ['desktop/src', 'plugins'];+const USES = [+ { dir: 'desktop/src', ext: /\.(css|tsx?)$/ },+ { dir: 'plugins', ext: /\.(css|tsx?)$/ },+ { dir: 'docs/astro/src/content/docs', ext: /\.mdx?$/ },+];++const SKIP = /^(node_modules|dist|build|\.astro|\.esengine|\.git)$/;++const everyFile = (dir, ext, out = []) => {+ if (!existsSync(dir)) return out;+ for (const e of readdirSync(dir, { withFileTypes: true })) {+ const p = path.join(dir, e.name);+ if (e.isDirectory()) { if (!SKIP.test(e.name)) everyFile(p, ext, out); }+ else if (ext.test(e.name)) out.push(p);+ }+ return out;+};++/** Comments out, offsets kept, so a name is never read out of one. */+const uncomment = (t) => t.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' '));++const defined = new Set();+for (const dir of DEFINES) {+ for (const file of everyFile(path.join(ROOT, dir), /\.(css|tsx?)$/)) {+ const text = uncomment(readFileSync(file, 'utf8'));+ // A declaration is a declaration wherever it sits: reading only line starts+ // called `--ag-tone` dead, which `.ag-ask--confirm { --ag-tone: … }` defines.+ for (const m of text.matchAll(/(?:^|[{;\s])(--[A-Za-z0-9_-]+)\s*:/g)) defined.add(m[1]);+ // A script sets one as a style-object key or through setProperty — which is+ // how TilesetEditor gives each cell its `--tcolor`.+ for (const m of text.matchAll(/[`"'](--[A-Za-z0-9_-]+)[`"']/g)) defined.add(m[1]);+ }+}++if (defined.size === 0) {+ console.error('check-css-vars: no variable definitions found — the stylesheets moved.');+ process.exit(1);+}++const problems = [];+let uses = 0;+for (const { dir, ext } of USES) {+ for (const file of everyFile(path.join(ROOT, dir), ext)) {+ const rel = path.relative(ROOT, file).replaceAll(path.sep, '/');+ const text = uncomment(readFileSync(file, 'utf8'));+ for (const m of text.matchAll(/var\(\s*(--[A-Za-z0-9_-]+)\s*([,)])/g)) {+ uses += 1;+ if (m[2] === ',' || defined.has(m[1])) continue;+ const line = text.slice(0, m.index).split('\n').length;+ problems.push(`${rel}:${line}: ${m[1]} is used and nothing defines it — `+ + 'the declaration resolves to nothing and draws nothing');+ }+ }+}++if (problems.length > 0) {+ for (const p of problems) console.error(` ${p}`);+ console.error(`check-css-vars: ${problems.length} finding(s).`);+ process.exit(1);+}++console.log(`check-css-vars: ${uses} var() over ${defined.size} defined variable(s) — `+ + 'every one names something, across the editor, its plugins and the docs.');diff --git a/tools/check-theme.mjs b/tools/check-theme.mjsindex 6d013312a..a30e376ff 100644--- a/tools/check-theme.mjs+++ b/tools/check-theme.mjs@@ -13,7 +13,8 @@** Three claims are absolute: text stays readable on the surfaces it sits on, a* panel label stays quieter than the viewport, and a token that NAMES a thing- * only colours that thing.+ * only colours that thing. That a token EXISTS at all is check-css-vars.mjs —+ * its subject is every reader of the editor's variables, plugins and docs too.** Six 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:@@ -173,39 +174,6 @@ for (const file of everyFile(SRC_DIR)) {}}-/**- * A `var(--x)` with no `--x` anywhere. CSS says nothing and draws nothing, so a- * filled toggle loses its fill and a dashed border disappears — silently, since- * there is no such thing as an unknown-variable error.- *- * Only a bare `var(--x)`: one with a fallback has an answer either way.- */-const declaredAnywhere = (text) => {- const out = new Set();- // A declaration is a declaration wherever it sits — a single-line rule defines- // too, and reading only line starts reported `--ag-tone` as dead.- for (const m of text.matchAll(/(?:^|[{;\s])(--[A-Za-z0-9_-]+)\s*:/g)) out.add(m[1]);- // A script sets one as a style-object key or through setProperty.- for (const m of text.matchAll(/[`"'](--[A-Za-z0-9_-]+)[`"']/g)) out.add(m[1]);- return out;-};--{- const files = everyFile(SRC_DIR);- const defined = new Set();- for (const f of files) for (const n of declaredAnywhere(uncomment(readFileSync(f, 'utf8')))) defined.add(n);- for (const file of files) {- const rel = path.relative(SRC_DIR, file).replaceAll(path.sep, '/');- const text = uncomment(readFileSync(file, 'utf8'));- for (const m of text.matchAll(/var\(\s*(--[A-Za-z0-9_-]+)\s*([,)])/g)) {- if (m[2] === ',' || defined.has(m[1])) continue;- const line = text.slice(0, m.index).split('\n').length;- problems.push(`desktop/src/${rel}:${line}: ${m[1]} is used and never defined — `- + 'the declaration resolves to nothing and draws nothing');- }- }-}-/*** Spacing that is not on the 4px grid, per file. A count rather than a line, so* inserting a rule does not churn the baseline; per file, so a fix in one placediff --git a/tools/gates.mjs b/tools/gates.mjsindex 426bba76a..4e09efb51 100644--- a/tools/gates.mjs+++ b/tools/gates.mjs@@ -252,6 +252,10 @@ export const GATES = [{ id: 'path-sandbox', run: 'node tools/check-path-sandbox.mjs' },{ id: 'key-codes', run: 'node tools/check-key-codes.mjs' },{ id: 'theme', run: 'node tools/check-theme.mjs', needs: 'editor' },+ // Its own gate rather than part of `theme`: the readers of the editor's+ // variables are the editor, the plugins and the docs, and only the first is+ // check-theme's subject.+ { id: 'css-vars', run: 'node tools/check-css-vars.mjs', needs: 'editor' },{ id: 'comment-style', run: 'node tools/check-comment-style.mjs' },{ id: 'silent-writes', run: 'node tools/mutation-census.mjs --gate' },{diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 9221bf8d5..5e6d86fb1 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 = {+ 'fix(docs): the plugin manual named two CSS variables the editor does not have':+ { note: 'A plugin styled from the manual gets the editor\'s real colours instead of none.' },+'fix(editor): six CSS variables that were never defined, so they drew nothing':{ note: "The Inspector's effect stack draws its toggle, its rows and its Add button again." },