@altnovatrail/canvas 0.3.38 → 0.3.40

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.
Files changed (79) hide show
  1. package/lib/core/boxes.d.ts +7 -7
  2. package/lib/core/boxes.js +10 -10
  3. package/lib/core/clock.d.ts +5 -5
  4. package/lib/core/clock.js +5 -5
  5. package/lib/core/crop.d.ts +13 -13
  6. package/lib/core/crop.js +10 -10
  7. package/lib/core/eraser.d.ts +6 -6
  8. package/lib/core/eraser.js +6 -6
  9. package/lib/core/example.d.ts +6 -6
  10. package/lib/core/example.js +9 -9
  11. package/lib/core/fields.d.ts +1 -1
  12. package/lib/core/fields.js +1 -1
  13. package/lib/core/geometry.d.ts +6 -5
  14. package/lib/core/geometry.js +8 -6
  15. package/lib/core/grid.d.ts +3 -3
  16. package/lib/core/grid.js +3 -3
  17. package/lib/core/groups.d.ts +14 -14
  18. package/lib/core/groups.js +6 -6
  19. package/lib/core/hands.d.ts +24 -16
  20. package/lib/core/hands.js +66 -14
  21. package/lib/core/history.d.ts +9 -9
  22. package/lib/core/history.js +6 -6
  23. package/lib/core/index.js +8 -9
  24. package/lib/core/ink.js +3 -3
  25. package/lib/core/manifest.d.ts +3 -3
  26. package/lib/core/manifest.js +6 -6
  27. package/lib/core/marks.d.ts +39 -39
  28. package/lib/core/marks.js +34 -34
  29. package/lib/core/notation.d.ts +29 -0
  30. package/lib/core/notation.js +180 -0
  31. package/lib/core/outline.d.ts +3 -3
  32. package/lib/core/outline.js +6 -6
  33. package/lib/core/page.d.ts +7 -7
  34. package/lib/core/page.js +10 -10
  35. package/lib/core/png.d.ts +3 -3
  36. package/lib/core/png.js +3 -3
  37. package/lib/core/raster.d.ts +3 -3
  38. package/lib/core/raster.js +3 -3
  39. package/lib/core/recorder.d.ts +7 -7
  40. package/lib/core/recorder.js +7 -7
  41. package/lib/core/screen.d.ts +2 -2
  42. package/lib/core/screen.js +1 -1
  43. package/lib/core/sets.d.ts +1 -1
  44. package/lib/core/sets.js +1 -1
  45. package/lib/core/sheet.d.ts +3 -3
  46. package/lib/core/sheet.js +3 -3
  47. package/lib/core/submission.d.ts +24 -24
  48. package/lib/core/submission.js +21 -21
  49. package/lib/core/task.d.ts +17 -16
  50. package/lib/core/task.js +14 -13
  51. package/lib/core/tracing.d.ts +20 -20
  52. package/lib/core/tracing.js +20 -20
  53. package/lib/core/widths.d.ts +2 -2
  54. package/lib/core/widths.js +5 -5
  55. package/lib/core/work.d.ts +18 -18
  56. package/lib/core/work.js +21 -21
  57. package/lib/core/zoom.d.ts +34 -0
  58. package/lib/core/zoom.js +64 -0
  59. package/lib/element/icons.d.ts +19 -1
  60. package/lib/element/icons.js +24 -2
  61. package/lib/element/index.d.ts +87 -87
  62. package/lib/element/index.js +397 -295
  63. package/lib/element/labels.d.ts +21 -18
  64. package/lib/element/labels.js +15 -12
  65. package/lib/element/notation.d.ts +2 -0
  66. package/lib/element/notation.js +94 -0
  67. package/lib/element/parts.d.ts +2 -2
  68. package/lib/element/parts.js +6 -6
  69. package/lib/element/pictures.js +1 -1
  70. package/lib/element/probe.d.ts +2 -2
  71. package/lib/element/probe.js +3 -3
  72. package/lib/element/session.d.ts +3 -0
  73. package/lib/element/session.js +8 -4
  74. package/lib/element/statement.d.ts +2 -2
  75. package/lib/element/statement.js +6 -6
  76. package/lib/element/tools.d.ts +21 -18
  77. package/lib/element/tools.js +46 -30
  78. package/lib/element/tracing.js +58 -31
  79. package/package.json +3 -3
