@openbooknetwork/hesap 0.0.0-stage → 0.2.2
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/LICENSE +21 -0
- package/README.md +116 -2
- package/package.json +45 -4
- package/scripts/assemble.mjs +40 -0
- package/src/client.css +240 -0
- package/src/client.js +111 -0
- package/src/families/counters/bonds.js +424 -0
- package/src/families/counters/client.css +150 -0
- package/src/families/counters/client.js +22 -0
- package/src/families/counters/count-figures.js +166 -0
- package/src/families/counters/count-goals.js +57 -0
- package/src/families/counters/count-model.js +57 -0
- package/src/families/counters/count.js +322 -0
- package/src/families/counters/count.mjs +88 -0
- package/src/families/counters/counter.js +52 -0
- package/src/families/counters/driver.js +16 -0
- package/src/families/counters/figures.js +172 -0
- package/src/families/counters/frame.js +28 -0
- package/src/families/counters/goals.js +75 -0
- package/src/families/counters/i18n/en.yaml +86 -0
- package/src/families/counters/i18n/tr.yaml +86 -0
- package/src/families/counters/index.mjs +104 -0
- package/src/families/counters/model.js +86 -0
- package/src/families/counters/move.js +44 -0
- package/src/families/counters/places.js +45 -0
- package/src/families.mjs +5 -0
- package/src/i18n/en.yaml +101 -0
- package/src/i18n/tr.yaml +101 -0
- package/src/index.mjs +82 -0
- package/src/kit/dom.js +32 -0
- package/src/kit/drag.js +40 -0
- package/src/kit/format.js +34 -0
- package/src/kit/goal.js +49 -0
- package/src/kit/i18n/en.yaml +15 -0
- package/src/kit/i18n/tr.yaml +15 -0
- package/src/kit/kit.css +89 -0
- package/src/kit/motion.js +44 -0
- package/src/kit/panel.js +70 -0
- package/src/kit/play.js +26 -0
- package/src/kit/random.js +35 -0
- package/src/kit/text.js +25 -0
- package/src/node.mjs +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Can Bascil
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Hesap
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The maths engine of the Open Book Network. A page shows a figure the reader can move, with the numbers and
|
|
4
|
+
formulas in the text following it. Hesap runs under [kitap](../kitap), which builds the book.
|
|
5
|
+
|
|
6
|
+
## A page
|
|
7
|
+
|
|
8
|
+
```yaml
|
|
9
|
+
hesap:
|
|
10
|
+
scene: counters/bonds # the figure: a family and one of its scenes, from the table below
|
|
11
|
+
look: frames # the scene's own fields
|
|
12
|
+
frames: 2
|
|
13
|
+
readout: [first, empty]
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The text links a value as `[0](@first)` and a worked formula as `[...](@formula-<id>)`. The page writes the live
|
|
17
|
+
value in the link's place, and `kitap check` prints the words to write when a text differs from what the page
|
|
18
|
+
shows as it opens.
|
|
19
|
+
|
|
20
|
+
A challenge page adds a goal and its targets:
|
|
21
|
+
|
|
22
|
+
```yaml
|
|
23
|
+
hesap:
|
|
24
|
+
scene: counters/bonds
|
|
25
|
+
look: frames
|
|
26
|
+
frames: 1
|
|
27
|
+
challenge: { goal: make-whole, whole: 10, part: [1, 9] }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The page draws the challenge from those ranges as it opens and again on "Another one", so a reader meets new
|
|
31
|
+
numbers each time. The panel shows the goal in words and whether it is reached. The build draws 300 targets for
|
|
32
|
+
each challenge and fails a page where one is solved as the page opens or lies out of the controls' reach.
|
|
33
|
+
|
|
34
|
+
## Scenes
|
|
35
|
+
|
|
36
|
+
Scenes come in families. Each family is a folder under `src/families/`. A page names a scene as
|
|
37
|
+
`<family>/<scene>`. A family whose one scene has the family's name is named alone.
|
|
38
|
+
|
|
39
|
+
| Family | Scenes |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `counters` | `bonds`, `count` |
|
|
42
|
+
|
|
43
|
+
`counters/bonds` shows a whole and its two parts: a part-whole diagram, one or two ten frames with counters of two
|
|
44
|
+
colours, a cup that hides a part and a list of the splits found. Its `index.mjs` holds the schema of its fields,
|
|
45
|
+
with a comment on every field.
|
|
46
|
+
|
|
47
|
+
`counters/count` counts objects one by one: apples, birds, cups, shells or counters that take the next number when
|
|
48
|
+
tapped, a closed box to count on from, counters that leave a tray, a marker in rows of ten, a bus and a staircase.
|
|
49
|
+
Its `count.mjs` holds the schema of its fields.
|
|
50
|
+
|
|
51
|
+
The tag `prototypes` holds 13 more families from the prototype stories: `geo`, `axes`, `graph`, `wave`, `linear`,
|
|
52
|
+
`chance`, `machine`, `parts`, `grid`, `venn`, `balance`, `network` and `proof`. A family comes back from there with
|
|
53
|
+
the first story that needs it: `git checkout prototypes -- src/families/<id>`, then its line in `src/families.mjs`.
|
|
54
|
+
|
|
55
|
+
## Layout
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
src/index.mjs the engine module kitap loads: finds a scene's family, checks the links in the text
|
|
59
|
+
src/families.mjs the list of families
|
|
60
|
+
src/client.js the browser shell: loads a family, gives it a stage and a panel, shows the cover
|
|
61
|
+
src/node.mjs checks every family's Node half shares
|
|
62
|
+
src/kit/ what every family's browser half shares
|
|
63
|
+
src/families/<id>/ one family: index.mjs, client.js, client.css, i18n/, and its own modules
|
|
64
|
+
scripts/assemble.mjs writes src/client.css and src/i18n/ from the kit and every family
|
|
65
|
+
test/ the contract every family keeps: npm test
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The kit:
|
|
69
|
+
|
|
70
|
+
| File | What it gives |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `panel.js` | `slider`, `chip`, `button`, `segment`, `stepper`, `row` |
|
|
73
|
+
| `goal.js` | `goalRow`, the line a challenge shows |
|
|
74
|
+
| `text.js` | `live` for the links in the text, `math` for a formula |
|
|
75
|
+
| `play.js` | `player`, a Start button's run with a time slider |
|
|
76
|
+
| `random.js` | `dice` and `fresh`, the seeded draws of a challenge |
|
|
77
|
+
| `drag.js` | `drag` and `nudge` for pointer and arrow key dragging |
|
|
78
|
+
| `motion.js` | `tracker`, anime.js animations that a page change stops |
|
|
79
|
+
| `format.js` | `numbers` per language, `aligned`, `fill` |
|
|
80
|
+
| `dom.js` | `svg`, `h`, `icon`, `svgPoint`, `esc` |
|
|
81
|
+
|
|
82
|
+
## A family
|
|
83
|
+
|
|
84
|
+
The Node half, `index.mjs`:
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
export default {
|
|
88
|
+
id: 'counters',
|
|
89
|
+
scenes: ['bonds'], // the scenes it owns
|
|
90
|
+
schema, // strict zod object of a page's fields, without scene
|
|
91
|
+
read(pg, { at, pid }, ctx) { ... }, // checks the page, returns { data, has, offers }
|
|
92
|
+
start(spec, lang, id) { ... }, // the words a link shows when the page opens
|
|
93
|
+
bundle(content) { ... }, // optional: { data, families }, data.overview is the overview scene
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The browser half, `client.js`:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
export default function counters({ host, box, stage, panel, T, lang, moving, motion, data }) {
|
|
101
|
+
return { show(spec, page) { ... }, hide() { ... }, point(id, on) { ... }, lang() { ... } };
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`families/counters/` is the family to read first. A new family is added to `src/families.mjs`.
|
|
106
|
+
|
|
107
|
+
Strings sit in the family's `i18n/en.yaml` and `i18n/tr.yaml` under the prefix `<id>_`, and `<id>_lead` is the
|
|
108
|
+
line the book shows under the story's title. Styles sit in the family's `client.css` under `.hesap-<id>`. Run
|
|
109
|
+
`node scripts/assemble.mjs` after a change to either.
|
|
110
|
+
|
|
111
|
+
## Libraries
|
|
112
|
+
|
|
113
|
+
anime.js animates and KaTeX sets formulas. A family that draws with a library of its own names it in the engine's
|
|
114
|
+
`client.imports`, so it loads with that family alone.
|
|
115
|
+
|
|
116
|
+
Kitap serves hesap's browser modules from a folder named after hesap's version. A release raises the version in
|
|
117
|
+
`package.json`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openbooknetwork/hesap",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Hesap: the maths engine of the Open Book Network, figures a reader can move with the numbers and formulas that follow them",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"maths",
|
|
8
|
+
"geometry",
|
|
9
|
+
"interactive",
|
|
10
|
+
"education",
|
|
11
|
+
"static-site"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Can Bascil",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/openbooknetwork/hesap.git"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/openbooknetwork/hesap#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/openbooknetwork/hesap/issues"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22.12"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./src/index.mjs",
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"src",
|
|
32
|
+
"scripts/assemble.mjs"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"assemble": "node scripts/assemble.mjs",
|
|
39
|
+
"test": "node scripts/assemble.mjs --check && node --test test/*.test.mjs",
|
|
40
|
+
"prepublishOnly": "npm test"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@openbooknetwork/kitap": "^0.7.2",
|
|
44
|
+
"animejs": "^4.5.0",
|
|
45
|
+
"katex": "^0.19.1"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Writes src/client.css and src/i18n/<lang>.yaml from the kit and every family, the two files kitap reads whole.
|
|
2
|
+
// Run it after a change to a family's client.css or i18n: node scripts/assemble.mjs
|
|
3
|
+
// With --check it writes nothing and fails when either file is out of date, which the tests run.
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import FAMILIES from '../src/families.mjs';
|
|
8
|
+
|
|
9
|
+
const SRC = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../src'), DIR = path.join(SRC, 'families');
|
|
10
|
+
const checking = process.argv.includes('--check');
|
|
11
|
+
const problems = [];
|
|
12
|
+
// src/families.mjs is the one list of families. A folder it leaves out would ship styles and strings with no scene.
|
|
13
|
+
const families = FAMILIES.map(f => f.id), folders = fs.readdirSync(DIR).filter(f => fs.statSync(path.join(DIR, f)).isDirectory());
|
|
14
|
+
for (const f of folders) if (!families.includes(f)) problems.push(`src/families/${f}/ is not in src/families.mjs, add it there or remove the folder`);
|
|
15
|
+
for (const f of families) if (!folders.includes(f)) problems.push(`src/families.mjs names ${f}, which has no folder in src/families/`);
|
|
16
|
+
|
|
17
|
+
const read = f => fs.existsSync(f) ? fs.readFileSync(f, 'utf8').trimEnd() : '';
|
|
18
|
+
const write = (file, text) => {
|
|
19
|
+
if (!checking) return fs.writeFileSync(file, text);
|
|
20
|
+
if (read(file) !== text.trimEnd()) problems.push(`${path.relative(path.dirname(SRC), file)} is out of date, run node scripts/assemble.mjs`);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const css = [read(path.join(SRC, 'kit/kit.css')), ...families.map(f => read(path.join(DIR, f, 'client.css')))].filter(Boolean);
|
|
24
|
+
write(path.join(SRC, 'client.css'), css.join('\n\n') + '\n');
|
|
25
|
+
|
|
26
|
+
fs.mkdirSync(path.join(SRC, 'i18n'), { recursive: true });
|
|
27
|
+
for (const file of fs.readdirSync(path.join(SRC, 'kit/i18n'))) {
|
|
28
|
+
const parts = [read(path.join(SRC, 'kit/i18n', file)), ...families.map(f => read(path.join(DIR, f, 'i18n', file)))].filter(Boolean);
|
|
29
|
+
// A key belongs to one file, and a second copy would silently win.
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
for (const line of parts.join('\n').split('\n')) {
|
|
32
|
+
const key = /^([\w.-]+):/.exec(line)?.[1];
|
|
33
|
+
if (key && seen.has(key)) problems.push(`${file}: the key ${key} is written twice`);
|
|
34
|
+
if (key) seen.add(key);
|
|
35
|
+
}
|
|
36
|
+
write(path.join(SRC, 'i18n', file), parts.join('\n') + '\n');
|
|
37
|
+
}
|
|
38
|
+
for (const p of problems) console.error(p);
|
|
39
|
+
if (problems.length) process.exit(1);
|
|
40
|
+
console.log(checking ? `the styles and strings of ${families.length} families are up to date` : `assembled ${families.length} families`);
|
package/src/client.css
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/* Hesap has a layer of its own, so nothing in a figure rises over a phone's text. Each family draws inside its own
|
|
2
|
+
box, which fills the viewport while one of its pages shows. */
|
|
3
|
+
.hesap{position:absolute;inset:0;background:var(--paper);isolation:isolate;user-select:none;-webkit-user-select:none;font-family:var(--body);color:var(--ink)}
|
|
4
|
+
.hesap-family{position:absolute;inset:0;display:flex;flex-direction:column}
|
|
5
|
+
.hesap-family[hidden],.hesap-stage[hidden],.hesap-panel[hidden],.hesap-cover[hidden],.hesap-panel [hidden]{display:none}
|
|
6
|
+
.hesap-cover{position:absolute;inset:0;width:100%;height:100%;object-fit:contain}
|
|
7
|
+
.hesap-stage{flex:1;min-height:0;position:relative}
|
|
8
|
+
/* On a screen with room the readouts stand above the figure in large type. */
|
|
9
|
+
.hesap-head{padding:.857rem 1.143rem 0}
|
|
10
|
+
.hesap-head[hidden]{display:none}
|
|
11
|
+
.hesap-head .hesap-out{gap:.571rem 1.714rem;align-items:flex-end}
|
|
12
|
+
.hesap-head .hesap-chip{flex-direction:column;align-items:flex-start;gap:.071rem;border:0;border-radius:0;padding:0;background:none;box-shadow:none}
|
|
13
|
+
.hesap-head .hesap-chip small{font-size:.857rem}
|
|
14
|
+
.hesap-head .hesap-chip b{font-family:var(--display);font-size:2.286rem;line-height:1.1;text-align:start}
|
|
15
|
+
.hesap-head .hesap-chip.hot b,.hesap-head .hesap-chip[aria-pressed="true"] b{color:var(--accent)}
|
|
16
|
+
.hesap-head .hesap-btn{margin-inline-start:auto}
|
|
17
|
+
|
|
18
|
+
/* The panel under the figure holds a challenge's line, then the controls, then the readouts. */
|
|
19
|
+
.hesap-panel{position:relative;border-top:1px solid var(--rule);background:var(--panel);padding:.571rem .857rem;display:flex;flex-direction:column;gap:.5rem}
|
|
20
|
+
.hesap-ctls,.hesap-acts{display:flex;flex-wrap:wrap;gap:.429rem .857rem;align-items:center}
|
|
21
|
+
.hesap-acts{margin-inline-start:auto}
|
|
22
|
+
.hesap-out{display:flex;flex-wrap:wrap;gap:.357rem .429rem;align-items:center}
|
|
23
|
+
.hesap-panel .hot{outline:2px solid var(--accent);outline-offset:2px}
|
|
24
|
+
|
|
25
|
+
/* A slider takes the room the other controls leave on its row. */
|
|
26
|
+
.hesap-ctl{flex:1 1 14rem;display:flex;align-items:center;gap:.571rem;min-height:44px;border-radius:6px}
|
|
27
|
+
.hesap-ctl span{color:var(--ink-2);white-space:nowrap}
|
|
28
|
+
.hesap-ctl input{flex:1;min-width:0;min-height:44px;margin:0;accent-color:var(--accent)}
|
|
29
|
+
.hesap-ctl output{font-variant-numeric:tabular-nums;font-weight:700;text-align:end;min-width:3ch}
|
|
30
|
+
|
|
31
|
+
.hesap-btn,.hesap-seg button,.hesap-step button{min-height:44px;min-width:44px;border:1px solid var(--rule);background:var(--paper);color:var(--ink);font:inherit;cursor:pointer;border-radius:6px;display:inline-flex;align-items:center;justify-content:center;gap:.357rem;padding:0 .714rem;white-space:nowrap}
|
|
32
|
+
.hesap-btn:disabled,.hesap-step button:disabled{opacity:.45;cursor:default}
|
|
33
|
+
.hesap-icon{width:18px;height:18px;flex:none}
|
|
34
|
+
:is(.hesap-btn,.hesap-seg button,.hesap-step button,.hesap-chip):focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
35
|
+
.hesap-btn[aria-pressed="true"]{background:var(--ink);color:var(--paper);border-color:var(--ink)}
|
|
36
|
+
/* The one button that starts something stands out. */
|
|
37
|
+
.hesap-primary{background:var(--accent);border-color:var(--accent);color:var(--paper);font-weight:700;padding:0 1.143rem}
|
|
38
|
+
|
|
39
|
+
.hesap-seg{display:inline-flex;align-items:center}
|
|
40
|
+
.hesap-seg-name{color:var(--ink-2);font-size:.857rem;margin-inline-end:.429rem}
|
|
41
|
+
.hesap-seg button{border-radius:0;margin-inline-start:-1px;font-variant-numeric:tabular-nums;padding:0 .571rem}
|
|
42
|
+
.hesap-seg button:first-of-type{border-start-start-radius:6px;border-end-start-radius:6px;margin-inline-start:0}
|
|
43
|
+
.hesap-seg button:last-of-type{border-start-end-radius:6px;border-end-end-radius:6px}
|
|
44
|
+
.hesap-seg button[aria-pressed="true"]{background:var(--ink);color:var(--paper);border-color:var(--ink);position:relative}
|
|
45
|
+
|
|
46
|
+
.hesap-step{display:inline-flex;align-items:center;gap:.357rem}
|
|
47
|
+
.hesap-step span{color:var(--ink-2);margin-inline-end:.214rem}
|
|
48
|
+
.hesap-step output{min-width:2.5ch;text-align:center;font-weight:700;font-variant-numeric:tabular-nums}
|
|
49
|
+
|
|
50
|
+
.hesap-chip{display:inline-flex;gap:.429rem;align-items:baseline;border:1px solid var(--rule);border-radius:999px;padding:.286rem .786rem;background:var(--paper);color:var(--ink);font:inherit}
|
|
51
|
+
button.hesap-chip{cursor:pointer;min-height:36px;align-items:center}
|
|
52
|
+
.hesap-chip small{color:var(--ink-2);font-size:.857rem;white-space:nowrap}
|
|
53
|
+
.hesap-chip b{font-variant-numeric:tabular-nums;text-align:end}
|
|
54
|
+
.hesap-swatch{width:.714rem;height:.714rem;border-radius:50%;flex:none;align-self:center;background:currentColor}
|
|
55
|
+
.hesap-short{display:none}
|
|
56
|
+
.hesap-chip.hot{outline:none;border-color:var(--accent);box-shadow:inset 0 0 0 1px var(--accent)}
|
|
57
|
+
.hesap-chip[aria-pressed="true"]{border-color:var(--ink);box-shadow:inset 0 0 0 1px var(--ink)}
|
|
58
|
+
|
|
59
|
+
/* A challenge's line holds the goal, whether it is reached, another target and a hint. The goal takes a line of its
|
|
60
|
+
own, so a longer status keeps the panel's height. */
|
|
61
|
+
.hesap-goal{display:flex;flex-wrap:wrap;align-items:center;gap:.286rem .571rem}
|
|
62
|
+
.hesap-goal-text{margin:0;flex-basis:100%;font-weight:600}
|
|
63
|
+
.hesap-goal-state{display:inline-flex;align-items:center;gap:.286rem;color:var(--ink-2);flex:1;min-width:0}
|
|
64
|
+
.hesap-goal.solved .hesap-goal-state{color:var(--accent)}
|
|
65
|
+
.hesap-goal-state svg{width:20px;height:20px}
|
|
66
|
+
.hesap-hint{margin:0;flex-basis:100%;color:var(--ink-2)}
|
|
67
|
+
.hesap-hint[hidden]{display:none}
|
|
68
|
+
|
|
69
|
+
/* The values in the text follow the figure. A worked formula takes its own line, and scrolls sideways on a narrow
|
|
70
|
+
screen. */
|
|
71
|
+
aside.story .place[data-live]{font-variant-numeric:tabular-nums;font-weight:700}
|
|
72
|
+
aside.story .place[data-formula],aside.story .place[data-formula]:is(:hover,:focus-visible,.on){display:block;text-decoration:none;background:none;overflow-x:auto;overflow-y:hidden;padding:.143rem 0}
|
|
73
|
+
aside.story .place[data-formula] .katex-display{margin:0;text-align:start}
|
|
74
|
+
aside.story .place[data-formula] .katex-display>.katex{text-align:start}
|
|
75
|
+
|
|
76
|
+
@media (max-width:900px){
|
|
77
|
+
.hesap-panel{padding:.429rem .571rem;gap:.357rem}
|
|
78
|
+
.hesap-ctls,.hesap-acts{gap:.286rem .571rem}
|
|
79
|
+
.hesap-btn,.hesap-seg button,.hesap-step button{min-height:42px}
|
|
80
|
+
.hesap-chip{padding:.214rem .643rem}
|
|
81
|
+
.hesap-chip small{font-size:.786rem}
|
|
82
|
+
.hesap-long{display:none}
|
|
83
|
+
.hesap-short{display:inline}
|
|
84
|
+
/* A compact button shows its glyph alone. */
|
|
85
|
+
.hesap-compact{min-width:44px;padding:0}
|
|
86
|
+
.hesap-compact span{display:none}
|
|
87
|
+
/* The peek card sits above the panel. A figure stays clear of the card by leaving --hesap-peek free at its foot. */
|
|
88
|
+
.peek{bottom:calc(var(--hesap-panel,0px) + .571rem)}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* counters: the colours are theme tokens and the two counter colours of the family, so a theme switch needs no
|
|
92
|
+
redraw. */
|
|
93
|
+
.hesap-counters .counters-svg{position:absolute;left:0;top:0;width:100%;height:100%;touch-action:none;font-family:var(--body);overflow:visible}
|
|
94
|
+
.hesap-counters text{fill:var(--ink);text-anchor:middle;dominant-baseline:central;pointer-events:none;font-variant-numeric:tabular-nums}
|
|
95
|
+
.hesap-counters .counters-a{--c:var(--z-counters-red,#d1453b)}
|
|
96
|
+
.hesap-counters .counters-b{--c:var(--z-counters-blue,#2a6bd1)}
|
|
97
|
+
|
|
98
|
+
/* A counter is a disc, a bead or a car, with a touch target round it. */
|
|
99
|
+
.hesap-counters .counters-hit{fill:transparent}
|
|
100
|
+
.hesap-counters .counters-body{fill:var(--c);stroke:var(--paper);stroke-width:1.5}
|
|
101
|
+
.hesap-counters .counters-ring{fill:none;stroke:var(--paper);stroke-width:2;opacity:.6}
|
|
102
|
+
.hesap-counters .counters-shine{fill:var(--paper);opacity:.55}
|
|
103
|
+
.hesap-counters .counters-glass{fill:var(--paper);opacity:.7}
|
|
104
|
+
.hesap-counters .counters-bead .counters-body{fill:var(--z-counters-blue,#2a6bd1)}
|
|
105
|
+
/* The cars of a car park come in six paints. */
|
|
106
|
+
.hesap-counters .counters-paint-0 .counters-body{fill:#d1453b}
|
|
107
|
+
.hesap-counters .counters-paint-1 .counters-body{fill:#2a6bd1}
|
|
108
|
+
.hesap-counters .counters-paint-2 .counters-body{fill:#2e9d5b}
|
|
109
|
+
.hesap-counters .counters-paint-3 .counters-body{fill:#d99a1f}
|
|
110
|
+
.hesap-counters .counters-paint-4 .counters-body{fill:#8a56c9}
|
|
111
|
+
.hesap-counters .counters-paint-5 .counters-body{fill:#1f9aa3}
|
|
112
|
+
.hesap-counters .counters-moves{cursor:grab;outline:none}
|
|
113
|
+
.hesap-counters .counters-moves.drag{cursor:grabbing}
|
|
114
|
+
.hesap-counters .counters-moves:focus-visible .counters-hit{stroke:var(--accent);stroke-width:2.5}
|
|
115
|
+
.hesap-counters .counters-tapping .counters-layer{pointer-events:none}
|
|
116
|
+
.hesap-counters .counters-over .counters-body{stroke:var(--ink);stroke-width:2.5;stroke-dasharray:4 3}
|
|
117
|
+
|
|
118
|
+
/* The part-whole diagram: the whole above, the two parts below, joined by lines. */
|
|
119
|
+
.hesap-counters .counters-link{stroke:var(--rule);stroke-width:3}
|
|
120
|
+
.hesap-counters .counters-whole{fill:var(--panel);stroke:var(--ink);stroke-width:2.5}
|
|
121
|
+
.hesap-counters .counters-part{fill:var(--paper);stroke:var(--ink-2);stroke-width:2}
|
|
122
|
+
.hesap-counters .counters-a-ring{stroke:var(--z-counters-red,#d1453b);stroke-width:3}
|
|
123
|
+
.hesap-counters .counters-b-ring{stroke:var(--z-counters-blue,#2a6bd1);stroke-width:3}
|
|
124
|
+
.hesap-counters .counters-big{font-size:28px;font-weight:700}
|
|
125
|
+
.hesap-counters .counters-badge{font-size:20px;font-weight:700;fill:var(--ink-2)}
|
|
126
|
+
.hesap-counters .counters-hot{stroke:var(--accent);stroke-width:4}
|
|
127
|
+
.hesap-counters g.counters-hot .counters-slot-box{stroke:var(--accent)}
|
|
128
|
+
|
|
129
|
+
/* The cup hides a part until the reader lifts it. */
|
|
130
|
+
.hesap-counters .counters-cup{cursor:pointer;outline:none}
|
|
131
|
+
.hesap-counters .counters-cup-body{fill:var(--ink-2);stroke:var(--ink);stroke-width:2}
|
|
132
|
+
.hesap-counters .counters-cup-rim,.hesap-counters .counters-cup-knob{fill:var(--ink);stroke:none}
|
|
133
|
+
.hesap-counters .counters-cup:focus-visible .counters-cup-body{stroke:var(--accent);stroke-width:4}
|
|
134
|
+
|
|
135
|
+
/* The hands hold the beads on their palms. */
|
|
136
|
+
.hesap-counters .counters-hand{fill:var(--panel);stroke:var(--ink-2);stroke-width:2}
|
|
137
|
+
.hesap-counters .counters-palm{stroke-width:2.5}
|
|
138
|
+
|
|
139
|
+
/* Ten frames, and the cells a reader taps. */
|
|
140
|
+
.hesap-counters .counters-frame-box{fill:var(--paper);stroke:var(--ink);stroke-width:2.5}
|
|
141
|
+
.hesap-counters .counters-frame line{stroke:var(--ink-2);stroke-width:1.5}
|
|
142
|
+
.hesap-counters .counters-cell{fill:transparent;cursor:pointer;outline:none}
|
|
143
|
+
.hesap-counters .counters-cell:hover{fill:var(--accent);fill-opacity:.1}
|
|
144
|
+
.hesap-counters .counters-cell:focus-visible{stroke:var(--accent);stroke-width:3}
|
|
145
|
+
|
|
146
|
+
/* The list keeps a slot for each split, and a slot fills when the reader finds its split. */
|
|
147
|
+
.hesap-counters .counters-list-title{font-size:15px;font-weight:600;fill:var(--ink-2)}
|
|
148
|
+
.hesap-counters .counters-slot-box{fill:none;stroke:var(--rule);stroke-width:1.5;stroke-dasharray:4 4}
|
|
149
|
+
.hesap-counters .counters-slot-text{font-size:15px;font-weight:600}
|
|
150
|
+
.hesap-counters .counters-found .counters-slot-box{fill:var(--panel);stroke:var(--ink-2);stroke-dasharray:none}
|
|
151
|
+
.hesap-counters .counters-now .counters-slot-box{stroke:var(--accent);stroke-width:2.5}
|
|
152
|
+
.hesap-counters .counters-slot[hidden]{display:none}
|
|
153
|
+
|
|
154
|
+
/* The lane of pins: a pin falls over when the reader knocks it down. */
|
|
155
|
+
.hesap-counters .counters-lane{fill:var(--panel);stroke:var(--rule);stroke-width:2}
|
|
156
|
+
.hesap-counters .counters-pin{cursor:pointer;outline:none}
|
|
157
|
+
.hesap-counters .counters-pin-shape{fill:var(--paper);stroke:var(--ink);stroke-width:2}
|
|
158
|
+
.hesap-counters .counters-pin-stripe{fill:var(--z-counters-red,#d1453b)}
|
|
159
|
+
.hesap-counters .counters-spot{fill:var(--rule)}
|
|
160
|
+
.hesap-counters .counters-down .counters-pin-body{opacity:.45}
|
|
161
|
+
.hesap-counters .counters-pin:focus-visible .counters-hit{stroke:var(--accent);stroke-width:2.5}
|
|
162
|
+
|
|
163
|
+
/* The car park: two rows of spaces, an aisle, and a sign that shows the free spaces. */
|
|
164
|
+
.hesap-counters .counters-ground{fill:var(--panel);stroke:var(--rule);stroke-width:2}
|
|
165
|
+
.hesap-counters .counters-space{fill:transparent;cursor:pointer;outline:none}
|
|
166
|
+
.hesap-counters .counters-space:hover{fill:var(--accent);fill-opacity:.1}
|
|
167
|
+
.hesap-counters .counters-space:focus-visible{stroke:var(--accent);stroke-width:3}
|
|
168
|
+
.hesap-counters .counters-bay{stroke:var(--ink-2);stroke-width:2}
|
|
169
|
+
.hesap-counters .counters-road{stroke:var(--rule);stroke-width:3;stroke-dasharray:14 10}
|
|
170
|
+
.hesap-counters .counters-sign-box{fill:var(--ink);stroke:none}
|
|
171
|
+
.hesap-counters .counters-sign-word{fill:var(--paper);font-size:12px;font-weight:600}
|
|
172
|
+
.hesap-counters .counters-sign-num{fill:var(--paper);font-size:24px;font-weight:700}
|
|
173
|
+
.hesap-counters .counters-sign.counters-hot .counters-sign-box{fill:var(--accent)}
|
|
174
|
+
|
|
175
|
+
/* The trays of the challenges, and the pile the reader takes counters from. */
|
|
176
|
+
.hesap-counters .counters-tray{fill:var(--panel);stroke:var(--ink-2);stroke-width:2}
|
|
177
|
+
.hesap-counters .counters-tray-label{font-size:14px;font-weight:600;fill:var(--ink-2)}
|
|
178
|
+
.hesap-counters .counters-heap-floor{fill:var(--rule);opacity:.6}
|
|
179
|
+
.hesap-counters .counters-press{cursor:pointer;outline:none}
|
|
180
|
+
.hesap-counters rect.counters-press:not(.counters-tray){fill:transparent}
|
|
181
|
+
.hesap-counters .counters-press:focus-visible{stroke:var(--accent);stroke-width:3}
|
|
182
|
+
|
|
183
|
+
@media (max-width:900px){
|
|
184
|
+
/* The figure ends above the peek card, which covers the foot of the stage until the reader closes it. */
|
|
185
|
+
.hesap-counters .counters-svg{height:calc(100% - var(--hesap-peek,0px))}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* The count scene: the places objects lie in, the objects, and the numbers the reader gives them. */
|
|
189
|
+
.hesap-counters .counters-sand{fill:#e8d3a6;stroke:#c9ad78;stroke-width:2}
|
|
190
|
+
.hesap-counters .counters-table{fill:#b98a5a;stroke:#8a6238;stroke-width:2}
|
|
191
|
+
.hesap-counters .counters-awning-0{fill:#d1453b}
|
|
192
|
+
.hesap-counters .counters-awning-1{fill:#f4ede1}
|
|
193
|
+
.hesap-counters .counters-wire{fill:none;stroke:var(--ink);stroke-width:2.5}
|
|
194
|
+
.hesap-counters .counters-pole{stroke:var(--ink-2);stroke-width:6;stroke-linecap:round}
|
|
195
|
+
.hesap-counters .counters-row-label{font-size:16px;font-weight:700;fill:var(--ink-2)}
|
|
196
|
+
.hesap-counters .counters-stem{fill:none;stroke:#6b4a2b;stroke-width:2.5;stroke-linecap:round}
|
|
197
|
+
.hesap-counters .counters-leaf{fill:#3f9a4a}
|
|
198
|
+
.hesap-counters .counters-apple .counters-shine{fill:#fff;opacity:.45}
|
|
199
|
+
.hesap-counters .counters-bird .counters-body{fill:var(--ink-2)}
|
|
200
|
+
.hesap-counters .counters-eye{fill:var(--paper)}
|
|
201
|
+
.hesap-counters .counters-feet{stroke:#d99a1f;stroke-width:2}
|
|
202
|
+
.hesap-counters .counters-trail{fill:none;stroke:var(--accent);stroke-width:3;stroke-dasharray:7 6;stroke-linecap:round;stroke-linejoin:round;opacity:.8}
|
|
203
|
+
.hesap-counters .counters-shell .counters-body{fill:#f2a679;stroke:#c46a3c}
|
|
204
|
+
.hesap-counters .counters-ribs{stroke:#c46a3c;stroke-width:1.5;fill:none}
|
|
205
|
+
.hesap-counters .counters-skin{fill:#e0ac7e;stroke:var(--paper);stroke-width:1.5}
|
|
206
|
+
.hesap-counters .counters-legs{stroke:var(--ink);stroke-width:5;stroke-linecap:round}
|
|
207
|
+
.hesap-counters .counters-walker .counters-body{fill:var(--accent)}
|
|
208
|
+
.hesap-counters .counters-tag{pointer-events:none}
|
|
209
|
+
.hesap-counters .counters-tag-box{fill:var(--paper);stroke:var(--ink);stroke-width:1.5}
|
|
210
|
+
.hesap-counters .counters-tag-text{font-size:12px;font-weight:700}
|
|
211
|
+
.hesap-counters .counters-pale .counters-body{fill:var(--panel);stroke:var(--rule)}
|
|
212
|
+
.hesap-counters .counters-pale .counters-ring{display:none}
|
|
213
|
+
.hesap-counters .counters-marked .counters-body{stroke:var(--accent);stroke-width:3.5}
|
|
214
|
+
.hesap-counters .counters-gap{fill:none;stroke:var(--rule);stroke-width:2;stroke-dasharray:4 3;opacity:0;pointer-events:none;outline:none}
|
|
215
|
+
.hesap-counters .counters-gap-on{opacity:1;pointer-events:all;cursor:pointer}
|
|
216
|
+
.hesap-counters .counters-gap-on:focus-visible{stroke:var(--accent);stroke-width:3}
|
|
217
|
+
.hesap-counters g.counters-counter[role=button]{cursor:pointer;outline:none}
|
|
218
|
+
.hesap-counters g.counters-counter[role=button]:focus-visible .counters-hit{stroke:var(--accent);stroke-width:2.5}
|
|
219
|
+
|
|
220
|
+
/* The closed box, the room beside it, and the basket. */
|
|
221
|
+
.hesap-counters .counters-box{fill:#c99a62;stroke:#8a6238;stroke-width:2.5}
|
|
222
|
+
.hesap-counters .counters-lid{fill:#b5844e;stroke:#8a6238;stroke-width:2.5}
|
|
223
|
+
.hesap-counters .counters-tape{stroke:#e8d3a6;stroke-width:8}
|
|
224
|
+
.hesap-counters .counters-box-num{font-size:34px;font-weight:700;fill:#2b1d0e}
|
|
225
|
+
.hesap-counters .counters-box.counters-hot{stroke:var(--accent);stroke-width:4}
|
|
226
|
+
.hesap-counters .counters-beside{fill:none;stroke:var(--rule);stroke-width:2;stroke-dasharray:6 5}
|
|
227
|
+
.hesap-counters .counters-basket{fill:#c99a62;stroke:#8a6238;stroke-width:2.5}
|
|
228
|
+
.hesap-counters .counters-weave{stroke:#8a6238;stroke-width:1.5;opacity:.6}
|
|
229
|
+
.hesap-counters .counters-rim{fill:#b5844e;stroke:#8a6238;stroke-width:2}
|
|
230
|
+
|
|
231
|
+
/* The bus and its stop, and the staircase. */
|
|
232
|
+
.hesap-counters .counters-bus{fill:#d1453b;stroke:var(--ink);stroke-width:2.5}
|
|
233
|
+
.hesap-counters .counters-window,.hesap-counters .counters-glass-front{fill:#dfeaf5;stroke:var(--ink);stroke-width:1.5}
|
|
234
|
+
.hesap-counters .counters-door{fill:#9fb7cc;stroke:var(--ink);stroke-width:1.5}
|
|
235
|
+
.hesap-counters .counters-wheel{fill:var(--ink);stroke:var(--ink-2);stroke-width:5}
|
|
236
|
+
.hesap-counters .counters-stop{fill:#2e9d5b}
|
|
237
|
+
.hesap-counters .counters-stop-word{fill:#fff;font-size:12px;font-weight:700}
|
|
238
|
+
.hesap-counters .counters-kerb{stroke:var(--ink-2);stroke-width:3}
|
|
239
|
+
.hesap-counters .counters-stairs{fill:var(--panel);stroke:var(--ink-2);stroke-width:2;stroke-linejoin:round}
|
|
240
|
+
.hesap-counters .counters-step-num{font-size:11px;font-weight:600;fill:var(--ink-2)}
|
package/src/client.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Hesap's browser half. It is the shell every family draws in: it loads the family that owns a page's scene, gives
|
|
2
|
+
// it a stage and a panel, shows the story's cover on the overview and keeps the peek card clear of the panel.
|
|
3
|
+
import { fill } from 'hesap/kit/format.js';
|
|
4
|
+
import { tracker } from 'hesap/kit/motion.js';
|
|
5
|
+
|
|
6
|
+
window.KITAP_ENGINE = function hesap(host) {
|
|
7
|
+
const ENGINE = host.engine;
|
|
8
|
+
const root = document.createElement('div'); root.className = 'hesap'; host.el.map.appendChild(root);
|
|
9
|
+
const cover = document.createElement('img'); cover.className = 'hesap-cover'; cover.alt = ''; cover.hidden = true; root.appendChild(cover);
|
|
10
|
+
host.el.legendButton.hidden = true; host.el.legend.hidden = true; host.el.view.hidden = true;
|
|
11
|
+
const sheet = document.createElement('link'); sheet.rel = 'stylesheet'; sheet.href = import.meta.resolve('katex-dist/katex.min.css'); document.head.appendChild(sheet);
|
|
12
|
+
const style = document.documentElement.style, peek = document.getElementById('peek');
|
|
13
|
+
// loaded holds each family once its module has arrived. now is the family on show, and turn counts the pages
|
|
14
|
+
// shown, so a family that arrives late does not draw a page the reader has left.
|
|
15
|
+
const loaded = new Map(), loading = new Map();
|
|
16
|
+
let now = null, turn = 0, page = null;
|
|
17
|
+
|
|
18
|
+
// The peek card stands clear of the panel, and a figure stays clear of the peek card.
|
|
19
|
+
const sizes = new ResizeObserver(() => { if (now) style.setProperty('--hesap-panel', `${now.panel.hidden ? 0 : now.panel.offsetHeight}px`); room(); });
|
|
20
|
+
function room() { const p = host.padding(); style.setProperty('--hesap-peek', `${typeof p === 'number' ? 0 : p.bottom}px`); }
|
|
21
|
+
if (peek) { sizes.observe(peek); new MutationObserver(room).observe(peek, { attributes: true, attributeFilter: ['hidden'] }); }
|
|
22
|
+
host.phone.addEventListener('change', room);
|
|
23
|
+
|
|
24
|
+
// The cover follows the screen: a story may hold a second cover for a dark screen.
|
|
25
|
+
const dark = matchMedia('(prefers-color-scheme: dark)');
|
|
26
|
+
function paint() { const src = dark.matches && host.B.coverDark ? host.B.coverDark : host.B.cover; if (src && !cover.hidden) cover.src = src; }
|
|
27
|
+
|
|
28
|
+
// A family gets a box of its own with a stage and a panel, and the strings under its own prefix. The box joins
|
|
29
|
+
// the page once the family is made, so a family that fails leaves nothing behind.
|
|
30
|
+
function make(id, module) {
|
|
31
|
+
const box = document.createElement('div'); box.className = `hesap-family hesap-${id}`; box.hidden = true;
|
|
32
|
+
const head = document.createElement('div'); head.className = 'hesap-head'; head.hidden = true;
|
|
33
|
+
const stage = document.createElement('div'); stage.className = 'hesap-stage';
|
|
34
|
+
const panel = document.createElement('div'); panel.className = 'hesap-panel';
|
|
35
|
+
box.append(head, stage, panel);
|
|
36
|
+
// T gives a string of the family, or a shared one of hesap, with its {places} filled. It gives undefined for a
|
|
37
|
+
// key with no string, so a family can ask for an optional one and fall back.
|
|
38
|
+
const T = (key, vars) => fill(host.T()[`${id}_${key}`] ?? host.T()[`hesap_${key}`], vars);
|
|
39
|
+
const api = { host, box, stage, panel, T, lang: () => host.lang(), moving: () => !host.reduced, motion: tracker(), data: host.B[ENGINE]?.[id] ?? {}, peek: () => { const p = host.padding(); return typeof p === 'number' ? 0 : p.bottom; } };
|
|
40
|
+
const fam = { id, box, head, stage, panel, api, ...module.default(api) };
|
|
41
|
+
root.appendChild(box); sizes.observe(panel);
|
|
42
|
+
// A family builds its panel again as it likes, and the readouts are lifted each time.
|
|
43
|
+
new MutationObserver(() => { if (now === fam) settle(fam); }).observe(panel, { childList: true });
|
|
44
|
+
new ResizeObserver(() => { if (now === fam) settle(fam); }).observe(box);
|
|
45
|
+
return fam;
|
|
46
|
+
}
|
|
47
|
+
// On a screen with room the readouts stand above the figure in large type, where the reader's eye is. On a
|
|
48
|
+
// phone they stay in the panel under it.
|
|
49
|
+
const ROOMY = { width: 700, height: 600 };
|
|
50
|
+
function lift(fam) {
|
|
51
|
+
const roomy = page?.id != null && fam.box.clientWidth >= ROOMY.width && fam.box.clientHeight >= ROOMY.height;
|
|
52
|
+
const fresh = fam.panel.querySelector(':scope > .hesap-out'), held = fam.head.firstElementChild;
|
|
53
|
+
if (roomy && fresh) fam.head.replaceChildren(fresh);
|
|
54
|
+
else if (!roomy && held) { fam.panel.appendChild(held); }
|
|
55
|
+
fam.head.hidden = !fam.head.childElementCount;
|
|
56
|
+
}
|
|
57
|
+
// settle puts the readouts in their place, then hides the panel of the overview and a panel with nothing in it.
|
|
58
|
+
function settle(fam) {
|
|
59
|
+
lift(fam);
|
|
60
|
+
fam.panel.hidden = page.id == null || !fam.panel.childElementCount;
|
|
61
|
+
style.setProperty('--hesap-panel', `${fam.panel.hidden ? 0 : fam.panel.offsetHeight}px`);
|
|
62
|
+
}
|
|
63
|
+
// A family that fails to load is tried again the next time one of its pages opens.
|
|
64
|
+
function load(id) {
|
|
65
|
+
if (!loading.has(id)) loading.set(id, import(`hesap/families/${id}/client.js`).then(m => { const f = make(id, m); loaded.set(id, f); return f; })
|
|
66
|
+
.catch(err => { loading.delete(id); console.error(`hesap: the family ${id} did not load`, err); return null; }));
|
|
67
|
+
return loading.get(id);
|
|
68
|
+
}
|
|
69
|
+
// guard runs a family's own code. A family that throws is taken off the stage, so the book keeps turning pages.
|
|
70
|
+
function guard(what, fn) {
|
|
71
|
+
try { return fn(); } catch (err) { console.error(`hesap: the family ${now?.id} failed in ${what} on page ${page?.id ?? 'overview'}`, err); leave(); }
|
|
72
|
+
}
|
|
73
|
+
// The line under the story's title says how this family's figures are moved.
|
|
74
|
+
function lead() { host.lead(now?.api.T('lead')); }
|
|
75
|
+
function leave() {
|
|
76
|
+
if (!now) return;
|
|
77
|
+
const fam = now; now = null;
|
|
78
|
+
fam.api.motion.stop(); fam.box.hidden = true;
|
|
79
|
+
try { fam.hide?.(); } catch (err) { console.error(`hesap: the family ${fam.id} failed in hide`, err); }
|
|
80
|
+
style.setProperty('--hesap-panel', '0px'); lead();
|
|
81
|
+
}
|
|
82
|
+
function enter(fam, spec) {
|
|
83
|
+
if (now !== fam) { leave(); now = fam; fam.box.hidden = false; }
|
|
84
|
+
fam.api.motion.stop();
|
|
85
|
+
guard('show', () => fam.show(spec, page));
|
|
86
|
+
if (now !== fam) return;
|
|
87
|
+
// A page that shows no readouts has nothing above its figure.
|
|
88
|
+
if (!fam.panel.querySelector(':scope > .hesap-out')) fam.head.replaceChildren();
|
|
89
|
+
settle(fam); room(); lead();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
show(p) {
|
|
94
|
+
page = p; turn++;
|
|
95
|
+
// The overview shows the story's cover, or the overview scene of a story that has none.
|
|
96
|
+
const spec = p[ENGINE]?.scene && !(p.id == null && host.B.cover) ? p[ENGINE] : null, mine = turn;
|
|
97
|
+
cover.hidden = !!spec || !host.B.cover;
|
|
98
|
+
if (!spec) { leave(); paint(); return; }
|
|
99
|
+
const fam = loaded.get(spec.family);
|
|
100
|
+
if (fam) return enter(fam, spec);
|
|
101
|
+
// The stage stays empty while a family loads, so the last page's figure does not stand beside this page's text.
|
|
102
|
+
leave();
|
|
103
|
+
load(spec.family).then(f => { if (f && mine === turn) enter(f, spec); });
|
|
104
|
+
},
|
|
105
|
+
point(id, on) { if (now?.point) guard('point', () => now.point(id, on)); },
|
|
106
|
+
lang() { if (now?.lang) guard('lang', () => now.lang()); lead(); },
|
|
107
|
+
theme() { paint(); if (now?.theme) guard('theme', () => now.theme()); },
|
|
108
|
+
escape() { if (now?.escape) guard('escape', () => now.escape()); },
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
dispatchEvent(new Event('kitap-engine'));
|