@altnovatrail/canvas 0.3.35 → 0.3.37

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.
@@ -0,0 +1,110 @@
1
+ import type { TracingState } from "@altnovatrail/spec/canvas";
2
+ import type { Box } from "./geometry.js";
3
+ import type { Stroke } from "./ink.js";
4
+ import type { Point } from "./screen.js";
5
+ /**
6
+ * Where the tracing paper of a task from paper lies on the sheet, and whether it is hidden (R87):
7
+ * spec's type, of the contract of canvas and app (R74 spec).
8
+ */
9
+ export type { TracingState };
10
+ /**
11
+ * The tracing paper's rule (R87), in sheet units: the crop is drawn as large as fits within
12
+ * `width` × `height`, in its own proportions; it starts at `at`, right of the bar of buttons, which
13
+ * stands over the sheet's left edge; the keyboard moves it by `step`, or by `leap` with Shift. The
14
+ * dots of its sheet stand `dots` apart.
15
+ */
16
+ export declare const TRACING: Readonly<{
17
+ width: 800;
18
+ height: 700;
19
+ at: readonly [180, 60];
20
+ step: 20;
21
+ leap: 100;
22
+ dots: 25;
23
+ }>;
24
+ /** The tracing paper's size on the sheet, in units. */
25
+ export interface Size {
26
+ readonly width: number;
27
+ readonly height: number;
28
+ }
29
+ /** The size before the crop's picture is read: the largest the tracing paper may be. */
30
+ export declare const LARGEST: Size;
31
+ /**
32
+ * The tracing paper's size for a crop `width` × `height` px (R87): as large as fits within the
33
+ * rule's box, in the crop's proportions. A picture of no size has the largest.
34
+ */
35
+ export declare function sizeOf(width: number, height: number): Size;
36
+ /** Where a task from paper starts its tracing paper: at the rule's place, shown. */
37
+ export declare const TRACING_START: TracingState;
38
+ /**
39
+ * A tracing state a consumer gives (R74 spec), checked and frozen: an object of `at`, [x, y] in
40
+ * units, finite numbers, and `hidden`, true or false; other fields are passed over. A state that
41
+ * puts the tracing paper of `size` wholly off the sheet is a TypeError, as is anything else that is
42
+ * not such a state.
43
+ */
44
+ export declare function tracingStateOf(value: unknown, size: Size): TracingState;
45
+ /**
46
+ * The fields of a tracing state at `path`, checked and frozen: `at`, [x, y] in units, finite
47
+ * numbers, and `hidden`, true or false; other fields are passed over. Anything else is a
48
+ * TypeError. Where it lies on the sheet is the caller's to check.
49
+ */
50
+ export declare function tracingFieldsOf(value: unknown, path: string): TracingState;
51
+ /** Whether the tracing paper of `size` at `at` lies wholly off the sheet, touching it at most. */
52
+ export declare function whollyOff(at: readonly [number, number], size: Size): boolean;
53
+ /** Whether two tracing states say the same. */
54
+ export declare function sameTracing(a: TracingState, b: TracingState): boolean;
55
+ /** The tracing paper's rectangle on the sheet, in units. */
56
+ export declare function rectOf(at: readonly [number, number], size: Size): Box;
57
+ /**
58
+ * The place nearest `at` where the tracing paper of `size` lies wholly on the sheet: where the
59
+ * learner's grip and keys leave it (R87).
60
+ */
61
+ export declare function keptOn(at: readonly [number, number], size: Size): readonly [number, number];
62
+ /** Whether a point of the sheet lies on the tracing paper, its edges too. */
63
+ export declare function onTracing(point: Point, at: readonly [number, number], size: Size): boolean;
64
+ /**
65
+ * A point of the sheet as a stroke on the tracing paper holds it: from the paper's top left corner,
66
+ * kept to the paper (R74 spec).
67
+ */
68
+ export declare function toTracing(point: Point, at: readonly [number, number], size: Size): Point;
69
+ /**
70
+ * A stroke of the tracing paper where it lies on the sheet: its points moved by `at`, and kept to
71
+ * the sheet, should the paper lie in part beyond it — the rules of the groups and the crop hold on
72
+ * the sheet alone (R24, R25). The same ID, kind and times.
73
+ */
74
+ export declare function onSheet(stroke: Stroke, at: readonly [number, number]): Stroke;
75
+ /**
76
+ * The box of a tracing paper's stroke where it lies on the sheet, from the box of its points on the
77
+ * paper: the box of `onSheet`'s points, for moving and keeping to the sheet keep the order of the
78
+ * numbers, without a copy of the stroke.
79
+ */
80
+ export declare function boxOnSheet(box: Box, at: readonly [number, number]): Box;
81
+ /**
82
+ * The tracing paper's rectangle on the sheet in whole tenths of a unit, as the crop counts (R25),
83
+ * kept to the sheet: the part of it a crop of the work takes in.
84
+ */
85
+ export declare function tenthsOf(rect: Box): Box;
86
+ /** A grey picture, a byte to a pixel, row by row from the top: white 255. */
87
+ export interface Gray {
88
+ readonly gray: Uint8Array;
89
+ readonly width: number;
90
+ readonly height: number;
91
+ }
92
+ /**
93
+ * The grey of a picture's pixels, four bytes each — red, green, blue and alpha — as a canvas reads
94
+ * them: the luma of BT.601 in whole numbers, over white where a pixel is transparent (R87).
95
+ */
96
+ export declare function grayOf(rgba: Uint8ClampedArray | Uint8Array, width: number, height: number): Gray;
97
+ /**
98
+ * The crop's picture laid into the pixels of a crop of the work (R87), multiplied, as the screen
99
+ * lays the tracing paper over the sheet: `ink` the crop's pixels, `width` px wide, and `rect`
100
+ * where the tracing paper lies on them, in px, which may reach beyond them. Each pixel of the crop
101
+ * under the paper takes the mean of the picture's pixels whose centres fall within it, or the one
102
+ * nearest its centre when none does, so the crop shrinks or grows by sums of whole numbers alone,
103
+ * the same in every engine. Changes `ink` in place.
104
+ */
105
+ export declare function layOver(ink: Uint8Array, width: number, picture: Gray, rect: {
106
+ readonly left: number;
107
+ readonly top: number;
108
+ readonly right: number;
109
+ readonly bottom: number;
110
+ }): void;
@@ -0,0 +1,219 @@
1
+ import { record, shown } from "./fields.js";
2
+ import { tenths } from "./geometry.js";
3
+ import { SHEET } from "./sheet.js";
4
+ /**
5
+ * The tracing paper's rule (R87), in sheet units: the crop is drawn as large as fits within
6
+ * `width` × `height`, in its own proportions; it starts at `at`, right of the bar of buttons, which
7
+ * stands over the sheet's left edge; the keyboard moves it by `step`, or by `leap` with Shift. The
8
+ * dots of its sheet stand `dots` apart.
9
+ */
10
+ export const TRACING = Object.freeze({
11
+ width: 800,
12
+ height: 700,
13
+ at: Object.freeze([180, 60]),
14
+ step: 20,
15
+ leap: 100,
16
+ dots: 25,
17
+ });
18
+ /** The size before the crop's picture is read: the largest the tracing paper may be. */
19
+ export const LARGEST = Object.freeze({ width: TRACING.width, height: TRACING.height });
20
+ /**
21
+ * The tracing paper's size for a crop `width` × `height` px (R87): as large as fits within the
22
+ * rule's box, in the crop's proportions. A picture of no size has the largest.
23
+ */
24
+ export function sizeOf(width, height) {
25
+ if (!(width > 0 && height > 0))
26
+ return LARGEST;
27
+ const scale = Math.min(TRACING.width / width, TRACING.height / height);
28
+ return Object.freeze({ width: width * scale, height: height * scale });
29
+ }
30
+ /** Where a task from paper starts its tracing paper: at the rule's place, shown. */
31
+ export const TRACING_START = Object.freeze({
32
+ at: Object.freeze([TRACING.at[0], TRACING.at[1]]),
33
+ hidden: false,
34
+ });
35
+ /**
36
+ * A tracing state a consumer gives (R74 spec), checked and frozen: an object of `at`, [x, y] in
37
+ * units, finite numbers, and `hidden`, true or false; other fields are passed over. A state that
38
+ * puts the tracing paper of `size` wholly off the sheet is a TypeError, as is anything else that is
39
+ * not such a state.
40
+ */
41
+ export function tracingStateOf(value, size) {
42
+ const state = tracingFieldsOf(value, "tracing");
43
+ if (whollyOff(state.at, size)) {
44
+ throw new TypeError(`tracing.at: ${shown(state.at)} puts the tracing paper wholly off the sheet`);
45
+ }
46
+ return state;
47
+ }
48
+ /**
49
+ * The fields of a tracing state at `path`, checked and frozen: `at`, [x, y] in units, finite
50
+ * numbers, and `hidden`, true or false; other fields are passed over. Anything else is a
51
+ * TypeError. Where it lies on the sheet is the caller's to check.
52
+ */
53
+ export function tracingFieldsOf(value, path) {
54
+ const fields = record(value, path);
55
+ const at = fields.at;
56
+ if (!Array.isArray(at) ||
57
+ at.length !== 2 ||
58
+ !at.every((n) => typeof n === "number" && Number.isFinite(n))) {
59
+ throw new TypeError(`${path}.at: [x, y], its top left corner in sheet units, not ${shown(at)}`);
60
+ }
61
+ if (typeof fields.hidden !== "boolean") {
62
+ throw new TypeError(`${path}.hidden: true or false, not ${shown(fields.hidden)}`);
63
+ }
64
+ const [x, y] = at;
65
+ return Object.freeze({ at: Object.freeze([x, y]), hidden: fields.hidden });
66
+ }
67
+ /** Whether the tracing paper of `size` at `at` lies wholly off the sheet, touching it at most. */
68
+ export function whollyOff(at, size) {
69
+ const [x, y] = at;
70
+ return x >= SHEET.width || y >= SHEET.height || x + size.width <= 0 || y + size.height <= 0;
71
+ }
72
+ /** Whether two tracing states say the same. */
73
+ export function sameTracing(a, b) {
74
+ return a.at[0] === b.at[0] && a.at[1] === b.at[1] && a.hidden === b.hidden;
75
+ }
76
+ /** The tracing paper's rectangle on the sheet, in units. */
77
+ export function rectOf(at, size) {
78
+ return { minX: at[0], minY: at[1], maxX: at[0] + size.width, maxY: at[1] + size.height };
79
+ }
80
+ /**
81
+ * The place nearest `at` where the tracing paper of `size` lies wholly on the sheet: where the
82
+ * learner's grip and keys leave it (R87).
83
+ */
84
+ export function keptOn(at, size) {
85
+ return Object.freeze([
86
+ clamp(at[0], 0, Math.max(0, SHEET.width - size.width)),
87
+ clamp(at[1], 0, Math.max(0, SHEET.height - size.height)),
88
+ ]);
89
+ }
90
+ /** Whether a point of the sheet lies on the tracing paper, its edges too. */
91
+ export function onTracing(point, at, size) {
92
+ const { minX, minY, maxX, maxY } = rectOf(at, size);
93
+ return point.x >= minX && point.x <= maxX && point.y >= minY && point.y <= maxY;
94
+ }
95
+ /**
96
+ * A point of the sheet as a stroke on the tracing paper holds it: from the paper's top left corner,
97
+ * kept to the paper (R74 spec).
98
+ */
99
+ export function toTracing(point, at, size) {
100
+ return {
101
+ x: clamp(point.x - at[0], 0, size.width),
102
+ y: clamp(point.y - at[1], 0, size.height),
103
+ };
104
+ }
105
+ /**
106
+ * A stroke of the tracing paper where it lies on the sheet: its points moved by `at`, and kept to
107
+ * the sheet, should the paper lie in part beyond it — the rules of the groups and the crop hold on
108
+ * the sheet alone (R24, R25). The same ID, kind and times.
109
+ */
110
+ export function onSheet(stroke, at) {
111
+ return Object.freeze({
112
+ id: stroke.id,
113
+ kind: stroke.kind,
114
+ points: Object.freeze(stroke.points.map(({ x, y, t, p }) => Object.freeze({
115
+ x: clamp(x + at[0], 0, SHEET.width),
116
+ y: clamp(y + at[1], 0, SHEET.height),
117
+ t,
118
+ p,
119
+ }))),
120
+ });
121
+ }
122
+ /**
123
+ * The box of a tracing paper's stroke where it lies on the sheet, from the box of its points on the
124
+ * paper: the box of `onSheet`'s points, for moving and keeping to the sheet keep the order of the
125
+ * numbers, without a copy of the stroke.
126
+ */
127
+ export function boxOnSheet(box, at) {
128
+ return {
129
+ minX: clamp(box.minX + at[0], 0, SHEET.width),
130
+ minY: clamp(box.minY + at[1], 0, SHEET.height),
131
+ maxX: clamp(box.maxX + at[0], 0, SHEET.width),
132
+ maxY: clamp(box.maxY + at[1], 0, SHEET.height),
133
+ };
134
+ }
135
+ /**
136
+ * The tracing paper's rectangle on the sheet in whole tenths of a unit, as the crop counts (R25),
137
+ * kept to the sheet: the part of it a crop of the work takes in.
138
+ */
139
+ export function tenthsOf(rect) {
140
+ return {
141
+ minX: tenths(clamp(rect.minX, 0, SHEET.width)),
142
+ minY: tenths(clamp(rect.minY, 0, SHEET.height)),
143
+ maxX: tenths(clamp(rect.maxX, 0, SHEET.width)),
144
+ maxY: tenths(clamp(rect.maxY, 0, SHEET.height)),
145
+ };
146
+ }
147
+ /**
148
+ * The grey of a picture's pixels, four bytes each — red, green, blue and alpha — as a canvas reads
149
+ * them: the luma of BT.601 in whole numbers, over white where a pixel is transparent (R87).
150
+ */
151
+ export function grayOf(rgba, width, height) {
152
+ if (rgba.length !== 4 * width * height) {
153
+ throw new RangeError(`${rgba.length} bytes are no picture ${width} × ${height}`);
154
+ }
155
+ const gray = new Uint8Array(width * height);
156
+ for (let at = 0; at < gray.length; at++) {
157
+ const r = rgba[4 * at];
158
+ const g = rgba[4 * at + 1];
159
+ const b = rgba[4 * at + 2];
160
+ const a = rgba[4 * at + 3];
161
+ const luma = Math.round((299 * r + 587 * g + 114 * b) / 1000);
162
+ gray[at] = Math.round((luma * a + 255 * (255 - a)) / 255);
163
+ }
164
+ return { gray, width, height };
165
+ }
166
+ /**
167
+ * The crop's picture laid into the pixels of a crop of the work (R87), multiplied, as the screen
168
+ * lays the tracing paper over the sheet: `ink` the crop's pixels, `width` px wide, and `rect`
169
+ * where the tracing paper lies on them, in px, which may reach beyond them. Each pixel of the crop
170
+ * under the paper takes the mean of the picture's pixels whose centres fall within it, or the one
171
+ * nearest its centre when none does, so the crop shrinks or grows by sums of whole numbers alone,
172
+ * the same in every engine. Changes `ink` in place.
173
+ */
174
+ export function layOver(ink, width, picture, rect) {
175
+ const height = ink.length / width;
176
+ const across = (rect.right - rect.left) / picture.width;
177
+ const down = (rect.bottom - rect.top) / picture.height;
178
+ if (!(across > 0 && down > 0))
179
+ return;
180
+ const firstColumn = Math.max(0, Math.floor(rect.left));
181
+ const lastColumn = Math.min(width - 1, Math.ceil(rect.right) - 1);
182
+ const firstRow = Math.max(0, Math.floor(rect.top));
183
+ const lastRow = Math.min(height - 1, Math.ceil(rect.bottom) - 1);
184
+ // The picture's columns, and rows, whose centres fall within each pixel of the crop.
185
+ const spans = (first, last, start, scale, size) => {
186
+ const out = [];
187
+ for (let at = first; at <= last; at++) {
188
+ let from = Math.ceil((at - start) / scale - 0.5);
189
+ let to = Math.ceil((at + 1 - start) / scale - 0.5) - 1;
190
+ if (to < from) {
191
+ from = Math.floor((at + 0.5 - start) / scale);
192
+ to = from;
193
+ }
194
+ out.push([clamp(from, 0, size - 1), clamp(to, 0, size - 1)]);
195
+ }
196
+ return out;
197
+ };
198
+ const columns = spans(firstColumn, lastColumn, rect.left, across, picture.width);
199
+ const rows = spans(firstRow, lastRow, rect.top, down, picture.height);
200
+ for (const [r, [rowFrom, rowTo]] of rows.entries()) {
201
+ const row = firstRow + r;
202
+ for (const [c, [columnFrom, columnTo]] of columns.entries()) {
203
+ let sum = 0;
204
+ let count = 0;
205
+ for (let y = rowFrom; y <= rowTo; y++) {
206
+ for (let x = columnFrom; x <= columnTo; x++) {
207
+ sum += picture.gray[y * picture.width + x];
208
+ count += 1;
209
+ }
210
+ }
211
+ const at = row * width + firstColumn + c;
212
+ const mean = Math.round(sum / count);
213
+ ink[at] = Math.round((ink[at] * mean) / 255);
214
+ }
215
+ }
216
+ }
217
+ function clamp(value, low, high) {
218
+ return Math.min(Math.max(value, low), high);
219
+ }
@@ -21,9 +21,10 @@ export declare class Work {
21
21
  * the sheet's order; a clearing clears a sheet with strokes, all of them; an undo takes back the
22
22
  * last action still in force and says what the stack says. A history the sheet could not have
23
23
  * written is a TypeError that names the event. The clock is not asked: it goes on as the sheet
24
- * that takes the work tells it (`Clock.resume`).
24
+ * that takes the work tells it (`Clock.resume`). On a task from paper, `paper`, a stroke may
25
+ * be the tracing paper's (R87).
25
26
  */
26
- static restore(value: unknown, clock: Clock): Work;
27
+ static restore(value: unknown, clock: Clock, paper?: boolean): Work;
27
28
  /**
28
29
  * The strokes on the sheet, in the order they were written. Every action gives a new array, and
29
30
  * undoing a clearing gives back the very one it cleared.
@@ -34,6 +35,13 @@ export declare class Work {
34
35
  * button stands unavailable while it is (R28).
35
36
  */
36
37
  get undoable(): boolean;
38
+ /**
39
+ * Whether a stroke of this ID was written on the tracing paper of a task from paper, its points
40
+ * from the paper's corner (R87).
41
+ */
42
+ onTracing(id: number): boolean;
43
+ /** Whether any stroke was written on the tracing paper, erased or not. */
44
+ get traced(): boolean;
37
45
  /**
38
46
  * The history of writing: every action, in the order it landed, frozen through. An array once
39
47
  * handed out never changes: after an action the history is a new one, made when it is next asked
@@ -45,9 +53,9 @@ export declare class Work {
45
53
  * than a longer one, for an array once handed out never changes: a clearing keeps the one it
46
54
  * cleared, and whoever read `strokes` keeps what they read. It lands at the sheet's latest time:
47
55
  * its last point's, unless an action landed while it was under way and it ended without its
48
- * pointerup, its last point earlier.
56
+ * pointerup, its last point earlier. A stroke on the tracing paper says so, `on` (R87).
49
57
  */
50
- write(stroke: Stroke): void;
58
+ write(stroke: Stroke, on?: "tracing"): void;
51
59
  /**
52
60
  * Takes the strokes of these IDs off the sheet, whole, in one action — one press of the eraser.
53
61
  * IDs no longer on the sheet are left out; if none is on it, nothing is done.
@@ -63,9 +71,11 @@ export declare class Work {
63
71
  /**
64
72
  * The strokes on the sheet whose line comes within `reach` of the segment from `from` to `to`, in
65
73
  * sheet units: the index finds those whose box is near enough, and the distance to each segment
66
- * of their points decides (R05). A segment whose ends are one point is that point.
74
+ * of their points decides (R05). A segment whose ends are one point is that point. On a task from
75
+ * paper an erasing takes the strokes of one layer alone, `layer`: the tracing paper's, its
76
+ * points from its corner, or the sheet's (R87).
67
77
  */
68
- near(from: Point, to: Point, reach: number): Stroke[];
78
+ near(from: Point, to: Point, reach: number, layer?: "tracing" | "sheet"): Stroke[];
69
79
  }
