@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
package/src/i18n/tr.yaml CHANGED
@@ -9,10 +9,17 @@ hesap_start: Başlat
9
9
  hesap_time: Zaman
10
10
  hesap_reset: Baştan başla
11
11
  hesap_undo: Geri al
12
+ hesap_check: Kontrol et
12
13
  hesap_hint: İpucu
13
14
  hesap_another: Bir tane daha
14
15
  hesap_solved: Çözüldü
15
16
  hesap_not-yet: Henüz çözülmedi.
17
+ hesap_written: İşlem
18
+ hesap_written-reading: Sözle
19
+ hesap_written-plus: "{a} artı {b} eşittir {c}"
20
+ hesap_written-minus: "{a} eksi {b} eşittir {c}"
21
+ hesap_written-plus-open: "{a} artı {b}"
22
+ hesap_written-minus-open: "{a} eksi {b}"
16
23
  counters_lead: "Sayaçlara dokunun, onları sürükleyin ve sayıların onları nasıl izlediğine bakın."
17
24
  counters_whole: Bütün
18
25
  counters_first: Birinci parça
@@ -29,8 +36,8 @@ counters_one-found: Bulunan ikililer
29
36
  counters_one-ways: Tüm ikililer
30
37
  counters_two-first: Kırmızı
31
38
  counters_two-second: Mavi
32
- counters_cup-first: Görünen parça
33
- counters_cup-second: Gizli parça
39
+ counters_cup-first: Bilinen parça
40
+ counters_cup-second: Bilinmeyen parça
34
41
  counters_cup-added: Eklenen mavi
35
42
  counters_pins-first: Ayakta
36
43
  counters_pins-empty: Devrilen
@@ -42,7 +49,6 @@ counters_fill: İkinci çerçeveyi doldur
42
49
  counters_unfill: İkinci çerçeveyi boşalt
43
50
  counters_lift: Bardağı kaldır
44
51
  counters_lower: Bardağı geri koy
45
- counters_check: Kontrol et
46
52
  counters_blue: Mavi sayaçlar
47
53
  counters_tray: Tepsi
48
54
  counters_pile: Yığın
@@ -58,7 +64,7 @@ counters_list-splits: "{x} sayısının ayrımları"
58
64
  counters_list-pairs: "{x} yapan ikililer"
59
65
  counters_goal-make-whole: "Kırmızı tepside {part} sayaç var. Çerçeve {whole} sayaç tutacak biçimde mavi sayaçları ayarlayın, sonra Kontrol et düğmesine basın."
60
66
  counters_goal-make-whole-two: "Kırmızı tepside {part} sayaç var. İki çerçeve {whole} sayaç tutacak biçimde mavi sayaçları ayarlayın, sonra Kontrol et düğmesine basın."
61
- counters_goal-hidden-part: "Bütün {whole}, görünen parça {part}. Bardağın altındaki parçayı tepside kurun, sonra bardağı kaldırın."
67
+ counters_goal-hidden-part: "Bütün {whole}, bilinen parça {part}. Bardağın altındaki parçayı tepside kurun, sonra bardağı kaldırın."
62
68
  counters_note-short: Bazı hücreler hâlâ boş.
63
69
  counters_note-over: Bazı sayaçlara hücre kalmadı.
64
70
  counters_note-more: Tepside bardaktakinden çok sayaç var.
@@ -102,8 +108,8 @@ counters_set-up: Lobutları diz
102
108
  counters_ctl-top: Üst sıra
103
109
  counters_ctl-bottom: Alt sıra
104
110
  counters_ctl-spread: Aralık
105
- counters_match-unpaired: Eşi olmayan
106
- counters_match-pairs: Çiftler
111
+ counters_match-unpaired: Eşleşmeyen
112
+ counters_match-pairs: Eşleşenler
107
113
  counters_word-same: Aynı
108
114
  counters_tag-more: daha çok
109
115
  counters_tag-fewer: daha az
@@ -148,22 +154,128 @@ counters_verdict-true: "doğru"
148
154
  counters_verdict-false: "yanlış"
149
155
  counters_sign: İşaret
150
156
  counters_match-reading: Sözle
151
- counters_match-verdict: Satır
157
+ counters_match-verdict: İfade
152
158
  counters_match-scoreboard-top: Ev sahibi
153
159
  counters_match-scoreboard-bottom: Deplasman
