@altnovatrail/skill-map 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,6 @@
1
+ @altnovatrail/skill-map
2
+
3
+ The package embeds icons of Material Symbols, by Google, under the Apache License, Version 2.0,
4
+ the license in LICENSE: https://github.com/google/material-design-icons. They come from the npm
5
+ package @iconify-json/material-symbols 1.2.97, and the package holds only the icons of the
6
+ map's states, marks and holdings.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # skill-map
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/altnovatrail/skill-map/actions/workflows/ci.yml/badge.svg)](https://github.com/altnovatrail/skill-map/actions/workflows/ci.yml)
4
+ [![Release](https://github.com/altnovatrail/skill-map/actions/workflows/release.yml/badge.svg)](https://github.com/altnovatrail/skill-map/actions/workflows/release.yml)
5
+ [![CodeQL](https://github.com/altnovatrail/skill-map/actions/workflows/codeql.yml/badge.svg)](https://github.com/altnovatrail/skill-map/actions/workflows/codeql.yml)
6
+ [![Latest release](https://img.shields.io/github/v/release/altnovatrail/skill-map)](https://github.com/altnovatrail/skill-map/releases/latest)
7
+ [![TypeScript version](https://img.shields.io/github/package-json/dependency-version/altnovatrail/skill-map/dev/typescript)](package.json)
8
+ [![Coverage](https://codecov.io/gh/altnovatrail/skill-map/branch/main/graph/badge.svg)](https://codecov.io/gh/altnovatrail/skill-map)
9
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/altnovatrail/skill-map/badge)](https://scorecard.dev/viewer/?uri=github.com/altnovatrail/skill-map)
10
+ [![License](https://img.shields.io/github/license/altnovatrail/skill-map)](LICENSE)
11
+
12
+ [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=altnovatrail_skill-map&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=altnovatrail_skill-map)
13
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=altnovatrail_skill-map&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=altnovatrail_skill-map)
14
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=altnovatrail_skill-map&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=altnovatrail_skill-map)
15
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=altnovatrail_skill-map&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=altnovatrail_skill-map)
16
+ [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=altnovatrail_skill-map&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=altnovatrail_skill-map)
17
+
18
+ The NovaTrail skill map: a UI package that draws a module's skill graph — its skills in tiers, linked by their prerequisites — and the learner model's state over it: what is mastered, what opens next and what each skill builds on. It draws from data that api has prepared and app hands it: it fetches nothing, computes no mastery and chooses no task, and when the learner picks a skill on the map, the engine chooses what comes next. It goes into app as a web component, built in at an exact version from npm, under `@altnovatrail`, and later site gets a build of its own.
19
+
20
+ A component of [NovaTrail](https://github.com/altnovatrail/spec/tree/v0.9.5), a universal open platform for adaptive learning, interactive lessons and AI tutoring. It belongs to stage 2, First slice with learners, with tutor, canvas, api, app and infra.
21
+
22
+ ## Status
23
+
24
+ Detailing done. The first epic of the plan, now in [docs/plan/E1.md](docs/plan/E1.md), decided what the component's card left open, and section 3 of [docs/architecture.md](docs/architecture.md) describes the package. The first code is the current epic, E2 of RUN.md: so far the element `<novatrail-skill-map>` of the package `@altnovatrail/skill-map` — its tree, its words in English and Russian, its icons and its look — with its tools and CI, and its first release, v0.1.0. Inside the devcontainer, `just ci` runs the four checks CI runs — lint and types, the tests in Node and in Chromium with their coverage, advisories and licenses. `just release-files v0.1.0` writes the files a release would hold into `dist/` — the package's archive at that version, checked as a consumer takes it, `LICENSE` and `SHA256SUMS` — and a release comes out by itself after CI passes on `main`, when a path it is built from has changed: the package's archive, with its NOTICE, LICENSE and their sums, built, signed and checked by .github's shared release. The same archive goes to npm: the first version, v0.1.0, by hand, and the later ones by the release's own npm step, through trusted publishing, with no long-lived token. A pull request from a branch of this repository tries the release and publishes nothing.
25
+
26
+ To try the map by hand, `just demo` serves a page at http://127.0.0.1:5173, which VS Code forwards to a browser outside the container. It draws the tests' example, a graph of eight tiers, the modules of the first slice and spec's vectors of tiers, with switches for the view, the language, the state, the theme and the width. For a tablet, `just demo-build` writes the same page into `demo/dist/`, with the graphs inside it, and any server of files on your network serves that folder — for one, `python3 -m http.server -d demo/dist` on your computer. A browser loads no modules from `file://`.
27
+
28
+ ## Theme and accessibility
29
+
30
+ The map holds the standard of NovaTrail's packages of the interface: WCAG 2.2 AA, with targets of 44 by 44 CSS pixels and no motion triggered by interaction, as R90 spec decides. A consumer fits it to its theme by three custom properties, which the element's shadow tree inherits; their defaults are light:
31
+
32
+ | Property | What | Default |
33
+ |---|---|---|
34
+ | `--novatrail-skill-map-paper` | the ground of the map, its tiles and the details | `#fff` |
35
+ | `--novatrail-skill-map-ink` | text, frames and icons | `#111` |
36
+ | `--novatrail-skill-map-accent` | the expanded tile, the frames of the tiles linked to it and of the details, the button that chooses a skill, the ring of the focus | `#1d4ed8` |
37
+
38
+ The contrast of a theme the consumer sets is the consumer's to check. With forced colours the system's colours stand in for the theme. The map's own words are in English and Russian, by the element's attribute `lang`, and English for any other language. What the package does not meet yet is declared in section 3.8 of [docs/architecture.md](docs/architecture.md): nothing so far. The icons are Material Symbols, by Google, under the Apache License 2.0, as [NOTICE](NOTICE) says.
39
+
40
+ ## Install
41
+
42
+ The app takes the package from npm at an exact version, and the packages of spec whose types the element's contract is in — the module format's `@altnovatrail/spec`, at the version the package has in its `dependencies`, and the contracts' `@altnovatrail/contracts`, the app's own, at the same version:
43
+
44
+ ```sh
45
+ npm install --save-exact @altnovatrail/skill-map@<version>
46
+ npm install --save-exact --save-dev @altnovatrail/spec@<its version>
47
+ ```
48
+
49
+ A pull request that changes the lock file has spec's recipe check it, as NovaTrail's rules ask of every package of `@altnovatrail`: `just -f spec/justfile release-verify-npm package-lock.json`, from a checkout of spec at a tag. It takes the archive from the registry only if it is the same bytes as the file of skill-map's release, signed by .github's shared release at the call of skill-map's `release.yml` on `main`.
50
+
51
+ ## Documents
52
+
53
+ The documents are in Russian.
54
+
55
+ - [docs/architecture.md](docs/architecture.md) — the component: what it does and does not do, its data and links, what was left to decide and is now decided or deferred on purpose, and how the package is built.
56
+ - [docs/decisions.md](docs/decisions.md) — the decision log: what was decided, why, and what was rejected.
57
+ - [RUN.md](RUN.md) — the work plan, in epics.
58
+
59
+ The working rules, for people and coding agents alike, are in [CLAUDE.md](CLAUDE.md) and [AGENTS.md](AGENTS.md). The platform's shared vocabulary, formats, contracts and decisions are in [spec](https://github.com/altnovatrail/spec/tree/v0.9.5), checked out here as a git submodule at `v0.9.5`: clone this repository with `git clone --recurse-submodules`.
60
+
61
+ ## License
62
+
63
+ [Apache-2.0](LICENSE).
@@ -0,0 +1,18 @@
1
+ /** The view of the map: the learner's or the adult's (R03). */
2
+ export type View = "learner" | "adult";
3
+ /**
4
+ * The view an attribute `view` names, or null without it or with another value: then the map has
5
+ * neither the choice nor the adult's details, so a mistake of the consumer opens no choice (R04).
6
+ */
7
+ export declare function viewOf(attribute: string | null): View | null;
8
+ /** The level of the bands' headings an attribute `heading-level` names: 2 to 6, and otherwise 3. */
9
+ export declare function headingLevel(attribute: string | null): 2 | 3 | 4 | 5 | 6;
10
+ /**
11
+ * The language of the map's own words an attribute `lang` names, of the languages the package
12
+ * has: the tag is cut from its end, a subtag at a time, until a language matches, as the lookup of
13
+ * RFC 4647, section 3.4, does; a single letter, `x` or an extension's, goes with what follows it.
14
+ * Case does not count. Without the attribute, or with no language of the package in it, null: the
15
+ * map then speaks English (R91 spec; architecture 6 spec). The element reads no ancestor's
16
+ * language (R36 spec).
17
+ */
18
+ export declare function languageOf(attribute: string | null, known: ReadonlySet<string>): string | null;
@@ -0,0 +1,44 @@
1
+ // The element's attributes, read as R04 says (docs/architecture.md, section 3.3). A value the
2
+ // contract does not name falls back to what keeps the map safe: no view, the level of headings 3.
3
+ /**
4
+ * The view an attribute `view` names, or null without it or with another value: then the map has
5
+ * neither the choice nor the adult's details, so a mistake of the consumer opens no choice (R04).
6
+ */
7
+ export function viewOf(attribute) {
8
+ return attribute === "learner" || attribute === "adult" ? attribute : null;
9
+ }
10
+ /** The level of the bands' headings an attribute `heading-level` names: 2 to 6, and otherwise 3. */
11
+ export function headingLevel(attribute) {
12
+ switch (attribute) {
13
+ case "2":
14
+ return 2;
15
+ case "4":
16
+ return 4;
17
+ case "5":
18
+ return 5;
19
+ case "6":
20
+ return 6;
21
+ default:
22
+ return 3;
23
+ }
24
+ }
25
+ /**
26
+ * The language of the map's own words an attribute `lang` names, of the languages the package
27
+ * has: the tag is cut from its end, a subtag at a time, until a language matches, as the lookup of
28
+ * RFC 4647, section 3.4, does; a single letter, `x` or an extension's, goes with what follows it.
29
+ * Case does not count. Without the attribute, or with no language of the package in it, null: the
30
+ * map then speaks English (R91 spec; architecture 6 spec). The element reads no ancestor's
31
+ * language (R36 spec).
32
+ */
33
+ export function languageOf(attribute, known) {
34
+ let range = (attribute ?? "").trim().toLowerCase();
35
+ while (range !== "") {
36
+ if (known.has(range))
37
+ return range;
38
+ let cut = range.lastIndexOf("-");
39
+ if (cut >= 2 && range[cut - 2] === "-")
40
+ cut -= 2;
41
+ range = cut > 0 ? range.slice(0, cut) : "";
42
+ }
43
+ return null;
44
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The full ID of a skill, as ChooseNext takes it in its field `skill`: the module's ID, `skill` and
3
+ * the skill's ID in the module, joined by `/` — `example/fair-shares/skill/halves` (R04; the
4
+ * format's text, section 10).
5
+ */
6
+ export declare function fullSkillId(moduleId: string, skillId: string): string;
7
+ export * from "./attributes.js";
8
+ export * from "./layout.js";
9
+ export * from "./lines.js";
10
+ export * from "./states.js";
@@ -0,0 +1,15 @@
1
+ // The DOM-free part of the skill map: the rules the element draws by, the same in a browser and in
2
+ // Node (R08 in docs/decisions.md). It is no entry point of the package: the element is the one
3
+ // contract with app (R04), and this part is what it is built from.
4
+ /**
5
+ * The full ID of a skill, as ChooseNext takes it in its field `skill`: the module's ID, `skill` and
6
+ * the skill's ID in the module, joined by `/` — `example/fair-shares/skill/halves` (R04; the
7
+ * format's text, section 10).
8
+ */
9
+ export function fullSkillId(moduleId, skillId) {
10
+ return `${moduleId}/skill/${skillId}`;
11
+ }
12
+ export * from "./attributes.js";
13
+ export * from "./layout.js";
14
+ export * from "./lines.js";
15
+ export * from "./states.js";
@@ -0,0 +1,68 @@
1
+ import type { SkillGraph } from "@altnovatrail/spec/formatv0/open";
2
+ /** A band of the map, top to bottom: the anchor skills before tier 1, then each tier. */
3
+ export type Band = AnchorBand | TierBand;
4
+ /** The band of the anchor skills that skills of the module have as prerequisites. */
5
+ export interface AnchorBand {
6
+ readonly kind: "anchors";
7
+ /** The anchor skills, by ID. */
8
+ readonly skills: readonly string[];
9
+ }
10
+ /** The band of a tier. Its heading is the tier's word, its number and its name, if it has one. */
11
+ export interface TierBand {
12
+ readonly kind: "tier";
13
+ /** The tier's number, from 1. */
14
+ readonly tier: number;
15
+ /** The tier's name from the graph's `tiers`, in the explanation language; null if it has none. */
16
+ readonly name: string | null;
17
+ /** The skills of the module in the tier, in their order in the band. */
18
+ readonly skills: readonly string[];
19
+ }
20
+ /** The layout of a map: its bands, top to bottom, and where each skill stands. */
21
+ export interface Layout {
22
+ readonly bands: readonly Band[];
23
+ /** Where each skill of the module and each anchor skill of the band stands. */
24
+ readonly places: ReadonlyMap<string, Place>;
25
+ }
26
+ /** Where a skill stands: its band, by its index in `bands`, and its place in it, from 0. */
27
+ export interface Place {
28
+ readonly band: number;
29
+ readonly index: number;
30
+ }
31
+ /**
32
+ * The bands of a map (R06). The anchor skills come first, only those that skills of the module on
33
+ * the map have as prerequisites, each by its ID; without any there is no such band. Then each tier with
34
+ * skills, in order. Tier 1 is ordered by ID; each band after it by the mean of the places of the
35
+ * skill's prerequisites among the module's skills, and by ID where those tie. Anchor skills give
36
+ * no place. IDs are compared by their code units, which for the IDs of the format are its
37
+ * characters. The order of the skills in the graph carries no meaning, and neither the state nor
38
+ * the expansion moves a tile.
39
+ *
40
+ * A skill of the graph without a tier, as `tiers` gives it, a whole number from 1, stands in no
41
+ * band: the tiers come from the same package as the graph (R99 spec), and the map does not work
42
+ * one out. One of a tier past 1 with no prerequisite among the module's skills, which the rule of
43
+ * tiers rules out (R49 spec), goes after those that have, by ID.
44
+ */
45
+ export declare function layout(graph: SkillGraph, tiers: Readonly<Record<string, number>>): Layout;
46
+ /** The links of an expanded skill to the tiles of the map, and what it teaches. */
47
+ export interface Links {
48
+ /** What it builds on: its prerequisites on the map, skills and anchor skills, in its order. */
49
+ readonly buildsOn: readonly string[];
50
+ /** What it opens: the skills on the map that have it as a prerequisite, in its order. */
51
+ readonly opens: readonly string[];
52
+ /** What it teaches: the anchor skills of its `teaches`, by ID. Empty for an anchor skill. */
53
+ readonly teaches: readonly string[];
54
+ }
55
+ /**
56
+ * The links of a skill of the module, or of an anchor skill, that is expanded (R06). Its tiles
57
+ * get the labels: «нужен раньше» on each it builds on, «откроется после» on each it opens. A link
58
+ * goes only to a tile of the map: a skill that stands in no band has none.
59
+ */
60
+ export declare function linksOf(graph: SkillGraph, map: Layout, id: string): Links;
61
+ /**
62
+ * The tile the focus goes to when the node it was on is gone with new data — the tile, or the
63
+ * button «Заниматься» that «ждёт» replaced (the second amendment of 2026-11-07 to R04): the tile of
64
+ * the same skill; without it, the first tile of the band the skill stood in; without that, the
65
+ * first tile of the map. Null when the map has no tile. A band is the same when it is the band of
66
+ * the anchor skills, or the band of the same tier.
67
+ */
68
+ export declare function focusAfter(before: Layout, after: Layout, skill: string): string | null;
@@ -0,0 +1,109 @@
1
+ // The layout of the map (R06; docs/architecture.md, section 3.4): which band each skill stands in,
2
+ // its place in the band, the links of an expanded skill, and where the focus goes when its node is
3
+ // gone. The tiers come ready from module-kit through api (R49 spec, R62 spec): the map orders the
4
+ // skills within them and never works a tier out.
5
+ /**
6
+ * The bands of a map (R06). The anchor skills come first, only those that skills of the module on
7
+ * the map have as prerequisites, each by its ID; without any there is no such band. Then each tier with
8
+ * skills, in order. Tier 1 is ordered by ID; each band after it by the mean of the places of the
9
+ * skill's prerequisites among the module's skills, and by ID where those tie. Anchor skills give
10
+ * no place. IDs are compared by their code units, which for the IDs of the format are its
11
+ * characters. The order of the skills in the graph carries no meaning, and neither the state nor
12
+ * the expansion moves a tile.
13
+ *
14
+ * A skill of the graph without a tier, as `tiers` gives it, a whole number from 1, stands in no
15
+ * band: the tiers come from the same package as the graph (R99 spec), and the map does not work
16
+ * one out. One of a tier past 1 with no prerequisite among the module's skills, which the rule of
17
+ * tiers rules out (R49 spec), goes after those that have, by ID.
18
+ */
19
+ export function layout(graph, tiers) {
20
+ const prerequisitesOf = (id) => graph.skills[id]?.prerequisites ?? [];
21
+ const byTier = new Map();
22
+ for (const id of Object.keys(graph.skills)) {
23
+ const tier = Object.hasOwn(tiers, id) ? tiers[id] : undefined;
24
+ if (tier === undefined || !Number.isInteger(tier) || tier < 1)
25
+ continue;
26
+ byTier.set(tier, [...(byTier.get(tier) ?? []), id]);
27
+ }
28
+ const onMap = [...byTier.values()].flat();
29
+ const bands = [];
30
+ const places = new Map();
31
+ const push = (band) => {
32
+ band.skills.forEach((id, index) => {
33
+ places.set(id, { band: bands.length, index });
34
+ });
35
+ bands.push(band);
36
+ };
37
+ const anchors = new Set(onMap.flatMap(prerequisitesOf).filter((id) => !Object.hasOwn(graph.skills, id)));
38
+ if (anchors.size > 0)
39
+ push({ kind: "anchors", skills: [...anchors].sort(byCodeUnits) });
40
+ for (const [tier, members] of [...byTier].sort(([a], [b]) => a - b)) {
41
+ const keyed = members.map((id) => {
42
+ // Only the module's skills already laid out have a place in a tier's band: anchor skills,
43
+ // in theirs, give none.
44
+ const ofModule = (place) => place !== undefined && bands[place.band]?.kind === "tier";
45
+ const indices = prerequisitesOf(id)
46
+ .map((prerequisite) => places.get(prerequisite))
47
+ .filter(ofModule)
48
+ .map((place) => place.index);
49
+ const mean = tier === 1
50
+ ? 0
51
+ : indices.length === 0
52
+ ? Number.POSITIVE_INFINITY
53
+ : indices.reduce((sum, index) => sum + index, 0) / indices.length;
54
+ return { id, mean };
55
+ });
56
+ keyed.sort((a, b) => a.mean - b.mean || byCodeUnits(a.id, b.id));
57
+ const skills = keyed.map(({ id }) => id);
58
+ push({ kind: "tier", tier, name: graph.tiers?.[tier - 1] ?? null, skills });
59
+ }
60
+ return { bands, places };
61
+ }
62
+ /**
63
+ * The links of a skill of the module, or of an anchor skill, that is expanded (R06). Its tiles
64
+ * get the labels: «нужен раньше» on each it builds on, «откроется после» on each it opens. A link
65
+ * goes only to a tile of the map: a skill that stands in no band has none.
66
+ */
67
+ export function linksOf(graph, map, id) {
68
+ const inOrder = (list) => list
69
+ .flatMap((other) => {
70
+ const place = map.places.get(other);
71
+ return place === undefined ? [] : [{ other, place }];
72
+ })
73
+ .sort((a, b) => a.place.band - b.place.band || a.place.index - b.place.index)
74
+ .map(({ other }) => other);
75
+ const skill = Object.hasOwn(graph.skills, id) ? graph.skills[id] : undefined;
76
+ const opens = Object.entries(graph.skills)
77
+ .filter(([, other]) => (other.prerequisites ?? []).includes(id))
78
+ .map(([other]) => other);
79
+ return {
80
+ buildsOn: inOrder(skill?.prerequisites ?? []),
81
+ opens: inOrder(opens),
82
+ teaches: [...(skill?.teaches ?? [])].sort(byCodeUnits),
83
+ };
84
+ }
85
+ /**
86
+ * The tile the focus goes to when the node it was on is gone with new data — the tile, or the
87
+ * button «Заниматься» that «ждёт» replaced (the second amendment of 2026-11-07 to R04): the tile of
88
+ * the same skill; without it, the first tile of the band the skill stood in; without that, the
89
+ * first tile of the map. Null when the map has no tile. A band is the same when it is the band of
90
+ * the anchor skills, or the band of the same tier.
91
+ */
92
+ export function focusAfter(before, after, skill) {
93
+ if (after.places.has(skill))
94
+ return skill;
95
+ const place = before.places.get(skill);
96
+ const band = place === undefined ? undefined : before.bands[place.band];
97
+ // No band of a layout is empty.
98
+ const same = band === undefined ? undefined : after.bands.find((other) => sameBand(band, other));
99
+ return same?.skills[0] ?? after.bands[0]?.skills[0] ?? null;
100
+ }
101
+ function sameBand(a, b) {
102
+ if (a.kind === "anchors" || b.kind === "anchors")
103
+ return a.kind === b.kind;
104
+ return a.tier === b.tier;
105
+ }
106
+ /** Two IDs by their code units. */
107
+ function byCodeUnits(a, b) {
108
+ return Number(a > b) - Number(a < b);
109
+ }
@@ -0,0 +1,29 @@
1
+ import type { Links } from "./layout.js";
2
+ /** A box of the map, in CSS pixels from the map's top left corner. */
3
+ export interface Box {
4
+ readonly left: number;
5
+ readonly top: number;
6
+ readonly right: number;
7
+ readonly bottom: number;
8
+ }
9
+ /** A point of the map. */
10
+ export interface Point {
11
+ readonly x: number;
12
+ readonly y: number;
13
+ }
14
+ /** A line between two tiles: the skills it links, its ends, and its path in SVG. */
15
+ export interface Line {
16
+ readonly from: string;
17
+ readonly to: string;
18
+ readonly start: Point;
19
+ readonly end: Point;
20
+ readonly d: string;
21
+ }
22
+ /** The cubic curve from one point down to another: both ends leave and come in upright. */
23
+ export declare function curve(start: Point, end: Point): string;
24
+ /**
25
+ * The lines of the expanded skill: one from each tile it builds on, into its tile's top edge, and
26
+ * one to each tile it opens, out of its details' bottom edge, in the order of the links. A skill
27
+ * whose tile has no box has no line, and without the expanded tile's box there is none.
28
+ */
29
+ export declare function linesOf(expanded: string, links: Links, boxes: ReadonlyMap<string, Box>, details: Box): Line[];
@@ -0,0 +1,55 @@
1
+ // The lines of the expanded skill (R06; R11 in docs/decisions.md; docs/architecture.md, section 3.4):
2
+ // where each starts and ends, and the curve between, from the boxes the element measured. Each
3
+ // line goes down: from the bottom edge of a prerequisite's tile into the top edge of the expanded
4
+ // tile, and from the bottom edge of the details into the top edge of each tile the skill opens.
5
+ // The ends on the expanded tile and on its details are spread across the tile's width, in the order
6
+ // of the other ends from left to right, so that their points do not fall on one another and the
7
+ // lines do not cross for nothing. Each point is rounded to a tenth of a CSS pixel, as its curve is. A line is a cubic curve,
8
+ // leaving its start straight down and coming into its end straight down.
9
+ /** A number of the drawing, to a tenth of a CSS pixel. */
10
+ const tenth = (value) => Math.round(value * 10) / 10;
11
+ /** A point to a tenth of a CSS pixel. */
12
+ const rounded = ({ x, y }) => ({ x: tenth(x), y: tenth(y) });
13
+ /** The cubic curve from one point down to another: both ends leave and come in upright. */
14
+ export function curve(start, end) {
15
+ const middle = tenth((start.y + end.y) / 2);
16
+ const [sx, sy, ex, ey] = [start.x, start.y, end.x, end.y].map(tenth);
17
+ return `M${sx} ${sy}C${sx} ${middle} ${ex} ${middle} ${ex} ${ey}`;
18
+ }
19
+ /** The middle of a box's bottom edge, and of its top edge. */
20
+ const bottomOf = (box) => ({ x: (box.left + box.right) / 2, y: box.bottom });
21
+ const topOf = (box) => ({ x: (box.left + box.right) / 2, y: box.top });
22
+ /** The i-th of n points spread across a box's width, at the height given. */
23
+ const spread = (box, i, n, y) => ({
24
+ x: box.left + ((box.right - box.left) * (i + 1)) / (n + 1),
25
+ y,
26
+ });
27
+ /**
28
+ * The lines of the expanded skill: one from each tile it builds on, into its tile's top edge, and
29
+ * one to each tile it opens, out of its details' bottom edge, in the order of the links. A skill
30
+ * whose tile has no box has no line, and without the expanded tile's box there is none.
31
+ */
32
+ export function linesOf(expanded, links, boxes, details) {
33
+ const tile = boxes.get(expanded);
34
+ if (tile === undefined)
35
+ return [];
36
+ const line = (from, to, start, end) => ({
37
+ from,
38
+ to,
39
+ start: rounded(start),
40
+ end: rounded(end),
41
+ d: curve(start, end),
42
+ });
43
+ /** The skills with a box, and the place of each among them from left to right. */
44
+ const ranked = (ids, end) => {
45
+ const placed = ids.filter((id) => boxes.has(id));
46
+ const order = [...placed].sort((a, b) => end(boxes.get(a)).x - end(boxes.get(b)).x);
47
+ return placed.map((id) => ({ id, box: boxes.get(id), rank: order.indexOf(id) }));
48
+ };
49
+ const into = ranked(links.buildsOn, bottomOf);
50
+ const out = ranked(links.opens, topOf);
51
+ return [
52
+ ...into.map(({ id, box, rank }) => line(id, expanded, bottomOf(box), spread(tile, rank, into.length, tile.top))),
53
+ ...out.map(({ id, box, rank }) => line(expanded, id, spread(tile, rank, out.length, details.bottom), topOf(box))),
54
+ ];
55
+ }