@altnovatrail/canvas 0.3.10 → 0.3.12

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 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.14.0), 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.
20
+ A component of [NovaTrail](https://github.com/altnovatrail/spec/tree/v0.15.0), 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. 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 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 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. 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 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 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.14.0), checked out here as a git submodule at `v0.14.0`: clone this repository with `git clone --recurse-submodules`.
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.14.0), checked out here as a git submodule at `v0.15.0`: clone this repository with `git clone --recurse-submodules`.
84
84
 
85
85
  ## License
86
86
 
@@ -100,8 +100,13 @@ const UP_DOWN = 4 / 5;
100
100
  // Above the column, as wide, stands the row of the element's own buttons, outside the container's
101
101
  // scrolling: it sticks to the top of whatever scrolls the element, as far down as the consumer's
102
102
  // --novatrail-canvas-top says, while the element is in sight, over the sheet as it scrolls by
103
- // (R28). The element is as tall as the row, the statement and the sheet unless it is given a
104
- // height: then the statement and the sheet scroll in it, under the row. A worked example's open
103
+ // (R28). In a low window, where the row would cover more than a quarter of what it sticks in, it
104
+ // stands in its place instead, `loose`, and goes with the scrolling (1.4.10, 2.4.11). A button in
105
+ // focus shows a ring in the ink's colour, two pixels out, that the row's side margins keep on its
106
+ // paper; an unavailable one is paler by its colour, not its opacity, which would pale the ring too
107
+ // (2.4.7, 1.4.11). Nothing in the element moves but the scrolling, which jumps (2.3.3). The
108
+ // element is as tall as the row, the statement and the sheet unless it is given a height: then
109
+ // the statement and the sheet scroll in it, under the row. A worked example's open
105
110
  // parts stand between the statement and the sheet, and the region that tells of them is out of
106
111
  // sight, but not out of the tree a screen reader reads, where a hidden region would tell nothing
107
112
  // (R42). A picture's frame there stands in its item's line, from its top, so that the item's
@@ -130,9 +135,10 @@ const STYLE = `
130
135
  .tools {
131
136
  position: sticky; top: var(--novatrail-canvas-top, 0px); z-index: 1; flex: none;
132
137
  box-sizing: border-box; width: min(100%, ${K_MAX * SHEET.width}px); margin: 0 auto;
133
- padding: 8px 0; display: flex; flex-wrap: wrap; gap: 8px;
138
+ padding: 8px 4px; display: flex; flex-wrap: wrap; gap: 8px;
134
139
  background: var(--novatrail-canvas-paper, ${PAPER}); color: var(--novatrail-canvas-ink, ${INK});
135
140
  }
141
+ .tools.loose { position: static; }
136
142
  .tools .demo, .tools .choice, .tools .updown {
137
143
  display: flex; gap: 8px; margin-inline-end: 16px;
138
144
  }
@@ -145,7 +151,18 @@ const STYLE = `
145
151
  background: var(--novatrail-canvas-ink, ${INK}); color: var(--novatrail-canvas-paper, ${PAPER});
146
152
  border-color: var(--novatrail-canvas-ink, ${INK});
147
153
  }
148
- .tools [aria-disabled="true"] { opacity: 0.4; cursor: default; }
154
+ .tools button:focus-visible {
155
+ outline: 2px solid var(--novatrail-canvas-ink, ${INK}); outline-offset: 2px;
156
+ }
157
+ .tools [aria-disabled="true"] {
158
+ color: color-mix(
159
+ in srgb, var(--novatrail-canvas-ink, ${INK}) 40%, var(--novatrail-canvas-paper, ${PAPER})
160
+ );
161
+ cursor: default;
162
+ }
163
+ @supports not (color: color-mix(in srgb, red 40%, blue)) {
164
+ .tools [aria-disabled="true"] { opacity: 0.4; }
165
+ }
149
166
  .tools [hidden] { display: none; }
