Assumes that an ES5 platform where, if {@code WeakMap} is\n * already present, then it conforms to the anticipated ES6\n * specification. To run this file on an ES5 or almost ES5\n * implementation where the {@code WeakMap} specification does not\n * quite conform, run repairES5.js
first.\n *\n * Even though WeakMapModule is not global, the linter thinks it\n * is, which is why it is in the overrides list below.\n *\n *
NOTE: Before using this WeakMap emulation in a non-SES\n * environment, see the note below about hiddenRecord.\n *\n * @author Mark S. Miller\n * @requires crypto, ArrayBuffer, Uint8Array, navigator, console\n * @overrides WeakMap, ses, Proxy\n * @overrides WeakMapModule\n */\n\n/**\n * This {@code WeakMap} emulation is observably equivalent to the\n * ES-Harmony WeakMap, but with leakier garbage collection properties.\n *\n *
As with true WeakMaps, in this emulation, a key does not\n * retain maps indexed by that key and (crucially) a map does not\n * retain the keys it indexes. A map by itself also does not retain\n * the values associated with that map.\n *\n *
However, the values associated with a key in some map are\n * retained so long as that key is retained and those associations are\n * not overridden. For example, when used to support membranes, all\n * values exported from a given membrane will live for the lifetime\n * they would have had in the absence of an interposed membrane. Even\n * when the membrane is revoked, all objects that would have been\n * reachable in the absence of revocation will still be reachable, as\n * far as the GC can tell, even though they will no longer be relevant\n * to ongoing computation.\n *\n *
The API implemented here is approximately the API as implemented\n * in FF6.0a1 and agreed to by MarkM, Andreas Gal, and Dave Herman,\n * rather than the offially approved proposal page. TODO(erights):\n * upgrade the ecmascript WeakMap proposal page to explain this API\n * change and present to EcmaScript committee for their approval.\n *\n *
The first difference between the emulation here and that in\n * FF6.0a1 is the presence of non enumerable {@code get___, has___,\n * set___, and delete___} methods on WeakMap instances to represent\n * what would be the hidden internal properties of a primitive\n * implementation. Whereas the FF6.0a1 WeakMap.prototype methods\n * require their {@code this} to be a genuine WeakMap instance (i.e.,\n * an object of {@code [[Class]]} \"WeakMap}), since there is nothing\n * unforgeable about the pseudo-internal method names used here,\n * nothing prevents these emulated prototype methods from being\n * applied to non-WeakMaps with pseudo-internal methods of the same\n * names.\n *\n *
Another difference is that our emulated {@code\n * WeakMap.prototype} is not itself a WeakMap. A problem with the\n * current FF6.0a1 API is that WeakMap.prototype is itself a WeakMap\n * providing ambient mutability and an ambient communications\n * channel. Thus, if a WeakMap is already present and has this\n * problem, repairES5.js wraps it in a safe wrappper in order to\n * prevent access to this channel. (See\n * PATCH_MUTABLE_FROZEN_WEAKMAP_PROTO in repairES5.js).\n */\n\n/**\n * If this is a full secureable ES5 platform and the ES-Harmony {@code WeakMap} is\n * absent, install an approximate emulation.\n *\n *
If WeakMap is present but cannot store some objects, use our approximate\n * emulation as a wrapper.\n *\n *
If this is almost a secureable ES5 platform, then WeakMap.js\n * should be run after repairES5.js.\n *\n *
See {@code WeakMap} for documentation of the garbage collection\n * properties of this WeakMap emulation.\n */\n(function WeakMapModule() {\n \"use strict\";\n\n if (typeof ses !== 'undefined' && ses.ok && !ses.ok()) {\n // already too broken, so give up\n return;\n }\n\n /**\n * In some cases (current Firefox), we must make a choice betweeen a\n * WeakMap which is capable of using all varieties of host objects as\n * keys and one which is capable of safely using proxies as keys. See\n * comments below about HostWeakMap and DoubleWeakMap for details.\n *\n * This function (which is a global, not exposed to guests) marks a\n * WeakMap as permitted to do what is necessary to index all host\n * objects, at the cost of making it unsafe for proxies.\n *\n * Do not apply this function to anything which is not a genuine\n * fresh WeakMap.\n */\n function weakMapPermitHostObjects(map) {\n // identity of function used as a secret -- good enough and cheap\n if (map.permitHostObjects___) {\n map.permitHostObjects___(weakMapPermitHostObjects);\n }\n }\n if (typeof ses !== 'undefined') {\n ses.weakMapPermitHostObjects = weakMapPermitHostObjects;\n }\n\n // IE 11 has no Proxy but has a broken WeakMap such that we need to patch\n // it using DoubleWeakMap; this flag tells DoubleWeakMap so.\n var doubleWeakMapCheckSilentFailure = false;\n\n // Check if there is already a good-enough WeakMap implementation, and if so\n // exit without replacing it.\n if (typeof WeakMap === 'function') {\n var HostWeakMap = WeakMap;\n // There is a WeakMap -- is it good enough?\n if (typeof navigator !== 'undefined' &&\n /Firefox/.test(navigator.userAgent)) {\n // We're now *assuming not*, because as of this writing (2013-05-06)\n // Firefox's WeakMaps have a miscellany of objects they won't accept, and\n // we don't want to make an exhaustive list, and testing for just one\n // will be a problem if that one is fixed alone (as they did for Event).\n\n // If there is a platform that we *can* reliably test on, here's how to\n // do it:\n // var problematic = ... ;\n // var testHostMap = new HostWeakMap();\n // try {\n // testHostMap.set(problematic, 1); // Firefox 20 will throw here\n // if (testHostMap.get(problematic) === 1) {\n // return;\n // }\n // } catch (e) {}\n\n } else {\n // IE 11 bug: WeakMaps silently fail to store frozen objects.\n var testMap = new HostWeakMap();\n var testObject = Object.freeze({});\n testMap.set(testObject, 1);\n if (testMap.get(testObject) !== 1) {\n doubleWeakMapCheckSilentFailure = true;\n // Fall through to installing our WeakMap.\n } else {\n module.exports = WeakMap;\n return;\n }\n }\n }\n\n var hop = Object.prototype.hasOwnProperty;\n var gopn = Object.getOwnPropertyNames;\n var defProp = Object.defineProperty;\n var isExtensible = Object.isExtensible;\n\n /**\n * Security depends on HIDDEN_NAME being both unguessable and\n * undiscoverable by untrusted code.\n *\n *
Given the known weaknesses of Math.random() on existing\n * browsers, it does not generate unguessability we can be confident\n * of.\n *\n *
It is the monkey patching logic in this file that is intended\n * to ensure undiscoverability. The basic idea is that there are\n * three fundamental means of discovering properties of an object:\n * The for/in loop, Object.keys(), and Object.getOwnPropertyNames(),\n * as well as some proposed ES6 extensions that appear on our\n * whitelist. The first two only discover enumerable properties, and\n * we only use HIDDEN_NAME to name a non-enumerable property, so the\n * only remaining threat should be getOwnPropertyNames and some\n * proposed ES6 extensions that appear on our whitelist. We monkey\n * patch them to remove HIDDEN_NAME from the list of properties they\n * returns.\n *\n *
TODO(erights): On a platform with built-in Proxies, proxies\n * could be used to trap and thereby discover the HIDDEN_NAME, so we\n * need to monkey patch Proxy.create, Proxy.createFunction, etc, in\n * order to wrap the provided handler with the real handler which\n * filters out all traps using HIDDEN_NAME.\n *\n *
TODO(erights): Revisit Mike Stay's suggestion that we use an\n * encapsulated function at a not-necessarily-secret name, which\n * uses the Stiegler shared-state rights amplification pattern to\n * reveal the associated value only to the WeakMap in which this key\n * is associated with that value. Since only the key retains the\n * function, the function can also remember the key without causing\n * leakage of the key, so this doesn't violate our general gc\n * goals. In addition, because the name need not be a guarded\n * secret, we could efficiently handle cross-frame frozen keys.\n */\n var HIDDEN_NAME_PREFIX = 'weakmap:';\n var HIDDEN_NAME = HIDDEN_NAME_PREFIX + 'ident:' + Math.random() + '___';\n\n if (typeof crypto !== 'undefined' &&\n typeof crypto.getRandomValues === 'function' &&\n typeof ArrayBuffer === 'function' &&\n typeof Uint8Array === 'function') {\n var ab = new ArrayBuffer(25);\n var u8s = new Uint8Array(ab);\n crypto.getRandomValues(u8s);\n HIDDEN_NAME = HIDDEN_NAME_PREFIX + 'rand:' +\n Array.prototype.map.call(u8s, function(u8) {\n return (u8 % 36).toString(36);\n }).join('') + '___';\n }\n\n function isNotHiddenName(name) {\n return !(\n name.substr(0, HIDDEN_NAME_PREFIX.length) == HIDDEN_NAME_PREFIX &&\n name.substr(name.length - 3) === '___');\n }\n\n /**\n * Monkey patch getOwnPropertyNames to avoid revealing the\n * HIDDEN_NAME.\n *\n *
The ES5.1 spec requires each name to appear only once, but as\n * of this writing, this requirement is controversial for ES6, so we\n * made this code robust against this case. If the resulting extra\n * search turns out to be expensive, we can probably relax this once\n * ES6 is adequately supported on all major browsers, iff no browser\n * versions we support at that time have relaxed this constraint\n * without providing built-in ES6 WeakMaps.\n */\n defProp(Object, 'getOwnPropertyNames', {\n value: function fakeGetOwnPropertyNames(obj) {\n return gopn(obj).filter(isNotHiddenName);\n }\n });\n\n /**\n * getPropertyNames is not in ES5 but it is proposed for ES6 and\n * does appear in our whitelist, so we need to clean it too.\n */\n if ('getPropertyNames' in Object) {\n var originalGetPropertyNames = Object.getPropertyNames;\n defProp(Object, 'getPropertyNames', {\n value: function fakeGetPropertyNames(obj) {\n return originalGetPropertyNames(obj).filter(isNotHiddenName);\n }\n });\n }\n\n /**\n *
To treat objects as identity-keys with reasonable efficiency\n * on ES5 by itself (i.e., without any object-keyed collections), we\n * need to add a hidden property to such key objects when we\n * can. This raises several issues:\n *
\n * - Arranging to add this property to objects before we lose the\n * chance, and\n *
- Hiding the existence of this new property from most\n * JavaScript code.\n *
- Preventing certification theft, where one object is\n * created falsely claiming to be the key of an association\n * actually keyed by another object.\n *
- Preventing value theft, where untrusted code with\n * access to a key object but not a weak map nevertheless\n * obtains access to the value associated with that key in that\n * weak map.\n *
\n * We do so by\n * \n * - Making the name of the hidden property unguessable, so \"[]\"\n * indexing, which we cannot intercept, cannot be used to access\n * a property without knowing the name.\n *
- Making the hidden property non-enumerable, so we need not\n * worry about for-in loops or {@code Object.keys},\n *
- monkey patching those reflective methods that would\n * prevent extensions, to add this hidden property first,\n *
- monkey patching those methods that would reveal this\n * hidden property.\n *
\n * Unfortunately, because of same-origin iframes, we cannot reliably\n * add this hidden property before an object becomes\n * non-extensible. Instead, if we encounter a non-extensible object\n * without a hidden record that we can detect (whether or not it has\n * a hidden record stored under a name secret to us), then we just\n * use the key object itself to represent its identity in a brute\n * force leaky map stored in the weak map, losing all the advantages\n * of weakness for these.\n */\n function getHiddenRecord(key) {\n if (key !== Object(key)) {\n throw new TypeError('Not an object: ' + key);\n }\n var hiddenRecord = key[HIDDEN_NAME];\n if (hiddenRecord && hiddenRecord.key === key) { return hiddenRecord; }\n if (!isExtensible(key)) {\n // Weak map must brute force, as explained in doc-comment above.\n return void 0;\n }\n\n // The hiddenRecord and the key point directly at each other, via\n // the \"key\" and HIDDEN_NAME properties respectively. The key\n // field is for quickly verifying that this hidden record is an\n // own property, not a hidden record from up the prototype chain.\n //\n // NOTE: Because this WeakMap emulation is meant only for systems like\n // SES where Object.prototype is frozen without any numeric\n // properties, it is ok to use an object literal for the hiddenRecord.\n // This has two advantages:\n // * It is much faster in a performance critical place\n // * It avoids relying on Object.create(null), which had been\n // problematic on Chrome 28.0.1480.0. See\n // https://code.google.com/p/google-caja/issues/detail?id=1687\n hiddenRecord = { key: key };\n\n // When using this WeakMap emulation on platforms where\n // Object.prototype might not be frozen and Object.create(null) is\n // reliable, use the following two commented out lines instead.\n // hiddenRecord = Object.create(null);\n // hiddenRecord.key = key;\n\n // Please contact us if you need this to work on platforms where\n // Object.prototype might not be frozen and\n // Object.create(null) might not be reliable.\n\n try {\n defProp(key, HIDDEN_NAME, {\n value: hiddenRecord,\n writable: false,\n enumerable: false,\n configurable: false\n });\n return hiddenRecord;\n } catch (error) {\n // Under some circumstances, isExtensible seems to misreport whether\n // the HIDDEN_NAME can be defined.\n // The circumstances have not been isolated, but at least affect\n // Node.js v0.10.26 on TravisCI / Linux, but not the same version of\n // Node.js on OS X.\n return void 0;\n }\n }\n\n /**\n * Monkey patch operations that would make their argument\n * non-extensible.\n *\n * The monkey patched versions throw a TypeError if their\n * argument is not an object, so it should only be done to functions\n * that should throw a TypeError anyway if their argument is not an\n * object.\n */\n (function(){\n var oldFreeze = Object.freeze;\n defProp(Object, 'freeze', {\n value: function identifyingFreeze(obj) {\n getHiddenRecord(obj);\n return oldFreeze(obj);\n }\n });\n var oldSeal = Object.seal;\n defProp(Object, 'seal', {\n value: function identifyingSeal(obj) {\n getHiddenRecord(obj);\n return oldSeal(obj);\n }\n });\n var oldPreventExtensions = Object.preventExtensions;\n defProp(Object, 'preventExtensions', {\n value: function identifyingPreventExtensions(obj) {\n getHiddenRecord(obj);\n return oldPreventExtensions(obj);\n }\n });\n })();\n\n function constFunc(func) {\n func.prototype = null;\n return Object.freeze(func);\n }\n\n var calledAsFunctionWarningDone = false;\n function calledAsFunctionWarning() {\n // Future ES6 WeakMap is currently (2013-09-10) expected to reject WeakMap()\n // but we used to permit it and do it ourselves, so warn only.\n if (!calledAsFunctionWarningDone && typeof console !== 'undefined') {\n calledAsFunctionWarningDone = true;\n console.warn('WeakMap should be invoked as new WeakMap(), not ' +\n 'WeakMap(). This will be an error in the future.');\n }\n }\n\n var nextId = 0;\n\n var OurWeakMap = function() {\n if (!(this instanceof OurWeakMap)) { // approximate test for new ...()\n calledAsFunctionWarning();\n }\n\n // We are currently (12/25/2012) never encountering any prematurely\n // non-extensible keys.\n var keys = []; // brute force for prematurely non-extensible keys.\n var values = []; // brute force for corresponding values.\n var id = nextId++;\n\n function get___(key, opt_default) {\n var index;\n var hiddenRecord = getHiddenRecord(key);\n if (hiddenRecord) {\n return id in hiddenRecord ? hiddenRecord[id] : opt_default;\n } else {\n index = keys.indexOf(key);\n return index >= 0 ? values[index] : opt_default;\n }\n }\n\n function has___(key) {\n var hiddenRecord = getHiddenRecord(key);\n if (hiddenRecord) {\n return id in hiddenRecord;\n } else {\n return keys.indexOf(key) >= 0;\n }\n }\n\n function set___(key, value) {\n var index;\n var hiddenRecord = getHiddenRecord(key);\n if (hiddenRecord) {\n hiddenRecord[id] = value;\n } else {\n index = keys.indexOf(key);\n if (index >= 0) {\n values[index] = value;\n } else {\n // Since some browsers preemptively terminate slow turns but\n // then continue computing with presumably corrupted heap\n // state, we here defensively get keys.length first and then\n // use it to update both the values and keys arrays, keeping\n // them in sync.\n index = keys.length;\n values[index] = value;\n // If we crash here, values will be one longer than keys.\n keys[index] = key;\n }\n }\n return this;\n }\n\n function delete___(key) {\n var hiddenRecord = getHiddenRecord(key);\n var index, lastIndex;\n if (hiddenRecord) {\n return id in hiddenRecord && delete hiddenRecord[id];\n } else {\n index = keys.indexOf(key);\n if (index < 0) {\n return false;\n }\n // Since some browsers preemptively terminate slow turns but\n // then continue computing with potentially corrupted heap\n // state, we here defensively get keys.length first and then use\n // it to update both the keys and the values array, keeping\n // them in sync. We update the two with an order of assignments,\n // such that any prefix of these assignments will preserve the\n // key/value correspondence, either before or after the delete.\n // Note that this needs to work correctly when index === lastIndex.\n lastIndex = keys.length - 1;\n keys[index] = void 0;\n // If we crash here, there's a void 0 in the keys array, but\n // no operation will cause a \"keys.indexOf(void 0)\", since\n // getHiddenRecord(void 0) will always throw an error first.\n values[index] = values[lastIndex];\n // If we crash here, values[index] cannot be found here,\n // because keys[index] is void 0.\n keys[index] = keys[lastIndex];\n // If index === lastIndex and we crash here, then keys[index]\n // is still void 0, since the aliasing killed the previous key.\n keys.length = lastIndex;\n // If we crash here, keys will be one shorter than values.\n values.length = lastIndex;\n return true;\n }\n }\n\n return Object.create(OurWeakMap.prototype, {\n get___: { value: constFunc(get___) },\n has___: { value: constFunc(has___) },\n set___: { value: constFunc(set___) },\n delete___: { value: constFunc(delete___) }\n });\n };\n\n OurWeakMap.prototype = Object.create(Object.prototype, {\n get: {\n /**\n * Return the value most recently associated with key, or\n * opt_default if none.\n */\n value: function get(key, opt_default) {\n return this.get___(key, opt_default);\n },\n writable: true,\n configurable: true\n },\n\n has: {\n /**\n * Is there a value associated with key in this WeakMap?\n */\n value: function has(key) {\n return this.has___(key);\n },\n writable: true,\n configurable: true\n },\n\n set: {\n /**\n * Associate value with key in this WeakMap, overwriting any\n * previous association if present.\n */\n value: function set(key, value) {\n return this.set___(key, value);\n },\n writable: true,\n configurable: true\n },\n\n 'delete': {\n /**\n * Remove any association for key in this WeakMap, returning\n * whether there was one.\n *\n *
Note that the boolean return here does not work like the\n * {@code delete} operator. The {@code delete} operator returns\n * whether the deletion succeeds at bringing about a state in\n * which the deleted property is absent. The {@code delete}\n * operator therefore returns true if the property was already\n * absent, whereas this {@code delete} method returns false if\n * the association was already absent.\n */\n value: function remove(key) {\n return this.delete___(key);\n },\n writable: true,\n configurable: true\n }\n });\n\n if (typeof HostWeakMap === 'function') {\n (function() {\n // If we got here, then the platform has a WeakMap but we are concerned\n // that it may refuse to store some key types. Therefore, make a map\n // implementation which makes use of both as possible.\n\n // In this mode we are always using double maps, so we are not proxy-safe.\n // This combination does not occur in any known browser, but we had best\n // be safe.\n if (doubleWeakMapCheckSilentFailure && typeof Proxy !== 'undefined') {\n Proxy = undefined;\n }\n\n function DoubleWeakMap() {\n if (!(this instanceof OurWeakMap)) { // approximate test for new ...()\n calledAsFunctionWarning();\n }\n\n // Preferable, truly weak map.\n var hmap = new HostWeakMap();\n\n // Our hidden-property-based pseudo-weak-map. Lazily initialized in the\n // 'set' implementation; thus we can avoid performing extra lookups if\n // we know all entries actually stored are entered in 'hmap'.\n var omap = undefined;\n\n // Hidden-property maps are not compatible with proxies because proxies\n // can observe the hidden name and either accidentally expose it or fail\n // to allow the hidden property to be set. Therefore, we do not allow\n // arbitrary WeakMaps to switch to using hidden properties, but only\n // those which need the ability, and unprivileged code is not allowed\n // to set the flag.\n //\n // (Except in doubleWeakMapCheckSilentFailure mode in which case we\n // disable proxies.)\n var enableSwitching = false;\n\n function dget(key, opt_default) {\n if (omap) {\n return hmap.has(key) ? hmap.get(key)\n : omap.get___(key, opt_default);\n } else {\n return hmap.get(key, opt_default);\n }\n }\n\n function dhas(key) {\n return hmap.has(key) || (omap ? omap.has___(key) : false);\n }\n\n var dset;\n if (doubleWeakMapCheckSilentFailure) {\n dset = function(key, value) {\n hmap.set(key, value);\n if (!hmap.has(key)) {\n if (!omap) { omap = new OurWeakMap(); }\n omap.set(key, value);\n }\n return this;\n };\n } else {\n dset = function(key, value) {\n if (enableSwitching) {\n try {\n hmap.set(key, value);\n } catch (e) {\n if (!omap) { omap = new OurWeakMap(); }\n omap.set___(key, value);\n }\n } else {\n hmap.set(key, value);\n }\n return this;\n };\n }\n\n function ddelete(key) {\n var result = !!hmap['delete'](key);\n if (omap) { return omap.delete___(key) || result; }\n return result;\n }\n\n return Object.create(OurWeakMap.prototype, {\n get___: { value: constFunc(dget) },\n has___: { value: constFunc(dhas) },\n set___: { value: constFunc(dset) },\n delete___: { value: constFunc(ddelete) },\n permitHostObjects___: { value: constFunc(function(token) {\n if (token === weakMapPermitHostObjects) {\n enableSwitching = true;\n } else {\n throw new Error('bogus call to permitHostObjects___');\n }\n })}\n });\n }\n DoubleWeakMap.prototype = OurWeakMap.prototype;\n module.exports = DoubleWeakMap;\n\n // define .constructor to hide OurWeakMap ctor\n Object.defineProperty(WeakMap.prototype, 'constructor', {\n value: WeakMap,\n enumerable: false, // as default .constructor is\n configurable: true,\n writable: true\n });\n })();\n } else {\n // There is no host WeakMap, so we must use the emulation.\n\n // Emulated WeakMaps are incompatible with native proxies (because proxies\n // can observe the hidden name), so we must disable Proxy usage (in\n // ArrayLike and Domado, currently).\n if (typeof Proxy !== 'undefined') {\n Proxy = undefined;\n }\n\n module.exports = OurWeakMap;\n }\n})();\n","export default function _arrayLikeToArray(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n\n for (var i = 0, arr2 = new Array(len); i < len; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n}","export default function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}","export default function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nexport default function _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n Object.defineProperty(Constructor, \"prototype\", {\n writable: false\n });\n return Constructor;\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","export default function _extends() {\n _extends = Object.assign || function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n\n return target;\n };\n\n return _extends.apply(this, arguments);\n}","import setPrototypeOf from \"./setPrototypeOf.js\";\nexport default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n setPrototypeOf(subClass, superClass);\n}","import objectWithoutPropertiesLoose from \"./objectWithoutPropertiesLoose.js\";\nexport default function _objectWithoutProperties(source, excluded) {\n if (source == null) return {};\n var target = objectWithoutPropertiesLoose(source, excluded);\n var key, i;\n\n if (Object.getOwnPropertySymbols) {\n var sourceSymbolKeys = Object.getOwnPropertySymbols(source);\n\n for (i = 0; i < sourceSymbolKeys.length; i++) {\n key = sourceSymbolKeys[i];\n if (excluded.indexOf(key) >= 0) continue;\n if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;\n target[key] = source[key];\n }\n }\n\n return target;\n}","export default function _objectWithoutPropertiesLoose(source, excluded) {\n if (source == null) return {};\n var target = {};\n var sourceKeys = Object.keys(source);\n var key, i;\n\n for (i = 0; i < sourceKeys.length; i++) {\n key = sourceKeys[i];\n if (excluded.indexOf(key) >= 0) continue;\n target[key] = source[key];\n }\n\n return target;\n}","export default function _setPrototypeOf(o, p) {\n _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}","import arrayWithHoles from \"./arrayWithHoles.js\";\nimport iterableToArrayLimit from \"./iterableToArrayLimit.js\";\nimport unsupportedIterableToArray from \"./unsupportedIterableToArray.js\";\nimport nonIterableRest from \"./nonIterableRest.js\";\nexport default function _slicedToArray(arr, i) {\n return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();\n}","export default function _arrayWithHoles(arr) {\n if (Array.isArray(arr)) return arr;\n}","export default function _iterableToArrayLimit(arr, i) {\n var _i = arr == null ? null : typeof Symbol !== \"undefined\" && arr[Symbol.iterator] || arr[\"@@iterator\"];\n\n if (_i == null) return;\n var _arr = [];\n var _n = true;\n var _d = false;\n\n var _s, _e;\n\n try {\n for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}","export default function _nonIterableRest() {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}","import arrayWithoutHoles from \"./arrayWithoutHoles.js\";\nimport iterableToArray from \"./iterableToArray.js\";\nimport unsupportedIterableToArray from \"./unsupportedIterableToArray.js\";\nimport nonIterableSpread from \"./nonIterableSpread.js\";\nexport default function _toConsumableArray(arr) {\n return arrayWithoutHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableSpread();\n}","import arrayLikeToArray from \"./arrayLikeToArray.js\";\nexport default function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) return arrayLikeToArray(arr);\n}","export default function _iterableToArray(iter) {\n if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter);\n}","export default function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}","export default function _typeof(obj) {\n \"@babel/helpers - typeof\";\n\n return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (obj) {\n return typeof obj;\n } : function (obj) {\n return obj && \"function\" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n }, _typeof(obj);\n}","import arrayLikeToArray from \"./arrayLikeToArray.js\";\nexport default function _unsupportedIterableToArray(o, minLen) {\n if (!o) return;\n if (typeof o === \"string\") return arrayLikeToArray(o, minLen);\n var n = Object.prototype.toString.call(o).slice(8, -1);\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return Array.from(o);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);\n}","import React, { useMemo, useState, useReducer, useCallback, useEffect, useRef, useContext, useLayoutEffect, forwardRef, useImperativeHandle, Children } from 'react';\nimport { createPortal } from 'react-dom';\nimport isDeepEqual from 'fast-deep-equal';\n\nfunction _extends() {\n return _extends = Object.assign ? Object.assign.bind() : function (n) {\n for (var e = 1; e < arguments.length; e++) {\n var t = arguments[e];\n for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);\n }\n return n;\n }, _extends.apply(null, arguments);\n}\nfunction _objectWithoutPropertiesLoose(r, e) {\n if (null == r) return {};\n var t = {};\n for (var n in r) if ({}.hasOwnProperty.call(r, n)) {\n if (e.includes(n)) continue;\n t[n] = r[n];\n }\n return t;\n}\nfunction _toPrimitive(t, r) {\n if (\"object\" != typeof t || !t) return t;\n var e = t[Symbol.toPrimitive];\n if (void 0 !== e) {\n var i = e.call(t, r || \"default\");\n if (\"object\" != typeof i) return i;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (\"string\" === r ? String : Number)(t);\n}\nfunction _toPropertyKey(t) {\n var i = _toPrimitive(t, \"string\");\n return \"symbol\" == typeof i ? i : i + \"\";\n}\n\nconst APILoadingStatus = {\n NOT_LOADED: 'NOT_LOADED',\n LOADING: 'LOADING',\n LOADED: 'LOADED',\n FAILED: 'FAILED',\n AUTH_FAILURE: 'AUTH_FAILURE'\n};\n\nconst MAPS_API_BASE_URL = 'https://maps.googleapis.com/maps/api/js';\n/**\n * A GoogleMapsApiLoader to reliably load and unload the Google Maps JavaScript API.\n *\n * The actual loading and unloading is delayed into the microtask queue, to\n * allow using the API in an useEffect hook, without worrying about multiple API loads.\n */\nclass GoogleMapsApiLoader {\n /**\n * Loads the Maps JavaScript API with the specified parameters.\n * Since the Maps library can only be loaded once per page, this will\n * produce a warning when called multiple times with different\n * parameters.\n *\n * The returned promise resolves when loading completes\n * and rejects in case of an error or when the loading was aborted.\n */\n static async load(params, onLoadingStatusChange) {\n var _window$google;\n const libraries = params.libraries ? params.libraries.split(',') : [];\n const serializedParams = this.serializeParams(params);\n this.listeners.push(onLoadingStatusChange);\n // Note: if `google.maps.importLibrary` has been defined externally, we\n // assume that loading is complete and successful.\n // If it was defined by a previous call to this method, a warning\n // message is logged if there are differences in api-parameters used\n // for both calls.\n if ((_window$google = window.google) != null && (_window$google = _window$google.maps) != null && _window$google.importLibrary) {\n // no serialized parameters means it was loaded externally\n if (!this.serializedApiParams) {\n this.loadingStatus = APILoadingStatus.LOADED;\n }\n this.notifyLoadingStatusListeners();\n } else {\n this.serializedApiParams = serializedParams;\n this.initImportLibrary(params);\n }\n if (this.serializedApiParams && this.serializedApiParams !== serializedParams) {\n 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.`);\n }\n const librariesToLoad = ['maps', ...libraries];\n await Promise.all(librariesToLoad.map(name => google.maps.importLibrary(name)));\n }\n /**\n * Serialize the parameters used to load the library for easier comparison.\n */\n static serializeParams(params) {\n return [params.v, params.key, params.language, params.region, params.authReferrerPolicy, params.solutionChannel].join('/');\n }\n /**\n * Creates the global `google.maps.importLibrary` function for bootstrapping.\n * This is essentially a formatted version of the dynamic loading script\n * from the official documentation with some minor adjustments.\n *\n * The created importLibrary function will load the Google Maps JavaScript API,\n * which will then replace the `google.maps.importLibrary` function with the full\n * implementation.\n *\n * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import\n */\n static initImportLibrary(params) {\n if (!window.google) window.google = {};\n if (!window.google.maps) window.google.maps = {};\n if (window.google.maps['importLibrary']) {\n console.error('[google-maps-api-loader-internal]: initImportLibrary must only be called once');\n return;\n }\n let apiPromise = null;\n const loadApi = () => {\n if (apiPromise) return apiPromise;\n apiPromise = new Promise((resolve, reject) => {\n var _document$querySelect;\n const scriptElement = document.createElement('script');\n const urlParams = new URLSearchParams();\n for (const [key, value] of Object.entries(params)) {\n const urlParamName = key.replace(/[A-Z]/g, t => '_' + t[0].toLowerCase());\n urlParams.set(urlParamName, String(value));\n }\n urlParams.set('loading', 'async');\n urlParams.set('callback', '__googleMapsCallback__');\n scriptElement.async = true;\n scriptElement.src = MAPS_API_BASE_URL + `?` + urlParams.toString();\n scriptElement.nonce = ((_document$querySelect = document.querySelector('script[nonce]')) == null ? void 0 : _document$querySelect.nonce) || '';\n scriptElement.onerror = () => {\n this.loadingStatus = APILoadingStatus.FAILED;\n this.notifyLoadingStatusListeners();\n reject(new Error('The Google Maps JavaScript API could not load.'));\n };\n window.__googleMapsCallback__ = () => {\n this.loadingStatus = APILoadingStatus.LOADED;\n this.notifyLoadingStatusListeners();\n resolve();\n };\n window.gm_authFailure = () => {\n this.loadingStatus = APILoadingStatus.AUTH_FAILURE;\n this.notifyLoadingStatusListeners();\n };\n this.loadingStatus = APILoadingStatus.LOADING;\n this.notifyLoadingStatusListeners();\n document.head.append(scriptElement);\n });\n return apiPromise;\n };\n // for the first load, we declare an importLibrary function that will\n // be overwritten once the api is loaded.\n google.maps.importLibrary = libraryName => loadApi().then(() => google.maps.importLibrary(libraryName));\n }\n /**\n * Calls all registered loadingStatusListeners after a status update.\n */\n static notifyLoadingStatusListeners() {\n for (const fn of this.listeners) {\n fn(this.loadingStatus);\n }\n }\n}\n/**\n * The current loadingStatus of the API.\n */\nGoogleMapsApiLoader.loadingStatus = APILoadingStatus.NOT_LOADED;\n/**\n * The parameters used for first loading the API.\n */\nGoogleMapsApiLoader.serializedApiParams = void 0;\n/**\n * A list of functions to be notified when the loading status changes.\n */\nGoogleMapsApiLoader.listeners = [];\n\nconst _excluded$3 = [\"onLoad\", \"onError\", \"apiKey\", \"version\", \"libraries\"],\n _excluded2$1 = [\"children\"];\nconst DEFAULT_SOLUTION_CHANNEL = 'GMP_visgl_rgmlibrary_v1_default';\nconst APIProviderContext = React.createContext(null);\n/**\n * local hook to set up the map-instance management context.\n */\nfunction useMapInstances() {\n const [mapInstances, setMapInstances] = useState({});\n const addMapInstance = (mapInstance, id = 'default') => {\n setMapInstances(instances => _extends({}, instances, {\n [id]: mapInstance\n }));\n };\n const removeMapInstance = (id = 'default') => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n setMapInstances(_ref => {\n let remaining = _objectWithoutPropertiesLoose(_ref, [id].map(_toPropertyKey));\n return remaining;\n });\n };\n const clearMapInstances = () => {\n setMapInstances({});\n };\n return {\n mapInstances,\n addMapInstance,\n removeMapInstance,\n clearMapInstances\n };\n}\n/**\n * local hook to handle the loading of the maps API, returns the current loading status\n * @param props\n */\nfunction useGoogleMapsApiLoader(props) {\n const {\n onLoad,\n onError,\n apiKey,\n version,\n libraries = []\n } = props,\n otherApiParams = _objectWithoutPropertiesLoose(props, _excluded$3);\n const [status, setStatus] = useState(GoogleMapsApiLoader.loadingStatus);\n const [loadedLibraries, addLoadedLibrary] = useReducer((loadedLibraries, action) => {\n return loadedLibraries[action.name] ? loadedLibraries : _extends({}, loadedLibraries, {\n [action.name]: action.value\n });\n }, {});\n const librariesString = useMemo(() => libraries == null ? void 0 : libraries.join(','), [libraries]);\n const serializedParams = useMemo(() => JSON.stringify(_extends({\n apiKey,\n version\n }, otherApiParams)), [apiKey, version, otherApiParams]);\n const importLibrary = useCallback(async name => {\n var _google;\n if (loadedLibraries[name]) {\n return loadedLibraries[name];\n }\n if (!((_google = google) != null && (_google = _google.maps) != null && _google.importLibrary)) {\n throw new Error('[api-provider-internal] importLibrary was called before ' + 'google.maps.importLibrary was defined.');\n }\n const res = await window.google.maps.importLibrary(name);\n addLoadedLibrary({\n name,\n value: res\n });\n return res;\n }, [loadedLibraries]);\n useEffect(() => {\n (async () => {\n try {\n const params = _extends({\n key: apiKey\n }, otherApiParams);\n if (version) params.v = version;\n if ((librariesString == null ? void 0 : librariesString.length) > 0) params.libraries = librariesString;\n if (params.channel === undefined || params.channel < 0 || params.channel > 999) delete params.channel;\n if (params.solutionChannel === undefined) params.solutionChannel = DEFAULT_SOLUTION_CHANNEL;else if (params.solutionChannel === '') delete params.solutionChannel;\n await GoogleMapsApiLoader.load(params, status => setStatus(status));\n for (const name of ['core', 'maps', ...libraries]) {\n await importLibrary(name);\n }\n if (onLoad) {\n onLoad();\n }\n } catch (error) {\n if (onError) {\n onError(error);\n } else {\n console.error(' failed to load the Google Maps JavaScript API', error);\n }\n }\n })();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [apiKey, librariesString, serializedParams]);\n return {\n status,\n loadedLibraries,\n importLibrary\n };\n}\n/**\n * Component to wrap the components from this library and load the Google Maps JavaScript API\n */\nconst APIProvider = props => {\n const {\n children\n } = props,\n loaderProps = _objectWithoutPropertiesLoose(props, _excluded2$1);\n const {\n mapInstances,\n addMapInstance,\n removeMapInstance,\n clearMapInstances\n } = useMapInstances();\n const {\n status,\n loadedLibraries,\n importLibrary\n } = useGoogleMapsApiLoader(loaderProps);\n const contextValue = useMemo(() => ({\n mapInstances,\n addMapInstance,\n removeMapInstance,\n clearMapInstances,\n status,\n loadedLibraries,\n importLibrary\n }), [mapInstances, addMapInstance, removeMapInstance, clearMapInstances, status, loadedLibraries, importLibrary]);\n return /*#__PURE__*/React.createElement(APIProviderContext.Provider, {\n value: contextValue\n }, children);\n};\n\n/**\n * Sets up effects to bind event-handlers for all event-props in MapEventProps.\n * @internal\n */\nfunction useMapEvents(map, props) {\n // note: calling a useEffect hook from within a loop is prohibited by the\n // rules of hooks, but it's ok here since it's unconditional and the number\n // and order of iterations is always strictly the same.\n // (see https://legacy.reactjs.org/docs/hooks-rules.html)\n for (const propName of eventPropNames) {\n // fixme: this cast is essentially a 'trust me, bro' for typescript, but\n // a proper solution seems way too complicated right now\n const handler = props[propName];\n const eventType = propNameToEventType[propName];\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (!map) return;\n if (!handler) return;\n const listener = google.maps.event.addListener(map, eventType, ev => {\n handler(createMapEvent(eventType, map, ev));\n });\n return () => listener.remove();\n }, [map, eventType, handler]);\n }\n}\n/**\n * Create the wrapped map-events used for the event-props.\n * @param type the event type as it is specified to the maps api\n * @param map the map instance the event originates from\n * @param srcEvent the source-event if there is one.\n */\nfunction createMapEvent(type, map, srcEvent) {\n const ev = {\n type,\n map,\n detail: {},\n stoppable: false,\n stop: () => {}\n };\n if (cameraEventTypes.includes(type)) {\n const camEvent = ev;\n const center = map.getCenter();\n const zoom = map.getZoom();\n const heading = map.getHeading() || 0;\n const tilt = map.getTilt() || 0;\n const bounds = map.getBounds();\n if (!center || !bounds || !Number.isFinite(zoom)) {\n 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');\n }\n camEvent.detail = {\n center: (center == null ? void 0 : center.toJSON()) || {\n lat: 0,\n lng: 0\n },\n zoom: zoom || 0,\n heading: heading,\n tilt: tilt,\n bounds: (bounds == null ? void 0 : bounds.toJSON()) || {\n north: 90,\n east: 180,\n south: -90,\n west: -180\n }\n };\n return camEvent;\n } else if (mouseEventTypes.includes(type)) {\n var _srcEvent$latLng;\n if (!srcEvent) throw new Error('[createEvent] mouse events must provide a srcEvent');\n const mouseEvent = ev;\n mouseEvent.domEvent = srcEvent.domEvent;\n mouseEvent.stoppable = true;\n mouseEvent.stop = () => srcEvent.stop();\n mouseEvent.detail = {\n latLng: ((_srcEvent$latLng = srcEvent.latLng) == null ? void 0 : _srcEvent$latLng.toJSON()) || null,\n placeId: srcEvent.placeId\n };\n return mouseEvent;\n }\n return ev;\n}\n/**\n * maps the camelCased names of event-props to the corresponding event-types\n * used in the maps API.\n */\nconst propNameToEventType = {\n onBoundsChanged: 'bounds_changed',\n onCenterChanged: 'center_changed',\n onClick: 'click',\n onContextmenu: 'contextmenu',\n onDblclick: 'dblclick',\n onDrag: 'drag',\n onDragend: 'dragend',\n onDragstart: 'dragstart',\n onHeadingChanged: 'heading_changed',\n onIdle: 'idle',\n onIsFractionalZoomEnabledChanged: 'isfractionalzoomenabled_changed',\n onMapCapabilitiesChanged: 'mapcapabilities_changed',\n onMapTypeIdChanged: 'maptypeid_changed',\n onMousemove: 'mousemove',\n onMouseout: 'mouseout',\n onMouseover: 'mouseover',\n onProjectionChanged: 'projection_changed',\n onRenderingTypeChanged: 'renderingtype_changed',\n onTilesLoaded: 'tilesloaded',\n onTiltChanged: 'tilt_changed',\n onZoomChanged: 'zoom_changed',\n // note: onCameraChanged is an alias for the bounds_changed event,\n // since that is going to be fired in every situation where the camera is\n // updated.\n onCameraChanged: 'bounds_changed'\n};\nconst cameraEventTypes = ['bounds_changed', 'center_changed', 'heading_changed', 'tilt_changed', 'zoom_changed'];\nconst mouseEventTypes = ['click', 'contextmenu', 'dblclick', 'mousemove', 'mouseout', 'mouseover'];\nconst eventPropNames = Object.keys(propNameToEventType);\n\nfunction useDeepCompareEffect(effect, deps) {\n const ref = useRef(undefined);\n if (!ref.current || !isDeepEqual(deps, ref.current)) {\n ref.current = deps;\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(effect, ref.current);\n}\n\nconst mapOptionKeys = 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']);\n/**\n * Internal hook to update the map-options when props are changed.\n *\n * @param map the map instance\n * @param mapProps the props to update the map-instance with\n * @internal\n */\nfunction useMapOptions(map, mapProps) {\n /* eslint-disable react-hooks/exhaustive-deps --\n *\n * The following effects aren't triggered when the map is changed.\n * In that case, the values will be or have been passed to the map\n * constructor via mapOptions.\n */\n const mapOptions = {};\n const keys = Object.keys(mapProps);\n for (const key of keys) {\n if (!mapOptionKeys.has(key)) continue;\n mapOptions[key] = mapProps[key];\n }\n // update the map options when mapOptions is changed\n // Note: due to the destructuring above, mapOptions will be seen as changed\n // with every re-render, so we're assuming the maps-api will properly\n // deal with unchanged option-values passed into setOptions.\n useDeepCompareEffect(() => {\n if (!map) return;\n map.setOptions(mapOptions);\n }, [mapOptions]);\n /* eslint-enable react-hooks/exhaustive-deps */\n}\n\nfunction useApiLoadingStatus() {\n var _useContext;\n return ((_useContext = useContext(APIProviderContext)) == null ? void 0 : _useContext.status) || APILoadingStatus.NOT_LOADED;\n}\n\n/**\n * Internal hook that updates the camera when deck.gl viewState changes.\n * @internal\n */\nfunction useDeckGLCameraUpdate(map, props) {\n const {\n viewport,\n viewState\n } = props;\n const isDeckGlControlled = !!viewport;\n useLayoutEffect(() => {\n if (!map || !viewState) return;\n const {\n latitude,\n longitude,\n bearing: heading,\n pitch: tilt,\n zoom\n } = viewState;\n map.moveCamera({\n center: {\n lat: latitude,\n lng: longitude\n },\n heading,\n tilt,\n zoom: zoom + 1\n });\n }, [map, viewState]);\n return isDeckGlControlled;\n}\n\nfunction isLatLngLiteral(obj) {\n if (!obj || typeof obj !== 'object') return false;\n if (!('lat' in obj && 'lng' in obj)) return false;\n return Number.isFinite(obj.lat) && Number.isFinite(obj.lng);\n}\nfunction latLngEquals(a, b) {\n if (!a || !b) return false;\n const A = toLatLngLiteral(a);\n const B = toLatLngLiteral(b);\n if (A.lat !== B.lat || A.lng !== B.lng) return false;\n return true;\n}\nfunction toLatLngLiteral(obj) {\n if (isLatLngLiteral(obj)) return obj;\n return obj.toJSON();\n}\n\nfunction useMapCameraParams(map, cameraStateRef, mapProps) {\n const center = mapProps.center ? toLatLngLiteral(mapProps.center) : null;\n let lat = null;\n let lng = null;\n if (center && Number.isFinite(center.lat) && Number.isFinite(center.lng)) {\n lat = center.lat;\n lng = center.lng;\n }\n const zoom = Number.isFinite(mapProps.zoom) ? mapProps.zoom : null;\n const heading = Number.isFinite(mapProps.heading) ? mapProps.heading : null;\n const tilt = Number.isFinite(mapProps.tilt) ? mapProps.tilt : null;\n // the following effect runs for every render of the map component and checks\n // if there are differences between the known state of the map instance\n // (cameraStateRef, which is updated by all bounds_changed events) and the\n // desired state in the props.\n useLayoutEffect(() => {\n if (!map) return;\n const nextCamera = {};\n let needsUpdate = false;\n if (lat !== null && lng !== null && (cameraStateRef.current.center.lat !== lat || cameraStateRef.current.center.lng !== lng)) {\n nextCamera.center = {\n lat,\n lng\n };\n needsUpdate = true;\n }\n if (zoom !== null && cameraStateRef.current.zoom !== zoom) {\n nextCamera.zoom = zoom;\n needsUpdate = true;\n }\n if (heading !== null && cameraStateRef.current.heading !== heading) {\n nextCamera.heading = heading;\n needsUpdate = true;\n }\n if (tilt !== null && cameraStateRef.current.tilt !== tilt) {\n nextCamera.tilt = tilt;\n needsUpdate = true;\n }\n if (needsUpdate) {\n map.moveCamera(nextCamera);\n }\n });\n}\n\nconst AuthFailureMessage = () => {\n const style = {\n position: 'absolute',\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n zIndex: 999,\n display: 'flex',\n flexFlow: 'column nowrap',\n textAlign: 'center',\n justifyContent: 'center',\n fontSize: '.8rem',\n color: 'rgba(0,0,0,0.6)',\n background: '#dddddd',\n padding: '1rem 1.5rem'\n };\n return /*#__PURE__*/React.createElement(\"div\", {\n style: style\n }, /*#__PURE__*/React.createElement(\"h2\", null, \"Error: AuthFailure\"), /*#__PURE__*/React.createElement(\"p\", null, \"A problem with your API key prevents the map from rendering correctly. Please make sure the value of the \", /*#__PURE__*/React.createElement(\"code\", null, \"APIProvider.apiKey\"), \" prop is correct. Check the error-message in the console for further details.\"));\n};\n\nfunction useCallbackRef() {\n const [el, setEl] = useState(null);\n const ref = useCallback(value => setEl(value), [setEl]);\n return [el, ref];\n}\n\n/**\n * Hook to check if the Maps JavaScript API is loaded\n */\nfunction useApiIsLoaded() {\n const status = useApiLoadingStatus();\n return status === APILoadingStatus.LOADED;\n}\n\nfunction useForceUpdate() {\n const [, forceUpdate] = useReducer(x => x + 1, 0);\n return forceUpdate;\n}\n\nfunction handleBoundsChange(map, ref) {\n const center = map.getCenter();\n const zoom = map.getZoom();\n const heading = map.getHeading() || 0;\n const tilt = map.getTilt() || 0;\n const bounds = map.getBounds();\n if (!center || !bounds || !Number.isFinite(zoom)) {\n 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');\n }\n // fixme: do we need the `undefined` cases for the camera-params? When are they used in the maps API?\n Object.assign(ref.current, {\n center: (center == null ? void 0 : center.toJSON()) || {\n lat: 0,\n lng: 0\n },\n zoom: zoom || 0,\n heading: heading,\n tilt: tilt\n });\n}\n/**\n * Creates a mutable ref object to track the last known state of the map camera.\n * This is used in `useMapCameraParams` to reduce stuttering in normal operation\n * by avoiding updates of the map camera with values that have already been processed.\n */\nfunction useTrackedCameraStateRef(map) {\n const forceUpdate = useForceUpdate();\n const ref = useRef({\n center: {\n lat: 0,\n lng: 0\n },\n heading: 0,\n tilt: 0,\n zoom: 0\n });\n // Record camera state with every bounds_changed event dispatched by the map.\n // This data is used to prevent feeding these values back to the\n // map-instance when a typical \"controlled component\" setup (state variable is\n // fed into and updated by the map).\n useEffect(() => {\n if (!map) return;\n const listener = google.maps.event.addListener(map, 'bounds_changed', () => {\n handleBoundsChange(map, ref);\n // When an event is occured, we have to update during the next cycle.\n // The application could decide to ignore the event and not update any\n // camera props of the map, meaning that in that case we will have to\n // 'undo' the change to the camera.\n forceUpdate();\n });\n return () => listener.remove();\n }, [map, forceUpdate]);\n return ref;\n}\n\nconst _excluded$2 = [\"id\", \"defaultBounds\", \"defaultCenter\", \"defaultZoom\", \"defaultHeading\", \"defaultTilt\", \"reuseMaps\", \"renderingType\", \"colorScheme\"],\n _excluded2 = [\"padding\"];\n/**\n * Stores a stack of map-instances for each mapId. Whenever an\n * instance is used, it is removed from the stack while in use,\n * and returned to the stack when the component unmounts.\n * This allows us to correctly implement caching for multiple\n * maps om the same page, while reusing as much as possible.\n *\n * FIXME: while it should in theory be possible to reuse maps solely\n * based on the mapId (as all other parameters can be changed at\n * runtime), we don't yet have good enough tracking of options to\n * reliably unset all the options that have been set.\n */\nclass CachedMapStack {\n static has(key) {\n return this.entries[key] && this.entries[key].length > 0;\n }\n static pop(key) {\n if (!this.entries[key]) return null;\n return this.entries[key].pop() || null;\n }\n static push(key, value) {\n if (!this.entries[key]) this.entries[key] = [];\n this.entries[key].push(value);\n }\n}\n/**\n * The main hook takes care of creating map-instances and registering them in\n * the api-provider context.\n * @return a tuple of the map-instance created (or null) and the callback\n * ref that will be used to pass the map-container into this hook.\n * @internal\n */\nCachedMapStack.entries = {};\nfunction useMapInstance(props, context) {\n const apiIsLoaded = useApiIsLoaded();\n const [map, setMap] = useState(null);\n const [container, containerRef] = useCallbackRef();\n const cameraStateRef = useTrackedCameraStateRef(map);\n const {\n id,\n defaultBounds,\n defaultCenter,\n defaultZoom,\n defaultHeading,\n defaultTilt,\n reuseMaps,\n renderingType,\n colorScheme\n } = props,\n mapOptions = _objectWithoutPropertiesLoose(props, _excluded$2);\n const hasZoom = props.zoom !== undefined || props.defaultZoom !== undefined;\n const hasCenter = props.center !== undefined || props.defaultCenter !== undefined;\n if (!defaultBounds && (!hasZoom || !hasCenter)) {\n console.warn('