@altnovatrail/canvas 0.1.5 → 0.1.7
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/README.md +2 -2
- package/lib/element/index.d.ts +2 -0
- package/lib/element/index.js +31 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,14 +39,14 @@ A pull request that changes the lock file has spec's recipe check it, as NovaTra
|
|
|
39
39
|
- `src/core/` — the DOM-free part, `@altnovatrail/canvas/core`: it runs the same in a browser and in Node, and its entry point gives the sheet's size, the types of the data and the fold of a history into its strokes.
|
|
40
40
|
- `src/element/` — the element `<novatrail-canvas>`, `@altnovatrail/canvas`: importing it registers the element. The types of its contract with the app — the element as `CanvasElement` has it, its events, the media, the tutor's marks, the history of writing, the work for checking and its context — are spec's, from `@altnovatrail/spec/canvas`, and this entry point gives them under spec's names, the same types; the DOM-free part gives the data's among them, the history of writing and the context of a submission. The app takes them from spec's package, `import type { CanvasElement } from "@altnovatrail/spec/canvas"`, at the version canvas has in its `dependencies`; canvas's own are only what the contract does not name: the commands `undo()` and `clear()`, and the task's temporary tools.
|
|
41
41
|
- `src/eval/` — the sample file of spec's eval protocol, which the samples page and the synthetic samples write: a sample of each composition, on a sheet or a workbook, its final geometry and its crops, written and read by the code of `@altnovatrail/contracts`; and the synthetic samples themselves, which code draws from a seed, with a hand of its own, on tasks of tutor's file of open tasks. It runs the same in a browser and in Node, and is no part of the package.
|
|
42
|
-
- `scripts/` — the check of the package as a consumer takes it, and of the archive a release puts out, the script that writes the synthetic samples into a folder, and the script that writes the row's icons, `src/element/icons.ts`, and `NOTICE` from the set of icons the lock file pins: `just icons` runs it, and `just ci` fails if they are not what it writes.
|
|
42
|
+
- `scripts/` — the check of the package as a consumer takes it, and of the archive a release puts out, the script that writes the synthetic samples into a folder and the one that packs them for a release, and the script that writes the row's icons, `src/element/icons.ts`, and `NOTICE` from the set of icons the lock file pins: `just icons` runs it, and `just ci` fails if they are not what it writes.
|
|
43
43
|
- `demo/` — a page to try the element on by hand, as the app is to have it: it gives the element a language and its task the tools allowed, keeps the history of writing as the element tells it and opens the sheet again from it, draws the groups of the strokes and the crop for checking under the sheet, gives the tutor's marks back over the crop Check sent, and shows a workbook's pages in the font and the language it gives, how many boxes are filled, the crop of each filled box Check sent and a mark given back on a box, and a lesson's worked example on a new element, on which nothing is written, whose demo opens part by part — a picture on an area of the sheet on the sheet itself — the page keeping how far it has gone and giving it back to the next element. `just demo` serves it on this machine.
|
|
44
44
|
- `vectors/` — the test vectors of the workbook's page layout, which its test writes and keeps current. The vectors of the rules the sheet shares with tutor's eval runner — the groups of strokes, the crop for checking, the snapping of a model's box to the strokes and the rule of boxes — are spec's, from its npm package `@altnovatrail/contracts`, and the tests hold the sheet's code to them.
|
|
45
45
|
- `examples/` — synthetic sample files, one of each composition, which the test of `src/eval/` writes and keeps current, and which spec's `sample-check` checks in CI.
|
|
46
46
|
- `tasks/` — the file of open tasks of a release of tutor that the synthetic samples answer, as the release has it, with its signature, which spec's `release-verify` checks in CI.
|
|
47
47
|
- `licenses.json` — the packages the license check accepts by name, each with why.
|
|
48
48
|
|
|
49
|
-
`just build` builds the package into `lib/`, and `just release-files v0.1.0` writes the files of that release into `dist/` — the package's archive, with NOTICE in it, LICENSE and SHA256SUMS — and prints the sums, which a build of the same commit gives again. `just synthetic <folder>` writes the synthetic samples into a folder, one file each, and prints what each shows: no tree holds them. `just ci` runs the checks CI runs: format, lint and types; the tests in Node and in Chromium; advisories; licenses. They run in the devcontainer, whose toolchain stage holds the browser the tests run in. The license check is spec's recipe, run from the `spec/` submodule with the exceptions in `licenses.json`, so it needs `spec/` checked out: see [CLAUDE.md](CLAUDE.md), Environment.
|
|
49
|
+
`just build` builds the package into `lib/`, and `just release-files v0.1.0` writes the files of that release into `dist/` — the package's archive, with NOTICE in it, the synthetic samples' archive and the list of what each shows, LICENSE and SHA256SUMS — and prints the sums, which a build of the same commit gives again. `just synthetic <folder>` writes the synthetic samples into a folder, one file each, and prints what each shows: no tree holds them. `just ci` runs the checks CI runs: format, lint and types; the tests in Node and in Chromium; advisories; licenses. They run in the devcontainer, whose toolchain stage holds the browser the tests run in. The license check is spec's recipe, run from the `spec/` submodule with the exceptions in `licenses.json`, so it needs `spec/` checked out: see [CLAUDE.md](CLAUDE.md), Environment.
|
|
50
50
|
|
|
51
51
|
## Documents
|
|
52
52
|
|
package/lib/element/index.d.ts
CHANGED
|
@@ -172,6 +172,8 @@ export declare class NovatrailCanvas extends HTMLElement implements CanvasElemen
|
|
|
172
172
|
*/
|
|
173
173
|
get marks(): Marks | undefined;
|
|
174
174
|
set marks(marks: Marks | undefined);
|
|
175
|
+
/** The element moved into another document: its root adopts that document's sheet (R51). */
|
|
176
|
+
adoptedCallback(): void;
|
|
175
177
|
connectedCallback(): void;
|
|
176
178
|
/**
|
|
177
179
|
* The element's `lang` came, changed or went: its buttons and a workbook's boxes are labelled in
|
package/lib/element/index.js
CHANGED
|
@@ -226,6 +226,30 @@ canvas {
|
|
|
226
226
|
.tools [aria-disabled="true"] { color: GrayText; border-color: GrayText; opacity: 1; }
|
|
227
227
|
}
|
|
228
228
|
`;
|
|
229
|
+
/** The sheet of STYLE that the elements of a document adopt, made by the first of them there. */
|
|
230
|
+
const sheets = new WeakMap();
|
|
231
|
+
/**
|
|
232
|
+
* Gives the element's shadow root its style, as a sheet the root adopts, and not a `<style>` in
|
|
233
|
+
* its tree: a consumer's content security policy that allows no inline style, as app's
|
|
234
|
+
* `style-src 'self'`, blocks the one and not the other, and the element asks of the policy only
|
|
235
|
+
* `img-src blob:` (R51; the second amendment of 2026-11-02 to R36 spec). A root adopts only a sheet
|
|
236
|
+
* made for its own document, by that document's window, and an element moved into another document
|
|
237
|
+
* comes there without its sheets: it adopts that document's sheet then. A document without a
|
|
238
|
+
* window, which can make no sheet, leaves the element unstyled till it comes into one that can.
|
|
239
|
+
*/
|
|
240
|
+
function adoptStyle(root) {
|
|
241
|
+
const owner = root.ownerDocument;
|
|
242
|
+
const view = owner.defaultView;
|
|
243
|
+
if (view === null)
|
|
244
|
+
return;
|
|
245
|
+
let sheet = sheets.get(owner);
|
|
246
|
+
if (sheet === undefined) {
|
|
247
|
+
sheet = new view.CSSStyleSheet();
|
|
248
|
+
sheet.replaceSync(STYLE);
|
|
249
|
+
sheets.set(owner, sheet);
|
|
250
|
+
}
|
|
251
|
+
root.adoptedStyleSheets = [sheet];
|
|
252
|
+
}
|
|
229
253
|
/** An `<svg>` layer of the sheet, which counts in sheet units and hides from screen readers. */
|
|
230
254
|
function svgLayer(name) {
|
|
231
255
|
const svg = document.createElementNS(SVG, "svg");
|
|
@@ -419,8 +443,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
419
443
|
constructor() {
|
|
420
444
|
super();
|
|
421
445
|
const root = this.attachShadow({ mode: "open" });
|
|
422
|
-
|
|
423
|
-
style.textContent = STYLE;
|
|
446
|
+
adoptStyle(root);
|
|
424
447
|
this.#viewport.className = "viewport";
|
|
425
448
|
this.#column.className = "column";
|
|
426
449
|
this.#sheet.className = "sheet";
|
|
@@ -435,7 +458,7 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
435
458
|
this.#sheet.append(this.#stage, this.#parts.spot);
|
|
436
459
|
this.#column.append(this.#statement.element, this.#parts.list, this.#parts.status, this.#sheet);
|
|
437
460
|
this.#viewport.append(this.#column);
|
|
438
|
-
root.append(
|
|
461
|
+
root.append(this.#tools.element, this.#viewport);
|
|
439
462
|
this.#lay(NO_TASK);
|
|
440
463
|
this.#refresh();
|
|
441
464
|
this.#canvas.addEventListener("pointerdown", (event) => this.#down(event));
|
|
@@ -768,6 +791,11 @@ export class NovatrailCanvas extends HTMLElement {
|
|
|
768
791
|
this.#given = given;
|
|
769
792
|
this.#showMarks(shown);
|
|
770
793
|
}
|
|
794
|
+
/** The element moved into another document: its root adopts that document's sheet (R51). */
|
|
795
|
+
adoptedCallback() {
|
|
796
|
+
if (this.shadowRoot !== null)
|
|
797
|
+
adoptStyle(this.shadowRoot);
|
|
798
|
+
}
|
|
771
799
|
connectedCallback() {
|
|
772
800
|
this.#resize.observe(this.#viewport);
|
|
773
801
|
this.#resize.observe(this.#statement.element);
|