@altnovatrail/canvas 0.3.11 → 0.3.13

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
@@ -21,7 +21,7 @@ A component of [NovaTrail](https://github.com/altnovatrail/spec/tree/v0.15.0), a
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 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 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.
25
25
 
26
26
  ## Install
27
27
 
@@ -38,6 +38,13 @@ export declare const PAIR_MS = 150;
38
38
  * has gone further.
39
39
  */
40
40
  export declare const SLOP_PX = 8;
41
+ /**
42
+ * Two fingers that have gone this many times further along one axis than along the other, when
43
+ * they pass the slop, scroll along that axis alone for the rest of the gesture (T94): a scroll
44
+ * down a zoomed sheet does not wander sideways, nor one across it up and down. Between, they go
45
+ * both ways. T22 tries it on devices.
46
+ */
47
+ export declare const RAIL = 2;
41
48
  /**
42
49
  * The pen mode (R29): on from a pen's touch on a sheet, off when the learner asks for the finger.
43
50
  * While it is on, a finger neither writes nor erases. One is shared by every sheet of a page, and
@@ -70,10 +77,15 @@ export interface HandsSheet {
70
77
  /** The stroke or the erasing of a pointer goes, as on `pointercancel`. */
71
78
  drop(pointerId: number): void;
72
79
  /**
73
- * Two fingers moved down the screen by `dy` CSS pixels, or up for a negative one: the sheet goes
74
- * with them. `fresh` marks a gesture's first step.
80
+ * Two fingers moved right on the screen by `dx` CSS pixels and down it by `dy`, or left and up
81
+ * for negative ones: the sheet goes with them. `fresh` marks a gesture's first step.
82
+ */
83
+ scroll(dx: number, dy: number, fresh: boolean): void;
84
+ /**
85
+ * Whether the sheet scrolls across at all now: a zoomed sheet does (T94). A gesture on a sheet
86
+ * that does not goes by its travel down alone, as before.
75
87
  */
76
- scroll(dy: number, fresh: boolean): void;
88
+ across(): boolean;
77
89
  }
78
90
  /**
79
91
  * What a pointer down on the sheet does:
@@ -97,7 +109,8 @@ export type Role = "writes" | "waits" | "scrolls" | "palm" | "idle";
97
109
  * comes later does nothing.
98
110
  * - In pen mode a finger writes nothing, and two that come down within `PAIR_MS` scroll.
99
111
  * - A third finger does nothing. When one of the two lifts, the other does nothing until it lifts.
100
- * - Two fingers scroll by the travel of their middle down the screen, past the first `SLOP_PX`.
112
+ * - Two fingers scroll by the travel of their middle on the screen, past its first `SLOP_PX`: along
113
+ * one axis alone if they went `RAIL` times further along it than along the other, or else both.
101
114
  * - Any other pointer, a mouse or one of no type, writes when nothing does, whatever the mode.
102
115
  */