150
167
  .tools button svg {
151
168
  display: inline-block; width: 1.125em; height: 1.125em; margin-inline-end: 4px;
@@ -224,7 +241,8 @@ canvas {
224
241
  .tools [aria-checked="true"] {
225
242
  background: Highlight; color: HighlightText; border-color: Highlight;
226
243
  }
227
- .tools [aria-disabled="true"] { color: GrayText; border-color: GrayText; opacity: 1; }
244
+ .tools [aria-disabled="true"] { color: GrayText; border-color: GrayText; }
245
+ .tools button:focus-visible { outline-color: Highlight; }
228
246
  }
229
247
  `;
230
248
  /** The sheet of STYLE that the elements of a document adopt, made by the first of them there. */
@@ -362,12 +380,27 @@ export class NovatrailCanvas extends HTMLElement {
362
380
  */
363
381
  #heard = (event) => {
364
382
  const target = event.target;
365
- if (target === document || (target instanceof Element && holds(target, this)))
383
+ if (target === document || (target instanceof Element && holds(target, this))) {
384
+ // A new --novatrail-canvas-top changes no size: the next scroll is the first to hear of it,
385
+ // by one read of the row's style, and only a new offset asks anew whether the row sticks.
386
+ if (getComputedStyle(this.#tools.element).top !== this.#topSeen)
387
+ this.#stick();
366
388
  this.#edges();
389
+ }
367
390
  };
368
- /** The page grown or shrunk, or the window: what scrolls the element may have room now, or none. */
369
- #page = new ResizeObserver(() => this.#edges());
370
- #resized = () => this.#edges();
391
+ /**
392
+ * The page grown or shrunk, or the window, the scroller the row sticks in or the row itself: what
393
+ * scrolls the element may have room now, or none, and the row may cover too much of it to stick.
394
+ */
395
+ #resized = () => {
396
+ this.#stick();
397
+ this.#edges();
398
+ };
399
+ #page = new ResizeObserver(this.#resized);
400
+ /** The scroll container the row sticks in, which `#page` watches, or null for the page's viewport. */
401
+ #port = null;
402
+ /** The row's `top` as the last check of whether it sticks read it: the consumer's offset. */
403
+ #topSeen = "";
371
404
  #unwatchPen;
372
405
  #tool = "pen";
373
406
  #task;
@@ -829,6 +862,9 @@ export class NovatrailCanvas extends HTMLElement {
829
862
  // page that grows or shrinks scrolls nothing, and neither does a window of another size.
830
863
  document.addEventListener("scroll", this.#heard, { capture: true, passive: true });
831
864
  this.#page.observe(document.documentElement);
865
+ // The row wraps anew with the element's width, its language, the canvas kind and the finger's
866
+ // button, and grows or shrinks.
867
+ this.#page.observe(this.#tools.element);
832
868
  window.addEventListener("resize", this.#resized);
833
869
  this.#refresh();
834
870
  }
@@ -920,6 +956,7 @@ export class NovatrailCanvas extends HTMLElement {
920
956
  this.#unwatchPen = undefined;
921
957
  document.removeEventListener("scroll", this.#heard, { capture: true });
922
958
  this.#page.disconnect();
959
+ this.#port = null;
923
960
  window.removeEventListener("resize", this.#resized);
924
961
  // A stroke that ended here may be the one the other rows of the page waited for.
925
962
  PEN_MODE.settle();
@@ -1275,7 +1312,8 @@ export class NovatrailCanvas extends HTMLElement {
1275
1312
  * on the screen, after whatever transform the page puts on the element. The container's
1276
1313
  * rectangle gives the part of the canvas it shows: with the statement in sight, the canvas
1277
1314
  * goes on below the container's bottom. The row of buttons above the container hides what it
1278
- * covers, once it sticks over the sheet as the page scrolls the element by (R28).
1315
+ * covers, once it sticks over the sheet as the page scrolls the element by (R28); in its place,
1316
+ * in a low window, it stands above the container and hides nothing of it.
1279
1317
  */
1280
1318
  #view() {
1281
1319
  const canvas = this.#canvas.getBoundingClientRect();
@@ -1328,8 +1366,9 @@ export class NovatrailCanvas extends HTMLElement {
1328
1366
  }
1329
1367
  /**
1330
1368
  * How much of what a scroller shows is in sight, down the screen: within the ancestors that clip
1331
- * it and the visual viewport, and below the row of buttons while the row sticks over its top. A
1332
- * scroller out of sight counts whole.
1369
+ * it and the visual viewport, and below the row of buttons while the row sticks over its top, or
1370
+ * below the consumer's band, --novatrail-canvas-top, while the row stands in its place in a low
1371
+ * window. A scroller out of sight counts whole.
1333
1372
  */
1334
1373
  #seen(target) {
1335
1374
  const sight = window.visualViewport;
@@ -1350,14 +1389,57 @@ export class NovatrailCanvas extends HTMLElement {
1350
1389
  bottom = Math.min(bottom, clip.bottom);
1351
1390
  }
1352
1391
  }
1353
- // The row hides the top while it sticks there, as far down as the consumer's offset puts it.
1392
+ // The row hides the top while it sticks there, as far down as the consumer's offset puts it. A
1393
+ // row that stands in its place, in a low window, leaves the consumer's band over it alone.
1354
1394
  const row = this.#tools.element;
1355
- const box = row.getBoundingClientRect();
1356
- if (box.top <= top + (Number.parseFloat(getComputedStyle(row).top) || 0) + 0.5) {
1357
- top = Math.max(top, box.bottom);
1395
+ if (this.#tools.sticks) {
1396
+ const box = row.getBoundingClientRect();
1397
+ if (box.top <= top + offsetOf(row, 0) * scaleOf(row, box) + 0.5) {
1398
+ top = Math.max(top, box.bottom);
1399
+ }
1400
+ }
1401
+ else {
1402
+ top = Math.max(top, this.#band(target));
1358
1403
  }
1359
1404
  return bottom > top ? bottom - top : whole;
1360
1405
  }
1406
+ /**
1407
+ * Whether the row sticks (R28): while it is no taller than a quarter of what it sticks in, below
1408
+ * the consumer's offset. In a lower window, or once it wraps over more of it, it stands in its
1409
+ * place, above the statement, and goes with the scrolling, as WCAG's technique C34 un-fixes a
1410
+ * sticky header (1.4.10, 2.4.11). Its place and its size are the same either way, so the choice
1411
+ * changes nothing it is made from. The scroller it sticks in is watched for its size. Only an
1412
+ * element on the page asks: what calls this goes when the element leaves it.
1413
+ */
1414
+ #stick() {
1415
+ const room = roomOf(this.#tools.element);
1416
+ if (room.port !== this.#port) {
1417
+ if (this.#port !== null)
1418
+ this.#page.unobserve(this.#port);
1419
+ if (room.port !== null)
1420
+ this.#page.observe(room.port);
1421
+ this.#port = room.port;
1422
+ }
1423
+ const row = this.#tools.element;
1424
+ const tall = row.getBoundingClientRect().height;
1425
+ if (tall > 0 && room.height > 0)
1426
+ this.#tools.stick(4 * tall <= room.height - room.offset);
1427
+ this.#topSeen = getComputedStyle(row).top;
1428
+ }
1429
+ /**
1430
+ * Where the consumer's band over the top of what the row sticks in ends, down the screen: its
1431
+ * offset, --novatrail-canvas-top, below the top of the scroller or of the window — for a target
1432
+ * that is or lies within what the row sticks in, and above everything for any other.
1433
+ */
1434
+ #band(target) {
1435
+ const room = roomOf(this.#tools.element);
1436
+ // The band stands over the top of what the row sticks in, and so over a scroller within it,
1437
+ // but not over the page's when the row sticks in a scroller of its own.
1438
+ const within = room.port === null
1439
+ ? target !== undefined
1440
+ : target instanceof Element && (target === room.port || holds(room.port, target));
1441
+ return within ? room.top + room.offset : Number.NEGATIVE_INFINITY;
1442
+ }
1361
1443
  /**
1362
1444
  * Up and Down as the scrolling now is (R33): each stands unavailable while what two fingers would
1363
1445
  * scroll its way can go no further. The element hears its container, the page and the ancestors
@@ -1400,13 +1482,9 @@ export class NovatrailCanvas extends HTMLElement {
1400
1482
  if (scrollsOn(this.#viewport, onward)) {
1401
1483
  return { target: this.#viewport, scale: scaleOf(this.#viewport), rest: 0 };
1402
1484
  }
1403
- // The viewport takes the root's overflow, or the body's when the root's is visible (CSS
1404
- // Overflow 3): then the body scrolls nothing of its own, and the page scrolls only as it allows.
1405
- const root = getComputedStyle(document.documentElement).overflowY;
1406
- const body = document.body === null ? "visible" : getComputedStyle(document.body).overflowY;
1407
- const fromBody = root === "visible" && body !== "visible";
1485
+ const { overflow, fromBody } = pageOverflow();
1408
1486
  for (let node = parentOf(this); node !== null; node = parentOf(node)) {
1409
- if (node === document.documentElement || (fromBody && node === document.body))
1487
+ if (isPage(node, fromBody))
1410
1488
  break;
1411
1489
  const style = getComputedStyle(node);
1412
1490
  if (!SCROLLING.test(style.overflowY))
@@ -1419,7 +1497,6 @@ export class NovatrailCanvas extends HTMLElement {
1419
1497
  }
1420
1498
  }
1421
1499
  // A page that hides its overflow, as one under a modal does, a finger would not scroll: nor do two.
1422
- const overflow = fromBody ? body : root;
1423
1500
  if (overflow === "hidden" || overflow === "clip")
1424
1501
  return undefined;
1425
1502
  const page = document.scrollingElement;
@@ -1631,7 +1708,9 @@ export class NovatrailCanvas extends HTMLElement {
1631
1708
  /**
1632
1709
  * An item of the list, or an area of the sheet, comes into sight at once, as near as it is (R42),
1633
1710
  * and then out from under the row of buttons, should the row stick over where it came to: what
1634
- * scrolls back up goes back as far as the row covers it. A margin of scrolling would hold for
1711
+ * scrolls back up goes back as far as the row covers it. A row in its place, in a low window,
1712
+ * covers nothing, and the consumer's band, --novatrail-canvas-top, is what it comes out from
1713
+ * under then. A margin of scrolling would hold for
1635
1714
  * every scroller of the chain alike — the sheet's container, which the row stands above, and the
1636
1715
  * page, which it sticks over. An area of the sheet taller than what is in sight comes by its top
1637
1716
  * from below, but by its bottom from above, and then the row's cover brings its top back into
@@ -1643,10 +1722,14 @@ export class NovatrailCanvas extends HTMLElement {
1643
1722
  // the chain goes once.
1644
1723
  const gone = new Set();
1645
1724
  for (;;) {
1646
- const row = this.#tools.element.getBoundingClientRect();
1647
- const cover = row.bottom - item.getBoundingClientRect().top;
1648
- const latch = cover > 0.5 ? this.#scrollerFor(false) : undefined;
1649
- if (latch === undefined || gone.has(latch.target))
1725
+ const latch = this.#scrollerFor(false);
1726
+ // A row in its place, in a low window, covers nothing of it: the consumer's band may, over
1727
+ // what the row sticks in.
1728
+ const over = this.#tools.sticks
1729
+ ? this.#tools.element.getBoundingClientRect().bottom
1730
+ : this.#band(latch?.target);
1731
+ const cover = over - item.getBoundingClientRect().top;
1732
+ if (cover <= 0.5 || latch === undefined || gone.has(latch.target))
1650
1733
  return;
1651
1734
  gone.add(latch.target);
1652
1735
  latch.target.scrollBy({ top: -cover / latch.scale, behavior: "instant" });
@@ -1926,6 +2009,67 @@ function contactOf(event) {
1926
2009
  }
1927
2010
  /** The values of `overflow-y` that make an element scroll its content. */
1928
2011
  const SCROLLING = /^(auto|scroll|overlay)$/;
2012
+ /**
2013
+ * The values of `overflow-y` that make an element a scroll container, which a sticky box sticks in:
2014
+ * a hidden overflow too, which a script may scroll though no hand does (CSS Overflow 3).
2015
+ */
2016
+ const CONTAINING = /^(auto|scroll|overlay|hidden)$/;
2017
+ /**
2018
+ * The overflow of the page's viewport: the root's, or the body's when the root's is visible (CSS
2019
+ * Overflow 3), and then the body scrolls nothing of its own.
2020
+ */
2021
+ function pageOverflow() {
2022
+ const root = getComputedStyle(document.documentElement).overflowY;
2023
+ const body = document.body === null ? "visible" : getComputedStyle(document.body).overflowY;
2024
+ const fromBody = root === "visible" && body !== "visible";
2025
+ return { overflow: fromBody ? body : root, fromBody };
2026
+ }
2027
+ /** Whether an ancestor on the way up is where the page's viewport takes over. */
2028
+ function isPage(node, fromBody) {
2029
+ return node === document.documentElement || (fromBody && node === document.body);
2030
+ }
2031
+ /**
2032
+ * The scroll container a sticky box sticks in: its nearest ancestor in the flat tree that is one,
2033
+ * or null for the page's viewport.
2034
+ */
2035
+ function stickyPortOf(element) {
2036
+ const { fromBody } = pageOverflow();
2037
+ let node = parentOf(element);
2038
+ while (node !== null && !isPage(node, fromBody)) {
2039
+ if (CONTAINING.test(getComputedStyle(node).overflowY))
2040
+ return node;
2041
+ node = parentOf(node);
2042
+ }
2043
+ return null;
2044
+ }
2045
+ /**
2046
+ * What a sticky box sticks in, on the screen: the scroll container, or null for the page's
2047
+ * viewport, its top and its height — the viewport's without its scroll bar, which does not change
2048
+ * as a phone's toolbar of the browser comes and goes — and the box's offset below that top.
2049
+ */
2050
+ function roomOf(element) {
2051
+ const port = stickyPortOf(element);
2052
+ const laid = port === null ? (document.scrollingElement?.clientHeight ?? 0) : port.clientHeight;
2053
+ const own = port === null ? undefined : clientBoxOf(port);
2054
+ return {
2055
+ port,
2056
+ top: own?.top ?? 0,
2057
+ height: own === undefined ? laid : own.bottom - own.top,
2058
+ offset: offsetOf(element, laid) * scaleOf(element),
2059
+ };
2060
+ }
2061
+ /**
2062
+ * How far below the top of what it sticks in a sticky box stands, by its `top`, in CSS pixels as
2063
+ * laid out: a percentage of the scroller's `height`, and nothing for `auto`. A sticky box's `top`
2064
+ * reads as the pixels it is used at, a static one's as it was given.
2065
+ */
2066
+ function offsetOf(element, height) {
2067
+ const top = getComputedStyle(element).top;
2068
+ const value = Number.parseFloat(top);
2069
+ if (!Number.isFinite(value))
2070
+ return 0;
2071
+ return top.endsWith("%") ? (value / 100) * height : value;
2072
+ }
1929
2073
  /** Whether an element can scroll on down its content, for `onward`, or back up it. */
1930
2074
  function scrollsOn(element, onward) {
1931
2075
  const end = element.scrollHeight - element.clientHeight;
@@ -57,6 +57,14 @@ export declare class Tools {
57
57
  * nowhere to go stands unavailable. Only what has changed is written.
58
58
  */
59
59
  edges(above: boolean, below: boolean): void;
60
+ /**
61
+ * Whether the row sticks over what scrolls the element (R28): in a low window it stands in its
62
+ * place instead, above the statement, and scrolls away with it. The same state writes nothing:
63
+ * a token forced to what it is already changes no attribute.
64
+ */
65
+ stick(sticks: boolean): void;
66
+ /** Whether the row sticks, or stands in its place in a low window. */
67
+ get sticks(): boolean;
60
68
  /**
61
69
  * The labels in the language of a tag — the element's `lang` — and the row's own `lang` theirs,
62
70
  * so that a screen reader reads them in the language they are in.
@@ -151,6 +151,18 @@ export class Tools {
151
151
  write(this.#up, "aria-disabled", above ? null : "true");
152
152
  write(this.#down, "aria-disabled", below ? null : "true");
153
153
  }
154
+ /**
155
+ * Whether the row sticks over what scrolls the element (R28): in a low window it stands in its
156
+ * place instead, above the statement, and scrolls away with it. The same state writes nothing:
157
+ * a token forced to what it is already changes no attribute.
158
+ */
159
+ stick(sticks) {
160
+ this.element.classList.toggle("loose", !sticks);
161
+ }
162
+ /** Whether the row sticks, or stands in its place in a low window. */
163
+ get sticks() {
164
+ return !this.element.classList.contains("loose");
165
+ }
154
166
  /**
155
167
  * The labels in the language of a tag — the element's `lang` — and the row's own `lang` theirs,
156
168
  * so that a screen reader reads them in the language they are in.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altnovatrail/canvas",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
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.14.0",
29
+ "@altnovatrail/spec": "0.15.0",
30
30
  "perfect-freehand": "1.2.3",
31
31
  "rbush": "4.0.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@altnovatrail/contracts": "0.14.0",
34
+ "@altnovatrail/contracts": "0.15.0",
35
35
  "@biomejs/biome": "2.6.5",
36
36
  "@bufbuild/protobuf": "2.16.0",
37
37
  "@iconify-json/material-symbols": "1.2.97",