@altnovatrail/canvas 0.3.12 → 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.
@@ -1,13 +1,18 @@
1
1
  /**
2
- * What the element says: the row of buttons its own name — the canvas kind's, or a worked
3
- * example's — the name of the group of tools and each button, a workbook's box its name, and the
4
- * number of a part of a demo the element tells of. A label with places names them in braces.
2
+ * What the element says: its scroll container the canvas kind's name, or a worked example's, and
3
+ * the row of buttons a name of its own, that of the kind's buttons (T93), the name of the group of
4
+ * tools and each button, a workbook's box its name, and the number of a part of a demo the element
5
+ * tells of. A label with places names them in braces.
5
6
  */
6
7
  export interface Labels {
7
8
  readonly sheet: string;
8
9
  readonly workbook: string;
9
- /** The row of a lesson's worked example, which has no tools of writing (R42). */
10
+ /** A lesson's worked example, whose row has no tools of writing (R42). */
10
11
  readonly example: string;
12
+ /** The row of buttons of each: not the name of the container, which a screen reader shows too. */
13
+ readonly sheetButtons: string;
14
+ readonly workbookButtons: string;
15
+ readonly exampleButtons: string;
11
16
  /** The buttons of a worked example's demo: the next part, and the whole demo, shown or hidden. */
12
17
  readonly next: string;
13
18
  readonly demo: string;
@@ -19,6 +24,12 @@ export interface Labels {
19
24
  /** The buttons that scroll the sheet back up and on down, with a single pointer (R33). */
20
25
  readonly up: string;
21
26
  readonly down: string;
27
+ /** The buttons of the page's zoom, a step larger and a step smaller (T94). */
28
+ readonly zoomIn: string;
29
+ readonly zoomOut: string;
30
+ /** The buttons that scroll a zoomed sheet left and right, with a single pointer (T94). */
31
+ readonly left: string;
32
+ readonly right: string;
22
33
  /** The button that lets a finger write again, in pen mode (R29). */
23
34
  readonly finger: string;
24
35
  /** A box of a workbook's line, alone in it (R36). */
@@ -8,13 +8,18 @@
8
8
  // - no label counts a thing, so none has forms of number yet. The first that does takes CLDR's
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
- // - the buttons' words are those of the table of words of architecture 6 spec.
11
+ // - the buttons' words are those of the table of words of architecture 6 spec, but for the four of
12
+ // the page's zoom and of the scroll across, Zoom in and Zoom out, Left and Right, which wait for
13
+ // it by В76 in RUN.md (T94).
12
14
  // This module is no entry point of the package.
13
15
  /** The labels in English, the code's own language: those of any language the table has not. */
14
16
  const ENGLISH = Object.freeze({
15
17
  sheet: "Sheet",
16
18
  workbook: "Workbook",
17
19
  example: "Worked example",
20
+ sheetButtons: "Sheet buttons",
21
+ workbookButtons: "Workbook buttons",
22
+ exampleButtons: "Worked example buttons",
18
23
  next: "Next",
19
24
  demo: "Demo",
20
25
  tool: "Tool",
@@ -24,6 +29,10 @@ const ENGLISH = Object.freeze({
24
29
  clear: "Clear",
25
30
  up: "Up",
26
31
  down: "Down",
32
+ zoomIn: "Zoom in",
33
+ zoomOut: "Zoom out",
34
+ left: "Left",
35
+ right: "Right",
27
36
  finger: "Draw with finger",
28
37
  box: "Box",
29
38
  boxAt: "Box {slot}",
@@ -44,6 +53,9 @@ const LABELS = new Map([
44
53
  sheet: "Лист",
45
54
  workbook: "Тетрадь",
46
55
  example: "Пример",
56
+ sheetButtons: "Кнопки листа",
57
+ workbookButtons: "Кнопки тетради",
58
+ exampleButtons: "Кнопки примера",
47
59
  next: "Дальше",
48
60
  demo: "Показ",
49
61
  tool: "Инструмент",
@@ -53,6 +65,10 @@ const LABELS = new Map([
53
65
  clear: "Очистить",
54
66
  up: "Выше",
55
67
  down: "Ниже",
68
+ zoomIn: "Крупнее",
69
+ zoomOut: "Мельче",
70
+ left: "Левее",
71
+ right: "Правее",
56
72
  finger: "Рисовать пальцем",
57
73
  box: "Окошко",
58
74
  boxAt: "Окошко {slot}",
@@ -1,3 +1,6 @@
1
1
  import { PenMode } from "../core/hands.js";
2
+ import { PageZoom } from "../core/zoom.js";
2
3
  /** The pen mode of every sheet of this page. */
3
4
  export declare const PEN_MODE: PenMode;
5
+ /** The zoom of every sheet of this page. */
6
+ export declare const PAGE_ZOOM: PageZoom;
@@ -1,7 +1,11 @@
1
- // The page's pen mode (R29): one for every sheet of the page, from a pen's first touch on any of
2
- // them until the learner asks for the finger, or the page is loaded again. The next task is a new
3
- // element (R20), and the mode stays. It is a state of the interface in memory, not data: nothing is
4
- // stored or sent. This module is no entry point of the package.
1
+ // The page's pen mode (R29) and its zoom (T94): 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.
5
6
  import { PenMode } from "../core/hands.js";
7
+ import { PageZoom } from "../core/zoom.js";
6
8
  /** The pen mode of every sheet of this page. */
7
9
  export const PEN_MODE = new PenMode();
10
+ /** The zoom of every sheet of this page. */
11
+ export const PAGE_ZOOM = new PageZoom();
@@ -1,7 +1,8 @@
1
1
  import type { Tool } from "../core/task.js";
2
2
  /**
3
3
  * What the row asks of the element: a tool the learner chose — perhaps the one in use — an undo, a
4
- * clearing, a scroll on down the sheet, for `onward`, or back up it, the finger to write again,
4
+ * clearing, a scroll on down the sheet, for `onward`, or back up it, a step of the zoom, larger or
5
+ * smaller, a scroll right across the sheet, for `onward`, or back left, the finger to write again,
5
6
  * out of pen mode, and on a worked example the next part of its demo, or the whole demo hidden or
6
7
  * shown (R42).
7
8
  */
@@ -10,6 +11,8 @@ export interface ToolActions {
10
11
  readonly undo: () => void;
11
12
  readonly clear: () => void;
12
13
  readonly upOrDown: (onward: boolean) => void;
14
+ readonly zoom: (larger: boolean) => void;
15
+ readonly leftOrRight: (onward: boolean) => void;
13
16
  readonly fingers: () => void;
14
17
  readonly next: () => void;
15
18
  readonly toggle: () => void;
@@ -25,7 +28,8 @@ export interface DemoControls {
25
28
  export type RowKind = "sheet" | "workbook" | "example";
26
29
  /**
27
30
  * What the row shows: what it is of, the tools the task allows, the one in use, whether undo and
28
- * clearing have anything to do, whether the finger may be asked to write again, and on a worked
31
+ * clearing have anything to do, whether the zoom has a larger step and a smaller one, and so
32
+ * whether the sheet is zoomed, whether the finger may be asked to write again, and on a worked
29
33
  * example whether Next has a part to open and whether the demo is shown (R42).
30
34
  */
31
35
  export interface ToolState {
@@ -34,6 +38,8 @@ export interface ToolState {
34
38
  readonly tool: Tool;
35
39
  readonly undoable: boolean;
36
40
  readonly clearable: boolean;
41
+ readonly larger: boolean;
42
+ readonly smaller: boolean;
37
43
  readonly finger: boolean;
38
44
  readonly opens: boolean;
39
45
  readonly expanded: boolean;
@@ -48,15 +54,17 @@ export declare class Tools {
48
54
  * The row as the sheet now is. Only what has changed is written. A worked example's row has no
49
55
  * tools of writing, no undo and no clearing, for the learner does not write on its sheet, and has
50
56
  * Next, unavailable while the demo is hidden or open whole, and Demo, expanded while the demo is
51
- * shown (R42). The tool in use shows its icon filled, and Demo's icon points down while the demo
52
- * is shown, and along the row while it is hidden (R46).
57
+ * shown (R42). Zoom in and Zoom out stand unavailable at their ends, and Left and Right are there
58
+ * while the sheet is zoomed (T94). The tool in use shows its icon filled, and Demo's icon points
59
+ * down while the demo is shown, and along the row while it is hidden (R46).
53
60
  */
54
- show({ kind, tools, tool, undoable, clearable, finger, opens, expanded }: ToolState): void;
61
+ show(state: ToolState): void;
55
62
  /**
56
- * Whether anything scrolls back up the sheet, for Up, and on down it, for Down: a button with
57
- * nowhere to go stands unavailable. Only what has changed is written.
63
+ * Whether anything scrolls back up the sheet, for Up, on down it, for Down, back left across it,
64
+ * for Left, and on right, for Right: a button with nowhere to go stands unavailable. Only what has
65
+ * changed is written.
58
66
  */
59
- edges(above: boolean, below: boolean): void;
67
+ edges(above: boolean, below: boolean, before: boolean, after: boolean): void;
60
68
  /**
61
69
  * Whether the row sticks over what scrolls the element (R28): in a low window it stands in its
62
70
  * place instead, above the statement, and scrolls away with it. The same state writes nothing:
@@ -4,15 +4,19 @@
4
4
  // through without choosing one. Undo and Clear with nothing to take back or to clear stay where the
5
5
  // focus can reach them, marked unavailable: a last undo from the keyboard leaves the focus where it
6
6
  // was. Up and Down scroll the sheet with a single pointer, and stand unavailable at the end they
7
- // scroll to (R33). In pen mode a last button lets a finger write again (R29). The labels are in
8
- // the element's language (labels.ts), and the row is named by the canvas kind: the sheet or the
9
- // workbook (R36). A lesson's worked example names it too, and has no tools of writing in it: the
10
- // learner does not write on its sheet. Its first buttons are its demo's, Next, which opens the next
11
- // part, and Demo, a disclosure button that hides the whole demo and shows it again (R42). A button
12
- // that goes gives its stop of Tab and the focus to the first button shown. Each button shows an
13
- // icon of the set every NovaTrail package of the interface draws from, before its label, which
14
- // stays its name: the icon says nothing to a screen reader (R46; R78 spec). This module is no entry
15
- // point of the package.
7
+ // scroll to (R33). Zoom in and Zoom out step the page's zoom of the sheet, from its fit to twice
8
+ // it, each unavailable at its end, and while the sheet is zoomed, Left and Right scroll it across
9
+ // as Up and Down do down it (T94). They come after the zoom's pair: a last Zoom out hides them and
10
+ // moves no button under the pointer. In pen mode a last button lets a finger write again (R29).
11
+ // The labels are in the element's language (labels.ts), and the row is named by the canvas kind's
12
+ // buttons: the sheet's or the workbook's (R36), for the kind's own name is the scroll container's
13
+ // (T93). A lesson's worked example names it too, and has no tools of writing in it: the learner
14
+ // does not write on its sheet. Its first buttons are its demo's, Next, which opens the next part,
15
+ // and Demo, a disclosure button that hides the whole demo and shows it again (R42). A button that
16
+ // goes gives its stop of Tab and the focus to the first button shown. Each button shows an icon of
17
+ // the set every NovaTrail package of the interface draws from, before its label, which stays its
18
+ // name: the icon says nothing to a screen reader (R46; R78 spec). This module is no entry point of
19
+ // the package.
16
20
  import { SVG, write } from "./attributes.js";
17
21
  import { ICONS, ROW } from "./icons.js";
18
22
  import { labelsFor } from "./labels.js";
@@ -33,6 +37,13 @@ export class Tools {
33
37
  #pair = document.createElement("div");
34
38
  #up = plainButton("up");
35
39
  #down = plainButton("down");
40
+ /** Zoom in and Zoom out, and Left and Right, two more pairs of the same kind (T94). */
41
+ #zoomPair = document.createElement("div");
42
+ #zoomIn = plainButton("zoomIn");
43
+ #zoomOut = plainButton("zoomOut");
44
+ #acrossPair = document.createElement("div");
45
+ #left = plainButton("left");
46
+ #right = plainButton("right");
36
47
  #finger = plainButton("finger");
37
48
  /**
38
49
  * The buttons with the keys of their labels, in the order the arrow keys go through them: the
@@ -47,6 +58,10 @@ export class Tools {
47
58
  [this.#clear, "clear"],
48
59
  [this.#up, "up"],
49
60
  [this.#down, "down"],
61
+ [this.#zoomIn, "zoomIn"],
62
+ [this.#zoomOut, "zoomOut"],
63
+ [this.#left, "left"],
64
+ [this.#right, "right"],
50
65
  [this.#finger, "finger"],
51
66
  ];
52
67
  /** The buttons in the order the arrow keys go through them. */
@@ -71,10 +86,16 @@ export class Tools {
71
86
  this.#group.append(this.#pen, this.#eraser);
72
87
  this.#pair.className = "updown";
73
88
  this.#pair.append(this.#up, this.#down);
74
- // The finger's button comes last: coming and going, it moves no other button of the row.
75
- this.element.append(this.#demoPair, this.#group, this.#undo, this.#clear, this.#pair, this.#finger);
76
- // A worked example's buttons and the finger's come with what they are for.
77
- for (const hidden of [this.#demoPair, this.#next, this.#demo, this.#finger]) {
89
+ this.#zoomPair.className = "zoom";
90
+ this.#zoomPair.append(this.#zoomIn, this.#zoomOut);
91
+ this.#acrossPair.className = "across";
92
+ this.#acrossPair.append(this.#left, this.#right);
93
+ // The finger's button comes last: coming and going, it moves no other button of the row. Left
94
+ // and Right come after the zoom's pair, for the same reason.
95
+ this.element.append(this.#demoPair, this.#group, this.#undo, this.#clear, this.#pair, this.#zoomPair, this.#acrossPair, this.#finger);
96
+ // A worked example's buttons, Left and Right, and the finger's come with what they are for.
97
+ const later = [this.#demoPair, this.#next, this.#demo, this.#acrossPair, this.#left];
98
+ for (const hidden of [...later, this.#right, this.#finger]) {
78
99
  hidden.hidden = true;
79
100
  }
80
101
  // Tab comes to the first button shown, until another has had the focus.
@@ -92,11 +113,15 @@ export class Tools {
92
113
  doing(this.#undo, actions.undo);
93
114
  doing(this.#clear, actions.clear);
94
115
  doing(this.#next, actions.next);
116
+ doing(this.#zoomIn, () => actions.zoom(true));
117
+ doing(this.#zoomOut, () => actions.zoom(false));
95
118
  this.#demo.addEventListener("click", () => actions.toggle());
96
- // Up and Down ask the element anew at every press, unavailable or not: a scroll the element did
97
- // not hear may have left either standing as it no longer is.
119
+ // Up and Down, Left and Right ask the element anew at every press, unavailable or not: a scroll
120
+ // the element did not hear may have left any of them standing as it no longer is.
98
121
  this.#up.addEventListener("click", () => actions.upOrDown(false));
99
122
  this.#down.addEventListener("click", () => actions.upOrDown(true));
123
+ this.#left.addEventListener("click", () => actions.leftOrRight(false));
124
+ this.#right.addEventListener("click", () => actions.leftOrRight(true));
100
125
  this.#finger.addEventListener("click", () => actions.fingers());
101
126
  this.element.addEventListener("keydown", (event) => this.#key(event));
102
127
  // The button that had the focus last is the one Tab comes back to.
@@ -113,10 +138,12 @@ export class Tools {
113
138
  * The row as the sheet now is. Only what has changed is written. A worked example's row has no
114
139
  * tools of writing, no undo and no clearing, for the learner does not write on its sheet, and has
115
140
  * Next, unavailable while the demo is hidden or open whole, and Demo, expanded while the demo is
116
- * shown (R42). The tool in use shows its icon filled, and Demo's icon points down while the demo
117
- * is shown, and along the row while it is hidden (R46).
141
+ * shown (R42). Zoom in and Zoom out stand unavailable at their ends, and Left and Right are there
142
+ * while the sheet is zoomed (T94). The tool in use shows its icon filled, and Demo's icon points
143
+ * down while the demo is shown, and along the row while it is hidden (R46).
118
144
  */
119
- show({ kind, tools, tool, undoable, clearable, finger, opens, expanded }) {
145
+ show(state) {
146
+ const { kind, tools, tool, undoable, clearable, larger, smaller, finger, opens, expanded } = state;
120
147
  if (kind !== this.#kind) {
121
148
  this.#kind = kind;
122
149
  this.#name();
@@ -131,6 +158,9 @@ export class Tools {
131
158
  [this.#eraser, writes && tools.includes("eraser")],
132
159
  [this.#undo, writes],
133
160
  [this.#clear, writes],
161
+ [this.#acrossPair, smaller],
162
+ [this.#left, smaller],
163
+ [this.#right, smaller],
134
164
  [this.#finger, writes && finger],
135
165
  ]);
136
166
  write(this.#pen, "aria-checked", String(tool === "pen"));
@@ -138,18 +168,23 @@ export class Tools {
138
168
  write(this.#undo, "aria-disabled", undoable ? null : "true");
139
169
  write(this.#clear, "aria-disabled", clearable ? null : "true");
140
170
  write(this.#next, "aria-disabled", opens ? null : "true");
171
+ write(this.#zoomIn, "aria-disabled", larger ? null : "true");
172
+ write(this.#zoomOut, "aria-disabled", smaller ? null : "true");
141
173
  write(this.#demo, "aria-expanded", String(expanded));
142
174
  draw(this.#pen, "pen", tool === "pen");
143
175
  draw(this.#eraser, "eraser", tool === "eraser");
144
176
  draw(this.#demo, expanded ? "demoShown" : "demoHidden", false);
145
177
  }
146
178
  /**
147
- * Whether anything scrolls back up the sheet, for Up, and on down it, for Down: a button with
148
- * nowhere to go stands unavailable. Only what has changed is written.
179
+ * Whether anything scrolls back up the sheet, for Up, on down it, for Down, back left across it,
180
+ * for Left, and on right, for Right: a button with nowhere to go stands unavailable. Only what has
181
+ * changed is written.
149
182
  */
150
- edges(above, below) {
183
+ edges(above, below, before, after) {
151
184
  write(this.#up, "aria-disabled", above ? null : "true");
152
185
  write(this.#down, "aria-disabled", below ? null : "true");
186
+ write(this.#left, "aria-disabled", before ? null : "true");
187
+ write(this.#right, "aria-disabled", after ? null : "true");
153
188
  }
154
189
  /**
155
190
  * Whether the row sticks over what scrolls the element (R28): in a low window it stands in its
@@ -181,10 +216,10 @@ export class Tools {
181
216
  label.textContent = labels[key];
182
217
  }
183
218
  }
184
- /** The row's name: the canvas kind's, in the labels' language. */
219
+ /** The row's name: the canvas kind's buttons, in the labels' language. */
185
220
  #name() {
186
221
  const { labels } = labelsFor(this.#lang ?? null);
187
- write(this.element, "aria-label", labels[this.#kind]);
222
+ write(this.element, "aria-label", labels[`${this.#kind}Buttons`]);
188
223
  }
189
224
  /**
190
225
  * The arrow keys move the focus to the next button or the one before, round the row — the next
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altnovatrail/canvas",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
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": {