@altnovatrail/canvas 0.3.40 → 0.3.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@ The NovaTrail canvases: the UI package `@altnovatrail/canvas`, which the app bui
19
19
 
20
20
  canvas knows no accounts, no api and no subject, and holds no data of its own: nothing on the tutor's layer ever changes the learner's work.
21
21
 
22
- canvas is a component of [NovaTrail](https://github.com/altnovatrail/spec), a universal open platform for adaptive learning, interactive lessons and AI tutoring. Its card is [architecture 3.2 spec](https://github.com/altnovatrail/spec/blob/main/docs/architecture.md#32-canvas--canvases).
22
+ canvas is a component of [NovaTrail](https://github.com/altnovatrail/spec), a universal open platform for adaptive learning, interactive lessons and AI tutoring. Its card is in [spec's architecture](https://github.com/altnovatrail/spec/blob/main/docs/architecture.md#32-canvas--canvases).
23
23
 
24
24
  - **app** builds the package in and gives it the task and the tutor's marks; app keeps the learner's strokes on the device and sends the picture of the work to api, since canvas itself calls no network.
25
25
  - **spec** gives it the module format, the element's contract with app and the eval protocol of the sample file.
package/lib/core/boxes.js CHANGED
@@ -1,4 +1,4 @@
1
- // The boxes of a workbook's page and the strokes in them (R37). Each visible stroke is in one
1
+ // The boxes of a workbook's page and the strokes in them. Each visible stroke is in one
2
2
  // box or in none: the rule takes it alone, in whole numbers, with no DOM and no time, and what is
3
3
  // in no box is the draft. A stroke is a box's if the middle of the box of its points lies in the
4
4
  // box widened by 120 thousandths of its size — 12 units of a box of 100, short of the 16 to halfway
@@ -3,7 +3,7 @@ import { type Box } from "./geometry.js";
3
3
  import type { Group } from "./groups.js";
4
4
  import type { Stroke } from "./ink.js";
5
5
  /**
6
- * The crop's rule in its numbers: sizes on the crop in pixels, heights on the sheet in units (R25).
6
+ * The crop's rule in its numbers: sizes on the crop in pixels, heights on the sheet in units.
7
7
  * The rule counts in whole numbers — places in tenths of a unit, as the groups do — and each
8
8
  * number it hands out that is not whole is one division of two whole numbers, so that tutor's
9
9
  * runner, which crops by the same rule, gets the same numbers to the bit.
package/lib/core/crop.js CHANGED
@@ -2,7 +2,7 @@ import RBush from "rbush";
2
2
  import { around, extentOf } from "./geometry.js";
3
3
  import { Sets } from "./sets.js";
4
4
  /**
5
- * The crop's rule in its numbers: sizes on the crop in pixels, heights on the sheet in units (R25).
5
+ * The crop's rule in its numbers: sizes on the crop in pixels, heights on the sheet in units.
6
6
  * The rule counts in whole numbers — places in tenths of a unit, as the groups do — and each
7
7
  * number it hands out that is not whole is one division of two whole numbers, so that tutor's
8
8
  * runner, which crops by the same rule, gets the same numbers to the bit.
@@ -5,7 +5,7 @@ import type { Point } from "./screen.js";
5
5
  export declare const ERASER_BUTTON = 5;
6
6
  /**
7
7
  * The eraser: one press of a pointer takes off the sheet, whole, every stroke its path comes
8
- * near — a tap is a path of one point (R22). The strokes it comes near are pending while it is
8
+ * near — a tap is a path of one point. The strokes it comes near are pending while it is
9
9
  * down, and when it lifts they go to the handler the eraser is made with, in one action, with the
10
10
  * page's time of the lift: one undo brings them all back. `pointercancel` drops the press and
11
11
  * erases nothing. One pointer erases at a time, with the primary button or a pen's eraser.
@@ -6,7 +6,7 @@ const ERASER_HELD = 32;
6
6
  const NONE = new Set();
7
7
  /**
8
8
  * The eraser: one press of a pointer takes off the sheet, whole, every stroke its path comes
9
- * near — a tap is a path of one point (R22). The strokes it comes near are pending while it is
9
+ * near — a tap is a path of one point. The strokes it comes near are pending while it is
10
10
  * down, and when it lifts they go to the handler the eraser is made with, in one action, with the
11
11
  * page's time of the lift: one undo brings them all back. `pointercancel` drops the press and
12
12
  * erases nothing. One pointer erases at a time, with the primary button or a pen's eraser.
@@ -1,7 +1,7 @@
1
1
  // A lesson's worked example: the open view of a segment `worked_example`, of spec's
2
2
  // type WorkedExample — its statement, the handwriting sheet or the workbook the
3
3
  // author's demo is shown on, and the demo's parts in order: paragraphs, pictures beside the sheet,
4
- // pictures on areas of a sheet, and on a workbook the boxes it fills (R42). The
4
+ // pictures on areas of a sheet, and on a workbook the boxes it fills. The
5
5
  // element checks it as the schema does, every object closed, and by the format's rules
6
6
  // lesson.areas, lesson.example-fills and lesson.workbook-page too: an area lies on the sheet, the
7
7
  // demo fills each box of the lines once, and the lines fit the page, each value its box. What the
@@ -4,7 +4,7 @@ import type { Stroke } from "./ink.js";
4
4
  /**
5
5
  * The rule of the groups of strokes: two strokes are neighbours if no more than `pause`
6
6
  * milliseconds lie between them and their boxes come within `across` sheet units of each other
7
- * across the sheet and within `down` units down it (R24). A group is the strokes a chain of
7
+ * across the sheet and within `down` units down it. A group is the strokes a chain of
8
8
  * neighbours joins. The rule counts in whole numbers — tenths of a unit and milliseconds, the
9
9
  * precision of a sample file, rounded half up as `Math.round` rounds: 1000.5 tenths are 1001 — and
10
10
  * only subtracts and compares them, so that tutor's runner, which groups by the same rule, gets the
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * A pointer as the hands on the sheet see it: where it is on the screen, how big its contact
3
- * is, and when (R29). The DOM-free part sees no DOM, so the element hands it this much of each
3
+ * is, and when. The DOM-free part sees no DOM, so the element hands it this much of each
4
4
  * pointer event. The contact's size decides only what the pointer may do: it goes into no stroke,
5
5
  * no history and no sample.
6
6
  */
@@ -77,6 +77,11 @@ export interface HandsSheet {
77
77
  writer(): number | undefined;
78
78
  /** The stroke or the erasing of a pointer goes, as on `pointercancel`. */
79
79
  drop(pointerId: number): void;
80
+ /**
81
+ * The stroke or the erasing of a pointer ends where it was, its `pointerup` never to come: as on
82
+ * a lost capture.
83
+ */
84
+ end(pointerId: number): void;
80
85
  /**
81
86
  * Two fingers moved right on the screen by `dx` CSS pixels and down it by `dy`, or left and up
82
87
  * for negative ones: the sheet goes with them. `fresh` marks a gesture's first step.
@@ -109,6 +114,8 @@ export type Role = "writes" | "waits" | "scrolls" | "palm" | "idle";
109
114
  * - One pointer writes at a time, and the sheet's recorder and eraser say which.
110
115
  * - A pen's touch puts the page in pen mode and takes away the stroke of a touch under way: it was
111
116
  * a palm. While a pen or a mouse writes, a touch does nothing until it lifts.
117
+ * - A pen's touch while another pen is down ends what that one writes or erases where it was, and
118
+ * the new pen writes: a screen has one pen, and the other lost its way up.
112
119
  * - A touch wider or taller than `PALM_PX`, at its `pointerdown` or at any move, is a palm: it does
113
120
  * nothing until it lifts, and what it was writing goes.
114
121
  * - Without pen mode the first finger writes. A second that comes down within `PAIR_MS`, before the
package/lib/core/hands.js CHANGED
@@ -85,6 +85,8 @@ export class PenMode {
85
85
  * - One pointer writes at a time, and the sheet's recorder and eraser say which.
86
86
  * - A pen's touch puts the page in pen mode and takes away the stroke of a touch under way: it was
87
87
  * a palm. While a pen or a mouse writes, a touch does nothing until it lifts.
88
+ * - A pen's touch while another pen is down ends what that one writes or erases where it was, and
89
+ * the new pen writes: a screen has one pen, and the other lost its way up.
88
90
  * - A touch wider or taller than `PALM_PX`, at its `pointerdown` or at any move, is a palm: it does
89
91
  * nothing until it lifts, and what it was writing goes.
90
92
  * - Without pen mode the first finger writes. A second that comes down within `PAIR_MS`, before the
@@ -191,6 +193,16 @@ export class Hands {
191
193
  }
192
194
  #pen(contact) {
193
195
  this.#mode.on = true;
196
+ // A pen still down when a pen comes lost its way up: the system took its touch and told the
197
+ // page nothing, as an iPad's selection did (measurements 1.8). What it wrote ends where it
198
+ // was, or the sheet would wait for its lift for good.
199
+ for (const [id, hand] of this.#hands) {
200
+ if (hand.kind !== "pen")
201
+ continue;
202
+ if (this.#sheet.writer() === id)
203
+ this.#sheet.end(id);
204
+ this.#hands.delete(id);
205
+ }
194
206
  // A touch writing when a pen comes was a palm, and its stroke goes. A gesture under way ends,
195
207
  // and every touch down now does nothing until it lifts.
196
208
  const writer = this.#sheet.writer();
@@ -4,7 +4,7 @@ import type { Stroke } from "./ink.js";
4
4
  * An event of the history of writing: spec's type, of the contract of canvas and app.
5
5
  * What an action on the sheet did, at the sheet's time `t` when it landed, in the
6
6
  * order the actions landed; each event says which strokes it put on the sheet or took off, so
7
- * whoever reads the history replays it without the rules of the stack of undo (R19). Those the
7
+ * whoever reads the history replays it without the rules of the stack of undo. Those the
8
8
  * sheet hands out are frozen through.
9
9
  */
10
10
  export type { HistoryEvent };
package/lib/core/ink.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // A point of a stroke and a stroke: spec's types, of the contract of canvas
2
2
  // and app — where a point lies on the sheet, in logical units, when it was written
3
3
  // and how hard the pointer pressed, and a stroke's ID on its sheet, its pointer's type and its
4
- // points. Only a pen's pressure changes the width of the line (R05).
4
+ // points. Only a pen's pressure changes the width of the line.
5
5
  export {};
@@ -6,7 +6,7 @@ import type { Stroke } from "./ink.js";
6
6
  /**
7
7
  * The rule that snaps a model's box to the learner's strokes: the box widens on every side by
8
8
  * `margin` thousandths of the height its crop draws digits at, D′, and a stroke is taken if its
9
- * share of points in it, its edges too, is `share` at least, and one point at least (R26). Both are
9
+ * share of points in it, its edges too, is `share` at least, and one point at least. Both are
10
10
  * parameters of eval (C2). The rule counts in whole numbers, places on the crop as the crop's
11
11
  * raster has them, so that whoever snaps by it takes the same strokes.
12
12
  */
@@ -22,7 +22,7 @@ export interface SnapRule {
22
22
  /**
23
23
  * The rule the sheet snaps by: a quarter of a digit — 6 px at 24, a quarter of H on the
24
24
  * sheet, H the height the crop scales by — and two thirds of the points. A sweep over the
25
- * synthetic sheets chose two thirds over the half R43 canvas-api took: as many strokes taken
25
+ * synthetic sheets chose two thirds over the half canvas-api took: as many strokes taken
26
26
  * whole, and fewer of their neighbours.
27
27
  */
28
28
  export declare const SNAP_RULE: SnapRule;
package/lib/core/marks.js CHANGED
@@ -7,7 +7,7 @@ import { tracingFieldsOf } from "./tracing.js";
7
7
  /**
8
8
  * The rule the sheet snaps by: a quarter of a digit — 6 px at 24, a quarter of H on the
9
9
  * sheet, H the height the crop scales by — and two thirds of the points. A sweep over the
10
- * synthetic sheets chose two thirds over the half R43 canvas-api took: as many strokes taken
10
+ * synthetic sheets chose two thirds over the half canvas-api took: as many strokes taken
11
11
  * whole, and fewer of their neighbours.
12
12
  */
13
13
  export const SNAP_RULE = Object.freeze({
@@ -5,10 +5,18 @@ import type { Stroke } from "./ink.js";
5
5
  * of 3 px on its sheet 1000 wide.
6
6
  */
7
7
  export declare const INK_WIDTH = 3;
8
+ /** A pen's line at no pressure, and at full pressure, in widths of a finger's line. */
9
+ export declare const PEN_THINNEST = 0.5;
10
+ export declare const PEN_WIDEST = 2;
11
+ /**
12
+ * A pen's line at a pressure, in widths of a finger's line: `PEN_THINNEST` at none, `PEN_WIDEST`
13
+ * at full, and between by the pressure to the power `PEN_POWER`. A pressure past 0–1 is taken as
14
+ * the nearer end.
15
+ */
16
+ export declare function penWidth(pressure: number): number;
8
17
  /**
9
18
  * How far the ink reaches from a stroke's points, in sheet units, at most: half the widest line, a
10
- * pen's at full pressure. perfect-freehand's radius at a point is `size × (0.5 − thinning × (0.5 −
11
- * pressure))`, so 2.25 units with a pressure of 1.
19
+ * pen's at full pressure.
12
20
  */
13
21
  export declare const INK_REACH: number;
14
22
  /** Whether a stroke's line widens with its pressure on the screen: only a pen's does. */
@@ -4,28 +4,52 @@ import { getStroke } from "perfect-freehand";
4
4
  * of 3 px on its sheet 1000 wide.
5
5
  */
6
6
  export const INK_WIDTH = 3;
7
- /** How much a pen's pressure changes the width: from half of it to one and a half. */
8
- const PEN_THINNING = 0.5;
7
+ /** A pen's line at no pressure, and at full pressure, in widths of a finger's line. */
8
+ export const PEN_THINNEST = 0.5;
9
+ export const PEN_WIDEST = 2;
10
+ /**
11
+ * The power of the pressure in a pen's width, below 1: Apple Pencil in WebKit gives writing a
12
+ * pressure of about 0–0.2, its median about 0.1 (measurements 1.8), and the curve widens the line
13
+ * more in that low range than a straight one would.
14
+ */
15
+ const PEN_POWER = 0.8;
16
+ /** How much of a point's pressure is its own: the rest is the point's before it, so that the line
17
+ * does not jump with the pointer's noise. */
18
+ const PEN_FOLLOW = 0.65;
19
+ /**
20
+ * A pen's line at a pressure, in widths of a finger's line: `PEN_THINNEST` at none, `PEN_WIDEST`
21
+ * at full, and between by the pressure to the power `PEN_POWER`. A pressure past 0–1 is taken as
22
+ * the nearer end.
23
+ */
24
+ export function penWidth(pressure) {
25
+ const p = Math.min(Math.max(pressure, 0), 1);
26
+ return PEN_THINNEST + (PEN_WIDEST - PEN_THINNEST) * p ** PEN_POWER;
27
+ }
9
28
  /**
10
29
  * How far the ink reaches from a stroke's points, in sheet units, at most: half the widest line, a
11
- * pen's at full pressure. perfect-freehand's radius at a point is `size × (0.5 − thinning × (0.5 −
12
- * pressure))`, so 2.25 units with a pressure of 1.
30
+ * pen's at full pressure.
13
31
  */
14
- export const INK_REACH = INK_WIDTH * (0.5 + PEN_THINNING / 2);
32
+ export const INK_REACH = (INK_WIDTH * PEN_WIDEST) / 2;
15
33
  /**
16
34
  * Every option of perfect-freehand 1.2.3 is given: its code's defaults are not its README's.
17
35
  * The pressure is the pointer's own, the third number of each point, never simulated, and
18
- * the ends are round, without a taper.
36
+ * the ends are round, without a taper. The library's radius is `size × easing(0.5 − thinning ×
37
+ * (0.5 − pressure))`: a pen's `thinning` of 1 hands `easing` the pressure itself, and half the
38
+ * pen's width is the radius. With a `thinning` of 0 the library calls no `easing`, and the radius
39
+ * is half the size.
19
40
  */
20
41
  const OPTIONS = {
21
42
  size: INK_WIDTH,
22
43
  smoothing: 0.5,
23
44
  streamline: 0.5,
24
45
  simulatePressure: false,
25
- easing: (pressure) => pressure,
46
+ easing: (pressure) => penWidth(pressure) / 2,
26
47
  start: { cap: true, taper: false },
27
48
  end: { cap: true, taper: false },
28
49
  };
50
+ /** perfect-freehand's `thinning` of a pen's line, and of an even one. */
51
+ const PEN_THINNING = 1;
52
+ const EVEN = 0;
29
53
  /** Whether a stroke's line widens with its pressure on the screen: only a pen's does. */
30
54
  export function followsPressure(stroke) {
31
55
  return stroke.kind === "pen";
@@ -37,14 +61,25 @@ export function followsPressure(stroke) {
37
61
  * then taken as it is, rather than eased toward.
38
62
  */
39
63
  export function outline(stroke, complete) {
40
- return polygon(stroke, followsPressure(stroke) ? PEN_THINNING : 0, complete);
64
+ return polygon(stroke, followsPressure(stroke) ? PEN_THINNING : EVEN, complete);
41
65
  }
42
66
  function polygon(stroke, thinning, complete) {
43
- const points = stroke.points.map(({ x, y, p }) => [x, y, p]);
67
+ // Each point's pressure leans on the point's before it: the line widens and narrows smoothly.
68
+ let eased;
69
+ const points = stroke.points.map(({ x, y, p }) => {
70
+ eased = eased === undefined ? p : (1 - PEN_FOLLOW) * eased + PEN_FOLLOW * p;
71
+ return [x, y, eased];
72
+ });
44
73
  // One point alone perfect-freehand pairs with another a unit off and draws as an oval. The same
45
74
  // point twice it draws as a round dot, as wide as the line.
46
- const [only] = points;
75
+ const [only, end] = points;
47
76
  if (points.length === 1 && only !== undefined)
48
77
  points.push(only);
78
+ // Two points it takes as the first and four of its own toward the second, of a pressure of 0.5
79
+ // whatever the two had: three are put between them here, at the pressures between.
80
+ if (points.length === 2 && only !== undefined && end !== undefined) {
81
+ const between = [1, 2, 3].map((quarter) => only.map((value, i) => value + ((end[i] ?? value) - value) * (quarter / 4)));
82
+ points.splice(1, 0, ...between);
83
+ }
49
84
  return getStroke(points, { ...OPTIONS, thinning, last: complete });
50
85
  }
package/lib/core/page.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // The layout of a workbook's page: where the template puts each item's number, the
2
- // pieces of its line and its boxes, in whole page units, from the task's items alone (R35). The
2
+ // pieces of its line and its boxes, in whole page units, from the task's items alone. The
3
3
  // page is the sheet's, 1000 × 1400 units, and the boxes stay where the layout puts them on any
4
4
  // device: the widths of the text come from the canvas's own table (widths.ts), and SVG fits the
5
5
  // text to them. Short lines stand two to a row, in the task's order; a long line takes the page's
@@ -24,7 +24,7 @@ export interface PointerSample {
24
24
  /**
25
25
  * How close two recorded points of a stroke may come, in sheet units: 0.1, the precision of a
26
26
  * sample file. A point nearer than that to the last one recorded adds nothing the file would
27
- * keep (R18).
27
+ * keep.
28
28
  */
29
29
  export declare const MIN_STEP = 0.1;
30
30
  /** `button` of the primary button: a pen's tip, a finger, a mouse's left button. */
@@ -2,7 +2,7 @@ import { Clock } from "./clock.js";
2
2
  /**
3
3
  * How close two recorded points of a stroke may come, in sheet units: 0.1, the precision of a
4
4
  * sample file. A point nearer than that to the last one recorded adds nothing the file would
5
- * keep (R18).
5
+ * keep.
6
6
  */
7
7
  export const MIN_STEP = 0.1;
8
8
  /** `button` of the primary button: a pen's tip, a finger, a mouse's left button. */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The task's page on the handwriting sheet in logical units: 1000 wide and 1400 tall, at the
3
- * sheet's top left corner, the origin, with y pointing down, one scale on both axes (R06). Every
3
+ * sheet's top left corner, the origin, with y pointing down, one scale on both axes. Every
4
4
  * layer of the sheet counts in these units, whatever the device's screen; the task's zones, the
5
5
  * workbook's lines and the areas of a worked example lie on the page.
6
6
  */
@@ -34,7 +34,7 @@ export declare function extentOf(ink: {
34
34
  } | undefined, room: Size): Size;
35
35
  /**
36
36
  * The bytes of a work's picture at most, before its encoding: the page's rows at a pixel a unit,
37
- * each with its filter byte, which keep its PNG within the page's bound of bytes (R83).
37
+ * each with its filter byte, which keep its PNG within the page's bound of bytes.
38
38
  */
39
39
  export declare const PICTURE_BYTES: number;
40
40
  /**
package/lib/core/sheet.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The task's page on the handwriting sheet in logical units: 1000 wide and 1400 tall, at the
3
- * sheet's top left corner, the origin, with y pointing down, one scale on both axes (R06). Every
3
+ * sheet's top left corner, the origin, with y pointing down, one scale on both axes. Every
4
4
  * layer of the sheet counts in these units, whatever the device's screen; the task's zones, the
5
5
  * workbook's lines and the areas of a worked example lie on the page.
6
6
  */
@@ -27,7 +27,7 @@ export function extentOf(ink, room) {
27
27
  }
28
28
  /**
29
29
  * The bytes of a work's picture at most, before its encoding: the page's rows at a pixel a unit,
30
- * each with its filter byte, which keep its PNG within the page's bound of bytes (R83).
30
+ * each with its filter byte, which keep its PNG within the page's bound of bytes.
31
31
  */
32
32
  export const PICTURE_BYTES = (SHEET.width + 1) * SHEET.height;
33
33
  /**
@@ -16,7 +16,7 @@ export interface PaperForCheck {
16
16
  readonly png: Uint8Array<ArrayBuffer>;
17
17
  readonly submission: PaperSubmission;
18
18
  }
19
- /** The crop of one filled box of a workbook: its item and its slot, from 1, and its PNG (R38). */
19
+ /** The crop of one filled box of a workbook: its item and its slot, from 1, and its PNG. */
20
20
  export interface CellForCheck {
21
21
  readonly item: number;
22
22
  readonly slot: number;
@@ -5,7 +5,7 @@ import type { Stroke } from "./ink.js";
5
5
  import type { Point } from "./screen.js";
6
6
  /**
7
7
  * Where the tracing paper of a task from paper lies on the sheet, and whether it is hidden:
8
- * spec's type, of the contract of canvas and app (R87).
8
+ * spec's type, of the contract of canvas and app.
9
9
  */
10
10
  export type { TracingState };
11
11
  /**
@@ -25,7 +25,7 @@ export declare const TRACING: Readonly<{
25
25
  /**
26
26
  * The tracing paper's scale: from `min` to `max` times its own size, as the mockup's
27
27
  * `Zadacha-masshtab` has it; a button's press multiplies it by `button`, a notch of the wheel by
28
- * `wheel`, and a scale is kept in hundredths, as the percentage shows it (R89).
28
+ * `wheel`, and a scale is kept in hundredths, as the percentage shows it.
29
29
  */
30
30
  export declare const SCALE: Readonly<{
31
31
  min: 0.4;
@@ -18,7 +18,7 @@ export const TRACING = Object.freeze({
18
18
  /**
19
19
  * The tracing paper's scale: from `min` to `max` times its own size, as the mockup's
20
20
  * `Zadacha-masshtab` has it; a button's press multiplies it by `button`, a notch of the wheel by
21
- * `wheel`, and a scale is kept in hundredths, as the percentage shows it (R89).
21
+ * `wheel`, and a scale is kept in hundredths, as the percentage shows it.
22
22
  */
23
23
  export const SCALE = Object.freeze({ min: 0.4, max: 4, button: 1.2, wheel: 1.08 });
24
24
  /** A scale kept to the rule's bounds, in hundredths. */
@@ -8,7 +8,7 @@ import type { Point } from "./screen.js";
8
8
  * Clearing and erasing are actions too, so undo brings their strokes back. Nothing is
9
9
  * redone. The times its methods take are the page's, and the sheet's clock turns one into the
10
10
  * sheet's time only when the action lands: an undo that has nothing to take back is no event. A
11
- * history given to the sheet is replayed by the same rules, each action at its own time (R27).
11
+ * history given to the sheet is replayed by the same rules, each action at its own time.
12
12
  */
13
13
  export declare class Work {
14
14
  #private;
package/lib/core/work.js CHANGED
@@ -10,7 +10,7 @@ import { frozen, historyOf, sameEvent } from "./history.js";
10
10
  * Clearing and erasing are actions too, so undo brings their strokes back. Nothing is
11
11
  * redone. The times its methods take are the page's, and the sheet's clock turns one into the
12
12
  * sheet's time only when the action lands: an undo that has nothing to take back is no event. A
13
- * history given to the sheet is replayed by the same rules, each action at its own time (R27).
13
+ * history given to the sheet is replayed by the same rules, each action at its own time.
14
14
  */
15
15
  export class Work {
16
16
  #clock;
@@ -1,4 +1,4 @@
1
- /** The smallest and the largest zoom of the sheet: half its fit, and twice it (R73). */
1
+ /** The smallest and the largest zoom of the sheet: half its fit, and twice it. */
2
2
  export declare const ZOOM_MIN = 0.5;
3
3
  export declare const ZOOM_MAX = 2;
4
4
  /**
package/lib/core/zoom.js CHANGED
@@ -1,4 +1,4 @@
1
- /** The smallest and the largest zoom of the sheet: half its fit, and twice it (R73). */
1
+ /** The smallest and the largest zoom of the sheet: half its fit, and twice it. */
2
2
  export const ZOOM_MIN = 0.5;
3
3
  export const ZOOM_MAX = 2;
4
4
  /**
@@ -102,7 +102,7 @@ export type IconName = keyof typeof ICONS;
102
102
  /**
103
103
  * Each value of the row, by its button's key: the icon in outline, the one the button shows while
104
104
  * chosen — the same for a value without a fill — and whether the icon is mirrored in a row that
105
- * runs right to left (R78 spec).
105
+ * runs right to left.
106
106
  */
107
107
  export declare const ROW: {
108
108
  readonly task: {
@@ -1,5 +1,5 @@
1
1
  // Written by scripts/icons.ts — `just icons` — from @iconify-json/material-symbols 1.2.99:
2
- // Material Symbols by Google, under the Apache License 2.0 (R46; R78 spec).
2
+ // Material Symbols by Google, under the Apache License 2.0.
3
3
  // ci-lint fails unless it is what the script writes, so it is never edited by hand. This module is
4
4
  // no entry point of the package.
5
5
  /** The icons of the row's buttons, by their names in the set, as the element draws them. */
@@ -152,7 +152,7 @@ export const ICONS = {
152
152
  /**
153
153
  * Each value of the row, by its button's key: the icon in outline, the one the button shows while
154
154
  * chosen — the same for a value without a fill — and whether the icon is mirrored in a row that
155
- * runs right to left (R78 spec).
155
+ * runs right to left.
156
156
  */
157
157
  export const ROW = {
158
158
  task: { outline: "article-outline-rounded", filled: "article-rounded", mirrored: false },
@@ -1,5 +1,5 @@
1
1
  // The package's entry point @altnovatrail/canvas: the canvas as a custom element, one for every
2
- // canvas kind, with its markup in an open shadow root (R07). Importing it registers the element,
2
+ // canvas kind, with its markup in an open shadow root. Importing it registers the element,
3
3
  // once: a page has one element of this name. The types of its contract with app are spec's, of
4
4
  // @altnovatrail/spec/canvas: the element implements its CanvasElement, and the package puts the
5
5
  // element and its events in the DOM's maps.
@@ -12,7 +12,7 @@
12
12
  // over the work. The history of writing comes in and goes out, an event tells of every
13
13
  // action, and the work for checking is the crop with the context of its submission. Over it
14
14
  // all stand the element's own buttons — the tools the task allows, undo and clearing —, labelled
15
- // in the element's `lang`, on a vertical bar of glass at its left edge (R84). On a tablet a
15
+ // in the element's `lang`, on a vertical bar of glass at its left edge. On a tablet a
16
16
  // pen's touch puts the page in pen mode, where a finger writes nothing, a palm writes nothing, and
17
17
  // two fingers scroll, one finger too.
18
18
  // The task comes in the names of the module format 0.4, checked as its schema checks it, and the
@@ -193,6 +193,11 @@ const ERASER_RADIUS_PX = 10;
193
193
  // writing and the buttons' pointer, though not their keys. A worked example's canvas
194
194
  // takes no pointer at all: a finger or a pen on its sheet scrolls, and zooms, as the browser does
195
195
  // on the statement, and a long press or a right click opens no menu over the sheet all the same.
196
+ // No text of the element is selected, nor does a long press open a menu of the system over it: on
197
+ // an iPad a pen's double tap or long press, the way a dot or an equals sign is written, would
198
+ // select the nearest text, a button's label out of sight among it, and the system's menu of the
199
+ // selection would come up over the sheet (measurements 1.8). A screen reader reads what it read
200
+ // before.
196
201
  // The theme is the consumer's, by custom properties that the shadow tree inherits; with
197
202
  // forced colours the system's colours stand in for them. The element is horizontal whatever writing
198
203
  // mode the page is in: a sheet has no other.
@@ -205,7 +210,10 @@ const ERASER_RADIUS_PX = 10;
205
210
  // is three pixels across at the fit and above it, and smaller by the zoom below it, so that a sheet
206
211
  // zoomed out is no field of dots.
207
212
  const STYLE = `
208
- :host { display: flex; flex-direction: column; isolation: isolate; writing-mode: horizontal-tb; }
213
+ :host {
214
+ display: flex; flex-direction: column; isolation: isolate; writing-mode: horizontal-tb;
215
+ user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
216
+ }
209
217
  :host([hidden]) { display: none; }
210
218
  .frame {
211
219
  position: relative; flex: 1 1 auto; min-height: 0; display: grid;
@@ -342,10 +350,7 @@ const STYLE = `
342
350
  position: relative; aspect-ratio: ${SHEET.width} / ${SHEET.height};
343
351
  background: var(--novatrail-canvas-paper, ${PAPER});
344
352
  }
345
- .stage {
346
- position: sticky; top: 0; left: 0; max-height: 100%; overflow: clip;
347
- user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
348
- }
353
+ .stage { position: sticky; top: 0; left: 0; max-height: 100%; overflow: clip; }
349
354
  .spot { position: absolute; visibility: hidden; }
350
355
  .stage > * { position: absolute; inset: 0; width: 100%; height: 100%; }
351
356
  .stage > :not(canvas) { pointer-events: none; }
@@ -356,6 +361,7 @@ const STYLE = `
356
361
  .grid.dots { stroke-width: calc(3px * min(1, var(--zoom, 1))); stroke-linecap: round; }
357
362
  .print {
358
363
  all: initial; font-family: inherit; visibility: inherit; pointer-events: none; direction: ltr;
364
+ user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
359
365
  font-variant-numeric: tabular-nums; font-size: ${LAYOUT.size}px;
360
366
  color: var(--novatrail-canvas-ink, ${INK});
361
367
  }
@@ -474,7 +480,7 @@ canvas {
474
480
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
475
481
  }
476
482
  .tracing-scale .mode.back { background: #f2f2f7; color: var(--novatrail-canvas-ink, ${INK}); }
477
- /* The one motion: a wait for the reading the learner asked for, and only to whom it is no harm (R89). */
483
+ /* The one motion: a wait for the reading the learner asked for, and only to whom it is no harm. */
478
484
  @media (prefers-reduced-motion: no-preference) {
479
485
  .scan i { animation: novatrail-scan 1s ease-in-out infinite; }
480
486
  .spinner, .tracing-scale .mode.busy::before { animation: novatrail-spin 0.8s linear infinite; }
@@ -545,7 +551,7 @@ const sheets = new WeakMap();
545
551
  * Gives the element's shadow root its style, as a sheet the root adopts, and not a `<style>` in
546
552
  * its tree: a consumer's content security policy that allows no inline style, as app's
547
553
  * `style-src 'self'`, blocks the one and not the other, and the element asks of the policy only
548
- * `img-src blob:` (R51). A root adopts only a sheet made for its own document, by that
554
+ * `img-src blob:`. A root adopts only a sheet made for its own document, by that
549
555
  * document's window, and an element moved into another document comes there without its sheets:
550
556
  * it adopts that document's sheet then. A document without a window, which can make no sheet,
551
557
  * leaves the element unstyled till it comes into one that can.
@@ -763,6 +769,10 @@ export class NovatrailCanvas extends HTMLElement {
763
769
  #hands = new Hands({
764
770
  writer: () => this.#writer(),
765
771
  drop: (pointerId) => this.#drop(pointerId),
772
+ end: (pointerId) => {
773
+ this.#recorder.end(pointerId);
774
+ this.#eraser.end(pointerId);
775
+ },
766
776
  scroll: (dx, dy, fresh) => this.#scroll(dx, dy, fresh),
767
777
  zoom: (ratio, x, y) => this.#pinch(ratio, x, y),
768
778
  across: () => overflowOf(this.#viewport, "x") > EDGE,
@@ -799,7 +809,7 @@ export class NovatrailCanvas extends HTMLElement {
799
809
  */
800
810
  #held;
801
811
  #tool = "pen";
802
- /** The pointer the hand moves the sheet by, and where it was on the screen last. */
812
+ /** The pointer the hand moves the sheet by, of its type, and where it was on the screen last. */
803
813
  #pan;
804
814
  /** A task from paper's grid, the learner's. */
805
815
  #paperGrid = "dots";
@@ -927,6 +937,9 @@ export class NovatrailCanvas extends HTMLElement {
927
937
  // The bar comes first, as the row of buttons before it did: Tab reaches it before the sheet.
928
938
  this.#wrapper.append(this.#tools.rail, this.#viewport, this.#ring);
929
939
  root.append(this.#wrapper);
940
+ // The styles keep every text of the element from a selection; a selection that a script or an
941
+ // engine starts anyway does not start here.
942
+ root.addEventListener("selectstart", (event) => event.preventDefault());
930
943
  this.#lay(NO_TASK);
931
944
  this.#refresh();
932
945
  this.#canvas.addEventListener("pointerdown", (event) => this.#down(event));
@@ -948,6 +961,15 @@ export class NovatrailCanvas extends HTMLElement {
948
961
  // canvas's event comes up to the stage, and so does the stage's own, where a worked example's
949
962
  // sheet takes the pointer instead.
950
963
  this.#stage.addEventListener("contextmenu", (event) => event.preventDefault());
964
+ // A pen's touch on the canvas starts none of the system's gestures: on an iPad a long press or a
965
+ // double tap would select text and open the menu of the selection, and a pen writes by pointer
966
+ // events alone, which come before the touch events. A finger's touch is left as it is.
967
+ for (const type of ["touchstart", "touchmove"]) {
968
+ this.#canvas.addEventListener(type, (event) => {
969
+ if (byStylus(event))
970
+ event.preventDefault();
971
+ }, { passive: false });
972
+ }
951
973
  // A new colour of the ink, from the consumer's theme or the page's colour scheme, ends a
952
974
  // transition of the canvas's colour a millisecond long: the ink is drawn anew in it.
953
975
  this.#canvas.addEventListener("transitionend", () => this.#request());
@@ -1909,9 +1931,17 @@ export class NovatrailCanvas extends HTMLElement {
1909
1931
  // The hand moves the sheet under a pen, a finger or a mouse alike, and writes nothing: one
1910
1932
  // pointer at a time, and the others do nothing while it moves.
1911
1933
  if (this.#tool === HAND) {
1934
+ // A pen that moves the sheet lost its way up when a pen comes down again: a screen has one.
1935
+ if (this.#pan?.kind === "pen" && event.pointerType === "pen")
1936
+ this.#endPan();
1912
1937
  if (this.#pan !== undefined)
1913
1938
  return;
1914
- this.#pan = { pointerId: event.pointerId, x: event.clientX, y: event.clientY };
1939
+ this.#pan = {
1940
+ pointerId: event.pointerId,
1941
+ kind: event.pointerType,
1942
+ x: event.clientX,
1943
+ y: event.clientY,
1944
+ };
1915
1945
  this.#latch = undefined;
1916
1946
  this.#latchAcross = undefined;
1917
1947
  this.#sheet.classList.add("panning");
@@ -1972,7 +2002,7 @@ export class NovatrailCanvas extends HTMLElement {
1972
2002
  const pan = this.#pan;
1973
2003
  if (pan !== undefined && pan.pointerId === event.pointerId) {
1974
2004
  this.#scroll(event.clientX - pan.x, event.clientY - pan.y, false);
1975
- this.#pan = { pointerId: pan.pointerId, x: event.clientX, y: event.clientY };
2005
+ this.#pan = { ...pan, x: event.clientX, y: event.clientY };
1976
2006
  this.#flush();
1977
2007
  return;
1978
2008
  }
@@ -3220,6 +3250,14 @@ function contactOf(event) {
3220
3250
  time: event.timeStamp,
3221
3251
  };
3222
3252
  }
3253
+ /**
3254
+ * Whether a touch event is a pen's: WebKit gives a pen's touch the `touchType` "stylus". A touch
3255
+ * without it is taken for a finger's, and is left as it is.
3256
+ */
3257
+ function byStylus(event) {
3258
+ const touches = [...event.changedTouches];
3259
+ return touches.some((touch) => touch.touchType === "stylus");
3260
+ }
3223
3261
  /** The scroll an event's fingers owe a scroller, in whole pixels, if any: the rest waits. */
3224
3262
  function owed(latch) {
3225
3263
  if (!latch)
@@ -1,6 +1,6 @@
1
1
  // The element's own buttons: the tools the task allows — the pen and the eraser — and
2
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
3
+ // edge of the element, as the interface mockup draws it. 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altnovatrail/canvas",
3
- "version": "0.3.40",
3
+ "version": "0.3.42",
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.11",
29
+ "@altnovatrail/spec": "0.19.12",
30
30
  "perfect-freehand": "1.2.3",
31
31
  "rbush": "4.0.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@altnovatrail/contracts": "0.19.11",
34
+ "@altnovatrail/contracts": "0.19.12",
35
35
  "@biomejs/biome": "2.6.6",
36
36
  "@bufbuild/protobuf": "2.17.0",
37
37
  "@iconify-json/material-symbols": "1.2.99",