@wix/editor-react-components 1.2717.0 → 1.2719.0

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.
@@ -1,13 +1,12 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import React__default, { forwardRef, useState, useCallback, useMemo, useImperativeHandle, Children, useEffect, useContext, useRef, useLayoutEffect, useReducer, memo, Suspense } from "react";
3
+ import React__default, { forwardRef, useState, useCallback, useContext, useEffect, useRef, useMemo, useReducer, useImperativeHandle, createContext, useLayoutEffect, Children, memo, Suspense } from "react";
4
4
  import { c as clsx } from "../chunks/clsx.js";
5
5
  import { f as formatClassNames } from "../chunks/classNames.js";
6
6
  import { a as getDataAttributes } from "../chunks/dataUtils.js";
7
7
  import { e as getTabIndexAttribute, f as convertA11yKeysToHtmlFormat } from "../chunks/a11y.js";
8
8
  import { createPortal } from "react-dom";
9
- import { g as getDefaultExportFromCjs } from "../chunks/_commonjsHelpers.js";
10
- import { G as GOOGLE_MAPS_DIRECTIONS_BASE_URL, M as MIN_ZOOM, a as MAX_ZOOM, T as TestIds, D as DEFAULT_ZOOM, b as MAP_IDS, c as MAP_TYPES, d as MAP_MOBILE_CONTROL_SIZE, A as API_KEY, e as DEFAULT_LOCATION, f as DefaultTranslations, g as TranslationKeys, h as TRANSLATIONS_NAMESPACES, C as COMPANY_NAME_DEFAULT, i as COMPANY_NAME_KEY, j as COMPONENT_NAME_DEFAULT, k as COMPONENT_NAME_KEY } from "../chunks/consts.js";
9
+ import { G as GOOGLE_MAPS_DIRECTIONS_BASE_URL, M as MIN_ZOOM, a as MAX_ZOOM, T as TestIds, I as INFO_WINDOW_PIXEL_OFFSET, D as DEFAULT_ZOOM, b as MAP_IDS, c as MAP_TYPES, d as MAP_MOBILE_CONTROL_SIZE, A as API_KEY, e as DEFAULT_LOCATION, f as DefaultTranslations, g as TranslationKeys, h as TRANSLATIONS_NAMESPACES, C as COMPANY_NAME_DEFAULT, i as COMPANY_NAME_KEY, j as COMPONENT_NAME_DEFAULT, k as COMPONENT_NAME_KEY } from "../chunks/consts.js";
11
10
  import { p as parse } from "../chunks/index4.js";
12
11
  import { useService } from "@wix/services-manager-react";
13
12
  import { E as EnvironmentDefinition } from "../chunks/index2.js";
@@ -76,327 +75,1527 @@ const GoogleMapReact = forwardRef((props, forwardedRef) => {
76
75
  }
77
76
  );
78
77
  });
