@quantaroute/checkout 1.7.2 → 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.
@@ -8,7 +8,8 @@ import type { AutocompleteSuggestion } from '../core/api';
8
8
  import { useGeolocation } from '../hooks/useGeolocation';
9
9
  import type { MapPinSelectorProps } from '../core/types';
10
10
  import {
11
- DEFAULT_MAP_STYLE_URL,
11
+ addQuantaRouteWatermark,
12
+ resolveQuantaRouteMapStyle,
12
13
  waitForExternalMapRuntime,
13
14
  type MapRuntime,
14
15
  } from '../core/map-runtime';
@@ -100,12 +101,11 @@ function createPinElement(brandColor: string = DEFAULT_BRAND): HTMLDivElement {
100
101
  }
101
102
 
102
103
  function collapseCompactAttribution(container: HTMLElement | null): void {
103
- const attribEl = container?.querySelector(
104
- '.maplibregl-ctrl-attrib.maplibregl-compact'
105
- );
104
+ const attribEl = container?.querySelector('.maplibregl-ctrl-attrib');
106
105
  if (attribEl instanceof HTMLElement) {
106
+ attribEl.classList.add('maplibregl-compact');
107
107
  attribEl.classList.remove('maplibregl-compact-show');
108
- attribEl.setAttribute('open', '');
108
+ attribEl.removeAttribute('open');
109
109
  }
110
110
  }
111
111
 
@@ -150,20 +150,19 @@ function initMapWithRuntime(
150
150
  zoom: initZoom,
151
151
  minZoom: MIN_ZOOM,
152
152
  attributionControl: false,
153
+ maplibreLogo: false,
153
154
  touchZoomRotate: true,
154
155
  });
155
156
 
156
157
  if (typeof runtime.AttributionControl === 'function') {
157
158
  map.addControl(
158
- new runtime.AttributionControl({
159
- compact: true,
160
- customAttribution:
161
- '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors &nbsp;© <a href="https://carto.com/attributions" target="_blank" rel="noopener">CARTO</a>',
162
- }),
159
+ new runtime.AttributionControl({ compact: true }),
163
160
  'bottom-right'
164
161
  );
165
162
  }
166
163
 
