@maptiler/geocoding-control 2.1.0-rc1 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/leaflet-controller.js +1942 -1523
  2. package/leaflet-controller.js.map +1 -1
  3. package/leaflet-controller.umd.js +1 -22
  4. package/leaflet-controller.umd.js.map +1 -1
  5. package/leaflet.js +2800 -2368
  6. package/leaflet.js.map +1 -1
  7. package/leaflet.umd.js +1 -22
  8. package/leaflet.umd.js.map +1 -1
  9. package/maplibregl-controller.js +1918 -1498
  10. package/maplibregl-controller.js.map +1 -1
  11. package/maplibregl-controller.umd.js +1 -22
  12. package/maplibregl-controller.umd.js.map +1 -1
  13. package/maplibregl.js +2858 -2425
  14. package/maplibregl.js.map +1 -1
  15. package/maplibregl.umd.js +1 -22
  16. package/maplibregl.umd.js.map +1 -1
  17. package/maptilersdk.js +2863 -2428
  18. package/maptilersdk.js.map +1 -1
  19. package/maptilersdk.umd.js +1 -22
  20. package/maptilersdk.umd.js.map +1 -1
  21. package/openlayers-controller.js +1686 -1264
  22. package/openlayers-controller.js.map +1 -1
  23. package/openlayers-controller.umd.js +1 -22
  24. package/openlayers-controller.umd.js.map +1 -1
  25. package/openlayers.js +2785 -2353
  26. package/openlayers.js.map +1 -1
  27. package/openlayers.umd.js +1 -22
  28. package/openlayers.umd.js.map +1 -1
  29. package/package.json +19 -19
  30. package/react.js +800 -784
  31. package/react.js.map +1 -1
  32. package/react.umd.js +1 -1
  33. package/react.umd.js.map +1 -1
  34. package/{MapLibreBasedGeocodingControl.d.ts → src/MapLibreBasedGeocodingControl.d.ts} +35 -69
  35. package/{maplibregl.d.ts → src/maplibregl.d.ts} +34 -68
  36. package/{maptilersdk.d.ts → src/maptilersdk.d.ts} +34 -68
  37. package/src/types.d.ts +391 -0
  38. package/svelte/GeocodingControl.svelte +55 -14
  39. package/svelte/GeocodingControl.svelte.d.ts +5 -2
  40. package/svelte/MapLibreBasedGeocodingControl.d.ts +35 -69
  41. package/svelte/maplibregl.d.ts +34 -68
  42. package/svelte/maptilersdk.d.ts +34 -68
  43. package/svelte/maptilersdk.js +2 -0
  44. package/svelte/react.js +3 -0
  45. package/svelte/types.d.ts +175 -127
  46. package/vanilla.js +870 -857
  47. package/vanilla.js.map +1 -1
  48. package/vanilla.umd.js +1 -1
  49. package/vanilla.umd.js.map +1 -1
  50. package/types.d.ts +0 -343
  51. /package/{geo-coordinates-parser.t.d.ts → src/geo-coordinates-parser.t.d.ts} +0 -0
  52. /package/{geoUtils.d.ts → src/geoUtils.d.ts} +0 -0
  53. /package/{leaflet-controller.d.ts → src/leaflet-controller.d.ts} +0 -0
  54. /package/{leaflet.d.ts → src/leaflet.d.ts} +0 -0
  55. /package/{maplibregl-controller.d.ts → src/maplibregl-controller.d.ts} +0 -0
  56. /package/{mask.d.ts → src/mask.d.ts} +0 -0
  57. /package/{openlayers-controller.d.ts → src/openlayers-controller.d.ts} +0 -0
  58. /package/{openlayers.d.ts → src/openlayers.d.ts} +0 -0
  59. /package/{proximity.d.ts → src/proximity.d.ts} +0 -0
  60. /package/{react.d.ts → src/react.d.ts} +0 -0
  61. /package/{vanilla.d.ts → src/vanilla.d.ts} +0 -0
