@altnovatrail/canvas 0.3.25 → 0.3.26

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.
@@ -8,13 +8,14 @@
8
8
  // marks of a submission hold on to the learner's strokes, and a frame shows where each is, over
9
9
  // the work (T14; R26). The history of writing comes in and goes out, an event tells of every
10
10
  // action, and the work for checking is the crop with the context of its submission (T15; R27).
11
- // Above it all stands the element's own row of buttons — the tools the task allows, undo and
12
- // clearing — labelled in the element's `lang` (T41; R28). On a tablet a pen's touch puts the page
11
+ // Over it all stand the element's own buttons — the tools the task allows, undo and clearing —
12
+ // labelled in the element's `lang` (T41; R28), on a vertical bar of glass at its left edge (T121;
13
+ // R84). On a tablet a pen's touch puts the page
13
14
  // in pen mode, where a finger writes nothing and a button lets it write again, a palm writes
14
15
  // nothing, and two fingers scroll (T35; R29). The task comes in the names of the module format
15
16
  // 0.4, checked as its schema checks it, and the module's manifest gives the height of a digit and
16
- // the statement's language (T44; R32). Up and Down in the row scroll what two fingers would, with
17
- // a single pointer (T45; R33). The workbook's lines, laid out on its page, stand on the template in
17
+ // the statement's language (T44; R32). In pen mode one finger drags the sheet too (T121; R84). The
18
+ // workbook's lines, laid out on its page, stand on the template in
18
19
  // place of the grid — numbers, text and boxes, which a screen reader reads in the task's order (T51;
19
20
  // R35, R36). Each stroke is in one box or in none, by a rule of whole numbers, and `filled` tells
20
21
  // which boxes hold one: a filled box's frame is thicker, and its name says so (T48; R37). A
@@ -36,7 +37,7 @@
36
37
  // a ring when the keyboard brings the focus there (T93; R33); for a `lang` the labels are not in,
37
38
  // the container is in theirs and the column in the element's (T106; R74). The row's Zoom in and Zoom out step
38
39
  // 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).
40
+ // as down, with two fingers, the wheel and the keys (T94).
40
41
  import { cellOf, cellsOf, filledOf, sheetFilledOf } from "../core/boxes.js";
41
42
  import { Clock } from "../core/clock.js";
42
43
  import { ERASER_BUTTON, Eraser } from "../core/eraser.js";
@@ -71,6 +72,12 @@ export const TAG = "novatrail-canvas";
71
72
  const INK = "#111";
72
73
  /** The colour of the sheet unless the consumer's theme gives one. */
73
74
  const PAPER = "#fff";
75
+ /**
76
+ * The colour of the tool in use and of the focus on the bar unless the consumer's theme gives one,
77
+ * and the bar's glass: the interface mockup's (R84; R148 spec).
78
+ */
79
+ const ACCENT = "#0071E3";
80
+ const GLASS = "rgba(255, 255, 255, 0.76)";
74
81
  /** The event the element sends after every action on the sheet, with the history's new events. */
75
82
  const HISTORY_CHANGE = "historychange";
76
83
  /** The event the element sends when the learner chooses another tool with its buttons. */
@@ -93,40 +100,38 @@ const MARK_CORNER = 6;
93
100
  * the sheet's scale (R22). T22 tries it on devices.
94
101
  */
95
102
  const ERASER_RADIUS_PX = 10;
96
- /**
97
- * How much of what it shows a press of Up or Down scrolls (R33): four fifths, as WebKit pages on
98
- * an iPad, so that the last lines stay in sight. T22 tries it on devices.
99
- */
100
- const UP_DOWN = 4 / 5;
101
103
  // The statement and the sheet stand in a column of their own, as wide as the element up to
102
104
  // 1000 CSS pixels and in its middle beyond, and scroll in a container of their own, by the
103
105
  // browser's own scrolling: the wheel, the scroll bar and the keyboard work as anywhere on a page.
104
106
  // The page's zoom widens the column with the sheet, to twice its fit, and the container scrolls
105
107
  // it across too, left to right whatever the page's direction, while the statement and a demo's
106
108
  // parts stay as wide as the fit and stick to its left, in the element's own direction: they wrap