154
160
  counters_score-top: Ev sahibi golü
155
161
  counters_score-bottom: Deplasman golü
156
162
  counters_new-match: Yeni maç
157
163
  counters_goal-same-rows: "Üst sırayı alt sırayla aynı yapın, sonra Kontrol et düğmesine basın."
158
- counters_note-same-rows-top: Üst sıradaki bazı sayaçların eşi yok.
159
- counters_note-same-rows-bottom: Alt sıradaki bazı sayaçların eşi yok.
164
+ counters_note-same-rows-top: Üst sıradaki bazı sayaçlar eşleşmedi.
165
+ counters_note-same-rows-bottom: Alt sıradaki bazı sayaçlar eşleşmedi.
160
166
  counters_hint-same-rows: "Her üst sayaçtan bir alt sayaca çizgi çizin. Çizgisiz kalan sayaçlar neyi değiştireceğinizi gösterir."
161
167
  counters_goal-one-less: "Üst sıraya alt sıradan bir sayaç az verin, sonra Kontrol et düğmesine basın."
162
168
  counters_note-one-less-over: Üst sırada fazla sayaç var.
163
169
  counters_note-one-less-short: Üst sırada eksik sayaç var.
164
- counters_hint-one-less: "Sıraları eşleştirin. Bir sayaç az olunca alt sıranın bir sayacı eşsiz kalır."
165
- counters_goal-right-sign: "İki sıranın arasına satırı doğru yapan işareti koyun, sonra Kontrol et düğmesine basın."
170
+ counters_hint-one-less: "Sıraları eşleştirin. Bir sayaç az olunca alt sıranın bir sayacı eşleşmeden kalır."
171
+ counters_goal-right-sign: "İki sıranın arasına ifadeyi doğru yapan işareti koyun, sonra Kontrol et düğmesine basın."
166
172
  counters_note-right-sign-more: Üst sırada bu işaretin söylediğinden çok sayaç var.
167
173
  counters_note-right-sign-fewer: Üst sırada bu işaretin söylediğinden az sayaç var.
168
- counters_hint-right-sign: "Her üst sayaçtan bir alt sayaca çizgi çizin. Eşsiz sayacı kalan sırada daha çok sayaç vardır ve işaretin açık yanı ona bakar. Hiç sayaç kalmazsa işaret = olur."
174
+ counters_hint-right-sign: "Her üst sayaçtan bir alt sayaca çizgi çizin. Eşleşmeyen sayacı kalan sırada daha çok sayaç vardır ve işaretin açık yanı ona bakar. Hiç sayaç kalmazsa işaret = olur."
169
175
  counters_new-numbers: Yeni sayılar
