@openbooknetwork/hesap 0.3.1 → 0.3.3

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.
@@ -2,9 +2,9 @@
2
2
  // group, or the jars of a shop shelf, with the written lines of their calculation. It checks a page's fields and says
3
3
  // what each link shows when the page opens.
4
4
  import { schema } from '@openbooknetwork/kitap';
5
- import { ADD_LOOKS, CELLS, JARS, DIE, opening, counts, LINES, measuresOf } from './add-model.js';
5
+ import { ADD_LOOKS, CELLS, JARS, DIE, EGGS, PIPS, PITCH, BENCH, opening, counts, LINES, measuresOf, family } from './add-model.js';
6
6
  import { ADD_GOALS, addStart } from './add-goals.js';
7
- import { words, reading, DASH } from '../../kit/written.js';
7
+ import { words, reading, DASH, FACTS, FACT_IDS } from '../../kit/written.js';
8
8
  import { numbers } from '../../kit/format.js';
9
9
  import { list, value, string, challenge, drawn } from '../../node.mjs';
10
10
 
@@ -13,26 +13,45 @@ const Int = z.number().int();
13
13
  const Range = z.tuple([Int, Int]);
14
14
  const Stepper = z.object({ stepper: Range, start: Int.optional() }).strict();
15
15
  const Fields = z.object({
16
- look: z.enum(ADD_LOOKS).default('frames'), // Two ten frames, or the shop shelf or the seed tray of a world page.
16
+ look: z.enum(ADD_LOOKS).default('frames'), // Two ten frames, or the shelf, the seed tray, the eggs, the domino or the squad.
17
+ whole: z.union([Int, Stepper]).optional(), // The whole, with first as its known part and places for the missing part.
17
18
  first: z.union([Int, Stepper]).optional(), // The counters of the first group, round and red, as a number or on a stepper.
18
19
  second: z.union([Int, Stepper]).optional(), // The counters of the second group in the frames, square and blue.
19
20
  waiting: Int.optional(), // Counters of the second group that wait in a tray beside the frames.
20
21
  dice: z.boolean().default(false), // Two dice and a Roll button set the first group and the counters waiting.
21
22
  take: z.boolean().default(false), // The page takes counters away, and second counts the counters taken.
22
- // The written line under the frames, and with ten the two steps of making ten under it.
23
- written: z.union([z.literal(true), z.literal('ten')]).optional(),
23
+ // The written line under the frames, with ten the two steps of making ten under it, and with family the facts.
24
+ written: z.union([z.literal(true), z.literal('ten'), z.literal('family')]).optional(),
25
+ facts: z.array(z.enum(FACTS)).optional(), // The facts a family page writes, all four when left out.
26
+ cover: z.boolean().default(false), // A tap on a half of the domino covers it with a card, and the line finds it.
24
27
  split: z.boolean().default(false), // A counter dropped on a frame joins that frame, so the reader splits the group.
28
+ undo: z.boolean().default(false), // The join is done once the tray is empty, and counters sent back undo it.
29
+ claim: z.union([Int, Stepper]).optional(), // A sum claimed for first + second, which the second line checks.
25
30
  readout: z.array(z.string()).default([]),
26
31
  // A challenge names a goal of add-goals.js and the range it draws its target from.
27
- challenge: z.object({ goal: z.string(), first: Range.optional(), second: Range.optional(), sum: Range.optional() }).strict().optional(),
32
+ challenge: z.object({ goal: z.string(), first: Range.optional(), second: Range.optional(), sum: Range.optional(), whole: Range.optional(), part: Range.optional() }).strict().optional(),
28
33
  }).strict();
29
34
 
