@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/index.js
CHANGED
|
@@ -31,7 +31,12 @@
|
|
|
31
31
|
// area as the part opens (T61; R42). A worked example on a workbook lays its lines out as a task's,
|
|
32
32
|
// and a part of its demo that fills a box writes the box's value in it (T85; R61). The types of
|
|
33
33
|
// its contract with app are spec's, of @altnovatrail/spec/canvas: the element implements its CanvasElement, and the package puts the
|
|
34
|
-
// element and its events in the DOM's maps (T69; R07).
|
|
34
|
+
// element and its events in the DOM's maps (T69; R07). The keyboard goes into the sheet and out:
|
|
35
|
+
// a container that scrolls is a region named by the canvas kind, with a stop of Tab of its own and
|
|
36
|
+
// a ring when the keyboard brings the focus there (T93; R33); for a `lang` the labels are not in,
|
|
37
|
+
// the container is in theirs and the column in the element's (T106; R74). The row's Zoom in and Zoom out step
|
|
38
|
+
// the page's zoom of the sheet from its fit to twice it, and a zoomed sheet scrolls across as well
|
|
39
|
+
// as down, with Left and Right in the row, two fingers and the keys (T94).
|
|
35
40
|
import { cellOf, cellsOf, filledOf, sheetFilledOf } from "../core/boxes.js";
|
|
36
41
|
import { Clock } from "../core/clock.js";
|
|
37
42
|
import { ERASER_BUTTON, Eraser } from "../core/eraser.js";
|
|
@@ -52,11 +57,11 @@ import { cellsForCheck, workForCheck } from "../core/submission.js";
|
|
|
52
57
|
import { isTool, isWorkbook, NO_TASK, sameLayer, sameStatement, taskOf, templateOf, wholeSheet, } from "../core/task.js";
|
|
53
58
|
import { nextIdOf, resumeOf, Work } from "../core/work.js";
|
|
54
59
|
import { placeOver, SVG, write } from "./attributes.js";
|
|
55
|
-
import { labelsFor, say } from "./labels.js";
|
|
60
|
+
import { knows, labelsFor, say, sayAround } from "./labels.js";
|
|
56
61
|
import { Parts } from "./parts.js";
|
|
57
62
|
import { Pictures } from "./pictures.js";
|
|
58
63
|
import { attachProbe } from "./probe.js";
|
|
59
|
-
import { PEN_MODE } from "./session.js";
|
|
64
|
+
import { PAGE_ZOOM, PEN_MODE } from "./session.js";
|
|
60
65
|
import { Statement } from "./statement.js";
|
|
61
66
|
import { Tools } from "./tools.js";
|
|
62
67
|
/** The name the element is registered under. */
|
|
@@ -95,8 +100,13 @@ const UP_DOWN = 4 / 5;
|
|
|
95
100
|
// The statement and the sheet stand in a column of their own, as wide as the element up to
|
|
96
101
|
// 1000 CSS pixels and in its middle beyond, and scroll in a container of their own, by the
|
|
97
102
|
// browser's own scrolling: the wheel, the scroll bar and the keyboard work as anywhere on a page.
|
|
98
|
-
// The
|
|
99
|
-
//
|
|
103
|
+
// The page's zoom widens the column with the sheet, to twice its fit, and the container scrolls
|
|
104
|
+
// it across too, left to right whatever the page's direction, while the statement and a demo's
|
|
105
|
+
// parts stay as wide as the fit and stick to its left, in the element's own direction: they wrap
|
|
106
|
+
// as before, and scroll down alone (T94). Left and Right stand in that order in a row that runs
|
|
107
|
+
// right to left too: they point to the sides of the screen. The layers of the sheet stand in its visible part, the stage, which sticks to the
|
|
108
|
+
// container's top and left, and each shows what lies there, shifted in the frame the ink is drawn
|
|
109
|
+
// in (R18, R23; architecture 3.2 in docs/architecture.md).
|
|
100
110
|
// Above the column, as wide, stands the row of the element's own buttons, outside the container's
|
|
101
111
|
// scrolling: it sticks to the top of whatever scrolls the element, as far down as the consumer's
|
|
102
112
|
// --novatrail-canvas-top says, while the element is in sight, over the sheet as it scrolls by
|
|
@@ -139,9 +149,10 @@ const STYLE = `
|
|
|
139
149
|
background: var(--novatrail-canvas-paper, ${PAPER}); color: var(--novatrail-canvas-ink, ${INK});
|
|
140
150
|
}
|
|
141
151
|
.tools.loose { position: static; }
|
|
142
|
-
.tools .demo, .tools .choice, .tools .updown {
|
|
152
|
+
.tools .demo, .tools .choice, .tools .updown, .tools .zoom, .tools .across {
|
|
143
153
|
display: flex; gap: 8px; margin-inline-end: 16px;
|
|
144
154
|
}
|
|
155
|
+
.tools:dir(rtl) .across { flex-direction: row-reverse; }
|
|
145
156
|
.tools button {
|
|
146
157
|
box-sizing: border-box; min-width: 44px; min-height: 44px; padding: 0 8px; margin: 0;
|
|
147
158
|
font: inherit; color: inherit; background: transparent; cursor: pointer;
|
|
@@ -169,10 +180,26 @@ const STYLE = `
|
|
|
169
180
|
vertical-align: -0.25em; fill: currentColor;
|
|
170
181
|
}
|
|
171
182
|
.tools:dir(rtl) svg.mirrored { transform: scaleX(-1); }
|
|
183
|
+
.frame {
|
|
184
|
+
position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
|
|
185
|
+
}
|
|
172
186
|
.viewport {
|
|
173
187
|
flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; overflow-anchor: none;
|
|
188
|
+
outline: none; -webkit-tap-highlight-color: transparent;
|
|
189
|
+
}
|
|
190
|
+
.viewport.zoomed { overflow-x: auto; direction: ltr; }
|
|
191
|
+
.ring { position: absolute; inset: 0; z-index: 0; pointer-events: none; display: none; }
|
|
192
|
+
.viewport:focus-visible + .ring {
|
|
193
|
+
display: block; outline: 2px solid var(--novatrail-canvas-ink, ${INK}); outline-offset: -2px;
|
|
194
|
+
}
|
|
195
|
+
.column {
|
|
196
|
+
position: relative; width: calc(min(100%, ${K_MAX * SHEET.width}px) * var(--zoom));
|
|
197
|
+
margin: 0 auto;
|
|
198
|
+
}
|
|
199
|
+
.zoomed .statement, .zoomed .parts {
|
|
200
|
+
position: sticky; left: 0; box-sizing: border-box; width: calc(100% / var(--zoom));
|
|
201
|
+
direction: var(--direction, ltr);
|
|
174
202
|
}
|
|
175
|
-
.column { position: relative; width: min(100%, ${K_MAX * SHEET.width}px); margin: 0 auto; }
|
|
176
203
|
.statement { padding: 0 0 12px; overflow-wrap: break-word; }
|
|
177
204
|
.statement:empty { display: none; }
|
|
178
205
|
.statement p { margin: 0 0 8px; }
|
|
@@ -196,7 +223,7 @@ const STYLE = `
|
|
|
196
223
|
background: var(--novatrail-canvas-paper, ${PAPER});
|
|
197
224
|
}
|
|
198
225
|
.stage {
|
|
199
|
-
position: sticky; top: 0; max-height: 100%; overflow: clip;
|
|
226
|
+
position: sticky; top: 0; left: 0; max-height: 100%; overflow: clip;
|
|
200
227
|
user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
|
|
201
228
|
}
|
|
202
229
|
.spot { position: absolute; visibility: hidden; }
|
|
@@ -242,7 +269,7 @@ canvas {
|
|
|
242
269
|
background: Highlight; color: HighlightText; border-color: Highlight;
|
|
243
270
|
}
|
|
244
271
|
.tools [aria-disabled="true"] { color: GrayText; border-color: GrayText; }
|
|
245
|
-
.tools button:focus-visible { outline-color: Highlight; }
|
|
272
|
+
.tools button:focus-visible, .viewport:focus-visible + .ring { outline-color: Highlight; }
|
|
246
273
|
}
|
|
247
274
|
`;
|
|
248
275
|
/** The sheet of STYLE that the elements of a document adopt, made by the first of them there. */
|
|
@@ -299,7 +326,14 @@ function htmlLayer(name) {
|
|
|
299
326
|
* commands undo and clear, which the contract does not name.
|
|
300
327
|
*/
|
|
301
328
|
export class NovatrailCanvas extends HTMLElement {
|
|
329
|
+
/**
|
|
330
|
+
* The wrapper, which does not scroll, of the container that scrolls and of the ring of its focus
|
|
331
|
+
* over it: an outline of the container itself would stand under the sheet's paper and stage,
|
|
332
|
+
* which are positioned in it (T93).
|
|
333
|
+
*/
|
|
334
|
+
#wrapper = document.createElement("div");
|
|
302
335
|
#viewport = document.createElement("div");
|
|
336
|
+
#ring = document.createElement("div");
|
|
303
337
|
#column = document.createElement("div");
|
|
304
338
|
#sheet = document.createElement("div");
|
|
305
339
|
/** The sheet's visible part, where its layers stand, bottom to top (concepts 8 spec; R23). */
|
|
@@ -332,7 +366,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
332
366
|
choose: (tool) => this.#choose(tool),
|
|
333
367
|
undo: () => this.undo(),
|
|
334
368
|
clear: () => this.clear(),
|
|
335
|
-
upOrDown: (onward) => this.#
|
|
369
|
+
upOrDown: (onward) => this.#step(onward, "y"),
|
|
370
|
+
zoom: (larger) => this.#zoomBy(larger),
|
|
371
|
+
leftOrRight: (onward) => this.#step(onward, "x"),
|
|
336
372
|
// The finger writes again on every sheet of the page, with no event: the next pen's touch
|
|
337
373
|
// puts the page back in pen mode (R29).
|
|
338
374
|
fingers: () => {
|
|
@@ -368,12 +404,17 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
368
404
|
#hands = new Hands({
|
|
369
405
|
writer: () => this.#writer(),
|
|
370
406
|
drop: (pointerId) => this.#drop(pointerId),
|
|
371
|
-
scroll: (dy, fresh) => this.#scroll(dy, fresh),
|
|
407
|
+
scroll: (dx, dy, fresh) => this.#scroll(dx, dy, fresh),
|
|
408
|
+
across: () => this.#zoom > 1,
|
|
372
409
|
}, PEN_MODE);
|
|
373
410
|
/** Whether the row shows the finger's button: it comes and goes between strokes alone. */
|
|
374
411
|
#finger = false;
|
|
375
|
-
/**
|
|
412
|
+
/**
|
|
413
|
+
* What two fingers scroll in the gesture under way, down and across, each chosen at the first
|
|
414
|
+
* step that goes along its axis (T94): undefined till then, and null when nothing scrolls so.
|
|
415
|
+
*/
|
|
376
416
|
#latch;
|
|
417
|
+
#latchAcross;
|
|
377
418
|
/**
|
|
378
419
|
* A scroll of the page, or of an ancestor of the element in the page's own tree, heard on its way
|
|
379
420
|
* down: Up or Down may have come to an end, or left one (R33). Other scrollers are none of theirs.
|
|
@@ -394,6 +435,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
394
435
|
*/
|
|
395
436
|
#resized = () => {
|
|
396
437
|
this.#stick();
|
|
438
|
+
this.#region();
|
|
397
439
|
this.#edges();
|
|
398
440
|
};
|
|
399
441
|
#page = new ResizeObserver(this.#resized);
|
|
@@ -402,6 +444,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
402
444
|
/** The row's `top` as the last check of whether it sticks read it: the consumer's offset. */
|
|
403
445
|
#topSeen = "";
|
|
404
446
|
#unwatchPen;
|
|
447
|
+
#unwatchZoom;
|
|
448
|
+
/** The page's zoom as the sheet is laid out by it (T94). */
|
|
449
|
+
#zoom = 0;
|
|
405
450
|
#tool = "pen";
|
|
406
451
|
#task;
|
|
407
452
|
/** A lesson's worked example as the consumer gave it, and as the element checked it (R42). */
|
|
@@ -418,10 +463,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
418
463
|
#cells = [];
|
|
419
464
|
#rects = [];
|
|
420
465
|
/**
|
|
421
|
-
* The values a worked example's demo has written in its boxes,
|
|
422
|
-
*
|
|
466
|
+
* The texts of the values a worked example's demo has written in its boxes, one for each frame
|
|
467
|
+
* that has had one (T85; R60).
|
|
423
468
|
*/
|
|
424
|
-
#fills = new Map();
|
|
425
469
|
#values = [];
|
|
426
470
|
#taken = new WeakMap();
|
|
427
471
|
/** Which answer slots are filled, the same array until one changes, or null (R37, R42). */
|
|
@@ -472,8 +516,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
472
516
|
*/
|
|
473
517
|
#k = 0;
|
|
474
518
|
#sheetAt = 0;
|
|
475
|
-
/** The
|
|
519
|
+
/** The sheet's left in the container's content, as laid out then, in CSS pixels (T94). */
|
|
520
|
+
#sheetAtX = 0;
|
|
521
|
+
/** The top and the left of the visible part, in sheet units, kept from the last scroll. */
|
|
476
522
|
#vy = 0;
|
|
523
|
+
#vx = 0;
|
|
477
524
|
/** The view box the layers were last given, so that a frame without a scroll writes none. */
|
|
478
525
|
#viewBox = "";
|
|
479
526
|
#frame = 0;
|
|
@@ -484,7 +531,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
484
531
|
super();
|
|
485
532
|
const root = this.attachShadow({ mode: "open" });
|
|
486
533
|
adoptStyle(root);
|
|
534
|
+
this.#wrapper.className = "frame";
|
|
487
535
|
this.#viewport.className = "viewport";
|
|
536
|
+
this.#ring.className = "ring";
|
|
488
537
|
this.#column.className = "column";
|
|
489
538
|
this.#sheet.className = "sheet";
|
|
490
539
|
this.#stage.className = "stage";
|
|
@@ -500,7 +549,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
500
549
|
this.#sheet.append(this.#stage, this.#parts.spot);
|
|
501
550
|
this.#column.append(this.#statement.element, this.#parts.list, this.#parts.status, this.#sheet);
|
|
502
551
|
this.#viewport.append(this.#column);
|
|
503
|
-
|
|
552
|
+
this.#wrapper.append(this.#viewport, this.#ring);
|
|
553
|
+
root.append(this.#tools.element, this.#wrapper);
|
|
554
|
+
this.#zoomTo(PAGE_ZOOM.value);
|
|
504
555
|
this.#lay(NO_TASK);
|
|
505
556
|
this.#refresh();
|
|
506
557
|
this.#canvas.addEventListener("pointerdown", (event) => this.#down(event));
|
|
@@ -527,6 +578,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
527
578
|
this.#canvas.addEventListener("transitionend", () => this.#request());
|
|
528
579
|
this.#canvas.addEventListener("transitioncancel", () => this.#request());
|
|
529
580
|
this.#viewport.addEventListener("scroll", () => this.#scrolled(), { passive: true });
|
|
581
|
+
// A container that has nothing to scroll any more keeps its stop of Tab while it has the focus.
|
|
582
|
+
this.#viewport.addEventListener("blur", () => this.#region());
|
|
530
583
|
attachProbe(this, () => ({
|
|
531
584
|
strokes: this.#work.strokes,
|
|
532
585
|
live: this.#recorder.live,
|
|
@@ -858,6 +911,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
858
911
|
unwatch();
|
|
859
912
|
unenlist();
|
|
860
913
|
};
|
|
914
|
+
// The page's zoom, on every sheet of it (T94): it may have changed while the element was away.
|
|
915
|
+
this.#zoomTo(PAGE_ZOOM.value);
|
|
916
|
+
this.#unwatchZoom = PAGE_ZOOM.watch(() => this.#zoomed());
|
|
861
917
|
// A scroll does not bubble, but the document hears every one of its tree on the way down. A
|
|
862
918
|
// page that grows or shrinks scrolls nothing, and neither does a window of another size.
|
|
863
919
|
document.addEventListener("scroll", this.#heard, { capture: true, passive: true });
|
|
@@ -876,19 +932,24 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
876
932
|
*/
|
|
877
933
|
attributeChangedCallback() {
|
|
878
934
|
this.#tools.label(this.getAttribute("lang"));
|
|
935
|
+
this.#nameRegion();
|
|
879
936
|
this.#nameBoxes();
|
|
880
937
|
this.#markBoxes();
|
|
881
938
|
}
|
|
882
939
|
/**
|
|
883
|
-
* The demo's list says a box it fills in the labels' language,
|
|
884
|
-
* its
|
|
940
|
+
* The demo's list says a box it fills in the labels' language, around its value, which is a node
|
|
941
|
+
* of its own in the parts' language: "Box 1.2: " and "5" (T107); its open items too, anew.
|
|
942
|
+
* Without `lang` the labels are English, as the element's own.
|
|
885
943
|
*/
|
|
886
944
|
#nameBoxes(tag = this.getAttribute("lang")) {
|
|
887
945
|
const { lang, labels } = labelsFor(tag);
|
|
888
946
|
this.#parts.fillWords = (part) => {
|
|
889
947
|
const name = say(labels.boxIn, { line: part.fill.line, slot: part.fill.box });
|
|
890
948
|
const value = this.#example === undefined ? "" : fillValue(this.#example, part);
|
|
891
|
-
|
|
949
|
+
if (value === "")
|
|
950
|
+
return { before: name, value, after: "", lang };
|
|
951
|
+
const [before, after] = sayAround(labels.valued, "value", { name });
|
|
952
|
+
return { before, value, after, lang };
|
|
892
953
|
};
|
|
893
954
|
}
|
|
894
955
|
/**
|
|
@@ -952,8 +1013,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
952
1013
|
this.#eraser.end();
|
|
953
1014
|
this.#hands.reset();
|
|
954
1015
|
this.#latch = undefined;
|
|
1016
|
+
this.#latchAcross = undefined;
|
|
955
1017
|
this.#unwatchPen?.();
|
|
956
1018
|
this.#unwatchPen = undefined;
|
|
1019
|
+
this.#unwatchZoom?.();
|
|
1020
|
+
this.#unwatchZoom = undefined;
|
|
957
1021
|
document.removeEventListener("scroll", this.#heard, { capture: true });
|
|
958
1022
|
this.#page.disconnect();
|
|
959
1023
|
this.#port = null;
|
|
@@ -1095,7 +1159,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1095
1159
|
/**
|
|
1096
1160
|
* Each box of the lines as it now is (R36, R37): its frame, thicker when it is filled, and its
|
|
1097
1161
|
* name in the labels' language, by the element's `lang` — "Box" alone in its line, numbered by
|
|
1098
|
-
* its slot among several, and "filled" when it is.
|
|
1162
|
+
* its slot among several, and "filled" when it is. A value a worked example's demo wrote in it is
|
|
1163
|
+
* no part of its name: its text after the frame says it, in the lines' language (T107). Only
|
|
1164
|
+
* what has changed is written.
|
|
1099
1165
|
*/
|
|
1100
1166
|
#markBoxes() {
|
|
1101
1167
|
const { lang, labels } = labelsFor(this.getAttribute("lang"));
|
|
@@ -1106,13 +1172,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1106
1172
|
const several = (this.#laid?.items[cell.item - 1]?.boxes.length ?? 0) > 1;
|
|
1107
1173
|
const filled = this.#filled?.[cell.item - 1]?.[cell.slot - 1] === true;
|
|
1108
1174
|
const name = several ? say(labels.boxAt, { slot: cell.slot }) : labels.box;
|
|
1109
|
-
// A worked example's box says what its demo wrote in it: the text itself says nothing.
|
|
1110
|
-
const value = this.#fills.get(`${cell.item}.${cell.slot}`);
|
|
1111
1175
|
rect.classList.toggle("filled", filled);
|
|
1112
|
-
|
|
1113
|
-
if (value !== undefined)
|
|
1114
|
-
label = say(labels.valued, { name, value });
|
|
1115
|
-
write(rect, "aria-label", label);
|
|
1176
|
+
write(rect, "aria-label", filled ? say(labels.filled, { name }) : name);
|
|
1116
1177
|
write(rect, "lang", lang);
|
|
1117
1178
|
}
|
|
1118
1179
|
}
|
|
@@ -1271,8 +1332,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1271
1332
|
*/
|
|
1272
1333
|
#lifted(pointerId) {
|
|
1273
1334
|
this.#hands.lift(pointerId);
|
|
1274
|
-
if (!this.#hands.scrolling)
|
|
1335
|
+
if (!this.#hands.scrolling) {
|
|
1275
1336
|
this.#latch = undefined;
|
|
1337
|
+
this.#latchAcross = undefined;
|
|
1338
|
+
}
|
|
1276
1339
|
this.#refresh();
|
|
1277
1340
|
PEN_MODE.settle();
|
|
1278
1341
|
}
|
|
@@ -1308,8 +1371,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1308
1371
|
}
|
|
1309
1372
|
/**
|
|
1310
1373
|
* Where the sheet is on the screen now. The rectangles of the canvas and of the sheet give it:
|
|
1311
|
-
* the canvas is
|
|
1312
|
-
* on the screen, after whatever transform the page puts on the element. The container's
|
|
1374
|
+
* the canvas's top left corner is that of the visible part, and the sheet's width gives `k`, the
|
|
1375
|
+
* one on the screen, after whatever transform the page puts on the element. The container's
|
|
1313
1376
|
* rectangle gives the part of the canvas it shows: with the statement in sight, the canvas
|
|
1314
1377
|
* goes on below the container's bottom. The row of buttons above the container hides what it
|
|
1315
1378
|
* covers, once it sticks over the sheet as the page scrolls the element by (R28); in its place,
|
|
@@ -1317,10 +1380,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1317
1380
|
*/
|
|
1318
1381
|
#view() {
|
|
1319
1382
|
const canvas = this.#canvas.getBoundingClientRect();
|
|
1320
|
-
if (canvas.width <= 0)
|
|
1321
|
-
return undefined;
|
|
1322
|
-
const k = scaleFor(canvas.width);
|
|
1323
1383
|
const sheet = this.#sheet.getBoundingClientRect();
|
|
1384
|
+
if (canvas.width <= 0 || sheet.width <= 0)
|
|
1385
|
+
return undefined;
|
|
1386
|
+
const k = scaleFor(sheet.width);
|
|
1387
|
+
const vx = (canvas.left - sheet.left) / k;
|
|
1324
1388
|
const vy = (canvas.top - sheet.top) / k;
|
|
1325
1389
|
const port = clientBoxOf(this.#viewport);
|
|
1326
1390
|
// The row ends where the container begins, unless it sticks over it.
|
|
@@ -1331,64 +1395,109 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1331
1395
|
right: Math.min(canvas.right, port.right),
|
|
1332
1396
|
bottom: Math.min(canvas.bottom, port.bottom),
|
|
1333
1397
|
};
|
|
1334
|
-
|
|
1398
|
+
const { left, top, width, height } = canvas;
|
|
1399
|
+
return { k, vx, vy, left, top, width, height, shown };
|
|
1335
1400
|
}
|
|
1336
|
-
/**
|
|
1337
|
-
|
|
1401
|
+
/**
|
|
1402
|
+
* The sheet's top in the container's content, in CSS pixels as laid out: under the statement —
|
|
1403
|
+
* or, along `x`, its left: its margin in the middle of a wide container, and none once it is
|
|
1404
|
+
* wider (T94).
|
|
1405
|
+
*/
|
|
1406
|
+
#sheetEdge(axis) {
|
|
1338
1407
|
const port = clientBoxOf(this.#viewport);
|
|
1339
1408
|
const sheet = this.#sheet.getBoundingClientRect();
|
|
1340
|
-
return
|
|
1409
|
+
return axis === "y"
|
|
1410
|
+
? (sheet.top - port.top) / port.down + this.#viewport.scrollTop
|
|
1411
|
+
: (sheet.left - port.left) / port.across + this.#viewport.scrollLeft;
|
|
1341
1412
|
}
|
|
1342
1413
|
/**
|
|
1343
|
-
* The top of the visible part from the scroll and the last layout, without reading
|
|
1344
|
-
* again: the stage sticks to the container's top once the sheet's top has gone past
|
|
1345
|
-
* Down may have come to an end of the container, or
|
|
1414
|
+
* The top and the left of the visible part from the scroll and the last layout, without reading
|
|
1415
|
+
* the layout again: the stage sticks to the container's top once the sheet's top has gone past
|
|
1416
|
+
* it, and to its left so. Up or Down, Left or Right may have come to an end of the container, or
|
|
1417
|
+
* left one.
|
|
1346
1418
|
*/
|
|
1347
1419
|
#scrolled() {
|
|
1348
|
-
if (this.#k > 0)
|
|
1420
|
+
if (this.#k > 0) {
|
|
1349
1421
|
this.#vy = Math.max(0, this.#viewport.scrollTop - this.#sheetAt) / this.#k;
|
|
1422
|
+
this.#vx = Math.max(0, this.#viewport.scrollLeft - this.#sheetAtX) / this.#k;
|
|
1423
|
+
}
|
|
1350
1424
|
this.#request();
|
|
1351
1425
|
this.#edges();
|
|
1352
1426
|
}
|
|
1353
1427
|
/**
|
|
1354
|
-
* Up or Down was pressed (R33)
|
|
1355
|
-
* it shows in sight. It is chosen anew at every press, so
|
|
1356
|
-
* scroll on at the next. While a pointer writes or erases
|
|
1357
|
-
* under it.
|
|
1428
|
+
* Up or Down was pressed (R33), or along `x` Left or Right (T94): what two fingers would scroll
|
|
1429
|
+
* that way goes by four fifths of what it shows in sight. It is chosen anew at every press, so
|
|
1430
|
+
* that a container at its end hands the scroll on at the next. While a pointer writes or erases
|
|
1431
|
+
* on a sheet of the page, nothing moves under it.
|
|
1358
1432
|
*/
|
|
1359
|
-
#
|
|
1360
|
-
const latch = PEN_MODE.writing ? undefined : this.#scrollerFor(onward);
|
|
1433
|
+
#step(onward, axis) {
|
|
1434
|
+
const latch = PEN_MODE.writing ? undefined : this.#scrollerFor(onward, axis);
|
|
1361
1435
|
if (latch !== undefined) {
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1436
|
+
const seen = this.#seen(latch.target, axis);
|
|
1437
|
+
const step = Math.max(1, Math.round((UP_DOWN * seen) / latch.scale));
|
|
1438
|
+
const by = onward ? step : -step;
|
|
1439
|
+
latch.target.scrollBy({ [axis === "y" ? "top" : "left"]: by, behavior: "instant" });
|
|
1364
1440
|
}
|
|
1365
1441
|
this.#edges();
|
|
1366
1442
|
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Zoom in or Zoom out was pressed (T94): the page's zoom goes a step larger or smaller, and every
|
|
1445
|
+
* sheet of the page is laid out by it — but not while a pointer writes or erases on one of them,
|
|
1446
|
+
* for nothing moves under it.
|
|
1447
|
+
*/
|
|
1448
|
+
#zoomBy(larger) {
|
|
1449
|
+
if (!PEN_MODE.writing)
|
|
1450
|
+
PAGE_ZOOM.step(larger);
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* The page's zoom has changed (T94): the sheet is laid out by it at once, its top left corner in
|
|
1454
|
+
* sight staying where it was on the sheet, and the row shows what the zoom can do now.
|
|
1455
|
+
*/
|
|
1456
|
+
#zoomed() {
|
|
1457
|
+
if (!this.#zoomTo(PAGE_ZOOM.value))
|
|
1458
|
+
return;
|
|
1459
|
+
this.#layout();
|
|
1460
|
+
this.#refresh();
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* The column and the container as wide as a zoom asks, and whether that is another than the
|
|
1464
|
+
* last: the column widens with the sheet, and the container scrolls it across while the zoom is
|
|
1465
|
+
* beyond the fit (T94).
|
|
1466
|
+
*/
|
|
1467
|
+
#zoomTo(zoom) {
|
|
1468
|
+
if (zoom === this.#zoom)
|
|
1469
|
+
return false;
|
|
1470
|
+
this.#zoom = zoom;
|
|
1471
|
+
this.#column.style.setProperty("--zoom", String(zoom));
|
|
1472
|
+
this.#viewport.classList.toggle("zoomed", zoom > 1);
|
|
1473
|
+
this.#keepDirection();
|
|
1474
|
+
return true;
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* The statement and a demo's parts keep the element's own direction while the zoomed container
|
|
1478
|
+
* runs left to right: the direction the element computes, by an attribute or by a style, as the
|
|
1479
|
+
* last layout read it (T94).
|
|
1480
|
+
*/
|
|
1481
|
+
#keepDirection() {
|
|
1482
|
+
if (this.#zoom <= 1 || !this.isConnected)
|
|
1483
|
+
return;
|
|
1484
|
+
const direction = getComputedStyle(this).direction;
|
|
1485
|
+
if (this.#column.style.getPropertyValue("--direction") !== direction) {
|
|
1486
|
+
this.#column.style.setProperty("--direction", direction);
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1367
1489
|
/**
|
|
1368
1490
|
* How much of what a scroller shows is in sight, down the screen: within the ancestors that clip
|
|
1369
1491
|
* it and the visual viewport, and below the row of buttons while the row sticks over its top, or
|
|
1370
1492
|
* below the consumer's band, --novatrail-canvas-top, while the row stands in its place in a low
|
|
1371
|
-
* window. A scroller out of sight counts whole.
|
|
1372
|
-
*/
|
|
1373
|
-
#seen(target) {
|
|
1374
|
-
const
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
const own = clientBoxOf(target);
|
|
1380
|
-
whole = own.bottom - own.top;
|
|
1381
|
-
// The scroller, and every ancestor that clips it, up to the page, whose part is the sight.
|
|
1382
|
-
for (let node = target; node !== null; node = parentOf(node)) {
|
|
1383
|
-
if (node === document.documentElement)
|
|
1384
|
-
break;
|
|
1385
|
-
if (node !== target && getComputedStyle(node).overflowY === "visible")
|
|
1386
|
-
continue;
|
|
1387
|
-
const clip = node === target ? own : clientBoxOf(node);
|
|
1388
|
-
top = Math.max(top, clip.top);
|
|
1389
|
-
bottom = Math.min(bottom, clip.bottom);
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1493
|
+
* window. A scroller out of sight counts whole. Across the screen, the row covers nothing (T94).
|
|
1494
|
+
*/
|
|
1495
|
+
#seen(target, axis = "y") {
|
|
1496
|
+
const { start, end, whole } = sightOf(target, axis);
|
|
1497
|
+
if (axis === "x")
|
|
1498
|
+
return end > start ? end - start : whole;
|
|
1499
|
+
const bottom = end;
|
|
1500
|
+
let top = start;
|
|
1392
1501
|
// The row hides the top while it sticks there, as far down as the consumer's offset puts it. A
|
|
1393
1502
|
// row that stands in its place, in a low window, leaves the consumer's band over it alone.
|
|
1394
1503
|
const row = this.#tools.element;
|
|
@@ -1441,90 +1550,124 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1441
1550
|
return within ? room.top + room.offset : Number.NEGATIVE_INFINITY;
|
|
1442
1551
|
}
|
|
1443
1552
|
/**
|
|
1444
|
-
* Up and Down as the scrolling now is (R33)
|
|
1445
|
-
* scroll its way can go no further. The
|
|
1446
|
-
*
|
|
1447
|
-
* in another shadow tree: a press asks
|
|
1553
|
+
* Up and Down as the scrolling now is (R33), and Left and Right while the sheet is zoomed (T94):
|
|
1554
|
+
* each stands unavailable while what two fingers would scroll its way can go no further. The
|
|
1555
|
+
* element hears its container, the page and the ancestors in the page's own tree scroll, and the
|
|
1556
|
+
* page and the window change size, but not the scrolling in another shadow tree: a press asks
|
|
1557
|
+
* anew.
|
|
1448
1558
|
*/
|
|
1449
1559
|
#edges() {
|
|
1450
1560
|
if (!this.isConnected)
|
|
1451
1561
|
return;
|
|
1452
1562
|
const above = this.#scrollerFor(false) !== undefined;
|
|
1453
|
-
|
|
1563
|
+
const below = this.#scrollerFor(true) !== undefined;
|
|
1564
|
+
const zoomed = this.#zoom > 1;
|
|
1565
|
+
const before = zoomed && this.#scrollerFor(false, "x") !== undefined;
|
|
1566
|
+
const after = zoomed && this.#scrollerFor(true, "x") !== undefined;
|
|
1567
|
+
this.#tools.edges(above, below, before, after);
|
|
1454
1568
|
}
|
|
1455
1569
|
/**
|
|
1456
|
-
* Two fingers moved
|
|
1457
|
-
* them.
|
|
1458
|
-
*
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
1570
|
+
* Two fingers moved right on the screen by `dx` CSS pixels and down it by `dy` (R29), and what
|
|
1571
|
+
* they scroll goes with them. The gesture's first step down chooses what it scrolls down, for the
|
|
1572
|
+
* whole gesture, and its first step across, while the sheet is zoomed, what it scrolls across
|
|
1573
|
+
* (T94): the sheet's own container if it can go that way, or else the nearest ancestor of the
|
|
1574
|
+
* element that scrolls and can, or else the page. A container at its end hands the scroll on at
|
|
1575
|
+
* the next gesture, not within this one. The steps of an event add up, and its end scrolls them
|
|
1576
|
+
* at once.
|
|
1461
1577
|
*/
|
|
1462
|
-
#scroll(dy, fresh) {
|
|
1463
|
-
if (fresh)
|
|
1464
|
-
this.#latch =
|
|
1578
|
+
#scroll(dx, dy, fresh) {
|
|
1579
|
+
if (fresh) {
|
|
1580
|
+
this.#latch = undefined;
|
|
1581
|
+
this.#latchAcross = undefined;
|
|
1582
|
+
}
|
|
1465
1583
|
// The content goes with the fingers: down the screen, the scroll goes back.
|
|
1466
|
-
if (this.#latch
|
|
1584
|
+
if (dy !== 0 && this.#latch === undefined)
|
|
1585
|
+
this.#latch = this.#scrollerFor(dy < 0) ?? null;
|
|
1586
|
+
if (dx !== 0 && this.#latchAcross === undefined) {
|
|
1587
|
+
this.#latchAcross = this.#zoom > 1 ? (this.#scrollerFor(dx < 0, "x") ?? null) : null;
|
|
1588
|
+
}
|
|
1589
|
+
if (this.#latch)
|
|
1467
1590
|
this.#latch.rest -= dy / this.#latch.scale;
|
|
1591
|
+
if (this.#latchAcross)
|
|
1592
|
+
this.#latchAcross.rest -= dx / this.#latchAcross.scale;
|
|
1468
1593
|
}
|
|
1469
|
-
/**
|
|
1594
|
+
/**
|
|
1595
|
+
* The scroll the fingers' moves of an event owe, in whole pixels: the rest waits for the next.
|
|
1596
|
+
* One scroller that goes both ways goes both at once.
|
|
1597
|
+
*/
|
|
1470
1598
|
#flush() {
|
|
1471
|
-
const
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
if (step === 0)
|
|
1599
|
+
const down = owed(this.#latch);
|
|
1600
|
+
const across = owed(this.#latchAcross);
|
|
1601
|
+
if (down !== undefined && across !== undefined && down.target === across.target) {
|
|
1602
|
+
down.target.scrollBy({ left: across.step, top: down.step, behavior: "instant" });
|
|
1476
1603
|
return;
|
|
1477
|
-
|
|
1478
|
-
|
|
1604
|
+
}
|
|
1605
|
+
if (down !== undefined)
|
|
1606
|
+
down.target.scrollBy({ top: down.step, behavior: "instant" });
|
|
1607
|
+
if (across !== undefined)
|
|
1608
|
+
across.target.scrollBy({ left: across.step, behavior: "instant" });
|
|
1479
1609
|
}
|
|
1480
|
-
/**
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1610
|
+
/**
|
|
1611
|
+
* What scrolls on down the content, for `onward`, or back up it — or, along `x`, on right across
|
|
1612
|
+
* it or back left (T94).
|
|
1613
|
+
*/
|
|
1614
|
+
#scrollerFor(onward, axis = "y") {
|
|
1615
|
+
if (scrollsOn(this.#viewport, onward, axis)) {
|
|
1616
|
+
return { target: this.#viewport, scale: scaleOf(this.#viewport, undefined, axis), rest: 0 };
|
|
1484
1617
|
}
|
|
1485
|
-
const { overflow, fromBody } = pageOverflow();
|
|
1618
|
+
const { overflow, fromBody } = pageOverflow(axis);
|
|
1486
1619
|
for (let node = parentOf(this); node !== null; node = parentOf(node)) {
|
|
1487
1620
|
if (isPage(node, fromBody))
|
|
1488
1621
|
break;
|
|
1489
1622
|
const style = getComputedStyle(node);
|
|
1490
|
-
if (!SCROLLING.test(style.overflowY))
|
|
1623
|
+
if (!SCROLLING.test(axis === "y" ? style.overflowY : style.overflowX))
|
|
1491
1624
|
continue;
|
|
1492
|
-
if (scrollsOn(node, onward))
|
|
1493
|
-
return { target: node, scale: scaleOf(node), rest: 0 };
|
|
1625
|
+
if (scrollsOn(node, onward, axis)) {
|
|
1626
|
+
return { target: node, scale: scaleOf(node, undefined, axis), rest: 0 };
|
|
1627
|
+
}
|
|
1494
1628
|
// A container that keeps its scrolling to itself hands none on.
|
|
1495
|
-
|
|
1629
|
+
const keeps = axis === "y" ? style.overscrollBehaviorY : style.overscrollBehaviorX;
|
|
1630
|
+
if (keeps === "contain" || keeps === "none")
|
|
1496
1631
|
return undefined;
|
|
1497
|
-
}
|
|
1498
1632
|
}
|
|
1499
1633
|
// A page that hides its overflow, as one under a modal does, a finger would not scroll: nor do two.
|
|
1500
1634
|
if (overflow === "hidden" || overflow === "clip")
|
|
1501
1635
|
return undefined;
|
|
1502
1636
|
const page = document.scrollingElement;
|
|
1503
|
-
if (page === null || !scrollsOn(page, onward))
|
|
1637
|
+
if (page === null || !scrollsOn(page, onward, axis))
|
|
1504
1638
|
return undefined;
|
|
1505
1639
|
return { target: window, scale: 1, rest: 0 };
|
|
1506
1640
|
}
|
|
1507
1641
|
/**
|
|
1508
1642
|
* The stage takes the visible part of the sheet, and the canvas a pixel of its buffer for each
|
|
1509
1643
|
* device pixel: its size on the screen times the density (R18). The layers follow in the same
|
|
1510
|
-
* frame.
|
|
1644
|
+
* frame. However large the zoom, the canvas is no larger than the container (T94).
|
|
1511
1645
|
*/
|
|
1512
1646
|
#layout() {
|
|
1647
|
+
// The content of a new size, or the container, may overflow it now, or no more.
|
|
1648
|
+
this.#region();
|
|
1513
1649
|
const area = this.#area;
|
|
1514
1650
|
if (area === undefined || area.width === 0)
|
|
1515
1651
|
return;
|
|
1516
|
-
// The column is as wide as the container up to the cap,
|
|
1517
|
-
// part of the sheet.
|
|
1518
|
-
const k = fitScale(area.width);
|
|
1519
|
-
const sheetAt = this.#
|
|
1520
|
-
|
|
1521
|
-
//
|
|
1522
|
-
//
|
|
1652
|
+
// The column is as wide as the container up to the cap, times the page's zoom, and the stage
|
|
1653
|
+
// as tall and as wide as the visible part of the sheet.
|
|
1654
|
+
const k = fitScale(area.width, this.#zoom);
|
|
1655
|
+
const sheetAt = this.#sheetEdge("y");
|
|
1656
|
+
const sheetAtX = this.#sheetEdge("x");
|
|
1657
|
+
// A new width or zoom scales the sheet, and a statement of a new height moves it: the top left
|
|
1658
|
+
// corner of the visible part stays where it was on the sheet, unless the sheet's top, or its
|
|
1659
|
+
// left, is in sight. A new height of the container alone moves neither, and a scroll under way
|
|
1660
|
+
// goes on.
|
|
1523
1661
|
if (this.#vy > 0 && (k !== this.#k || Math.abs(sheetAt - this.#sheetAt) > 0.5)) {
|
|
1524
1662
|
this.#viewport.scrollTop = sheetAt + this.#vy * k;
|
|
1525
1663
|
}
|
|
1664
|
+
if (this.#vx > 0 && k !== this.#k)
|
|
1665
|
+
this.#viewport.scrollLeft = sheetAtX + this.#vx * k;
|
|
1526
1666
|
this.#k = k;
|
|
1527
1667
|
this.#sheetAt = sheetAt;
|
|
1668
|
+
this.#sheetAtX = sheetAtX;
|
|
1669
|
+
this.#keepDirection();
|
|
1670
|
+
this.#stage.style.width = `${Math.min(area.width, SHEET.width * k)}px`;
|
|
1528
1671
|
this.#stage.style.height = `${Math.min(area.height, SHEET.height * k)}px`;
|
|
1529
1672
|
const onScreen = this.#canvas.getBoundingClientRect();
|
|
1530
1673
|
const width = Math.round(onScreen.width * devicePixelRatio);
|
|
@@ -1654,20 +1797,19 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1654
1797
|
/**
|
|
1655
1798
|
* The values a worked example's demo has written in the boxes of its workbook (T85; R60): each in
|
|
1656
1799
|
* the middle of its box, on the line's baseline, at the width the layout gives its text, as the
|
|
1657
|
-
* lines' texts are; none while the demo is hidden.
|
|
1800
|
+
* lines' texts are; none while the demo is hidden. A value is a text of its own just after its
|
|
1801
|
+
* box's frame, which a screen reader reads after the box, in the lines' language, as the lines'
|
|
1802
|
+
* texts are (T107; 3.1.2). Only what changed is written.
|
|
1658
1803
|
*/
|
|
1659
1804
|
#showFills(fills) {
|
|
1660
|
-
this.#fills = fills;
|
|
1661
1805
|
const page = this.#laid;
|
|
1662
1806
|
if (page === undefined)
|
|
1663
1807
|
return;
|
|
1664
|
-
let changed = false;
|
|
1665
1808
|
for (const [c, cell] of this.#cells.entries()) {
|
|
1666
1809
|
const value = fills.get(`${cell.item}.${cell.slot}`);
|
|
1667
1810
|
let text = this.#values[c];
|
|
1668
1811
|
if (value === (text?.textContent ?? undefined))
|
|
1669
1812
|
continue;
|
|
1670
|
-
changed = true;
|
|
1671
1813
|
if (value === undefined) {
|
|
1672
1814
|
text?.remove();
|
|
1673
1815
|
this.#values[c] = undefined;
|
|
@@ -1679,7 +1821,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1679
1821
|
continue;
|
|
1680
1822
|
if (text === undefined) {
|
|
1681
1823
|
text = document.createElementNS(SVG, "text");
|
|
1682
|
-
text.setAttribute("
|
|
1824
|
+
text.setAttribute("class", "value");
|
|
1683
1825
|
text.setAttribute("lengthAdjust", "spacingAndGlyphs");
|
|
1684
1826
|
rect.after(text);
|
|
1685
1827
|
this.#values[c] = text;
|
|
@@ -1690,8 +1832,6 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1690
1832
|
text.setAttribute("textLength", String(width));
|
|
1691
1833
|
text.textContent = value;
|
|
1692
1834
|
}
|
|
1693
|
-
if (changed)
|
|
1694
|
-
this.#markBoxes();
|
|
1695
1835
|
}
|
|
1696
1836
|
/** Whoever listens hears of the demo's new state, which the learner chose (R42). */
|
|
1697
1837
|
#demoChanged() {
|
|
@@ -1718,9 +1858,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1718
1858
|
*/
|
|
1719
1859
|
#bringIntoSight(item) {
|
|
1720
1860
|
item.scrollIntoView({ block: "nearest", behavior: "instant" });
|
|
1721
|
-
// A scroller that comes to its top hands the rest on to the next, as Up does (R33)
|
|
1722
|
-
// the
|
|
1723
|
-
|
|
1861
|
+
// A scroller that comes to its top hands the rest on to the next, as Up does (R33). A scroller
|
|
1862
|
+
// goes again only while each of its scrolls leaves less covered than the last: a row that the
|
|
1863
|
+
// element's bottom pushed up from where it sticks comes back down as the page scrolls, over
|
|
1864
|
+
// what the scroll brought out, and the next brings it out again (T94).
|
|
1865
|
+
const covered = new Map();
|
|
1724
1866
|
for (;;) {
|
|
1725
1867
|
const latch = this.#scrollerFor(false);
|
|
1726
1868
|
// A row in its place, in a low window, covers nothing of it: the consumer's band may, over
|
|
@@ -1729,9 +1871,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1729
1871
|
? this.#tools.element.getBoundingClientRect().bottom
|
|
1730
1872
|
: this.#band(latch?.target);
|
|
1731
1873
|
const cover = over - item.getBoundingClientRect().top;
|
|
1732
|
-
if (cover <=
|
|
1874
|
+
if (cover <= EDGE || latch === undefined)
|
|
1733
1875
|
return;
|
|
1734
|
-
|
|
1876
|
+
const last = covered.get(latch.target);
|
|
1877
|
+
if (last !== undefined && cover >= last - EDGE)
|
|
1878
|
+
return;
|
|
1879
|
+
covered.set(latch.target, cover);
|
|
1735
1880
|
latch.target.scrollBy({ top: -cover / latch.scale, behavior: "instant" });
|
|
1736
1881
|
}
|
|
1737
1882
|
}
|
|
@@ -1753,10 +1898,51 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1753
1898
|
tool: this.#tool,
|
|
1754
1899
|
undoable: this.#work.undoable,
|
|
1755
1900
|
clearable: this.#work.strokes.length > 0,
|
|
1901
|
+
larger: PAGE_ZOOM.larger,
|
|
1902
|
+
smaller: PAGE_ZOOM.smaller,
|
|
1756
1903
|
finger: this.#finger,
|
|
1757
1904
|
opens: this.#nextPart() !== undefined,
|
|
1758
1905
|
expanded: demo?.hidden !== true,
|
|
1759
1906
|
});
|
|
1907
|
+
this.#nameRegion();
|
|
1908
|
+
}
|
|
1909
|
+
/**
|
|
1910
|
+
* The container as a region of its own, a stop of Tab and a name, while its content overflows
|
|
1911
|
+
* it, and the keyboard scrolls it: in Safari a container that nothing in it can take the focus in
|
|
1912
|
+
* scrolls by no key without (R90 spec; WebKit's bug 277290). Without a height of its own the
|
|
1913
|
+
* element scrolls with the page and has no stop of Tab, and neither has one whose task fits. A
|
|
1914
|
+
* container that holds the focus keeps all three till the focus leaves it, not the window (T93).
|
|
1915
|
+
* Across, it scrolls while the sheet is zoomed, and an element without a height has a region
|
|
1916
|
+
* then too, if its sheet is wider than it (T94); unzoomed, it hides what overflows across.
|
|
1917
|
+
*/
|
|
1918
|
+
#region() {
|
|
1919
|
+
if (!this.isConnected)
|
|
1920
|
+
return;
|
|
1921
|
+
const viewport = this.#viewport;
|
|
1922
|
+
const across = this.#zoom > 1 && overflowOf(viewport, "x") > EDGE;
|
|
1923
|
+
const focused = this.shadowRoot?.activeElement === viewport;
|
|
1924
|
+
const scrolls = overflowOf(viewport) > EDGE || across || focused;
|
|
1925
|
+
write(viewport, "tabindex", scrolls ? "0" : null);
|
|
1926
|
+
write(viewport, "role", scrolls ? "region" : null);
|
|
1927
|
+
this.#nameRegion();
|
|
1928
|
+
}
|
|
1929
|
+
/**
|
|
1930
|
+
* The region's name: the canvas kind's, or a worked example's, in the labels' language, which
|
|
1931
|
+
* the row's buttons are named in. For a `lang` the labels are not in, the container is in
|
|
1932
|
+
* theirs, English, and the column, all the container holds, in the element's: the name is said
|
|
1933
|
+
* in the language it is in, and the statement, the parts and the sheet as before (T106; R74).
|
|
1934
|
+
* With a `lang` the labels are in, the name is in the element's language already; without one,
|
|
1935
|
+
* the element's language is the page's, which no attribute of the column could name. Neither
|
|
1936
|
+
* then has a `lang` of its own.
|
|
1937
|
+
*/
|
|
1938
|
+
#nameRegion() {
|
|
1939
|
+
const tag = this.getAttribute("lang");
|
|
1940
|
+
const { lang, labels } = labelsFor(tag);
|
|
1941
|
+
const apart = tag !== null && !knows(tag);
|
|
1942
|
+
const named = this.#viewport.hasAttribute("role");
|
|
1943
|
+
write(this.#viewport, "aria-label", named ? labels[this.#rowKind()] : null);
|
|
1944
|
+
write(this.#viewport, "lang", apart ? lang : null);
|
|
1945
|
+
write(this.#column, "lang", apart ? tag : null);
|
|
1760
1946
|
}
|
|
1761
1947
|
/** What the row of buttons is of, and is named by: a worked example, or the canvas kind (R42). */
|
|
1762
1948
|
#rowKind() {
|
|
@@ -1778,10 +1964,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1778
1964
|
* showing a part of the sheet the others have left.
|
|
1779
1965
|
*/
|
|
1780
1966
|
#place(screen) {
|
|
1967
|
+
const width = screen.width / screen.k;
|
|
1781
1968
|
const height = screen.height / screen.k;
|
|
1782
1969
|
if (!(height > 0))
|
|
1783
1970
|
return;
|
|
1784
|
-
const viewBox =
|
|
1971
|
+
const viewBox = `${screen.vx} ${screen.vy} ${width} ${height}`;
|
|
1785
1972
|
if (viewBox === this.#viewBox)
|
|
1786
1973
|
return;
|
|
1787
1974
|
this.#viewBox = viewBox;
|
|
@@ -1895,14 +2082,15 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1895
2082
|
const { width, height } = this.#canvas;
|
|
1896
2083
|
if (context === null || width === 0 || height === 0)
|
|
1897
2084
|
return;
|
|
1898
|
-
// Device pixels to a unit, across and down
|
|
1899
|
-
//
|
|
1900
|
-
const across = width /
|
|
2085
|
+
// Device pixels to a unit, across and down: the ratio of the canvas's buffer to its rectangle,
|
|
2086
|
+
// which holds under any scale the page puts on the element, times `k`.
|
|
2087
|
+
const across = (width / screen.width) * screen.k;
|
|
1901
2088
|
const down = (height / screen.height) * screen.k;
|
|
1902
2089
|
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
1903
2090
|
context.clearRect(0, 0, width, height);
|
|
1904
|
-
context.setTransform(across, 0, 0, down,
|
|
2091
|
+
context.setTransform(across, 0, 0, down, -screen.vx * across, -screen.vy * down);
|
|
1905
2092
|
context.fillStyle = colour;
|
|
2093
|
+
const right = screen.vx + screen.width / screen.k;
|
|
1906
2094
|
const bottom = screen.vy + screen.height / screen.k;
|
|
1907
2095
|
const erasing = this.#eraser.pending;
|
|
1908
2096
|
for (const stroke of this.#work.strokes) {
|
|
@@ -1912,6 +2100,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1912
2100
|
const box = this.#pointBoxOf(stroke);
|
|
1913
2101
|
if (box.maxY + 2 * INK_REACH < screen.vy || box.minY - 2 * INK_REACH > bottom)
|
|
1914
2102
|
continue;
|
|
2103
|
+
if (box.maxX + 2 * INK_REACH < screen.vx || box.minX - 2 * INK_REACH > right)
|
|
2104
|
+
continue;
|
|
1915
2105
|
const ink = this.#finished(stroke);
|
|
1916
2106
|
if (ink.bottom >= screen.vy && ink.top <= bottom)
|
|
1917
2107
|
context.fill(ink.path);
|
|
@@ -2007,7 +2197,17 @@ function contactOf(event) {
|
|
|
2007
2197
|
time: event.timeStamp,
|
|
2008
2198
|
};
|
|
2009
2199
|
}
|
|
2010
|
-
/** The
|
|
2200
|
+
/** The scroll an event's fingers owe a scroller, in whole pixels, if any: the rest waits (R29). */
|
|
2201
|
+
function owed(latch) {
|
|
2202
|
+
if (!latch)
|
|
2203
|
+
return undefined;
|
|
2204
|
+
const step = Math.round(latch.rest);
|
|
2205
|
+
if (step === 0)
|
|
2206
|
+
return undefined;
|
|
2207
|
+
latch.rest -= step;
|
|
2208
|
+
return { target: latch.target, step };
|
|
2209
|
+
}
|
|
2210
|
+
/** The values of `overflow-y`, or of `overflow-x`, that make an element scroll its content. */
|
|
2011
2211
|
const SCROLLING = /^(auto|scroll|overlay)$/;
|
|
2012
2212
|
/**
|
|
2013
2213
|
* The values of `overflow-y` that make an element a scroll container, which a sticky box sticks in:
|
|
@@ -2018,9 +2218,10 @@ const CONTAINING = /^(auto|scroll|overlay|hidden)$/;
|
|
|
2018
2218
|
* The overflow of the page's viewport: the root's, or the body's when the root's is visible (CSS
|
|
2019
2219
|
* Overflow 3), and then the body scrolls nothing of its own.
|
|
2020
2220
|
*/
|
|
2021
|
-
function pageOverflow() {
|
|
2022
|
-
const
|
|
2023
|
-
const
|
|
2221
|
+
function pageOverflow(axis = "y") {
|
|
2222
|
+
const along = (style) => (axis === "y" ? style.overflowY : style.overflowX);
|
|
2223
|
+
const root = along(getComputedStyle(document.documentElement));
|
|
2224
|
+
const body = document.body === null ? "visible" : along(getComputedStyle(document.body));
|
|
2024
2225
|
const fromBody = root === "visible" && body !== "visible";
|
|
2025
2226
|
return { overflow: fromBody ? body : root, fromBody };
|
|
2026
2227
|
}
|
|
@@ -2070,10 +2271,68 @@ function offsetOf(element, height) {
|
|
|
2070
2271
|
return 0;
|
|
2071
2272
|
return top.endsWith("%") ? (value / 100) * height : value;
|
|
2072
2273
|
}
|
|
2073
|
-
/**
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2274
|
+
/** How far a scroll short of its end, or past it, still counts as at it: half a CSS pixel. */
|
|
2275
|
+
const EDGE = 0.5;
|
|
2276
|
+
/**
|
|
2277
|
+
* How far an element's content overflows it down, or across along `x`, in CSS pixels: where its
|
|
2278
|
+
* scroll ends.
|
|
2279
|
+
*/
|
|
2280
|
+
function overflowOf(element, axis = "y") {
|
|
2281
|
+
return axis === "y"
|
|
2282
|
+
? element.scrollHeight - element.clientHeight
|
|
2283
|
+
: element.scrollWidth - element.clientWidth;
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* How far an element is scrolled from the top of its content, or from its left along `x`: in a
|
|
2287
|
+
* scroller that runs right to left, `scrollLeft` goes from 0 at the right down to minus its
|
|
2288
|
+
* overflow at the left (CSSOM View).
|
|
2289
|
+
*/
|
|
2290
|
+
function scrolledOf(element, axis) {
|
|
2291
|
+
if (axis === "y")
|
|
2292
|
+
return element.scrollTop;
|
|
2293
|
+
// Only one that overflows across reads its direction: it is asked at every scroll.
|
|
2294
|
+
const over = overflowOf(element, "x");
|
|
2295
|
+
if (over <= EDGE)
|
|
2296
|
+
return 0;
|
|
2297
|
+
return getComputedStyle(element).direction === "rtl"
|
|
2298
|
+
? over + element.scrollLeft
|
|
2299
|
+
: element.scrollLeft;
|
|
2300
|
+
}
|
|
2301
|
+
/**
|
|
2302
|
+
* Whether an element can scroll on down its content, for `onward`, or back up it — or, along `x`,
|
|
2303
|
+
* on right across it or back left.
|
|
2304
|
+
*/
|
|
2305
|
+
function scrollsOn(element, onward, axis = "y") {
|
|
2306
|
+
const at = scrolledOf(element, axis);
|
|
2307
|
+
return onward ? at < overflowOf(element, axis) - EDGE : at > EDGE;
|
|
2308
|
+
}
|
|
2309
|
+
/**
|
|
2310
|
+
* Where what a scroller shows is in sight down the screen, or across it along `x` (T94): within
|
|
2311
|
+
* the ancestors that clip it and the visual viewport, from `start` to `end` — and how much it
|
|
2312
|
+
* shows whole, for a scroller out of sight.
|
|
2313
|
+
*/
|
|
2314
|
+
function sightOf(target, axis) {
|
|
2315
|
+
const down = axis === "y";
|
|
2316
|
+
const sight = window.visualViewport;
|
|
2317
|
+
let start = (down ? sight?.offsetTop : sight?.offsetLeft) ?? 0;
|
|
2318
|
+
let end = start + ((down ? sight?.height : sight?.width) ?? (down ? innerHeight : innerWidth));
|
|
2319
|
+
let whole = end - start;
|
|
2320
|
+
if (target instanceof Element) {
|
|
2321
|
+
const own = clientBoxOf(target);
|
|
2322
|
+
whole = down ? own.bottom - own.top : own.right - own.left;
|
|
2323
|
+
// The scroller, and every ancestor that clips it, up to the page, whose part is the sight.
|
|
2324
|
+
for (let node = target; node !== null; node = parentOf(node)) {
|
|
2325
|
+
if (node === document.documentElement)
|
|
2326
|
+
break;
|
|
2327
|
+
const style = node === target ? undefined : getComputedStyle(node);
|
|
2328
|
+
if (style !== undefined && (down ? style.overflowY : style.overflowX) === "visible")
|
|
2329
|
+
continue;
|
|
2330
|
+
const clip = node === target ? own : clientBoxOf(node);
|
|
2331
|
+
start = Math.max(start, down ? clip.top : clip.left);
|
|
2332
|
+
end = Math.min(end, down ? clip.bottom : clip.right);
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
return { start, end, whole };
|
|
2077
2336
|
}
|
|
2078
2337
|
/** Whether an element holds another in the flat tree, across the borders of shadow trees. */
|
|
2079
2338
|
function holds(ancestor, element) {
|
|
@@ -2099,22 +2358,24 @@ function parentOf(element) {
|
|
|
2099
2358
|
*/
|
|
2100
2359
|
function clientBoxOf(element) {
|
|
2101
2360
|
const box = element.getBoundingClientRect();
|
|
2102
|
-
const
|
|
2103
|
-
const across = wide > 0 ? box.width / wide : 1;
|
|
2361
|
+
const across = scaleOf(element, box, "x");
|
|
2104
2362
|
const down = scaleOf(element, box);
|
|
2105
2363
|
const left = box.left + element.clientLeft * across;
|
|
2106
2364
|
const top = box.top + element.clientTop * down;
|
|
2107
2365
|
const right = left + element.clientWidth * across;
|
|
2108
2366
|
const bottom = top + element.clientHeight * down;
|
|
2109
|
-
return { left, top, right, bottom, down };
|
|
2367
|
+
return { left, top, right, bottom, across, down };
|
|
2110
2368
|
}
|
|
2111
2369
|
/**
|
|
2112
|
-
* How much the page scales an element down the screen
|
|
2113
|
-
* its rectangle on the screen, when the caller has it already.
|
|
2370
|
+
* How much the page scales an element down the screen, or across it along `x` (T94): 1 unless an
|
|
2371
|
+
* ancestor transforms it. `box` is its rectangle on the screen, when the caller has it already.
|
|
2114
2372
|
*/
|
|
2115
|
-
function scaleOf(element, box) {
|
|
2116
|
-
const
|
|
2117
|
-
|
|
2373
|
+
function scaleOf(element, box, axis = "y") {
|
|
2374
|
+
const laid = element instanceof HTMLElement ? element[axis === "y" ? "offsetHeight" : "offsetWidth"] : 0;
|
|
2375
|
+
if (laid <= 0)
|
|
2376
|
+
return 1;
|
|
2377
|
+
const shown = box ?? element.getBoundingClientRect();
|
|
2378
|
+
return (axis === "y" ? shown.height : shown.width) / laid;
|
|
2118
2379
|
}
|
|
2119
2380
|
/**
|
|
2120
2381
|
* A path around an outline: a closed curve through the midpoints of its edges, each point of the
|