@altnovatrail/skill-map 0.0.0-stage → 0.1.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.
@@ -0,0 +1,185 @@
1
+ // The element's styles: one constructed sheet, which the shadow root adopts. No <style> and no
2
+ // attribute style in the tree, so that a consumer's CSP lets them through without 'unsafe-inline'
3
+ // (the second amendment of 2026-11-02 to R36 spec; R09 in docs/decisions.md).
4
+ //
5
+ // The look holds the standard of the packages of the interface, WCAG 2.2 AA with 2.5.5 and 2.3.3
6
+ // (R90 spec; R10). The theme is the consumer's, by three custom properties the shadow tree
7
+ // inherits: --novatrail-skill-map-paper, the map's ground, --novatrail-skill-map-ink, its text,
8
+ // frames and icons, and --novatrail-skill-map-accent, the expanded tile, the frames of the tiles
9
+ // linked to it, the details and the ring of the focus. Their defaults stand in each var(), not in
10
+ // :host: a declaration there would set the property on the host, and a value the page gives the
11
+ // host's ancestors would never reach the shadow tree. A value that is not a colour gives none: the
12
+ // property is then as if unset, and the text takes the host's colour, the ground none. A state has
13
+ // no colour of its own: its word and its icon name it (1.4.1). With forced colours the system's
14
+ // colours stand in for the theme. The expanded skill's lines lie under the bands, in the accent,
15
+ // and their places are attributes of SVG (R11). Nothing moves: no transition and no animation, the
16
+ // lines' too, so there is nothing for prefers-reduced-motion to stop. The size of text is the consumer's, in em and rem,
17
+ // and a target is 44 by 44 CSS pixels at least.
18
+ /** The defaults of the theme: light, as canvas's. The accent is 6.7:1 against the paper. */
19
+ const PAPER = "#fff";
20
+ const INK = "#111";
21
+ const ACCENT = "#1d4ed8";
22
+ const paper = `var(--novatrail-skill-map-paper, ${PAPER})`;
23
+ const ink = `var(--novatrail-skill-map-ink, ${INK})`;
24
+ const accent = `var(--novatrail-skill-map-accent, ${ACCENT})`;
25
+ const CSS = `
26
+ :host {
27
+ display: block;
28
+ }
29
+ :host([hidden]) {
30
+ display: none;
31
+ }
32
+ .map {
33
+ position: relative;
34
+ background: ${paper};
35
+ color: ${ink};
36
+ overflow-wrap: anywhere;
37
+ }
38
+ /* The lines fill the map under its bands: a band is positioned, and comes after them. */
39
+ /* The lines are drawn in the colour of .lines, the accent, and so fall back to the ink when the
40
+ accent is no colour, as the tiles do. */
41
+ .lines {
42
+ color: ${accent};
43
+ position: absolute;
44
+ inset: 0;
45
+ width: 100%;
46
+ height: 100%;
47
+ overflow: visible;
48
+ pointer-events: none;
49
+ }
50
+ .lines path {
51
+ fill: none;
52
+ stroke: currentColor;
53
+ stroke-width: 2px;
54
+ }
55
+ .lines circle {
56
+ fill: currentColor;
57
+ }
58
+ .band {
59
+ position: relative;
60
+ }
61
+ .band > :is(h2, h3, h4, h5, h6) {
62
+ margin: 1rem 0 0.5rem;
63
+ }
64
+ .band > ul {
65
+ display: flex;
66
+ flex-wrap: wrap;
67
+ gap: 0.5rem;
68
+ margin: 0;
69
+ padding: 0;
70
+ list-style: none;
71
+ }
72
+ .band > ul > li {
73
+ max-width: 100%;
74
+ }
75
+ /* The parts of a tile stay inline: a block or an element out of the flow would put a space into
76
+ its accessible name, "Quarters , Locked" (R09). */
77
+ .tile,
78
+ .practise {
79
+ box-sizing: border-box;
80
+ min-width: 44px;
81
+ min-height: 44px;
82
+ max-width: 100%;
83
+ margin: 0;
84
+ padding: 0.5rem 0.75rem;
85
+ font: inherit;
86
+ line-height: 1.4;
87
+ text-align: start;
88
+ border-radius: 0.5rem;
89
+ cursor: pointer;
90
+ }
91
+ .tile {
92
+ color: inherit;
93
+ background: ${paper};
94
+ border: 1px solid currentColor;
95
+ }
96
+ .tile .title {
97
+ font-weight: 600;
98
+ }
99
+ .tile.locked {
100
+ border-style: dashed;
101
+ }
102
+ .tile.linked {
103
+ border-width: 2px;
104
+ border-color: ${accent};
105
+ padding: calc(0.5rem - 1px) calc(0.75rem - 1px);
106
+ }
107
+ .tile[aria-expanded="true"] {
108
+ color: ${paper};
109
+ background: ${accent};
110
+ border-color: ${accent};
111
+ }
112
+ .tile:focus-visible,
113
+ .practise:focus-visible {
114
+ outline: 3px solid ${accent};
115
+ outline-offset: 2px;
116
+ }
117
+ .icon {
118
+ width: 1.25em;
119
+ height: 1.25em;
120
+ margin-inline-end: 0.25em;
121
+ vertical-align: -0.3em;
122
+ fill: currentColor;
123
+ }
124
+ .details {
125
+ box-sizing: border-box;
126
+ flex-basis: 100%;
127
+ padding: 0.75rem;
128
+ background: ${paper};
129
+ border: 2px solid ${accent};
130
+ border-radius: 0.5rem;
131
+ }
132
+ .details p,
133
+ .details ul {
134
+ margin: 0 0 0.5rem;
135
+ }
136
+ .details ul {
137
+ padding-inline-start: 1.5em;
138
+ }
139
+ .practise {
140
+ color: ${paper};
141
+ background: ${accent};
142
+ border: 1px solid ${accent};
143
+ }
144
+ @media (forced-colors: active) {
145
+ .map,
146
+ .details {
147
+ background: Canvas;
148
+ color: CanvasText;
149
+ }
150
+ .details {
151
+ border-color: CanvasText;
152
+ }
153
+ .tile,
154
+ .practise {
155
+ background: ButtonFace;
156
+ color: ButtonText;
157
+ border-color: ButtonBorder;
158
+ }
159
+ .tile.linked {
160
+ border-color: Highlight;
161
+ }
162
+ .tile[aria-expanded="true"] {
163
+ background: Highlight;
164
+ color: HighlightText;
165
+ border-color: Highlight;
166
+ }
167
+ .tile:focus-visible,
168
+ .practise:focus-visible {
169
+ outline-color: Highlight;
170
+ }
171
+ /* The lines take the system's highlight, as the frames of the tiles they link do. */
172
+ .lines {
173
+ color: Highlight;
174
+ }
175
+ }
176
+ `;
177
+ let sheet;
178
+ /** The sheet of this copy of the module, made once, the first time an element needs it. */
179
+ export function styles() {
180
+ if (sheet === undefined) {
181
+ sheet = new CSSStyleSheet();
182
+ sheet.replaceSync(CSS);
183
+ }
184
+ return sheet;
185
+ }
@@ -0,0 +1,31 @@
1
+ import type { GetSkillMapResponse } from "@altnovatrail/contracts/novatrail/api/v1/progress_pb.js";
2
+ import type { Manifest, SkillGraph } from "@altnovatrail/spec/formatv0/open";
3
+ import type { View } from "../core/attributes.js";
4
+ import { type Words } from "./words.js";
5
+ /** What the tree is drawn from. */
6
+ export interface MapData {
7
+ readonly graph: SkillGraph;
8
+ readonly tiers: Readonly<Record<string, number>>;
9
+ readonly manifest: Manifest;
10
+ readonly skillMap: GetSkillMapResponse | null;
11
+ readonly view: View | null;
12
+ readonly headingLevel: number;
13
+ readonly now: Date;
14
+ readonly words: Words;
15
+ }
16
+ /** The tree of one element's map. */
17
+ export declare class MapTree {
18
+ #private;
19
+ constructor(root: ShadowRoot, choose: (skill: string) => void);
20
+ /**
21
+ * The element is on a page: the map, the details and each tile are watched from now on. A node
22
+ * starts to be watched with a first notice, which draws the lines anew.
23
+ */
24
+ connect(): void;
25
+ /** The element is off the page: nothing is watched until it is back. */
26
+ disconnect(): void;
27
+ /** Draws the map from new data, or clears it without any. */
28
+ render(data: MapData | null): void;
29
+ }
30
+ /** A template's text with its places filled: {name} by text or by a node. */
31
+ export declare function fill(template: string, values: Readonly<Record<string, string | Node | readonly (string | Node)[]>>): (string | Node)[];
@@ -0,0 +1,454 @@
1
+ // The tree of the map in the element's shadow root (R06; docs/architecture.md, section 3.4): a band
2
+ // is a heading and a list of tiles, a tile is a button that expands the skill, and the details are
3
+ // an item of the list right after it. The tree is the map's text alternative too: the order of the
4
+ // DOM is the order on the screen. On new data it is updated in place, by the skill's ID, so that
5
+ // the focus and the expanded skill stay (the second amendment of 2026-11-07 to R04).
6
+ import { fullSkillId } from "../core/index.js";
7
+ import { focusAfter, layout, linksOf } from "../core/layout.js";
8
+ import { linesOf } from "../core/lines.js";
9
+ import { mapStates } from "../core/states.js";
10
+ import { ANCHOR_TITLES } from "./anchor-titles.js";
11
+ import { ICONS } from "./icons.js";
12
+ import { Lines, SVG } from "./lines.js";
13
+ import { formatsOf, formOf } from "./words.js";
14
+ /** The ID of the details, the one item that a tile's aria-controls names. */
15
+ const DETAILS = "details";
16
+ /** The tree of one element's map. */
17
+ export class MapTree {
18
+ #root;
19
+ #choose;
20
+ #container;
21
+ #bands = new Map();
22
+ #tiles = new Map();
23
+ /** The skill of each node the focus can be on: a tile, or the button «Practise». */
24
+ #skillOf = new WeakMap();
25
+ #details;
26
+ #practise;
27
+ #expanded = null;
28
+ /** The full ID of the skill «Practise» chooses, set when it is drawn. */
29
+ #chosen = "";
30
+ #layout = null;
31
+ /** Each icon, built once from its paths, and cloned wherever it stands. */
32
+ #icons = new Map();
33
+ #data = null;
34
+ /** The expanded skill's links, which its lines are drawn by, or null with none expanded. */
35
+ #links = null;
36
+ #lines;
37
+ /**
38
+ * Draws the lines anew whenever the map, a tile or the details changes its size: the width of the
39
+ * page, its zoom, a font that came late (R11). It watches only while the element is on a page.
40
+ */
41
+ #observer = new ResizeObserver(() => {
42
+ if (this.#expanded !== null)
43
+ this.#drawLines();
44
+ });
45
+ #connected = false;
46
+ constructor(root, choose) {
47
+ this.#root = root;
48
+ this.#choose = choose;
49
+ this.#container = root.ownerDocument.createElement("div");
50
+ this.#container.className = "map";
51
+ this.#details = this.#element("li", "details");
52
+ this.#details.id = DETAILS;
53
+ this.#practise = this.#element("button", "practise");
54
+ this.#practise.type = "button";
55
+ this.#practise.addEventListener("click", () => this.#choose(this.#chosen));
56
+ this.#lines = new Lines(root.ownerDocument);
57
+ root.append(this.#container);
58
+ }
59
+ /**
60
+ * The element is on a page: the map, the details and each tile are watched from now on. A node
61
+ * starts to be watched with a first notice, which draws the lines anew.
62
+ */
63
+ connect() {
64
+ this.#connected = true;
65
+ this.#observer.observe(this.#container);
66
+ this.#observer.observe(this.#details);
67
+ for (const { button } of this.#tiles.values())
68
+ this.#observer.observe(button);
69
+ }
70
+ /** The element is off the page: nothing is watched until it is back. */
71
+ disconnect() {
72
+ this.#connected = false;
73
+ this.#observer.disconnect();
74
+ }
75
+ /** Draws the map from new data, or clears it without any. */
76
+ render(data) {
77
+ const active = this.#root.activeElement;
78
+ const focused = active === null ? undefined : this.#skillOf.get(active);
79
+ const before = this.#layout;
80
+ this.#data = data;
81
+ if (data === null) {
82
+ this.#container.replaceChildren();
83
+ this.#bands.clear();
84
+ for (const { button } of this.#tiles.values())
85
+ this.#observer.unobserve(button);
86
+ this.#tiles.clear();
87
+ this.#expanded = null;
88
+ this.#layout = null;
89
+ this.#links = null;
90
+ return;
91
+ }
92
+ // The package's words are of their own language, which the titles' lang overrides (3.1.2).
93
+ this.#container.lang = data.words.lang;
94
+ const map = layout(data.graph, data.tiers);
95
+ const states = mapStates(data.graph, data.skillMap, data.now);
96
+ if (this.#expanded !== null && !map.places.has(this.#expanded))
97
+ this.#expanded = null;
98
+ const links = this.#expanded === null ? null : linksOf(data.graph, map, this.#expanded);
99
+ const sections = [];
100
+ const bandsUsed = new Set();
101
+ const tilesUsed = new Set();
102
+ for (const band of map.bands) {
103
+ const key = band.kind === "anchors" ? "anchors" : `tier ${band.tier}`;
104
+ bandsUsed.add(key);
105
+ const nodes = this.#band(key, band, data);
106
+ const items = [];
107
+ for (const id of band.skills) {
108
+ tilesUsed.add(id);
109
+ const tile = this.#tile(id);
110
+ this.#drawTile(tile, id, band, states, links, data);
111
+ items.push(tile.item);
112
+ if (id === this.#expanded) {
113
+ this.#drawDetails(id, band, states, links ?? linksOf(data.graph, map, id), data);
114
+ items.push(this.#details);
115
+ }
116
+ }
117
+ place(nodes.list, items);
118
+ sections.push(nodes.section);
119
+ }
120
+ // The lines lie under the bands: first in the map, and drawn once the tiles have their places.
121
+ place(this.#container, [this.#lines.svg, ...sections]);
122
+ for (const key of [...this.#bands.keys()])
123
+ if (!bandsUsed.has(key))
124
+ this.#bands.delete(key);
125
+ for (const [id, { button }] of [...this.#tiles]) {
126
+ if (!tilesUsed.has(id)) {
127
+ this.#observer.unobserve(button);
128
+ this.#tiles.delete(id);
129
+ }
130
+ }
131
+ this.#layout = map;
132
+ this.#links = links;
133
+ this.#drawLines();
134
+ // A node the focus was on stays focused where it still is, though it was moved; one that is
135
+ // gone hands the focus to a tile by R06.
136
+ if (active instanceof HTMLElement && focused !== undefined) {
137
+ if (active.isConnected && active.getRootNode() === this.#root) {
138
+ if (this.#root.activeElement !== active)
139
+ active.focus({ preventScroll: true });
140
+ }
141
+ else if (before !== null) {
142
+ const target = focusAfter(before, map, focused);
143
+ if (target !== null)
144
+ this.#tiles.get(target)?.button.focus({ preventScroll: true });
145
+ }
146
+ }
147
+ }
148
+ /** The expanded skill's lines, by the places of the tiles as they are measured now (R11). */
149
+ #drawLines() {
150
+ const expanded = this.#expanded;
151
+ const links = this.#links;
152
+ if (expanded === null || links === null || !this.#connected) {
153
+ this.#lines.draw([]);
154
+ return;
155
+ }
156
+ const origin = this.#container.getBoundingClientRect();
157
+ const box = (node) => {
158
+ const { left, top, right, bottom } = node.getBoundingClientRect();
159
+ return {
160
+ left: left - origin.left,
161
+ top: top - origin.top,
162
+ right: right - origin.left,
163
+ bottom: bottom - origin.top,
164
+ };
165
+ };
166
+ // The links name tiles of the layout just drawn, and an expanded skill has its details there.
167
+ const boxes = new Map([expanded, ...links.buildsOn, ...links.opens].map((id) => [
168
+ id,
169
+ box(this.#tiles.get(id).button),
170
+ ]));
171
+ this.#lines.draw(linesOf(expanded, links, boxes, box(this.#details)));
172
+ }
173
+ #band(key, band, data) {
174
+ let nodes = this.#bands.get(key);
175
+ if (nodes === undefined) {
176
+ const section = this.#element("section", "band");
177
+ const list = this.#element("ul");
178
+ nodes = { section, heading: this.#element("h3"), list };
179
+ section.append(nodes.heading, list);
180
+ this.#bands.set(key, nodes);
181
+ }
182
+ const tag = `H${data.headingLevel}`;
183
+ if (nodes.heading.tagName !== tag) {
184
+ const heading = this.#element(`h${data.headingLevel}`);
185
+ nodes.heading.replaceWith(heading);
186
+ nodes.heading = heading;
187
+ }
188
+ const { words } = data;
189
+ nodes.heading.replaceChildren(...(band.kind === "anchors"
190
+ ? [words.anchors]
191
+ : band.name === null
192
+ ? fill(words.tier, { tier: String(band.tier) })
193
+ : fill(words.tierNamed, {
194
+ tier: String(band.tier),
195
+ name: this.#text("span", band.name, data.manifest.languages.explanation),
196
+ })));
197
+ return nodes;
198
+ }
199
+ #tile(id) {
200
+ let nodes = this.#tiles.get(id);
201
+ if (nodes === undefined) {
202
+ const item = this.#element("li");
203
+ const button = this.#element("button", "tile");
204
+ button.type = "button";
205
+ button.addEventListener("click", () => {
206
+ this.#expanded = this.#expanded === id ? null : id;
207
+ this.render(this.#data);
208
+ });
209
+ this.#skillOf.set(button, id);
210
+ if (this.#connected)
211
+ this.#observer.observe(button);
212
+ item.append(button);
213
+ nodes = { item, button };
214
+ this.#tiles.set(id, nodes);
215
+ }
216
+ return nodes;
217
+ }
218
+ #drawTile(tile, id, band, states, links, data) {
219
+ const { words } = data;
220
+ const parts = [];
221
+ const skill = states.skills.get(id);
222
+ const value = band.kind === "anchors"
223
+ ? (states.anchors.get(id)?.holding ?? null)
224
+ : skill === undefined
225
+ ? null
226
+ : shownOf(skill);
227
+ if (value !== null)
228
+ parts.push(this.#status(value, words));
229
+ const linked = links?.buildsOn.includes(id) || links?.opens.includes(id) || false;
230
+ if (links?.buildsOn.includes(id))
231
+ parts.push(this.#text("span", words.neededBefore));
232
+ if (links?.opens.includes(id))
233
+ parts.push(this.#text("span", words.opensAfter));
234
+ tile.button.replaceChildren(this.#title(id, band.kind === "anchors", data), ...parts.flatMap((part) => [words.separator, part]));
235
+ // Marks of the look beside the words: a locked tile's frame is dashed, a linked one's thicker.
236
+ tile.button.classList.toggle("locked", value === "locked");
237
+ tile.button.classList.toggle("linked", linked);
238
+ const expanded = id === this.#expanded;
239
+ tile.button.setAttribute("aria-expanded", String(expanded));
240
+ if (expanded)
241
+ tile.button.setAttribute("aria-controls", DETAILS);
242
+ else
243
+ tile.button.removeAttribute("aria-controls");
244
+ }
245
+ #drawDetails(id, band, states, links, data) {
246
+ const { words, graph } = data;
247
+ const content = [this.#paragraph([this.#title(id, band.kind === "anchors", data)])];
248
+ let action = null;
249
+ if (band.kind === "anchors") {
250
+ const anchor = states.anchors.get(id);
251
+ if (anchor !== undefined && anchor.holding !== null) {
252
+ const holding = this.#status(anchor.holding, words);
253
+ content.push(this.#paragraph(anchorPhrase(holding, anchor, words)));
254
+ }
255
+ content.push(...this.#list(words.neededBy, links.opens, data));
256
+ }
257
+ else {
258
+ const skill = states.skills.get(id);
259
+ const description = graph.skills[id]?.description;
260
+ if (description !== undefined) {
261
+ content.push(this.#paragraph([this.#text("span", description, data.manifest.languages.explanation)]));
262
+ }
263
+ const value = skill === undefined ? null : shownOf(skill);
264
+ if (value !== null)
265
+ content.push(this.#paragraph([this.#status(value, words)]));
266
+ content.push(...this.#list(words.buildsOn, links.buildsOn, data, skill?.waitsFor));
267
+ content.push(...this.#list(words.opens, links.opens, data));
268
+ content.push(...this.#teaches(links.teaches, states, data));
269
+ // GetSkillMap gives state only to a skill of verdict: one of rubric or none has no numbers.
270
+ if (data.view === "adult" && data.skillMap !== null && skill?.assessability === "verdict") {
271
+ content.push(...this.#numbers(skill.record, data));
272
+ }
273
+ if (data.view === "learner" && data.skillMap !== null && skill !== undefined) {
274
+ if (skill.open) {
275
+ this.#practise.textContent = words.practise;
276
+ this.#skillOf.set(this.#practise, id);
277
+ this.#chosen = fullSkillId(data.manifest.id, id);
278
+ action = this.#practise;
279
+ }
280
+ else {
281
+ // In the order of the layout, as Builds on: the order of the graph carries no meaning.
282
+ const waiting = links.buildsOn.filter((other) => skill.waitsFor.includes(other));
283
+ action = this.#paragraph(fill(words.waitsFor, { skills: this.#titles(waiting, data) }));
284
+ }
285
+ }
286
+ }
287
+ // The button «Practise» stays where it is while it stays: moving it would take the focus off it.
288
+ if (action === this.#practise && this.#practise.parentNode === this.#details) {
289
+ for (const child of [...this.#details.childNodes])
290
+ if (child !== this.#practise)
291
+ child.remove();
292
+ this.#practise.before(...content);
293
+ }
294
+ else {
295
+ this.#details.replaceChildren(...content, ...(action === null ? [] : [action]));
296
+ }
297
+ }
298
+ /** A part of the details: a label and the titles of the tiles it names, if there are any. */
299
+ #list(label, ids, data, notMastered = []) {
300
+ if (ids.length === 0)
301
+ return [];
302
+ const list = this.#element("ul");
303
+ for (const id of ids) {
304
+ const item = this.#element("li");
305
+ const title = this.#title(id, !Object.hasOwn(data.graph.skills, id), data);
306
+ item.append(...(notMastered.includes(id) ? fill(data.words.notMastered, { skill: title }) : [title]));
307
+ list.append(item);
308
+ }
309
+ return [this.#paragraph([label]), list];
310
+ }
311
+ /** What a skill teaches: each anchor skill of its teaches, with its holding if there is one. */
312
+ #teaches(ids, states, data) {
313
+ if (ids.length === 0)
314
+ return [];
315
+ const list = this.#element("ul");
316
+ for (const id of ids) {
317
+ const item = this.#element("li");
318
+ const title = this.#title(id, true, data);
319
+ const anchor = states.anchors.get(id);
320
+ item.append(...(anchor === undefined || anchor.holding === null
321
+ ? [title]
322
+ : fill(data.words.taught, {
323
+ skill: title,
324
+ holding: anchorPhrase(this.#status(anchor.holding, data.words), anchor, data.words),
325
+ })));
326
+ list.append(item);
327
+ }
328
+ return [this.#paragraph([data.words.teaches]), list];
329
+ }
330
+ /** The adult's details of a skill of verdict (R03): no estimate, uncertainty or retention. */
331
+ #numbers(state, data) {
332
+ const { words, manifest } = data;
333
+ const formats = formatsOf(words);
334
+ const count = state?.evidenceCount ?? 0;
335
+ const lines = [
336
+ fill(formOf(words.evidence, count, formats), { count: formats.number.format(count) }),
337
+ ];
338
+ if (state?.lastPracticedAt !== undefined) {
339
+ lines.push(fill(words.lastPractised, { date: formats.date.format(dateOf(state.lastPracticedAt)) }));
340
+ }
341
+ if (state !== undefined && state.masteryBand !== "") {
342
+ const band = manifest.bands?.find(({ id }) => id === state.masteryBand);
343
+ const title = band === undefined
344
+ ? state.masteryBand
345
+ : this.#text("span", band.title, manifest.languages.explanation);
346
+ lines.push(fill(words.band, { band: title }));
347
+ if (state.reviewDue)
348
+ lines.push([words.reviewDue]);
349
+ else if (state.reviewDate !== undefined)
350
+ lines.push(fill(words.reviewOn, { date: formats.date.format(dateOf(state.reviewDate)) }));
351
+ }
352
+ return lines.map((line) => this.#paragraph(line));
353
+ }
354
+ /** The title of a skill of the module in its language, or an anchor skill's in English (R04). */
355
+ #title(id, anchor, data) {
356
+ return anchor
357
+ ? this.#text("span", ANCHOR_TITLES[id] ?? id, "en", "title")
358
+ : this.#text("span", data.graph.skills[id]?.title ?? id, data.manifest.languages.explanation, "title");
359
+ }
360
+ /** The titles of skills of the module, as a list of the words' language. */
361
+ #titles(ids, data) {
362
+ return formatsOf(data.words)
363
+ .list.formatToParts(ids)
364
+ .map((part) => part.type === "element"
365
+ ? this.#title(part.value, false, data)
366
+ : this.#root.ownerDocument.createTextNode(part.value));
367
+ }
368
+ /**
369
+ * A state, a mark or a holding: its icon, then its word, which names it (R90 spec). The icon is
370
+ * hidden from the tree of accessibility and has no title, and it is drawn in the text's colour,
371
+ * by attributes of SVG alone: no attribute style (R78 spec; R09).
372
+ */
373
+ #status(value, words) {
374
+ let icon = this.#icons.get(value);
375
+ if (icon === undefined) {
376
+ const { viewBox, paths } = ICONS[value];
377
+ icon = this.#root.ownerDocument.createElementNS(SVG, "svg");
378
+ icon.setAttribute("class", "icon");
379
+ icon.setAttribute("viewBox", viewBox);
380
+ icon.setAttribute("aria-hidden", "true");
381
+ icon.setAttribute("focusable", "false");
382
+ for (const d of paths) {
383
+ const path = this.#root.ownerDocument.createElementNS(SVG, "path");
384
+ path.setAttribute("d", d);
385
+ icon.append(path);
386
+ }
387
+ this.#icons.set(value, icon);
388
+ }
389
+ const status = this.#element("span", "status");
390
+ status.append(icon.cloneNode(true), wordOf(value, words));
391
+ return status;
392
+ }
393
+ #paragraph(children) {
394
+ const paragraph = this.#element("p");
395
+ paragraph.append(...children);
396
+ return paragraph;
397
+ }
398
+ #text(tag, text, lang = null, name) {
399
+ const node = this.#element(tag, name);
400
+ node.textContent = text;
401
+ if (lang !== null)
402
+ node.lang = lang;
403
+ return node;
404
+ }
405
+ #element(tag, name) {
406
+ const node = this.#root.ownerDocument.createElement(tag);
407
+ if (name !== undefined)
408
+ node.className = name;
409
+ return node;
410
+ }
411
+ }
412
+ /** Puts the children of a node in order, moving only those that are not where they belong. */
413
+ function place(parent, children) {
414
+ children.forEach((child, index) => {
415
+ const there = parent.children[index];
416
+ if (there !== child)
417
+ parent.insertBefore(child, there ?? null);
418
+ });
419
+ while (parent.children.length > children.length)
420
+ parent.lastElementChild?.remove();
421
+ }
422
+ /** A template's text with its places filled: {name} by text or by a node. */
423
+ export function fill(template, values) {
424
+ return template.split(/(\{[a-z]+\})/).flatMap((piece) => {
425
+ const value = /^\{([a-z]+)\}$/.exec(piece)?.[1];
426
+ if (value === undefined)
427
+ return piece === "" ? [] : [piece];
428
+ const filled = values[value] ?? piece;
429
+ return typeof filled === "string" || filled instanceof Node ? [filled] : [...filled];
430
+ });
431
+ }
432
+ /** A skill of the module's state or mark, or null on a map without state. */
433
+ function shownOf(skill) {
434
+ return skill.assessability !== "verdict" ? skill.assessability : skill.state;
435
+ }
436
+ /** The word of a state, a mark or a holding. */
437
+ function wordOf(value, words) {
438
+ const named = {
439
+ ...words.states,
440
+ ...words.marks,
441
+ ...words.holdings,
442
+ };
443
+ return named[value];
444
+ }
445
+ /** An anchor skill's holding — its word, or its icon and word — with its reason, if it has one. */
446
+ function anchorPhrase(holding, anchor, words) {
447
+ return anchor.reason === null
448
+ ? [holding]
449
+ : fill(words.holdingReason, { holding, reason: words.reasons[anchor.reason] });
450
+ }
451
+ /** A moment of the contract as a Date of the device. */
452
+ function dateOf(moment) {
453
+ return new Date(Number(moment.seconds) * 1000 + Math.floor(moment.nanos / 1_000_000));
454
+ }