@zumer/orbit-kit 2.0.0 → 2.1.0
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 -0
- package/package.json +1 -1
- package/src/base.js +42 -0
package/README.md
CHANGED
|
@@ -41,6 +41,8 @@ import '@zumer/orbit-kit/o-timer.js'
|
|
|
41
41
|
|
|
42
42
|
`@zumer/orbit` 2 is a peer dependency. The kit does not work with Orbit 1.x. Components are standard custom elements, so they work in plain HTML and in any framework that renders the DOM.
|
|
43
43
|
|
|
44
|
+
Inside a shadow root (a card, a component of yours) the page's stylesheets do not reach the components. The kit adopts its own stylesheets into that root on its own. Orbit's stylesheet is yours to put there, as for any Orbit layout in shadow DOM: `root.adoptedStyleSheets = [orbitSheet]`, or a `<link>` inside the root. `base.js` exports `adoptKitStyles(root)` for a root you fill before any component connects.
|
|
45
|
+
|
|
44
46
|
## Components
|
|
45
47
|
|
|
46
48
|
| Tag | What it is |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zumer/orbit-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Ready-made radial web components built on Orbit 2: gauges, donut charts, activity rings, knobs, radial menus, instruments, clocks, compasses, radars, timers and status rings, one tag each.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/orbit-kit.js",
|
package/src/base.js
CHANGED
|
@@ -207,6 +207,8 @@ export class OrbitKitElement extends HTMLElementBase {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
this._render();
|
|
210
|
+
// build() injected this component's stylesheet; a shadow root needs it too.
|
|
211
|
+
adoptKitStyles(this.getRootNode?.());
|
|
210
212
|
this.onConnected?.();
|
|
211
213
|
}
|
|
212
214
|
|
|
@@ -557,8 +559,12 @@ export function define(tag, cls) {
|
|
|
557
559
|
}
|
|
558
560
|
}
|
|
559
561
|
|
|
562
|
+
/** The kit's stylesheets by id: the page gets a <style>, a shadow root adopts them. */
|
|
563
|
+
const SHEETS = new Map();
|
|
564
|
+
|
|
560
565
|
/** Inject a stylesheet once, keyed by id. */
|
|
561
566
|
export function injectStyleOnce(id, css) {
|
|
567
|
+
if (!SHEETS.has(id)) SHEETS.set(id, { css, sheets: new WeakMap() });
|
|
562
568
|
if (typeof document === 'undefined' || !document.head || document.getElementById(id)) return;
|
|
563
569
|
const style = document.createElement('style');
|
|
564
570
|
style.id = id;
|
|
@@ -566,6 +572,42 @@ export function injectStyleOnce(id, css) {
|
|
|
566
572
|
document.head.appendChild(style);
|
|
567
573
|
}
|
|
568
574
|
|
|
575
|
+
/**
|
|
576
|
+
* The page's stylesheets stop at a shadow root, so a component inside one
|
|
577
|
+
* adopts the kit's stylesheets into that root (every component does this when
|
|
578
|
+
* it connects): constructed sheets, one per document, or a <style> where the
|
|
579
|
+
* browser has none. Orbit's own stylesheet is yours to put in that root, as
|
|
580
|
+
* for any Orbit layout in shadow DOM.
|
|
581
|
+
*/
|
|
582
|
+
export function adoptKitStyles(root) {
|
|
583
|
+
if (!root || root.nodeType !== 11 || !root.host) return;
|
|
584
|
+
const doc = root.ownerDocument;
|
|
585
|
+
const Sheet = doc?.defaultView?.CSSStyleSheet;
|
|
586
|
+
if (Array.isArray(root.adoptedStyleSheets) && Sheet) {
|
|
587
|
+
try {
|
|
588
|
+
const missing = [];
|
|
589
|
+
for (const entry of SHEETS.values()) {
|
|
590
|
+
let sheet = entry.sheets.get(doc);
|
|
591
|
+
if (!sheet) {
|
|
592
|
+
sheet = new Sheet();
|
|
593
|
+
sheet.replaceSync(entry.css);
|
|
594
|
+
entry.sheets.set(doc, sheet);
|
|
595
|
+
}
|
|
596
|
+
if (!root.adoptedStyleSheets.includes(sheet)) missing.push(sheet);
|
|
597
|
+
}
|
|
598
|
+
if (missing.length) root.adoptedStyleSheets = [...root.adoptedStyleSheets, ...missing];
|
|
599
|
+
return;
|
|
600
|
+
} catch { /* no constructed sheets here: fall back to <style> */ }
|
|
601
|
+
}
|
|
602
|
+
for (const [id, entry] of SHEETS) {
|
|
603
|
+
if (root.querySelector(`style[data-orbit-kit="${id}"]`)) continue;
|
|
604
|
+
const style = doc.createElement('style');
|
|
605
|
+
style.dataset.orbitKit = id;
|
|
606
|
+
style.textContent = entry.css;
|
|
607
|
+
root.prepend(style);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
569
611
|
export const KIT_TAGS = 'o-gauge,o-donut,o-rings,o-meter,o-knob,o-menu,o-compass,o-radar,o-spinner,o-radar-chart,o-clock,o-instrument,o-timer,o-status,o-range,o-time-picker,o-sunburst,o-wheel,o-color-wheel';
|
|
570
612
|
|
|
571
613
|
|