@altnovatrail/canvas 0.3.39 → 0.3.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/boxes.d.ts +7 -7
- package/lib/core/boxes.js +10 -10
- package/lib/core/clock.d.ts +5 -5
- package/lib/core/clock.js +5 -5
- package/lib/core/crop.d.ts +13 -13
- package/lib/core/crop.js +10 -10
- package/lib/core/eraser.d.ts +6 -6
- package/lib/core/eraser.js +6 -6
- package/lib/core/example.d.ts +6 -6
- package/lib/core/example.js +9 -9
- package/lib/core/fields.d.ts +1 -1
- package/lib/core/fields.js +1 -1
- package/lib/core/geometry.d.ts +6 -5
- package/lib/core/geometry.js +8 -6
- package/lib/core/grid.d.ts +3 -3
- package/lib/core/grid.js +3 -3
- package/lib/core/groups.d.ts +14 -14
- package/lib/core/groups.js +6 -6
- package/lib/core/hands.d.ts +19 -18
- package/lib/core/hands.js +16 -15
- package/lib/core/history.d.ts +9 -9
- package/lib/core/history.js +6 -6
- package/lib/core/index.js +8 -9
- package/lib/core/ink.js +3 -3
- package/lib/core/manifest.d.ts +3 -3
- package/lib/core/manifest.js +6 -6
- package/lib/core/marks.d.ts +39 -39
- package/lib/core/marks.js +34 -34
- package/lib/core/notation.d.ts +5 -5
- package/lib/core/outline.d.ts +3 -3
- package/lib/core/outline.js +6 -6
- package/lib/core/page.d.ts +7 -7
- package/lib/core/page.js +10 -10
- package/lib/core/png.d.ts +3 -3
- package/lib/core/png.js +3 -3
- package/lib/core/raster.d.ts +3 -3
- package/lib/core/raster.js +3 -3
- package/lib/core/recorder.d.ts +7 -7
- package/lib/core/recorder.js +7 -7
- package/lib/core/screen.d.ts +2 -2
- package/lib/core/screen.js +1 -1
- package/lib/core/sets.d.ts +1 -1
- package/lib/core/sets.js +1 -1
- package/lib/core/sheet.d.ts +3 -3
- package/lib/core/sheet.js +3 -3
- package/lib/core/submission.d.ts +24 -24
- package/lib/core/submission.js +21 -21
- package/lib/core/task.d.ts +17 -16
- package/lib/core/task.js +14 -13
- package/lib/core/tracing.d.ts +20 -20
- package/lib/core/tracing.js +20 -20
- package/lib/core/widths.d.ts +2 -2
- package/lib/core/widths.js +5 -5
- package/lib/core/work.d.ts +18 -18
- package/lib/core/work.js +21 -21
- package/lib/core/zoom.d.ts +4 -4
- package/lib/core/zoom.js +4 -4
- package/lib/element/index.d.ts +87 -87
- package/lib/element/index.js +284 -281
- package/lib/element/labels.d.ts +17 -17
- package/lib/element/labels.js +7 -8
- package/lib/element/notation.js +1 -1
- package/lib/element/parts.d.ts +2 -2
- package/lib/element/parts.js +6 -6
- package/lib/element/pictures.js +1 -1
- package/lib/element/probe.d.ts +2 -2
- package/lib/element/probe.js +3 -3
- package/lib/element/session.js +2 -2
- package/lib/element/statement.d.ts +2 -2
- package/lib/element/statement.js +6 -6
- package/lib/element/tools.d.ts +17 -18
- package/lib/element/tools.js +30 -29
- package/lib/element/tracing.js +8 -8
- package/package.json +3 -3
package/lib/element/index.js
CHANGED
|
@@ -2,27 +2,27 @@
|
|
|
2
2
|
// canvas kind, with its markup in an open shadow root (R07). Importing it registers the element,
|
|
3
3
|
// once: a page has one element of this name. The types of its contract with app are spec's, of
|
|
4
4
|
// @altnovatrail/spec/canvas: the element implements its CanvasElement, and the package puts the
|
|
5
|
-
// element and its events in the DOM's maps
|
|
5
|
+
// element and its events in the DOM's maps.
|
|
6
6
|
//
|
|
7
|
-
// The handwriting sheet takes its input one pointer at a time
|
|
7
|
+
// The handwriting sheet takes its input one pointer at a time, with undo and clearing.
|
|
8
8
|
// Its eraser takes strokes off whole, by the path of a press, as the tool or a pen's eraser, and
|
|
9
|
-
// the sheet keeps the history of writing
|
|
10
|
-
// its template and the task's statement above it, its look the consumer's to theme
|
|
9
|
+
// the sheet keeps the history of writing. The sheet is a stack of layers, the task's grid on
|
|
10
|
+
// its template and the task's statement above it, its look the consumer's to theme. The
|
|
11
11
|
// tutor's marks of a submission hold on to the learner's strokes, and a frame shows where each is,
|
|
12
|
-
// over the work
|
|
13
|
-
// action, and the work for checking is the crop with the context of its submission
|
|
12
|
+
// over the work. The history of writing comes in and goes out, an event tells of every
|
|
13
|
+
// action, and the work for checking is the crop with the context of its submission. Over it
|
|
14
14
|
// all stand the element's own buttons — the tools the task allows, undo and clearing —, labelled
|
|
15
|
-
// in the element's `lang
|
|
15
|
+
// in the element's `lang`, on a vertical bar of glass at its left edge (R84). On a tablet a
|
|
16
16
|
// pen's touch puts the page in pen mode, where a finger writes nothing, a palm writes nothing, and
|
|
17
|
-
// two fingers scroll
|
|
17
|
+
// two fingers scroll, one finger too.
|
|
18
18
|
// The task comes in the names of the module format 0.4, checked as its schema checks it, and the
|
|
19
|
-
// module's manifest gives the height of a digit and the statement's language
|
|
19
|
+
// module's manifest gives the height of a digit and the statement's language.
|
|
20
20
|
//
|
|
21
21
|
// The workbook's lines, laid out on its page, stand on the template in place of the grid —
|
|
22
|
-
// numbers, text and boxes, which a screen reader reads in the task's order
|
|
22
|
+
// numbers, text and boxes, which a screen reader reads in the task's order. Each stroke
|
|
23
23
|
// is in one box or in none, by a rule of whole numbers, and `filled` tells which boxes hold one: a
|
|
24
|
-
// filled box's frame is thicker, and its name says so
|
|
25
|
-
// crop of each filled box, with the table of the boxes' strokes for its context
|
|
24
|
+
// filled box's frame is thicker, and its name says so. A workbook's work for checking is the
|
|
25
|
+
// crop of each filled box, with the table of the boxes' strokes for its context.
|
|
26
26
|
//
|
|
27
27
|
// A lesson's worked example it shows on a sheet the learner does not write on: its statement above
|
|
28
28
|
// the sheet, its grid, and no bar, while a finger or a pen scrolls the sheet as the browser scrolls
|
|
@@ -32,23 +32,22 @@
|
|
|
32
32
|
// pictures of the statement and of the demo come from the consumer's media, one file for each
|
|
33
33
|
// reference, all of them as the task or the example comes: a part opened shows its picture at
|
|
34
34
|
// once. A picture on an area of the sheet stands on the layer of the author's demo, over its area,
|
|
35
|
-
// and the sheet scrolls to the area as the part opens
|
|
36
|
-
// its lines out as a task's, and a part of its demo that fills a box writes the box's value in it
|
|
37
|
-
// (R61).
|
|
35
|
+
// and the sheet scrolls to the area as the part opens. A worked example on a workbook lays
|
|
36
|
+
// its lines out as a task's, and a part of its demo that fills a box writes the box's value in it.
|
|
38
37
|
//
|
|
39
38
|
// The keyboard goes into the sheet and out: a container that scrolls is a region named by the
|
|
40
|
-
// canvas kind, with a stop of Tab of its own and a ring when the keyboard brings the focus there
|
|
41
|
-
//
|
|
42
|
-
// element's
|
|
39
|
+
// canvas kind, with a stop of Tab of its own and a ring when the keyboard brings the focus there;
|
|
40
|
+
// for a `lang` the labels are not in, the container is in theirs and the column in the
|
|
41
|
+
// element's. The sheet goes on past the task's page, which stands at its left, right and
|
|
43
42
|
// down as far as the ink and one view more, and nothing zooms it: the hand, two fingers, the wheel
|
|
44
|
-
// and the keys move it across as well as down
|
|
43
|
+
// and the keys move it across as well as down.
|
|
45
44
|
//
|
|
46
45
|
// A task from the learner's paper it shows on a sheet of the learner's grid, which the grid's
|
|
47
|
-
// button turns round, dots as the task comes
|
|
46
|
+
// button turns round, dots as the task comes, with the task's crop over it as tracing paper,
|
|
48
47
|
// which the learner moves by its grip, hides and shows by the button atop the tools, and writes on
|
|
49
48
|
// as on the sheet: a stroke begun on the paper is the paper's and moves with it, and an erasing
|
|
50
49
|
// begun on it takes the paper's strokes alone. The work for checking is the crop of the paper and
|
|
51
|
-
// of the sheet's strokes, with the task's crop beside it
|
|
50
|
+
// of the sheet's strokes, with the task's crop beside it.
|
|
52
51
|
import { cellOf, cellsOf, filledOf, sheetFilledOf } from "../core/boxes.js";
|
|
53
52
|
import { Clock } from "../core/clock.js";
|
|
54
53
|
import { ERASER_BUTTON, Eraser } from "../core/eraser.js";
|
|
@@ -88,7 +87,7 @@ const INK = "#111";
|
|
|
88
87
|
const PAPER = "#fff";
|
|
89
88
|
/**
|
|
90
89
|
* The colour of the tool in use and of the focus on the bar unless the consumer's theme gives one,
|
|
91
|
-
* and the bar's glass: the interface mockup's
|
|
90
|
+
* and the bar's glass: the interface mockup's.
|
|
92
91
|
*/
|
|
93
92
|
const ACCENT = "#0071E3";
|
|
94
93
|
const GLASS = "rgba(255, 255, 255, 0.76)";
|
|
@@ -105,14 +104,14 @@ const TRACING_READ = "tracingread";
|
|
|
105
104
|
const GRID_CHANGE = "gridchange";
|
|
106
105
|
/**
|
|
107
106
|
* A task from paper's template: no statement, the pen and the eraser, and a dotted sheet, as the
|
|
108
|
-
* task comes, whose grid the learner turns
|
|
107
|
+
* task comes, whose grid the learner turns.
|
|
109
108
|
*/
|
|
110
109
|
const PAPER_TEMPLATE = Object.freeze({
|
|
111
110
|
grid: Object.freeze({ kind: "dots", step: TRACING.dots }),
|
|
112
111
|
statement: Object.freeze([]),
|
|
113
112
|
tools: NO_TASK.tools,
|
|
114
113
|
});
|
|
115
|
-
/** What Next and Demo control, by their IDs in the shadow root: the region, and the list
|
|
114
|
+
/** What Next and Demo control, by their IDs in the shadow root: the region, and the list. */
|
|
116
115
|
const DEMO_IDS = { status: "demo-status", parts: "demo-parts" };
|
|
117
116
|
/**
|
|
118
117
|
* The colour of the tutor's frames unless the consumer's theme gives one: a blue, and not a red,
|
|
@@ -122,7 +121,7 @@ const MARK = "#2563eb";
|
|
|
122
121
|
/**
|
|
123
122
|
* The colours of a verdict's tick and cross, over its white halo: a green, and an amber rather than
|
|
124
123
|
* a red, for «not yet» is no failure; each holds more than 3:1 on white, and the halo holds them
|
|
125
|
-
* over any sheet or photo of a page
|
|
124
|
+
* over any sheet or photo of a page.
|
|
126
125
|
*/
|
|
127
126
|
const RIGHT = "#15803d";
|
|
128
127
|
const NOT_YET = "#b45309";
|
|
@@ -136,7 +135,7 @@ const CROSS = "M8 8l8 8M16 8l-8 8";
|
|
|
136
135
|
/**
|
|
137
136
|
* The colour of the tutor's wavy line of "Show where" unless the consumer's theme gives one: an
|
|
138
137
|
* orange, as the mockup's, 3.58:1 on white, over a white halo that holds it over any sheet or photo
|
|
139
|
-
* of a page
|
|
138
|
+
* of a page.
|
|
140
139
|
*/
|
|
141
140
|
const WAVY = "#e8590c";
|
|
142
141
|
/**
|
|
@@ -147,13 +146,13 @@ const WAVY_HALF = GRID_STEP / 4;
|
|
|
147
146
|
const WAVY_CREST = 3.5;
|
|
148
147
|
const WAVY_BELOW = 12;
|
|
149
148
|
const WAVY_REACH = 10;
|
|
150
|
-
/** How far a frame stands off the points of its strokes, in sheet units, as canvas-api's
|
|
149
|
+
/** How far a frame stands off the points of its strokes, in sheet units, as canvas-api's. */
|
|
151
150
|
const MARK_PADDING = 10;
|
|
152
151
|
/** The rounding of a frame's corners, in sheet units. */
|
|
153
152
|
const MARK_CORNER = 6;
|
|
154
153
|
/**
|
|
155
154
|
* How near a stroke's ink the eraser takes it, in CSS pixels: the same on every screen, whatever
|
|
156
|
-
* the sheet's scale
|
|
155
|
+
* the sheet's scale.
|
|
157
156
|
*/
|
|
158
157
|
const ERASER_RADIUS_PX = 10;
|
|
159
158
|
// The statement and the sheet stand in a column of their own, and scroll in a container of their
|
|
@@ -162,18 +161,18 @@ const ERASER_RADIUS_PX = 10;
|
|
|
162
161
|
// sheet's left; the sheet goes on past it as far as `#extent` says, and the container scrolls it
|
|
163
162
|
// across too, left to right whatever the page's direction, while the statement and a demo's parts
|
|
164
163
|
// stay as wide as the page and stick to its left, in the element's own direction: they scroll down
|
|
165
|
-
// alone
|
|
164
|
+
// alone. The layers of the sheet stand in its visible part, the stage, which sticks to the
|
|
166
165
|
// container's top and left, and each shows what lies there, shifted in the frame the ink is drawn
|
|
167
|
-
// in
|
|
166
|
+
// in. Over the container, in the same cell of the frame's grid, stands the rail of the
|
|
168
167
|
// element's own buttons: a band as tall as the part of the element in sight and as wide as nothing,
|
|
169
168
|
// sticking to the top of whatever scrolls the element, as far down as the consumer's
|
|
170
169
|
// --novatrail-canvas-top says, and up to its bottom less --novatrail-canvas-pad-bottom, and in its
|
|
171
170
|
// middle, 16 pixels from the left edge, the bar of buttons: 52 pixels wide, round at its ends, of
|
|
172
171
|
// the mockup's glass — the fill the consumer's theme gives, blurred behind, or the paper alone
|
|
173
|
-
// where nothing blurs — over the sheet as it scrolls by
|
|
172
|
+
// where nothing blurs — over the sheet as it scrolls by. A bar taller than the
|
|
174
173
|
// band scrolls inside its glass (WCAG 1.4.10). A worked example has no bar, and its Next and Demo
|
|
175
174
|
// stand in a row of the same glass at the band's bottom, the consumer's buttons of the slot actions
|
|
176
|
-
// after them
|
|
175
|
+
// after them. The tool in use is filled with the accent at an eighth, its icon in the accent;
|
|
177
176
|
// a button in focus shows a ring in the accent; an unavailable one is paler by its colour, not its
|
|
178
177
|
// opacity, which would pale the ring too (WCAG 2.4.7, 1.4.11). A button's tooltip stands beside it,
|
|
179
178
|
// white on near-black, as the mockup has it. Nothing in the element moves but the scrolling, which
|
|
@@ -181,30 +180,30 @@ const ERASER_RADIUS_PX = 10;
|
|
|
181
180
|
// unless it is given a height: then the statement and the sheet scroll in it, under the bar. A
|
|
182
181
|
// consumer whose own bars float over the element's top and bottom says how far by
|
|
183
182
|
// --novatrail-canvas-pad-top and -bottom: the statement starts below the first, and the sheet
|
|
184
|
-
// scrolls up past the second
|
|
183
|
+
// scrolls up past the second. A worked example's open parts stand between the statement and
|
|
185
184
|
// the sheet, and the region that tells of them is out of sight, but not out of the tree a screen
|
|
186
|
-
// reader reads, where a hidden region would tell nothing
|
|
185
|
+
// reader reads, where a hidden region would tell nothing. A picture's frame there stands in
|
|
187
186
|
// its item's line, from its top, so that the item's number stands at the top too, as a paragraph's
|
|
188
187
|
// does, and not at the picture's bottom. A picture on an area of the sheet stands on the layer of
|
|
189
188
|
// the author's demo, and the sheet scrolls to a hidden box of the area in its own flow, which
|
|
190
|
-
// neither paints nor takes a pointer
|
|
189
|
+
// neither paints nor takes a pointer. On the canvas the browser neither scrolls nor zooms:
|
|
191
190
|
// the pointer writes, or with the hand moves the sheet, and two fingers scroll by the element's own
|
|
192
|
-
// code
|
|
191
|
+
// code, and in pen mode one finger too. The canvas and the buttons take pointer
|
|
193
192
|
// events only as the element does: a consumer's pointer-events: none on the element stops the
|
|
194
|
-
// writing and the buttons' pointer, though not their keys
|
|
193
|
+
// writing and the buttons' pointer, though not their keys. A worked example's canvas
|
|
195
194
|
// takes no pointer at all: a finger or a pen on its sheet scrolls, and zooms, as the browser does
|
|
196
|
-
// on the statement, and a long press or a right click opens no menu over the sheet all the same
|
|
197
|
-
//
|
|
195
|
+
// on the statement, and a long press or a right click opens no menu over the sheet all the same.
|
|
196
|
+
// The theme is the consumer's, by custom properties that the shadow tree inherits; with
|
|
198
197
|
// forced colours the system's colours stand in for them. The element is horizontal whatever writing
|
|
199
|
-
// mode the page is in: a sheet has no other
|
|
198
|
+
// mode the page is in: a sheet has no other.
|
|
200
199
|
//
|
|
201
200
|
// A workbook's lines are printed in the ink's colour and the consumer's font, and nothing else the
|
|
202
201
|
// element inherits — spacing, weight, transforms, the direction — moves them: `all: initial` takes
|
|
203
|
-
// it off, and what the print needs comes back
|
|
202
|
+
// it off, and what the print needs comes back. A box's frame is one CSS pixel at any scale,
|
|
204
203
|
// on whole device pixels: an antialiased line of one pixel would lose its contrast. A filled box's
|
|
205
|
-
// is three, in the same ink, and the system's highlight with forced colours
|
|
204
|
+
// is three, in the same ink, and the system's highlight with forced colours. A dot of the grid
|
|
206
205
|
// is three pixels across at the fit and above it, and smaller by the zoom below it, so that a sheet
|
|
207
|
-
// zoomed out is no field of dots
|
|
206
|
+
// zoomed out is no field of dots.
|
|
208
207
|
const STYLE = `
|
|
209
208
|
:host { display: flex; flex-direction: column; isolation: isolate; writing-mode: horizontal-tb; }
|
|
210
209
|
:host([hidden]) { display: none; }
|
|
@@ -546,7 +545,7 @@ const sheets = new WeakMap();
|
|
|
546
545
|
* Gives the element's shadow root its style, as a sheet the root adopts, and not a `<style>` in
|
|
547
546
|
* its tree: a consumer's content security policy that allows no inline style, as app's
|
|
548
547
|
* `style-src 'self'`, blocks the one and not the other, and the element asks of the policy only
|
|
549
|
-
* `img-src blob:` (R51
|
|
548
|
+
* `img-src blob:` (R51). A root adopts only a sheet made for its own document, by that
|
|
550
549
|
* document's window, and an element moved into another document comes there without its sheets:
|
|
551
550
|
* it adopts that document's sheet then. A document without a window, which can make no sheet,
|
|
552
551
|
* leaves the element unstyled till it comes into one that can.
|
|
@@ -574,7 +573,7 @@ function svgLayer(name) {
|
|
|
574
573
|
}
|
|
575
574
|
/**
|
|
576
575
|
* The layer of the tutor's marks, over the work: a screen reader reads each mark by its name, and
|
|
577
|
-
* the layer itself is no picture of its own
|
|
576
|
+
* the layer itself is no picture of its own.
|
|
578
577
|
*/
|
|
579
578
|
function marksLayer() {
|
|
580
579
|
const svg = svgLayer("marks");
|
|
@@ -589,7 +588,7 @@ function frameNode() {
|
|
|
589
588
|
return rect;
|
|
590
589
|
}
|
|
591
590
|
/**
|
|
592
|
-
* A verdict of a task from paper
|
|
591
|
+
* A verdict of a task from paper: a tick or a cross on a white circle, on the 24 × 24
|
|
593
592
|
* that its place scales.
|
|
594
593
|
*/
|
|
595
594
|
function verdictNode(correct) {
|
|
@@ -607,7 +606,7 @@ function verdictNode(correct) {
|
|
|
607
606
|
return g;
|
|
608
607
|
}
|
|
609
608
|
/**
|
|
610
|
-
* The wavy line of "Show where"
|
|
609
|
+
* The wavy line of "Show where": the line over a wider white one, its halo, both
|
|
611
610
|
* of the path the marks give them.
|
|
612
611
|
*/
|
|
613
612
|
function wavyNode() {
|
|
@@ -664,35 +663,35 @@ function htmlLayer(name) {
|
|
|
664
663
|
return div;
|
|
665
664
|
}
|
|
666
665
|
/**
|
|
667
|
-
* The element `<novatrail-canvas>`: the contract's `CanvasElement
|
|
666
|
+
* The element `<novatrail-canvas>`: the contract's `CanvasElement`, and beyond it the
|
|
668
667
|
* commands undo and clear, which the contract does not name.
|
|
669
668
|
*/
|
|
670
669
|
export class NovatrailCanvas extends HTMLElement {
|
|
671
670
|
/**
|
|
672
671
|
* The wrapper, which does not scroll, of the container that scrolls and of the ring of its focus
|
|
673
672
|
* over it: an outline of the container itself would stand under the sheet's paper and stage,
|
|
674
|
-
* which are positioned in it
|
|
673
|
+
* which are positioned in it.
|
|
675
674
|
*/
|
|
676
675
|
#wrapper = document.createElement("div");
|
|
677
676
|
#viewport = document.createElement("div");
|
|
678
677
|
#ring = document.createElement("div");
|
|
679
678
|
#column = document.createElement("div");
|
|
680
679
|
#sheet = document.createElement("div");
|
|
681
|
-
/** The sheet's visible part, where its layers stand, bottom to top
|
|
680
|
+
/** The sheet's visible part, where its layers stand, bottom to top. */
|
|
682
681
|
#stage = document.createElement("div");
|
|
683
|
-
/** The author's template: a sheet's grid, or a workbook's lines, a list of its items
|
|
682
|
+
/** The author's template: a sheet's grid, or a workbook's lines, a list of its items. */
|
|
684
683
|
#template = svgLayer("template");
|
|
685
684
|
#grid = document.createElementNS(SVG, "path");
|
|
686
|
-
/** The grid going on above the sheet and below it, under the consumer's floating bars
|
|
685
|
+
/** The grid going on above the sheet and below it, under the consumer's floating bars. */
|
|
687
686
|
#above = document.createElementNS(SVG, "svg");
|
|
688
687
|
#below = document.createElementNS(SVG, "svg");
|
|
689
688
|
#print = document.createElementNS(SVG, "g");
|
|
690
689
|
#lines = document.createElementNS(SVG, "g");
|
|
691
|
-
/** The module's widget, from stage 4
|
|
690
|
+
/** The module's widget, from stage 4: empty till then. */
|
|
692
691
|
#widget = htmlLayer("widget");
|
|
693
|
-
/** The author's demo: a worked example's pictures on areas of the sheet
|
|
692
|
+
/** The author's demo: a worked example's pictures on areas of the sheet. */
|
|
694
693
|
#show = svgLayer("show");
|
|
695
|
-
/** The tutor's layer, in two: the sketch under the learner's work, the marks over it
|
|
694
|
+
/** The tutor's layer, in two: the sketch under the learner's work, the marks over it. */
|
|
696
695
|
#sketch = svgLayer("sketch");
|
|
697
696
|
/** The learner's work: the ink. */
|
|
698
697
|
#canvas = document.createElement("canvas");
|
|
@@ -700,13 +699,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
700
699
|
#context = this.#canvas.getContext("2d");
|
|
701
700
|
/** The canvas's style as it is computed, read live: its colour is the ink's on the screen. */
|
|
702
701
|
#canvasStyle = getComputedStyle(this.#canvas);
|
|
703
|
-
/** The files of the pictures of the statement and of a worked example's demo
|
|
702
|
+
/** The files of the pictures of the statement and of a worked example's demo. */
|
|
704
703
|
#pictures = new Pictures();
|
|
705
|
-
/** The task's statement, above the sheet
|
|
704
|
+
/** The task's statement, above the sheet. */
|
|
706
705
|
#statement = new Statement(this.#pictures);
|
|
707
|
-
/** A worked example's open parts, under its statement, and the region that tells of them
|
|
706
|
+
/** A worked example's open parts, under its statement, and the region that tells of them. */
|
|
708
707
|
#parts = new Parts(DEMO_IDS, this.#pictures);
|
|
709
|
-
/** The element's own buttons, on a bar over the sheet's left edge
|
|
708
|
+
/** The element's own buttons, on a bar over the sheet's left edge. */
|
|
710
709
|
#tools = new Tools({
|
|
711
710
|
choose: (tool) => this.#choose(tool),
|
|
712
711
|
undo: () => this.undo(),
|
|
@@ -717,7 +716,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
717
716
|
toggle: () => this.#toggleDemo(),
|
|
718
717
|
trace: () => this.#trace(),
|
|
719
718
|
}, DEMO_IDS);
|
|
720
|
-
/** A task from paper's tracing paper: its layer, its grip and the crop's picture
|
|
719
|
+
/** A task from paper's tracing paper: its layer, its grip and the crop's picture. */
|
|
721
720
|
#tracingPaper = new TracingPaper({
|
|
722
721
|
move: (at) => this.#moveTracing(at),
|
|
723
722
|
resize: (at, scale) => this.#resizeTracing(at, scale),
|
|
@@ -725,23 +724,23 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
725
724
|
moved: () => this.#tracingMoved(),
|
|
726
725
|
read: () => this.dispatchEvent(new CustomEvent(TRACING_READ, { bubbles: true, composed: true, detail: null })),
|
|
727
726
|
});
|
|
728
|
-
/** The reading of the statement of the task from paper, as the consumer gave it
|
|
727
|
+
/** The reading of the statement of the task from paper, as the consumer gave it. */
|
|
729
728
|
#reading;
|
|
730
|
-
/** The task from paper as the consumer gave it, and where its tracing paper lies
|
|
729
|
+
/** The task from paper as the consumer gave it, and where its tracing paper lies. */
|
|
731
730
|
#paper;
|
|
732
731
|
#tracing;
|
|
733
732
|
/** The tracing paper's state the learner's move began at: the move tells only if it changed it. */
|
|
734
733
|
#moveFrom;
|
|
735
|
-
/** The layer the stroke under way is written on, and the erasing under way erases
|
|
734
|
+
/** The layer the stroke under way is written on, and the erasing under way erases. */
|
|
736
735
|
#writeOn;
|
|
737
736
|
#eraseOn;
|
|
738
737
|
/** Each stroke of the tracing paper where it lies on the sheet, for the place it was moved to. */
|
|
739
738
|
#placed = new WeakMap();
|
|
740
|
-
/** The sheet's clock, for its strokes and its actions alike
|
|
739
|
+
/** The sheet's clock, for its strokes and its actions alike. */
|
|
741
740
|
#clock = new Clock();
|
|
742
741
|
/**
|
|
743
|
-
* The strokes on the sheet, the actions undo takes back and the history of writing
|
|
744
|
-
* new work when the sheet is given another history
|
|
742
|
+
* The strokes on the sheet, the actions undo takes back and the history of writing: a
|
|
743
|
+
* new work when the sheet is given another history.
|
|
745
744
|
*/
|
|
746
745
|
#work = new Work(this.#clock);
|
|
747
746
|
/** How many events of the history `historychange` has told of, and whether it is telling now. */
|
|
@@ -758,7 +757,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
758
757
|
this.#changed();
|
|
759
758
|
});
|
|
760
759
|
/**
|
|
761
|
-
* The hands on the sheet
|
|
760
|
+
* The hands on the sheet: which pointer may write, which is a palm, and which two fingers
|
|
762
761
|
* scroll, in the page's pen mode. The recorder and the eraser say which pointer writes.
|
|
763
762
|
*/
|
|
764
763
|
#hands = new Hands({
|
|
@@ -770,7 +769,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
770
769
|
}, PEN_MODE);
|
|
771
770
|
/**
|
|
772
771
|
* What two fingers, or the hand, scroll in the gesture under way, down and across, each chosen at
|
|
773
|
-
* the first step that goes along its axis
|
|
772
|
+
* the first step that goes along its axis: undefined till then, and null when nothing
|
|
774
773
|
* scrolls so.
|
|
775
774
|
*/
|
|
776
775
|
#latch;
|
|
@@ -781,35 +780,35 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
781
780
|
this.#fit();
|
|
782
781
|
};
|
|
783
782
|
#page = new ResizeObserver(this.#resized);
|
|
784
|
-
/** A window of another size has another view: the sheet goes as far past the ink by it
|
|
783
|
+
/** A window of another size has another view: the sheet goes as far past the ink by it. */
|
|
785
784
|
#rewindowed = () => this.#regrow();
|
|
786
785
|
/** What the bar's rail sticks in, when a scroller of the page's: its height is the rail's room. */
|
|
787
786
|
#port = null;
|
|
788
787
|
#ported = new ResizeObserver(() => this.#fit());
|
|
789
788
|
#unwatchPen;
|
|
790
789
|
#unwatchZoom;
|
|
791
|
-
/** The zoom the sheet is laid out by: the page's, and a worked example's 1
|
|
790
|
+
/** The zoom the sheet is laid out by: the page's, and a worked example's 1. */
|
|
792
791
|
#zoom = 1;
|
|
793
|
-
/** Where on the screen a pinch zooms about, while it sets the page's zoom
|
|
792
|
+
/** Where on the screen a pinch zooms about, while it sets the page's zoom. */
|
|
794
793
|
#anchor;
|
|
795
794
|
/**
|
|
796
795
|
* The point of the sheet a press zoomed about, where on the screen it stood, and where the press
|
|
797
|
-
* left the container: while nothing has scrolled or moved it since, the next press zooms about
|
|
798
|
-
* same point, so that a zoom out at the sheet's edge, where the scroll stops short, and back
|
|
799
|
-
* comes back where it was
|
|
796
|
+
* left the container: while nothing has scrolled or moved it since, the next press zooms about
|
|
797
|
+
* the same point, so that a zoom out at the sheet's edge, where the scroll stops short, and back
|
|
798
|
+
* in comes back where it was.
|
|
800
799
|
*/
|
|
801
800
|
#held;
|
|
802
801
|
#tool = "pen";
|
|
803
|
-
/** The pointer the hand moves the sheet by, and where it was on the screen last
|
|
802
|
+
/** The pointer the hand moves the sheet by, and where it was on the screen last. */
|
|
804
803
|
#pan;
|
|
805
|
-
/** A task from paper's grid, the learner's
|
|
804
|
+
/** A task from paper's grid, the learner's. */
|
|
806
805
|
#paperGrid = "dots";
|
|
807
|
-
/** How far the sheet goes, in units, as laid out: the page and past it
|
|
806
|
+
/** How far the sheet goes, in units, as laid out: the page and past it. */
|
|
808
807
|
#extent = SHEET;
|
|
809
808
|
/** The grid's path as last drawn: its rulings and the extent they cover. */
|
|
810
809
|
#gridDrawn = "";
|
|
811
810
|
#task;
|
|
812
|
-
/** A lesson's worked example as the consumer gave it, and as the element checked it
|
|
811
|
+
/** A lesson's worked example as the consumer gave it, and as the element checked it. */
|
|
813
812
|
#workedExample;
|
|
814
813
|
#example;
|
|
815
814
|
/** How far the learner has gone through the example's demo, frozen, or undefined without one. */
|
|
@@ -817,25 +816,25 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
817
816
|
#shownTemplate = NO_TASK;
|
|
818
817
|
/**
|
|
819
818
|
* A workbook's page, its boxes in the task's order and their frames, and the box each stroke is
|
|
820
|
-
* in, worked out once: a stroke never changes
|
|
819
|
+
* in, worked out once: a stroke never changes, and a new page starts the map anew.
|
|
821
820
|
*/
|
|
822
821
|
#laid;
|
|
823
822
|
#cells = [];
|
|
824
823
|
#rects = [];
|
|
825
824
|
/**
|
|
826
825
|
* The texts of the values a worked example's demo has written in its boxes, one for each frame
|
|
827
|
-
* that has had one
|
|
826
|
+
* that has had one.
|
|
828
827
|
*/
|
|
829
828
|
#values = [];
|
|
830
829
|
#taken = new WeakMap();
|
|
831
|
-
/** Which answer slots are filled, the same array until one changes, or null
|
|
830
|
+
/** Which answer slots are filled, the same array until one changes, or null. */
|
|
832
831
|
#filled = null;
|
|
833
|
-
/** Whether the task's one answer is anywhere on the sheet or the whole sheet
|
|
832
|
+
/** Whether the task's one answer is anywhere on the sheet or the whole sheet. */
|
|
834
833
|
#whole = false;
|
|
835
|
-
/** The module's manifest as the consumer gave it, and what the element makes of it
|
|
834
|
+
/** The module's manifest as the consumer gave it, and what the element makes of it. */
|
|
836
835
|
#manifest;
|
|
837
836
|
#settings = NO_MANIFEST;
|
|
838
|
-
/** The tutor's marks as the consumer gave them, and those of them that have a place
|
|
837
|
+
/** The tutor's marks as the consumer gave them, and those of them that have a place. */
|
|
839
838
|
#marks;
|
|
840
839
|
/** The marks as they were checked when given: a new history places these, whatever became of those. */
|
|
841
840
|
#given;
|
|
@@ -850,11 +849,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
850
849
|
* strokes are the same array.
|
|
851
850
|
*/
|
|
852
851
|
#strokesById = { strokes: [], byId: new Map() };
|
|
853
|
-
/** The box of each stroke's points, worked out once: a stroke never changes
|
|
852
|
+
/** The box of each stroke's points, worked out once: a stroke never changes. */
|
|
854
853
|
#pointBoxes = new WeakMap();
|
|
855
854
|
/** The stroke under way, and how many of its points the marks have been checked against. */
|
|
856
855
|
#writing;
|
|
857
|
-
/** The path of each finished stroke, outlined once
|
|
856
|
+
/** The path of each finished stroke, outlined once. */
|
|
858
857
|
#inks = new WeakMap();
|
|
859
858
|
#resize = new ResizeObserver((entries) => {
|
|
860
859
|
for (const entry of entries) {
|
|
@@ -877,7 +876,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
877
876
|
*/
|
|
878
877
|
#k = 0;
|
|
879
878
|
#sheetAt = 0;
|
|
880
|
-
/** The sheet's left in the container's content, as laid out then, in CSS pixels
|
|
879
|
+
/** The sheet's left in the container's content, as laid out then, in CSS pixels. */
|
|
881
880
|
#sheetAtX = 0;
|
|
882
881
|
/** The top and the left of the visible part, in sheet units, kept from the last scroll. */
|
|
883
882
|
#vy = 0;
|
|
@@ -912,7 +911,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
912
911
|
band.firstElementChild?.setAttribute("class", "grid");
|
|
913
912
|
}
|
|
914
913
|
this.#print.setAttribute("class", "print");
|
|
915
|
-
// The constructor reads no attribute: the labels of a demo's boxes are English till `lang`
|
|
914
|
+
// The constructor reads no attribute: the labels of a demo's boxes are English till `lang`
|
|
915
|
+
// comes.
|
|
916
916
|
this.#nameBoxes(null);
|
|
917
917
|
this.#nameGrip(null);
|
|
918
918
|
this.#lines.setAttribute("role", "list");
|
|
@@ -946,14 +946,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
946
946
|
});
|
|
947
947
|
// A long press of a pen or a finger, or a right click, opens no menu over the sheet: the
|
|
948
948
|
// canvas's event comes up to the stage, and so does the stage's own, where a worked example's
|
|
949
|
-
// sheet takes the pointer instead
|
|
949
|
+
// sheet takes the pointer instead.
|
|
950
950
|
this.#stage.addEventListener("contextmenu", (event) => event.preventDefault());
|
|
951
951
|
// A new colour of the ink, from the consumer's theme or the page's colour scheme, ends a
|
|
952
952
|
// transition of the canvas's colour a millisecond long: the ink is drawn anew in it.
|
|
953
953
|
this.#canvas.addEventListener("transitionend", () => this.#request());
|
|
954
954
|
this.#canvas.addEventListener("transitioncancel", () => this.#request());
|
|
955
955
|
this.#viewport.addEventListener("scroll", () => this.#scrolled(), { passive: true });
|
|
956
|
-
// Ctrl or ⌘ with the wheel over the tracing paper scales it, not the page
|
|
956
|
+
// Ctrl or ⌘ with the wheel over the tracing paper scales it, not the page.
|
|
957
957
|
this.#viewport.addEventListener("wheel", (event) => this.#wheel(event), { passive: false });
|
|
958
958
|
// A container left with nothing to scroll keeps its stop of Tab while it has the focus.
|
|
959
959
|
this.#viewport.addEventListener("blur", () => this.#region());
|
|
@@ -981,16 +981,16 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
981
981
|
this.#adopt("history");
|
|
982
982
|
this.#adopt("marks");
|
|
983
983
|
}
|
|
984
|
-
/** The element follows its own `lang`: its buttons are labelled in it
|
|
984
|
+
/** The element follows its own `lang`: its buttons are labelled in it. */
|
|
985
985
|
static observedAttributes = ["lang", "tools-hidden"];
|
|
986
986
|
/**
|
|
987
|
-
* What a press of the primary button does: "pen" writes, as the element starts, "eraser" erases
|
|
988
|
-
*
|
|
987
|
+
* What a press of the primary button does: "pen" writes, as the element starts, "eraser" erases,
|
|
988
|
+
* and "hand" moves the sheet, under any pointer. The learner switches it with the
|
|
989
989
|
* element's own buttons, which say a choice of theirs with a `toolchange`, and the consumer may
|
|
990
|
-
* set it too, which says nothing
|
|
990
|
+
* set it too, which says nothing. A press under way goes on as it began. A pen's eraser
|
|
991
991
|
* erases whatever the tool but the hand. A task without the eraser has none of it: "eraser" is a
|
|
992
992
|
* TypeError then, and a new task without it puts the pen back. Every sheet the learner writes on
|
|
993
|
-
* has the hand. A worked example has the pen alone, which writes nothing on its sheet
|
|
993
|
+
* has the hand. A worked example has the pen alone, which writes nothing on its sheet.
|
|
994
994
|
*/
|
|
995
995
|
get tool() {
|
|
996
996
|
return this.#tool;
|
|
@@ -1007,18 +1007,18 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1007
1007
|
this.#refresh();
|
|
1008
1008
|
}
|
|
1009
1009
|
/**
|
|
1010
|
-
* The open view of the task, of the module format 0.4
|
|
1011
|
-
* element shows above the page
|
|
1012
|
-
*
|
|
1013
|
-
* items. A workbook's items are its lines, which the template shows, laid out on the page
|
|
1014
|
-
*
|
|
1010
|
+
* The open view of the task, of the module format 0.4: its ID, its statement, which the
|
|
1011
|
+
* element shows above the page, what the statement gives and asks, which app shows, its
|
|
1012
|
+
* canvas — the kind, the sheet's grid and the tools the task allows — and its
|
|
1013
|
+
* items. A workbook's items are its lines, which the template shows, laid out on the page. The
|
|
1014
|
+
* type is spec's, with the element's own tools. A task the schema
|
|
1015
1015
|
* refuses is a TypeError that names the field, a field the open view has not among it, and so are
|
|
1016
|
-
* a workbook whose lines do not fit, at the first item that does not
|
|
1016
|
+
* a workbook whose lines do not fit, at the first item that does not, and an answer slot in
|
|
1017
1017
|
* a zone; the sheet passes over a choice and an item's text, which app shows. Another task of the
|
|
1018
1018
|
* same layer, tools and statement changes nothing, and any other changes the template alone, of
|
|
1019
|
-
* either kind: the work stays, for the next task is a new element
|
|
1019
|
+
* either kind: the work stays, for the next task is a new element. A task without the
|
|
1020
1020
|
* eraser puts the pen back, with no event. While a worked example is shown a task is a TypeError,
|
|
1021
|
-
* and `undefined` changes nothing: the element shows one or the other
|
|
1021
|
+
* and `undefined` changes nothing: the element shows one or the other.
|
|
1022
1022
|
*/
|
|
1023
1023
|
get task() {
|
|
1024
1024
|
return this.#task;
|
|
@@ -1039,10 +1039,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1039
1039
|
this.#present(template);
|
|
1040
1040
|
}
|
|
1041
1041
|
/**
|
|
1042
|
-
* A lesson's worked example
|
|
1043
|
-
* module format 0.4 — its statement, which the element shows above the sheet as a task's
|
|
1042
|
+
* A lesson's worked example: the open view of a segment `worked_example` of the
|
|
1043
|
+
* module format 0.4 — its statement, which the element shows above the sheet as a task's,
|
|
1044
1044
|
* the grid of its sheet or the lines of its workbook, and the parts of the author's demo, which
|
|
1045
|
-
* on a workbook fill the lines' boxes with their values
|
|
1045
|
+
* on a workbook fill the lines' boxes with their values. The type is spec's.
|
|
1046
1046
|
* The element shows a task or a worked example, not both: an example while a task is given, while
|
|
1047
1047
|
* the sheet has a history of writing, or while a stroke or an erasing is under way, is a
|
|
1048
1048
|
* TypeError, and so is one the schema refuses, at its field. `undefined` takes the example off,
|
|
@@ -1051,9 +1051,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1051
1051
|
*
|
|
1052
1052
|
* On a worked example's sheet the learner does not write: the canvas takes no input, and a finger
|
|
1053
1053
|
* or a pen there scrolls the sheet as the browser scrolls the statement. It has no bar: its row
|
|
1054
|
-
* holds Next and Demo, and its region is named a worked example's. `task`, `history` other than
|
|
1055
|
-
* `marks` are TypeErrors, and so is an eraser: the tool is the pen alone, and
|
|
1056
|
-
* `filled` give null. The next segment of a lesson is a new element
|
|
1054
|
+
* holds Next and Demo, and its region is named a worked example's. `task`, `history` other than
|
|
1055
|
+
* the empty one and `marks` are TypeErrors, and so is an eraser: the tool is the pen alone, and
|
|
1056
|
+
* `exportWork()` and `filled` give null. The next segment of a lesson is a new element.
|
|
1057
1057
|
*
|
|
1058
1058
|
* The parts of the demo the learner opens one at a time with the row's Next, into a list between
|
|
1059
1059
|
* the statement and the sheet, and hides and shows whole with Demo; `demoState` tells how far
|
|
@@ -1094,16 +1094,16 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1094
1094
|
}
|
|
1095
1095
|
}
|
|
1096
1096
|
/**
|
|
1097
|
-
* A task from the learner's paper
|
|
1097
|
+
* A task from the learner's paper: `statement`, the task's crop as app cut it, a
|
|
1098
1098
|
* Blob of a JPEG or a PNG. The element shows it in place of a task and of a worked example: a
|
|
1099
1099
|
* dotted sheet with no statement, the pen and the eraser, and the crop over it as tracing paper,
|
|
1100
1100
|
* at the element's own place for it, shown, which `tracing` tells. While a task or an example is
|
|
1101
1101
|
* shown it is a TypeError, and so is what is not such a task. Another task from paper, of
|
|
1102
1102
|
* another crop, lays its crop at the start again, and the history stays: the next task is a new
|
|
1103
|
-
* element
|
|
1104
|
-
* history has strokes on the tracing paper, a TypeError. Either drops a stroke or an erasing
|
|
1105
|
-
* way on the tracing paper, as a new history drops the one under the pen. The crop's
|
|
1106
|
-
* read as it comes; till then the paper has its largest size.
|
|
1103
|
+
* element; one of the same crop changes nothing. `undefined` takes it off, but not while the
|
|
1104
|
+
* history has strokes on the tracing paper, a TypeError. Either drops a stroke or an erasing
|
|
1105
|
+
* under way on the tracing paper, as a new history drops the one under the pen. The crop's
|
|
1106
|
+
* picture is read as it comes; till then the paper has its largest size.
|
|
1107
1107
|
*/
|
|
1108
1108
|
get paper() {
|
|
1109
1109
|
return this.#paper;
|
|
@@ -1155,13 +1155,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1155
1155
|
}
|
|
1156
1156
|
/**
|
|
1157
1157
|
* Where the tracing paper of the task from paper lies on the sheet, its top left corner in sheet
|
|
1158
|
-
* units, and whether it is hidden
|
|
1159
|
-
* `undefined` without a task from paper. The learner moves it by its grip and hides or shows it
|
|
1160
|
-
* the button atop the tools, which a `tracingchange` tells; the consumer keeps it and gives it
|
|
1161
|
-
* back, which tells nothing. Given before the task from paper it is a TypeError, and so is a
|
|
1162
|
-
* that is not one, or one that puts the paper wholly off the sheet; `undefined` changes
|
|
1163
|
-
* Till the crop's picture is read the paper has its largest size: a state that puts the
|
|
1164
|
-
* its real size wholly off the sheet then moves to the nearest place wholly on it, with
|
|
1158
|
+
* units, and whether it is hidden: frozen, and the same object until it changes;
|
|
1159
|
+
* `undefined` without a task from paper. The learner moves it by its grip and hides or shows it
|
|
1160
|
+
* by the button atop the tools, which a `tracingchange` tells; the consumer keeps it and gives it
|
|
1161
|
+
* back, which tells nothing. Given before the task from paper it is a TypeError, and so is a
|
|
1162
|
+
* state that is not one, or one that puts the paper wholly off the sheet; `undefined` changes
|
|
1163
|
+
* nothing. Till the crop's picture is read the paper has its largest size: a state that puts the
|
|
1164
|
+
* paper of its real size wholly off the sheet then moves to the nearest place wholly on it, with
|
|
1165
|
+
* no event.
|
|
1165
1166
|
*/
|
|
1166
1167
|
get tracing() {
|
|
1167
1168
|
return this.#tracing;
|
|
@@ -1183,7 +1184,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1183
1184
|
this.#request();
|
|
1184
1185
|
}
|
|
1185
1186
|
/**
|
|
1186
|
-
* The reading of the task from paper's statement in clean print
|
|
1187
|
+
* The reading of the task from paper's statement in clean print: `undefined` offers no
|
|
1187
1188
|
* "Recognise"; `"ready"` offers it, and its press sends a `tracingread`; `"busy"` waits; `"done"`
|
|
1188
1189
|
* holds the statements, which take the crop's place for the learner who asked, till "Original".
|
|
1189
1190
|
* Frozen; given without a task from paper, or not a reading, it is a TypeError.
|
|
@@ -1201,7 +1202,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1201
1202
|
this.#request();
|
|
1202
1203
|
}
|
|
1203
1204
|
/**
|
|
1204
|
-
* How far the learner has gone through the worked example's demo
|
|
1205
|
+
* How far the learner has gone through the worked example's demo: `opened`, how many of
|
|
1205
1206
|
* its parts are open, from the first, and `hidden`, whether the whole demo is hidden — frozen,
|
|
1206
1207
|
* and the same object until it changes. A new example starts at `{ opened: 0, hidden: false }`,
|
|
1207
1208
|
* and without one it is `undefined`. The learner changes it with the row's Next and Demo, which
|
|
@@ -1230,8 +1231,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1230
1231
|
this.#showDemo(example, checked);
|
|
1231
1232
|
}
|
|
1232
1233
|
/**
|
|
1233
|
-
* The open view of the module's manifest
|
|
1234
|
-
* module format — "0.4", or the manifest is a TypeError
|
|
1234
|
+
* The open view of the module's manifest, of which the element reads the version of the
|
|
1235
|
+
* module format — "0.4", or the manifest is a TypeError — the height of a digit on the
|
|
1235
1236
|
* crop for checking, `canvas.digit_height`, 24 px unless given, and the explanation language, the
|
|
1236
1237
|
* statement's and a workbook's lines'. Without a manifest the digits are 24 px, and the statement
|
|
1237
1238
|
* and the lines are in the element's own `lang`. The rest of it the element passes over, but for
|
|
@@ -1239,7 +1240,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1239
1240
|
* cannot read is a TypeError that names the field, and the element stays as it was; the same
|
|
1240
1241
|
* object given again is read again, for the consumer may have changed it. The task and the
|
|
1241
1242
|
* manifest are each the consumer's to give, in either order: `exportWork()` takes the height
|
|
1242
|
-
* when it is called
|
|
1243
|
+
* when it is called.
|
|
1243
1244
|
*/
|
|
1244
1245
|
get manifest() {
|
|
1245
1246
|
return this.#manifest;
|
|
@@ -1256,9 +1257,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1256
1257
|
this.#settings = settings;
|
|
1257
1258
|
}
|
|
1258
1259
|
/**
|
|
1259
|
-
* What gives the files of the pictures, by their references, as the contract has it
|
|
1260
|
-
*
|
|
1261
|
-
* its demo, which it asks for as the example comes, before the learner opens them
|
|
1260
|
+
* What gives the files of the pictures, by their references, as the contract has it: a
|
|
1261
|
+
* task's statement's, and a worked example's — its statement's and every part's of
|
|
1262
|
+
* its demo, which it asks for as the example comes, before the learner opens them. A
|
|
1262
1263
|
* reference is asked for once, whichever pictures show it, and its file stays while the task or
|
|
1263
1264
|
* the example names it. Until a picture's file comes, or if it never does, its frame shows what
|
|
1264
1265
|
* it shows in words. A new function serves the references that have no file yet, and stops no
|
|
@@ -1274,7 +1275,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1274
1275
|
this.#pictures.media = media;
|
|
1275
1276
|
}
|
|
1276
1277
|
/**
|
|
1277
|
-
* The grid of the task from paper's sheet
|
|
1278
|
+
* The grid of the task from paper's sheet: `undefined` without a task from paper, and
|
|
1278
1279
|
* "dots" as one comes. The learner turns it by the element's button, which a `gridchange`
|
|
1279
1280
|
* tells; the consumer keeps it and gives it back, which tells nothing. A grid given before the
|
|
1280
1281
|
* task from paper is a TypeError, and so is one not of `PaperGrid`; `undefined` changes nothing.
|
|
@@ -1299,7 +1300,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1299
1300
|
this.#refresh();
|
|
1300
1301
|
}
|
|
1301
1302
|
/**
|
|
1302
|
-
* The history of writing
|
|
1303
|
+
* The history of writing: every stroke, erasing, clearing and undo on the sheet, in the
|
|
1303
1304
|
* order they landed, at the sheet's time — frozen, and the same array until the next action. The
|
|
1304
1305
|
* consumer keeps it, adding what `historychange` tells, and gives it back to open the sheet as it
|
|
1305
1306
|
* was: the strokes, and the actions undo takes back.
|
|
@@ -1313,8 +1314,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1313
1314
|
* event, the next stroke takes the next ID, and the tutor's marks go back on the strokes, or off,
|
|
1314
1315
|
* if the history has not their strokes. A history that is where the sheet's began loses what came
|
|
1315
1316
|
* after, and says so in the console. The task and the history are each the consumer's to give, in
|
|
1316
|
-
* either order. A worked example's sheet has the empty history alone: any other is a TypeError
|
|
1317
|
-
* (R42).
|
|
1317
|
+
* either order. A worked example's sheet has the empty history alone: any other is a TypeError.
|
|
1318
1318
|
*/
|
|
1319
1319
|
get history() {
|
|
1320
1320
|
return this.#work.history;
|
|
@@ -1339,7 +1339,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1339
1339
|
};
|
|
1340
1340
|
return;
|
|
1341
1341
|
}
|
|
1342
|
-
// A worked example's sheet is no one's to write on
|
|
1342
|
+
// A worked example's sheet is no one's to write on.
|
|
1343
1343
|
if (this.#example !== undefined) {
|
|
1344
1344
|
throw new TypeError(`<${TAG}> shows a worked example, whose sheet has no history of writing`);
|
|
1345
1345
|
}
|
|
@@ -1368,9 +1368,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1368
1368
|
/**
|
|
1369
1369
|
* Which answer slots the learner's strokes fill, per item, per slot, in the task's order, by the
|
|
1370
1370
|
* strokes `exportWork()` would take — not the stroke under way, but those under an eraser not
|
|
1371
|
-
* yet lifted. A workbook's boxes, each whether it holds one
|
|
1372
|
-
* or in none, by the rule
|
|
1373
|
-
* on it or the whole sheet, whether the sheet holds one
|
|
1371
|
+
* yet lifted. A workbook's boxes, each whether it holds one: a stroke is in one box
|
|
1372
|
+
* or in none, by the boxes' rule, and what is in none is the draft. A sheet's one answer anywhere
|
|
1373
|
+
* on it or the whole sheet, whether the sheet holds one. `null` for a sheet of choices,
|
|
1374
1374
|
* whose options app marks, for a sheet with no task, and for a worked example. Frozen, and the
|
|
1375
1375
|
* same array until a slot changes. An action on the sheet changes it before its
|
|
1376
1376
|
* `historychange`, and a task or a history given changes it with no event.
|
|
@@ -1379,20 +1379,20 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1379
1379
|
return this.#filled;
|
|
1380
1380
|
}
|
|
1381
1381
|
/**
|
|
1382
|
-
* The tutor's marks of one submission, with the context the element gave with its work
|
|
1383
|
-
*
|
|
1384
|
-
*
|
|
1385
|
-
*
|
|
1386
|
-
*
|
|
1387
|
-
*
|
|
1388
|
-
*
|
|
1389
|
-
*
|
|
1390
|
-
*
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1382
|
+
* The tutor's marks of one submission, with the context the element gave with its work: each a
|
|
1383
|
+
* frame where a group of strokes is, or a box on the crop the model saw, and on a workbook where
|
|
1384
|
+
* an answer cell is, by its item and its slot. A mark holds on to the strokes the model saw there
|
|
1385
|
+
* and is drawn around those of them the sheet shows, as they are now — a cell's around its box
|
|
1386
|
+
* too: new strokes do not move it, and when all of them are erased it is gone, till undo brings
|
|
1387
|
+
* them back. A box of a workbook that was empty is framed alone. A box that comes near no stroke,
|
|
1388
|
+
* and a cell on a sheet, which takes no zones, have no frame: the question is asked without one.
|
|
1389
|
+
* The type is spec's. A submission goes back to a sheet whose history holds its strokes, as its
|
|
1390
|
+
* digest tells, and a workbook's to a page of its boxes: one of other strokes or other boxes is a
|
|
1391
|
+
* TypeError, and so are marks given before the task and the history they hold on to, and marks
|
|
1392
|
+
* that are not marks. A new history, and a new page, put the marks back on their strokes, or take
|
|
1393
|
+
* them off. `undefined` takes the marks off. Every value is checked as it comes, and marks equal
|
|
1394
|
+
* to those shown write nothing. A worked example's sheet has nothing to mark: marks are a
|
|
1395
|
+
* TypeError there.
|
|
1396
1396
|
*/
|
|
1397
1397
|
get marks() {
|
|
1398
1398
|
return this.#marks;
|
|
@@ -1407,7 +1407,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1407
1407
|
this.#given = given;
|
|
1408
1408
|
this.#showMarks(shown);
|
|
1409
1409
|
}
|
|
1410
|
-
/** The element moved into another document: its root adopts that document's sheet
|
|
1410
|
+
/** The element moved into another document: its root adopts that document's sheet. */
|
|
1411
1411
|
adoptedCallback() {
|
|
1412
1412
|
if (this.shadowRoot !== null)
|
|
1413
1413
|
adoptStyle(this.shadowRoot);
|
|
@@ -1420,15 +1420,16 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1420
1420
|
this.#watchColours();
|
|
1421
1421
|
this.#pictures.connect();
|
|
1422
1422
|
this.#tracingPaper.connect();
|
|
1423
|
-
// The page's pen mode, on every sheet of it
|
|
1424
|
-
// made it is over: by then a pen that came down writes. The sheet tells the page whether it is
|
|
1423
|
+
// The page's pen mode, on every sheet of it. The bar shows a change once the event that
|
|
1424
|
+
// made it is over: by then a pen that came down writes. The sheet tells the page whether it is
|
|
1425
|
+
// written on, and hears when a stroke ends.
|
|
1425
1426
|
const unwatch = PEN_MODE.watch(() => queueMicrotask(() => this.#refresh()));
|
|
1426
1427
|
const unenlist = PEN_MODE.enlist(() => this.#writer() !== undefined);
|
|
1427
1428
|
this.#unwatchPen = () => {
|
|
1428
1429
|
unwatch();
|
|
1429
1430
|
unenlist();
|
|
1430
1431
|
};
|
|
1431
|
-
// The page's zoom, on every sheet of it
|
|
1432
|
+
// The page's zoom, on every sheet of it: it may have changed while the element was away.
|
|
1432
1433
|
this.#unwatchZoom = PAGE_ZOOM.watch(() => this.#zoomed());
|
|
1433
1434
|
// A page that grows or shrinks scrolls nothing, and neither does a window of another size.
|
|
1434
1435
|
this.#page.observe(document.documentElement);
|
|
@@ -1440,9 +1441,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1440
1441
|
}
|
|
1441
1442
|
/**
|
|
1442
1443
|
* The element's `lang` came, changed or went: its buttons and a workbook's boxes are labelled in
|
|
1443
|
-
* it, or in English for a language their labels are not in, and for none
|
|
1444
|
+
* it, or in English for a language their labels are not in, and for none. Or
|
|
1444
1445
|
* `tools-hidden` did: while the element has it, the bar is out of sight and of the accessibility
|
|
1445
|
-
* tree, as `app` hides it on a phone under its tutor's sheet
|
|
1446
|
+
* tree, as `app` hides it on a phone under its tutor's sheet. An attribute the
|
|
1446
1447
|
* element had before it was defined comes here just after the constructor, which reads no
|
|
1447
1448
|
* attribute.
|
|
1448
1449
|
*/
|
|
@@ -1460,7 +1461,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1460
1461
|
}
|
|
1461
1462
|
/**
|
|
1462
1463
|
* The demo's list says a box it fills in the labels' language, around its value, which is a node
|
|
1463
|
-
* of its own in the parts' language: "Box 1.2: " and "5"
|
|
1464
|
+
* of its own in the parts' language: "Box 1.2: " and "5"; its open items too, anew.
|
|
1464
1465
|
* Without `lang` the labels are English, as the element's own.
|
|
1465
1466
|
*/
|
|
1466
1467
|
#nameBoxes(tag = this.getAttribute("lang")) {
|
|
@@ -1474,15 +1475,15 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1474
1475
|
return { before, value, after, lang };
|
|
1475
1476
|
};
|
|
1476
1477
|
}
|
|
1477
|
-
/** The tracing paper's grip is named in the labels' language, and its tooltip says it
|
|
1478
|
+
/** The tracing paper's grip is named in the labels' language, and its tooltip says it. */
|
|
1478
1479
|
#nameGrip(tag = this.getAttribute("lang")) {
|
|
1479
1480
|
const { lang, labels } = labelsFor(tag);
|
|
1480
1481
|
this.#tracingPaper.label(labels, lang);
|
|
1481
1482
|
}
|
|
1482
1483
|
/**
|
|
1483
1484
|
* Takes back the last action on the sheet — the last stroke written, the last erasing, or the
|
|
1484
|
-
* clearing — and says whether there was one
|
|
1485
|
-
*
|
|
1485
|
+
* clearing — and says whether there was one, with a `historychange` if there was.
|
|
1486
|
+
* The element's Undo button calls it, and so may the consumer. A stroke under way
|
|
1486
1487
|
* stays: it lands when it ends. So does an erasing: what it came near leaves the sheet when it
|
|
1487
1488
|
* lifts, if it is on the sheet then.
|
|
1488
1489
|
*/
|
|
@@ -1494,8 +1495,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1494
1495
|
}
|
|
1495
1496
|
/**
|
|
1496
1497
|
* Takes every stroke off the sheet, an action that undo takes back, and says whether there were
|
|
1497
|
-
* any
|
|
1498
|
-
* so may the consumer
|
|
1498
|
+
* any, with a `historychange` if there were. The element's Clear button calls it, and
|
|
1499
|
+
* so may the consumer. A stroke under way stays: it lands when it ends.
|
|
1499
1500
|
*/
|
|
1500
1501
|
clear() {
|
|
1501
1502
|
const cleared = this.#work.clear(performance.now());
|
|
@@ -1504,17 +1505,17 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1504
1505
|
return cleared;
|
|
1505
1506
|
}
|
|
1506
1507
|
/**
|
|
1507
|
-
* The work for checking
|
|
1508
|
-
* digit the manifest asks for
|
|
1508
|
+
* The work for checking, when the consumer asks for it, at Check, at the height of a
|
|
1509
|
+
* digit the manifest asks for. On a sheet it is the crop of the strokes the sheet
|
|
1509
1510
|
* shows, its PNG, and the context of the submission — the crop's numbers, the groups and their
|
|
1510
|
-
* digest
|
|
1511
|
-
* its item and its slot, and the context — the table «box → stroke IDs» and its digest
|
|
1512
|
-
*
|
|
1513
|
-
* places to be checked
|
|
1511
|
+
* digest. On a workbook it is the crop of each filled box, by its strokes alone, with
|
|
1512
|
+
* its item and its slot, and the context — the table «box → stroke IDs» and its digest; the
|
|
1513
|
+
* draft goes nowhere. The consumer keeps the context, sends only the PNGs and their
|
|
1514
|
+
* places to be checked, and gives the context back with the tutor's marks. It is the
|
|
1514
1515
|
* sheet as it is when this is called: a stroke under way is not on it yet, while the strokes
|
|
1515
1516
|
* under an eraser not yet lifted still are, as `filled` has them. A sheet without strokes, and a
|
|
1516
1517
|
* workbook with no box filled, have no work to check, and the promise gives null (H3); so has a
|
|
1517
|
-
* worked example, whose sheet the learner does not write on
|
|
1518
|
+
* worked example, whose sheet the learner does not write on.
|
|
1518
1519
|
*/
|
|
1519
1520
|
async exportWork() {
|
|
1520
1521
|
if (this.#example !== undefined)
|
|
@@ -1555,23 +1556,23 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1555
1556
|
}
|
|
1556
1557
|
/**
|
|
1557
1558
|
* The picture of the work, for the `picture` of a stored work that app puts on the server, a
|
|
1558
|
-
* method of the agreement with app
|
|
1559
|
+
* method of the agreement with app: the PNG of the strokes the surface shows,
|
|
1559
1560
|
* with no condition — the sheet's page, or the workbook's whole page with its draft, and the ink
|
|
1560
|
-
* past the page, right and down, with the tracing paper where it lies
|
|
1561
|
+
* past the page, right and down, with the tracing paper where it lies: one pixel a unit,
|
|
1561
1562
|
* 1000 × 1400 for the page alone, and scaled down past the page to hold no more pixels than it,
|
|
1562
1563
|
* its size in its PNG's header —, whatever is filled and whether the work was sent to be checked
|
|
1563
|
-
* or not; an empty surface, and a worked example's, is white. The strokes are those
|
|
1564
|
-
* the history has them: not the stroke under way, but those under an
|
|
1565
|
-
* is the outline the screen fills, black on white with no theme and
|
|
1566
|
-
* paper the strokes of both layers, the tracing paper's where it
|
|
1567
|
-
* crop's picture laid in grey and multiplied
|
|
1568
|
-
*
|
|
1569
|
-
*
|
|
1570
|
-
*
|
|
1564
|
+
* or not; an empty surface, and a worked example's, is white. The strokes are those
|
|
1565
|
+
* `exportWork()` takes, as the history has them: not the stroke under way, but those under an
|
|
1566
|
+
* eraser not yet lifted. Each is the outline the screen fills, black on white with no theme and
|
|
1567
|
+
* no template — on a task from paper the strokes of both layers, the tracing paper's where it
|
|
1568
|
+
* lies, hidden or not, with the crop's picture laid in grey and multiplied —, and the pixels go
|
|
1569
|
+
* through the crop's encoder, grey a byte each: so the picture looks as the sheet does, and holds
|
|
1570
|
+
* at most 1,576,640 bytes, for the encoder spends at most 9 bits on a byte of a row, under the 4
|
|
1571
|
+
* MiB of a stored work.
|
|
1571
1572
|
*/
|
|
1572
1573
|
async exportPicture() {
|
|
1573
|
-
// A pixel a unit, the ink 3 px wide as on a screen of a pixel a unit, while the page and the
|
|
1574
|
-
// past it hold no more pixels than the page; scaled down to hold them past that
|
|
1574
|
+
// A pixel a unit, the ink 3 px wide as on a screen of a pixel a unit, while the page and the
|
|
1575
|
+
// ink past it hold no more pixels than the page; scaled down to hold them past that.
|
|
1575
1576
|
const reach = this.#inkReach();
|
|
1576
1577
|
const { width, height, scale } = pictureOf({
|
|
1577
1578
|
maxX: reach.maxX + INK_REACH,
|
|
@@ -1592,7 +1593,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1592
1593
|
for (const stroke of strokes) {
|
|
1593
1594
|
const traced = tracing !== undefined && work.onTracing(stroke.id);
|
|
1594
1595
|
const [x, y] = traced ? tracing.at : [0, 0];
|
|
1595
|
-
// A stroke of the tracing paper is as large as the paper's scale draws it
|
|
1596
|
+
// A stroke of the tracing paper is as large as the paper's scale draws it.
|
|
1596
1597
|
const by = traced ? scale * scaleIn(tracing) : scale;
|
|
1597
1598
|
context.setTransform(by, 0, 0, by, x * scale, y * scale);
|
|
1598
1599
|
context.fill(this.#finished(stroke).path);
|
|
@@ -1607,7 +1608,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1607
1608
|
for (let at = 0; at < gray.length; at++)
|
|
1608
1609
|
gray[at] = data[4 * at];
|
|
1609
1610
|
// A task from paper's crop lies over it where the tracing paper lies, shown or hidden, at the
|
|
1610
|
-
// picture's scale, as the crop of the work has it
|
|
1611
|
+
// picture's scale, as the crop of the work has it.
|
|
1611
1612
|
if (tracing !== undefined) {
|
|
1612
1613
|
const { size, gray: picture } = await this.#tracingPaper.read;
|
|
1613
1614
|
if (picture !== null) {
|
|
@@ -1675,7 +1676,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1675
1676
|
}
|
|
1676
1677
|
}
|
|
1677
1678
|
/**
|
|
1678
|
-
* A task's template, or a worked example's, in place of the last
|
|
1679
|
+
* A task's template, or a worked example's, in place of the last. The layer and the
|
|
1679
1680
|
* statement apart: a new grid or new lines leave the statement and its pictures as they are, and
|
|
1680
1681
|
* the other way round. A tool not allowed puts the pen back, with no event, and the row shows
|
|
1681
1682
|
* what it is of, by its name, and the tools allowed: only what has changed is written. Then the
|
|
@@ -1688,11 +1689,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1688
1689
|
this.#shownTemplate = template;
|
|
1689
1690
|
if (!sameLayer(template, shown)) {
|
|
1690
1691
|
this.#lay(template);
|
|
1691
|
-
// A page of other boxes, or of the other kind, puts the marks back or takes them off
|
|
1692
|
+
// A page of other boxes, or of the other kind, puts the marks back or takes them off.
|
|
1692
1693
|
this.#replace();
|
|
1693
1694
|
}
|
|
1694
1695
|
else if (this.#laid === undefined) {
|
|
1695
|
-
// The same grid may ask another answer: the sheet's strokes, or choices that app marks
|
|
1696
|
+
// The same grid may ask another answer: the sheet's strokes, or choices that app marks.
|
|
1696
1697
|
this.#fill();
|
|
1697
1698
|
}
|
|
1698
1699
|
if (!sameStatement(template, shown))
|
|
@@ -1704,14 +1705,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1704
1705
|
this.#regrow();
|
|
1705
1706
|
this.#refresh();
|
|
1706
1707
|
}
|
|
1707
|
-
/** Whether the sheet shown has a tool: the task's, and the hand on every sheet written on
|
|
1708
|
+
/** Whether the sheet shown has a tool: the task's, and the hand on every sheet written on. */
|
|
1708
1709
|
#allows(tool) {
|
|
1709
1710
|
if (tool === HAND)
|
|
1710
1711
|
return this.#example === undefined;
|
|
1711
1712
|
return this.#shownTemplate.tools.includes(tool);
|
|
1712
1713
|
}
|
|
1713
1714
|
/**
|
|
1714
|
-
* Whether the element may show a worked example now
|
|
1715
|
+
* Whether the element may show a worked example now: not while it shows a task, not on a
|
|
1715
1716
|
* sheet the learner has written on, and not while a stroke or an erasing is under way, which
|
|
1716
1717
|
* would land on a sheet that takes none. A TypeError says which.
|
|
1717
1718
|
*/
|
|
@@ -1730,7 +1731,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1730
1731
|
}
|
|
1731
1732
|
}
|
|
1732
1733
|
/**
|
|
1733
|
-
* The template's layer
|
|
1734
|
+
* The template's layer: a sheet's grid, which says nothing to a screen reader, or a
|
|
1734
1735
|
* workbook's lines, which it reads — a list of the items in the task's order, each its number,
|
|
1735
1736
|
* its text and its boxes, where the layout puts them.
|
|
1736
1737
|
*/
|
|
@@ -1740,8 +1741,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1740
1741
|
write(this.#template, "aria-hidden", workbook ? null : "true");
|
|
1741
1742
|
write(this.#template, "role", workbook ? "none" : null);
|
|
1742
1743
|
this.#lines.replaceChildren(...(workbook ? template.page.items.map(itemOf) : []));
|
|
1743
|
-
// A canvas of the other kind fills its answer slots anew: a workbook's are its own arrays, and
|
|
1744
|
-
// sheet's those all sheets share
|
|
1744
|
+
// A canvas of the other kind fills its answer slots anew: a workbook's are its own arrays, and
|
|
1745
|
+
// a sheet's those all sheets share.
|
|
1745
1746
|
if (workbook !== (this.#laid !== undefined))
|
|
1746
1747
|
this.#filled = null;
|
|
1747
1748
|
this.#laid = workbook ? template.page : undefined;
|
|
@@ -1755,10 +1756,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1755
1756
|
this.#markBoxes();
|
|
1756
1757
|
}
|
|
1757
1758
|
/**
|
|
1758
|
-
* Which answer slots the strokes fill, and whether that changed. A workbook's boxes by the
|
|
1759
|
-
*
|
|
1759
|
+
* Which answer slots the strokes fill, and whether that changed. A workbook's boxes by the boxes'
|
|
1760
|
+
* rule, each stroke's box worked out once: a new array, and the frames marked anew, only if a
|
|
1760
1761
|
* box changed. A sheet's one answer anywhere on it or the whole sheet by any stroke on it, or
|
|
1761
|
-
* nothing for a sheet of choices or with no task
|
|
1762
|
+
* nothing for a sheet of choices or with no task.
|
|
1762
1763
|
*/
|
|
1763
1764
|
#fill() {
|
|
1764
1765
|
const page = this.#laid;
|
|
@@ -1787,10 +1788,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1787
1788
|
return true;
|
|
1788
1789
|
}
|
|
1789
1790
|
/**
|
|
1790
|
-
* Each box of the lines as it now is
|
|
1791
|
+
* Each box of the lines as it now is: its frame, thicker when it is filled, and its
|
|
1791
1792
|
* name in the labels' language, by the element's `lang` — "Box" alone in its line, numbered by
|
|
1792
1793
|
* its slot among several, and "filled" when it is. A value a worked example's demo wrote in it is
|
|
1793
|
-
* no part of its name: its text after the frame says it, in the lines' language
|
|
1794
|
+
* no part of its name: its text after the frame says it, in the lines' language. Only
|
|
1794
1795
|
* what has changed is written.
|
|
1795
1796
|
*/
|
|
1796
1797
|
#markBoxes() {
|
|
@@ -1809,7 +1810,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1809
1810
|
}
|
|
1810
1811
|
/**
|
|
1811
1812
|
* The marks as they were checked when given, back on their strokes after a new history or a new
|
|
1812
|
-
* page, if those have their strokes and boxes, or else off, with no event
|
|
1813
|
+
* page, if those have their strokes and boxes, or else off, with no event.
|
|
1813
1814
|
*/
|
|
1814
1815
|
#replace() {
|
|
1815
1816
|
if (this.#given === undefined)
|
|
@@ -1836,7 +1837,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1836
1837
|
}
|
|
1837
1838
|
/**
|
|
1838
1839
|
* The marks of a submission, as `marksOf` checked them, that have a place on this sheet, each
|
|
1839
|
-
* with its name: a TypeError for a submission that is not this sheet's
|
|
1840
|
+
* with its name: a TypeError for a submission that is not this sheet's.
|
|
1840
1841
|
*/
|
|
1841
1842
|
#places(given) {
|
|
1842
1843
|
const cells = isWorkbook(this.#shownTemplate) ? this.#cells : null;
|
|
@@ -1891,13 +1892,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1891
1892
|
this.#request();
|
|
1892
1893
|
}
|
|
1893
1894
|
/**
|
|
1894
|
-
* One pointer at a time writes or erases
|
|
1895
|
-
* pen mode, or a mouse
|
|
1895
|
+
* One pointer at a time writes or erases, as the hands let it: a pen, a finger out of
|
|
1896
|
+
* pen mode, or a mouse. The primary button does what the tool says, and a pen's eraser
|
|
1896
1897
|
* erases — if the task allows the eraser: without it, the pen's eraser does nothing, for the
|
|
1897
|
-
* recorder takes the primary button alone
|
|
1898
|
+
* recorder takes the primary button alone.
|
|
1898
1899
|
*/
|
|
1899
1900
|
#down(event) {
|
|
1900
|
-
// A worked example's sheet takes no input
|
|
1901
|
+
// A worked example's sheet takes no input: the canvas takes no pointer then, and an event
|
|
1901
1902
|
// that a script sends it does nothing either, nor puts the page in pen mode.
|
|
1902
1903
|
if (this.#example !== undefined)
|
|
1903
1904
|
return;
|
|
@@ -1906,7 +1907,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1906
1907
|
this.#recorder.end(event.pointerId);
|
|
1907
1908
|
this.#eraser.end(event.pointerId);
|
|
1908
1909
|
// The hand moves the sheet under a pen, a finger or a mouse alike, and writes nothing: one
|
|
1909
|
-
// pointer at a time, and the others do nothing while it moves
|
|
1910
|
+
// pointer at a time, and the others do nothing while it moves.
|
|
1910
1911
|
if (this.#tool === HAND) {
|
|
1911
1912
|
if (this.#pan !== undefined)
|
|
1912
1913
|
return;
|
|
@@ -1918,9 +1919,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1918
1919
|
return;
|
|
1919
1920
|
}
|
|
1920
1921
|
const writes = this.#hands.down(contactOf(event));
|
|
1921
|
-
// The canvas holds on to every pointer that comes down on it until it lifts, writing or not:
|
|
1922
|
-
// moves and its lift come here, so that a stroke goes on beyond the canvas, two fingers
|
|
1923
|
-
// a palm stays one, and the hands forget no pointer that lifted elsewhere.
|
|
1922
|
+
// The canvas holds on to every pointer that comes down on it until it lifts, writing or not:
|
|
1923
|
+
// its moves and its lift come here, so that a stroke goes on beyond the canvas, two fingers
|
|
1924
|
+
// scroll, a palm stays one, and the hands forget no pointer that lifted elsewhere.
|
|
1924
1925
|
this.#capture(event.pointerId);
|
|
1925
1926
|
if (!writes)
|
|
1926
1927
|
return;
|
|
@@ -1931,7 +1932,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1931
1932
|
const erases = this.#shownTemplate.tools.includes("eraser") &&
|
|
1932
1933
|
(this.#tool === "eraser" || onSheetSample.button === ERASER_BUTTON);
|
|
1933
1934
|
// On a task from paper a press begun on the tracing paper in sight writes or erases on it, its
|
|
1934
|
-
// points from its corner; one begun elsewhere, on the sheet
|
|
1935
|
+
// points from its corner; one begun elsewhere, on the sheet.
|
|
1935
1936
|
const tracing = this.#tracing;
|
|
1936
1937
|
const size = this.#tracingPaper.size;
|
|
1937
1938
|
const scale = tracing === undefined ? 1 : scaleIn(tracing);
|
|
@@ -1939,7 +1940,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1939
1940
|
!tracing.hidden &&
|
|
1940
1941
|
this.#tracingPaper.ready &&
|
|
1941
1942
|
onTracing(onSheetSample, tracing.at, scaled(size, scale));
|
|
1942
|
-
// A press on the sheet lets the tracing paper go: its frame and bar of scale leave
|
|
1943
|
+
// A press on the sheet lets the tracing paper go: its frame and bar of scale leave.
|
|
1943
1944
|
this.#tracingPaper.letGo();
|
|
1944
1945
|
const layer = traced ? "tracing" : undefined;
|
|
1945
1946
|
if (erases)
|
|
@@ -2020,7 +2021,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2020
2021
|
}
|
|
2021
2022
|
/**
|
|
2022
2023
|
* A pointer lifted, or the device or the page took it from the sheet: the hands forget it, and a
|
|
2023
|
-
* gesture that ended, or the hand's move, lets go of what it scrolled
|
|
2024
|
+
* gesture that ended, or the hand's move, lets go of what it scrolled.
|
|
2024
2025
|
*/
|
|
2025
2026
|
#lifted(pointerId) {
|
|
2026
2027
|
if (this.#pan?.pointerId === pointerId)
|
|
@@ -2059,14 +2060,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2059
2060
|
return this.#eraser;
|
|
2060
2061
|
return undefined;
|
|
2061
2062
|
}
|
|
2062
|
-
/** The layer a pointer's stroke or erasing is on: the tracing paper's, or the sheet's
|
|
2063
|
+
/** The layer a pointer's stroke or erasing is on: the tracing paper's, or the sheet's. */
|
|
2063
2064
|
#layerOf(input) {
|
|
2064
2065
|
const on = input === this.#eraser ? this.#eraseOn : this.#writeOn;
|
|
2065
2066
|
return on === "tracing" ? "tracing" : undefined;
|
|
2066
2067
|
}
|
|
2067
2068
|
/**
|
|
2068
2069
|
* A pointer's place on the sheet, or on the tracing paper, `layer`, from its corner and kept to
|
|
2069
|
-
* it
|
|
2070
|
+
* it.
|
|
2070
2071
|
*/
|
|
2071
2072
|
#sample(event, screen, layer) {
|
|
2072
2073
|
const point = toSheet(screen, event.clientX - screen.left, event.clientY - screen.top);
|
|
@@ -2091,7 +2092,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2091
2092
|
* one on the screen, after whatever transform the page puts on the element. The container's
|
|
2092
2093
|
* rectangle gives the part of the canvas it shows: with the statement in sight, the canvas
|
|
2093
2094
|
* goes on below the container's bottom. The bar of buttons over the sheet takes what is under it
|
|
2094
|
-
* itself: a pointer there presses a button, and writes nothing
|
|
2095
|
+
* itself: a pointer there presses a button, and writes nothing.
|
|
2095
2096
|
*/
|
|
2096
2097
|
#view() {
|
|
2097
2098
|
const canvas = this.#canvas.getBoundingClientRect();
|
|
@@ -2113,7 +2114,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2113
2114
|
}
|
|
2114
2115
|
/**
|
|
2115
2116
|
* The sheet's top in the container's content, in CSS pixels as laid out: under the statement —
|
|
2116
|
-
* or, along `x`, its left
|
|
2117
|
+
* or, along `x`, its left.
|
|
2117
2118
|
*/
|
|
2118
2119
|
#sheetEdge(axis) {
|
|
2119
2120
|
const port = clientBoxOf(this.#viewport);
|
|
@@ -2137,7 +2138,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2137
2138
|
/**
|
|
2138
2139
|
* The statement and a demo's parts keep the element's own direction while the container runs
|
|
2139
2140
|
* left to right: the direction the element computes, by an attribute or by a style, as the last
|
|
2140
|
-
* layout read it
|
|
2141
|
+
* layout read it.
|
|
2141
2142
|
*/
|
|
2142
2143
|
#keepDirection() {
|
|
2143
2144
|
if (!this.isConnected)
|
|
@@ -2148,7 +2149,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2148
2149
|
}
|
|
2149
2150
|
}
|
|
2150
2151
|
/**
|
|
2151
|
-
* What the rail's CSS cannot know
|
|
2152
|
+
* What the rail's CSS cannot know: the height of what it sticks in — the scroller's, which
|
|
2152
2153
|
* it watches, or the window's —, from whose top it runs down to its bottom, below the consumer's
|
|
2153
2154
|
* --novatrail-canvas-top; and the element's width, which a worked example's row keeps within, as
|
|
2154
2155
|
* the rail is as wide as nothing. A band in pixels is taken as it changes; one in percent, of the
|
|
@@ -2192,12 +2193,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2192
2193
|
return within ? room.top + room.offset : Number.NEGATIVE_INFINITY;
|
|
2193
2194
|
}
|
|
2194
2195
|
/**
|
|
2195
|
-
* Two fingers, or the hand, moved right on the screen by `dx` CSS pixels and down it by `dy
|
|
2196
|
-
*
|
|
2197
|
-
* scrolls down, for the whole gesture, and its first step across what it scrolls across
|
|
2198
|
-
*
|
|
2199
|
-
*
|
|
2200
|
-
* at once.
|
|
2196
|
+
* Two fingers, or the hand, moved right on the screen by `dx` CSS pixels and down it by `dy`,
|
|
2197
|
+
* and what they scroll goes with them. The gesture's first step down chooses what it
|
|
2198
|
+
* scrolls down, for the whole gesture, and its first step across what it scrolls across: the
|
|
2199
|
+
* sheet's own container if it can go that way, or else the nearest ancestor of the element that
|
|
2200
|
+
* scrolls and can, or else the page. A container at its end hands the scroll on at the next
|
|
2201
|
+
* gesture, not within this one. The steps of an event add up, and its end scrolls them at once.
|
|
2201
2202
|
*/
|
|
2202
2203
|
#scroll(dx, dy, fresh) {
|
|
2203
2204
|
if (fresh) {
|
|
@@ -2233,7 +2234,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2233
2234
|
}
|
|
2234
2235
|
/**
|
|
2235
2236
|
* What scrolls on down the content, for `onward`, or back up it — or, along `x`, on right across
|
|
2236
|
-
* it or back left
|
|
2237
|
+
* it or back left.
|
|
2237
2238
|
*/
|
|
2238
2239
|
#scrollerFor(onward, axis = "y") {
|
|
2239
2240
|
if (scrollsOn(this.#viewport, onward, axis)) {
|
|
@@ -2254,7 +2255,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2254
2255
|
if (keeps === "contain" || keeps === "none")
|
|
2255
2256
|
return undefined;
|
|
2256
2257
|
}
|
|
2257
|
-
// A page that hides its overflow, as one under a modal does, a finger would not scroll: nor do
|
|
2258
|
+
// A page that hides its overflow, as one under a modal does, a finger would not scroll: nor do
|
|
2259
|
+
// two.
|
|
2258
2260
|
if (overflow === "hidden" || overflow === "clip")
|
|
2259
2261
|
return undefined;
|
|
2260
2262
|
const page = document.scrollingElement;
|
|
@@ -2264,8 +2266,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2264
2266
|
}
|
|
2265
2267
|
/**
|
|
2266
2268
|
* The stage takes the visible part of the sheet, and the canvas a pixel of its buffer for each
|
|
2267
|
-
* device pixel: its size on the screen times the density
|
|
2268
|
-
* frame. However far the sheet goes, the canvas is no larger than the container
|
|
2269
|
+
* device pixel: its size on the screen times the density. The layers follow in the same
|
|
2270
|
+
* frame. However far the sheet goes, the canvas is no larger than the container.
|
|
2269
2271
|
*/
|
|
2270
2272
|
#layout() {
|
|
2271
2273
|
// The content of a new size, or the container, may overflow it now, or no more.
|
|
@@ -2309,7 +2311,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2309
2311
|
this.#region();
|
|
2310
2312
|
}
|
|
2311
2313
|
/**
|
|
2312
|
-
* How far the sheet goes
|
|
2314
|
+
* How far the sheet goes: past the page, the ink and the tracing paper where it lies, by
|
|
2313
2315
|
* one view of the window more across and two down, at the window's own fit times the zoom,
|
|
2314
2316
|
* within the reach. A worked example's sheet is its page alone. The window's view and not the
|
|
2315
2317
|
* container's: the sheet is sized by its style, and a size that the container's observer gave
|
|
@@ -2350,7 +2352,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2350
2352
|
/**
|
|
2351
2353
|
* The ink, the tracing paper or the window went past the sheet's extent, or back: the sheet is
|
|
2352
2354
|
* sized anew by its style — the column as wide as the page's fit times the extent's share of the
|
|
2353
|
-
* page, and the sheet in the extent's proportions —, and laid out
|
|
2355
|
+
* page, and the sheet in the extent's proportions —, and laid out.
|
|
2354
2356
|
*/
|
|
2355
2357
|
#regrow() {
|
|
2356
2358
|
const zoom = this.#example === undefined ? PAGE_ZOOM.value : 1;
|
|
@@ -2372,7 +2374,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2372
2374
|
this.#layout();
|
|
2373
2375
|
}
|
|
2374
2376
|
/**
|
|
2375
|
-
* Zoom in or Zoom out was pressed
|
|
2377
|
+
* Zoom in or Zoom out was pressed: the page's zoom goes a quarter larger or smaller, and
|
|
2376
2378
|
* every sheet of the page is laid out by it — but not while a pointer writes or erases on one of
|
|
2377
2379
|
* them, for nothing moves under it.
|
|
2378
2380
|
*/
|
|
@@ -2393,7 +2395,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2393
2395
|
}
|
|
2394
2396
|
}
|
|
2395
2397
|
/**
|
|
2396
|
-
* The page's zoom has changed
|
|
2398
|
+
* The page's zoom has changed: the sheet is laid out by it at once, the point of the sheet
|
|
2397
2399
|
* under a pinch's middle, or else the one the last press held, or else under the middle of the
|
|
2398
2400
|
* part in sight, standing where it was on the screen, and the bar shows what the zoom can do now.
|
|
2399
2401
|
*/
|
|
@@ -2425,8 +2427,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2425
2427
|
return [left, top, right, bottom, scrollLeft, scrollTop].join(" ");
|
|
2426
2428
|
}
|
|
2427
2429
|
/**
|
|
2428
|
-
* The template's grid over the whole sheet, as far as it goes
|
|
2429
|
-
* paper's that the learner turns, none on a blank one
|
|
2430
|
+
* The template's grid over the whole sheet, as far as it goes: the task's, or a task from
|
|
2431
|
+
* paper's that the learner turns, none on a blank one; a workbook has its lines instead.
|
|
2430
2432
|
*/
|
|
2431
2433
|
#drawGrid() {
|
|
2432
2434
|
const template = this.#shownTemplate;
|
|
@@ -2477,7 +2479,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2477
2479
|
/**
|
|
2478
2480
|
* The work has changed — a stroke landed, an erasing, an undo, a clearing: the sheet is drawn
|
|
2479
2481
|
* anew, and whoever listens hears of it at once, the history already as it now is, with the
|
|
2480
|
-
* events it has gained
|
|
2482
|
+
* events it has gained. The event goes up from the element itself, and out of a consumer's
|
|
2481
2483
|
* own shadow tree too, should the element be in one. An action a listener takes while it hears is
|
|
2482
2484
|
* told of next, once every listener has heard of the one before: each hears the history's events
|
|
2483
2485
|
* in its order. A history given meanwhile is no action, and what it replaced is told of no more.
|
|
@@ -2507,7 +2509,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2507
2509
|
}
|
|
2508
2510
|
}
|
|
2509
2511
|
/**
|
|
2510
|
-
* The learner chose a tool with the element's own button
|
|
2512
|
+
* The learner chose a tool with the element's own button: it is the tool now, and whoever
|
|
2511
2513
|
* listens hears of it. A consumer that gives the tool follows it, or its next render would set
|
|
2512
2514
|
* back what the learner chose.
|
|
2513
2515
|
*/
|
|
@@ -2520,7 +2522,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2520
2522
|
this.dispatchEvent(new CustomEvent(TOOL_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2521
2523
|
}
|
|
2522
2524
|
/**
|
|
2523
|
-
* The learner turned the task from paper's grid with its button
|
|
2525
|
+
* The learner turned the task from paper's grid with its button: the next, round, and
|
|
2524
2526
|
* whoever listens hears of it. A consumer that gives the grid follows it.
|
|
2525
2527
|
*/
|
|
2526
2528
|
#turnGrid() {
|
|
@@ -2533,7 +2535,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2533
2535
|
this.dispatchEvent(new CustomEvent(GRID_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2534
2536
|
}
|
|
2535
2537
|
/**
|
|
2536
|
-
* The learner hid the tracing paper with the button atop the tools, or showed it again
|
|
2538
|
+
* The learner hid the tracing paper with the button atop the tools, or showed it again: its
|
|
2537
2539
|
* strokes go out of sight with it and stay in the history and in the work, and whoever listens
|
|
2538
2540
|
* hears of the new state. A stroke or an erasing under way on the paper ends where it is, as on a
|
|
2539
2541
|
* lost capture: the pointer goes on over a paper that is not there.
|
|
@@ -2550,7 +2552,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2550
2552
|
this.#tracingChanged();
|
|
2551
2553
|
}
|
|
2552
2554
|
/**
|
|
2553
|
-
* The learner's grip moves the tracing paper to a place, kept to the sheet whole
|
|
2555
|
+
* The learner's grip moves the tracing paper to a place, kept to the sheet whole: its
|
|
2554
2556
|
* strokes move with it, and the marks on them too. The move tells of itself once it is over.
|
|
2555
2557
|
*/
|
|
2556
2558
|
#moveTracing(to) {
|
|
@@ -2567,7 +2569,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2567
2569
|
this.#request();
|
|
2568
2570
|
return at;
|
|
2569
2571
|
}
|
|
2570
|
-
/** Ctrl or ⌘ with the wheel over the tracing paper in sight: a notch of its scale
|
|
2572
|
+
/** Ctrl or ⌘ with the wheel over the tracing paper in sight: a notch of its scale. */
|
|
2571
2573
|
#wheel(event) {
|
|
2572
2574
|
if (!(event.ctrlKey || event.metaKey) || event.deltaY === 0)
|
|
2573
2575
|
return;
|
|
@@ -2585,7 +2587,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2585
2587
|
this.#tracingPaper.wheel(event.deltaY < 0);
|
|
2586
2588
|
}
|
|
2587
2589
|
/**
|
|
2588
|
-
* The learner scales the tracing paper by a corner, the bar of scale or the wheel
|
|
2590
|
+
* The learner scales the tracing paper by a corner, the bar of scale or the wheel: to a
|
|
2589
2591
|
* place and a scale, kept to the rule and to the sheet whole; its strokes scale with it, and the
|
|
2590
2592
|
* marks on them too. The change tells of itself once it is over.
|
|
2591
2593
|
*/
|
|
@@ -2605,7 +2607,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2605
2607
|
return { at, scale };
|
|
2606
2608
|
}
|
|
2607
2609
|
/**
|
|
2608
|
-
* "Fit"
|
|
2610
|
+
* "Fit": the tracing paper as wide as the window shows the sheet right of the bar of tools,
|
|
2609
2611
|
* at the rule's place there, kept to the rule; down the window, centred, below the rule's top.
|
|
2610
2612
|
*/
|
|
2611
2613
|
#fitTracing() {
|
|
@@ -2626,13 +2628,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2626
2628
|
if (from === undefined || state === undefined || sameTracing(from, state))
|
|
2627
2629
|
return;
|
|
2628
2630
|
// The marks were placed by the strokes where they lay: a submission of the paper elsewhere is
|
|
2629
|
-
// not this sheet's any more, and they go
|
|
2631
|
+
// not this sheet's any more, and they go.
|
|
2630
2632
|
this.#replace();
|
|
2631
2633
|
this.#tracingChanged();
|
|
2632
2634
|
}
|
|
2633
2635
|
/**
|
|
2634
2636
|
* A stroke or an erasing under way on the tracing paper ends where it is, `end`, or goes, as on
|
|
2635
|
-
* `pointercancel`: the paper it was on goes out of sight or away
|
|
2637
|
+
* `pointercancel`: the paper it was on goes out of sight or away.
|
|
2636
2638
|
*/
|
|
2637
2639
|
#leaveTracing(end) {
|
|
2638
2640
|
const writer = this.#writeOn === "tracing" ? this.#recorder.pointer : undefined;
|
|
@@ -2652,7 +2654,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2652
2654
|
this.#eraseOn = undefined;
|
|
2653
2655
|
}
|
|
2654
2656
|
/**
|
|
2655
|
-
* The crop's picture is read, and the tracing paper has its size
|
|
2657
|
+
* The crop's picture is read, and the tracing paper has its size: a state the consumer gave,
|
|
2656
2658
|
* checked against the largest paper, that puts the paper of this size wholly off the sheet moves
|
|
2657
2659
|
* to the nearest place wholly on it, with its strokes and their marks. It tells nothing, as the
|
|
2658
2660
|
* state given did not.
|
|
@@ -2671,14 +2673,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2671
2673
|
}
|
|
2672
2674
|
this.#request();
|
|
2673
2675
|
}
|
|
2674
|
-
/** Whoever listens hears of the tracing paper's new state, which the learner chose
|
|
2676
|
+
/** Whoever listens hears of the tracing paper's new state, which the learner chose. */
|
|
2675
2677
|
#tracingChanged() {
|
|
2676
2678
|
const detail = this.#tracing;
|
|
2677
2679
|
this.dispatchEvent(new CustomEvent(TRACING_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2678
2680
|
}
|
|
2679
2681
|
/**
|
|
2680
|
-
* A stroke where it lies on the sheet: one of the tracing paper's moved to where the paper lies
|
|
2681
|
-
* its scale, once for each place
|
|
2682
|
+
* A stroke where it lies on the sheet: one of the tracing paper's moved to where the paper lies
|
|
2683
|
+
* at its scale, once for each place; the sheet's as it is.
|
|
2682
2684
|
*/
|
|
2683
2685
|
#onSheet(stroke, tracing) {
|
|
2684
2686
|
if (!this.#work.onTracing(stroke.id))
|
|
@@ -2697,11 +2699,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2697
2699
|
return placed;
|
|
2698
2700
|
}
|
|
2699
2701
|
/**
|
|
2700
|
-
* The learner opened the next part of the demo with the row's Next
|
|
2702
|
+
* The learner opened the next part of the demo with the row's Next. The list grows above
|
|
2701
2703
|
* the sheet, and the layout keeps a sheet scrolled into sight where it was at once, before the
|
|
2702
2704
|
* scroll of the container is heard; then the part comes into sight between the band and the row
|
|
2703
2705
|
* of glass, the region tells of it, and whoever listens hears of the new state. The focus stays
|
|
2704
|
-
* on Next, which opens the part after it. Nothing happens while the demo is hidden, or open
|
|
2706
|
+
* on Next, which opens the part after it. Nothing happens while the demo is hidden, or open
|
|
2707
|
+
* whole.
|
|
2705
2708
|
*/
|
|
2706
2709
|
#openNext() {
|
|
2707
2710
|
const example = this.#example;
|
|
@@ -2719,7 +2722,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2719
2722
|
this.#demoChanged();
|
|
2720
2723
|
}
|
|
2721
2724
|
/**
|
|
2722
|
-
* The learner hid the whole demo with the row's Demo, or showed it again
|
|
2725
|
+
* The learner hid the whole demo with the row's Demo, or showed it again: its open parts
|
|
2723
2726
|
* stay open, out of sight, and the region tells of none. A sheet scrolled into sight stays where
|
|
2724
2727
|
* it was, and nothing else scrolls.
|
|
2725
2728
|
*/
|
|
@@ -2734,7 +2737,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2734
2737
|
}
|
|
2735
2738
|
/**
|
|
2736
2739
|
* The demo as a state has it: the list, laid out at once, so that the sheet's place is the new
|
|
2737
|
-
* one before any scroll is heard
|
|
2740
|
+
* one before any scroll is heard, and the row.
|
|
2738
2741
|
*/
|
|
2739
2742
|
#showDemo(example, state) {
|
|
2740
2743
|
this.#demoState = state;
|
|
@@ -2744,11 +2747,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2744
2747
|
this.#refresh();
|
|
2745
2748
|
}
|
|
2746
2749
|
/**
|
|
2747
|
-
* The values a worked example's demo has written in the boxes of its workbook
|
|
2750
|
+
* The values a worked example's demo has written in the boxes of its workbook: each in
|
|
2748
2751
|
* the middle of its box, on the line's baseline, at the width the layout gives its text, as the
|
|
2749
2752
|
* lines' texts are; none while the demo is hidden. A value is a text of its own just after its
|
|
2750
2753
|
* box's frame, which a screen reader reads after the box, in the lines' language, as the lines'
|
|
2751
|
-
* texts are (
|
|
2754
|
+
* texts are (WCAG 3.1.2). Only what changed is written.
|
|
2752
2755
|
*/
|
|
2753
2756
|
#showFills(fills) {
|
|
2754
2757
|
const page = this.#laid;
|
|
@@ -2785,12 +2788,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2785
2788
|
text.textContent = value;
|
|
2786
2789
|
}
|
|
2787
2790
|
}
|
|
2788
|
-
/** Whoever listens hears of the demo's new state, which the learner chose
|
|
2791
|
+
/** Whoever listens hears of the demo's new state, which the learner chose. */
|
|
2789
2792
|
#demoChanged() {
|
|
2790
2793
|
const detail = this.#demoState;
|
|
2791
2794
|
this.dispatchEvent(new CustomEvent(DEMO_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2792
2795
|
}
|
|
2793
|
-
/** The part Next opens: the one after those open, while the demo is shown
|
|
2796
|
+
/** The part Next opens: the one after those open, while the demo is shown. */
|
|
2794
2797
|
#nextPart() {
|
|
2795
2798
|
const state = this.#demoState;
|
|
2796
2799
|
if (state === undefined || state.hidden)
|
|
@@ -2798,24 +2801,24 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2798
2801
|
return this.#example?.demo[state.opened];
|
|
2799
2802
|
}
|
|
2800
2803
|
/**
|
|
2801
|
-
* An item of the list, or an area of the sheet, comes into sight at once, as near as it is
|
|
2804
|
+
* An item of the list, or an area of the sheet, comes into sight at once, as near as it is,
|
|
2802
2805
|
* and then out from under the consumer's band, --novatrail-canvas-top, should the band cover
|
|
2803
2806
|
* where it came to: what scrolls back up goes back as far as the band covers it. A margin of
|
|
2804
2807
|
* scrolling would hold for every scroller of the chain alike — the sheet's container and the
|
|
2805
2808
|
* page. An area of the sheet taller than what is in sight comes by its top from below, but by its
|
|
2806
|
-
* bottom from above, and then the band's cover brings its top back into sight
|
|
2809
|
+
* bottom from above, and then the band's cover brings its top back into sight. The bar of
|
|
2807
2810
|
* buttons covers nothing at the top: it stands at the left edge, and a worked example's row at
|
|
2808
|
-
* the bottom, where a scroll margin keeps what comes from below above it
|
|
2811
|
+
* the bottom, where a scroll margin keeps what comes from below above it.
|
|
2809
2812
|
*/
|
|
2810
2813
|
#bringIntoSight(item) {
|
|
2811
2814
|
// A worked example's row of glass stands over the bottom of what is in sight: what comes into
|
|
2812
|
-
// sight from below stops 16 pixels above it
|
|
2815
|
+
// sight from below stops 16 pixels above it.
|
|
2813
2816
|
const { rail, row } = this.#tools;
|
|
2814
2817
|
const under = rail.hidden || row.hidden ? 0 : row.offsetHeight + 32;
|
|
2815
2818
|
item.style.setProperty("scroll-margin-bottom", `${under}px`);
|
|
2816
2819
|
item.scrollIntoView({ block: "nearest", behavior: "instant" });
|
|
2817
2820
|
// A scroller that comes to its top hands the rest on to the next. A scroller goes again only
|
|
2818
|
-
// while each of its scrolls leaves less covered than the last
|
|
2821
|
+
// while each of its scrolls leaves less covered than the last.
|
|
2819
2822
|
const covered = new Map();
|
|
2820
2823
|
for (;;) {
|
|
2821
2824
|
const latch = this.#scrollerFor(false);
|
|
@@ -2831,7 +2834,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2831
2834
|
}
|
|
2832
2835
|
/**
|
|
2833
2836
|
* The row of buttons as the sheet now is: the tools the task allows, the one in use, whether
|
|
2834
|
-
* undo and clearing have anything to do
|
|
2837
|
+
* undo and clearing have anything to do, and a worked example's demo.
|
|
2835
2838
|
*/
|
|
2836
2839
|
#refresh() {
|
|
2837
2840
|
const demo = this.#demoState;
|
|
@@ -2854,11 +2857,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2854
2857
|
/**
|
|
2855
2858
|
* The container as a region of its own, a stop of Tab and a name, while its content overflows
|
|
2856
2859
|
* it, and the keyboard scrolls it: in Safari a container that nothing in it can take the focus in
|
|
2857
|
-
* scrolls by no key without (
|
|
2860
|
+
* scrolls by no key without (WebKit's bug 277290). Without a height of its own the
|
|
2858
2861
|
* element scrolls with the page and has no stop of Tab, and neither has one whose task fits. A
|
|
2859
|
-
* container that holds the focus keeps all three till the focus leaves it, not the window
|
|
2862
|
+
* container that holds the focus keeps all three till the focus leaves it, not the window.
|
|
2860
2863
|
* Across, it scrolls while the sheet is wider than it, and an element without a height has a
|
|
2861
|
-
* region then too
|
|
2864
|
+
* region then too.
|
|
2862
2865
|
*/
|
|
2863
2866
|
#region() {
|
|
2864
2867
|
if (!this.isConnected)
|
|
@@ -2875,11 +2878,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2875
2878
|
* The region's name: the canvas kind's, or a worked example's, in the labels' language, which
|
|
2876
2879
|
* the row's buttons are named in. For a `lang` the labels are not in, the container is in
|
|
2877
2880
|
* theirs, English, and the column, all the container holds, in the element's: the name is said
|
|
2878
|
-
* in the language it is in, and the statement, the parts and the sheet in the element's
|
|
2881
|
+
* in the language it is in, and the statement, the parts and the sheet in the element's.
|
|
2879
2882
|
* With a `lang` the labels are in, the name is in the element's language already, and both are
|
|
2880
2883
|
* in it, by an attribute of their own: Firefox gives a shadow tree no language of its host, and
|
|
2881
2884
|
* WebKit takes no new one into the tree, though HTML has a node whose parent is a shadow root
|
|
2882
|
-
* take its host's
|
|
2885
|
+
* take its host's. Without a `lang` the element's language is the page's, which no
|
|
2883
2886
|
* attribute could name, and neither has one.
|
|
2884
2887
|
*/
|
|
2885
2888
|
#nameRegion() {
|
|
@@ -2891,7 +2894,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2891
2894
|
write(this.#viewport, "lang", apart ? lang : tag);
|
|
2892
2895
|
write(this.#column, "lang", tag);
|
|
2893
2896
|
}
|
|
2894
|
-
/** What the row of buttons is of, and is named by: a worked example, or the canvas kind
|
|
2897
|
+
/** What the row of buttons is of, and is named by: a worked example, or the canvas kind. */
|
|
2895
2898
|
#rowKind() {
|
|
2896
2899
|
if (this.#example !== undefined)
|
|
2897
2900
|
return "example";
|
|
@@ -2909,7 +2912,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2909
2912
|
}
|
|
2910
2913
|
/**
|
|
2911
2914
|
* The layers show the visible part of the sheet: each `<svg>` layer by its view box, in sheet
|
|
2912
|
-
* units, which the browser scales to the stage
|
|
2915
|
+
* units, which the browser scales to the stage. Before any is drawn, so that none goes on
|
|
2913
2916
|
* showing a part of the sheet the others have left.
|
|
2914
2917
|
*/
|
|
2915
2918
|
#place(screen) {
|
|
@@ -2934,7 +2937,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2934
2937
|
}
|
|
2935
2938
|
}
|
|
2936
2939
|
/**
|
|
2937
|
-
* The frames of the marks, around their strokes as the sheet shows them now
|
|
2940
|
+
* The frames of the marks, around their strokes as the sheet shows them now: off their
|
|
2938
2941
|
* points by the padding, in sheet units, and kept to the sheet by half the frame's line, so that
|
|
2939
2942
|
* a frame at its edge stays whole. A frame the stroke under way comes into fades till the stroke
|
|
2940
2943
|
* lands, and only what has changed is written.
|
|
@@ -2947,8 +2950,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2947
2950
|
const pending = this.#eraser.pending;
|
|
2948
2951
|
const tracing = this.#tracing;
|
|
2949
2952
|
const work = this.#work;
|
|
2950
|
-
// A stroke of the tracing paper is where the paper lies, and out of sight while it is hidden
|
|
2951
|
-
//
|
|
2953
|
+
// A stroke of the tracing paper is where the paper lies, and out of sight while it is hidden.
|
|
2954
|
+
// Its box moves with the paper, and the stroke is not copied for each place of a drag.
|
|
2952
2955
|
const onScreen = (id) => {
|
|
2953
2956
|
const stroke = pending.has(id) ? undefined : byId.get(id);
|
|
2954
2957
|
if (stroke === undefined)
|
|
@@ -2977,7 +2980,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2977
2980
|
else if (!mark.under) {
|
|
2978
2981
|
// A frame that came or moved while the stroke was under way is checked against all of it.
|
|
2979
2982
|
const points = sameBox(frame, mark.frame) ? fresh : this.#writing.stroke.points;
|
|
2980
|
-
// A stroke on the tracing paper holds its points from the paper's corner
|
|
2983
|
+
// A stroke on the tracing paper holds its points from the paper's corner.
|
|
2981
2984
|
const on = this.#writeOn === "tracing" ? this.#tracing : undefined;
|
|
2982
2985
|
const [dx, dy] = on?.at ?? [0, 0];
|
|
2983
2986
|
const by = on === undefined ? 1 : scaleIn(on);
|
|
@@ -3033,7 +3036,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
3033
3036
|
this.#writing.seen = live.points.length;
|
|
3034
3037
|
return fresh;
|
|
3035
3038
|
}
|
|
3036
|
-
/** The strokes on the sheet by ID: each action on the work gives a new array of them
|
|
3039
|
+
/** The strokes on the sheet by ID: each action on the work gives a new array of them. */
|
|
3037
3040
|
#byId() {
|
|
3038
3041
|
const strokes = this.#work.strokes;
|
|
3039
3042
|
if (this.#strokesById.strokes !== strokes) {
|
|
@@ -3053,7 +3056,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
3053
3056
|
* The layers in the visible part, and the strokes there, in device pixels: each finished stroke
|
|
3054
3057
|
* by the path it was given once, the stroke under way outlined anew. A stroke whose points lie
|
|
3055
3058
|
* far out of sight is not outlined till it comes into sight: a history given to the sheet may
|
|
3056
|
-
* hold thousands
|
|
3059
|
+
* hold thousands. What the eraser under way has come near is out of sight already, though
|
|
3057
3060
|
* still on the sheet until it lifts. The ink's colour is the canvas's, as the theme makes it.
|
|
3058
3061
|
*/
|
|
3059
3062
|
#draw() {
|
|
@@ -3079,7 +3082,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
3079
3082
|
const bottom = screen.vy + screen.height / screen.k;
|
|
3080
3083
|
const erasing = this.#eraser.pending;
|
|
3081
3084
|
// A task from paper's tracing paper: its strokes over the sheet's, moved to where it lies, and
|
|
3082
|
-
// none while it is hidden
|
|
3085
|
+
// none while it is hidden.
|
|
3083
3086
|
const tracing = this.#tracing;
|
|
3084
3087
|
const work = this.#work;
|
|
3085
3088
|
const shown = tracing !== undefined && !tracing.hidden;
|
|
@@ -3112,7 +3115,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
3112
3115
|
if (!shown)
|
|
3113
3116
|
return;
|
|
3114
3117
|
const [dx, dy] = tracing.at;
|
|
3115
|
-
// The paper's strokes are as large as its scale draws it, from its corner
|
|
3118
|
+
// The paper's strokes are as large as its scale draws it, from its corner.
|
|
3116
3119
|
const by = scaleIn(tracing);
|
|
3117
3120
|
context.setTransform(across * by, 0, 0, down * by, (dx - screen.vx) * across, (dy - screen.vy) * down);
|
|
3118
3121
|
for (const stroke of traced)
|
|
@@ -3152,7 +3155,7 @@ function near({ x, y }, box, reach) {
|
|
|
3152
3155
|
return (x >= box.minX - reach && x <= box.maxX + reach && y >= box.minY - reach && y <= box.maxY + reach);
|
|
3153
3156
|
}
|
|
3154
3157
|
/**
|
|
3155
|
-
* An item of a workbook's lines
|
|
3158
|
+
* An item of a workbook's lines: its number, then its text and its boxes in the order they
|
|
3156
3159
|
* are read, each where the layout put it. The item is an `<svg>` of its own place and size, which
|
|
3157
3160
|
* shows what it holds beyond its edges, and its parts lie from its origin: Firefox brings a group
|
|
3158
3161
|
* into view as a point at its origin, and only a box with a size whole.
|
|
@@ -3180,7 +3183,7 @@ function textOf({ text, left, baseline, width }, item) {
|
|
|
3180
3183
|
element.textContent = text;
|
|
3181
3184
|
return element;
|
|
3182
3185
|
}
|
|
3183
|
-
/** A box, a picture to a screen reader, which its name tells of
|
|
3186
|
+
/** A box, a picture to a screen reader, which its name tells of. */
|
|
3184
3187
|
function rectOf(box, item) {
|
|
3185
3188
|
const rect = document.createElementNS(SVG, "rect");
|
|
3186
3189
|
const { x, y } = fromItem(item, box.left, box.top);
|
|
@@ -3205,7 +3208,7 @@ function coalesced(event) {
|
|
|
3205
3208
|
const events = typeof event.getCoalescedEvents === "function" ? event.getCoalescedEvents() : [];
|
|
3206
3209
|
return events.length > 0 ? events : [event];
|
|
3207
3210
|
}
|
|
3208
|
-
/** What the hands see of a pointer event
|
|
3211
|
+
/** What the hands see of a pointer event: where on the screen, how big, when. */
|
|
3209
3212
|
function contactOf(event) {
|
|
3210
3213
|
return {
|
|
3211
3214
|
pointerId: event.pointerId,
|
|
@@ -3217,7 +3220,7 @@ function contactOf(event) {
|
|
|
3217
3220
|
time: event.timeStamp,
|
|
3218
3221
|
};
|
|
3219
3222
|
}
|
|
3220
|
-
/** The scroll an event's fingers owe a scroller, in whole pixels, if any: the rest waits
|
|
3223
|
+
/** The scroll an event's fingers owe a scroller, in whole pixels, if any: the rest waits. */
|
|
3221
3224
|
function owed(latch) {
|
|
3222
3225
|
if (!latch)
|
|
3223
3226
|
return undefined;
|
|
@@ -3347,7 +3350,7 @@ function parentOf(element) {
|
|
|
3347
3350
|
* An element's client box on the screen — what it shows of its content, within its borders and
|
|
3348
3351
|
* without its scroll bar — and how much the page scales it down the screen: 1 unless an ancestor
|
|
3349
3352
|
* transforms it. The sheet's container has one, and so has any ancestor the fingers or
|
|
3350
|
-
* the hand scroll
|
|
3353
|
+
* the hand scroll.
|
|
3351
3354
|
*/
|
|
3352
3355
|
function clientBoxOf(element) {
|
|
3353
3356
|
const box = element.getBoundingClientRect();
|
|
@@ -3360,7 +3363,7 @@ function clientBoxOf(element) {
|
|
|
3360
3363
|
return { left, top, right, bottom, across, down };
|
|
3361
3364
|
}
|
|
3362
3365
|
/**
|
|
3363
|
-
* How much the page scales an element down the screen, or across it along `x
|
|
3366
|
+
* How much the page scales an element down the screen, or across it along `x`: 1 unless an
|
|
3364
3367
|
* ancestor transforms it. `box` is its rectangle on the screen, when the caller has it already.
|
|
3365
3368
|
*/
|
|
3366
3369
|
function scaleOf(element, box, axis = "y") {
|