@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
@@ -4,11 +4,11 @@ import { type Box } from "./geometry.js";
4
4
  import type { Group } from "./groups.js";
5
5
  import type { Stroke } from "./ink.js";
6
6
  /**
7
- * The rule that snaps a model's box to the learner's strokes (R26): the box widens on every side by
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. Both are
9
+ * share of points in it, its edges too, is `share` at least, and one point at least (R26). Both are
10
10
  * parameters of eval (C2). The rule counts in whole numbers, places on the crop as the crop's
11
- * raster has them (R25), so that whoever snaps by it takes the same strokes.
11
+ * raster has them, so that whoever snaps by it takes the same strokes.
12
12
  */
13
13
  export interface SnapRule {
14
14
  /** How far the box widens on every side, in thousandths of D′: 0 to 1000. */
@@ -20,7 +20,7 @@ export interface SnapRule {
20
20
  readonly share: readonly [above: number, below: number];
21
21
  }
22
22
  /**
23
- * The rule the sheet snaps by (R26): a quarter of a digit — 6 px at 24, a quarter of H on the
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
25
  * synthetic sheets chose two thirds over the half R43 canvas-api took: as many strokes taken
26
26
  * whole, and fewer of their neighbours.
@@ -28,48 +28,48 @@ export interface SnapRule {
28
28
  export declare const SNAP_RULE: SnapRule;
29
29
  /**
30
30
  * The context of one submission, of a sheet or of a workbook, and its parts: spec's types, of the
31
- * contract of canvas and app (R74 spec; R07). A sheet's context, which the element gives with its
31
+ * contract of canvas and app. A sheet's context, which the element gives with its
32
32
  * crop and takes back with the tutor's marks, holds the crop's numbers — its `sheet_box`, the
33
33
  * frames of the groups and the whole numbers they come from — the groups of the strokes, the table
34
- * «label → stroke IDs», and the digest of it all, `digestOf` it (R27). It goes back to a sheet
34
+ * «label → stroke IDs», and the digest of it all, `digestOf` it. It goes back to a sheet
35
35
  * whose history holds its strokes: the same sheet, or one given the same history later. Each sheet
36
36
  * numbers its strokes from 1, so a sheet of other strokes with the same IDs tells it by the digest.
37
37
  * A workbook's holds the table «box → stroke IDs», each filled box by its place, in the task's
38
- * order, and the digest of its strokes and of every box of the page, `workbookDigestOf` it (R34,
39
- * R38): no numbers of the crops, for no mark on a workbook is snapped. A task from paper's holds
38
+ * order, and the digest of its strokes and of every box of the page, `workbookDigestOf` it: no
39
+ * numbers of the crops, for no mark on a workbook is snapped. A task from paper's holds
40
40
  * what a sheet's does, its strokes where they lie on the sheet, and where the tracing paper lay,
41
- * which its digest holds with the strokes written on it (R87). An answer cell has no ID:
42
- * its place names it, its item and its place among the item's cells, each from 1 (R51 spec).
41
+ * which its digest holds with the strokes written on it. An answer cell has no ID:
42
+ * its place names it, its item and its place among the item's cells, each from 1.
43
43
  *
44
44
  * The tutor's marks of one submission, with the submission's context, are spec's types too, of the
45
- * same contract (R74 spec; R83 spec): a mark is a frame, with where it is and the name a screen
45
+ * same contract: a mark is a frame, with where it is and the name a screen
46
46
  * reader gives it, in the consumer's words — the element words nothing. Where it is: a group of
47
47
  * strokes by its label, an answer cell by its place, or a box on the crop the model saw,
48
- * [ymin, xmin, ymax, xmax] in whole thousandths of its height and width, min < max (R53 spec). On a
49
- * workbook a mark stands on a cell alone (R34). On a task from paper a mark may be a verdict too, a
50
- * tick or a cross at a box alone: the box of an answer its reading gave (R162 spec).
48
+ * [ymin, xmin, ymax, xmax] in whole thousandths of its height and width, min < max. On a
49
+ * workbook a mark stands on a cell alone. On a task from paper a mark may be a verdict too, a
50
+ * tick or a cross at a box alone: the box of an answer its reading gave.
51
51
  */
52
52
  export type { Anchor, CellPlace, CropNumbers, Mark, Marks, PaperSubmission, SheetSubmission, Submission, WorkbookSubmission, };
53
53
  /**
54
- * What a task from paper's sheet tells `placesOf` and `digestOf` (R87): where its tracing paper
54
+ * What a task from paper's sheet tells `placesOf` and `digestOf`: where its tracing paper
55
55
  * lies, and which strokes were written on it.
56
56
  */
57
57
  export interface Paper {
58
58
  readonly at: readonly [number, number];
59
- /** The tracing paper's scale (R89). */
59
+ /** The tracing paper's scale. */
60
60
  readonly scale: number;
61
61
  readonly onTracing: (id: number) => boolean;
62
62
  }
63
63
  /**
64
64
  * A mark on the sheet, `{stroke_ids, snapped_box}` (C2): the strokes it holds on to, by ID in
65
65
  * ascending order, and the rectangle of their points, in units, as the model saw them. A mark of a
66
- * workbook's cell has the box of its cell too, which its frame stands round with the ink (R39). A
66
+ * workbook's cell has the box of its cell too, which its frame stands round with the ink. A
67
67
  * mark of a box the submission found empty holds no strokes, and its `box` is then the cell's own:
68
68
  * `shownOf` frames it alone. A verdict stands by the group of strokes `verdictsOf` gives it, its
69
69
  * `box` theirs, or, with none, by the answer's box laid on the sheet by the crop's `sheetBox`: the
70
- * answer may be ink on the photo of the page. `correct` says a tick or a cross (R162 spec). A wavy
70
+ * answer may be ink on the photo of the page. `correct` says a tick or a cross. A wavy
71
71
  * line holds on to the strokes its box takes, as a frame does, and with none stands under the box
72
- * laid on the sheet, the place of the mistake; `wavy` says it is one (R87).
72
+ * laid on the sheet, the place of the mistake; `wavy` says it is one.
73
73
  */
74
74
  export interface Placed {
75
75
  readonly ids: readonly number[];
@@ -79,17 +79,17 @@ export interface Placed {
79
79
  readonly wavy?: true;
80
80
  }
81
81
  /**
82
- * The tutor's marks a value gives, checked (R26). A value that is not the marks of a submission is
82
+ * The tutor's marks a value gives, checked. A value that is not the marks of a submission is
83
83
  * a TypeError that names the field; fields the sheet does not read are passed over. The context's
84
- * keys tell its kind (R38): a sheet's crop and groups, or a workbook's boxes. The crop's
84
+ * keys tell its kind: a sheet's crop and groups, or a workbook's boxes. The crop's
85
85
  * `sheet_box` must be the one its whole numbers give, to a millionth of a unit, its frames the
86
86
  * groups', in their order, a group's label must be one of the submission's, and the digest 16 hex
87
87
  * digits. A workbook's rows name each box once and each stroke in one box, and its marks stand on
88
- * cells alone (R39). Whether the submission is this sheet's, its strokes tell (`placesOf`).
88
+ * cells alone. Whether the submission is this sheet's, its strokes tell (`placesOf`).
89
89
  */
90
90
  export declare function marksOf(value: unknown): Marks;
91
91
  /**
92
- * The strokes a model's box takes (R26), by ID in ascending order: of the strokes given, those with
92
+ * The strokes a model's box takes, by ID in ascending order: of the strokes given, those with
93
93
  * the rule's share of their points, and one at least, in the box widened by the rule's margin. The
94
94
  * box is in thousandths of the crop the model saw, and a point counts where it lies on that crop:
95
95
  * the same as the box laid on the sheet by the crop's `sheet_box` and widened there by H × margin /
@@ -98,55 +98,55 @@ export declare function marksOf(value: unknown): Marks;
98
98
  */
99
99
  export declare function snapOf(box: readonly [number, number, number, number], crop: CropNumbers, strokes: readonly Stroke[], rule?: SnapRule): number[];
100
100
  /**
101
- * Where each mark of a submission is on the sheet (R26): the strokes it holds on to, or null for a
102
- * mark that has none — the question is asked without it (R43 canvas-api). `known` is every stroke
101
+ * Where each mark of a submission is on the sheet: the strokes it holds on to, or null for a
102
+ * mark that has none — the question is asked without it. `known` is every stroke
103
103
  * the sheet has known, erased or not, as its history wrote them: a mark holds on to the strokes the
104
104
  * model saw, and shows those of them the sheet shows at the time (C2). A stroke written after the
105
105
  * submission is in none of its groups, and no mark takes it. A group's mark holds its strokes, a
106
106
  * box's the strokes it snaps to; an answer cell's holds none on a sheet, which takes no zones.
107
107
  * `cells` are the boxes of a workbook's page, in the task's order, and null on a sheet: there a
108
108
  * cell's mark holds the strokes of its row of the table, with its box; one of a box not in the
109
- * table, an empty one, holds its box alone, and one of a box not on the page holds none (R39;
110
- * R74 spec). A verdict of a task from paper always has its place, its box on the sheet (R162 spec).
109
+ * table, an empty one, holds its box alone, and one of a box not on the page holds none. A verdict
110
+ * of a task from paper always has its place, its box on the sheet.
111
111
  *
112
112
  * A submission of other strokes is a TypeError: a stroke of its groups the sheet does not know, or
113
- * a digest the sheet's strokes of those IDs do not give with the submission's numbers (R27). A
113
+ * a digest the sheet's strokes of those IDs do not give with the submission's numbers. A
114
114
  * sheet of other strokes would have those IDs too — each numbers its strokes from 1 — and a
115
115
  * context changed since the sheet gave it would place the marks by other numbers. The sheet's own
116
116
  * submission always passes, the strokes erased since too, and so does the same history given to
117
117
  * another sheet. A workbook's digest holds every box of its page too, so a page of another layout
118
- * is not its submission's (R38), and a context of the other kind of canvas is a TypeError.
118
+ * is not its submission's, and a context of the other kind of canvas is a TypeError.
119
119
  * On a task from paper, `paper`, `known` are the strokes where they lie on the sheet now, and a
120
- * context of the tracing paper at another place is a TypeError: its strokes lie elsewhere (R87).
120
+ * context of the tracing paper at another place is a TypeError: its strokes lie elsewhere.
121
121
  */
122
122
  export declare function placesOf(marks: Marks, known: readonly Stroke[], cells?: readonly Cell[] | null, rule?: SnapRule, paper?: Paper): (Placed | null)[];
123
123
  /**
124
- * The rectangle a mark shows now (R26): around the points of those of its strokes the sheet shows,
124
+ * The rectangle a mark shows now: around the points of those of its strokes the sheet shows,
125
125
  * in units, or null while it shows none of them. A mark of a box that was empty shows the box
126
- * itself, always (R39), a verdict its box, and a wavy line of no strokes its box (R162 spec).
126
+ * itself, always, a verdict its box, and a wavy line of no strokes its box.
127
127
  * `shown` gives the box of a stroke's points by its ID while the stroke is
128
- * on the screen — not erased, nor under the eraser under way (R22). New strokes are none of a
128
+ * on the screen — not erased, nor under the eraser under way. New strokes are none of a
129
129
  * mark's.
130
130
  */
131
131
  export declare function shownOf(placed: Placed, shown: (id: number) => Box | undefined): Box | null;
132
132
  /**
133
- * The digest of a submission (R27): what it was made of, in 16 hex digits — the CRC-32 and then the
134
- * Adler-32 of PNG and zlib (png.ts) of a text that holds its strokes, by ID ascending, each with its
135
- * points in tenths of a unit and whole milliseconds, as the rules see them (R24, R25), and its whole
133
+ * The digest of a submission: what it was made of, in 16 hex digits — the CRC-32 and then the
134
+ * Adler-32 of PNG and zlib (png.ts) of a text that holds its strokes, by ID ascending, each with
135
+ * its points in tenths of a unit and whole milliseconds, as the rules see them, and its whole
136
136
  * numbers: D′, the crop's size and margins, the box and the median it comes from, the groups and
137
137
  * their frames. `sheet_box` is not in it: it comes from those numbers, and is checked against them
138
138
  * within its slack. The same strokes and numbers give the same digest in every engine, through any
139
139
  * store that keeps them as JSON does. The digest tells an accidental difference, not a forged one:
140
140
  * CRC-32 tells every change within 32 bits running, and any other change keeps both sums with a
141
141
  * chance of about one in 2^32 at most. A task from paper's, `paper`, holds a last line: where the
142
- * tracing paper lies, in tenths, and the IDs of the strokes written on it, ascending (R87).
142
+ * tracing paper lies, in tenths, and the IDs of the strokes written on it, ascending.
143
143
  */
144
144
  export declare function digestOf(strokes: readonly Stroke[], crop: Pick<CropNumbers, "drawn" | "width" | "height" | "margins" | "frames" | "exact">, groups: readonly Group[], paper?: Paper): string;
145
145
  /**
146
- * The digest of a workbook's submission (R38), as `digestOf` makes a sheet's: of a text that holds
146
+ * The digest of a workbook's submission, as `digestOf` makes a sheet's: of a text that holds
147
147
  * the strokes of its table, by ID ascending, as a sheet's digest has them, then every box of the
148
148
  * page, `cells` in the task's order, with its item, its slot and its rectangle in whole page units,
149
149
  * and then the table's rows. A context of another layout gives another digest even where its
150
- * filled boxes stand where they stood (R34).
150
+ * filled boxes stand where they stood.
151
151
  */
152
152
  export declare function workbookDigestOf(strokes: readonly Stroke[], boxes: readonly Filling[], cells: readonly Cell[]): string;
package/lib/core/marks.js CHANGED
@@ -5,7 +5,7 @@ import { adler32, crc32 } from "./png.js";
5
5
  import { REACH } from "./sheet.js";
6
6
  import { tracingFieldsOf } from "./tracing.js";
7
7
  /**
8
- * The rule the sheet snaps by (R26): a quarter of a digit — 6 px at 24, a quarter of H on the
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
10
  * synthetic sheets chose two thirds over the half R43 canvas-api took: as many strokes taken
11
11
  * whole, and fewer of their neighbours.
@@ -23,13 +23,13 @@ const SHEET_BOX_SLACK = 1e-6;
23
23
  /** A digest as `digestOf` writes it. */
24
24
  const DIGEST = /^[0-9a-f]{16}$/;
25
25
  /**
26
- * The tutor's marks a value gives, checked (R26). A value that is not the marks of a submission is
26
+ * The tutor's marks a value gives, checked. A value that is not the marks of a submission is
27
27
  * a TypeError that names the field; fields the sheet does not read are passed over. The context's
28
- * keys tell its kind (R38): a sheet's crop and groups, or a workbook's boxes. The crop's
28
+ * keys tell its kind: a sheet's crop and groups, or a workbook's boxes. The crop's
29
29
  * `sheet_box` must be the one its whole numbers give, to a millionth of a unit, its frames the
30
30
  * groups', in their order, a group's label must be one of the submission's, and the digest 16 hex
31
31
  * digits. A workbook's rows name each box once and each stroke in one box, and its marks stand on
32
- * cells alone (R39). Whether the submission is this sheet's, its strokes tell (`placesOf`).
32
+ * cells alone. Whether the submission is this sheet's, its strokes tell (`placesOf`).
33
33
  */
34
34
  export function marksOf(value) {
35
35
  const fields = record(value, "marks");
@@ -46,7 +46,7 @@ export function marksOf(value) {
46
46
  };
47
47
  }
48
48
  /**
49
- * The strokes a model's box takes (R26), by ID in ascending order: of the strokes given, those with
49
+ * The strokes a model's box takes, by ID in ascending order: of the strokes given, those with
50
50
  * the rule's share of their points, and one at least, in the box widened by the rule's margin. The
51
51
  * box is in thousandths of the crop the model saw, and a point counts where it lies on that crop:
52
52
  * the same as the box laid on the sheet by the crop's `sheet_box` and widened there by H × margin /
@@ -69,26 +69,26 @@ export function snapOf(box, crop, strokes, rule = SNAP_RULE) {
69
69
  .sort(byNumber);
70
70
  }
71
71
  /**
72
- * Where each mark of a submission is on the sheet (R26): the strokes it holds on to, or null for a
73
- * mark that has none — the question is asked without it (R43 canvas-api). `known` is every stroke
72
+ * Where each mark of a submission is on the sheet: the strokes it holds on to, or null for a
73
+ * mark that has none — the question is asked without it. `known` is every stroke
74
74
  * the sheet has known, erased or not, as its history wrote them: a mark holds on to the strokes the
75
75
  * model saw, and shows those of them the sheet shows at the time (C2). A stroke written after the
76
76
  * submission is in none of its groups, and no mark takes it. A group's mark holds its strokes, a
77
77
  * box's the strokes it snaps to; an answer cell's holds none on a sheet, which takes no zones.
78
78
  * `cells` are the boxes of a workbook's page, in the task's order, and null on a sheet: there a
79
79
  * cell's mark holds the strokes of its row of the table, with its box; one of a box not in the
80
- * table, an empty one, holds its box alone, and one of a box not on the page holds none (R39;
81
- * R74 spec). A verdict of a task from paper always has its place, its box on the sheet (R162 spec).
80
+ * table, an empty one, holds its box alone, and one of a box not on the page holds none. A verdict
81
+ * of a task from paper always has its place, its box on the sheet.
82
82
  *
83
83
  * A submission of other strokes is a TypeError: a stroke of its groups the sheet does not know, or
84
- * a digest the sheet's strokes of those IDs do not give with the submission's numbers (R27). A
84
+ * a digest the sheet's strokes of those IDs do not give with the submission's numbers. A
85
85
  * sheet of other strokes would have those IDs too — each numbers its strokes from 1 — and a
86
86
  * context changed since the sheet gave it would place the marks by other numbers. The sheet's own
87
87
  * submission always passes, the strokes erased since too, and so does the same history given to
88
88
  * another sheet. A workbook's digest holds every box of its page too, so a page of another layout
89
- * is not its submission's (R38), and a context of the other kind of canvas is a TypeError.
89
+ * is not its submission's, and a context of the other kind of canvas is a TypeError.
90
90
  * On a task from paper, `paper`, `known` are the strokes where they lie on the sheet now, and a
91
- * context of the tracing paper at another place is a TypeError: its strokes lie elsewhere (R87).
91
+ * context of the tracing paper at another place is a TypeError: its strokes lie elsewhere.
92
92
  */
93
93
  export function placesOf(marks, known, cells = null, rule = SNAP_RULE, paper) {
94
94
  checkRule(rule);
@@ -153,11 +153,11 @@ export function placesOf(marks, known, cells = null, rule = SNAP_RULE, paper) {
153
153
  });
154
154
  }
155
155
  /**
156
- * The rectangle a mark shows now (R26): around the points of those of its strokes the sheet shows,
156
+ * The rectangle a mark shows now: around the points of those of its strokes the sheet shows,
157
157
  * in units, or null while it shows none of them. A mark of a box that was empty shows the box
158
- * itself, always (R39), a verdict its box, and a wavy line of no strokes its box (R162 spec).
158
+ * itself, always, a verdict its box, and a wavy line of no strokes its box.
159
159
  * `shown` gives the box of a stroke's points by its ID while the stroke is
160
- * on the screen — not erased, nor under the eraser under way (R22). New strokes are none of a
160
+ * on the screen — not erased, nor under the eraser under way. New strokes are none of a
161
161
  * mark's.
162
162
  */
163
163
  export function shownOf(placed, shown) {
@@ -169,10 +169,10 @@ export function shownOf(placed, shown) {
169
169
  const boxes = placed.ids.flatMap((id) => shown(id) ?? []);
170
170
  if (boxes.length === 0)
171
171
  return null;
172
- // A cell's frame stands round its box and its ink together, by the author's answer (R39).
172
+ // A cell's frame stands round its box and its ink together, by the author's answer.
173
173
  return around(placed.cell === undefined ? boxes : [...boxes, placed.cell]);
174
174
  }
175
- /** What a context of the other kind of canvas is, and what this one is (R39). */
175
+ /** What a context of the other kind of canvas is, and what this one is. */
176
176
  function otherKind(context, here) {
177
177
  return `${context} context, and this is ${here}: the task comes before the marks`;
178
178
  }
@@ -195,7 +195,7 @@ function absent(value) {
195
195
  return value === undefined || value === null;
196
196
  }
197
197
  /**
198
- * Where each mark of a workbook's submission is (R39): a cell's, on the strokes of its row of the
198
+ * Where each mark of a workbook's submission is: a cell's, on the strokes of its row of the
199
199
  * table and its box of the page; one of a cell not in the table, on none.
200
200
  */
201
201
  function cellsPlacesOf(marks, { boxes, digest }, byId, cells) {
@@ -213,7 +213,7 @@ function cellsPlacesOf(marks, { boxes, digest }, byId, cells) {
213
213
  return null;
214
214
  const { left, top, width, height } = cell.box;
215
215
  const frame = { minX: left, minY: top, maxX: left + width, maxY: top + height };
216
- // A box the submission found empty is framed alone (R39; R74 spec).
216
+ // A box the submission found empty is framed alone.
217
217
  if (row === undefined)
218
218
  return { ids: [], box: frame, cell: frame };
219
219
  return {
@@ -224,16 +224,16 @@ function cellsPlacesOf(marks, { boxes, digest }, byId, cells) {
224
224
  });
225
225
  }
226
226
  /**
227
- * The digest of a submission (R27): what it was made of, in 16 hex digits — the CRC-32 and then the
228
- * Adler-32 of PNG and zlib (png.ts) of a text that holds its strokes, by ID ascending, each with its
229
- * points in tenths of a unit and whole milliseconds, as the rules see them (R24, R25), and its whole
227
+ * The digest of a submission: what it was made of, in 16 hex digits — the CRC-32 and then the
228
+ * Adler-32 of PNG and zlib (png.ts) of a text that holds its strokes, by ID ascending, each with
229
+ * its points in tenths of a unit and whole milliseconds, as the rules see them, and its whole
230
230
  * numbers: D′, the crop's size and margins, the box and the median it comes from, the groups and
231
231
  * their frames. `sheet_box` is not in it: it comes from those numbers, and is checked against them
232
232
  * within its slack. The same strokes and numbers give the same digest in every engine, through any
233
233
  * store that keeps them as JSON does. The digest tells an accidental difference, not a forged one:
234
234
  * CRC-32 tells every change within 32 bits running, and any other change keeps both sums with a
235
235
  * chance of about one in 2^32 at most. A task from paper's, `paper`, holds a last line: where the
236
- * tracing paper lies, in tenths, and the IDs of the strokes written on it, ascending (R87).
236
+ * tracing paper lies, in tenths, and the IDs of the strokes written on it, ascending.
237
237
  */
238
238
  export function digestOf(strokes, crop, groups, paper) {
239
239
  const lines = strokeLines(strokes);
@@ -248,18 +248,18 @@ export function digestOf(strokes, crop, groups, paper) {
248
248
  .map(({ id }) => id)
249
249
  .filter((id) => paper.onTracing(id))
250
250
  .sort(byNumber);
251
- // A scale of 1 adds nothing, so a digest made before scales came stays the same (R89).
251
+ // A scale of 1 adds nothing, so a digest made before scales came stays the same.
252
252
  const scale = paper.scale === 1 ? "" : ` ${paper.scale}`;
253
253
  lines.push(`tracing ${tenths(paper.at[0])} ${tenths(paper.at[1])} ${traced.join(",")}${scale}`);
254
254
  }
255
255
  return sumOf(lines);
256
256
  }
257
257
  /**
258
- * The digest of a workbook's submission (R38), as `digestOf` makes a sheet's: of a text that holds
258
+ * The digest of a workbook's submission, as `digestOf` makes a sheet's: of a text that holds
259
259
  * the strokes of its table, by ID ascending, as a sheet's digest has them, then every box of the
260
260
  * page, `cells` in the task's order, with its item, its slot and its rectangle in whole page units,
261
261
  * and then the table's rows. A context of another layout gives another digest even where its
262
- * filled boxes stand where they stood (R34).
262
+ * filled boxes stand where they stood.
263
263
  */
264
264
  export function workbookDigestOf(strokes, boxes, cells) {
265
265
  const lines = strokeLines(strokes);
@@ -342,7 +342,7 @@ function onSheetOf(box, crop) {
342
342
  }
343
343
  /**
344
344
  * Whether a point lies in a box of the crop widened by `margin` thousandths of D′, its edges too:
345
- * in whole numbers, a place on the crop times 1000 × H (R25). For a stroke of the submission every
345
+ * in whole numbers, a place on the crop times 1000 × H. For a stroke of the submission every
346
346
  * number stays below 2^31; the place X of a point is ((x − B.minX) × D′ + mx × H) / H px, in
347
347
  * tenths.
348
348
  */
@@ -374,7 +374,7 @@ function checkRule({ margin, share }) {
374
374
  throw new RangeError(`the snapping rule's share: a fraction of whole numbers no more than 1, below from 1 to 1000, not ${shown(share)}`);
375
375
  }
376
376
  }
377
- /** A submission's context, a sheet's, a workbook's or a task from paper's by its keys (R38, R87). */
377
+ /** A submission's context, a sheet's, a workbook's or a task from paper's by its keys. */
378
378
  function submissionOf(value, path) {
379
379
  const fields = record(value, path);
380
380
  let parts;
@@ -414,7 +414,7 @@ function groupTableOf(value, path) {
414
414
  return { label, ids: idsOf(fields.ids, `${path}[${n}].ids`, strokes, "group") };
415
415
  });
416
416
  }
417
- /** The rows of a workbook's table (R38): each box once, by its place, each stroke in one box. */
417
+ /** The rows of a workbook's table: each box once, by its place, each stroke in one box. */
418
418
  function rowsOf(value, path) {
419
419
  if (!Array.isArray(value) || value.length === 0) {
420
420
  throw new TypeError(`${path}: the filled boxes and their strokes, not ${shown(value)}`);
@@ -444,7 +444,7 @@ function idsOf(value, path, taken, of) {
444
444
  }
445
445
  return [...value];
446
446
  }
447
- /** An answer cell's place (R51 spec): its item, and its place among the item's cells, from 1. */
447
+ /** An answer cell's place: its item, and its place among the item's cells, from 1. */
448
448
  function placeOf(fields, path) {
449
449
  return {
450
450
  item: whole(fields.item, `${path}.item`, 1),
@@ -503,7 +503,7 @@ function numbersOf(value, path, groups) {
503
503
  }
504
504
  /**
505
505
  * A mark checked: a frame, or on a task from paper, `paper`, a verdict too, at a box alone and with
506
- * whether the answer is right, and a wavy line, at a box alone (R162 spec).
506
+ * whether the answer is right, and a wavy line, at a box alone.
507
507
  */
508
508
  function markOf(value, path, labels, paper) {
509
509
  const mark = record(value, path);
@@ -528,7 +528,7 @@ function markOf(value, path, labels, paper) {
528
528
  }
529
529
  return { kind: "verdict", at, correct: mark.correct, name: mark.name };
530
530
  }
531
- /** Where a mark is: on a sheet, `labels` its groups'; on a workbook, null, a cell alone (R39). */
531
+ /** Where a mark is: on a sheet, `labels` its groups'; on a workbook, null, a cell alone. */
532
532
  function anchorOf(value, path, labels) {
533
533
  const at = record(value, path);
534
534
  const given = ["group", "cell", "box"].filter((key) => at[key] !== undefined);
@@ -548,7 +548,7 @@ function anchorOf(value, path, labels) {
548
548
  return { cell: placeOf(record(at.cell, `${path}.cell`), `${path}.cell`) };
549
549
  return { box: fractionsOf(at.box, `${path}.box`) };
550
550
  }
551
- /** A box on a crop, valid as R53 spec has it: whole thousandths from 0 to 1000, min < max. */
551
+ /** A box on a crop, valid: whole thousandths from 0 to 1000, min < max. */
552
552
  function fractionsOf(value, path) {
553
553
  if (Array.isArray(value) &&
554
554
  value.length === 4 &&
@@ -564,7 +564,7 @@ function byNumber(a, b) {
564
564
  }
565
565
  /**
566
566
  * A text's bytes in UTF-8, its code units one by one — a lone surrogate too, as three bytes: the
567
- * labels are the consumer's to give. The DOM-free part has no TextEncoder (R05).
567
+ * labels are the consumer's to give. The DOM-free part has no TextEncoder.
568
568
  */
569
569
  function utf8(text) {
570
570
  const bytes = [];
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A statement read from a task from paper, as the element draws it: the text as printed,
3
+ * "□" for each box an answer goes in, and what one line of text cannot hold written LaTeX's way —
4
+ * a fraction with a bar as `\frac{3}{17}`, nested as printed, and a raised power as `^{2}`. Nothing
5
+ * else of LaTeX is the reading's; a model that strays all the same gets its few common signs drawn
6
+ * as signs, `\left` and `\right` dropped, and any other command shown as written, so a reading is
7
+ * never lost to its notation.
8
+ */
9
+ export type Piece = {
10
+ readonly kind: "text";
11
+ readonly text: string;
12
+ } | {
13
+ readonly kind: "box";
14
+ } | {
15
+ readonly kind: "fraction";
16
+ readonly over: readonly Piece[];
17
+ readonly under: readonly Piece[];
18
+ } | {
19
+ readonly kind: "power";
20
+ readonly base: readonly Piece[];
21
+ readonly exponent: readonly Piece[];
22
+ };
23
+ /** The pieces of a statement read, in order. */
24
+ export declare function piecesOf(statement: string): readonly Piece[];
25
+ /**
26
+ * Whether a statement is a formula to the eye, its lone letters its unknowns: it holds no word of
27
+ * two letters or more, outside LaTeX's commands. "3x + 5 = 20" is one, "Ann has 3 apples" is not.
28
+ */
29
+ export declare function formulaic(statement: string): boolean;
@@ -0,0 +1,180 @@
1
+ /** The signs a model may write as LaTeX's commands, drawn as the page prints them. */
2
+ const SIGNS = Object.freeze({
3
+ cdot: "·",
4
+ times: "×",
5
+ div: "÷",
6
+ pm: "±",
7
+ le: "≤",
8
+ leq: "≤",
9
+ ge: "≥",
10
+ geq: "≥",
11
+ ne: "≠",
12
+ neq: "≠",
13
+ approx: "≈",
14
+ square: "□",
15
+ Box: "□",
16
+ });
17
+ /** The commands that only size a bracket, dropped with the space after them. */
18
+ const DROPPED = new Set(["left", "right"]);
19
+ /** The pieces of a statement read, in order. */
20
+ export function piecesOf(statement) {
21
+ return new Reader(statement).pieces(false);
22
+ }
23
+ /**
24
+ * Whether a statement is a formula to the eye, its lone letters its unknowns: it holds no word of
25
+ * two letters or more, outside LaTeX's commands. "3x + 5 = 20" is one, "Ann has 3 apples" is not.
26
+ */
27
+ export function formulaic(statement) {
28
+ return !/\p{L}{2,}/u.test(statement.replace(/\\[A-Za-z]+/g, " "));
29
+ }
30
+ /** Whether a character is an ASCII digit. */
31
+ const digit = (c) => c !== undefined && c >= "0" && c <= "9";
32
+ /**
33
+ * The atom a power raises: the number, with one decimal mark, the letter or the bracket at the
34
+ * text's end. Read back from the end: a pattern anchored at the end alone tries every start, and
35
+ * is quadratic on a long run of digits.
36
+ */
37
+ function atomAtEnd(text) {
38
+ let start = text.length;
39
+ while (digit(text[start - 1]))
40
+ start--;
41
+ if (start === text.length) {
42
+ const last = [...text.slice(-2)].at(-1);
43
+ return last !== undefined && /^(?:\p{L}|[)\]])$/u.test(last) ? last : undefined;
44
+ }
45
+ const mark = text[start - 1];
46
+ if ((mark === "." || mark === ",") && digit(text[start - 2])) {
47
+ start--;
48
+ while (digit(text[start - 1]))
49
+ start--;
50
+ }
51
+ return text.slice(start);
52
+ }
53
+ class Reader {
54
+ #at = 0;
55
+ #text;
56
+ constructor(text) {
57
+ this.#text = text;
58
+ }
59
+ /** The pieces up to the end, or to the brace that closes a group when `inGroup`. */
60
+ pieces(inGroup) {
61
+ const out = [];
62
+ const text = this.#text;
63
+ while (this.#at < text.length) {
64
+ const c = text[this.#at];
65
+ if (c === "}" && inGroup) {
66
+ this.#at++;
67
+ return out;
68
+ }
69
+ if (c === "□") {
70
+ this.#at++;
71
+ out.push({ kind: "box" });
72
+ }
73
+ else if (c === "\\") {
74
+ this.#command(out);
75
+ }
76
+ else if (c === "^") {
77
+ this.#at++;
78
+ out.push({ kind: "power", base: baseOf(out), exponent: this.#argument() });
79
+ }
80
+ else if (c === "{") {
81
+ // A group of its own only groups: its pieces stand in the line.
82
+ this.#at++;
83
+ for (const piece of this.pieces(true)) {
84
+ if (piece.kind === "text")
85
+ push(out, piece.text);
86
+ else
87
+ out.push(piece);
88
+ }
89
+ }
90
+ else if (c === "}") {
91
+ // A brace that closes nothing is no part of the print.
92
+ this.#at++;
93
+ }
94
+ else {
95
+ this.#at++;
96
+ push(out, c);
97
+ }
98
+ }
99
+ return out;
100
+ }
101
+ /** A command after its backslash: a fraction, a sign, a bracket's size, or the text as written. */
102
+ #command(out) {
103
+ const text = this.#text;
104
+ const name = /^\\([A-Za-z]+|.)/.exec(text.slice(this.#at))?.[1] ?? "";
105
+ this.#at += 1 + name.length;
106
+ if (name === "frac" || name === "dfrac" || name === "tfrac") {
107
+ const over = this.#argument();
108
+ const under = this.#argument();
109
+ out.push({ kind: "fraction", over, under });
110
+ }
111
+ else if (name in SIGNS) {
112
+ const sign = SIGNS[name];
113
+ if (sign === "□")
114
+ out.push({ kind: "box" });
115
+ else
116
+ push(out, sign);
117
+ }
118
+ else if (DROPPED.has(name)) {
119
+ if (text[this.#at] === " ")
120
+ this.#at++;
121
+ }
122
+ else if (name === "{" || name === "}" || name === " " || name === ",") {
123
+ push(out, name === "," ? " " : name);
124
+ }
125
+ else {
126
+ push(out, `\\${name}`);
127
+ }
128
+ }
129
+ /** A command's argument: a group in braces, or the one character after it, spaces passed over. */
130
+ #argument() {
131
+ const text = this.#text;
132
+ while (text[this.#at] === " ")
133
+ this.#at++;
134
+ if (text[this.#at] === "{") {
135
+ this.#at++;
136
+ return this.pieces(true);
137
+ }
138
+ const out = [];
139
+ const c = text[this.#at];
140
+ if (c === undefined)
141
+ return out;
142
+ if (c === "\\") {
143
+ this.#command(out);
144
+ return out;
145
+ }
146
+ this.#at++;
147
+ if (c === "□")
148
+ out.push({ kind: "box" });
149
+ else
150
+ push(out, c);
151
+ return out;
152
+ }
153
+ }
154
+ /** Text added to the pieces: joined to the text before it. */
155
+ function push(out, text) {
156
+ const last = out.at(-1);
157
+ if (last?.kind === "text")
158
+ out[out.length - 1] = { kind: "text", text: last.text + text };
159
+ else
160
+ out.push({ kind: "text", text });
161
+ }
162
+ /** What a power raises, taken from the pieces before it: their last atom, or none. */
163
+ function baseOf(out) {
164
+ const last = out.at(-1);
165
+ if (last === undefined)
166
+ return [];
167
+ if (last.kind !== "text") {
168
+ out.pop();
169
+ return [last];
170
+ }
171
+ const atom = atomAtEnd(last.text);
172
+ if (atom === undefined)
173
+ return [];
174
+ const rest = last.text.slice(0, -atom.length);
175
+ if (rest === "")
176
+ out.pop();
177
+ else
178
+ out[out.length - 1] = { kind: "text", text: rest };
179
+ return [{ kind: "text", text: atom }];
180
+ }
@@ -2,7 +2,7 @@ import { type Vec2 } from "perfect-freehand";
2
2
  import type { Stroke } from "./ink.js";
3
3
  /**
4
4
  * The width of the line, in sheet units: 3, as the check board of tutor draws with a `lineWidth`
5
- * of 3 px on its sheet 1000 wide (R19 tutor; R18).
5
+ * of 3 px on its sheet 1000 wide.
6
6
  */
7
7
  export declare const INK_WIDTH = 3;
8
8
  /**
@@ -11,12 +11,12 @@ export declare const INK_WIDTH = 3;
11
11
  * pressure))`, so 2.25 units with a pressure of 1.
12
12
  */
13
13
  export declare const INK_REACH: number;
14
- /** Whether a stroke's line widens with its pressure on the screen: only a pen's does (R05, R18). */
14
+ /** Whether a stroke's line widens with its pressure on the screen: only a pen's does. */
15
15
  export declare function followsPressure(stroke: Stroke): boolean;
16
16
  /**
17
17
  * The outline of a stroke on the screen, as perfect-freehand draws it: a closed polygon around the
18
18
  * stroke's points, in sheet units, to be filled. A pen's line widens with its pressure; a mouse's
19
- * or a finger's is as wide all along (R18). `complete` says the stroke has ended: its last point is
19
+ * or a finger's is as wide all along. `complete` says the stroke has ended: its last point is
20
20
  * then taken as it is, rather than eased toward.
21
21
  */
22
22
  export declare function outline(stroke: Stroke, complete: boolean): Vec2[];