@openbooknetwork/hesap 0.3.0 → 0.3.2

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 (40) hide show
  1. package/package.json +1 -1
  2. package/src/client.css +168 -0
  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 +51 -12
  9. package/src/families/counters/client.css +40 -0
  10. package/src/families/counters/client.js +2 -1
  11. package/src/families/counters/count.js +4 -5
  12. package/src/families/counters/counter.js +14 -0
  13. package/src/families/counters/figures.js +12 -4
  14. package/src/families/counters/goals.js +1 -9
  15. package/src/families/counters/i18n/en.yaml +89 -45
  16. package/src/families/counters/i18n/tr.yaml +56 -12
  17. package/src/families/counters/index.mjs +5 -3
  18. package/src/families/counters/match-model.js +10 -1
  19. package/src/families/counters/match.js +31 -11
  20. package/src/families/counters/match.mjs +7 -1
  21. package/src/families/line/client.css +118 -0
  22. package/src/families/line/client.js +12 -0
  23. package/src/families/line/figures.js +143 -0
  24. package/src/families/line/goals.js +168 -0
  25. package/src/families/line/i18n/en.yaml +61 -0
  26. package/src/families/line/i18n/tr.yaml +61 -0
  27. package/src/families/line/index.mjs +227 -0
  28. package/src/families/line/lens.js +49 -0
  29. package/src/families/line/line.js +624 -0
  30. package/src/families/line/model.js +219 -0
  31. package/src/families.mjs +2 -1
  32. package/src/i18n/en.yaml +158 -46
  33. package/src/i18n/tr.yaml +124 -12
  34. package/src/kit/i18n/en.yaml +8 -1
  35. package/src/kit/i18n/tr.yaml +7 -0
  36. package/src/kit/kit.css +9 -0
  37. package/src/kit/panel.js +2 -0
  38. package/src/kit/random.js +9 -0
  39. package/src/kit/written.js +70 -0
  40. package/src/node.mjs +3 -1
@@ -1,12 +1,14 @@
1
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.
2
+ // count scene counts objects one by one, the match scene pairs two rows, the order scene compares numbers, and the
3
+ // add scene joins two groups and writes their sum. It checks a page's fields against its scene and says what each
4
+ // link shows when the page opens.
4
5
  import { schema } from '@openbooknetwork/kitap';
5
6
  import { LOOKS, modeOf, capOf, opening, counts, measuresOf } from './model.js';
6
7
  import { GOALS, challengeStart } from './goals.js';
7
8
  import count from './count.mjs';
8
9
  import match from './match.mjs';
9
10
  import order from './order.mjs';
11
+ import add from './add.mjs';
10
12
  import { numbers } from '../../kit/format.js';
11
13
  import { list, challenge, drawn, value } from '../../node.mjs';
12
14
 
