aumera-on-screen-widget 0.0.18 → 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.
- package/df-btn.js +27 -4
- 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",
|
|
@@ -139,6 +150,9 @@
|
|
|
139
150
|
showNotification: false,
|
|
140
151
|
};
|
|
141
152
|
|
|
153
|
+
// Track if dark mode was explicitly requested via HTML attribute
|
|
154
|
+
const hasExplicitDarkBackground = !!wrapper.getAttribute("backgroundDark");
|
|
155
|
+
|
|
142
156
|
// Initial config from HTML attributes with fallback to defaults
|
|
143
157
|
const config = {
|
|
144
158
|
src: wrapper.getAttribute("src"),
|
|
@@ -151,6 +165,7 @@
|
|
|
151
165
|
background: wrapper.getAttribute("background") || defaultConfig.background,
|
|
152
166
|
backgroundDark:
|
|
153
167
|
wrapper.getAttribute("backgroundDark") || defaultConfig.backgroundDark,
|
|
168
|
+
hasDarkMode: hasExplicitDarkBackground,
|
|
154
169
|
fontColor: wrapper.getAttribute("fontColor") || defaultConfig.fontColor,
|
|
155
170
|
fontColorDark:
|
|
156
171
|
wrapper.getAttribute("fontColorDark") || defaultConfig.fontColorDark,
|
|
@@ -219,6 +234,8 @@
|
|
|
219
234
|
config.background = settings.oswColourBackgroundLight || config.background;
|
|
220
235
|
config.backgroundDark =
|
|
221
236
|
settings.oswColourBackgroundDark || config.backgroundDark;
|
|
237
|
+
// Update hasDarkMode if GraphQL provides dark background
|
|
238
|
+
config.hasDarkMode = config.hasDarkMode || !!settings.oswColourBackgroundDark;
|
|
222
239
|
config.fontColor = settings.oswColourFontLight || config.fontColor;
|
|
223
240
|
config.fontColorDark = settings.oswColourFontDark || config.fontColorDark;
|
|
224
241
|
config.showNotification =
|
|
@@ -487,6 +504,7 @@
|
|
|
487
504
|
}
|
|
488
505
|
}
|
|
489
506
|
|
|
507
|
+
${config.hasDarkMode ? `
|
|
490
508
|
@media (prefers-color-scheme: dark){
|
|
491
509
|
.df-btn {
|
|
492
510
|
background-color: ${config.backgroundDark || "#171717"}
|
|
@@ -505,7 +523,7 @@
|
|
|
505
523
|
}
|
|
506
524
|
|
|
507
525
|
.df-btn:not(.df-closed) > .df-btn-text:before {
|
|
508
|
-
background-image: url('${origin}/assets/
|
|
526
|
+
background-image: url('${origin}/assets/close${isColorDark(config.backgroundDark) ? "_dark" : ""}.svg')
|
|
509
527
|
}
|
|
510
528
|
|
|
511
529
|
.df-notification {
|
|
@@ -517,6 +535,7 @@
|
|
|
517
535
|
border-top: 6px solid ${config.backgroundDark || "#171717"};
|
|
518
536
|
}
|
|
519
537
|
}
|
|
538
|
+
` : ''}
|
|
520
539
|
|
|
521
540
|
@keyframes shake {
|
|
522
541
|
0%, 100% { transform: translateX(0); }
|
|
@@ -757,12 +776,16 @@
|
|
|
757
776
|
const maxBtn = document.createElement("div");
|
|
758
777
|
maxBtn.className = "maximize-minimize-btn";
|
|
759
778
|
const maximized = btn.classList.contains("df-maximized");
|
|
760
|
-
const
|
|
779
|
+
const systemDarkMode =
|
|
780
|
+
config.hasDarkMode &&
|
|
761
781
|
window.matchMedia &&
|
|
762
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);
|
|
763
786
|
maxBtn.innerHTML = `<img class="maximize-minimize-icon" src="${origin}/assets/${
|
|
764
787
|
maximized ? "collapse" : "expand"
|
|
765
|
-
}${
|
|
788
|
+
}${useDarkIcons ? "_dark" : ""}.svg" alt="${
|
|
766
789
|
maximized ? "Minimize" : "Maximize"
|
|
767
790
|
}" style="width:24px;height:24px;cursor:pointer;" />`;
|
|
768
791
|
header.appendChild(maxBtn);
|
|
@@ -775,7 +798,7 @@
|
|
|
775
798
|
const closeBtn = document.createElement("div");
|
|
776
799
|
closeBtn.className = "close-btn";
|
|
777
800
|
closeBtn.innerHTML = `<img src="${origin}/assets/close${
|
|
778
|
-
|
|
801
|
+
useDarkIcons ? "_dark" : ""
|
|
779
802
|
}.svg" alt="Close" style="width:20px;height:20px;cursor:pointer;" />`;
|
|
780
803
|
header.insertBefore(closeBtn, btnText);
|
|
781
804
|
closeBtn.addEventListener("click", (e) => {
|