@altnovatrail/canvas 0.3.37 → 0.3.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,8 +13,8 @@
13
13
  // action, and the work for checking is the crop with the context of its submission (R27). Over it
14
14
  // all stand the element's own buttons — the tools the task allows, undo and clearing —, labelled
15
15
  // in the element's `lang` (R28), on a vertical bar of glass at its left edge (R84). On a tablet a
16
- // pen's touch puts the page in pen mode, where a finger writes nothing and a button lets it write
17
- // again, a palm writes nothing, and two fingers scroll (R29), one finger too (R84).
16
+ // pen's touch puts the page in pen mode, where a finger writes nothing, a palm writes nothing, and
17
+ // two fingers scroll (R29), one finger too (R84).
18
18
  // The task comes in the names of the module format 0.4, checked as its schema checks it, and the
19
19
  // module's manifest gives the height of a digit and the statement's language (R32; R60).
20
20
  //
@@ -25,8 +25,8 @@
25
25
  // crop of each filled box, with the table of the boxes' strokes for its context (R38).
26
26
  //
27
27
  // A lesson's worked example it shows on a sheet the learner does not write on: its statement above
28
- // the sheet, its grid, and a bar without the tools of writing, while a finger or a pen scrolls the
29
- // sheet as the browser scrolls the statement. The parts of its demo the learner opens one at a time
28
+ // the sheet, its grid, and no bar, while a finger or a pen scrolls the sheet as the browser scrolls
29
+ // the statement. The parts of its demo the learner opens one at a time
30
30
  // with Next, into a list above the sheet that a polite region tells a screen reader of, and hides
31
31
  // and shows with Demo; app keeps how far the learner has gone by `demoState` and `demochange`. The
32
32
  // pictures of the statement and of the demo come from the consumer's media, one file for each
@@ -39,22 +39,23 @@
39
39
  // The keyboard goes into the sheet and out: a container that scrolls is a region named by the
40
40
  // canvas kind, with a stop of Tab of its own and a ring when the keyboard brings the focus there
41
41
  // (R33); for a `lang` the labels are not in, the container is in theirs and the column in the
42
- // element's (R74). Zoom in and Zoom out step the page's zoom of the sheet from its fit to twice
43
- // it, and a zoomed sheet scrolls across as well as down, with two fingers, the wheel and the keys
44
- // (R73).
42
+ // element's (R74). The sheet goes on past the task's page, which stands at its left, right and
43
+ // down as far as the ink and one view more, and nothing zooms it: the hand, two fingers, the wheel
44
+ // and the keys move it across as well as down (R73; R88).
45
45
  //
46
- // A task from the learner's paper it shows on a dotted sheet, with the task's crop over it as
47
- // tracing paper, which the learner moves by its grip, hides and shows by the button atop the tools,
48
- // and writes on as on the sheet: a stroke begun on the paper is the paper's and moves with it, and
49
- // an erasing begun on it takes the paper's strokes alone. The work for checking is the crop of the
50
- // paper and of the sheet's strokes, with the task's crop beside it (R87).
46
+ // A task from the learner's paper it shows on a sheet of the learner's grid, which the grid's
47
+ // button turns round, dots as the task comes (R88), with the task's crop over it as tracing paper,
48
+ // which the learner moves by its grip, hides and shows by the button atop the tools, and writes on
49
+ // as on the sheet: a stroke begun on the paper is the paper's and moves with it, and an erasing
50
+ // begun on it takes the paper's strokes alone. The work for checking is the crop of the paper and
51
+ // of the sheet's strokes, with the task's crop beside it (R87).
51
52
  import { cellOf, cellsOf, filledOf, sheetFilledOf } from "../core/boxes.js";
52
53
  import { Clock } from "../core/clock.js";
53
54
  import { ERASER_BUTTON, Eraser } from "../core/eraser.js";
54
55
  import { DEMO_START, demoStateOf, exampleOf, exampleTemplate, filledBy, fillValue, sameExample, } from "../core/example.js";
55
56
  import { sameItems } from "../core/fields.js";
56
57
  import { boxOf } from "../core/geometry.js";
57
- import { GRID_STEP, gridPath } from "../core/grid.js";
58
+ import { GRID_STEP, gridBand, gridPath } from "../core/grid.js";
58
59
  import { Hands } from "../core/hands.js";
59
60
  import { begins, sameHistory } from "../core/history.js";
60
61
  import { NO_MANIFEST, settingsOf } from "../core/manifest.js";
@@ -64,17 +65,17 @@ import { isBox, LAYOUT, pieceWidth, } from "../core/page.js";
64
65
  import { encodePNG } from "../core/png.js";
65
66
  import { Recorder } from "../core/recorder.js";
66
67
  import { fitScale, K_MAX, scaleFor, toSheet } from "../core/screen.js";
67
- import { SHEET } from "../core/sheet.js";
68
+ import { extentOf, pictureOf, REACH, SHEET } from "../core/sheet.js";
68
69
  import { cellsForCheck, paperWorkForCheck, workForCheck } from "../core/submission.js";
69
- import { isTool, isWorkbook, NO_TASK, sameLayer, sameStatement, taskOf, templateOf, wholeSheet, } from "../core/task.js";
70
- import { boxOnSheet, keptOn, layOver, onSheet, onTracing, sameTracing, TRACING, TRACING_START, toTracing, rectOf as tracingRect, tracingStateOf, whollyOff, } from "../core/tracing.js";
70
+ import { HAND, isTool, isWorkbook, NO_TASK, sameLayer, sameStatement, taskOf, templateOf, wholeSheet, } from "../core/task.js";
71
+ import { boxOnSheet, isPaperGrid, keptOn, layOver, nextGrid, onSheet, onTracing, PAPER_GRIDS, readingOf, rulingsOf, sameTracing, scaled, scaleIn, TRACING, TRACING_START, toTracing, rectOf as tracingRect, scaleOf as tracingScaleOf, tracingStateOf, whollyOff, } from "../core/tracing.js";
71
72
  import { nextIdOf, resumeOf, Work } from "../core/work.js";
72
73
  import { placeOver, SVG, write } from "./attributes.js";
73
74
  import { knows, labelsFor, say, sayAround } from "./labels.js";
74
75
  import { Parts } from "./parts.js";
75
76
  import { Pictures } from "./pictures.js";
76
77
  import { attachProbe } from "./probe.js";
77
- import { PAGE_ZOOM, PEN_MODE } from "./session.js";
78
+ import { PEN_MODE } from "./session.js";
78
79
  import { Statement } from "./statement.js";
79
80
  import { Tools } from "./tools.js";
80
81
  import { TracingPaper } from "./tracing.js";
@@ -98,9 +99,12 @@ const TOOL_CHANGE = "toolchange";
98
99
  const DEMO_CHANGE = "demochange";
99
100
  /** The event the element sends when the learner moves the tracing paper, or hides or shows it. */
100
101
  const TRACING_CHANGE = "tracingchange";
102
+ const TRACING_READ = "tracingread";
103
+ /** The event the element sends when the learner turns a task from paper's grid with its button. */
104
+ const GRID_CHANGE = "gridchange";
101
105
  /**
102
- * A task from paper's template: a dotted sheet, no statement, the pen and the eraser (R87; R162
103
- * spec).
106
+ * A task from paper's template: no statement, the pen and the eraser, and a dotted sheet, as the
107
+ * task comes, whose grid the learner turns (R87; R88; R162 spec).
104
108
  */
