@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.
- package/package.json +1 -1
- package/src/client.css +111 -1
- package/src/families/counters/add-figures.js +66 -0
- package/src/families/counters/add-goals.js +30 -2
- package/src/families/counters/add-model.js +60 -10
- package/src/families/counters/add.js +269 -33
- package/src/families/counters/add.mjs +85 -11
- package/src/families/counters/bar-goals.js +107 -0
- package/src/families/counters/bar-model.js +38 -0
- package/src/families/counters/bar.js +412 -0
- package/src/families/counters/bar.mjs +79 -0
- package/src/families/counters/bonds.js +46 -7
- package/src/families/counters/client.css +102 -0
- package/src/families/counters/client.js +2 -1
- package/src/families/counters/counter.js +13 -0
- package/src/families/counters/facts.js +73 -0
- package/src/families/counters/figures.js +12 -4
- package/src/families/counters/i18n/en.yaml +64 -0
- package/src/families/counters/i18n/tr.yaml +64 -0
- package/src/families/counters/index.mjs +9 -7
- package/src/families/line/i18n/en.yaml +2 -0
- package/src/families/line/i18n/tr.yaml +3 -0
- package/src/families/line/index.mjs +34 -5
- package/src/families/line/line.js +34 -12
- package/src/families/line/model.js +50 -16
- package/src/i18n/en.yaml +67 -0
- package/src/i18n/tr.yaml +68 -0
- package/src/kit/goal.js +8 -1
- package/src/kit/i18n/en.yaml +1 -0
- package/src/kit/i18n/tr.yaml +1 -0
- package/src/kit/kit.css +9 -1
- package/src/kit/written.js +35 -2
package/package.json
CHANGED
package/src/client.css
CHANGED
|
@@ -59,7 +59,7 @@ button.hesap-chip{cursor:pointer;min-height:36px;align-items:center}
|
|
|
59
59
|
/* A challenge's line holds the goal, whether it is reached, another target and a hint. The goal takes a line of its
|
|
60
60
|
own, so a longer status keeps the panel's height. */
|
|
61
61
|
.hesap-goal{display:flex;flex-wrap:wrap;align-items:center;gap:.286rem .571rem}
|
|
62
|
-
.hesap-goal-text{margin:0;flex-basis:100%;font-weight:600}
|
|
62
|
+
.hesap-goal-text{margin:0;flex-basis:100%;font-weight:600;line-height:1.4}
|
|
63
63
|
.hesap-goal-state{display:inline-flex;align-items:center;gap:.286rem;color:var(--ink-2);flex:1;min-width:0}
|
|
64
64
|
.hesap-goal.solved .hesap-goal-state{color:var(--accent)}
|
|
65
65
|
.hesap-goal-state svg{width:20px;height:20px}
|
|
@@ -79,6 +79,10 @@ aside.story .place[data-formula] .katex-display>.katex{text-align:start}
|
|
|
79
79
|
.hesap-btn,.hesap-seg button,.hesap-step button{min-height:42px}
|
|
80
80
|
.hesap-chip{padding:.214rem .643rem}
|
|
81
81
|
.hesap-chip small{font-size:.786rem}
|
|
82
|
+
/* On a phone the goal line and the status keep room for two lines each, and the status takes a line of its own,
|
|
83
|
+
so a note or the done line leaves the panel's height as it was. */
|
|
84
|
+
.hesap-goal-text{min-height:2.8em}
|
|
85
|
+
.hesap-goal-state{flex-basis:100%;min-height:2.8em;line-height:1.4}
|
|
82
86
|
.hesap-long{display:none}
|
|
83
87
|
.hesap-short{display:inline}
|
|
84
88
|
/* A compact button shows its glyph alone. */
|
|
@@ -97,6 +101,10 @@ aside.story .place[data-formula] .katex-display>.katex{text-align:start}
|
|
|
97
101
|
.hesap .hesap-written .hesap-written-num{fill:var(--c,var(--ink))}
|
|
98
102
|
.hesap .hesap-written .hesap-written-hot,.hesap .hesap-written.hesap-written-hot{text-decoration:underline}
|
|
99
103
|
|
|
104
|
+
/* A number sentence or a calculation written in the text, marked up as code: it stays on one line and stands out from
|
|
105
|
+
the words around it, in the text's own font, in the text and on the folded card. */
|
|
106
|
+
:is(aside.story,.peek) code{font:inherit;font-weight:700;font-variant-numeric:tabular-nums;white-space:nowrap;padding:.071rem .357rem;border-radius:4px;background:color-mix(in srgb,var(--accent) 14%,transparent)}
|
|
107
|
+
|
|
100
108
|
/* counters: the colours are theme tokens and the two counter colours of the family, so a theme switch needs no
|
|
101
109
|
redraw. */
|
|
102
110
|
.hesap-counters .counters-svg{position:absolute;left:0;top:0;width:100%;height:100%;touch-action:none;font-family:var(--body);overflow:visible}
|
|
@@ -167,6 +175,9 @@ aside.story .place[data-formula] .katex-display>.katex{text-align:start}
|
|
|
167
175
|
.hesap-counters .counters-pin-stripe{fill:var(--z-counters-red,#d1453b)}
|
|
168
176
|
.hesap-counters .counters-spot{fill:var(--rule)}
|
|
169
177
|
.hesap-counters .counters-down .counters-pin-body{opacity:.45}
|
|
178
|
+
.hesap-counters .counters-ball{pointer-events:none}
|
|
179
|
+
.hesap-counters .counters-ball-shape{fill:var(--z-counters-blue,#2a6bd1);stroke:var(--ink);stroke-width:2}
|
|
180
|
+
.hesap-counters .counters-ball-hole{fill:var(--ink)}
|
|
170
181
|
.hesap-counters .counters-pin:focus-visible .counters-hit{stroke:var(--accent);stroke-width:2.5}
|
|
171
182
|
|
|
172
183
|
/* The car park: two rows of spaces, an aisle, and a sign that shows the free spaces. */
|
|
@@ -373,6 +384,105 @@ aside.story .place[data-formula] .katex-display>.katex{text-align:start}
|
|
|
373
384
|
.hesap-counters .counters-paired-lit .counters-body{stroke:var(--paper);stroke-width:2.5}
|
|
374
385
|
.hesap-counters .counters-wire.counters-hot{stroke:var(--accent);stroke-width:5}
|
|
375
386
|
|
|
387
|
+
/* The egg box: a carton of ten cups, brown eggs with speckles and white eggs with a shell outline. The numbers of the
|
|
388
|
+
facts take the brown and the shell as the colours of the two parts. */
|
|
389
|
+
.hesap-counters .counters-egg-a{--c:var(--z-counters-brown,#a0602c)}
|
|
390
|
+
.hesap-counters .counters-egg-b{--c:var(--z-counters-shell,#7f7462)}
|
|
391
|
+
.hesap-counters .counters-carton{fill:#dcc9a4;stroke:#a88a55;stroke-width:2.5}
|
|
392
|
+
.hesap-counters .counters-egg-cup{fill:#c8b088;stroke:#a88a55;stroke-width:1}
|
|
393
|
+
.hesap-counters .counters-egg-brown .counters-body{fill:var(--z-counters-brown,#a0602c);stroke:#6b3d1c;stroke-width:1.5}
|
|
394
|
+
.hesap-counters .counters-egg-white .counters-body{fill:#fbf8f1;stroke:var(--z-counters-shell,#7f7462);stroke-width:2}
|
|
395
|
+
.hesap-counters .counters-speck{fill:#5a3215;stroke:none}
|
|
396
|
+
.hesap-counters .counters-lit:is(.counters-egg-brown,.counters-egg-white) .counters-body{stroke:var(--accent);stroke-width:4}
|
|
397
|
+
/* A lit counter of the frames and the egg box also takes a ring in ink round it, so it shows where the accent is
|
|
398
|
+
close to the counter's own colour. */
|
|
399
|
+
.hesap-counters .counters-layer .counters-lit .counters-hit{stroke:var(--ink);stroke-width:2.5}
|
|
400
|
+
|
|
401
|
+
/* The facts of a family: each fact is a button in a box, and the picked fact is outlined in the accent. */
|
|
402
|
+
.hesap-counters .counters-fact{cursor:pointer;outline:none}
|
|
403
|
+
.hesap-counters .counters-fact-box{fill:transparent;stroke:var(--rule);stroke-width:1.5}
|
|
404
|
+
.hesap-counters .counters-fact:hover .counters-fact-box{fill:var(--accent);fill-opacity:.08}
|
|
405
|
+
.hesap-counters .counters-fact:focus-visible .counters-fact-box{stroke:var(--accent);stroke-width:3}
|
|
406
|
+
.hesap-counters .counters-fact-on .counters-fact-box{fill:var(--accent);fill-opacity:.12;stroke:var(--accent);stroke-width:3}
|
|
407
|
+
|
|
408
|
+
/* The domino: two halves of pips, the whole above it, and the card that covers a half. */
|
|
409
|
+
.hesap-counters .counters-domino{fill:var(--paper);stroke:var(--ink);stroke-width:3}
|
|
410
|
+
.hesap-counters .counters-domino-bar{stroke:var(--ink);stroke-width:2.5}
|
|
411
|
+
.hesap-counters .counters-domino-pip{fill:var(--c)}
|
|
412
|
+
.hesap-counters .counters-half{cursor:pointer;outline:none}
|
|
413
|
+
.hesap-counters .counters-half-box{fill:transparent;stroke:none}
|
|
414
|
+
.hesap-counters .counters-half:hover .counters-half-box{fill:var(--accent);fill-opacity:.08}
|
|
415
|
+
.hesap-counters .counters-half:focus-visible .counters-half-box{stroke:var(--accent);stroke-width:3}
|
|
416
|
+
.hesap-counters .counters-half.counters-hot{stroke:none}
|
|
417
|
+
.hesap-counters .counters-half.counters-hot .counters-half-box{stroke:var(--accent);stroke-width:4}
|
|
418
|
+
.hesap-counters .counters-domino-whole{font-size:40px;font-weight:700}
|
|
419
|
+
.hesap-counters .counters-domino-whole.counters-hot{stroke:none;fill:var(--accent)}
|
|
420
|
+
.hesap-counters .counters-domino-card{cursor:pointer;outline:none}
|
|
421
|
+
.hesap-counters .counters-domino-card-box{fill:var(--panel);stroke:var(--ink);stroke-width:2.5}
|
|
422
|
+
.hesap-counters .counters-domino-card:focus-visible .counters-domino-card-box{stroke:var(--accent);stroke-width:4}
|
|
423
|
+
.hesap-counters .counters-cover-q{font-size:60px;font-weight:700;fill:var(--ink-2)}
|
|
424
|
+
|
|
425
|
+
/* The places of a missing part are outlined squares that the counters put in cover. A counter put in carries the number
|
|
426
|
+
the count reaches, and the red counters let a tap through to the frames. */
|
|
427
|
+
.hesap-counters .counters-gap-place{fill:none;stroke:var(--ink-2);stroke-width:2;stroke-dasharray:5 4;pointer-events:none}
|
|
428
|
+
.hesap-counters .counters-gap-place.counters-hot{stroke:var(--accent);stroke-width:3.5}
|
|
429
|
+
.hesap-counters .counters-still{pointer-events:none}
|
|
430
|
+
.hesap-counters .counters-numbered .counters-ring{display:none}
|
|
431
|
+
.hesap-counters text.counters-num{fill:#fff;font-size:15px;font-weight:700}
|
|
432
|
+
.hesap-counters .counters-taken text.counters-num{display:none}
|
|
433
|
+
/* The squad: a pitch of grass with white lines, and a bench beside it. */
|
|
434
|
+
.hesap-counters .counters-pitch{fill:#4f8f45;stroke:var(--ink-2);stroke-width:2}
|
|
435
|
+
.hesap-counters .counters-pitch.counters-hot{stroke:var(--accent);stroke-width:4}
|
|
436
|
+
.hesap-counters .counters-pitch-line{fill:none;stroke:#fff;stroke-width:2;stroke-opacity:.85;pointer-events:none}
|
|
437
|
+
.hesap-counters .counters-bench{fill:var(--panel);stroke:var(--ink-2);stroke-width:2}
|
|
438
|
+
.hesap-counters .counters-bench.counters-hot{stroke:var(--accent);stroke-width:4}
|
|
439
|
+
/* The line under a claim's check says whether the sum is right, in ink when it is and in the accent when it is not. */
|
|
440
|
+
.hesap-counters text.counters-verdict{font-size:17px;font-weight:600;fill:var(--accent)}
|
|
441
|
+
.hesap-counters text.counters-verdict.counters-verdict-right{fill:var(--ink)}
|
|
442
|
+
.hesap-counters .counters-shirt .counters-body{stroke:var(--ink);stroke-width:1.5;stroke-linejoin:round}
|
|
443
|
+
|
|
444
|
+
/* The bar model: two parts drawn to scale with the whole above them over a bracket, the handles of the split and the
|
|
445
|
+
end, and the card that covers a number. A subtraction draws the part it takes away pale with a dashed outline. */
|
|
446
|
+
.hesap-counters .counters-bar-row{pointer-events:none}
|
|
447
|
+
.hesap-counters .counters-bar-part{fill:var(--c);fill-opacity:.2;stroke:var(--c);stroke-width:2.5}
|
|
448
|
+
.hesap-counters .counters-bar-num{font-size:24px;font-weight:700;fill:var(--c)}
|
|
449
|
+
.hesap-counters .counters-bar-lead{stroke:var(--c);stroke-width:1.5}
|
|
450
|
+
.hesap-counters .counters-bar-whole{font-size:30px;font-weight:700}
|
|
451
|
+
.hesap-counters .counters-bracket{fill:none;stroke:var(--ink-2);stroke-width:2.5;stroke-linejoin:round}
|
|
452
|
+
.hesap-counters .counters-bar-outline{fill:none;stroke:var(--ink);stroke-width:2.5}
|
|
453
|
+
.hesap-counters .counters-bar-split{stroke:var(--ink);stroke-width:3}
|
|
454
|
+
.hesap-counters .counters-bar-part.counters-hot,.hesap-counters .counters-bar-outline.counters-hot,.hesap-counters .counters-bracket.counters-hot{stroke:var(--accent);stroke-width:4}
|
|
455
|
+
.hesap-counters .counters-bar-num.counters-hot,.hesap-counters .counters-bar-whole.counters-hot{stroke:none;fill:var(--accent)}
|
|
456
|
+
.hesap-counters .counters-bar-gone .counters-bar-part{fill-opacity:.04;stroke-dasharray:7 5;stroke-width:2.5}
|
|
457
|
+
.hesap-counters .counters-bar-gone .counters-bar-num,.hesap-counters .counters-bar-gone .counters-choc-grooves{opacity:.4}
|
|
458
|
+
.hesap-counters .counters-handle{cursor:ew-resize;outline:none}
|
|
459
|
+
.hesap-counters .counters-handle-hit{fill:transparent}
|
|
460
|
+
.hesap-counters .counters-knob{fill:var(--paper);stroke:var(--ink);stroke-width:2.5;stroke-linejoin:round}
|
|
461
|
+
.hesap-counters .counters-grip{fill:none;stroke:var(--ink-2);stroke-width:2;stroke-linecap:round}
|
|
462
|
+
.hesap-counters .counters-handle.drag .counters-knob,.hesap-counters .counters-handle.counters-hot .counters-knob{fill:var(--accent);stroke:var(--accent)}
|
|
463
|
+
.hesap-counters .counters-handle:focus-visible .counters-knob{stroke:var(--accent);stroke-width:4}
|
|
464
|
+
.hesap-counters .counters-bar-tap{fill:transparent;cursor:pointer;outline:none}
|
|
465
|
+
.hesap-counters .counters-bar-tap:hover{fill:var(--accent);fill-opacity:.08}
|
|
466
|
+
.hesap-counters .counters-bar-tap:focus-visible{stroke:var(--accent);stroke-width:3}
|
|
467
|
+
.hesap-counters .counters-bar-card{cursor:pointer;outline:none}
|
|
468
|
+
.hesap-counters .counters-bar-card-box{fill:var(--panel);stroke:var(--ink);stroke-width:2.5}
|
|
469
|
+
.hesap-counters .counters-bar-card:focus-visible .counters-bar-card-box{stroke:var(--accent);stroke-width:4}
|
|
470
|
+
.hesap-counters .counters-bar-card-q{font-size:28px;font-weight:700;fill:var(--ink-2)}
|
|
471
|
+
/* A bar of chocolate: each piece has a square for each 1, its edge in its part's colour, and its number on a badge. */
|
|
472
|
+
.hesap-counters .counters-bar-part.counters-choc{fill:#6b3f23;fill-opacity:1;stroke:var(--c);stroke-width:3}
|
|
473
|
+
.hesap-counters .counters-bar-part.counters-choc.counters-hot{stroke:var(--accent);stroke-width:4}
|
|
474
|
+
.hesap-counters .counters-choc-grooves line{stroke:#4a2a15;stroke-width:2}
|
|
475
|
+
.hesap-counters .counters-choc-badge{fill:var(--paper);stroke:var(--c);stroke-width:2.5}
|
|
476
|
+
.hesap-counters .counters-choc~.counters-bar-num{font-size:18px}
|
|
477
|
+
.hesap-counters .counters-bar-gone .counters-bar-part.counters-choc{fill-opacity:.3}
|
|
478
|
+
/* The number of a bar-for-two bar that the reader finds: its part or its bracket is dashed and its number is a
|
|
479
|
+
question mark. */
|
|
480
|
+
.hesap-counters .counters-bar-unknown .counters-bar-part{fill:none;stroke-dasharray:7 5}
|
|
481
|
+
.hesap-counters .counters-bracket-unknown{stroke-dasharray:6 5}
|
|
482
|
+
/* A fact's place the page leaves empty is a dashed box with nothing in it. */
|
|
483
|
+
.hesap-counters .counters-fact-empty{cursor:default}
|
|
484
|
+
.hesap-counters .counters-fact-empty .counters-fact-box,.hesap-counters .counters-fact-empty:hover .counters-fact-box{fill:none;stroke:var(--ink-2);stroke-width:1.5;stroke-dasharray:6 5}
|
|
485
|
+
|
|
376
486
|
/* line: the colours are theme tokens and the two point colours of the family, so a theme switch needs no redraw. */
|
|
377
487
|
.hesap-line .line-svg{position:absolute;left:0;top:0;width:100%;height:100%;touch-action:none;font-family:var(--body);overflow:hidden}
|
|
378
488
|
.hesap-line text{fill:var(--ink);text-anchor:middle;dominant-baseline:central;pointer-events:none;font-variant-numeric:tabular-nums}
|
|
@@ -83,3 +83,69 @@ export function seedTray() {
|
|
|
83
83
|
return { nodes: [el('rect', { class: 'counters-seedtray', x, y, width: w, height: h, rx: 8 }), ...soil], cells, box: { x, y, w, h } };
|
|
84
84
|
} };
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
// eggBox draws a box of ten eggs, two rows of five cups, and gives the middle of every cup, the first row first.
|
|
88
|
+
export function eggBox() {
|
|
89
|
+
const w = 5 * CELL + 2 * EDGE, h = 2 * CELL + 2 * EDGE;
|
|
90
|
+
return { w, h, draw(x, y) {
|
|
91
|
+
const cells = Array.from({ length: 10 }, (_, i) => ({ x: x + EDGE + (i % 5 + 0.5) * CELL, y: y + EDGE + (Math.floor(i / 5) + 0.5) * CELL }));
|
|
92
|
+
const cups = cells.map(c => el('circle', { class: 'counters-egg-cup', cx: c.x, cy: c.y, r: CELL * 0.42 }));
|
|
93
|
+
return { nodes: [el('rect', { class: 'counters-carton', x, y, width: w, height: h, rx: 12 }), ...cups], cells };
|
|
94
|
+
} };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// A half of a domino is DOMINO wide and high, and the whole's number takes WHOLE_ROOM above it. A half sets its pips
|
|
98
|
+
// as a die does.
|
|
99
|
+
const DOMINO = 112, WHOLE_ROOM = 60;
|
|
100
|
+
// domino draws one domino with its two halves side by side and the whole's number above it. The first half shows
|
|
101
|
+
// first pips and the second half second pips. Each half is a button, and the card that covers a half carries a
|
|
102
|
+
// question mark.
|
|
103
|
+
export function domino(first, second) {
|
|
104
|
+
const w = 2 * DOMINO, h = WHOLE_ROOM + DOMINO;
|
|
105
|
+
return { w, h, draw(x, y) {
|
|
106
|
+
const top = y + WHOLE_ROOM, nodes = [el('rect', { class: 'counters-domino', x, y: top, width: w, height: DOMINO, rx: 14 })];
|
|
107
|
+
const halves = [first, second].map((n, k) => {
|
|
108
|
+
const hx = x + k * DOMINO, c = { x: hx + DOMINO / 2, y: top + DOMINO / 2 };
|
|
109
|
+
const pips = PIPS[n].map(([i, j]) => el('circle', { class: 'counters-domino-pip', cx: c.x + i * DOMINO * 0.27, cy: c.y + j * DOMINO * 0.27, r: DOMINO * 0.08 }));
|
|
110
|
+
const g = el('g', { class: `counters-half counters-${k ? 'b' : 'a'}`, role: 'button', tabindex: 0, 'data-ref': k ? 'second' : 'first' },
|
|
111
|
+
[el('rect', { class: 'counters-half-box', x: hx + 4, y: top + 4, width: DOMINO - 8, height: DOMINO - 8, rx: 10 }), ...pips]);
|
|
112
|
+
return { g, x: hx, y: top };
|
|
113
|
+
});
|
|
114
|
+
nodes.push(...halves.map(hf => hf.g), el('line', { class: 'counters-domino-bar', x1: x + DOMINO, y1: top + 12, x2: x + DOMINO, y2: top + DOMINO - 12 }));
|
|
115
|
+
const whole = el('text', { class: 'counters-domino-whole', 'data-ref': 'whole', x: x + w / 2, y: y + WHOLE_ROOM / 2 - 4 });
|
|
116
|
+
const mark = el('text', { class: 'counters-cover-q', x: DOMINO / 2, y: DOMINO / 2 });
|
|
117
|
+
mark.textContent = '?';
|
|
118
|
+
const card = el('g', { class: 'counters-domino-card', role: 'button', tabindex: 0, display: 'none' }, [el('rect', { class: 'counters-domino-card-box', x: 2, y: 2, width: DOMINO - 4, height: DOMINO - 4, rx: 12 }), mark]);
|
|
119
|
+
nodes.push(whole, card);
|
|
120
|
+
return { nodes, halves, whole, card };
|
|
121
|
+
} };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// The squad: a football pitch seen from above, the long side across, with a spot for each player of a team, and a
|
|
125
|
+
// bench beside it where the players of the missing part sit down in turn.
|
|
126
|
+
const PITCH_W = 330, PITCH_H = 230;
|
|
127
|
+
const SEAT = 48; // A player on the bench takes this much room, in the figure's units.
|
|
128
|
+
// The spots of the players in the order of their shirts: the keeper, four defenders, four in midfield and two up
|
|
129
|
+
// front, as fractions of the pitch.
|
|
130
|
+
const SPOTS = [[0.07, 0.5], ...[0.25, 0.5].flatMap(x => [0.14, 0.38, 0.62, 0.86].map(y => [x, y])), [0.76, 0.34], [0.76, 0.66]];
|
|
131
|
+
export function pitch() {
|
|
132
|
+
return { w: PITCH_W, h: PITCH_H, draw(x, y) {
|
|
133
|
+
const w = PITCH_W, h = PITCH_H, m = 10, box = (bx, bw, bh) => el('rect', { class: 'counters-pitch-line', x: bx, y: y + (h - bh) / 2, width: bw, height: bh });
|
|
134
|
+
const nodes = [el('rect', { class: 'counters-pitch', 'data-ref': 'first', x, y, width: w, height: h, rx: 6 }),
|
|
135
|
+
el('rect', { class: 'counters-pitch-line', x: x + m, y: y + m, width: w - 2 * m, height: h - 2 * m }),
|
|
136
|
+
el('line', { class: 'counters-pitch-line', x1: x + w / 2, y1: y + m, x2: x + w / 2, y2: y + h - m }),
|
|
137
|
+
el('circle', { class: 'counters-pitch-line', cx: x + w / 2, cy: y + h / 2, r: 34 }),
|
|
138
|
+
box(x + m, 48, 130), box(x + w - m - 48, 48, 130)];
|
|
139
|
+
return { nodes, spots: SPOTS.map(([px, py]) => ({ x: x + px * w, y: y + py * h })) };
|
|
140
|
+
} };
|
|
141
|
+
}
|
|
142
|
+
// bench gives the size of a bench with room for n players in rows of cols, and draws it at a corner with the place of
|
|
143
|
+
// each player. Its area takes a tap anywhere on the bench.
|
|
144
|
+
export function bench(n, cols) {
|
|
145
|
+
const rows = Math.ceil(n / cols), w = cols * SEAT + 2 * EDGE, h = rows * SEAT + 2 * EDGE;
|
|
146
|
+
return { w, h, draw(x, y) {
|
|
147
|
+
const area = el('rect', { class: 'counters-bench counters-press', 'data-ref': 'missing', x, y, width: w, height: h, rx: 10, tabindex: 0, role: 'button' });
|
|
148
|
+
const seats = Array.from({ length: n }, (_, i) => ({ x: x + EDGE + (i % cols + 0.5) * SEAT, y: y + EDGE + (Math.floor(i / cols) + 0.5) * SEAT }));
|
|
149
|
+
return { nodes: [area], seats, area };
|
|
150
|
+
} };
|
|
151
|
+
}
|
|
@@ -7,6 +7,8 @@ export const PART_STEP = [0, 9]; // The steppers Makes ten and The rest of a ste
|
|
|
7
7
|
// The widest ranges a page may draw from. A first number reaches past the first ten, and the second joins after it
|
|
8
8
|
// within the two frames.
|
|
9
9
|
const FIRSTS = [1, 19], PARTS = [1, 10], SUMS = [1, 20], SECONDS = [2, 9];
|
|
10
|
+
// A missing-part page draws a whole the two frames hold and a known part below it.
|
|
11
|
+
const WHOLES = [2, 20], KNOWN = [1, 19];
|
|
10
12
|
const span = (lo, hi) => Array.from({ length: Math.max(0, hi - lo + 1) }, (_, i) => lo + i);
|
|
11
13
|
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;
|
|
12
14
|
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; };
|
|
@@ -20,6 +22,9 @@ const sums = c => span(...c.first).flatMap(a => span(...c.second).map(b => ({ a,
|
|
|
20
22
|
const crossing = (c, sign) => sign === PLUS
|
|
21
23
|
? span(1, 9).flatMap(a => span(...c.second).map(b => ({ a, sign, b }))).filter(t => t.a + t.b >= 11 && t.a + t.b <= 18)
|
|
22
24
|
: span(11, 18).flatMap(a => span(...c.second).map(b => ({ a, sign, b }))).filter(t => t.a - t.b >= 1 && t.a - t.b <= 9);
|
|
25
|
+
// The subtractions a missing-part page can draw: every whole and known part of their ranges with the part below the
|
|
26
|
+
// whole.
|
|
27
|
+
const asks = c => span(...c.whole).flatMap(whole => span(...c.part).filter(part => part < whole).map(part => ({ whole, part })));
|
|
23
28
|
// toTenOf gives the part of the second number that takes the first number to 10.
|
|
24
29
|
export const toTenOf = t => t.sign === PLUS ? 10 - t.a : t.a - 10;
|
|
25
30
|
|
|
@@ -76,7 +81,30 @@ export const ADD_GOALS = {
|
|
|
76
81
|
steps: t => [{ a: t.a, sign: t.sign, b: toTenOf(t) }, { a: 10, sign: t.sign, b: t.b - toTenOf(t) }],
|
|
77
82
|
words: (c, t, f) => ({ first: f.int(t.a), second: f.int(t.b), sum: f.int(answerOf(t)) }),
|
|
78
83
|
},
|
|
84
|
+
// The page writes a drawn subtraction open, such as 13 − 8, over its known part as red counters. The reader taps blue
|
|
85
|
+
// counters in or out and presses Check, which holds once the blue counters are the missing part.
|
|
86
|
+
'missing-part': {
|
|
87
|
+
scenes: ['add'],
|
|
88
|
+
problem(c) {
|
|
89
|
+
const stop = extra(c, ['whole', 'part']);
|
|
90
|
+
if (stop) return stop;
|
|
91
|
+
if (!range(c.whole, WHOLES)) return `whole is ${words(c.whole)}, write the range of the whole as [low, high] from ${WHOLES[0]} to ${WHOLES[1]}, such as [11, 18]`;
|
|
92
|
+
if (!range(c.part, KNOWN)) return `part is ${words(c.part)}, write the range of the known part as [low, high] from ${KNOWN[0]} to ${KNOWN[1]}, such as [3, 9]`;
|
|
93
|
+
return asks(c).length ? null : 'whole and part leave no subtraction to draw, give part numbers below the whole';
|
|
94
|
+
},
|
|
95
|
+
draw: (c, spec, dice) => { const all = asks(c); return all.length ? dice.pick(all) : null; },
|
|
96
|
+
// put says that a tap on the frames puts a blue counter in the next cell.
|
|
97
|
+
page: t => ({ first: t.part, second: 0, put: true }),
|
|
98
|
+
holds(state, spec, c, t) {
|
|
99
|
+
if (!state.checked) return { done: false };
|
|
100
|
+
const missing = t.whole - t.part;
|
|
101
|
+
return state.put === missing ? { done: true } : { done: false, note: state.put > missing ? 'more' : 'less' };
|
|
102
|
+
},
|
|
103
|
+
reach: (spec, c, t) => t.whole > WHOLES[1] ? `the two frames hold ${WHOLES[1]}, fewer than ${t.whole}` : null,
|
|
104
|
+
line: (t, done) => ({ a: t.whole, sign: MINUS, b: t.part, open: !done }),
|
|
105
|
+
words: (c, t, f) => ({ whole: f.int(t.whole), part: f.int(t.part), missing: f.int(t.whole - t.part) }),
|
|
106
|
+
},
|
|
79
107
|
};
|
|
80
108
|
|
|
81
|
-
// The reader's state as a challenge opens: every stepper at 0 and nothing checked.
|
|
82
|
-
export const addStart = () => ({ sum: 0, toTen: 0, rest: 0, checked: false });
|
|
109
|
+
// The reader's state as a challenge opens: every stepper at 0, no counter put in and nothing checked.
|
|
110
|
+
export const addStart = () => ({ sum: 0, toTen: 0, rest: 0, put: 0, checked: false });
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
// What a counters/add page holds and what it counts: two groups of counters in two ten frames, or counters taken
|
|
2
2
|
// away from one group, or the jars of a shop shelf, and the written lines of their calculation. The build and the
|
|
3
3
|
// browser both use this file, so a page's text and its live values agree.
|
|
4
|
-
import { PLUS, MINUS } from '../../kit/written.js';
|
|
4
|
+
import { PLUS, MINUS, FACTS, FACT_IDS, factLine, finding } from '../../kit/written.js';
|
|
5
5
|
|
|
6
6
|
// frames is two ten frames, shelf a shop shelf of jars of jam with two crates under it, and tray a seed tray of two
|
|
7
|
-
// rows of ten that fills as the frames do, the first row first.
|
|
8
|
-
|
|
7
|
+
// rows of ten that fills as the frames do, the first row first. eggs is a box of ten eggs that fills as one ten frame
|
|
8
|
+
// does, and domino one domino whose two halves show the two groups as pips. squad is a football pitch with the players
|
|
9
|
+
// of the known part and a bench where the players of the missing part sit down.
|
|
10
|
+
export const ADD_LOOKS = ['frames', 'shelf', 'tray', 'eggs', 'domino', 'squad'];
|
|
11
|
+
// A team has this many players on the pitch, and the bench of the squad holds this many players at most.
|
|
12
|
+
export const PITCH = 11, BENCH = 9;
|
|
13
|
+
// The egg box holds this many eggs, and a half of a domino shows from 1 to 6 pips.
|
|
14
|
+
export const EGGS = 10;
|
|
15
|
+
export const PIPS = [1, 6];
|
|
9
16
|
// The two ten frames hold this many counters, and every counter of a page fits in them.
|
|
10
17
|
export const CELLS = 20;
|
|
11
18
|
// The shelf holds this many jars.
|
|
@@ -14,6 +21,12 @@ export const JARS = 10;
|
|
|
14
21
|
export const DIE = [1, 6];
|
|
15
22
|
|
|
16
23
|
const shelf = spec => spec.look === 'shelf';
|
|
24
|
+
// A family page writes the facts of its two groups.
|
|
25
|
+
export const family = spec => spec.written === 'family';
|
|
26
|
+
// A claim page writes the parts with a sum the reader claims, and checks it by taking the second part away again.
|
|
27
|
+
export const claims = spec => spec.claim != null;
|
|
28
|
+
// A page with a whole has outlined places for the missing part, which taps fill.
|
|
29
|
+
export const fills = spec => spec.whole != null;
|
|
17
30
|
// A seed tray with waiting has a packet of seeds beside it, and its written line writes the whole packet.
|
|
18
31
|
export const packet = spec => spec.look === 'tray' && spec.waiting != null;
|
|
19
32
|
|
|
@@ -22,7 +35,10 @@ export const packet = spec => spec.look === 'tray' && spec.waiting != null;
|
|
|
22
35
|
// in the afternoon. waiting is the counters of the second group in the tray.
|
|
23
36
|
// ten says that the figure shows the full ten: on an addition the first frame is full, and on a take away every
|
|
24
37
|
// counter of the second frame is taken. The counters open in order, so they show it as the page opens.
|
|
25
|
-
|
|
38
|
+
// On a cover page, cover is the half under the card, and found the number the written line finds, which it keeps
|
|
39
|
+
// once the card is lifted. On a claim page, claim is the sum the reader claims. On a page with a whole, whole is the whole and second the counters put in. On an undo page,
|
|
40
|
+
// done says that the join is done, which happens once the tray is empty for the first time.
|
|
41
|
+
export const opening = spec => ({ first: spec.first, second: spec.second, waiting: spec.waiting ?? 0, ten: true, cover: null, found: null, whole: spec.whole ?? null, done: false, claim: spec.claim ?? null });
|
|
26
42
|
|
|
27
43
|
// stepsOf gives the two steps of making ten while the calculation crosses ten and the figure shows the ten: to-ten
|
|
28
44
|
// fills the ten or takes the first number down to it, and rest is the rest of the second number. It gives null
|
|
@@ -43,37 +59,71 @@ export function stepsOf(spec, s) {
|
|
|
43
59
|
|
|
44
60
|
// counts gives every number a page can show. A take-away page leaves first minus second, and the shelf leaves the
|
|
45
61
|
// jars that are not sold.
|
|
62
|
+
// A page with a whole counts the missing part, and an undo page the counters taken back and left once the join is done.
|
|
46
63
|
export function counts(spec, s) {
|
|
47
64
|
const sum = s.first + s.second;
|
|
48
|
-
const steps = stepsOf(spec, s);
|
|
49
|
-
return { first: s.first, second: s.second, waiting: s.waiting, sum,
|
|
65
|
+
const steps = stepsOf(spec, s), undone = spec.undo && s.done;
|
|
66
|
+
return { first: s.first, second: s.second, waiting: s.waiting, sum, whole: fills(spec) ? s.whole : sum,
|
|
67
|
+
left: spec.take ? s.first - s.second : shelf(spec) ? JARS - sum : undone ? sum : null,
|
|
68
|
+
missing: fills(spec) ? s.whole - s.first : null, back: undone ? s.waiting : null, claim: claims(spec) ? s.claim : null,
|
|
50
69
|
'to-ten': steps?.toTen ?? null, rest: steps?.rest ?? null };
|
|
51
70
|
}
|
|
52
71
|
|
|
53
72
|
// lineOf gives the written line of the counters: first + second, or first − second on a take-away page. The line of
|
|
54
73
|
// a seed packet adds the seeds sown and in the packet, and takes its answer once the packet is empty.
|
|
55
|
-
|
|
74
|
+
// A cover page writes the addition until a half is covered, then the calculation that finds the covered half, open
|
|
75
|
+
// while the card is on.
|
|
76
|
+
// A page with a whole writes the subtraction that asks for the missing part, and a family page with a whole the first
|
|
77
|
+
// fact of its family. An undo page keeps the line of the join once it is done.
|
|
78
|
+
export const lineOf = (spec, s) => spec.cover && s.found ? finding(s.first, s.second, s.found, s.cover != null)
|
|
79
|
+
: claims(spec) ? { a: s.first, sign: PLUS, b: s.second, c: s.claim }
|
|
80
|
+
: fills(spec) ? (family(spec) ? factLine('written', s.first, s.whole - s.first) : askOf(spec, s))
|
|
81
|
+
: spec.undo && s.done ? { a: s.first, sign: PLUS, b: s.second + s.waiting }
|
|
82
|
+
: packet(spec) ? { a: s.first, sign: PLUS, b: s.second + s.waiting, open: s.waiting > 0 }
|
|
56
83
|
: { a: s.first, sign: spec.take ? MINUS : PLUS, b: s.second };
|
|
84
|
+
// askOf gives the subtraction that asks for the missing part, whole − first, open until every place is filled. Each
|
|
85
|
+
// number carries the link id of what it counts.
|
|
86
|
+
export const askOf = (spec, s) => ({ a: s.whole, sign: MINUS, b: s.first, open: s.second < s.whole - s.first, refs: { a: 'whole', b: 'first', c: 'missing' } });
|
|
87
|
+
// full says that every place of the missing part is filled.
|
|
88
|
+
export const full = s => s.second === s.whole - s.first;
|
|
89
|
+
// backOf gives the line that undoes the join: the sum of the join minus the counters taken back, once one is back.
|
|
90
|
+
// On a claim page it is the check of the claimed sum: the claim minus the second part.
|
|
91
|
+
export const backOf = (spec, s) => claims(spec) ? { a: s.claim, sign: MINUS, b: s.second } : spec.undo && s.done && s.waiting > 0 ? { a: s.first + s.second + s.waiting, sign: MINUS, b: s.waiting } : null;
|
|
92
|
+
// checked says whether the check of a claim page gives back the first part, so the claimed sum is right.
|
|
93
|
+
export const checked = s => s.claim - s.second === s.first;
|
|
57
94
|
// leftOf gives the shelf's line of the jars left: the jars of a full shelf minus the jars sold.
|
|
58
95
|
export const leftOf = (spec, s) => ({ a: JARS, sign: MINUS, b: s.first + s.second });
|
|
59
96
|
// The lines a link reads, by its id: the written line, its words, and on the shelf the line of the jars left.
|
|
60
97
|
// A step line gives null while the steps do not show.
|
|
61
98
|
const step = k => (spec, s) => stepsOf(spec, s)?.lines[k] ?? null;
|
|
62
|
-
|
|
63
|
-
|
|
99
|
+
// The facts of a family page beside the first addition, which is the written line. With a whole they are the facts of
|
|
100
|
+
// the known part and the missing part from the start, whatever the counters put in.
|
|
101
|
+
const fact = id => (spec, s) => factLine(id, s.first, fills(spec) ? s.whole - s.first : s.second);
|
|
102
|
+
export const LINES = { written: lineOf, reading: lineOf, 'written-left': leftOf, 'reading-left': leftOf, 'written-back': backOf, 'reading-back': backOf,
|
|
103
|
+
'written-to-ten': step(0), 'reading-to-ten': step(0), 'written-rest': step(1), 'reading-rest': step(1),
|
|
104
|
+
...Object.fromEntries(FACT_IDS.filter(id => !['written', 'reading'].includes(id)).map(id => [id, fact(id)])) };
|
|
64
105
|
|
|
65
106
|
// The measures a page can read out and link in its text. The written lines and their words come with written.
|
|
66
107
|
export function measuresOf(spec) {
|
|
67
108
|
if (spec.challenge) return [];
|
|
68
109
|
const lines = spec.written ? ['written', 'reading'] : [];
|
|
110
|
+
if (fills(spec)) return ['first', 'second', 'whole', 'missing', ...(family(spec) ? FACT_IDS : lines)];
|
|
111
|
+
if (claims(spec)) return ['first', 'second', 'claim', 'written', 'reading', 'written-back', 'reading-back'];
|
|
112
|
+
if (spec.undo) return ['first', 'second', 'sum', 'waiting', 'back', 'left', ...lines, 'written-back', 'reading-back'];
|
|
69
113
|
if (spec.written === 'ten') lines.push('to-ten', 'rest', 'written-to-ten', 'reading-to-ten', 'written-rest', 'reading-rest');
|
|
114
|
+
if (family(spec)) return ['first', 'second', 'whole', ...FACT_IDS];
|
|
115
|
+
if (spec.look === 'domino') return ['first', 'second', 'whole', ...lines];
|
|
70
116
|
if (shelf(spec)) return ['first', 'second', 'sum', 'left', ...lines, ...(spec.written ? ['written-left', 'reading-left'] : [])];
|
|
71
117
|
if (spec.take) return ['first', 'second', 'left', ...lines];
|
|
72
118
|
return ['first', 'second', 'sum', ...(spec.waiting != null ? ['waiting'] : []), ...lines];
|
|
73
119
|
}
|
|
74
120
|
|
|
75
121
|
// The context of a page picks the names of its readouts and steppers, such as "Taken away" for second.
|
|
76
|
-
|
|
122
|
+
// A family page and the eggs name their groups as parts, and the domino as halves. A page with a whole names the known
|
|
123
|
+
// part and the missing part, and an undo page the counters taken back.
|
|
124
|
+
export const contextOf = spec => shelf(spec) ? 'shelf' : spec.look === 'squad' ? 'squad' : fills(spec) ? 'whole' : spec.undo ? 'undo' : spec.look === 'domino' ? 'domino' : family(spec) || spec.look === 'eggs' ? 'family' : spec.take ? 'take' : 'add';
|
|
125
|
+
// The facts a family page writes, all four when it lists none.
|
|
126
|
+
export const factsListed = spec => spec.facts ?? FACTS;
|
|
77
127
|
// labelKeys gives the strings that may name a readout or a stepper, the page's own first, so to-ten reads "Makes ten"
|
|
78
128
|
// on an addition and "Down to ten" on a take away. A dice page comes before the word sum, so its count has a plain name.
|
|
79
129
|
export const labelKeys = (spec, id) => [...(spec.dice ? [`add-dice-${id}`] : []), `add-${contextOf(spec)}-${id}`, `add-${id}`];
|