176
+ counters_add-first: Birinci sayı
177
+ counters_add-second: İkinci sayı
178
+ counters_add-waiting: Bekleyen
179
+ counters_add-sum: Toplam
180
+ counters_add-dice-sum: Çerçevelerdeki sayaçlar
181
+ counters_add-roll: Zar at
182
+ counters_add-die: "{x} gösteren zar"
183
+ counters_add-counter-waiting: Bekleyen sayaç
184
+ counters_add-counter-joined: Bir araya getirilen sayaç
185
+ counters_add-take-second: Çıkan
186
+ counters_add-left: Fark
187
+ counters_add-take-counter: Sayaç
188
+ counters_add-take-ring: Çıkan sayacın halkası
189
+ counters_add-shelf-first: Sabah
190
+ counters_add-shelf-second: Öğleden sonra
191
+ counters_add-shelf-sum: Satılan
192
+ counters_add-shelf-written: Satılan kavanozlar
193
+ counters_add-shelf-written-left: Kalan kavanozlar
194
+ counters_add-shelf-reading: Satılan kavanozlar sözle
195
+ counters_add-shelf-reading-left: Kalan kavanozlar sözle
196
+ counters_add-shelf-crate: Satış kasası
197
+ counters_add-shelf-jar: Raftaki kavanoz
198
+ counters_add-sold-jar: "Kasadaki kavanoz, {x}"
199
+ counters_add-to-ten: 10'a tamamlayan
200
+ counters_add-rest: Diğer parça
201
+ counters_add-seedling: Fide
202
+ counters_add-sprout: Filiz
203
+ counters_add-seed-waiting: Paketteki tohum
204
+ counters_add-seed-joined: Viyoldeki filiz
205
+ counters_goal-find-sum: "{a} ile {b} sayısının toplamını Toplam düğmeleriyle ayarlayın, sonra Kontrol et düğmesine basın."
206
+ counters_goal-find-sum-done: "{a} sayaçlık bir grup ile {b} sayaçlık bir grup bir araya gelince {sum} eder."
207
+ counters_note-find-sum-less: "Toplam {n} sayısından küçük."
208
+ counters_note-find-sum-greater: "Toplam {n} sayısından büyük."
209
+ counters_hint-find-sum: "Çerçevelerde {a} kırmızı sayaç ve onlarla bir araya gelen {b} mavi sayaç düşünün. {a} sayısından başlayıp her mavi sayaç için bir sayı ileri sayın."
210
+ counters_goal-steps-to-ten: "{calc} için 10'a tamamlayan ve Diğer parça düğmelerini ayarlayın, sonra Kontrol et düğmesine basın."
211
+ counters_goal-steps-to-ten-done: "{line}; {toTen} ve {rest}."
212
+ counters_note-steps-to-ten-past: "{step}, 10'u geçiyor."
213
+ counters_note-steps-to-ten-short: "{step}, 10'a varmıyor."
214
+ counters_note-steps-to-ten-more: "10'a tamamlayan ve Diğer parça, {second} sayısından çok ediyor."
215
+ counters_note-steps-to-ten-less: "10'a tamamlayan ve Diğer parça, {second} sayısından az ediyor."
216
+ counters_hint-steps-to-ten-plus: "10'a tamamlayan, {first} ile 10 eden sayıdır. Diğer parça, {second} sayısından geriye kalandır."
217
+ counters_hint-steps-to-ten-minus: "Ona kadar, {first} sayısının dolu onluğundan sonraki sayaçların sayısıdır. Diğer parça, {second} sayısından geriye kalandır."
218
+ counters_add-take-to-ten: Ona kadar
219
+ 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."
220
+ counters_add-shelf-left: Kalan
221
+ line_lead: "Noktayı doğru boyunca hareket ettirin ve çizgisindeki sayıyı okuyun."
222
+ line_jump-left: Sola zıpla
223
+ line_jump-right: Sağa zıpla
224
+ line_point: Noktadaki sayı
225
+ line_point-short: Nokta
226
+ line_second: İkinci noktadaki sayı
227
+ line_second-short: İkinci nokta
228
+ line_jumps: Zıplamalar
229
+ line_step: Adım
230
+ line_from: Sol uç
231
+ line_to: Sağ uç
232
+ line_point-name: Nokta
233
+ line_second-name: İkinci nokta
234
+ line_reading-later: "{a}, {b} sayısından büyüktür"
235
+ line_reading-both: "İki nokta da {a} üzerinde"
236
+ line_goal-place: "Noktayı {target} üzerine koyun, sonra Kontrol et düğmesine basın."
237
+ line_goal-place-done: "Nokta {target} üzerinde."
238
+ line_note-place-left: Nokta sayının solunda.
239
+ line_note-place-right: Nokta sayının sağında.
240
+ line_ten-before: Önceki onluk
241
+ line_ten-after: Sonraki onluk
242
+ line_placed: Yerleşen kartlar
243
+ line_placed-short: Yerleşen
244
+ line_placed-of: "{n} / {all}"
245
+ line_open-gap: "{a} ile {b} arasındaki aralık"
246
+ line_card: "Kart {x}"
247
+ line_find: Bul
248
+ line_show: Göster
249
+ line_next: Sonraki
250
+ line_middle: Orta
251
+ line_van: Kamyonet
252
+ line_estimate: Tahmin
253
+ line_open-book: Kitabı aç
254
+ line_bookmark: Ayraç
255
+ line_hint-place-unmarked: "Orta düğmesine basın. Sayı ortadan önce mi sonra mı? Sonra ortaya ve yakın uca ne kadar uzak olduğunu kestirin."
256
+ line_goal-place-unmarked-done: "Nokta {target} sayısına yakın."
257
+ line_between: "{a} ile {b} arasında"
258
+ line_gaps-unequal: Bazı aralıklar ötekilerden uzun.
259
+ line_gaps-equal: Bütün aralıklar eşit.
260
+ line_mark-name: "Çizgi {x}"
261
+ line_mark-left: Solundaki aralık daha uzun
262
+ line_mark-right: Sağındaki aralık daha uzun
263
+ line_mark-even: İki aralığı eşit
264
+ line_start: Başlangıç
265
+ line_goal-jump: "{start} sayısından zıplayarak {calc} işlemini bulun, sonra Kontrol et düğmesine basın."
266
+ line_note-jump-few: Zıplamalar az.
267
+ line_note-jump-many: Zıplamalar çok.
268
+ line_new-line: Yeni doğru
269
+ line_goal-place-unmarked: "Noktayı {target} sayısına yakın koyun, sonra Kontrol et düğmesine basın."
270
+ line_find-short: Bul
271
+ line_hint-place-on: "Sayının arasında durduğu iki uzun çizgiyi bulun. Soldakinden ileri ya da sağdakinden geri zıplayarak sayın."
272
+ line_hint-place-back: "Sayının arasında durduğu iki uzun çizgiyi bulun. Soldakinden ileri ya da sağdakinden geri zıplayarak sayın."
273
+ line_hint-place-two-labels-on: "Yan yana iki etiket adımı verir. Bir etiketten sayıya kadar zıplamaları sayın."
274
+ line_hint-place-two-labels-back: "Yan yana iki etiket adımı verir. Bir etiketten sayıya kadar zıplamaları sayın."
275
+ line_hint-jump-plus: "Başlangıçtaki sayıyı söyleyin, sonra her zıplamada bir sayı sayın. + için sağa, − için sola zıplayın."
276
+ line_hint-jump-minus: "Başlangıçtaki sayıyı söyleyin, sonra her zıplamada bir sayı sayın. + için sağa, − için sola zıplayın."
277
+ line_hint-jump-plus-one: "Başlangıçtaki sayıyı söyleyin, sonra her zıplamada bir sayı sayın. + için sağa, − için sola zıplayın."
278
+ line_hint-jump-minus-one: "Başlangıçtaki sayıyı söyleyin, sonra her zıplamada bir sayı sayın. + için sağa, − için sola zıplayın."
279
+ line_note-jump-way-plus: Nokta yanlış yöne zıpladı.
280
+ line_note-jump-way-minus: Nokta yanlış yöne zıpladı.
281
+ line_note-jump-few-none: Zıplamalar az.
@@ -1,4 +1,4 @@
1
- hint: Move the figure and watch the numbers follow it.
1
+ hint: "Move things on the figure and watch the numbers change."
2
2
  tab_map: Figure
