@quantaroute/checkout 1.7.1 → 1.7.3
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/CHANGELOG.md +18 -0
- package/README.md +1 -1
- package/dist/lib/index.d.ts +100 -2
- package/dist/lib/quantaroute-checkout.es.js +207 -193
- package/dist/lib/quantaroute-checkout.umd.js +137 -123
- package/dist/style.css +1 -1
- package/package.json +7 -3
- package/src/components/CheckoutWidget.tsx +9 -0
- package/src/components/MapPinSelector.native.tsx +2 -8
- package/src/components/MapPinSelector.tsx +257 -175
- package/src/core/map-runtime.ts +173 -0
- package/src/core/types.ts +36 -2
- package/src/index.ts +22 -0
- package/src/styles/checkout.css +19 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Map as MapLibreMap,
|
|
3
|
+
MapMouseEvent,
|
|
4
|
+
Marker as MapLibreMarker,
|
|
5
|
+
} from 'maplibre-gl';
|
|
6
|
+
|
|
7
|
+
/** Subset of maplibre-gl used by the web MapPinSelector. */
|
|
8
|
+
export interface MapRuntime {
|
|
9
|
+
Map: new (
|
|
10
|
+
options: ConstructorParameters<typeof import('maplibre-gl').Map>[0]
|
|
11
|
+
) => MapLibreMap;
|
|
12
|
+
Marker: new (
|
|
13
|
+
options?: ConstructorParameters<typeof import('maplibre-gl').Marker>[0]
|
|
14
|
+
) => MapLibreMarker;
|
|
15
|
+
AttributionControl?: new (
|
|
16
|
+
options?: ConstructorParameters<
|
|
17
|
+
NonNullable<typeof import('maplibre-gl').AttributionControl>
|
|
18
|
+
>[0]
|
|
19
|
+
) => import('maplibre-gl').AttributionControl;
|
|
20
|
+
NavigationControl?: new (
|
|
21
|
+
options?: ConstructorParameters<
|
|
22
|
+
NonNullable<typeof import('maplibre-gl').NavigationControl>
|
|
23
|
+
>[0]
|
|
24
|
+
) => import('maplibre-gl').NavigationControl;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type { MapLibreMap, MapLibreMarker, MapMouseEvent };
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* How the host provides MapLibre GL JS.
|
|
31
|
+
* - `bundled`: import from `maplibre-gl` (default — Next.js, Vite apps with the peer installed)
|
|
32
|
+
* - `external`: read from `window.maplibregl` (CDN script loaded before the widget, e.g. Shopify)
|
|
33
|
+
*/
|
|
34
|
+
export type MapEmbedMode = 'bundled' | 'external';
|
|
35
|
+
|
|
36
|
+
/** QuantaRoute India basemap (Geofabrik PBF, Survey of India outline). */
|
|
37
|
+
export const QUANTAROUTE_MAP_STYLE_URL =
|
|
38
|
+
'https://maps.quantaroute.com/styles/quantaroute.json';
|
|
39
|
+
|
|
40
|
+
export const QUANTAROUTE_MAP_STYLE_LIGHT_URL =
|
|
41
|
+
'https://maps.quantaroute.com/styles/quantaroute-pro-light.json';
|
|
42
|
+
|
|
43
|
+
export const QUANTAROUTE_MAP_STYLE_DARK_URL =
|
|
44
|
+
'https://maps.quantaroute.com/styles/quantaroute-pro-dark.json';
|
|
45
|
+
|
|
46
|
+
export const QUANTAROUTE_MAP_STYLES = {
|
|
47
|
+
pro: QUANTAROUTE_MAP_STYLE_URL,
|
|
48
|
+
light: QUANTAROUTE_MAP_STYLE_LIGHT_URL,
|
|
49
|
+
dark: QUANTAROUTE_MAP_STYLE_DARK_URL,
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
export type QuantaRouteMapTheme = keyof typeof QUANTAROUTE_MAP_STYLES;
|
|
53
|
+
|
|
54
|
+
export const QUANTAROUTE_MAP_STYLES_CATALOG_URL =
|
|
55
|
+
'https://maps.quantaroute.com/styles.json';
|
|
56
|
+
|
|
57
|
+
export function resolveQuantaRouteMapStyle(
|
|
58
|
+
mapStyle?: string,
|
|
59
|
+
mapTheme?: QuantaRouteMapTheme
|
|
60
|
+
): string {
|
|
61
|
+
if (mapStyle) return mapStyle;
|
|
62
|
+
if (mapTheme) return QUANTAROUTE_MAP_STYLES[mapTheme];
|
|
63
|
+
return QUANTAROUTE_MAP_STYLE_URL;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Official India outline GeoJSON (Survey of India / Datameet). Same file as the style overlay. */
|
|
67
|
+
export const QUANTAROUTE_INDIA_BOUNDARY_URL =
|
|
68
|
+
'https://maps.quantaroute.com/geojson/india.geojson';
|
|
69
|
+
|
|
70
|
+
/** Bottom-left watermark; hide MapLibre’s logo so this owns that corner. */
|
|
71
|
+
export const QUANTAROUTE_WATERMARK_URL =
|
|
72
|
+
'https://maps.quantaroute.com/brand/quantaroute-mark.png';
|
|
73
|
+
|
|
74
|
+
export function addQuantaRouteWatermark(
|
|
75
|
+
map: MapLibreMap,
|
|
76
|
+
imageUrl: string = QUANTAROUTE_WATERMARK_URL
|
|
77
|
+
): void {
|
|
78
|
+
let container: HTMLElement | undefined;
|
|
79
|
+
map.addControl(
|
|
80
|
+
{
|
|
81
|
+
onAdd() {
|
|
82
|
+
const anchor = document.createElement('a');
|
|
83
|
+
anchor.className = 'maplibregl-ctrl qr-map-watermark';
|
|
84
|
+
anchor.href = 'https://quantaroute.com';
|
|
85
|
+
anchor.target = '_blank';
|
|
86
|
+
anchor.rel = 'noopener noreferrer';
|
|
87
|
+
anchor.title = 'QuantaRoute';
|
|
88
|
+
anchor.setAttribute('aria-label', 'QuantaRoute');
|
|
89
|
+
const img = document.createElement('img');
|
|
90
|
+
img.src = imageUrl;
|
|
91
|
+
img.alt = 'QuantaRoute';
|
|
92
|
+
img.width = 28;
|
|
93
|
+
img.height = 28;
|
|
94
|
+
anchor.appendChild(img);
|
|
95
|
+
container = anchor;
|
|
96
|
+
return anchor;
|
|
97
|
+
},
|
|
98
|
+
onRemove() {
|
|
99
|
+
container?.remove();
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
'bottom-left'
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Default basemap for web embeds (Atlas Pro). */
|
|
107
|
+
export const DEFAULT_MAP_STYLE_URL = QUANTAROUTE_MAP_STYLE_URL;
|
|
108
|
+
|
|
109
|
+
/** Carto Positron — fallback if maps.quantaroute.com is unavailable. */
|
|
110
|
+
export const CARTO_POSITRON_STYLE_URL =
|
|
111
|
+
'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json';
|
|
112
|
+
|
|
113
|
+
/** OpenFreeMap Positron — fallback used by some Shopify embeds historically. */
|
|
114
|
+
export const OPENFREEMAP_POSITRON_STYLE_URL =
|
|
115
|
+
'https://tiles.openfreemap.org/styles/positron';
|
|
116
|
+
|
|
117
|
+
const MAPLIBRE_WAIT_MS = 8_000;
|
|
118
|
+
const MAPLIBRE_RETRY_MS = 100;
|
|
119
|
+
|
|
120
|
+
declare global {
|
|
121
|
+
interface Window {
|
|
122
|
+
maplibregl?: MapRuntime;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function getExternalMapRuntime(): MapRuntime | null {
|
|
127
|
+
if (typeof window === 'undefined') return null;
|
|
128
|
+
const maplibre = window.maplibregl;
|
|
129
|
+
if (
|
|
130
|
+
!maplibre ||
|
|
131
|
+
typeof maplibre.Map !== 'function' ||
|
|
132
|
+
typeof maplibre.Marker !== 'function'
|
|
133
|
+
) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return maplibre;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Poll `window.maplibregl` until available or timeout (for async CDN loads).
|
|
141
|
+
* Returns a cancel function for useEffect cleanup.
|
|
142
|
+
*/
|
|
143
|
+
export function waitForExternalMapRuntime(
|
|
144
|
+
onReady: (runtime: MapRuntime) => void,
|
|
145
|
+
onUnavailable: () => void,
|
|
146
|
+
waitMs: number = MAPLIBRE_WAIT_MS,
|
|
147
|
+
retryMs: number = MAPLIBRE_RETRY_MS
|
|
148
|
+
): () => void {
|
|
149
|
+
const startedAt = Date.now();
|
|
150
|
+
let retryTimer: number | null = null;
|
|
151
|
+
let cancelled = false;
|
|
152
|
+
|
|
153
|
+
const tryGet = () => {
|
|
154
|
+
if (cancelled) return;
|
|
155
|
+
const runtime = getExternalMapRuntime();
|
|
156
|
+
if (runtime) {
|
|
157
|
+
onReady(runtime);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (Date.now() - startedAt >= waitMs) {
|
|
161
|
+
onUnavailable();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
retryTimer = window.setTimeout(tryGet, retryMs);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
tryGet();
|
|
168
|
+
|
|
169
|
+
return () => {
|
|
170
|
+
cancelled = true;
|
|
171
|
+
if (retryTimer !== null) window.clearTimeout(retryTimer);
|
|
172
|
+
};
|
|
173
|
+
}
|
package/src/core/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
+
import type { MapEmbedMode, QuantaRouteMapTheme } from './map-runtime';
|
|
2
3
|
import type { UtmParams } from './utm';
|
|
3
4
|
import type {
|
|
4
5
|
AddressRiskScore,
|
|
@@ -197,7 +198,7 @@ export interface MapPinSelectorProps {
|
|
|
197
198
|
* When provided, a thin grey outline of India's border is drawn on the map
|
|
198
199
|
* to satisfy Indian government map policy requirements.
|
|
199
200
|
* The file is fetched in parallel with map initialisation — no visible delay.
|
|
200
|
-
* Example: indiaBoundaryUrl="/geojson/india.geojson"
|
|
201
|
+
* Example: indiaBoundaryUrl="https://maps.quantaroute.com/geojson/india.geojson"
|
|
201
202
|
*/
|
|
202
203
|
indiaBoundaryUrl?: string;
|
|
203
204
|
/**
|
|
@@ -216,6 +217,23 @@ export interface MapPinSelectorProps {
|
|
|
216
217
|
* Brand accent colour (hex, e.g. `#7c3aed`). Sets map pin, buttons, focus rings via `--qr-primary` on web.
|
|
217
218
|
*/
|
|
218
219
|
brandColor?: string;
|
|
220
|
+
/**
|
|
221
|
+
* MapLibre style URL for the basemap. Defaults to QuantaRoute India
|
|
222
|
+
* (`QUANTAROUTE_MAP_STYLE_URL`). `CARTO_POSITRON_STYLE_URL` and
|
|
223
|
+
* `OPENFREEMAP_POSITRON_STYLE_URL` remain available as fallbacks.
|
|
224
|
+
* Wins over `mapTheme`.
|
|
225
|
+
*/
|
|
226
|
+
mapStyle?: string;
|
|
227
|
+
/**
|
|
228
|
+
* Named QuantaRoute Atlas theme when `mapStyle` is omitted:
|
|
229
|
+
* `pro` (default), `light`, or `dark`.
|
|
230
|
+
*/
|
|
231
|
+
mapTheme?: QuantaRouteMapTheme;
|
|
232
|
+
/**
|
|
233
|
+
* How MapLibre GL JS is loaded on web. `bundled` imports the peer dependency;
|
|
234
|
+
* `external` waits for `window.maplibregl` (CDN script loaded by the host).
|
|
235
|
+
*/
|
|
236
|
+
embedMode?: MapEmbedMode;
|
|
219
237
|
}
|
|
220
238
|
|
|
221
239
|
/** Pre-fill manual fields when verifying an imported saved address. */
|
|
@@ -294,9 +312,25 @@ export interface CheckoutWidgetProps {
|
|
|
294
312
|
* URL to an India boundary GeoJSON file (FeatureCollection).
|
|
295
313
|
* When provided, a thin grey outline is drawn on the map for legal compliance.
|
|
296
314
|
* Host the file in your app's public folder and pass its path here.
|
|
297
|
-
* Example: indiaBoundaryUrl="/geojson/india.geojson"
|
|
315
|
+
* Example: indiaBoundaryUrl="https://maps.quantaroute.com/geojson/india.geojson"
|
|
298
316
|
*/
|
|
299
317
|
indiaBoundaryUrl?: string;
|
|
318
|
+
/**
|
|
319
|
+
* MapLibre style URL for the map step. Defaults to QuantaRoute India.
|
|
320
|
+
* `CARTO_POSITRON_STYLE_URL` / `OPENFREEMAP_POSITRON_STYLE_URL` remain fallbacks.
|
|
321
|
+
* Wins over `mapTheme`.
|
|
322
|
+
*/
|
|
323
|
+
mapStyle?: string;
|
|
324
|
+
/**
|
|
325
|
+
* Named QuantaRoute Atlas theme when `mapStyle` is omitted:
|
|
326
|
+
* `pro` (default), `light`, or `dark`.
|
|
327
|
+
*/
|
|
328
|
+
mapTheme?: QuantaRouteMapTheme;
|
|
329
|
+
/**
|
|
330
|
+
* How MapLibre GL JS is loaded on web. `external` waits for `window.maplibregl`
|
|
331
|
+
* when the host loads MapLibre from a CDN (e.g. Shopify theme extensions).
|
|
332
|
+
*/
|
|
333
|
+
embedMode?: MapEmbedMode;
|
|
300
334
|
/**
|
|
301
335
|
* Show the smart search bar on the map step (default: true).
|
|
302
336
|
* Supports address search (API) and DigiPin lookup (100% offline).
|
package/src/index.ts
CHANGED
|
@@ -124,6 +124,28 @@ export { useDigiPin } from './hooks/useDigiPin';
|
|
|
124
124
|
export { captureUtmFromUrl, hasUtmParams } from './core/utm';
|
|
125
125
|
export type { UtmParams } from './core/utm';
|
|
126
126
|
export { getWebDeviceContext, detectDeviceType, detectPlatform } from './core/device';
|
|
127
|
+
export type {
|
|
128
|
+
MapRuntime,
|
|
129
|
+
MapEmbedMode,
|
|
130
|
+
MapLibreMap,
|
|
131
|
+
MapLibreMarker,
|
|
132
|
+
MapMouseEvent,
|
|
133
|
+
QuantaRouteMapTheme,
|
|
134
|
+
} from './core/map-runtime';
|
|
135
|
+
export {
|
|
136
|
+
DEFAULT_MAP_STYLE_URL,
|
|
137
|
+
QUANTAROUTE_MAP_STYLE_URL,
|
|
138
|
+
QUANTAROUTE_MAP_STYLE_LIGHT_URL,
|
|
139
|
+
QUANTAROUTE_MAP_STYLE_DARK_URL,
|
|
140
|
+
QUANTAROUTE_MAP_STYLES,
|
|
141
|
+
QUANTAROUTE_MAP_STYLES_CATALOG_URL,
|
|
142
|
+
QUANTAROUTE_INDIA_BOUNDARY_URL,
|
|
143
|
+
CARTO_POSITRON_STYLE_URL,
|
|
144
|
+
OPENFREEMAP_POSITRON_STYLE_URL,
|
|
145
|
+
resolveQuantaRouteMapStyle,
|
|
146
|
+
getExternalMapRuntime,
|
|
147
|
+
waitForExternalMapRuntime,
|
|
148
|
+
} from './core/map-runtime';
|
|
127
149
|
export type {
|
|
128
150
|
CheckoutWidgetProps,
|
|
129
151
|
CheckoutMobilePresentation,
|
package/src/styles/checkout.css
CHANGED
|
@@ -427,6 +427,25 @@
|
|
|
427
427
|
height: 100%;
|
|
428
428
|
}
|
|
429
429
|
|
|
430
|
+
.qr-map-watermark.maplibregl-ctrl {
|
|
431
|
+
background: transparent;
|
|
432
|
+
box-shadow: none;
|
|
433
|
+
border: 0;
|
|
434
|
+
padding: 0 0 2px 2px;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.qr-map-watermark img {
|
|
438
|
+
display: block;
|
|
439
|
+
width: 28px;
|
|
440
|
+
height: 28px;
|
|
441
|
+
opacity: 0.4;
|
|
442
|
+
filter: none;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.qr-map-outer .maplibregl-ctrl-attrib.maplibregl-compact:not(.maplibregl-compact-show) .maplibregl-ctrl-attrib-inner {
|
|
446
|
+
display: none !important;
|
|
447
|
+
}
|
|
448
|
+
|
|
430
449
|
/* Hide MapLibre's default navigation on small screens */
|
|
431
450
|
@media (max-width: 380px) {
|
|
432
451
|
.maplibregl-ctrl-top-right {
|