@skillpet/circuit 0.5.2 → 0.6.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/dist/circuit.bundle.js +66 -1
- package/dist/circuit.bundle.min.js +21 -21
- package/dist/circuit.esm.js +66 -1
- package/dist/index.cjs +67 -1
- package/dist/index.d.ts +1 -1
- package/dist/json/mount.d.ts +6 -0
- package/dist/json/theme.d.ts +9 -0
- package/package.json +1 -1
package/dist/circuit.bundle.js
CHANGED
|
@@ -14387,6 +14387,7 @@ var Circuit = (() => {
|
|
|
14387
14387
|
BusLine: () => BusLine,
|
|
14388
14388
|
Button: () => Button,
|
|
14389
14389
|
CPE: () => CPE,
|
|
14390
|
+
CSS_VARS: () => CSS_VARS,
|
|
14390
14391
|
Capacitor: () => Capacitor,
|
|
14391
14392
|
Capacitor2: () => Capacitor2,
|
|
14392
14393
|
CapacitorTrim: () => CapacitorTrim,
|
|
@@ -30565,15 +30566,37 @@ var Circuit = (() => {
|
|
|
30565
30566
|
lw: 1.5
|
|
30566
30567
|
}
|
|
30567
30568
|
};
|
|
30569
|
+
var CSS_VARS = {
|
|
30570
|
+
bg: "--circuit-bg",
|
|
30571
|
+
stroke: "--circuit-stroke",
|
|
30572
|
+
fill: "--circuit-fill",
|
|
30573
|
+
text: "--circuit-text",
|
|
30574
|
+
font: "--circuit-font",
|
|
30575
|
+
lw: "--circuit-lw"
|
|
30576
|
+
};
|
|
30577
|
+
function readCssTheme() {
|
|
30578
|
+
if (typeof getComputedStyle === "undefined") return { ...BUILTIN_THEMES.light };
|
|
30579
|
+
const s = getComputedStyle(document.documentElement);
|
|
30580
|
+
const v = (name) => s.getPropertyValue(name).trim();
|
|
30581
|
+
return {
|
|
30582
|
+
bg: v(CSS_VARS.bg) || "transparent",
|
|
30583
|
+
stroke: v(CSS_VARS.stroke) || BUILTIN_THEMES.light.stroke,
|
|
30584
|
+
fill: v(CSS_VARS.fill) || "none",
|
|
30585
|
+
text: v(CSS_VARS.text) || BUILTIN_THEMES.light.text,
|
|
30586
|
+
font: v(CSS_VARS.font) || BUILTIN_THEMES.light.font,
|
|
30587
|
+
lw: parseFloat(v(CSS_VARS.lw)) || BUILTIN_THEMES.light.lw
|
|
30588
|
+
};
|
|
30589
|
+
}
|
|
30568
30590
|
function resolveTheme(theme2) {
|
|
30569
30591
|
if (theme2 === void 0) {
|
|
30570
30592
|
return { ...BUILTIN_THEMES.light };
|
|
30571
30593
|
}
|
|
30572
30594
|
if (typeof theme2 === "string") {
|
|
30595
|
+
if (theme2 === "auto") return readCssTheme();
|
|
30573
30596
|
const found = BUILTIN_THEMES[theme2];
|
|
30574
30597
|
if (!found) {
|
|
30575
30598
|
throw new Error(
|
|
30576
|
-
`Unknown theme "${theme2}". Available: ${Object.keys(BUILTIN_THEMES).join(", ")}`
|
|
30599
|
+
`Unknown theme "${theme2}". Available: ${Object.keys(BUILTIN_THEMES).join(", ")}, auto`
|
|
30577
30600
|
);
|
|
30578
30601
|
}
|
|
30579
30602
|
return { ...found };
|
|
@@ -30794,6 +30817,9 @@ var Circuit = (() => {
|
|
|
30794
30817
|
__publicField(this, "_theme");
|
|
30795
30818
|
__publicField(this, "_destroyed", false);
|
|
30796
30819
|
__publicField(this, "_tooltipEl", null);
|
|
30820
|
+
__publicField(this, "_autoObserver", null);
|
|
30821
|
+
__publicField(this, "_mediaQuery", null);
|
|
30822
|
+
__publicField(this, "_mediaHandler", null);
|
|
30797
30823
|
__publicField(this, "_boundClick");
|
|
30798
30824
|
__publicField(this, "_boundMouseover");
|
|
30799
30825
|
__publicField(this, "_boundMouseout");
|
|
@@ -30811,6 +30837,42 @@ var Circuit = (() => {
|
|
|
30811
30837
|
this._render();
|
|
30812
30838
|
this._bindEvents();
|
|
30813
30839
|
this._initTooltip();
|
|
30840
|
+
this._initAutoTheme();
|
|
30841
|
+
}
|
|
30842
|
+
_isAutoTheme() {
|
|
30843
|
+
return (this._opts.theme ?? this._json.theme) === "auto";
|
|
30844
|
+
}
|
|
30845
|
+
_initAutoTheme() {
|
|
30846
|
+
if (!this._isAutoTheme()) return;
|
|
30847
|
+
const rerender = () => {
|
|
30848
|
+
if (this._destroyed) return;
|
|
30849
|
+
this._theme = resolveTheme("auto");
|
|
30850
|
+
this._unbindEvents();
|
|
30851
|
+
this._render();
|
|
30852
|
+
this._bindEvents();
|
|
30853
|
+
this._selectedId = null;
|
|
30854
|
+
};
|
|
30855
|
+
this._autoObserver = new MutationObserver(rerender);
|
|
30856
|
+
this._autoObserver.observe(document.documentElement, {
|
|
30857
|
+
attributes: true,
|
|
30858
|
+
attributeFilter: ["class", "data-theme", "data-color-mode", "style"]
|
|
30859
|
+
});
|
|
30860
|
+
if (typeof matchMedia !== "undefined") {
|
|
30861
|
+
this._mediaQuery = matchMedia("(prefers-color-scheme: dark)");
|
|
30862
|
+
this._mediaHandler = rerender;
|
|
30863
|
+
this._mediaQuery.addEventListener("change", this._mediaHandler);
|
|
30864
|
+
}
|
|
30865
|
+
}
|
|
30866
|
+
_teardownAutoTheme() {
|
|
30867
|
+
if (this._autoObserver) {
|
|
30868
|
+
this._autoObserver.disconnect();
|
|
30869
|
+
this._autoObserver = null;
|
|
30870
|
+
}
|
|
30871
|
+
if (this._mediaQuery && this._mediaHandler) {
|
|
30872
|
+
this._mediaQuery.removeEventListener("change", this._mediaHandler);
|
|
30873
|
+
this._mediaQuery = null;
|
|
30874
|
+
this._mediaHandler = null;
|
|
30875
|
+
}
|
|
30814
30876
|
}
|
|
30815
30877
|
_render() {
|
|
30816
30878
|
const svgString = renderFromJson(this._json, this._opts);
|
|
@@ -31044,9 +31106,11 @@ var Circuit = (() => {
|
|
|
31044
31106
|
this._selectedId = null;
|
|
31045
31107
|
}
|
|
31046
31108
|
setTheme(theme2) {
|
|
31109
|
+
this._teardownAutoTheme();
|
|
31047
31110
|
this._opts = { ...this._opts, theme: theme2 };
|
|
31048
31111
|
this._theme = resolveTheme(theme2);
|
|
31049
31112
|
this.update(this._json);
|
|
31113
|
+
this._initAutoTheme();
|
|
31050
31114
|
}
|
|
31051
31115
|
update(json) {
|
|
31052
31116
|
const circuit = typeof json === "string" ? JSON.parse(json) : json;
|
|
@@ -31060,6 +31124,7 @@ var Circuit = (() => {
|
|
|
31060
31124
|
if (this._destroyed) return;
|
|
31061
31125
|
this._destroyed = true;
|
|
31062
31126
|
this._unbindEvents();
|
|
31127
|
+
this._teardownAutoTheme();
|
|
31063
31128
|
if (this._tooltipEl) {
|
|
31064
31129
|
this._tooltipEl.remove();
|
|
31065
31130
|
this._tooltipEl = null;
|