3
3
  map_data: Data
4
4
  map_view: View
@@ -9,7 +9,14 @@ hesap_start: Start
9
9
  hesap_time: Time
10
10
  hesap_reset: Start again
11
11
  hesap_undo: Undo
12
+ hesap_check: Check
12
13
  hesap_hint: Hint
13
14
  hesap_another: Another one
14
15
  hesap_solved: Solved
15
16
  hesap_not-yet: Not solved yet.
17
+ hesap_written: Number sentence
18
+ hesap_written-reading: In words
19
+ hesap_written-plus: "{a} plus {b} is equal to {c}"
20
+ hesap_written-minus: "{a} minus {b} is equal to {c}"
21
+ hesap_written-plus-open: "{a} plus {b}"
22
+ hesap_written-minus-open: "{a} minus {b}"
@@ -9,7 +9,14 @@ hesap_start: Başlat
9
9
  hesap_time: Zaman
10
10
  hesap_reset: Baştan başla
11
11
  hesap_undo: Geri al
12
+ hesap_check: Kontrol et
12
13
  hesap_hint: İpucu
13
14
  hesap_another: Bir tane daha
14
15
  hesap_solved: Çözüldü
15
16
  hesap_not-yet: Henüz çözülmedi.
17
+ hesap_written: İşlem
18
+ hesap_written-reading: Sözle
19
+ hesap_written-plus: "{a} artı {b} eşittir {c}"
20
+ hesap_written-minus: "{a} eksi {b} eşittir {c}"
21
+ hesap_written-plus-open: "{a} artı {b}"
22
+ hesap_written-minus-open: "{a} eksi {b}"
package/src/kit/kit.css CHANGED
@@ -87,3 +87,12 @@ aside.story .place[data-formula] .katex-display>.katex{text-align:start}
87
87
  /* The peek card sits above the panel. A figure stays clear of the card by leaving --hesap-peek free at its foot. */
