@altnovatrail/canvas 0.3.13 → 0.3.14
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/README.md +3 -3
- package/lib/element/index.js +31 -25
- package/lib/element/labels.d.ts +18 -4
- package/lib/element/labels.js +27 -1
- package/lib/element/parts.d.ts +15 -1
- package/lib/element/parts.js +42 -24
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
|
|
18
18
|
The NovaTrail canvases. A canvas is the workplace of a task, where the learner writes, draws and types; this UI package holds the canvas kinds — for now two, the handwriting sheet and the workbook — with their layers and tools, captures the learner's strokes with time and pressure, draws the picture of the work that goes to be checked and shows the tutor's marks tied to the learner's strokes, and the app builds it in at an exact version. A separate build of it is the samples page, where adult volunteers make samples for eval on the same canvas that learners use: a sample is saved as a file on the volunteer's device and reaches a module's eval set by pull request, and nothing goes to the platform's server. The same page opens a sample file to be looked at — its strokes, what a history erased too, its crops and its markup — so that a person, not an AI, looks in it for a name or a contact before it goes on.
|
|
19
19
|
|
|
20
|
-
A component of [NovaTrail](https://github.com/altnovatrail/spec/tree/v0.15.
|
|
20
|
+
A component of [NovaTrail](https://github.com/altnovatrail/spec/tree/v0.15.1), a universal open platform for adaptive learning, interactive lessons and AI tutoring. It belongs to stage 2, First slice with learners, with tutor, api, app, skill-map and infra; with tutor it is the stage's first code: first the handwriting sheet, while the samples page waits until a measurement needs volunteers' or children's samples.
|
|
21
21
|
|
|
22
22
|
## Status
|
|
23
23
|
|
|
24
|
-
Code started. The detailing is done — epic E1, archived in [docs/plan/E1.md](docs/plan/E1.md). Epic E2, replanned for the MVP on 2026-10-22, built the handwriting sheet as the element `<novatrail-canvas>`, for tutor's check board to take in place of its own sheet; the board has decided to keep its own. Its last task was the author's try of the sheet by hand on the demo page, which found nothing to fix. E2 is done and archived in [docs/plan/E2.md](docs/plan/E2.md). The text canvas, epic E3, was dropped on 2026-10-25: canvas builds no text canvas. Epic E4, taken the same day, built the sheet for the product: the eraser and the history of writing, the layers and the grid, the groups of strokes and the crop for checking, the tutor's marks tied to the strokes, the package's full interface and the input on tablets. It was done on 2026-10-26 and is archived in [docs/plan/E4.md](docs/plan/E4.md). Epic E6, taken the same day, detailed and built the workbook, the first slice's second canvas kind, for school maths in grade 3, and was done on 2026-10-27; it is archived in [docs/plan/E6.md](docs/plan/E6.md). Epic E7, taken the same day, took what spec v0.2.42 brought: the task's new open fields, the exit condition that every answer slot holds something — `filled` on a sheet too — and the lesson's worked example, shown on a sheet the learner does not write on. On the way canvas moved to spec v0.4.1, whose npm package gives the types of the module format. E7 was done on 2026-11-01 and is archived in [docs/plan/E7.md](docs/plan/E7.md). Epic E8, taken the same day, is the first release of the package, which spec's cross-repository plan asks for before the app's code; the tests' coverage and the release's build come first. Then canvas moved to spec v0.6.2, of spec's 0.6 line, and its CI now checks the signature of each package of `@altnovatrail` in its lock file, as spec's rules ask; then the element took the module format 0.2 and the types of its contract with the app from spec's npm package, and the package came out in its first release, v0.1.0; from the next one on, the release puts it in npm itself. E8 was done on 2026-11-02 and is archived in [docs/plan/E8.md](docs/plan/E8.md). The same day canvas moved to spec v0.6.5, which made the `media` property part of the element's contract with the app and gave the buttons of every NovaTrail interface package one set of icons, and epic E5, the samples page, was taken: first trying a build opened from a file on the devices and building the page. On 2026-11-08 canvas moved to spec v0.9.8, whose eval protocol now holds the sample file, its markup and the rules the sheet shares with tutor's eval runner — the groups of strokes, the crop, the snapping of a model's box and a workbook's boxes: the tests hold the sheet's code to spec's test vectors of those rules, and the types of the tutor's marks are spec's too. The same day it moved on to v0.9.9, which answers canvas's last two open questions and changes nothing in its code. On 2026-11-09 it moved to spec v0.12.0, whose module format 0.4 lays a workbook's page out by numbers and test vectors of spec's own, which were canvas's, and lets a lesson's worked example stand on a workbook, its demo filling the boxes. Then epic E5 built the samples page and the synthetic samples that tutor's CI reads, and was done on 2026-11-10; it is archived in [docs/plan/E5.md](docs/plan/E5.md). Every release of canvas since v0.3.4 carries the page's build and the synthetic samples. The same day canvas moved to spec v0.14.0, whose legal part holds the sets of texts the page is to take, and epic E10 was taken: the standard of UI packages, the accessibility and the translations of the element. On 2026-11-11 the page took the tasks of modules for a module's eval set, and canvas moved to spec v0.15.0, whose sets of the measurement and of the eval set are in force: the page opens both to adults whose form the organiser accepted. So far there is the package, `@altnovatrail/canvas`, with its tools and the sheet's input: the element takes a pen, a finger or a mouse, one pointer at a time, and draws the strokes, and its methods `undo()` and `clear()` undo the last action and clear the sheet. Its eraser, E4's first task, takes strokes off whole along the path of a press: the element's `tool` switches to it, and a pen's eraser erases whatever the tool, if the task allows the eraser. The sheet keeps the history of writing — every stroke, erasing, clearing and undo, at the sheet's time — for the app to keep. The sheet is a stack of layers, in the order of spec's canvas layers: its task, the element's `task` property, rules it in squares, lines or dots, and the task's statement stands above the sheet, its pictures from the consumer's `media`. The task and the module's manifest come in the types of spec's npm package, `@altnovatrail/spec`; the element reads the module format 0.4, which spec v0.10.0 brought — a manifest of another version, 0.3 too, is a TypeError — and the task is checked as its schema checks it, a field it does not know a TypeError; what the statement gives and asks, the fields `givens` and `unknown`, the element takes and leaves for the app to show; a workbook's task the element shows too: its lines laid out on a page the size of the sheet — numbers, text fitted to the layout's own widths, and boxes, up to ten rows — which a screen reader reads as a list. On a workbook each stroke falls in one box or in none, by a rule in integers on the middle of its points' box; what falls in no box is draft, which stays on the page and goes to no check, and the property `filled` tells which boxes hold writing, and on a sheet whether its one answer anywhere on it, or the whole sheet, does. The module's manifest, the `manifest` property, gives the height of a digit on the crop, 24 px unless it gives another, as without a manifest, and the language of the statement. The sheet fits the element's width, at most 1000 CSS pixels, and the row's Zoom in and Zoom out make it larger, up to twice that, on every sheet of the page till it is loaded again, so that a workbook's printed lines can be read at 200 %; a zoomed sheet scrolls across as well as down, with the row's Left and Right, two fingers and the arrow keys, while the statement stays as wide as the fit. The consumer themes it by custom properties. The DOM-free part parts the strokes into groups by place and time — two strokes no more than 2 seconds apart whose boxes come within a cell of each other are neighbours, and a chain of neighbours is a group — labels the groups A, B, C… by place and gives each one's rectangle on the sheet, for the crop, the tutor's marks and the samples to come; the rule's test vectors are a proposal for the eval protocol. It also draws the crop for checking, with its own raster and PNG encoder: the ink of the visible strokes, scaled so that the writing comes out at the digit height the module's manifest asks for, within the size every Claude model takes as it is, with the groups' frames in its fractions. Its test vectors go to the eval protocol too. The element takes the tutor's marks of a submission back by its property `marks`, with the context it is to give with the crop: a mark holds on to the learner's strokes — a group's, or those a model's box on the crop takes, two thirds of their points within a quarter of a digit of it — and a frame stands round those of them the sheet shows, over the work, read by its name and fading while the learner writes into it. The history goes out by the property `history` and the event `historychange`, which tells of every action with the events it adds, and comes back by the same property: the same history changes nothing, and another, one the sheet could have written, replaces the sheet, undo and all. The pictures' files come from the consumer's `media`, a function that gives a file's Blob by its reference, the contract's own. `exportWork()` gives the work for checking: the PNG of the crop and the context of its submission, which the app keeps and gives back with the tutor's marks, its digest telling the sheet's own context from another sheet's. On a workbook it gives the crop of each filled box, with its item and slot, and the context of the table of boxes; a tutor's mark there stands on an answer cell by its place and frames the box with its ink. Above the statement and the sheet, outside their scrolling, stands the element's own row of buttons — the pen and the eraser the task allows, undo and clear — a toolbar worked by pointer and by keyboard, labelled in English or Russian by the element's own `lang`, each label after an icon of Material Symbols, Google's set, which the build embeds, so the element asks no network for one and the package's NOTICE names it; a `toolchange` event tells of the learner's choice of tool. On a tablet a pen's touch puts the whole page in pen mode, where a finger writes nothing until the row's Draw with finger lets it write again; a touch wider or taller than 100 CSS pixels is a palm and writes nothing, and two fingers scroll the sheet. The row's Up and Down scroll it the same way with a single pointer, on any device, by four fifths of what is in sight. An element whose content overflows it — of a height of its own, or with a zoomed sheet wider than it — scrolls as a region named by the canvas kind, which Tab goes into from the row and out of, and the keys scroll, in Safari too. What of spec's standard of UI packages, WCAG 2.2 AA with 2.5.5 and 2.3.3, the element does not meet yet — a workbook's printed lines keep their own text spacing (1.4.12); a value a demo writes in a box is spoken in the labels' language rather than the lines' (3.1.2); and without a `lang` of the labels' table on the element, the region's English name is spoken in the element's language (3.1.2) — section 3.10 of [docs/architecture.md](docs/architecture.md) names, with what stands instead and when it goes, for the app's Accessibility page. A lesson's worked example comes by the property `workedExample`, in place of a task: its statement stands above the sheet and its grid on it, but the learner does not write there — a finger or a pen scrolls the sheet as the browser scrolls the statement, and the row, named Worked example buttons, has Next, Demo, Up, Down and the zoom's buttons. Next opens the parts of the author's demo one at a time, into a numbered list above the sheet that a polite region tells a screen reader of, and Demo hides the whole demo and shows it again; the property `demoState` and the event `demochange` tell the app how far the learner has gone, and the app may give it back to a new element after the example — in React's JSX `workedExample` comes before `demoState`, and `ondemochange` listens. The pictures of the demo come from the consumer's `media` with the statement's, one file for each reference, all of them as the example comes, so that a part opened shows its picture at once; a picture on an area of the sheet stands on the sheet itself, stretched over its area, and the sheet scrolls to it as its part opens. The element now waits for the app, and the samples page is built on it; a test plays the app's part, and `just demo` serves a page to try the element on by hand. 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, and the same archive goes to npm: the first version by hand, 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.
|
|
24
|
+
Code started. The detailing is done — epic E1, archived in [docs/plan/E1.md](docs/plan/E1.md). Epic E2, replanned for the MVP on 2026-10-22, built the handwriting sheet as the element `<novatrail-canvas>`, for tutor's check board to take in place of its own sheet; the board has decided to keep its own. Its last task was the author's try of the sheet by hand on the demo page, which found nothing to fix. E2 is done and archived in [docs/plan/E2.md](docs/plan/E2.md). The text canvas, epic E3, was dropped on 2026-10-25: canvas builds no text canvas. Epic E4, taken the same day, built the sheet for the product: the eraser and the history of writing, the layers and the grid, the groups of strokes and the crop for checking, the tutor's marks tied to the strokes, the package's full interface and the input on tablets. It was done on 2026-10-26 and is archived in [docs/plan/E4.md](docs/plan/E4.md). Epic E6, taken the same day, detailed and built the workbook, the first slice's second canvas kind, for school maths in grade 3, and was done on 2026-10-27; it is archived in [docs/plan/E6.md](docs/plan/E6.md). Epic E7, taken the same day, took what spec v0.2.42 brought: the task's new open fields, the exit condition that every answer slot holds something — `filled` on a sheet too — and the lesson's worked example, shown on a sheet the learner does not write on. On the way canvas moved to spec v0.4.1, whose npm package gives the types of the module format. E7 was done on 2026-11-01 and is archived in [docs/plan/E7.md](docs/plan/E7.md). Epic E8, taken the same day, is the first release of the package, which spec's cross-repository plan asks for before the app's code; the tests' coverage and the release's build come first. Then canvas moved to spec v0.6.2, of spec's 0.6 line, and its CI now checks the signature of each package of `@altnovatrail` in its lock file, as spec's rules ask; then the element took the module format 0.2 and the types of its contract with the app from spec's npm package, and the package came out in its first release, v0.1.0; from the next one on, the release puts it in npm itself. E8 was done on 2026-11-02 and is archived in [docs/plan/E8.md](docs/plan/E8.md). The same day canvas moved to spec v0.6.5, which made the `media` property part of the element's contract with the app and gave the buttons of every NovaTrail interface package one set of icons, and epic E5, the samples page, was taken: first trying a build opened from a file on the devices and building the page. On 2026-11-08 canvas moved to spec v0.9.8, whose eval protocol now holds the sample file, its markup and the rules the sheet shares with tutor's eval runner — the groups of strokes, the crop, the snapping of a model's box and a workbook's boxes: the tests hold the sheet's code to spec's test vectors of those rules, and the types of the tutor's marks are spec's too. The same day it moved on to v0.9.9, which answers canvas's last two open questions and changes nothing in its code. On 2026-11-09 it moved to spec v0.12.0, whose module format 0.4 lays a workbook's page out by numbers and test vectors of spec's own, which were canvas's, and lets a lesson's worked example stand on a workbook, its demo filling the boxes. Then epic E5 built the samples page and the synthetic samples that tutor's CI reads, and was done on 2026-11-10; it is archived in [docs/plan/E5.md](docs/plan/E5.md). Every release of canvas since v0.3.4 carries the page's build and the synthetic samples. The same day canvas moved to spec v0.14.0, whose legal part holds the sets of texts the page is to take, and epic E10 was taken: the standard of UI packages, the accessibility and the translations of the element. On 2026-11-11 the page took the tasks of modules for a module's eval set, and canvas moved to spec v0.15.0, whose sets of the measurement and of the eval set are in force: the page opens both to adults whose form the organiser accepted. On 2026-11-12 canvas moved to spec v0.15.1, whose rule keeps one task to one session, with its hook in `.claude/settings.json`, and whose devcontainer takes Go 1.27.4. So far there is the package, `@altnovatrail/canvas`, with its tools and the sheet's input: the element takes a pen, a finger or a mouse, one pointer at a time, and draws the strokes, and its methods `undo()` and `clear()` undo the last action and clear the sheet. Its eraser, E4's first task, takes strokes off whole along the path of a press: the element's `tool` switches to it, and a pen's eraser erases whatever the tool, if the task allows the eraser. The sheet keeps the history of writing — every stroke, erasing, clearing and undo, at the sheet's time — for the app to keep. The sheet is a stack of layers, in the order of spec's canvas layers: its task, the element's `task` property, rules it in squares, lines or dots, and the task's statement stands above the sheet, its pictures from the consumer's `media`. The task and the module's manifest come in the types of spec's npm package, `@altnovatrail/spec`; the element reads the module format 0.4, which spec v0.10.0 brought — a manifest of another version, 0.3 too, is a TypeError — and the task is checked as its schema checks it, a field it does not know a TypeError; what the statement gives and asks, the fields `givens` and `unknown`, the element takes and leaves for the app to show; a workbook's task the element shows too: its lines laid out on a page the size of the sheet — numbers, text fitted to the layout's own widths, and boxes, up to ten rows — which a screen reader reads as a list. On a workbook each stroke falls in one box or in none, by a rule in integers on the middle of its points' box; what falls in no box is draft, which stays on the page and goes to no check, and the property `filled` tells which boxes hold writing, and on a sheet whether its one answer anywhere on it, or the whole sheet, does. The module's manifest, the `manifest` property, gives the height of a digit on the crop, 24 px unless it gives another, as without a manifest, and the language of the statement. The sheet fits the element's width, at most 1000 CSS pixels, and the row's Zoom in and Zoom out make it larger, up to twice that, on every sheet of the page till it is loaded again, so that a workbook's printed lines can be read at 200 %; a zoomed sheet scrolls across as well as down, with the row's Left and Right, two fingers and the arrow keys, while the statement stays as wide as the fit. The consumer themes it by custom properties. The DOM-free part parts the strokes into groups by place and time — two strokes no more than 2 seconds apart whose boxes come within a cell of each other are neighbours, and a chain of neighbours is a group — labels the groups A, B, C… by place and gives each one's rectangle on the sheet, for the crop, the tutor's marks and the samples to come; the rule's test vectors are a proposal for the eval protocol. It also draws the crop for checking, with its own raster and PNG encoder: the ink of the visible strokes, scaled so that the writing comes out at the digit height the module's manifest asks for, within the size every Claude model takes as it is, with the groups' frames in its fractions. Its test vectors go to the eval protocol too. The element takes the tutor's marks of a submission back by its property `marks`, with the context it is to give with the crop: a mark holds on to the learner's strokes — a group's, or those a model's box on the crop takes, two thirds of their points within a quarter of a digit of it — and a frame stands round those of them the sheet shows, over the work, read by its name and fading while the learner writes into it. The history goes out by the property `history` and the event `historychange`, which tells of every action with the events it adds, and comes back by the same property: the same history changes nothing, and another, one the sheet could have written, replaces the sheet, undo and all. The pictures' files come from the consumer's `media`, a function that gives a file's Blob by its reference, the contract's own. `exportWork()` gives the work for checking: the PNG of the crop and the context of its submission, which the app keeps and gives back with the tutor's marks, its digest telling the sheet's own context from another sheet's. On a workbook it gives the crop of each filled box, with its item and slot, and the context of the table of boxes; a tutor's mark there stands on an answer cell by its place and frames the box with its ink. Above the statement and the sheet, outside their scrolling, stands the element's own row of buttons — the pen and the eraser the task allows, undo and clear — a toolbar worked by pointer and by keyboard, labelled in English or Russian by the element's own `lang`, each label after an icon of Material Symbols, Google's set, which the build embeds, so the element asks no network for one and the package's NOTICE names it; a `toolchange` event tells of the learner's choice of tool. On a tablet a pen's touch puts the whole page in pen mode, where a finger writes nothing until the row's Draw with finger lets it write again; a touch wider or taller than 100 CSS pixels is a palm and writes nothing, and two fingers scroll the sheet. The row's Up and Down scroll it the same way with a single pointer, on any device, by four fifths of what is in sight. An element whose content overflows it — of a height of its own, or with a zoomed sheet wider than it — scrolls as a region named by the canvas kind, which Tab goes into from the row and out of, and the keys scroll, in Safari too. What of spec's standard of UI packages, WCAG 2.2 AA with 2.5.5 and 2.3.3, the element does not meet yet — a workbook's printed lines keep their own text spacing (1.4.12), and on an element without a `lang`, the region's English name is spoken in the language it inherits from the page (3.1.2) — section 3.10 of [docs/architecture.md](docs/architecture.md) names, with what stands instead and when it goes, for the app's Accessibility page. A lesson's worked example comes by the property `workedExample`, in place of a task: its statement stands above the sheet and its grid on it, but the learner does not write there — a finger or a pen scrolls the sheet as the browser scrolls the statement, and the row, named Worked example buttons, has Next, Demo, Up, Down and the zoom's buttons. Next opens the parts of the author's demo one at a time, into a numbered list above the sheet that a polite region tells a screen reader of, and Demo hides the whole demo and shows it again; the property `demoState` and the event `demochange` tell the app how far the learner has gone, and the app may give it back to a new element after the example — in React's JSX `workedExample` comes before `demoState`, and `ondemochange` listens. The pictures of the demo come from the consumer's `media` with the statement's, one file for each reference, all of them as the example comes, so that a part opened shows its picture at once; a picture on an area of the sheet stands on the sheet itself, stretched over its area, and the sheet scrolls to it as its part opens. The element now waits for the app, and the samples page is built on it; a test plays the app's part, and `just demo` serves a page to try the element on by hand. 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, and the same archive goes to npm: the first version by hand, 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
25
|
|
|
26
26
|
## Install
|
|
27
27
|
|
|
@@ -80,7 +80,7 @@ The documents are in Russian.
|
|
|
80
80
|
- [docs/decisions.md](docs/decisions.md) — the decision log: what was decided, why, and what was rejected.
|
|
81
81
|
- [RUN.md](RUN.md) — the work plan, in epics.
|
|
82
82
|
|
|
83
|
-
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.
|
|
83
|
+
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.15.1), checked out here as a git submodule at `v0.15.1`: clone this repository with `git clone --recurse-submodules`.
|
|
84
84
|
|
|
85
85
|
## License
|
|
86
86
|
|
package/lib/element/index.js
CHANGED
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
// its contract with app are spec's, of @altnovatrail/spec/canvas: the element implements its CanvasElement, and the package puts the
|
|
34
34
|
// element and its events in the DOM's maps (T69; R07). The keyboard goes into the sheet and out:
|
|
35
35
|
// a container that scrolls is a region named by the canvas kind, with a stop of Tab of its own and
|
|
36
|
-
// a ring when the keyboard brings the focus there (T93; R33)
|
|
36
|
+
// a ring when the keyboard brings the focus there (T93; R33); for a `lang` the labels are not in,
|
|
37
|
+
// the container is in theirs and the column in the element's (T106; R74). The row's Zoom in and Zoom out step
|
|
37
38
|
// the page's zoom of the sheet from its fit to twice it, and a zoomed sheet scrolls across as well
|
|
38
39
|
// as down, with Left and Right in the row, two fingers and the keys (T94).
|
|
39
40
|
import { cellOf, cellsOf, filledOf, sheetFilledOf } from "../core/boxes.js";
|
|
@@ -56,7 +57,7 @@ import { cellsForCheck, workForCheck } from "../core/submission.js";
|
|
|
56
57
|
import { isTool, isWorkbook, NO_TASK, sameLayer, sameStatement, taskOf, templateOf, wholeSheet, } from "../core/task.js";
|
|
57
58
|
import { nextIdOf, resumeOf, Work } from "../core/work.js";
|
|
58
59
|
import { placeOver, SVG, write } from "./attributes.js";
|
|
59
|
-
import { labelsFor, say } from "./labels.js";
|
|
60
|
+
import { knows, labelsFor, say, sayAround } from "./labels.js";
|
|
60
61
|
import { Parts } from "./parts.js";
|
|
61
62
|
import { Pictures } from "./pictures.js";
|
|
62
63
|
import { attachProbe } from "./probe.js";
|
|
@@ -462,10 +463,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
462
463
|
#cells = [];
|
|
463
464
|
#rects = [];
|
|
464
465
|
/**
|
|
465
|
-
* The values a worked example's demo has written in its boxes,
|
|
466
|
-
*
|
|
466
|
+
* The texts of the values a worked example's demo has written in its boxes, one for each frame
|
|
467
|
+
* that has had one (T85; R60).
|
|
467
468
|
*/
|
|
468
|
-
#fills = new Map();
|
|
469
469
|
#values = [];
|
|
470
470
|
#taken = new WeakMap();
|
|
471
471
|
/** Which answer slots are filled, the same array until one changes, or null (R37, R42). */
|
|
@@ -937,15 +937,19 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
937
937
|
this.#markBoxes();
|
|
938
938
|
}
|
|
939
939
|
/**
|
|
940
|
-
* The demo's list says a box it fills in the labels' language,
|
|
941
|
-
* its
|
|
940
|
+
* The demo's list says a box it fills in the labels' language, around its value, which is a node
|
|
941
|
+
* of its own in the parts' language: "Box 1.2: " and "5" (T107); its open items too, anew.
|
|
942
|
+
* Without `lang` the labels are English, as the element's own.
|
|
942
943
|
*/
|
|
943
944
|
#nameBoxes(tag = this.getAttribute("lang")) {
|
|
944
945
|
const { lang, labels } = labelsFor(tag);
|
|
945
946
|
this.#parts.fillWords = (part) => {
|
|
946
947
|
const name = say(labels.boxIn, { line: part.fill.line, slot: part.fill.box });
|
|
947
948
|
const value = this.#example === undefined ? "" : fillValue(this.#example, part);
|
|
948
|
-
|
|
949
|
+
if (value === "")
|
|
950
|
+
return { before: name, value, after: "", lang };
|
|
951
|
+
const [before, after] = sayAround(labels.valued, "value", { name });
|
|
952
|
+
return { before, value, after, lang };
|
|
949
953
|
};
|
|
950
954
|
}
|
|
951
955
|
/**
|
|
@@ -1155,7 +1159,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1155
1159
|
/**
|
|
1156
1160
|
* Each box of the lines as it now is (R36, R37): its frame, thicker when it is filled, and its
|
|
1157
1161
|
* name in the labels' language, by the element's `lang` — "Box" alone in its line, numbered by
|
|
1158
|
-
* its slot among several, and "filled" when it is.
|
|
1162
|
+
* its slot among several, and "filled" when it is. A value a worked example's demo wrote in it is
|
|
1163
|
+
* no part of its name: its text after the frame says it, in the lines' language (T107). Only
|
|
1164
|
+
* what has changed is written.
|
|
1159
1165
|
*/
|
|
1160
1166
|
#markBoxes() {
|
|
1161
1167
|
const { lang, labels } = labelsFor(this.getAttribute("lang"));
|
|
@@ -1166,13 +1172,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1166
1172
|
const several = (this.#laid?.items[cell.item - 1]?.boxes.length ?? 0) > 1;
|
|
1167
1173
|
const filled = this.#filled?.[cell.item - 1]?.[cell.slot - 1] === true;
|
|
1168
1174
|
const name = several ? say(labels.boxAt, { slot: cell.slot }) : labels.box;
|
|
1169
|
-
// A worked example's box says what its demo wrote in it: the text itself says nothing.
|
|
1170
|
-
const value = this.#fills.get(`${cell.item}.${cell.slot}`);
|
|
1171
1175
|
rect.classList.toggle("filled", filled);
|
|
1172
|
-
|
|
1173
|
-
if (value !== undefined)
|
|
1174
|
-
label = say(labels.valued, { name, value });
|
|
1175
|
-
write(rect, "aria-label", label);
|
|
1176
|
+
write(rect, "aria-label", filled ? say(labels.filled, { name }) : name);
|
|
1176
1177
|
write(rect, "lang", lang);
|
|
1177
1178
|
}
|
|
1178
1179
|
}
|
|
@@ -1796,20 +1797,19 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1796
1797
|
/**
|
|
1797
1798
|
* The values a worked example's demo has written in the boxes of its workbook (T85; R60): each in
|
|
1798
1799
|
* the middle of its box, on the line's baseline, at the width the layout gives its text, as the
|
|
1799
|
-
* lines' texts are; none while the demo is hidden.
|
|
1800
|
+
* lines' texts are; none while the demo is hidden. A value is a text of its own just after its
|
|
1801
|
+
* box's frame, which a screen reader reads after the box, in the lines' language, as the lines'
|
|
1802
|
+
* texts are (T107; 3.1.2). Only what changed is written.
|
|
1800
1803
|
*/
|
|
1801
1804
|
#showFills(fills) {
|
|
1802
|
-
this.#fills = fills;
|
|
1803
1805
|
const page = this.#laid;
|
|
1804
1806
|
if (page === undefined)
|
|
1805
1807
|
return;
|
|
1806
|
-
let changed = false;
|
|
1807
1808
|
for (const [c, cell] of this.#cells.entries()) {
|
|
1808
1809
|
const value = fills.get(`${cell.item}.${cell.slot}`);
|
|
1809
1810
|
let text = this.#values[c];
|
|
1810
1811
|
if (value === (text?.textContent ?? undefined))
|
|
1811
1812
|
continue;
|
|
1812
|
-
changed = true;
|
|
1813
1813
|
if (value === undefined) {
|
|
1814
1814
|
text?.remove();
|
|
1815
1815
|
this.#values[c] = undefined;
|
|
@@ -1821,7 +1821,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1821
1821
|
continue;
|
|
1822
1822
|
if (text === undefined) {
|
|
1823
1823
|
text = document.createElementNS(SVG, "text");
|
|
1824
|
-
text.setAttribute("
|
|
1824
|
+
text.setAttribute("class", "value");
|
|
1825
1825
|
text.setAttribute("lengthAdjust", "spacingAndGlyphs");
|
|
1826
1826
|
rect.after(text);
|
|
1827
1827
|
this.#values[c] = text;
|
|
@@ -1832,8 +1832,6 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1832
1832
|
text.setAttribute("textLength", String(width));
|
|
1833
1833
|
text.textContent = value;
|
|
1834
1834
|
}
|
|
1835
|
-
if (changed)
|
|
1836
|
-
this.#markBoxes();
|
|
1837
1835
|
}
|
|
1838
1836
|
/** Whoever listens hears of the demo's new state, which the learner chose (R42). */
|
|
1839
1837
|
#demoChanged() {
|
|
@@ -1930,13 +1928,21 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1930
1928
|
}
|
|
1931
1929
|
/**
|
|
1932
1930
|
* The region's name: the canvas kind's, or a worked example's, in the labels' language, which
|
|
1933
|
-
* the row's buttons are named in.
|
|
1934
|
-
*
|
|
1931
|
+
* the row's buttons are named in. For a `lang` the labels are not in, the container is in
|
|
1932
|
+
* theirs, English, and the column, all the container holds, in the element's: the name is said
|
|
1933
|
+
* in the language it is in, and the statement, the parts and the sheet as before (T106; R74).
|
|
1934
|
+
* With a `lang` the labels are in, the name is in the element's language already; without one,
|
|
1935
|
+
* the element's language is the page's, which no attribute of the column could name. Neither
|
|
1936
|
+
* then has a `lang` of its own.
|
|
1935
1937
|
*/
|
|
1936
1938
|
#nameRegion() {
|
|
1937
|
-
const
|
|
1939
|
+
const tag = this.getAttribute("lang");
|
|
1940
|
+
const { lang, labels } = labelsFor(tag);
|
|
1941
|
+
const apart = tag !== null && !knows(tag);
|
|
1938
1942
|
const named = this.#viewport.hasAttribute("role");
|
|
1939
1943
|
write(this.#viewport, "aria-label", named ? labels[this.#rowKind()] : null);
|
|
1944
|
+
write(this.#viewport, "lang", apart ? lang : null);
|
|
1945
|
+
write(this.#column, "lang", apart ? tag : null);
|
|
1940
1946
|
}
|
|
1941
1947
|
/** What the row of buttons is of, and is named by: a worked example, or the canvas kind (R42). */
|
|
1942
1948
|
#rowKind() {
|
package/lib/element/labels.d.ts
CHANGED
|
@@ -47,16 +47,23 @@ export interface Labels {
|
|
|
47
47
|
}
|
|
48
48
|
/** Every language the table has, by its tag: the tests hold each to English's places. */
|
|
49
49
|
export declare const LANGUAGES: readonly string[];
|
|
50
|
+
/** Labels, and the language they are in. */
|
|
51
|
+
type Labelled = {
|
|
52
|
+
readonly lang: string;
|
|
53
|
+
readonly labels: Labels;
|
|
54
|
+
};
|
|
50
55
|
/**
|
|
51
56
|
* The labels for a language tag, and the language they are in. The tag is looked up as RFC 4647,
|
|
52
57
|
* section 3.4, does it: in lower case, cut subtag by subtag from its end until the table has what
|
|
53
58
|
* is left, a single-letter subtag going with the subtag after it. English stands for any other
|
|
54
59
|
* tag, and for none.
|
|
55
60
|
*/
|
|
56
|
-
export declare function labelsFor(tag: string | null):
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
export declare function labelsFor(tag: string | null): Labelled;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the table has labels in the language of a tag, as `labelsFor` looks it up: the English
|
|
64
|
+
* that stands for a tag it has not is in no language of the tag's (R74).
|
|
65
|
+
*/
|
|
66
|
+
export declare function knows(tag: string | null): boolean;
|
|
60
67
|
/** The places a label names, each once, in the order it names them. */
|
|
61
68
|
export declare function placesOf(label: string): string[];
|
|
62
69
|
/**
|
|
@@ -64,3 +71,10 @@ export declare function placesOf(label: string): string[];
|
|
|
64
71
|
* never shows its braces.
|
|
65
72
|
*/
|
|
66
73
|
export declare function say(label: string, values: Readonly<Record<string, string | number>>): string;
|
|
74
|
+
/**
|
|
75
|
+
* A label with its places filled by name but one, which it is cut at: what comes before that place
|
|
76
|
+
* and what comes after it, for a node of its own to stand between them (T107). A label that names
|
|
77
|
+
* the place not once is a TypeError, and so is a place the values do not give, as with `say`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function sayAround(label: string, place: string, values: Readonly<Record<string, string | number>>): readonly [string, string];
|
|
80
|
+
export {};
|
package/lib/element/labels.js
CHANGED
|
@@ -88,6 +88,17 @@ export const LANGUAGES = [...LABELS.keys()];
|
|
|
88
88
|
* tag, and for none.
|
|
89
89
|
*/
|
|
90
90
|
export function labelsFor(tag) {
|
|
91
|
+
return lookup(tag) ?? { lang: "en", labels: ENGLISH };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Whether the table has labels in the language of a tag, as `labelsFor` looks it up: the English
|
|
95
|
+
* that stands for a tag it has not is in no language of the tag's (R74).
|
|
96
|
+
*/
|
|
97
|
+
export function knows(tag) {
|
|
98
|
+
return lookup(tag) !== undefined;
|
|
99
|
+
}
|
|
100
|
+
/** The labels the table has for a tag, by RFC 4647, section 3.4, or none. */
|
|
101
|
+
function lookup(tag) {
|
|
91
102
|
let range = (tag ?? "").toLowerCase();
|
|
92
103
|
while (range !== "") {
|
|
93
104
|
const labels = LABELS.get(range);
|
|
@@ -99,7 +110,7 @@ export function labelsFor(tag) {
|
|
|
99
110
|
cut -= 2;
|
|
100
111
|
range = cut > 0 ? range.slice(0, cut) : "";
|
|
101
112
|
}
|
|
102
|
-
return
|
|
113
|
+
return undefined;
|
|
103
114
|
}
|
|
104
115
|
/** A place of a label: a name of Latin letters, digits and underscores in braces. */
|
|
105
116
|
const PLACE = /\{(\w+)\}/g;
|
|
@@ -119,3 +130,18 @@ export function say(label, values) {
|
|
|
119
130
|
return String(value);
|
|
120
131
|
});
|
|
121
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* A label with its places filled by name but one, which it is cut at: what comes before that place
|
|
135
|
+
* and what comes after it, for a node of its own to stand between them (T107). A label that names
|
|
136
|
+
* the place not once is a TypeError, and so is a place the values do not give, as with `say`.
|
|
137
|
+
*/
|
|
138
|
+
export function sayAround(label, place, values) {
|
|
139
|
+
const parts = label.split(`{${place}}`);
|
|
140
|
+
const [before, after] = parts;
|
|
141
|
+
if (parts.length !== 2 || before === undefined || after === undefined) {
|
|
142
|
+
throw new TypeError(`the label "${label}" names {${place}} not once`);
|
|
143
|
+
}
|
|
144
|
+
// The label whole first, so that a place with no value is named in it, not in a cut of it.
|
|
145
|
+
say(label, { ...values, [place]: "" });
|
|
146
|
+
return [say(before, values), say(after, values)];
|
|
147
|
+
}
|
package/lib/element/parts.d.ts
CHANGED
|
@@ -7,6 +7,20 @@ export interface Told {
|
|
|
7
7
|
/** The language of the labels the number is in. */
|
|
8
8
|
readonly lang: string;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* What a part that fills a box says: the box, in the labels' language, around the value the demo
|
|
12
|
+
* wrote in it, which is in the parts' own (T107). Without a value the box is `before` alone.
|
|
13
|
+
*/
|
|
14
|
+
export interface FillWords {
|
|
15
|
+
/** The labels' words before the value: "Box 1.2: ". */
|
|
16
|
+
readonly before: string;
|
|
17
|
+
/** The value, in the parts' language, or "" for none. */
|
|
18
|
+
readonly value: string;
|
|
19
|
+
/** The labels' words after the value, most often none. */
|
|
20
|
+
readonly after: string;
|
|
21
|
+
/** The language of the labels the words around the value are in. */
|
|
22
|
+
readonly lang: string;
|
|
23
|
+
}
|
|
10
24
|
/** The list of a demo's open parts and the region that tells of them, as the element shows them. */
|
|
11
25
|
export declare class Parts {
|
|
12
26
|
#private;
|
|
@@ -29,7 +43,7 @@ export declare class Parts {
|
|
|
29
43
|
*/
|
|
30
44
|
readonly spot: HTMLDivElement;
|
|
31
45
|
/** What a part that fills a box says from now on, the items already open too. */
|
|
32
|
-
set fillWords(words: (part: FillPart) =>
|
|
46
|
+
set fillWords(words: (part: FillPart) => FillWords);
|
|
33
47
|
/** The list and the region, by their IDs, whose pictures the element's pictures give files. */
|
|
34
48
|
constructor(ids: {
|
|
35
49
|
readonly status: string;
|
package/lib/element/parts.js
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
// in words till then. A picture on an area of the sheet is read by its words here, while the
|
|
8
8
|
// picture itself stands on the layer of the author's demo, stretched over its area, the later part
|
|
9
9
|
// over the earlier, and nothing stands there till its file is decoded (T61). A box of a workbook
|
|
10
|
-
// the demo fills is read as the box and its value,
|
|
11
|
-
//
|
|
10
|
+
// the demo fills is read as the box, in the labels' language, and its value, a node of its own in
|
|
11
|
+
// the parts' language, which the element writes in the box itself too (T85, T107). This module is
|
|
12
|
+
// no entry point of the package.
|
|
12
13
|
import { isFill, onSheet, } from "../core/example.js";
|
|
13
14
|
import { SHEET } from "../core/sheet.js";
|
|
14
15
|
import { placeOver, SVG, write } from "./attributes.js";
|
|
@@ -42,13 +43,14 @@ export class Parts {
|
|
|
42
43
|
/** The open items of parts that fill a box, which a new language words anew. */
|
|
43
44
|
#fills = new Map();
|
|
44
45
|
/**
|
|
45
|
-
* What a part that fills a box says
|
|
46
|
-
*
|
|
47
|
-
*
|
|
46
|
+
* What a part that fills a box says: the box, in the labels' language, around its value. The
|
|
47
|
+
* element sets it with each example and as its language changes; `fillWords` says the open items
|
|
48
|
+
* again in the new one. On its own, the list says the box by the English label, and no value.
|
|
48
49
|
*/
|
|
49
50
|
#fillWords = ({ fill }) => {
|
|
50
51
|
const { lang, labels } = labelsFor(null);
|
|
51
|
-
|
|
52
|
+
const before = say(labels.boxIn, { line: fill.line, slot: fill.box });
|
|
53
|
+
return { before, value: "", after: "", lang };
|
|
52
54
|
};
|
|
53
55
|
/** What a part that fills a box says from now on, the items already open too. */
|
|
54
56
|
set fillWords(words) {
|
|
@@ -132,16 +134,11 @@ export class Parts {
|
|
|
132
134
|
* has its number alone.
|
|
133
135
|
*/
|
|
134
136
|
tell(part, told) {
|
|
135
|
-
const number =
|
|
136
|
-
number.lang = told.lang;
|
|
137
|
-
number.textContent = told.number;
|
|
138
|
-
const said = document.createElement("span");
|
|
137
|
+
const number = spanOf(told.number, told.lang);
|
|
139
138
|
if (isFill(part)) {
|
|
140
|
-
//
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
said.textContent = words;
|
|
144
|
-
this.status.replaceChildren(number, " ", said);
|
|
139
|
+
// The box in the labels' language and its value in the parts', as its item says them.
|
|
140
|
+
const nodes = this.#fillNodes(part, this.list.getAttribute("lang"));
|
|
141
|
+
this.status.replaceChildren(number, " ", ...nodes);
|
|
145
142
|
return;
|
|
146
143
|
}
|
|
147
144
|
const words = "text" in part ? part.text : part.alt;
|
|
@@ -150,21 +147,34 @@ export class Parts {
|
|
|
150
147
|
return;
|
|
151
148
|
}
|
|
152
149
|
// The parts' language, which the list has, or none: then the element's own, as the list's.
|
|
153
|
-
|
|
154
|
-
if (lang !== null)
|
|
155
|
-
said.lang = lang;
|
|
156
|
-
said.textContent = words;
|
|
157
|
-
this.status.replaceChildren(number, " ", said);
|
|
150
|
+
this.status.replaceChildren(number, " ", spanOf(words, this.list.getAttribute("lang")));
|
|
158
151
|
}
|
|
159
152
|
/** The region is empty: what it told is no more, and the same words may be told again. */
|
|
160
153
|
quiet() {
|
|
161
154
|
this.status.replaceChildren();
|
|
162
155
|
}
|
|
163
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* An item of a part that fills a box says the box, in the labels' language, and its value, in the
|
|
158
|
+
* list's, which the item and the value inherit: a new language of the parts reaches them too.
|
|
159
|
+
*/
|
|
164
160
|
#sayFill(item, part) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
item.replaceChildren(...this.#fillNodes(part, null));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* What a part that fills a box says, as nodes (T107; 3.1.2): the labels' words, each run a span
|
|
165
|
+
* in their language, and the value a span of its own between them, in the language given, or
|
|
166
|
+
* with none, the one it inherits.
|
|
167
|
+
*/
|
|
168
|
+
#fillNodes(part, valueLang) {
|
|
169
|
+
const { before, value, after, lang } = this.#fillWords(part);
|
|
170
|
+
const nodes = [];
|
|
171
|
+
if (before !== "")
|
|
172
|
+
nodes.push(spanOf(before, lang));
|
|
173
|
+
if (value !== "")
|
|
174
|
+
nodes.push(spanOf(value, valueLang));
|
|
175
|
+
if (after !== "")
|
|
176
|
+
nodes.push(spanOf(after, lang));
|
|
177
|
+
return nodes;
|
|
168
178
|
}
|
|
169
179
|
/** An item leaving the list takes its picture off, once, and is no fill's any more. */
|
|
170
180
|
#takeOff(item) {
|
|
@@ -228,3 +238,11 @@ export class Parts {
|
|
|
228
238
|
};
|
|
229
239
|
}
|
|
230
240
|
}
|
|
241
|
+
/** A span of text, in a language given, or with none, in the one it inherits. */
|
|
242
|
+
function spanOf(text, lang) {
|
|
243
|
+
const span = document.createElement("span");
|
|
244
|
+
if (lang !== null)
|
|
245
|
+
span.lang = lang;
|
|
246
|
+
span.textContent = text;
|
|
247
|
+
return span;
|
|
248
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altnovatrail/canvas",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "NovaTrail's canvases: the workplace of a task, where the learner writes, draws and types.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"./lib/element/index.js"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@altnovatrail/spec": "0.15.
|
|
29
|
+
"@altnovatrail/spec": "0.15.1",
|
|
30
30
|
"perfect-freehand": "1.2.3",
|
|
31
31
|
"rbush": "4.0.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@altnovatrail/contracts": "0.15.
|
|
34
|
+
"@altnovatrail/contracts": "0.15.1",
|
|
35
35
|
"@biomejs/biome": "2.6.5",
|
|
36
36
|
"@bufbuild/protobuf": "2.16.0",
|
|
37
37
|
"@iconify-json/material-symbols": "1.2.97",
|