@geophrase/core 1.3.10 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +37 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geophrase/core",
3
- "version": "1.3.10",
3
+ "version": "1.3.11",
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
@@ -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,6 +81,34 @@ class Geophrase {
78
81
  `;
79
82
  }
80
83
 
84
+ _getWidgetBg() {
85
+ const light = '#ffffff';
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
+ }
92
+
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;
101
+ }
102
+
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
+ }
111
+
81
112
  _safeCall(fn, payload) {
82
113
  if (typeof fn !== 'function') return;
83
114
  try {
@@ -145,6 +176,8 @@ class Geophrase {
145
176
  }
146
177
  document.body.style.overflow = 'hidden';
147
178
 
179
+ this._applyHostBg();
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._restoreHostBg();
191
+
157
192
  document.getElementById(this.overlayId)?.classList.remove('geophrase-active');
158
193
 
159
194
  const iframe = document.getElementById(this.iframeId);
@@ -169,6 +204,8 @@ class Geophrase {
169
204
  document.body.style.overflow = this._prevBodyOverflow ?? '';
170
205
  this._prevBodyOverflow = null;
171
206
 
207
+ this._restoreHostBg();
208
+
172
209
  window.removeEventListener('message', this._boundHandleMessage);
173
210
 
174
211
  this.onSuccess = null;