@nuitee/booking-widget 1.0.10 → 1.0.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/README.md
CHANGED
|
@@ -94,15 +94,15 @@ widget.open();
|
|
|
94
94
|
No bundler: load the script and CSS from the CDN, then create the widget.
|
|
95
95
|
|
|
96
96
|
```html
|
|
97
|
-
<link rel="stylesheet" href="https://cdn.thehotelplanet.com/booking-widget/v1.0.
|
|
98
|
-
<script src="https://cdn.thehotelplanet.com/booking-widget/v1.0.
|
|
97
|
+
<link rel="stylesheet" href="https://cdn.thehotelplanet.com/booking-widget/v1.0.11/dist/booking-widget.css">
|
|
98
|
+
<script src="https://cdn.thehotelplanet.com/booking-widget/v1.0.11/dist/booking-widget-standalone.js"></script>
|
|
99
99
|
|
|
100
100
|
<div id="booking-widget-container"></div>
|
|
101
101
|
|
|
102
102
|
<script>
|
|
103
103
|
const widget = new BookingWidget({
|
|
104
104
|
containerId: 'booking-widget-container',
|
|
105
|
-
cssUrl: 'https://cdn.thehotelplanet.com/booking-widget/v1.0.
|
|
105
|
+
cssUrl: 'https://cdn.thehotelplanet.com/booking-widget/v1.0.11/dist/booking-widget.css',
|
|
106
106
|
propertyKey: 'your-property-key',
|
|
107
107
|
onOpen: () => console.log('Opened'),
|
|
108
108
|
onClose: () => console.log('Closed'),
|
|
@@ -910,7 +910,7 @@ if (typeof window !== 'undefined') {
|
|
|
910
910
|
}
|
|
911
911
|
return [Math.round(h * 360), Math.round(s * 100), Math.round(l * 100)];
|
|
912
912
|
}
|
|
913
|
-
var bg = c.background || '#
|
|
913
|
+
var bg = c.background || '#222222', fg = c.text || '#ffffff', primary = c.primary || '#AA8453', primaryFg = c.primaryText || '#ffffff';
|
|
914
914
|
var primaryRgb = hexToRgb(primary), bgHsl = hexToHsl(bg), fgHsl = hexToHsl(fg);
|
|
915
915
|
var styles = { '--primary': primary, '--primary-fg': primaryFg, '--bg': bg, '--fg': fg, '--card-fg': fg };
|
|
916
916
|
if (primaryRgb) styles['--primary-rgb'] = primaryRgb[0] + ', ' + primaryRgb[1] + ', ' + primaryRgb[2];
|
|
@@ -1432,6 +1432,10 @@ if (typeof window !== 'undefined') {
|
|
|
1432
1432
|
}
|
|
1433
1433
|
|
|
1434
1434
|
render() {
|
|
1435
|
+
if (!this.widget) return;
|
|
1436
|
+
var installerBg = this._rawInstallerColors && this._rawInstallerColors.background != null && String(this._rawInstallerColors.background).trim() !== '';
|
|
1437
|
+
if (this._configState !== 'loaded' && !installerBg) this.widget.style.setProperty('--bg', '#222222');
|
|
1438
|
+
else this.widget.style.removeProperty('--bg');
|
|
1435
1439
|
this.renderStepIndicator();
|
|
1436
1440
|
this.renderPropertyKeyMessage();
|
|
1437
1441
|
this.renderStepContent();
|
package/dist/booking-widget.js
CHANGED
|
@@ -79,7 +79,7 @@ function deriveWidgetStyles(c) {
|
|
|
79
79
|
}
|
|
80
80
|
return [Math.round(h * 360), Math.round(s * 100), Math.round(l * 100)];
|
|
81
81
|
};
|
|
82
|
-
|
|
82
|
+
var bg = c.background || '#222222', fg = c.text || '#ffffff', primary = c.primary || '#AA8453', primaryFg = c.primaryText || '#ffffff';
|
|
83
83
|
var primaryRgb = hexToRgb(primary), bgHsl = hexToHsl(bg), fgHsl = hexToHsl(fg);
|
|
84
84
|
var styles = { '--primary': primary, '--primary-fg': primaryFg, '--bg': bg, '--fg': fg, '--card-fg': fg };
|
|
85
85
|
if (primaryRgb) styles['--primary-rgb'] = primaryRgb[0] + ', ' + primaryRgb[1] + ', ' + primaryRgb[2];
|
|
@@ -647,6 +647,9 @@ class BookingWidget {
|
|
|
647
647
|
this._renderInProgress = true;
|
|
648
648
|
window.__bookingWidgetRendering = true;
|
|
649
649
|
try {
|
|
650
|
+
const installerBg = this._rawInstallerColors && this._rawInstallerColors.background != null && String(this._rawInstallerColors.background).trim() !== '';
|
|
651
|
+
if (this._configState !== 'loaded' && !installerBg) this.widget.style.setProperty('--bg', '#222222');
|
|
652
|
+
else this.widget.style.removeProperty('--bg');
|
|
650
653
|
this.renderStepIndicator();
|
|
651
654
|
this.renderPropertyKeyMessage();
|
|
652
655
|
this.renderStepContent();
|
package/dist/core/color-utils.js
CHANGED
|
@@ -48,13 +48,13 @@ function hexToHsl(hex) {
|
|
|
48
48
|
/**
|
|
49
49
|
* Derive full widget CSS variables from 4 base colors.
|
|
50
50
|
* @param {Object} c - { background, text, primary, primaryText, card? }
|
|
51
|
-
* @returns {Object} CSS variable names to values, e.g. { '--bg': '#
|
|
51
|
+
* @returns {Object} CSS variable names to values, e.g. { '--bg': '#222222', ... }
|
|
52
52
|
*/
|
|
53
53
|
export function deriveWidgetStyles(c) {
|
|
54
54
|
if (!c || (!c.background && !c.text && !c.primary && !c.primaryText)) return {};
|
|
55
|
-
const bg = c.background || '#
|
|
56
|
-
const fg = c.text || '#
|
|
57
|
-
const primary = c.primary || '#
|
|
55
|
+
const bg = c.background || '#222222';
|
|
56
|
+
const fg = c.text || '#ffffff';
|
|
57
|
+
const primary = c.primary || '#AA8453';
|
|
58
58
|
const primaryFg = c.primaryText || '#ffffff';
|
|
59
59
|
const cardExplicit = c.card;
|
|
60
60
|
|
|
@@ -3,6 +3,7 @@ import { loadStripe } from '@stripe/stripe-js';
|
|
|
3
3
|
import { Calendar, Users, User, Check, MapPin, Phone, Square, CreditCard, Lock, Star, X, ChevronLeft, ChevronRight } from 'lucide-react';
|
|
4
4
|
import '../core/styles.css';
|
|
5
5
|
import { createBookingApi, formatPrice, buildCheckoutPayload, buildPaymentIntentPayload } from '../core/booking-api.js';
|
|
6
|
+
import { deriveWidgetStyles } from '../core/color-utils.js';
|
|
6
7
|
import { STRIPE_PUBLISHABLE_KEY, API_BASE_URL } from '../core/stripe-config.js';
|
|
7
8
|
import { fetchRuntimeConfig } from '../utils/config-service.js';
|
|
8
9
|
import { init as initAnalytics, capture as captureEvent, identify as identifyAnalytics } from '../utils/analytics.js';
|
|
@@ -11,6 +12,13 @@ import { init as initAnalytics, capture as captureEvent, identify as identifyAna
|
|
|
11
12
|
// library) wraps window.fetch for session recording. The wrapped version drops
|
|
12
13
|
// non-standard request headers such as 'Source'.
|
|
13
14
|
const _nativeFetch = typeof fetch === 'function' ? fetch : /* istanbul ignore next */ undefined;
|
|
15
|
+
const PRELOAD_DEFAULT_COLORS = {
|
|
16
|
+
background: '#222222',
|
|
17
|
+
text: '#ffffff',
|
|
18
|
+
primary: '#AA8453',
|
|
19
|
+
primaryText: '#ffffff',
|
|
20
|
+
card: '#222222',
|
|
21
|
+
};
|
|
14
22
|
|
|
15
23
|
const BASE_STEPS = [
|
|
16
24
|
{ key: 'dates', label: 'Dates & Guests', num: '01' },
|
|
@@ -117,6 +125,17 @@ const BookingWidget = ({
|
|
|
117
125
|
const [runtimeWidgetStyles, setRuntimeWidgetStyles] = useState({});
|
|
118
126
|
const [runtimeS3BaseUrl, setRuntimeS3BaseUrl] = useState('');
|
|
119
127
|
const [configRetryCount, setConfigRetryCount] = useState(0);
|
|
128
|
+
const preloadWidgetStyles = useMemo(() => {
|
|
129
|
+
const installerColors = colors && typeof colors === 'object' ? colors : {};
|
|
130
|
+
const preloadColors = {
|
|
131
|
+
background: installerColors.background ?? PRELOAD_DEFAULT_COLORS.background,
|
|
132
|
+
text: installerColors.text ?? PRELOAD_DEFAULT_COLORS.text,
|
|
133
|
+
primary: installerColors.primary ?? PRELOAD_DEFAULT_COLORS.primary,
|
|
134
|
+
primaryText: installerColors.primaryText ?? PRELOAD_DEFAULT_COLORS.primaryText,
|
|
135
|
+
card: installerColors.card ?? installerColors.background ?? PRELOAD_DEFAULT_COLORS.card,
|
|
136
|
+
};
|
|
137
|
+
return deriveWidgetStyles(preloadColors);
|
|
138
|
+
}, [colors]);
|
|
120
139
|
const widgetRef = useRef(null);
|
|
121
140
|
const stripeRef = useRef(null);
|
|
122
141
|
const elementsRef = useRef(null);
|
|
@@ -315,10 +334,11 @@ const BookingWidget = ({
|
|
|
315
334
|
useEffect(() => {
|
|
316
335
|
if (!widgetRef.current) return;
|
|
317
336
|
const style = widgetRef.current.style;
|
|
318
|
-
|
|
337
|
+
const activeStyles = configLoaded ? runtimeWidgetStyles : preloadWidgetStyles;
|
|
338
|
+
Object.entries(activeStyles).forEach(([key, val]) => {
|
|
319
339
|
if (val != null && val !== '') style.setProperty(key, val);
|
|
320
340
|
});
|
|
321
|
-
}, [runtimeWidgetStyles, isOpen]);
|
|
341
|
+
}, [runtimeWidgetStyles, preloadWidgetStyles, configLoaded, isOpen]);
|
|
322
342
|
|
|
323
343
|
const getNights = () => {
|
|
324
344
|
if (!state.checkIn || !state.checkOut) return 0;
|
|
@@ -480,6 +480,7 @@
|
|
|
480
480
|
import { loadStripe } from '@stripe/stripe-js';
|
|
481
481
|
import '../core/styles.css';
|
|
482
482
|
import { createBookingApi, formatPrice, buildCheckoutPayload, buildPaymentIntentPayload } from '../core/booking-api.js';
|
|
483
|
+
import { deriveWidgetStyles } from '../core/color-utils.js';
|
|
483
484
|
import { STRIPE_PUBLISHABLE_KEY, API_BASE_URL } from '../core/stripe-config.js';
|
|
484
485
|
import { fetchRuntimeConfig } from '../utils/config-service.js';
|
|
485
486
|
import { init as initAnalytics, capture as captureEvent, identify as identifyAnalytics } from '../utils/analytics.js';
|
|
@@ -488,6 +489,13 @@ import { init as initAnalytics, capture as captureEvent, identify as identifyAna
|
|
|
488
489
|
// library) wraps window.fetch for session recording. The wrapped version drops
|
|
489
490
|
// non-standard request headers such as 'Source'.
|
|
490
491
|
const _nativeFetch = typeof fetch === 'function' ? fetch : /* istanbul ignore next */ undefined;
|
|
492
|
+
const PRELOAD_DEFAULT_COLORS = {
|
|
493
|
+
background: '#222222',
|
|
494
|
+
text: '#ffffff',
|
|
495
|
+
primary: '#AA8453',
|
|
496
|
+
primaryText: '#ffffff',
|
|
497
|
+
card: '#222222',
|
|
498
|
+
};
|
|
491
499
|
|
|
492
500
|
|
|
493
501
|
const BASE_STEPS = [
|
|
@@ -652,7 +660,16 @@ export default {
|
|
|
652
660
|
return null;
|
|
653
661
|
},
|
|
654
662
|
widgetStyles() {
|
|
655
|
-
return this.runtimeWidgetStyles;
|
|
663
|
+
if (this.configLoaded) return this.runtimeWidgetStyles;
|
|
664
|
+
const installerColors = this.colors && typeof this.colors === 'object' ? this.colors : {};
|
|
665
|
+
const preloadColors = {
|
|
666
|
+
background: installerColors.background ?? PRELOAD_DEFAULT_COLORS.background,
|
|
667
|
+
text: installerColors.text ?? PRELOAD_DEFAULT_COLORS.text,
|
|
668
|
+
primary: installerColors.primary ?? PRELOAD_DEFAULT_COLORS.primary,
|
|
669
|
+
primaryText: installerColors.primaryText ?? PRELOAD_DEFAULT_COLORS.primaryText,
|
|
670
|
+
card: installerColors.card ?? installerColors.background ?? PRELOAD_DEFAULT_COLORS.card,
|
|
671
|
+
};
|
|
672
|
+
return deriveWidgetStyles(preloadColors);
|
|
656
673
|
},
|
|
657
674
|
nights() {
|
|
658
675
|
if (!this.state.checkIn || !this.state.checkOut) return 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuitee/booking-widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "A beautiful, customizable booking widget modal that can be embedded in any website. Supports vanilla JavaScript, React, and Vue.js.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|