@@ -1,28 +1,30 @@
1
- // The element's own buttons (R28, R84): the tools the task allows — the pen and the eraser — and
2
- // the hand, which moves the sheet (R88), undo and clearing, on a vertical bar of glass at the left
3
- // edge of the element, as the interface mockup draws it (R148 spec). It is a toolbar as WAI-ARIA's
1
+ // The element's own buttons: the tools the task allows — the pen and the eraser — and
2
+ // the hand, which moves the sheet, undo and clearing, on a vertical bar of glass at the left
3
+ // edge of the element, as the interface mockup draws it (R28). It is a toolbar as WAI-ARIA's
4
4
  // Authoring Practices have one: one stop of Tab, the arrow keys up and down from button to button,
5
5
  // and the tools a group of radio buttons that the arrows go through without choosing one. Undo and
6
6
  // Clear with nothing to take back or to clear stay where the focus can reach them, marked
7
- // unavailable: a last undo from the keyboard leaves the focus where it was. The sheet has no
7
+ // unavailable: a last undo from the keyboard leaves the focus where it was. After a line, Zoom in
8
+ // and Zoom out step the page's zoom of the sheet by quarters from half its fit to twice it, each
9
+ // unavailable at its end, as a pinch of two fingers sets it between. The sheet has no
8
10
  // buttons that scroll it: the hand, two fingers or a finger in pen mode drag it, the wheel and the
9
- // keys scroll it (R84; R88; R90 spec). The buttons of the bar show an icon alone, of the set every
10
- // NovaTrail package of the interface draws from (R46; R78 spec): each is named by its label, in the
11
+ // keys scroll it. The buttons of the bar show an icon alone, of the set every
12
+ // NovaTrail package of the interface draws from: each is named by its label, in the
11
13
  // element's language (labels.ts), which only a screen reader reads, and shows it in a tooltip of
12
14
  // its own on the pointer's hover and on the keyboard's focus, which Escape dismisses and the
13
- // pointer can move onto (R90 spec; WCAG 1.4.13). The bar is named by the canvas kind's buttons: the
14
- // sheet's or the workbook's (R36), for the kind's own name is the scroll container's (R28). A
15
+ // pointer can move onto (WCAG 1.4.13). The bar is named by the canvas kind's buttons: the
16
+ // sheet's or the workbook's, for the kind's own name is the scroll container's. A
15
17
  // lesson's worked example has no bar: the learner does not write on its sheet, which scrolls as the
16
18
  // page does. Its demo's buttons, Next, which opens the next part, and Demo, a disclosure button
17
- // that hides the whole demo and shows it again, are actions, not tools (R42; R90 spec): each shows
19
+ // that hides the whole demo and shows it again, are actions, not tools: each shows
18
20
  // its label beside its icon, a stop of Tab of its own, in a row of glass at the bottom of the
19
21
  // element, and after a line the slot `actions`, where the consumer puts its own buttons — app's
20
- // Continue —, as the mockup has one row (R84; R36 spec). A task from paper's bar has one button
22
+ // Continue —, as the mockup has one row. A task from paper's bar has one button
21
23
  // more, atop the tools, after a line: "Hide the task" while its tracing paper is shown, its icon
22
24
  // filled, and "Show the task" while it is hidden — the name says the state, so the button is no
23
- // toggle button as well, which would say it twice (R87; R90 spec) —, and one last, after a line:
25
+ // toggle button as well, which would say it twice —, and one last, after a line:
24
26
  // the sheet's grid, its icon and its name the grid shown now, which a press turns to the next,
25
- // round — dots, lines, blank, squares (R88). A button that goes gives its stop of Tab and the focus
27
+ // round — dots, lines, blank, squares. A button that goes gives its stop of Tab and the focus
26
28
  // to the first button shown. This module is no entry point of the package.
