@altnovatrail/canvas 0.0.0-stage → 0.1.1

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.
Files changed (75) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +59 -2
  3. package/lib/core/boxes.d.ts +54 -0
  4. package/lib/core/boxes.js +116 -0
  5. package/lib/core/clock.d.ts +25 -0
  6. package/lib/core/clock.js +39 -0
  7. package/lib/core/crop.d.ts +87 -0
  8. package/lib/core/crop.js +227 -0
  9. package/lib/core/eraser.d.ts +42 -0
  10. package/lib/core/eraser.js +127 -0
  11. package/lib/core/example.d.ts +66 -0
  12. package/lib/core/example.js +116 -0
  13. package/lib/core/fields.d.ts +29 -0
  14. package/lib/core/fields.js +78 -0
  15. package/lib/core/geometry.d.ts +38 -0
  16. package/lib/core/geometry.js +107 -0
  17. package/lib/core/grid.d.ts +30 -0
  18. package/lib/core/grid.js +47 -0
  19. package/lib/core/groups.d.ts +55 -0
  20. package/lib/core/groups.js +172 -0
  21. package/lib/core/hands.d.ts +120 -0
  22. package/lib/core/hands.js +273 -0
  23. package/lib/core/history.d.ts +42 -0
  24. package/lib/core/history.js +228 -0
  25. package/lib/core/index.d.ts +12 -0
  26. package/lib/core/index.js +15 -0
  27. package/lib/core/ink.d.ts +1 -0
  28. package/lib/core/ink.js +5 -0
  29. package/lib/core/manifest.d.ts +22 -0
  30. package/lib/core/manifest.js +50 -0
  31. package/lib/core/marks.d.ts +145 -0
  32. package/lib/core/marks.js +454 -0
  33. package/lib/core/outline.d.ts +22 -0
  34. package/lib/core/outline.js +50 -0
  35. package/lib/core/page.d.ts +62 -0
  36. package/lib/core/page.js +309 -0
  37. package/lib/core/png.d.ts +13 -0
  38. package/lib/core/png.js +231 -0
  39. package/lib/core/raster.d.ts +14 -0
  40. package/lib/core/raster.js +72 -0
  41. package/lib/core/recorder.d.ts +73 -0
  42. package/lib/core/recorder.js +127 -0
  43. package/lib/core/screen.d.ts +35 -0
  44. package/lib/core/screen.js +36 -0
  45. package/lib/core/sets.d.ts +10 -0
  46. package/lib/core/sets.js +31 -0
  47. package/lib/core/sheet.d.ts +9 -0
  48. package/lib/core/sheet.js +6 -0
  49. package/lib/core/submission.d.ts +41 -0
  50. package/lib/core/submission.js +63 -0
  51. package/lib/core/task.d.ts +214 -0
  52. package/lib/core/task.js +343 -0
  53. package/lib/core/widths.d.ts +57 -0
  54. package/lib/core/widths.js +218 -0
  55. package/lib/core/work.d.ts +77 -0
  56. package/lib/core/work.js +293 -0
  57. package/lib/element/attributes.d.ts +11 -0
  58. package/lib/element/attributes.js +22 -0
  59. package/lib/element/index.d.ts +219 -0
  60. package/lib/element/index.js +1898 -0
  61. package/lib/element/labels.d.ts +41 -0
  62. package/lib/element/labels.js +74 -0
  63. package/lib/element/parts.d.ts +63 -0
  64. package/lib/element/parts.js +191 -0
  65. package/lib/element/pictures.d.ts +45 -0
  66. package/lib/element/pictures.js +167 -0
  67. package/lib/element/probe.d.ts +33 -0
  68. package/lib/element/probe.js +18 -0
  69. package/lib/element/session.d.ts +3 -0
  70. package/lib/element/session.js +7 -0
  71. package/lib/element/statement.d.ts +35 -0
  72. package/lib/element/statement.js +116 -0
  73. package/lib/element/tools.d.ts +64 -0
  74. package/lib/element/tools.js +254 -0
  75. package/package.json +41 -4
