@altnovatrail/canvas 0.3.39 → 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.
- 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 +9 -9
- 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 +34 -34
- 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 +7 -7
- package/lib/core/recorder.js +7 -7
- 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 +3 -3
- package/lib/core/sheet.js +3 -3
- 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 +20 -20
- package/lib/core/tracing.js +20 -20
- package/lib/core/widths.d.ts +2 -2
- package/lib/core/widths.js +5 -5
- package/lib/core/work.d.ts +18 -18
- package/lib/core/work.js +21 -21
- package/lib/core/zoom.d.ts +4 -4
- package/lib/core/zoom.js +4 -4
- package/lib/element/index.d.ts +87 -87
- package/lib/element/index.js +284 -281
- 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/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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
73
|
-
* mark that has none — the question is asked without it
|
|
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
|
|
81
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
228
|
-
* Adler-32 of PNG and zlib (png.ts) of a text that holds its strokes, by ID ascending, each with
|
|
229
|
-
* points in tenths of a unit and whole milliseconds, as the rules see them
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 = [];
|
package/lib/core/notation.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A statement read from a task from paper, as the element draws it
|
|
2
|
+
* A statement read from a task from paper, as the element draws it: the text as printed,
|
|
3
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}
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
8
|
*/
|
|
9
9
|
export type Piece = {
|
|
10
10
|
readonly kind: "text";
|
package/lib/core/outline.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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[];
|
package/lib/core/outline.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getStroke } from "perfect-freehand";
|
|
2
2
|
/**
|
|
3
3
|
* The width of the line, in sheet units: 3, as the check board of tutor draws with a `lineWidth`
|
|
4
|
-
* of 3 px on its sheet 1000 wide
|
|
4
|
+
* of 3 px on its sheet 1000 wide.
|
|
5
5
|
*/
|
|
6
6
|
export const INK_WIDTH = 3;
|
|
7
|
-
/** How much a pen's pressure changes the width: from half of it to one and a half
|
|
7
|
+
/** How much a pen's pressure changes the width: from half of it to one and a half. */
|
|
8
8
|
const PEN_THINNING = 0.5;
|
|
9
9
|
/**
|
|
10
10
|
* How far the ink reaches from a stroke's points, in sheet units, at most: half the widest line, a
|
|
@@ -13,8 +13,8 @@ const PEN_THINNING = 0.5;
|
|
|
13
13
|
*/
|
|
14
14
|
export const INK_REACH = INK_WIDTH * (0.5 + PEN_THINNING / 2);
|
|
15
15
|
/**
|
|
16
|
-
* Every option of perfect-freehand 1.2.3 is given: its code's defaults are not its README's
|
|
17
|
-
*
|
|
16
|
+
* Every option of perfect-freehand 1.2.3 is given: its code's defaults are not its README's.
|
|
17
|
+
* The pressure is the pointer's own, the third number of each point, never simulated, and
|
|
18
18
|
* the ends are round, without a taper.
|
|
19
19
|
*/
|
|
20
20
|
const OPTIONS = {
|
|
@@ -26,14 +26,14 @@ const OPTIONS = {
|
|
|
26
26
|
start: { cap: true, taper: false },
|
|
27
27
|
end: { cap: true, taper: false },
|
|
28
28
|
};
|
|
29
|
-
/** Whether a stroke's line widens with its pressure on the screen: only a pen's does
|
|
29
|
+
/** Whether a stroke's line widens with its pressure on the screen: only a pen's does. */
|
|
30
30
|
export function followsPressure(stroke) {
|
|
31
31
|
return stroke.kind === "pen";
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* The outline of a stroke on the screen, as perfect-freehand draws it: a closed polygon around the
|
|
35
35
|
* stroke's points, in sheet units, to be filled. A pen's line widens with its pressure; a mouse's
|
|
36
|
-
* or a finger's is as wide all along
|
|
36
|
+
* or a finger's is as wide all along. `complete` says the stroke has ended: its last point is
|
|
37
37
|
* then taken as it is, rather than eased toward.
|
|
38
38
|
*/
|
|
39
39
|
export function outline(stroke, complete) {
|
package/lib/core/page.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { WorkbookItem } from "./task.js";
|
|
2
|
-
/** The numbers of the layout
|
|
2
|
+
/** The numbers of the layout, in page units, the type size among them. */
|
|
3
3
|
export interface Layout {
|
|
4
4
|
/** The type size of the line's text. */
|
|
5
5
|
readonly size: number;
|
|
6
|
-
/** A box, the same for the whole task
|
|
6
|
+
/** A box, the same for the whole task. */
|
|
7
7
|
readonly boxWidth: number;
|
|
8
8
|
readonly boxHeight: number;
|
|
9
9
|
/** The height of a line of text without a box. */
|
|
@@ -21,9 +21,9 @@ export interface Layout {
|
|
|
21
21
|
/** The margin of the page on its sides, its top and its bottom. */
|
|
22
22
|
readonly margin: number;
|
|
23
23
|
}
|
|
24
|
-
/** The layout the workbook has: a sweep chose it around the box the author chose
|
|
24
|
+
/** The layout the workbook has: a sweep chose it around the box the author chose. */
|
|
25
25
|
export declare const LAYOUT: Layout;
|
|
26
|
-
/** A piece of a line's text, or its part on one line of the page: one `<text
|
|
26
|
+
/** A piece of a line's text, or its part on one line of the page: one `<text>`. */
|
|
27
27
|
export interface PageText {
|
|
28
28
|
readonly text: string;
|
|
29
29
|
/** Where it starts, and its alphabetic baseline, in page units. */
|
|
@@ -66,12 +66,12 @@ export interface Page {
|
|
|
66
66
|
export declare function isBox(part: PageText | PageBox): part is PageBox;
|
|
67
67
|
/**
|
|
68
68
|
* The width of a text as one piece on one line, in whole units: its words and the spaces between
|
|
69
|
-
* them, as the layout measures a fragment of a piece
|
|
70
|
-
* box's width by it (the format's rule lesson.workbook-page
|
|
69
|
+
* them, as the layout measures a fragment of a piece. A worked example's value is held to its
|
|
70
|
+
* box's width by it (the format's rule lesson.workbook-page), and drawn at it.
|
|
71
71
|
*/
|
|
72
72
|
export declare function pieceWidth(text: string, layout?: Layout): number;
|
|
73
73
|
/**
|
|
74
|
-
* The page of a workbook's items
|
|
74
|
+
* The page of a workbook's items: a function of the items alone, in whole units, frozen. A
|
|
75
75
|
* row that does not fit is a TypeError at the first item of it, `task.items[i]`.
|
|
76
76
|
*/
|
|
77
77
|
export declare function pageOf(items: readonly WorkbookItem[], layout?: Layout): Page;
|
package/lib/core/page.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// The layout of a workbook's page
|
|
2
|
-
// pieces of its line and its boxes, in whole page units, from the task's items alone. The
|
|
3
|
-
// the sheet's, 1000 × 1400 units
|
|
1
|
+
// The layout of a workbook's page: where the template puts each item's number, the
|
|
2
|
+
// pieces of its line and its boxes, in whole page units, from the task's items alone (R35). The
|
|
3
|
+
// page is the sheet's, 1000 × 1400 units, and the boxes stay where the layout puts them on any
|
|
4
4
|
// device: the widths of the text come from the canvas's own table (widths.ts), and SVG fits the
|
|
5
5
|
// text to them. Short lines stand two to a row, in the task's order; a long line takes the page's
|
|
6
6
|
// width and wraps. A task whose lines do not fit is a TypeError: nothing shrinks. The numbers and
|
|
7
7
|
// the rule are the module format's, its page.yaml and its test vectors, which the npm package
|
|
8
|
-
// @altnovatrail/spec carries and the tests hold the layout to
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// @altnovatrail/spec carries and the tests hold the layout to: they change only with the format,
|
|
9
|
+
// for histories know neither the task nor the layout. The core's entry point does not give the
|
|
10
|
+
// layout.
|
|
11
11
|
import { SHEET } from "./sheet.js";
|
|
12
12
|
import { clustersOf, clusterWidth, SPACE, wordsOf, wordWidth } from "./widths.js";
|
|
13
|
-
/** The layout the workbook has: a sweep chose it around the box the author chose
|
|
13
|
+
/** The layout the workbook has: a sweep chose it around the box the author chose. */
|
|
14
14
|
export const LAYOUT = Object.freeze({
|
|
15
15
|
size: 30,
|
|
16
16
|
boxWidth: 100,
|
|
@@ -50,8 +50,8 @@ function measuresOf(layout) {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* The width of a text as one piece on one line, in whole units: its words and the spaces between
|
|
53
|
-
* them, as the layout measures a fragment of a piece
|
|
54
|
-
* box's width by it (the format's rule lesson.workbook-page
|
|
53
|
+
* them, as the layout measures a fragment of a piece. A worked example's value is held to its
|
|
54
|
+
* box's width by it (the format's rule lesson.workbook-page), and drawn at it.
|
|
55
55
|
*/
|
|
56
56
|
export function pieceWidth(text, layout = LAYOUT) {
|
|
57
57
|
const words = wordsOf(text);
|
|
@@ -66,7 +66,7 @@ function textWidth(layout, hundredths) {
|
|
|
66
66
|
return (product - (product % 100)) / 100 + (product % 100 > 0 ? 1 : 0);
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
* The page of a workbook's items
|
|
69
|
+
* The page of a workbook's items: a function of the items alone, in whole units, frozen. A
|
|
70
70
|
* row that does not fit is a TypeError at the first item of it, `task.items[i]`.
|
|
71
71
|
*/
|
|
72
72
|
export function pageOf(items, layout = LAYOUT) {
|
package/lib/core/png.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The PNG of a grey image, a byte to a pixel, row by row from the top
|
|
3
|
-
* same pixels give the same bytes in every browser and in Node, as no browser's canvas promises
|
|
4
|
-
*
|
|
2
|
+
* The PNG of a grey image, a byte to a pixel, row by row from the top: own code, so that the
|
|
3
|
+
* same pixels give the same bytes in every browser and in Node, as no browser's canvas promises.
|
|
4
|
+
* The file is the least PNG holds: its signature, the header, one chunk of data and the end,
|
|
5
5
|
* no ancillary chunk, for a decoder may ignore them (PNG Third Edition, 11.3). The data is a zlib
|
|
6
6
|
* stream of one deflate block with the fixed Huffman codes (RFC 1950, RFC 1951): every row
|
|
7
7
|
* unfiltered, and a repeat looked for in two places only — the byte before, which takes the runs of
|
package/lib/core/png.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The PNG of a grey image, a byte to a pixel, row by row from the top
|
|
3
|
-
* same pixels give the same bytes in every browser and in Node, as no browser's canvas promises
|
|
4
|
-
*
|
|
2
|
+
* The PNG of a grey image, a byte to a pixel, row by row from the top: own code, so that the
|
|
3
|
+
* same pixels give the same bytes in every browser and in Node, as no browser's canvas promises.
|
|
4
|
+
* The file is the least PNG holds: its signature, the header, one chunk of data and the end,
|
|
5
5
|
* no ancillary chunk, for a decoder may ignore them (PNG Third Edition, 11.3). The data is a zlib
|
|
6
6
|
* stream of one deflate block with the fixed Huffman codes (RFC 1950, RFC 1951): every row
|
|
7
7
|
* unfiltered, and a repeat looked for in two places only — the byte before, which takes the runs of
|
package/lib/core/raster.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Crop } from "./crop.js";
|
|
2
2
|
import type { Stroke } from "./ink.js";
|
|
3
3
|
/**
|
|
4
|
-
* The pixels of a crop
|
|
4
|
+
* The pixels of a crop: grey, a byte each, row by row from the top, white 255 and the ink 0,
|
|
5
5
|
* of the strokes the crop was made of. Every segment of a stroke is a line as wide all along, with
|
|
6
6
|
* round ends, and a stroke of one point a dot as wide as the line: a pixel takes the share of it
|
|
7
7
|
* that the line covers, along a ramp a pixel wide at the line's edge, and the darkest of what
|
|
8
8
|
* covers it. The places are the crop's own whole numbers, from the points in tenths of a unit, as
|
|
9
|
-
* a sample keeps them
|
|
9
|
+
* a sample keeps them. Only adding, subtracting, multiplying, dividing and Math.sqrt go into
|
|
10
10
|
* a pixel, which ECMAScript rounds alike in every engine, so the bytes are the same in each.
|
|
11
11
|
*/
|
|
12
12
|
export declare function rasterOf(strokes: readonly Stroke[], crop: Crop): Uint8Array<ArrayBuffer>;
|
|
13
|
-
/** The PNG of a crop: its pixels, encoded
|
|
13
|
+
/** The PNG of a crop: its pixels, encoded. */
|
|
14
14
|
export declare function pictureOf(strokes: readonly Stroke[], crop: Crop): Uint8Array<ArrayBuffer>;
|
package/lib/core/raster.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { tenths } from "./geometry.js";
|
|
2
2
|
import { encodePNG } from "./png.js";
|
|
3
3
|
/**
|
|
4
|
-
* The pixels of a crop
|
|
4
|
+
* The pixels of a crop: grey, a byte each, row by row from the top, white 255 and the ink 0,
|
|
5
5
|
* of the strokes the crop was made of. Every segment of a stroke is a line as wide all along, with
|
|
6
6
|
* round ends, and a stroke of one point a dot as wide as the line: a pixel takes the share of it
|
|
7
7
|
* that the line covers, along a ramp a pixel wide at the line's edge, and the darkest of what
|
|
8
8
|
* covers it. The places are the crop's own whole numbers, from the points in tenths of a unit, as
|
|
9
|
-
* a sample keeps them
|
|
9
|
+
* a sample keeps them. Only adding, subtracting, multiplying, dividing and Math.sqrt go into
|
|
10
10
|
* a pixel, which ECMAScript rounds alike in every engine, so the bytes are the same in each.
|
|
11
11
|
*/
|
|
12
12
|
export function rasterOf(strokes, crop) {
|
|
@@ -33,7 +33,7 @@ export function rasterOf(strokes, crop) {
|
|
|
33
33
|
}
|
|
34
34
|
return gray;
|
|
35
35
|
}
|
|
36
|
-
/** The PNG of a crop: its pixels, encoded
|
|
36
|
+
/** The PNG of a crop: its pixels, encoded. */
|
|
37
37
|
export function pictureOf(strokes, crop) {
|
|
38
38
|
return encodePNG(rasterOf(strokes, crop), crop.width, crop.height);
|
|
39
39
|
}
|
package/lib/core/recorder.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Clock } from "./clock.js";
|
|
|
2
2
|
import type { Stroke } from "./ink.js";
|
|
3
3
|
/**
|
|
4
4
|
* What the recorder takes of a pointer event, and of each event coalesced into it. The DOM-free
|
|
5
|
-
* part sees no DOM
|
|
5
|
+
* part sees no DOM, so the element hands it this much, the place already in sheet units.
|
|
6
6
|
*/
|
|
7
7
|
export interface PointerSample {
|
|
8
8
|
/** The event's `pointerId`. */
|
|
@@ -23,7 +23,7 @@ export interface PointerSample {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* How close two recorded points of a stroke may come, in sheet units: 0.1, the precision of a
|
|
26
|
-
* sample file
|
|
26
|
+
* sample file. A point nearer than that to the last one recorded adds nothing the file would
|
|
27
27
|
* keep (R18).
|
|
28
28
|
*/
|
|
29
29
|
export declare const MIN_STEP = 0.1;
|
|
@@ -32,11 +32,11 @@ export declare const PRIMARY = 0;
|
|
|
32
32
|
/** The primary button's bit in `buttons`. */
|
|
33
33
|
export declare const PRIMARY_HELD = 1;
|
|
34
34
|
/**
|
|
35
|
-
* The strokes of one sheet, from the pointer's samples
|
|
35
|
+
* The strokes of one sheet, from the pointer's samples. One pointer writes at a time, with
|
|
36
36
|
* its primary button: a second pointer, and any other button, write nothing while a stroke is
|
|
37
37
|
* under way. A finished stroke goes to the handler the recorder is made with — onto the work on
|
|
38
|
-
* the sheet
|
|
39
|
-
* actions keep too
|
|
38
|
+
* the sheet. Its points take their time from the sheet's clock, which the sheet's other
|
|
39
|
+
* actions keep too.
|
|
40
40
|
*/
|
|
41
41
|
export declare class Recorder {
|
|
42
42
|
#private;
|
|
@@ -58,7 +58,7 @@ export declare class Recorder {
|
|
|
58
58
|
* is 0 by definition, the buttons no longer pressed, rather than measured.
|
|
59
59
|
*/
|
|
60
60
|
up(sample: PointerSample): boolean;
|
|
61
|
-
/** `pointercancel`: the device took the touch for an accident, and the stroke goes
|
|
61
|
+
/** `pointercancel`: the device took the touch for an accident, and the stroke goes. */
|
|
62
62
|
cancel(pointerId: number): boolean;
|
|
63
63
|
/**
|
|
64
64
|
* The stroke ends where the pointer last was, its `pointerup` never to come: the pointer's
|
|
@@ -66,7 +66,7 @@ export declare class Recorder {
|
|
|
66
66
|
*/
|
|
67
67
|
end(pointerId?: number): boolean;
|
|
68
68
|
/**
|
|
69
|
-
* The sheet has taken another history of writing
|
|
69
|
+
* The sheet has taken another history of writing: the stroke under way goes, as on
|
|
70
70
|
* `pointercancel` — its ID and its times are the last sheet's — and the next stroke is `nextId`.
|
|
71
71
|
*/
|
|
72
72
|
restart(nextId: number): void;
|
package/lib/core/recorder.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Clock } from "./clock.js";
|
|
2
2
|
/**
|
|
3
3
|
* How close two recorded points of a stroke may come, in sheet units: 0.1, the precision of a
|
|
4
|
-
* sample file
|
|
4
|
+
* sample file. A point nearer than that to the last one recorded adds nothing the file would
|
|
5
5
|
* keep (R18).
|
|
6
6
|
*/
|
|
7
7
|
export const MIN_STEP = 0.1;
|
|
@@ -10,11 +10,11 @@ export const PRIMARY = 0;
|
|
|
10
10
|
/** The primary button's bit in `buttons`. */
|
|
11
11
|
export const PRIMARY_HELD = 1;
|
|
12
12
|
/**
|
|
13
|
-
* The strokes of one sheet, from the pointer's samples
|
|
13
|
+
* The strokes of one sheet, from the pointer's samples. One pointer writes at a time, with
|
|
14
14
|
* its primary button: a second pointer, and any other button, write nothing while a stroke is
|
|
15
15
|
* under way. A finished stroke goes to the handler the recorder is made with — onto the work on
|
|
16
|
-
* the sheet
|
|
17
|
-
* actions keep too
|
|
16
|
+
* the sheet. Its points take their time from the sheet's clock, which the sheet's other
|
|
17
|
+
* actions keep too.
|
|
18
18
|
*/
|
|
19
19
|
export class Recorder {
|
|
20
20
|
#finished;
|
|
@@ -78,7 +78,7 @@ export class Recorder {
|
|
|
78
78
|
live.latest = this.#point(sample, live.latest.p);
|
|
79
79
|
return this.#finish();
|
|
80
80
|
}
|
|
81
|
-
/** `pointercancel`: the device took the touch for an accident, and the stroke goes
|
|
81
|
+
/** `pointercancel`: the device took the touch for an accident, and the stroke goes. */
|
|
82
82
|
cancel(pointerId) {
|
|
83
83
|
if (this.#live?.pointerId !== pointerId)
|
|
84
84
|
return false;
|
|
@@ -97,7 +97,7 @@ export class Recorder {
|
|
|
97
97
|
return this.#finish();
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* The sheet has taken another history of writing
|
|
100
|
+
* The sheet has taken another history of writing: the stroke under way goes, as on
|
|
101
101
|
* `pointercancel` — its ID and its times are the last sheet's — and the next stroke is `nextId`.
|
|
102
102
|
*/
|
|
103
103
|
restart(nextId) {
|
|
@@ -118,7 +118,7 @@ export class Recorder {
|
|
|
118
118
|
/**
|
|
119
119
|
* A point of the sample, its time the sheet's and never going back. Its pressure is kept to 0–1,
|
|
120
120
|
* the range Pointer Events gives it: an event a script makes may say more, and the sheet would
|
|
121
|
-
* write a history it does not take back
|
|
121
|
+
* write a history it does not take back.
|
|
122
122
|
*/
|
|
123
123
|
#point(sample, pressure) {
|
|
124
124
|
const p = Math.min(Math.max(pressure, 0), 1);
|
package/lib/core/screen.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Where the sheet is on the screen, one view for every layer
|
|
2
|
+
* Where the sheet is on the screen, one view for every layer: `k` CSS pixels to a logical
|
|
3
3
|
* unit, for the page fits the width of its area, and `vx` and `vy`, the left and the top of the
|
|
4
4
|
* sheet's visible part, in units.
|
|
5
5
|
*/
|
|
@@ -15,7 +15,7 @@ export interface Point {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
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
|
|
18
|
+
* unit as on the picture of the work, at the sheet's left, and the sheet goes on past it.
|
|
19
19
|
*/
|
|
20
20
|
export declare const K_MAX = 1;
|
|
21
21
|
/** `k` of a sheet `width` CSS pixels wide as it is on the screen, `across` units wide: k = A / W. */
|
package/lib/core/screen.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { REACH, SHEET } from "./sheet.js";
|
|
2
2
|
/**
|
|
3
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
|
|
4
|
+
* unit as on the picture of the work, at the sheet's left, and the sheet goes on past it.
|
|
5
5
|
*/
|
|
6
6
|
export const K_MAX = 1;
|
|
7
7
|
/** `k` of a sheet `width` CSS pixels wide as it is on the screen, `across` units wide: k = A / W. */
|
package/lib/core/sets.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The sets that strokes join into, pair by pair: union-find, each set known by its root, which is
|
|
3
|
-
* its smallest member. The groups grow in them
|
|
3
|
+
* its smallest member. The groups grow in them, and the crop's bundles.
|
|
4
4
|
*/
|
|
5
5
|
export declare class Sets {
|
|
6
6
|
#private;
|
package/lib/core/sets.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The sets that strokes join into, pair by pair: union-find, each set known by its root, which is
|
|
3
|
-
* its smallest member. The groups grow in them
|
|
3
|
+
* its smallest member. The groups grow in them, and the crop's bundles.
|
|
4
4
|
*/
|
|
5
5
|
export class Sets {
|
|
6
6
|
#parent;
|
package/lib/core/sheet.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const SHEET: Readonly<{
|
|
|
11
11
|
/**
|
|
12
12
|
* How far the sheet goes from its origin, in units: ten pages across and ten down. The learner
|
|
13
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
|
|
14
|
+
* history: the bound keeps the rules' whole numbers small and a history's numbers sane.
|
|
15
15
|
*/
|
|
16
16
|
export declare const REACH: Readonly<{
|
|
17
17
|
readonly width: 10000;
|
|
@@ -23,7 +23,7 @@ export interface Size {
|
|
|
23
23
|
readonly height: number;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* The sheet as large as it is laid out
|
|
26
|
+
* The sheet as large as it is laid out: the page, and past it and past the furthest ink a
|
|
27
27
|
* `room` more — the part of the sheet in sight, so that there is always somewhere to move it to and
|
|
28
28
|
* write —, within `REACH`. `ink` is the right and the bottom of the furthest strokes, none for an
|
|
29
29
|
* empty sheet.
|
|
@@ -38,7 +38,7 @@ export declare function extentOf(ink: {
|
|
|
38
38
|
*/
|
|
39
39
|
export declare const PICTURE_BYTES: number;
|
|
40
40
|
/**
|
|
41
|
-
* The picture of a work
|
|
41
|
+
* The picture of a work: the page, and the ink past it, right and down, with no room past the
|
|
42
42
|
* ink, at a pixel a unit while its rows hold no more than `PICTURE_BYTES`, and scaled down to hold
|
|
43
43
|
* them otherwise. `scale` is pixels a unit.
|
|
44
44
|
*/
|