107
- // as before, and scroll down alone (T94). Left and Right stand in that order in a row that runs
108
- // 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
109
- // container's top and left, and each shows what lies there, shifted in the frame the ink is drawn
110
- // in (R18, R23; architecture 3.2 in docs/architecture.md).
111
- // Above the column, as wide, stands the row of the element's own buttons, outside the container's
112
- // scrolling: it sticks to the top of whatever scrolls the element, as far down as the consumer's
113
- // --novatrail-canvas-top says, while the element is in sight, over the sheet as it scrolls by
114
- // (R28). In a low window, where the row would cover more than a quarter of what it sticks in, it
115
- // stands in its place instead, `loose`, and goes with the scrolling (1.4.10, 2.4.11). A button in
116
- // focus shows a ring in the ink's colour, two pixels out, that the row's side margins keep on its
117
- // paper; an unavailable one is paler by its colour, not its opacity, which would pale the ring too
118
- // (2.4.7, 1.4.11). Nothing in the element moves but the scrolling, which jumps (2.3.3). The
119
- // element is as tall as the row, the statement and the sheet unless it is given a height: then
120
- // the statement and the sheet scroll in it, under the row. A worked example's open
121
- // parts stand between the statement and the sheet, and the region that tells of them is out of
122
- // sight, but not out of the tree a screen reader reads, where a hidden region would tell nothing
123
- // (R42). A picture's frame there stands in its item's line, from its top, so that the item's
124
- // number stands at the top too, as a paragraph's does, and not at the picture's bottom (T64). A
125
- // picture on an area of the sheet stands on the layer of the author's demo, and the sheet scrolls
126
- // to a hidden box of the area in its own flow, which neither paints nor takes a pointer (T61). On
127
- // the canvas the browser neither scrolls nor zooms: the pointer writes, and two fingers scroll by
128
- // the element's own code (R29), as Up and Down of the row do with a single pointer, a pair the
129
- // row wraps together (R33).
109
+ // as before, and scroll down alone (T94). The layers of the sheet stand in its visible part, the
110
+ // stage, which sticks to the container's top and left, and each shows what lies there, shifted in
111
+ // the frame the ink is drawn in (R18, R23; architecture 3.2 in docs/architecture.md).
112
+ // Over the container, in the same cell of the frame's grid, stands the rail of the element's own
113
+ // buttons: a band as tall as the part of the element in sight and as wide as nothing, sticking to
114
+ // the top of whatever scrolls the element, as far down as the consumer's --novatrail-canvas-top
115
+ // says, and in its middle, 16 pixels from the left edge, the bar of buttons: 52 pixels wide, round
116
+ // at its ends, of the mockup's glass — the fill the consumer's theme gives, blurred behind, or the
117
+ // paper alone where nothing blurs — over the sheet as it scrolls by (R84; R148 spec). A bar taller
118
+ // than the band scrolls inside its glass (1.4.10). A worked example's bar holds the zoom's pair
119
+ // alone, and its Next and Demo stand in a row of the same glass at the band's bottom, the
120
+ // consumer's buttons of the slot actions after them (R84). The tool in use is filled with the
121
+ // accent at an eighth, its icon in the accent; a button in focus shows a ring in the accent; an
122
+ // unavailable one is paler by its colour, not its opacity, which would pale the ring too (2.4.7,
123
+ // 1.4.11). A button's tooltip stands beside it, white on near-black, as the mockup has it. Nothing
124
+ // in the element moves but the scrolling, which jumps, and no tooltip fades (2.3.3). The element is
125
+ // as tall as the statement and the sheet unless it is given a height: then the statement and the
126
+ // sheet scroll in it, under the bar. A worked example's open parts stand between the statement and
127
+ // the sheet, and the region that tells of them is out of sight, but not out of the tree a screen
128
+ // reader reads, where a hidden region would tell nothing (R42). A picture's frame there stands in
129
+ // its item's line, from its top, so that the item's number stands at the top too, as a paragraph's
130
+ // does, and not at the picture's bottom (T64). A picture on an area of the sheet stands on the
131
+ // layer of the author's demo, and the sheet scrolls to a hidden box of the area in its own flow,
132
+ // which neither paints nor takes a pointer (T61). On the canvas the browser neither scrolls nor
133
+ // zooms: the pointer writes, and two fingers scroll by the element's own code (R29), and in pen
134
+ // mode one finger too (R84).
130
135
  // The canvas and the buttons take pointer events only as the element does: a consumer's
131
136
  // pointer-events: none on the element stops the writing and the buttons' pointer, though not
132
137
  // their keys (R20, R28). A worked example's canvas takes no pointer at all: a finger or a pen on
