@altnovatrail/canvas 0.3.12 → 0.3.14
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 +3 -3
- package/lib/core/hands.d.ts +17 -4
- package/lib/core/hands.js +42 -12
- package/lib/core/screen.d.ts +10 -7
- package/lib/core/screen.js +10 -9
- package/lib/core/zoom.d.ts +23 -0
- package/lib/core/zoom.js +43 -0
- package/lib/element/icons.d.ts +36 -0
- package/lib/element/icons.js +44 -0
- package/lib/element/index.js +405 -144
- package/lib/element/labels.d.ts +33 -8
- package/lib/element/labels.js +44 -2
- package/lib/element/parts.d.ts +15 -1
- package/lib/element/parts.js +42 -24
- package/lib/element/session.d.ts +3 -0
- package/lib/element/session.js +8 -4
- package/lib/element/tools.d.ts +16 -8
- package/lib/element/tools.js +58 -23
- package/package.json +3 -3
package/lib/element/labels.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What the element says:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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
|
-
/**
|
|
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). */
|
|
@@ -36,16 +47,23 @@ export interface Labels {
|
|
|
36
47
|
}
|
|
37
48
|
/** Every language the table has, by its tag: the tests hold each to English's places. */
|
|
38
49
|
export declare const LANGUAGES: readonly string[];
|
|
50
|
+
/** Labels, and the language they are in. */
|
|
51
|
+
type Labelled = {
|
|
52
|
+
readonly lang: string;
|
|
53
|
+
readonly labels: Labels;
|
|
54
|
+
};
|
|
39
55
|
/**
|
|
40
56
|
* The labels for a language tag, and the language they are in. The tag is looked up as RFC 4647,
|
|
41
57
|
* section 3.4, does it: in lower case, cut subtag by subtag from its end until the table has what
|
|
42
58
|
* is left, a single-letter subtag going with the subtag after it. English stands for any other
|
|
43
59
|
* tag, and for none.
|
|
44
60
|
*/
|
|
45
|
-
export declare function labelsFor(tag: string | null):
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
export declare function labelsFor(tag: string | null): Labelled;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the table has labels in the language of a tag, as `labelsFor` looks it up: the English
|
|
64
|
+
* that stands for a tag it has not is in no language of the tag's (R74).
|
|
65
|
+
*/
|
|
66
|
+
export declare function knows(tag: string | null): boolean;
|
|
49
67
|
/** The places a label names, each once, in the order it names them. */
|
|
50
68
|
export declare function placesOf(label: string): string[];
|
|
51
69
|
/**
|
|
@@ -53,3 +71,10 @@ export declare function placesOf(label: string): string[];
|
|
|
53
71
|
* never shows its braces.
|
|
54
72
|
*/
|
|
55
73
|
export declare function say(label: string, values: Readonly<Record<string, string | number>>): string;
|
|
74
|
+
/**
|
|
75
|
+
* A label with its places filled by name but one, which it is cut at: what comes before that place
|
|
76
|
+
* and what comes after it, for a node of its own to stand between them (T107). A label that names
|
|
77
|
+
* the place not once is a TypeError, and so is a place the values do not give, as with `say`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function sayAround(label: string, place: string, values: Readonly<Record<string, string | number>>): readonly [string, string];
|
|
80
|
+
export {};
|
package/lib/element/labels.js
CHANGED
|
@@ -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}",
|
|
@@ -72,6 +88,17 @@ export const LANGUAGES = [...LABELS.keys()];
|
|
|
72
88
|
* tag, and for none.
|
|
73
89
|
*/
|
|
74
90
|
export function labelsFor(tag) {
|
|
91
|
+
return lookup(tag) ?? { lang: "en", labels: ENGLISH };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Whether the table has labels in the language of a tag, as `labelsFor` looks it up: the English
|
|
95
|
+
* that stands for a tag it has not is in no language of the tag's (R74).
|
|
96
|
+
*/
|
|
97
|
+
export function knows(tag) {
|
|
98
|
+
return lookup(tag) !== undefined;
|
|
99
|
+
}
|
|
100
|
+
/** The labels the table has for a tag, by RFC 4647, section 3.4, or none. */
|
|
101
|
+
function lookup(tag) {
|
|
75
102
|
let range = (tag ?? "").toLowerCase();
|
|
76
103
|
while (range !== "") {
|
|
77
104
|
const labels = LABELS.get(range);
|
|
@@ -83,7 +110,7 @@ export function labelsFor(tag) {
|
|
|
83
110
|
cut -= 2;
|
|
84
111
|
range = cut > 0 ? range.slice(0, cut) : "";
|
|
85
112
|
}
|
|
86
|
-
return
|
|
113
|
+
return undefined;
|
|
87
114
|
}
|
|
88
115
|
/** A place of a label: a name of Latin letters, digits and underscores in braces. */
|
|
89
116
|
const PLACE = /\{(\w+)\}/g;
|
|
@@ -103,3 +130,18 @@ export function say(label, values) {
|
|
|
103
130
|
return String(value);
|
|
104
131
|
});
|
|
105
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* A label with its places filled by name but one, which it is cut at: what comes before that place
|
|
135
|
+
* and what comes after it, for a node of its own to stand between them (T107). A label that names
|
|
136
|
+
* the place not once is a TypeError, and so is a place the values do not give, as with `say`.
|
|
137
|
+
*/
|
|
138
|
+
export function sayAround(label, place, values) {
|
|
139
|
+
const parts = label.split(`{${place}}`);
|
|
140
|
+
const [before, after] = parts;
|
|
141
|
+
if (parts.length !== 2 || before === undefined || after === undefined) {
|
|
142
|
+
throw new TypeError(`the label "${label}" names {${place}} not once`);
|
|
143
|
+
}
|
|
144
|
+
// The label whole first, so that a place with no value is named in it, not in a cut of it.
|
|
145
|
+
say(label, { ...values, [place]: "" });
|
|
146
|
+
return [say(before, values), say(after, values)];
|
|
147
|
+
}
|
package/lib/element/parts.d.ts
CHANGED
|
@@ -7,6 +7,20 @@ export interface Told {
|
|
|
7
7
|
/** The language of the labels the number is in. */
|
|
8
8
|
readonly lang: string;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* What a part that fills a box says: the box, in the labels' language, around the value the demo
|
|
12
|
+
* wrote in it, which is in the parts' own (T107). Without a value the box is `before` alone.
|
|
13
|
+
*/
|
|
14
|
+
export interface FillWords {
|
|
15
|
+
/** The labels' words before the value: "Box 1.2: ". */
|
|
16
|
+
readonly before: string;
|
|
17
|
+
/** The value, in the parts' language, or "" for none. */
|
|
18
|
+
readonly value: string;
|
|
19
|
+
/** The labels' words after the value, most often none. */
|
|
20
|
+
readonly after: string;
|
|
21
|
+
/** The language of the labels the words around the value are in. */
|
|
22
|
+
readonly lang: string;
|
|
23
|
+
}
|
|
10
24
|
/** The list of a demo's open parts and the region that tells of them, as the element shows them. */
|
|
11
25
|
export declare class Parts {
|
|
12
26
|
#private;
|
|
@@ -29,7 +43,7 @@ export declare class Parts {
|
|
|
29
43
|
*/
|
|
30
44
|
readonly spot: HTMLDivElement;
|
|
31
45
|
/** What a part that fills a box says from now on, the items already open too. */
|
|
32
|
-
set fillWords(words: (part: FillPart) =>
|
|
46
|
+
set fillWords(words: (part: FillPart) => FillWords);
|
|
33
47
|
/** The list and the region, by their IDs, whose pictures the element's pictures give files. */
|
|
34
48
|
constructor(ids: {
|
|
35
49
|
readonly status: string;
|
package/lib/element/parts.js
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
// in words till then. A picture on an area of the sheet is read by its words here, while the
|
|
8
8
|
// picture itself stands on the layer of the author's demo, stretched over its area, the later part
|
|
9
9
|
// over the earlier, and nothing stands there till its file is decoded (T61). A box of a workbook
|
|
10
|
-
// the demo fills is read as the box and its value,
|
|
11
|
-
//
|
|
10
|
+
// the demo fills is read as the box, in the labels' language, and its value, a node of its own in
|
|
11
|
+
// the parts' language, which the element writes in the box itself too (T85, T107). This module is
|
|
12
|
+
// no entry point of the package.
|
|
12
13
|
import { isFill, onSheet, } from "../core/example.js";
|
|
13
14
|
import { SHEET } from "../core/sheet.js";
|
|
14
15
|
import { placeOver, SVG, write } from "./attributes.js";
|
|
@@ -42,13 +43,14 @@ export class Parts {
|
|
|
42
43
|
/** The open items of parts that fill a box, which a new language words anew. */
|
|
43
44
|
#fills = new Map();
|
|
44
45
|
/**
|
|
45
|
-
* What a part that fills a box says
|
|
46
|
-
*
|
|
47
|
-
*
|
|
46
|
+
* What a part that fills a box says: the box, in the labels' language, around its value. The
|
|
47
|
+
* element sets it with each example and as its language changes; `fillWords` says the open items
|
|
48
|
+
* again in the new one. On its own, the list says the box by the English label, and no value.
|
|
48
49
|
*/
|
|
49
50
|
#fillWords = ({ fill }) => {
|
|
50
51
|
const { lang, labels } = labelsFor(null);
|
|
51
|
-
|
|
52
|
+
const before = say(labels.boxIn, { line: fill.line, slot: fill.box });
|
|
53
|
+
return { before, value: "", after: "", lang };
|
|
52
54
|
};
|
|
53
55
|
/** What a part that fills a box says from now on, the items already open too. */
|
|
54
56
|
set fillWords(words) {
|
|
@@ -132,16 +134,11 @@ export class Parts {
|
|
|
132
134
|
* has its number alone.
|
|
133
135
|
*/
|
|
134
136
|
tell(part, told) {
|
|
135
|
-
const number =
|
|
136
|
-
number.lang = told.lang;
|
|
137
|
-
number.textContent = told.number;
|
|
138
|
-
const said = document.createElement("span");
|
|
137
|
+
const number = spanOf(told.number, told.lang);
|
|
139
138
|
if (isFill(part)) {
|
|
140
|
-
//
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
said.textContent = words;
|
|
144
|
-
this.status.replaceChildren(number, " ", said);
|
|
139
|
+
// The box in the labels' language and its value in the parts', as its item says them.
|
|
140
|
+
const nodes = this.#fillNodes(part, this.list.getAttribute("lang"));
|
|
141
|
+
this.status.replaceChildren(number, " ", ...nodes);
|
|
145
142
|
return;
|
|
146
143
|
}
|
|
147
144
|
const words = "text" in part ? part.text : part.alt;
|
|
@@ -150,21 +147,34 @@ export class Parts {
|
|
|
150
147
|
return;
|
|
151
148
|
}
|
|
152
149
|
// The parts' language, which the list has, or none: then the element's own, as the list's.
|
|
153
|
-
|
|
154
|
-
if (lang !== null)
|
|
155
|
-
said.lang = lang;
|
|
156
|
-
said.textContent = words;
|
|
157
|
-
this.status.replaceChildren(number, " ", said);
|
|
150
|
+
this.status.replaceChildren(number, " ", spanOf(words, this.list.getAttribute("lang")));
|
|
158
151
|
}
|
|
159
152
|
/** The region is empty: what it told is no more, and the same words may be told again. */
|
|
160
153
|
quiet() {
|
|
161
154
|
this.status.replaceChildren();
|
|
162
155
|
}
|
|
163
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* An item of a part that fills a box says the box, in the labels' language, and its value, in the
|
|
158
|
+
* list's, which the item and the value inherit: a new language of the parts reaches them too.
|
|
159
|
+
*/
|
|
164
160
|
#sayFill(item, part) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
item.replaceChildren(...this.#fillNodes(part, null));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* What a part that fills a box says, as nodes (T107; 3.1.2): the labels' words, each run a span
|
|
165
|
+
* in their language, and the value a span of its own between them, in the language given, or
|
|
166
|
+
* with none, the one it inherits.
|
|
167
|
+
*/
|
|
168
|
+
#fillNodes(part, valueLang) {
|
|
169
|
+
const { before, value, after, lang } = this.#fillWords(part);
|
|
170
|
+
const nodes = [];
|
|
171
|
+
if (before !== "")
|
|
172
|
+
nodes.push(spanOf(before, lang));
|
|
173
|
+
if (value !== "")
|
|
174
|
+
nodes.push(spanOf(value, valueLang));
|
|
175
|
+
if (after !== "")
|
|
176
|
+
nodes.push(spanOf(after, lang));
|
|
177
|
+
return nodes;
|
|
168
178
|
}
|
|
169
179
|
/** An item leaving the list takes its picture off, once, and is no fill's any more. */
|
|
170
180
|
#takeOff(item) {
|
|
@@ -228,3 +238,11 @@ export class Parts {
|
|
|
228
238
|
};
|
|
229
239
|
}
|
|
230
240
|
}
|
|
241
|
+
/** A span of text, in a language given, or with none, in the one it inherits. */
|
|
242
|
+
function spanOf(text, lang) {
|
|
243
|
+
const span = document.createElement("span");
|
|
244
|
+
if (lang !== null)
|
|
245
|
+
span.lang = lang;
|
|
246
|
+
span.textContent = text;
|
|
247
|
+
return span;
|
|
248
|
+
}
|
package/lib/element/session.d.ts
CHANGED
|
@@ -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;
|
package/lib/element/session.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
// The page's pen mode (R29): one for every sheet of the page,
|
|
2
|
-
// them until the learner asks for the finger,
|
|
3
|
-
//
|
|
4
|
-
//
|
|
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();
|
package/lib/element/tools.d.ts
CHANGED
|
@@ -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,
|
|
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
|
|
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).
|
|
52
|
-
* is
|
|
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(
|
|
61
|
+
show(state: ToolState): void;
|
|
55
62
|
/**
|
|
56
|
-
* Whether anything scrolls back up the sheet, for Up,
|
|
57
|
-
* nowhere to go stands unavailable. Only what has
|
|
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:
|
package/lib/element/tools.js
CHANGED
|
@@ -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).
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
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
|
-
|
|
75
|
-
this.
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
97
|
-
// not hear may have left
|
|
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).
|
|
117
|
-
* is
|
|
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(
|
|
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,
|
|
148
|
-
* nowhere to go stands unavailable. Only what has
|
|
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.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "NovaTrail's canvases: the workplace of a task, where the learner writes, draws and types.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"./lib/element/index.js"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@altnovatrail/spec": "0.15.
|
|
29
|
+
"@altnovatrail/spec": "0.15.1",
|
|
30
30
|
"perfect-freehand": "1.2.3",
|
|
31
31
|
"rbush": "4.0.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@altnovatrail/contracts": "0.15.
|
|
34
|
+
"@altnovatrail/contracts": "0.15.1",
|
|
35
35
|
"@biomejs/biome": "2.6.5",
|
|
36
36
|
"@bufbuild/protobuf": "2.16.0",
|
|
37
37
|
"@iconify-json/material-symbols": "1.2.97",
|