164
+ addQuantaRouteWatermark(map);
165
+
167
166
  if (typeof runtime.NavigationControl === 'function') {
168
167
  map.addControl(
169
168
  new runtime.NavigationControl({ showCompass: false }),
@@ -173,11 +172,17 @@ function initMapWithRuntime(
173
172
 
174
173
  let marker: MapLibreMarker | null = null;
175
174
 
175
+ map.on('style.load', () => {
176
+ collapseCompactAttribution(container);
177
+ });
178
+
176
179
  map.on('load', () => {
177
180
  collapseCompactAttribution(container);
178
181
  onReady();
179
182
 
180
183
  boundaryPromise.then((geoJson) => {
184
+ // Our hosted style already draws the official outline; skip a second line.
185
+ if (styleUrl.includes('maps.quantaroute.com')) return;
181
186
  if (!geoJson || !map.isStyleLoaded()) return;
182
187
  try {
183
188
  map.addSource('india-boundary', {
@@ -255,9 +260,11 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
255
260
  apiKey,
256
261
  apiBaseUrl,
257
262
  brandColor = DEFAULT_BRAND,
258
- mapStyle = DEFAULT_MAP_STYLE_URL,
263
+ mapStyle,
264
+ mapTheme,
259
265
  embedMode = 'bundled',
260
266
  }) => {
267
+ const resolvedMapStyle = resolveQuantaRouteMapStyle(mapStyle, mapTheme);
261
268
  const containerRef = useRef<HTMLDivElement>(null);
262
269
  const mapRef = useRef<MapLibreMap | null>(null);
263
270
  const markerRef = useRef<MapLibreMarker | null>(null);
@@ -394,7 +401,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
394
401
 
395
402
  try {
396
403
  const { map, cleanup } = initMapWithRuntime(runtime, container, markerRef, {
397
- styleUrl: mapStyle,
404
+ styleUrl: resolvedMapStyle,
398
405
  initLat,
399
406
  initLng,
400
407
  initZoom,
@@ -449,7 +456,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
449
456
  indiaBoundaryUrl,
450
457
  initLat,
451
458
  initLng,
452
- mapStyle,
459
+ resolvedMapStyle,
453
460
  refreshDigipin,
454
461
  ]);
455
462
 
@@ -33,11 +33,84 @@ export type { MapLibreMap, MapLibreMarker, MapMouseEvent };
33
33
  */
34
34
  export type MapEmbedMode = 'bundled' | 'external';
35
35
 
36
- /** Carto Positron — default basemap for standard web embeds. */
37
- export const DEFAULT_MAP_STYLE_URL =
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 =
38
111
  'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json';
39
112
 
40
- /** OpenFreeMap Positron — free, no API key (used when Carto credentials are unavailable). */
113
+ /** OpenFreeMap Positron — fallback used by some Shopify embeds historically. */
41
114
  export const OPENFREEMAP_POSITRON_STYLE_URL =
42
115
  'https://tiles.openfreemap.org/styles/positron';
43
116
 
package/src/core/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
- import type { MapEmbedMode } from './map-runtime';
2
+ import type { MapEmbedMode, QuantaRouteMapTheme } from './map-runtime';
3
3
  import type { UtmParams } from './utm';
4
4
  import type {
5
5
  AddressRiskScore,
@@ -198,7 +198,7 @@ export interface MapPinSelectorProps {
198
198
  * When provided, a thin grey outline of India's border is drawn on the map
199
199
  * to satisfy Indian government map policy requirements.
200
200
  * The file is fetched in parallel with map initialisation — no visible delay.
201
- * Example: indiaBoundaryUrl="/geojson/india.geojson"
201
+ * Example: indiaBoundaryUrl="https://maps.quantaroute.com/geojson/india.geojson"
202
202
  */
203
203
  indiaBoundaryUrl?: string;
204
204
  /**
@@ -218,10 +218,17 @@ export interface MapPinSelectorProps {
218
218
  */
219
219
  brandColor?: string;
220
220
  /**
221
- * MapLibre style URL for the basemap. Defaults to Carto Positron.
222
- * Use `OPENFREEMAP_POSITRON_STYLE_URL` when Carto credentials are unavailable.
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`.
223
225
  */
224
226
  mapStyle?: string;
227
+ /**
228
+ * Named QuantaRoute Atlas theme when `mapStyle` is omitted:
229
+ * `pro` (default), `light`, or `dark`.
230
+ */
231
+ mapTheme?: QuantaRouteMapTheme;
225
232
  /**
226
233
  * How MapLibre GL JS is loaded on web. `bundled` imports the peer dependency;
227
234
  * `external` waits for `window.maplibregl` (CDN script loaded by the host).
@@ -305,14 +312,20 @@ export interface CheckoutWidgetProps {
305
312
  * URL to an India boundary GeoJSON file (FeatureCollection).
306
313
  * When provided, a thin grey outline is drawn on the map for legal compliance.
307
314
  * Host the file in your app's public folder and pass its path here.
308
- * Example: indiaBoundaryUrl="/geojson/india.geojson"
315
+ * Example: indiaBoundaryUrl="https://maps.quantaroute.com/geojson/india.geojson"
309
316
  */
310
317
  indiaBoundaryUrl?: string;
311
318
  /**
312
- * MapLibre style URL for the map step. Defaults to Carto Positron.
313
- * Pass `OPENFREEMAP_POSITRON_STYLE_URL` when Carto basemaps require credentials.
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`.
314
322
  */
315
323
  mapStyle?: string;
324
+ /**
325
+ * Named QuantaRoute Atlas theme when `mapStyle` is omitted:
326
+ * `pro` (default), `light`, or `dark`.
327
+ */
328
+ mapTheme?: QuantaRouteMapTheme;
316
329
  /**
317
330
  * How MapLibre GL JS is loaded on web. `external` waits for `window.maplibregl`
318
331
  * when the host loads MapLibre from a CDN (e.g. Shopify theme extensions).
package/src/index.ts CHANGED
@@ -130,10 +130,19 @@ export type {
130
130
  MapLibreMap,
131
131
  MapLibreMarker,
132
132
  MapMouseEvent,
133
+ QuantaRouteMapTheme,
133
134
  } from './core/map-runtime';
134
135
  export {
135
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,
136
144
  OPENFREEMAP_POSITRON_STYLE_URL,
145
+ resolveQuantaRouteMapStyle,
137
146
  getExternalMapRuntime,
138
147
  waitForExternalMapRuntime,
139
148
  } from './core/map-runtime';
@@ -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 {