UNPKG

@rapideditor/location-conflation

Version:

Define complex geographic regions by including and excluding country codes and geojson shapes

1,153 lines (1,136 loc) 835 kB
var LocationConflation = (() => { var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // node_modules/quickselect/quickselect.js var require_quickselect = __commonJS({ "node_modules/quickselect/quickselect.js"(exports, module) { (function(global, factory) { typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : global.quickselect = factory(); })(exports, function() { "use strict"; function quickselect(arr, k, left, right, compare2) { quickselectStep(arr, k, left || 0, right || arr.length - 1, compare2 || defaultCompare); } function quickselectStep(arr, k, left, right, compare2) { while (right > left) { if (right - left > 600) { var n = right - left + 1; var m = k - left + 1; var z = Math.log(n); var s = 0.5 * Math.exp(2 * z / 3); var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1); var newLeft = Math.max(left, Math.floor(k - m * s / n + sd)); var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd)); quickselectStep(arr, k, newLeft, newRight, compare2); } var t = arr[k]; var i = left; var j = right; swap(arr, left, k); if (compare2(arr[right], t) > 0) swap(arr, left, right); while (i < j) { swap(arr, i, j); i++; j--; while (compare2(arr[i], t) < 0) i++; while (compare2(arr[j], t) > 0) j--; } if (compare2(arr[left], t) === 0) swap(arr, left, j); else { j++; swap(arr, j, right); } if (j <= k) left = j + 1; if (k <= j) right = j - 1; } } function swap(arr, i, j) { var tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } function defaultCompare(a, b) { return a < b ? -1 : a > b ? 1 : 0; } return quickselect; }); } }); // node_modules/rbush/index.js var require_rbush = __commonJS({ "node_modules/rbush/index.js"(exports, module) { "use strict"; module.exports = rbush; module.exports.default = rbush; var quickselect = require_quickselect(); function rbush(maxEntries, format) { if (!(this instanceof rbush)) return new rbush(maxEntries, format); this._maxEntries = Math.max(4, maxEntries || 9); this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)); if (format) { this._initFormat(format); } this.clear(); } rbush.prototype = { all: function() { return this._all(this.data, []); }, search: function(bbox) { var node = this.data, result = [], toBBox = this.toBBox; if (!intersects(bbox, node)) return result; var nodesToSearch = [], i, len, child, childBBox; while (node) { for (i = 0, len = node.children.length; i < len; i++) { child = node.children[i]; childBBox = node.leaf ? toBBox(child) : child; if (intersects(bbox, childBBox)) { if (node.leaf) result.push(child); else if (contains(bbox, childBBox)) this._all(child, result); else nodesToSearch.push(child); } } node = nodesToSearch.pop(); } return result; }, collides: function(bbox) { var node = this.data, toBBox = this.toBBox; if (!intersects(bbox, node)) return false; var nodesToSearch = [], i, len, child, childBBox; while (node) { for (i = 0, len = node.children.length; i < len; i++) { child = node.children[i]; childBBox = node.leaf ? toBBox(child) : child; if (intersects(bbox, childBBox)) { if (node.leaf || contains(bbox, childBBox)) return true; nodesToSearch.push(child); } } node = nodesToSearch.pop(); } return false; }, load: function(data) { if (!(data && data.length)) return this; if (data.length < this._minEntries) { for (var i = 0, len = data.length; i < len; i++) { this.insert(data[i]); } return this; } var node = this._build(data.slice(), 0, data.length - 1, 0); if (!this.data.children.length) { this.data = node; } else if (this.data.height === node.height) { this._splitRoot(this.data, node); } else { if (this.data.height < node.height) { var tmpNode = this.data; this.data = node; node = tmpNode; } this._insert(node, this.data.height - node.height - 1, true); } return this; }, insert: function(item) { if (item) this._insert(item, this.data.height - 1); return this; }, clear: function() { this.data = createNode([]); return this; }, remove: function(item, equalsFn) { if (!item) return this; var node = this.data, bbox = this.toBBox(item), path = [], indexes = [], i, parent, index, goingUp; while (node || path.length) { if (!node) { node = path.pop(); parent = path[path.length - 1]; i = indexes.pop(); goingUp = true; } if (node.leaf) { index = findItem(item, node.children, equalsFn); if (index !== -1) { node.children.splice(index, 1); path.push(node); this._condense(path); return this; } } if (!goingUp && !node.leaf && contains(node, bbox)) { path.push(node); indexes.push(i); i = 0; parent = node; node = node.children[0]; } else if (parent) { i++; node = parent.children[i]; goingUp = false; } else node = null; } return this; }, toBBox: function(item) { return item; }, compareMinX: compareNodeMinX, compareMinY: compareNodeMinY, toJSON: function() { return this.data; }, fromJSON: function(data) { this.data = data; return this; }, _all: function(node, result) { var nodesToSearch = []; while (node) { if (node.leaf) result.push.apply(result, node.children); else nodesToSearch.push.apply(nodesToSearch, node.children); node = nodesToSearch.pop(); } return result; }, _build: function(items, left, right, height) { var N = right - left + 1, M = this._maxEntries, node; if (N <= M) { node = createNode(items.slice(left, right + 1)); calcBBox(node, this.toBBox); return node; } if (!height) { height = Math.ceil(Math.log(N) / Math.log(M)); M = Math.ceil(N / Math.pow(M, height - 1)); } node = createNode([]); node.leaf = false; node.height = height; var N2 = Math.ceil(N / M), N1 = N2 * Math.ceil(Math.sqrt(M)), i, j, right2, right3; multiSelect(items, left, right, N1, this.compareMinX); for (i = left; i <= right; i += N1) { right2 = Math.min(i + N1 - 1, right); multiSelect(items, i, right2, N2, this.compareMinY); for (j = i; j <= right2; j += N2) { right3 = Math.min(j + N2 - 1, right2); node.children.push(this._build(items, j, right3, height - 1)); } } calcBBox(node, this.toBBox); return node; }, _chooseSubtree: function(bbox, node, level, path) { var i, len, child, targetNode, area, enlargement, minArea, minEnlargement; while (true) { path.push(node); if (node.leaf || path.length - 1 === level) break; minArea = minEnlargement = Infinity; for (i = 0, len = node.children.length; i < len; i++) { child = node.children[i]; area = bboxArea(child); enlargement = enlargedArea(bbox, child) - area; if (enlargement < minEnlargement) { minEnlargement = enlargement; minArea = area < minArea ? area : minArea; targetNode = child; } else if (enlargement === minEnlargement) { if (area < minArea) { minArea = area; targetNode = child; } } } node = targetNode || node.children[0]; } return node; }, _insert: function(item, level, isNode) { var toBBox = this.toBBox, bbox = isNode ? item : toBBox(item), insertPath = []; var node = this._chooseSubtree(bbox, this.data, level, insertPath); node.children.push(item); extend(node, bbox); while (level >= 0) { if (insertPath[level].children.length > this._maxEntries) { this._split(insertPath, level); level--; } else break; } this._adjustParentBBoxes(bbox, insertPath, level); }, // split overflowed node into two _split: function(insertPath, level) { var node = insertPath[level], M = node.children.length, m = this._minEntries; this._chooseSplitAxis(node, m, M); var splitIndex = this._chooseSplitIndex(node, m, M); var newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex)); newNode.height = node.height; newNode.leaf = node.leaf; calcBBox(node, this.toBBox); calcBBox(newNode, this.toBBox); if (level) insertPath[level - 1].children.push(newNode); else this._splitRoot(node, newNode); }, _splitRoot: function(node, newNode) { this.data = createNode([node, newNode]); this.data.height = node.height + 1; this.data.leaf = false; calcBBox(this.data, this.toBBox); }, _chooseSplitIndex: function(node, m, M) { var i, bbox1, bbox2, overlap, area, minOverlap, minArea, index; minOverlap = minArea = Infinity; for (i = m; i <= M - m; i++) { bbox1 = distBBox(node, 0, i, this.toBBox); bbox2 = distBBox(node, i, M, this.toBBox); overlap = intersectionArea(bbox1, bbox2); area = bboxArea(bbox1) + bboxArea(bbox2); if (overlap < minOverlap) { minOverlap = overlap; index = i; minArea = area < minArea ? area : minArea; } else if (overlap === minOverlap) { if (area < minArea) { minArea = area; index = i; } } } return index; }, // sorts node children by the best axis for split _chooseSplitAxis: function(node, m, M) { var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX, compareMinY = node.leaf ? this.compareMinY : compareNodeMinY, xMargin = this._allDistMargin(node, m, M, compareMinX), yMargin = this._allDistMargin(node, m, M, compareMinY); if (xMargin < yMargin) node.children.sort(compareMinX); }, // total margin of all possible split distributions where each node is at least m full _allDistMargin: function(node, m, M, compare2) { node.children.sort(compare2); var toBBox = this.toBBox, leftBBox = distBBox(node, 0, m, toBBox), rightBBox = distBBox(node, M - m, M, toBBox), margin = bboxMargin(leftBBox) + bboxMargin(rightBBox), i, child; for (i = m; i < M - m; i++) { child = node.children[i]; extend(leftBBox, node.leaf ? toBBox(child) : child); margin += bboxMargin(leftBBox); } for (i = M - m - 1; i >= m; i--) { child = node.children[i]; extend(rightBBox, node.leaf ? toBBox(child) : child); margin += bboxMargin(rightBBox); } return margin; }, _adjustParentBBoxes: function(bbox, path, level) { for (var i = level; i >= 0; i--) { extend(path[i], bbox); } }, _condense: function(path) { for (var i = path.length - 1, siblings; i >= 0; i--) { if (path[i].children.length === 0) { if (i > 0) { siblings = path[i - 1].children; siblings.splice(siblings.indexOf(path[i]), 1); } else this.clear(); } else calcBBox(path[i], this.toBBox); } }, _initFormat: function(format) { var compareArr = ["return a", " - b", ";"]; this.compareMinX = new Function("a", "b", compareArr.join(format[0])); this.compareMinY = new Function("a", "b", compareArr.join(format[1])); this.toBBox = new Function( "a", "return {minX: a" + format[0] + ", minY: a" + format[1] + ", maxX: a" + format[2] + ", maxY: a" + format[3] + "};" ); } }; function findItem(item, items, equalsFn) { if (!equalsFn) return items.indexOf(item); for (var i = 0; i < items.length; i++) { if (equalsFn(item, items[i])) return i; } return -1; } function calcBBox(node, toBBox) { distBBox(node, 0, node.children.length, toBBox, node); } function distBBox(node, k, p, toBBox, destNode) { if (!destNode) destNode = createNode(null); destNode.minX = Infinity; destNode.minY = Infinity; destNode.maxX = -Infinity; destNode.maxY = -Infinity; for (var i = k, child; i < p; i++) { child = node.children[i]; extend(destNode, node.leaf ? toBBox(child) : child); } return destNode; } function extend(a, b) { a.minX = Math.min(a.minX, b.minX); a.minY = Math.min(a.minY, b.minY); a.maxX = Math.max(a.maxX, b.maxX); a.maxY = Math.max(a.maxY, b.maxY); return a; } function compareNodeMinX(a, b) { return a.minX - b.minX; } function compareNodeMinY(a, b) { return a.minY - b.minY; } function bboxArea(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); } function bboxMargin(a) { return a.maxX - a.minX + (a.maxY - a.minY); } function enlargedArea(a, b) { return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) * (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY)); } function intersectionArea(a, b) { var minX = Math.max(a.minX, b.minX), minY = Math.max(a.minY, b.minY), maxX = Math.min(a.maxX, b.maxX), maxY = Math.min(a.maxY, b.maxY); return Math.max(0, maxX - minX) * Math.max(0, maxY - minY); } function contains(a, b) { return a.minX <= b.minX && a.minY <= b.minY && b.maxX <= a.maxX && b.maxY <= a.maxY; } function intersects(a, b) { return b.minX <= a.maxX && b.minY <= a.maxY && b.maxX >= a.minX && b.maxY >= a.minY; } function createNode(children) { return { children, height: 1, leaf: true, minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }; } function multiSelect(arr, left, right, n, compare2) { var stack = [left, right], mid; while (stack.length) { right = stack.pop(); left = stack.pop(); if (right - left <= n) continue; mid = left + Math.ceil((right - left) / n / 2) * n; quickselect(arr, mid, left, right, compare2); stack.push(left, mid, mid, right); } } } }); // node_modules/lineclip/index.js var require_lineclip = __commonJS({ "node_modules/lineclip/index.js"(exports, module) { "use strict"; module.exports = lineclip; lineclip.polyline = lineclip; lineclip.polygon = polygonclip; function lineclip(points, bbox, result) { var len = points.length, codeA = bitCode(points[0], bbox), part = [], i, a, b, codeB, lastCode; if (!result) result = []; for (i = 1; i < len; i++) { a = points[i - 1]; b = points[i]; codeB = lastCode = bitCode(b, bbox); while (true) { if (!(codeA | codeB)) { part.push(a); if (codeB !== lastCode) { part.push(b); if (i < len - 1) { result.push(part); part = []; } } else if (i === len - 1) { part.push(b); } break; } else if (codeA & codeB) { break; } else if (codeA) { a = intersect(a, b, codeA, bbox); codeA = bitCode(a, bbox); } else { b = intersect(a, b, codeB, bbox); codeB = bitCode(b, bbox); } } codeA = lastCode; } if (part.length) result.push(part); return result; } function polygonclip(points, bbox) { var result, edge, prev, prevInside, i, p, inside; for (edge = 1; edge <= 8; edge *= 2) { result = []; prev = points[points.length - 1]; prevInside = !(bitCode(prev, bbox) & edge); for (i = 0; i < points.length; i++) { p = points[i]; inside = !(bitCode(p, bbox) & edge); if (inside !== prevInside) result.push(intersect(prev, p, edge, bbox)); if (inside) result.push(p); prev = p; prevInside = inside; } points = result; if (!points.length) break; } return result; } function intersect(a, b, edge, bbox) { return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox[3] - a[1]) / (b[1] - a[1]), bbox[3]] : ( // top edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox[1] - a[1]) / (b[1] - a[1]), bbox[1]] : ( // bottom edge & 2 ? [bbox[2], a[1] + (b[1] - a[1]) * (bbox[2] - a[0]) / (b[0] - a[0])] : ( // right edge & 1 ? [bbox[0], a[1] + (b[1] - a[1]) * (bbox[0] - a[0]) / (b[0] - a[0])] : ( // left null ) ) ) ); } function bitCode(p, bbox) { var code = 0; if (p[0] < bbox[0]) code |= 1; else if (p[0] > bbox[2]) code |= 2; if (p[1] < bbox[1]) code |= 4; else if (p[1] > bbox[3]) code |= 8; return code; } } }); // node_modules/which-polygon/index.js var require_which_polygon = __commonJS({ "node_modules/which-polygon/index.js"(exports, module) { "use strict"; var rbush = require_rbush(); var lineclip = require_lineclip(); module.exports = whichPolygon2; function whichPolygon2(data) { var bboxes = []; for (var i = 0; i < data.features.length; i++) { var feature2 = data.features[i]; if (!feature2.geometry) continue; var coords = feature2.geometry.coordinates; if (feature2.geometry.type === "Polygon") { bboxes.push(treeItem(coords, feature2.properties)); } else if (feature2.geometry.type === "MultiPolygon") { for (var j = 0; j < coords.length; j++) { bboxes.push(treeItem(coords[j], feature2.properties)); } } } var tree = rbush().load(bboxes); function query(p, multi) { var output = [], result = tree.search({ minX: p[0], minY: p[1], maxX: p[0], maxY: p[1] }); for (var i2 = 0; i2 < result.length; i2++) { if (insidePolygon(result[i2].coords, p)) { if (multi) output.push(result[i2].props); else return result[i2].props; } } return multi && output.length ? output : null; } query.tree = tree; query.bbox = function queryBBox(bbox) { var output = []; var result = tree.search({ minX: bbox[0], minY: bbox[1], maxX: bbox[2], maxY: bbox[3] }); for (var i2 = 0; i2 < result.length; i2++) { if (polygonIntersectsBBox(result[i2].coords, bbox)) { output.push(result[i2].props); } } return output; }; return query; } function polygonIntersectsBBox(polygon, bbox) { var bboxCenter = [ (bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2 ]; if (insidePolygon(polygon, bboxCenter)) return true; for (var i = 0; i < polygon.length; i++) { if (lineclip(polygon[i], bbox).length > 0) return true; } return false; } function insidePolygon(rings, p) { var inside = false; for (var i = 0, len = rings.length; i < len; i++) { var ring = rings[i]; for (var j = 0, len2 = ring.length, k = len2 - 1; j < len2; k = j++) { if (rayIntersect(p, ring[j], ring[k])) inside = !inside; } } return inside; } function rayIntersect(p, p1, p2) { return p1[1] > p[1] !== p2[1] > p[1] && p[0] < (p2[0] - p1[0]) * (p[1] - p1[1]) / (p2[1] - p1[1]) + p1[0]; } function treeItem(coords, props) { var item = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity, coords, props }; for (var i = 0; i < coords[0].length; i++) { var p = coords[0][i]; item.minX = Math.min(item.minX, p[0]); item.minY = Math.min(item.minY, p[1]); item.maxX = Math.max(item.maxX, p[0]); item.maxY = Math.max(item.maxY, p[1]); } return item; } } }); // node_modules/wgs84/index.js var require_wgs84 = __commonJS({ "node_modules/wgs84/index.js"(exports, module) { module.exports.RADIUS = 6378137; module.exports.FLATTENING = 1 / 298.257223563; module.exports.POLAR_RADIUS = 63567523142e-4; } }); // node_modules/@mapbox/geojson-area/index.js var require_geojson_area = __commonJS({ "node_modules/@mapbox/geojson-area/index.js"(exports, module) { var wgs84 = require_wgs84(); module.exports.geometry = geometry; module.exports.ring = ringArea; function geometry(_) { var area = 0, i; switch (_.type) { case "Polygon": return polygonArea(_.coordinates); case "MultiPolygon": for (i = 0; i < _.coordinates.length; i++) { area += polygonArea(_.coordinates[i]); } return area; case "Point": case "MultiPoint": case "LineString": case "MultiLineString": return 0; case "GeometryCollection": for (i = 0; i < _.geometries.length; i++) { area += geometry(_.geometries[i]); } return area; } } function polygonArea(coords) { var area = 0; if (coords && coords.length > 0) { area += Math.abs(ringArea(coords[0])); for (var i = 1; i < coords.length; i++) { area -= Math.abs(ringArea(coords[i])); } } return area; } function ringArea(coords) { var p1, p2, p3, lowerIndex, middleIndex, upperIndex, i, area = 0, coordsLength = coords.length; if (coordsLength > 2) { for (i = 0; i < coordsLength; i++) { if (i === coordsLength - 2) { lowerIndex = coordsLength - 2; middleIndex = coordsLength - 1; upperIndex = 0; } else if (i === coordsLength - 1) { lowerIndex = coordsLength - 1; middleIndex = 0; upperIndex = 1; } else { lowerIndex = i; middleIndex = i + 1; upperIndex = i + 2; } p1 = coords[lowerIndex]; p2 = coords[middleIndex]; p3 = coords[upperIndex]; area += (rad(p3[0]) - rad(p1[0])) * Math.sin(rad(p2[1])); } area = area * wgs84.RADIUS * wgs84.RADIUS / 2; } return area; } function rad(_) { return _ * Math.PI / 180; } } }); // node_modules/circle-to-polygon/input-validation/validateCenter.js var require_validateCenter = __commonJS({ "node_modules/circle-to-polygon/input-validation/validateCenter.js"(exports) { exports.validateCenter = function validateCenter(center) { var validCenterLengths = [2, 3]; if (!Array.isArray(center) || !validCenterLengths.includes(center.length)) { throw new Error("ERROR! Center has to be an array of length two or three"); } var [lng, lat] = center; if (typeof lng !== "number" || typeof lat !== "number") { throw new Error( `ERROR! Longitude and Latitude has to be numbers but where ${typeof lng} and ${typeof lat}` ); } if (lng > 180 || lng < -180) { throw new Error(`ERROR! Longitude has to be between -180 and 180 but was ${lng}`); } if (lat > 90 || lat < -90) { throw new Error(`ERROR! Latitude has to be between -90 and 90 but was ${lat}`); } }; } }); // node_modules/circle-to-polygon/input-validation/validateRadius.js var require_validateRadius = __commonJS({ "node_modules/circle-to-polygon/input-validation/validateRadius.js"(exports) { exports.validateRadius = function validateRadius(radius) { if (typeof radius !== "number") { throw new Error(`ERROR! Radius has to be a positive number but was: ${typeof radius}`); } if (radius <= 0) { throw new Error(`ERROR! Radius has to be a positive number but was: ${radius}`); } }; } }); // node_modules/circle-to-polygon/input-validation/validateNumberOfEdges.js var require_validateNumberOfEdges = __commonJS({ "node_modules/circle-to-polygon/input-validation/validateNumberOfEdges.js"(exports) { exports.validateNumberOfEdges = function validateNumberOfEdges(numberOfEdges) { if (typeof numberOfEdges !== "number") { const ARGUMENT_TYPE = Array.isArray(numberOfEdges) ? "array" : typeof numberOfEdges; throw new Error(`ERROR! Number of edges has to be a number but was: ${ARGUMENT_TYPE}`); } if (numberOfEdges < 3) { throw new Error(`ERROR! Number of edges has to be at least 3 but was: ${numberOfEdges}`); } }; } }); // node_modules/circle-to-polygon/input-validation/validateEarthRadius.js var require_validateEarthRadius = __commonJS({ "node_modules/circle-to-polygon/input-validation/validateEarthRadius.js"(exports) { exports.validateEarthRadius = function validateEarthRadius(earthRadius) { if (typeof earthRadius !== "number") { const ARGUMENT_TYPE = Array.isArray(earthRadius) ? "array" : typeof earthRadius; throw new Error(`ERROR! Earth radius has to be a number but was: ${ARGUMENT_TYPE}`); } if (earthRadius <= 0) { throw new Error(`ERROR! Earth radius has to be a positive number but was: ${earthRadius}`); } }; } }); // node_modules/circle-to-polygon/input-validation/validateBearing.js var require_validateBearing = __commonJS({ "node_modules/circle-to-polygon/input-validation/validateBearing.js"(exports) { exports.validateBearing = function validateBearing(bearing) { if (typeof bearing !== "number") { const ARGUMENT_TYPE = Array.isArray(bearing) ? "array" : typeof bearing; throw new Error(`ERROR! Bearing has to be a number but was: ${ARGUMENT_TYPE}`); } }; } }); // node_modules/circle-to-polygon/input-validation/index.js var require_input_validation = __commonJS({ "node_modules/circle-to-polygon/input-validation/index.js"(exports) { var validateCenter = require_validateCenter().validateCenter; var validateRadius = require_validateRadius().validateRadius; var validateNumberOfEdges = require_validateNumberOfEdges().validateNumberOfEdges; var validateEarthRadius = require_validateEarthRadius().validateEarthRadius; var validateBearing = require_validateBearing().validateBearing; function validateInput({ center, radius, numberOfEdges, earthRadius, bearing }) { validateCenter(center); validateRadius(radius); validateNumberOfEdges(numberOfEdges); validateEarthRadius(earthRadius); validateBearing(bearing); } exports.validateCenter = validateCenter; exports.validateRadius = validateRadius; exports.validateNumberOfEdges = validateNumberOfEdges; exports.validateEarthRadius = validateEarthRadius; exports.validateBearing = validateBearing; exports.validateInput = validateInput; } }); // node_modules/circle-to-polygon/index.js var require_circle_to_polygon = __commonJS({ "node_modules/circle-to-polygon/index.js"(exports, module) { "use strict"; var { validateInput } = require_input_validation(); var defaultEarthRadius = 6378137; function toRadians(angleInDegrees) { return angleInDegrees * Math.PI / 180; } function toDegrees(angleInRadians) { return angleInRadians * 180 / Math.PI; } function offset(c1, distance, earthRadius, bearing) { var lat1 = toRadians(c1[1]); var lon1 = toRadians(c1[0]); var dByR = distance / earthRadius; var lat = Math.asin( Math.sin(lat1) * Math.cos(dByR) + Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing) ); var lon = lon1 + Math.atan2( Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1), Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat) ); return [toDegrees(lon), toDegrees(lat)]; } module.exports = function circleToPolygon2(center, radius, options) { var n = getNumberOfEdges(options); var earthRadius = getEarthRadius(options); var bearing = getBearing(options); var direction = getDirection(options); validateInput({ center, radius, numberOfEdges: n, earthRadius, bearing }); var start = toRadians(bearing); var coordinates = []; for (var i = 0; i < n; ++i) { coordinates.push( offset( center, radius, earthRadius, start + direction * 2 * Math.PI * -i / n ) ); } coordinates.push(coordinates[0]); return { type: "Polygon", coordinates: [coordinates] }; }; function getNumberOfEdges(options) { if (isUndefinedOrNull(options)) { return 32; } else if (isObjectNotArray(options)) { var numberOfEdges = options.numberOfEdges; return numberOfEdges === void 0 ? 32 : numberOfEdges; } return options; } function getEarthRadius(options) { if (isUndefinedOrNull(options)) { return defaultEarthRadius; } else if (isObjectNotArray(options)) { var earthRadius = options.earthRadius; return earthRadius === void 0 ? defaultEarthRadius : earthRadius; } return defaultEarthRadius; } function getDirection(options) { if (isObjectNotArray(options) && options.rightHandRule) { return -1; } return 1; } function getBearing(options) { if (isUndefinedOrNull(options)) { return 0; } else if (isObjectNotArray(options)) { var bearing = options.bearing; return bearing === void 0 ? 0 : bearing; } return 0; } function isObjectNotArray(argument) { return argument !== null && typeof argument === "object" && !Array.isArray(argument); } function isUndefinedOrNull(argument) { return argument === null || argument === void 0; } } }); // node_modules/geojson-precision/index.js var require_geojson_precision = __commonJS({ "node_modules/geojson-precision/index.js"(exports, module) { (function() { function parse(t, coordinatePrecision, extrasPrecision) { function point(p) { return p.map(function(e, index) { if (index < 2) { return 1 * e.toFixed(coordinatePrecision); } else { return 1 * e.toFixed(extrasPrecision); } }); } function multi(l) { return l.map(point); } function poly(p) { return p.map(multi); } function multiPoly(m) { return m.map(poly); } function geometry(obj) { if (!obj) { return {}; } switch (obj.type) { case "Point": obj.coordinates = point(obj.coordinates); return obj; case "LineString": case "MultiPoint": obj.coordinates = multi(obj.coordinates); return obj; case "Polygon": case "MultiLineString": obj.coordinates = poly(obj.coordinates); return obj; case "MultiPolygon": obj.coordinates = multiPoly(obj.coordinates); return obj; case "GeometryCollection": obj.geometries = obj.geometries.map(geometry); return obj; default: return {}; } } function feature2(obj) { obj.geometry = geometry(obj.geometry); return obj; } function featureCollection(f) { f.features = f.features.map(feature2); return f; } function geometryCollection(g) { g.geometries = g.geometries.map(geometry); return g; } if (!t) { return t; } switch (t.type) { case "Feature": return feature2(t); case "GeometryCollection": return geometryCollection(t); case "FeatureCollection": return featureCollection(t); case "Point": case "LineString": case "Polygon": case "MultiPoint": case "MultiPolygon": case "MultiLineString": return geometry(t); default: return t; } } module.exports = parse; module.exports.parse = parse; })(); } }); // node_modules/@aitodotai/json-stringify-pretty-compact/index.js var require_json_stringify_pretty_compact = __commonJS({ "node_modules/@aitodotai/json-stringify-pretty-compact/index.js"(exports, module) { function isObject(obj) { return typeof obj === "object" && obj !== null; } function forEach(obj, cb) { if (Array.isArray(obj)) { obj.forEach(cb); } else if (isObject(obj)) { Object.keys(obj).forEach(function(key) { var val = obj[key]; cb(val, key); }); } } function getTreeDepth(obj) { var depth = 0; if (Array.isArray(obj) || isObject(obj)) { forEach(obj, function(val) { if (Array.isArray(val) || isObject(val)) { var tmpDepth = getTreeDepth(val); if (tmpDepth > depth) { depth = tmpDepth; } } }); return depth + 1; } return depth; } function stringify(obj, options) { options = options || {}; var indent = JSON.stringify([1], null, get(options, "indent", 2)).slice(2, -3); var addMargin = get(options, "margins", false); var addArrayMargin = get(options, "arrayMargins", false); var addObjectMargin = get(options, "objectMargins", false); var maxLength = indent === "" ? Infinity : get(options, "maxLength", 80); var maxNesting = get(options, "maxNesting", Infinity); return function _stringify(obj2, currentIndent, reserved) { if (obj2 && typeof obj2.toJSON === "function") { obj2 = obj2.toJSON(); } var string = JSON.stringify(obj2); if (string === void 0) { return string; } var length2 = maxLength - currentIndent.length - reserved; var treeDepth = getTreeDepth(obj2); if (treeDepth <= maxNesting && string.length <= length2) { var prettified = prettify(string, { addMargin, addArrayMargin, addObjectMargin }); if (prettified.length <= length2) { return prettified; } } if (isObject(obj2)) { var nextIndent = currentIndent + indent; var items = []; var delimiters; var comma = function(array, index2) { return index2 === array.length - 1 ? 0 : 1; }; if (Array.isArray(obj2)) { for (var index = 0; index < obj2.length; index++) { items.push( _stringify(obj2[index], nextIndent, comma(obj2, index)) || "null" ); } delimiters = "[]"; } else { Object.keys(obj2).forEach(function(key, index2, array) { var keyPart = JSON.stringify(key) + ": "; var value = _stringify( obj2[key], nextIndent, keyPart.length + comma(array, index2) ); if (value !== void 0) { items.push(keyPart + value); } }); delimiters = "{}"; } if (items.length > 0) { return [ delimiters[0], indent + items.join(",\n" + nextIndent), delimiters[1] ].join("\n" + currentIndent); } } return string; }(obj, "", 0); } var stringOrChar = /("(?:[^\\"]|\\.)*")|[:,\][}{]/g; function prettify(string, options) { options = options || {}; var tokens = { "{": "{", "}": "}", "[": "[", "]": "]", ",": ", ", ":": ": " }; if (options.addMargin || options.addObjectMargin) { tokens["{"] = "{ "; tokens["}"] = " }"; } if (options.addMargin || options.addArrayMargin) { tokens["["] = "[ "; tokens["]"] = " ]"; } return string.replace(stringOrChar, function(match, string2) { return string2 ? match : tokens[match]; }); } function get(options, name, defaultValue) { return name in options ? options[name] : defaultValue; } module.exports = stringify; } }); // index.mjs var index_exports = {}; __export(index_exports, { LocationConflation: () => LocationConflation, default: () => index_default }); // node_modules/@rapideditor/country-coder/dist/country-coder.mjs var import_which_polygon = __toESM(require_which_polygon(), 1); var borders_default = { type: "FeatureCollection", features: [ { type: "Feature", properties: { wikidata: "Q21", nameEn: "England", aliases: ["GB-ENG"], country: "GB", groups: ["Q23666", "Q3336843", "154", "150", "UN"], driveSide: "left", roadSpeedUnit: "mph", roadHeightUnit: "ft", callingCodes: ["44"] }, geometry: { type: "MultiPolygon", coordinates: [[[[-6.03913, 51.13217], [-7.74976, 48.64773], [1.17405, 50.74239], [2.18458, 51.52087], [2.56575, 51.85301], [0.792, 57.56437], [-2.30613, 55.62698], [-2.17058, 55.45916], [-2.6095, 55.28488], [-2.63532, 55.19452], [-3.02906, 55.04606], [-3.09361, 54.94924], [-3.38407, 54.94278], [-4.1819, 54.57861], [-3.5082, 53.54318], [-3.08228, 53.25526], [-3.03675, 53.25092], [-2.92329, 53.19383], [-2.92022, 53.17685], [-2.98598, 53.15589], [-2.90649, 53.10964], [-2.87469, 53.12337], [-2.89131, 53.09374], [-2.83133, 52.99184], [-2.7251, 52.98389], [-2.72221, 52.92969], [-2.80549, 52.89428], [-2.85897, 52.94487], [-2.92401, 52.93836], [-2.97243, 52.9651], [-3.13576, 52.895], [-3.15744, 52.84947], [-3.16105, 52.79599], [-3.08734, 52.77504], [-3.01001, 52.76636], [-2.95581, 52.71794], [-3.01724, 52.72083], [-3.04398, 52.65435], [-3.13648, 52.58208], [-3.12926, 52.5286], [-3.09746, 52.53077], [-3.08662, 52.54811], [-3.00929, 52.57774], [-2.99701, 52.551], [-3.03603, 52.49969], [-3.13359, 52.49174], [-3.22971, 52.45344], [-3.22754, 52.42526], [-3.04687, 52.34504], [-2.95364, 52.3501], [-2.99701, 52.323], [-3.00785, 52.2753], [-3.09289, 52.20546], [-3.12638, 52.08114], [-2.97111, 51.90456], [-2.8818, 51.93196], [-2.78742, 51.88833], [-2.74277, 51.84367], [-2.66234, 51.83555], [-2.66336, 51.59504], [-3.20563, 51.31615], [-6.03913, 51.13217]]]] } }, { type: "Feature", properties: { wikidata: "Q22", nameEn: "Scotland", aliases: ["GB-SCT"], country: "GB", groups: ["Q23666", "Q3336843", "154", "150", "UN"], driveSide: "left", roadSpeedUnit: "mph", roadHeightUnit: "ft", callingCodes: ["44"] }, geometry: { type: "MultiPolygon", coordinates: [[[[0.792, 57.56437], [-0.3751, 61.32236], [-14.78497, 57.60709], [-6.82333, 55.83103], [-4.69044, 54.3629], [-3.38407, 54.94278], [-3.09361, 54.94924], [-3.02906, 55.04606], [-2.63532, 55.19452], [-2.6095, 55.28488], [-2.17058, 55.45916], [-2.30613, 55.62698], [0.792, 57.56437]]]] } }, { type: "Feature", properties: { wikidata: "Q25", nameEn: "Wales", aliases: ["GB-WLS"], country: "GB", groups: ["Q23666", "Q3336843", "154", "150", "UN"], driveSide: "left", roadSpeedUnit: "mph", roadHeightUnit: "ft", callingCodes: ["44"] }, geometry: { type: "MultiPolygon", coordinates: [[[[-3.5082, 53.54318], [-5.37267, 53.63269], [-6.03913, 51.13217], [-3.20563, 51.31615], [-2.66336, 51.59504], [-2.66234, 51.83555], [-2.74277, 51.84367], [-2.78742, 51.88833], [-2.8818, 51.93196], [-2.97111, 51.90456], [-3.12638, 52.08114], [-3.09289, 52.20546], [-3.00785, 52.2753], [-2.99701, 52.323], [-2.95364, 52.3501], [-3.04687, 52.34504], [-3.22754, 52.42526], [-3.22971, 52.45344], [-3.13359, 52.49174], [-3.03603, 52.49969], [-2.99701, 52.551], [-3.00929, 52.57774], [-3.08662, 52.54811], [-3.09746, 52.53077], [-3.12926, 52.5286], [-3.13648, 52.58208], [-3.04398, 52.65435], [-3.01724, 52.72083], [-2.95581, 52.71794], [-3.01001, 52.76636], [-3.08734, 52.77504], [-3.16105, 52.79599], [-3.15744, 52.84947], [-3.13576, 52.895], [-2.97243, 52.9651], [-2.92401, 52.93836], [-2.85897, 52.94487], [-2.80549, 52.89428], [-2.72221, 52.92969], [-2.7251, 52.98389], [-2.83133, 52.99184], [-2.89131, 53.09374], [-2.87469, 53.12337], [-2.90649, 53.10964], [-2.98598, 53.15589], [-2.92022, 53.17685], [-2.92329, 53.19383], [-3.03675, 53.25092], [-3.08228, 53.25526], [-3.5082, 53.54318]]]] } }, { type: "Feature", properties: { wikidata: "Q26", nameEn: "Northern Ireland", aliases: ["GB-NIR"], country: "GB", groups: ["Q22890", "Q3336843", "154", "150", "UN"], driveSide: "left", roadSpeedUnit: "mph", roadHeightUnit: "ft", callingCodes: ["44"] }, geometry: { type: "MultiPolygon", coordinates: [[[[-6.34755, 55.49206], [-7.2471, 55.06933], [-7.34464, 55.04688], [-7.4033, 55.00391], [-7.40004, 54.94498], [-7.44404, 54.9403], [-7.4473, 54.87003], [-7.47626, 54.83084], [-7.54508, 54.79401], [-7.54671, 54.74606], [-7.64449, 54.75265], [-7.75041, 54.7103], [-7.83352, 54.73854], [-7.93293, 54.66603], [-7.70315, 54.62077], [-7.8596, 54.53671], [-7.99812, 54.54427], [-8.04538, 54.48941], [-8.179, 54.46763], [-8.04555, 54.36292], [-7.87101, 54.29299], [-7.8596, 54.21779], [-7.81397, 54.20159], [-7.69501, 54.20731], [-7.55812, 54.12239], [-7.4799, 54.12239], [-7.44567, 54.1539], [-7.32834, 54.11475], [-7.30553, 54.11869], [-7.34005, 54.14698], [-7.29157, 54.17191], [-7.28017, 54.16714], [-7.29687, 54.1354], [-7.29493, 54.12013], [-7.26316, 54.13863], [-7.25012, 54.20063], [-7.14908, 54.22732], [-7.19145, 54.31296], [-7.02034, 54.4212], [-6.87775, 54.34682], [-6.85179, 54.29176], [-6.81583, 54.22791], [-6.74575, 54.18788], [-6.70175, 54.20218], [-6.6382, 54.17071], [-6.66264, 54.0666], [-6.62842, 54.03503], [-6.47849, 54.06947], [-6.36605, 54.07234], [-6.36279, 54.11248], [-6.32694, 54.09337], [-6.29003, 54.11278], [-6.26218, 54.09785], [-5.83481, 53.87749], [-4.69044, 54.3629], [-6.34755, 55.49206]]]] } }, { type: "Feature", properties: { wikidata: "Q35", nameEn: "Denmark", country: "DK", groups: ["EU", "154", "150", "UN"], callingCodes: ["45"] }, geometry: { type: "MultiPolygon", coordinates: [[[[12.16597, 56.60205], [10.40861, 58.38489], [7.28637, 57.35913], [8.02459, 55.09613], [8.45719, 55.06747], [8.55769, 54.91837], [8.63979, 54.91069], [8.76387, 54.8948], [8.81178, 54.90518], [8.92795, 54.90452], [9.04629, 54.87249], [9.14275, 54.87421], [9.20571, 54.85841], [9.24631, 54.84726], [9.23445, 54.83432], [9.2474, 54.8112], [9.32771, 54.80602], [9.33849, 54.80233], [9.36496, 54.81749], [9.38532, 54.83968], [9.41213, 54.84254], [9.43155, 54.82586], [9.4659, 54.83131], [9.58937, 54.88785], [9.62734, 54.88057], [9.61187, 54.85548], [9.73563, 54.8247], [9.89314, 54.84171], [10.16755, 54.73883], [10.31111, 54.65968], [11.00303, 54.63689], [11.90309, 54.38543], [12.85844, 54.82438], [13.93395, 54.84044], [15.36991, 54.73263], [15.79951, 55.54655], [14.89259, 55.5623], [14.28399, 55.1553], [12.84405, 55.13257], [12.60345, 55.42675], [12.88472, 55.63369], [12.6372, 55.91371], [12.65312, 56.04345], [12.07466, 56.29488], [12.16597, 56.60205]]]] } }, { type: "Feature", properties: { wikidata: "Q55", nameEn: "Netherlands", country: "NL", groups: ["EU", "155", "150", "UN"], callingCodes: ["31"] }, geometry: { type: "MultiPolygon", coordinates: [[[[5.45168, 54.20039], [2.56575, 51.85301], [3.36263, 51.37112], [3.38696, 51.33436], [3.35847, 51.31572], [3.38289, 51.27331], [3.41704, 51.25933], [3.43488, 51.24135], [3.52698, 51.2458], [3.51502, 51.28697], [3.58939, 51.30064], [3.78999, 51.25766], [3.78783, 51.2151], [3.90125, 51.20371], [3.97889, 51.22537], [4.01957, 51.24504], [4.05165, 51.24171], [4.16721, 51.29348], [4.24024, 51.35371], [4.21923, 51.37443], [4.33265, 51.37687], [4.34086, 51.35738], [4.39292, 51.35547], [4.43777, 51.36989], [4.38064, 51.41965], [4.39747, 51.43316], [4.38122, 51.44905], [4.47736, 51.4778], [4.5388, 51.48184], [4.54675, 51.47265], [4.52846, 51.45002], [4.53521, 51.4243], [4.57489, 51.4324], [4.65442, 51.42352], [4.72935, 51.48424], [4.74578, 51.48937], [4.77321, 51.50529], [4.78803, 51.50284], [4.84139, 51.4799], [4.82409, 51.44736], [4.82946, 51.4213], [4.78314, 51.43319], [4.76577, 51.43046], [4.77229, 51.41337], [4.78941, 51.41102], [4.84988, 51.41502], [4.90016, 51.41404]