@altnovatrail/spec 0.19.15 → 0.19.16

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/canvas/index.d.ts CHANGED
@@ -96,6 +96,58 @@ export interface GridChange {
96
96
  */
97
97
  export type GridChangeEvent = CustomEvent<GridChange>;
98
98
 
99
+ /**
100
+ * The kind of pen a stroke is written with, which the learner picks in the pen's popover: "pen",
101
+ * whose line is drawn wider and finer by a pen's pressure, or without one by the speed of the
102
+ * pointer, and a little finer at its ends; "liner", one width all along; and "marker", one width,
103
+ * multiplied with what lies under it.
104
+ */
105
+ export type PenKind = "pen" | "liner" | "marker";
106
+
107
+ /**
108
+ * How a stroke looks: its kind of pen, its colour, its width and its opacity, as the learner chose
109
+ * them before it was written. A stroke keeps its style: a new choice changes the strokes after it.
110
+ */
111
+ export interface StrokeStyle {
112
+ readonly pen: PenKind;
113
+ /** Any colour of sRGB, `#rrggbb` in lowercase hexadecimal digits, the palette's or another. */
114
+ readonly color: string;
115
+ /**
116
+ * The width of its line, in the sheet's units to a tenth, from 0.1 to 50 — on the tracing paper in its
117
+ * units, so that it scales with it. A pen of the kind "pen" draws it as the middle of what its
118
+ * pressure or its speed makes of it; a crop for checking draws every stroke at its width.
119
+ */
120
+ readonly width: number;
121
+ /** Its opacity, in whole percent from 10 to 100: the stroke is laid as one layer, at it. */
122
+ readonly opacity: number;
123
+ }
124
+
125
+ /**
126
+ * What the eraser takes off: "stroke", every stroke it touches, whole; "part", only what it passes
127
+ * over, cutting the strokes it crosses into pieces.
128
+ */
129
+ export type EraserMode = "stroke" | "part";
130
+
131
+ /**
132
+ * The learner's settings of the pen and the eraser: the kind of pen in use, each kind's own style,
133
+ * which its next stroke takes, and the eraser's mode and size. An element starts with canvas's.
134
+ */
135
+ export interface PenSettings {
136
+ readonly pen: PenKind;
137
+ /** Each kind's style, its `pen` that kind. */
138
+ readonly styles: { readonly pen: StrokeStyle; readonly liner: StrokeStyle; readonly marker: StrokeStyle };
139
+ readonly eraser: EraserMode;
140
+ /** The eraser's diameter, in the sheet's units, from 1 to 200. */
141
+ readonly eraserSize: number;
142
+ }
143
+
144
+ /**
145
+ * The event the element sends from its host, bubbling and composed, when the learner changes a
146
+ * setting in the popover of the pen or of the eraser, opened by a second press of the chosen tool —
147
+ * not when the consumer sets `pens`. Its detail is the new settings, frozen.
148
+ */
149
+ export type PenChangeEvent = CustomEvent<PenSettings>;
150
+
99
151
  /**
100
152
  * Where the tracing paper of a task from paper lies on the sheet, how large, and whether it is
101
153
  * hidden. A new task from paper starts at the element's own place for it, shown, at its own size.
@@ -158,26 +210,51 @@ export interface InkPoint {
158
210
  readonly y: number;
159
211
  /** Milliseconds since the sheet's first event: the time of a sample has no date. */
160
212
  readonly t: number;
161
- /** The pressure, 0 to 1, as the pointer reported it. */
213
+ /**
214
+ * The pressure, 0 to 1, as the pointer reported it, and never one the element made up: the width
215
+ * of a pen's line without a pen's pressure comes from its speed, by the times of its points.
216
+ */
162
217
  readonly p: number;
163
218
  }
164
219
 
165
- /** A stroke: one press of a pointer, from going down to coming up. */
220
+ /**
221
+ * A stroke: one press of a pointer, from going down to coming up, or a piece of one that the
222
+ * eraser cut.
223
+ */
166
224
  export interface Stroke {
167
225
  /**
168
- * The stroke's ID on its sheet: 1, 2, … in the order the strokes began, never reused within one
169
- * history. A sheet given another history numbers on from that history's highest ID.
226
+ * The stroke's ID on its sheet: 1, 2, … in the order the strokes began, a piece when the eraser
227
+ * that cut it lifted, never reused within one history. A sheet given another history numbers on
228
+ * from that history's highest ID.
170
229
  */
171
230
  readonly id: number;
172
231
  /**
173
232
  * The pointer's type as the browser reported it — "pen", "touch", "mouse" or whatever else it
174
- * says. Only a pen's pressure changes the width of the line.
233
+ * says. Only a pen's pressure changes the width of the line, and only of a pen of the kind "pen".
175
234
  */
176
235
  readonly kind: string;
236
+ /**
237
+ * How it looks. The element gives every stroke it writes one; a stroke of a history written
238
+ * before strokes had a style has none, and is drawn as the pen then drew: of the kind "pen",
239
+ * black and opaque.
240
+ */
241
+ readonly style?: StrokeStyle;
177
242
  /** The points in the order they were written, the first where the pointer went down. */
178
243
  readonly points: readonly InkPoint[];
179
244
  }
