@altnovatrail/canvas 0.3.36 → 0.3.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/geometry.js +2 -2
- package/lib/core/grid.d.ts +11 -4
- package/lib/core/grid.js +33 -8
- package/lib/core/hands.d.ts +7 -7
- package/lib/core/hands.js +5 -5
- package/lib/core/history.js +3 -3
- package/lib/core/marks.d.ts +2 -0
- package/lib/core/marks.js +11 -6
- package/lib/core/screen.d.ts +10 -11
- package/lib/core/screen.js +13 -14
- package/lib/core/sheet.d.ts +46 -3
- package/lib/core/sheet.js +46 -3
- package/lib/core/submission.js +5 -1
- package/lib/core/task.d.ts +9 -4
- package/lib/core/task.js +7 -2
- package/lib/core/tracing.d.ts +49 -13
- package/lib/core/tracing.js +110 -31
- package/lib/element/icons.d.ts +81 -14
- package/lib/element/icons.js +82 -15
- package/lib/element/index.d.ts +32 -13
- package/lib/element/index.js +619 -246
- package/lib/element/labels.d.ts +29 -7
- package/lib/element/labels.js +32 -9
- package/lib/element/session.d.ts +0 -3
- package/lib/element/session.js +4 -8
- package/lib/element/tools.d.ts +30 -19
- package/lib/element/tools.js +80 -62
- package/lib/element/tracing.d.ts +49 -5
- package/lib/element/tracing.js +419 -10
- package/package.json +3 -3
- package/lib/core/zoom.d.ts +0 -23
- package/lib/core/zoom.js +0 -43
package/lib/core/geometry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { REACH } from "./sheet.js";
|
|
2
2
|
/**
|
|
3
3
|
* A length or a place in whole tenths of a unit, as a sample file keeps them (R09), rounded half
|
|
4
4
|
* up: 100.05 units, 1000.5 tenths, are 1001. The groups and the crop count in them (R24, R25).
|
|
@@ -19,7 +19,7 @@ export function extentOf({ id, points }) {
|
|
|
19
19
|
let maxX = Number.NEGATIVE_INFINITY;
|
|
20
20
|
let maxY = Number.NEGATIVE_INFINITY;
|
|
21
21
|
for (const { x, y } of points) {
|
|
22
|
-
if (!onSheet(x,
|
|
22
|
+
if (!onSheet(x, REACH.width) || !onSheet(y, REACH.height)) {
|
|
23
23
|
throw new RangeError(`the stroke ${id} has a point (${x}, ${y}) off the sheet`);
|
|
24
24
|
}
|
|
25
25
|
minX = Math.min(minX, tenths(x));
|
package/lib/core/grid.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Size } from "./sheet.js";
|
|
1
2
|
/** How a task rules the sheet: in squares, in lines or in dots. */
|
|
2
3
|
export type GridKind = "squares" | "lines" | "dots";
|
|
3
4
|
/** The grid of a sheet: its kind and its step, in sheet units. */
|
|
@@ -20,8 +21,14 @@ export declare const GRID_STEP_MAX = 500;
|
|
|
20
21
|
*/
|
|
21
22
|
export declare const DEFAULT_GRID: Grid;
|
|
22
23
|
/**
|
|
23
|
-
* A grid's path in SVG, in sheet units: a line along every ruling, strictly inside the sheet
|
|
24
|
-
*
|
|
25
|
-
* dot.
|
|
24
|
+
* A grid's path in SVG, in sheet units: a line along every ruling, strictly inside the sheet as
|
|
25
|
+
* large as `size` — the page, unless the sheet is laid out larger —, or, for dots, a dot where two
|
|
26
|
+
* rulings cross — a subpath of no length, which a round cap draws as a dot.
|
|
26
27
|
*/
|
|
27
|
-
export declare function gridPath(grid: Grid): string;
|
|
28
|
+
export declare function gridPath(grid: Grid, size?: Size): string;
|
|
29
|
+
/**
|
|
30
|
+
* A grid's path on a band of the sheet across its whole width, from `top` to `bottom` in units,
|
|
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 (R73).
|
|
33
|
+
*/
|
|
34
|
+
export declare function gridBand(grid: Grid, width: number, top: number, bottom: number): string;
|
package/lib/core/grid.js
CHANGED
|
@@ -14,15 +14,15 @@ export const GRID_STEP_MAX = 500;
|
|
|
14
14
|
*/
|
|
15
15
|
export const DEFAULT_GRID = Object.freeze({ kind: "squares", step: GRID_STEP });
|
|
16
16
|
/**
|
|
17
|
-
* A grid's path in SVG, in sheet units: a line along every ruling, strictly inside the sheet
|
|
18
|
-
*
|
|
19
|
-
* dot.
|
|
17
|
+
* A grid's path in SVG, in sheet units: a line along every ruling, strictly inside the sheet as
|
|
18
|
+
* large as `size` — the page, unless the sheet is laid out larger —, or, for dots, a dot where two
|
|
19
|
+
* rulings cross — a subpath of no length, which a round cap draws as a dot.
|
|
20
20
|
*/
|
|
21
|
-
export function gridPath(grid) {
|
|
22
|
-
const xs = rulings(grid.step,
|
|
23
|
-
const ys = rulings(grid.step,
|
|
24
|
-
const down = xs.map((x) => `M${x} 0V${
|
|
25
|
-
const across = ys.map((y) => `M0 ${y}H${
|
|
21
|
+
export function gridPath(grid, size = SHEET) {
|
|
22
|
+
const xs = rulings(grid.step, size.width);
|
|
23
|
+
const ys = rulings(grid.step, size.height);
|
|
24
|
+
const down = xs.map((x) => `M${x} 0V${size.height}`);
|
|
25
|
+
const across = ys.map((y) => `M0 ${y}H${size.width}`);
|
|
26
26
|
switch (grid.kind) {
|
|
27
27
|
case "squares":
|
|
28
28
|
return [...down, ...across].join("");
|
|
@@ -45,3 +45,28 @@ function rulings(step, length) {
|
|
|
45
45
|
places.push(place);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* A grid's path on a band of the sheet across its whole width, from `top` to `bottom` in units,
|
|
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 (R73).
|
|
52
|
+
*/
|
|
53
|
+
export function gridBand(grid, width, top, bottom) {
|
|
54
|
+
const xs = rulings(grid.step, width);
|
|
55
|
+
const ys = [];
|
|
56
|
+
for (let i = Math.ceil(top / grid.step - 1e-9);; i++) {
|
|
57
|
+
const place = Math.round(i * grid.step * 1000) / 1000;
|
|
58
|
+
if (place > bottom)
|
|
59
|
+
break;
|
|
60
|
+
ys.push(place);
|
|
61
|
+
}
|
|
62
|
+
const down = xs.map((x) => `M${x} ${top}V${bottom}`);
|
|
63
|
+
const across = ys.map((y) => `M0 ${y}H${width}`);
|
|
64
|
+
switch (grid.kind) {
|
|
65
|
+
case "squares":
|
|
66
|
+
return [...down, ...across].join("");
|
|
67
|
+
case "lines":
|
|
68
|
+
return across.join("");
|
|
69
|
+
case "dots":
|
|
70
|
+
return ys.flatMap((y) => xs.map((x) => `M${x} ${y}h0`)).join("");
|
|
71
|
+
}
|
|
72
|
+
}
|
package/lib/core/hands.d.ts
CHANGED
|
@@ -41,17 +41,17 @@ export declare const SLOP_PX = 8;
|
|
|
41
41
|
/**
|
|
42
42
|
* Two fingers that have gone this many times further along one axis than along the other, when
|
|
43
43
|
* they pass the slop, scroll along that axis alone for the rest of the gesture (R73): a scroll
|
|
44
|
-
* down a
|
|
44
|
+
* down a sheet does not wander sideways, nor one across it up and down. Between, they go
|
|
45
45
|
* both ways.
|
|
46
46
|
*/
|
|
47
47
|
export declare const RAIL = 2;
|
|
48
48
|
/**
|
|
49
|
-
* The pen mode (R29): on from a pen's touch on a sheet,
|
|
50
|
-
*
|
|
49
|
+
* The pen mode (R29): on from a pen's touch on a sheet, till the page goes, with no button that
|
|
50
|
+
* turns it off: while it is on, a finger neither writes nor erases, and moves the sheet (R84). One is shared by every sheet of a page, and
|
|
51
51
|
* it lives in memory alone: nothing is stored or sent, and a new page starts without it.
|
|
52
52
|
*
|
|
53
|
-
* It knows, too, whether any sheet of the page is written on
|
|
54
|
-
*
|
|
53
|
+
* It knows, too, whether any sheet of the page is written on, and tells its sheets when the last
|
|
54
|
+
* stroke ends: each bar shows the mode as it is then.
|
|
55
55
|
*/
|
|
56
56
|
export declare class PenMode {
|
|
57
57
|
#private;
|
|
@@ -82,8 +82,8 @@ export interface HandsSheet {
|
|
|
82
82
|
*/
|
|
83
83
|
scroll(dx: number, dy: number, fresh: boolean): void;
|
|
84
84
|
/**
|
|
85
|
-
* Whether the sheet scrolls across at all now:
|
|
86
|
-
* that does not goes by its travel down alone.
|
|
85
|
+
* Whether the sheet scrolls across at all now: one wider than its container does (R73). A
|
|
86
|
+
* gesture on a sheet that does not goes by its travel down alone.
|
|
87
87
|
*/
|
|
88
88
|
across(): boolean;
|
|
89
89
|
}
|
package/lib/core/hands.js
CHANGED
|
@@ -18,17 +18,17 @@ export const SLOP_PX = 8;
|
|
|
18
18
|
/**
|
|
19
19
|
* Two fingers that have gone this many times further along one axis than along the other, when
|
|
20
20
|
* they pass the slop, scroll along that axis alone for the rest of the gesture (R73): a scroll
|
|
21
|
-
* down a
|
|
21
|
+
* down a sheet does not wander sideways, nor one across it up and down. Between, they go
|
|
22
22
|
* both ways.
|
|
23
23
|
*/
|
|
24
24
|
export const RAIL = 2;
|
|
25
25
|
/**
|
|
26
|
-
* The pen mode (R29): on from a pen's touch on a sheet,
|
|
27
|
-
*
|
|
26
|
+
* The pen mode (R29): on from a pen's touch on a sheet, till the page goes, with no button that
|
|
27
|
+
* turns it off: while it is on, a finger neither writes nor erases, and moves the sheet (R84). One is shared by every sheet of a page, and
|
|
28
28
|
* it lives in memory alone: nothing is stored or sent, and a new page starts without it.
|
|
29
29
|
*
|
|
30
|
-
* It knows, too, whether any sheet of the page is written on
|
|
31
|
-
*
|
|
30
|
+
* It knows, too, whether any sheet of the page is written on, and tells its sheets when the last
|
|
31
|
+
* stroke ends: each bar shows the mode as it is then.
|
|
32
32
|
*/
|
|
33
33
|
export class PenMode {
|
|
34
34
|
#on = false;
|
package/lib/core/history.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { record, shown } from "./fields.js";
|
|
2
|
-
import {
|
|
2
|
+
import { REACH } from "./sheet.js";
|
|
3
3
|
/**
|
|
4
4
|
* The strokes a history leaves on the sheet, in the order they were written: what the sheet shows
|
|
5
5
|
* after it (R09).
|
|
@@ -194,8 +194,8 @@ function strokeOf(value, path) {
|
|
|
194
194
|
const points = Array.from(fields.points, (item, n) => {
|
|
195
195
|
const at = `${path}.points[${n}]`;
|
|
196
196
|
const point = record(item, at);
|
|
197
|
-
const x = within(point.x, `${at}.x`, 0,
|
|
198
|
-
const y = within(point.y, `${at}.y`, 0,
|
|
197
|
+
const x = within(point.x, `${at}.x`, 0, REACH.width);
|
|
198
|
+
const y = within(point.y, `${at}.y`, 0, REACH.height);
|
|
199
199
|
const t = timeOf(point.t, `${at}.t`);
|
|
200
200
|
if (t < latest) {
|
|
201
201
|
throw new TypeError(`${at}.t: ${t}, earlier than the point before it, at ${latest}`);
|
package/lib/core/marks.d.ts
CHANGED
|
@@ -56,6 +56,8 @@ export type { Anchor, CellPlace, CropNumbers, Mark, Marks, PaperSubmission, Shee
|
|
|
56
56
|
*/
|
|
57
57
|
export interface Paper {
|
|
58
58
|
readonly at: readonly [number, number];
|
|
59
|
+
/** The tracing paper's scale (R89). */
|
|
60
|
+
readonly scale: number;
|
|
59
61
|
readonly onTracing: (id: number) => boolean;
|
|
60
62
|
}
|
|
61
63
|
/**
|
package/lib/core/marks.js
CHANGED
|
@@ -2,7 +2,7 @@ import { CROP, sheetBoxOf } from "./crop.js";
|
|
|
2
2
|
import { record, shown, whole } from "./fields.js";
|
|
3
3
|
import { around, boxOf, tenths } from "./geometry.js";
|
|
4
4
|
import { adler32, crc32 } from "./png.js";
|
|
5
|
-
import {
|
|
5
|
+
import { REACH } from "./sheet.js";
|
|
6
6
|
import { tracingFieldsOf } from "./tracing.js";
|
|
7
7
|
/**
|
|
8
8
|
* The rule the sheet snaps by (R26): a quarter of a digit — 6 px at 24, a quarter of H on the
|
|
@@ -112,6 +112,9 @@ export function placesOf(marks, known, cells = null, rule = SNAP_RULE, paper) {
|
|
|
112
112
|
if (traced.at[0] !== paper.at[0] || traced.at[1] !== paper.at[1]) {
|
|
113
113
|
throw new TypeError(`marks.submission.tracing.at: ${shown(traced.at)}, and the tracing paper lies at ${shown(paper.at)}: the submission's strokes lie elsewhere`);
|
|
114
114
|
}
|
|
115
|
+
if ((traced.scale ?? 1) !== paper.scale) {
|
|
116
|
+
throw new TypeError(`marks.submission.tracing.scale: ${shown(traced.scale ?? 1)}, and the tracing paper's scale is ${shown(paper.scale)}: the submission's strokes lie elsewhere`);
|
|
117
|
+
}
|
|
115
118
|
}
|
|
116
119
|
const { crop, groups, digest } = submission;
|
|
117
120
|
const sent = [];
|
|
@@ -245,7 +248,9 @@ export function digestOf(strokes, crop, groups, paper) {
|
|
|
245
248
|
.map(({ id }) => id)
|
|
246
249
|
.filter((id) => paper.onTracing(id))
|
|
247
250
|
.sort(byNumber);
|
|
248
|
-
|
|
251
|
+
// A scale of 1 adds nothing, so a digest made before scales came stays the same (R89).
|
|
252
|
+
const scale = paper.scale === 1 ? "" : ` ${paper.scale}`;
|
|
253
|
+
lines.push(`tracing ${tenths(paper.at[0])} ${tenths(paper.at[1])} ${traced.join(",")}${scale}`);
|
|
249
254
|
}
|
|
250
255
|
return sumOf(lines);
|
|
251
256
|
}
|
|
@@ -461,10 +466,10 @@ function numbersOf(value, path, groups) {
|
|
|
461
466
|
const exact = record(crop.exact, `${path}.exact`);
|
|
462
467
|
const median = whole(exact.median, `${path}.exact.median`, CROP.flat * 10, CROP.ceiling * 10);
|
|
463
468
|
const points = record(exact.box, `${path}.exact.box`);
|
|
464
|
-
const minX = whole(points.minX, `${path}.exact.box.minX`, 0,
|
|
465
|
-
const minY = whole(points.minY, `${path}.exact.box.minY`, 0,
|
|
466
|
-
const maxX = whole(points.maxX, `${path}.exact.box.maxX`, minX,
|
|
467
|
-
const maxY = whole(points.maxY, `${path}.exact.box.maxY`, minY,
|
|
469
|
+
const minX = whole(points.minX, `${path}.exact.box.minX`, 0, REACH.width * 10);
|
|
470
|
+
const minY = whole(points.minY, `${path}.exact.box.minY`, 0, REACH.height * 10);
|
|
471
|
+
const maxX = whole(points.maxX, `${path}.exact.box.maxX`, minX, REACH.width * 10);
|
|
472
|
+
const maxY = whole(points.maxY, `${path}.exact.box.maxY`, minY, REACH.height * 10);
|
|
468
473
|
const numbers = {
|
|
469
474
|
drawn,
|
|
470
475
|
width,
|
package/lib/core/screen.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Where the sheet is on the screen, one view for every layer (R06): `k` CSS pixels to a logical
|
|
3
|
-
* unit, for the
|
|
4
|
-
*
|
|
3
|
+
* unit, for the page fits the width of its area, and `vx` and `vy`, the left and the top of the
|
|
4
|
+
* sheet's visible part, in units.
|
|
5
5
|
*/
|
|
6
6
|
export interface View {
|
|
7
7
|
readonly k: number;
|
|
@@ -14,19 +14,18 @@ export interface Point {
|
|
|
14
14
|
readonly y: number;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* The most CSS pixels to a unit
|
|
18
|
-
*
|
|
19
|
-
* The page's zoom takes it beyond that, to twice the fit (R73).
|
|
17
|
+
* The most CSS pixels to a unit: on a wide screen the page is 1000 CSS pixels wide, a pixel to a
|
|
18
|
+
* unit as on the picture of the work, at the sheet's left, and the sheet goes on past it (R23).
|
|
20
19
|
*/
|
|
21
20
|
export declare const K_MAX = 1;
|
|
22
|
-
/** `k` of a sheet `width` CSS pixels wide as it is on the screen: k = A / W. */
|
|
23
|
-
export declare function scaleFor(width: number): number;
|
|
21
|
+
/** `k` of a sheet `width` CSS pixels wide as it is on the screen, `across` units wide: k = A / W. */
|
|
22
|
+
export declare function scaleFor(width: number, across?: number): number;
|
|
24
23
|
/**
|
|
25
|
-
* `k` for a sheet laid out in an area `width` CSS pixels wide:
|
|
26
|
-
*
|
|
27
|
-
*
|
|
24
|
+
* `k` for a sheet laid out in an area `width` CSS pixels wide: the page fits the width, up to
|
|
25
|
+
* `K_MAX`. This is the layout's `k`, before any transform the page puts on the element; input takes
|
|
26
|
+
* `k` from the sheet's rectangle on the screen, by `scaleFor`.
|
|
28
27
|
*/
|
|
29
|
-
export declare function fitScale(width: number
|
|
28
|
+
export declare function fitScale(width: number): number;
|
|
30
29
|
/**
|
|
31
30
|
* The point of the sheet under a point of the screen, given in CSS pixels from the top left corner
|
|
32
31
|
* of the sheet's visible part. A point beyond the sheet is clamped to its edge: a pointer captured
|
package/lib/core/screen.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { SHEET } from "./sheet.js";
|
|
1
|
+
import { REACH, SHEET } from "./sheet.js";
|
|
2
2
|
/**
|
|
3
|
-
* The most CSS pixels to a unit
|
|
4
|
-
*
|
|
5
|
-
* The page's zoom takes it beyond that, to twice the fit (R73).
|
|
3
|
+
* The most CSS pixels to a unit: on a wide screen the page is 1000 CSS pixels wide, a pixel to a
|
|
4
|
+
* unit as on the picture of the work, at the sheet's left, and the sheet goes on past it (R23).
|
|
6
5
|
*/
|
|
7
6
|
export const K_MAX = 1;
|
|
8
|
-
/** `k` of a sheet `width` CSS pixels wide as it is on the screen: k = A / W. */
|
|
9
|
-
export function scaleFor(width) {
|
|
10
|
-
return width /
|
|
7
|
+
/** `k` of a sheet `width` CSS pixels wide as it is on the screen, `across` units wide: k = A / W. */
|
|
8
|
+
export function scaleFor(width, across = SHEET.width) {
|
|
9
|
+
return width / across;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
|
-
* `k` for a sheet laid out in an area `width` CSS pixels wide:
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* `k` for a sheet laid out in an area `width` CSS pixels wide: the page fits the width, up to
|
|
13
|
+
* `K_MAX`. This is the layout's `k`, before any transform the page puts on the element; input takes
|
|
14
|
+
* `k` from the sheet's rectangle on the screen, by `scaleFor`.
|
|
16
15
|
*/
|
|
17
|
-
export function fitScale(width
|
|
18
|
-
return Math.min(width / SHEET.width, K_MAX)
|
|
16
|
+
export function fitScale(width) {
|
|
17
|
+
return Math.min(width / SHEET.width, K_MAX);
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
20
|
* The point of the sheet under a point of the screen, given in CSS pixels from the top left corner
|
|
@@ -24,8 +23,8 @@ export function fitScale(width, zoom = 1) {
|
|
|
24
23
|
*/
|
|
25
24
|
export function toSheet(view, x, y) {
|
|
26
25
|
return {
|
|
27
|
-
x: clamp(x / view.k + view.vx, 0,
|
|
28
|
-
y: clamp(y / view.k + view.vy, 0,
|
|
26
|
+
x: clamp(x / view.k + view.vx, 0, REACH.width),
|
|
27
|
+
y: clamp(y / view.k + view.vy, 0, REACH.height),
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
30
|
/** The point of the screen over a point of the sheet, from the top left corner of its visible part. */
|
package/lib/core/sheet.d.ts
CHANGED
|
@@ -1,9 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The handwriting sheet in logical units: 1000 wide and 1400 tall,
|
|
3
|
-
* corner
|
|
4
|
-
* these units, whatever the device's screen
|
|
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
|
|
4
|
+
* layer of the sheet counts in these units, whatever the device's screen; the task's zones, the
|
|
5
|
+
* workbook's lines and the areas of a worked example lie on the page.
|
|
5
6
|
*/
|
|
6
7
|
export declare const SHEET: Readonly<{
|
|
7
8
|
readonly width: 1000;
|
|
8
9
|
readonly height: 1400;
|
|
9
10
|
}>;
|
|
11
|
+
/**
|
|
12
|
+
* How far the sheet goes from its origin, in units: ten pages across and ten down. The learner
|
|
13
|
+
* writes past the page, to the right of it and below it, and a point beyond this is no point of a
|
|
14
|
+
* history: the bound keeps the rules' whole numbers small and a history's numbers sane (R06).
|
|
15
|
+
*/
|
|
16
|
+
export declare const REACH: Readonly<{
|
|
17
|
+
readonly width: 10000;
|
|
18
|
+
readonly height: 14000;
|
|
19
|
+
}>;
|
|
20
|
+
/** A size on the sheet, in units. */
|
|
21
|
+
export interface Size {
|
|
22
|
+
readonly width: number;
|
|
23
|
+
readonly height: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The sheet as large as it is laid out (R06): the page, and past it and past the furthest ink a
|
|
27
|
+
* `room` more — the part of the sheet in sight, so that there is always somewhere to move it to and
|
|
28
|
+
* write —, within `REACH`. `ink` is the right and the bottom of the furthest strokes, none for an
|
|
29
|
+
* empty sheet.
|
|
30
|
+
*/
|
|
31
|
+
export declare function extentOf(ink: {
|
|
32
|
+
readonly maxX: number;
|
|
33
|
+
readonly maxY: number;
|
|
34
|
+
} | undefined, room: Size): Size;
|
|
35
|
+
/**
|
|
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).
|
|
38
|
+
*/
|
|
39
|
+
export declare const PICTURE_BYTES: number;
|
|
40
|
+
/**
|
|
41
|
+
* The picture of a work (R83): the page, and the ink past it, right and down, with no room past the
|
|
42
|
+
* ink, at a pixel a unit while its rows hold no more than `PICTURE_BYTES`, and scaled down to hold
|
|
43
|
+
* them otherwise. `scale` is pixels a unit.
|
|
44
|
+
*/
|
|
45
|
+
export declare function pictureOf(ink: {
|
|
46
|
+
readonly maxX: number;
|
|
47
|
+
readonly maxY: number;
|
|
48
|
+
} | undefined): {
|
|
49
|
+
readonly width: number;
|
|
50
|
+
readonly height: number;
|
|
51
|
+
readonly scale: number;
|
|
52
|
+
};
|
package/lib/core/sheet.js
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The handwriting sheet in logical units: 1000 wide and 1400 tall,
|
|
3
|
-
* corner
|
|
4
|
-
* these units, whatever the device's screen
|
|
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
|
|
4
|
+
* layer of the sheet counts in these units, whatever the device's screen; the task's zones, the
|
|
5
|
+
* workbook's lines and the areas of a worked example lie on the page.
|
|
5
6
|
*/
|
|
6
7
|
export const SHEET = Object.freeze({ width: 1000, height: 1400 });
|
|
8
|
+
/**
|
|
9
|
+
* How far the sheet goes from its origin, in units: ten pages across and ten down. The learner
|
|
10
|
+
* writes past the page, to the right of it and below it, and a point beyond this is no point of a
|
|
11
|
+
* history: the bound keeps the rules' whole numbers small and a history's numbers sane (R06).
|
|
12
|
+
*/
|
|
13
|
+
export const REACH = Object.freeze({ width: 10000, height: 14000 });
|
|
14
|
+
/**
|
|
15
|
+
* The sheet as large as it is laid out (R06): the page, and past it and past the furthest ink a
|
|
16
|
+
* `room` more — the part of the sheet in sight, so that there is always somewhere to move it to and
|
|
17
|
+
* write —, within `REACH`. `ink` is the right and the bottom of the furthest strokes, none for an
|
|
18
|
+
* empty sheet.
|
|
19
|
+
*/
|
|
20
|
+
export function extentOf(ink, room) {
|
|
21
|
+
const right = Math.max(SHEET.width, ink?.maxX ?? 0);
|
|
22
|
+
const bottom = Math.max(SHEET.height, ink?.maxY ?? 0);
|
|
23
|
+
return {
|
|
24
|
+
width: Math.min(REACH.width, Math.ceil(right + room.width)),
|
|
25
|
+
height: Math.min(REACH.height, Math.ceil(bottom + room.height)),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
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).
|
|
31
|
+
*/
|
|
32
|
+
export const PICTURE_BYTES = (SHEET.width + 1) * SHEET.height;
|
|
33
|
+
/**
|
|
34
|
+
* The picture of a work (R83): the page, and the ink past it, right and down, with no room past the
|
|
35
|
+
* ink, at a pixel a unit while its rows hold no more than `PICTURE_BYTES`, and scaled down to hold
|
|
36
|
+
* them otherwise. `scale` is pixels a unit.
|
|
37
|
+
*/
|
|
38
|
+
export function pictureOf(ink) {
|
|
39
|
+
const { width, height } = extentOf(ink, { width: 0, height: 0 });
|
|
40
|
+
// The scale s whose rows, (width s + 1) × height s, are PICTURE_BYTES: the root of a quadratic.
|
|
41
|
+
const area = width * height;
|
|
42
|
+
const fit = (Math.sqrt(height * height + 4 * area * PICTURE_BYTES) - height) / (2 * area);
|
|
43
|
+
const scale = Math.min(1, fit);
|
|
44
|
+
return {
|
|
45
|
+
width: Math.max(1, Math.floor(width * scale)),
|
|
46
|
+
height: Math.max(1, Math.floor(height * scale)),
|
|
47
|
+
scale,
|
|
48
|
+
};
|
|
49
|
+
}
|
package/lib/core/submission.js
CHANGED
|
@@ -74,7 +74,11 @@ export function paperWorkForCheck(strokes, paper, tracing, rect, picture, digit)
|
|
|
74
74
|
const submission = {
|
|
75
75
|
crop: numbers,
|
|
76
76
|
groups,
|
|
77
|
-
tracing: {
|
|
77
|
+
tracing: {
|
|
78
|
+
at: [tracing.at[0], tracing.at[1]],
|
|
79
|
+
hidden: tracing.hidden,
|
|
80
|
+
scale: tracing.scale ?? 1,
|
|
81
|
+
},
|
|
78
82
|
digest: digestOf(strokes, numbers, groups, paper),
|
|
79
83
|
};
|
|
80
84
|
return Object.freeze({
|
package/lib/core/task.d.ts
CHANGED
|
@@ -6,13 +6,18 @@ import { type Page } from "./page.js";
|
|
|
6
6
|
export declare const SHEET_KIND = "handwriting_sheet";
|
|
7
7
|
export declare const WORKBOOK_KIND = "workbook";
|
|
8
8
|
/**
|
|
9
|
-
* What a press of the primary button does on the sheet: the pen writes, the eraser erases (R22)
|
|
10
|
-
* pen's eraser erases whatever the tool, if the task allows the
|
|
11
|
-
* spec).
|
|
9
|
+
* What a press of the primary button does on the sheet: the pen writes, the eraser erases (R22),
|
|
10
|
+
* the hand moves the sheet (R84). A pen's eraser erases whatever the tool, if the task allows the
|
|
11
|
+
* eraser (R28). spec's type (R74 spec).
|
|
12
12
|
*/
|
|
13
13
|
export type { Tool };
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* The tools of the module format a task allows, in the order their buttons stand: the pen, the
|
|
16
|
+
* eraser. The hand is no tool of the format: every sheet the learner writes on has it.
|
|
17
|
+
*/
|
|
15
18
|
export declare const TOOLS: readonly Tool[];
|
|
19
|
+
/** The tool that moves the sheet and writes nothing (R84). */
|
|
20
|
+
export declare const HAND: Tool;
|
|
16
21
|
export declare function isTool(value: unknown): value is Tool;
|
|
17
22
|
/** A paragraph of a task's statement, or a piece of text of a workbook's line. */
|
|
18
23
|
export interface TextPart {
|
package/lib/core/task.js
CHANGED
|
@@ -10,10 +10,15 @@ import { pageOf, samePage } from "./page.js";
|
|
|
10
10
|
/** The canvas kinds of the module format: the handwriting sheet and the workbook. */
|
|
11
11
|
export const SHEET_KIND = "handwriting_sheet";
|
|
12
12
|
export const WORKBOOK_KIND = "workbook";
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* The tools of the module format a task allows, in the order their buttons stand: the pen, the
|
|
15
|
+
* eraser. The hand is no tool of the format: every sheet the learner writes on has it.
|
|
16
|
+
*/
|
|
14
17
|
export const TOOLS = Object.freeze(["pen", "eraser"]);
|
|
18
|
+
/** The tool that moves the sheet and writes nothing (R84). */
|
|
19
|
+
export const HAND = "hand";
|
|
15
20
|
export function isTool(value) {
|
|
16
|
-
return TOOLS.includes(value);
|
|
21
|
+
return value === HAND || TOOLS.includes(value);
|
|
17
22
|
}
|
|
18
23
|
/** The template of a sheet without a task: squares of 50 units, no statement, both tools. */
|
|
19
24
|
export const NO_TASK = Object.freeze({
|
package/lib/core/tracing.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { TracingState } from "@altnovatrail/spec/canvas";
|
|
1
|
+
import type { PaperGrid, TracingReading, TracingState } from "@altnovatrail/spec/canvas";
|
|
2
2
|
import type { Box } from "./geometry.js";
|
|
3
|
+
import type { Grid } from "./grid.js";
|
|
3
4
|
import type { Stroke } from "./ink.js";
|
|
4
5
|
import type { Point } from "./screen.js";
|
|
5
6
|
/**
|
|
@@ -21,6 +22,34 @@ export declare const TRACING: Readonly<{
|
|
|
21
22
|
leap: 100;
|
|
22
23
|
dots: 25;
|
|
23
24
|
}>;
|
|
25
|
+
/**
|
|
26
|
+
* The tracing paper's scale (R89): from `min` to `max` times its own size, as the mockup's
|
|
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.
|
|
29
|
+
*/
|
|
30
|
+
export declare const SCALE: Readonly<{
|
|
31
|
+
min: 0.4;
|
|
32
|
+
max: 4;
|
|
33
|
+
button: 1.2;
|
|
34
|
+
wheel: 1.08;
|
|
35
|
+
}>;
|
|
36
|
+
/** A scale kept to the rule's bounds, in hundredths (R89). */
|
|
37
|
+
export declare function scaleOf(scale: number): number;
|
|
38
|
+
/** The scale of a tracing state: 1 where it has none (R89). */
|
|
39
|
+
export declare function scaleIn(state: TracingState): number;
|
|
40
|
+
/** A size as large as `scale` makes it. */
|
|
41
|
+
export declare function scaled(size: Size, scale: number): Size;
|
|
42
|
+
/**
|
|
43
|
+
* The grids of a task from paper's sheet in the order its button turns them, round, the first as
|
|
44
|
+
* the task comes (R88).
|
|
45
|
+
*/
|
|
46
|
+
export declare const PAPER_GRIDS: readonly PaperGrid[];
|
|
47
|
+
/** Whether a value is a grid of a task from paper's sheet. */
|
|
48
|
+
export declare function isPaperGrid(value: unknown): value is PaperGrid;
|
|
49
|
+
/** The rulings of a task from paper's grid, or none for a blank sheet (R88). */
|
|
50
|
+
export declare function rulingsOf(grid: PaperGrid): Grid | undefined;
|
|
51
|
+
/** The grid the button turns a task from paper's grid to: the next, round (R88). */
|
|
52
|
+
export declare function nextGrid(grid: PaperGrid): PaperGrid;
|
|
24
53
|
/** The tracing paper's size on the sheet, in units. */
|
|
25
54
|
export interface Size {
|
|
26
55
|
readonly width: number;
|
|
@@ -37,19 +66,26 @@ export declare function sizeOf(width: number, height: number): Size;
|
|
|
37
66
|
export declare const TRACING_START: TracingState;
|
|
38
67
|
/**
|
|
39
68
|
* A tracing state a consumer gives (R74 spec), checked and frozen: an object of `at`, [x, y] in
|
|
40
|
-
* units, finite numbers,
|
|
41
|
-
* puts the tracing paper of `size` wholly off the sheet
|
|
42
|
-
* not such a state.
|
|
69
|
+
* units, finite numbers, `hidden`, true or false, and `scale`, if any, from 0.4 to 4; other fields
|
|
70
|
+
* are passed over. A state that puts the tracing paper of `size` at its scale wholly off the sheet
|
|
71
|
+
* is a TypeError, as is anything else that is not such a state.
|
|
43
72
|
*/
|
|
44
73
|
export declare function tracingStateOf(value: unknown, size: Size): TracingState;
|
|
45
74
|
/**
|
|
46
75
|
* The fields of a tracing state at `path`, checked and frozen: `at`, [x, y] in units, finite
|
|
47
|
-
* numbers,
|
|
48
|
-
* TypeError. Where it lies on the sheet is the caller's
|
|
76
|
+
* numbers, `hidden`, true or false, and `scale`, from 0.4 to 4, 1 where it is absent; other
|
|
77
|
+
* fields are passed over. Anything else is a TypeError. Where it lies on the sheet is the caller's
|
|
78
|
+
* to check.
|
|
49
79
|
*/
|
|
50
80
|
export declare function tracingFieldsOf(value: unknown, path: string): TracingState;
|
|
51
81
|
/** Whether the tracing paper of `size` at `at` lies wholly off the sheet, touching it at most. */
|
|
52
82
|
export declare function whollyOff(at: readonly [number, number], size: Size): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* A reading of the statement a consumer gives (R89), checked and frozen: `state` "ready" or
|
|
85
|
+
* "busy", or "done" with `statements`, from none to 20 strings; other fields are passed over.
|
|
86
|
+
* Anything else is a TypeError.
|
|
87
|
+
*/
|
|
88
|
+
export declare function readingOf(value: unknown): TracingReading;
|
|
53
89
|
/** Whether two tracing states say the same. */
|
|
54
90
|
export declare function sameTracing(a: TracingState, b: TracingState): boolean;
|
|
55
91
|
/** The tracing paper's rectangle on the sheet, in units. */
|
|
@@ -62,22 +98,22 @@ export declare function keptOn(at: readonly [number, number], size: Size): reado
|
|
|
62
98
|
/** Whether a point of the sheet lies on the tracing paper, its edges too. */
|
|
63
99
|
export declare function onTracing(point: Point, at: readonly [number, number], size: Size): boolean;
|
|
64
100
|
/**
|
|
65
|
-
* A point of the sheet as a stroke on the tracing paper holds it: from the
|
|
66
|
-
* kept to the paper (R74 spec).
|
|
101
|
+
* A point of the sheet as a stroke on the tracing paper of `size` at `scale` holds it: from the
|
|
102
|
+
* paper's top left corner, in its own units, kept to the paper (R74 spec; R89).
|
|
67
103
|
*/
|
|
68
|
-
export declare function toTracing(point: Point, at: readonly [number, number], size: Size): Point;
|
|
104
|
+
export declare function toTracing(point: Point, at: readonly [number, number], size: Size, scale?: number): Point;
|
|
69
105
|
/**
|
|
70
|
-
* A stroke of the tracing paper where it lies on the sheet: its points
|
|
71
|
-
* the sheet, should the paper lie in part beyond it — the rules of the groups and the crop hold on
|
|
106
|
+
* A stroke of the tracing paper where it lies on the sheet: its points scaled by `scale` and moved
|
|
107
|
+
* by `at`, and kept to the sheet, should the paper lie in part beyond it — the rules of the groups and the crop hold on
|
|
72
108
|
* the sheet alone (R24, R25). The same ID, kind and times.
|
|
73
109
|
*/
|
|
74
|
-
export declare function onSheet(stroke: Stroke, at: readonly [number, number]): Stroke;
|
|
110
|
+
export declare function onSheet(stroke: Stroke, at: readonly [number, number], scale?: number): Stroke;
|
|
75
111
|
/**
|
|
76
112
|
* The box of a tracing paper's stroke where it lies on the sheet, from the box of its points on the
|
|
77
113
|
* paper: the box of `onSheet`'s points, for moving and keeping to the sheet keep the order of the
|
|
78
114
|
* numbers, without a copy of the stroke.
|
|
79
115
|
*/
|
|
80
|
-
export declare function boxOnSheet(box: Box, at: readonly [number, number]): Box;
|
|
116
|
+
export declare function boxOnSheet(box: Box, at: readonly [number, number], scale?: number): Box;
|
|
81
117
|
/**
|
|
82
118
|
* The tracing paper's rectangle on the sheet in whole tenths of a unit, as the crop counts (R25),
|
|
83
119
|
* kept to the sheet: the part of it a crop of the work takes in.
|