@openbooknetwork/hesap 0.2.3 → 0.3.1

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.
Files changed (50) hide show
  1. package/package.json +2 -2
  2. package/src/client.css +254 -1
  3. package/src/families/counters/add-figures.js +85 -0
  4. package/src/families/counters/add-goals.js +82 -0
  5. package/src/families/counters/add-model.js +82 -0
  6. package/src/families/counters/add.js +442 -0
  7. package/src/families/counters/add.mjs +102 -0
  8. package/src/families/counters/bonds.js +5 -5
  9. package/src/families/counters/client.css +126 -1
  10. package/src/families/counters/client.js +10 -12
  11. package/src/families/counters/count-figures.js +23 -3
  12. package/src/families/counters/count-model.js +5 -0
  13. package/src/families/counters/count.js +31 -9
  14. package/src/families/counters/count.mjs +5 -3
  15. package/src/families/counters/counter.js +25 -0
  16. package/src/families/counters/goals.js +1 -9
  17. package/src/families/counters/i18n/en.yaml +142 -30
  18. package/src/families/counters/i18n/tr.yaml +116 -4
  19. package/src/families/counters/index.mjs +11 -6
  20. package/src/families/counters/match-figures.js +60 -0
  21. package/src/families/counters/match-goals.js +63 -0
  22. package/src/families/counters/match-model.js +93 -0
  23. package/src/families/counters/match.js +399 -0
  24. package/src/families/counters/match.mjs +102 -0
  25. package/src/families/counters/order-figures.js +46 -0
  26. package/src/families/counters/order-model.js +69 -0
  27. package/src/families/counters/order.js +199 -0
  28. package/src/families/counters/order.mjs +62 -0
  29. package/src/families/counters/reading.js +66 -0
  30. package/src/families/counters/scenes.js +18 -0
  31. package/src/families/line/client.css +118 -0
  32. package/src/families/line/client.js +12 -0
  33. package/src/families/line/figures.js +143 -0
  34. package/src/families/line/goals.js +168 -0
  35. package/src/families/line/i18n/en.yaml +61 -0
  36. package/src/families/line/i18n/tr.yaml +61 -0
  37. package/src/families/line/index.mjs +227 -0
  38. package/src/families/line/lens.js +49 -0
  39. package/src/families/line/line.js +624 -0
  40. package/src/families/line/model.js +219 -0
  41. package/src/families.mjs +2 -1
  42. package/src/i18n/en.yaml +211 -31
  43. package/src/i18n/tr.yaml +184 -4
  44. package/src/kit/i18n/en.yaml +8 -1
  45. package/src/kit/i18n/tr.yaml +7 -0
  46. package/src/kit/kit.css +9 -0
  47. package/src/kit/panel.js +9 -4
  48. package/src/kit/random.js +9 -0
  49. package/src/kit/written.js +70 -0
  50. package/src/node.mjs +13 -1
