@altnovatrail/canvas 0.3.37 → 0.3.39

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.
@@ -7,7 +7,7 @@
7
7
  export interface Labels {
8
8
  readonly sheet: string;
9
9
  readonly workbook: string;
10
- /** A task from the learner's paper, its crop as tracing paper over a dotted sheet (R87). */
10
+ /** A task from the learner's paper, its crop as tracing paper over a sheet (R87). */
11
11
  readonly paper: string;
12
12
  /** A lesson's worked example, whose row has no tools of writing (R42). */
13
13
  readonly example: string;
@@ -15,7 +15,6 @@ export interface Labels {
15
15
  readonly sheetButtons: string;
16
16
  readonly workbookButtons: string;
17
17
  readonly paperButtons: string;
18
- readonly exampleButtons: string;
19
18
  /** The buttons of a worked example's demo: the next part, and the whole demo, shown or hidden. */
20
19
  readonly next: string;
21
20
  readonly demo: string;
@@ -24,15 +23,41 @@ export interface Labels {
24
23
  readonly eraser: string;
25
24
  readonly undo: string;
26
25
  readonly clear: string;
27
- /** The buttons of the page's zoom, a step larger and a step smaller (R73). */
26
+ /** The tool that moves the sheet and writes nothing (R88). */
27
+ readonly hand: string;
28
+ /** The buttons of the page's zoom of the sheet, a step larger and a step smaller (R73). */
28
29
  readonly zoomIn: string;
29
30
  readonly zoomOut: string;
30
- /** The button that lets a finger write again, in pen mode (R29). */
31
- readonly finger: string;
31
+ /**
32
+ * The button of a task from paper's grid, by the grid the sheet shows now: a press turns it to
33
+ * the next (R88).
34
+ */
35
+ readonly gridDots: string;
36
+ readonly gridLines: string;
37
+ readonly gridBlank: string;
38
+ readonly gridSquares: string;
32
39
  /** The tracing paper's grip, and the button atop the tools that hides it or shows it (R87). */
33
40
  readonly moveTask: string;
34
41
  readonly hideTask: string;
35
42
  readonly showTask: string;
43
+ /**
44
+ * The tracing paper's bar of scale (R89): its name, smaller, larger, the scale as a percentage,
45
+ * {percent}, which a press sets back to its own size, and fit to the window.
46
+ */
47
+ readonly scaleButtons: string;
48
+ readonly smaller: string;
49
+ readonly larger: string;
50
+ readonly scaleReset: string;
51
+ readonly fit: string;
52
+ /**
53
+ * The reading of the statement in clean print (R89): its button, as it offers it, waits and
54
+ * offers the photo back, and the sign above the paper of what it shows.
55
+ */
56
+ readonly recognise: string;
57
+ readonly recognising: string;
58
+ readonly original: string;
59
+ readonly photoShown: string;
60
+ readonly readingShown: string;
36
61
  /** A box of a workbook's line, alone in it (R36). */
37
62
  readonly box: string;
38
63
  /** A box among several of its line, by its slot: {slot} (R36). */
@@ -9,7 +9,8 @@
9
9
  // categories, `other` always among them, chosen by `Intl.PluralRules` of the label's language;
10
10
  // - no label tells the learner's gender (R70 spec) or speaks as the AI in the first person (П-15);
11
11
  // - the buttons' words are those of spec's table of words, the two of the page's zoom among them
12
- // (R91 spec; R73); no button scrolls the sheet, so no label says a direction (R84).
12
+ // (R91 spec); no button scrolls the sheet, which the hand moves, so no label says a direction
13
+ // (R84; R88).
13
14
  // This module is no entry point of the package.
14
15
  /** The labels in English, the code's own language: those of any language the table has not. */
15
16
  const ENGLISH = Object.freeze({
@@ -20,7 +21,6 @@ const ENGLISH = Object.freeze({
20
21
  sheetButtons: "Sheet buttons",
21
22
  workbookButtons: "Workbook buttons",
22
23
  paperButtons: "Task from paper buttons",
23
- exampleButtons: "Worked example buttons",
24
24
  next: "Next",
25
25
  demo: "Demo",
26
26
  tool: "Tool",
@@ -28,12 +28,26 @@ const ENGLISH = Object.freeze({
28
28
  eraser: "Eraser",
29
29
  undo: "Undo",
30
30
  clear: "Clear",
31
+ hand: "Hand",
31
32
  zoomIn: "Zoom in",
32
33
  zoomOut: "Zoom out",
33
- finger: "Draw with finger",
34
+ gridDots: "Grid: dots",
35
+ gridLines: "Grid: lines",
36
+ gridBlank: "Grid: blank",
37
+ gridSquares: "Grid: squares",
34
38
  moveTask: "Move the task",
35
39
  hideTask: "Hide the task",
36
40
  showTask: "Show the task",
41
+ scaleButtons: "Task scale",
42
+ smaller: "Smaller",
43
+ larger: "Larger",
44
+ scaleReset: "{percent}: back to 100%",
45
+ fit: "Fit",
46
+ recognise: "Recognise",
47
+ recognising: "Recognising…",
48
+ original: "Original",
49
+ photoShown: "Photo of the task",
50
+ readingShown: "Recognised by AI",
37
51
  box: "Box",
38
52
  boxAt: "Box {slot}",
39
53
  boxIn: "Box {line}.{slot}",
@@ -57,7 +71,6 @@ const LABELS = new Map([
57
71
  sheetButtons: "Кнопки листа",
58
72
  workbookButtons: "Кнопки тетради",
59
73
  paperButtons: "Кнопки задачи с бумаги",
60
- exampleButtons: "Кнопки примера",
61
74
  next: "Дальше",
62
75
  demo: "Показ",
63
76
  tool: "Инструмент",
@@ -65,12 +78,26 @@ const LABELS = new Map([
65
78
  eraser: "Ластик",
66
79
  undo: "Отменить",
67
80
  clear: "Очистить",
81
+ hand: "Рука",
68
82
  zoomIn: "Крупнее",
69
83
  zoomOut: "Мельче",
70
- finger: "Рисовать пальцем",
84
+ gridDots: "Сетка: точки",
85
+ gridLines: "Сетка: строчки",
86
+ gridBlank: "Сетка: пусто",
87
+ gridSquares: "Сетка: клетки",
71
88
  moveTask: "Подвинуть задачу",
72
89
  hideTask: "Спрятать задачу",
73
90
  showTask: "Показать задачу",
91
+ scaleButtons: "Масштаб задачи",
92
+ smaller: "Уменьшить",
93
+ larger: "Увеличить",
94
+ scaleReset: "{percent}: вернуть 100 %",
95
+ fit: "Вписать",
96
+ recognise: "Распознать",
97
+ recognising: "Распознаём…",
98
+ original: "Оригинал",
99
+ photoShown: "Фото задачи",
100
+ readingShown: "Распознано ИИ",
74
101
  box: "Окошко",
75
102
  boxAt: "Окошко {slot}",
76
103
  boxIn: "Окошко {line}.{slot}",
@@ -0,0 +1,2 @@
1
+ /** The nodes of one statement's line. */
2
+ export declare function lineOf(statement: string): Node[];
@@ -0,0 +1,94 @@
1
+ import { formulaic, piecesOf } from "../core/notation.js";
2
+ // A statement read, drawn as the page prints it (R89): its text as text, a box an answer goes in
3
+ // as a dashed box, and a fraction or a power as MathML, which the browser lays out itself, a
4
+ // fraction full size on the line and those within it smaller, as a book sets them. In a statement
5
+ // with no word its lone letters are its unknowns, in italics as MathML sets a letter.
6
+ const MATHML = "http://www.w3.org/1998/Math/MathML";
7
+ /** The nodes of one statement's line. */
8
+ export function lineOf(statement) {
9
+ const letters = formulaic(statement);
10
+ const out = [];
11
+ for (const piece of piecesOf(statement)) {
12
+ if (piece.kind === "text")
13
+ out.push(...textOf(piece.text, letters));
14
+ else if (piece.kind === "box")
15
+ out.push(slot());
16
+ else {
17
+ const math = mathml("math");
18
+ math.setAttribute("displaystyle", "true");
19
+ math.append(mathOf(piece));
20
+ out.push(math);
21
+ }
22
+ }
23
+ return out;
24
+ }
25
+ /** Text of the line: in a formula, each lone letter in italics. */
26
+ function textOf(text, letters) {
27
+ if (!letters)
28
+ return [document.createTextNode(text)];
29
+ return text
30
+ .split(/(\p{L})/u)
31
+ .filter((part) => part !== "")
32
+ .map((part) => {
33
+ if (!/^\p{L}$/u.test(part))
34
+ return document.createTextNode(part);
35
+ const letter = document.createElement("i");
36
+ letter.textContent = part;
37
+ return letter;
38
+ });
39
+ }
40
+ /** A dashed box an answer goes in. */
41
+ function slot() {
42
+ const box = document.createElement("span");
43
+ box.className = "slot";
44
+ return box;
45
+ }
46
+ /** A piece as MathML. */
47
+ function mathOf(piece) {
48
+ switch (piece.kind) {
49
+ case "text":
50
+ return row(tokensOf(piece.text));
51
+ case "box": {
52
+ const box = mathml("mspace");
53
+ box.setAttribute("class", "slot");
54
+ // The box of the line's own, 1.08em square, its foot as far under the baseline.
55
+ box.setAttribute("width", "1.08em");
56
+ box.setAttribute("height", "0.86em");
57
+ box.setAttribute("depth", "0.22em");
58
+ return box;
59
+ }
60
+ case "fraction": {
61
+ const fraction = mathml("mfrac");
62
+ fraction.append(rowOf(piece.over), rowOf(piece.under));
63
+ return fraction;
64
+ }
65
+ case "power": {
66
+ const power = mathml("msup");
67
+ power.append(rowOf(piece.base), rowOf(piece.exponent));
68
+ return power;
69
+ }
70
+ }
71
+ }
72
+ /** Pieces as one row of MathML. */
73
+ function rowOf(pieces) {
74
+ return row(pieces.map(mathOf));
75
+ }
76
+ function row(children) {
77
+ const out = mathml("mrow");
78
+ out.append(...children);
79
+ return out;
80
+ }
81
+ /** Text as MathML's tokens: a number, a letter, and each other sign an operator; spaces dropped. */
82
+ function tokensOf(text) {
83
+ const out = [];
84
+ for (const [token] of text.matchAll(/\d+(?:[.,]\d+)?|\p{L}|\S/gu)) {
85
+ const kind = /^\d/.test(token) ? "mn" : /^\p{L}$/u.test(token) ? "mi" : "mo";
86
+ const element = mathml(kind);
87
+ element.textContent = token;
88
+ out.push(element);
89
+ }
90
+ return out;
91
+ }
92
+ function mathml(name) {
93
+ return document.createElementNS(MATHML, name);
94
+ }
@@ -1,8 +1,8 @@
1
1
  // The page's pen mode (R29) and its zoom (R73): one of each for every sheet of the page, the mode
2
- // from a pen's first touch on any of them until the learner asks for the finger, the zoom as the
3
- // learner last stepped it, till the page is loaded again. The next task is a new element (R20),
4
- // and both stay. They are states of the interface in memory, not data: nothing is stored or sent.
5
- // This module is no entry point of the package.
2
+ // from a pen's first touch on any of them, the zoom as the learner last set it, till the page is
3
+ // loaded again. The next task is a new element (R20), and both stay. They are states of the
4
+ // interface in memory, not data: nothing is stored or sent. This module is no entry point of the
5
+ // package.
6
6
  import { PenMode } from "../core/hands.js";
7
7
  import { PageZoom } from "../core/zoom.js";
8
8
  /** The pen mode of every sheet of this page. */
@@ -1,15 +1,20 @@
1
+ import type { PaperGrid } from "@altnovatrail/spec/canvas";
1
2
  import type { Tool } from "../core/task.js";
3
+ import { ROW } from "./icons.js";
4
+ /** A value of the bar, by its button's key: what its icon shows (icons.ts). */
5
+ export type Value = keyof typeof ROW;
2
6
  /**
3
7
  * What the bar asks of the element: a tool the learner chose — perhaps the one in use — an undo, a
4
- * clearing, a step of the zoom, larger or smaller, the finger to write again, out of pen mode, and
5
- * on a worked example the next part of its demo, or the whole demo hidden or shown (R42).
8
+ * clearing, a step of the zoom, larger or smaller (R73), and on a worked example the next part of its demo, or the whole demo hidden or shown
9
+ * (R42).
6
10
  */
7
11
  export interface ToolActions {
8
12
  readonly choose: (tool: Tool) => void;
9
13
  readonly undo: () => void;
10
14
  readonly clear: () => void;
11
15
  readonly zoom: (larger: boolean) => void;
12
- readonly fingers: () => void;
16
+ /** A task from paper's grid turned to the next (R88). */
17
+ readonly turnGrid: () => void;
13
18
  readonly next: () => void;
14
19
  readonly toggle: () => void;
15
20
  /** A task from paper's tracing paper hidden, or shown again (R87). */
@@ -28,10 +33,10 @@ export interface DemoControls {
28
33
  */
29
34
  export type RowKind = "sheet" | "workbook" | "paper" | "example";
30
35
  /**
31
- * What the bar shows: what it is of, the tools the task allows, the one in use, whether undo and
32
- * clearing have anything to do, whether the zoom has a larger step and a smaller one, whether the
33
- * finger may be asked to write again, and on a worked example whether Next has a part to open and
34
- * whether the demo is shown (R42).
36
+ * What the bar shows: what it is of, the tools the task allows — the hand besides, always —, the
37
+ * one in use, whether undo and clearing have anything to do, whether the zoom has a larger step
38
+ * and a smaller one (R73), and on a worked example whether Next has a part to open and whether the
39
+ * demo is shown (R42).
35
40
  */
36
41
  export interface ToolState {
37
42
  readonly kind: RowKind;
@@ -41,11 +46,11 @@ export interface ToolState {
41
46
  readonly clearable: boolean;
42
47
  readonly larger: boolean;
43
48
  readonly smaller: boolean;
44
- readonly finger: boolean;
45
49
  readonly opens: boolean;
46
50
  readonly expanded: boolean;
47
- /** On a task from paper, whether its tracing paper is shown (R87). */
51
+ /** On a task from paper, whether its tracing paper is shown (R87), and its sheet's grid (R88). */
48
52
  readonly traced: boolean;
53
+ readonly grid: PaperGrid;
49
54
  }
50
55
  /**
51
56
  * How long a tooltip stays after the pointer leaves its button, in milliseconds: long enough for
@@ -69,13 +74,12 @@ export declare class Tools {
69
74
  readonly tip: HTMLDivElement;
70
75
  constructor(actions: ToolActions, controls: DemoControls);
71
76
  /**
72
- * The bar as the sheet now is. Only what has changed is written. A worked example's has no tools
73
- * of writing, no undo and no clearing, for the learner does not write on its sheet, and its row
74
- * has Next, unavailable while the demo is hidden or open whole, and Demo, expanded while the demo
75
- * is shown (R42). Zoom in and Zoom out stand unavailable at their ends (R73). The tool in use
76
- * shows its icon filled, and Demo's icon points down while the demo is shown, and along the row
77
- * while it is hidden (R46). A task from paper's button atop the tools says what it does to the
78
- * tracing paper, and fills its icon while the paper is shown (R87).
77
+ * The bar as the sheet now is. Only what has changed is written. A worked example has no bar, for
78
+ * the learner does not write on its sheet, and its row has Next, unavailable while the demo is
79
+ * hidden or open whole, and Demo, expanded while the demo is shown (R42). The tool in use shows its
80
+ * icon filled, and Demo's icon points down while the demo is shown, and along the row while it is
81
+ * hidden (R46). A task from paper's button atop the tools says what it does to the tracing paper,
82
+ * and fills its icon while the paper is shown (R87), and its grid's button shows the grid (R88).
79
83
  */
80
84
  show(state: ToolState): void;
81
85
  /**
@@ -86,3 +90,14 @@ export declare class Tools {
86
90
  /** The element left the page: a tooltip goes with it, and Escape is no longer heard. */
87
91
  disconnect(): void;
88
92
  }
93
+ /**
94
+ * A button: its icon, an SVG that says nothing — no title, hidden from a screen reader — and its
95
+ * label, which names it (R46; R78 spec): on the bar, only a screen reader reads it (R84).
96
+ */
97
+ export declare function plainButton(value: Value): HTMLButtonElement;
98
+ /**
99
+ * A value's icon on its button, filled or in outline, written only when it is another than the one
100
+ * there: the icon's name stays on the SVG, as data. One mirrored in a row that runs right to left
101
+ * says so by its class, which the style turns (R46).
102
+ */
103
+ export declare function draw(button: HTMLButtonElement, value: Value, filled: boolean): void;
@@ -1,33 +1,41 @@
1
- // The element's own buttons (R28, R84): the tools the task allows — the pen and the eraser — undo
2
- // and clearing, the page's zoom and, in pen mode, the finger's button, on a vertical bar of glass at
3
- // the left edge of the element, as the interface mockup draws it (R148 spec). It is a toolbar as
4
- // WAI-ARIA's Authoring Practices have one: one stop of Tab, the arrow keys up and down from button
5
- // to button, and the tools a group of radio buttons that the arrows go through without choosing
6
- // one. Undo and Clear with nothing to take back or to clear stay where the focus can reach them,
7
- // marked unavailable: a last undo from the keyboard leaves the focus where it was. Zoom in and Zoom
8
- // out step the page's zoom of the sheet, from its fit to twice it, each unavailable at its end
9
- // (R73). In pen mode a last button lets a finger write again (R29). The sheet has no buttons that
10
- // scroll it: a hand drags it, the wheel and the keys scroll it (R84; R90 spec).
11
- // The buttons of the bar show an icon alone, of the set every NovaTrail package of the interface
12
- // draws from (R46; R78 spec): each is named by its label, in the element's language (labels.ts),
13
- // which only a screen reader reads, and shows it in a tooltip of its own on the pointer's hover and
14
- // on the keyboard's focus, which Escape dismisses and the pointer can move onto (R90 spec; WCAG
15
- // 1.4.13). The bar is named by the canvas kind's buttons: the sheet's or the workbook's (R36), for
16
- // the kind's own name is the scroll container's (R28). A lesson's worked example names it too, and
17
- // has no tools of writing: the learner does not write on its sheet, and its bar holds the zoom's
18
- // pair alone. Its demo's buttons, Next, which opens the next part, and Demo, a disclosure button
1
+ // The element's own buttons (R28, R84): the tools the task allows — the pen and the eraser — and
2
+ // the hand, which moves the sheet (R88), undo and clearing, on a vertical bar of glass at the left
3
+ // edge of the element, as the interface mockup draws it (R148 spec). It is a toolbar as WAI-ARIA's
4
+ // Authoring Practices have one: one stop of Tab, the arrow keys up and down from button to button,
5
+ // and the tools a group of radio buttons that the arrows go through without choosing one. Undo and
6
+ // Clear with nothing to take back or to clear stay where the focus can reach them, marked
7
+ // unavailable: a last undo from the keyboard leaves the focus where it was. After a line, Zoom in
8
+ // and Zoom out step the page's zoom of the sheet by quarters from half its fit to twice it, each
9
+ // unavailable at its end, as a pinch of two fingers sets it between (R73). The sheet has no
10
+ // buttons that scroll it: the hand, two fingers or a finger in pen mode drag it, the wheel and the
11
+ // keys scroll it (R84; R88; R90 spec). The buttons of the bar show an icon alone, of the set every
12
+ // NovaTrail package of the interface draws from (R46; R78 spec): each is named by its label, in the
13
+ // element's language (labels.ts), which only a screen reader reads, and shows it in a tooltip of
14
+ // its own on the pointer's hover and on the keyboard's focus, which Escape dismisses and the
15
+ // pointer can move onto (R90 spec; WCAG 1.4.13). The bar is named by the canvas kind's buttons: the
16
+ // sheet's or the workbook's (R36), for the kind's own name is the scroll container's (R28). A
17
+ // lesson's worked example has no bar: the learner does not write on its sheet, which scrolls as the
18
+ // page does. Its demo's buttons, Next, which opens the next part, and Demo, a disclosure button
19
19
  // that hides the whole demo and shows it again, are actions, not tools (R42; R90 spec): each shows
20
20
  // its label beside its icon, a stop of Tab of its own, in a row of glass at the bottom of the
21
21
  // element, and after a line the slot `actions`, where the consumer puts its own buttons — app's
22
22
  // Continue —, as the mockup has one row (R84; R36 spec). A task from paper's bar has one button
23
23
  // more, atop the tools, after a line: "Hide the task" while its tracing paper is shown, its icon
24
24
  // filled, and "Show the task" while it is hidden — the name says the state, so the button is no
25
- // toggle button as well, which would say it twice (R87; R90 spec). A button that goes gives its
26
- // stop of Tab and the focus to the first button shown. This module is no entry point of the
27
- // package.
25
+ // toggle button as well, which would say it twice (R87; R90 spec) —, and one last, after a line:
26
+ // the sheet's grid, its icon and its name the grid shown now, which a press turns to the next,
27
+ // round — dots, lines, blank, squares (R88). A button that goes gives its stop of Tab and the focus
28
+ // to the first button shown. This module is no entry point of the package.
28
29
  import { SVG, write } from "./attributes.js";
29
30
  import { ICONS, ROW } from "./icons.js";
30
31
  import { labelsFor } from "./labels.js";
32
+ /** The value of the grid's button, and the key of its label, by the grid shown. */
33
+ const GRID_VALUES = {
34
+ dots: "gridDots",
35
+ lines: "gridLines",
36
+ blank: "gridBlank",
37
+ squares: "gridSquares",
38
+ };
31
39
  /**
32
40
  * How long a tooltip stays after the pointer leaves its button, in milliseconds: long enough for
33
41
  * the pointer to cross the bar's edge and the gap onto the tooltip, which keeps it (WCAG 1.4.13).
@@ -57,15 +65,16 @@ export class Tools {
57
65
  #group = document.createElement("div");
58
66
  #pen = radioButton("pen");
59
67
  #eraser = radioButton("eraser");
68
+ #hand = radioButton("hand");
60
69
  #undo = plainButton("undo");
61
70
  #clear = plainButton("clear");
62
- /** The lines between the bar's groups: before the zoom's pair, and before the finger's button. */
71
+ /** The page's zoom of the sheet, after a line (R73). */
63
72
  #beforeZoom = separator();
64
- #beforeFinger = separator();
65
- #zoomPair = document.createElement("div");
66
73
  #zoomIn = plainButton("zoomIn");
67
74
  #zoomOut = plainButton("zoomOut");
68
- #finger = plainButton("finger");
75
+ /** A task from paper's grid, after a line (R88). */
76
+ #beforeGrid = separator();
77
+ #grid = plainButton("gridDots");
69
78
  /**
70
79
  * The buttons with the keys of their labels, the row's and then the bar's in the order the arrow
71
80
  * keys go through them. A button is named only by its label (R46), so each is here with its key.
@@ -76,11 +85,12 @@ export class Tools {
76
85
  [this.#task, "hideTask"],
77
86
  [this.#pen, "pen"],
78
87
  [this.#eraser, "eraser"],
88
+ [this.#hand, "hand"],
79
89
  [this.#undo, "undo"],
80
90
  [this.#clear, "clear"],
81
91
  [this.#zoomIn, "zoomIn"],
82
92
  [this.#zoomOut, "zoomOut"],
83
- [this.#finger, "finger"],
93
+ [this.#grid, "gridDots"],
84
94
  ];
85
95
  /**
86
96
  * The bar's buttons in the order the arrow keys go through them: each shows an icon alone, and a
@@ -95,6 +105,8 @@ export class Tools {
95
105
  #kind = "sheet";
96
106
  /** Whether a task from paper's tracing paper is shown: the button atop the tools says which. */
97
107
  #traced = true;
108
+ /** A task from paper's grid: its button's icon and name say which. */
109
+ #gridShown = "dots";
98
110
  /** Whether a button of the bar has had the focus: Tab comes to the first button until one has. */
99
111
  #chosen = false;
100
112
  /** The button the pointer is over, the one the keyboard's focus is on, and the tooltip's. */
@@ -147,23 +159,20 @@ export class Tools {
147
159
  this.row.append(this.#next, this.#demo, this.#beforeActions, this.#actions);
148
160
  this.#group.className = "choice";
149
161
  this.#group.setAttribute("role", "radiogroup");
150
- this.#group.append(this.#pen, this.#eraser);
151
- this.#zoomPair.className = "zoom";
152
- this.#zoomPair.append(this.#zoomIn, this.#zoomOut);
153
- // The finger's button comes last: coming and going, it moves no other button of the bar.
154
- this.element.append(this.#task, this.#afterTask, this.#group, this.#undo, this.#clear, this.#beforeZoom, this.#zoomPair, this.#beforeFinger, this.#finger);
162
+ this.#group.append(this.#pen, this.#eraser, this.#hand);
163
+ this.element.append(this.#task, this.#afterTask, this.#group, this.#undo, this.#clear, this.#beforeZoom, this.#zoomIn, this.#zoomOut, this.#beforeGrid, this.#grid);
155
164
  this.rail.append(this.element, this.row, this.tip);
156
165
  for (const button of this.#buttons)
157
166
  button.classList.add("icon");
158
- // A worked example's row and the finger's button come with what they are for.
167
+ // A worked example's row and a task from paper's buttons come with what they are for.
159
168
  for (const hidden of [
160
169
  this.row,
161
170
  this.#next,
162
171
  this.#demo,
163
172
  this.#task,
164
173
  this.#afterTask,
165
- this.#beforeFinger,
166
- this.#finger,
174
+ this.#beforeGrid,
175
+ this.#grid,
167
176
  ]) {
168
177
  hidden.hidden = true;
169
178
  }
@@ -172,6 +181,7 @@ export class Tools {
172
181
  // The element decides whether a choice is a change: the tool in use, chosen again, is none.
173
182
  this.#pen.addEventListener("click", () => actions.choose("pen"));
174
183
  this.#eraser.addEventListener("click", () => actions.choose("eraser"));
184
+ this.#hand.addEventListener("click", () => actions.choose("hand"));
175
185
  const doing = (button, act) => {
176
186
  // aria-disabled stops no click: the button does nothing while it stands unavailable.
177
187
  button.addEventListener("click", () => {
@@ -181,11 +191,11 @@ export class Tools {
181
191
  };
182
192
  doing(this.#undo, actions.undo);
183
193
  doing(this.#clear, actions.clear);
184
- doing(this.#next, actions.next);
185
194
  doing(this.#zoomIn, () => actions.zoom(true));
186
195
  doing(this.#zoomOut, () => actions.zoom(false));
196
+ doing(this.#next, actions.next);
187
197
  this.#demo.addEventListener("click", () => actions.toggle());
188
- this.#finger.addEventListener("click", () => actions.fingers());
198
+ this.#grid.addEventListener("click", () => actions.turnGrid());
189
199
  this.#task.addEventListener("click", () => actions.trace());
190
200
  this.element.addEventListener("keydown", (event) => this.#key(event));
191
201
  // The button that had the focus last is the one Tab comes back to.
@@ -223,16 +233,15 @@ export class Tools {
223
233
  this.label(null);
224
234
  }
225
235
  /**
226
- * The bar as the sheet now is. Only what has changed is written. A worked example's has no tools
227
- * of writing, no undo and no clearing, for the learner does not write on its sheet, and its row
228
- * has Next, unavailable while the demo is hidden or open whole, and Demo, expanded while the demo
229
- * is shown (R42). Zoom in and Zoom out stand unavailable at their ends (R73). The tool in use
230
- * shows its icon filled, and Demo's icon points down while the demo is shown, and along the row
231
- * while it is hidden (R46). A task from paper's button atop the tools says what it does to the
232
- * tracing paper, and fills its icon while the paper is shown (R87).
236
+ * The bar as the sheet now is. Only what has changed is written. A worked example has no bar, for
237
+ * the learner does not write on its sheet, and its row has Next, unavailable while the demo is
238
+ * hidden or open whole, and Demo, expanded while the demo is shown (R42). The tool in use shows its
239
+ * icon filled, and Demo's icon points down while the demo is shown, and along the row while it is
240
+ * hidden (R46). A task from paper's button atop the tools says what it does to the tracing paper,
241
+ * and fills its icon while the paper is shown (R87), and its grid's button shows the grid (R88).
233
242
  */
234
243
  show(state) {
235
- const { kind, tools, tool, undoable, clearable, larger, smaller, finger, opens, expanded, traced, } = state;
244
+ const { kind, tools, tool, undoable, clearable, larger, smaller, opens, expanded, traced, grid, } = state;
236
245
  if (kind !== this.#kind) {
237
246
  this.#kind = kind;
238
247
  this.#name();
@@ -240,6 +249,7 @@ export class Tools {
240
249
  const writes = kind !== "example";
241
250
  this.rail.classList.toggle("example", !writes);
242
251
  this.#reveal([
252
+ [this.element, writes],
243
253
  [this.row, !writes],
244
254
  [this.#next, !writes],
245
255
  [this.#demo, !writes],
@@ -248,22 +258,32 @@ export class Tools {
248
258
  [this.#group, writes],
249
259
  [this.#pen, writes],
250
260
  [this.#eraser, writes && tools.includes("eraser")],
261
+ [this.#hand, writes],
251
262
  [this.#undo, writes],
252
263
  [this.#clear, writes],
253
264
  [this.#beforeZoom, writes],
254
- [this.#beforeFinger, writes && finger],
255
- [this.#finger, writes && finger],
265
+ [this.#zoomIn, writes],
266
+ [this.#zoomOut, writes],
267
+ [this.#beforeGrid, kind === "paper"],
268
+ [this.#grid, kind === "paper"],
256
269
  ]);
257
270
  write(this.#pen, "aria-checked", String(tool === "pen"));
258
271
  write(this.#eraser, "aria-checked", String(tool === "eraser"));
272
+ write(this.#hand, "aria-checked", String(tool === "hand"));
259
273
  write(this.#undo, "aria-disabled", undoable ? null : "true");
260
274
  write(this.#clear, "aria-disabled", clearable ? null : "true");
261
- write(this.#next, "aria-disabled", opens ? null : "true");
262
275
  write(this.#zoomIn, "aria-disabled", larger ? null : "true");
263
276
  write(this.#zoomOut, "aria-disabled", smaller ? null : "true");
277
+ write(this.#next, "aria-disabled", opens ? null : "true");
264
278
  write(this.#demo, "aria-expanded", String(expanded));
265
279
  draw(this.#pen, "pen", tool === "pen");
266
280
  draw(this.#eraser, "eraser", tool === "eraser");
281
+ draw(this.#hand, "hand", tool === "hand");
282
+ draw(this.#grid, GRID_VALUES[grid], false);
283
+ if (grid !== this.#gridShown) {
284
+ this.#gridShown = grid;
285
+ this.#nameGrid();
286
+ }
267
287
  draw(this.#demo, expanded ? "demoShown" : "demoHidden", false);
268
288
  draw(this.#task, "task", traced);
269
289
  if (traced !== this.#traced) {
@@ -291,6 +311,7 @@ export class Tools {
291
311
  label.textContent = labels[key];
292
312
  }
293
313
  this.#nameTask();
314
+ this.#nameGrid();
294
315
  this.#tipFor = undefined;
295
316
  this.#showTip();
296
317
  }
@@ -316,10 +337,22 @@ export class Tools {
316
337
  if (this.#tipFor === this.#task)
317
338
  this.tip.textContent = name;
318
339
  }
319
- /** The bar's name: the canvas kind's buttons, in the labels' language. */
340
+ /** The name of a task from paper's grid button, by the grid shown, and its tooltip's (R88). */
341
+ #nameGrid() {
342
+ const { labels } = labelsFor(this.#lang ?? null);
343
+ const label = this.#grid.lastElementChild;
344
+ const name = labels[GRID_VALUES[this.#gridShown]];
345
+ if (label === null || label.textContent === name)
346
+ return;
347
+ label.textContent = name;
348
+ if (this.#tipFor === this.#grid)
349
+ this.tip.textContent = name;
350
+ }
351
+ /** The bar's name: the canvas kind's buttons, in the labels' language; an example has none. */
320
352
  #name() {
321
353
  const { labels } = labelsFor(this.#lang ?? null);
322
- write(this.element, "aria-label", labels[`${this.#kind}Buttons`]);
354
+ const kind = this.#kind;
355
+ write(this.element, "aria-label", kind === "example" ? null : labels[`${kind}Buttons`]);
323
356
  }
324
357
  /**
325
358
  * A button's tooltip on the hover of a pointer that hovers — a mouse, a pen above the screen —,
@@ -420,7 +453,7 @@ export class Tools {
420
453
  }
421
454
  /**
422
455
  * Buttons come or go, all of them at once, and then a button that went gives its stop of Tab and
423
- * the focus to the first button shown: the pen on a sheet, Zoom in on a worked example (R28). Till
456
+ * the focus to the first button shown: the pen on a sheet, or a task from paper's button (R28). Till
424
457
  * a button has had the focus, the stop is the first button shown, whichever it is now. Nothing is
425
458
  * read or written while every button stays as it is: the bar is shown anew after every stroke.
426
459
  */
@@ -447,9 +480,9 @@ export class Tools {
447
480
  #shown() {
448
481
  return this.#buttons.filter((button) => !button.hidden);
449
482
  }
450
- /** The first button the bar shows: Zoom in and Zoom out are on every bar (R73). */
483
+ /** The first button the bar shows: the pen is on every bar a learner writes on. */
451
484
  #first() {
452
- return this.#shown()[0] ?? this.#zoomIn;
485
+ return this.#shown()[0] ?? this.#pen;
453
486
  }
454
487
  /** The one button Tab comes to: the arrow keys reach the others. */
455
488
  #stopAt(stop) {
@@ -498,7 +531,7 @@ function radioButton(value) {
498
531
  * A button: its icon, an SVG that says nothing — no title, hidden from a screen reader — and its
499
532
  * label, which names it (R46; R78 spec): on the bar, only a screen reader reads it (R84).
500
533
  */
501
- function plainButton(value) {
534
+ export function plainButton(value) {
502
535
  const button = document.createElement("button");
503
536
  button.type = "button";
504
537
  const icon = document.createElementNS(SVG, "svg");
@@ -517,7 +550,7 @@ function plainButton(value) {
517
550
  * there: the icon's name stays on the SVG, as data. One mirrored in a row that runs right to left
518
551
  * says so by its class, which the style turns (R46).
519
552
  */
520
- function draw(button, value, filled) {
553
+ export function draw(button, value, filled) {
521
554
  const icon = button.firstElementChild;
522
555
  if (!(icon instanceof SVGSVGElement))
523
556
  return;