30
35
  function read(fields, { at }, ctx) {
31
36
  const pg = check(Fields, fields, at), fail = words => ctx.fail(at, words);
32
- const first = value(pg.first), second = value(pg.second);
33
- const spec = { ...pg, scene: 'add', first: first.n, firstCtl: first.ctl, second: second.n ?? 0, secondCtl: second.ctl, waiting: pg.waiting ?? null };
37
+ const first = value(pg.first), second = value(pg.second), whole = value(pg.whole);
38
+ const spec = { ...pg, scene: 'add', first: first.n, firstCtl: first.ctl, second: second.n ?? 0, secondCtl: second.ctl, waiting: pg.waiting ?? null, whole: whole.n, wholeCtl: whole.ctl };
34
39
  if (pg.challenge) { readChallenge(pg, spec, at, ctx); return { data: spec, has: () => false, offers: 'nothing, a challenge page draws its numbers as it opens' }; }
40
+ if (pg.cover && pg.look !== 'domino') fail('cover belongs to the domino, write look: domino');
35
41
  if (pg.look === 'shelf') return readShelf(pg, spec, first, second, fail);
42
+ if (pg.look === 'domino') return readDomino(pg, spec, first, second, fail);
43
+ if (pg.facts && !family(pg)) fail('facts goes with written: family, write written: family or leave facts out');
44
+ if (pg.facts && (!pg.facts.length || new Set(pg.facts).size < pg.facts.length)) fail(`facts lists ${list(pg.facts) || 'nothing'}, write each fact once, out of ${list(FACTS)}`);
45
+ if (pg.whole !== undefined || pg.look === 'squad') return readWhole(pg, spec, first, whole, fail);
46
+ if (pg.undo) readUndo(pg, first, fail);
47
+ if (pg.claim !== undefined) return readClaim(pg, spec, first, second, fail);
48
+ if (family(pg) || pg.look === 'eggs') for (const f of ['take', 'waiting', 'dice', 'split']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} belongs to other pages, ${family(pg) ? 'written: family' : 'the eggs'} takes first, second, written, facts and readout`);
49
+ if (family(pg) && !['frames', 'eggs'].includes(pg.look)) fail(`written: family belongs to the frames and the eggs, this page shows ${pg.look}`);
50
+ if (pg.look === 'eggs') {
51
+ if (pg.written === 'ten') fail('written: ten belongs to the frames and the seed tray, write written: true or family on the eggs');
52
+ const most = (first.ctl?.hi ?? first.n ?? 0) + (second.ctl?.hi ?? second.n ?? 0);
53
+ if (most > EGGS) fail(`the eggs reach ${most}, and the box holds ${EGGS}, write first and second that come to ${EGGS} at most`);
54
+ }
36
55
  if (pg.look === 'tray') for (const f of ['dice', 'take']) if (pg[f]) fail(`${f} belongs to the frames, the seed tray takes first, second, waiting, split, written and readout`);
37
56
  if (first.n == null) fail('first is missing, write the counters of the first group, such as 5, or { stepper: [0, 10], start: 4 }');
38
57
  for (const [v, name] of [[first, 'first'], [second, 'second']]) {
@@ -62,18 +81,73 @@ function read(fields, { at }, ctx) {
62
81
  return offered(pg, spec, fail);
63
82
  }
64
83
 
84
+ // A page with a whole shows the known part as red counters and outlined places for the missing part, on the frames or
85
+ // as the pitch and the bench of the squad. One of whole and first may have a stepper.
86
+ function readWhole(pg, spec, first, whole, fail) {
87
+ for (const f of ['second', 'waiting', 'take', 'dice', 'split', 'undo', 'claim']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} belongs to other pages, a page with a whole takes look, first, written, facts and readout`);
88
+ if (!['frames', 'squad'].includes(pg.look)) fail(`whole belongs to the frames and the squad, this page shows ${pg.look}`);
89
+ if (whole.n == null) return fail('whole is missing, the squad needs the whole, such as whole: 16 with first: 11'), offered(pg, spec, fail);
90
+ if (first.n == null) return fail('first is missing, write the known part, such as 4, a number below the whole'), offered(pg, spec, fail);
91
+ if (pg.written === 'ten') fail('written: ten belongs to pages without a whole, write written: true or family');
92
+ if (first.ctl && whole.ctl) fail('whole and first both have a stepper, give one of them a number');
93
+ for (const [v, name] of [[whole, 'whole'], [first, 'first']]) if (v.ctl && (v.ctl.lo > v.ctl.hi || v.n < v.ctl.lo || v.n > v.ctl.hi)) fail(`${name} has the range [${v.ctl.lo}, ${v.ctl.hi}] and starts at ${v.n}, write [low, high] and a start between them`);
94
+ const wlo = whole.ctl?.lo ?? whole.n, whi = whole.ctl?.hi ?? whole.n, flo = first.ctl?.lo ?? first.n, fhi = first.ctl?.hi ?? first.n;
95
+ if (wlo < 2 || whi > CELLS) fail(`whole reaches ${whole.ctl ? `[${wlo}, ${whi}]` : whi}, write a whole from 2 to ${CELLS}`);
96
+ if (flo < 1 || fhi >= wlo) fail(`first reaches ${first.ctl ? `[${flo}, ${fhi}]` : fhi} with a whole of ${whole.ctl ? `[${wlo}, ${whi}]` : wlo}, write a known part from 1 to one less than the whole`);
97
+ if (pg.look === 'squad') {
98
+ if (whole.ctl || first.ctl) fail('the squad takes whole and first as numbers, write them without a stepper');
99
+ if (family(pg)) fail('written: family belongs to the frames, write written: true on the squad');
100
+ if (first.n > PITCH) fail(`first is ${first.n}, and ${PITCH} players are on the pitch at most`);
101
+ if (whole.n - first.n > BENCH) fail(`the bench needs ${whole.n - first.n} seats, and it has ${BENCH}, write a whole at most ${BENCH} more than first`);
102
+ }
103
+ return offered(pg, spec, fail);
104
+ }
105
+
106
+ // An undo page joins the counters of the tray and then takes them back, on the frames with a written line.
107
+ // A claim page writes first + second with a sum on the stepper Sum, right or wrong, and checks it by subtracting the
108
+ // second part. The frames show the two parts.
109
+ function readClaim(pg, spec, first, second, fail) {
110
+ const claim = value(pg.claim);
111
+ Object.assign(spec, { claim: claim.n, claimCtl: claim.ctl });
112
+ for (const f of ['waiting', 'take', 'dice', 'split', 'undo', 'cover', 'facts']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} belongs to other pages, a claim page takes first, second, claim, written: true and readout`);
113
+ if (pg.look !== 'frames') fail(`claim belongs to the frames, this page shows ${pg.look}`);
114
+ if (pg.written !== true) fail('claim writes the sum and its check under the frames, write written: true');
115
+ if (first.ctl || second.ctl || first.n == null || pg.second === undefined) fail('claim checks a sum of fixed parts, write first and second as numbers');
116
+ else if (first.n < 1 || second.n < 1 || first.n + second.n > CELLS) fail(`first and second are ${first.n} and ${second.n}, write two parts from 1 that come to ${CELLS} at most`);
117
+ const lo = claim.ctl?.lo ?? claim.n, hi = claim.ctl?.hi ?? claim.n;
118
+ if (claim.ctl && (lo > hi || claim.n < lo || claim.n > hi)) fail(`claim has the range [${lo}, ${hi}] and starts at ${claim.n}, write [low, high] and a start between them`);
119
+ else if (lo < (second.n ?? 0) || hi > 2 * CELLS) fail(`claim reaches ${claim.ctl ? `[${lo}, ${hi}]` : lo}, write sums from ${second.n ?? 0}, the second part, to ${2 * CELLS}, so the check takes the second part away`);
120
+ return offered(pg, spec, fail);
121
+ }
122
+
123
+ function readUndo(pg, first, fail) {
124
+ if (pg.look !== 'frames') fail(`undo belongs to the frames, this page shows ${pg.look}`);
125
+ if (first.ctl || first.n == null || pg.waiting == null) fail('undo joins the counters of the tray by hand, write first and waiting as numbers');
126
+ for (const f of ['second', 'take', 'dice', 'split']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} belongs to other pages, undo takes first, waiting, written: true and readout`);
127
+ if (pg.written !== true) fail('undo writes the join and the take away under the frames, write written: true');
128
+ }
129
+
65
130
  // The shelf is a page of its own: the jars sold in the morning and in the afternoon as numbers, the written lines and
