@altnovatrail/canvas 0.3.37 → 0.3.39
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/geometry.js +2 -2
- package/lib/core/grid.d.ts +11 -4
- package/lib/core/grid.js +33 -8
- package/lib/core/hands.d.ts +14 -7
- package/lib/core/hands.js +58 -7
- package/lib/core/history.js +3 -3
- package/lib/core/marks.d.ts +2 -0
- package/lib/core/marks.js +11 -6
- package/lib/core/notation.d.ts +29 -0
- package/lib/core/notation.js +180 -0
- package/lib/core/screen.d.ts +10 -11
- package/lib/core/screen.js +13 -14
- package/lib/core/sheet.d.ts +46 -3
- package/lib/core/sheet.js +46 -3
- package/lib/core/submission.js +5 -1
- package/lib/core/task.d.ts +9 -4
- package/lib/core/task.js +7 -2
- package/lib/core/tracing.d.ts +49 -13
- package/lib/core/tracing.js +110 -31
- package/lib/core/zoom.d.ts +19 -8
- package/lib/core/zoom.js +36 -15
- package/lib/element/icons.d.ts +90 -5
- package/lib/element/icons.js +94 -5
- package/lib/element/index.d.ts +32 -13
- package/lib/element/index.js +712 -240
- package/lib/element/labels.d.ts +30 -5
- package/lib/element/labels.js +32 -5
- package/lib/element/notation.d.ts +2 -0
- package/lib/element/notation.js +94 -0
- package/lib/element/session.js +4 -4
- package/lib/element/tools.d.ts +31 -16
- package/lib/element/tools.js +87 -54
- package/lib/element/tracing.d.ts +49 -5
- package/lib/element/tracing.js +446 -10
- package/package.json +3 -3
package/lib/element/index.js
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
// action, and the work for checking is the crop with the context of its submission (R27). Over it
|
|
14
14
|
// all stand the element's own buttons — the tools the task allows, undo and clearing —, labelled
|
|
15
15
|
// in the element's `lang` (R28), on a vertical bar of glass at its left edge (R84). On a tablet a
|
|
16
|
-
// pen's touch puts the page in pen mode, where a finger writes nothing
|
|
17
|
-
//
|
|
16
|
+
// pen's touch puts the page in pen mode, where a finger writes nothing, a palm writes nothing, and
|
|
17
|
+
// two fingers scroll (R29), one finger too (R84).
|
|
18
18
|
// The task comes in the names of the module format 0.4, checked as its schema checks it, and the
|
|
19
19
|
// module's manifest gives the height of a digit and the statement's language (R32; R60).
|
|
20
20
|
//
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
// crop of each filled box, with the table of the boxes' strokes for its context (R38).
|
|
26
26
|
//
|
|
27
27
|
// A lesson's worked example it shows on a sheet the learner does not write on: its statement above
|
|
28
|
-
// the sheet, its grid, and
|
|
29
|
-
//
|
|
28
|
+
// the sheet, its grid, and no bar, while a finger or a pen scrolls the sheet as the browser scrolls
|
|
29
|
+
// the statement. The parts of its demo the learner opens one at a time
|
|
30
30
|
// with Next, into a list above the sheet that a polite region tells a screen reader of, and hides
|
|
31
31
|
// and shows with Demo; app keeps how far the learner has gone by `demoState` and `demochange`. The
|
|
32
32
|
// pictures of the statement and of the demo come from the consumer's media, one file for each
|
|
@@ -39,22 +39,23 @@
|
|
|
39
39
|
// The keyboard goes into the sheet and out: a container that scrolls is a region named by the
|
|
40
40
|
// canvas kind, with a stop of Tab of its own and a ring when the keyboard brings the focus there
|
|
41
41
|
// (R33); for a `lang` the labels are not in, the container is in theirs and the column in the
|
|
42
|
-
// element's (R74).
|
|
43
|
-
//
|
|
44
|
-
// (R73).
|
|
42
|
+
// element's (R74). The sheet goes on past the task's page, which stands at its left, right and
|
|
43
|
+
// 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 (R73; R88).
|
|
45
45
|
//
|
|
46
|
-
// A task from the learner's paper it shows on a
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
46
|
+
// 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 (R88), with the task's crop over it as tracing paper,
|
|
48
|
+
// which the learner moves by its grip, hides and shows by the button atop the tools, and writes on
|
|
49
|
+
// as on the sheet: a stroke begun on the paper is the paper's and moves with it, and an erasing
|
|
50
|
+
// 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 (R87).
|
|
51
52
|
import { cellOf, cellsOf, filledOf, sheetFilledOf } from "../core/boxes.js";
|
|
52
53
|
import { Clock } from "../core/clock.js";
|
|
53
54
|
import { ERASER_BUTTON, Eraser } from "../core/eraser.js";
|
|
54
55
|
import { DEMO_START, demoStateOf, exampleOf, exampleTemplate, filledBy, fillValue, sameExample, } from "../core/example.js";
|
|
55
56
|
import { sameItems } from "../core/fields.js";
|
|
56
57
|
import { boxOf } from "../core/geometry.js";
|
|
57
|
-
import { GRID_STEP, gridPath } from "../core/grid.js";
|
|
58
|
+
import { GRID_STEP, gridBand, gridPath } from "../core/grid.js";
|
|
58
59
|
import { Hands } from "../core/hands.js";
|
|
59
60
|
import { begins, sameHistory } from "../core/history.js";
|
|
60
61
|
import { NO_MANIFEST, settingsOf } from "../core/manifest.js";
|
|
@@ -64,11 +65,12 @@ import { isBox, LAYOUT, pieceWidth, } from "../core/page.js";
|
|
|
64
65
|
import { encodePNG } from "../core/png.js";
|
|
65
66
|
import { Recorder } from "../core/recorder.js";
|
|
66
67
|
import { fitScale, K_MAX, scaleFor, toSheet } from "../core/screen.js";
|
|
67
|
-
import { SHEET } from "../core/sheet.js";
|
|
68
|
+
import { extentOf, pictureOf, REACH, SHEET } from "../core/sheet.js";
|
|
68
69
|
import { cellsForCheck, paperWorkForCheck, workForCheck } from "../core/submission.js";
|
|
69
|
-
import { isTool, isWorkbook, NO_TASK, sameLayer, sameStatement, taskOf, templateOf, wholeSheet, } from "../core/task.js";
|
|
70
|
-
import { boxOnSheet, keptOn, layOver, onSheet, onTracing, sameTracing, TRACING, TRACING_START, toTracing, rectOf as tracingRect, tracingStateOf, whollyOff, } from "../core/tracing.js";
|
|
70
|
+
import { HAND, isTool, isWorkbook, NO_TASK, sameLayer, sameStatement, taskOf, templateOf, wholeSheet, } from "../core/task.js";
|
|
71
|
+
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";
|
|
71
72
|
import { nextIdOf, resumeOf, Work } from "../core/work.js";
|
|
73
|
+
import { ZOOM_MIN, ZOOM_STEP } from "../core/zoom.js";
|
|
72
74
|
import { placeOver, SVG, write } from "./attributes.js";
|
|
73
75
|
import { knows, labelsFor, say, sayAround } from "./labels.js";
|
|
74
76
|
import { Parts } from "./parts.js";
|
|
@@ -98,9 +100,12 @@ const TOOL_CHANGE = "toolchange";
|
|
|
98
100
|
const DEMO_CHANGE = "demochange";
|
|
99
101
|
/** The event the element sends when the learner moves the tracing paper, or hides or shows it. */
|
|
100
102
|
const TRACING_CHANGE = "tracingchange";
|
|
103
|
+
const TRACING_READ = "tracingread";
|
|
104
|
+
/** The event the element sends when the learner turns a task from paper's grid with its button. */
|
|
105
|
+
const GRID_CHANGE = "gridchange";
|
|
101
106
|
/**
|
|
102
|
-
* A task from paper's template:
|
|
103
|
-
* spec).
|
|
107
|
+
* A task from paper's template: no statement, the pen and the eraser, and a dotted sheet, as the
|
|
108
|
+
* task comes, whose grid the learner turns (R87; R88; R162 spec).
|
|
104
109
|
*/
|
|
105
110
|
const PAPER_TEMPLATE = Object.freeze({
|
|
106
111
|
grid: Object.freeze({ kind: "dots", step: TRACING.dots }),
|
|
@@ -151,51 +156,55 @@ const MARK_CORNER = 6;
|
|
|
151
156
|
* the sheet's scale (R22).
|
|
152
157
|
*/
|
|
153
158
|
const ERASER_RADIUS_PX = 10;
|
|
154
|
-
// The statement and the sheet stand in a column of their own,
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
// in the
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
//
|
|
185
|
-
// (
|
|
186
|
-
//
|
|
187
|
-
//
|
|
188
|
-
//
|
|
189
|
-
//
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
//
|
|
159
|
+
// The statement and the sheet stand in a column of their own, and scroll in a container of their
|
|
160
|
+
// own, by the browser's own scrolling: the wheel, the scroll bar and the keyboard work as anywhere
|
|
161
|
+
// on a page. The task's page is as wide as the element up to 1000 CSS pixels and stands at the
|
|
162
|
+
// sheet's left; the sheet goes on past it as far as `#extent` says, and the container scrolls it
|
|
163
|
+
// across too, left to right whatever the page's direction, while the statement and a demo's parts
|
|
164
|
+
// stay as wide as the page and stick to its left, in the element's own direction: they scroll down
|
|
165
|
+
// alone (R73). The layers of the sheet stand in its visible part, the stage, which sticks to the
|
|
166
|
+
// container's top and left, and each shows what lies there, shifted in the frame the ink is drawn
|
|
167
|
+
// in (R18, R23). Over the container, in the same cell of the frame's grid, stands the rail of the
|
|
168
|
+
// element's own buttons: a band as tall as the part of the element in sight and as wide as nothing,
|
|
169
|
+
// sticking to the top of whatever scrolls the element, as far down as the consumer's
|
|
170
|
+
// --novatrail-canvas-top says, and up to its bottom less --novatrail-canvas-pad-bottom, and in its
|
|
171
|
+
// middle, 16 pixels from the left edge, the bar of buttons: 52 pixels wide, round at its ends, of
|
|
172
|
+
// the mockup's glass — the fill the consumer's theme gives, blurred behind, or the paper alone
|
|
173
|
+
// where nothing blurs — over the sheet as it scrolls by (R84; R148 spec). A bar taller than the
|
|
174
|
+
// band scrolls inside its glass (WCAG 1.4.10). A worked example has no bar, and its Next and Demo
|
|
175
|
+
// stand in a row of the same glass at the band's bottom, the consumer's buttons of the slot actions
|
|
176
|
+
// after them (R84). The tool in use is filled with the accent at an eighth, its icon in the accent;
|
|
177
|
+
// a button in focus shows a ring in the accent; an unavailable one is paler by its colour, not its
|
|
178
|
+
// opacity, which would pale the ring too (WCAG 2.4.7, 1.4.11). A button's tooltip stands beside it,
|
|
179
|
+
// white on near-black, as the mockup has it. Nothing in the element moves but the scrolling, which
|
|
180
|
+
// jumps, and no tooltip fades (WCAG 2.3.3). The element is as tall as the statement and the sheet
|
|
181
|
+
// unless it is given a height: then the statement and the sheet scroll in it, under the bar. A
|
|
182
|
+
// consumer whose own bars float over the element's top and bottom says how far by
|
|
183
|
+
// --novatrail-canvas-pad-top and -bottom: the statement starts below the first, and the sheet
|
|
184
|
+
// scrolls up past the second (R73). A worked example's open parts stand between the statement and
|
|
185
|
+
// the sheet, and the region that tells of them is out of sight, but not out of the tree a screen
|
|
186
|
+
// reader reads, where a hidden region would tell nothing (R42). A picture's frame there stands in
|
|
187
|
+
// its item's line, from its top, so that the item's number stands at the top too, as a paragraph's
|
|
188
|
+
// does, and not at the picture's bottom. A picture on an area of the sheet stands on the layer of
|
|
189
|
+
// the author's demo, and the sheet scrolls to a hidden box of the area in its own flow, which
|
|
190
|
+
// neither paints nor takes a pointer (R42). On the canvas the browser neither scrolls nor zooms:
|
|
191
|
+
// the pointer writes, or with the hand moves the sheet, and two fingers scroll by the element's own
|
|
192
|
+
// code (R29), and in pen mode one finger too (R84; R88). The canvas and the buttons take pointer
|
|
193
|
+
// events only as the element does: a consumer's pointer-events: none on the element stops the
|
|
194
|
+
// writing and the buttons' pointer, though not their keys (R20, R28). A worked example's canvas
|
|
195
|
+
// takes no pointer at all: a finger or a pen on its sheet scrolls, and zooms, as the browser does
|
|
196
|
+
// on the statement, and a long press or a right click opens no menu over the sheet all the same
|
|
197
|
+
// (R42). The theme is the consumer's, by custom properties that the shadow tree inherits; with
|
|
198
|
+
// forced colours the system's colours stand in for them. The element is horizontal whatever writing
|
|
199
|
+
// mode the page is in: a sheet has no other (R36).
|
|
193
200
|
//
|
|
194
201
|
// A workbook's lines are printed in the ink's colour and the consumer's font, and nothing else the
|
|
195
202
|
// element inherits — spacing, weight, transforms, the direction — moves them: `all: initial` takes
|
|
196
203
|
// it off, and what the print needs comes back (R36). A box's frame is one CSS pixel at any scale,
|
|
197
204
|
// on whole device pixels: an antialiased line of one pixel would lose its contrast. A filled box's
|
|
198
|
-
// is three, in the same ink, and the system's highlight with forced colours (R37).
|
|
205
|
+
// is three, in the same ink, and the system's highlight with forced colours (R37). A dot of the grid
|
|
206
|
+
// is three pixels across at the fit and above it, and smaller by the zoom below it, so that a sheet
|
|
207
|
+
// zoomed out is no field of dots (R73).
|
|
199
208
|
const STYLE = `
|
|
200
209
|
:host { display: flex; flex-direction: column; isolation: isolate; writing-mode: horizontal-tb; }
|
|
201
210
|
:host([hidden]) { display: none; }
|
|
@@ -204,19 +213,23 @@ const STYLE = `
|
|
|
204
213
|
grid-template: minmax(0, 1fr) / minmax(0, 1fr);
|
|
205
214
|
}
|
|
206
215
|
.viewport {
|
|
207
|
-
grid-area: 1 / 1; min-height: 0; overflow
|
|
208
|
-
outline: none; -webkit-tap-highlight-color: transparent;
|
|
216
|
+
grid-area: 1 / 1; min-height: 0; overflow: auto; overflow-anchor: none; direction: ltr;
|
|
217
|
+
scrollbar-width: none; outline: none; -webkit-tap-highlight-color: transparent;
|
|
209
218
|
}
|
|
210
219
|
.rail {
|
|
211
220
|
grid-area: 1 / 1; align-self: start; justify-self: left; width: 0; direction: ltr;
|
|
212
221
|
position: sticky; top: var(--rail-top, var(--novatrail-canvas-top, 0px)); z-index: 1;
|
|
213
222
|
box-sizing: border-box; padding: 16px 0;
|
|
214
|
-
height: min(
|
|
223
|
+
height: min(
|
|
224
|
+
100%,
|
|
225
|
+
var(--rail-room, 100dvh) - var(--rail-top, var(--novatrail-canvas-top, 0px)) -
|
|
226
|
+
var(--novatrail-canvas-pad-bottom, 0px)
|
|
227
|
+
);
|
|
215
228
|
display: flex; align-items: center;
|
|
216
229
|
}
|
|
217
230
|
.rail[hidden] { display: none; }
|
|
218
231
|
.rail.example { padding-bottom: 88px; }
|
|
219
|
-
.tools {
|
|
232
|
+
.tools, .tracing-scale {
|
|
220
233
|
box-sizing: border-box; flex: none; width: 52px; max-height: 100%;
|
|
221
234
|
margin: 0 0 0 16px; padding: 4px; border-radius: 26px;
|
|
222
235
|
display: flex; flex-direction: column; align-items: center; gap: 2px;
|
|
@@ -228,7 +241,7 @@ const STYLE = `
|
|
|
228
241
|
0 1px 2px rgba(0, 0, 0, 0.04);
|
|
229
242
|
}
|
|
230
243
|
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
|
|
231
|
-
.tools { background: var(--novatrail-canvas-paper, ${PAPER}); }
|
|
244
|
+
.tools, .tracing-scale { background: var(--novatrail-canvas-paper, ${PAPER}); }
|
|
232
245
|
}
|
|
233
246
|
.tools:dir(rtl) { direction: rtl; }
|
|
234
247
|
.tools.row {
|
|
@@ -237,20 +250,20 @@ const STYLE = `
|
|
|
237
250
|
max-height: none; margin: 0; padding: 6px; border-radius: 28px; flex-direction: row; gap: 4px;
|
|
238
251
|
overflow-x: auto; overflow-y: hidden;
|
|
239
252
|
}
|
|
240
|
-
.tools .choice
|
|
241
|
-
.tools .line {
|
|
253
|
+
.tools .choice { display: flex; flex-direction: column; gap: 2px; flex: none; }
|
|
254
|
+
:is(.tools, .tracing-scale) .line {
|
|
242
255
|
flex: none; width: 24px; height: 1px; margin: 4px 0; background: rgba(0, 0, 0, 0.1);
|
|
243
256
|
}
|
|
244
257
|
.tools.row .line { width: 1px; height: 24px; margin: 0 4px; }
|
|
245
258
|
.tools.row ::slotted(*) { flex: none; }
|
|
246
|
-
.tools button {
|
|
259
|
+
:is(.tools, .tracing-scale) button {
|
|
247
260
|
box-sizing: border-box; flex: none; min-width: 44px; min-height: 44px; margin: 0;
|
|
248
261
|
padding: 0 14px 0 10px; display: flex; align-items: center; justify-content: center; gap: 6px;
|
|
249
262
|
font: inherit; font-weight: 500; white-space: nowrap; color: inherit; background: transparent;
|
|
250
263
|
cursor: pointer; border: none; border-radius: 22px;
|
|
251
264
|
}
|
|
252
|
-
.tools button.icon { width: 44px; height: 44px; padding: 0; }
|
|
253
|
-
.tools button.icon .label {
|
|
265
|
+
:is(.tools, .tracing-scale) button.icon { width: 44px; height: 44px; padding: 0; }
|
|
266
|
+
:is(.tools, .tracing-scale) button.icon .label {
|
|
254
267
|
position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
|
|
255
268
|
overflow: hidden; clip-path: inset(50%); white-space: nowrap;
|
|
256
269
|
}
|
|
@@ -258,21 +271,21 @@ const STYLE = `
|
|
|
258
271
|
background: color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 12%, transparent);
|
|
259
272
|
color: var(--novatrail-canvas-accent, ${ACCENT});
|
|
260
273
|
}
|
|
261
|
-
.tools button:focus-visible {
|
|
274
|
+
:is(.tools, .tracing-scale) button:focus-visible {
|
|
262
275
|
outline: 2px solid var(--novatrail-canvas-accent, ${ACCENT}); outline-offset: 0;
|
|
263
276
|
}
|
|
264
|
-
.tools [aria-disabled="true"] {
|
|
277
|
+
:is(.tools, .tracing-scale) [aria-disabled="true"] {
|
|
265
278
|
color: color-mix(
|
|
266
279
|
in srgb, var(--novatrail-canvas-ink, ${INK}) 40%, var(--novatrail-canvas-paper, ${PAPER})
|
|
267
280
|
);
|
|
268
281
|
cursor: default;
|
|
269
282
|
}
|
|
270
283
|
@supports not (color: color-mix(in srgb, red 40%, blue)) {
|
|
271
|
-
.tools [aria-disabled="true"] { opacity: 0.4; }
|
|
284
|
+
:is(.tools, .tracing-scale) [aria-disabled="true"] { opacity: 0.4; }
|
|
272
285
|
.tools [aria-checked="true"] { background: transparent; }
|
|
273
286
|
}
|
|
274
|
-
.tools[hidden], .tools [hidden] { display: none; }
|
|
275
|
-
.tools button svg { display: block; flex: none; width: 20px; height: 20px; fill: currentColor; }
|
|
287
|
+
.tools[hidden], :is(.tools, .tracing-scale) [hidden] { display: none; }
|
|
288
|
+
:is(.tools, .tracing-scale) button svg { display: block; flex: none; width: 20px; height: 20px; fill: currentColor; }
|
|
276
289
|
.tools:dir(rtl) svg.mirrored { transform: scaleX(-1); }
|
|
277
290
|
.tip {
|
|
278
291
|
position: absolute; left: var(--tip-x, 76px); top: var(--tip-y, 0px); z-index: 2;
|
|
@@ -281,21 +294,35 @@ const STYLE = `
|
|
|
281
294
|
background: #1d1d1f; color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
|
|
282
295
|
}
|
|
283
296
|
.tip[hidden] { display: none; }
|
|
284
|
-
.viewport.zoomed { overflow-x: auto; direction: ltr; }
|
|
285
297
|
.ring { position: absolute; inset: 0; z-index: 0; pointer-events: none; display: none; }
|
|
286
298
|
.viewport:focus-visible + .ring {
|
|
287
299
|
display: block; outline: 2px solid var(--novatrail-canvas-ink, ${INK}); outline-offset: -2px;
|
|
288
300
|
}
|
|
289
301
|
.column {
|
|
290
|
-
position: relative;
|
|
291
|
-
|
|
302
|
+
position: relative;
|
|
303
|
+
width: calc(min(100%, ${K_MAX * SHEET.width}px) * var(--zoom, 1) * var(--across, 1));
|
|
304
|
+
padding-block: var(--novatrail-canvas-pad-top, 0px) var(--novatrail-canvas-pad-bottom, 0px);
|
|
292
305
|
}
|
|
293
|
-
.
|
|
294
|
-
position: sticky; left: 0; box-sizing: border-box;
|
|
306
|
+
.statement, .parts {
|
|
307
|
+
position: sticky; left: 0; box-sizing: border-box;
|
|
308
|
+
width: calc(100% / (var(--zoom, 1) * var(--across, 1)));
|
|
295
309
|
direction: var(--direction, ltr);
|
|
296
310
|
}
|
|
297
311
|
.statement { padding: 0 0 12px; overflow-wrap: break-word; }
|
|
298
312
|
.statement:empty { display: none; }
|
|
313
|
+
.band {
|
|
314
|
+
position: absolute; left: 0; display: none; width: 100%; overflow: visible; pointer-events: none;
|
|
315
|
+
background: var(--novatrail-canvas-paper, ${PAPER});
|
|
316
|
+
}
|
|
317
|
+
.band.above {
|
|
318
|
+
--pad: var(--novatrail-canvas-pad-top, 0px);
|
|
319
|
+
top: 0; height: var(--pad); clip-path: inset(0 0 calc(-1 * min(2px, var(--pad))) 0);
|
|
320
|
+
}
|
|
321
|
+
.band.below {
|
|
322
|
+
--pad: var(--novatrail-canvas-pad-bottom, 0px);
|
|
323
|
+
bottom: 0; height: var(--pad); clip-path: inset(calc(-1 * min(2px, var(--pad))) 0 0 0);
|
|
324
|
+
}
|
|
325
|
+
.statement:empty ~ .band.above, .band.below { display: block; }
|
|
299
326
|
.statement p { margin: 0 0 8px; }
|
|
300
327
|
.picture {
|
|
301
328
|
box-sizing: border-box; max-width: 100%; margin: 0 0 8px; padding: 8px;
|
|
@@ -327,7 +354,7 @@ const STYLE = `
|
|
|
327
354
|
fill: none; stroke: var(--novatrail-canvas-grid, #d3dbe5); stroke-width: 1px;
|
|
328
355
|
vector-effect: non-scaling-stroke;
|
|
329
356
|
}
|
|
330
|
-
.grid.dots { stroke-width: 3px; stroke-linecap: round; }
|
|
357
|
+
.grid.dots { stroke-width: calc(3px * min(1, var(--zoom, 1))); stroke-linecap: round; }
|
|
331
358
|
.print {
|
|
332
359
|
all: initial; font-family: inherit; visibility: inherit; pointer-events: none; direction: ltr;
|
|
333
360
|
font-variant-numeric: tabular-nums; font-size: ${LAYOUT.size}px;
|
|
@@ -344,6 +371,8 @@ canvas {
|
|
|
344
371
|
touch-action: none;
|
|
345
372
|
}
|
|
346
373
|
.sheet.example canvas { pointer-events: none; touch-action: auto; }
|
|
374
|
+
.sheet.hand canvas { cursor: grab; }
|
|
375
|
+
.sheet.panning canvas { cursor: grabbing; }
|
|
347
376
|
.tracing { mix-blend-mode: multiply; }
|
|
348
377
|
.tracing .edge {
|
|
349
378
|
fill: none; stroke: rgba(60, 60, 67, 0.3); stroke-width: 1px; vector-effect: non-scaling-stroke;
|
|
@@ -361,7 +390,96 @@ canvas {
|
|
|
361
390
|
.grip.dragging { cursor: grabbing; }
|
|
362
391
|
.grip.dragging .bar { background: var(--novatrail-canvas-accent, ${ACCENT}); }
|
|
363
392
|
.grip:focus-visible { outline: 2px solid var(--novatrail-canvas-accent, ${ACCENT}); }
|
|
364
|
-
.stage > .tip {
|
|
393
|
+
.stage > .tip {
|
|
394
|
+
inset: var(--tip-y, 0px) auto auto var(--tip-x, 0px); width: auto; height: auto;
|
|
395
|
+
pointer-events: none;
|
|
396
|
+
}
|
|
397
|
+
.stage > .tracing-cover, .stage > .tracing-frame { inset: 0 auto auto 0; box-sizing: border-box; }
|
|
398
|
+
.stage > .tracing-cover[hidden], .stage > .tracing-frame[hidden], .stage > .tracing-sign[hidden],
|
|
399
|
+
.stage > .tracing-scale[hidden], .tracing-cover [hidden] { display: none; }
|
|
400
|
+
.statements {
|
|
401
|
+
position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
|
|
402
|
+
justify-content: center; gap: 0.2em; font-weight: 500; line-height: 1.2;
|
|
403
|
+
letter-spacing: -0.02em; white-space: nowrap; direction: ltr;
|
|
404
|
+
color: var(--novatrail-canvas-ink, ${INK});
|
|
405
|
+
}
|
|
406
|
+
.statements .slot {
|
|
407
|
+
box-sizing: border-box; border-radius: 0.2em;
|
|
408
|
+
border: max(2px, 0.04em) dashed var(--novatrail-canvas-accent, ${ACCENT});
|
|
409
|
+
}
|
|
410
|
+
.statements span.slot {
|
|
411
|
+
display: inline-block; width: 1.08em; height: 1.08em; margin: 0 0.18em; vertical-align: -0.22em;
|
|
412
|
+
}
|
|
413
|
+
.statements mspace.slot { margin: 0 0.1em; }
|
|
414
|
+
.statements math { font-family: inherit; font-size: inherit; color: inherit; }
|
|
415
|
+
.scan {
|
|
416
|
+
position: absolute; inset: 0; overflow: hidden;
|
|
417
|
+
background: color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 4%, transparent);
|
|
418
|
+
}
|
|
419
|
+
.scan i {
|
|
420
|
+
position: absolute; top: 0; bottom: 0; left: -30%; width: 30%;
|
|
421
|
+
background: linear-gradient(90deg, transparent,
|
|
422
|
+
color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 18%, transparent), transparent);
|
|
423
|
+
left: 35%;
|
|
424
|
+
}
|
|
425
|
+
/* The line runs through the middle of its glow, so the glow is the same on both sides of it. */
|
|
426
|
+
.scan i::after {
|
|
427
|
+
content: ""; position: absolute; top: 0; bottom: 0; left: calc(50% - 1px); width: 2px;
|
|
428
|
+
background: color-mix(in srgb, var(--novatrail-canvas-accent, ${ACCENT}) 60%, transparent);
|
|
429
|
+
}
|
|
430
|
+
@keyframes novatrail-scan { from { left: -30%; } to { left: 100%; } }
|
|
431
|
+
@keyframes novatrail-spin { to { transform: rotate(360deg); } }
|
|
432
|
+
.tracing-frame {
|
|
433
|
+
border: 1.5px solid var(--novatrail-canvas-accent, ${ACCENT}); border-radius: var(--round, 6px);
|
|
434
|
+
}
|
|
435
|
+
.tracing-frame .corner {
|
|
436
|
+
position: absolute; width: 44px; height: 44px; margin: -22px; pointer-events: auto;
|
|
437
|
+
touch-action: none;
|
|
438
|
+
}
|
|
439
|
+
.tracing-frame .corner::after {
|
|
440
|
+
content: ""; position: absolute; inset: 13px; box-sizing: border-box; border-radius: 50%;
|
|
441
|
+
background: #fff; border: 2px solid var(--novatrail-canvas-accent, ${ACCENT});
|
|
442
|
+
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
|
|
443
|
+
}
|
|
444
|
+
.tracing-frame .tl { left: 0; top: 0; cursor: nwse-resize; }
|
|
445
|
+
.tracing-frame .tr { left: 100%; top: 0; cursor: nesw-resize; }
|
|
446
|
+
.tracing-frame .bl { left: 0; top: 100%; cursor: nesw-resize; }
|
|
447
|
+
.tracing-frame .br { left: 100%; top: 100%; cursor: nwse-resize; }
|
|
448
|
+
.stage > .tracing-sign {
|
|
449
|
+
inset: 0 auto auto 0; width: auto; height: 24px; box-sizing: border-box; padding: 0 10px;
|
|
450
|
+
display: flex; align-items: center; gap: 6px; border-radius: 999px; white-space: nowrap;
|
|
451
|
+
font-size: 12px; font-weight: 600; background: #f2f2f2; color: #6e6e73;
|
|
452
|
+
}
|
|
453
|
+
.stage > .tracing-sign[data-shows="busy"], .stage > .tracing-sign[data-shows="text"] {
|
|
454
|
+
background: #e5f0ff; color: #0058b8;
|
|
455
|
+
}
|
|
456
|
+
.tracing-sign svg { display: block; width: 12px; height: 12px; fill: currentColor; }
|
|
457
|
+
.spinner {
|
|
458
|
+
display: block; box-sizing: border-box; width: 12px; height: 12px; border-radius: 50%;
|
|
459
|
+
border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
|
|
460
|
+
}
|
|
461
|
+
.stage > .tracing-scale {
|
|
462
|
+
inset: var(--bar-y, 0px) auto auto var(--bar-x, 0px); transform: translateX(-50%);
|
|
463
|
+
width: max-content; height: auto; max-height: none; margin: 0; padding: 4px;
|
|
464
|
+
flex-direction: row; gap: 2px; pointer-events: auto; overflow: visible;
|
|
465
|
+
}
|
|
466
|
+
.tracing-scale .line { width: 1px; height: 24px; margin: 0 4px; }
|
|
467
|
+
.tracing-scale .percent { min-width: 64px; padding: 0 8px; font-variant-numeric: tabular-nums; }
|
|
468
|
+
.tracing-scale .mode {
|
|
469
|
+
background: var(--novatrail-canvas-accent, ${ACCENT}); color: #fff; margin-inline-start: 2px;
|
|
470
|
+
}
|
|
471
|
+
.tracing-scale .mode.busy { background: #e5f0ff; color: #0058b8; cursor: default; }
|
|
472
|
+
.tracing-scale .mode.busy svg { display: none; }
|
|
473
|
+
.tracing-scale .mode.busy::before {
|
|
474
|
+
content: ""; display: block; box-sizing: border-box; width: 15px; height: 15px; border-radius: 50%;
|
|
475
|
+
border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
|
|
476
|
+
}
|
|
477
|
+
.tracing-scale .mode.back { background: #f2f2f7; color: var(--novatrail-canvas-ink, ${INK}); }
|
|
478
|
+
/* The one motion: a wait for the reading the learner asked for, and only to whom it is no harm (R89). */
|
|
479
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
480
|
+
.scan i { animation: novatrail-scan 1s ease-in-out infinite; }
|
|
481
|
+
.spinner, .tracing-scale .mode.busy::before { animation: novatrail-spin 0.8s linear infinite; }
|
|
482
|
+
}
|
|
365
483
|
.marks rect {
|
|
366
484
|
fill: none; stroke: var(--novatrail-canvas-mark, ${MARK}); stroke-width: 2px;
|
|
367
485
|
vector-effect: non-scaling-stroke;
|
|
@@ -394,17 +512,32 @@ canvas {
|
|
|
394
512
|
.tracing .edge { stroke: CanvasText; }
|
|
395
513
|
.grip .bar, .grip.dragging .bar { background: ButtonText; }
|
|
396
514
|
.grip:focus-visible { outline-color: Highlight; }
|
|
397
|
-
.
|
|
398
|
-
.
|
|
399
|
-
.
|
|
515
|
+
.tracing-frame { border-color: Highlight; }
|
|
516
|
+
.tracing-frame .corner::after { background: Canvas; border-color: Highlight; }
|
|
517
|
+
.statements { color: CanvasText; }
|
|
518
|
+
.statements .slot { border-color: CanvasText; }
|
|
519
|
+
.scan { background: transparent; }
|
|
520
|
+
.scan i { background: transparent; }
|
|
521
|
+
.scan i::after { background: Highlight; }
|
|
522
|
+
.stage > .tracing-sign, .stage > .tracing-sign[data-shows] {
|
|
523
|
+
background: Canvas; color: CanvasText; border: 1px solid CanvasText;
|
|
524
|
+
}
|
|
525
|
+
.tracing-scale .mode, .tracing-scale .mode.busy, .tracing-scale .mode.back {
|
|
526
|
+
background: ButtonFace; color: ButtonText; border: 1px solid ButtonBorder;
|
|
527
|
+
}
|
|
528
|
+
.tools, .tracing-scale { background: Canvas; color: CanvasText; border: 1px solid CanvasText; }
|
|
529
|
+
:is(.tools, .tracing-scale) .line { background: CanvasText; }
|
|
530
|
+
:is(.tools, .tracing-scale) button {
|
|
400
531
|
background: ButtonFace; color: ButtonText; border: 1px solid ButtonBorder;
|
|
401
532
|
}
|
|
402
533
|
.tools [aria-checked="true"] {
|
|
403
534
|
background: Highlight; color: HighlightText; border-color: Highlight;
|
|
404
535
|
}
|
|
405
|
-
.tools [aria-disabled="true"] { color: GrayText; border-color: GrayText; }
|
|
536
|
+
:is(.tools, .tracing-scale) [aria-disabled="true"] { color: GrayText; border-color: GrayText; }
|
|
406
537
|
.tip { background: Canvas; color: CanvasText; border: 1px solid CanvasText; }
|
|
407
|
-
.tools button:focus-visible, .viewport:focus-visible + .ring {
|
|
538
|
+
:is(.tools, .tracing-scale) button:focus-visible, .viewport:focus-visible + .ring {
|
|
539
|
+
outline-color: Highlight;
|
|
540
|
+
}
|
|
408
541
|
}
|
|
409
542
|
`;
|
|
410
543
|
/** The sheet of STYLE that the elements of a document adopt, made by the first of them there. */
|
|
@@ -492,11 +625,11 @@ function wavyNode() {
|
|
|
492
625
|
* trough, kept to the sheet by `half` its line.
|
|
493
626
|
*/
|
|
494
627
|
function wavyAt(box, half) {
|
|
495
|
-
const y = Math.min(box.maxY + WAVY_BELOW,
|
|
628
|
+
const y = Math.min(box.maxY + WAVY_BELOW, REACH.height - WAVY_CREST - half);
|
|
496
629
|
return {
|
|
497
630
|
minX: Math.max(box.minX - WAVY_REACH, half),
|
|
498
631
|
minY: y - WAVY_CREST,
|
|
499
|
-
maxX: Math.min(box.maxX + WAVY_REACH,
|
|
632
|
+
maxX: Math.min(box.maxX + WAVY_REACH, REACH.width - half),
|
|
500
633
|
maxY: y + WAVY_CREST,
|
|
501
634
|
};
|
|
502
635
|
}
|
|
@@ -519,8 +652,8 @@ function wavyPath({ minX, minY, maxX, maxY }) {
|
|
|
519
652
|
*/
|
|
520
653
|
function verdictAt(box, k) {
|
|
521
654
|
const size = VERDICT_PX / k;
|
|
522
|
-
const minX = Math.min(Math.max(box.maxX + VERDICT_GAP_PX / k, 0),
|
|
523
|
-
const minY = Math.min(Math.max((box.minY + box.maxY - size) / 2, 0),
|
|
655
|
+
const minX = Math.min(Math.max(box.maxX + VERDICT_GAP_PX / k, 0), REACH.width - size);
|
|
656
|
+
const minY = Math.min(Math.max((box.minY + box.maxY - size) / 2, 0), REACH.height - size);
|
|
524
657
|
return { minX, minY, maxX: minX + size, maxY: minY + size };
|
|
525
658
|
}
|
|
526
659
|
/** An HTML layer of the sheet, for the module's widget from stage 4: empty till then. */
|
|
@@ -550,6 +683,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
550
683
|
/** The author's template: a sheet's grid, or a workbook's lines, a list of its items (R36). */
|
|
551
684
|
#template = svgLayer("template");
|
|
552
685
|
#grid = document.createElementNS(SVG, "path");
|
|
686
|
+
/** The grid going on above the sheet and below it, under the consumer's floating bars (R73). */
|
|
687
|
+
#above = document.createElementNS(SVG, "svg");
|
|
688
|
+
#below = document.createElementNS(SVG, "svg");
|
|
553
689
|
#print = document.createElementNS(SVG, "g");
|
|
554
690
|
#lines = document.createElementNS(SVG, "g");
|
|
555
691
|
/** The module's widget, from stage 4 (R16 spec): empty till then. */
|
|
@@ -576,11 +712,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
576
712
|
undo: () => this.undo(),
|
|
577
713
|
clear: () => this.clear(),
|
|
578
714
|
zoom: (larger) => this.#zoomBy(larger),
|
|
579
|
-
|
|
580
|
-
// puts the page back in pen mode (R29).
|
|
581
|
-
fingers: () => {
|
|
582
|
-
PEN_MODE.on = false;
|
|
583
|
-
},
|
|
715
|
+
turnGrid: () => this.#turnGrid(),
|
|
584
716
|
next: () => this.#openNext(),
|
|
585
717
|
toggle: () => this.#toggleDemo(),
|
|
586
718
|
trace: () => this.#trace(),
|
|
@@ -588,8 +720,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
588
720
|
/** A task from paper's tracing paper: its layer, its grip and the crop's picture (R87). */
|
|
589
721
|
#tracingPaper = new TracingPaper({
|
|
590
722
|
move: (at) => this.#moveTracing(at),
|
|
723
|
+
resize: (at, scale) => this.#resizeTracing(at, scale),
|
|
724
|
+
fit: () => this.#fitTracing(),
|
|
591
725
|
moved: () => this.#tracingMoved(),
|
|
726
|
+
read: () => this.dispatchEvent(new CustomEvent(TRACING_READ, { bubbles: true, composed: true, detail: null })),
|
|
592
727
|
});
|
|
728
|
+
/** The reading of the statement of the task from paper, as the consumer gave it (R89). */
|
|
729
|
+
#reading;
|
|
593
730
|
/** The task from paper as the consumer gave it, and where its tracing paper lies (R87). */
|
|
594
731
|
#paper;
|
|
595
732
|
#tracing;
|
|
@@ -628,13 +765,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
628
765
|
writer: () => this.#writer(),
|
|
629
766
|
drop: (pointerId) => this.#drop(pointerId),
|
|
630
767
|
scroll: (dx, dy, fresh) => this.#scroll(dx, dy, fresh),
|
|
631
|
-
|
|
768
|
+
zoom: (ratio, x, y) => this.#pinch(ratio, x, y),
|
|
769
|
+
across: () => overflowOf(this.#viewport, "x") > EDGE,
|
|
632
770
|
}, PEN_MODE);
|
|
633
|
-
/** Whether the row shows the finger's button: it comes and goes between strokes alone. */
|
|
634
|
-
#finger = false;
|
|
635
771
|
/**
|
|
636
|
-
* What two fingers scroll in the gesture under way, down and across, each chosen at
|
|
637
|
-
* step that goes along its axis (R73): undefined till then, and null when nothing
|
|
772
|
+
* What two fingers, or the hand, scroll in the gesture under way, down and across, each chosen at
|
|
773
|
+
* the first step that goes along its axis (R73): undefined till then, and null when nothing
|
|
774
|
+
* scrolls so.
|
|
638
775
|
*/
|
|
639
776
|
#latch;
|
|
640
777
|
#latchAcross;
|
|
@@ -644,14 +781,33 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
644
781
|
this.#fit();
|
|
645
782
|
};
|
|
646
783
|
#page = new ResizeObserver(this.#resized);
|
|
784
|
+
/** A window of another size has another view: the sheet goes as far past the ink by it (R73). */
|
|
785
|
+
#rewindowed = () => this.#regrow();
|
|
647
786
|
/** What the bar's rail sticks in, when a scroller of the page's: its height is the rail's room. */
|
|
648
787
|
#port = null;
|
|
649
788
|
#ported = new ResizeObserver(() => this.#fit());
|
|
650
789
|
#unwatchPen;
|
|
651
790
|
#unwatchZoom;
|
|
652
|
-
/** The
|
|
653
|
-
#zoom =
|
|
791
|
+
/** The zoom the sheet is laid out by: the page's, and a worked example's 1 (R73). */
|
|
792
|
+
#zoom = 1;
|
|
793
|
+
/** Where on the screen a pinch zooms about, while it sets the page's zoom (R73). */
|
|
794
|
+
#anchor;
|
|
795
|
+
/**
|
|
796
|
+
* The point of the sheet a press zoomed about, where on the screen it stood, and where the press
|
|
797
|
+
* left the container: while nothing has scrolled or moved it since, the next press zooms about the
|
|
798
|
+
* same point, so that a zoom out at the sheet's edge, where the scroll stops short, and back in
|
|
799
|
+
* comes back where it was (R73).
|
|
800
|
+
*/
|
|
801
|
+
#held;
|
|
654
802
|
#tool = "pen";
|
|
803
|
+
/** The pointer the hand moves the sheet by, and where it was on the screen last (R88). */
|
|
804
|
+
#pan;
|
|
805
|
+
/** A task from paper's grid, the learner's (R88). */
|
|
806
|
+
#paperGrid = "dots";
|
|
807
|
+
/** How far the sheet goes, in units, as laid out: the page and past it (R73). */
|
|
808
|
+
#extent = SHEET;
|
|
809
|
+
/** The grid's path as last drawn: its rulings and the extent they cover. */
|
|
810
|
+
#gridDrawn = "";
|
|
655
811
|
#task;
|
|
656
812
|
/** A lesson's worked example as the consumer gave it, and as the element checked it (R42). */
|
|
657
813
|
#workedExample;
|
|
@@ -743,6 +899,18 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
743
899
|
this.#sheet.className = "sheet";
|
|
744
900
|
this.#stage.className = "stage";
|
|
745
901
|
this.#grid.setAttribute("class", "grid");
|
|
902
|
+
for (const [band, place] of [
|
|
903
|
+
[this.#above, "above"],
|
|
904
|
+
[this.#below, "below"],
|
|
905
|
+
]) {
|
|
906
|
+
band.setAttribute("class", `band ${place}`);
|
|
907
|
+
band.setAttribute("aria-hidden", "true");
|
|
908
|
+
// Units at the sheet's scale: the band's width is the extent's, and its height is the
|
|
909
|
+
// padding's, which the band's units outrun and slice at the sheet's edge.
|
|
910
|
+
band.setAttribute("preserveAspectRatio", place === "above" ? "xMinYMax slice" : "xMinYMin slice");
|
|
911
|
+
band.append(document.createElementNS(SVG, "path"));
|
|
912
|
+
band.firstElementChild?.setAttribute("class", "grid");
|
|
913
|
+
}
|
|
746
914
|
this.#print.setAttribute("class", "print");
|
|
747
915
|
// The constructor reads no attribute: the labels of a demo's boxes are English till `lang` comes.
|
|
748
916
|
this.#nameBoxes(null);
|
|
@@ -751,14 +919,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
751
919
|
this.#print.append(this.#lines);
|
|
752
920
|
this.#template.append(this.#grid, this.#print);
|
|
753
921
|
this.#show.append(this.#parts.layer);
|
|
754
|
-
this.#stage.append(this.#template, this.#widget, this.#show, this.#tracingPaper.layer, this.#sketch, this.#canvas, this.#marksLayer, this.#tracingPaper.grip, this.#tracingPaper.tip);
|
|
922
|
+
this.#stage.append(this.#template, this.#widget, this.#show, this.#tracingPaper.layer, this.#tracingPaper.cover, this.#sketch, this.#canvas, this.#marksLayer, this.#tracingPaper.frame, this.#tracingPaper.sign, this.#tracingPaper.grip, this.#tracingPaper.tip, this.#tracingPaper.bar);
|
|
755
923
|
this.#sheet.append(this.#stage, this.#parts.spot);
|
|
756
|
-
|
|
924
|
+
// The bands come after the sheet: the ruling on its edge, half past the band, lies over it.
|
|
925
|
+
this.#column.append(this.#statement.element, this.#parts.list, this.#parts.status, this.#sheet, this.#above, this.#below);
|
|
757
926
|
this.#viewport.append(this.#column);
|
|
758
927
|
// The bar comes first, as the row of buttons before it did: Tab reaches it before the sheet.
|
|
759
928
|
this.#wrapper.append(this.#tools.rail, this.#viewport, this.#ring);
|
|
760
929
|
root.append(this.#wrapper);
|
|
761
|
-
this.#zoomTo(PAGE_ZOOM.value);
|
|
762
930
|
this.#lay(NO_TASK);
|
|
763
931
|
this.#refresh();
|
|
764
932
|
this.#canvas.addEventListener("pointerdown", (event) => this.#down(event));
|
|
@@ -785,6 +953,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
785
953
|
this.#canvas.addEventListener("transitionend", () => this.#request());
|
|
786
954
|
this.#canvas.addEventListener("transitioncancel", () => this.#request());
|
|
787
955
|
this.#viewport.addEventListener("scroll", () => this.#scrolled(), { passive: true });
|
|
956
|
+
// Ctrl or ⌘ with the wheel over the tracing paper scales it, not the page (R89).
|
|
957
|
+
this.#viewport.addEventListener("wheel", (event) => this.#wheel(event), { passive: false });
|
|
788
958
|
// A container left with nothing to scroll keeps its stop of Tab while it has the focus.
|
|
789
959
|
this.#viewport.addEventListener("blur", () => this.#region());
|
|
790
960
|
attachProbe(this, () => ({
|
|
@@ -804,6 +974,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
804
974
|
// is a TypeError without it.
|
|
805
975
|
this.#adopt("demoState");
|
|
806
976
|
this.#adopt("tracing");
|
|
977
|
+
this.#adopt("grid");
|
|
807
978
|
this.#adopt("manifest");
|
|
808
979
|
this.#adopt("media");
|
|
809
980
|
// The history before the marks: they hold on to its strokes.
|
|
@@ -813,21 +984,22 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
813
984
|
/** The element follows its own `lang`: its buttons are labelled in it (R07, R28). */
|
|
814
985
|
static observedAttributes = ["lang", "tools-hidden"];
|
|
815
986
|
/**
|
|
816
|
-
* What a press of the primary button does: "pen" writes, as the element starts,
|
|
817
|
-
*
|
|
818
|
-
* theirs with a `toolchange`, and the consumer may
|
|
819
|
-
* under way goes on as it began. A pen's eraser
|
|
820
|
-
*
|
|
821
|
-
*
|
|
987
|
+
* What a press of the primary button does: "pen" writes, as the element starts, "eraser" erases
|
|
988
|
+
* (R22), and "hand" moves the sheet, under any pointer (R88). The learner switches it with the
|
|
989
|
+
* element's own buttons, which say a choice of theirs with a `toolchange`, and the consumer may
|
|
990
|
+
* set it too, which says nothing (R28). A press under way goes on as it began. A pen's eraser
|
|
991
|
+
* erases whatever the tool but the hand. A task without the eraser has none of it: "eraser" is a
|
|
992
|
+
* TypeError then, and a new task without it puts the pen back. Every sheet the learner writes on
|
|
993
|
+
* has the hand. A worked example has the pen alone, which writes nothing on its sheet (R42).
|
|
822
994
|
*/
|
|
823
995
|
get tool() {
|
|
824
996
|
return this.#tool;
|
|
825
997
|
}
|
|
826
998
|
set tool(tool) {
|
|
827
999
|
if (!isTool(tool)) {
|
|
828
|
-
throw new TypeError(`the tool of <${TAG}> is "pen" or "
|
|
1000
|
+
throw new TypeError(`the tool of <${TAG}> is "pen", "eraser" or "hand", not ${JSON.stringify(tool)}`);
|
|
829
1001
|
}
|
|
830
|
-
if (!this.#
|
|
1002
|
+
if (!this.#allows(tool)) {
|
|
831
1003
|
const shown = this.#example === undefined ? "task" : "worked example";
|
|
832
1004
|
throw new TypeError(`the ${shown} of <${TAG}> allows no ${tool}`);
|
|
833
1005
|
}
|
|
@@ -878,8 +1050,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
878
1050
|
* another replaces it, its grid and its statement apart, as a task does.
|
|
879
1051
|
*
|
|
880
1052
|
* On a worked example's sheet the learner does not write: the canvas takes no input, and a finger
|
|
881
|
-
* or a pen there scrolls the sheet as the browser scrolls the statement.
|
|
882
|
-
*
|
|
1053
|
+
* or a pen there scrolls the sheet as the browser scrolls the statement. It has no bar: its row
|
|
1054
|
+
* holds Next and Demo, and its region is named a worked example's. `task`, `history` other than the empty one and
|
|
883
1055
|
* `marks` are TypeErrors, and so is an eraser: the tool is the pen alone, and `exportWork()` and
|
|
884
1056
|
* `filled` give null. The next segment of a lesson is a new element (R20).
|
|
885
1057
|
*
|
|
@@ -946,6 +1118,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
946
1118
|
this.#leaveTracing(false);
|
|
947
1119
|
this.#paper = undefined;
|
|
948
1120
|
this.#tracing = undefined;
|
|
1121
|
+
this.#reading = undefined;
|
|
1122
|
+
this.#tracingPaper.reading = undefined;
|
|
949
1123
|
this.#tracingPaper.show(undefined, () => { });
|
|
950
1124
|
this.#whole = false;
|
|
951
1125
|
this.#present(NO_TASK);
|
|
@@ -967,8 +1141,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
967
1141
|
return;
|
|
968
1142
|
}
|
|
969
1143
|
this.#leaveTracing(false);
|
|
1144
|
+
// A new task from paper comes on dots; another crop in its place keeps the learner's grid.
|
|
1145
|
+
if (this.#paper === undefined)
|
|
1146
|
+
this.#paperGrid = PAPER_GRIDS[0];
|
|
970
1147
|
this.#paper = paper;
|
|
971
1148
|
this.#tracing = TRACING_START;
|
|
1149
|
+
this.#reading = undefined;
|
|
1150
|
+
this.#tracingPaper.reading = undefined;
|
|
972
1151
|
this.#tracingPaper.show(statement, () => this.#sized());
|
|
973
1152
|
this.#whole = true;
|
|
974
1153
|
this.#present(PAPER_TEMPLATE);
|
|
@@ -999,9 +1178,28 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
999
1178
|
return;
|
|
1000
1179
|
this.#tracing = checked;
|
|
1001
1180
|
this.#replace();
|
|
1181
|
+
this.#regrow();
|
|
1002
1182
|
this.#refresh();
|
|
1003
1183
|
this.#request();
|
|
1004
1184
|
}
|
|
1185
|
+
/**
|
|
1186
|
+
* The reading of the task from paper's statement in clean print (R89): `undefined` offers no
|
|
1187
|
+
* "Recognise"; `"ready"` offers it, and its press sends a `tracingread`; `"busy"` waits; `"done"`
|
|
1188
|
+
* holds the statements, which take the crop's place for the learner who asked, till "Original".
|
|
1189
|
+
* Frozen; given without a task from paper, or not a reading, it is a TypeError.
|
|
1190
|
+
*/
|
|
1191
|
+
get reading() {
|
|
1192
|
+
return this.#reading;
|
|
1193
|
+
}
|
|
1194
|
+
set reading(reading) {
|
|
1195
|
+
if (reading !== undefined && this.#paper === undefined) {
|
|
1196
|
+
throw new TypeError(`<${TAG}> shows no task from paper: the reading is given after the paper`);
|
|
1197
|
+
}
|
|
1198
|
+
const checked = reading === undefined ? undefined : readingOf(reading);
|
|
1199
|
+
this.#reading = checked;
|
|
1200
|
+
this.#tracingPaper.reading = checked;
|
|
1201
|
+
this.#request();
|
|
1202
|
+
}
|
|
1005
1203
|
/**
|
|
1006
1204
|
* How far the learner has gone through the worked example's demo (R42): `opened`, how many of
|
|
1007
1205
|
* its parts are open, from the first, and `hidden`, whether the whole demo is hidden — frozen,
|
|
@@ -1075,6 +1273,31 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1075
1273
|
}
|
|
1076
1274
|
this.#pictures.media = media;
|
|
1077
1275
|
}
|
|
1276
|
+
/**
|
|
1277
|
+
* The grid of the task from paper's sheet (R88): `undefined` without a task from paper, and
|
|
1278
|
+
* "dots" as one comes. The learner turns it by the element's button, which a `gridchange`
|
|
1279
|
+
* tells; the consumer keeps it and gives it back, which tells nothing. A grid given before the
|
|
1280
|
+
* task from paper is a TypeError, and so is one not of `PaperGrid`; `undefined` changes nothing.
|
|
1281
|
+
*/
|
|
1282
|
+
get grid() {
|
|
1283
|
+
return this.#paper === undefined ? undefined : this.#paperGrid;
|
|
1284
|
+
}
|
|
1285
|
+
set grid(grid) {
|
|
1286
|
+
if (grid === undefined)
|
|
1287
|
+
return;
|
|
1288
|
+
if (!isPaperGrid(grid)) {
|
|
1289
|
+
const grids = PAPER_GRIDS.map((each) => JSON.stringify(each)).join(", ");
|
|
1290
|
+
throw new TypeError(`the grid of <${TAG}> is one of ${grids}, not ${JSON.stringify(grid)}`);
|
|
1291
|
+
}
|
|
1292
|
+
if (this.#paper === undefined) {
|
|
1293
|
+
throw new TypeError(`<${TAG}> shows no task from paper: its grid is given after the paper`);
|
|
1294
|
+
}
|
|
1295
|
+
if (grid === this.#paperGrid)
|
|
1296
|
+
return;
|
|
1297
|
+
this.#paperGrid = grid;
|
|
1298
|
+
this.#drawGrid();
|
|
1299
|
+
this.#refresh();
|
|
1300
|
+
}
|
|
1078
1301
|
/**
|
|
1079
1302
|
* The history of writing (R22, R27): every stroke, erasing, clearing and undo on the sheet, in the
|
|
1080
1303
|
* order they landed, at the sheet's time — frozen, and the same array until the next action. The
|
|
@@ -1138,6 +1361,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1138
1361
|
this.#writing = undefined;
|
|
1139
1362
|
this.#equal = undefined;
|
|
1140
1363
|
this.#replace();
|
|
1364
|
+
this.#regrow();
|
|
1141
1365
|
this.#refresh();
|
|
1142
1366
|
this.#request();
|
|
1143
1367
|
}
|
|
@@ -1196,9 +1420,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1196
1420
|
this.#watchColours();
|
|
1197
1421
|
this.#pictures.connect();
|
|
1198
1422
|
this.#tracingPaper.connect();
|
|
1199
|
-
// The page's pen mode, on every sheet of it (R29). The
|
|
1200
|
-
// made it is over: by then a pen that came down writes
|
|
1201
|
-
// stroke. The sheet tells the page whether it is written on, and hears when a stroke ends.
|
|
1423
|
+
// The page's pen mode, on every sheet of it (R29). 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 written on, and hears when a stroke ends.
|
|
1202
1425
|
const unwatch = PEN_MODE.watch(() => queueMicrotask(() => this.#refresh()));
|
|
1203
1426
|
const unenlist = PEN_MODE.enlist(() => this.#writer() !== undefined);
|
|
1204
1427
|
this.#unwatchPen = () => {
|
|
@@ -1206,11 +1429,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1206
1429
|
unenlist();
|
|
1207
1430
|
};
|
|
1208
1431
|
// The page's zoom, on every sheet of it (R73): it may have changed while the element was away.
|
|
1209
|
-
this.#zoomTo(PAGE_ZOOM.value);
|
|
1210
1432
|
this.#unwatchZoom = PAGE_ZOOM.watch(() => this.#zoomed());
|
|
1211
1433
|
// A page that grows or shrinks scrolls nothing, and neither does a window of another size.
|
|
1212
1434
|
this.#page.observe(document.documentElement);
|
|
1213
1435
|
window.addEventListener("resize", this.#resized);
|
|
1436
|
+
window.addEventListener("resize", this.#rewindowed);
|
|
1437
|
+
this.#regrow();
|
|
1214
1438
|
this.#refresh();
|
|
1215
1439
|
this.#fit();
|
|
1216
1440
|
}
|
|
@@ -1253,7 +1477,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1253
1477
|
/** The tracing paper's grip is named in the labels' language, and its tooltip says it (R87). */
|
|
1254
1478
|
#nameGrip(tag = this.getAttribute("lang")) {
|
|
1255
1479
|
const { lang, labels } = labelsFor(tag);
|
|
1256
|
-
this.#tracingPaper.label(labels
|
|
1480
|
+
this.#tracingPaper.label(labels, lang);
|
|
1257
1481
|
}
|
|
1258
1482
|
/**
|
|
1259
1483
|
* Takes back the last action on the sheet — the last stroke written, the last erasing, or the
|
|
@@ -1300,14 +1524,15 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1300
1524
|
const tracing = this.#tracing;
|
|
1301
1525
|
if (paper !== undefined && tracing !== undefined) {
|
|
1302
1526
|
// The sheet as it is now: the crop's picture, read by now or soon, does not change it.
|
|
1303
|
-
const strokes = this.#work.strokes.map((stroke) => this.#onSheet(stroke, tracing
|
|
1527
|
+
const strokes = this.#work.strokes.map((stroke) => this.#onSheet(stroke, tracing));
|
|
1304
1528
|
if (strokes.length === 0)
|
|
1305
1529
|
return null;
|
|
1306
1530
|
const written = this.#work;
|
|
1307
1531
|
const onTracing = (id) => written.onTracing(id);
|
|
1308
1532
|
const { size, gray } = await this.#tracingPaper.read;
|
|
1309
|
-
const
|
|
1310
|
-
const
|
|
1533
|
+
const scale = scaleIn(tracing);
|
|
1534
|
+
const rect = tracingRect(tracing.at, scaled(size, scale));
|
|
1535
|
+
const work = paperWorkForCheck(strokes, { at: tracing.at, scale, onTracing }, tracing, rect, gray, digit);
|
|
1311
1536
|
if (work === null)
|
|
1312
1537
|
return null;
|
|
1313
1538
|
return Object.freeze({
|
|
@@ -1331,9 +1556,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1331
1556
|
/**
|
|
1332
1557
|
* The picture of the work, for the `picture` of a stored work that app puts on the server, a
|
|
1333
1558
|
* method of the agreement with app (R83; R36 spec): the PNG of the strokes the surface shows,
|
|
1334
|
-
* with no condition — the
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1559
|
+
* with no condition — the sheet's page, or the workbook's whole page with its draft, and the ink
|
|
1560
|
+
* past the page, right and down, with the tracing paper where it lies (R73): one pixel a unit,
|
|
1561
|
+
* 1000 × 1400 for the page alone, and scaled down past the page to hold no more pixels than it,
|
|
1562
|
+
* its size in its PNG's header —, whatever is filled and whether the work was sent to be checked
|
|
1563
|
+
* or not; an empty surface, and a worked example's, is white. The strokes are those `exportWork()` takes, as
|
|
1337
1564
|
* the history has them: not the stroke under way, but those under an eraser not yet lifted. Each
|
|
1338
1565
|
* is the outline the screen fills, black on white with no theme and no template — on a task from
|
|
1339
1566
|
* paper the strokes of both layers, the tracing paper's where it lies, hidden or not, with the
|
|
@@ -1343,8 +1570,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1343
1570
|
* the 4 MiB of a stored work.
|
|
1344
1571
|
*/
|
|
1345
1572
|
async exportPicture() {
|
|
1346
|
-
// A pixel a unit
|
|
1347
|
-
|
|
1573
|
+
// A pixel a unit, the ink 3 px wide as on a screen of a pixel a unit, while the page and the ink
|
|
1574
|
+
// past it hold no more pixels than the page; scaled down to hold them past that (R83).
|
|
1575
|
+
const reach = this.#inkReach();
|
|
1576
|
+
const { width, height, scale } = pictureOf({
|
|
1577
|
+
maxX: reach.maxX + INK_REACH,
|
|
1578
|
+
maxY: reach.maxY + INK_REACH,
|
|
1579
|
+
});
|
|
1348
1580
|
const canvas = document.createElement("canvas");
|
|
1349
1581
|
canvas.width = width;
|
|
1350
1582
|
canvas.height = height;
|
|
@@ -1358,14 +1590,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1358
1590
|
const strokes = this.#work.strokes;
|
|
1359
1591
|
const work = this.#work;
|
|
1360
1592
|
for (const stroke of strokes) {
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
context.fill(this.#finished(stroke).path);
|
|
1368
|
-
}
|
|
1593
|
+
const traced = tracing !== undefined && work.onTracing(stroke.id);
|
|
1594
|
+
const [x, y] = traced ? tracing.at : [0, 0];
|
|
1595
|
+
// A stroke of the tracing paper is as large as the paper's scale draws it (R89).
|
|
1596
|
+
const by = traced ? scale * scaleIn(tracing) : scale;
|
|
1597
|
+
context.setTransform(by, 0, 0, by, x * scale, y * scale);
|
|
1598
|
+
context.fill(this.#finished(stroke).path);
|
|
1369
1599
|
}
|
|
1370
1600
|
const { data } = context.getImageData(0, 0, width, height);
|
|
1371
1601
|
// The canvas's memory goes at once, not at a collection: WebKit caps what all canvases hold.
|
|
@@ -1376,17 +1606,17 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1376
1606
|
const gray = new Uint8Array(width * height);
|
|
1377
1607
|
for (let at = 0; at < gray.length; at++)
|
|
1378
1608
|
gray[at] = data[4 * at];
|
|
1379
|
-
// A task from paper's crop lies over it where the tracing paper lies, shown or hidden,
|
|
1380
|
-
//
|
|
1609
|
+
// A task from paper's crop lies over it where the tracing paper lies, shown or hidden, at the
|
|
1610
|
+
// picture's scale, as the crop of the work has it (R87).
|
|
1381
1611
|
if (tracing !== undefined) {
|
|
1382
1612
|
const { size, gray: picture } = await this.#tracingPaper.read;
|
|
1383
1613
|
if (picture !== null) {
|
|
1384
|
-
const rect = tracingRect(tracing.at, size);
|
|
1614
|
+
const rect = tracingRect(tracing.at, scaled(size, scaleIn(tracing)));
|
|
1385
1615
|
layOver(gray, width, picture, {
|
|
1386
|
-
left: rect.minX,
|
|
1387
|
-
top: rect.minY,
|
|
1388
|
-
right: rect.maxX,
|
|
1389
|
-
bottom: rect.maxY,
|
|
1616
|
+
left: rect.minX * scale,
|
|
1617
|
+
top: rect.minY * scale,
|
|
1618
|
+
right: rect.maxX * scale,
|
|
1619
|
+
bottom: rect.maxY * scale,
|
|
1390
1620
|
});
|
|
1391
1621
|
}
|
|
1392
1622
|
}
|
|
@@ -1405,11 +1635,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1405
1635
|
this.#unwatchPen = undefined;
|
|
1406
1636
|
this.#unwatchZoom?.();
|
|
1407
1637
|
this.#unwatchZoom = undefined;
|
|
1638
|
+
this.#endPan();
|
|
1408
1639
|
this.#page.disconnect();
|
|
1409
1640
|
this.#ported.disconnect();
|
|
1410
1641
|
this.#port = null;
|
|
1411
1642
|
this.#tools.disconnect();
|
|
1412
1643
|
window.removeEventListener("resize", this.#resized);
|
|
1644
|
+
window.removeEventListener("resize", this.#rewindowed);
|
|
1413
1645
|
// A stroke that ended here may be the one the other rows of the page waited for.
|
|
1414
1646
|
PEN_MODE.settle();
|
|
1415
1647
|
this.#pictures.disconnect();
|
|
@@ -1467,10 +1699,17 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1467
1699
|
this.#statement.show(template.statement);
|
|
1468
1700
|
const parts = [...template.statement, ...(this.#example?.demo ?? [])];
|
|
1469
1701
|
this.#pictures.name(parts.flatMap((part) => ("picture" in part ? [part.picture] : [])));
|
|
1470
|
-
if (!
|
|
1702
|
+
if (!this.#allows(this.#tool))
|
|
1471
1703
|
this.#tool = "pen";
|
|
1704
|
+
this.#regrow();
|
|
1472
1705
|
this.#refresh();
|
|
1473
1706
|
}
|
|
1707
|
+
/** Whether the sheet shown has a tool: the task's, and the hand on every sheet written on (R88). */
|
|
1708
|
+
#allows(tool) {
|
|
1709
|
+
if (tool === HAND)
|
|
1710
|
+
return this.#example === undefined;
|
|
1711
|
+
return this.#shownTemplate.tools.includes(tool);
|
|
1712
|
+
}
|
|
1474
1713
|
/**
|
|
1475
1714
|
* Whether the element may show a worked example now (R42): not while it shows a task, not on a
|
|
1476
1715
|
* sheet the learner has written on, and not while a stroke or an erasing is under way, which
|
|
@@ -1497,8 +1736,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1497
1736
|
*/
|
|
1498
1737
|
#lay(template) {
|
|
1499
1738
|
const workbook = isWorkbook(template);
|
|
1500
|
-
this.#
|
|
1501
|
-
this.#grid.classList.toggle("dots", !workbook && template.grid.kind === "dots");
|
|
1739
|
+
this.#drawGrid();
|
|
1502
1740
|
write(this.#template, "aria-hidden", workbook ? null : "true");
|
|
1503
1741
|
write(this.#template, "role", workbook ? "none" : null);
|
|
1504
1742
|
this.#lines.replaceChildren(...(workbook ? template.page.items.map(itemOf) : []));
|
|
@@ -1593,7 +1831,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1593
1831
|
return this.#work.history.flatMap((event) => {
|
|
1594
1832
|
if (event.kind !== "write")
|
|
1595
1833
|
return [];
|
|
1596
|
-
return [tracing === undefined ? event.stroke : this.#onSheet(event.stroke, tracing
|
|
1834
|
+
return [tracing === undefined ? event.stroke : this.#onSheet(event.stroke, tracing)];
|
|
1597
1835
|
});
|
|
1598
1836
|
}
|
|
1599
1837
|
/**
|
|
@@ -1606,7 +1844,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1606
1844
|
const work = this.#work;
|
|
1607
1845
|
const paper = tracing === undefined
|
|
1608
1846
|
? undefined
|
|
1609
|
-
: {
|
|
1847
|
+
: {
|
|
1848
|
+
at: tracing.at,
|
|
1849
|
+
scale: scaleIn(tracing),
|
|
1850
|
+
onTracing: (id) => work.onTracing(id),
|
|
1851
|
+
};
|
|
1610
1852
|
const places = placesOf(given, this.#known(), cells, undefined, paper);
|
|
1611
1853
|
return given.marks.flatMap(({ name }, n) => {
|
|
1612
1854
|
const placed = places[n];
|
|
@@ -1663,6 +1905,18 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1663
1905
|
// was, as on a lost capture.
|
|
1664
1906
|
this.#recorder.end(event.pointerId);
|
|
1665
1907
|
this.#eraser.end(event.pointerId);
|
|
1908
|
+
// The hand moves the sheet under a pen, a finger or a mouse alike, and writes nothing: one
|
|
1909
|
+
// pointer at a time, and the others do nothing while it moves (R88).
|
|
1910
|
+
if (this.#tool === HAND) {
|
|
1911
|
+
if (this.#pan !== undefined)
|
|
1912
|
+
return;
|
|
1913
|
+
this.#pan = { pointerId: event.pointerId, x: event.clientX, y: event.clientY };
|
|
1914
|
+
this.#latch = undefined;
|
|
1915
|
+
this.#latchAcross = undefined;
|
|
1916
|
+
this.#sheet.classList.add("panning");
|
|
1917
|
+
this.#capture(event.pointerId);
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1666
1920
|
const writes = this.#hands.down(contactOf(event));
|
|
1667
1921
|
// The canvas holds on to every pointer that comes down on it until it lifts, writing or not: its
|
|
1668
1922
|
// moves and its lift come here, so that a stroke goes on beyond the canvas, two fingers scroll,
|
|
@@ -1680,20 +1934,25 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1680
1934
|
// points from its corner; one begun elsewhere, on the sheet (R87).
|
|
1681
1935
|
const tracing = this.#tracing;
|
|
1682
1936
|
const size = this.#tracingPaper.size;
|
|
1937
|
+
const scale = tracing === undefined ? 1 : scaleIn(tracing);
|
|
1683
1938
|
const traced = tracing !== undefined &&
|
|
1684
1939
|
!tracing.hidden &&
|
|
1685
1940
|
this.#tracingPaper.ready &&
|
|
1686
|
-
onTracing(onSheetSample, tracing.at, size);
|
|
1941
|
+
onTracing(onSheetSample, tracing.at, scaled(size, scale));
|
|
1942
|
+
// A press on the sheet lets the tracing paper go: its frame and bar of scale leave (R89).
|
|
1943
|
+
this.#tracingPaper.letGo();
|
|
1687
1944
|
const layer = traced ? "tracing" : undefined;
|
|
1688
1945
|
if (erases)
|
|
1689
1946
|
this.#eraseOn = tracing === undefined ? undefined : (layer ?? "sheet");
|
|
1690
1947
|
else
|
|
1691
1948
|
this.#writeOn = layer;
|
|
1692
1949
|
const sample = traced && tracing !== undefined
|
|
1693
|
-
? { ...onSheetSample, ...toTracing(onSheetSample, tracing.at, size) }
|
|
1950
|
+
? { ...onSheetSample, ...toTracing(onSheetSample, tracing.at, size, scale) }
|
|
1694
1951
|
: onSheetSample;
|
|
1952
|
+
// On the tracing paper the eraser reaches as far on the screen, in the paper's own units.
|
|
1953
|
+
const reach = traced ? ERASER_RADIUS_PX / screen.k / scale : ERASER_RADIUS_PX / screen.k;
|
|
1695
1954
|
const began = erases
|
|
1696
|
-
? this.#eraser.down(sample,
|
|
1955
|
+
? this.#eraser.down(sample, reach + INK_REACH)
|
|
1697
1956
|
: this.#recorder.down(sample);
|
|
1698
1957
|
if (began)
|
|
1699
1958
|
this.#request();
|
|
@@ -1708,6 +1967,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1708
1967
|
}
|
|
1709
1968
|
}
|
|
1710
1969
|
#move(event) {
|
|
1970
|
+
// The sheet goes with the hand, as with two fingers.
|
|
1971
|
+
const pan = this.#pan;
|
|
1972
|
+
if (pan !== undefined && pan.pointerId === event.pointerId) {
|
|
1973
|
+
this.#scroll(event.clientX - pan.x, event.clientY - pan.y, false);
|
|
1974
|
+
this.#pan = { pointerId: pan.pointerId, x: event.clientX, y: event.clientY };
|
|
1975
|
+
this.#flush();
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1711
1978
|
// A pointer the hands did not see come down, such as a mouse or a pen hovering, does nothing,
|
|
1712
1979
|
// and reads no layout.
|
|
1713
1980
|
if (!this.#hands.knows(event.pointerId))
|
|
@@ -1752,11 +2019,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1752
2019
|
this.#lifted(event.pointerId);
|
|
1753
2020
|
}
|
|
1754
2021
|
/**
|
|
1755
|
-
* A pointer lifted, or the device or the page took it from the sheet: the hands forget it, a
|
|
1756
|
-
* gesture that ended lets go of what it scrolled
|
|
1757
|
-
* this row and on the others of the page (R29).
|
|
2022
|
+
* A pointer lifted, or the device or the page took it from the sheet: the hands forget it, and a
|
|
2023
|
+
* gesture that ended, or the hand's move, lets go of what it scrolled (R29; R88).
|
|
1758
2024
|
*/
|
|
1759
2025
|
#lifted(pointerId) {
|
|
2026
|
+
if (this.#pan?.pointerId === pointerId)
|
|
2027
|
+
this.#endPan();
|
|
1760
2028
|
this.#hands.lift(pointerId);
|
|
1761
2029
|
if (!this.#hands.scrolling) {
|
|
1762
2030
|
this.#latch = undefined;
|
|
@@ -1765,6 +2033,15 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1765
2033
|
this.#refresh();
|
|
1766
2034
|
PEN_MODE.settle();
|
|
1767
2035
|
}
|
|
2036
|
+
/** The hand's move ends, and lets go of what it scrolled. */
|
|
2037
|
+
#endPan() {
|
|
2038
|
+
if (this.#pan === undefined)
|
|
2039
|
+
return;
|
|
2040
|
+
this.#pan = undefined;
|
|
2041
|
+
this.#sheet.classList.remove("panning");
|
|
2042
|
+
this.#latch = undefined;
|
|
2043
|
+
this.#latchAcross = undefined;
|
|
2044
|
+
}
|
|
1768
2045
|
/** The pointer that writes or erases now, if one does: the recorder's or the eraser's. */
|
|
1769
2046
|
#writer() {
|
|
1770
2047
|
return this.#recorder.pointer ?? this.#eraser.pointer;
|
|
@@ -1795,7 +2072,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1795
2072
|
const point = toSheet(screen, event.clientX - screen.left, event.clientY - screen.top);
|
|
1796
2073
|
const tracing = this.#tracing;
|
|
1797
2074
|
const { x, y } = layer === "tracing" && tracing !== undefined
|
|
1798
|
-
? toTracing(point, tracing.at, this.#tracingPaper.size)
|
|
2075
|
+
? toTracing(point, tracing.at, this.#tracingPaper.size, scaleIn(tracing))
|
|
1799
2076
|
: point;
|
|
1800
2077
|
return {
|
|
1801
2078
|
pointerId: event.pointerId,
|
|
@@ -1821,7 +2098,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1821
2098
|
const sheet = this.#sheet.getBoundingClientRect();
|
|
1822
2099
|
if (canvas.width <= 0 || sheet.width <= 0)
|
|
1823
2100
|
return undefined;
|
|
1824
|
-
const k = scaleFor(sheet.width);
|
|
2101
|
+
const k = scaleFor(sheet.width, this.#extent.width);
|
|
1825
2102
|
const vx = (canvas.left - sheet.left) / k;
|
|
1826
2103
|
const vy = (canvas.top - sheet.top) / k;
|
|
1827
2104
|
const port = clientBoxOf(this.#viewport);
|
|
@@ -1836,8 +2113,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1836
2113
|
}
|
|
1837
2114
|
/**
|
|
1838
2115
|
* The sheet's top in the container's content, in CSS pixels as laid out: under the statement —
|
|
1839
|
-
* or, along `x`, its left
|
|
1840
|
-
* wider (R73).
|
|
2116
|
+
* or, along `x`, its left (R73).
|
|
1841
2117
|
*/
|
|
1842
2118
|
#sheetEdge(axis) {
|
|
1843
2119
|
const port = clientBoxOf(this.#viewport);
|
|
@@ -1859,45 +2135,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1859
2135
|
this.#request();
|
|
1860
2136
|
}
|
|
1861
2137
|
/**
|
|
1862
|
-
*
|
|
1863
|
-
*
|
|
1864
|
-
*
|
|
1865
|
-
*/
|
|
1866
|
-
#zoomBy(larger) {
|
|
1867
|
-
if (!PEN_MODE.writing)
|
|
1868
|
-
PAGE_ZOOM.step(larger);
|
|
1869
|
-
}
|
|
1870
|
-
/**
|
|
1871
|
-
* The page's zoom has changed (R73): the sheet is laid out by it at once, its top left corner in
|
|
1872
|
-
* sight staying where it was on the sheet, and the row shows what the zoom can do now.
|
|
1873
|
-
*/
|
|
1874
|
-
#zoomed() {
|
|
1875
|
-
if (!this.#zoomTo(PAGE_ZOOM.value))
|
|
1876
|
-
return;
|
|
1877
|
-
this.#layout();
|
|
1878
|
-
this.#refresh();
|
|
1879
|
-
}
|
|
1880
|
-
/**
|
|
1881
|
-
* The column and the container as wide as a zoom asks, and whether that is another than the
|
|
1882
|
-
* last: the column widens with the sheet, and the container scrolls it across while the zoom is
|
|
1883
|
-
* beyond the fit (R73).
|
|
1884
|
-
*/
|
|
1885
|
-
#zoomTo(zoom) {
|
|
1886
|
-
if (zoom === this.#zoom)
|
|
1887
|
-
return false;
|
|
1888
|
-
this.#zoom = zoom;
|
|
1889
|
-
this.#column.style.setProperty("--zoom", String(zoom));
|
|
1890
|
-
this.#viewport.classList.toggle("zoomed", zoom > 1);
|
|
1891
|
-
this.#keepDirection();
|
|
1892
|
-
return true;
|
|
1893
|
-
}
|
|
1894
|
-
/**
|
|
1895
|
-
* The statement and a demo's parts keep the element's own direction while the zoomed container
|
|
1896
|
-
* runs left to right: the direction the element computes, by an attribute or by a style, as the
|
|
1897
|
-
* last layout read it (R73).
|
|
2138
|
+
* The statement and a demo's parts keep the element's own direction while the container runs
|
|
2139
|
+
* left to right: the direction the element computes, by an attribute or by a style, as the last
|
|
2140
|
+
* layout read it (R73).
|
|
1898
2141
|
*/
|
|
1899
2142
|
#keepDirection() {
|
|
1900
|
-
if (
|
|
2143
|
+
if (!this.isConnected)
|
|
1901
2144
|
return;
|
|
1902
2145
|
const direction = getComputedStyle(this).direction;
|
|
1903
2146
|
if (this.#column.style.getPropertyValue("--direction") !== direction) {
|
|
@@ -1949,10 +2192,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1949
2192
|
return within ? room.top + room.offset : Number.NEGATIVE_INFINITY;
|
|
1950
2193
|
}
|
|
1951
2194
|
/**
|
|
1952
|
-
* Two fingers moved right on the screen by `dx` CSS pixels and down it by `dy`
|
|
1953
|
-
* they scroll goes with them. The gesture's first step down chooses what it
|
|
1954
|
-
* whole gesture, and its first step across
|
|
1955
|
-
* (R73): the sheet's own container if it can go that way, or else the nearest ancestor of the
|
|
2195
|
+
* Two fingers, or the hand, moved right on the screen by `dx` CSS pixels and down it by `dy`
|
|
2196
|
+
* (R29; R88), and what they scroll goes with them. The gesture's first step down chooses what it
|
|
2197
|
+
* scrolls down, for the whole gesture, and its first step across what it scrolls across (R73): the sheet's own container if it can go that way, or else the nearest ancestor of the
|
|
1956
2198
|
* element that scrolls and can, or else the page. A container at its end hands the scroll on at
|
|
1957
2199
|
* the next gesture, not within this one. The steps of an event add up, and its end scrolls them
|
|
1958
2200
|
* at once.
|
|
@@ -1966,7 +2208,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
1966
2208
|
if (dy !== 0 && this.#latch === undefined)
|
|
1967
2209
|
this.#latch = this.#scrollerFor(dy < 0) ?? null;
|
|
1968
2210
|
if (dx !== 0 && this.#latchAcross === undefined) {
|
|
1969
|
-
this.#latchAcross = this.#
|
|
2211
|
+
this.#latchAcross = this.#scrollerFor(dx < 0, "x") ?? null;
|
|
1970
2212
|
}
|
|
1971
2213
|
if (this.#latch)
|
|
1972
2214
|
this.#latch.rest -= dy / this.#latch.scale;
|
|
@@ -2023,7 +2265,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2023
2265
|
/**
|
|
2024
2266
|
* The stage takes the visible part of the sheet, and the canvas a pixel of its buffer for each
|
|
2025
2267
|
* device pixel: its size on the screen times the density (R18). The layers follow in the same
|
|
2026
|
-
* frame. However
|
|
2268
|
+
* frame. However far the sheet goes, the canvas is no larger than the container (R73).
|
|
2027
2269
|
*/
|
|
2028
2270
|
#layout() {
|
|
2029
2271
|
// The content of a new size, or the container, may overflow it now, or no more.
|
|
@@ -2031,12 +2273,15 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2031
2273
|
const area = this.#area;
|
|
2032
2274
|
if (area === undefined || area.width === 0)
|
|
2033
2275
|
return;
|
|
2034
|
-
// The
|
|
2035
|
-
// as tall and as wide as the visible part of the sheet.
|
|
2036
|
-
const k = fitScale(area.width
|
|
2276
|
+
// The page is as wide as the container up to the cap, times the zoom, the column as wide as the
|
|
2277
|
+
// sheet goes, by the style, and the stage as tall and as wide as the visible part of the sheet.
|
|
2278
|
+
const k = fitScale(area.width) * this.#zoom;
|
|
2279
|
+
const extent = this.#extent;
|
|
2280
|
+
this.#stage.style.width = `${Math.min(area.width, extent.width * k)}px`;
|
|
2281
|
+
this.#stage.style.height = `${Math.min(area.height, extent.height * k)}px`;
|
|
2037
2282
|
const sheetAt = this.#sheetEdge("y");
|
|
2038
2283
|
const sheetAtX = this.#sheetEdge("x");
|
|
2039
|
-
// A new width
|
|
2284
|
+
// A new width scales the sheet, and a statement of a new height moves it: the top left
|
|
2040
2285
|
// corner of the visible part stays where it was on the sheet, unless the sheet's top, or its
|
|
2041
2286
|
// left, is in sight. A new height of the container alone moves neither, and a scroll under way
|
|
2042
2287
|
// goes on.
|
|
@@ -2049,8 +2294,6 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2049
2294
|
this.#sheetAt = sheetAt;
|
|
2050
2295
|
this.#sheetAtX = sheetAtX;
|
|
2051
2296
|
this.#keepDirection();
|
|
2052
|
-
this.#stage.style.width = `${Math.min(area.width, SHEET.width * k)}px`;
|
|
2053
|
-
this.#stage.style.height = `${Math.min(area.height, SHEET.height * k)}px`;
|
|
2054
2297
|
const onScreen = this.#canvas.getBoundingClientRect();
|
|
2055
2298
|
const width = Math.round(onScreen.width * devicePixelRatio);
|
|
2056
2299
|
const height = Math.round(onScreen.height * devicePixelRatio);
|
|
@@ -2062,6 +2305,154 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2062
2305
|
this.#canvas.height = height;
|
|
2063
2306
|
}
|
|
2064
2307
|
this.#draw();
|
|
2308
|
+
// The sheet sized anew may overflow the container now, or no more.
|
|
2309
|
+
this.#region();
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* How far the sheet goes (R73): past the page, the ink and the tracing paper where it lies, by
|
|
2313
|
+
* one view of the window more across and two down, at the window's own fit times the zoom,
|
|
2314
|
+
* within the reach. A worked example's sheet is its page alone. The window's view and not the
|
|
2315
|
+
* container's: the sheet is sized by its style, and a size that the container's observer gave
|
|
2316
|
+
* would resize the container again while the observer reports it, which the browser tells the
|
|
2317
|
+
* window as a loop. A zoom below the fit counts by its quarter below, so that a pinch lays the
|
|
2318
|
+
* sheet out anew only as it crosses one, and above the fit as the fit: the view is smaller then.
|
|
2319
|
+
*/
|
|
2320
|
+
#reach() {
|
|
2321
|
+
if (this.#example !== undefined)
|
|
2322
|
+
return SHEET;
|
|
2323
|
+
const quarter = Math.max(ZOOM_MIN, Math.floor(this.#zoom / ZOOM_STEP + 1e-6) * ZOOM_STEP);
|
|
2324
|
+
const k = fitScale(innerWidth) * Math.min(1, quarter);
|
|
2325
|
+
return extentOf(this.#inkReach(), { width: innerWidth / k, height: (2 * innerHeight) / k });
|
|
2326
|
+
}
|
|
2327
|
+
/** The right and the bottom of the sheet's ink and of the tracing paper, which counts whole. */
|
|
2328
|
+
#inkReach() {
|
|
2329
|
+
let maxX = 0;
|
|
2330
|
+
let maxY = 0;
|
|
2331
|
+
const tracing = this.#tracing;
|
|
2332
|
+
for (const stroke of this.#work.strokes) {
|
|
2333
|
+
// The tracing paper's strokes stay on it, and it counts whole.
|
|
2334
|
+
if (tracing !== undefined && this.#work.onTracing(stroke.id))
|
|
2335
|
+
continue;
|
|
2336
|
+
for (const { x, y } of stroke.points) {
|
|
2337
|
+
if (x > maxX)
|
|
2338
|
+
maxX = x;
|
|
2339
|
+
if (y > maxY)
|
|
2340
|
+
maxY = y;
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
if (tracing !== undefined) {
|
|
2344
|
+
const rect = tracingRect(tracing.at, scaled(this.#tracingPaper.size, scaleIn(tracing)));
|
|
2345
|
+
maxX = Math.max(maxX, rect.maxX);
|
|
2346
|
+
maxY = Math.max(maxY, rect.maxY);
|
|
2347
|
+
}
|
|
2348
|
+
return { maxX, maxY };
|
|
2349
|
+
}
|
|
2350
|
+
/**
|
|
2351
|
+
* The ink, the tracing paper or the window went past the sheet's extent, or back: the sheet is
|
|
2352
|
+
* sized anew by its style — the column as wide as the page's fit times the extent's share of the
|
|
2353
|
+
* page, and the sheet in the extent's proportions —, and laid out (R73).
|
|
2354
|
+
*/
|
|
2355
|
+
#regrow() {
|
|
2356
|
+
const zoom = this.#example === undefined ? PAGE_ZOOM.value : 1;
|
|
2357
|
+
const zoomed = zoom !== this.#zoom;
|
|
2358
|
+
if (zoomed) {
|
|
2359
|
+
this.#zoom = zoom;
|
|
2360
|
+
this.#column.style.setProperty("--zoom", String(zoom));
|
|
2361
|
+
}
|
|
2362
|
+
const extent = this.#reach();
|
|
2363
|
+
const grown = extent.width !== this.#extent.width || extent.height !== this.#extent.height;
|
|
2364
|
+
if (!zoomed && !grown)
|
|
2365
|
+
return;
|
|
2366
|
+
if (grown) {
|
|
2367
|
+
this.#extent = extent;
|
|
2368
|
+
this.#column.style.setProperty("--across", String(extent.width / SHEET.width));
|
|
2369
|
+
this.#sheet.style.aspectRatio = `${extent.width} / ${extent.height}`;
|
|
2370
|
+
this.#drawGrid();
|
|
2371
|
+
}
|
|
2372
|
+
this.#layout();
|
|
2373
|
+
}
|
|
2374
|
+
/**
|
|
2375
|
+
* Zoom in or Zoom out was pressed (R73): the page's zoom goes a quarter larger or smaller, and
|
|
2376
|
+
* every sheet of the page is laid out by it — but not while a pointer writes or erases on one of
|
|
2377
|
+
* them, for nothing moves under it.
|
|
2378
|
+
*/
|
|
2379
|
+
#zoomBy(larger) {
|
|
2380
|
+
if (!PEN_MODE.writing)
|
|
2381
|
+
PAGE_ZOOM.step(larger);
|
|
2382
|
+
}
|
|
2383
|
+
/** Two fingers pinched by `ratio` about `x` and `y` on the screen: the page's zoom goes by it. */
|
|
2384
|
+
#pinch(ratio, x, y) {
|
|
2385
|
+
if (this.#example !== undefined)
|
|
2386
|
+
return;
|
|
2387
|
+
this.#anchor = { x, y };
|
|
2388
|
+
try {
|
|
2389
|
+
PAGE_ZOOM.set(PAGE_ZOOM.value * ratio);
|
|
2390
|
+
}
|
|
2391
|
+
finally {
|
|
2392
|
+
this.#anchor = undefined;
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
/**
|
|
2396
|
+
* The page's zoom has changed (R73): the sheet is laid out by it at once, the point of the sheet
|
|
2397
|
+
* under a pinch's middle, or else the one the last press held, or else under the middle of the
|
|
2398
|
+
* part in sight, standing where it was on the screen, and the bar shows what the zoom can do now.
|
|
2399
|
+
*/
|
|
2400
|
+
#zoomed() {
|
|
2401
|
+
const before = this.isConnected ? this.#view() : undefined;
|
|
2402
|
+
const k = this.#k;
|
|
2403
|
+
this.#regrow();
|
|
2404
|
+
if (before !== undefined && this.#k !== k && this.#k > 0) {
|
|
2405
|
+
const { shown } = before;
|
|
2406
|
+
const held = this.#anchor === undefined && this.#held?.box === this.#heldBox() ? this.#held : undefined;
|
|
2407
|
+
const x = this.#anchor?.x ?? held?.x ?? (shown.left + shown.right) / 2;
|
|
2408
|
+
const y = this.#anchor?.y ?? held?.y ?? (shown.top + shown.bottom) / 2;
|
|
2409
|
+
const at = held?.at ?? {
|
|
2410
|
+
x: (x - before.left) / before.k + before.vx,
|
|
2411
|
+
y: (y - before.top) / before.k + before.vy,
|
|
2412
|
+
};
|
|
2413
|
+
const port = clientBoxOf(this.#viewport);
|
|
2414
|
+
this.#viewport.scrollLeft = this.#sheetAtX + at.x * this.#k - (x - port.left) / port.across;
|
|
2415
|
+
this.#viewport.scrollTop = this.#sheetAt + at.y * this.#k - (y - port.top) / port.down;
|
|
2416
|
+
this.#scrolled();
|
|
2417
|
+
this.#held = this.#anchor === undefined ? { at, x, y, box: this.#heldBox() } : undefined;
|
|
2418
|
+
}
|
|
2419
|
+
this.#refresh();
|
|
2420
|
+
}
|
|
2421
|
+
/** Where the container stands on the screen and how far it is scrolled, as a press leaves it. */
|
|
2422
|
+
#heldBox() {
|
|
2423
|
+
const { left, top, right, bottom } = this.#viewport.getBoundingClientRect();
|
|
2424
|
+
const { scrollLeft, scrollTop } = this.#viewport;
|
|
2425
|
+
return [left, top, right, bottom, scrollLeft, scrollTop].join(" ");
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* The template's grid over the whole sheet, as far as it goes (R73): the task's, or a task from
|
|
2429
|
+
* paper's that the learner turns, none on a blank one (R88); a workbook has its lines instead.
|
|
2430
|
+
*/
|
|
2431
|
+
#drawGrid() {
|
|
2432
|
+
const template = this.#shownTemplate;
|
|
2433
|
+
const grid = isWorkbook(template)
|
|
2434
|
+
? undefined
|
|
2435
|
+
: this.#paper === undefined
|
|
2436
|
+
? template.grid
|
|
2437
|
+
: rulingsOf(this.#paperGrid);
|
|
2438
|
+
const { width, height } = this.#extent;
|
|
2439
|
+
const key = grid === undefined ? "" : `${grid.kind} ${grid.step} ${width} ${height}`;
|
|
2440
|
+
if (key === this.#gridDrawn)
|
|
2441
|
+
return;
|
|
2442
|
+
this.#gridDrawn = key;
|
|
2443
|
+
this.#grid.setAttribute("d", grid === undefined ? "" : gridPath(grid, this.#extent));
|
|
2444
|
+
this.#grid.classList.toggle("dots", grid?.kind === "dots");
|
|
2445
|
+
// A page of units is more than any padding at the smallest k.
|
|
2446
|
+
const band = SHEET.height;
|
|
2447
|
+
for (const [svg, top] of [
|
|
2448
|
+
[this.#above, -band],
|
|
2449
|
+
[this.#below, height],
|
|
2450
|
+
]) {
|
|
2451
|
+
svg.setAttribute("viewBox", `0 ${top} ${width} ${band}`);
|
|
2452
|
+
const path = svg.firstElementChild;
|
|
2453
|
+
path?.setAttribute("d", grid === undefined ? "" : gridBand(grid, width, top, top + band));
|
|
2454
|
+
path?.classList.toggle("dots", grid?.kind === "dots");
|
|
2455
|
+
}
|
|
2065
2456
|
}
|
|
2066
2457
|
/** A new density — the window on another screen, the page zoomed — lays the canvas out anew. */
|
|
2067
2458
|
#watchDensity() {
|
|
@@ -2092,6 +2483,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2092
2483
|
* in its order. A history given meanwhile is no action, and what it replaced is told of no more.
|
|
2093
2484
|
*/
|
|
2094
2485
|
#changed() {
|
|
2486
|
+
this.#regrow();
|
|
2095
2487
|
this.#request();
|
|
2096
2488
|
// The boxes and the row before the event, and for an action a listener takes as well.
|
|
2097
2489
|
this.#fill();
|
|
@@ -2120,13 +2512,26 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2120
2512
|
* back what the learner chose.
|
|
2121
2513
|
*/
|
|
2122
2514
|
#choose(tool) {
|
|
2123
|
-
if (tool === this.#tool || !this.#
|
|
2515
|
+
if (tool === this.#tool || !this.#allows(tool))
|
|
2124
2516
|
return;
|
|
2125
2517
|
this.#tool = tool;
|
|
2126
2518
|
this.#refresh();
|
|
2127
2519
|
const detail = Object.freeze({ tool });
|
|
2128
2520
|
this.dispatchEvent(new CustomEvent(TOOL_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2129
2521
|
}
|
|
2522
|
+
/**
|
|
2523
|
+
* The learner turned the task from paper's grid with its button (R88): the next, round, and
|
|
2524
|
+
* whoever listens hears of it. A consumer that gives the grid follows it.
|
|
2525
|
+
*/
|
|
2526
|
+
#turnGrid() {
|
|
2527
|
+
if (this.#paper === undefined)
|
|
2528
|
+
return;
|
|
2529
|
+
this.#paperGrid = nextGrid(this.#paperGrid);
|
|
2530
|
+
this.#drawGrid();
|
|
2531
|
+
this.#refresh();
|
|
2532
|
+
const detail = Object.freeze({ grid: this.#paperGrid });
|
|
2533
|
+
this.dispatchEvent(new CustomEvent(GRID_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2534
|
+
}
|
|
2130
2535
|
/**
|
|
2131
2536
|
* The learner hid the tracing paper with the button atop the tools, or showed it again (R87): its
|
|
2132
2537
|
* strokes go out of sight with it and stay in the history and in the work, and whoever listens
|
|
@@ -2139,7 +2544,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2139
2544
|
const state = this.#tracing;
|
|
2140
2545
|
if (this.#paper === undefined || state === undefined)
|
|
2141
2546
|
return;
|
|
2142
|
-
this.#tracing = Object.freeze({
|
|
2547
|
+
this.#tracing = Object.freeze({ ...state, hidden: !state.hidden });
|
|
2143
2548
|
this.#refresh();
|
|
2144
2549
|
this.#request();
|
|
2145
2550
|
this.#tracingChanged();
|
|
@@ -2153,13 +2558,66 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2153
2558
|
if (state === undefined)
|
|
2154
2559
|
return to;
|
|
2155
2560
|
this.#moveFrom ??= state;
|
|
2156
|
-
const
|
|
2561
|
+
const scale = scaleIn(state);
|
|
2562
|
+
const at = keptOn(to, scaled(this.#tracingPaper.size, scale));
|
|
2157
2563
|
if (at[0] === state.at[0] && at[1] === state.at[1])
|
|
2158
2564
|
return state.at;
|
|
2159
|
-
this.#tracing = Object.freeze({ at, hidden: state.hidden });
|
|
2565
|
+
this.#tracing = Object.freeze({ at, hidden: state.hidden, scale });
|
|
2566
|
+
this.#regrow();
|
|
2160
2567
|
this.#request();
|
|
2161
2568
|
return at;
|
|
2162
2569
|
}
|
|
2570
|
+
/** Ctrl or ⌘ with the wheel over the tracing paper in sight: a notch of its scale (R89). */
|
|
2571
|
+
#wheel(event) {
|
|
2572
|
+
if (!(event.ctrlKey || event.metaKey) || event.deltaY === 0)
|
|
2573
|
+
return;
|
|
2574
|
+
const tracing = this.#tracing;
|
|
2575
|
+
if (tracing === undefined || tracing.hidden || !this.#tracingPaper.ready)
|
|
2576
|
+
return;
|
|
2577
|
+
const screen = this.#view();
|
|
2578
|
+
if (screen === undefined)
|
|
2579
|
+
return;
|
|
2580
|
+
const point = toSheet(screen, event.clientX - screen.left, event.clientY - screen.top);
|
|
2581
|
+
const size = scaled(this.#tracingPaper.size, scaleIn(tracing));
|
|
2582
|
+
if (!onTracing(point, tracing.at, size))
|
|
2583
|
+
return;
|
|
2584
|
+
event.preventDefault();
|
|
2585
|
+
this.#tracingPaper.wheel(event.deltaY < 0);
|
|
2586
|
+
}
|
|
2587
|
+
/**
|
|
2588
|
+
* The learner scales the tracing paper by a corner, the bar of scale or the wheel (R89): to a
|
|
2589
|
+
* place and a scale, kept to the rule and to the sheet whole; its strokes scale with it, and the
|
|
2590
|
+
* marks on them too. The change tells of itself once it is over.
|
|
2591
|
+
*/
|
|
2592
|
+
#resizeTracing(to, by) {
|
|
2593
|
+
const state = this.#tracing;
|
|
2594
|
+
if (state === undefined)
|
|
2595
|
+
return { at: to, scale: by };
|
|
2596
|
+
this.#moveFrom ??= state;
|
|
2597
|
+
const scale = tracingScaleOf(by);
|
|
2598
|
+
const at = keptOn(to, scaled(this.#tracingPaper.size, scale));
|
|
2599
|
+
const next = Object.freeze({ at, hidden: state.hidden, scale });
|
|
2600
|
+
if (sameTracing(state, next))
|
|
2601
|
+
return { at: state.at, scale: scaleIn(state) };
|
|
2602
|
+
this.#tracing = next;
|
|
2603
|
+
this.#regrow();
|
|
2604
|
+
this.#request();
|
|
2605
|
+
return { at, scale };
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* "Fit" (R89): the tracing paper as wide as the window shows the sheet right of the bar of tools,
|
|
2609
|
+
* at the rule's place there, kept to the rule; down the window, centred, below the rule's top.
|
|
2610
|
+
*/
|
|
2611
|
+
#fitTracing() {
|
|
2612
|
+
const screen = this.#view();
|
|
2613
|
+
if (screen === undefined)
|
|
2614
|
+
return;
|
|
2615
|
+
const { width, height } = this.#tracingPaper.size;
|
|
2616
|
+
const across = screen.width / screen.k;
|
|
2617
|
+
const down = screen.height / screen.k;
|
|
2618
|
+
const scale = tracingScaleOf((across - TRACING.at[0] - TRACING.at[1]) / width);
|
|
2619
|
+
this.#resizeTracing([screen.vx + TRACING.at[0], screen.vy + Math.max(TRACING.at[1], (down - height * scale) / 2)], scale);
|
|
2620
|
+
}
|
|
2163
2621
|
/** The learner's move of the tracing paper is over: whoever listens hears of it, if it moved. */
|
|
2164
2622
|
#tracingMoved() {
|
|
2165
2623
|
const from = this.#moveFrom;
|
|
@@ -2202,8 +2660,13 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2202
2660
|
#sized() {
|
|
2203
2661
|
const state = this.#tracing;
|
|
2204
2662
|
const size = this.#tracingPaper.size;
|
|
2205
|
-
|
|
2206
|
-
|
|
2663
|
+
const scale = state === undefined ? 1 : scaleIn(state);
|
|
2664
|
+
if (state !== undefined && whollyOff(state.at, scaled(size, scale))) {
|
|
2665
|
+
this.#tracing = Object.freeze({
|
|
2666
|
+
at: keptOn(state.at, scaled(size, scale)),
|
|
2667
|
+
hidden: state.hidden,
|
|
2668
|
+
scale,
|
|
2669
|
+
});
|
|
2207
2670
|
this.#replace();
|
|
2208
2671
|
}
|
|
2209
2672
|
this.#request();
|
|
@@ -2214,17 +2677,23 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2214
2677
|
this.dispatchEvent(new CustomEvent(TRACING_CHANGE, { bubbles: true, composed: true, detail }));
|
|
2215
2678
|
}
|
|
2216
2679
|
/**
|
|
2217
|
-
* A stroke where it lies on the sheet: one of the tracing paper's moved to where the paper lies
|
|
2218
|
-
* once for each place (R87); the sheet's as it is.
|
|
2680
|
+
* A stroke where it lies on the sheet: one of the tracing paper's moved to where the paper lies at
|
|
2681
|
+
* its scale, once for each place (R87; R89); the sheet's as it is.
|
|
2219
2682
|
*/
|
|
2220
|
-
#onSheet(stroke,
|
|
2683
|
+
#onSheet(stroke, tracing) {
|
|
2221
2684
|
if (!this.#work.onTracing(stroke.id))
|
|
2222
2685
|
return stroke;
|
|
2686
|
+
const { at } = tracing;
|
|
2687
|
+
const scale = scaleIn(tracing);
|
|
2223
2688
|
const kept = this.#placed.get(stroke);
|
|
2224
|
-
if (kept !== undefined &&
|
|
2689
|
+
if (kept !== undefined &&
|
|
2690
|
+
kept.at[0] === at[0] &&
|
|
2691
|
+
kept.at[1] === at[1] &&
|
|
2692
|
+
kept.scale === scale) {
|
|
2225
2693
|
return kept.stroke;
|
|
2226
|
-
|
|
2227
|
-
|
|
2694
|
+
}
|
|
2695
|
+
const placed = onSheet(stroke, at, scale);
|
|
2696
|
+
this.#placed.set(stroke, { at, scale, stroke: placed });
|
|
2228
2697
|
return placed;
|
|
2229
2698
|
}
|
|
2230
2699
|
/**
|
|
@@ -2365,12 +2834,6 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2365
2834
|
* undo and clearing have anything to do (R28), and a worked example's demo (R42).
|
|
2366
2835
|
*/
|
|
2367
2836
|
#refresh() {
|
|
2368
|
-
// The finger's button comes and goes between the strokes of the whole page alone: a row that
|
|
2369
|
-
// wraps would move this sheet, and the sheets below it, under the pen. It is there in pen mode,
|
|
2370
|
-
// on a device that has touch (R29).
|
|
2371
|
-
if (this.#writer() === undefined && !PEN_MODE.writing) {
|
|
2372
|
-
this.#finger = PEN_MODE.on && navigator.maxTouchPoints > 0;
|
|
2373
|
-
}
|
|
2374
2837
|
const demo = this.#demoState;
|
|
2375
2838
|
this.#tools.show({
|
|
2376
2839
|
kind: this.#rowKind(),
|
|
@@ -2380,11 +2843,12 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2380
2843
|
clearable: this.#work.strokes.length > 0,
|
|
2381
2844
|
larger: PAGE_ZOOM.larger,
|
|
2382
2845
|
smaller: PAGE_ZOOM.smaller,
|
|
2383
|
-
finger: this.#finger,
|
|
2384
2846
|
opens: this.#nextPart() !== undefined,
|
|
2385
2847
|
expanded: demo?.hidden !== true,
|
|
2386
2848
|
traced: this.#tracing?.hidden !== true,
|
|
2849
|
+
grid: this.#paperGrid,
|
|
2387
2850
|
});
|
|
2851
|
+
this.#sheet.classList.toggle("hand", this.#tool === HAND);
|
|
2388
2852
|
this.#nameRegion();
|
|
2389
2853
|
}
|
|
2390
2854
|
/**
|
|
@@ -2393,14 +2857,14 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2393
2857
|
* scrolls by no key without (R90 spec; WebKit's bug 277290). Without a height of its own the
|
|
2394
2858
|
* element scrolls with the page and has no stop of Tab, and neither has one whose task fits. A
|
|
2395
2859
|
* container that holds the focus keeps all three till the focus leaves it, not the window (R33).
|
|
2396
|
-
* Across, it scrolls while the sheet is
|
|
2397
|
-
* then too
|
|
2860
|
+
* Across, it scrolls while the sheet is wider than it, and an element without a height has a
|
|
2861
|
+
* region then too (R73).
|
|
2398
2862
|
*/
|
|
2399
2863
|
#region() {
|
|
2400
2864
|
if (!this.isConnected)
|
|
2401
2865
|
return;
|
|
2402
2866
|
const viewport = this.#viewport;
|
|
2403
|
-
const across =
|
|
2867
|
+
const across = overflowOf(viewport, "x") > EDGE;
|
|
2404
2868
|
const focused = this.shadowRoot?.activeElement === viewport;
|
|
2405
2869
|
const scrolls = overflowOf(viewport) > EDGE || across || focused;
|
|
2406
2870
|
write(viewport, "tabindex", scrolls ? "0" : null);
|
|
@@ -2491,7 +2955,9 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2491
2955
|
return undefined;
|
|
2492
2956
|
if (tracing === undefined || !work.onTracing(id))
|
|
2493
2957
|
return this.#pointBoxOf(stroke);
|
|
2494
|
-
return tracing.hidden
|
|
2958
|
+
return tracing.hidden
|
|
2959
|
+
? undefined
|
|
2960
|
+
: boxOnSheet(this.#pointBoxOf(stroke), tracing.at, scaleIn(tracing));
|
|
2495
2961
|
};
|
|
2496
2962
|
const half = 1 / screen.k;
|
|
2497
2963
|
for (const mark of this.#shown) {
|
|
@@ -2503,8 +2969,8 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2503
2969
|
: shown && {
|
|
2504
2970
|
minX: Math.max(shown.minX - MARK_PADDING, half),
|
|
2505
2971
|
minY: Math.max(shown.minY - MARK_PADDING, half),
|
|
2506
|
-
maxX: Math.min(shown.maxX + MARK_PADDING,
|
|
2507
|
-
maxY: Math.min(shown.maxY + MARK_PADDING,
|
|
2972
|
+
maxX: Math.min(shown.maxX + MARK_PADDING, REACH.width - half),
|
|
2973
|
+
maxY: Math.min(shown.maxY + MARK_PADDING, REACH.height - half),
|
|
2508
2974
|
};
|
|
2509
2975
|
if (this.#writing === undefined || frame === null)
|
|
2510
2976
|
mark.under = false;
|
|
@@ -2512,8 +2978,10 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2512
2978
|
// A frame that came or moved while the stroke was under way is checked against all of it.
|
|
2513
2979
|
const points = sameBox(frame, mark.frame) ? fresh : this.#writing.stroke.points;
|
|
2514
2980
|
// A stroke on the tracing paper holds its points from the paper's corner (R87).
|
|
2515
|
-
const
|
|
2516
|
-
|
|
2981
|
+
const on = this.#writeOn === "tracing" ? this.#tracing : undefined;
|
|
2982
|
+
const [dx, dy] = on?.at ?? [0, 0];
|
|
2983
|
+
const by = on === undefined ? 1 : scaleIn(on);
|
|
2984
|
+
mark.under = points.some((point) => near({ ...point, x: point.x * by + dx, y: point.y * by + dy }, frame, INK_REACH + half));
|
|
2517
2985
|
}
|
|
2518
2986
|
mark.frame = frame;
|
|
2519
2987
|
const drawn = frame === null
|
|
@@ -2615,15 +3083,16 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2615
3083
|
const tracing = this.#tracing;
|
|
2616
3084
|
const work = this.#work;
|
|
2617
3085
|
const shown = tracing !== undefined && !tracing.hidden;
|
|
2618
|
-
const draw = (stroke, dx, dy) => {
|
|
3086
|
+
const draw = (stroke, dx, dy, by = 1) => {
|
|
2619
3087
|
// The outline keeps within half the widest line of the points: twice that is out of sight.
|
|
2620
3088
|
const box = this.#pointBoxOf(stroke);
|
|
2621
|
-
|
|
3089
|
+
const reach = 2 * INK_REACH * by;
|
|
3090
|
+
if (box.maxY * by + dy + reach < screen.vy || box.minY * by + dy - reach > bottom)
|
|
2622
3091
|
return;
|
|
2623
|
-
if (box.maxX + dx +
|
|
3092
|
+
if (box.maxX * by + dx + reach < screen.vx || box.minX * by + dx - reach > right)
|
|
2624
3093
|
return;
|
|
2625
3094
|
const ink = this.#finished(stroke);
|
|
2626
|
-
if (ink.bottom + dy >= screen.vy && ink.top + dy <= bottom)
|
|
3095
|
+
if (ink.bottom * by + dy >= screen.vy && ink.top * by + dy <= bottom)
|
|
2627
3096
|
context.fill(ink.path);
|
|
2628
3097
|
};
|
|
2629
3098
|
context.setTransform(across, 0, 0, down, -screen.vx * across, -screen.vy * down);
|
|
@@ -2643,9 +3112,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
2643
3112
|
if (!shown)
|
|
2644
3113
|
return;
|
|
2645
3114
|
const [dx, dy] = tracing.at;
|
|
2646
|
-
|
|
3115
|
+
// The paper's strokes are as large as its scale draws it, from its corner (R89).
|
|
3116
|
+
const by = scaleIn(tracing);
|
|
3117
|
+
context.setTransform(across * by, 0, 0, down * by, (dx - screen.vx) * across, (dy - screen.vy) * down);
|
|
2647
3118
|
for (const stroke of traced)
|
|
2648
|
-
draw(stroke, dx, dy);
|
|
3119
|
+
draw(stroke, dx, dy, by);
|
|
2649
3120
|
if (live !== undefined && liveTraced)
|
|
2650
3121
|
context.fill(pathOf(this.#outline(live, false)));
|
|
2651
3122
|
}
|
|
@@ -2875,7 +3346,8 @@ function parentOf(element) {
|
|
|
2875
3346
|
/**
|
|
2876
3347
|
* An element's client box on the screen — what it shows of its content, within its borders and
|
|
2877
3348
|
* without its scroll bar — and how much the page scales it down the screen: 1 unless an ancestor
|
|
2878
|
-
* transforms it. The sheet's container has one, and so has any ancestor
|
|
3349
|
+
* transforms it. The sheet's container has one, and so has any ancestor the fingers or
|
|
3350
|
+
* the hand scroll (R29; R88).
|
|
2879
3351
|
*/
|
|
2880
3352
|
function clientBoxOf(element) {
|
|
2881
3353
|
const box = element.getBoundingClientRect();
|