@@ -143,28 +148,67 @@ const UP_DOWN = 4 / 5;
143
148
  const STYLE = `
144
149
  :host { display: flex; flex-direction: column; isolation: isolate; writing-mode: horizontal-tb; }
145
150
  :host([hidden]) { display: none; }
151
+ .frame {
152
+ position: relative; flex: 1 1 auto; min-height: 0; display: grid;
153
+ grid-template: minmax(0, 1fr) / minmax(0, 1fr);
154
+ }
155
+ .viewport {
156
+ grid-area: 1 / 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overflow-anchor: none;
157
+ outline: none; -webkit-tap-highlight-color: transparent;
158
+ }
159
+ .rail {
160
+ grid-area: 1 / 1; align-self: start; justify-self: left; width: 0; direction: ltr;
161
+ position: sticky; top: var(--rail-top, var(--novatrail-canvas-top, 0px)); z-index: 1;
162
+ box-sizing: border-box; padding: 16px 0;
163
+ height: min(100%, var(--rail-room, 100dvh) - var(--rail-top, var(--novatrail-canvas-top, 0px)));
164
+ display: flex; align-items: center;
165
+ }
166
+ .rail[hidden] { display: none; }
167
+ .rail.example { padding-bottom: 88px; }
146
168
  .tools {
147
- position: sticky; top: var(--novatrail-canvas-top, 0px); z-index: 1; flex: none;
148
- box-sizing: border-box; width: min(100%, ${K_MAX * SHEET.width}px); margin: 0 auto;
149
- padding: 8px 4px; display: flex; flex-wrap: wrap; gap: 8px;
150
- background: var(--novatrail-canvas-paper, ${PAPER}); color: var(--novatrail-canvas-ink, ${INK});
169
+ box-sizing: border-box; flex: none; width: 52px; max-height: 100%;
170
+ margin: 0 0 0 16px; padding: 4px; border-radius: 26px;
171
+ display: flex; flex-direction: column; align-items: center; gap: 2px;
172
+ overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
173
+ font-size: 14px; line-height: 1.2; color: var(--novatrail-canvas-ink, ${INK});
174
+ background: var(--novatrail-canvas-glass, ${GLASS});
175
+ -webkit-backdrop-filter: blur(22px) saturate(180%); backdrop-filter: blur(22px) saturate(180%);
176
+ box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.08), 0 8px 28px rgba(0, 0, 0, 0.08),
177
+ 0 1px 2px rgba(0, 0, 0, 0.04);
178
+ }
179
+ @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
180
+ .tools { background: var(--novatrail-canvas-paper, ${PAPER}); }
151
181
  }
152
- .tools.loose { position: static; }
153
- .tools .demo, .tools .choice, .tools .updown, .tools .zoom, .tools .across {
154
- display: flex; gap: 8px; margin-inline-end: 16px;
182
+ .tools:dir(rtl) { direction: rtl; }
183
+ .tools.row {
184
+ position: absolute; bottom: 16px; left: calc(var(--rail-width, 100vw) / 2);
185
+ transform: translateX(-50%); width: max-content; max-width: calc(var(--rail-width, 100vw) - 32px);
186
+ max-height: none; margin: 0; padding: 6px; border-radius: 28px; flex-direction: row; gap: 4px;
187
+ overflow-x: auto; overflow-y: hidden;
155
188
  }
156
- .tools:dir(rtl) .across { flex-direction: row-reverse; }
189
+ .tools .choice, .tools .zoom { display: flex; flex-direction: column; gap: 2px; flex: none; }
190
+ .tools .line {
191
+ flex: none; width: 24px; height: 1px; margin: 4px 0; background: rgba(0, 0, 0, 0.1);
192
+ }
193
+ .tools.row .line { width: 1px; height: 24px; margin: 0 4px; }
194
+ .tools.row ::slotted(*) { flex: none; }
157
195
  .tools button {
158
- box-sizing: border-box; min-width: 44px; min-height: 44px; padding: 0 8px; margin: 0;
159
- font: inherit; color: inherit; background: transparent; cursor: pointer;
160
- border: 1px solid currentColor; border-radius: 6px;
196
+ box-sizing: border-box; flex: none; min-width: 44px; min-height: 44px; margin: 0;
197
+ padding: 0 14px 0 10px; display: flex; align-items: center; justify-content: center; gap: 6px;
198
+ font: inherit; font-weight: 500; white-space: nowrap; color: inherit; background: transparent;
199
+ cursor: pointer; border: none; border-radius: 22px;
200
+ }
201
+ .tools button.icon { width: 44px; height: 44px; padding: 0; }
202
+ .tools button.icon .label {
203
+ position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
204
+ overflow: hidden; clip-path: inset(50%); white-space: nowrap;
161
205
  }
162
206
  .tools [aria-checked="true"] {
163
- background: var(--novatrail-canvas-ink, ${INK}); color: var(--novatrail-canvas-paper, ${PAPER});
164
- border-color: var(--novatrail-canvas-ink, ${INK});
207
+ background: color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 12%, transparent);
208
+ color: var(--novatrail-canvas-accent, ${ACCENT});
165
209
  }
166
210
  .tools button:focus-visible {
167
- outline: 2px solid var(--novatrail-canvas-ink, ${INK}); outline-offset: 2px;
211
+ outline: 2px solid var(--novatrail-canvas-accent, ${ACCENT}); outline-offset: 0;
168
212
  }
169
213
  .tools [aria-disabled="true"] {
170
214
  color: color-mix(
@@ -174,20 +218,18 @@ const STYLE = `
174
218
  }
175
219
  @supports not (color: color-mix(in srgb, red 40%, blue)) {
176
220
  .tools [aria-disabled="true"] { opacity: 0.4; }
221
+ .tools [aria-checked="true"] { background: transparent; }
177
222
  }
178
- .tools [hidden] { display: none; }
179
- .tools button svg {
180
- display: inline-block; width: 1.125em; height: 1.125em; margin-inline-end: 4px;
181
- vertical-align: -0.25em; fill: currentColor;
182
- }
223
+ .tools[hidden], .tools [hidden] { display: none; }
224
+ .tools button svg { display: block; flex: none; width: 20px; height: 20px; fill: currentColor; }
183
225
  .tools:dir(rtl) svg.mirrored { transform: scaleX(-1); }