66
131
  // the readouts.
67
132
  function readShelf(pg, spec, first, second, fail) {
68
133
  for (const f of ['waiting', 'dice', 'take', 'split']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} belongs to the frames, the shelf takes first, second, written and readout`);
69
- if (pg.written === 'ten') fail('written: ten belongs to the frames and the seed tray, write written: true on the shelf');
134
+ if (pg.written && pg.written !== true) fail(`written: ${pg.written} belongs to the frames, write written: true on the shelf`);
70
135
  if (first.ctl || second.ctl || first.n == null || first.n < 0 || second.n < 0 || first.n + second.n > JARS) fail(`first and second are the jars sold in the morning and in the afternoon, write them as numbers that come to ${JARS} at most`);
71
136
  return offered(pg, spec, fail);
72
137
  }
73
138
 
139
+ // The domino shows two halves of pips as numbers, and may cover a half and write the line.
140
+ function readDomino(pg, spec, first, second, fail) {
141
+ for (const f of ['waiting', 'dice', 'take', 'split', 'facts']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} belongs to other pages, the domino takes first, second, cover, written and readout`);
142
+ if (pg.written && pg.written !== true) fail(`written: ${pg.written} belongs to the frames, write written: true on the domino`);
143
+ for (const [v, name] of [[first, 'first'], [second, 'second']]) if (v.ctl || v.n == null || v.n < PIPS[0] || v.n > PIPS[1]) fail(`${name} is the pips of a half, write it as a number from ${PIPS[0]} to ${PIPS[1]}`);
144
+ return offered(pg, spec, fail);
145
+ }
146
+
147
+ // A page reads out its counts and its lines. The facts of a family page take no readout, since the figure writes them.
74
148
  function offered(pg, spec, fail) {
75
- const ids = measuresOf(spec);
76
- for (const id of pg.readout) if (!ids.includes(id)) fail(`readout names "${id}", this page reads out ${list(ids)}`);
149
+ const ids = measuresOf(spec), shown = family(spec) ? ids.filter(id => !FACT_IDS.includes(id)) : ids;
150
+ for (const id of pg.readout) if (!shown.includes(id)) fail(`readout names "${id}", this page reads out ${list(shown)}`);
77
151
  return { data: spec, has: id => ids.includes(id), offers: `one of ${list(ids)}` };
78
152
  }
