@openbooknetwork/hesap 0.2.2 → 0.3.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.
@@ -1,10 +1,12 @@
1
- // The Node half of the counters family. The bonds scene moves counters between parts and fills ten frames, and the
2
- // count scene counts objects one by one. It checks a page's fields against its scene and says what each link shows
3
- // when the page opens.
1
+ // The Node half of the counters family. The bonds scene moves counters between parts and fills ten frames, the
2
+ // count scene counts objects one by one, and the match scene pairs two rows, and the order scene compares numbers. It checks a page's fields against its
3
+ // scene and says what each link shows when the page opens.
4
4
  import { schema } from '@openbooknetwork/kitap';
5
5
  import { LOOKS, modeOf, capOf, opening, counts, measuresOf } from './model.js';
6
6
  import { GOALS, challengeStart } from './goals.js';
7
7
  import count from './count.mjs';
8
+ import match from './match.mjs';
9
+ import order from './order.mjs';
8
10
  import { numbers } from '../../kit/format.js';
9
11
  import { list, challenge, drawn, value } from '../../node.mjs';
10
12
 
@@ -94,11 +96,12 @@ function startBonds(spec, lang, id) {
94
96
 
95
97
  // Each scene checks its own fields, so the family's schema lets every field through to the scene.
96
98
  const Fields = z.object({}).passthrough();
97
- const read = ({ scene, ...fields }, info, ctx) => scene === 'count' ? count.read(fields, info, ctx) : readBonds(fields, info, ctx);
98
- const start = (spec, lang, id) => spec.scene === 'count' ? count.start(spec, lang, id) : startBonds(spec, lang, id);
99
+ const SCENES = { bonds: { read: readBonds, start: startBonds }, count, match, order };
100
+ const read = ({ scene, ...fields }, info, ctx) => SCENES[scene].read(fields, info, ctx);
101
+ const start = (spec, lang, id) => SCENES[spec.scene].start(spec, lang, id);
99
102
 
100
103
  // The two colours of the counters, a red and a blue that readers with any colour vision tell apart, each with a step
101
104
  // for the dark themes.
102
105
  const bundle = () => ({ families: { 'counters-red': { color: '#d1453b', color_dark: '#f0776d' }, 'counters-blue': { color: '#2a6bd1', color_dark: '#6fa4f5' } } });
103
106
 
104
- export default { id: 'counters', scenes: ['bonds', 'count'], schema: Fields, read, start, bundle };
107
+ export default { id: 'counters', scenes: Object.keys(SCENES), schema: Fields, read, start, bundle };
@@ -0,0 +1,60 @@
1
+ // The places of a match figure: two rows of counters, or a tray of cups above a table of saucers. Each gives its
2
+ // size, the place of every object of the top and the bottom row, the height of the middle between the rows, and a
3
+ // draw for the parts that stay put.
4
+ import { svg as el } from '../../kit/dom.js';
5
+ import { R } from './counter.js';
6
+ import { txt } from './figures.js';
7
+
8
+ export const GAP = 40; // Counters of a row stand this far apart.
9
+ export const CLOSE = 33, WIDE = 40; // The gaps of the close and the wide row of a challenge.
10
+ const EDGE = 24; // The room round the rows, which holds a counter's touch target.
11
+ const DROP = 116; // The bottom row stands this far under the top row.
12
+
13
+ // rowsOf sets two rows out from the left. top and bottom are the most counters each row reaches. gap gives the gap
14
+ // of each row as it stands, and widest the greatest gap each row takes, which the figure keeps room for. tag is the
15
+ // room after the rows for the tag at a row's end, and names the room above and below them for a row's name. line
16
+ // is the width and the height of the line of two numbers under the rows, and the figure gives its place.
17
+ export function rowsOf({ top, bottom, gap = {}, widest = gap, tag = 0, names = 0, line = { w: 0, h: 0 } }) {
18
+ const room = { top, bottom };
19
+ const span = Math.max(...Object.keys(room).map(row => (Math.max(1, room[row]) - 1) * (widest[row] ?? GAP)));
20
+ const place = (row, y) => i => ({ x: EDGE + i * (gap[row] ?? GAP), y: y + names });
21
+ const h = DROP + 2 * EDGE + 2 * names;
22
+ return { w: Math.max(span + 2 * EDGE + tag, line.w + EDGE), h: h + line.h, mid: names + EDGE + DROP / 2, line: { x: EDGE - 16, y: h + line.h / 2 - 4 },
23
+ top: place('top', EDGE), bottom: place('bottom', EDGE + DROP), draw: () => ({ nodes: [] }) };
24
+ }
25
+
26
+ const CUP = 42, SAUCER = 58; // The cups of the tray and the saucers of the table stand this far apart.
27
+ const TRAY = 56, TABLE = 62; // The heights of the tray and the table.
28
+ const BETWEEN = 64; // The room between the tray and the table.
29
+
30
+ // cupsOf sets a tray of cups above a table of saucers. seat is the place of a cup that sits on a saucer.
31
+ export function cupsOf(top, bottom) {
32
+ const tw = Math.max(1, top) * CUP + 16, bw = Math.max(1, bottom) * SAUCER + 16, w = Math.max(tw, bw), ty = TRAY + BETWEEN;
33
+ const saucer = j => ({ x: (w - bw) / 2 + 8 + (j + 0.5) * SAUCER, y: ty + TABLE / 2 + 2 });
34
+ return {
35
+ w, h: ty + TABLE, mid: TRAY + BETWEEN / 2,
36
+ top: i => ({ x: (w - tw) / 2 + 8 + (i + 0.5) * CUP, y: TRAY / 2 }),
37
+ bottom: saucer,
38
+ seat: j => { const p = saucer(j); return { x: p.x, y: p.y - R * 0.85 }; },
39
+ draw: () => ({ nodes: [el('rect', { class: 'counters-tray', x: (w - tw) / 2, y: 0, width: tw, height: TRAY, rx: 12 }),
40
+ el('rect', { class: 'counters-table', x: (w - bw) / 2, y: ty, width: bw, height: TABLE, rx: 8 })] }),
41
+ };
42
+ }
43
+
44
+ export const BALL = 11; // The radius of a ball of the scoreboard.
45
+ // scoreOf sets a scoreboard out: the name and the score of two teams with a sign between the scores, and under
46
+ // each score room for max balls in rows of five. draw gives the board and the texts the scene writes: the two
47
+ // scores and the sign.
48
+ export function scoreOf(max, names) {
49
+ const w = 320, board = 132, half = w / 2, gap = 2 * BALL + 5, per = 5, rows = Math.ceil(max / per);
50
+ const ball = k => i => ({ x: (k + 0.5) * half + (i % per - (per - 1) / 2) * gap, y: board + 22 + Math.floor(i / per) * gap });
51
+ return {
52
+ w, h: board + 22 + (rows - 1) * gap + BALL + 6, mid: board / 2, top: ball(0), bottom: ball(1),
53
+ draw() {
54
+ const side = ['top', 'bottom'].map((r, k) => ({ name: txt(`counters-team counters-${k ? 'b' : 'a'}`, (k + 0.5) * half + (k ? 14 : -14), 28, names[k]), score: txt('counters-score', (k + 0.5) * half + (k ? 14 : -14), 84) }));
55
+ for (const [k, r] of ['top', 'bottom'].entries()) side[k].score.setAttribute('data-ref', r);
56
+ const sign = txt('counters-score-sign', half, 84);
57
+ return { nodes: [el('rect', { class: 'counters-board', x: 0, y: 0, width: w, height: board, rx: 14 }), ...side.flatMap(t => [t.name, t.score]), sign], refs: { top: side[0].score, bottom: side[1].score, sign } };
58
+ },
59
+ };
60
+ }
@@ -0,0 +1,63 @@
1
+ // The goals a match page can name. The page declares ranges, and the goal draws two rows from them each time the
2
+ // page opens and each time the reader asks for another one. One of the rows stands wide and the other close, so the
3
+ // ends of the rows say nothing about their numbers. The build and the browser both use this file.
4
+ import { SIGNS, signOf } from './reading.js';
5
+
6
+ export const STEP = [0, 12]; // The stepper of the top row on a challenge page.
7
+ const TOPS = [1, 10], BOTTOMS = [3, 10], ROWS = [1, 10]; // The widest ranges a page may draw its rows from.
8
+ const span = ([lo, hi]) => Array.from({ length: Math.max(0, hi - lo + 1) }, (_, i) => lo + i);
9
+ const range = (r, [lo, hi]) => Array.isArray(r) && r.length === 2 && r.every(Number.isInteger) && r[0] <= r[1] && r[0] >= lo && r[1] <= hi;
10
+ const words = r => JSON.stringify(r ?? null);
11
+ // The two rows of a goal whose top row the reader steps: every pair of the page's ranges that fits.
12
+ const pairs = (c, fits) => span(c.bottom).flatMap(bottom => span(c.top).filter(top => fits(top, bottom)).map(top => ({ top, bottom })));
13
+ const ranges = c => !range(c.top, TOPS) ? `top is ${words(c.top)}, write the top row's range as [low, high] from ${TOPS[0]} to ${TOPS[1]}, such as [1, 10]`
14
+ : !range(c.bottom, BOTTOMS) ? `bottom is ${words(c.bottom)}, write the bottom row's range as [low, high] from ${BOTTOMS[0]} to ${BOTTOMS[1]}, such as [3, 10]` : null;
15
+ const extra = (c, names) => { const f = Object.keys(c).find(k => k !== 'goal' && !names.includes(k)); return f ? `${f} belongs to another goal, this one draws from ${names.join(' and ')}` : null; };
16
+ // A goal the reader reaches with the top row's stepper opens with that stepper and no lines.
17
+ const stepped = (fits, off) => ({
18
+ scenes: ['match'],
19
+ problem(c) {
20
+ const stop = extra(c, ['top', 'bottom']) ?? ranges(c);
21
+ return stop ?? (pairs(c, fits).length ? null : 'top and bottom leave no two rows to draw, widen one of them');
22
+ },
23
+ draw(c, spec, dice) { const all = pairs(c, fits); return all.length ? { ...dice.pick(all), wide: dice.pick(['top', 'bottom']) } : null; },
24
+ page: t => ({ top: t.top, bottom: t.bottom, wide: t.wide, topCtl: { kind: 'stepper', lo: STEP[0], hi: STEP[1] } }),
25
+ holds: (state, spec, c, t) => !state.checked ? { done: false } : off(state.top, state.bottom),
26
+ });
27
+
28
+ export const MATCH_GOALS = {
29
+ // The reader steps the top row until it has as many counters as the bottom row. A wrong check names the row that
30
+ // has counters without a partner.
31
+ 'same-rows': stepped((top, bottom) => top !== bottom, (top, bottom) => top === bottom ? { done: true } : { done: false, note: top > bottom ? 'top' : 'bottom' }),
32
+ // The reader steps the top row until it has one counter fewer than the bottom row. Once it has, each row shows
33
+ // its number at its end.
34
+ 'one-less': { ...stepped((top, bottom) => top !== bottom - 1, (top, bottom) => top === bottom - 1 ? { done: true } : { done: false, note: top > bottom - 1 ? 'over' : 'short' }), ends: true },
35
+ // Two rows show no numbers, and the reader sets the sign between them. Each of the three signs is the true one in
36
+ // one draw of three, and the tile opens on one of the two false signs. A wrong check says in which direction the
37
+ // top row is off, with the signs in the order <, =, >.
38
+ 'right-sign': {
39
+ scenes: ['match'],
40
+ problem(c) {
41
+ const stop = extra(c, ['rows', 'apart']);
42
+ if (stop) return stop;
43
+ if (!range(c.rows, ROWS)) return `rows is ${words(c.rows)}, write the range of both rows as [low, high] from ${ROWS[0]} to ${ROWS[1]}, such as [4, 10]`;
44
+ if (!range(c.apart, [1, ROWS[1]])) return `apart is ${words(c.apart)}, write how far two different rows stand apart as [low, high] from 1, such as [1, 3]`;
45
+ return c.rows[1] - c.rows[0] >= c.apart[0] ? null : `apart starts at ${c.apart[0]}, and rows from ${c.rows[0]} to ${c.rows[1]} hold no two rows that far apart, so the signs < and > have nothing to draw`;
46
+ },
47
+ draw(c, spec, dice) {
48
+ const sign = dice.pick(SIGNS), far = span(c.rows).flatMap(a => span(c.apart).filter(d => a + d <= c.rows[1]).map(d => [a, a + d]));
49
+ const [less, more] = sign === '=' ? Array(2).fill(dice.pick(span(c.rows))) : dice.pick(far);
50
+ const [top, bottom] = sign === '>' ? [more, less] : [less, more];
51
+ return { top, bottom, wide: dice.pick(['top', 'bottom']), opens: dice.pick(SIGNS.filter(x => x !== sign)) };
52
+ },
53
+ page: t => ({ top: t.top, bottom: t.bottom, wide: t.wide, sign: t.opens, hidden: true }),
54
+ holds(state, spec, c, t) {
55
+ if (!state.checked) return { done: false };
56
+ const want = signOf(state.top, state.bottom);
57
+ return state.sign === want ? { done: true } : { done: false, note: SIGNS.indexOf(want) > SIGNS.indexOf(state.sign) ? 'more' : 'fewer' };
58
+ },
59
+ },
60
+ };
61
+
62
+ // The reader's state as a challenge opens: the drawn rows, the sign the tile opens on, and nothing checked.
63
+ export const matchStart = (spec, t) => ({ checked: false, top: t.top, bottom: t.bottom, sign: t.opens ?? null });
@@ -0,0 +1,84 @@
1
+ // What a match page holds and what it counts: two rows of objects and the pairs between them. The build and the
2
+ // browser both use this file, so a page's text and its live values agree.
3
+ import { isTile, signShown, readingKey, verdictKey } from './reading.js';
4
+
5
+ // A page draws its rows as counters, as cups on a tray above saucers on a table, as the players and the chairs of
6
+ // a game of musical chairs, or as the two scores of a scoreboard with a ball for each goal.
7
+ export const MATCH_LOOKS = ['rows', 'cups', 'chairs', 'scoreboard'];
8
+ export const GOALS_MAX = 9; // A score of the scoreboard stops here.
9
+ export const ROWS = ['top', 'bottom'];
10
+ export const ROW_MAX = 12; // The counters one row holds, which fit the width of a phone.
11
+ export const SPREAD_MAX = 6; // A row that spreads to twice its length holds this many.
12
+ export const PLAYERS = [2, 10]; // The players a game of musical chairs opens with.
13
+
14
+ // The most counters a row can reach on a page: the top of its stepper, or its number. A bottom row that trails the
15
+ // top row reaches as far as the top row.
16
+ export const roomOf = (spec, row) => spec.trail && spec.topCtl ? Math.max(spec.topCtl.hi, spec.bottom) : spec[`${row}Ctl`]?.hi ?? spec[row];
17
+
18
+ // opening gives the rows as the page opens. lines holds each pair the reader drew as [top, bottom], counted from 0.
19
+ // said holds the ids of the counters the reader numbered, in the order of their numbers. base keeps the rows as the
20
+ // page opened, and music says whether the music of the chairs plays.
21
+ export const opening = spec => ({ top: spec.top, bottom: spec.bottom, lines: [], said: [], base: { top: spec.top, bottom: spec.bottom }, music: true, sign: isTile(spec) ? spec.sign : null });
22
+ export const idOf = (row, i) => `${row[0]}${i}`;
23
+
24
+ // linesOf gives the pairs of the rows. An auto page pairs the first counter of the top row with the first of the
25
+ // bottom row and on, and so do the chairs once the music has stopped.
26
+ export function linesOf(spec, s) {
27
+ if (spec.look === 'chairs' ? !s.music : spec.pair === 'auto') return Array.from({ length: Math.min(s.top, s.bottom) }, (_, i) => [i, i]);
28
+ return s.lines;
29
+ }
30
+
31
+ // resize sets a row to n counters. A counter that leaves takes its line with it, and the numbers come off.
32
+ export function resize(s, row, n) {
33
+ const next = { ...s, [row]: n, said: [] };
34
+ return { ...next, lines: s.lines.filter(([t, b]) => t < next.top && b < next.bottom) };
35
+ }
36
+
37
+ // step sets a row to n counters after a press on its stepper. On a trail page the bottom row first takes the number
38
+ // the top row had.
39
+ export const step = (spec, s, row, n) => resize(spec.trail ? resize(s, 'bottom', s.top) : s, row, n);
40
+
41
+ // lone lists the counters of each row without a partner. They take a ring once one row has none left to pair. The
42
+ // players take theirs when the music stops, and the last player of a game takes a crown in its place. The balls of
43
+ // a scoreboard take none.
44
+ export function lone(spec, s) {
45
+ const lines = linesOf(spec, s), free = (n, k) => Array.from({ length: n }, (_, i) => i).filter(i => !lines.some(l => l[k] === i));
46
+ const top = free(s.top, 0), bottom = free(s.bottom, 1);
47
+ return { top, bottom, ringed: spec.look === 'scoreboard' ? false : spec.look === 'chairs' ? !s.music && s.bottom > 0 : !top.length || !bottom.length };
48
+ }
49
+ // A game of musical chairs is won when one player is left.
50
+ export const won = (spec, s) => spec.look === 'chairs' && s.top === 1;
51
+
52
+ // counts gives every number a page can show. added and taken count the counters that came and went since the page
53
+ // opened, over both rows, and counted is the last number the reader said.
54
+ export function counts(spec, s) {
55
+ const l = lone(spec, s), moved = sign => ROWS.reduce((sum, row) => sum + Math.max(0, sign * (s[row] - s.base[row])), 0);
56
+ return { unpaired: l.top.length + l.bottom.length, pairs: linesOf(spec, s).length, top: s.top, bottom: s.bottom,
57
+ counted: s.said.length, added: moved(1), taken: moved(-1) };
58
+ }
59
+
60
+ // The two groups are the same when each row has a counter and every counter has a partner.
61
+ export const same = (spec, s) => s.top > 0 && s.bottom > 0 && counts(spec, s).unpaired === 0;
62
+
63
+ // wordsOf gives the tag of each row: the row with counters left over has more, the other has fewer, and rows whose
64
+ // every counter has a partner are the same. n is how many more, once the reader has numbered every counter left over.
65
+ export function wordsOf(spec, s) {
66
+ const l = lone(spec, s), left = l.top.length + l.bottom.length;
67
+ if (!left) return { top: { word: 'same' }, bottom: { word: 'same' } };
68
+ const n = spec.tap && s.said.length === left ? left : null, more = l.top.length ? 'top' : 'bottom';
69
+ return Object.fromEntries(ROWS.map(row => [row, { word: row === more ? 'more' : 'fewer', n }]));
70
+ }
71
+ // The string of a tag, which takes n when the tag holds a number.
72
+ export const tagKey = w => w.n == null ? `tag-${w.word}` : `tag-${w.word}-n`;
73
+
74
+ // The measures a page can read out and link in its text. The words of the tags are linked and take no readout.
75
+ export function measuresOf(spec) {
76
+ if (spec.challenge) return [];
77
+ const signed = [...(spec.sign ? ['reading'] : []), ...(isTile(spec) ? ['verdict'] : [])];
78
+ if (spec.look === 'chairs' || spec.look === 'scoreboard') return ['top', 'bottom', ...signed];
79
+ return ['unpaired', 'pairs', 'top', 'bottom', ...signed, ...(spec.tap ? ['counted'] : []), ...(spec.trace ? ['added', 'taken'] : [])];
80
+ }
81
+ export const wordsLinked = spec => spec.word === true ? ['top-word', 'bottom-word'] : [];
82
+ // The strings of the line of words and of the mark of a page with a sign, as the page stands.
83
+ export const readingOf = (spec, s) => readingKey(s.top, s.bottom, signShown(spec, s));
84
+ export const verdictOf = (spec, s) => verdictKey(s.top, s.bottom, signShown(spec, s));
@@ -0,0 +1,379 @@
1
+ // The match scene: two rows of objects paired one to one. The reader draws a line between a counter of each row,
2
+ // seats a cup on a saucer, steps a row or stops the music of a game of chairs, and the counters left without a
3
+ // partner take a ring.
4
+ import { ROWS, GOALS_MAX, idOf, roomOf, opening, linesOf, resize, step, lone, won, counts, same, wordsOf, tagKey, measuresOf, wordsLinked, readingOf, verdictOf } from './match-model.js';
5
+ import { signTile, verdictMark, isTile, nextSign, signShown, signOf } from './reading.js';
6
+ import { counter, show, put, R, HIT } from './counter.js';
7
+ import { rowsOf, cupsOf, scoreOf, BALL, GAP, CLOSE, WIDE } from './match-figures.js';
8
+ import { MATCH_GOALS } from './match-goals.js';
9
+ import { another } from './goals.js';
10
+ import { carry, press } from './move.js';
11
+ import { driver } from './driver.js';
12
+ import { svg as el, svgPoint } from '../../kit/dom.js';
13
+ import { stepper, slider, chip, button, row as line } from '../../kit/panel.js';
14
+ import { goalRow } from '../../kit/goal.js';
15
+ import { dice, fresh } from '../../kit/random.js';
16
+ import { live } from '../../kit/text.js';
17
+ import { numbers } from '../../kit/format.js';
18
+
19
+ const MAX = 1.7; // A figure grows to at most this scale on a wide stage.
20
+ const PAD = 14; // The figure keeps this far from the stage's edges, in pixels.
21
+ const SAUCER = 15; // The radius a saucer is drawn round.
22
+ const NEAR = 34; // A cup let go this close to a saucer sits on it.
23
+ const rowOf = id => id[0] === 't' ? 'top' : 'bottom', at = id => Number(id.slice(1));
24
+ const NAMES = 26; // The room above and below the rows of a trail page for the names of the rows.
25
+ const tagWide = words => 24 + 8.4 * words.length; // The width of a row's tag round its words.
26
+ const SIGNED = { w: 258, h: 70 }; // The room under the rows for the line of two numbers with a sign.
27
+ const far = (p, q) => Math.hypot(p.x - q.x, p.y - q.y);
28
+
29
+ export default function match({ host, stage, panel, T, lang, moving, motion: fx }) {
30
+ const go = driver(fx);
31
+ const back = el('g'), voids = el('g'), wires = el('g'), rings = el('g'), lower = el('g'), upper = el('g', { class: 'counters-layer' });
32
+ // The tag at the end of each row, in the row's colour.
33
+ const tags = Object.fromEntries(ROWS.map(r => { const pop = el('g', { class: 'a' }, [el('rect', { class: 'counters-rowtag-box', rx: 13 }), el('text', { class: 'counters-rowtag-text' })]); return [r, { pop, g: el('g', { class: `counters-rowtag counters-${r === 'top' ? 'a' : 'b'}`, 'data-ref': `${r}-word`, display: 'none' }, [pop]) }]; }));
34
+ const rubber = el('line', { class: 'counters-rubber', display: 'none' });
35
+ const wordPop = el('g', { class: 'counters-word-pop a' }, [el('rect', { class: 'counters-word-box', rx: 15 }), el('text', { class: 'counters-word-text' })]);
36
+ const word = el('g', { class: 'counters-word', display: 'none' }, [wordPop]);
37
+ // The line under the rows of a page with a sign: the top row's number, the sign, the bottom row's number and the
38
+ // mark that says whether the line is true.
39
+ const tile = signTile(), told = verdictMark(), cards = ROWS.map((r, k) => el('rect', { class: `counters-line-card counters-${k ? 'b' : 'a'}`, x: (k ? 132 : 22) - 23, y: -25, width: 46, height: 50, rx: 8, display: 'none' })), nums = Object.fromEntries(ROWS.map((r, k) => [r, el('text', { class: `counters-line-num counters-${k ? 'b' : 'a'}`, 'data-ref': r, x: k ? 132 : 22 })]));
40
+ const signed = el('g', { display: 'none' }, [...cards, nums.top, el('g', { transform: 'translate(77 0)' }, [tile.el]), nums.bottom, el('g', { transform: 'translate(170 0)' }, [told.el])]);
41
+ press(tile.el, () => { if (!spec || !isTile(spec)) return; s.sign = nextSign(s.sign); if (cs) cs.checked = false; changed(); });
42
+ const svg = el('svg', { class: 'counters-svg' }, [back, voids, wires, rings, lower, upper, tags.top.g, tags.bottom.g, rubber, word, signed]);
43
+ stage.appendChild(svg);
44
+ // spec is the page. s holds the counters of each row, the lines the reader drew and how far the Spacing slider
45
+ // stands, from 0 to 1. geo holds the places of the figure, nodes the drawn object of each id, pick the counter a
46
+ // tap chose as the first of a pair, hold the cup the reader carries and ringed the ids that wear a ring.
47
+ let spec = null, s = null, geo = null, area = { w: 0, h: 0 }, nodes = new Map(), pick = null, hold = null, over = null;
48
+ // round is the button of the chairs.
49
+ let chips = [], ringed = new Set(), worded = false, round = null, board = null, goals = [];
50
+ // base is the page as written. On a challenge page spec is base with the rows the goal drew, target is the draw,
51
+ // cs says whether the reader has pressed Check, goal is the challenge's line and solved whether the goal holds.
52
+ let base = null, target = null, cs = null, goal = null, solved = false, steps = [];
53
+
54
+ const int = n => numbers(lang()).int(n);
55
+ const cups = () => spec.look === 'cups', chairs = () => spec.look === 'chairs', scores = () => spec.look === 'scoreboard';
56
+ new ResizeObserver(() => { const r = svg.getBoundingClientRect(); if (spec && (Math.round(r.width) !== area.w || Math.round(r.height) !== area.h)) build(); }).observe(svg);
57
+
58
+ const partner = id => { const k = rowOf(id) === 'top' ? 0 : 1, l = linesOf(spec, s).find(l => l[k] === at(id)); return l ? idOf(ROWS[1 - k], l[1 - k]) : null; };
59
+ const layout = () => scores() ? scoreOf(GOALS_MAX, [T('match-scoreboard-top'), T('match-scoreboard-bottom')]) : cups() ? cupsOf(roomOf(spec, 'top'), roomOf(spec, 'bottom'))
60
+ : rowsOf({ top: roomOf(spec, 'top'), bottom: roomOf(spec, 'bottom'), ...gaps(), tag: tagRoom(), names: spec.trail ? NAMES : 0, line: spec.sign ? SIGNED : undefined });
61
+ // The Spacing slider sets the gap of its row up to twice the gap, and a challenge draws one row wide and one close.
62
+ function gaps() {
63
+ if (spec.spread) return { gap: { [spec.spread]: GAP * (1 + s.spread) }, widest: { [spec.spread]: 2 * GAP } };
64
+ if (spec.wide) return { gap: Object.fromEntries(ROWS.map(r => [r, r === spec.wide ? WIDE : CLOSE])) };
65
+ return {};
66
+ }
67
+ // deal sets the rows as the page opens. A challenge draws its rows, and takes its stepper or its sign from its goal.
68
+ function deal() {
69
+ const c = base.challenge;
70
+ spec = base; cs = null; solved = false;
71
+ if (c) { target = another(MATCH_GOALS[c.goal], c, base, dice(fresh()), target); spec = { ...base, ...MATCH_GOALS[c.goal].page(target) }; cs = { checked: false }; }
72
+ s = { ...opening(spec), spread: 0 }; pick = null; worded = false;
73
+ }
74
+ const holds = () => cs ? MATCH_GOALS[base.challenge.goal].holds({ checked: cs.checked, top: s.top, bottom: s.bottom, sign: s.sign }, spec, base.challenge, target) : { done: false };
75
+ const ends = () => solved && MATCH_GOALS[base.challenge.goal].ends;
76
+
77
+ // The tag at a row's end gets the room of its longest words in the page's language, with the greatest number a
78
+ // row can count to.
79
+ function tagRoom() {
80
+ if (cs && MATCH_GOALS[base.challenge.goal].ends) return 6 + tagWide(int(roomOf(spec, 'top')));
81
+ if (spec.word !== true) return 0;
82
+ const n = int(Math.max(roomOf(spec, 'top'), roomOf(spec, 'bottom')));
83
+ return 6 + Math.max(...['same', 'more', 'fewer'].map(w => tagWide(T(`tag-${w}`))), ...(spec.tap ? ['more', 'fewer'].map(w => tagWide(T(`tag-${w}-n`, { n }))) : []));
84
+ }
85
+
86
+ // build draws the figure to fit the stage and puts every object in its place.
87
+ function build() {
88
+ const r = svg.getBoundingClientRect(); area = { w: Math.round(r.width), h: Math.round(r.height) };
89
+ if (!area.w || !area.h) { geo = null; return; } // A phone is showing the text, so the figure is drawn when the stage shows.
90
+ geo = layout();
91
+ const scale = Math.min(MAX, (area.w - 2 * PAD) / geo.w, (area.h - 2 * PAD) / geo.h);
92
+ svg.setAttribute('viewBox', `${geo.w / 2 - area.w / 2 / scale} ${geo.h / 2 - area.h / 2 / scale} ${area.w / scale} ${area.h / scale}`);
93
+ // A trail page names its rows: the top row is the group now, and the bottom row the group before.
94
+ const names = spec.trail ? [['top', 'now', -1], ['bottom', 'before', 1]].map(([r, key, side]) => { const p = geo[r](0), t = el('text', { class: 'counters-row-name', x: p.x - R, y: p.y + side * (R + 17), 'data-ref': r }); t.textContent = T(`row-${key}`); return t; }) : [];
95
+ const drawn = geo.draw(); board = drawn.refs ?? null;
96
+ back.replaceChildren(...drawn.nodes, ...names);
97
+ signed.setAttribute('display', geo.line && spec.sign ? 'inline' : 'none');
98
+ if (geo.line) signed.setAttribute('transform', `translate(${geo.line.x} ${geo.line.y})`);
99
+ tile.open(isTile(spec), T('sign')); told.show(isTile(spec) && !cs);
100
+ for (const card of cards) card.setAttribute('display', spec.hidden ? 'inline' : 'none');
101
+ for (const n of nodes.values()) n.tween?.pause();
102
+ lower.replaceChildren(); upper.replaceChildren(); voids.replaceChildren(); nodes = new Map(); ringed = new Set();
103
+ for (const r of ROWS) tags[r].pop.lastChild.textContent = '';
104
+ render('jump');
105
+ }
106
+
107
+ // where gives the place of every object on show. A cup with a saucer sits on it.
108
+ function where() {
109
+ const out = new Map();
110
+ for (let i = 0; i < s.bottom; i++) out.set(idOf('bottom', i), geo.bottom(i));
111
+ for (let i = 0; i < s.top; i++) {
112
+ const id = idOf('top', i), to = cups() ? partner(id) : null;
113
+ out.set(id, to ? geo.seat(at(to)) : geo.top(i));
114
+ }
115
+ return out;
116
+ }
117
+
118
+ // render moves every object to its place. After a change the reader made, objects glide, arrive and leave.
119
+ function render(how) {
120
+ if (!geo) return;
121
+ geo = layout(); solved = holds().done;
122
+ const to = where(), anim = how === 'move' && moving();
123
+ for (const [id, n] of nodes) if (!to.has(id)) {
124
+ nodes.delete(id); n.tween?.pause();
125
+ if (anim) go.vanish(n.pop, () => n.g.remove()); else n.g.remove();
126
+ }
127
+ for (const [id, p] of to) {
128
+ let n = nodes.get(id);
129
+ if (!n) {
130
+ n = make(id); nodes.set(id, n); (rowOf(id) === 'top' ? upper : lower).append(n.g); put(n, p);
131
+ if (anim) go.pop(n.pop);
132
+ continue;
133
+ }
134
+ if (n === hold || (n.at.x === p.x && n.at.y === p.y)) continue;
135
+ n.tween?.pause();
136
+ if (anim) n.tween = go.tween(n.at, { x: p.x, y: p.y }, () => show(n)); else put(n, p);
137
+ }
138
+ paint(to, anim); refresh();
139
+ }
140
+
141
+ // make draws a counter, a cup, a saucer, a player or a chair. The reader pairs counters and carries cups. A
142
+ // counter added since a trace page opened carries a plus, and a counter of a tap page has room for its number.
143
+ function make(id) {
144
+ const top = rowOf(id) === 'top';
145
+ if (cups() && !top) return counter('saucer', 'b', SAUCER);
146
+ if (chairs()) return top ? counter('person', 'a', R, at(id)) : counter('chair', 'b');
147
+ if (scores()) return counter('ball', top ? 'a' : 'b', BALL);
148
+ const n = counter(cups() ? 'mug' : 'disc', top ? 'a' : 'b');
149
+ // A counter added since a trace page opened carries a plus in place of the inner ring.
150
+ if (spec.trace && at(id) >= s.base[rowOf(id)]) { n.g.classList.add('counters-added'); n.pop.append(el('path', { class: 'counters-plus', d: 'M -8 0 H 8 M 0 -8 V 8' })); }
151
+ if (spec.tap) {
152
+ n.tagPop = el('g', { class: 'counters-tag-pop' }, [el('rect', { class: 'counters-tag-box', x: -9, y: -9, width: 18, height: 18, rx: 9 }), el('text', { class: 'counters-tag-text' })]);
153
+ n.tag = el('g', { class: 'counters-tag', transform: `translate(${R * 0.8} ${-R * 1.15})`, display: 'none' }, [n.tagPop]);
154
+ n.g.append(n.tag);
155
+ press(n.g, () => numbered(id));
156
+ }
157
+ if (!cups() && spec.pair === 'auto') return n;
158
+ n.g.setAttribute('tabindex', 0); n.g.setAttribute('role', 'button'); n.g.setAttribute('aria-label', T(cups() ? 'cup' : 'kind-disc'));
159
+ n.g.classList.add('counters-moves');
160
+ carry(n.g, cups() ? carried(id, n) : drawn(id, n));
161
+ return n;
162
+ }
163
+
164
+ // A drag from a counter draws a line that follows the finger, and the line stays when it is let go on a counter
165
+ // of the other row that has none. A counter that has a line keeps it until a tap takes it away.
166
+ function drawn(id, n) {
167
+ const aim = q => { const to = aimed(id, q); mark(to); return to; };
168
+ const end = () => { rubber.setAttribute('display', 'none'); mark(null); };
169
+ return {
170
+ point: e => svgPoint(svg, e),
171
+ move(q) {
172
+ if (partner(id)) return;
173
+ const to = aim(q), p = to ? nodes.get(to).at : q;
174
+ for (const [k, v] of Object.entries({ x1: n.at.x, y1: n.at.y, x2: p.x, y2: p.y, display: 'inline' })) rubber.setAttribute(k, v);
175
+ },
176
+ drop(q) { const to = q && !partner(id) ? aim(q) : null; end(); if (to) join(id, to); },
177
+ tap() { end(); tapped(id); },
178
+ };
179
+ }
180
+ // aimed gives the counter of the other row under the point q, when it has no line yet.
181
+ function aimed(id, q) {
182
+ let best = null, d = HIT + 4;
183
+ for (const [to, n] of nodes) if (rowOf(to) !== rowOf(id) && !partner(to) && far(n.at, q) < d) { best = to; d = far(n.at, q); }
184
+ return best;
185
+ }
186
+ // mark shows where a line or a cup would land.
187
+ function mark(id) {
188
+ if (over === id) return;
189
+ nodes.get(over)?.g.classList.remove('counters-over'); nodes.get(id)?.g.classList.add('counters-over'); over = id;
190
+ }
191
+ function join(a, b) {
192
+ const [t, u] = rowOf(a) === 'top' ? [a, b] : [b, a];
193
+ s.lines = [...s.lines.filter(l => l[0] !== at(t) && l[1] !== at(u)), [at(t), at(u)]];
194
+ pick = null; changed();
195
+ }
196
+ const part = id => { s.lines = s.lines.filter(l => l[rowOf(id) === 'top' ? 0 : 1] !== at(id)); pick = null; changed(); };
197
+ // A tap on a paired counter takes its line away. A tap on a counter and then on one of the other row pairs them.
198
+ function tapped(id) {
199
+ if (partner(id)) return part(id);
200
+ if (pick && rowOf(pick) !== rowOf(id)) return join(pick, id);
201
+ pick = pick === id ? null : id; changed();
202
+ }
203
+
204
+ // The reader carries a cup. Let go on an empty saucer it sits there, and anywhere else it goes back to the tray.
205
+ // A tap sends a cup of the tray to the first empty saucer, and a cup on a saucer back to the tray.
206
+ function carried(id, n) {
207
+ let dx = 0, dy = 0;
208
+ const saucer = p => { let best = null, d = NEAR; for (let j = 0; j < s.bottom; j++) { const to = idOf('bottom', j), free = !partner(to) || partner(to) === id; if (free && far(geo.seat(j), p) < d) { best = to; d = far(geo.seat(j), p); } } return best; };
209
+ const free = () => Array.from({ length: s.bottom }, (_, j) => idOf('bottom', j)).find(to => !partner(to));
210
+ return {
211
+ point: e => svgPoint(svg, e), raise: () => upper.append(n.g),
212
+ start(q) { n.tween?.pause(); hold = n; dx = n.at.x - q.x; dy = n.at.y - q.y; },
213
+ move(q) { put(n, { x: q.x + dx, y: q.y + dy }); mark(saucer(n.at)); },
214
+ drop(q) {
215
+ hold = null;
216
+ const to = q ? saucer(n.at) : partner(id);
217
+ mark(null);
218
+ if (to) join(id, to); else part(id);
219
+ },
220
+ tap() { hold = null; const to = partner(id) ? null : free(); if (to) join(id, to); else part(id); },
221
+ };
222
+ }
223
+
224
+ // A tap on a counter left over gives it the next number. A counter that holds its number shakes it once.
225
+ function numbered(id) {
226
+ if (!lone(spec, s)[rowOf(id)].includes(at(id))) return;
227
+ if (s.said.includes(id)) { if (moving()) go.flash(nodes.get(id)?.tagPop); return; }
228
+ s.said = [...s.said, id]; changed();
229
+ }
230
+ // The button of the chairs stops the music, then takes the player left over out with one chair, and starts a new
231
+ // game once one player is left.
232
+ function turn() {
233
+ if (won(spec, s)) s = { ...opening(spec), spread: 0 };
234
+ else if (s.music) s.music = false;
235
+ else s = { ...resize(resize(s, 'top', s.top - 1), 'bottom', s.bottom - 1), music: true };
236
+ changed();
237
+ }
238
+ const turnWords = () => T(won(spec, s) ? 'chairs-again' : s.music ? 'chairs-stop' : 'chairs-next');
239
+
240
+ function changed() { render('move'); }
241
+
242
+ // paint draws the pair lines, rings the counters without a partner and shows the words between the rows.
243
+ function paint(to, anim) {
244
+ wires.replaceChildren(...(cups() ? [] : linesOf(spec, s).map(([t, b]) => {
245
+ const p = to.get(idOf('top', t)), q = to.get(idOf('bottom', b));
246
+ return el('line', { class: 'counters-wire', 'data-ref': 'pairs', x1: p.x, y1: p.y, x2: q.x, y2: q.y });
247
+ })));
248
+ const l = lone(spec, s), ids = l.ringed ? ROWS.flatMap(r => l[r].map(i => idOf(r, i))) : [];
249
+ rings.replaceChildren(...ids.map(id => {
250
+ const p = to.get(id), r = cups() ? (rowOf(id) === 'top' ? R + 9 : 1.5 * SAUCER + 6) : chairs() ? R + 8 : R + 3.5;
251
+ const c = el('circle', { class: 'counters-lone a', 'data-ref': 'unpaired', cx: p.x, cy: p.y, r });
252
+ if (anim && !ringed.has(id)) go.pop(c);
253
+ return c;
254
+ }));
255
+ ringed = new Set(ids);
256
+ for (const [id, n] of nodes) n.g.classList.toggle('counters-picked', id === pick);
257
+ if (spec.trace) voids.replaceChildren(...ROWS.flatMap(r => Array.from({ length: Math.max(0, s.base[r] - s[r]) }, (_, k) => {
258
+ const p = geo[r](s[r] + k);
259
+ return el('circle', { class: 'counters-void', 'data-ref': 'taken', cx: p.x, cy: p.y, r: R - 2 });
260
+ })));
261
+ if (spec.tap) for (const [id, n] of nodes) {
262
+ const k = s.said.indexOf(id), words = k < 0 ? '' : int(k + 1), text = n.tagPop.lastChild, open = k < 0 && ids.includes(id);
263
+ for (const [name, v] of [['tabindex', 0], ['role', 'button'], ['aria-label', T('kind-disc')]]) if (open) n.g.setAttribute(name, v); else n.g.removeAttribute(name);
264
+ if (text.textContent === words) continue;
265
+ text.textContent = words; n.tag.setAttribute('display', words ? 'inline' : 'none');
266
+ if (words && anim) go.pop(n.tagPop);
267
+ }
268
+ if (chairs()) {
269
+ const sway = s.music && !won(spec, s) && moving();
270
+ for (const [id, n] of nodes) if (rowOf(id) === 'top') { n.pop.classList.toggle('counters-sway', sway); n.pop.style.animationDelay = `${-0.35 * (at(id) % 3)}s`; }
271
+ if (won(spec, s)) { const p = to.get(idOf('top', 0)), crown = el('path', { class: 'counters-crown a', d: 'M -10 -17 L -10 -28 L -5 -22 L 0 -30 L 5 -22 L 10 -28 L 10 -17 Z' }); rings.append(el('g', { transform: `translate(${p.x} ${p.y})` }, [crown])); if (anim) go.pop(crown); }
272
+ if (round) round.querySelector('span').textContent = turnWords();
273
+ }
274
+ if (spec.sign) {
275
+ // The scoreboard writes its scores and its sign on the board, and the rows write theirs on the line under them.
276
+ const sign = signShown(spec, s), flash = part => { if (anim) go.flash(part); };
277
+ // The cards of a challenge keep the numbers of the rows face down until the goal holds.
278
+ const shown = r => spec.hidden && !solved ? '?' : int(s[r]);
279
+ for (const r of ROWS) { const t = board?.[r] ?? nums[r]; if (t.textContent !== shown(r)) { const first = !t.textContent; t.textContent = shown(r); if (!first) flash(t); } }
280
+ if (board) { if (board.sign.textContent !== sign) { board.sign.textContent = sign; flash(board.sign); } }
281
+ else {
282
+ if (tile.set(sign)) flash(tile.pop);
283
+ if (isTile(spec) && told.set(signOf(s.top, s.bottom) === sign, T(verdictOf(spec, s)))) flash(told.el);
284
+ }
285
+ for (const [k, b] of goals.entries()) b.disabled = s[ROWS[k]] >= GOALS_MAX;
286
+ }
287
+ // A challenge that writes the numbers of its rows once it is reached uses the tags for them.
288
+ const ws = ends() ? Object.fromEntries(ROWS.map(r => [r, null])) : spec.word === true ? wordsOf(spec, s) : null;
289
+ for (const r of ROWS) {
290
+ const t = tags[r], text = t.pop.lastChild;
291
+ t.g.setAttribute('display', ws ? 'inline' : 'none');
292
+ if (!ws) continue;
293
+ // The tag stands after the last counter of its row, or after the last empty place.
294
+ const words = ws[r] ? T(tagKey(ws[r]), { n: int(ws[r].n ?? 0) }) : int(s[r]), w = tagWide(words), n = Math.max(s[r], spec.trace ? s.base[r] : 0), p = geo[r](Math.max(0, n - 1));
295
+ for (const [k, v] of Object.entries({ x: -w / 2, y: -13, width: w, height: 26 })) t.pop.firstChild.setAttribute(k, v);
296
+ t.g.setAttribute('transform', `translate(${p.x + (n ? R : -R) + 12 + w / 2} ${p.y})`);
297
+ if (text.textContent !== words) { const first = !text.textContent; text.textContent = words; if (anim && !first) go.flash(t.pop); }
298
+ }
299
+ const on = spec.word === 'same' && same(spec, s);
300
+ word.setAttribute('display', on ? 'inline' : 'none');
301
+ if (on) {
302
+ const text = T('word-same'), w = 30 + 9.4 * text.length, xs = [...to.values()].map(p => p.x);
303
+ wordPop.lastChild.textContent = text;
304
+ for (const [k, v] of Object.entries({ x: -w / 2, y: -15, width: w, height: 30 })) wordPop.firstChild.setAttribute(k, v);
305
+ word.setAttribute('transform', `translate(${(Math.min(...xs) + Math.max(...xs)) / 2} ${geo.mid})`);
306
+ if (anim && !worded) go.pop(wordPop);
307
+ }
308
+ worded = on;
309
+ }
310
+
311
+ // refresh writes every value that follows the rows, in the readouts and the text: the counts and the words of the
312
+ // tags.
313
+ function refresh() {
314
+ const st = counts(spec, s), ids = measuresOf(spec), ws = wordsLinked(spec).length ? wordsOf(spec, s) : null;
315
+ const said = { reading: () => T(readingOf(spec, s), { a: int(s.top), b: int(s.bottom) }), verdict: () => T(verdictOf(spec, s)) }, value = id => said[id]?.() ?? int(st[id]);
316
+ for (const k of chips) if (k.set(value(k.id)) && moving()) go.flash(k.el);
317
+ judge();
318
+ live(host, { value: id => ids.includes(id) ? value(id) : wordsLinked(spec).includes(id) ? T(tagKey(ws[id.split('-')[0]]), { n: int(ws[id.split('-')[0]].n ?? 0) }) : null });
319
+ }
320
+
321
+ // judge writes a challenge's line and whether its goal holds. The counters swell the first time it does.
322
+ function judge() {
323
+ if (!goal) return;
324
+ const name = base.challenge.goal, r = holds();
325
+ goal.say(T(`goal-${name}`));
326
+ for (const st of steps) st.show(r.done);
327
+ if (goal.show(r.done, r.note ? T(`note-${name}-${r.note}`) : undefined) && moving()) go.cheer([...nodes.values()].map(n => n.pop));
328
+ }
329
+
330
+ // The panel holds a stepper for each row that has one, the Spacing slider, the button of the chairs and the
331
+ // readouts.
332
+ function drawPanel() {
333
+ // A challenge keeps the number of its stepper out of sight until the goal holds.
334
+ const ctls = ROWS.filter(r => spec[`${r}Ctl`]).map(r => stepper({ shown: !cs || solved, id: r, label: T(`ctl-${r}`), min: spec[`${r}Ctl`].lo, max: spec[`${r}Ctl`].hi, value: s[r], write: int,
335
+ change: v => { s = step(spec, s, r, v); pick = null; if (cs) cs.checked = false; changed(); } }));
336
+ steps = [...ctls];
337
+ if (spec.spread) ctls.push(slider({ id: 'spread', label: T('ctl-spread'), min: 0, max: 100, value: s.spread * 100, output: false,
338
+ write: v => `×${numbers(lang()).fmt(1 + v / 100)}`, input: v => { s.spread = v / 100; render('jump'); } }));
339
+ round = chairs() ? button({ label: turnWords(), act: 'round', primary: true, press: turn }) : null;
340
+ if (round) ctls.push(round);
341
+ // The scoreboard has a button for a goal of each team and one for a new match.
342
+ goals = scores() ? ROWS.map(r => button({ label: T(`score-${r}`), act: `score-${r}`, press: () => { if (s[r] < GOALS_MAX) { s = resize(s, r, s[r] + 1); changed(); } } })) : [];
343
+ if (scores()) ctls.push(...goals, button({ label: T('new-match'), act: 'new-match', press: () => { s = { ...opening(spec), spread: 0 }; changed(); } }));
344
+ // The line of words takes a line of the panel to itself, so the panel keeps its height as the words change.
345
+ chips = spec.readout.map(id => chip({ id, label: T(`match-${spec.trail ? 'trail' : spec.look}-${id}`) ?? T(`match-${id}`), cls: id === 'reading' ? 'counters-chip-wide' : '' }));
346
+ for (const k of chips) if (k.id !== 'reading') k.width(k.id === 'verdict' ? 5 : 2);
347
+ // A challenge has its line with Another one and a hint, and a Check button beside its controls.
348
+ goal = null;
349
+ if (cs) {
350
+ const name = base.challenge.goal;
351
+ goal = goalRow({ T, motion: moving() ? fx : null, hint: on => on ? T(`hint-${name}`) : null, another: () => { deal(); drawPanel(); build(); if (!geo) refresh(); } });
352
+ ctls.push(button({ label: T('check'), act: 'check', primary: true, press: () => { if (!cs.checked) { cs.checked = true; render('move'); if (!geo) refresh(); } } }));
353
+ }
354
+ panel.replaceChildren(...[goal?.el, ctls.length ? line('ctls', ctls) : null, chips.length ? line('out', chips) : null].filter(Boolean));
355
+ }
356
+
357
+ function point(id, on) {
358
+ if (!spec) return;
359
+ for (const part of svg.querySelectorAll(`[data-ref="${id}"]`)) part.classList.toggle('counters-hot', on);
360
+ for (const part of panel.querySelectorAll('[data-ref]')) part.classList.toggle('hot', on && part.dataset.ref === id);
361
+ }
362
+ function stop() { for (const n of nodes.values()) n.tween?.pause(); hold = null; over = null; rubber.setAttribute('display', 'none'); }
363
+
364
+ return {
365
+ show(page) {
366
+ stop(); base = page; target = null; deal();
367
+ drawPanel(); build();
368
+ if (!geo) refresh();
369
+ },
370
+ hide() {
371
+ stop(); spec = null; base = null; cs = null; goal = null; geo = null; nodes = new Map();
372
+ for (const g of [back, voids, wires, rings, lower, upper]) g.replaceChildren();
373
+ for (const g of [word, tags.top.g, tags.bottom.g, signed]) g.setAttribute('display', 'none');
374
+ for (const r of ROWS) nums[r].textContent = '';
375
+ },
376
+ point,
377
+ lang() { if (!spec) return; const was = goal; drawPanel(); goal?.keep(was); build(); if (!geo) refresh(); },
378
+ };
379
+ }