@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radioactive-labs/plutonium",
3
- "version": "0.47.0",
3
+ "version": "0.49.0",
4
4
  "description": "Build production-ready Rails apps in minutes, not days. Convention-driven, fully customizable, AI-ready.",
5
5
  "type": "module",
6
6
  "main": "src/js/core.js",
@@ -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
- const mode = localStorage.getItem("theme") || "light";
13390
- this.setMode(mode);
13390
+ this.applyMode(this.readMode());
13391
13391
  this.handleStorageChange = (e4) => {
13392
- console.log("Storage event received in color-mode controller:", e4.key, e4.newValue, e4.oldValue);
13393
- if (e4.key === "theme" && e4.newValue) {
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.currentValue || "light";
13405
- const next = current === "light" ? "dark" : "light";
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
- if (mode === "dark") {
13410
- document.documentElement.classList.add("dark");
13411
- } else {
13412
- document.documentElement.classList.remove("dark");
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
- localStorage.setItem("theme", mode);
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 sun = this.element.querySelector(".color-mode-icon-light");
13420
- const moon = this.element.querySelector(".color-mode-icon-dark");
13421
- if (sun && moon) {
13422
- if (mode === "light") {
13423
- sun.classList.remove("hidden");
13424
- moon.classList.add("hidden");
13425
- } else {
13426
- sun.classList.add("hidden");
13427
- moon.classList.remove("hidden");
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
  };