@altnovatrail/canvas 0.3.39 → 0.3.41
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 +1 -1
- package/lib/core/boxes.d.ts +7 -7
- package/lib/core/boxes.js +10 -10
- package/lib/core/clock.d.ts +5 -5
- package/lib/core/clock.js +5 -5
- package/lib/core/crop.d.ts +13 -13
- package/lib/core/crop.js +10 -10
- package/lib/core/eraser.d.ts +6 -6
- package/lib/core/eraser.js +6 -6
- package/lib/core/example.d.ts +6 -6
- package/lib/core/example.js +9 -9
- package/lib/core/fields.d.ts +1 -1
- package/lib/core/fields.js +1 -1
- package/lib/core/geometry.d.ts +6 -5
- package/lib/core/geometry.js +8 -6
- package/lib/core/grid.d.ts +3 -3
- package/lib/core/grid.js +3 -3
- package/lib/core/groups.d.ts +14 -14
- package/lib/core/groups.js +6 -6
- package/lib/core/hands.d.ts +19 -18
- package/lib/core/hands.js +16 -15
- package/lib/core/history.d.ts +10 -10
- package/lib/core/history.js +6 -6
- package/lib/core/index.js +8 -9
- package/lib/core/ink.js +3 -3
- package/lib/core/manifest.d.ts +3 -3
- package/lib/core/manifest.js +6 -6
- package/lib/core/marks.d.ts +39 -39
- package/lib/core/marks.js +35 -35
- package/lib/core/notation.d.ts +5 -5
- package/lib/core/outline.d.ts +3 -3
- package/lib/core/outline.js +6 -6
- package/lib/core/page.d.ts +7 -7
- package/lib/core/page.js +10 -10
- package/lib/core/png.d.ts +3 -3
- package/lib/core/png.js +3 -3
- package/lib/core/raster.d.ts +3 -3
- package/lib/core/raster.js +3 -3
- package/lib/core/recorder.d.ts +8 -8
- package/lib/core/recorder.js +8 -8
- package/lib/core/screen.d.ts +2 -2
- package/lib/core/screen.js +1 -1
- package/lib/core/sets.d.ts +1 -1
- package/lib/core/sets.js +1 -1
- package/lib/core/sheet.d.ts +5 -5
- package/lib/core/sheet.js +5 -5
- package/lib/core/submission.d.ts +24 -24
- package/lib/core/submission.js +21 -21
- package/lib/core/task.d.ts +17 -16
- package/lib/core/task.js +14 -13
- package/lib/core/tracing.d.ts +19 -19
- package/lib/core/tracing.js +19 -19
- package/lib/core/widths.d.ts +2 -2
- package/lib/core/widths.js +5 -5
- package/lib/core/work.d.ts +19 -19
- package/lib/core/work.js +22 -22
- package/lib/core/zoom.d.ts +5 -5
- package/lib/core/zoom.js +5 -5
- package/lib/element/icons.d.ts +1 -1
- package/lib/element/icons.js +2 -2
- package/lib/element/index.d.ts +87 -87
- package/lib/element/index.js +286 -283
- package/lib/element/labels.d.ts +17 -17
- package/lib/element/labels.js +7 -8
- package/lib/element/notation.js +1 -1
- package/lib/element/parts.d.ts +2 -2
- package/lib/element/parts.js +6 -6
- package/lib/element/pictures.js +1 -1
- package/lib/element/probe.d.ts +2 -2
- package/lib/element/probe.js +3 -3
- package/lib/element/session.js +2 -2
- package/lib/element/statement.d.ts +2 -2
- package/lib/element/statement.js +6 -6
- package/lib/element/tools.d.ts +17 -18
- package/lib/element/tools.js +30 -29
- package/lib/element/tracing.js +8 -8
- package/package.json +3 -3
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
|
|
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.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface Cell {
|
|
|
8
8
|
readonly box: PageBox;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* The rule of boxes
|
|
11
|
+
* The rule of boxes, in thousandths of a box's width across and of its height down: how far
|
|
12
12
|
* the box is widened for the middle of a stroke's points, and how wide and how tall the box of its
|
|
13
13
|
* points may be.
|
|
14
14
|
*/
|
|
@@ -16,16 +16,16 @@ export interface BoxRule {
|
|
|
16
16
|
readonly margin: number;
|
|
17
17
|
readonly limit: number;
|
|
18
18
|
}
|
|
19
|
-
/** The rule the workbook has
|
|
19
|
+
/** The rule the workbook has. */
|
|
20
20
|
export declare const BOX_RULE: BoxRule;
|
|
21
21
|
/**
|
|
22
22
|
* Which answer slots the learner's strokes fill, per item, per slot, in the task's order: a
|
|
23
|
-
* workbook's boxes, each whether it holds a stroke
|
|
24
|
-
* it or the whole sheet, whether the sheet holds one
|
|
23
|
+
* workbook's boxes, each whether it holds a stroke, or a sheet's one answer anywhere on
|
|
24
|
+
* it or the whole sheet, whether the sheet holds one. spec's type.
|
|
25
25
|
*/
|
|
26
26
|
export type { Filled };
|
|
27
27
|
/**
|
|
28
|
-
* What a sheet's one answer slot — anywhere on it, or the whole sheet — is filled with
|
|
28
|
+
* What a sheet's one answer slot — anywhere on it, or the whole sheet — is filled with: a
|
|
29
29
|
* stroke on the sheet, or none. The same array each time, as a workbook's filling stays the same
|
|
30
30
|
* until a box changes.
|
|
31
31
|
*/
|
|
@@ -39,10 +39,10 @@ export declare function cellsOf(page: Page): readonly Cell[];
|
|
|
39
39
|
* one with a point off the sheet a RangeError, as the crop has them.
|
|
40
40
|
*/
|
|
41
41
|
export declare function cellOf(stroke: Stroke, cells: readonly Cell[], rule?: BoxRule): number;
|
|
42
|
-
/** A filled box and the IDs of its strokes, in ascending order: spec's type
|
|
42
|
+
/** A filled box and the IDs of its strokes, in ascending order: spec's type. */
|
|
43
43
|
export type { Filling };
|
|
44
44
|
/**
|
|
45
|
-
* The table of the boxes the strokes fill
|
|
45
|
+
* The table of the boxes the strokes fill: each box that holds a stroke, in the order of
|
|
46
46
|
* `cells`, with the IDs of its strokes. A stroke ID twice is a TypeError.
|
|
47
47
|
*/
|
|
48
48
|
export declare function tableOf(strokes: readonly Stroke[], cells: readonly Cell[], rule?: BoxRule): readonly Filling[];
|
package/lib/core/boxes.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
// The boxes of a workbook's page and the strokes in them
|
|
2
|
-
// box or in none: the rule takes it alone, in whole numbers, with no DOM and no time, and what is
|
|
3
|
-
// no box is the draft. A stroke is a box's if the middle of the box of its points lies in the
|
|
4
|
-
// widened by 120 thousandths of its size — 12 units of a box of 100, short of the 16 to halfway
|
|
5
|
-
// the next box — and it is no wider and no taller than the box and 30 units on each side: a
|
|
1
|
+
// The boxes of a workbook's page and the strokes in them. Each visible stroke is in one
|
|
2
|
+
// box or in none: the rule takes it alone, in whole numbers, with no DOM and no time, and what is
|
|
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
|
+
// box widened by 120 thousandths of its size — 12 units of a box of 100, short of the 16 to halfway
|
|
5
|
+
// to the next box — and it is no wider and no taller than the box and 30 units on each side: a
|
|
6
6
|
// fraction's bar wider than the box is its own, and a line through the whole line is not. The
|
|
7
7
|
// core's entry point does not give the rule. It is the eval protocol's too, and spec's test vectors
|
|
8
|
-
// pin it
|
|
8
|
+
// pin it.
|
|
9
9
|
import { extentOf, tenths } from "./geometry.js";
|
|
10
|
-
/** The rule the workbook has
|
|
10
|
+
/** The rule the workbook has. */
|
|
11
11
|
export const BOX_RULE = Object.freeze({ margin: 120, limit: 1600 });
|
|
12
|
-
/** A sheet's one answer slot, filled and not: the same frozen arrays for every sheet
|
|
12
|
+
/** A sheet's one answer slot, filled and not: the same frozen arrays for every sheet. */
|
|
13
13
|
const STROKED = Object.freeze([Object.freeze([true])]);
|
|
14
14
|
const BLANK = Object.freeze([Object.freeze([false])]);
|
|
15
15
|
/**
|
|
16
|
-
* What a sheet's one answer slot — anywhere on it, or the whole sheet — is filled with
|
|
16
|
+
* What a sheet's one answer slot — anywhere on it, or the whole sheet — is filled with: a
|
|
17
17
|
* stroke on the sheet, or none. The same array each time, as a workbook's filling stays the same
|
|
18
18
|
* until a box changes.
|
|
19
19
|
*/
|
|
@@ -69,7 +69,7 @@ export function cellOf(stroke, cells, rule = BOX_RULE) {
|
|
|
69
69
|
return chosen;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
|
-
* The table of the boxes the strokes fill
|
|
72
|
+
* The table of the boxes the strokes fill: each box that holds a stroke, in the order of
|
|
73
73
|
* `cells`, with the IDs of its strokes. A stroke ID twice is a TypeError.
|
|
74
74
|
*/
|
|
75
75
|
export function tableOf(strokes, cells, rule = BOX_RULE) {
|
package/lib/core/clock.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The sheet's clock: milliseconds of the sheet, never going back
|
|
2
|
+
* The sheet's clock: milliseconds of the sheet, never going back. The page's time it is
|
|
3
3
|
* given — a pointer event's `timeStamp`, or `performance.now()` for a method the consumer calls —
|
|
4
4
|
* both count from the page's time origin (DOM Standard; High Resolution Time), so one clock serves
|
|
5
|
-
* the strokes, the eraser and the actions of the sheet alike
|
|
6
|
-
* its first event; a sheet given a history of writing goes on from where that history leaves off
|
|
7
|
-
*
|
|
5
|
+
* the strokes, the eraser and the actions of the sheet alike. A new sheet's time starts at
|
|
6
|
+
* its first event; a sheet given a history of writing goes on from where that history leaves off:
|
|
7
|
+
* the sheet's time is its history's.
|
|
8
8
|
*/
|
|
9
9
|
export declare class Clock {
|
|
10
10
|
#private;
|
|
@@ -18,7 +18,7 @@ export declare class Clock {
|
|
|
18
18
|
get latest(): number;
|
|
19
19
|
/**
|
|
20
20
|
* The clock goes on at `t`: the next moment asked about is the sheet's `t`, whatever the page's
|
|
21
|
-
* time, and the clock counts on from there
|
|
21
|
+
* time, and the clock counts on from there. It may go back, when the sheet takes a history
|
|
22
22
|
* shorter than the one it had; `resume(0)` makes it a new sheet's clock.
|
|
23
23
|
*/
|
|
24
24
|
resume(t: number): void;
|
package/lib/core/clock.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The sheet's clock: milliseconds of the sheet, never going back
|
|
2
|
+
* The sheet's clock: milliseconds of the sheet, never going back. The page's time it is
|
|
3
3
|
* given — a pointer event's `timeStamp`, or `performance.now()` for a method the consumer calls —
|
|
4
4
|
* both count from the page's time origin (DOM Standard; High Resolution Time), so one clock serves
|
|
5
|
-
* the strokes, the eraser and the actions of the sheet alike
|
|
6
|
-
* its first event; a sheet given a history of writing goes on from where that history leaves off
|
|
7
|
-
*
|
|
5
|
+
* the strokes, the eraser and the actions of the sheet alike. A new sheet's time starts at
|
|
6
|
+
* its first event; a sheet given a history of writing goes on from where that history leaves off:
|
|
7
|
+
* the sheet's time is its history's.
|
|
8
8
|
*/
|
|
9
9
|
export class Clock {
|
|
10
10
|
#origin;
|
|
@@ -28,7 +28,7 @@ export class Clock {
|
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* The clock goes on at `t`: the next moment asked about is the sheet's `t`, whatever the page's
|
|
31
|
-
* time, and the clock counts on from there
|
|
31
|
+
* time, and the clock counts on from there. It may go back, when the sheet takes a history
|
|
32
32
|
* shorter than the one it had; `resume(0)` makes it a new sheet's clock.
|
|
33
33
|
*/
|
|
34
34
|
resume(t) {
|
package/lib/core/crop.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ 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
|
|
7
|
-
* The rule counts in whole numbers — places in tenths of a unit, as the groups do
|
|
6
|
+
* The crop's rule in its numbers: sizes on the crop in pixels, heights on the sheet in units.
|
|
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.
|
|
10
10
|
*/
|
|
11
11
|
export declare const CROP: Readonly<{
|
|
12
|
-
/** The margin around the work, px
|
|
12
|
+
/** The margin around the work, px. */
|
|
13
13
|
margin: 12;
|
|
14
14
|
/**
|
|
15
15
|
* A stroke lower than this, in units, is a line, not writing — a dot, a minus, a bar, an
|
|
@@ -31,7 +31,7 @@ export declare const CROP: Readonly<{
|
|
|
31
31
|
digit: 24;
|
|
32
32
|
/**
|
|
33
33
|
* The heights of digits a sample's crops are drawn at, px, as the eval protocol names them,
|
|
34
|
-
* beside the module's own
|
|
34
|
+
* beside the module's own.
|
|
35
35
|
*/
|
|
36
36
|
heights: readonly [16, 24, 32, 48];
|
|
37
37
|
/** The tallest digit a crop takes, px: its ink then still stays within the margin. */
|
|
@@ -39,13 +39,13 @@ export declare const CROP: Readonly<{
|
|
|
39
39
|
}>;
|
|
40
40
|
/**
|
|
41
41
|
* A group's frame on a crop: its label, and its ink in fractions 0–1000 of the crop, [ymin, xmin,
|
|
42
|
-
* ymax, xmax] — every pixel the ink of its strokes touches lies within it. spec's type
|
|
42
|
+
* ymax, xmax] — every pixel the ink of its strokes touches lies within it. spec's type.
|
|
43
43
|
*/
|
|
44
44
|
export type { Frame };
|
|
45
45
|
/**
|
|
46
|
-
* The crop of a sheet for checking
|
|
46
|
+
* The crop of a sheet for checking, all but its pixels: what lies where, at what scale. Its
|
|
47
47
|
* numbers the marks are placed by — D′, the size, the margins, `sheet_box`, the frames and the
|
|
48
|
-
* whole numbers they come from — are spec's CropNumbers
|
|
48
|
+
* whole numbers they come from — are spec's CropNumbers, and the rest the crop's own.
|
|
49
49
|
*/
|
|
50
50
|
export interface Crop extends CropNumbers {
|
|
51
51
|
/** D, the height of a digit asked for, px. */
|
|
@@ -58,24 +58,24 @@ export interface Crop extends CropNumbers {
|
|
|
58
58
|
readonly line: number;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
* The bundles of the strokes on a sheet
|
|
61
|
+
* The bundles of the strokes on a sheet: strokes no lower than `CROP.flat`, joined by a chain
|
|
62
62
|
* of boxes that touch or overlap, whenever each was written. Each bundle by its IDs ascending, the
|
|
63
63
|
* bundles by their smallest ID.
|
|
64
64
|
*/
|
|
65
65
|
export declare function bundlesOf(strokes: readonly Stroke[]): number[][];
|
|
66
|
-
/** h_med
|
|
66
|
+
/** h_med: the lower median of the heights of the bundles, in units; `CROP.flat` if none. */
|
|
67
67
|
export declare function medianOf(strokes: readonly Stroke[]): number;
|
|
68
68
|
/**
|
|
69
69
|
* The crop of the strokes on a sheet with its digits `digit` px high, and the frames of their
|
|
70
|
-
* groups
|
|
70
|
+
* groups: the strokes the sheet shows, and their groups by the sheet's rule. A sheet
|
|
71
71
|
* without strokes has no crop: it goes to no check (H3). On a task from paper the crop takes in
|
|
72
|
-
* `also` too, the tracing paper's rectangle in whole tenths, at the same scale
|
|
72
|
+
* `also` too, the tracing paper's rectangle in whole tenths, at the same scale.
|
|
73
73
|
*/
|
|
74
74
|
export declare function cropOf(strokes: readonly Stroke[], groups: readonly Group[], digit?: number, also?: Box): Crop | null;
|
|
75
75
|
/**
|
|
76
|
-
* Where a crop with its margins lies on the sheet, its `sheet_box
|
|
76
|
+
* Where a crop with its margins lies on the sheet, its `sheet_box`: [ymin, xmin, ymax, xmax]
|
|
77
77
|
* in units, each one division of two whole numbers, from the whole numbers of the crop. A
|
|
78
|
-
* submission's `sheet_box` is checked by it when the tutor's marks come back with it
|
|
78
|
+
* submission's `sheet_box` is checked by it when the tutor's marks come back with it.
|
|
79
79
|
*/
|
|
80
80
|
export declare function sheetBoxOf(crop: Pick<Crop, "drawn" | "width" | "height" | "margins" | "exact">): readonly [number, number, number, number];
|
|
81
81
|
/** What Claude counts an image as: ⌈w / 28⌉ × ⌈h / 28⌉ visual tokens, each a patch 28 px square. */
|
package/lib/core/crop.js
CHANGED
|
@@ -2,13 +2,13 @@ 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
|
|
6
|
-
* The rule counts in whole numbers — places in tenths of a unit, as the groups do
|
|
5
|
+
* The crop's rule in its numbers: sizes on the crop in pixels, heights on the sheet in units.
|
|
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.
|
|
9
9
|
*/
|
|
10
10
|
export const CROP = Object.freeze({
|
|
11
|
-
/** The margin around the work, px
|
|
11
|
+
/** The margin around the work, px. */
|
|
12
12
|
margin: 12,
|
|
13
13
|
/**
|
|
14
14
|
* A stroke lower than this, in units, is a line, not writing — a dot, a minus, a bar, an
|
|
@@ -30,14 +30,14 @@ export const CROP = Object.freeze({
|
|
|
30
30
|
digit: 24,
|
|
31
31
|
/**
|
|
32
32
|
* The heights of digits a sample's crops are drawn at, px, as the eval protocol names them,
|
|
33
|
-
* beside the module's own
|
|
33
|
+
* beside the module's own.
|
|
34
34
|
*/
|
|
35
35
|
heights: Object.freeze([16, 24, 32, 48]),
|
|
36
36
|
/** The tallest digit a crop takes, px: its ink then still stays within the margin. */
|
|
37
37
|
tallest: 256,
|
|
38
38
|
});
|
|
39
39
|
/**
|
|
40
|
-
* The bundles of the strokes on a sheet
|
|
40
|
+
* The bundles of the strokes on a sheet: strokes no lower than `CROP.flat`, joined by a chain
|
|
41
41
|
* of boxes that touch or overlap, whenever each was written. Each bundle by its IDs ascending, the
|
|
42
42
|
* bundles by their smallest ID.
|
|
43
43
|
*/
|
|
@@ -46,15 +46,15 @@ export function bundlesOf(strokes) {
|
|
|
46
46
|
.map((bundle) => bundle.map(({ id }) => id).sort(byNumber))
|
|
47
47
|
.sort((a, b) => (a[0] ?? 0) - (b[0] ?? 0));
|
|
48
48
|
}
|
|
49
|
-
/** h_med
|
|
49
|
+
/** h_med: the lower median of the heights of the bundles, in units; `CROP.flat` if none. */
|
|
50
50
|
export function medianOf(strokes) {
|
|
51
51
|
return medianTenths(extentsOf(strokes)) / 10;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* The crop of the strokes on a sheet with its digits `digit` px high, and the frames of their
|
|
55
|
-
* groups
|
|
55
|
+
* groups: the strokes the sheet shows, and their groups by the sheet's rule. A sheet
|
|
56
56
|
* without strokes has no crop: it goes to no check (H3). On a task from paper the crop takes in
|
|
57
|
-
* `also` too, the tracing paper's rectangle in whole tenths, at the same scale
|
|
57
|
+
* `also` too, the tracing paper's rectangle in whole tenths, at the same scale.
|
|
58
58
|
*/
|
|
59
59
|
export function cropOf(strokes, groups, digit = CROP.digit, also) {
|
|
60
60
|
if (!Number.isInteger(digit) || digit < 1 || digit > CROP.tallest) {
|
|
@@ -108,9 +108,9 @@ export function cropOf(strokes, groups, digit = CROP.digit, also) {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
|
-
* Where a crop with its margins lies on the sheet, its `sheet_box
|
|
111
|
+
* Where a crop with its margins lies on the sheet, its `sheet_box`: [ymin, xmin, ymax, xmax]
|
|
112
112
|
* in units, each one division of two whole numbers, from the whole numbers of the crop. A
|
|
113
|
-
* submission's `sheet_box` is checked by it when the tutor's marks come back with it
|
|
113
|
+
* submission's `sheet_box` is checked by it when the tutor's marks come back with it.
|
|
114
114
|
*/
|
|
115
115
|
export function sheetBoxOf(crop) {
|
|
116
116
|
const { drawn, width, height, margins: [top, left], exact: { box, median: unit }, } = crop;
|
package/lib/core/eraser.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ import type { Point } from "./screen.js";
|
|
|
4
4
|
/** `button` of a pen's eraser, its other end (Pointer Events Level 3). */
|
|
5
5
|
export declare const ERASER_BUTTON = 5;
|
|
6
6
|
/**
|
|
7
|
-
* The eraser
|
|
8
|
-
* near — a tap is a path of one point. The strokes it comes near are pending while it is
|
|
9
|
-
* when it lifts they go to the handler the eraser is made with, in one action, with the
|
|
10
|
-
* time of the lift: one undo brings them all back. `pointercancel` drops the press and
|
|
11
|
-
* nothing. One pointer erases at a time, with the primary button or a pen's eraser.
|
|
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. The strokes it comes near are pending while it is
|
|
9
|
+
* down, and when it lifts they go to the handler the eraser is made with, in one action, with the
|
|
10
|
+
* page's time of the lift: one undo brings them all back. `pointercancel` drops the press and
|
|
11
|
+
* erases nothing. One pointer erases at a time, with the primary button or a pen's eraser.
|
|
12
12
|
*/
|
|
13
13
|
export declare class Eraser {
|
|
14
14
|
#private;
|
|
@@ -32,7 +32,7 @@ export declare class Eraser {
|
|
|
32
32
|
move(sample: PointerSample, inSight?: boolean): boolean;
|
|
33
33
|
/** `pointerup`: the eraser goes on to where the pointer left, if in sight, and the press lands. */
|
|
34
34
|
up(sample: PointerSample, inSight?: boolean): boolean;
|
|
35
|
-
/** `pointercancel`: the device took the touch for an accident, and nothing is erased
|
|
35
|
+
/** `pointercancel`: the device took the touch for an accident, and nothing is erased. */
|
|
36
36
|
cancel(pointerId: number): boolean;
|
|
37
37
|
/**
|
|
38
38
|
* The press ends where the pointer last was, its `pointerup` never to come: the pointer's capture
|
package/lib/core/eraser.js
CHANGED
|
@@ -5,11 +5,11 @@ export const ERASER_BUTTON = 5;
|
|
|
5
5
|
const ERASER_HELD = 32;
|
|
6
6
|
const NONE = new Set();
|
|
7
7
|
/**
|
|
8
|
-
* The eraser
|
|
9
|
-
* near — a tap is a path of one point. The strokes it comes near are pending while it is
|
|
10
|
-
* when it lifts they go to the handler the eraser is made with, in one action, with the
|
|
11
|
-
* time of the lift: one undo brings them all back. `pointercancel` drops the press and
|
|
12
|
-
* nothing. One pointer erases at a time, with the primary button or a pen's eraser.
|
|
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. The strokes it comes near are pending while it is
|
|
10
|
+
* down, and when it lifts they go to the handler the eraser is made with, in one action, with the
|
|
11
|
+
* page's time of the lift: one undo brings them all back. `pointercancel` drops the press and
|
|
12
|
+
* erases nothing. One pointer erases at a time, with the primary button or a pen's eraser.
|
|
13
13
|
*/
|
|
14
14
|
export class Eraser {
|
|
15
15
|
#near;
|
|
@@ -84,7 +84,7 @@ export class Eraser {
|
|
|
84
84
|
this.#take(press, { x: sample.x, y: sample.y });
|
|
85
85
|
return this.#finish(sample.time);
|
|
86
86
|
}
|
|
87
|
-
/** `pointercancel`: the device took the touch for an accident, and nothing is erased
|
|
87
|
+
/** `pointercancel`: the device took the touch for an accident, and nothing is erased. */
|
|
88
88
|
cancel(pointerId) {
|
|
89
89
|
if (this.#press?.pointerId !== pointerId)
|
|
90
90
|
return false;
|
package/lib/core/example.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { DemoState } from "@altnovatrail/spec/canvas";
|
|
|
2
2
|
import type * as open from "@altnovatrail/spec/formatv0/open";
|
|
3
3
|
import type { GridKind } from "./grid.js";
|
|
4
4
|
import { type PicturePart, SHEET_KIND, type StatementPart, type Template, type TextPart, WORKBOOK_KIND, type Zone } from "./task.js";
|
|
5
|
-
/** A lesson's worked example as a consumer gives it: spec's type
|
|
5
|
+
/** A lesson's worked example as a consumer gives it: spec's type. */
|
|
6
6
|
export type WorkedExample = open.WorkedExample;
|
|
7
7
|
/**
|
|
8
8
|
* What a worked example is shown on, as the element checked it: a handwriting sheet and its grid,
|
|
@@ -61,9 +61,9 @@ export interface CheckedExample {
|
|
|
61
61
|
readonly demo: readonly ExamplePart[];
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
|
-
* How far the learner has gone through the author's demo
|
|
64
|
+
* How far the learner has gone through the author's demo: how many of its parts are open,
|
|
65
65
|
* from the first, and whether the whole demo is hidden. app keeps it and may give it back. spec's
|
|
66
|
-
* type
|
|
66
|
+
* type.
|
|
67
67
|
*/
|
|
68
68
|
export type { DemoState };
|
|
69
69
|
/** Where every demo starts: no part open, and nothing hidden. One for every element. */
|
|
@@ -76,7 +76,7 @@ export declare const DEMO_START: DemoState;
|
|
|
76
76
|
*/
|
|
77
77
|
export declare function exampleOf(value: unknown): CheckedExample;
|
|
78
78
|
/**
|
|
79
|
-
* What the canvas makes of a worked example, as of a task
|
|
79
|
+
* What the canvas makes of a worked example, as of a task: the grid on the sheet, or the
|
|
80
80
|
* example's lines laid out on the workbook's page as a task's are, its boxes empty till the demo
|
|
81
81
|
* fills them; the statement above it, and the pen alone, for the learner does not write on it.
|
|
82
82
|
*/
|
|
@@ -91,7 +91,7 @@ export declare function filledBy(example: CheckedExample, { opened, hidden }: De
|
|
|
91
91
|
/** What a fill of the demo writes: the value of its box, which the check found among the lines. */
|
|
92
92
|
export declare function fillValue(example: CheckedExample, { fill }: FillPart): string;
|
|
93
93
|
/**
|
|
94
|
-
* The state of a demo of `parts` parts, checked
|
|
94
|
+
* The state of a demo of `parts` parts, checked: an object of `opened`, a whole number from 0
|
|
95
95
|
* to `parts`, and `hidden`, true or false, both of them and nothing else. What it refuses is a
|
|
96
96
|
* TypeError that names the field by its path. It gives a frozen copy of its own.
|
|
97
97
|
*/
|
|
@@ -99,7 +99,7 @@ export declare function demoStateOf(value: unknown, parts: number): DemoState;
|
|
|
99
99
|
/** Whether a part of the demo stands on the sheet, in an area of it. */
|
|
100
100
|
export declare function onSheet(part: ExamplePart): part is AreaPicture;
|
|
101
101
|
/**
|
|
102
|
-
* Whether two worked examples show the same
|
|
102
|
+
* Whether two worked examples show the same: the same statement, the same grid — its kind and
|
|
103
103
|
* step as drawn, the defaults filled in — and the same parts of the demo in the same order.
|
|
104
104
|
*/
|
|
105
105
|
export declare function sameExample(a: CheckedExample, b: CheckedExample): boolean;
|
package/lib/core/example.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// A lesson's worked example
|
|
2
|
-
// type WorkedExample
|
|
1
|
+
// A lesson's worked example: the open view of a segment `worked_example`, of spec's
|
|
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
|
|
5
|
-
// element checks it as the schema does, every object closed
|
|
4
|
+
// pictures on areas of a sheet, and on a workbook the boxes it fills. The
|
|
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
|
|
8
8
|
// check gives is the element's own shape of the same example, the kinds of its parts apart, which
|
|
@@ -19,7 +19,7 @@ export const DEMO_START = Object.freeze({ opened: 0, hidden: false });
|
|
|
19
19
|
const ROOT = "workedExample";
|
|
20
20
|
/** The path the element names the state of a demo's fields by: its property's name. */
|
|
21
21
|
const STATE = "demoState";
|
|
22
|
-
/** A worked example's tools: the pen alone, which writes nothing on its sheet
|
|
22
|
+
/** A worked example's tools: the pen alone, which writes nothing on its sheet. */
|
|
23
23
|
const PEN_ALONE = Object.freeze(["pen"]);
|
|
24
24
|
/**
|
|
25
25
|
* A worked example's open view, checked as the format's schema and its rule lesson.areas check it,
|
|
@@ -57,7 +57,7 @@ export function exampleOf(value) {
|
|
|
57
57
|
return { statement, canvas, lines, demo: fillsOf(parts, lines) };
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* What the canvas makes of a worked example, as of a task
|
|
60
|
+
* What the canvas makes of a worked example, as of a task: the grid on the sheet, or the
|
|
61
61
|
* example's lines laid out on the workbook's page as a task's are, its boxes empty till the demo
|
|
62
62
|
* fills them; the statement above it, and the pen alone, for the learner does not write on it.
|
|
63
63
|
*/
|
|
@@ -95,7 +95,7 @@ function boxesOf(line) {
|
|
|
95
95
|
return (line?.line ?? []).filter((piece) => "value" in piece);
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
|
-
* The state of a demo of `parts` parts, checked
|
|
98
|
+
* The state of a demo of `parts` parts, checked: an object of `opened`, a whole number from 0
|
|
99
99
|
* to `parts`, and `hidden`, true or false, both of them and nothing else. What it refuses is a
|
|
100
100
|
* TypeError that names the field by its path. It gives a frozen copy of its own.
|
|
101
101
|
*/
|
|
@@ -112,7 +112,7 @@ export function onSheet(part) {
|
|
|
112
112
|
return "area" in part;
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
|
-
* Whether two worked examples show the same
|
|
115
|
+
* Whether two worked examples show the same: the same statement, the same grid — its kind and
|
|
116
116
|
* step as drawn, the defaults filled in — and the same parts of the demo in the same order.
|
|
117
117
|
*/
|
|
118
118
|
export function sameExample(a, b) {
|
|
@@ -137,7 +137,7 @@ function sameLine(a, b) {
|
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* What a worked example is shown on: a handwriting sheet and its grid, or a workbook, and no tools,
|
|
140
|
-
* for the learner does not write on it
|
|
140
|
+
* for the learner does not write on it.
|
|
141
141
|
*/
|
|
142
142
|
function exampleCanvasOf(value, path) {
|
|
143
143
|
const canvas = closed(value, path, ["kind", "grid", "grid_step"], "a worked example's canvas");
|
package/lib/core/fields.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/** The fields of an object; anything else is a TypeError at `path`. */
|
|
7
7
|
export declare function record(value: unknown, path: string): Record<string, unknown>;
|
|
8
8
|
/**
|
|
9
|
-
* The fields of an object closed as the module format closes its objects
|
|
9
|
+
* The fields of an object closed as the module format closes its objects, read once into a
|
|
10
10
|
* record of their own: a field it does not name is a TypeError at that field's path. A field left
|
|
11
11
|
* out by `undefined` is no field, and is not in the record.
|
|
12
12
|
*/
|
package/lib/core/fields.js
CHANGED
|
@@ -11,7 +11,7 @@ export function record(value, path) {
|
|
|
11
11
|
return value;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* The fields of an object closed as the module format closes its objects
|
|
14
|
+
* The fields of an object closed as the module format closes its objects, read once into a
|
|
15
15
|
* record of their own: a field it does not name is a TypeError at that field's path. A field left
|
|
16
16
|
* out by `undefined` is no field, and is not in the record.
|
|
17
17
|
*/
|
package/lib/core/geometry.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Stroke } from "./ink.js";
|
|
2
2
|
import type { Point } from "./screen.js";
|
|
3
3
|
/**
|
|
4
|
-
* A rectangle on the sheet, as rbush takes one
|
|
4
|
+
* A rectangle on the sheet, as rbush takes one: in units, or in tenths of a unit where the
|
|
5
5
|
* rules count in whole numbers. The contract's Box, spec's, is one in tenths: of a crop's numbers.
|
|
6
6
|
*/
|
|
7
7
|
export interface Box {
|
|
@@ -11,8 +11,8 @@ export interface Box {
|
|
|
11
11
|
readonly maxY: number;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* A length or a place in whole tenths of a unit, as a sample file keeps them
|
|
15
|
-
* up: 100.05 units, 1000.5 tenths, are 1001. The groups and the crop count in them
|
|
14
|
+
* A length or a place in whole tenths of a unit, as a sample file keeps them, rounded half
|
|
15
|
+
* up: 100.05 units, 1000.5 tenths, are 1001. The groups and the crop count in them.
|
|
16
16
|
*/
|
|
17
17
|
export declare function tenths(value: number): number;
|
|
18
18
|
/** A stroke's box in whole tenths, with its ID: what the crop and the boxes' rule count by. */
|
|
@@ -20,9 +20,10 @@ export interface Extent extends Box {
|
|
|
20
20
|
readonly id: number;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* The box of a stroke's points in whole tenths
|
|
23
|
+
* The box of a stroke's points in whole tenths: rounding keeps order, so its edges are
|
|
24
24
|
* the rounded least and most of the points. A stroke with no points is a TypeError, and one with a
|
|
25
|
-
* point off the sheet, or no number, a RangeError: the rules' whole numbers hold on the sheet
|
|
25
|
+
* point off the sheet, or no number, a RangeError: the rules' whole numbers hold on the sheet
|
|
26
|
+
* alone.
|
|
26
27
|
*/
|
|
27
28
|
export declare function extentOf({ id, points }: Stroke): Extent;
|
|
28
29
|
/** The box around a stroke's points, the raw points rather than the ink's outline. */
|
package/lib/core/geometry.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { REACH } from "./sheet.js";
|
|
2
2
|
/**
|
|
3
|
-
* A length or a place in whole tenths of a unit, as a sample file keeps them
|
|
4
|
-
* up: 100.05 units, 1000.5 tenths, are 1001. The groups and the crop count in them
|
|
3
|
+
* A length or a place in whole tenths of a unit, as a sample file keeps them, rounded half
|
|
4
|
+
* up: 100.05 units, 1000.5 tenths, are 1001. The groups and the crop count in them.
|
|
5
5
|
*/
|
|
6
6
|
export function tenths(value) {
|
|
7
7
|
return Math.round(value * 10);
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* The box of a stroke's points in whole tenths
|
|
10
|
+
* The box of a stroke's points in whole tenths: rounding keeps order, so its edges are
|
|
11
11
|
* the rounded least and most of the points. A stroke with no points is a TypeError, and one with a
|
|
12
|
-
* point off the sheet, or no number, a RangeError: the rules' whole numbers hold on the sheet
|
|
12
|
+
* point off the sheet, or no number, a RangeError: the rules' whole numbers hold on the sheet
|
|
13
|
+
* alone.
|
|
13
14
|
*/
|
|
14
15
|
export function extentOf({ id, points }) {
|
|
15
16
|
if (points.length === 0)
|
|
@@ -88,8 +89,9 @@ function pointDistance(p, a, b) {
|
|
|
88
89
|
return Math.hypot(p.x - (a.x + along * dx), p.y - (a.y + along * dy));
|
|
89
90
|
}
|
|
90
91
|
/**
|
|
91
|
-
* Whether ab and cd cross: each segment's ends lie on either side of the other's line. Segments
|
|
92
|
-
* only touch, or lie along one line, are left to the distances of their ends, which are 0
|
|
92
|
+
* Whether ab and cd cross: each segment's ends lie on either side of the other's line. Segments
|
|
93
|
+
* that only touch, or lie along one line, are left to the distances of their ends, which are 0
|
|
94
|
+
* then.
|
|
93
95
|
*/
|
|
94
96
|
function crosses(a, b, c, d) {
|
|
95
97
|
const abc = turn(a, b, c);
|
package/lib/core/grid.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface Grid {
|
|
|
7
7
|
readonly step: number;
|
|
8
8
|
}
|
|
9
9
|
export declare const GRID_KINDS: readonly GridKind[];
|
|
10
|
-
/** The step of a grid whose task gives none, in units: canvas-api's square
|
|
10
|
+
/** The step of a grid whose task gives none, in units: canvas-api's square. */
|
|
11
11
|
export declare const GRID_STEP = 50;
|
|
12
12
|
/**
|
|
13
13
|
* The steps a task may give, in units. A finer grid would be thousands of dots, and one wider than
|
|
@@ -17,7 +17,7 @@ export declare const GRID_STEP_MIN = 20;
|
|
|
17
17
|
export declare const GRID_STEP_MAX = 500;
|
|
18
18
|
/**
|
|
19
19
|
* The grid of a sheet whose task gives none, or that has no task: squares of 50 units. spec knows
|
|
20
|
-
* no sheet without a grid
|
|
20
|
+
* no sheet without a grid.
|
|
21
21
|
*/
|
|
22
22
|
export declare const DEFAULT_GRID: Grid;
|
|
23
23
|
/**
|
|
@@ -29,6 +29,6 @@ export declare function gridPath(grid: Grid, size?: Size): string;
|
|
|
29
29
|
/**
|
|
30
30
|
* A grid's path on a band of the sheet across its whole width, from `top` to `bottom` in units,
|
|
31
31
|
* either of them past the sheet: its rulings at the step's multiples within the band, both ends
|
|
32
|
-
* taken, so that they go on from the sheet's own above or below it
|
|
32
|
+
* taken, so that they go on from the sheet's own above or below it.
|
|
33
33
|
*/
|
|
34
34
|
export declare function gridBand(grid: Grid, width: number, top: number, bottom: number): string;
|
package/lib/core/grid.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SHEET } from "./sheet.js";
|
|
2
2
|
export const GRID_KINDS = ["squares", "lines", "dots"];
|
|
3
|
-
/** The step of a grid whose task gives none, in units: canvas-api's square
|
|
3
|
+
/** The step of a grid whose task gives none, in units: canvas-api's square. */
|
|
4
4
|
export const GRID_STEP = 50;
|
|
5
5
|
/**
|
|
6
6
|
* The steps a task may give, in units. A finer grid would be thousands of dots, and one wider than
|
|
@@ -10,7 +10,7 @@ export const GRID_STEP_MIN = 20;
|
|
|
10
10
|
export const GRID_STEP_MAX = 500;
|
|
11
11
|
/**
|
|
12
12
|
* The grid of a sheet whose task gives none, or that has no task: squares of 50 units. spec knows
|
|
13
|
-
* no sheet without a grid
|
|
13
|
+
* no sheet without a grid.
|
|
14
14
|
*/
|
|
15
15
|
export const DEFAULT_GRID = Object.freeze({ kind: "squares", step: GRID_STEP });
|
|
16
16
|
/**
|
|
@@ -48,7 +48,7 @@ function rulings(step, length) {
|
|
|
48
48
|
/**
|
|
49
49
|
* A grid's path on a band of the sheet across its whole width, from `top` to `bottom` in units,
|
|
50
50
|
* either of them past the sheet: its rulings at the step's multiples within the band, both ends
|
|
51
|
-
* taken, so that they go on from the sheet's own above or below it
|
|
51
|
+
* taken, so that they go on from the sheet's own above or below it.
|
|
52
52
|
*/
|
|
53
53
|
export function gridBand(grid, width, top, bottom) {
|
|
54
54
|
const xs = rulings(grid.step, width);
|