@geophrase/core 1.3.9 → 1.3.11
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 +1 -1
- package/src/index.js +28 -27
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -50,6 +50,9 @@ class Geophrase {
|
|
|
50
50
|
|
|
51
51
|
this._boundHandleMessage = this._handleMessage.bind(this);
|
|
52
52
|
this._prevBodyOverflow = null;
|
|
53
|
+
this._prevHtmlBg = null;
|
|
54
|
+
this._prevBodyBg = null;
|
|
55
|
+
this._hostBgApplied = false;
|
|
53
56
|
|
|
54
57
|
// 6. Pre-compute the secure widget URL
|
|
55
58
|
const url = new URL(this.widgetOrigin);
|
|
@@ -78,35 +81,32 @@ class Geophrase {
|
|
|
78
81
|
`;
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
_getWidgetBg() {
|
|
82
85
|
const light = '#ffffff';
|
|
83
86
|
const dark = '#121212';
|
|
87
|
+
if (this.theme === 'light') return light;
|
|
88
|
+
if (this.theme === 'dark') return dark;
|
|
89
|
+
// 'system' or unspecified → resolve at open time
|
|
90
|
+
return window.matchMedia?.('(prefers-color-scheme: dark)').matches ? dark : light;
|
|
91
|
+
}
|
|
84
92
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
el.content = color;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
if (this.theme === 'light') {
|
|
98
|
-
ensure(`${this.styleId}-tc`, '', light);
|
|
99
|
-
} else if (this.theme === 'dark') {
|
|
100
|
-
ensure(`${this.styleId}-tc`, '', dark);
|
|
101
|
-
} else {
|
|
102
|
-
ensure(`${this.styleId}-tc-light`, '(prefers-color-scheme: light)', light);
|
|
103
|
-
ensure(`${this.styleId}-tc-dark`, '(prefers-color-scheme: dark)', dark);
|
|
104
|
-
}
|
|
93
|
+
_applyHostBg() {
|
|
94
|
+
if (this._hostBgApplied) return;
|
|
95
|
+
this._prevHtmlBg = document.documentElement.style.backgroundColor;
|
|
96
|
+
this._prevBodyBg = document.body.style.backgroundColor;
|
|
97
|
+
const bg = this._getWidgetBg();
|
|
98
|
+
document.documentElement.style.backgroundColor = bg;
|
|
99
|
+
document.body.style.backgroundColor = bg;
|
|
100
|
+
this._hostBgApplied = true;
|
|
105
101
|
}
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
_restoreHostBg() {
|
|
104
|
+
if (!this._hostBgApplied) return;
|
|
105
|
+
document.documentElement.style.backgroundColor = this._prevHtmlBg ?? '';
|
|
106
|
+
document.body.style.backgroundColor = this._prevBodyBg ?? '';
|
|
107
|
+
this._prevHtmlBg = null;
|
|
108
|
+
this._prevBodyBg = null;
|
|
109
|
+
this._hostBgApplied = false;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
_safeCall(fn, payload) {
|
|
@@ -176,7 +176,7 @@ class Geophrase {
|
|
|
176
176
|
}
|
|
177
177
|
document.body.style.overflow = 'hidden';
|
|
178
178
|
|
|
179
|
-
this.
|
|
179
|
+
this._applyHostBg();
|
|
180
180
|
|
|
181
181
|
document.getElementById(this.overlayId)?.classList.add('geophrase-active');
|
|
182
182
|
}
|
|
@@ -187,7 +187,7 @@ class Geophrase {
|
|
|
187
187
|
document.body.style.overflow = this._prevBodyOverflow ?? '';
|
|
188
188
|
this._prevBodyOverflow = null;
|
|
189
189
|
|
|
190
|
-
this.
|
|
190
|
+
this._restoreHostBg();
|
|
191
191
|
|
|
192
192
|
document.getElementById(this.overlayId)?.classList.remove('geophrase-active');
|
|
193
193
|
|
|
@@ -200,11 +200,12 @@ class Geophrase {
|
|
|
200
200
|
|
|
201
201
|
document.getElementById(this.overlayId)?.remove();
|
|
202
202
|
document.getElementById(this.styleId)?.remove();
|
|
203
|
-
this._removeHostThemeColor();
|
|
204
203
|
|
|
205
204
|
document.body.style.overflow = this._prevBodyOverflow ?? '';
|
|
206
205
|
this._prevBodyOverflow = null;
|
|
207
206
|
|
|
207
|
+
this._restoreHostBg();
|
|
208
|
+
|
|
208
209
|
window.removeEventListener('message', this._boundHandleMessage);
|
|
209
210
|
|
|
210
211
|
this.onSuccess = null;
|