@geophrase/core 1.3.7 → 1.3.9

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/package.json +1 -1
  2. package/src/index.js +37 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geophrase/core",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "description": "Drop-in address picker widget for Indian e-commerce checkouts. Captures structured addresses with coordinates to reduce RTO.",
5
5
  "license": "MIT",
6
6
  "author": "Geophrase",
package/src/index.js CHANGED
@@ -78,6 +78,37 @@ class Geophrase {
78
78
  `;
79
79
  }
80
80
 
81
+ _applyHostThemeColor() {
82
+ const light = '#ffffff';
83
+ const dark = '#121212';
84
+
85
+ const ensure = (id, media, color) => {
86
+ let el = document.getElementById(id);
87
+ if (!el) {
88
+ el = document.createElement('meta');
89
+ el.id = id;
90
+ el.name = 'theme-color';
91
+ if (media) el.media = media;
92
+ document.head.appendChild(el);
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
+ }
105
+ }
106
+
107
+ _removeHostThemeColor() {
108
+ [`${this.styleId}-tc`, `${this.styleId}-tc-light`, `${this.styleId}-tc-dark`]
109
+ .forEach(id => document.getElementById(id)?.remove());
110
+ }
111
+
81
112
  _safeCall(fn, payload) {
82
113
  if (typeof fn !== 'function') return;
83
114
  try {
@@ -95,7 +126,7 @@ class Geophrase {
95
126
  style.id = this.styleId;
96
127
  style.innerHTML = `
97
128
  #${this.overlayId} {
98
- position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
129
+ position: fixed; inset: 0; width: 100dvw; height: 100dvh;
99
130
  background-color: rgba(0, 0, 0, 0.6); z-index: 999999;
100
131
  display: flex; justify-content: center; align-items: center;
101
132
  opacity: 0; visibility: hidden; transition: opacity 0.3s ease;
@@ -145,6 +176,8 @@ class Geophrase {
145
176
  }
146
177
  document.body.style.overflow = 'hidden';
147
178
 
179
+ this._applyHostThemeColor();
180
+
148
181
  document.getElementById(this.overlayId)?.classList.add('geophrase-active');
149
182
  }
150
183
 
@@ -154,6 +187,8 @@ class Geophrase {
154
187
  document.body.style.overflow = this._prevBodyOverflow ?? '';
155
188
  this._prevBodyOverflow = null;
156
189
 
190
+ this._removeHostThemeColor();
191
+
157
192
  document.getElementById(this.overlayId)?.classList.remove('geophrase-active');
158
193
 
159
194
  const iframe = document.getElementById(this.iframeId);
@@ -165,6 +200,7 @@ class Geophrase {
165
200
 
166
201
  document.getElementById(this.overlayId)?.remove();
167
202
  document.getElementById(this.styleId)?.remove();
203
+ this._removeHostThemeColor();
168
204
 
169
205
  document.body.style.overflow = this._prevBodyOverflow ?? '';
170
206
  this._prevBodyOverflow = null;