79
- var fastDeepEqual;
80
- var hasRequiredFastDeepEqual;
81
- function requireFastDeepEqual() {
82
- if (hasRequiredFastDeepEqual) return fastDeepEqual;
83
- hasRequiredFastDeepEqual = 1;
84
- fastDeepEqual = function equal(a, b) {
85
- if (a === b) return true;
86
- if (a && b && typeof a == "object" && typeof b == "object") {
87
- if (a.constructor !== b.constructor) return false;
88
- var length, i, keys;
89
- if (Array.isArray(a)) {
90
- length = a.length;
91
- if (length != b.length) return false;
92
- for (i = length; i-- !== 0; )
93
- if (!equal(a[i], b[i])) return false;
94
- return true;
78
+ function usePropBinding(object, prop, value) {
79
+ const writtenTo = useRef(null);
80
+ useEffect(() => {
81
+ if (!object)
82
+ return;
83
+ if (value === void 0 && writtenTo.current !== object)
84
+ return;
85
+ writtenTo.current = object;
86
+ object[prop] = value;
87
+ }, [object, prop, value]);
88
+ }
89
+ const SafeReact = Object.assign({}, React);
90
+ const useInsertionEffect = SafeReact.useInsertionEffect;
91
+ const useSafeInsertionEffect = (
92
+ // React 17 doesn't have useInsertionEffect.
93
+ useInsertionEffect && // Preact replaces useInsertionEffect with useLayoutEffect and fires too late.
94
+ useInsertionEffect !== SafeReact.useLayoutEffect ? useInsertionEffect : (fn) => {
95
+ fn();
96
+ }
97
+ );
98
+ function forbiddenInRender() {
99
+ throw new Error("useEffectEvent: invalid call during rendering.");
100
+ }
101
+ function useEffectEventPolyfill(fn) {
102
+ const ref = useRef(forbiddenInRender);
103
+ useSafeInsertionEffect(() => {
104
+ ref.current = fn;
105
+ }, [fn]);
106
+ return ((...args) => ref.current(...args));
107
+ }
108
+ const useEffectEvent = useEffectEventPolyfill;
109
+ const noop$1 = () => {
110
+ };
111
+ function useDomEventListener(target, name, callback) {
112
+ const eventFn = useEffectEvent(callback !== null && callback !== void 0 ? callback : noop$1);
113
+ const isCallbackDefined = Boolean(callback);
114
+ useEffect(() => {
115
+ if (!target || !name || !isCallbackDefined)
116
+ return;
117
+ const listenerCallback = eventFn;
118
+ target.addEventListener(name, listenerCallback);
119
+ return () => target.removeEventListener(name, listenerCallback);
120
+ }, [target, name, isCallbackDefined]);
121
+ }
122
+ function __rest(s, e) {
123
+ var t = {};
124
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
125
+ t[p] = s[p];
126
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
127
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
128
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
129
+ t[p[i]] = s[p[i]];
130
+ }
131
+ return t;
132
+ }
133
+ function __awaiter(thisArg, _arguments, P, generator) {
134
+ function adopt(value) {
135
+ return value instanceof P ? value : new P(function(resolve) {
136
+ resolve(value);
137
+ });
138
+ }
139
+ return new (P || (P = Promise))(function(resolve, reject) {
140
+ function fulfilled(value) {
141
+ try {
142
+ step(generator.next(value));
143
+ } catch (e) {
144
+ reject(e);
145
+ }
146
+ }
147
+ function rejected(value) {
148
+ try {
149
+ step(generator["throw"](value));
150
+ } catch (e) {
151
+ reject(e);
152
+ }
153
+ }
154
+ function step(result) {
155
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
156
+ }
157
+ step((generator = generator.apply(thisArg, [])).next());
158
+ });
159
+ }
160
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
161
+ var e = new Error(message);
162
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
163
+ };
164
+ const MSG_REPEATED_SET_OPTIONS = (options) => `The setOptions() function should only be called once. The options passed to the additional call (${JSON.stringify(options)}) will be ignored.`;
165
+ const MSG_IMPORT_LIBRARY_EXISTS = (options) => `The google.maps.importLibrary() function is already defined, and @googlemaps/js-api-loader will use the existing function instead of overwriting it. The options passed to setOptions (${JSON.stringify(options)}) will be ignored.`;
166
+ const MSG_SET_OPTIONS_NOT_CALLED = "No options were set before calling importLibrary. Make sure to configure the loader using setOptions().";
167
+ const MSG_SCRIPT_ELEMENT_EXISTS = "There already is a script loading the Google Maps JavaScript API, and no google.maps.importLibrary function is defined. @googlemaps/js-api-loader will proceed to bootstrap the API with the specified options, but the existing script might cause problems using the API. Make sure to remove the script loading the API.";
168
+ const MSG_API_KEY_USED = "The 'apiKey' parameter was used in setOptions(), but 'key' is the correct parameter name. Please update your configuration.";
169
+ const MSG_TRUSTED_TYPES_POLICY_FAILED = (policyName, error) => `Failed to create Trusted Types policy "${policyName}": ${error instanceof Error ? error.message : String(error)}.
170
+
171
+ If your Content Security Policy uses "require-trusted-types-for 'script'", allow this policy with "trusted-types ${policyName} google-maps-api-loader google-maps-api#html lit-html". The "google-maps-api-loader", "lit-html", and "google-maps-api#html" policies are required for full Maps JavaScript API execution. Falling back to a string script URL.`;
172
+ const __DEV__$1 = process.env.NODE_ENV !== "production";
173
+ const logDevWarning = __DEV__$1 ? (message) => {
174
+ console.warn(`[@googlemaps/js-api-loader] ${message}`);
175
+ } : () => {
176
+ };
177
+ const logDevNotice = __DEV__$1 ? (message) => {
178
+ console.info(`[@googlemaps/js-api-loader] ${message}`);
179
+ } : () => {
180
+ };
181
+ const TRUSTED_TYPES_POLICY_NAME = "@googlemaps/js-api-loader";
182
+ const fallbackPolicy = { createScriptURL: (url) => url };
183
+ let policy;
184
+ function getPolicy() {
185
+ if (policy) {
186
+ return policy;
187
+ }
188
+ const trustedTypes = globalThis.trustedTypes;
189
+ if (!trustedTypes) {
190
+ policy = fallbackPolicy;
191
+ return policy;
192
+ }
193
+ try {
194
+ policy = trustedTypes.createPolicy(TRUSTED_TYPES_POLICY_NAME, {
195
+ createScriptURL: (url) => url
196
+ });
197
+ } catch (e) {
198
+ logDevWarning(MSG_TRUSTED_TYPES_POLICY_FAILED(TRUSTED_TYPES_POLICY_NAME, e));
199
+ policy = fallbackPolicy;
200
+ }
201
+ return policy;
202
+ }
203
+ function setScriptSrc(script, src) {
204
+ script.src = getPolicy().createScriptURL(src);
205
+ }
206
+ const bootstrap = (bootstrapParams) => {
207
+ var bootstrapPromise;
208
+ var script;
209
+ var bootstrapParamsKey;
210
+ var PRODUCT_NAME = "The Google Maps JavaScript API";
211
+ var GOOGLE = "google";
212
+ var IMPORT_API_NAME = "importLibrary";
213
+ var PENDING_BOOTSTRAP_KEY = "__ib__";
214
+ var doc = document;
215
+ var global_ = window;
216
+ var google_ = global_[GOOGLE] || (global_[GOOGLE] = {});
217
+ var namespace = google_.maps || (google_.maps = {});
218
+ var libraries = /* @__PURE__ */ new Set();
219
+ var searchParams = new URLSearchParams();
220
+ var triggerBootstrap = () => bootstrapPromise || (bootstrapPromise = new Promise(async (resolve, reject) => {
221
+ var _a;
222
+ await (script = doc.createElement("script"));
223
+ searchParams.set("libraries", [...libraries] + "");
224
+ for (bootstrapParamsKey in bootstrapParams) {
225
+ searchParams.set(bootstrapParamsKey.replace(/[A-Z]/g, (g) => "_" + g[0].toLowerCase()), bootstrapParams[bootstrapParamsKey]);
226
+ }
227
+ searchParams.set("callback", GOOGLE + ".maps." + PENDING_BOOTSTRAP_KEY);
228
+ setScriptSrc(script, "https://maps.googleapis.com/maps/api/js?" + searchParams);
229
+ namespace[PENDING_BOOTSTRAP_KEY] = resolve;
230
+ script.onerror = () => bootstrapPromise = reject(Error(PRODUCT_NAME + " could not load."));
231
+ script.nonce = ((_a = doc.querySelector("script[nonce]")) == null ? void 0 : _a.nonce) || "";
232
+ doc.head.append(script);
233
+ }));
234
+ namespace[IMPORT_API_NAME] ? console.warn(PRODUCT_NAME + " only loads once. Ignoring:", bootstrapParams) : namespace[IMPORT_API_NAME] = (libraryName, ...args) => libraries.add(libraryName) && triggerBootstrap().then(() => namespace[IMPORT_API_NAME](libraryName, ...args));
235
+ };
236
+ const __DEV__ = process.env.NODE_ENV !== "production";
237
+ let setOptionsWasCalled_ = false;
238
+ function setOptions(options) {
239
+ if (setOptionsWasCalled_) {
240
+ logDevWarning(MSG_REPEATED_SET_OPTIONS(options));
241
+ return;
242
+ }
243
+ if (options.apiKey) {
244
+ logDevWarning(MSG_API_KEY_USED);
245
+ if (!options.key) {
246
+ options.key = options.apiKey;
247
+ }
248
+ }
249
+ installImportLibrary_(options);
250
+ setOptionsWasCalled_ = true;
251
+ }
252
+ async function importLibrary(libraryName) {
253
+ var _a, _b;
254
+ if (!setOptionsWasCalled_) {
255
+ logDevWarning(MSG_SET_OPTIONS_NOT_CALLED);
256
+ }
257
+ if (!((_b = (_a = window == null ? void 0 : window.google) == null ? void 0 : _a.maps) == null ? void 0 : _b.importLibrary)) {
258
+ throw new Error("google.maps.importLibrary is not installed.");
259
+ }
260
+ return await google.maps.importLibrary(libraryName);
261
+ }
262
+ function installImportLibrary_(options) {
263
+ var _a, _b;
264
+ const importLibraryExists = Boolean((_b = (_a = window.google) == null ? void 0 : _a.maps) == null ? void 0 : _b.importLibrary);
265
+ if (importLibraryExists) {
266
+ logDevNotice(MSG_IMPORT_LIBRARY_EXISTS(options));
267
+ } else if (__DEV__) {
268
+ const scriptEl = document.querySelector('script[src*="maps.googleapis.com/maps/api/js"]');
269
+ if (scriptEl) {
270
+ logDevWarning(MSG_SCRIPT_ELEMENT_EXISTS);
271
+ }
272
+ }
273
+ if (!importLibraryExists) {
274
+ bootstrap(options);
275
+ }
276
+ }
277
+ const APILoadingStatus = {
278
+ NOT_LOADED: "NOT_LOADED",
279
+ LOADING: "LOADING",
280
+ LOADED: "LOADED",
281
+ FAILED: "FAILED",
282
+ AUTH_FAILURE: "AUTH_FAILURE"
283
+ };
284
+ const VERSION = "1.10.1";
285
+ const DEFAULT_SOLUTION_CHANNEL = "GMP_visgl_rgmlibrary_v1_default";
286
+ const DEFAULT_INTERNAL_USAGE_ATTRIBUTION_IDS = [
287
+ `gmp_visgl_reactgooglemaps_v${VERSION}`
288
+ ];
289
+ const APIProviderContext = React__default.createContext(null);
290
+ let loadingStatus = APILoadingStatus.NOT_LOADED;
291
+ let serializedApiParams;
292
+ const listeners = /* @__PURE__ */ new Set();
293
+ function updateLoadingStatus(status) {
294
+ if (status === loadingStatus) {
295
+ return;
296
+ }
297
+ loadingStatus = status;
298
+ listeners.forEach((listener) => listener(loadingStatus));
299
+ }
300
+ function useMapInstances() {
301
+ const [mapInstances, setMapInstances] = useState({});
302
+ const addMapInstance = (mapInstance, id = "default") => {
303
+ setMapInstances((instances) => Object.assign(Object.assign({}, instances), { [id]: mapInstance }));
304
+ };
305
+ const removeMapInstance = (id = "default") => {
306
+ setMapInstances((_a) => {
307
+ var _b = id;
308
+ _a[_b];
309
+ var remaining = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
310
+ return remaining;
311
+ });
312
+ };
313
+ const clearMapInstances = () => {
314
+ setMapInstances({});
315
+ };
316
+ return { mapInstances, addMapInstance, removeMapInstance, clearMapInstances };
317
+ }
318
+ function useMap3DInstances() {
319
+ const [map3dInstances, setMap3DInstances] = useState({});
320
+ const addMap3DInstance = (map3dInstance, id = "default") => {
321
+ setMap3DInstances((instances) => Object.assign(Object.assign({}, instances), { [id]: map3dInstance }));
322
+ };
323
+ const removeMap3DInstance = (id = "default") => {
324
+ setMap3DInstances((_a) => {
325
+ var _b = id;
326
+ _a[_b];
327
+ var remaining = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
328
+ return remaining;
329
+ });
330
+ };
331
+ const clearMap3DInstances = () => {
332
+ setMap3DInstances({});
333
+ };
334
+ return {
335
+ map3dInstances,
336
+ addMap3DInstance,
337
+ removeMap3DInstance,
338
+ clearMap3DInstances
339
+ };
340
+ }
341
+ function useGoogleMapsApiLoader(props) {
342
+ const { onLoad, onError, apiKey, version, libraries = [], region, language, authReferrerPolicy, channel, solutionChannel, fetchAppCheckToken } = props;
343
+ const [status, setStatus] = useState(loadingStatus);
344
+ const [loadedLibraries, addLoadedLibrary] = useReducer((loadedLibraries2, action) => {
345
+ return loadedLibraries2[action.name] ? loadedLibraries2 : Object.assign(Object.assign({}, loadedLibraries2), { [action.name]: action.value });
346
+ }, {});
347
+ const currentSerializedParams = useMemo(() => {
348
+ const params = {
349
+ apiKey,
350
+ version,
351
+ libraries: libraries.join(","),
352
+ region,
353
+ language,
354
+ authReferrerPolicy,
355
+ channel,
356
+ solutionChannel
357
+ };
358
+ return JSON.stringify(params);
359
+ }, [
360
+ apiKey,
361
+ version,
362
+ libraries,
363
+ region,
364
+ language,
365
+ authReferrerPolicy,
366
+ channel,
367
+ solutionChannel
368
+ ]);
369
+ const importLibraryCallback = useCallback((name) => __awaiter(this, void 0, void 0, function* () {
370
+ if (loadedLibraries[name]) {
371
+ return loadedLibraries[name];
372
+ }
373
+ const res = yield importLibrary(name);
374
+ addLoadedLibrary({ name, value: res });
375
+ return res;
376
+ }), [loadedLibraries]);
377
+ useEffect(() => {
378
+ listeners.add(setStatus);
379
+ setStatus(loadingStatus);
380
+ return () => {
381
+ listeners.delete(setStatus);
382
+ };
383
+ }, []);
384
+ useEffect(
385
+ () => {
386
+ (() => __awaiter(this, void 0, void 0, function* () {
387
+ var _a, _b;
388
+ try {
389
+ if (serializedApiParams && serializedApiParams !== currentSerializedParams) {
390
+ console.warn(`The Google Maps JavaScript API has already been loaded with different parameters. The new parameters will be ignored. If you need to use different parameters, please refresh the page.`);
391
+ }
392
+ const librariesToLoad = [
393
+ "core",
394
+ "maps",
395
+ ...libraries
396
+ ];
397
+ const options = Object.fromEntries(Object.entries({
398
+ key: apiKey,
399
+ v: version,
400
+ libraries,
401
+ region,
402
+ language,
403
+ authReferrerPolicy
404
+ }).filter(([, value]) => value !== void 0));
405
+ if (channel !== void 0 && channel >= 0 && channel <= 999) {
406
+ options.channel = String(channel);
407
+ }
408
+ if (solutionChannel === void 0) {
409
+ options.solutionChannel = DEFAULT_SOLUTION_CHANNEL;
410
+ } else if (solutionChannel !== "") {
411
+ options.solutionChannel = solutionChannel;
412
+ }
413
+ if ((_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.maps) === null || _b === void 0 ? void 0 : _b.importLibrary) {
414
+ const shouldUpdateLoadingStatus = !serializedApiParams;
415
+ if (shouldUpdateLoadingStatus) {
416
+ serializedApiParams = currentSerializedParams;
417
+ setOptions(options);
418
+ }
419
+ yield Promise.all(librariesToLoad.map((name) => importLibraryCallback(name)));
420
+ if (shouldUpdateLoadingStatus) {
421
+ updateLoadingStatus(APILoadingStatus.LOADED);
422
+ }
423
+ if (onLoad)
424
+ onLoad();
425
+ return;
426
+ }
427
+ if (loadingStatus === APILoadingStatus.LOADING || loadingStatus === APILoadingStatus.LOADED) {
428
+ if (loadingStatus === APILoadingStatus.LOADED && onLoad)
429
+ onLoad();
430
+ return;
431
+ }
432
+ serializedApiParams = currentSerializedParams;
433
+ updateLoadingStatus(APILoadingStatus.LOADING);
434
+ setOptions(options);
435
+ yield Promise.all(librariesToLoad.map((name) => importLibraryCallback(name)));
436
+ updateLoadingStatus(APILoadingStatus.LOADED);
437
+ if (onLoad) {
438
+ onLoad();
439
+ }
440
+ } catch (error) {
441
+ updateLoadingStatus(APILoadingStatus.FAILED);
442
+ if (onError) {
443
+ onError(error);
444
+ } else {
445
+ console.error("The Google Maps JavaScript API failed to load.", error);
446
+ }
447
+ }
448
+ }))();
449
+ },
450
+ // eslint-disable-next-line react-hooks/exhaustive-deps
451
+ [currentSerializedParams, onLoad, onError, importLibraryCallback, libraries]
452
+ );
453
+ useEffect(() => {
454
+ if (status !== APILoadingStatus.LOADED)
455
+ return;
456
+ const settings = google.maps.Settings.getInstance();
457
+ if (fetchAppCheckToken) {
458
+ settings.fetchAppCheckToken = fetchAppCheckToken;
459
+ }
460
+ }, [status, fetchAppCheckToken]);
461
+ return {
462
+ status,
463
+ loadedLibraries,
464
+ importLibrary: importLibraryCallback
465
+ };
466
+ }
467
+ function useInternalUsageAttributionIds(props) {
468
+ return useMemo(() => props.disableUsageAttribution ? null : DEFAULT_INTERNAL_USAGE_ATTRIBUTION_IDS, [props.disableUsageAttribution]);
469
+ }
470
+ const APIProvider = (props) => {
471
+ const { children } = props, loaderProps = __rest(props, ["children"]);
472
+ const { mapInstances, addMapInstance, removeMapInstance, clearMapInstances } = useMapInstances();
473
+ const { map3dInstances, addMap3DInstance, removeMap3DInstance, clearMap3DInstances } = useMap3DInstances();
474
+ const { status, loadedLibraries, importLibrary: importLibrary2 } = useGoogleMapsApiLoader(loaderProps);
475
+ const internalUsageAttributionIds = useInternalUsageAttributionIds(loaderProps);
476
+ const contextValue = useMemo(() => ({
477
+ mapInstances,
478
+ addMapInstance,
479
+ removeMapInstance,
480
+ clearMapInstances,
481
+ map3dInstances,
482
+ addMap3DInstance,
483
+ removeMap3DInstance,
484
+ clearMap3DInstances,
485
+ status,
486
+ loadedLibraries,
487
+ importLibrary: importLibrary2,
488
+ internalUsageAttributionIds
489
+ }), [
490
+ mapInstances,
491
+ addMapInstance,
492
+ removeMapInstance,
493
+ clearMapInstances,
494
+ map3dInstances,
495
+ addMap3DInstance,
496
+ removeMap3DInstance,
497
+ clearMap3DInstances,
498
+ status,
499
+ loadedLibraries,
500
+ importLibrary2,
501
+ internalUsageAttributionIds
502
+ ]);
503
+ return React__default.createElement(APIProviderContext.Provider, { value: contextValue }, children);
504
+ };
505
+ function useCallbackRef() {
506
+ const [el, setEl] = useState(null);
507
+ const ref = useCallback((value) => setEl(value), [setEl]);
508
+ return [el, ref];
509
+ }
510
+ function useApiLoadingStatus() {
511
+ var _a;
512
+ return ((_a = useContext(APIProviderContext)) === null || _a === void 0 ? void 0 : _a.status) || APILoadingStatus.NOT_LOADED;
513
+ }
514
+ function useApiIsLoaded() {
515
+ const status = useApiLoadingStatus();
516
+ return status === APILoadingStatus.LOADED;
517
+ }
518
+ function useMapsLibrary(name) {
519
+ var _a;
520
+ const apiIsLoaded = useApiIsLoaded();
521
+ const ctx = useContext(APIProviderContext);
522
+ useEffect(() => {
523
+ if (!apiIsLoaded || !ctx)
524
+ return;
525
+ void ctx.importLibrary(name);
526
+ }, [apiIsLoaded, ctx, name]);
527
+ return (_a = ctx === null || ctx === void 0 ? void 0 : ctx.loadedLibraries[name]) !== null && _a !== void 0 ? _a : null;
528
+ }
529
+ function useForceUpdate() {
530
+ const [, forceUpdate] = useReducer((x) => x + 1, 0);
531
+ return forceUpdate;
532
+ }
533
+ const DEFAULT_CAMERA_STATE = {
534
+ center: { lat: 0, lng: 0, altitude: 0 },
535
+ range: 0,
536
+ heading: 0,
537
+ tilt: 0,
538
+ roll: 0
539
+ };
540
+ const CAMERA_PROPS = ["center", "range", "heading", "tilt", "roll"];
541
+ function updateCameraState(map3d, ref, prop) {
542
+ const value = map3d[prop];
543
+ if (value == null)
544
+ return;
545
+ if (prop === "center") {
546
+ const center = value;
547
+ ref.current.center = center.toJSON ? center.toJSON() : center;
548
+ } else {
549
+ ref.current[prop] = value;
550
+ }
551
+ }
552
+ function useTrackedCameraStateRef3D(map3d) {
553
+ const forceUpdate = useForceUpdate();
554
+ const ref = useRef(Object.assign({}, DEFAULT_CAMERA_STATE));
555
+ useEffect(() => {
556
+ if (!map3d)
557
+ return;
558
+ const listeners2 = [];
559
+ for (const prop of CAMERA_PROPS) {
560
+ const eventName = `gmp-${prop}change`;
561
+ const handler = () => {
562
+ updateCameraState(map3d, ref, prop);
563
+ forceUpdate();
564
+ };
565
+ map3d.addEventListener(eventName, handler);
566
+ listeners2.push(() => map3d.removeEventListener(eventName, handler));
567
+ }
568
+ return () => {
569
+ for (const removeListener of listeners2) {
570
+ removeListener();
571
+ }
572
+ };
573
+ }, [map3d, forceUpdate]);
574
+ return ref;
575
+ }
576
+ function useMap3DInstance(props) {
577
+ const maps3dLib = useMapsLibrary("maps3d");
578
+ const [customElementReady, setCustomElementReady] = useState(false);
579
+ const [, containerRef] = useCallbackRef();
580
+ const [map3d, map3dRef] = useCallbackRef();
581
+ const cameraStateRef = useTrackedCameraStateRef3D(map3d);
582
+ useEffect(() => {
583
+ customElements.whenDefined("gmp-map-3d").then(() => {
584
+ setCustomElementReady(true);
585
+ });
586
+ }, []);
587
+ useEffect(
588
+ () => {
589
+ if (!map3d)
590
+ return;
591
+ const {
592
+ center,
593
+ heading,
594
+ tilt,
595
+ range,
596
+ roll,
597
+ defaultCenter,
598
+ defaultHeading,
599
+ defaultTilt,
600
+ defaultRange,
601
+ defaultRoll,
602
+ // Non-element props to exclude
603
+ id,
604
+ style: style2,
605
+ className,
606
+ children,
607
+ onCenterChanged,
608
+ onHeadingChanged,
609
+ onTiltChanged,
610
+ onRangeChanged,
611
+ onRollChanged,
612
+ onCameraChanged,
613
+ onClick,
614
+ onSteadyChange,
615
+ onAnimationEnd,
616
+ onError,
617
+ mode,
618
+ gestureHandling
619
+ } = props, elementOptions = __rest(props, ["center", "heading", "tilt", "range", "roll", "defaultCenter", "defaultHeading", "defaultTilt", "defaultRange", "defaultRoll", "id", "style", "className", "children", "onCenterChanged", "onHeadingChanged", "onTiltChanged", "onRangeChanged", "onRollChanged", "onCameraChanged", "onClick", "onSteadyChange", "onAnimationEnd", "onError", "mode", "gestureHandling"]);
620
+ const initialCenter = center !== null && center !== void 0 ? center : defaultCenter;
621
+ const initialHeading = heading !== null && heading !== void 0 ? heading : defaultHeading;
622
+ const initialTilt = tilt !== null && tilt !== void 0 ? tilt : defaultTilt;
623
+ const initialRange = range !== null && range !== void 0 ? range : defaultRange;
624
+ const initialRoll = roll !== null && roll !== void 0 ? roll : defaultRoll;
625
+ const initialOptions = Object.assign({}, elementOptions);
626
+ if (initialCenter)
627
+ initialOptions.center = initialCenter;
628
+ if (initialHeading !== void 0)
629
+ initialOptions.heading = initialHeading;
630
+ if (initialTilt !== void 0)
631
+ initialOptions.tilt = initialTilt;
632
+ if (initialRange !== void 0)
633
+ initialOptions.range = initialRange;
634
+ if (initialRoll !== void 0)
635
+ initialOptions.roll = initialRoll;
636
+ Object.assign(map3d, initialOptions);
637
+ },
638
+ // this effect should only run when the map3d element first becomes
639
+ // available, so we skip re-running it when other props change.
640
+ // eslint-disable-next-line react-hooks/exhaustive-deps
641
+ [map3d]
642
+ );
643
+ const isReady = !!maps3dLib && customElementReady;
644
+ return [map3d, containerRef, map3dRef, cameraStateRef, isReady];
645
+ }
646
+ function toLatLngAltitudeLiteral(value) {
647
+ if (!value)
648
+ return null;
649
+ if ("toJSON" in value && typeof value.toJSON === "function") {
650
+ return value.toJSON();
651
+ }
652
+ return value;
653
+ }
654
+ function useMap3DCameraParams(map3d, cameraStateRef, props) {
655
+ var _a, _b, _c, _d, _e, _f, _g;
656
+ const centerLiteral = toLatLngAltitudeLiteral(props.center);
657
+ const lat = (_a = centerLiteral === null || centerLiteral === void 0 ? void 0 : centerLiteral.lat) !== null && _a !== void 0 ? _a : null;
658
+ const lng = (_b = centerLiteral === null || centerLiteral === void 0 ? void 0 : centerLiteral.lng) !== null && _b !== void 0 ? _b : null;
659
+ const altitude = (_c = centerLiteral === null || centerLiteral === void 0 ? void 0 : centerLiteral.altitude) !== null && _c !== void 0 ? _c : null;
660
+ const range = (_d = props.range) !== null && _d !== void 0 ? _d : null;
661
+ const heading = (_e = props.heading) !== null && _e !== void 0 ? _e : null;
662
+ const tilt = (_f = props.tilt) !== null && _f !== void 0 ? _f : null;
663
+ const roll = (_g = props.roll) !== null && _g !== void 0 ? _g : null;
664
+ useLayoutEffect(() => {
665
+ var _a2;
666
+ if (!map3d)
667
+ return;
668
+ const currentState = cameraStateRef.current;
669
+ if (lat !== null && lng !== null && (currentState.center.lat !== lat || currentState.center.lng !== lng || altitude !== null && currentState.center.altitude !== altitude)) {
670
+ map3d.center = {
671
+ lat,
672
+ lng,
673
+ altitude: (_a2 = altitude !== null && altitude !== void 0 ? altitude : currentState.center.altitude) !== null && _a2 !== void 0 ? _a2 : 0
674
+ };
675
+ }
676
+ if (range !== null && currentState.range !== range) {
677
+ map3d.range = range;
678
+ }
679
+ if (heading !== null && currentState.heading !== heading) {
680
+ map3d.heading = heading;
681
+ }
682
+ if (tilt !== null && currentState.tilt !== tilt) {
683
+ map3d.tilt = tilt;
684
+ }
685
+ if (roll !== null && currentState.roll !== roll) {
686
+ map3d.roll = roll;
687
+ }
688
+ });
689
+ }
690
+ const CAMERA_EVENTS = [
691
+ "gmp-centerchange",
692
+ "gmp-headingchange",
693
+ "gmp-tiltchange",
694
+ "gmp-rangechange",
695
+ "gmp-rollchange"
696
+ ];
697
+ function createCameraEvent(map3d, type) {
698
+ const center = map3d.center;
699
+ let centerLiteral;
700
+ if (center && "toJSON" in center && typeof center.toJSON === "function") {
701
+ centerLiteral = center.toJSON();
702
+ } else if (center) {
703
+ centerLiteral = center;
704
+ } else {
705
+ centerLiteral = { lat: 0, lng: 0, altitude: 0 };
706
+ }
707
+ return {
708
+ type,
709
+ map3d,
710
+ detail: {
711
+ center: centerLiteral,
712
+ range: map3d.range || 0,
713
+ heading: map3d.heading || 0,
714
+ tilt: map3d.tilt || 0,
715
+ roll: map3d.roll || 0
716
+ }
717
+ };
718
+ }
719
+ function createClickEvent(map3d, srcEvent) {
720
+ const placeClickEvent = srcEvent;
721
+ return {
722
+ type: "gmp-click",
723
+ map3d,
724
+ detail: {
725
+ position: srcEvent.position || null,
726
+ placeId: placeClickEvent.placeId
727
+ }
728
+ };
729
+ }
730
+ function createSteadyChangeEvent(map3d, srcEvent) {
731
+ return {
732
+ type: "gmp-steadychange",
733
+ map3d,
734
+ detail: {
735
+ isSteady: srcEvent.isSteady
736
+ }
737
+ };
738
+ }
739
+ function useMap3DEvents(map3d, props) {
740
+ const { onCenterChanged, onHeadingChanged, onTiltChanged, onRangeChanged, onRollChanged, onCameraChanged, onClick, onSteadyChange, onAnimationEnd, onError } = props;
741
+ useMap3DEvent(map3d, "gmp-centerchange", onCenterChanged, createCameraEvent);
742
+ useMap3DEvent(map3d, "gmp-headingchange", onHeadingChanged, createCameraEvent);
743
+ useMap3DEvent(map3d, "gmp-tiltchange", onTiltChanged, createCameraEvent);
744
+ useMap3DEvent(map3d, "gmp-rangechange", onRangeChanged, createCameraEvent);
745
+ useMap3DEvent(map3d, "gmp-rollchange", onRollChanged, createCameraEvent);
746
+ useEffect(() => {
747
+ if (!map3d || !onCameraChanged)
748
+ return;
749
+ const handler = () => {
750
+ onCameraChanged(createCameraEvent(map3d, "camerachange"));
751
+ };
752
+ for (const eventName of CAMERA_EVENTS) {
753
+ map3d.addEventListener(eventName, handler);
754
+ }
755
+ return () => {
756
+ for (const eventName of CAMERA_EVENTS) {
757
+ map3d.removeEventListener(eventName, handler);
758
+ }
759
+ };
760
+ }, [map3d, onCameraChanged]);
761
+ useEffect(() => {
762
+ if (!map3d || !onClick)
763
+ return;
764
+ const handler = (ev) => {
765
+ onClick(createClickEvent(map3d, ev));
766
+ };
767
+ map3d.addEventListener("gmp-click", handler);
768
+ return () => map3d.removeEventListener("gmp-click", handler);
769
+ }, [map3d, onClick]);
770
+ useEffect(() => {
771
+ if (!map3d || !onSteadyChange)
772
+ return;
773
+ const handler = (ev) => {
774
+ onSteadyChange(createSteadyChangeEvent(map3d, ev));
775
+ };
776
+ map3d.addEventListener("gmp-steadychange", handler);
777
+ return () => map3d.removeEventListener("gmp-steadychange", handler);
778
+ }, [map3d, onSteadyChange]);
779
+ useMap3DEvent(map3d, "gmp-animationend", onAnimationEnd, (map3d2, type) => ({
780
+ type,
781
+ map3d: map3d2
782
+ }));
783
+ useMap3DEvent(map3d, "gmp-error", onError, (map3d2, type) => ({
784
+ type,
785
+ map3d: map3d2
786
+ }));
787
+ }
788
+ function useMap3DEvent(map3d, eventName, handler, createEvent) {
789
+ useEffect(() => {
790
+ if (!map3d || !handler)
791
+ return;
792
+ const listener = () => {
793
+ handler(createEvent(map3d, eventName));
794
+ };
795
+ map3d.addEventListener(eventName, listener);
796
+ return () => map3d.removeEventListener(eventName, listener);
797
+ }, [map3d, eventName, handler, createEvent]);
798
+ }
799
+ function useMemoized(value, isEqual) {
800
+ const ref = useRef(value);
801
+ if (!isEqual(value, ref.current)) {
802
+ ref.current = value;
803
+ }
804
+ return ref.current;
805
+ }
806
+ function useCustomCompareEffect(effect, dependencies, isEqual) {
807
+ useEffect(effect, [useMemoized(dependencies, isEqual)]);
808
+ }
809
+ const { getOwnPropertyNames, getOwnPropertySymbols } = Object;
810
+ const { hasOwnProperty } = Object.prototype;
811
+ function combineComparators(comparatorA, comparatorB) {
812
+ return function isEqual(a, b, state) {
813
+ return comparatorA(a, b, state) && comparatorB(a, b, state);
814
+ };
815
+ }
816
+ function createIsCircular(areItemsEqual) {
817
+ return function isCircular(a, b, state) {
818
+ if (!a || !b || typeof a !== "object" || typeof b !== "object") {
819
+ return areItemsEqual(a, b, state);
820
+ }
821
+ const { cache } = state;
822
+ const cachedA = cache.get(a);
823
+ const cachedB = cache.get(b);
824
+ if (cachedA && cachedB) {
825
+ return cachedA === b && cachedB === a;
826
+ }
827
+ cache.set(a, b);
828
+ cache.set(b, a);
829
+ const result = areItemsEqual(a, b, state);
830
+ cache.delete(a);
831
+ cache.delete(b);
832
+ return result;
833
+ };
834
+ }
835
+ function getStrictProperties(object) {
836
+ const symbols = getOwnPropertySymbols(object);
837
+ return symbols.length ? getOwnPropertyNames(object).concat(symbols) : getOwnPropertyNames(object);
838
+ }
839
+ const hasOwn$1 = (
840
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
841
+ Object.hasOwn || ((object, property) => hasOwnProperty.call(object, property))
842
+ );
843
+ const PREACT_VNODE = "__v";
844
+ const PREACT_OWNER = "__o";
845
+ const REACT_OWNER = "_owner";
846
+ const HAS_FLOAT_16_ARRAY = typeof Float16Array !== "undefined";
847
+ const { getOwnPropertyDescriptor, keys } = Object;
848
+ const sameValueEqual = (
849
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
850
+ Object.is || function sameValueEqual2(a, b) {
851
+ return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
852
+ }
853
+ );
854
+ function strictEqual(a, b) {
855
+ return a === b;
856
+ }
857
+ function areArrayBuffersEqual(a, b) {
858
+ return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b));
859
+ }
860
+ function areArraysEqual(a, b, state) {
861
+ let index = a.length;
862
+ if (b.length !== index) {
863
+ return false;
864
+ }
865
+ while (index-- > 0) {
866
+ if (!state.equals(a[index], b[index], index, index, a, b, state)) {
867
+ return false;
868
+ }
869
+ }
870
+ return true;
871
+ }
872
+ function areDataViewsEqual(a, b) {
873
+ return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength));
874
+ }
875
+ function areDatesEqual(a, b) {
876
+ return sameValueEqual(a.getTime(), b.getTime());
877
+ }
878
+ function areErrorsEqual(a, b, state) {
879
+ return a.name === b.name && a.message === b.message && a.stack === b.stack && state.equals(a.cause, b.cause, "cause", "cause", a, b, state);
880
+ }
881
+ function areMapsEqual(a, b, state) {
882
+ const size = a.size;
883
+ if (size !== b.size) {
884
+ return false;
885
+ }
886
+ if (!size) {
887
+ return true;
888
+ }
889
+ const matchedIndices = new Uint8Array(size);
890
+ const aIterable = a.entries();
891
+ let aResult;
892
+ let bResult;
893
+ let index = 0;
894
+ while (aResult = aIterable.next()) {
895
+ if (aResult.done) {
896
+ break;
897
+ }
898
+ const bIterable = b.entries();
899
+ let hasMatch = 0;
900
+ let matchIndex = 0;
901
+ while (bResult = bIterable.next()) {
902
+ if (bResult.done) {
903
+ break;
95
904
  }
96
- if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
97
- if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
98
- if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
99
- keys = Object.keys(a);
100
- length = keys.length;
101
- if (length !== Object.keys(b).length) return false;
102
- for (i = length; i-- !== 0; )
103
- if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
104
- for (i = length; i-- !== 0; ) {
105
- var key = keys[i];
106
- if (!equal(a[key], b[key])) return false;
905
+ if (matchedIndices[matchIndex]) {
906
+ matchIndex++;
907
+ continue;
107
908
  }
909
+ const aEntry = aResult.value;
910
+ const bEntry = bResult.value;
911
+ if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
912
+ hasMatch = matchedIndices[matchIndex] = 1;
913
+ break;
914
+ }
915
+ matchIndex++;
916
+ }
917
+ if (!hasMatch) {
918
+ return false;
919
+ }
920
+ index++;
921
+ }
922
+ return true;
923
+ }
924
+ function areObjectsEqual(a, b, state) {
925
+ const properties = keys(a);
926
+ let index = properties.length;
927
+ if (keys(b).length !== index) {
928
+ return false;
929
+ }
930
+ while (index-- > 0) {
931
+ if (!isPropertyEqual(a, b, state, properties[index])) {
932
+ return false;
933
+ }
934
+ }
935
+ return true;
936
+ }
937
+ function areObjectsEqualStrict(a, b, state) {
938
+ const properties = getStrictProperties(a);
939
+ let index = properties.length;
940
+ if (getStrictProperties(b).length !== index) {
941
+ return false;
942
+ }
943
+ let property;
944
+ let descriptorA;
945
+ let descriptorB;
946
+ while (index-- > 0) {
947
+ property = properties[index];
948
+ if (!isPropertyEqual(a, b, state, property)) {
949
+ return false;
950
+ }
951
+ descriptorA = getOwnPropertyDescriptor(a, property);
952
+ descriptorB = getOwnPropertyDescriptor(b, property);
953
+ if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) {
954
+ return false;
955
+ }
956
+ }
957
+ return true;
958
+ }
959
+ function arePrimitiveWrappersEqual(a, b) {
960
+ return sameValueEqual(a.valueOf(), b.valueOf());
961
+ }
962
+ function areRegExpsEqual(a, b) {
963
+ return a.source === b.source && a.flags === b.flags;
964
+ }
965
+ function areSetsEqual(a, b, state) {
966
+ const size = a.size;
967
+ if (size !== b.size) {
968
+ return false;
969
+ }
970
+ if (!size) {
971
+ return true;
972
+ }
973
+ const matchedIndices = new Uint8Array(size);
974
+ const aIterable = a.values();
975
+ let aResult;
976
+ let bResult;
977
+ while (aResult = aIterable.next()) {
978
+ if (aResult.done) {
979
+ break;
980
+ }
981
+ const bIterable = b.values();
982
+ let hasMatch = 0;
983
+ let matchIndex = 0;
984
+ while (bResult = bIterable.next()) {
985
+ if (bResult.done) {
986
+ break;
987
+ }
988
+ if (!matchedIndices[matchIndex] && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
989
+ hasMatch = matchedIndices[matchIndex] = 1;
990
+ break;
991
+ }
992
+ matchIndex++;
993
+ }
994
+ if (!hasMatch) {
995
+ return false;
996
+ }
997
+ }
998
+ return true;
999
+ }
1000
+ function areTypedArraysEqual(a, b) {
1001
+ let index = a.length;
1002
+ if (b.length !== index || a.byteOffset !== b.byteOffset) {
1003
+ return false;
1004
+ }
1005
+ if (a instanceof Float64Array || a instanceof Float32Array || HAS_FLOAT_16_ARRAY && a instanceof Float16Array) {
1006
+ while (index-- > 0) {
1007
+ if (a[index] !== b[index] && (a[index] === a[index] || b[index] === b[index])) {
1008
+ return false;
1009
+ }
1010
+ }
1011
+ return true;
1012
+ }
1013
+ while (index-- > 0) {
1014
+ if (a[index] !== b[index]) {
1015
+ return false;
1016
+ }
1017
+ }
1018
+ return true;
1019
+ }
1020
+ function areUrlsEqual(a, b) {
1021
+ if (a.href === b.href) {
1022
+ return true;
1023
+ }
1024
+ return a.protocol === b.protocol && a.username === b.username && a.password === b.password && a.host === b.host && a.pathname === b.pathname && a.hash === b.hash && areSearchParamsEqual(a.searchParams, b.searchParams);
1025
+ }
1026
+ function areSearchParamsEqual(a, b) {
1027
+ const serializedA = a.toString();
1028
+ const serializedB = b.toString();
1029
+ return serializedA === serializedB || sortSearchParams(serializedA) === sortSearchParams(serializedB);
1030
+ }
1031
+ function sortSearchParams(serialized) {
1032
+ return serialized.split("&").sort().join("&");
1033
+ }
1034
+ function isPropertyEqual(a, b, state, property) {
1035
+ if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE) && (a.$$typeof || b.$$typeof)) {
1036
+ return true;
1037
+ }
1038
+ return hasOwn$1(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
1039
+ }
1040
+ const toString = Object.prototype.toString;
1041
+ function createEqualityComparator(config) {
1042
+ const supportedComparatorMap = createSupportedComparatorMap(config);
1043
+ const { areArraysEqual: areArraysEqual2, areDatesEqual: areDatesEqual2, areFunctionsEqual, areMapsEqual: areMapsEqual2, areNumbersEqual, areObjectsEqual: areObjectsEqual2, areRegExpsEqual: areRegExpsEqual2, areSetsEqual: areSetsEqual2, getUnsupportedCustomComparator } = config;
1044
+ return function comparator(a, b, state) {
1045
+ if (a === b) {
108
1046
  return true;
109
1047
  }
110
- return a !== a && b !== b;
1048
+ if (a == null || b == null) {
1049
+ return false;
1050
+ }
1051
+ const type = typeof a;
1052
+ if (type !== typeof b) {
1053
+ return false;
1054
+ }
1055
+ if (type !== "object") {
1056
+ if (type === "number" || type === "bigint") {
1057
+ return areNumbersEqual(a, b, state);
1058
+ }
1059
+ if (type === "function") {
1060
+ return areFunctionsEqual(a, b, state);
1061
+ }
1062
+ return false;
1063
+ }
1064
+ const constructor = a.constructor;
1065
+ if (constructor !== b.constructor) {
1066
+ return false;
1067
+ }
1068
+ if (constructor === Object) {
1069
+ return areObjectsEqual2(a, b, state);
1070
+ }
1071
+ if (constructor === Array) {
1072
+ return areArraysEqual2(a, b, state);
1073
+ }
1074
+ if (constructor === Date) {
1075
+ return areDatesEqual2(a, b, state);
1076
+ }
1077
+ if (constructor === RegExp) {
1078
+ return areRegExpsEqual2(a, b, state);
1079
+ }
1080
+ if (constructor === Map) {
1081
+ return areMapsEqual2(a, b, state);
1082
+ }
1083
+ if (constructor === Set) {
1084
+ return areSetsEqual2(a, b, state);
1085
+ }
1086
+ if (constructor === Promise) {
1087
+ return false;
1088
+ }
1089
+ if (Array.isArray(a)) {
1090
+ return areArraysEqual2(a, b, state);
1091
+ }
1092
+ const tag = toString.call(a);
1093
+ const supportedComparator = supportedComparatorMap[tag];
1094
+ if (supportedComparator) {
1095
+ return supportedComparator(a, b, state);
1096
+ }
1097
+ const unsupportedCustomComparator = getUnsupportedCustomComparator && getUnsupportedCustomComparator(a, b, state, tag);
1098
+ if (unsupportedCustomComparator) {
1099
+ return unsupportedCustomComparator(a, b, state);
1100
+ }
1101
+ return false;
111
1102
  };
112
- return fastDeepEqual;
113
1103
  }