180
245
 
246
+ /**
247
+ * A piece of a stroke that the eraser cut, a stroke of its own: the ID of the stroke it was cut of,
248
+ * and the piece, with that stroke's pointer and style. Its points are a run of that stroke's, with
249
+ * one point of its own at most at each end, where the eraser's edge crossed the stroke, its place
250
+ * and its time and pressure between those of its neighbours. A piece of a stroke on the tracing
251
+ * paper is on the tracing paper too.
252
+ */
253
+ export interface Piece {
254
+ readonly of: number;
255
+ readonly stroke: Stroke;
256
+ }
257
+
181
258
  /**
182
259
  * An event of the history of writing: what an action on the sheet did, at the sheet's time `t`
183
260
  * when it landed, in the order the actions landed — so `t` never goes back along a history. Each
@@ -196,13 +273,28 @@ export type HistoryEvent =
196
273
  * no `on`.
197
274
  */
198
275
  | { readonly kind: "write"; readonly t: number; readonly stroke: Stroke; readonly on?: "tracing" }
199
- /** One press of the eraser: the strokes it took off, in the sheet's order, when it lifted. */
276
+ /**
277
+ * One press of the eraser that takes strokes whole: the strokes it took off, in the sheet's
278
+ * order, when it lifted.
279
+ */
200
280
  | { readonly kind: "erase"; readonly t: number; readonly ids: readonly number[] }
281
+ /**
282
+ * One press of the eraser that takes a part: the strokes it crossed, in the sheet's order, which
283
+ * it took off, and the pieces of them it left, in the order of `ids` and along each stroke, new
284
+ * strokes on the sheet, when it lifted. A stroke it covered whole leaves no piece.
285
+ */
286
+ | {
287
+ readonly kind: "cut";
288
+ readonly t: number;
289
+ readonly ids: readonly number[];
290
+ readonly pieces: readonly Piece[];
291
+ }
201
292
  /** The sheet cleared: every stroke that was on it, in the sheet's order. */
202
293
  | { readonly kind: "clear"; readonly t: number; readonly ids: readonly number[] }
203
294
  /**
204
295
  * The last action still in force taken back: the stroke it took off, if it was a writing, or the
205
- * strokes it brought back, if it was an erasing or a clearing.
296
+ * strokes it brought back, if it was an erasing or a clearing — and of a cut, the pieces it took
297
+ * off too.
206
298
  */
