cornfield 0.39.0 → 0.41.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/config.js +5 -0
- package/core/contrast.js +47 -6
- package/core/layers.js +412 -0
- package/core/map-tokens.js +48 -3
- package/core/strings.js +3 -0
- package/core/theme.js +5 -4
- package/core/validate.js +4 -1
- package/explorer/camera.js +1 -1
- package/explorer/cluster.js +26 -0
- package/explorer/explorer.css +80 -6
- package/explorer/fly.js +48 -0
- package/explorer/header-fit.js +8 -0
- package/explorer/index.html +18 -3
- package/explorer/input.js +16 -5
- package/explorer/keyboard.js +12 -22
- package/explorer/kind-letters.js +70 -0
- package/explorer/labels.js +239 -80
- package/explorer/layer-model.js +59 -0
- package/explorer/layers.js +239 -53
- package/explorer/layout.js +43 -15
- package/explorer/main.js +15 -35
- package/explorer/map-style.js +49 -14
- package/explorer/panels.js +5 -3
- package/explorer/render.js +19 -1
- package/explorer/renderer-canvas2d.js +9 -0
- package/explorer/renderer-webgl.js +21 -11
- package/explorer/scenario-ui.js +5 -2
- package/explorer/scene.js +43 -37
- package/explorer/search-model.js +156 -0
- package/explorer/search-status.js +24 -13
- package/explorer/search.js +335 -0
- package/explorer/shaders.js +1 -1
- package/explorer/state.js +13 -0
- package/explorer/tokens.css +2 -0
- package/package.json +1 -1
- package/server/server.js +4 -1
package/core/theme.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
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)
|
|
14
|
+
* icons: { app: './tools/cornfield/icons/app.svg' }, // an icon per node type ("app"), per finer kind ("service:timer") or per project layer ("layer:timers"), drawn inside the node on the map (svg or png)
|
|
15
15
|
* pixelated: true, // small icons are drawn crisp (nearest-neighbour), not smoothed
|
|
16
16
|
* contrast: 'error', // 'warn' turns a failing contrast pair in `validate` into a warning
|
|
17
17
|
* }
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import fs from 'node:fs';
|
|
23
23
|
import path from 'node:path';
|
|
24
24
|
import { NODE_THEMES } from './schema.js';
|
|
25
|
+
import { iconKeyShape } from './layers.js';
|
|
25
26
|
|
|
26
27
|
export const THEME_KEYS = Object.freeze(['css', 'fonts', 'fontHosts', 'names', 'default', 'icons', 'pixelated', 'contrast']);
|
|
27
28
|
/** The node kinds an icon may be set for: every node type of the map */
|
|
@@ -109,10 +110,10 @@ export function themeProblems(t) {
|
|
|
109
110
|
}
|
|
110
111
|
if (t.pixelated !== undefined && typeof t.pixelated !== 'boolean') out.push('theme.pixelated is true or false.');
|
|
111
112
|
if (t.icons !== undefined) {
|
|
112
|
-
if (!isObject(t.icons)) out.push('theme.icons is { "<node
|
|
113
|
+
if (!isObject(t.icons)) out.push('theme.icons is { "<node type>": "./path.svg" } (or "<type>:<kind>", or "layer:<key>").');
|
|
113
114
|
else {
|
|
114
115
|
for (const [kind, rel] of Object.entries(t.icons)) {
|
|
115
|
-
if (!
|
|
116
|
+
if (!iconKeyShape(kind)) out.push(`theme.icons "${kind.slice(0, 60)}": not a node type (${ICON_KINDS.join(', ')}), a finer kind like "service:timer", or a project layer like "layer:timers".`);
|
|
116
117
|
const found = themeIconAsset(t, rel);
|
|
117
118
|
if ('problem' in found) out.push(`theme.icons.${kind} ${found.problem}`);
|
|
118
119
|
}
|
|
@@ -145,7 +146,7 @@ export function iconUrls(theme) {
|
|
|
145
146
|
const out = {};
|
|
146
147
|
if (!theme || !isObject(theme.icons)) return out;
|
|
147
148
|
for (const [kind, rel] of Object.entries(theme.icons)) {
|
|
148
|
-
if (!
|
|
149
|
+
if (!iconKeyShape(kind)) continue;
|
|
149
150
|
const found = themeIconAsset(theme, rel);
|
|
150
151
|
if (!('problem' in found)) out[kind] = THEME_ASSET_PREFIX + found.asset;
|
|
151
152
|
}
|
package/core/validate.js
CHANGED
|
@@ -24,7 +24,8 @@ import { deriveTopology } from './derive.js';
|
|
|
24
24
|
import { missingPaths, planSync } from './sync.js';
|
|
25
25
|
import { repoPaths, repoReader } from './repo.js';
|
|
26
26
|
import { checkThemeContrast } from './contrast.js';
|
|
27
|
-
import { mapTokenWarnings } from './map-tokens.js';
|
|
27
|
+
import { layerTokenWarnings, mapTokenWarnings } from './map-tokens.js';
|
|
28
|
+
import { layersMapWarnings } from './layers.js';
|
|
28
29
|
import { BRAND_IMAGE_KEYS, brandAssetFile } from './brand.js';
|
|
29
30
|
import { MAX_THEME_BYTES, cssProblems, cssUrls, themeAssetFile, themeFileUrl, themeFiles, themeIconFileProblems, themeUrlTarget } from './theme.js';
|
|
30
31
|
|
|
@@ -286,6 +287,8 @@ export async function validateRepo({ config, derivers, topology = readTopology(c
|
|
|
286
287
|
warnings.push(...contrast.warnings);
|
|
287
288
|
if (contrast.summary) notes.push(contrast.summary);
|
|
288
289
|
warnings.push(...mapTokenWarnings(config)); // a map font, line width or glow the map cannot read draws as auto
|
|
290
|
+
warnings.push(...layerTokenWarnings(config, topology)); // a kind token, a group token or an icon for a kind or layer that is not there
|
|
291
|
+
warnings.push(...layersMapWarnings(config.layers, topology)); // a project layer that matches nothing, or whose every node an earlier layer took
|
|
289
292
|
errors.push(...validateCloudNodes(topology, config.root));
|
|
290
293
|
errors.push(...validateProposalFiles(topology, path.join(config.root, config.proposals), config.root));
|
|
291
294
|
const io = repoReader(config.root);
|
package/explorer/camera.js
CHANGED
|
@@ -64,7 +64,7 @@ export function pinchCamera(start, dist, mid, min = ZOOM_MIN) {
|
|
|
64
64
|
// Framing: put these nodes in the part of the map nothing covers
|
|
65
65
|
// ---------------------------------------------------------------------------
|
|
66
66
|
|
|
67
|
-
/** The zoom at which a node's label is about 11px on screen (
|
|
67
|
+
/** The zoom at which a node's label is about 11px on screen (a label is never drawn under 11px, labels.js): where a step or a picked change is shown */
|
|
68
68
|
export const READ_ZOOM = 1.0;
|
|
69
69
|
/**
|
|
70
70
|
* The lowest zoom a change is framed at when it opens (proposal.js `fitToChange`): below it node discs and marks run together, so a change
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/cluster
|
|
3
|
+
*
|
|
4
|
+
* A cluster is a hub and what hangs under it (spec 0008 D1): an app and its pages, a store and its tables. A click or tap on a cluster's title
|
|
5
|
+
* (its hub's label) frames the cluster: the camera fits to all of it. Pure: nodes and edges in, ids out.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The ids of a hub and everything under it, by ownership edges (no kind, not dashed).
|
|
10
|
+
* @param {string} hubId
|
|
11
|
+
* @param {{from: string, to: string, kind?: string, dashed?: boolean}[]} edges
|
|
12
|
+
* @returns {Set<string>}
|
|
13
|
+
*/
|
|
14
|
+
export function clusterIds(hubId, edges) {
|
|
15
|
+
const kids = new Map();
|
|
16
|
+
for (const e of edges) {
|
|
17
|
+
if (e.kind || e.dashed || !e.from || !e.to) continue;
|
|
18
|
+
(kids.get(e.from) || kids.set(e.from, []).get(e.from)).push(e.to);
|
|
19
|
+
}
|
|
20
|
+
const out = new Set([hubId]);
|
|
21
|
+
const todo = [hubId];
|
|
22
|
+
while (todo.length) {
|
|
23
|
+
for (const k of kids.get(todo.pop()) || []) if (!out.has(k)) { out.add(k); todo.push(k); }
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
package/explorer/explorer.css
CHANGED
|
@@ -177,7 +177,11 @@ h1, h2, h3, p { margin: 0; }
|
|
|
177
177
|
.hx-brand { min-width: 0; min-height: 0; }
|
|
178
178
|
.hx-only-wide { display: inline; }
|
|
179
179
|
.hx-only-mobile { display: none; }
|
|
180
|
-
.hx-search { display: flex; }
|
|
180
|
+
.hx-search { display: flex; flex: 0 1 260px; width: auto; }
|
|
181
|
+
/* A narrow desktop (768 to about 900 px, signed in): the search gives up width before it runs over the Layers chip; the left group
|
|
182
|
+
keeps its own (the right group shrinks, the search down to its min-width) */
|
|
183
|
+
.hx-header-left { flex: none; }
|
|
184
|
+
.hx-header-right { flex: 0 1 auto; min-width: 0; }
|
|
181
185
|
}
|
|
182
186
|
/* Not for a desktop: the brand keeps its logo and shows its wordmark; with no wordmark the logo stands alone (the button keeps its name) */
|
|
183
187
|
@media (max-width: 767px) {
|
|
@@ -193,7 +197,6 @@ h1, h2, h3, p { margin: 0; }
|
|
|
193
197
|
.hx-view-fit { position: absolute; top: calc(100% + var(--corn-space-4)); right: var(--corn-space-4); width: 44px; height: 44px; margin: 0; border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); background: var(--corn-surface-1); color: var(--corn-text-2); box-shadow: var(--corn-shadow); }
|
|
194
198
|
.hx-header .hx-layers { position: absolute; top: calc(100% + var(--corn-space-4)); left: var(--corn-space-4); }
|
|
195
199
|
.hx-layers-chip { height: 44px; padding: 0 var(--corn-space-5); border-radius: var(--corn-radius-pill); background: var(--corn-surface-1); box-shadow: var(--corn-shadow); }
|
|
196
|
-
.hx-layers .hx-menu { width: min(288px, calc(100vw - 24px)); }
|
|
197
200
|
/* The live chip sits on the map too, left of Fit */
|
|
198
201
|
.hx-header .hx-live { position: absolute; top: calc(100% + var(--corn-space-4)); right: calc(var(--corn-space-4) + var(--corn-space-3) + 44px); }
|
|
199
202
|
.hx-work { height: 44px; min-width: 44px; justify-content: center; padding: 0 var(--corn-space-3); }
|
|
@@ -969,6 +972,8 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
|
|
|
969
972
|
/* ---- the node panel (panels.js, #138): type · name · one line · facts · mockups · threads · the diff · the actions ------------ */
|
|
970
973
|
.hx-drawer-id { flex: 1; min-width: 0; }
|
|
971
974
|
.hx-kicker { display: flex; flex-wrap: wrap; align-items: center; margin: 0 0 var(--corn-space-2); font-size: var(--corn-text-sm); color: var(--corn-text-3); }
|
|
975
|
+
/* The badge carries a project's own kind ("Service · timer", spec 0009): a long one wraps inside the panel, never past it */
|
|
976
|
+
.hx-kicker [data-corn="badge"] { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
|
|
972
977
|
#drawer-host { white-space: pre; } /* the kicker is a flex row, which drops a leading space: keep " · host" */
|
|
973
978
|
.hx-diffpill { margin-left: var(--corn-space-3); padding: 0 var(--corn-space-3); border-radius: var(--corn-radius-pill); border: var(--corn-border) dashed var(--corn-added); color: var(--corn-added-text); font-size: var(--corn-text-xs); }
|
|
974
979
|
.hx-drawer-id .hx-drawer-title { font-size: var(--corn-text-xl); font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
|
|
@@ -1093,11 +1098,10 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
|
|
|
1093
1098
|
.hx-drawer[data-sheet-state="peek"] .hx-drawer-title { overflow: visible; text-overflow: clip; white-space: normal; }
|
|
1094
1099
|
}
|
|
1095
1100
|
|
|
1096
|
-
/* Search
|
|
1101
|
+
/* Search status (F24, spec 0008): the polite live region by each search field. The count and the list say it on the screen (below), so
|
|
1102
|
+
the region itself is only for a screen reader: it stays in the page, out of sight. */
|
|
1097
1103
|
.hx-search { position: relative; }
|
|
1098
|
-
.hx-search-status { position: absolute;
|
|
1099
|
-
.hx-search-status:empty { display: none; }
|
|
1100
|
-
.hx-mobile-search .hx-search-status { top: calc(100% - var(--corn-space-1)); left: var(--corn-space-3); right: var(--corn-space-3); }
|
|
1104
|
+
.hx-search-status { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
|
|
1101
1105
|
|
|
1102
1106
|
/* The node panel's facts break at word boundaries only (F60): "hook" is never "hoo / k". A long path or name still wraps, at its slashes and dashes, and only as a last resort anywhere. */
|
|
1103
1107
|
.hx-fact-v { overflow-wrap: break-word; word-break: normal; }
|
|
@@ -1174,6 +1178,51 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
|
|
|
1174
1178
|
.hx-offline[hidden] { display: none; }
|
|
1175
1179
|
.hx-offline[data-corn-state="success"] { border-color: var(--corn-ok); }
|
|
1176
1180
|
|
|
1181
|
+
/* ---------------------------------------------------------------------------
|
|
1182
|
+
Search: the count, the step buttons and the list of what was found (spec 0008 D4)
|
|
1183
|
+
--------------------------------------------------------------------------- */
|
|
1184
|
+
.hx-search-steps { display: flex; align-items: center; flex: none; gap: var(--corn-space-1); }
|
|
1185
|
+
.hx-search-steps[hidden] { display: none; }
|
|
1186
|
+
.hx-search-count { padding: 0 var(--corn-space-2); font-size: var(--corn-text-2xs); color: var(--corn-text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
|
|
1187
|
+
.hx-search-count[data-empty="true"] { color: var(--corn-text); font-weight: 600; }
|
|
1188
|
+
.hx-search-btn { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: var(--corn-radius-xs); background: none; color: var(--corn-text-3); }
|
|
1189
|
+
.hx-search-btn:hover { background: var(--corn-surface-3); color: var(--corn-text); }
|
|
1190
|
+
.hx-search-btn:focus-visible, .hx-search-row:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: calc(var(--corn-focus-offset) * -1); }
|
|
1191
|
+
.hx-search:has(.hx-search-steps:not([hidden])) { flex-basis: 340px; }
|
|
1192
|
+
/* A narrow desktop leaves the field too little room for the count and three buttons: Previous and Next go (Enter and Shift+Enter, N and P
|
|
1193
|
+
and the list's rows still step), the count and Clear stay */
|
|
1194
|
+
@media (min-width: 768px) and (max-width: 959px) {
|
|
1195
|
+
.hx-search [data-action="search-prev"], .hx-search [data-action="search-next"] { display: none; }
|
|
1196
|
+
}
|
|
1197
|
+
.hx-search-results { position: absolute; top: calc(100% + var(--corn-space-2)); right: 0; z-index: 40; width: min(440px, 92vw); max-height: min(60vh, 560px); overflow-y: auto; padding: var(--corn-space-1) 0; border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: var(--corn-ground); box-shadow: var(--corn-shadow); color: var(--corn-text); font-size: var(--corn-text-sm); } /* the ground itself, not a surface: a surface is see-through, and the panel under the list would show in it */
|
|
1198
|
+
.hx-search-results[hidden] { display: none; }
|
|
1199
|
+
/* The list is part of the header, which sits under the node panel (40): while the list is open the header is over it, so a row is never half under the panel */
|
|
1200
|
+
.hx-header:has(.hx-search-results:not([hidden])) { z-index: 46; }
|
|
1201
|
+
/* On a phone the list is in the search bar, under the sheets (the dock, 45): while it is open the bar is over them, so a proposal's or the
|
|
1202
|
+
Work sheet never covers rows of it. Without :has() the list stays under the sheets, as the bar always was */
|
|
1203
|
+
.hx-mobile-search:has(.hx-search-results:not([hidden])) { z-index: 46; }
|
|
1204
|
+
.hx-search-group-title { position: sticky; top: 0; display: flex; justify-content: space-between; gap: var(--corn-space-3); padding: var(--corn-space-2) var(--corn-space-3) var(--corn-space-1); background: var(--corn-ground); color: var(--corn-text-3); font-size: var(--corn-text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
1205
|
+
.hx-search-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--corn-space-3); width: 100%; min-height: 28px; padding: var(--corn-space-1) var(--corn-space-3); border: 0; border-left: var(--corn-border-strong) solid transparent; background: none; color: var(--corn-text); font: inherit; text-align: left; cursor: pointer; }
|
|
1206
|
+
.hx-search-row:hover, .hx-search-row:focus-visible { background: var(--corn-surface-3); }
|
|
1207
|
+
.hx-search-row[aria-current="true"] { border-left-color: var(--corn-accent); background: var(--corn-accent-soft); }
|
|
1208
|
+
.hx-search-row-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1209
|
+
.hx-search-row-parent { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--corn-text-3); font-size: var(--corn-text-xs); }
|
|
1210
|
+
.hx-search-frame { font-weight: 600; color: var(--corn-text); }
|
|
1211
|
+
.hx-search-empty, .hx-search-more { margin: 0; padding: var(--corn-space-2) var(--corn-space-3); color: var(--corn-text-2); overflow-wrap: anywhere; }
|
|
1212
|
+
.hx-mobile-search { flex-wrap: wrap; }
|
|
1213
|
+
.hx-mobile-search .hx-input { flex: 1 1 0; min-width: 0; }
|
|
1214
|
+
.hx-mobile-search::before { top: calc(var(--corn-space-3) + 22px); } /* the magnifier stays by the field when the bar wraps to a second row of steps */
|
|
1215
|
+
.hx-mobile-search .hx-search-steps { flex: 1 0 100%; justify-content: flex-end; gap: var(--corn-space-1); }
|
|
1216
|
+
.hx-mobile-search .hx-search-count { margin-right: auto; font-size: var(--corn-text-xs); }
|
|
1217
|
+
.hx-mobile-search .hx-search-results { top: 100%; left: 0; right: 0; width: auto; max-height: 50vh; border-radius: 0; border-left: 0; border-right: 0; }
|
|
1218
|
+
@media (max-width: 767px), (pointer: coarse) {
|
|
1219
|
+
.hx-search-btn { min-width: 44px; min-height: 44px; }
|
|
1220
|
+
.hx-search-row { min-height: 44px; }
|
|
1221
|
+
}
|
|
1222
|
+
@media (forced-colors: active) {
|
|
1223
|
+
.hx-search-row[aria-current="true"] { border-left-color: Highlight; }
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1177
1226
|
/* ==== the review column (spec 0006, review-column.js): the changes, and the personas with the scenarios that apply to them ==============
|
|
1178
1227
|
From 768px it is docked on the left of the map under the proposal bar (the free map is what it leaves: sheets.js visibleMapRect);
|
|
1179
1228
|
on a phone it is the expanded proposal sheet's body, a two-part switch at its top, its foot (the decision) always in view. */
|
|
@@ -1284,6 +1333,31 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
|
|
|
1284
1333
|
.hx-player-speed[data-corn="control"] { color: var(--corn-text); }
|
|
1285
1334
|
/* ==== end of the player bar ===================================================================================================== */
|
|
1286
1335
|
|
|
1336
|
+
/* ---------------------------------------------------------------------------
|
|
1337
|
+
Project layers and finer kinds (spec 0009): the Layers menu holds its title (with All and None) while the rows scroll, the Overlays heading,
|
|
1338
|
+
the "+N shown by the proposal" note and the kinds key under a row. Every colour is a token; a theme reaches each through its data-corn hook.
|
|
1339
|
+
--------------------------------------------------------------------------- */
|
|
1340
|
+
.hx-layers .hx-menu { display: flex; flex-direction: column; overflow: hidden; }
|
|
1341
|
+
.hx-layers .hx-menu[hidden] { display: none; }
|
|
1342
|
+
.hx-layers .hx-menu-head { flex: none; }
|
|
1343
|
+
.hx-menu-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
|
|
1344
|
+
.hx-overlays { margin-top: var(--corn-space-3); padding-top: var(--corn-space-3); border-top: var(--corn-border) solid var(--corn-line); }
|
|
1345
|
+
.hx-layer-note { font-size: var(--corn-text-2xs); }
|
|
1346
|
+
.hx-kinds { padding: 0 var(--corn-space-3) var(--corn-space-1) var(--corn-space-5); }
|
|
1347
|
+
.hx-kinds-btn { display: inline-flex; align-items: center; gap: var(--corn-space-1); }
|
|
1348
|
+
.hx-kind-keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: calc(var(--corn-space-1) / 2); }
|
|
1349
|
+
.hx-kind-key { display: flex; align-items: center; gap: var(--corn-space-3); padding: calc(var(--corn-space-1) / 2) 0; color: var(--corn-text-2); font-size: var(--corn-text-xs); }
|
|
1350
|
+
.hx-kind-letter { display: inline-flex; align-items: center; justify-content: center; min-width: 1.6em; padding: 0 var(--corn-space-1); border-radius: var(--corn-radius-xs); background: var(--corn-surface-3); color: var(--corn-text); font-family: var(--corn-mono); font-size: var(--corn-text-2xs); font-weight: 700; }
|
|
1351
|
+
.hx-kind-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
|
1352
|
+
@media (max-width: 767px) {
|
|
1353
|
+
/* On a phone the menu spans the screen, at most 70% of its height */
|
|
1354
|
+
.hx-layers .hx-menu { position: fixed; top: calc(56px + var(--corn-space-4) + 44px + var(--corn-space-2)); left: 12px; right: 12px; width: auto; max-width: none; max-height: 70dvh; }
|
|
1355
|
+
/* An open menu is over the phone's sheets (the dock, z-index 45), not under them: else a proposal's sheet hides its last rows, which no scroll reaches */
|
|
1356
|
+
.hx-header:has(.hx-layers .hx-menu:not([hidden])) { z-index: 46; }
|
|
1357
|
+
.hx-kinds-btn { min-height: 44px; }
|
|
1358
|
+
}
|
|
1359
|
+
/* ==== end of project layers and finer kinds ============================================================================================ */
|
|
1360
|
+
|
|
1287
1361
|
/* ==========================================================================
|
|
1288
1362
|
What is waiting on you (spec 0010): the one number's badge, the Specs groups, each row's review state, the search, the Runs headings
|
|
1289
1363
|
========================================================================== */
|
package/explorer/fly.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/fly
|
|
3
|
+
*
|
|
4
|
+
* The camera flying to a place: a short glide to `{ x, y, zoom }`, as the scenario player's steps do, so a match chosen in a search
|
|
5
|
+
* is not a jump the eye has to find again. Under reduced motion the camera jumps. A new flight replaces the one in the air, and a
|
|
6
|
+
* hand on the map (a pan, a wheel) is not fought: `stopFlight()` ends it (input.js calls it when the pointer takes the camera).
|
|
7
|
+
* It is a frame client of render.js's loop, so it asks for frames only while it flies.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { state } from './state.js';
|
|
11
|
+
import { render, ensureFlowLoop, addFrameClient } from './render.js';
|
|
12
|
+
import { flowReduceMotion } from './flows.js';
|
|
13
|
+
|
|
14
|
+
/** How quickly the camera closes on the target: the time constant of the glide (ms) */
|
|
15
|
+
export const FLY_MS = 120;
|
|
16
|
+
let glide = null; // { to: {x, y, zoom}, last: nowMs|null }
|
|
17
|
+
|
|
18
|
+
/** Flies the camera to `target` (jumps there when motion is reduced) */
|
|
19
|
+
export function flyTo(target) {
|
|
20
|
+
if (!target) return;
|
|
21
|
+
if (flowReduceMotion || !state.width) { Object.assign(state.camera, target); glide = null; render(); return; }
|
|
22
|
+
glide = { to: { ...target }, last: null };
|
|
23
|
+
ensureFlowLoop();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Ends a flight where it is */
|
|
27
|
+
export function stopFlight() { glide = null; }
|
|
28
|
+
|
|
29
|
+
/** Whether the camera is in the air */
|
|
30
|
+
export const flying = () => !!glide;
|
|
31
|
+
|
|
32
|
+
/** One frame of the glide (exported so a test can be the loop) */
|
|
33
|
+
export function tickFlight(now) {
|
|
34
|
+
if (!glide) return;
|
|
35
|
+
const dt = glide.last === null ? 16 : Math.min(now - glide.last, 100);
|
|
36
|
+
glide.last = now;
|
|
37
|
+
const k = 1 - Math.exp(-dt / FLY_MS);
|
|
38
|
+
const cam = state.camera;
|
|
39
|
+
cam.x += (glide.to.x - cam.x) * k;
|
|
40
|
+
cam.y += (glide.to.y - cam.y) * k;
|
|
41
|
+
cam.zoom += (glide.to.zoom - cam.zoom) * k;
|
|
42
|
+
if (Math.abs(glide.to.x - cam.x) < 0.5 && Math.abs(glide.to.y - cam.y) < 0.5 && Math.abs(glide.to.zoom - cam.zoom) < 0.002) {
|
|
43
|
+
Object.assign(cam, glide.to);
|
|
44
|
+
glide = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
addFrameClient({ wants: flying, tick: tickFlight });
|
package/explorer/header-fit.js
CHANGED
|
@@ -22,6 +22,14 @@ const wider = (el) => el.scrollWidth > el.clientWidth + 1;
|
|
|
22
22
|
export function fitLeft(left) {
|
|
23
23
|
left.removeAttribute(SHORT_ATTR);
|
|
24
24
|
left.removeAttribute(OVERFLOW_ATTR);
|
|
25
|
+
// A menu that is open hangs under its chip and past the group's edge; that is not the group's content running over, and the fade
|
|
26
|
+
// (explorer.css [data-overflow]) is a mask that would hide the menu itself. Measure with open menus out of the way, then put them back.
|
|
27
|
+
const open = [...left.querySelectorAll('.hx-menu')].filter((m) => !m.hidden).map((m) => [m, m.style.display]);
|
|
28
|
+
open.forEach(([m]) => { m.style.display = 'none'; });
|
|
29
|
+
try { return measure(left); } finally { open.forEach(([m, was]) => { m.style.display = was; }); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function measure(left) {
|
|
25
33
|
let short = false;
|
|
26
34
|
if (left.querySelector('[data-corn="brand-wordmark"]') && wider(left)) {
|
|
27
35
|
left.setAttribute(SHORT_ATTR, '');
|
package/explorer/index.html
CHANGED
|
@@ -53,11 +53,12 @@
|
|
|
53
53
|
<div class="hx-menu-title hx-menu-head" data-corn="menu-title">
|
|
54
54
|
<span>Section Toggles</span>
|
|
55
55
|
<span class="hx-menu-links">
|
|
56
|
-
<button type="button" class="hx-textbtn hx-textbtn--accent" data-action="layers-all" data-corn-kind="quiet">All</button>
|
|
56
|
+
<button type="button" class="hx-textbtn hx-textbtn--accent" data-action="layers-all" data-corn="layers-all" data-corn-kind="quiet" data-corn-string="layersAll">All</button>
|
|
57
57
|
<span class="hx-faint">•</span>
|
|
58
|
-
<button type="button" class="hx-textbtn" data-action="layers-none" data-corn-kind="quiet">None</button>
|
|
58
|
+
<button type="button" class="hx-textbtn" data-action="layers-none" data-corn="layers-none" data-corn-kind="quiet" data-corn-string="layersNone">None</button>
|
|
59
59
|
</span>
|
|
60
60
|
</div>
|
|
61
|
+
<div class="hx-menu-body">
|
|
61
62
|
<p id="layers-preset-note" class="hx-note" data-corn="notice" hidden>The data-flow view shows its own tiers and ignores these toggles. Switch it off to use them.</p>
|
|
62
63
|
<div id="layer-toggles-container" class="hx-toggles"></div>
|
|
63
64
|
<div id="flow-legend" hidden></div>
|
|
@@ -93,6 +94,7 @@
|
|
|
93
94
|
<span class="hx-faint hx-mono">Usage & Dependency</span>
|
|
94
95
|
</div>
|
|
95
96
|
</div>
|
|
97
|
+
</div><!-- .hx-menu-body: the rows scroll, the title with All and None stays (spec 0009 D8) -->
|
|
96
98
|
</div>
|
|
97
99
|
</div>
|
|
98
100
|
|
|
@@ -116,7 +118,14 @@
|
|
|
116
118
|
<svg class="hx-search-icon" viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false"><circle cx="7" cy="7" r="4.5" /><path d="M10.5 10.5L14 14" /></svg>
|
|
117
119
|
<input type="text" id="node-search" class="hx-search-input" placeholder="Search..." data-corn-string-placeholder="searchPlaceholder" aria-label="Search nodes" aria-keyshortcuts="/" data-corn="search-input" />
|
|
118
120
|
<kbd class="hx-kbd" data-corn="search-key" aria-hidden="true">/</kbd>
|
|
121
|
+
<span id="search-steps" class="hx-search-steps" data-corn="search-steps" hidden>
|
|
122
|
+
<span id="search-count" class="hx-search-count" data-corn="search-count" aria-hidden="true"></span>
|
|
123
|
+
<button type="button" class="hx-search-btn" data-action="search-prev" aria-label="Previous match" title="Previous match (Shift+Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 10.5L8 6l4.5 4.5" /></svg></button>
|
|
124
|
+
<button type="button" class="hx-search-btn" data-action="search-next" aria-label="Next match" title="Next match (Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 5.5L8 10l4.5-4.5" /></svg></button>
|
|
125
|
+
<button type="button" class="hx-search-btn" data-action="clear-search" aria-label="Clear search" title="Clear search (Escape)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true" focusable="false"><path d="M4 4l8 8M12 4l-8 8" /></svg></button>
|
|
126
|
+
</span>
|
|
119
127
|
<div id="search-status" class="hx-search-status" role="status" aria-live="polite" data-corn="search-status"></div>
|
|
128
|
+
<div id="search-results" class="hx-search-results" data-corn="search-results" hidden></div>
|
|
120
129
|
</div>
|
|
121
130
|
|
|
122
131
|
<!-- The Work toggle (explorer/forge-panel.js): opens the Work panel; shown only when the config names a forge -->
|
|
@@ -175,9 +184,15 @@
|
|
|
175
184
|
<!-- Mobile search bar -->
|
|
176
185
|
<div id="mobile-search-bar" class="hx-mobile-search glass-header" role="search" hidden data-corn="mobile-search">
|
|
177
186
|
<input type="text" id="mobile-node-search" class="hx-input hx-input--wide" placeholder="Search nodes, apps, components..." aria-label="Search nodes" data-corn="search-input" />
|
|
178
|
-
<button type="button" class="hx-textbtn" data-action="clear-search" aria-label="Clear search" data-corn-kind="quiet">✕</button>
|
|
179
187
|
<button type="button" class="hx-textbtn" data-action="close-mobile-search" data-corn-kind="quiet">Cancel</button>
|
|
188
|
+
<span id="mobile-search-steps" class="hx-search-steps" data-corn="search-steps" hidden>
|
|
189
|
+
<span id="mobile-search-count" class="hx-search-count" data-corn="search-count" aria-hidden="true"></span>
|
|
190
|
+
<button type="button" class="hx-search-btn" data-action="search-prev" aria-label="Previous match" title="Previous match (Shift+Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 10.5L8 6l4.5 4.5" /></svg></button>
|
|
191
|
+
<button type="button" class="hx-search-btn" data-action="search-next" aria-label="Next match" title="Next match (Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 5.5L8 10l4.5-4.5" /></svg></button>
|
|
192
|
+
<button type="button" class="hx-search-btn" data-action="clear-search" aria-label="Clear search" title="Clear search (Escape)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true" focusable="false"><path d="M4 4l8 8M12 4l-8 8" /></svg></button>
|
|
193
|
+
</span>
|
|
180
194
|
<div id="mobile-search-status" class="hx-search-status" role="status" aria-live="polite" data-corn="search-status"></div>
|
|
195
|
+
<div id="mobile-search-results" class="hx-search-results" data-corn="search-results" hidden></div>
|
|
181
196
|
</div>
|
|
182
197
|
|
|
183
198
|
<!-- The map -->
|
package/explorer/input.js
CHANGED
|
@@ -13,11 +13,14 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { state, touchScene } from './state.js';
|
|
16
|
-
import { render, getSpatialIndex, queueFrameWork, screenToWorld, getMinZoom } from './render.js';
|
|
16
|
+
import { render, getSpatialIndex, queueFrameWork, screenToWorld, getMinZoom, setHoverNode, labelNodeAt, fitGraphToViewport, fitPadding } from './render.js';
|
|
17
|
+
import { clusterIds } from './cluster.js';
|
|
18
|
+
import { LANDMARK_TYPES } from './scene.js';
|
|
17
19
|
import { saveFreeformPositions } from './layout.js';
|
|
18
20
|
import { selectNode, closeDrawer } from './panels.js';
|
|
19
21
|
import { hitTestScreen } from './spatial.js';
|
|
20
22
|
import { zoomAbout, pinchStart, pinchCamera } from './camera.js';
|
|
23
|
+
import { stopFlight } from './fly.js';
|
|
21
24
|
|
|
22
25
|
let isDragging = false;
|
|
23
26
|
let dragNode = null;
|
|
@@ -71,6 +74,8 @@ function touchMid(e) {
|
|
|
71
74
|
|
|
72
75
|
function onPointerDown(e) {
|
|
73
76
|
downOnCanvas = true;
|
|
77
|
+
stopFlight(); // the hand takes the camera: a flight to a match ends where it is
|
|
78
|
+
setHoverNode(null); // a press starts a tap or a drag: the chip that named a node under the pointer goes
|
|
74
79
|
if (e.touches && e.touches.length === 2) {
|
|
75
80
|
pinch = pinchStart(state.camera, touchDistance(e), touchMid(e));
|
|
76
81
|
pendingPos = null;
|
|
@@ -124,7 +129,9 @@ function applyHover() {
|
|
|
124
129
|
const p = pendingHover;
|
|
125
130
|
pendingHover = null;
|
|
126
131
|
if (!p || isDragging || dragNode) return;
|
|
127
|
-
|
|
132
|
+
const over = findNodeAt(p.x, p.y, false);
|
|
133
|
+
setHover(!!over);
|
|
134
|
+
setHoverNode(over ? over.id : null); // a node with no label is named by a chip (labels.js)
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
function setHover(over) {
|
|
@@ -183,8 +190,11 @@ function onPointerUp(e) {
|
|
|
183
190
|
}
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
|
-
} else
|
|
187
|
-
|
|
193
|
+
} else {
|
|
194
|
+
// A cluster's title (its hub's label) is not a node to select: a click on it frames the cluster (spec 0008 D1)
|
|
195
|
+
const titled = topologyNode(labelNodeAt(p.x, p.y));
|
|
196
|
+
if (titled && LANDMARK_TYPES.includes(titled.type) && titled.id !== 'root') fitGraphToViewport(fitPadding(), clusterIds(titled.id, state.edges));
|
|
197
|
+
else if (state.selectedNode) closeDrawer(); // the background was clicked: back to the normal view
|
|
188
198
|
}
|
|
189
199
|
}
|
|
190
200
|
isDragging = false;
|
|
@@ -199,7 +209,7 @@ export function bindCanvasInput() {
|
|
|
199
209
|
const { canvas } = state;
|
|
200
210
|
canvas.addEventListener('mousedown', onPointerDown);
|
|
201
211
|
canvas.addEventListener('mousemove', onPointerMove);
|
|
202
|
-
canvas.addEventListener('mouseleave', () => { pendingHover = null; setHover(false); });
|
|
212
|
+
canvas.addEventListener('mouseleave', () => { pendingHover = null; setHover(false); setHoverNode(null); });
|
|
203
213
|
window.addEventListener('mouseup', onPointerUp);
|
|
204
214
|
|
|
205
215
|
canvas.addEventListener('touchstart', onPointerDown, { passive: false });
|
|
@@ -209,6 +219,7 @@ export function bindCanvasInput() {
|
|
|
209
219
|
|
|
210
220
|
canvas.addEventListener('wheel', (e) => {
|
|
211
221
|
e.preventDefault();
|
|
222
|
+
stopFlight();
|
|
212
223
|
const p = getPointerPos(e);
|
|
213
224
|
Object.assign(state.camera, zoomAbout(state.camera, e.deltaY < 0 ? 1.12 : 0.88, p.x, p.y, getMinZoom()));
|
|
214
225
|
render(); // a camera change is cheap; the draw is one per frame however many wheel events arrive
|
package/explorer/keyboard.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Escape closes it, and in Freeform Alt+arrow moves the selected node;
|
|
11
11
|
* - `#map-announcer` (a polite live region) says where the keyboard landed: the node, its type, its
|
|
12
12
|
* connections, its place; the zoom; a search's hit;
|
|
13
|
-
* - Enter in the search box selects the
|
|
13
|
+
* - Enter in the search box selects the best match and goes on to the next (search.js); with a search on, N and P step through its matches;
|
|
14
14
|
* - the panel: Escape inside it closes it and gives the focus back to the map; it is `inert` while closed
|
|
15
15
|
* (panels.js), so its buttons are never tabbed to off screen;
|
|
16
16
|
* - the Layers menu says whether it is open (`aria-expanded`), and Escape closes it, back on its button;
|
|
@@ -24,6 +24,7 @@ import { selectNode, closeDrawer } from './panels.js';
|
|
|
24
24
|
import { saveFreeformPositions } from './layout.js';
|
|
25
25
|
import { closeLegendMenu } from './layers.js';
|
|
26
26
|
import * as K from './keyboard-model.js';
|
|
27
|
+
import { searchActive, stepMatch } from './search.js';
|
|
27
28
|
|
|
28
29
|
const $ = (id) => document.getElementById(id);
|
|
29
30
|
let wired = false;
|
|
@@ -42,17 +43,21 @@ export function announce(text) {
|
|
|
42
43
|
/** The visible nodes, in the order the keys step through them */
|
|
43
44
|
const stepOrder = () => K.readingOrder(state.nodes.filter((n) => isNodeVisible(n)));
|
|
44
45
|
|
|
45
|
-
/**
|
|
46
|
-
export function
|
|
47
|
-
const {
|
|
46
|
+
/** The camera that puts `node` in the middle of the part of the map not under the panels or a phone's sheets, at `zoom` (the current one by default) */
|
|
47
|
+
export function centreTarget(node, zoom = state.camera.zoom) {
|
|
48
|
+
const { width, height } = state;
|
|
48
49
|
const visibleHeight = Math.max(160, height - (state.coveredBottom || 0));
|
|
49
50
|
const panel = $('spec-drawer');
|
|
50
51
|
const visibleWidth = width >= 768 && panel && panel.classList.contains('drawer-open') ? Math.max(160, width - (panel.offsetWidth || 480)) : width;
|
|
51
52
|
// The issues and PRs panel slides in from the left (forge-panel.js)
|
|
52
53
|
const forge = $('forge-panel');
|
|
53
54
|
const left = width >= 768 && forge && forge.classList.contains('forge-open') ? Math.min(forge.offsetWidth || 400, visibleWidth - 160) : 0;
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
return { x: left + (visibleWidth - left) / 2 - node.x * zoom, y: visibleHeight / 2 - node.y * zoom, zoom };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Moves the camera so `node` is in the middle of the part of the map not under the panels or a phone's sheets */
|
|
59
|
+
export function centreOn(node) {
|
|
60
|
+
Object.assign(state.camera, centreTarget(node));
|
|
56
61
|
render();
|
|
57
62
|
}
|
|
58
63
|
|
|
@@ -108,6 +113,7 @@ function onMapKey(e) {
|
|
|
108
113
|
announce(`The whole map. ${K.zoomWords(camera.zoom)}`);
|
|
109
114
|
break;
|
|
110
115
|
case 'step': {
|
|
116
|
+
if (searchActive() && stepMatch(action.by)) break; // with a search on, N and P walk its matches (search.js)
|
|
111
117
|
const order = stepOrder();
|
|
112
118
|
land(K.stepFrom(order, state.selectedNode && state.selectedNode.id, action.by), order);
|
|
113
119
|
break;
|
|
@@ -147,18 +153,6 @@ function onPanelClick(e) {
|
|
|
147
153
|
if (close && state.canvas) setTimeout(() => state.canvas.focus(), 0);
|
|
148
154
|
}
|
|
149
155
|
|
|
150
|
-
/** Enter in a search box: the first visible node it matches is selected, like a click on it */
|
|
151
|
-
function onSearchKey(e) {
|
|
152
|
-
if (e.key !== 'Enter') return;
|
|
153
|
-
const q = e.target.value.trim().toLowerCase();
|
|
154
|
-
if (!q) return;
|
|
155
|
-
e.preventDefault();
|
|
156
|
-
const order = stepOrder();
|
|
157
|
-
const hit = order.find((n) => n.label.toLowerCase().includes(q));
|
|
158
|
-
if (!hit) { announce(`No node matches ${e.target.value.trim()}`); return; }
|
|
159
|
-
land(hit, order);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
156
|
/** Whether the key went to something that takes typing */
|
|
163
157
|
const typing = (el) => !!el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName));
|
|
164
158
|
|
|
@@ -198,10 +192,6 @@ export function initKeyboard() {
|
|
|
198
192
|
drawer.addEventListener('keydown', onPanelKey);
|
|
199
193
|
drawer.addEventListener('click', onPanelClick);
|
|
200
194
|
}
|
|
201
|
-
for (const id of ['node-search', 'mobile-node-search']) {
|
|
202
|
-
const input = $(id);
|
|
203
|
-
if (input) input.addEventListener('keydown', onSearchKey);
|
|
204
|
-
}
|
|
205
195
|
document.addEventListener('keydown', onDocumentKey);
|
|
206
196
|
}
|
|
207
197
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/kind-letters
|
|
3
|
+
*
|
|
4
|
+
* The letters a finer `kind` shows in the middle of its node (spec 0009 D5): `j` for a job, `h` for a hook (core/layers.js `kindLetters`
|
|
5
|
+
* chooses them; scene.js puts them on the node as `letters`). Both renderers draw the same picture, so it is made once, here: a small
|
|
6
|
+
* transparent image of the letters (dark ink under a light outline, so it reads over the node's own colour and the white core in either
|
|
7
|
+
* theme), and the rule for when it is drawn.
|
|
8
|
+
*
|
|
9
|
+
* - Canvas 2D draws it with `drawImage` where the theme's icon would go.
|
|
10
|
+
* - WebGL uploads it as a texture and draws it in the icon pass, grouped by letters like an icon is grouped by kind (`letters:<l>`).
|
|
11
|
+
*
|
|
12
|
+
* A theme icon for the node's kind replaces it (the node then carries `icon`); spec 0008's type glyphs sit in this same place and can draw
|
|
13
|
+
* beside or instead of it. The letters are text: an image of them is made with fillText, never markup.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { FONT_NODE } from './scene.js';
|
|
17
|
+
|
|
18
|
+
/** A node is at least this many px across (on screen) before its letters are drawn: smaller, they are a smudge */
|
|
19
|
+
export const LETTER_MIN_PX = 14;
|
|
20
|
+
/** The letters' box, as a fraction of the node's radius across (a square centred on the node, like an icon) */
|
|
21
|
+
export const LETTER_RATIO = 1;
|
|
22
|
+
/** The image's side in px: sharp up to a node several times its size on screen */
|
|
23
|
+
const SIDE = 96;
|
|
24
|
+
const KEY_PREFIX = 'letters:';
|
|
25
|
+
|
|
26
|
+
/** The key a node's letters go under in the renderers' icon tables */
|
|
27
|
+
export const letterKey = (letters) => `${KEY_PREFIX}${letters}`;
|
|
28
|
+
export const isLetterKey = (key) => typeof key === 'string' && key.startsWith(KEY_PREFIX);
|
|
29
|
+
export const lettersOfKey = (key) => key.slice(KEY_PREFIX.length);
|
|
30
|
+
|
|
31
|
+
/** Whether a node's letters are drawn at this zoom: it has some, no theme icon replaces them, and it is wide enough on screen */
|
|
32
|
+
export const showsLetters = (node, zoom) => !!node.letters && !node.icon && node.r * 2 * zoom >= LETTER_MIN_PX;
|
|
33
|
+
|
|
34
|
+
const images = new Map();
|
|
35
|
+
/** The most letter images made (and so WebGL textures, one each): a map's kinds are its own data, so the count is held, not trusted. A kind
|
|
36
|
+
* past it draws as a plain node, as one with no letters does */
|
|
37
|
+
export const MAX_LETTER_IMAGES = 128;
|
|
38
|
+
/** Lets the images go (a test starts afresh with it) */
|
|
39
|
+
export const forgetLetterImages = () => images.clear();
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The image of some letters, made once (null where there is no canvas to draw one on, as in a test without a browser).
|
|
43
|
+
* @param {string} letters one or two characters
|
|
44
|
+
* @returns {CanvasImageSource | null}
|
|
45
|
+
*/
|
|
46
|
+
export function letterImage(letters) {
|
|
47
|
+
if (typeof letters !== 'string' || !letters) return null;
|
|
48
|
+
if (images.has(letters)) return images.get(letters);
|
|
49
|
+
if (images.size >= MAX_LETTER_IMAGES) return null;
|
|
50
|
+
let image = null;
|
|
51
|
+
try {
|
|
52
|
+
const canvas = typeof OffscreenCanvas !== 'undefined' ? new OffscreenCanvas(SIDE, SIDE) : typeof document !== 'undefined' ? Object.assign(document.createElement('canvas'), { width: SIDE, height: SIDE }) : null;
|
|
53
|
+
const ctx = canvas && canvas.getContext && canvas.getContext('2d');
|
|
54
|
+
if (ctx && ctx.fillText) {
|
|
55
|
+
const size = letters.length > 1 ? 56 : 72;
|
|
56
|
+
ctx.font = `700 ${size}px ${FONT_NODE}`;
|
|
57
|
+
ctx.textAlign = 'center';
|
|
58
|
+
ctx.textBaseline = 'middle';
|
|
59
|
+
ctx.lineJoin = 'round';
|
|
60
|
+
ctx.lineWidth = 10;
|
|
61
|
+
ctx.strokeStyle = 'rgba(255, 255, 255, 0.92)';
|
|
62
|
+
ctx.strokeText(letters, SIDE / 2, SIDE / 2 + 3);
|
|
63
|
+
ctx.fillStyle = '#0b1220';
|
|
64
|
+
ctx.fillText(letters, SIDE / 2, SIDE / 2 + 3);
|
|
65
|
+
image = canvas;
|
|
66
|
+
}
|
|
67
|
+
} catch { image = null; }
|
|
68
|
+
images.set(letters, image);
|
|
69
|
+
return image;
|
|
70
|
+
}
|