@@ -1,23 +1,2 @@
1
- (function(S,L){typeof exports=="object"&&typeof module<"u"?L(exports,require("ol"),require("ol/geom"),require("ol/layer/Vector"),require("ol/proj"),require("ol/source/Vector"),require("ol/style/Fill"),require("ol/style/Icon"),require("ol/style/Stroke"),require("ol/style/Style"),require("ol/style/Text")):typeof define=="function"&&define.amd?define(["exports","ol","ol/geom","ol/layer/Vector","ol/proj","ol/source/Vector","ol/style/Fill","ol/style/Icon","ol/style/Stroke","ol/style/Style","ol/style/Text"],L):(S=typeof globalThis<"u"?globalThis:S||self,L(S.openlayersMaptilerGeocodingController={},S.ol,S.ol.geom,S.ol.layer.Vector,S.ol.proj,S.ol.source.Vector,S.ol.style.Fill,S.ol.style.Icon,S.ol.style.Stroke,S.ol.style.Style,S.ol.style.Text))})(this,function(S,L,R,At,$,Ft,ft,Ot,ct,Nt,Gt){"use strict";function j(o,t,e={}){const n={type:"Feature"};return(e.id===0||e.id)&&(n.id=e.id),e.bbox&&(n.bbox=e.bbox),n.properties=t||{},n.geometry=o,n}function K(o,t,e={}){for(const r of o){if(r.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(r[r.length-1].length!==r[0].length)throw new Error("First and last Position are not equivalent.");for(let i=0;i<r[r.length-1].length;i++)if(r[r.length-1][i]!==r[0][i])throw new Error("First and last Position are not equivalent.")}return j({type:"Polygon",coordinates:o},t,e)}function H(o,t={}){const e={type:"FeatureCollection"};return t.id&&(e.id=t.id),t.bbox&&(e.bbox=t.bbox),e.features=o,e}function ht(o,t,e={}){return j({type:"MultiPolygon",coordinates:o},t,e)}function at(o,t,e){if(o!==null)for(var n,r,i,u,l,c,f,a=0,s=0,h,g=o.type,y=g==="FeatureCollection",p=g==="Feature",d=y?o.features.length:1,x=0;x<d;x++){f=y?o.features[x].geometry:p?o.geometry:o,h=f?f.type==="GeometryCollection":!1,l=h?f.geometries.length:1;for(var v=0;v<l;v++){var m=0,w=0;if(u=h?f.geometries[v]:f,u!==null){c=u.coordinates;var E=u.type;switch(a=0,E){case null:break;case"Point":if(t(c,s,x,m,w)===!1)return!1;s++,m++;break;case"LineString":case"MultiPoint":for(n=0;n<c.length;n++){if(t(c[n],s,x,m,w)===!1)return!1;s++,E==="MultiPoint"&&m++}E==="LineString"&&m++;break;case"Polygon":case"MultiLineString":for(n=0;n<c.length;n++){for(r=0;r<c[n].length-a;r++){if(t(c[n][r],s,x,m,w)===!1)return!1;s++}E==="MultiLineString"&&m++,E==="Polygon"&&w++}E==="Polygon"&&m++;break;case"MultiPolygon":for(n=0;n<c.length;n++){for(w=0,r=0;r<c[n].length;r++){for(i=0;i<c[n][r].length-a;i++){if(t(c[n][r][i],s,x,m,w)===!1)return!1;s++}w++}m++}break;case"GeometryCollection":for(n=0;n<u.geometries.length;n++)if(at(u.geometries[n],t)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function tt(o,t){var e,n,r,i,u,l,c,f,a,s,h=0,g=o.type==="FeatureCollection",y=o.type==="Feature",p=g?o.features.length:1;for(e=0;e<p;e++){for(l=g?o.features[e].geometry:y?o.geometry:o,f=g?o.features[e].properties:y?o.properties:{},a=g?o.features[e].bbox:y?o.bbox:void 0,s=g?o.features[e].id:y?o.id:void 0,c=l?l.type==="GeometryCollection":!1,u=c?l.geometries.length:1,r=0;r<u;r++){if(i=c?l.geometries[r]:l,i===null){if(t(null,h,f,a,s)===!1)return!1;continue}switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(i,h,f,a,s)===!1)return!1;break}case"GeometryCollection":{for(n=0;n<i.geometries.length;n++)if(t(i.geometries[n],h,f,a,s)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}h++}}function Bt(o,t){tt(o,function(e,n,r,i,u){var l=e===null?null:e.type;switch(l){case null:case"Point":case"LineString":case"Polygon":return t(j(e,r,{bbox:i,id:u}),n,0)===!1?!1:void 0}var c;switch(l){case"MultiPoint":c="Point";break;case"MultiLineString":c="LineString";break;case"MultiPolygon":c="Polygon";break}for(var f=0;f<e.coordinates.length;f++){var a=e.coordinates[f],s={type:c,coordinates:a};if(t(j(s,r),n,f)===!1)return!1}})}function $t(o,t={}){if(o.bbox!=null&&t.recompute!==!0)return o.bbox;const e=[1/0,1/0,-1/0,-1/0];return at(o,n=>{e[0]>n[0]&&(e[0]=n[0]),e[1]>n[1]&&(e[1]=n[1]),e[2]<n[0]&&(e[2]=n[0]),e[3]<n[1]&&(e[3]=n[1])}),e}var gt=$t;/**
2
- * splaytree v3.1.2
3
- * Fast Splay tree for Node and browser
4
- *
5
- * @author Alexander Milevski <info@w8r.name>
6
- * @license MIT
7
- * @preserve
8
- *//*! *****************************************************************************
9
- Copyright (c) Microsoft Corporation. All rights reserved.
10
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
11
- this file except in compliance with the License. You may obtain a copy of the
12
- License at http://www.apache.org/licenses/LICENSE-2.0
13
-
14
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17
- MERCHANTABLITY OR NON-INFRINGEMENT.
18
-
19
- See the Apache Version 2.0 License for specific language governing permissions
20
- and limitations under the License.
21
- ***************************************************************************** */function Tt(o,t){var e={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,r,i,u;return u={next:l(0),throw:l(1),return:l(2)},typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function l(f){return function(a){return c([f,a])}}function c(f){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,r&&(i=f[0]&2?r.return:f[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,f[1])).done)return i;switch(r=0,i&&(f=[f[0]&2,i.value]),f[0]){case 0:case 1:i=f;break;case 4:return e.label++,{value:f[1],done:!1};case 5:e.label++,r=f[1],f=[0];continue;case 7:f=e.ops.pop(),e.trys.pop();continue;default:if(i=e.trys,!(i=i.length>0&&i[i.length-1])&&(f[0]===6||f[0]===2)){e=0;continue}if(f[0]===3&&(!i||f[1]>i[0]&&f[1]<i[3])){e.label=f[1];break}if(f[0]===6&&e.label<i[1]){e.label=i[1],i=f;break}if(i&&e.label<i[2]){e.label=i[2],e.ops.push(f);break}i[2]&&e.ops.pop(),e.trys.pop();continue}f=t.call(o,e)}catch(a){f=[6,a],r=0}finally{n=i=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}var T=function(){function o(t,e){this.next=null,this.key=t,this.data=e,this.left=null,this.right=null}return o}();function zt(o,t){return o>t?1:o<t?-1:0}function z(o,t,e){for(var n=new T(null,null),r=n,i=n;;){var u=e(o,t.key);if(u<0){if(t.left===null)break;if(e(o,t.left.key)<0){var l=t.left;if(t.left=l.right,l.right=t,t=l,t.left===null)break}i.left=t,i=t,t=t.left}else if(u>0){if(t.right===null)break;if(e(o,t.right.key)>0){var l=t.right;if(t.right=l.left,l.left=t,t=l,t.right===null)break}r.right=t,r=t,t=t.right}else break}return r.right=t.left,i.left=t.right,t.left=n.right,t.right=n.left,t}function et(o,t,e,n){var r=new T(o,t);if(e===null)return r.left=r.right=null,r;e=z(o,e,n);var i=n(o,e.key);return i<0?(r.left=e.left,r.right=e,e.left=null):i>=0&&(r.right=e.right,r.left=e,e.right=null),r}function pt(o,t,e){var n=null,r=null;if(t){t=z(o,t,e);var i=e(t.key,o);i===0?(n=t.left,r=t.right):i<0?(r=t.right,t.right=null,n=t):(n=t.left,t.left=null,r=t)}return{left:n,right:r}}function qt(o,t,e){return t===null?o:(o===null||(t=z(o.key,t,e),t.left=o),t)}function nt(o,t,e,n,r){if(o){n(""+t+(e?"└── ":"├── ")+r(o)+`
22
- `);var i=t+(e?" ":"│ ");o.left&&nt(o.left,i,!1,n,r),o.right&&nt(o.right,i,!0,n,r)}}var rt=function(){function o(t){t===void 0&&(t=zt),this._root=null,this._size=0,this._comparator=t}return o.prototype.insert=function(t,e){return this._size++,this._root=et(t,e,this._root,this._comparator)},o.prototype.add=function(t,e){var n=new T(t,e);this._root===null&&(n.left=n.right=null,this._size++,this._root=n);var r=this._comparator,i=z(t,this._root,r),u=r(t,i.key);return u===0?this._root=i:(u<0?(n.left=i.left,n.right=i,i.left=null):u>0&&(n.right=i.right,n.left=i,i.right=null),this._size++,this._root=n),this._root},o.prototype.remove=function(t){this._root=this._remove(t,this._root,this._comparator)},o.prototype._remove=function(t,e,n){var r;if(e===null)return null;e=z(t,e,n);var i=n(t,e.key);return i===0?(e.left===null?r=e.right:(r=z(t,e.left,n),r.right=e.right),this._size--,r):e},o.prototype.pop=function(){var t=this._root;if(t){for(;t.left;)t=t.left;return this._root=z(t.key,this._root,this._comparator),this._root=this._remove(t.key,this._root,this._comparator),{key:t.key,data:t.data}}return null},o.prototype.findStatic=function(t){for(var e=this._root,n=this._comparator;e;){var r=n(t,e.key);if(r===0)return e;r<0?e=e.left:e=e.right}return null},o.prototype.find=function(t){return this._root&&(this._root=z(t,this._root,this._comparator),this._comparator(t,this._root.key)!==0)?null:this._root},o.prototype.contains=function(t){for(var e=this._root,n=this._comparator;e;){var r=n(t,e.key);if(r===0)return!0;r<0?e=e.left:e=e.right}return!1},o.prototype.forEach=function(t,e){for(var n=this._root,r=[],i=!1;!i;)n!==null?(r.push(n),n=n.left):r.length!==0?(n=r.pop(),t.call(e,n),n=n.right):i=!0;return this},o.prototype.range=function(t,e,n,r){for(var i=[],u=this._comparator,l=this._root,c;i.length!==0||l;)if(l)i.push(l),l=l.left;else{if(l=i.pop(),c=u(l.key,e),c>0)break;if(u(l.key,t)>=0&&n.call(r,l))return this;l=l.right}return this},o.prototype.keys=function(){var t=[];return this.forEach(function(e){var n=e.key;return t.push(n)}),t},o.prototype.values=function(){var t=[];return this.forEach(function(e){var n=e.data;return t.push(n)}),t},o.prototype.min=function(){return this._root?this.minNode(this._root).key:null},o.prototype.max=function(){return this._root?this.maxNode(this._root).key:null},o.prototype.minNode=function(t){if(t===void 0&&(t=this._root),t)for(;t.left;)t=t.left;return t},o.prototype.maxNode=function(t){if(t===void 0&&(t=this._root),t)for(;t.right;)t=t.right;return t},o.prototype.at=function(t){for(var e=this._root,n=!1,r=0,i=[];!n;)if(e)i.push(e),e=e.left;else if(i.length>0){if(e=i.pop(),r===t)return e;r++,e=e.right}else n=!0;return null},o.prototype.next=function(t){var e=this._root,n=null;if(t.right){for(n=t.right;n.left;)n=n.left;return n}for(var r=this._comparator;e;){var i=r(t.key,e.key);if(i===0)break;i<0?(n=e,e=e.left):e=e.right}return n},o.prototype.prev=function(t){var e=this._root,n=null;if(t.left!==null){for(n=t.left;n.right;)n=n.right;return n}for(var r=this._comparator;e;){var i=r(t.key,e.key);if(i===0)break;i<0?e=e.left:(n=e,e=e.right)}return n},o.prototype.clear=function(){return this._root=null,this._size=0,this},o.prototype.toList=function(){return Qt(this._root)},o.prototype.load=function(t,e,n){e===void 0&&(e=[]),n===void 0&&(n=!1);var r=t.length,i=this._comparator;if(n&&st(t,e,0,r-1,i),this._root===null)this._root=it(t,e,0,r),this._size=r;else{var u=Ut(this.toList(),Vt(t,e),i);r=this._size+r,this._root=ot({head:u},0,r)}return this},o.prototype.isEmpty=function(){return this._root===null},Object.defineProperty(o.prototype,"size",{get:function(){return this._size},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),o.prototype.toString=function(t){t===void 0&&(t=function(n){return String(n.key)});var e=[];return nt(this._root,"",!0,function(n){return e.push(n)},t),e.join("")},o.prototype.update=function(t,e,n){var r=this._comparator,i=pt(t,this._root,r),u=i.left,l=i.right;r(t,e)<0?l=et(e,n,l,r):u=et(e,n,u,r),this._root=qt(u,l,r)},o.prototype.split=function(t){return pt(t,this._root,this._comparator)},o.prototype[Symbol.iterator]=function(){var t,e,n;return Tt(this,function(r){switch(r.label){case 0:t=this._root,e=[],n=!1,r.label=1;case 1:return n?[3,6]:t===null?[3,2]:(e.push(t),t=t.left,[3,5]);case 2:return e.length===0?[3,4]:(t=e.pop(),[4,t]);case 3:return r.sent(),t=t.right,[3,5];case 4:n=!0,r.label=5;case 5:return[3,1];case 6:return[2]}})},o}();function it(o,t,e,n){var r=n-e;if(r>0){var i=e+Math.floor(r/2),u=o[i],l=t[i],c=new T(u,l);return c.left=it(o,t,e,i),c.right=it(o,t,i+1,n),c}return null}function Vt(o,t){for(var e=new T(null,null),n=e,r=0;r<o.length;r++)n=n.next=new T(o[r],t[r]);return n.next=null,e.next}function Qt(o){for(var t=o,e=[],n=!1,r=new T(null,null),i=r;!n;)t?(e.push(t),t=t.left):e.length>0?(t=i=i.next=e.pop(),t=t.right):n=!0;return i.next=null,r.next}function ot(o,t,e){var n=e-t;if(n>0){var r=t+Math.floor(n/2),i=ot(o,t,r),u=o.head;return u.left=i,o.head=o.head.next,u.right=ot(o,r+1,e),u}return null}function Ut(o,t,e){for(var n=new T(null,null),r=n,i=o,u=t;i!==null&&u!==null;)e(i.key,u.key)<0?(r.next=i,i=i.next):(r.next=u,u=u.next),r=r.next;return i!==null?r.next=i:u!==null&&(r.next=u),n.next}function st(o,t,e,n,r){if(!(e>=n)){for(var i=o[e+n>>1],u=e-1,l=n+1;;){do u++;while(r(o[u],i)<0);do l--;while(r(o[l],i)>0);if(u>=l)break;var c=o[u];o[u]=o[l],o[l]=c,c=t[u],t[u]=t[l],t[l]=c}st(o,t,e,l,r),st(o,t,l+1,n,r)}}const G=11102230246251565e-32,b=134217729,Yt=(3+8*G)*G;function lt(o,t,e,n,r){let i,u,l,c,f=t[0],a=n[0],s=0,h=0;a>f==a>-f?(i=f,f=t[++s]):(i=a,a=n[++h]);let g=0;if(s<o&&h<e)for(a>f==a>-f?(u=f+i,l=i-(u-f),f=t[++s]):(u=a+i,l=i-(u-a),a=n[++h]),i=u,l!==0&&(r[g++]=l);s<o&&h<e;)a>f==a>-f?(u=i+f,c=u-i,l=i-(u-c)+(f-c),f=t[++s]):(u=i+a,c=u-i,l=i-(u-c)+(a-c),a=n[++h]),i=u,l!==0&&(r[g++]=l);for(;s<o;)u=i+f,c=u-i,l=i-(u-c)+(f-c),f=t[++s],i=u,l!==0&&(r[g++]=l);for(;h<e;)u=i+a,c=u-i,l=i-(u-c)+(a-c),a=n[++h],i=u,l!==0&&(r[g++]=l);return(i!==0||g===0)&&(r[g++]=i),g}function Dt(o,t){let e=t[0];for(let n=1;n<o;n++)e+=t[n];return e}function U(o){return new Float64Array(o)}const Xt=(3+16*G)*G,jt=(2+12*G)*G,Wt=(9+64*G)*G*G,Q=U(4),yt=U(8),xt=U(12),dt=U(16),M=U(4);function Zt(o,t,e,n,r,i,u){let l,c,f,a,s,h,g,y,p,d,x,v,m,w,E,_,k,P;const A=o-r,F=e-r,O=t-i,N=n-i;w=A*N,h=b*A,g=h-(h-A),y=A-g,h=b*N,p=h-(h-N),d=N-p,E=y*d-(w-g*p-y*p-g*d),_=O*F,h=b*O,g=h-(h-O),y=O-g,h=b*F,p=h-(h-F),d=F-p,k=y*d-(_-g*p-y*p-g*d),x=E-k,s=E-x,Q[0]=E-(x+s)+(s-k),v=w+x,s=v-w,m=w-(v-s)+(x-s),x=m-_,s=m-x,Q[1]=m-(x+s)+(s-_),P=v+x,s=P-v,Q[2]=v-(P-s)+(x-s),Q[3]=P;let B=Dt(4,Q),X=jt*u;if(B>=X||-B>=X||(s=o-A,l=o-(A+s)+(s-r),s=e-F,f=e-(F+s)+(s-r),s=t-O,c=t-(O+s)+(s-i),s=n-N,a=n-(N+s)+(s-i),l===0&&c===0&&f===0&&a===0)||(X=Wt*u+Yt*Math.abs(B),B+=A*a+N*l-(O*f+F*c),B>=X||-B>=X))return B;w=l*N,h=b*l,g=h-(h-l),y=l-g,h=b*N,p=h-(h-N),d=N-p,E=y*d-(w-g*p-y*p-g*d),_=c*F,h=b*c,g=h-(h-c),y=c-g,h=b*F,p=h-(h-F),d=F-p,k=y*d-(_-g*p-y*p-g*d),x=E-k,s=E-x,M[0]=E-(x+s)+(s-k),v=w+x,s=v-w,m=w-(v-s)+(x-s),x=m-_,s=m-x,M[1]=m-(x+s)+(s-_),P=v+x,s=P-v,M[2]=v-(P-s)+(x-s),M[3]=P;const de=lt(4,Q,4,M,yt);w=A*a,h=b*A,g=h-(h-A),y=A-g,h=b*a,p=h-(h-a),d=a-p,E=y*d-(w-g*p-y*p-g*d),_=O*f,h=b*O,g=h-(h-O),y=O-g,h=b*f,p=h-(h-f),d=f-p,k=y*d-(_-g*p-y*p-g*d),x=E-k,s=E-x,M[0]=E-(x+s)+(s-k),v=w+x,s=v-w,m=w-(v-s)+(x-s),x=m-_,s=m-x,M[1]=m-(x+s)+(s-_),P=v+x,s=P-v,M[2]=v-(P-s)+(x-s),M[3]=P;const ve=lt(de,yt,4,M,xt);w=l*a,h=b*l,g=h-(h-l),y=l-g,h=b*a,p=h-(h-a),d=a-p,E=y*d-(w-g*p-y*p-g*d),_=c*f,h=b*c,g=h-(h-c),y=c-g,h=b*f,p=h-(h-f),d=f-p,k=y*d-(_-g*p-y*p-g*d),x=E-k,s=E-x,M[0]=E-(x+s)+(s-k),v=w+x,s=v-w,m=w-(v-s)+(x-s),x=m-_,s=m-x,M[1]=m-(x+s)+(s-_),P=v+x,s=P-v,M[2]=v-(P-s)+(x-s),M[3]=P;const we=lt(ve,xt,4,M,dt);return dt[we-1]}function Jt(o,t,e,n,r,i){const u=(t-i)*(e-r),l=(o-r)*(n-i),c=u-l,f=Math.abs(u+l);return Math.abs(c)>=Xt*f?c:-Zt(o,t,e,n,r,i,f)}const Y=(o,t)=>o.ll.x<=t.x&&t.x<=o.ur.x&&o.ll.y<=t.y&&t.y<=o.ur.y,ut=(o,t)=>{if(t.ur.x<o.ll.x||o.ur.x<t.ll.x||t.ur.y<o.ll.y||o.ur.y<t.ll.y)return null;const e=o.ll.x<t.ll.x?t.ll.x:o.ll.x,n=o.ur.x<t.ur.x?o.ur.x:t.ur.x,r=o.ll.y<t.ll.y?t.ll.y:o.ll.y,i=o.ur.y<t.ur.y?o.ur.y:t.ur.y;return{ll:{x:e,y:r},ur:{x:n,y:i}}};let q=Number.EPSILON;q===void 0&&(q=Math.pow(2,-52));const Kt=q*q,vt=(o,t)=>{if(-q<o&&o<q&&-q<t&&t<q)return 0;const e=o-t;return e*e<Kt*o*t?0:o<t?-1:1};class Ht{constructor(){this.reset()}reset(){this.xRounder=new wt,this.yRounder=new wt}round(t,e){return{x:this.xRounder.round(t),y:this.yRounder.round(e)}}}class wt{constructor(){this.tree=new rt,this.round(0)}round(t){const e=this.tree.add(t),n=this.tree.prev(e);if(n!==null&&vt(e.key,n.key)===0)return this.tree.remove(t),n.key;const r=this.tree.next(e);return r!==null&&vt(e.key,r.key)===0?(this.tree.remove(t),r.key):t}}const D=new Ht,W=(o,t)=>o.x*t.y-o.y*t.x,mt=(o,t)=>o.x*t.x+o.y*t.y,Et=(o,t,e)=>{const n=Jt(o.x,o.y,t.x,t.y,e.x,e.y);return n>0?-1:n<0?1:0},Z=o=>Math.sqrt(mt(o,o)),te=(o,t,e)=>{const n={x:t.x-o.x,y:t.y-o.y},r={x:e.x-o.x,y:e.y-o.y};return W(r,n)/Z(r)/Z(n)},ee=(o,t,e)=>{const n={x:t.x-o.x,y:t.y-o.y},r={x:e.x-o.x,y:e.y-o.y};return mt(r,n)/Z(r)/Z(n)},St=(o,t,e)=>t.y===0?null:{x:o.x+t.x/t.y*(e-o.y),y:e},bt=(o,t,e)=>t.x===0?null:{x:e,y:o.y+t.y/t.x*(e-o.x)},ne=(o,t,e,n)=>{if(t.x===0)return bt(e,n,o.x);if(n.x===0)return bt(o,t,e.x);if(t.y===0)return St(e,n,o.y);if(n.y===0)return St(o,t,e.y);const r=W(t,n);if(r==0)return null;const i={x:e.x-o.x,y:e.y-o.y},u=W(i,t)/r,l=W(i,n)/r,c=o.x+l*t.x,f=e.x+u*n.x,a=o.y+l*t.y,s=e.y+u*n.y,h=(c+f)/2,g=(a+s)/2;return{x:h,y:g}};class I{static compare(t,e){const n=I.comparePoints(t.point,e.point);return n!==0?n:(t.point!==e.point&&t.link(e),t.isLeft!==e.isLeft?t.isLeft?1:-1:V.compare(t.segment,e.segment))}static comparePoints(t,e){return t.x<e.x?-1:t.x>e.x?1:t.y<e.y?-1:t.y>e.y?1:0}constructor(t,e){t.events===void 0?t.events=[this]:t.events.push(this),this.point=t,this.isLeft=e}link(t){if(t.point===this.point)throw new Error("Tried to link already linked events");const e=t.point.events;for(let n=0,r=e.length;n<r;n++){const i=e[n];this.point.events.push(i),i.point=this.point}this.checkForConsuming()}checkForConsuming(){const t=this.point.events.length;for(let e=0;e<t;e++){const n=this.point.events[e];if(n.segment.consumedBy===void 0)for(let r=e+1;r<t;r++){const i=this.point.events[r];i.consumedBy===void 0&&n.otherSE.point.events===i.otherSE.point.events&&n.segment.consume(i.segment)}}}getAvailableLinkedEvents(){const t=[];for(let e=0,n=this.point.events.length;e<n;e++){const r=this.point.events[e];r!==this&&!r.segment.ringOut&&r.segment.isInResult()&&t.push(r)}return t}getLeftmostComparator(t){const e=new Map,n=r=>{const i=r.otherSE;e.set(r,{sine:te(this.point,t.point,i.point),cosine:ee(this.point,t.point,i.point)})};return(r,i)=>{e.has(r)||n(r),e.has(i)||n(i);const{sine:u,cosine:l}=e.get(r),{sine:c,cosine:f}=e.get(i);return u>=0&&c>=0?l<f?1:l>f?-1:0:u<0&&c<0?l<f?-1:l>f?1:0:c<u?-1:c>u?1:0}}}let re=0;class V{static compare(t,e){const n=t.leftSE.point.x,r=e.leftSE.point.x,i=t.rightSE.point.x,u=e.rightSE.point.x;if(u<n)return 1;if(i<r)return-1;const l=t.leftSE.point.y,c=e.leftSE.point.y,f=t.rightSE.point.y,a=e.rightSE.point.y;if(n<r){if(c<l&&c<f)return 1;if(c>l&&c>f)return-1;const s=t.comparePoint(e.leftSE.point);if(s<0)return 1;if(s>0)return-1;const h=e.comparePoint(t.rightSE.point);return h!==0?h:-1}if(n>r){if(l<c&&l<a)return-1;if(l>c&&l>a)return 1;const s=e.comparePoint(t.leftSE.point);if(s!==0)return s;const h=t.comparePoint(e.rightSE.point);return h<0?1:h>0?-1:1}if(l<c)return-1;if(l>c)return 1;if(i<u){const s=e.comparePoint(t.rightSE.point);if(s!==0)return s}if(i>u){const s=t.comparePoint(e.rightSE.point);if(s<0)return 1;if(s>0)return-1}if(i!==u){const s=f-l,h=i-n,g=a-c,y=u-r;if(s>h&&g<y)return 1;if(s<h&&g>y)return-1}return i>u?1:i<u||f<a?-1:f>a?1:t.id<e.id?-1:t.id>e.id?1:0}constructor(t,e,n,r){this.id=++re,this.leftSE=t,t.segment=this,t.otherSE=e,this.rightSE=e,e.segment=this,e.otherSE=t,this.rings=n,this.windings=r}static fromRing(t,e,n){let r,i,u;const l=I.comparePoints(t,e);if(l<0)r=t,i=e,u=1;else if(l>0)r=e,i=t,u=-1;else throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);const c=new I(r,!0),f=new I(i,!1);return new V(c,f,[n],[u])}replaceRightSE(t){this.rightSE=t,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const t=this.leftSE.point.y,e=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:t<e?t:e},ur:{x:this.rightSE.point.x,y:t>e?t:e}}}vector(){return{x:this.rightSE.point.x-this.leftSE.point.x,y:this.rightSE.point.y-this.leftSE.point.y}}isAnEndpoint(t){return t.x===this.leftSE.point.x&&t.y===this.leftSE.point.y||t.x===this.rightSE.point.x&&t.y===this.rightSE.point.y}comparePoint(t){if(this.isAnEndpoint(t))return 0;const e=this.leftSE.point,n=this.rightSE.point,r=this.vector();if(e.x===n.x)return t.x===e.x?0:t.x<e.x?1:-1;const i=(t.y-e.y)/r.y,u=e.x+i*r.x;if(t.x===u)return 0;const l=(t.x-e.x)/r.x,c=e.y+l*r.y;return t.y===c?0:t.y<c?-1:1}getIntersection(t){const e=this.bbox(),n=t.bbox(),r=ut(e,n);if(r===null)return null;const i=this.leftSE.point,u=this.rightSE.point,l=t.leftSE.point,c=t.rightSE.point,f=Y(e,l)&&this.comparePoint(l)===0,a=Y(n,i)&&t.comparePoint(i)===0,s=Y(e,c)&&this.comparePoint(c)===0,h=Y(n,u)&&t.comparePoint(u)===0;if(a&&f)return h&&!s?u:!h&&s?c:null;if(a)return s&&i.x===c.x&&i.y===c.y?null:i;if(f)return h&&u.x===l.x&&u.y===l.y?null:l;if(h&&s)return null;if(h)return u;if(s)return c;const g=ne(i,this.vector(),l,t.vector());return g===null||!Y(r,g)?null:D.round(g.x,g.y)}split(t){const e=[],n=t.events!==void 0,r=new I(t,!0),i=new I(t,!1),u=this.rightSE;this.replaceRightSE(i),e.push(i),e.push(r);const l=new V(r,u,this.rings.slice(),this.windings.slice());return I.comparePoints(l.leftSE.point,l.rightSE.point)>0&&l.swapEvents(),I.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),n&&(r.checkForConsuming(),i.checkForConsuming()),e}swapEvents(){const t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let e=0,n=this.windings.length;e<n;e++)this.windings[e]*=-1}consume(t){let e=this,n=t;for(;e.consumedBy;)e=e.consumedBy;for(;n.consumedBy;)n=n.consumedBy;const r=V.compare(e,n);if(r!==0){if(r>0){const i=e;e=n,n=i}if(e.prev===n){const i=e;e=n,n=i}for(let i=0,u=n.rings.length;i<u;i++){const l=n.rings[i],c=n.windings[i],f=e.rings.indexOf(l);f===-1?(e.rings.push(l),e.windings.push(c)):e.windings[f]+=c}n.rings=null,n.windings=null,n.consumedBy=e,n.leftSE.consumedBy=e.leftSE,n.rightSE.consumedBy=e.rightSE}}prevInResult(){return this._prevInResult!==void 0?this._prevInResult:(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null,this._prevInResult)}beforeState(){if(this._beforeState!==void 0)return this._beforeState;if(!this.prev)this._beforeState={rings:[],windings:[],multiPolys:[]};else{const t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}return this._beforeState}afterState(){if(this._afterState!==void 0)return this._afterState;const t=this.beforeState();this._afterState={rings:t.rings.slice(0),windings:t.windings.slice(0),multiPolys:[]};const e=this._afterState.rings,n=this._afterState.windings,r=this._afterState.multiPolys;for(let l=0,c=this.rings.length;l<c;l++){const f=this.rings[l],a=this.windings[l],s=e.indexOf(f);s===-1?(e.push(f),n.push(a)):n[s]+=a}const i=[],u=[];for(let l=0,c=e.length;l<c;l++){if(n[l]===0)continue;const f=e[l],a=f.poly;if(u.indexOf(a)===-1)if(f.isExterior)i.push(a);else{u.indexOf(a)===-1&&u.push(a);const s=i.indexOf(f.poly);s!==-1&&i.splice(s,1)}}for(let l=0,c=i.length;l<c;l++){const f=i[l].multiPoly;r.indexOf(f)===-1&&r.push(f)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(this._isInResult!==void 0)return this._isInResult;const t=this.beforeState().multiPolys,e=this.afterState().multiPolys;switch(C.type){case"union":{const n=t.length===0,r=e.length===0;this._isInResult=n!==r;break}case"intersection":{let n,r;t.length<e.length?(n=t.length,r=e.length):(n=e.length,r=t.length),this._isInResult=r===C.numMultiPolys&&n<r;break}case"xor":{const n=Math.abs(t.length-e.length);this._isInResult=n%2===1;break}case"difference":{const n=r=>r.length===1&&r[0].isSubject;this._isInResult=n(t)!==n(e);break}default:throw new Error(`Unrecognized operation type found ${C.type}`)}return this._isInResult}}class _t{constructor(t,e,n){if(!Array.isArray(t)||t.length===0)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=e,this.isExterior=n,this.segments=[],typeof t[0][0]!="number"||typeof t[0][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const r=D.round(t[0][0],t[0][1]);this.bbox={ll:{x:r.x,y:r.y},ur:{x:r.x,y:r.y}};let i=r;for(let u=1,l=t.length;u<l;u++){if(typeof t[u][0]!="number"||typeof t[u][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");let c=D.round(t[u][0],t[u][1]);c.x===i.x&&c.y===i.y||(this.segments.push(V.fromRing(i,c,this)),c.x<this.bbox.ll.x&&(this.bbox.ll.x=c.x),c.y<this.bbox.ll.y&&(this.bbox.ll.y=c.y),c.x>this.bbox.ur.x&&(this.bbox.ur.x=c.x),c.y>this.bbox.ur.y&&(this.bbox.ur.y=c.y),i=c)}(r.x!==i.x||r.y!==i.y)&&this.segments.push(V.fromRing(i,r,this))}getSweepEvents(){const t=[];for(let e=0,n=this.segments.length;e<n;e++){const r=this.segments[e];t.push(r.leftSE),t.push(r.rightSE)}return t}}class ie{constructor(t,e){if(!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new _t(t[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let n=1,r=t.length;n<r;n++){const i=new _t(t[n],this,!1);i.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=i.bbox.ll.x),i.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=i.bbox.ll.y),i.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=i.bbox.ur.x),i.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=i.bbox.ur.y),this.interiorRings.push(i)}this.multiPoly=e}getSweepEvents(){const t=this.exteriorRing.getSweepEvents();for(let e=0,n=this.interiorRings.length;e<n;e++){const r=this.interiorRings[e].getSweepEvents();for(let i=0,u=r.length;i<u;i++)t.push(r[i])}return t}}class Pt{constructor(t,e){if(!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{typeof t[0][0][0]=="number"&&(t=[t])}catch{}this.polys=[],this.bbox={ll:{x:Number.POSITIVE_INFINITY,y:Number.POSITIVE_INFINITY},ur:{x:Number.NEGATIVE_INFINITY,y:Number.NEGATIVE_INFINITY}};for(let n=0,r=t.length;n<r;n++){const i=new ie(t[n],this);i.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=i.bbox.ll.x),i.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=i.bbox.ll.y),i.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=i.bbox.ur.x),i.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=i.bbox.ur.y),this.polys.push(i)}this.isSubject=e}getSweepEvents(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const r=this.polys[e].getSweepEvents();for(let i=0,u=r.length;i<u;i++)t.push(r[i])}return t}}class J{static factory(t){const e=[];for(let n=0,r=t.length;n<r;n++){const i=t[n];if(!i.isInResult()||i.ringOut)continue;let u=null,l=i.leftSE,c=i.rightSE;const f=[l],a=l.point,s=[];for(;u=l,l=c,f.push(l),l.point!==a;)for(;;){const h=l.getAvailableLinkedEvents();if(h.length===0){const p=f[0].point,d=f[f.length-1].point;throw new Error(`Unable to complete output ring starting at [${p.x}, ${p.y}]. Last matching segment found ends at [${d.x}, ${d.y}].`)}if(h.length===1){c=h[0].otherSE;break}let g=null;for(let p=0,d=s.length;p<d;p++)if(s[p].point===l.point){g=p;break}if(g!==null){const p=s.splice(g)[0],d=f.splice(p.index);d.unshift(d[0].otherSE),e.push(new J(d.reverse()));continue}s.push({index:f.length,point:l.point});const y=l.getLeftmostComparator(u);c=h.sort(y)[0].otherSE;break}e.push(new J(f))}return e}constructor(t){this.events=t;for(let e=0,n=t.length;e<n;e++)t[e].segment.ringOut=this;this.poly=null}getGeom(){let t=this.events[0].point;const e=[t];for(let f=1,a=this.events.length-1;f<a;f++){const s=this.events[f].point,h=this.events[f+1].point;Et(s,t,h)!==0&&(e.push(s),t=s)}if(e.length===1)return null;const n=e[0],r=e[1];Et(n,t,r)===0&&e.shift(),e.push(e[0]);const i=this.isExteriorRing()?1:-1,u=this.isExteriorRing()?0:e.length-1,l=this.isExteriorRing()?e.length:-1,c=[];for(let f=u;f!=l;f+=i)c.push([e[f].x,e[f].y]);return c}isExteriorRing(){if(this._isExteriorRing===void 0){const t=this.enclosingRing();this._isExteriorRing=t?!t.isExteriorRing():!0}return this._isExteriorRing}enclosingRing(){return this._enclosingRing===void 0&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let t=this.events[0];for(let r=1,i=this.events.length;r<i;r++){const u=this.events[r];I.compare(t,u)>0&&(t=u)}let e=t.segment.prevInResult(),n=e?e.prevInResult():null;for(;;){if(!e)return null;if(!n)return e.ringOut;if(n.ringOut!==e.ringOut)return n.ringOut.enclosingRing()!==e.ringOut?e.ringOut:e.ringOut.enclosingRing();e=n.prevInResult(),n=e?e.prevInResult():null}}}class Mt{constructor(t){this.exteriorRing=t,t.poly=this,this.interiorRings=[]}addInterior(t){this.interiorRings.push(t),t.poly=this}getGeom(){const t=[this.exteriorRing.getGeom()];if(t[0]===null)return null;for(let e=0,n=this.interiorRings.length;e<n;e++){const r=this.interiorRings[e].getGeom();r!==null&&t.push(r)}return t}}class oe{constructor(t){this.rings=t,this.polys=this._composePolys(t)}getGeom(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const r=this.polys[e].getGeom();r!==null&&t.push(r)}return t}_composePolys(t){const e=[];for(let n=0,r=t.length;n<r;n++){const i=t[n];if(!i.poly)if(i.isExteriorRing())e.push(new Mt(i));else{const u=i.enclosingRing();u.poly||e.push(new Mt(u)),u.poly.addInterior(i)}}return e}}class se{constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:V.compare;this.queue=t,this.tree=new rt(e),this.segments=[]}process(t){const e=t.segment,n=[];if(t.consumedBy)return t.isLeft?this.queue.remove(t.otherSE):this.tree.remove(e),n;const r=t.isLeft?this.tree.add(e):this.tree.find(e);if(!r)throw new Error(`Unable to find segment #${e.id} [${e.leftSE.point.x}, ${e.leftSE.point.y}] -> [${e.rightSE.point.x}, ${e.rightSE.point.y}] in SweepLine tree.`);let i=r,u=r,l,c;for(;l===void 0;)i=this.tree.prev(i),i===null?l=null:i.key.consumedBy===void 0&&(l=i.key);for(;c===void 0;)u=this.tree.next(u),u===null?c=null:u.key.consumedBy===void 0&&(c=u.key);if(t.isLeft){let f=null;if(l){const s=l.getIntersection(e);if(s!==null&&(e.isAnEndpoint(s)||(f=s),!l.isAnEndpoint(s))){const h=this._splitSafely(l,s);for(let g=0,y=h.length;g<y;g++)n.push(h[g])}}let a=null;if(c){const s=c.getIntersection(e);if(s!==null&&(e.isAnEndpoint(s)||(a=s),!c.isAnEndpoint(s))){const h=this._splitSafely(c,s);for(let g=0,y=h.length;g<y;g++)n.push(h[g])}}if(f!==null||a!==null){let s=null;f===null?s=a:a===null?s=f:s=I.comparePoints(f,a)<=0?f:a,this.queue.remove(e.rightSE),n.push(e.rightSE);const h=e.split(s);for(let g=0,y=h.length;g<y;g++)n.push(h[g])}n.length>0?(this.tree.remove(e),n.push(t)):(this.segments.push(e),e.prev=l)}else{if(l&&c){const f=l.getIntersection(c);if(f!==null){if(!l.isAnEndpoint(f)){const a=this._splitSafely(l,f);for(let s=0,h=a.length;s<h;s++)n.push(a[s])}if(!c.isAnEndpoint(f)){const a=this._splitSafely(c,f);for(let s=0,h=a.length;s<h;s++)n.push(a[s])}}}this.tree.remove(e)}return n}_splitSafely(t,e){this.tree.remove(t);const n=t.rightSE;this.queue.remove(n);const r=t.split(e);return r.push(n),t.consumedBy===void 0&&this.tree.add(t),r}}const Lt=typeof process<"u"&&process.env.POLYGON_CLIPPING_MAX_QUEUE_SIZE||1e6,le=typeof process<"u"&&process.env.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS||1e6;class ue{run(t,e,n){C.type=t,D.reset();const r=[new Pt(e,!0)];for(let s=0,h=n.length;s<h;s++)r.push(new Pt(n[s],!1));if(C.numMultiPolys=r.length,C.type==="difference"){const s=r[0];let h=1;for(;h<r.length;)ut(r[h].bbox,s.bbox)!==null?h++:r.splice(h,1)}if(C.type==="intersection")for(let s=0,h=r.length;s<h;s++){const g=r[s];for(let y=s+1,p=r.length;y<p;y++)if(ut(g.bbox,r[y].bbox)===null)return[]}const i=new rt(I.compare);for(let s=0,h=r.length;s<h;s++){const g=r[s].getSweepEvents();for(let y=0,p=g.length;y<p;y++)if(i.insert(g[y]),i.size>Lt)throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big).")}const u=new se(i);let l=i.size,c=i.pop();for(;c;){const s=c.key;if(i.size===l){const g=s.segment;throw new Error(`Unable to pop() ${s.isLeft?"left":"right"} SweepEvent [${s.point.x}, ${s.point.y}] from segment #${g.id} [${g.leftSE.point.x}, ${g.leftSE.point.y}] -> [${g.rightSE.point.x}, ${g.rightSE.point.y}] from queue.`)}if(i.size>Lt)throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big).");if(u.segments.length>le)throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments).");const h=u.process(s);for(let g=0,y=h.length;g<y;g++){const p=h[g];p.consumedBy===void 0&&i.insert(p)}l=i.size,c=i.pop()}D.reset();const f=J.factory(u.segments);return new oe(f).getGeom()}}const C=new ue;var Rt={union:function(o){for(var t=arguments.length,e=new Array(t>1?t-1:0),n=1;n<t;n++)e[n-1]=arguments[n];return C.run("union",o,e)},intersection:function(o){for(var t=arguments.length,e=new Array(t>1?t-1:0),n=1;n<t;n++)e[n-1]=arguments[n];return C.run("intersection",o,e)},xor:function(o){for(var t=arguments.length,e=new Array(t>1?t-1:0),n=1;n<t;n++)e[n-1]=arguments[n];return C.run("xor",o,e)},difference:function(o){for(var t=arguments.length,e=new Array(t>1?t-1:0),n=1;n<t;n++)e[n-1]=arguments[n];return C.run("difference",o,e)}};function fe(o){const t=[];if(tt(o,r=>{t.push(r.coordinates)}),t.length<2)throw new Error("Must have at least two features");const e=o.features[0].properties||{},n=Rt.difference(t[0],...t.slice(1));return n.length===0?null:n.length===1?K(n[0],e):ht(n,e)}var ce=fe;function he(o){if(!o)throw new Error("geojson is required");var t=[];return Bt(o,function(e){t.push(e)}),H(t)}var ae=he;function ge(o,t={}){const e=[];if(tt(o,r=>{e.push(r.coordinates)}),e.length<2)throw new Error("Must have at least 2 geometries");const n=Rt.union(e[0],...e.slice(1));return n.length===0?null:n.length===1?K(n[0],t.properties):ht(n,t.properties)}var pe=ge;function It(o){const t=[...o];return t[2]<t[0]&&(Math.abs((t[0]+t[2]+360)/2)>Math.abs((t[0]-360+t[2])/2)?t[0]-=360:t[2]+=360),t}function kt(o,t){const e=ce(H([K([[[180,90],[-180,90],[-180,-90],[180,-90],[180,90]]]),o]));if(!e)return;e.properties={isMask:!0};const n=It(gt(o)),r=(n[2]-n[0])/360/1e3,i=n[0]<-180,u=n[2]>180,l=ae(o);if(l.features.length>1&&(i||u))for(const c of l.features){const f=It(gt(c));if(u&&f[0]<-180+r)for(const a of c.geometry.coordinates)for(const s of a)s[0]+=360-r;if(i&&f[2]>180-r)for(const a of c.geometry.coordinates)for(const s of a)s[0]-=360-r}t(H([l.features.length<2?o:pe(l)??o,e]))}const Ct="EPSG:4326";function ye(o){var i;const t=o.getProperties(),{isMask:e}=t,n=(i=o.getGeometry())==null?void 0:i.getType(),r=e?0:n==="LineString"||n==="MultiLineString"?3:2;return new Nt({stroke:e?void 0:new ct({color:"#3170fe",lineDash:[r,r],width:r,lineCap:"butt"}),fill:e?new ft({color:"#00000020"}):void 0,image:new Ot({src:`/icons/marker_${t.isReverse?"reverse":t.isSelected?"selected":"unselected"}.svg`,anchor:[.5,1]}),zIndex:t.isSelected?2:t.isReverse?0:1,text:t.isSelected&&t.tooltip?new Gt({backgroundFill:new ft({color:"white"}),text:t.tooltip,offsetY:-40,backgroundStroke:new ct({color:"white",lineJoin:"round",width:3}),padding:[2,0,0,2]}):void 0})}function xe(o,t={},e={},n=ye){let r=-1,i,u,l,c=!1;const f=new At({updateWhileAnimating:!0});o.addLayer(f);const a=new Ft({});f.setSource(a),f.setStyle(n),o.on("click",y=>{o.forEachFeatureAtPixel(y.pixel,p=>{const d=p.getId();if(d)return y.stopPropagation(),u==null||u({type:"markerClick",id:d}),p})}),o.on("pointermove",y=>{const p=o.forEachFeatureAtPixel(y.pixel,d=>d.getId());i!==p&&(i&&(u==null||u({type:"markerMouseLeave",id:i})),p&&(u==null||u({type:"markerMouseEnter",id:p})),o.getTargetElement().style.cursor=p?"pointer":c?"crosshair":"",i=p)});function s(){return $.getUserProjection()??o.getView().getProjection()}function h(y){return y.transform(Ct,s())}const g=y=>{u==null||u({type:"mapClick",coordinates:$.toLonLat(y.coordinate,s())})};return{setEventHandler(y){y?(u=y,o.on("click",g)):(u=void 0,o.un("click",g))},flyTo(y,p){o.getView().animate({center:$.fromLonLat(y,s()),...p?{zoom:p}:{},duration:2e3,...t})},fitBounds(y,p,d){o.getView().fit($.transformExtent(y,Ct,s()),{padding:[p,p,p,p],...d?{maxZoom:d}:{},duration:2e3,...e})},indicateReverse(y){c=y,o.getTargetElement().style.cursor=y?"crosshair":""},setReverseMarker(y){l?y?l.getGeometry().setCoordinates($.fromLonLat(y,s())):(a.removeFeature(l),l.dispose(),l=void 0):y&&(l=new L.Feature(new R.Point($.fromLonLat(y,s()))),l.setProperties({isReverse:!0}),a.addFeature(l))},setFeatures(y,p,d){function x(v){var m;if(v)for(const w of v.features){const E=w.geometry.type==="Polygon"?new R.Polygon(w.geometry.coordinates):w.geometry.type==="MultiPolygon"?new R.MultiPolygon(w.geometry.coordinates):null;E&&a.addFeature(new L.Feature({isMask:!!((m=w.properties)!=null&&m.isMask),geometry:h(E)}))}}a.clear(),l&&a.addFeature(l);t:if(p){let v=!1;if(p.geometry.type==="GeometryCollection"){const m=p.geometry.geometries.map(w=>w.type==="Polygon"?new R.Polygon(w.coordinates):w.type==="MultiPolygon"?new R.MultiPolygon(w.coordinates):null).filter(w=>!!w);if(m.length>0)a.addFeature(new L.Feature(h(new R.GeometryCollection(m)))),v=!0;else for(const w of p.geometry.geometries)w.type==="LineString"?(a.addFeature(new L.Feature(h(new R.LineString(w.coordinates)))),v=!0):w.type==="MultiLineString"&&a.addFeature(new L.Feature(h(new R.MultiLineString(w.coordinates)))),v=!0}if(!v){if(p.geometry.type==="Polygon")kt(p,x);else if(p.geometry.type==="MultiPolygon")kt(p,x);else if(p.geometry.type==="LineString"){a.addFeature(new L.Feature(h(new R.LineString(p.geometry.coordinates))));break t}else if(p.geometry.type==="MultiLineString"){a.addFeature(new L.Feature(h(new R.MultiLineString(p.geometry.coordinates))));break t}}if(!d&&p.geometry.type!=="Point")break t;a.addFeature(new L.Feature(h(new R.Point(p.center))))}for(const v of y??[]){if(v===p)continue;const m=new L.Feature(new R.Point($.fromLonLat(v.center,s())));m.setId(v.id),m.setProperties({fuzzy:!!v.matching_text,tooltip:v.place_type[0]==="reverse"?v.place_name:v.place_name.replace(/,.*/,"")}),a.addFeature(m)}},setSelectedMarker(y){var x,v,m;const p=a.getFeatures(),d=(x=p[0])!=null&&x.getProperties().isReverse?1:0;r>-1&&((v=p[r+d])==null||v.setProperties({isSelected:!1})),y>-1&&((m=p[y+d])==null||m.setProperties({isSelected:!0})),r=y},getCenterAndZoom(){const y=o.getView(),p=y.getCenter(),d=y.getZoom();if(!(!p||d===void 0))return[d,...$.toLonLat(p,s())]}}}S.createOpenLayersMapController=xe,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
1
+ (function(D,V){typeof exports=="object"&&typeof module<"u"?V(exports,require("ol"),require("ol/geom"),require("ol/layer/Vector"),require("ol/proj"),require("ol/source/Vector"),require("ol/style/Fill"),require("ol/style/Icon"),require("ol/style/Stroke"),require("ol/style/Style"),require("ol/style/Text")):typeof define=="function"&&define.amd?define(["exports","ol","ol/geom","ol/layer/Vector","ol/proj","ol/source/Vector","ol/style/Fill","ol/style/Icon","ol/style/Stroke","ol/style/Style","ol/style/Text"],V):(D=typeof globalThis<"u"?globalThis:D||self,V(D.openlayersMaptilerGeocodingController={},D.ol,D.ol.geom,D.ol.layer.Vector,D.ol.proj,D.ol.source.Vector,D.ol.style.Fill,D.ol.style.Icon,D.ol.style.Stroke,D.ol.style.Style,D.ol.style.Text))})(this,function(D,V,K,lt,he,ut,Fe,ft,De,ht,ct){"use strict";var zt=Object.defineProperty;var Ut=(D,V,K)=>V in D?zt(D,V,{enumerable:!0,configurable:!0,writable:!0,value:K}):D[V]=K;var M=(D,V,K)=>Ut(D,typeof V!="symbol"?V+"":V,K);var rt,st;function xe(i,t,e={}){const n={type:"Feature"};return(e.id===0||e.id)&&(n.id=e.id),e.bbox&&(n.bbox=e.bbox),n.properties=t||{},n.geometry=i,n}function Re(i,t,e={}){for(const r of i){if(r.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(r[r.length-1].length!==r[0].length)throw new Error("First and last Position are not equivalent.");for(let f=0;f<r[r.length-1].length;f++)if(r[r.length-1][f]!==r[0][f])throw new Error("First and last Position are not equivalent.")}return xe({type:"Polygon",coordinates:i},t,e)}function Oe(i,t={}){const e={type:"FeatureCollection"};return t.id&&(e.id=t.id),t.bbox&&(e.bbox=t.bbox),e.features=i,e}function ze(i,t,e={}){return xe({type:"MultiPolygon",coordinates:i},t,e)}function Ue(i,t,e){if(i!==null)for(var n,r,f,a,c,E,m,L=0,T=0,b,N=i.type,O=N==="FeatureCollection",P=N==="Feature",A=O?i.features.length:1,X=0;X<A;X++){m=O?i.features[X].geometry:P?i.geometry:i,b=m?m.type==="GeometryCollection":!1,c=b?m.geometries.length:1;for(var S=0;S<c;S++){var q=0,B=0;if(a=b?m.geometries[S]:m,a!==null){E=a.coordinates;var J=a.type;switch(L=0,J){case null:break;case"Point":if(t(E,T,X,q,B)===!1)return!1;T++,q++;break;case"LineString":case"MultiPoint":for(n=0;n<E.length;n++){if(t(E[n],T,X,q,B)===!1)return!1;T++,J==="MultiPoint"&&q++}J==="LineString"&&q++;break;case"Polygon":case"MultiLineString":for(n=0;n<E.length;n++){for(r=0;r<E[n].length-L;r++){if(t(E[n][r],T,X,q,B)===!1)return!1;T++}J==="MultiLineString"&&q++,J==="Polygon"&&B++}J==="Polygon"&&q++;break;case"MultiPolygon":for(n=0;n<E.length;n++){for(B=0,r=0;r<E[n].length;r++){for(f=0;f<E[n][r].length-L;f++){if(t(E[n][r][f],T,X,q,B)===!1)return!1;T++}B++}q++}break;case"GeometryCollection":for(n=0;n<a.geometries.length;n++)if(Ue(a.geometries[n],t)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function _e(i,t){var e,n,r,f,a,c,E,m,L,T,b=0,N=i.type==="FeatureCollection",O=i.type==="Feature",P=N?i.features.length:1;for(e=0;e<P;e++){for(c=N?i.features[e].geometry:O?i.geometry:i,m=N?i.features[e].properties:O?i.properties:{},L=N?i.features[e].bbox:O?i.bbox:void 0,T=N?i.features[e].id:O?i.id:void 0,E=c?c.type==="GeometryCollection":!1,a=E?c.geometries.length:1,r=0;r<a;r++){if(f=E?c.geometries[r]:c,f===null){if(t(null,b,m,L,T)===!1)return!1;continue}switch(f.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(t(f,b,m,L,T)===!1)return!1;break}case"GeometryCollection":{for(n=0;n<f.geometries.length;n++)if(t(f.geometries[n],b,m,L,T)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}b++}}function at(i,t){_e(i,function(e,n,r,f,a){var c=e===null?null:e.type;switch(c){case null:case"Point":case"LineString":case"Polygon":return t(xe(e,r,{bbox:f,id:a}),n,0)===!1?!1:void 0}var E;switch(c){case"MultiPoint":E="Point";break;case"MultiLineString":E="LineString";break;case"MultiPolygon":E="Polygon";break}for(var m=0;m<e.coordinates.length;m++){var L=e.coordinates[m],T={type:E,coordinates:L};if(t(xe(T,r),n,m)===!1)return!1}})}function pt(i,t={}){if(i.bbox!=null&&t.recompute!==!0)return i.bbox;const e=[1/0,1/0,-1/0,-1/0];return Ue(i,n=>{e[0]>n[0]&&(e[0]=n[0]),e[1]>n[1]&&(e[1]=n[1]),e[2]<n[0]&&(e[2]=n[0]),e[3]<n[1]&&(e[3]=n[1])}),e}var Ve=pt,gt=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Ce=Math.ceil,Q=Math.floor,Z="[BigNumber Error] ",$e=Z+"Number primitive has more than 15 significant digits: ",ne=1e14,C=14,Ke=9007199254740991,Ne=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],ce=1e7,H=1e9;function Xe(i){var t,e,n,r=S.prototype={constructor:S,toString:null,valueOf:null},f=new S(1),a=20,c=4,E=-7,m=21,L=-1e7,T=1e7,b=!1,N=1,O=0,P={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},A="0123456789abcdefghijklmnopqrstuvwxyz",X=!0;function S(s,o){var l,d,h,g,w,u,p,x,y=this;if(!(y instanceof S))return new S(s,o);if(o==null){if(s&&s._isBigNumber===!0){y.s=s.s,!s.c||s.e>T?y.c=y.e=null:s.e<L?y.c=[y.e=0]:(y.e=s.e,y.c=s.c.slice());return}if((u=typeof s=="number")&&s*0==0){if(y.s=1/s<0?(s=-s,-1):1,s===~~s){for(g=0,w=s;w>=10;w/=10,g++);g>T?y.c=y.e=null:(y.e=g,y.c=[s]);return}x=String(s)}else{if(!gt.test(x=String(s)))return n(y,x,u);y.s=x.charCodeAt(0)==45?(x=x.slice(1),-1):1}(g=x.indexOf("."))>-1&&(x=x.replace(".","")),(w=x.search(/e/i))>0?(g<0&&(g=w),g+=+x.slice(w+1),x=x.substring(0,w)):g<0&&(g=x.length)}else{if(F(o,2,A.length,"Base"),o==10&&X)return y=new S(s),te(y,a+y.e+1,c);if(x=String(s),u=typeof s=="number"){if(s*0!=0)return n(y,x,u,o);if(y.s=1/s<0?(x=x.slice(1),-1):1,S.DEBUG&&x.replace(/^0\.0*|\./,"").length>15)throw Error($e+s)}else y.s=x.charCodeAt(0)===45?(x=x.slice(1),-1):1;for(l=A.slice(0,o),g=w=0,p=x.length;w<p;w++)if(l.indexOf(d=x.charAt(w))<0){if(d=="."){if(w>g){g=p;continue}}else if(!h&&(x==x.toUpperCase()&&(x=x.toLowerCase())||x==x.toLowerCase()&&(x=x.toUpperCase()))){h=!0,w=-1,g=0;continue}return n(y,String(s),u,o)}u=!1,x=e(x,o,10,y.s),(g=x.indexOf("."))>-1?x=x.replace(".",""):g=x.length}for(w=0;x.charCodeAt(w)===48;w++);for(p=x.length;x.charCodeAt(--p)===48;);if(x=x.slice(w,++p)){if(p-=w,u&&S.DEBUG&&p>15&&(s>Ke||s!==Q(s)))throw Error($e+y.s*s);if((g=g-w-1)>T)y.c=y.e=null;else if(g<L)y.c=[y.e=0];else{if(y.e=g,y.c=[],w=(g+1)%C,g<0&&(w+=C),w<p){for(w&&y.c.push(+x.slice(0,w)),p-=C;w<p;)y.c.push(+x.slice(w,w+=C));w=C-(x=x.slice(w)).length}else w-=p;for(;w--;x+="0");y.c.push(+x)}}else y.c=[y.e=0]}S.clone=Xe,S.ROUND_UP=0,S.ROUND_DOWN=1,S.ROUND_CEIL=2,S.ROUND_FLOOR=3,S.ROUND_HALF_UP=4,S.ROUND_HALF_DOWN=5,S.ROUND_HALF_EVEN=6,S.ROUND_HALF_CEIL=7,S.ROUND_HALF_FLOOR=8,S.EUCLID=9,S.config=S.set=function(s){var o,l;if(s!=null)if(typeof s=="object"){if(s.hasOwnProperty(o="DECIMAL_PLACES")&&(l=s[o],F(l,0,H,o),a=l),s.hasOwnProperty(o="ROUNDING_MODE")&&(l=s[o],F(l,0,8,o),c=l),s.hasOwnProperty(o="EXPONENTIAL_AT")&&(l=s[o],l&&l.pop?(F(l[0],-1e9,0,o),F(l[1],0,H,o),E=l[0],m=l[1]):(F(l,-1e9,H,o),E=-(m=l<0?-l:l))),s.hasOwnProperty(o="RANGE"))if(l=s[o],l&&l.pop)F(l[0],-1e9,-1,o),F(l[1],1,H,o),L=l[0],T=l[1];else if(F(l,-1e9,H,o),l)L=-(T=l<0?-l:l);else throw Error(Z+o+" cannot be zero: "+l);if(s.hasOwnProperty(o="CRYPTO"))if(l=s[o],l===!!l)if(l)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))b=l;else throw b=!l,Error(Z+"crypto unavailable");else b=l;else throw Error(Z+o+" not true or false: "+l);if(s.hasOwnProperty(o="MODULO_MODE")&&(l=s[o],F(l,0,9,o),N=l),s.hasOwnProperty(o="POW_PRECISION")&&(l=s[o],F(l,0,H,o),O=l),s.hasOwnProperty(o="FORMAT"))if(l=s[o],typeof l=="object")P=l;else throw Error(Z+o+" not an object: "+l);if(s.hasOwnProperty(o="ALPHABET"))if(l=s[o],typeof l=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(l))X=l.slice(0,10)=="0123456789",A=l;else throw Error(Z+o+" invalid: "+l)}else throw Error(Z+"Object expected: "+s);return{DECIMAL_PLACES:a,ROUNDING_MODE:c,EXPONENTIAL_AT:[E,m],RANGE:[L,T],CRYPTO:b,MODULO_MODE:N,POW_PRECISION:O,FORMAT:P,ALPHABET:A}},S.isBigNumber=function(s){if(!s||s._isBigNumber!==!0)return!1;if(!S.DEBUG)return!0;var o,l,d=s.c,h=s.e,g=s.s;e:if({}.toString.call(d)=="[object Array]"){if((g===1||g===-1)&&h>=-1e9&&h<=H&&h===Q(h)){if(d[0]===0){if(h===0&&d.length===1)return!0;break e}if(o=(h+1)%C,o<1&&(o+=C),String(d[0]).length==o){for(o=0;o<d.length;o++)if(l=d[o],l<0||l>=ne||l!==Q(l))break e;if(l!==0)return!0}}}else if(d===null&&h===null&&(g===null||g===1||g===-1))return!0;throw Error(Z+"Invalid BigNumber: "+s)},S.maximum=S.max=function(){return B(arguments,-1)},S.minimum=S.min=function(){return B(arguments,1)},S.random=function(){var s=9007199254740992,o=Math.random()*s&2097151?function(){return Q(Math.random()*s)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(l){var d,h,g,w,u,p=0,x=[],y=new S(f);if(l==null?l=a:F(l,0,H),w=Ce(l/C),b)if(crypto.getRandomValues){for(d=crypto.getRandomValues(new Uint32Array(w*=2));p<w;)u=d[p]*131072+(d[p+1]>>>11),u>=9e15?(h=crypto.getRandomValues(new Uint32Array(2)),d[p]=h[0],d[p+1]=h[1]):(x.push(u%1e14),p+=2);p=w/2}else if(crypto.randomBytes){for(d=crypto.randomBytes(w*=7);p<w;)u=(d[p]&31)*281474976710656+d[p+1]*1099511627776+d[p+2]*4294967296+d[p+3]*16777216+(d[p+4]<<16)+(d[p+5]<<8)+d[p+6],u>=9e15?crypto.randomBytes(7).copy(d,p):(x.push(u%1e14),p+=7);p=w/7}else throw b=!1,Error(Z+"crypto unavailable");if(!b)for(;p<w;)u=o(),u<9e15&&(x[p++]=u%1e14);for(w=x[--p],l%=C,w&&l&&(u=Ne[C-l],x[p]=Q(w/u)*u);x[p]===0;x.pop(),p--);if(p<0)x=[g=0];else{for(g=-1;x[0]===0;x.splice(0,1),g-=C);for(p=1,u=x[0];u>=10;u/=10,p++);p<C&&(g-=C-p)}return y.e=g,y.c=x,y}}(),S.sum=function(){for(var s=1,o=arguments,l=new S(o[0]);s<o.length;)l=l.plus(o[s++]);return l},e=function(){var s="0123456789";function o(l,d,h,g){for(var w,u=[0],p,x=0,y=l.length;x<y;){for(p=u.length;p--;u[p]*=d);for(u[0]+=g.indexOf(l.charAt(x++)),w=0;w<u.length;w++)u[w]>h-1&&(u[w+1]==null&&(u[w+1]=0),u[w+1]+=u[w]/h|0,u[w]%=h)}return u.reverse()}return function(l,d,h,g,w){var u,p,x,y,v,R,_,k,z=l.indexOf("."),$=a,I=c;for(z>=0&&(y=O,O=0,l=l.replace(".",""),k=new S(d),R=k.pow(l.length-z),O=y,k.c=o(le(ee(R.c),R.e,"0"),10,h,s),k.e=k.c.length),_=o(l,d,h,w?(u=A,s):(u=s,A)),x=y=_.length;_[--y]==0;_.pop());if(!_[0])return u.charAt(0);if(z<0?--x:(R.c=_,R.e=x,R.s=g,R=t(R,k,$,I,h),_=R.c,v=R.r,x=R.e),p=x+$+1,z=_[p],y=h/2,v=v||p<0||_[p+1]!=null,v=I<4?(z!=null||v)&&(I==0||I==(R.s<0?3:2)):z>y||z==y&&(I==4||v||I==6&&_[p-1]&1||I==(R.s<0?8:7)),p<1||!_[0])l=v?le(u.charAt(1),-$,u.charAt(0)):u.charAt(0);else{if(_.length=p,v)for(--h;++_[--p]>h;)_[p]=0,p||(++x,_=[1].concat(_));for(y=_.length;!_[--y];);for(z=0,l="";z<=y;l+=u.charAt(_[z++]));l=le(l,x,u.charAt(0))}return l}}(),t=function(){function s(d,h,g){var w,u,p,x,y=0,v=d.length,R=h%ce,_=h/ce|0;for(d=d.slice();v--;)p=d[v]%ce,x=d[v]/ce|0,w=_*p+x*R,u=R*p+w%ce*ce+y,y=(u/g|0)+(w/ce|0)+_*x,d[v]=u%g;return y&&(d=[y].concat(d)),d}function o(d,h,g,w){var u,p;if(g!=w)p=g>w?1:-1;else for(u=p=0;u<g;u++)if(d[u]!=h[u]){p=d[u]>h[u]?1:-1;break}return p}function l(d,h,g,w){for(var u=0;g--;)d[g]-=u,u=d[g]<h[g]?1:0,d[g]=u*w+d[g]-h[g];for(;!d[0]&&d.length>1;d.splice(0,1));}return function(d,h,g,w,u){var p,x,y,v,R,_,k,z,$,I,G,Y,Pe,Be,Ge,oe,de,ie=d.s==h.s?1:-1,W=d.c,U=h.c;if(!W||!W[0]||!U||!U[0])return new S(!d.s||!h.s||(W?U&&W[0]==U[0]:!U)?NaN:W&&W[0]==0||!U?ie*0:ie/0);for(z=new S(ie),$=z.c=[],x=d.e-h.e,ie=g+x+1,u||(u=ne,x=j(d.e/C)-j(h.e/C),ie=ie/C|0),y=0;U[y]==(W[y]||0);y++);if(U[y]>(W[y]||0)&&x--,ie<0)$.push(1),v=!0;else{for(Be=W.length,oe=U.length,y=0,ie+=2,R=Q(u/(U[0]+1)),R>1&&(U=s(U,R,u),W=s(W,R,u),oe=U.length,Be=W.length),Pe=oe,I=W.slice(0,oe),G=I.length;G<oe;I[G++]=0);de=U.slice(),de=[0].concat(de),Ge=U[0],U[1]>=u/2&&Ge++;do{if(R=0,p=o(U,I,oe,G),p<0){if(Y=I[0],oe!=G&&(Y=Y*u+(I[1]||0)),R=Q(Y/Ge),R>1)for(R>=u&&(R=u-1),_=s(U,R,u),k=_.length,G=I.length;o(_,I,k,G)==1;)R--,l(_,oe<k?de:U,k,u),k=_.length,p=1;else R==0&&(p=R=1),_=U.slice(),k=_.length;if(k<G&&(_=[0].concat(_)),l(I,_,G,u),G=I.length,p==-1)for(;o(U,I,oe,G)<1;)R++,l(I,oe<G?de:U,G,u),G=I.length}else p===0&&(R++,I=[0]);$[y++]=R,I[0]?I[G++]=W[Pe]||0:(I=[W[Pe]],G=1)}while((Pe++<Be||I[0]!=null)&&ie--);v=I[0]!=null,$[0]||$.splice(0,1)}if(u==ne){for(y=1,ie=$[0];ie>=10;ie/=10,y++);te(z,g+(z.e=y+x*C-1)+1,w,v)}else z.e=x,z.r=+v;return z}}();function q(s,o,l,d){var h,g,w,u,p;if(l==null?l=c:F(l,0,8),!s.c)return s.toString();if(h=s.c[0],w=s.e,o==null)p=ee(s.c),p=d==1||d==2&&(w<=E||w>=m)?Ee(p,w):le(p,w,"0");else if(s=te(new S(s),o,l),g=s.e,p=ee(s.c),u=p.length,d==1||d==2&&(o<=g||g<=E)){for(;u<o;p+="0",u++);p=Ee(p,g)}else if(o-=w,p=le(p,g,"0"),g+1>u){if(--o>0)for(p+=".";o--;p+="0");}else if(o+=g-u,o>0)for(g+1==u&&(p+=".");o--;p+="0");return s.s<0&&h?"-"+p:p}function B(s,o){for(var l,d,h=1,g=new S(s[0]);h<s.length;h++)d=new S(s[h]),(!d.s||(l=ae(g,d))===o||l===0&&g.s===o)&&(g=d);return g}function J(s,o,l){for(var d=1,h=o.length;!o[--h];o.pop());for(h=o[0];h>=10;h/=10,d++);return(l=d+l*C-1)>T?s.c=s.e=null:l<L?s.c=[s.e=0]:(s.e=l,s.c=o),s}n=function(){var s=/^(-?)0([xbo])(?=\w[\w.]*$)/i,o=/^([^.]+)\.$/,l=/^\.([^.]+)$/,d=/^-?(Infinity|NaN)$/,h=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(g,w,u,p){var x,y=u?w:w.replace(h,"");if(d.test(y))g.s=isNaN(y)?null:y<0?-1:1;else{if(!u&&(y=y.replace(s,function(v,R,_){return x=(_=_.toLowerCase())=="x"?16:_=="b"?2:8,!p||p==x?R:v}),p&&(x=p,y=y.replace(o,"$1").replace(l,"0.$1")),w!=y))return new S(y,x);if(S.DEBUG)throw Error(Z+"Not a"+(p?" base "+p:"")+" number: "+w);g.s=null}g.c=g.e=null}}();function te(s,o,l,d){var h,g,w,u,p,x,y,v=s.c,R=Ne;if(v){e:{for(h=1,u=v[0];u>=10;u/=10,h++);if(g=o-h,g<0)g+=C,w=o,p=v[x=0],y=Q(p/R[h-w-1]%10);else if(x=Ce((g+1)/C),x>=v.length)if(d){for(;v.length<=x;v.push(0));p=y=0,h=1,g%=C,w=g-C+1}else break e;else{for(p=u=v[x],h=1;u>=10;u/=10,h++);g%=C,w=g-C+h,y=w<0?0:Q(p/R[h-w-1]%10)}if(d=d||o<0||v[x+1]!=null||(w<0?p:p%R[h-w-1]),d=l<4?(y||d)&&(l==0||l==(s.s<0?3:2)):y>5||y==5&&(l==4||d||l==6&&(g>0?w>0?p/R[h-w]:0:v[x-1])%10&1||l==(s.s<0?8:7)),o<1||!v[0])return v.length=0,d?(o-=s.e+1,v[0]=R[(C-o%C)%C],s.e=-o||0):v[0]=s.e=0,s;if(g==0?(v.length=x,u=1,x--):(v.length=x+1,u=R[C-g],v[x]=w>0?Q(p/R[h-w]%R[w])*u:0),d)for(;;)if(x==0){for(g=1,w=v[0];w>=10;w/=10,g++);for(w=v[0]+=u,u=1;w>=10;w/=10,u++);g!=u&&(s.e++,v[0]==ne&&(v[0]=1));break}else{if(v[x]+=u,v[x]!=ne)break;v[x--]=0,u=1}for(g=v.length;v[--g]===0;v.pop());}s.e>T?s.c=s.e=null:s.e<L&&(s.c=[s.e=0])}return s}function fe(s){var o,l=s.e;return l===null?s.toString():(o=ee(s.c),o=l<=E||l>=m?Ee(o,l):le(o,l,"0"),s.s<0?"-"+o:o)}return r.absoluteValue=r.abs=function(){var s=new S(this);return s.s<0&&(s.s=1),s},r.comparedTo=function(s,o){return ae(this,new S(s,o))},r.decimalPlaces=r.dp=function(s,o){var l,d,h,g=this;if(s!=null)return F(s,0,H),o==null?o=c:F(o,0,8),te(new S(g),s+g.e+1,o);if(!(l=g.c))return null;if(d=((h=l.length-1)-j(this.e/C))*C,h=l[h])for(;h%10==0;h/=10,d--);return d<0&&(d=0),d},r.dividedBy=r.div=function(s,o){return t(this,new S(s,o),a,c)},r.dividedToIntegerBy=r.idiv=function(s,o){return t(this,new S(s,o),0,1)},r.exponentiatedBy=r.pow=function(s,o){var l,d,h,g,w,u,p,x,y,v=this;if(s=new S(s),s.c&&!s.isInteger())throw Error(Z+"Exponent not an integer: "+fe(s));if(o!=null&&(o=new S(o)),u=s.e>14,!v.c||!v.c[0]||v.c[0]==1&&!v.e&&v.c.length==1||!s.c||!s.c[0])return y=new S(Math.pow(+fe(v),u?s.s*(2-we(s)):+fe(s))),o?y.mod(o):y;if(p=s.s<0,o){if(o.c?!o.c[0]:!o.s)return new S(NaN);d=!p&&v.isInteger()&&o.isInteger(),d&&(v=v.mod(o))}else{if(s.e>9&&(v.e>0||v.e<-1||(v.e==0?v.c[0]>1||u&&v.c[1]>=24e7:v.c[0]<8e13||u&&v.c[0]<=9999975e7)))return g=v.s<0&&we(s)?-0:0,v.e>-1&&(g=1/g),new S(p?1/g:g);O&&(g=Ce(O/C+2))}for(u?(l=new S(.5),p&&(s.s=1),x=we(s)):(h=Math.abs(+fe(s)),x=h%2),y=new S(f);;){if(x){if(y=y.times(v),!y.c)break;g?y.c.length>g&&(y.c.length=g):d&&(y=y.mod(o))}if(h){if(h=Q(h/2),h===0)break;x=h%2}else if(s=s.times(l),te(s,s.e+1,1),s.e>14)x=we(s);else{if(h=+fe(s),h===0)break;x=h%2}v=v.times(v),g?v.c&&v.c.length>g&&(v.c.length=g):d&&(v=v.mod(o))}return d?y:(p&&(y=f.div(y)),o?y.mod(o):g?te(y,O,c,w):y)},r.integerValue=function(s){var o=new S(this);return s==null?s=c:F(s,0,8),te(o,o.e+1,s)},r.isEqualTo=r.eq=function(s,o){return ae(this,new S(s,o))===0},r.isFinite=function(){return!!this.c},r.isGreaterThan=r.gt=function(s,o){return ae(this,new S(s,o))>0},r.isGreaterThanOrEqualTo=r.gte=function(s,o){return(o=ae(this,new S(s,o)))===1||o===0},r.isInteger=function(){return!!this.c&&j(this.e/C)>this.c.length-2},r.isLessThan=r.lt=function(s,o){return ae(this,new S(s,o))<0},r.isLessThanOrEqualTo=r.lte=function(s,o){return(o=ae(this,new S(s,o)))===-1||o===0},r.isNaN=function(){return!this.s},r.isNegative=function(){return this.s<0},r.isPositive=function(){return this.s>0},r.isZero=function(){return!!this.c&&this.c[0]==0},r.minus=function(s,o){var l,d,h,g,w=this,u=w.s;if(s=new S(s,o),o=s.s,!u||!o)return new S(NaN);if(u!=o)return s.s=-o,w.plus(s);var p=w.e/C,x=s.e/C,y=w.c,v=s.c;if(!p||!x){if(!y||!v)return y?(s.s=-o,s):new S(v?w:NaN);if(!y[0]||!v[0])return v[0]?(s.s=-o,s):new S(y[0]?w:c==3?-0:0)}if(p=j(p),x=j(x),y=y.slice(),u=p-x){for((g=u<0)?(u=-u,h=y):(x=p,h=v),h.reverse(),o=u;o--;h.push(0));h.reverse()}else for(d=(g=(u=y.length)<(o=v.length))?u:o,u=o=0;o<d;o++)if(y[o]!=v[o]){g=y[o]<v[o];break}if(g&&(h=y,y=v,v=h,s.s=-s.s),o=(d=v.length)-(l=y.length),o>0)for(;o--;y[l++]=0);for(o=ne-1;d>u;){if(y[--d]<v[d]){for(l=d;l&&!y[--l];y[l]=o);--y[l],y[d]+=ne}y[d]-=v[d]}for(;y[0]==0;y.splice(0,1),--x);return y[0]?J(s,y,x):(s.s=c==3?-1:1,s.c=[s.e=0],s)},r.modulo=r.mod=function(s,o){var l,d,h=this;return s=new S(s,o),!h.c||!s.s||s.c&&!s.c[0]?new S(NaN):!s.c||h.c&&!h.c[0]?new S(h):(N==9?(d=s.s,s.s=1,l=t(h,s,0,3),s.s=d,l.s*=d):l=t(h,s,0,N),s=h.minus(l.times(s)),!s.c[0]&&N==1&&(s.s=h.s),s)},r.multipliedBy=r.times=function(s,o){var l,d,h,g,w,u,p,x,y,v,R,_,k,z,$,I=this,G=I.c,Y=(s=new S(s,o)).c;if(!G||!Y||!G[0]||!Y[0])return!I.s||!s.s||G&&!G[0]&&!Y||Y&&!Y[0]&&!G?s.c=s.e=s.s=null:(s.s*=I.s,!G||!Y?s.c=s.e=null:(s.c=[0],s.e=0)),s;for(d=j(I.e/C)+j(s.e/C),s.s*=I.s,p=G.length,v=Y.length,p<v&&(k=G,G=Y,Y=k,h=p,p=v,v=h),h=p+v,k=[];h--;k.push(0));for(z=ne,$=ce,h=v;--h>=0;){for(l=0,R=Y[h]%$,_=Y[h]/$|0,w=p,g=h+w;g>h;)x=G[--w]%$,y=G[w]/$|0,u=_*x+y*R,x=R*x+u%$*$+k[g]+l,l=(x/z|0)+(u/$|0)+_*y,k[g--]=x%z;k[g]=l}return l?++d:k.splice(0,1),J(s,k,d)},r.negated=function(){var s=new S(this);return s.s=-s.s||null,s},r.plus=function(s,o){var l,d=this,h=d.s;if(s=new S(s,o),o=s.s,!h||!o)return new S(NaN);if(h!=o)return s.s=-o,d.minus(s);var g=d.e/C,w=s.e/C,u=d.c,p=s.c;if(!g||!w){if(!u||!p)return new S(h/0);if(!u[0]||!p[0])return p[0]?s:new S(u[0]?d:h*0)}if(g=j(g),w=j(w),u=u.slice(),h=g-w){for(h>0?(w=g,l=p):(h=-h,l=u),l.reverse();h--;l.push(0));l.reverse()}for(h=u.length,o=p.length,h-o<0&&(l=p,p=u,u=l,o=h),h=0;o;)h=(u[--o]=u[o]+p[o]+h)/ne|0,u[o]=ne===u[o]?0:u[o]%ne;return h&&(u=[h].concat(u),++w),J(s,u,w)},r.precision=r.sd=function(s,o){var l,d,h,g=this;if(s!=null&&s!==!!s)return F(s,1,H),o==null?o=c:F(o,0,8),te(new S(g),s,o);if(!(l=g.c))return null;if(h=l.length-1,d=h*C+1,h=l[h]){for(;h%10==0;h/=10,d--);for(h=l[0];h>=10;h/=10,d++);}return s&&g.e+1>d&&(d=g.e+1),d},r.shiftedBy=function(s){return F(s,-9007199254740991,Ke),this.times("1e"+s)},r.squareRoot=r.sqrt=function(){var s,o,l,d,h,g=this,w=g.c,u=g.s,p=g.e,x=a+4,y=new S("0.5");if(u!==1||!w||!w[0])return new S(!u||u<0&&(!w||w[0])?NaN:w?g:1/0);if(u=Math.sqrt(+fe(g)),u==0||u==1/0?(o=ee(w),(o.length+p)%2==0&&(o+="0"),u=Math.sqrt(+o),p=j((p+1)/2)-(p<0||p%2),u==1/0?o="5e"+p:(o=u.toExponential(),o=o.slice(0,o.indexOf("e")+1)+p),l=new S(o)):l=new S(u+""),l.c[0]){for(p=l.e,u=p+x,u<3&&(u=0);;)if(h=l,l=y.times(h.plus(t(g,h,x,1))),ee(h.c).slice(0,u)===(o=ee(l.c)).slice(0,u))if(l.e<p&&--u,o=o.slice(u-3,u+1),o=="9999"||!d&&o=="4999"){if(!d&&(te(h,h.e+a+2,0),h.times(h).eq(g))){l=h;break}x+=4,u+=4,d=1}else{(!+o||!+o.slice(1)&&o.charAt(0)=="5")&&(te(l,l.e+a+2,1),s=!l.times(l).eq(g));break}}return te(l,l.e+a+1,c,s)},r.toExponential=function(s,o){return s!=null&&(F(s,0,H),s++),q(this,s,o,1)},r.toFixed=function(s,o){return s!=null&&(F(s,0,H),s=s+this.e+1),q(this,s,o)},r.toFormat=function(s,o,l){var d,h=this;if(l==null)s!=null&&o&&typeof o=="object"?(l=o,o=null):s&&typeof s=="object"?(l=s,s=o=null):l=P;else if(typeof l!="object")throw Error(Z+"Argument not an object: "+l);if(d=h.toFixed(s,o),h.c){var g,w=d.split("."),u=+l.groupSize,p=+l.secondaryGroupSize,x=l.groupSeparator||"",y=w[0],v=w[1],R=h.s<0,_=R?y.slice(1):y,k=_.length;if(p&&(g=u,u=p,p=g,k-=g),u>0&&k>0){for(g=k%u||u,y=_.substr(0,g);g<k;g+=u)y+=x+_.substr(g,u);p>0&&(y+=x+_.slice(g)),R&&(y="-"+y)}d=v?y+(l.decimalSeparator||"")+((p=+l.fractionGroupSize)?v.replace(new RegExp("\\d{"+p+"}\\B","g"),"$&"+(l.fractionGroupSeparator||"")):v):y}return(l.prefix||"")+d+(l.suffix||"")},r.toFraction=function(s){var o,l,d,h,g,w,u,p,x,y,v,R,_=this,k=_.c;if(s!=null&&(u=new S(s),!u.isInteger()&&(u.c||u.s!==1)||u.lt(f)))throw Error(Z+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+fe(u));if(!k)return new S(_);for(o=new S(f),x=l=new S(f),d=p=new S(f),R=ee(k),g=o.e=R.length-_.e-1,o.c[0]=Ne[(w=g%C)<0?C+w:w],s=!s||u.comparedTo(o)>0?g>0?o:x:u,w=T,T=1/0,u=new S(R),p.c[0]=0;y=t(u,o,0,1),h=l.plus(y.times(d)),h.comparedTo(s)!=1;)l=d,d=h,x=p.plus(y.times(h=x)),p=h,o=u.minus(y.times(h=o)),u=h;return h=t(s.minus(l),d,0,1),p=p.plus(h.times(x)),l=l.plus(h.times(d)),p.s=x.s=_.s,g=g*2,v=t(x,d,g,c).minus(_).abs().comparedTo(t(p,l,g,c).minus(_).abs())<1?[x,d]:[p,l],T=w,v},r.toNumber=function(){return+fe(this)},r.toPrecision=function(s,o){return s!=null&&F(s,1,H),q(this,s,o,2)},r.toString=function(s){var o,l=this,d=l.s,h=l.e;return h===null?d?(o="Infinity",d<0&&(o="-"+o)):o="NaN":(s==null?o=h<=E||h>=m?Ee(ee(l.c),h):le(ee(l.c),h,"0"):s===10&&X?(l=te(new S(l),a+h+1,c),o=le(ee(l.c),l.e,"0")):(F(s,2,A.length,"Base"),o=e(le(ee(l.c),h,"0"),10,s,d,!0)),d<0&&l.c[0]&&(o="-"+o)),o},r.valueOf=r.toJSON=function(){return fe(this)},r._isBigNumber=!0,r[Symbol.toStringTag]="BigNumber",r[Symbol.for("nodejs.util.inspect.custom")]=r.valueOf,i!=null&&S.set(i),S}function j(i){var t=i|0;return i>0||i===t?t:t-1}function ee(i){for(var t,e,n=1,r=i.length,f=i[0]+"";n<r;){for(t=i[n++]+"",e=C-t.length;e--;t="0"+t);f+=t}for(r=f.length;f.charCodeAt(--r)===48;);return f.slice(0,r+1||1)}function ae(i,t){var e,n,r=i.c,f=t.c,a=i.s,c=t.s,E=i.e,m=t.e;if(!a||!c)return null;if(e=r&&!r[0],n=f&&!f[0],e||n)return e?n?0:-c:a;if(a!=c)return a;if(e=a<0,n=E==m,!r||!f)return n?0:!r^e?1:-1;if(!n)return E>m^e?1:-1;for(c=(E=r.length)<(m=f.length)?E:m,a=0;a<c;a++)if(r[a]!=f[a])return r[a]>f[a]^e?1:-1;return E==m?0:E>m^e?1:-1}function F(i,t,e,n){if(i<t||i>e||i!==Q(i))throw Error(Z+(n||"Argument")+(typeof i=="number"?i<t||i>e?" out of range: ":" not an integer: ":" not a primitive number: ")+String(i))}function we(i){var t=i.c.length-1;return j(i.e/C)==t&&i.c[t]%2!=0}function Ee(i,t){return(i.length>1?i.charAt(0)+"."+i.slice(1):i)+(t<0?"e":"e+")+t}function le(i,t,e){var n,r;if(t<0){for(r=e+".";++t;r+=e);i=r+i}else if(n=i.length,++t>n){for(r=e,t-=n;--t;r+=e);i+=r}else t<n&&(i=i.slice(0,t)+"."+i.slice(t));return i}var re=Xe(),yt=class{constructor(i){M(this,"key");M(this,"left",null);M(this,"right",null);this.key=i}},pe=class extends yt{constructor(i){super(i)}},dt=class{constructor(){M(this,"size",0);M(this,"modificationCount",0);M(this,"splayCount",0)}splay(i){const t=this.root;if(t==null)return this.compare(i,i),-1;let e=null,n=null,r=null,f=null,a=t;const c=this.compare;let E;for(;;)if(E=c(a.key,i),E>0){let m=a.left;if(m==null||(E=c(m.key,i),E>0&&(a.left=m.right,m.right=a,a=m,m=a.left,m==null)))break;e==null?n=a:e.left=a,e=a,a=m}else if(E<0){let m=a.right;if(m==null||(E=c(m.key,i),E<0&&(a.right=m.left,m.left=a,a=m,m=a.right,m==null)))break;r==null?f=a:r.right=a,r=a,a=m}else break;return r!=null&&(r.right=a.left,a.left=f),e!=null&&(e.left=a.right,a.right=n),this.root!==a&&(this.root=a,this.splayCount++),E}splayMin(i){let t=i,e=t.left;for(;e!=null;){const n=e;t.left=n.right,n.right=t,t=n,e=t.left}return t}splayMax(i){let t=i,e=t.right;for(;e!=null;){const n=e;t.right=n.left,n.left=t,t=n,e=t.right}return t}_delete(i){if(this.root==null||this.splay(i)!=0)return null;let e=this.root;const n=e,r=e.left;if(this.size--,r==null)this.root=e.right;else{const f=e.right;e=this.splayMax(r),e.right=f,this.root=e}return this.modificationCount++,n}addNewRoot(i,t){this.size++,this.modificationCount++;const e=this.root;if(e==null){this.root=i;return}t<0?(i.left=e,i.right=e.right,e.right=null):(i.right=e,i.left=e.left,e.left=null),this.root=i}_first(){const i=this.root;return i==null?null:(this.root=this.splayMin(i),this.root)}_last(){const i=this.root;return i==null?null:(this.root=this.splayMax(i),this.root)}clear(){this.root=null,this.size=0,this.modificationCount++}has(i){return this.validKey(i)&&this.splay(i)==0}defaultCompare(){return(i,t)=>i<t?-1:i>t?1:0}wrap(){return{getRoot:()=>this.root,setRoot:i=>{this.root=i},getSize:()=>this.size,getModificationCount:()=>this.modificationCount,getSplayCount:()=>this.splayCount,setSplayCount:i=>{this.splayCount=i},splay:i=>this.splay(i),has:i=>this.has(i)}}},Se=class me extends dt{constructor(e,n){super();M(this,"root",null);M(this,"compare");M(this,"validKey");M(this,rt,"[object Set]");this.compare=e??this.defaultCompare(),this.validKey=n??(r=>r!=null&&r!=null)}delete(e){return this.validKey(e)?this._delete(e)!=null:!1}deleteAll(e){for(const n of e)this.delete(n)}forEach(e){const n=this[Symbol.iterator]();let r;for(;r=n.next(),!r.done;)e(r.value,r.value,this)}add(e){const n=this.splay(e);return n!=0&&this.addNewRoot(new pe(e),n),this}addAndReturn(e){const n=this.splay(e);return n!=0&&this.addNewRoot(new pe(e),n),this.root.key}addAll(e){for(const n of e)this.add(n)}isEmpty(){return this.root==null}isNotEmpty(){return this.root!=null}single(){if(this.size==0)throw"Bad state: No element";if(this.size>1)throw"Bad state: Too many element";return this.root.key}first(){if(this.size==0)throw"Bad state: No element";return this._first().key}last(){if(this.size==0)throw"Bad state: No element";return this._last().key}lastBefore(e){if(e==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(e)<0)return this.root.key;let r=this.root.left;if(r==null)return null;let f=r.right;for(;f!=null;)r=f,f=r.right;return r.key}firstAfter(e){if(e==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(e)>0)return this.root.key;let r=this.root.right;if(r==null)return null;let f=r.left;for(;f!=null;)r=f,f=r.left;return r.key}retainAll(e){const n=new me(this.compare,this.validKey),r=this.modificationCount;for(const f of e){if(r!=this.modificationCount)throw"Concurrent modification during iteration.";this.validKey(f)&&this.splay(f)==0&&n.add(this.root.key)}n.size!=this.size&&(this.root=n.root,this.size=n.size,this.modificationCount++)}lookup(e){return!this.validKey(e)||this.splay(e)!=0?null:this.root.key}intersection(e){const n=new me(this.compare,this.validKey);for(const r of this)e.has(r)&&n.add(r);return n}difference(e){const n=new me(this.compare,this.validKey);for(const r of this)e.has(r)||n.add(r);return n}union(e){const n=this.clone();return n.addAll(e),n}clone(){const e=new me(this.compare,this.validKey);return e.size=this.size,e.root=this.copyNode(this.root),e}copyNode(e){if(e==null)return null;function n(f,a){let c,E;do{if(c=f.left,E=f.right,c!=null){const m=new pe(c.key);a.left=m,n(c,m)}if(E!=null){const m=new pe(E.key);a.right=m,f=E,a=m}}while(E!=null)}const r=new pe(e.key);return n(e,r),r}toSet(){return this.clone()}entries(){return new xt(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[(st=Symbol.iterator,rt=Symbol.toStringTag,st)](){return new mt(this.wrap())}},Ye=class{constructor(i){M(this,"tree");M(this,"path",new Array);M(this,"modificationCount",null);M(this,"splayCount");this.tree=i,this.splayCount=i.getSplayCount()}[Symbol.iterator](){return this}next(){return this.moveNext()?{done:!1,value:this.current()}:{done:!0,value:null}}current(){if(!this.path.length)return null;const i=this.path[this.path.length-1];return this.getValue(i)}rebuildPath(i){this.path.splice(0,this.path.length),this.tree.splay(i),this.path.push(this.tree.getRoot()),this.splayCount=this.tree.getSplayCount()}findLeftMostDescendent(i){for(;i!=null;)this.path.push(i),i=i.left}moveNext(){if(this.modificationCount!=this.tree.getModificationCount()){if(this.modificationCount==null){this.modificationCount=this.tree.getModificationCount();let e=this.tree.getRoot();for(;e!=null;)this.path.push(e),e=e.left;return this.path.length>0}throw"Concurrent modification during iteration."}if(!this.path.length)return!1;this.splayCount!=this.tree.getSplayCount()&&this.rebuildPath(this.path[this.path.length-1].key);let i=this.path[this.path.length-1],t=i.right;if(t!=null){for(;t!=null;)this.path.push(t),t=t.left;return!0}for(this.path.pop();this.path.length&&this.path[this.path.length-1].right===i;)i=this.path.pop();return this.path.length>0}},mt=class extends Ye{getValue(i){return i.key}},xt=class extends Ye{getValue(i){return[i.key,i.key]}},We=i=>()=>i,Ae=i=>{const t=i?(e,n)=>n.minus(e).abs().isLessThanOrEqualTo(i):We(!1);return(e,n)=>t(e,n)?0:e.comparedTo(n)};function wt(i){const t=i?(e,n,r,f,a)=>e.exponentiatedBy(2).isLessThanOrEqualTo(f.minus(n).exponentiatedBy(2).plus(a.minus(r).exponentiatedBy(2)).times(i)):We(!1);return(e,n,r)=>{const f=e.x,a=e.y,c=r.x,E=r.y,m=a.minus(E).times(n.x.minus(c)).minus(f.minus(c).times(n.y.minus(E)));return t(m,f,a,c,E)?0:m.comparedTo(0)}}var Et=i=>i,St=i=>{if(i){const t=new Se(Ae(i)),e=new Se(Ae(i)),n=(f,a)=>a.addAndReturn(f),r=f=>({x:n(f.x,t),y:n(f.y,e)});return r({x:new re(0),y:new re(0)}),r}return Et},Ie=i=>({set:t=>{ue=Ie(t)},reset:()=>Ie(i),compare:Ae(i),snap:St(i),orient:wt(i)}),ue=Ie(),ge=(i,t)=>i.ll.x.isLessThanOrEqualTo(t.x)&&t.x.isLessThanOrEqualTo(i.ur.x)&&i.ll.y.isLessThanOrEqualTo(t.y)&&t.y.isLessThanOrEqualTo(i.ur.y),ke=(i,t)=>{if(t.ur.x.isLessThan(i.ll.x)||i.ur.x.isLessThan(t.ll.x)||t.ur.y.isLessThan(i.ll.y)||i.ur.y.isLessThan(t.ll.y))return null;const e=i.ll.x.isLessThan(t.ll.x)?t.ll.x:i.ll.x,n=i.ur.x.isLessThan(t.ur.x)?i.ur.x:t.ur.x,r=i.ll.y.isLessThan(t.ll.y)?t.ll.y:i.ll.y,f=i.ur.y.isLessThan(t.ur.y)?i.ur.y:t.ur.y;return{ll:{x:e,y:r},ur:{x:n,y:f}}},ve=(i,t)=>i.x.times(t.y).minus(i.y.times(t.x)),Ze=(i,t)=>i.x.times(t.x).plus(i.y.times(t.y)),Te=i=>Ze(i,i).sqrt(),vt=(i,t,e)=>{const n={x:t.x.minus(i.x),y:t.y.minus(i.y)},r={x:e.x.minus(i.x),y:e.y.minus(i.y)};return ve(r,n).div(Te(r)).div(Te(n))},Tt=(i,t,e)=>{const n={x:t.x.minus(i.x),y:t.y.minus(i.y)},r={x:e.x.minus(i.x),y:e.y.minus(i.y)};return Ze(r,n).div(Te(r)).div(Te(n))},He=(i,t,e)=>t.y.isZero()?null:{x:i.x.plus(t.x.div(t.y).times(e.minus(i.y))),y:e},Je=(i,t,e)=>t.x.isZero()?null:{x:e,y:i.y.plus(t.y.div(t.x).times(e.minus(i.x)))},Lt=(i,t,e,n)=>{if(t.x.isZero())return Je(e,n,i.x);if(n.x.isZero())return Je(i,t,e.x);if(t.y.isZero())return He(e,n,i.y);if(n.y.isZero())return He(i,t,e.y);const r=ve(t,n);if(r.isZero())return null;const f={x:e.x.minus(i.x),y:e.y.minus(i.y)},a=ve(f,t).div(r),c=ve(f,n).div(r),E=i.x.plus(c.times(t.x)),m=e.x.plus(a.times(n.x)),L=i.y.plus(c.times(t.y)),T=e.y.plus(a.times(n.y)),b=E.plus(m).div(2),N=L.plus(T).div(2);return{x:b,y:N}},se=class ot{constructor(t,e){M(this,"point");M(this,"isLeft");M(this,"segment");M(this,"otherSE");M(this,"consumedBy");t.events===void 0?t.events=[this]:t.events.push(this),this.point=t,this.isLeft=e}static compare(t,e){const n=ot.comparePoints(t.point,e.point);return n!==0?n:(t.point!==e.point&&t.link(e),t.isLeft!==e.isLeft?t.isLeft?1:-1:be.compare(t.segment,e.segment))}static comparePoints(t,e){return t.x.isLessThan(e.x)?-1:t.x.isGreaterThan(e.x)?1:t.y.isLessThan(e.y)?-1:t.y.isGreaterThan(e.y)?1:0}link(t){if(t.point===this.point)throw new Error("Tried to link already linked events");const e=t.point.events;for(let n=0,r=e.length;n<r;n++){const f=e[n];this.point.events.push(f),f.point=this.point}this.checkForConsuming()}checkForConsuming(){const t=this.point.events.length;for(let e=0;e<t;e++){const n=this.point.events[e];if(n.segment.consumedBy===void 0)for(let r=e+1;r<t;r++){const f=this.point.events[r];f.consumedBy===void 0&&n.otherSE.point.events===f.otherSE.point.events&&n.segment.consume(f.segment)}}}getAvailableLinkedEvents(){const t=[];for(let e=0,n=this.point.events.length;e<n;e++){const r=this.point.events[e];r!==this&&!r.segment.ringOut&&r.segment.isInResult()&&t.push(r)}return t}getLeftmostComparator(t){const e=new Map,n=r=>{const f=r.otherSE;e.set(r,{sine:vt(this.point,t.point,f.point),cosine:Tt(this.point,t.point,f.point)})};return(r,f)=>{e.has(r)||n(r),e.has(f)||n(f);const{sine:a,cosine:c}=e.get(r),{sine:E,cosine:m}=e.get(f);return a.isGreaterThanOrEqualTo(0)&&E.isGreaterThanOrEqualTo(0)?c.isLessThan(m)?1:c.isGreaterThan(m)?-1:0:a.isLessThan(0)&&E.isLessThan(0)?c.isLessThan(m)?-1:c.isGreaterThan(m)?1:0:E.isLessThan(a)?-1:E.isGreaterThan(a)?1:0}}},bt=class qe{constructor(t){M(this,"events");M(this,"poly");M(this,"_isExteriorRing");M(this,"_enclosingRing");this.events=t;for(let e=0,n=t.length;e<n;e++)t[e].segment.ringOut=this;this.poly=null}static factory(t){const e=[];for(let n=0,r=t.length;n<r;n++){const f=t[n];if(!f.isInResult()||f.ringOut)continue;let a=null,c=f.leftSE,E=f.rightSE;const m=[c],L=c.point,T=[];for(;a=c,c=E,m.push(c),c.point!==L;)for(;;){const b=c.getAvailableLinkedEvents();if(b.length===0){const P=m[0].point,A=m[m.length-1].point;throw new Error(`Unable to complete output ring starting at [${P.x}, ${P.y}]. Last matching segment found ends at [${A.x}, ${A.y}].`)}if(b.length===1){E=b[0].otherSE;break}let N=null;for(let P=0,A=T.length;P<A;P++)if(T[P].point===c.point){N=P;break}if(N!==null){const P=T.splice(N)[0],A=m.splice(P.index);A.unshift(A[0].otherSE),e.push(new qe(A.reverse()));continue}T.push({index:m.length,point:c.point});const O=c.getLeftmostComparator(a);E=b.sort(O)[0].otherSE;break}e.push(new qe(m))}return e}getGeom(){let t=this.events[0].point;const e=[t];for(let m=1,L=this.events.length-1;m<L;m++){const T=this.events[m].point,b=this.events[m+1].point;ue.orient(T,t,b)!==0&&(e.push(T),t=T)}if(e.length===1)return null;const n=e[0],r=e[1];ue.orient(n,t,r)===0&&e.shift(),e.push(e[0]);const f=this.isExteriorRing()?1:-1,a=this.isExteriorRing()?0:e.length-1,c=this.isExteriorRing()?e.length:-1,E=[];for(let m=a;m!=c;m+=f)E.push([e[m].x.toNumber(),e[m].y.toNumber()]);return E}isExteriorRing(){if(this._isExteriorRing===void 0){const t=this.enclosingRing();this._isExteriorRing=t?!t.isExteriorRing():!0}return this._isExteriorRing}enclosingRing(){return this._enclosingRing===void 0&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){var r,f;let t=this.events[0];for(let a=1,c=this.events.length;a<c;a++){const E=this.events[a];se.compare(t,E)>0&&(t=E)}let e=t.segment.prevInResult(),n=e?e.prevInResult():null;for(;;){if(!e)return null;if(!n)return e.ringOut;if(n.ringOut!==e.ringOut)return((r=n.ringOut)==null?void 0:r.enclosingRing())!==e.ringOut?e.ringOut:(f=e.ringOut)==null?void 0:f.enclosingRing();e=n.prevInResult(),n=e?e.prevInResult():null}}},Qe=class{constructor(i){M(this,"exteriorRing");M(this,"interiorRings");this.exteriorRing=i,i.poly=this,this.interiorRings=[]}addInterior(i){this.interiorRings.push(i),i.poly=this}getGeom(){const i=this.exteriorRing.getGeom();if(i===null)return null;const t=[i];for(let e=0,n=this.interiorRings.length;e<n;e++){const r=this.interiorRings[e].getGeom();r!==null&&t.push(r)}return t}},Pt=class{constructor(i){M(this,"rings");M(this,"polys");this.rings=i,this.polys=this._composePolys(i)}getGeom(){const i=[];for(let t=0,e=this.polys.length;t<e;t++){const n=this.polys[t].getGeom();n!==null&&i.push(n)}return i}_composePolys(i){var e;const t=[];for(let n=0,r=i.length;n<r;n++){const f=i[n];if(!f.poly)if(f.isExteriorRing())t.push(new Qe(f));else{const a=f.enclosingRing();a!=null&&a.poly||t.push(new Qe(a)),(e=a==null?void 0:a.poly)==null||e.addInterior(f)}}return t}},Mt=class{constructor(i,t=be.compare){M(this,"queue");M(this,"tree");M(this,"segments");this.queue=i,this.tree=new Se(t),this.segments=[]}process(i){const t=i.segment,e=[];if(i.consumedBy)return i.isLeft?this.queue.delete(i.otherSE):this.tree.delete(t),e;i.isLeft&&this.tree.add(t);let n=t,r=t;do n=this.tree.lastBefore(n);while(n!=null&&n.consumedBy!=null);do r=this.tree.firstAfter(r);while(r!=null&&r.consumedBy!=null);if(i.isLeft){let f=null;if(n){const c=n.getIntersection(t);if(c!==null&&(t.isAnEndpoint(c)||(f=c),!n.isAnEndpoint(c))){const E=this._splitSafely(n,c);for(let m=0,L=E.length;m<L;m++)e.push(E[m])}}let a=null;if(r){const c=r.getIntersection(t);if(c!==null&&(t.isAnEndpoint(c)||(a=c),!r.isAnEndpoint(c))){const E=this._splitSafely(r,c);for(let m=0,L=E.length;m<L;m++)e.push(E[m])}}if(f!==null||a!==null){let c=null;f===null?c=a:a===null?c=f:c=se.comparePoints(f,a)<=0?f:a,this.queue.delete(t.rightSE),e.push(t.rightSE);const E=t.split(c);for(let m=0,L=E.length;m<L;m++)e.push(E[m])}e.length>0?(this.tree.delete(t),e.push(i)):(this.segments.push(t),t.prev=n)}else{if(n&&r){const f=n.getIntersection(r);if(f!==null){if(!n.isAnEndpoint(f)){const a=this._splitSafely(n,f);for(let c=0,E=a.length;c<E;c++)e.push(a[c])}if(!r.isAnEndpoint(f)){const a=this._splitSafely(r,f);for(let c=0,E=a.length;c<E;c++)e.push(a[c])}}}this.tree.delete(t)}return e}_splitSafely(i,t){this.tree.delete(i);const e=i.rightSE;this.queue.delete(e);const n=i.split(t);return n.push(e),i.consumedBy===void 0&&this.tree.add(i),n}},Rt=class{constructor(){M(this,"type");M(this,"numMultiPolys")}run(i,t,e){ye.type=i;const n=[new et(t,!0)];for(let m=0,L=e.length;m<L;m++)n.push(new et(e[m],!1));if(ye.numMultiPolys=n.length,ye.type==="difference"){const m=n[0];let L=1;for(;L<n.length;)ke(n[L].bbox,m.bbox)!==null?L++:n.splice(L,1)}if(ye.type==="intersection")for(let m=0,L=n.length;m<L;m++){const T=n[m];for(let b=m+1,N=n.length;b<N;b++)if(ke(T.bbox,n[b].bbox)===null)return[]}const r=new Se(se.compare);for(let m=0,L=n.length;m<L;m++){const T=n[m].getSweepEvents();for(let b=0,N=T.length;b<N;b++)r.add(T[b])}const f=new Mt(r);let a=null;for(r.size!=0&&(a=r.first(),r.delete(a));a;){const m=f.process(a);for(let L=0,T=m.length;L<T;L++){const b=m[L];b.consumedBy===void 0&&r.add(b)}r.size!=0?(a=r.first(),r.delete(a)):a=null}ue.reset();const c=bt.factory(f.segments);return new Pt(c).getGeom()}},ye=new Rt,Le=ye,Ot=0,be=class Me{constructor(t,e,n,r){M(this,"id");M(this,"leftSE");M(this,"rightSE");M(this,"rings");M(this,"windings");M(this,"ringOut");M(this,"consumedBy");M(this,"prev");M(this,"_prevInResult");M(this,"_beforeState");M(this,"_afterState");M(this,"_isInResult");this.id=++Ot,this.leftSE=t,t.segment=this,t.otherSE=e,this.rightSE=e,e.segment=this,e.otherSE=t,this.rings=n,this.windings=r}static compare(t,e){const n=t.leftSE.point.x,r=e.leftSE.point.x,f=t.rightSE.point.x,a=e.rightSE.point.x;if(a.isLessThan(n))return 1;if(f.isLessThan(r))return-1;const c=t.leftSE.point.y,E=e.leftSE.point.y,m=t.rightSE.point.y,L=e.rightSE.point.y;if(n.isLessThan(r)){if(E.isLessThan(c)&&E.isLessThan(m))return 1;if(E.isGreaterThan(c)&&E.isGreaterThan(m))return-1;const T=t.comparePoint(e.leftSE.point);if(T<0)return 1;if(T>0)return-1;const b=e.comparePoint(t.rightSE.point);return b!==0?b:-1}if(n.isGreaterThan(r)){if(c.isLessThan(E)&&c.isLessThan(L))return-1;if(c.isGreaterThan(E)&&c.isGreaterThan(L))return 1;const T=e.comparePoint(t.leftSE.point);if(T!==0)return T;const b=t.comparePoint(e.rightSE.point);return b<0?1:b>0?-1:1}if(c.isLessThan(E))return-1;if(c.isGreaterThan(E))return 1;if(f.isLessThan(a)){const T=e.comparePoint(t.rightSE.point);if(T!==0)return T}if(f.isGreaterThan(a)){const T=t.comparePoint(e.rightSE.point);if(T<0)return 1;if(T>0)return-1}if(!f.eq(a)){const T=m.minus(c),b=f.minus(n),N=L.minus(E),O=a.minus(r);if(T.isGreaterThan(b)&&N.isLessThan(O))return 1;if(T.isLessThan(b)&&N.isGreaterThan(O))return-1}return f.isGreaterThan(a)?1:f.isLessThan(a)||m.isLessThan(L)?-1:m.isGreaterThan(L)?1:t.id<e.id?-1:t.id>e.id?1:0}static fromRing(t,e,n){let r,f,a;const c=se.comparePoints(t,e);if(c<0)r=t,f=e,a=1;else if(c>0)r=e,f=t,a=-1;else throw new Error(`Tried to create degenerate segment at [${t.x}, ${t.y}]`);const E=new se(r,!0),m=new se(f,!1);return new Me(E,m,[n],[a])}replaceRightSE(t){this.rightSE=t,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const t=this.leftSE.point.y,e=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:t.isLessThan(e)?t:e},ur:{x:this.rightSE.point.x,y:t.isGreaterThan(e)?t:e}}}vector(){return{x:this.rightSE.point.x.minus(this.leftSE.point.x),y:this.rightSE.point.y.minus(this.leftSE.point.y)}}isAnEndpoint(t){return t.x.eq(this.leftSE.point.x)&&t.y.eq(this.leftSE.point.y)||t.x.eq(this.rightSE.point.x)&&t.y.eq(this.rightSE.point.y)}comparePoint(t){return ue.orient(this.leftSE.point,t,this.rightSE.point)}getIntersection(t){const e=this.bbox(),n=t.bbox(),r=ke(e,n);if(r===null)return null;const f=this.leftSE.point,a=this.rightSE.point,c=t.leftSE.point,E=t.rightSE.point,m=ge(e,c)&&this.comparePoint(c)===0,L=ge(n,f)&&t.comparePoint(f)===0,T=ge(e,E)&&this.comparePoint(E)===0,b=ge(n,a)&&t.comparePoint(a)===0;if(L&&m)return b&&!T?a:!b&&T?E:null;if(L)return T&&f.x.eq(E.x)&&f.y.eq(E.y)?null:f;if(m)return b&&a.x.eq(c.x)&&a.y.eq(c.y)?null:c;if(b&&T)return null;if(b)return a;if(T)return E;const N=Lt(f,this.vector(),c,t.vector());return N===null||!ge(r,N)?null:ue.snap(N)}split(t){const e=[],n=t.events!==void 0,r=new se(t,!0),f=new se(t,!1),a=this.rightSE;this.replaceRightSE(f),e.push(f),e.push(r);const c=new Me(r,a,this.rings.slice(),this.windings.slice());return se.comparePoints(c.leftSE.point,c.rightSE.point)>0&&c.swapEvents(),se.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),n&&(r.checkForConsuming(),f.checkForConsuming()),e}swapEvents(){const t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let e=0,n=this.windings.length;e<n;e++)this.windings[e]*=-1}consume(t){let e=this,n=t;for(;e.consumedBy;)e=e.consumedBy;for(;n.consumedBy;)n=n.consumedBy;const r=Me.compare(e,n);if(r!==0){if(r>0){const f=e;e=n,n=f}if(e.prev===n){const f=e;e=n,n=f}for(let f=0,a=n.rings.length;f<a;f++){const c=n.rings[f],E=n.windings[f],m=e.rings.indexOf(c);m===-1?(e.rings.push(c),e.windings.push(E)):e.windings[m]+=E}n.rings=null,n.windings=null,n.consumedBy=e,n.leftSE.consumedBy=e.leftSE,n.rightSE.consumedBy=e.rightSE}}prevInResult(){return this._prevInResult!==void 0?this._prevInResult:(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null,this._prevInResult)}beforeState(){if(this._beforeState!==void 0)return this._beforeState;if(!this.prev)this._beforeState={rings:[],windings:[],multiPolys:[]};else{const t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}return this._beforeState}afterState(){if(this._afterState!==void 0)return this._afterState;const t=this.beforeState();this._afterState={rings:t.rings.slice(0),windings:t.windings.slice(0),multiPolys:[]};const e=this._afterState.rings,n=this._afterState.windings,r=this._afterState.multiPolys;for(let c=0,E=this.rings.length;c<E;c++){const m=this.rings[c],L=this.windings[c],T=e.indexOf(m);T===-1?(e.push(m),n.push(L)):n[T]+=L}const f=[],a=[];for(let c=0,E=e.length;c<E;c++){if(n[c]===0)continue;const m=e[c],L=m.poly;if(a.indexOf(L)===-1)if(m.isExterior)f.push(L);else{a.indexOf(L)===-1&&a.push(L);const T=f.indexOf(m.poly);T!==-1&&f.splice(T,1)}}for(let c=0,E=f.length;c<E;c++){const m=f[c].multiPoly;r.indexOf(m)===-1&&r.push(m)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(this._isInResult!==void 0)return this._isInResult;const t=this.beforeState().multiPolys,e=this.afterState().multiPolys;switch(Le.type){case"union":{const n=t.length===0,r=e.length===0;this._isInResult=n!==r;break}case"intersection":{let n,r;t.length<e.length?(n=t.length,r=e.length):(n=e.length,r=t.length),this._isInResult=r===Le.numMultiPolys&&n<r;break}case"xor":{const n=Math.abs(t.length-e.length);this._isInResult=n%2===1;break}case"difference":{const n=r=>r.length===1&&r[0].isSubject;this._isInResult=n(t)!==n(e);break}}return this._isInResult}},je=class{constructor(i,t,e){M(this,"poly");M(this,"isExterior");M(this,"segments");M(this,"bbox");if(!Array.isArray(i)||i.length===0)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=t,this.isExterior=e,this.segments=[],typeof i[0][0]!="number"||typeof i[0][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const n=ue.snap({x:new re(i[0][0]),y:new re(i[0][1])});this.bbox={ll:{x:n.x,y:n.y},ur:{x:n.x,y:n.y}};let r=n;for(let f=1,a=i.length;f<a;f++){if(typeof i[f][0]!="number"||typeof i[f][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const c=ue.snap({x:new re(i[f][0]),y:new re(i[f][1])});c.x.eq(r.x)&&c.y.eq(r.y)||(this.segments.push(be.fromRing(r,c,this)),c.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=c.x),c.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=c.y),c.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=c.x),c.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=c.y),r=c)}(!n.x.eq(r.x)||!n.y.eq(r.y))&&this.segments.push(be.fromRing(r,n,this))}getSweepEvents(){const i=[];for(let t=0,e=this.segments.length;t<e;t++){const n=this.segments[t];i.push(n.leftSE),i.push(n.rightSE)}return i}},_t=class{constructor(i,t){M(this,"multiPoly");M(this,"exteriorRing");M(this,"interiorRings");M(this,"bbox");if(!Array.isArray(i))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new je(i[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let e=1,n=i.length;e<n;e++){const r=new je(i[e],this,!1);r.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=r.bbox.ll.x),r.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=r.bbox.ll.y),r.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=r.bbox.ur.x),r.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=r.bbox.ur.y),this.interiorRings.push(r)}this.multiPoly=t}getSweepEvents(){const i=this.exteriorRing.getSweepEvents();for(let t=0,e=this.interiorRings.length;t<e;t++){const n=this.interiorRings[t].getSweepEvents();for(let r=0,f=n.length;r<f;r++)i.push(n[r])}return i}},et=class{constructor(i,t){M(this,"isSubject");M(this,"polys");M(this,"bbox");if(!Array.isArray(i))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{typeof i[0][0][0]=="number"&&(i=[i])}catch{}this.polys=[],this.bbox={ll:{x:new re(Number.POSITIVE_INFINITY),y:new re(Number.POSITIVE_INFINITY)},ur:{x:new re(Number.NEGATIVE_INFINITY),y:new re(Number.NEGATIVE_INFINITY)}};for(let e=0,n=i.length;e<n;e++){const r=new _t(i[e],this);r.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=r.bbox.ll.x),r.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=r.bbox.ll.y),r.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=r.bbox.ur.x),r.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=r.bbox.ur.y),this.polys.push(r)}this.isSubject=t}getSweepEvents(){const i=[];for(let t=0,e=this.polys.length;t<e;t++){const n=this.polys[t].getSweepEvents();for(let r=0,f=n.length;r<f;r++)i.push(n[r])}return i}},Ct=(i,...t)=>Le.run("union",i,t),Nt=(i,...t)=>Le.run("difference",i,t);ue.set;function At(i){const t=[];if(_e(i,r=>{t.push(r.coordinates)}),t.length<2)throw new Error("Must have at least two features");const e=i.features[0].properties||{},n=Nt(t[0],...t.slice(1));return n.length===0?null:n.length===1?Re(n[0],e):ze(n,e)}var It=At;function kt(i){if(!i)throw new Error("geojson is required");var t=[];return at(i,function(e){t.push(e)}),Oe(t)}var Bt=kt;function Gt(i,t={}){const e=[];if(_e(i,r=>{e.push(r.coordinates)}),e.length<2)throw new Error("Must have at least 2 geometries");const n=Ct(e[0],...e.slice(1));return n.length===0?null:n.length===1?Re(n[0],t.properties):ze(n,t.properties)}var qt=Gt;function tt(i){const t=[...i];return t[2]<t[0]&&(Math.abs((t[0]+t[2]+360)/2)>Math.abs((t[0]-360+t[2])/2)?t[0]-=360:t[2]+=360),t}function it(i,t){const e=It(Oe([Re([[[180,90],[-180,90],[-180,-90],[180,-90],[180,90]]]),i]));if(!e)return;e.properties={isMask:!0};const n=tt(Ve(i)),r=(n[2]-n[0])/360/1e3,f=n[0]<-180,a=n[2]>180,c=Bt(i);if(c.features.length>1&&(f||a))for(const E of c.features){const m=tt(Ve(E));if(a&&m[0]<-180+r)for(const L of E.geometry.coordinates)for(const T of L)T[0]+=360-r;if(f&&m[2]>180-r)for(const L of E.geometry.coordinates)for(const T of L)T[0]-=360-r}t(Oe([c.features.length<2?i:qt(c)??i,e]))}const nt="EPSG:4326";function Ft(i){var f;const t=i.getProperties(),{isMask:e}=t,n=(f=i.getGeometry())==null?void 0:f.getType(),r=e?0:n==="LineString"||n==="MultiLineString"?3:2;return new ht({stroke:e?void 0:new De({color:"#3170fe",lineDash:[r,r],width:r,lineCap:"butt"}),fill:e?new Fe({color:"#00000020"}):void 0,image:new ft({src:`/icons/marker_${t.isReverse?"reverse":t.isSelected?"selected":"unselected"}.svg`,anchor:[.5,1]}),zIndex:t.isSelected?2:t.isReverse?0:1,text:t.isSelected&&t.tooltip?new ct({backgroundFill:new Fe({color:"white"}),text:t.tooltip,offsetY:-40,backgroundStroke:new De({color:"white",lineJoin:"round",width:3}),padding:[2,0,0,2]}):void 0})}function Dt(i,t={},e={},n=Ft){let r=-1,f,a,c,E=!1;const m=new lt({updateWhileAnimating:!0});i.addLayer(m);const L=new ut({});m.setSource(L),m.setStyle(n),i.on("click",O=>{i.forEachFeatureAtPixel(O.pixel,P=>{const A=P.getId();if(A)return O.stopPropagation(),a==null||a({type:"markerClick",id:A}),P})}),i.on("pointermove",O=>{const P=i.forEachFeatureAtPixel(O.pixel,A=>A.getId());f!==P&&(f&&(a==null||a({type:"markerMouseLeave",id:f})),P&&(a==null||a({type:"markerMouseEnter",id:P})),i.getTargetElement().style.cursor=P?"pointer":E?"crosshair":"",f=P)});function T(){return he.getUserProjection()??i.getView().getProjection()}function b(O){return O.transform(nt,T())}const N=O=>{a==null||a({type:"mapClick",coordinates:he.toLonLat(O.coordinate,T())})};return{setEventHandler(O){O?(a=O,i.on("click",N)):(a=void 0,i.un("click",N))},flyTo(O,P){i.getView().animate({center:he.fromLonLat(O,T()),...P?{zoom:P}:{},duration:2e3,...t})},fitBounds(O,P,A){i.getView().fit(he.transformExtent(O,nt,T()),{padding:[P,P,P,P],...A?{maxZoom:A}:{},duration:2e3,...e})},indicateReverse(O){E=O,i.getTargetElement().style.cursor=O?"crosshair":""},setReverseMarker(O){c?O?c.getGeometry().setCoordinates(he.fromLonLat(O,T())):(L.removeFeature(c),c.dispose(),c=void 0):O&&(c=new V.Feature(new K.Point(he.fromLonLat(O,T()))),c.setProperties({isReverse:!0}),L.addFeature(c))},setFeatures(O,P,A){function X(S){var q;if(S)for(const B of S.features){const J=B.geometry.type==="Polygon"?new K.Polygon(B.geometry.coordinates):B.geometry.type==="MultiPolygon"?new K.MultiPolygon(B.geometry.coordinates):null;J&&L.addFeature(new V.Feature({isMask:!!((q=B.properties)!=null&&q.isMask),geometry:b(J)}))}}L.clear(),c&&L.addFeature(c);e:if(P){let S=!1;if(P.geometry.type==="GeometryCollection"){const q=P.geometry.geometries.map(B=>B.type==="Polygon"?new K.Polygon(B.coordinates):B.type==="MultiPolygon"?new K.MultiPolygon(B.coordinates):null).filter(B=>!!B);if(q.length>0)L.addFeature(new V.Feature(b(new K.GeometryCollection(q)))),S=!0;else for(const B of P.geometry.geometries)B.type==="LineString"?(L.addFeature(new V.Feature(b(new K.LineString(B.coordinates)))),S=!0):B.type==="MultiLineString"&&L.addFeature(new V.Feature(b(new K.MultiLineString(B.coordinates)))),S=!0}if(!S){if(P.geometry.type==="Polygon")it(P,X);else if(P.geometry.type==="MultiPolygon")it(P,X);else if(P.geometry.type==="LineString"){L.addFeature(new V.Feature(b(new K.LineString(P.geometry.coordinates))));break e}else if(P.geometry.type==="MultiLineString"){L.addFeature(new V.Feature(b(new K.MultiLineString(P.geometry.coordinates))));break e}}if(!A&&P.geometry.type!=="Point")break e;L.addFeature(new V.Feature(b(new K.Point(P.center))))}for(const S of O??[]){if(S===P)continue;const q=new V.Feature(new K.Point(he.fromLonLat(S.center,T())));q.setId(S.id),q.setProperties({fuzzy:!!S.matching_text,tooltip:S.place_type[0]==="reverse"?S.place_name:S.place_name.replace(/,.*/,"")}),L.addFeature(q)}},setSelectedMarker(O){var X,S,q;const P=L.getFeatures(),A=(X=P[0])!=null&&X.getProperties().isReverse?1:0;r>-1&&((S=P[r+A])==null||S.setProperties({isSelected:!1})),O>-1&&((q=P[O+A])==null||q.setProperties({isSelected:!0})),r=O},getCenterAndZoom(){const O=i.getView(),P=O.getCenter(),A=O.getZoom();if(!(!P||A===void 0))return[A,...he.toLonLat(P,T())]}}}D.createOpenLayersMapController=Dt,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
23
2
  //# sourceMappingURL=openlayers-controller.umd.js.map