88
88
  .peek{bottom:calc(var(--hesap-panel,0px) + .571rem)}
89
89
  }
90
+
91
+ /* The written line of a calculation under a figure, such as 5 + 3 = 8. A number takes its group's colour through
92
+ the family's class, and the signs and the answer are ink. A link underlines the numbers it points to, and a link
93
+ to the whole line underlines the line. */
94
+ .hesap .hesap-written{font-size:34px;font-weight:700;white-space:pre;fill:var(--ink);stroke:none;text-anchor:middle;dominant-baseline:central;font-variant-numeric:tabular-nums;pointer-events:none}
95
+ .hesap .hesap-written.hesap-written-step{font-size:26px}
96
+ .hesap .hesap-written [data-ref]{stroke:none}
97
+ .hesap .hesap-written .hesap-written-num{fill:var(--c,var(--ink))}
98
+ .hesap .hesap-written .hesap-written-hot,.hesap .hesap-written.hesap-written-hot{text-decoration:underline}
package/src/kit/panel.js CHANGED
@@ -47,6 +47,8 @@ export function button({ label, act, press, primary = false, glyph = null, compa
47
47
  if (press) el.addEventListener('click', press);
48
48
  return el;
49
49
  }
50
+ // check is the button that commits a challenge's answer. T gives the shared strings, and press runs once per press.
51
+ export const check = ({ T, press }) => button({ label: T('check'), act: 'check', primary: true, press });
50
52
  // segment is one choice out of a few, each a button. items are [value, words] pairs.
51
53
  export function segment({ id, label, items, value, pick }) {
52
54
  const buttons = items.map(([v, words]) => h('button', { type: 'button', 'data-v': v }, words));
package/src/kit/random.js CHANGED
@@ -33,3 +33,12 @@ export function dice(seed) {
33
33
  const shuffle = items => { const a = [...items]; for (let i = a.length - 1; i > 0; i--) { const j = int(0, i); [a[i], a[j]] = [a[j], a[i]]; } return a; };
34
34
  return { next, int, pick: items => items[int(0, items.length - 1)], shuffle, some: (items, n) => shuffle(items).slice(0, n) };
35
35
  }
36
+
37
+ // another draws a goal's target that differs from the last one, so Another one always changes the figure.
38
+ export function another(goal, c, spec, dice, last) {
39
+ for (let i = 0; i < 40; i++) {
40
+ const t = goal.draw(c, spec, dice);
41
+ if (!last || JSON.stringify(t) !== JSON.stringify(last)) return t;
42
+ }
43
+ return goal.draw(c, spec, dice);
44
+ }
@@ -0,0 +1,70 @@
1
+ // The written line of a calculation under a figure, such as 5 + 3 = 8, or 13 − 8 before the figure shows the
2
+ // answer. The model half gives a line's words and its reading aloud, and the build and the browser both use it, so a
3
+ // text and its live value agree. writtenLine draws a line in a family's figure.
4
+ import { svg as el } from './dom.js';
5
+
6
+ export const PLUS = '+', MINUS = '−';
7
+ // A line is { a, sign, b }, the number before the sign, the sign and the number after it. A line with open: true
8
+ // leaves out its answer.
9
+ export const answerOf = line => line.sign === PLUS ? line.a + line.b : line.a - line.b;
10
+
11
+ // parts gives the pieces of a line in order. A number carries its role: a and b for the numbers either side of the
12
+ // sign, and c for the answer.
13
+ export function parts(line) {
14
+ const out = [{ role: 'a', n: line.a }, { sign: line.sign }, { role: 'b', n: line.b }];
15
+ if (!line.open) out.push({ sign: '=' }, { role: 'c', n: answerOf(line) });
16
+ return out;
17
+ }
18
+ // words writes a line, such as "5 + 3 = 8". int writes a number in the page's language.
19
+ export const words = (line, int) => parts(line).map(p => p.sign ?? int(p.n)).join(' ');
20
+ // The kit's string of the line in words. The four strings take the numbers as {a}, {b} and {c}.
21
+ export const readingKey = line => `written-${line.sign === PLUS ? 'plus' : 'minus'}${line.open ? '-open' : ''}`;
22
+ // reading says a line in words, such as "5 plus 3 is equal to 8". T reads the kit's strings without their prefix
23
+ // hesap_, as a family's T does in the browser.
24
+ export const reading = (line, int, T) => T(readingKey(line), { a: int(line.a), b: int(line.b), c: int(answerOf(line)) });
25
+
26
+ // The size of a written line in a figure's units, the size of the numbers of the line of two numbers in counters/match.
27
+ export const SIZE = 34;
28
+ // The size of a step line.
29
+ export const STEP_SIZE = 26;
30
+ // widthOf gives the room a line of these words takes, a little wider than its digits and signs.
31
+ export const widthOf = text => text.length * SIZE * 0.6;
32
+
33
+ // A link of a line that does not show reads this, such as a step of making ten while the figure does not show it.
34
+ export const DASH = '–';
35
+
36
+ // writtenLine makes a line with its middle at 0, 0. refs gives the link id of each role, and cls the class that
37
+ // colours a number in its group's colour, such as { a: 'counters-a', b: 'counters-b' }. A role without a class is
38
+ // written in ink, as the signs are. A line whose roles change with the figure carries its own refs and cls. A step
39
+ // line, such as a step of making ten under the line of the calculation, is written smaller.
40
+ export function writtenLine({ refs = {}, cls = {}, step = false } = {}) {
41
+ const text = el('text', { class: `hesap-written${step ? ' hesap-written-step' : ''}`, display: 'none' });
42
+ let said = null, drawn = null, lit = new Set();
43
+ const paint = () => { for (const t of text.querySelectorAll('[data-ref]')) t.classList.toggle('hesap-written-hot', lit.has(t.dataset.ref)); };
44
+ return {
45
+ el: text,
46
+ // set writes the line and says whether it changed words it showed already, for a flash. A line of null takes the
47
+ // line off the figure.
48
+ set(line, int) {
49
+ text.setAttribute('display', line ? 'inline' : 'none');
50
+ const r = line?.refs ?? refs, c = line?.cls ?? cls, now = line ? words(line, int) : null, key = line ? JSON.stringify([now, r, c]) : null;
51
+ if (key === drawn) return false;
52
+ const first = said === null, changed = now !== said;
53
+ said = now; drawn = key;
54
+ text.replaceChildren(...(line ? parts(line).flatMap((p, i) => {
55
+ const gap = i ? ' ' : '';
56
+ if (p.sign) return [`${gap}${p.sign}`];
57
+ const span = el('tspan', { class: ['hesap-written-num', c[p.role]].filter(Boolean).join(' '), 'data-ref': r[p.role] });
58
+ span.textContent = int(p.n);
59
+ return [gap, span];
60
+ }) : []));
61
+ paint();
62
+ return !first && !!line && changed;
63
+ },
64
+ words: () => said,
65
+ at(x, y) { text.setAttribute('x', x); text.setAttribute('y', y); },
66
+ // light marks the numbers a link points to, together with the family's part of the figure. whole names the
67
+ // links that mark the whole line, such as written and reading.
68
+ light(id, on, whole = []) { if (on) lit.add(id); else lit.delete(id); paint(); text.classList.toggle('hesap-written-hot', whole.some(w => lit.has(w))); },
69
+ };
70
+ }
package/src/node.mjs CHANGED
@@ -44,10 +44,12 @@ export function drawn(goal, c, spec, { at, ctx, starts }) {
44
44
  export function hidden(readout, hides, at, ctx) {
45
45
  for (const id of readout) if (hides.includes(id)) ctx.fail(at, `readout names "${id}", which gives the challenge's answer away, leave it out`);
46
46
  }
47
- // value reads a field that is a number, a slider or a stepper as its starting value and its control's range.
47
+ // value reads a field that is a number, a slider, a stepper or a segment as its starting value and its control. A
48
+ // segment's control holds its items, and a slider's or a stepper's its range.
48
49
  export function value(v) {
49
50
  if (v == null) return { n: null, ctl: null };
50
51
  if (typeof v === 'number') return { n: v, ctl: null };
52
+ if (v.segment) return { n: v.start ?? v.segment[0], ctl: { kind: 'segment', items: v.segment } };
51
53
  const kind = v.slider ? 'slider' : 'stepper', [lo, hi] = v[kind];
52
54
  return { n: v.start ?? lo, ctl: { kind, lo, hi } };
53
55
  }