27
29
  import { SVG, write } from "./attributes.js";
28
30
  import { ICONS, ROW } from "./icons.js";
@@ -43,13 +45,13 @@ export const TIP_GRACE_MS = 200;
43
45
  export class Tools {
44
46
  /**
45
47
  * What the element puts beside its scroll container: the band the bar stands in the middle of,
46
- * as wide as nothing, so that only the bar and its tooltip, which stand out of it, take a pointer,
47
- * and as the element does: a consumer's pointer-events: none stops them too (R20, R28).
48
+ * as wide as nothing, so that only the bar and its tooltip, which stand out of it, take a
49
+ * pointer, and as the element does: a consumer's pointer-events: none stops them too.
48
50
  */
49
51
  rail = document.createElement("div");
50
52
  /** The bar: a toolbar, named in the element's language. */
51
53
  element = document.createElement("div");
52
- /** A worked example's row: Next, Demo and the consumer's buttons in the slot `actions` (R84). */
54
+ /** A worked example's row: Next, Demo and the consumer's buttons in the slot `actions`. */
53
55
  row = document.createElement("div");
54
56
  #actions = document.createElement("slot");
55
57
  #beforeActions = separator();
@@ -57,7 +59,7 @@ export class Tools {
57
59
  tip = document.createElement("div");
58
60
  #next = plainButton("next");
59
61
  #demo = plainButton("demoShown");
60
- /** A task from paper's button atop the tools, and the line under it (R87). */
62
+ /** A task from paper's button atop the tools, and the line under it. */
61
63
  #task = plainButton("task");
62
64
  #afterTask = separator();
63
65
  #group = document.createElement("div");
@@ -66,12 +68,16 @@ export class Tools {
66
68
  #hand = radioButton("hand");
67
69
  #undo = plainButton("undo");
68
70
  #clear = plainButton("clear");
69
- /** A task from paper's grid, after a line (R88). */
71
+ /** The page's zoom of the sheet, after a line. */
72
+ #beforeZoom = separator();
73
+ #zoomIn = plainButton("zoomIn");
74
+ #zoomOut = plainButton("zoomOut");
75
+ /** A task from paper's grid, after a line. */
70
76
  #beforeGrid = separator();
71
77
  #grid = plainButton("gridDots");
72
78
  /**
73
79
  * The buttons with the keys of their labels, the row's and then the bar's in the order the arrow
74
- * keys go through them. A button is named only by its label (R46), so each is here with its key.
80
+ * keys go through them. A button is named only by its label, so each is here with its key.
75
81
  */
76
82
  #labelled = [
77
83
  [this.#next, "next"],
@@ -82,11 +88,13 @@ export class Tools {
82
88
  [this.#hand, "hand"],
83
89
  [this.#undo, "undo"],
84
90
  [this.#clear, "clear"],
91
+ [this.#zoomIn, "zoomIn"],
92
+ [this.#zoomOut, "zoomOut"],
85
93
  [this.#grid, "gridDots"],
86
94
  ];
87
95
  /**
88
96
  * The bar's buttons in the order the arrow keys go through them: each shows an icon alone, and a
89
- * tooltip. Next and Demo show their labels (R90 spec).
97
+ * tooltip. Next and Demo show their labels.
90
98
  */
91
99
  #buttons = this.#labelled
92
100
  .map(([button]) => button)
@@ -152,7 +160,7 @@ export class Tools {
152
160
  this.#group.className = "choice";
153
161
  this.#group.setAttribute("role", "radiogroup");
154
162
  this.#group.append(this.#pen, this.#eraser, this.#hand);
155
- this.element.append(this.#task, this.#afterTask, this.#group, this.#undo, this.#clear, this.#beforeGrid, this.#grid);
163
+ this.element.append(this.#task, this.#afterTask, this.#group, this.#undo, this.#clear, this.#beforeZoom, this.#zoomIn, this.#zoomOut, this.#beforeGrid, this.#grid);
156
164
  this.rail.append(this.element, this.row, this.tip);
157
165
  for (const button of this.#buttons)
158
166
  button.classList.add("icon");
@@ -183,6 +191,8 @@ export class Tools {
183
191
  };
184
192
  doing(this.#undo, actions.undo);
185
193
  doing(this.#clear, actions.clear);
194
+ doing(this.#zoomIn, () => actions.zoom(true));
195
+ doing(this.#zoomOut, () => actions.zoom(false));
186
196
  doing(this.#next, actions.next);
187
197
  this.#demo.addEventListener("click", () => actions.toggle());
188
198
  this.#grid.addEventListener("click", () => actions.turnGrid());
@@ -225,13 +235,13 @@ export class Tools {
225
235
  /**
226
236
  * The bar as the sheet now is. Only what has changed is written. A worked example has no bar, for
227
237
  * the learner does not write on its sheet, and its row has Next, unavailable while the demo is
228
- * hidden or open whole, and Demo, expanded while the demo is shown (R42). The tool in use shows its
238
+ * hidden or open whole, and Demo, expanded while the demo is shown. The tool in use shows its
229
239
  * icon filled, and Demo's icon points down while the demo is shown, and along the row while it is
230
- * hidden (R46). A task from paper's button atop the tools says what it does to the tracing paper,
231
- * and fills its icon while the paper is shown (R87), and its grid's button shows the grid (R88).
240
+ * hidden. A task from paper's button atop the tools says what it does to the tracing paper,
241
+ * and fills its icon while the paper is shown, and its grid's button shows the grid.
232
242
  */
233
243
  show(state) {
234
- const { kind, tools, tool, undoable, clearable, opens, expanded, traced, grid } = state;
244
+ const { kind, tools, tool, undoable, clearable, larger, smaller, opens, expanded, traced, grid, } = state;
235
245
  if (kind !== this.#kind) {
236
246
  this.#kind = kind;
237
247
  this.#name();
@@ -251,6 +261,9 @@ export class Tools {
251
261
  [this.#hand, writes],
252
262
  [this.#undo, writes],
253
263
  [this.#clear, writes],
264
+ [this.#beforeZoom, writes],
265
+ [this.#zoomIn, writes],
266
+ [this.#zoomOut, writes],
254
267
  [this.#beforeGrid, kind === "paper"],
255
268
  [this.#grid, kind === "paper"],
256
269
  ]);
@@ -259,6 +272,8 @@ export class Tools {
259
272
  write(this.#hand, "aria-checked", String(tool === "hand"));
260
273
  write(this.#undo, "aria-disabled", undoable ? null : "true");
261
274
  write(this.#clear, "aria-disabled", clearable ? null : "true");
275
+ write(this.#zoomIn, "aria-disabled", larger ? null : "true");
276
+ write(this.#zoomOut, "aria-disabled", smaller ? null : "true");
262
277
  write(this.#next, "aria-disabled", opens ? null : "true");
263
278
  write(this.#demo, "aria-expanded", String(expanded));
264
279
  draw(this.#pen, "pen", tool === "pen");
@@ -310,7 +325,7 @@ export class Tools {
310
325
  }
311
326
  /**
312
327
  * The name of a task from paper's button atop the tools, by the tracing paper's state, and its
313
- * tooltip's, should it show (R87).
328
+ * tooltip's, should it show.
314
329
  */
315
330
  #nameTask() {
316
331
  const { labels } = labelsFor(this.#lang ?? null);
@@ -322,7 +337,7 @@ export class Tools {
322
337
  if (this.#tipFor === this.#task)
323
338
  this.tip.textContent = name;
324
339
  }
325
- /** The name of a task from paper's grid button, by the grid shown, and its tooltip's (R88). */
340
+ /** The name of a task from paper's grid button, by the grid shown, and its tooltip's. */
326
341
  #nameGrid() {
327
342
  const { labels } = labelsFor(this.#lang ?? null);
328
343
  const label = this.#grid.lastElementChild;
@@ -372,7 +387,8 @@ export class Tools {
372
387
  * beside it at the bar's edge, unless Escape dismissed it: only what has changed is written.
373
388
  */
374
389
  #showTip() {
375
- // A button the pointer was over may have gone with no pointerleave: the focus's has its tooltip.
390
+ // A button the pointer was over may have gone with no pointerleave: the focus's has its
391
+ // tooltip.
376
392
  const wanted = [this.#hovered, this.#focused].find((button) => button && !button.hidden);
377
393
  if (this.#dismissed !== undefined && this.#dismissed !== wanted)
378
394
  this.#dismissed = undefined;
@@ -438,7 +454,7 @@ export class Tools {
438
454
  }
439
455
  /**
440
456
  * Buttons come or go, all of them at once, and then a button that went gives its stop of Tab and
441
- * the focus to the first button shown: the pen on a sheet, or a task from paper's button (R28). Till
457
+ * the focus to the first button shown: the pen on a sheet, or a task from paper's button. Till
442
458
  * a button has had the focus, the stop is the first button shown, whichever it is now. Nothing is
443
459
  * read or written while every button stays as it is: the bar is shown anew after every stroke.
444
460
  */
@@ -514,7 +530,7 @@ function radioButton(value) {
514
530
  }
515
531
  /**
516
532
  * A button: its icon, an SVG that says nothing — no title, hidden from a screen reader — and its
517
- * label, which names it (R46; R78 spec): on the bar, only a screen reader reads it (R84).
533
+ * label, which names it: on the bar, only a screen reader reads it.
518
534
  */
519
535
  export function plainButton(value) {
520
536
  const button = document.createElement("button");
@@ -533,7 +549,7 @@ export function plainButton(value) {
533
549
  /**
534
550
  * A value's icon on its button, filled or in outline, written only when it is another than the one
535
551
  * there: the icon's name stays on the SVG, as data. One mirrored in a row that runs right to left
536
- * says so by its class, which the style turns (R46).
552
+ * says so by its class, which the style turns.
537
553
  */
538
554
  export function draw(button, value, filled) {
539
555
  const icon = button.firstElementChild;
@@ -1,14 +1,14 @@
1
- // The tracing paper of a task from paper (R87): the task's crop over the dotted sheet, on a layer
1
+ // The tracing paper of a task from paper: the task's crop over the dotted sheet, on a layer
2
2
  // of its own between the author's demo and the learner's ink, in sheet units, so that it moves with
3
3
  // the sheet as it scrolls and zooms. The crop is multiplied over the sheet: the white of its paper
4
4
  // lets the dots and the strokes under it show, and its print stays dark. Its grip "Move the task",
5
5
  // a bar above its top edge, moves it by the pointer — a drag, kept to the sheet — and by the arrow
6
6
  // keys, a step at a time, Shift a leap (WCAG 2.1.1); a drag is the pointer's one way, as the sheet
7
- // moves under the hand (R90 spec). The grip's tooltip says its name on the hover of a pointer that
7
+ // moves under the hand. The grip's tooltip says its name on the hover of a pointer that
8
8
  // hovers and on the keyboard's focus, and Escape dismisses it, as the bar's do (WCAG 1.4.13). The
9
9
  // crop's picture is read once, to its grey pixels, for the crop of the work.
10
10
  //
11
- // Its scale (R89), as the mockup's `Zadacha-masshtab` has it: the grip's press, or its focus,
11
+ // Its scale, as the mockup's `Zadacha-masshtab` has it: the grip's press, or its focus,
12
12
  // chooses the paper — a blue frame round it with a handle at each corner, which a drag scales from
13
13
  // the corner across, and under it the bar of scale: smaller, the percentage, which sets it back to
14
14
  // its own size, larger, and fit to the window —; a press on the sheet lets it go. The bar's buttons
@@ -20,6 +20,7 @@ import { grayOf, LARGEST, SCALE, scaleOf, sizeOf, TRACING, } from "../core/traci
20
20
  import { SVG, write } from "./attributes.js";
21
21
  import { ICONS, ROW } from "./icons.js";
22
22
  import { say } from "./labels.js";
23
+ import { lineOf } from "./notation.js";
23
24
  import { draw, plainButton } from "./tools.js";
24
25
  /** The grip's size, CSS pixels: a target of 68 × 44 (WCAG 2.5.5), the bar above the paper's edge. */
25
26
  const GRIP = Object.freeze({ width: 68, height: 44, over: 29 });
@@ -55,9 +56,9 @@ export class TracingPaper {
55
56
  #signWords = document.createElement("span");
56
57
  /** Over the ink: the bar of scale under the paper chosen. */
57
58
  bar = document.createElement("div");
58
- #smaller = plainButton("zoomOut");
59
+ #smaller = plainButton("smaller");
59
60
  #percent = document.createElement("button");
60
- #larger = plainButton("zoomIn");
61
+ #larger = plainButton("larger");
61
62
  #fit = plainButton("fit");
62
63
  #mode = plainButton("recognise");
63
64
  #moves;
@@ -71,6 +72,13 @@ export class TracingPaper {
71
72
  #asked = false;
72
73
  /** The statements drawn, and the size they were fitted to: drawn again only when either changes. */
73
74
  #drawn = "";
75
+ /** The letters' size the paper's height gives the statements, before they are fitted. */
76
+ #full = 0;
77
+ /**
78
+ * The lines' sizes, which change when they are first laid out — the paper hidden when they were
79
+ * drawn, or the font not yet loaded — and when they are fitted: each time they are fitted again.
80
+ */
81
+ #lines = new ResizeObserver(() => this.#fitText());
74
82
  /** The paper on the stage, CSS pixels, as last placed. */
75
83
  #box = { width: 0, height: 0 };
76
84
  /** A corner's drag under way: its pointer, where it began, the paper then and the corner. */
@@ -291,8 +299,8 @@ export class TracingPaper {
291
299
  write(part, "lang", lang);
292
300
  write(this.bar, "aria-label", labels.scaleButtons);
293
301
  for (const [button, words] of [
294
- [this.#smaller, labels.zoomOut],
295
- [this.#larger, labels.zoomIn],
302
+ [this.#smaller, labels.smaller],
303
+ [this.#larger, labels.larger],
296
304
  [this.#fit, labels.fit],
297
305
  ]) {
298
306
  const label = button.querySelector(".label");
@@ -375,6 +383,8 @@ export class TracingPaper {
375
383
  /** The element left the page: the crop's address goes, and a drag or a tooltip with it. */
376
384
  disconnect() {
377
385
  this.#connected = false;
386
+ this.#lines.disconnect();
387
+ this.#drawn = "";
378
388
  this.#release();
379
389
  this.#drag = undefined;
380
390
  this.grip.classList.remove("dragging");
@@ -514,9 +524,9 @@ export class TracingPaper {
514
524
  };
515
525
  }
516
526
  /**
517
- * The scale a corner's drag gives, as the mockup's: the larger of the pointer's two moves outward,
518
- * each over the paper's own size on the screen, added to the scale it began at; the corner across
519
- * stays where it was.
527
+ * The scale a corner's drag gives, as the mockup's: the larger of the pointer's two moves
528
+ * outward, each over the paper's own size on the screen, added to the scale it began at; the
529
+ * corner across stays where it was.
520
530
  */
521
531
  #cornerMove(event) {
522
532
  const drag = this.#corner;
@@ -562,8 +572,8 @@ export class TracingPaper {
562
572
  }
563
573
  }
564
574
  /**
565
- * "Recognise" offers the reading, waits for it, and gives the photo back once the statements show;
566
- * statements that came show again with no new reading.
575
+ * "Recognise" offers the reading, waits for it, and gives the photo back once the statements
576
+ * show; statements that came show again with no new reading.
567
577
  */
568
578
  #pressMode() {
569
579
  const reading = this.#reading;
@@ -613,8 +623,9 @@ export class TracingPaper {
613
623
  this.#signWords.textContent = sign;
614
624
  }
615
625
  /**
616
- * The statements in place of the crop, a line each, "□" a dashed box: their letters as large as
617
- * the paper's height shares out among them, and smaller where the longest line would not fit.
626
+ * The statements in place of the crop, a line each, "□" a dashed box and a fraction built up
627
+ * (./notation.ts): their letters as large as the paper's height shares out among them, and
628
+ * smaller where the longest line, or the lines with their fractions, would not fit.
618
629
  */
619
630
  #drawText() {
620
631
  const { width, height } = this.#box;
@@ -627,25 +638,41 @@ export class TracingPaper {
627
638
  this.#text.replaceChildren(...statements.map((statement) => {
628
639
  const line = document.createElement("div");
629
640
  line.className = "line";
630
- for (const [n, piece] of statement.split("□").entries()) {
631
- if (n > 0) {
632
- const box = document.createElement("span");
633
- box.className = "slot";
634
- line.append(box);
635
- }
636
- if (piece !== "")
637
- line.append(piece);
638
- }
641
+ line.append(...lineOf(statement));
639
642
  return line;
640
643
  }));
641
- const lines = Math.max(1, statements.length);
642
- let size = Math.min(height / (lines * 1.5), height * 0.55);
643
- this.#text.style.fontSize = `${size}px`;
644
- const wide = this.#text.scrollWidth;
645
- if (wide > width && wide > 0) {
646
- size *= (width * 0.92) / wide;
647
- this.#text.style.fontSize = `${size}px`;
648
- }
644
+ const count = Math.max(1, statements.length);
645
+ this.#full = Math.min(height / (count * 1.5), height * 0.55);
646
+ this.#text.style.fontSize = `${this.#full}px`;
647
+ this.#lines.disconnect();
648
+ for (const line of this.#text.children)
649
+ this.#lines.observe(line);
650
+ this.#fitText();
651
+ }
652
+ /**
653
+ * The statements' letters at the paper's full size, or smaller by as much as the widest line, or
654
+ * the lines together, exceed the paper. Measured at the size they have, so that once fitted they
655
+ * fit and their size stays: the observer of the lines, which calls this again, then stops.
656
+ */
657
+ #fitText() {
658
+ const { width, height } = this.#box;
659
+ // The lines as laid out, not the box's scroll: centred, they spill over both its edges.
660
+ const lines = [...this.#text.children];
661
+ const wide = Math.max(0, ...lines.map((line) => line.offsetWidth));
662
+ const first = lines[0];
663
+ const last = lines.at(-1);
664
+ const tall = first === undefined || last === undefined
665
+ ? 0
666
+ : last.offsetTop + last.offsetHeight - first.offsetTop;
667
+ // Not laid out: hidden, or out of the page. The observer calls again once they are.
668
+ if (wide === 0 || tall === 0)
669
+ return;
670
+ const size = Number.parseFloat(this.#text.style.fontSize) || this.#full;
671
+ const k = Math.min((width * 0.92) / wide, (height * 0.92) / tall);
672
+ const fitted = Math.min(this.#full, size * k);
673
+ // Within half a percent it stays: a size that moves by a rounding feeds the observer again.
674
+ if (Math.abs(fitted - size) > size * 0.005)
675
+ this.#text.style.fontSize = `${fitted}px`;
649
676
  }
650
677
  /** The tooltip on hover or the keyboard's focus, unless Escape or a drag dismissed it. */
651
678
  #showTip() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altnovatrail/canvas",
3
- "version": "0.3.38",
3
+ "version": "0.3.40",
4
4
  "description": "NovaTrail's canvases: the workplace of a task, where the learner writes, draws and types.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -26,12 +26,12 @@
26
26
  "./lib/element/index.js"
27
27
  ],
28
28
  "dependencies": {
29
- "@altnovatrail/spec": "0.19.8",
29
+ "@altnovatrail/spec": "0.19.11",
30
30
  "perfect-freehand": "1.2.3",
31
31
  "rbush": "4.0.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@altnovatrail/contracts": "0.19.8",
34
+ "@altnovatrail/contracts": "0.19.11",
35
35
  "@biomejs/biome": "2.6.6",
36
36
  "@bufbuild/protobuf": "2.17.0",
37
37
  "@iconify-json/material-symbols": "1.2.99",