@openbooknetwork/hesap 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/package.json +1 -1
  2. package/src/client.css +165 -0
  3. package/src/families/counters/add-figures.js +85 -0
  4. package/src/families/counters/add-goals.js +82 -0
  5. package/src/families/counters/add-model.js +82 -0
  6. package/src/families/counters/add.js +442 -0
  7. package/src/families/counters/add.mjs +102 -0
  8. package/src/families/counters/bonds.js +5 -5
  9. package/src/families/counters/client.css +37 -0
  10. package/src/families/counters/client.js +2 -1
  11. package/src/families/counters/count.js +4 -5
  12. package/src/families/counters/counter.js +14 -0
  13. package/src/families/counters/goals.js +1 -9
  14. package/src/families/counters/i18n/en.yaml +89 -45
  15. package/src/families/counters/i18n/tr.yaml +56 -12
  16. package/src/families/counters/index.mjs +5 -3
  17. package/src/families/counters/match-model.js +10 -1
  18. package/src/families/counters/match.js +31 -11
  19. package/src/families/counters/match.mjs +7 -1
  20. package/src/families/line/client.css +118 -0
  21. package/src/families/line/client.js +12 -0
  22. package/src/families/line/figures.js +143 -0
  23. package/src/families/line/goals.js +168 -0
  24. package/src/families/line/i18n/en.yaml +61 -0
  25. package/src/families/line/i18n/tr.yaml +61 -0
  26. package/src/families/line/index.mjs +227 -0
  27. package/src/families/line/lens.js +49 -0
  28. package/src/families/line/line.js +624 -0
  29. package/src/families/line/model.js +219 -0
  30. package/src/families.mjs +2 -1
  31. package/src/i18n/en.yaml +158 -46
  32. package/src/i18n/tr.yaml +124 -12
  33. package/src/kit/i18n/en.yaml +8 -1
  34. package/src/kit/i18n/tr.yaml +7 -0
  35. package/src/kit/kit.css +9 -0
  36. package/src/kit/panel.js +2 -0
  37. package/src/kit/random.js +9 -0
  38. package/src/kit/written.js +70 -0
  39. package/src/node.mjs +3 -1
