- // modules/core/locations.js
- var _mainLocations = coreLocations();
- function coreLocations() {
- let _this = {};
- let _resolvedFeatures = {};
- let _loco = new location_conflation_default();
- let _wp;
- const world = { locationSet: { include: ["Q2"] } };
- resolveLocationSet(world);
- rebuildIndex();
- let _queue = [];
- let _deferred2 = /* @__PURE__ */ new Set();
- let _inProcess;
- function processQueue() {
- if (!_queue.length)
- return Promise.resolve();
- const chunk = _queue.pop();
- return new Promise((resolvePromise) => {
- const handle = window.requestIdleCallback(() => {
- _deferred2.delete(handle);
- chunk.forEach(resolveLocationSet);
- resolvePromise();
- });
- _deferred2.add(handle);
- }).then(() => processQueue());
- }
- function resolveLocationSet(obj) {
- if (obj.locationSetID)
- return;
- try {
- let locationSet = obj.locationSet;
- if (!locationSet) {
- throw new Error("object missing locationSet property");
- }
- if (!locationSet.include) {
- locationSet.include = ["Q2"];
- }
- const resolved = _loco.resolveLocationSet(locationSet);
- const locationSetID = resolved.id;
- obj.locationSetID = locationSetID;
- if (!resolved.feature.geometry.coordinates.length || !resolved.feature.properties.area) {
- throw new Error(`locationSet ${locationSetID} resolves to an empty feature.`);
- }
- if (!_resolvedFeatures[locationSetID]) {
- let feature3 = JSON.parse(JSON.stringify(resolved.feature));
- feature3.id = locationSetID;
- feature3.properties.id = locationSetID;
- _resolvedFeatures[locationSetID] = feature3;
- }
- } catch (err) {
- obj.locationSet = { include: ["Q2"] };
- obj.locationSetID = "+[Q2]";
- }
- }
- function rebuildIndex() {
- _wp = (0, import_which_polygon2.default)({ features: Object.values(_resolvedFeatures) });
- }
- _this.mergeCustomGeoJSON = (fc) => {
- if (fc && fc.type === "FeatureCollection" && Array.isArray(fc.features)) {
- fc.features.forEach((feature3) => {
- feature3.properties = feature3.properties || {};
- let props = feature3.properties;
- let id2 = feature3.id || props.id;
- if (!id2 || !/^\S+\.geojson$/i.test(id2))
- return;
- id2 = id2.toLowerCase();
- feature3.id = id2;
- props.id = id2;
- if (!props.area) {
- const area = import_geojson_area2.default.geometry(feature3.geometry) / 1e6;
- props.area = Number(area.toFixed(2));
- }
- _loco._cache[id2] = feature3;
- });
- }
- };
- _this.mergeLocationSets = (objects) => {
- if (!Array.isArray(objects))
- return Promise.reject("nothing to do");
- _queue = _queue.concat(utilArrayChunk(objects, 200));
- if (!_inProcess) {
- _inProcess = processQueue().then(() => {
- rebuildIndex();
- _inProcess = null;
- return objects;
- });
- }
- return _inProcess;
- };
- _this.locationSetID = (locationSet) => {
- let locationSetID;
- try {
- locationSetID = _loco.validateLocationSet(locationSet).id;
- } catch (err) {
- locationSetID = "+[Q2]";
- }
- return locationSetID;
- };
- _this.feature = (locationSetID) => _resolvedFeatures[locationSetID] || _resolvedFeatures["+[Q2]"];
- _this.locationsAt = (loc) => {
- let result = {};
- (_wp(loc, true) || []).forEach((prop) => result[prop.id] = prop.area);
- return result;
- };
- _this.query = (loc, multi) => _wp(loc, multi);
- _this.loco = () => _loco;
- _this.wp = () => _wp;
- return _this;
- }
-
- // node_modules/lodash-es/_freeGlobal.js
- var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
- var freeGlobal_default = freeGlobal;
-
- // node_modules/lodash-es/_root.js
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
- var root2 = freeGlobal_default || freeSelf || Function("return this")();
- var root_default = root2;
-
- // node_modules/lodash-es/_Symbol.js
- var Symbol2 = root_default.Symbol;
- var Symbol_default = Symbol2;
-
- // node_modules/lodash-es/_getRawTag.js
- var objectProto = Object.prototype;
- var hasOwnProperty = objectProto.hasOwnProperty;
- var nativeObjectToString = objectProto.toString;
- var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
- function getRawTag(value) {
- var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
- try {
- value[symToStringTag] = void 0;
- var unmasked = true;
- } catch (e) {
- }
- var result = nativeObjectToString.call(value);
- if (unmasked) {
- if (isOwn) {
- value[symToStringTag] = tag;
- } else {
- delete value[symToStringTag];
- }
- }
- return result;
- }
- var getRawTag_default = getRawTag;
-
- // node_modules/lodash-es/_objectToString.js
- var objectProto2 = Object.prototype;
- var nativeObjectToString2 = objectProto2.toString;
- function objectToString(value) {
- return nativeObjectToString2.call(value);
- }
- var objectToString_default = objectToString;
-
- // node_modules/lodash-es/_baseGetTag.js
- var nullTag = "[object Null]";
- var undefinedTag = "[object Undefined]";
- var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
- function baseGetTag(value) {
- if (value == null) {
- return value === void 0 ? undefinedTag : nullTag;
- }
- return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
- }
- var baseGetTag_default = baseGetTag;
-
- // node_modules/lodash-es/isObjectLike.js
- function isObjectLike(value) {
- return value != null && typeof value == "object";
- }
- var isObjectLike_default = isObjectLike;
-
- // node_modules/lodash-es/isSymbol.js
- var symbolTag = "[object Symbol]";
- function isSymbol(value) {
- return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
- }
- var isSymbol_default = isSymbol;
-
- // node_modules/lodash-es/_arrayMap.js
- function arrayMap(array2, iteratee) {
- var index = -1, length = array2 == null ? 0 : array2.length, result = Array(length);
- while (++index < length) {
- result[index] = iteratee(array2[index], index, array2);
- }
- return result;
- }
- var arrayMap_default = arrayMap;
-
- // node_modules/lodash-es/isArray.js
- var isArray = Array.isArray;
- var isArray_default = isArray;
-
- // node_modules/lodash-es/_baseToString.js
- var INFINITY = 1 / 0;
- var symbolProto = Symbol_default ? Symbol_default.prototype : void 0;
- var symbolToString = symbolProto ? symbolProto.toString : void 0;
- function baseToString(value) {
- if (typeof value == "string") {
- return value;
- }
- if (isArray_default(value)) {
- return arrayMap_default(value, baseToString) + "";
- }
- if (isSymbol_default(value)) {
- return symbolToString ? symbolToString.call(value) : "";
- }
- var result = value + "";
- return result == "0" && 1 / value == -INFINITY ? "-0" : result;
- }
- var baseToString_default = baseToString;
-
- // node_modules/lodash-es/_trimmedEndIndex.js
- var reWhitespace = /\s/;
- function trimmedEndIndex(string) {
- var index = string.length;
- while (index-- && reWhitespace.test(string.charAt(index))) {
- }
- return index;
- }
- var trimmedEndIndex_default = trimmedEndIndex;
-
- // node_modules/lodash-es/_baseTrim.js
- var reTrimStart = /^\s+/;
- function baseTrim(string) {
- return string ? string.slice(0, trimmedEndIndex_default(string) + 1).replace(reTrimStart, "") : string;
- }
- var baseTrim_default = baseTrim;
-
- // node_modules/lodash-es/isObject.js
- function isObject(value) {
- var type3 = typeof value;
- return value != null && (type3 == "object" || type3 == "function");
- }
- var isObject_default = isObject;
-
- // node_modules/lodash-es/toNumber.js
- var NAN = 0 / 0;
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
- var reIsBinary = /^0b[01]+$/i;
- var reIsOctal = /^0o[0-7]+$/i;
- var freeParseInt = parseInt;
- function toNumber(value) {
- if (typeof value == "number") {
- return value;
- }
- if (isSymbol_default(value)) {
- return NAN;
- }
- if (isObject_default(value)) {
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
- value = isObject_default(other) ? other + "" : other;
- }
- if (typeof value != "string") {
- return value === 0 ? value : +value;
- }
- value = baseTrim_default(value);
- var isBinary = reIsBinary.test(value);
- return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
- }
- var toNumber_default = toNumber;
-
- // node_modules/lodash-es/toString.js
- function toString(value) {
- return value == null ? "" : baseToString_default(value);
- }
- var toString_default = toString;
-
- // node_modules/lodash-es/_basePropertyOf.js
- function basePropertyOf(object) {
- return function(key) {
- return object == null ? void 0 : object[key];
- };
- }
- var basePropertyOf_default = basePropertyOf;
-
- // node_modules/lodash-es/now.js
- var now2 = function() {
- return root_default.Date.now();
- };
- var now_default = now2;
-
- // node_modules/lodash-es/debounce.js
- var FUNC_ERROR_TEXT = "Expected a function";
- var nativeMax = Math.max;
- var nativeMin = Math.min;
- function debounce(func, wait, options2) {
- var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
- if (typeof func != "function") {
- throw new TypeError(FUNC_ERROR_TEXT);
- }
- wait = toNumber_default(wait) || 0;
- if (isObject_default(options2)) {
- leading = !!options2.leading;
- maxing = "maxWait" in options2;
- maxWait = maxing ? nativeMax(toNumber_default(options2.maxWait) || 0, wait) : maxWait;
- trailing = "trailing" in options2 ? !!options2.trailing : trailing;
- }
- function invokeFunc(time) {
- var args = lastArgs, thisArg = lastThis;
- lastArgs = lastThis = void 0;
- lastInvokeTime = time;
- result = func.apply(thisArg, args);
- return result;
- }
- function leadingEdge(time) {
- lastInvokeTime = time;
- timerId = setTimeout(timerExpired, wait);
- return leading ? invokeFunc(time) : result;
- }
- function remainingWait(time) {
- var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
- return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
- }
- function shouldInvoke(time) {
- var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
- return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
- }
- function timerExpired() {
- var time = now_default();
- if (shouldInvoke(time)) {
- return trailingEdge(time);
- }
- timerId = setTimeout(timerExpired, remainingWait(time));
- }
- function trailingEdge(time) {
- timerId = void 0;
- if (trailing && lastArgs) {
- return invokeFunc(time);
- }
- lastArgs = lastThis = void 0;
- return result;
- }
- function cancel() {
- if (timerId !== void 0) {
- clearTimeout(timerId);
- }
- lastInvokeTime = 0;
- lastArgs = lastCallTime = lastThis = timerId = void 0;
- }
- function flush() {
- return timerId === void 0 ? result : trailingEdge(now_default());
- }
- function debounced() {
- var time = now_default(), isInvoking = shouldInvoke(time);
- lastArgs = arguments;
- lastThis = this;
- lastCallTime = time;
- if (isInvoking) {
- if (timerId === void 0) {
- return leadingEdge(lastCallTime);
- }
- if (maxing) {
- clearTimeout(timerId);
- timerId = setTimeout(timerExpired, wait);
- return invokeFunc(lastCallTime);
- }
- }
- if (timerId === void 0) {
- timerId = setTimeout(timerExpired, wait);
- }
- return result;
- }
- debounced.cancel = cancel;
- debounced.flush = flush;
- return debounced;
- }
- var debounce_default = debounce;
-
- // node_modules/lodash-es/_escapeHtmlChar.js
- var htmlEscapes = {
- "&": "&",
- "<": "<",
- ">": ">",
- '"': """,
- "'": "'"
- };
- var escapeHtmlChar = basePropertyOf_default(htmlEscapes);
- var escapeHtmlChar_default = escapeHtmlChar;
-
- // node_modules/lodash-es/escape.js
- var reUnescapedHtml = /[&<>"']/g;
- var reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
- function escape2(string) {
- string = toString_default(string);
- return string && reHasUnescapedHtml.test(string) ? string.replace(reUnescapedHtml, escapeHtmlChar_default) : string;
- }
- var escape_default = escape2;
-
- // node_modules/lodash-es/throttle.js
- var FUNC_ERROR_TEXT2 = "Expected a function";
- function throttle(func, wait, options2) {
- var leading = true, trailing = true;
- if (typeof func != "function") {
- throw new TypeError(FUNC_ERROR_TEXT2);
- }
- if (isObject_default(options2)) {
- leading = "leading" in options2 ? !!options2.leading : leading;
- trailing = "trailing" in options2 ? !!options2.trailing : trailing;
- }
- return debounce_default(func, wait, {
- "leading": leading,
- "maxWait": wait,
- "trailing": trailing
- });
- }
- var throttle_default = throttle;
-
- // node_modules/lodash-es/_unescapeHtmlChar.js
- var htmlUnescapes = {
- "&": "&",
- "<": "<",
- ">": ">",
- """: '"',
- "'": "'"
- };
- var unescapeHtmlChar = basePropertyOf_default(htmlUnescapes);
- var unescapeHtmlChar_default = unescapeHtmlChar;
-
- // node_modules/lodash-es/unescape.js
- var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g;
- var reHasEscapedHtml = RegExp(reEscapedHtml.source);
- function unescape2(string) {
- string = toString_default(string);
- return string && reHasEscapedHtml.test(string) ? string.replace(reEscapedHtml, unescapeHtmlChar_default) : string;
- }
- var unescape_default = unescape2;
-