@altnovatrail/canvas 0.3.38 → 0.3.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +24 -16
- package/lib/core/hands.js +66 -14
- 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 +29 -0
- package/lib/core/notation.js +180 -0
- 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 +34 -0
- package/lib/core/zoom.js +64 -0
- package/lib/element/icons.d.ts +19 -1
- package/lib/element/icons.js +24 -2
- package/lib/element/index.d.ts +87 -87
- package/lib/element/index.js +397 -295
- package/lib/element/labels.d.ts +21 -18
- package/lib/element/labels.js +15 -12
- package/lib/element/notation.d.ts +2 -0
- package/lib/element/notation.js +94 -0
- 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.d.ts +3 -0
- package/lib/element/session.js +8 -4
- package/lib/element/statement.d.ts +2 -2
- package/lib/element/statement.js +6 -6
- package/lib/element/tools.d.ts +21 -18
- package/lib/element/tools.js +46 -30
- package/lib/element/tracing.js +58 -31
- package/package.json +3 -3
package/lib/core/groups.js
CHANGED
|
@@ -2,15 +2,15 @@ import RBush from "rbush";
|
|
|
2
2
|
import { boxOf, tenths } from "./geometry.js";
|
|
3
3
|
import { Sets } from "./sets.js";
|
|
4
4
|
/**
|
|
5
|
-
* The rule the sheet groups by
|
|
5
|
+
* The rule the sheet groups by: 2 seconds, the threshold by which studies of writing tell a
|
|
6
6
|
* pause of writing from one of thinking, and a cell of the default grid, across and down.
|
|
7
7
|
*/
|
|
8
8
|
export const GROUP_RULE = Object.freeze({ pause: 2000, across: 50, down: 50 });
|
|
9
9
|
/**
|
|
10
|
-
* The groups of the strokes on a sheet
|
|
10
|
+
* The groups of the strokes on a sheet: the strokes it shows, with the times of their points
|
|
11
11
|
* as they were written, in any order. Erased strokes are none of it: whoever groups a history
|
|
12
12
|
* replays it first, and the groups come from what the sheet shows. Labelled by place, from the top
|
|
13
|
-
* down
|
|
13
|
+
* down: A, B, … Z, then AA, AB, … — by the top of a group's rectangle, then its left edge.
|
|
14
14
|
*/
|
|
15
15
|
export function groupsOf(strokes, rule = GROUP_RULE) {
|
|
16
16
|
const pieces = piecesOf(strokes);
|
|
@@ -32,9 +32,9 @@ export function groupsOf(strokes, rule = GROUP_RULE) {
|
|
|
32
32
|
.map(({ ids }, n) => ({ label: labelOf(n), ids }));
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* The pairs of neighbours among the strokes on a sheet, by ID
|
|
35
|
+
* The pairs of neighbours among the strokes on a sheet, by ID: each pair once, the smaller
|
|
36
36
|
* ID first, in ascending order. Its groups join these pairs; spec's test vectors give them too, for
|
|
37
|
-
* a runner to see where its grouping parts from the sheet's
|
|
37
|
+
* a runner to see where its grouping parts from the sheet's.
|
|
38
38
|
*/
|
|
39
39
|
export function neighboursOf(strokes, rule = GROUP_RULE) {
|
|
40
40
|
return pairsOf(piecesOf(strokes), rule)
|
|
@@ -43,7 +43,7 @@ export function neighboursOf(strokes, rule = GROUP_RULE) {
|
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* The rectangle of a group on the sheet: the box around the points of its strokes, in sheet units,
|
|
46
|
-
* of the geometry it is given — the raw strokes on the device, the recorded ones in a sample
|
|
46
|
+
* of the geometry it is given — the raw strokes on the device, the recorded ones in a sample.
|
|
47
47
|
* Its box in the fractions of a cut-out is the cut-out's.
|
|
48
48
|
*/
|
|
49
49
|
export function rectOf(ids, strokes) {
|
package/lib/core/hands.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A pointer as the hands on the sheet see it
|
|
3
|
-
* is, and when. The DOM-free part sees no DOM
|
|
2
|
+
* A pointer as the hands on the sheet see it: where it is on the screen, how big its contact
|
|
3
|
+
* is, and when (R29). The DOM-free part sees no DOM, so the element hands it this much of each
|
|
4
4
|
* pointer event. The contact's size decides only what the pointer may do: it goes into no stroke,
|
|
5
|
-
* no history and no sample
|
|
5
|
+
* no history and no sample.
|
|
6
6
|
*/
|
|
7
7
|
export interface Contact {
|
|
8
8
|
/** The event's `pointerId`. */
|
|
@@ -22,33 +22,34 @@ export interface Contact {
|
|
|
22
22
|
readonly time: number;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* A touch wider or taller than this, in CSS pixels, is a palm
|
|
25
|
+
* A touch wider or taller than this, in CSS pixels, is a palm. WebKit on iPadOS gives a touch
|
|
26
26
|
* twice its contact's radius, a fingertip's 40–60 px by one report, so canvas-api's 30 px would
|
|
27
27
|
* take most fingers there for palms. No tablet has measured it.
|
|
28
28
|
*/
|
|
29
29
|
export declare const PALM_PX = 100;
|
|
30
30
|
/**
|
|
31
|
-
* Two touches that come down at most this many milliseconds apart are two fingers of one gesture
|
|
32
|
-
*
|
|
31
|
+
* Two touches that come down at most this many milliseconds apart are two fingers of one gesture:
|
|
32
|
+
* Android's tap timeout, 100 ms, with a margin for children's fingers.
|
|
33
33
|
*/
|
|
34
34
|
export declare const PAIR_MS = 150;
|
|
35
35
|
/**
|
|
36
|
-
* How far a touch may wander, in CSS pixels, before it is going somewhere
|
|
36
|
+
* How far a touch may wander, in CSS pixels, before it is going somewhere: Android's touch
|
|
37
37
|
* slop, 8 dp. A finger that has gone further is writing, and two fingers scroll once their middle
|
|
38
38
|
* has gone further.
|
|
39
39
|
*/
|
|
40
40
|
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
|
-
* they pass the slop, scroll along that axis alone for the rest of the gesture
|
|
43
|
+
* they pass the slop, scroll along that axis alone for the rest of the gesture: a scroll
|
|
44
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
|
|
50
|
-
* turns it off: while it is on, a finger neither writes nor erases, and moves the sheet
|
|
51
|
-
* it lives in memory alone: nothing is stored or sent, and a
|
|
49
|
+
* The pen mode: 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. One is
|
|
51
|
+
* shared by every sheet of a page, and it lives in memory alone: nothing is stored or sent, and a
|
|
52
|
+
* new page starts without it.
|
|
52
53
|
*
|
|
53
54
|
* It knows, too, whether any sheet of the page is written on, and tells its sheets when the last
|
|
54
55
|
* stroke ends: each bar shows the mode as it is then.
|
|
@@ -82,7 +83,12 @@ export interface HandsSheet {
|
|
|
82
83
|
*/
|
|
83
84
|
scroll(dx: number, dy: number, fresh: boolean): void;
|
|
84
85
|
/**
|
|
85
|
-
*
|
|
86
|
+
* Two fingers drew apart, or together, by `ratio` of the span between them: the sheet's zoom
|
|
87
|
+
* goes by it, the point of the sheet at `x` and `y` on the screen, their middle, standing.
|
|
88
|
+
*/
|
|
89
|
+
zoom(ratio: number, x: number, y: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the sheet scrolls across at all now: one wider than its container does. A
|
|
86
92
|
* gesture on a sheet that does not goes by its travel down alone.
|
|
87
93
|
*/
|
|
88
94
|
across(): boolean;
|
|
@@ -91,16 +97,16 @@ export interface HandsSheet {
|
|
|
91
97
|
* What a pointer down on the sheet does:
|
|
92
98
|
* - "writes": it may write or erase, and does while the sheet says it is the writer;
|
|
93
99
|
* - "waits": a finger in pen mode, waiting for a second to scroll with, or to go past the slop
|
|
94
|
-
* and drag the sheet alone
|
|
100
|
+
* and drag the sheet alone;
|
|
95
101
|
* - "scrolls": the finger that drags the sheet, or one of the two fingers of a gesture;
|
|
96
102
|
* - "palm": too big for a finger, it does nothing until it lifts;
|
|
97
103
|
* - "idle": it does nothing until it lifts.
|
|
98
104
|
*/
|
|
99
105
|
export type Role = "writes" | "waits" | "scrolls" | "palm" | "idle";
|
|
100
106
|
/**
|
|
101
|
-
* The hands on a sheet
|
|
107
|
+
* The hands on a sheet: which pointer may write, which is a palm, and which two fingers
|
|
102
108
|
* scroll, for a pen, fingers and a mouse on one screen.
|
|
103
|
-
* - One pointer writes at a time
|
|
109
|
+
* - One pointer writes at a time, and the sheet's recorder and eraser say which.
|
|
104
110
|
* - A pen's touch puts the page in pen mode and takes away the stroke of a touch under way: it was
|
|
105
111
|
* a palm. While a pen or a mouse writes, a touch does nothing until it lifts.
|
|
106
112
|
* - A touch wider or taller than `PALM_PX`, at its `pointerdown` or at any move, is a palm: it does
|
|
@@ -110,11 +116,13 @@ export type Role = "writes" | "waits" | "scrolls" | "palm" | "idle";
|
|
|
110
116
|
* comes later does nothing.
|
|
111
117
|
* - In pen mode a finger writes nothing, and two that come down within `PAIR_MS` scroll. One that
|
|
112
118
|
* goes further than `SLOP_PX` alone, before a second comes, drags the sheet: the second does
|
|
113
|
-
* nothing then
|
|
119
|
+
* nothing then.
|
|
114
120
|
* - A third finger does nothing. When one of the two lifts, the other does nothing until it lifts.
|
|
115
121
|
* - Two fingers scroll by the travel of their middle on the screen, and one by its own, past its
|
|
116
122
|
* first `SLOP_PX`: along one axis alone if it went `RAIL` times further along it than along the
|
|
117
123
|
* other, or else both.
|
|
124
|
+
* - Two fingers whose span has changed by more than `SLOP_PX` pinch too: the zoom goes by the
|
|
125
|
+
* span's ratio from there, about their middle.
|
|
118
126
|
* - Any other pointer, a mouse or one of no type, writes when nothing does, whatever the mode.
|
|
119
127
|
*/
|
|
120
128
|
export declare class Hands {
|
package/lib/core/hands.js
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A touch wider or taller than this, in CSS pixels, is a palm
|
|
2
|
+
* A touch wider or taller than this, in CSS pixels, is a palm. WebKit on iPadOS gives a touch
|
|
3
3
|
* twice its contact's radius, a fingertip's 40–60 px by one report, so canvas-api's 30 px would
|
|
4
4
|
* take most fingers there for palms. No tablet has measured it.
|
|
5
5
|
*/
|
|
6
6
|
export const PALM_PX = 100;
|
|
7
7
|
/**
|
|
8
|
-
* Two touches that come down at most this many milliseconds apart are two fingers of one gesture
|
|
9
|
-
*
|
|
8
|
+
* Two touches that come down at most this many milliseconds apart are two fingers of one gesture:
|
|
9
|
+
* Android's tap timeout, 100 ms, with a margin for children's fingers.
|
|
10
10
|
*/
|
|
11
11
|
export const PAIR_MS = 150;
|
|
12
12
|
/**
|
|
13
|
-
* How far a touch may wander, in CSS pixels, before it is going somewhere
|
|
13
|
+
* How far a touch may wander, in CSS pixels, before it is going somewhere: Android's touch
|
|
14
14
|
* slop, 8 dp. A finger that has gone further is writing, and two fingers scroll once their middle
|
|
15
15
|
* has gone further.
|
|
16
16
|
*/
|
|
17
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
|
-
* they pass the slop, scroll along that axis alone for the rest of the gesture
|
|
20
|
+
* they pass the slop, scroll along that axis alone for the rest of the gesture: a scroll
|
|
21
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
|
|
27
|
-
* turns it off: while it is on, a finger neither writes nor erases, and moves the sheet
|
|
28
|
-
* it lives in memory alone: nothing is stored or sent, and a
|
|
26
|
+
* The pen mode: 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. One is
|
|
28
|
+
* shared by every sheet of a page, and it lives in memory alone: nothing is stored or sent, and a
|
|
29
|
+
* new page starts without it.
|
|
29
30
|
*
|
|
30
31
|
* It knows, too, whether any sheet of the page is written on, and tells its sheets when the last
|
|
31
32
|
* stroke ends: each bar shows the mode as it is then.
|
|
@@ -79,9 +80,9 @@ export class PenMode {
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
|
-
* The hands on a sheet
|
|
83
|
+
* The hands on a sheet: which pointer may write, which is a palm, and which two fingers
|
|
83
84
|
* scroll, for a pen, fingers and a mouse on one screen.
|
|
84
|
-
* - One pointer writes at a time
|
|
85
|
+
* - One pointer writes at a time, and the sheet's recorder and eraser say which.
|
|
85
86
|
* - A pen's touch puts the page in pen mode and takes away the stroke of a touch under way: it was
|
|
86
87
|
* a palm. While a pen or a mouse writes, a touch does nothing until it lifts.
|
|
87
88
|
* - A touch wider or taller than `PALM_PX`, at its `pointerdown` or at any move, is a palm: it does
|
|
@@ -91,11 +92,13 @@ export class PenMode {
|
|
|
91
92
|
* comes later does nothing.
|
|
92
93
|
* - In pen mode a finger writes nothing, and two that come down within `PAIR_MS` scroll. One that
|
|
93
94
|
* goes further than `SLOP_PX` alone, before a second comes, drags the sheet: the second does
|
|
94
|
-
* nothing then
|
|
95
|
+
* nothing then.
|
|
95
96
|
* - A third finger does nothing. When one of the two lifts, the other does nothing until it lifts.
|
|
96
97
|
* - Two fingers scroll by the travel of their middle on the screen, and one by its own, past its
|
|
97
98
|
* first `SLOP_PX`: along one axis alone if it went `RAIL` times further along it than along the
|
|
98
99
|
* other, or else both.
|
|
100
|
+
* - Two fingers whose span has changed by more than `SLOP_PX` pinch too: the zoom goes by the
|
|
101
|
+
* span's ratio from there, about their middle.
|
|
99
102
|
* - Any other pointer, a mouse or one of no type, writes when nothing does, whatever the mode.
|
|
100
103
|
*/
|
|
101
104
|
export class Hands {
|
|
@@ -146,7 +149,7 @@ export class Hands {
|
|
|
146
149
|
hand.x = contact.x;
|
|
147
150
|
hand.y = contact.y;
|
|
148
151
|
hand.travel = Math.max(hand.travel, Math.hypot(contact.x - hand.x0, contact.y - hand.y0));
|
|
149
|
-
// A finger of pen mode that has gone past the slop with no second drags the sheet alone
|
|
152
|
+
// A finger of pen mode that has gone past the slop with no second drags the sheet alone,
|
|
150
153
|
// but not while a sheet of the page is written on: nothing moves under the pen. Another finger
|
|
151
154
|
// that waits then does nothing until it lifts, and takes no drag over from where it came down.
|
|
152
155
|
if (hand.role === "waits" &&
|
|
@@ -163,10 +166,13 @@ export class Hands {
|
|
|
163
166
|
last: undefined,
|
|
164
167
|
across: true,
|
|
165
168
|
down: true,
|
|
169
|
+
span0: 0,
|
|
170
|
+
span: undefined,
|
|
171
|
+
unpaired: undefined,
|
|
166
172
|
};
|
|
167
173
|
}
|
|
168
174
|
if (hand.role === "scrolls")
|
|
169
|
-
this.#step();
|
|
175
|
+
this.#step(contact.pointerId);
|
|
170
176
|
return hand.role === "writes" && this.#sheet.writer() === contact.pointerId;
|
|
171
177
|
}
|
|
172
178
|
/** `pointerup`, `pointercancel` or a lost capture: the pointer has gone, and its gesture too. */
|
|
@@ -265,6 +271,9 @@ export class Hands {
|
|
|
265
271
|
last: undefined,
|
|
266
272
|
across: true,
|
|
267
273
|
down: true,
|
|
274
|
+
span0: spanOf(one, two),
|
|
275
|
+
span: undefined,
|
|
276
|
+
unpaired: undefined,
|
|
268
277
|
};
|
|
269
278
|
}
|
|
270
279
|
/** The gesture ends: its fingers do nothing until they lift. */
|
|
@@ -283,7 +292,7 @@ export class Hands {
|
|
|
283
292
|
* The two fingers' middle has moved, or the one finger: past the slop, the sheet goes with it,
|
|
284
293
|
* along the axes the gesture chose as it passed it.
|
|
285
294
|
*/
|
|
286
|
-
#step() {
|
|
295
|
+
#step(pointerId) {
|
|
287
296
|
const gesture = this.#gesture;
|
|
288
297
|
if (gesture === undefined)
|
|
289
298
|
return;
|
|
@@ -291,7 +300,17 @@ export class Hands {
|
|
|
291
300
|
const two = gesture.fingers.length === 2 ? this.#hands.get(gesture.fingers[1]) : one;
|
|
292
301
|
if (one === undefined || two === undefined)
|
|
293
302
|
return;
|
|
303
|
+
// Two fingers are read once both have moved: between their moves the middle stands half a
|
|
304
|
+
// step aside and the span is off, which would scroll a pinch off the point under it.
|
|
305
|
+
if (one !== two && !paired(gesture, pointerId))
|
|
306
|
+
return;
|
|
294
307
|
const middle = middleOf(one, two);
|
|
308
|
+
this.#move(gesture, middle);
|
|
309
|
+
if (one !== two)
|
|
310
|
+
this.#pinch(gesture, spanOf(one, two), middle);
|
|
311
|
+
}
|
|
312
|
+
/** The sheet goes with the fingers' middle, past the slop, along the axes the gesture chose. */
|
|
313
|
+
#move(gesture, middle) {
|
|
295
314
|
if (gesture.last === undefined) {
|
|
296
315
|
// A sheet that does not scroll across counts the travel down alone.
|
|
297
316
|
const dx = this.#sheet.across() ? middle.x - gesture.from.x : 0;
|
|
@@ -314,6 +333,39 @@ export class Hands {
|
|
|
314
333
|
if (dx !== 0 || dy !== 0)
|
|
315
334
|
this.#sheet.scroll(dx, dy, false);
|
|
316
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* The two fingers' span has changed: past the slop, the zoom goes by its ratio to the last
|
|
338
|
+
* step's, from the slop on, without a jump, about their middle.
|
|
339
|
+
*/
|
|
340
|
+
#pinch(gesture, span, middle) {
|
|
341
|
+
if (gesture.span === undefined) {
|
|
342
|
+
const change = span - gesture.span0;
|
|
343
|
+
if (Math.abs(change) <= SLOP_PX)
|
|
344
|
+
return;
|
|
345
|
+
gesture.span = gesture.span0 + Math.sign(change) * SLOP_PX;
|
|
346
|
+
}
|
|
347
|
+
if (span > 0 && gesture.span > 0 && span !== gesture.span) {
|
|
348
|
+
this.#sheet.zoom(span / gesture.span, middle.x, middle.y);
|
|
349
|
+
}
|
|
350
|
+
gesture.span = span;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Whether two fingers are read at this finger's move — their middle and their span: once both have
|
|
355
|
+
* moved, or this one twice while the other stood still.
|
|
356
|
+
*/
|
|
357
|
+
function paired(gesture, pointerId) {
|
|
358
|
+
if (gesture.unpaired === undefined) {
|
|
359
|
+
gesture.unpaired = pointerId;
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
if (gesture.unpaired !== pointerId)
|
|
363
|
+
gesture.unpaired = undefined;
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
/** The span between two fingers on the screen. */
|
|
367
|
+
function spanOf(one, two) {
|
|
368
|
+
return Math.hypot(one.x - two.x, one.y - two.y);
|
|
317
369
|
}
|
|
318
370
|
/** The middle of two fingers on the screen. */
|
|
319
371
|
function middleOf(one, two) {
|
package/lib/core/history.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { HistoryEvent } from "@altnovatrail/spec/canvas";
|
|
2
2
|
import type { Stroke } from "./ink.js";
|
|
3
3
|
/**
|
|
4
|
-
* An event of the history of writing
|
|
5
|
-
*
|
|
4
|
+
* An event of the history of writing: spec's type, of the contract of canvas and app.
|
|
5
|
+
* What an action on the sheet did, at the sheet's time `t` when it landed, in the
|
|
6
6
|
* order the actions landed; each event says which strokes it put on the sheet or took off, so
|
|
7
7
|
* whoever reads the history replays it without the rules of the stack of undo (R19). Those the
|
|
8
|
-
* sheet hands out are frozen through
|
|
8
|
+
* sheet hands out are frozen through.
|
|
9
9
|
*/
|
|
10
10
|
export type { HistoryEvent };
|
|
11
11
|
/**
|
|
12
12
|
* The strokes a history leaves on the sheet, in the order they were written: what the sheet shows
|
|
13
|
-
* after it
|
|
13
|
+
* after it.
|
|
14
14
|
*/
|
|
15
15
|
export declare function replay(history: readonly HistoryEvent[]): Stroke[];
|
|
16
16
|
/**
|
|
17
|
-
* The events of a history given to the sheet
|
|
17
|
+
* The events of a history given to the sheet, each checked field by field and copied into
|
|
18
18
|
* frozen objects of the sheet's own, with only the fields the sheet keeps: others are passed over.
|
|
19
19
|
* A value that is not such a history is a TypeError that names the field. Each event must be one of
|
|
20
20
|
* the four, at a time from 0 that never goes back along the history; a stroke must have a new ID, a
|
|
@@ -22,18 +22,18 @@ export declare function replay(history: readonly HistoryEvent[]): Stroke[];
|
|
|
22
22
|
* times never going back and none after the time it landed. Times are checked for their order
|
|
23
23
|
* alone: strokes may overlap in time, as several pointers at once would write them. On a task from
|
|
24
24
|
* paper, `paper`, a stroke written on the tracing paper says so, `on: "tracing"`, its points from
|
|
25
|
-
* the paper's top left corner within the sheet's size; anywhere else `on` is a TypeError
|
|
26
|
-
*
|
|
25
|
+
* the paper's top left corner within the sheet's size; anywhere else `on` is a TypeError.
|
|
26
|
+
* Whether the actions keep the rules of the stack, the work on the sheet checks as it
|
|
27
27
|
* replays them (`Work.restore`).
|
|
28
28
|
*/
|
|
29
29
|
export declare function historyOf(value: unknown, paper?: boolean): HistoryEvent[];
|
|
30
30
|
/**
|
|
31
|
-
* An event, frozen through: its stroke with its points, or its lists of IDs
|
|
31
|
+
* An event, frozen through: its stroke with its points, or its lists of IDs. Whoever holds
|
|
32
32
|
* an event the sheet handed out cannot change the sheet by it.
|
|
33
33
|
*/
|
|
34
34
|
export declare function frozen(event: HistoryEvent): HistoryEvent;
|
|
35
35
|
/**
|
|
36
|
-
* Whether a value given as a history is the history the sheet has
|
|
36
|
+
* Whether a value given as a history is the history the sheet has: the very array, or a list
|
|
37
37
|
* whose every event says what the sheet's says, by the fields the sheet keeps — others are passed
|
|
38
38
|
* over. `undefined` is the empty history. It never throws: a value that is no history is simply not
|
|
39
39
|
* the same one.
|
package/lib/core/history.js
CHANGED
|
@@ -2,7 +2,7 @@ import { record, shown } from "./fields.js";
|
|
|
2
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
|
-
* after it
|
|
5
|
+
* after it.
|
|
6
6
|
*/
|
|
7
7
|
export function replay(history) {
|
|
8
8
|
const written = [];
|
|
@@ -29,7 +29,7 @@ export function replay(history) {
|
|
|
29
29
|
return written.filter((stroke) => visible.has(stroke.id));
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* The events of a history given to the sheet
|
|
32
|
+
* The events of a history given to the sheet, each checked field by field and copied into
|
|
33
33
|
* frozen objects of the sheet's own, with only the fields the sheet keeps: others are passed over.
|
|
34
34
|
* A value that is not such a history is a TypeError that names the field. Each event must be one of
|
|
35
35
|
* the four, at a time from 0 that never goes back along the history; a stroke must have a new ID, a
|
|
@@ -37,8 +37,8 @@ export function replay(history) {
|
|
|
37
37
|
* times never going back and none after the time it landed. Times are checked for their order
|
|
38
38
|
* alone: strokes may overlap in time, as several pointers at once would write them. On a task from
|
|
39
39
|
* paper, `paper`, a stroke written on the tracing paper says so, `on: "tracing"`, its points from
|
|
40
|
-
* the paper's top left corner within the sheet's size; anywhere else `on` is a TypeError
|
|
41
|
-
*
|
|
40
|
+
* the paper's top left corner within the sheet's size; anywhere else `on` is a TypeError.
|
|
41
|
+
* Whether the actions keep the rules of the stack, the work on the sheet checks as it
|
|
42
42
|
* replays them (`Work.restore`).
|
|
43
43
|
*/
|
|
44
44
|
export function historyOf(value, paper = false) {
|
|
@@ -90,7 +90,7 @@ export function historyOf(value, paper = false) {
|
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
|
-
* An event, frozen through: its stroke with its points, or its lists of IDs
|
|
93
|
+
* An event, frozen through: its stroke with its points, or its lists of IDs. Whoever holds
|
|
94
94
|
* an event the sheet handed out cannot change the sheet by it.
|
|
95
95
|
*/
|
|
96
96
|
export function frozen(event) {
|
|
@@ -110,7 +110,7 @@ export function frozen(event) {
|
|
|
110
110
|
return Object.freeze(event);
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
|
-
* Whether a value given as a history is the history the sheet has
|
|
113
|
+
* Whether a value given as a history is the history the sheet has: the very array, or a list
|
|
114
114
|
* whose every event says what the sheet's says, by the fields the sheet keeps — others are passed
|
|
115
115
|
* over. `undefined` is the empty history. It never throws: a value that is no history is simply not
|
|
116
116
|
* the same one.
|
package/lib/core/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
// The DOM-free part of the canvas, the package's entry point @altnovatrail/canvas/core: plain
|
|
2
2
|
// TypeScript that runs the same in a browser and in Node, for the tests and the synthetic samples
|
|
3
|
-
// too
|
|
3
|
+
// too. Importing it registers no element: the element is the other entry point. It
|
|
4
4
|
// gives the sheet's size, the types of the data the element takes and gives — the strokes and the
|
|
5
5
|
// history of writing, the task, the worked example and the manifest, how far the learner has gone
|
|
6
|
-
// through the example's demo
|
|
7
|
-
// task from paper with where its tracing paper lay
|
|
8
|
-
// spec
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// vectors pin them (R94 spec).
|
|
6
|
+
// through the example's demo and the context of a submission, of a sheet, a workbook or a
|
|
7
|
+
// task from paper with where its tracing paper lay, all of spec's types, and the tutor's marks,
|
|
8
|
+
// spec's types too — and the fold of a history into the strokes it leaves, so that a consumer reads
|
|
9
|
+
// a history it keeps without the DOM. The code runs without the DOM, but spec's declarations of the
|
|
10
|
+
// element's contract, which its types come from, name the DOM's types too: a consumer without the
|
|
11
|
+
// DOM's types skips them with skipLibCheck. The rules of the groups, the crop and the snapping stay
|
|
12
|
+
// inside: the eval protocol has taken them as they are, and spec's test vectors pin them.
|
|
14
13
|
export { replay } from "./history.js";
|
|
15
14
|
export { SHEET } from "./sheet.js";
|
package/lib/core/ink.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// A point of a stroke and a stroke
|
|
2
|
-
// and app
|
|
1
|
+
// A point of a stroke and a stroke: spec's types, of the contract of canvas
|
|
2
|
+
// and app — where a point lies on the sheet, in logical units, when it was written
|
|
3
3
|
// and how hard the pointer pressed, and a stroke's ID on its sheet, its pointer's type and its
|
|
4
|
-
// points. Only a pen's pressure changes the width of the line (R05
|
|
4
|
+
// points. Only a pen's pressure changes the width of the line (R05).
|
|
5
5
|
export {};
|
package/lib/core/manifest.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The version of the module format the element reads: while the format is v0, the platform reads
|
|
3
|
-
* its current version alone, and a module of another is refused with the reason
|
|
4
|
-
* format's rules of a module's versions are module-kit's and api's: the element compares none
|
|
3
|
+
* its current version alone, and a module of another is refused with the reason. The
|
|
4
|
+
* format's rules of a module's versions are module-kit's and api's: the element compares none.
|
|
5
5
|
*/
|
|
6
6
|
export declare const FORMAT = "0.4";
|
|
7
|
-
/** The open view of a module's manifest, whole: spec's type
|
|
7
|
+
/** The open view of a module's manifest, whole: spec's type. */
|
|
8
8
|
export type { Manifest } from "@altnovatrail/spec/formatv0/open";
|
|
9
9
|
/**
|
|
10
10
|
* What the element makes of a manifest: the height of a digit its crop for checking is drawn at,
|
package/lib/core/manifest.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// The module's manifest as the element reads it
|
|
1
|
+
// The module's manifest as the element reads it: the open view of manifest.yaml, of which it
|
|
2
2
|
// takes three fields — the version of the module format, the height of a digit on the crop for
|
|
3
|
-
// checking and the explanation language, which the task's statement is in
|
|
3
|
+
// checking and the explanation language, which the task's statement is in. The rest of
|
|
4
4
|
// the manifest it passes over: what a manifest may hold, module-kit checks. Its canvas settings are
|
|
5
5
|
// the canvas's own, though: a setting the element does not know is a TypeError, as a field of a
|
|
6
6
|
// task is, for the element would draw the module's canvas without it. The type is spec's, from
|
|
7
|
-
// its npm package at the version of the spec/ submodule
|
|
8
|
-
// manifest's open view once for a module's package and gives it to the element as it is
|
|
7
|
+
// its npm package at the version of the spec/ submodule, and app gets the
|
|
8
|
+
// manifest's open view once for a module's package and gives it to the element as it is.
|
|
9
9
|
import { CROP } from "./crop.js";
|
|
10
10
|
import { closed, record, shown, whole } from "./fields.js";
|
|
11
11
|
/**
|
|
12
12
|
* The version of the module format the element reads: while the format is v0, the platform reads
|
|
13
|
-
* its current version alone, and a module of another is refused with the reason
|
|
14
|
-
* format's rules of a module's versions are module-kit's and api's: the element compares none
|
|
13
|
+
* its current version alone, and a module of another is refused with the reason. The
|
|
14
|
+
* format's rules of a module's versions are module-kit's and api's: the element compares none.
|
|
15
15
|
*/
|
|
16
16
|
export const FORMAT = "0.4";
|
|
17
17
|
/** The settings without a manifest: digits of 24 px, and the element's own language. */
|