105
109
  const PAPER_TEMPLATE = Object.freeze({
106
110
  grid: Object.freeze({ kind: "dots", step: TRACING.dots }),
@@ -151,45 +155,47 @@ const MARK_CORNER = 6;
151
155
  * the sheet's scale (R22).
152
156
  */
153
157
  const ERASER_RADIUS_PX = 10;
154
- // The statement and the sheet stand in a column of their own, as wide as the element up to
155
- // 1000 CSS pixels and in its middle beyond, and scroll in a container of their own, by the
156
- // browser's own scrolling: the wheel, the scroll bar and the keyboard work as anywhere on a page.
157
- // The page's zoom widens the column with the sheet, to twice its fit, and the container scrolls
158
- // it across too, left to right whatever the page's direction, while the statement and a demo's
159
- // parts stay as wide as the fit and stick to its left, in the element's own direction: they wrap
160
- // as at the fit, and scroll down alone (R73). The layers of the sheet stand in its visible part,
161
- // the stage, which sticks to the container's top and left, and each shows what lies there, shifted
162
- // in the frame the ink is drawn in (R18, R23).
163
- // Over the container, in the same cell of the frame's grid, stands the rail of the element's own
164
- // buttons: a band as tall as the part of the element in sight and as wide as nothing, sticking to
165
- // the top of whatever scrolls the element, as far down as the consumer's --novatrail-canvas-top
166
- // says, and in its middle, 16 pixels from the left edge, the bar of buttons: 52 pixels wide, round
167
- // at its ends, of the mockup's glass — the fill the consumer's theme gives, blurred behind, or the
168
- // paper alone where nothing blurs — over the sheet as it scrolls by (R84; R148 spec). A bar taller
169
- // than the band scrolls inside its glass (WCAG 1.4.10). A worked example's bar holds the zoom's
170
- // pair alone, and its Next and Demo stand in a row of the same glass at the band's bottom, the
171
- // consumer's buttons of the slot actions after them (R84). The tool in use is filled with the
172
- // accent at an eighth, its icon in the accent; a button in focus shows a ring in the accent; an
173
- // unavailable one is paler by its colour, not its opacity, which would pale the ring too (WCAG
174
- // 2.4.7, 1.4.11). A button's tooltip stands beside it, white on near-black, as the mockup has it.
175
- // Nothing in the element moves but the scrolling, which jumps, and no tooltip fades (WCAG 2.3.3).
176
- // The element is as tall as the statement and the sheet unless it is given a height: then the
177
- // statement and the sheet scroll in it, under the bar. A worked example's open parts stand between
178
- // the statement and the sheet, and the region that tells of them is out of sight, but not out of
179
- // the tree a screen reader reads, where a hidden region would tell nothing (R42). A picture's
180
- // frame there stands in its item's line, from its top, so that the item's number stands at the
181
- // top too, as a paragraph's does, and not at the picture's bottom. A picture on an area of the
182
- // sheet stands on the layer of the author's demo, and the sheet scrolls to a hidden box of the
183
- // area in its own flow, which neither paints nor takes a pointer (R42). On the canvas the browser
184
- // neither scrolls nor zooms: the pointer writes, and two fingers scroll by the element's own code
185
- // (R29), and in pen mode one finger too (R84).
186
- // The canvas and the buttons take pointer events only as the element does: a consumer's
187
- // pointer-events: none on the element stops the writing and the buttons' pointer, though not
188
- // their keys (R20, R28). A worked example's canvas takes no pointer at all: a finger or a pen on
189
- // its sheet scrolls, and zooms, as the browser does on the statement, and a long press or a right
190
- // click opens no menu over the sheet all the same (R42). The theme is the consumer's, by custom
191
- // properties that the shadow tree inherits; with forced colours the system's colours stand in for
192
- // them. The element is horizontal whatever writing mode the page is in: a sheet has no other (R36).
158
+ // The statement and the sheet stand in a column of their own, and scroll in a container of their
159
+ // own, by the browser's own scrolling: the wheel, the scroll bar and the keyboard work as anywhere
160
+ // on a page. The task's page is as wide as the element up to 1000 CSS pixels and stands at the
161
+ // sheet's left; the sheet goes on past it as far as `#extent` says, and the container scrolls it
162
+ // across too, left to right whatever the page's direction, while the statement and a demo's parts
163
+ // stay as wide as the page and stick to its left, in the element's own direction: they scroll down
164
+ // alone (R73). The layers of the sheet stand in its visible part, the stage, which sticks to the
165
+ // container's top and left, and each shows what lies there, shifted in the frame the ink is drawn
166
+ // in (R18, R23). Over the container, in the same cell of the frame's grid, stands the rail of the
167
+ // element's own buttons: a band as tall as the part of the element in sight and as wide as nothing,
168
+ // sticking to the top of whatever scrolls the element, as far down as the consumer's
169
+ // --novatrail-canvas-top says, and up to its bottom less --novatrail-canvas-pad-bottom, and in its
170
+ // middle, 16 pixels from the left edge, the bar of buttons: 52 pixels wide, round at its ends, of
171
+ // the mockup's glass — the fill the consumer's theme gives, blurred behind, or the paper alone
172
+ // where nothing blurs — over the sheet as it scrolls by (R84; R148 spec). A bar taller than the
173
+ // band scrolls inside its glass (WCAG 1.4.10). A worked example has no bar, and its Next and Demo
174
+ // stand in a row of the same glass at the band's bottom, the consumer's buttons of the slot actions
175
+ // after them (R84). The tool in use is filled with the accent at an eighth, its icon in the accent;
176
+ // a button in focus shows a ring in the accent; an unavailable one is paler by its colour, not its
177
+ // opacity, which would pale the ring too (WCAG 2.4.7, 1.4.11). A button's tooltip stands beside it,
178
+ // white on near-black, as the mockup has it. Nothing in the element moves but the scrolling, which
179
+ // jumps, and no tooltip fades (WCAG 2.3.3). The element is as tall as the statement and the sheet
180
+ // unless it is given a height: then the statement and the sheet scroll in it, under the bar. A
181
+ // consumer whose own bars float over the element's top and bottom says how far by
182
+ // --novatrail-canvas-pad-top and -bottom: the statement starts below the first, and the sheet
183
+ // scrolls up past the second (R73). A worked example's open parts stand between the statement and
184
+ // the sheet, and the region that tells of them is out of sight, but not out of the tree a screen
185
+ // reader reads, where a hidden region would tell nothing (R42). A picture's frame there stands in
186
+ // its item's line, from its top, so that the item's number stands at the top too, as a paragraph's
187
+ // does, and not at the picture's bottom. A picture on an area of the sheet stands on the layer of
188
+ // the author's demo, and the sheet scrolls to a hidden box of the area in its own flow, which
189
+ // neither paints nor takes a pointer (R42). On the canvas the browser neither scrolls nor zooms:
190
+ // the pointer writes, or with the hand moves the sheet, and two fingers scroll by the element's own
191
+ // code (R29), and in pen mode one finger too (R84; R88). The canvas and the buttons take pointer
192
+ // events only as the element does: a consumer's pointer-events: none on the element stops the
193
+ // writing and the buttons' pointer, though not their keys (R20, R28). A worked example's canvas
194
+ // takes no pointer at all: a finger or a pen on its sheet scrolls, and zooms, as the browser does
195
+ // on the statement, and a long press or a right click opens no menu over the sheet all the same
196
+ // (R42). The theme is the consumer's, by custom properties that the shadow tree inherits; with
197
+ // forced colours the system's colours stand in for them. The element is horizontal whatever writing
198
+ // mode the page is in: a sheet has no other (R36).
193
199
  //
194
200
  // A workbook's lines are printed in the ink's colour and the consumer's font, and nothing else the
195
201
  // element inherits — spacing, weight, transforms, the direction — moves them: `all: initial` takes
@@ -204,19 +210,23 @@ const STYLE = `
204
210
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
205
211
  }
206
212
  .viewport {
207
- grid-area: 1 / 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overflow-anchor: none;
208
- outline: none; -webkit-tap-highlight-color: transparent;
213
+ grid-area: 1 / 1; min-height: 0; overflow: auto; overflow-anchor: none; direction: ltr;
214
+ scrollbar-width: none; outline: none; -webkit-tap-highlight-color: transparent;
209
215
  }
210
216
  .rail {
211
217
  grid-area: 1 / 1; align-self: start; justify-self: left; width: 0; direction: ltr;
212
218
  position: sticky; top: var(--rail-top, var(--novatrail-canvas-top, 0px)); z-index: 1;
213
219
  box-sizing: border-box; padding: 16px 0;
214
- height: min(100%, var(--rail-room, 100dvh) - var(--rail-top, var(--novatrail-canvas-top, 0px)));
220
+ height: min(
221
+ 100%,
222
+ var(--rail-room, 100dvh) - var(--rail-top, var(--novatrail-canvas-top, 0px)) -
223
+ var(--novatrail-canvas-pad-bottom, 0px)
224
+ );
215
225
  display: flex; align-items: center;
216
226
  }
217
227
  .rail[hidden] { display: none; }
218
228
  .rail.example { padding-bottom: 88px; }
219
- .tools {
229
+ .tools, .tracing-scale {
220
230
  box-sizing: border-box; flex: none; width: 52px; max-height: 100%;
221
231
  margin: 0 0 0 16px; padding: 4px; border-radius: 26px;
222
232
  display: flex; flex-direction: column; align-items: center; gap: 2px;
@@ -228,7 +238,7 @@ const STYLE = `
228
238
  0 1px 2px rgba(0, 0, 0, 0.04);
229
239
  }
230
240
  @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
231
- .tools { background: var(--novatrail-canvas-paper, ${PAPER}); }
241
+ .tools, .tracing-scale { background: var(--novatrail-canvas-paper, ${PAPER}); }
232
242
  }
233
243
  .tools:dir(rtl) { direction: rtl; }
234
244
  .tools.row {
@@ -237,20 +247,20 @@ const STYLE = `
237
247
  max-height: none; margin: 0; padding: 6px; border-radius: 28px; flex-direction: row; gap: 4px;
238
248
  overflow-x: auto; overflow-y: hidden;
239
249
  }
240
- .tools .choice, .tools .zoom { display: flex; flex-direction: column; gap: 2px; flex: none; }
241
- .tools .line {
250
+ .tools .choice { display: flex; flex-direction: column; gap: 2px; flex: none; }
251
+ :is(.tools, .tracing-scale) .line {
242
252
  flex: none; width: 24px; height: 1px; margin: 4px 0; background: rgba(0, 0, 0, 0.1);
243
253
  }
244
254
  .tools.row .line { width: 1px; height: 24px; margin: 0 4px; }
245
255
  .tools.row ::slotted(*) { flex: none; }
246
- .tools button {
256
+ :is(.tools, .tracing-scale) button {
247
257
  box-sizing: border-box; flex: none; min-width: 44px; min-height: 44px; margin: 0;
248
258
  padding: 0 14px 0 10px; display: flex; align-items: center; justify-content: center; gap: 6px;
249
259
  font: inherit; font-weight: 500; white-space: nowrap; color: inherit; background: transparent;
250
260
  cursor: pointer; border: none; border-radius: 22px;
251
261
  }
252
- .tools button.icon { width: 44px; height: 44px; padding: 0; }
253
- .tools button.icon .label {
262
+ :is(.tools, .tracing-scale) button.icon { width: 44px; height: 44px; padding: 0; }
263
+ :is(.tools, .tracing-scale) button.icon .label {
254
264
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
255
265
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
256
266
  }
@@ -258,21 +268,21 @@ const STYLE = `
258
268
  background: color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 12%, transparent);
259
269
  color: var(--novatrail-canvas-accent, ${ACCENT});
260
270
  }
