cornfield 0.39.0 → 0.40.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 +45 -1
- package/core/strings.js +3 -0
- package/core/theme.js +5 -4
- package/core/validate.js +4 -1
- package/explorer/explorer.css +27 -1
- package/explorer/header-fit.js +8 -0
- package/explorer/index.html +4 -2
- package/explorer/kind-letters.js +70 -0
- package/explorer/layer-model.js +59 -0
- package/explorer/layers.js +239 -53
- package/explorer/main.js +9 -10
- package/explorer/map-style.js +28 -6
- package/explorer/panels.js +5 -3
- 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 +15 -1
- package/explorer/shaders.js +1 -1
- package/explorer/state.js +9 -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/explorer.css
CHANGED
|
@@ -193,7 +193,6 @@ h1, h2, h3, p { margin: 0; }
|
|
|
193
193
|
.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
194
|
.hx-header .hx-layers { position: absolute; top: calc(100% + var(--corn-space-4)); left: var(--corn-space-4); }
|
|
195
195
|
.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
196
|
/* The live chip sits on the map too, left of Fit */
|
|
198
197
|
.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
198
|
.hx-work { height: 44px; min-width: 44px; justify-content: center; padding: 0 var(--corn-space-3); }
|
|
@@ -969,6 +968,8 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
|
|
|
969
968
|
/* ---- the node panel (panels.js, #138): type · name · one line · facts · mockups · threads · the diff · the actions ------------ */
|
|
970
969
|
.hx-drawer-id { flex: 1; min-width: 0; }
|
|
971
970
|
.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); }
|
|
971
|
+
/* The badge carries a project's own kind ("Service · timer", spec 0009): a long one wraps inside the panel, never past it */
|
|
972
|
+
.hx-kicker [data-corn="badge"] { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
|
|
972
973
|
#drawer-host { white-space: pre; } /* the kicker is a flex row, which drops a leading space: keep " · host" */
|
|
973
974
|
.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
975
|
.hx-drawer-id .hx-drawer-title { font-size: var(--corn-text-xl); font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
|
|
@@ -1284,6 +1285,31 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
|
|
|
1284
1285
|
.hx-player-speed[data-corn="control"] { color: var(--corn-text); }
|
|
1285
1286
|
/* ==== end of the player bar ===================================================================================================== */
|
|
1286
1287
|
|
|
1288
|
+
/* ---------------------------------------------------------------------------
|
|
1289
|
+
Project layers and finer kinds (spec 0009): the Layers menu holds its title (with All and None) while the rows scroll, the Overlays heading,
|
|
1290
|
+
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.
|
|
1291
|
+
--------------------------------------------------------------------------- */
|
|
1292
|
+
.hx-layers .hx-menu { display: flex; flex-direction: column; overflow: hidden; }
|
|
1293
|
+
.hx-layers .hx-menu[hidden] { display: none; }
|
|
1294
|
+
.hx-layers .hx-menu-head { flex: none; }
|
|
1295
|
+
.hx-menu-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
|
|
1296
|
+
.hx-overlays { margin-top: var(--corn-space-3); padding-top: var(--corn-space-3); border-top: var(--corn-border) solid var(--corn-line); }
|
|
1297
|
+
.hx-layer-note { font-size: var(--corn-text-2xs); }
|
|
1298
|
+
.hx-kinds { padding: 0 var(--corn-space-3) var(--corn-space-1) var(--corn-space-5); }
|
|
1299
|
+
.hx-kinds-btn { display: inline-flex; align-items: center; gap: var(--corn-space-1); }
|
|
1300
|
+
.hx-kind-keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: calc(var(--corn-space-1) / 2); }
|
|
1301
|
+
.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); }
|
|
1302
|
+
.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; }
|
|
1303
|
+
.hx-kind-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
|
1304
|
+
@media (max-width: 767px) {
|
|
1305
|
+
/* On a phone the menu spans the screen, at most 70% of its height */
|
|
1306
|
+
.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; }
|
|
1307
|
+
/* 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 */
|
|
1308
|
+
.hx-header:has(.hx-layers .hx-menu:not([hidden])) { z-index: 46; }
|
|
1309
|
+
.hx-kinds-btn { min-height: 44px; }
|
|
1310
|
+
}
|
|
1311
|
+
/* ==== end of project layers and finer kinds ============================================================================================ */
|
|
1312
|
+
|
|
1287
1313
|
/* ==========================================================================
|
|
1288
1314
|
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
1315
|
========================================================================== */
|
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
|
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/layer-model
|
|
3
|
+
*
|
|
4
|
+
* Which layer a node is in, as the Layers menu and the map read it (spec 0009 D3), from the state alone: no DOM, no drawing.
|
|
5
|
+
*
|
|
6
|
+
* - `projectLayerKey(state, node)`: the first project layer (`state.projectLayers`, from the config's `layers.add`) whose match the node
|
|
7
|
+
* meets, or null. A project layer takes its nodes from their starting layer, so a node is in exactly one row.
|
|
8
|
+
* - `rowKeyOf(state, node)`: the row a node is under: that layer, else its starting layer. The root has none (null).
|
|
9
|
+
* - `shownByProposal(state, node)`: a node the open proposal touches is always drawn, whatever its layer says, so a review never hides its
|
|
10
|
+
* own change.
|
|
11
|
+
*
|
|
12
|
+
* The matching itself is core/layers.js (data only); this file only hands it the map's ownership line.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { kindLetters, layerKeyOf, parentIndex, projectLayerOf } from '../core/layers.js';
|
|
16
|
+
import { touchedIds } from './proposal-model.js';
|
|
17
|
+
|
|
18
|
+
/** Asks the ownership line of the map the state holds, only when a layer matches by `parent` */
|
|
19
|
+
const parentFn = (state) => ((state.projectLayers || []).some((l) => l.match && l.match.parent !== undefined) ? (n) => parentIndex(state.edges || []).get(n.id) : undefined);
|
|
20
|
+
|
|
21
|
+
/** The key of the project layer that takes `node`, or null */
|
|
22
|
+
export function projectLayerKey(state, node) {
|
|
23
|
+
const add = state.projectLayers;
|
|
24
|
+
if (!add || !add.length) return null;
|
|
25
|
+
return projectLayerOf(add, node, parentFn(state));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The key of the row `node` is under (null for the root) */
|
|
29
|
+
export const rowKeyOf = (state, node) => layerKeyOf(state.projectLayers || [], node, parentFn(state));
|
|
30
|
+
|
|
31
|
+
const touchedMemo = new WeakMap();
|
|
32
|
+
/** The ids of the nodes the open proposal touches: a node it marks, and both ends of an edge it marks (what Diff keeps bright) */
|
|
33
|
+
function touchedBy(state) {
|
|
34
|
+
const edges = state.edges || [];
|
|
35
|
+
const hit = touchedMemo.get(state.nodes);
|
|
36
|
+
if (hit && hit.edges === edges && hit.n === state.nodes.length && hit.e === edges.length) return hit.touched;
|
|
37
|
+
const touched = touchedIds(state.nodes, edges).touched;
|
|
38
|
+
touchedMemo.set(state.nodes, { edges, n: state.nodes.length, e: edges.length, touched });
|
|
39
|
+
return touched;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Whether the open proposal touches `node` (false with no proposal open) */
|
|
43
|
+
export const shownByProposal = (state, node) => !!state.proposal && touchedBy(state).has(node.id);
|
|
44
|
+
|
|
45
|
+
const lettersMemo = new WeakMap();
|
|
46
|
+
/**
|
|
47
|
+
* The letters of the node's finer kind (core/layers.js `kindLetters`, over the whole map so two kinds of a type never share one), or ''.
|
|
48
|
+
* An outside node's kind is its layer (cloud or web), not a finer one.
|
|
49
|
+
*/
|
|
50
|
+
export function lettersOf(state, node) {
|
|
51
|
+
if (typeof node.kind !== 'string' || !node.kind || node.type === 'external') return '';
|
|
52
|
+
let hit = lettersMemo.get(state.nodes);
|
|
53
|
+
if (!hit || hit.n !== state.nodes.length) {
|
|
54
|
+
hit = { n: state.nodes.length, map: kindLetters(state.nodes) };
|
|
55
|
+
lettersMemo.set(state.nodes, hit);
|
|
56
|
+
}
|
|
57
|
+
const t = hit.map.get(node.type);
|
|
58
|
+
return (t && t.get(node.kind)) || '';
|
|
59
|
+
}
|