@altnovatrail/canvas 0.3.42 → 0.3.43
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/crop.d.ts +17 -2
- package/lib/core/crop.js +45 -17
- package/lib/core/cut.d.ts +46 -0
- package/lib/core/cut.js +297 -0
- package/lib/core/eraser.d.ts +27 -9
- package/lib/core/eraser.js +32 -10
- package/lib/core/history.d.ts +21 -15
- package/lib/core/history.js +234 -28
- package/lib/core/index.d.ts +2 -1
- package/lib/core/index.js +3 -2
- package/lib/core/outline.d.ts +13 -3
- package/lib/core/outline.js +110 -11
- package/lib/core/png.d.ts +4 -3
- package/lib/core/png.js +15 -10
- package/lib/core/raster.d.ts +20 -9
- package/lib/core/raster.js +121 -35
- package/lib/core/recorder.d.ts +13 -2
- package/lib/core/recorder.js +20 -4
- package/lib/core/sheet.d.ts +3 -2
- package/lib/core/sheet.js +6 -4
- package/lib/core/style.d.ts +54 -0
- package/lib/core/style.js +146 -0
- package/lib/core/submission.js +4 -3
- package/lib/core/tracing.d.ts +6 -4
- package/lib/core/tracing.js +15 -7
- package/lib/core/work.d.ts +40 -11
- package/lib/core/work.js +106 -15
- package/lib/element/index.d.ts +37 -15
- package/lib/element/index.js +412 -70
- package/lib/element/labels.d.ts +42 -0
- package/lib/element/labels.js +73 -3
- package/lib/element/pens.d.ts +55 -0
- package/lib/element/pens.js +676 -0
- package/lib/element/tools.d.ts +9 -0
- package/lib/element/tools.js +77 -9
- package/package.json +3 -3
package/lib/element/tools.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PaperGrid } from "@altnovatrail/spec/canvas";
|
|
2
|
+
import { type PenSettings } from "../core/style.js";
|
|
2
3
|
import type { Tool } from "../core/task.js";
|
|
3
4
|
import { ROW } from "./icons.js";
|
|
5
|
+
import { Pens } from "./pens.js";
|
|
4
6
|
/** A value of the bar, by its button's key: what its icon shows (icons.ts). */
|
|
5
7
|
export type Value = keyof typeof ROW;
|
|
6
8
|
/**
|
|
@@ -19,6 +21,8 @@ export interface ToolActions {
|
|
|
19
21
|
readonly toggle: () => void;
|
|
20
22
|
/** A task from paper's tracing paper hidden, or shown again. */
|
|
21
23
|
readonly trace: () => void;
|
|
24
|
+
/** The settings of the pen and the eraser as the learner made them in a popover. */
|
|
25
|
+
readonly pens: (settings: PenSettings) => void;
|
|
22
26
|
}
|
|
23
27
|
/** What Next and Demo control, by their IDs in the element's shadow root. */
|
|
24
28
|
export interface DemoControls {
|
|
@@ -50,6 +54,9 @@ export interface ToolState {
|
|
|
50
54
|
/** On a task from paper, whether its tracing paper is shown, and its sheet's grid. */
|
|
51
55
|
readonly traced: boolean;
|
|
52
56
|
readonly grid: PaperGrid;
|
|
57
|
+
/** The settings of the pen and the eraser, and whether the strokes take them, and the popovers. */
|
|
58
|
+
readonly pens: PenSettings;
|
|
59
|
+
readonly styled: boolean;
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
55
62
|
* How long a tooltip stays after the pointer leaves its button, in milliseconds: long enough for
|
|
@@ -71,6 +78,8 @@ export declare class Tools {
|
|
|
71
78
|
readonly row: HTMLDivElement;
|
|
72
79
|
/** The tooltip of the button the pointer is over, or the keyboard's focus is on. */
|
|
73
80
|
readonly tip: HTMLDivElement;
|
|
81
|
+
/** The popovers of the pen and of the eraser, beside the bar. */
|
|
82
|
+
readonly pens: Pens;
|
|
74
83
|
constructor(actions: ToolActions, controls: DemoControls);
|
|
75
84
|
/**
|
|
76
85
|
* The bar as the sheet now is. Only what has changed is written. A worked example has no bar, for
|
package/lib/element/tools.js
CHANGED
|
@@ -25,10 +25,17 @@
|
|
|
25
25
|
// toggle button as well, which would say it twice —, and one last, after a line:
|
|
26
26
|
// the sheet's grid, its icon and its name the grid shown now, which a press turns to the next,
|
|
27
27
|
// round — dots, lines, blank, squares. A button that goes gives its stop of Tab and the focus
|
|
28
|
-
// to the first button shown.
|
|
28
|
+
// to the first button shown. The chosen pen and the chosen eraser open their popovers by a second
|
|
29
|
+
// press, Enter or Space from the keyboard (pens.ts), which their description says, unless the
|
|
30
|
+
// element writes without styles; the pen shows a dot of its colour, and each of them a mark in its
|
|
31
|
+
// corner while chosen. A press of any other button closes the popover, and so does the choice of
|
|
32
|
+
// another tool; its button's tooltip gives way to it. This module is no entry point of the
|
|
33
|
+
// package.
|
|
34
|
+
import { PALETTE } from "../core/style.js";
|
|
29
35
|
import { SVG, write } from "./attributes.js";
|
|
30
36
|
import { ICONS, ROW } from "./icons.js";
|
|
31
37
|
import { labelsFor } from "./labels.js";
|
|
38
|
+
import { HINT_ID, Pens } from "./pens.js";
|
|
32
39
|
/** The value of the grid's button, and the key of its label, by the grid shown. */
|
|
33
40
|
const GRID_VALUES = {
|
|
34
41
|
dots: "gridDots",
|
|
@@ -75,6 +82,8 @@ export class Tools {
|
|
|
75
82
|
/** A task from paper's grid, after a line. */
|
|
76
83
|
#beforeGrid = separator();
|
|
77
84
|
#grid = plainButton("gridDots");
|
|
85
|
+
/** The popovers of the pen and of the eraser, beside the bar. */
|
|
86
|
+
pens;
|
|
78
87
|
/**
|
|
79
88
|
* The buttons with the keys of their labels, the row's and then the bar's in the order the arrow
|
|
80
89
|
* keys go through them. A button is named only by its label, so each is here with its key.
|
|
@@ -107,6 +116,10 @@ export class Tools {
|
|
|
107
116
|
#traced = true;
|
|
108
117
|
/** A task from paper's grid: its button's icon and name say which. */
|
|
109
118
|
#gridShown = "dots";
|
|
119
|
+
/** The tool in use, whether the bar is one to write with, and with the popovers. */
|
|
120
|
+
#tool = "pen";
|
|
121
|
+
#writes = true;
|
|
122
|
+
#styled = true;
|
|
110
123
|
/** Whether a button of the bar has had the focus: Tab comes to the first button until one has. */
|
|
111
124
|
#chosen = false;
|
|
112
125
|
/** The button the pointer is over, the one the keyboard's focus is on, and the tooltip's. */
|
|
@@ -161,7 +174,8 @@ export class Tools {
|
|
|
161
174
|
this.#group.setAttribute("role", "radiogroup");
|
|
162
175
|
this.#group.append(this.#pen, this.#eraser, this.#hand);
|
|
163
176
|
this.element.append(this.#task, this.#afterTask, this.#group, this.#undo, this.#clear, this.#beforeZoom, this.#zoomIn, this.#zoomOut, this.#beforeGrid, this.#grid);
|
|
164
|
-
this.
|
|
177
|
+
this.pens = new Pens(actions.pens, () => this.#showTip());
|
|
178
|
+
this.rail.append(this.element, this.row, this.tip, this.pens.pen, this.pens.eraser, this.pens.hint);
|
|
165
179
|
for (const button of this.#buttons)
|
|
166
180
|
button.classList.add("icon");
|
|
167
181
|
// A worked example's row and a task from paper's buttons come with what they are for.
|
|
@@ -178,10 +192,27 @@ export class Tools {
|
|
|
178
192
|
}
|
|
179
193
|
// Tab comes to the first button shown, until another has had the focus.
|
|
180
194
|
this.#stopAt(this.#first());
|
|
181
|
-
// The element decides whether a choice is a change: the tool in use, chosen again, is none
|
|
182
|
-
|
|
183
|
-
|
|
195
|
+
// The element decides whether a choice is a change: the tool in use, chosen again, is none,
|
|
196
|
+
// but for the pen's and the eraser's popovers. A click from the keyboard has no detail.
|
|
197
|
+
const press = (tool, button, event) => {
|
|
198
|
+
if (this.#tool !== tool || !this.#styled || !this.#writes) {
|
|
199
|
+
actions.choose(tool);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.pens.opened === tool)
|
|
203
|
+
this.pens.close();
|
|
204
|
+
else
|
|
205
|
+
this.pens.open(tool, button, event.detail === 0);
|
|
206
|
+
};
|
|
207
|
+
this.#pen.addEventListener("click", (event) => press("pen", this.#pen, event));
|
|
208
|
+
this.#eraser.addEventListener("click", (event) => press("eraser", this.#eraser, event));
|
|
184
209
|
this.#hand.addEventListener("click", () => actions.choose("hand"));
|
|
210
|
+
// A press of any other button of the bar closes a popover.
|
|
211
|
+
this.element.addEventListener("click", (event) => {
|
|
212
|
+
const button = event.target instanceof Element ? event.target.closest("button") : null;
|
|
213
|
+
if (button !== this.#pen && button !== this.#eraser)
|
|
214
|
+
this.pens.close();
|
|
215
|
+
});
|
|
185
216
|
const doing = (button, act) => {
|
|
186
217
|
// aria-disabled stops no click: the button does nothing while it stands unavailable.
|
|
187
218
|
button.addEventListener("click", () => {
|
|
@@ -214,8 +245,11 @@ export class Tools {
|
|
|
214
245
|
if (event.target instanceof Element)
|
|
215
246
|
bringIn(this.row, event.target);
|
|
216
247
|
});
|
|
217
|
-
// A tooltip
|
|
218
|
-
this.element.addEventListener("scroll", () =>
|
|
248
|
+
// A tooltip and a popover stand by their button as the bar scrolls under it.
|
|
249
|
+
this.element.addEventListener("scroll", () => {
|
|
250
|
+
this.#placeTip();
|
|
251
|
+
this.pens.place();
|
|
252
|
+
});
|
|
219
253
|
this.element.addEventListener("focusout", () => {
|
|
220
254
|
this.#focused = undefined;
|
|
221
255
|
this.#showTip();
|
|
@@ -241,7 +275,7 @@ export class Tools {
|
|
|
241
275
|
* and fills its icon while the paper is shown, and its grid's button shows the grid.
|
|
242
276
|
*/
|
|
243
277
|
show(state) {
|
|
244
|
-
const { kind, tools, tool, undoable, clearable, larger, smaller, opens, expanded, traced, grid, } = state;
|
|
278
|
+
const { kind, tools, tool, undoable, clearable, larger, smaller, opens, expanded, traced, grid, pens, styled, } = state;
|
|
245
279
|
if (kind !== this.#kind) {
|
|
246
280
|
this.#kind = kind;
|
|
247
281
|
this.#name();
|
|
@@ -284,6 +318,7 @@ export class Tools {
|
|
|
284
318
|
this.#gridShown = grid;
|
|
285
319
|
this.#nameGrid();
|
|
286
320
|
}
|
|
321
|
+
this.#settings(tool, writes, styled, pens);
|
|
287
322
|
draw(this.#demo, expanded ? "demoShown" : "demoHidden", false);
|
|
288
323
|
draw(this.#task, "task", traced);
|
|
289
324
|
if (traced !== this.#traced) {
|
|
@@ -312,11 +347,41 @@ export class Tools {
|
|
|
312
347
|
}
|
|
313
348
|
this.#nameTask();
|
|
314
349
|
this.#nameGrid();
|
|
350
|
+
this.pens.label(tag);
|
|
315
351
|
this.#tipFor = undefined;
|
|
316
352
|
this.#showTip();
|
|
317
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* The chosen pen and eraser as the settings are: described by the hint of a second press, marked
|
|
356
|
+
* in the corner, and the pen's dot of its colour, while the strokes take a style. A popover of a
|
|
357
|
+
* tool no longer in use, or of a bar without styles, closes.
|
|
358
|
+
*/
|
|
359
|
+
#settings(tool, writes, styled, pens) {
|
|
360
|
+
this.#tool = tool;
|
|
361
|
+
this.#writes = writes;
|
|
362
|
+
this.#styled = styled;
|
|
363
|
+
const opens = writes && styled;
|
|
364
|
+
for (const [button, value] of [
|
|
365
|
+
[this.#pen, "pen"],
|
|
366
|
+
[this.#eraser, "eraser"],
|
|
367
|
+
]) {
|
|
368
|
+
button.classList.toggle("settings", opens);
|
|
369
|
+
write(button, "aria-describedby", opens && tool === value ? HINT_ID : null);
|
|
370
|
+
}
|
|
371
|
+
this.#pen.classList.toggle("dotted", opens);
|
|
372
|
+
const { color } = pens.styles[pens.pen];
|
|
373
|
+
// The palette's black is the theme's ink, as the sheet draws it.
|
|
374
|
+
if (color === PALETTE[0])
|
|
375
|
+
this.#pen.style.removeProperty("--pen-dot");
|
|
376
|
+
else
|
|
377
|
+
this.#pen.style.setProperty("--pen-dot", color);
|
|
378
|
+
this.pens.show(pens);
|
|
379
|
+
if (!opens || (this.pens.opened !== undefined && this.pens.opened !== tool))
|
|
380
|
+
this.pens.close();
|
|
381
|
+
}
|
|
318
382
|
/** The element left the page: a tooltip goes with it, and Escape is no longer heard. */
|
|
319
383
|
disconnect() {
|
|
384
|
+
this.pens.close();
|
|
320
385
|
clearTimeout(this.#grace);
|
|
321
386
|
this.#hovered = undefined;
|
|
322
387
|
this.#focused = undefined;
|
|
@@ -389,7 +454,10 @@ export class Tools {
|
|
|
389
454
|
#showTip() {
|
|
390
455
|
// A button the pointer was over may have gone with no pointerleave: the focus's has its
|
|
391
456
|
// tooltip.
|
|
392
|
-
|
|
457
|
+
// An open popover stands where the tooltip would.
|
|
458
|
+
const wanted = this.pens?.opened === undefined
|
|
459
|
+
? [this.#hovered, this.#focused].find((button) => button && !button.hidden)
|
|
460
|
+
: undefined;
|
|
393
461
|
if (this.#dismissed !== undefined && this.#dismissed !== wanted)
|
|
394
462
|
this.#dismissed = undefined;
|
|
395
463
|
const button = wanted !== this.#dismissed ? wanted : undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altnovatrail/canvas",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.43",
|
|
4
4
|
"description": "NovaTrail's canvases: the workplace of a task, where the learner writes, draws and types.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"./lib/element/index.js"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@altnovatrail/spec": "0.19.
|
|
29
|
+
"@altnovatrail/spec": "0.19.16",
|
|
30
30
|
"perfect-freehand": "1.2.3",
|
|
31
31
|
"rbush": "4.0.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@altnovatrail/contracts": "0.19.
|
|
34
|
+
"@altnovatrail/contracts": "0.19.16",
|
|
35
35
|
"@biomejs/biome": "2.6.6",
|
|
36
36
|
"@bufbuild/protobuf": "2.17.0",
|
|
37
37
|
"@iconify-json/material-symbols": "1.2.99",
|