@altnovatrail/canvas 0.3.37 → 0.3.38
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/lib/core/geometry.js +2 -2
- package/lib/core/grid.d.ts +11 -4
- package/lib/core/grid.js +33 -8
- package/lib/core/hands.d.ts +7 -7
- package/lib/core/hands.js +5 -5
- package/lib/core/history.js +3 -3
- package/lib/core/marks.d.ts +2 -0
- package/lib/core/marks.js +11 -6
- package/lib/core/screen.d.ts +10 -11
- package/lib/core/screen.js +13 -14
- package/lib/core/sheet.d.ts +46 -3
- package/lib/core/sheet.js +46 -3
- package/lib/core/submission.js +5 -1
- package/lib/core/task.d.ts +9 -4
- package/lib/core/task.js +7 -2
- package/lib/core/tracing.d.ts +49 -13
- package/lib/core/tracing.js +110 -31
- package/lib/element/icons.d.ts +81 -14
- package/lib/element/icons.js +82 -15
- package/lib/element/index.d.ts +32 -13
- package/lib/element/index.js +619 -246
- package/lib/element/labels.d.ts +29 -7
- package/lib/element/labels.js +32 -9
- package/lib/element/session.d.ts +0 -3
- package/lib/element/session.js +4 -8
- package/lib/element/tools.d.ts +30 -19
- package/lib/element/tools.js +80 -62
- package/lib/element/tracing.d.ts +49 -5
- package/lib/element/tracing.js +419 -10
- package/package.json +3 -3
- package/lib/core/zoom.d.ts +0 -23
- package/lib/core/zoom.js +0 -43
package/lib/element/labels.d.ts
CHANGED
|
@@ -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
|
|
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,38 @@ export interface Labels {
|
|
|
24
23
|
readonly eraser: string;
|
|
25
24
|
readonly undo: string;
|
|
26
25
|
readonly clear: string;
|
|
27
|
-
/** The
|
|
28
|
-
readonly
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
/** The tool that moves the sheet and writes nothing (R88). */
|
|
27
|
+
readonly hand: string;
|
|
28
|
+
/**
|
|
29
|
+
* The button of a task from paper's grid, by the grid the sheet shows now: a press turns it to
|
|
30
|
+
* the next (R88).
|
|
31
|
+
*/
|
|
32
|
+
readonly gridDots: string;
|
|
33
|
+
readonly gridLines: string;
|
|
34
|
+
readonly gridBlank: string;
|
|
35
|
+
readonly gridSquares: string;
|
|
32
36
|
/** The tracing paper's grip, and the button atop the tools that hides it or shows it (R87). */
|
|
33
37
|
readonly moveTask: string;
|
|
34
38
|
readonly hideTask: string;
|
|
35
39
|
readonly showTask: string;
|
|
40
|
+
/**
|
|
41
|
+
* The tracing paper's bar of scale (R89): its name, smaller, larger, the scale as a percentage,
|
|
42
|
+
* {percent}, which a press sets back to its own size, and fit to the window.
|
|
43
|
+
*/
|
|
44
|
+
readonly scaleButtons: string;
|
|
45
|
+
readonly zoomOut: string;
|
|
46
|
+
readonly zoomIn: string;
|
|
47
|
+
readonly scaleReset: string;
|
|
48
|
+
readonly fit: string;
|
|
49
|
+
/**
|
|
50
|
+
* The reading of the statement in clean print (R89): its button, as it offers it, waits and
|
|
51
|
+
* offers the photo back, and the sign above the paper of what it shows.
|
|
52
|
+
*/
|
|
53
|
+
readonly recognise: string;
|
|
54
|
+
readonly recognising: string;
|
|
55
|
+
readonly original: string;
|
|
56
|
+
readonly photoShown: string;
|
|
57
|
+
readonly readingShown: string;
|
|
36
58
|
/** A box of a workbook's line, alone in it (R36). */
|
|
37
59
|
readonly box: string;
|
|
38
60
|
/** A box among several of its line, by its slot: {slot} (R36). */
|
package/lib/element/labels.js
CHANGED
|
@@ -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
|
|
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,24 @@ const ENGLISH = Object.freeze({
|
|
|
28
28
|
eraser: "Eraser",
|
|
29
29
|
undo: "Undo",
|
|
30
30
|
clear: "Clear",
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
hand: "Hand",
|
|
32
|
+
gridDots: "Grid: dots",
|
|
33
|
+
gridLines: "Grid: lines",
|
|
34
|
+
gridBlank: "Grid: blank",
|
|
35
|
+
gridSquares: "Grid: squares",
|
|
34
36
|
moveTask: "Move the task",
|
|
35
37
|
hideTask: "Hide the task",
|
|
36
38
|
showTask: "Show the task",
|
|
39
|
+
scaleButtons: "Task scale",
|
|
40
|
+
zoomOut: "Smaller",
|
|
41
|
+
zoomIn: "Larger",
|
|
42
|
+
scaleReset: "{percent}: back to 100%",
|
|
43
|
+
fit: "Fit",
|
|
44
|
+
recognise: "Recognise",
|
|
45
|
+
recognising: "Recognising…",
|
|
46
|
+
original: "Original",
|
|
47
|
+
photoShown: "Photo of the task",
|
|
48
|
+
readingShown: "Recognised by AI",
|
|
37
49
|
box: "Box",
|
|
38
50
|
boxAt: "Box {slot}",
|
|
39
51
|
boxIn: "Box {line}.{slot}",
|
|
@@ -57,7 +69,6 @@ const LABELS = new Map([
|
|
|
57
69
|
sheetButtons: "Кнопки листа",
|
|
58
70
|
workbookButtons: "Кнопки тетради",
|
|
59
71
|
paperButtons: "Кнопки задачи с бумаги",
|
|
60
|
-
exampleButtons: "Кнопки примера",
|
|
61
72
|
next: "Дальше",
|
|
62
73
|
demo: "Показ",
|
|
63
74
|
tool: "Инструмент",
|
|
@@ -65,12 +76,24 @@ const LABELS = new Map([
|
|
|
65
76
|
eraser: "Ластик",
|
|
66
77
|
undo: "Отменить",
|
|
67
78
|
clear: "Очистить",
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
hand: "Рука",
|
|
80
|
+
gridDots: "Сетка: точки",
|
|
81
|
+
gridLines: "Сетка: строчки",
|
|
82
|
+
gridBlank: "Сетка: пусто",
|
|
83
|
+
gridSquares: "Сетка: клетки",
|
|
71
84
|
moveTask: "Подвинуть задачу",
|
|
72
85
|
hideTask: "Спрятать задачу",
|
|
73
86
|
showTask: "Показать задачу",
|
|
87
|
+
scaleButtons: "Масштаб задачи",
|
|
88
|
+
zoomOut: "Уменьшить",
|
|
89
|
+
zoomIn: "Увеличить",
|
|
90
|
+
scaleReset: "{percent}: вернуть 100 %",
|
|
91
|
+
fit: "Вписать",
|
|
92
|
+
recognise: "Распознать",
|
|
93
|
+
recognising: "Распознаём…",
|
|
94
|
+
original: "Оригинал",
|
|
95
|
+
photoShown: "Фото задачи",
|
|
96
|
+
readingShown: "Распознано ИИ",
|
|
74
97
|
box: "Окошко",
|
|
75
98
|
boxAt: "Окошко {slot}",
|
|
76
99
|
boxIn: "Окошко {line}.{slot}",
|
package/lib/element/session.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { PenMode } from "../core/hands.js";
|
|
2
|
-
import { PageZoom } from "../core/zoom.js";
|
|
3
2
|
/** The pen mode of every sheet of this page. */
|
|
4
3
|
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,11 +1,7 @@
|
|
|
1
|
-
// The page's pen mode (R29)
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// This module is no entry point of the package.
|
|
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 till the page is loaded again. The next task is a new element (R20), and it stays. It is a
|
|
3
|
+
// state of the interface in memory, not data: nothing is stored or sent. This module is no entry
|
|
4
|
+
// point of the package.
|
|
6
5
|
import { PenMode } from "../core/hands.js";
|
|
7
|
-
import { PageZoom } from "../core/zoom.js";
|
|
8
6
|
/** The pen mode of every sheet of this page. */
|
|
9
7
|
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,15 +1,19 @@
|
|
|
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
|
|
5
|
-
*
|
|
8
|
+
* clearing, 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
|
-
|
|
12
|
-
readonly
|
|
15
|
+
/** A task from paper's grid turned to the next (R88). */
|
|
16
|
+
readonly turnGrid: () => void;
|
|
13
17
|
readonly next: () => void;
|
|
14
18
|
readonly toggle: () => void;
|
|
15
19
|
/** A task from paper's tracing paper hidden, or shown again (R87). */
|
|
@@ -28,10 +32,9 @@ export interface DemoControls {
|
|
|
28
32
|
*/
|
|
29
33
|
export type RowKind = "sheet" | "workbook" | "paper" | "example";
|
|
30
34
|
/**
|
|
31
|
-
* What the bar shows: what it is of, the tools the task allows
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* whether the demo is shown (R42).
|
|
35
|
+
* What the bar shows: what it is of, the tools the task allows — the hand besides, always —, the
|
|
36
|
+
* one in use, whether undo and clearing have anything to do, and on a worked example whether Next
|
|
37
|
+
* has a part to open and whether the demo is shown (R42).
|
|
35
38
|
*/
|
|
36
39
|
export interface ToolState {
|
|
37
40
|
readonly kind: RowKind;
|
|
@@ -39,13 +42,11 @@ export interface ToolState {
|
|
|
39
42
|
readonly tool: Tool;
|
|
40
43
|
readonly undoable: boolean;
|
|
41
44
|
readonly clearable: boolean;
|
|
42
|
-
readonly larger: boolean;
|
|
43
|
-
readonly smaller: boolean;
|
|
44
|
-
readonly finger: boolean;
|
|
45
45
|
readonly opens: boolean;
|
|
46
46
|
readonly expanded: boolean;
|
|
47
|
-
/** On a task from paper, whether its tracing paper is shown (R87). */
|
|
47
|
+
/** On a task from paper, whether its tracing paper is shown (R87), and its sheet's grid (R88). */
|
|
48
48
|
readonly traced: boolean;
|
|
49
|
+
readonly grid: PaperGrid;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* How long a tooltip stays after the pointer leaves its button, in milliseconds: long enough for
|
|
@@ -69,13 +70,12 @@ export declare class Tools {
|
|
|
69
70
|
readonly tip: HTMLDivElement;
|
|
70
71
|
constructor(actions: ToolActions, controls: DemoControls);
|
|
71
72
|
/**
|
|
72
|
-
* The bar as the sheet now is. Only what has changed is written. A worked example
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* while
|
|
78
|
-
* tracing paper, and fills its icon while the paper is shown (R87).
|
|
73
|
+
* The bar as the sheet now is. Only what has changed is written. A worked example has no bar, for
|
|
74
|
+
* the learner does not write on its sheet, and its row has Next, unavailable while the demo is
|
|
75
|
+
* hidden or open whole, and Demo, expanded while the demo is shown (R42). The tool in use shows its
|
|
76
|
+
* icon filled, and Demo's icon points down while the demo is shown, and along the row while it is
|
|
77
|
+
* hidden (R46). A task from paper's button atop the tools says what it does to the tracing paper,
|
|
78
|
+
* and fills its icon while the paper is shown (R87), and its grid's button shows the grid (R88).
|
|
79
79
|
*/
|
|
80
80
|
show(state: ToolState): void;
|
|
81
81
|
/**
|
|
@@ -86,3 +86,14 @@ export declare class Tools {
|
|
|
86
86
|
/** The element left the page: a tooltip goes with it, and Escape is no longer heard. */
|
|
87
87
|
disconnect(): void;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* A button: its icon, an SVG that says nothing — no title, hidden from a screen reader — and its
|
|
91
|
+
* label, which names it (R46; R78 spec): on the bar, only a screen reader reads it (R84).
|
|
92
|
+
*/
|
|
93
|
+
export declare function plainButton(value: Value): HTMLButtonElement;
|
|
94
|
+
/**
|
|
95
|
+
* A value's icon on its button, filled or in outline, written only when it is another than the one
|
|
96
|
+
* there: the icon's name stays on the SVG, as data. One mirrored in a row that runs right to left
|
|
97
|
+
* says so by its class, which the style turns (R46).
|
|
98
|
+
*/
|
|
99
|
+
export declare function draw(button: HTMLButtonElement, value: Value, filled: boolean): void;
|
package/lib/element/tools.js
CHANGED
|
@@ -1,33 +1,39 @@
|
|
|
1
|
-
// The element's own buttons (R28, R84): the tools the task allows — the pen and the eraser —
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
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. The sheet has no
|
|
8
|
+
// buttons that scroll it: the hand, two fingers or a finger in pen mode drag it, the wheel and the
|
|
9
|
+
// keys scroll it (R84; R88; R90 spec). The buttons of the bar show an icon alone, of the set every
|
|
10
|
+
// NovaTrail package of the interface draws from (R46; R78 spec): each is named by its label, in the
|
|
11
|
+
// element's language (labels.ts), which only a screen reader reads, and shows it in a tooltip of
|
|
12
|
+
// its own on the pointer's hover and on the keyboard's focus, which Escape dismisses and the
|
|
13
|
+
// pointer can move onto (R90 spec; WCAG 1.4.13). The bar is named by the canvas kind's buttons: the
|
|
14
|
+
// sheet's or the workbook's (R36), for the kind's own name is the scroll container's (R28). A
|
|
15
|
+
// lesson's worked example has no bar: the learner does not write on its sheet, which scrolls as the
|
|
16
|
+
// page does. Its demo's buttons, Next, which opens the next part, and Demo, a disclosure button
|
|
19
17
|
// that hides the whole demo and shows it again, are actions, not tools (R42; R90 spec): each shows
|
|
20
18
|
// its label beside its icon, a stop of Tab of its own, in a row of glass at the bottom of the
|
|
21
19
|
// element, and after a line the slot `actions`, where the consumer puts its own buttons — app's
|
|
22
20
|
// Continue —, as the mockup has one row (R84; R36 spec). A task from paper's bar has one button
|
|
23
21
|
// more, atop the tools, after a line: "Hide the task" while its tracing paper is shown, its icon
|
|
24
22
|
// 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)
|
|
26
|
-
//
|
|
27
|
-
//
|
|
23
|
+
// toggle button as well, which would say it twice (R87; R90 spec) —, and one last, after a line:
|
|
24
|
+
// the sheet's grid, its icon and its name the grid shown now, which a press turns to the next,
|
|
25
|
+
// round — dots, lines, blank, squares (R88). A button that goes gives its stop of Tab and the focus
|
|
26
|
+
// to the first button shown. This module is no entry point of the package.
|
|
28
27
|
import { SVG, write } from "./attributes.js";
|
|
29
28
|
import { ICONS, ROW } from "./icons.js";
|
|
30
29
|
import { labelsFor } from "./labels.js";
|
|
30
|
+
/** The value of the grid's button, and the key of its label, by the grid shown. */
|
|
31
|
+
const GRID_VALUES = {
|
|
32
|
+
dots: "gridDots",
|
|
33
|
+
lines: "gridLines",
|
|
34
|
+
blank: "gridBlank",
|
|
35
|
+
squares: "gridSquares",
|
|
36
|
+
};
|
|
31
37
|
/**
|
|
32
38
|
* How long a tooltip stays after the pointer leaves its button, in milliseconds: long enough for
|
|
33
39
|
* the pointer to cross the bar's edge and the gap onto the tooltip, which keeps it (WCAG 1.4.13).
|
|
@@ -57,15 +63,12 @@ export class Tools {
|
|
|
57
63
|
#group = document.createElement("div");
|
|
58
64
|
#pen = radioButton("pen");
|
|
59
65
|
#eraser = radioButton("eraser");
|
|
66
|
+
#hand = radioButton("hand");
|
|
60
67
|
#undo = plainButton("undo");
|
|
61
68
|
#clear = plainButton("clear");
|
|
62
|
-
/**
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#zoomPair = document.createElement("div");
|
|
66
|
-
#zoomIn = plainButton("zoomIn");
|
|
67
|
-
#zoomOut = plainButton("zoomOut");
|
|
68
|
-
#finger = plainButton("finger");
|
|
69
|
+
/** A task from paper's grid, after a line (R88). */
|
|
70
|
+
#beforeGrid = separator();
|
|
71
|
+
#grid = plainButton("gridDots");
|
|
69
72
|
/**
|
|
70
73
|
* The buttons with the keys of their labels, the row's and then the bar's in the order the arrow
|
|
71
74
|
* keys go through them. A button is named only by its label (R46), so each is here with its key.
|
|
@@ -76,11 +79,10 @@ export class Tools {
|
|
|
76
79
|
[this.#task, "hideTask"],
|
|
77
80
|
[this.#pen, "pen"],
|
|
78
81
|
[this.#eraser, "eraser"],
|
|
82
|
+
[this.#hand, "hand"],
|
|
79
83
|
[this.#undo, "undo"],
|
|
80
84
|
[this.#clear, "clear"],
|
|
81
|
-
[this.#
|
|
82
|
-
[this.#zoomOut, "zoomOut"],
|
|
83
|
-
[this.#finger, "finger"],
|
|
85
|
+
[this.#grid, "gridDots"],
|
|
84
86
|
];
|
|
85
87
|
/**
|
|
86
88
|
* The bar's buttons in the order the arrow keys go through them: each shows an icon alone, and a
|
|
@@ -95,6 +97,8 @@ export class Tools {
|
|
|
95
97
|
#kind = "sheet";
|
|
96
98
|
/** Whether a task from paper's tracing paper is shown: the button atop the tools says which. */
|
|
97
99
|
#traced = true;
|
|
100
|
+
/** A task from paper's grid: its button's icon and name say which. */
|
|
101
|
+
#gridShown = "dots";
|
|
98
102
|
/** Whether a button of the bar has had the focus: Tab comes to the first button until one has. */
|
|
99
103
|
#chosen = false;
|
|
100
104
|
/** The button the pointer is over, the one the keyboard's focus is on, and the tooltip's. */
|
|
@@ -147,23 +151,20 @@ export class Tools {
|
|
|
147
151
|
this.row.append(this.#next, this.#demo, this.#beforeActions, this.#actions);
|
|
148
152
|
this.#group.className = "choice";
|
|
149
153
|
this.#group.setAttribute("role", "radiogroup");
|
|
150
|
-
this.#group.append(this.#pen, this.#eraser);
|
|
151
|
-
this.#
|
|
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);
|
|
154
|
+
this.#group.append(this.#pen, this.#eraser, this.#hand);
|
|
155
|
+
this.element.append(this.#task, this.#afterTask, this.#group, this.#undo, this.#clear, this.#beforeGrid, this.#grid);
|
|
155
156
|
this.rail.append(this.element, this.row, this.tip);
|
|
156
157
|
for (const button of this.#buttons)
|
|
157
158
|
button.classList.add("icon");
|
|
158
|
-
// A worked example's row and
|
|
159
|
+
// A worked example's row and a task from paper's buttons come with what they are for.
|
|
159
160
|
for (const hidden of [
|
|
160
161
|
this.row,
|
|
161
162
|
this.#next,
|
|
162
163
|
this.#demo,
|
|
163
164
|
this.#task,
|
|
164
165
|
this.#afterTask,
|
|
165
|
-
this.#
|
|
166
|
-
this.#
|
|
166
|
+
this.#beforeGrid,
|
|
167
|
+
this.#grid,
|
|
167
168
|
]) {
|
|
168
169
|
hidden.hidden = true;
|
|
169
170
|
}
|
|
@@ -172,6 +173,7 @@ export class Tools {
|
|
|
172
173
|
// The element decides whether a choice is a change: the tool in use, chosen again, is none.
|
|
173
174
|
this.#pen.addEventListener("click", () => actions.choose("pen"));
|
|
174
175
|
this.#eraser.addEventListener("click", () => actions.choose("eraser"));
|
|
176
|
+
this.#hand.addEventListener("click", () => actions.choose("hand"));
|
|
175
177
|
const doing = (button, act) => {
|
|
176
178
|
// aria-disabled stops no click: the button does nothing while it stands unavailable.
|
|
177
179
|
button.addEventListener("click", () => {
|
|
@@ -182,10 +184,8 @@ export class Tools {
|
|
|
182
184
|
doing(this.#undo, actions.undo);
|
|
183
185
|
doing(this.#clear, actions.clear);
|
|
184
186
|
doing(this.#next, actions.next);
|
|
185
|
-
doing(this.#zoomIn, () => actions.zoom(true));
|
|
186
|
-
doing(this.#zoomOut, () => actions.zoom(false));
|
|
187
187
|
this.#demo.addEventListener("click", () => actions.toggle());
|
|
188
|
-
this.#
|
|
188
|
+
this.#grid.addEventListener("click", () => actions.turnGrid());
|
|
189
189
|
this.#task.addEventListener("click", () => actions.trace());
|
|
190
190
|
this.element.addEventListener("keydown", (event) => this.#key(event));
|
|
191
191
|
// The button that had the focus last is the one Tab comes back to.
|
|
@@ -223,16 +223,15 @@ export class Tools {
|
|
|
223
223
|
this.label(null);
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
|
-
* The bar as the sheet now is. Only what has changed is written. A worked example
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* while
|
|
232
|
-
* tracing paper, and fills its icon while the paper is shown (R87).
|
|
226
|
+
* The bar as the sheet now is. Only what has changed is written. A worked example has no bar, for
|
|
227
|
+
* the learner does not write on its sheet, and its row has Next, unavailable while the demo is
|
|
228
|
+
* hidden or open whole, and Demo, expanded while the demo is shown (R42). The tool in use shows its
|
|
229
|
+
* icon filled, and Demo's icon points down while the demo is shown, and along the row while it is
|
|
230
|
+
* hidden (R46). A task from paper's button atop the tools says what it does to the tracing paper,
|
|
231
|
+
* and fills its icon while the paper is shown (R87), and its grid's button shows the grid (R88).
|
|
233
232
|
*/
|
|
234
233
|
show(state) {
|
|
235
|
-
const { kind, tools, tool, undoable, clearable,
|
|
234
|
+
const { kind, tools, tool, undoable, clearable, opens, expanded, traced, grid } = state;
|
|
236
235
|
if (kind !== this.#kind) {
|
|
237
236
|
this.#kind = kind;
|
|
238
237
|
this.#name();
|
|
@@ -240,6 +239,7 @@ export class Tools {
|
|
|
240
239
|
const writes = kind !== "example";
|
|
241
240
|
this.rail.classList.toggle("example", !writes);
|
|
242
241
|
this.#reveal([
|
|
242
|
+
[this.element, writes],
|
|
243
243
|
[this.row, !writes],
|
|
244
244
|
[this.#next, !writes],
|
|
245
245
|
[this.#demo, !writes],
|
|
@@ -248,22 +248,27 @@ export class Tools {
|
|
|
248
248
|
[this.#group, writes],
|
|
249
249
|
[this.#pen, writes],
|
|
250
250
|
[this.#eraser, writes && tools.includes("eraser")],
|
|
251
|
+
[this.#hand, writes],
|
|
251
252
|
[this.#undo, writes],
|
|
252
253
|
[this.#clear, writes],
|
|
253
|
-
[this.#
|
|
254
|
-
[this.#
|
|
255
|
-
[this.#finger, writes && finger],
|
|
254
|
+
[this.#beforeGrid, kind === "paper"],
|
|
255
|
+
[this.#grid, kind === "paper"],
|
|
256
256
|
]);
|
|
257
257
|
write(this.#pen, "aria-checked", String(tool === "pen"));
|
|
258
258
|
write(this.#eraser, "aria-checked", String(tool === "eraser"));
|
|
259
|
+
write(this.#hand, "aria-checked", String(tool === "hand"));
|
|
259
260
|
write(this.#undo, "aria-disabled", undoable ? null : "true");
|
|
260
261
|
write(this.#clear, "aria-disabled", clearable ? null : "true");
|
|
261
262
|
write(this.#next, "aria-disabled", opens ? null : "true");
|
|
262
|
-
write(this.#zoomIn, "aria-disabled", larger ? null : "true");
|
|
263
|
-
write(this.#zoomOut, "aria-disabled", smaller ? null : "true");
|
|
264
263
|
write(this.#demo, "aria-expanded", String(expanded));
|
|
265
264
|
draw(this.#pen, "pen", tool === "pen");
|
|
266
265
|
draw(this.#eraser, "eraser", tool === "eraser");
|
|
266
|
+
draw(this.#hand, "hand", tool === "hand");
|
|
267
|
+
draw(this.#grid, GRID_VALUES[grid], false);
|
|
268
|
+
if (grid !== this.#gridShown) {
|
|
269
|
+
this.#gridShown = grid;
|
|
270
|
+
this.#nameGrid();
|
|
271
|
+
}
|
|
267
272
|
draw(this.#demo, expanded ? "demoShown" : "demoHidden", false);
|
|
268
273
|
draw(this.#task, "task", traced);
|
|
269
274
|
if (traced !== this.#traced) {
|
|
@@ -291,6 +296,7 @@ export class Tools {
|
|
|
291
296
|
label.textContent = labels[key];
|
|
292
297
|
}
|
|
293
298
|
this.#nameTask();
|
|
299
|
+
this.#nameGrid();
|
|
294
300
|
this.#tipFor = undefined;
|
|
295
301
|
this.#showTip();
|
|
296
302
|
}
|
|
@@ -316,10 +322,22 @@ export class Tools {
|
|
|
316
322
|
if (this.#tipFor === this.#task)
|
|
317
323
|
this.tip.textContent = name;
|
|
318
324
|
}
|
|
319
|
-
/** The
|
|
325
|
+
/** The name of a task from paper's grid button, by the grid shown, and its tooltip's (R88). */
|
|
326
|
+
#nameGrid() {
|
|
327
|
+
const { labels } = labelsFor(this.#lang ?? null);
|
|
328
|
+
const label = this.#grid.lastElementChild;
|
|
329
|
+
const name = labels[GRID_VALUES[this.#gridShown]];
|
|
330
|
+
if (label === null || label.textContent === name)
|
|
331
|
+
return;
|
|
332
|
+
label.textContent = name;
|
|
333
|
+
if (this.#tipFor === this.#grid)
|
|
334
|
+
this.tip.textContent = name;
|
|
335
|
+
}
|
|
336
|
+
/** The bar's name: the canvas kind's buttons, in the labels' language; an example has none. */
|
|
320
337
|
#name() {
|
|
321
338
|
const { labels } = labelsFor(this.#lang ?? null);
|
|
322
|
-
|
|
339
|
+
const kind = this.#kind;
|
|
340
|
+
write(this.element, "aria-label", kind === "example" ? null : labels[`${kind}Buttons`]);
|
|
323
341
|
}
|
|
324
342
|
/**
|
|
325
343
|
* A button's tooltip on the hover of a pointer that hovers — a mouse, a pen above the screen —,
|
|
@@ -420,7 +438,7 @@ export class Tools {
|
|
|
420
438
|
}
|
|
421
439
|
/**
|
|
422
440
|
* 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,
|
|
441
|
+
* the focus to the first button shown: the pen on a sheet, or a task from paper's button (R28). Till
|
|
424
442
|
* a button has had the focus, the stop is the first button shown, whichever it is now. Nothing is
|
|
425
443
|
* read or written while every button stays as it is: the bar is shown anew after every stroke.
|
|
426
444
|
*/
|
|
@@ -447,9 +465,9 @@ export class Tools {
|
|
|
447
465
|
#shown() {
|
|
448
466
|
return this.#buttons.filter((button) => !button.hidden);
|
|
449
467
|
}
|
|
450
|
-
/** The first button the bar shows:
|
|
468
|
+
/** The first button the bar shows: the pen is on every bar a learner writes on. */
|
|
451
469
|
#first() {
|
|
452
|
-
return this.#shown()[0] ?? this.#
|
|
470
|
+
return this.#shown()[0] ?? this.#pen;
|
|
453
471
|
}
|
|
454
472
|
/** The one button Tab comes to: the arrow keys reach the others. */
|
|
455
473
|
#stopAt(stop) {
|
|
@@ -498,7 +516,7 @@ function radioButton(value) {
|
|
|
498
516
|
* A button: its icon, an SVG that says nothing — no title, hidden from a screen reader — and its
|
|
499
517
|
* label, which names it (R46; R78 spec): on the bar, only a screen reader reads it (R84).
|
|
500
518
|
*/
|
|
501
|
-
function plainButton(value) {
|
|
519
|
+
export function plainButton(value) {
|
|
502
520
|
const button = document.createElement("button");
|
|
503
521
|
button.type = "button";
|
|
504
522
|
const icon = document.createElementNS(SVG, "svg");
|
|
@@ -517,7 +535,7 @@ function plainButton(value) {
|
|
|
517
535
|
* there: the icon's name stays on the SVG, as data. One mirrored in a row that runs right to left
|
|
518
536
|
* says so by its class, which the style turns (R46).
|
|
519
537
|
*/
|
|
520
|
-
function draw(button, value, filled) {
|
|
538
|
+
export function draw(button, value, filled) {
|
|
521
539
|
const icon = button.firstElementChild;
|
|
522
540
|
if (!(icon instanceof SVGSVGElement))
|
|
523
541
|
return;
|
package/lib/element/tracing.d.ts
CHANGED
|
@@ -1,16 +1,37 @@
|
|
|
1
|
+
import type { TracingReading } from "@altnovatrail/spec/canvas";
|
|
1
2
|
import { type Gray, type Size } from "../core/tracing.js";
|
|
2
|
-
|
|
3
|
+
import { type Labels } from "./labels.js";
|
|
4
|
+
/**
|
|
5
|
+
* What the grip, the corners and the bar ask of the element: the tracing paper moved to a place,
|
|
6
|
+
* or to a place at a scale, or fit to the window, the change ended, and the statement read.
|
|
7
|
+
*/
|
|
3
8
|
export interface TracingMoves {
|
|
4
9
|
/** The place the learner moves it to: the element keeps it to the sheet, and gives where it lies. */
|
|
5
10
|
readonly move: (at: readonly [number, number]) => readonly [number, number];
|
|
6
|
-
/** The
|
|
11
|
+
/** The place and the scale the learner gives it: the element keeps it to the sheet. */
|
|
12
|
+
readonly resize: (at: readonly [number, number], scale: number) => Placed;
|
|
13
|
+
/** As large as the window's width takes it, right of the bar of tools. */
|
|
14
|
+
readonly fit: () => void;
|
|
15
|
+
/** The change is over: a drag let go, a key pressed, a button pressed, the wheel at rest. */
|
|
7
16
|
readonly moved: () => void;
|
|
17
|
+
/** The learner pressed "Recognise" while the reading is offered. */
|
|
18
|
+
readonly read: () => void;
|
|
8
19
|
}
|
|
9
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Where the sheet is on the stage: `k` CSS pixels a unit, the visible part's top left corner, and
|
|
22
|
+
* the stage's size, CSS pixels.
|
|
23
|
+
*/
|
|
10
24
|
export interface StageView {
|
|
11
25
|
readonly k: number;
|
|
12
26
|
readonly vx: number;
|
|
13
27
|
readonly vy: number;
|
|
28
|
+
readonly width: number;
|
|
29
|
+
readonly height: number;
|
|
30
|
+
}
|
|
31
|
+
/** Where the paper lies and how large, as the element kept it to the sheet. */
|
|
32
|
+
interface Placed {
|
|
33
|
+
readonly at: readonly [number, number];
|
|
34
|
+
readonly scale: number;
|
|
14
35
|
}
|
|
15
36
|
/** The crop's picture as the element read it: its size on the sheet and its grey pixels. */
|
|
16
37
|
interface Read {
|
|
@@ -26,7 +47,29 @@ export declare class TracingPaper {
|
|
|
26
47
|
readonly grip: HTMLButtonElement;
|
|
27
48
|
/** The grip's tooltip, which says what its name says already: a screen reader reads that alone. */
|
|
28
49
|
readonly tip: HTMLDivElement;
|
|
50
|
+
/**
|
|
51
|
+
* Under the ink, over the paper: the statements read, in place of the crop, and the light that
|
|
52
|
+
* sweeps the crop while they are read. It says nothing: the bar's button and the sign do.
|
|
53
|
+
*/
|
|
54
|
+
readonly cover: HTMLDivElement;
|
|
55
|
+
/** Over the ink: the frame of the paper chosen, and its corners, which scale it. */
|
|
56
|
+
readonly frame: HTMLDivElement;
|
|
57
|
+
/** Over the ink: the sign above the paper's corner of what it shows. */
|
|
58
|
+
readonly sign: HTMLDivElement;
|
|
59
|
+
/** Over the ink: the bar of scale under the paper chosen. */
|
|
60
|
+
readonly bar: HTMLDivElement;
|
|
29
61
|
constructor(moves: TracingMoves);
|
|
62
|
+
/** The paper's scale, as the element last placed it. */
|
|
63
|
+
get scale(): number;
|
|
64
|
+
/**
|
|
65
|
+
* The reading of the statement the consumer gives: the bar offers "Recognise" while it is any,
|
|
66
|
+
* and the statements take the crop's place once they come for the learner who asked.
|
|
67
|
+
*/
|
|
68
|
+
set reading(reading: TracingReading | undefined);
|
|
69
|
+
/** The press on the sheet lets the paper go: its frame, corners and bar go out of sight. */
|
|
70
|
+
letGo(): void;
|
|
71
|
+
/** Ctrl or ⌘ with the wheel over the paper: its scale by a notch, over once the wheel rests. */
|
|
72
|
+
wheel(up: boolean): void;
|
|
30
73
|
/** The tracing paper's size on the sheet: the largest till the crop's picture is read. */
|
|
31
74
|
get size(): Size;
|
|
32
75
|
/**
|
|
@@ -41,8 +84,8 @@ export declare class TracingPaper {
|
|
|
41
84
|
* the paper's size is known.
|
|
42
85
|
*/
|
|
43
86
|
show(blob: Blob | undefined, sized: () => void): void;
|
|
44
|
-
/** The
|
|
45
|
-
label(
|
|
87
|
+
/** The labels of the grip, its tooltip, the sign and the bar, in the element's language. */
|
|
88
|
+
label(labels: Labels, lang: string): void;
|
|
46
89
|
/**
|
|
47
90
|
* The layer and the grip as the tracing paper now is: at `at`, shown or hidden, or not there at
|
|
48
91
|
* all, and the grip where the sheet's view puts the paper's top edge on the stage.
|
|
@@ -50,6 +93,7 @@ export declare class TracingPaper {
|
|
|
50
93
|
place(state: {
|
|
51
94
|
readonly at: readonly [number, number];
|
|
52
95
|
readonly hidden: boolean;
|
|
96
|
+
readonly scale?: number;
|
|
53
97
|
} | undefined, view: StageView): void;
|
|
54
98
|
connect(): void;
|
|
55
99
|
/** The element left the page: the crop's address goes, and a drag or a tooltip with it. */
|