261
- .tools button:focus-visible {
271
+ :is(.tools, .tracing-scale) button:focus-visible {
262
272
  outline: 2px solid var(--novatrail-canvas-accent, ${ACCENT}); outline-offset: 0;
263
273
  }
264
- .tools [aria-disabled="true"] {
274
+ :is(.tools, .tracing-scale) [aria-disabled="true"] {
265
275
  color: color-mix(
266
276
  in srgb, var(--novatrail-canvas-ink, ${INK}) 40%, var(--novatrail-canvas-paper, ${PAPER})
267
277
  );
268
278
  cursor: default;
269
279
  }
270
280
  @supports not (color: color-mix(in srgb, red 40%, blue)) {
271
- .tools [aria-disabled="true"] { opacity: 0.4; }
281
+ :is(.tools, .tracing-scale) [aria-disabled="true"] { opacity: 0.4; }
272
282
  .tools [aria-checked="true"] { background: transparent; }
273
283
  }
274
- .tools[hidden], .tools [hidden] { display: none; }
275
- .tools button svg { display: block; flex: none; width: 20px; height: 20px; fill: currentColor; }
284
+ .tools[hidden], :is(.tools, .tracing-scale) [hidden] { display: none; }
285
+ :is(.tools, .tracing-scale) button svg { display: block; flex: none; width: 20px; height: 20px; fill: currentColor; }
276
286
  .tools:dir(rtl) svg.mirrored { transform: scaleX(-1); }
277
287
  .tip {
278
288
  position: absolute; left: var(--tip-x, 76px); top: var(--tip-y, 0px); z-index: 2;
@@ -281,21 +291,33 @@ const STYLE = `
281
291
  background: #1d1d1f; color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
282
292
  }
283
293
  .tip[hidden] { display: none; }
284
- .viewport.zoomed { overflow-x: auto; direction: ltr; }
285
294
  .ring { position: absolute; inset: 0; z-index: 0; pointer-events: none; display: none; }
286
295
  .viewport:focus-visible + .ring {
287
296
  display: block; outline: 2px solid var(--novatrail-canvas-ink, ${INK}); outline-offset: -2px;
288
297
  }
289
298
  .column {
290
- position: relative; width: calc(min(100%, ${K_MAX * SHEET.width}px) * var(--zoom));
291
- margin: 0 auto;
299
+ position: relative; width: calc(min(100%, ${K_MAX * SHEET.width}px) * var(--across, 1));
300
+ padding-block: var(--novatrail-canvas-pad-top, 0px) var(--novatrail-canvas-pad-bottom, 0px);
292
301
  }
293
- .zoomed .statement, .zoomed .parts {
294
- position: sticky; left: 0; box-sizing: border-box; width: calc(100% / var(--zoom));
302
+ .statement, .parts {
303
+ position: sticky; left: 0; box-sizing: border-box; width: calc(100% / var(--across, 1));
295
304
  direction: var(--direction, ltr);
296
305
  }
297
306
  .statement { padding: 0 0 12px; overflow-wrap: break-word; }
298
307
  .statement:empty { display: none; }
308
+ .band {
309
+ position: absolute; left: 0; display: none; width: 100%; overflow: visible; pointer-events: none;
310
+ background: var(--novatrail-canvas-paper, ${PAPER});
311
+ }
312
+ .band.above {
313
+ --pad: var(--novatrail-canvas-pad-top, 0px);
314
+ top: 0; height: var(--pad); clip-path: inset(0 0 calc(-1 * min(2px, var(--pad))) 0);
315
+ }
316
+ .band.below {
317
+ --pad: var(--novatrail-canvas-pad-bottom, 0px);
318
+ bottom: 0; height: var(--pad); clip-path: inset(calc(-1 * min(2px, var(--pad))) 0 0 0);
319
+ }
320
+ .statement:empty ~ .band.above, .band.below { display: block; }
299
321
  .statement p { margin: 0 0 8px; }
300
322
  .picture {
301
323
  box-sizing: border-box; max-width: 100%; margin: 0 0 8px; padding: 8px;
@@ -344,6 +366,8 @@ canvas {
344
366
  touch-action: none;
345
367
  }
346
368
  .sheet.example canvas { pointer-events: none; touch-action: auto; }
369
+ .sheet.hand canvas { cursor: grab; }
370
+ .sheet.panning canvas { cursor: grabbing; }
347
371
  .tracing { mix-blend-mode: multiply; }
348
372
  .tracing .edge {
349
373
  fill: none; stroke: rgba(60, 60, 67, 0.3); stroke-width: 1px; vector-effect: non-scaling-stroke;
@@ -361,7 +385,88 @@ canvas {
361
385
  .grip.dragging { cursor: grabbing; }
362
386
  .grip.dragging .bar { background: var(--novatrail-canvas-accent, ${ACCENT}); }
363
387
  .grip:focus-visible { outline: 2px solid var(--novatrail-canvas-accent, ${ACCENT}); }
364
- .stage > .tip { inset: auto; width: auto; height: auto; pointer-events: none; }
388
+ .stage > .tip {
389
+ inset: var(--tip-y, 0px) auto auto var(--tip-x, 0px); width: auto; height: auto;
390
+ pointer-events: none;
391
+ }
392
+ .stage > .tracing-cover, .stage > .tracing-frame { inset: 0 auto auto 0; box-sizing: border-box; }
393
+ .stage > .tracing-cover[hidden], .stage > .tracing-frame[hidden], .stage > .tracing-sign[hidden],
394
+ .stage > .tracing-scale[hidden], .tracing-cover [hidden] { display: none; }
395
+ .statements {
396
+ position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
397
+ justify-content: center; gap: 0.2em; font-weight: 500; line-height: 1.2;
398
+ letter-spacing: -0.02em; white-space: nowrap; direction: ltr;
399
+ color: var(--novatrail-canvas-ink, ${INK});
400
+ }
401
+ .statements .slot {
402
+ display: inline-block; box-sizing: border-box; width: 1.08em; height: 1.08em;
403
+ margin: 0 0.18em; vertical-align: -0.22em; border-radius: 0.2em;
404
+ border: max(2px, 0.04em) dashed var(--novatrail-canvas-accent, ${ACCENT});
405
+ }
406
+ .scan {
407
+ position: absolute; inset: 0; overflow: hidden;
408
+ background: color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 4%, transparent);
409
+ }
410
+ .scan i {
411
+ position: absolute; top: 0; bottom: 0; left: -30%; width: 30%;
412
+ background: linear-gradient(90deg, transparent,
413
+ color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 18%, transparent), transparent);
414
+ border-right: 2px solid color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 60%, transparent);
415
+ left: 35%;
416
+ }
417
+ @keyframes novatrail-scan { from { left: -30%; } to { left: 100%; } }
418
+ @keyframes novatrail-spin { to { transform: rotate(360deg); } }
419
+ .tracing-frame {
420
+ border: 1.5px solid var(--novatrail-canvas-accent, ${ACCENT}); border-radius: var(--round, 6px);
421
+ }
422
+ .tracing-frame .corner {
423
+ position: absolute; width: 44px; height: 44px; margin: -22px; pointer-events: auto;
424
+ touch-action: none;
425
+ }
426
+ .tracing-frame .corner::after {
427
+ content: ""; position: absolute; inset: 13px; box-sizing: border-box; border-radius: 50%;
428
+ background: #fff; border: 2px solid var(--novatrail-canvas-accent, ${ACCENT});
429
+ box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
430
+ }
431
+ .tracing-frame .tl { left: 0; top: 0; cursor: nwse-resize; }
432
+ .tracing-frame .tr { left: 100%; top: 0; cursor: nesw-resize; }
433
+ .tracing-frame .bl { left: 0; top: 100%; cursor: nesw-resize; }
434
+ .tracing-frame .br { left: 100%; top: 100%; cursor: nwse-resize; }
435
+ .stage > .tracing-sign {
436
+ inset: 0 auto auto 0; width: auto; height: 24px; box-sizing: border-box; padding: 0 10px;
437
+ display: flex; align-items: center; gap: 6px; border-radius: 999px; white-space: nowrap;
438
+ font-size: 12px; font-weight: 600; background: #f2f2f2; color: #6e6e73;
439
+ }
440
+ .stage > .tracing-sign[data-shows="busy"], .stage > .tracing-sign[data-shows="text"] {
441
+ background: #e5f0ff; color: #0058b8;
442
+ }
443
+ .tracing-sign svg { display: block; width: 12px; height: 12px; fill: currentColor; }
444
+ .spinner {
445
+ display: block; box-sizing: border-box; width: 12px; height: 12px; border-radius: 50%;
446
+ border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
447
+ }
448
+ .stage > .tracing-scale {
449
+ inset: var(--bar-y, 0px) auto auto var(--bar-x, 0px); transform: translateX(-50%);
450
+ width: max-content; height: auto; max-height: none; margin: 0; padding: 4px;
451
+ flex-direction: row; gap: 2px; pointer-events: auto; overflow: visible;
452
+ }
453
+ .tracing-scale .line { width: 1px; height: 24px; margin: 0 4px; }
454
+ .tracing-scale .percent { min-width: 64px; padding: 0 8px; font-variant-numeric: tabular-nums; }
455
+ .tracing-scale .mode {
456
+ background: var(--novatrail-canvas-accent, ${ACCENT}); color: #fff; margin-inline-start: 2px;
457
+ }
458
+ .tracing-scale .mode.busy { background: #e5f0ff; color: #0058b8; cursor: default; }
459
+ .tracing-scale .mode.busy svg { display: none; }
460
+ .tracing-scale .mode.busy::before {
461
+ content: ""; display: block; box-sizing: border-box; width: 15px; height: 15px; border-radius: 50%;
462
+ border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
463
+ }
464
+ .tracing-scale .mode.back { background: #f2f2f7; color: var(--novatrail-canvas-ink, ${INK}); }
465
+ /* The one motion: a wait for the reading the learner asked for, and only to whom it is no harm (R89). */
466
+ @media (prefers-reduced-motion: no-preference) {
467
+ .scan i { animation: novatrail-scan 1s ease-in-out infinite; }
468
+ .spinner, .tracing-scale .mode.busy::before { animation: novatrail-spin 0.8s linear infinite; }
469
+ }
365
470
  .marks rect {
366
471
  fill: none; stroke: var(--novatrail-canvas-mark, ${MARK}); stroke-width: 2px;
367
472
  vector-effect: non-scaling-stroke;
@@ -394,17 +499,31 @@ canvas {
394
499
  .tracing .edge { stroke: CanvasText; }
395
500
  .grip .bar, .grip.dragging .bar { background: ButtonText; }
396
501
  .grip:focus-visible { outline-color: Highlight; }
397
- .tools { background: Canvas; color: CanvasText; border: 1px solid CanvasText; }
398
- .tools .line { background: CanvasText; }
399
- .tools button {
502
+ .tracing-frame { border-color: Highlight; }
503
+ .tracing-frame .corner::after { background: Canvas; border-color: Highlight; }
504
+ .statements { color: CanvasText; }
505
+ .statements .slot { border-color: CanvasText; }
506
+ .scan { background: transparent; }
507
+ .scan i { background: transparent; border-right-color: Highlight; }
508
+ .stage > .tracing-sign, .stage > .tracing-sign[data-shows] {
509
+ background: Canvas; color: CanvasText; border: 1px solid CanvasText;
510
+ }
511
+ .tracing-scale .mode, .tracing-scale .mode.busy, .tracing-scale .mode.back {
512
+ background: ButtonFace; color: ButtonText; border: 1px solid ButtonBorder;
513
+ }
514
+ .tools, .tracing-scale { background: Canvas; color: CanvasText; border: 1px solid CanvasText; }
515
+ :is(.tools, .tracing-scale) .line { background: CanvasText; }
516
+ :is(.tools, .tracing-scale) button {
400
517
  background: ButtonFace; color: ButtonText; border: 1px solid ButtonBorder;
401
518
  }
402
519
  .tools [aria-checked="true"] {
403
520
  background: Highlight; color: HighlightText; border-color: Highlight;
404
521
  }
405
- .tools [aria-disabled="true"] { color: GrayText; border-color: GrayText; }
522
+ :is(.tools, .tracing-scale) [aria-disabled="true"] { color: GrayText; border-color: GrayText; }
406
523
  .tip { background: Canvas; color: CanvasText; border: 1px solid CanvasText; }
407
- .tools button:focus-visible, .viewport:focus-visible + .ring { outline-color: Highlight; }
524
+ :is(.tools, .tracing-scale) button:focus-visible, .viewport:focus-visible + .ring {
525
+ outline-color: Highlight;
526
+ }
408
527
  }
409
528
  `;
410
529
  /** The sheet of STYLE that the elements of a document adopt, made by the first of them there. */
@@ -492,11 +611,11 @@ function wavyNode() {
492
611
  * trough, kept to the sheet by `half` its line.
493
612
  */
494
613
  function wavyAt(box, half) {
495
- const y = Math.min(box.maxY + WAVY_BELOW, SHEET.height - WAVY_CREST - half);
614
+ const y = Math.min(box.maxY + WAVY_BELOW, REACH.height - WAVY_CREST - half);
496
615
  return {
497
616
  minX: Math.max(box.minX - WAVY_REACH, half),
498
617
  minY: y - WAVY_CREST,
499
- maxX: Math.min(box.maxX + WAVY_REACH, SHEET.width - half),
618
+ maxX: Math.min(box.maxX + WAVY_REACH, REACH.width - half),
500
619
  maxY: y + WAVY_CREST,
501
620
  };
502
621
  }
@@ -519,8 +638,8 @@ function wavyPath({ minX, minY, maxX, maxY }) {
519
638
  */
520
639
  function verdictAt(box, k) {
521
640
  const size = VERDICT_PX / k;
522
- const minX = Math.min(Math.max(box.maxX + VERDICT_GAP_PX / k, 0), SHEET.width - size);
523
- const minY = Math.min(Math.max((box.minY + box.maxY - size) / 2, 0), SHEET.height - size);
641
+ const minX = Math.min(Math.max(box.maxX + VERDICT_GAP_PX / k, 0), REACH.width - size);
642
+ const minY = Math.min(Math.max((box.minY + box.maxY - size) / 2, 0), REACH.height - size);
524
643
  return { minX, minY, maxX: minX + size, maxY: minY + size };
525
644
  }
526
645
  /** An HTML layer of the sheet, for the module's widget from stage 4: empty till then. */
@@ -550,6 +669,9 @@ export class NovatrailCanvas extends HTMLElement {
550
669
  /** The author's template: a sheet's grid, or a workbook's lines, a list of its items (R36). */
551
670
  #template = svgLayer("template");
552
671
  #grid = document.createElementNS(SVG, "path");
672
+ /** The grid going on above the sheet and below it, under the consumer's floating bars (R73). */
673
+ #above = document.createElementNS(SVG, "svg");
674
+ #below = document.createElementNS(SVG, "svg");
553
675
  #print = document.createElementNS(SVG, "g");
554
676
  #lines = document.createElementNS(SVG, "g");
555
677
  /** The module's widget, from stage 4 (R16 spec): empty till then. */
@@ -575,12 +697,7 @@ export class NovatrailCanvas extends HTMLElement {
575
697
  choose: (tool) => this.#choose(tool),
576
698
  undo: () => this.undo(),
577
699
  clear: () => this.clear(),
578
- zoom: (larger) => this.#zoomBy(larger),
579
- // The finger writes again on every sheet of the page, with no event: the next pen's touch
580
- // puts the page back in pen mode (R29).
581
- fingers: () => {
582
- PEN_MODE.on = false;
583
- },
700
+ turnGrid: () => this.#turnGrid(),
584
701
  next: () => this.#openNext(),
585
702
  toggle: () => this.#toggleDemo(),
586
703
  trace: () => this.#trace(),
@@ -588,8 +705,13 @@ export class NovatrailCanvas extends HTMLElement {
588
705
  /** A task from paper's tracing paper: its layer, its grip and the crop's picture (R87). */
589
706
  #tracingPaper = new TracingPaper({
590
707
  move: (at) => this.#moveTracing(at),
708
+ resize: (at, scale) => this.#resizeTracing(at, scale),
709
+ fit: () => this.#fitTracing(),
591
710
  moved: () => this.#tracingMoved(),
711
+ read: () => this.dispatchEvent(new CustomEvent(TRACING_READ, { bubbles: true, composed: true, detail: null })),
592
712
  });
713
+ /** The reading of the statement of the task from paper, as the consumer gave it (R89). */
714
+ #reading;
593
715
  /** The task from paper as the consumer gave it, and where its tracing paper lies (R87). */
594
716
  #paper;
595
717
  #tracing;
@@ -628,13 +750,12 @@ export class NovatrailCanvas extends HTMLElement {
628
750
  writer: () => this.#writer(),
629
751
  drop: (pointerId) => this.#drop(pointerId),
630
752
  scroll: (dx, dy, fresh) => this.#scroll(dx, dy, fresh),
631
- across: () => this.#zoom > 1,
753
+ across: () => overflowOf(this.#viewport, "x") > EDGE,
632
754
  }, PEN_MODE);
633
- /** Whether the row shows the finger's button: it comes and goes between strokes alone. */
634
- #finger = false;
635
755
  /**
636
- * What two fingers scroll in the gesture under way, down and across, each chosen at the first
637
- * step that goes along its axis (R73): undefined till then, and null when nothing scrolls so.
756
+ * What two fingers, or the hand, scroll in the gesture under way, down and across, each chosen at
757
+ * the first step that goes along its axis (R73): undefined till then, and null when nothing
758
+ * scrolls so.
638
759
  */
639
760
  #latch;
640
761
  #latchAcross;
@@ -644,14 +765,21 @@ export class NovatrailCanvas extends HTMLElement {
644
765
  this.#fit();
645
766
  };
646
767
  #page = new ResizeObserver(this.#resized);
768
+ /** A window of another size has another view: the sheet goes as far past the ink by it (R73). */
769
+ #rewindowed = () => this.#regrow();
647
770
  /** What the bar's rail sticks in, when a scroller of the page's: its height is the rail's room. */
648
771
  #port = null;
649
772
  #ported = new ResizeObserver(() => this.#fit());
650
773
  #unwatchPen;
651
- #unwatchZoom;
652
- /** The page's zoom as the sheet is laid out by it (R73). */
653
- #zoom = 0;
654
774
  #tool = "pen";
775
+ /** The pointer the hand moves the sheet by, and where it was on the screen last (R88). */
776
+ #pan;
777
+ /** A task from paper's grid, the learner's (R88). */
778
+ #paperGrid = "dots";
779
+ /** How far the sheet goes, in units, as laid out: the page and past it (R73). */
780
+ #extent = SHEET;
781
+ /** The grid's path as last drawn: its rulings and the extent they cover. */
782
+ #gridDrawn = "";
655
783
  #task;
656
784
  /** A lesson's worked example as the consumer gave it, and as the element checked it (R42). */
657
785
  #workedExample;
@@ -743,6 +871,18 @@ export class NovatrailCanvas extends HTMLElement {
743
871
  this.#sheet.className = "sheet";
744
872
  this.#stage.className = "stage";
745
873
  this.#grid.setAttribute("class", "grid");
874
+ for (const [band, place] of [
875
+ [this.#above, "above"],
876
+ [this.#below, "below"],
877
+ ]) {
878
+ band.setAttribute("class", `band ${place}`);
879
+ band.setAttribute("aria-hidden", "true");
880
+ // Units at the sheet's scale: the band's width is the extent's, and its height is the
881
+ // padding's, which the band's units outrun and slice at the sheet's edge.
882
+ band.setAttribute("preserveAspectRatio", place === "above" ? "xMinYMax slice" : "xMinYMin slice");
883
+ band.append(document.createElementNS(SVG, "path"));
884
+ band.firstElementChild?.setAttribute("class", "grid");
885
+ }
746
886
  this.#print.setAttribute("class", "print");
747
887
  // The constructor reads no attribute: the labels of a demo's boxes are English till `lang` comes.
748
888
  this.#nameBoxes(null);
@@ -751,14 +891,14 @@ export class NovatrailCanvas extends HTMLElement {
751
891
  this.#print.append(this.#lines);
752
892
  this.#template.append(this.#grid, this.#print);
753
893
  this.#show.append(this.#parts.layer);
754
- this.#stage.append(this.#template, this.#widget, this.#show, this.#tracingPaper.layer, this.#sketch, this.#canvas, this.#marksLayer, this.#tracingPaper.grip, this.#tracingPaper.tip);
894
+ this.#stage.append(this.#template, this.#widget, this.#show, this.#tracingPaper.layer, this.#tracingPaper.cover, this.#sketch, this.#canvas, this.#marksLayer, this.#tracingPaper.frame, this.#tracingPaper.sign, this.#tracingPaper.grip, this.#tracingPaper.tip, this.#tracingPaper.bar);
755
895
  this.#sheet.append(this.#stage, this.#parts.spot);
756
- this.#column.append(this.#statement.element, this.#parts.list, this.#parts.status, this.#sheet);
896
+ // The bands come after the sheet: the ruling on its edge, half past the band, lies over it.
897
+ this.#column.append(this.#statement.element, this.#parts.list, this.#parts.status, this.#sheet, this.#above, this.#below);
757
898
  this.#viewport.append(this.#column);
758
899
  // The bar comes first, as the row of buttons before it did: Tab reaches it before the sheet.
759
900
  this.#wrapper.append(this.#tools.rail, this.#viewport, this.#ring);
760
901
  root.append(this.#wrapper);
761
- this.#zoomTo(PAGE_ZOOM.value);
762
902
  this.#lay(NO_TASK);
763
903
  this.#refresh();
764
904
  this.#canvas.addEventListener("pointerdown", (event) => this.#down(event));
@@ -785,6 +925,8 @@ export class NovatrailCanvas extends HTMLElement {
785
925
  this.#canvas.addEventListener("transitionend", () => this.#request());
786
926
  this.#canvas.addEventListener("transitioncancel", () => this.#request());
787
927
  this.#viewport.addEventListener("scroll", () => this.#scrolled(), { passive: true });
928
+ // Ctrl or ⌘ with the wheel over the tracing paper scales it, not the page (R89).
929
+ this.#viewport.addEventListener("wheel", (event) => this.#wheel(event), { passive: false });
788
930
  // A container left with nothing to scroll keeps its stop of Tab while it has the focus.
789
931
  this.#viewport.addEventListener("blur", () => this.#region());
790
932
  attachProbe(this, () => ({
@@ -804,6 +946,7 @@ export class NovatrailCanvas extends HTMLElement {
804
946
  // is a TypeError without it.
805
947
  this.#adopt("demoState");
806
948
  this.#adopt("tracing");
949
+ this.#adopt("grid");
807
950
  this.#adopt("manifest");
808
951
  this.#adopt("media");
809
952
  // The history before the marks: they hold on to its strokes.
@@ -813,21 +956,22 @@ export class NovatrailCanvas extends HTMLElement {
813
956
  /** The element follows its own `lang`: its buttons are labelled in it (R07, R28). */
814
957
  static observedAttributes = ["lang", "tools-hidden"];
815
958
  /**
816
- * What a press of the primary button does: "pen" writes, as the element starts, and "eraser"
817
- * erases (R22). The learner switches it with the element's own buttons, which say a choice of
818
- * theirs with a `toolchange`, and the consumer may set it too, which says nothing (R28). A press
819
- * under way goes on as it began. A pen's eraser erases whatever the tool. A task without the
820
- * eraser has none of it: "eraser" is a TypeError then, and a new task without it puts the pen
821
- * back. A worked example has the pen alone, which writes nothing on its sheet (R42).
959
+ * What a press of the primary button does: "pen" writes, as the element starts, "eraser" erases
960
+ * (R22), and "hand" moves the sheet, under any pointer (R88). The learner switches it with the
961
+ * element's own buttons, which say a choice of theirs with a `toolchange`, and the consumer may
962
+ * set it too, which says nothing (R28). A press under way goes on as it began. A pen's eraser
963
+ * erases whatever the tool but the hand. A task without the eraser has none of it: "eraser" is a
964
+ * TypeError then, and a new task without it puts the pen back. Every sheet the learner writes on
965
+ * has the hand. A worked example has the pen alone, which writes nothing on its sheet (R42).
822
966
  */
823
967
  get tool() {
824
968
  return this.#tool;
825
969
  }
826
970
  set tool(tool) {
827
971
  if (!isTool(tool)) {
828
- throw new TypeError(`the tool of <${TAG}> is "pen" or "eraser", not ${JSON.stringify(tool)}`);
972
+ throw new TypeError(`the tool of <${TAG}> is "pen", "eraser" or "hand", not ${JSON.stringify(tool)}`);
829
973
  }
830
- if (!this.#shownTemplate.tools.includes(tool)) {
974
+ if (!this.#allows(tool)) {
831
975
  const shown = this.#example === undefined ? "task" : "worked example";
832
976
  throw new TypeError(`the ${shown} of <${TAG}> allows no ${tool}`);
833
977
  }
@@ -878,8 +1022,8 @@ export class NovatrailCanvas extends HTMLElement {
878
1022
  * another replaces it, its grid and its statement apart, as a task does.
879
1023
  *
880
1024
  * On a worked example's sheet the learner does not write: the canvas takes no input, and a finger
881
- * or a pen there scrolls the sheet as the browser scrolls the statement. Its row has no tools of
882
- * writing and is named a worked example's. `task`, `history` other than the empty one and
1025
+ * or a pen there scrolls the sheet as the browser scrolls the statement. It has no bar: its row
1026
+ * holds Next and Demo, and its region is named a worked example's. `task`, `history` other than the empty one and
883
1027
  * `marks` are TypeErrors, and so is an eraser: the tool is the pen alone, and `exportWork()` and
884
1028
  * `filled` give null. The next segment of a lesson is a new element (R20).
885
1029
  *
@@ -946,6 +1090,8 @@ export class NovatrailCanvas extends HTMLElement {
946
1090
  this.#leaveTracing(false);
947
1091
  this.#paper = undefined;
948
1092
  this.#tracing = undefined;
1093
+ this.#reading = undefined;
1094
+ this.#tracingPaper.reading = undefined;
949
1095
  this.#tracingPaper.show(undefined, () => { });
950
1096
  this.#whole = false;
951
1097
  this.#present(NO_TASK);
@@ -967,8 +1113,13 @@ export class NovatrailCanvas extends HTMLElement {
967
1113
  return;
968
1114
  }
969
1115
  this.#leaveTracing(false);
1116
+ // A new task from paper comes on dots; another crop in its place keeps the learner's grid.
1117
+ if (this.#paper === undefined)
1118
+ this.#paperGrid = PAPER_GRIDS[0];
970
1119
  this.#paper = paper;
971
1120
  this.#tracing = TRACING_START;
1121
+ this.#reading = undefined;
1122
+ this.#tracingPaper.reading = undefined;
972
1123
  this.#tracingPaper.show(statement, () => this.#sized());
973
1124
  this.#whole = true;
974
1125
  this.#present(PAPER_TEMPLATE);
@@ -999,9 +1150,28 @@ export class NovatrailCanvas extends HTMLElement {
999
1150
  return;
1000
1151
  this.#tracing = checked;
1001
1152
  this.#replace();
1153
+ this.#regrow();
1002
1154
  this.#refresh();
1003
1155
  this.#request();
1004
1156
  }
1157
+ /**
1158
+ * The reading of the task from paper's statement in clean print (R89): `undefined` offers no
1159
+ * "Recognise"; `"ready"` offers it, and its press sends a `tracingread`; `"busy"` waits; `"done"`
1160
+ * holds the statements, which take the crop's place for the learner who asked, till "Original".
1161
+ * Frozen; given without a task from paper, or not a reading, it is a TypeError.
1162
+ */
1163
+ get reading() {
1164
+ return this.#reading;
1165
+ }
1166
+ set reading(reading) {
1167
+ if (reading !== undefined && this.#paper === undefined) {
1168
+ throw new TypeError(`<${TAG}> shows no task from paper: the reading is given after the paper`);
1169
+ }
1170
+ const checked = reading === undefined ? undefined : readingOf(reading);
1171
+ this.#reading = checked;
1172
+ this.#tracingPaper.reading = checked;
1173
+ this.#request();
1174
+ }
1005
1175
  /**
1006
1176
  * How far the learner has gone through the worked example's demo (R42): `opened`, how many of
1007
1177
  * its parts are open, from the first, and `hidden`, whether the whole demo is hidden — frozen,
@@ -1075,6 +1245,31 @@ export class NovatrailCanvas extends HTMLElement {
1075
1245
  }
1076
1246
  this.#pictures.media = media;
1077
1247
  }
1248
+ /**
1249
+ * The grid of the task from paper's sheet (R88): `undefined` without a task from paper, and
1250
+ * "dots" as one comes. The learner turns it by the element's button, which a `gridchange`
1251
+ * tells; the consumer keeps it and gives it back, which tells nothing. A grid given before the
1252
+ * task from paper is a TypeError, and so is one not of `PaperGrid`; `undefined` changes nothing.
1253
+ */
1254
+ get grid() {
1255
+ return this.#paper === undefined ? undefined : this.#paperGrid;
1256
+ }
1257
+ set grid(grid) {
1258
+ if (grid === undefined)
1259
+ return;
1260
+ if (!isPaperGrid(grid)) {
1261
+ const grids = PAPER_GRIDS.map((each) => JSON.stringify(each)).join(", ");
1262
+ throw new TypeError(`the grid of <${TAG}> is one of ${grids}, not ${JSON.stringify(grid)}`);
1263
+ }
1264
+ if (this.#paper === undefined) {
1265
+ throw new TypeError(`<${TAG}> shows no task from paper: its grid is given after the paper`);
1266
+ }
1267
+ if (grid === this.#paperGrid)
1268
+ return;
1269
+ this.#paperGrid = grid;
1270
+ this.#drawGrid();
1271
+ this.#refresh();
1272
+ }
1078
1273
  /**
1079
1274
  * The history of writing (R22, R27): every stroke, erasing, clearing and undo on the sheet, in the
1080
1275
  * order they landed, at the sheet's time — frozen, and the same array until the next action. The
@@ -1138,6 +1333,7 @@ export class NovatrailCanvas extends HTMLElement {
1138
1333
  this.#writing = undefined;
1139
1334
  this.#equal = undefined;
1140
1335
  this.#replace();
1336
+ this.#regrow();
1141
1337
  this.#refresh();
1142
1338
  this.#request();
1143
1339
  }
@@ -1196,21 +1392,19 @@ export class NovatrailCanvas extends HTMLElement {
1196
1392
  this.#watchColours();
1197
1393
  this.#pictures.connect();
1198
1394
  this.#tracingPaper.connect();
1199
- // The page's pen mode, on every sheet of it (R29). The row shows a change once the event that
1200
- // made it is over: by then a pen that came down writes, and every row of the page waits for its
1201
- // stroke. The sheet tells the page whether it is written on, and hears when a stroke ends.
1395
+ // The page's pen mode, on every sheet of it (R29). The bar shows a change once the event that
1396
+ // made it is over: by then a pen that came down writes. The sheet tells the page whether it is written on, and hears when a stroke ends.
1202
1397
  const unwatch = PEN_MODE.watch(() => queueMicrotask(() => this.#refresh()));
1203
1398
  const unenlist = PEN_MODE.enlist(() => this.#writer() !== undefined);
1204
1399
  this.#unwatchPen = () => {
1205
1400
  unwatch();
1206
1401
  unenlist();
1207
1402
  };
1208
- // The page's zoom, on every sheet of it (R73): it may have changed while the element was away.
1209
- this.#zoomTo(PAGE_ZOOM.value);
1210
- this.#unwatchZoom = PAGE_ZOOM.watch(() => this.#zoomed());
1211
1403
  // A page that grows or shrinks scrolls nothing, and neither does a window of another size.
1212
1404
  this.#page.observe(document.documentElement);
1213
1405
  window.addEventListener("resize", this.#resized);
1406
+ window.addEventListener("resize", this.#rewindowed);
1407
+ this.#regrow();
1214
1408
  this.#refresh();
1215
1409
  this.#fit();
1216
1410
  }
@@ -1253,7 +1447,7 @@ export class NovatrailCanvas extends HTMLElement {
1253
1447
  /** The tracing paper's grip is named in the labels' language, and its tooltip says it (R87). */
1254
1448
  #nameGrip(tag = this.getAttribute("lang")) {
1255
1449
  const { lang, labels } = labelsFor(tag);
1256
- this.#tracingPaper.label(labels.moveTask, lang);
1450
+ this.#tracingPaper.label(labels, lang);
1257
1451
  }
1258
1452
  /**
1259
1453
  * Takes back the last action on the sheet — the last stroke written, the last erasing, or the
@@ -1300,14 +1494,15 @@ export class NovatrailCanvas extends HTMLElement {
1300
1494
  const tracing = this.#tracing;
1301
1495
  if (paper !== undefined && tracing !== undefined) {
1302
1496
  // The sheet as it is now: the crop's picture, read by now or soon, does not change it.
1303
- const strokes = this.#work.strokes.map((stroke) => this.#onSheet(stroke, tracing.at));
1497
+ const strokes = this.#work.strokes.map((stroke) => this.#onSheet(stroke, tracing));
1304
1498
  if (strokes.length === 0)
1305
1499
  return null;
1306
1500
  const written = this.#work;
1307
1501
  const onTracing = (id) => written.onTracing(id);
1308
1502
  const { size, gray } = await this.#tracingPaper.read;
1309
- const rect = tracingRect(tracing.at, size);
1310
- const work = paperWorkForCheck(strokes, { at: tracing.at, onTracing }, tracing, rect, gray, digit);
1503
+ const scale = scaleIn(tracing);
1504
+ const rect = tracingRect(tracing.at, scaled(size, scale));
1505
+ const work = paperWorkForCheck(strokes, { at: tracing.at, scale, onTracing }, tracing, rect, gray, digit);
1311
1506
  if (work === null)
1312
1507
  return null;
1313
1508
  return Object.freeze({
@@ -1331,9 +1526,11 @@ export class NovatrailCanvas extends HTMLElement {
1331
1526
  /**
1332
1527
  * The picture of the work, for the `picture` of a stored work that app puts on the server, a
1333
1528
  * method of the agreement with app (R83; R36 spec): the PNG of the strokes the surface shows,
1334
- * with no condition — the whole sheet, or the workbook's whole page with its draft, one pixel a
1335
- * unit, 1000 × 1400, whatever is filled and whether the work was sent to be checked or not; an
1336
- * empty surface, and a worked example's, is white. The strokes are those `exportWork()` takes, as
1529
+ * with no condition — the sheet's page, or the workbook's whole page with its draft, and the ink
1530
+ * past the page, right and down, with the tracing paper where it lies (R73): one pixel a unit,
1531
+ * 1000 × 1400 for the page alone, and scaled down past the page to hold no more pixels than it,
1532
+ * its size in its PNG's header —, whatever is filled and whether the work was sent to be checked
1533
+ * or not; an empty surface, and a worked example's, is white. The strokes are those `exportWork()` takes, as
1337
1534
  * the history has them: not the stroke under way, but those under an eraser not yet lifted. Each
1338
1535
  * is the outline the screen fills, black on white with no theme and no template — on a task from
1339
1536
  * paper the strokes of both layers, the tracing paper's where it lies, hidden or not, with the
@@ -1343,8 +1540,13 @@ export class NovatrailCanvas extends HTMLElement {
1343
1540
  * the 4 MiB of a stored work.
1344
1541
  */
1345
1542
  async exportPicture() {
1346
- // A pixel a unit: the ink is 3 px wide, as on a screen of a pixel a unit.
1347
- const { width, height } = SHEET;
1543
+ // A pixel a unit, the ink 3 px wide as on a screen of a pixel a unit, while the page and the ink
1544
+ // past it hold no more pixels than the page; scaled down to hold them past that (R83).
1545
+ const reach = this.#inkReach();
1546
+ const { width, height, scale } = pictureOf({
1547
+ maxX: reach.maxX + INK_REACH,
1548
+ maxY: reach.maxY + INK_REACH,
1549
+ });
1348
1550
  const canvas = document.createElement("canvas");
1349
1551
  canvas.width = width;
1350
1552
  canvas.height = height;
@@ -1358,14 +1560,12 @@ export class NovatrailCanvas extends HTMLElement {
1358
1560
  const strokes = this.#work.strokes;
1359
1561
  const work = this.#work;
1360
1562
  for (const stroke of strokes) {
1361
- if (tracing !== undefined && work.onTracing(stroke.id)) {
1362
- context.setTransform(1, 0, 0, 1, tracing.at[0], tracing.at[1]);
1363
- context.fill(this.#finished(stroke).path);
1364
- context.setTransform(1, 0, 0, 1, 0, 0);
1365
- }
1366
- else {
1367
- context.fill(this.#finished(stroke).path);
1368
- }
1563
+ const traced = tracing !== undefined && work.onTracing(stroke.id);
1564
+ const [x, y] = traced ? tracing.at : [0, 0];
1565
+ // A stroke of the tracing paper is as large as the paper's scale draws it (R89).
1566
+ const by = traced ? scale * scaleIn(tracing) : scale;
1567
+ context.setTransform(by, 0, 0, by, x * scale, y * scale);
1568
+ context.fill(this.#finished(stroke).path);
1369
1569
  }
1370
1570
  const { data } = context.getImageData(0, 0, width, height);
1371
1571
  // The canvas's memory goes at once, not at a collection: WebKit caps what all canvases hold.
@@ -1376,17 +1576,17 @@ export class NovatrailCanvas extends HTMLElement {
1376
1576
  const gray = new Uint8Array(width * height);
1377
1577
  for (let at = 0; at < gray.length; at++)
1378
1578
  gray[at] = data[4 * at];
1379
- // A task from paper's crop lies over it where the tracing paper lies, shown or hidden, a pixel a
1380
- // unit, as the crop of the work has it (R87).
1579
+ // A task from paper's crop lies over it where the tracing paper lies, shown or hidden, at the
1580
+ // picture's scale, as the crop of the work has it (R87).
1381
1581
  if (tracing !== undefined) {
1382
1582
  const { size, gray: picture } = await this.#tracingPaper.read;
1383
1583
  if (picture !== null) {
1384
- const rect = tracingRect(tracing.at, size);
1584
+ const rect = tracingRect(tracing.at, scaled(size, scaleIn(tracing)));
1385
1585
  layOver(gray, width, picture, {
1386
- left: rect.minX,
1387
- top: rect.minY,
1388
- right: rect.maxX,
1389
- bottom: rect.maxY,
1586
+ left: rect.minX * scale,
1587
+ top: rect.minY * scale,
1588
+ right: rect.maxX * scale,
1589
+ bottom: rect.maxY * scale,
1390
1590
  });
1391
1591
  }
1392
1592
  }
@@ -1403,13 +1603,13 @@ export class NovatrailCanvas extends HTMLElement {
1403
1603
  this.#latchAcross = undefined;
1404
1604
  this.#unwatchPen?.();
1405
1605
  this.#unwatchPen = undefined;
1406
- this.#unwatchZoom?.();
1407
- this.#unwatchZoom = undefined;
1606
+ this.#endPan();
1408
1607
  this.#page.disconnect();
1409
1608
  this.#ported.disconnect();
1410
1609
  this.#port = null;
1411
1610
  this.#tools.disconnect();
1412
1611
  window.removeEventListener("resize", this.#resized);
1612
+ window.removeEventListener("resize", this.#rewindowed);
1413
1613
  // A stroke that ended here may be the one the other rows of the page waited for.
1414
1614
  PEN_MODE.settle();
1415
1615
  this.#pictures.disconnect();
@@ -1467,10 +1667,17 @@ export class NovatrailCanvas extends HTMLElement {
1467
1667
  this.#statement.show(template.statement);
1468
1668
  const parts = [...template.statement, ...(this.#example?.demo ?? [])];
1469
1669
  this.#pictures.name(parts.flatMap((part) => ("picture" in part ? [part.picture] : [])));
1470
- if (!template.tools.includes(this.#tool))
1670
+ if (!this.#allows(this.#tool))
1471
1671
  this.#tool = "pen";
1672
+ this.#regrow();
1472
1673
  this.#refresh();
1473
1674
  }
1675
+ /** Whether the sheet shown has a tool: the task's, and the hand on every sheet written on (R88). */
1676
+ #allows(tool) {
1677
+ if (tool === HAND)
1678
+ return this.#example === undefined;
1679
+ return this.#shownTemplate.tools.includes(tool);
1680
+ }
1474
1681
  /**
1475
1682
  * Whether the element may show a worked example now (R42): not while it shows a task, not on a
1476
1683
  * sheet the learner has written on, and not while a stroke or an erasing is under way, which
@@ -1497,8 +1704,7 @@ export class NovatrailCanvas extends HTMLElement {
1497
1704
  */
1498
1705
  #lay(template) {
1499
1706
  const workbook = isWorkbook(template);
1500
- this.#grid.setAttribute("d", workbook ? "" : gridPath(template.grid));
1501
- this.#grid.classList.toggle("dots", !workbook && template.grid.kind === "dots");
1707
+ this.#drawGrid();
1502
1708
  write(this.#template, "aria-hidden", workbook ? null : "true");
1503
1709
  write(this.#template, "role", workbook ? "none" : null);
1504
1710
  this.#lines.replaceChildren(...(workbook ? template.page.items.map(itemOf) : []));
@@ -1593,7 +1799,7 @@ export class NovatrailCanvas extends HTMLElement {
1593
1799
  return this.#work.history.flatMap((event) => {
1594
1800
  if (event.kind !== "write")
1595
1801
  return [];
1596
- return [tracing === undefined ? event.stroke : this.#onSheet(event.stroke, tracing.at)];
1802
+ return [tracing === undefined ? event.stroke : this.#onSheet(event.stroke, tracing)];
1597
1803
  });
1598
1804
  }
1599
1805
  /**
@@ -1606,7 +1812,11 @@ export class NovatrailCanvas extends HTMLElement {
1606
1812
  const work = this.#work;
1607
1813
  const paper = tracing === undefined
1608
1814
  ? undefined
1609
- : { at: tracing.at, onTracing: (id) => work.onTracing(id) };
1815
+ : {
1816
+ at: tracing.at,
1817
+ scale: scaleIn(tracing),
1818
+ onTracing: (id) => work.onTracing(id),
1819
+ };
1610
1820
  const places = placesOf(given, this.#known(), cells, undefined, paper);
1611
1821
  return given.marks.flatMap(({ name }, n) => {
1612
1822
  const placed = places[n];
@@ -1663,6 +1873,18 @@ export class NovatrailCanvas extends HTMLElement {
1663
1873
  // was, as on a lost capture.
1664
1874
  this.#recorder.end(event.pointerId);
1665
1875
  this.#eraser.end(event.pointerId);
1876
+ // The hand moves the sheet under a pen, a finger or a mouse alike, and writes nothing: one
1877
+ // pointer at a time, and the others do nothing while it moves (R88).
1878
+ if (this.#tool === HAND) {
1879
+ if (this.#pan !== undefined)
1880
+ return;
1881
+ this.#pan = { pointerId: event.pointerId, x: event.clientX, y: event.clientY };
1882
+ this.#latch = undefined;
1883
+ this.#latchAcross = undefined;
1884
+ this.#sheet.classList.add("panning");
1885
+ this.#capture(event.pointerId);
1886
+ return;
1887
+ }
1666
1888
  const writes = this.#hands.down(contactOf(event));
1667
1889
  // The canvas holds on to every pointer that comes down on it until it lifts, writing or not: its
1668
1890
  // moves and its lift come here, so that a stroke goes on beyond the canvas, two fingers scroll,
@@ -1680,20 +1902,25 @@ export class NovatrailCanvas extends HTMLElement {
1680
1902
  // points from its corner; one begun elsewhere, on the sheet (R87).
1681
1903
  const tracing = this.#tracing;
1682
1904
  const size = this.#tracingPaper.size;
1905
+ const scale = tracing === undefined ? 1 : scaleIn(tracing);
1683
1906
  const traced = tracing !== undefined &&
1684
1907
  !tracing.hidden &&
1685
1908
  this.#tracingPaper.ready &&
1686
- onTracing(onSheetSample, tracing.at, size);
1909
+ onTracing(onSheetSample, tracing.at, scaled(size, scale));
1910
+ // A press on the sheet lets the tracing paper go: its frame and bar of scale leave (R89).
1911
+ this.#tracingPaper.letGo();
1687
1912
  const layer = traced ? "tracing" : undefined;
1688
1913
  if (erases)
1689
1914
  this.#eraseOn = tracing === undefined ? undefined : (layer ?? "sheet");
1690
1915
  else
1691
1916
  this.#writeOn = layer;
1692
1917
  const sample = traced && tracing !== undefined
1693
- ? { ...onSheetSample, ...toTracing(onSheetSample, tracing.at, size) }
1918
+ ? { ...onSheetSample, ...toTracing(onSheetSample, tracing.at, size, scale) }
1694
1919
  : onSheetSample;
1920
+ // On the tracing paper the eraser reaches as far on the screen, in the paper's own units.
1921
+ const reach = traced ? ERASER_RADIUS_PX / screen.k / scale : ERASER_RADIUS_PX / screen.k;
1695
1922
  const began = erases
1696
- ? this.#eraser.down(sample, ERASER_RADIUS_PX / screen.k + INK_REACH)
1923
+ ? this.#eraser.down(sample, reach + INK_REACH)
1697
1924
  : this.#recorder.down(sample);
1698
1925
  if (began)
1699
1926
  this.#request();
@@ -1708,6 +1935,14 @@ export class NovatrailCanvas extends HTMLElement {
1708
1935
  }
1709
1936
  }
1710
1937
  #move(event) {
1938
+ // The sheet goes with the hand, as with two fingers.
1939
+ const pan = this.#pan;
1940
+ if (pan !== undefined && pan.pointerId === event.pointerId) {
1941
+ this.#scroll(event.clientX - pan.x, event.clientY - pan.y, false);
1942
+ this.#pan = { pointerId: pan.pointerId, x: event.clientX, y: event.clientY };
1943
+ this.#flush();
1944
+ return;
1945
+ }
1711
1946
  // A pointer the hands did not see come down, such as a mouse or a pen hovering, does nothing,
1712
1947
  // and reads no layout.
1713
1948
  if (!this.#hands.knows(event.pointerId))
@@ -1752,11 +1987,12 @@ export class NovatrailCanvas extends HTMLElement {
1752
1987
  this.#lifted(event.pointerId);
1753
1988
  }
1754
1989
  /**
1755
- * A pointer lifted, or the device or the page took it from the sheet: the hands forget it, a
1756
- * gesture that ended lets go of what it scrolled, and the finger's button may come or go now, on
1757
- * this row and on the others of the page (R29).
1990
+ * A pointer lifted, or the device or the page took it from the sheet: the hands forget it, and a
1991
+ * gesture that ended, or the hand's move, lets go of what it scrolled (R29; R88).
1758
1992
  */
1759
1993
  #lifted(pointerId) {
1994
+ if (this.#pan?.pointerId === pointerId)
1995
+ this.#endPan();
1760
1996
  this.#hands.lift(pointerId);
1761
1997
  if (!this.#hands.scrolling) {
1762
1998
  this.#latch = undefined;
@@ -1765,6 +2001,15 @@ export class NovatrailCanvas extends HTMLElement {
1765
2001
  this.#refresh();
1766
2002
  PEN_MODE.settle();
1767
2003
  }
2004
+ /** The hand's move ends, and lets go of what it scrolled. */
2005
+ #endPan() {
2006
+ if (this.#pan === undefined)
2007
+ return;
2008
+ this.#pan = undefined;
2009
+ this.#sheet.classList.remove("panning");
2010
+ this.#latch = undefined;
2011
+ this.#latchAcross = undefined;
2012
+ }
1768
2013
  /** The pointer that writes or erases now, if one does: the recorder's or the eraser's. */
1769
2014
  #writer() {
1770
2015
  return this.#recorder.pointer ?? this.#eraser.pointer;
@@ -1795,7 +2040,7 @@ export class NovatrailCanvas extends HTMLElement {
1795
2040
  const point = toSheet(screen, event.clientX - screen.left, event.clientY - screen.top);
1796
2041
  const tracing = this.#tracing;
1797
2042
  const { x, y } = layer === "tracing" && tracing !== undefined
1798
- ? toTracing(point, tracing.at, this.#tracingPaper.size)
2043
+ ? toTracing(point, tracing.at, this.#tracingPaper.size, scaleIn(tracing))
1799
2044
  : point;
1800
2045
  return {
1801
2046
  pointerId: event.pointerId,
@@ -1821,7 +2066,7 @@ export class NovatrailCanvas extends HTMLElement {
1821
2066
  const sheet = this.#sheet.getBoundingClientRect();
1822
2067
  if (canvas.width <= 0 || sheet.width <= 0)
1823
2068
  return undefined;
1824
- const k = scaleFor(sheet.width);
2069
+ const k = scaleFor(sheet.width, this.#extent.width);
1825
2070
  const vx = (canvas.left - sheet.left) / k;
1826
2071
  const vy = (canvas.top - sheet.top) / k;
1827
2072
  const port = clientBoxOf(this.#viewport);
@@ -1836,8 +2081,7 @@ export class NovatrailCanvas extends HTMLElement {
1836
2081
  }
1837
2082
  /**
1838
2083
  * The sheet's top in the container's content, in CSS pixels as laid out: under the statement —
1839
- * or, along `x`, its left: its margin in the middle of a wide container, and none once it is
1840
- * wider (R73).
2084
+ * or, along `x`, its left (R73).
1841
2085
  */
1842
2086
  #sheetEdge(axis) {
1843
2087
  const port = clientBoxOf(this.#viewport);
@@ -1859,45 +2103,12 @@ export class NovatrailCanvas extends HTMLElement {
1859
2103
  this.#request();
1860
2104
  }
1861
2105
  /**
1862
- * Zoom in or Zoom out was pressed (R73): the page's zoom goes a step larger or smaller, and every
1863
- * sheet of the page is laid out by it — but not while a pointer writes or erases on one of them,
1864
- * for nothing moves under it.
1865
- */
1866
- #zoomBy(larger) {
1867
- if (!PEN_MODE.writing)
1868
- PAGE_ZOOM.step(larger);
1869
- }
1870
- /**
1871
- * The page's zoom has changed (R73): the sheet is laid out by it at once, its top left corner in
1872
- * sight staying where it was on the sheet, and the row shows what the zoom can do now.
1873
- */
1874
- #zoomed() {
1875
- if (!this.#zoomTo(PAGE_ZOOM.value))
1876
- return;
1877
- this.#layout();
1878
- this.#refresh();
1879
- }
1880
- /**
1881
- * The column and the container as wide as a zoom asks, and whether that is another than the
1882
- * last: the column widens with the sheet, and the container scrolls it across while the zoom is
1883
- * beyond the fit (R73).
1884
- */
1885
- #zoomTo(zoom) {
1886
- if (zoom === this.#zoom)
1887
- return false;
1888
- this.#zoom = zoom;
1889
- this.#column.style.setProperty("--zoom", String(zoom));
1890
- this.#viewport.classList.toggle("zoomed", zoom > 1);
1891
- this.#keepDirection();
1892
- return true;
1893
- }
1894
- /**
1895
- * The statement and a demo's parts keep the element's own direction while the zoomed container
1896
- * runs left to right: the direction the element computes, by an attribute or by a style, as the
1897
- * last layout read it (R73).
2106
+ * The statement and a demo's parts keep the element's own direction while the container runs
2107
+ * left to right: the direction the element computes, by an attribute or by a style, as the last
2108
+ * layout read it (R73).
1898
2109
  */
1899
2110
  #keepDirection() {
1900
- if (this.#zoom <= 1 || !this.isConnected)
2111
+ if (!this.isConnected)
1901
2112
  return;
1902
2113
  const direction = getComputedStyle(this).direction;
1903
2114
  if (this.#column.style.getPropertyValue("--direction") !== direction) {
@@ -1949,10 +2160,9 @@ export class NovatrailCanvas extends HTMLElement {
1949
2160
  return within ? room.top + room.offset : Number.NEGATIVE_INFINITY;
1950
2161
  }
1951
2162
  /**
1952
- * Two fingers moved right on the screen by `dx` CSS pixels and down it by `dy` (R29), and what
1953
- * they scroll goes with them. The gesture's first step down chooses what it scrolls down, for the
1954
- * whole gesture, and its first step across, while the sheet is zoomed, what it scrolls across
1955
- * (R73): the sheet's own container if it can go that way, or else the nearest ancestor of the
2163
+ * Two fingers, or the hand, moved right on the screen by `dx` CSS pixels and down it by `dy`
2164
+ * (R29; R88), and what they scroll goes with them. The gesture's first step down chooses what it
2165
+ * scrolls down, for the whole gesture, and its first step across what it scrolls across (R73): the sheet's own container if it can go that way, or else the nearest ancestor of the
1956
2166
  * element that scrolls and can, or else the page. A container at its end hands the scroll on at
1957
2167
  * the next gesture, not within this one. The steps of an event add up, and its end scrolls them
1958
2168
  * at once.
@@ -1966,7 +2176,7 @@ export class NovatrailCanvas extends HTMLElement {
1966
2176
  if (dy !== 0 && this.#latch === undefined)
1967
2177
  this.#latch = this.#scrollerFor(dy < 0) ?? null;
1968
2178
  if (dx !== 0 && this.#latchAcross === undefined) {
1969
- this.#latchAcross = this.#zoom > 1 ? (this.#scrollerFor(dx < 0, "x") ?? null) : null;
2179
+ this.#latchAcross = this.#scrollerFor(dx < 0, "x") ?? null;
1970
2180
  }
1971
2181
  if (this.#latch)
1972
2182
  this.#latch.rest -= dy / this.#latch.scale;
@@ -2023,7 +2233,7 @@ export class NovatrailCanvas extends HTMLElement {
2023
2233
  /**
2024
2234
  * The stage takes the visible part of the sheet, and the canvas a pixel of its buffer for each
2025
2235
  * device pixel: its size on the screen times the density (R18). The layers follow in the same
2026
- * frame. However large the zoom, the canvas is no larger than the container (R73).
2236
+ * frame. However far the sheet goes, the canvas is no larger than the container (R73).
2027
2237
  */
2028
2238
  #layout() {
2029
2239
  // The content of a new size, or the container, may overflow it now, or no more.
@@ -2031,12 +2241,15 @@ export class NovatrailCanvas extends HTMLElement {
2031
2241
  const area = this.#area;
2032
2242
  if (area === undefined || area.width === 0)
2033
2243
  return;
2034
- // The column is as wide as the container up to the cap, times the page's zoom, and the stage
2035
- // as tall and as wide as the visible part of the sheet.
2036
- const k = fitScale(area.width, this.#zoom);
2244
+ // The page is as wide as the container up to the cap, the column as wide as the sheet goes, by
2245
+ // the style, and the stage as tall and as wide as the visible part of the sheet.
2246
+ const k = fitScale(area.width);
2247
+ const extent = this.#extent;
2248
+ this.#stage.style.width = `${Math.min(area.width, extent.width * k)}px`;
2249
+ this.#stage.style.height = `${Math.min(area.height, extent.height * k)}px`;
2037
2250
  const sheetAt = this.#sheetEdge("y");
2038
2251
  const sheetAtX = this.#sheetEdge("x");
2039
- // A new width or zoom scales the sheet, and a statement of a new height moves it: the top left
2252
+ // A new width scales the sheet, and a statement of a new height moves it: the top left
2040
2253
  // corner of the visible part stays where it was on the sheet, unless the sheet's top, or its
2041
2254
  // left, is in sight. A new height of the container alone moves neither, and a scroll under way
2042
2255
  // goes on.
@@ -2049,8 +2262,6 @@ export class NovatrailCanvas extends HTMLElement {
2049
2262
  this.#sheetAt = sheetAt;
2050
2263
  this.#sheetAtX = sheetAtX;
2051
2264
  this.#keepDirection();
2052
- this.#stage.style.width = `${Math.min(area.width, SHEET.width * k)}px`;
2053
- this.#stage.style.height = `${Math.min(area.height, SHEET.height * k)}px`;
2054
2265
  const onScreen = this.#canvas.getBoundingClientRect();
2055
2266
  const width = Math.round(onScreen.width * devicePixelRatio);
2056
2267
  const height = Math.round(onScreen.height * devicePixelRatio);
@@ -2062,6 +2273,89 @@ export class NovatrailCanvas extends HTMLElement {
2062
2273
  this.#canvas.height = height;
2063
2274
  }
2064
2275
  this.#draw();
2276
+ // The sheet sized anew may overflow the container now, or no more.
2277
+ this.#region();
2278
+ }
2279
+ /**
2280
+ * How far the sheet goes (R73): past the page, the ink and the tracing paper where it lies, by
2281
+ * one view of the window more, at the window's own fit, within the reach. A worked example's
2282
+ * sheet is its page alone. The window's view and not the container's: the sheet is sized by its
2283
+ * style, and a size that the container's observer gave would resize the container again while
2284
+ * the observer reports it, which the browser tells the window as a loop.
2285
+ */
2286
+ #reach() {
2287
+ if (this.#example !== undefined)
2288
+ return SHEET;
2289
+ const k = fitScale(innerWidth);
2290
+ return extentOf(this.#inkReach(), { width: innerWidth / k, height: innerHeight / k });
2291
+ }
2292
+ /** The right and the bottom of the sheet's ink and of the tracing paper, which counts whole. */
2293
+ #inkReach() {
2294
+ let maxX = 0;
2295
+ let maxY = 0;
2296
+ const tracing = this.#tracing;
2297
+ for (const stroke of this.#work.strokes) {
2298
+ // The tracing paper's strokes stay on it, and it counts whole.
2299
+ if (tracing !== undefined && this.#work.onTracing(stroke.id))
2300
+ continue;
2301
+ for (const { x, y } of stroke.points) {
2302
+ if (x > maxX)
2303
+ maxX = x;
2304
+ if (y > maxY)
2305
+ maxY = y;
2306
+ }
2307
+ }
2308
+ if (tracing !== undefined) {
2309
+ const rect = tracingRect(tracing.at, scaled(this.#tracingPaper.size, scaleIn(tracing)));
2310
+ maxX = Math.max(maxX, rect.maxX);
2311
+ maxY = Math.max(maxY, rect.maxY);
2312
+ }
2313
+ return { maxX, maxY };
2314
+ }
2315
+ /**
2316
+ * The ink, the tracing paper or the window went past the sheet's extent, or back: the sheet is
2317
+ * sized anew by its style — the column as wide as the page's fit times the extent's share of the
2318
+ * page, and the sheet in the extent's proportions —, and laid out (R73).
2319
+ */
2320
+ #regrow() {
2321
+ const extent = this.#reach();
2322
+ if (extent.width === this.#extent.width && extent.height === this.#extent.height)
2323
+ return;
2324
+ this.#extent = extent;
2325
+ this.#column.style.setProperty("--across", String(extent.width / SHEET.width));
2326
+ this.#sheet.style.aspectRatio = `${extent.width} / ${extent.height}`;
2327
+ this.#drawGrid();
2328
+ this.#layout();
2329
+ }
2330
+ /**
2331
+ * The template's grid over the whole sheet, as far as it goes (R73): the task's, or a task from
2332
+ * paper's that the learner turns, none on a blank one (R88); a workbook has its lines instead.
2333
+ */
2334
+ #drawGrid() {
2335
+ const template = this.#shownTemplate;
2336
+ const grid = isWorkbook(template)
2337
+ ? undefined
2338
+ : this.#paper === undefined
2339
+ ? template.grid
2340
+ : rulingsOf(this.#paperGrid);
2341
+ const { width, height } = this.#extent;
2342
+ const key = grid === undefined ? "" : `${grid.kind} ${grid.step} ${width} ${height}`;
2343
+ if (key === this.#gridDrawn)
2344
+ return;
2345
+ this.#gridDrawn = key;
2346
+ this.#grid.setAttribute("d", grid === undefined ? "" : gridPath(grid, this.#extent));
2347
+ this.#grid.classList.toggle("dots", grid?.kind === "dots");
2348
+ // A page of units is more than any padding at the smallest k.
2349
+ const band = SHEET.height;
2350
+ for (const [svg, top] of [
2351
+ [this.#above, -band],
2352
+ [this.#below, height],
2353
+ ]) {
2354
+ svg.setAttribute("viewBox", `0 ${top} ${width} ${band}`);
2355
+ const path = svg.firstElementChild;
2356
+ path?.setAttribute("d", grid === undefined ? "" : gridBand(grid, width, top, top + band));
2357
+ path?.classList.toggle("dots", grid?.kind === "dots");
2358
+ }
2065
2359
  }
2066
2360
  /** A new density — the window on another screen, the page zoomed — lays the canvas out anew. */
2067
2361
  #watchDensity() {
@@ -2092,6 +2386,7 @@ export class NovatrailCanvas extends HTMLElement {
2092
2386
  * in its order. A history given meanwhile is no action, and what it replaced is told of no more.
2093
2387
  */
2094
2388
  #changed() {
2389
+ this.#regrow();
2095
2390
  this.#request();
2096
2391
  // The boxes and the row before the event, and for an action a listener takes as well.
2097
2392
  this.#fill();
@@ -2120,13 +2415,26 @@ export class NovatrailCanvas extends HTMLElement {
2120
2415
  * back what the learner chose.
2121
2416
  */
2122
2417
  #choose(tool) {
2123
- if (tool === this.#tool || !this.#shownTemplate.tools.includes(tool))
2418
+ if (tool === this.#tool || !this.#allows(tool))
2124
2419
  return;
2125
2420
  this.#tool = tool;
2126
2421
  this.#refresh();
2127
2422
  const detail = Object.freeze({ tool });
2128
2423
  this.dispatchEvent(new CustomEvent(TOOL_CHANGE, { bubbles: true, composed: true, detail }));
2129
2424
  }
2425
+ /**
2426
+ * The learner turned the task from paper's grid with its button (R88): the next, round, and
2427
+ * whoever listens hears of it. A consumer that gives the grid follows it.
2428
+ */
2429
+ #turnGrid() {
2430
+ if (this.#paper === undefined)
2431
+ return;
2432
+ this.#paperGrid = nextGrid(this.#paperGrid);
2433
+ this.#drawGrid();
2434
+ this.#refresh();
2435
+ const detail = Object.freeze({ grid: this.#paperGrid });
2436
+ this.dispatchEvent(new CustomEvent(GRID_CHANGE, { bubbles: true, composed: true, detail }));
2437
+ }
2130
2438
  /**
2131
2439
  * The learner hid the tracing paper with the button atop the tools, or showed it again (R87): its
2132
2440
  * strokes go out of sight with it and stay in the history and in the work, and whoever listens
@@ -2153,13 +2461,66 @@ export class NovatrailCanvas extends HTMLElement {
2153
2461
  if (state === undefined)
2154
2462
  return to;
2155
2463
  this.#moveFrom ??= state;
2156
- const at = keptOn(to, this.#tracingPaper.size);
2464
+ const scale = scaleIn(state);
2465
+ const at = keptOn(to, scaled(this.#tracingPaper.size, scale));
2157
2466
  if (at[0] === state.at[0] && at[1] === state.at[1])
2158
2467
  return state.at;
2159
- this.#tracing = Object.freeze({ at, hidden: state.hidden });
2468
+ this.#tracing = Object.freeze({ at, hidden: state.hidden, scale });
2469
+ this.#regrow();
2160
2470
  this.#request();
2161
2471
  return at;
2162
2472
  }
2473
+ /** Ctrl or ⌘ with the wheel over the tracing paper in sight: a notch of its scale (R89). */
2474
+ #wheel(event) {
2475
+ if (!(event.ctrlKey || event.metaKey) || event.deltaY === 0)
2476
+ return;
2477
+ const tracing = this.#tracing;
2478
+ if (tracing === undefined || tracing.hidden || !this.#tracingPaper.ready)
2479
+ return;
2480
+ const screen = this.#view();
2481
+ if (screen === undefined)
2482
+ return;
2483
+ const point = toSheet(screen, event.clientX - screen.left, event.clientY - screen.top);
2484
+ const size = scaled(this.#tracingPaper.size, scaleIn(tracing));
2485
+ if (!onTracing(point, tracing.at, size))
2486
+ return;
2487
+ event.preventDefault();
2488
+ this.#tracingPaper.wheel(event.deltaY < 0);
2489
+ }
2490
+ /**
2491
+ * The learner scales the tracing paper by a corner, the bar of scale or the wheel (R89): to a
2492
+ * place and a scale, kept to the rule and to the sheet whole; its strokes scale with it, and the
2493
+ * marks on them too. The change tells of itself once it is over.
2494
+ */
2495
+ #resizeTracing(to, by) {
2496
+ const state = this.#tracing;
2497
+ if (state === undefined)
2498
+ return { at: to, scale: by };
2499
+ this.#moveFrom ??= state;
2500
+ const scale = tracingScaleOf(by);
2501
+ const at = keptOn(to, scaled(this.#tracingPaper.size, scale));
2502
+ const next = Object.freeze({ at, hidden: state.hidden, scale });
2503
+ if (sameTracing(state, next))
2504
+ return { at: state.at, scale: scaleIn(state) };
2505
+ this.#tracing = next;
2506
+ this.#regrow();
2507
+ this.#request();
2508
+ return { at, scale };
2509
+ }
2510
+ /**
2511
+ * "Fit" (R89): the tracing paper as wide as the window shows the sheet right of the bar of tools,
2512
+ * at the rule's place there, kept to the rule; down the window, centred, below the rule's top.
2513
+ */
2514
+ #fitTracing() {
2515
+ const screen = this.#view();
2516
+ if (screen === undefined)
2517
+ return;
2518
+ const { width, height } = this.#tracingPaper.size;
2519
+ const across = screen.width / screen.k;
2520
+ const down = screen.height / screen.k;
2521
+ const scale = tracingScaleOf((across - TRACING.at[0] - TRACING.at[1]) / width);
2522
+ this.#resizeTracing([screen.vx + TRACING.at[0], screen.vy + Math.max(TRACING.at[1], (down - height * scale) / 2)], scale);
2523
+ }
2163
2524
  /** The learner's move of the tracing paper is over: whoever listens hears of it, if it moved. */
2164
2525
  #tracingMoved() {
2165
2526
  const from = this.#moveFrom;
@@ -2202,8 +2563,13 @@ export class NovatrailCanvas extends HTMLElement {
2202
2563
  #sized() {
2203
2564
  const state = this.#tracing;
2204
2565
  const size = this.#tracingPaper.size;
2205
- if (state !== undefined && whollyOff(state.at, size)) {
2206
- this.#tracing = Object.freeze({ at: keptOn(state.at, size), hidden: state.hidden });
2566
+ const scale = state === undefined ? 1 : scaleIn(state);
2567
+ if (state !== undefined && whollyOff(state.at, scaled(size, scale))) {
2568
+ this.#tracing = Object.freeze({
2569
+ at: keptOn(state.at, scaled(size, scale)),
2570
+ hidden: state.hidden,
2571
+ scale,
2572
+ });
2207
2573
  this.#replace();
2208
2574
  }
2209
2575
  this.#request();
@@ -2214,17 +2580,23 @@ export class NovatrailCanvas extends HTMLElement {
2214
2580
  this.dispatchEvent(new CustomEvent(TRACING_CHANGE, { bubbles: true, composed: true, detail }));
2215
2581
  }
2216
2582
  /**
2217
- * A stroke where it lies on the sheet: one of the tracing paper's moved to where the paper lies,
2218
- * once for each place (R87); the sheet's as it is.
2583
+ * A stroke where it lies on the sheet: one of the tracing paper's moved to where the paper lies at
2584
+ * its scale, once for each place (R87; R89); the sheet's as it is.
2219
2585
  */
2220
- #onSheet(stroke, at) {
2586
+ #onSheet(stroke, tracing) {
2221
2587
  if (!this.#work.onTracing(stroke.id))
2222
2588
  return stroke;
2589
+ const { at } = tracing;
2590
+ const scale = scaleIn(tracing);
2223
2591
  const kept = this.#placed.get(stroke);
2224
- if (kept !== undefined && kept.at[0] === at[0] && kept.at[1] === at[1])
2592
+ if (kept !== undefined &&
2593
+ kept.at[0] === at[0] &&
2594
+ kept.at[1] === at[1] &&
2595
+ kept.scale === scale) {
2225
2596
  return kept.stroke;
2226
- const placed = onSheet(stroke, at);
2227
- this.#placed.set(stroke, { at, stroke: placed });
2597
+ }
2598
+ const placed = onSheet(stroke, at, scale);
2599
+ this.#placed.set(stroke, { at, scale, stroke: placed });
2228
2600
  return placed;
2229
2601
  }
2230
2602
  /**
@@ -2365,12 +2737,6 @@ export class NovatrailCanvas extends HTMLElement {
2365
2737
  * undo and clearing have anything to do (R28), and a worked example's demo (R42).
2366
2738
  */
2367
2739
  #refresh() {
2368
- // The finger's button comes and goes between the strokes of the whole page alone: a row that
2369
- // wraps would move this sheet, and the sheets below it, under the pen. It is there in pen mode,
2370
- // on a device that has touch (R29).
2371
- if (this.#writer() === undefined && !PEN_MODE.writing) {
2372
- this.#finger = PEN_MODE.on && navigator.maxTouchPoints > 0;
2373
- }
2374
2740
  const demo = this.#demoState;
2375
2741
  this.#tools.show({
2376
2742
  kind: this.#rowKind(),
@@ -2378,13 +2744,12 @@ export class NovatrailCanvas extends HTMLElement {
2378
2744
  tool: this.#tool,
2379
2745
  undoable: this.#work.undoable,
2380
2746
  clearable: this.#work.strokes.length > 0,
2381
- larger: PAGE_ZOOM.larger,
2382
- smaller: PAGE_ZOOM.smaller,
2383
- finger: this.#finger,
2384
2747
  opens: this.#nextPart() !== undefined,
2385
2748
  expanded: demo?.hidden !== true,
2386
2749
  traced: this.#tracing?.hidden !== true,
2750
+ grid: this.#paperGrid,
2387
2751
  });
2752
+ this.#sheet.classList.toggle("hand", this.#tool === HAND);
2388
2753
  this.#nameRegion();
2389
2754
  }
2390
2755
  /**
@@ -2393,14 +2758,14 @@ export class NovatrailCanvas extends HTMLElement {
2393
2758
  * scrolls by no key without (R90 spec; WebKit's bug 277290). Without a height of its own the
2394
2759
  * element scrolls with the page and has no stop of Tab, and neither has one whose task fits. A
2395
2760
  * container that holds the focus keeps all three till the focus leaves it, not the window (R33).
2396
- * Across, it scrolls while the sheet is zoomed, and an element without a height has a region
2397
- * then too, if its sheet is wider than it (R73); unzoomed, it hides what overflows across.
2761
+ * Across, it scrolls while the sheet is wider than it, and an element without a height has a
2762
+ * region then too (R73).
2398
2763
  */
2399
2764
  #region() {
2400
2765
  if (!this.isConnected)
2401
2766
  return;
2402
2767
  const viewport = this.#viewport;
2403
- const across = this.#zoom > 1 && overflowOf(viewport, "x") > EDGE;
2768
+ const across = overflowOf(viewport, "x") > EDGE;
2404
2769
  const focused = this.shadowRoot?.activeElement === viewport;
2405
2770
  const scrolls = overflowOf(viewport) > EDGE || across || focused;
2406
2771
  write(viewport, "tabindex", scrolls ? "0" : null);
@@ -2491,7 +2856,9 @@ export class NovatrailCanvas extends HTMLElement {
2491
2856
  return undefined;
2492
2857
  if (tracing === undefined || !work.onTracing(id))
2493
2858
  return this.#pointBoxOf(stroke);
2494
- return tracing.hidden ? undefined : boxOnSheet(this.#pointBoxOf(stroke), tracing.at);
2859
+ return tracing.hidden
2860
+ ? undefined
2861
+ : boxOnSheet(this.#pointBoxOf(stroke), tracing.at, scaleIn(tracing));
2495
2862
  };
2496
2863
  const half = 1 / screen.k;
2497
2864
  for (const mark of this.#shown) {
@@ -2503,8 +2870,8 @@ export class NovatrailCanvas extends HTMLElement {
2503
2870
  : shown && {
2504
2871
  minX: Math.max(shown.minX - MARK_PADDING, half),
2505
2872
  minY: Math.max(shown.minY - MARK_PADDING, half),
2506
- maxX: Math.min(shown.maxX + MARK_PADDING, SHEET.width - half),
2507
- maxY: Math.min(shown.maxY + MARK_PADDING, SHEET.height - half),
2873
+ maxX: Math.min(shown.maxX + MARK_PADDING, REACH.width - half),
2874
+ maxY: Math.min(shown.maxY + MARK_PADDING, REACH.height - half),
2508
2875
  };
2509
2876
  if (this.#writing === undefined || frame === null)
2510
2877
  mark.under = false;
@@ -2512,8 +2879,10 @@ export class NovatrailCanvas extends HTMLElement {
2512
2879
  // A frame that came or moved while the stroke was under way is checked against all of it.
2513
2880
  const points = sameBox(frame, mark.frame) ? fresh : this.#writing.stroke.points;
2514
2881
  // A stroke on the tracing paper holds its points from the paper's corner (R87).
2515
- const [dx, dy] = this.#writeOn === "tracing" ? (this.#tracing?.at ?? [0, 0]) : [0, 0];
2516
- mark.under = points.some((point) => near({ ...point, x: point.x + dx, y: point.y + dy }, frame, INK_REACH + half));
2882
+ const on = this.#writeOn === "tracing" ? this.#tracing : undefined;
2883
+ const [dx, dy] = on?.at ?? [0, 0];
2884
+ const by = on === undefined ? 1 : scaleIn(on);
2885
+ mark.under = points.some((point) => near({ ...point, x: point.x * by + dx, y: point.y * by + dy }, frame, INK_REACH + half));
2517
2886
  }
2518
2887
  mark.frame = frame;
2519
2888
  const drawn = frame === null
@@ -2615,15 +2984,16 @@ export class NovatrailCanvas extends HTMLElement {
2615
2984
  const tracing = this.#tracing;
2616
2985
  const work = this.#work;
2617
2986
  const shown = tracing !== undefined && !tracing.hidden;
2618
- const draw = (stroke, dx, dy) => {
2987
+ const draw = (stroke, dx, dy, by = 1) => {
2619
2988
  // The outline keeps within half the widest line of the points: twice that is out of sight.
2620
2989
  const box = this.#pointBoxOf(stroke);
2621
- if (box.maxY + dy + 2 * INK_REACH < screen.vy || box.minY + dy - 2 * INK_REACH > bottom)
2990
+ const reach = 2 * INK_REACH * by;
2991
+ if (box.maxY * by + dy + reach < screen.vy || box.minY * by + dy - reach > bottom)
2622
2992
  return;
2623
- if (box.maxX + dx + 2 * INK_REACH < screen.vx || box.minX + dx - 2 * INK_REACH > right)
2993
+ if (box.maxX * by + dx + reach < screen.vx || box.minX * by + dx - reach > right)
2624
2994
  return;
2625
2995
  const ink = this.#finished(stroke);
2626
- if (ink.bottom + dy >= screen.vy && ink.top + dy <= bottom)
2996
+ if (ink.bottom * by + dy >= screen.vy && ink.top * by + dy <= bottom)
2627
2997
  context.fill(ink.path);
2628
2998
  };
2629
2999
  context.setTransform(across, 0, 0, down, -screen.vx * across, -screen.vy * down);
@@ -2643,9 +3013,11 @@ export class NovatrailCanvas extends HTMLElement {
2643
3013
  if (!shown)
2644
3014
  return;
2645
3015
  const [dx, dy] = tracing.at;
2646
- context.setTransform(across, 0, 0, down, (dx - screen.vx) * across, (dy - screen.vy) * down);
3016
+ // The paper's strokes are as large as its scale draws it, from its corner (R89).
3017
+ const by = scaleIn(tracing);
3018
+ context.setTransform(across * by, 0, 0, down * by, (dx - screen.vx) * across, (dy - screen.vy) * down);
2647
3019
  for (const stroke of traced)
2648
- draw(stroke, dx, dy);
3020
+ draw(stroke, dx, dy, by);
2649
3021
  if (live !== undefined && liveTraced)
2650
3022
  context.fill(pathOf(this.#outline(live, false)));
2651
3023
  }
@@ -2875,7 +3247,8 @@ function parentOf(element) {
2875
3247
  /**
2876
3248
  * An element's client box on the screen — what it shows of its content, within its borders and
2877
3249
  * without its scroll bar — and how much the page scales it down the screen: 1 unless an ancestor
2878
- * transforms it. The sheet's container has one, and so has any ancestor Up and Down scroll (R33).
3250
+ * transforms it. The sheet's container has one, and so has any ancestor the fingers or
3251
+ * the hand scroll (R29; R88).
2879
3252
  */
2880
3253
  function clientBoxOf(element) {
2881
3254
  const box = element.getBoundingClientRect();