@altnovatrail/canvas 0.3.25 → 0.3.27
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 +2 -12
- package/lib/core/hands.d.ts +11 -7
- package/lib/core/hands.js +30 -8
- package/lib/element/icons.d.ts +0 -36
- package/lib/element/icons.js +0 -44
- package/lib/element/index.d.ts +6 -4
- package/lib/element/index.js +184 -243
- package/lib/element/labels.d.ts +0 -6
- package/lib/element/labels.js +3 -10
- package/lib/element/tools.d.ts +35 -36
- package/lib/element/tools.js +277 -111
- package/package.json +1 -1
package/lib/element/tools.js
CHANGED
|
@@ -1,31 +1,52 @@
|
|
|
1
|
-
// The element's own
|
|
2
|
-
//
|
|
3
|
-
// the
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// buttons
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// the
|
|
18
|
-
//
|
|
19
|
-
// the
|
|
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
|
+
// (T94). 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; the second 2026-11-14
|
|
11
|
+
// amendment to R90 spec).
|
|
12
|
+
// The buttons of the bar show an icon alone, of the set every NovaTrail package of the interface
|
|
13
|
+
// draws from (R46; R78 spec): each is named by its label, in the element's language (labels.ts),
|
|
14
|
+
// which only a screen reader reads, and shows it in a tooltip of its own on the pointer's hover and
|
|
15
|
+
// on the keyboard's focus, which Escape dismisses and the pointer can move onto (the 2026-11-14
|
|
16
|
+
// amendment to R90 spec; WCAG 1.4.13). The bar is named by the canvas kind's buttons: the sheet's
|
|
17
|
+
// or the workbook's (R36), for the kind's own name is the scroll container's (T93). A lesson's
|
|
18
|
+
// worked example names it too, and has no tools of writing: the learner does not write on its
|
|
19
|
+
// sheet, and its bar holds the zoom's pair alone. Its demo's buttons, Next, which opens the next
|
|
20
|
+
// part, and Demo, a disclosure button that hides the whole demo and shows it again, are actions,
|
|
21
|
+
// not tools (R42; R90 spec): each shows its label beside its icon, a stop of Tab of its own, in a
|
|
22
|
+
// row of glass at the bottom of the element, and after a line the slot `actions`, where the
|
|
23
|
+
// consumer puts its own buttons — app's Continue —, as the mockup has one row (R84; В85 in
|
|
24
|
+
// run/QUESTIONS.md). A button that goes gives its stop of Tab and the focus to the first button
|
|
25
|
+
// shown. This module is no entry point of the package.
|
|
20
26
|
import { SVG, write } from "./attributes.js";
|
|
21
27
|
import { ICONS, ROW } from "./icons.js";
|
|
22
28
|
import { labelsFor } from "./labels.js";
|
|
23
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* How long a tooltip stays after the pointer leaves its button, in milliseconds: long enough for
|
|
31
|
+
* the pointer to cross the bar's edge and the gap onto the tooltip, which keeps it (WCAG 1.4.13).
|
|
32
|
+
*/
|
|
33
|
+
export const TIP_GRACE_MS = 200;
|
|
34
|
+
/** The element's own buttons, as the element shows them. */
|
|
24
35
|
export class Tools {
|
|
25
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* What the element puts beside its scroll container: the band the bar stands in the middle of,
|
|
38
|
+
* as wide as nothing, so that only the bar and its tooltip, which stand out of it, take a pointer,
|
|
39
|
+
* and as the element does: a consumer's pointer-events: none stops them too (R20, R28).
|
|
40
|
+
*/
|
|
41
|
+
rail = document.createElement("div");
|
|
42
|
+
/** The bar: a toolbar, named in the element's language. */
|
|
26
43
|
element = document.createElement("div");
|
|
27
|
-
/**
|
|
28
|
-
|
|
44
|
+
/** A worked example's row: Next, Demo and the consumer's buttons in the slot `actions` (R84). */
|
|
45
|
+
row = document.createElement("div");
|
|
46
|
+
#actions = document.createElement("slot");
|
|
47
|
+
#beforeActions = separator();
|
|
48
|
+
/** The tooltip of the button the pointer is over, or the keyboard's focus is on. */
|
|
49
|
+
tip = document.createElement("div");
|
|
29
50
|
#next = plainButton("next");
|
|
30
51
|
#demo = plainButton("demoShown");
|
|
31
52
|
#group = document.createElement("div");
|
|
@@ -33,21 +54,16 @@ export class Tools {
|
|
|
33
54
|
#eraser = radioButton("eraser");
|
|
34
55
|
#undo = plainButton("undo");
|
|
35
56
|
#clear = plainButton("clear");
|
|
36
|
-
/**
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#down = plainButton("down");
|
|
40
|
-
/** Zoom in and Zoom out, and Left and Right, two more pairs of the same kind (T94). */
|
|
57
|
+
/** The lines between the bar's groups: before the zoom's pair, and before the finger's button. */
|
|
58
|
+
#beforeZoom = separator();
|
|
59
|
+
#beforeFinger = separator();
|
|
41
60
|
#zoomPair = document.createElement("div");
|
|
42
61
|
#zoomIn = plainButton("zoomIn");
|
|
43
62
|
#zoomOut = plainButton("zoomOut");
|
|
44
|
-
#acrossPair = document.createElement("div");
|
|
45
|
-
#left = plainButton("left");
|
|
46
|
-
#right = plainButton("right");
|
|
47
63
|
#finger = plainButton("finger");
|
|
48
64
|
/**
|
|
49
|
-
* The buttons with the keys of their labels,
|
|
50
|
-
*
|
|
65
|
+
* The buttons with the keys of their labels, the row's and then the bar's in the order the arrow
|
|
66
|
+
* keys go through them. A button is named only by its label (R46), so each is here with its key.
|
|
51
67
|
*/
|
|
52
68
|
#labelled = [
|
|
53
69
|
[this.#next, "next"],
|
|
@@ -56,46 +72,83 @@ export class Tools {
|
|
|
56
72
|
[this.#eraser, "eraser"],
|
|
57
73
|
[this.#undo, "undo"],
|
|
58
74
|
[this.#clear, "clear"],
|
|
59
|
-
[this.#up, "up"],
|
|
60
|
-
[this.#down, "down"],
|
|
61
75
|
[this.#zoomIn, "zoomIn"],
|
|
62
76
|
[this.#zoomOut, "zoomOut"],
|
|
63
|
-
[this.#left, "left"],
|
|
64
|
-
[this.#right, "right"],
|
|
65
77
|
[this.#finger, "finger"],
|
|
66
78
|
];
|
|
67
|
-
/**
|
|
68
|
-
|
|
79
|
+
/**
|
|
80
|
+
* The bar's buttons in the order the arrow keys go through them: each shows an icon alone, and a
|
|
81
|
+
* tooltip. Next and Demo show their labels (R90 spec).
|
|
82
|
+
*/
|
|
83
|
+
#buttons = this.#labelled
|
|
84
|
+
.map(([button]) => button)
|
|
85
|
+
.filter((button) => button !== this.#next && button !== this.#demo);
|
|
69
86
|
/** The language of the labels shown. */
|
|
70
87
|
#lang;
|
|
71
|
-
/** What the
|
|
88
|
+
/** What the bar is of, named so. */
|
|
72
89
|
#kind = "sheet";
|
|
73
|
-
/** Whether a button of the
|
|
90
|
+
/** Whether a button of the bar has had the focus: Tab comes to the first button until one has. */
|
|
74
91
|
#chosen = false;
|
|
92
|
+
/** The button the pointer is over, the one the keyboard's focus is on, and the tooltip's. */
|
|
93
|
+
#hovered;
|
|
94
|
+
#focused;
|
|
95
|
+
#tipFor;
|
|
96
|
+
/** Whether the pointer is over the tooltip, which keeps it. */
|
|
97
|
+
#onTip = false;
|
|
98
|
+
/** The tooltip Escape dismissed: it comes again only for another button, or anew. */
|
|
99
|
+
#dismissed;
|
|
100
|
+
#grace;
|
|
101
|
+
/** Escape, heard on the document while a tooltip shows, wherever the focus is. */
|
|
102
|
+
#escape = (event) => {
|
|
103
|
+
if (event.key !== "Escape" || this.#tipFor === undefined)
|
|
104
|
+
return;
|
|
105
|
+
this.#dismissed = this.#tipFor;
|
|
106
|
+
this.#showTip();
|
|
107
|
+
};
|
|
75
108
|
constructor(actions, controls) {
|
|
109
|
+
this.rail.className = "rail";
|
|
76
110
|
this.element.className = "tools";
|
|
77
111
|
this.element.setAttribute("role", "toolbar");
|
|
78
|
-
this
|
|
112
|
+
this.element.setAttribute("aria-orientation", "vertical");
|
|
113
|
+
// Glass that scrolls inside itself is no stop of Tab of its own, as Firefox makes it, and a
|
|
114
|
+
// press on the glass between buttons, which would focus it then, takes the focus nowhere.
|
|
115
|
+
for (const glass of [this.element, this.row]) {
|
|
116
|
+
glass.tabIndex = -1;
|
|
117
|
+
glass.addEventListener("mousedown", (event) => {
|
|
118
|
+
const { target } = event;
|
|
119
|
+
if (target === glass || (target instanceof HTMLElement && target.className === "line")) {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
this.tip.className = "tip";
|
|
125
|
+
// The tooltip says what the button's name says already: a screen reader reads that alone.
|
|
126
|
+
this.tip.setAttribute("aria-hidden", "true");
|
|
127
|
+
this.tip.hidden = true;
|
|
128
|
+
this.row.className = "tools row";
|
|
79
129
|
// Next and Demo control what they do not hold: the region that tells of a part, and the list.
|
|
80
130
|
this.#next.setAttribute("aria-controls", controls.status);
|
|
81
131
|
this.#demo.setAttribute("aria-controls", controls.parts);
|
|
82
132
|
this.#demo.setAttribute("aria-expanded", "true");
|
|
83
|
-
this.#
|
|
133
|
+
this.#actions.name = "actions";
|
|
134
|
+
// The line stands between the element's buttons and the consumer's only while there are any.
|
|
135
|
+
this.#beforeActions.hidden = true;
|
|
136
|
+
this.#actions.addEventListener("slotchange", () => {
|
|
137
|
+
this.#beforeActions.hidden = this.#actions.assignedNodes({ flatten: true }).length === 0;
|
|
138
|
+
});
|
|
139
|
+
this.row.append(this.#next, this.#demo, this.#beforeActions, this.#actions);
|
|
84
140
|
this.#group.className = "choice";
|
|
85
141
|
this.#group.setAttribute("role", "radiogroup");
|
|
86
142
|
this.#group.append(this.#pen, this.#eraser);
|
|
87
|
-
this.#pair.className = "updown";
|
|
88
|
-
this.#pair.append(this.#up, this.#down);
|
|
89
143
|
this.#zoomPair.className = "zoom";
|
|
90
144
|
this.#zoomPair.append(this.#zoomIn, this.#zoomOut);
|
|
91
|
-
|
|
92
|
-
this
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// A worked example's
|
|
97
|
-
const
|
|
98
|
-
for (const hidden of [...later, this.#right, this.#finger]) {
|
|
145
|
+
// The finger's button comes last: coming and going, it moves no other button of the bar.
|
|
146
|
+
this.element.append(this.#group, this.#undo, this.#clear, this.#beforeZoom, this.#zoomPair, this.#beforeFinger, this.#finger);
|
|
147
|
+
this.rail.append(this.element, this.row, this.tip);
|
|
148
|
+
for (const button of this.#buttons)
|
|
149
|
+
button.classList.add("icon");
|
|
150
|
+
// A worked example's row and the finger's button come with what they are for.
|
|
151
|
+
for (const hidden of [this.row, this.#next, this.#demo, this.#beforeFinger, this.#finger]) {
|
|
99
152
|
hidden.hidden = true;
|
|
100
153
|
}
|
|
101
154
|
// Tab comes to the first button shown, until another has had the focus.
|
|
@@ -116,12 +169,6 @@ export class Tools {
|
|
|
116
169
|
doing(this.#zoomIn, () => actions.zoom(true));
|
|
117
170
|
doing(this.#zoomOut, () => actions.zoom(false));
|
|
118
171
|
this.#demo.addEventListener("click", () => actions.toggle());
|
|
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.
|
|
121
|
-
this.#up.addEventListener("click", () => actions.upOrDown(false));
|
|
122
|
-
this.#down.addEventListener("click", () => actions.upOrDown(true));
|
|
123
|
-
this.#left.addEventListener("click", () => actions.leftOrRight(false));
|
|
124
|
-
this.#right.addEventListener("click", () => actions.leftOrRight(true));
|
|
125
172
|
this.#finger.addEventListener("click", () => actions.fingers());
|
|
126
173
|
this.element.addEventListener("keydown", (event) => this.#key(event));
|
|
127
174
|
// The button that had the focus last is the one Tab comes back to.
|
|
@@ -131,16 +178,40 @@ export class Tools {
|
|
|
131
178
|
return;
|
|
132
179
|
this.#chosen = true;
|
|
133
180
|
this.#stopAt(focused);
|
|
181
|
+
// The keyboard's focus shows the tooltip; a press of the pointer, which focuses too, not.
|
|
182
|
+
this.#focused = focused.matches(":focus-visible") ? focused : undefined;
|
|
183
|
+
this.#showTip();
|
|
184
|
+
});
|
|
185
|
+
// Next, Demo or the consumer's button, reached by Tab in a row narrower than its buttons.
|
|
186
|
+
this.row.addEventListener("focusin", (event) => {
|
|
187
|
+
if (event.target instanceof Element)
|
|
188
|
+
bringIn(this.row, event.target);
|
|
189
|
+
});
|
|
190
|
+
// A tooltip stands by its button as the bar scrolls under it.
|
|
191
|
+
this.element.addEventListener("scroll", () => this.#placeTip());
|
|
192
|
+
this.element.addEventListener("focusout", () => {
|
|
193
|
+
this.#focused = undefined;
|
|
194
|
+
this.#showTip();
|
|
195
|
+
});
|
|
196
|
+
for (const button of this.#buttons)
|
|
197
|
+
this.#hover(button);
|
|
198
|
+
this.tip.addEventListener("pointerenter", () => {
|
|
199
|
+
this.#onTip = true;
|
|
200
|
+
this.#showTip();
|
|
201
|
+
});
|
|
202
|
+
this.tip.addEventListener("pointerleave", () => {
|
|
203
|
+
this.#onTip = false;
|
|
204
|
+
this.#leave();
|
|
134
205
|
});
|
|
135
206
|
this.label(null);
|
|
136
207
|
}
|
|
137
208
|
/**
|
|
138
|
-
* The
|
|
139
|
-
*
|
|
140
|
-
* Next, unavailable while the demo is hidden or open whole, and Demo, expanded while the demo
|
|
141
|
-
* shown (R42). Zoom in and Zoom out stand unavailable at their ends
|
|
142
|
-
*
|
|
143
|
-
*
|
|
209
|
+
* The bar as the sheet now is. Only what has changed is written. A worked example's has no tools
|
|
210
|
+
* of writing, no undo and no clearing, for the learner does not write on its sheet, and its row
|
|
211
|
+
* has Next, unavailable while the demo is hidden or open whole, and Demo, expanded while the demo
|
|
212
|
+
* is shown (R42). Zoom in and Zoom out stand unavailable at their ends (T94). The tool in use
|
|
213
|
+
* shows its icon filled, and Demo's icon points down while the demo is shown, and along the row
|
|
214
|
+
* while it is hidden (R46).
|
|
144
215
|
*/
|
|
145
216
|
show(state) {
|
|
146
217
|
const { kind, tools, tool, undoable, clearable, larger, smaller, finger, opens, expanded } = state;
|
|
@@ -149,8 +220,9 @@ export class Tools {
|
|
|
149
220
|
this.#name();
|
|
150
221
|
}
|
|
151
222
|
const writes = kind !== "example";
|
|
223
|
+
this.rail.classList.toggle("example", !writes);
|
|
152
224
|
this.#reveal([
|
|
153
|
-
[this
|
|
225
|
+
[this.row, !writes],
|
|
154
226
|
[this.#next, !writes],
|
|
155
227
|
[this.#demo, !writes],
|
|
156
228
|
[this.#group, writes],
|
|
@@ -158,9 +230,8 @@ export class Tools {
|
|
|
158
230
|
[this.#eraser, writes && tools.includes("eraser")],
|
|
159
231
|
[this.#undo, writes],
|
|
160
232
|
[this.#clear, writes],
|
|
161
|
-
[this.#
|
|
162
|
-
[this.#
|
|
163
|
-
[this.#right, smaller],
|
|
233
|
+
[this.#beforeZoom, writes],
|
|
234
|
+
[this.#beforeFinger, writes && finger],
|
|
164
235
|
[this.#finger, writes && finger],
|
|
165
236
|
]);
|
|
166
237
|
write(this.#pen, "aria-checked", String(tool === "pen"));
|
|
@@ -176,31 +247,8 @@ export class Tools {
|
|
|
176
247
|
draw(this.#demo, expanded ? "demoShown" : "demoHidden", false);
|
|
177
248
|
}
|
|
178
249
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* changed is written.
|
|
182
|
-
*/
|
|
183
|
-
edges(above, below, before, after) {
|
|
184
|
-
write(this.#up, "aria-disabled", above ? null : "true");
|
|
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");
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Whether the row sticks over what scrolls the element (R28): in a low window it stands in its
|
|
191
|
-
* place instead, above the statement, and scrolls away with it. The same state writes nothing:
|
|
192
|
-
* a token forced to what it is already changes no attribute.
|
|
193
|
-
*/
|
|
194
|
-
stick(sticks) {
|
|
195
|
-
this.element.classList.toggle("loose", !sticks);
|
|
196
|
-
}
|
|
197
|
-
/** Whether the row sticks, or stands in its place in a low window. */
|
|
198
|
-
get sticks() {
|
|
199
|
-
return !this.element.classList.contains("loose");
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* The labels in the language of a tag — the element's `lang` — and the row's own `lang` theirs,
|
|
203
|
-
* so that a screen reader reads them in the language they are in.
|
|
250
|
+
* The labels in the language of a tag — the element's `lang` — and the bar's own `lang` theirs,
|
|
251
|
+
* so that a screen reader reads them in the language they are in, and the tooltip too.
|
|
204
252
|
*/
|
|
205
253
|
label(tag) {
|
|
206
254
|
const { lang, labels } = labelsFor(tag);
|
|
@@ -208,6 +256,8 @@ export class Tools {
|
|
|
208
256
|
return;
|
|
209
257
|
this.#lang = lang;
|
|
210
258
|
this.element.lang = lang;
|
|
259
|
+
this.row.lang = lang;
|
|
260
|
+
this.tip.lang = lang;
|
|
211
261
|
this.#name();
|
|
212
262
|
this.#group.setAttribute("aria-label", labels.tool);
|
|
213
263
|
for (const [button, key] of this.#labelled) {
|
|
@@ -215,16 +265,93 @@ export class Tools {
|
|
|
215
265
|
if (label !== null)
|
|
216
266
|
label.textContent = labels[key];
|
|
217
267
|
}
|
|
268
|
+
this.#tipFor = undefined;
|
|
269
|
+
this.#showTip();
|
|
270
|
+
}
|
|
271
|
+
/** The element left the page: a tooltip goes with it, and Escape is no longer heard. */
|
|
272
|
+
disconnect() {
|
|
273
|
+
clearTimeout(this.#grace);
|
|
274
|
+
this.#hovered = undefined;
|
|
275
|
+
this.#focused = undefined;
|
|
276
|
+
this.#onTip = false;
|
|
277
|
+
this.#showTip();
|
|
218
278
|
}
|
|
219
|
-
/** The
|
|
279
|
+
/** The bar's name: the canvas kind's buttons, in the labels' language. */
|
|
220
280
|
#name() {
|
|
221
281
|
const { labels } = labelsFor(this.#lang ?? null);
|
|
222
282
|
write(this.element, "aria-label", labels[`${this.#kind}Buttons`]);
|
|
223
283
|
}
|
|
224
284
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
|
|
285
|
+
* A button's tooltip on the hover of a pointer that hovers — a mouse, a pen above the screen —,
|
|
286
|
+
* not on a touch, which has no hover and would leave a tooltip standing over the sheet.
|
|
287
|
+
*/
|
|
288
|
+
#hover(button) {
|
|
289
|
+
button.addEventListener("pointerenter", (event) => {
|
|
290
|
+
if (event.pointerType === "touch")
|
|
291
|
+
return;
|
|
292
|
+
clearTimeout(this.#grace);
|
|
293
|
+
this.#hovered = button;
|
|
294
|
+
this.#showTip();
|
|
295
|
+
});
|
|
296
|
+
button.addEventListener("pointerleave", (event) => {
|
|
297
|
+
if (event.pointerType === "touch" || this.#hovered !== button)
|
|
298
|
+
return;
|
|
299
|
+
this.#leave();
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
/** The pointer left a button or the tooltip: the tooltip goes, unless it comes back in time. */
|
|
303
|
+
#leave() {
|
|
304
|
+
clearTimeout(this.#grace);
|
|
305
|
+
this.#grace = setTimeout(() => {
|
|
306
|
+
if (this.#onTip)
|
|
307
|
+
return;
|
|
308
|
+
this.#hovered = undefined;
|
|
309
|
+
this.#showTip();
|
|
310
|
+
}, TIP_GRACE_MS);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* The tooltip of the button the pointer is over, or else of the one the keyboard's focus is on,
|
|
314
|
+
* beside it at the bar's edge, unless Escape dismissed it: only what has changed is written.
|
|
315
|
+
*/
|
|
316
|
+
#showTip() {
|
|
317
|
+
// A button the pointer was over may have gone with no pointerleave: the focus's has its tooltip.
|
|
318
|
+
const wanted = [this.#hovered, this.#focused].find((button) => button && !button.hidden);
|
|
319
|
+
if (this.#dismissed !== undefined && this.#dismissed !== wanted)
|
|
320
|
+
this.#dismissed = undefined;
|
|
321
|
+
const button = wanted !== this.#dismissed ? wanted : undefined;
|
|
322
|
+
if (button === this.#tipFor && this.tip.hidden === (button === undefined))
|
|
323
|
+
return;
|
|
324
|
+
this.#tipFor = button;
|
|
325
|
+
if (button === undefined) {
|
|
326
|
+
this.tip.hidden = true;
|
|
327
|
+
document.removeEventListener("keydown", this.#escape, true);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
this.tip.textContent = button.lastElementChild?.textContent ?? "";
|
|
331
|
+
this.#placeTip();
|
|
332
|
+
this.tip.hidden = false;
|
|
333
|
+
document.addEventListener("keydown", this.#escape, true);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The tooltip stands beside its button, 8 pixels off the bar's edge and level with its middle,
|
|
337
|
+
* read from the bar, which may scroll.
|
|
338
|
+
*/
|
|
339
|
+
#placeTip() {
|
|
340
|
+
const button = this.#tipFor;
|
|
341
|
+
if (button === undefined)
|
|
342
|
+
return;
|
|
343
|
+
const rail = this.rail.getBoundingClientRect();
|
|
344
|
+
const bar = this.element.getBoundingClientRect();
|
|
345
|
+
const box = button.getBoundingClientRect();
|
|
346
|
+
const scale = this.rail.offsetHeight > 0 ? rail.height / this.rail.offsetHeight : 1;
|
|
347
|
+
const x = bar.right + 8 * scale;
|
|
348
|
+
const y = box.top + box.height / 2;
|
|
349
|
+
this.tip.style.setProperty("--tip-x", `${(x - rail.left) / scale}px`);
|
|
350
|
+
this.tip.style.setProperty("--tip-y", `${(y - rail.top) / scale}px`);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* The arrow keys move the focus to the next button or the one before, round the bar, down and up,
|
|
354
|
+
* and Home and End to the first and the last: nothing is chosen, and no other key is the bar's.
|
|
228
355
|
*/
|
|
229
356
|
#key(event) {
|
|
230
357
|
if (event.altKey || event.ctrlKey || event.metaKey)
|
|
@@ -233,12 +360,10 @@ export class Tools {
|
|
|
233
360
|
const at = shown.indexOf(event.target);
|
|
234
361
|
if (at < 0)
|
|
235
362
|
return;
|
|
236
|
-
const onward = this.element.matches(":dir(rtl)") ? "ArrowLeft" : "ArrowRight";
|
|
237
|
-
const back = onward === "ArrowLeft" ? "ArrowRight" : "ArrowLeft";
|
|
238
363
|
let next;
|
|
239
|
-
if (event.key ===
|
|
364
|
+
if (event.key === "ArrowDown")
|
|
240
365
|
next = shown[(at + 1) % shown.length];
|
|
241
|
-
else if (event.key ===
|
|
366
|
+
else if (event.key === "ArrowUp")
|
|
242
367
|
next = shown[(at - 1 + shown.length) % shown.length];
|
|
243
368
|
else if (event.key === "Home")
|
|
244
369
|
next = shown[0];
|
|
@@ -247,35 +372,44 @@ export class Tools {
|
|
|
247
372
|
else
|
|
248
373
|
return;
|
|
249
374
|
event.preventDefault();
|
|
250
|
-
next
|
|
375
|
+
if (next === undefined)
|
|
376
|
+
return;
|
|
377
|
+
next.focus();
|
|
378
|
+
bringIn(this.element, next);
|
|
379
|
+
this.#placeTip();
|
|
251
380
|
}
|
|
252
381
|
/**
|
|
253
382
|
* Buttons come or go, all of them at once, and then a button that went gives its stop of Tab and
|
|
254
|
-
* the focus to the first button shown: the pen on a sheet,
|
|
383
|
+
* the focus to the first button shown: the pen on a sheet, Zoom in on a worked example (R28). Till
|
|
255
384
|
* a button has had the focus, the stop is the first button shown, whichever it is now. Nothing is
|
|
256
|
-
* read or written while every button stays as it is: the
|
|
385
|
+
* read or written while every button stays as it is: the bar is shown anew after every stroke.
|
|
257
386
|
*/
|
|
258
387
|
#reveal(wanted) {
|
|
259
388
|
if (wanted.every(([element, shown]) => element.hidden !== shown))
|
|
260
389
|
return;
|
|
261
390
|
// Read before a button hides: a hidden one loses the focus at the next update of the style.
|
|
262
|
-
const focused = this.#
|
|
391
|
+
const focused = this.#labelled.find(([button]) => button.matches(":focus"))?.[0];
|
|
263
392
|
for (const [element, shown] of wanted)
|
|
264
393
|
element.hidden = !shown;
|
|
394
|
+
if (this.#hovered?.hidden)
|
|
395
|
+
this.#hovered = undefined;
|
|
265
396
|
const first = this.#first();
|
|
266
397
|
if (!this.#chosen || this.#buttons.some((button) => button.tabIndex === 0 && button.hidden)) {
|
|
267
398
|
this.#stopAt(first);
|
|
268
399
|
}
|
|
269
400
|
if (focused?.hidden)
|
|
270
401
|
first.focus();
|
|
402
|
+
// A tooltip of a button that went goes with it, and one of a button that stays moves with it.
|
|
403
|
+
this.#tipFor = undefined;
|
|
404
|
+
this.#showTip();
|
|
271
405
|
}
|
|
272
|
-
/** The buttons the
|
|
406
|
+
/** The buttons the bar shows, in its order. */
|
|
273
407
|
#shown() {
|
|
274
408
|
return this.#buttons.filter((button) => !button.hidden);
|
|
275
409
|
}
|
|
276
|
-
/** The first button the
|
|
410
|
+
/** The first button the bar shows: Zoom in and Zoom out are on every bar (T94). */
|
|
277
411
|
#first() {
|
|
278
|
-
return this.#shown()[0] ?? this.#
|
|
412
|
+
return this.#shown()[0] ?? this.#zoomIn;
|
|
279
413
|
}
|
|
280
414
|
/** The one button Tab comes to: the arrow keys reach the others. */
|
|
281
415
|
#stopAt(stop) {
|
|
@@ -283,6 +417,36 @@ export class Tools {
|
|
|
283
417
|
button.tabIndex = button === stop ? 0 : -1;
|
|
284
418
|
}
|
|
285
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Glass that scrolls inside itself — the bar down, a worked example's row across — brings what has
|
|
422
|
+
* the focus wholly into its view, within its padding, as the first button and the last stand at its
|
|
423
|
+
* ends (2.4.11): Firefox's focus() leaves one in sight in part where it is, and so do all three
|
|
424
|
+
* engines in a row. The glass alone scrolls, not what scrolls the element.
|
|
425
|
+
*/
|
|
426
|
+
function bringIn(glass, item) {
|
|
427
|
+
const outer = glass.getBoundingClientRect();
|
|
428
|
+
const style = getComputedStyle(glass);
|
|
429
|
+
const top = outer.top + Number.parseFloat(style.paddingTop);
|
|
430
|
+
const bottom = outer.bottom - Number.parseFloat(style.paddingBottom);
|
|
431
|
+
const left = outer.left + Number.parseFloat(style.paddingLeft);
|
|
432
|
+
const right = outer.right - Number.parseFloat(style.paddingRight);
|
|
433
|
+
const box = item.getBoundingClientRect();
|
|
434
|
+
if (box.bottom > bottom)
|
|
435
|
+
glass.scrollTop += box.bottom - bottom;
|
|
436
|
+
else if (box.top < top)
|
|
437
|
+
glass.scrollTop -= top - box.top;
|
|
438
|
+
if (box.right > right)
|
|
439
|
+
glass.scrollLeft += box.right - right;
|
|
440
|
+
else if (box.left < left)
|
|
441
|
+
glass.scrollLeft -= left - box.left;
|
|
442
|
+
}
|
|
443
|
+
/** A line between two groups of the bar, which says nothing to a screen reader. */
|
|
444
|
+
function separator() {
|
|
445
|
+
const line = document.createElement("div");
|
|
446
|
+
line.className = "line";
|
|
447
|
+
line.setAttribute("aria-hidden", "true");
|
|
448
|
+
return line;
|
|
449
|
+
}
|
|
286
450
|
/** A button of a tool: a radio button of the group, a button still, which the arrows leave alone. */
|
|
287
451
|
function radioButton(value) {
|
|
288
452
|
const button = plainButton(value);
|
|
@@ -292,7 +456,7 @@ function radioButton(value) {
|
|
|
292
456
|
}
|
|
293
457
|
/**
|
|
294
458
|
* A button: its icon, an SVG that says nothing — no title, hidden from a screen reader — and its
|
|
295
|
-
* label, which names it (R46; R78 spec).
|
|
459
|
+
* label, which names it (R46; R78 spec): on the bar, only a screen reader reads it (R84).
|
|
296
460
|
*/
|
|
297
461
|
function plainButton(value) {
|
|
298
462
|
const button = document.createElement("button");
|
|
@@ -302,7 +466,9 @@ function plainButton(value) {
|
|
|
302
466
|
// The size of a letter, should the element's style not come; the style sets the one shown.
|
|
303
467
|
icon.setAttribute("width", "1em");
|
|
304
468
|
icon.setAttribute("height", "1em");
|
|
305
|
-
|
|
469
|
+
const label = document.createElement("span");
|
|
470
|
+
label.className = "label";
|
|
471
|
+
button.append(icon, label);
|
|
306
472
|
draw(button, value, false);
|
|
307
473
|
return button;
|
|
308
474
|
}
|