103
116
  export declare class Hands {
package/lib/core/hands.js CHANGED
@@ -15,6 +15,13 @@ export const PAIR_MS = 150;
15
15
  * has gone further.
16
16
  */
17
17
  export const SLOP_PX = 8;
18
+ /**
19
+ * Two fingers that have gone this many times further along one axis than along the other, when
20
+ * they pass the slop, scroll along that axis alone for the rest of the gesture (T94): a scroll
21
+ * down a zoomed sheet does not wander sideways, nor one across it up and down. Between, they go
22
+ * both ways. T22 tries it on devices.
23
+ */
24
+ export const RAIL = 2;
18
25
  /**
19
26
  * The pen mode (R29): on from a pen's touch on a sheet, off when the learner asks for the finger.
20
27
  * While it is on, a finger neither writes nor erases. One is shared by every sheet of a page, and
@@ -84,7 +91,8 @@ export class PenMode {
84
91
  * comes later does nothing.
85
92
  * - In pen mode a finger writes nothing, and two that come down within `PAIR_MS` scroll.
86
93
  * - A third finger does nothing. When one of the two lifts, the other does nothing until it lifts.
87
- * - Two fingers scroll by the travel of their middle down the screen, past the first `SLOP_PX`.
94
+ * - Two fingers scroll by the travel of their middle on the screen, past its first `SLOP_PX`: along
95
+ * one axis alone if they went `RAIL` times further along it than along the other, or else both.
88
96
  * - Any other pointer, a mouse or one of no type, writes when nothing does, whatever the mode.
89
97
  */
90
98
  export class Hands {
@@ -132,6 +140,7 @@ export class Hands {
132
140
  hand.role = "palm";
133
141
  return false;
134
142
  }
143
+ hand.x = contact.x;
135
144
  hand.y = contact.y;
136
145
  hand.travel = Math.max(hand.travel, Math.hypot(contact.x - hand.x0, contact.y - hand.y0));
137
146
  if (hand.role === "scrolls")
@@ -201,6 +210,7 @@ export class Hands {
201
210
  x0: contact.x,
202
211
  y0: contact.y,
203
212
  t0: contact.time,
213
+ x: contact.x,
204
214
  y: contact.y,
205
215
  travel: 0,
206
216
  });
@@ -227,7 +237,13 @@ export class Hands {
227
237
  return;
228
238
  one.role = "scrolls";
229
239
  two.role = "scrolls";
230
- this.#gesture = { fingers: [first, second], from: (one.y + two.y) / 2, last: undefined };
240
+ this.#gesture = {
241
+ fingers: [first, second],
242
+ from: middleOf(one, two),
243
+ last: undefined,
244
+ across: true,
245
+ down: true,
246
+ };
231
247
  }
232
248
  /** The gesture ends: its fingers do nothing until they lift. */
233
249
  #end() {
@@ -241,7 +257,10 @@ export class Hands {
241
257
  hand.role = "idle";
242
258
  }
243
259
  }
244
- /** The two fingers' middle has moved: past the slop, the sheet goes with it. */
260
+ /**
261
+ * The two fingers' middle has moved: past the slop, the sheet goes with it, along the axes the
262
+ * gesture chose as it passed it.
263
+ */
245
264
  #step() {
246
265
  const gesture = this.#gesture;
247
266
  if (gesture === undefined)
@@ -250,23 +269,34 @@ export class Hands {
250
269
  const two = this.#hands.get(gesture.fingers[1]);
251
270
  if (one === undefined || two === undefined)
252
271
  return;
253
- const middle = (one.y + two.y) / 2;
272
+ const middle = middleOf(one, two);
254
273
  if (gesture.last === undefined) {
255
- const gone = middle - gesture.from;
256
- if (Math.abs(gone) <= SLOP_PX)
274
+ // A sheet that does not scroll across counts the travel down alone, as before T94.
275
+ const dx = this.#sheet.across() ? middle.x - gesture.from.x : 0;
276
+ const dy = middle.y - gesture.from.y;
277
+ const gone = Math.hypot(dx, dy);
278
+ if (gone <= SLOP_PX)
257
279
  return;
258
- // The slop is where the gesture starts: the sheet moves from there, without a jump.
280
+ gesture.across = Math.abs(dx) * RAIL > Math.abs(dy);
281
+ gesture.down = Math.abs(dy) * RAIL > Math.abs(dx);
259
282
  gesture.last = middle;
260
- this.#sheet.scroll(gone - Math.sign(gone) * SLOP_PX, true);
283
+ // The slop is where the gesture starts: the sheet moves from there, without a jump, by the
284
+ // share of each axis's travel past it, along the axes the gesture goes.
285
+ const past = (d) => (d * (gone - SLOP_PX)) / gone;
286
+ this.#sheet.scroll(gesture.across ? past(dx) : 0, gesture.down ? past(dy) : 0, true);
261
287
  return;
262
288
  }
263
- if (middle === gesture.last)
264
- return;
265
- const dy = middle - gesture.last;
289
+ const dx = gesture.across ? middle.x - gesture.last.x : 0;
290
+ const dy = gesture.down ? middle.y - gesture.last.y : 0;
266
291
  gesture.last = middle;
267
- this.#sheet.scroll(dy, false);
292
+ if (dx !== 0 || dy !== 0)
293
+ this.#sheet.scroll(dx, dy, false);
268
294
  }