79
153
 
@@ -0,0 +1,107 @@
1
+ // The goals a counters/bar page can name. The page declares a range, and the goal draws a target from it each time the
2
+ // page opens and each time the reader asks for another one. The build and the browser both use this file.
3
+ import { FACTS, sameFact, factLine } from '../../kit/written.js';
4
+
5
+ // The bar bar-for-fact opens on, with both handles.
6
+ export const OPEN = { whole: 10, first: 5 };
7
+ // The stepper Third number of bar-for-two, and the two uses its segment offers.
8
+ export const THIRD = [0, 20];
9
+ export const USES = ['parts', 'whole'];
10
+ const WHOLES = [3, 20], NUMBERS = [1, 19];
11
+ const span = (lo, hi) => Array.from({ length: Math.max(0, hi - lo + 1) }, (_, i) => lo + i);
12
+ 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;
13
+ 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; };
14
+ const words = r => JSON.stringify(r ?? null);
15
+
16
+ // The pairs a bar-for-two page can draw: two different numbers of its range whose sum the stepper reaches. The
17
+ // stepper opens at 0, which neither use of two different numbers needs.
18
+ const pairs = c => span(...c.numbers).flatMap(less => span(less + 1, c.numbers[1]).map(greater => ({ greater, less }))).filter(p => p.greater + p.less <= THIRD[1]);
19
+ // The third number of each use: the sum for the two parts, and the missing part for the whole and a part.
20
+ export const thirdOf = (t, use) => use === 'parts' ? t.greater + t.less : t.greater - t.less;
21
+ // The parts of the bar of a use: the two numbers as the parts, or the less and the third number as the parts of the
22
+ // greater.
23
+ export const partsOf = (t, use, third) => use === 'parts' ? { first: t.greater, second: t.less, whole: third } : { first: t.less, second: third, whole: t.greater };
24
+
25
+
26
+ export const BAR_GOALS = {
27
+ // The page writes a drawn fact under the bar. The reader drags the end to its whole and the split to one of its
28
+ // parts, and presses Check. Once the goal holds the other facts of the family join it.
29
+ 'bar-for-fact': {
30
+ scenes: ['bar'],
31
+ problem(c) {
32
+ const stop = extra(c, ['whole']);
33
+ if (stop) return stop;
34
+ return range(c.whole, WHOLES) ? null : `whole is ${words(c.whole)}, write the range of the whole as [low, high] from ${WHOLES[0]} to ${WHOLES[1]}, such as [6, 18]`;
35
+ },
36
+ // A whole of the range, a part below it, and an addition that writes that part first or a subtraction that takes
37
+ // it away, each half the time. So every fact the page writes comes from one draw, and Another one gives a new fact.
38
+ // Two equal parts give two facts, and the drawn fact is the one the figure writes.
39
+ draw(c, spec, dice) {
40
+ for (let i = 0; i < 50; i++) {
41
+ const whole = dice.int(...c.whole), first = dice.int(1, whole - 1), fact = dice.pick(['written', 'written-minus-first']);
42
+ if (whole === OPEN.whole && first === OPEN.first) continue;
43
+ return { whole, first, fact: sameFact(fact, first, whole - first) };
44
+ }
45
+ return null;
46
+ },
47
+ page: () => ({ ...OPEN, drag: ['split', 'end'] }),
48
+ // A wrong whole says which way the end goes. A right whole with wrong parts says which way the split goes, to the
49
+ // nearer of the two places that give the fact's parts.
50
+ holds(state, spec, c, t) {
51
+ if (!state.checked) return { done: false };
52
+ if (state.whole !== t.whole) return { done: false, note: state.whole > t.whole ? 'longer' : 'shorter' };
53
+ const places = [t.first, t.whole - t.first];
54
+ if (places.includes(state.first)) return { done: true };
55
+ const near = places.reduce((a, b) => Math.abs(b - state.first) < Math.abs(a - state.first) ? b : a);
56
+ return { done: false, note: near > state.first ? 'right' : 'left' };
57
+ },
58
+ reach: (spec, c, t) => t.whole < 2 || t.whole > WHOLES[1] || t.first < 1 || t.first >= t.whole ? `its whole ${t.whole} and part ${t.first} lie out of the reach of the handles` : null,
59
+ // The facts the figure writes: the drawn fact in the first place, under the bar, then its whole family in their
60
+ // places once the goal holds, with the parts in the order of the reader's bar so each number takes its part's
61
+ // colour.
62
+ facts: (t, s, done) => done ? { first: s.first, second: s.whole - s.first, listed: FACTS }
63
+ : { first: t.first, second: t.whole - t.first, listed: ['written'], lines: { written: factLine(t.fact, t.first, t.whole - t.first) } },
64
+ words(c, t, s, { int, written }) {
65
+ const b = t.whole - t.first;
66
+ return { fact: written(factLine(t.fact, t.first, b)), whole: int(t.whole), first: int(Math.max(t.first, b)), second: int(Math.min(t.first, b)) };
67
+ },
68
+ hint: t => factLine(t.fact, t.first, t.whole - t.first).sign === '+' ? 'plus' : 'minus',
69
+ },
70
+ // The page draws two different numbers. The reader picks whether they are the two parts or the whole and a part,
71
+ // sets the third number of the family and presses Check. Either use solves a draw. Until it holds the bar is a
72
+ // sketch: the third number carries a question mark, and as the whole and a part the two pieces are half and half,
73
+ // so no length gives the answer. Once it holds the reader's family is drawn to scale.
74
+ 'bar-for-two': {
75
+ scenes: ['bar'],
76
+ problem(c) {
77
+ const stop = extra(c, ['numbers']);
78
+ if (stop) return stop;
79
+ if (!range(c.numbers, NUMBERS)) return `numbers is ${words(c.numbers)}, write the range of the two numbers as [low, high] from ${NUMBERS[0]} to ${NUMBERS[1]}, such as [2, 12]`;
80
+ return pairs(c).length ? null : `numbers ${words(c.numbers)} leave no two different numbers whose sum is ${THIRD[1]} at most, widen the range`;
81
+ },
82
+ draw: (c, spec, dice) => { const all = pairs(c); return all.length ? dice.pick(all) : null; },
83
+ page: () => ({ drag: [], useCtl: { kind: 'segment', items: USES }, thirdCtl: { kind: 'stepper', lo: THIRD[0], hi: THIRD[1] } }),
84
+ // A wrong third number says which way it is off, in the reader's numbers, without the answer.
85
+ holds(state, spec, c, t) {
86
+ if (!state.checked) return { done: false };
87
+ // Either third number makes a family, whatever the segment shows, and the goal names the use it matches.
88
+ const use = USES.find(u => state.third === thirdOf(t, u));
89
+ if (use) return { done: true, use };
90
+ const right = thirdOf(t, state.use);
91
+ return { done: false, note: `${state.use}-${state.third > right ? 'over' : 'under'}` };
92
+ },
93
+ reach: (spec, c, t) => USES.every(u => thirdOf(t, u) >= THIRD[0] && thirdOf(t, u) <= THIRD[1]) ? null : `a third number of ${t.greater} and ${t.less} lies past the stepper's reach of ${THIRD[0]} to ${THIRD[1]}`,
94
+ // The facts of the reader's family, once the goal holds.
95
+ facts: (t, s, done) => { const p = partsOf(t, s.use, s.third); return { first: p.first, second: p.second, listed: done ? FACTS : [] }; },
96
+ // The done line names the reader's family first, then the family of the other use.
97
+ words(c, t, s, { int }) {
98
+ const use = s?.use ?? 'parts', other = USES.find(u => u !== use);
99
+ return { greater: int(t.greater), less: int(t.less), n: int(s?.third ?? 0), mine: int(thirdOf(t, use)), other: int(thirdOf(t, other)) };
100
+ },
101
+ },
102
+ };
103
+
104
+ // The reader's state as a challenge opens: the opening bar, the two numbers as parts, and nothing checked. The third
105
+ // number opens at the greater of the two drawn numbers, which solves neither use: the sum is more and the difference
106
+ // less.
107
+ export const barStart = t => ({ ...OPEN, use: 'parts', third: t?.greater ?? THIRD[0], checked: false });
@@ -0,0 +1,38 @@
1
+ // What a counters/bar page holds: a bar model whose whole is split into two parts, with the written line or the facts
2
+ // of its family under it. The build and the browser both use this file, so a page's text and its live values agree.
3
+ import { PLUS, FACTS, FACT_IDS, factLine, finding } from '../../kit/written.js';
4
+
5
+ // bar is the plain bar model, and chocolate a bar of chocolate with a square for each 1.
6
+ export const BAR_LOOKS = ['bar', 'chocolate'];
7
+ // The whole of a bar runs from 2 to 20, and a dragged end reaches this far.
8
+ export const WHOLE = [2, 20];
9
+ // The handles a page lets the reader drag, and the numbers a card can cover.
10
+ export const HANDLES = ['split', 'end'];
11
+ export const NUMBERS = ['whole', 'first', 'second'];
12
+
13
+ export const family = spec => spec.written === 'family';
14
+ // opening gives the bar as the page opens. cover is the number under the card, and found the number the written line
15
+ // finds, which it keeps once the card is lifted. A page with ask opens with that number covered.
16
+ export const opening = spec => ({ whole: spec.whole, first: spec.first, cover: spec.ask ?? null, found: spec.ask ?? null });
17
+
18
+ // counts gives every number of the bar: the whole, the first part and the second part, the whole minus the first.
19
+ export const counts = (spec, s) => ({ whole: s.whole, first: s.first, second: s.whole - s.first });
20
+
21
+ // lineOf gives the written line: first + second = whole until a number is covered, then the calculation that finds
22
+ // the covered number, open while the card is on.
23
+ export const lineOf = (spec, s) => s.found ? finding(s.first, s.whole - s.first, s.found, s.cover != null) : { a: s.first, sign: PLUS, b: s.whole - s.first };
24
+ // The lines a link reads, by its id: the written line and its words, and the facts of a family page.
25
+ const fact = id => (spec, s) => factLine(id, s.first, s.whole - s.first);
26
+ export const LINES = { written: (spec, s) => family(spec) ? fact('written')(spec, s) : lineOf(spec, s), reading: (spec, s) => family(spec) ? fact('reading')(spec, s) : lineOf(spec, s),
27
+ ...Object.fromEntries(FACT_IDS.filter(id => !['written', 'reading'].includes(id)).map(id => [id, fact(id)])) };
28
+
29
+ // The measures a page can link in its text. The facts take no readout, since the figure writes them.
30
+ export function measuresOf(spec) {
31
+ if (spec.challenge) return [];
32
+ return [...NUMBERS, ...(family(spec) ? FACT_IDS : spec.written ? ['written', 'reading'] : [])];
33
+ }
34
+ export const readable = spec => measuresOf(spec).filter(id => !family(spec) || !FACT_IDS.includes(id));
35
+ // labelKeys gives the strings that may name a readout or a handle: the chocolate's own first, then the bar's.
36
+ export const labelKeys = (spec, id) => [...(spec.look === 'chocolate' ? [`bar-chocolate-${id}`] : []), `bar-${id}`];
37
+ // The facts a family page writes, all four when it lists none.
38
+ export const factsListed = spec => spec.facts ?? FACTS;