184
- .frame {
185
- position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
186
- }
187
- .viewport {
188
- flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; overflow-anchor: none;
189
- outline: none; -webkit-tap-highlight-color: transparent;
226
+ .tip {
227
+ position: absolute; left: var(--tip-x, 76px); top: var(--tip-y, 0px); z-index: 2;
228
+ transform: translateY(-50%); white-space: nowrap;
229
+ font-size: 12.5px; font-weight: 500; line-height: 1; padding: 8px 10px; border-radius: 9px;
230
+ background: #1d1d1f; color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
190
231
  }
232
+ .tip[hidden] { display: none; }
191
233
  .viewport.zoomed { overflow-x: auto; direction: ltr; }
192
234
  .ring { position: absolute; inset: 0; z-index: 0; pointer-events: none; display: none; }
193
235
  .viewport:focus-visible + .ring {
@@ -264,12 +306,16 @@ canvas {
264
306
  .print rect.filled { stroke: Highlight; }
265
307
  canvas { color: CanvasText; }
266
308
  .marks rect { stroke: Highlight; }
267
- .tools { background: Canvas; color: CanvasText; }
268
- .tools button { background: ButtonFace; color: ButtonText; border-color: ButtonBorder; }
309
+ .tools { background: Canvas; color: CanvasText; border: 1px solid CanvasText; }
310
+ .tools .line { background: CanvasText; }
311
+ .tools button {
312
+ background: ButtonFace; color: ButtonText; border: 1px solid ButtonBorder;
313
+ }
269
314
  .tools [aria-checked="true"] {
270
315
  background: Highlight; color: HighlightText; border-color: Highlight;
271
316
  }
272
317
  .tools [aria-disabled="true"] { color: GrayText; border-color: GrayText; }
318
+ .tip { background: Canvas; color: CanvasText; border: 1px solid CanvasText; }
273
319
  .tools button:focus-visible, .viewport:focus-visible + .ring { outline-color: Highlight; }
274
320
  }
275
321
  `;
@@ -362,14 +408,12 @@ export class NovatrailCanvas extends HTMLElement {
362
408
  #statement = new Statement(this.#pictures);
363
409
  /** A worked example's open parts, under its statement, and the region that tells of them (R42). */
364
410
  #parts = new Parts(DEMO_IDS, this.#pictures);
365
- /** The element's own buttons, above the statement and the sheet (R28). */
411
+ /** The element's own buttons, on a bar over the sheet's left edge (R28, R84). */
366
412
  #tools = new Tools({
367
413
  choose: (tool) => this.#choose(tool),
368
414
  undo: () => this.undo(),
369
415
  clear: () => this.clear(),
370
- upOrDown: (onward) => this.#step(onward, "y"),
371
416
  zoom: (larger) => this.#zoomBy(larger),
372
- leftOrRight: (onward) => this.#step(onward, "x"),
373
417
  // The finger writes again on every sheet of the page, with no event: the next pen's touch
374
418
  // puts the page back in pen mode (R29).
375
419
  fingers: () => {
@@ -416,34 +460,15 @@ export class NovatrailCanvas extends HTMLElement {
416
460
  */
417
461
  #latch;
418
462
  #latchAcross;
419
- /**
420
- * A scroll of the page, or of an ancestor of the element in the page's own tree, heard on its way
421
- * down: Up or Down may have come to an end, or left one (R33). Other scrollers are none of theirs.
422
- */
423
- #heard = (event) => {
424
- const target = event.target;
425
- if (target === document || (target instanceof Element && holds(target, this))) {
426
- // A new --novatrail-canvas-top changes no size: the next scroll is the first to hear of it,
427
- // by one read of the row's style, and only a new offset asks anew whether the row sticks.
428
- if (getComputedStyle(this.#tools.element).top !== this.#topSeen)
429
- this.#stick();
430
- this.#edges();
431
- }
432
- };
433
- /**
434
- * The page grown or shrunk, or the window, the scroller the row sticks in or the row itself: what
435
- * scrolls the element may have room now, or none, and the row may cover too much of it to stick.
436
- */
463
+ /** The page grown or shrunk, or the window: what scrolls the element may have room now, or none. */
437
464
  #resized = () => {
438
- this.#stick();
439
465
  this.#region();
440
- this.#edges();
466
+ this.#fit();
441
467
  };
442
468
  #page = new ResizeObserver(this.#resized);
443
- /** The scroll container the row sticks in, which `#page` watches, or null for the page's viewport. */
469
+ /** What the bar's rail sticks in, when a scroller of the page's: its height is the rail's room. */
444
470
  #port = null;
445
- /** The row's `top` as the last check of whether it sticks read it: the consumer's offset. */
446
- #topSeen = "";
471
+ #ported = new ResizeObserver(() => this.#fit());
447
472
  #unwatchPen;
448
473
  #unwatchZoom;
449
474
  /** The page's zoom as the sheet is laid out by it (T94). */
@@ -506,8 +531,9 @@ export class NovatrailCanvas extends HTMLElement {
506
531
  this.#area = { width: box.inlineSize, height: box.blockSize };
507
532
  }
508
533
  // The container's new size, the statement's or that of the list of a demo's parts: each moves
509
- // the sheet.
534
+ // the sheet, and the first is the room of a worked example's row.
510
535
  this.#layout();
536
+ this.#fit();
511
537
  });
512
538
  /** The size of the container's visible part, in CSS pixels as laid out, before any transform. */
513
539
  #area;
