@altnovatrail/canvas 0.3.38 → 0.3.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/boxes.d.ts +7 -7
- package/lib/core/boxes.js +10 -10
- package/lib/core/clock.d.ts +5 -5
- package/lib/core/clock.js +5 -5
- package/lib/core/crop.d.ts +13 -13
- package/lib/core/crop.js +10 -10
- package/lib/core/eraser.d.ts +6 -6
- package/lib/core/eraser.js +6 -6
- package/lib/core/example.d.ts +6 -6
- package/lib/core/example.js +9 -9
- package/lib/core/fields.d.ts +1 -1
- package/lib/core/fields.js +1 -1
- package/lib/core/geometry.d.ts +6 -5
- package/lib/core/geometry.js +8 -6
- package/lib/core/grid.d.ts +3 -3
- package/lib/core/grid.js +3 -3
- package/lib/core/groups.d.ts +14 -14
- package/lib/core/groups.js +6 -6
- package/lib/core/hands.d.ts +24 -16
- package/lib/core/hands.js +66 -14
- package/lib/core/history.d.ts +9 -9
- package/lib/core/history.js +6 -6
- package/lib/core/index.js +8 -9
- package/lib/core/ink.js +3 -3
- package/lib/core/manifest.d.ts +3 -3
- package/lib/core/manifest.js +6 -6
- package/lib/core/marks.d.ts +39 -39
- package/lib/core/marks.js +34 -34
- package/lib/core/notation.d.ts +29 -0
- package/lib/core/notation.js +180 -0
- package/lib/core/outline.d.ts +3 -3
- package/lib/core/outline.js +6 -6
- package/lib/core/page.d.ts +7 -7
- package/lib/core/page.js +10 -10
- package/lib/core/png.d.ts +3 -3
- package/lib/core/png.js +3 -3
- package/lib/core/raster.d.ts +3 -3
- package/lib/core/raster.js +3 -3
- package/lib/core/recorder.d.ts +7 -7
- package/lib/core/recorder.js +7 -7
- package/lib/core/screen.d.ts +2 -2
- package/lib/core/screen.js +1 -1
- package/lib/core/sets.d.ts +1 -1
- package/lib/core/sets.js +1 -1
- package/lib/core/sheet.d.ts +3 -3
- package/lib/core/sheet.js +3 -3
- package/lib/core/submission.d.ts +24 -24
- package/lib/core/submission.js +21 -21
- package/lib/core/task.d.ts +17 -16
- package/lib/core/task.js +14 -13
- package/lib/core/tracing.d.ts +20 -20
- package/lib/core/tracing.js +20 -20
- package/lib/core/widths.d.ts +2 -2
- package/lib/core/widths.js +5 -5
- package/lib/core/work.d.ts +18 -18
- package/lib/core/work.js +21 -21
- package/lib/core/zoom.d.ts +34 -0
- package/lib/core/zoom.js +64 -0
- package/lib/element/icons.d.ts +19 -1
- package/lib/element/icons.js +24 -2
- package/lib/element/index.d.ts +87 -87
- package/lib/element/index.js +397 -295
- package/lib/element/labels.d.ts +21 -18
- package/lib/element/labels.js +15 -12
- package/lib/element/notation.d.ts +2 -0
- package/lib/element/notation.js +94 -0
- package/lib/element/parts.d.ts +2 -2
- package/lib/element/parts.js +6 -6
- package/lib/element/pictures.js +1 -1
- package/lib/element/probe.d.ts +2 -2
- package/lib/element/probe.js +3 -3
- package/lib/element/session.d.ts +3 -0
- package/lib/element/session.js +8 -4
- package/lib/element/statement.d.ts +2 -2
- package/lib/element/statement.js +6 -6
- package/lib/element/tools.d.ts +21 -18
- package/lib/element/tools.js +46 -30
- package/lib/element/tracing.js +58 -31
- package/package.json +3 -3
package/lib/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";
|
|
@@ -70,12 +69,13 @@ import { cellsForCheck, paperWorkForCheck, workForCheck } from "../core/submissi
|
|
|
70
69
|
import { HAND, isTool, isWorkbook, NO_TASK, sameLayer, sameStatement, taskOf, templateOf, wholeSheet, } from "../core/task.js";
|
|
71
70
|
import { boxOnSheet, isPaperGrid, keptOn, layOver, nextGrid, onSheet, onTracing, PAPER_GRIDS, readingOf, rulingsOf, sameTracing, scaled, scaleIn, TRACING, TRACING_START, toTracing, rectOf as tracingRect, scaleOf as tracingScaleOf, tracingStateOf, whollyOff, } from "../core/tracing.js";
|
|
72
71
|
import { nextIdOf, resumeOf, Work } from "../core/work.js";
|
|
72
|
+
import { ZOOM_MIN, ZOOM_STEP } from "../core/zoom.js";
|
|
73
73
|
import { placeOver, SVG, write } from "./attributes.js";
|
|
74
74
|
import { knows, labelsFor, say, sayAround } from "./labels.js";
|
|
75
75
|
import { Parts } from "./parts.js";
|
|
76
76
|
import { Pictures } from "./pictures.js";
|
|
77
77
|
import { attachProbe } from "./probe.js";
|
|
78
|
-
import { PEN_MODE } from "./session.js";
|
|
78
|
+
import { PAGE_ZOOM, PEN_MODE } from "./session.js";
|
|
79
79
|
import { Statement } from "./statement.js";
|
|
80
80
|
import { Tools } from "./tools.js";
|
|
81
81
|
import { TracingPaper } from "./tracing.js";
|
|
@@ -87,7 +87,7 @@ const INK = "#111";
|
|
|
87
87
|
const PAPER = "#fff";
|
|
88
88
|
/**
|
|
89
89
|
* The colour of the tool in use and of the focus on the bar unless the consumer's theme gives one,
|
|
90
|
-
* and the bar's glass: the interface mockup's
|
|
90
|
+
* and the bar's glass: the interface mockup's.
|
|
91
91
|
*/
|
|
92
92
|
const ACCENT = "#0071E3";
|
|
93
93
|
const GLASS = "rgba(255, 255, 255, 0.76)";
|
|
@@ -104,14 +104,14 @@ const TRACING_READ = "tracingread";
|
|
|
104
104
|
const GRID_CHANGE = "gridchange";
|
|
105
105
|
/**
|
|
106
106
|
* A task from paper's template: no statement, the pen and the eraser, and a dotted sheet, as the
|
|
107
|
-
* task comes, whose grid the learner turns
|
|
107
|
+
* task comes, whose grid the learner turns.
|
|
108
108
|
*/
|
|
109
109
|
const PAPER_TEMPLATE = Object.freeze({
|
|
110
110
|
grid: Object.freeze({ kind: "dots", step: TRACING.dots }),
|
|
111
111
|
statement: Object.freeze([]),
|
|
112
112
|
tools: NO_TASK.tools,
|
|
113
113
|
});
|
|
114
|
-
/** 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. */
|
|
115
115
|
const DEMO_IDS = { status: "demo-status", parts: "demo-parts" };
|
|
116
116
|
/**
|
|
117
117
|
* The colour of the tutor's frames unless the consumer's theme gives one: a blue, and not a red,
|
|
@@ -121,7 +121,7 @@ const MARK = "#2563eb";
|
|
|
121
121
|
/**
|
|
122
122
|
* The colours of a verdict's tick and cross, over its white halo: a green, and an amber rather than
|
|
123
123
|
* a red, for «not yet» is no failure; each holds more than 3:1 on white, and the halo holds them
|
|
124
|
-
* over any sheet or photo of a page
|
|
124
|
+
* over any sheet or photo of a page.
|
|
125
125
|
*/
|
|
126
126
|
const RIGHT = "#15803d";
|
|
127
127
|
const NOT_YET = "#b45309";
|
|
@@ -135,7 +135,7 @@ const CROSS = "M8 8l8 8M16 8l-8 8";
|
|
|
135
135
|
/**
|
|
136
136
|
* The colour of the tutor's wavy line of "Show where" unless the consumer's theme gives one: an
|
|
137
137
|
* orange, as the mockup's, 3.58:1 on white, over a white halo that holds it over any sheet or photo
|
|
138
|
-
* of a page
|
|
138
|
+
* of a page.
|
|
139
139
|
*/
|
|
140
140
|
const WAVY = "#e8590c";
|
|
141
141
|
/**
|
|
@@ -146,13 +146,13 @@ const WAVY_HALF = GRID_STEP / 4;
|
|
|
146
146
|
const WAVY_CREST = 3.5;
|
|
147
147
|
const WAVY_BELOW = 12;
|
|
148
148
|
const WAVY_REACH = 10;
|
|
149
|
-
/** 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. */
|
|
150
150
|
const MARK_PADDING = 10;
|
|
151
151
|
/** The rounding of a frame's corners, in sheet units. */
|
|
152
152
|
const MARK_CORNER = 6;
|
|
153
153
|
/**
|
|
154
154
|
* How near a stroke's ink the eraser takes it, in CSS pixels: the same on every screen, whatever
|
|
155
|
-
* the sheet's scale
|
|
155
|
+
* the sheet's scale.
|
|
156
156
|
*/
|
|
157
157
|
const ERASER_RADIUS_PX = 10;
|
|
158
158
|
// The statement and the sheet stand in a column of their own, and scroll in a container of their
|
|
@@ -161,18 +161,18 @@ const ERASER_RADIUS_PX = 10;
|
|
|
161
161
|
// sheet's left; the sheet goes on past it as far as `#extent` says, and the container scrolls it
|
|
162
162
|
// across too, left to right whatever the page's direction, while the statement and a demo's parts
|
|
163
163
|
// stay as wide as the page and stick to its left, in the element's own direction: they scroll down
|
|
164
|
-
// alone
|
|
164
|
+
// alone. The layers of the sheet stand in its visible part, the stage, which sticks to the
|
|
165
165
|
// container's top and left, and each shows what lies there, shifted in the frame the ink is drawn
|
|
166
|
-
// in
|
|
166
|
+
// in. Over the container, in the same cell of the frame's grid, stands the rail of the
|
|
167
167
|
// element's own buttons: a band as tall as the part of the element in sight and as wide as nothing,
|
|
168
168
|
// sticking to the top of whatever scrolls the element, as far down as the consumer's
|
|
169
169
|
// --novatrail-canvas-top says, and up to its bottom less --novatrail-canvas-pad-bottom, and in its
|
|
170
170
|
// middle, 16 pixels from the left edge, the bar of buttons: 52 pixels wide, round at its ends, of
|
|
171
171
|
// the mockup's glass — the fill the consumer's theme gives, blurred behind, or the paper alone
|
|
172
|
-
// 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
|
|
173
173
|
// band scrolls inside its glass (WCAG 1.4.10). A worked example has no bar, and its Next and Demo
|
|
174
174
|
// stand in a row of the same glass at the band's bottom, the consumer's buttons of the slot actions
|
|
175
|
-
// after them
|
|
175
|
+
// after them. The tool in use is filled with the accent at an eighth, its icon in the accent;
|
|
176
176
|
// a button in focus shows a ring in the accent; an unavailable one is paler by its colour, not its
|
|
177
177
|
// opacity, which would pale the ring too (WCAG 2.4.7, 1.4.11). A button's tooltip stands beside it,
|
|
178
178
|
// white on near-black, as the mockup has it. Nothing in the element moves but the scrolling, which
|
|
@@ -180,28 +180,30 @@ const ERASER_RADIUS_PX = 10;
|
|
|
180
180
|
// unless it is given a height: then the statement and the sheet scroll in it, under the bar. A
|
|
181
181
|
// consumer whose own bars float over the element's top and bottom says how far by
|
|
182
182
|
// --novatrail-canvas-pad-top and -bottom: the statement starts below the first, and the sheet
|
|
183
|
-
// scrolls up past the second
|
|
183
|
+
// scrolls up past the second. A worked example's open parts stand between the statement and
|
|
184
184
|
// the sheet, and the region that tells of them is out of sight, but not out of the tree a screen
|
|
185
|
-
// 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
|
|
186
186
|
// its item's line, from its top, so that the item's number stands at the top too, as a paragraph's
|
|
187
187
|
// does, and not at the picture's bottom. A picture on an area of the sheet stands on the layer of
|
|
188
188
|
// the author's demo, and the sheet scrolls to a hidden box of the area in its own flow, which
|
|
189
|
-
// neither paints nor takes a pointer
|
|
189
|
+
// neither paints nor takes a pointer. On the canvas the browser neither scrolls nor zooms:
|
|
190
190
|
// the pointer writes, or with the hand moves the sheet, and two fingers scroll by the element's own
|
|
191
|
-
// code
|
|
191
|
+
// code, and in pen mode one finger too. The canvas and the buttons take pointer
|
|
192
192
|
// events only as the element does: a consumer's pointer-events: none on the element stops the
|
|
193
|
-
// writing and the buttons' pointer, though not their keys
|
|
193
|
+
// writing and the buttons' pointer, though not their keys. A worked example's canvas
|
|
194
194
|
// takes no pointer at all: a finger or a pen on its sheet scrolls, and zooms, as the browser does
|
|
195
|
-
// on the statement, and a long press or a right click opens no menu over the sheet all the same
|
|
196
|
-
//
|
|
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
|
|
197
197
|
// forced colours the system's colours stand in for them. The element is horizontal whatever writing
|
|
198
|
-
// mode the page is in: a sheet has no other
|
|
198
|
+
// mode the page is in: a sheet has no other.
|
|
199
199
|
//
|
|
200
200
|
// A workbook's lines are printed in the ink's colour and the consumer's font, and nothing else the
|
|
201
201
|
// element inherits — spacing, weight, transforms, the direction — moves them: `all: initial` takes
|
|
202
|
-
// 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,
|
|
203
203
|
// on whole device pixels: an antialiased line of one pixel would lose its contrast. A filled box's
|
|
204
|
-
// 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
|
|
205
|
+
// is three pixels across at the fit and above it, and smaller by the zoom below it, so that a sheet
|
|
206
|
+
// zoomed out is no field of dots.
|
|
205
207
|
const STYLE = `
|
|
206
208
|
:host { display: flex; flex-direction: column; isolation: isolate; writing-mode: horizontal-tb; }
|
|
207
209
|
:host([hidden]) { display: none; }
|
|
@@ -296,11 +298,13 @@ const STYLE = `
|
|
|
296
298
|
display: block; outline: 2px solid var(--novatrail-canvas-ink, ${INK}); outline-offset: -2px;
|
|
297
299
|
}
|
|
298
300
|
.column {
|
|
299
|
-
position: relative;
|
|
301
|
+
position: relative;
|
|
302
|
+
width: calc(min(100%, ${K_MAX * SHEET.width}px) * var(--zoom, 1) * var(--across, 1));
|
|
300
303
|
padding-block: var(--novatrail-canvas-pad-top, 0px) var(--novatrail-canvas-pad-bottom, 0px);
|
|
301
304
|
}
|
|
302
305
|
.statement, .parts {
|
|
303
|
-
position: sticky; left: 0; box-sizing: border-box;
|
|
306
|
+
position: sticky; left: 0; box-sizing: border-box;
|
|
307
|
+
width: calc(100% / (var(--zoom, 1) * var(--across, 1)));
|
|
304
308
|
direction: var(--direction, ltr);
|
|
305
309
|
}
|
|
306
310
|
.statement { padding: 0 0 12px; overflow-wrap: break-word; }
|
|
@@ -349,7 +353,7 @@ const STYLE = `
|
|
|
349
353
|
fill: none; stroke: var(--novatrail-canvas-grid, #d3dbe5); stroke-width: 1px;
|
|
350
354
|
vector-effect: non-scaling-stroke;
|
|
351
355
|
}
|
|
352
|
-
.grid.dots { stroke-width: 3px; stroke-linecap: round; }
|
|
356
|
+
.grid.dots { stroke-width: calc(3px * min(1, var(--zoom, 1))); stroke-linecap: round; }
|
|
353
357
|
.print {
|
|
354
358
|
all: initial; font-family: inherit; visibility: inherit; pointer-events: none; direction: ltr;
|
|
355
359
|
font-variant-numeric: tabular-nums; font-size: ${LAYOUT.size}px;
|
|
@@ -399,10 +403,14 @@ canvas {
|
|
|
399
403
|
color: var(--novatrail-canvas-ink, ${INK});
|
|
400
404
|
}
|
|
401
405
|
.statements .slot {
|
|
402
|
-
|
|
403
|
-
margin: 0 0.18em; vertical-align: -0.22em; border-radius: 0.2em;
|
|
406
|
+
box-sizing: border-box; border-radius: 0.2em;
|
|
404
407
|
border: max(2px, 0.04em) dashed var(--novatrail-canvas-accent, ${ACCENT});
|
|
405
408
|
}
|
|
409
|
+
.statements span.slot {
|
|
410
|
+
display: inline-block; width: 1.08em; height: 1.08em; margin: 0 0.18em; vertical-align: -0.22em;
|
|
411
|
+
}
|
|
412
|
+
.statements mspace.slot { margin: 0 0.1em; }
|
|
413
|
+
.statements math { font-family: inherit; font-size: inherit; color: inherit; }
|
|
406
414
|
.scan {
|
|
407
415
|
position: absolute; inset: 0; overflow: hidden;
|
|
408
416
|
background: color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 4%, transparent);
|
|
@@ -411,9 +419,13 @@ canvas {
|
|
|
411
419
|
position: absolute; top: 0; bottom: 0; left: -30%; width: 30%;
|
|
412
420
|
background: linear-gradient(90deg, transparent,
|
|
413
421
|
color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 18%, transparent), transparent);
|
|
414
|
-
border-right: 2px solid color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 60%, transparent);
|
|
415
422
|
left: 35%;
|
|
416
423
|
}
|
|
424
|
+
/* The line runs through the middle of its glow, so the glow is the same on both sides of it. */
|
|
425
|
+
.scan i::after {
|
|
426
|
+
content: ""; position: absolute; top: 0; bottom: 0; left: calc(50% - 1px); width: 2px;
|
|
427
|
+
background: color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 60%, transparent);
|
|
428
|
+
}
|
|
417
429
|
@keyframes novatrail-scan { from { left: -30%; } to { left: 100%; } }
|
|
418
430
|
@keyframes novatrail-spin { to { transform: rotate(360deg); } }
|
|
419
431
|
.tracing-frame {
|
|
@@ -504,7 +516,8 @@ canvas {
|
|
|
504
516
|
.statements { color: CanvasText; }
|
|
505
517
|
.statements .slot { border-color: CanvasText; }
|
|
506
518
|
.scan { background: transparent; }
|
|
507
|
-
.scan i { background: transparent;
|
|
519
|
+
.scan i { background: transparent; }
|
|
520
|
+
.scan i::after { background: Highlight; }
|
|
508
521
|
.stage > .tracing-sign, .stage > .tracing-sign[data-shows] {
|
|
509
522
|
background: Canvas; color: CanvasText; border: 1px solid CanvasText;
|
|
510
523
|
}
|
|
@@ -532,7 +545,7 @@ const sheets = new WeakMap();
|
|
|
532
545
|
* Gives the element's shadow root its style, as a sheet the root adopts, and not a `<style>` in
|
|
533
546
|
* its tree: a consumer's content security policy that allows no inline style, as app's
|
|
534
547
|
* `style-src 'self'`, blocks the one and not the other, and the element asks of the policy only
|
|
535
|
-
* `img-src blob:` (R51
|
|
548
|
+
* `img-src blob:` (R51). A root adopts only a sheet made for its own document, by that
|
|
536
549
|
* document's window, and an element moved into another document comes there without its sheets:
|
|
537
550
|
* it adopts that document's sheet then. A document without a window, which can make no sheet,
|
|
538
551
|
* leaves the element unstyled till it comes into one that can.
|
|
@@ -560,7 +573,7 @@ function svgLayer(name) {
|
|
|
560
573
|
}
|
|
561
574
|
/**
|
|
562
575
|
* The layer of the tutor's marks, over the work: a screen reader reads each mark by its name, and
|
|
563
|
-
* the layer itself is no picture of its own
|
|
576
|
+
* the layer itself is no picture of its own.
|
|
564
577
|
*/
|
|
565
578
|
function marksLayer() {
|
|
566
579
|
const svg = svgLayer("marks");
|
|
@@ -575,7 +588,7 @@ function frameNode() {
|
|
|
575
588
|
return rect;
|
|
576
589
|
}
|
|
577
590
|
/**
|
|
578
|
-
* 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
|
|
579
592
|
* that its place scales.
|
|
580
593
|
*/
|
|
581
594
|
function verdictNode(correct) {
|
|
@@ -593,7 +606,7 @@ function verdictNode(correct) {
|
|
|
593
606
|
return g;
|
|
594
607
|
}
|
|
595
608
|
/**
|
|
596
|
-
* The wavy line of "Show where"
|
|
609
|
+
* The wavy line of "Show where": the line over a wider white one, its halo, both
|
|
597
610
|
* of the path the marks give them.
|
|
598
611
|
*/
|
|
599
612
|
function wavyNode() {
|
|
@@ -650,35 +663,35 @@ function htmlLayer(name) {
|
|
|
650
663
|
return div;
|
|
651
664
|
}
|
|
652
665
|
/**
|
|
653
|
-
* The element `<novatrail-canvas>`: the contract's `CanvasElement
|
|
666
|
+
* The element `<novatrail-canvas>`: the contract's `CanvasElement`, and beyond it the
|
|
654
667
|
* commands undo and clear, which the contract does not name.
|
|
655
668
|
*/
|
|
656
669
|
export class NovatrailCanvas extends HTMLElement {
|
|
657
670
|
/**
|
|
658
671
|
* The wrapper, which does not scroll, of the container that scrolls and of the ring of its focus
|
|
659
672
|
* over it: an outline of the container itself would stand under the sheet's paper and stage,
|
|
660
|
-
* which are positioned in it
|
|
673
|
+
* which are positioned in it.
|
|
661
674
|
*/
|
|
662
675
|
#wrapper = document.createElement("div");
|
|
663
676
|
#viewport = document.createElement("div");
|
|
664
677
|
#ring = document.createElement("div");
|
|
665
678
|
#column = document.createElement("div");
|
|
666
679
|
#sheet = document.createElement("div");
|
|
667
|
-
/** 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. */
|
|
668
681
|
#stage = document.createElement("div");
|
|
669
|
-
/** 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. */
|
|
670
683
|
#template = svgLayer("template");
|
|
671
684
|
#grid = document.createElementNS(SVG, "path");
|
|
672
|
-
/** 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. */
|
|
673
686
|
#above = document.createElementNS(SVG, "svg");
|
|
674
687
|
#below = document.createElementNS(SVG, "svg");
|
|
675
688
|
#print = document.createElementNS(SVG, "g");
|
|
676
689
|
#lines = document.createElementNS(SVG, "g");
|
|
677
|
-
/** The module's widget, from stage 4
|
|
690
|
+
/** The module's widget, from stage 4: empty till then. */
|
|
678
691
|
#widget = htmlLayer("widget");
|
|
679
|
-
/** 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. */
|
|
680
693
|
#show = svgLayer("show");
|
|
681
|
-
/** 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. */
|
|
682
695
|
#sketch = svgLayer("sketch");
|
|
683
696
|
/** The learner's work: the ink. */
|
|
684
697
|
#canvas = document.createElement("canvas");
|
|
@@ -686,23 +699,24 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
686
699
|
#context = this.#canvas.getContext("2d");
|
|
687
700
|
/** The canvas's style as it is computed, read live: its colour is the ink's on the screen. */
|
|
688
701
|
#canvasStyle = getComputedStyle(this.#canvas);
|
|
689
|
-
/** 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. */
|
|
690
703
|
#pictures = new Pictures();
|
|
691
|
-
/** The task's statement, above the sheet
|
|
704
|
+
/** The task's statement, above the sheet. */
|
|
692
705
|
#statement = new Statement(this.#pictures);
|
|
693
|
-
/** 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. */
|
|
694
707
|
#parts = new Parts(DEMO_IDS, this.#pictures);
|
|
695
|
-
/** 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. */
|
|
696
709
|
#tools = new Tools({
|
|
697
710
|
choose: (tool) => this.#choose(tool),
|
|
698
711
|
undo: () => this.undo(),
|
|
699
712
|
clear: () => this.clear(),
|
|
713
|
+
zoom: (larger) => this.#zoomBy(larger),
|
|
700
714
|
turnGrid: () => this.#turnGrid(),
|
|
701
715
|
next: () => this.#openNext(),
|
|
702
716
|
toggle: () => this.#toggleDemo(),
|
|
703
717
|
trace: () => this.#trace(),
|
|
704
718
|
}, DEMO_IDS);
|
|
705
|
-
/** 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. */
|
|
706
720
|
#tracingPaper = new TracingPaper({
|
|
707
721
|
move: (at) => this.#moveTracing(at),
|
|
708
722
|
resize: (at, scale) => this.#resizeTracing(at, scale),
|
|
@@ -710,23 +724,23 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
710
724
|
moved: () => this.#tracingMoved(),
|
|
711
725
|
read: () => this.dispatchEvent(new CustomEvent(TRACING_READ, { bubbles: true, composed: true, detail: null })),
|
|
712
726
|
});
|
|
713
|
-
/** 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. */
|
|
714
728
|
#reading;
|
|
715
|
-
/** 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. */
|
|
716
730
|
#paper;
|
|
717
731
|
#tracing;
|
|
718
732
|
/** The tracing paper's state the learner's move began at: the move tells only if it changed it. */
|
|
719
733
|
#moveFrom;
|
|
720
|
-
/** 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. */
|
|
721
735
|
#writeOn;
|
|
722
736
|
#eraseOn;
|
|
723
737
|
/** Each stroke of the tracing paper where it lies on the sheet, for the place it was moved to. */
|
|
724
738
|
#placed = new WeakMap();
|
|
725
|
-
/** The sheet's clock, for its strokes and its actions alike
|
|
739
|
+
/** The sheet's clock, for its strokes and its actions alike. */
|
|
726
740
|
#clock = new Clock();
|
|
727
741
|
/**
|
|
728
|
-
* The strokes on the sheet, the actions undo takes back and the history of writing
|
|
729
|
-
* 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.
|
|
730
744
|
*/
|
|
731
745
|
#work = new Work(this.#clock);
|
|
732
746
|
/** How many events of the history `historychange` has told of, and whether it is telling now. */
|
|
@@ -743,18 +757,19 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
743
757
|
this.#changed();
|
|
744
758
|
});
|
|
745
759
|
/**
|
|
746
|
-
* The hands on the sheet
|
|
760
|
+
* The hands on the sheet: which pointer may write, which is a palm, and which two fingers
|
|
747
761
|
* scroll, in the page's pen mode. The recorder and the eraser say which pointer writes.
|
|
748
762
|
*/
|
|
749
763
|
#hands = new Hands({
|
|
750
764
|
writer: () => this.#writer(),
|
|
751
765
|
drop: (pointerId) => this.#drop(pointerId),
|
|
752
766
|
scroll: (dx, dy, fresh) => this.#scroll(dx, dy, fresh),
|
|
767
|
+
zoom: (ratio, x, y) => this.#pinch(ratio, x, y),
|
|
753
768
|
across: () => overflowOf(this.#viewport, "x") > EDGE,
|
|
754
769
|
}, PEN_MODE);
|
|
755
770
|
/**
|
|
756
771
|
* What two fingers, or the hand, scroll in the gesture under way, down and across, each chosen at
|
|
757
|
-
* the first step that goes along its axis
|
|
772
|
+
* the first step that goes along its axis: undefined till then, and null when nothing
|
|
758
773
|
* scrolls so.
|
|
759
774
|
*/
|
|
760
775
|
#latch;
|
|
@@ -765,23 +780,35 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
765
780
|
this.#fit();
|
|
766
781
|
};
|
|
767
782
|
#page = new ResizeObserver(this.#resized);
|
|
768
|
-
/** 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. */
|
|
769
784
|
#rewindowed = () => this.#regrow();
|
|
770
785
|
/** What the bar's rail sticks in, when a scroller of the page's: its height is the rail's room. */
|
|
771
786
|
#port = null;
|
|
772
787
|
#ported = new ResizeObserver(() => this.#fit());
|
|
773
788
|
#unwatchPen;
|
|
789
|
+
#unwatchZoom;
|
|
790
|
+
/** The zoom the sheet is laid out by: the page's, and a worked example's 1. */
|
|
791
|
+
#zoom = 1;
|
|
792
|
+
/** Where on the screen a pinch zooms about, while it sets the page's zoom. */
|
|
793
|
+
#anchor;
|
|
794
|
+
/**
|
|
795
|
+
* The point of the sheet a press zoomed about, where on the screen it stood, and where the press
|
|
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.
|
|
799
|
+
*/
|
|
800
|
+
#held;
|
|
774
801
|
#tool = "pen";
|
|
775
|
-
/** 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. */
|
|
776
803
|
#pan;
|
|
777
|
-
/** A task from paper's grid, the learner's
|
|
804
|
+
/** A task from paper's grid, the learner's. */
|
|
778
805
|
#paperGrid = "dots";
|
|
779
|
-
/** 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. */
|
|
780
807
|
#extent = SHEET;
|
|
781
808
|
/** The grid's path as last drawn: its rulings and the extent they cover. */
|
|
782
809
|
#gridDrawn = "";
|
|
783
810
|
#task;
|
|
784
|
-
/** 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. */
|
|
785
812
|
#workedExample;
|
|
786
813
|
#example;
|
|
787
814
|
/** How far the learner has gone through the example's demo, frozen, or undefined without one. */
|
|
@@ -789,25 +816,25 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
789
816
|
#shownTemplate = NO_TASK;
|
|
790
817
|
/**
|
|
791
818
|
* A workbook's page, its boxes in the task's order and their frames, and the box each stroke is
|
|
792
|
-
* 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.
|
|
793
820
|
*/
|
|
794
821
|
#laid;
|
|
795
822
|
#cells = [];
|
|
796
823
|
#rects = [];
|
|
797
824
|
/**
|
|
798
825
|
* The texts of the values a worked example's demo has written in its boxes, one for each frame
|
|
799
|
-
* that has had one
|
|
826
|
+
* that has had one.
|
|
800
827
|
*/
|
|
801
828
|
#values = [];
|
|
802
829
|
#taken = new WeakMap();
|
|
803
|
-
/** 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. */
|
|
804
831
|
#filled = null;
|
|
805
|
-
/** 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. */
|
|
806
833
|
#whole = false;
|
|
807
|
-
/** 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. */
|
|
808
835
|
#manifest;
|
|
809
836
|
#settings = NO_MANIFEST;
|
|
810
|
-
/** 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. */
|
|
811
838
|
#marks;
|
|
812
839
|
/** The marks as they were checked when given: a new history places these, whatever became of those. */
|
|
813
840
|
#given;
|
|
@@ -822,11 +849,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
822
849
|
* strokes are the same array.
|
|
823
850
|
*/
|
|
824
851
|
#strokesById = { strokes: [], byId: new Map() };
|
|
825
|
-
/** 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. */
|
|
826
853
|
#pointBoxes = new WeakMap();
|
|
827
854
|
/** The stroke under way, and how many of its points the marks have been checked against. */
|
|
828
855
|
#writing;
|
|
829
|
-
/** The path of each finished stroke, outlined once
|
|
856
|
+
/** The path of each finished stroke, outlined once. */
|
|
830
857
|
#inks = new WeakMap();
|
|
831
858
|
#resize = new ResizeObserver((entries) => {
|
|
832
859
|
for (const entry of entries) {
|
|
@@ -849,7 +876,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
849
876
|
*/
|
|
850
877
|
#k = 0;
|
|
851
878
|
#sheetAt = 0;
|
|
852
|
-
/** 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. */
|
|
853
880
|
#sheetAtX = 0;
|
|
854
881
|
/** The top and the left of the visible part, in sheet units, kept from the last scroll. */
|
|
855
882
|
#vy = 0;
|
|
@@ -884,7 +911,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
884
911
|
band.firstElementChild?.setAttribute("class", "grid");
|
|
885
912
|
}
|
|
886
913
|
this.#print.setAttribute("class", "print");
|
|
887
|
-
// 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.
|
|
888
916
|
this.#nameBoxes(null);
|
|
889
917
|
this.#nameGrip(null);
|
|
890
918
|
this.#lines.setAttribute("role", "list");
|
|
@@ -918,14 +946,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
918
946
|
});
|
|
919
947
|
// A long press of a pen or a finger, or a right click, opens no menu over the sheet: the
|
|
920
948
|
// canvas's event comes up to the stage, and so does the stage's own, where a worked example's
|
|
921
|
-
// sheet takes the pointer instead
|
|
949
|
+
// sheet takes the pointer instead.
|
|
922
950
|
this.#stage.addEventListener("contextmenu", (event) => event.preventDefault());
|
|
923
951
|
// A new colour of the ink, from the consumer's theme or the page's colour scheme, ends a
|
|
924
952
|
// transition of the canvas's colour a millisecond long: the ink is drawn anew in it.
|
|
925
953
|
this.#canvas.addEventListener("transitionend", () => this.#request());
|
|
926
954
|
this.#canvas.addEventListener("transitioncancel", () => this.#request());
|
|
927
955
|
this.#viewport.addEventListener("scroll", () => this.#scrolled(), { passive: true });
|
|
928
|
-
// 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.
|
|
929
957
|
this.#viewport.addEventListener("wheel", (event) => this.#wheel(event), { passive: false });
|
|
930
958
|
// A container left with nothing to scroll keeps its stop of Tab while it has the focus.
|
|
931
959
|
this.#viewport.addEventListener("blur", () => this.#region());
|
|
@@ -953,16 +981,16 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
953
981
|
this.#adopt("history");
|
|
954
982
|
this.#adopt("marks");
|
|
955
983
|
}
|
|
956
|
-
/** 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. */
|
|
957
985
|
static observedAttributes = ["lang", "tools-hidden"];
|
|
958
986
|
/**
|
|
959
|
-
* What a press of the primary button does: "pen" writes, as the element starts, "eraser" erases
|
|
960
|
-
*
|
|
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
|
|
961
989
|
* element's own buttons, which say a choice of theirs with a `toolchange`, and the consumer may
|
|
962
|
-
* 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
|
|
963
991
|
* erases whatever the tool but the hand. A task without the eraser has none of it: "eraser" is a
|
|
964
992
|
* TypeError then, and a new task without it puts the pen back. Every sheet the learner writes on
|
|
965
|
-
* 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.
|
|
966
994
|
*/
|
|
967
995
|
get tool() {
|
|
968
996
|
return this.#tool;
|
|
@@ -979,18 +1007,18 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
979
1007
|
this.#refresh();
|
|
980
1008
|
}
|
|
981
1009
|
/**
|
|
982
|
-
* The open view of the task, of the module format 0.4
|
|
983
|
-
* element shows above the page
|
|
984
|
-
*
|
|
985
|
-
* items. A workbook's items are its lines, which the template shows, laid out on the page
|
|
986
|
-
*
|
|
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
|
|
987
1015
|
* refuses is a TypeError that names the field, a field the open view has not among it, and so are
|
|
988
|
-
* 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
|
|
989
1017
|
* a zone; the sheet passes over a choice and an item's text, which app shows. Another task of the
|
|
990
1018
|
* same layer, tools and statement changes nothing, and any other changes the template alone, of
|
|
991
|
-
* 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
|
|
992
1020
|
* eraser puts the pen back, with no event. While a worked example is shown a task is a TypeError,
|
|
993
|
-
* and `undefined` changes nothing: the element shows one or the other
|
|
1021
|
+
* and `undefined` changes nothing: the element shows one or the other.
|
|
994
1022
|
*/
|
|
995
1023
|
get task() {
|
|
996
1024
|
return this.#task;
|
|
@@ -1011,10 +1039,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1011
1039
|
this.#present(template);
|
|
1012
1040
|
}
|
|
1013
1041
|
/**
|
|
1014
|
-
* A lesson's worked example
|
|
1015
|
-
* 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,
|
|
1016
1044
|
* the grid of its sheet or the lines of its workbook, and the parts of the author's demo, which
|
|
1017
|
-
* 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.
|
|
1018
1046
|
* The element shows a task or a worked example, not both: an example while a task is given, while
|
|
1019
1047
|
* the sheet has a history of writing, or while a stroke or an erasing is under way, is a
|
|
1020
1048
|
* TypeError, and so is one the schema refuses, at its field. `undefined` takes the example off,
|
|
@@ -1023,9 +1051,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1023
1051
|
*
|
|
1024
1052
|
* On a worked example's sheet the learner does not write: the canvas takes no input, and a finger
|
|
1025
1053
|
* or a pen there scrolls the sheet as the browser scrolls the statement. It has no bar: its row
|
|
1026
|
-
* holds Next and Demo, and its region is named a worked example's. `task`, `history` other than
|
|
1027
|
-
* `marks` are TypeErrors, and so is an eraser: the tool is the pen alone, and
|
|
1028
|
-
* `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.
|
|
1029
1057
|
*
|
|
1030
1058
|
* The parts of the demo the learner opens one at a time with the row's Next, into a list between
|
|
1031
1059
|
* the statement and the sheet, and hides and shows whole with Demo; `demoState` tells how far
|
|
@@ -1066,16 +1094,16 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1066
1094
|
}
|
|
1067
1095
|
}
|
|
1068
1096
|
/**
|
|
1069
|
-
* 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
|
|
1070
1098
|
* Blob of a JPEG or a PNG. The element shows it in place of a task and of a worked example: a
|
|
1071
1099
|
* dotted sheet with no statement, the pen and the eraser, and the crop over it as tracing paper,
|
|
1072
1100
|
* at the element's own place for it, shown, which `tracing` tells. While a task or an example is
|
|
1073
1101
|
* shown it is a TypeError, and so is what is not such a task. Another task from paper, of
|
|
1074
1102
|
* another crop, lays its crop at the start again, and the history stays: the next task is a new
|
|
1075
|
-
* element
|
|
1076
|
-
* history has strokes on the tracing paper, a TypeError. Either drops a stroke or an erasing
|
|
1077
|
-
* way on the tracing paper, as a new history drops the one under the pen. The crop's
|
|
1078
|
-
* 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.
|
|
1079
1107
|
*/
|
|
1080
1108
|
get paper() {
|
|
1081
1109
|
return this.#paper;
|
|
@@ -1127,13 +1155,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1127
1155
|
}
|
|
1128
1156
|
/**
|
|
1129
1157
|
* Where the tracing paper of the task from paper lies on the sheet, its top left corner in sheet
|
|
1130
|
-
* units, and whether it is hidden
|
|
1131
|
-
* `undefined` without a task from paper. The learner moves it by its grip and hides or shows it
|
|
1132
|
-
* the button atop the tools, which a `tracingchange` tells; the consumer keeps it and gives it
|
|
1133
|
-
* back, which tells nothing. Given before the task from paper it is a TypeError, and so is a
|
|
1134
|
-
* that is not one, or one that puts the paper wholly off the sheet; `undefined` changes
|
|
1135
|
-
* Till the crop's picture is read the paper has its largest size: a state that puts the
|
|
1136
|
-
* 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.
|
|
1137
1166
|
*/
|
|
1138
1167
|
get tracing() {
|
|
1139
1168
|
return this.#tracing;
|
|
@@ -1155,7 +1184,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1155
1184
|
this.#request();
|
|
1156
1185
|
}
|
|
1157
1186
|
/**
|
|
1158
|
-
* 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
|
|
1159
1188
|
* "Recognise"; `"ready"` offers it, and its press sends a `tracingread`; `"busy"` waits; `"done"`
|
|
1160
1189
|
* holds the statements, which take the crop's place for the learner who asked, till "Original".
|
|
1161
1190
|
* Frozen; given without a task from paper, or not a reading, it is a TypeError.
|
|
@@ -1173,7 +1202,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1173
1202
|
this.#request();
|
|
1174
1203
|
}
|
|
1175
1204
|
/**
|
|
1176
|
-
* 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
|
|
1177
1206
|
* its parts are open, from the first, and `hidden`, whether the whole demo is hidden — frozen,
|
|
1178
1207
|
* and the same object until it changes. A new example starts at `{ opened: 0, hidden: false }`,
|
|
1179
1208
|
* and without one it is `undefined`. The learner changes it with the row's Next and Demo, which
|
|
@@ -1202,8 +1231,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1202
1231
|
this.#showDemo(example, checked);
|
|
1203
1232
|
}
|
|
1204
1233
|
/**
|
|
1205
|
-
* The open view of the module's manifest
|
|
1206
|
-
* 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
|
|
1207
1236
|
* crop for checking, `canvas.digit_height`, 24 px unless given, and the explanation language, the
|
|
1208
1237
|
* statement's and a workbook's lines'. Without a manifest the digits are 24 px, and the statement
|
|
1209
1238
|
* and the lines are in the element's own `lang`. The rest of it the element passes over, but for
|
|
@@ -1211,7 +1240,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1211
1240
|
* cannot read is a TypeError that names the field, and the element stays as it was; the same
|
|
1212
1241
|
* object given again is read again, for the consumer may have changed it. The task and the
|
|
1213
1242
|
* manifest are each the consumer's to give, in either order: `exportWork()` takes the height
|
|
1214
|
-
* when it is called
|
|
1243
|
+
* when it is called.
|
|
1215
1244
|
*/
|
|
1216
1245
|
get manifest() {
|
|
1217
1246
|
return this.#manifest;
|
|
@@ -1228,9 +1257,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1228
1257
|
this.#settings = settings;
|
|
1229
1258
|
}
|
|
1230
1259
|
/**
|
|
1231
|
-
* What gives the files of the pictures, by their references, as the contract has it
|
|
1232
|
-
*
|
|
1233
|
-
* 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
|
|
1234
1263
|
* reference is asked for once, whichever pictures show it, and its file stays while the task or
|
|
1235
1264
|
* the example names it. Until a picture's file comes, or if it never does, its frame shows what
|
|
1236
1265
|
* it shows in words. A new function serves the references that have no file yet, and stops no
|
|
@@ -1246,7 +1275,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1246
1275
|
this.#pictures.media = media;
|
|
1247
1276
|
}
|
|
1248
1277
|
/**
|
|
1249
|
-
* 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
|
|
1250
1279
|
* "dots" as one comes. The learner turns it by the element's button, which a `gridchange`
|
|
1251
1280
|
* tells; the consumer keeps it and gives it back, which tells nothing. A grid given before the
|
|
1252
1281
|
* task from paper is a TypeError, and so is one not of `PaperGrid`; `undefined` changes nothing.
|
|
@@ -1271,7 +1300,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1271
1300
|
this.#refresh();
|
|
1272
1301
|
}
|
|
1273
1302
|
/**
|
|
1274
|
-
* The history of writing
|
|
1303
|
+
* The history of writing: every stroke, erasing, clearing and undo on the sheet, in the
|
|
1275
1304
|
* order they landed, at the sheet's time — frozen, and the same array until the next action. The
|
|
1276
1305
|
* consumer keeps it, adding what `historychange` tells, and gives it back to open the sheet as it
|
|
1277
1306
|
* was: the strokes, and the actions undo takes back.
|
|
@@ -1285,8 +1314,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1285
1314
|
* event, the next stroke takes the next ID, and the tutor's marks go back on the strokes, or off,
|
|
1286
1315
|
* if the history has not their strokes. A history that is where the sheet's began loses what came
|
|
1287
1316
|
* after, and says so in the console. The task and the history are each the consumer's to give, in
|
|
1288
|
-
* either order. A worked example's sheet has the empty history alone: any other is a TypeError
|
|
1289
|
-
* (R42).
|
|
1317
|
+
* either order. A worked example's sheet has the empty history alone: any other is a TypeError.
|
|
1290
1318
|
*/
|
|
1291
1319
|
get history() {
|
|
1292
1320
|
return this.#work.history;
|
|
@@ -1311,7 +1339,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1311
1339
|
};
|
|
1312
1340
|
return;
|
|
1313
1341
|
}
|
|
1314
|
-
// 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.
|
|
1315
1343
|
if (this.#example !== undefined) {
|
|
1316
1344
|
throw new TypeError(`<${TAG}> shows a worked example, whose sheet has no history of writing`);
|
|
1317
1345
|
}
|
|
@@ -1340,9 +1368,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1340
1368
|
/**
|
|
1341
1369
|
* Which answer slots the learner's strokes fill, per item, per slot, in the task's order, by the
|
|
1342
1370
|
* strokes `exportWork()` would take — not the stroke under way, but those under an eraser not
|
|
1343
|
-
* yet lifted. A workbook's boxes, each whether it holds one
|
|
1344
|
-
* or in none, by the rule
|
|
1345
|
-
* 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,
|
|
1346
1374
|
* whose options app marks, for a sheet with no task, and for a worked example. Frozen, and the
|
|
1347
1375
|
* same array until a slot changes. An action on the sheet changes it before its
|
|
1348
1376
|
* `historychange`, and a task or a history given changes it with no event.
|
|
@@ -1351,20 +1379,20 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1351
1379
|
return this.#filled;
|
|
1352
1380
|
}
|
|
1353
1381
|
/**
|
|
1354
|
-
* The tutor's marks of one submission, with the context the element gave with its work
|
|
1355
|
-
*
|
|
1356
|
-
*
|
|
1357
|
-
*
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1362
|
-
*
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
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.
|
|
1368
1396
|
*/
|
|
1369
1397
|
get marks() {
|
|
1370
1398
|
return this.#marks;
|
|
@@ -1379,7 +1407,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1379
1407
|
this.#given = given;
|
|
1380
1408
|
this.#showMarks(shown);
|
|
1381
1409
|
}
|
|
1382
|
-
/** 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. */
|
|
1383
1411
|
adoptedCallback() {
|
|
1384
1412
|
if (this.shadowRoot !== null)
|
|
1385
1413
|
adoptStyle(this.shadowRoot);
|
|
@@ -1392,14 +1420,17 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1392
1420
|
this.#watchColours();
|
|
1393
1421
|
this.#pictures.connect();
|
|
1394
1422
|
this.#tracingPaper.connect();
|
|
1395
|
-
// The page's pen mode, on every sheet of it
|
|
1396
|
-
// 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.
|
|
1397
1426
|
const unwatch = PEN_MODE.watch(() => queueMicrotask(() => this.#refresh()));
|
|
1398
1427
|
const unenlist = PEN_MODE.enlist(() => this.#writer() !== undefined);
|
|
1399
1428
|
this.#unwatchPen = () => {
|
|
1400
1429
|
unwatch();
|
|
1401
1430
|
unenlist();
|
|
1402
1431
|
};
|
|
1432
|
+
// The page's zoom, on every sheet of it: it may have changed while the element was away.
|
|
1433
|
+
this.#unwatchZoom = PAGE_ZOOM.watch(() => this.#zoomed());
|
|
1403
1434
|
// A page that grows or shrinks scrolls nothing, and neither does a window of another size.
|
|
1404
1435
|
this.#page.observe(document.documentElement);
|
|
1405
1436
|
window.addEventListener("resize", this.#resized);
|
|
@@ -1410,9 +1441,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1410
1441
|
}
|
|
1411
1442
|
/**
|
|
1412
1443
|
* The element's `lang` came, changed or went: its buttons and a workbook's boxes are labelled in
|
|
1413
|
-
* 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
|
|
1414
1445
|
* `tools-hidden` did: while the element has it, the bar is out of sight and of the accessibility
|
|
1415
|
-
* 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
|
|
1416
1447
|
* element had before it was defined comes here just after the constructor, which reads no
|
|
1417
1448
|
* attribute.
|
|
1418
1449
|
*/
|
|
@@ -1430,7 +1461,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1430
1461
|
}
|
|
1431
1462
|
/**
|
|
1432
1463
|
* The demo's list says a box it fills in the labels' language, around its value, which is a node
|
|
1433
|
-
* 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.
|
|
1434
1465
|
* Without `lang` the labels are English, as the element's own.
|
|
1435
1466
|
*/
|
|
1436
1467
|
#nameBoxes(tag = this.getAttribute("lang")) {
|
|
@@ -1444,15 +1475,15 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1444
1475
|
return { before, value, after, lang };
|
|
1445
1476
|
};
|
|
1446
1477
|
}
|
|
1447
|
-
/** 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. */
|
|
1448
1479
|
#nameGrip(tag = this.getAttribute("lang")) {
|
|
1449
1480
|
const { lang, labels } = labelsFor(tag);
|
|
1450
1481
|
this.#tracingPaper.label(labels, lang);
|
|
1451
1482
|
}
|
|
1452
1483
|
/**
|
|
1453
1484
|
* Takes back the last action on the sheet — the last stroke written, the last erasing, or the
|
|
1454
|
-
* clearing — and says whether there was one
|
|
1455
|
-
*
|
|
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
|
|
1456
1487
|
* stays: it lands when it ends. So does an erasing: what it came near leaves the sheet when it
|
|
1457
1488
|
* lifts, if it is on the sheet then.
|
|
1458
1489
|
*/
|
|
@@ -1464,8 +1495,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1464
1495
|
}
|
|
1465
1496
|
/**
|
|
1466
1497
|
* Takes every stroke off the sheet, an action that undo takes back, and says whether there were
|
|
1467
|
-
* any
|
|
1468
|
-
* 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.
|
|
1469
1500
|
*/
|
|
1470
1501
|
clear() {
|
|
1471
1502
|
const cleared = this.#work.clear(performance.now());
|
|
@@ -1474,17 +1505,17 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1474
1505
|
return cleared;
|
|
1475
1506
|
}
|
|
1476
1507
|
/**
|
|
1477
|
-
* The work for checking
|
|
1478
|
-
* 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
|
|
1479
1510
|
* shows, its PNG, and the context of the submission — the crop's numbers, the groups and their
|
|
1480
|
-
* digest
|
|
1481
|
-
* its item and its slot, and the context — the table «box → stroke IDs» and its digest
|
|
1482
|
-
*
|
|
1483
|
-
* 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
|
|
1484
1515
|
* sheet as it is when this is called: a stroke under way is not on it yet, while the strokes
|
|
1485
1516
|
* under an eraser not yet lifted still are, as `filled` has them. A sheet without strokes, and a
|
|
1486
1517
|
* workbook with no box filled, have no work to check, and the promise gives null (H3); so has a
|
|
1487
|
-
* worked example, whose sheet the learner does not write on
|
|
1518
|
+
* worked example, whose sheet the learner does not write on.
|
|
1488
1519
|
*/
|
|
1489
1520
|
async exportWork() {
|
|
1490
1521
|
if (this.#example !== undefined)
|
|
@@ -1525,23 +1556,23 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1525
1556
|
}
|
|
1526
1557
|
/**
|
|
1527
1558
|
* The picture of the work, for the `picture` of a stored work that app puts on the server, a
|
|
1528
|
-
* method of the agreement with app
|
|
1559
|
+
* method of the agreement with app: the PNG of the strokes the surface shows,
|
|
1529
1560
|
* with no condition — the sheet's page, or the workbook's whole page with its draft, and the ink
|
|
1530
|
-
* 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,
|
|
1531
1562
|
* 1000 × 1400 for the page alone, and scaled down past the page to hold no more pixels than it,
|
|
1532
1563
|
* its size in its PNG's header —, whatever is filled and whether the work was sent to be checked
|
|
1533
|
-
* or not; an empty surface, and a worked example's, is white. The strokes are those
|
|
1534
|
-
* the history has them: not the stroke under way, but those under an
|
|
1535
|
-
* is the outline the screen fills, black on white with no theme and
|
|
1536
|
-
* paper the strokes of both layers, the tracing paper's where it
|
|
1537
|
-
* crop's picture laid in grey and multiplied
|
|
1538
|
-
*
|
|
1539
|
-
*
|
|
1540
|
-
*
|
|
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.
|
|
1541
1572
|
*/
|
|
1542
1573
|
async exportPicture() {
|
|
1543
|
-
// A pixel a unit, the ink 3 px wide as on a screen of a pixel a unit, while the page and the
|
|
1544
|
-
// 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.
|
|
1545
1576
|
const reach = this.#inkReach();
|
|
1546
1577
|
const { width, height, scale } = pictureOf({
|
|
1547
1578
|
maxX: reach.maxX + INK_REACH,
|
|
@@ -1562,7 +1593,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1562
1593
|
for (const stroke of strokes) {
|
|
1563
1594
|
const traced = tracing !== undefined && work.onTracing(stroke.id);
|
|
1564
1595
|
const [x, y] = traced ? tracing.at : [0, 0];
|
|
1565
|
-
// 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.
|
|
1566
1597
|
const by = traced ? scale * scaleIn(tracing) : scale;
|
|
1567
1598
|
context.setTransform(by, 0, 0, by, x * scale, y * scale);
|
|
1568
1599
|
context.fill(this.#finished(stroke).path);
|
|
@@ -1577,7 +1608,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1577
1608
|
for (let at = 0; at < gray.length; at++)
|
|
1578
1609
|
gray[at] = data[4 * at];
|
|
1579
1610
|
// A task from paper's crop lies over it where the tracing paper lies, shown or hidden, at the
|
|
1580
|
-
// picture's scale, as the crop of the work has it
|
|
1611
|
+
// picture's scale, as the crop of the work has it.
|
|
1581
1612
|
if (tracing !== undefined) {
|
|
1582
1613
|
const { size, gray: picture } = await this.#tracingPaper.read;
|
|
1583
1614
|
if (picture !== null) {
|
|
@@ -1603,6 +1634,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1603
1634
|
this.#latchAcross = undefined;
|
|
1604
1635
|
this.#unwatchPen?.();
|
|
1605
1636
|
this.#unwatchPen = undefined;
|
|
1637
|
+
this.#unwatchZoom?.();
|
|
1638
|
+
this.#unwatchZoom = undefined;
|
|
1606
1639
|
this.#endPan();
|
|
1607
1640
|
this.#page.disconnect();
|
|
1608
1641
|
this.#ported.disconnect();
|
|
@@ -1643,7 +1676,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1643
1676
|
}
|
|
1644
1677
|
}
|
|
1645
1678
|
/**
|
|
1646
|
-
* 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
|
|
1647
1680
|
* statement apart: a new grid or new lines leave the statement and its pictures as they are, and
|
|
1648
1681
|
* the other way round. A tool not allowed puts the pen back, with no event, and the row shows
|
|
1649
1682
|
* what it is of, by its name, and the tools allowed: only what has changed is written. Then the
|
|
@@ -1656,11 +1689,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1656
1689
|
this.#shownTemplate = template;
|
|
1657
1690
|
if (!sameLayer(template, shown)) {
|
|
1658
1691
|
this.#lay(template);
|
|
1659
|
-
// 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.
|
|
1660
1693
|
this.#replace();
|
|
1661
1694
|
}
|
|
1662
1695
|
else if (this.#laid === undefined) {
|
|
1663
|
-
// 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.
|
|
1664
1697
|
this.#fill();
|
|
1665
1698
|
}
|
|
1666
1699
|
if (!sameStatement(template, shown))
|
|
@@ -1672,14 +1705,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1672
1705
|
this.#regrow();
|
|
1673
1706
|
this.#refresh();
|
|
1674
1707
|
}
|
|
1675
|
-
/** 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. */
|
|
1676
1709
|
#allows(tool) {
|
|
1677
1710
|
if (tool === HAND)
|
|
1678
1711
|
return this.#example === undefined;
|
|
1679
1712
|
return this.#shownTemplate.tools.includes(tool);
|
|
1680
1713
|
}
|
|
1681
1714
|
/**
|
|
1682
|
-
* 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
|
|
1683
1716
|
* sheet the learner has written on, and not while a stroke or an erasing is under way, which
|
|
1684
1717
|
* would land on a sheet that takes none. A TypeError says which.
|
|
1685
1718
|
*/
|
|
@@ -1698,7 +1731,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1698
1731
|
}
|
|
1699
1732
|
}
|
|
1700
1733
|
/**
|
|
1701
|
-
* The template's layer
|
|
1734
|
+
* The template's layer: a sheet's grid, which says nothing to a screen reader, or a
|
|
1702
1735
|
* workbook's lines, which it reads — a list of the items in the task's order, each its number,
|
|
1703
1736
|
* its text and its boxes, where the layout puts them.
|
|
1704
1737
|
*/
|
|
@@ -1708,8 +1741,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1708
1741
|
write(this.#template, "aria-hidden", workbook ? null : "true");
|
|
1709
1742
|
write(this.#template, "role", workbook ? "none" : null);
|
|
1710
1743
|
this.#lines.replaceChildren(...(workbook ? template.page.items.map(itemOf) : []));
|
|
1711
|
-
// A canvas of the other kind fills its answer slots anew: a workbook's are its own arrays, and
|
|
1712
|
-
// 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.
|
|
1713
1746
|
if (workbook !== (this.#laid !== undefined))
|
|
1714
1747
|
this.#filled = null;
|
|
1715
1748
|
this.#laid = workbook ? template.page : undefined;
|
|
@@ -1723,10 +1756,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1723
1756
|
this.#markBoxes();
|
|
1724
1757
|
}
|
|
1725
1758
|
/**
|
|
1726
|
-
* Which answer slots the strokes fill, and whether that changed. A workbook's boxes by the
|
|
1727
|
-
*
|
|
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
|
|
1728
1761
|
* box changed. A sheet's one answer anywhere on it or the whole sheet by any stroke on it, or
|
|
1729
|
-
* nothing for a sheet of choices or with no task
|
|
1762
|
+
* nothing for a sheet of choices or with no task.
|
|
1730
1763
|
*/
|
|
1731
1764
|
#fill() {
|
|
1732
1765
|
const page = this.#laid;
|
|
@@ -1755,10 +1788,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1755
1788
|
return true;
|
|
1756
1789
|
}
|
|
1757
1790
|
/**
|
|
1758
|
-
* 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
|
|
1759
1792
|
* name in the labels' language, by the element's `lang` — "Box" alone in its line, numbered by
|
|
1760
1793
|
* its slot among several, and "filled" when it is. A value a worked example's demo wrote in it is
|
|
1761
|
-
* 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
|
|
1762
1795
|
* what has changed is written.
|
|
1763
1796
|
*/
|
|
1764
1797
|
#markBoxes() {
|
|
@@ -1777,7 +1810,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1777
1810
|
}
|
|
1778
1811
|
/**
|
|
1779
1812
|
* The marks as they were checked when given, back on their strokes after a new history or a new
|
|
1780
|
-
* 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.
|
|
1781
1814
|
*/
|
|
1782
1815
|
#replace() {
|
|
1783
1816
|
if (this.#given === undefined)
|
|
@@ -1804,7 +1837,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1804
1837
|
}
|
|
1805
1838
|
/**
|
|
1806
1839
|
* The marks of a submission, as `marksOf` checked them, that have a place on this sheet, each
|
|
1807
|
-
* 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.
|
|
1808
1841
|
*/
|
|
1809
1842
|
#places(given) {
|
|
1810
1843
|
const cells = isWorkbook(this.#shownTemplate) ? this.#cells : null;
|
|
@@ -1859,13 +1892,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1859
1892
|
this.#request();
|
|
1860
1893
|
}
|
|
1861
1894
|
/**
|
|
1862
|
-
* One pointer at a time writes or erases
|
|
1863
|
-
* 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
|
|
1864
1897
|
* erases — if the task allows the eraser: without it, the pen's eraser does nothing, for the
|
|
1865
|
-
* recorder takes the primary button alone
|
|
1898
|
+
* recorder takes the primary button alone.
|
|
1866
1899
|
*/
|
|
1867
1900
|
#down(event) {
|
|
1868
|
-
// 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
|
|
1869
1902
|
// that a script sends it does nothing either, nor puts the page in pen mode.
|
|
1870
1903
|
if (this.#example !== undefined)
|
|
1871
1904
|
return;
|
|
@@ -1874,7 +1907,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1874
1907
|
this.#recorder.end(event.pointerId);
|
|
1875
1908
|
this.#eraser.end(event.pointerId);
|
|
1876
1909
|
// The hand moves the sheet under a pen, a finger or a mouse alike, and writes nothing: one
|
|
1877
|
-
// 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.
|
|
1878
1911
|
if (this.#tool === HAND) {
|
|
1879
1912
|
if (this.#pan !== undefined)
|
|
1880
1913
|
return;
|
|
@@ -1886,9 +1919,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1886
1919
|
return;
|
|
1887
1920
|
}
|
|
1888
1921
|
const writes = this.#hands.down(contactOf(event));
|
|
1889
|
-
// The canvas holds on to every pointer that comes down on it until it lifts, writing or not:
|
|
1890
|
-
// moves and its lift come here, so that a stroke goes on beyond the canvas, two fingers
|
|
1891
|
-
// 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.
|
|
1892
1925
|
this.#capture(event.pointerId);
|
|
1893
1926
|
if (!writes)
|
|
1894
1927
|
return;
|
|
@@ -1899,7 +1932,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1899
1932
|
const erases = this.#shownTemplate.tools.includes("eraser") &&
|
|
1900
1933
|
(this.#tool === "eraser" || onSheetSample.button === ERASER_BUTTON);
|
|
1901
1934
|
// On a task from paper a press begun on the tracing paper in sight writes or erases on it, its
|
|
1902
|
-
// points from its corner; one begun elsewhere, on the sheet
|
|
1935
|
+
// points from its corner; one begun elsewhere, on the sheet.
|
|
1903
1936
|
const tracing = this.#tracing;
|
|
1904
1937
|
const size = this.#tracingPaper.size;
|
|
1905
1938
|
const scale = tracing === undefined ? 1 : scaleIn(tracing);
|
|
@@ -1907,7 +1940,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1907
1940
|
!tracing.hidden &&
|
|
1908
1941
|
this.#tracingPaper.ready &&
|
|
1909
1942
|
onTracing(onSheetSample, tracing.at, scaled(size, scale));
|
|
1910
|
-
// 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.
|
|
1911
1944
|
this.#tracingPaper.letGo();
|
|
1912
1945
|
const layer = traced ? "tracing" : undefined;
|
|
1913
1946
|
if (erases)
|
|
@@ -1988,7 +2021,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1988
2021
|
}
|
|
1989
2022
|
/**
|
|
1990
2023
|
* A pointer lifted, or the device or the page took it from the sheet: the hands forget it, and a
|
|
1991
|
-
* 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.
|
|
1992
2025
|
*/
|
|
1993
2026
|
#lifted(pointerId) {
|
|
1994
2027
|
if (this.#pan?.pointerId === pointerId)
|
|
@@ -2027,14 +2060,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2027
2060
|
return this.#eraser;
|
|
2028
2061
|
return undefined;
|
|
2029
2062
|
}
|
|
2030
|
-
/** 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. */
|
|
2031
2064
|
#layerOf(input) {
|
|
2032
2065
|
const on = input === this.#eraser ? this.#eraseOn : this.#writeOn;
|
|
2033
2066
|
return on === "tracing" ? "tracing" : undefined;
|
|
2034
2067
|
}
|
|
2035
2068
|
/**
|
|
2036
2069
|
* A pointer's place on the sheet, or on the tracing paper, `layer`, from its corner and kept to
|
|
2037
|
-
* it
|
|
2070
|
+
* it.
|
|
2038
2071
|
*/
|
|
2039
2072
|
#sample(event, screen, layer) {
|
|
2040
2073
|
const point = toSheet(screen, event.clientX - screen.left, event.clientY - screen.top);
|
|
@@ -2059,7 +2092,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2059
2092
|
* one on the screen, after whatever transform the page puts on the element. The container's
|
|
2060
2093
|
* rectangle gives the part of the canvas it shows: with the statement in sight, the canvas
|
|
2061
2094
|
* goes on below the container's bottom. The bar of buttons over the sheet takes what is under it
|
|
2062
|
-
* itself: a pointer there presses a button, and writes nothing
|
|
2095
|
+
* itself: a pointer there presses a button, and writes nothing.
|
|
2063
2096
|
*/
|
|
2064
2097
|
#view() {
|
|
2065
2098
|
const canvas = this.#canvas.getBoundingClientRect();
|
|
@@ -2081,7 +2114,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2081
2114
|
}
|
|
2082
2115
|
/**
|
|
2083
2116
|
* The sheet's top in the container's content, in CSS pixels as laid out: under the statement —
|
|
2084
|
-
* or, along `x`, its left
|
|
2117
|
+
* or, along `x`, its left.
|
|
2085
2118
|
*/
|
|
2086
2119
|
#sheetEdge(axis) {
|
|
2087
2120
|
const port = clientBoxOf(this.#viewport);
|
|
@@ -2105,7 +2138,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2105
2138
|
/**
|
|
2106
2139
|
* The statement and a demo's parts keep the element's own direction while the container runs
|
|
2107
2140
|
* left to right: the direction the element computes, by an attribute or by a style, as the last
|
|
2108
|
-
* layout read it
|
|
2141
|
+
* layout read it.
|
|
2109
2142
|
*/
|
|
2110
2143
|
#keepDirection() {
|
|
2111
2144
|
if (!this.isConnected)
|
|
@@ -2116,7 +2149,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2116
2149
|
}
|
|
2117
2150
|
}
|
|
2118
2151
|
/**
|
|
2119
|
-
* 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
|
|
2120
2153
|
* it watches, or the window's —, from whose top it runs down to its bottom, below the consumer's
|
|
2121
2154
|
* --novatrail-canvas-top; and the element's width, which a worked example's row keeps within, as
|
|
2122
2155
|
* the rail is as wide as nothing. A band in pixels is taken as it changes; one in percent, of the
|
|
@@ -2160,12 +2193,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2160
2193
|
return within ? room.top + room.offset : Number.NEGATIVE_INFINITY;
|
|
2161
2194
|
}
|
|
2162
2195
|
/**
|
|
2163
|
-
* Two fingers, or the hand, moved right on the screen by `dx` CSS pixels and down it by `dy
|
|
2164
|
-
*
|
|
2165
|
-
* scrolls down, for the whole gesture, and its first step across what it scrolls across
|
|
2166
|
-
*
|
|
2167
|
-
*
|
|
2168
|
-
* 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.
|
|
2169
2202
|
*/
|
|
2170
2203
|
#scroll(dx, dy, fresh) {
|
|
2171
2204
|
if (fresh) {
|
|
@@ -2201,7 +2234,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2201
2234
|
}
|
|
2202
2235
|
/**
|
|
2203
2236
|
* What scrolls on down the content, for `onward`, or back up it — or, along `x`, on right across
|
|
2204
|
-
* it or back left
|
|
2237
|
+
* it or back left.
|
|
2205
2238
|
*/
|
|
2206
2239
|
#scrollerFor(onward, axis = "y") {
|
|
2207
2240
|
if (scrollsOn(this.#viewport, onward, axis)) {
|
|
@@ -2222,7 +2255,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2222
2255
|
if (keeps === "contain" || keeps === "none")
|
|
2223
2256
|
return undefined;
|
|
2224
2257
|
}
|
|
2225
|
-
// 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.
|
|
2226
2260
|
if (overflow === "hidden" || overflow === "clip")
|
|
2227
2261
|
return undefined;
|
|
2228
2262
|
const page = document.scrollingElement;
|
|
@@ -2232,8 +2266,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2232
2266
|
}
|
|
2233
2267
|
/**
|
|
2234
2268
|
* The stage takes the visible part of the sheet, and the canvas a pixel of its buffer for each
|
|
2235
|
-
* device pixel: its size on the screen times the density
|
|
2236
|
-
* 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.
|
|
2237
2271
|
*/
|
|
2238
2272
|
#layout() {
|
|
2239
2273
|
// The content of a new size, or the container, may overflow it now, or no more.
|
|
@@ -2241,9 +2275,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2241
2275
|
const area = this.#area;
|
|
2242
2276
|
if (area === undefined || area.width === 0)
|
|
2243
2277
|
return;
|
|
2244
|
-
// The page is as wide as the container up to the cap, the column as wide as the
|
|
2245
|
-
// the style, and the stage as tall and as wide as the visible part of the sheet.
|
|
2246
|
-
const k = fitScale(area.width);
|
|
2278
|
+
// The page is as wide as the container up to the cap, times the zoom, the column as wide as the
|
|
2279
|
+
// sheet goes, by the style, and the stage as tall and as wide as the visible part of the sheet.
|
|
2280
|
+
const k = fitScale(area.width) * this.#zoom;
|
|
2247
2281
|
const extent = this.#extent;
|
|
2248
2282
|
this.#stage.style.width = `${Math.min(area.width, extent.width * k)}px`;
|
|
2249
2283
|
this.#stage.style.height = `${Math.min(area.height, extent.height * k)}px`;
|
|
@@ -2277,17 +2311,20 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2277
2311
|
this.#region();
|
|
2278
2312
|
}
|
|
2279
2313
|
/**
|
|
2280
|
-
* How far the sheet goes
|
|
2281
|
-
* one view of the window more, at the window's own fit
|
|
2282
|
-
* sheet is its page alone. The window's view and not the
|
|
2283
|
-
* style, and a size that the container's observer gave
|
|
2284
|
-
* the observer reports it, which the browser tells the
|
|
2314
|
+
* How far the sheet goes: past the page, the ink and the tracing paper where it lies, by
|
|
2315
|
+
* one view of the window more across and two down, at the window's own fit times the zoom,
|
|
2316
|
+
* within the reach. A worked example's sheet is its page alone. The window's view and not the
|
|
2317
|
+
* container's: the sheet is sized by its style, and a size that the container's observer gave
|
|
2318
|
+
* would resize the container again while the observer reports it, which the browser tells the
|
|
2319
|
+
* window as a loop. A zoom below the fit counts by its quarter below, so that a pinch lays the
|
|
2320
|
+
* sheet out anew only as it crosses one, and above the fit as the fit: the view is smaller then.
|
|
2285
2321
|
*/
|
|
2286
2322
|
#reach() {
|
|
2287
2323
|
if (this.#example !== undefined)
|
|
2288
2324
|
return SHEET;
|
|
2289
|
-
const
|
|
2290
|
-
|
|
2325
|
+
const quarter = Math.max(ZOOM_MIN, Math.floor(this.#zoom / ZOOM_STEP + 1e-6) * ZOOM_STEP);
|
|
2326
|
+
const k = fitScale(innerWidth) * Math.min(1, quarter);
|
|
2327
|
+
return extentOf(this.#inkReach(), { width: innerWidth / k, height: (2 * innerHeight) / k });
|
|
2291
2328
|
}
|
|
2292
2329
|
/** The right and the bottom of the sheet's ink and of the tracing paper, which counts whole. */
|
|
2293
2330
|
#inkReach() {
|
|
@@ -2315,21 +2352,83 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2315
2352
|
/**
|
|
2316
2353
|
* The ink, the tracing paper or the window went past the sheet's extent, or back: the sheet is
|
|
2317
2354
|
* sized anew by its style — the column as wide as the page's fit times the extent's share of the
|
|
2318
|
-
* 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.
|
|
2319
2356
|
*/
|
|
2320
2357
|
#regrow() {
|
|
2358
|
+
const zoom = this.#example === undefined ? PAGE_ZOOM.value : 1;
|
|
2359
|
+
const zoomed = zoom !== this.#zoom;
|
|
2360
|
+
if (zoomed) {
|
|
2361
|
+
this.#zoom = zoom;
|
|
2362
|
+
this.#column.style.setProperty("--zoom", String(zoom));
|
|
2363
|
+
}
|
|
2321
2364
|
const extent = this.#reach();
|
|
2322
|
-
|
|
2365
|
+
const grown = extent.width !== this.#extent.width || extent.height !== this.#extent.height;
|
|
2366
|
+
if (!zoomed && !grown)
|
|
2323
2367
|
return;
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2368
|
+
if (grown) {
|
|
2369
|
+
this.#extent = extent;
|
|
2370
|
+
this.#column.style.setProperty("--across", String(extent.width / SHEET.width));
|
|
2371
|
+
this.#sheet.style.aspectRatio = `${extent.width} / ${extent.height}`;
|
|
2372
|
+
this.#drawGrid();
|
|
2373
|
+
}
|
|
2328
2374
|
this.#layout();
|
|
2329
2375
|
}
|
|
2330
2376
|
/**
|
|
2331
|
-
*
|
|
2332
|
-
*
|
|
2377
|
+
* Zoom in or Zoom out was pressed: the page's zoom goes a quarter larger or smaller, and
|
|
2378
|
+
* every sheet of the page is laid out by it — but not while a pointer writes or erases on one of
|
|
2379
|
+
* them, for nothing moves under it.
|
|
2380
|
+
*/
|
|
2381
|
+
#zoomBy(larger) {
|
|
2382
|
+
if (!PEN_MODE.writing)
|
|
2383
|
+
PAGE_ZOOM.step(larger);
|
|
2384
|
+
}
|
|
2385
|
+
/** Two fingers pinched by `ratio` about `x` and `y` on the screen: the page's zoom goes by it. */
|
|
2386
|
+
#pinch(ratio, x, y) {
|
|
2387
|
+
if (this.#example !== undefined)
|
|
2388
|
+
return;
|
|
2389
|
+
this.#anchor = { x, y };
|
|
2390
|
+
try {
|
|
2391
|
+
PAGE_ZOOM.set(PAGE_ZOOM.value * ratio);
|
|
2392
|
+
}
|
|
2393
|
+
finally {
|
|
2394
|
+
this.#anchor = undefined;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
/**
|
|
2398
|
+
* The page's zoom has changed: the sheet is laid out by it at once, the point of the sheet
|
|
2399
|
+
* under a pinch's middle, or else the one the last press held, or else under the middle of the
|
|
2400
|
+
* part in sight, standing where it was on the screen, and the bar shows what the zoom can do now.
|
|
2401
|
+
*/
|
|
2402
|
+
#zoomed() {
|
|
2403
|
+
const before = this.isConnected ? this.#view() : undefined;
|
|
2404
|
+
const k = this.#k;
|
|
2405
|
+
this.#regrow();
|
|
2406
|
+
if (before !== undefined && this.#k !== k && this.#k > 0) {
|
|
2407
|
+
const { shown } = before;
|
|
2408
|
+
const held = this.#anchor === undefined && this.#held?.box === this.#heldBox() ? this.#held : undefined;
|
|
2409
|
+
const x = this.#anchor?.x ?? held?.x ?? (shown.left + shown.right) / 2;
|
|
2410
|
+
const y = this.#anchor?.y ?? held?.y ?? (shown.top + shown.bottom) / 2;
|
|
2411
|
+
const at = held?.at ?? {
|
|
2412
|
+
x: (x - before.left) / before.k + before.vx,
|
|
2413
|
+
y: (y - before.top) / before.k + before.vy,
|
|
2414
|
+
};
|
|
2415
|
+
const port = clientBoxOf(this.#viewport);
|
|
2416
|
+
this.#viewport.scrollLeft = this.#sheetAtX + at.x * this.#k - (x - port.left) / port.across;
|
|
2417
|
+
this.#viewport.scrollTop = this.#sheetAt + at.y * this.#k - (y - port.top) / port.down;
|
|
2418
|
+
this.#scrolled();
|
|
2419
|
+
this.#held = this.#anchor === undefined ? { at, x, y, box: this.#heldBox() } : undefined;
|
|
2420
|
+
}
|
|
2421
|
+
this.#refresh();
|
|
2422
|
+
}
|
|
2423
|
+
/** Where the container stands on the screen and how far it is scrolled, as a press leaves it. */
|
|
2424
|
+
#heldBox() {
|
|
2425
|
+
const { left, top, right, bottom } = this.#viewport.getBoundingClientRect();
|
|
2426
|
+
const { scrollLeft, scrollTop } = this.#viewport;
|
|
2427
|
+
return [left, top, right, bottom, scrollLeft, scrollTop].join(" ");
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
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.
|
|
2333
2432
|
*/
|
|
2334
2433
|
#drawGrid() {
|
|
2335
2434
|
const template = this.#shownTemplate;
|
|
@@ -2380,7 +2479,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2380
2479
|
/**
|
|
2381
2480
|
* The work has changed — a stroke landed, an erasing, an undo, a clearing: the sheet is drawn
|
|
2382
2481
|
* anew, and whoever listens hears of it at once, the history already as it now is, with the
|
|
2383
|
-
* events it has gained
|
|
2482
|
+
* events it has gained. The event goes up from the element itself, and out of a consumer's
|
|
2384
2483
|
* own shadow tree too, should the element be in one. An action a listener takes while it hears is
|
|
2385
2484
|
* told of next, once every listener has heard of the one before: each hears the history's events
|
|
2386
2485
|
* in its order. A history given meanwhile is no action, and what it replaced is told of no more.
|
|
@@ -2410,7 +2509,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2410
2509
|
}
|
|
2411
2510
|
}
|
|
2412
2511
|
/**
|
|
2413
|
-
* 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
|
|
2414
2513
|
* listens hears of it. A consumer that gives the tool follows it, or its next render would set
|
|
2415
2514
|
* back what the learner chose.
|
|
2416
2515
|
*/
|
|
@@ -2423,7 +2522,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2423
2522
|
this.dispatchEvent(new CustomEvent(TOOL_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2424
2523
|
}
|
|
2425
2524
|
/**
|
|
2426
|
-
* 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
|
|
2427
2526
|
* whoever listens hears of it. A consumer that gives the grid follows it.
|
|
2428
2527
|
*/
|
|
2429
2528
|
#turnGrid() {
|
|
@@ -2436,7 +2535,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2436
2535
|
this.dispatchEvent(new CustomEvent(GRID_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2437
2536
|
}
|
|
2438
2537
|
/**
|
|
2439
|
-
* 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
|
|
2440
2539
|
* strokes go out of sight with it and stay in the history and in the work, and whoever listens
|
|
2441
2540
|
* hears of the new state. A stroke or an erasing under way on the paper ends where it is, as on a
|
|
2442
2541
|
* lost capture: the pointer goes on over a paper that is not there.
|
|
@@ -2447,13 +2546,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2447
2546
|
const state = this.#tracing;
|
|
2448
2547
|
if (this.#paper === undefined || state === undefined)
|
|
2449
2548
|
return;
|
|
2450
|
-
this.#tracing = Object.freeze({
|
|
2549
|
+
this.#tracing = Object.freeze({ ...state, hidden: !state.hidden });
|
|
2451
2550
|
this.#refresh();
|
|
2452
2551
|
this.#request();
|
|
2453
2552
|
this.#tracingChanged();
|
|
2454
2553
|
}
|
|
2455
2554
|
/**
|
|
2456
|
-
* 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
|
|
2457
2556
|
* strokes move with it, and the marks on them too. The move tells of itself once it is over.
|
|
2458
2557
|
*/
|
|
2459
2558
|
#moveTracing(to) {
|
|
@@ -2470,7 +2569,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2470
2569
|
this.#request();
|
|
2471
2570
|
return at;
|
|
2472
2571
|
}
|
|
2473
|
-
/** 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. */
|
|
2474
2573
|
#wheel(event) {
|
|
2475
2574
|
if (!(event.ctrlKey || event.metaKey) || event.deltaY === 0)
|
|
2476
2575
|
return;
|
|
@@ -2488,7 +2587,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2488
2587
|
this.#tracingPaper.wheel(event.deltaY < 0);
|
|
2489
2588
|
}
|
|
2490
2589
|
/**
|
|
2491
|
-
* 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
|
|
2492
2591
|
* place and a scale, kept to the rule and to the sheet whole; its strokes scale with it, and the
|
|
2493
2592
|
* marks on them too. The change tells of itself once it is over.
|
|
2494
2593
|
*/
|
|
@@ -2508,7 +2607,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2508
2607
|
return { at, scale };
|
|
2509
2608
|
}
|
|
2510
2609
|
/**
|
|
2511
|
-
* "Fit"
|
|
2610
|
+
* "Fit": the tracing paper as wide as the window shows the sheet right of the bar of tools,
|
|
2512
2611
|
* at the rule's place there, kept to the rule; down the window, centred, below the rule's top.
|
|
2513
2612
|
*/
|
|
2514
2613
|
#fitTracing() {
|
|
@@ -2529,13 +2628,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2529
2628
|
if (from === undefined || state === undefined || sameTracing(from, state))
|
|
2530
2629
|
return;
|
|
2531
2630
|
// The marks were placed by the strokes where they lay: a submission of the paper elsewhere is
|
|
2532
|
-
// not this sheet's any more, and they go
|
|
2631
|
+
// not this sheet's any more, and they go.
|
|
2533
2632
|
this.#replace();
|
|
2534
2633
|
this.#tracingChanged();
|
|
2535
2634
|
}
|
|
2536
2635
|
/**
|
|
2537
2636
|
* A stroke or an erasing under way on the tracing paper ends where it is, `end`, or goes, as on
|
|
2538
|
-
* `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.
|
|
2539
2638
|
*/
|
|
2540
2639
|
#leaveTracing(end) {
|
|
2541
2640
|
const writer = this.#writeOn === "tracing" ? this.#recorder.pointer : undefined;
|
|
@@ -2555,7 +2654,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2555
2654
|
this.#eraseOn = undefined;
|
|
2556
2655
|
}
|
|
2557
2656
|
/**
|
|
2558
|
-
* 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,
|
|
2559
2658
|
* checked against the largest paper, that puts the paper of this size wholly off the sheet moves
|
|
2560
2659
|
* to the nearest place wholly on it, with its strokes and their marks. It tells nothing, as the
|
|
2561
2660
|
* state given did not.
|
|
@@ -2574,14 +2673,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2574
2673
|
}
|
|
2575
2674
|
this.#request();
|
|
2576
2675
|
}
|
|
2577
|
-
/** 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. */
|
|
2578
2677
|
#tracingChanged() {
|
|
2579
2678
|
const detail = this.#tracing;
|
|
2580
2679
|
this.dispatchEvent(new CustomEvent(TRACING_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2581
2680
|
}
|
|
2582
2681
|
/**
|
|
2583
|
-
* A stroke where it lies on the sheet: one of the tracing paper's moved to where the paper lies
|
|
2584
|
-
* 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.
|
|
2585
2684
|
*/
|
|
2586
2685
|
#onSheet(stroke, tracing) {
|
|
2587
2686
|
if (!this.#work.onTracing(stroke.id))
|
|
@@ -2600,11 +2699,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2600
2699
|
return placed;
|
|
2601
2700
|
}
|
|
2602
2701
|
/**
|
|
2603
|
-
* 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
|
|
2604
2703
|
* the sheet, and the layout keeps a sheet scrolled into sight where it was at once, before the
|
|
2605
2704
|
* scroll of the container is heard; then the part comes into sight between the band and the row
|
|
2606
2705
|
* of glass, the region tells of it, and whoever listens hears of the new state. The focus stays
|
|
2607
|
-
* 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.
|
|
2608
2708
|
*/
|
|
2609
2709
|
#openNext() {
|
|
2610
2710
|
const example = this.#example;
|
|
@@ -2622,7 +2722,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2622
2722
|
this.#demoChanged();
|
|
2623
2723
|
}
|
|
2624
2724
|
/**
|
|
2625
|
-
* 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
|
|
2626
2726
|
* stay open, out of sight, and the region tells of none. A sheet scrolled into sight stays where
|
|
2627
2727
|
* it was, and nothing else scrolls.
|
|
2628
2728
|
*/
|
|
@@ -2637,7 +2737,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2637
2737
|
}
|
|
2638
2738
|
/**
|
|
2639
2739
|
* The demo as a state has it: the list, laid out at once, so that the sheet's place is the new
|
|
2640
|
-
* one before any scroll is heard
|
|
2740
|
+
* one before any scroll is heard, and the row.
|
|
2641
2741
|
*/
|
|
2642
2742
|
#showDemo(example, state) {
|
|
2643
2743
|
this.#demoState = state;
|
|
@@ -2647,11 +2747,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2647
2747
|
this.#refresh();
|
|
2648
2748
|
}
|
|
2649
2749
|
/**
|
|
2650
|
-
* 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
|
|
2651
2751
|
* the middle of its box, on the line's baseline, at the width the layout gives its text, as the
|
|
2652
2752
|
* lines' texts are; none while the demo is hidden. A value is a text of its own just after its
|
|
2653
2753
|
* box's frame, which a screen reader reads after the box, in the lines' language, as the lines'
|
|
2654
|
-
* texts are (
|
|
2754
|
+
* texts are (WCAG 3.1.2). Only what changed is written.
|
|
2655
2755
|
*/
|
|
2656
2756
|
#showFills(fills) {
|
|
2657
2757
|
const page = this.#laid;
|
|
@@ -2688,12 +2788,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2688
2788
|
text.textContent = value;
|
|
2689
2789
|
}
|
|
2690
2790
|
}
|
|
2691
|
-
/** 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. */
|
|
2692
2792
|
#demoChanged() {
|
|
2693
2793
|
const detail = this.#demoState;
|
|
2694
2794
|
this.dispatchEvent(new CustomEvent(DEMO_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2695
2795
|
}
|
|
2696
|
-
/** 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. */
|
|
2697
2797
|
#nextPart() {
|
|
2698
2798
|
const state = this.#demoState;
|
|
2699
2799
|
if (state === undefined || state.hidden)
|
|
@@ -2701,24 +2801,24 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2701
2801
|
return this.#example?.demo[state.opened];
|
|
2702
2802
|
}
|
|
2703
2803
|
/**
|
|
2704
|
-
* 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,
|
|
2705
2805
|
* and then out from under the consumer's band, --novatrail-canvas-top, should the band cover
|
|
2706
2806
|
* where it came to: what scrolls back up goes back as far as the band covers it. A margin of
|
|
2707
2807
|
* scrolling would hold for every scroller of the chain alike — the sheet's container and the
|
|
2708
2808
|
* page. An area of the sheet taller than what is in sight comes by its top from below, but by its
|
|
2709
|
-
* 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
|
|
2710
2810
|
* buttons covers nothing at the top: it stands at the left edge, and a worked example's row at
|
|
2711
|
-
* 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.
|
|
2712
2812
|
*/
|
|
2713
2813
|
#bringIntoSight(item) {
|
|
2714
2814
|
// A worked example's row of glass stands over the bottom of what is in sight: what comes into
|
|
2715
|
-
// sight from below stops 16 pixels above it
|
|
2815
|
+
// sight from below stops 16 pixels above it.
|
|
2716
2816
|
const { rail, row } = this.#tools;
|
|
2717
2817
|
const under = rail.hidden || row.hidden ? 0 : row.offsetHeight + 32;
|
|
2718
2818
|
item.style.setProperty("scroll-margin-bottom", `${under}px`);
|
|
2719
2819
|
item.scrollIntoView({ block: "nearest", behavior: "instant" });
|
|
2720
2820
|
// A scroller that comes to its top hands the rest on to the next. A scroller goes again only
|
|
2721
|
-
// while each of its scrolls leaves less covered than the last
|
|
2821
|
+
// while each of its scrolls leaves less covered than the last.
|
|
2722
2822
|
const covered = new Map();
|
|
2723
2823
|
for (;;) {
|
|
2724
2824
|
const latch = this.#scrollerFor(false);
|
|
@@ -2734,7 +2834,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2734
2834
|
}
|
|
2735
2835
|
/**
|
|
2736
2836
|
* The row of buttons as the sheet now is: the tools the task allows, the one in use, whether
|
|
2737
|
-
* undo and clearing have anything to do
|
|
2837
|
+
* undo and clearing have anything to do, and a worked example's demo.
|
|
2738
2838
|
*/
|
|
2739
2839
|
#refresh() {
|
|
2740
2840
|
const demo = this.#demoState;
|
|
@@ -2744,6 +2844,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2744
2844
|
tool: this.#tool,
|
|
2745
2845
|
undoable: this.#work.undoable,
|
|
2746
2846
|
clearable: this.#work.strokes.length > 0,
|
|
2847
|
+
larger: PAGE_ZOOM.larger,
|
|
2848
|
+
smaller: PAGE_ZOOM.smaller,
|
|
2747
2849
|
opens: this.#nextPart() !== undefined,
|
|
2748
2850
|
expanded: demo?.hidden !== true,
|
|
2749
2851
|
traced: this.#tracing?.hidden !== true,
|
|
@@ -2755,11 +2857,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2755
2857
|
/**
|
|
2756
2858
|
* The container as a region of its own, a stop of Tab and a name, while its content overflows
|
|
2757
2859
|
* it, and the keyboard scrolls it: in Safari a container that nothing in it can take the focus in
|
|
2758
|
-
* scrolls by no key without (
|
|
2860
|
+
* scrolls by no key without (WebKit's bug 277290). Without a height of its own the
|
|
2759
2861
|
* element scrolls with the page and has no stop of Tab, and neither has one whose task fits. A
|
|
2760
|
-
* 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.
|
|
2761
2863
|
* Across, it scrolls while the sheet is wider than it, and an element without a height has a
|
|
2762
|
-
* region then too
|
|
2864
|
+
* region then too.
|
|
2763
2865
|
*/
|
|
2764
2866
|
#region() {
|
|
2765
2867
|
if (!this.isConnected)
|
|
@@ -2776,11 +2878,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2776
2878
|
* The region's name: the canvas kind's, or a worked example's, in the labels' language, which
|
|
2777
2879
|
* the row's buttons are named in. For a `lang` the labels are not in, the container is in
|
|
2778
2880
|
* theirs, English, and the column, all the container holds, in the element's: the name is said
|
|
2779
|
-
* 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.
|
|
2780
2882
|
* With a `lang` the labels are in, the name is in the element's language already, and both are
|
|
2781
2883
|
* in it, by an attribute of their own: Firefox gives a shadow tree no language of its host, and
|
|
2782
2884
|
* WebKit takes no new one into the tree, though HTML has a node whose parent is a shadow root
|
|
2783
|
-
* take its host's
|
|
2885
|
+
* take its host's. Without a `lang` the element's language is the page's, which no
|
|
2784
2886
|
* attribute could name, and neither has one.
|
|
2785
2887
|
*/
|
|
2786
2888
|
#nameRegion() {
|
|
@@ -2792,7 +2894,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2792
2894
|
write(this.#viewport, "lang", apart ? lang : tag);
|
|
2793
2895
|
write(this.#column, "lang", tag);
|
|
2794
2896
|
}
|
|
2795
|
-
/** 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. */
|
|
2796
2898
|
#rowKind() {
|
|
2797
2899
|
if (this.#example !== undefined)
|
|
2798
2900
|
return "example";
|
|
@@ -2810,7 +2912,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2810
2912
|
}
|
|
2811
2913
|
/**
|
|
2812
2914
|
* The layers show the visible part of the sheet: each `<svg>` layer by its view box, in sheet
|
|
2813
|
-
* 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
|
|
2814
2916
|
* showing a part of the sheet the others have left.
|
|
2815
2917
|
*/
|
|
2816
2918
|
#place(screen) {
|
|
@@ -2835,7 +2937,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2835
2937
|
}
|
|
2836
2938
|
}
|
|
2837
2939
|
/**
|
|
2838
|
-
* 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
|
|
2839
2941
|
* points by the padding, in sheet units, and kept to the sheet by half the frame's line, so that
|
|
2840
2942
|
* a frame at its edge stays whole. A frame the stroke under way comes into fades till the stroke
|
|
2841
2943
|
* lands, and only what has changed is written.
|
|
@@ -2848,8 +2950,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2848
2950
|
const pending = this.#eraser.pending;
|
|
2849
2951
|
const tracing = this.#tracing;
|
|
2850
2952
|
const work = this.#work;
|
|
2851
|
-
// A stroke of the tracing paper is where the paper lies, and out of sight while it is hidden
|
|
2852
|
-
//
|
|
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.
|
|
2853
2955
|
const onScreen = (id) => {
|
|
2854
2956
|
const stroke = pending.has(id) ? undefined : byId.get(id);
|
|
2855
2957
|
if (stroke === undefined)
|
|
@@ -2878,7 +2980,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2878
2980
|
else if (!mark.under) {
|
|
2879
2981
|
// A frame that came or moved while the stroke was under way is checked against all of it.
|
|
2880
2982
|
const points = sameBox(frame, mark.frame) ? fresh : this.#writing.stroke.points;
|
|
2881
|
-
// 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.
|
|
2882
2984
|
const on = this.#writeOn === "tracing" ? this.#tracing : undefined;
|
|
2883
2985
|
const [dx, dy] = on?.at ?? [0, 0];
|
|
2884
2986
|
const by = on === undefined ? 1 : scaleIn(on);
|
|
@@ -2934,7 +3036,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2934
3036
|
this.#writing.seen = live.points.length;
|
|
2935
3037
|
return fresh;
|
|
2936
3038
|
}
|
|
2937
|
-
/** 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. */
|
|
2938
3040
|
#byId() {
|
|
2939
3041
|
const strokes = this.#work.strokes;
|
|
2940
3042
|
if (this.#strokesById.strokes !== strokes) {
|
|
@@ -2954,7 +3056,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2954
3056
|
* The layers in the visible part, and the strokes there, in device pixels: each finished stroke
|
|
2955
3057
|
* by the path it was given once, the stroke under way outlined anew. A stroke whose points lie
|
|
2956
3058
|
* far out of sight is not outlined till it comes into sight: a history given to the sheet may
|
|
2957
|
-
* hold thousands
|
|
3059
|
+
* hold thousands. What the eraser under way has come near is out of sight already, though
|
|
2958
3060
|
* still on the sheet until it lifts. The ink's colour is the canvas's, as the theme makes it.
|
|
2959
3061
|
*/
|
|
2960
3062
|
#draw() {
|
|
@@ -2980,7 +3082,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2980
3082
|
const bottom = screen.vy + screen.height / screen.k;
|
|
2981
3083
|
const erasing = this.#eraser.pending;
|
|
2982
3084
|
// A task from paper's tracing paper: its strokes over the sheet's, moved to where it lies, and
|
|
2983
|
-
// none while it is hidden
|
|
3085
|
+
// none while it is hidden.
|
|
2984
3086
|
const tracing = this.#tracing;
|
|
2985
3087
|
const work = this.#work;
|
|
2986
3088
|
const shown = tracing !== undefined && !tracing.hidden;
|
|
@@ -3013,7 +3115,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
3013
3115
|
if (!shown)
|
|
3014
3116
|
return;
|
|
3015
3117
|
const [dx, dy] = tracing.at;
|
|
3016
|
-
// 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.
|
|
3017
3119
|
const by = scaleIn(tracing);
|
|
3018
3120
|
context.setTransform(across * by, 0, 0, down * by, (dx - screen.vx) * across, (dy - screen.vy) * down);
|
|
3019
3121
|
for (const stroke of traced)
|
|
@@ -3053,7 +3155,7 @@ function near({ x, y }, box, reach) {
|
|
|
3053
3155
|
return (x >= box.minX - reach && x <= box.maxX + reach && y >= box.minY - reach && y <= box.maxY + reach);
|
|
3054
3156
|
}
|
|
3055
3157
|
/**
|
|
3056
|
-
* 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
|
|
3057
3159
|
* are read, each where the layout put it. The item is an `<svg>` of its own place and size, which
|
|
3058
3160
|
* shows what it holds beyond its edges, and its parts lie from its origin: Firefox brings a group
|
|
3059
3161
|
* into view as a point at its origin, and only a box with a size whole.
|
|
@@ -3081,7 +3183,7 @@ function textOf({ text, left, baseline, width }, item) {
|
|
|
3081
3183
|
element.textContent = text;
|
|
3082
3184
|
return element;
|
|
3083
3185
|
}
|
|
3084
|
-
/** 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. */
|
|
3085
3187
|
function rectOf(box, item) {
|
|
3086
3188
|
const rect = document.createElementNS(SVG, "rect");
|
|
3087
3189
|
const { x, y } = fromItem(item, box.left, box.top);
|
|
@@ -3106,7 +3208,7 @@ function coalesced(event) {
|
|
|
3106
3208
|
const events = typeof event.getCoalescedEvents === "function" ? event.getCoalescedEvents() : [];
|
|
3107
3209
|
return events.length > 0 ? events : [event];
|
|
3108
3210
|
}
|
|
3109
|
-
/** What the hands see of a pointer event
|
|
3211
|
+
/** What the hands see of a pointer event: where on the screen, how big, when. */
|
|
3110
3212
|
function contactOf(event) {
|
|
3111
3213
|
return {
|
|
3112
3214
|
pointerId: event.pointerId,
|
|
@@ -3118,7 +3220,7 @@ function contactOf(event) {
|
|
|
3118
3220
|
time: event.timeStamp,
|
|
3119
3221
|
};
|
|
3120
3222
|
}
|
|
3121
|
-
/** 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. */
|
|
3122
3224
|
function owed(latch) {
|
|
3123
3225
|
if (!latch)
|
|
3124
3226
|
return undefined;
|
|
@@ -3248,7 +3350,7 @@ function parentOf(element) {
|
|
|
3248
3350
|
* An element's client box on the screen — what it shows of its content, within its borders and
|
|
3249
3351
|
* without its scroll bar — and how much the page scales it down the screen: 1 unless an ancestor
|
|
3250
3352
|
* transforms it. The sheet's container has one, and so has any ancestor the fingers or
|
|
3251
|
-
* the hand scroll
|
|
3353
|
+
* the hand scroll.
|
|
3252
3354
|
*/
|
|
3253
3355
|
function clientBoxOf(element) {
|
|
3254
3356
|
const box = element.getBoundingClientRect();
|
|
@@ -3261,7 +3363,7 @@ function clientBoxOf(element) {
|
|
|
3261
3363
|
return { left, top, right, bottom, across, down };
|
|
3262
3364
|
}
|
|
3263
3365
|
/**
|
|
3264
|
-
* 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
|
|
3265
3367
|
* ancestor transforms it. `box` is its rectangle on the screen, when the caller has it already.
|
|
3266
3368
|
*/
|
|
3267
3369
|
function scaleOf(element, box, axis = "y") {
|