@@ -0,0 +1,199 @@
1
+ // The order scene: two numbers compared and three numbers put in order. The reader moves two markers along one
2
+ // count of 100, lays two numbers out as blocks of rows of ten, or drags three number cards into places.
3
+ import { ROWS, CARDS, opening, isCards, counts, decides, between, ordered, measuresOf, readingOf, verdictOf, pinShift, drawCards } from './order-model.js';
4
+ import { readingLine, signTile, verdictMark, isTile, nextSign, signShown, signOf } from './reading.js';
5
+ import { show, put, R } from './counter.js';
6
+ import { rows } from './count-figures.js';
7
+ import { dot, block, card, BLOCK, CARD } from './order-figures.js';
8
+ import { txt } from './figures.js';
9
+ import { carry, press } from './move.js';
10
+ import { driver } from './driver.js';
11
+ import { svg as el, svgPoint } from '../../kit/dom.js';
12
+ import { slider, stepper, chip, button, row as line } from '../../kit/panel.js';
13
+ import { live } from '../../kit/text.js';
14
+ import { numbers } from '../../kit/format.js';
15
+ import { dice, fresh } from '../../kit/random.js';
16
+
17
+ const PAD = 14; // The figure keeps this far from the stage's edges, in pixels.
18
+ // The top number is the first number, in red, and the bottom number the second, in blue. The colour is a second
19
+ // cue: the first number stands left or above, and the second right or below.
20
+ const COLOUR = { top: 'a', bottom: 'b' };
21
+ const LINE = 44; // The room under a figure for the line of words.
22
+ const far = (p, q) => Math.hypot(p.x - q.x, p.y - q.y);
23
+
24
+ export default function order({ host, stage, panel, T, lang, moving, motion: fx }) {
25
+ const go = driver(fx);
26
+ const svg = el('svg', { class: 'counters-svg' });
27
+ stage.appendChild(svg);
28
+ // spec is the page and s its numbers, or the places of its cards. fig is the figure as drawn: its size, the
29
+ // greatest scale it takes and a paint that follows s. reveal is the button of a covered page.
30
+ let spec = null, s = null, fig = null, area = { w: 0, h: 0 }, chips = [], reveal = null, cards = [];
31
+
32
+ const int = n => numbers(lang()).int(n);
33
+ const words = () => T(readingOf(spec, s), { a: int(s.top), b: int(s.bottom) });
34
+ new ResizeObserver(() => { const r = svg.getBoundingClientRect(); if (spec && (Math.round(r.width) !== area.w || Math.round(r.height) !== area.h)) build(); }).observe(svg);
35
+
36
+ // build draws the page's figure to fit the stage.
37
+ function build() {
38
+ const r = svg.getBoundingClientRect(); area = { w: Math.round(r.width), h: Math.round(r.height) };
39
+ for (const c of cards) c.tween?.pause();
40
+ cards = [];
41
+ if (!area.w || !area.h) { fig = null; return; } // A phone is showing the text, so the figure is drawn when the stage shows.
42
+ fig = isCards(spec) ? cardsFig() : spec.show === 'count' ? countFig() : blocksFig();
43
+ const scale = Math.min(fig.max, (area.w - 2 * PAD) / fig.w, (area.h - 2 * PAD) / fig.h);
44
+ svg.setAttribute('viewBox', `${fig.w / 2 - area.w / 2 / scale} ${fig.h / 2 - area.h / 2 / scale} ${area.w / scale} ${area.h / scale}`);
45
+ svg.replaceChildren(...fig.nodes);
46
+ fig.paint(false); refresh();
47
+ }
48
+
49
+ // One count of 100 in rows of ten with a marker on each number. The counters up to the less number are filled
50
+ // grey. The counters after it up to the greater number are hollow, with a heavy outline in that number's colour.
51
+ function countFig() {
52
+ const top = 18, tray = rows(100)[0], d = tray.draw(0, top), at = i => d.places.slots.pos(i);
53
+ for (const l of d.refs.labels) l.t.textContent = int(l.n);
54
+ const dots = Array.from({ length: 100 }, (_, i) => dot('b', R, at(i)));
55
+ // A marker is a frame round its counter and a pin that holds the number. The first number has a ring and a round
56
+ // pin above its counter, the second a square frame and a square pin below, so the two differ without their colours.
57
+ const pins = ROWS.map((r, k) => {
58
+ const half = R + 5.5, ring = k ? el('rect', { class: `counters-pin-ring counters-${COLOUR[r]}`, width: 2 * half, height: 2 * half, rx: 4 }) : el('circle', { class: `counters-pin-ring counters-${COLOUR[r]}`, r: R + 2.5 });
59
+ const box = el('rect', { class: 'counters-pin-box', y: -10, height: 20, rx: k ? 3 : 10 }), num = el('text', { class: 'counters-pin-num' });
60
+ return { r, k, ring, box, num, g: el('g', { class: `counters-pin counters-${COLOUR[r]}`, 'data-ref': r }, [box, num]) };
61
+ });
62
+ const said = readingLine(tray.tray / 2, top + tray.h + LINE / 2 + 4);
63
+ said.show(spec.reading);
64
+ return {
65
+ w: tray.w, h: top + tray.h + (spec.reading ? LINE : 0), max: 1.7,
66
+ nodes: [...d.nodes, ...dots, ...pins.map(p => p.ring), ...pins.map(p => p.g), said.el],
67
+ paint() {
68
+ const lo = Math.min(s.top, s.bottom), hi = Math.max(s.top, s.bottom), big = COLOUR[s.top > s.bottom ? 'top' : 'bottom'];
69
+ dots.forEach((g, i) => { const cls = `counters-counter ${i < lo ? 'counters-both' : i < hi ? `counters-${big} counters-hollow` : 'counters-pale'}`; if (g.getAttribute('class') !== cls) g.setAttribute('class', cls); });
70
+ const shift = pinShift(s);
71
+ for (const p of pins) {
72
+ const c = at(s[p.r] - 1), text = int(s[p.r]), w = 14 + 8 * text.length;
73
+ if (p.k) { p.ring.setAttribute('x', c.x - R - 5.5); p.ring.setAttribute('y', c.y - R - 5.5); } else { p.ring.setAttribute('cx', c.x); p.ring.setAttribute('cy', c.y); }
74
+ p.num.textContent = text; p.box.setAttribute('x', -w / 2); p.box.setAttribute('width', w);
75
+ p.g.setAttribute('transform', `translate(${c.x + shift[p.r] * (w / 2 + 1)} ${c.y + (p.k ? 1 : -1) * R * 1.3})`);
76
+ }
77
+ said.say(words());
78
+ },
79
+ };
80
+ }
81
+
82
+ // Two blocks side by side, each a number in rows of ten. A frame surrounds the rows that decide, and a covered
83
+ // page hides the rows, the frame and the line until the reader asks for them.
84
+ function blocksFig() {
85
+ const tiled = isTile(spec), between = tiled ? 62 : 28, w = 2 * BLOCK.w + between, blocks = ROWS.map((r, k) => ({ r, ...block(r, COLOUR[r], k * (BLOCK.w + between)) }));
86
+ const said = readingLine(w / 2, BLOCK.h + LINE / 2 + 4), low = BLOCK.h + (spec.reading ? LINE : 0);
87
+ // The sign tile stands between the two numbers, and the mark that says true or false under the blocks.
88
+ const tile = signTile(74), mark = verdictMark(), extra = [];
89
+ if (tiled) {
90
+ extra.push(el('g', { transform: `translate(${w / 2} ${BLOCK.num})` }, [tile.el]), el('g', { transform: `translate(${w / 2 - 44} ${low + 24})` }, [mark.el]));
91
+ tile.open(true, T('sign'));
92
+ press(tile.el, () => { s.sign = nextSign(s.sign); fig.paint(true); refresh(); });
93
+ }
94
+ return {
95
+ w, h: low + (tiled ? 44 : 0), max: 2.4,
96
+ nodes: [...blocks.flatMap(b => b.nodes), said.el, ...extra],
97
+ paint(anim) {
98
+ const kind = spec.decide && s.open ? decides(s) : null;
99
+ for (const b of blocks) { b.set(s[b.r], int(s[b.r])); b.frame(kind, s[b.r]); b.cover(!s.open); }
100
+ said.show(spec.reading && s.open); said.say(words());
101
+ if (reveal) reveal.disabled = s.open;
102
+ if (tiled) { const turned = tile.set(signShown(spec, s)), told = mark.set(signOf(s.top, s.bottom) === s.sign, T(verdictOf(spec, s))); if (anim && moving()) { if (turned) go.flash(tile.pop); if (told) go.flash(mark.el); } }
103
+ },
104
+ };
105
+ }
106
+
107
+ // Three number cards in a tray above three places. A card let go on a place sits there and trades with a card
108
+ // that holds the place, and anywhere else it goes back to the tray. A tap sends a card to the first empty place,
109
+ // or back to the tray.
110
+ function cardsFig() {
111
+ const gap = 22, edge = 12, w = CARDS * CARD.w + (CARDS - 1) * gap + 2 * edge, trayH = CARD.h + 2 * edge, py = trayH + 50 + CARD.h / 2;
112
+ const x = k => edge + k * (CARD.w + gap) + CARD.w / 2, home = i => ({ x: x(i), y: trayH / 2 }), spot = k => ({ x: x(k), y: py });
113
+ const posOf = i => s.place[i] == null ? home(i) : spot(s.place[i]);
114
+ const labels = [txt('counters-place-word', x(0), trayH + 32, T('least')), txt('counters-place-word', x(CARDS - 1), trayH + 32, T('greatest'))];
115
+ const places = Array.from({ length: CARDS }, (_, k) => el('rect', { class: 'counters-place', x: x(k) - CARD.w / 2, y: py - CARD.h / 2, width: CARD.w, height: CARD.h, rx: 9 }));
116
+ const says = Array.from({ length: CARDS - 1 }, (_, k) => txt('counters-between', (x(k) + x(k + 1)) / 2, py + CARD.h / 2 + 22));
117
+ const frame = el('rect', { class: 'counters-decide', x: edge - 6, y: py - CARD.h / 2 - 6, width: w - 2 * edge + 12, height: CARD.h + 12, rx: 12, display: 'none' });
118
+ const tick = el('path', { class: 'counters-tick a', d: 'M -9 0 l 6 7 l 12 -14', display: 'none' }), tickAt = el('g', { transform: `translate(${x(1)} ${trayH + 30})` }, [tick]);
119
+ const layer = el('g', { class: 'counters-layer' });
120
+ let hold = null, done = false;
121
+ const sit = (i, k) => { const j = s.place.indexOf(k); if (j >= 0 && j !== i) s.place[j] = s.place[i]; s.place[i] = k; };
122
+ cards = s.cards.map((n, i) => {
123
+ const pop = el('g', { class: 'counters-pop a' }, card(n, int(n))), g = el('g', { class: 'counters-card counters-moves', tabindex: 0, role: 'button', 'aria-label': int(n) }, [pop]);
124
+ const c = { g, pop, at: { x: 0, y: 0 } };
125
+ let dx = 0, dy = 0;
126
+ carry(g, {
127
+ point: e => svgPoint(svg, e), raise: () => layer.append(g),
128
+ start(q) { c.tween?.pause(); hold = c; dx = c.at.x - q.x; dy = c.at.y - q.y; },
129
+ move(q) { put(c, { x: q.x + dx, y: q.y + dy }); },
130
+ drop(q) {
131
+ hold = null;
132
+ if (q) { const k = Array.from({ length: CARDS }, (_, k) => k).sort((a, b) => far(spot(a), c.at) - far(spot(b), c.at))[0]; if (far(spot(k), c.at) < CARD.h * 0.6) sit(i, k); else s.place[i] = null; }
133
+ fig.paint(true);
134
+ },
135
+ tap() { hold = null; const free = Array.from({ length: CARDS }, (_, k) => k).find(k => !s.place.includes(k)); s.place[i] = s.place[i] == null && free !== undefined ? free : null; fig.paint(true); },
136
+ });
137
+ put(c, posOf(i)); layer.append(g);
138
+ return c;
139
+ });
140
+ return {
141
+ w, h: py + CARD.h / 2 + 38, max: 1.7,
142
+ nodes: [el('rect', { class: 'counters-tray', x: 0, y: 0, width: w, height: trayH, rx: 12 }), ...labels, ...places, frame, tickAt, ...says, layer],
143
+ paint(anim) {
144
+ const glide = anim && moving();
145
+ cards.forEach((c, i) => {
146
+ const p = posOf(i);
147
+ if (c === hold || (c.at.x === p.x && c.at.y === p.y)) return;
148
+ c.tween?.pause();
149
+ if (glide) c.tween = go.tween(c.at, p, () => show(c)); else put(c, p);
150
+ });
151
+ says.forEach((t, k) => { const rel = between(spec, s, k), text = rel ? T(`is-${rel}`) : ''; if (t.textContent !== text) { t.textContent = text; if (text && glide) go.flash(t); } });
152
+ const now = ordered(spec, s);
153
+ for (const part of [frame, tick]) part.setAttribute('display', now ? 'inline' : 'none');
154
+ if (now && !done && glide) { go.pop(tick); go.cheer(cards.map(c => c.pop)); }
155
+ done = now;
156
+ },
157
+ };
158
+ }
159
+
160
+ // refresh writes every value that follows the numbers, in the readouts and the text.
161
+ function refresh() {
162
+ const st = counts(spec, s), ids = measuresOf(spec), value = id => id === 'reading' ? words() : id === 'verdict' ? T(verdictOf(spec, s)) : int(st[id]);
163
+ for (const k of chips) if (k.set(value(k.id)) && moving()) go.flash(k.el);
164
+ live(host, { value: id => ids.includes(id) ? value(id) : null });
165
+ }
166
+ // A change of a number closes the covers of a covered page.
167
+ function set(r, v) { s[r] = v; if (spec.cover) s.open = false; fig?.paint(true); refresh(); }
168
+
169
+ // The panel holds a slider or a stepper for each number that has one, the button of a covered page and the readouts.
170
+ function drawPanel() {
171
+ const ctls = isCards(spec) ? [] : ROWS.filter(r => spec[`${r}Ctl`]).map(r => {
172
+ const c = spec[`${r}Ctl`], opts = { id: r, label: T(`order-${r}`), min: c.lo, max: c.hi, value: s[r], write: int };
173
+ if (c.kind === 'stepper') return stepper({ ...opts, change: v => set(r, v) });
174
+ const sl = slider({ ...opts, input: v => set(r, v) }); sl.width(3);
175
+ return sl;
176
+ });
177
+ // New numbers puts three other cards in the tray and empties the places.
178
+ if (spec.draw) ctls.push(button({ label: T('new-numbers'), act: 'new-numbers', press: () => { s = { ...opening(spec), cards: drawCards(dice(fresh()), s.cards) }; build(); } }));
179
+ reveal = spec.cover ? button({ label: T('show-rows'), act: 'reveal', primary: true, press: () => { s.open = true; fig?.paint(true); refresh(); } }) : null;
180
+ // The line of words takes a line of the panel to itself, so the panel keeps its height as the words change.
181
+ chips = spec.readout.map(id => chip({ id, label: T(`order-${id}`) ?? T(`match-${id}`), cls: id === 'reading' ? 'counters-chip-wide' : '' }));
182
+ for (const k of chips) if (k.id !== 'reading') k.width(k.id === 'verdict' ? 5 : 3);
183
+ panel.replaceChildren(...[ctls.length ? line('ctls', ctls) : null, reveal ? line('acts', [reveal]) : null, chips.length ? line('out', chips) : null].filter(Boolean));
184
+ }
185
+
186
+ function point(id, on) {
187
+ if (!spec) return;
188
+ for (const part of svg.querySelectorAll(`[data-ref="${id}"]`)) part.classList.toggle('counters-hot', on);
189
+ for (const part of panel.querySelectorAll('[data-ref]')) part.classList.toggle('hot', on && part.dataset.ref === id);
190
+ }
191
+
192
+ return {
193
+ // A page that asks for a draw and names no cards opens on a draw, a new one each time.
194
+ show(page) { spec = page; s = opening(spec); if (spec.draw && !spec.cards) s.cards = drawCards(dice(fresh())); drawPanel(); build(); if (!fig) refresh(); },
195
+ hide() { for (const c of cards) c.tween?.pause(); cards = []; spec = null; fig = null; svg.replaceChildren(); },
196
+ point,
197
+ lang() { if (!spec) return; drawPanel(); build(); if (!fig) refresh(); },
198
+ };
199
+ }
@@ -0,0 +1,62 @@
1
+ // The Node half of the order scene: two numbers compared on one count or as two blocks, and three cards put in
2
+ // order. It checks a page's fields and says what each link shows when the page opens.
3
+ import { schema } from '@openbooknetwork/kitap';
4
+ import { SHOWS, TOP, CARDS, opening, counts, measuresOf, readingOf, verdictOf } from './order-model.js';
5
+ import { SIGNS } from './reading.js';
6
+ import { numbers } from '../../kit/format.js';
7
+ import { list, value, string } from '../../node.mjs';
8
+
9
+ const { z, check } = schema;
10
+ const Int = z.number().int();
11
+ const Range = z.tuple([Int, Int]);
12
+ const Num = z.union([Int, z.object({ slider: Range, start: Int.optional() }).strict(), z.object({ stepper: Range, start: Int.optional() }).strict()]);
13
+ const Fields = z.object({
14
+ show: z.enum(SHOWS).optional(), // Two markers on one count of 100, or two blocks of rows of ten.
15
+ top: Num.optional(), // The red number, as a number or on a slider or a stepper.
16
+ bottom: Num.optional(), // The blue number.
17
+ reading: z.boolean().default(false), // A line of words states the comparison.
18
+ decide: z.boolean().default(false), // A frame surrounds the rows of the blocks that decide.
19
+ cover: z.boolean().default(false), // Covers hide the blocks until the reader asks for the rows.
20
+ sign: z.enum(SIGNS).optional(), // A sign tile between the two numbers of the blocks, opening on this sign.
21
+ cards: z.array(Int).optional(), // Three numbers on cards for the reader to put in order.
22
+ // A New numbers button draws three other cards. A page with draw and no cards opens on a draw too.
23
+ draw: z.boolean().default(false),
24
+ readout: z.array(z.string()).default([]),
25
+ }).strict();
26
+
27
+ function read(fields, { at }, ctx) {
28
+ const pg = check(Fields, fields, at), fail = words => ctx.fail(at, words);
29
+ const top = value(pg.top), bottom = value(pg.bottom);
30
+ const spec = { ...pg, scene: 'order', top: top.n, topCtl: top.ctl, bottom: bottom.n, bottomCtl: bottom.ctl };
31
+ if (pg.cards || pg.draw) {
32
+ if (pg.cards && (pg.cards.length !== CARDS || new Set(pg.cards).size !== CARDS || pg.cards.some(n => n < 0 || n > TOP))) fail(`cards is ${JSON.stringify(pg.cards)}, write ${CARDS} different numbers from 0 to ${TOP}, such as [63, 36, 39]`);
33
+ for (const f of ['top', 'bottom', 'show']) if (pg[f] !== undefined) fail(`${f} belongs to pages with two numbers, leave it out of a page with cards`);
34
+ for (const f of ['reading', 'decide', 'cover', 'sign']) if (pg[f]) fail(`${f} belongs to pages with two numbers, leave it out of a page with cards`);
35
+ } else {
36
+ if (!pg.show) fail(`show is missing, write how the two numbers are drawn: ${list(SHOWS)}, or give the page cards or draw: true`);
37
+ const low = pg.show === 'count' ? 1 : 0;
38
+ for (const [v, name] of [[top, 'top'], [bottom, 'bottom']]) {
39
+ if (v.n == null) { fail(`${name} is missing, write the ${name} number, such as 18, or { slider: [${low}, ${TOP}], start: 18 }`); continue; }
40
+ const lo = v.ctl?.lo ?? v.n, hi = v.ctl?.hi ?? v.n;
41
+ if (lo > hi || v.n < lo || v.n > hi) fail(`${name} has the range [${lo}, ${hi}] and starts at ${v.n}, write [low, high] and a start between them`);
42
+ else if (lo < low || hi > TOP) fail(`${name} reaches ${v.ctl ? `[${lo}, ${hi}]` : v.n}, ${pg.show === 'count' ? 'a marker stands on a counter' : 'a block holds a number'} from ${low} to ${TOP}`);
43
+ }
44
+ for (const f of ['decide', 'cover']) if (pg[f] && pg.show !== 'blocks') fail(`${f} belongs to the rows of two blocks, write show: blocks`);
45
+ if (pg.sign && pg.show !== 'blocks') fail('sign stands between the numbers of two blocks, write show: blocks');
46
+ if (pg.sign && pg.cover) fail('sign says whether the line is true, which gives away what cover hides, keep one');
47
+ }
48
+ const ids = measuresOf(spec);
49
+ for (const id of pg.readout) if (!ids.includes(id)) fail(`readout names "${id}", this page reads out ${list(ids) || 'nothing'}`);
50
+ return { data: spec, has: id => ids.includes(id), offers: ids.length ? `one of ${list(ids)}` : 'nothing, the cards carry their numbers' };
51
+ }
52
+
53
+ // A link shows a number or the line of words as the page opens.
54
+ function start(spec, lang, id) {
55
+ if (!measuresOf(spec).includes(id)) return null;
56
+ const s = opening(spec), int = numbers(lang).int;
57
+ if (id === 'reading') return string(lang, `counters_${readingOf(spec, s)}`, { a: int(s.top), b: int(s.bottom) });
58
+ if (id === 'verdict') return string(lang, `counters_${verdictOf(spec, s)}`);
59
+ return int(counts(spec, s)[id]);
60
+ }
61
+
62
+ export default { read, start };
@@ -0,0 +1,66 @@
1
+ // How two numbers compare, in a sign and in words: the three signs, the line of words such as "18 is less than 25",
2
+ // and whether a line with a sign is true. match-model.js and order-model.js take the rules from here, so the build
3
+ // and the browser agree, and match.js and order.js draw the line, the sign tile and the mark with the parts below.
4
+ import { svg as el } from '../../kit/dom.js';
5
+
6
+ // relation says how a stands to b: less, same or greater.
7
+ export const relation = (a, b) => a < b ? 'less' : a > b ? 'greater' : 'same';
8
+ // The signs in the order a tap on the tile goes through them, and the sign that makes a true line of a and b.
9
+ export const SIGNS = ['<', '=', '>'];
10
+ export const signOf = (a, b) => a < b ? '<' : a > b ? '>' : '=';
11
+ export const nextSign = sign => SIGNS[(SIGNS.indexOf(sign) + 1) % SIGNS.length];
12
+ // A page's sign field is one of the signs for a tile the reader taps, or follow for a sign the scene keeps true.
13
+ export const SIGN_FIELD = [...SIGNS, 'follow'];
14
+ export const isTile = spec => SIGNS.includes(spec.sign);
15
+ // signShown gives the sign a line shows: the tile's, or the true one on a follow page. A page without a sign has none.
16
+ export const signShown = (spec, s) => isTile(spec) ? s.sign : spec.sign === 'follow' ? signOf(s.top, s.bottom) : null;
17
+
18
+ const WORDS = { '<': 'less', '=': 'equal', '>': 'greater' };
19
+ // The string of the line of words, which takes the two numbers as {a} and {b}. A line with a sign reads the sign,
20
+ // so equal numbers read "is equal to" and a false line reads as it is written. Without a sign the line states how
21
+ // the numbers stand, and equal numbers read "is the same as".
22
+ export const readingKey = (a, b, sign) => `reading-${sign ? WORDS[sign] : relation(a, b)}`;
23
+ // The string of the mark beside a line with a sign tile: true or false.
24
+ export const verdictKey = (a, b, sign) => `verdict-${signOf(a, b) === sign}`;
25
+
26
+ // readingLine makes the line of words as a part of a figure, with its middle at x, y. say writes its words, and
27
+ // show puts it on or off the figure.
28
+ export function readingLine(x, y) {
29
+ const text = el('text', { class: 'counters-reading', 'data-ref': 'reading', x, y });
30
+ return { el: text, say(words) { if (text.textContent !== words) text.textContent = words; }, show(on) { text.setAttribute('display', on ? 'inline' : 'none'); } };
31
+ }
32
+
33
+ // signTile makes the sign between two numbers, with its middle at 0, 0 of its own group. set writes the sign and
34
+ // says whether it changed. open makes it a tile the reader taps, named by label. reach is the width of the square
35
+ // that takes a touch, which a figure drawn small makes wider.
36
+ export function signTile(reach = 64) {
37
+ const text = el('text', { class: 'counters-sign-tile-text' }), pop = el('g', { class: 'a' }, [el('rect', { class: 'counters-sign-tile-box', x: -26, y: -26, width: 52, height: 52, rx: 9 }), text]);
38
+ // The tile takes a touch a little past its box, so it is about 44px across on a phone.
39
+ const hit = el('rect', { class: 'counters-hit', x: -reach / 2, y: -reach / 2, width: reach, height: reach });
40
+ const g = el('g', { class: 'counters-sign-tile' }, [hit, pop]);
41
+ return {
42
+ el: g, pop,
43
+ set(sign) { if (text.textContent === sign) return false; text.textContent = sign; return true; },
44
+ open(on, label) {
45
+ g.classList.toggle('counters-sign-tile-open', on);
46
+ for (const [name, v] of [['tabindex', 0], ['role', 'button'], ['aria-label', label]]) if (on) g.setAttribute(name, v); else g.removeAttribute(name);
47
+ },
48
+ };
49
+ }
50
+
51
+ // verdictMark makes the mark beside a line: a tick or a cross with the word true or false. It starts at 0, 0 of
52
+ // its own group and runs to the right.
53
+ export function verdictMark() {
54
+ const sign = el('path', { class: 'counters-mark-sign' }), text = el('text', { class: 'counters-mark-word', x: 26 });
55
+ const g = el('g', { class: 'counters-mark', 'data-ref': 'verdict' }, [sign, text]);
56
+ return {
57
+ el: g,
58
+ set(ok, words) {
59
+ g.classList.toggle('counters-mark-true', ok); g.classList.toggle('counters-mark-false', !ok);
60
+ sign.setAttribute('d', ok ? 'M 1 0 l 6 7 l 12 -14' : 'M 2 -8 l 16 16 M 18 -8 l -16 16');
61
+ if (text.textContent === words) return false;
62
+ text.textContent = words; return true;
63
+ },
64
+ show(on) { g.setAttribute('display', on ? 'inline' : 'none'); },
65
+ };
66
+ }
@@ -0,0 +1,18 @@
1
+ // The scenes of a family share one stage, and one of them shows at a time. A scene adds its svg to the stage as it
2
+ // is made. A scene off show takes its svg off the stage, so the scene on show gets every touch.
3
+ export function scenes(makers, stage) {
4
+ // made holds each scene once it has been made, with its svg, and now is the scene on show.
5
+ const made = {};
6
+ let now = null;
7
+ const make = name => { const scene = makers[name](); return { scene, svg: stage.lastElementChild }; };
8
+ const off = () => { if (!now) return; now.scene.hide(); now.svg.setAttribute('display', 'none'); now = null; };
9
+ return {
10
+ show(name, ...page) {
11
+ const next = made[name] ??= make(name);
12
+ if (now !== next) off();
13
+ now = next; now.svg.removeAttribute('display'); now.scene.show(...page);
14
+ },
15
+ hide: off,
16
+ now: () => now?.scene ?? null,
17
+ };
18
+ }
@@ -0,0 +1,118 @@
1
+ /* line: the colours are theme tokens and the two point colours of the family, so a theme switch needs no redraw. */
2
+ .hesap-line .line-svg{position:absolute;left:0;top:0;width:100%;height:100%;touch-action:none;font-family:var(--body);overflow:hidden}
3
+ .hesap-line text{fill:var(--ink);text-anchor:middle;dominant-baseline:central;pointer-events:none;font-variant-numeric:tabular-nums}
4
+ .hesap-line .line-c-point{--c:var(--z-line-point,#d1453b)}
5
+ .hesap-line .line-c-second{--c:var(--z-line-second,#2a6bd1)}
6
+ /* The flag of the number to find is ink, apart from both points' colours. */
7
+ .hesap-line .line-c-find{--c:var(--ink)}
8
+ .hesap-line .line-c-find .line-flag-text{fill:var(--paper)}
9
+
10
+ /* The line, its marks and their labels. */
11
+ .hesap-line .line-axis{stroke:var(--ink);stroke-width:2.5;stroke-linecap:round}
12
+ .hesap-line .line-mark{stroke:var(--ink);stroke-width:2;stroke-linecap:round}
13
+ .hesap-line .line-short{stroke:var(--ink-2);stroke-width:1.5}
14
+ .hesap-line .line-label{font-weight:400;font-variant-numeric:proportional-nums}
15
+ .hesap-line .line-label.line-lit{font-weight:700;fill:var(--accent)}
16
+ .hesap-line .line-guide{stroke:var(--ink-2);stroke-width:1;stroke-dasharray:2 4;opacity:.6}
17
+
18
+ /* A point is a disc or a square with a touch target round it, and its flag carries its number. */
19
+ .hesap-line .line-hit{fill:transparent}
20
+ .hesap-line .line-point{cursor:grab;outline:none}
21
+ .hesap-line .line-point.drag{cursor:grabbing}
22
+ .hesap-line .line-dot{fill:var(--c);stroke:var(--paper);stroke-width:2}
23
+ .hesap-line .line-point:focus-visible .line-hit{stroke:var(--accent);stroke-width:2.5}
24
+ .hesap-line .line-pole{stroke:var(--c);stroke-width:2}
25
+ .hesap-line .line-flag-box{fill:var(--c);stroke:var(--paper);stroke-width:1.5}
26
+ .hesap-line .line-flag-text{font-size:14px;font-weight:700;fill:#fff}
27
+
28
+ /* The jumps are arcs over the gaps they cross, with a head that shows their way. */
29
+ .hesap-line .line-arc{fill:none;stroke:var(--accent);stroke-width:2.5;stroke-linecap:round}
30
+ .hesap-line .line-arc-head{fill:var(--accent)}
31
+
32
+ /* The lens shows the marks around the point at full size, above a line whose gaps are too narrow to read. */
33
+ .hesap-line .line-lens{pointer-events:none}
34
+ .hesap-line .line-lens-box{fill:var(--panel);stroke:var(--ink-2);stroke-width:1.5}
35
+ .hesap-line .line-lens-tip{fill:var(--ink-2)}
36
+
37
+ /* The bracket over the tens round the point. */
38
+ .hesap-line .line-bracket{fill:none;stroke:var(--accent);stroke-width:2.5;stroke-linejoin:round;stroke-linecap:round}
39
+
40
+ /* A gap opens under the line as a line of its own. */
41
+ .hesap-line .line-gap{fill:transparent;cursor:pointer;outline:none}
42
+ .hesap-line .line-gap:hover,.hesap-line .line-gap[aria-pressed="true"]{fill:var(--accent);fill-opacity:.08}
43
+ .hesap-line .line-gap:focus-visible{stroke:var(--accent);stroke-width:2}
44
+ .hesap-line .line-open-gap{stroke:var(--accent);stroke-width:5;stroke-linecap:round}
45
+ .hesap-line .line-funnel{stroke:var(--ink-2);stroke-width:1;stroke-dasharray:3 3}
46
+
47
+ /* Blank label boxes and the label cards that fill them. */
48
+ .hesap-line .line-blank{fill:var(--paper);stroke:var(--ink-2);stroke-width:1.5;stroke-dasharray:4 3}
49
+ .hesap-line .line-card{cursor:grab;outline:none}
50
+ .hesap-line .line-card.drag{cursor:grabbing}
51
+ .hesap-line .line-card-box{fill:var(--panel);stroke:var(--ink);stroke-width:1.5}
52
+ .hesap-line .line-card-num{font-size:16px;font-weight:700}
53
+
54
+ /* The middle's long mark. */
55
+ .hesap-line .line-middle{stroke:var(--accent);stroke-width:2.5}
56
+
57
+ /* The street: a road, a house at each mark, door numbers on plaques, and the van as the point. */
58
+ .hesap-line .line-road{fill:color-mix(in srgb,var(--ink) 22%,var(--paper))}
59
+ .hesap-line .line-house-body{fill:color-mix(in srgb,#d99a1f 30%,var(--paper));stroke:var(--ink-2);stroke-width:1}
60
+ .hesap-line .line-door{fill:var(--ink-2)}
61
+ .hesap-line .line-plaque rect{fill:var(--paper);stroke:var(--ink);stroke-width:1.2}
62
+ .hesap-line .line-plaque text{font-weight:700}
63
+ .hesap-line .line-wheel{fill:var(--ink)}
64
+ .hesap-line .line-van-tip{fill:var(--c)}
65
+ .hesap-line .line-van-num{font-size:10px;font-weight:700;fill:#fff}
66
+ .hesap-line .line-card:focus-visible .line-card-box{stroke:var(--accent);stroke-width:3}
67
+
68
+ /* The estimate mark is pale, apart from the point and the marks. */
69
+ .hesap-line .line-estimate line{stroke:var(--accent);stroke-width:3;stroke-linecap:round;opacity:.55;stroke-dasharray:4 3}
70
+ .hesap-line .line-estimate path{fill:var(--accent);opacity:.55}
71
+ .hesap-line .line-fixed .line-dot{fill:var(--c);stroke:var(--paper);stroke-width:2}
72
+
73
+ /* The book: the edge of its pages between its covers, and the bookmark. */
74
+ .hesap-line .line-book-pages{fill:color-mix(in srgb,#f3e6c4 80%,var(--paper));stroke:var(--ink-2);stroke-width:1}
75
+ .hesap-line .line-book-leaf{stroke:var(--ink-2);stroke-width:.6;opacity:.5}
76
+ .hesap-line .line-book-cover{fill:color-mix(in srgb,#2a6bd1 60%,var(--ink))}
77
+
78
+ /* The touch band of a mark that the reader drags into place. */
79
+ .hesap-line .line-band{fill:transparent}
80
+ .hesap-line .line-handle{cursor:ew-resize;outline:none}
81
+ .hesap-line .line-mark-key{outline:none}
82
+ .hesap-line .line-handle.line-focus .line-band{stroke:var(--accent);stroke-width:2;fill:var(--accent);fill-opacity:.06}
83
+
84
+ /* The start of the jumps: a ring round its mark, and the point that moves by the buttons alone inside it. */
85
+ .hesap-line .line-ring{fill:none;stroke:var(--c);stroke-width:3}
86
+ .hesap-line .line-start.line-moves{cursor:grab;outline:none}
87
+ .hesap-line .line-start:focus-visible .line-hit{stroke:var(--accent);stroke-width:2.5}
88
+ .hesap-line .line-start.line-hot .line-ring{stroke-width:5}
89
+ .hesap-line .line-fixed{pointer-events:none}
90
+ .hesap-line .line-chip-wide{flex-basis:100%}
91
+
92
+ /* The words under the line. */
93
+ .hesap-line .line-reading{font-size:20px;font-weight:700}
94
+
95
+ /* The pond of the opening pages: the water, the bank, the stones and the frog. */
96
+ .hesap-line .line-water{fill:color-mix(in srgb,#2a8bd1 20%,var(--paper));stroke:none}
97
+ .hesap-line .line-bank{fill:color-mix(in srgb,#4a9d4f 40%,var(--paper));stroke:color-mix(in srgb,#4a9d4f 70%,var(--paper));stroke-width:2}
98
+ .hesap-line .line-stone-body{fill:color-mix(in srgb,var(--ink) 16%,var(--paper));stroke:var(--ink-2);stroke-width:1.5}
99
+ .hesap-line .line-stone-num{font-weight:700}
100
+ .hesap-line .line-frog-body,.hesap-line .line-frog-leg{fill:#3f9a46;stroke:#24622a;stroke-width:1.5}
101
+ .hesap-line .line-frog-eye{fill:#fff;stroke:#24622a;stroke-width:1.5}
102
+ .hesap-line .line-frog-pupil{fill:#1d1d1d}
103
+ .hesap-line .line-frog-mouth{fill:none;stroke:#24622a;stroke-width:1.5;stroke-linecap:round}
104
+
105
+ /* A part the text points at stands out. */
106
+ .hesap-line .line-hot .line-dot,.hesap-line .line-hot .line-flag-box{stroke:var(--accent);stroke-width:3}
107
+ .hesap-line .line-arcs.line-hot .line-arc{stroke-width:4}
108
+ .hesap-line .line-reading.line-hot{fill:var(--accent)}
109
+ .hesap-line .line-hot .line-frog-body{stroke:var(--accent);stroke-width:3}
110
+
111
+ /* The jump buttons keep to one row and show their sign large beside their name. */
112
+ .hesap-line .line-jumps{display:inline-flex;flex-wrap:nowrap;gap:.429rem}
113
+ .hesap-line .line-jump b{font-size:1.286rem;line-height:1}
114
+
115
+ @media (max-width:900px){
116
+ /* The figure ends above the peek card, which covers the foot of the stage until the reader closes it. */
117
+ .hesap-line .line-svg{height:calc(100% - var(--hesap-peek,0px))}
118
+ }
@@ -0,0 +1,12 @@
1
+ // The browser half of the line family. The family has one scene, the number line, so it hands every page to it.
2
+ import line from './line.js';
3
+
4
+ export default function family(api) {
5
+ const scene = line(api);
6
+ return {
7
+ show(spec, page) { scene.show(spec, page); },
8
+ hide() { scene.hide(); },
9
+ point(id, on) { scene.point(id, on); },
10
+ lang() { scene.lang(); },
11
+ };
12
+ }
@@ -0,0 +1,143 @@
1
+ // The parts of a line figure: the points with their flags, the arcs of the jumps, and the frog, the stones and the
2
+ // bank of the opening pages. Every part is drawn in pixels of the stage.
3
+ import { svg as el } from '../../kit/dom.js';
4
+
5
+ const HIT = 22; // The radius that takes a touch round a point, about 44px across.
6
+
7
+ // pointShape draws a point round 0, 0: a disc for the point and a smaller square for the second, so the disc shows
8
+ // round a square on the same mark. A hit area round it takes the touch.
9
+ export function pointShape(who, r) {
10
+ const shape = who === 'second'
11
+ ? el('rect', { class: 'line-dot', x: -r * 0.72, y: -r * 0.72, width: r * 1.44, height: r * 1.44, rx: 2 })
12
+ : el('circle', { class: 'line-dot', r });
13
+ return [el('circle', { class: 'line-hit', r: HIT }), shape];
14
+ }
15
+
16
+ // flag draws a pole up from a point and a box with the point's number at its top. set writes the number and the
17
+ // pole's length, so two flags over one place stand one above the other.
18
+ export function flag(who) {
19
+ const pole = el('line', { class: 'line-pole', x1: 0, x2: 0 }), box = el('rect', { class: 'line-flag-box', height: 24, rx: who === 'second' ? 3 : 12 });
20
+ const text = el('text', { class: 'line-flag-text' });
21
+ const g = el('g', { class: `line-flag line-c-${who}`, 'data-ref': who }, [pole, box, text]);
22
+ return {
23
+ el: g, width: words => 16 + 8.4 * words.length,
24
+ set(words, from, length) {
25
+ const w = 16 + 8.4 * words.length, top = from - length;
26
+ if (text.textContent !== words) text.textContent = words;
27
+ pole.setAttribute('y1', from); pole.setAttribute('y2', top);
28
+ box.setAttribute('x', -w / 2); box.setAttribute('width', w); box.setAttribute('y', top - 24);
29
+ text.setAttribute('x', 0); text.setAttribute('y', top - 12);
30
+ },
31
+ };
32
+ }
33
+
34
+ // arc draws a jump from x1 to x2 at height y, rising h above it, or dipping h below it with down, with a head at
35
+ // its end that shows the way it went.
36
+ export function arc(x1, x2, y, h, down) {
37
+ const cy = down ? y + 2 * h : y - 2 * h, mx = (x1 + x2) / 2;
38
+ const a = Math.atan2(y - cy, x2 - mx), len = Math.max(4, Math.min(7, Math.abs(x2 - x1) * 0.3)), wide = len * 0.57;
39
+ const bx = x2 - len * Math.cos(a), by = y - len * Math.sin(a), nx = -Math.sin(a) * wide, ny = Math.cos(a) * wide;
40
+ return {
41
+ path: el('path', { class: 'line-arc', d: `M ${x1} ${y} Q ${mx} ${cy} ${x2} ${y}`, pathLength: 1 }),
42
+ head: el('path', { class: 'line-arc-head', d: `M ${x2} ${y} L ${bx + nx} ${by + ny} L ${bx - nx} ${by - ny} Z` }),
43
+ };
44
+ }
45
+
46
+ // frog draws the frog standing on 0, 0, size pixels tall.
47
+ export function frog(size) {
48
+ const k = size / 33, at = (x, y) => ({ cx: x * k, cy: y * k });
49
+ return el('g', { class: 'line-frog' }, [
50
+ el('circle', { class: 'line-hit', cy: -size / 2, r: Math.max(HIT, size / 2) }),
51
+ el('ellipse', { class: 'line-frog-leg', ...at(-11, -4), rx: 8 * k, ry: 4 * k }),
52
+ el('ellipse', { class: 'line-frog-leg', ...at(11, -4), rx: 8 * k, ry: 4 * k }),
53
+ el('ellipse', { class: 'line-frog-body', ...at(0, -14), rx: 14 * k, ry: 12 * k }),
54
+ ...[-7, 7].flatMap(x => [el('circle', { class: 'line-frog-eye', ...at(x, -27), r: 5.5 * k }), el('circle', { class: 'line-frog-pupil', ...at(x, -27.5), r: 2.4 * k })]),
55
+ el('path', { class: 'line-frog-mouth', d: `M ${-6 * k} ${-12 * k} Q 0 ${-8 * k} ${6 * k} ${-12 * k}` }),
56
+ ]);
57
+ }
58
+
59
+ // stone draws a stepping stone round x, y, w wide, with its number on it.
60
+ export function stone(x, y, w, words, size) {
61
+ return el('g', { class: 'line-stone' }, [
62
+ el('ellipse', { class: 'line-stone-body', cx: x, cy: y, rx: w / 2, ry: w * 0.3 }),
63
+ el('text', { class: 'line-stone-num', x, y, 'font-size': size }, [words]),
64
+ ]);
65
+ }
66
+
67
+ // pond draws the water under the stones from x1 to x2 and from y1 to y2, and the bank, which ends at bank.
68
+ export function pond(x1, x2, y1, y2, bank) {
69
+ return [
70
+ el('rect', { class: 'line-water', x: x1, y: y1, width: x2 - x1, height: y2 - y1, rx: 10 }),
71
+ el('path', { class: 'line-bank', d: `M 0 ${y1 - 6} L ${bank - 8} ${y1 - 6} Q ${bank + 6} ${(y1 + y2) / 2} ${bank - 8} ${y2 + 6} L 0 ${y2 + 6} Z` }),
72
+ ];
73
+ }
74
+
75
+ // bracket draws the bracket over the line from the ten before the point to the ten after it, plain with no mark
76
+ // between its ends, as two halves that the text can point at one by one. set moves it from x1 to x2 at height y, or
77
+ // hides it with null.
78
+ export function bracket() {
79
+ const before = el('path', { class: 'line-bracket', 'data-ref': 'ten-before' }), after = el('path', { class: 'line-bracket', 'data-ref': 'ten-after' });
80
+ const g = el('g', {}, [before, after]);
81
+ return {
82
+ el: g,
83
+ set(x1, x2, y) {
84
+ g.setAttribute('display', x1 === null ? 'none' : 'inline');
85
+ if (x1 === null) return;
86
+ const m = (x1 + x2) / 2, top = y - 10;
87
+ before.setAttribute('d', `M ${x1} ${y} V ${top} H ${m}`);
88
+ after.setAttribute('d', `M ${x2} ${y} V ${top} H ${m}`);
89
+ },
90
+ };
91
+ }
92
+
93
+ export const BOX = { w: 40, h: 26 }; // An empty label box, and a label card a little larger.
94
+ export const CARD = { w: 46, h: 34 };
95
+ // blankBox draws an empty label box round x, y, narrower where the gaps are narrow.
96
+ export const blankBox = (x, y, w) => el('rect', { class: 'line-blank', x: x - w / 2, y: y - BOX.h / 2, width: w, height: BOX.h, rx: 5 });
97
+ // card draws a label card round 0, 0 with its number, and a hit area about 44px tall.
98
+ export const card = words => [
99
+ el('rect', { class: 'line-hit', x: -CARD.w / 2, y: -24, width: CARD.w, height: 48 }),
100
+ el('rect', { class: 'line-card-box', x: -CARD.w / 2, y: -CARD.h / 2, width: CARD.w, height: CARD.h, rx: 6 }),
101
+ el('text', { class: 'line-card-num' }, [words]),
102
+ ];
103
+
104
+ // house draws a house standing on x, y, w wide and h tall, with a door. A house with a number carries it on a
105
+ // plaque over its door, which plaque draws at size font.
106
+ export function house(x, y, w, h) {
107
+ const roof = h * 0.4, d = Math.max(2, w * 0.28);
108
+ return el('g', { class: 'line-house' }, [
109
+ el('path', { class: 'line-house-body', d: `M ${x - w / 2} ${y} V ${y - h + roof} L ${x} ${y - h} L ${x + w / 2} ${y - h + roof} V ${y} Z` }),
110
+ el('rect', { class: 'line-door', x: x - d / 2, y: y - Math.min(h * 0.45, h - roof), width: d, height: Math.min(h * 0.45, h - roof) }),
111
+ ]);
112
+ }
113
+ export function plaque(x, y, words, font) {
114
+ const w = 8 + 0.62 * font * words.length;
115
+ return el('g', { class: 'line-plaque' }, [el('rect', { x: x - w / 2, y: y - font * 0.75, width: w, height: font * 1.5, rx: 3 }), el('text', { x, y, 'font-size': font }, [words])]);
116
+ }
117
+ // van draws a small van on the road in front of the houses, round 0, dy, with a marker that points at its house, the
118
+ // number of its house on its side and a hit area about 44px across. say writes the number, or takes it away with null.
119
+ export function van(dy) {
120
+ const words = el('text', { class: 'line-van-num', x: -2, y: dy });
121
+ const g = [
122
+ el('rect', { class: 'line-hit', x: -22, y: dy - 22, width: 44, height: 44 }),
123
+ el('path', { class: 'line-van-tip', d: `M -4 ${dy - 8} L 0 ${dy - 13} L 4 ${dy - 8} Z` }),
124
+ el('path', { class: 'line-dot', d: `M -13 ${dy + 6} V ${dy - 7} H 6 L 13 ${dy - 1} V ${dy + 6} Z` }),
125
+ el('circle', { class: 'line-wheel', cx: -8, cy: dy + 7, r: 2.6 }), el('circle', { class: 'line-wheel', cx: 8, cy: dy + 7, r: 2.6 }),
126
+ words,
127
+ ];
128
+ return { nodes: g, say(n) { words.textContent = n ?? ''; } };
129
+ }
130
+
131
+ // book draws the edge of a closed book from x1 to x2 at height y: the edge of its pages between its two covers,
132
+ // with no mark along it.
133
+ export const book = (x1, x2, y) => [
134
+ el('rect', { class: 'line-book-pages', x: x1, y: y - 9, width: x2 - x1, height: 18 }),
135
+ el('line', { class: 'line-book-leaf', x1, x2, y1: y - 3, y2: y - 3 }), el('line', { class: 'line-book-leaf', x1, x2, y1: y + 3, y2: y + 3 }),
136
+ el('rect', { class: 'line-book-cover', x: x1 - 7, y: y - 12, width: 7, height: 24, rx: 2 }),
137
+ el('rect', { class: 'line-book-cover', x: x2, y: y - 12, width: 7, height: 24, rx: 2 }),
138
+ ];
139
+ // bookmark draws a ribbon that stands top pixels above the edge round 0, 0, with a hit area about 44px across.
140
+ export const bookmark = top => [
141
+ el('rect', { class: 'line-hit', x: -22, y: -top - 6, width: 44, height: top + 20 }),
142
+ el('path', { class: 'line-dot', d: `M -6 8 V ${-top} L 0 ${-top + 6} L 6 ${-top} V 8 Z` }),
143
+ ];