@geophrase/core 1.3.11 → 1.3.12
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 +32 -3
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -92,20 +92,40 @@ class Geophrase {
|
|
|
92
92
|
|
|
93
93
|
_applyHostBg() {
|
|
94
94
|
if (this._hostBgApplied) return;
|
|
95
|
-
|
|
95
|
+
const html = document.documentElement;
|
|
96
|
+
this._prevHtmlBg = html.style.backgroundColor;
|
|
96
97
|
this._prevBodyBg = document.body.style.backgroundColor;
|
|
98
|
+
this._prevHtmlColorScheme = html.style.colorScheme;
|
|
97
99
|
const bg = this._getWidgetBg();
|
|
98
|
-
|
|
100
|
+
const scheme = bg === '#121212' ? 'dark' : 'light';
|
|
101
|
+
html.style.backgroundColor = bg;
|
|
99
102
|
document.body.style.backgroundColor = bg;
|
|
103
|
+
html.style.colorScheme = scheme;
|
|
104
|
+
|
|
105
|
+
// Add a theme-color meta as a final lever for iOS Safari chrome.
|
|
106
|
+
const tcId = `${this.styleId}-tc`;
|
|
107
|
+
let tc = document.getElementById(tcId);
|
|
108
|
+
if (!tc) {
|
|
109
|
+
tc = document.createElement('meta');
|
|
110
|
+
tc.id = tcId;
|
|
111
|
+
tc.name = 'theme-color';
|
|
112
|
+
document.head.appendChild(tc);
|
|
113
|
+
}
|
|
114
|
+
tc.content = bg;
|
|
115
|
+
|
|
100
116
|
this._hostBgApplied = true;
|
|
101
117
|
}
|
|
102
118
|
|
|
103
119
|
_restoreHostBg() {
|
|
104
120
|
if (!this._hostBgApplied) return;
|
|
105
|
-
|
|
121
|
+
const html = document.documentElement;
|
|
122
|
+
html.style.backgroundColor = this._prevHtmlBg ?? '';
|
|
106
123
|
document.body.style.backgroundColor = this._prevBodyBg ?? '';
|
|
124
|
+
html.style.colorScheme = this._prevHtmlColorScheme ?? '';
|
|
125
|
+
document.getElementById(`${this.styleId}-tc`)?.remove();
|
|
107
126
|
this._prevHtmlBg = null;
|
|
108
127
|
this._prevBodyBg = null;
|
|
128
|
+
this._prevHtmlColorScheme = null;
|
|
109
129
|
this._hostBgApplied = false;
|
|
110
130
|
}
|
|
111
131
|
|
|
@@ -167,6 +187,15 @@ class Geophrase {
|
|
|
167
187
|
|
|
168
188
|
const iframe = document.getElementById(this.iframeId);
|
|
169
189
|
if (iframe && !iframe.hasAttribute('src')) {
|
|
190
|
+
// Hide the iframe until its document has actually painted.
|
|
191
|
+
// Browsers render an unloaded iframe as a white rectangle, which
|
|
192
|
+
// (a) causes a visible white flash and (b) on iOS Safari can lock
|
|
193
|
+
// the chrome appearance to light because Safari samples the page
|
|
194
|
+
// at the moment the modal appears.
|
|
195
|
+
iframe.style.opacity = '0';
|
|
196
|
+
iframe.addEventListener('load', () => {
|
|
197
|
+
iframe.style.opacity = '';
|
|
198
|
+
}, { once: true });
|
|
170
199
|
iframe.src = this.widgetUrl;
|
|
171
200
|
}
|
|
172
201
|
|