@@ -0,0 +1,227 @@
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
+ // reader drags or jumps. It checks a page's fields and says what each link shows when the page opens.
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';
5
+ import { GOALS, challengeStart } from './goals.js';
6
+ import { numbers } from '../../kit/format.js';
7
+ import { words, reading, DASH } from '../../kit/written.js';
8
+ import { list, string, value, challenge, drawn } from '../../node.mjs';
9
+
10
+ const { z, check } = schema;
11
+ // The longest line a page with moved marks takes: on a 390px phone a longer one leaves no room for a mark off its
12
+ // place a third of a gap with its label 10px from the next.
13
+ const MOVED_TO = 12;
14
+ const Int = z.number().int();
15
+ const Fields = z.object({
16
+ look: z.enum(LOOKS).default('line'), // The number line, or the frog's stones for the opening pages.
17
+ from: Int.min(0).default(0), // The number at the left end.
18
+ to: Int.optional(), // The number at the right end, at the page's own step.
19
+ // The number between two marks next to each other, or a row of steps the reader picks from.
20
+ step: z.union([Int.min(1), z.object({ segment: z.array(Int.min(1)).min(2), start: Int.optional() }).strict()]).default(1),
21
+ marks: z.enum(['all', 'ends']).default('all'), // A mark at every step, or at the two ends alone for an unmarked line.
22
+ // Every mark carries its number, or the two ends alone, or the multiples of a number, or the numbers of a list.
23
+ labels: z.union([z.enum(['all', 'ends']), Int.min(1), z.array(Int)]).optional(),
24
+ blank: z.array(Int).default([]), // Marks that carry an empty label box.
25
+ cards: z.union([z.literal(true), z.array(Int)]).optional(), // Label cards the reader drags onto the blank marks.
26
+ point: z.union([Int, z.literal(false)]).optional(), // The mark the point starts on, the left end when left out, or no point.
27
+ start: Int.optional(), // The start of the jumps, a ring the reader drags, which the point takes when point is left out.
28
+ // The written line of the jumps under the line, or of the difference of the start and the second point.
29
+ written: z.union([z.literal(true), z.literal('difference')]).optional(),
30
+ second: Int.optional(), // A second point, of another shape and colour.
31
+ flag: z.boolean().default(false), // Each point carries its number in a flag above it.
32
+ reading: z.boolean().default(false), // A line of words says which point's number comes later in the count.
33
+ jump: z.boolean().default(false), // Jump left and Jump right move the point one gap and draw an arc over it.
34
+ bracket: z.literal(10).optional(), // A bracket from the ten before the point to the ten after it.
35
+ open: z.boolean().default(false), // A tap on a gap opens it under the line, with a mark for every number in it.
36
+ middle: z.union([z.boolean(), z.literal('button')]).default(false), // The middle's long mark, or a button that draws it.
37
+ find: z.union([Int, z.array(Int).min(1)]).optional(), // The number to place, or a list of them, with Show and Next.
38
+ // The reader's estimate of the number at the point, on a stepper or a slider, with its estimate mark.
39
+ estimate: z.union([z.object({ stepper: z.tuple([Int, Int]), start: Int.optional() }).strict(), z.object({ slider: z.tuple([Int, Int]), start: Int.optional() }).strict()]).optional(),
40
+ // Marks that start off their places, each by a part of a gap, for the reader to drag back.
41
+ moved: z.array(z.object({ mark: Int, by: z.number() }).strict()).min(1).optional(),
42
+ draw: z.boolean().default(false), // A line of label cards drawn at random, with New line to draw another.
43
+ readout: z.array(z.string()).default([]),
44
+ // A challenge names a goal of goals.js and the ranges it draws from.
45
+ challenge: z.object({ goal: z.string(), target: z.tuple([Int, Int]).optional(), step: z.array(Int).optional(), from: z.tuple([Int, Int]).optional(), to: z.tuple([Int, Int]).optional(),
46
+ start: z.tuple([Int, Int]).optional(), add: z.tuple([Int, Int]).optional(), subtract: z.tuple([Int, Int]).optional() }).strict().optional(),
47
+ }).strict();
48
+
49
+ function read({ scene, ...fields }, { at }, ctx) {
50
+ const pg = check(Fields, fields, at), fail = words => ctx.fail(at, words), step = value(pg.step), est = value(pg.estimate);
51
+ // The book is an unmarked line. An unmarked line labels its ends unless the page says otherwise.
52
+ const marks = pg.look === 'book' ? 'ends' : pg.marks;
53
+ const spec = { ...pg, scene, marks, labels: pg.labels ?? (marks === 'ends' ? 'ends' : 'all'), step: step.n, stepCtl: step.ctl, estimate: est.n, estimateCtl: est.ctl };
54
+ 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
+ // A page that draws its line of cards takes no field of the line, and the browser draws it as the page opens.
56
+ 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`);
58
+ if (pg.look !== 'line') fail(`look is ${pg.look}, a page with draw shows the line look, leave look out`);
59
+ const outs = readoutsOf(spec);
60
+ for (const id of pg.readout) if (!outs.includes(id)) fail(`readout names "${id}", this page reads out ${list(outs)}`);
61
+ return done();
62
+ }
63
+ // A goal that draws its line takes no line from the page.
64
+ if (pg.challenge && GOALS[pg.challenge.goal]?.draws) { readDrawn(fields, pg, spec, at, ctx); return done(); }
65
+ if (spec.to === undefined) { fail('to is missing, write the number at the right end, such as 20'); return done(); }
66
+ if (step.ctl) {
67
+ const items = step.ctl.items;
68
+ if (items.some((v, i) => i && v <= items[i - 1])) fail(`step.segment is [${items}], write different steps from the least to the greatest, such as [1, 2, 5, 10]`);
69
+ if (!items.includes(spec.step)) fail(`step.start is ${spec.step}, write one of the steps ${list(items)}`);
70
+ if (spec.labels !== 'all') fail('labels is set on a page whose reader picks the step, and such a page labels every mark, leave labels out');
71
+ for (const f of ['blank', 'cards', 'bracket']) if (fields[f] !== undefined) fail(`${f} belongs to a line of one step, write step as a number`);
72
+ }
73
+ if (spec.to <= spec.from) return fail(`to is ${spec.to}, write a number above the left end ${spec.from}`), done();
74
+ if (!Number.isInteger(gapsOf(spec))) return fail(`to is ${spec.to}, and to minus from is ${spec.to - spec.from}, write a right end that is a whole number of steps of ${spec.step} from ${spec.from}`), done();
75
+ if (!isFree(spec) && gapsOf(spec) > GAPS) fail(`to is ${spec.to}, which gives ${gapsOf(spec)} gaps, and a marked line holds at most ${GAPS}`);
76
+ if (Number.isInteger(spec.labels) && spec.labels % spec.step) fail(`labels is ${spec.labels}, write a multiple of the step ${spec.step}, so each labelled number is a mark of the line`);
77
+ if (Array.isArray(spec.labels)) for (const n of spec.labels) if (!isMark(spec, n)) fail(`labels lists ${n}, which is no mark of the line from ${spec.from} to ${spec.to} in steps of ${spec.step}`);
78
+ for (const n of pg.blank) if (!isMark(spec, n) || labelled(spec, n)) fail(`blank lists ${n}, write marks of the line that carry no label`);
79
+ if (pg.cards !== undefined) {
80
+ const cards = cardsOf(spec);
81
+ if (!pg.blank.length) fail('cards go with blank, write the marks whose labels the cards fill');
82
+ if (new Set(cards).size !== cards.length) fail(`cards is [${cards}], write each number once`);
83
+ for (const n of pg.blank) if (!cards.includes(n)) fail(`cards leaves out ${n}, write a card for every blank mark`);
84
+ }
85
+ if (isStones(spec)) {
86
+ if (spec.to > STONES_TO) fail(`to is ${spec.to}, and the ${spec.look} look holds at most ${STONES_TO} stones`);
87
+ for (const f of ['from', 'step', 'labels', 'second', 'blank', 'cards', 'bracket', 'open', 'middle', 'find', 'challenge']) if (fields[f] !== undefined) fail(`${f} belongs to the line look, the ${spec.look} look takes to, point, jump and readout`);
88
+ for (const f of ['flag', 'reading']) if (pg[f]) fail(`${f} belongs to the line look, the ${spec.look} look takes to, point, jump and readout`);
89
+ if (pg.point === false) fail(`point is false, and the ${spec.look} look shows the frog as the point, write a number`);
90
+ }
91
+ for (const f of ['point', 'second']) {
92
+ const n = pg[f];
93
+ if (n !== undefined && n !== false && !isMark(spec, n)) fail(`${f} is ${n}, write a number on a mark from ${spec.from} to ${spec.to}`);
94
+ }
95
+ if (pg.point === false) for (const f of ['jump', 'second', 'bracket', 'flag', 'reading']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} moves or reads the point, and point is false, write the point's start or leave ${f} out`);
96
+ if (pg.start !== undefined) {
97
+ if (!pg.jump) fail('start is the start of the jumps, write jump: true');
98
+ if (spec.look !== 'line' || isFree(spec)) fail(`start takes a marked line in the line look, this page has look ${spec.look}${isFree(spec) ? ' and marks: ends' : ''}`);
99
+ if (!isMark(spec, pg.start)) fail(`start is ${pg.start}, write a number on a mark from ${spec.from} to ${spec.to}`);
100
+ if (pg.point === false) fail(`start carries the point, write the point's place or leave point out`);
101
+ if (pg.challenge) fail(`start is drawn by challenge.goal ${pg.challenge.goal}, leave it out`);
102
+ }
103
+ if (pg.written !== undefined) {
104
+ if (!pg.jump) fail('written writes the jumps, write jump: true');
105
+ if (pg.reading) fail('reading is the written line in words on a page with written, leave the field reading out');
106
+ if (pg.written === 'difference' && pg.second === undefined) fail('written: difference writes the second point minus the start, write second as well');
107
+ // The page counts on from the start to the second point, so the second point is the greater number.
108
+ else if (pg.written === 'difference' && pg.start !== undefined && pg.second <= pg.start) fail(`second is ${pg.second}, at or left of the start ${pg.start}, and the page counts on from the start, write a second point greater than the start, such as ${Math.min(spec.to, pg.start + 5)}`);
109
+ }
110
+ if (pg.second !== undefined && !pg.flag) fail('second goes with flag, write flag: true so each point shows its number');
111
+ if (pg.reading && pg.second === undefined) fail('reading compares two points, write second as well');
112
+ if (pg.bracket) {
113
+ if (10 % spec.step || spec.from % 10 || spec.to % 10) fail(`bracket reaches from a ten to a ten, which are marks of the line when from and to are tens and the step is 1, 2, 5 or 10, this line runs from ${spec.from} to ${spec.to} in steps of ${spec.step}`);
114
+ else if (!Array.from({ length: (spec.to - spec.from) / 10 + 1 }, (_, i) => spec.from + 10 * i).every(n => labelled(spec, n))) fail('bracket lights the labels of two tens, label every ten, such as with labels: 10');
115
+ }
116
+ if (isFree(spec)) {
117
+ if (spec.labels !== 'ends') fail('labels of an unmarked line are its ends, which carry the only marks, leave labels out');
118
+ for (const f of ['step', 'second', 'jump', 'bracket', 'open', 'blank', 'cards']) if (fields[f] !== undefined) fail(`${f} takes a marked line, and marks is ends, leave ${f} out or write marks: all`);
119
+ if (isStones(spec) || spec.look === 'street') fail(`marks is ends, and the ${spec.look} look has a mark at every step, leave marks out`);
120
+ }
121
+ if (spec.look === 'book') for (const f of ['marks', 'labels', 'step', 'second', 'flag', 'reading', 'jump', 'bracket', 'open', 'blank', 'cards', 'middle', 'estimate', 'challenge']) if (fields[f] !== undefined) fail(`${f} belongs to the line look, the book look takes from, to, point, find and readout`);
122
+ if (est.ctl) {
123
+ const { lo, hi } = est.ctl;
124
+ if (!isFree(spec)) fail('estimate takes an unmarked line, write marks: ends');
125
+ if (lo > hi || spec.estimate < lo || spec.estimate > hi) fail(`estimate has the range [${lo}, ${hi}] and starts at ${spec.estimate}, write [low, high] and a start between them`);
126
+ else if (lo < spec.from || hi > spec.to) fail(`estimate reaches [${lo}, ${hi}], write a range inside the line from ${spec.from} to ${spec.to}`);
127
+ for (const f of ['jump', 'find']) if (fields[f] !== undefined) fail(`${f} belongs to pages without an estimate, an estimate page leaves the point where it is`);
128
+ if (pg.point === false) fail(`estimate is of the number at the point, write the point's place`);
129
+ }
130
+ if (spec.look === 'street') {
131
+ if (!Array.isArray(spec.labels)) fail('labels of the street look are the door numbers it shows, write them as a list, such as [1, 20, 50, 60]');
132
+ for (const f of ['step', 'second', 'jump', 'bracket', 'open', 'blank', 'cards', 'middle', 'challenge']) if (fields[f] !== undefined) fail(`${f} belongs to the line look, the street look takes from, to, labels, point, find and readout`);
133
+ for (const f of ['flag', 'reading']) if (pg[f]) fail(`${f} belongs to the line look, the street look takes from, to, labels, point, find and readout`);
134
+ }
135
+ if (pg.middle) {
136
+ if (gapsOf(spec) % 2) fail(`middle is set, and the line from ${spec.from} to ${spec.to} has ${gapsOf(spec)} gaps, so its middle is no mark, write ends an even number of steps apart`);
137
+ if (spec.look !== 'line') fail(`middle belongs to the line look, leave it out of the ${spec.look} look`);
138
+ if (labelled(spec, middleOf(spec))) fail(`middle draws the label of ${middleOf(spec)}, which labels already gives, leave middle out or the label out`);
139
+ }
140
+ if (pg.find !== undefined) {
141
+ for (const n of findsOf(spec)) {
142
+ if (!isMark(spec, n)) fail(`find has ${n}, write numbers on marks from ${spec.from} to ${spec.to}`);
143
+ else if (labelled(spec, n) || (pg.middle && n === middleOf(spec))) fail(`find has ${n}, which carries a label, write numbers whose marks have none`);
144
+ }
145
+ for (const f of ['second', 'flag', 'reading']) if (pg[f] !== undefined && pg[f] !== false) fail(`${f} belongs to pages without find, a find page shows the number at the point once the reader presses Show`);
146
+ if (pg.challenge) fail('find belongs to pages without a challenge, leave it out');
147
+ }
148
+ if (pg.moved) {
149
+ if (spec.look !== 'line' || spec.from !== 0 || spec.stepCtl || spec.step !== 1 || spec.labels !== 'all' || spec.to < 4 || spec.to > MOVED_TO) fail(`moved takes the line look from 0 in steps of 1 with every mark labelled and to from 4 to ${MOVED_TO}, so a mark off its place keeps its label ${LABELS_APART}px from the next on a phone, this page has look ${spec.look}, from ${spec.from}, to ${spec.to} and step ${spec.step}`);
150
+ for (const f of ['second', 'blank', 'cards', 'bracket', 'middle', 'find', 'estimate', 'challenge', 'marks']) if (fields[f] !== undefined) fail(`${f} belongs to pages without moved, a moved page takes point, jump and readout`);
151
+ for (const f of ['flag', 'reading', 'open']) if (pg[f]) fail(`${f} belongs to pages without moved, a moved page takes point, jump and readout`);
152
+ const marks = pg.moved.map(m => m.mark).sort((a, b) => a - b);
153
+ for (const m of pg.moved) {
154
+ if (!Number.isInteger(m.mark) || m.mark <= spec.from || m.mark >= spec.to) fail(`moved has the mark ${m.mark}, write a mark between the ends ${spec.from} and ${spec.to}`);
155
+ if (Math.abs(m.by) < 0.3 || Math.abs(m.by) > 0.6) fail(`moved has ${m.mark} by ${m.by}, write by from 0.3 to 0.6 in size, so the page opens with a gap that looks wrong`);
156
+ }
157
+ if (marks.some((m, i) => i && m - marks[i - 1] < 2)) fail(`moved lists the marks ${marks.join(', ')}, write marks with no two next to each other or the same`);
158
+ // On a 390px phone the labels of two marks next to each other stand at least LABELS_APART pixels apart as the page opens.
159
+ else if (spec.to >= 4 && spec.to <= MOVED_TO) {
160
+ const s = opening(spec), keep = labelKeep(spec, PHONE), gap = gapOn(PHONE, gapsOf(spec), false);
161
+ for (let k = 0; k < gapsOf(spec); k++) {
162
+ const d = posOf(s, k + 1) - posOf(s, k);
163
+ // The largest by that keeps them apart, and when that is below the least by of 0.3, no by fits this mark.
164
+ const most = Math.floor((1 - keep(k, k + 1)) * 100) / 100;
165
+ const way = most >= 0.3 ? `write a by that leaves them ${LABELS_APART}px apart, such as one of at most ${most} in size` : `no by from 0.3 to 0.6 leaves them ${LABELS_APART}px apart, move another mark or shorten the line`;
166
+ if (d < keep(k, k + 1) - 1e-9) fail(`moved puts the labels of ${k} and ${k + 1} about ${Math.max(0, Math.round((d - keep(k, k + 1)) * gap + LABELS_APART))}px apart on a 390px phone, where they would read as one number, ${way}`);
167
+ }
168
+ }
169
+ }
170
+ 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
+ if (pg.challenge) readChallenge(pg, spec, at, ctx);
172
+ const outs = readoutsOf(spec);
173
+ for (const id of pg.readout) if (!outs.includes(id)) fail(`readout names "${id}", this page reads out ${list(outs) || 'nothing'}`);
174
+ return done();
175
+ }
176
+
177
+ // A challenge page names its goal and the range it draws from. The reader finds the target with the drag and the
178
+ // jumps, so the page shows no number that gives it away. Every target it can draw must be open as the page starts.
179
+ function readChallenge(pg, spec, at, ctx) {
180
+ const c = pg.challenge, goal = goalOf(c, at, ctx);
181
+ if (!goal) return;
182
+ const fail = words => ctx.fail(at, words);
183
+ if (pg.look !== 'line') fail(`look is ${pg.look}, a challenge page shows the line look, leave look out`);
184
+ if (pg.readout.length) fail(`readout names ${list(pg.readout)}, and a challenge page shows no readouts, which would give the answer away, leave readout out`);
185
+ for (const f of ['flag', 'reading']) if (pg[f]) fail(`${f} would give the answer away, a challenge page shows the point's number once the goal holds, leave ${f} out`);
186
+ for (const f of ['second', 'blank', 'cards', 'bracket']) if (f === 'blank' ? pg.blank.length : pg[f] !== undefined) fail(`${f} belongs to pages without a challenge, leave it out`);
187
+ if (pg.point === false) fail('point is false, and the reader places the point, write its start or leave point out');
188
+ if (spec.stepCtl) fail(`step is a segment, write the step of the challenge's line as a number`);
189
+ // jump-to asks for a calculation whose answer every label may show, as the reader counts the jumps.
190
+ if (spec.labels === 'all' && !goal.labels) fail(`labels is all, so every target would carry its label, write the labels of the line, such as labels: 10`);
191
+ const problem = goal.problem(c, spec);
192
+ if (problem) return fail(`challenge.${problem}`);
193
+ drawn(goal, c, spec, { at, ctx, starts: (s, t) => challengeStart(s, t) });
194
+ }
195
+ // A goal that draws its line takes the challenge alone, with no field of the line.
196
+ function readDrawn(fields, pg, spec, at, ctx) {
197
+ const c = pg.challenge, goal = goalOf(c, at, ctx);
198
+ if (!goal) return;
199
+ for (const f of Object.keys(fields)) if (f !== 'challenge' && !(goal.takes ?? []).includes(f)) ctx.fail(at, `${f} is drawn by challenge.goal ${c.goal}, which draws the line, leave it out`);
200
+ if (fields.middle !== undefined && fields.middle !== 'button') ctx.fail(at, `middle is ${JSON.stringify(fields.middle)}, write middle: button, so the reader draws the middle of the line the goal draws`);
201
+ const problem = goal.problem(c, spec);
202
+ if (problem) return ctx.fail(at, `challenge.${problem}`);
203
+ if (!goal.lines(c).length) return ctx.fail(at, `challenge.goal ${c.goal} draws no line, as ${goal.noLine(c)}, widen the ranges`);
204
+ drawn(goal, c, spec, { at, ctx, starts: (s, t) => challengeStart(s, t) });
205
+ }
206
+ function goalOf(c, at, ctx) {
207
+ const goal = challenge(c, GOALS, { scene: 'line', at, ctx });
208
+ if (goal) for (const f of Object.keys(c)) if (f !== 'goal' && !goal.fields.includes(f)) ctx.fail(at, `challenge.${f} belongs to another goal, ${c.goal} draws from ${list(goal.fields)}`);
209
+ return goal;
210
+ }
211
+
212
+ // A link shows a number or the line of words as the page opens. The ten before and the ten after read a dash
213
+ // while the point is on a ten.
214
+ function start(spec, lang, id) {
215
+ if (!measuresOf(spec).includes(id)) return null;
216
+ const s = opening(spec), int = numbers(lang).int;
217
+ if (id === 'gaps') return string(lang, `line_${gapsKey(s)}`);
218
+ if (id === 'written' || id === 'reading' && spec.written) { const w = writtenOf(spec, s); return id === 'written' ? words(w, int) : reading(w, int, (key, vars) => string(lang, `hesap_${key}`, vars)); }
219
+ if (id === 'reading') { const r = readingOf(spec, s); return string(lang, `line_${r.key}`, { a: int(r.a), b: int(r.b) }); }
220
+ const v = counts(spec, s)[id];
221
+ return v === null ? DASH : int(v);
222
+ }
223
+
224
+ // The two points: a red round one and a blue square one, each with a step for the dark themes.
225
+ const bundle = () => ({ families: { 'line-point': { color: '#d1453b', color_dark: '#f0776d' }, 'line-second': { color: '#2a6bd1', color_dark: '#6fa4f5' } } });
226
+
227
+ export default { id: 'line', scenes: ['line'], schema: z.object({}).passthrough(), read, start, bundle };
@@ -0,0 +1,49 @@
1
+ // The lens: a window above the point that shows about a dozen gaps of the line around it at full size, for a line whose
2
+ // gaps are too narrow to tell apart on the stage. It draws the marks, the labels and the arcs the line has there.
3
+ import { svg as el } from '../../kit/dom.js';
4
+ import { arc, house, plaque } from './figures.js';
5
+
6
+ const GAP = 21, SPAN = 16, H = 84, LINE = -56; // The lens's gap, its width in gaps, its height and the height of its line.
7
+ export const LENS_H = H + 8; // The room the lens and its tip take above the point.
8
+ let made = 0;
9
+
10
+ // lens makes the window. Its group stands with the middle of its foot at 0, 0. draw shows the line around the place
11
+ // c, counted in marks, on a line of n gaps. label gives the words of mark k, or null for a short mark, and arcs are
12
+ // the jumps of the point.
13
+ export function lens() {
14
+ const w = GAP * SPAN, id = `line-lens-${++made}`;
15
+ const inner = el('g', { 'clip-path': `url(#${id})` }), tip = el('path', { class: 'line-lens-tip', d: 'M -8 -1 L 0 8 L 8 -1 Z' });
16
+ const g = el('g', { class: 'line-lens', 'aria-hidden': 'true', display: 'none' }, [
17
+ el('defs', {}, [el('clipPath', { id }, [el('rect', { x: -w / 2, y: -H, width: w, height: H, rx: 10 })])]),
18
+ el('rect', { class: 'line-lens-box', x: -w / 2, y: -H, width: w, height: H, rx: 10 }), tip, inner,
19
+ ]);
20
+ return {
21
+ el: g, w,
22
+ show(on) { g.setAttribute('display', on ? 'inline' : 'none'); },
23
+ // at moves the lens so that it stays on the stage, with its tip over the point at x.
24
+ at(x, y, lo, hi) { const cx = Math.max(lo + w / 2, Math.min(hi - w / 2, x)); g.setAttribute('transform', `translate(${cx} ${y})`); tip.setAttribute('transform', `translate(${x - cx} 0)`); },
25
+ // On the street look the lens shows the houses with their door numbers in place of the marks.
26
+ draw(c, n, label, arcs, street = false) {
27
+ const x = k => (k - c) * GAP, lo = Math.max(0, Math.floor(c - SPAN / 2 - 1)), hi = Math.min(n, Math.ceil(c + SPAN / 2 + 1)), kids = [];
28
+ if (street) {
29
+ kids.push(el('rect', { class: 'line-road', x: Math.max(-w / 2, x(0) - GAP / 2), y: LINE + 14, width: Math.min(w / 2, x(n) + GAP / 2) - Math.max(-w / 2, x(0) - GAP / 2), height: 8 }));
30
+ for (let k = lo; k <= hi; k++) { kids.push(house(x(k), LINE + 14, GAP * 0.8, 22)); const words = label(k); if (words !== null) kids.push(plaque(x(k), LINE - 16, words, 11)); }
31
+ kids.push(el('path', { class: 'line-dot line-c-point', d: `M -6 ${LINE + 26} L 0 ${LINE + 18} L 6 ${LINE + 26} Z` }));
32
+ return inner.replaceChildren(...kids);
33
+ }
34
+ kids.push(el('line', { class: 'line-axis', x1: Math.max(-w / 2, x(0)), x2: Math.min(w / 2, x(n)), y1: LINE, y2: LINE }));
35
+ for (let k = lo; k <= hi; k++) {
36
+ const words = label(k), long = words !== null;
37
+ kids.push(el('line', { class: 'line-mark', x1: x(k), x2: x(k), y1: LINE - (long ? 9 : 5), y2: LINE + (long ? 9 : 5) }));
38
+ if (long) kids.push(el('text', { class: 'line-label', x: x(k), y: LINE + 18, 'font-size': 12 }, [words]));
39
+ }
40
+ for (const a of arcs) if (Math.max(a.from, a.to) >= lo && Math.min(a.from, a.to) <= hi) {
41
+ // A jump to the left dips under the labels, with its head clear of them.
42
+ const part = arc(x(a.from), x(a.to), a.dir < 0 ? LINE + 33 : LINE - 4, a.dir < 0 ? 6 : 8, a.dir < 0);
43
+ kids.push(part.path, part.head);
44
+ }
45
+ kids.push(el('circle', { class: 'line-dot line-c-point', r: 7, cy: LINE }));
46
+ inner.replaceChildren(...kids);
47
+ },
48
+ };
49
+ }