@altnovatrail/canvas 0.1.6 → 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/lib/element/index.d.ts +2 -0
- package/lib/element/index.js +31 -3
- package/package.json +1 -1
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);
|