@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
|
@@ -68,6 +68,9 @@
|
|
|
68
68
|
.hesap-counters .counters-pin-stripe{fill:var(--z-counters-red,#d1453b)}
|
|
69
69
|
.hesap-counters .counters-spot{fill:var(--rule)}
|
|
70
70
|
.hesap-counters .counters-down .counters-pin-body{opacity:.45}
|
|
71
|
+
.hesap-counters .counters-ball{pointer-events:none}
|
|
72
|
+
.hesap-counters .counters-ball-shape{fill:var(--z-counters-blue,#2a6bd1);stroke:var(--ink);stroke-width:2}
|
|
73
|
+
.hesap-counters .counters-ball-hole{fill:var(--ink)}
|
|
71
74
|
.hesap-counters .counters-pin:focus-visible .counters-hit{stroke:var(--accent);stroke-width:2.5}
|
|
72
75
|
|
|
73
76
|
/* The car park: two rows of spaces, an aisle, and a sign that shows the free spaces. */
|
|
@@ -273,3 +276,102 @@
|
|
|
273
276
|
.hesap-counters .counters-paired-lit .counters-hit{fill:var(--accent);fill-opacity:.6;stroke:var(--accent);stroke-width:4}
|
|
274
277
|
.hesap-counters .counters-paired-lit .counters-body{stroke:var(--paper);stroke-width:2.5}
|
|
275
278
|
.hesap-counters .counters-wire.counters-hot{stroke:var(--accent);stroke-width:5}
|
|
279
|
+
|
|
280
|
+
/* The egg box: a carton of ten cups, brown eggs with speckles and white eggs with a shell outline. The numbers of the
|
|
281
|
+
facts take the brown and the shell as the colours of the two parts. */
|
|
282
|
+
.hesap-counters .counters-egg-a{--c:var(--z-counters-brown,#a0602c)}
|
|
283
|
+
.hesap-counters .counters-egg-b{--c:var(--z-counters-shell,#7f7462)}
|
|
284
|
+
.hesap-counters .counters-carton{fill:#dcc9a4;stroke:#a88a55;stroke-width:2.5}
|
|
285
|
+
.hesap-counters .counters-egg-cup{fill:#c8b088;stroke:#a88a55;stroke-width:1}
|
|
286
|
+
.hesap-counters .counters-egg-brown .counters-body{fill:var(--z-counters-brown,#a0602c);stroke:#6b3d1c;stroke-width:1.5}
|
|
287
|
+
.hesap-counters .counters-egg-white .counters-body{fill:#fbf8f1;stroke:var(--z-counters-shell,#7f7462);stroke-width:2}
|
|
288
|
+
.hesap-counters .counters-speck{fill:#5a3215;stroke:none}
|
|
289
|
+
.hesap-counters .counters-lit:is(.counters-egg-brown,.counters-egg-white) .counters-body{stroke:var(--accent);stroke-width:4}
|
|
290
|
+
/* 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
|
|
291
|
+
close to the counter's own colour. */
|
|
292
|
+
.hesap-counters .counters-layer .counters-lit .counters-hit{stroke:var(--ink);stroke-width:2.5}
|
|
293
|
+
|
|
294
|
+
/* The facts of a family: each fact is a button in a box, and the picked fact is outlined in the accent. */
|
|
295
|
+
.hesap-counters .counters-fact{cursor:pointer;outline:none}
|
|
296
|
+
.hesap-counters .counters-fact-box{fill:transparent;stroke:var(--rule);stroke-width:1.5}
|
|
297
|
+
.hesap-counters .counters-fact:hover .counters-fact-box{fill:var(--accent);fill-opacity:.08}
|
|
298
|
+
.hesap-counters .counters-fact:focus-visible .counters-fact-box{stroke:var(--accent);stroke-width:3}
|
|
299
|
+
.hesap-counters .counters-fact-on .counters-fact-box{fill:var(--accent);fill-opacity:.12;stroke:var(--accent);stroke-width:3}
|
|
300
|
+
|
|
301
|
+
/* The domino: two halves of pips, the whole above it, and the card that covers a half. */
|
|
302
|
+
.hesap-counters .counters-domino{fill:var(--paper);stroke:var(--ink);stroke-width:3}
|
|
303
|
+
.hesap-counters .counters-domino-bar{stroke:var(--ink);stroke-width:2.5}
|
|
304
|
+
.hesap-counters .counters-domino-pip{fill:var(--c)}
|
|
305
|
+
.hesap-counters .counters-half{cursor:pointer;outline:none}
|
|
306
|
+
.hesap-counters .counters-half-box{fill:transparent;stroke:none}
|
|
307
|
+
.hesap-counters .counters-half:hover .counters-half-box{fill:var(--accent);fill-opacity:.08}
|
|
308
|
+
.hesap-counters .counters-half:focus-visible .counters-half-box{stroke:var(--accent);stroke-width:3}
|
|
309
|
+
.hesap-counters .counters-half.counters-hot{stroke:none}
|
|
310
|
+
.hesap-counters .counters-half.counters-hot .counters-half-box{stroke:var(--accent);stroke-width:4}
|
|
311
|
+
.hesap-counters .counters-domino-whole{font-size:40px;font-weight:700}
|
|
312
|
+
.hesap-counters .counters-domino-whole.counters-hot{stroke:none;fill:var(--accent)}
|
|
313
|
+
.hesap-counters .counters-domino-card{cursor:pointer;outline:none}
|
|
314
|
+
.hesap-counters .counters-domino-card-box{fill:var(--panel);stroke:var(--ink);stroke-width:2.5}
|
|
315
|
+
.hesap-counters .counters-domino-card:focus-visible .counters-domino-card-box{stroke:var(--accent);stroke-width:4}
|
|
316
|
+
.hesap-counters .counters-cover-q{font-size:60px;font-weight:700;fill:var(--ink-2)}
|
|
317
|
+
|
|
318
|
+
/* The places of a missing part are outlined squares that the counters put in cover. A counter put in carries the number
|
|
319
|
+
the count reaches, and the red counters let a tap through to the frames. */
|
|
320
|
+
.hesap-counters .counters-gap-place{fill:none;stroke:var(--ink-2);stroke-width:2;stroke-dasharray:5 4;pointer-events:none}
|
|
321
|
+
.hesap-counters .counters-gap-place.counters-hot{stroke:var(--accent);stroke-width:3.5}
|
|
322
|
+
.hesap-counters .counters-still{pointer-events:none}
|
|
323
|
+
.hesap-counters .counters-numbered .counters-ring{display:none}
|
|
324
|
+
.hesap-counters text.counters-num{fill:#fff;font-size:15px;font-weight:700}
|
|
325
|
+
.hesap-counters .counters-taken text.counters-num{display:none}
|
|
326
|
+
/* The squad: a pitch of grass with white lines, and a bench beside it. */
|
|
327
|
+
.hesap-counters .counters-pitch{fill:#4f8f45;stroke:var(--ink-2);stroke-width:2}
|
|
328
|
+
.hesap-counters .counters-pitch.counters-hot{stroke:var(--accent);stroke-width:4}
|
|
329
|
+
.hesap-counters .counters-pitch-line{fill:none;stroke:#fff;stroke-width:2;stroke-opacity:.85;pointer-events:none}
|
|
330
|
+
.hesap-counters .counters-bench{fill:var(--panel);stroke:var(--ink-2);stroke-width:2}
|
|
331
|
+
.hesap-counters .counters-bench.counters-hot{stroke:var(--accent);stroke-width:4}
|
|
332
|
+
/* 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. */
|
|
333
|
+
.hesap-counters text.counters-verdict{font-size:17px;font-weight:600;fill:var(--accent)}
|
|
334
|
+
.hesap-counters text.counters-verdict.counters-verdict-right{fill:var(--ink)}
|
|
335
|
+
.hesap-counters .counters-shirt .counters-body{stroke:var(--ink);stroke-width:1.5;stroke-linejoin:round}
|
|
336
|
+
|
|
337
|
+
/* The bar model: two parts drawn to scale with the whole above them over a bracket, the handles of the split and the
|
|
338
|
+
end, and the card that covers a number. A subtraction draws the part it takes away pale with a dashed outline. */
|
|
339
|
+
.hesap-counters .counters-bar-row{pointer-events:none}
|
|
340
|
+
.hesap-counters .counters-bar-part{fill:var(--c);fill-opacity:.2;stroke:var(--c);stroke-width:2.5}
|
|
341
|
+
.hesap-counters .counters-bar-num{font-size:24px;font-weight:700;fill:var(--c)}
|
|
342
|
+
.hesap-counters .counters-bar-lead{stroke:var(--c);stroke-width:1.5}
|
|
343
|
+
.hesap-counters .counters-bar-whole{font-size:30px;font-weight:700}
|
|
344
|
+
.hesap-counters .counters-bracket{fill:none;stroke:var(--ink-2);stroke-width:2.5;stroke-linejoin:round}
|
|
345
|
+
.hesap-counters .counters-bar-outline{fill:none;stroke:var(--ink);stroke-width:2.5}
|
|
346
|
+
.hesap-counters .counters-bar-split{stroke:var(--ink);stroke-width:3}
|
|
347
|
+
.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}
|
|
348
|
+
.hesap-counters .counters-bar-num.counters-hot,.hesap-counters .counters-bar-whole.counters-hot{stroke:none;fill:var(--accent)}
|
|
349
|
+
.hesap-counters .counters-bar-gone .counters-bar-part{fill-opacity:.04;stroke-dasharray:7 5;stroke-width:2.5}
|
|
350
|
+
.hesap-counters .counters-bar-gone .counters-bar-num,.hesap-counters .counters-bar-gone .counters-choc-grooves{opacity:.4}
|
|
351
|
+
.hesap-counters .counters-handle{cursor:ew-resize;outline:none}
|
|
352
|
+
.hesap-counters .counters-handle-hit{fill:transparent}
|
|
353
|
+
.hesap-counters .counters-knob{fill:var(--paper);stroke:var(--ink);stroke-width:2.5;stroke-linejoin:round}
|
|
354
|
+
.hesap-counters .counters-grip{fill:none;stroke:var(--ink-2);stroke-width:2;stroke-linecap:round}
|
|
355
|
+
.hesap-counters .counters-handle.drag .counters-knob,.hesap-counters .counters-handle.counters-hot .counters-knob{fill:var(--accent);stroke:var(--accent)}
|
|
356
|
+
.hesap-counters .counters-handle:focus-visible .counters-knob{stroke:var(--accent);stroke-width:4}
|
|
357
|
+
.hesap-counters .counters-bar-tap{fill:transparent;cursor:pointer;outline:none}
|
|
358
|
+
.hesap-counters .counters-bar-tap:hover{fill:var(--accent);fill-opacity:.08}
|
|
359
|
+
.hesap-counters .counters-bar-tap:focus-visible{stroke:var(--accent);stroke-width:3}
|
|
360
|
+
.hesap-counters .counters-bar-card{cursor:pointer;outline:none}
|
|
361
|
+
.hesap-counters .counters-bar-card-box{fill:var(--panel);stroke:var(--ink);stroke-width:2.5}
|
|
362
|
+
.hesap-counters .counters-bar-card:focus-visible .counters-bar-card-box{stroke:var(--accent);stroke-width:4}
|
|
363
|
+
.hesap-counters .counters-bar-card-q{font-size:28px;font-weight:700;fill:var(--ink-2)}
|
|
364
|
+
/* 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. */
|
|
365
|
+
.hesap-counters .counters-bar-part.counters-choc{fill:#6b3f23;fill-opacity:1;stroke:var(--c);stroke-width:3}
|
|
366
|
+
.hesap-counters .counters-bar-part.counters-choc.counters-hot{stroke:var(--accent);stroke-width:4}
|
|
367
|
+
.hesap-counters .counters-choc-grooves line{stroke:#4a2a15;stroke-width:2}
|
|
368
|
+
.hesap-counters .counters-choc-badge{fill:var(--paper);stroke:var(--c);stroke-width:2.5}
|
|
369
|
+
.hesap-counters .counters-choc~.counters-bar-num{font-size:18px}
|
|
370
|
+
.hesap-counters .counters-bar-gone .counters-bar-part.counters-choc{fill-opacity:.3}
|
|
371
|
+
/* The number of a bar-for-two bar that the reader finds: its part or its bracket is dashed and its number is a
|
|
372
|
+
question mark. */
|
|
373
|
+
.hesap-counters .counters-bar-unknown .counters-bar-part{fill:none;stroke-dasharray:7 5}
|
|
374
|
+
.hesap-counters .counters-bracket-unknown{stroke-dasharray:6 5}
|
|
375
|
+
/* A fact's place the page leaves empty is a dashed box with nothing in it. */
|
|
376
|
+
.hesap-counters .counters-fact-empty{cursor:default}
|
|
377
|
+
.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}
|
|
@@ -5,9 +5,10 @@ import count from './count.js';
|
|
|
5
5
|
import match from './match.js';
|
|
6
6
|
import order from './order.js';
|
|
7
7
|
import add from './add.js';
|
|
8
|
+
import bar from './bar.js';
|
|
8
9
|
import { scenes } from './scenes.js';
|
|
9
10
|
|
|
10
|
-
const SCENES = { bonds, count, match, order, add };
|
|
11
|
+
const SCENES = { bonds, count, match, order, add, bar };
|
|
11
12
|
|
|
12
13
|
export default function counters(api) {
|
|
13
14
|
const all = scenes(Object.fromEntries(Object.entries(SCENES).map(([name, make]) => [name, () => make(api)])), api.stage);
|
|
@@ -29,6 +29,8 @@ const OBJECTS = {
|
|
|
29
29
|
chair: r => [el('path', { class: 'counters-legs', d: `M ${-r * 0.55} ${r * 0.15} L ${-r * 0.55} ${r} M ${r * 0.6} ${r * 0.15} L ${r * 0.6} ${r}` }),
|
|
30
30
|
el('rect', { class: 'counters-body', x: -r * 0.75, y: -r, width: r * 0.4, height: r * 1.3, rx: r * 0.15 }),
|
|
31
31
|
el('rect', { class: 'counters-body', x: -r * 0.75, y: -r * 0.05, width: r * 1.55, height: r * 0.4, rx: r * 0.15 })],
|
|
32
|
+
// A football shirt seen from the front, with room for its number.
|
|
33
|
+
shirt: r => [el('path', { class: 'counters-body', d: `M ${-r * 0.42} ${-r * 0.95} L ${-r * 1.05} ${-r * 0.62} L ${-r * 1.15} ${-r * 0.05} L ${-r * 0.72} ${r * 0.02} L ${-r * 0.72} ${r * 0.98} L ${r * 0.72} ${r * 0.98} L ${r * 0.72} ${r * 0.02} L ${r * 1.15} ${-r * 0.05} L ${r * 1.05} ${-r * 0.62} L ${r * 0.42} ${-r * 0.95} Q 0 ${-r * 0.55} ${-r * 0.42} ${-r * 0.95} Z` })],
|
|
32
34
|
// A football: a ball in its team's colour with a patch.
|
|
33
35
|
ball: r => [el('circle', { class: 'counters-body', r }), el('path', { class: 'counters-patch', d: `M 0 ${-r * 0.5} L ${r * 0.48} ${-r * 0.15} L ${r * 0.3} ${r * 0.42} L ${-r * 0.3} ${r * 0.42} L ${-r * 0.48} ${-r * 0.15} Z` })],
|
|
34
36
|
saucer: r => [el('ellipse', { class: 'counters-body', rx: r * 1.5, ry: r * 0.5 }), el('ellipse', { class: 'counters-well', rx: r * 0.8, ry: r * 0.24 })],
|
|
@@ -50,6 +52,10 @@ function glyph(kind, r) {
|
|
|
50
52
|
el('rect', { class: 'counters-jar-lid', x: -r * 0.86, y: -r * 1.08, width: r * 1.72, height: r * 0.46, rx: r * 0.12 })];
|
|
51
53
|
// A square counter tells the second group of counters/add from the round first group by its shape.
|
|
52
54
|
if (kind === 'square') return [el('rect', { class: 'counters-body', x: -r * 0.9, y: -r * 0.9, width: r * 1.8, height: r * 1.8, rx: r * 0.22 }), el('rect', { class: 'counters-ring', x: -r * 0.52, y: -r * 0.52, width: r * 1.04, height: r * 1.04, rx: r * 0.1 })];
|
|
55
|
+
// An egg stands upright in its cup. A brown egg has speckles, so the two sorts of the egg box differ by more than
|
|
56
|
+
// their colour.
|
|
57
|
+
if (kind === 'egg-brown' || kind === 'egg-white') return [el('ellipse', { class: 'counters-body', rx: r * 0.8, ry: r * 1.02 }),
|
|
58
|
+
...(kind === 'egg-brown' ? [[-0.35, -0.45], [0.3, -0.2], [-0.15, 0.25], [0.35, 0.5], [-0.42, 0.62], [0.05, -0.75]].map(([cx, cy]) => el('circle', { class: 'counters-speck', cx: cx * r, cy: cy * r, r: r * 0.09 })) : [])];
|
|
53
59
|
if (kind === 'bead') return [el('circle', { class: 'counters-body', r }), el('circle', { class: 'counters-shine', r: r * 0.32, cx: -r * 0.35, cy: -r * 0.35 })];
|
|
54
60
|
if (kind === 'car') {
|
|
55
61
|
const w = r * 1.5, l = r * 2.5;
|
|
@@ -72,6 +78,13 @@ export function counter(kind, colour, r = R, n = 0) {
|
|
|
72
78
|
return { g, pop, at: { x: 0, y: 0 }, colour };
|
|
73
79
|
}
|
|
74
80
|
|
|
81
|
+
// gone draws the dashed outline a counter of this kind leaves when it is taken away.
|
|
82
|
+
export function gone(kind, r = R) {
|
|
83
|
+
if (kind === 'square') return el('rect', { class: 'counters-void counters-gone', x: -r * 0.86, y: -r * 0.86, width: r * 1.72, height: r * 1.72, rx: r * 0.22 });
|
|
84
|
+
if (kind.startsWith('egg')) return el('ellipse', { class: 'counters-void counters-gone', rx: r * 0.76, ry: r * 0.98 });
|
|
85
|
+
return el('circle', { class: 'counters-void counters-gone', r: r - 2 });
|
|
86
|
+
}
|
|
87
|
+
|
|
75
88
|
// show draws a counter where its at says, and put moves it there.
|
|
76
89
|
export const show = c => c.g.setAttribute('transform', `translate(${c.at.x} ${c.at.y})`);
|
|
77
90
|
export const put = (c, p) => { c.at.x = p.x; c.at.y = p.y; show(c); };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The facts of a family under a figure: the two additions above and the two subtractions under them. Each fact is a button named by its reading, and a tap picks it. A fact the page leaves out, or the second
|
|
2
|
+
// of two equal facts, keeps its place empty, so the block does not move when the numbers change.
|
|
3
|
+
import { svg as el } from '../../kit/dom.js';
|
|
4
|
+
import { writtenLine, widthOf, reading, FACTS, FACT_IDS, factsOf, shownFacts, sameFact } from '../../kit/written.js';
|
|
5
|
+
import { press } from './move.js';
|
|
6
|
+
|
|
7
|
+
// A fact's box is this much wider than its widest line, and the boxes stand GAP apart.
|
|
8
|
+
const FACT_W = widthOf('00 + 00 = 00') + 20, GAP = 10;
|
|
9
|
+
|
|
10
|
+
// factsBlock makes the block. tint gives a line the classes of its numbers, and pick runs on a tap on a fact.
|
|
11
|
+
export function factsBlock({ tint, pick }) {
|
|
12
|
+
const slots = FACTS.map(id => {
|
|
13
|
+
const line = writtenLine(), box = el('rect', { class: 'counters-fact-box', rx: 8 });
|
|
14
|
+
const g = el('g', { class: 'counters-fact', role: 'button', 'data-fact': id }, [box, line.el]);
|
|
15
|
+
press(g, () => { if (g.getAttribute('display') !== 'none' && !g.classList.contains('counters-fact-empty')) pick(id); });
|
|
16
|
+
return { id, g, box, line };
|
|
17
|
+
});
|
|
18
|
+
const group = el('g', { class: 'counters-facts', role: 'group' }, slots.map(s => s.g));
|
|
19
|
+
let parts = [0, 0], lit = new Set();
|
|
20
|
+
// mine gives the links that light a slot. With two equal parts the swap lights the first addition, and the whole
|
|
21
|
+
// minus the first part lights the whole minus the second. lights gives those the reader points at.
|
|
22
|
+
const mine = slot => FACT_IDS.filter(id => sameFact(id, ...parts) === slot.id), lights = slot => mine(slot).filter(id => lit.has(id));
|
|
23
|
+
return {
|
|
24
|
+
el: group,
|
|
25
|
+
// ways gives the block's size for a row of this height: two rows of two, so each fact keeps its place, such as
|
|
26
|
+
// the empty place beside an addition or the first column of a family of two facts.
|
|
27
|
+
ways: row => [{ cols: 2, w: 2 * FACT_W + GAP, h: 2 * row + GAP }],
|
|
28
|
+
// at puts the block's top left corner at x, y in the way of cols columns.
|
|
29
|
+
at(x, y, cols, row) {
|
|
30
|
+
slots.forEach((s, k) => {
|
|
31
|
+
const c = cols === 2 ? k % 2 : 0, r = cols === 2 ? Math.floor(k / 2) : k, bx = x + c * (FACT_W + GAP), by = y + r * (row + GAP);
|
|
32
|
+
for (const [a, v] of Object.entries({ x: bx, y: by, width: FACT_W, height: row })) s.box.setAttribute(a, v);
|
|
33
|
+
s.line.at(bx + FACT_W / 2, by + row / 2);
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
// set writes the facts of the two parts that the page lists, names each by its reading and marks the picked one.
|
|
37
|
+
// lines puts another line in a place, such as a challenge's drawn fact in the first place. It gives the lines
|
|
38
|
+
// whose words changed, for a flash.
|
|
39
|
+
set({ first, second, listed, int, T, picked, lines: over = {} }) {
|
|
40
|
+
parts = [first, second];
|
|
41
|
+
const shown = shownFacts(first, second, listed), lines = { ...factsOf(first, second), ...over }, changed = [];
|
|
42
|
+
group.setAttribute('aria-label', T('facts'));
|
|
43
|
+
// A place the page leaves out shows as an empty dashed box, so the reader sees a place there. The second of two
|
|
44
|
+
// equal facts has no place.
|
|
45
|
+
const own = shownFacts(first, second);
|
|
46
|
+
for (const s of slots) {
|
|
47
|
+
const on = shown.includes(s.id), empty = !on && own.includes(s.id);
|
|
48
|
+
s.g.setAttribute('display', on || empty ? 'inline' : 'none');
|
|
49
|
+
s.g.classList.toggle('counters-fact-empty', empty);
|
|
50
|
+
if (!on) {
|
|
51
|
+
for (const a of ['tabindex', 'role', 'aria-label', 'aria-pressed']) s.g.removeAttribute(a);
|
|
52
|
+
s.g.classList.remove('counters-fact-on'); s.line.set(null, int);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
s.g.setAttribute('tabindex', 0); s.g.setAttribute('role', 'button');
|
|
56
|
+
if (s.line.set(tint(lines[s.id]), int)) changed.push(s.line.el);
|
|
57
|
+
s.g.setAttribute('aria-label', reading(lines[s.id], int, T));
|
|
58
|
+
s.g.setAttribute('aria-pressed', String(picked === s.id));
|
|
59
|
+
s.g.classList.toggle('counters-fact-on', picked === s.id || lights(s).length > 0);
|
|
60
|
+
s.line.light('', false, mine(s));
|
|
61
|
+
}
|
|
62
|
+
return changed;
|
|
63
|
+
},
|
|
64
|
+
// light marks the numbers a link points to in every fact, and a whole fact for a link to a fact.
|
|
65
|
+
light(id, on) {
|
|
66
|
+
if (on) lit.add(id); else lit.delete(id);
|
|
67
|
+
for (const s of slots) {
|
|
68
|
+
s.line.light(id, on, mine(s));
|
|
69
|
+
if (FACT_IDS.includes(id)) s.g.classList.toggle('counters-fact-on', s.g.getAttribute('aria-pressed') === 'true' || lights(s).length > 0);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -99,9 +99,11 @@ export function splits(ways) {
|
|
|
99
99
|
|
|
100
100
|
// A bowling pin's outline, standing on 0, 0.
|
|
101
101
|
const PIN = 'M -7 0 C -13 -12 -12 -26 -6 -36 C -4 -40 -5 -44 -5 -48 C -6 -56 -3 -62 0 -62 C 3 -62 6 -56 5 -48 C 5 -44 4 -40 6 -36 C 12 -26 13 -12 7 0 Z';
|
|
102
|
-
|
|
102
|
+
const RUN = 84; // The length of lane in front of the head pin that the ball rolls along.
|
|
103
|
+
// pins stand at the end of a lane in rows of 4, 3, 2 and 1, and the ball rests at the near end. Cell 0 is the head pin
|
|
104
|
+
// at the front.
|
|
103
105
|
export function pins() {
|
|
104
|
-
const dx = 58, dy = 46, w = 4 * dx + 56, h = 70 + 3 * dy + 40;
|
|
106
|
+
const dx = 58, dy = 46, w = 4 * dx + 56, h = 70 + 3 * dy + 40 + RUN;
|
|
105
107
|
return [{ w, h, draw(x, y) {
|
|
106
108
|
const spots = [], order = [[3, 1], [2, 2], [1, 3], [0, 4]];
|
|
107
109
|
for (const [row, n] of order) for (let k = 0; k < n; k++) spots.push({ x: x + w / 2 + (k - (n - 1) / 2) * dx, y: y + 70 + row * dy });
|
|
@@ -109,10 +111,16 @@ export function pins() {
|
|
|
109
111
|
const pinsOf = spots.map((p, i) => {
|
|
110
112
|
const body = el('g', { class: 'counters-pin-body' }, [el('path', { class: 'counters-pin-shape', d: PIN }), el('rect', { class: 'counters-pin-stripe', x: -5, y: -44, width: 10, height: 3 }), el('rect', { class: 'counters-pin-stripe', x: -5, y: -39, width: 10, height: 3 })]);
|
|
111
113
|
const g = el('g', { class: 'counters-pin', transform: `translate(${p.x} ${p.y})`, tabindex: 0, role: 'button', 'data-cell': i }, [el('rect', { class: 'counters-hit', x: -27, y: -48, width: 54, height: 54 }), el('ellipse', { class: 'counters-spot', rx: 10, ry: 4 }), body]);
|
|
112
|
-
return { g, body, tilt: { a: 0 } };
|
|
114
|
+
return { g, body, tilt: { a: 0 }, x: p.x, y: p.y };
|
|
113
115
|
});
|
|
116
|
+
// The ball goes behind the pins, so a pin it reaches covers it. It rolls from rest to past the back row.
|
|
117
|
+
// The outer group takes the ball's place, and the inner one takes the pop, whose CSS transform would replace it.
|
|
118
|
+
const look = el('g', {}, [el('circle', { class: 'counters-ball-shape', r: 15 }),
|
|
119
|
+
...[[-4, -6], [3, -7], [-1, 0]].map(([cx, cy]) => el('circle', { class: 'counters-ball-hole', cx, cy, r: 2.4 }))]);
|
|
120
|
+
const ball = el('g', { class: 'counters-ball' }, [look]);
|
|
121
|
+
const rest = { x: x + w / 2, y: y + h - 26 }, end = { y: y + 30 };
|
|
114
122
|
// The pins at the back are drawn first, so the front pins stand before them.
|
|
115
|
-
return { nodes: [lane, ...[...pinsOf].reverse().map(p => p.g)], places: {}, refs: { pins: pinsOf, lane } };
|
|
123
|
+
return { nodes: [lane, ball, ...[...pinsOf].reverse().map(p => p.g)], places: {}, refs: { pins: pinsOf, lane, ball: { g: ball, look, rest, end } } };
|
|
116
124
|
} }];
|
|
117
125
|
}
|
|
118
126
|
|
|
@@ -196,3 +196,67 @@ counters_hint-steps-to-ten-minus: "First work out how many to take away to bring
|
|
|
196
196
|
counters_add-take-to-ten: Down to ten
|
|
197
197
|
counters_goal-steps-to-ten-minus: "Split the {second} in {calc} into the part that takes {first} down to ten and the rest, then press Check."
|
|
198
198
|
counters_add-shelf-left: Left
|
|
199
|
+
counters_add-family-first: First part
|
|
200
|
+
counters_add-family-second: Second part
|
|
201
|
+
counters_add-family-whole: Whole
|
|
202
|
+
counters_add-domino-first: First half
|
|
203
|
+
counters_add-domino-second: Second half
|
|
204
|
+
counters_add-domino-whole: Whole
|
|
205
|
+
counters_add-domino-cover: "Cover the half that shows {x}"
|
|
206
|
+
counters_add-domino-lift: Lift the card
|
|
207
|
+
counters_add-whole-whole: Whole
|
|
208
|
+
counters_add-whole-first: Known part
|
|
209
|
+
counters_add-whole-missing: Missing part
|
|
210
|
+
counters_add-whole-second: Counters put in
|
|
211
|
+
counters_add-claim: Sum
|
|
212
|
+
counters_add-claim-right: "The check gives back {first}, so the sum is right."
|
|
213
|
+
counters_add-claim-wrong: "{back} is not {first}, so the sum is wrong."
|
|
214
|
+
counters_add-squad-whole: Squad
|
|
215
|
+
counters_add-squad-first: On the pitch
|
|
216
|
+
counters_add-squad-missing: Bench seats
|
|
217
|
+
counters_add-squad-second: On the bench
|
|
218
|
+
counters_add-undo-back: Taken back
|
|
219
|
+
counters_add-undo-left: Left
|
|
220
|
+
counters_add-whole-put: Put a counter in the next place
|
|
221
|
+
counters_add-put: Put in a counter
|
|
222
|
+
counters_add-squad-put: Seat the next player on the bench
|
|
223
|
+
counters_add-squad-player: "Player {x} on the pitch"
|
|
224
|
+
counters_add-squad-bench: "Player {x} on the bench"
|
|
225
|
+
counters_add-whole-out: "Counter {x}. Take out the last counter."
|
|
226
|
+
counters_add-out: Take out the last counter
|
|
227
|
+
counters_goal-missing-part: "Put in the part that {calc} asks for, then press Check."
|
|
228
|
+
counters_goal-missing-part-done: "{line}, since {part} and {missing} make {whole}."
|
|
229
|
+
counters_note-missing-part-more: "{part} and {put} make {made}, more than {whole}."
|
|
230
|
+
counters_note-missing-part-less: "{part} and {put} make {made}, less than {whole}."
|
|
231
|
+
counters_hint-missing-part: "{calc} asks: {part} and what make {whole}? Count on from {part} to {whole} and put in a counter for each number you say."
|
|
232
|
+
counters_bar-first: First part
|
|
233
|
+
counters_bar-second: Second part
|
|
234
|
+
counters_bar-whole: Whole
|
|
235
|
+
counters_bar-chocolate-first: First piece
|
|
236
|
+
counters_bar-chocolate-second: Second piece
|
|
237
|
+
counters_bar-chocolate-whole: Squares
|
|
238
|
+
counters_bar-split: Split
|
|
239
|
+
counters_bar-end: End
|
|
240
|
+
counters_bar-cover-whole: Cover the whole
|
|
241
|
+
counters_bar-cover-first: Cover the first part
|
|
242
|
+
counters_bar-cover-second: Cover the second part
|
|
243
|
+
counters_bar-lift: Lift the card
|
|
244
|
+
counters_goal-bar-for-fact: "Set the bar model of the family of {fact}, then press Check."
|
|
245
|
+
counters_goal-bar-for-fact-done: "{whole} is the whole, and {first} and {second} are its parts."
|
|
246
|
+
counters_note-bar-for-fact-longer: "The bar is longer than the whole of {fact}."
|
|
247
|
+
counters_note-bar-for-fact-shorter: "The bar is shorter than the whole of {fact}."
|
|
248
|
+
counters_bar-use: Use them as
|
|
249
|
+
counters_bar-use-parts: the two parts
|
|
250
|
+
counters_bar-use-whole: the whole and a part
|
|
251
|
+
counters_bar-third: Third number
|
|
252
|
+
counters_note-bar-for-fact-right: "The whole is right, and the split is too far to the left for the parts of {fact}. Drag it to the right."
|
|
253
|
+
counters_note-bar-for-fact-left: "The whole is right, and the split is too far to the right for the parts of {fact}. Drag it to the left."
|
|
254
|
+
counters_hint-bar-for-fact-plus: "In {fact}, the whole comes after the = sign. Drag the end to the whole, then split it into the two parts."
|
|
255
|
+
counters_hint-bar-for-fact-minus: "In {fact}, the whole comes first. Drag the end to the whole, then split it into the other two numbers."
|
|
256
|
+
counters_goal-bar-for-two: "Find a third number that makes a family with {greater} and {less}, then press Check."
|
|
257
|
+
counters_goal-bar-for-two-done: "The family of {greater}, {less} and {mine} holds both numbers. So does the family of {greater}, {less} and {other}."
|
|
258
|
+
counters_note-bar-for-two-parts-over: "{greater} and {less} make less than {n}."
|
|
259
|
+
counters_note-bar-for-two-parts-under: "{greater} and {less} make more than {n}."
|
|
260
|
+
counters_note-bar-for-two-whole-over: "{less} and {n} make more than {greater}."
|
|
261
|
+
counters_note-bar-for-two-whole-under: "{less} and {n} make less than {greater}."
|
|
262
|
+
counters_hint-bar-for-two: "A family holds a whole and two parts. Use {greater} and {less} as the two parts and add them, or use {greater} as the whole and {less} as a part and find the missing part."
|
|
@@ -196,3 +196,67 @@ counters_hint-steps-to-ten-minus: "Ona kadar, {first} sayısının dolu onluğun
|
|
|
196
196
|
counters_add-take-to-ten: Ona kadar
|
|
197
197
|
counters_goal-steps-to-ten-minus: "{calc} için Ona kadar ve Diğer parça düğmelerini ayarlayın, sonra Kontrol et düğmesine basın."
|
|
198
198
|
counters_add-shelf-left: Kalan
|
|
199
|
+
counters_add-family-first: Birinci parça
|
|
200
|
+
counters_add-family-second: İkinci parça
|
|
201
|
+
counters_add-family-whole: Bütün
|
|
202
|
+
counters_add-domino-first: Birinci yarı
|
|
203
|
+
counters_add-domino-second: İkinci yarı
|
|
204
|
+
counters_add-domino-whole: Bütün
|
|
205
|
+
counters_add-domino-cover: "{x} gösteren yarıyı kapat"
|
|
206
|
+
counters_add-domino-lift: Kartı kaldır
|
|
207
|
+
counters_add-whole-whole: Bütün
|
|
208
|
+
counters_add-whole-first: Bilinen parça
|
|
209
|
+
counters_add-whole-missing: Bilinmeyen parça
|
|
210
|
+
counters_add-whole-second: Konan sayaçlar
|
|
211
|
+
counters_add-claim: Toplam
|
|
212
|
+
counters_add-claim-right: "Çıkarma işlemi {first} sayısını geri veriyor, yani toplam doğru."
|
|
213
|
+
counters_add-claim-wrong: "{back}, {first} sayısına eşit değil, yani toplam yanlış."
|
|
214
|
+
counters_add-squad-whole: Kadro
|
|
215
|
+
counters_add-squad-first: Sahada
|
|
216
|
+
counters_add-squad-missing: Kulübedeki yerler
|
|
217
|
+
counters_add-squad-second: Kulübede
|
|
218
|
+
counters_add-undo-back: Geri alınan
|
|
219
|
+
counters_add-undo-left: Kalan
|
|
220
|
+
counters_add-whole-put: Sonraki yere bir sayaç koy
|
|
221
|
+
counters_add-put: Bir sayaç koy
|
|
222
|
+
counters_add-squad-put: Sıradaki oyuncuyu kulübeye oturt
|
|
223
|
+
counters_add-squad-player: "Sahadaki {x} numaralı oyuncu"
|
|
224
|
+
counters_add-squad-bench: "Kulübedeki {x} numaralı oyuncu"
|
|
225
|
+
counters_add-whole-out: "{x} numaralı sayaç. Son sayacı geri al."
|
|
226
|
+
counters_add-out: Son sayacı geri al
|
|
227
|
+
counters_goal-missing-part: "{calc} işleminin sorduğu parçayı koyun, sonra Kontrol et düğmesine basın."
|
|
228
|
+
counters_goal-missing-part-done: "{line}, çünkü {part} ile {missing}, {whole} eder."
|
|
229
|
+
counters_note-missing-part-more: "{part} ile {put}, {made} eder. Bu, {whole} sayısından büyük."
|
|
230
|
+
counters_note-missing-part-less: "{part} ile {put}, {made} eder. Bu, {whole} sayısından küçük."
|
|
231
|
+
counters_hint-missing-part: "{calc} şunu sorar: {part} ile kaç, {whole} eder? {part} sayısından {whole} sayısına kadar ileri sayın ve söylediğiniz her sayı için bir sayaç koyun."
|
|
232
|
+
counters_bar-first: Birinci parça
|
|
233
|
+
counters_bar-second: İkinci parça
|
|
234
|
+
counters_bar-whole: Bütün
|
|
235
|
+
counters_bar-chocolate-first: Birinci parça
|
|
236
|
+
counters_bar-chocolate-second: İkinci parça
|
|
237
|
+
counters_bar-chocolate-whole: Kareler
|
|
238
|
+
counters_bar-cover-whole: Bütünü kapat
|
|
239
|
+
counters_bar-cover-first: Birinci parçayı kapat
|
|
240
|
+
counters_bar-cover-second: İkinci parçayı kapat
|
|
241
|
+
counters_bar-lift: Kartı kaldır
|
|
242
|
+
counters_goal-bar-for-fact-done: "Bütün {whole}, parçaları {first} ve {second}."
|
|
243
|
+
# waits: counters_bar-split, for "split (bar model)" in the book's i18n/terms/tr.yaml
|
|
244
|
+
# waits: counters_bar-end, for "end (bar model)"
|
|
245
|
+
# waits: counters_goal-bar-for-fact, for "bar model (figure)" and "fact family (calculations)"
|
|
246
|
+
# waits: counters_note-bar-for-fact-longer, for "bar model (figure)"
|
|
247
|
+
# waits: counters_note-bar-for-fact-shorter, for "bar model (figure)"
|
|
248
|
+
counters_bar-use: Sayılar
|
|
249
|
+
counters_bar-use-parts: iki parça
|
|
250
|
+
counters_bar-use-whole: bütün ve bir parça
|
|
251
|
+
counters_bar-third: Üçüncü sayı
|
|
252
|
+
# waits: counters_note-bar-for-fact-right, for "split (bar model)"
|
|
253
|
+
# waits: counters_note-bar-for-fact-left, for "split (bar model)"
|
|
254
|
+
# waits: counters_hint-bar-for-fact-plus, for "end (bar model)" and "split (bar model)"
|
|
255
|
+
# waits: counters_hint-bar-for-fact-minus, for "end (bar model)" and "split (bar model)"
|
|
256
|
+
counters_note-bar-for-two-parts-over: "{greater} ile {less}, {n} sayısından küçük bir sayı eder."
|
|
257
|
+
counters_note-bar-for-two-parts-under: "{greater} ile {less}, {n} sayısından büyük bir sayı eder."
|
|
258
|
+
counters_note-bar-for-two-whole-over: "{less} ile {n}, {greater} sayısından büyük bir sayı eder."
|
|
259
|
+
counters_note-bar-for-two-whole-under: "{less} ile {n}, {greater} sayısından küçük bir sayı eder."
|
|
260
|
+
# waits: counters_goal-bar-for-two, for "fact family (calculations)"
|
|
261
|
+
# waits: counters_goal-bar-for-two-done, for "fact family (calculations)"
|
|
262
|
+
# waits: counters_hint-bar-for-two, for "fact family (calculations)"
|
|
@@ -1,7 +1,7 @@
|
|
|
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, the match scene pairs two rows, the order scene compares numbers,
|
|
3
|
-
//
|
|
4
|
-
// 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, the add
|
|
3
|
+
// scene joins two groups and writes their sum, and the bar scene draws a whole and its parts as a bar model. It
|
|
4
|
+
// checks a page's fields against its scene and says what each link shows when the page opens.
|
|
5
5
|
import { schema } from '@openbooknetwork/kitap';
|
|
6
6
|
import { LOOKS, modeOf, capOf, opening, counts, measuresOf } from './model.js';
|
|
7
7
|
import { GOALS, challengeStart } from './goals.js';
|
|
@@ -9,6 +9,7 @@ import count from './count.mjs';
|
|
|
9
9
|
import match from './match.mjs';
|
|
10
10
|
import order from './order.mjs';
|
|
11
11
|
import add from './add.mjs';
|
|
12
|
+
import bar from './bar.mjs';
|
|
12
13
|
import { numbers } from '../../kit/format.js';
|
|
13
14
|
import { list, challenge, drawn, value } from '../../node.mjs';
|
|
14
15
|
|
|
@@ -98,12 +99,13 @@ function startBonds(spec, lang, id) {
|
|
|
98
99
|
|
|
99
100
|
// Each scene checks its own fields, so the family's schema lets every field through to the scene.
|
|
100
101
|
const Fields = z.object({}).passthrough();
|
|
101
|
-
const SCENES = { bonds: { read: readBonds, start: startBonds }, count, match, order, add };
|
|
102
|
+
const SCENES = { bonds: { read: readBonds, start: startBonds }, count, match, order, add, bar };
|
|
102
103
|
const read = ({ scene, ...fields }, info, ctx) => SCENES[scene].read(fields, info, ctx);
|
|
103
104
|
const start = (spec, lang, id) => SCENES[spec.scene].start(spec, lang, id);
|
|
104
105
|
|
|
105
|
-
// The two colours of the counters, a red and a blue that readers with any colour vision tell apart,
|
|
106
|
-
// for the dark themes.
|
|
107
|
-
const bundle = () => ({ families: { 'counters-red': { color: '#d1453b', color_dark: '#f0776d' }, 'counters-blue': { color: '#2a6bd1', color_dark: '#6fa4f5' }
|
|
106
|
+
// The two colours of the counters, a red and a blue that readers with any colour vision tell apart, and the brown and
|
|
107
|
+
// the shell of the egg box, each with a step for the dark themes.
|
|
108
|
+
const bundle = () => ({ families: { 'counters-red': { color: '#d1453b', color_dark: '#f0776d' }, 'counters-blue': { color: '#2a6bd1', color_dark: '#6fa4f5' },
|
|
109
|
+
'counters-brown': { color: '#a0602c', color_dark: '#d9a273' }, 'counters-shell': { color: '#7f7462', color_dark: '#cdc3b2' } } });
|
|
108
110
|
|
|
109
111
|
export default { id: 'counters', scenes: Object.keys(SCENES), schema: Fields, read, start, bundle };
|
|
@@ -59,3 +59,5 @@ line_hint-jump-minus-one: "Start at {start}. Press Jump left once and say the nu
|
|
|
59
59
|
line_note-jump-way-plus: "{calc} is an addition, so the jumps go to the right from {start}."
|
|
60
60
|
line_note-jump-way-minus: "{calc} is a subtraction, so the jumps go to the left from {start}."
|
|
61
61
|
line_note-jump-few-none: "The point is still on {start}. Make the jumps for {calc} from there."
|
|
62
|
+
line_size: Size of a jump
|
|
63
|
+
line_size-short: Size
|
|
@@ -59,3 +59,6 @@ line_hint-jump-minus-one: "Başlangıçtaki sayıyı söyleyin, sonra her zıpla
|
|
|
59
59
|
line_note-jump-way-plus: Nokta yanlış yöne zıpladı.
|
|
60
60
|
line_note-jump-way-minus: Nokta yanlış yöne zıpladı.
|
|
61
61
|
line_note-jump-few-none: Zıplamalar az.
|
|
62
|
+
# The Turkish words wait for the term "jump (number line)", which the book's i18n/terms/tr.yaml has not sourced yet.
|
|
63
|
+
line_size: Size of a jump
|
|
64
|
+
line_size-short: Size
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The Node half of the line family. Its one scene draws a number line with marks at equal gaps and a point the
|
|
2
2
|
// reader drags or jumps. It checks a page's fields and says what each link shows when the page opens.
|
|
3
3
|
import { schema } from '@openbooknetwork/kitap';
|
|
4
|
-
import { LOOKS, isFree, gapsKey, writtenOf, labelKeep, posOf, gapOn, LABELS_APART, PHONE, STONES_TO, GAPS, isStones, isMark, gapsOf, labelled, cardsOf, middleOf, findsOf, opening, counts, measuresOf, readoutsOf, readingOf } from './model.js';
|
|
4
|
+
import { LOOKS, isFree, gapsKey, writtenOf, backOf, labelKeep, posOf, gapOn, LABELS_APART, PHONE, STONES_TO, GAPS, isStones, isMark, gapsOf, labelled, cardsOf, middleOf, findsOf, opening, counts, measuresOf, readoutsOf, readingOf } from './model.js';
|
|
5
5
|
import { GOALS, challengeStart } from './goals.js';
|
|
6
6
|
import { numbers } from '../../kit/format.js';
|
|
7
7
|
import { words, reading, DASH } from '../../kit/written.js';
|
|
@@ -30,7 +30,10 @@ const Fields = z.object({
|
|
|
30
30
|
second: Int.optional(), // A second point, of another shape and colour.
|
|
31
31
|
flag: z.boolean().default(false), // Each point carries its number in a flag above it.
|
|
32
32
|
reading: z.boolean().default(false), // A line of words says which point's number comes later in the count.
|
|
33
|
-
|
|
33
|
+
// Jump left and Jump right move the point one jump and draw an arc over it: one gap with true, or a size of a jump
|
|
34
|
+
// in gaps, fixed or on a stepper.
|
|
35
|
+
jump: z.union([z.boolean(), Int.min(1), z.object({ stepper: z.tuple([Int, Int]), start: Int.optional() }).strict()]).default(false),
|
|
36
|
+
undo: z.boolean().default(false), // A jump and the same jump back, with the line of each.
|
|
34
37
|
bracket: z.literal(10).optional(), // A bracket from the ten before the point to the ten after it.
|
|
35
38
|
open: z.boolean().default(false), // A tap on a gap opens it under the line, with a mark for every number in it.
|
|
36
39
|
middle: z.union([z.boolean(), z.literal('button')]).default(false), // The middle's long mark, or a button that draws it.
|
|
@@ -50,11 +53,13 @@ function read({ scene, ...fields }, { at }, ctx) {
|
|
|
50
53
|
const pg = check(Fields, fields, at), fail = words => ctx.fail(at, words), step = value(pg.step), est = value(pg.estimate);
|
|
51
54
|
// The book is an unmarked line. An unmarked line labels its ends unless the page says otherwise.
|
|
52
55
|
const marks = pg.look === 'book' ? 'ends' : pg.marks;
|
|
53
|
-
|
|
56
|
+
// A jump of true is one gap, and a number or a stepper gives the size of a jump, which the page then links as size.
|
|
57
|
+
const sized = typeof pg.jump === 'number' || typeof pg.jump === 'object', size = sized ? value(pg.jump) : { n: pg.jump ? 1 : null, ctl: null };
|
|
58
|
+
const spec = { ...pg, scene, marks, labels: pg.labels ?? (marks === 'ends' ? 'ends' : 'all'), step: step.n, stepCtl: step.ctl, estimate: est.n, estimateCtl: est.ctl, sized, size: size.n, sizeCtl: size.ctl };
|
|
54
59
|
const done = () => { const ids = measuresOf(spec); return { data: spec, has: id => ids.includes(id), offers: ids.length ? `one of ${list(ids)}` : 'nothing, a challenge page draws its numbers as it opens' }; };
|
|
55
60
|
// A page that draws its line of cards takes no field of the line, and the browser draws it as the page opens.
|
|
56
61
|
if (pg.draw) {
|
|
57
|
-
for (const f of ['from', 'to', 'step', 'labels', 'blank', 'cards', 'point', 'marks', 'second', 'flag', 'reading', 'jump', 'bracket', 'open', 'middle', 'find', 'estimate', 'challenge', 'start', 'written', 'moved']) if (fields[f] !== undefined) fail(`${f} is drawn with the line on a page with draw, leave it out`);
|
|
62
|
+
for (const f of ['from', 'to', 'step', 'labels', 'blank', 'cards', 'point', 'marks', 'second', 'flag', 'reading', 'jump', 'undo', 'bracket', 'open', 'middle', 'find', 'estimate', 'challenge', 'start', 'written', 'moved']) if (fields[f] !== undefined) fail(`${f} is drawn with the line on a page with draw, leave it out`);
|
|
58
63
|
if (pg.look !== 'line') fail(`look is ${pg.look}, a page with draw shows the line look, leave look out`);
|
|
59
64
|
const outs = readoutsOf(spec);
|
|
60
65
|
for (const id of pg.readout) if (!outs.includes(id)) fail(`readout names "${id}", this page reads out ${list(outs)}`);
|
|
@@ -167,6 +172,8 @@ function read({ scene, ...fields }, { at }, ctx) {
|
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
174
|
}
|
|
175
|
+
if (sized) readSize(pg, spec, fail);
|
|
176
|
+
if (pg.undo && !sized) fail(`undo jumps a size and back, write jump as a size, such as jump: 5`);
|
|
170
177
|
if (pg.open && spec.step === 1) fail('open shows the numbers inside a gap, and a line in ones has none, write a step above 1');
|
|
171
178
|
if (pg.challenge) readChallenge(pg, spec, at, ctx);
|
|
172
179
|
const outs = readoutsOf(spec);
|
|
@@ -174,6 +181,26 @@ function read({ scene, ...fields }, { at }, ctx) {
|
|
|
174
181
|
return done();
|
|
175
182
|
}
|
|
176
183
|
|
|
184
|
+
// A jump of a size takes a marked line in the line look, and fits it. An undo page jumps from its start and back,
|
|
185
|
+
// writing both lines, so it takes start, a size and written: true, and none of the fields that move or read the point
|
|
186
|
+
// another way.
|
|
187
|
+
function readSize(pg, spec, fail) {
|
|
188
|
+
const n = gapsOf(spec), { size, sizeCtl: c } = spec;
|
|
189
|
+
if (spec.look !== 'line' || isFree(spec)) fail(`jump has a size, which takes a marked line in the line look, write jump: true`);
|
|
190
|
+
if (pg.challenge) fail('jump has a size, and a challenge jumps one gap at a time, write jump: true');
|
|
191
|
+
if (c && (c.lo < 1 || c.lo >= c.hi || size < c.lo || size > c.hi)) fail(`jump.stepper is [${c.lo}, ${c.hi}] with start ${size}, write [low, high] from 1 with low under high and a start between them`);
|
|
192
|
+
else if ((c?.hi ?? size) > n) fail(`jump reaches a size of ${c?.hi ?? size}, and the line has ${n} gaps, write a size of ${n} at most`);
|
|
193
|
+
else if (pg.start !== undefined && isMark(spec, pg.start) && (pg.start - spec.from) / spec.step - size < 0 && (pg.start - spec.from) / spec.step + size > n) fail(`jump is ${size}, and a jump of ${size} either way from the start ${pg.start} leaves the line, write a smaller size or another start`);
|
|
194
|
+
if (!pg.undo) return;
|
|
195
|
+
// The start of an undo page moves, and from the middle of the line a size over half its gaps rests both buttons.
|
|
196
|
+
if ((c?.hi ?? size) > n / 2) fail(`jump reaches a size of ${c?.hi ?? size}, and from the middle of the line of ${n} gaps a jump over ${n / 2} leaves it either way, write a size of ${Math.floor(n / 2)} at most`);
|
|
197
|
+
if (pg.start === undefined) fail('undo jumps from the start and back to it, write start');
|
|
198
|
+
if (pg.written !== true) fail('undo writes the line of each jump, write written: true');
|
|
199
|
+
for (const f of ['point', 'second', 'bracket', 'find', 'estimate', 'moved']) if (pg[f] !== undefined) fail(`${f} belongs to pages without undo, an undo page takes start, jump, written and readout`);
|
|
200
|
+
for (const f of ['flag', 'open', 'reading']) if (pg[f]) fail(`${f} belongs to pages without undo, an undo page takes start, jump, written and readout`);
|
|
201
|
+
if (spec.stepCtl) fail('undo takes a line of one step, write step as a number');
|
|
202
|
+
}
|
|
203
|
+
|
|
177
204
|
// A challenge page names its goal and the range it draws from. The reader finds the target with the drag and the
|
|
178
205
|
// jumps, so the page shows no number that gives it away. Every target it can draw must be open as the page starts.
|
|
179
206
|
function readChallenge(pg, spec, at, ctx) {
|
|
@@ -215,7 +242,9 @@ function start(spec, lang, id) {
|
|
|
215
242
|
if (!measuresOf(spec).includes(id)) return null;
|
|
216
243
|
const s = opening(spec), int = numbers(lang).int;
|
|
217
244
|
if (id === 'gaps') return string(lang, `line_${gapsKey(s)}`);
|
|
218
|
-
|
|
245
|
+
const say = (w, wording) => !w ? DASH : wording ? reading(w, int, (key, vars) => string(lang, `hesap_${key}`, vars)) : words(w, int);
|
|
246
|
+
if (id === 'written' || id === 'reading' && spec.written) return say(writtenOf(spec, s), id === 'reading');
|
|
247
|
+
if (id === 'written-back' || id === 'reading-back') return say(backOf(spec, s), id === 'reading-back');
|
|
219
248
|
if (id === 'reading') { const r = readingOf(spec, s); return string(lang, `line_${r.key}`, { a: int(r.a), b: int(r.b) }); }
|
|
220
249
|
const v = counts(spec, s)[id];
|
|
221
250
|
return v === null ? DASH : int(v);
|