70
80
  /** The ID the next stroke takes after a history (R27): one past the highest written, or 1. */
71
81
  export declare function nextIdOf(history: readonly HistoryEvent[]): number;
package/lib/core/work.js CHANGED
@@ -28,6 +28,8 @@ export class Work {
28
28
  #index = new RBush();
29
29
  #indexed = this.#strokes;
30
30
  #entries = new WeakMap();
31
+ /** The IDs of the strokes written on the tracing paper of a task from paper (R87). */
32
+ #tracing = new Set();
31
33
  constructor(clock = new Clock()) {
32
34
  this.#clock = clock;
33
35
  }
@@ -39,13 +41,15 @@ export class Work {
39
41
  * the sheet's order; a clearing clears a sheet with strokes, all of them; an undo takes back the
40
42
  * last action still in force and says what the stack says. A history the sheet could not have
41
43
  * written is a TypeError that names the event. The clock is not asked: it goes on as the sheet
42
- * that takes the work tells it (`Clock.resume`).
44
+ * that takes the work tells it (`Clock.resume`). On a task from paper, `paper`, a stroke may
45
+ * be the tracing paper's (R87).
43
46
  */
44
- static restore(value, clock) {
47
+ static restore(value, clock, paper = false) {
45
48
  const work = new Work(clock);
46
49
  work.#replaying = true;
47
- for (const [n, event] of historyOf(value).entries())
50
+ for (const [n, event] of historyOf(value, paper).entries()) {
48
51
  work.#replay(event, `history[${n}]`);
52
+ }
49
53
  work.#replaying = false;
50
54
  // A new array for the sheet, which the index of the strokes is then built for.
51
55
  work.#strokes = [...work.#strokes];
@@ -65,6 +69,17 @@ export class Work {
65
69
  get undoable() {
66
70
  return this.#done.length > 0;
67
71
  }
72
+ /**
73
+ * Whether a stroke of this ID was written on the tracing paper of a task from paper, its points
74
+ * from the paper's corner (R87).
75
+ */
76
+ onTracing(id) {
77
+ return this.#tracing.has(id);
78
+ }
79
+ /** Whether any stroke was written on the tracing paper, erased or not. */
80
+ get traced() {
81
+ return this.#tracing.size > 0;
82
+ }
68
83
  /**
69
84
  * The history of writing: every action, in the order it landed, frozen through. An array once
70
85
  * handed out never changes: after an action the history is a new one, made when it is next asked
@@ -79,10 +94,10 @@ export class Work {
79
94
  * than a longer one, for an array once handed out never changes: a clearing keeps the one it
80
95
  * cleared, and whoever read `strokes` keeps what they read. It lands at the sheet's latest time:
81
96
  * its last point's, unless an action landed while it was under way and it ended without its
82
- * pointerup, its last point earlier.
97
+ * pointerup, its last point earlier. A stroke on the tracing paper says so, `on` (R87).
83
98
  */
84
- write(stroke) {
85
- this.#write(stroke, Math.max(this.#clock.latest, stroke.points.at(-1)?.t ?? 0));
99
+ write(stroke, on) {
100
+ this.#write(stroke, Math.max(this.#clock.latest, stroke.points.at(-1)?.t ?? 0), on);
86
101
  }
87
102
  /**
88
103
  * Takes the strokes of these IDs off the sheet, whole, in one action — one press of the eraser.
@@ -105,18 +120,22 @@ export class Work {
105
120
  /**
106
121
  * The strokes on the sheet whose line comes within `reach` of the segment from `from` to `to`, in
107
122
  * sheet units: the index finds those whose box is near enough, and the distance to each segment
108
- * of their points decides (R05). A segment whose ends are one point is that point.
123
+ * of their points decides (R05). A segment whose ends are one point is that point. On a task from
124
+ * paper an erasing takes the strokes of one layer alone, `layer`: the tracing paper's, its
125
+ * points from its corner, or the sheet's (R87).
109
126
  */
110
- near(from, to, reach) {
127
+ near(from, to, reach, layer) {
111
128
  const hits = [];
112
129
  for (const { stroke } of this.#indexOf().search(segmentBox(from, to, reach))) {
130
+ if (layer !== undefined && this.#tracing.has(stroke.id) !== (layer === "tracing"))
131
+ continue;
113
132
  if (lineDistance(stroke, from, to) <= reach)
114
133
  hits.push(stroke);
115
134
  }
116
135
  return hits;
117
136
  }
118
137
  // The actions, each with the sheet's time it lands at, asked for only once it does.
119
- #write(stroke, t) {
138
+ #write(stroke, t, on) {
120
139
  // A history replayed writes its strokes one after another, without a copy of the sheet for
121
140
  // each: thousands of strokes would copy the sheet thousands of times. A clearing keeps the array
122
141
  // it cleared and leaves the sheet a new one, so no array an action keeps grows by it.
@@ -125,7 +144,13 @@ export class Work {
125
144
  else
126
145
  this.#strokes = [...this.#strokes, stroke];
127
146
  this.#done.push({ kind: "write", stroke });
128
- this.#record({ kind: "write", t, stroke });
147
+ if (on === undefined) {
148
+ this.#record({ kind: "write", t, stroke });
149
+ }
150
+ else {
151
+ this.#tracing.add(stroke.id);
152
+ this.#record({ kind: "write", t, stroke, on });
153
+ }
129
154
  }
130
155
  #erase(ids, at) {
131
156
  const wanted = new Set(ids);
@@ -188,7 +213,7 @@ export class Work {
188
213
  const at = () => event.t;
189
214
  let done = true;
190
215
  if (event.kind === "write")
191
- this.#write(event.stroke, event.t);
216
+ this.#write(event.stroke, event.t, event.on);
192
217
  else if (event.kind === "erase")
193
218
  done = this.#erase(event.ids, at);
194
219
  else if (event.kind === "clear")
@@ -1,5 +1,13 @@
1
1
  /** The icons of the row's buttons, by their names in the set, as the element draws them. */
2
2
  export declare const ICONS: {
3
+ readonly "article-outline-rounded": {
4
+ readonly viewBox: "0 0 24 24";
5
+ readonly paths: readonly ["M5 21q-.825 0-1.412-.587T3 19V5q0-.825.588-1.412T5 3h14q.825 0 1.413.588T21 5v14q0 .825-.587 1.413T19 21zm0-2h14V5H5zM5 5v14zm3 12h5q.425 0 .713-.288T14 16t-.288-.712T13 15H8q-.425 0-.712.288T7 16t.288.713T8 17m0-4h8q.425 0 .713-.288T17 12t-.288-.712T16 11H8q-.425 0-.712.288T7 12t.288.713T8 13m0-4h8q.425 0 .713-.288T17 8t-.288-.712T16 7H8q-.425 0-.712.288T7 8t.288.713T8 9"];
6
+ };
7
+ readonly "article-rounded": {
8
+ readonly viewBox: "0 0 24 24";
9
+ readonly paths: readonly ["M5 21q-.825 0-1.412-.587T3 19V5q0-.825.588-1.412T5 3h14q.825 0 1.413.588T21 5v14q0 .825-.587 1.413T19 21zm3-4h5q.425 0 .713-.288T14 16t-.288-.712T13 15H8q-.425 0-.712.288T7 16t.288.713T8 17m0-4h8q.425 0 .713-.288T17 12t-.288-.712T16 11H8q-.425 0-.712.288T7 12t.288.713T8 13m0-4h8q.425 0 .713-.288T17 8t-.288-.712T16 7H8q-.425 0-.712.288T7 8t.288.713T8 9"];
10
+ };
3
11
  readonly "arrow-forward-outline-rounded": {
4
12
  readonly viewBox: "0 0 24 24";
5
13
  readonly paths: readonly ["M16.175 13H5q-.425 0-.712-.288T4 12t.288-.712T5 11h11.175l-4.9-4.9q-.3-.3-.288-.7t.313-.7q.3-.275.7-.288t.7.288l6.6 6.6q.15.15.213.325t.062.375t-.062.375t-.213.325l-6.6 6.6q-.275.275-.687.275T11.3 19.3q-.3-.3-.3-.712t.3-.713z"];
@@ -57,6 +65,11 @@ export type IconName = keyof typeof ICONS;
57
65
  * runs right to left (R78 spec).
58
66
  */
59
67
  export declare const ROW: {
68
+ readonly task: {
69
+ readonly outline: "article-outline-rounded";
70
+ readonly filled: "article-rounded";
71
+ readonly mirrored: false;
72
+ };
60
73
  readonly next: {
61
74
  readonly outline: "arrow-forward-outline-rounded";
62
75
  readonly filled: "arrow-forward-outline-rounded";
@@ -4,6 +4,18 @@
4
4
  // no entry point of the package.
5
5
  /** The icons of the row's buttons, by their names in the set, as the element draws them. */
6
6
  export const ICONS = {
7
+ "article-outline-rounded": {
8
+ viewBox: "0 0 24 24",
9
+ paths: [
10
+ "M5 21q-.825 0-1.412-.587T3 19V5q0-.825.588-1.412T5 3h14q.825 0 1.413.588T21 5v14q0 .825-.587 1.413T19 21zm0-2h14V5H5zM5 5v14zm3 12h5q.425 0 .713-.288T14 16t-.288-.712T13 15H8q-.425 0-.712.288T7 16t.288.713T8 17m0-4h8q.425 0 .713-.288T17 12t-.288-.712T16 11H8q-.425 0-.712.288T7 12t.288.713T8 13m0-4h8q.425 0 .713-.288T17 8t-.288-.712T16 7H8q-.425 0-.712.288T7 8t.288.713T8 9",
11
+ ],
12
+ },
13
+ "article-rounded": {
14
+ viewBox: "0 0 24 24",
15
+ paths: [
16
+ "M5 21q-.825 0-1.412-.587T3 19V5q0-.825.588-1.412T5 3h14q.825 0 1.413.588T21 5v14q0 .825-.587 1.413T19 21zm3-4h5q.425 0 .713-.288T14 16t-.288-.712T13 15H8q-.425 0-.712.288T7 16t.288.713T8 17m0-4h8q.425 0 .713-.288T17 12t-.288-.712T16 11H8q-.425 0-.712.288T7 12t.288.713T8 13m0-4h8q.425 0 .713-.288T17 8t-.288-.712T16 7H8q-.425 0-.712.288T7 8t.288.713T8 9",
17
+ ],
18
+ },
7
19
  "arrow-forward-outline-rounded": {
8
20
  viewBox: "0 0 24 24",
9
21
  paths: [
@@ -83,6 +95,7 @@ export const ICONS = {
83
95
  * runs right to left (R78 spec).
84
96
  */
85
97
  export const ROW = {
98
+ task: { outline: "article-outline-rounded", filled: "article-rounded", mirrored: false },
86
99
  next: {
87
100
  outline: "arrow-forward-outline-rounded",
88
101
  filled: "arrow-forward-outline-rounded",
@@ -1,4 +1,4 @@
1
- import type { CanvasElement, CanvasEventMap, ExportedWork, Media } from "@altnovatrail/spec/canvas";
1
+ import type { CanvasElement, CanvasEventMap, ExportedWork, Media, PaperTask, TracingState } from "@altnovatrail/spec/canvas";
2
2
  import { type Filled } from "../core/boxes.js";
3
3
  import { type DemoState, type WorkedExample } from "../core/example.js";
4
4
  import { type HistoryEvent } from "../core/history.js";
@@ -13,7 +13,7 @@ import { type Task, type Tool } from "../core/task.js";
13
13
  * media and the tutor's marks too. The crop and a task with its temporary tools are the element's
14
14
  * own (R26, R41).
15
15
  */
16
- export type { Box, CanvasElement, CanvasEventMap, DemoChangeEvent, ExportedCell, ExportedSheet, ExportedWork, ExportedWorkbook, HistoryChange, HistoryChangeEvent, Media, ToolChange, ToolChangeEvent, } from "@altnovatrail/spec/canvas";
16
+ export type { Box, CanvasElement, CanvasEventMap, DemoChangeEvent, ExportedCell, ExportedPaper, ExportedSheet, ExportedWork, ExportedWorkbook, HistoryChange, HistoryChangeEvent, Media, PaperTask, ToolChange, ToolChangeEvent, TracingChangeEvent, TracingState, } from "@altnovatrail/spec/canvas";
17
17
  export type { Filled, Filling } from "../core/boxes.js";
18
18
  export type { Crop, Frame } from "../core/crop.js";
19
19
  export type { DemoState, WorkedExample } from "../core/example.js";
@@ -22,7 +22,7 @@ export type { Group } from "../core/groups.js";
22
22
  export type { HistoryEvent } from "../core/history.js";
23
23
  export type { InkPoint, Stroke } from "../core/ink.js";
24
24
  export type { Manifest } from "../core/manifest.js";
25
- export type { Anchor, CellPlace, CropNumbers, Mark, Marks, SheetSubmission, Submission, WorkbookSubmission, } from "../core/marks.js";
25
+ export type { Anchor, CellPlace, CropNumbers, Mark, Marks, PaperSubmission, SheetSubmission, Submission, WorkbookSubmission, } from "../core/marks.js";
26
26
  export type { Canvas, Task, Tool } from "../core/task.js";
27
27
  /** The name the element is registered under. */
28
28
  export declare const TAG = "novatrail-canvas";
@@ -84,6 +84,32 @@ export declare class NovatrailCanvas extends HTMLElement implements CanvasElemen
84
84
  */
85
85
  get workedExample(): WorkedExample | undefined;
86
86
  set workedExample(example: WorkedExample | undefined);
87
+ /**
88
+ * A task from the learner's paper (R87; R162 spec): `statement`, the task's crop as app cut it, a
89
+ * Blob of a JPEG or a PNG. The element shows it in place of a task and of a worked example: a
90
+ * dotted sheet with no statement, the pen and the eraser, and the crop over it as tracing paper,
91
+ * at the element's own place for it, shown, which `tracing` tells. While a task or an example is
92
+ * shown it is a TypeError, and so is what is not such a task. Another task from paper, of
93
+ * another crop, lays its crop at the start again, and the history stays: the next task is a new
94
+ * element (R20); one of the same crop changes nothing. `undefined` takes it off, but not while the
95
+ * history has strokes on the tracing paper, a TypeError. Either drops a stroke or an erasing under
96
+ * way on the tracing paper, as a new history drops the one under the pen. The crop's picture is
97
+ * read as it comes; till then the paper has its largest size.
98
+ */
99
+ get paper(): PaperTask | undefined;
100
+ set paper(paper: PaperTask | undefined);
101
+ /**
102
+ * Where the tracing paper of the task from paper lies on the sheet, its top left corner in sheet
103
+ * units, and whether it is hidden (R87): frozen, and the same object until it changes;
104
+ * `undefined` without a task from paper. The learner moves it by its grip and hides or shows it by
105
+ * the button atop the tools, which a `tracingchange` tells; the consumer keeps it and gives it
106
+ * back, which tells nothing. Given before the task from paper it is a TypeError, and so is a state
107
+ * that is not one, or one that puts the paper wholly off the sheet; `undefined` changes nothing.
108
+ * Till the crop's picture is read the paper has its largest size: a state that puts the paper of
109
+ * its real size wholly off the sheet then moves to the nearest place wholly on it, with no event.
110
+ */
111
+ get tracing(): TracingState | undefined;
112
+ set tracing(state: TracingState | undefined);
87
113
  /**
88
114
  * How far the learner has gone through the worked example's demo (R42): `opened`, how many of
89
115
  * its parts are open, from the first, and `hidden`, whether the whole demo is hidden — frozen,
@@ -219,7 +245,9 @@ export declare class NovatrailCanvas extends HTMLElement implements CanvasElemen
219
245
  * unit, 1000 × 1400, whatever is filled and whether the work was sent to be checked or not; an
220
246
  * empty surface, and a worked example's, is white. The strokes are those `exportWork()` takes, as
221
247
  * the history has them: not the stroke under way, but those under an eraser not yet lifted. Each
222
- * is the outline the screen fills, black on white with no theme and no template, and the pixels
248
+ * is the outline the screen fills, black on white with no theme and no template — on a task from
249
+ * paper the strokes of both layers, the tracing paper's where it lies, hidden or not, with the
250
+ * crop's picture laid in grey and multiplied (R87) —, and the pixels
223
251
  * go through the crop's encoder, grey a byte each: so the picture looks as the sheet does, and
224
252
  * holds at most 1,576,640 bytes, for the encoder spends at most 9 bits on a byte of a row, under
225
253
  * the 4 MiB of a stored work.