@radioactive-labs/plutonium 0.4.10 → 0.31.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.
@@ -13151,30 +13151,49 @@
13151
13151
 
13152
13152
  // src/js/controllers/color_mode_controller.js
13153
13153
  var color_mode_controller_default = class extends Controller {
13154
- // static targets = ["trigger", "menu"]
13154
+ static values = { current: String };
13155
13155
  connect() {
13156
- this.updateColorMode();
13156
+ const mode = localStorage.getItem("theme") || "light";
13157
+ this.setMode(mode);
13158
+ this.handleStorageChange = (e4) => {
13159
+ console.log("Storage event received in color-mode controller:", e4.key, e4.newValue, e4.oldValue);
13160
+ if (e4.key === "theme" && e4.newValue) {
13161
+ console.log("Updating color-mode theme to:", e4.newValue);
13162
+ this.setMode(e4.newValue);
13163
+ }
13164
+ };
13165
+ window.addEventListener("storage", this.handleStorageChange);
13157
13166
  }
13158
13167
  disconnect() {
13168
+ window.removeEventListener("storage", this.handleStorageChange);
13169
+ }
13170
+ toggleMode() {
13171
+ const current = this.currentValue || "light";
13172
+ const next = current === "light" ? "dark" : "light";
13173
+ this.setMode(next);
13159
13174
  }
13160
- updateColorMode() {
13161
- if (localStorage.theme === "dark" || !("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches) {
13175
+ setMode(mode) {
13176
+ if (mode === "dark") {
13162
13177
  document.documentElement.classList.add("dark");
13163
13178
  } else {
13164
13179
  document.documentElement.classList.remove("dark");
13165
13180
  }
13166
- }
13167
- setLightColorMode() {
13168
- localStorage.theme = "light";
13169
- this.updateColorMode();
13170
- }
13171
- setDarkColorMode() {
13172
- localStorage.theme = "dark";
13173
- this.updateColorMode();
13174
- }
13175
- setSystemColorMode() {
13176
- localStorage.removeItem("theme");
13177
- this.updateColorMode();
13181
+ this.currentValue = mode;
13182
+ this.toggleIcons(mode);
13183
+ localStorage.setItem("theme", mode);
13184
+ }
13185
+ toggleIcons(mode) {
13186
+ const sun = this.element.querySelector(".color-mode-icon-light");
13187
+ const moon = this.element.querySelector(".color-mode-icon-dark");
13188
+ if (sun && moon) {
13189
+ if (mode === "light") {
13190
+ sun.classList.remove("hidden");
13191
+ moon.classList.add("hidden");
13192
+ } else {
13193
+ sun.classList.add("hidden");
13194
+ moon.classList.remove("hidden");
13195
+ }
13196
+ }
13178
13197
  }
13179
13198
  };
13180
13199