@@ -96,7 +98,7 @@ function startBonds(spec, lang, id) {
96
98
 
97
99
  // Each scene checks its own fields, so the family's schema lets every field through to the scene.
98
100
  const Fields = z.object({}).passthrough();
99
- const SCENES = { bonds: { read: readBonds, start: startBonds }, count, match, order };
101
+ const SCENES = { bonds: { read: readBonds, start: startBonds }, count, match, order, add };
100
102
  const read = ({ scene, ...fields }, info, ctx) => SCENES[scene].read(fields, info, ctx);
101
103
  const start = (spec, lang, id) => SCENES[spec.scene].start(spec, lang, id);
102
104
 
@@ -1,6 +1,7 @@
1
1
  // What a match page holds and what it counts: two rows of objects and the pairs between them. The build and the
2
2
  // browser both use this file, so a page's text and its live values agree.
3
3
  import { isTile, signShown, readingKey, verdictKey } from './reading.js';
4
+ import { MINUS } from '../../kit/written.js';
4
5
 
5
6
  // 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
7
  // a game of musical chairs, or as the two scores of a scoreboard with a ball for each goal.
@@ -74,7 +75,7 @@ export const tagKey = w => w.n == null ? `tag-${w.word}` : `tag-${w.word}-n`;
74
75
  // The measures a page can read out and link in its text. The words of the tags are linked and take no readout.
75
76
  export function measuresOf(spec) {
76
77
  if (spec.challenge) return [];
77
- const signed = [...(spec.sign ? ['reading'] : []), ...(isTile(spec) ? ['verdict'] : [])];
78
+ const signed = [...(spec.sign ? ['reading'] : []), ...(isTile(spec) ? ['verdict'] : []), ...(spec.written ? ['written', 'reading'] : [])];
78
79
  if (spec.look === 'chairs' || spec.look === 'scoreboard') return ['top', 'bottom', ...signed];
79
80
  return ['unpaired', 'pairs', 'top', 'bottom', ...signed, ...(spec.tap ? ['counted'] : []), ...(spec.trace ? ['added', 'taken'] : [])];
80
81
  }
@@ -82,3 +83,11 @@ export const wordsLinked = spec => spec.word === true ? ['top-word', 'bottom-wor
82
83
  // The strings of the line of words and of the mark of a page with a sign, as the page stands.
83
84
  export const readingOf = (spec, s) => readingKey(s.top, s.bottom, signShown(spec, s));
84
85
  export const verdictOf = (spec, s) => verdictKey(s.top, s.bottom, signShown(spec, s));
86
+
87
+ // differenceOf gives the written line of the difference of the rows: the greater row's number minus the less row's,
88
+ // with its answer once one row has every counter paired, when the counters left over take their rings. greater
89
+ // names the row whose number comes first, the top row when the rows are equal.
90
+ export function differenceOf(spec, s) {
91
+ const greater = s.bottom > s.top ? 'bottom' : 'top', less = greater === 'top' ? 'bottom' : 'top';
92
+ return { line: { a: s[greater], sign: MINUS, b: s[less], open: !lone(spec, s).ringed }, greater, less };
93
+ }
@@ -1,18 +1,18 @@
1
1
  // The match scene: two rows of objects paired one to one. The reader draws a line between a counter of each row,
2
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
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';
4
+ import { ROWS, GOALS_MAX, idOf, roomOf, opening, linesOf, resize, step, lone, won, counts, same, wordsOf, tagKey, measuresOf, wordsLinked, readingOf, verdictOf, differenceOf } from './match-model.js';
5
+ import { writtenLine, words, reading } from '../../kit/written.js';
5
6
  import { signTile, verdictMark, isTile, nextSign, signShown, signOf } from './reading.js';
6
7
  import { counter, show, put, R, HIT } from './counter.js';
7
8
  import { rowsOf, cupsOf, scoreOf, BALL, GAP, CLOSE, WIDE } from './match-figures.js';
8
9
  import { MATCH_GOALS } from './match-goals.js';
9
- import { another } from './goals.js';
10
10
  import { carry, press } from './move.js';
11
11
  import { driver } from './driver.js';
12
12
  import { svg as el, svgPoint } from '../../kit/dom.js';
13
- import { stepper, slider, chip, button, row as line } from '../../kit/panel.js';
13
+ import { stepper, slider, chip, button, row as line, check } from '../../kit/panel.js';
14
14
  import { goalRow } from '../../kit/goal.js';
15
- import { dice, fresh } from '../../kit/random.js';
15
+ import { dice, fresh, another } from '../../kit/random.js';
16
16
  import { live } from '../../kit/text.js';
17
17
  import { numbers } from '../../kit/format.js';
18
18
 
@@ -39,7 +39,9 @@ export default function match({ host, stage, panel, T, lang, moving, motion: fx
39
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
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
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]);
42
+ // The written line of the difference of the rows, which stands where the line of a sign page stands.
43
+ const written = writtenLine();
44
+ const svg = el('svg', { class: 'counters-svg' }, [back, voids, wires, rings, lower, upper, tags.top.g, tags.bottom.g, rubber, word, signed, written.el]);
43
45
  stage.appendChild(svg);
44
46
  // spec is the page. s holds the counters of each row, the lines the reader drew and how far the Spacing slider
45
47
  // stands, from 0 to 1. geo holds the places of the figure, nodes the drawn object of each id, pick the counter a
@@ -57,7 +59,7 @@ export default function match({ host, stage, panel, T, lang, moving, motion: fx
57
59
 
58
60
  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
61
  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 });
62
+ : rowsOf({ top: roomOf(spec, 'top'), bottom: roomOf(spec, 'bottom'), ...gaps(), tag: tagRoom(), names: spec.trail ? NAMES : 0, line: spec.sign || spec.written ? SIGNED : undefined });
61
63
  // 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
64
  function gaps() {
63
65
  if (spec.spread) return { gap: { [spec.spread]: GAP * (1 + s.spread) }, widest: { [spec.spread]: 2 * GAP } };
@@ -96,6 +98,7 @@ export default function match({ host, stage, panel, T, lang, moving, motion: fx
96
98
  back.replaceChildren(...drawn.nodes, ...names);
97
99
  signed.setAttribute('display', geo.line && spec.sign ? 'inline' : 'none');
98
100
  if (geo.line) signed.setAttribute('transform', `translate(${geo.line.x} ${geo.line.y})`);
101
+ if (geo.line && spec.written) written.at(geo.w / 2, geo.line.y); else written.set(null);
99
102
  tile.open(isTile(spec), T('sign')); told.show(isTile(spec) && !cs);
100
103
  for (const card of cards) card.setAttribute('display', spec.hidden ? 'inline' : 'none');
101
104
  for (const n of nodes.values()) n.tween?.pause();
@@ -245,6 +248,7 @@ export default function match({ host, stage, panel, T, lang, moving, motion: fx
245
248
  const p = to.get(idOf('top', t)), q = to.get(idOf('bottom', b));
246
249
  return el('line', { class: 'counters-wire', 'data-ref': 'pairs', x1: p.x, y1: p.y, x2: q.x, y2: q.y });
247
250
  })));
251
+ lightPairs();
248
252
  const l = lone(spec, s), ids = l.ringed ? ROWS.flatMap(r => l[r].map(i => idOf(r, i))) : [];
249
253
  rings.replaceChildren(...ids.map(id => {
250
254
  const p = to.get(id), r = cups() ? (rowOf(id) === 'top' ? R + 9 : 1.5 * SAUCER + 6) : chairs() ? R + 8 : R + 3.5;
@@ -284,6 +288,11 @@ export default function match({ host, stage, panel, T, lang, moving, motion: fx
284
288
  }
285
289
  for (const [k, b] of goals.entries()) b.disabled = s[ROWS[k]] >= GOALS_MAX;
286
290
  }
291
+ if (spec.written) {
292
+ // The greater row's number comes first, in its row's colour, and the counters left over are the answer.
293
+ const d = differenceOf(spec, s), cls = r => `counters-${r === 'top' ? 'a' : 'b'}`;
294
+ if (written.set({ ...d.line, refs: { a: d.greater, b: d.less, c: 'unpaired' }, cls: { a: cls(d.greater), b: cls(d.less) } }, int) && anim) go.flash(written.el);
295
+ }
287
296
  // A challenge that writes the numbers of its rows once it is reached uses the tags for them.
288
297
  const ws = ends() ? Object.fromEntries(ROWS.map(r => [r, null])) : spec.word === true ? wordsOf(spec, s) : null;
289
298
  for (const r of ROWS) {
@@ -312,7 +321,8 @@ export default function match({ host, stage, panel, T, lang, moving, motion: fx
312
321
  // tags.
313
322
  function refresh() {
314
323
  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]);
324
+ const said = { reading: () => spec.written ? reading(differenceOf(spec, s).line, int, T) : T(readingOf(spec, s), { a: int(s.top), b: int(s.bottom) }),
325
+ written: () => words(differenceOf(spec, s).line, int), verdict: () => T(verdictOf(spec, s)) }, value = id => said[id]?.() ?? int(st[id]);
316
326
  for (const k of chips) if (k.set(value(k.id)) && moving()) go.flash(k.el);
317
327
  judge();
318
328
  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 });
@@ -342,20 +352,29 @@ export default function match({ host, stage, panel, T, lang, moving, motion: fx
342
352
  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
353
  if (scores()) ctls.push(...goals, button({ label: T('new-match'), act: 'new-match', press: () => { s = { ...opening(spec), spread: 0 }; changed(); } }));
344
354
  // 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);
355
+ chips = spec.readout.map(id => chip({ id, label: T(`match-${spec.trail ? 'trail' : spec.look}-${id}`) ?? T(`match-${id}`) ?? T(id), cls: ['reading', 'written'].includes(id) ? 'counters-chip-wide' : '' }));
356
+ for (const k of chips) if (!['reading', 'written'].includes(k.id)) k.width(k.id === 'verdict' ? 5 : 2);
347
357
  // A challenge has its line with Another one and a hint, and a Check button beside its controls.
348
358
  goal = null;
349
359
  if (cs) {
350
360
  const name = base.challenge.goal;
351
361
  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(); } } }));
362
+ ctls.push(check({ T, press: () => { if (!cs.checked) { cs.checked = true; render('move'); if (!geo) refresh(); } } }));
353
363
  }
354
364
  panel.replaceChildren(...[goal?.el, ctls.length ? line('ctls', ctls) : null, chips.length ? line('out', chips) : null].filter(Boolean));
355
365
  }
356
366
 
367
+ // pairsLit says the reader points at the link pairs, which lights each pair line and the counters at its ends.
368
+ let pairsLit = false;
369
+ function lightPairs() {
370
+ const paired = new Set(linesOf(spec, s).flatMap(([t, b]) => [idOf('top', t), idOf('bottom', b)]));
371
+ for (const [id, n] of nodes) n.g.classList.toggle('counters-paired-lit', pairsLit && paired.has(id));
372
+ for (const w of wires.children) w.classList.toggle('counters-hot', pairsLit);
373
+ }
357
374
  function point(id, on) {
358
375
  if (!spec) return;
376
+ written.light(id, on, ['written', 'reading']);
377
+ if (id === 'pairs') { pairsLit = on; lightPairs(); }
359
378
  for (const part of svg.querySelectorAll(`[data-ref="${id}"]`)) part.classList.toggle('counters-hot', on);
360
379
  for (const part of panel.querySelectorAll('[data-ref]')) part.classList.toggle('hot', on && part.dataset.ref === id);
361
380
  }
@@ -363,7 +382,7 @@ export default function match({ host, stage, panel, T, lang, moving, motion: fx
363
382
 
364
383
  return {
365
384
  show(page) {
366
- stop(); base = page; target = null; deal();
385
+ stop(); pairsLit = false; base = page; target = null; deal();
367
386
  drawPanel(); build();
368
387
  if (!geo) refresh();
369
388
  },
@@ -372,6 +391,7 @@ export default function match({ host, stage, panel, T, lang, moving, motion: fx
372
391
  for (const g of [back, voids, wires, rings, lower, upper]) g.replaceChildren();
373
392
  for (const g of [word, tags.top.g, tags.bottom.g, signed]) g.setAttribute('display', 'none');
374
393
  for (const r of ROWS) nums[r].textContent = '';
394
+ written.set(null);
375
395
  },
376
396
  point,
377
397
  lang() { if (!spec) return; const was = goal; drawPanel(); goal?.keep(was); build(); if (!geo) refresh(); },
@@ -1,7 +1,8 @@
1
1
  // The Node half of the match scene: two rows of objects paired one to one. It checks a page's fields and says what
2
2
  // each link shows when the page opens.
3
3
  import { schema } from '@openbooknetwork/kitap';
4
- import { MATCH_LOOKS, ROWS, ROW_MAX, SPREAD_MAX, PLAYERS, GOALS_MAX, roomOf, opening, counts, wordsOf, tagKey, measuresOf, wordsLinked, readingOf, verdictOf } from './match-model.js';
4
+ import { MATCH_LOOKS, ROWS, ROW_MAX, SPREAD_MAX, PLAYERS, GOALS_MAX, roomOf, opening, counts, wordsOf, tagKey, measuresOf, wordsLinked, readingOf, verdictOf, differenceOf } from './match-model.js';
5
+ import { words, reading } from '../../kit/written.js';
5
6
  import { SIGN_FIELD } from './reading.js';
6
7
  import { MATCH_GOALS, matchStart } from './match-goals.js';
7
8
  import { numbers } from '../../kit/format.js';
@@ -26,6 +27,8 @@ const Fields = z.object({
26
27
  trail: z.boolean().default(false), // The bottom row holds the top row as it was one step ago.
27
28
  // A line of the two numbers with a sign between them: a tile that opens on this sign, or a sign that follows.
28
29
  sign: z.enum(SIGN_FIELD).optional(),
30
+ // The written line of the difference of the rows under them, such as 11 − 7 = 4.
31
+ written: z.literal('difference').optional(),
29
32
  // A challenge names a goal of match-goals.js and the ranges it draws its rows from.
30
33
  challenge: z.object({ goal: z.string(), top: Range.optional(), bottom: Range.optional(), rows: Range.optional(), apart: Range.optional() }).strict().optional(),
31
34
  readout: z.array(z.string()).default([]),
@@ -43,6 +46,7 @@ function read(fields, { at }, ctx) {
43
46
  else if (lo < 0 || hi > ROW_MAX) fail(`${name} reaches ${v.ctl ? `[${lo}, ${hi}]` : v.n}, a row holds from 0 to ${ROW_MAX} objects`);
44
47
  }
45
48
  if (pg.sign && !['rows', 'scoreboard'].includes(pg.look)) fail('sign stands between the numbers of two rows or two scores, write look: rows or look: scoreboard');
49
+ if (pg.written && (pg.look !== 'rows' || pg.sign || pg.trail)) fail('written writes the difference of two rows of counters, write look: rows and leave sign and trail out');
46
50
  if (pg.look === 'scoreboard') {
47
51
  for (const f of ['pair', 'word', 'tap', 'trace', 'trail', 'spread']) if (pg[f]) fail(`${f} belongs to look: rows, the buttons add the goals of the scoreboard`);
48
52
  if (top.ctl || bottom.ctl || [top.n, bottom.n].some(n => n > GOALS_MAX)) fail(`top and bottom are the scores of the home team and the away team, write each as a number from 0 to ${GOALS_MAX}`);
@@ -88,6 +92,8 @@ function start(spec, lang, id) {
88
92
  if (wordsLinked(spec).includes(id)) { const w = wordsOf(spec, s)[id.split('-')[0]]; return string(lang, `counters_${tagKey(w)}`, { n: numbers(lang).int(w.n) }); }
89
93
  if (!measuresOf(spec).includes(id)) return null;
90
94
  const int = numbers(lang).int;
95
+ if (id === 'written') return words(differenceOf(spec, s).line, int);
96
+ if (id === 'reading' && spec.written) return reading(differenceOf(spec, s).line, int, (key, vars) => string(lang, `hesap_${key}`, vars));
91
97
  if (id === 'reading') return string(lang, `counters_${readingOf(spec, s)}`, { a: int(s.top), b: int(s.bottom) });
92
98
  if (id === 'verdict') return string(lang, `counters_${verdictOf(spec, s)}`);
93
99
  return int(counts(spec, s)[id]);
@@ -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
+ ];