114
- var fastDeepEqualExports = requireFastDeepEqual();
115
- const isDeepEqual = /* @__PURE__ */ getDefaultExportFromCjs(fastDeepEqualExports);
116
- function _extends() {
117
- return _extends = Object.assign ? Object.assign.bind() : function(n) {
118
- for (var e = 1; e < arguments.length; e++) {
119
- var t = arguments[e];
120
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
1104
+ function createEqualityComparatorConfig({ circular, createCustomConfig, strict }) {
1105
+ let config = {
1106
+ areArrayBuffersEqual,
1107
+ areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
1108
+ areDataViewsEqual,
1109
+ areDatesEqual,
1110
+ // `Error` subclasses routinely carry their own enumerable properties (`status`, `code`, ...),
1111
+ // which the error comparator alone does not see, so it is composed with the object comparator.
1112
+ // `name` / `message` / `stack` are own but not enumerable, which is why errors need a
1113
+ // comparator of their own rather than being treated as plain objects in the first place.
1114
+ areErrorsEqual: strict ? combineComparators(areErrorsEqual, areObjectsEqualStrict) : combineComparators(areErrorsEqual, areObjectsEqual),
1115
+ areFunctionsEqual: strictEqual,
1116
+ areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
1117
+ areNumbersEqual: sameValueEqual,
1118
+ areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
1119
+ arePrimitiveWrappersEqual,
1120
+ areRegExpsEqual,
1121
+ areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
1122
+ areTypedArraysEqual: strict ? combineComparators(areTypedArraysEqual, areObjectsEqualStrict) : areTypedArraysEqual,
1123
+ areUrlsEqual,
1124
+ getUnsupportedCustomComparator: void 0
1125
+ };
1126
+ if (createCustomConfig) {
1127
+ config = Object.assign({}, config, createCustomConfig(config));
1128
+ }
1129
+ if (circular) {
1130
+ const areArraysEqual2 = createIsCircular(config.areArraysEqual);
1131
+ const areErrorsEqual2 = createIsCircular(config.areErrorsEqual);
1132
+ const areMapsEqual2 = createIsCircular(config.areMapsEqual);
1133
+ const areObjectsEqual2 = createIsCircular(config.areObjectsEqual);
1134
+ const areSetsEqual2 = createIsCircular(config.areSetsEqual);
1135
+ config = Object.assign({}, config, {
1136
+ areArraysEqual: areArraysEqual2,
1137
+ areErrorsEqual: areErrorsEqual2,
1138
+ areMapsEqual: areMapsEqual2,
1139
+ areObjectsEqual: areObjectsEqual2,
1140
+ areSetsEqual: areSetsEqual2
1141
+ });
1142
+ }
1143
+ return config;
1144
+ }
1145
+ function createInternalEqualityComparator(compare) {
1146
+ return function(a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, state) {
1147
+ return compare(a, b, state);
1148
+ };
1149
+ }
1150
+ function createIsEqual({ circular, comparator, createState, equals, strict }) {
1151
+ if (createState) {
1152
+ return function isEqual(a, b) {
1153
+ const { cache = circular ? /* @__PURE__ */ new WeakMap() : void 0, meta } = createState();
1154
+ return comparator(a, b, {
1155
+ cache,
1156
+ equals,
1157
+ meta,
1158
+ strict
1159
+ });
1160
+ };
1161
+ }
1162
+ if (circular) {
1163
+ return function isEqual(a, b) {
1164
+ return comparator(a, b, {
1165
+ cache: /* @__PURE__ */ new WeakMap(),
1166
+ equals,
1167
+ meta: void 0,
1168
+ strict
1169
+ });
1170
+ };
1171
+ }
1172
+ const state = {
1173
+ cache: void 0,
1174
+ equals,
1175
+ meta: void 0,
1176
+ strict
1177
+ };
1178
+ return function isEqual(a, b) {
1179
+ return comparator(a, b, state);
1180
+ };
1181
+ }
1182
+ function createSupportedComparatorMap({ areArrayBuffersEqual: areArrayBuffersEqual2, areArraysEqual: areArraysEqual2, areDataViewsEqual: areDataViewsEqual2, areDatesEqual: areDatesEqual2, areErrorsEqual: areErrorsEqual2, areFunctionsEqual, areMapsEqual: areMapsEqual2, areObjectsEqual: areObjectsEqual2, arePrimitiveWrappersEqual: arePrimitiveWrappersEqual2, areRegExpsEqual: areRegExpsEqual2, areSetsEqual: areSetsEqual2, areTypedArraysEqual: areTypedArraysEqual2, areUrlsEqual: areUrlsEqual2 }) {
1183
+ return {
1184
+ "[object Arguments]": areObjectsEqual2,
1185
+ "[object Array]": areArraysEqual2,
1186
+ "[object ArrayBuffer]": areArrayBuffersEqual2,
1187
+ "[object AsyncGeneratorFunction]": areFunctionsEqual,
1188
+ "[object BigInt]": arePrimitiveWrappersEqual2,
1189
+ "[object BigInt64Array]": areTypedArraysEqual2,
1190
+ "[object BigUint64Array]": areTypedArraysEqual2,
1191
+ "[object Boolean]": arePrimitiveWrappersEqual2,
1192
+ "[object DataView]": areDataViewsEqual2,
1193
+ "[object Date]": areDatesEqual2,
1194
+ // If an error tag, it should be tested explicitly. Like RegExp, the properties are not
1195
+ // enumerable, and therefore will give false positives if tested like a standard object.
1196
+ "[object Error]": areErrorsEqual2,
1197
+ "[object Float16Array]": areTypedArraysEqual2,
1198
+ "[object Float32Array]": areTypedArraysEqual2,
1199
+ "[object Float64Array]": areTypedArraysEqual2,
1200
+ "[object Function]": areFunctionsEqual,
1201
+ "[object GeneratorFunction]": areFunctionsEqual,
1202
+ "[object Int8Array]": areTypedArraysEqual2,
1203
+ "[object Int16Array]": areTypedArraysEqual2,
1204
+ "[object Int32Array]": areTypedArraysEqual2,
1205
+ "[object Map]": areMapsEqual2,
1206
+ "[object Number]": arePrimitiveWrappersEqual2,
1207
+ "[object Object]": (a, b, state) => (
1208
+ // The exception for value comparison is custom `Promise`-like class instances. These should
1209
+ // be treated the same as standard `Promise` objects, which means strict equality, and if
1210
+ // it reaches this point then that strict equality comparison has already failed.
1211
+ typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state)
1212
+ ),
1213
+ // For RegExp, the properties are not enumerable, and therefore will give false positives if
1214
+ // tested like a standard object.
1215
+ "[object RegExp]": areRegExpsEqual2,
1216
+ "[object Set]": areSetsEqual2,
1217
+ "[object String]": arePrimitiveWrappersEqual2,
1218
+ "[object URL]": areUrlsEqual2,
1219
+ "[object Uint8Array]": areTypedArraysEqual2,
1220
+ "[object Uint8ClampedArray]": areTypedArraysEqual2,
1221
+ "[object Uint16Array]": areTypedArraysEqual2,
1222
+ "[object Uint32Array]": areTypedArraysEqual2
1223
+ };
1224
+ }
1225
+ const deepEqual = createCustomEqual();
1226
+ createCustomEqual({ strict: true });
1227
+ createCustomEqual({ circular: true });
1228
+ createCustomEqual({
1229
+ circular: true,
1230
+ strict: true
1231
+ });
1232
+ createCustomEqual({
1233
+ createInternalComparator: () => sameValueEqual
1234
+ });
1235
+ createCustomEqual({
1236
+ strict: true,
1237
+ createInternalComparator: () => sameValueEqual
1238
+ });
1239
+ createCustomEqual({
1240
+ circular: true,
1241
+ createInternalComparator: () => sameValueEqual
1242
+ });
1243
+ createCustomEqual({
1244
+ circular: true,
1245
+ createInternalComparator: () => sameValueEqual,
1246
+ strict: true
1247
+ });
1248
+ function createCustomEqual(options = {}) {
1249
+ const { circular = false, createInternalComparator: createCustomInternalComparator, createState, strict = false } = options;
1250
+ const config = createEqualityComparatorConfig(options);
1251
+ const comparator = createEqualityComparator(config);
1252
+ const equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator);
1253
+ return createIsEqual({ circular, comparator, createState, equals, strict });
1254
+ }
1255
+ function useDeepCompareEffect(effect, dependencies) {
1256
+ useCustomCompareEffect(effect, dependencies, deepEqual);
1257
+ }
1258
+ const MAP_3D_OPTION_KEYS = /* @__PURE__ */ new Set([
1259
+ "bounds",
1260
+ "defaultUIHidden",
1261
+ "gestureHandling",
1262
+ "internalUsageAttributionIds",
1263
+ "maxAltitude",
1264
+ "maxHeading",
1265
+ "maxTilt",
1266
+ "minAltitude",
1267
+ "minHeading",
1268
+ "minTilt",
1269
+ "mode"
1270
+ ]);
1271
+ function useMap3DOptions(map3d, props) {
1272
+ const options = useMemo(() => {
1273
+ const result = {};
1274
+ const keys2 = Object.keys(props);
1275
+ for (const key of keys2) {
1276
+ if (!MAP_3D_OPTION_KEYS.has(key))
1277
+ continue;
1278
+ const value = props[key];
1279
+ if (value === void 0)
1280
+ continue;
1281
+ result[key] = value;
121
1282
  }
122
- return n;
123
- }, _extends.apply(null, arguments);
1283
+ return result;
1284
+ }, [props]);
1285
+ useDeepCompareEffect(() => {
1286
+ if (!map3d)
1287
+ return;
1288
+ Object.assign(map3d, options);
1289
+ }, [map3d, options]);
124
1290
  }