207
299
  | {
208
300
  readonly kind: "undo";
@@ -223,7 +315,7 @@ export interface HistoryChange {
223
315
 
224
316
  /**
225
317
  * The event the element sends from its host, bubbling and composed, at once after every action on
226
- * the sheet: a stroke, an erasing, a clearing and an undo. Its detail is frozen. Setting `history`
318
+ * the sheet: a stroke, an erasing, a cut, a clearing and an undo. Its detail is frozen. Setting `history`
227
319
  * sends none.
228
320
  */
229
321
  export type HistoryChangeEvent = CustomEvent<HistoryChange>;
@@ -483,6 +575,7 @@ export interface CanvasEventMap {
483
575
  tracingchange: TracingChangeEvent;
484
576
  tracingread: TracingReadEvent;
485
577
  gridchange: GridChangeEvent;
578
+ penchange: PenChangeEvent;
486
579
  }
487
580
 
488
581
  /**
@@ -552,6 +645,15 @@ export interface CanvasElement extends HTMLElement {
552
645
  */
553
646
  get grid(): PaperGrid | undefined;
554
647
  set grid(grid: PaperGrid | undefined);
648
+ /**
649
+ * The settings of the pen and the eraser, frozen: canvas's as an element comes. The learner
650
+ * changes them in the popovers of the pen and the eraser, which a `penchange` tells; the consumer
651
+ * keeps them and gives them back to the next element, which tells nothing. Settings not of
652
+ * `PenSettings` — a style whose `pen` is not its kind's, a colour, a width, an opacity or a size
653
+ * out of its bounds — are a TypeError; `undefined` changes nothing.
654
+ */
655
+ get pens(): PenSettings;
656
+ set pens(settings: PenSettings | undefined);
555
657
  /**
556
658
  * The open view of a lesson's worked example, its segment `worked_example`, in place of a task;
557
659
  * its module's manifest is `manifest`, as a task's is. The element shows the example's statement
@@ -588,7 +690,7 @@ export interface CanvasElement extends HTMLElement {
588
690
  */
589
691
  media: Media | undefined;
590
692
  /**
591
- * The history of writing: every stroke, erasing, clearing and undo on the sheet, frozen. The
693
+ * The history of writing: every stroke, erasing, cut, clearing and undo on the sheet, frozen. The
592
694
  * consumer keeps it, adding what `historychange` tells, and gives it back to open the sheet as it
593
695
  * was. A history the sheet could not have written is a TypeError, and the sheet stays as it was;
594
696
  * `undefined` is the empty one.
@@ -598,7 +700,7 @@ export interface CanvasElement extends HTMLElement {
598
700
  /**
599
701
  * The tutor's marks of one submission, on the tutor's layer, given after the task and the
600
702
  * history they hold on to. A mark holds on to the strokes the model saw at its place and is drawn
601
- * around those of them the sheet shows, as they are now: a box on the crop takes the strokes by
703
+ * around those of them the sheet shows, and the pieces the eraser has cut of them, as they are now: a box on the crop takes the strokes by
602
704
  * the rule of snapping of `contracts/README.md`, and a cell of a workbook is framed with
603
705
  * its box — round the box alone when the box was empty. A cell on a sheet, and a box that comes
604
706
  * near no stroke, have no frame: the question is asked without one. A submission goes back to the
@@ -631,8 +733,8 @@ export interface CanvasElement extends HTMLElement {
631
733
  * The picture of the work, which app puts as the stored work's `picture` in the contract between
632
734
  * app and api: always a Blob of a PNG, with no condition, of the strokes the surface shows as it is
633
735
  * when it is called — the page, a sheet's or a workbook's, and the ink past it, right and down, with
634
- * the tracing paper of a task from paper where it lies —, within the limit of a stored work there.
635
- * Its size, in its PNG's header, and its colours are canvas's.
736
+ * the tracing paper of a task from paper where it lies —, each stroke in its style, within the limit
737
+ * of a stored work there. Its size, in its PNG's header, is canvas's.
636
738
  */
637
739
  exportPicture(): Promise<Blob>;
638
740
  }
@@ -317,8 +317,8 @@ export interface DeviceAttempt {
317
317
  */
318
318
  readonly attempt_id: ID;
319
319
  /**
320
- * The history of writing as the canvas gave it: write/erase/clear/undo events with t; strokes
321
- * with id, kind and points x, y, t, p.
320
+ * The history of writing as the canvas gave it: write/erase/cut/clear/undo events with t, a cut
321
+ * with the pieces it left; strokes with id, kind, style and points x, y, t, p.
322
322
  */
323
323
  readonly history: unknown;
324
324
  /**
@@ -550,8 +550,8 @@ export interface Task {
550
550
  readonly statement: Image;
551
551
  /**
552
552
  * The history of writing as the canvas gave it, the strokes of the sheet and of the tracing
553
- * paper: write/erase/clear/undo events with t; strokes with id, kind and points x, y, t, p; on a
554
- * stroke of the tracing paper, on "tracing".
553
+ * paper: write/erase/cut/clear/undo events with t, a cut with the pieces it left; strokes with
554
+ * id, kind, style and points x, y, t, p; on a stroke of the tracing paper, on "tracing".
555
555
  */
556
556
  readonly history: unknown;
557
557
  /**
@@ -1645,7 +1645,8 @@ export interface Work {
1645
1645
  readonly stored_at: Time;
1646
1646
  /**
1647
1647
  * The history of writing as the canvas gave it, the JSON array its bytes hold, not their base64:
1648
- * write/erase/clear/undo events with t; strokes with id, kind and points x, y, t, p.
1648
+ * write/erase/cut/clear/undo events with t, a cut with the pieces it left; strokes with id, kind,
1649
+ * style and points x, y, t, p.
1649
1650
  */
1650
1651
  readonly history: unknown;
1651
1652
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altnovatrail/spec",
3
- "version": "0.19.15",
3
+ "version": "0.19.16",
4
4
  "description": "The types of NovaTrail's module format for TypeScript, generated from its schemas: the parts of a module and their open views, the canonical view, the inventory, the module index and the test vectors. And the types of the element <novatrail-canvas>, the contract of the canvas and the app. And the types of the admission table, which says which AI provider may serve which age category. And the numbers and widths of the workbook's page and its test vectors, as JSON, by which a canvas lays the page out. And the types of the deployment configuration, the file /deployment.json that the app reads at its start. And the types of the legal texts' passport, which names each text, its versions and the sets of texts of the samples page. And the types of the table of the age of digital consent, which gives each country's age with the law that sets it. And the types of the files of an export, the file the owner of an account gets of a profile or of the account.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {