@popcorn245/cornfield 0.25.0 → 0.27.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/core/color.js +177 -0
- package/core/config.js +2 -2
- package/core/contrast.js +600 -0
- package/core/theme.js +88 -5
- package/core/validate.js +9 -3
- package/explorer/explorer.css +15 -11
- package/explorer/labels.js +13 -6
- package/explorer/main.js +4 -1
- package/explorer/map-style.js +428 -0
- package/explorer/proposal.js +4 -1
- package/explorer/renderer-canvas2d.js +26 -5
- package/explorer/renderer-webgl.js +182 -38
- package/explorer/scene.js +13 -2
- package/explorer/shaders.js +27 -0
- package/explorer/theme-model.js +6 -23
- package/explorer/theme.js +4 -1
- package/explorer/tokens.css +85 -9
- package/package.json +1 -1
- package/server/server.js +1 -1
package/core/theme.js
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
* fontHosts: [], // the hosts of the font FILES, when a fonts host is not a known pair
|
|
12
12
|
* names: { day: './tools/cornfield/day.css' }, // named themes: data-theme-name on <html>, a picker in the header
|
|
13
13
|
* default: 'day', // the name used until a viewer picks one
|
|
14
|
+
* icons: { app: './tools/cornfield/icons/app.svg' }, // an icon per node kind, drawn inside the node on the map (svg or png)
|
|
15
|
+
* pixelated: true, // small icons are drawn crisp (nearest-neighbour), not smoothed
|
|
16
|
+
* contrast: 'error', // 'warn' turns a failing contrast pair in `validate` into a warning
|
|
14
17
|
* }
|
|
15
18
|
*
|
|
16
19
|
* A theme is CSS only: never script, never inlined into the page.
|
|
@@ -18,8 +21,13 @@
|
|
|
18
21
|
|
|
19
22
|
import fs from 'node:fs';
|
|
20
23
|
import path from 'node:path';
|
|
24
|
+
import { NODE_THEMES } from './schema.js';
|
|
21
25
|
|
|
22
|
-
export const THEME_KEYS = Object.freeze(['css', 'fonts', 'fontHosts', 'names', 'default']);
|
|
26
|
+
export const THEME_KEYS = Object.freeze(['css', 'fonts', 'fontHosts', 'names', 'default', 'icons', 'pixelated', 'contrast']);
|
|
27
|
+
/** The node kinds an icon may be set for: every node type of the map */
|
|
28
|
+
export const ICON_KINDS = Object.freeze(Object.keys(NODE_THEMES));
|
|
29
|
+
/** The file types of a node icon */
|
|
30
|
+
export const ICON_EXTENSIONS = Object.freeze(['.svg', '.png']);
|
|
23
31
|
/** The largest a theme file may be, in bytes */
|
|
24
32
|
export const MAX_THEME_BYTES = 256 * 1024;
|
|
25
33
|
export const MAX_THEME_NAMES = 12;
|
|
@@ -59,7 +67,7 @@ export function fontUrl(v) {
|
|
|
59
67
|
*/
|
|
60
68
|
export function themeProblems(t) {
|
|
61
69
|
if (t === undefined) return [];
|
|
62
|
-
if (!isObject(t)) return ['"theme" is { css?, fonts?, fontHosts?, names?, default? }.'];
|
|
70
|
+
if (!isObject(t)) return ['"theme" is { css?, fonts?, fontHosts?, names?, default?, icons?, pixelated?, contrast? }.'];
|
|
63
71
|
const out = [];
|
|
64
72
|
for (const k of Object.keys(t)) if (!THEME_KEYS.includes(k)) out.push(`theme.${k}: the keys are ${THEME_KEYS.join(', ')}.`);
|
|
65
73
|
if (t.css !== undefined && t.css !== null && !cssPathInRepo(t.css)) out.push('theme.css is one stylesheet (a .css file) inside the repo, written relative to it, like "./tools/cornfield/theme.css".');
|
|
@@ -94,10 +102,53 @@ export function themeProblems(t) {
|
|
|
94
102
|
}
|
|
95
103
|
}
|
|
96
104
|
}
|
|
105
|
+
if (t.contrast !== undefined && t.contrast !== 'error' && t.contrast !== 'warn') out.push('theme.contrast is "error" (a pair below WCAG AA fails validate; the default) or "warn" (it is a warning).');
|
|
97
106
|
if (t.default !== undefined && t.default !== null) {
|
|
98
107
|
if (!isText(t.default)) out.push('theme.default is the name of one of theme.names.');
|
|
99
108
|
else if (!names.includes(t.default)) out.push(`theme.default "${t.default}" is not one of theme.names (${names.join(', ') || 'none are listed'}).`);
|
|
100
109
|
}
|
|
110
|
+
if (t.pixelated !== undefined && typeof t.pixelated !== 'boolean') out.push('theme.pixelated is true or false.');
|
|
111
|
+
if (t.icons !== undefined) {
|
|
112
|
+
if (!isObject(t.icons)) out.push('theme.icons is { "<node kind>": "./path.svg" }.');
|
|
113
|
+
else {
|
|
114
|
+
for (const [kind, rel] of Object.entries(t.icons)) {
|
|
115
|
+
if (!ICON_KINDS.includes(kind)) out.push(`theme.icons "${kind}": not a node kind (${ICON_KINDS.join(', ')}).`);
|
|
116
|
+
const found = themeIconAsset(t, rel);
|
|
117
|
+
if ('problem' in found) out.push(`theme.icons.${kind} ${found.problem}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Where a node icon of the config is served, by its repo path: `{ asset }` (the path after THEME_ASSET_PREFIX) or `{ problem }`.
|
|
126
|
+
* An icon is an .svg or .png file inside the repo, and inside the theme folder (themeAssetDir): it is served by the route that serves the
|
|
127
|
+
* images beside a theme, nothing else. No disk is read here (core/validate.js checks the file).
|
|
128
|
+
* @param {object} theme
|
|
129
|
+
* @param {unknown} rel the icon's path as the config wrote it
|
|
130
|
+
* @returns {{ asset: string } | { problem: string }}
|
|
131
|
+
*/
|
|
132
|
+
export function themeIconAsset(theme, rel) {
|
|
133
|
+
if (!isText(rel) || path.isAbsolute(rel) || /^[a-z]:/i.test(rel) || rel.includes('\0') || rel.includes('\\') || rel.split('/').includes('..')) return { problem: 'is an .svg or .png file inside the repo, written relative to it, like "./tools/cornfield/icons/app.svg".' };
|
|
134
|
+
if (!ICON_EXTENSIONS.includes(path.posix.extname(rel).toLowerCase())) return { problem: `(${rel}) is not an .svg or .png file.` };
|
|
135
|
+
const dir = themeAssetDir(theme);
|
|
136
|
+
if (!dir) return { problem: `(${rel}) cannot be served: icons are served beside the theme files, so the theme needs a stylesheet (theme.css or theme.names) in a folder, not at the top of the repo.` };
|
|
137
|
+
const norm = path.posix.normalize(rel);
|
|
138
|
+
if (!norm.startsWith(`${dir}/`)) return { problem: `(${rel}) is outside the theme folder ${dir}, the only folder whose images are served; put the icon under it.` };
|
|
139
|
+
const asset = themeAssetPath(norm.slice(dir.length + 1));
|
|
140
|
+
return asset ? { asset } : { problem: `(${rel}) has a name that cannot be served (letters, digits, ".", "_" and "-" only, no segment starting with a dot).` };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The icons the browser is told: `{ kind: '/cornfield/theme/assets/<path>' }`, those the config names validly */
|
|
144
|
+
export function iconUrls(theme) {
|
|
145
|
+
const out = {};
|
|
146
|
+
if (!theme || !isObject(theme.icons)) return out;
|
|
147
|
+
for (const [kind, rel] of Object.entries(theme.icons)) {
|
|
148
|
+
if (!ICON_KINDS.includes(kind)) continue;
|
|
149
|
+
const found = themeIconAsset(theme, rel);
|
|
150
|
+
if (!('problem' in found)) out[kind] = THEME_ASSET_PREFIX + found.asset;
|
|
151
|
+
}
|
|
101
152
|
return out;
|
|
102
153
|
}
|
|
103
154
|
|
|
@@ -146,7 +197,7 @@ const FORBIDDEN = [
|
|
|
146
197
|
* @param {string} text
|
|
147
198
|
* @param {string} gap
|
|
148
199
|
*/
|
|
149
|
-
function withoutComments(text, gap) {
|
|
200
|
+
export function withoutComments(text, gap) {
|
|
150
201
|
let out = '';
|
|
151
202
|
let quote = null;
|
|
152
203
|
for (let i = 0; i < text.length; i++) {
|
|
@@ -301,11 +352,14 @@ export function themeUrlTarget(ref, servedAt) {
|
|
|
301
352
|
return asset ? { asset } : { problem: why };
|
|
302
353
|
}
|
|
303
354
|
|
|
304
|
-
/** The theme as the browser is told it: names and the default, never a path on this machine */
|
|
355
|
+
/** The theme as the browser is told it: names and the default, the icons' served paths and the pixelated flag, never a path on this machine */
|
|
305
356
|
export function clientTheme(theme) {
|
|
306
357
|
if (!theme) return null;
|
|
307
358
|
const names = Object.keys(theme.names || {});
|
|
308
|
-
|
|
359
|
+
const icons = iconUrls(theme);
|
|
360
|
+
const pixelated = theme.pixelated === true;
|
|
361
|
+
if (!names.length && !Object.keys(icons).length && !pixelated) return null;
|
|
362
|
+
return { names, default: names.length ? theme.default || null : null, ...(Object.keys(icons).length ? { icons } : {}), ...(pixelated ? { pixelated } : {}) };
|
|
309
363
|
}
|
|
310
364
|
|
|
311
365
|
/**
|
|
@@ -335,3 +389,32 @@ export function themeAssetFile(root, theme, rel) {
|
|
|
335
389
|
if (stats.size > MAX_THEME_ASSET_BYTES) return { problem: `${dir}/${rel} is ${Math.ceil(stats.size / 1024)} KB; an asset beside a theme is at most ${MAX_THEME_ASSET_BYTES / 1024 / 1024} MB.` };
|
|
336
390
|
return { file: real, size: stats.size, type };
|
|
337
391
|
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* What is wrong with the icon files of the config (`theme.icons`): each one exists as a plain file under the theme folder (a link out of it is
|
|
395
|
+
* refused), is at most MAX_THEME_ASSET_BYTES, and is what its extension says (an .svg is text with an <svg> element and no script, a .png starts
|
|
396
|
+
* with the PNG signature). The server serves an icon only if themeAssetFile finds it, so this is the same rule.
|
|
397
|
+
* @param {{ root: string, theme?: object }} config
|
|
398
|
+
* @returns {string[]}
|
|
399
|
+
*/
|
|
400
|
+
export function themeIconFileProblems(config) {
|
|
401
|
+
const out = [];
|
|
402
|
+
const icons = config.theme && isObject(config.theme.icons) ? config.theme.icons : {};
|
|
403
|
+
for (const [kind, rel] of Object.entries(icons)) {
|
|
404
|
+
const where = `theme.icons.${kind} (${rel})`;
|
|
405
|
+
const target = themeIconAsset(config.theme, rel);
|
|
406
|
+
if ('problem' in target) { out.push(`${where} ${target.problem}`); continue; }
|
|
407
|
+
const found = themeAssetFile(config.root, config.theme, target.asset);
|
|
408
|
+
if ('problem' in found) { out.push(`${where} ${found.problem}`); continue; }
|
|
409
|
+
let head;
|
|
410
|
+
try { head = fs.readFileSync(found.file); } catch { out.push(`${where} cannot be read.`); continue; }
|
|
411
|
+
if (path.posix.extname(target.asset).toLowerCase() === '.png') {
|
|
412
|
+
if (!head.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))) out.push(`${where} is not a PNG image.`);
|
|
413
|
+
} else {
|
|
414
|
+
const text = head.toString('utf8');
|
|
415
|
+
if (!/<svg[\s>]/i.test(text)) out.push(`${where} is not an SVG image (no <svg> element).`);
|
|
416
|
+
else if (/<\s*script\b|\son[a-z]+\s*=|javascript\s*:/i.test(text)) out.push(`${where} holds script, which an icon may not (an icon is an image only).`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return out;
|
|
420
|
+
}
|
package/core/validate.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - `validateRepo(...)`: everything, against the repo. The schema, the paths the map cites, drift from
|
|
9
9
|
* the code (every deriver run again, `planSync` must change nothing), what the derivers themselves
|
|
10
10
|
* report, the personas file, the cloud file against the map's cloud nodes, every proposal file, and
|
|
11
|
-
* each deriver's own `validate
|
|
11
|
+
* each deriver's own `validate`, and the theme's contrast (core/contrast.js: WCAG AA on the `--corn-*` pairs, light and dark).
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import fs from 'node:fs';
|
|
@@ -23,8 +23,9 @@ import { CLOUD_FILE, cloudNodeProblems } from './cloud.js';
|
|
|
23
23
|
import { deriveTopology } from './derive.js';
|
|
24
24
|
import { missingPaths, planSync } from './sync.js';
|
|
25
25
|
import { repoPaths, repoReader } from './repo.js';
|
|
26
|
+
import { checkThemeContrast } from './contrast.js';
|
|
26
27
|
import { BRAND_IMAGE_KEYS, brandAssetFile } from './brand.js';
|
|
27
|
-
import { MAX_THEME_BYTES, cssProblems, cssUrls, themeAssetFile, themeFileUrl, themeFiles, themeUrlTarget } from './theme.js';
|
|
28
|
+
import { MAX_THEME_BYTES, cssProblems, cssUrls, themeAssetFile, themeFileUrl, themeFiles, themeIconFileProblems, themeUrlTarget } from './theme.js';
|
|
28
29
|
|
|
29
30
|
/** How a page is produced today, and whether it is baked to a file */
|
|
30
31
|
export const RENDER_NOW = ['build', 'request', 'build+request', 'rom'];
|
|
@@ -35,7 +36,8 @@ const ONLY_REMOVES_HINT = '(A proposal that adds nothing cannot show it has been
|
|
|
35
36
|
/**
|
|
36
37
|
* The config's theme files (docs/config.md#theme): each one exists, is a plain file inside the repo (a link out of it is refused),
|
|
37
38
|
* is at most MAX_THEME_BYTES, is CSS that keeps out of script (core/theme.js `cssProblems`), and every url() in it is a data: image
|
|
38
|
-
* or an image or font the server serves beside the theme (core/theme.js `themeUrlTarget`, `themeAssetFile`)
|
|
39
|
+
* or an image or font the server serves beside the theme (core/theme.js `themeUrlTarget`, `themeAssetFile`), and every node icon
|
|
40
|
+
* (`theme.icons`) is an .svg or .png file there (`themeIconFileProblems`).
|
|
39
41
|
* @param {{ root: string, theme?: object }} config
|
|
40
42
|
* @returns {string[]}
|
|
41
43
|
*/
|
|
@@ -64,6 +66,7 @@ export function validateThemeFiles(config) {
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
}
|
|
69
|
+
errors.push(...themeIconFileProblems(config)); // theme.icons: each file is there, served, and an image
|
|
67
70
|
return errors;
|
|
68
71
|
}
|
|
69
72
|
|
|
@@ -276,6 +279,9 @@ export async function validateRepo({ config, derivers, topology = readTopology(c
|
|
|
276
279
|
errors.push(...validatePersonasFile(config.root, config.personas.roles));
|
|
277
280
|
errors.push(...validateThemeFiles(config));
|
|
278
281
|
errors.push(...validateBrandFiles(config));
|
|
282
|
+
const contrast = checkThemeContrast(config);
|
|
283
|
+
errors.push(...contrast.errors);
|
|
284
|
+
warnings.push(...contrast.warnings);
|
|
279
285
|
errors.push(...validateCloudNodes(topology, config.root));
|
|
280
286
|
errors.push(...validateProposalFiles(topology, path.join(config.root, config.proposals), config.root));
|
|
281
287
|
const io = repoReader(config.root);
|
package/explorer/explorer.css
CHANGED
|
@@ -119,7 +119,8 @@ h1, h2, h3, p { margin: 0; }
|
|
|
119
119
|
.hx-btn:hover { background: var(--corn-surface-3); color: var(--corn-text); }
|
|
120
120
|
.hx-btn:focus-visible, .hx-toggle-row:focus-visible, .hx-zoom-btn:focus-visible, .hx-textbtn:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: 2px; }
|
|
121
121
|
.hx-btn--active, .hx-btn--active:hover { background: var(--corn-accent); border-color: var(--corn-accent-text); color: var(--corn-text-on-accent); box-shadow: var(--corn-shadow-sm); }
|
|
122
|
-
.hx-btn--dim {
|
|
122
|
+
.hx-btn--dim { color: var(--corn-text-3); border-color: var(--corn-line-soft); } /* dimmed by its colours, not by opacity: opacity would take the text below AA */
|
|
123
|
+
.hx-btn--dim:hover { color: var(--corn-text-2); }
|
|
123
124
|
.hx-btn--quiet { font-weight: 500; color: var(--corn-text-3); }
|
|
124
125
|
.hx-btn--icon { width: 28px; height: 28px; padding: 0; justify-content: center; font-size: var(--corn-text-base); }
|
|
125
126
|
.hx-btn--preset { border-color: color-mix(in srgb, var(--corn-hue-orange) 35%, transparent); color: var(--corn-hue-orange); }
|
|
@@ -146,7 +147,7 @@ h1, h2, h3, p { margin: 0; }
|
|
|
146
147
|
transition: width 0.2s, border-color 0.2s;
|
|
147
148
|
user-select: text;
|
|
148
149
|
}
|
|
149
|
-
.hx-input:focus { width: 208px; border-color: var(--corn-
|
|
150
|
+
.hx-input:focus { width: 208px; border-color: var(--corn-focus); }
|
|
150
151
|
.hx-input::placeholder { color: var(--corn-text-3); }
|
|
151
152
|
.hx-input--wide, .hx-input--wide:focus { width: 100%; flex: 1; }
|
|
152
153
|
|
|
@@ -193,7 +194,7 @@ h1, h2, h3, p { margin: 0; }
|
|
|
193
194
|
.hx-menu-head { padding-bottom: var(--corn-space-2); border-bottom: var(--corn-border) solid var(--corn-line); margin-bottom: var(--corn-space-3); }
|
|
194
195
|
.hx-menu-links { display: flex; align-items: center; gap: var(--corn-space-3); text-transform: none; letter-spacing: 0; }
|
|
195
196
|
.hx-menu-section { padding-top: var(--corn-space-3); margin-top: var(--corn-space-3); border-top: var(--corn-border) solid var(--corn-line); }
|
|
196
|
-
.hx-note { padding: var(--corn-space-2) var(--corn-space-3); margin-bottom: var(--corn-space-3); border-radius: var(--corn-radius-sm); background:
|
|
197
|
+
.hx-note { padding: var(--corn-space-2) var(--corn-space-3); margin-bottom: var(--corn-space-3); border-radius: var(--corn-radius-sm); background: var(--corn-hue-orange-soft); color: var(--corn-hue-orange-text); font-size: var(--corn-text-xs); line-height: 1.4; }
|
|
197
198
|
.hx-textbtn { padding: calc(var(--corn-space-1) / 2) var(--corn-space-1); border: 0; border-radius: var(--corn-radius-xs); background: none; color: var(--corn-text-3); font-size: var(--corn-text-2xs); font-weight: 600; }
|
|
198
199
|
.hx-textbtn:hover { background: var(--corn-line-soft); color: var(--corn-text-2); }
|
|
199
200
|
.hx-textbtn--accent { color: var(--corn-accent-text); }
|
|
@@ -201,7 +202,7 @@ h1, h2, h3, p { margin: 0; }
|
|
|
201
202
|
.hx-toggles { display: flex; flex-direction: column; gap: var(--corn-space-1); }
|
|
202
203
|
.hx-toggle-row { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-2); color: var(--corn-text); text-align: left; transition: background 0.15s; }
|
|
203
204
|
.hx-toggle-row:hover { background: var(--corn-surface-3); }
|
|
204
|
-
.hx-toggle-row.is-off { background: color-mix(in srgb, var(--corn-ground) 40%, transparent); border-color: transparent; color: var(--corn-text-3);
|
|
205
|
+
.hx-toggle-row.is-off { background: color-mix(in srgb, var(--corn-ground) 40%, transparent); border-color: transparent; color: var(--corn-text-3); } /* off: dimmed by the fill, the text-3 colour and the dot, never by opacity on text */
|
|
205
206
|
.hx-toggle-label, .hx-toggle-meta { display: flex; align-items: center; gap: var(--corn-space-3); }
|
|
206
207
|
.hx-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; transition: transform 0.15s; }
|
|
207
208
|
.hx-toggle-row.is-off .hx-dot { transform: scale(0.75); opacity: 0.4; }
|
|
@@ -327,7 +328,7 @@ h1, h2, h3, p { margin: 0; }
|
|
|
327
328
|
.hx-proposal-item { display: flex; flex-direction: column; align-items: flex-start; gap: var(--corn-space-1); width: 100%; padding: var(--corn-space-3) var(--corn-space-3); border-radius: var(--corn-radius); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-2); color: var(--corn-text); text-align: left; font-size: var(--corn-text-xs); }
|
|
328
329
|
button.hx-proposal-item:hover { background: var(--corn-surface-3); }
|
|
329
330
|
button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: 2px; }
|
|
330
|
-
.hx-proposal-item.is-current { border-color: var(--corn-added); background: color-mix(in srgb, var(--corn-added) 12%, transparent); }
|
|
331
|
+
.hx-proposal-item.is-current { border-color: var(--corn-added-text); background: color-mix(in srgb, var(--corn-added) 12%, transparent); }
|
|
331
332
|
.hx-proposal-item.is-broken { opacity: 0.8; cursor: default; }
|
|
332
333
|
.hx-proposal-title { font-size: var(--corn-text-sm); font-weight: 600; color: var(--corn-text); overflow-wrap: anywhere; }
|
|
333
334
|
.hx-proposal-sum { color: var(--corn-text-2); line-height: 1.4; }
|
|
@@ -430,7 +431,7 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
|
|
|
430
431
|
.hx-whatif-field { display: flex; align-items: center; gap: var(--corn-space-3); color: var(--corn-text-2); }
|
|
431
432
|
.hx-whatif-field > select, .hx-whatif-field > .hx-whatif-input { flex: 1; min-width: 0; }
|
|
432
433
|
.hx-whatif-input, .hx-whatif-field select, .hx-whatif select { padding: var(--corn-space-1) var(--corn-space-3); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: color-mix(in srgb, var(--corn-ground) 80%, transparent); color: var(--corn-text); font: inherit; font-size: var(--corn-text-sm); user-select: text; }
|
|
433
|
-
.hx-whatif-input:focus, .hx-whatif-field select:focus { outline: var(--corn-focus-width) solid var(--corn-edit); outline-offset: 1px; }
|
|
434
|
+
.hx-whatif-input:focus, .hx-whatif-field select:focus { outline: var(--corn-focus-width) solid var(--corn-edit-text); outline-offset: 1px; }
|
|
434
435
|
.hx-whatif-help { margin: 0; font-size: var(--corn-text-xs); }
|
|
435
436
|
.hx-whatif-pair { margin: 0; }
|
|
436
437
|
.hx-whatif-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-2); }
|
|
@@ -459,7 +460,7 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
|
|
|
459
460
|
.hx-review[hidden] { display: none; }
|
|
460
461
|
.hx-review-label { color: var(--corn-text-3); font-size: var(--corn-text-xs); }
|
|
461
462
|
.hx-review-note { width: 100%; min-height: 44px; resize: vertical; padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: color-mix(in srgb, var(--corn-ground) 80%, transparent); color: var(--corn-text); font: inherit; font-size: var(--corn-text-sm); line-height: 1.4; user-select: text; }
|
|
462
|
-
.hx-review-note:focus { outline: var(--corn-focus-width) solid var(--corn-added); outline-offset: 1px; }
|
|
463
|
+
.hx-review-note:focus { outline: var(--corn-focus-width) solid var(--corn-added-text); outline-offset: 1px; }
|
|
463
464
|
.hx-review-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-2) var(--corn-space-3); }
|
|
464
465
|
.hx-review .hx-btn:disabled { opacity: 0.4; cursor: default; }
|
|
465
466
|
.hx-btn--approve { border-color: color-mix(in srgb, var(--corn-added) 50%, transparent); color: var(--corn-added-text); }
|
|
@@ -558,7 +559,7 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
|
|
|
558
559
|
.hx-live-token-label { display: block; margin-bottom: var(--corn-space-1); color: var(--corn-text); font-size: var(--corn-text-sm); font-weight: 600; }
|
|
559
560
|
.hx-live-token-row { display: flex; gap: var(--corn-space-2); align-items: center; margin-bottom: var(--corn-space-2); }
|
|
560
561
|
.hx-live-token-input { flex: 1; min-width: 0; padding: var(--corn-space-2) var(--corn-space-3); font-size: var(--corn-text-sm); }
|
|
561
|
-
.hx-live-token-input:focus { outline: none; border-color: var(--corn-
|
|
562
|
+
.hx-live-token-input:focus { outline: none; border-color: var(--corn-focus); }
|
|
562
563
|
.hx-live-help code { font-family: var(--corn-mono); font-size: var(--corn-text-2xs); color: var(--corn-text-2); overflow-wrap: anywhere; }
|
|
563
564
|
.hx-live-second { font-size: var(--corn-text-xs); }
|
|
564
565
|
.hx-live-buttons { display: inline-flex; gap: var(--corn-space-2); }
|
|
@@ -803,10 +804,10 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
|
|
|
803
804
|
.hx-run-overlay.is-static .hx-run-ring { animation: none; transform: none; opacity: 1; border-width: calc(var(--corn-border-strong) + var(--corn-border)); }
|
|
804
805
|
@media (prefers-reduced-motion: reduce) { .hx-run-ring { animation: none !important; transform: none; opacity: 1; border-width: calc(var(--corn-border-strong) + var(--corn-border)); } }
|
|
805
806
|
/* Collision: dashed, a sign and words; the same ring whether or not colour is seen */
|
|
806
|
-
.hx-run-mark--collision .hx-run-ring { border: calc(var(--corn-border-strong) + var(--corn-border)) dashed var(--corn-
|
|
807
|
-
.hx-run-tag { position: absolute; left: 0; top: calc(var(--r) + 4px); transform: translateX(-50%); white-space: nowrap; padding: calc(var(--corn-space-1) / 2) var(--corn-space-2); border-radius: var(--corn-radius-pill); border: var(--corn-border) solid var(--corn-
|
|
807
|
+
.hx-run-mark--collision .hx-run-ring { border: calc(var(--corn-border-strong) + var(--corn-border)) dashed var(--corn-map-collision); animation: none; }
|
|
808
|
+
.hx-run-tag { position: absolute; left: 0; top: calc(var(--r) + 4px); transform: translateX(-50%); white-space: nowrap; padding: calc(var(--corn-space-1) / 2) var(--corn-space-2); border-radius: var(--corn-radius-pill); border: var(--corn-border) solid var(--corn-map-collision); background: color-mix(in srgb, var(--corn-ground) 80%, transparent); color: var(--corn-map-collision); font-size: var(--corn-text-xs); font-weight: 700; }
|
|
808
809
|
.hx-run-swatch { display: inline-block; width: 14px; height: 14px; flex: none; box-sizing: border-box; border-radius: 50%; border: var(--corn-border-strong) solid var(--corn-added); }
|
|
809
|
-
.hx-run-swatch--collision { border: var(--corn-border-strong) dashed var(--corn-
|
|
810
|
+
.hx-run-swatch--collision { border: var(--corn-border-strong) dashed var(--corn-map-collision); }
|
|
810
811
|
|
|
811
812
|
/* The Runs view (forge-panel.js, runs-view.js): each run, its limits beside what was reported, its timeline; the compare puts profiles side by side */
|
|
812
813
|
.hx-runs-list { display: flex; flex-direction: column; gap: var(--corn-space-3); margin: 0; padding: 0; list-style: none; }
|
|
@@ -834,3 +835,6 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
|
|
|
834
835
|
.hx-stage:has(.hx-forge .hx-run-compare):has(.drawer-open) { --hx-forge-w: min(400px, calc(100% - 24px)); }
|
|
835
836
|
.hx-stage:has(.drawer-open) .hx-run-columns { grid-template-columns: 1fr; }
|
|
836
837
|
}
|
|
838
|
+
|
|
839
|
+
/* theme.pixelated (docs/config.md#theme): small pixel-art images are sampled without smoothing, in the page as on the map (map-style.js) */
|
|
840
|
+
:root[data-pixelated] img { image-rendering: pixelated; }
|
package/explorer/labels.js
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
import { EDGE_LABEL_SIZE, FONT_EDGE, FONT_NODE, labelAt, looksFor } from './scene.js';
|
|
39
|
+
import { getMapStyle, styledScene } from './map-style.js';
|
|
39
40
|
|
|
40
41
|
/** At most this many node labels at a time (lane text and selection edge labels are extra) */
|
|
41
42
|
export const MAX_LABELS = 400;
|
|
@@ -68,7 +69,7 @@ const TIER_REST = 3;
|
|
|
68
69
|
export function chooseLabels(scene, camera, viewport, opts = {}) {
|
|
69
70
|
const { max = MAX_LABELS, margin = CULL_MARGIN, measure = null } = opts;
|
|
70
71
|
const out = [];
|
|
71
|
-
const outline = looksFor(scene.theme).labelOutline; // the ground's own colour, under the text
|
|
72
|
+
const outline = scene.labelOutline || looksFor(scene.theme).labelOutline; // the ground's own colour (or the theme's --corn-map-label-halo), under the text
|
|
72
73
|
|
|
73
74
|
// Always there: the data-flow lanes' titles, notes and arrows ...
|
|
74
75
|
for (const lane of scene.decor.lanes) {
|
|
@@ -168,13 +169,16 @@ function coverWithNodes(ctx, nodes) {
|
|
|
168
169
|
/**
|
|
169
170
|
* A transparent 2D canvas that draws the chosen labels over the map
|
|
170
171
|
* @param {HTMLCanvasElement} canvas
|
|
172
|
+
* @param {{mapStyle?: () => import('./map-style.js').MapStyle}} [opts] `mapStyle`: where the theme's map tokens come from (default: the page's, map-style.js `getMapStyle`);
|
|
173
|
+
* a node's label colour is the theme's `--corn-map-label`, and the outline under every label its `--corn-map-label-halo`, when it sets them
|
|
171
174
|
* @returns {{draw: (scene: import('./scene.js').Scene, camera: import('./scene.js').Camera) => boolean, resize: (width: number, height: number, dpr: number) => void, destroy: () => void}}
|
|
172
175
|
* `draw` returns whether it painted: false when the camera, the scene and the size were unchanged
|
|
173
176
|
*/
|
|
174
|
-
export function createLabelLayer(canvas) {
|
|
177
|
+
export function createLabelLayer(canvas, opts = {}) {
|
|
178
|
+
const styleOf = opts.mapStyle || getMapStyle;
|
|
175
179
|
const ctx = canvas.getContext('2d');
|
|
176
180
|
let width = 0, height = 0, dpr = 1;
|
|
177
|
-
let lastScene = null, lastVersion, lastX, lastY, lastZoom;
|
|
181
|
+
let lastScene = null, lastVersion, lastX, lastY, lastZoom, lastStyle;
|
|
178
182
|
let dirty = true;
|
|
179
183
|
let destroyed = false;
|
|
180
184
|
|
|
@@ -202,11 +206,14 @@ export function createLabelLayer(canvas) {
|
|
|
202
206
|
dirty = true;
|
|
203
207
|
},
|
|
204
208
|
|
|
205
|
-
draw(
|
|
209
|
+
draw(drawn, camera) {
|
|
206
210
|
if (destroyed) return false;
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
const style = styleOf();
|
|
212
|
+
const styleKey = style.plain ? 0 : style.version;
|
|
213
|
+
if (!dirty && drawn === lastScene && drawn.version === lastVersion && camera.x === lastX && camera.y === lastY && camera.zoom === lastZoom && styleKey === lastStyle) return false;
|
|
214
|
+
lastScene = drawn; lastVersion = drawn.version; lastX = camera.x; lastY = camera.y; lastZoom = camera.zoom; lastStyle = styleKey;
|
|
209
215
|
dirty = false;
|
|
216
|
+
const scene = styledScene(drawn, style); // the label colours of the theme (map-style.js)
|
|
210
217
|
|
|
211
218
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
212
219
|
ctx.clearRect(0, 0, width, height);
|
package/explorer/main.js
CHANGED
|
@@ -47,6 +47,7 @@ import { initForgePanel } from './forge-panel.js';
|
|
|
47
47
|
import { initReviewTokens } from './review-tokens.js';
|
|
48
48
|
import { loadClientConfig, loadSources, applyBranding } from './plugins.js';
|
|
49
49
|
import { cycleTheme, initTheme } from './theme.js';
|
|
50
|
+
import { applyMapTheme, onMapStyleChange, watchMapStyle } from './map-style.js';
|
|
50
51
|
|
|
51
52
|
const $ = (id) => document.getElementById(id);
|
|
52
53
|
|
|
@@ -186,6 +187,8 @@ async function runPageBench(frames, zoomFactor, sync) {
|
|
|
186
187
|
// Start
|
|
187
188
|
// ---------------------------------------------------------------------------
|
|
188
189
|
initTheme(); // light or dark, before the first scene is built (theme.js)
|
|
190
|
+
watchMapStyle(document); // the map reads --corn-map-* from the theme, and again when it changes (map-style.js)
|
|
191
|
+
onMapStyleChange(() => render());
|
|
189
192
|
state.canvas = $('graph-canvas');
|
|
190
193
|
state.labelCanvas = $('label-canvas');
|
|
191
194
|
// A 2d context that only measures text (layout.js labelWidth): the map canvas may be WebGL, and a
|
|
@@ -204,7 +207,7 @@ $('mobile-node-search').addEventListener('input', (e) => handleSearch(e.target.v
|
|
|
204
207
|
resize();
|
|
205
208
|
syncViewUi();
|
|
206
209
|
// /?proposal=<slug> opens a proposal over the map, /?view=dataflow the data-flow preset: both have a link
|
|
207
|
-
const configReady = loadClientConfig().then((config) => { applyBranding(document, config); return config; });
|
|
210
|
+
const configReady = loadClientConfig().then((config) => { applyBranding(document, config); applyMapTheme(document, config.theme); return config; }); // the brand, then the theme's icons for the map
|
|
208
211
|
loadTopology().then(async (ok) => {
|
|
209
212
|
if (!ok) return;
|
|
210
213
|
// The sources the repo's cornfield.config.js names (plugins.js): a live layer, a house, devices, a checker; each optional
|