269
295
  }
296
+ /** The middle of two fingers on the screen. */
297
+ function middleOf(one, two) {
298
+ return { x: (one.x + two.x) / 2, y: (one.y + two.y) / 2 };
299
+ }
270
300
  /** Whether a touch is too big for a finger: a palm, or the side of a hand. */
271
301
  function isPalm(contact) {
272
302
  return contact.width > PALM_PX || contact.height > PALM_PX;
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * Where the sheet is on the screen, one view for every layer (R06; architecture 3.2 in
3
3
  * docs/architecture.md): `k` CSS pixels to a logical unit, for the sheet fits the width of its
4
- * area, and `vy`, the top of the sheet's visible part, in units.
4
+ * area times the page's zoom, and `vx` and `vy`, the left and the top of the sheet's visible part,
5
+ * in units (T94).
5
6
  */
6
7
  export interface View {
7
8
  readonly k: number;
9
+ readonly vx: number;
8
10
  readonly vy: number;
9
11
  }
10
12
  /** A point, on the sheet in logical units or on the screen in CSS pixels. */
@@ -13,18 +15,19 @@ export interface Point {
13
15
  readonly y: number;
14
16
  }
15
17
  /**
16
- * The most CSS pixels to a unit: on a wide screen the sheet is at most 1000 CSS pixels wide, a
17
- * pixel to a unit as on the picture of the work, and stands in the middle (R23).
18
+ * The most CSS pixels to a unit of the sheet's fit: on a wide screen the sheet fits at most 1000
19
+ * CSS pixels wide, a pixel to a unit as on the picture of the work, and stands in the middle (R23).
20
+ * The page's zoom takes it beyond that, to twice the fit (T94).
18
21
  */
19
22
  export declare const K_MAX = 1;
20
23
  /** `k` of a sheet `width` CSS pixels wide as it is on the screen: k = A / W. */
21
24
  export declare function scaleFor(width: number): number;
22
25
  /**
23
- * `k` for a sheet laid out in an area `width` CSS pixels wide: it fits the width, up to `K_MAX`.
24
- * This is the layout's `k`, before any transform the page puts on the element; input takes `k`
25
- * from the sheet's rectangle on the screen, by `scaleFor`.
26
+ * `k` for a sheet laid out in an area `width` CSS pixels wide: it fits the width, up to `K_MAX`,
27
+ * times the page's `zoom` (T94). This is the layout's `k`, before any transform the page puts on
28
+ * the element; input takes `k` from the sheet's rectangle on the screen, by `scaleFor`.
26
29
  */
27
- export declare function fitScale(width: number): number;
30
+ export declare function fitScale(width: number, zoom?: number): number;
28
31
  /**
29
32
  * The point of the sheet under a point of the screen, given in CSS pixels from the top left corner
30
33
  * of the sheet's visible part. A point beyond the sheet is clamped to its edge, as in spec 4.2 of
@@ -1,7 +1,8 @@
1
1
  import { SHEET } from "./sheet.js";
2
2
  /**
3
- * The most CSS pixels to a unit: on a wide screen the sheet is at most 1000 CSS pixels wide, a
4
- * pixel to a unit as on the picture of the work, and stands in the middle (R23).
3
+ * The most CSS pixels to a unit of the sheet's fit: on a wide screen the sheet fits at most 1000
4
+ * CSS pixels wide, a pixel to a unit as on the picture of the work, and stands in the middle (R23).
5
+ * The page's zoom takes it beyond that, to twice the fit (T94).
5
6
  */
6
7
  export const K_MAX = 1;
7
8
  /** `k` of a sheet `width` CSS pixels wide as it is on the screen: k = A / W. */
@@ -9,12 +10,12 @@ export function scaleFor(width) {
9
10
  return width / SHEET.width;
10
11
  }
11
12
  /**
12
- * `k` for a sheet laid out in an area `width` CSS pixels wide: it fits the width, up to `K_MAX`.
13
- * This is the layout's `k`, before any transform the page puts on the element; input takes `k`
14
- * from the sheet's rectangle on the screen, by `scaleFor`.
13
+ * `k` for a sheet laid out in an area `width` CSS pixels wide: it fits the width, up to `K_MAX`,
14
+ * times the page's `zoom` (T94). This is the layout's `k`, before any transform the page puts on
15
+ * the element; input takes `k` from the sheet's rectangle on the screen, by `scaleFor`.
15
16
  */
16
- export function fitScale(width) {
17
- return Math.min(width / SHEET.width, K_MAX);
17
+ export function fitScale(width, zoom = 1) {
18
+ return Math.min(width / SHEET.width, K_MAX) * zoom;
18
19
  }
19
20
  /**
20
21
  * The point of the sheet under a point of the screen, given in CSS pixels from the top left corner
@@ -23,13 +24,13 @@ export function fitScale(width) {
23
24
  */
24
25
  export function toSheet(view, x, y) {
25
26
  return {
26
- x: clamp(x / view.k, 0, SHEET.width),
27
+ x: clamp(x / view.k + view.vx, 0, SHEET.width),
27
28
  y: clamp(y / view.k + view.vy, 0, SHEET.height),
28
29
  };
29
30
  }
30
31
  /** The point of the screen over a point of the sheet, from the top left corner of its visible part. */
31
32
  export function toScreen(view, x, y) {
32
- return { x: x * view.k, y: (y - view.vy) * view.k };
33
+ return { x: (x - view.vx) * view.k, y: (y - view.vy) * view.k };
33
34
  }
34
35
  function clamp(value, low, high) {
35
36
  return Math.min(Math.max(value, low), high);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The zooms of the sheet, from its fit to twice it, by quarters (T94): the learner steps through
3
+ * them with the row's Zoom in and Zoom out, so that the workbook's printed lines, and the ink, can
4
+ * be read at 200 % (WCAG 1.4.4, by the technique G178; R90 spec).
5
+ */
6
+ export declare const ZOOMS: readonly number[];
7
+ /**
8
+ * The page's zoom (T94): one for every sheet of the page, from 100 % when the page is loaded, as
9
+ * the pen mode is (R29). The next task is a new element (R20), and the zoom stays: a learner who
10
+ * needs it larger asks once. It lives in memory alone: nothing is stored or sent.
11
+ */
12
+ export declare class PageZoom {
13
+ #private;
14
+ /** The zoom now: 1 for the fit, 2 for twice it. */
15
+ get value(): number;
16
+ /** Whether there is a larger zoom to step to, for Zoom in, or a smaller one, for Zoom out. */
17
+ get larger(): boolean;
18
+ get smaller(): boolean;
19
+ /** A step larger, for `larger`, or smaller, if there is one: every watcher hears of it. */
20
+ step(larger: boolean): boolean;
21
+ /** `watcher` hears of every change from now on, until the function this gives is called. */
22
+ watch(watcher: () => void): () => void;
23
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The zooms of the sheet, from its fit to twice it, by quarters (T94): the learner steps through
3
+ * them with the row's Zoom in and Zoom out, so that the workbook's printed lines, and the ink, can
4
+ * be read at 200 % (WCAG 1.4.4, by the technique G178; R90 spec).
5
+ */
6
+ export const ZOOMS = [1, 1.25, 1.5, 1.75, 2];
7
+ /**
8
+ * The page's zoom (T94): one for every sheet of the page, from 100 % when the page is loaded, as
9
+ * the pen mode is (R29). The next task is a new element (R20), and the zoom stays: a learner who
10
+ * needs it larger asks once. It lives in memory alone: nothing is stored or sent.
11
+ */
12
+ export class PageZoom {
13
+ #step = 0;
14
+ #watchers = new Set();
15
+ /** The zoom now: 1 for the fit, 2 for twice it. */
16
+ get value() {
17
+ return ZOOMS[this.#step] ?? 1;
18
+ }
19
+ /** Whether there is a larger zoom to step to, for Zoom in, or a smaller one, for Zoom out. */
20
+ get larger() {
21
+ return this.#step < ZOOMS.length - 1;
22
+ }
23
+ get smaller() {
24
+ return this.#step > 0;
25
+ }
26
+ /** A step larger, for `larger`, or smaller, if there is one: every watcher hears of it. */
27
+ step(larger) {
28
+ const step = this.#step + (larger ? 1 : -1);
29
+ if (step < 0 || step >= ZOOMS.length)
30
+ return false;
31
+ this.#step = step;
32
+ for (const watcher of [...this.#watchers])
33
+ watcher();
34
+ return true;
35
+ }
36
+ /** `watcher` hears of every change from now on, until the function this gives is called. */
37
+ watch(watcher) {
38
+ this.#watchers.add(watcher);
39
+ return () => {
40
+ this.#watchers.delete(watcher);
41
+ };
42
+ }
43
+ }
@@ -44,6 +44,22 @@ export declare const ICONS: {
44
44
  readonly viewBox: "0 0 24 24";
45
45
  readonly paths: readonly ["M11 16.175V5q0-.425.288-.712T12 4t.713.288T13 5v11.175l4.9-4.9q.3-.3.7-.288t.7.313q.275.3.287.7t-.287.7l-6.6 6.6q-.15.15-.325.213t-.375.062t-.375-.062t-.325-.213l-6.6-6.6q-.275-.275-.275-.687T4.7 11.3q.3-.3.713-.3t.712.3z"];
46
46
  };
47
+ readonly "zoom-in-outline-rounded": {
48
+ readonly viewBox: "0 0 24 24";
49
+ readonly paths: readonly ["M8.5 10.5h-1q-.425 0-.712-.288T6.5 9.5t.288-.712T7.5 8.5h1v-1q0-.425.288-.712T9.5 6.5t.713.288t.287.712v1h1q.425 0 .713.288t.287.712t-.288.713t-.712.287h-1v1q0 .425-.288.713T9.5 12.5t-.712-.288T8.5 11.5zm1 5.5q-2.725 0-4.612-1.888T3 9.5t1.888-4.612T9.5 3t4.613 1.888T16 9.5q0 1.1-.35 2.075T14.7 13.3l5.6 5.6q.275.275.275.7t-.275.7t-.7.275t-.7-.275l-5.6-5.6q-.75.6-1.725.95T9.5 16m0-2q1.875 0 3.188-1.312T14 9.5t-1.312-3.187T9.5 5T6.313 6.313T5 9.5t1.313 3.188T9.5 14"];
50
+ };
51
+ readonly "zoom-out-outline-rounded": {
52
+ readonly viewBox: "0 0 24 24";
53
+ readonly paths: readonly ["M8 10.5q-.425 0-.712-.288T7 9.5t.288-.712T8 8.5h3q.425 0 .713.288T12 9.5t-.288.713T11 10.5zM9.5 16q-2.725 0-4.612-1.888T3 9.5t1.888-4.612T9.5 3t4.613 1.888T16 9.5q0 1.1-.35 2.075T14.7 13.3l5.6 5.6q.275.275.275.7t-.275.7t-.7.275t-.7-.275l-5.6-5.6q-.75.6-1.725.95T9.5 16m0-2q1.875 0 3.188-1.312T14 9.5t-1.312-3.187T9.5 5T6.313 6.313T5 9.5t1.313 3.188T9.5 14"];
54
+ };
55
+ readonly "arrow-left-alt-outline-rounded": {
56
+ readonly viewBox: "0 0 24 24";
57
+ readonly paths: readonly ["m7.85 13l2.85 2.85q.3.3.288.7t-.288.7q-.3.3-.712.313t-.713-.288L4.7 12.7q-.3-.3-.3-.7t.3-.7l4.575-4.575q.3-.3.713-.287t.712.312q.275.3.288.7t-.288.7L7.85 11H19q.425 0 .713.288T20 12t-.288.713T19 13z"];
58
+ };
59
+ readonly "arrow-right-alt-outline-rounded": {
60
+ readonly viewBox: "0 0 24 24";
61
+ readonly paths: readonly ["M16.15 13H5q-.425 0-.712-.288T4 12t.288-.712T5 11h11.15L13.3 8.15q-.3-.3-.288-.7t.288-.7q.3-.3.713-.312t.712.287L19.3 11.3q.15.15.213.325t.062.375t-.062.375t-.213.325l-4.575 4.575q-.3.3-.712.288t-.713-.313q-.275-.3-.288-.7t.288-.7z"];
62
+ };
47
63
  readonly "touch-app-outline-rounded": {
48
64
  readonly viewBox: "0 0 24 24";
49
65
  readonly paths: readonly ["M10.475 22q-.7 0-1.312-.3t-1.038-.85L3.1 14.475q-.2-.225-.175-.537t.225-.513q.5-.525 1.2-.625t1.3.275L7.5 14.2V6q0-.425.288-.712T8.5 5t.725.288t.3.712v10q0 .575-.513.863T8 16.85l-.9-.55l2.6 3.325q.15.175.35.275t.425.1H16q.825 0 1.413-.587T18 18v-4q0-.425-.288-.712T17 13h-4.475q-.425 0-.712-.288T11.525 12t.288-.712t.712-.288H17q1.25 0 2.125.875T20 14v4q0 1.65-1.175 2.825T16 22zm1.5-13q-.425 0-.712-.288T10.975 8q0-.05.125-.5q.2-.35.3-.712T11.5 6q0-1.25-.875-2.125T8.5 3t-2.125.875T5.5 6q0 .425.1.788t.3.712q.075.125.1.25t.025.25q0 .425-.275.713T5.05 9q-.275 0-.512-.15t-.363-.375q-.325-.55-.5-1.175T3.5 6q0-2.075 1.463-3.537T8.5 1t3.538 1.463T13.5 6q0 .675-.175 1.3t-.5 1.175q-.125.225-.35.375t-.5.15"];
@@ -102,6 +118,26 @@ export declare const ROW: {
102
118
  readonly filled: "arrow-downward-outline-rounded";
103
119
  readonly mirrored: false;
104
120
  };
121
+ readonly zoomIn: {
122
+ readonly outline: "zoom-in-outline-rounded";
123
+ readonly filled: "zoom-in-outline-rounded";
124
+ readonly mirrored: false;
125
+ };
126
+ readonly zoomOut: {
127
+ readonly outline: "zoom-out-outline-rounded";
128
+ readonly filled: "zoom-out-outline-rounded";
129
+ readonly mirrored: false;
130
+ };
131
+ readonly left: {
132
+ readonly outline: "arrow-left-alt-outline-rounded";
133
+ readonly filled: "arrow-left-alt-outline-rounded";
134
+ readonly mirrored: false;
135
+ };
136
+ readonly right: {
137
+ readonly outline: "arrow-right-alt-outline-rounded";
138
+ readonly filled: "arrow-right-alt-outline-rounded";
139
+ readonly mirrored: false;
140
+ };
105
141
  readonly finger: {
106
142
  readonly outline: "touch-app-outline-rounded";
107
143
  readonly filled: "touch-app-outline-rounded";
@@ -70,6 +70,30 @@ export const ICONS = {
70
70
  "M11 16.175V5q0-.425.288-.712T12 4t.713.288T13 5v11.175l4.9-4.9q.3-.3.7-.288t.7.313q.275.3.287.7t-.287.7l-6.6 6.6q-.15.15-.325.213t-.375.062t-.375-.062t-.325-.213l-6.6-6.6q-.275-.275-.275-.687T4.7 11.3q.3-.3.713-.3t.712.3z",
71
71
  ],
72
72
  },
73
+ "zoom-in-outline-rounded": {
74
+ viewBox: "0 0 24 24",
75
+ paths: [
76
+ "M8.5 10.5h-1q-.425 0-.712-.288T6.5 9.5t.288-.712T7.5 8.5h1v-1q0-.425.288-.712T9.5 6.5t.713.288t.287.712v1h1q.425 0 .713.288t.287.712t-.288.713t-.712.287h-1v1q0 .425-.288.713T9.5 12.5t-.712-.288T8.5 11.5zm1 5.5q-2.725 0-4.612-1.888T3 9.5t1.888-4.612T9.5 3t4.613 1.888T16 9.5q0 1.1-.35 2.075T14.7 13.3l5.6 5.6q.275.275.275.7t-.275.7t-.7.275t-.7-.275l-5.6-5.6q-.75.6-1.725.95T9.5 16m0-2q1.875 0 3.188-1.312T14 9.5t-1.312-3.187T9.5 5T6.313 6.313T5 9.5t1.313 3.188T9.5 14",
77
+ ],
78
+ },
79
+ "zoom-out-outline-rounded": {
80
+ viewBox: "0 0 24 24",
81
+ paths: [
82
+ "M8 10.5q-.425 0-.712-.288T7 9.5t.288-.712T8 8.5h3q.425 0 .713.288T12 9.5t-.288.713T11 10.5zM9.5 16q-2.725 0-4.612-1.888T3 9.5t1.888-4.612T9.5 3t4.613 1.888T16 9.5q0 1.1-.35 2.075T14.7 13.3l5.6 5.6q.275.275.275.7t-.275.7t-.7.275t-.7-.275l-5.6-5.6q-.75.6-1.725.95T9.5 16m0-2q1.875 0 3.188-1.312T14 9.5t-1.312-3.187T9.5 5T6.313 6.313T5 9.5t1.313 3.188T9.5 14",
83
+ ],
84
+ },
85
+ "arrow-left-alt-outline-rounded": {
86
+ viewBox: "0 0 24 24",
87
+ paths: [
88
+ "m7.85 13l2.85 2.85q.3.3.288.7t-.288.7q-.3.3-.712.313t-.713-.288L4.7 12.7q-.3-.3-.3-.7t.3-.7l4.575-4.575q.3-.3.713-.287t.712.312q.275.3.288.7t-.288.7L7.85 11H19q.425 0 .713.288T20 12t-.288.713T19 13z",
89
+ ],
90
+ },
91
+ "arrow-right-alt-outline-rounded": {
92
+ viewBox: "0 0 24 24",
93
+ paths: [
94
+ "M16.15 13H5q-.425 0-.712-.288T4 12t.288-.712T5 11h11.15L13.3 8.15q-.3-.3-.288-.7t.288-.7q.3-.3.713-.312t.712.287L19.3 11.3q.15.15.213.325t.062.375t-.062.375t-.213.325l-4.575 4.575q-.3.3-.712.288t-.713-.313q-.275-.3-.288-.7t.288-.7z",
95
+ ],
96
+ },
73
97
  "touch-app-outline-rounded": {
74
98
  viewBox: "0 0 24 24",
75
99
  paths: [
@@ -116,6 +140,26 @@ export const ROW = {
116
140
  filled: "arrow-downward-outline-rounded",
117
141
  mirrored: false,
118
142
  },
143
+ zoomIn: {
144
+ outline: "zoom-in-outline-rounded",
145
+ filled: "zoom-in-outline-rounded",
146
+ mirrored: false,
147
+ },
148
+ zoomOut: {
149
+ outline: "zoom-out-outline-rounded",
150
+ filled: "zoom-out-outline-rounded",
151
+ mirrored: false,
152
+ },
153
+ left: {
154
+ outline: "arrow-left-alt-outline-rounded",
155
+ filled: "arrow-left-alt-outline-rounded",
156
+ mirrored: false,
157
+ },
158
+ right: {
159
+ outline: "arrow-right-alt-outline-rounded",
160
+ filled: "arrow-right-alt-outline-rounded",
161
+ mirrored: false,
162
+ },
119
163
  finger: {
120
164
  outline: "touch-app-outline-rounded",
121
165
  filled: "touch-app-outline-rounded",