@@ -550,8 +576,9 @@ export class NovatrailCanvas extends HTMLElement {
550
576
  this.#sheet.append(this.#stage, this.#parts.spot);
551
577
  this.#column.append(this.#statement.element, this.#parts.list, this.#parts.status, this.#sheet);
552
578
  this.#viewport.append(this.#column);
553
- this.#wrapper.append(this.#viewport, this.#ring);
554
- root.append(this.#tools.element, this.#wrapper);
579
+ // The bar comes first, as the row of buttons before it did: Tab reaches it before the sheet.
580
+ this.#wrapper.append(this.#tools.rail, this.#viewport, this.#ring);
581
+ root.append(this.#wrapper);
555
582
  this.#zoomTo(PAGE_ZOOM.value);
556
583
  this.#lay(NO_TASK);
557
584
  this.#refresh();
@@ -602,7 +629,7 @@ export class NovatrailCanvas extends HTMLElement {
602
629
  this.#adopt("marks");
603
630
  }
604
631
  /** The element follows its own `lang`: its buttons are labelled in it (R07, R28). */
605
- static observedAttributes = ["lang"];
632
+ static observedAttributes = ["lang", "tools-hidden"];
606
633
  /**
607
634
  * What a press of the primary button does: "pen" writes, as the element starts, and "eraser"
608
635
  * erases (R22). The learner switches it with the element's own buttons, which say a choice of
@@ -915,23 +942,26 @@ export class NovatrailCanvas extends HTMLElement {
915
942
  // The page's zoom, on every sheet of it (T94): it may have changed while the element was away.
916
943
  this.#zoomTo(PAGE_ZOOM.value);
917
944
  this.#unwatchZoom = PAGE_ZOOM.watch(() => this.#zoomed());
918
- // A scroll does not bubble, but the document hears every one of its tree on the way down. A
919
- // page that grows or shrinks scrolls nothing, and neither does a window of another size.
920
- document.addEventListener("scroll", this.#heard, { capture: true, passive: true });
945
+ // A page that grows or shrinks scrolls nothing, and neither does a window of another size.
921
946
  this.#page.observe(document.documentElement);
922
- // The row wraps anew with the element's width, its language, the canvas kind and the finger's
923
- // button, and grows or shrinks.
924
- this.#page.observe(this.#tools.element);
925
947
  window.addEventListener("resize", this.#resized);
926
948
  this.#refresh();
949
+ this.#fit();
927
950
  }
928
951
  /**
929
952
  * The element's `lang` came, changed or went: its buttons and a workbook's boxes are labelled in
930
- * it, or in English for a language their labels are not in, and for none (R28, R36). An attribute
931
- * the element had before it was defined comes here just after the constructor, which reads no
932
- * attribute.
933
- */
934
- attributeChangedCallback() {
953
+ * it, or in English for a language their labels are not in, and for none (R28, R36). Or
954
+ * `tools-hidden` did: while the element has it, the bar is out of sight and of the accessibility
955
+ * tree, as `app` hides it on a phone under its tutor's sheet (R84; В83 in run/QUESTIONS.md). An
956
+ * attribute the element had before it was defined comes here just after the constructor, which
957
+ * reads no attribute.
958
+ */
959
+ attributeChangedCallback(name) {
960
+ if (name === "tools-hidden") {
961
+ this.#tools.rail.hidden = this.hasAttribute("tools-hidden");
962
+ this.#fit();
963
+ return;
964
+ }
935
965
  this.#tools.label(this.getAttribute("lang"));
936
966
  this.#nameRegion();
937
967
  this.#nameBoxes();
@@ -1056,9 +1086,10 @@ export class NovatrailCanvas extends HTMLElement {
1056
1086
  this.#unwatchPen = undefined;
1057
1087
  this.#unwatchZoom?.();
1058
1088
  this.#unwatchZoom = undefined;
1059
- document.removeEventListener("scroll", this.#heard, { capture: true });
1060
1089
  this.#page.disconnect();
1090
+ this.#ported.disconnect();
1061
1091
  this.#port = null;
1092
+ this.#tools.disconnect();
1062
1093
  window.removeEventListener("resize", this.#resized);
1063
1094
  // A stroke that ended here may be the one the other rows of the page waited for.
1064
1095
  PEN_MODE.settle();
@@ -1412,9 +1443,8 @@ export class NovatrailCanvas extends HTMLElement {
1412
1443
  * the canvas's top left corner is that of the visible part, and the sheet's width gives `k`, the
1413
1444
  * one on the screen, after whatever transform the page puts on the element. The container's
1414
1445
  * rectangle gives the part of the canvas it shows: with the statement in sight, the canvas
1415
- * goes on below the container's bottom. The row of buttons above the container hides what it
1416
- * covers, once it sticks over the sheet as the page scrolls the element by (R28); in its place,
1417
- * in a low window, it stands above the container and hides nothing of it.
1446
+ * goes on below the container's bottom. The bar of buttons over the sheet takes what is under it
1447
+ * itself: a pointer there presses a button, and writes nothing (R84).
1418
1448
  */
1419
1449
  #view() {
1420
1450
  const canvas = this.#canvas.getBoundingClientRect();
@@ -1425,11 +1455,9 @@ export class NovatrailCanvas extends HTMLElement {
1425
1455
  const vx = (canvas.left - sheet.left) / k;
1426
1456
  const vy = (canvas.top - sheet.top) / k;
1427
1457
  const port = clientBoxOf(this.#viewport);
1428
- // The row ends where the container begins, unless it sticks over it.
1429
- const row = this.#tools.element.getBoundingClientRect();
1430
1458
  const shown = {
1431
1459
  left: Math.max(canvas.left, port.left),
1432
- top: Math.max(canvas.top, port.top, row.bottom),
1460
+ top: Math.max(canvas.top, port.top),
1433
1461
  right: Math.min(canvas.right, port.right),
1434
1462
  bottom: Math.min(canvas.bottom, port.bottom),
1435
1463
  };
@@ -1451,8 +1479,7 @@ export class NovatrailCanvas extends HTMLElement {
1451
1479
  /**
1452
1480
  * The top and the left of the visible part from the scroll and the last layout, without reading
1453
1481
  * the layout again: the stage sticks to the container's top once the sheet's top has gone past
1454
- * it, and to its left so. Up or Down, Left or Right may have come to an end of the container, or
1455
- * left one.
1482
+ * it, and to its left so.
1456
1483
  */
1457
1484
  #scrolled() {
1458
1485
  if (this.#k > 0) {
@@ -1460,23 +1487,6 @@ export class NovatrailCanvas extends HTMLElement {
1460
1487
  this.#vx = Math.max(0, this.#viewport.scrollLeft - this.#sheetAtX) / this.#k;
1461
1488
  }
1462
1489
  this.#request();
1463
- this.#edges();
1464
- }
1465
- /**
1466
- * Up or Down was pressed (R33), or along `x` Left or Right (T94): what two fingers would scroll
1467
- * that way goes by four fifths of what it shows in sight. It is chosen anew at every press, so
1468
- * that a container at its end hands the scroll on at the next. While a pointer writes or erases
1469
- * on a sheet of the page, nothing moves under it.
1470
- */
1471
- #step(onward, axis) {
1472
- const latch = PEN_MODE.writing ? undefined : this.#scrollerFor(onward, axis);
1473
- if (latch !== undefined) {
1474
- const seen = this.#seen(latch.target, axis);
1475
- const step = Math.max(1, Math.round((UP_DOWN * seen) / latch.scale));
1476
- const by = onward ? step : -step;
1477
- latch.target.scrollBy({ [axis === "y" ? "top" : "left"]: by, behavior: "instant" });
1478
- }
1479
- this.#edges();
1480
1490
  }
1481
1491
  /**
1482
1492
  * Zoom in or Zoom out was pressed (T94): the page's zoom goes a step larger or smaller, and every
@@ -1525,85 +1535,49 @@ export class NovatrailCanvas extends HTMLElement {
1525
1535
  }
1526
1536
  }
1527
1537
  /**
1528
- * How much of what a scroller shows is in sight, down the screen: within the ancestors that clip
1529
- * it and the visual viewport, and below the row of buttons while the row sticks over its top, or
1530
- * below the consumer's band, --novatrail-canvas-top, while the row stands in its place in a low
1531
- * window. A scroller out of sight counts whole. Across the screen, the row covers nothing (T94).
1532
- */
1533
- #seen(target, axis = "y") {
1534
- const { start, end, whole } = sightOf(target, axis);
1535
- if (axis === "x")
1536
- return end > start ? end - start : whole;
1537
- const bottom = end;
1538
- let top = start;
1539
- // The row hides the top while it sticks there, as far down as the consumer's offset puts it. A
1540
- // row that stands in its place, in a low window, leaves the consumer's band over it alone.
1541
- const row = this.#tools.element;
1542
- if (this.#tools.sticks) {
1543
- const box = row.getBoundingClientRect();
1544
- if (box.top <= top + offsetOf(row, 0) * scaleOf(row, box) + 0.5) {
1545
- top = Math.max(top, box.bottom);
1546
- }
1547
- }
1548
- else {
1549
- top = Math.max(top, this.#band(target));
1550
- }
1551
- return bottom > top ? bottom - top : whole;
1552
- }
1553
- /**
1554
- * Whether the row sticks (R28): while it is no taller than a quarter of what it sticks in, below
1555
- * the consumer's offset. In a lower window, or once it wraps over more of it, it stands in its
1556
- * place, above the statement, and goes with the scrolling, as WCAG's technique C34 un-fixes a
1557
- * sticky header (1.4.10, 2.4.11). Its place and its size are the same either way, so the choice
1558
- * changes nothing it is made from. The scroller it sticks in is watched for its size. Only an
1559
- * element on the page asks: what calls this goes when the element leaves it.
1538
+ * What the rail's CSS cannot know (R84): the height of what it sticks in — the scroller's, which
1539
+ * it watches, or the window's —, from whose top it runs down to its bottom, below the consumer's
1540
+ * --novatrail-canvas-top; and the element's width, which a worked example's row keeps within, as
1541
+ * the rail is as wide as nothing. A band in pixels is taken as it changes; one in percent, of the
1542
+ * scroller's height as `top` takes it and not of the element's as `height` would, and `auto`,
1543
+ * nothing as `#band` counts it, are taken here, at the next resize.
1560
1544
  */
1561
- #stick() {
1562
- const room = roomOf(this.#tools.element);
1545
+ #fit() {
1546
+ const rail = this.#tools.rail;
1547
+ if (!this.isConnected || rail.hidden)
1548
+ return;
1549
+ const band = getComputedStyle(this).getPropertyValue("--novatrail-canvas-top").trim();
1550
+ rail.style.removeProperty("--rail-top");
1551
+ if (band === "auto")
1552
+ rail.style.setProperty("--rail-top", "0px");
1553
+ // A sticky box's `top` reads as the pixels it is used at.
1554
+ else if (band.includes("%"))
1555
+ rail.style.setProperty("--rail-top", getComputedStyle(rail).top);
1556
+ const room = roomOf(rail);
1563
1557
  if (room.port !== this.#port) {
1564
1558
  if (this.#port !== null)
1565
- this.#page.unobserve(this.#port);
1566
- if (room.port !== null)
1567
- this.#page.observe(room.port);
1559
+ this.#ported.unobserve(this.#port);
1568
1560
  this.#port = room.port;
1561
+ if (room.port !== null)
1562
+ this.#ported.observe(room.port);
1569
1563
  }
1570
- const row = this.#tools.element;
1571
- const tall = row.getBoundingClientRect().height;
1572
- if (tall > 0 && room.height > 0)
1573
- this.#tools.stick(4 * tall <= room.height - room.offset);
1574
- this.#topSeen = getComputedStyle(row).top;
1564
+ rail.style.setProperty("--rail-room", `${room.height / scaleOf(rail)}px`);
1565
+ rail.style.setProperty("--rail-width", `${this.#wrapper.clientWidth}px`);
1575
1566
  }
1576
1567
  /**
1577
- * Where the consumer's band over the top of what the row sticks in ends, down the screen: its
1578
- * offset, --novatrail-canvas-top, below the top of the scroller or of the window — for a target
1579
- * that is or lies within what the row sticks in, and above everything for any other.
1568
+ * Where the consumer's band over the top of what the bar's rail sticks in ends, down the screen:
1569
+ * its offset, --novatrail-canvas-top, below the top of the scroller or of the window — for a
1570
+ * target that is or lies within what the rail sticks in, and above everything for any other.
1580
1571
  */
1581
1572
  #band(target) {
1582
- const room = roomOf(this.#tools.element);
1583
- // The band stands over the top of what the row sticks in, and so over a scroller within it,
1584
- // but not over the page's when the row sticks in a scroller of its own.
1573
+ const room = roomOf(this.#tools.rail);
1574
+ // The band stands over the top of what the rail sticks in, and so over a scroller within it,
1575
+ // but not over the page's when the rail sticks in a scroller of its own.
1585
1576
  const within = room.port === null
1586
1577
  ? target !== undefined
1587
1578
  : target instanceof Element && (target === room.port || holds(room.port, target));
1588
1579
  return within ? room.top + room.offset : Number.NEGATIVE_INFINITY;
1589
1580
  }
1590
- /**
1591
- * Up and Down as the scrolling now is (R33), and Left and Right while the sheet is zoomed (T94):
1592
- * each stands unavailable while what two fingers would scroll its way can go no further. The
1593
- * element hears its container, the page and the ancestors in the page's own tree scroll, and the
1594
- * page and the window change size, but not the scrolling in another shadow tree: a press asks
1595
- * anew.
1596
- */
1597
- #edges() {
1598
- if (!this.isConnected)
1599
- return;
1600
- const above = this.#scrollerFor(false) !== undefined;
1601
- const below = this.#scrollerFor(true) !== undefined;
1602
- const zoomed = this.#zoom > 1;
1603
- const before = zoomed && this.#scrollerFor(false, "x") !== undefined;
1604
- const after = zoomed && this.#scrollerFor(true, "x") !== undefined;
1605
- this.#tools.edges(above, below, before, after);
1606
- }
1607
1581
  /**
1608
1582
  * Two fingers moved right on the screen by `dx` CSS pixels and down it by `dy` (R29), and what
1609
1583
  * they scroll goes with them. The gesture's first step down chooses what it scrolls down, for the
@@ -1718,8 +1692,6 @@ export class NovatrailCanvas extends HTMLElement {
1718
1692
  this.#canvas.height = height;
1719
1693
  }
1720
1694
  this.#draw();
1721
- // A container of another height, or a statement, may give Up or Down somewhere to go, or none.
1722
- this.#edges();
1723
1695
  }
1724
1696
  /** A new density — the window on another screen, the page zoomed — lays the canvas out anew. */
1725
1697
  #watchDensity() {
@@ -1788,9 +1760,9 @@ export class NovatrailCanvas extends HTMLElement {
1788
1760
  /**
1789
1761
  * The learner opened the next part of the demo with the row's Next (R42). The list grows above
1790
1762
  * the sheet, and the layout keeps a sheet scrolled into sight where it was at once, before the
1791
- * scroll of the container is heard; then the part comes into sight below the row of buttons, the
1792
- * region tells of it, and whoever listens hears of the new state. The focus stays on Next, which
1793
- * opens the part after it. Nothing happens while the demo is hidden, or open whole.
1763
+ * scroll of the container is heard; then the part comes into sight between the band and the row
1764
+ * of glass, the region tells of it, and whoever listens hears of the new state. The focus stays
1765
+ * on Next, which opens the part after it. Nothing happens while the demo is hidden, or open whole.
1794
1766
  */
1795
1767
  #openNext() {
1796
1768
  const example = this.#example;
@@ -1888,30 +1860,27 @@ export class NovatrailCanvas extends HTMLElement {
1888
1860
  }
1889
1861
  /**
1890
1862
  * An item of the list, or an area of the sheet, comes into sight at once, as near as it is (R42),
1891
- * and then out from under the row of buttons, should the row stick over where it came to: what
1892
- * scrolls back up goes back as far as the row covers it. A row in its place, in a low window,
1893
- * covers nothing, and the consumer's band, --novatrail-canvas-top, is what it comes out from
1894
- * under then. A margin of scrolling would hold for
1895
- * every scroller of the chain alike — the sheet's container, which the row stands above, and the
1896
- * page, which it sticks over. An area of the sheet taller than what is in sight comes by its top
1897
- * from below, but by its bottom from above, and then the row's cover brings its top back into
1898
- * sight, under the row (T61).
1863
+ * and then out from under the consumer's band, --novatrail-canvas-top, should the band cover
1864
+ * where it came to: what scrolls back up goes back as far as the band covers it. A margin of
1865
+ * scrolling would hold for every scroller of the chain alike — the sheet's container and the
1866
+ * page. An area of the sheet taller than what is in sight comes by its top from below, but by its
1867
+ * bottom from above, and then the band's cover brings its top back into sight (T61). The bar of
1868
+ * buttons covers nothing at the top: it stands at the left edge, and a worked example's row at
1869
+ * the bottom, where a scroll margin keeps what comes from below above it (R84).
1899
1870
  */
1900
1871
  #bringIntoSight(item) {
1872
+ // A worked example's row of glass stands over the bottom of what is in sight: what comes into
1873
+ // sight from below stops 16 pixels above it (R84).
1874
+ const { rail, row } = this.#tools;
1875
+ const under = rail.hidden || row.hidden ? 0 : row.offsetHeight + 32;
1876
+ item.style.setProperty("scroll-margin-bottom", `${under}px`);
1901
1877
  item.scrollIntoView({ block: "nearest", behavior: "instant" });
1902
- // A scroller that comes to its top hands the rest on to the next, as Up does (R33). A scroller
1903
- // goes again only while each of its scrolls leaves less covered than the last: a row that the
1904
- // element's bottom pushed up from where it sticks comes back down as the page scrolls, over
1905
- // what the scroll brought out, and the next brings it out again (T94).
1878
+ // A scroller that comes to its top hands the rest on to the next. A scroller goes again only
1879
+ // while each of its scrolls leaves less covered than the last (T94).
1906
1880
  const covered = new Map();
1907
1881
  for (;;) {
1908
1882
  const latch = this.#scrollerFor(false);
1909
- // A row in its place, in a low window, covers nothing of it: the consumer's band may, over
1910
- // what the row sticks in.
1911
- const over = this.#tools.sticks
1912
- ? this.#tools.element.getBoundingClientRect().bottom
1913
- : this.#band(latch?.target);
1914
- const cover = over - item.getBoundingClientRect().top;
1883
+ const cover = this.#band(latch?.target) - item.getBoundingClientRect().top;
1915
1884
  if (cover <= EDGE || latch === undefined)
1916
1885
  return;
1917
1886
  const last = covered.get(latch.target);
@@ -2359,34 +2328,6 @@ function scrollsOn(element, onward, axis = "y") {
2359
2328
  const at = scrolledOf(element, axis);
2360
2329
  return onward ? at < overflowOf(element, axis) - EDGE : at > EDGE;
2361
2330
  }
2362
- /**
2363
- * Where what a scroller shows is in sight down the screen, or across it along `x` (T94): within
2364
- * the ancestors that clip it and the visual viewport, from `start` to `end` — and how much it
2365
- * shows whole, for a scroller out of sight.
2366
- */
2367
- function sightOf(target, axis) {
2368
- const down = axis === "y";
2369
- const sight = window.visualViewport;
2370
- let start = (down ? sight?.offsetTop : sight?.offsetLeft) ?? 0;
2371
- let end = start + ((down ? sight?.height : sight?.width) ?? (down ? innerHeight : innerWidth));
2372
- let whole = end - start;
2373
- if (target instanceof Element) {
2374
- const own = clientBoxOf(target);
2375
- whole = down ? own.bottom - own.top : own.right - own.left;
2376
- // The scroller, and every ancestor that clips it, up to the page, whose part is the sight.
2377
- for (let node = target; node !== null; node = parentOf(node)) {
2378
- if (node === document.documentElement)
2379
- break;
2380
- const style = node === target ? undefined : getComputedStyle(node);
2381
- if (style !== undefined && (down ? style.overflowY : style.overflowX) === "visible")
2382
- continue;
2383
- const clip = node === target ? own : clientBoxOf(node);
2384
- start = Math.max(start, down ? clip.top : clip.left);
2385
- end = Math.min(end, down ? clip.bottom : clip.right);
2386
- }
2387
- }
2388
- return { start, end, whole };
2389
- }
2390
2331
  /** Whether an element holds another in the flat tree, across the borders of shadow trees. */
2391
2332
  function holds(ancestor, element) {
2392
2333
  for (let node = parentOf(element); node !== null; node = parentOf(node)) {