@@ -0,0 +1,219 @@
1
+ import type { CanvasElement, CanvasEventMap, ExportedWork } from "@altnovatrail/spec/canvas";
2
+ import { type Filled } from "../core/boxes.js";
3
+ import { type DemoState, type WorkedExample } from "../core/example.js";
4
+ import { type HistoryEvent } from "../core/history.js";
5
+ import { type Manifest } from "../core/manifest.js";
6
+ import { type Marks } from "../core/marks.js";
7
+ import { type Task, type Tool } from "../core/task.js";
8
+ import { type Media } from "./pictures.js";
9
+ /**
10
+ * The types of the contract of canvas and app are spec's (R74 spec; R07): the element as
11
+ * CanvasElement has it, what its events tell and the work it gives for checking, here, and the data
12
+ * — the history of writing, the context of a submission, the filled slots and the state of a demo
13
+ * — through the DOM-free part. The entry point gives them under spec's names, the same types. The
14
+ * tutor's marks, the media, the crop and a task with its temporary tools are the element's own
15
+ * (R26, R41).
16
+ */
17
+ export type { Box, CanvasElement, CanvasEventMap, DemoChangeEvent, ExportedCell, ExportedSheet, ExportedWork, ExportedWorkbook, HistoryChange, HistoryChangeEvent, ToolChange, ToolChangeEvent, } from "@altnovatrail/spec/canvas";
18
+ export type { Filled, Filling } from "../core/boxes.js";
19
+ export type { Crop, Frame } from "../core/crop.js";
20
+ export type { DemoState, WorkedExample } from "../core/example.js";
21
+ export type { GridKind } from "../core/grid.js";
22
+ export type { Group } from "../core/groups.js";
23
+ export type { HistoryEvent } from "../core/history.js";
24
+ export type { InkPoint, Stroke } from "../core/ink.js";
25
+ export type { Manifest } from "../core/manifest.js";
26
+ export type { Anchor, CellPlace, CropNumbers, Mark, Marks, SheetSubmission, Submission, WorkbookSubmission, } from "../core/marks.js";
27
+ export type { Canvas, Task, Tool } from "../core/task.js";
28
+ export type { Media } from "./pictures.js";
29
+ /** The name the element is registered under. */
30
+ export declare const TAG = "novatrail-canvas";
31
+ /**
32
+ * The element `<novatrail-canvas>`: the contract's `CanvasElement` (R74 spec), and beyond it the
33
+ * tutor's marks, the media and the commands undo and clear, which the contract does not name.
34
+ */
35
+ export declare class NovatrailCanvas extends HTMLElement implements CanvasElement {
36
+ #private;
37
+ constructor();
38
+ /** The element follows its own `lang`: its buttons are labelled in it (R07, R28). */
39
+ static readonly observedAttributes: string[];
40
+ /**
41
+ * What a press of the primary button does: "pen" writes, as the element starts, and "eraser"
42
+ * erases (R22). The learner switches it with the element's own buttons, which say a choice of
43
+ * theirs with a `toolchange`, and the consumer may set it too, which says nothing (R28). A press
44
+ * under way goes on as it began. A pen's eraser erases whatever the tool. A task without the
45
+ * eraser has none of it: "eraser" is a TypeError then, and a new task without it puts the pen
46
+ * back. A worked example has the pen alone, which writes nothing on its sheet (R42).
47
+ */
48
+ get tool(): Tool;
49
+ set tool(tool: Tool);
50
+ /**
51
+ * The open view of the task, of the module format 0.2 (R32): its ID, its statement, which the
52
+ * element shows above the page (R23), what the statement gives and asks, which app shows (R57
53
+ * spec), its canvas — the kind, the sheet's grid and the tools the task allows (R28) — and its
54
+ * items. A workbook's items are its lines, which the template shows, laid out on the page (R35,
55
+ * R36). The type is spec's, with the element's own tools (R73 spec; R41). A task the schema
56
+ * refuses is a TypeError that names the field, a field the open view has not among it, and so are
57
+ * a workbook whose lines do not fit, at the first item that does not (R35), and an answer slot in
58
+ * a zone; the sheet passes over a choice and an item's text, which app shows. Another task of the
59
+ * same layer, tools and statement changes nothing, and any other changes the template alone, of
60
+ * either kind: the work stays, for the next task is a new element (R20). A task without the
61
+ * eraser puts the pen back, with no event. While a worked example is shown a task is a TypeError,
62
+ * and `undefined` changes nothing: the element shows one or the other (R42).
63
+ */
64
+ get task(): Task | undefined;
65
+ set task(task: Task | undefined);
66
+ /**
67
+ * A lesson's worked example (R42; R58 spec): the open view of a segment `worked_example` of the
68
+ * module format 0.2 — its statement, which the element shows above the sheet as a task's (R23),
69
+ * the grid of its sheet, and the parts of the author's demo. The type is spec's (R73 spec; R41).
70
+ * The element shows a task or a worked example, not both: an example while a task is given, while
71
+ * the sheet has a history of writing, or while a stroke or an erasing is under way, is a
72
+ * TypeError, and so is one the schema refuses, at its field. `undefined` takes the example off,
73
+ * and the sheet is one with no task again. An example equal to the one shown changes nothing, and
74
+ * another replaces it, its grid and its statement apart, as a task does.
75
+ *
76
+ * On a worked example's sheet the learner does not write: the canvas takes no input, and a finger
77
+ * or a pen there scrolls the sheet as the browser scrolls the statement. Its row has no tools of
78
+ * writing and is named a worked example's. `task`, `history` other than the empty one and
79
+ * `marks` are TypeErrors, and so is an eraser: the tool is the pen alone, and `exportWork()` and
80
+ * `filled` give null. The next segment of a lesson is a new element (R20).
81
+ *
82
+ * The parts of the demo the learner opens one at a time with the row's Next, into a list between
83
+ * the statement and the sheet, and hides and shows whole with Demo; `demoState` tells how far
84
+ * they have gone. Another example starts its demo at the beginning.
85
+ */
86
+ get workedExample(): WorkedExample | undefined;
87
+ set workedExample(example: WorkedExample | undefined);
88
+ /**
89
+ * How far the learner has gone through the worked example's demo (R42): `opened`, how many of
90
+ * its parts are open, from the first, and `hidden`, whether the whole demo is hidden — frozen,
91
+ * and the same object until it changes. A new example starts at `{ opened: 0, hidden: false }`,
92
+ * and without one it is `undefined`. The learner changes it with the row's Next and Demo, which
93
+ * say so with a `demochange`; the consumer may give it back, which says nothing, tells a screen
94
+ * reader nothing, and scrolls nothing. It is given after the example, for it is checked against
95
+ * the example's parts: before one, a state is a TypeError, and `undefined` changes nothing. A
96
+ * state is an object of `opened`, a whole number from 0 to the number of parts, and `hidden`,
97
+ * true or false, or it is a TypeError that names the field. One that says the same changes
98
+ * nothing. Parts do not close one by one for the learner, but a consumer may give fewer.
99
+ */
100
+ get demoState(): DemoState | undefined;
101
+ set demoState(state: DemoState | undefined);
102
+ /**
103
+ * The open view of the module's manifest (R32), of which the element reads the version of the
104
+ * module format — "0.2", or the manifest is a TypeError (R44 spec) — the height of a digit on the
105
+ * crop for checking, `canvas.digit_height`, 24 px unless given, and the explanation language, the
106
+ * statement's and a workbook's lines'. Without a manifest the digits are 24 px, and the statement
107
+ * and the lines are in the element's own `lang`. The rest of it the element passes over, but for
108
+ * the canvas settings, which are its own: one it does not know is a TypeError. A manifest it
109
+ * cannot read is a TypeError that names the field, and the element stays as it was; the same
110
+ * object given again is read again, for the consumer may have changed it. The task and the
111
+ * manifest are each the consumer's to give, in either order: `exportWork()` takes the height
112
+ * when it is called (R27).
113
+ */
114
+ get manifest(): Manifest | undefined;
115
+ set manifest(manifest: Manifest | undefined);
116
+ /**
117
+ * What gives the files of the pictures, by their references (R07): a task's statement's, and a
118
+ * worked example's — its statement's and every part's of its demo, which it asks for as the
119
+ * example comes, before the learner opens them (R42). A reference is asked for once, whichever
120
+ * pictures show it, and its file stays while the task or the example names it. Until a picture's
121
+ * file comes, or if it never does, its frame shows what it shows in words. A new function serves
122
+ * the references that have no file yet, and stops no load the last one began.
123
+ */
124
+ get media(): Media | undefined;
125
+ set media(media: Media | undefined);
126
+ /**
127
+ * The history of writing (R22, R27): every stroke, erasing, clearing and undo on the sheet, in the
128
+ * order they landed, at the sheet's time — frozen, and the same array until the next action. The
129
+ * consumer keeps it, adding what `historychange` tells, and gives it back to open the sheet as it
130
+ * was: the strokes, and the actions undo takes back.
131
+ *
132
+ * The history the sheet has changes nothing: the very array, or one whose every event says the
133
+ * same — fields the sheet does not keep are passed over, and `undefined` is the empty one. A
134
+ * stroke under way goes on, and the marks stay. Any other history replaces the sheet, with no
135
+ * event: it must be one the sheet could have written, or it is a TypeError that names the field,
136
+ * and the sheet stays as it was. A stroke or an erasing under way goes: its IDs and its times are
137
+ * the last sheet's. The clock goes on more than the pause of the groups after the history's last
138
+ * event, the next stroke takes the next ID, and the tutor's marks go back on the strokes, or off,
139
+ * if the history has not their strokes. A history that is where the sheet's began loses what came
140
+ * after, and says so in the console. The task and the history are each the consumer's to give, in
141
+ * either order. A worked example's sheet has the empty history alone: any other is a TypeError
142
+ * (R42).
143
+ */
144
+ get history(): readonly HistoryEvent[];
145
+ set history(history: readonly HistoryEvent[] | undefined);
146
+ /**
147
+ * Which answer slots the learner's strokes fill, per item, per slot, in the task's order, by the
148
+ * strokes `exportWork()` would take — not the stroke under way, but those under an eraser not
149
+ * yet lifted. A workbook's boxes, each whether it holds one (R34, R37): a stroke is in one box
150
+ * or in none, by the rule of R37, and what is in none is the draft. A sheet's one answer anywhere
151
+ * on it or the whole sheet, whether the sheet holds one (R42). `null` for a sheet of choices,
152
+ * whose options app marks, for a sheet with no task, and for a worked example. Frozen, and the
153
+ * same array until a slot changes. An action on the sheet changes it before its
154
+ * `historychange`, and a task or a history given changes it with no event.
155
+ */
156
+ get filled(): Filled | null;
157
+ /**
158
+ * The tutor's marks of one submission, with the context the element gave with its work (R07,
159
+ * R26): each a frame where a group of strokes is, or a box on the crop the model saw, and on a
160
+ * workbook where an answer cell is, by its item and its slot (R39). A mark holds on to the
161
+ * strokes the model saw there and is drawn around those of them the sheet shows, as they are now
162
+ * — a cell's around its box too: new strokes do not move it, and when all of them are erased it
163
+ * is gone, till undo brings them back. A box that comes near no stroke, a cell on a sheet, which
164
+ * takes no zones, and a box of a workbook that was empty, have no frame: the question is asked
165
+ * without one. The type is the element's own until spec's contract gives one. A submission goes
166
+ * back to a sheet whose history holds its strokes, as its digest tells (R27), and a workbook's
167
+ * to a page of its boxes: one of other strokes or other boxes is a TypeError, and so are marks
168
+ * given before the task and the history they hold on to, and marks that are not marks. A new
169
+ * history, and a new page, put the marks back on their strokes, or take them off. `undefined`
170
+ * takes the marks off. Every value is checked as it comes, and marks equal to those shown write
171
+ * nothing. A worked example's sheet has nothing to mark: marks are a TypeError there (R42).
172
+ */
173
+ get marks(): Marks | undefined;
174
+ set marks(marks: Marks | undefined);
175
+ connectedCallback(): void;
176
+ /**
177
+ * The element's `lang` came, changed or went: its buttons and a workbook's boxes are labelled in
178
+ * it, or in English for a language their labels are not in, and for none (R28, R36). An attribute
179
+ * the element had before it was defined comes here just after the constructor, which reads no
180
+ * attribute.
181
+ */
182
+ attributeChangedCallback(): void;
183
+ /**
184
+ * Takes back the last action on the sheet — the last stroke written, the last erasing, or the
185
+ * clearing — and says whether there was one (R19, R22), with a `historychange` if there was
186
+ * (R27). The element's Undo button calls it, and so may the consumer (R28). A stroke under way
187
+ * stays: it lands when it ends. So does an erasing: what it came near leaves the sheet when it
188
+ * lifts, if it is on the sheet then.
189
+ */
190
+ undo(): boolean;
191
+ /**
192
+ * Takes every stroke off the sheet, an action that undo takes back, and says whether there were
193
+ * any (R19), with a `historychange` if there were (R27). The element's Clear button calls it, and
194
+ * so may the consumer (R28). A stroke under way stays: it lands when it ends.
195
+ */
196
+ clear(): boolean;
197
+ /**
198
+ * The work for checking (R07, R27), when the consumer asks for it, at Check, at the height of a
199
+ * digit the manifest asks for (R25, R32). On a sheet it is the crop of the strokes the sheet
200
+ * shows, its PNG, and the context of the submission — the crop's numbers, the groups and their
201
+ * digest (R26, R27). On a workbook it is the crop of each filled box, by its strokes alone, with
202
+ * its item and its slot, and the context — the table «box → stroke IDs» and its digest (R34,
203
+ * R38); the draft goes nowhere. The consumer keeps the context, sends only the PNGs and their
204
+ * places to be checked (R09 spec), and gives the context back with the tutor's marks. It is the
205
+ * sheet as it is when this is called: a stroke under way is not on it yet, while the strokes
206
+ * under an eraser not yet lifted still are, as `filled` has them. A sheet without strokes, and a
207
+ * workbook with no box filled, have no work to check, and the promise gives null (H3); so has a
208
+ * worked example, whose sheet the learner does not write on (R42).
209
+ */
210
+ exportWork(): Promise<ExportedWork | null>;
211
+ disconnectedCallback(): void;
212
+ }
213
+ declare global {
214
+ interface HTMLElementTagNameMap {
215
+ "novatrail-canvas": NovatrailCanvas;
216
+ }
217
+ interface GlobalEventHandlersEventMap extends CanvasEventMap {
218
+ }
219
+ }