125
- function _objectWithoutPropertiesLoose(r, e) {
126
- if (null == r) return {};
127
- var t = {};
128
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
129
- if (-1 !== e.indexOf(n)) continue;
130
- t[n] = r[n];
1291
+ const GoogleMaps3DContext = React__default.createContext(null);
1292
+ const DEFAULT_CONTAINER_STYLE = {
1293
+ width: "100%",
1294
+ height: "100%",
1295
+ position: "relative"
1296
+ };
1297
+ const Map3D = forwardRef((props, ref) => {
1298
+ const { children, id, className, style: style2 } = props;
1299
+ const context = useContext(APIProviderContext);
1300
+ if (!context) {
1301
+ throw new Error("<Map3D> can only be used inside an <APIProvider> component.");
1302
+ }
1303
+ const { addMap3DInstance, removeMap3DInstance } = context;
1304
+ const [map3d, containerRef, map3dRef, cameraStateRef, isReady] = useMap3DInstance(props);
1305
+ useMap3DCameraParams(map3d, cameraStateRef, props);
1306
+ useMap3DEvents(map3d, props);
1307
+ useMap3DOptions(map3d, props);
1308
+ useEffect(() => {
1309
+ if (!map3d)
1310
+ return;
1311
+ const instanceId = id !== null && id !== void 0 ? id : "default";
1312
+ addMap3DInstance(map3d, instanceId);
1313
+ return () => {
1314
+ removeMap3DInstance(instanceId);
1315
+ };
1316
+ }, [map3d, id]);
1317
+ useImperativeHandle(ref, () => ({
1318
+ map3d,
1319
+ flyCameraAround: (options) => {
1320
+ map3d === null || map3d === void 0 ? void 0 : map3d.flyCameraAround(options);
1321
+ },
1322
+ flyCameraTo: (options) => {
1323
+ map3d === null || map3d === void 0 ? void 0 : map3d.flyCameraTo(options);
1324
+ },
1325
+ stopCameraAnimation: () => {
1326
+ map3d === null || map3d === void 0 ? void 0 : map3d.stopCameraAnimation();
1327
+ }
1328
+ }), [map3d]);
1329
+ const combinedStyle = useMemo(() => Object.assign(Object.assign({}, DEFAULT_CONTAINER_STYLE), style2), [style2]);
1330
+ const contextValue = useMemo(() => ({ map3d }), [map3d]);
1331
+ if (!isReady) {
1332
+ return React__default.createElement("div", Object.assign({ ref: containerRef, "data-testid": "map-3d", style: className ? void 0 : combinedStyle, className }, id ? { id } : {}));
1333
+ }
1334
+ return React__default.createElement(
1335
+ "div",
1336
+ Object.assign({ ref: containerRef, "data-testid": "map-3d", style: className ? void 0 : combinedStyle, className }, id ? { id } : {}),
1337
+ React__default.createElement("gmp-map-3d", { ref: map3dRef, style: { width: "100%", height: "100%" } }, map3d && React__default.createElement(GoogleMaps3DContext.Provider, { value: contextValue }, children))
1338
+ );
1339
+ });
1340
+ Map3D.displayName = "Map3D";
1341
+ const Marker3DContext = createContext(null);
1342
+ const Marker3D = forwardRef(function Marker3D2(props, ref) {
1343
+ const { children, onClick, position, altitudeMode, collisionBehavior, drawsWhenOccluded, extruded, label, sizePreserved, zIndex, title: title2 } = props;
1344
+ const isInteractive = Boolean(onClick);
1345
+ const [marker, setMarker] = useState(null);
1346
+ const [contentHandledExternally, setContentHandledExternally] = useState(false);
1347
+ const contentContainer = useMemo(() => {
1348
+ const container = document.createElement("div");
1349
+ container.style.display = "none";
1350
+ document.body.appendChild(container);
1351
+ return container;
1352
+ }, []);
1353
+ useEffect(() => {
1354
+ return () => contentContainer.remove();
1355
+ }, [contentContainer]);
1356
+ const markerRef = useCallback((node) => {
1357
+ setMarker(node);
1358
+ if (typeof ref === "function") {
1359
+ ref(node);
1360
+ } else if (ref) {
1361
+ ref.current = node;
1362
+ }
1363
+ }, [ref]);
1364
+ useDomEventListener(marker, "gmp-click", onClick);
1365
+ useLayoutEffect(() => {
1366
+ if (contentHandledExternally)
1367
+ return;
1368
+ if (!marker || !contentContainer)
1369
+ return;
1370
+ while (marker.firstChild) {
1371
+ marker.removeChild(marker.firstChild);
1372
+ }
1373
+ const childNodes = Array.from(contentContainer.childNodes);
1374
+ for (const node of childNodes) {
1375
+ if (node.nodeType !== Node.ELEMENT_NODE)
1376
+ continue;
1377
+ const element = node;
1378
+ const tagName = element.tagName.toLowerCase();
1379
+ if (tagName === "img" || tagName === "svg") {
1380
+ const template = document.createElement("template");
1381
+ template.content.appendChild(element.cloneNode(true));
1382
+ marker.appendChild(template);
1383
+ } else {
1384
+ marker.appendChild(element.cloneNode(true));
1385
+ }
1386
+ }
1387
+ }, [marker, contentContainer, children, contentHandledExternally]);
1388
+ const contextValue = useMemo(() => ({ marker, setContentHandledExternally }), [marker]);
1389
+ usePropBinding(marker, "position", position);
1390
+ usePropBinding(marker, "altitudeMode", altitudeMode);
1391
+ usePropBinding(marker, "collisionBehavior", collisionBehavior);
1392
+ usePropBinding(marker, "drawsWhenOccluded", drawsWhenOccluded);
1393
+ usePropBinding(marker, "extruded", extruded);
1394
+ usePropBinding(marker, "label", label);
1395
+ usePropBinding(marker, "sizePreserved", sizePreserved);
1396
+ usePropBinding(marker, "zIndex", zIndex);
1397
+ usePropBinding(marker, "title", title2 !== null && title2 !== void 0 ? title2 : "");
1398
+ return React__default.createElement(
1399
+ Marker3DContext.Provider,
1400
+ { value: contextValue },
1401
+ isInteractive ? React__default.createElement("gmp-marker-3d-interactive", { ref: markerRef }) : React__default.createElement("gmp-marker-3d", { ref: markerRef }),
1402
+ createPortal(children, contentContainer)
1403
+ );
1404
+ });
1405
+ Marker3D.displayName = "Marker3D";
1406
+ function setValueForStyles(element, styles2, prevStyles) {
1407
+ if (styles2 != null && typeof styles2 !== "object") {
1408
+ throw new Error("The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.");
1409
+ }
1410
+ const elementStyle = element.style;
1411
+ if (prevStyles == null) {
1412
+ if (styles2 == null)
1413
+ return;
1414
+ for (const styleName in styles2) {
1415
+ if (!styles2.hasOwnProperty(styleName))
1416
+ continue;
1417
+ setValueForStyle(elementStyle, styleName, styles2[styleName]);
1418
+ }
1419
+ return;
1420
+ }
1421
+ for (const styleName in prevStyles) {
1422
+ if (prevStyles.hasOwnProperty(styleName) && (styles2 == null || !styles2.hasOwnProperty(styleName))) {
1423
+ const isCustomProperty = styleName.indexOf("--") === 0;
1424
+ if (isCustomProperty) {
1425
+ elementStyle.setProperty(styleName, "");
1426
+ } else if (styleName === "float") {
1427
+ elementStyle.cssFloat = "";
1428
+ } else {
1429
+ elementStyle[styleName] = "";
1430
+ }
1431
+ }
1432
+ }
1433
+ if (styles2 == null)
1434
+ return;
1435
+ for (const styleName in styles2) {
1436
+ const value = styles2[styleName];
1437
+ if (styles2.hasOwnProperty(styleName) && prevStyles[styleName] !== value) {
1438
+ setValueForStyle(elementStyle, styleName, value);
1439
+ }
131
1440
  }
132
- return t;
133
1441
  }
134
- function _toPrimitive(t, r) {
135
- if ("object" != typeof t || !t) return t;
136
- var e = t[Symbol.toPrimitive];
137
- if (void 0 !== e) {
138
- var i = e.call(t, r);
139
- if ("object" != typeof i) return i;
140
- throw new TypeError("@@toPrimitive must return a primitive value.");
1442
+ function setValueForStyle(elementStyle, styleName, value) {
1443
+ const isCustomProperty = styleName.indexOf("--") === 0;
1444
+ if (value == null || typeof value === "boolean" || value === "") {
1445
+ if (isCustomProperty) {
1446
+ elementStyle.setProperty(styleName, "");
1447
+ } else if (styleName === "float") {
1448
+ elementStyle.cssFloat = "";
1449
+ } else {
1450
+ elementStyle[styleName] = "";
1451
+ }
1452
+ } else if (isCustomProperty) {
1453
+ elementStyle.setProperty(styleName, value);
1454
+ } else if (typeof value === "number" && value !== 0 && !isUnitlessNumber(styleName)) {
1455
+ elementStyle[styleName] = value + "px";
1456
+ } else {
1457
+ if (styleName === "float") {
1458
+ elementStyle.cssFloat = value;
1459
+ } else {
1460
+ elementStyle[styleName] = ("" + value).trim();
1461
+ }
141
1462
  }
142
- return String(t);
143
1463
  }
144
- function _toPropertyKey(t) {
145
- var i = _toPrimitive(t, "string");
146
- return "symbol" == typeof i ? i : i + "";
1464
+ const unitlessNumbers = /* @__PURE__ */ new Set([
1465
+ "animationIterationCount",
1466
+ "aspectRatio",
1467
+ "borderImageOutset",
1468
+ "borderImageSlice",
1469
+ "borderImageWidth",
1470
+ "boxFlex",
1471
+ "boxFlexGroup",
1472
+ "boxOrdinalGroup",
1473
+ "columnCount",
1474
+ "columns",
1475
+ "flex",
1476
+ "flexGrow",
1477
+ "flexPositive",
1478
+ "flexShrink",
1479
+ "flexNegative",
1480
+ "flexOrder",
1481
+ "gridArea",
1482
+ "gridRow",
1483
+ "gridRowEnd",
1484
+ "gridRowSpan",
1485
+ "gridRowStart",
1486
+ "gridColumn",
1487
+ "gridColumnEnd",
1488
+ "gridColumnSpan",
1489
+ "gridColumnStart",
1490
+ "fontWeight",
1491
+ "lineClamp",
1492
+ "lineHeight",
1493
+ "opacity",
1494
+ "order",
1495
+ "orphans",
1496
+ "scale",
1497
+ "tabSize",
1498
+ "widows",
1499
+ "zIndex",
1500
+ "zoom",
1501
+ "fillOpacity",
1502
+ // SVG-related properties
1503
+ "floodOpacity",
1504
+ "stopOpacity",
1505
+ "strokeDasharray",
1506
+ "strokeDashoffset",
1507
+ "strokeMiterlimit",
1508
+ "strokeOpacity",
1509
+ "strokeWidth"
1510
+ ]);
1511
+ function isUnitlessNumber(name) {
1512
+ return unitlessNumbers.has(name);
147
1513
  }
148
- const APILoadingStatus = {
149
- NOT_LOADED: "NOT_LOADED",
150
- LOADING: "LOADING",
151
- LOADED: "LOADED",
152
- FAILED: "FAILED",
153
- AUTH_FAILURE: "AUTH_FAILURE"
154
- };
155
- const MAPS_API_BASE_URL = "https://maps.googleapis.com/maps/api/js";
156
- class GoogleMapsApiLoader {
157
- /**
158
- * Loads the Maps JavaScript API with the specified parameters.
159
- * Since the Maps library can only be loaded once per page, this will
160
- * produce a warning when called multiple times with different
161
- * parameters.
162
- *
163
- * The returned promise resolves when loading completes
164
- * and rejects in case of an error or when the loading was aborted.
165
- */
166
- static async load(params, onLoadingStatusChange) {
167
- var _window$google;
168
- const libraries = params.libraries ? params.libraries.split(",") : [];
169
- const serializedParams = this.serializeParams(params);
170
- this.listeners.push(onLoadingStatusChange);
171
- if ((_window$google = window.google) != null && (_window$google = _window$google.maps) != null && _window$google.importLibrary) {
172
- if (!this.serializedApiParams) {
173
- this.loadingStatus = APILoadingStatus.LOADED;
174
- }
175
- this.notifyLoadingStatusListeners();
176
- } else {
177
- this.serializedApiParams = serializedParams;
178
- this.initImportLibrary(params);
179
- }
180
- if (this.serializedApiParams && this.serializedApiParams !== serializedParams) {
181
- console.warn(`[google-maps-api-loader] The maps API has already been loaded with different parameters and will not be loaded again. Refresh the page for new values to have effect.`);
182
- }
183
- const librariesToLoad = ["maps", ...libraries];
184
- await Promise.all(librariesToLoad.map((name) => google.maps.importLibrary(name)));
185
- }
186
- /**
187
- * Serialize the parameters used to load the library for easier comparison.
188
- */
189
- static serializeParams(params) {
190
- return [params.v, params.key, params.language, params.region, params.authReferrerPolicy, params.solutionChannel].join("/");
191
- }
192
- /**
193
- * Creates the global `google.maps.importLibrary` function for bootstrapping.
194
- * This is essentially a formatted version of the dynamic loading script
195
- * from the official documentation with some minor adjustments.
196
- *
197
- * The created importLibrary function will load the Google Maps JavaScript API,
198
- * which will then replace the `google.maps.importLibrary` function with the full
199
- * implementation.
200
- *
201
- * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import
202
- */
203
- static initImportLibrary(params) {
204
- if (!window.google) window.google = {};
205
- if (!window.google.maps) window.google.maps = {};
206
- if (window.google.maps["importLibrary"]) {
207
- console.error("[google-maps-api-loader-internal]: initImportLibrary must only be called once");
1514
+ const Popover = forwardRef(function Popover2(props, ref) {
1515
+ var _a;
1516
+ const { children, headerContent, style: style2, className, open = true, position, anchor, anchorId, altitudeMode, lightDismissDisabled, autoPanDisabled, onClose } = props;
1517
+ const [popover, setPopover] = useState(null);
1518
+ const prevStyleRef = useRef(null);
1519
+ useImperativeHandle(ref, () => popover, [popover]);
1520
+ usePopoverCloseObserver(popover, open, onClose);
1521
+ usePropBinding(popover, "open", open !== null && open !== void 0 ? open : false);
1522
+ usePropBinding(popover, "altitudeMode", altitudeMode);
1523
+ usePropBinding(popover, "lightDismissDisabled", lightDismissDisabled);
1524
+ usePropBinding(popover, "autoPanDisabled", autoPanDisabled);
1525
+ const positionAnchor = (_a = anchor !== null && anchor !== void 0 ? anchor : anchorId) !== null && _a !== void 0 ? _a : position;
1526
+ usePropBinding(popover, "positionAnchor", positionAnchor);
1527
+ useLayoutEffect(() => {
1528
+ if (!popover)
208
1529
  return;
209
- }
210
- let apiPromise = null;
211
- const loadApi = () => {
212
- if (apiPromise) return apiPromise;
213
- apiPromise = new Promise((resolve, reject) => {
214
- var _document$querySelect;
215
- const scriptElement = document.createElement("script");
216
- const urlParams = new URLSearchParams();
217
- for (const [key, value] of Object.entries(params)) {
218
- const urlParamName = key.replace(/[A-Z]/g, (t) => "_" + t[0].toLowerCase());
219
- urlParams.set(urlParamName, String(value));
1530
+ setValueForStyles(popover, style2 || null, prevStyleRef.current);
1531
+ prevStyleRef.current = style2 || null;
1532
+ }, [popover, style2]);
1533
+ return React__default.createElement(
1534
+ "gmp-popover",
1535
+ { ref: setPopover, className },
1536
+ headerContent && React__default.createElement("div", { slot: "header" }, headerContent),
1537
+ children
1538
+ );
1539
+ });
1540
+ Popover.displayName = "Popover";
1541
+ function usePopoverCloseObserver(popover, open, onClose) {
1542
+ const previousOpenState = useRef(void 0);
1543
+ const openPropRef = useRef(open);
1544
+ useEffect(() => {
1545
+ openPropRef.current = open;
1546
+ }, [open]);
1547
+ useEffect(() => {
1548
+ if (!popover || !onClose)
1549
+ return;
1550
+ const observer = new MutationObserver((mutations) => {
1551
+ for (const mutation of mutations) {
1552
+ if (mutation.type === "attributes" && mutation.attributeName === "open") {
1553
+ const isOpen = popover.hasAttribute("open");
1554
+ if (previousOpenState.current === true && !isOpen && openPropRef.current !== false) {
1555
+ onClose();
1556
+ }
1557
+ previousOpenState.current = isOpen;
220
1558
  }
221
- urlParams.set("loading", "async");
222
- urlParams.set("callback", "__googleMapsCallback__");
223
- scriptElement.async = true;
224
- scriptElement.src = MAPS_API_BASE_URL + `?` + urlParams.toString();
225
- scriptElement.nonce = ((_document$querySelect = document.querySelector("script[nonce]")) == null ? void 0 : _document$querySelect.nonce) || "";
226
- scriptElement.onerror = () => {
227
- this.loadingStatus = APILoadingStatus.FAILED;
228
- this.notifyLoadingStatusListeners();
229
- reject(new Error("The Google Maps JavaScript API could not load."));
230
- };
231
- window.__googleMapsCallback__ = () => {
232
- this.loadingStatus = APILoadingStatus.LOADED;
233
- this.notifyLoadingStatusListeners();
234
- resolve();
235
- };
236
- window.gm_authFailure = () => {
237
- this.loadingStatus = APILoadingStatus.AUTH_FAILURE;
238
- this.notifyLoadingStatusListeners();
239
- };
240
- this.loadingStatus = APILoadingStatus.LOADING;
241
- this.notifyLoadingStatusListeners();
242
- document.head.append(scriptElement);
243
- });
244
- return apiPromise;
245
- };
246
- google.maps.importLibrary = (libraryName) => loadApi().then(() => google.maps.importLibrary(libraryName));
247
- }
248
- /**
249
- * Calls all registered loadingStatusListeners after a status update.
250
- */
251
- static notifyLoadingStatusListeners() {
252
- for (const fn of this.listeners) {
253
- fn(this.loadingStatus);
254
- }
255
- }
256
- }
257
- GoogleMapsApiLoader.loadingStatus = APILoadingStatus.NOT_LOADED;
258
- GoogleMapsApiLoader.serializedApiParams = void 0;
259
- GoogleMapsApiLoader.listeners = [];
260
- const _excluded$3 = ["onLoad", "onError", "apiKey", "version", "libraries"], _excluded2$1 = ["children"];
261
- const DEFAULT_SOLUTION_CHANNEL = "GMP_visgl_rgmlibrary_v1_default";
262
- const APIProviderContext = React__default.createContext(null);
263
- function useMapInstances() {
264
- const [mapInstances, setMapInstances] = useState({});
265
- const addMapInstance = (mapInstance, id = "default") => {
266
- setMapInstances((instances) => _extends({}, instances, {
267
- [id]: mapInstance
268
- }));
269
- };
270
- const removeMapInstance = (id = "default") => {
271
- setMapInstances((_ref) => {
272
- let remaining = _objectWithoutPropertiesLoose(_ref, [id].map(_toPropertyKey));
273
- return remaining;
274
- });
275
- };
276
- const clearMapInstances = () => {
277
- setMapInstances({});
278
- };
279
- return {
280
- mapInstances,
281
- addMapInstance,
282
- removeMapInstance,
283
- clearMapInstances
284
- };
285
- }
286
- function useGoogleMapsApiLoader(props) {
287
- const {
288
- onLoad,
289
- onError,
290
- apiKey,
291
- version,
292
- libraries = []
293
- } = props, otherApiParams = _objectWithoutPropertiesLoose(props, _excluded$3);
294
- const [status, setStatus] = useState(GoogleMapsApiLoader.loadingStatus);
295
- const [loadedLibraries, addLoadedLibrary] = useReducer((loadedLibraries2, action) => {
296
- return loadedLibraries2[action.name] ? loadedLibraries2 : _extends({}, loadedLibraries2, {
297
- [action.name]: action.value
1559
+ }
298
1560
  });
299
- }, {});
300
- const librariesString = useMemo(() => libraries == null ? void 0 : libraries.join(","), [libraries]);
301
- const serializedParams = useMemo(() => JSON.stringify(_extends({
302
- apiKey,
303
- version
304
- }, otherApiParams)), [apiKey, version, otherApiParams]);
305
- const importLibrary = useCallback(async (name) => {
306
- var _google;
307
- if (loadedLibraries[name]) {
308
- return loadedLibraries[name];
309
- }
310
- if (!((_google = google) != null && (_google = _google.maps) != null && _google.importLibrary)) {
311
- throw new Error("[api-provider-internal] importLibrary was called before google.maps.importLibrary was defined.");
312
- }
313
- const res = await window.google.maps.importLibrary(name);
314
- addLoadedLibrary({
315
- name,
316
- value: res
1561
+ observer.observe(popover, {
1562
+ attributes: true,
1563
+ attributeFilter: ["open"]
317
1564
  });
318
- return res;
319
- }, [loadedLibraries]);
320
- useEffect(
321
- () => {
322
- (async () => {
323
- try {
324
- const params = _extends({
325
- key: apiKey
326
- }, otherApiParams);
327
- if (version) params.v = version;
328
- if ((librariesString == null ? void 0 : librariesString.length) > 0) params.libraries = librariesString;
329
- if (params.channel === void 0 || params.channel < 0 || params.channel > 999) delete params.channel;
330
- if (params.solutionChannel === void 0) params.solutionChannel = DEFAULT_SOLUTION_CHANNEL;
331
- else if (params.solutionChannel === "") delete params.solutionChannel;
332
- await GoogleMapsApiLoader.load(params, (status2) => setStatus(status2));
333
- for (const name of ["core", "maps", ...libraries]) {
334
- await importLibrary(name);
335
- }
336
- if (onLoad) {
337
- onLoad();
338
- }
339
- } catch (error) {
340
- if (onError) {
341
- onError(error);
342
- } else {
343
- console.error("<ApiProvider> failed to load the Google Maps JavaScript API", error);
344
- }
345
- }
346
- })();
347
- },
348
- // eslint-disable-next-line react-hooks/exhaustive-deps
349
- [apiKey, librariesString, serializedParams]
350
- );
351
- return {
352
- status,
353
- loadedLibraries,
354
- importLibrary
355
- };
1565
+ previousOpenState.current = popover.hasAttribute("open");
1566
+ return () => {
1567
+ observer.disconnect();
1568
+ };
1569
+ }, [popover, onClose]);
1570
+ }
1571
+ const shownMessages = /* @__PURE__ */ new Set();
1572
+ function logErrorOnce(...args) {
1573
+ const key = JSON.stringify(args);
1574
+ if (!shownMessages.has(key)) {
1575
+ shownMessages.add(key);
1576
+ console.error(...args);
1577
+ }
356
1578
  }
357
- const APIProvider = (props) => {
358
- const {
359
- children
360
- } = props, loaderProps = _objectWithoutPropertiesLoose(props, _excluded2$1);
361
- const {
362
- mapInstances,
363
- addMapInstance,
364
- removeMapInstance,
365
- clearMapInstances
366
- } = useMapInstances();
367
- const {
368
- status,
369
- loadedLibraries,
370
- importLibrary
371
- } = useGoogleMapsApiLoader(loaderProps);
372
- const contextValue = useMemo(() => ({
373
- mapInstances,
374
- addMapInstance,
375
- removeMapInstance,
376
- clearMapInstances,
377
- status,
378
- loadedLibraries,
379
- importLibrary
380
- }), [mapInstances, addMapInstance, removeMapInstance, clearMapInstances, status, loadedLibraries, importLibrary]);
381
- return /* @__PURE__ */ React__default.createElement(APIProviderContext.Provider, {
382
- value: contextValue
383
- }, children);
384
- };
385
1579
  function useMapEvents(map, props) {
386
1580
  for (const propName of eventPropNames) {
387
1581
  const handler = props[propName];
388
1582
  const eventType = propNameToEventType[propName];
389
1583
  useEffect(() => {
390
- if (!map) return;
391
- if (!handler) return;
1584
+ if (!map)
1585
+ return;
1586
+ if (!handler)
1587
+ return;
392
1588
  const listener = google.maps.event.addListener(map, eventType, (ev) => {
393
- handler(createMapEvent(eventType, map, ev));
1589
+ const mapEvent = createMapEvent(eventType, map, ev);
1590
+ if (mapEvent)
1591
+ handler(mapEvent);
394
1592
  });
395
1593
  return () => listener.remove();
396
1594
  }, [map, eventType, handler]);
397
1595
  }
398
1596
  }
399
1597
  function createMapEvent(type, map, srcEvent) {
1598
+ var _a;
400
1599
  const ev = {
401
1600
  type,
402
1601
  map,
@@ -414,32 +1613,25 @@ function createMapEvent(type, map, srcEvent) {
414
1613
  const bounds = map.getBounds();
415
1614
  if (!center || !bounds || !Number.isFinite(zoom)) {
416
1615
  console.warn("[createEvent] at least one of the values from the map returned undefined. This is not expected to happen. Please report an issue at https://github.com/visgl/react-google-maps/issues/new");
1616
+ return null;
417
1617
  }
418
1618
  camEvent.detail = {
419
- center: (center == null ? void 0 : center.toJSON()) || {
420
- lat: 0,
421
- lng: 0
422
- },
423
- zoom: zoom || 0,
1619
+ center: center.toJSON(),
1620
+ zoom,
424
1621
  heading,
425
1622
  tilt,
426
- bounds: (bounds == null ? void 0 : bounds.toJSON()) || {
427
- north: 90,
428
- east: 180,
429
- south: -90,
430
- west: -180
431
- }
1623
+ bounds: bounds.toJSON()
432
1624
  };
433
1625
  return camEvent;
434
1626
  } else if (mouseEventTypes.includes(type)) {
435
- var _srcEvent$latLng;
436
- if (!srcEvent) throw new Error("[createEvent] mouse events must provide a srcEvent");
1627
+ if (!srcEvent)
1628
+ throw new Error("[createEvent] mouse events must provide a srcEvent");
437
1629
  const mouseEvent = ev;
438
1630
  mouseEvent.domEvent = srcEvent.domEvent;
439
1631
  mouseEvent.stoppable = true;
440
1632
  mouseEvent.stop = () => srcEvent.stop();
441
1633
  mouseEvent.detail = {
442
- latLng: ((_srcEvent$latLng = srcEvent.latLng) == null ? void 0 : _srcEvent$latLng.toJSON()) || null,
1634
+ latLng: ((_a = srcEvent.latLng) === null || _a === void 0 ? void 0 : _a.toJSON()) || null,
443
1635
  placeId: srcEvent.placeId
444
1636
  };
445
1637
  return mouseEvent;
@@ -473,53 +1665,82 @@ const propNameToEventType = {
473
1665
  // updated.
474
1666
  onCameraChanged: "bounds_changed"
475
1667
  };
476
- const cameraEventTypes = ["bounds_changed", "center_changed", "heading_changed", "tilt_changed", "zoom_changed"];
477
- const mouseEventTypes = ["click", "contextmenu", "dblclick", "mousemove", "mouseout", "mouseover"];
1668
+ const cameraEventTypes = [
1669
+ "bounds_changed",
1670
+ "center_changed",
1671
+ "heading_changed",
1672
+ "tilt_changed",
1673
+ "zoom_changed"
1674
+ ];
1675
+ const mouseEventTypes = [
1676
+ "click",
1677
+ "contextmenu",
1678
+ "dblclick",
1679
+ "mousemove",
1680
+ "mouseout",
1681
+ "mouseover"
1682
+ ];
478
1683
  const eventPropNames = Object.keys(propNameToEventType);
479
- function useDeepCompareEffect(effect, deps) {
480
- const ref = useRef(void 0);
481
- if (!ref.current || !isDeepEqual(deps, ref.current)) {
482
- ref.current = deps;
483
- }
484
- useEffect(effect, ref.current);
485
- }
486
- const mapOptionKeys = /* @__PURE__ */ new Set(["backgroundColor", "clickableIcons", "controlSize", "disableDefaultUI", "disableDoubleClickZoom", "draggable", "draggableCursor", "draggingCursor", "fullscreenControl", "fullscreenControlOptions", "gestureHandling", "headingInteractionEnabled", "isFractionalZoomEnabled", "keyboardShortcuts", "mapTypeControl", "mapTypeControlOptions", "mapTypeId", "maxZoom", "minZoom", "noClear", "panControl", "panControlOptions", "restriction", "rotateControl", "rotateControlOptions", "scaleControl", "scaleControlOptions", "scrollwheel", "streetView", "streetViewControl", "streetViewControlOptions", "styles", "tiltInteractionEnabled", "zoomControl", "zoomControlOptions"]);
1684
+ const mapOptionKeys = /* @__PURE__ */ new Set([
1685
+ "backgroundColor",
1686
+ "clickableIcons",
1687
+ "controlSize",
1688
+ "disableDefaultUI",
1689
+ "disableDoubleClickZoom",
1690
+ "draggable",
1691
+ "draggableCursor",
1692
+ "draggingCursor",
1693
+ "fullscreenControl",
1694
+ "fullscreenControlOptions",
1695
+ "gestureHandling",
1696
+ "headingInteractionEnabled",
1697
+ "isFractionalZoomEnabled",
1698
+ "keyboardShortcuts",
1699
+ "mapTypeControl",
1700
+ "mapTypeControlOptions",
1701
+ "mapTypeId",
1702
+ "maxZoom",
1703
+ "minZoom",
1704
+ "noClear",
1705
+ "panControl",
1706
+ "panControlOptions",
1707
+ "restriction",
1708
+ "rotateControl",
1709
+ "rotateControlOptions",
1710
+ "scaleControl",
1711
+ "scaleControlOptions",
1712
+ "scrollwheel",
1713
+ "streetView",
1714
+ "streetViewControl",
1715
+ "streetViewControlOptions",
1716
+ "styles",
1717
+ "tiltInteractionEnabled",
1718
+ "zoomControl",
1719
+ "zoomControlOptions"
1720
+ ]);
487
1721
  function useMapOptions(map, mapProps) {
488
1722
  const mapOptions = {};
489
- const keys = Object.keys(mapProps);
490
- for (const key of keys) {
491
- if (!mapOptionKeys.has(key)) continue;
1723
+ const keys2 = Object.keys(mapProps);
1724
+ for (const key of keys2) {
1725
+ if (!mapOptionKeys.has(key))
1726
+ continue;
492
1727
  mapOptions[key] = mapProps[key];
493
1728
  }
494
1729
  useDeepCompareEffect(() => {
495
- if (!map) return;
1730
+ if (!map)
1731
+ return;
496
1732
  map.setOptions(mapOptions);
497
1733
  }, [mapOptions]);
498
1734
  }
499
- function useApiLoadingStatus() {
500
- var _useContext;
501
- return ((_useContext = useContext(APIProviderContext)) == null ? void 0 : _useContext.status) || APILoadingStatus.NOT_LOADED;
502
- }
503
1735
  function useDeckGLCameraUpdate(map, props) {
504
- const {
505
- viewport,
506
- viewState
507
- } = props;
1736
+ const { viewport, viewState } = props;
508
1737
  const isDeckGlControlled = !!viewport;
509
1738
  useLayoutEffect(() => {
510
- if (!map || !viewState) return;
511
- const {
512
- latitude,
513
- longitude,
514
- bearing: heading,
515
- pitch: tilt,
516
- zoom
517
- } = viewState;
1739
+ if (!map || !viewState)
1740
+ return;
1741
+ const { latitude, longitude, bearing: heading, pitch: tilt, zoom } = viewState;
518
1742
  map.moveCamera({
519
- center: {
520
- lat: latitude,
521
- lng: longitude
522
- },
1743
+ center: { lat: latitude, lng: longitude },
523
1744
  heading,
524
1745
  tilt,
525
1746
  zoom: zoom + 1
@@ -528,14 +1749,70 @@ function useDeckGLCameraUpdate(map, props) {
528
1749
  return isDeckGlControlled;
529
1750
  }
530
1751
  function isLatLngLiteral(obj) {
531
- if (!obj || typeof obj !== "object") return false;
532
- if (!("lat" in obj && "lng" in obj)) return false;
1752
+ if (!obj || typeof obj !== "object")
1753
+ return false;
1754
+ if (!("lat" in obj && "lng" in obj))
1755
+ return false;
533
1756
  return Number.isFinite(obj.lat) && Number.isFinite(obj.lng);
534
1757
  }
1758
+ function latLngEquals(a, b) {
1759
+ if (!a || !b)
1760
+ return false;
1761
+ const A = toLatLngLiteral(a);
1762
+ const B = toLatLngLiteral(b);
1763
+ if (A.lat !== B.lat || A.lng !== B.lng)
1764
+ return false;
1765
+ return true;
1766
+ }
535
1767
  function toLatLngLiteral(obj) {
536
- if (isLatLngLiteral(obj)) return obj;
1768
+ if (isLatLngLiteral(obj))
1769
+ return obj;
537
1770
  return obj.toJSON();
538
1771
  }
1772
+ function toLatLngBoundsLiteral(obj) {
1773
+ if ("north" in obj && "south" in obj && "east" in obj && "west" in obj) {
1774
+ return obj;
1775
+ }
1776
+ const ne = obj.getNorthEast().toJSON();
1777
+ const sw = obj.getSouthWest().toJSON();
1778
+ return {
1779
+ north: ne.lat,
1780
+ east: ne.lng,
1781
+ south: sw.lat,
1782
+ west: sw.lng
1783
+ };
1784
+ }
1785
+ function boundsEquals(a, b) {
1786
+ if (!a || !b)
1787
+ return false;
1788
+ const A = toLatLngBoundsLiteral(a);
1789
+ const B = toLatLngBoundsLiteral(b);
1790
+ return A.north === B.north && A.south === B.south && A.east === B.east && A.west === B.west;
1791
+ }
1792
+ function pathEquals(a, b) {
1793
+ if (!a || !b)
1794
+ return a === b;
1795
+ const arrayB = "getArray" in b ? b.getArray() : b;
1796
+ if (a.length !== arrayB.length)
1797
+ return false;
1798
+ for (let i = 0; i < a.length; i++) {
1799
+ if (!latLngEquals(a[i], arrayB[i]))
1800
+ return false;
1801
+ }
1802
+ return true;
1803
+ }
1804
+ function pathsEquals(a, b) {
1805
+ if (!a || !b)
1806
+ return a === b;
1807
+ const arrayB = "getArray" in b ? b.getArray().map((inner) => inner.getArray()) : b;
1808
+ if (a.length !== arrayB.length)
1809
+ return false;
1810
+ for (let i = 0; i < a.length; i++) {
1811
+ if (!pathEquals(a[i], arrayB[i]))
1812
+ return false;
1813
+ }
1814
+ return true;
1815
+ }
539
1816
  function useMapCameraParams(map, cameraStateRef, mapProps) {
540
1817
  const center = mapProps.center ? toLatLngLiteral(mapProps.center) : null;
541
1818
  let lat = null;
@@ -548,14 +1825,12 @@ function useMapCameraParams(map, cameraStateRef, mapProps) {
548
1825
  const heading = Number.isFinite(mapProps.heading) ? mapProps.heading : null;
549
1826
  const tilt = Number.isFinite(mapProps.tilt) ? mapProps.tilt : null;
550
1827
  useLayoutEffect(() => {
551
- if (!map) return;
1828
+ if (!map)
1829
+ return;
552
1830
  const nextCamera = {};
553
1831
  let needsUpdate = false;
554
1832
  if (lat !== null && lng !== null && (cameraStateRef.current.center.lat !== lat || cameraStateRef.current.center.lng !== lng)) {
555
- nextCamera.center = {
556
- lat,
557
- lng
558
- };
1833
+ nextCamera.center = { lat, lng };
559
1834
  needsUpdate = true;
560
1835
  }
561
1836
  if (zoom !== null && cameraStateRef.current.zoom !== zoom) {
@@ -592,38 +1867,31 @@ const AuthFailureMessage = () => {
592
1867
  background: "#dddddd",
593
1868
  padding: "1rem 1.5rem"
594
1869
  };
595
- return /* @__PURE__ */ React__default.createElement("div", {
596
- style: style2
597
- }, /* @__PURE__ */ React__default.createElement("h2", null, "Error: AuthFailure"), /* @__PURE__ */ React__default.createElement("p", null, "A problem with your API key prevents the map from rendering correctly. Please make sure the value of the ", /* @__PURE__ */ React__default.createElement("code", null, "APIProvider.apiKey"), " prop is correct. Check the error-message in the console for further details."));
1870
+ return React__default.createElement(
1871
+ "div",
1872
+ { style: style2 },
1873
+ React__default.createElement("h2", null, "Error: AuthFailure"),
1874
+ React__default.createElement(
1875
+ "p",
1876
+ null,
1877
+ "A problem with your API key prevents the map from rendering correctly. Please make sure the value of the ",
1878
+ React__default.createElement("code", null, "APIProvider.apiKey"),
1879
+ " prop is correct. Check the error-message in the console for further details."
1880
+ )
1881
+ );
598
1882
  };
599
- function useCallbackRef() {
600
- const [el, setEl] = useState(null);
601
- const ref = useCallback((value) => setEl(value), [setEl]);
602
- return [el, ref];
603
- }
604
- function useApiIsLoaded() {
605
- const status = useApiLoadingStatus();
606
- return status === APILoadingStatus.LOADED;
607
- }
608
- function useForceUpdate() {
609
- const [, forceUpdate] = useReducer((x) => x + 1, 0);
610
- return forceUpdate;
611
- }
612
1883
  function handleBoundsChange(map, ref) {
613
1884
  const center = map.getCenter();
614
1885
  const zoom = map.getZoom();
615
1886
  const heading = map.getHeading() || 0;
616
1887
  const tilt = map.getTilt() || 0;
617
- const bounds = map.getBounds();
618
- if (!center || !bounds || !Number.isFinite(zoom)) {
1888
+ if (!center || !Number.isFinite(zoom)) {
619
1889
  console.warn("[useTrackedCameraState] at least one of the values from the map returned undefined. This is not expected to happen. Please report an issue at https://github.com/visgl/react-google-maps/issues/new");
1890
+ return;
620
1891
  }
621
1892
  Object.assign(ref.current, {
622
- center: (center == null ? void 0 : center.toJSON()) || {
623
- lat: 0,
624
- lng: 0
625
- },
626
- zoom: zoom || 0,
1893
+ center: center.toJSON(),
1894
+ zoom,
627
1895
  heading,
628
1896
  tilt
629
1897
  });
@@ -631,16 +1899,14 @@ function handleBoundsChange(map, ref) {
631
1899
  function useTrackedCameraStateRef(map) {
632
1900
  const forceUpdate = useForceUpdate();
633
1901
  const ref = useRef({
634
- center: {
635
- lat: 0,
636
- lng: 0
637
- },
1902
+ center: { lat: 0, lng: 0 },
638
1903
  heading: 0,
639
1904
  tilt: 0,
640
1905
  zoom: 0
641
1906
  });
642
1907
  useEffect(() => {
643
- if (!map) return;
1908
+ if (!map)
1909
+ return;
644
1910
  const listener = google.maps.event.addListener(map, "bounds_changed", () => {
645
1911
  handleBoundsChange(map, ref);
646
1912
  forceUpdate();
@@ -649,17 +1915,18 @@ function useTrackedCameraStateRef(map) {
649
1915
  }, [map, forceUpdate]);
650
1916
  return ref;
651
1917
  }
652
- const _excluded$2 = ["id", "defaultBounds", "defaultCenter", "defaultZoom", "defaultHeading", "defaultTilt", "reuseMaps", "renderingType", "colorScheme"], _excluded2 = ["padding"];
653
1918
  class CachedMapStack {
654
1919
  static has(key) {
655
1920
  return this.entries[key] && this.entries[key].length > 0;
656
1921
  }
657
1922
  static pop(key) {
658
- if (!this.entries[key]) return null;
1923
+ if (!this.entries[key])
1924
+ return null;
659
1925
  return this.entries[key].pop() || null;
660
1926
  }
661
1927
  static push(key, value) {
662
- if (!this.entries[key]) this.entries[key] = [];
1928
+ if (!this.entries[key])
1929
+ this.entries[key] = [];
663
1930
  this.entries[key].push(value);
664
1931
  }
665
1932
  }
@@ -669,79 +1936,75 @@ function useMapInstance(props, context) {
669
1936
  const [map, setMap] = useState(null);
670
1937
  const [container, containerRef] = useCallbackRef();
671
1938
  const cameraStateRef = useTrackedCameraStateRef(map);
672
- const {
673
- id,
674
- defaultBounds,
675
- defaultCenter,
676
- defaultZoom,
677
- defaultHeading,
678
- defaultTilt,
679
- reuseMaps,
680
- renderingType,
681
- colorScheme
682
- } = props, mapOptions = _objectWithoutPropertiesLoose(props, _excluded$2);
1939
+ const { id, defaultBounds, defaultCenter, defaultZoom, defaultHeading, defaultTilt, reuseMaps, renderingType, colorScheme } = props, mapOptions = __rest(props, ["id", "defaultBounds", "defaultCenter", "defaultZoom", "defaultHeading", "defaultTilt", "reuseMaps", "renderingType", "colorScheme"]);
683
1940
  const hasZoom = props.zoom !== void 0 || props.defaultZoom !== void 0;
684
1941
  const hasCenter = props.center !== void 0 || props.defaultCenter !== void 0;
685
1942
  if (!defaultBounds && (!hasZoom || !hasCenter)) {
686
1943
  console.warn("<Map> component is missing configuration. You have to provide zoom and center (via the `zoom`/`defaultZoom` and `center`/`defaultCenter` props) or specify the region to show using `defaultBounds`. See https://visgl.github.io/react-google-maps/docs/api-reference/components/map#required");
687
1944
  }
688
- if (!mapOptions.center && defaultCenter) mapOptions.center = defaultCenter;
689
- if (!mapOptions.zoom && Number.isFinite(defaultZoom)) mapOptions.zoom = defaultZoom;
690
- if (!mapOptions.heading && Number.isFinite(defaultHeading)) mapOptions.heading = defaultHeading;
691
- if (!mapOptions.tilt && Number.isFinite(defaultTilt)) mapOptions.tilt = defaultTilt;
692
- for (const key of Object.keys(mapOptions)) if (mapOptions[key] === void 0) delete mapOptions[key];
1945
+ if (!mapOptions.center && defaultCenter)
1946
+ mapOptions.center = defaultCenter;
1947
+ if (!mapOptions.zoom && Number.isFinite(defaultZoom))
1948
+ mapOptions.zoom = defaultZoom;
1949
+ if (!mapOptions.heading && Number.isFinite(defaultHeading))
1950
+ mapOptions.heading = defaultHeading;
1951
+ if (!mapOptions.tilt && Number.isFinite(defaultTilt))
1952
+ mapOptions.tilt = defaultTilt;
1953
+ const customIds = mapOptions.internalUsageAttributionIds;
1954
+ if (customIds == null) {
1955
+ mapOptions.internalUsageAttributionIds = context.internalUsageAttributionIds;
1956
+ } else {
1957
+ mapOptions.internalUsageAttributionIds = [
1958
+ ...context.internalUsageAttributionIds || [],
1959
+ ...customIds
1960
+ ];
1961
+ }
1962
+ for (const key of Object.keys(mapOptions))
1963
+ if (mapOptions[key] === void 0)
1964
+ delete mapOptions[key];
693
1965
  const savedMapStateRef = useRef(void 0);
1966
+ const reuseMapsRef = useRef(reuseMaps);
1967
+ useEffect(() => {
1968
+ reuseMapsRef.current = reuseMaps;
1969
+ }, [reuseMaps]);
694
1970
  useEffect(
695
1971
  () => {
696
- if (!container || !apiIsLoaded) return;
697
- const {
698
- addMapInstance,
699
- removeMapInstance
700
- } = context;
701
- const {
702
- mapId
703
- } = props;
1972
+ if (!container || !apiIsLoaded)
1973
+ return;
1974
+ const { addMapInstance, removeMapInstance } = context;
1975
+ const { mapId } = props;
704
1976
  const cacheKey = `${mapId || "default"}:${renderingType || "default"}:${colorScheme || "LIGHT"}`;
705
1977
  let mapDiv;
706
1978
  let map2;
707
- if (reuseMaps && CachedMapStack.has(cacheKey)) {
708
- map2 = CachedMapStack.pop(cacheKey);
709
- mapDiv = map2.getDiv();
1979
+ const cachedMap = reuseMapsRef.current && CachedMapStack.has(cacheKey) ? CachedMapStack.pop(cacheKey) : null;
1980
+ const cachedMapDiv = cachedMap === null || cachedMap === void 0 ? void 0 : cachedMap.getDiv();
1981
+ const reusedMap = cachedMap && cachedMapDiv instanceof Node ? cachedMap : null;
1982
+ if (reusedMap) {
1983
+ map2 = reusedMap;
1984
+ mapDiv = cachedMapDiv;
710
1985
  container.appendChild(mapDiv);
711
1986
  map2.setOptions(mapOptions);
712
- setTimeout(() => map2.setCenter(map2.getCenter()), 0);
1987
+ setTimeout(() => map2.moveCamera({}), 0);
713
1988
  } else {
1989
+ if (cachedMap)
1990
+ google.maps.event.clearInstanceListeners(cachedMap);
714
1991
  mapDiv = document.createElement("div");
715
1992
  mapDiv.style.height = "100%";
716
1993
  container.appendChild(mapDiv);
717
- map2 = new google.maps.Map(mapDiv, _extends({}, mapOptions, renderingType ? {
718
- renderingType
719
- } : {}, colorScheme ? {
720
- colorScheme
721
- } : {}));
1994
+ map2 = new google.maps.Map(mapDiv, Object.assign(Object.assign(Object.assign({}, mapOptions), renderingType ? { renderingType } : {}), colorScheme ? { colorScheme } : {}));
722
1995
  }
723
1996
  setMap(map2);
724
1997
  addMapInstance(map2, id);
725
1998
  if (defaultBounds) {
726
- const {
727
- padding
728
- } = defaultBounds, defBounds = _objectWithoutPropertiesLoose(defaultBounds, _excluded2);
1999
+ const { padding } = defaultBounds, defBounds = __rest(defaultBounds, ["padding"]);
729
2000
  map2.fitBounds(defBounds, padding);
730
2001
  } else if (!hasZoom || !hasCenter) {
731
- map2.fitBounds({
732
- east: 180,
733
- west: -180,
734
- south: -90,
735
- north: 90
736
- });
2002
+ map2.fitBounds({ east: 180, west: -180, south: -90, north: 90 });
737
2003
  }
738
2004
  if (savedMapStateRef.current) {
739
- const {
740
- mapId: savedMapId,
741
- cameraState: savedCameraState
742
- } = savedMapStateRef.current;
2005
+ const { mapId: savedMapId, cameraState: savedCameraState } = savedMapStateRef.current;
743
2006
  if (savedMapId !== mapId) {
744
- map2.setOptions(savedCameraState);
2007
+ map2.moveCamera(savedCameraState);
745
2008
  }
746
2009
  }
747
2010
  return () => {
@@ -751,7 +2014,7 @@ function useMapInstance(props, context) {
751
2014
  cameraState: cameraStateRef.current
752
2015
  };
753
2016
  mapDiv.remove();
754
- if (reuseMaps) {
2017
+ if (reuseMapsRef.current) {
755
2018
  CachedMapStack.push(cacheKey, map2);
756
2019
  } else {
757
2020
  google.maps.event.clearInstanceListeners(map2);
@@ -779,15 +2042,10 @@ function useMapInstance(props, context) {
779
2042
  return [map, containerRef, cameraStateRef];
780
2043
  }
781
2044
  const GoogleMapsContext = React__default.createContext(null);
782
- const Map = (props) => {
783
- const {
784
- children,
785
- id,
786
- className,
787
- style: style2
788
- } = props;
2045
+ const Map$1 = (props) => {
2046
+ const { children, id, className, style: style2 } = props;
789
2047
  const context = useContext(APIProviderContext);
790
- const loadingStatus = useApiLoadingStatus();
2048
+ const loadingStatus2 = useApiLoadingStatus();
791
2049
  if (!context) {
792
2050
  throw new Error("<Map> can only be used inside an <ApiProvider> component.");
793
2051
  }
@@ -798,11 +2056,10 @@ const Map = (props) => {
798
2056
  const isDeckGlControlled = useDeckGLCameraUpdate(map, props);
799
2057
  const isControlledExternally = !!props.controlled;
800
2058
  useEffect(() => {
801
- if (!map) return;
2059
+ if (!map)
2060
+ return;
802
2061
  if (isDeckGlControlled) {
803
- map.setOptions({
804
- disableDefaultUI: true
805
- });
2062
+ map.setOptions({ disableDefaultUI: true });
806
2063
  }
807
2064
  if (isDeckGlControlled || isControlledExternally) {
808
2065
  map.setOptions({
@@ -816,7 +2073,13 @@ const Map = (props) => {
816
2073
  keyboardShortcuts: props.keyboardShortcuts
817
2074
  });
818
2075
  };
819
- }, [map, isDeckGlControlled, isControlledExternally, props.gestureHandling, props.keyboardShortcuts]);
2076
+ }, [
2077
+ map,
2078
+ isDeckGlControlled,
2079
+ isControlledExternally,
2080
+ props.gestureHandling,
2081
+ props.keyboardShortcuts
2082
+ ]);
820
2083
  const center = props.center ? toLatLngLiteral(props.center) : null;
821
2084
  let lat = null;
822
2085
  let lng = null;
@@ -825,348 +2088,352 @@ const Map = (props) => {
825
2088
  lng = center.lng;
826
2089
  }
827
2090
  const cameraOptions = useMemo(() => {
828
- var _lat, _lng, _props$zoom, _props$heading, _props$tilt;
2091
+ var _a, _b, _c;
829
2092
  return {
830
- center: {
831
- lat: (_lat = lat) != null ? _lat : 0,
832
- lng: (_lng = lng) != null ? _lng : 0
833
- },
834
- zoom: (_props$zoom = props.zoom) != null ? _props$zoom : 0,
835
- heading: (_props$heading = props.heading) != null ? _props$heading : 0,
836
- tilt: (_props$tilt = props.tilt) != null ? _props$tilt : 0
2093
+ center: { lat: lat !== null && lat !== void 0 ? lat : 0, lng: lng !== null && lng !== void 0 ? lng : 0 },
2094
+ zoom: (_a = props.zoom) !== null && _a !== void 0 ? _a : 0,
2095
+ heading: (_b = props.heading) !== null && _b !== void 0 ? _b : 0,
2096
+ tilt: (_c = props.tilt) !== null && _c !== void 0 ? _c : 0
837
2097
  };
838
2098
  }, [lat, lng, props.zoom, props.heading, props.tilt]);
839
2099
  useLayoutEffect(() => {
840
- if (!map || !isControlledExternally) return;
2100
+ if (!map || !isControlledExternally)
2101
+ return;
841
2102
  map.moveCamera(cameraOptions);
842
2103
  const listener = map.addListener("bounds_changed", () => {
843
2104
  map.moveCamera(cameraOptions);
844
2105
  });
845
2106
  return () => listener.remove();
846
2107
  }, [map, isControlledExternally, cameraOptions]);
847
- const combinedStyle = useMemo(() => _extends({
2108
+ const combinedStyle = useMemo(() => Object.assign({
848
2109
  width: "100%",
849
2110
  height: "100%",
850
2111
  position: "relative",
851
2112
  // when using deckgl, the map should be sent to the back
852
2113
  zIndex: isDeckGlControlled ? -1 : 0
853
2114
  }, style2), [style2, isDeckGlControlled]);
854
- const contextValue = useMemo(() => ({
855
- map
856
- }), [map]);
857
- if (loadingStatus === APILoadingStatus.AUTH_FAILURE) {
858
- return /* @__PURE__ */ React__default.createElement("div", {
859
- style: _extends({
860
- position: "relative"
861
- }, className ? {} : combinedStyle),
862
- className
863
- }, /* @__PURE__ */ React__default.createElement(AuthFailureMessage, null));
864
- }
865
- return /* @__PURE__ */ React__default.createElement("div", _extends({
866
- ref: mapRef,
867
- "data-testid": "map",
868
- style: className ? void 0 : combinedStyle,
869
- className
870
- }, id ? {
871
- id
872
- } : {}), map ? /* @__PURE__ */ React__default.createElement(GoogleMapsContext.Provider, {
873
- value: contextValue
874
- }, children) : null);
875
- };
876
- Map.deckGLViewProps = true;
877
- const shownMessages = /* @__PURE__ */ new Set();
878
- function logErrorOnce(...args) {
879
- const key = JSON.stringify(args);
880
- if (!shownMessages.has(key)) {
881
- shownMessages.add(key);
882
- console.error(...args);
2115
+ const contextValue = useMemo(() => ({ map }), [map]);
2116
+ if (loadingStatus2 === APILoadingStatus.AUTH_FAILURE) {
2117
+ return React__default.createElement(
2118
+ "div",
2119
+ { style: Object.assign({ position: "relative" }, className ? {} : combinedStyle), className },
2120
+ React__default.createElement(AuthFailureMessage, null)
2121
+ );
883
2122
  }
884
- }
2123
+ return React__default.createElement("div", Object.assign({ ref: mapRef, "data-testid": "map", style: className ? void 0 : combinedStyle, className }, id ? { id } : {}), map ? React__default.createElement(GoogleMapsContext.Provider, { value: contextValue }, children) : null);
2124
+ };
2125
+ Map$1.deckGLViewProps = true;
885
2126
  const useMap = (id = null) => {
886
2127
  const ctx = useContext(APIProviderContext);
887
- const {
888
- map
889
- } = useContext(GoogleMapsContext) || {};
2128
+ const { map } = useContext(GoogleMapsContext) || {};
890
2129
  if (ctx === null) {
891
2130
  logErrorOnce("useMap(): failed to retrieve APIProviderContext. Make sure that the <APIProvider> component exists and that the component you are calling `useMap()` from is a sibling of the <APIProvider>.");
892
2131
  return null;
893
2132
  }
894
- const {
895
- mapInstances
896
- } = ctx;
897
- if (id !== null) return mapInstances[id] || null;
898
- if (map) return map;
2133
+ const { mapInstances } = ctx;
2134
+ if (id !== null)
2135
+ return mapInstances[id] || null;
2136
+ if (map)
2137
+ return map;
899
2138
  return mapInstances["default"] || null;
900
2139
  };
901
- function useMapsLibrary(name) {
902
- const apiIsLoaded = useApiIsLoaded();
903
- const ctx = useContext(APIProviderContext);
904
- useEffect(() => {
905
- if (!apiIsLoaded || !ctx) return;
906
- void ctx.importLibrary(name);
907
- }, [apiIsLoaded, ctx, name]);
908
- return (ctx == null ? void 0 : ctx.loadedLibraries[name]) || null;
909
- }
2140
+ const noop = () => {
2141
+ };
910
2142
  function useMapsEventListener(target, name, callback) {
2143
+ const eventFn = useEffectEvent(callback !== null && callback !== void 0 ? callback : noop);
2144
+ const isCallbackDefined = Boolean(callback);
911
2145
  useEffect(() => {
912
- if (!target || !name || !callback) return;
913
- const listener = google.maps.event.addListener(target, name, callback);
2146
+ if (!target || !name || !isCallbackDefined)
2147
+ return;
2148
+ const listener = google.maps.event.addListener(target, name, eventFn);
914
2149
  return () => listener.remove();
915
- }, [target, name, callback]);
2150
+ }, [target, name, isCallbackDefined]);
916
2151
  }
917
- function usePropBinding(object, prop, value) {
918
- useEffect(() => {
919
- if (!object) return;
920
- object[prop] = value;
921
- }, [object, prop, value]);
2152
+ class GlobalStyleManager {
2153
+ constructor() {
2154
+ this.renderedStyles = /* @__PURE__ */ new Set();
2155
+ this.styleElement = null;
2156
+ }
2157
+ getStyleElement() {
2158
+ if (!this.styleElement) {
2159
+ this.styleElement = document.createElement("style");
2160
+ this.styleElement.setAttribute("data-rgm-anchor-styles", "");
2161
+ document.head.appendChild(this.styleElement);
2162
+ }
2163
+ return this.styleElement;
2164
+ }
2165
+ addAdvancedMarkerPointerEventsOverwrite() {
2166
+ if (this.renderedStyles.has("marker-pointer-events")) {
2167
+ return;
2168
+ }
2169
+ const styleElement = this.getStyleElement();
2170
+ styleElement.textContent += `
2171
+ gmp-advanced-marker[data-origin='rgm'] {
2172
+ pointer-events: none !important;
2173
+ }
2174
+ `;
2175
+ this.renderedStyles.add("marker-pointer-events");
2176
+ }
2177
+ cleanup() {
2178
+ if (this.styleElement) {
2179
+ this.styleElement.remove();
2180
+ this.styleElement = null;
2181
+ this.renderedStyles.clear();
2182
+ }
2183
+ }
922
2184
  }
923
- function useDomEventListener(target, name, callback) {
924
- useEffect(() => {
925
- if (!target || !name || !callback) return;
926
- target.addEventListener(name, callback);
927
- return () => target.removeEventListener(name, callback);
928
- }, [target, name, callback]);
2185
+ const globalStyleManager = new GlobalStyleManager();
2186
+ function isVersionGreaterEqual(major, minor) {
2187
+ var _a;
2188
+ if (!((_a = google === null || google === void 0 ? void 0 : google.maps) === null || _a === void 0 ? void 0 : _a.version))
2189
+ return void 0;
2190
+ const version = google.maps.version.split(".");
2191
+ const currentMajor = parseInt(version[0], 10);
2192
+ const currentMinor = parseInt(version[1], 10);
2193
+ return currentMajor > major || currentMajor === major && currentMinor >= minor;
929
2194
  }
2195
+ const AdvancedMarkerContext = React__default.createContext(null);
2196
+ const AdvancedMarkerAnchorPoint = {
2197
+ BOTTOM: ["50%", "100%"]
2198
+ };
2199
+ const AdvancedMarker = forwardRef((props, ref) => {
2200
+ const { children, style: style2, className, anchorPoint } = props;
2201
+ const [marker, contentContainer] = useAdvancedMarker(props);
2202
+ const advancedMarkerContextValue = useMemo(() => marker ? { marker } : null, [marker]);
2203
+ useImperativeHandle(ref, () => marker, [marker]);
2204
+ if (!contentContainer)
2205
+ return null;
2206
+ return React__default.createElement(AdvancedMarkerContext.Provider, { value: advancedMarkerContextValue }, createPortal(React__default.createElement(MarkerContent, { anchorPoint, styles: style2, className }, children), contentContainer));
2207
+ });
2208
+ AdvancedMarker.displayName = "AdvancedMarker";
930
2209
  function isAdvancedMarker(marker) {
931
2210
  return marker.content !== void 0;
932
2211
  }
933
2212
  function isElementNode(node) {
934
2213
  return node.nodeType === Node.ELEMENT_NODE;
935
2214
  }
936
- const AdvancedMarkerContext = React__default.createContext(null);
937
- const AdvancedMarkerAnchorPoint = {
938
- BOTTOM: ["50%", "100%"]
939
- };
940
- const MarkerContent = ({
941
- children,
942
- styles: styles2,
943
- className,
944
- anchorPoint
945
- }) => {
946
- const [xTranslation, yTranslation] = anchorPoint != null ? anchorPoint : AdvancedMarkerAnchorPoint["BOTTOM"];
947
- let xTranslationFlipped = `-${xTranslation}`;
948
- let yTranslationFlipped = `-${yTranslation}`;
949
- if (xTranslation.trimStart().startsWith("-")) {
950
- xTranslationFlipped = xTranslation.substring(1);
951
- }
952
- if (yTranslation.trimStart().startsWith("-")) {
953
- yTranslationFlipped = yTranslation.substring(1);
954
- }
955
- const transformStyle = `translate(50%, 100%) translate(${xTranslationFlipped}, ${yTranslationFlipped})`;
956
- return (
957
- // anchoring container
958
- /* @__PURE__ */ React__default.createElement("div", {
959
- style: {
960
- transform: transformStyle
961
- }
962
- }, /* @__PURE__ */ React__default.createElement("div", {
963
- className,
964
- style: styles2
965
- }, children))
966
- );
2215
+ const MarkerContent = ({ children, styles: styles2, className }) => {
2216
+ return React__default.createElement("div", { className, style: styles2 }, children);
967
2217
  };
968
2218
  function useAdvancedMarker(props) {
969
2219
  const [marker, setMarker] = useState(null);
970
2220
  const [contentContainer, setContentContainer] = useState(null);
971
2221
  const map = useMap();
972
2222
  const markerLibrary = useMapsLibrary("marker");
973
- const {
974
- children,
975
- onClick,
976
- className,
977
- onMouseEnter,
978
- onMouseLeave,
979
- onDrag,
980
- onDragStart,
981
- onDragEnd,
982
- collisionBehavior,
983
- clickable,
984
- draggable,
985
- position,
986
- title: title2,
987
- zIndex
988
- } = props;
2223
+ const { children, onClick, onKeyDown, onKeyUp, className, onMouseEnter, onMouseLeave, onDrag, onDragStart, onDragEnd, collisionBehavior, clickable, draggable, position, title: title2, zIndex, anchorPoint, anchorLeft, anchorTop } = props;
989
2224
  const numChildren = Children.count(children);
990
2225
  useEffect(() => {
991
- if (!map || !markerLibrary) return;
2226
+ if (!map || !markerLibrary)
2227
+ return;
992
2228
  const newMarker = new markerLibrary.AdvancedMarkerElement();
993
2229
  newMarker.map = map;
994
2230
  setMarker(newMarker);
995
2231
  let contentElement = null;
996
2232
  if (numChildren > 0) {
997
2233
  contentElement = document.createElement("div");
998
- contentElement.isCustomMarker = true;
999
2234
  newMarker.content = contentElement;
1000
2235
  setContentContainer(contentElement);
1001
2236
  }
1002
2237
  return () => {
1003
- var _contentElement;
1004
2238
  newMarker.map = null;
1005
- (_contentElement = contentElement) == null || _contentElement.remove();
2239
+ contentElement === null || contentElement === void 0 ? void 0 : contentElement.remove();
1006
2240
  setMarker(null);
1007
2241
  setContentContainer(null);
1008
2242
  };
1009
2243
  }, [map, markerLibrary, numChildren]);
1010
2244
  useEffect(() => {
1011
- if (!marker || !marker.content || numChildren > 0) return;
1012
- marker.content.className = className || "";
2245
+ if (!(marker === null || marker === void 0 ? void 0 : marker.content) || !isElementNode(marker.content) || numChildren > 0)
2246
+ return;
2247
+ marker.content.className = className !== null && className !== void 0 ? className : "";
1013
2248
  }, [marker, className, numChildren]);
2249
+ useAdvancedMarkerAnchoring(marker, anchorPoint, anchorLeft, anchorTop, numChildren > 0);
1014
2250
  usePropBinding(marker, "position", position);
1015
- usePropBinding(marker, "title", title2 != null ? title2 : "");
2251
+ usePropBinding(marker, "title", title2 !== null && title2 !== void 0 ? title2 : "");
1016
2252
  usePropBinding(marker, "zIndex", zIndex);
1017
2253
  usePropBinding(marker, "collisionBehavior", collisionBehavior);
1018
2254
  useEffect(() => {
1019
- if (!marker) return;
1020
- if (draggable !== void 0) marker.gmpDraggable = draggable;
1021
- else if (onDrag || onDragStart || onDragEnd) marker.gmpDraggable = true;
1022
- else marker.gmpDraggable = false;
2255
+ if (!marker)
2256
+ return;
2257
+ if (draggable !== void 0)
2258
+ marker.gmpDraggable = draggable;
2259
+ else if (onDrag || onDragStart || onDragEnd)
2260
+ marker.gmpDraggable = true;
2261
+ else
2262
+ marker.gmpDraggable = false;
1023
2263
  }, [marker, draggable, onDrag, onDragEnd, onDragStart]);
1024
2264
  useEffect(() => {
1025
- if (!marker) return;
1026
- const gmpClickable = clickable !== void 0 || Boolean(onClick) || Boolean(onMouseEnter) || Boolean(onMouseLeave);
2265
+ if (!marker)
2266
+ return;
2267
+ const gmpClickable = clickable !== void 0 ? clickable : Boolean(onClick) || Boolean(onKeyDown) || Boolean(onKeyUp) || Boolean(onMouseEnter) || Boolean(onMouseLeave);
1027
2268
  marker.gmpClickable = gmpClickable;
1028
- if (gmpClickable && marker != null && marker.content && isElementNode(marker.content)) {
1029
- marker.content.style.pointerEvents = "none";
1030
- if (marker.content.firstElementChild) {
1031
- marker.content.firstElementChild.style.pointerEvents = "all";
1032
- }
2269
+ if ((marker === null || marker === void 0 ? void 0 : marker.content) && isElementNode(marker.content)) {
2270
+ marker.content.style.pointerEvents = gmpClickable ? "all" : "none";
2271
+ marker.content.style.cursor = gmpClickable && onClick ? "pointer" : "";
1033
2272
  }
1034
- }, [marker, clickable, onClick, onMouseEnter, onMouseLeave]);
1035
- useMapsEventListener(marker, "click", onClick);
2273
+ }, [
2274
+ marker,
2275
+ clickable,
2276
+ onClick,
2277
+ onKeyDown,
2278
+ onKeyUp,
2279
+ onMouseEnter,
2280
+ onMouseLeave
2281
+ ]);
1036
2282
  useMapsEventListener(marker, "drag", onDrag);
1037
2283
  useMapsEventListener(marker, "dragstart", onDragStart);
1038
2284
  useMapsEventListener(marker, "dragend", onDragEnd);
1039
- useDomEventListener(marker == null ? void 0 : marker.element, "mouseenter", onMouseEnter);
1040
- useDomEventListener(marker == null ? void 0 : marker.element, "mouseleave", onMouseLeave);
2285
+ useDomEventListener(marker, "gmp-click", onClick);
2286
+ useDomEventListener(marker, "keydown", onKeyDown);
2287
+ useDomEventListener(marker, "keyup", onKeyUp);
2288
+ useDomEventListener(marker, "mouseenter", onMouseEnter);
2289
+ useDomEventListener(marker, "mouseleave", onMouseLeave);
1041
2290
  return [marker, contentContainer];
1042
2291
  }
1043
- const AdvancedMarker = forwardRef((props, ref) => {
1044
- const {
1045
- children,
1046
- style: style2,
1047
- className,
1048
- anchorPoint
1049
- } = props;
1050
- const [marker, contentContainer] = useAdvancedMarker(props);
1051
- const advancedMarkerContextValue = useMemo(() => marker ? {
1052
- marker
1053
- } : null, [marker]);
1054
- useImperativeHandle(ref, () => marker, [marker]);
1055
- if (!contentContainer) return null;
1056
- return /* @__PURE__ */ React__default.createElement(AdvancedMarkerContext.Provider, {
1057
- value: advancedMarkerContextValue
1058
- }, createPortal(/* @__PURE__ */ React__default.createElement(MarkerContent, {
1059
- anchorPoint,
1060
- styles: style2,
1061
- className
1062
- }, children), contentContainer));
1063
- });
1064
- function setValueForStyles(element, styles2, prevStyles) {
1065
- if (styles2 != null && typeof styles2 !== "object") {
1066
- throw new Error("The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.");
1067
- }
1068
- const elementStyle = element.style;
1069
- if (prevStyles == null) {
1070
- if (styles2 == null) return;
1071
- for (const styleName in styles2) {
1072
- if (!styles2.hasOwnProperty(styleName)) continue;
1073
- setValueForStyle(elementStyle, styleName, styles2[styleName]);
2292
+ function useAdvancedMarkerAnchoring(marker, anchorPoint, anchorLeft, anchorTop, hasChildren) {
2293
+ useEffect(() => {
2294
+ if (!marker || !hasChildren)
2295
+ return;
2296
+ const anchorOptionsSupported = isVersionGreaterEqual(3, 62);
2297
+ const contentElement = marker.content;
2298
+ if (!contentElement || !isElementNode(contentElement))
2299
+ return;
2300
+ if (anchorLeft !== void 0 || anchorTop !== void 0) {
2301
+ if (!anchorOptionsSupported) {
2302
+ console.warn(`AdvancedMarker: The anchorLeft and anchorTop props are only supported in Google Maps API version 3.62 and above. The current version is ${google.maps.version}.`);
2303
+ }
2304
+ marker.anchorLeft = anchorLeft;
2305
+ marker.anchorTop = anchorTop;
2306
+ if (anchorPoint !== void 0) {
2307
+ console.warn("AdvancedMarker: the anchorPoint prop is ignored when anchorLeft and/or anchorTop are set.");
2308
+ }
2309
+ return;
1074
2310
  }
1075
- return;
1076
- }
1077
- for (const styleName in prevStyles) {
1078
- if (prevStyles.hasOwnProperty(styleName) && (styles2 == null || !styles2.hasOwnProperty(styleName))) {
1079
- const isCustomProperty = styleName.indexOf("--") === 0;
1080
- if (isCustomProperty) {
1081
- elementStyle.setProperty(styleName, "");
1082
- } else if (styleName === "float") {
1083
- elementStyle.cssFloat = "";
2311
+ if (anchorPoint !== void 0) {
2312
+ const [x, y] = anchorPoint !== null && anchorPoint !== void 0 ? anchorPoint : AdvancedMarkerAnchorPoint["BOTTOM"];
2313
+ const translateX = `calc(-1 * ${x})`;
2314
+ const translateY = `calc(-1 * ${y})`;
2315
+ if (anchorOptionsSupported) {
2316
+ marker.anchorLeft = translateX;
2317
+ marker.anchorTop = translateY;
2318
+ contentElement.style.transform = "";
1084
2319
  } else {
1085
- elementStyle[styleName] = "";
2320
+ contentElement.style.transform = `translate(50%, 100%) translate(${translateX}, ${translateY})`;
2321
+ marker.dataset.origin = "rgm";
2322
+ globalStyleManager.addAdvancedMarkerPointerEventsOverwrite();
1086
2323
  }
1087
2324
  }
1088
- }
1089
- if (styles2 == null) return;
1090
- for (const styleName in styles2) {
1091
- const value = styles2[styleName];
1092
- if (styles2.hasOwnProperty(styleName) && prevStyles[styleName] !== value) {
1093
- setValueForStyle(elementStyle, styleName, value);
2325
+ }, [marker, anchorPoint, anchorLeft, anchorTop, hasChildren]);
2326
+ }
2327
+ const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
2328
+ const UNSET = null;
2329
+ function getChangedOptions(nextOptions, trackedOptions) {
2330
+ let changedOptions = null;
2331
+ const keys2 = /* @__PURE__ */ new Set([
2332
+ ...Object.keys(trackedOptions),
2333
+ ...Object.keys(nextOptions)
2334
+ ]);
2335
+ for (const key of keys2) {
2336
+ if (!hasOwn(nextOptions, key)) {
2337
+ changedOptions !== null && changedOptions !== void 0 ? changedOptions : changedOptions = /* @__PURE__ */ Object.create(null);
2338
+ changedOptions[key] = UNSET;
2339
+ continue;
1094
2340
  }
2341
+ if (hasOwn(trackedOptions, key) && deepEqual(trackedOptions[key], nextOptions[key]))
2342
+ continue;
2343
+ changedOptions !== null && changedOptions !== void 0 ? changedOptions : changedOptions = /* @__PURE__ */ Object.create(null);
2344
+ changedOptions[key] = nextOptions[key];
1095
2345
  }
2346
+ return changedOptions;
1096
2347
  }
1097
- function setValueForStyle(elementStyle, styleName, value) {
1098
- const isCustomProperty = styleName.indexOf("--") === 0;
1099
- if (value == null || typeof value === "boolean" || value === "") {
1100
- if (isCustomProperty) {
1101
- elementStyle.setProperty(styleName, "");
1102
- } else if (styleName === "float") {
1103
- elementStyle.cssFloat = "";
1104
- } else {
1105
- elementStyle[styleName] = "";
1106
- }
1107
- } else if (isCustomProperty) {
1108
- elementStyle.setProperty(styleName, value);
1109
- } else if (typeof value === "number" && value !== 0 && !isUnitlessNumber(styleName)) {
1110
- elementStyle[styleName] = value + "px";
1111
- } else {
1112
- if (styleName === "float") {
1113
- elementStyle.cssFloat = value;
1114
- } else {
1115
- elementStyle[styleName] = ("" + value).trim();
1116
- }
2348
+ function snapshotOptions(value) {
2349
+ if (Array.isArray(value))
2350
+ return value.map((entry) => snapshotOptions(entry));
2351
+ if (value === null || typeof value !== "object")
2352
+ return value;
2353
+ const prototype = Object.getPrototypeOf(value);
2354
+ if (prototype !== Object.prototype)
2355
+ return value;
2356
+ const copy = {};
2357
+ for (const key of Object.keys(value))
2358
+ copy[key] = snapshotOptions(value[key]);
2359
+ return copy;
2360
+ }
2361
+ const appliedOptionsByObject = /* @__PURE__ */ new WeakMap();
2362
+ function setMapObjectOptions(object, options, { alreadyApplied = false } = {}) {
2363
+ var _a;
2364
+ if (alreadyApplied) {
2365
+ appliedOptionsByObject.set(object, snapshotOptions(options));
2366
+ return;
1117
2367
  }
2368
+ const appliedOptions = (_a = appliedOptionsByObject.get(object)) !== null && _a !== void 0 ? _a : {};
2369
+ const changedOptions = getChangedOptions(options, appliedOptions);
2370
+ if (!changedOptions)
2371
+ return;
2372
+ object.setOptions(changedOptions);
2373
+ appliedOptionsByObject.set(object, snapshotOptions(options));
1118
2374
  }
1119
- const unitlessNumbers = /* @__PURE__ */ new Set([
1120
- "animationIterationCount",
1121
- "aspectRatio",
1122
- "borderImageOutset",
1123
- "borderImageSlice",
1124
- "borderImageWidth",
1125
- "boxFlex",
1126
- "boxFlexGroup",
1127
- "boxOrdinalGroup",
1128
- "columnCount",
1129
- "columns",
1130
- "flex",
1131
- "flexGrow",
1132
- "flexPositive",
1133
- "flexShrink",
1134
- "flexNegative",
1135
- "flexOrder",
1136
- "gridArea",
1137
- "gridRow",
1138
- "gridRowEnd",
1139
- "gridRowSpan",
1140
- "gridRowStart",
1141
- "gridColumn",
1142
- "gridColumnEnd",
1143
- "gridColumnSpan",
1144
- "gridColumnStart",
1145
- "fontWeight",
1146
- "lineClamp",
1147
- "lineHeight",
1148
- "opacity",
1149
- "order",
1150
- "orphans",
1151
- "scale",
1152
- "tabSize",
1153
- "widows",
1154
- "zIndex",
1155
- "zoom",
1156
- "fillOpacity",
1157
- // SVG-related properties
1158
- "floodOpacity",
1159
- "stopOpacity",
1160
- "strokeDasharray",
1161
- "strokeDashoffset",
1162
- "strokeMiterlimit",
1163
- "strokeOpacity",
1164
- "strokeWidth"
1165
- ]);
1166
- function isUnitlessNumber(name) {
1167
- return unitlessNumbers.has(name);
2375
+ function useCircle(props) {
2376
+ var _a, _b, _c;
2377
+ const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut, onRadiusChanged, onCenterChanged, center, defaultCenter, radius, defaultRadius } = props, destructuredOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut", "onRadiusChanged", "onCenterChanged", "center", "defaultCenter", "radius", "defaultRadius"]);
2378
+ const [circle, setCircle] = useState(null);
2379
+ const map = useMap();
2380
+ const circleOptions = useMemoized(Object.assign(Object.assign({}, destructuredOptions), { clickable: (_a = destructuredOptions.clickable) !== null && _a !== void 0 ? _a : Boolean(onClick), draggable: (_b = destructuredOptions.draggable) !== null && _b !== void 0 ? _b : Boolean(onDrag || onDragStart || onDragEnd || onCenterChanged), editable: (_c = destructuredOptions.editable) !== null && _c !== void 0 ? _c : Boolean(onRadiusChanged) }), deepEqual);
2381
+ useEffect(() => {
2382
+ if (!map) {
2383
+ if (map === void 0)
2384
+ console.error("<Circle> has to be inside a Map component.");
2385
+ return;
2386
+ }
2387
+ const newCircle = new google.maps.Circle(Object.assign(Object.assign({}, circleOptions), { center: center !== null && center !== void 0 ? center : defaultCenter, radius: radius !== null && radius !== void 0 ? radius : defaultRadius }));
2388
+ setMapObjectOptions(newCircle, circleOptions, { alreadyApplied: true });
2389
+ newCircle.setMap(map);
2390
+ setCircle(newCircle);
2391
+ return () => {
2392
+ newCircle.setMap(null);
2393
+ setCircle(null);
2394
+ };
2395
+ }, [map]);
2396
+ useMapsEventListener(circle, "click", onClick);
2397
+ useMapsEventListener(circle, "drag", onDrag);
2398
+ useMapsEventListener(circle, "dragstart", onDragStart);
2399
+ useMapsEventListener(circle, "dragend", onDragEnd);
2400
+ useMapsEventListener(circle, "mouseover", onMouseOver);
2401
+ useMapsEventListener(circle, "mouseout", onMouseOut);
2402
+ useMapsEventListener(circle, "radius_changed", onRadiusChanged ? () => {
2403
+ const newRadius = circle === null || circle === void 0 ? void 0 : circle.getRadius();
2404
+ if (newRadius !== void 0)
2405
+ onRadiusChanged(newRadius);
2406
+ } : null);
2407
+ useMapsEventListener(circle, "center_changed", onCenterChanged ? () => {
2408
+ onCenterChanged(circle === null || circle === void 0 ? void 0 : circle.getCenter());
2409
+ } : null);
2410
+ useEffect(() => {
2411
+ if (!circle)
2412
+ return;
2413
+ setMapObjectOptions(circle, circleOptions);
2414
+ }, [circle, circleOptions]);
2415
+ useEffect(() => {
2416
+ if (!circle || !center)
2417
+ return;
2418
+ if (!latLngEquals(center, circle.getCenter())) {
2419
+ circle.setCenter(center);
2420
+ }
2421
+ }, [circle, center]);
2422
+ useEffect(() => {
2423
+ if (!circle || radius === void 0)
2424
+ return;
2425
+ if (radius !== circle.getRadius()) {
2426
+ circle.setRadius(radius);
2427
+ }
2428
+ }, [circle, radius]);
2429
+ return circle;
1168
2430
  }
1169
- const _excluded$1 = ["children", "headerContent", "style", "className", "pixelOffset", "anchor", "shouldFocus", "onClose", "onCloseClick"];
2431
+ const Circle = forwardRef((props, ref) => {
2432
+ const circle = useCircle(props);
2433
+ useImperativeHandle(ref, () => circle, [circle]);
2434
+ return React__default.createElement(React__default.Fragment, null);
2435
+ });
2436
+ Circle.displayName = "Circle";
1170
2437
  const InfoWindow = (props) => {
1171
2438
  const {
1172
2439
  // content options
@@ -1181,32 +2448,33 @@ const InfoWindow = (props) => {
1181
2448
  // events
1182
2449
  onClose,
1183
2450
  onCloseClick
1184
- // other options
1185
- } = props, infoWindowOptions = _objectWithoutPropertiesLoose(props, _excluded$1);
2451
+ } = props, volatileInfoWindowOptions = __rest(props, ["children", "headerContent", "style", "className", "pixelOffset", "anchor", "shouldFocus", "onClose", "onCloseClick"]);
1186
2452
  const mapsLibrary = useMapsLibrary("maps");
1187
2453
  const [infoWindow, setInfoWindow] = useState(null);
1188
2454
  const contentContainerRef = useRef(null);
1189
2455
  const headerContainerRef = useRef(null);
2456
+ const infoWindowOptions = useMemoized(volatileInfoWindowOptions, deepEqual);
1190
2457
  useEffect(
1191
2458
  () => {
1192
- if (!mapsLibrary) return;
2459
+ if (!mapsLibrary)
2460
+ return;
1193
2461
  contentContainerRef.current = document.createElement("div");
1194
2462
  headerContainerRef.current = document.createElement("div");
1195
- const opts = infoWindowOptions;
2463
+ const opts = Object.assign({}, infoWindowOptions);
1196
2464
  if (pixelOffset) {
1197
2465
  opts.pixelOffset = new google.maps.Size(pixelOffset[0], pixelOffset[1]);
1198
2466
  }
1199
2467
  if (headerContent) {
1200
2468
  opts.headerContent = typeof headerContent === "string" ? headerContent : headerContainerRef.current;
1201
2469
  }
1202
- const infoWindow2 = new google.maps.InfoWindow(infoWindowOptions);
2470
+ const infoWindow2 = new google.maps.InfoWindow(opts);
1203
2471
  infoWindow2.setContent(contentContainerRef.current);
1204
2472
  setInfoWindow(infoWindow2);
1205
2473
  return () => {
1206
- var _contentContainerRef$, _headerContainerRef$c;
2474
+ var _a, _b;
1207
2475
  infoWindow2.setContent(null);
1208
- (_contentContainerRef$ = contentContainerRef.current) == null || _contentContainerRef$.remove();
1209
- (_headerContainerRef$c = headerContainerRef.current) == null || _headerContainerRef$c.remove();
2476
+ (_a = contentContainerRef.current) === null || _a === void 0 ? void 0 : _a.remove();
2477
+ (_b = headerContainerRef.current) === null || _b === void 0 ? void 0 : _b.remove();
1210
2478
  contentContainerRef.current = null;
1211
2479
  headerContainerRef.current = null;
1212
2480
  setInfoWindow(null);
@@ -1222,16 +2490,19 @@ const InfoWindow = (props) => {
1222
2490
  [mapsLibrary]
1223
2491
  );
1224
2492
  const prevStyleRef = useRef(null);
1225
- useEffect(() => {
1226
- if (!infoWindow || !contentContainerRef.current) return;
2493
+ useLayoutEffect(() => {
2494
+ if (!infoWindow || !contentContainerRef.current)
2495
+ return;
1227
2496
  setValueForStyles(contentContainerRef.current, style2 || null, prevStyleRef.current);
1228
2497
  prevStyleRef.current = style2 || null;
1229
- if (className !== contentContainerRef.current.className) contentContainerRef.current.className = className || "";
2498
+ if (className !== contentContainerRef.current.className)
2499
+ contentContainerRef.current.className = className || "";
1230
2500
  }, [infoWindow, className, style2]);
1231
- useDeepCompareEffect(
2501
+ useEffect(
1232
2502
  () => {
1233
- if (!infoWindow) return;
1234
- const opts = infoWindowOptions;
2503
+ if (!infoWindow)
2504
+ return;
2505
+ const opts = Object.assign({}, infoWindowOptions);
1235
2506
  if (!pixelOffset) {
1236
2507
  opts.pixelOffset = null;
1237
2508
  } else {
@@ -1242,7 +2513,7 @@ const InfoWindow = (props) => {
1242
2513
  } else {
1243
2514
  opts.headerContent = typeof headerContent === "string" ? headerContent : headerContainerRef.current;
1244
2515
  }
1245
- infoWindow.setOptions(infoWindowOptions);
2516
+ infoWindow.setOptions(opts);
1246
2517
  },
1247
2518
  // dependency `infoWindow` isn't needed since options are also passed
1248
2519
  // to the constructor when a new infoWindow is created.
@@ -1252,24 +2523,22 @@ const InfoWindow = (props) => {
1252
2523
  useMapsEventListener(infoWindow, "close", onClose);
1253
2524
  useMapsEventListener(infoWindow, "closeclick", onCloseClick);
1254
2525
  const map = useMap();
1255
- useDeepCompareEffect(() => {
1256
- if (!map || !infoWindow || anchor === null) return;
2526
+ useEffect(() => {
2527
+ var _a;
2528
+ if (!map || !infoWindow || anchor === null)
2529
+ return;
1257
2530
  const isOpenedWithAnchor = !!anchor;
1258
- const openOptions = {
1259
- map
1260
- };
2531
+ const openOptions = { map };
1261
2532
  if (anchor) {
1262
2533
  openOptions.anchor = anchor;
1263
2534
  if (isAdvancedMarker(anchor) && anchor.content instanceof Element) {
1264
- const wrapper = anchor.content;
1265
- const wrapperBcr = wrapper == null ? void 0 : wrapper.getBoundingClientRect();
1266
- if (wrapperBcr && wrapper != null && wrapper.isCustomMarker) {
1267
- var _anchor$content$first;
1268
- const anchorDomContent = (_anchor$content$first = anchor.content.firstElementChild) == null ? void 0 : _anchor$content$first.firstElementChild;
1269
- const contentBcr = anchorDomContent == null ? void 0 : anchorDomContent.getBoundingClientRect();
1270
- const anchorOffsetX = contentBcr.x - wrapperBcr.x + (contentBcr.width - wrapperBcr.width) / 2;
1271
- const anchorOffsetY = contentBcr.y - wrapperBcr.y;
1272
- const opts = infoWindowOptions;
2535
+ const anchorBcr = anchor === null || anchor === void 0 ? void 0 : anchor.getBoundingClientRect();
2536
+ if (anchorBcr && anchor.dataset.origin === "rgm") {
2537
+ const anchorDomContent = (_a = anchor.content.firstElementChild) === null || _a === void 0 ? void 0 : _a.firstElementChild;
2538
+ const contentBcr = anchorDomContent === null || anchorDomContent === void 0 ? void 0 : anchorDomContent.getBoundingClientRect();
2539
+ const anchorOffsetX = contentBcr.x - anchorBcr.x + (contentBcr.width - anchorBcr.width) / 2;
2540
+ const anchorOffsetY = contentBcr.y - anchorBcr.y;
2541
+ const opts = Object.assign({}, infoWindowOptions);
1273
2542
  opts.pixelOffset = new google.maps.Size(pixelOffset ? pixelOffset[0] + anchorOffsetX : anchorOffsetX, pixelOffset ? pixelOffset[1] + anchorOffsetY : anchorOffsetY);
1274
2543
  infoWindow.setOptions(opts);
1275
2544
  }
@@ -1280,31 +2549,267 @@ const InfoWindow = (props) => {
1280
2549
  }
1281
2550
  infoWindow.open(openOptions);
1282
2551
  return () => {
1283
- if (isOpenedWithAnchor) infoWindow.set("anchor", null);
2552
+ if (isOpenedWithAnchor)
2553
+ infoWindow.set("anchor", null);
1284
2554
  infoWindow.close();
1285
2555
  };
1286
2556
  }, [infoWindow, anchor, map, shouldFocus, infoWindowOptions, pixelOffset]);
1287
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, contentContainerRef.current && createPortal(children, contentContainerRef.current), headerContainerRef.current !== null && createPortal(headerContent, headerContainerRef.current));
2557
+ return React__default.createElement(
2558
+ React__default.Fragment,
2559
+ null,
2560
+ contentContainerRef.current && createPortal(children, contentContainerRef.current),
2561
+ headerContainerRef.current !== null && createPortal(headerContent, headerContainerRef.current)
2562
+ );
1288
2563
  };
1289
- const _excluded = ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut"];
2564
+ function getPathsArray(polygon) {
2565
+ const mvcPaths = polygon.getPaths();
2566
+ const result = [];
2567
+ for (let i = 0; i < mvcPaths.getLength(); i++) {
2568
+ result.push(mvcPaths.getAt(i).getArray());
2569
+ }
2570
+ return result;
2571
+ }
2572
+ function usePolygon(props) {
2573
+ var _a, _b, _c;
2574
+ const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut, onPathsChanged, polygon: externalPolygon, encodedPaths, paths, defaultPaths } = props, destructuredOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut", "onPathsChanged", "polygon", "encodedPaths", "paths", "defaultPaths"]);
2575
+ const [polygon, setPolygon] = useState(null);
2576
+ const map = useMap();
2577
+ const geometryLibrary = useMapsLibrary("geometry");
2578
+ const isUpdatingRef = useRef(false);
2579
+ const polygonOptions = useMemoized(Object.assign(Object.assign({}, destructuredOptions), { clickable: (_a = destructuredOptions.clickable) !== null && _a !== void 0 ? _a : Boolean(onClick), draggable: (_b = destructuredOptions.draggable) !== null && _b !== void 0 ? _b : Boolean(onDrag || onDragStart || onDragEnd || onPathsChanged), editable: (_c = destructuredOptions.editable) !== null && _c !== void 0 ? _c : Boolean(onPathsChanged) }), deepEqual);
2580
+ useEffect(() => {
2581
+ if (!map) {
2582
+ if (map === void 0)
2583
+ console.error("<Polygon> has to be inside a Map component.");
2584
+ return;
2585
+ }
2586
+ let instance;
2587
+ if (externalPolygon) {
2588
+ instance = externalPolygon;
2589
+ const initialPaths = paths !== null && paths !== void 0 ? paths : defaultPaths;
2590
+ if (initialPaths && Array.isArray(initialPaths)) {
2591
+ instance.setPaths(initialPaths);
2592
+ }
2593
+ instance.setOptions(polygonOptions);
2594
+ } else {
2595
+ const initialPaths = paths !== null && paths !== void 0 ? paths : defaultPaths;
2596
+ const polygonOptionsWithPaths = Object.assign({}, polygonOptions);
2597
+ if (initialPaths && Array.isArray(initialPaths)) {
2598
+ polygonOptionsWithPaths.paths = initialPaths;
2599
+ }
2600
+ instance = new google.maps.Polygon(polygonOptionsWithPaths);
2601
+ }
2602
+ setMapObjectOptions(instance, polygonOptions, { alreadyApplied: true });
2603
+ instance.setMap(map);
2604
+ setPolygon(instance);
2605
+ return () => {
2606
+ instance.setMap(null);
2607
+ setPolygon(null);
2608
+ };
2609
+ }, [map, externalPolygon]);
2610
+ useMapsEventListener(polygon, "click", onClick);
2611
+ useMapsEventListener(polygon, "drag", onDrag);
2612
+ useMapsEventListener(polygon, "dragstart", onDragStart);
2613
+ useMapsEventListener(polygon, "mouseover", onMouseOver);
2614
+ useMapsEventListener(polygon, "mouseout", onMouseOut);
2615
+ useMapsEventListener(polygon, "dragend", (e) => {
2616
+ onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd(e);
2617
+ if (onPathsChanged && polygon && !isUpdatingRef.current) {
2618
+ onPathsChanged(getPathsArray(polygon));
2619
+ }
2620
+ });
2621
+ useEffect(() => {
2622
+ if (!polygon || !onPathsChanged)
2623
+ return;
2624
+ const listeners2 = [];
2625
+ const mvcPaths = polygon.getPaths();
2626
+ if (typeof mvcPaths.getLength !== "function" || typeof mvcPaths.getAt !== "function") {
2627
+ return;
2628
+ }
2629
+ const handlePathsChange = () => {
2630
+ if (!isUpdatingRef.current) {
2631
+ onPathsChanged(getPathsArray(polygon));
2632
+ }
2633
+ };
2634
+ const subscribeToInnerPath = (innerPath) => {
2635
+ listeners2.push(google.maps.event.addListener(innerPath, "insert_at", handlePathsChange));
2636
+ listeners2.push(google.maps.event.addListener(innerPath, "remove_at", handlePathsChange));
2637
+ listeners2.push(google.maps.event.addListener(innerPath, "set_at", handlePathsChange));
2638
+ };
2639
+ for (let i = 0; i < mvcPaths.getLength(); i++) {
2640
+ subscribeToInnerPath(mvcPaths.getAt(i));
2641
+ }
2642
+ listeners2.push(google.maps.event.addListener(mvcPaths, "insert_at", (index) => {
2643
+ subscribeToInnerPath(mvcPaths.getAt(index));
2644
+ handlePathsChange();
2645
+ }));
2646
+ listeners2.push(google.maps.event.addListener(mvcPaths, "set_at", (index) => {
2647
+ subscribeToInnerPath(mvcPaths.getAt(index));
2648
+ handlePathsChange();
2649
+ }));
2650
+ listeners2.push(google.maps.event.addListener(mvcPaths, "remove_at", handlePathsChange));
2651
+ return () => {
2652
+ listeners2.forEach((listener) => listener.remove());
2653
+ };
2654
+ }, [
2655
+ polygon,
2656
+ onPathsChanged,
2657
+ paths,
2658
+ encodedPaths,
2659
+ polygonOptions.editable,
2660
+ polygonOptions.draggable
2661
+ ]);
2662
+ useEffect(() => {
2663
+ if (!polygon)
2664
+ return;
2665
+ setMapObjectOptions(polygon, polygonOptions);
2666
+ }, [polygon, polygonOptions]);
2667
+ useEffect(() => {
2668
+ if (!polygon || !paths)
2669
+ return;
2670
+ if (!Array.isArray(paths))
2671
+ return;
2672
+ const firstPath = paths[0];
2673
+ const normalizedPaths = Array.isArray(firstPath) ? paths : [paths];
2674
+ const currentPaths = polygon.getPaths();
2675
+ if (!pathsEquals(normalizedPaths, currentPaths)) {
2676
+ isUpdatingRef.current = true;
2677
+ polygon.setPaths(paths);
2678
+ isUpdatingRef.current = false;
2679
+ }
2680
+ }, [polygon, paths]);
2681
+ useEffect(() => {
2682
+ if (!polygon || !encodedPaths || !geometryLibrary)
2683
+ return;
2684
+ isUpdatingRef.current = true;
2685
+ const decodedPaths = encodedPaths.map((encodedPath) => geometryLibrary.encoding.decodePath(encodedPath));
2686
+ polygon.setPaths(decodedPaths);
2687
+ isUpdatingRef.current = false;
2688
+ }, [polygon, encodedPaths, geometryLibrary]);
2689
+ return polygon;
2690
+ }
2691
+ const Polygon = forwardRef((props, ref) => {
2692
+ const polygon = usePolygon(props);
2693
+ useImperativeHandle(ref, () => polygon, [polygon]);
2694
+ return React__default.createElement(React__default.Fragment, null);
2695
+ });
2696
+ Polygon.displayName = "Polygon";
2697
+ function usePolyline(props) {
2698
+ var _a, _b, _c;
2699
+ const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut, onPathChanged, polyline: externalPolyline, encodedPath, path, defaultPath } = props, destructuredOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut", "onPathChanged", "polyline", "encodedPath", "path", "defaultPath"]);
2700
+ const [polyline, setPolyline] = useState(null);
2701
+ const map = useMap();
2702
+ const geometryLibrary = useMapsLibrary("geometry");
2703
+ const isUpdatingRef = useRef(false);
2704
+ const polylineOptions = useMemoized(Object.assign(Object.assign({}, destructuredOptions), { clickable: (_a = destructuredOptions.clickable) !== null && _a !== void 0 ? _a : Boolean(onClick), draggable: (_b = destructuredOptions.draggable) !== null && _b !== void 0 ? _b : Boolean(onDrag || onDragStart || onDragEnd || onPathChanged), editable: (_c = destructuredOptions.editable) !== null && _c !== void 0 ? _c : Boolean(onPathChanged) }), deepEqual);
2705
+ useEffect(() => {
2706
+ if (!map) {
2707
+ if (map === void 0)
2708
+ console.error("<Polyline> has to be inside a Map component.");
2709
+ return;
2710
+ }
2711
+ let instance;
2712
+ if (externalPolyline) {
2713
+ instance = externalPolyline;
2714
+ const initialPath = path !== null && path !== void 0 ? path : defaultPath;
2715
+ if (initialPath && Array.isArray(initialPath)) {
2716
+ instance.setPath(initialPath);
2717
+ }
2718
+ instance.setOptions(polylineOptions);
2719
+ } else {
2720
+ const initialPath = path !== null && path !== void 0 ? path : defaultPath;
2721
+ const polylineOptionsWithPath = Object.assign({}, polylineOptions);
2722
+ if (initialPath && Array.isArray(initialPath)) {
2723
+ polylineOptionsWithPath.path = initialPath;
2724
+ }
2725
+ instance = new google.maps.Polyline(polylineOptionsWithPath);
2726
+ }
2727
+ setMapObjectOptions(instance, polylineOptions, { alreadyApplied: true });
2728
+ instance.setMap(map);
2729
+ setPolyline(instance);
2730
+ return () => {
2731
+ instance.setMap(null);
2732
+ setPolyline(null);
2733
+ };
2734
+ }, [map, externalPolyline]);
2735
+ useMapsEventListener(polyline, "click", onClick);
2736
+ useMapsEventListener(polyline, "drag", onDrag);
2737
+ useMapsEventListener(polyline, "dragstart", onDragStart);
2738
+ useMapsEventListener(polyline, "mouseover", onMouseOver);
2739
+ useMapsEventListener(polyline, "mouseout", onMouseOut);
2740
+ useMapsEventListener(polyline, "dragend", (e) => {
2741
+ onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd(e);
2742
+ if (onPathChanged && polyline && !isUpdatingRef.current) {
2743
+ onPathChanged(polyline.getPath().getArray());
2744
+ }
2745
+ });
2746
+ useEffect(() => {
2747
+ if (!polyline || !onPathChanged)
2748
+ return;
2749
+ const mvcPath = polyline.getPath();
2750
+ if (!mvcPath)
2751
+ return;
2752
+ const handlePathChange = () => {
2753
+ if (!isUpdatingRef.current) {
2754
+ onPathChanged(mvcPath.getArray());
2755
+ }
2756
+ };
2757
+ const listeners2 = [
2758
+ google.maps.event.addListener(mvcPath, "insert_at", handlePathChange),
2759
+ google.maps.event.addListener(mvcPath, "remove_at", handlePathChange),
2760
+ google.maps.event.addListener(mvcPath, "set_at", handlePathChange)
2761
+ ];
2762
+ return () => {
2763
+ listeners2.forEach((listener) => listener.remove());
2764
+ };
2765
+ }, [
2766
+ polyline,
2767
+ onPathChanged,
2768
+ path,
2769
+ encodedPath,
2770
+ polylineOptions.editable,
2771
+ polylineOptions.draggable
2772
+ ]);
2773
+ useEffect(() => {
2774
+ if (!polyline)
2775
+ return;
2776
+ setMapObjectOptions(polyline, polylineOptions);
2777
+ }, [polyline, polylineOptions]);
2778
+ useEffect(() => {
2779
+ if (!polyline || !path)
2780
+ return;
2781
+ const currentPath = polyline.getPath();
2782
+ if (!pathEquals(path, currentPath)) {
2783
+ isUpdatingRef.current = true;
2784
+ polyline.setPath(path);
2785
+ isUpdatingRef.current = false;
2786
+ }
2787
+ }, [polyline, path]);
2788
+ useEffect(() => {
2789
+ if (!polyline || !encodedPath || !geometryLibrary)
2790
+ return;
2791
+ isUpdatingRef.current = true;
2792
+ const decodedPath = geometryLibrary.encoding.decodePath(encodedPath);
2793
+ polyline.setPath(decodedPath);
2794
+ isUpdatingRef.current = false;
2795
+ }, [polyline, encodedPath, geometryLibrary]);
2796
+ return polyline;
2797
+ }
2798
+ const Polyline = forwardRef((props, ref) => {
2799
+ const polyline = usePolyline(props);
2800
+ useImperativeHandle(ref, () => polyline, [polyline]);
2801
+ return React__default.createElement(React__default.Fragment, null);
2802
+ });
2803
+ Polyline.displayName = "Polyline";
1290
2804
  function useMarker(props) {
1291
2805
  const [marker, setMarker] = useState(null);
1292
2806
  const map = useMap();
1293
- const {
1294
- onClick,
1295
- onDrag,
1296
- onDragStart,
1297
- onDragEnd,
1298
- onMouseOver,
1299
- onMouseOut
1300
- } = props, markerOptions = _objectWithoutPropertiesLoose(props, _excluded);
1301
- const {
1302
- position,
1303
- draggable
1304
- } = markerOptions;
2807
+ const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut } = props, markerOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut"]);
2808
+ const { position, draggable } = markerOptions;
1305
2809
  useEffect(() => {
1306
2810
  if (!map) {
1307
- if (map === void 0) console.error("<Marker> has to be inside a Map component.");
2811
+ if (map === void 0)
2812
+ console.error("<Marker> has to be inside a Map component.");
1308
2813
  return;
1309
2814
  }
1310
2815
  const newMarker = new google.maps.Marker(markerOptions);
@@ -1316,35 +2821,107 @@ function useMarker(props) {
1316
2821
  };
1317
2822
  }, [map]);
1318
2823
  useEffect(() => {
1319
- if (!marker) return;
2824
+ if (!marker)
2825
+ return;
1320
2826
  const m = marker;
1321
2827
  const gme = google.maps.event;
1322
- if (onClick) gme.addListener(m, "click", onClick);
1323
- if (onDrag) gme.addListener(m, "drag", onDrag);
1324
- if (onDragStart) gme.addListener(m, "dragstart", onDragStart);
1325
- if (onDragEnd) gme.addListener(m, "dragend", onDragEnd);
1326
- if (onMouseOver) gme.addListener(m, "mouseover", onMouseOver);
1327
- if (onMouseOut) gme.addListener(m, "mouseout", onMouseOut);
2828
+ if (onClick)
2829
+ gme.addListener(m, "click", onClick);
2830
+ if (onDrag)
2831
+ gme.addListener(m, "drag", onDrag);
2832
+ if (onDragStart)
2833
+ gme.addListener(m, "dragstart", onDragStart);
2834
+ if (onDragEnd)
2835
+ gme.addListener(m, "dragend", onDragEnd);
2836
+ if (onMouseOver)
2837
+ gme.addListener(m, "mouseover", onMouseOver);
2838
+ if (onMouseOut)
2839
+ gme.addListener(m, "mouseout", onMouseOut);
1328
2840
  marker.setDraggable(Boolean(draggable));
1329
2841
  return () => {
1330
2842
  gme.clearInstanceListeners(m);
1331
2843
  };
1332
- }, [marker, draggable, onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut]);
2844
+ }, [
2845
+ marker,
2846
+ draggable,
2847
+ onClick,
2848
+ onDrag,
2849
+ onDragStart,
2850
+ onDragEnd,
2851
+ onMouseOver,
2852
+ onMouseOut
2853
+ ]);
1333
2854
  useEffect(() => {
1334
- if (!marker) return;
1335
- if (markerOptions) marker.setOptions(markerOptions);
2855
+ if (!marker)
2856
+ return;
2857
+ if (markerOptions)
2858
+ marker.setOptions(markerOptions);
1336
2859
  }, [marker, markerOptions]);
1337
2860
  useEffect(() => {
1338
- if (draggable || !position || !marker) return;
2861
+ if (draggable || !position || !marker)
2862
+ return;
1339
2863
  marker.setPosition(position);
1340
2864
  }, [draggable, position, marker]);
1341
2865
  return marker;
1342
2866
  }
1343
- forwardRef((props, ref) => {
2867
+ const Marker = forwardRef((props, ref) => {
1344
2868
  const marker = useMarker(props);
1345
2869
  useImperativeHandle(ref, () => marker, [marker]);
1346
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null);
2870
+ return React__default.createElement(React__default.Fragment, null);
2871
+ });
2872
+ Marker.displayName = "Marker";
2873
+ function useRectangle(props) {
2874
+ var _a, _b, _c;
2875
+ const { onClick, onDrag, onDragStart, onDragEnd, onMouseOver, onMouseOut, onBoundsChanged, bounds, defaultBounds } = props, destructuredOptions = __rest(props, ["onClick", "onDrag", "onDragStart", "onDragEnd", "onMouseOver", "onMouseOut", "onBoundsChanged", "bounds", "defaultBounds"]);
2876
+ const [rectangle, setRectangle] = useState(null);
2877
+ const map = useMap();
2878
+ const rectangleOptions = useMemoized(Object.assign(Object.assign({}, destructuredOptions), { clickable: (_a = destructuredOptions.clickable) !== null && _a !== void 0 ? _a : Boolean(onClick), draggable: (_b = destructuredOptions.draggable) !== null && _b !== void 0 ? _b : Boolean(onDrag || onDragStart || onDragEnd || onBoundsChanged), editable: (_c = destructuredOptions.editable) !== null && _c !== void 0 ? _c : Boolean(onBoundsChanged) }), deepEqual);
2879
+ useEffect(() => {
2880
+ if (!map) {
2881
+ if (map === void 0)
2882
+ console.error("<Rectangle> has to be inside a Map component.");
2883
+ return;
2884
+ }
2885
+ const newRectangle = new google.maps.Rectangle(Object.assign(Object.assign({}, rectangleOptions), { bounds: bounds !== null && bounds !== void 0 ? bounds : defaultBounds }));
2886
+ setMapObjectOptions(newRectangle, rectangleOptions, { alreadyApplied: true });
2887
+ newRectangle.setMap(map);
2888
+ setRectangle(newRectangle);
2889
+ return () => {
2890
+ newRectangle.setMap(null);
2891
+ setRectangle(null);
2892
+ };
2893
+ }, [map]);
2894
+ useMapsEventListener(rectangle, "click", onClick);
2895
+ useMapsEventListener(rectangle, "drag", onDrag);
2896
+ useMapsEventListener(rectangle, "dragstart", onDragStart);
2897
+ useMapsEventListener(rectangle, "dragend", onDragEnd);
2898
+ useMapsEventListener(rectangle, "mouseover", onMouseOver);
2899
+ useMapsEventListener(rectangle, "mouseout", onMouseOut);
2900
+ useMapsEventListener(rectangle, "bounds_changed", onBoundsChanged ? () => {
2901
+ onBoundsChanged(rectangle === null || rectangle === void 0 ? void 0 : rectangle.getBounds());
2902
+ } : null);
2903
+ useEffect(() => {
2904
+ if (!rectangle)
2905
+ return;
2906
+ setMapObjectOptions(rectangle, rectangleOptions);
2907
+ }, [rectangle, rectangleOptions]);
2908
+ useEffect(() => {
2909
+ if (!rectangle || !bounds)
2910
+ return;
2911
+ if (!boundsEquals(bounds, rectangle.getBounds())) {
2912
+ rectangle.setBounds(bounds);
2913
+ }
2914
+ }, [rectangle, bounds]);
2915
+ return rectangle;
2916
+ }
2917
+ const Rectangle = forwardRef((props, ref) => {
2918
+ const rectangle = useRectangle(props);
2919
+ useImperativeHandle(ref, () => rectangle, [
2920
+ rectangle
2921
+ ]);
2922
+ return React__default.createElement(React__default.Fragment, null);
1347
2923
  });
2924
+ Rectangle.displayName = "Rectangle";
1348
2925
  const title = "title__jE00O";
1349
2926
  const description = "description__bjRoW";
1350
2927
  const link = "link__AM1ap";
@@ -1394,6 +2971,7 @@ function hasMarkerInfoWindowFields(location, mapData) {
1394
2971
  );
1395
2972
  }
1396
2973
  const GoogleMapMarker = ({
2974
+ index,
1397
2975
  location,
1398
2976
  infoWindowOpen,
1399
2977
  onMarkerClick,
@@ -1406,7 +2984,7 @@ const GoogleMapMarker = ({
1406
2984
  const { isLinkValid, anchorProps } = getLinkInfo(location);
1407
2985
  const handleMarkerClick = () => {
1408
2986
  var _a2;
1409
- onMarkerClick == null ? void 0 : onMarkerClick({
2987
+ onMarkerClick == null ? void 0 : onMarkerClick(index, {
1410
2988
  type: "markerClicked",
1411
2989
  address: location.address,
1412
2990
  location: {
@@ -1477,7 +3055,7 @@ const GoogleMapMarker = ({
1477
3055
  InfoWindow,
1478
3056
  {
1479
3057
  position,
1480
- pixelOffset: [0, -32],
3058
+ pixelOffset: INFO_WINDOW_PIXEL_OFFSET,
1481
3059
  shouldFocus: false,
1482
3060
  maxWidth: 300,
1483
3061
  minWidth: 228,
@@ -1690,10 +3268,14 @@ const GoogleMapReactInner = forwardRef((props, forwardedRef) => {
1690
3268
  },
1691
3269
  [onMapClicked, id]
1692
3270
  );
1693
- const handleMarkerClicked = (index) => (data) => {
1694
- setOpenInfoWindowIndex(openInfoWindowIndex === index ? null : index);
1695
- onMarkerClicked == null ? void 0 : onMarkerClicked(data);
1696
- };
3271
+ const handleMarkerClicked = useCallback(
3272
+ (index, data) => {
3273
+ setOpenInfoWindowIndex((current) => current === index ? null : index);
3274
+ onMarkerClicked == null ? void 0 : onMarkerClicked(data);
3275
+ },
3276
+ [onMarkerClicked]
3277
+ );
3278
+ const closeInfoWindow = useCallback(() => setOpenInfoWindowIndex(null), []);
1697
3279
  useImperativeHandle(
1698
3280
  forwardedRef,
1699
3281
  () => createImperativeMethods(
@@ -1737,7 +3319,7 @@ const GoogleMapReactInner = forwardRef((props, forwardedRef) => {
1737
3319
  ]
1738
3320
  );
1739
3321
  return /* @__PURE__ */ jsx(
1740
- Map,
3322
+ Map$1,
1741
3323
  {
1742
3324
  onCenterChanged: (e) => handleCenterChanged(e.detail.center),
1743
3325
  onZoomChanged: (e) => handleZoomChange(e.detail.zoom),
@@ -1752,10 +3334,11 @@ const GoogleMapReactInner = forwardRef((props, forwardedRef) => {
1752
3334
  children: mapData.locations.map((location, index) => /* @__PURE__ */ jsx(
1753
3335
  GoogleMapMarker$1,
1754
3336
  {
3337
+ index,
1755
3338
  location,
1756
3339
  infoWindowOpen: openInfoWindowIndex === index && hasMarkerInfoWindowFields(location, mapData),
1757
- onMarkerClick: handleMarkerClicked(index),
1758
- onInfoWindowClose: () => setOpenInfoWindowIndex(null),
3340
+ onMarkerClick: handleMarkerClicked,
3341
+ onInfoWindowClose: closeInfoWindow,
1759
3342
  showDirectionLink: mapData.showDirectionsLink,
1760
3343
  allyTargetBlankDescription: translations.allyTargetBlankDescription
1761
3344
  },