@radioactive-labs/plutonium 0.47.0 → 0.49.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/package.json
CHANGED
package/src/dist/js/plutonium.js
CHANGED
|
@@ -13383,49 +13383,62 @@
|
|
|
13383
13383
|
};
|
|
13384
13384
|
|
|
13385
13385
|
// src/js/controllers/color_mode_controller.js
|
|
13386
|
+
var ORDER = ["auto", "light", "dark"];
|
|
13386
13387
|
var color_mode_controller_default = class extends Controller {
|
|
13387
13388
|
static values = { current: String };
|
|
13388
13389
|
connect() {
|
|
13389
|
-
|
|
13390
|
-
this.setMode(mode);
|
|
13390
|
+
this.applyMode(this.readMode());
|
|
13391
13391
|
this.handleStorageChange = (e4) => {
|
|
13392
|
-
|
|
13393
|
-
|
|
13394
|
-
console.log("Updating color-mode theme to:", e4.newValue);
|
|
13395
|
-
this.setMode(e4.newValue);
|
|
13396
|
-
}
|
|
13392
|
+
if (e4.key === "theme")
|
|
13393
|
+
this.applyMode(this.readMode());
|
|
13397
13394
|
};
|
|
13398
13395
|
window.addEventListener("storage", this.handleStorageChange);
|
|
13396
|
+
this.mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
13397
|
+
this.handleMqChange = () => {
|
|
13398
|
+
if (this.readMode() === "auto")
|
|
13399
|
+
this.applyMode("auto");
|
|
13400
|
+
};
|
|
13401
|
+
this.mq.addEventListener("change", this.handleMqChange);
|
|
13399
13402
|
}
|
|
13400
13403
|
disconnect() {
|
|
13401
13404
|
window.removeEventListener("storage", this.handleStorageChange);
|
|
13405
|
+
if (this.mq)
|
|
13406
|
+
this.mq.removeEventListener("change", this.handleMqChange);
|
|
13402
13407
|
}
|
|
13403
13408
|
toggleMode() {
|
|
13404
|
-
const current = this.
|
|
13405
|
-
const next = current
|
|
13409
|
+
const current = this.readMode();
|
|
13410
|
+
const next = ORDER[(ORDER.indexOf(current) + 1) % ORDER.length];
|
|
13406
13411
|
this.setMode(next);
|
|
13407
13412
|
}
|
|
13408
13413
|
setMode(mode) {
|
|
13409
|
-
|
|
13410
|
-
|
|
13411
|
-
|
|
13412
|
-
|
|
13413
|
-
|
|
13414
|
+
localStorage.setItem("theme", mode);
|
|
13415
|
+
this.applyMode(mode);
|
|
13416
|
+
}
|
|
13417
|
+
applyMode(mode) {
|
|
13418
|
+
const effective = this.effectiveMode(mode);
|
|
13419
|
+
document.documentElement.classList.toggle("dark", effective === "dark");
|
|
13414
13420
|
this.currentValue = mode;
|
|
13415
13421
|
this.toggleIcons(mode);
|
|
13416
|
-
|
|
13422
|
+
}
|
|
13423
|
+
readMode() {
|
|
13424
|
+
const saved = localStorage.getItem("theme");
|
|
13425
|
+
return ORDER.includes(saved) ? saved : "auto";
|
|
13426
|
+
}
|
|
13427
|
+
effectiveMode(mode) {
|
|
13428
|
+
if (mode === "light" || mode === "dark")
|
|
13429
|
+
return mode;
|
|
13430
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
13417
13431
|
}
|
|
13418
13432
|
toggleIcons(mode) {
|
|
13419
|
-
const
|
|
13420
|
-
|
|
13421
|
-
|
|
13422
|
-
|
|
13423
|
-
|
|
13424
|
-
|
|
13425
|
-
|
|
13426
|
-
|
|
13427
|
-
|
|
13428
|
-
}
|
|
13433
|
+
const icons = {
|
|
13434
|
+
auto: this.element.querySelector(".color-mode-icon-auto"),
|
|
13435
|
+
light: this.element.querySelector(".color-mode-icon-light"),
|
|
13436
|
+
dark: this.element.querySelector(".color-mode-icon-dark")
|
|
13437
|
+
};
|
|
13438
|
+
for (const [key, el] of Object.entries(icons)) {
|
|
13439
|
+
if (!el)
|
|
13440
|
+
continue;
|
|
13441
|
+
el.classList.toggle("hidden", key !== mode);
|
|
13429
13442
|
}
|
|
13430
13443
|
}
|
|
13431
13444
|
};
|