@altnovatrail/canvas 0.1.2 → 0.1.3
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 +5 -5
- package/lib/core/boxes.js +2 -2
- package/lib/core/crop.d.ts +2 -2
- package/lib/core/crop.js +2 -2
- package/lib/core/groups.d.ts +2 -2
- package/lib/core/groups.js +2 -2
- package/lib/core/index.js +4 -4
- package/lib/core/marks.d.ts +19 -35
- package/lib/core/marks.js +17 -7
- package/lib/element/index.d.ts +7 -6
- package/lib/element/index.js +5 -4
- package/package.json +3 -2
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.
|
|
19
19
|
|
|
20
|
-
A component of [NovaTrail](https://github.com/altnovatrail/spec/tree/v0.
|
|
20
|
+
A component of [NovaTrail](https://github.com/altnovatrail/spec/tree/v0.9.8), 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,
|
|
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 synthetic samples that tutor's CI reads come first now, then the page. 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.2, which spec v0.6.0 brought — a manifest of another version 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 is at most 1000 CSS pixels wide, and 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. 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, has Next, Demo, Up and Down. 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; 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
|
|
|
@@ -37,10 +37,10 @@ A pull request that changes the lock file has spec's recipe check it, as NovaTra
|
|
|
37
37
|
## Code
|
|
38
38
|
|
|
39
39
|
- `src/core/` — the DOM-free part, `@altnovatrail/canvas/core`: it runs the same in a browser and in Node, and its entry point gives the sheet's size, the types of the data and the fold of a history into its strokes.
|
|
40
|
-
- `src/element/` — the element `<novatrail-canvas>`, `@altnovatrail/canvas`: importing it registers the element. The types of its contract with the app — the element as `CanvasElement` has it, its events, the media, the history of writing, the work for checking and its context — are spec's, from `@altnovatrail/spec/canvas`, and this entry point gives them under spec's names, the same types; the DOM-free part gives the data's among them, the history of writing and the context of a submission. The app takes them from spec's package, `import type { CanvasElement } from "@altnovatrail/spec/canvas"`, at the version canvas has in its `dependencies`; canvas's own are only what the contract does not name: the
|
|
40
|
+
- `src/element/` — the element `<novatrail-canvas>`, `@altnovatrail/canvas`: importing it registers the element. The types of its contract with the app — the element as `CanvasElement` has it, its events, the media, the tutor's marks, the history of writing, the work for checking and its context — are spec's, from `@altnovatrail/spec/canvas`, and this entry point gives them under spec's names, the same types; the DOM-free part gives the data's among them, the history of writing and the context of a submission. The app takes them from spec's package, `import type { CanvasElement } from "@altnovatrail/spec/canvas"`, at the version canvas has in its `dependencies`; canvas's own are only what the contract does not name: the commands `undo()` and `clear()`, and the task's temporary tools.
|
|
41
41
|
- `scripts/` — the check of the package as a consumer takes it, and of the archive a release puts out, and the script that writes the row's icons, `src/element/icons.ts`, and `NOTICE` from the set of icons the lock file pins: `just icons` runs it, and `just ci` fails if they are not what it writes.
|
|
42
42
|
- `demo/` — a page to try the element on by hand, as the app is to have it: it gives the element a language and its task the tools allowed, keeps the history of writing as the element tells it and opens the sheet again from it, draws the groups of the strokes and the crop for checking under the sheet, gives the tutor's marks back over the crop Check sent, and shows a workbook's pages in the font and the language it gives, how many boxes are filled, the crop of each filled box Check sent and a mark given back on a box, and a lesson's worked example on a new element, on which nothing is written, whose demo opens part by part — a picture on an area of the sheet on the sheet itself — the page keeping how far it has gone and giving it back to the next element. `just demo` serves it on this machine.
|
|
43
|
-
- `vectors/` — the test vectors of the
|
|
43
|
+
- `vectors/` — the test vectors of the workbook's page layout, which its test writes and keeps current. The vectors of the rules the sheet shares with tutor's eval runner — the groups of strokes, the crop for checking, the snapping of a model's box to the strokes and the rule of boxes — are spec's, from its npm package `@altnovatrail/contracts`, and the tests hold the sheet's code to them.
|
|
44
44
|
- `licenses.json` — the packages the license check accepts by name, each with why.
|
|
45
45
|
|
|
46
46
|
`just build` builds the package into `lib/`, and `just release-files v0.1.0` writes the files of that release into `dist/` — the package's archive, with NOTICE in it, LICENSE and SHA256SUMS — and prints the sums, which a build of the same commit gives again. `just ci` runs the checks CI runs: format, lint and types; the tests in Node and in Chromium; advisories; licenses. They run in the devcontainer, whose toolchain stage holds the browser the tests run in. The license check is spec's recipe, run from the `spec/` submodule with the exceptions in `licenses.json`, so it needs `spec/` checked out: see [CLAUDE.md](CLAUDE.md), Environment.
|
|
@@ -53,7 +53,7 @@ The documents are in Russian.
|
|
|
53
53
|
- [docs/decisions.md](docs/decisions.md) — the decision log: what was decided, why, and what was rejected.
|
|
54
54
|
- [RUN.md](RUN.md) — the work plan, in epics.
|
|
55
55
|
|
|
56
|
-
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.
|
|
56
|
+
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.8), checked out here as a git submodule at `v0.9.8`: clone this repository with `git clone --recurse-submodules`.
|
|
57
57
|
|
|
58
58
|
## License
|
|
59
59
|
|
package/lib/core/boxes.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// widened by 120 thousandths of its size — 12 units of a box of 100, short of the 16 to halfway to
|
|
5
5
|
// the next box — and it is no wider and no taller than the box and 30 units on each side: a
|
|
6
6
|
// fraction's bar wider than the box is its own, and a line through the whole line is not. The
|
|
7
|
-
// core's entry point does not give the rule
|
|
8
|
-
//
|
|
7
|
+
// core's entry point does not give the rule. It is the eval protocol's now, as the sheet wrote it,
|
|
8
|
+
// and spec's test vectors pin it (R94 spec; T16).
|
|
9
9
|
import { extentOf, tenths } from "./geometry.js";
|
|
10
10
|
/** The rule the workbook has (R37): the sweep of T48 chose it. */
|
|
11
11
|
export const BOX_RULE = Object.freeze({ margin: 120, limit: 1600 });
|
package/lib/core/crop.d.ts
CHANGED
|
@@ -32,8 +32,8 @@ export declare const CROP: Readonly<{
|
|
|
32
32
|
*/
|
|
33
33
|
digit: 24;
|
|
34
34
|
/**
|
|
35
|
-
* The heights of digits a sample's crops are drawn at, px,
|
|
36
|
-
* (R09;
|
|
35
|
+
* The heights of digits a sample's crops are drawn at, px, as the eval protocol names them,
|
|
36
|
+
* beside the module's own (R09; R93 spec).
|
|
37
37
|
*/
|
|
38
38
|
heights: readonly [16, 24, 32, 48];
|
|
39
39
|
/** The tallest digit a crop takes, px: its ink then still stays within the margin. */
|
package/lib/core/crop.js
CHANGED
|
@@ -32,8 +32,8 @@ export const CROP = Object.freeze({
|
|
|
32
32
|
*/
|
|
33
33
|
digit: 24,
|
|
34
34
|
/**
|
|
35
|
-
* The heights of digits a sample's crops are drawn at, px,
|
|
36
|
-
* (R09;
|
|
35
|
+
* The heights of digits a sample's crops are drawn at, px, as the eval protocol names them,
|
|
36
|
+
* beside the module's own (R09; R93 spec).
|
|
37
37
|
*/
|
|
38
38
|
heights: Object.freeze([16, 24, 32, 48]),
|
|
39
39
|
/** The tallest digit a crop takes, px: its ink then still stays within the margin. */
|
package/lib/core/groups.d.ts
CHANGED
|
@@ -38,8 +38,8 @@ export type { Group };
|
|
|
38
38
|
export declare function groupsOf(strokes: readonly Stroke[], rule?: GroupRule): Group[];
|
|
39
39
|
/**
|
|
40
40
|
* The pairs of neighbours among the strokes on a sheet, by ID (R24): each pair once, the smaller
|
|
41
|
-
* ID first, in ascending order. Its groups join these pairs;
|
|
42
|
-
* runner to see where its grouping parts from the sheet's.
|
|
41
|
+
* ID first, in ascending order. Its groups join these pairs; spec's test vectors give them too, for
|
|
42
|
+
* a runner to see where its grouping parts from the sheet's (R94 spec).
|
|
43
43
|
*/
|
|
44
44
|
export declare function neighboursOf(strokes: readonly Stroke[], rule?: GroupRule): [number, number][];
|
|
45
45
|
/**
|
package/lib/core/groups.js
CHANGED
|
@@ -33,8 +33,8 @@ export function groupsOf(strokes, rule = GROUP_RULE) {
|
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* The pairs of neighbours among the strokes on a sheet, by ID (R24): each pair once, the smaller
|
|
36
|
-
* ID first, in ascending order. Its groups join these pairs;
|
|
37
|
-
* runner to see where its grouping parts from the sheet's.
|
|
36
|
+
* ID first, in ascending order. Its groups join these pairs; spec's test vectors give them too, for
|
|
37
|
+
* a runner to see where its grouping parts from the sheet's (R94 spec).
|
|
38
38
|
*/
|
|
39
39
|
export function neighboursOf(strokes, rule = GROUP_RULE) {
|
|
40
40
|
return pairsOf(piecesOf(strokes), rule)
|
package/lib/core/index.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
// gives the sheet's size, the types of the data the element takes and gives — the strokes and the
|
|
5
5
|
// history of writing, the task, the worked example and the manifest, how far the learner has gone
|
|
6
6
|
// through the example's demo (R42) and the context of a submission, of a sheet or of a workbook,
|
|
7
|
-
// all of spec's types (R73 spec, R74 spec), and the tutor's marks,
|
|
8
|
-
//
|
|
7
|
+
// all of spec's types (R73 spec, R74 spec), and the tutor's marks, spec's types too (R83 spec) —
|
|
8
|
+
// and the fold of a history into the strokes it leaves, so that a consumer
|
|
9
9
|
// reads a history it keeps without the DOM (R27). The code runs without the DOM, but spec's
|
|
10
10
|
// declarations of the element's contract, which its types come from, name the DOM's types too: a
|
|
11
11
|
// consumer without the DOM's types skips them with skipLibCheck (T69). The rules of the groups, the
|
|
12
|
-
// crop and the snapping stay inside
|
|
13
|
-
//
|
|
12
|
+
// crop and the snapping stay inside: the eval protocol has taken them as they are, and spec's test
|
|
13
|
+
// vectors pin them (R94 spec; T16).
|
|
14
14
|
export { replay } from "./history.js";
|
|
15
15
|
export { SHEET } from "./sheet.js";
|
package/lib/core/marks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CellPlace, CropNumbers, Filling, SheetSubmission, Submission, WorkbookSubmission } from "@altnovatrail/spec/canvas";
|
|
1
|
+
import type { Anchor, CellPlace, CropNumbers, Filling, Mark, Marks, SheetSubmission, Submission, WorkbookSubmission } from "@altnovatrail/spec/canvas";
|
|
2
2
|
import type { Cell } from "./boxes.js";
|
|
3
3
|
import { type Box } from "./geometry.js";
|
|
4
4
|
import type { Group } from "./groups.js";
|
|
@@ -38,39 +38,21 @@ export declare const SNAP_RULE: SnapRule;
|
|
|
38
38
|
* order, and the digest of its strokes and of every box of the page, `workbookDigestOf` it (R34,
|
|
39
39
|
* R38): no numbers of the crops, for no mark on a workbook is snapped. An answer cell has no ID:
|
|
40
40
|
* its place names it, its item and its place among the item's cells, each from 1 (R51 spec).
|
|
41
|
+
*
|
|
42
|
+
* The tutor's marks of one submission, with the submission's context, are spec's types too, of the
|
|
43
|
+
* same contract (R83 spec; T16): a mark is a frame, so far, with where it is and the name a screen
|
|
44
|
+
* reader gives it, in the consumer's words — the element words nothing. Where it is: a group of
|
|
45
|
+
* strokes by its label, an answer cell by its place, or a box on the crop the model saw,
|
|
46
|
+
* [ymin, xmin, ymax, xmax] in whole thousandths of its height and width, min < max (R53 spec). On a
|
|
47
|
+
* workbook a mark stands on a cell alone (R34).
|
|
41
48
|
*/
|
|
42
|
-
export type { CellPlace, CropNumbers, SheetSubmission, Submission, WorkbookSubmission };
|
|
43
|
-
/**
|
|
44
|
-
* Where a mark is: a group of strokes by its label, an answer cell by its place, or a box on the
|
|
45
|
-
* crop the model saw, [ymin, xmin, ymax, xmax] in whole thousandths of its height and width, min <
|
|
46
|
-
* max (R53 spec). On a workbook a mark stands on a cell alone (R34).
|
|
47
|
-
*/
|
|
48
|
-
export type Anchor = {
|
|
49
|
-
readonly group: string;
|
|
50
|
-
} | {
|
|
51
|
-
readonly cell: CellPlace;
|
|
52
|
-
} | {
|
|
53
|
-
readonly box: readonly [number, number, number, number];
|
|
54
|
-
};
|
|
55
|
-
/** A mark of the tutor's layer: a frame, so far, with where it is and its name. */
|
|
56
|
-
export interface Mark {
|
|
57
|
-
readonly kind: "frame";
|
|
58
|
-
readonly at: Anchor;
|
|
59
|
-
/** What a screen reader names it, in the consumer's words: the element words nothing. */
|
|
60
|
-
readonly name: string;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* The tutor's marks of one submission, with the submission's context (R07): a sheet's or a
|
|
64
|
-
* workbook's.
|
|
65
|
-
*/
|
|
66
|
-
export interface Marks {
|
|
67
|
-
readonly submission: Submission;
|
|
68
|
-
readonly marks: readonly Mark[];
|
|
69
|
-
}
|
|
49
|
+
export type { Anchor, CellPlace, CropNumbers, Mark, Marks, SheetSubmission, Submission, WorkbookSubmission, };
|
|
70
50
|
/**
|
|
71
51
|
* A mark on the sheet, `{stroke_ids, snapped_box}` (C2): the strokes it holds on to, by ID in
|
|
72
52
|
* ascending order, and the rectangle of their points, in units, as the model saw them. A mark of a
|
|
73
|
-
* workbook's cell has the box of its cell too, which its frame stands round with the ink (R39).
|
|
53
|
+
* workbook's cell has the box of its cell too, which its frame stands round with the ink (R39). A
|
|
54
|
+
* mark of a box the submission found empty holds no strokes, and its `box` is then the cell's own:
|
|
55
|
+
* `shownOf` frames it alone.
|
|
74
56
|
*/
|
|
75
57
|
export interface Placed {
|
|
76
58
|
readonly ids: readonly number[];
|
|
@@ -104,8 +86,9 @@ export declare function snapOf(box: readonly [number, number, number, number], c
|
|
|
104
86
|
* submission is in none of its groups, and no mark takes it. A group's mark holds its strokes, a
|
|
105
87
|
* box's the strokes it snaps to; an answer cell's holds none on a sheet, which takes no zones.
|
|
106
88
|
* `cells` are the boxes of a workbook's page, in the task's order, and null on a sheet: there a
|
|
107
|
-
* cell's mark holds the strokes of its row of the table, with its box
|
|
108
|
-
* holds none (R39
|
|
89
|
+
* cell's mark holds the strokes of its row of the table, with its box; one of a box not in the
|
|
90
|
+
* table, an empty one, holds its box alone, and one of a box not on the page holds none (R39; the
|
|
91
|
+
* second 2026-11-03 amendment to R74 spec).
|
|
109
92
|
*
|
|
110
93
|
* A submission of other strokes is a TypeError: a stroke of its groups the sheet does not know, or
|
|
111
94
|
* a digest the sheet's strokes of those IDs do not give with the submission's numbers (R27). A
|
|
@@ -118,9 +101,10 @@ export declare function snapOf(box: readonly [number, number, number, number], c
|
|
|
118
101
|
export declare function placesOf(marks: Marks, known: readonly Stroke[], cells?: readonly Cell[] | null, rule?: SnapRule): (Placed | null)[];
|
|
119
102
|
/**
|
|
120
103
|
* The rectangle a mark shows now (R26): around the points of those of its strokes the sheet shows,
|
|
121
|
-
* in units, or null while it shows none of them.
|
|
122
|
-
*
|
|
123
|
-
* strokes are none of a
|
|
104
|
+
* in units, or null while it shows none of them. A mark of a box that was empty shows the box
|
|
105
|
+
* itself, always (R39). `shown` gives the box of a stroke's points by its ID while the stroke is
|
|
106
|
+
* on the screen — not erased, nor under the eraser under way (R22). New strokes are none of a
|
|
107
|
+
* mark's.
|
|
124
108
|
*/
|
|
125
109
|
export declare function shownOf(placed: Placed, shown: (id: number) => Box | undefined): Box | null;
|
|
126
110
|
/**
|
package/lib/core/marks.js
CHANGED
|
@@ -74,8 +74,9 @@ export function snapOf(box, crop, strokes, rule = SNAP_RULE) {
|
|
|
74
74
|
* submission is in none of its groups, and no mark takes it. A group's mark holds its strokes, a
|
|
75
75
|
* box's the strokes it snaps to; an answer cell's holds none on a sheet, which takes no zones.
|
|
76
76
|
* `cells` are the boxes of a workbook's page, in the task's order, and null on a sheet: there a
|
|
77
|
-
* cell's mark holds the strokes of its row of the table, with its box
|
|
78
|
-
* holds none (R39
|
|
77
|
+
* cell's mark holds the strokes of its row of the table, with its box; one of a box not in the
|
|
78
|
+
* table, an empty one, holds its box alone, and one of a box not on the page holds none (R39; the
|
|
79
|
+
* second 2026-11-03 amendment to R74 spec).
|
|
79
80
|
*
|
|
80
81
|
* A submission of other strokes is a TypeError: a stroke of its groups the sheet does not know, or
|
|
81
82
|
* a digest the sheet's strokes of those IDs do not give with the submission's numbers (R27). A
|
|
@@ -123,11 +124,15 @@ export function placesOf(marks, known, cells = null, rule = SNAP_RULE) {
|
|
|
123
124
|
}
|
|
124
125
|
/**
|
|
125
126
|
* The rectangle a mark shows now (R26): around the points of those of its strokes the sheet shows,
|
|
126
|
-
* in units, or null while it shows none of them.
|
|
127
|
-
*
|
|
128
|
-
* strokes are none of a
|
|
127
|
+
* in units, or null while it shows none of them. A mark of a box that was empty shows the box
|
|
128
|
+
* itself, always (R39). `shown` gives the box of a stroke's points by its ID while the stroke is
|
|
129
|
+
* on the screen — not erased, nor under the eraser under way (R22). New strokes are none of a
|
|
130
|
+
* mark's.
|
|
129
131
|
*/
|
|
130
132
|
export function shownOf(placed, shown) {
|
|
133
|
+
// A mark of a box that was empty stands round the box alone, whatever is written in it since.
|
|
134
|
+
if (placed.cell !== undefined && placed.ids.length === 0)
|
|
135
|
+
return placed.cell;
|
|
131
136
|
const boxes = placed.ids.flatMap((id) => shown(id) ?? []);
|
|
132
137
|
if (boxes.length === 0)
|
|
133
138
|
return null;
|
|
@@ -171,13 +176,18 @@ function cellsPlacesOf(marks, { boxes, digest }, byId, cells) {
|
|
|
171
176
|
const same = ({ item, slot }) => item === place?.item && slot === place.slot;
|
|
172
177
|
const row = boxes.find(same);
|
|
173
178
|
const cell = cells.find(same);
|
|
174
|
-
if (
|
|
179
|
+
if (cell === undefined)
|
|
175
180
|
return null;
|
|
176
181
|
const { left, top, width, height } = cell.box;
|
|
182
|
+
const frame = { minX: left, minY: top, maxX: left + width, maxY: top + height };
|
|
183
|
+
// A box the submission found empty is framed alone (the second 2026-11-03 amendment to R74
|
|
184
|
+
// spec; R39).
|
|
185
|
+
if (row === undefined)
|
|
186
|
+
return { ids: [], box: frame, cell: frame };
|
|
177
187
|
return {
|
|
178
188
|
ids: [...row.ids].sort(byNumber),
|
|
179
189
|
box: boxOf(row.ids.flatMap((id) => byId.get(id)?.points ?? [])),
|
|
180
|
-
cell:
|
|
190
|
+
cell: frame,
|
|
181
191
|
};
|
|
182
192
|
});
|
|
183
193
|
}
|
package/lib/element/index.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ import { type Task, type Tool } from "../core/task.js";
|
|
|
10
10
|
* CanvasElement has it, what its events tell and the work it gives for checking, here, and the data
|
|
11
11
|
* — the history of writing, the context of a submission, the filled slots and the state of a demo
|
|
12
12
|
* — through the DOM-free part. The entry point gives them under spec's names, the same types, the
|
|
13
|
-
* media
|
|
14
|
-
* element's own (R26, R41).
|
|
13
|
+
* media (T73) and the tutor's marks (T16) too. The crop and a task with its temporary tools are
|
|
14
|
+
* the element's own (R26, R41).
|
|
15
15
|
*/
|
|
16
16
|
export type { Box, CanvasElement, CanvasEventMap, DemoChangeEvent, ExportedCell, ExportedSheet, ExportedWork, ExportedWorkbook, HistoryChange, HistoryChangeEvent, Media, ToolChange, ToolChangeEvent, } from "@altnovatrail/spec/canvas";
|
|
17
17
|
export type { Filled, Filling } from "../core/boxes.js";
|
|
@@ -28,7 +28,7 @@ export type { Canvas, Task, Tool } from "../core/task.js";
|
|
|
28
28
|
export declare const TAG = "novatrail-canvas";
|
|
29
29
|
/**
|
|
30
30
|
* The element `<novatrail-canvas>`: the contract's `CanvasElement` (R74 spec), and beyond it the
|
|
31
|
-
*
|
|
31
|
+
* commands undo and clear, which the contract does not name.
|
|
32
32
|
*/
|
|
33
33
|
export declare class NovatrailCanvas extends HTMLElement implements CanvasElement {
|
|
34
34
|
#private;
|
|
@@ -159,9 +159,10 @@ export declare class NovatrailCanvas extends HTMLElement implements CanvasElemen
|
|
|
159
159
|
* workbook where an answer cell is, by its item and its slot (R39). A mark holds on to the
|
|
160
160
|
* strokes the model saw there and is drawn around those of them the sheet shows, as they are now
|
|
161
161
|
* — a cell's around its box too: new strokes do not move it, and when all of them are erased it
|
|
162
|
-
* is gone, till undo brings them back. A box
|
|
163
|
-
*
|
|
164
|
-
*
|
|
162
|
+
* is gone, till undo brings them back. A box of a workbook that was empty is framed alone (the
|
|
163
|
+
* second 2026-11-03 amendment to R74 spec). A box that comes near no stroke, and a cell on a
|
|
164
|
+
* sheet, which takes no zones, have no frame: the question is asked without one. The type is
|
|
165
|
+
* spec's (R83 spec; T16). A submission goes
|
|
165
166
|
* back to a sheet whose history holds its strokes, as its digest tells (R27), and a workbook's
|
|
166
167
|
* to a page of its boxes: one of other strokes or other boxes is a TypeError, and so are marks
|
|
167
168
|
* given before the task and the history they hold on to, and marks that are not marks. A new
|
package/lib/element/index.js
CHANGED
|
@@ -253,7 +253,7 @@ function htmlLayer(name) {
|
|
|
253
253
|
}
|
|
254
254
|
/**
|
|
255
255
|
* The element `<novatrail-canvas>`: the contract's `CanvasElement` (R74 spec), and beyond it the
|
|
256
|
-
*
|
|
256
|
+
* commands undo and clear, which the contract does not name.
|
|
257
257
|
*/
|
|
258
258
|
export class NovatrailCanvas extends HTMLElement {
|
|
259
259
|
#viewport = document.createElement("div");
|
|
@@ -744,9 +744,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
744
744
|
* workbook where an answer cell is, by its item and its slot (R39). A mark holds on to the
|
|
745
745
|
* strokes the model saw there and is drawn around those of them the sheet shows, as they are now
|
|
746
746
|
* — a cell's around its box too: new strokes do not move it, and when all of them are erased it
|
|
747
|
-
* is gone, till undo brings them back. A box
|
|
748
|
-
*
|
|
749
|
-
*
|
|
747
|
+
* is gone, till undo brings them back. A box of a workbook that was empty is framed alone (the
|
|
748
|
+
* second 2026-11-03 amendment to R74 spec). A box that comes near no stroke, and a cell on a
|
|
749
|
+
* sheet, which takes no zones, have no frame: the question is asked without one. The type is
|
|
750
|
+
* spec's (R83 spec; T16). A submission goes
|
|
750
751
|
* back to a sheet whose history holds its strokes, as its digest tells (R27), and a workbook's
|
|
751
752
|
* to a page of its boxes: one of other strokes or other boxes is a TypeError, and so are marks
|
|
752
753
|
* given before the task and the history they hold on to, and marks that are not marks. A new
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altnovatrail/canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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,11 +26,12 @@
|
|
|
26
26
|
"./lib/element/index.js"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@altnovatrail/spec": "0.
|
|
29
|
+
"@altnovatrail/spec": "0.9.8",
|
|
30
30
|
"perfect-freehand": "1.2.3",
|
|
31
31
|
"rbush": "4.0.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@altnovatrail/contracts": "0.9.8",
|
|
34
35
|
"@biomejs/biome": "2.6.4",
|
|
35
36
|
"@iconify-json/material-symbols": "1.2.97",
|
|
36
37
|
"@iconify/utils": "3.1.7",
|