aumera-on-screen-widget 0.0.19 → 0.0.20

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.
Files changed (2) hide show
  1. package/df-btn.js +18 -4
  2. package/package.json +1 -1
package/df-btn.js CHANGED
@@ -119,6 +119,17 @@
119
119
  }
120
120
  }
121
121
 
122
+ // Helper function to determine if a color is dark based on luminance
123
+ function isColorDark(hexColor) {
124
+ if (!hexColor) return false;
125
+ const hex = hexColor.replace("#", "");
126
+ const r = parseInt(hex.substr(0, 2), 16) / 255;
127
+ const g = parseInt(hex.substr(2, 2), 16) / 255;
128
+ const b = parseInt(hex.substr(4, 2), 16) / 255;
129
+ const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
130
+ return luminance < 0.5;
131
+ }
132
+
122
133
  // Default configuration with fallback values
123
134
  const defaultConfig = {
124
135
  env: "prod",
@@ -512,7 +523,7 @@
512
523
  }
513
524
 
514
525
  .df-btn:not(.df-closed) > .df-btn-text:before {
515
- background-image: url('${origin}/assets/close_dark.svg')
526
+ background-image: url('${origin}/assets/close${isColorDark(config.backgroundDark) ? "_dark" : ""}.svg')
516
527
  }
517
528
 
518
529
  .df-notification {
@@ -765,13 +776,16 @@
765
776
  const maxBtn = document.createElement("div");
766
777
  maxBtn.className = "maximize-minimize-btn";
767
778
  const maximized = btn.classList.contains("df-maximized");
768
- const isDarkMode =
779
+ const systemDarkMode =
769
780
  config.hasDarkMode &&
770
781
  window.matchMedia &&
771
782
  window.matchMedia("(prefers-color-scheme: dark)").matches;
783
+ // Use white icons only if the actual background is dark
784
+ const currentBg = systemDarkMode ? config.backgroundDark : config.background;
785
+ const useDarkIcons = isColorDark(currentBg);
772
786
  maxBtn.innerHTML = `<img class="maximize-minimize-icon" src="${origin}/assets/${
773
787
  maximized ? "collapse" : "expand"
774
- }${isDarkMode ? "_dark" : ""}.svg" alt="${
788
+ }${useDarkIcons ? "_dark" : ""}.svg" alt="${
775
789
  maximized ? "Minimize" : "Maximize"
776
790
  }" style="width:24px;height:24px;cursor:pointer;" />`;
777
791
  header.appendChild(maxBtn);
@@ -784,7 +798,7 @@
784
798
  const closeBtn = document.createElement("div");
785
799
  closeBtn.className = "close-btn";
786
800
  closeBtn.innerHTML = `<img src="${origin}/assets/close${
787
- isDarkMode ? "_dark" : ""
801
+ useDarkIcons ? "_dark" : ""
788
802
  }.svg" alt="Close" style="width:20px;height:20px;cursor:pointer;" />`;
789
803
  header.insertBefore(closeBtn, btnText);
790
804
  closeBtn.addEventListener("click", (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aumera-on-screen-widget",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "A lightweight, customizable chat widget for websites",
5
5
  "main": "df-btn.js",
6
6
  "scripts": {