leaflet-polydraw 1.3.2 → 2.0.0-alpha.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 (39) hide show
  1. package/README.md +1 -1
  2. package/dist/icons/icon-grip-vertical.svg +8 -0
  3. package/dist/icons/icon-layer-toggle.svg +6 -0
  4. package/dist/leaflet-polydraw.css +1 -1
  5. package/dist/polydraw.es.js +4597 -10003
  6. package/dist/polydraw.es.js.map +1 -1
  7. package/dist/polydraw.umd.min.js +1 -1
  8. package/dist/polydraw.umd.min.js.map +1 -1
  9. package/dist/styles/polydraw.css +357 -0
  10. package/dist/types/buttons.d.ts.map +1 -1
  11. package/dist/types/config.d.ts.map +1 -1
  12. package/dist/types/coordinate-utils.d.ts.map +1 -1
  13. package/dist/types/guards/config-deprecation-guard.d.ts +3 -0
  14. package/dist/types/guards/config-deprecation-guard.d.ts.map +1 -0
  15. package/dist/types/guards/config-runtime-fallback-guard.d.ts +3 -0
  16. package/dist/types/guards/config-runtime-fallback-guard.d.ts.map +1 -0
  17. package/dist/types/managers/event-manager.d.ts +45 -0
  18. package/dist/types/managers/event-manager.d.ts.map +1 -1
  19. package/dist/types/managers/history-manager.d.ts +16 -3
  20. package/dist/types/managers/history-manager.d.ts.map +1 -1
  21. package/dist/types/managers/layer-manager.d.ts +79 -0
  22. package/dist/types/managers/layer-manager.d.ts.map +1 -0
  23. package/dist/types/managers/polygon-draw-manager.d.ts +1 -0
  24. package/dist/types/managers/polygon-draw-manager.d.ts.map +1 -1
  25. package/dist/types/managers/polygon-interaction-manager.d.ts +27 -0
  26. package/dist/types/managers/polygon-interaction-manager.d.ts.map +1 -1
  27. package/dist/types/managers/polygon-mutation-manager.d.ts +33 -2
  28. package/dist/types/managers/polygon-mutation-manager.d.ts.map +1 -1
  29. package/dist/types/polydraw.d.ts +157 -7
  30. package/dist/types/polydraw.d.ts.map +1 -1
  31. package/dist/types/transform/transform-overlay.d.ts +2 -0
  32. package/dist/types/transform/transform-overlay.d.ts.map +1 -1
  33. package/dist/types/turf-helper.d.ts +5 -6
  34. package/dist/types/turf-helper.d.ts.map +1 -1
  35. package/dist/types/types/polydraw-interfaces.d.ts +224 -111
  36. package/dist/types/types/polydraw-interfaces.d.ts.map +1 -1
  37. package/dist/types/ui/layer-panel.d.ts +13 -0
  38. package/dist/types/ui/layer-panel.d.ts.map +1 -0
  39. package/package.json +11 -5
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("leaflet")):"function"==typeof define&&define.amd?define(["exports","leaflet"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).LeafletPolydraw={},t.L)}(this,function(t,e){"use strict";var n,i,r=Object.defineProperty,o=(t,e,n)=>((t,e,n)=>e in t?r(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n)(t,"symbol"!=typeof e?e+"":e,n);function s(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const n in t)if("default"!==n){const i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:()=>t[n]})}return e.default=t,Object.freeze(e)}const a=s(e);var l=(t=>(t.V1="1.x",t.V2="2.x",t))(l||{}),u=(t=>(t[t.Off=0]="Off",t[t.Add=1]="Add",t[t.Edit=2]="Edit",t[t.Subtract=4]="Subtract",t[t.AppendMarker=8]="AppendMarker",t[t.LoadPredefined=16]="LoadPredefined",t[t.PointToPoint=32]="PointToPoint",t[t.PointToPointSubtract=64]="PointToPointSubtract",t[t.Clone=128]="Clone",t))(u||{}),h=(t=>(t[t.SouthWest=0]="SouthWest",t[t.South=1]="South",t[t.SouthEast=2]="SouthEast",t[t.East=3]="East",t[t.NorthEast=4]="NorthEast",t[t.North=5]="North",t[t.NorthWest=6]="NorthWest",t[t.West=7]="West",t[t.Hole=8]="Hole",t))(h||{});const c={mergePolygons:!0,kinks:!1,modes:{draw:!0,subtract:!0,deleteAll:!0,p2p:!0,p2pSubtract:!0,clonePolygons:!0,attachElbow:!0,dragElbow:!0,dragPolygons:!0,edgeDeletion:!0},defaultMode:u.Off,modifierSubtractMode:!0,dragPolygons:{opacity:.7,dragCursor:"move",hoverCursor:"grab",markerBehavior:"hide",markerAnimationDuration:200,modifierSubtract:{keys:{windows:"ctrlKey",mac:"metaKey",linux:"ctrlKey"},hideMarkersOnDrag:!0}},edgeDeletion:{keys:{windows:"ctrlKey",mac:"metaKey",linux:"ctrlKey"},minVertices:3},markers:{deleteMarker:!0,infoMarker:!0,menuMarker:!0,coordsTitle:!0,zIndexOffset:0,markerIcon:{styleClasses:["polygon-marker"],zIndexOffset:null},holeIcon:{styleClasses:["polygon-marker","hole"],zIndexOffset:null},markerInfoIcon:{position:3,showArea:!0,showPerimeter:!0,useMetrics:!0,usePerimeterMinValue:!1,areaLabel:"Area",perimeterLabel:"Perimeter",values:{min:{metric:"50",imperial:"100"},unknown:{metric:"-",imperial:"-"}},units:{unknownUnit:"",metric:{onlyMetrics:!0,perimeter:{m:"m",km:"km"},area:{m2:"m²",km2:"km²",daa:"daa",ha:"ha"}},imperial:{perimeter:{feet:"ft",yards:"yd",miles:"mi"},area:{feet2:"ft²",yards2:"yd²",acres:"ac",miles2:"mi²"}}},styleClasses:["polygon-marker","info"],zIndexOffset:1e4},markerMenuIcon:{position:1,styleClasses:["polygon-marker","menu"],zIndexOffset:1e4},markerDeleteIcon:{position:5,styleClasses:["polygon-marker","delete"],zIndexOffset:1e4},holeMarkers:{menuMarker:!1,deleteMarker:!0,infoMarker:!1},visualOptimization:{toleranceMin:5e-6,toleranceMax:.005,curve:1.35,sharpAngleThreshold:30,thresholdBoundingBox:.05,thresholdDistance:.05,useDistance:!0,useBoundingBox:!1,useAngles:!0}},polyLineOptions:{opacity:1,weight:2},subtractLineOptions:{opacity:1,weight:2},polygonOptions:{weight:2,opacity:1,fillOpacity:.2,smoothFactor:.3,noClip:!0},holeOptions:{weight:2,opacity:1,fillOpacity:.5},polygonCreation:{method:"concaveman",simplification:{mode:"simple",tolerance:.001,highQuality:!1}},simplification:{mode:"simple",simple:{tolerance:1e-4,highQuality:!1},dynamic:{baseTolerance:1e-4,highQuality:!1,fractionGuard:.9,multiplier:2}},menuOperations:{simplify:{enabled:!0,processHoles:!0},doubleElbows:{enabled:!0,processHoles:!0},bbox:{enabled:!0,processHoles:!0},bezier:{enabled:!0},scale:{enabled:!0},rotate:{enabled:!0},visualOptimizationToggle:{enabled:!0}},boundingBox:{addMidPointMarkers:!0},bezier:{resolution:1e4,sharpness:.75,resampleMultiplier:10,maxNodes:1e3,visualOptimizationLevel:10,ghostMarkers:!1},colors:{dragPolygons:{subtract:"#D9460F"},p2p:{closingMarker:"#4CAF50"},edgeHover:"#7a9441",edgeDeletion:{hover:"#D9460F"},polyline:"#50622b",subtractLine:"#D9460F",polygon:{border:"#50622b",fill:"#b4cd8a"},hole:{border:"#aa0000",fill:"#ffcccc"},styles:{controlButton:{backgroundColor:"#fff",color:"#000"},controlButtonHover:{backgroundColor:"#f4f4f4"},controlButtonActive:{backgroundColor:"rgb(128, 218, 255)",color:"#fff"},indicatorActive:{backgroundColor:"#ffcc00"},p2pMarker:{backgroundColor:"#fff",borderColor:"#50622b"}}},history:{capture:{freehand:!0,pointToPoint:!0,addPredefinedPolygon:!0,eraseAll:!0,markerDrag:!0,polygonDrag:!0,polygonClone:!0,addVertex:!0,removeVertex:!0,removeHole:!0,modifierSubtract:!0,deletePolygon:!0,polygonActions:{simplify:!0,doubleElbows:!0,bbox:!0,bezier:!0,scale:!0,rotate:!0,toggleOptimization:!0}}},maxHistorySize:50},f=6371e3,g=6371,d=3959,p=Math.PI/180,y=180/Math.PI;Math.PI;function m(t,e={}){return{type:"Feature",geometry:{type:"Point",coordinates:t},properties:e}}function v(t,e={}){return{type:"Feature",geometry:{type:"LineString",coordinates:t},properties:e}}function _(t,e={}){return{type:"Feature",geometry:{type:"Polygon",coordinates:t},properties:e}}function k(t,e={}){return{type:"Feature",geometry:{type:"MultiPolygon",coordinates:t},properties:e}}function x(t){return{type:"FeatureCollection",features:t}}function E(t){if("Polygon"===t.geometry.type)return[t.geometry.coordinates];if("MultiPolygon"===t.geometry.type)return t.geometry.coordinates;throw new Error("Feature must be a Polygon or MultiPolygon")}function w(t){let e=1/0,n=1/0,i=-1/0,r=-1/0;const o=t=>{if(Array.isArray(t[0]))t.forEach(t=>o(t));else{const[o,s]=t;e=Math.min(e,o),n=Math.min(n,s),i=Math.max(i,o),r=Math.max(r,s)}},s=t=>{if("GeometryCollection"===t.type){return void t.geometries.forEach(s)}o(t.coordinates)};return s(t.geometry),[e,n,i,r]}function M(t,e,n="kilometers"){const i=Array.isArray(t)?t:t.geometry.coordinates,r=Array.isArray(e)?e:e.geometry.coordinates,[o,s]=i,[a,l]=r,u="miles"===n?d:"meters"===n?f:g,h=I(l-s),c=I(a-o),p=Math.sin(h/2)*Math.sin(h/2)+Math.cos(I(s))*Math.cos(I(l))*Math.sin(c/2)*Math.sin(c/2);return u*(2*Math.atan2(Math.sqrt(p),Math.sqrt(1-p)))}function P(t,e){const n=Array.isArray(t)?t:t.geometry.coordinates,i=Array.isArray(e)?e:e.geometry.coordinates,[r,o]=n,[s,a]=i;return m([(r+s)/2,(o+a)/2])}function b(t){const e=E(t);let n=0,i=0,r=0;for(const o of e)for(const t of o)for(const e of t)n+=e[0],i+=e[1],r++;return m([n/r,i/r])}function I(t){return t*p}var S=6371008.8,L={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*S,kilometers:6371.0088,kilometres:6371.0088,meters:S,metres:S,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:S/1852,radians:1,yards:6967335.223679999};function C(t,e,n={}){const i={type:"Feature"};return(0===n.id||n.id)&&(i.id=n.id),n.bbox&&(i.bbox=n.bbox),i.properties=e||{},i.geometry=t,i}function N(t,e,n={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!B(t[0])||!B(t[1]))throw new Error("coordinates must contain numbers");return C({type:"Point",coordinates:t},e,n)}function T(t,e,n={}){for(const i of t){if(i.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(i[i.length-1].length!==i[0].length)throw new Error("First and last Position are not equivalent.");for(let t=0;t<i[i.length-1].length;t++)if(i[i.length-1][t]!==i[0][t])throw new Error("First and last Position are not equivalent.")}return C({type:"Polygon",coordinates:t},e,n)}function D(t,e,n={}){if(t.length<2)throw new Error("coordinates must be an array of two or more positions");return C({type:"LineString",coordinates:t},e,n)}function O(t,e={}){const n={type:"FeatureCollection"};return e.id&&(n.id=e.id),e.bbox&&(n.bbox=e.bbox),n.features=t,n}function A(t,e,n={}){return C({type:"MultiPolygon",coordinates:t},e,n)}function R(t,e="kilometers"){const n=L[e];if(!n)throw new Error(e+" units is invalid");return t*n}function F(t){return t%360*Math.PI/180}function B(t){return!isNaN(t)&&null!==t&&!Array.isArray(t)}function G(t,e,n){if(null!==t)for(var i,r,o,s,a,l,u,h,c=0,f=0,g=t.type,d="FeatureCollection"===g,p="Feature"===g,y=d?t.features.length:1,m=0;m<y;m++){a=(h=!!(u=d?t.features[m].geometry:p?t.geometry:t)&&"GeometryCollection"===u.type)?u.geometries.length:1;for(var v=0;v<a;v++){var _=0,k=0;if(null!==(s=h?u.geometries[v]:u)){l=s.coordinates;var x=s.type;switch(c=!n||"Polygon"!==x&&"MultiPolygon"!==x?0:1,x){case null:break;case"Point":if(!1===e(l,f,m,_,k))return!1;f++,_++;break;case"LineString":case"MultiPoint":for(i=0;i<l.length;i++){if(!1===e(l[i],f,m,_,k))return!1;f++,"MultiPoint"===x&&_++}"LineString"===x&&_++;break;case"Polygon":case"MultiLineString":for(i=0;i<l.length;i++){for(r=0;r<l[i].length-c;r++){if(!1===e(l[i][r],f,m,_,k))return!1;f++}"MultiLineString"===x&&_++,"Polygon"===x&&k++}"Polygon"===x&&_++;break;case"MultiPolygon":for(i=0;i<l.length;i++){for(k=0,r=0;r<l[i].length;r++){for(o=0;o<l[i][r].length-c;o++){if(!1===e(l[i][r][o],f,m,_,k))return!1;f++}k++}_++}break;case"GeometryCollection":for(i=0;i<s.geometries.length;i++)if(!1===G(s.geometries[i],e,n))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function z(t,e){if("Feature"===t.type)e(t,0);else if("FeatureCollection"===t.type)for(var n=0;n<t.features.length&&!1!==e(t.features[n],n);n++);}function H(t,e){var n,i,r,o,s,a,l,u,h,c,f=0,g="FeatureCollection"===t.type,d="Feature"===t.type,p=g?t.features.length:1;for(n=0;n<p;n++){for(a=g?t.features[n].geometry:d?t.geometry:t,u=g?t.features[n].properties:d?t.properties:{},h=g?t.features[n].bbox:d?t.bbox:void 0,c=g?t.features[n].id:d?t.id:void 0,s=(l=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,r=0;r<s;r++)if(null!==(o=l?a.geometries[r]:a))switch(o.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===e(o,f,u,h,c))return!1;break;case"GeometryCollection":for(i=0;i<o.geometries.length;i++)if(!1===e(o.geometries[i],f,u,h,c))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===e(null,f,u,h,c))return!1;f++}}function Y(t,e){H(t,function(t,n,i,r,o){var s,a=null===t?null:t.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return!1!==e(C(t,i,{bbox:r,id:o}),n,0)&&void 0}switch(a){case"MultiPoint":s="Point";break;case"MultiLineString":s="LineString";break;case"MultiPolygon":s="Polygon"}for(var l=0;l<t.coordinates.length;l++){var u=t.coordinates[l];if(!1===e(C({type:s,coordinates:u},i),n,l))return!1}})}function U(t,e,n){var i=n,r=!1;return function(t,e){Y(t,function(t,n,i){var r=0;if(t.geometry){var o=t.geometry.type;if("Point"!==o&&"MultiPoint"!==o){var s,a=0,l=0,u=0;return!1!==G(t,function(o,h,c,f,g){if(void 0===s||n>a||f>l||g>u)return s=o,a=n,l=f,u=g,void(r=0);var d=D([s,o],t.properties);if(!1===e(d,n,i,g,r))return!1;r++,s=o})&&void 0}}})}(t,function(t,o,s,a,l){i=!1===r&&void 0===n?t:e(i,t,o,s,a,l),r=!0}),i}function X(t){return function(t,e,n){var i=n;return H(t,function(t,n,r,o,s){i=e(i,t,n,r,o,s)}),i}(t,(t,e)=>t+function(t){let e,n=0;switch(t.type){case"Polygon":return q(t.coordinates);case"MultiPolygon":for(e=0;e<t.coordinates.length;e++)n+=q(t.coordinates[e]);return n;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(e),0)}function q(t){let e=0;if(t&&t.length>0){e+=Math.abs(K(t[0]));for(let n=1;n<t.length;n++)e-=Math.abs(K(t[n]))}return e}var V=20294876564838.72,j=Math.PI/180;function K(t){const e=t.length-1;if(e<=2)return 0;let n=0,i=0;for(;i<e;){const r=t[i],o=t[i+1===e?0:i+1],s=t[i+2>=e?(i+2)%e:i+2],a=r[0]*j,l=o[1]*j;n+=(s[0]*j-a)*Math.sin(l),i++}return n*V}var W=X;function Z(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function J(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if("function"==typeof e){var n=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var i=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,i.get?i:{enumerable:!0,get:function(){return t[e]}})}),n}var $,Q={exports:{}},tt={exports:{}};function et(){return $||($=1,tt.exports=function(){function t(t,i,r,o,s){!function t(n,i,r,o,s){for(;o>r;){if(o-r>600){var a=o-r+1,l=i-r+1,u=Math.log(a),h=.5*Math.exp(2*u/3),c=.5*Math.sqrt(u*h*(a-h)/a)*(l-a/2<0?-1:1);t(n,i,Math.max(r,Math.floor(i-l*h/a+c)),Math.min(o,Math.floor(i+(a-l)*h/a+c)),s)}var f=n[i],g=r,d=o;for(e(n,r,i),s(n[o],f)>0&&e(n,r,o);g<d;){for(e(n,g,d),g++,d--;s(n[g],f)<0;)g++;for(;s(n[d],f)>0;)d--}0===s(n[r],f)?e(n,r,d):e(n,++d,o),d<=i&&(r=d+1),i<=d&&(o=d-1)}}(t,i,r||0,o||t.length-1,s||n)}function e(t,e,n){var i=t[e];t[e]=t[n],t[n]=i}function n(t,e){return t<e?-1:t>e?1:0}var i=function(t){void 0===t&&(t=9),this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function r(t,e,n){if(!n)return e.indexOf(t);for(var i=0;i<e.length;i++)if(n(t,e[i]))return i;return-1}function o(t,e){s(t,0,t.children.length,e,t)}function s(t,e,n,i,r){r||(r=d(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(var o=e;o<n;o++){var s=t.children[o];a(r,t.leaf?i(s):s)}return r}function a(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function l(t,e){return t.minX-e.minX}function u(t,e){return t.minY-e.minY}function h(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function c(t){return t.maxX-t.minX+(t.maxY-t.minY)}function f(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function g(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function d(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function p(e,n,i,r,o){for(var s=[n,i];s.length;)if(!((i=s.pop())-(n=s.pop())<=r)){var a=n+Math.ceil((i-n)/r/2)*r;t(e,a,n,i,o),s.push(n,a,a,i)}}return i.prototype.all=function(){return this._all(this.data,[])},i.prototype.search=function(t){var e=this.data,n=[];if(!g(t,e))return n;for(var i=this.toBBox,r=[];e;){for(var o=0;o<e.children.length;o++){var s=e.children[o],a=e.leaf?i(s):s;g(t,a)&&(e.leaf?n.push(s):f(t,a)?this._all(s,n):r.push(s))}e=r.pop()}return n},i.prototype.collides=function(t){var e=this.data;if(!g(t,e))return!1;for(var n=[];e;){for(var i=0;i<e.children.length;i++){var r=e.children[i],o=e.leaf?this.toBBox(r):r;if(g(t,o)){if(e.leaf||f(t,o))return!0;n.push(r)}}e=n.pop()}return!1},i.prototype.load=function(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(var e=0;e<t.length;e++)this.insert(t[e]);return this}var n=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var i=this.data;this.data=n,n=i}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this},i.prototype.insert=function(t){return t&&this._insert(t,this.data.height-1),this},i.prototype.clear=function(){return this.data=d([]),this},i.prototype.remove=function(t,e){if(!t)return this;for(var n,i,o,s=this.data,a=this.toBBox(t),l=[],u=[];s||l.length;){if(s||(s=l.pop(),i=l[l.length-1],n=u.pop(),o=!0),s.leaf){var h=r(t,s.children,e);if(-1!==h)return s.children.splice(h,1),l.push(s),this._condense(l),this}o||s.leaf||!f(s,a)?i?(n++,s=i.children[n],o=!1):s=null:(l.push(s),u.push(n),n=0,i=s,s=s.children[0])}return this},i.prototype.toBBox=function(t){return t},i.prototype.compareMinX=function(t,e){return t.minX-e.minX},i.prototype.compareMinY=function(t,e){return t.minY-e.minY},i.prototype.toJSON=function(){return this.data},i.prototype.fromJSON=function(t){return this.data=t,this},i.prototype._all=function(t,e){for(var n=[];t;)t.leaf?e.push.apply(e,t.children):n.push.apply(n,t.children),t=n.pop();return e},i.prototype._build=function(t,e,n,i){var r,s=n-e+1,a=this._maxEntries;if(s<=a)return o(r=d(t.slice(e,n+1)),this.toBBox),r;i||(i=Math.ceil(Math.log(s)/Math.log(a)),a=Math.ceil(s/Math.pow(a,i-1))),(r=d([])).leaf=!1,r.height=i;var l=Math.ceil(s/a),u=l*Math.ceil(Math.sqrt(a));p(t,e,n,u,this.compareMinX);for(var h=e;h<=n;h+=u){var c=Math.min(h+u-1,n);p(t,h,c,l,this.compareMinY);for(var f=h;f<=c;f+=l){var g=Math.min(f+l-1,c);r.children.push(this._build(t,f,g,i-1))}}return o(r,this.toBBox),r},i.prototype._chooseSubtree=function(t,e,n,i){for(;i.push(e),!e.leaf&&i.length-1!==n;){for(var r=1/0,o=1/0,s=void 0,a=0;a<e.children.length;a++){var l=e.children[a],u=h(l),c=(f=t,g=l,(Math.max(g.maxX,f.maxX)-Math.min(g.minX,f.minX))*(Math.max(g.maxY,f.maxY)-Math.min(g.minY,f.minY))-u);c<o?(o=c,r=u<r?u:r,s=l):c===o&&u<r&&(r=u,s=l)}e=s||e.children[0]}var f,g;return e},i.prototype._insert=function(t,e,n){var i=n?t:this.toBBox(t),r=[],o=this._chooseSubtree(i,this.data,e,r);for(o.children.push(t),a(o,i);e>=0&&r[e].children.length>this._maxEntries;)this._split(r,e),e--;this._adjustParentBBoxes(i,r,e)},i.prototype._split=function(t,e){var n=t[e],i=n.children.length,r=this._minEntries;this._chooseSplitAxis(n,r,i);var s=this._chooseSplitIndex(n,r,i),a=d(n.children.splice(s,n.children.length-s));a.height=n.height,a.leaf=n.leaf,o(n,this.toBBox),o(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(n,a)},i.prototype._splitRoot=function(t,e){this.data=d([t,e]),this.data.height=t.height+1,this.data.leaf=!1,o(this.data,this.toBBox)},i.prototype._chooseSplitIndex=function(t,e,n){for(var i,r,o,a,l,u,c,f=1/0,g=1/0,d=e;d<=n-e;d++){var p=s(t,0,d,this.toBBox),y=s(t,d,n,this.toBBox),m=(r=p,o=y,a=void 0,l=void 0,u=void 0,c=void 0,a=Math.max(r.minX,o.minX),l=Math.max(r.minY,o.minY),u=Math.min(r.maxX,o.maxX),c=Math.min(r.maxY,o.maxY),Math.max(0,u-a)*Math.max(0,c-l)),v=h(p)+h(y);m<f?(f=m,i=d,g=v<g?v:g):m===f&&v<g&&(g=v,i=d)}return i||n-e},i.prototype._chooseSplitAxis=function(t,e,n){var i=t.leaf?this.compareMinX:l,r=t.leaf?this.compareMinY:u;this._allDistMargin(t,e,n,i)<this._allDistMargin(t,e,n,r)&&t.children.sort(i)},i.prototype._allDistMargin=function(t,e,n,i){t.children.sort(i);for(var r=this.toBBox,o=s(t,0,e,r),l=s(t,n-e,n,r),u=c(o)+c(l),h=e;h<n-e;h++){var f=t.children[h];a(o,t.leaf?r(f):f),u+=c(o)}for(var g=n-e-1;g>=e;g--){var d=t.children[g];a(l,t.leaf?r(d):d),u+=c(l)}return u},i.prototype._adjustParentBBoxes=function(t,e,n){for(var i=n;i>=0;i--)a(e[i],t)},i.prototype._condense=function(t){for(var e=t.length-1,n=void 0;e>=0;e--)0===t[e].children.length?e>0?(n=t[e-1].children).splice(n.indexOf(t[e]),1):this.clear():o(t[e],this.toBBox)},i}()),tt.exports}function nt(t,e){return t<e?-1:t>e?1:0}const it=Object.freeze(Object.defineProperty({__proto__:null,default:class{constructor(t=[],e=nt){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let n=(this.length>>1)-1;n>=0;n--)this._down(n)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:n}=this,i=e[t];for(;t>0;){const r=t-1>>1,o=e[r];if(n(i,o)>=0)break;e[t]=o,t=r}e[t]=i}_down(t){const{data:e,compare:n}=this,i=this.length>>1,r=e[t];for(;t<i;){let i=1+(t<<1),o=e[i];const s=i+1;if(s<this.length&&n(e[s],o)<0&&(i=s,o=e[s]),n(o,r)>=0)break;e[t]=o,t=i}e[t]=r}}},Symbol.toStringTag,{value:"Module"})),rt=J(it);var ot,st,at,lt,ut,ht={exports:{}};function ct(){if(ut)return ht.exports;ut=1;var t=st?ot:(st=1,ot=function(t,e,n,i){var r=t[0],o=t[1],s=!1;void 0===n&&(n=0),void 0===i&&(i=e.length);for(var a=(i-n)/2,l=0,u=a-1;l<a;u=l++){var h=e[n+2*l+0],c=e[n+2*l+1],f=e[n+2*u+0],g=e[n+2*u+1];c>o!=g>o&&r<(f-h)*(o-c)/(g-c)+h&&(s=!s)}return s}),e=lt?at:(lt=1,at=function(t,e,n,i){var r=t[0],o=t[1],s=!1;void 0===n&&(n=0),void 0===i&&(i=e.length);for(var a=i-n,l=0,u=a-1;l<a;u=l++){var h=e[l+n][0],c=e[l+n][1],f=e[u+n][0],g=e[u+n][1];c>o!=g>o&&r<(f-h)*(o-c)/(g-c)+h&&(s=!s)}return s});return ht.exports=function(n,i,r,o){return i.length>0&&Array.isArray(i[0])?e(n,i,r,o):t(n,i,r,o)},ht.exports.nested=e,ht.exports.flat=t,ht.exports}var ft,gt,dt={exports:{}};function pt(){return ft||(ft=1,function(t){const e=134217729,n=33306690738754706e-32;function i(t,e,n,i,r){let o,s,a,l,u=e[0],h=i[0],c=0,f=0;h>u==h>-u?(o=u,u=e[++c]):(o=h,h=i[++f]);let g=0;if(c<t&&f<n)for(h>u==h>-u?(a=o-((s=u+o)-u),u=e[++c]):(a=o-((s=h+o)-h),h=i[++f]),o=s,0!==a&&(r[g++]=a);c<t&&f<n;)h>u==h>-u?(a=o-((s=o+u)-(l=s-o))+(u-l),u=e[++c]):(a=o-((s=o+h)-(l=s-o))+(h-l),h=i[++f]),o=s,0!==a&&(r[g++]=a);for(;c<t;)a=o-((s=o+u)-(l=s-o))+(u-l),u=e[++c],o=s,0!==a&&(r[g++]=a);for(;f<n;)a=o-((s=o+h)-(l=s-o))+(h-l),h=i[++f],o=s,0!==a&&(r[g++]=a);return 0===o&&0!==g||(r[g++]=o),g}function r(t){return new Float64Array(t)}const o=33306690738754716e-32,s=22204460492503146e-32,a=11093356479670487e-47,l=r(4),u=r(8),h=r(12),c=r(16),f=r(4);t.orient2d=function(t,r,g,d,p,y){const m=(r-y)*(g-p),v=(t-p)*(d-y),_=m-v;if(0===m||0===v||m>0!=v>0)return _;const k=Math.abs(m+v);return Math.abs(_)>=o*k?_:-function(t,r,o,g,d,p,y){let m,v,_,k,x,E,w,M,P,b,I,S,L,C,N,T,D,O;const A=t-d,R=o-d,F=r-p,B=g-p;x=(N=(M=A-(w=(E=e*A)-(E-A)))*(b=B-(P=(E=e*B)-(E-B)))-((C=A*B)-w*P-M*P-w*b))-(I=N-(D=(M=F-(w=(E=e*F)-(E-F)))*(b=R-(P=(E=e*R)-(E-R)))-((T=F*R)-w*P-M*P-w*b))),l[0]=N-(I+x)+(x-D),x=(L=C-((S=C+I)-(x=S-C))+(I-x))-(I=L-T),l[1]=L-(I+x)+(x-T),x=(O=S+I)-S,l[2]=S-(O-x)+(I-x),l[3]=O;let G=function(t,e){let n=e[0];for(let i=1;i<t;i++)n+=e[i];return n}(4,l),z=s*y;if(G>=z||-G>=z)return G;if(m=t-(A+(x=t-A))+(x-d),_=o-(R+(x=o-R))+(x-d),v=r-(F+(x=r-F))+(x-p),k=g-(B+(x=g-B))+(x-p),0===m&&0===v&&0===_&&0===k)return G;if(z=a*y+n*Math.abs(G),(G+=A*k+B*m-(F*_+R*v))>=z||-G>=z)return G;x=(N=(M=m-(w=(E=e*m)-(E-m)))*(b=B-(P=(E=e*B)-(E-B)))-((C=m*B)-w*P-M*P-w*b))-(I=N-(D=(M=v-(w=(E=e*v)-(E-v)))*(b=R-(P=(E=e*R)-(E-R)))-((T=v*R)-w*P-M*P-w*b))),f[0]=N-(I+x)+(x-D),x=(L=C-((S=C+I)-(x=S-C))+(I-x))-(I=L-T),f[1]=L-(I+x)+(x-T),x=(O=S+I)-S,f[2]=S-(O-x)+(I-x),f[3]=O;const H=i(4,l,4,f,u);x=(N=(M=A-(w=(E=e*A)-(E-A)))*(b=k-(P=(E=e*k)-(E-k)))-((C=A*k)-w*P-M*P-w*b))-(I=N-(D=(M=F-(w=(E=e*F)-(E-F)))*(b=_-(P=(E=e*_)-(E-_)))-((T=F*_)-w*P-M*P-w*b))),f[0]=N-(I+x)+(x-D),x=(L=C-((S=C+I)-(x=S-C))+(I-x))-(I=L-T),f[1]=L-(I+x)+(x-T),x=(O=S+I)-S,f[2]=S-(O-x)+(I-x),f[3]=O;const Y=i(H,u,4,f,h);x=(N=(M=m-(w=(E=e*m)-(E-m)))*(b=k-(P=(E=e*k)-(E-k)))-((C=m*k)-w*P-M*P-w*b))-(I=N-(D=(M=v-(w=(E=e*v)-(E-v)))*(b=_-(P=(E=e*_)-(E-_)))-((T=v*_)-w*P-M*P-w*b))),f[0]=N-(I+x)+(x-D),x=(L=C-((S=C+I)-(x=S-C))+(I-x))-(I=L-T),f[1]=L-(I+x)+(x-T),x=(O=S+I)-S,f[2]=S-(O-x)+(I-x),f[3]=O;const U=i(Y,h,4,f,c);return c[U-1]}(t,r,g,d,p,y,k)},t.orient2dfast=function(t,e,n,i,r,o){return(e-o)*(n-r)-(t-r)*(i-o)},Object.defineProperty(t,"__esModule",{value:!0})}(dt.exports)),dt.exports}const yt=Z(function(){if(gt)return Q.exports;gt=1;var t=et(),e=rt,n=ct(),i=pt().orient2d;function r(e,i,r){i=Math.max(0,void 0===i?2:i),r=r||0;var s=function(t){for(var e=t[0],i=t[0],r=t[0],o=t[0],s=0;s<t.length;s++){var a=t[s];a[0]<e[0]&&(e=a),a[0]>r[0]&&(r=a),a[1]<i[1]&&(i=a),a[1]>o[1]&&(o=a)}var l=[e,i,r,o],u=l.slice();for(s=0;s<t.length;s++)n(t[s],l)||u.push(t[s]);return function(t){t.sort(m);for(var e=[],n=0;n<t.length;n++){for(;e.length>=2&&h(e[e.length-2],e[e.length-1],t[n])<=0;)e.pop();e.push(t[n])}for(var i=[],r=t.length-1;r>=0;r--){for(;i.length>=2&&h(i[i.length-2],i[i.length-1],t[r])<=0;)i.pop();i.push(t[r])}return i.pop(),e.pop(),e.concat(i)}(u)}(e),a=new t(16);a.toBBox=function(t){return{minX:t[0],minY:t[1],maxX:t[0],maxY:t[1]}},a.compareMinX=function(t,e){return t[0]-e[0]},a.compareMinY=function(t,e){return t[1]-e[1]},a.load(e);for(var l,u=[],c=0;c<s.length;c++){var p=s[c];a.remove(p),l=g(p,l),u.push(l)}var y=new t(16);for(c=0;c<u.length;c++)y.insert(f(u[c]));for(var v=i*i,_=r*r;u.length;){var k=u.shift(),x=k.p,E=k.next.p,w=d(x,E);if(!(w<_)){var M=w/v;(p=o(a,k.prev.p,x,E,k.next.next.p,M,y))&&Math.min(d(p,x),d(p,E))<=M&&(u.push(k),u.push(g(p,k)),a.remove(p),y.remove(k),y.insert(f(k)),y.insert(f(k.next)))}}k=l;var P=[];do{P.push(k.p),k=k.next}while(k!==l);return P.push(k.p),P}function o(t,n,i,r,o,l,h){for(var c=new e([],s),f=t.data;f;){for(var g=0;g<f.children.length;g++){var d=f.children[g],y=f.leaf?p(d,i,r):a(i,r,d);y>l||c.push({node:d,dist:y})}for(;c.length&&!c.peek().node.children;){var m=c.pop(),v=m.node,_=p(v,n,i),k=p(v,r,o);if(m.dist<_&&m.dist<k&&u(i,v,h)&&u(r,v,h))return v}(f=c.pop())&&(f=f.node)}return null}function s(t,e){return t.dist-e.dist}function a(t,e,n){if(l(t,n)||l(e,n))return 0;var i=y(t[0],t[1],e[0],e[1],n.minX,n.minY,n.maxX,n.minY);if(0===i)return 0;var r=y(t[0],t[1],e[0],e[1],n.minX,n.minY,n.minX,n.maxY);if(0===r)return 0;var o=y(t[0],t[1],e[0],e[1],n.maxX,n.minY,n.maxX,n.maxY);if(0===o)return 0;var s=y(t[0],t[1],e[0],e[1],n.minX,n.maxY,n.maxX,n.maxY);return 0===s?0:Math.min(i,r,o,s)}function l(t,e){return t[0]>=e.minX&&t[0]<=e.maxX&&t[1]>=e.minY&&t[1]<=e.maxY}function u(t,e,n){for(var i=Math.min(t[0],e[0]),r=Math.min(t[1],e[1]),o=Math.max(t[0],e[0]),s=Math.max(t[1],e[1]),a=n.search({minX:i,minY:r,maxX:o,maxY:s}),l=0;l<a.length;l++)if(c(a[l].p,a[l].next.p,t,e))return!1;return!0}function h(t,e,n){return i(t[0],t[1],e[0],e[1],n[0],n[1])}function c(t,e,n,i){return t!==i&&e!==n&&h(t,e,n)>0!=h(t,e,i)>0&&h(n,i,t)>0!=h(n,i,e)>0}function f(t){var e=t.p,n=t.next.p;return t.minX=Math.min(e[0],n[0]),t.minY=Math.min(e[1],n[1]),t.maxX=Math.max(e[0],n[0]),t.maxY=Math.max(e[1],n[1]),t}function g(t,e){var n={p:t,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return e?(n.next=e.next,n.prev=e,e.next.prev=n,e.next=n):(n.prev=n,n.next=n),n}function d(t,e){var n=t[0]-e[0],i=t[1]-e[1];return n*n+i*i}function p(t,e,n){var i=e[0],r=e[1],o=n[0]-i,s=n[1]-r;if(0!==o||0!==s){var a=((t[0]-i)*o+(t[1]-r)*s)/(o*o+s*s);a>1?(i=n[0],r=n[1]):a>0&&(i+=o*a,r+=s*a)}return(o=t[0]-i)*o+(s=t[1]-r)*s}function y(t,e,n,i,r,o,s,a){var l,u,h,c,f=n-t,g=i-e,d=s-r,p=a-o,y=t-r,m=e-o,v=f*f+g*g,_=f*d+g*p,k=d*d+p*p,x=f*y+g*m,E=d*y+p*m,w=v*k-_*_,M=w,P=w;0===w?(u=0,M=1,c=E,P=k):(c=v*E-_*x,(u=_*E-k*x)<0?(u=0,c=E,P=k):u>M&&(u=M,c=E+_,P=k)),c<0?(c=0,-x<0?u=0:-x>v?u=M:(u=-x,M=v)):c>P&&(c=P,-x+_<0?u=0:-x+_>v?u=M:(u=-x+_,M=v));var b=(1-(h=0===c?0:c/P))*r+h*s-((1-(l=0===u?0:u/M))*t+l*n),I=(1-h)*o+h*a-((1-l)*e+l*i);return b*b+I*I}function m(t,e){return t[0]===e[0]?t[1]-e[1]:t[0]-e[0]}return e.default&&(e=e.default),Q.exports=r,Q.exports.default=r,Q.exports}());function mt(t,e={}){e.concavity=e.concavity||1/0;const n=[];if(G(t,t=>{n.push([t[0],t[1]])}),!n.length)return null;const i=yt(n,e.concavity);return i.length>3?T([i]):null}var vt=mt;function _t(t,e={}){let n=0,i=0,r=0;return G(t,function(t){n+=t[0],i+=t[1],r++},!0),N([n/r,i/r],e.properties)}function kt(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if("Feature"===t.type&&null!==t.geometry&&"Point"===t.geometry.type)return[...t.geometry.coordinates];if("Point"===t.type)return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function xt(t){if(Array.isArray(t))return t;if("Feature"===t.type){if(null!==t.geometry)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function Et(t){return"Feature"===t.type?t.geometry:t}function wt(t,e){return"FeatureCollection"===t.type?"FeatureCollection":"GeometryCollection"===t.type?"GeometryCollection":"Feature"===t.type&&null!==t.geometry?t.geometry.type:t.type}var Mt=function t(e,n={}){switch(wt(e)){case"Point":return N(kt(e),n.properties);case"Polygon":var i=[];G(e,function(t){i.push(t)});var r,o,s,a,l,u,h,c,f=_t(e,{properties:n.properties}),g=f.geometry.coordinates,d=0,p=0,y=0,m=i.map(function(t){return[t[0]-g[0],t[1]-g[1]]});for(r=0;r<i.length-1;r++)a=(o=m[r])[0],u=o[1],l=(s=m[r+1])[0],y+=c=a*(h=s[1])-l*u,d+=(a+l)*c,p+=(u+h)*c;if(0===y)return f;var v=1/(6*(.5*y));return N([g[0]+v*d,g[1]+v*p],n.properties);default:var _=mt(e);return _?t(_,{properties:n.properties}):_t(e,{properties:n.properties})}};let Pt=class{constructor(t=[],e=bt){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let n=(this.length>>1)-1;n>=0;n--)this._down(n)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:n}=this,i=e[t];for(;t>0;){const r=t-1>>1,o=e[r];if(n(i,o)>=0)break;e[t]=o,t=r}e[t]=i}_down(t){const{data:e,compare:n}=this,i=this.length>>1,r=e[t];for(;t<i;){let i=1+(t<<1),o=e[i];const s=i+1;if(s<this.length&&n(e[s],o)<0&&(i=s,o=e[s]),n(o,r)>=0)break;e[t]=o,t=i}e[t]=r}};function bt(t,e){return t<e?-1:t>e?1:0}function It(t,e){return t.p.x>e.p.x?1:t.p.x<e.p.x?-1:t.p.y!==e.p.y?t.p.y>e.p.y?1:-1:1}function St(t,e){return t.rightSweepEvent.p.x>e.rightSweepEvent.p.x?1:t.rightSweepEvent.p.x<e.rightSweepEvent.p.x?-1:t.rightSweepEvent.p.y!==e.rightSweepEvent.p.y?t.rightSweepEvent.p.y<e.rightSweepEvent.p.y?1:-1:1}let Lt=class{constructor(t,e,n,i){this.p={x:t[0],y:t[1]},this.featureId=e,this.ringId=n,this.eventId=i,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(t){return this.p.x===t.p.x&&this.p.y===t.p.y}};let Ct=0,Nt=0,Tt=0;function Dt(t,e){const n="Feature"===t.type?t.geometry:t;let i=n.coordinates;"Polygon"!==n.type&&"MultiLineString"!==n.type||(i=[i]),"LineString"===n.type&&(i=[[i]]);for(let r=0;r<i.length;r++)for(let t=0;t<i[r].length;t++){let n=i[r][t][0],o=null;Nt+=1;for(let s=0;s<i[r][t].length-1;s++){o=i[r][t][s+1];const a=new Lt(n,Ct,Nt,Tt),l=new Lt(o,Ct,Nt,Tt+1);a.otherEvent=l,l.otherEvent=a,It(a,l)>0?(l.isLeftEndpoint=!0,a.isLeftEndpoint=!1):(a.isLeftEndpoint=!0,l.isLeftEndpoint=!1),e.push(a),e.push(l),n=o,Tt+=1}}Ct+=1}let Ot=class{constructor(t){this.leftSweepEvent=t,this.rightSweepEvent=t.otherEvent}};function At(t,e){if(null===t||null===e)return!1;if(t.leftSweepEvent.ringId===e.leftSweepEvent.ringId&&(t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.rightSweepEvent)||t.leftSweepEvent.isSamePoint(e.leftSweepEvent)||t.leftSweepEvent.isSamePoint(e.rightSweepEvent)))return!1;const n=t.leftSweepEvent.p.x,i=t.leftSweepEvent.p.y,r=t.rightSweepEvent.p.x,o=t.rightSweepEvent.p.y,s=e.leftSweepEvent.p.x,a=e.leftSweepEvent.p.y,l=e.rightSweepEvent.p.x,u=e.rightSweepEvent.p.y,h=(u-a)*(r-n)-(l-s)*(o-i),c=(l-s)*(i-a)-(u-a)*(n-s),f=(r-n)*(i-a)-(o-i)*(n-s);if(0===h)return!1;const g=c/h,d=f/h;if(g>=0&&g<=1&&d>=0&&d<=1){return[n+g*(r-n),i+g*(o-i)]}return!1}var Rt=function(t,e){const n=new Pt([],It);return function(t,e){if("FeatureCollection"===t.type){const n=t.features;for(let t=0;t<n.length;t++)Dt(n[t],e)}else Dt(t,e)}(t,n),function(t,e){e=e||!1;const n=[],i=new Pt([],St);for(;t.length;){const r=t.pop();if(r.isLeftEndpoint){const t=new Ot(r);for(let o=0;o<i.data.length;o++){const s=i.data[o];if(e&&s.leftSweepEvent.featureId===r.featureId)continue;const a=At(t,s);!1!==a&&n.push(a)}i.push(t)}else!1===r.isLeftEndpoint&&i.pop()}return n}(n,e)};var Ft=function(t,e,n={}){const{removeDuplicates:i=!0,ignoreSelfIntersections:r=!0}=n;let o=[];"FeatureCollection"===t.type?o=o.concat(t.features):"Feature"===t.type?o.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||o.push(C(t)),"FeatureCollection"===e.type?o=o.concat(e.features):"Feature"===e.type?o.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||o.push(C(e));const s=Rt(O(o),r);let a=[];if(i){const t={};s.forEach(e=>{const n=e.join(",");t[n]||(t[n]=!0,a.push(e))})}else a=s;return O(a.map(t=>N(t)))},Bt=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Gt=Math.ceil,zt=Math.floor,Ht="[BigNumber Error] ",Yt=Ht+"Number primitive has more than 15 significant digits: ",Ut=1e14,Xt=14,qt=9007199254740991,Vt=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],jt=1e7,Kt=1e9;function Wt(t){var e=0|t;return t>0||t===e?e:e-1}function Zt(t){for(var e,n,i=1,r=t.length,o=t[0]+"";i<r;){for(e=t[i++]+"",n=Xt-e.length;n--;e="0"+e);o+=e}for(r=o.length;48===o.charCodeAt(--r););return o.slice(0,r+1||1)}function Jt(t,e){var n,i,r=t.c,o=e.c,s=t.s,a=e.s,l=t.e,u=e.e;if(!s||!a)return null;if(n=r&&!r[0],i=o&&!o[0],n||i)return n?i?0:-a:s;if(s!=a)return s;if(n=s<0,i=l==u,!r||!o)return i?0:!r^n?1:-1;if(!i)return l>u^n?1:-1;for(a=(l=r.length)<(u=o.length)?l:u,s=0;s<a;s++)if(r[s]!=o[s])return r[s]>o[s]^n?1:-1;return l==u?0:l>u^n?1:-1}function $t(t,e,n,i){if(t<e||t>n||t!==zt(t))throw Error(Ht+(i||"Argument")+("number"==typeof t?t<e||t>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function Qt(t){var e=t.c.length-1;return Wt(t.e/Xt)==e&&t.c[e]%2!=0}function te(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(e<0?"e":"e+")+e}function ee(t,e,n){var i,r;if(e<0){for(r=n+".";++e;r+=n);t=r+t}else if(++e>(i=t.length)){for(r=n,e-=i;--e;r+=n);t+=r}else e<i&&(t=t.slice(0,e)+"."+t.slice(e));return t}var ne=function t(e){var n,i,r,o,s,a=x.prototype={constructor:x,toString:null,valueOf:null},l=new x(1),u=20,h=4,c=-7,f=21,g=-1e7,d=1e7,p=!1,y=1,m=0,v={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},_="0123456789abcdefghijklmnopqrstuvwxyz",k=!0;function x(t,e){var n,o,s,a,l,c,f,p,y=this;if(!(y instanceof x))return new x(t,e);if(null==e){if(t&&!0===t._isBigNumber)return y.s=t.s,void(!t.c||t.e>d?y.c=y.e=null:t.e<g?y.c=[y.e=0]:(y.e=t.e,y.c=t.c.slice()));if((c="number"==typeof t)&&0*t==0){if(y.s=1/t<0?(t=-t,-1):1,t===~~t){for(a=0,l=t;l>=10;l/=10,a++);return void(a>d?y.c=y.e=null:(y.e=a,y.c=[t]))}p=String(t)}else{if(!Bt.test(p=String(t)))return r(y,p,c);y.s=45==p.charCodeAt(0)?(p=p.slice(1),-1):1}(a=p.indexOf("."))>-1&&(p=p.replace(".","")),(l=p.search(/e/i))>0?(a<0&&(a=l),a+=+p.slice(l+1),p=p.substring(0,l)):a<0&&(a=p.length)}else{if($t(e,2,_.length,"Base"),10==e&&k)return P(y=new x(t),u+y.e+1,h);if(p=String(t),c="number"==typeof t){if(0*t!=0)return r(y,p,c,e);if(y.s=1/t<0?(p=p.slice(1),-1):1,x.DEBUG&&p.replace(/^0\.0*|\./,"").length>15)throw Error(Yt+t)}else y.s=45===p.charCodeAt(0)?(p=p.slice(1),-1):1;for(n=_.slice(0,e),a=l=0,f=p.length;l<f;l++)if(n.indexOf(o=p.charAt(l))<0){if("."==o){if(l>a){a=f;continue}}else if(!s&&(p==p.toUpperCase()&&(p=p.toLowerCase())||p==p.toLowerCase()&&(p=p.toUpperCase()))){s=!0,l=-1,a=0;continue}return r(y,String(t),c,e)}c=!1,(a=(p=i(p,e,10,y.s)).indexOf("."))>-1?p=p.replace(".",""):a=p.length}for(l=0;48===p.charCodeAt(l);l++);for(f=p.length;48===p.charCodeAt(--f););if(p=p.slice(l,++f)){if(f-=l,c&&x.DEBUG&&f>15&&(t>qt||t!==zt(t)))throw Error(Yt+y.s*t);if((a=a-l-1)>d)y.c=y.e=null;else if(a<g)y.c=[y.e=0];else{if(y.e=a,y.c=[],l=(a+1)%Xt,a<0&&(l+=Xt),l<f){for(l&&y.c.push(+p.slice(0,l)),f-=Xt;l<f;)y.c.push(+p.slice(l,l+=Xt));l=Xt-(p=p.slice(l)).length}else l-=f;for(;l--;p+="0");y.c.push(+p)}}else y.c=[y.e=0]}function E(t,e,n,i){var r,o,s,a,l;if(null==n?n=h:$t(n,0,8),!t.c)return t.toString();if(r=t.c[0],s=t.e,null==e)l=Zt(t.c),l=1==i||2==i&&(s<=c||s>=f)?te(l,s):ee(l,s,"0");else if(o=(t=P(new x(t),e,n)).e,a=(l=Zt(t.c)).length,1==i||2==i&&(e<=o||o<=c)){for(;a<e;l+="0",a++);l=te(l,o)}else if(e-=s+(2===i&&o>s),l=ee(l,o,"0"),o+1>a){if(--e>0)for(l+=".";e--;l+="0");}else if((e+=o-a)>0)for(o+1==a&&(l+=".");e--;l+="0");return t.s<0&&r?"-"+l:l}function w(t,e){for(var n,i,r=1,o=new x(t[0]);r<t.length;r++)(!(i=new x(t[r])).s||(n=Jt(o,i))===e||0===n&&o.s===e)&&(o=i);return o}function M(t,e,n){for(var i=1,r=e.length;!e[--r];e.pop());for(r=e[0];r>=10;r/=10,i++);return(n=i+n*Xt-1)>d?t.c=t.e=null:n<g?t.c=[t.e=0]:(t.e=n,t.c=e),t}function P(t,e,n,i){var r,o,s,a,l,u,h,c=t.c,f=Vt;if(c){t:{for(r=1,a=c[0];a>=10;a/=10,r++);if((o=e-r)<0)o+=Xt,s=e,l=c[u=0],h=zt(l/f[r-s-1]%10);else if((u=Gt((o+1)/Xt))>=c.length){if(!i)break t;for(;c.length<=u;c.push(0));l=h=0,r=1,s=(o%=Xt)-Xt+1}else{for(l=a=c[u],r=1;a>=10;a/=10,r++);h=(s=(o%=Xt)-Xt+r)<0?0:zt(l/f[r-s-1]%10)}if(i=i||e<0||null!=c[u+1]||(s<0?l:l%f[r-s-1]),i=n<4?(h||i)&&(0==n||n==(t.s<0?3:2)):h>5||5==h&&(4==n||i||6==n&&(o>0?s>0?l/f[r-s]:0:c[u-1])%10&1||n==(t.s<0?8:7)),e<1||!c[0])return c.length=0,i?(e-=t.e+1,c[0]=f[(Xt-e%Xt)%Xt],t.e=-e||0):c[0]=t.e=0,t;if(0==o?(c.length=u,a=1,u--):(c.length=u+1,a=f[Xt-o],c[u]=s>0?zt(l/f[r-s]%f[s])*a:0),i)for(;;){if(0==u){for(o=1,s=c[0];s>=10;s/=10,o++);for(s=c[0]+=a,a=1;s>=10;s/=10,a++);o!=a&&(t.e++,c[0]==Ut&&(c[0]=1));break}if(c[u]+=a,c[u]!=Ut)break;c[u--]=0,a=1}for(o=c.length;0===c[--o];c.pop());}t.e>d?t.c=t.e=null:t.e<g&&(t.c=[t.e=0])}return t}function b(t){var e,n=t.e;return null===n?t.toString():(e=Zt(t.c),e=n<=c||n>=f?te(e,n):ee(e,n,"0"),t.s<0?"-"+e:e)}return x.clone=t,x.ROUND_UP=0,x.ROUND_DOWN=1,x.ROUND_CEIL=2,x.ROUND_FLOOR=3,x.ROUND_HALF_UP=4,x.ROUND_HALF_DOWN=5,x.ROUND_HALF_EVEN=6,x.ROUND_HALF_CEIL=7,x.ROUND_HALF_FLOOR=8,x.EUCLID=9,x.config=x.set=function(t){var e,n;if(null!=t){if("object"!=typeof t)throw Error(Ht+"Object expected: "+t);if(t.hasOwnProperty(e="DECIMAL_PLACES")&&($t(n=t[e],0,Kt,e),u=n),t.hasOwnProperty(e="ROUNDING_MODE")&&($t(n=t[e],0,8,e),h=n),t.hasOwnProperty(e="EXPONENTIAL_AT")&&((n=t[e])&&n.pop?($t(n[0],-Kt,0,e),$t(n[1],0,Kt,e),c=n[0],f=n[1]):($t(n,-Kt,Kt,e),c=-(f=n<0?-n:n))),t.hasOwnProperty(e="RANGE"))if((n=t[e])&&n.pop)$t(n[0],-Kt,-1,e),$t(n[1],1,Kt,e),g=n[0],d=n[1];else{if($t(n,-Kt,Kt,e),!n)throw Error(Ht+e+" cannot be zero: "+n);g=-(d=n<0?-n:n)}if(t.hasOwnProperty(e="CRYPTO")){if((n=t[e])!==!!n)throw Error(Ht+e+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw p=!n,Error(Ht+"crypto unavailable");p=n}else p=n}if(t.hasOwnProperty(e="MODULO_MODE")&&($t(n=t[e],0,9,e),y=n),t.hasOwnProperty(e="POW_PRECISION")&&($t(n=t[e],0,Kt,e),m=n),t.hasOwnProperty(e="FORMAT")){if("object"!=typeof(n=t[e]))throw Error(Ht+e+" not an object: "+n);v=n}if(t.hasOwnProperty(e="ALPHABET")){if("string"!=typeof(n=t[e])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(Ht+e+" invalid: "+n);k="0123456789"==n.slice(0,10),_=n}}return{DECIMAL_PLACES:u,ROUNDING_MODE:h,EXPONENTIAL_AT:[c,f],RANGE:[g,d],CRYPTO:p,MODULO_MODE:y,POW_PRECISION:m,FORMAT:v,ALPHABET:_}},x.isBigNumber=function(t){if(!t||!0!==t._isBigNumber)return!1;if(!x.DEBUG)return!0;var e,n,i=t.c,r=t.e,o=t.s;t:if("[object Array]"=={}.toString.call(i)){if((1===o||-1===o)&&r>=-Kt&&r<=Kt&&r===zt(r)){if(0===i[0]){if(0===r&&1===i.length)return!0;break t}if((e=(r+1)%Xt)<1&&(e+=Xt),String(i[0]).length==e){for(e=0;e<i.length;e++)if((n=i[e])<0||n>=Ut||n!==zt(n))break t;if(0!==n)return!0}}}else if(null===i&&null===r&&(null===o||1===o||-1===o))return!0;throw Error(Ht+"Invalid BigNumber: "+t)},x.maximum=x.max=function(){return w(arguments,-1)},x.minimum=x.min=function(){return w(arguments,1)},x.random=(o=9007199254740992,s=Math.random()*o&2097151?function(){return zt(Math.random()*o)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(t){var e,n,i,r,o,a=0,h=[],c=new x(l);if(null==t?t=u:$t(t,0,Kt),r=Gt(t/Xt),p)if(crypto.getRandomValues){for(e=crypto.getRandomValues(new Uint32Array(r*=2));a<r;)(o=131072*e[a]+(e[a+1]>>>11))>=9e15?(n=crypto.getRandomValues(new Uint32Array(2)),e[a]=n[0],e[a+1]=n[1]):(h.push(o%1e14),a+=2);a=r/2}else{if(!crypto.randomBytes)throw p=!1,Error(Ht+"crypto unavailable");for(e=crypto.randomBytes(r*=7);a<r;)(o=281474976710656*(31&e[a])+1099511627776*e[a+1]+4294967296*e[a+2]+16777216*e[a+3]+(e[a+4]<<16)+(e[a+5]<<8)+e[a+6])>=9e15?crypto.randomBytes(7).copy(e,a):(h.push(o%1e14),a+=7);a=r/7}if(!p)for(;a<r;)(o=s())<9e15&&(h[a++]=o%1e14);for(r=h[--a],t%=Xt,r&&t&&(o=Vt[Xt-t],h[a]=zt(r/o)*o);0===h[a];h.pop(),a--);if(a<0)h=[i=0];else{for(i=-1;0===h[0];h.splice(0,1),i-=Xt);for(a=1,o=h[0];o>=10;o/=10,a++);a<Xt&&(i-=Xt-a)}return c.e=i,c.c=h,c}),x.sum=function(){for(var t=1,e=arguments,n=new x(e[0]);t<e.length;)n=n.plus(e[t++]);return n},i=function(){var t="0123456789";function e(t,e,n,i){for(var r,o,s=[0],a=0,l=t.length;a<l;){for(o=s.length;o--;s[o]*=e);for(s[0]+=i.indexOf(t.charAt(a++)),r=0;r<s.length;r++)s[r]>n-1&&(null==s[r+1]&&(s[r+1]=0),s[r+1]+=s[r]/n|0,s[r]%=n)}return s.reverse()}return function(i,r,o,s,a){var l,c,f,g,d,p,y,v,k=i.indexOf("."),E=u,w=h;for(k>=0&&(g=m,m=0,i=i.replace(".",""),p=(v=new x(r)).pow(i.length-k),m=g,v.c=e(ee(Zt(p.c),p.e,"0"),10,o,t),v.e=v.c.length),f=g=(y=e(i,r,o,a?(l=_,t):(l=t,_))).length;0==y[--g];y.pop());if(!y[0])return l.charAt(0);if(k<0?--f:(p.c=y,p.e=f,p.s=s,y=(p=n(p,v,E,w,o)).c,d=p.r,f=p.e),k=y[c=f+E+1],g=o/2,d=d||c<0||null!=y[c+1],d=w<4?(null!=k||d)&&(0==w||w==(p.s<0?3:2)):k>g||k==g&&(4==w||d||6==w&&1&y[c-1]||w==(p.s<0?8:7)),c<1||!y[0])i=d?ee(l.charAt(1),-E,l.charAt(0)):l.charAt(0);else{if(y.length=c,d)for(--o;++y[--c]>o;)y[c]=0,c||(++f,y=[1].concat(y));for(g=y.length;!y[--g];);for(k=0,i="";k<=g;i+=l.charAt(y[k++]));i=ee(i,f,l.charAt(0))}return i}}(),n=function(){function t(t,e,n){var i,r,o,s,a=0,l=t.length,u=e%jt,h=e/jt|0;for(t=t.slice();l--;)a=((r=u*(o=t[l]%jt)+(i=h*o+(s=t[l]/jt|0)*u)%jt*jt+a)/n|0)+(i/jt|0)+h*s,t[l]=r%n;return a&&(t=[a].concat(t)),t}function e(t,e,n,i){var r,o;if(n!=i)o=n>i?1:-1;else for(r=o=0;r<n;r++)if(t[r]!=e[r]){o=t[r]>e[r]?1:-1;break}return o}function n(t,e,n,i){for(var r=0;n--;)t[n]-=r,r=t[n]<e[n]?1:0,t[n]=r*i+t[n]-e[n];for(;!t[0]&&t.length>1;t.splice(0,1));}return function(i,r,o,s,a){var l,u,h,c,f,g,d,p,y,m,v,_,k,E,w,M,b,I=i.s==r.s?1:-1,S=i.c,L=r.c;if(!(S&&S[0]&&L&&L[0]))return new x(i.s&&r.s&&(S?!L||S[0]!=L[0]:L)?S&&0==S[0]||!L?0*I:I/0:NaN);for(y=(p=new x(I)).c=[],I=o+(u=i.e-r.e)+1,a||(a=Ut,u=Wt(i.e/Xt)-Wt(r.e/Xt),I=I/Xt|0),h=0;L[h]==(S[h]||0);h++);if(L[h]>(S[h]||0)&&u--,I<0)y.push(1),c=!0;else{for(E=S.length,M=L.length,h=0,I+=2,(f=zt(a/(L[0]+1)))>1&&(L=t(L,f,a),S=t(S,f,a),M=L.length,E=S.length),k=M,v=(m=S.slice(0,M)).length;v<M;m[v++]=0);b=L.slice(),b=[0].concat(b),w=L[0],L[1]>=a/2&&w++;do{if(f=0,(l=e(L,m,M,v))<0){if(_=m[0],M!=v&&(_=_*a+(m[1]||0)),(f=zt(_/w))>1)for(f>=a&&(f=a-1),d=(g=t(L,f,a)).length,v=m.length;1==e(g,m,d,v);)f--,n(g,M<d?b:L,d,a),d=g.length,l=1;else 0==f&&(l=f=1),d=(g=L.slice()).length;if(d<v&&(g=[0].concat(g)),n(m,g,v,a),v=m.length,-1==l)for(;e(L,m,M,v)<1;)f++,n(m,M<v?b:L,v,a),v=m.length}else 0===l&&(f++,m=[0]);y[h++]=f,m[0]?m[v++]=S[k]||0:(m=[S[k]],v=1)}while((k++<E||null!=m[0])&&I--);c=null!=m[0],y[0]||y.splice(0,1)}if(a==Ut){for(h=1,I=y[0];I>=10;I/=10,h++);P(p,o+(p.e=h+u*Xt-1)+1,s,c)}else p.e=u,p.r=+c;return p}}(),r=function(){var t=/^(-?)0([xbo])(?=\w[\w.]*$)/i,e=/^([^.]+)\.$/,n=/^\.([^.]+)$/,i=/^-?(Infinity|NaN)$/,r=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(o,s,a,l){var u,h=a?s:s.replace(r,"");if(i.test(h))o.s=isNaN(h)?null:h<0?-1:1;else{if(!a&&(h=h.replace(t,function(t,e,n){return u="x"==(n=n.toLowerCase())?16:"b"==n?2:8,l&&l!=u?t:e}),l&&(u=l,h=h.replace(e,"$1").replace(n,"0.$1")),s!=h))return new x(h,u);if(x.DEBUG)throw Error(Ht+"Not a"+(l?" base "+l:"")+" number: "+s);o.s=null}o.c=o.e=null}}(),a.absoluteValue=a.abs=function(){var t=new x(this);return t.s<0&&(t.s=1),t},a.comparedTo=function(t,e){return Jt(this,new x(t,e))},a.decimalPlaces=a.dp=function(t,e){var n,i,r,o=this;if(null!=t)return $t(t,0,Kt),null==e?e=h:$t(e,0,8),P(new x(o),t+o.e+1,e);if(!(n=o.c))return null;if(i=((r=n.length-1)-Wt(this.e/Xt))*Xt,r=n[r])for(;r%10==0;r/=10,i--);return i<0&&(i=0),i},a.dividedBy=a.div=function(t,e){return n(this,new x(t,e),u,h)},a.dividedToIntegerBy=a.idiv=function(t,e){return n(this,new x(t,e),0,1)},a.exponentiatedBy=a.pow=function(t,e){var n,i,r,o,s,a,u,c,f=this;if((t=new x(t)).c&&!t.isInteger())throw Error(Ht+"Exponent not an integer: "+b(t));if(null!=e&&(e=new x(e)),s=t.e>14,!f.c||!f.c[0]||1==f.c[0]&&!f.e&&1==f.c.length||!t.c||!t.c[0])return c=new x(Math.pow(+b(f),s?t.s*(2-Qt(t)):+b(t))),e?c.mod(e):c;if(a=t.s<0,e){if(e.c?!e.c[0]:!e.s)return new x(NaN);(i=!a&&f.isInteger()&&e.isInteger())&&(f=f.mod(e))}else{if(t.e>9&&(f.e>0||f.e<-1||(0==f.e?f.c[0]>1||s&&f.c[1]>=24e7:f.c[0]<8e13||s&&f.c[0]<=9999975e7)))return o=f.s<0&&Qt(t)?-0:0,f.e>-1&&(o=1/o),new x(a?1/o:o);m&&(o=Gt(m/Xt+2))}for(s?(n=new x(.5),a&&(t.s=1),u=Qt(t)):u=(r=Math.abs(+b(t)))%2,c=new x(l);;){if(u){if(!(c=c.times(f)).c)break;o?c.c.length>o&&(c.c.length=o):i&&(c=c.mod(e))}if(r){if(0===(r=zt(r/2)))break;u=r%2}else if(P(t=t.times(n),t.e+1,1),t.e>14)u=Qt(t);else{if(0===(r=+b(t)))break;u=r%2}f=f.times(f),o?f.c&&f.c.length>o&&(f.c.length=o):i&&(f=f.mod(e))}return i?c:(a&&(c=l.div(c)),e?c.mod(e):o?P(c,m,h,undefined):c)},a.integerValue=function(t){var e=new x(this);return null==t?t=h:$t(t,0,8),P(e,e.e+1,t)},a.isEqualTo=a.eq=function(t,e){return 0===Jt(this,new x(t,e))},a.isFinite=function(){return!!this.c},a.isGreaterThan=a.gt=function(t,e){return Jt(this,new x(t,e))>0},a.isGreaterThanOrEqualTo=a.gte=function(t,e){return 1===(e=Jt(this,new x(t,e)))||0===e},a.isInteger=function(){return!!this.c&&Wt(this.e/Xt)>this.c.length-2},a.isLessThan=a.lt=function(t,e){return Jt(this,new x(t,e))<0},a.isLessThanOrEqualTo=a.lte=function(t,e){return-1===(e=Jt(this,new x(t,e)))||0===e},a.isNaN=function(){return!this.s},a.isNegative=function(){return this.s<0},a.isPositive=function(){return this.s>0},a.isZero=function(){return!!this.c&&0==this.c[0]},a.minus=function(t,e){var n,i,r,o,s=this,a=s.s;if(e=(t=new x(t,e)).s,!a||!e)return new x(NaN);if(a!=e)return t.s=-e,s.plus(t);var l=s.e/Xt,u=t.e/Xt,c=s.c,f=t.c;if(!l||!u){if(!c||!f)return c?(t.s=-e,t):new x(f?s:NaN);if(!c[0]||!f[0])return f[0]?(t.s=-e,t):new x(c[0]?s:3==h?-0:0)}if(l=Wt(l),u=Wt(u),c=c.slice(),a=l-u){for((o=a<0)?(a=-a,r=c):(u=l,r=f),r.reverse(),e=a;e--;r.push(0));r.reverse()}else for(i=(o=(a=c.length)<(e=f.length))?a:e,a=e=0;e<i;e++)if(c[e]!=f[e]){o=c[e]<f[e];break}if(o&&(r=c,c=f,f=r,t.s=-t.s),(e=(i=f.length)-(n=c.length))>0)for(;e--;c[n++]=0);for(e=Ut-1;i>a;){if(c[--i]<f[i]){for(n=i;n&&!c[--n];c[n]=e);--c[n],c[i]+=Ut}c[i]-=f[i]}for(;0==c[0];c.splice(0,1),--u);return c[0]?M(t,c,u):(t.s=3==h?-1:1,t.c=[t.e=0],t)},a.modulo=a.mod=function(t,e){var i,r,o=this;return t=new x(t,e),!o.c||!t.s||t.c&&!t.c[0]?new x(NaN):!t.c||o.c&&!o.c[0]?new x(o):(9==y?(r=t.s,t.s=1,i=n(o,t,0,3),t.s=r,i.s*=r):i=n(o,t,0,y),(t=o.minus(i.times(t))).c[0]||1!=y||(t.s=o.s),t)},a.multipliedBy=a.times=function(t,e){var n,i,r,o,s,a,l,u,h,c,f,g,d,p,y,m=this,v=m.c,_=(t=new x(t,e)).c;if(!(v&&_&&v[0]&&_[0]))return!m.s||!t.s||v&&!v[0]&&!_||_&&!_[0]&&!v?t.c=t.e=t.s=null:(t.s*=m.s,v&&_?(t.c=[0],t.e=0):t.c=t.e=null),t;for(i=Wt(m.e/Xt)+Wt(t.e/Xt),t.s*=m.s,(l=v.length)<(c=_.length)&&(d=v,v=_,_=d,r=l,l=c,c=r),r=l+c,d=[];r--;d.push(0));for(p=Ut,y=jt,r=c;--r>=0;){for(n=0,f=_[r]%y,g=_[r]/y|0,o=r+(s=l);o>r;)n=((u=f*(u=v[--s]%y)+(a=g*u+(h=v[s]/y|0)*f)%y*y+d[o]+n)/p|0)+(a/y|0)+g*h,d[o--]=u%p;d[o]=n}return n?++i:d.splice(0,1),M(t,d,i)},a.negated=function(){var t=new x(this);return t.s=-t.s||null,t},a.plus=function(t,e){var n,i=this,r=i.s;if(e=(t=new x(t,e)).s,!r||!e)return new x(NaN);if(r!=e)return t.s=-e,i.minus(t);var o=i.e/Xt,s=t.e/Xt,a=i.c,l=t.c;if(!o||!s){if(!a||!l)return new x(r/0);if(!a[0]||!l[0])return l[0]?t:new x(a[0]?i:0*r)}if(o=Wt(o),s=Wt(s),a=a.slice(),r=o-s){for(r>0?(s=o,n=l):(r=-r,n=a),n.reverse();r--;n.push(0));n.reverse()}for((r=a.length)-(e=l.length)<0&&(n=l,l=a,a=n,e=r),r=0;e;)r=(a[--e]=a[e]+l[e]+r)/Ut|0,a[e]=Ut===a[e]?0:a[e]%Ut;return r&&(a=[r].concat(a),++s),M(t,a,s)},a.precision=a.sd=function(t,e){var n,i,r,o=this;if(null!=t&&t!==!!t)return $t(t,1,Kt),null==e?e=h:$t(e,0,8),P(new x(o),t,e);if(!(n=o.c))return null;if(i=(r=n.length-1)*Xt+1,r=n[r]){for(;r%10==0;r/=10,i--);for(r=n[0];r>=10;r/=10,i++);}return t&&o.e+1>i&&(i=o.e+1),i},a.shiftedBy=function(t){return $t(t,-9007199254740991,qt),this.times("1e"+t)},a.squareRoot=a.sqrt=function(){var t,e,i,r,o,s=this,a=s.c,l=s.s,c=s.e,f=u+4,g=new x("0.5");if(1!==l||!a||!a[0])return new x(!l||l<0&&(!a||a[0])?NaN:a?s:1/0);if(0==(l=Math.sqrt(+b(s)))||l==1/0?(((e=Zt(a)).length+c)%2==0&&(e+="0"),l=Math.sqrt(+e),c=Wt((c+1)/2)-(c<0||c%2),i=new x(e=l==1/0?"5e"+c:(e=l.toExponential()).slice(0,e.indexOf("e")+1)+c)):i=new x(l+""),i.c[0])for((l=(c=i.e)+f)<3&&(l=0);;)if(o=i,i=g.times(o.plus(n(s,o,f,1))),Zt(o.c).slice(0,l)===(e=Zt(i.c)).slice(0,l)){if(i.e<c&&--l,"9999"!=(e=e.slice(l-3,l+1))&&(r||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(P(i,i.e+u+2,1),t=!i.times(i).eq(s));break}if(!r&&(P(o,o.e+u+2,0),o.times(o).eq(s))){i=o;break}f+=4,l+=4,r=1}return P(i,i.e+u+1,h,t)},a.toExponential=function(t,e){return null!=t&&($t(t,0,Kt),t++),E(this,t,e,1)},a.toFixed=function(t,e){return null!=t&&($t(t,0,Kt),t=t+this.e+1),E(this,t,e)},a.toFormat=function(t,e,n){var i,r=this;if(null==n)null!=t&&e&&"object"==typeof e?(n=e,e=null):t&&"object"==typeof t?(n=t,t=e=null):n=v;else if("object"!=typeof n)throw Error(Ht+"Argument not an object: "+n);if(i=r.toFixed(t,e),r.c){var o,s=i.split("."),a=+n.groupSize,l=+n.secondaryGroupSize,u=n.groupSeparator||"",h=s[0],c=s[1],f=r.s<0,g=f?h.slice(1):h,d=g.length;if(l&&(o=a,a=l,l=o,d-=o),a>0&&d>0){for(o=d%a||a,h=g.substr(0,o);o<d;o+=a)h+=u+g.substr(o,a);l>0&&(h+=u+g.slice(o)),f&&(h="-"+h)}i=c?h+(n.decimalSeparator||"")+((l=+n.fractionGroupSize)?c.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):c):h}return(n.prefix||"")+i+(n.suffix||"")},a.toFraction=function(t){var e,i,r,o,s,a,u,c,f,g,p,y,m=this,v=m.c;if(null!=t&&(!(u=new x(t)).isInteger()&&(u.c||1!==u.s)||u.lt(l)))throw Error(Ht+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+b(u));if(!v)return new x(m);for(e=new x(l),f=i=new x(l),r=c=new x(l),y=Zt(v),s=e.e=y.length-m.e-1,e.c[0]=Vt[(a=s%Xt)<0?Xt+a:a],t=!t||u.comparedTo(e)>0?s>0?e:f:u,a=d,d=1/0,u=new x(y),c.c[0]=0;g=n(u,e,0,1),1!=(o=i.plus(g.times(r))).comparedTo(t);)i=r,r=o,f=c.plus(g.times(o=f)),c=o,e=u.minus(g.times(o=e)),u=o;return o=n(t.minus(i),r,0,1),c=c.plus(o.times(f)),i=i.plus(o.times(r)),c.s=f.s=m.s,p=n(f,r,s*=2,h).minus(m).abs().comparedTo(n(c,i,s,h).minus(m).abs())<1?[f,r]:[c,i],d=a,p},a.toNumber=function(){return+b(this)},a.toPrecision=function(t,e){return null!=t&&$t(t,1,Kt),E(this,t,e,2)},a.toString=function(t){var e,n=this,r=n.s,o=n.e;return null===o?r?(e="Infinity",r<0&&(e="-"+e)):e="NaN":(null==t?e=o<=c||o>=f?te(Zt(n.c),o):ee(Zt(n.c),o,"0"):10===t&&k?e=ee(Zt((n=P(new x(n),u+o+1,h)).c),n.e,"0"):($t(t,2,_.length,"Base"),e=i(ee(Zt(n.c),o,"0"),10,t,r,!0)),r<0&&n.c[0]&&(e="-"+e)),e},a.valueOf=a.toJSON=function(){return b(this)},a._isBigNumber=!0,a[Symbol.toStringTag]="BigNumber",a[Symbol.for("nodejs.util.inspect.custom")]=a.valueOf,null!=e&&x.set(e),x}(),ie=class{constructor(t){o(this,"key"),o(this,"left",null),o(this,"right",null),this.key=t}},re=class extends ie{constructor(t){super(t)}},oe=class{constructor(){o(this,"size",0),o(this,"modificationCount",0),o(this,"splayCount",0)}splay(t){const e=this.root;if(null==e)return this.compare(t,t),-1;let n=null,i=null,r=null,o=null,s=e;const a=this.compare;let l;for(;;)if(l=a(s.key,t),l>0){let e=s.left;if(null==e)break;if(l=a(e.key,t),l>0&&(s.left=e.right,e.right=s,s=e,e=s.left,null==e))break;null==n?i=s:n.left=s,n=s,s=e}else{if(!(l<0))break;{let e=s.right;if(null==e)break;if(l=a(e.key,t),l<0&&(s.right=e.left,e.left=s,s=e,e=s.right,null==e))break;null==r?o=s:r.right=s,r=s,s=e}}return null!=r&&(r.right=s.left,s.left=o),null!=n&&(n.left=s.right,s.right=i),this.root!==s&&(this.root=s,this.splayCount++),l}splayMin(t){let e=t,n=e.left;for(;null!=n;){const t=n;e.left=t.right,t.right=e,e=t,n=e.left}return e}splayMax(t){let e=t,n=e.right;for(;null!=n;){const t=n;e.right=t.left,t.left=e,e=t,n=e.right}return e}_delete(t){if(null==this.root)return null;if(0!=this.splay(t))return null;let e=this.root;const n=e,i=e.left;if(this.size--,null==i)this.root=e.right;else{const t=e.right;e=this.splayMax(i),e.right=t,this.root=e}return this.modificationCount++,n}addNewRoot(t,e){this.size++,this.modificationCount++;const n=this.root;null!=n?(e<0?(t.left=n,t.right=n.right,n.right=null):(t.right=n,t.left=n.left,n.left=null),this.root=t):this.root=t}_first(){const t=this.root;return null==t?null:(this.root=this.splayMin(t),this.root)}_last(){const t=this.root;return null==t?null:(this.root=this.splayMax(t),this.root)}clear(){this.root=null,this.size=0,this.modificationCount++}has(t){return this.validKey(t)&&0==this.splay(t)}defaultCompare(){return(t,e)=>t<e?-1:t>e?1:0}wrap(){return{getRoot:()=>this.root,setRoot:t=>{this.root=t},getSize:()=>this.size,getModificationCount:()=>this.modificationCount,getSplayCount:()=>this.splayCount,setSplayCount:t=>{this.splayCount=t},splay:t=>this.splay(t),has:t=>this.has(t)}}},se=class t extends oe{constructor(t,e){super(),o(this,"root",null),o(this,"compare"),o(this,"validKey"),o(this,n,"[object Set]"),this.compare=t??this.defaultCompare(),this.validKey=e??(t=>null!=t&&null!=t)}delete(t){return!!this.validKey(t)&&null!=this._delete(t)}deleteAll(t){for(const e of t)this.delete(e)}forEach(t){const e=this[Symbol.iterator]();let n;for(;n=e.next(),!n.done;)t(n.value,n.value,this)}add(t){const e=this.splay(t);return 0!=e&&this.addNewRoot(new re(t),e),this}addAndReturn(t){const e=this.splay(t);return 0!=e&&this.addNewRoot(new re(t),e),this.root.key}addAll(t){for(const e of t)this.add(e)}isEmpty(){return null==this.root}isNotEmpty(){return null!=this.root}single(){if(0==this.size)throw"Bad state: No element";if(this.size>1)throw"Bad state: Too many element";return this.root.key}first(){if(0==this.size)throw"Bad state: No element";return this._first().key}last(){if(0==this.size)throw"Bad state: No element";return this._last().key}lastBefore(t){if(null==t)throw"Invalid arguments(s)";if(null==this.root)return null;if(this.splay(t)<0)return this.root.key;let e=this.root.left;if(null==e)return null;let n=e.right;for(;null!=n;)e=n,n=e.right;return e.key}firstAfter(t){if(null==t)throw"Invalid arguments(s)";if(null==this.root)return null;if(this.splay(t)>0)return this.root.key;let e=this.root.right;if(null==e)return null;let n=e.left;for(;null!=n;)e=n,n=e.left;return e.key}retainAll(e){const n=new t(this.compare,this.validKey),i=this.modificationCount;for(const t of e){if(i!=this.modificationCount)throw"Concurrent modification during iteration.";this.validKey(t)&&0==this.splay(t)&&n.add(this.root.key)}n.size!=this.size&&(this.root=n.root,this.size=n.size,this.modificationCount++)}lookup(t){if(!this.validKey(t))return null;return 0!=this.splay(t)?null:this.root.key}intersection(e){const n=new t(this.compare,this.validKey);for(const t of this)e.has(t)&&n.add(t);return n}difference(e){const n=new t(this.compare,this.validKey);for(const t of this)e.has(t)||n.add(t);return n}union(t){const e=this.clone();return e.addAll(t),e}clone(){const e=new t(this.compare,this.validKey);return e.size=this.size,e.root=this.copyNode(this.root),e}copyNode(t){if(null==t)return null;const e=new re(t.key);return function t(e,n){let i,r;do{if(i=e.left,r=e.right,null!=i){const e=new re(i.key);n.left=e,t(i,e)}if(null!=r){const t=new re(r.key);n.right=t,e=r,n=t}}while(null!=r)}(t,e),e}toSet(){return this.clone()}entries(){return new ue(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[(i=Symbol.iterator,n=Symbol.toStringTag,i)](){return new le(this.wrap())}},ae=class{constructor(t){o(this,"tree"),o(this,"path",new Array),o(this,"modificationCount",null),o(this,"splayCount"),this.tree=t,this.splayCount=t.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 t=this.path[this.path.length-1];return this.getValue(t)}rebuildPath(t){this.path.splice(0,this.path.length),this.tree.splay(t),this.path.push(this.tree.getRoot()),this.splayCount=this.tree.getSplayCount()}findLeftMostDescendent(t){for(;null!=t;)this.path.push(t),t=t.left}moveNext(){if(this.modificationCount!=this.tree.getModificationCount()){if(null==this.modificationCount){this.modificationCount=this.tree.getModificationCount();let t=this.tree.getRoot();for(;null!=t;)this.path.push(t),t=t.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 t=this.path[this.path.length-1],e=t.right;if(null!=e){for(;null!=e;)this.path.push(e),e=e.left;return!0}for(this.path.pop();this.path.length&&this.path[this.path.length-1].right===t;)t=this.path.pop();return this.path.length>0}},le=class extends ae{getValue(t){return t.key}},ue=class extends ae{getValue(t){return[t.key,t.key]}},he=t=>()=>t,ce=t=>{const e=t?(e,n)=>n.minus(e).abs().isLessThanOrEqualTo(t):he(!1);return(t,n)=>e(t,n)?0:t.comparedTo(n)};function fe(t){const e=t?(e,n,i,r,o)=>e.exponentiatedBy(2).isLessThanOrEqualTo(r.minus(n).exponentiatedBy(2).plus(o.minus(i).exponentiatedBy(2)).times(t)):he(!1);return(t,n,i)=>{const r=t.x,o=t.y,s=i.x,a=i.y,l=o.minus(a).times(n.x.minus(s)).minus(r.minus(s).times(n.y.minus(a)));return e(l,r,o,s,a)?0:l.comparedTo(0)}}var ge=t=>t,de=t=>{if(t){const e=new se(ce(t)),n=new se(ce(t)),i=(t,e)=>e.addAndReturn(t),r=t=>({x:i(t.x,e),y:i(t.y,n)});return r({x:new ne(0),y:new ne(0)}),r}return ge},pe=t=>({set:t=>{ye=pe(t)},reset:()=>pe(t),compare:ce(t),snap:de(t),orient:fe(t)}),ye=pe(),me=(t,e)=>t.ll.x.isLessThanOrEqualTo(e.x)&&e.x.isLessThanOrEqualTo(t.ur.x)&&t.ll.y.isLessThanOrEqualTo(e.y)&&e.y.isLessThanOrEqualTo(t.ur.y),ve=(t,e)=>{if(e.ur.x.isLessThan(t.ll.x)||t.ur.x.isLessThan(e.ll.x)||e.ur.y.isLessThan(t.ll.y)||t.ur.y.isLessThan(e.ll.y))return null;const n=t.ll.x.isLessThan(e.ll.x)?e.ll.x:t.ll.x,i=t.ur.x.isLessThan(e.ur.x)?t.ur.x:e.ur.x;return{ll:{x:n,y:t.ll.y.isLessThan(e.ll.y)?e.ll.y:t.ll.y},ur:{x:i,y:t.ur.y.isLessThan(e.ur.y)?t.ur.y:e.ur.y}}},_e=(t,e)=>t.x.times(e.y).minus(t.y.times(e.x)),ke=(t,e)=>t.x.times(e.x).plus(t.y.times(e.y)),xe=t=>ke(t,t).sqrt(),Ee=(t,e,n)=>{const i={x:e.x.minus(t.x),y:e.y.minus(t.y)},r={x:n.x.minus(t.x),y:n.y.minus(t.y)};return _e(r,i).div(xe(r)).div(xe(i))},we=(t,e,n)=>{const i={x:e.x.minus(t.x),y:e.y.minus(t.y)},r={x:n.x.minus(t.x),y:n.y.minus(t.y)};return ke(r,i).div(xe(r)).div(xe(i))},Me=(t,e,n)=>e.y.isZero()?null:{x:t.x.plus(e.x.div(e.y).times(n.minus(t.y))),y:n},Pe=(t,e,n)=>e.x.isZero()?null:{x:n,y:t.y.plus(e.y.div(e.x).times(n.minus(t.x)))},be=class t{constructor(t,e){o(this,"point"),o(this,"isLeft"),o(this,"segment"),o(this,"otherSE"),o(this,"consumedBy"),void 0===t.events?t.events=[this]:t.events.push(this),this.point=t,this.isLeft=e}static compare(e,n){const i=t.comparePoints(e.point,n.point);return 0!==i?i:(e.point!==n.point&&e.link(n),e.isLeft!==n.isLeft?e.isLeft?1:-1:Oe.compare(e.segment,n.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,i=e.length;n<i;n++){const t=e[n];this.point.events.push(t),t.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(void 0===n.segment.consumedBy)for(let i=e+1;i<t;i++){const t=this.point.events[i];void 0===t.consumedBy&&(n.otherSE.point.events===t.otherSE.point.events&&n.segment.consume(t.segment))}}}getAvailableLinkedEvents(){const t=[];for(let e=0,n=this.point.events.length;e<n;e++){const n=this.point.events[e];n!==this&&!n.segment.ringOut&&n.segment.isInResult()&&t.push(n)}return t}getLeftmostComparator(t){const e=new Map,n=n=>{const i=n.otherSE;e.set(n,{sine:Ee(this.point,t.point,i.point),cosine:we(this.point,t.point,i.point)})};return(t,i)=>{e.has(t)||n(t),e.has(i)||n(i);const{sine:r,cosine:o}=e.get(t),{sine:s,cosine:a}=e.get(i);return r.isGreaterThanOrEqualTo(0)&&s.isGreaterThanOrEqualTo(0)?o.isLessThan(a)?1:o.isGreaterThan(a)?-1:0:r.isLessThan(0)&&s.isLessThan(0)?o.isLessThan(a)?-1:o.isGreaterThan(a)?1:0:s.isLessThan(r)?-1:s.isGreaterThan(r)?1:0}}},Ie=class t{constructor(t){o(this,"events"),o(this,"poly"),o(this,"_isExteriorRing"),o(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(e){const n=[];for(let i=0,r=e.length;i<r;i++){const r=e[i];if(!r.isInResult()||r.ringOut)continue;let o=null,s=r.leftSE,a=r.rightSE;const l=[s],u=s.point,h=[];for(;o=s,s=a,l.push(s),s.point!==u;)for(;;){const e=s.getAvailableLinkedEvents();if(0===e.length){const t=l[0].point,e=l[l.length-1].point;throw new Error(`Unable to complete output ring starting at [${t.x}, ${t.y}]. Last matching segment found ends at [${e.x}, ${e.y}].`)}if(1===e.length){a=e[0].otherSE;break}let i=null;for(let t=0,n=h.length;t<n;t++)if(h[t].point===s.point){i=t;break}if(null!==i){const e=h.splice(i)[0],r=l.splice(e.index);r.unshift(r[0].otherSE),n.push(new t(r.reverse()));continue}h.push({index:l.length,point:s.point});const r=s.getLeftmostComparator(o);a=e.sort(r)[0].otherSE;break}n.push(new t(l))}return n}getGeom(){let t=this.events[0].point;const e=[t];for(let l=1,u=this.events.length-1;l<u;l++){const n=this.events[l].point,i=this.events[l+1].point;0!==ye.orient(n,t,i)&&(e.push(n),t=n)}if(1===e.length)return null;const n=e[0],i=e[1];0===ye.orient(n,t,i)&&e.shift(),e.push(e[0]);const r=this.isExteriorRing()?1:-1,o=this.isExteriorRing()?0:e.length-1,s=this.isExteriorRing()?e.length:-1,a=[];for(let l=o;l!=s;l+=r)a.push([e[l].x.toNumber(),e[l].y.toNumber()]);return a}isExteriorRing(){if(void 0===this._isExteriorRing){const t=this.enclosingRing();this._isExteriorRing=!t||!t.isExteriorRing()}return this._isExteriorRing}enclosingRing(){return void 0===this._enclosingRing&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){var t,e;let n=this.events[0];for(let o=1,s=this.events.length;o<s;o++){const t=this.events[o];be.compare(n,t)>0&&(n=t)}let i=n.segment.prevInResult(),r=i?i.prevInResult():null;for(;;){if(!i)return null;if(!r)return i.ringOut;if(r.ringOut!==i.ringOut)return(null==(t=r.ringOut)?void 0:t.enclosingRing())!==i.ringOut?i.ringOut:null==(e=i.ringOut)?void 0:e.enclosingRing();i=r.prevInResult(),r=i?i.prevInResult():null}}},Se=class{constructor(t){o(this,"exteriorRing"),o(this,"interiorRings"),this.exteriorRing=t,t.poly=this,this.interiorRings=[]}addInterior(t){this.interiorRings.push(t),t.poly=this}getGeom(){const t=this.exteriorRing.getGeom();if(null===t)return null;const e=[t];for(let n=0,i=this.interiorRings.length;n<i;n++){const t=this.interiorRings[n].getGeom();null!==t&&e.push(t)}return e}},Le=class{constructor(t){o(this,"rings"),o(this,"polys"),this.rings=t,this.polys=this._composePolys(t)}getGeom(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const n=this.polys[e].getGeom();null!==n&&t.push(n)}return t}_composePolys(t){var e;const n=[];for(let i=0,r=t.length;i<r;i++){const r=t[i];if(!r.poly)if(r.isExteriorRing())n.push(new Se(r));else{const t=r.enclosingRing();(null==t?void 0:t.poly)||n.push(new Se(t)),null==(e=null==t?void 0:t.poly)||e.addInterior(r)}}return n}},Ce=class{constructor(t,e=Oe.compare){o(this,"queue"),o(this,"tree"),o(this,"segments"),this.queue=t,this.tree=new se(e),this.segments=[]}process(t){const e=t.segment,n=[];if(t.consumedBy)return t.isLeft?this.queue.delete(t.otherSE):this.tree.delete(e),n;t.isLeft&&this.tree.add(e);let i=e,r=e;do{i=this.tree.lastBefore(i)}while(null!=i&&null!=i.consumedBy);do{r=this.tree.firstAfter(r)}while(null!=r&&null!=r.consumedBy);if(t.isLeft){let o=null;if(i){const t=i.getIntersection(e);if(null!==t&&(e.isAnEndpoint(t)||(o=t),!i.isAnEndpoint(t))){const e=this._splitSafely(i,t);for(let t=0,i=e.length;t<i;t++)n.push(e[t])}}let s=null;if(r){const t=r.getIntersection(e);if(null!==t&&(e.isAnEndpoint(t)||(s=t),!r.isAnEndpoint(t))){const e=this._splitSafely(r,t);for(let t=0,i=e.length;t<i;t++)n.push(e[t])}}if(null!==o||null!==s){let t=null;if(null===o)t=s;else if(null===s)t=o;else{t=be.comparePoints(o,s)<=0?o:s}this.queue.delete(e.rightSE),n.push(e.rightSE);const i=e.split(t);for(let e=0,r=i.length;e<r;e++)n.push(i[e])}n.length>0?(this.tree.delete(e),n.push(t)):(this.segments.push(e),e.prev=i)}else{if(i&&r){const t=i.getIntersection(r);if(null!==t){if(!i.isAnEndpoint(t)){const e=this._splitSafely(i,t);for(let t=0,i=e.length;t<i;t++)n.push(e[t])}if(!r.isAnEndpoint(t)){const e=this._splitSafely(r,t);for(let t=0,i=e.length;t<i;t++)n.push(e[t])}}}this.tree.delete(e)}return n}_splitSafely(t,e){this.tree.delete(t);const n=t.rightSE;this.queue.delete(n);const i=t.split(e);return i.push(n),void 0===t.consumedBy&&this.tree.add(t),i}},Ne=new class{constructor(){o(this,"type"),o(this,"numMultiPolys")}run(t,e,n){Ne.type=t;const i=[new Fe(e,!0)];for(let l=0,u=n.length;l<u;l++)i.push(new Fe(n[l],!1));if(Ne.numMultiPolys=i.length,"difference"===Ne.type){const t=i[0];let e=1;for(;e<i.length;)null!==ve(i[e].bbox,t.bbox)?e++:i.splice(e,1)}if("intersection"===Ne.type)for(let l=0,u=i.length;l<u;l++){const t=i[l];for(let e=l+1,n=i.length;e<n;e++)if(null===ve(t.bbox,i[e].bbox))return[]}const r=new se(be.compare);for(let l=0,u=i.length;l<u;l++){const t=i[l].getSweepEvents();for(let e=0,n=t.length;e<n;e++)r.add(t[e])}const o=new Ce(r);let s=null;for(0!=r.size&&(s=r.first(),r.delete(s));s;){const t=o.process(s);for(let e=0,n=t.length;e<n;e++){const n=t[e];void 0===n.consumedBy&&r.add(n)}0!=r.size?(s=r.first(),r.delete(s)):s=null}ye.reset();const a=Ie.factory(o.segments);return new Le(a).getGeom()}},Te=Ne,De=0,Oe=class t{constructor(t,e,n,i){o(this,"id"),o(this,"leftSE"),o(this,"rightSE"),o(this,"rings"),o(this,"windings"),o(this,"ringOut"),o(this,"consumedBy"),o(this,"prev"),o(this,"_prevInResult"),o(this,"_beforeState"),o(this,"_afterState"),o(this,"_isInResult"),this.id=++De,this.leftSE=t,t.segment=this,t.otherSE=e,this.rightSE=e,e.segment=this,e.otherSE=t,this.rings=n,this.windings=i}static compare(t,e){const n=t.leftSE.point.x,i=e.leftSE.point.x,r=t.rightSE.point.x,o=e.rightSE.point.x;if(o.isLessThan(n))return 1;if(r.isLessThan(i))return-1;const s=t.leftSE.point.y,a=e.leftSE.point.y,l=t.rightSE.point.y,u=e.rightSE.point.y;if(n.isLessThan(i)){if(a.isLessThan(s)&&a.isLessThan(l))return 1;if(a.isGreaterThan(s)&&a.isGreaterThan(l))return-1;const n=t.comparePoint(e.leftSE.point);if(n<0)return 1;if(n>0)return-1;const i=e.comparePoint(t.rightSE.point);return 0!==i?i:-1}if(n.isGreaterThan(i)){if(s.isLessThan(a)&&s.isLessThan(u))return-1;if(s.isGreaterThan(a)&&s.isGreaterThan(u))return 1;const n=e.comparePoint(t.leftSE.point);if(0!==n)return n;const i=t.comparePoint(e.rightSE.point);return i<0?1:i>0?-1:1}if(s.isLessThan(a))return-1;if(s.isGreaterThan(a))return 1;if(r.isLessThan(o)){const n=e.comparePoint(t.rightSE.point);if(0!==n)return n}if(r.isGreaterThan(o)){const n=t.comparePoint(e.rightSE.point);if(n<0)return 1;if(n>0)return-1}if(!r.eq(o)){const t=l.minus(s),e=r.minus(n),h=u.minus(a),c=o.minus(i);if(t.isGreaterThan(e)&&h.isLessThan(c))return 1;if(t.isLessThan(e)&&h.isGreaterThan(c))return-1}return r.isGreaterThan(o)?1:r.isLessThan(o)||l.isLessThan(u)?-1:l.isGreaterThan(u)?1:t.id<e.id?-1:t.id>e.id?1:0}static fromRing(e,n,i){let r,o,s;const a=be.comparePoints(e,n);if(a<0)r=e,o=n,s=1;else{if(!(a>0))throw new Error(`Tried to create degenerate segment at [${e.x}, ${e.y}]`);r=n,o=e,s=-1}const l=new be(r,!0),u=new be(o,!1);return new t(l,u,[i],[s])}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 ye.orient(this.leftSE.point,t,this.rightSE.point)}getIntersection(t){const e=this.bbox(),n=t.bbox(),i=ve(e,n);if(null===i)return null;const r=this.leftSE.point,o=this.rightSE.point,s=t.leftSE.point,a=t.rightSE.point,l=me(e,s)&&0===this.comparePoint(s),u=me(n,r)&&0===t.comparePoint(r),h=me(e,a)&&0===this.comparePoint(a),c=me(n,o)&&0===t.comparePoint(o);if(u&&l)return c&&!h?o:!c&&h?a:null;if(u)return h&&r.x.eq(a.x)&&r.y.eq(a.y)?null:r;if(l)return c&&o.x.eq(s.x)&&o.y.eq(s.y)?null:s;if(c&&h)return null;if(c)return o;if(h)return a;const f=((t,e,n,i)=>{if(e.x.isZero())return Pe(n,i,t.x);if(i.x.isZero())return Pe(t,e,n.x);if(e.y.isZero())return Me(n,i,t.y);if(i.y.isZero())return Me(t,e,n.y);const r=_e(e,i);if(r.isZero())return null;const o={x:n.x.minus(t.x),y:n.y.minus(t.y)},s=_e(o,e).div(r),a=_e(o,i).div(r),l=t.x.plus(a.times(e.x)),u=n.x.plus(s.times(i.x)),h=t.y.plus(a.times(e.y)),c=n.y.plus(s.times(i.y));return{x:l.plus(u).div(2),y:h.plus(c).div(2)}})(r,this.vector(),s,t.vector());return null===f?null:me(i,f)?ye.snap(f):null}split(e){const n=[],i=void 0!==e.events,r=new be(e,!0),o=new be(e,!1),s=this.rightSE;this.replaceRightSE(o),n.push(o),n.push(r);const a=new t(r,s,this.rings.slice(),this.windings.slice());return be.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),be.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),i&&(r.checkForConsuming(),o.checkForConsuming()),n}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(e){let n=this,i=e;for(;n.consumedBy;)n=n.consumedBy;for(;i.consumedBy;)i=i.consumedBy;const r=t.compare(n,i);if(0!==r){if(r>0){const t=n;n=i,i=t}if(n.prev===i){const t=n;n=i,i=t}for(let t=0,e=i.rings.length;t<e;t++){const e=i.rings[t],r=i.windings[t],o=n.rings.indexOf(e);-1===o?(n.rings.push(e),n.windings.push(r)):n.windings[o]+=r}i.rings=null,i.windings=null,i.consumedBy=n,i.leftSE.consumedBy=n.leftSE,i.rightSE.consumedBy=n.rightSE}}prevInResult(){return 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(void 0!==this._beforeState)return this._beforeState;if(this.prev){const t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}else this._beforeState={rings:[],windings:[],multiPolys:[]};return this._beforeState}afterState(){if(void 0!==this._afterState)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,i=this._afterState.multiPolys;for(let s=0,a=this.rings.length;s<a;s++){const t=this.rings[s],i=this.windings[s],r=e.indexOf(t);-1===r?(e.push(t),n.push(i)):n[r]+=i}const r=[],o=[];for(let s=0,a=e.length;s<a;s++){if(0===n[s])continue;const t=e[s],i=t.poly;if(-1===o.indexOf(i))if(t.isExterior)r.push(i);else{-1===o.indexOf(i)&&o.push(i);const e=r.indexOf(t.poly);-1!==e&&r.splice(e,1)}}for(let s=0,a=r.length;s<a;s++){const t=r[s].multiPoly;-1===i.indexOf(t)&&i.push(t)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(void 0!==this._isInResult)return this._isInResult;const t=this.beforeState().multiPolys,e=this.afterState().multiPolys;switch(Te.type){case"union":{const n=0===t.length,i=0===e.length;this._isInResult=n!==i;break}case"intersection":{let n,i;t.length<e.length?(n=t.length,i=e.length):(n=e.length,i=t.length),this._isInResult=i===Te.numMultiPolys&&n<i;break}case"xor":{const n=Math.abs(t.length-e.length);this._isInResult=n%2==1;break}case"difference":{const n=t=>1===t.length&&t[0].isSubject;this._isInResult=n(t)!==n(e);break}}return this._isInResult}},Ae=class{constructor(t,e,n){if(o(this,"poly"),o(this,"isExterior"),o(this,"segments"),o(this,"bbox"),!Array.isArray(t)||0===t.length)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=e,this.isExterior=n,this.segments=[],"number"!=typeof t[0][0]||"number"!=typeof t[0][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const i=ye.snap({x:new ne(t[0][0]),y:new ne(t[0][1])});this.bbox={ll:{x:i.x,y:i.y},ur:{x:i.x,y:i.y}};let r=i;for(let o=1,s=t.length;o<s;o++){if("number"!=typeof t[o][0]||"number"!=typeof t[o][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const e=ye.snap({x:new ne(t[o][0]),y:new ne(t[o][1])});e.x.eq(r.x)&&e.y.eq(r.y)||(this.segments.push(Oe.fromRing(r,e,this)),e.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=e.x),e.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=e.y),e.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=e.x),e.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=e.y),r=e)}i.x.eq(r.x)&&i.y.eq(r.y)||this.segments.push(Oe.fromRing(r,i,this))}getSweepEvents(){const t=[];for(let e=0,n=this.segments.length;e<n;e++){const n=this.segments[e];t.push(n.leftSE),t.push(n.rightSE)}return t}},Re=class{constructor(t,e){if(o(this,"multiPoly"),o(this,"exteriorRing"),o(this,"interiorRings"),o(this,"bbox"),!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new Ae(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,i=t.length;n<i;n++){const e=new Ae(t[n],this,!1);e.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=e.bbox.ll.x),e.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=e.bbox.ll.y),e.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=e.bbox.ur.x),e.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=e.bbox.ur.y),this.interiorRings.push(e)}this.multiPoly=e}getSweepEvents(){const t=this.exteriorRing.getSweepEvents();for(let e=0,n=this.interiorRings.length;e<n;e++){const n=this.interiorRings[e].getSweepEvents();for(let e=0,i=n.length;e<i;e++)t.push(n[e])}return t}},Fe=class{constructor(t,e){if(o(this,"isSubject"),o(this,"polys"),o(this,"bbox"),!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{"number"==typeof t[0][0][0]&&(t=[t])}catch(n){}this.polys=[],this.bbox={ll:{x:new ne(Number.POSITIVE_INFINITY),y:new ne(Number.POSITIVE_INFINITY)},ur:{x:new ne(Number.NEGATIVE_INFINITY),y:new ne(Number.NEGATIVE_INFINITY)}};for(let i=0,r=t.length;i<r;i++){const e=new Re(t[i],this);e.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=e.bbox.ll.x),e.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=e.bbox.ll.y),e.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=e.bbox.ur.x),e.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=e.bbox.ur.y),this.polys.push(e)}this.isSubject=e}getSweepEvents(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const n=this.polys[e].getSweepEvents();for(let e=0,i=n.length;e<i;e++)t.push(n[e])}return t}};ye.set;var Be=function(t,e={}){const n=[];if(H(t,t=>{n.push(t.coordinates)}),n.length<2)throw new Error("Must have at least 2 geometries");const i=((t,...e)=>Te.run("union",t,e))(n[0],...n.slice(1));return 0===i.length?null:1===i.length?T(i[0],e.properties):A(i,e.properties)};var Ge=function(t,e={}){const n=[];if(H(t,t=>{n.push(t.coordinates)}),n.length<2)throw new Error("Must specify at least 2 geometries");const i=((t,...e)=>Te.run("intersection",t,e))(n[0],...n.slice(1));return 0===i.length?null:1===i.length?T(i[0],e.properties):A(i,e.properties)};var ze=function(t){const e=[];if(H(t,t=>{e.push(t.coordinates)}),e.length<2)throw new Error("Must have at least two features");const n=t.features[0].properties||{},i=((t,...e)=>Te.run("difference",t,e))(e[0],...e.slice(1));return 0===i.length?null:1===i.length?T(i[0],n):A(i,n)};var He=function(t){const e=[];return"FeatureCollection"===t.type?z(t,function(t){G(t,function(n){e.push(N(n,t.properties))})}):"Feature"===t.type?G(t,function(n){e.push(N(n,t.properties))}):G(t,function(t){e.push(N(t))}),O(e)};function Ye(t,e={}){if(null!=t.bbox&&!0!==e.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return G(t,t=>{n[0]>t[0]&&(n[0]=t[0]),n[1]>t[1]&&(n[1]=t[1]),n[2]<t[0]&&(n[2]=t[0]),n[3]<t[1]&&(n[3]=t[1])}),n}var Ue,Xe={exports:{}};var qe=(Ue||(Ue=1,Xe.exports=function(){function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function e(t,e,n){return e=l(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,h()?Reflect.construct(e,n||[],l(t).constructor):e.apply(t,n))}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e,n){if(h())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,e);var r=new(t.bind.apply(t,i));return n&&c(r,n.prototype),r}function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,d(i.key),i)}}function o(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=p(t))||e){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return s=t.done,t},e:function(t){a=!0,o=t},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw o}}}}function a(){return a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=function(t,e){for(;!{}.hasOwnProperty.call(t,e)&&null!==(t=l(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(arguments.length<3?t:n):r.value}},a.apply(null,arguments)}function l(t){return(l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}function h(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(h=function(){return!!t})()}function c(t,e){return(c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function f(t,e,n,i){var r=a(l(1&i?t.prototype:t),e,n);return 2&i&&"function"==typeof r?function(t){return r.apply(n,t)}:r}function g(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||p(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e);if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}function p(e,n){if(e){if("string"==typeof e)return t(e,n);var i={}.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?t(e,n):void 0}}function y(t){var e="function"==typeof Map?new Map:void 0;return y=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return i(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,t)},y(t)}var m=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getEndCapStyle",value:function(){return this._endCapStyle}},{key:"isSingleSided",value:function(){return this._isSingleSided}},{key:"setQuadrantSegments",value:function(e){this._quadrantSegments=e,0===this._quadrantSegments&&(this._joinStyle=t.JOIN_BEVEL),this._quadrantSegments<0&&(this._joinStyle=t.JOIN_MITRE,this._mitreLimit=Math.abs(this._quadrantSegments)),e<=0&&(this._quadrantSegments=1),this._joinStyle!==t.JOIN_ROUND&&(this._quadrantSegments=t.DEFAULT_QUADRANT_SEGMENTS)}},{key:"getJoinStyle",value:function(){return this._joinStyle}},{key:"setJoinStyle",value:function(t){this._joinStyle=t}},{key:"setSimplifyFactor",value:function(t){this._simplifyFactor=t<0?0:t}},{key:"getSimplifyFactor",value:function(){return this._simplifyFactor}},{key:"getQuadrantSegments",value:function(){return this._quadrantSegments}},{key:"setEndCapStyle",value:function(t){this._endCapStyle=t}},{key:"getMitreLimit",value:function(){return this._mitreLimit}},{key:"setMitreLimit",value:function(t){this._mitreLimit=t}},{key:"setSingleSided",value:function(t){this._isSingleSided=t}}],[{key:"constructor_",value:function(){if(this._quadrantSegments=t.DEFAULT_QUADRANT_SEGMENTS,this._endCapStyle=t.CAP_ROUND,this._joinStyle=t.JOIN_ROUND,this._mitreLimit=t.DEFAULT_MITRE_LIMIT,this._isSingleSided=!1,this._simplifyFactor=t.DEFAULT_SIMPLIFY_FACTOR,0===arguments.length);else if(1===arguments.length){var e=arguments[0];this.setQuadrantSegments(e)}else if(2===arguments.length){var n=arguments[0],i=arguments[1];this.setQuadrantSegments(n),this.setEndCapStyle(i)}else if(4===arguments.length){var r=arguments[0],o=arguments[1],s=arguments[2],a=arguments[3];this.setQuadrantSegments(r),this.setEndCapStyle(o),this.setJoinStyle(s),this.setMitreLimit(a)}}},{key:"bufferDistanceError",value:function(t){var e=Math.PI/2/t;return 1-Math.cos(e/2)}}])}();m.CAP_ROUND=1,m.CAP_FLAT=2,m.CAP_SQUARE=3,m.JOIN_ROUND=1,m.JOIN_MITRE=2,m.JOIN_BEVEL=3,m.DEFAULT_QUADRANT_SEGMENTS=8,m.DEFAULT_MITRE_LIMIT=5,m.DEFAULT_SIMPLIFY_FACTOR=.01;var v=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({Exception:i})[0],r}return u(i,t),o(i,[{key:"toString",value:function(){return this.message}}])}(y(Error)),_=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({IllegalArgumentException:i})[0],r}return u(i,t),o(i)}(v),k=o(function t(){n(this,t)},[{key:"filter",value:function(t){}}]);function x(){}function E(){}function w(){}var M,P,b,I,S,L,C,N,T=o(function t(){n(this,t)},null,[{key:"equalsWithTolerance",value:function(t,e,n){return Math.abs(t-e)<=n}}]),D=o(function t(e,i){n(this,t),this.low=i||0,this.high=e||0},null,[{key:"toBinaryString",value:function(t){var e,n="";for(e=2147483648;e>0;e>>>=1)n+=(t.high&e)===e?"1":"0";for(e=2147483648;e>0;e>>>=1)n+=(t.low&e)===e?"1":"0";return n}}]);function O(){}function A(){}O.NaN=NaN,O.isNaN=function(t){return Number.isNaN(t)},O.isInfinite=function(t){return!Number.isFinite(t)},O.MAX_VALUE=Number.MAX_VALUE,O.POSITIVE_INFINITY=Number.POSITIVE_INFINITY,O.NEGATIVE_INFINITY=Number.NEGATIVE_INFINITY,"function"==typeof Float64Array&&"function"==typeof Int32Array?(L=2146435072,C=new Float64Array(1),N=new Int32Array(C.buffer),O.doubleToLongBits=function(t){C[0]=t;var e=0|N[0],n=0|N[1];return(n&L)===L&&1048575&n&&0!==e&&(e=0,n=2146959360),new D(n,e)},O.longBitsToDouble=function(t){return N[0]=t.low,N[1]=t.high,C[0]}):(M=1023,P=Math.log2,b=Math.floor,I=Math.pow,S=function(){for(var t=53;t>0;t--){var e=I(2,t)-1;if(b(P(e))+1===t)return e}return 0}(),O.doubleToLongBits=function(t){var e,n,i,r,o,s,a,l,u;if(t<0||1/t===Number.NEGATIVE_INFINITY?(s=1<<31,t=-t):s=0,0===t)return new D(l=s,u=0);if(t===1/0)return new D(l=2146435072|s,u=0);if(t!=t)return new D(l=2146959360,u=0);if(r=0,u=0,(e=b(t))>1)if(e<=S)(r=b(P(e)))<=20?(u=0,l=e<<20-r&1048575):(u=e%(n=I(2,i=r-20))<<32-i,l=e/n&1048575);else for(i=e,u=0;0!==(i=b(n=i/2));)r++,u>>>=1,u|=(1&l)<<31,l>>>=1,n!==i&&(l|=524288);if(a=r+M,o=0===e,e=t-e,r<52&&0!==e)for(i=0;;){if((n=2*e)>=1?(e=n-1,o?(a--,o=!1):(i<<=1,i|=1,r++)):(e=n,o?0==--a&&(r++,o=!1):(i<<=1,r++)),20===r)l|=i,i=0;else if(52===r){u|=i;break}if(1===n){r<20?l|=i<<20-r:r<52&&(u|=i<<52-r);break}}return l|=a<<20,new D(l|=s,u)},O.longBitsToDouble=function(t){var e,n,i,r,o=t.high,s=t.low,a=o&1<<31?-1:1;for(i=((2146435072&o)>>20)-M,r=0,n=1<<19,e=1;e<=20;e++)o&n&&(r+=I(2,-e)),n>>>=1;for(n=1<<31,e=21;e<=52;e++)s&n&&(r+=I(2,-e)),n>>>=1;if(-1023===i){if(0===r)return 0*a;i=-1022}else{if(1024===i)return 0===r?a/0:NaN;r+=1}return a*r*I(2,i)});var R=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({RuntimeException:i})[0],r}return u(i,t),o(i)}(v),F=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,null,[{key:"constructor_",value:function(){if(0===arguments.length)R.constructor_.call(this);else if(1===arguments.length){var t=arguments[0];R.constructor_.call(this,t)}}}])}(R),B=function(){function t(){n(this,t)}return o(t,null,[{key:"shouldNeverReachHere",value:function(){if(0===arguments.length)t.shouldNeverReachHere(null);else if(1===arguments.length){var e=arguments[0];throw new F("Should never reach here"+(null!==e?": "+e:""))}}},{key:"isTrue",value:function(){if(1===arguments.length){var e=arguments[0];t.isTrue(e,null)}else if(2===arguments.length){var n=arguments[1];if(!arguments[0])throw null===n?new F:new F(n)}}},{key:"equals",value:function(){if(2===arguments.length){var e=arguments[0],n=arguments[1];t.equals(e,n,null)}else if(3===arguments.length){var i=arguments[0],r=arguments[1],o=arguments[2];if(!r.equals(i))throw new F("Expected "+i+" but encountered "+r+(null!==o?": "+o:""))}}}])}(),G=new ArrayBuffer(8),z=new Float64Array(G),H=new Int32Array(G),Y=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getM",value:function(){return O.NaN}},{key:"setOrdinate",value:function(e,n){switch(e){case t.X:this.x=n;break;case t.Y:this.y=n;break;case t.Z:this.setZ(n);break;default:throw new _("Invalid ordinate index: "+e)}}},{key:"equals2D",value:function(){if(1===arguments.length){var t=arguments[0];return this.x===t.x&&this.y===t.y}if(2===arguments.length){var e=arguments[0],n=arguments[1];return!!T.equalsWithTolerance(this.x,e.x,n)&&!!T.equalsWithTolerance(this.y,e.y,n)}}},{key:"setM",value:function(e){throw new _("Invalid ordinate index: "+t.M)}},{key:"getZ",value:function(){return this.z}},{key:"getOrdinate",value:function(e){switch(e){case t.X:return this.x;case t.Y:return this.y;case t.Z:return this.getZ()}throw new _("Invalid ordinate index: "+e)}},{key:"equals3D",value:function(t){return this.x===t.x&&this.y===t.y&&(this.getZ()===t.getZ()||O.isNaN(this.getZ())&&O.isNaN(t.getZ()))}},{key:"equals",value:function(e){return e instanceof t&&this.equals2D(e)}},{key:"equalInZ",value:function(t,e){return T.equalsWithTolerance(this.getZ(),t.getZ(),e)}},{key:"setX",value:function(t){this.x=t}},{key:"compareTo",value:function(t){var e=t;return this.x<e.x?-1:this.x>e.x?1:this.y<e.y?-1:this.y>e.y?1:0}},{key:"getX",value:function(){return this.x}},{key:"setZ",value:function(t){this.z=t}},{key:"clone",value:function(){try{return null}catch(t){if(t instanceof CloneNotSupportedException)return B.shouldNeverReachHere("this shouldn't happen because this class is Cloneable"),null;throw t}}},{key:"copy",value:function(){return new t(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+", "+this.getZ()+")"}},{key:"distance3D",value:function(t){var e=this.x-t.x,n=this.y-t.y,i=this.getZ()-t.getZ();return Math.sqrt(e*e+n*n+i*i)}},{key:"getY",value:function(){return this.y}},{key:"setY",value:function(t){this.y=t}},{key:"distance",value:function(t){var e=this.x-t.x,n=this.y-t.y;return Math.sqrt(e*e+n*n)}},{key:"hashCode",value:function(){var e=17;return 37*(e=37*e+t.hashCode(this.x))+t.hashCode(this.y)}},{key:"setCoordinate",value:function(t){this.x=t.x,this.y=t.y,this.z=t.getZ()}},{key:"interfaces_",get:function(){return[x,E,w]}}],[{key:"constructor_",value:function(){if(this.x=null,this.y=null,this.z=null,0===arguments.length)t.constructor_.call(this,0,0);else if(1===arguments.length){var e=arguments[0];t.constructor_.call(this,e.x,e.y,e.getZ())}else if(2===arguments.length){var n=arguments[0],i=arguments[1];t.constructor_.call(this,n,i,t.NULL_ORDINATE)}else if(3===arguments.length){var r=arguments[0],o=arguments[1],s=arguments[2];this.x=r,this.y=o,this.z=s}}},{key:"hashCode",value:function(t){return z[0]=t,H[0]^H[1]}}])}(),U=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"compare",value:function(e,n){var i=t.compare(e.x,n.x);if(0!==i)return i;var r=t.compare(e.y,n.y);return 0!==r?r:this._dimensionsToTest<=2?0:t.compare(e.getZ(),n.getZ())}},{key:"interfaces_",get:function(){return[A]}}],[{key:"constructor_",value:function(){if(this._dimensionsToTest=2,0===arguments.length)t.constructor_.call(this,2);else if(1===arguments.length){var e=arguments[0];if(2!==e&&3!==e)throw new _("only 2 or 3 dimensions may be specified");this._dimensionsToTest=e}}},{key:"compare",value:function(t,e){return t<e?-1:t>e?1:O.isNaN(t)?O.isNaN(e)?0:-1:O.isNaN(e)?1:0}}])}();Y.DimensionalComparator=U,Y.NULL_ORDINATE=O.NaN,Y.X=0,Y.Y=1,Y.Z=2,Y.M=3;var X=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getArea",value:function(){return this.getWidth()*this.getHeight()}},{key:"equals",value:function(e){if(!(e instanceof t))return!1;var n=e;return this.isNull()?n.isNull():this._maxx===n.getMaxX()&&this._maxy===n.getMaxY()&&this._minx===n.getMinX()&&this._miny===n.getMinY()}},{key:"intersection",value:function(e){if(this.isNull()||e.isNull()||!this.intersects(e))return new t;var n=this._minx>e._minx?this._minx:e._minx,i=this._miny>e._miny?this._miny:e._miny;return new t(n,this._maxx<e._maxx?this._maxx:e._maxx,i,this._maxy<e._maxy?this._maxy:e._maxy)}},{key:"isNull",value:function(){return this._maxx<this._minx}},{key:"getMaxX",value:function(){return this._maxx}},{key:"covers",value:function(){if(1===arguments.length){if(arguments[0]instanceof Y){var e=arguments[0];return this.covers(e.x,e.y)}if(arguments[0]instanceof t){var n=arguments[0];return!this.isNull()&&!n.isNull()&&n.getMinX()>=this._minx&&n.getMaxX()<=this._maxx&&n.getMinY()>=this._miny&&n.getMaxY()<=this._maxy}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];return!this.isNull()&&i>=this._minx&&i<=this._maxx&&r>=this._miny&&r<=this._maxy}}},{key:"intersects",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return!this.isNull()&&!e.isNull()&&!(e._minx>this._maxx||e._maxx<this._minx||e._miny>this._maxy||e._maxy<this._miny)}if(arguments[0]instanceof Y){var n=arguments[0];return this.intersects(n.x,n.y)}}else if(2===arguments.length){if(arguments[0]instanceof Y&&arguments[1]instanceof Y){var i=arguments[0],r=arguments[1];return!(this.isNull()||(i.x<r.x?i.x:r.x)>this._maxx||(i.x>r.x?i.x:r.x)<this._minx||(i.y<r.y?i.y:r.y)>this._maxy||(i.y>r.y?i.y:r.y)<this._miny)}if("number"==typeof arguments[0]&&"number"==typeof arguments[1]){var o=arguments[0],s=arguments[1];return!this.isNull()&&!(o>this._maxx||o<this._minx||s>this._maxy||s<this._miny)}}}},{key:"getMinY",value:function(){return this._miny}},{key:"getDiameter",value:function(){if(this.isNull())return 0;var t=this.getWidth(),e=this.getHeight();return Math.sqrt(t*t+e*e)}},{key:"getMinX",value:function(){return this._minx}},{key:"expandToInclude",value:function(){if(1===arguments.length){if(arguments[0]instanceof Y){var e=arguments[0];this.expandToInclude(e.x,e.y)}else if(arguments[0]instanceof t){var n=arguments[0];if(n.isNull())return null;this.isNull()?(this._minx=n.getMinX(),this._maxx=n.getMaxX(),this._miny=n.getMinY(),this._maxy=n.getMaxY()):(n._minx<this._minx&&(this._minx=n._minx),n._maxx>this._maxx&&(this._maxx=n._maxx),n._miny<this._miny&&(this._miny=n._miny),n._maxy>this._maxy&&(this._maxy=n._maxy))}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this.isNull()?(this._minx=i,this._maxx=i,this._miny=r,this._maxy=r):(i<this._minx&&(this._minx=i),i>this._maxx&&(this._maxx=i),r<this._miny&&(this._miny=r),r>this._maxy&&(this._maxy=r))}}},{key:"minExtent",value:function(){if(this.isNull())return 0;var t=this.getWidth(),e=this.getHeight();return t<e?t:e}},{key:"getWidth",value:function(){return this.isNull()?0:this._maxx-this._minx}},{key:"compareTo",value:function(t){var e=t;return this.isNull()?e.isNull()?0:-1:e.isNull()?1:this._minx<e._minx?-1:this._minx>e._minx?1:this._miny<e._miny?-1:this._miny>e._miny?1:this._maxx<e._maxx?-1:this._maxx>e._maxx?1:this._maxy<e._maxy?-1:this._maxy>e._maxy?1:0}},{key:"translate",value:function(t,e){if(this.isNull())return null;this.init(this.getMinX()+t,this.getMaxX()+t,this.getMinY()+e,this.getMaxY()+e)}},{key:"copy",value:function(){return new t(this)}},{key:"toString",value:function(){return"Env["+this._minx+" : "+this._maxx+", "+this._miny+" : "+this._maxy+"]"}},{key:"setToNull",value:function(){this._minx=0,this._maxx=-1,this._miny=0,this._maxy=-1}},{key:"disjoint",value:function(t){return!(!this.isNull()&&!t.isNull())||t._minx>this._maxx||t._maxx<this._minx||t._miny>this._maxy||t._maxy<this._miny}},{key:"getHeight",value:function(){return this.isNull()?0:this._maxy-this._miny}},{key:"maxExtent",value:function(){if(this.isNull())return 0;var t=this.getWidth(),e=this.getHeight();return t>e?t:e}},{key:"expandBy",value:function(){if(1===arguments.length){var t=arguments[0];this.expandBy(t,t)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];if(this.isNull())return null;this._minx-=e,this._maxx+=e,this._miny-=n,this._maxy+=n,(this._minx>this._maxx||this._miny>this._maxy)&&this.setToNull()}}},{key:"contains",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return this.covers(e)}if(arguments[0]instanceof Y){var n=arguments[0];return this.covers(n)}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];return this.covers(i,r)}}},{key:"centre",value:function(){return this.isNull()?null:new Y((this.getMinX()+this.getMaxX())/2,(this.getMinY()+this.getMaxY())/2)}},{key:"init",value:function(){if(0===arguments.length)this.setToNull();else if(1===arguments.length){if(arguments[0]instanceof Y){var e=arguments[0];this.init(e.x,e.x,e.y,e.y)}else if(arguments[0]instanceof t){var n=arguments[0];this._minx=n._minx,this._maxx=n._maxx,this._miny=n._miny,this._maxy=n._maxy}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this.init(i.x,r.x,i.y,r.y)}else if(4===arguments.length){var o=arguments[0],s=arguments[1],a=arguments[2],l=arguments[3];o<s?(this._minx=o,this._maxx=s):(this._minx=s,this._maxx=o),a<l?(this._miny=a,this._maxy=l):(this._miny=l,this._maxy=a)}}},{key:"getMaxY",value:function(){return this._maxy}},{key:"distance",value:function(t){if(this.intersects(t))return 0;var e=0;this._maxx<t._minx?e=t._minx-this._maxx:this._minx>t._maxx&&(e=this._minx-t._maxx);var n=0;return this._maxy<t._miny?n=t._miny-this._maxy:this._miny>t._maxy&&(n=this._miny-t._maxy),0===e?n:0===n?e:Math.sqrt(e*e+n*n)}},{key:"hashCode",value:function(){var t=17;return 37*(t=37*(t=37*(t=37*t+Y.hashCode(this._minx))+Y.hashCode(this._maxx))+Y.hashCode(this._miny))+Y.hashCode(this._maxy)}},{key:"interfaces_",get:function(){return[x,w]}}],[{key:"constructor_",value:function(){if(this._minx=null,this._maxx=null,this._miny=null,this._maxy=null,0===arguments.length)this.init();else if(1===arguments.length){if(arguments[0]instanceof Y){var e=arguments[0];this.init(e.x,e.x,e.y,e.y)}else if(arguments[0]instanceof t){var n=arguments[0];this.init(n)}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this.init(i.x,r.x,i.y,r.y)}else if(4===arguments.length){var o=arguments[0],s=arguments[1],a=arguments[2],l=arguments[3];this.init(o,s,a,l)}}},{key:"intersects",value:function(){if(3===arguments.length){var t=arguments[0],e=arguments[1],n=arguments[2];return n.x>=(t.x<e.x?t.x:e.x)&&n.x<=(t.x>e.x?t.x:e.x)&&n.y>=(t.y<e.y?t.y:e.y)&&n.y<=(t.y>e.y?t.y:e.y)}if(4===arguments.length){var i=arguments[0],r=arguments[1],o=arguments[2],s=arguments[3],a=Math.min(o.x,s.x),l=Math.max(o.x,s.x),u=Math.min(i.x,r.x),h=Math.max(i.x,r.x);return!(u>l||h<a||(a=Math.min(o.y,s.y),l=Math.max(o.y,s.y),u=Math.min(i.y,r.y),h=Math.max(i.y,r.y),u>l||h<a))}}}])}(),q=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"isGeometryCollection",value:function(){return this.getTypeCode()===t.TYPECODE_GEOMETRYCOLLECTION}},{key:"getFactory",value:function(){return this._factory}},{key:"getGeometryN",value:function(t){return this}},{key:"getArea",value:function(){return 0}},{key:"isRectangle",value:function(){return!1}},{key:"equalsExact",value:function(t){return this===t||this.equalsExact(t,0)}},{key:"geometryChanged",value:function(){this.apply(t.geometryChangedFilter)}},{key:"geometryChangedAction",value:function(){this._envelope=null}},{key:"equalsNorm",value:function(t){return null!==t&&this.norm().equalsExact(t.norm())}},{key:"getLength",value:function(){return 0}},{key:"getNumGeometries",value:function(){return 1}},{key:"compareTo",value:function(){var t;if(1===arguments.length){var e=arguments[0];return t=e,this.getTypeCode()!==t.getTypeCode()?this.getTypeCode()-t.getTypeCode():this.isEmpty()&&t.isEmpty()?0:this.isEmpty()?-1:t.isEmpty()?1:this.compareToSameClass(e)}if(2===arguments.length){var n=arguments[0],i=arguments[1];return t=n,this.getTypeCode()!==t.getTypeCode()?this.getTypeCode()-t.getTypeCode():this.isEmpty()&&t.isEmpty()?0:this.isEmpty()?-1:t.isEmpty()?1:this.compareToSameClass(n,i)}}},{key:"getUserData",value:function(){return this._userData}},{key:"getSRID",value:function(){return this._SRID}},{key:"getEnvelope",value:function(){return this.getFactory().toGeometry(this.getEnvelopeInternal())}},{key:"checkNotGeometryCollection",value:function(e){if(e.getTypeCode()===t.TYPECODE_GEOMETRYCOLLECTION)throw new _("This method does not support GeometryCollection arguments")}},{key:"equal",value:function(t,e,n){return 0===n?t.equals(e):t.distance(e)<=n}},{key:"norm",value:function(){var t=this.copy();return t.normalize(),t}},{key:"reverse",value:function(){var t=this.reverseInternal();return null!=this.envelope&&(t.envelope=this.envelope.copy()),t.setSRID(this.getSRID()),t}},{key:"copy",value:function(){var t=this.copyInternal();return t.envelope=null==this._envelope?null:this._envelope.copy(),t._SRID=this._SRID,t._userData=this._userData,t}},{key:"getPrecisionModel",value:function(){return this._factory.getPrecisionModel()}},{key:"getEnvelopeInternal",value:function(){return null===this._envelope&&(this._envelope=this.computeEnvelopeInternal()),new X(this._envelope)}},{key:"setSRID",value:function(t){this._SRID=t}},{key:"setUserData",value:function(t){this._userData=t}},{key:"compare",value:function(t,e){for(var n=t.iterator(),i=e.iterator();n.hasNext()&&i.hasNext();){var r=n.next(),o=i.next(),s=r.compareTo(o);if(0!==s)return s}return n.hasNext()?1:i.hasNext()?-1:0}},{key:"hashCode",value:function(){return this.getEnvelopeInternal().hashCode()}},{key:"isEquivalentClass",value:function(t){return this.getClass()===t.getClass()}},{key:"isGeometryCollectionOrDerived",value:function(){return this.getTypeCode()===t.TYPECODE_GEOMETRYCOLLECTION||this.getTypeCode()===t.TYPECODE_MULTIPOINT||this.getTypeCode()===t.TYPECODE_MULTILINESTRING||this.getTypeCode()===t.TYPECODE_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[E,x,w]}},{key:"getClass",value:function(){return t}}],[{key:"hasNonEmptyElements",value:function(t){for(var e=0;e<t.length;e++)if(!t[e].isEmpty())return!0;return!1}},{key:"hasNullElements",value:function(t){for(var e=0;e<t.length;e++)if(null===t[e])return!0;return!1}}])}();q.constructor_=function(t){t&&(this._envelope=null,this._userData=null,this._factory=t,this._SRID=t.getSRID())},q.TYPECODE_POINT=0,q.TYPECODE_MULTIPOINT=1,q.TYPECODE_LINESTRING=2,q.TYPECODE_LINEARRING=3,q.TYPECODE_MULTILINESTRING=4,q.TYPECODE_POLYGON=5,q.TYPECODE_MULTIPOLYGON=6,q.TYPECODE_GEOMETRYCOLLECTION=7,q.TYPENAME_POINT="Point",q.TYPENAME_MULTIPOINT="MultiPoint",q.TYPENAME_LINESTRING="LineString",q.TYPENAME_LINEARRING="LinearRing",q.TYPENAME_MULTILINESTRING="MultiLineString",q.TYPENAME_POLYGON="Polygon",q.TYPENAME_MULTIPOLYGON="MultiPolygon",q.TYPENAME_GEOMETRYCOLLECTION="GeometryCollection",q.geometryChangedFilter={get interfaces_(){return[k]},filter:function(t){t.geometryChangedAction()}};var V=function(){function t(){n(this,t)}return o(t,null,[{key:"toLocationSymbol",value:function(e){switch(e){case t.EXTERIOR:return"e";case t.BOUNDARY:return"b";case t.INTERIOR:return"i";case t.NONE:return"-"}throw new _("Unknown location value: "+e)}}])}();V.INTERIOR=0,V.BOUNDARY=1,V.EXTERIOR=2,V.NONE=-1;var j=o(function t(){n(this,t)},[{key:"add",value:function(){}},{key:"addAll",value:function(){}},{key:"isEmpty",value:function(){}},{key:"iterator",value:function(){}},{key:"size",value:function(){}},{key:"toArray",value:function(){}},{key:"remove",value:function(){}}]),K=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({NoSuchElementException:i})[0],r}return u(i,t),o(i)}(v),W=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({UnsupportedOperationException:i})[0],r}return u(i,t),o(i)}(v),Z=function(t){function i(){return n(this,i),e(this,i,arguments)}return u(i,t),o(i,[{key:"contains",value:function(){}}])}(j),J=function(t){function i(t){var r;return n(this,i),(r=e(this,i)).map=new Map,t instanceof j&&r.addAll(t),r}return u(i,t),o(i,[{key:"contains",value:function(t){var e=t.hashCode?t.hashCode():t;return!!this.map.has(e)}},{key:"add",value:function(t){var e=t.hashCode?t.hashCode():t;return!this.map.has(e)&&!!this.map.set(e,t)}},{key:"addAll",value:function(t){var e,n=s(t);try{for(n.s();!(e=n.n()).done;){var i=e.value;this.add(i)}}catch(r){n.e(r)}finally{n.f()}return!0}},{key:"remove",value:function(){throw new W}},{key:"size",value:function(){return this.map.size}},{key:"isEmpty",value:function(){return 0===this.map.size}},{key:"toArray",value:function(){return Array.from(this.map.values())}},{key:"iterator",value:function(){return new $(this.map)}},{key:Symbol.iterator,value:function(){return this.map}}])}(Z),$=o(function t(e){n(this,t),this.iterator=e.values();var i=this.iterator.next(),r=i.done,o=i.value;this.done=r,this.value=o},[{key:"next",value:function(){if(this.done)throw new K;var t=this.value,e=this.iterator.next(),n=e.done,i=e.value;return this.done=n,this.value=i,t}},{key:"hasNext",value:function(){return!this.done}},{key:"remove",value:function(){throw new W}}]),Q=function(){function t(){n(this,t)}return o(t,null,[{key:"opposite",value:function(e){return e===t.LEFT?t.RIGHT:e===t.RIGHT?t.LEFT:e}}])}();Q.ON=0,Q.LEFT=1,Q.RIGHT=2;var tt=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({EmptyStackException:i})[0],r}return u(i,t),o(i)}(v),et=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({IndexOutOfBoundsException:i})[0],r}return u(i,t),o(i)}(v),nt=function(t){function i(){return n(this,i),e(this,i,arguments)}return u(i,t),o(i,[{key:"get",value:function(){}},{key:"set",value:function(){}},{key:"isEmpty",value:function(){}}])}(j),it=function(t){function i(){var t;return n(this,i),(t=e(this,i)).array=[],t}return u(i,t),o(i,[{key:"add",value:function(t){return this.array.push(t),!0}},{key:"get",value:function(t){if(t<0||t>=this.size())throw new et;return this.array[t]}},{key:"push",value:function(t){return this.array.push(t),t}},{key:"pop",value:function(){if(0===this.array.length)throw new tt;return this.array.pop()}},{key:"peek",value:function(){if(0===this.array.length)throw new tt;return this.array[this.array.length-1]}},{key:"empty",value:function(){return 0===this.array.length}},{key:"isEmpty",value:function(){return this.empty()}},{key:"search",value:function(t){return this.array.indexOf(t)}},{key:"size",value:function(){return this.array.length}},{key:"toArray",value:function(){return this.array.slice()}}])}(nt);function rt(t,e){return t.interfaces_&&t.interfaces_.indexOf(e)>-1}var ot=o(function t(e){n(this,t),this.str=e},[{key:"append",value:function(t){this.str+=t}},{key:"setCharAt",value:function(t,e){this.str=this.str.substr(0,t)+e+this.str.substr(t+1)}},{key:"toString",value:function(){return this.str}}]),st=function(){function t(e){n(this,t),this.value=e}return o(t,[{key:"intValue",value:function(){return this.value}},{key:"compareTo",value:function(t){return this.value<t?-1:this.value>t?1:0}}],[{key:"compare",value:function(t,e){return t<e?-1:t>e?1:0}},{key:"isNan",value:function(t){return Number.isNaN(t)}},{key:"valueOf",value:function(e){return new t(e)}}])}(),at=o(function t(){n(this,t)},null,[{key:"isWhitespace",value:function(t){return t<=32&&t>=0||127===t}},{key:"toUpperCase",value:function(t){return t.toUpperCase()}}]),lt=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"le",value:function(t){return this._hi<t._hi||this._hi===t._hi&&this._lo<=t._lo}},{key:"extractSignificantDigits",value:function(e,n){var i=this.abs(),r=t.magnitude(i._hi),o=t.TEN.pow(r);(i=i.divide(o)).gt(t.TEN)?(i=i.divide(t.TEN),r+=1):i.lt(t.ONE)&&(i=i.multiply(t.TEN),r-=1);for(var s=r+1,a=new ot,l=t.MAX_PRINT_DIGITS-1,u=0;u<=l;u++){e&&u===s&&a.append(".");var h=Math.trunc(i._hi);if(h<0)break;var c=!1,f=0;h>9?(c=!0,f="9"):f="0"+h,a.append(f),i=i.subtract(t.valueOf(h)).multiply(t.TEN),c&&i.selfAdd(t.TEN);var g=!0,d=t.magnitude(i._hi);if(d<0&&Math.abs(d)>=l-u&&(g=!1),!g)break}return n[0]=r,a.toString()}},{key:"sqr",value:function(){return this.multiply(this)}},{key:"doubleValue",value:function(){return this._hi+this._lo}},{key:"subtract",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return this.add(e.negate())}if("number"==typeof arguments[0]){var n=arguments[0];return this.add(-n)}}},{key:"equals",value:function(){if(1===arguments.length&&arguments[0]instanceof t){var e=arguments[0];return this._hi===e._hi&&this._lo===e._lo}}},{key:"isZero",value:function(){return 0===this._hi&&0===this._lo}},{key:"selfSubtract",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return this.isNaN()?this:this.selfAdd(-e._hi,-e._lo)}if("number"==typeof arguments[0]){var n=arguments[0];return this.isNaN()?this:this.selfAdd(-n,0)}}},{key:"getSpecialNumberString",value:function(){return this.isZero()?"0.0":this.isNaN()?"NaN ":null}},{key:"min",value:function(t){return this.le(t)?this:t}},{key:"selfDivide",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return this.selfDivide(e._hi,e._lo)}if("number"==typeof arguments[0]){var n=arguments[0];return this.selfDivide(n,0)}}else if(2===arguments.length){var i,r,o,s,a=arguments[0],l=arguments[1],u=null,h=null,c=null,f=null;return o=this._hi/a,f=(u=(c=t.SPLIT*o)-(u=c-o))*(h=(f=t.SPLIT*a)-(h=f-a))-(s=o*a)+u*(r=a-h)+(i=o-u)*h+i*r,f=o+(c=(this._hi-s-f+this._lo-o*l)/a),this._hi=f,this._lo=o-f+c,this}}},{key:"dump",value:function(){return"DD<"+this._hi+", "+this._lo+">"}},{key:"divide",value:function(){if(arguments[0]instanceof t){var e,n,i,r,o=arguments[0],s=null,a=null,l=null,u=null;return e=(i=this._hi/o._hi)-(s=(l=t.SPLIT*i)-(s=l-i)),u=s*(a=(u=t.SPLIT*o._hi)-(a=u-o._hi))-(r=i*o._hi)+s*(n=o._hi-a)+e*a+e*n,new t(u=i+(l=(this._hi-r-u+this._lo-i*o._lo)/o._hi),i-u+l)}if("number"==typeof arguments[0]){var h=arguments[0];return O.isNaN(h)?t.createNaN():t.copy(this).selfDivide(h,0)}}},{key:"ge",value:function(t){return this._hi>t._hi||this._hi===t._hi&&this._lo>=t._lo}},{key:"pow",value:function(e){if(0===e)return t.valueOf(1);var n=new t(this),i=t.valueOf(1),r=Math.abs(e);if(r>1)for(;r>0;)r%2==1&&i.selfMultiply(n),(r/=2)>0&&(n=n.sqr());else i=n;return e<0?i.reciprocal():i}},{key:"ceil",value:function(){if(this.isNaN())return t.NaN;var e=Math.ceil(this._hi),n=0;return e===this._hi&&(n=Math.ceil(this._lo)),new t(e,n)}},{key:"compareTo",value:function(t){var e=t;return this._hi<e._hi?-1:this._hi>e._hi?1:this._lo<e._lo?-1:this._lo>e._lo?1:0}},{key:"rint",value:function(){return this.isNaN()?this:this.add(.5).floor()}},{key:"setValue",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return this.init(e),this}if("number"==typeof arguments[0]){var n=arguments[0];return this.init(n),this}}},{key:"max",value:function(t){return this.ge(t)?this:t}},{key:"sqrt",value:function(){if(this.isZero())return t.valueOf(0);if(this.isNegative())return t.NaN;var e=1/Math.sqrt(this._hi),n=this._hi*e,i=t.valueOf(n),r=this.subtract(i.sqr())._hi*(.5*e);return i.add(r)}},{key:"selfAdd",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return this.selfAdd(e._hi,e._lo)}if("number"==typeof arguments[0]){var n,i,r,o,s,a=arguments[0],l=null;return l=(r=this._hi+a)-(o=r-this._hi),i=(s=(l=a-o+(this._hi-l))+this._lo)+(r-(n=r+s)),this._hi=n+i,this._lo=i+(n-this._hi),this}}else if(2===arguments.length){var u,h,c,f,g=arguments[0],d=arguments[1],p=null,y=null,m=null;c=this._hi+g,h=this._lo+d,y=c-(m=c-this._hi),p=h-(f=h-this._lo);var v=(u=c+(m=(y=g-m+(this._hi-y))+h))+(m=(p=d-f+(this._lo-p))+(m+(c-u))),_=m+(u-v);return this._hi=v,this._lo=_,this}}},{key:"selfMultiply",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return this.selfMultiply(e._hi,e._lo)}if("number"==typeof arguments[0]){var n=arguments[0];return this.selfMultiply(n,0)}}else if(2===arguments.length){var i,r,o=arguments[0],s=arguments[1],a=null,l=null,u=null,h=null;a=(u=t.SPLIT*this._hi)-this._hi,h=t.SPLIT*o,a=u-a,i=this._hi-a,l=h-o;var c=(u=this._hi*o)+(h=a*(l=h-l)-u+a*(r=o-l)+i*l+i*r+(this._hi*s+this._lo*o)),f=h+(a=u-c);return this._hi=c,this._lo=f,this}}},{key:"selfSqr",value:function(){return this.selfMultiply(this)}},{key:"floor",value:function(){if(this.isNaN())return t.NaN;var e=Math.floor(this._hi),n=0;return e===this._hi&&(n=Math.floor(this._lo)),new t(e,n)}},{key:"negate",value:function(){return this.isNaN()?this:new t(-this._hi,-this._lo)}},{key:"clone",value:function(){try{return null}catch(t){if(t instanceof CloneNotSupportedException)return null;throw t}}},{key:"multiply",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return e.isNaN()?t.createNaN():t.copy(this).selfMultiply(e)}if("number"==typeof arguments[0]){var n=arguments[0];return O.isNaN(n)?t.createNaN():t.copy(this).selfMultiply(n,0)}}},{key:"isNaN",value:function(){return O.isNaN(this._hi)}},{key:"intValue",value:function(){return Math.trunc(this._hi)}},{key:"toString",value:function(){var e=t.magnitude(this._hi);return e>=-3&&e<=20?this.toStandardNotation():this.toSciNotation()}},{key:"toStandardNotation",value:function(){var e=this.getSpecialNumberString();if(null!==e)return e;var n=new Array(1).fill(null),i=this.extractSignificantDigits(!0,n),r=n[0]+1,o=i;if("."===i.charAt(0))o="0"+i;else if(r<0)o="0."+t.stringOfChar("0",-r)+i;else if(-1===i.indexOf(".")){var s=r-i.length;o=i+t.stringOfChar("0",s)+".0"}return this.isNegative()?"-"+o:o}},{key:"reciprocal",value:function(){var e,n,i,r,o=null,s=null,a=null,l=null;e=(i=1/this._hi)-(o=(a=t.SPLIT*i)-(o=a-i)),s=(l=t.SPLIT*this._hi)-this._hi;var u=i+(a=(1-(r=i*this._hi)-(l=o*(s=l-s)-r+o*(n=this._hi-s)+e*s+e*n)-i*this._lo)/this._hi);return new t(u,i-u+a)}},{key:"toSciNotation",value:function(){if(this.isZero())return t.SCI_NOT_ZERO;var e=this.getSpecialNumberString();if(null!==e)return e;var n=new Array(1).fill(null),i=this.extractSignificantDigits(!1,n),r=t.SCI_NOT_EXPONENT_CHAR+n[0];if("0"===i.charAt(0))throw new IllegalStateException("Found leading zero: "+i);var o="";i.length>1&&(o=i.substring(1));var s=i.charAt(0)+"."+o;return this.isNegative()?"-"+s+r:s+r}},{key:"abs",value:function(){return this.isNaN()?t.NaN:this.isNegative()?this.negate():new t(this)}},{key:"isPositive",value:function(){return this._hi>0||0===this._hi&&this._lo>0}},{key:"lt",value:function(t){return this._hi<t._hi||this._hi===t._hi&&this._lo<t._lo}},{key:"add",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return t.copy(this).selfAdd(e)}if("number"==typeof arguments[0]){var n=arguments[0];return t.copy(this).selfAdd(n)}}},{key:"init",value:function(){if(1===arguments.length){if("number"==typeof arguments[0]){var e=arguments[0];this._hi=e,this._lo=0}else if(arguments[0]instanceof t){var n=arguments[0];this._hi=n._hi,this._lo=n._lo}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this._hi=i,this._lo=r}}},{key:"gt",value:function(t){return this._hi>t._hi||this._hi===t._hi&&this._lo>t._lo}},{key:"isNegative",value:function(){return this._hi<0||0===this._hi&&this._lo<0}},{key:"trunc",value:function(){return this.isNaN()?t.NaN:this.isPositive()?this.floor():this.ceil()}},{key:"signum",value:function(){return this._hi>0?1:this._hi<0?-1:this._lo>0?1:this._lo<0?-1:0}},{key:"interfaces_",get:function(){return[w,x,E]}}],[{key:"constructor_",value:function(){if(this._hi=0,this._lo=0,0===arguments.length)this.init(0);else if(1===arguments.length){if("number"==typeof arguments[0]){var e=arguments[0];this.init(e)}else if(arguments[0]instanceof t){var n=arguments[0];this.init(n)}else if("string"==typeof arguments[0]){var i=arguments[0];t.constructor_.call(this,t.parse(i))}}else if(2===arguments.length){var r=arguments[0],o=arguments[1];this.init(r,o)}}},{key:"determinant",value:function(){if("number"==typeof arguments[3]&&"number"==typeof arguments[2]&&"number"==typeof arguments[0]&&"number"==typeof arguments[1]){var e=arguments[0],n=arguments[1],i=arguments[2],r=arguments[3];return t.determinant(t.valueOf(e),t.valueOf(n),t.valueOf(i),t.valueOf(r))}if(arguments[3]instanceof t&&arguments[2]instanceof t&&arguments[0]instanceof t&&arguments[1]instanceof t){var o=arguments[1],s=arguments[2],a=arguments[3];return arguments[0].multiply(a).selfSubtract(o.multiply(s))}}},{key:"sqr",value:function(e){return t.valueOf(e).selfMultiply(e)}},{key:"valueOf",value:function(){if("string"==typeof arguments[0]){var e=arguments[0];return t.parse(e)}if("number"==typeof arguments[0])return new t(arguments[0])}},{key:"sqrt",value:function(e){return t.valueOf(e).sqrt()}},{key:"parse",value:function(e){for(var n=0,i=e.length;at.isWhitespace(e.charAt(n));)n++;var r=!1;if(n<i){var o=e.charAt(n);"-"!==o&&"+"!==o||(n++,"-"===o&&(r=!0))}for(var s=new t,a=0,l=0,u=0,h=!1;!(n>=i);){var c=e.charAt(n);if(n++,at.isDigit(c)){var f=c-"0";s.selfMultiply(t.TEN),s.selfAdd(f),a++}else{if("."!==c){if("e"===c||"E"===c){var g=e.substring(n);try{u=st.parseInt(g)}catch(v){throw v instanceof NumberFormatException?new NumberFormatException("Invalid exponent "+g+" in string "+e):v}break}throw new NumberFormatException("Unexpected character '"+c+"' at position "+n+" in string "+e)}l=a,h=!0}}var d=s;h||(l=a);var p=a-l-u;if(0===p)d=s;else if(p>0){var y=t.TEN.pow(p);d=s.divide(y)}else if(p<0){var m=t.TEN.pow(-p);d=s.multiply(m)}return r?d.negate():d}},{key:"createNaN",value:function(){return new t(O.NaN,O.NaN)}},{key:"copy",value:function(e){return new t(e)}},{key:"magnitude",value:function(t){var e=Math.abs(t),n=Math.log(e)/Math.log(10),i=Math.trunc(Math.floor(n));return 10*Math.pow(10,i)<=e&&(i+=1),i}},{key:"stringOfChar",value:function(t,e){for(var n=new ot,i=0;i<e;i++)n.append(t);return n.toString()}}])}();lt.PI=new lt(3.141592653589793,12246467991473532e-32),lt.TWO_PI=new lt(6.283185307179586,24492935982947064e-32),lt.PI_2=new lt(1.5707963267948966,6123233995736766e-32),lt.E=new lt(2.718281828459045,14456468917292502e-32),lt.NaN=new lt(O.NaN,O.NaN),lt.EPS=123259516440783e-46,lt.SPLIT=134217729,lt.MAX_PRINT_DIGITS=32,lt.TEN=lt.valueOf(10),lt.ONE=lt.valueOf(1),lt.SCI_NOT_EXPONENT_CHAR="E",lt.SCI_NOT_ZERO="0.0E0";var ut=function(){function t(){n(this,t)}return o(t,null,[{key:"orientationIndex",value:function(e,n,i){var r=t.orientationIndexFilter(e,n,i);if(r<=1)return r;var o=lt.valueOf(n.x).selfAdd(-e.x),s=lt.valueOf(n.y).selfAdd(-e.y),a=lt.valueOf(i.x).selfAdd(-n.x),l=lt.valueOf(i.y).selfAdd(-n.y);return o.selfMultiply(l).selfSubtract(s.selfMultiply(a)).signum()}},{key:"signOfDet2x2",value:function(){if(arguments[3]instanceof lt&&arguments[2]instanceof lt&&arguments[0]instanceof lt&&arguments[1]instanceof lt){var t=arguments[1],e=arguments[2],n=arguments[3];return arguments[0].multiply(n).selfSubtract(t.multiply(e)).signum()}if("number"==typeof arguments[3]&&"number"==typeof arguments[2]&&"number"==typeof arguments[0]&&"number"==typeof arguments[1]){var i=arguments[0],r=arguments[1],o=arguments[2],s=arguments[3],a=lt.valueOf(i),l=lt.valueOf(r),u=lt.valueOf(o),h=lt.valueOf(s);return a.multiply(h).selfSubtract(l.multiply(u)).signum()}}},{key:"intersection",value:function(t,e,n,i){var r=new lt(t.y).selfSubtract(e.y),o=new lt(e.x).selfSubtract(t.x),s=new lt(t.x).selfMultiply(e.y).selfSubtract(new lt(e.x).selfMultiply(t.y)),a=new lt(n.y).selfSubtract(i.y),l=new lt(i.x).selfSubtract(n.x),u=new lt(n.x).selfMultiply(i.y).selfSubtract(new lt(i.x).selfMultiply(n.y)),h=o.multiply(u).selfSubtract(l.multiply(s)),c=a.multiply(s).selfSubtract(r.multiply(u)),f=r.multiply(l).selfSubtract(a.multiply(o)),g=h.selfDivide(f).doubleValue(),d=c.selfDivide(f).doubleValue();return O.isNaN(g)||O.isInfinite(g)||O.isNaN(d)||O.isInfinite(d)?null:new Y(g,d)}},{key:"orientationIndexFilter",value:function(e,n,i){var r=null,o=(e.x-i.x)*(n.y-i.y),s=(e.y-i.y)*(n.x-i.x),a=o-s;if(o>0){if(s<=0)return t.signum(a);r=o+s}else{if(!(o<0))return t.signum(a);if(s>=0)return t.signum(a);r=-o-s}var l=t.DP_SAFE_EPSILON*r;return a>=l||-a>=l?t.signum(a):2}},{key:"signum",value:function(t){return t>0?1:t<0?-1:0}}])}();ut.DP_SAFE_EPSILON=1e-15;var ht=o(function t(){n(this,t)},[{key:"getM",value:function(t){if(this.hasM()){var e=this.getDimension()-this.getMeasures();return this.getOrdinate(t,e)}return O.NaN}},{key:"setOrdinate",value:function(t,e,n){}},{key:"getZ",value:function(t){return this.hasZ()?this.getOrdinate(t,2):O.NaN}},{key:"size",value:function(){}},{key:"getOrdinate",value:function(t,e){}},{key:"getCoordinate",value:function(){}},{key:"getCoordinateCopy",value:function(t){}},{key:"createCoordinate",value:function(){}},{key:"getDimension",value:function(){}},{key:"hasM",value:function(){return this.getMeasures()>0}},{key:"getX",value:function(t){}},{key:"hasZ",value:function(){return this.getDimension()-this.getMeasures()>2}},{key:"getMeasures",value:function(){return 0}},{key:"expandEnvelope",value:function(t){}},{key:"copy",value:function(){}},{key:"getY",value:function(t){}},{key:"toCoordinateArray",value:function(){}},{key:"interfaces_",get:function(){return[E]}}]);ht.X=0,ht.Y=1,ht.Z=2,ht.M=3;var ct=function(){function t(){n(this,t)}return o(t,null,[{key:"index",value:function(t,e,n){return ut.orientationIndex(t,e,n)}},{key:"isCCW",value:function(){if(arguments[0]instanceof Array){var e=arguments[0],n=e.length-1;if(n<3)throw new _("Ring has fewer than 4 points, so orientation cannot be determined");for(var i=e[0],r=0,o=1;o<=n;o++){var s=e[o];s.y>i.y&&(i=s,r=o)}var a=r;do{(a-=1)<0&&(a=n)}while(e[a].equals2D(i)&&a!==r);var l=r;do{l=(l+1)%n}while(e[l].equals2D(i)&&l!==r);var u=e[a],h=e[l];if(u.equals2D(i)||h.equals2D(i)||u.equals2D(h))return!1;var c=t.index(u,i,h);return 0===c?u.x>h.x:c>0}if(rt(arguments[0],ht)){var f=arguments[0],g=f.size()-1;if(g<3)throw new _("Ring has fewer than 4 points, so orientation cannot be determined");for(var d=f.getCoordinate(0),p=0,y=1;y<=g;y++){var m=f.getCoordinate(y);m.y>d.y&&(d=m,p=y)}var v=null,k=p;do{(k-=1)<0&&(k=g),v=f.getCoordinate(k)}while(v.equals2D(d)&&k!==p);var x=null,E=p;do{E=(E+1)%g,x=f.getCoordinate(E)}while(x.equals2D(d)&&E!==p);if(v.equals2D(d)||x.equals2D(d)||v.equals2D(x))return!1;var w=t.index(v,d,x);return 0===w?v.x>x.x:w>0}}}])}();ct.CLOCKWISE=-1,ct.RIGHT=ct.CLOCKWISE,ct.COUNTERCLOCKWISE=1,ct.LEFT=ct.COUNTERCLOCKWISE,ct.COLLINEAR=0,ct.STRAIGHT=ct.COLLINEAR;var ft=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"getCoordinate",value:function(){return this._minCoord}},{key:"getRightmostSide",value:function(t,e){var n=this.getRightmostSideOfSegment(t,e);return n<0&&(n=this.getRightmostSideOfSegment(t,e-1)),n<0&&(this._minCoord=null,this.checkForRightmostCoordinate(t)),n}},{key:"findRightmostEdgeAtVertex",value:function(){var t=this._minDe.getEdge().getCoordinates();B.isTrue(this._minIndex>0&&this._minIndex<t.length,"rightmost point expected to be interior vertex of edge");var e=t[this._minIndex-1],n=t[this._minIndex+1],i=ct.index(this._minCoord,n,e),r=!1;(e.y<this._minCoord.y&&n.y<this._minCoord.y&&i===ct.COUNTERCLOCKWISE||e.y>this._minCoord.y&&n.y>this._minCoord.y&&i===ct.CLOCKWISE)&&(r=!0),r&&(this._minIndex=this._minIndex-1)}},{key:"getRightmostSideOfSegment",value:function(t,e){var n=t.getEdge().getCoordinates();if(e<0||e+1>=n.length)return-1;if(n[e].y===n[e+1].y)return-1;var i=Q.LEFT;return n[e].y<n[e+1].y&&(i=Q.RIGHT),i}},{key:"getEdge",value:function(){return this._orientedDe}},{key:"checkForRightmostCoordinate",value:function(t){for(var e=t.getEdge().getCoordinates(),n=0;n<e.length-1;n++)(null===this._minCoord||e[n].x>this._minCoord.x)&&(this._minDe=t,this._minIndex=n,this._minCoord=e[n])}},{key:"findRightmostEdgeAtNode",value:function(){var t=this._minDe.getNode().getEdges();this._minDe=t.getRightmostEdge(),this._minDe.isForward()||(this._minDe=this._minDe.getSym(),this._minIndex=this._minDe.getEdge().getCoordinates().length-1)}},{key:"findEdge",value:function(t){for(var e=t.iterator();e.hasNext();){var n=e.next();n.isForward()&&this.checkForRightmostCoordinate(n)}B.isTrue(0!==this._minIndex||this._minCoord.equals(this._minDe.getCoordinate()),"inconsistency in rightmost processing"),0===this._minIndex?this.findRightmostEdgeAtNode():this.findRightmostEdgeAtVertex(),this._orientedDe=this._minDe,this.getRightmostSide(this._minDe,this._minIndex)===Q.LEFT&&(this._orientedDe=this._minDe.getSym())}}],[{key:"constructor_",value:function(){this._minIndex=-1,this._minCoord=null,this._minDe=null,this._orientedDe=null}}]),gt=function(t){function i(t,r){var o;return n(this,i),(o=e(this,i,[r?t+" [ "+r+" ]":t])).pt=r?new Y(r):void 0,o.name=Object.keys({TopologyException:i})[0],o}return u(i,t),o(i,[{key:"getCoordinate",value:function(){return this.pt}}])}(R),dt=o(function t(){n(this,t),this.array=[]},[{key:"addLast",value:function(t){this.array.push(t)}},{key:"removeFirst",value:function(){return this.array.shift()}},{key:"isEmpty",value:function(){return 0===this.array.length}}]),pt=function(t){function i(t){var r;return n(this,i),(r=e(this,i)).array=[],t instanceof j&&r.addAll(t),r}return u(i,t),o(i,[{key:"interfaces_",get:function(){return[nt,j]}},{key:"ensureCapacity",value:function(){}},{key:"add",value:function(t){return 1===arguments.length?this.array.push(t):this.array.splice(arguments[0],0,arguments[1]),!0}},{key:"clear",value:function(){this.array=[]}},{key:"addAll",value:function(t){var e,n=s(t);try{for(n.s();!(e=n.n()).done;){var i=e.value;this.array.push(i)}}catch(r){n.e(r)}finally{n.f()}}},{key:"set",value:function(t,e){var n=this.array[t];return this.array[t]=e,n}},{key:"iterator",value:function(){return new yt(this)}},{key:"get",value:function(t){if(t<0||t>=this.size())throw new et;return this.array[t]}},{key:"isEmpty",value:function(){return 0===this.array.length}},{key:"sort",value:function(t){t?this.array.sort(function(e,n){return t.compare(e,n)}):this.array.sort()}},{key:"size",value:function(){return this.array.length}},{key:"toArray",value:function(){return this.array.slice()}},{key:"remove",value:function(t){for(var e=0,n=this.array.length;e<n;e++)if(this.array[e]===t)return!!this.array.splice(e,1);return!1}},{key:Symbol.iterator,value:function(){return this.array.values()}}])}(nt),yt=o(function t(e){n(this,t),this.arrayList=e,this.position=0},[{key:"next",value:function(){if(this.position===this.arrayList.size())throw new K;return this.arrayList.get(this.position++)}},{key:"hasNext",value:function(){return this.position<this.arrayList.size()}},{key:"set",value:function(t){return this.arrayList.set(this.position-1,t)}},{key:"remove",value:function(){this.arrayList.remove(this.arrayList.get(this.position))}}]),mt=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"clearVisitedEdges",value:function(){for(var t=this._dirEdgeList.iterator();t.hasNext();)t.next().setVisited(!1)}},{key:"getRightmostCoordinate",value:function(){return this._rightMostCoord}},{key:"computeNodeDepth",value:function(t){for(var e=null,n=t.getEdges().iterator();n.hasNext();){var i=n.next();if(i.isVisited()||i.getSym().isVisited()){e=i;break}}if(null===e)throw new gt("unable to find edge to compute depths at "+t.getCoordinate());t.getEdges().computeDepths(e);for(var r=t.getEdges().iterator();r.hasNext();){var o=r.next();o.setVisited(!0),this.copySymDepths(o)}}},{key:"computeDepth",value:function(t){this.clearVisitedEdges();var e=this._finder.getEdge();e.getNode(),e.getLabel(),e.setEdgeDepths(Q.RIGHT,t),this.copySymDepths(e),this.computeDepths(e)}},{key:"create",value:function(t){this.addReachable(t),this._finder.findEdge(this._dirEdgeList),this._rightMostCoord=this._finder.getCoordinate()}},{key:"findResultEdges",value:function(){for(var t=this._dirEdgeList.iterator();t.hasNext();){var e=t.next();e.getDepth(Q.RIGHT)>=1&&e.getDepth(Q.LEFT)<=0&&!e.isInteriorAreaEdge()&&e.setInResult(!0)}}},{key:"computeDepths",value:function(t){var e=new J,n=new dt,i=t.getNode();for(n.addLast(i),e.add(i),t.setVisited(!0);!n.isEmpty();){var r=n.removeFirst();e.add(r),this.computeNodeDepth(r);for(var o=r.getEdges().iterator();o.hasNext();){var s=o.next().getSym();if(!s.isVisited()){var a=s.getNode();e.contains(a)||(n.addLast(a),e.add(a))}}}}},{key:"compareTo",value:function(t){var e=t;return this._rightMostCoord.x<e._rightMostCoord.x?-1:this._rightMostCoord.x>e._rightMostCoord.x?1:0}},{key:"getEnvelope",value:function(){if(null===this._env){for(var t=new X,e=this._dirEdgeList.iterator();e.hasNext();)for(var n=e.next().getEdge().getCoordinates(),i=0;i<n.length-1;i++)t.expandToInclude(n[i]);this._env=t}return this._env}},{key:"addReachable",value:function(t){var e=new it;for(e.add(t);!e.empty();){var n=e.pop();this.add(n,e)}}},{key:"copySymDepths",value:function(t){var e=t.getSym();e.setDepth(Q.LEFT,t.getDepth(Q.RIGHT)),e.setDepth(Q.RIGHT,t.getDepth(Q.LEFT))}},{key:"add",value:function(t,e){t.setVisited(!0),this._nodes.add(t);for(var n=t.getEdges().iterator();n.hasNext();){var i=n.next();this._dirEdgeList.add(i);var r=i.getSym().getNode();r.isVisited()||e.push(r)}}},{key:"getNodes",value:function(){return this._nodes}},{key:"getDirectedEdges",value:function(){return this._dirEdgeList}},{key:"interfaces_",get:function(){return[x]}}],[{key:"constructor_",value:function(){this._finder=null,this._dirEdgeList=new pt,this._nodes=new pt,this._rightMostCoord=null,this._env=null,this._finder=new ft}}]),vt=o(function t(){n(this,t)},null,[{key:"intersection",value:function(t,e,n,i){var r=t.x<e.x?t.x:e.x,o=t.y<e.y?t.y:e.y,s=t.x>e.x?t.x:e.x,a=t.y>e.y?t.y:e.y,l=n.x<i.x?n.x:i.x,u=n.y<i.y?n.y:i.y,h=n.x>i.x?n.x:i.x,c=n.y>i.y?n.y:i.y,f=((r>l?r:l)+(s<h?s:h))/2,g=((o>u?o:u)+(a<c?a:c))/2,d=t.x-f,p=t.y-g,y=e.x-f,m=e.y-g,v=n.x-f,_=n.y-g,k=i.x-f,x=i.y-g,E=p-m,w=y-d,M=d*m-y*p,P=_-x,b=k-v,I=v*x-k*_,S=E*b-P*w,L=(w*I-b*M)/S,C=(P*M-E*I)/S;return O.isNaN(L)||O.isInfinite(L)||O.isNaN(C)||O.isInfinite(C)?null:new Y(L+f,C+g)}}]),_t=o(function t(){n(this,t)},null,[{key:"arraycopy",value:function(t,e,n,i,r){for(var o=0,s=e;s<e+r;s++)n[i+o]=t[s],o++}},{key:"getProperty",value:function(t){return{"line.separator":"\n"}[t]}}]),kt=function(){function t(){n(this,t)}return o(t,null,[{key:"log10",value:function(e){var n=Math.log(e);return O.isInfinite(n)||O.isNaN(n)?n:n/t.LOG_10}},{key:"min",value:function(t,e,n,i){var r=t;return e<r&&(r=e),n<r&&(r=n),i<r&&(r=i),r}},{key:"clamp",value:function(){if("number"==typeof arguments[2]&&"number"==typeof arguments[0]&&"number"==typeof arguments[1]){var t=arguments[0],e=arguments[1],n=arguments[2];return t<e?e:t>n?n:t}if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var i=arguments[0],r=arguments[1],o=arguments[2];return i<r?r:i>o?o:i}}},{key:"wrap",value:function(t,e){return t<0?e- -t%e:t%e}},{key:"max",value:function(){if(3===arguments.length){var t=arguments[1],e=arguments[2],n=arguments[0];return t>n&&(n=t),e>n&&(n=e),n}if(4===arguments.length){var i=arguments[1],r=arguments[2],o=arguments[3],s=arguments[0];return i>s&&(s=i),r>s&&(s=r),o>s&&(s=o),s}}},{key:"average",value:function(t,e){return(t+e)/2}}])}();kt.LOG_10=Math.log(10);var xt=function(){function t(){n(this,t)}return o(t,null,[{key:"segmentToSegment",value:function(e,n,i,r){if(e.equals(n))return t.pointToSegment(e,i,r);if(i.equals(r))return t.pointToSegment(r,e,n);var o=!1;if(X.intersects(e,n,i,r)){var s=(n.x-e.x)*(r.y-i.y)-(n.y-e.y)*(r.x-i.x);if(0===s)o=!0;else{var a=(e.y-i.y)*(r.x-i.x)-(e.x-i.x)*(r.y-i.y),l=((e.y-i.y)*(n.x-e.x)-(e.x-i.x)*(n.y-e.y))/s,u=a/s;(u<0||u>1||l<0||l>1)&&(o=!0)}}else o=!0;return o?kt.min(t.pointToSegment(e,i,r),t.pointToSegment(n,i,r),t.pointToSegment(i,e,n),t.pointToSegment(r,e,n)):0}},{key:"pointToSegment",value:function(t,e,n){if(e.x===n.x&&e.y===n.y)return t.distance(e);var i=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),r=((t.x-e.x)*(n.x-e.x)+(t.y-e.y)*(n.y-e.y))/i;if(r<=0)return t.distance(e);if(r>=1)return t.distance(n);var o=((e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y))/i;return Math.abs(o)*Math.sqrt(i)}},{key:"pointToLinePerpendicular",value:function(t,e,n){var i=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),r=((e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y))/i;return Math.abs(r)*Math.sqrt(i)}},{key:"pointToSegmentString",value:function(e,n){if(0===n.length)throw new _("Line array must contain at least one vertex");for(var i=e.distance(n[0]),r=0;r<n.length-1;r++){var o=t.pointToSegment(e,n[r],n[r+1]);o<i&&(i=o)}return i}}])}(),Et=o(function t(){n(this,t)},[{key:"create",value:function(){if(1===arguments.length)arguments[0]instanceof Array||rt(arguments[0],ht);else if(2===arguments.length);else if(3===arguments.length){var t=arguments[0],e=arguments[1];return this.create(t,e)}}}]),wt=o(function t(){n(this,t)},[{key:"filter",value:function(t){}}]),Mt=o(function t(){n(this,t)},null,[{key:"ofLine",value:function(t){var e=t.size();if(e<=1)return 0;var n=0,i=new Y;t.getCoordinate(0,i);for(var r=i.x,o=i.y,s=1;s<e;s++){t.getCoordinate(s,i);var a=i.x,l=i.y,u=a-r,h=l-o;n+=Math.sqrt(u*u+h*h),r=a,o=l}return n}}]),Pt=o(function t(){n(this,t)}),bt=function(){function t(){n(this,t)}return o(t,null,[{key:"copyCoord",value:function(t,e,n,i){for(var r=Math.min(t.getDimension(),n.getDimension()),o=0;o<r;o++)n.setOrdinate(i,o,t.getOrdinate(e,o))}},{key:"isRing",value:function(t){var e=t.size();return 0===e||!(e<=3)&&t.getOrdinate(0,ht.X)===t.getOrdinate(e-1,ht.X)&&t.getOrdinate(0,ht.Y)===t.getOrdinate(e-1,ht.Y)}},{key:"scroll",value:function(){if(2===arguments.length){if(rt(arguments[0],ht)&&Number.isInteger(arguments[1])){var e=arguments[0],n=arguments[1];t.scroll(e,n,t.isRing(e))}else if(rt(arguments[0],ht)&&arguments[1]instanceof Y){var i=arguments[0],r=arguments[1],o=t.indexOf(r,i);if(o<=0)return null;t.scroll(i,o)}}else if(3===arguments.length){var s=arguments[0],a=arguments[1],l=arguments[2];if(a<=0)return null;for(var u=s.copy(),h=l?s.size()-1:s.size(),c=0;c<h;c++)for(var f=0;f<s.getDimension();f++)s.setOrdinate(c,f,u.getOrdinate((a+c)%h,f));if(l)for(var g=0;g<s.getDimension();g++)s.setOrdinate(h,g,s.getOrdinate(0,g))}}},{key:"isEqual",value:function(t,e){var n=t.size();if(n!==e.size())return!1;for(var i=Math.min(t.getDimension(),e.getDimension()),r=0;r<n;r++)for(var o=0;o<i;o++){var s=t.getOrdinate(r,o),a=e.getOrdinate(r,o);if(!(t.getOrdinate(r,o)===e.getOrdinate(r,o)||O.isNaN(s)&&O.isNaN(a)))return!1}return!0}},{key:"minCoordinateIndex",value:function(){if(1===arguments.length){var e=arguments[0];return t.minCoordinateIndex(e,0,e.size()-1)}if(3===arguments.length){for(var n=arguments[0],i=arguments[2],r=-1,o=null,s=arguments[1];s<=i;s++){var a=n.getCoordinate(s);(null===o||o.compareTo(a)>0)&&(o=a,r=s)}return r}}},{key:"extend",value:function(e,n,i){var r=e.create(i,n.getDimension()),o=n.size();if(t.copy(n,0,r,0,o),o>0)for(var s=o;s<i;s++)t.copy(n,o-1,r,s,1);return r}},{key:"reverse",value:function(e){for(var n=e.size()-1,i=Math.trunc(n/2),r=0;r<=i;r++)t.swap(e,r,n-r)}},{key:"swap",value:function(t,e,n){if(e===n)return null;for(var i=0;i<t.getDimension();i++){var r=t.getOrdinate(e,i);t.setOrdinate(e,i,t.getOrdinate(n,i)),t.setOrdinate(n,i,r)}}},{key:"copy",value:function(e,n,i,r,o){for(var s=0;s<o;s++)t.copyCoord(e,n+s,i,r+s)}},{key:"ensureValidRing",value:function(e,n){var i=n.size();return 0===i?n:i<=3?t.createClosedRing(e,n,4):n.getOrdinate(0,ht.X)===n.getOrdinate(i-1,ht.X)&&n.getOrdinate(0,ht.Y)===n.getOrdinate(i-1,ht.Y)?n:t.createClosedRing(e,n,i+1)}},{key:"indexOf",value:function(t,e){for(var n=0;n<e.size();n++)if(t.x===e.getOrdinate(n,ht.X)&&t.y===e.getOrdinate(n,ht.Y))return n;return-1}},{key:"createClosedRing",value:function(e,n,i){var r=e.create(i,n.getDimension()),o=n.size();t.copy(n,0,r,0,o);for(var s=o;s<i;s++)t.copy(n,0,r,s,1);return r}},{key:"minCoordinate",value:function(t){for(var e=null,n=0;n<t.size();n++){var i=t.getCoordinate(n);(null===e||e.compareTo(i)>0)&&(e=i)}return e}}])}(),It=function(){function t(){n(this,t)}return o(t,null,[{key:"toDimensionSymbol",value:function(e){switch(e){case t.FALSE:return t.SYM_FALSE;case t.TRUE:return t.SYM_TRUE;case t.DONTCARE:return t.SYM_DONTCARE;case t.P:return t.SYM_P;case t.L:return t.SYM_L;case t.A:return t.SYM_A}throw new _("Unknown dimension value: "+e)}},{key:"toDimensionValue",value:function(e){switch(at.toUpperCase(e)){case t.SYM_FALSE:return t.FALSE;case t.SYM_TRUE:return t.TRUE;case t.SYM_DONTCARE:return t.DONTCARE;case t.SYM_P:return t.P;case t.SYM_L:return t.L;case t.SYM_A:return t.A}throw new _("Unknown dimension symbol: "+e)}}])}();It.P=0,It.L=1,It.A=2,It.FALSE=-1,It.TRUE=-2,It.DONTCARE=-3,It.SYM_FALSE="F",It.SYM_TRUE="T",It.SYM_DONTCARE="*",It.SYM_P="0",It.SYM_L="1",It.SYM_A="2";var St=o(function t(){n(this,t)},[{key:"filter",value:function(t){}}]),Lt=o(function t(){n(this,t)},[{key:"filter",value:function(t,e){}},{key:"isDone",value:function(){}},{key:"isGeometryChanged",value:function(){}}]),Ct=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"computeEnvelopeInternal",value:function(){return this.isEmpty()?new X:this._points.expandEnvelope(new X)}},{key:"isRing",value:function(){return this.isClosed()&&this.isSimple()}},{key:"getCoordinates",value:function(){return this._points.toCoordinateArray()}},{key:"copyInternal",value:function(){return new i(this._points.copy(),this._factory)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof q){var t=arguments[0],e=arguments[1];if(!this.isEquivalentClass(t))return!1;var n=t;if(this._points.size()!==n._points.size())return!1;for(var r=0;r<this._points.size();r++)if(!this.equal(this._points.getCoordinate(r),n._points.getCoordinate(r),e))return!1;return!0}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var t=0;t<Math.trunc(this._points.size()/2);t++){var e=this._points.size()-1-t;if(!this._points.getCoordinate(t).equals(this._points.getCoordinate(e))){if(this._points.getCoordinate(t).compareTo(this._points.getCoordinate(e))>0){var n=this._points.copy();bt.reverse(n),this._points=n}return null}}}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this._points.getCoordinate(0)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?It.FALSE:0}},{key:"isClosed",value:function(){return!this.isEmpty()&&this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints()-1))}},{key:"reverseInternal",value:function(){var t=this._points.copy();return bt.reverse(t),this.getFactory().createLineString(t)}},{key:"getEndPoint",value:function(){return this.isEmpty()?null:this.getPointN(this.getNumPoints()-1)}},{key:"getTypeCode",value:function(){return q.TYPECODE_LINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getLength",value:function(){return Mt.ofLine(this._points)}},{key:"getNumPoints",value:function(){return this._points.size()}},{key:"compareToSameClass",value:function(){if(1===arguments.length){for(var t=arguments[0],e=0,n=0;e<this._points.size()&&n<t._points.size();){var i=this._points.getCoordinate(e).compareTo(t._points.getCoordinate(n));if(0!==i)return i;e++,n++}return e<this._points.size()?1:n<t._points.size()?-1:0}if(2===arguments.length){var r=arguments[0];return arguments[1].compare(this._points,r._points)}}},{key:"apply",value:function(){if(rt(arguments[0],wt))for(var t=arguments[0],e=0;e<this._points.size();e++)t.filter(this._points.getCoordinate(e));else if(rt(arguments[0],Lt)){var n=arguments[0];if(0===this._points.size())return null;for(var i=0;i<this._points.size()&&(n.filter(this._points,i),!n.isDone());i++);n.isGeometryChanged()&&this.geometryChanged()}else(rt(arguments[0],St)||rt(arguments[0],k))&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){throw new W}},{key:"isEquivalentClass",value:function(t){return t instanceof i}},{key:"getCoordinateN",value:function(t){return this._points.getCoordinate(t)}},{key:"getGeometryType",value:function(){return q.TYPENAME_LINESTRING}},{key:"getCoordinateSequence",value:function(){return this._points}},{key:"isEmpty",value:function(){return 0===this._points.size()}},{key:"init",value:function(t){if(null===t&&(t=this.getFactory().getCoordinateSequenceFactory().create([])),1===t.size())throw new _("Invalid number of points in LineString (found "+t.size()+" - must be 0 or >= 2)");this._points=t}},{key:"isCoordinate",value:function(t){for(var e=0;e<this._points.size();e++)if(this._points.getCoordinate(e).equals(t))return!0;return!1}},{key:"getStartPoint",value:function(){return this.isEmpty()?null:this.getPointN(0)}},{key:"getPointN",value:function(t){return this.getFactory().createPoint(this._points.getCoordinate(t))}},{key:"interfaces_",get:function(){return[Pt]}}],[{key:"constructor_",value:function(){if(this._points=null,0===arguments.length);else if(2===arguments.length){var t=arguments[0],e=arguments[1];q.constructor_.call(this,e),this.init(t)}}}])}(q),Nt=o(function t(){n(this,t)}),Tt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"computeEnvelopeInternal",value:function(){if(this.isEmpty())return new X;var t=new X;return t.expandToInclude(this._coordinates.getX(0),this._coordinates.getY(0)),t}},{key:"getCoordinates",value:function(){return this.isEmpty()?[]:[this.getCoordinate()]}},{key:"copyInternal",value:function(){return new i(this._coordinates.copy(),this._factory)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof q){var t=arguments[0],e=arguments[1];return!!this.isEquivalentClass(t)&&(!(!this.isEmpty()||!t.isEmpty())||this.isEmpty()===t.isEmpty()&&this.equal(t.getCoordinate(),this.getCoordinate(),e))}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){}},{key:"getCoordinate",value:function(){return 0!==this._coordinates.size()?this._coordinates.getCoordinate(0):null}},{key:"getBoundaryDimension",value:function(){return It.FALSE}},{key:"reverseInternal",value:function(){return this.getFactory().createPoint(this._coordinates.copy())}},{key:"getTypeCode",value:function(){return q.TYPECODE_POINT}},{key:"getDimension",value:function(){return 0}},{key:"getNumPoints",value:function(){return this.isEmpty()?0:1}},{key:"getX",value:function(){if(null===this.getCoordinate())throw new IllegalStateException("getX called on empty Point");return this.getCoordinate().x}},{key:"compareToSameClass",value:function(){if(1===arguments.length){var t=arguments[0];return this.getCoordinate().compareTo(t.getCoordinate())}if(2===arguments.length){var e=arguments[0];return arguments[1].compare(this._coordinates,e._coordinates)}}},{key:"apply",value:function(){if(rt(arguments[0],wt)){var t=arguments[0];if(this.isEmpty())return null;t.filter(this.getCoordinate())}else if(rt(arguments[0],Lt)){var e=arguments[0];if(this.isEmpty())return null;e.filter(this._coordinates,0),e.isGeometryChanged()&&this.geometryChanged()}else(rt(arguments[0],St)||rt(arguments[0],k))&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return q.TYPENAME_POINT}},{key:"getCoordinateSequence",value:function(){return this._coordinates}},{key:"getY",value:function(){if(null===this.getCoordinate())throw new IllegalStateException("getY called on empty Point");return this.getCoordinate().y}},{key:"isEmpty",value:function(){return 0===this._coordinates.size()}},{key:"init",value:function(t){null===t&&(t=this.getFactory().getCoordinateSequenceFactory().create([])),B.isTrue(t.size()<=1),this._coordinates=t}},{key:"isSimple",value:function(){return!0}},{key:"interfaces_",get:function(){return[Nt]}}],[{key:"constructor_",value:function(){this._coordinates=null;var t=arguments[0],e=arguments[1];q.constructor_.call(this,e),this.init(t)}}])}(q),Dt=function(){function t(){n(this,t)}return o(t,null,[{key:"ofRing",value:function(){if(arguments[0]instanceof Array){var e=arguments[0];return Math.abs(t.ofRingSigned(e))}if(rt(arguments[0],ht)){var n=arguments[0];return Math.abs(t.ofRingSigned(n))}}},{key:"ofRingSigned",value:function(){if(arguments[0]instanceof Array){var t=arguments[0];if(t.length<3)return 0;for(var e=0,n=t[0].x,i=1;i<t.length-1;i++){var r=t[i].x-n,o=t[i+1].y;e+=r*(t[i-1].y-o)}return e/2}if(rt(arguments[0],ht)){var s=arguments[0],a=s.size();if(a<3)return 0;var l=new Y,u=new Y,h=new Y;s.getCoordinate(0,u),s.getCoordinate(1,h);var c=u.x;h.x-=c;for(var f=0,g=1;g<a-1;g++)l.y=u.y,u.x=h.x,u.y=h.y,s.getCoordinate(g+1,h),h.x-=c,f+=u.x*(l.y-h.y);return f/2}}}])}(),Ot=o(function t(){n(this,t)},null,[{key:"sort",value:function(){var t=arguments,e=arguments[0];if(1===arguments.length)e.sort(function(t,e){return t.compareTo(e)});else if(2===arguments.length)e.sort(function(e,n){return t[1].compare(e,n)});else if(3===arguments.length){var n=e.slice(arguments[1],arguments[2]);n.sort();var i=e.slice(0,arguments[1]).concat(n,e.slice(arguments[2],e.length));e.splice(0,e.length);var r,o=s(i);try{for(o.s();!(r=o.n()).done;){var a=r.value;e.push(a)}}catch(g){o.e(g)}finally{o.f()}}else if(4===arguments.length){var l=e.slice(arguments[1],arguments[2]);l.sort(function(e,n){return t[3].compare(e,n)});var u=e.slice(0,arguments[1]).concat(l,e.slice(arguments[2],e.length));e.splice(0,e.length);var h,c=s(u);try{for(c.s();!(h=c.n()).done;){var f=h.value;e.push(f)}}catch(g){c.e(g)}finally{c.f()}}}},{key:"asList",value:function(t){var e,n=new pt,i=s(t);try{for(i.s();!(e=i.n()).done;){var r=e.value;n.add(r)}}catch(o){i.e(o)}finally{i.f()}return n}},{key:"copyOf",value:function(t,e){return t.slice(0,e)}}]),At=o(function t(){n(this,t)}),Rt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"computeEnvelopeInternal",value:function(){return this._shell.getEnvelopeInternal()}},{key:"getCoordinates",value:function(){if(this.isEmpty())return[];for(var t=new Array(this.getNumPoints()).fill(null),e=-1,n=this._shell.getCoordinates(),i=0;i<n.length;i++)t[++e]=n[i];for(var r=0;r<this._holes.length;r++)for(var o=this._holes[r].getCoordinates(),s=0;s<o.length;s++)t[++e]=o[s];return t}},{key:"getArea",value:function(){var t=0;t+=Dt.ofRing(this._shell.getCoordinateSequence());for(var e=0;e<this._holes.length;e++)t-=Dt.ofRing(this._holes[e].getCoordinateSequence());return t}},{key:"copyInternal",value:function(){for(var t=this._shell.copy(),e=new Array(this._holes.length).fill(null),n=0;n<this._holes.length;n++)e[n]=this._holes[n].copy();return new i(t,e,this._factory)}},{key:"isRectangle",value:function(){if(0!==this.getNumInteriorRing())return!1;if(null===this._shell)return!1;if(5!==this._shell.getNumPoints())return!1;for(var t=this._shell.getCoordinateSequence(),e=this.getEnvelopeInternal(),n=0;n<5;n++){var i=t.getX(n);if(i!==e.getMinX()&&i!==e.getMaxX())return!1;var r=t.getY(n);if(r!==e.getMinY()&&r!==e.getMaxY())return!1}for(var o=t.getX(0),s=t.getY(0),a=1;a<=4;a++){var l=t.getX(a),u=t.getY(a);if(l!==o==(u!==s))return!1;o=l,s=u}return!0}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof q){var t=arguments[0],e=arguments[1];if(!this.isEquivalentClass(t))return!1;var n=t,r=this._shell,o=n._shell;if(!r.equalsExact(o,e))return!1;if(this._holes.length!==n._holes.length)return!1;for(var s=0;s<this._holes.length;s++)if(!this._holes[s].equalsExact(n._holes[s],e))return!1;return!0}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){if(0===arguments.length){this._shell=this.normalized(this._shell,!0);for(var t=0;t<this._holes.length;t++)this._holes[t]=this.normalized(this._holes[t],!1);Ot.sort(this._holes)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];if(e.isEmpty())return null;var i=e.getCoordinateSequence(),r=bt.minCoordinateIndex(i,0,i.size()-2);bt.scroll(i,r,!0),ct.isCCW(i)===n&&bt.reverse(i)}}},{key:"getCoordinate",value:function(){return this._shell.getCoordinate()}},{key:"getNumInteriorRing",value:function(){return this._holes.length}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"reverseInternal",value:function(){for(var t=this.getExteriorRing().reverse(),e=new Array(this.getNumInteriorRing()).fill(null),n=0;n<e.length;n++)e[n]=this.getInteriorRingN(n).reverse();return this.getFactory().createPolygon(t,e)}},{key:"getTypeCode",value:function(){return q.TYPECODE_POLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getLength",value:function(){var t=0;t+=this._shell.getLength();for(var e=0;e<this._holes.length;e++)t+=this._holes[e].getLength();return t}},{key:"getNumPoints",value:function(){for(var t=this._shell.getNumPoints(),e=0;e<this._holes.length;e++)t+=this._holes[e].getNumPoints();return t}},{key:"convexHull",value:function(){return this.getExteriorRing().convexHull()}},{key:"normalized",value:function(t,e){var n=t.copy();return this.normalize(n,e),n}},{key:"compareToSameClass",value:function(){if(1===arguments.length){var t=arguments[0],e=this._shell,n=t._shell;return e.compareToSameClass(n)}if(2===arguments.length){var i=arguments[1],r=arguments[0],o=this._shell,s=r._shell,a=o.compareToSameClass(s,i);if(0!==a)return a;for(var l=this.getNumInteriorRing(),u=r.getNumInteriorRing(),h=0;h<l&&h<u;){var c=this.getInteriorRingN(h),f=r.getInteriorRingN(h),g=c.compareToSameClass(f,i);if(0!==g)return g;h++}return h<l?1:h<u?-1:0}}},{key:"apply",value:function(){if(rt(arguments[0],wt)){var t=arguments[0];this._shell.apply(t);for(var e=0;e<this._holes.length;e++)this._holes[e].apply(t)}else if(rt(arguments[0],Lt)){var n=arguments[0];if(this._shell.apply(n),!n.isDone())for(var i=0;i<this._holes.length&&(this._holes[i].apply(n),!n.isDone());i++);n.isGeometryChanged()&&this.geometryChanged()}else if(rt(arguments[0],St))arguments[0].filter(this);else if(rt(arguments[0],k)){var r=arguments[0];r.filter(this),this._shell.apply(r);for(var o=0;o<this._holes.length;o++)this._holes[o].apply(r)}}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();var t=new Array(this._holes.length+1).fill(null);t[0]=this._shell;for(var e=0;e<this._holes.length;e++)t[e+1]=this._holes[e];return t.length<=1?this.getFactory().createLinearRing(t[0].getCoordinateSequence()):this.getFactory().createMultiLineString(t)}},{key:"getGeometryType",value:function(){return q.TYPENAME_POLYGON}},{key:"getExteriorRing",value:function(){return this._shell}},{key:"isEmpty",value:function(){return this._shell.isEmpty()}},{key:"getInteriorRingN",value:function(t){return this._holes[t]}},{key:"interfaces_",get:function(){return[At]}}],[{key:"constructor_",value:function(){this._shell=null,this._holes=null;var t=arguments[0],e=arguments[1],n=arguments[2];if(q.constructor_.call(this,n),null===t&&(t=this.getFactory().createLinearRing()),null===e&&(e=[]),q.hasNullElements(e))throw new _("holes must not contain null elements");if(t.isEmpty()&&q.hasNonEmptyElements(e))throw new _("shell is empty but holes are not");this._shell=t,this._holes=e}}])}(q),Ft=function(t){function i(){return n(this,i),e(this,i,arguments)}return u(i,t),o(i)}(Z),Bt=function(t){function i(t){var r;return n(this,i),(r=e(this,i)).array=[],t instanceof j&&r.addAll(t),r}return u(i,t),o(i,[{key:"contains",value:function(t){var e,n=s(this.array);try{for(n.s();!(e=n.n()).done;)if(0===e.value.compareTo(t))return!0}catch(i){n.e(i)}finally{n.f()}return!1}},{key:"add",value:function(t){if(this.contains(t))return!1;for(var e=0,n=this.array.length;e<n;e++)if(1===this.array[e].compareTo(t))return!!this.array.splice(e,0,t);return this.array.push(t),!0}},{key:"addAll",value:function(t){var e,n=s(t);try{for(n.s();!(e=n.n()).done;){var i=e.value;this.add(i)}}catch(r){n.e(r)}finally{n.f()}return!0}},{key:"remove",value:function(){throw new W}},{key:"size",value:function(){return this.array.length}},{key:"isEmpty",value:function(){return 0===this.array.length}},{key:"toArray",value:function(){return this.array.slice()}},{key:"iterator",value:function(){return new Gt(this.array)}}])}(Ft),Gt=o(function t(e){n(this,t),this.array=e,this.position=0},[{key:"next",value:function(){if(this.position===this.array.length)throw new K;return this.array[this.position++]}},{key:"hasNext",value:function(){return this.position<this.array.length}},{key:"remove",value:function(){throw new W}}]),zt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"computeEnvelopeInternal",value:function(){for(var t=new X,e=0;e<this._geometries.length;e++)t.expandToInclude(this._geometries[e].getEnvelopeInternal());return t}},{key:"getGeometryN",value:function(t){return this._geometries[t]}},{key:"getCoordinates",value:function(){for(var t=new Array(this.getNumPoints()).fill(null),e=-1,n=0;n<this._geometries.length;n++)for(var i=this._geometries[n].getCoordinates(),r=0;r<i.length;r++)t[++e]=i[r];return t}},{key:"getArea",value:function(){for(var t=0,e=0;e<this._geometries.length;e++)t+=this._geometries[e].getArea();return t}},{key:"copyInternal",value:function(){for(var t=new Array(this._geometries.length).fill(null),e=0;e<t.length;e++)t[e]=this._geometries[e].copy();return new i(t,this._factory)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof q){var t=arguments[0],e=arguments[1];if(!this.isEquivalentClass(t))return!1;var n=t;if(this._geometries.length!==n._geometries.length)return!1;for(var r=0;r<this._geometries.length;r++)if(!this._geometries[r].equalsExact(n._geometries[r],e))return!1;return!0}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var t=0;t<this._geometries.length;t++)this._geometries[t].normalize();Ot.sort(this._geometries)}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this._geometries[0].getCoordinate()}},{key:"getBoundaryDimension",value:function(){for(var t=It.FALSE,e=0;e<this._geometries.length;e++)t=Math.max(t,this._geometries[e].getBoundaryDimension());return t}},{key:"reverseInternal",value:function(){for(var t=this._geometries.length,e=new pt(t),n=0;n<t;n++)e.add(this._geometries[n].reverse());return this.getFactory().buildGeometry(e)}},{key:"getTypeCode",value:function(){return q.TYPECODE_GEOMETRYCOLLECTION}},{key:"getDimension",value:function(){for(var t=It.FALSE,e=0;e<this._geometries.length;e++)t=Math.max(t,this._geometries[e].getDimension());return t}},{key:"getLength",value:function(){for(var t=0,e=0;e<this._geometries.length;e++)t+=this._geometries[e].getLength();return t}},{key:"getNumPoints",value:function(){for(var t=0,e=0;e<this._geometries.length;e++)t+=this._geometries[e].getNumPoints();return t}},{key:"getNumGeometries",value:function(){return this._geometries.length}},{key:"compareToSameClass",value:function(){if(1===arguments.length){var t=arguments[0],e=new Bt(Ot.asList(this._geometries)),n=new Bt(Ot.asList(t._geometries));return this.compare(e,n)}if(2===arguments.length){for(var i=arguments[1],r=arguments[0],o=this.getNumGeometries(),s=r.getNumGeometries(),a=0;a<o&&a<s;){var l=this.getGeometryN(a),u=r.getGeometryN(a),h=l.compareToSameClass(u,i);if(0!==h)return h;a++}return a<o?1:a<s?-1:0}}},{key:"apply",value:function(){if(rt(arguments[0],wt))for(var t=arguments[0],e=0;e<this._geometries.length;e++)this._geometries[e].apply(t);else if(rt(arguments[0],Lt)){var n=arguments[0];if(0===this._geometries.length)return null;for(var i=0;i<this._geometries.length&&(this._geometries[i].apply(n),!n.isDone());i++);n.isGeometryChanged()&&this.geometryChanged()}else if(rt(arguments[0],St)){var r=arguments[0];r.filter(this);for(var o=0;o<this._geometries.length;o++)this._geometries[o].apply(r)}else if(rt(arguments[0],k)){var s=arguments[0];s.filter(this);for(var a=0;a<this._geometries.length;a++)this._geometries[a].apply(s)}}},{key:"getBoundary",value:function(){return q.checkNotGeometryCollection(this),B.shouldNeverReachHere(),null}},{key:"getGeometryType",value:function(){return q.TYPENAME_GEOMETRYCOLLECTION}},{key:"isEmpty",value:function(){for(var t=0;t<this._geometries.length;t++)if(!this._geometries[t].isEmpty())return!1;return!0}}],[{key:"constructor_",value:function(){if(this._geometries=null,0===arguments.length);else if(2===arguments.length){var t=arguments[0],e=arguments[1];if(q.constructor_.call(this,e),null===t&&(t=[]),q.hasNullElements(t))throw new _("geometries must not contain null elements");this._geometries=t}}}])}(q),Ht=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"copyInternal",value:function(){for(var t=new Array(this._geometries.length).fill(null),e=0;e<t.length;e++)t[e]=this._geometries[e].copy();return new i(t,this._factory)}},{key:"isValid",value:function(){return!0}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof q){var t=arguments[0],e=arguments[1];return!!this.isEquivalentClass(t)&&f(i,"equalsExact",this,1).call(this,t,e)}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"getCoordinate",value:function(){if(1===arguments.length&&Number.isInteger(arguments[0])){var t=arguments[0];return this._geometries[t].getCoordinate()}return f(i,"getCoordinate",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return It.FALSE}},{key:"getTypeCode",value:function(){return q.TYPECODE_MULTIPOINT}},{key:"getDimension",value:function(){return 0}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return q.TYPENAME_MULTIPOINT}},{key:"interfaces_",get:function(){return[Nt]}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];zt.constructor_.call(this,t,e)}}])}(zt),Yt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"copyInternal",value:function(){return new i(this._points.copy(),this._factory)}},{key:"getBoundaryDimension",value:function(){return It.FALSE}},{key:"isClosed",value:function(){return!!this.isEmpty()||f(i,"isClosed",this,1).call(this)}},{key:"reverseInternal",value:function(){var t=this._points.copy();return bt.reverse(t),this.getFactory().createLinearRing(t)}},{key:"getTypeCode",value:function(){return q.TYPECODE_LINEARRING}},{key:"validateConstruction",value:function(){if(!this.isEmpty()&&!f(i,"isClosed",this,1).call(this))throw new _("Points of LinearRing do not form a closed linestring");if(this.getCoordinateSequence().size()>=1&&this.getCoordinateSequence().size()<i.MINIMUM_VALID_SIZE)throw new _("Invalid number of points in LinearRing (found "+this.getCoordinateSequence().size()+" - must be 0 or >= 4)")}},{key:"getGeometryType",value:function(){return q.TYPENAME_LINEARRING}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];Ct.constructor_.call(this,t,e),this.validateConstruction()}}])}(Ct);Yt.MINIMUM_VALID_SIZE=4;var Ut=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"setOrdinate",value:function(t,e){switch(t){case i.X:this.x=e;break;case i.Y:this.y=e;break;default:throw new _("Invalid ordinate index: "+t)}}},{key:"getZ",value:function(){return Y.NULL_ORDINATE}},{key:"getOrdinate",value:function(t){switch(t){case i.X:return this.x;case i.Y:return this.y}throw new _("Invalid ordinate index: "+t)}},{key:"setZ",value:function(t){throw new _("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new i(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+")"}},{key:"setCoordinate",value:function(t){this.x=t.x,this.y=t.y,this.z=t.getZ()}}],[{key:"constructor_",value:function(){if(0===arguments.length)Y.constructor_.call(this);else if(1===arguments.length){if(arguments[0]instanceof i){var t=arguments[0];Y.constructor_.call(this,t.x,t.y)}else if(arguments[0]instanceof Y){var e=arguments[0];Y.constructor_.call(this,e.x,e.y)}}else if(2===arguments.length){var n=arguments[0],r=arguments[1];Y.constructor_.call(this,n,r,Y.NULL_ORDINATE)}}}])}(Y);Ut.X=0,Ut.Y=1,Ut.Z=-1,Ut.M=-1;var Xt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"getM",value:function(){return this._m}},{key:"setOrdinate",value:function(t,e){switch(t){case i.X:this.x=e;break;case i.Y:this.y=e;break;case i.M:this._m=e;break;default:throw new _("Invalid ordinate index: "+t)}}},{key:"setM",value:function(t){this._m=t}},{key:"getZ",value:function(){return Y.NULL_ORDINATE}},{key:"getOrdinate",value:function(t){switch(t){case i.X:return this.x;case i.Y:return this.y;case i.M:return this._m}throw new _("Invalid ordinate index: "+t)}},{key:"setZ",value:function(t){throw new _("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new i(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(t){this.x=t.x,this.y=t.y,this.z=t.getZ(),this._m=t.getM()}}],[{key:"constructor_",value:function(){if(this._m=null,0===arguments.length)Y.constructor_.call(this),this._m=0;else if(1===arguments.length){if(arguments[0]instanceof i){var t=arguments[0];Y.constructor_.call(this,t.x,t.y),this._m=t._m}else if(arguments[0]instanceof Y){var e=arguments[0];Y.constructor_.call(this,e.x,e.y),this._m=this.getM()}}else if(3===arguments.length){var n=arguments[0],r=arguments[1],o=arguments[2];Y.constructor_.call(this,n,r,Y.NULL_ORDINATE),this._m=o}}}])}(Y);Xt.X=0,Xt.Y=1,Xt.Z=-1,Xt.M=2;var qt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"getM",value:function(){return this._m}},{key:"setOrdinate",value:function(t,e){switch(t){case Y.X:this.x=e;break;case Y.Y:this.y=e;break;case Y.Z:this.z=e;break;case Y.M:this._m=e;break;default:throw new _("Invalid ordinate index: "+t)}}},{key:"setM",value:function(t){this._m=t}},{key:"getOrdinate",value:function(t){switch(t){case Y.X:return this.x;case Y.Y:return this.y;case Y.Z:return this.getZ();case Y.M:return this.getM()}throw new _("Invalid ordinate index: "+t)}},{key:"copy",value:function(){return new i(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+", "+this.getZ()+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(t){this.x=t.x,this.y=t.y,this.z=t.getZ(),this._m=t.getM()}}],[{key:"constructor_",value:function(){if(this._m=null,0===arguments.length)Y.constructor_.call(this),this._m=0;else if(1===arguments.length){if(arguments[0]instanceof i){var t=arguments[0];Y.constructor_.call(this,t),this._m=t._m}else if(arguments[0]instanceof Y){var e=arguments[0];Y.constructor_.call(this,e),this._m=this.getM()}}else if(4===arguments.length){var n=arguments[0],r=arguments[1],o=arguments[2],s=arguments[3];Y.constructor_.call(this,n,r,o),this._m=s}}}])}(Y),Vt=function(){function t(){n(this,t)}return o(t,null,[{key:"measures",value:function(t){return t instanceof Ut?0:t instanceof Xt||t instanceof qt?1:0}},{key:"dimension",value:function(t){return t instanceof Ut?2:t instanceof Xt?3:t instanceof qt?4:3}},{key:"create",value:function(){if(1===arguments.length){var e=arguments[0];return t.create(e,0)}if(2===arguments.length){var n=arguments[0],i=arguments[1];return 2===n?new Ut:3===n&&0===i?new Y:3===n&&1===i?new Xt:4===n&&1===i?new qt:new Y}}}])}(),jt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"getCoordinate",value:function(t){return this.get(t)}},{key:"addAll",value:function(){if(2===arguments.length&&"boolean"==typeof arguments[1]&&rt(arguments[0],j)){for(var t=arguments[1],e=!1,n=arguments[0].iterator();n.hasNext();)this.add(n.next(),t),e=!0;return e}return f(i,"addAll",this,1).apply(this,arguments)}},{key:"clone",value:function(){for(var t=f(i,"clone",this,1).call(this),e=0;e<this.size();e++)t.add(e,this.get(e).clone());return t}},{key:"toCoordinateArray",value:function(){if(0===arguments.length)return this.toArray(i.coordArrayType);if(1===arguments.length){if(arguments[0])return this.toArray(i.coordArrayType);for(var t=this.size(),e=new Array(t).fill(null),n=0;n<t;n++)e[n]=this.get(t-n-1);return e}}},{key:"add",value:function(){if(1===arguments.length){var t=arguments[0];return f(i,"add",this,1).call(this,t)}if(2===arguments.length){if(arguments[0]instanceof Array&&"boolean"==typeof arguments[1]){var e=arguments[0],n=arguments[1];return this.add(e,n,!0),!0}if(arguments[0]instanceof Y&&"boolean"==typeof arguments[1]){var r=arguments[0];if(!arguments[1]&&this.size()>=1&&this.get(this.size()-1).equals2D(r))return null;f(i,"add",this,1).call(this,r)}else if(arguments[0]instanceof Object&&"boolean"==typeof arguments[1]){var o=arguments[0],s=arguments[1];return this.add(o,s),!0}}else if(3===arguments.length){if("boolean"==typeof arguments[2]&&arguments[0]instanceof Array&&"boolean"==typeof arguments[1]){var a=arguments[0],l=arguments[1];if(arguments[2])for(var u=0;u<a.length;u++)this.add(a[u],l);else for(var h=a.length-1;h>=0;h--)this.add(a[h],l);return!0}if("boolean"==typeof arguments[2]&&Number.isInteger(arguments[0])&&arguments[1]instanceof Y){var c=arguments[0],g=arguments[1];if(!arguments[2]){var d=this.size();if(d>0){if(c>0&&this.get(c-1).equals2D(g))return null;if(c<d&&this.get(c).equals2D(g))return null}}f(i,"add",this,1).call(this,c,g)}}else if(4===arguments.length){var p=arguments[0],y=arguments[1],m=arguments[2],v=arguments[3],_=1;m>v&&(_=-1);for(var k=m;k!==v;k+=_)this.add(p[k],y);return!0}}},{key:"closeRing",value:function(){if(this.size()>0){var t=this.get(0).copy();this.add(t,!1)}}}],[{key:"constructor_",value:function(){if(0===arguments.length);else if(1===arguments.length){var t=arguments[0];this.ensureCapacity(t.length),this.add(t,!0)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.ensureCapacity(e.length),this.add(e,n)}}}])}(pt);jt.coordArrayType=new Array(0).fill(null);var Kt=function(){function t(){n(this,t)}return o(t,null,[{key:"isRing",value:function(t){return!(t.length<4||!t[0].equals2D(t[t.length-1]))}},{key:"ptNotInList",value:function(e,n){for(var i=0;i<e.length;i++){var r=e[i];if(t.indexOf(r,n)<0)return r}return null}},{key:"scroll",value:function(e,n){var i=t.indexOf(n,e);if(i<0)return null;var r=new Array(e.length).fill(null);_t.arraycopy(e,i,r,0,e.length-i),_t.arraycopy(e,0,r,e.length-i,i),_t.arraycopy(r,0,e,0,e.length)}},{key:"equals",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];if(t===e)return!0;if(null===t||null===e)return!1;if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!t[n].equals(e[n]))return!1;return!0}if(3===arguments.length){var i=arguments[0],r=arguments[1],o=arguments[2];if(i===r)return!0;if(null===i||null===r)return!1;if(i.length!==r.length)return!1;for(var s=0;s<i.length;s++)if(0!==o.compare(i[s],r[s]))return!1;return!0}}},{key:"intersection",value:function(t,e){for(var n=new jt,i=0;i<t.length;i++)e.intersects(t[i])&&n.add(t[i],!0);return n.toCoordinateArray()}},{key:"measures",value:function(t){if(null===t||0===t.length)return 0;var e,n=0,i=s(t);try{for(i.s();!(e=i.n()).done;){var r=e.value;n=Math.max(n,Vt.measures(r))}}catch(o){i.e(o)}finally{i.f()}return n}},{key:"hasRepeatedPoints",value:function(t){for(var e=1;e<t.length;e++)if(t[e-1].equals(t[e]))return!0;return!1}},{key:"removeRepeatedPoints",value:function(e){return t.hasRepeatedPoints(e)?new jt(e,!1).toCoordinateArray():e}},{key:"reverse",value:function(t){for(var e=t.length-1,n=Math.trunc(e/2),i=0;i<=n;i++){var r=t[i];t[i]=t[e-i],t[e-i]=r}}},{key:"removeNull",value:function(t){for(var e=0,n=0;n<t.length;n++)null!==t[n]&&e++;var i=new Array(e).fill(null);if(0===e)return i;for(var r=0,o=0;o<t.length;o++)null!==t[o]&&(i[r++]=t[o]);return i}},{key:"copyDeep",value:function(){if(1===arguments.length){for(var t=arguments[0],e=new Array(t.length).fill(null),n=0;n<t.length;n++)e[n]=t[n].copy();return e}if(5===arguments.length)for(var i=arguments[0],r=arguments[1],o=arguments[2],s=arguments[3],a=arguments[4],l=0;l<a;l++)o[s+l]=i[r+l].copy()}},{key:"isEqualReversed",value:function(t,e){for(var n=0;n<t.length;n++){var i=t[n],r=e[t.length-n-1];if(0!==i.compareTo(r))return!1}return!0}},{key:"envelope",value:function(t){for(var e=new X,n=0;n<t.length;n++)e.expandToInclude(t[n]);return e}},{key:"toCoordinateArray",value:function(e){return e.toArray(t.coordArrayType)}},{key:"dimension",value:function(t){if(null===t||0===t.length)return 3;var e,n=0,i=s(t);try{for(i.s();!(e=i.n()).done;){var r=e.value;n=Math.max(n,Vt.dimension(r))}}catch(o){i.e(o)}finally{i.f()}return n}},{key:"atLeastNCoordinatesOrNothing",value:function(t,e){return e.length>=t?e:[]}},{key:"indexOf",value:function(t,e){for(var n=0;n<e.length;n++)if(t.equals(e[n]))return n;return-1}},{key:"increasingDirection",value:function(t){for(var e=0;e<Math.trunc(t.length/2);e++){var n=t.length-1-e,i=t[e].compareTo(t[n]);if(0!==i)return i}return 1}},{key:"compare",value:function(t,e){for(var n=0;n<t.length&&n<e.length;){var i=t[n].compareTo(e[n]);if(0!==i)return i;n++}return n<e.length?-1:n<t.length?1:0}},{key:"minCoordinate",value:function(t){for(var e=null,n=0;n<t.length;n++)(null===e||e.compareTo(t[n])>0)&&(e=t[n]);return e}},{key:"extract",value:function(t,e,n){e=kt.clamp(e,0,t.length);var i=(n=kt.clamp(n,-1,t.length))-e+1;n<0&&(i=0),e>=t.length&&(i=0),n<e&&(i=0);var r=new Array(i).fill(null);if(0===i)return r;for(var o=0,s=e;s<=n;s++)r[o++]=t[s];return r}}])}(),Wt=o(function t(){n(this,t)},[{key:"compare",value:function(t,e){var n=t,i=e;return Kt.compare(n,i)}},{key:"interfaces_",get:function(){return[A]}}]),Zt=o(function t(){n(this,t)},[{key:"compare",value:function(t,e){var n=t,i=e;if(n.length<i.length)return-1;if(n.length>i.length)return 1;if(0===n.length)return 0;var r=Kt.compare(n,i);return Kt.isEqualReversed(n,i)?0:r}},{key:"OLDcompare",value:function(t,e){var n=t,i=e;if(n.length<i.length)return-1;if(n.length>i.length)return 1;if(0===n.length)return 0;for(var r=Kt.increasingDirection(n),o=Kt.increasingDirection(i),s=r>0?0:n.length-1,a=o>0?0:n.length-1,l=0;l<n.length;l++){var u=n[s].compareTo(i[a]);if(0!==u)return u;s+=r,a+=o}return 0}},{key:"interfaces_",get:function(){return[A]}}]);Kt.ForwardComparator=Wt,Kt.BidirectionalComparator=Zt,Kt.coordArrayType=new Array(0).fill(null);var Jt=o(function t(e){n(this,t),this.str=e},[{key:"append",value:function(t){this.str+=t}},{key:"setCharAt",value:function(t,e){this.str=this.str.substr(0,t)+e+this.str.substr(t+1)}},{key:"toString",value:function(){return this.str}}]),$t=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getM",value:function(t){return this.hasM()?this._coordinates[t].getM():O.NaN}},{key:"setOrdinate",value:function(t,e,n){switch(e){case ht.X:this._coordinates[t].x=n;break;case ht.Y:this._coordinates[t].y=n;break;default:this._coordinates[t].setOrdinate(e,n)}}},{key:"getZ",value:function(t){return this.hasZ()?this._coordinates[t].getZ():O.NaN}},{key:"size",value:function(){return this._coordinates.length}},{key:"getOrdinate",value:function(t,e){switch(e){case ht.X:return this._coordinates[t].x;case ht.Y:return this._coordinates[t].y;default:return this._coordinates[t].getOrdinate(e)}}},{key:"getCoordinate",value:function(){if(1===arguments.length){var t=arguments[0];return this._coordinates[t]}if(2===arguments.length){var e=arguments[0];arguments[1].setCoordinate(this._coordinates[e])}}},{key:"getCoordinateCopy",value:function(t){var e=this.createCoordinate();return e.setCoordinate(this._coordinates[t]),e}},{key:"createCoordinate",value:function(){return Vt.create(this.getDimension(),this.getMeasures())}},{key:"getDimension",value:function(){return this._dimension}},{key:"getX",value:function(t){return this._coordinates[t].x}},{key:"getMeasures",value:function(){return this._measures}},{key:"expandEnvelope",value:function(t){for(var e=0;e<this._coordinates.length;e++)t.expandToInclude(this._coordinates[e]);return t}},{key:"copy",value:function(){for(var e=new Array(this.size()).fill(null),n=0;n<this._coordinates.length;n++){var i=this.createCoordinate();i.setCoordinate(this._coordinates[n]),e[n]=i}return new t(e,this._dimension,this._measures)}},{key:"toString",value:function(){if(this._coordinates.length>0){var t=new Jt(17*this._coordinates.length);t.append("("),t.append(this._coordinates[0]);for(var e=1;e<this._coordinates.length;e++)t.append(", "),t.append(this._coordinates[e]);return t.append(")"),t.toString()}return"()"}},{key:"getY",value:function(t){return this._coordinates[t].y}},{key:"toCoordinateArray",value:function(){return this._coordinates}},{key:"interfaces_",get:function(){return[ht,w]}}],[{key:"constructor_",value:function(){if(this._dimension=3,this._measures=0,this._coordinates=null,1===arguments.length){if(arguments[0]instanceof Array){var e=arguments[0];t.constructor_.call(this,e,Kt.dimension(e),Kt.measures(e))}else if(Number.isInteger(arguments[0])){var n=arguments[0];this._coordinates=new Array(n).fill(null);for(var i=0;i<n;i++)this._coordinates[i]=new Y}else if(rt(arguments[0],ht)){var r=arguments[0];if(null===r)return this._coordinates=new Array(0).fill(null),null;this._dimension=r.getDimension(),this._measures=r.getMeasures(),this._coordinates=new Array(r.size()).fill(null);for(var o=0;o<this._coordinates.length;o++)this._coordinates[o]=r.getCoordinateCopy(o)}}else if(2===arguments.length){if(arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var s=arguments[0],a=arguments[1];t.constructor_.call(this,s,a,Kt.measures(s))}else if(Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var l=arguments[0],u=arguments[1];this._coordinates=new Array(l).fill(null),this._dimension=u;for(var h=0;h<l;h++)this._coordinates[h]=Vt.create(u)}}else if(3===arguments.length)if(Number.isInteger(arguments[2])&&arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var c=arguments[0],f=arguments[1],g=arguments[2];this._dimension=f,this._measures=g,this._coordinates=null===c?new Array(0).fill(null):c}else if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var d=arguments[0],p=arguments[1],y=arguments[2];this._coordinates=new Array(d).fill(null),this._dimension=p,this._measures=y;for(var m=0;m<d;m++)this._coordinates[m]=this.createCoordinate()}}}])}(),Qt=function(){function t(){n(this,t)}return o(t,[{key:"readResolve",value:function(){return t.instance()}},{key:"create",value:function(){if(1===arguments.length){if(arguments[0]instanceof Array)return new $t(arguments[0]);if(rt(arguments[0],ht))return new $t(arguments[0])}else{if(2===arguments.length){var t=arguments[1];return t>3&&(t=3),t<2&&(t=2),new $t(arguments[0],t)}if(3===arguments.length){var e=arguments[2],n=arguments[1]-e;return e>1&&(e=1),n>3&&(n=3),n<2&&(n=2),new $t(arguments[0],n+e,e)}}}},{key:"interfaces_",get:function(){return[Et,w]}}],[{key:"instance",value:function(){return t.instanceObject}}])}();Qt.instanceObject=new Qt;var te=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"copyInternal",value:function(){for(var t=new Array(this._geometries.length).fill(null),e=0;e<t.length;e++)t[e]=this._geometries[e].copy();return new i(t,this._factory)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof q){var t=arguments[0],e=arguments[1];return!!this.isEquivalentClass(t)&&f(i,"equalsExact",this,1).call(this,t,e)}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"getTypeCode",value:function(){return q.TYPECODE_MULTIPOLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();for(var t=new pt,e=0;e<this._geometries.length;e++)for(var n=this._geometries[e].getBoundary(),i=0;i<n.getNumGeometries();i++)t.add(n.getGeometryN(i));var r=new Array(t.size()).fill(null);return this.getFactory().createMultiLineString(t.toArray(r))}},{key:"getGeometryType",value:function(){return q.TYPENAME_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[At]}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];zt.constructor_.call(this,t,e)}}])}(zt),ee=o(function t(){n(this,t)},[{key:"get",value:function(){}},{key:"put",value:function(){}},{key:"size",value:function(){}},{key:"values",value:function(){}},{key:"entrySet",value:function(){}}]),ne=function(t){function i(){var t;return n(this,i),(t=e(this,i)).map=new Map,t}return u(i,t),o(i,[{key:"get",value:function(t){return this.map.get(t)||null}},{key:"put",value:function(t,e){return this.map.set(t,e),e}},{key:"values",value:function(){for(var t=new pt,e=this.map.values(),n=e.next();!n.done;)t.add(n.value),n=e.next();return t}},{key:"entrySet",value:function(){var t=new J;return this.map.entries().forEach(function(e){return t.add(e)}),t}},{key:"size",value:function(){return this.map.size()}}])}(ee),ie=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"equals",value:function(e){if(!(e instanceof t))return!1;var n=e;return this._modelType===n._modelType&&this._scale===n._scale}},{key:"compareTo",value:function(t){var e=t,n=this.getMaximumSignificantDigits(),i=e.getMaximumSignificantDigits();return st.compare(n,i)}},{key:"getScale",value:function(){return this._scale}},{key:"isFloating",value:function(){return this._modelType===t.FLOATING||this._modelType===t.FLOATING_SINGLE}},{key:"getType",value:function(){return this._modelType}},{key:"toString",value:function(){var e="UNKNOWN";return this._modelType===t.FLOATING?e="Floating":this._modelType===t.FLOATING_SINGLE?e="Floating-Single":this._modelType===t.FIXED&&(e="Fixed (Scale="+this.getScale()+")"),e}},{key:"makePrecise",value:function(){if("number"==typeof arguments[0]){var e=arguments[0];return O.isNaN(e)||this._modelType===t.FLOATING_SINGLE?e:this._modelType===t.FIXED?Math.round(e*this._scale)/this._scale:e}if(arguments[0]instanceof Y){var n=arguments[0];if(this._modelType===t.FLOATING)return null;n.x=this.makePrecise(n.x),n.y=this.makePrecise(n.y)}}},{key:"getMaximumSignificantDigits",value:function(){var e=16;return this._modelType===t.FLOATING?e=16:this._modelType===t.FLOATING_SINGLE?e=6:this._modelType===t.FIXED&&(e=1+Math.trunc(Math.ceil(Math.log(this.getScale())/Math.log(10)))),e}},{key:"setScale",value:function(t){this._scale=Math.abs(t)}},{key:"interfaces_",get:function(){return[w,x]}}],[{key:"constructor_",value:function(){if(this._modelType=null,this._scale=null,0===arguments.length)this._modelType=t.FLOATING;else if(1===arguments.length)if(arguments[0]instanceof re){var e=arguments[0];this._modelType=e,e===t.FIXED&&this.setScale(1)}else if("number"==typeof arguments[0]){var n=arguments[0];this._modelType=t.FIXED,this.setScale(n)}else if(arguments[0]instanceof t){var i=arguments[0];this._modelType=i._modelType,this._scale=i._scale}}},{key:"mostPrecise",value:function(t,e){return t.compareTo(e)>=0?t:e}}])}(),re=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"readResolve",value:function(){return t.nameToTypeMap.get(this._name)}},{key:"toString",value:function(){return this._name}},{key:"interfaces_",get:function(){return[w]}}],[{key:"constructor_",value:function(){this._name=null;var e=arguments[0];this._name=e,t.nameToTypeMap.put(e,this)}}])}();re.nameToTypeMap=new ne,ie.Type=re,ie.FIXED=new re("FIXED"),ie.FLOATING=new re("FLOATING"),ie.FLOATING_SINGLE=new re("FLOATING SINGLE"),ie.maximumPreciseValue=9007199254740992;var oe=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"copyInternal",value:function(){for(var t=new Array(this._geometries.length).fill(null),e=0;e<t.length;e++)t[e]=this._geometries[e].copy();return new i(t,this._factory)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof q){var t=arguments[0],e=arguments[1];return!!this.isEquivalentClass(t)&&f(i,"equalsExact",this,1).call(this,t,e)}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?It.FALSE:0}},{key:"isClosed",value:function(){if(this.isEmpty())return!1;for(var t=0;t<this._geometries.length;t++)if(!this._geometries[t].isClosed())return!1;return!0}},{key:"getTypeCode",value:function(){return q.TYPECODE_MULTILINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getBoundary",value:function(){throw new W}},{key:"getGeometryType",value:function(){return q.TYPENAME_MULTILINESTRING}},{key:"interfaces_",get:function(){return[Pt]}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];zt.constructor_.call(this,t,e)}}])}(zt),se=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"createEmpty",value:function(t){switch(t){case-1:return this.createGeometryCollection();case 0:return this.createPoint();case 1:return this.createLineString();case 2:return this.createPolygon();default:throw new _("Invalid dimension: "+t)}}},{key:"toGeometry",value:function(t){return t.isNull()?this.createPoint():t.getMinX()===t.getMaxX()&&t.getMinY()===t.getMaxY()?this.createPoint(new Y(t.getMinX(),t.getMinY())):t.getMinX()===t.getMaxX()||t.getMinY()===t.getMaxY()?this.createLineString([new Y(t.getMinX(),t.getMinY()),new Y(t.getMaxX(),t.getMaxY())]):this.createPolygon(this.createLinearRing([new Y(t.getMinX(),t.getMinY()),new Y(t.getMinX(),t.getMaxY()),new Y(t.getMaxX(),t.getMaxY()),new Y(t.getMaxX(),t.getMinY()),new Y(t.getMinX(),t.getMinY())]),null)}},{key:"createLineString",value:function(){if(0===arguments.length)return this.createLineString(this.getCoordinateSequenceFactory().create([]));if(1===arguments.length){if(arguments[0]instanceof Array){var t=arguments[0];return this.createLineString(null!==t?this.getCoordinateSequenceFactory().create(t):null)}if(rt(arguments[0],ht))return new Ct(arguments[0],this)}}},{key:"createMultiLineString",value:function(){return 0===arguments.length?new oe(null,this):1===arguments.length?new oe(arguments[0],this):void 0}},{key:"buildGeometry",value:function(e){for(var n=null,i=!1,r=!1,o=e.iterator();o.hasNext();){var s=o.next(),a=s.getTypeCode();null===n&&(n=a),a!==n&&(i=!0),s instanceof zt&&(r=!0)}if(null===n)return this.createGeometryCollection();if(i||r)return this.createGeometryCollection(t.toGeometryArray(e));var l=e.iterator().next();if(e.size()>1){if(l instanceof Rt)return this.createMultiPolygon(t.toPolygonArray(e));if(l instanceof Ct)return this.createMultiLineString(t.toLineStringArray(e));if(l instanceof Tt)return this.createMultiPoint(t.toPointArray(e));B.shouldNeverReachHere("Unhandled geometry type: "+l.getGeometryType())}return l}},{key:"createMultiPointFromCoords",value:function(t){return this.createMultiPoint(null!==t?this.getCoordinateSequenceFactory().create(t):null)}},{key:"createPoint",value:function(){if(0===arguments.length)return this.createPoint(this.getCoordinateSequenceFactory().create([]));if(1===arguments.length){if(arguments[0]instanceof Y){var t=arguments[0];return this.createPoint(null!==t?this.getCoordinateSequenceFactory().create([t]):null)}if(rt(arguments[0],ht))return new Tt(arguments[0],this)}}},{key:"getCoordinateSequenceFactory",value:function(){return this._coordinateSequenceFactory}},{key:"createPolygon",value:function(){if(0===arguments.length)return this.createPolygon(null,null);if(1===arguments.length){if(rt(arguments[0],ht)){var t=arguments[0];return this.createPolygon(this.createLinearRing(t))}if(arguments[0]instanceof Array){var e=arguments[0];return this.createPolygon(this.createLinearRing(e))}if(arguments[0]instanceof Yt){var n=arguments[0];return this.createPolygon(n,null)}}else if(2===arguments.length)return new Rt(arguments[0],arguments[1],this)}},{key:"getSRID",value:function(){return this._SRID}},{key:"createGeometryCollection",value:function(){return 0===arguments.length?new zt(null,this):1===arguments.length?new zt(arguments[0],this):void 0}},{key:"getPrecisionModel",value:function(){return this._precisionModel}},{key:"createLinearRing",value:function(){if(0===arguments.length)return this.createLinearRing(this.getCoordinateSequenceFactory().create([]));if(1===arguments.length){if(arguments[0]instanceof Array){var t=arguments[0];return this.createLinearRing(null!==t?this.getCoordinateSequenceFactory().create(t):null)}if(rt(arguments[0],ht))return new Yt(arguments[0],this)}}},{key:"createMultiPolygon",value:function(){return 0===arguments.length?new te(null,this):1===arguments.length?new te(arguments[0],this):void 0}},{key:"createMultiPoint",value:function(){if(0===arguments.length)return new Ht(null,this);if(1===arguments.length){if(arguments[0]instanceof Array)return new Ht(arguments[0],this);if(rt(arguments[0],ht)){var t=arguments[0];if(null===t)return this.createMultiPoint(new Array(0).fill(null));for(var e=new Array(t.size()).fill(null),n=0;n<t.size();n++){var i=this.getCoordinateSequenceFactory().create(1,t.getDimension(),t.getMeasures());bt.copy(t,n,i,0,1),e[n]=this.createPoint(i)}return this.createMultiPoint(e)}}}},{key:"interfaces_",get:function(){return[w]}}],[{key:"constructor_",value:function(){if(this._precisionModel=null,this._coordinateSequenceFactory=null,this._SRID=null,0===arguments.length)t.constructor_.call(this,new ie,0);else if(1===arguments.length){if(rt(arguments[0],Et)){var e=arguments[0];t.constructor_.call(this,new ie,0,e)}else if(arguments[0]instanceof ie){var n=arguments[0];t.constructor_.call(this,n,0,t.getDefaultCoordinateSequenceFactory())}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];t.constructor_.call(this,i,r,t.getDefaultCoordinateSequenceFactory())}else if(3===arguments.length){var o=arguments[0],s=arguments[1],a=arguments[2];this._precisionModel=o,this._coordinateSequenceFactory=a,this._SRID=s}}},{key:"toMultiPolygonArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toGeometryArray",value:function(t){if(null===t)return null;var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"getDefaultCoordinateSequenceFactory",value:function(){return Qt.instance()}},{key:"toMultiLineStringArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toLineStringArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toMultiPointArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toLinearRingArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toPointArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toPolygonArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"createPointFromInternalCoord",value:function(t,e){return e.getPrecisionModel().makePrecise(t),e.getFactory().createPoint(t)}}])}(),ae="XY",le="XYZ",ue="XYM",he="XYZM",ce={POINT:"Point",LINE_STRING:"LineString",LINEAR_RING:"LinearRing",POLYGON:"Polygon",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon",GEOMETRY_COLLECTION:"GeometryCollection",CIRCLE:"Circle"},fe="EMPTY",ge=1,de=2,pe=3,ye=4,me=5,ve=6;for(var _e in ce)ce[_e].toUpperCase();var ke=o(function t(e){n(this,t),this.wkt=e,this.index_=-1},[{key:"isAlpha_",value:function(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}},{key:"isNumeric_",value:function(t,e){return t>="0"&&t<="9"||"."==t&&!(void 0!==e&&e)}},{key:"isWhiteSpace_",value:function(t){return" "==t||"\t"==t||"\r"==t||"\n"==t}},{key:"nextChar_",value:function(){return this.wkt.charAt(++this.index_)}},{key:"nextToken",value:function(){var t,e=this.nextChar_(),n=this.index_,i=e;if("("==e)t=de;else if(","==e)t=me;else if(")"==e)t=pe;else if(this.isNumeric_(e)||"-"==e)t=ye,i=this.readNumber_();else if(this.isAlpha_(e))t=ge,i=this.readText_();else{if(this.isWhiteSpace_(e))return this.nextToken();if(""!==e)throw new Error("Unexpected character: "+e);t=ve}return{position:n,value:i,type:t}}},{key:"readNumber_",value:function(){var t,e=this.index_,n=!1,i=!1;do{"."==t?n=!0:"e"!=t&&"E"!=t||(i=!0),t=this.nextChar_()}while(this.isNumeric_(t,n)||!i&&("e"==t||"E"==t)||i&&("-"==t||"+"==t));return parseFloat(this.wkt.substring(e,this.index_--))}},{key:"readText_",value:function(){var t,e=this.index_;do{t=this.nextChar_()}while(this.isAlpha_(t));return this.wkt.substring(e,this.index_--).toUpperCase()}}]),xe=o(function t(e,i){n(this,t),this.lexer_=e,this.token_,this.layout_=ae,this.factory=i},[{key:"consume_",value:function(){this.token_=this.lexer_.nextToken()}},{key:"isTokenType",value:function(t){return this.token_.type==t}},{key:"match",value:function(t){var e=this.isTokenType(t);return e&&this.consume_(),e}},{key:"parse",value:function(){return this.consume_(),this.parseGeometry_()}},{key:"parseGeometryLayout_",value:function(){var t=ae,e=this.token_;if(this.isTokenType(ge)){var n=e.value;"Z"===n?t=le:"M"===n?t=ue:"ZM"===n&&(t=he),t!==ae&&this.consume_()}return t}},{key:"parseGeometryCollectionText_",value:function(){if(this.match(de)){var t=[];do{t.push(this.parseGeometry_())}while(this.match(me));if(this.match(pe))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePointText_",value:function(){if(this.match(de)){var t=this.parsePoint_();if(this.match(pe))return t}else if(this.isEmptyGeometry_())return null;throw new Error(this.formatErrorMessage_())}},{key:"parseLineStringText_",value:function(){if(this.match(de)){var t=this.parsePointList_();if(this.match(pe))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePolygonText_",value:function(){if(this.match(de)){var t=this.parseLineStringTextList_();if(this.match(pe))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiPointText_",value:function(){var t;if(this.match(de)){if(t=this.token_.type==de?this.parsePointTextList_():this.parsePointList_(),this.match(pe))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiLineStringText_",value:function(){if(this.match(de)){var t=this.parseLineStringTextList_();if(this.match(pe))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiPolygonText_",value:function(){if(this.match(de)){var t=this.parsePolygonTextList_();if(this.match(pe))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePoint_",value:function(){for(var t=[],e=this.layout_.length,n=0;n<e;++n){var i=this.token_;if(!this.match(ye))break;t.push(i.value)}if(t.length==e)return t;throw new Error(this.formatErrorMessage_())}},{key:"parsePointList_",value:function(){for(var t=[this.parsePoint_()];this.match(me);)t.push(this.parsePoint_());return t}},{key:"parsePointTextList_",value:function(){for(var t=[this.parsePointText_()];this.match(me);)t.push(this.parsePointText_());return t}},{key:"parseLineStringTextList_",value:function(){for(var t=[this.parseLineStringText_()];this.match(me);)t.push(this.parseLineStringText_());return t}},{key:"parsePolygonTextList_",value:function(){for(var t=[this.parsePolygonText_()];this.match(me);)t.push(this.parsePolygonText_());return t}},{key:"isEmptyGeometry_",value:function(){var t=this.isTokenType(ge)&&this.token_.value==fe;return t&&this.consume_(),t}},{key:"formatErrorMessage_",value:function(){return"Unexpected `"+this.token_.value+"` at position "+this.token_.position+" in `"+this.lexer_.wkt+"`"}},{key:"parseGeometry_",value:function(){var t=this.factory,e=function(t){return i(Y,g(t))},n=function(n){var i=n.map(function(n){return t.createLinearRing(n.map(e))});return i.length>1?t.createPolygon(i[0],i.slice(1)):t.createPolygon(i[0])},r=this.token_;if(this.match(ge)){var o=r.value;if(this.layout_=this.parseGeometryLayout_(),"GEOMETRYCOLLECTION"==o){var s=this.parseGeometryCollectionText_();return t.createGeometryCollection(s)}switch(o){case"POINT":var a=this.parsePointText_();return a?t.createPoint(i(Y,g(a))):t.createPoint();case"LINESTRING":var l=this.parseLineStringText_().map(e);return t.createLineString(l);case"LINEARRING":var u=this.parseLineStringText_().map(e);return t.createLinearRing(u);case"POLYGON":var h=this.parsePolygonText_();return h&&0!==h.length?n(h):t.createPolygon();case"MULTIPOINT":var c=this.parseMultiPointText_();if(!c||0===c.length)return t.createMultiPoint();var f=c.map(e).map(function(e){return t.createPoint(e)});return t.createMultiPoint(f);case"MULTILINESTRING":var d=this.parseMultiLineStringText_().map(function(n){return t.createLineString(n.map(e))});return t.createMultiLineString(d);case"MULTIPOLYGON":var p=this.parseMultiPolygonText_();if(!p||0===p.length)return t.createMultiPolygon();var y=p.map(n);return t.createMultiPolygon(y);default:throw new Error("Invalid geometry type: "+o)}}throw new Error(this.formatErrorMessage_())}}]);function Ee(t){if(t.isEmpty())return"";var e=t.getCoordinate(),n=[e.x,e.y];return void 0===e.z||Number.isNaN(e.z)||n.push(e.z),void 0===e.m||Number.isNaN(e.m)||n.push(e.m),n.join(" ")}function we(t){for(var e=t.getCoordinates().map(function(t){var e=[t.x,t.y];return void 0===t.z||Number.isNaN(t.z)||e.push(t.z),void 0===t.m||Number.isNaN(t.m)||e.push(t.m),e}),n=[],i=0,r=e.length;i<r;++i)n.push(e[i].join(" "));return n.join(", ")}function Me(t){var e=[];e.push("("+we(t.getExteriorRing())+")");for(var n=0,i=t.getNumInteriorRing();n<i;++n)e.push("("+we(t.getInteriorRingN(n))+")");return e.join(", ")}var Pe={Point:Ee,LineString:we,LinearRing:we,Polygon:Me,MultiPoint:function(t){for(var e=[],n=0,i=t.getNumGeometries();n<i;++n)e.push("("+Ee(t.getGeometryN(n))+")");return e.join(", ")},MultiLineString:function(t){for(var e=[],n=0,i=t.getNumGeometries();n<i;++n)e.push("("+we(t.getGeometryN(n))+")");return e.join(", ")},MultiPolygon:function(t){for(var e=[],n=0,i=t.getNumGeometries();n<i;++n)e.push("("+Me(t.getGeometryN(n))+")");return e.join(", ")},GeometryCollection:function(t){for(var e=[],n=0,i=t.getNumGeometries();n<i;++n)e.push(be(t.getGeometryN(n)));return e.join(", ")}};function be(t){var e=t.getGeometryType(),n=Pe[e];e=e.toUpperCase();var i=function(t){var e="";if(t.isEmpty())return e;var n=t.getCoordinate();return void 0===n.z||Number.isNaN(n.z)||(e+="Z"),void 0===n.m||Number.isNaN(n.m)||(e+="M"),e}(t);return i.length>0&&(e+=" "+i),t.isEmpty()?e+" "+fe:e+" ("+n(t)+")"}var Ie=o(function t(e){n(this,t),this.geometryFactory=e||new se,this.precisionModel=this.geometryFactory.getPrecisionModel()},[{key:"read",value:function(t){var e=new ke(t);return new xe(e,this.geometryFactory).parse()}},{key:"write",value:function(t){return be(t)}}]),Se=o(function t(e){n(this,t),this.parser=new Ie(e)},[{key:"write",value:function(t){return this.parser.write(t)}}],[{key:"toLineString",value:function(t,e){if(2!==arguments.length)throw new Error("Not implemented");return"LINESTRING ( "+t.x+" "+t.y+", "+e.x+" "+e.y+" )"}}]),Le=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getIndexAlongSegment",value:function(t,e){return this.computeIntLineIndex(),this._intLineIndex[t][e]}},{key:"getTopologySummary",value:function(){var t=new Jt;return this.isEndPoint()&&t.append(" endpoint"),this._isProper&&t.append(" proper"),this.isCollinear()&&t.append(" collinear"),t.toString()}},{key:"computeIntersection",value:function(t,e,n,i){this._inputLines[0][0]=t,this._inputLines[0][1]=e,this._inputLines[1][0]=n,this._inputLines[1][1]=i,this._result=this.computeIntersect(t,e,n,i)}},{key:"getIntersectionNum",value:function(){return this._result}},{key:"computeIntLineIndex",value:function(){if(0===arguments.length)null===this._intLineIndex&&(this._intLineIndex=Array(2).fill().map(function(){return Array(2)}),this.computeIntLineIndex(0),this.computeIntLineIndex(1));else if(1===arguments.length){var t=arguments[0];this.getEdgeDistance(t,0)>this.getEdgeDistance(t,1)?(this._intLineIndex[t][0]=0,this._intLineIndex[t][1]=1):(this._intLineIndex[t][0]=1,this._intLineIndex[t][1]=0)}}},{key:"isProper",value:function(){return this.hasIntersection()&&this._isProper}},{key:"setPrecisionModel",value:function(t){this._precisionModel=t}},{key:"isInteriorIntersection",value:function(){if(0===arguments.length)return!!this.isInteriorIntersection(0)||!!this.isInteriorIntersection(1);if(1===arguments.length){for(var t=arguments[0],e=0;e<this._result;e++)if(!this._intPt[e].equals2D(this._inputLines[t][0])&&!this._intPt[e].equals2D(this._inputLines[t][1]))return!0;return!1}}},{key:"getIntersection",value:function(t){return this._intPt[t]}},{key:"isEndPoint",value:function(){return this.hasIntersection()&&!this._isProper}},{key:"hasIntersection",value:function(){return this._result!==t.NO_INTERSECTION}},{key:"getEdgeDistance",value:function(e,n){return t.computeEdgeDistance(this._intPt[n],this._inputLines[e][0],this._inputLines[e][1])}},{key:"isCollinear",value:function(){return this._result===t.COLLINEAR_INTERSECTION}},{key:"toString",value:function(){return Se.toLineString(this._inputLines[0][0],this._inputLines[0][1])+" - "+Se.toLineString(this._inputLines[1][0],this._inputLines[1][1])+this.getTopologySummary()}},{key:"getEndpoint",value:function(t,e){return this._inputLines[t][e]}},{key:"isIntersection",value:function(t){for(var e=0;e<this._result;e++)if(this._intPt[e].equals2D(t))return!0;return!1}},{key:"getIntersectionAlongSegment",value:function(t,e){return this.computeIntLineIndex(),this._intPt[this._intLineIndex[t][e]]}}],[{key:"constructor_",value:function(){this._result=null,this._inputLines=Array(2).fill().map(function(){return Array(2)}),this._intPt=new Array(2).fill(null),this._intLineIndex=null,this._isProper=null,this._pa=null,this._pb=null,this._precisionModel=null,this._intPt[0]=new Y,this._intPt[1]=new Y,this._pa=this._intPt[0],this._pb=this._intPt[1],this._result=0}},{key:"computeEdgeDistance",value:function(t,e,n){var i=Math.abs(n.x-e.x),r=Math.abs(n.y-e.y),o=-1;if(t.equals(e))o=0;else if(t.equals(n))o=i>r?i:r;else{var s=Math.abs(t.x-e.x),a=Math.abs(t.y-e.y);0!==(o=i>r?s:a)||t.equals(e)||(o=Math.max(s,a))}return B.isTrue(!(0===o&&!t.equals(e)),"Bad distance calculation"),o}},{key:"nonRobustComputeEdgeDistance",value:function(t,e,n){var i=t.x-e.x,r=t.y-e.y,o=Math.sqrt(i*i+r*r);return B.isTrue(!(0===o&&!t.equals(e)),"Invalid distance calculation"),o}}])}();Le.DONT_INTERSECT=0,Le.DO_INTERSECT=1,Le.COLLINEAR=2,Le.NO_INTERSECTION=0,Le.POINT_INTERSECTION=1,Le.COLLINEAR_INTERSECTION=2;var Ce=function(t){function i(){return n(this,i),e(this,i)}return u(i,t),o(i,[{key:"isInSegmentEnvelopes",value:function(t){var e=new X(this._inputLines[0][0],this._inputLines[0][1]),n=new X(this._inputLines[1][0],this._inputLines[1][1]);return e.contains(t)&&n.contains(t)}},{key:"computeIntersection",value:function(){if(3!==arguments.length)return f(i,"computeIntersection",this,1).apply(this,arguments);var t=arguments[0],e=arguments[1],n=arguments[2];if(this._isProper=!1,X.intersects(e,n,t)&&0===ct.index(e,n,t)&&0===ct.index(n,e,t))return this._isProper=!0,(t.equals(e)||t.equals(n))&&(this._isProper=!1),this._result=Le.POINT_INTERSECTION,null;this._result=Le.NO_INTERSECTION}},{key:"intersection",value:function(t,e,n,r){var o=this.intersectionSafe(t,e,n,r);return this.isInSegmentEnvelopes(o)||(o=new Y(i.nearestEndpoint(t,e,n,r))),null!==this._precisionModel&&this._precisionModel.makePrecise(o),o}},{key:"checkDD",value:function(t,e,n,i,r){var o=ut.intersection(t,e,n,i),s=this.isInSegmentEnvelopes(o);_t.out.println("DD in env = "+s+" --------------------- "+o),r.distance(o)>1e-4&&_t.out.println("Distance = "+r.distance(o))}},{key:"intersectionSafe",value:function(t,e,n,r){var o=vt.intersection(t,e,n,r);return null===o&&(o=i.nearestEndpoint(t,e,n,r)),o}},{key:"computeCollinearIntersection",value:function(t,e,n,i){var r=X.intersects(t,e,n),o=X.intersects(t,e,i),s=X.intersects(n,i,t),a=X.intersects(n,i,e);return r&&o?(this._intPt[0]=n,this._intPt[1]=i,Le.COLLINEAR_INTERSECTION):s&&a?(this._intPt[0]=t,this._intPt[1]=e,Le.COLLINEAR_INTERSECTION):r&&s?(this._intPt[0]=n,this._intPt[1]=t,!n.equals(t)||o||a?Le.COLLINEAR_INTERSECTION:Le.POINT_INTERSECTION):r&&a?(this._intPt[0]=n,this._intPt[1]=e,!n.equals(e)||o||s?Le.COLLINEAR_INTERSECTION:Le.POINT_INTERSECTION):o&&s?(this._intPt[0]=i,this._intPt[1]=t,!i.equals(t)||r||a?Le.COLLINEAR_INTERSECTION:Le.POINT_INTERSECTION):o&&a?(this._intPt[0]=i,this._intPt[1]=e,!i.equals(e)||r||s?Le.COLLINEAR_INTERSECTION:Le.POINT_INTERSECTION):Le.NO_INTERSECTION}},{key:"computeIntersect",value:function(t,e,n,i){if(this._isProper=!1,!X.intersects(t,e,n,i))return Le.NO_INTERSECTION;var r=ct.index(t,e,n),o=ct.index(t,e,i);if(r>0&&o>0||r<0&&o<0)return Le.NO_INTERSECTION;var s=ct.index(n,i,t),a=ct.index(n,i,e);return s>0&&a>0||s<0&&a<0?Le.NO_INTERSECTION:0===r&&0===o&&0===s&&0===a?this.computeCollinearIntersection(t,e,n,i):(0===r||0===o||0===s||0===a?(this._isProper=!1,t.equals2D(n)||t.equals2D(i)?this._intPt[0]=t:e.equals2D(n)||e.equals2D(i)?this._intPt[0]=e:0===r?this._intPt[0]=new Y(n):0===o?this._intPt[0]=new Y(i):0===s?this._intPt[0]=new Y(t):0===a&&(this._intPt[0]=new Y(e))):(this._isProper=!0,this._intPt[0]=this.intersection(t,e,n,i)),Le.POINT_INTERSECTION)}}],[{key:"nearestEndpoint",value:function(t,e,n,i){var r=t,o=xt.pointToSegment(t,n,i),s=xt.pointToSegment(e,n,i);return s<o&&(o=s,r=e),(s=xt.pointToSegment(n,t,e))<o&&(o=s,r=n),(s=xt.pointToSegment(i,t,e))<o&&(o=s,r=i),r}}])}(Le),Ne=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"countSegment",value:function(t,e){if(t.x<this._p.x&&e.x<this._p.x)return null;if(this._p.x===e.x&&this._p.y===e.y)return this._isPointOnSegment=!0,null;if(t.y===this._p.y&&e.y===this._p.y){var n=t.x,i=e.x;return n>i&&(n=e.x,i=t.x),this._p.x>=n&&this._p.x<=i&&(this._isPointOnSegment=!0),null}if(t.y>this._p.y&&e.y<=this._p.y||e.y>this._p.y&&t.y<=this._p.y){var r=ct.index(t,e,this._p);if(r===ct.COLLINEAR)return this._isPointOnSegment=!0,null;e.y<t.y&&(r=-r),r===ct.LEFT&&this._crossingCount++}}},{key:"isPointInPolygon",value:function(){return this.getLocation()!==V.EXTERIOR}},{key:"getLocation",value:function(){return this._isPointOnSegment?V.BOUNDARY:this._crossingCount%2==1?V.INTERIOR:V.EXTERIOR}},{key:"isOnSegment",value:function(){return this._isPointOnSegment}}],[{key:"constructor_",value:function(){this._p=null,this._crossingCount=0,this._isPointOnSegment=!1;var t=arguments[0];this._p=t}},{key:"locatePointInRing",value:function(){if(arguments[0]instanceof Y&&rt(arguments[1],ht)){for(var e=arguments[1],n=new t(arguments[0]),i=new Y,r=new Y,o=1;o<e.size();o++)if(e.getCoordinate(o,i),e.getCoordinate(o-1,r),n.countSegment(i,r),n.isOnSegment())return n.getLocation();return n.getLocation()}if(arguments[0]instanceof Y&&arguments[1]instanceof Array){for(var s=arguments[1],a=new t(arguments[0]),l=1;l<s.length;l++){var u=s[l],h=s[l-1];if(a.countSegment(u,h),a.isOnSegment())return a.getLocation()}return a.getLocation()}}}])}(),Te=function(){function t(){n(this,t)}return o(t,null,[{key:"isOnLine",value:function(){if(arguments[0]instanceof Y&&rt(arguments[1],ht)){for(var t=arguments[0],e=arguments[1],n=new Ce,i=new Y,r=new Y,o=e.size(),s=1;s<o;s++)if(e.getCoordinate(s-1,i),e.getCoordinate(s,r),n.computeIntersection(t,i,r),n.hasIntersection())return!0;return!1}if(arguments[0]instanceof Y&&arguments[1]instanceof Array){for(var a=arguments[0],l=arguments[1],u=new Ce,h=1;h<l.length;h++){var c=l[h-1],f=l[h];if(u.computeIntersection(a,c,f),u.hasIntersection())return!0}return!1}}},{key:"locateInRing",value:function(t,e){return Ne.locatePointInRing(t,e)}},{key:"isInRing",value:function(e,n){return t.locateInRing(e,n)!==V.EXTERIOR}}])}(),De=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"setAllLocations",value:function(t){for(var e=0;e<this.location.length;e++)this.location[e]=t}},{key:"isNull",value:function(){for(var t=0;t<this.location.length;t++)if(this.location[t]!==V.NONE)return!1;return!0}},{key:"setAllLocationsIfNull",value:function(t){for(var e=0;e<this.location.length;e++)this.location[e]===V.NONE&&(this.location[e]=t)}},{key:"isLine",value:function(){return 1===this.location.length}},{key:"merge",value:function(t){if(t.location.length>this.location.length){var e=new Array(3).fill(null);e[Q.ON]=this.location[Q.ON],e[Q.LEFT]=V.NONE,e[Q.RIGHT]=V.NONE,this.location=e}for(var n=0;n<this.location.length;n++)this.location[n]===V.NONE&&n<t.location.length&&(this.location[n]=t.location[n])}},{key:"getLocations",value:function(){return this.location}},{key:"flip",value:function(){if(this.location.length<=1)return null;var t=this.location[Q.LEFT];this.location[Q.LEFT]=this.location[Q.RIGHT],this.location[Q.RIGHT]=t}},{key:"toString",value:function(){var t=new ot;return this.location.length>1&&t.append(V.toLocationSymbol(this.location[Q.LEFT])),t.append(V.toLocationSymbol(this.location[Q.ON])),this.location.length>1&&t.append(V.toLocationSymbol(this.location[Q.RIGHT])),t.toString()}},{key:"setLocations",value:function(t,e,n){this.location[Q.ON]=t,this.location[Q.LEFT]=e,this.location[Q.RIGHT]=n}},{key:"get",value:function(t){return t<this.location.length?this.location[t]:V.NONE}},{key:"isArea",value:function(){return this.location.length>1}},{key:"isAnyNull",value:function(){for(var t=0;t<this.location.length;t++)if(this.location[t]===V.NONE)return!0;return!1}},{key:"setLocation",value:function(){if(1===arguments.length){var t=arguments[0];this.setLocation(Q.ON,t)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.location[e]=n}}},{key:"init",value:function(t){this.location=new Array(t).fill(null),this.setAllLocations(V.NONE)}},{key:"isEqualOnSide",value:function(t,e){return this.location[e]===t.location[e]}},{key:"allPositionsEqual",value:function(t){for(var e=0;e<this.location.length;e++)if(this.location[e]!==t)return!1;return!0}}],[{key:"constructor_",value:function(){if(this.location=null,1===arguments.length){if(arguments[0]instanceof Array){var e=arguments[0];this.init(e.length)}else if(Number.isInteger(arguments[0])){var n=arguments[0];this.init(1),this.location[Q.ON]=n}else if(arguments[0]instanceof t){var i=arguments[0];if(this.init(i.location.length),null!==i)for(var r=0;r<this.location.length;r++)this.location[r]=i.location[r]}}else if(3===arguments.length){var o=arguments[0],s=arguments[1],a=arguments[2];this.init(3),this.location[Q.ON]=o,this.location[Q.LEFT]=s,this.location[Q.RIGHT]=a}}}])}(),Oe=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getGeometryCount",value:function(){var t=0;return this.elt[0].isNull()||t++,this.elt[1].isNull()||t++,t}},{key:"setAllLocations",value:function(t,e){this.elt[t].setAllLocations(e)}},{key:"isNull",value:function(t){return this.elt[t].isNull()}},{key:"setAllLocationsIfNull",value:function(){if(1===arguments.length){var t=arguments[0];this.setAllLocationsIfNull(0,t),this.setAllLocationsIfNull(1,t)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.elt[e].setAllLocationsIfNull(n)}}},{key:"isLine",value:function(t){return this.elt[t].isLine()}},{key:"merge",value:function(t){for(var e=0;e<2;e++)null===this.elt[e]&&null!==t.elt[e]?this.elt[e]=new De(t.elt[e]):this.elt[e].merge(t.elt[e])}},{key:"flip",value:function(){this.elt[0].flip(),this.elt[1].flip()}},{key:"getLocation",value:function(){if(1===arguments.length){var t=arguments[0];return this.elt[t].get(Q.ON)}if(2===arguments.length){var e=arguments[0],n=arguments[1];return this.elt[e].get(n)}}},{key:"toString",value:function(){var t=new ot;return null!==this.elt[0]&&(t.append("A:"),t.append(this.elt[0].toString())),null!==this.elt[1]&&(t.append(" B:"),t.append(this.elt[1].toString())),t.toString()}},{key:"isArea",value:function(){if(0===arguments.length)return this.elt[0].isArea()||this.elt[1].isArea();if(1===arguments.length){var t=arguments[0];return this.elt[t].isArea()}}},{key:"isAnyNull",value:function(t){return this.elt[t].isAnyNull()}},{key:"setLocation",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];this.elt[t].setLocation(Q.ON,e)}else if(3===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2];this.elt[n].setLocation(i,r)}}},{key:"isEqualOnSide",value:function(t,e){return this.elt[0].isEqualOnSide(t.elt[0],e)&&this.elt[1].isEqualOnSide(t.elt[1],e)}},{key:"allPositionsEqual",value:function(t,e){return this.elt[t].allPositionsEqual(e)}},{key:"toLine",value:function(t){this.elt[t].isArea()&&(this.elt[t]=new De(this.elt[t].location[0]))}}],[{key:"constructor_",value:function(){if(this.elt=new Array(2).fill(null),1===arguments.length){if(Number.isInteger(arguments[0])){var e=arguments[0];this.elt[0]=new De(e),this.elt[1]=new De(e)}else if(arguments[0]instanceof t){var n=arguments[0];this.elt[0]=new De(n.elt[0]),this.elt[1]=new De(n.elt[1])}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this.elt[0]=new De(V.NONE),this.elt[1]=new De(V.NONE),this.elt[i].setLocation(r)}else if(3===arguments.length){var o=arguments[0],s=arguments[1],a=arguments[2];this.elt[0]=new De(o,s,a),this.elt[1]=new De(o,s,a)}else if(4===arguments.length){var l=arguments[0],u=arguments[1],h=arguments[2],c=arguments[3];this.elt[0]=new De(V.NONE,V.NONE,V.NONE),this.elt[1]=new De(V.NONE,V.NONE,V.NONE),this.elt[l].setLocations(u,h,c)}}},{key:"toLineLabel",value:function(e){for(var n=new t(V.NONE),i=0;i<2;i++)n.setLocation(i,e.getLocation(i));return n}}])}(),Ae=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"computeRing",value:function(){if(null!==this._ring)return null;for(var t=new Array(this._pts.size()).fill(null),e=0;e<this._pts.size();e++)t[e]=this._pts.get(e);this._ring=this._geometryFactory.createLinearRing(t),this._isHole=ct.isCCW(this._ring.getCoordinates())}},{key:"isIsolated",value:function(){return 1===this._label.getGeometryCount()}},{key:"computePoints",value:function(t){this._startDe=t;var e=t,n=!0;do{if(null===e)throw new gt("Found null DirectedEdge");if(e.getEdgeRing()===this)throw new gt("Directed Edge visited twice during ring-building at "+e.getCoordinate());this._edges.add(e);var i=e.getLabel();B.isTrue(i.isArea()),this.mergeLabel(i),this.addPoints(e.getEdge(),e.isForward(),n),n=!1,this.setEdgeRing(e,this),e=this.getNext(e)}while(e!==this._startDe)}},{key:"getLinearRing",value:function(){return this._ring}},{key:"getCoordinate",value:function(t){return this._pts.get(t)}},{key:"computeMaxNodeDegree",value:function(){this._maxNodeDegree=0;var t=this._startDe;do{var e=t.getNode().getEdges().getOutgoingDegree(this);e>this._maxNodeDegree&&(this._maxNodeDegree=e),t=this.getNext(t)}while(t!==this._startDe);this._maxNodeDegree*=2}},{key:"addPoints",value:function(t,e,n){var i=t.getCoordinates();if(e){var r=1;n&&(r=0);for(var o=r;o<i.length;o++)this._pts.add(i[o])}else{var s=i.length-2;n&&(s=i.length-1);for(var a=s;a>=0;a--)this._pts.add(i[a])}}},{key:"isHole",value:function(){return this._isHole}},{key:"setInResult",value:function(){var t=this._startDe;do{t.getEdge().setInResult(!0),t=t.getNext()}while(t!==this._startDe)}},{key:"containsPoint",value:function(t){var e=this.getLinearRing();if(!e.getEnvelopeInternal().contains(t))return!1;if(!Te.isInRing(t,e.getCoordinates()))return!1;for(var n=this._holes.iterator();n.hasNext();)if(n.next().containsPoint(t))return!1;return!0}},{key:"addHole",value:function(t){this._holes.add(t)}},{key:"isShell",value:function(){return null===this._shell}},{key:"getLabel",value:function(){return this._label}},{key:"getEdges",value:function(){return this._edges}},{key:"getMaxNodeDegree",value:function(){return this._maxNodeDegree<0&&this.computeMaxNodeDegree(),this._maxNodeDegree}},{key:"getShell",value:function(){return this._shell}},{key:"mergeLabel",value:function(){if(1===arguments.length){var t=arguments[0];this.mergeLabel(t,0),this.mergeLabel(t,1)}else if(2===arguments.length){var e=arguments[1],n=arguments[0].getLocation(e,Q.RIGHT);if(n===V.NONE)return null;if(this._label.getLocation(e)===V.NONE)return this._label.setLocation(e,n),null}}},{key:"setShell",value:function(t){this._shell=t,null!==t&&t.addHole(this)}},{key:"toPolygon",value:function(t){for(var e=new Array(this._holes.size()).fill(null),n=0;n<this._holes.size();n++)e[n]=this._holes.get(n).getLinearRing();return t.createPolygon(this.getLinearRing(),e)}}],[{key:"constructor_",value:function(){if(this._startDe=null,this._maxNodeDegree=-1,this._edges=new pt,this._pts=new pt,this._label=new Oe(V.NONE),this._ring=null,this._isHole=null,this._shell=null,this._holes=new pt,this._geometryFactory=null,0===arguments.length);else if(2===arguments.length){var t=arguments[0],e=arguments[1];this._geometryFactory=e,this.computePoints(t),this.computeRing()}}}]),Re=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"setEdgeRing",value:function(t,e){t.setMinEdgeRing(e)}},{key:"getNext",value:function(t){return t.getNextMin()}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];Ae.constructor_.call(this,t,e)}}])}(Ae),Fe=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"buildMinimalRings",value:function(){var t=new pt,e=this._startDe;do{if(null===e.getMinEdgeRing()){var n=new Re(e,this._geometryFactory);t.add(n)}e=e.getNext()}while(e!==this._startDe);return t}},{key:"setEdgeRing",value:function(t,e){t.setEdgeRing(e)}},{key:"linkDirectedEdgesForMinimalEdgeRings",value:function(){var t=this._startDe;do{t.getNode().getEdges().linkMinimalDirectedEdges(this),t=t.getNext()}while(t!==this._startDe)}},{key:"getNext",value:function(t){return t.getNext()}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];Ae.constructor_.call(this,t,e)}}])}(Ae),Be=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"setVisited",value:function(t){this._isVisited=t}},{key:"setInResult",value:function(t){this._isInResult=t}},{key:"isCovered",value:function(){return this._isCovered}},{key:"isCoveredSet",value:function(){return this._isCoveredSet}},{key:"setLabel",value:function(t){this._label=t}},{key:"getLabel",value:function(){return this._label}},{key:"setCovered",value:function(t){this._isCovered=t,this._isCoveredSet=!0}},{key:"updateIM",value:function(t){B.isTrue(this._label.getGeometryCount()>=2,"found partial label"),this.computeIM(t)}},{key:"isInResult",value:function(){return this._isInResult}},{key:"isVisited",value:function(){return this._isVisited}}],[{key:"constructor_",value:function(){if(this._label=null,this._isInResult=!1,this._isCovered=!1,this._isCoveredSet=!1,this._isVisited=!1,0===arguments.length);else if(1===arguments.length){var t=arguments[0];this._label=t}}}]),Ge=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"isIncidentEdgeInResult",value:function(){for(var t=this.getEdges().getEdges().iterator();t.hasNext();)if(t.next().getEdge().isInResult())return!0;return!1}},{key:"isIsolated",value:function(){return 1===this._label.getGeometryCount()}},{key:"getCoordinate",value:function(){return this._coord}},{key:"print",value:function(t){t.println("node "+this._coord+" lbl: "+this._label)}},{key:"computeIM",value:function(t){}},{key:"computeMergedLocation",value:function(t,e){var n=V.NONE;if(n=this._label.getLocation(e),!t.isNull(e)){var i=t.getLocation(e);n!==V.BOUNDARY&&(n=i)}return n}},{key:"setLabel",value:function(){if(2!==arguments.length||!Number.isInteger(arguments[1])||!Number.isInteger(arguments[0]))return f(i,"setLabel",this,1).apply(this,arguments);var t=arguments[0],e=arguments[1];null===this._label?this._label=new Oe(t,e):this._label.setLocation(t,e)}},{key:"getEdges",value:function(){return this._edges}},{key:"mergeLabel",value:function(){if(arguments[0]instanceof i){var t=arguments[0];this.mergeLabel(t._label)}else if(arguments[0]instanceof Oe)for(var e=arguments[0],n=0;n<2;n++){var r=this.computeMergedLocation(e,n);this._label.getLocation(n)===V.NONE&&this._label.setLocation(n,r)}}},{key:"add",value:function(t){this._edges.insert(t),t.setNode(this)}},{key:"setLabelBoundary",value:function(t){if(null===this._label)return null;var e=V.NONE;null!==this._label&&(e=this._label.getLocation(t));var n=null;switch(e){case V.BOUNDARY:n=V.INTERIOR;break;case V.INTERIOR:default:n=V.BOUNDARY}this._label.setLocation(t,n)}}],[{key:"constructor_",value:function(){this._coord=null,this._edges=null;var t=arguments[0],e=arguments[1];this._coord=t,this._edges=e,this._label=new Oe(0,V.NONE)}}])}(Be),ze=function(t){function i(){return n(this,i),e(this,i,arguments)}return u(i,t),o(i)}(ee);function He(t){return null==t?0:t.color}function Ye(t){return null==t?null:t.parent}function Ue(t,e){null!==t&&(t.color=e)}function Xe(t){return null==t?null:t.left}function qe(t){return null==t?null:t.right}var Ve=function(t){function i(){var t;return n(this,i),(t=e(this,i)).root_=null,t.size_=0,t}return u(i,t),o(i,[{key:"get",value:function(t){for(var e=this.root_;null!==e;){var n=t.compareTo(e.key);if(n<0)e=e.left;else{if(!(n>0))return e.value;e=e.right}}return null}},{key:"put",value:function(t,e){if(null===this.root_)return this.root_={key:t,value:e,left:null,right:null,parent:null,color:0,getValue:function(){return this.value},getKey:function(){return this.key}},this.size_=1,null;var n,i,r=this.root_;do{if(n=r,(i=t.compareTo(r.key))<0)r=r.left;else{if(!(i>0)){var o=r.value;return r.value=e,o}r=r.right}}while(null!==r);var s={key:t,left:null,right:null,value:e,parent:n,color:0,getValue:function(){return this.value},getKey:function(){return this.key}};return i<0?n.left=s:n.right=s,this.fixAfterInsertion(s),this.size_++,null}},{key:"fixAfterInsertion",value:function(t){var e;for(t.color=1;null!=t&&t!==this.root_&&1===t.parent.color;)Ye(t)===Xe(Ye(Ye(t)))?1===He(e=qe(Ye(Ye(t))))?(Ue(Ye(t),0),Ue(e,0),Ue(Ye(Ye(t)),1),t=Ye(Ye(t))):(t===qe(Ye(t))&&(t=Ye(t),this.rotateLeft(t)),Ue(Ye(t),0),Ue(Ye(Ye(t)),1),this.rotateRight(Ye(Ye(t)))):1===He(e=Xe(Ye(Ye(t))))?(Ue(Ye(t),0),Ue(e,0),Ue(Ye(Ye(t)),1),t=Ye(Ye(t))):(t===Xe(Ye(t))&&(t=Ye(t),this.rotateRight(t)),Ue(Ye(t),0),Ue(Ye(Ye(t)),1),this.rotateLeft(Ye(Ye(t))));this.root_.color=0}},{key:"values",value:function(){var t=new pt,e=this.getFirstEntry();if(null!==e)for(t.add(e.value);null!==(e=i.successor(e));)t.add(e.value);return t}},{key:"entrySet",value:function(){var t=new J,e=this.getFirstEntry();if(null!==e)for(t.add(e);null!==(e=i.successor(e));)t.add(e);return t}},{key:"rotateLeft",value:function(t){if(null!=t){var e=t.right;t.right=e.left,null!=e.left&&(e.left.parent=t),e.parent=t.parent,null==t.parent?this.root_=e:t.parent.left===t?t.parent.left=e:t.parent.right=e,e.left=t,t.parent=e}}},{key:"rotateRight",value:function(t){if(null!=t){var e=t.left;t.left=e.right,null!=e.right&&(e.right.parent=t),e.parent=t.parent,null==t.parent?this.root_=e:t.parent.right===t?t.parent.right=e:t.parent.left=e,e.right=t,t.parent=e}}},{key:"getFirstEntry",value:function(){var t=this.root_;if(null!=t)for(;null!=t.left;)t=t.left;return t}},{key:"size",value:function(){return this.size_}},{key:"containsKey",value:function(t){for(var e=this.root_;null!==e;){var n=t.compareTo(e.key);if(n<0)e=e.left;else{if(!(n>0))return!0;e=e.right}}return!1}}],[{key:"successor",value:function(t){var e;if(null===t)return null;if(null!==t.right){for(e=t.right;null!==e.left;)e=e.left;return e}e=t.parent;for(var n=t;null!==e&&n===e.right;)n=e,e=e.parent;return e}}])}(ze),je=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"find",value:function(t){return this.nodeMap.get(t)}},{key:"addNode",value:function(){if(arguments[0]instanceof Y){var t=arguments[0],e=this.nodeMap.get(t);return null===e&&(e=this.nodeFact.createNode(t),this.nodeMap.put(t,e)),e}if(arguments[0]instanceof Ge){var n=arguments[0],i=this.nodeMap.get(n.getCoordinate());return null===i?(this.nodeMap.put(n.getCoordinate(),n),n):(i.mergeLabel(n),i)}}},{key:"print",value:function(t){for(var e=this.iterator();e.hasNext();)e.next().print(t)}},{key:"iterator",value:function(){return this.nodeMap.values().iterator()}},{key:"values",value:function(){return this.nodeMap.values()}},{key:"getBoundaryNodes",value:function(t){for(var e=new pt,n=this.iterator();n.hasNext();){var i=n.next();i.getLabel().getLocation(t)===V.BOUNDARY&&e.add(i)}return e}},{key:"add",value:function(t){var e=t.getCoordinate();this.addNode(e).add(t)}}],[{key:"constructor_",value:function(){this.nodeMap=new Ve,this.nodeFact=null;var t=arguments[0];this.nodeFact=t}}]),Ke=function(){function t(){n(this,t)}return o(t,null,[{key:"isNorthern",value:function(e){return e===t.NE||e===t.NW}},{key:"isOpposite",value:function(t,e){return t!==e&&2==(t-e+4)%4}},{key:"commonHalfPlane",value:function(t,e){if(t===e)return t;if(2==(t-e+4)%4)return-1;var n=t<e?t:e;return 0===n&&3===(t>e?t:e)?3:n}},{key:"isInHalfPlane",value:function(e,n){return n===t.SE?e===t.SE||e===t.SW:e===n||e===n+1}},{key:"quadrant",value:function(){if("number"==typeof arguments[0]&&"number"==typeof arguments[1]){var e=arguments[0],n=arguments[1];if(0===e&&0===n)throw new _("Cannot compute the quadrant for point ( "+e+", "+n+" )");return e>=0?n>=0?t.NE:t.SE:n>=0?t.NW:t.SW}if(arguments[0]instanceof Y&&arguments[1]instanceof Y){var i=arguments[0],r=arguments[1];if(r.x===i.x&&r.y===i.y)throw new _("Cannot compute the quadrant for two identical points "+i);return r.x>=i.x?r.y>=i.y?t.NE:t.SE:r.y>=i.y?t.NW:t.SW}}}])}();Ke.NE=0,Ke.NW=1,Ke.SW=2,Ke.SE=3;var We=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"compareDirection",value:function(t){return this._dx===t._dx&&this._dy===t._dy?0:this._quadrant>t._quadrant?1:this._quadrant<t._quadrant?-1:ct.index(t._p0,t._p1,this._p1)}},{key:"getDy",value:function(){return this._dy}},{key:"getCoordinate",value:function(){return this._p0}},{key:"setNode",value:function(t){this._node=t}},{key:"print",value:function(t){var e=Math.atan2(this._dy,this._dx),n=this.getClass().getName(),i=n.lastIndexOf("."),r=n.substring(i+1);t.print(" "+r+": "+this._p0+" - "+this._p1+" "+this._quadrant+":"+e+" "+this._label)}},{key:"compareTo",value:function(t){var e=t;return this.compareDirection(e)}},{key:"getDirectedCoordinate",value:function(){return this._p1}},{key:"getDx",value:function(){return this._dx}},{key:"getLabel",value:function(){return this._label}},{key:"getEdge",value:function(){return this._edge}},{key:"getQuadrant",value:function(){return this._quadrant}},{key:"getNode",value:function(){return this._node}},{key:"toString",value:function(){var t=Math.atan2(this._dy,this._dx),e=this.getClass().getName(),n=e.lastIndexOf(".");return" "+e.substring(n+1)+": "+this._p0+" - "+this._p1+" "+this._quadrant+":"+t+" "+this._label}},{key:"computeLabel",value:function(t){}},{key:"init",value:function(t,e){this._p0=t,this._p1=e,this._dx=e.x-t.x,this._dy=e.y-t.y,this._quadrant=Ke.quadrant(this._dx,this._dy),B.isTrue(!(0===this._dx&&0===this._dy),"EdgeEnd with identical endpoints found")}},{key:"interfaces_",get:function(){return[x]}}],[{key:"constructor_",value:function(){if(this._edge=null,this._label=null,this._node=null,this._p0=null,this._p1=null,this._dx=null,this._dy=null,this._quadrant=null,1===arguments.length){var e=arguments[0];this._edge=e}else if(3===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2];t.constructor_.call(this,n,i,r,null)}else if(4===arguments.length){var o=arguments[0],s=arguments[1],a=arguments[2],l=arguments[3];t.constructor_.call(this,o),this.init(s,a),this._label=l}}}])}(),Ze=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"getNextMin",value:function(){return this._nextMin}},{key:"getDepth",value:function(t){return this._depth[t]}},{key:"setVisited",value:function(t){this._isVisited=t}},{key:"computeDirectedLabel",value:function(){this._label=new Oe(this._edge.getLabel()),this._isForward||this._label.flip()}},{key:"getNext",value:function(){return this._next}},{key:"setDepth",value:function(t,e){if(-999!==this._depth[t]&&this._depth[t]!==e)throw new gt("assigned depths do not match",this.getCoordinate());this._depth[t]=e}},{key:"isInteriorAreaEdge",value:function(){for(var t=!0,e=0;e<2;e++)this._label.isArea(e)&&this._label.getLocation(e,Q.LEFT)===V.INTERIOR&&this._label.getLocation(e,Q.RIGHT)===V.INTERIOR||(t=!1);return t}},{key:"setNextMin",value:function(t){this._nextMin=t}},{key:"print",value:function(t){f(i,"print",this,1).call(this,t),t.print(" "+this._depth[Q.LEFT]+"/"+this._depth[Q.RIGHT]),t.print(" ("+this.getDepthDelta()+")"),this._isInResult&&t.print(" inResult")}},{key:"setMinEdgeRing",value:function(t){this._minEdgeRing=t}},{key:"isLineEdge",value:function(){var t=this._label.isLine(0)||this._label.isLine(1),e=!this._label.isArea(0)||this._label.allPositionsEqual(0,V.EXTERIOR),n=!this._label.isArea(1)||this._label.allPositionsEqual(1,V.EXTERIOR);return t&&e&&n}},{key:"setEdgeRing",value:function(t){this._edgeRing=t}},{key:"getMinEdgeRing",value:function(){return this._minEdgeRing}},{key:"getDepthDelta",value:function(){var t=this._edge.getDepthDelta();return this._isForward||(t=-t),t}},{key:"setInResult",value:function(t){this._isInResult=t}},{key:"getSym",value:function(){return this._sym}},{key:"isForward",value:function(){return this._isForward}},{key:"getEdge",value:function(){return this._edge}},{key:"printEdge",value:function(t){this.print(t),t.print(" "),this._isForward?this._edge.print(t):this._edge.printReverse(t)}},{key:"setSym",value:function(t){this._sym=t}},{key:"setVisitedEdge",value:function(t){this.setVisited(t),this._sym.setVisited(t)}},{key:"setEdgeDepths",value:function(t,e){var n=this.getEdge().getDepthDelta();this._isForward||(n=-n);var i=1;t===Q.LEFT&&(i=-1);var r=Q.opposite(t),o=e+n*i;this.setDepth(t,e),this.setDepth(r,o)}},{key:"getEdgeRing",value:function(){return this._edgeRing}},{key:"isInResult",value:function(){return this._isInResult}},{key:"setNext",value:function(t){this._next=t}},{key:"isVisited",value:function(){return this._isVisited}}],[{key:"constructor_",value:function(){this._isForward=null,this._isInResult=!1,this._isVisited=!1,this._sym=null,this._next=null,this._nextMin=null,this._edgeRing=null,this._minEdgeRing=null,this._depth=[0,-999,-999];var t=arguments[0],e=arguments[1];if(We.constructor_.call(this,t),this._isForward=e,e)this.init(t.getCoordinate(0),t.getCoordinate(1));else{var n=t.getNumPoints()-1;this.init(t.getCoordinate(n),t.getCoordinate(n-1))}this.computeDirectedLabel()}},{key:"depthFactor",value:function(t,e){return t===V.EXTERIOR&&e===V.INTERIOR?1:t===V.INTERIOR&&e===V.EXTERIOR?-1:0}}])}(We),Je=o(function t(){n(this,t)},[{key:"createNode",value:function(t){return new Ge(t,null)}}]),$e=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"printEdges",value:function(t){t.println("Edges:");for(var e=0;e<this._edges.size();e++){t.println("edge "+e+":");var n=this._edges.get(e);n.print(t),n.eiList.print(t)}}},{key:"find",value:function(t){return this._nodes.find(t)}},{key:"addNode",value:function(){if(arguments[0]instanceof Ge){var t=arguments[0];return this._nodes.addNode(t)}if(arguments[0]instanceof Y){var e=arguments[0];return this._nodes.addNode(e)}}},{key:"getNodeIterator",value:function(){return this._nodes.iterator()}},{key:"linkResultDirectedEdges",value:function(){for(var t=this._nodes.iterator();t.hasNext();)t.next().getEdges().linkResultDirectedEdges()}},{key:"debugPrintln",value:function(t){_t.out.println(t)}},{key:"isBoundaryNode",value:function(t,e){var n=this._nodes.find(e);if(null===n)return!1;var i=n.getLabel();return null!==i&&i.getLocation(t)===V.BOUNDARY}},{key:"linkAllDirectedEdges",value:function(){for(var t=this._nodes.iterator();t.hasNext();)t.next().getEdges().linkAllDirectedEdges()}},{key:"matchInSameDirection",value:function(t,e,n,i){return!!t.equals(n)&&ct.index(t,e,i)===ct.COLLINEAR&&Ke.quadrant(t,e)===Ke.quadrant(n,i)}},{key:"getEdgeEnds",value:function(){return this._edgeEndList}},{key:"debugPrint",value:function(t){_t.out.print(t)}},{key:"getEdgeIterator",value:function(){return this._edges.iterator()}},{key:"findEdgeInSameDirection",value:function(t,e){for(var n=0;n<this._edges.size();n++){var i=this._edges.get(n),r=i.getCoordinates();if(this.matchInSameDirection(t,e,r[0],r[1]))return i;if(this.matchInSameDirection(t,e,r[r.length-1],r[r.length-2]))return i}return null}},{key:"insertEdge",value:function(t){this._edges.add(t)}},{key:"findEdgeEnd",value:function(t){for(var e=this.getEdgeEnds().iterator();e.hasNext();){var n=e.next();if(n.getEdge()===t)return n}return null}},{key:"addEdges",value:function(t){for(var e=t.iterator();e.hasNext();){var n=e.next();this._edges.add(n);var i=new Ze(n,!0),r=new Ze(n,!1);i.setSym(r),r.setSym(i),this.add(i),this.add(r)}}},{key:"add",value:function(t){this._nodes.add(t),this._edgeEndList.add(t)}},{key:"getNodes",value:function(){return this._nodes.values()}},{key:"findEdge",value:function(t,e){for(var n=0;n<this._edges.size();n++){var i=this._edges.get(n),r=i.getCoordinates();if(t.equals(r[0])&&e.equals(r[1]))return i}return null}}],[{key:"constructor_",value:function(){if(this._edges=new pt,this._nodes=null,this._edgeEndList=new pt,0===arguments.length)this._nodes=new je(new Je);else if(1===arguments.length){var t=arguments[0];this._nodes=new je(t)}}},{key:"linkResultDirectedEdges",value:function(t){for(var e=t.iterator();e.hasNext();)e.next().getEdges().linkResultDirectedEdges()}}]),Qe=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"sortShellsAndHoles",value:function(t,e,n){for(var i=t.iterator();i.hasNext();){var r=i.next();r.isHole()?n.add(r):e.add(r)}}},{key:"computePolygons",value:function(t){for(var e=new pt,n=t.iterator();n.hasNext();){var i=n.next().toPolygon(this._geometryFactory);e.add(i)}return e}},{key:"placeFreeHoles",value:function(e,n){for(var i=n.iterator();i.hasNext();){var r=i.next();if(null===r.getShell()){var o=t.findEdgeRingContaining(r,e);if(null===o)throw new gt("unable to assign hole to a shell",r.getCoordinate(0));r.setShell(o)}}}},{key:"buildMinimalEdgeRings",value:function(t,e,n){for(var i=new pt,r=t.iterator();r.hasNext();){var o=r.next();if(o.getMaxNodeDegree()>2){o.linkDirectedEdgesForMinimalEdgeRings();var s=o.buildMinimalRings(),a=this.findShell(s);null!==a?(this.placePolygonHoles(a,s),e.add(a)):n.addAll(s)}else i.add(o)}return i}},{key:"buildMaximalEdgeRings",value:function(t){for(var e=new pt,n=t.iterator();n.hasNext();){var i=n.next();if(i.isInResult()&&i.getLabel().isArea()&&null===i.getEdgeRing()){var r=new Fe(i,this._geometryFactory);e.add(r),r.setInResult()}}return e}},{key:"placePolygonHoles",value:function(t,e){for(var n=e.iterator();n.hasNext();){var i=n.next();i.isHole()&&i.setShell(t)}}},{key:"getPolygons",value:function(){return this.computePolygons(this._shellList)}},{key:"findShell",value:function(t){for(var e=0,n=null,i=t.iterator();i.hasNext();){var r=i.next();r.isHole()||(n=r,e++)}return B.isTrue(e<=1,"found two shells in MinimalEdgeRing list"),n}},{key:"add",value:function(){if(1===arguments.length){var t=arguments[0];this.add(t.getEdgeEnds(),t.getNodes())}else if(2===arguments.length){var e=arguments[0],n=arguments[1];$e.linkResultDirectedEdges(n);var i=this.buildMaximalEdgeRings(e),r=new pt,o=this.buildMinimalEdgeRings(i,this._shellList,r);this.sortShellsAndHoles(o,this._shellList,r),this.placeFreeHoles(this._shellList,r)}}}],[{key:"constructor_",value:function(){this._geometryFactory=null,this._shellList=new pt;var t=arguments[0];this._geometryFactory=t}},{key:"findEdgeRingContaining",value:function(t,e){for(var n=t.getLinearRing(),i=n.getEnvelopeInternal(),r=n.getCoordinateN(0),o=null,s=null,a=e.iterator();a.hasNext();){var l=a.next(),u=l.getLinearRing(),h=u.getEnvelopeInternal();if(!h.equals(i)&&h.contains(i)){r=Kt.ptNotInList(n.getCoordinates(),u.getCoordinates());var c=!1;Te.isInRing(r,u.getCoordinates())&&(c=!0),c&&(null===o||s.contains(h))&&(s=(o=l).getLinearRing().getEnvelopeInternal())}}return o}}])}(),tn=o(function t(){n(this,t)},[{key:"getBounds",value:function(){}}]),en=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"getItem",value:function(){return this._item}},{key:"getBounds",value:function(){return this._bounds}},{key:"interfaces_",get:function(){return[tn,w]}}],[{key:"constructor_",value:function(){this._bounds=null,this._item=null;var t=arguments[0],e=arguments[1];this._bounds=t,this._item=e}}]),nn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"poll",value:function(){if(this.isEmpty())return null;var t=this._items.get(1);return this._items.set(1,this._items.get(this._size)),this._size-=1,this.reorder(1),t}},{key:"size",value:function(){return this._size}},{key:"reorder",value:function(t){for(var e=null,n=this._items.get(t);2*t<=this._size&&((e=2*t)!==this._size&&this._items.get(e+1).compareTo(this._items.get(e))<0&&e++,this._items.get(e).compareTo(n)<0);t=e)this._items.set(t,this._items.get(e));this._items.set(t,n)}},{key:"clear",value:function(){this._size=0,this._items.clear()}},{key:"peek",value:function(){return this.isEmpty()?null:this._items.get(1)}},{key:"isEmpty",value:function(){return 0===this._size}},{key:"add",value:function(t){this._items.add(null),this._size+=1;var e=this._size;for(this._items.set(0,t);t.compareTo(this._items.get(Math.trunc(e/2)))<0;e/=2)this._items.set(e,this._items.get(Math.trunc(e/2)));this._items.set(e,t)}}],[{key:"constructor_",value:function(){this._size=null,this._items=null,this._size=0,this._items=new pt,this._items.add(null)}}]),rn=o(function t(){n(this,t)},[{key:"insert",value:function(t,e){}},{key:"remove",value:function(t,e){}},{key:"query",value:function(){}}]),on=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"getLevel",value:function(){return this._level}},{key:"size",value:function(){return this._childBoundables.size()}},{key:"getChildBoundables",value:function(){return this._childBoundables}},{key:"addChildBoundable",value:function(t){B.isTrue(null===this._bounds),this._childBoundables.add(t)}},{key:"isEmpty",value:function(){return this._childBoundables.isEmpty()}},{key:"getBounds",value:function(){return null===this._bounds&&(this._bounds=this.computeBounds()),this._bounds}},{key:"interfaces_",get:function(){return[tn,w]}}],[{key:"constructor_",value:function(){if(this._childBoundables=new pt,this._bounds=null,this._level=null,0===arguments.length);else if(1===arguments.length){var t=arguments[0];this._level=t}}}]),sn={reverseOrder:function(){return{compare:function(t,e){return e.compareTo(t)}}},min:function(t){return sn.sort(t),t.get(0)},sort:function(t,e){var n=t.toArray();e?Ot.sort(n,e):Ot.sort(n);for(var i=t.iterator(),r=0,o=n.length;r<o;r++)i.next(),i.set(n[r])},singletonList:function(t){var e=new pt;return e.add(t),e}},an=function(){function t(){n(this,t)}return o(t,null,[{key:"maxDistance",value:function(e,n,i,r,o,s,a,l){var u=t.distance(e,n,o,s);return u=Math.max(u,t.distance(e,n,a,l)),u=Math.max(u,t.distance(i,r,o,s)),Math.max(u,t.distance(i,r,a,l))}},{key:"distance",value:function(t,e,n,i){var r=n-t,o=i-e;return Math.sqrt(r*r+o*o)}},{key:"maximumDistance",value:function(e,n){var i=Math.min(e.getMinX(),n.getMinX()),r=Math.min(e.getMinY(),n.getMinY()),o=Math.max(e.getMaxX(),n.getMaxX()),s=Math.max(e.getMaxY(),n.getMaxY());return t.distance(i,r,o,s)}},{key:"minMaxDistance",value:function(e,n){var i=e.getMinX(),r=e.getMinY(),o=e.getMaxX(),s=e.getMaxY(),a=n.getMinX(),l=n.getMinY(),u=n.getMaxX(),h=n.getMaxY(),c=t.maxDistance(i,r,i,s,a,l,a,h);return c=Math.min(c,t.maxDistance(i,r,i,s,a,l,u,l)),c=Math.min(c,t.maxDistance(i,r,i,s,u,h,a,h)),c=Math.min(c,t.maxDistance(i,r,i,s,u,h,u,l)),c=Math.min(c,t.maxDistance(i,r,o,r,a,l,a,h)),c=Math.min(c,t.maxDistance(i,r,o,r,a,l,u,l)),c=Math.min(c,t.maxDistance(i,r,o,r,u,h,a,h)),c=Math.min(c,t.maxDistance(i,r,o,r,u,h,u,l)),c=Math.min(c,t.maxDistance(o,s,i,s,a,l,a,h)),c=Math.min(c,t.maxDistance(o,s,i,s,a,l,u,l)),c=Math.min(c,t.maxDistance(o,s,i,s,u,h,a,h)),c=Math.min(c,t.maxDistance(o,s,i,s,u,h,u,l)),c=Math.min(c,t.maxDistance(o,s,o,r,a,l,a,h)),c=Math.min(c,t.maxDistance(o,s,o,r,a,l,u,l)),c=Math.min(c,t.maxDistance(o,s,o,r,u,h,a,h)),Math.min(c,t.maxDistance(o,s,o,r,u,h,u,l))}}])}(),ln=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"maximumDistance",value:function(){return an.maximumDistance(this._boundable1.getBounds(),this._boundable2.getBounds())}},{key:"expandToQueue",value:function(e,n){var i=t.isComposite(this._boundable1),r=t.isComposite(this._boundable2);if(i&&r)return t.area(this._boundable1)>t.area(this._boundable2)?(this.expand(this._boundable1,this._boundable2,!1,e,n),null):(this.expand(this._boundable2,this._boundable1,!0,e,n),null);if(i)return this.expand(this._boundable1,this._boundable2,!1,e,n),null;if(r)return this.expand(this._boundable2,this._boundable1,!0,e,n),null;throw new _("neither boundable is composite")}},{key:"isLeaves",value:function(){return!(t.isComposite(this._boundable1)||t.isComposite(this._boundable2))}},{key:"compareTo",value:function(t){var e=t;return this._distance<e._distance?-1:this._distance>e._distance?1:0}},{key:"expand",value:function(e,n,i,r,o){for(var s=e.getChildBoundables().iterator();s.hasNext();){var a=s.next(),l=null;(l=i?new t(n,a,this._itemDistance):new t(a,n,this._itemDistance)).getDistance()<o&&r.add(l)}}},{key:"getBoundable",value:function(t){return 0===t?this._boundable1:this._boundable2}},{key:"getDistance",value:function(){return this._distance}},{key:"distance",value:function(){return this.isLeaves()?this._itemDistance.distance(this._boundable1,this._boundable2):this._boundable1.getBounds().distance(this._boundable2.getBounds())}},{key:"interfaces_",get:function(){return[x]}}],[{key:"constructor_",value:function(){this._boundable1=null,this._boundable2=null,this._distance=null,this._itemDistance=null;var t=arguments[0],e=arguments[1],n=arguments[2];this._boundable1=t,this._boundable2=e,this._itemDistance=n,this._distance=this.distance()}},{key:"area",value:function(t){return t.getBounds().getArea()}},{key:"isComposite",value:function(t){return t instanceof on}}])}(),un=o(function t(){n(this,t)},[{key:"visitItem",value:function(t){}}]),hn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"queryInternal",value:function(){if(rt(arguments[2],un)&&arguments[0]instanceof Object&&arguments[1]instanceof on)for(var t=arguments[0],e=arguments[2],n=arguments[1].getChildBoundables(),i=0;i<n.size();i++){var r=n.get(i);this.getIntersectsOp().intersects(r.getBounds(),t)&&(r instanceof on?this.queryInternal(t,r,e):r instanceof en?e.visitItem(r.getItem()):B.shouldNeverReachHere())}else if(rt(arguments[2],nt)&&arguments[0]instanceof Object&&arguments[1]instanceof on)for(var o=arguments[0],s=arguments[2],a=arguments[1].getChildBoundables(),l=0;l<a.size();l++){var u=a.get(l);this.getIntersectsOp().intersects(u.getBounds(),o)&&(u instanceof on?this.queryInternal(o,u,s):u instanceof en?s.add(u.getItem()):B.shouldNeverReachHere())}}},{key:"getNodeCapacity",value:function(){return this._nodeCapacity}},{key:"lastNode",value:function(t){return t.get(t.size()-1)}},{key:"size",value:function(){if(0===arguments.length)return this.isEmpty()?0:(this.build(),this.size(this._root));if(1===arguments.length){for(var t=0,e=arguments[0].getChildBoundables().iterator();e.hasNext();){var n=e.next();n instanceof on?t+=this.size(n):n instanceof en&&(t+=1)}return t}}},{key:"removeItem",value:function(t,e){for(var n=null,i=t.getChildBoundables().iterator();i.hasNext();){var r=i.next();r instanceof en&&r.getItem()===e&&(n=r)}return null!==n&&(t.getChildBoundables().remove(n),!0)}},{key:"itemsTree",value:function(){if(0===arguments.length){this.build();var t=this.itemsTree(this._root);return null===t?new pt:t}if(1===arguments.length){for(var e=arguments[0],n=new pt,i=e.getChildBoundables().iterator();i.hasNext();){var r=i.next();if(r instanceof on){var o=this.itemsTree(r);null!==o&&n.add(o)}else r instanceof en?n.add(r.getItem()):B.shouldNeverReachHere()}return n.size()<=0?null:n}}},{key:"insert",value:function(t,e){B.isTrue(!this._built,"Cannot insert items into an STR packed R-tree after it has been built."),this._itemBoundables.add(new en(t,e))}},{key:"boundablesAtLevel",value:function(){if(1===arguments.length){var t=arguments[0],e=new pt;return this.boundablesAtLevel(t,this._root,e),e}if(3===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2];if(B.isTrue(n>-2),i.getLevel()===n)return r.add(i),null;for(var o=i.getChildBoundables().iterator();o.hasNext();){var s=o.next();s instanceof on?this.boundablesAtLevel(n,s,r):(B.isTrue(s instanceof en),-1===n&&r.add(s))}return null}}},{key:"query",value:function(){if(1===arguments.length){var t=arguments[0];this.build();var e=new pt;return this.isEmpty()||this.getIntersectsOp().intersects(this._root.getBounds(),t)&&this.queryInternal(t,this._root,e),e}if(2===arguments.length){var n=arguments[0],i=arguments[1];if(this.build(),this.isEmpty())return null;this.getIntersectsOp().intersects(this._root.getBounds(),n)&&this.queryInternal(n,this._root,i)}}},{key:"build",value:function(){if(this._built)return null;this._root=this._itemBoundables.isEmpty()?this.createNode(0):this.createHigherLevels(this._itemBoundables,-1),this._itemBoundables=null,this._built=!0}},{key:"getRoot",value:function(){return this.build(),this._root}},{key:"remove",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];return this.build(),!!this.getIntersectsOp().intersects(this._root.getBounds(),t)&&this.remove(t,this._root,e)}if(3===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2],o=this.removeItem(i,r);if(o)return!0;for(var s=null,a=i.getChildBoundables().iterator();a.hasNext();){var l=a.next();if(this.getIntersectsOp().intersects(l.getBounds(),n)&&l instanceof on&&(o=this.remove(n,l,r))){s=l;break}}return null!==s&&s.getChildBoundables().isEmpty()&&i.getChildBoundables().remove(s),o}}},{key:"createHigherLevels",value:function(t,e){B.isTrue(!t.isEmpty());var n=this.createParentBoundables(t,e+1);return 1===n.size()?n.get(0):this.createHigherLevels(n,e+1)}},{key:"depth",value:function(){if(0===arguments.length)return this.isEmpty()?0:(this.build(),this.depth(this._root));if(1===arguments.length){for(var t=0,e=arguments[0].getChildBoundables().iterator();e.hasNext();){var n=e.next();if(n instanceof on){var i=this.depth(n);i>t&&(t=i)}}return t+1}}},{key:"createParentBoundables",value:function(t,e){B.isTrue(!t.isEmpty());var n=new pt;n.add(this.createNode(e));var i=new pt(t);sn.sort(i,this.getComparator());for(var r=i.iterator();r.hasNext();){var o=r.next();this.lastNode(n).getChildBoundables().size()===this.getNodeCapacity()&&n.add(this.createNode(e)),this.lastNode(n).addChildBoundable(o)}return n}},{key:"isEmpty",value:function(){return this._built?this._root.isEmpty():this._itemBoundables.isEmpty()}},{key:"interfaces_",get:function(){return[w]}}],[{key:"constructor_",value:function(){if(this._root=null,this._built=!1,this._itemBoundables=new pt,this._nodeCapacity=null,0===arguments.length)t.constructor_.call(this,t.DEFAULT_NODE_CAPACITY);else if(1===arguments.length){var e=arguments[0];B.isTrue(e>1,"Node capacity must be greater than 1"),this._nodeCapacity=e}}},{key:"compareDoubles",value:function(t,e){return t>e?1:t<e?-1:0}}])}();hn.IntersectsOp=function(){},hn.DEFAULT_NODE_CAPACITY=10;var cn=o(function t(){n(this,t)},[{key:"distance",value:function(t,e){}}]),fn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"createParentBoundablesFromVerticalSlices",value:function(t,e){B.isTrue(t.length>0);for(var n=new pt,i=0;i<t.length;i++)n.addAll(this.createParentBoundablesFromVerticalSlice(t[i],e));return n}},{key:"nearestNeighbourK",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];return this.nearestNeighbourK(t,O.POSITIVE_INFINITY,e)}if(3===arguments.length){var n=arguments[0],r=arguments[2],o=arguments[1],s=new nn;s.add(n);for(var a=new nn;!s.isEmpty()&&o>=0;){var l=s.poll(),u=l.getDistance();if(u>=o)break;l.isLeaves()?a.size()<r?a.add(l):(a.peek().getDistance()>u&&(a.poll(),a.add(l)),o=a.peek().getDistance()):l.expandToQueue(s,o)}return i.getItems(a)}}},{key:"createNode",value:function(t){return new gn(t)}},{key:"size",value:function(){return 0===arguments.length?f(i,"size",this,1).call(this):f(i,"size",this,1).apply(this,arguments)}},{key:"insert",value:function(){if(!(2===arguments.length&&arguments[1]instanceof Object&&arguments[0]instanceof X))return f(i,"insert",this,1).apply(this,arguments);var t=arguments[0],e=arguments[1];if(t.isNull())return null;f(i,"insert",this,1).call(this,t,e)}},{key:"getIntersectsOp",value:function(){return i.intersectsOp}},{key:"verticalSlices",value:function(t,e){for(var n=Math.trunc(Math.ceil(t.size()/e)),i=new Array(e).fill(null),r=t.iterator(),o=0;o<e;o++){i[o]=new pt;for(var s=0;r.hasNext()&&s<n;){var a=r.next();i[o].add(a),s++}}return i}},{key:"query",value:function(){if(1===arguments.length){var t=arguments[0];return f(i,"query",this,1).call(this,t)}if(2===arguments.length){var e=arguments[0],n=arguments[1];f(i,"query",this,1).call(this,e,n)}}},{key:"getComparator",value:function(){return i.yComparator}},{key:"createParentBoundablesFromVerticalSlice",value:function(t,e){return f(i,"createParentBoundables",this,1).call(this,t,e)}},{key:"remove",value:function(){if(2===arguments.length&&arguments[1]instanceof Object&&arguments[0]instanceof X){var t=arguments[0],e=arguments[1];return f(i,"remove",this,1).call(this,t,e)}return f(i,"remove",this,1).apply(this,arguments)}},{key:"depth",value:function(){return 0===arguments.length?f(i,"depth",this,1).call(this):f(i,"depth",this,1).apply(this,arguments)}},{key:"createParentBoundables",value:function(t,e){B.isTrue(!t.isEmpty());var n=Math.trunc(Math.ceil(t.size()/this.getNodeCapacity())),r=new pt(t);sn.sort(r,i.xComparator);var o=this.verticalSlices(r,Math.trunc(Math.ceil(Math.sqrt(n))));return this.createParentBoundablesFromVerticalSlices(o,e)}},{key:"nearestNeighbour",value:function(){if(1===arguments.length){if(rt(arguments[0],cn)){var t=arguments[0];if(this.isEmpty())return null;var e=new ln(this.getRoot(),this.getRoot(),t);return this.nearestNeighbour(e)}if(arguments[0]instanceof ln){var n=arguments[0],i=O.POSITIVE_INFINITY,r=null,o=new nn;for(o.add(n);!o.isEmpty()&&i>0;){var s=o.poll(),a=s.getDistance();if(a>=i)break;s.isLeaves()?(i=a,r=s):s.expandToQueue(o,i)}return null===r?null:[r.getBoundable(0).getItem(),r.getBoundable(1).getItem()]}}else{if(2===arguments.length){var l=arguments[0],u=arguments[1];if(this.isEmpty()||l.isEmpty())return null;var h=new ln(this.getRoot(),l.getRoot(),u);return this.nearestNeighbour(h)}if(3===arguments.length){var c=arguments[2],f=new en(arguments[0],arguments[1]),g=new ln(this.getRoot(),f,c);return this.nearestNeighbour(g)[0]}if(4===arguments.length){var d=arguments[2],p=arguments[3],y=new en(arguments[0],arguments[1]),m=new ln(this.getRoot(),y,d);return this.nearestNeighbourK(m,p)}}}},{key:"isWithinDistance",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1],n=O.POSITIVE_INFINITY,i=new nn;for(i.add(t);!i.isEmpty();){var r=i.poll(),o=r.getDistance();if(o>e)return!1;if(r.maximumDistance()<=e)return!0;if(r.isLeaves()){if((n=o)<=e)return!0}else r.expandToQueue(i,n)}return!1}if(3===arguments.length){var s=arguments[0],a=arguments[1],l=arguments[2],u=new ln(this.getRoot(),s.getRoot(),a);return this.isWithinDistance(u,l)}}},{key:"interfaces_",get:function(){return[rn,w]}}],[{key:"constructor_",value:function(){if(0===arguments.length)i.constructor_.call(this,i.DEFAULT_NODE_CAPACITY);else if(1===arguments.length){var t=arguments[0];hn.constructor_.call(this,t)}}},{key:"centreX",value:function(t){return i.avg(t.getMinX(),t.getMaxX())}},{key:"avg",value:function(t,e){return(t+e)/2}},{key:"getItems",value:function(t){for(var e=new Array(t.size()).fill(null),n=0;!t.isEmpty();){var i=t.poll();e[n]=i.getBoundable(0).getItem(),n++}return e}},{key:"centreY",value:function(t){return i.avg(t.getMinY(),t.getMaxY())}}])}(hn),gn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"computeBounds",value:function(){for(var t=null,e=this.getChildBoundables().iterator();e.hasNext();){var n=e.next();null===t?t=new X(n.getBounds()):t.expandToInclude(n.getBounds())}return t}}],[{key:"constructor_",value:function(){var t=arguments[0];on.constructor_.call(this,t)}}])}(on);fn.STRtreeNode=gn,fn.xComparator=new(o(function t(){n(this,t)},[{key:"interfaces_",get:function(){return[A]}},{key:"compare",value:function(t,e){return hn.compareDoubles(fn.centreX(t.getBounds()),fn.centreX(e.getBounds()))}}])),fn.yComparator=new(o(function t(){n(this,t)},[{key:"interfaces_",get:function(){return[A]}},{key:"compare",value:function(t,e){return hn.compareDoubles(fn.centreY(t.getBounds()),fn.centreY(e.getBounds()))}}])),fn.intersectsOp=new(o(function t(){n(this,t)},[{key:"interfaces_",get:function(){return[IntersectsOp]}},{key:"intersects",value:function(t,e){return t.intersects(e)}}])),fn.DEFAULT_NODE_CAPACITY=10;var dn=function(){function t(){n(this,t)}return o(t,null,[{key:"relativeSign",value:function(t,e){return t<e?-1:t>e?1:0}},{key:"compare",value:function(e,n,i){if(n.equals2D(i))return 0;var r=t.relativeSign(n.x,i.x),o=t.relativeSign(n.y,i.y);switch(e){case 0:return t.compareValue(r,o);case 1:return t.compareValue(o,r);case 2:return t.compareValue(o,-r);case 3:return t.compareValue(-r,o);case 4:return t.compareValue(-r,-o);case 5:return t.compareValue(-o,-r);case 6:return t.compareValue(-o,r);case 7:return t.compareValue(r,-o)}return B.shouldNeverReachHere("invalid octant value"),0}},{key:"compareValue",value:function(t,e){return t<0?-1:t>0?1:e<0?-1:e>0?1:0}}])}(),pn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"getCoordinate",value:function(){return this.coord}},{key:"print",value:function(t){t.print(this.coord),t.print(" seg # = "+this.segmentIndex)}},{key:"compareTo",value:function(t){var e=t;return this.segmentIndex<e.segmentIndex?-1:this.segmentIndex>e.segmentIndex?1:this.coord.equals2D(e.coord)?0:this._isInterior?e._isInterior?dn.compare(this._segmentOctant,this.coord,e.coord):1:-1}},{key:"isEndPoint",value:function(t){return 0===this.segmentIndex&&!this._isInterior||this.segmentIndex===t}},{key:"toString",value:function(){return this.segmentIndex+":"+this.coord.toString()}},{key:"isInterior",value:function(){return this._isInterior}},{key:"interfaces_",get:function(){return[x]}}],[{key:"constructor_",value:function(){this._segString=null,this.coord=null,this.segmentIndex=null,this._segmentOctant=null,this._isInterior=null;var t=arguments[0],e=arguments[1],n=arguments[2],i=arguments[3];this._segString=t,this.coord=new Y(e),this.segmentIndex=n,this._segmentOctant=i,this._isInterior=!e.equals2D(t.getCoordinate(n))}}]),yn=o(function t(){n(this,t)},[{key:"hasNext",value:function(){}},{key:"next",value:function(){}},{key:"remove",value:function(){}}]),mn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"getSplitCoordinates",value:function(){var t=new jt;this.addEndpoints();for(var e=this.iterator(),n=e.next();e.hasNext();){var i=e.next();this.addEdgeCoordinates(n,i,t),n=i}return t.toCoordinateArray()}},{key:"addCollapsedNodes",value:function(){var t=new pt;this.findCollapsesFromInsertedNodes(t),this.findCollapsesFromExistingVertices(t);for(var e=t.iterator();e.hasNext();){var n=e.next().intValue();this.add(this._edge.getCoordinate(n),n)}}},{key:"createSplitEdgePts",value:function(t,e){var n=e.segmentIndex-t.segmentIndex+2;if(2===n)return[new Y(t.coord),new Y(e.coord)];var i=this._edge.getCoordinate(e.segmentIndex),r=e.isInterior()||!e.coord.equals2D(i);r||n--;var o=new Array(n).fill(null),s=0;o[s++]=new Y(t.coord);for(var a=t.segmentIndex+1;a<=e.segmentIndex;a++)o[s++]=this._edge.getCoordinate(a);return r&&(o[s]=new Y(e.coord)),o}},{key:"print",value:function(t){t.println("Intersections:");for(var e=this.iterator();e.hasNext();)e.next().print(t)}},{key:"findCollapsesFromExistingVertices",value:function(t){for(var e=0;e<this._edge.size()-2;e++){var n=this._edge.getCoordinate(e);this._edge.getCoordinate(e+1);var i=this._edge.getCoordinate(e+2);n.equals2D(i)&&t.add(st.valueOf(e+1))}}},{key:"addEdgeCoordinates",value:function(t,e,n){var i=this.createSplitEdgePts(t,e);n.add(i,!1)}},{key:"iterator",value:function(){return this._nodeMap.values().iterator()}},{key:"addSplitEdges",value:function(t){this.addEndpoints(),this.addCollapsedNodes();for(var e=this.iterator(),n=e.next();e.hasNext();){var i=e.next(),r=this.createSplitEdge(n,i);t.add(r),n=i}}},{key:"findCollapseIndex",value:function(t,e,n){if(!t.coord.equals2D(e.coord))return!1;var i=e.segmentIndex-t.segmentIndex;return e.isInterior()||i--,1===i&&(n[0]=t.segmentIndex+1,!0)}},{key:"findCollapsesFromInsertedNodes",value:function(t){for(var e=new Array(1).fill(null),n=this.iterator(),i=n.next();n.hasNext();){var r=n.next();this.findCollapseIndex(i,r,e)&&t.add(st.valueOf(e[0])),i=r}}},{key:"getEdge",value:function(){return this._edge}},{key:"addEndpoints",value:function(){var t=this._edge.size()-1;this.add(this._edge.getCoordinate(0),0),this.add(this._edge.getCoordinate(t),t)}},{key:"createSplitEdge",value:function(t,e){var n=this.createSplitEdgePts(t,e);return new xn(n,this._edge.getData())}},{key:"add",value:function(t,e){var n=new pn(this._edge,t,e,this._edge.getSegmentOctant(e)),i=this._nodeMap.get(n);return null!==i?(B.isTrue(i.coord.equals2D(t),"Found equal nodes with different coordinates"),i):(this._nodeMap.put(n,n),n)}},{key:"checkSplitEdgesCorrectness",value:function(t){var e=this._edge.getCoordinates(),n=t.get(0).getCoordinate(0);if(!n.equals2D(e[0]))throw new R("bad split edge start point at "+n);var i=t.get(t.size()-1).getCoordinates(),r=i[i.length-1];if(!r.equals2D(e[e.length-1]))throw new R("bad split edge end point at "+r)}}],[{key:"constructor_",value:function(){this._nodeMap=new Ve,this._edge=null;var t=arguments[0];this._edge=t}}]),vn=function(){function t(){n(this,t)}return o(t,null,[{key:"octant",value:function(){if("number"==typeof arguments[0]&&"number"==typeof arguments[1]){var e=arguments[0],n=arguments[1];if(0===e&&0===n)throw new _("Cannot compute the octant for point ( "+e+", "+n+" )");var i=Math.abs(e),r=Math.abs(n);return e>=0?n>=0?i>=r?0:1:i>=r?7:6:n>=0?i>=r?3:2:i>=r?4:5}if(arguments[0]instanceof Y&&arguments[1]instanceof Y){var o=arguments[0],s=arguments[1],a=s.x-o.x,l=s.y-o.y;if(0===a&&0===l)throw new _("Cannot compute the octant for two identical points "+o);return t.octant(a,l)}}}])}(),_n=o(function t(){n(this,t)},[{key:"getCoordinates",value:function(){}},{key:"size",value:function(){}},{key:"getCoordinate",value:function(t){}},{key:"isClosed",value:function(){}},{key:"setData",value:function(t){}},{key:"getData",value:function(){}}]),kn=o(function t(){n(this,t)},[{key:"addIntersection",value:function(t,e){}},{key:"interfaces_",get:function(){return[_n]}}]),xn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getCoordinates",value:function(){return this._pts}},{key:"size",value:function(){return this._pts.length}},{key:"getCoordinate",value:function(t){return this._pts[t]}},{key:"isClosed",value:function(){return this._pts[0].equals(this._pts[this._pts.length-1])}},{key:"getSegmentOctant",value:function(t){return t===this._pts.length-1?-1:this.safeOctant(this.getCoordinate(t),this.getCoordinate(t+1))}},{key:"setData",value:function(t){this._data=t}},{key:"safeOctant",value:function(t,e){return t.equals2D(e)?0:vn.octant(t,e)}},{key:"getData",value:function(){return this._data}},{key:"addIntersection",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];this.addIntersectionNode(t,e)}else if(4===arguments.length){var n=arguments[1],i=arguments[3],r=new Y(arguments[0].getIntersection(i));this.addIntersection(r,n)}}},{key:"toString",value:function(){return Se.toLineString(new $t(this._pts))}},{key:"getNodeList",value:function(){return this._nodeList}},{key:"addIntersectionNode",value:function(t,e){var n=e,i=n+1;if(i<this._pts.length){var r=this._pts[i];t.equals2D(r)&&(n=i)}return this._nodeList.add(t,n)}},{key:"addIntersections",value:function(t,e,n){for(var i=0;i<t.getIntersectionNum();i++)this.addIntersection(t,e,n,i)}},{key:"interfaces_",get:function(){return[kn]}}],[{key:"constructor_",value:function(){this._nodeList=new mn(this),this._pts=null,this._data=null;var t=arguments[0],e=arguments[1];this._pts=t,this._data=e}},{key:"getNodedSubstrings",value:function(){if(1===arguments.length){var e=arguments[0],n=new pt;return t.getNodedSubstrings(e,n),n}if(2===arguments.length)for(var i=arguments[1],r=arguments[0].iterator();r.hasNext();)r.next().getNodeList().addSplitEdges(i)}}])}(),En=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"minX",value:function(){return Math.min(this.p0.x,this.p1.x)}},{key:"orientationIndex",value:function(){if(arguments[0]instanceof t){var e=arguments[0],n=ct.index(this.p0,this.p1,e.p0),i=ct.index(this.p0,this.p1,e.p1);return n>=0&&i>=0||n<=0&&i<=0?Math.max(n,i):0}if(arguments[0]instanceof Y){var r=arguments[0];return ct.index(this.p0,this.p1,r)}}},{key:"toGeometry",value:function(t){return t.createLineString([this.p0,this.p1])}},{key:"isVertical",value:function(){return this.p0.x===this.p1.x}},{key:"equals",value:function(e){if(!(e instanceof t))return!1;var n=e;return this.p0.equals(n.p0)&&this.p1.equals(n.p1)}},{key:"intersection",value:function(t){var e=new Ce;return e.computeIntersection(this.p0,this.p1,t.p0,t.p1),e.hasIntersection()?e.getIntersection(0):null}},{key:"project",value:function(){if(arguments[0]instanceof Y){var e=arguments[0];if(e.equals(this.p0)||e.equals(this.p1))return new Y(e);var n=this.projectionFactor(e),i=new Y;return i.x=this.p0.x+n*(this.p1.x-this.p0.x),i.y=this.p0.y+n*(this.p1.y-this.p0.y),i}if(arguments[0]instanceof t){var r=arguments[0],o=this.projectionFactor(r.p0),s=this.projectionFactor(r.p1);if(o>=1&&s>=1)return null;if(o<=0&&s<=0)return null;var a=this.project(r.p0);o<0&&(a=this.p0),o>1&&(a=this.p1);var l=this.project(r.p1);return s<0&&(l=this.p0),s>1&&(l=this.p1),new t(a,l)}}},{key:"normalize",value:function(){this.p1.compareTo(this.p0)<0&&this.reverse()}},{key:"angle",value:function(){return Math.atan2(this.p1.y-this.p0.y,this.p1.x-this.p0.x)}},{key:"getCoordinate",value:function(t){return 0===t?this.p0:this.p1}},{key:"distancePerpendicular",value:function(t){return xt.pointToLinePerpendicular(t,this.p0,this.p1)}},{key:"minY",value:function(){return Math.min(this.p0.y,this.p1.y)}},{key:"midPoint",value:function(){return t.midPoint(this.p0,this.p1)}},{key:"projectionFactor",value:function(t){if(t.equals(this.p0))return 0;if(t.equals(this.p1))return 1;var e=this.p1.x-this.p0.x,n=this.p1.y-this.p0.y,i=e*e+n*n;return i<=0?O.NaN:((t.x-this.p0.x)*e+(t.y-this.p0.y)*n)/i}},{key:"closestPoints",value:function(t){var e=this.intersection(t);if(null!==e)return[e,e];var n=new Array(2).fill(null),i=O.MAX_VALUE,r=null,o=this.closestPoint(t.p0);i=o.distance(t.p0),n[0]=o,n[1]=t.p0;var s=this.closestPoint(t.p1);(r=s.distance(t.p1))<i&&(i=r,n[0]=s,n[1]=t.p1);var a=t.closestPoint(this.p0);(r=a.distance(this.p0))<i&&(i=r,n[0]=this.p0,n[1]=a);var l=t.closestPoint(this.p1);return(r=l.distance(this.p1))<i&&(i=r,n[0]=this.p1,n[1]=l),n}},{key:"closestPoint",value:function(t){var e=this.projectionFactor(t);return e>0&&e<1?this.project(t):this.p0.distance(t)<this.p1.distance(t)?this.p0:this.p1}},{key:"maxX",value:function(){return Math.max(this.p0.x,this.p1.x)}},{key:"getLength",value:function(){return this.p0.distance(this.p1)}},{key:"compareTo",value:function(t){var e=t,n=this.p0.compareTo(e.p0);return 0!==n?n:this.p1.compareTo(e.p1)}},{key:"reverse",value:function(){var t=this.p0;this.p0=this.p1,this.p1=t}},{key:"equalsTopo",value:function(t){return this.p0.equals(t.p0)&&this.p1.equals(t.p1)||this.p0.equals(t.p1)&&this.p1.equals(t.p0)}},{key:"lineIntersection",value:function(t){return vt.intersection(this.p0,this.p1,t.p0,t.p1)}},{key:"maxY",value:function(){return Math.max(this.p0.y,this.p1.y)}},{key:"pointAlongOffset",value:function(t,e){var n=this.p0.x+t*(this.p1.x-this.p0.x),i=this.p0.y+t*(this.p1.y-this.p0.y),r=this.p1.x-this.p0.x,o=this.p1.y-this.p0.y,s=Math.sqrt(r*r+o*o),a=0,l=0;if(0!==e){if(s<=0)throw new IllegalStateException("Cannot compute offset from zero-length line segment");a=e*r/s,l=e*o/s}return new Y(n-l,i+a)}},{key:"setCoordinates",value:function(){if(1===arguments.length){var t=arguments[0];this.setCoordinates(t.p0,t.p1)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.p0.x=e.x,this.p0.y=e.y,this.p1.x=n.x,this.p1.y=n.y}}},{key:"segmentFraction",value:function(t){var e=this.projectionFactor(t);return e<0?e=0:(e>1||O.isNaN(e))&&(e=1),e}},{key:"toString",value:function(){return"LINESTRING( "+this.p0.x+" "+this.p0.y+", "+this.p1.x+" "+this.p1.y+")"}},{key:"isHorizontal",value:function(){return this.p0.y===this.p1.y}},{key:"reflect",value:function(t){var e=this.p1.getY()-this.p0.getY(),n=this.p0.getX()-this.p1.getX(),i=this.p0.getY()*(this.p1.getX()-this.p0.getX())-this.p0.getX()*(this.p1.getY()-this.p0.getY()),r=e*e+n*n,o=e*e-n*n,s=t.getX(),a=t.getY();return new Y((-o*s-2*e*n*a-2*e*i)/r,(o*a-2*e*n*s-2*n*i)/r)}},{key:"distance",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return xt.segmentToSegment(this.p0,this.p1,e.p0,e.p1)}if(arguments[0]instanceof Y){var n=arguments[0];return xt.pointToSegment(n,this.p0,this.p1)}}},{key:"pointAlong",value:function(t){var e=new Y;return e.x=this.p0.x+t*(this.p1.x-this.p0.x),e.y=this.p0.y+t*(this.p1.y-this.p0.y),e}},{key:"hashCode",value:function(){var t=O.doubleToLongBits(this.p0.x);t^=31*O.doubleToLongBits(this.p0.y);var e=Math.trunc(t)^Math.trunc(t>>32),n=O.doubleToLongBits(this.p1.x);return n^=31*O.doubleToLongBits(this.p1.y),e^Math.trunc(n)^Math.trunc(n>>32)}},{key:"interfaces_",get:function(){return[x,w]}}],[{key:"constructor_",value:function(){if(this.p0=null,this.p1=null,0===arguments.length)t.constructor_.call(this,new Y,new Y);else if(1===arguments.length){var e=arguments[0];t.constructor_.call(this,e.p0,e.p1)}else if(2===arguments.length){var n=arguments[0],i=arguments[1];this.p0=n,this.p1=i}else if(4===arguments.length){var r=arguments[0],o=arguments[1],s=arguments[2],a=arguments[3];t.constructor_.call(this,new Y(r,o),new Y(s,a))}}},{key:"midPoint",value:function(t,e){return new Y((t.x+e.x)/2,(t.y+e.y)/2)}}])}(),wn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"overlap",value:function(){if(2===arguments.length);else if(4===arguments.length){var t=arguments[1],e=arguments[2],n=arguments[3];arguments[0].getLineSegment(t,this._overlapSeg1),e.getLineSegment(n,this._overlapSeg2),this.overlap(this._overlapSeg1,this._overlapSeg2)}}}],[{key:"constructor_",value:function(){this._overlapSeg1=new En,this._overlapSeg2=new En}}]),Mn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"getLineSegment",value:function(t,e){e.p0=this._pts[t],e.p1=this._pts[t+1]}},{key:"computeSelect",value:function(t,e,n,i){var r=this._pts[e],o=this._pts[n];if(n-e==1)return i.select(this,e),null;if(!t.intersects(r,o))return null;var s=Math.trunc((e+n)/2);e<s&&this.computeSelect(t,e,s,i),s<n&&this.computeSelect(t,s,n,i)}},{key:"getCoordinates",value:function(){for(var t=new Array(this._end-this._start+1).fill(null),e=0,n=this._start;n<=this._end;n++)t[e++]=this._pts[n];return t}},{key:"computeOverlaps",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];this.computeOverlaps(this._start,this._end,t,t._start,t._end,e)}else if(6===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2],o=arguments[3],s=arguments[4],a=arguments[5];if(i-n==1&&s-o==1)return a.overlap(this,n,r,o),null;if(!this.overlaps(n,i,r,o,s))return null;var l=Math.trunc((n+i)/2),u=Math.trunc((o+s)/2);n<l&&(o<u&&this.computeOverlaps(n,l,r,o,u,a),u<s&&this.computeOverlaps(n,l,r,u,s,a)),l<i&&(o<u&&this.computeOverlaps(l,i,r,o,u,a),u<s&&this.computeOverlaps(l,i,r,u,s,a))}}},{key:"setId",value:function(t){this._id=t}},{key:"select",value:function(t,e){this.computeSelect(t,this._start,this._end,e)}},{key:"getEnvelope",value:function(){if(null===this._env){var t=this._pts[this._start],e=this._pts[this._end];this._env=new X(t,e)}return this._env}},{key:"overlaps",value:function(t,e,n,i,r){return X.intersects(this._pts[t],this._pts[e],n._pts[i],n._pts[r])}},{key:"getEndIndex",value:function(){return this._end}},{key:"getStartIndex",value:function(){return this._start}},{key:"getContext",value:function(){return this._context}},{key:"getId",value:function(){return this._id}}],[{key:"constructor_",value:function(){this._pts=null,this._start=null,this._end=null,this._env=null,this._context=null,this._id=null;var t=arguments[0],e=arguments[1],n=arguments[2],i=arguments[3];this._pts=t,this._start=e,this._end=n,this._context=i}}]),Pn=function(){function t(){n(this,t)}return o(t,null,[{key:"findChainEnd",value:function(t,e){for(var n=e;n<t.length-1&&t[n].equals2D(t[n+1]);)n++;if(n>=t.length-1)return t.length-1;for(var i=Ke.quadrant(t[n],t[n+1]),r=e+1;r<t.length&&(t[r-1].equals2D(t[r])||Ke.quadrant(t[r-1],t[r])===i);)r++;return r-1}},{key:"getChains",value:function(){if(1===arguments.length){var e=arguments[0];return t.getChains(e,null)}if(2===arguments.length){var n=arguments[0],i=arguments[1],r=new pt,o=0;do{var s=t.findChainEnd(n,o),a=new Mn(n,o,s,i);r.add(a),o=s}while(o<n.length-1);return r}}}])}(),bn=o(function t(){n(this,t)},[{key:"computeNodes",value:function(t){}},{key:"getNodedSubstrings",value:function(){}}]),In=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"setSegmentIntersector",value:function(t){this._segInt=t}},{key:"interfaces_",get:function(){return[bn]}}],[{key:"constructor_",value:function(){if(this._segInt=null,0===arguments.length);else if(1===arguments.length){var t=arguments[0];this.setSegmentIntersector(t)}}}]),Sn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"getMonotoneChains",value:function(){return this._monoChains}},{key:"getNodedSubstrings",value:function(){return xn.getNodedSubstrings(this._nodedSegStrings)}},{key:"getIndex",value:function(){return this._index}},{key:"add",value:function(t){for(var e=Pn.getChains(t.getCoordinates(),t).iterator();e.hasNext();){var n=e.next();n.setId(this._idCounter++),this._index.insert(n.getEnvelope(),n),this._monoChains.add(n)}}},{key:"computeNodes",value:function(t){this._nodedSegStrings=t;for(var e=t.iterator();e.hasNext();)this.add(e.next());this.intersectChains()}},{key:"intersectChains",value:function(){for(var t=new Ln(this._segInt),e=this._monoChains.iterator();e.hasNext();)for(var n=e.next(),i=this._index.query(n.getEnvelope()).iterator();i.hasNext();){var r=i.next();if(r.getId()>n.getId()&&(n.computeOverlaps(r,t),this._nOverlaps++),this._segInt.isDone())return null}}}],[{key:"constructor_",value:function(){if(this._monoChains=new pt,this._index=new fn,this._idCounter=0,this._nodedSegStrings=null,this._nOverlaps=0,0===arguments.length);else if(1===arguments.length){var t=arguments[0];In.constructor_.call(this,t)}}}])}(In),Ln=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"overlap",value:function(){if(4!==arguments.length)return f(i,"overlap",this,1).apply(this,arguments);var t=arguments[1],e=arguments[2],n=arguments[3],r=arguments[0].getContext(),o=e.getContext();this._si.processIntersections(r,t,o,n)}}],[{key:"constructor_",value:function(){this._si=null;var t=arguments[0];this._si=t}}])}(wn);Sn.SegmentOverlapAction=Ln;var Cn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"isDeletable",value:function(t,e,n,i){var r=this._inputLine[t],o=this._inputLine[e],s=this._inputLine[n];return!!this.isConcave(r,o,s)&&!!this.isShallow(r,o,s,i)&&this.isShallowSampled(r,o,t,n,i)}},{key:"deleteShallowConcavities",value:function(){for(var e=1,n=this.findNextNonDeletedIndex(e),i=this.findNextNonDeletedIndex(n),r=!1;i<this._inputLine.length;){var o=!1;this.isDeletable(e,n,i,this._distanceTol)&&(this._isDeleted[n]=t.DELETE,o=!0,r=!0),e=o?i:n,n=this.findNextNonDeletedIndex(e),i=this.findNextNonDeletedIndex(n)}return r}},{key:"isShallowConcavity",value:function(t,e,n,i){return ct.index(t,e,n)===this._angleOrientation&&xt.pointToSegment(e,t,n)<i}},{key:"isShallowSampled",value:function(e,n,i,r,o){var s=Math.trunc((r-i)/t.NUM_PTS_TO_CHECK);s<=0&&(s=1);for(var a=i;a<r;a+=s)if(!this.isShallow(e,n,this._inputLine[a],o))return!1;return!0}},{key:"isConcave",value:function(t,e,n){return ct.index(t,e,n)===this._angleOrientation}},{key:"simplify",value:function(t){this._distanceTol=Math.abs(t),t<0&&(this._angleOrientation=ct.CLOCKWISE),this._isDeleted=new Array(this._inputLine.length).fill(null);var e=!1;do{e=this.deleteShallowConcavities()}while(e);return this.collapseLine()}},{key:"findNextNonDeletedIndex",value:function(e){for(var n=e+1;n<this._inputLine.length&&this._isDeleted[n]===t.DELETE;)n++;return n}},{key:"isShallow",value:function(t,e,n,i){return xt.pointToSegment(e,t,n)<i}},{key:"collapseLine",value:function(){for(var e=new jt,n=0;n<this._inputLine.length;n++)this._isDeleted[n]!==t.DELETE&&e.add(this._inputLine[n]);return e.toCoordinateArray()}}],[{key:"constructor_",value:function(){this._inputLine=null,this._distanceTol=null,this._isDeleted=null,this._angleOrientation=ct.COUNTERCLOCKWISE;var t=arguments[0];this._inputLine=t}},{key:"simplify",value:function(e,n){return new t(e).simplify(n)}}])}();Cn.INIT=0,Cn.DELETE=1,Cn.KEEP=1,Cn.NUM_PTS_TO_CHECK=10;var Nn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getCoordinates",value:function(){return this._ptList.toArray(t.COORDINATE_ARRAY_TYPE)}},{key:"setPrecisionModel",value:function(t){this._precisionModel=t}},{key:"addPt",value:function(t){var e=new Y(t);if(this._precisionModel.makePrecise(e),this.isRedundant(e))return null;this._ptList.add(e)}},{key:"reverse",value:function(){}},{key:"addPts",value:function(t,e){if(e)for(var n=0;n<t.length;n++)this.addPt(t[n]);else for(var i=t.length-1;i>=0;i--)this.addPt(t[i])}},{key:"isRedundant",value:function(t){if(this._ptList.size()<1)return!1;var e=this._ptList.get(this._ptList.size()-1);return t.distance(e)<this._minimimVertexDistance}},{key:"toString",value:function(){return(new se).createLineString(this.getCoordinates()).toString()}},{key:"closeRing",value:function(){if(this._ptList.size()<1)return null;var t=new Y(this._ptList.get(0)),e=this._ptList.get(this._ptList.size()-1);if(t.equals(e))return null;this._ptList.add(t)}},{key:"setMinimumVertexDistance",value:function(t){this._minimimVertexDistance=t}}],[{key:"constructor_",value:function(){this._ptList=null,this._precisionModel=null,this._minimimVertexDistance=0,this._ptList=new pt}}])}();Nn.COORDINATE_ARRAY_TYPE=new Array(0).fill(null);var Tn=function(){function t(){n(this,t)}return o(t,null,[{key:"toDegrees",value:function(t){return 180*t/Math.PI}},{key:"normalize",value:function(e){for(;e>Math.PI;)e-=t.PI_TIMES_2;for(;e<=-Math.PI;)e+=t.PI_TIMES_2;return e}},{key:"angle",value:function(){if(1===arguments.length){var t=arguments[0];return Math.atan2(t.y,t.x)}if(2===arguments.length){var e=arguments[0],n=arguments[1],i=n.x-e.x,r=n.y-e.y;return Math.atan2(r,i)}}},{key:"isAcute",value:function(t,e,n){var i=t.x-e.x,r=t.y-e.y;return i*(n.x-e.x)+r*(n.y-e.y)>0}},{key:"isObtuse",value:function(t,e,n){var i=t.x-e.x,r=t.y-e.y;return i*(n.x-e.x)+r*(n.y-e.y)<0}},{key:"interiorAngle",value:function(e,n,i){var r=t.angle(n,e),o=t.angle(n,i);return Math.abs(o-r)}},{key:"normalizePositive",value:function(e){if(e<0){for(;e<0;)e+=t.PI_TIMES_2;e>=t.PI_TIMES_2&&(e=0)}else{for(;e>=t.PI_TIMES_2;)e-=t.PI_TIMES_2;e<0&&(e=0)}return e}},{key:"angleBetween",value:function(e,n,i){var r=t.angle(n,e),o=t.angle(n,i);return t.diff(r,o)}},{key:"diff",value:function(t,e){var n=null;return(n=t<e?e-t:t-e)>Math.PI&&(n=2*Math.PI-n),n}},{key:"toRadians",value:function(t){return t*Math.PI/180}},{key:"getTurn",value:function(e,n){var i=Math.sin(n-e);return i>0?t.COUNTERCLOCKWISE:i<0?t.CLOCKWISE:t.NONE}},{key:"angleBetweenOriented",value:function(e,n,i){var r=t.angle(n,e),o=t.angle(n,i)-r;return o<=-Math.PI?o+t.PI_TIMES_2:o>Math.PI?o-t.PI_TIMES_2:o}}])}();Tn.PI_TIMES_2=2*Math.PI,Tn.PI_OVER_2=Math.PI/2,Tn.PI_OVER_4=Math.PI/4,Tn.COUNTERCLOCKWISE=ct.COUNTERCLOCKWISE,Tn.CLOCKWISE=ct.CLOCKWISE,Tn.NONE=ct.COLLINEAR;var Dn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"addNextSegment",value:function(t,e){if(this._s0=this._s1,this._s1=this._s2,this._s2=t,this._seg0.setCoordinates(this._s0,this._s1),this.computeOffsetSegment(this._seg0,this._side,this._distance,this._offset0),this._seg1.setCoordinates(this._s1,this._s2),this.computeOffsetSegment(this._seg1,this._side,this._distance,this._offset1),this._s1.equals(this._s2))return null;var n=ct.index(this._s0,this._s1,this._s2),i=n===ct.CLOCKWISE&&this._side===Q.LEFT||n===ct.COUNTERCLOCKWISE&&this._side===Q.RIGHT;0===n?this.addCollinear(e):i?this.addOutsideTurn(n,e):this.addInsideTurn(n,e)}},{key:"addLineEndCap",value:function(t,e){var n=new En(t,e),i=new En;this.computeOffsetSegment(n,Q.LEFT,this._distance,i);var r=new En;this.computeOffsetSegment(n,Q.RIGHT,this._distance,r);var o=e.x-t.x,s=e.y-t.y,a=Math.atan2(s,o);switch(this._bufParams.getEndCapStyle()){case m.CAP_ROUND:this._segList.addPt(i.p1),this.addDirectedFillet(e,a+Math.PI/2,a-Math.PI/2,ct.CLOCKWISE,this._distance),this._segList.addPt(r.p1);break;case m.CAP_FLAT:this._segList.addPt(i.p1),this._segList.addPt(r.p1);break;case m.CAP_SQUARE:var l=new Y;l.x=Math.abs(this._distance)*Math.cos(a),l.y=Math.abs(this._distance)*Math.sin(a);var u=new Y(i.p1.x+l.x,i.p1.y+l.y),h=new Y(r.p1.x+l.x,r.p1.y+l.y);this._segList.addPt(u),this._segList.addPt(h)}}},{key:"getCoordinates",value:function(){return this._segList.getCoordinates()}},{key:"addMitreJoin",value:function(t,e,n,i){var r=vt.intersection(e.p0,e.p1,n.p0,n.p1);if(null!==r&&(i<=0?1:r.distance(t)/Math.abs(i))<=this._bufParams.getMitreLimit())return this._segList.addPt(r),null;this.addLimitedMitreJoin(e,n,i,this._bufParams.getMitreLimit())}},{key:"addOutsideTurn",value:function(e,n){if(this._offset0.p1.distance(this._offset1.p0)<this._distance*t.OFFSET_SEGMENT_SEPARATION_FACTOR)return this._segList.addPt(this._offset0.p1),null;this._bufParams.getJoinStyle()===m.JOIN_MITRE?this.addMitreJoin(this._s1,this._offset0,this._offset1,this._distance):this._bufParams.getJoinStyle()===m.JOIN_BEVEL?this.addBevelJoin(this._offset0,this._offset1):(n&&this._segList.addPt(this._offset0.p1),this.addCornerFillet(this._s1,this._offset0.p1,this._offset1.p0,e,this._distance),this._segList.addPt(this._offset1.p0))}},{key:"createSquare",value:function(t){this._segList.addPt(new Y(t.x+this._distance,t.y+this._distance)),this._segList.addPt(new Y(t.x+this._distance,t.y-this._distance)),this._segList.addPt(new Y(t.x-this._distance,t.y-this._distance)),this._segList.addPt(new Y(t.x-this._distance,t.y+this._distance)),this._segList.closeRing()}},{key:"addSegments",value:function(t,e){this._segList.addPts(t,e)}},{key:"addFirstSegment",value:function(){this._segList.addPt(this._offset1.p0)}},{key:"addCornerFillet",value:function(t,e,n,i,r){var o=e.x-t.x,s=e.y-t.y,a=Math.atan2(s,o),l=n.x-t.x,u=n.y-t.y,h=Math.atan2(u,l);i===ct.CLOCKWISE?a<=h&&(a+=2*Math.PI):a>=h&&(a-=2*Math.PI),this._segList.addPt(e),this.addDirectedFillet(t,a,h,i,r),this._segList.addPt(n)}},{key:"addLastSegment",value:function(){this._segList.addPt(this._offset1.p1)}},{key:"initSideSegments",value:function(t,e,n){this._s1=t,this._s2=e,this._side=n,this._seg1.setCoordinates(t,e),this.computeOffsetSegment(this._seg1,n,this._distance,this._offset1)}},{key:"addLimitedMitreJoin",value:function(t,e,n,i){var r=this._seg0.p1,o=Tn.angle(r,this._seg0.p0),s=Tn.angleBetweenOriented(this._seg0.p0,r,this._seg1.p1)/2,a=Tn.normalize(o+s),l=Tn.normalize(a+Math.PI),u=i*n,h=n-u*Math.abs(Math.sin(s)),c=r.x+u*Math.cos(l),f=r.y+u*Math.sin(l),g=new Y(c,f),d=new En(r,g),p=d.pointAlongOffset(1,h),y=d.pointAlongOffset(1,-h);this._side===Q.LEFT?(this._segList.addPt(p),this._segList.addPt(y)):(this._segList.addPt(y),this._segList.addPt(p))}},{key:"addDirectedFillet",value:function(t,e,n,i,r){var o=i===ct.CLOCKWISE?-1:1,s=Math.abs(e-n),a=Math.trunc(s/this._filletAngleQuantum+.5);if(a<1)return null;for(var l=s/a,u=new Y,h=0;h<a;h++){var c=e+o*h*l;u.x=t.x+r*Math.cos(c),u.y=t.y+r*Math.sin(c),this._segList.addPt(u)}}},{key:"computeOffsetSegment",value:function(t,e,n,i){var r=e===Q.LEFT?1:-1,o=t.p1.x-t.p0.x,s=t.p1.y-t.p0.y,a=Math.sqrt(o*o+s*s),l=r*n*o/a,u=r*n*s/a;i.p0.x=t.p0.x-u,i.p0.y=t.p0.y+l,i.p1.x=t.p1.x-u,i.p1.y=t.p1.y+l}},{key:"addInsideTurn",value:function(e,n){if(this._li.computeIntersection(this._offset0.p0,this._offset0.p1,this._offset1.p0,this._offset1.p1),this._li.hasIntersection())this._segList.addPt(this._li.getIntersection(0));else if(this._hasNarrowConcaveAngle=!0,this._offset0.p1.distance(this._offset1.p0)<this._distance*t.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR)this._segList.addPt(this._offset0.p1);else{if(this._segList.addPt(this._offset0.p1),this._closingSegLengthFactor>0){var i=new Y((this._closingSegLengthFactor*this._offset0.p1.x+this._s1.x)/(this._closingSegLengthFactor+1),(this._closingSegLengthFactor*this._offset0.p1.y+this._s1.y)/(this._closingSegLengthFactor+1));this._segList.addPt(i);var r=new Y((this._closingSegLengthFactor*this._offset1.p0.x+this._s1.x)/(this._closingSegLengthFactor+1),(this._closingSegLengthFactor*this._offset1.p0.y+this._s1.y)/(this._closingSegLengthFactor+1));this._segList.addPt(r)}else this._segList.addPt(this._s1);this._segList.addPt(this._offset1.p0)}}},{key:"createCircle",value:function(t){var e=new Y(t.x+this._distance,t.y);this._segList.addPt(e),this.addDirectedFillet(t,0,2*Math.PI,-1,this._distance),this._segList.closeRing()}},{key:"addBevelJoin",value:function(t,e){this._segList.addPt(t.p1),this._segList.addPt(e.p0)}},{key:"init",value:function(e){this._distance=e,this._maxCurveSegmentError=e*(1-Math.cos(this._filletAngleQuantum/2)),this._segList=new Nn,this._segList.setPrecisionModel(this._precisionModel),this._segList.setMinimumVertexDistance(e*t.CURVE_VERTEX_SNAP_DISTANCE_FACTOR)}},{key:"addCollinear",value:function(t){this._li.computeIntersection(this._s0,this._s1,this._s1,this._s2),this._li.getIntersectionNum()>=2&&(this._bufParams.getJoinStyle()===m.JOIN_BEVEL||this._bufParams.getJoinStyle()===m.JOIN_MITRE?(t&&this._segList.addPt(this._offset0.p1),this._segList.addPt(this._offset1.p0)):this.addCornerFillet(this._s1,this._offset0.p1,this._offset1.p0,ct.CLOCKWISE,this._distance))}},{key:"closeRing",value:function(){this._segList.closeRing()}},{key:"hasNarrowConcaveAngle",value:function(){return this._hasNarrowConcaveAngle}}],[{key:"constructor_",value:function(){this._maxCurveSegmentError=0,this._filletAngleQuantum=null,this._closingSegLengthFactor=1,this._segList=null,this._distance=0,this._precisionModel=null,this._bufParams=null,this._li=null,this._s0=null,this._s1=null,this._s2=null,this._seg0=new En,this._seg1=new En,this._offset0=new En,this._offset1=new En,this._side=0,this._hasNarrowConcaveAngle=!1;var e=arguments[0],n=arguments[1],i=arguments[2];this._precisionModel=e,this._bufParams=n,this._li=new Ce,this._filletAngleQuantum=Math.PI/2/n.getQuadrantSegments(),n.getQuadrantSegments()>=8&&n.getJoinStyle()===m.JOIN_ROUND&&(this._closingSegLengthFactor=t.MAX_CLOSING_SEG_LEN_FACTOR),this.init(i)}}])}();Dn.OFFSET_SEGMENT_SEPARATION_FACTOR=.001,Dn.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR=.001,Dn.CURVE_VERTEX_SNAP_DISTANCE_FACTOR=1e-6,Dn.MAX_CLOSING_SEG_LEN_FACTOR=80;var On=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getOffsetCurve",value:function(t,e){if(this._distance=e,0===e)return null;var n=e<0,i=Math.abs(e),r=this.getSegGen(i);t.length<=1?this.computePointCurve(t[0],r):this.computeOffsetCurve(t,n,r);var o=r.getCoordinates();return n&&Kt.reverse(o),o}},{key:"computeSingleSidedBufferCurve",value:function(t,e,n){var i=this.simplifyTolerance(this._distance);if(e){n.addSegments(t,!0);var r=Cn.simplify(t,-i),o=r.length-1;n.initSideSegments(r[o],r[o-1],Q.LEFT),n.addFirstSegment();for(var s=o-2;s>=0;s--)n.addNextSegment(r[s],!0)}else{n.addSegments(t,!1);var a=Cn.simplify(t,i),l=a.length-1;n.initSideSegments(a[0],a[1],Q.LEFT),n.addFirstSegment();for(var u=2;u<=l;u++)n.addNextSegment(a[u],!0)}n.addLastSegment(),n.closeRing()}},{key:"computeRingBufferCurve",value:function(t,e,n){var i=this.simplifyTolerance(this._distance);e===Q.RIGHT&&(i=-i);var r=Cn.simplify(t,i),o=r.length-1;n.initSideSegments(r[o-1],r[0],e);for(var s=1;s<=o;s++){var a=1!==s;n.addNextSegment(r[s],a)}n.closeRing()}},{key:"computeLineBufferCurve",value:function(t,e){var n=this.simplifyTolerance(this._distance),i=Cn.simplify(t,n),r=i.length-1;e.initSideSegments(i[0],i[1],Q.LEFT);for(var o=2;o<=r;o++)e.addNextSegment(i[o],!0);e.addLastSegment(),e.addLineEndCap(i[r-1],i[r]);var s=Cn.simplify(t,-n),a=s.length-1;e.initSideSegments(s[a],s[a-1],Q.LEFT);for(var l=a-2;l>=0;l--)e.addNextSegment(s[l],!0);e.addLastSegment(),e.addLineEndCap(s[1],s[0]),e.closeRing()}},{key:"computePointCurve",value:function(t,e){switch(this._bufParams.getEndCapStyle()){case m.CAP_ROUND:e.createCircle(t);break;case m.CAP_SQUARE:e.createSquare(t)}}},{key:"getLineCurve",value:function(t,e){if(this._distance=e,this.isLineOffsetEmpty(e))return null;var n=Math.abs(e),i=this.getSegGen(n);if(t.length<=1)this.computePointCurve(t[0],i);else if(this._bufParams.isSingleSided()){var r=e<0;this.computeSingleSidedBufferCurve(t,r,i)}else this.computeLineBufferCurve(t,i);return i.getCoordinates()}},{key:"getBufferParameters",value:function(){return this._bufParams}},{key:"simplifyTolerance",value:function(t){return t*this._bufParams.getSimplifyFactor()}},{key:"getRingCurve",value:function(e,n,i){if(this._distance=i,e.length<=2)return this.getLineCurve(e,i);if(0===i)return t.copyCoordinates(e);var r=this.getSegGen(i);return this.computeRingBufferCurve(e,n,r),r.getCoordinates()}},{key:"computeOffsetCurve",value:function(t,e,n){var i=this.simplifyTolerance(this._distance);if(e){var r=Cn.simplify(t,-i),o=r.length-1;n.initSideSegments(r[o],r[o-1],Q.LEFT),n.addFirstSegment();for(var s=o-2;s>=0;s--)n.addNextSegment(r[s],!0)}else{var a=Cn.simplify(t,i),l=a.length-1;n.initSideSegments(a[0],a[1],Q.LEFT),n.addFirstSegment();for(var u=2;u<=l;u++)n.addNextSegment(a[u],!0)}n.addLastSegment()}},{key:"isLineOffsetEmpty",value:function(t){return 0===t||t<0&&!this._bufParams.isSingleSided()}},{key:"getSegGen",value:function(t){return new Dn(this._precisionModel,this._bufParams,t)}}],[{key:"constructor_",value:function(){this._distance=0,this._precisionModel=null,this._bufParams=null;var t=arguments[0],e=arguments[1];this._precisionModel=t,this._bufParams=e}},{key:"copyCoordinates",value:function(t){for(var e=new Array(t.length).fill(null),n=0;n<e.length;n++)e[n]=new Y(t[n]);return e}}])}(),An=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"findStabbedSegments",value:function(){if(1===arguments.length){for(var t=arguments[0],e=new pt,n=this._subgraphs.iterator();n.hasNext();){var i=n.next(),r=i.getEnvelope();t.y<r.getMinY()||t.y>r.getMaxY()||this.findStabbedSegments(t,i.getDirectedEdges(),e)}return e}if(3===arguments.length)if(rt(arguments[2],nt)&&arguments[0]instanceof Y&&arguments[1]instanceof Ze){for(var o=arguments[0],s=arguments[1],a=arguments[2],l=s.getEdge().getCoordinates(),u=0;u<l.length-1;u++)if(this._seg.p0=l[u],this._seg.p1=l[u+1],this._seg.p0.y>this._seg.p1.y&&this._seg.reverse(),!(Math.max(this._seg.p0.x,this._seg.p1.x)<o.x||this._seg.isHorizontal()||o.y<this._seg.p0.y||o.y>this._seg.p1.y||ct.index(this._seg.p0,this._seg.p1,o)===ct.RIGHT)){var h=s.getDepth(Q.LEFT);this._seg.p0.equals(l[u])||(h=s.getDepth(Q.RIGHT));var c=new Rn(this._seg,h);a.add(c)}}else if(rt(arguments[2],nt)&&arguments[0]instanceof Y&&rt(arguments[1],nt))for(var f=arguments[0],g=arguments[2],d=arguments[1].iterator();d.hasNext();){var p=d.next();p.isForward()&&this.findStabbedSegments(f,p,g)}}},{key:"getDepth",value:function(t){var e=this.findStabbedSegments(t);return 0===e.size()?0:sn.min(e)._leftDepth}}],[{key:"constructor_",value:function(){this._subgraphs=null,this._seg=new En;var t=arguments[0];this._subgraphs=t}}]),Rn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"compareTo",value:function(t){var e=t;if(this._upwardSeg.minX()>=e._upwardSeg.maxX())return 1;if(this._upwardSeg.maxX()<=e._upwardSeg.minX())return-1;var n=this._upwardSeg.orientationIndex(e._upwardSeg);return 0!==n||0!=(n=-1*e._upwardSeg.orientationIndex(this._upwardSeg))?n:this._upwardSeg.compareTo(e._upwardSeg)}},{key:"compareX",value:function(t,e){var n=t.p0.compareTo(e.p0);return 0!==n?n:t.p1.compareTo(e.p1)}},{key:"toString",value:function(){return this._upwardSeg.toString()}},{key:"interfaces_",get:function(){return[x]}}],[{key:"constructor_",value:function(){this._upwardSeg=null,this._leftDepth=null;var t=arguments[0],e=arguments[1];this._upwardSeg=new En(t),this._leftDepth=e}}]);An.DepthSegment=Rn;var Fn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,null,[{key:"constructor_",value:function(){v.constructor_.call(this,"Projective point not representable on the Cartesian plane.")}}])}(v),Bn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getY",value:function(){var t=this.y/this.w;if(O.isNaN(t)||O.isInfinite(t))throw new Fn;return t}},{key:"getX",value:function(){var t=this.x/this.w;if(O.isNaN(t)||O.isInfinite(t))throw new Fn;return t}},{key:"getCoordinate",value:function(){var t=new Y;return t.x=this.getX(),t.y=this.getY(),t}}],[{key:"constructor_",value:function(){if(this.x=null,this.y=null,this.w=null,0===arguments.length)this.x=0,this.y=0,this.w=1;else if(1===arguments.length){var e=arguments[0];this.x=e.x,this.y=e.y,this.w=1}else if(2===arguments.length){if("number"==typeof arguments[0]&&"number"==typeof arguments[1]){var n=arguments[0],i=arguments[1];this.x=n,this.y=i,this.w=1}else if(arguments[0]instanceof t&&arguments[1]instanceof t){var r=arguments[0],o=arguments[1];this.x=r.y*o.w-o.y*r.w,this.y=o.x*r.w-r.x*o.w,this.w=r.x*o.y-o.x*r.y}else if(arguments[0]instanceof Y&&arguments[1]instanceof Y){var s=arguments[0],a=arguments[1];this.x=s.y-a.y,this.y=a.x-s.x,this.w=s.x*a.y-a.x*s.y}}else if(3===arguments.length){var l=arguments[0],u=arguments[1],h=arguments[2];this.x=l,this.y=u,this.w=h}else if(4===arguments.length){var c=arguments[0],f=arguments[1],g=arguments[2],d=arguments[3],p=c.y-f.y,y=f.x-c.x,m=c.x*f.y-f.x*c.y,v=g.y-d.y,_=d.x-g.x,k=g.x*d.y-d.x*g.y;this.x=y*k-_*m,this.y=v*m-p*k,this.w=p*_-v*y}}}])}(),Gn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"area",value:function(){return t.area(this.p0,this.p1,this.p2)}},{key:"signedArea",value:function(){return t.signedArea(this.p0,this.p1,this.p2)}},{key:"interpolateZ",value:function(e){if(null===e)throw new _("Supplied point is null.");return t.interpolateZ(e,this.p0,this.p1,this.p2)}},{key:"longestSideLength",value:function(){return t.longestSideLength(this.p0,this.p1,this.p2)}},{key:"isAcute",value:function(){return t.isAcute(this.p0,this.p1,this.p2)}},{key:"circumcentre",value:function(){return t.circumcentre(this.p0,this.p1,this.p2)}},{key:"area3D",value:function(){return t.area3D(this.p0,this.p1,this.p2)}},{key:"centroid",value:function(){return t.centroid(this.p0,this.p1,this.p2)}},{key:"inCentre",value:function(){return t.inCentre(this.p0,this.p1,this.p2)}}],[{key:"constructor_",value:function(){this.p0=null,this.p1=null,this.p2=null;var t=arguments[0],e=arguments[1],n=arguments[2];this.p0=t,this.p1=e,this.p2=n}},{key:"area",value:function(t,e,n){return Math.abs(((n.x-t.x)*(e.y-t.y)-(e.x-t.x)*(n.y-t.y))/2)}},{key:"signedArea",value:function(t,e,n){return((n.x-t.x)*(e.y-t.y)-(e.x-t.x)*(n.y-t.y))/2}},{key:"det",value:function(t,e,n,i){return t*i-e*n}},{key:"interpolateZ",value:function(t,e,n,i){var r=e.x,o=e.y,s=n.x-r,a=i.x-r,l=n.y-o,u=i.y-o,h=s*u-a*l,c=t.x-r,f=t.y-o,g=(u*c-a*f)/h,d=(-l*c+s*f)/h;return e.getZ()+g*(n.getZ()-e.getZ())+d*(i.getZ()-e.getZ())}},{key:"longestSideLength",value:function(t,e,n){var i=t.distance(e),r=e.distance(n),o=n.distance(t),s=i;return r>s&&(s=r),o>s&&(s=o),s}},{key:"circumcentreDD",value:function(t,e,n){var i=lt.valueOf(t.x).subtract(n.x),r=lt.valueOf(t.y).subtract(n.y),o=lt.valueOf(e.x).subtract(n.x),s=lt.valueOf(e.y).subtract(n.y),a=lt.determinant(i,r,o,s).multiply(2),l=i.sqr().add(r.sqr()),u=o.sqr().add(s.sqr()),h=lt.determinant(r,l,s,u),c=lt.determinant(i,l,o,u),f=lt.valueOf(n.x).subtract(h.divide(a)).doubleValue(),g=lt.valueOf(n.y).add(c.divide(a)).doubleValue();return new Y(f,g)}},{key:"isAcute",value:function(t,e,n){return!!Tn.isAcute(t,e,n)&&!!Tn.isAcute(e,n,t)&&!!Tn.isAcute(n,t,e)}},{key:"circumcentre",value:function(e,n,i){var r=i.x,o=i.y,s=e.x-r,a=e.y-o,l=n.x-r,u=n.y-o,h=2*t.det(s,a,l,u),c=t.det(a,s*s+a*a,u,l*l+u*u),f=t.det(s,s*s+a*a,l,l*l+u*u);return new Y(r-c/h,o+f/h)}},{key:"perpendicularBisector",value:function(t,e){var n=e.x-t.x,i=e.y-t.y,r=new Bn(t.x+n/2,t.y+i/2,1),o=new Bn(t.x-i+n/2,t.y+n+i/2,1);return new Bn(r,o)}},{key:"angleBisector",value:function(t,e,n){var i=e.distance(t),r=i/(i+e.distance(n)),o=n.x-t.x,s=n.y-t.y;return new Y(t.x+r*o,t.y+r*s)}},{key:"area3D",value:function(t,e,n){var i=e.x-t.x,r=e.y-t.y,o=e.getZ()-t.getZ(),s=n.x-t.x,a=n.y-t.y,l=n.getZ()-t.getZ(),u=r*l-o*a,h=o*s-i*l,c=i*a-r*s,f=u*u+h*h+c*c;return Math.sqrt(f)/2}},{key:"centroid",value:function(t,e,n){var i=(t.x+e.x+n.x)/3,r=(t.y+e.y+n.y)/3;return new Y(i,r)}},{key:"inCentre",value:function(t,e,n){var i=e.distance(n),r=t.distance(n),o=t.distance(e),s=i+r+o,a=(i*t.x+r*e.x+o*n.x)/s,l=(i*t.y+r*e.y+o*n.y)/s;return new Y(a,l)}}])}(),zn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"addRingSide",value:function(t,e,n,i,r){if(0===e&&t.length<Yt.MINIMUM_VALID_SIZE)return null;var o=i,s=r;t.length>=Yt.MINIMUM_VALID_SIZE&&ct.isCCW(t)&&(o=r,s=i,n=Q.opposite(n));var a=this._curveBuilder.getRingCurve(t,n,e);this.addCurve(a,o,s)}},{key:"addRingBothSides",value:function(t,e){this.addRingSide(t,e,Q.LEFT,V.EXTERIOR,V.INTERIOR),this.addRingSide(t,e,Q.RIGHT,V.INTERIOR,V.EXTERIOR)}},{key:"addPoint",value:function(t){if(this._distance<=0)return null;var e=t.getCoordinates(),n=this._curveBuilder.getLineCurve(e,this._distance);this.addCurve(n,V.EXTERIOR,V.INTERIOR)}},{key:"addPolygon",value:function(t){var e=this._distance,n=Q.LEFT;this._distance<0&&(e=-this._distance,n=Q.RIGHT);var i=t.getExteriorRing(),r=Kt.removeRepeatedPoints(i.getCoordinates());if(this._distance<0&&this.isErodedCompletely(i,this._distance))return null;if(this._distance<=0&&r.length<3)return null;this.addRingSide(r,e,n,V.EXTERIOR,V.INTERIOR);for(var o=0;o<t.getNumInteriorRing();o++){var s=t.getInteriorRingN(o),a=Kt.removeRepeatedPoints(s.getCoordinates());this._distance>0&&this.isErodedCompletely(s,-this._distance)||this.addRingSide(a,e,Q.opposite(n),V.INTERIOR,V.EXTERIOR)}}},{key:"isTriangleErodedCompletely",value:function(t,e){var n=new Gn(t[0],t[1],t[2]),i=n.inCentre();return xt.pointToSegment(i,n.p0,n.p1)<Math.abs(e)}},{key:"addLineString",value:function(t){if(this._curveBuilder.isLineOffsetEmpty(this._distance))return null;var e=Kt.removeRepeatedPoints(t.getCoordinates());if(Kt.isRing(e)&&!this._curveBuilder.getBufferParameters().isSingleSided())this.addRingBothSides(e,this._distance);else{var n=this._curveBuilder.getLineCurve(e,this._distance);this.addCurve(n,V.EXTERIOR,V.INTERIOR)}}},{key:"addCurve",value:function(t,e,n){if(null===t||t.length<2)return null;var i=new xn(t,new Oe(0,V.BOUNDARY,e,n));this._curveList.add(i)}},{key:"getCurves",value:function(){return this.add(this._inputGeom),this._curveList}},{key:"add",value:function(t){if(t.isEmpty())return null;if(t instanceof Rt)this.addPolygon(t);else if(t instanceof Ct)this.addLineString(t);else if(t instanceof Tt)this.addPoint(t);else if(t instanceof Ht)this.addCollection(t);else if(t instanceof oe)this.addCollection(t);else if(t instanceof te)this.addCollection(t);else{if(!(t instanceof zt))throw new W(t.getGeometryType());this.addCollection(t)}}},{key:"isErodedCompletely",value:function(t,e){var n=t.getCoordinates();if(n.length<4)return e<0;if(4===n.length)return this.isTriangleErodedCompletely(n,e);var i=t.getEnvelopeInternal(),r=Math.min(i.getHeight(),i.getWidth());return e<0&&2*Math.abs(e)>r}},{key:"addCollection",value:function(t){for(var e=0;e<t.getNumGeometries();e++){var n=t.getGeometryN(e);this.add(n)}}}],[{key:"constructor_",value:function(){this._inputGeom=null,this._distance=null,this._curveBuilder=null,this._curveList=new pt;var t=arguments[0],e=arguments[1],n=arguments[2];this._inputGeom=t,this._distance=e,this._curveBuilder=n}}]),Hn=o(function t(){n(this,t)},[{key:"locate",value:function(t){}}]),Yn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"next",value:function(){if(this._atStart)return this._atStart=!1,t.isAtomic(this._parent)&&this._index++,this._parent;if(null!==this._subcollectionIterator){if(this._subcollectionIterator.hasNext())return this._subcollectionIterator.next();this._subcollectionIterator=null}if(this._index>=this._max)throw new K;var e=this._parent.getGeometryN(this._index++);return e instanceof zt?(this._subcollectionIterator=new t(e),this._subcollectionIterator.next()):e}},{key:"remove",value:function(){throw new W(this.getClass().getName())}},{key:"hasNext",value:function(){if(this._atStart)return!0;if(null!==this._subcollectionIterator){if(this._subcollectionIterator.hasNext())return!0;this._subcollectionIterator=null}return!(this._index>=this._max)}},{key:"interfaces_",get:function(){return[yn]}}],[{key:"constructor_",value:function(){this._parent=null,this._atStart=null,this._max=null,this._index=null,this._subcollectionIterator=null;var t=arguments[0];this._parent=t,this._atStart=!0,this._index=0,this._max=t.getNumGeometries()}},{key:"isAtomic",value:function(t){return!(t instanceof zt)}}])}(),Un=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"locate",value:function(e){return t.locate(e,this._geom)}},{key:"interfaces_",get:function(){return[Hn]}}],[{key:"constructor_",value:function(){this._geom=null;var t=arguments[0];this._geom=t}},{key:"locatePointInPolygon",value:function(e,n){if(n.isEmpty())return V.EXTERIOR;var i=n.getExteriorRing(),r=t.locatePointInRing(e,i);if(r!==V.INTERIOR)return r;for(var o=0;o<n.getNumInteriorRing();o++){var s=n.getInteriorRingN(o),a=t.locatePointInRing(e,s);if(a===V.BOUNDARY)return V.BOUNDARY;if(a===V.INTERIOR)return V.EXTERIOR}return V.INTERIOR}},{key:"locatePointInRing",value:function(t,e){return e.getEnvelopeInternal().intersects(t)?Te.locateInRing(t,e.getCoordinates()):V.EXTERIOR}},{key:"containsPointInPolygon",value:function(e,n){return V.EXTERIOR!==t.locatePointInPolygon(e,n)}},{key:"locateInGeometry",value:function(e,n){if(n instanceof Rt)return t.locatePointInPolygon(e,n);if(n instanceof zt)for(var i=new Yn(n);i.hasNext();){var r=i.next();if(r!==n){var o=t.locateInGeometry(e,r);if(o!==V.EXTERIOR)return o}}return V.EXTERIOR}},{key:"isContained",value:function(e,n){return V.EXTERIOR!==t.locate(e,n)}},{key:"locate",value:function(e,n){return n.isEmpty()?V.EXTERIOR:n.getEnvelopeInternal().intersects(e)?t.locateInGeometry(e,n):V.EXTERIOR}}])}(),Xn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"getNextCW",value:function(t){this.getEdges();var e=this._edgeList.indexOf(t),n=e-1;return 0===e&&(n=this._edgeList.size()-1),this._edgeList.get(n)}},{key:"propagateSideLabels",value:function(t){for(var e=V.NONE,n=this.iterator();n.hasNext();){var i=n.next().getLabel();i.isArea(t)&&i.getLocation(t,Q.LEFT)!==V.NONE&&(e=i.getLocation(t,Q.LEFT))}if(e===V.NONE)return null;for(var r=e,o=this.iterator();o.hasNext();){var s=o.next(),a=s.getLabel();if(a.getLocation(t,Q.ON)===V.NONE&&a.setLocation(t,Q.ON,r),a.isArea(t)){var l=a.getLocation(t,Q.LEFT),u=a.getLocation(t,Q.RIGHT);if(u!==V.NONE){if(u!==r)throw new gt("side location conflict",s.getCoordinate());l===V.NONE&&B.shouldNeverReachHere("found single null side (at "+s.getCoordinate()+")"),r=l}else B.isTrue(a.getLocation(t,Q.LEFT)===V.NONE,"found single null side"),a.setLocation(t,Q.RIGHT,r),a.setLocation(t,Q.LEFT,r)}}}},{key:"getCoordinate",value:function(){var t=this.iterator();return t.hasNext()?t.next().getCoordinate():null}},{key:"print",value:function(t){_t.out.println("EdgeEndStar: "+this.getCoordinate());for(var e=this.iterator();e.hasNext();)e.next().print(t)}},{key:"isAreaLabelsConsistent",value:function(t){return this.computeEdgeEndLabels(t.getBoundaryNodeRule()),this.checkAreaLabelsConsistent(0)}},{key:"checkAreaLabelsConsistent",value:function(t){var e=this.getEdges();if(e.size()<=0)return!0;var n=e.size()-1,i=e.get(n).getLabel().getLocation(t,Q.LEFT);B.isTrue(i!==V.NONE,"Found unlabelled area edge");for(var r=i,o=this.iterator();o.hasNext();){var s=o.next().getLabel();B.isTrue(s.isArea(t),"Found non-area edge");var a=s.getLocation(t,Q.LEFT),l=s.getLocation(t,Q.RIGHT);if(a===l)return!1;if(l!==r)return!1;r=a}return!0}},{key:"findIndex",value:function(t){this.iterator();for(var e=0;e<this._edgeList.size();e++)if(this._edgeList.get(e)===t)return e;return-1}},{key:"iterator",value:function(){return this.getEdges().iterator()}},{key:"getEdges",value:function(){return null===this._edgeList&&(this._edgeList=new pt(this._edgeMap.values())),this._edgeList}},{key:"getLocation",value:function(t,e,n){return this._ptInAreaLocation[t]===V.NONE&&(this._ptInAreaLocation[t]=Un.locate(e,n[t].getGeometry())),this._ptInAreaLocation[t]}},{key:"toString",value:function(){var t=new ot;t.append("EdgeEndStar: "+this.getCoordinate()),t.append("\n");for(var e=this.iterator();e.hasNext();){var n=e.next();t.append(n),t.append("\n")}return t.toString()}},{key:"computeEdgeEndLabels",value:function(t){for(var e=this.iterator();e.hasNext();)e.next().computeLabel(t)}},{key:"computeLabelling",value:function(t){this.computeEdgeEndLabels(t[0].getBoundaryNodeRule()),this.propagateSideLabels(0),this.propagateSideLabels(1);for(var e=[!1,!1],n=this.iterator();n.hasNext();)for(var i=n.next().getLabel(),r=0;r<2;r++)i.isLine(r)&&i.getLocation(r)===V.BOUNDARY&&(e[r]=!0);for(var o=this.iterator();o.hasNext();)for(var s=o.next(),a=s.getLabel(),l=0;l<2;l++)if(a.isAnyNull(l)){var u=V.NONE;if(e[l])u=V.EXTERIOR;else{var h=s.getCoordinate();u=this.getLocation(l,h,t)}a.setAllLocationsIfNull(l,u)}}},{key:"getDegree",value:function(){return this._edgeMap.size()}},{key:"insertEdgeEnd",value:function(t,e){this._edgeMap.put(t,e),this._edgeList=null}}],[{key:"constructor_",value:function(){this._edgeMap=new Ve,this._edgeList=null,this._ptInAreaLocation=[V.NONE,V.NONE]}}]),qn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"linkResultDirectedEdges",value:function(){this.getResultAreaEdges();for(var t=null,e=null,n=this._SCANNING_FOR_INCOMING,i=0;i<this._resultAreaEdgeList.size();i++){var r=this._resultAreaEdgeList.get(i),o=r.getSym();if(r.getLabel().isArea())switch(null===t&&r.isInResult()&&(t=r),n){case this._SCANNING_FOR_INCOMING:if(!o.isInResult())continue;e=o,n=this._LINKING_TO_OUTGOING;break;case this._LINKING_TO_OUTGOING:if(!r.isInResult())continue;e.setNext(r),n=this._SCANNING_FOR_INCOMING}}if(n===this._LINKING_TO_OUTGOING){if(null===t)throw new gt("no outgoing dirEdge found",this.getCoordinate());B.isTrue(t.isInResult(),"unable to link last incoming dirEdge"),e.setNext(t)}}},{key:"insert",value:function(t){var e=t;this.insertEdgeEnd(e,e)}},{key:"getRightmostEdge",value:function(){var t=this.getEdges(),e=t.size();if(e<1)return null;var n=t.get(0);if(1===e)return n;var i=t.get(e-1),r=n.getQuadrant(),o=i.getQuadrant();return Ke.isNorthern(r)&&Ke.isNorthern(o)?n:Ke.isNorthern(r)||Ke.isNorthern(o)?0!==n.getDy()?n:0!==i.getDy()?i:(B.shouldNeverReachHere("found two horizontal edges incident on node"),null):i}},{key:"print",value:function(t){_t.out.println("DirectedEdgeStar: "+this.getCoordinate());for(var e=this.iterator();e.hasNext();){var n=e.next();t.print("out "),n.print(t),t.println(),t.print("in "),n.getSym().print(t),t.println()}}},{key:"getResultAreaEdges",value:function(){if(null!==this._resultAreaEdgeList)return this._resultAreaEdgeList;this._resultAreaEdgeList=new pt;for(var t=this.iterator();t.hasNext();){var e=t.next();(e.isInResult()||e.getSym().isInResult())&&this._resultAreaEdgeList.add(e)}return this._resultAreaEdgeList}},{key:"updateLabelling",value:function(t){for(var e=this.iterator();e.hasNext();){var n=e.next().getLabel();n.setAllLocationsIfNull(0,t.getLocation(0)),n.setAllLocationsIfNull(1,t.getLocation(1))}}},{key:"linkAllDirectedEdges",value:function(){this.getEdges();for(var t=null,e=null,n=this._edgeList.size()-1;n>=0;n--){var i=this._edgeList.get(n),r=i.getSym();null===e&&(e=r),null!==t&&r.setNext(t),t=i}e.setNext(t)}},{key:"computeDepths",value:function(){if(1===arguments.length){var t=arguments[0],e=this.findIndex(t),n=t.getDepth(Q.LEFT),i=t.getDepth(Q.RIGHT),r=this.computeDepths(e+1,this._edgeList.size(),n);if(this.computeDepths(0,e,r)!==i)throw new gt("depth mismatch at "+t.getCoordinate())}else if(3===arguments.length){for(var o=arguments[1],s=arguments[2],a=arguments[0];a<o;a++){var l=this._edgeList.get(a);l.setEdgeDepths(Q.RIGHT,s),s=l.getDepth(Q.LEFT)}return s}}},{key:"mergeSymLabels",value:function(){for(var t=this.iterator();t.hasNext();){var e=t.next();e.getLabel().merge(e.getSym().getLabel())}}},{key:"linkMinimalDirectedEdges",value:function(t){for(var e=null,n=null,i=this._SCANNING_FOR_INCOMING,r=this._resultAreaEdgeList.size()-1;r>=0;r--){var o=this._resultAreaEdgeList.get(r),s=o.getSym();switch(null===e&&o.getEdgeRing()===t&&(e=o),i){case this._SCANNING_FOR_INCOMING:if(s.getEdgeRing()!==t)continue;n=s,i=this._LINKING_TO_OUTGOING;break;case this._LINKING_TO_OUTGOING:if(o.getEdgeRing()!==t)continue;n.setNextMin(o),i=this._SCANNING_FOR_INCOMING}}i===this._LINKING_TO_OUTGOING&&(B.isTrue(null!==e,"found null for first outgoing dirEdge"),B.isTrue(e.getEdgeRing()===t,"unable to link last incoming dirEdge"),n.setNextMin(e))}},{key:"getOutgoingDegree",value:function(){if(0===arguments.length){for(var t=0,e=this.iterator();e.hasNext();)e.next().isInResult()&&t++;return t}if(1===arguments.length){for(var n=arguments[0],i=0,r=this.iterator();r.hasNext();)r.next().getEdgeRing()===n&&i++;return i}}},{key:"getLabel",value:function(){return this._label}},{key:"findCoveredLineEdges",value:function(){for(var t=V.NONE,e=this.iterator();e.hasNext();){var n=e.next(),i=n.getSym();if(!n.isLineEdge()){if(n.isInResult()){t=V.INTERIOR;break}if(i.isInResult()){t=V.EXTERIOR;break}}}if(t===V.NONE)return null;for(var r=t,o=this.iterator();o.hasNext();){var s=o.next(),a=s.getSym();s.isLineEdge()?s.getEdge().setCovered(r===V.INTERIOR):(s.isInResult()&&(r=V.EXTERIOR),a.isInResult()&&(r=V.INTERIOR))}}},{key:"computeLabelling",value:function(t){f(i,"computeLabelling",this,1).call(this,t),this._label=new Oe(V.NONE);for(var e=this.iterator();e.hasNext();)for(var n=e.next().getEdge().getLabel(),r=0;r<2;r++){var o=n.getLocation(r);o!==V.INTERIOR&&o!==V.BOUNDARY||this._label.setLocation(r,V.INTERIOR)}}}],[{key:"constructor_",value:function(){this._resultAreaEdgeList=null,this._label=null,this._SCANNING_FOR_INCOMING=1,this._LINKING_TO_OUTGOING=2}}])}(Xn),Vn=function(t){function i(){return n(this,i),e(this,i)}return u(i,t),o(i,[{key:"createNode",value:function(t){return new Ge(t,new qn)}}])}(Je),jn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"compareTo",value:function(e){var n=e;return t.compareOriented(this._pts,this._orientation,n._pts,n._orientation)}},{key:"interfaces_",get:function(){return[x]}}],[{key:"constructor_",value:function(){this._pts=null,this._orientation=null;var e=arguments[0];this._pts=e,this._orientation=t.orientation(e)}},{key:"orientation",value:function(t){return 1===Kt.increasingDirection(t)}},{key:"compareOriented",value:function(t,e,n,i){for(var r=e?1:-1,o=i?1:-1,s=e?t.length:-1,a=i?n.length:-1,l=e?0:t.length-1,u=i?0:n.length-1;;){var h=t[l].compareTo(n[u]);if(0!==h)return h;var c=(l+=r)===s,f=(u+=o)===a;if(c&&!f)return-1;if(!c&&f)return 1;if(c&&f)return 0}}}])}(),Kn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"print",value:function(t){t.print("MULTILINESTRING ( ");for(var e=0;e<this._edges.size();e++){var n=this._edges.get(e);e>0&&t.print(","),t.print("(");for(var i=n.getCoordinates(),r=0;r<i.length;r++)r>0&&t.print(","),t.print(i[r].x+" "+i[r].y);t.println(")")}t.print(") ")}},{key:"addAll",value:function(t){for(var e=t.iterator();e.hasNext();)this.add(e.next())}},{key:"findEdgeIndex",value:function(t){for(var e=0;e<this._edges.size();e++)if(this._edges.get(e).equals(t))return e;return-1}},{key:"iterator",value:function(){return this._edges.iterator()}},{key:"getEdges",value:function(){return this._edges}},{key:"get",value:function(t){return this._edges.get(t)}},{key:"findEqualEdge",value:function(t){var e=new jn(t.getCoordinates());return this._ocaMap.get(e)}},{key:"add",value:function(t){this._edges.add(t);var e=new jn(t.getCoordinates());this._ocaMap.put(e,t)}}],[{key:"constructor_",value:function(){this._edges=new pt,this._ocaMap=new Ve}}]),Wn=o(function t(){n(this,t)},[{key:"processIntersections",value:function(t,e,n,i){}},{key:"isDone",value:function(){}}]),Zn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"isTrivialIntersection",value:function(e,n,i,r){if(e===i&&1===this._li.getIntersectionNum()){if(t.isAdjacentSegments(n,r))return!0;if(e.isClosed()){var o=e.size()-1;if(0===n&&r===o||0===r&&n===o)return!0}}return!1}},{key:"getProperIntersectionPoint",value:function(){return this._properIntersectionPoint}},{key:"hasProperInteriorIntersection",value:function(){return this._hasProperInterior}},{key:"getLineIntersector",value:function(){return this._li}},{key:"hasProperIntersection",value:function(){return this._hasProper}},{key:"processIntersections",value:function(t,e,n,i){if(t===n&&e===i)return null;this.numTests++;var r=t.getCoordinates()[e],o=t.getCoordinates()[e+1],s=n.getCoordinates()[i],a=n.getCoordinates()[i+1];this._li.computeIntersection(r,o,s,a),this._li.hasIntersection()&&(this.numIntersections++,this._li.isInteriorIntersection()&&(this.numInteriorIntersections++,this._hasInterior=!0),this.isTrivialIntersection(t,e,n,i)||(this._hasIntersection=!0,t.addIntersections(this._li,e,0),n.addIntersections(this._li,i,1),this._li.isProper()&&(this.numProperIntersections++,this._hasProper=!0,this._hasProperInterior=!0)))}},{key:"hasIntersection",value:function(){return this._hasIntersection}},{key:"isDone",value:function(){return!1}},{key:"hasInteriorIntersection",value:function(){return this._hasInterior}},{key:"interfaces_",get:function(){return[Wn]}}],[{key:"constructor_",value:function(){this._hasIntersection=!1,this._hasProper=!1,this._hasProperInterior=!1,this._hasInterior=!1,this._properIntersectionPoint=null,this._li=null,this._isSelfIntersection=null,this.numIntersections=0,this.numInteriorIntersections=0,this.numProperIntersections=0,this.numTests=0;var t=arguments[0];this._li=t}},{key:"isAdjacentSegments",value:function(t,e){return 1===Math.abs(t-e)}}])}(),Jn=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"getSegmentIndex",value:function(){return this.segmentIndex}},{key:"getCoordinate",value:function(){return this.coord}},{key:"print",value:function(t){t.print(this.coord),t.print(" seg # = "+this.segmentIndex),t.println(" dist = "+this.dist)}},{key:"compareTo",value:function(t){var e=t;return this.compare(e.segmentIndex,e.dist)}},{key:"isEndPoint",value:function(t){return 0===this.segmentIndex&&0===this.dist||this.segmentIndex===t}},{key:"toString",value:function(){return this.coord+" seg # = "+this.segmentIndex+" dist = "+this.dist}},{key:"getDistance",value:function(){return this.dist}},{key:"compare",value:function(t,e){return this.segmentIndex<t?-1:this.segmentIndex>t?1:this.dist<e?-1:this.dist>e?1:0}},{key:"interfaces_",get:function(){return[x]}}],[{key:"constructor_",value:function(){this.coord=null,this.segmentIndex=null,this.dist=null;var t=arguments[0],e=arguments[1],n=arguments[2];this.coord=new Y(t),this.segmentIndex=e,this.dist=n}}]),$n=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"print",value:function(t){t.println("Intersections:");for(var e=this.iterator();e.hasNext();)e.next().print(t)}},{key:"iterator",value:function(){return this._nodeMap.values().iterator()}},{key:"addSplitEdges",value:function(t){this.addEndpoints();for(var e=this.iterator(),n=e.next();e.hasNext();){var i=e.next(),r=this.createSplitEdge(n,i);t.add(r),n=i}}},{key:"addEndpoints",value:function(){var t=this.edge.pts.length-1;this.add(this.edge.pts[0],0,0),this.add(this.edge.pts[t],t,0)}},{key:"createSplitEdge",value:function(t,e){var n=e.segmentIndex-t.segmentIndex+2,i=this.edge.pts[e.segmentIndex],r=e.dist>0||!e.coord.equals2D(i);r||n--;var o=new Array(n).fill(null),s=0;o[s++]=new Y(t.coord);for(var a=t.segmentIndex+1;a<=e.segmentIndex;a++)o[s++]=this.edge.pts[a];return r&&(o[s]=e.coord),new ri(o,new Oe(this.edge._label))}},{key:"add",value:function(t,e,n){var i=new Jn(t,e,n),r=this._nodeMap.get(i);return null!==r?r:(this._nodeMap.put(i,i),i)}},{key:"isIntersection",value:function(t){for(var e=this.iterator();e.hasNext();)if(e.next().coord.equals(t))return!0;return!1}}],[{key:"constructor_",value:function(){this._nodeMap=new Ve,this.edge=null;var t=arguments[0];this.edge=t}}]),Qn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"isIntersects",value:function(){return!this.isDisjoint()}},{key:"isCovers",value:function(){return(t.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])||t.isTrue(this._matrix[V.INTERIOR][V.BOUNDARY])||t.isTrue(this._matrix[V.BOUNDARY][V.INTERIOR])||t.isTrue(this._matrix[V.BOUNDARY][V.BOUNDARY]))&&this._matrix[V.EXTERIOR][V.INTERIOR]===It.FALSE&&this._matrix[V.EXTERIOR][V.BOUNDARY]===It.FALSE}},{key:"isCoveredBy",value:function(){return(t.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])||t.isTrue(this._matrix[V.INTERIOR][V.BOUNDARY])||t.isTrue(this._matrix[V.BOUNDARY][V.INTERIOR])||t.isTrue(this._matrix[V.BOUNDARY][V.BOUNDARY]))&&this._matrix[V.INTERIOR][V.EXTERIOR]===It.FALSE&&this._matrix[V.BOUNDARY][V.EXTERIOR]===It.FALSE}},{key:"set",value:function(){if(1===arguments.length)for(var t=arguments[0],e=0;e<t.length;e++){var n=Math.trunc(e/3),i=e%3;this._matrix[n][i]=It.toDimensionValue(t.charAt(e))}else if(3===arguments.length){var r=arguments[0],o=arguments[1],s=arguments[2];this._matrix[r][o]=s}}},{key:"isContains",value:function(){return t.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&this._matrix[V.EXTERIOR][V.INTERIOR]===It.FALSE&&this._matrix[V.EXTERIOR][V.BOUNDARY]===It.FALSE}},{key:"setAtLeast",value:function(){if(1===arguments.length)for(var t=arguments[0],e=0;e<t.length;e++){var n=Math.trunc(e/3),i=e%3;this.setAtLeast(n,i,It.toDimensionValue(t.charAt(e)))}else if(3===arguments.length){var r=arguments[0],o=arguments[1],s=arguments[2];this._matrix[r][o]<s&&(this._matrix[r][o]=s)}}},{key:"setAtLeastIfValid",value:function(t,e,n){t>=0&&e>=0&&this.setAtLeast(t,e,n)}},{key:"isWithin",value:function(){return t.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&this._matrix[V.INTERIOR][V.EXTERIOR]===It.FALSE&&this._matrix[V.BOUNDARY][V.EXTERIOR]===It.FALSE}},{key:"isTouches",value:function(e,n){return e>n?this.isTouches(n,e):(e===It.A&&n===It.A||e===It.L&&n===It.L||e===It.L&&n===It.A||e===It.P&&n===It.A||e===It.P&&n===It.L)&&this._matrix[V.INTERIOR][V.INTERIOR]===It.FALSE&&(t.isTrue(this._matrix[V.INTERIOR][V.BOUNDARY])||t.isTrue(this._matrix[V.BOUNDARY][V.INTERIOR])||t.isTrue(this._matrix[V.BOUNDARY][V.BOUNDARY]))}},{key:"isOverlaps",value:function(e,n){return e===It.P&&n===It.P||e===It.A&&n===It.A?t.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&t.isTrue(this._matrix[V.INTERIOR][V.EXTERIOR])&&t.isTrue(this._matrix[V.EXTERIOR][V.INTERIOR]):e===It.L&&n===It.L&&1===this._matrix[V.INTERIOR][V.INTERIOR]&&t.isTrue(this._matrix[V.INTERIOR][V.EXTERIOR])&&t.isTrue(this._matrix[V.EXTERIOR][V.INTERIOR])}},{key:"isEquals",value:function(e,n){return e===n&&t.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&this._matrix[V.INTERIOR][V.EXTERIOR]===It.FALSE&&this._matrix[V.BOUNDARY][V.EXTERIOR]===It.FALSE&&this._matrix[V.EXTERIOR][V.INTERIOR]===It.FALSE&&this._matrix[V.EXTERIOR][V.BOUNDARY]===It.FALSE}},{key:"toString",value:function(){for(var t=new Jt("123456789"),e=0;e<3;e++)for(var n=0;n<3;n++)t.setCharAt(3*e+n,It.toDimensionSymbol(this._matrix[e][n]));return t.toString()}},{key:"setAll",value:function(t){for(var e=0;e<3;e++)for(var n=0;n<3;n++)this._matrix[e][n]=t}},{key:"get",value:function(t,e){return this._matrix[t][e]}},{key:"transpose",value:function(){var t=this._matrix[1][0];return this._matrix[1][0]=this._matrix[0][1],this._matrix[0][1]=t,t=this._matrix[2][0],this._matrix[2][0]=this._matrix[0][2],this._matrix[0][2]=t,t=this._matrix[2][1],this._matrix[2][1]=this._matrix[1][2],this._matrix[1][2]=t,this}},{key:"matches",value:function(e){if(9!==e.length)throw new _("Should be length 9: "+e);for(var n=0;n<3;n++)for(var i=0;i<3;i++)if(!t.matches(this._matrix[n][i],e.charAt(3*n+i)))return!1;return!0}},{key:"add",value:function(t){for(var e=0;e<3;e++)for(var n=0;n<3;n++)this.setAtLeast(e,n,t.get(e,n))}},{key:"isDisjoint",value:function(){return this._matrix[V.INTERIOR][V.INTERIOR]===It.FALSE&&this._matrix[V.INTERIOR][V.BOUNDARY]===It.FALSE&&this._matrix[V.BOUNDARY][V.INTERIOR]===It.FALSE&&this._matrix[V.BOUNDARY][V.BOUNDARY]===It.FALSE}},{key:"isCrosses",value:function(e,n){return e===It.P&&n===It.L||e===It.P&&n===It.A||e===It.L&&n===It.A?t.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&t.isTrue(this._matrix[V.INTERIOR][V.EXTERIOR]):e===It.L&&n===It.P||e===It.A&&n===It.P||e===It.A&&n===It.L?t.isTrue(this._matrix[V.INTERIOR][V.INTERIOR])&&t.isTrue(this._matrix[V.EXTERIOR][V.INTERIOR]):e===It.L&&n===It.L&&0===this._matrix[V.INTERIOR][V.INTERIOR]}},{key:"interfaces_",get:function(){return[E]}}],[{key:"constructor_",value:function(){if(this._matrix=null,0===arguments.length)this._matrix=Array(3).fill().map(function(){return Array(3)}),this.setAll(It.FALSE);else if(1===arguments.length)if("string"==typeof arguments[0]){var e=arguments[0];t.constructor_.call(this),this.set(e)}else if(arguments[0]instanceof t){var n=arguments[0];t.constructor_.call(this),this._matrix[V.INTERIOR][V.INTERIOR]=n._matrix[V.INTERIOR][V.INTERIOR],this._matrix[V.INTERIOR][V.BOUNDARY]=n._matrix[V.INTERIOR][V.BOUNDARY],this._matrix[V.INTERIOR][V.EXTERIOR]=n._matrix[V.INTERIOR][V.EXTERIOR],this._matrix[V.BOUNDARY][V.INTERIOR]=n._matrix[V.BOUNDARY][V.INTERIOR],this._matrix[V.BOUNDARY][V.BOUNDARY]=n._matrix[V.BOUNDARY][V.BOUNDARY],this._matrix[V.BOUNDARY][V.EXTERIOR]=n._matrix[V.BOUNDARY][V.EXTERIOR],this._matrix[V.EXTERIOR][V.INTERIOR]=n._matrix[V.EXTERIOR][V.INTERIOR],this._matrix[V.EXTERIOR][V.BOUNDARY]=n._matrix[V.EXTERIOR][V.BOUNDARY],this._matrix[V.EXTERIOR][V.EXTERIOR]=n._matrix[V.EXTERIOR][V.EXTERIOR]}}},{key:"matches",value:function(){if(Number.isInteger(arguments[0])&&"string"==typeof arguments[1]){var e=arguments[0],n=arguments[1];return n===It.SYM_DONTCARE||n===It.SYM_TRUE&&(e>=0||e===It.TRUE)||n===It.SYM_FALSE&&e===It.FALSE||n===It.SYM_P&&e===It.P||n===It.SYM_L&&e===It.L||n===It.SYM_A&&e===It.A}if("string"==typeof arguments[0]&&"string"==typeof arguments[1]){var i=arguments[1];return new t(arguments[0]).matches(i)}}},{key:"isTrue",value:function(t){return t>=0||t===It.TRUE}}])}(),ti=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"size",value:function(){return this._size}},{key:"addAll",value:function(t){return null===t||0===t.length?null:(this.ensureCapacity(this._size+t.length),_t.arraycopy(t,0,this._data,this._size,t.length),void(this._size+=t.length))}},{key:"ensureCapacity",value:function(t){if(t<=this._data.length)return null;var e=Math.max(t,2*this._data.length);this._data=Ot.copyOf(this._data,e)}},{key:"toArray",value:function(){var t=new Array(this._size).fill(null);return _t.arraycopy(this._data,0,t,0,this._size),t}},{key:"add",value:function(t){this.ensureCapacity(this._size+1),this._data[this._size]=t,++this._size}}],[{key:"constructor_",value:function(){if(this._data=null,this._size=0,0===arguments.length)t.constructor_.call(this,10);else if(1===arguments.length){var e=arguments[0];this._data=new Array(e).fill(null)}}}])}(),ei=function(){function t(){n(this,t)}return o(t,[{key:"getChainStartIndices",value:function(t){var e=0,n=new ti(Math.trunc(t.length/2));n.add(e);do{var i=this.findChainEnd(t,e);n.add(i),e=i}while(e<t.length-1);return n.toArray()}},{key:"findChainEnd",value:function(t,e){for(var n=Ke.quadrant(t[e],t[e+1]),i=e+1;i<t.length&&Ke.quadrant(t[i-1],t[i])===n;)i++;return i-1}},{key:"OLDgetChainStartIndices",value:function(e){var n=0,i=new pt;i.add(n);do{var r=this.findChainEnd(e,n);i.add(r),n=r}while(n<e.length-1);return t.toIntArray(i)}}],[{key:"toIntArray",value:function(t){for(var e=new Array(t.size()).fill(null),n=0;n<e.length;n++)e[n]=t.get(n).intValue();return e}}])}(),ni=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"getCoordinates",value:function(){return this.pts}},{key:"getMaxX",value:function(t){var e=this.pts[this.startIndex[t]].x,n=this.pts[this.startIndex[t+1]].x;return e>n?e:n}},{key:"getMinX",value:function(t){var e=this.pts[this.startIndex[t]].x,n=this.pts[this.startIndex[t+1]].x;return e<n?e:n}},{key:"computeIntersectsForChain",value:function(){if(4===arguments.length){var t=arguments[0],e=arguments[1],n=arguments[2],i=arguments[3];this.computeIntersectsForChain(this.startIndex[t],this.startIndex[t+1],e,e.startIndex[n],e.startIndex[n+1],i)}else if(6===arguments.length){var r=arguments[0],o=arguments[1],s=arguments[2],a=arguments[3],l=arguments[4],u=arguments[5];if(o-r==1&&l-a==1)return u.addIntersections(this.e,r,s.e,a),null;if(!this.overlaps(r,o,s,a,l))return null;var h=Math.trunc((r+o)/2),c=Math.trunc((a+l)/2);r<h&&(a<c&&this.computeIntersectsForChain(r,h,s,a,c,u),c<l&&this.computeIntersectsForChain(r,h,s,c,l,u)),h<o&&(a<c&&this.computeIntersectsForChain(h,o,s,a,c,u),c<l&&this.computeIntersectsForChain(h,o,s,c,l,u))}}},{key:"overlaps",value:function(t,e,n,i,r){return X.intersects(this.pts[t],this.pts[e],n.pts[i],n.pts[r])}},{key:"getStartIndexes",value:function(){return this.startIndex}},{key:"computeIntersects",value:function(t,e){for(var n=0;n<this.startIndex.length-1;n++)for(var i=0;i<t.startIndex.length-1;i++)this.computeIntersectsForChain(n,t,i,e)}}],[{key:"constructor_",value:function(){this.e=null,this.pts=null,this.startIndex=null;var t=arguments[0];this.e=t,this.pts=t.getCoordinates();var e=new ei;this.startIndex=e.getChainStartIndices(this.pts)}}]),ii=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"getDepth",value:function(t,e){return this._depth[t][e]}},{key:"setDepth",value:function(t,e,n){this._depth[t][e]=n}},{key:"isNull",value:function(){if(0===arguments.length){for(var e=0;e<2;e++)for(var n=0;n<3;n++)if(this._depth[e][n]!==t.NULL_VALUE)return!1;return!0}if(1===arguments.length){var i=arguments[0];return this._depth[i][1]===t.NULL_VALUE}if(2===arguments.length){var r=arguments[0],o=arguments[1];return this._depth[r][o]===t.NULL_VALUE}}},{key:"normalize",value:function(){for(var t=0;t<2;t++)if(!this.isNull(t)){var e=this._depth[t][1];this._depth[t][2]<e&&(e=this._depth[t][2]),e<0&&(e=0);for(var n=1;n<3;n++){var i=0;this._depth[t][n]>e&&(i=1),this._depth[t][n]=i}}}},{key:"getDelta",value:function(t){return this._depth[t][Q.RIGHT]-this._depth[t][Q.LEFT]}},{key:"getLocation",value:function(t,e){return this._depth[t][e]<=0?V.EXTERIOR:V.INTERIOR}},{key:"toString",value:function(){return"A: "+this._depth[0][1]+","+this._depth[0][2]+" B: "+this._depth[1][1]+","+this._depth[1][2]}},{key:"add",value:function(){if(1===arguments.length)for(var e=arguments[0],n=0;n<2;n++)for(var i=1;i<3;i++){var r=e.getLocation(n,i);r!==V.EXTERIOR&&r!==V.INTERIOR||(this.isNull(n,i)?this._depth[n][i]=t.depthAtLocation(r):this._depth[n][i]+=t.depthAtLocation(r))}else if(3===arguments.length){var o=arguments[0],s=arguments[1];arguments[2]===V.INTERIOR&&this._depth[o][s]++}}}],[{key:"constructor_",value:function(){this._depth=Array(2).fill().map(function(){return Array(3)});for(var e=0;e<2;e++)for(var n=0;n<3;n++)this._depth[e][n]=t.NULL_VALUE}},{key:"depthAtLocation",value:function(e){return e===V.EXTERIOR?0:e===V.INTERIOR?1:t.NULL_VALUE}}])}();ii.NULL_VALUE=-1;var ri=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"getDepth",value:function(){return this._depth}},{key:"getCollapsedEdge",value:function(){var t=new Array(2).fill(null);return t[0]=this.pts[0],t[1]=this.pts[1],new i(t,Oe.toLineLabel(this._label))}},{key:"isIsolated",value:function(){return this._isIsolated}},{key:"getCoordinates",value:function(){return this.pts}},{key:"setIsolated",value:function(t){this._isIsolated=t}},{key:"setName",value:function(t){this._name=t}},{key:"equals",value:function(t){if(!(t instanceof i))return!1;var e=t;if(this.pts.length!==e.pts.length)return!1;for(var n=!0,r=!0,o=this.pts.length,s=0;s<this.pts.length;s++)if(this.pts[s].equals2D(e.pts[s])||(n=!1),this.pts[s].equals2D(e.pts[--o])||(r=!1),!n&&!r)return!1;return!0}},{key:"getCoordinate",value:function(){if(0===arguments.length)return this.pts.length>0?this.pts[0]:null;if(1===arguments.length){var t=arguments[0];return this.pts[t]}}},{key:"print",value:function(t){t.print("edge "+this._name+": "),t.print("LINESTRING (");for(var e=0;e<this.pts.length;e++)e>0&&t.print(","),t.print(this.pts[e].x+" "+this.pts[e].y);t.print(") "+this._label+" "+this._depthDelta)}},{key:"computeIM",value:function(t){i.updateIM(this._label,t)}},{key:"isCollapsed",value:function(){return!!this._label.isArea()&&3===this.pts.length&&!!this.pts[0].equals(this.pts[2])}},{key:"isClosed",value:function(){return this.pts[0].equals(this.pts[this.pts.length-1])}},{key:"getMaximumSegmentIndex",value:function(){return this.pts.length-1}},{key:"getDepthDelta",value:function(){return this._depthDelta}},{key:"getNumPoints",value:function(){return this.pts.length}},{key:"printReverse",value:function(t){t.print("edge "+this._name+": ");for(var e=this.pts.length-1;e>=0;e--)t.print(this.pts[e]+" ");t.println("")}},{key:"getMonotoneChainEdge",value:function(){return null===this._mce&&(this._mce=new ni(this)),this._mce}},{key:"getEnvelope",value:function(){if(null===this._env){this._env=new X;for(var t=0;t<this.pts.length;t++)this._env.expandToInclude(this.pts[t])}return this._env}},{key:"addIntersection",value:function(t,e,n,i){var r=new Y(t.getIntersection(i)),o=e,s=t.getEdgeDistance(n,i),a=o+1;if(a<this.pts.length){var l=this.pts[a];r.equals2D(l)&&(o=a,s=0)}this.eiList.add(r,o,s)}},{key:"toString",value:function(){var t=new Jt;t.append("edge "+this._name+": "),t.append("LINESTRING (");for(var e=0;e<this.pts.length;e++)e>0&&t.append(","),t.append(this.pts[e].x+" "+this.pts[e].y);return t.append(") "+this._label+" "+this._depthDelta),t.toString()}},{key:"isPointwiseEqual",value:function(t){if(this.pts.length!==t.pts.length)return!1;for(var e=0;e<this.pts.length;e++)if(!this.pts[e].equals2D(t.pts[e]))return!1;return!0}},{key:"setDepthDelta",value:function(t){this._depthDelta=t}},{key:"getEdgeIntersectionList",value:function(){return this.eiList}},{key:"addIntersections",value:function(t,e,n){for(var i=0;i<t.getIntersectionNum();i++)this.addIntersection(t,e,n,i)}}],[{key:"constructor_",value:function(){if(this.pts=null,this._env=null,this.eiList=new $n(this),this._name=null,this._mce=null,this._isIsolated=!0,this._depth=new ii,this._depthDelta=0,1===arguments.length){var t=arguments[0];i.constructor_.call(this,t,null)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.pts=e,this._label=n}}},{key:"updateIM",value:function(){if(!(2===arguments.length&&arguments[1]instanceof Qn&&arguments[0]instanceof Oe))return f(i,"updateIM",this).apply(this,arguments);var t=arguments[0],e=arguments[1];e.setAtLeastIfValid(t.getLocation(0,Q.ON),t.getLocation(1,Q.ON),1),t.isArea()&&(e.setAtLeastIfValid(t.getLocation(0,Q.LEFT),t.getLocation(1,Q.LEFT),2),e.setAtLeastIfValid(t.getLocation(0,Q.RIGHT),t.getLocation(1,Q.RIGHT),2))}}])}(Be),oi=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"setWorkingPrecisionModel",value:function(t){this._workingPrecisionModel=t}},{key:"insertUniqueEdge",value:function(e){var n=this._edgeList.findEqualEdge(e);if(null!==n){var i=n.getLabel(),r=e.getLabel();n.isPointwiseEqual(e)||(r=new Oe(e.getLabel())).flip(),i.merge(r);var o=t.depthDelta(r),s=n.getDepthDelta()+o;n.setDepthDelta(s)}else this._edgeList.add(e),e.setDepthDelta(t.depthDelta(e.getLabel()))}},{key:"buildSubgraphs",value:function(t,e){for(var n=new pt,i=t.iterator();i.hasNext();){var r=i.next(),o=r.getRightmostCoordinate(),s=new An(n).getDepth(o);r.computeDepth(s),r.findResultEdges(),n.add(r),e.add(r.getDirectedEdges(),r.getNodes())}}},{key:"createSubgraphs",value:function(t){for(var e=new pt,n=t.getNodes().iterator();n.hasNext();){var i=n.next();if(!i.isVisited()){var r=new mt;r.create(i),e.add(r)}}return sn.sort(e,sn.reverseOrder()),e}},{key:"createEmptyResultGeometry",value:function(){return this._geomFact.createPolygon()}},{key:"getNoder",value:function(t){if(null!==this._workingNoder)return this._workingNoder;var e=new Sn,n=new Ce;return n.setPrecisionModel(t),e.setSegmentIntersector(new Zn(n)),e}},{key:"buffer",value:function(t,e){var n=this._workingPrecisionModel;null===n&&(n=t.getPrecisionModel()),this._geomFact=t.getFactory();var i=new On(n,this._bufParams),r=new zn(t,e,i).getCurves();if(r.size()<=0)return this.createEmptyResultGeometry();this.computeNodedEdges(r,n),this._graph=new $e(new Vn),this._graph.addEdges(this._edgeList.getEdges());var o=this.createSubgraphs(this._graph),s=new Qe(this._geomFact);this.buildSubgraphs(o,s);var a=s.getPolygons();return a.size()<=0?this.createEmptyResultGeometry():this._geomFact.buildGeometry(a)}},{key:"computeNodedEdges",value:function(t,e){var n=this.getNoder(e);n.computeNodes(t);for(var i=n.getNodedSubstrings().iterator();i.hasNext();){var r=i.next(),o=r.getCoordinates();if(2!==o.length||!o[0].equals2D(o[1])){var s=r.getData(),a=new ri(r.getCoordinates(),new Oe(s));this.insertUniqueEdge(a)}}}},{key:"setNoder",value:function(t){this._workingNoder=t}}],[{key:"constructor_",value:function(){this._bufParams=null,this._workingPrecisionModel=null,this._workingNoder=null,this._geomFact=null,this._graph=null,this._edgeList=new Kn;var t=arguments[0];this._bufParams=t}},{key:"depthDelta",value:function(t){var e=t.getLocation(0,Q.LEFT),n=t.getLocation(0,Q.RIGHT);return e===V.INTERIOR&&n===V.EXTERIOR?1:e===V.EXTERIOR&&n===V.INTERIOR?-1:0}},{key:"convertSegStrings",value:function(t){for(var e=new se,n=new pt;t.hasNext();){var i=t.next(),r=e.createLineString(i.getCoordinates());n.add(r)}return e.buildGeometry(n)}}])}(),si=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"rescale",value:function(){if(rt(arguments[0],j))for(var t=arguments[0].iterator();t.hasNext();){var e=t.next();this.rescale(e.getCoordinates())}else if(arguments[0]instanceof Array){for(var n=arguments[0],i=0;i<n.length;i++)n[i].x=n[i].x/this._scaleFactor+this._offsetX,n[i].y=n[i].y/this._scaleFactor+this._offsetY;2===n.length&&n[0].equals2D(n[1])&&_t.out.println(n)}}},{key:"scale",value:function(){if(rt(arguments[0],j)){for(var t=arguments[0],e=new pt(t.size()),n=t.iterator();n.hasNext();){var i=n.next();e.add(new xn(this.scale(i.getCoordinates()),i.getData()))}return e}if(arguments[0]instanceof Array){for(var r=arguments[0],o=new Array(r.length).fill(null),s=0;s<r.length;s++)o[s]=new Y(Math.round((r[s].x-this._offsetX)*this._scaleFactor),Math.round((r[s].y-this._offsetY)*this._scaleFactor),r[s].getZ());return Kt.removeRepeatedPoints(o)}}},{key:"isIntegerPrecision",value:function(){return 1===this._scaleFactor}},{key:"getNodedSubstrings",value:function(){var t=this._noder.getNodedSubstrings();return this._isScaled&&this.rescale(t),t}},{key:"computeNodes",value:function(t){var e=t;this._isScaled&&(e=this.scale(t)),this._noder.computeNodes(e)}},{key:"interfaces_",get:function(){return[bn]}}],[{key:"constructor_",value:function(){if(this._noder=null,this._scaleFactor=null,this._offsetX=null,this._offsetY=null,this._isScaled=!1,2===arguments.length){var e=arguments[0],n=arguments[1];t.constructor_.call(this,e,n,0,0)}else if(4===arguments.length){var i=arguments[0],r=arguments[1];this._noder=i,this._scaleFactor=r,this._isScaled=!this.isIntegerPrecision()}}}])}(),ai=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"checkEndPtVertexIntersections",value:function(){if(0===arguments.length)for(var t=this._segStrings.iterator();t.hasNext();){var e=t.next().getCoordinates();this.checkEndPtVertexIntersections(e[0],this._segStrings),this.checkEndPtVertexIntersections(e[e.length-1],this._segStrings)}else if(2===arguments.length)for(var n=arguments[0],i=arguments[1].iterator();i.hasNext();)for(var r=i.next().getCoordinates(),o=1;o<r.length-1;o++)if(r[o].equals(n))throw new R("found endpt/interior pt intersection at index "+o+" :pt "+n)}},{key:"checkInteriorIntersections",value:function(){if(0===arguments.length)for(var t=this._segStrings.iterator();t.hasNext();)for(var e=t.next(),n=this._segStrings.iterator();n.hasNext();){var i=n.next();this.checkInteriorIntersections(e,i)}else if(2===arguments.length)for(var r=arguments[0],o=arguments[1],s=r.getCoordinates(),a=o.getCoordinates(),l=0;l<s.length-1;l++)for(var u=0;u<a.length-1;u++)this.checkInteriorIntersections(r,l,o,u);else if(4===arguments.length){var h=arguments[0],c=arguments[1],f=arguments[2],g=arguments[3];if(h===f&&c===g)return null;var d=h.getCoordinates()[c],p=h.getCoordinates()[c+1],y=f.getCoordinates()[g],m=f.getCoordinates()[g+1];if(this._li.computeIntersection(d,p,y,m),this._li.hasIntersection()&&(this._li.isProper()||this.hasInteriorIntersection(this._li,d,p)||this.hasInteriorIntersection(this._li,y,m)))throw new R("found non-noded intersection at "+d+"-"+p+" and "+y+"-"+m)}}},{key:"checkValid",value:function(){this.checkEndPtVertexIntersections(),this.checkInteriorIntersections(),this.checkCollapses()}},{key:"checkCollapses",value:function(){if(0===arguments.length)for(var t=this._segStrings.iterator();t.hasNext();){var e=t.next();this.checkCollapses(e)}else if(1===arguments.length)for(var n=arguments[0].getCoordinates(),i=0;i<n.length-2;i++)this.checkCollapse(n[i],n[i+1],n[i+2])}},{key:"hasInteriorIntersection",value:function(t,e,n){for(var i=0;i<t.getIntersectionNum();i++){var r=t.getIntersection(i);if(!r.equals(e)&&!r.equals(n))return!0}return!1}},{key:"checkCollapse",value:function(e,n,i){if(e.equals(i))throw new R("found non-noded collapse at "+t.fact.createLineString([e,n,i]))}}],[{key:"constructor_",value:function(){this._li=new Ce,this._segStrings=null;var t=arguments[0];this._segStrings=t}}])}();ai.fact=new se;var li=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"intersectsScaled",value:function(t,e){var n=Math.min(t.x,e.x),i=Math.max(t.x,e.x),r=Math.min(t.y,e.y),o=Math.max(t.y,e.y),s=this._maxx<n||this._minx>i||this._maxy<r||this._miny>o;if(s)return!1;var a=this.intersectsToleranceSquare(t,e);return B.isTrue(!(s&&a),"Found bad envelope test"),a}},{key:"initCorners",value:function(t){var e=.5;this._minx=t.x-e,this._maxx=t.x+e,this._miny=t.y-e,this._maxy=t.y+e,this._corner[0]=new Y(this._maxx,this._maxy),this._corner[1]=new Y(this._minx,this._maxy),this._corner[2]=new Y(this._minx,this._miny),this._corner[3]=new Y(this._maxx,this._miny)}},{key:"intersects",value:function(t,e){return 1===this._scaleFactor?this.intersectsScaled(t,e):(this.copyScaled(t,this._p0Scaled),this.copyScaled(e,this._p1Scaled),this.intersectsScaled(this._p0Scaled,this._p1Scaled))}},{key:"scale",value:function(t){return Math.round(t*this._scaleFactor)}},{key:"getCoordinate",value:function(){return this._originalPt}},{key:"copyScaled",value:function(t,e){e.x=this.scale(t.x),e.y=this.scale(t.y)}},{key:"getSafeEnvelope",value:function(){if(null===this._safeEnv){var e=t.SAFE_ENV_EXPANSION_FACTOR/this._scaleFactor;this._safeEnv=new X(this._originalPt.x-e,this._originalPt.x+e,this._originalPt.y-e,this._originalPt.y+e)}return this._safeEnv}},{key:"intersectsPixelClosure",value:function(t,e){return this._li.computeIntersection(t,e,this._corner[0],this._corner[1]),!!(this._li.hasIntersection()||(this._li.computeIntersection(t,e,this._corner[1],this._corner[2]),this._li.hasIntersection()||(this._li.computeIntersection(t,e,this._corner[2],this._corner[3]),this._li.hasIntersection()||(this._li.computeIntersection(t,e,this._corner[3],this._corner[0]),this._li.hasIntersection()))))}},{key:"intersectsToleranceSquare",value:function(t,e){var n=!1,i=!1;return this._li.computeIntersection(t,e,this._corner[0],this._corner[1]),!!(this._li.isProper()||(this._li.computeIntersection(t,e,this._corner[1],this._corner[2]),this._li.isProper()||(this._li.hasIntersection()&&(n=!0),this._li.computeIntersection(t,e,this._corner[2],this._corner[3]),this._li.isProper()||(this._li.hasIntersection()&&(i=!0),this._li.computeIntersection(t,e,this._corner[3],this._corner[0]),this._li.isProper()||n&&i||t.equals(this._pt)||e.equals(this._pt)))))}},{key:"addSnappedNode",value:function(t,e){var n=t.getCoordinate(e),i=t.getCoordinate(e+1);return!!this.intersects(n,i)&&(t.addIntersection(this.getCoordinate(),e),!0)}}],[{key:"constructor_",value:function(){this._li=null,this._pt=null,this._originalPt=null,this._ptScaled=null,this._p0Scaled=null,this._p1Scaled=null,this._scaleFactor=null,this._minx=null,this._maxx=null,this._miny=null,this._maxy=null,this._corner=new Array(4).fill(null),this._safeEnv=null;var t=arguments[0],e=arguments[1],n=arguments[2];if(this._originalPt=t,this._pt=t,this._scaleFactor=e,this._li=n,e<=0)throw new _("Scale factor must be non-zero");1!==e&&(this._pt=new Y(this.scale(t.x),this.scale(t.y)),this._p0Scaled=new Y,this._p1Scaled=new Y),this.initCorners(this._pt)}}])}();li.SAFE_ENV_EXPANSION_FACTOR=.75;var ui=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"select",value:function(){if(1===arguments.length);else if(2===arguments.length){var t=arguments[1];arguments[0].getLineSegment(t,this.selectedSegment),this.select(this.selectedSegment)}}}],[{key:"constructor_",value:function(){this.selectedSegment=new En}}]),hi=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"snap",value:function(){if(1===arguments.length){var t=arguments[0];return this.snap(t,null,-1)}if(3===arguments.length){var e=arguments[0],i=arguments[1],r=arguments[2],s=e.getSafeEnvelope(),a=new ci(e,i,r);return this._index.query(s,new(o(function t(){n(this,t)},[{key:"interfaces_",get:function(){return[un]}},{key:"visitItem",value:function(t){t.select(s,a)}}]))),a.isNodeAdded()}}}],[{key:"constructor_",value:function(){this._index=null;var t=arguments[0];this._index=t}}]),ci=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return u(i,t),o(i,[{key:"isNodeAdded",value:function(){return this._isNodeAdded}},{key:"select",value:function(){if(!(2===arguments.length&&Number.isInteger(arguments[1])&&arguments[0]instanceof Mn))return f(i,"select",this,1).apply(this,arguments);var t=arguments[1],e=arguments[0].getContext();if(this._parentEdge===e&&(t===this._hotPixelVertexIndex||t+1===this._hotPixelVertexIndex))return null;this._isNodeAdded|=this._hotPixel.addSnappedNode(e,t)}}],[{key:"constructor_",value:function(){this._hotPixel=null,this._parentEdge=null,this._hotPixelVertexIndex=null,this._isNodeAdded=!1;var t=arguments[0],e=arguments[1],n=arguments[2];this._hotPixel=t,this._parentEdge=e,this._hotPixelVertexIndex=n}}])}(ui);hi.HotPixelSnapAction=ci;var fi=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"processIntersections",value:function(t,e,n,i){if(t===n&&e===i)return null;var r=t.getCoordinates()[e],o=t.getCoordinates()[e+1],s=n.getCoordinates()[i],a=n.getCoordinates()[i+1];if(this._li.computeIntersection(r,o,s,a),this._li.hasIntersection()&&this._li.isInteriorIntersection()){for(var l=0;l<this._li.getIntersectionNum();l++)this._interiorIntersections.add(this._li.getIntersection(l));t.addIntersections(this._li,e,0),n.addIntersections(this._li,i,1)}}},{key:"isDone",value:function(){return!1}},{key:"getInteriorIntersections",value:function(){return this._interiorIntersections}},{key:"interfaces_",get:function(){return[Wn]}}],[{key:"constructor_",value:function(){this._li=null,this._interiorIntersections=null;var t=arguments[0];this._li=t,this._interiorIntersections=new pt}}]),gi=o(function t(){n(this,t),t.constructor_.apply(this,arguments)},[{key:"checkCorrectness",value:function(t){var e=xn.getNodedSubstrings(t),n=new ai(e);try{n.checkValid()}catch(i){if(!(i instanceof v))throw i;i.printStackTrace()}}},{key:"getNodedSubstrings",value:function(){return xn.getNodedSubstrings(this._nodedSegStrings)}},{key:"snapRound",value:function(t,e){var n=this.findInteriorIntersections(t,e);this.computeIntersectionSnaps(n),this.computeVertexSnaps(t)}},{key:"findInteriorIntersections",value:function(t,e){var n=new fi(e);return this._noder.setSegmentIntersector(n),this._noder.computeNodes(t),n.getInteriorIntersections()}},{key:"computeVertexSnaps",value:function(){if(rt(arguments[0],j))for(var t=arguments[0].iterator();t.hasNext();){var e=t.next();this.computeVertexSnaps(e)}else if(arguments[0]instanceof xn)for(var n=arguments[0],i=n.getCoordinates(),r=0;r<i.length;r++){var o=new li(i[r],this._scaleFactor,this._li);this._pointSnapper.snap(o,n,r)&&n.addIntersection(i[r],r)}}},{key:"computeNodes",value:function(t){this._nodedSegStrings=t,this._noder=new Sn,this._pointSnapper=new hi(this._noder.getIndex()),this.snapRound(t,this._li)}},{key:"computeIntersectionSnaps",value:function(t){for(var e=t.iterator();e.hasNext();){var n=e.next(),i=new li(n,this._scaleFactor,this._li);this._pointSnapper.snap(i)}}},{key:"interfaces_",get:function(){return[bn]}}],[{key:"constructor_",value:function(){this._pm=null,this._li=null,this._scaleFactor=null,this._noder=null,this._pointSnapper=null,this._nodedSegStrings=null;var t=arguments[0];this._pm=t,this._li=new Ce,this._li.setPrecisionModel(t),this._scaleFactor=t.getScale()}}]),di=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return o(t,[{key:"bufferFixedPrecision",value:function(t){var e=new si(new gi(new ie(1)),t.getScale()),n=new oi(this._bufParams);n.setWorkingPrecisionModel(t),n.setNoder(e),this._resultGeometry=n.buffer(this._argGeom,this._distance)}},{key:"bufferReducedPrecision",value:function(){if(0===arguments.length){for(var e=t.MAX_PRECISION_DIGITS;e>=0;e--){try{this.bufferReducedPrecision(e)}catch(o){if(!(o instanceof gt))throw o;this._saveException=o}if(null!==this._resultGeometry)return null}throw this._saveException}if(1===arguments.length){var n=arguments[0],i=t.precisionScaleFactor(this._argGeom,this._distance,n),r=new ie(i);this.bufferFixedPrecision(r)}}},{key:"computeGeometry",value:function(){if(this.bufferOriginalPrecision(),null!==this._resultGeometry)return null;var t=this._argGeom.getFactory().getPrecisionModel();t.getType()===ie.FIXED?this.bufferFixedPrecision(t):this.bufferReducedPrecision()}},{key:"setQuadrantSegments",value:function(t){this._bufParams.setQuadrantSegments(t)}},{key:"bufferOriginalPrecision",value:function(){try{var t=new oi(this._bufParams);this._resultGeometry=t.buffer(this._argGeom,this._distance)}catch(e){if(!(e instanceof R))throw e;this._saveException=e}}},{key:"getResultGeometry",value:function(t){return this._distance=t,this.computeGeometry(),this._resultGeometry}},{key:"setEndCapStyle",value:function(t){this._bufParams.setEndCapStyle(t)}}],[{key:"constructor_",value:function(){if(this._argGeom=null,this._distance=null,this._bufParams=new m,this._resultGeometry=null,this._saveException=null,1===arguments.length){var t=arguments[0];this._argGeom=t}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this._argGeom=e,this._bufParams=n}}},{key:"bufferOp",value:function(){if(2===arguments.length){var e=arguments[1];return new t(arguments[0]).getResultGeometry(e)}if(3===arguments.length){if(Number.isInteger(arguments[2])&&arguments[0]instanceof q&&"number"==typeof arguments[1]){var n=arguments[1],i=arguments[2],r=new t(arguments[0]);return r.setQuadrantSegments(i),r.getResultGeometry(n)}if(arguments[2]instanceof m&&arguments[0]instanceof q&&"number"==typeof arguments[1]){var o=arguments[1];return new t(arguments[0],arguments[2]).getResultGeometry(o)}}else if(4===arguments.length){var s=arguments[1],a=arguments[2],l=arguments[3],u=new t(arguments[0]);return u.setQuadrantSegments(a),u.setEndCapStyle(l),u.getResultGeometry(s)}}},{key:"precisionScaleFactor",value:function(t,e,n){var i=t.getEnvelopeInternal(),r=kt.max(Math.abs(i.getMaxX()),Math.abs(i.getMaxY()),Math.abs(i.getMinX()),Math.abs(i.getMinY()))+2*(e>0?e:0),o=n-Math.trunc(Math.log(r)/Math.log(10)+1);return Math.pow(10,o)}}])}();di.CAP_ROUND=m.CAP_ROUND,di.CAP_BUTT=m.CAP_FLAT,di.CAP_FLAT=m.CAP_FLAT,di.CAP_SQUARE=m.CAP_SQUARE,di.MAX_PRECISION_DIGITS=12;var pi=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],yi=o(function t(e){n(this,t),this.geometryFactory=e||new se},[{key:"read",value:function(t){var e,n=(e="string"==typeof t?JSON.parse(t):t).type;if(!mi[n])throw new Error("Unknown GeoJSON type: "+e.type);return-1!==pi.indexOf(n)?mi[n].call(this,e.coordinates):"GeometryCollection"===n?mi[n].call(this,e.geometries):mi[n].call(this,e)}},{key:"write",value:function(t){var e=t.getGeometryType();if(!vi[e])throw new Error("Geometry is not supported");return vi[e].call(this,t)}}]),mi={Feature:function(t){var e={};for(var n in t)e[n]=t[n];if(t.geometry){var i=t.geometry.type;if(!mi[i])throw new Error("Unknown GeoJSON type: "+t.type);e.geometry=this.read(t.geometry)}return t.bbox&&(e.bbox=mi.bbox.call(this,t.bbox)),e},FeatureCollection:function(t){var e={};if(t.features){e.features=[];for(var n=0;n<t.features.length;++n)e.features.push(this.read(t.features[n]))}return t.bbox&&(e.bbox=this.parse.bbox.call(this,t.bbox)),e},coordinates:function(t){for(var e=[],n=0;n<t.length;++n){var r=t[n];e.push(i(Y,g(r)))}return e},bbox:function(t){return this.geometryFactory.createLinearRing([new Y(t[0],t[1]),new Y(t[2],t[1]),new Y(t[2],t[3]),new Y(t[0],t[3]),new Y(t[0],t[1])])},Point:function(t){var e=i(Y,g(t));return this.geometryFactory.createPoint(e)},MultiPoint:function(t){for(var e=[],n=0;n<t.length;++n)e.push(mi.Point.call(this,t[n]));return this.geometryFactory.createMultiPoint(e)},LineString:function(t){var e=mi.coordinates.call(this,t);return this.geometryFactory.createLineString(e)},MultiLineString:function(t){for(var e=[],n=0;n<t.length;++n)e.push(mi.LineString.call(this,t[n]));return this.geometryFactory.createMultiLineString(e)},Polygon:function(t){for(var e=mi.coordinates.call(this,t[0]),n=this.geometryFactory.createLinearRing(e),i=[],r=1;r<t.length;++r){var o=t[r],s=mi.coordinates.call(this,o),a=this.geometryFactory.createLinearRing(s);i.push(a)}return this.geometryFactory.createPolygon(n,i)},MultiPolygon:function(t){for(var e=[],n=0;n<t.length;++n){var i=t[n];e.push(mi.Polygon.call(this,i))}return this.geometryFactory.createMultiPolygon(e)},GeometryCollection:function(t){for(var e=[],n=0;n<t.length;++n){var i=t[n];e.push(this.read(i))}return this.geometryFactory.createGeometryCollection(e)}},vi={coordinate:function(t){var e=[t.x,t.y];return t.z&&e.push(t.z),t.m&&e.push(t.m),e},Point:function(t){return{type:"Point",coordinates:vi.coordinate.call(this,t.getCoordinate())}},MultiPoint:function(t){for(var e=[],n=0;n<t._geometries.length;++n){var i=t._geometries[n],r=vi.Point.call(this,i);e.push(r.coordinates)}return{type:"MultiPoint",coordinates:e}},LineString:function(t){for(var e=[],n=t.getCoordinates(),i=0;i<n.length;++i){var r=n[i];e.push(vi.coordinate.call(this,r))}return{type:"LineString",coordinates:e}},MultiLineString:function(t){for(var e=[],n=0;n<t._geometries.length;++n){var i=t._geometries[n],r=vi.LineString.call(this,i);e.push(r.coordinates)}return{type:"MultiLineString",coordinates:e}},Polygon:function(t){var e=[],n=vi.LineString.call(this,t._shell);e.push(n.coordinates);for(var i=0;i<t._holes.length;++i){var r=t._holes[i],o=vi.LineString.call(this,r);e.push(o.coordinates)}return{type:"Polygon",coordinates:e}},MultiPolygon:function(t){for(var e=[],n=0;n<t._geometries.length;++n){var i=t._geometries[n],r=vi.Polygon.call(this,i);e.push(r.coordinates)}return{type:"MultiPolygon",coordinates:e}},GeometryCollection:function(t){for(var e=[],n=0;n<t._geometries.length;++n){var i=t._geometries[n],r=i.getGeometryType();e.push(vi[r].call(this,i))}return{type:"GeometryCollection",geometries:e}}};return{BufferOp:di,GeoJSONReader:o(function t(e){n(this,t),this.parser=new yi(e||new se)},[{key:"read",value:function(t){return this.parser.read(t)}}]),GeoJSONWriter:o(function t(){n(this,t),this.parser=new yi(this.geometryFactory)},[{key:"write",value:function(t){return this.parser.write(t)}}])}}()),Xe.exports);const Ve=Z(qe);function je(){return new Ke}function Ke(){this.reset()}Ke.prototype={constructor:Ke,reset:function(){this.s=this.t=0},add:function(t){Ze(We,t,this.t),Ze(this,We.s,this.s),this.s?this.t+=We.t:this.s=We.t},valueOf:function(){return this.s}};var We=new Ke;function Ze(t,e,n){var i=t.s=e+n,r=i-e,o=i-r;t.t=e-o+(n-r)}var Je=1e-6,$e=Math.PI,Qe=$e/2,tn=$e/4,en=2*$e,nn=180/$e,rn=$e/180,on=Math.abs,sn=Math.atan,an=Math.atan2,ln=Math.cos,un=Math.sin,hn=Math.sqrt;function cn(t){return t>1?0:t<-1?$e:Math.acos(t)}function fn(t){return t>1?Qe:t<-1?-Qe:Math.asin(t)}function gn(){}function dn(t,e){t&&vn.hasOwnProperty(t.type)&&vn[t.type](t,e)}var pn,yn,mn={Feature:function(t,e){dn(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)dn(n[i].geometry,e)}},vn={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)t=n[i],e.point(t[0],t[1],t[2])},LineString:function(t,e){_n(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)_n(n[i],e,0)},Polygon:function(t,e){kn(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)kn(n[i],e)},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)dn(n[i],e)}};function _n(t,e,n){var i,r=-1,o=t.length-n;for(e.lineStart();++r<o;)i=t[r],e.point(i[0],i[1],i[2]);e.lineEnd()}function kn(t,e){var n=-1,i=t.length;for(e.polygonStart();++n<i;)_n(t[n],e,1);e.polygonEnd()}function xn(t){return[an(t[1],t[0]),fn(t[2])]}function En(t){var e=t[0],n=t[1],i=ln(n);return[i*ln(e),i*un(e),un(n)]}function wn(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Mn(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Pn(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function bn(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function In(t){var e=hn(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}function Sn(t,e){function n(n,i){return n=t(n,i),e(n[0],n[1])}return t.invert&&e.invert&&(n.invert=function(n,i){return(n=e.invert(n,i))&&t.invert(n[0],n[1])}),n}function Ln(t,e){return[t>$e?t-en:t<-$e?t+en:t,e]}function Cn(t){return function(e,n){return[(e+=t)>$e?e-en:e<-$e?e+en:e,n]}}function Nn(t){var e=Cn(t);return e.invert=Cn(-t),e}function Tn(t,e){var n=ln(t),i=un(t),r=ln(e),o=un(e);function s(t,e){var s=ln(e),a=ln(t)*s,l=un(t)*s,u=un(e),h=u*n+a*i;return[an(l*r-h*o,a*n-u*i),fn(h*r+l*o)]}return s.invert=function(t,e){var s=ln(e),a=ln(t)*s,l=un(t)*s,u=un(e),h=u*r-l*o;return[an(l*r+u*o,a*n+h*i),fn(h*n-a*i)]},s}function Dn(t,e){(e=En(e))[0]-=t,In(e);var n=cn(-e[1]);return((-e[2]<0?-n:n)+en-Je)%en}function On(){var t,e=[];return{point:function(e,n){t.push([e,n])},lineStart:function(){e.push(t=[])},lineEnd:gn,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function An(t,e){return on(t[0]-e[0])<Je&&on(t[1]-e[1])<Je}function Rn(t,e,n,i){this.x=t,this.z=e,this.o=n,this.e=i,this.v=!1,this.n=this.p=null}function Fn(t,e,n,i,r){var o,s,a=[],l=[];if(t.forEach(function(t){if(!((e=t.length-1)<=0)){var e,n,i=t[0],s=t[e];if(An(i,s)){for(r.lineStart(),o=0;o<e;++o)r.point((i=t[o])[0],i[1]);r.lineEnd()}else a.push(n=new Rn(i,t,null,!0)),l.push(n.o=new Rn(i,null,n,!1)),a.push(n=new Rn(s,t,null,!1)),l.push(n.o=new Rn(s,null,n,!0))}}),a.length){for(l.sort(e),Bn(a),Bn(l),o=0,s=l.length;o<s;++o)l[o].e=n=!n;for(var u,h,c=a[0];;){for(var f=c,g=!0;f.v;)if((f=f.n)===c)return;u=f.z,r.lineStart();do{if(f.v=f.o.v=!0,f.e){if(g)for(o=0,s=u.length;o<s;++o)r.point((h=u[o])[0],h[1]);else i(f.x,f.n.x,1,r);f=f.n}else{if(g)for(u=f.p.z,o=u.length-1;o>=0;--o)r.point((h=u[o])[0],h[1]);else i(f.x,f.p.x,-1,r);f=f.p}u=(f=f.o).z,g=!g}while(!f.v);r.lineEnd()}}}function Bn(t){if(e=t.length){for(var e,n,i=0,r=t[0];++i<e;)r.n=n=t[i],n.p=r,r=n;r.n=n=t[0],n.p=r}}function Gn(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function zn(t){for(var e,n,i,r=t.length,o=-1,s=0;++o<r;)s+=t[o].length;for(n=new Array(s);--r>=0;)for(e=(i=t[r]).length;--e>=0;)n[--s]=i[e];return n}je(),je(),je(),Ln.invert=Ln,1===(pn=Gn).length&&(yn=pn,pn=function(t,e){return Gn(yn(t),e)});var Hn=1e9,Yn=-Hn;function Un(t,e,n,i){function r(r,o){return t<=r&&r<=n&&e<=o&&o<=i}function o(r,o,a,u){var h=0,c=0;if(null==r||(h=s(r,a))!==(c=s(o,a))||l(r,o)<0^a>0)do{u.point(0===h||3===h?t:n,h>1?i:e)}while((h=(h+a+4)%4)!==c);else u.point(o[0],o[1])}function s(i,r){return on(i[0]-t)<Je?r>0?0:3:on(i[0]-n)<Je?r>0?2:1:on(i[1]-e)<Je?r>0?1:0:r>0?3:2}function a(t,e){return l(t.x,e.x)}function l(t,e){var n=s(t,1),i=s(e,1);return n!==i?n-i:0===n?e[1]-t[1]:1===n?t[0]-e[0]:2===n?t[1]-e[1]:e[0]-t[0]}return function(s){var l,u,h,c,f,g,d,p,y,m,v,_=s,k=On(),x={point:E,lineStart:function(){x.point=w,u&&u.push(h=[]);m=!0,y=!1,d=p=NaN},lineEnd:function(){l&&(w(c,f),g&&y&&k.rejoin(),l.push(k.result()));x.point=E,y&&_.lineEnd()},polygonStart:function(){_=k,l=[],u=[],v=!0},polygonEnd:function(){var e=function(){for(var e=0,n=0,r=u.length;n<r;++n)for(var o,s,a=u[n],l=1,h=a.length,c=a[0],f=c[0],g=c[1];l<h;++l)o=f,s=g,f=(c=a[l])[0],g=c[1],s<=i?g>i&&(f-o)*(i-s)>(g-s)*(t-o)&&++e:g<=i&&(f-o)*(i-s)<(g-s)*(t-o)&&--e;return e}(),n=v&&e,r=(l=zn(l)).length;(n||r)&&(s.polygonStart(),n&&(s.lineStart(),o(null,null,1,s),s.lineEnd()),r&&Fn(l,a,e,o,s),s.polygonEnd());_=s,l=u=h=null}};function E(t,e){r(t,e)&&_.point(t,e)}function w(o,s){var a=r(o,s);if(u&&h.push([o,s]),m)c=o,f=s,g=a,m=!1,a&&(_.lineStart(),_.point(o,s));else if(a&&y)_.point(o,s);else{var l=[d=Math.max(Yn,Math.min(Hn,d)),p=Math.max(Yn,Math.min(Hn,p))],k=[o=Math.max(Yn,Math.min(Hn,o)),s=Math.max(Yn,Math.min(Hn,s))];!function(t,e,n,i,r,o){var s,a=t[0],l=t[1],u=0,h=1,c=e[0]-a,f=e[1]-l;if(s=n-a,c||!(s>0)){if(s/=c,c<0){if(s<u)return;s<h&&(h=s)}else if(c>0){if(s>h)return;s>u&&(u=s)}if(s=r-a,c||!(s<0)){if(s/=c,c<0){if(s>h)return;s>u&&(u=s)}else if(c>0){if(s<u)return;s<h&&(h=s)}if(s=i-l,f||!(s>0)){if(s/=f,f<0){if(s<u)return;s<h&&(h=s)}else if(f>0){if(s>h)return;s>u&&(u=s)}if(s=o-l,f||!(s<0)){if(s/=f,f<0){if(s>h)return;s>u&&(u=s)}else if(f>0){if(s<u)return;s<h&&(h=s)}return u>0&&(t[0]=a+u*c,t[1]=l+u*f),h<1&&(e[0]=a+h*c,e[1]=l+h*f),!0}}}}}(l,k,t,e,n,i)?a&&(_.lineStart(),_.point(o,s),v=!1):(y||(_.lineStart(),_.point(l[0],l[1])),_.point(k[0],k[1]),a||_.lineEnd(),v=!1)}d=o,p=s,y=a}return x}}var Xn=je();function qn(t){return t}je(),je(),je();var Vn=1/0,jn=Vn,Kn=-Vn,Wn=Kn,Zn={point:function(t,e){t<Vn&&(Vn=t);t>Kn&&(Kn=t);e<jn&&(jn=e);e>Wn&&(Wn=e)},lineStart:gn,lineEnd:gn,polygonStart:gn,polygonEnd:gn,result:function(){var t=[[Vn,jn],[Kn,Wn]];return Kn=Wn=-(jn=Vn=1/0),t}};function Jn(t,e,n,i){return function(r,o){var s,a,l,u=e(o),h=r.invert(i[0],i[1]),c=On(),f=e(c),g=!1,d={point:p,lineStart:m,lineEnd:v,polygonStart:function(){d.point=_,d.lineStart=k,d.lineEnd=x,a=[],s=[]},polygonEnd:function(){d.point=p,d.lineStart=m,d.lineEnd=v,a=zn(a);var t=function(t,e){var n=e[0],i=e[1],r=[un(n),-ln(n),0],o=0,s=0;Xn.reset();for(var a=0,l=t.length;a<l;++a)if(h=(u=t[a]).length)for(var u,h,c=u[h-1],f=c[0],g=c[1]/2+tn,d=un(g),p=ln(g),y=0;y<h;++y,f=v,d=k,p=x,c=m){var m=u[y],v=m[0],_=m[1]/2+tn,k=un(_),x=ln(_),E=v-f,w=E>=0?1:-1,M=w*E,P=M>$e,b=d*k;if(Xn.add(an(b*w*un(M),p*x+b*ln(M))),o+=P?E+w*en:E,P^f>=n^v>=n){var I=Mn(En(c),En(m));In(I);var S=Mn(r,I);In(S);var L=(P^E>=0?-1:1)*fn(S[2]);(i>L||i===L&&(I[0]||I[1]))&&(s+=P^E>=0?1:-1)}}return(o<-1e-6||o<Je&&Xn<-1e-6)^1&s}(s,h);a.length?(g||(o.polygonStart(),g=!0),Fn(a,Qn,t,n,o)):t&&(g||(o.polygonStart(),g=!0),o.lineStart(),n(null,null,1,o),o.lineEnd()),g&&(o.polygonEnd(),g=!1),a=s=null},sphere:function(){o.polygonStart(),o.lineStart(),n(null,null,1,o),o.lineEnd(),o.polygonEnd()}};function p(e,n){var i=r(e,n);t(e=i[0],n=i[1])&&o.point(e,n)}function y(t,e){var n=r(t,e);u.point(n[0],n[1])}function m(){d.point=y,u.lineStart()}function v(){d.point=p,u.lineEnd()}function _(t,e){l.push([t,e]);var n=r(t,e);f.point(n[0],n[1])}function k(){f.lineStart(),l=[]}function x(){_(l[0][0],l[0][1]),f.lineEnd();var t,e,n,i,r=f.clean(),u=c.result(),h=u.length;if(l.pop(),s.push(l),l=null,h)if(1&r){if((e=(n=u[0]).length-1)>0){for(g||(o.polygonStart(),g=!0),o.lineStart(),t=0;t<e;++t)o.point((i=n[t])[0],i[1]);o.lineEnd()}}else h>1&&2&r&&u.push(u.pop().concat(u.shift())),a.push(u.filter($n))}return d}}function $n(t){return t.length>1}function Qn(t,e){return((t=t.x)[0]<0?t[1]-Qe-Je:Qe-t[1])-((e=e.x)[0]<0?e[1]-Qe-Je:Qe-e[1])}je();const ti=Jn(function(){return!0},function(t){var e,n=NaN,i=NaN,r=NaN;return{lineStart:function(){t.lineStart(),e=1},point:function(o,s){var a=o>0?$e:-$e,l=on(o-n);on(l-$e)<Je?(t.point(n,i=(i+s)/2>0?Qe:-Qe),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),t.point(o,i),e=0):r!==a&&l>=$e&&(on(n-r)<Je&&(n-=r*Je),on(o-a)<Je&&(o-=a*Je),i=function(t,e,n,i){var r,o,s=un(t-n);return on(s)>Je?sn((un(e)*(o=ln(i))*un(n)-un(i)*(r=ln(e))*un(t))/(r*o*s)):(e+i)/2}(n,i,o,s),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),e=0),t.point(n=o,i=s),r=a},lineEnd:function(){t.lineEnd(),n=i=NaN},clean:function(){return 2-e}}},function(t,e,n,i){var r;if(null==t)r=n*Qe,i.point(-$e,r),i.point(0,r),i.point($e,r),i.point($e,0),i.point($e,-r),i.point(0,-r),i.point(-$e,-r),i.point(-$e,0),i.point(-$e,r);else if(on(t[0]-e[0])>Je){var o=t[0]<e[0]?$e:-$e;r=n*o/2,i.point(-o,r),i.point(0,r),i.point(o,r)}else i.point(e[0],e[1])},[-$e,-Qe]);function ei(t,e){var n=ln(t),i=n>0,r=on(n)>Je;function o(t,e){return ln(t)*ln(e)>n}function s(t,e,i){var r=[1,0,0],o=Mn(En(t),En(e)),s=wn(o,o),a=o[0],l=s-a*a;if(!l)return!i&&t;var u=n*s/l,h=-n*a/l,c=Mn(r,o),f=bn(r,u);Pn(f,bn(o,h));var g=c,d=wn(f,g),p=wn(g,g),y=d*d-p*(wn(f,f)-1);if(!(y<0)){var m=hn(y),v=bn(g,(-d-m)/p);if(Pn(v,f),v=xn(v),!i)return v;var _,k=t[0],x=e[0],E=t[1],w=e[1];x<k&&(_=k,k=x,x=_);var M=x-k,P=on(M-$e)<Je;if(!P&&w<E&&(_=E,E=w,w=_),P||M<Je?P?E+w>0^v[1]<(on(v[0]-k)<Je?E:w):E<=v[1]&&v[1]<=w:M>$e^(k<=v[0]&&v[0]<=x)){var b=bn(g,(-d+m)/p);return Pn(b,f),[v,xn(b)]}}}function a(e,n){var r=i?t:$e-t,o=0;return e<-r?o|=1:e>r&&(o|=2),n<-r?o|=4:n>r&&(o|=8),o}return Jn(o,function(t){var e,n,l,u,h;return{lineStart:function(){u=l=!1,h=1},point:function(c,f){var g,d=[c,f],p=o(c,f),y=i?p?0:a(c,f):p?a(c+(c<0?$e:-$e),f):0;if(!e&&(u=l=p)&&t.lineStart(),p!==l&&(!(g=s(e,d))||An(e,g)||An(d,g))&&(d[0]+=Je,d[1]+=Je,p=o(d[0],d[1])),p!==l)h=0,p?(t.lineStart(),g=s(d,e),t.point(g[0],g[1])):(g=s(e,d),t.point(g[0],g[1]),t.lineEnd()),e=g;else if(r&&e&&i^p){var m;y&n||!(m=s(d,e,!0))||(h=0,i?(t.lineStart(),t.point(m[0][0],m[0][1]),t.point(m[1][0],m[1][1]),t.lineEnd()):(t.point(m[1][0],m[1][1]),t.lineEnd(),t.lineStart(),t.point(m[0][0],m[0][1])))}!p||e&&An(e,d)||t.point(d[0],d[1]),e=d,l=p,n=y},lineEnd:function(){l&&t.lineEnd(),e=null},clean:function(){return h|(u&&l)<<1}}},function(n,i,r,o){!function(t,e,n,i,r,o){if(n){var s=ln(e),a=un(e),l=i*n;null==r?(r=e+i*en,o=e-l/2):(r=Dn(s,r),o=Dn(s,o),(i>0?r<o:r>o)&&(r+=i*en));for(var u,h=r;i>0?h>o:h<o;h-=l)u=xn([s,-a*ln(h),-a*un(h)]),t.point(u[0],u[1])}}(o,t,e,r,n,i)},i?[0,-t]:[-$e,t-$e])}function ni(t){return function(e){var n=new ii;for(var i in t)n[i]=t[i];return n.stream=e,n}}function ii(){}function ri(t,e,n){var i=e[1][0]-e[0][0],r=e[1][1]-e[0][1],o=t.clipExtent&&t.clipExtent();t.scale(150).translate([0,0]),null!=o&&t.clipExtent(null),function(t,e){t&&mn.hasOwnProperty(t.type)?mn[t.type](t,e):dn(t,e)}(n,t.stream(Zn));var s=Zn.result(),a=Math.min(i/(s[1][0]-s[0][0]),r/(s[1][1]-s[0][1])),l=+e[0][0]+(i-a*(s[1][0]+s[0][0]))/2,u=+e[0][1]+(r-a*(s[1][1]+s[0][1]))/2;return null!=o&&t.clipExtent(o),t.scale(150*a).translate([l,u])}ii.prototype={constructor:ii,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var oi=ln(30*rn);function si(t,e){return+e?function(t,e){function n(i,r,o,s,a,l,u,h,c,f,g,d,p,y){var m=u-i,v=h-r,_=m*m+v*v;if(_>4*e&&p--){var k=s+f,x=a+g,E=l+d,w=hn(k*k+x*x+E*E),M=fn(E/=w),P=on(on(E)-1)<Je||on(o-c)<Je?(o+c)/2:an(x,k),b=t(P,M),I=b[0],S=b[1],L=I-i,C=S-r,N=v*L-m*C;(N*N/_>e||on((m*L+v*C)/_-.5)>.3||s*f+a*g+l*d<oi)&&(n(i,r,o,s,a,l,I,S,P,k/=w,x/=w,E,p,y),y.point(I,S),n(I,S,P,k,x,E,u,h,c,f,g,d,p,y))}}return function(e){var i,r,o,s,a,l,u,h,c,f,g,d,p={point:y,lineStart:m,lineEnd:_,polygonStart:function(){e.polygonStart(),p.lineStart=k},polygonEnd:function(){e.polygonEnd(),p.lineStart=m}};function y(n,i){n=t(n,i),e.point(n[0],n[1])}function m(){h=NaN,p.point=v,e.lineStart()}function v(i,r){var o=En([i,r]),s=t(i,r);n(h,c,u,f,g,d,h=s[0],c=s[1],u=i,f=o[0],g=o[1],d=o[2],16,e),e.point(h,c)}function _(){p.point=y,e.lineEnd()}function k(){m(),p.point=x,p.lineEnd=E}function x(t,e){v(i=t,e),r=h,o=c,s=f,a=g,l=d,p.point=v}function E(){n(h,c,u,f,g,d,r,o,i,s,a,l,16,e),p.lineEnd=_,_()}return p}}(t,e):function(t){return ni({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}(t)}var ai=ni({point:function(t,e){this.stream.point(t*rn,e*rn)}});function li(t){return function(t){var e,n,i,r,o,s,a,l,u,h,c=150,f=480,g=250,d=0,p=0,y=0,m=0,v=0,_=null,k=ti,x=null,E=qn,w=.5,M=si(I,w);function P(t){return[(t=o(t[0]*rn,t[1]*rn))[0]*c+n,i-t[1]*c]}function b(t){return(t=o.invert((t[0]-n)/c,(i-t[1])/c))&&[t[0]*nn,t[1]*nn]}function I(t,r){return[(t=e(t,r))[0]*c+n,i-t[1]*c]}function S(){o=Sn(r=function(t,e,n){return(t%=en)?e||n?Sn(Nn(t),Tn(e,n)):Nn(t):e||n?Tn(e,n):Ln}(y,m,v),e);var t=e(d,p);return n=f-t[0]*c,i=g+t[1]*c,L()}function L(){return u=h=null,P}return P.stream=function(t){return u&&h===t?u:u=ai(k(r,M(E(h=t))))},P.clipAngle=function(t){return arguments.length?(k=+t?ei(_=t*rn,6*rn):(_=null,ti),L()):_*nn},P.clipExtent=function(t){return arguments.length?(E=null==t?(x=s=a=l=null,qn):Un(x=+t[0][0],s=+t[0][1],a=+t[1][0],l=+t[1][1]),L()):null==x?null:[[x,s],[a,l]]},P.scale=function(t){return arguments.length?(c=+t,S()):c},P.translate=function(t){return arguments.length?(f=+t[0],g=+t[1],S()):[f,g]},P.center=function(t){return arguments.length?(d=t[0]%360*rn,p=t[1]%360*rn,S()):[d*nn,p*nn]},P.rotate=function(t){return arguments.length?(y=t[0]%360*rn,m=t[1]%360*rn,v=t.length>2?t[2]%360*rn:0,S()):[y*nn,m*nn,v*nn]},P.precision=function(t){return arguments.length?(M=si(I,w=t*t),L()):hn(w)},P.fitExtent=function(t,e){return ri(P,t,e)},P.fitSize=function(t,e){return function(t,e,n){return ri(t,[[0,0],e],n)}(P,t,e)},function(){return e=t.apply(this,arguments),P.invert=e.invert&&b,S()}}(function(){return t})()}function ui(t){return function(e,n){var i=ln(e),r=ln(n),o=t(i*r);return[o*r*un(e),o*un(n)]}}function hi(t){return function(e,n){var i=hn(e*e+n*n),r=t(i),o=un(r),s=ln(r);return[an(e*o,i*s),fn(i&&n*o/i)]}}ui(function(t){return hn(2/(1+t))}).invert=hi(function(t){return 2*fn(t/2)});var ci=ui(function(t){return(t=cn(t))&&t/un(t)});function fi(t,e){return[t,e]}ci.invert=hi(function(t){return t}),fi.invert=fi;var{BufferOp:gi,GeoJSONReader:di,GeoJSONWriter:pi}=Ve;function yi(t,e,n,i){var r=t.properties||{},o="Feature"===t.type?t.geometry:t;if("GeometryCollection"===o.type){var s=[];return H(t,function(t){var r=yi(t,e,n,i);r&&s.push(r)}),O(s)}var a=function(t){var e=function(t,e={}){const n=Ye(t);return N([(n[0]+n[2])/2,(n[1]+n[3])/2],e.properties,e)}(t).geometry.coordinates,n=[-e[0],-e[1]];return li(ci).scale(79.4188).clipAngle(179.999).rotate(n).scale(S)}(o),l={type:o.type,coordinates:vi(o.coordinates,a)},u=(new di).read(l),h=R(function(t,e="kilometers"){const n=L[e];if(!n)throw new Error(e+" units is invalid");return t/n}(e,n),"meters"),c=gi.bufferOp(u,h,i);if(!mi((c=(new pi).write(c)).coordinates))return C({type:c.type,coordinates:_i(c.coordinates,a)},r)}function mi(t){return Array.isArray(t[0])?mi(t[0]):isNaN(t[0])}function vi(t,e){return"object"!=typeof t[0]?e(t):t.map(function(t){return vi(t,e)})}function _i(t,e){return"object"!=typeof t[0]?e.invert(t):t.map(function(t){return _i(t,e)})}var ki=function(t,e,n){var i=(n=n||{}).units||"kilometers",r=n.steps||8;if(!t)throw new Error("geojson is required");if("object"!=typeof n)throw new Error("options must be an object");if("number"!=typeof r)throw new Error("steps must be an number");if(void 0===e)throw new Error("radius is required");if(r<=0)throw new Error("steps must be greater than 0");var o=[];switch(t.type){case"GeometryCollection":return H(t,function(t){var n=yi(t,e,i,r);n&&o.push(n)}),O(o);case"FeatureCollection":return z(t,function(t){var n=yi(t,e,i,r);n&&z(n,function(t){t&&o.push(t)})}),O(o)}return yi(t,e,i,r)};function xi(t,e={}){var n="object"==typeof e?e.mutate:e;if(!t)throw new Error("geojson is required");var i=wt(t),r=[];switch(i){case"LineString":r=Ei(t,i);break;case"MultiLineString":case"Polygon":xt(t).forEach(function(t){r.push(Ei(t,i))});break;case"MultiPolygon":xt(t).forEach(function(t){var e=[];t.forEach(function(t){e.push(Ei(t,i))}),r.push(e)});break;case"Point":return t;case"MultiPoint":var o={};xt(t).forEach(function(t){var e=t.join("-");Object.prototype.hasOwnProperty.call(o,e)||(r.push(t),o[e]=!0)});break;default:throw new Error(i+" geometry not supported")}return t.coordinates?!0===n?(t.coordinates=r,t):{type:i,coordinates:r}:!0===n?(t.geometry.coordinates=r,t):C({type:i,coordinates:r},t.properties,{bbox:t.bbox,id:t.id})}function Ei(t,e){var n=xt(t);if(2===n.length&&!wi(n[0],n[1]))return n;var i=[],r=n.length-1,o=i.length;i.push(n[0]);for(var s=1;s<r;s++){var a=i[i.length-1];n[s][0]===a[0]&&n[s][1]===a[1]||(i.push(n[s]),(o=i.length)>2&&Mi(i[o-3],i[o-1],i[o-2])&&i.splice(i.length-2,1))}if(i.push(n[n.length-1]),o=i.length,("Polygon"===e||"MultiPolygon"===e)&&wi(n[0],n[n.length-1])&&o<4)throw new Error("invalid polygon");return"LineString"===e&&o<3||Mi(i[o-3],i[o-1],i[o-2])&&i.splice(i.length-2,1),i}function wi(t,e){return t[0]===e[0]&&t[1]===e[1]}function Mi(t,e,n){var i=n[0],r=n[1],o=t[0],s=t[1],a=e[0],l=e[1],u=a-o,h=l-s;return 0===(i-o)*h-(r-s)*u&&(Math.abs(u)>=Math.abs(h)?u>0?o<=i&&i<=a:a<=i&&i<=o:h>0?s<=r&&r<=l:l<=r&&r<=s)}function Pi(t){if(!t)throw new Error("geojson is required");switch(t.type){case"Feature":return bi(t);case"FeatureCollection":return function(t){const e={type:"FeatureCollection"};return Object.keys(t).forEach(n=>{switch(n){case"type":case"features":return;default:e[n]=t[n]}}),e.features=t.features.map(t=>bi(t)),e}(t);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Si(t);default:throw new Error("unknown GeoJSON type")}}function bi(t){const e={type:"Feature"};return Object.keys(t).forEach(n=>{switch(n){case"type":case"properties":case"geometry":return;default:e[n]=t[n]}}),e.properties=Ii(t.properties),null==t.geometry?e.geometry=null:e.geometry=Si(t.geometry),e}function Ii(t){const e={};return t?(Object.keys(t).forEach(n=>{const i=t[n];"object"==typeof i?null===i?e[n]=null:Array.isArray(i)?e[n]=i.map(t=>t):e[n]=Ii(i):e[n]=i}),e):e}function Si(t){const e={type:t.type};return t.bbox&&(e.bbox=t.bbox),"GeometryCollection"===t.type?(e.geometries=t.geometries.map(t=>Si(t)),e):(e.coordinates=Li(t.coordinates),e)}function Li(t){const e=t;return"object"!=typeof e[0]?e.slice():e.map(t=>Li(t))}function Ci(t,e){var n=t[0]-e[0],i=t[1]-e[1];return n*n+i*i}function Ni(t,e,n){var i=e[0],r=e[1],o=n[0]-i,s=n[1]-r;if(0!==o||0!==s){var a=((t[0]-i)*o+(t[1]-r)*s)/(o*o+s*s);a>1?(i=n[0],r=n[1]):a>0&&(i+=o*a,r+=s*a)}return(o=t[0]-i)*o+(s=t[1]-r)*s}function Ti(t,e,n,i,r){for(var o,s=i,a=e+1;a<n;a++){var l=Ni(t[a],t[e],t[n]);l>s&&(o=a,s=l)}s>i&&(o-e>1&&Ti(t,e,o,i,r),r.push(t[o]),n-o>1&&Ti(t,o,n,i,r))}function Di(t,e){var n=t.length-1,i=[t[0]];return Ti(t,0,n,e,i),i.push(t[n]),i}function Oi(t,e,n){if(t.length<=2)return t;var i=void 0!==e?e*e:1;return t=n?t:function(t,e){for(var n,i=t[0],r=[i],o=1,s=t.length;o<s;o++)Ci(n=t[o],i)>e&&(r.push(n),i=n);return i!==n&&r.push(n),r}(t,i),t=Di(t,i)}function Ai(t,e,n){return t.map(function(t){if(t.length<4)throw new Error("invalid polygon");let i=e,r=Oi(t,i,n);for(;!Ri(r);)i-=.01*i,r=Oi(t,i,n);return r[r.length-1][0]===r[0][0]&&r[r.length-1][1]===r[0][1]||r.push(r[0]),r})}function Ri(t){return!(t.length<3)&&!(3===t.length&&t[2][0]===t[0][0]&&t[2][1]===t[0][1])}var Fi=function(t,e={}){var n,i,r,o;if(null===(o=e=null!=e?e:{})||"object"!=typeof o||Array.isArray(o))throw new Error("options is invalid");const s=null!=(n=e.tolerance)?n:1,a=null!=(i=e.highQuality)&&i,l=null!=(r=e.mutate)&&r;if(!t)throw new Error("geojson is required");if(s&&s<0)throw new Error("invalid tolerance");return!0!==l&&(t=Pi(t)),H(t,function(t){!function(t,e,n){const i=t.type;if("Point"===i||"MultiPoint"===i)return t;if(xi(t,{mutate:!0}),"GeometryCollection"!==i)switch(i){case"LineString":t.coordinates=Oi(t.coordinates,e,n);break;case"MultiLineString":t.coordinates=t.coordinates.map(t=>Oi(t,e,n));break;case"Polygon":t.coordinates=Ai(t.coordinates,e,n);break;case"MultiPolygon":t.coordinates=t.coordinates.map(t=>Ai(t,e,n))}}(t,s,a)}),t};function Bi(t,e,n,i,r,o,s,a){let l,u,h,c,f;const g={x:null,y:null,onLine1:!1,onLine2:!1};return l=(a-o)*(n-t)-(s-r)*(i-e),0===l?null!==g.x&&null!==g.y&&g:(u=e-o,h=t-r,c=(s-r)*u-(a-o)*h,f=(n-t)*u-(i-e)*h,u=c/l,h=f/l,g.x=t+u*(n-t),g.y=e+u*(i-e),u>=0&&u<=1&&(g.onLine1=!0),h>=0&&h<=1&&(g.onLine2=!0),!(!g.onLine1||!g.onLine2)&&[g.x,g.y])}var Gi=function(t){let e,n;const i={type:"FeatureCollection",features:[]};if(n="Feature"===t.type?t.geometry:t,"LineString"===n.type)e=[n.coordinates];else if("MultiLineString"===n.type)e=n.coordinates;else if("MultiPolygon"===n.type)e=[].concat(...n.coordinates);else{if("Polygon"!==n.type)throw new Error("Input must be a LineString, MultiLineString, Polygon, or MultiPolygon Feature or Geometry");e=n.coordinates}return e.forEach(t=>{e.forEach(e=>{for(let n=0;n<t.length-1;n++)for(let r=n;r<e.length-1;r++){if(t===e){if(1===Math.abs(n-r))continue;if(0===n&&r===t.length-2&&t[n][0]===t[t.length-1][0]&&t[n][1]===t[t.length-1][1])continue}const o=Bi(t[n][0],t[n][1],t[n+1][0],t[n+1][1],e[r][0],e[r][1],e[r+1][0],e[r+1][1]);o&&i.features.push(N([o[0],o[1]]))}})}),i};function zi(t,e,n,i,r){Hi(t,e,n||0,i||t.length-1,r||Ui)}function Hi(t,e,n,i,r){for(;i>n;){if(i-n>600){var o=i-n+1,s=e-n+1,a=Math.log(o),l=.5*Math.exp(2*a/3),u=.5*Math.sqrt(a*l*(o-l)/o)*(s-o/2<0?-1:1);Hi(t,e,Math.max(n,Math.floor(e-s*l/o+u)),Math.min(i,Math.floor(e+(o-s)*l/o+u)),r)}var h=t[e],c=n,f=i;for(Yi(t,n,e),r(t[i],h)>0&&Yi(t,n,i);c<f;){for(Yi(t,c,f),c++,f--;r(t[c],h)<0;)c++;for(;r(t[f],h)>0;)f--}0===r(t[n],h)?Yi(t,n,f):Yi(t,++f,i),f<=e&&(n=f+1),e<=f&&(i=f-1)}}function Yi(t,e,n){var i=t[e];t[e]=t[n],t[n]=i}function Ui(t,e){return t<e?-1:t>e?1:0}let Xi=class{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const n=[];if(!nr(t,e))return n;const i=this.toBBox,r=[];for(;e;){for(let o=0;o<e.children.length;o++){const s=e.children[o],a=e.leaf?i(s):s;nr(t,a)&&(e.leaf?n.push(s):er(t,a)?this._all(s,n):r.push(s))}e=r.pop()}return n}collides(t){let e=this.data;if(!nr(t,e))return!1;const n=[];for(;e;){for(let i=0;i<e.children.length;i++){const r=e.children[i],o=e.leaf?this.toBBox(r):r;if(nr(t,o)){if(e.leaf||er(t,o))return!0;n.push(r)}}e=n.pop()}return!1}load(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e;return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=ir([]),this}remove(t,e){if(!t)return this;let n=this.data;const i=this.toBBox(t),r=[],o=[];let s,a,l;for(;n||r.length;){if(n||(n=r.pop(),a=r[r.length-1],s=o.pop(),l=!0),n.leaf){const i=qi(t,n.children,e);if(-1!==i)return n.children.splice(i,1),r.push(n),this._condense(r),this}l||n.leaf||!er(n,i)?a?(s++,n=a.children[s],l=!1):n=null:(r.push(n),o.push(s),s=0,a=n,n=n.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}_build(t,e,n,i){const r=n-e+1;let o,s=this._maxEntries;if(r<=s)return o=ir(t.slice(e,n+1)),Vi(o,this.toBBox),o;i||(i=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,i-1))),o=ir([]),o.leaf=!1,o.height=i;const a=Math.ceil(r/s),l=a*Math.ceil(Math.sqrt(s));rr(t,e,n,l,this.compareMinX);for(let u=e;u<=n;u+=l){const e=Math.min(u+l-1,n);rr(t,u,e,a,this.compareMinY);for(let n=u;n<=e;n+=a){const r=Math.min(n+a-1,e);o.children.push(this._build(t,n,r,i-1))}}return Vi(o,this.toBBox),o}_chooseSubtree(t,e,n,i){for(;i.push(e),!e.leaf&&i.length-1!==n;){let n,i=1/0,r=1/0;for(let o=0;o<e.children.length;o++){const s=e.children[o],a=Ji(s),l=Qi(t,s)-a;l<r?(r=l,i=a<i?a:i,n=s):l===r&&a<i&&(i=a,n=s)}e=n||e.children[0]}return e}_insert(t,e,n){const i=n?t:this.toBBox(t),r=[],o=this._chooseSubtree(i,this.data,e,r);for(o.children.push(t),Ki(o,i);e>=0&&r[e].children.length>this._maxEntries;)this._split(r,e),e--;this._adjustParentBBoxes(i,r,e)}_split(t,e){const n=t[e],i=n.children.length,r=this._minEntries;this._chooseSplitAxis(n,r,i);const o=this._chooseSplitIndex(n,r,i),s=ir(n.children.splice(o,n.children.length-o));s.height=n.height,s.leaf=n.leaf,Vi(n,this.toBBox),Vi(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(n,s)}_splitRoot(t,e){this.data=ir([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Vi(this.data,this.toBBox)}_chooseSplitIndex(t,e,n){let i,r=1/0,o=1/0;for(let s=e;s<=n-e;s++){const e=ji(t,0,s,this.toBBox),a=ji(t,s,n,this.toBBox),l=tr(e,a),u=Ji(e)+Ji(a);l<r?(r=l,i=s,o=u<o?u:o):l===r&&u<o&&(o=u,i=s)}return i||n-e}_chooseSplitAxis(t,e,n){const i=t.leaf?this.compareMinX:Wi,r=t.leaf?this.compareMinY:Zi;this._allDistMargin(t,e,n,i)<this._allDistMargin(t,e,n,r)&&t.children.sort(i)}_allDistMargin(t,e,n,i){t.children.sort(i);const r=this.toBBox,o=ji(t,0,e,r),s=ji(t,n-e,n,r);let a=$i(o)+$i(s);for(let l=e;l<n-e;l++){const e=t.children[l];Ki(o,t.leaf?r(e):e),a+=$i(o)}for(let l=n-e-1;l>=e;l--){const e=t.children[l];Ki(s,t.leaf?r(e):e),a+=$i(s)}return a}_adjustParentBBoxes(t,e,n){for(let i=n;i>=0;i--)Ki(e[i],t)}_condense(t){for(let e,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(e=t[n-1].children,e.splice(e.indexOf(t[n]),1)):this.clear():Vi(t[n],this.toBBox)}};function qi(t,e,n){if(!n)return e.indexOf(t);for(let i=0;i<e.length;i++)if(n(t,e[i]))return i;return-1}function Vi(t,e){ji(t,0,t.children.length,e,t)}function ji(t,e,n,i,r){r||(r=ir(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(let o=e;o<n;o++){const e=t.children[o];Ki(r,t.leaf?i(e):e)}return r}function Ki(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function Wi(t,e){return t.minX-e.minX}function Zi(t,e){return t.minY-e.minY}function Ji(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function $i(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Qi(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function tr(t,e){const n=Math.max(t.minX,e.minX),i=Math.max(t.minY,e.minY),r=Math.min(t.maxX,e.maxX),o=Math.min(t.maxY,e.maxY);return Math.max(0,r-n)*Math.max(0,o-i)}function er(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function nr(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function ir(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function rr(t,e,n,i,r){const o=[e,n];for(;o.length;){if((n=o.pop())-(e=o.pop())<=i)continue;const s=e+Math.ceil((n-e)/i/2)*i;zi(t,s,e,n,r),o.push(e,s,s,n)}}const or=11102230246251565e-32,sr=134217729,ar=(3+8*or)*or;function lr(t,e,n,i,r){let o,s,a,l,u=e[0],h=i[0],c=0,f=0;h>u==h>-u?(o=u,u=e[++c]):(o=h,h=i[++f]);let g=0;if(c<t&&f<n)for(h>u==h>-u?(s=u+o,a=o-(s-u),u=e[++c]):(s=h+o,a=o-(s-h),h=i[++f]),o=s,0!==a&&(r[g++]=a);c<t&&f<n;)h>u==h>-u?(s=o+u,l=s-o,a=o-(s-l)+(u-l),u=e[++c]):(s=o+h,l=s-o,a=o-(s-l)+(h-l),h=i[++f]),o=s,0!==a&&(r[g++]=a);for(;c<t;)s=o+u,l=s-o,a=o-(s-l)+(u-l),u=e[++c],o=s,0!==a&&(r[g++]=a);for(;f<n;)s=o+h,l=s-o,a=o-(s-l)+(h-l),h=i[++f],o=s,0!==a&&(r[g++]=a);return 0===o&&0!==g||(r[g++]=o),g}function ur(t){return new Float64Array(t)}const hr=ur(4),cr=ur(8),fr=ur(12),gr=ur(16),dr=ur(4);function pr(t,e,n,i,r,o){const s=(e-o)*(n-r),a=(t-r)*(i-o),l=s-a,u=Math.abs(s+a);return Math.abs(l)>=33306690738754716e-32*u?l:-function(t,e,n,i,r,o,s){let a,l,u,h,c,f,g,d,p,y,m,v,_,k,x,E,w,M;const P=t-r,b=n-r,I=e-o,S=i-o;k=P*S,f=sr*P,g=f-(f-P),d=P-g,f=sr*S,p=f-(f-S),y=S-p,x=d*y-(k-g*p-d*p-g*y),E=I*b,f=sr*I,g=f-(f-I),d=I-g,f=sr*b,p=f-(f-b),y=b-p,w=d*y-(E-g*p-d*p-g*y),m=x-w,c=x-m,hr[0]=x-(m+c)+(c-w),v=k+m,c=v-k,_=k-(v-c)+(m-c),m=_-E,c=_-m,hr[1]=_-(m+c)+(c-E),M=v+m,c=M-v,hr[2]=v-(M-c)+(m-c),hr[3]=M;let L=function(t,e){let n=e[0];for(let i=1;i<t;i++)n+=e[i];return n}(4,hr),C=22204460492503146e-32*s;if(L>=C||-L>=C)return L;if(c=t-P,a=t-(P+c)+(c-r),c=n-b,u=n-(b+c)+(c-r),c=e-I,l=e-(I+c)+(c-o),c=i-S,h=i-(S+c)+(c-o),0===a&&0===l&&0===u&&0===h)return L;if(C=11093356479670487e-47*s+ar*Math.abs(L),L+=P*h+S*a-(I*u+b*l),L>=C||-L>=C)return L;k=a*S,f=sr*a,g=f-(f-a),d=a-g,f=sr*S,p=f-(f-S),y=S-p,x=d*y-(k-g*p-d*p-g*y),E=l*b,f=sr*l,g=f-(f-l),d=l-g,f=sr*b,p=f-(f-b),y=b-p,w=d*y-(E-g*p-d*p-g*y),m=x-w,c=x-m,dr[0]=x-(m+c)+(c-w),v=k+m,c=v-k,_=k-(v-c)+(m-c),m=_-E,c=_-m,dr[1]=_-(m+c)+(c-E),M=v+m,c=M-v,dr[2]=v-(M-c)+(m-c),dr[3]=M;const N=lr(4,hr,4,dr,cr);k=P*h,f=sr*P,g=f-(f-P),d=P-g,f=sr*h,p=f-(f-h),y=h-p,x=d*y-(k-g*p-d*p-g*y),E=I*u,f=sr*I,g=f-(f-I),d=I-g,f=sr*u,p=f-(f-u),y=u-p,w=d*y-(E-g*p-d*p-g*y),m=x-w,c=x-m,dr[0]=x-(m+c)+(c-w),v=k+m,c=v-k,_=k-(v-c)+(m-c),m=_-E,c=_-m,dr[1]=_-(m+c)+(c-E),M=v+m,c=M-v,dr[2]=v-(M-c)+(m-c),dr[3]=M;const T=lr(N,cr,4,dr,fr);k=a*h,f=sr*a,g=f-(f-a),d=a-g,f=sr*h,p=f-(f-h),y=h-p,x=d*y-(k-g*p-d*p-g*y),E=l*u,f=sr*l,g=f-(f-l),d=l-g,f=sr*u,p=f-(f-u),y=u-p,w=d*y-(E-g*p-d*p-g*y),m=x-w,c=x-m,dr[0]=x-(m+c)+(c-w),v=k+m,c=v-k,_=k-(v-c)+(m-c),m=_-E,c=_-m,dr[1]=_-(m+c)+(c-E),M=v+m,c=M-v,dr[2]=v-(M-c)+(m-c),dr[3]=M;const D=lr(T,fr,4,dr,gr);return gr[D-1]}(t,e,n,i,r,o,u)}function yr(t,e){var n,i,r,o,s,a,l,u,h,c=0,f=t[0],g=t[1],d=e.length;for(n=0;n<d;n++){i=0;var p=e[n],y=p.length-1;if((u=p[0])[0]!==p[y][0]&&u[1]!==p[y][1])throw new Error("First and last coordinates in a ring must be the same");for(o=u[0]-f,s=u[1]-g;i<y;i++){if(a=(h=p[i+1])[0]-f,l=h[1]-g,0===s&&0===l){if(a<=0&&o>=0||o<=0&&a>=0)return 0}else if(l>=0&&s<=0||l<=0&&s>=0){if(0===(r=pr(o,a,s,l,0,0)))return 0;(r>0&&l>0&&s<=0||r<0&&l<=0&&s>0)&&c++}u=h,s=l,o=a}}return c%2!=0}function mr(t,e,n={}){if(!t)throw new Error("point is required");if(!e)throw new Error("polygon is required");const i=kt(t),r=Et(e),o=r.type,s=e.bbox;let a=r.coordinates;if(s&&!1===function(t,e){return e[0]<=t[0]&&e[1]<=t[1]&&e[2]>=t[0]&&e[3]>=t[1]}(i,s))return!1;"Polygon"===o&&(a=[a]);let l=!1;for(var u=0;u<a.length;++u){const t=yr(i,a[u]);if(0===t)return!n.ignoreBoundary;t&&(l=!0)}return l}var vr=mr;function _r(t,e,n){if("Polygon"!==t.geometry.type)throw new Error("The input feature must be a Polygon");void 0===n&&(n=1);var i=t.geometry.coordinates,r=[],o={};if(n){for(var s=[],a=0;a<i.length;a++)for(var l=0;l<i[a].length-1;l++)s.push(p(a,l));var u=new Xi;u.load(s)}for(var h=0;h<i.length;h++)for(var c=0;c<i[h].length-1;c++){if(n)u.search(p(h,c)).forEach(function(t){var e=t.ring,n=t.edge;d(h,c,e,n)});else for(var f=0;f<i.length;f++)for(var g=0;g<i[f].length-1;g++)d(h,c,f,g)}return e||(r={type:"Feature",geometry:{type:"MultiPoint",coordinates:r}}),r;function d(t,n,s,a){var l,u,h=i[t][n],c=i[t][n+1],f=i[s][a],g=i[s][a+1],d=function(t,e,n,i){if(kr(t,n)||kr(t,i)||kr(e,n)||kr(i,n))return null;var r=t[0],o=t[1],s=e[0],a=e[1],l=n[0],u=n[1],h=i[0],c=i[1],f=(r-s)*(u-c)-(o-a)*(l-h);return 0===f?null:[((r*a-o*s)*(l-h)-(r-s)*(l*c-u*h))/f,((r*a-o*s)*(u-c)-(o-a)*(l*c-u*h))/f]}(h,c,f,g);if(null!==d&&(l=c[0]!==h[0]?(d[0]-h[0])/(c[0]-h[0]):(d[1]-h[1])/(c[1]-h[1]),u=g[0]!==f[0]?(d[0]-f[0])/(g[0]-f[0]):(d[1]-f[1])/(g[1]-f[1]),!(l>=1||l<=0||u>=1||u<=0))){var p=d,y=!o[p];y&&(o[p]=!0),e?r.push(e(d,t,n,h,c,l,s,a,f,g,u,y)):r.push(d)}}function p(t,e){var n,r,o,s,a=i[t][e],l=i[t][e+1];return a[0]<l[0]?(n=a[0],r=l[0]):(n=l[0],r=a[0]),a[1]<l[1]?(o=a[1],s=l[1]):(o=l[1],s=a[1]),{minX:n,minY:o,maxX:r,maxY:s,ring:t,edge:e}}}function kr(t,e){if(!t||!e)return!1;if(t.length!==e.length)return!1;for(var n=0,i=t.length;n<i;n++)if(t[n]instanceof Array&&e[n]instanceof Array){if(!kr(t[n],e[n]))return!1}else if(t[n]!==e[n])return!1;return!0}function xr(t){if("Feature"!=t.type)throw new Error("The input must a geojson object of type Feature");if(void 0===t.geometry||null==t.geometry)throw new Error("The input must a geojson object with a non-empty geometry");if("Polygon"!=t.geometry.type)throw new Error("The input must be a geojson Polygon");for(var e=t.geometry.coordinates.length,n=[],i=0;i<e;i++){var r=t.geometry.coordinates[i];br(r[0],r[r.length-1])||r.push(r[0]);for(var o=0;o<r.length-1;o++)n.push(r[o])}if(!function(t){for(var e={},n=1,i=0,r=t.length;i<r;++i){if(Object.prototype.hasOwnProperty.call(e,t[i])){n=0;break}e[t[i]]=1}return n}(n))throw new Error("The input polygon may not have duplicate vertices (except for the first and last vertex of each ring)");var s=n.length,a=_r(t,function(t,e,n,i,r,o,s,a,l,u,h,c){return[t,e,n,i,r,o,s,a,l,u,h,c]}),l=a.length;if(0==l){var u=[];for(i=0;i<e;i++)u.push(T([t.geometry.coordinates[i]],{parent:-1,winding:Pr(t.geometry.coordinates[i])}));var h=O(u);return B(),G(),h}var c=[],f=[];for(i=0;i<e;i++){c.push([]);for(o=0;o<t.geometry.coordinates[i].length-1;o++)c[i].push([new Er(t.geometry.coordinates[i][Ir(o+1,t.geometry.coordinates[i].length-1)],1,[i,o],[i,Ir(o+1,t.geometry.coordinates[i].length-1)],void 0)]),f.push(new wr(t.geometry.coordinates[i][o],[i,Ir(o-1,t.geometry.coordinates[i].length-1)],[i,o],void 0,void 0,!1,!0))}for(i=0;i<l;i++)c[a[i][1]][a[i][2]].push(new Er(a[i][0],a[i][5],[a[i][1],a[i][2]],[a[i][6],a[i][7]],void 0)),a[i][11]&&f.push(new wr(a[i][0],[a[i][1],a[i][2]],[a[i][6],a[i][7]],void 0,void 0,!0,!0));var g=f.length;for(i=0;i<c.length;i++)for(o=0;o<c[i].length;o++)c[i][o].sort(function(t,e){return t.param<e.param?-1:1});var d=[];for(i=0;i<g;i++)d.push({minX:f[i].coord[0],minY:f[i].coord[1],maxX:f[i].coord[0],maxY:f[i].coord[1],index:i});var p=new Xi;p.load(d);for(i=0;i<c.length;i++)for(o=0;o<c[i].length;o++)for(var y=0;y<c[i][o].length;y++){v=y==c[i][o].length-1?c[i][Ir(o+1,t.geometry.coordinates[i].length-1)][0].coord:c[i][o][y+1].coord;var m=p.search({minX:v[0],minY:v[1],maxX:v[0],maxY:v[1]})[0];c[i][o][y].nxtIsectAlongEdgeIn=m.index}for(i=0;i<c.length;i++)for(o=0;o<c[i].length;o++)for(y=0;y<c[i][o].length;y++){var v=c[i][o][y].coord,_=(m=p.search({minX:v[0],minY:v[1],maxX:v[0],maxY:v[1]})[0]).index;_<s?f[_].nxtIsectAlongRingAndEdge2=c[i][o][y].nxtIsectAlongEdgeIn:br(f[_].ringAndEdge1,c[i][o][y].ringAndEdgeIn)?f[_].nxtIsectAlongRingAndEdge1=c[i][o][y].nxtIsectAlongEdgeIn:f[_].nxtIsectAlongRingAndEdge2=c[i][o][y].nxtIsectAlongEdgeIn}var k=[];for(i=0,o=0;o<e;o++){var x=i;for(y=0;y<t.geometry.coordinates[o].length-1;y++)f[i].coord[0]<f[x].coord[0]&&(x=i),i++;var E=f[x].nxtIsectAlongRingAndEdge2;for(y=0;y<f.length;y++)if(f[y].nxtIsectAlongRingAndEdge1==x||f[y].nxtIsectAlongRingAndEdge2==x){var w=y;break}var M=Mr([f[w].coord,f[x].coord,f[E].coord],!0)?1:-1;k.push({isect:x,parent:-1,winding:M})}k.sort(function(t,e){return f[t.isect].coord>f[e.isect].coord?-1:1});for(u=[];k.length>0;){var P=k.pop(),b=P.isect,I=P.parent,S=P.winding,L=u.length,C=[f[b].coord],N=b;if(f[b].ringAndEdge1Walkable)var D=f[b].ringAndEdge1,A=f[b].nxtIsectAlongRingAndEdge1;else D=f[b].ringAndEdge2,A=f[b].nxtIsectAlongRingAndEdge2;for(;!br(f[b].coord,f[A].coord);){C.push(f[A].coord);var R=void 0;for(i=0;i<k.length;i++)if(k[i].isect==A){R=i;break}if(null!=R&&k.splice(R,1),br(D,f[A].ringAndEdge1)){if(D=f[A].ringAndEdge2,f[A].ringAndEdge2Walkable=!1,f[A].ringAndEdge1Walkable){var F={isect:A};Mr([f[N].coord,f[A].coord,f[f[A].nxtIsectAlongRingAndEdge2].coord],1==S)?(F.parent=I,F.winding=-S):(F.parent=L,F.winding=S),k.push(F)}N=A,A=f[A].nxtIsectAlongRingAndEdge2}else{if(D=f[A].ringAndEdge1,f[A].ringAndEdge1Walkable=!1,f[A].ringAndEdge2Walkable){F={isect:A};Mr([f[N].coord,f[A].coord,f[f[A].nxtIsectAlongRingAndEdge1].coord],1==S)?(F.parent=I,F.winding=-S):(F.parent=L,F.winding=S),k.push(F)}N=A,A=f[A].nxtIsectAlongRingAndEdge1}}C.push(f[A].coord),u.push(T([C],{index:L,parent:I,winding:S,netWinding:void 0}))}h=O(u);function B(){for(var t=[],e=0;e<h.features.length;e++)-1==h.features[e].properties.parent&&t.push(e);if(t.length>1)for(e=0;e<t.length;e++){for(var n=-1,i=1/0,r=0;r<h.features.length;r++)t[e]!=r&&mr(h.features[t[e]].geometry.coordinates[0][0],h.features[r],{ignoreBoundary:!0})&&X(h.features[r])<i&&(n=r);h.features[t[e]].properties.parent=n}}function G(){for(var t=0;t<h.features.length;t++)if(-1==h.features[t].properties.parent){var e=h.features[t].properties.winding;h.features[t].properties.netWinding=e,z(t,e)}}function z(t,e){for(var n=0;n<h.features.length;n++)if(h.features[n].properties.parent==t){var i=e+h.features[n].properties.winding;h.features[n].properties.netWinding=i,z(n,i)}}return B(),G(),h}var Er=function(t,e,n,i,r){this.coord=t,this.param=e,this.ringAndEdgeIn=n,this.ringAndEdgeOut=i,this.nxtIsectAlongEdgeIn=r},wr=function(t,e,n,i,r,o,s){this.coord=t,this.ringAndEdge1=e,this.ringAndEdge2=n,this.nxtIsectAlongRingAndEdge1=i,this.nxtIsectAlongRingAndEdge2=r,this.ringAndEdge1Walkable=o,this.ringAndEdge2Walkable=s};function Mr(t,e){if(void 0===e&&(e=!0),3!=t.length)throw new Error("This function requires an array of three points [x,y]");return(t[1][0]-t[0][0])*(t[2][1]-t[0][1])-(t[1][1]-t[0][1])*(t[2][0]-t[0][0])>=0==e}function Pr(t){for(var e=0,n=0;n<t.length-1;n++)t[n][0]<t[e][0]&&(e=n);if(Mr([t[Ir(e-1,t.length-1)],t[e],t[Ir(e+1,t.length-1)]],!0))var i=1;else i=-1;return i}function br(t,e){if(!t||!e)return!1;if(t.length!=e.length)return!1;for(var n=0,i=t.length;n<i;n++)if(t[n]instanceof Array&&e[n]instanceof Array){if(!br(t[n],e[n]))return!1}else if(t[n]!=e[n])return!1;return!0}function Ir(t,e){return(t%e+e)%e}var Sr=function(t){var e=[];return Y(t,function(t){"Polygon"===t.geometry.type&&z(xr(t),function(n){e.push(T(n.geometry.coordinates,t.properties))})}),O(e)};function Lr(t,e,n={}){const i=kt(t),r=xt(e);for(let o=0;o<r.length-1;o++){let t=!1;if(n.ignoreEndVertices&&(0===o&&(t="start"),o===r.length-2&&(t="end"),0===o&&o+1===r.length-1&&(t="both")),Cr(r[o],r[o+1],i,t,void 0===n.epsilon?null:n.epsilon))return!0}return!1}function Cr(t,e,n,i,r){const o=n[0],s=n[1],a=t[0],l=t[1],u=e[0],h=e[1],c=u-a,f=h-l,g=(n[0]-a)*f-(n[1]-l)*c;if(null!==r){if(Math.abs(g)>r)return!1}else if(0!==g)return!1;return Math.abs(c)===Math.abs(f)&&0===Math.abs(c)?!i&&(n[0]===t[0]&&n[1]===t[1]):i?"start"===i?Math.abs(c)>=Math.abs(f)?c>0?a<o&&o<=u:u<=o&&o<a:f>0?l<s&&s<=h:h<=s&&s<l:"end"===i?Math.abs(c)>=Math.abs(f)?c>0?a<=o&&o<u:u<o&&o<=a:f>0?l<=s&&s<h:h<s&&s<=l:"both"===i&&(Math.abs(c)>=Math.abs(f)?c>0?a<o&&o<u:u<o&&o<a:f>0?l<s&&s<h:h<s&&s<l):Math.abs(c)>=Math.abs(f)?c>0?a<=o&&o<=u:u<=o&&o<=a:f>0?l<=s&&s<=h:h<=s&&s<=l}function Nr(t,e){return!(t[0]>e[0])&&(!(t[2]<e[2])&&(!(t[1]>e[1])&&!(t[3]<e[3])))}function Tr(t,e){return t[0]===e[0]&&t[1]===e[1]}function Dr(t,e){return[(t[0]+e[0])/2,(t[1]+e[1])/2]}var Or=function(t,e){var n=Et(t),i=Et(e),r=n.type,o=i.type;switch(r){case"Point":switch(o){case"MultiPoint":return function(t,e){var n,i=!1;for(n=0;n<e.coordinates.length;n++)if(Tr(e.coordinates[n],t.coordinates)){i=!0;break}return i}(n,i);case"LineString":return Lr(n,i,{ignoreEndVertices:!0});case"Polygon":case"MultiPolygon":return mr(n,i,{ignoreBoundary:!0});default:throw new Error("feature2 "+o+" geometry not supported")}case"MultiPoint":switch(o){case"MultiPoint":return function(t,e){for(var n=0;n<t.coordinates.length;n++){for(var i=!1,r=0;r<e.coordinates.length;r++)Tr(t.coordinates[n],e.coordinates[r])&&(i=!0);if(!i)return!1}return!0}(n,i);case"LineString":return function(t,e){for(var n=!1,i=0;i<t.coordinates.length;i++){if(!Lr(t.coordinates[i],e))return!1;n||(n=Lr(t.coordinates[i],e,{ignoreEndVertices:!0}))}return n}(n,i);case"Polygon":case"MultiPolygon":return function(t,e){for(var n=!0,i=!1,r=0;r<t.coordinates.length;r++){if(!(i=mr(t.coordinates[r],e))){n=!1;break}i=mr(t.coordinates[r],e,{ignoreBoundary:!0})}return n&&i}(n,i);default:throw new Error("feature2 "+o+" geometry not supported")}case"LineString":switch(o){case"LineString":return function(t,e){for(var n=0;n<t.coordinates.length;n++)if(!Lr(t.coordinates[n],e))return!1;return!0}(n,i);case"Polygon":case"MultiPolygon":return function(t,e){var n=Ye(e),i=Ye(t);if(!Nr(n,i))return!1;for(var r=!1,o=0;o<t.coordinates.length;o++){if(!mr(t.coordinates[o],e))return!1;if(r||(r=mr(t.coordinates[o],e,{ignoreBoundary:!0})),!r&&o<t.coordinates.length-1)r=mr(Dr(t.coordinates[o],t.coordinates[o+1]),e,{ignoreBoundary:!0})}return r}(n,i);default:throw new Error("feature2 "+o+" geometry not supported")}case"Polygon":switch(o){case"Polygon":case"MultiPolygon":return function(t,e){var n=Ye(t);if(!Nr(Ye(e),n))return!1;for(var i=0;i<t.coordinates[0].length;i++)if(!mr(t.coordinates[0][i],e))return!1;return!0}(n,i);default:throw new Error("feature2 "+o+" geometry not supported")}default:throw new Error("feature1 "+r+" geometry not supported")}},Ar=Object.defineProperty,Rr=(t,e)=>Ar(t,"name",{value:e,configurable:!0}),Fr=class{constructor(t){var e,n,i;this.direction=!1,this.compareProperties=!0,this.precision=10**-(null!=(e=null==t?void 0:t.precision)?e:17),this.direction=null!=(n=null==t?void 0:t.direction)&&n,this.compareProperties=null==(i=null==t?void 0:t.compareProperties)||i}compare(t,e){if(t.type!==e.type)return!1;if(!Gr(t,e))return!1;switch(t.type){case"Point":return this.compareCoord(t.coordinates,e.coordinates);case"LineString":return this.compareLine(t.coordinates,e.coordinates);case"Polygon":return this.comparePolygon(t,e);case"GeometryCollection":return this.compareGeometryCollection(t,e);case"Feature":return this.compareFeature(t,e);case"FeatureCollection":return this.compareFeatureCollection(t,e);default:if(t.type.startsWith("Multi")){const n=zr(t),i=zr(e);return n.every(t=>i.some(e=>this.compare(t,e)))}}return!1}compareCoord(t,e){return t.length===e.length&&t.every((t,n)=>Math.abs(t-e[n])<this.precision)}compareLine(t,e,n=0,i=!1){if(!Gr(t,e))return!1;const r=t;let o=e;if(i&&!this.compareCoord(r[0],o[0])){const t=this.fixStartIndex(o,r);if(!t)return!1;o=t}const s=this.compareCoord(r[n],o[n]);return this.direction||s?this.comparePath(r,o):!!this.compareCoord(r[n],o[o.length-(1+n)])&&this.comparePath(r.slice().reverse(),o)}fixStartIndex(t,e){let n,i=-1;for(let r=0;r<t.length;r++)if(this.compareCoord(t[r],e[0])){i=r;break}return i>=0&&(n=[].concat(t.slice(i,t.length),t.slice(1,i+1))),n}comparePath(t,e){return t.every((t,n)=>this.compareCoord(t,e[n]))}comparePolygon(t,e){if(this.compareLine(t.coordinates[0],e.coordinates[0],1,!0)){const n=t.coordinates.slice(1,t.coordinates.length),i=e.coordinates.slice(1,e.coordinates.length);return n.every(t=>i.some(e=>this.compareLine(t,e,1,!0)))}return!1}compareGeometryCollection(t,e){return Gr(t.geometries,e.geometries)&&this.compareBBox(t,e)&&t.geometries.every((t,n)=>this.compare(t,e.geometries[n]))}compareFeature(t,e){return t.id===e.id&&(!this.compareProperties||Yr(t.properties,e.properties))&&this.compareBBox(t,e)&&this.compare(t.geometry,e.geometry)}compareFeatureCollection(t,e){return Gr(t.features,e.features)&&this.compareBBox(t,e)&&t.features.every((t,n)=>this.compare(t,e.features[n]))}compareBBox(t,e){return Boolean(!t.bbox&&!e.bbox)||!(!t.bbox||!e.bbox)&&this.compareCoord(t.bbox,e.bbox)}};Rr(Fr,"GeojsonEquality");var Br=Fr;function Gr(t,e){return t.coordinates?t.coordinates.length===e.coordinates.length:t.length===e.length}function zr(t){return t.coordinates.map(e=>({type:t.type.replace("Multi",""),coordinates:e}))}function Hr(t,e,n){return new Br(n).compare(t,e)}function Yr(t,e){if(null===t&&null===e)return!0;if(null===t||null===e)return!1;const n=Object.keys(t),i=Object.keys(e);if(n.length!==i.length)return!1;for(var r of n){const n=t[r],i=e[r],o=Ur(n)&&Ur(i);if(o&&!Yr(n,i)||!o&&n!==i)return!1}return!0}Rr(Gr,"sameLength"),Rr(zr,"explode"),Rr(Hr,"geojsonEquality"),Rr(Yr,"equal");var Ur=Rr(t=>null!=t&&"object"==typeof t,"isObject");var Xr=function(t,e,n={}){let i=n.precision;if(i=null==i||isNaN(i)?6:i,"number"!=typeof i||!(i>=0))throw new Error("precision must be a positive number");return Et(t).type===Et(e).type&&Hr(xi(t),xi(e),{precision:i})};function qr(t,e,n={}){var i=kt(t),r=kt(e),o=F(r[1]-i[1]),s=F(r[0]-i[0]),a=F(i[1]),l=F(r[1]),u=Math.pow(Math.sin(o/2),2)+Math.pow(Math.sin(s/2),2)*Math.cos(a)*Math.cos(l);return R(2*Math.atan2(Math.sqrt(u),Math.sqrt(1-u)),n.units)}var Vr=Object.defineProperty,jr=Object.defineProperties,Kr=Object.getOwnPropertyDescriptors,Wr=Object.getOwnPropertySymbols,Zr=Object.prototype.hasOwnProperty,Jr=Object.prototype.propertyIsEnumerable,$r=(t,e,n)=>e in t?Vr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Qr=(t,e)=>{for(var n in e||(e={}))Zr.call(e,n)&&$r(t,n,e[n]);if(Wr)for(var n of Wr(e))Jr.call(e,n)&&$r(t,n,e[n]);return t},to=(t,e)=>jr(t,Kr(e));var eo=function(t,e,n={}){if(!t)throw new Error("targetPoint is required");if(!e)throw new Error("points is required");let i=1/0,r=0;z(e,(e,o)=>{const s=qr(t,e,n);s<i&&(r=o,i=s)});const o=Pi(e.features[r]);return to(Qr({},o),{properties:to(Qr({},o.properties),{featureIndex:r,distanceToPoint:i})})},no=class{constructor(t){this.points=t.points||[],this.duration=t.duration||1e4,this.sharpness=t.sharpness||.85,this.centers=[],this.controls=[],this.stepLength=t.stepLength||60,this.length=this.points.length,this.delay=0;for(let e=0;e<this.length;e++)this.points[e].z=this.points[e].z||0;for(let e=0;e<this.length-1;e++){const t=this.points[e],n=this.points[e+1];this.centers.push({x:(t.x+n.x)/2,y:(t.y+n.y)/2,z:(t.z+n.z)/2})}this.controls.push([this.points[0],this.points[0]]);for(let e=0;e<this.centers.length-1;e++){const t=this.points[e+1].x-(this.centers[e].x+this.centers[e+1].x)/2,n=this.points[e+1].y-(this.centers[e].y+this.centers[e+1].y)/2,i=this.points[e+1].z-(this.centers[e].y+this.centers[e+1].z)/2;this.controls.push([{x:(1-this.sharpness)*this.points[e+1].x+this.sharpness*(this.centers[e].x+t),y:(1-this.sharpness)*this.points[e+1].y+this.sharpness*(this.centers[e].y+n),z:(1-this.sharpness)*this.points[e+1].z+this.sharpness*(this.centers[e].z+i)},{x:(1-this.sharpness)*this.points[e+1].x+this.sharpness*(this.centers[e+1].x+t),y:(1-this.sharpness)*this.points[e+1].y+this.sharpness*(this.centers[e+1].y+n),z:(1-this.sharpness)*this.points[e+1].z+this.sharpness*(this.centers[e+1].z+i)}])}return this.controls.push([this.points[this.length-1],this.points[this.length-1]]),this.steps=this.cacheSteps(this.stepLength),this}cacheSteps(t){const e=[];let n=this.pos(0);e.push(0);for(let i=0;i<this.duration;i+=10){const r=this.pos(i);Math.sqrt((r.x-n.x)*(r.x-n.x)+(r.y-n.y)*(r.y-n.y)+(r.z-n.z)*(r.z-n.z))>t&&(e.push(i),n=r)}return e}vector(t){const e=this.pos(t+10),n=this.pos(t-10);return{angle:180*Math.atan2(e.y-n.y,e.x-n.x)/3.14,speed:Math.sqrt((n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y)+(n.z-e.z)*(n.z-e.z))}}pos(t){let e=t-this.delay;e<0&&(e=0),e>this.duration&&(e=this.duration-1);const n=e/this.duration;if(n>=1)return this.points[this.length-1];const i=Math.floor((this.points.length-1)*n);return function(t,e,n,i,r){const o=function(t){const e=t*t,n=e*t;return[n,3*e*(1-t),3*t*(1-t)*(1-t),(1-t)*(1-t)*(1-t)]}(t);return{x:r.x*o[0]+i.x*o[1]+n.x*o[2]+e.x*o[3],y:r.y*o[0]+i.y*o[1]+n.y*o[2]+e.y*o[3],z:r.z*o[0]+i.z*o[1]+n.z*o[2]+e.z*o[3]}}((this.length-1)*n-i,this.points[i],this.controls[i][1],this.controls[i+1][0],this.points[i+1])}};var io=function(t,e={}){const n=e.resolution||1e4,i=e.sharpness||.85,r=[],o=Et(t).coordinates.map(t=>({x:t[0],y:t[1]})),s=new no({duration:n,points:o,sharpness:i}),a=t=>{var e=s.pos(t);Math.floor(t/100)%2==0&&r.push([e.x,e.y])};for(var l=0;l<s.duration;l+=10)a(l);return a(s.duration),D(r,e.properties)};var ro=function(t,e={}){return U(t,(t,n)=>{const i=n.geometry.coordinates;return t+qr(i[0],i[1],e)},0)};function oo(t,e,n=0,i=t.length-1,r=ao){for(;i>n;){if(i-n>600){const o=i-n+1,s=e-n+1,a=Math.log(o),l=.5*Math.exp(2*a/3),u=.5*Math.sqrt(a*l*(o-l)/o)*(s-o/2<0?-1:1);oo(t,e,Math.max(n,Math.floor(e-s*l/o+u)),Math.min(i,Math.floor(e+(o-s)*l/o+u)),r)}const o=t[e];let s=n,a=i;for(so(t,n,e),r(t[i],o)>0&&so(t,n,i);s<a;){for(so(t,s,a),s++,a--;r(t[s],o)<0;)s++;for(;r(t[a],o)>0;)a--}0===r(t[n],o)?so(t,n,a):(a++,so(t,a,i)),a<=e&&(n=a+1),e<=a&&(i=a-1)}}function so(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function ao(t,e){return t<e?-1:t>e?1:0}class lo{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const n=[];if(!xo(t,e))return n;const i=this.toBBox,r=[];for(;e;){for(let o=0;o<e.children.length;o++){const s=e.children[o],a=e.leaf?i(s):s;xo(t,a)&&(e.leaf?n.push(s):ko(t,a)?this._all(s,n):r.push(s))}e=r.pop()}return n}collides(t){let e=this.data;if(!xo(t,e))return!1;const n=[];for(;e;){for(let i=0;i<e.children.length;i++){const r=e.children[i],o=e.leaf?this.toBBox(r):r;if(xo(t,o)){if(e.leaf||ko(t,o))return!0;n.push(r)}}e=n.pop()}return!1}load(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e;return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Eo([]),this}remove(t,e){if(!t)return this;let n=this.data;const i=this.toBBox(t),r=[],o=[];let s,a,l;for(;n||r.length;){if(n||(n=r.pop(),a=r[r.length-1],s=o.pop(),l=!0),n.leaf){const i=uo(t,n.children,e);if(-1!==i)return n.children.splice(i,1),r.push(n),this._condense(r),this}l||n.leaf||!ko(n,i)?a?(s++,n=a.children[s],l=!1):n=null:(r.push(n),o.push(s),s=0,a=n,n=n.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}_build(t,e,n,i){const r=n-e+1;let o,s=this._maxEntries;if(r<=s)return o=Eo(t.slice(e,n+1)),ho(o,this.toBBox),o;i||(i=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,i-1))),o=Eo([]),o.leaf=!1,o.height=i;const a=Math.ceil(r/s),l=a*Math.ceil(Math.sqrt(s));wo(t,e,n,l,this.compareMinX);for(let u=e;u<=n;u+=l){const e=Math.min(u+l-1,n);wo(t,u,e,a,this.compareMinY);for(let n=u;n<=e;n+=a){const r=Math.min(n+a-1,e);o.children.push(this._build(t,n,r,i-1))}}return ho(o,this.toBBox),o}_chooseSubtree(t,e,n,i){for(;i.push(e),!e.leaf&&i.length-1!==n;){let n,i=1/0,r=1/0;for(let o=0;o<e.children.length;o++){const s=e.children[o],a=yo(s),l=vo(t,s)-a;l<r?(r=l,i=a<i?a:i,n=s):l===r&&a<i&&(i=a,n=s)}e=n||e.children[0]}return e}_insert(t,e,n){const i=n?t:this.toBBox(t),r=[],o=this._chooseSubtree(i,this.data,e,r);for(o.children.push(t),fo(o,i);e>=0&&r[e].children.length>this._maxEntries;)this._split(r,e),e--;this._adjustParentBBoxes(i,r,e)}_split(t,e){const n=t[e],i=n.children.length,r=this._minEntries;this._chooseSplitAxis(n,r,i);const o=this._chooseSplitIndex(n,r,i),s=Eo(n.children.splice(o,n.children.length-o));s.height=n.height,s.leaf=n.leaf,ho(n,this.toBBox),ho(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(n,s)}_splitRoot(t,e){this.data=Eo([t,e]),this.data.height=t.height+1,this.data.leaf=!1,ho(this.data,this.toBBox)}_chooseSplitIndex(t,e,n){let i,r=1/0,o=1/0;for(let s=e;s<=n-e;s++){const e=co(t,0,s,this.toBBox),a=co(t,s,n,this.toBBox),l=_o(e,a),u=yo(e)+yo(a);l<r?(r=l,i=s,o=u<o?u:o):l===r&&u<o&&(o=u,i=s)}return i||n-e}_chooseSplitAxis(t,e,n){const i=t.leaf?this.compareMinX:go,r=t.leaf?this.compareMinY:po;this._allDistMargin(t,e,n,i)<this._allDistMargin(t,e,n,r)&&t.children.sort(i)}_allDistMargin(t,e,n,i){t.children.sort(i);const r=this.toBBox,o=co(t,0,e,r),s=co(t,n-e,n,r);let a=mo(o)+mo(s);for(let l=e;l<n-e;l++){const e=t.children[l];fo(o,t.leaf?r(e):e),a+=mo(o)}for(let l=n-e-1;l>=e;l--){const e=t.children[l];fo(s,t.leaf?r(e):e),a+=mo(s)}return a}_adjustParentBBoxes(t,e,n){for(let i=n;i>=0;i--)fo(e[i],t)}_condense(t){for(let e,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(e=t[n-1].children,e.splice(e.indexOf(t[n]),1)):this.clear():ho(t[n],this.toBBox)}}function uo(t,e,n){if(!n)return e.indexOf(t);for(let i=0;i<e.length;i++)if(n(t,e[i]))return i;return-1}function ho(t,e){co(t,0,t.children.length,e,t)}function co(t,e,n,i,r){r||(r=Eo(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(let o=e;o<n;o++){const e=t.children[o];fo(r,t.leaf?i(e):e)}return r}function fo(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function go(t,e){return t.minX-e.minX}function po(t,e){return t.minY-e.minY}function yo(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function mo(t){return t.maxX-t.minX+(t.maxY-t.minY)}function vo(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function _o(t,e){const n=Math.max(t.minX,e.minX),i=Math.max(t.minY,e.minY),r=Math.min(t.maxX,e.maxX),o=Math.min(t.maxY,e.maxY);return Math.max(0,r-n)*Math.max(0,o-i)}function ko(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function xo(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Eo(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function wo(t,e,n,i,r){const o=[e,n];for(;o.length;){if((n=o.pop())-(e=o.pop())<=i)continue;const s=e+Math.ceil((n-e)/i/2)*i;oo(t,s,e,n,r),o.push(e,s,s,n)}}class Mo{constructor(t=[],e=(t,e)=>t<e?-1:t>e?1:0){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let n=(this.length>>1)-1;n>=0;n--)this._down(n)}push(t){this.data.push(t),this._up(this.length++)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return--this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:n}=this,i=e[t];for(;t>0;){const r=t-1>>1,o=e[r];if(n(i,o)>=0)break;e[t]=o,t=r}e[t]=i}_down(t){const{data:e,compare:n}=this,i=this.length>>1,r=e[t];for(;t<i;){let i=1+(t<<1);const o=i+1;if(o<this.length&&n(e[o],e[i])<0&&(i=o),n(e[i],r)>=0)break;e[t]=e[i],t=i}e[t]=r}}const Po=Z(ct());function bo(t,e,n){e=Math.max(0,void 0===e?2:e),n=n||0;const i=function(t){let e=t[0],n=t[0],i=t[0],r=t[0];for(let a=0;a<t.length;a++){const o=t[a];o[0]<e[0]&&(e=o),o[0]>i[0]&&(i=o),o[1]<n[1]&&(n=o),o[1]>r[1]&&(r=o)}const o=[e,n,i,r],s=o.slice();for(let a=0;a<t.length;a++)Po(t[a],o)||s.push(t[a]);return function(t){t.sort(Go);const e=[];for(let i=0;i<t.length;i++){for(;e.length>=2&&To(e[e.length-2],e[e.length-1],t[i])<=0;)e.pop();e.push(t[i])}const n=[];for(let i=t.length-1;i>=0;i--){for(;n.length>=2&&To(n[n.length-2],n[n.length-1],t[i])<=0;)n.pop();n.push(t[i])}return n.pop(),e.pop(),e.concat(n)}(s)}(t),r=new lo(16);r.toBBox=function(t){return{minX:t[0],minY:t[1],maxX:t[0],maxY:t[1]}},r.compareMinX=function(t,e){return t[0]-e[0]},r.compareMinY=function(t,e){return t[1]-e[1]},r.load(t);const o=[];let s;for(let f=0;f<i.length;f++){const t=i[f];r.remove(t),s=Ao(t,s),o.push(s)}const a=new lo(16);for(let f=0;f<o.length;f++)a.insert(Oo(o[f]));const l=e*e,u=n*n;for(;o.length;){const t=o.shift(),e=t.p,n=t.next.p,i=Ro(e,n);if(i<u)continue;const s=i/l,h=Io(r,t.prev.p,e,n,t.next.next.p,s,a);h&&Math.min(Ro(h,e),Ro(h,n))<=s&&(o.push(t),o.push(Ao(h,t)),r.remove(h),a.remove(t),a.insert(Oo(t)),a.insert(Oo(t.next)))}let h=s;const c=[];do{c.push(h.p),h=h.next}while(h!==s);return c.push(h.p),c}function Io(t,e,n,i,r,o,s){const a=new Mo([],So);let l=t.data;for(;l;){for(let t=0;t<l.children.length;t++){const e=l.children[t],r=l.leaf?Fo(e,n,i):Lo(n,i,e);r>o||a.push({node:e,dist:r})}for(;a.length&&!a.peek().node.children;){const t=a.pop(),o=t.node,l=Fo(o,e,n),u=Fo(o,i,r);if(t.dist<l&&t.dist<u&&No(n,o,s)&&No(i,o,s))return o}l=a.pop(),l&&(l=l.node)}return null}function So(t,e){return t.dist-e.dist}function Lo(t,e,n){if(Co(t,n)||Co(e,n))return 0;const i=Bo(t[0],t[1],e[0],e[1],n.minX,n.minY,n.maxX,n.minY);if(0===i)return 0;const r=Bo(t[0],t[1],e[0],e[1],n.minX,n.minY,n.minX,n.maxY);if(0===r)return 0;const o=Bo(t[0],t[1],e[0],e[1],n.maxX,n.minY,n.maxX,n.maxY);if(0===o)return 0;const s=Bo(t[0],t[1],e[0],e[1],n.minX,n.maxY,n.maxX,n.maxY);return 0===s?0:Math.min(i,r,o,s)}function Co(t,e){return t[0]>=e.minX&&t[0]<=e.maxX&&t[1]>=e.minY&&t[1]<=e.maxY}function No(t,e,n){const i=Math.min(t[0],e[0]),r=Math.min(t[1],e[1]),o=Math.max(t[0],e[0]),s=Math.max(t[1],e[1]),a=n.search({minX:i,minY:r,maxX:o,maxY:s});for(let l=0;l<a.length;l++)if(Do(a[l].p,a[l].next.p,t,e))return!1;return!0}function To(t,e,n){return pr(t[0],t[1],e[0],e[1],n[0],n[1])}function Do(t,e,n,i){return t!==i&&e!==n&&To(t,e,n)>0!=To(t,e,i)>0&&To(n,i,t)>0!=To(n,i,e)>0}function Oo(t){const e=t.p,n=t.next.p;return t.minX=Math.min(e[0],n[0]),t.minY=Math.min(e[1],n[1]),t.maxX=Math.max(e[0],n[0]),t.maxY=Math.max(e[1],n[1]),t}function Ao(t,e){const n={p:t,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return e?(n.next=e.next,n.prev=e,e.next.prev=n,e.next=n):(n.prev=n,n.next=n),n}function Ro(t,e){const n=t[0]-e[0],i=t[1]-e[1];return n*n+i*i}function Fo(t,e,n){let i=e[0],r=e[1],o=n[0]-i,s=n[1]-r;if(0!==o||0!==s){const e=((t[0]-i)*o+(t[1]-r)*s)/(o*o+s*s);e>1?(i=n[0],r=n[1]):e>0&&(i+=o*e,r+=s*e)}return o=t[0]-i,s=t[1]-r,o*o+s*s}function Bo(t,e,n,i,r,o,s,a){const l=n-t,u=i-e,h=s-r,c=a-o,f=t-r,g=e-o,d=l*l+u*u,p=l*h+u*c,y=h*h+c*c,m=l*f+u*g,v=h*f+c*g,_=d*y-p*p;let k,x,E=_,w=_;0===_?(k=0,E=1,x=v,w=y):(k=p*v-y*m,x=d*v-p*m,k<0?(k=0,x=v,w=y):k>E&&(k=E,x=v+p,w=y)),x<0?(x=0,-m<0?k=0:-m>d?k=E:(k=-m,E=d)):x>w&&(x=w,-m+p<0?k=0:-m+p>d?k=E:(k=-m+p,E=d));const M=0===k?0:k/E,P=0===x?0:x/w,b=(1-P)*r+P*s-((1-M)*t+M*n),I=(1-P)*o+P*a-((1-M)*e+M*i);return b*b+I*I}function Go(t,e){return t[0]===e[0]?t[1]-e[1]:t[0]-e[0]}const zo=()=>"ontouchstart"in window||navigator.maxTouchPoints>0;function Ho(){return"undefined"!=typeof vitest}class Yo{static getBounds(t,e=0){const n=[];t.forEach(t=>{isNaN(t.lat)||isNaN(t.lng),n.push(t)});const i=new a.Polyline(n).getBounds();return 0!==e?i.pad(e):i}}class Uo{constructor(t=0,e=0,n=0,i=0){o(this,"direction",{East:new a.LatLng(0,0),North:new a.LatLng(0,0),NorthEast:new a.LatLng(0,0),NorthWest:new a.LatLng(0,0),South:new a.LatLng(0,0),SouthEast:new a.LatLng(0,0),SouthWest:new a.LatLng(0,0),West:new a.LatLng(0,0)}),this.direction.North=new a.LatLng(n,(e+i)/2),this.direction.NorthEast=new a.LatLng(n,i),this.direction.East=new a.LatLng((t+n)/2,i),this.direction.SouthEast=new a.LatLng(t,i),this.direction.South=new a.LatLng(t,(e+i)/2),this.direction.SouthWest=new a.LatLng(t,e),this.direction.West=new a.LatLng((t+n)/2,e),this.direction.NorthWest=new a.LatLng(n,e)}getDirection(t){switch(t){case h.SouthWest:return this.direction.SouthWest;case h.West:return this.direction.West;case h.NorthWest:return this.direction.NorthWest;case h.North:return this.direction.North;case h.NorthEast:return this.direction.NorthEast;case h.East:return this.direction.East;case h.SouthEast:return this.direction.SouthEast;case h.South:return this.direction.South;default:throw new Error}}getPositions(t=h.SouthWest,e=!1,n=!0){const i=[],r=this.getPositionAsArray(t,e);return r.forEach(t=>{i.push([t.lng,t.lat])}),n&&i.push([r[0].lng,r[0].lat]),i}getPositionAsArray(t=h.NorthEast,e=!1){const n=[];if(e?(n.push(this.direction.SouthWest),n.push(this.direction.West),n.push(this.direction.NorthWest),n.push(this.direction.North),n.push(this.direction.NorthEast),n.push(this.direction.East),n.push(this.direction.SouthEast),n.push(this.direction.South)):(n.push(this.direction.SouthWest),n.push(this.direction.South),n.push(this.direction.SouthEast),n.push(this.direction.East),n.push(this.direction.NorthEast),n.push(this.direction.North),n.push(this.direction.NorthWest),n.push(this.direction.West)),t!==h.SouthWest){n.splice(0,t).forEach((e,i)=>{n.splice(t+i,0,e)})}return n}}class Xo{constructor(t,e){if(o(this,"metricLength",""),o(this,"metricUnit",""),o(this,"imperialLength",""),o(this,"imperialUnit",""),null!==t||void 0!==t){0===t?e.markers.markerInfoIcon.usePerimeterMinValue?(this.metricLength=e.markers.markerInfoIcon.values.min.metric,this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.m,this.imperialLength=e.markers.markerInfoIcon.values.min.imperial,this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.feet):(this.metricLength=e.markers.markerInfoIcon.values.unknown.metric,this.metricUnit=e.markers.markerInfoIcon.units.unknownUnit,this.imperialLength=e.markers.markerInfoIcon.values.unknown.imperial,this.imperialUnit=e.markers.markerInfoIcon.units.unknownUnit):t<100?(this.metricLength=(10*Math.ceil(t/10)).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.m):t<500?(this.metricLength=(50*Math.ceil(t/50)).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.m):t<1e3?(this.metricLength=(100*Math.ceil(t/100)).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.m):t<1e4?(this.metricLength=(100*Math.ceil(t/100)/1e3).toFixed(1),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.km):(this.metricLength=(1e3*Math.ceil(t/1e3)/1e3).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.km);const n=t/.0254/12,i=n/3,r=i/1760;t<1e3/2.54?(this.imperialLength=(10*Math.ceil(n/10)).toString(),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.feet):t<1e3/2.54*3?(this.imperialLength=(10*Math.ceil(i/10)).toString(),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.yards):t<1609?(this.imperialLength=r.toFixed(2),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.miles):t<16093?(this.imperialLength=r.toFixed(1),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.miles):(this.imperialLength=r.toFixed(0),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.miles)}}}class qo{constructor(t,e){o(this,"metricArea",""),o(this,"metricUnit",""),o(this,"imperialArea",""),o(this,"imperialUnit","");const n=t,i=e.markers.markerInfoIcon.units.metric.onlyMetrics;if(null!==n||void 0!==n){0===n?(this.metricArea="-",this.metricUnit=e.markers.markerInfoIcon.units.unknownUnit,this.imperialArea="-",this.imperialUnit=e.markers.markerInfoIcon.units.unknownUnit):n<1e4?(this.metricArea=Math.round(n).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.m2):n<1e5?i?(this.metricArea=(n/1e6).toFixed(2),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.km2):(this.metricArea=(n/1e3).toFixed(1),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.daa):n<1e7?i?(this.metricArea=(n/1e6).toFixed(2),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.km2):(this.metricArea=Math.round(n/1e3).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.daa):n<1e8?i?(this.metricArea=(n/1e6).toFixed(1),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.km2):(this.metricArea=Math.round(n/1e4).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.ha):(this.metricArea=Math.round(n/1e6).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.km2);const t=.0069444*(1550*n),r=.11111*t,o=20661e-8*r,s=3.2283e-7*r;n<92.9?(this.imperialArea=Math.round(t).toString(),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.feet2):n<836.14?(this.imperialArea=r.toFixed(0),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.yards2):n<40469.6?(this.imperialArea=o.toFixed(2),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.acres):n<404696?(this.imperialArea=o.toFixed(1),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.acres):n<4046960?(this.imperialArea=o.toFixed(0),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.acres):n<25900404?(this.imperialArea=s.toFixed(2),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.miles2):n<259004040?(this.imperialArea=s.toFixed(1),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.miles2):(this.imperialArea=s.toFixed(0),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.miles2)}}}class Vo{constructor(t){o(this,"config",c),this.config={...c,...t}}toProjectedTolerance(t,e){if(t<=0)return 0;try{const n=f*p,i=t*n,r=Math.cos(e.lat*p);return 0===r?t:i/(n*r)}catch{return t}}getFeatureDiagonal(t){try{const[e,n,i,r]=w(t);return Math.hypot(i-e,r-n)}catch{return 0}}getRingDiagonal(t){if(!t||0===t.length)return 0;let e=t[0].lat,n=t[0].lat,i=t[0].lng,r=t[0].lng;for(const o of t)e=Math.min(e,o.lat),n=Math.max(n,o.lat),i=Math.min(i,o.lng),r=Math.max(r,o.lng);return Math.hypot(r-i,n-e)}getAdaptiveTolerance(t,e){if(t<=0)return 0;if(e<=0)return t;const n=.02*e;return Math.min(t,n)}union(t,e){try{const n=x([t,e]),i=Be(n);return i?this.getTurfPolygon(i):null}catch(n){return Ho()||console.warn("Error in union:",n instanceof Error?n.message:String(n)),null}}createPolygonFromTrace(t){var e;const n=(null==(e=this.config.polygonCreation)?void 0:e.method)||"concaveman";switch(n){case"concaveman":return this.turfConcaveman(t);case"convex":return this.createConvexPolygon(t);case"direct":return this.createDirectPolygon(t);case"buffer":return this.createBufferedPolygon(t);default:return Ho()||console.warn(`Unknown polygon creation method: ${n}, falling back to concaveman`),this.turfConcaveman(t)}}turfConcaveman(t){const e=He(t).features.map(t=>t.geometry.coordinates);return k([[bo(e)]])}createConvexPolygon(t){const e=He(t),n=vt(e);return n?this.getTurfPolygon(n):this.createDirectPolygon(t)}createDirectPolygon(t){let e;if("LineString"===t.geometry.type)e=t.geometry.coordinates;else if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else{e=He(t).features.map(t=>t.geometry.coordinates)}if(e.length>0){const t=e[0],n=e[e.length-1];t[0]===n[0]&&t[1]===n[1]||e.push([t[0],t[1]])}return e.length<4?(Ho()||console.warn("Not enough points for direct polygon, falling back to concaveman"),this.turfConcaveman(t)):k([[e]])}createBufferedPolygon(t){try{let e;if("LineString"===t.geometry.type)e=t;else{const n=He(t).features.map(t=>t.geometry.coordinates);e=v(n)}const n=ki(e,.001,{units:"kilometers"});return n?this.getTurfPolygon(n):this.createDirectPolygon(t)}catch(e){return Ho()||console.warn("Buffer polygon creation failed:",e instanceof Error?e.message:String(e)),this.createDirectPolygon(t)}}getSimplified(t,e=!1){const n=this.resolveSimplificationConfig();if("none"===n.mode)return t;if("simple"===n.mode){const e=this.getAdaptiveTolerance(n.simple.tolerance,this.getFeatureDiagonal(t));return Fi(t,{tolerance:this.toProjectedTolerance(e,this.getReferenceLatLng(t)),highQuality:n.simple.highQuality,mutate:!1})}const i=t.geometry.coordinates[0][0].length,r=n.dynamic.fractionGuard,o=n.dynamic.multiplier,s=this.getAdaptiveTolerance(n.dynamic.baseTolerance,this.getFeatureDiagonal(t)),a={highQuality:n.dynamic.highQuality,mutate:!1},l=e=>Fi(t,{...a,tolerance:this.toProjectedTolerance(e,this.getReferenceLatLng(t))});if(!e)return l(s);let u=s,h=l(u);for(;h.geometry.coordinates[0][0].length>4&&h.geometry.coordinates[0][0].length/(i+2)>r;)u*=o,h=l(u);return h}simplifyLatLngRing(t,e,n=!0){var i,r;if(!t||0===t.length||e<=0)return t?[...t]:[];const o=[...t],s=o[0],a=o[o.length-1];a&&s&&a.lat===s.lat&&a.lng===s.lng||o.push({lat:s.lat,lng:s.lng});const l=o.map(t=>[t.lng,t.lat]),u=this.getAdaptiveTolerance(e,this.getRingDiagonal(o));try{const e=_([l]),o=Fi(e,{tolerance:this.toProjectedTolerance(u,t[0]),highQuality:n,mutate:!1}),s=null==(r=null==(i=null==o?void 0:o.geometry)?void 0:i.coordinates)?void 0:r[0];return s&&0!==s.length?s.map(t=>({lat:t[1],lng:t[0]})):[...t]}catch(h){return Ho()||console.warn("Error simplifying ring:",h instanceof Error?h.message:String(h)),[...t]}}resolveSimplificationConfig(){var t,e,n,i,r,o,s,a,l,u,h,c,f;const g=null==(t=this.config.polygonCreation)?void 0:t.simplification,d=this.config.simplification,p=(null==g?void 0:g.tolerance)??1e-5,y=(null==g?void 0:g.highQuality)??!1,m=null==g?void 0:g.mode,v=(null==g?void 0:g.tolerance)??1e-4;return{mode:(null==d?void 0:d.mode)??("none"===m?"none":"dynamic"===m?"dynamic":"simple"),simple:{tolerance:(null==(e=null==d?void 0:d.simple)?void 0:e.tolerance)??(null==(n=null==d?void 0:d.simplifyTolerance)?void 0:n.tolerance)??p,highQuality:(null==(i=null==d?void 0:d.simple)?void 0:i.highQuality)??(null==(r=null==d?void 0:d.simplifyTolerance)?void 0:r.highQuality)??y},dynamic:{baseTolerance:(null==(o=null==d?void 0:d.dynamic)?void 0:o.baseTolerance)??(null==(s=null==d?void 0:d.simplifyTolerance)?void 0:s.tolerance)??v,highQuality:(null==(a=null==d?void 0:d.dynamic)?void 0:a.highQuality)??(null==(l=null==d?void 0:d.simplifyTolerance)?void 0:l.highQuality)??y,fractionGuard:(null==(u=null==d?void 0:d.dynamic)?void 0:u.fractionGuard)??(null==(h=null==d?void 0:d.dynamicMode)?void 0:h.fractionGuard)??.9,multiplier:(null==(c=null==d?void 0:d.dynamic)?void 0:c.multiplier)??(null==(f=null==d?void 0:d.dynamicMode)?void 0:f.multiplier)??2}}}getTurfPolygon(t){let e;return e="Polygon"===t.geometry.type?k([t.geometry.coordinates]):k(t.geometry.coordinates),e}getMultiPolygon(t){return k(t)}getKinks(t){try{if(!t||!t.geometry||!t.geometry.coordinates)return[t];const e=this.removeDuplicateVertices(t);if(!e||!e.geometry||!e.geometry.coordinates)return Ho()||console.warn("Feature became invalid after cleaning in getKinks"),[t];if(this.polygonHasHoles(e))return this.getKinksWithHolePreservation(e);{const t=Sr(e),n=[];return z(t,t=>{n.push(t)}),n}}catch(e){return Ho()||console.warn("Error processing kinks:",e instanceof Error?e.message:String(e)),[t]}}getCoords(t){return E(t)}getReferenceLatLng(t){var e,n;try{const i=E(t),r=null==(n=null==(e=null==i?void 0:i[0])?void 0:e[0])?void 0:n[0];if(r&&Array.isArray(r)&&r.length>=2)return{lat:r[1],lng:r[0]}}catch{}return{lat:0,lng:0}}hasKinks(t){return Gi(t).features.length>0}getConvexHull(t){try{const e=x([t]);return vt(e)}catch(e){return Ho()||console.warn("Error in getConvexHull:",e instanceof Error?e.message:String(e)),null}}getMidpoint(t,e){const n=P(m([t.lng,t.lat]),m([e.lng,e.lat]));return{lat:n.geometry.coordinates[1],lng:n.geometry.coordinates[0]}}polygonIntersect(t,e){try{if(!(t&&t.geometry&&t.geometry.coordinates&&e&&e.geometry&&e.geometry.coordinates))return Ho()||console.warn("Invalid features passed to polygonIntersect"),!1;const n=t=>{var e,n;return Array.isArray(null==(n=null==(e=t[0])?void 0:e[0])?void 0:n[0])},i=t=>{if(!Array.isArray(t))return!1;const e=n(t)?t.flat():t;for(const n of e){if(!Array.isArray(n))return!1;for(const t of n){if(!Array.isArray(t)||t.length<2)return!1;if(t.some(t=>null==t||!isFinite(t)))return!1}}return!0};if(!i(t.geometry.coordinates)||!i(e.geometry.coordinates))return!1;try{const n=x([t,e]),i=Ge(n);if(i&&i.geometry&&("Polygon"===i.geometry.type||"MultiPolygon"===i.geometry.type)){if(W(i)>1e-6)return!0}}catch{}try{const n=He(t),i=He(e);for(const e of i.features)if(vr(e,t))return!0;for(const t of n.features)if(vr(t,e))return!0}catch{}try{const n=E(t),i=E(e);for(const t of n){const e=t[0];if(e&&!(e.length<2))for(let t=0;t<e.length-1;t++){const n=e[t],r=e[t+1];if(!n||!r||!Array.isArray(n)||!Array.isArray(r)||n.length<2||r.length<2||n.some(t=>null==t||!isFinite(t))||r.some(t=>null==t||!isFinite(t)))continue;const o=v([n,r]);for(const t of i){const e=t[0];if(e&&!(e.length<2))for(let t=0;t<e.length-1;t++){const n=e[t],i=e[t+1];if(!n||!i||!Array.isArray(n)||!Array.isArray(i)||n.length<2||i.length<2||n.some(t=>null==t||!isFinite(t))||i.some(t=>null==t||!isFinite(t)))continue;const r=v([n,i]);try{const t=Ft(o,r);if(t&&t.features&&t.features.length>0)return!0}catch{}}}}}}catch{}return!1}catch(n){return Ho()||console.warn("Error in polygonIntersect:",n instanceof Error?n.message:String(n)),!1}}getIntersection(t,e){try{const n=x([t,e]),i=Ge(n);return i&&i.geometry&&("Polygon"===i.geometry.type||"MultiPolygon"===i.geometry.type)?i:null}catch(n){return Ho()||console.warn("Error in getIntersection:",n instanceof Error?n.message:String(n)),null}}getDistance(t,e){return M(t,e)}isWithin(t,e){return Or(_([t]),_([e]))}isPolygonCompletelyWithin(t,e){try{return Or(t,e)}catch{const n=E(t),i=E(e);for(const t of n)for(const e of t)for(const t of e){const e=m(t);let n=!1;for(const t of i){for(const i of t){const t=_([i]);if(vr(e,t)){n=!0;break}}if(n)break}if(!n)return!1}return!0}}toPointFeature(t){if((t=>{var e;if(!t||"object"!=typeof t)return!1;const n=t;return"Feature"===n.type&&"Point"===(null==(e=n.geometry)?void 0:e.type)})(t))return t;if(Array.isArray(t)&&t.length>=2&&"number"==typeof t[0]&&"number"==typeof t[1])return m(t);if((e=t)&&"object"==typeof e&&"number"==typeof e.lat&&"number"==typeof e.lng){const e=t;return m([e.lng,e.lat])}var e;if((t=>{if(!t||"object"!=typeof t)return!1;const e=t.geometry;return!!e&&Array.isArray(e.coordinates)})(t))return m(t.geometry.coordinates);throw new Error("Unsupported point format provided to toPointFeature")}isPointInsidePolygon(t,e){try{const n=this.toPointFeature(t);return vr(n,e)}catch{return!1}}equalPolygons(t,e){return Xr(t,e)}convertToBoundingBoxPolygon(t){const e=function(t){const[e,n,i,r]=t;return _([[[e,n],[i,n],[i,r],[e,r],[e,n]]])}(w(t));return e}polygonToMultiPolygon(t){return k([t.geometry.coordinates])}injectPointToPolygon(t,e,n){const i=JSON.parse(JSON.stringify(t));let r;if("MultiPolygon"===i.geometry.type)r=i.geometry.coordinates[0][n];else{if("Polygon"!==i.geometry.type)return i;r=i.geometry.coordinates[n]}if(!r)return i;let o=1/0,s=0;for(let a=0;a<r.length-1;a++){const t=r[a],n=r[a+1],i=this.distanceToLineSegment(e,t,n);i<o&&(o=i,s=a+1)}return r.splice(s,0,e),i}distanceToLineSegment(t,e,n){const i=t[0]-e[0],r=t[1]-e[1],o=n[0]-e[0],s=n[1]-e[1],a=i*o+r*s,l=o*o+s*s;if(0===l)return Math.sqrt(i*i+r*r);const u=a/l;let h,c;u<0?(h=e[0],c=e[1]):u>1?(h=n[0],c=n[1]):(h=e[0]+u*o,c=e[1]+u*s);const f=t[0]-h,g=t[1]-c;return Math.sqrt(f*f+g*g)}polygonDifference(t,e){try{const n=x([t,e]),i=ze(n);return i?this.getTurfPolygon(i):null}catch(n){return Ho()||console.warn("Error in polygonDifference:",n instanceof Error?n.message:String(n)),null}}getBoundingBoxCompassPosition(t,e,n,i){return null}getNearestPointIndex(t,e){return eo(t,e).properties.featureIndex??0}getCoord(t){return[t.lng,t.lat]}createPolygon(t){return _(t)}getFeaturePointCollection(t){const e=[];t.forEach(t=>{const n=m([t.lng,t.lat],{});e.push(n)});return x(e)}getPolygonArea(t){return W(t)}getPolygonPerimeter(t){return ro(t,{units:"kilometers"})}getCenterOfMass(t){return Mt(t)}getDoubleElbowLatLngs(t){const e=[],n=t.length,i=t[0].lat===t[n-1].lat&&t[0].lng===t[n-1].lng?n-1:n;for(let r=0;r<i;r++){const n=t[r],o=t[(r+1)%i];e.push(new a.LatLng(n.lat,n.lng));const s=P(m([n.lng,n.lat]),m([o.lng,o.lat]));e.push(new a.LatLng(s.geometry.coordinates[1],s.geometry.coordinates[0]))}return e}getBezierMultiPolygon(t){const e=t=>{if(!t||0===t.length)return t;const e=t[0],n=t[t.length-1];return e[0]===n[0]&&e[1]===n[1]?t:[...t,[e[0],e[1]]]},n=t.map(t=>t.map(t=>{const n=e(t);try{const t=v(n),i=io(t,{resolution:this.config.bezier.resolution,sharpness:this.config.bezier.sharpness}).geometry.coordinates??n,r=Math.max(2,n.length-1),o=Math.max(1,this.config.bezier.resampleMultiplier??10),s=Math.max(4,this.config.bezier.maxNodes??i.length),a=((t,n)=>{const i=e(t);if(!i||i.length<2)return i;const r=(t,e)=>{const n=t[0]-e[0],i=t[1]-e[1];return Math.sqrt(n*n+i*i)};let o=0;for(let e=1;e<i.length;e++)o+=r(i[e-1],i[e]);if(!Number.isFinite(o)||o<=0)return i;const s=o/Math.max(n,4),a=[i[0]];let l=0;for(let e=1;e<i.length;e++){let t=i[e-1];const n=i[e];let o=r(t,n);for(;l+o>=s&&o>0;){const e=(s-l)/o,i=[t[0]+(n[0]-t[0])*e,t[1]+(n[1]-t[1])*e];a.push(i),t=i,o=r(t,n),l=0}l+=o}return e(a)})(i,Math.max(4,Math.min(s,r*o))),l=(t=>{if(!t||0===t.length)return t;const n=1e-6,i=new Set,r=[];for(let e=0;e<t.length;e++){const o=t[e];if(!Array.isArray(o)||o.length<2)continue;const s=`${Math.round(o[0]/n)}:${Math.round(o[1]/n)}`;i.has(s)||(i.add(s),r.push(o))}return e(r)})(a);return l.length>=4?l:n}catch(i){return Ho()||console.warn("Bezier smoothing failed for ring, falling back to original:",i),n}}));return this.getMultiPolygon(n)}polygonHasHoles(t){try{return"Polygon"===t.geometry.type?t.geometry.coordinates.length>1:"MultiPolygon"===t.geometry.type&&t.geometry.coordinates.some(t=>t.length>1)}catch(e){return Ho()||console.warn("Error checking for holes:",e instanceof Error?e.message:String(e)),!1}}getKinksWithHolePreservation(t){try{if("Polygon"===t.geometry.type){const e=t.geometry.coordinates,n=e[0],i=e.slice(1),r={type:"Feature",geometry:{type:"Polygon",coordinates:[n]},properties:t.properties||{}},o=this.hasKinks(r),s=this.checkOuterRingHoleIntersection(n,i);if(o||s){if(this.checkIfDragCompletelyThroughHole(n,i))return this.handleCompleteHoleTraversal(r,i);const t=Sr(r),e=[];return z(t,t=>{const n=this.subtractIntersectingHoles(t,i);e.push(n)}),e}return[t]}if("MultiPolygon"===t.geometry.type){const e=[];for(const n of t.geometry.coordinates){const i={type:"Feature",geometry:{type:"Polygon",coordinates:n},properties:t.properties||{}},r=this.getKinksWithHolePreservation(i);e.push(...r)}return e}return[t]}catch(e){return Ho()||console.warn("Error in getKinksWithHolePreservation:",e instanceof Error?e.message:String(e)),[t]}}checkIfDragCompletelyThroughHole(t,e){try{if(this.findDuplicatePoints(t).length>0)return!0;const n=this.findSelfIntersectionLine(t);if(n&&e.length>0)for(const t of e)if(this.lineCompletelyTraversesHole(n,t))return!0;if(this.hasKinks({type:"Feature",geometry:{type:"Polygon",coordinates:[t]},properties:{}}))for(const i of e)if(this.holeIsCutByKinks(t,i))return!0;return!1}catch(n){return Ho()||console.warn("Error checking complete hole traversal:",n instanceof Error?n.message:String(n)),!1}}findSelfIntersectionLine(t){try{const e=new Map;for(let n=0;n<t.length-1;n++){const i=t[n],r=`${i[0]},${i[1]}`;e.has(r)?e.get(r).indices.push(n):e.set(r,{point:i,indices:[n]})}for(const[,n]of e)if(n.indices.length>=2){const e=n.indices[0],i=n.indices[1],r=[];for(let n=e;n<=i;n++)r.push(t[n]);return r}return null}catch(e){return Ho()||console.warn("Error finding self-intersection line:",e instanceof Error?e.message:String(e)),null}}lineCompletelyTraversesHole(t,e){try{if(t.length<2)return!1;const n=t[0],i=t[t.length-1],r=_([e]),o=vr(m(n),r);return o!==vr(m(i),r)}catch(n){return Ho()||console.warn("Error checking line hole traversal:",n instanceof Error?n.message:String(n)),!1}}holeIsCutByKinks(t,e){try{const n=_([t]),i=_([e]),r=Gi(n);if(0===r.features.length)return!1;for(const t of r.features){const e=t.geometry.coordinates;try{if(M(m(e),b(i))<.01)return!0;if(vr(m(e),i))return!0}catch{if(vr(m(e),i))return!0}}return!1}catch(n){return Ho()||console.warn("Error checking hole cut by kinks:",n.message),!1}}findDuplicatePoints(t){const e=[],n=new Set;for(let i=0;i<t.length-1;i++){const r=t[i],o=`${r[0]},${r[1]}`;n.has(o)?e.push(r):n.add(o)}return e}checkOuterRingHoleIntersection(t,e){try{if(0===e.length)return!1;const n=_([t]);for(const i of e){const e=_([i]);if(this.getIntersection(n,e))return!0;for(let n=0;n<t.length-1;n++){const i=t[n];if(vr(m(i),e))return!0}}return!1}catch{return!1}}handleCompleteHoleTraversal(t,e){try{const e={type:"Feature",geometry:{type:"Polygon",coordinates:[t.geometry.coordinates[0]]},properties:t.properties||{}},n=Sr(e),i=[];return z(n,t=>{t._polydrawHoleTraversalOccurred=!0,i.push(t)}),i}catch(n){Ho()||console.warn("Error handling complete hole traversal:",n instanceof Error?n.message:String(n));try{const e={...t,geometry:{...t.geometry,coordinates:[t.geometry.coordinates[0]]}};return e._polydrawHoleTraversalOccurred=!0,[e]}catch{return[t]}}}subtractIntersectingHoles(t,e){try{let n=t;for(const t of e){const e=_([t]);if(this.getIntersection(e,n)){const t=this.polygonDifference(n,e);if(t)if("Polygon"===t.geometry.type)n=t;else if("MultiPolygon"===t.geometry.type){const e=t;let i=0,r=null;for(const t of e.geometry.coordinates){const e={type:"Feature",geometry:{type:"Polygon",coordinates:t},properties:{}},n=W(e);n>i&&(i=n,r=e)}r&&(n=r)}}}return n}catch(n){return Ho()||console.warn("Error subtracting intersecting holes:",n instanceof Error?n.message:String(n)),t}}removeDuplicateVertices(t){if(!t||!t.geometry||!t.geometry.coordinates)return Ho()||console.warn("Invalid feature passed to removeDuplicateVertices"),t;const e=t=>{if(!t||t.length<3)return Ho()||console.warn("Invalid coordinates array - need at least 3 points for a polygon"),t||[];const e=[],n=1e-6,i=new Set;for(let r=0;r<t.length;r++){const o=t[r],s=t[(r+1)%t.length];if(!o||!Array.isArray(o)||o.length<2||!s||!Array.isArray(s)||s.length<2)continue;const a=Math.abs(o[1]-s[1]),l=Math.abs(o[0]-s[0]),u=`${Math.round(o[0]/n)}:${Math.round(o[1]/n)}`,h=i.has(u);(a>n||l>n)&&!h&&(e.push(o),i.add(u))}if(e.length<3)return Ho()||console.warn("After cleaning, polygon has less than 3 points"),t;if(e.length>0){const t=e[0],i=e[e.length-1],r=Math.abs(t[1]-i[1]),o=Math.abs(t[0]-i[0]);(r>n||o>n)&&e.push([t[0],t[1]])}return e};try{if("Polygon"===t.geometry.type){const n=t.geometry.coordinates.map(t=>e(t));return n.some(t=>t.length<4)?(Ho()||console.warn("Cleaned polygon has invalid ring with less than 4 coordinates"),t):{...t,geometry:{...t.geometry,coordinates:n}}}if("MultiPolygon"===t.geometry.type){const n=t.geometry.coordinates.map(t=>t.map(t=>e(t)));return n.some(t=>t.some(t=>t.length<4))?(Ho()||console.warn("Cleaned multipolygon has invalid ring with less than 4 coordinates"),t):{...t,geometry:{...t.geometry,coordinates:n}}}}catch(n){return Ho()||console.warn("Error in removeDuplicateVertices:",n instanceof Error?n.message:String(n)),t}return t}}const jo=()=>{if("undefined"!=typeof globalThis)return globalThis.L};class Ko{static getVersion(){if(this._detectedVersion)return this._detectedVersion;const t=jo();return t?(this._detectedVersion=this.detectVersion(t),this._detectedVersion):l.V2}static detectVersion(t){const e=t??jo();if(!e)return l.V2;if(e.version){if(e.version.startsWith("2."))return l.V2;if(e.version.startsWith("1."))return l.V1}return"function"!=typeof e.marker?l.V2:"function"==typeof e.marker&&"function"==typeof e.polyline&&"function"==typeof e.polygon?l.V1:e.Marker&&"function"==typeof e.Marker&&e.Polyline&&"function"==typeof e.Polyline?l.V2:l.V1}static isV1(){return this.getVersion()===l.V1}static isV2(){return this.getVersion()===l.V2}static reset(){this._detectedVersion=null}static getVersionInfo(){const t=this.getVersion(),e=jo();return{version:t,leafletVersion:null==e?void 0:e.version,hasFactoryMethods:"function"==typeof(null==e?void 0:e.marker),hasConstructors:!!(null==e?void 0:e.Marker)&&"function"==typeof e.Marker,globalLAvailable:!!e}}}o(Ko,"_detectedVersion",null);const Wo=new class{constructor(){o(this,"domUtil",{create:(t,e,n)=>{if(void 0!==a&&a.DomUtil)return a.DomUtil.create(t,e,n);{const i=document.createElement(t);return e&&(i.className=e),n&&n.appendChild(i),i}},addClass:(t,e)=>{this.version===l.V1?a.DomUtil.addClass(t,e):t.classList.add(e)},removeClass:(t,e)=>{this.version===l.V1?a.DomUtil.removeClass(t,e):t.classList.remove(e)},hasClass:(t,e)=>this.version===l.V1?a.DomUtil.hasClass(t,e):t.classList.contains(e),setPosition:(t,e)=>{a.DomUtil.setPosition(t,e)},getPosition:t=>a.DomUtil.getPosition(t)}),o(this,"domEvent",{on:(t,e,n,i)=>(a.DomEvent.on(t,e,n,i),this),off:(t,e,n,i)=>(a.DomEvent.off(t,e,n,i),this),stopPropagation:t=>(a.DomEvent.stopPropagation(t),this),preventDefault:t=>(a.DomEvent.preventDefault(t),this),stop:t=>(a.DomEvent.stop(t),this),disableClickPropagation:t=>(a.DomEvent.disableClickPropagation(t),this),disableScrollPropagation:t=>(a.DomEvent.disableScrollPropagation(t),this),getMousePosition:(t,e)=>{if(this.version===l.V1)return a.DomEvent.getMousePosition(t,e);{const n=a.DomEvent;return n.getPointerPosition?n.getPointerPosition(t,e):a.DomEvent.getMousePosition(t,e)}}}),o(this,"util",{extend:(t,...e)=>this.version===l.V1?a.Util.extend(t,...e):Object.assign(t,...e),bind:(t,e)=>this.version===l.V1?a.Util.bind(t,e):t.bind(e),stamp:t=>a.Util.stamp(t),throttle:(t,e,n)=>a.Util.throttle(t,e,n),wrapNum:(t,e,n)=>a.Util.wrapNum(t,e,n),falseFn:()=>a.Util.falseFn(),formatNum:(t,e)=>a.Util.formatNum(t,e),trim:t=>this.version===l.V1?a.Util.trim(t):t.trim(),splitWords:t=>a.Util.splitWords(t),setOptions:(t,e)=>a.Util.setOptions(t,e),getParamString:(t,e,n)=>{if(this.version===l.V1)return a.Util.getParamString(t,e,n);{const i=new URLSearchParams;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const r=n?e.toUpperCase():e;i.set(r,String(t[e]))}const r=i.toString();if(e){const t=-1===e.indexOf("?")?"?":"&";return e+t+r}return r?"?"+r:""}},template:(t,e)=>a.Util.template(t,e),isArray:t=>this.version===l.V1?a.Util.isArray(t):Array.isArray(t),indexOf:(t,e)=>a.Util.indexOf(t,e),requestAnimFrame:(t,e,n)=>this.version===l.V1?a.Util.requestAnimFrame(t,e,n):requestAnimationFrame(e?t.bind(e):t),cancelAnimFrame:t=>{this.version===l.V1?a.Util.cancelAnimFrame(t):cancelAnimationFrame(t)}})}get version(){return Ko.getVersion()}createTileLayer(t,e){return new a.TileLayer(t,e)}createMap(t,e){return new a.Map(t,e)}createMarker(t,e){return new a.Marker(t,e)}createPolyline(t,e){return new a.Polyline(t,e)}createPolygon(t,e){return new a.Polygon(t,e)}createDivIcon(t){return new a.DivIcon(t)}createLatLng(t,e,n){return new a.LatLng(t,e,n)}createLatLngBounds(t,e){return t&&e?new a.LatLngBounds(t,e):t?new a.LatLngBounds(t,t):new a.LatLngBounds([])}createPoint(t,e,n){return new a.Point(t,e,n)}createPopup(t,e){return new a.Popup(t,e)}createFeatureGroup(t){return new a.FeatureGroup(t)}createLayerGroup(t){return new a.LayerGroup(t)}getBrowser(){const t=this,e=a.Browser;return{get ie(){return t.version===l.V1&&a.Browser.ie},get ielt9(){return t.version===l.V1&&a.Browser.ielt9},get edge(){return t.version===l.V1&&a.Browser.edge},get webkit(){return t.version===l.V1&&a.Browser.webkit},get android(){return t.version===l.V1?a.Browser.android:/Android/.test(navigator.userAgent)},get android23(){return t.version===l.V1&&a.Browser.android23},get androidStock(){return t.version===l.V1&&a.Browser.androidStock},get opera(){return t.version===l.V1&&a.Browser.opera},get chrome(){return t.version===l.V1?a.Browser.chrome:/Chrome/.test(navigator.userAgent)},get gecko(){return t.version===l.V1&&a.Browser.gecko},get safari(){return t.version===l.V1?a.Browser.safari:/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)},get phantom(){return t.version===l.V1&&(e.phantom??!1)},get opera12(){return t.version===l.V1&&a.Browser.opera12},get win(){return t.version===l.V1?a.Browser.win:/Win/.test(navigator.platform)},get ie3d(){return t.version===l.V1&&a.Browser.ie3d},get webkit3d(){return t.version===l.V1&&a.Browser.webkit3d},get gecko3d(){return t.version===l.V1&&a.Browser.gecko3d},get any3d(){return t.version!==l.V1||a.Browser.any3d},get mobile(){return a.Browser.mobile},get mobileWebkit(){return t.version===l.V1&&a.Browser.mobileWebkit},get mobileWebkit3d(){return t.version===l.V1&&a.Browser.mobileWebkit3d},get msPointer(){return t.version===l.V1&&a.Browser.msPointer},get pointer(){return a.Browser.pointer||!0},get touch(){return a.Browser.touch},get touchNative(){return t.version===l.V1&&(e.touchNative??!1)},get mobileOpera(){return t.version===l.V1&&a.Browser.mobileOpera},get mobileGecko(){return t.version===l.V1&&a.Browser.mobileGecko},get retina(){return a.Browser.retina},get passiveEvents(){return t.version!==l.V1||(e.passiveEvents??!0)},get canvas(){return t.version!==l.V1||a.Browser.canvas},get svg(){return t.version!==l.V1||a.Browser.svg},get vml(){return t.version===l.V1&&a.Browser.vml},get inlineSvg(){return t.version!==l.V1||(e.inlineSvg??!0)}}}getVersion(){return this.version}isV1(){return this.version===l.V1}isV2(){return this.version===l.V2}};function Zo(t,e){t.innerHTML=e;const n=t.querySelector("svg");n&&(!function(t){if(t.hasAttribute("viewBox"))return;const e=t.getAttribute("width"),n=t.getAttribute("height"),i=e?parseFloat(e):NaN,r=n?parseFloat(n):NaN;Number.isFinite(i)&&Number.isFinite(r)&&i>0&&r>0&&t.setAttribute("viewBox",`0 0 ${i} ${r}`)}(n),function(t){const e=Array.from(t.querySelectorAll("style"));if(0===e.length)return;const n=new Set;if(e.forEach(e=>{const i=e.textContent;if(!i)return void e.remove();const r=/([^{]+)\{([^}]*)\}/g;let o;for(;null!==(o=r.exec(i));){const e=o[1].split(",").map(t=>t.trim()).filter(Boolean),i=o[2];e.forEach(e=>{if(!e.startsWith("."))return;const r=e.slice(1);n.add(r),t.querySelectorAll(`.${r}`).forEach(t=>{i.split(";").forEach(e=>{const[n,i]=e.split(":");n&&i&&t.style.setProperty(n.trim(),i.trim())})})})}e.remove()}),0===n.size)return;t.querySelectorAll("[class]").forEach(t=>{const e=Array.from(t.classList).filter(t=>!n.has(t));e.length>0?t.setAttribute("class",e.join(" ")):t.removeAttribute("class")})}(n),n.setAttribute("width","24"),n.setAttribute("height","24"),n.style.pointerEvents="none",n.querySelectorAll("*").forEach(t=>{t.style.pointerEvents="none"}))}const Jo={activate:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" id="svg1" width="512" height="512" version="1.1">\n <path id="Shape" fill="#000" fill-rule="evenodd" stroke="none" d="M73.574 425.687c-1.14.188-4.099-.592-6.574-1.735-2.475-1.142-5.513-3.027-6.75-4.188C58 417.65 58 417.65 58 348.144c0-69.506 0-69.506 6.152-80.075a1599.57 1599.57 0 0 1 12.84-21.569c3.677-6.05 12.679-21.125 20.004-33.5 7.324-12.375 15.666-26.325 18.538-31 2.87-4.675 13.163-21.88 22.872-38.233a33686.921 33686.921 0 0 1 34.229-57.5c9.117-15.272 18.261-30.022 20.322-32.777 2.298-3.074 5.78-6.117 9.008-7.874 3.583-1.95 7.22-3.017 11.399-3.342 4.972-.388 7.445.018 13.04 2.137 3.799 1.439 10.999 4.919 16 7.733 5.003 2.814 13.371 7.613 18.596 10.663s13.775 8.134 19 11.297c5.225 3.163 12.061 7.246 15.192 9.073 3.13 1.828 9.402 5.521 13.936 8.208 4.535 2.686 10.397 6.897 13.027 9.357 3.265 3.054 5.457 6.261 6.912 10.115 1.672 4.43 2.036 7.161 1.694 12.704-.324 5.244-1.186 8.511-3.349 12.695-1.601 3.098-9.388 16.57-17.303 29.939-7.915 13.368-16.24 27.326-18.5 31.019a3087.099 3087.099 0 0 0-9.697 16c-3.073 5.107-11.2 18.736-18.061 30.286-6.86 11.55-16.45 27.75-21.312 36-4.86 8.25-11.179 18.825-14.04 23.5-2.862 4.675-8.308 13.83-12.101 20.343-3.794 6.513-10.508 17.762-14.92 24.997-7.721 12.664-8.263 13.29-14.5 16.77-3.563 1.987-15.357 8.416-26.21 14.286-10.851 5.87-28.851 15.66-40 21.756-11.147 6.096-25.86 14.032-32.694 17.638-6.834 3.605-13.359 6.709-14.5 6.897ZM116 376.754c2.096-.21 12.525-5.28 26-12.636 12.375-6.757 23.394-13.153 24.486-14.215 1.495-1.453 1.734-2.331.966-3.548-.56-.889-7.304-5.352-14.986-9.918-7.681-4.565-17.116-10.268-20.966-12.672-3.85-2.405-15.046-9.073-24.88-14.818-9.834-5.746-19.087-10.976-20.561-11.623-1.641-.72-3.24-.831-4.12-.287-.981.606-1.598 3.444-1.939 8.924-.275 4.42-.347 17.312-.16 28.65.341 20.616.341 20.616 3.5 23.908 1.738 1.81 9.01 6.733 16.16 10.94 10.754 6.327 13.605 7.587 16.5 7.295ZM184.98 329c.9 0 2.342-.563 3.204-1.25.86-.688 3.803-4.85 6.537-9.25 2.735-4.4 17.476-28.925 32.759-54.5 15.283-25.575 29.64-49.497 31.904-53.16 2.264-3.662 6.141-10.152 8.616-14.422 2.475-4.27 5.957-10.274 7.738-13.341 1.785-3.075 3.244-7.005 3.25-8.759.011-2.982-.694-3.614-11.238-10.077A2882.894 2882.894 0 0 0 249 152.847c-4.125-2.475-13.245-7.94-20.267-12.145a9841.507 9841.507 0 0 1-20.5-12.309 1566.199 1566.199 0 0 0-14.685-8.73c-3.823-2.238-8.13-4.242-9.57-4.453-1.998-.293-3.333.43-5.64 3.057-1.661 1.893-5.368 7.444-8.237 12.337a2040.256 2040.256 0 0 1-11.477 19.251 5775.594 5775.594 0 0 0-12.325 20.5A7048.542 7048.542 0 0 1 131.47 195c-4.823 7.975-10.898 18.1-13.501 22.5-2.604 4.4-8.45 14.075-12.991 21.5-4.542 7.425-10.268 16.988-12.725 21.252-3.26 5.657-4.304 8.405-3.861 10.168.454 1.81 4.239 4.57 15.1 11.01 7.973 4.726 20.686 12.257 28.252 16.735 7.566 4.477 17.582 10.485 22.257 13.351 4.675 2.866 13.19 7.973 18.921 11.348 5.732 3.375 11.158 6.136 12.059 6.136Zm100.681-194.022c2.318.016 3.852-.798 5.75-3.055 1.497-1.78 2.589-4.313 2.589-6.01 0-2.269-.848-3.508-3.75-5.478-2.063-1.4-6.53-4.29-9.927-6.421-3.398-2.132-9.923-6.015-14.5-8.63-4.578-2.614-10.798-6.408-13.823-8.43-3.025-2.022-7.75-4.873-10.5-6.334-2.75-1.462-8.15-4.689-12-7.171-5.023-3.24-7.838-4.434-9.968-4.232-2.1.2-3.65 1.298-5.297 3.75-1.437 2.14-2.215 4.588-2.032 6.391.254 2.498 1.604 3.72 9.297 8.412 4.95 3.02 15.525 9.427 23.5 14.238a3631.896 3631.896 0 0 1 26 15.848c7.807 4.82 12.515 7.107 14.661 7.122Z"/>\n <path id="path1" fill="#000" fill-rule="evenodd" stroke="none" d="M479.5 119.5c0 34 0 34-7 34.262-3.85.144-11.275.947-16.5 1.785s-12.533 2.42-16.24 3.514c-3.708 1.095-9.416 3.559-12.686 5.475-3.269 1.916-7.401 4.71-9.183 6.209-1.781 1.499-4.926 5.336-6.988 8.526-2.395 3.706-4.41 8.588-5.576 13.515-1.346 5.684-1.817 11.548-1.79 22.282.023 8.902.749 19.208 1.866 26.5 1.006 6.563 2.964 17.107 4.352 23.432 1.388 6.325 3.152 14.2 3.92 17.5.768 3.3 3.14 14.55 5.272 25s4.816 24.901 5.965 32.114c1.57 9.86 2.088 17.705 2.088 31.622 0 16.395-.284 19.635-2.485 28.386-1.367 5.433-4.299 13.56-6.515 18.061-2.832 5.75-6.265 10.559-11.545 16.172-5.308 5.642-10.516 9.846-17.735 14.316-5.62 3.481-13.145 7.611-16.72 9.179-3.575 1.567-10.739 4.4-15.92 6.293-5.181 1.894-13.506 4.308-18.5 5.365-4.994 1.056-13.58 2.637-19.08 3.513-6.633 1.057-18.754 1.716-36 1.958-14.3.201-30.5.01-36-.424s-15.625-1.537-22.5-2.45c-6.875-.912-16.575-2.328-21.557-3.146-4.98-.817-12.406-2.176-16.5-3.02-4.093-.843-9.693-2.157-12.443-2.92-2.75-.763-7.7-2.083-11-2.932-3.3-.85-10.5-2.648-16-3.996-5.5-1.348-15.85-4.3-23-6.56-7.15-2.261-14.912-4.805-17.25-5.653-2.904-1.055-4.25-2.127-4.25-3.386 0-1.228 3.252-3.97 9.75-8.22 5.363-3.507 13.202-8.277 17.421-10.6 7.671-4.225 7.671-4.225 18.5-1.287 5.956 1.616 19.154 4.998 29.329 7.515 10.175 2.517 23.45 5.465 29.5 6.55 6.05 1.087 15.05 2.427 20 2.98 4.95.552 14.85 1.53 22 2.175 8.107.73 21.657.955 36 .598 13.264-.33 27.021-1.234 32.5-2.135 5.225-.86 14-2.963 19.5-4.673s12.925-4.443 16.5-6.073a870.93 870.93 0 0 0 11.5-5.354c2.75-1.314 7.94-4.836 11.535-7.826 3.888-3.234 7.591-7.403 9.142-10.29 1.433-2.668 3.653-8.143 4.932-12.166 1.934-6.082 2.319-9.415 2.283-19.794-.024-7.149-.774-16.627-1.756-22.186-.943-5.339-2.407-13.531-3.253-18.206-.847-4.675-2.454-12.775-3.572-18-1.118-5.225-3.15-14-4.514-19.5-1.365-5.5-3.5-14.725-4.746-20.5-1.246-5.775-2.995-15-3.886-20.5-.892-5.5-2.081-14.08-2.643-19.068-.562-4.987-1.014-13.987-1.005-20 .01-6.012.652-14.799 1.427-19.525.775-4.726 2.12-11.026 2.988-14 .869-2.974 3.04-8.224 4.824-11.668 1.784-3.443 5.256-9.004 7.715-12.356 2.46-3.353 8.084-8.988 12.5-12.523 4.416-3.534 11.629-8.164 16.029-10.287 4.4-2.124 12.05-5.194 17-6.823 4.95-1.63 14.625-3.757 21.5-4.729s16.1-1.824 20.5-1.894l8-.127Z"/>\n <path id="path2" fill="#B6BCC4" fill-rule="evenodd" stroke="none" d="M116 375.743c-2.73.236-5.372-.8-12-4.708-4.675-2.756-11.133-6.704-14.35-8.773-3.218-2.07-6.48-4.977-7.25-6.462-1.094-2.111-1.4-8.348-1.4-28.56 0-21.125.267-26.213 1.461-27.799 1.43-1.9 1.574-1.879 6.75.986 2.909 1.61 8.214 4.584 11.789 6.61 3.575 2.026 9.1 5.209 12.28 7.073 3.179 1.865 10.253 6.09 15.722 9.39 5.468 3.3 13.836 8.245 18.596 10.989 4.76 2.744 10.736 6.348 13.279 8.01 2.568 1.678 4.753 3.927 4.917 5.062.246 1.716-3.42 4.101-23 14.96-14.766 8.189-24.575 13.03-26.794 13.222Z"/>\n <path id="path3" fill="#fff" fill-rule="evenodd" stroke="none" d="M185.256 329c-1.012 0-5.646-2.194-10.298-4.875-4.652-2.68-22.633-13.322-39.958-23.648-17.325-10.325-34.65-20.844-38.5-23.375-6.25-4.109-7.029-4.977-7.268-8.102-.202-2.632.816-5.36 4.106-11 2.407-4.125 21.576-36.075 42.6-71 21.022-34.925 39.47-65.075 40.994-67 2.195-2.772 3.589-3.562 6.699-3.797 3.477-.262 6.271 1.103 24.398 11.925 11.259 6.722 30.146 18.027 41.971 25.123 11.825 7.095 23.075 14.15 25 15.675 2.099 1.664 3.627 3.836 3.816 5.425.19 1.592-1.021 5.145-3.035 8.9-1.844 3.437-21.525 36.528-43.737 73.537-22.211 37.008-41.411 68.395-42.666 69.75-1.256 1.354-3.11 2.462-4.122 2.462Z"/>\n</svg>'.trim(),draw:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" id="svg1" width="512" height="512" version="1.1">\n <path id="Shape" fill="#000" fill-rule="evenodd" stroke="none" d="M73.574 425.687c-1.14.188-4.099-.592-6.574-1.735-2.475-1.142-5.513-3.027-6.75-4.188C58 417.65 58 417.65 58 348.144c0-69.506 0-69.506 6.152-80.075a1599.57 1599.57 0 0 1 12.84-21.569c3.677-6.05 12.679-21.125 20.004-33.5 7.324-12.375 15.666-26.325 18.538-31 2.87-4.675 13.163-21.88 22.872-38.233a33686.921 33686.921 0 0 1 34.229-57.5c9.117-15.272 18.261-30.022 20.322-32.777 2.298-3.074 5.78-6.117 9.008-7.874 3.583-1.95 7.22-3.017 11.399-3.342 4.972-.388 7.445.018 13.04 2.137 3.799 1.439 10.999 4.919 16 7.733 5.003 2.814 13.371 7.613 18.596 10.663s13.775 8.134 19 11.297c5.225 3.163 12.061 7.246 15.192 9.073 3.13 1.828 9.402 5.521 13.936 8.208 4.535 2.686 10.397 6.897 13.027 9.357 3.265 3.054 5.457 6.261 6.912 10.115 1.672 4.43 2.036 7.161 1.694 12.704-.324 5.244-1.186 8.511-3.349 12.695-1.601 3.098-9.388 16.57-17.303 29.939-7.915 13.368-16.24 27.326-18.5 31.019a3087.099 3087.099 0 0 0-9.697 16c-3.073 5.107-11.2 18.736-18.061 30.286-6.86 11.55-16.45 27.75-21.312 36-4.86 8.25-11.179 18.825-14.04 23.5-2.862 4.675-8.308 13.83-12.101 20.343-3.794 6.513-10.508 17.762-14.92 24.997-7.721 12.664-8.263 13.29-14.5 16.77-3.563 1.987-15.357 8.416-26.21 14.286-10.851 5.87-28.851 15.66-40 21.756-11.147 6.096-25.86 14.032-32.694 17.638-6.834 3.605-13.359 6.709-14.5 6.897ZM116 376.754c2.096-.21 12.525-5.28 26-12.636 12.375-6.757 23.394-13.153 24.486-14.215 1.495-1.453 1.734-2.331.966-3.548-.56-.889-7.304-5.352-14.986-9.918-7.681-4.565-17.116-10.268-20.966-12.672-3.85-2.405-15.046-9.073-24.88-14.818-9.834-5.746-19.087-10.976-20.561-11.623-1.641-.72-3.24-.831-4.12-.287-.981.606-1.598 3.444-1.939 8.924-.275 4.42-.347 17.312-.16 28.65.341 20.616.341 20.616 3.5 23.908 1.738 1.81 9.01 6.733 16.16 10.94 10.754 6.327 13.605 7.587 16.5 7.295ZM184.98 329c.9 0 2.342-.563 3.204-1.25.86-.688 3.803-4.85 6.537-9.25 2.735-4.4 17.476-28.925 32.759-54.5 15.283-25.575 29.64-49.497 31.904-53.16 2.264-3.662 6.141-10.152 8.616-14.422 2.475-4.27 5.957-10.274 7.738-13.341 1.785-3.075 3.244-7.005 3.25-8.759.011-2.982-.694-3.614-11.238-10.077A2882.894 2882.894 0 0 0 249 152.847c-4.125-2.475-13.245-7.94-20.267-12.145a9841.507 9841.507 0 0 1-20.5-12.309 1566.199 1566.199 0 0 0-14.685-8.73c-3.823-2.238-8.13-4.242-9.57-4.453-1.998-.293-3.333.43-5.64 3.057-1.661 1.893-5.368 7.444-8.237 12.337a2040.256 2040.256 0 0 1-11.477 19.251 5775.594 5775.594 0 0 0-12.325 20.5A7048.542 7048.542 0 0 1 131.47 195c-4.823 7.975-10.898 18.1-13.501 22.5-2.604 4.4-8.45 14.075-12.991 21.5-4.542 7.425-10.268 16.988-12.725 21.252-3.26 5.657-4.304 8.405-3.861 10.168.454 1.81 4.239 4.57 15.1 11.01 7.973 4.726 20.686 12.257 28.252 16.735 7.566 4.477 17.582 10.485 22.257 13.351 4.675 2.866 13.19 7.973 18.921 11.348 5.732 3.375 11.158 6.136 12.059 6.136Zm100.681-194.022c2.318.016 3.852-.798 5.75-3.055 1.497-1.78 2.589-4.313 2.589-6.01 0-2.269-.848-3.508-3.75-5.478-2.063-1.4-6.53-4.29-9.927-6.421-3.398-2.132-9.923-6.015-14.5-8.63-4.578-2.614-10.798-6.408-13.823-8.43-3.025-2.022-7.75-4.873-10.5-6.334-2.75-1.462-8.15-4.689-12-7.171-5.023-3.24-7.838-4.434-9.968-4.232-2.1.2-3.65 1.298-5.297 3.75-1.437 2.14-2.215 4.588-2.032 6.391.254 2.498 1.604 3.72 9.297 8.412 4.95 3.02 15.525 9.427 23.5 14.238a3631.896 3631.896 0 0 1 26 15.848c7.807 4.82 12.515 7.107 14.661 7.122Z" style="stroke:#000;stroke-opacity:1;stroke-width:20;stroke-dasharray:none"/>\n <path id="path1" fill="#000" fill-rule="evenodd" stroke="none" d="M479.5 119.5c0 34 0 34-7 34.262-3.85.144-11.275.947-16.5 1.785s-12.533 2.42-16.24 3.514c-3.708 1.095-9.416 3.559-12.686 5.475-3.269 1.916-7.401 4.71-9.183 6.209-1.781 1.499-4.926 5.336-6.988 8.526-2.395 3.706-4.41 8.588-5.576 13.515-1.346 5.684-1.817 11.548-1.79 22.282.023 8.902.749 19.208 1.866 26.5 1.006 6.563 2.964 17.107 4.352 23.432 1.388 6.325 3.152 14.2 3.92 17.5.768 3.3 3.14 14.55 5.272 25s4.816 24.901 5.965 32.114c1.57 9.86 2.088 17.705 2.088 31.622 0 16.395-.284 19.635-2.485 28.386-1.367 5.433-4.299 13.56-6.515 18.061-2.832 5.75-6.265 10.559-11.545 16.172-5.308 5.642-10.516 9.846-17.735 14.316-5.62 3.481-13.145 7.611-16.72 9.179-3.575 1.567-10.739 4.4-15.92 6.293-5.181 1.894-13.506 4.308-18.5 5.365-4.994 1.056-13.58 2.637-19.08 3.513-6.633 1.057-18.754 1.716-36 1.958-14.3.201-30.5.01-36-.424s-15.625-1.537-22.5-2.45c-6.875-.912-16.575-2.328-21.557-3.146-4.98-.817-12.406-2.176-16.5-3.02-4.093-.843-9.693-2.157-12.443-2.92-2.75-.763-7.7-2.083-11-2.932-3.3-.85-10.5-2.648-16-3.996-5.5-1.348-15.85-4.3-23-6.56-7.15-2.261-14.912-4.805-17.25-5.653-2.904-1.055-4.25-2.127-4.25-3.386 0-1.228 3.252-3.97 9.75-8.22 5.363-3.507 13.202-8.277 17.421-10.6 7.671-4.225 7.671-4.225 18.5-1.287 5.956 1.616 19.154 4.998 29.329 7.515 10.175 2.517 23.45 5.465 29.5 6.55 6.05 1.087 15.05 2.427 20 2.98 4.95.552 14.85 1.53 22 2.175 8.107.73 21.657.955 36 .598 13.264-.33 27.021-1.234 32.5-2.135 5.225-.86 14-2.963 19.5-4.673s12.925-4.443 16.5-6.073a870.93 870.93 0 0 0 11.5-5.354c2.75-1.314 7.94-4.836 11.535-7.826 3.888-3.234 7.591-7.403 9.142-10.29 1.433-2.668 3.653-8.143 4.932-12.166 1.934-6.082 2.319-9.415 2.283-19.794-.024-7.149-.774-16.627-1.756-22.186-.943-5.339-2.407-13.531-3.253-18.206-.847-4.675-2.454-12.775-3.572-18-1.118-5.225-3.15-14-4.514-19.5-1.365-5.5-3.5-14.725-4.746-20.5-1.246-5.775-2.995-15-3.886-20.5-.892-5.5-2.081-14.08-2.643-19.068-.562-4.987-1.014-13.987-1.005-20 .01-6.012.652-14.799 1.427-19.525.775-4.726 2.12-11.026 2.988-14 .869-2.974 3.04-8.224 4.824-11.668 1.784-3.443 5.256-9.004 7.715-12.356 2.46-3.353 8.084-8.988 12.5-12.523 4.416-3.534 11.629-8.164 16.029-10.287 4.4-2.124 12.05-5.194 17-6.823 4.95-1.63 14.625-3.757 21.5-4.729s16.1-1.824 20.5-1.894l8-.127Z"/>\n <path id="path2" fill="#B6BCC4" fill-rule="evenodd" stroke="none" d="M116 375.743c-2.73.236-5.372-.8-12-4.708-4.675-2.756-11.133-6.704-14.35-8.773-3.218-2.07-6.48-4.977-7.25-6.462-1.094-2.111-1.4-8.348-1.4-28.56 0-21.125.267-26.213 1.461-27.799 1.43-1.9 1.574-1.879 6.75.986 2.909 1.61 8.214 4.584 11.789 6.61 3.575 2.026 9.1 5.209 12.28 7.073 3.179 1.865 10.253 6.09 15.722 9.39 5.468 3.3 13.836 8.245 18.596 10.989 4.76 2.744 10.736 6.348 13.279 8.01 2.568 1.678 4.753 3.927 4.917 5.062.246 1.716-3.42 4.101-23 14.96-14.766 8.189-24.575 13.03-26.794 13.222Z"/>\n</svg>'.trim(),subtract:'<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill-rule="evenodd" clip-rule="evenodd" d="M15.0722 3.9967L20.7508 9.83395L17.0544 13.5304L13.0758 17.5H21.0041V19H7.93503L4.00195 15.0669L15.0722 3.9967ZM10.952 17.5L15.4628 12.9994L11.8268 9.3634L6.12327 15.0669L8.55635 17.5H10.952Z" fill="#1F2328"></path> </g></svg>\n'.trim(),clone:'<?xml version="1.0" encoding="UTF-8"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">\n <rect x="88" y="88" width="252" height="252" fill="none" stroke="#000" stroke-width="42"/>\n <rect x="172" y="172" width="252" height="252" fill="none" stroke="#000" stroke-width="42"/>\n</svg>'.trim(),p2p:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" id="svg1" width="512" height="512" version="1.1">\n <path id="path7" d="m155.327 480.616 323.962-.033V45.207L32.68 44.87l.24 35.605 411.103-.882-.338 365.995-169.126-.577Z" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8" cx="460.396" cy="461.547" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8-8" cx="460.775" cy="65.834" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8-8-0" cx="67.176" cy="62.815" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <path id="path2" fill="#000" fill-rule="evenodd" stroke="none" d="M78.983 469.63c-2.155.594-4.661-.186-6.416-1.995-1.755-1.81-2.512-4.396-1.937-6.616.52-2.005 2.036-7.54 3.369-12.298 1.333-4.76 4.302-15.274 6.598-23.365 2.295-8.09 6.159-21.33 8.585-29.421a5326.7 5326.7 0 0 0 9.458-32.018c2.775-9.519 6.848-23.538 9.05-31.153a3424.585 3424.585 0 0 1 8.424-28.556c2.432-8.09 5.74-19.445 7.35-25.23 1.61-5.786 4.963-13.271 7.45-16.634 3.196-4.319 8.828-8.134 19.19-12.998 8.067-3.787 22.221-10.287 31.454-14.445 9.232-4.158 20.186-9.16 24.34-11.116a766.22 766.22 0 0 1 15.108-6.874c4.154-1.824 8.5-4.181 9.657-5.238 1.675-1.53 1.537-3.405-.681-9.226-2.27-5.96-2.436-8.498-.898-13.779 1.221-4.19 5.936-10.614 13.373-18.217 6.772-6.923 13.882-12.502 17.322-13.59 4.562-1.444 7.103-1.28 11.648.752 3.426 1.532 23.389 20.759 48.618 46.826 23.543 24.325 45.072 47.061 47.841 50.525 3.873 4.843 5.036 8.022 5.036 13.76 0 6.664-.988 8.548-9.232 17.594-5.078 5.572-11.81 12.267-14.959 14.876-4.16 3.448-7.614 4.745-12.635 4.745-3.801 0-8.653-1.259-10.783-2.797-2.18-1.574-4.506-2.141-5.322-1.298-.797.824-5.186 10.455-9.754 21.402a5146.966 5146.966 0 0 1-15.335 36.316c-3.866 9.027-10.026 22.886-13.689 30.798-4.617 9.975-8.217 15.361-11.743 17.572-2.796 1.753-10.879 5.156-17.961 7.562-7.083 2.406-20.431 6.749-29.664 9.65-9.232 2.902-25.661 8.033-36.509 11.403-10.847 3.37-31.242 9.76-45.323 14.201-14.08 4.44-32.777 10.286-41.547 12.99-8.771 2.704-17.539 5.355-19.483 5.892zm33.106-25.66c3.124-.525 14.558-3.756 25.407-7.18 10.85-3.424 33.511-10.53 50.36-15.791a27689.101 27689.101 0 0 1 50.776-15.803c14.114-4.37 21.467-7.596 24.568-10.778 2.433-2.497 8.003-13.108 12.378-23.578 4.374-10.471 10.397-24.88 13.384-32.018 2.987-7.14 8.327-19.6 11.866-27.691 3.54-8.091 6.71-17.047 7.046-19.903.555-4.717-2.161-8.042-29.692-36.345-16.667-17.133-31.78-31.396-33.584-31.694-1.804-.298-24.636 9.269-50.737 21.259-26.102 11.99-49.09 23.383-51.087 25.316-1.997 1.934-4.862 7.745-6.369 12.914a7969.157 7969.157 0 0 0-7.086 24.55 5161.998 5161.998 0 0 1-9.204 31.594c-2.67 9.043-9.076 30.85-14.234 48.46-5.158 17.609-10.028 34.72-10.822 38.026-.794 3.304-1.129 6.334-.743 6.731.385.397 3.176-1.24 6.202-3.637 3.026-2.397 17.965-17.532 33.199-33.633 15.233-16.1 31.64-33.573 36.46-38.83 8.522-9.292 8.717-9.73 7.063-15.905-1.163-4.344-1.143-8.487.066-13.114 1.094-4.191 4.275-9.1 8.364-12.909 3.648-3.398 9.265-6.662 12.561-7.3 4.51-.872 7.9-.158 13.92 2.932 4.845 2.486 9.223 6.36 11.188 9.9 1.776 3.2 3.3 9.202 3.385 13.339.09 4.285-1.167 10.058-2.921 13.416-1.693 3.242-6.11 7.651-9.814 9.798-5.669 3.285-8.24 3.73-16.226 2.804-9.49-1.099-9.49-1.099-49.778 40.478-22.158 22.867-40.577 42.47-40.932 43.56-.438 1.349 1.175 1.679 5.036 1.031zm90.33-98.225c3.355 0 6.06-1.502 8.524-4.733 2.602-3.409 3.338-6.138 2.634-9.765-.537-2.768-2.295-6.065-3.908-7.327-1.612-1.262-5.138-2.32-7.835-2.35-2.697-.03-6.285 1.234-7.974 2.81-1.808 1.687-3.07 5.242-3.07 8.653 0 3.481 1.339 7.169 3.358 9.25 1.846 1.904 5.568 3.462 8.271 3.462zm133.61-53.652c1.976 0 7.955-4.72 14.175-11.19 10.066-10.471 10.62-11.455 8.624-15.3-1.174-2.262-22.067-24.651-46.43-49.755-28.883-29.764-45.482-45.645-47.707-45.645-1.918 0-7.85 4.523-13.542 10.323-7.359 7.498-9.997 11.39-9.645 14.229.303 2.438 17.518 21.468 45.796 50.622 29.62 30.538 46.495 46.716 48.73 46.716z" style="stroke:#010101;stroke-width:17.0446;stroke-dasharray:none;stroke-opacity:1"/>\n <path id="path3" d="m243.547 189.376 16.458-15.442 96.745 96.717-16.459 16.256z" style="fill:green;fill-opacity:1;stroke:none;stroke-width:18.6862;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path9" cx="201.178" cy="332.215" r="13.593" style="fill:#fff;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n</svg>'.trim(),p2pSubtract:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" id="svg1" width="512" height="512" version="1.1">\n <path id="path2" fill="#000" fill-rule="evenodd" stroke="none" d="M193.812 478.594c-90.053.005-55.415-.21-62.995-.883-3.109-.277-27.11-21.644-46.82-41.478-19.71-19.834-38.405-39.3-41.545-43.255-3.14-3.957-6.62-10.716-7.734-15.02-1.731-6.696-1.64-9.153.633-17.007 2.63-9.085 3.646-10.163 97.355-103.187 67.82-67.324 96.742-95.006 101.9-97.53 4.693-2.298 10.024-3.498 15.308-3.447 5.932.057 10.337 1.334 16.417 4.757 5.373 3.027 23.906 20.087 52.456 48.29 24.281 23.987 46.739 47.413 49.906 52.058 4.533 6.648 5.893 10.36 6.393 17.444.536 7.598-.072 10.288-3.907 17.275-3.191 5.814-24.3 28.163-70.958 75.126-36.529 36.767-66.373 67.623-66.926 68.174-19.83 19.71-39.71 38.183-39.483 38.683zm84.581-137.331c-68.043-67.49-88.703-86.892-89.81-86.657-1.106.234-27.946 26.117-59.643 57.517-31.698 31.4-57.439 57.94-57.202 58.977.236 1.037 15.757 17.272 34.492 36.078 34.062 34.193 34.062 34.193 53.6 34.193 19.536 0 19.536 0 55.274-35.285 19.656-19.407 41.937-41.932 49.514-50.054zm60.94-60.024c-66.9-66.62-87.289-86.356-88.469-86.837-1.29-.527-8.787 5.684-18.813 15.585l-16.668 16.46 44.408 44.028c24.425 24.215 44.787 44.027 45.249 44.027.461 0 8.366-7.484 17.566-16.632z" style="stroke-width:1.5931"/>\n <path id="path3" d="m214.604 225.766 35.345-32.835 89.308 87.873-34.083 33.773z" style="fill:maroon;fill-opacity:1;stroke:#010101;stroke-width:7.48758"/>\n <path id="path7" d="m238.705 480.616 240.584-.033V45.207L32.68 44.87l.24 35.605 411.103-.882-.338 365.995-169.126-.577Z" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8" cx="460.396" cy="461.547" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8-8" cx="460.775" cy="65.834" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8-8-0" cx="67.176" cy="62.815" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n</svg>'.trim(),erase:'<?xml version="1.0" encoding="utf-8"?>\n<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" id="Layer_1" x="0" y="0" style="enable-background:new 0 0 48 48" version="1.1" viewBox="0 0 48 48">\n <style>\n .st0{fill:#000}\n </style>\n <path d="M0 0h48v48H0z" style="fill:#333;fill-opacity:0"/>\n <path d="M26.6 10V7.8h-5.2V10h-8.8v2.8h22.8V10zM35.4 15.4H12.6v4.3h1.8V37c0 1.1.9 2 2 2h15.2c1.1 0 2-.9 2-2V19.7h1.8v-4.3zM19.7 34.2c0 .5-.4 1-1 1-.5 0-1-.4-1-1V22.6c0-.5.4-1 1-1 .5 0 1 .4 1 1v11.6zm5.6-.4c0 .7-.6 1.3-1.3 1.3-.7 0-1.3-.6-1.3-1.3V23c0-.7.6-1.3 1.3-1.3.7 0 1.3.6 1.3 1.3v10.8zm5 .4c0 .5-.4 1-1 1-.5 0-1-.4-1-1V22.6c0-.5.4-1 1-1 .5 0 1 .4 1 1v11.6z" class="st0"/>\n</svg>'.trim(),collapse:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512">\n <path d="m80.033 292.15 175.755-174.592 175.755 174.591" style="fill:none;stroke:#000;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <path d="M80.105 394.539 255.86 219.947 431.615 394.54" style="fill:none;stroke:#000;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n</svg>'.trim(),undo:'<?xml version="1.0" encoding="utf-8"?>\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 48 48" xml:space="preserve">\n<style type="text/css">\n\t.st0{fill:none;stroke:#000000;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;}\n</style>\n<g>\n\t<path class="st0" d="M14,18h10c6.6,0,12,5.4,12,12s-5.4,12-12,12s-12-5.4-12-12"/>\n\t<polyline class="st0" points="18,14 14,18 18,22"/>\n</g>\n</svg>\n'.trim(),redo:'<?xml version="1.0" encoding="utf-8"?>\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 48 48" xml:space="preserve">\n<style type="text/css">\n\t.st0{fill:none;stroke:#000000;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;}\n</style>\n<g>\n\t<path class="st0" d="M34,18H24C17.4,18,12,23.4,12,30s5.4,12,12,12s12-5.4,12-12"/>\n\t<polyline class="st0" points="30,14 34,18 30,22"/>\n</g>\n</svg>\n'.trim()},$o=(t,e)=>{Zo(t,e)};class Qo{static getCenter(t){let e=0,n=0,i=0;t.forEach(t=>{let r=t.lat,o=t.lng;r*=p,o*=p,e+=Math.cos(r)*Math.cos(o),n+=Math.cos(r)*Math.sin(o),i+=Math.sin(r)});let r=Math.atan2(n,e);const o=Math.sqrt(e*e+n*n);let s=Math.atan2(i,o);s*=y,r*=y;return{lat:s,lng:r}}static getSouthWest(t){return this.getBounds(t).getSouthWest()}static getNorthEast(t){return this.getBounds(t).getNorthEast()}static getNorthWest(t){return this.getBounds(t).getNorthWest()}static getSouthEast(t){return this.getBounds(t).getSouthEast()}static getNorth(t){return this.getBounds(t).getNorth()}static getSouth(t){return this.getBounds(t).getSouth()}static getWest(t){return this.getBounds(t).getWest()}static getEast(t){return this.getBounds(t).getEast()}static getSqmArea(t){const e=new a.Polygon(t).toGeoJSON();return this.turfHelper.getPolygonArea(e)}static getPerimeter(t){const e=new a.Polygon(t).toGeoJSON();return 1e3*this.turfHelper.getPolygonPerimeter(e)}static getPolygonChecksum(t){const e=t.filter((t,e,n)=>{const i=n.find(e=>e.lat===t.lat&&e.lng===t.lng);return!!i&&n.indexOf(i)===e});return e.reduce((t,e)=>+t+ +e.lat,0)*e.reduce((t,e)=>+t+ +e.lng,0)}static getMidPoint(t,e){const n=this.turfHelper.getMidpoint(t,e);return{lat:n.lat,lng:n.lng}}static getBounds(t){const e=[];t.forEach(t=>{isNaN(t.lat)||isNaN(t.lng),e.push(t)});return new a.Polyline(e).getBounds()}static getCenterOfMass(t){const e=this.turfHelper.getCenterOfMass(t);return{lat:e.geometry.coordinates[1],lng:e.geometry.coordinates[0]}}static getCenterOfPolygonByIndexWithOffsetFromCenterOfMass(t,e){const n=this.turfHelper.getCenterOfMass(t),i={lat:n.geometry.coordinates[1],lng:n.geometry.coordinates[0]},r=this.getPolygonLatLngAtIndex(t,e)??i,o=r.lat-i.lat,s=r.lng-i.lng,a={geometry:{coordinates:[i.lng+.5*s,i.lat+.5*o]}};return{lat:a.geometry.coordinates[1],lng:a.geometry.coordinates[0]}}static getPolygonLatLngAtIndex(t,e){const n=t.geometry;if(!n)return null;let i;if("Polygon"===n.type)i=n.coordinates[0];else{if("MultiPolygon"!==n.type)return null;i=n.coordinates[0][0]}if(!i||0===i.length)return null;if(i.length>1){const t=i[0],e=i[i.length-1];t[0]===e[0]&&t[1]===e[1]&&(i=i.slice(0,i.length-1))}if(0===i.length)return null;const r=i[(e%i.length+i.length)%i.length];return{lat:r[1],lng:r[0]}}}o(Qo,"turfHelper",new Vo(c));class ts{constructor(t){if(o(this,"polygon",[]),o(this,"trashcanPoint",[]),o(this,"sqmArea",[]),o(this,"perimeter",[]),!Array.isArray(t))return;if(t.length>0&&Array.isArray(t[0])&&t[0].length>0&&"object"==typeof t[0][0]&&"lat"in t[0][0]){const e=t[0];return this.trashcanPoint[0]=this.getTrashcanPoint(e),this.sqmArea[0]=this.calculatePolygonArea(e),this.perimeter[0]=this.calculatePolygonPerimeter(e),void(this.polygon[0]=[e])}if(t.length>0&&t[0]&&"object"==typeof t[0]&&"lat"in t[0]){const e=t,n=[[e]];return this.trashcanPoint[0]=this.getTrashcanPoint(e),this.sqmArea[0]=this.calculatePolygonArea(e),this.perimeter[0]=this.calculatePolygonPerimeter(e),void(this.polygon[0]=n[0])}t.forEach((t,e)=>{t&&Array.isArray(t)&&t[0]&&Array.isArray(t[0])&&(this.trashcanPoint[e]=this.getTrashcanPoint(t[0]),this.sqmArea[e]=this.calculatePolygonArea(t[0]),this.perimeter[e]=this.calculatePolygonPerimeter(t[0]),this.polygon[e]=t)})}setSqmArea(t){this.sqmArea[0]=t}getTrashcanPoint(t){if(!Array.isArray(t)||0===t.length)return console.warn("getTrashcanPoint: Invalid polygon array:",t),{lat:0,lng:0};const e=t.filter(t=>t&&"object"==typeof t&&"number"==typeof t.lat&&"number"==typeof t.lng&&!isNaN(t.lat)&&!isNaN(t.lng));if(0===e.length)return console.warn("getTrashcanPoint: No valid coordinates found:",t),{lat:0,lng:0};const n=Math.max(...e.map(t=>t.lat)),i=e.findIndex(t=>t.lat===n);if(-1===i)return console.warn("getTrashcanPoint: Could not find max lat coordinate"),{lat:0,lng:0};let r,o;if(i>0?(r=e[i-1],o=i<e.length-1?e[i+1]:e[0]):(r=e[e.length-1],o=e[i+1]),!r||!o)return console.warn("getTrashcanPoint: Could not determine previous/next points"),e[i]||{lat:0,lng:0};const s=r.lng<o.lng?r:o;return Qo.getMidPoint(e[i],s)}calculatePolygonArea(t){return Qo.getSqmArea(t)}calculatePolygonPerimeter(t){return Qo.getPerimeter(t)}}class es{constructor(t){o(this,"polygonInfoListeners",[]),o(this,"polygonDrawStateListeners",[]),o(this,"polygonInformationStorage",[]),this.mapStateService=t}onPolygonInfoUpdated(t){this.polygonInfoListeners.push(t)}emitPolygonInfoUpdated(){for(const t of this.polygonInfoListeners)t(this.polygonInformationStorage)}onPolygonDrawStateUpdated(t){this.polygonDrawStateListeners.push(t)}updatePolygons(){const t=[];this.polygonInformationStorage.length>0&&this.polygonInformationStorage.forEach(e=>{const n=[];e.polygon.forEach(t=>{t.forEach(t=>{const e=[...t];t.length>0&&t[0].toString()!==t[t.length-1].toString()&&e.push(t[0]),n.push(e)})}),t.push(n)}),this.mapStateService.updatePolygons(t),this.saveCurrentState()}saveCurrentState(){this.emitPolygonInfoUpdated()}deleteTrashcan(t){const e=this.polygonInformationStorage.findIndex(e=>e.polygon[0]===t);-1!==e&&(this.polygonInformationStorage.splice(e,1),this.updatePolygons())}deleteTrashCanOnMulti(t){let e=0;this.polygonInformationStorage.forEach((n,i)=>{const r=n.polygon.findIndex(e=>e.toString()===t.toString());r>=0&&(e=i,n.trashcanPoint.splice(r,1),n.sqmArea.splice(r,1),n.perimeter.splice(r,1),n.polygon.splice(r,1))}),this.updatePolygons(),this.polygonInformationStorage.length>1&&this.polygonInformationStorage.splice(e,1)}deletePolygonInformationStorage(){this.polygonInformationStorage=[]}createPolygonInformationStorage(t){t.length>0&&(t.forEach(t=>{var e;const n=null==(e=t.getLayers)?void 0:e.call(t);if(null==n?void 0:n[0]){const t=n[0].getLatLngs(),e=new ts(t);this.polygonInformationStorage.push(e)}}),this.updatePolygons())}}class ns{constructor(){o(this,"map",null),o(this,"mapListeners",[])}onMapUpdated(t){this.map&&t(this.map),this.mapListeners.push(t)}emitMapUpdated(){if(this.map)for(const t of this.mapListeners)t(this.map)}updateMapState(t){this.map=t,this.emitMapUpdated()}updatePolygons(t){}}class is{constructor(){o(this,"eventListeners",new Map)}on(t,e){this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e)}off(t,e){const n=this.eventListeners.get(t);if(n){const t=n.indexOf(e);t>-1&&n.splice(t,1)}}emit(t,e){var n;this.eventListeners.has(t)&&(null==(n=this.eventListeners.get(t))||n.forEach(t=>{t(e)}))}}class rs{constructor(t,e){o(this,"state"),o(this,"config"),o(this,"eventManager"),this.config=t,this.eventManager=e,this.state=this.createInitialState()}createInitialState(){return{polygonDragging:this.config.modes.dragPolygons??!1,markerDragging:this.config.modes.dragElbow??!1,edgeClicking:!0,polygonClicking:!0,canStartDrawing:!0,canCompletePolygon:!1,mapDragging:!0,mapZooming:!0,mapDoubleClickZoom:!0,currentMode:u.Off,isDrawingActive:!1,isModifierKeyHeld:!1,showCrosshairCursor:!1,showDragCursor:!1}}updateStateForMode(t){switch(this.state.currentMode=t,t){case u.Off:this.setOffModeState();break;case u.Add:case u.Subtract:this.setDrawingModeState();break;case u.PointToPoint:case u.PointToPointSubtract:this.setPointToPointModeState();break;case u.Clone:this.setCloneModeState()}this.state.isDrawingActive=t!==u.Off&&t!==u.Clone,this.eventManager.emit("polydraw:mode:change",{mode:t})}setOffModeState(){this.state.polygonDragging=this.config.modes.dragPolygons??!1,this.state.markerDragging=this.config.modes.dragElbow??!1,this.state.edgeClicking=!0,this.state.polygonClicking=!0,this.state.canStartDrawing=!0,this.state.canCompletePolygon=!1,this.state.mapDragging=!0,this.state.mapZooming=!0,this.state.mapDoubleClickZoom=!0,this.state.showCrosshairCursor=!1,this.state.showDragCursor=!1}setDrawingModeState(){this.state.polygonDragging=!1,this.state.markerDragging=!1,this.state.edgeClicking=!1,this.state.polygonClicking=!1,this.state.canStartDrawing=!0,this.state.canCompletePolygon=!0,this.state.mapDragging=!1,this.state.mapZooming=!1,this.state.mapDoubleClickZoom=!1,this.state.showCrosshairCursor=!0,this.state.showDragCursor=!1}setPointToPointModeState(){this.state.polygonDragging=!1,this.state.markerDragging=!1,this.state.edgeClicking=!1,this.state.polygonClicking=!1,this.state.canStartDrawing=!0,this.state.canCompletePolygon=!0,this.state.mapDragging=!1,this.state.mapZooming=!1,this.state.mapDoubleClickZoom=!1,this.state.showCrosshairCursor=!0,this.state.showDragCursor=!1}setCloneModeState(){this.state.polygonDragging=this.config.modes.clonePolygons??!1,this.state.markerDragging=!1,this.state.edgeClicking=!1,this.state.polygonClicking=!1,this.state.canStartDrawing=!1,this.state.canCompletePolygon=!1,this.state.mapDragging=!0,this.state.mapZooming=!0,this.state.mapDoubleClickZoom=!0,this.state.showCrosshairCursor=!1,this.state.showDragCursor=!0}setModifierKeyState(t){this.state.isModifierKeyHeld=t,this.state.currentMode,u.Off}canPerformAction(t){switch(t){case"polygonDrag":return this.state.polygonDragging;case"markerDrag":return this.state.markerDragging;case"edgeClick":return this.state.edgeClicking;case"polygonClick":return this.state.polygonClicking;case"startDrawing":return this.state.canStartDrawing;case"completePolygon":return this.state.canCompletePolygon;case"mapDrag":return this.state.mapDragging;case"mapZoom":return this.state.mapZooming;case"mapDoubleClickZoom":return this.state.mapDoubleClickZoom;default:return!1}}isInDrawingMode(){return this.state.isDrawingActive}isInOffMode(){return this.state.currentMode===u.Off}getCurrentMode(){return this.state.currentMode}getState(){return{...this.state}}shouldShowCrosshairCursor(){return this.state.showCrosshairCursor}shouldShowDragCursor(){return this.state.showDragCursor}updateConfig(t){this.config=t,this.updateStateForMode(this.state.currentMode)}}class os{constructor(t){o(this,"turfHelper"),o(this,"map"),o(this,"config"),o(this,"modeManager"),o(this,"eventManager"),o(this,"tracer"),o(this,"p2pMarkers",[]),o(this,"isModifierKeyHeld",!1),o(this,"markerModifierHandlers",new WeakMap),this.turfHelper=t.turfHelper,this.map=t.map,this.config=t.config,this.modeManager=t.modeManager,this.eventManager=t.eventManager,this.tracer=t.tracer}mouseMove(t){if("latlng"in t&&t.latlng)this.tracer.addLatLng(t.latlng);else if("touches"in t&&t.touches&&t.touches.length>0){const e=this.map.getContainer().getBoundingClientRect(),n=this.map.containerPointToLatLng([t.touches[0].clientX-e.x,t.touches[0].clientY-e.y]);this.tracer.addLatLng(n)}}async mouseUpLeave(t){const e=this.tracer.toGeoJSON();if(!e||!e.geometry||!e.geometry.coordinates||e.geometry.coordinates.length<3)return{success:!1,error:"Not enough points to form a valid polygon. Event: "+JSON.stringify(t)};let n;try{n=this.turfHelper.createPolygonFromTrace(e)}catch(i){return{success:!1,error:(i instanceof Error?i.message:"Failed to create polygon from trace")+". Event: "+JSON.stringify(t)}}return n&&n.geometry&&n.geometry.coordinates&&0!==n.geometry.coordinates.length?(this.eventManager.emit("polydraw:polygon:created",{polygon:n,mode:this.modeManager.getCurrentMode()}),{success:!0,polygon:n}):{success:!1,error:"Invalid polygon created from trace. Event: "+JSON.stringify(t)}}setModifierKey(t){this.isModifierKeyHeld=t}shouldAllowP2PMarkerDeletion(){if(!this.isModifierKeyHeld||!this.config.modes.edgeDeletion)return!1;if(this.config.modifierSubtractMode){const t=this.modeManager.getCurrentMode();if(t===u.PointToPoint||t===u.PointToPointSubtract)return!1}return!0}handlePointToPointClick(t){if(t){if(this.p2pMarkers.length>=3){const e=this.p2pMarkers[0].getLatLng();if(this.isClickingFirstPoint(t,e))return void this.completePointToPointPolygon()}try{const e=0===this.p2pMarkers.length,n=e?"leaflet-polydraw-p2p-marker leaflet-polydraw-p2p-first-marker":"leaflet-polydraw-p2p-marker",i=new a.Marker(t,{icon:Wo.createDivIcon({className:n,iconSize:e?[20,20]:[16,16]}),draggable:this.config.modes.dragElbow}).addTo(this.map);i.on("mousedown",t=>{a.DomEvent.stopPropagation(t)}),i.on("drag",()=>{this.updateP2PTracer()}),i.on("click",t=>{this.shouldAllowP2PMarkerDeletion()&&(this.deleteP2PMarker(i),a.DomEvent.stopPropagation(t))}),i.on("mouseover",()=>this.onMarkerHoverForEdgeDeletion(i,!0)),i.on("mouseout",()=>this.onMarkerHoverForEdgeDeletion(i,!1)),e&&(i.on("mouseover",()=>{if(this.p2pMarkers.length>=3){const t=i.getElement();t&&(t.style.backgroundColor=this.config.colors.p2p.closingMarker,t.style.borderColor=this.config.colors.p2p.closingMarker,t.style.cursor="pointer",t.title="Click to close polygon")}}),i.on("mouseout",()=>{const t=i.getElement();t&&(t.style.backgroundColor="",t.style.borderColor="",t.style.cursor="",t.title="")}),i.on("click",t=>{if(this.shouldAllowP2PMarkerDeletion())return this.deleteP2PMarker(i),void a.DomEvent.stopPropagation(t);this.p2pMarkers.length>=3&&(a.DomEvent.stopPropagation(t),this.completePointToPointPolygon())})),this.p2pMarkers.push(i),this.updateP2PTracer(),this.updateFirstMarkerReadyState()}catch{}}}handleDoubleClick(t){this.modeManager.getCurrentMode()!==u.PointToPoint&&this.modeManager.getCurrentMode()!==u.PointToPointSubtract||this.p2pMarkers.length>=3&&this.completePointToPointPolygon()}handleDoubleTap(t){this.modeManager.getCurrentMode()!==u.PointToPoint&&this.modeManager.getCurrentMode()!==u.PointToPointSubtract||this.p2pMarkers.length>=3&&this.completePointToPointPolygon()}completePointToPointPolygon(){const t=this.p2pMarkers.map(t=>t.getLatLng());if(t.length<3)return;const e=[...t],n=t[0],i=t[t.length-1];n.lat===i.lat&&n.lng===i.lng||e.push(n);try{const t=e.map(t=>[t.lng,t.lat]),n=this.turfHelper.getMultiPolygon([[t]]);this.clearP2pMarkers(),this.resetTracer(),this.eventManager.emit("polydraw:polygon:created",{polygon:n,mode:this.modeManager.getCurrentMode(),isPointToPoint:!0})}catch(r){Ho()||console.warn("Error completing point-to-point polygon:",r),this.clearP2pMarkers(),this.resetTracer()}}cancelPointToPointDrawing(){this.clearP2pMarkers(),this.resetTracer(),this.eventManager.emit("polydraw:draw:cancel",{mode:u.PointToPoint})}clearP2pMarkers(){this.p2pMarkers.forEach(t=>this.map.removeLayer(t)),this.p2pMarkers=[]}resetTracer(){this.tracer.setLatLngs([]);try{this.tracer.setStyle({dashArray:void 0})}catch{}}isClickingFirstPoint(t,e){if(!e)return!1;const n=this.map.latLngToLayerPoint(t),i=this.map.latLngToLayerPoint(e);return n.distanceTo(i)<=(this.isTouchDevice()?24:12)}isTouchDevice(){return zo()}updateP2PTracer(){const t=this.p2pMarkers.map(t=>t.getLatLng());if(this.tracer.setLatLngs(t),this.p2pMarkers.length>=2)try{const t=this.modeManager.getCurrentMode()===u.PointToPointSubtract?this.config.colors.subtractLine:this.config.colors.polyline;this.tracer.setStyle({color:t,dashArray:"5, 5"})}catch{}else try{this.tracer.setStyle({dashArray:void 0})}catch{}}deleteP2PMarker(t){const e=this.p2pMarkers.findIndex(e=>e===t);e>-1&&(this.p2pMarkers.splice(e,1),this.map.removeLayer(t),this.updateP2PTracer(),0===e&&this.p2pMarkers.length>0&&this.setupFirstMarker(),this.updateFirstMarkerReadyState())}getP2pMarkers(){return[...this.p2pMarkers]}isInPointToPointMode(){const t=this.modeManager.getCurrentMode();return t===u.PointToPoint||t===u.PointToPointSubtract}getTracerPointsCount(){return this.tracer.getLatLngs().length}setupFirstMarker(){if(0===this.p2pMarkers.length)return;const t=this.p2pMarkers[0],e=t.getElement();e&&(e.classList.add("leaflet-polydraw-p2p-first-marker"),e.classList.remove("leaflet-polydraw-p2p-first-marker-ready"),t.setIcon(Wo.createDivIcon({className:"leaflet-polydraw-p2p-marker leaflet-polydraw-p2p-first-marker",iconSize:[20,20]}))),t.off("mouseover"),t.off("mouseout"),t.off("click"),t.on("mouseover",()=>{if(this.p2pMarkers.length>=3){const e=t.getElement();e&&(e.style.cursor="pointer",e.title="Click to close polygon")}}),t.on("mouseout",()=>{const e=t.getElement();e&&(e.style.backgroundColor="",e.style.borderColor="",e.style.cursor="",e.title="")}),t.on("click",e=>{if(this.shouldAllowP2PMarkerDeletion())return this.deleteP2PMarker(t),void a.DomEvent.stopPropagation(e);this.p2pMarkers.length>=3&&(a.DomEvent.stopPropagation(e),this.completePointToPointPolygon())})}updateFirstMarkerReadyState(){if(0===this.p2pMarkers.length)return;const t=this.p2pMarkers[0].getElement();t&&(this.p2pMarkers.length>=3?(t.classList.add("leaflet-polydraw-p2p-first-marker-ready"),t.setAttribute("data-p2p-mode",this.modeManager.getCurrentMode()===u.PointToPointSubtract?"subtract":"add"),t.style.cursor="pointer",t.title="Click to close polygon"):(t.classList.remove("leaflet-polydraw-p2p-first-marker-ready"),t.removeAttribute("data-p2p-mode"),t.style.cursor="",t.removeAttribute("title")))}refreshP2PMarkerState(){0!==this.p2pMarkers.length&&this.updateFirstMarkerReadyState()}onMarkerHoverForEdgeDeletion(t,e){const n=t.getElement();if(n)if(e){const e=t=>{if(this.shouldAllowP2PMarkerDeletion()){n.classList.add("edge-deletion-hover");try{this.map.getContainer().style.cursor="pointer"}catch{}}else{n.classList.remove("edge-deletion-hover");try{this.map.getContainer().style.cursor=""}catch{}}};this.markerModifierHandlers.set(t,e),document.addEventListener("keydown",e),document.addEventListener("keyup",e),n.addEventListener("mousemove",e)}else{n.classList.remove("edge-deletion-hover");try{this.map.getContainer().style.cursor=""}catch{}const e=this.markerModifierHandlers.get(t);e&&(document.removeEventListener("keydown",e),document.removeEventListener("keyup",e),n.removeEventListener("mousemove",e),this.markerModifierHandlers.delete(t))}}}class ss{constructor(t){o(this,"turfHelper"),o(this,"config"),this.turfHelper=t.turfHelper,this.config=t.config}checkPolygonIntersection(t,e){if(this.isPolygonInsideHole(t,e)||this.isPolygonInsideHole(e,t))return!1;try{const n=this.turfHelper.isPolygonCompletelyWithin(t,e),i=this.turfHelper.isPolygonCompletelyWithin(e,t);if(n||i)return!0}catch{}try{if(this.turfHelper.polygonIntersect(t,e))return!0}catch{}try{const n=this.turfHelper.getIntersection(t,e);if(n&&n.geometry&&("Polygon"===n.geometry.type||"MultiPolygon"===n.geometry.type)){if(this.turfHelper.getPolygonArea(n)>1e-6)return!0}}catch{}try{const n=this.turfHelper.getCoords(t),i=this.turfHelper.getCoords(e);for(const e of i)for(const n of e[0]){const e={type:"Feature",geometry:{type:"Point",coordinates:n},properties:{}};if(this.turfHelper.isPointInsidePolygon(e,t))return!0}for(const t of n)for(const n of t[0]){const t={type:"Feature",geometry:{type:"Point",coordinates:n},properties:{}};if(this.turfHelper.isPointInsidePolygon(t,e))return!0}}catch{}return!1}isPolygonInsideHole(t,e){try{const n=this.turfHelper.getCoords(e);for(const e of n){if(!e||e.length<=1)continue;const n=e.slice(1);for(const e of n)try{const n=this.turfHelper.createPolygon([e]);if(this.turfHelper.isPolygonCompletelyWithin(t,n))return!0}catch{continue}}}catch{}return!1}unionPolygons(t,e){try{let n=e;for(const e of t){const t=this.turfHelper.union(n,e);t&&(n=t)}return{success:!0,result:n}}catch(n){return{success:!1,error:n instanceof Error?n.message:"Unknown error in unionPolygons"}}}subtractPolygon(t,e){try{const n=this.turfHelper.polygonDifference(t,e);if(n){const t=this.turfHelper.getCoords(n),e=[];for(const n of t)e.push(this.turfHelper.getMultiPolygon([n]));return{success:!0,results:e}}return{success:!0,results:[]}}catch(n){return{success:!1,error:n instanceof Error?n.message:"Unknown error in subtractPolygon"}}}simplifyPolygon(t){var e,n;try{const i=this.turfHelper.getCoords(t);if(!i||0===i.length)return{success:!1,error:"Invalid polygon coordinates"};const r=(null==(n=null==(e=this.config.menuOperations)?void 0:e.simplify)?void 0:n.processHoles)??!0,o=i.map(t=>{const e=[];for(let n=0;n<t.length;n++){const i=t[n];if(0===n||r){if(i.length<=4){e.push(i);continue}const t=[];for(let e=0;e<i.length;e+=2)t.push(i[e]);const n=t[0],r=t[t.length-1];n[0]===r[0]&&n[1]===r[1]||t.push(n),t.length<4?e.push(i):e.push(t)}else e.push(i)}return e}),s=this.turfHelper.getMultiPolygon(o);return{success:!0,result:this.turfHelper.getTurfPolygon(s)}}catch(i){return{success:!1,error:i instanceof Error?i.message:"Unknown error in simplifyPolygon"}}}convertToBoundingBox(t){var e,n,i;try{const r=this.turfHelper.getCoords(t);if(!r||0===r.length)return{success:!1,error:"Invalid polygon coordinates"};if(!((null==(n=null==(e=this.config.menuOperations)?void 0:e.bbox)?void 0:n.processHoles)??!0)){const e=this.turfHelper.convertToBoundingBoxPolygon(t);return{success:!0,result:this.turfHelper.getTurfPolygon(e)}}const o=r.map(t=>{const e=[];for(let n=0;n<t.length;n++){const i=t[n];let r=1/0,o=-1/0,s=1/0,a=-1/0;for(const t of i)if(Array.isArray(t)&&t.length>=2){const e=t[0],n=t[1];"number"!=typeof e||"number"!=typeof n||isNaN(e)||isNaN(n)||(s=Math.min(s,e),a=Math.max(a,e),r=Math.min(r,n),o=Math.max(o,n))}if(r!==1/0&&o!==-1/0&&s!==1/0&&a!==-1/0){const t=[[s,r],[s,o],[a,o],[a,r],[s,r]];e.push(t)}else e.push(i)}return e}),s=this.turfHelper.getMultiPolygon(o);let a=this.turfHelper.getTurfPolygon(s);if(null==(i=this.config.boundingBox)?void 0:i.addMidPointMarkers){const t=this.doubleElbowsPolygon(a);t.success&&t.result&&(a=t.result)}return{success:!0,result:a}}catch(r){return{success:!1,error:r instanceof Error?r.message:"Unknown error in convertToBoundingBox"}}}bezierifyPolygon(t){try{const e=this.turfHelper.getCoords(t),n=this.turfHelper.getBezierMultiPolygon(e);return{success:!0,result:this.turfHelper.getTurfPolygon(n)}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Unknown error in bezierifyPolygon"}}}doubleElbowsPolygon(t){var e,n;try{const i=this.turfHelper.getCoords(t);if(!i||0===i.length)return{success:!1,error:"Invalid polygon coordinates"};const r=(null==(n=null==(e=this.config.menuOperations)?void 0:e.doubleElbows)?void 0:n.processHoles)??!0,o=i.map(t=>{const e=[];for(let n=0;n<t.length;n++){const i=t[n];if(0===n||r){const t=i.map(t=>({lat:t[1],lng:t[0]})),n=this.turfHelper.getDoubleElbowLatLngs(t).map(t=>[t.lng,t.lat]);e.push(n)}else e.push(i)}return e}),s=this.turfHelper.getMultiPolygon(o);return{success:!0,result:this.turfHelper.getTurfPolygon(s)}}catch(i){return{success:!1,error:i instanceof Error?i.message:"Unknown error in doubleElbowsPolygon"}}}}class as{static createDivIcon(t){const e=t.join(" ");return Wo.createDivIcon({className:e})}}var ls=(t=>(t.TopLeft="top-left",t.Top="top",t.TopRight="top-right",t.Right="right",t.BottomRight="bottom-right",t.Bottom="bottom",t.BottomLeft="bottom-left",t.Left="left",t.Rotate="rotate",t.Pivot="pivot",t))(ls||{});class us{constructor(t,e,n,i,r){var s;o(this,"map"),o(this,"pane"),o(this,"root"),o(this,"draggingHandle",null),o(this,"documentMoveHandler",null),o(this,"documentUpHandler",null),o(this,"pointerCaptureTarget",null),o(this,"activePointerId",null),o(this,"callbacks"),o(this,"rafId",null),o(this,"mode"),o(this,"onCancel"),o(this,"onConfirm"),o(this,"cancelBtn",null),o(this,"confirmBtn",null),o(this,"currentBBox",null),o(this,"currentRotation",0),o(this,"buttonsHidden",!1),o(this,"supportsPointerEvents","undefined"!=typeof window&&"PointerEvent"in window),this.map=t,this.callbacks=e,this.mode=n,this.onCancel=i,this.onConfirm=r;const a="polydraw-transform",l=this.map;let u=null==(s=l.getPane)?void 0:s.call(l,a);u||(u=this.map.createPane(a)),u.style.zIndex="650",u.style.pointerEvents="auto",this.pane=u,this.root=document.createElement("div"),this.root.className="polydraw-transform-root",this.root.style.position="absolute",this.root.style.left="0px",this.root.style.top="0px",this.root.style.pointerEvents="none",this.pane.appendChild(this.root)}destroy(){null!=this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.root.remove()}update(t,e,n=0){null==this.rafId&&(this.rafId=requestAnimationFrame(()=>{if(this.rafId=null,this.render(t,e,n),this.cancelBtn||this.confirmBtn){this.draggingHandle===ls.Rotate&&"rotate"===this.mode||this.updateButtonPositions(t,n)}}))}render(t,e,n=0){const i=this.cancelBtn,r=this.confirmBtn;this.root.innerHTML="",this.currentBBox=t,this.currentRotation=n,this.cancelBtn=i,this.confirmBtn=r;const o=t.maxX-t.minX,s=t.maxY-t.minY,l=t.minX+o/2,u=t.minY+s/2,h=document.createElement("div");h.className="polydraw-transform-box",Object.assign(h.style,{position:"absolute",left:`${l}px`,top:`${u}px`,width:`${o}px`,height:`${s}px`,marginLeft:-o/2+"px",marginTop:-s/2+"px",border:"1px dashed #2b90d9",pointerEvents:"none",transformOrigin:"center center",transform:`rotate(${180*n/Math.PI}deg)`}),this.root.appendChild(h);const c=(t,e,i)=>{const r=e-l,o=i-u,s=Math.cos(n),h=Math.sin(n),c=l+r*s-o*h,f=u+r*h+o*s,g=document.createElement("div");g.className=`polydraw-transform-handle handle-${t}`,Object.assign(g.style,{position:"absolute",left:c-5+"px",top:f-5+"px",width:"10px",height:"10px",borderRadius:"2px",background:"#2b90d9",boxShadow:"0 0 0 1px #fff",cursor:this.cursorForHandle(t),pointerEvents:"auto",touchAction:"none"}),this.supportsPointerEvents?a.DomEvent.on(g,"pointerdown",e=>this.startDrag(t,{x:c,y:f},e),this):(a.DomEvent.on(g,"mousedown",e=>this.startDrag(t,{x:c,y:f},e),this),a.DomEvent.on(g,"touchstart",e=>this.startDrag(t,{x:c,y:f},e),this)),this.root.appendChild(g)};"scale"===this.mode?(c(ls.TopLeft,t.minX,t.minY),c(ls.TopRight,t.maxX,t.minY),c(ls.BottomRight,t.maxX,t.maxY),c(ls.BottomLeft,t.minX,t.maxY),c(ls.Top,l,t.minY),c(ls.Right,t.maxX,u),c(ls.Bottom,l,t.maxY),c(ls.Left,t.minX,u)):(c(ls.Rotate,t.minX,t.minY),c(ls.Rotate,t.maxX,t.minY),c(ls.Rotate,t.maxX,t.maxY),c(ls.Rotate,t.minX,t.maxY)),this.cancelBtn||this.confirmBtn?(this.updateButtonPositions(t,n),this.cancelBtn&&this.root.appendChild(this.cancelBtn),this.confirmBtn&&this.root.appendChild(this.confirmBtn)):this.updateButtonPositions(t,n)}cursorForHandle(t){switch(t){case ls.Top:case ls.Bottom:return"ns-resize";case ls.Left:case ls.Right:return"ew-resize";case ls.TopLeft:case ls.BottomRight:return"nwse-resize";case ls.TopRight:case ls.BottomLeft:return"nesw-resize";case ls.Rotate:return"grab";case ls.Pivot:return"move";default:return"default"}}startDrag(t,e,n){var i,r;a.DomEvent.stop(n),this.draggingHandle=t,this.hideButtons(),this.documentMoveHandler=t=>this.onDrag(t),this.documentUpHandler=t=>this.endDrag(t);const o=document,s=this.documentMoveHandler,l=this.documentUpHandler;if(this.supportsPointerEvents&&n instanceof PointerEvent){this.activePointerId=n.pointerId,this.pointerCaptureTarget=this.map.getContainer();try{null==(r=null==(i=this.pointerCaptureTarget)?void 0:i.setPointerCapture)||r.call(i,n.pointerId)}catch{}a.DomEvent.on(o,"pointermove",s),a.DomEvent.on(o,"pointerup",l),a.DomEvent.on(o,"pointercancel",l)}else a.DomEvent.on(o,"mousemove",s),a.DomEvent.on(o,"mouseup",l),a.DomEvent.on(o,"touchmove",s),a.DomEvent.on(o,"touchend",l),a.DomEvent.on(o,"touchcancel",l);this.callbacks.onStartHandleDrag(t,e,n)}onDrag(t){if(null==this.draggingHandle)return;const e=this.getMouseLayerPoint(t);this.callbacks.onDragHandle(this.draggingHandle,e,t)}endDrag(t){var e,n;if(null==this.draggingHandle)return;const i=this.draggingHandle;this.draggingHandle=null;const r=this.getMouseLayerPoint(t);if(this.callbacks.onEndHandleDrag(i,r,t),this.currentBBox&&this.updateButtonPositions(this.currentBBox,this.currentRotation),this.showButtons(),this.documentMoveHandler||this.documentUpHandler){const t=document;if(this.supportsPointerEvents&&this.pointerCaptureTarget){if(null!=this.activePointerId)try{null==(n=(e=this.pointerCaptureTarget).releasePointerCapture)||n.call(e,this.activePointerId)}catch{}if(this.documentMoveHandler){const e=this.documentMoveHandler;a.DomEvent.off(t,"pointermove",e)}if(this.documentUpHandler){const e=this.documentUpHandler;a.DomEvent.off(t,"pointerup",e),a.DomEvent.off(t,"pointercancel",e)}this.pointerCaptureTarget=null,this.activePointerId=null}else{if(this.documentMoveHandler){const e=this.documentMoveHandler;a.DomEvent.off(t,"mousemove",e),a.DomEvent.off(t,"touchmove",e)}if(this.documentUpHandler){const e=this.documentUpHandler;a.DomEvent.off(t,"mouseup",e),a.DomEvent.off(t,"touchend",e),a.DomEvent.off(t,"touchcancel",e)}}this.documentMoveHandler=null,this.documentUpHandler=null}}getMouseLayerPoint(t){const e=this.map.getContainer();let n=null,i=null;if(t.touches&&t.touches.length>0){const e=t.touches[0];n=e.clientX,i=e.clientY}else if(t.changedTouches&&t.changedTouches.length>0){const e=t.changedTouches[0];n=e.clientX,i=e.clientY}else null!=t.clientX&&(n=t.clientX,i=t.clientY);null!=n&&null!=i||(n=0,i=0);const r=e.getBoundingClientRect(),o=n-r.left,s=i-r.top,a=Wo.createPoint(o,s),l=this.map.containerPointToLayerPoint(a);return{x:l.x,y:l.y}}updateButtonPositions(t,e){const n=t.maxX-t.minX,i=t.maxY-t.minY,r=t.minX+n/2,o=t.minY+i/2,s=[{x:t.minX,y:t.minY},{x:t.maxX,y:t.minY},{x:t.maxX,y:t.maxY},{x:t.minX,y:t.maxY}],l=Math.cos(e),u=Math.sin(e);let h={x:0,y:1/0},c=1/0;for(const a of s){const t=a.x-r,e=a.y-o,n=r+t*l-e*u,i=o+t*u+e*l,s=i<c,f=Math.abs(i-c)<1,g=n>h.x;(s||f&&g)&&(c=i,h={x:n,y:i})}const f=h.x,g=h.y-28,d=f+5,p=f-29;if(this.onCancel&&!this.cancelBtn&&(this.cancelBtn=document.createElement("div"),this.cancelBtn.className="polydraw-transform-cancel",this.cancelBtn.innerHTML='<?xml version="1.0" encoding="UTF-8"?>\n<svg width="512" height="512" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">\n <circle cx="256" cy="256" r="236" fill="#212A32"/>\n <circle cx="256" cy="256" r="190" fill="#ffffff"/>\n <path id="path2" fill="#800000" fill-rule="evenodd" stroke="none"\n d="M 156 373.906311 C 140.875 373.871002 127.9375 373.615112 127.25 373.337708 C 126.5625 373.060303 126 372.072937 126 371.143555 C 126 370.214203 146.628433 343.53772 171.840973 311.862488 C 197.053513 280.187286 217.991867 253.463562 218.370667 252.47644 C 218.806335 251.341125 218.221786 249.464233 216.779678 247.368073 C 215.525864 245.545563 196.612503 221.361847 174.75 193.626465 C 152.887497 165.891052 135 142.531311 135 141.715881 C 135 140.900421 136.012497 139.961914 137.25 139.63028 C 138.487503 139.298645 152.408203 139.021179 168.184906 139.013641 C 184.588272 139.005859 197.976456 139.420746 199.454529 139.982727 C 201.182831 140.639801 210.486664 152.319733 227.533463 175.232727 C 241.555283 194.079712 253.994949 210.166199 255.177185 210.980438 C 257.208252 212.379272 257.562622 212.186401 261.607452 207.480438 C 263.961853 204.74118 276.052643 189 288.47583 172.5 C 300.899048 156 312.286682 141.714874 313.781738 140.75528 C 316.198669 139.203949 319.554993 139.009949 344.058868 139.00528 C 366.27774 139.001007 371.993561 139.274811 373.557343 140.418274 C 375.458923 141.808746 375.448914 141.90155 373.046875 145.150452 C 371.699341 146.973114 352.828827 170.746307 331.112396 197.979767 C 309.395966 225.213257 291.465973 248.396271 291.267914 249.497589 C 291.012512 250.91803 304.435944 268.61731 337.453918 310.395416 C 363.05426 342.787903 384 370.077271 384 371.038422 C 384 371.999603 383.288208 373.059174 382.418213 373.393005 C 381.548218 373.726868 367.485718 373.993347 351.168213 373.98526 C 329.591888 373.974548 320.854309 373.633606 319.132629 372.73526 C 317.830597 372.055847 302.980591 353.049988 286.132629 330.5 C 260.059052 295.602051 255.12793 289.5 253 289.5 C 250.878326 289.5 245.808807 295.701355 219.5 330.479431 C 202.449997 353.018127 187.375 372.023987 186 372.714691 C 184.165009 373.636475 176.184906 373.95343 156 373.906311 Z"/>\n</svg>',a.DomEvent.on(this.cancelBtn,"mousedown",t=>{t.stopPropagation(),t.preventDefault(),this.onCancel&&this.onCancel()}),a.DomEvent.on(this.cancelBtn,"touchstart",t=>{t.stopPropagation(),t.preventDefault(),this.onCancel&&this.onCancel()}),a.DomEvent.on(this.cancelBtn,"pointerdown",t=>{t.stopPropagation(),t.preventDefault(),this.onCancel&&this.onCancel()}),this.root.appendChild(this.cancelBtn)),this.onConfirm&&!this.confirmBtn&&(this.confirmBtn=document.createElement("div"),this.confirmBtn.className="polydraw-transform-confirm",this.confirmBtn.innerHTML='<?xml version="1.0" encoding="UTF-8"?>\n<svg width="512" height="512" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">\n <circle cx="256" cy="256" r="236" fill="#212A32"/>\n <circle cx="256" cy="256" r="190" fill="#ffffff"/>\n <path id="check" fill="#008000" fill-rule="evenodd" stroke="none"\n d="M 223.844696 360 C 222.79425 360 204.506973 341.170593 178.987274 313.812744 \n C 144.992401 277.369232 135.966232 267.145691 136.201645 265.351257 \n C 136.396179 263.868408 143.092361 257.073425 155.444672 245.824249 \n C 166.363129 235.880859 175.214264 228.571442 176.336426 228.571442 \n C 177.515594 228.571442 181.716553 232.304138 186.987961 238.035706 \n C 191.775406 243.241058 201.629044 254.024994 208.884933 262 \n C 216.140823 269.975006 222.682266 276.635315 223.421478 276.80072 \n C 224.16246 276.966553 247.742722 250.494751 275.976837 217.800751 \n C 304.143097 185.185333 328.050385 157.879608 329.104156 157.121368 \n C 330.785767 155.911316 331.44046 156.0336 334.457672 158.121368 \n C 336.348328 159.429626 345.368622 167.190216 354.502747 175.367126 \n C 367.688812 187.171356 371.047394 190.689819 370.805115 192.445557 \n C 370.635864 193.67218 338.242889 231.469543 298.059082 277.32843 \n C 253.148834 328.581238 224.944153 360 223.844696 360 Z"/>\n</svg>',a.DomEvent.on(this.confirmBtn,"mousedown",t=>{t.stopPropagation(),t.preventDefault(),this.onConfirm&&this.onConfirm()}),a.DomEvent.on(this.confirmBtn,"touchstart",t=>{t.stopPropagation(),t.preventDefault(),this.onConfirm&&this.onConfirm()}),a.DomEvent.on(this.confirmBtn,"pointerdown",t=>{t.stopPropagation(),t.preventDefault(),this.onConfirm&&this.onConfirm()}),this.root.appendChild(this.confirmBtn)),this.cancelBtn){Object.assign(this.cancelBtn.style,{position:"absolute",left:`${p}px`,top:`${g}px`,display:"grid",placeItems:"center",pointerEvents:"auto",width:"28px",height:"28px"});const t=this.cancelBtn.querySelector("svg");t&&(t.setAttribute("width","24"),t.setAttribute("height","24")),this.cancelBtn.style.display=this.buttonsHidden?"none":"grid"}if(this.confirmBtn){Object.assign(this.confirmBtn.style,{position:"absolute",left:`${d}px`,top:`${g}px`,display:"grid",placeItems:"center",pointerEvents:"auto",width:"28px",height:"28px"});const t=this.confirmBtn.querySelector("svg");t&&(t.setAttribute("width","24"),t.setAttribute("height","24")),this.confirmBtn.style.display=this.buttonsHidden?"none":"grid"}}hideButtons(){this.buttonsHidden=!0,this.cancelBtn&&(this.cancelBtn.style.display="none"),this.confirmBtn&&(this.confirmBtn.style.display="none")}showButtons(){this.buttonsHidden=!1,this.cancelBtn&&(this.cancelBtn.style.display="grid"),this.confirmBtn&&(this.confirmBtn.style.display="grid")}}function hs(t,e){const n=t.latLngToLayerPoint(e);return{x:n.x,y:n.y}}function cs(t,e){const n=t.layerPointToLatLng(Wo.createPoint(e.x,e.y));return{lat:n.lat,lng:n.lng}}function fs(t){let e=1/0,n=1/0,i=-1/0,r=-1/0;for(const o of t)for(const t of o)for(const o of t)o.x<e&&(e=o.x),o.y<n&&(n=o.y),o.x>i&&(i=o.x),o.y>r&&(r=o.y);return{minX:e,minY:n,maxX:i,maxY:r}}function gs(t){return{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2}}function ds(t,e,n,i){const r=t.x-e.x,o=t.y-e.y;return{x:e.x+r*n,y:e.y+o*i}}function ps(t,e,n,i,r){return t.map(t=>t.map(t=>t.map(t=>function(t,e,n){const i=Math.cos(n),r=Math.sin(n),o=t.x-e.x,s=t.y-e.y;return{x:e.x+o*i-s*r,y:e.y+o*r+s*i}}(ds(t,e,n,i),e,r))))}function ys(t){if(0===t.length)return t;const e=t[0],n=t[t.length-1];return e.lat===n.lat&&e.lng===n.lng?t:[...t,{lat:e.lat,lng:e.lng}]}function ms(t){if(!Array.isArray(t))return[[t]];const e=t;return 0===e.length?[]:Array.isArray(e[0])?Array.isArray(e[0][0])?t:[t]:[[t]]}class vs{constructor(t,e,n="scale",i){var r,s;o(this,"map"),o(this,"polygon"),o(this,"overlay"),o(this,"state"),o(this,"normalizedLatLngs"),o(this,"wasMapDraggingEnabled",!1),o(this,"mode"),o(this,"onExit"),o(this,"rotateStartAngle",null),o(this,"rotateBaseRotation",0),o(this,"originalTouchAction",null),o(this,"mapDraggingHandler"),o(this,"onKeyDown",t=>{"Escape"===t.key&&this.handleCancel()}),o(this,"updateOverlay",()=>{const t=fs(this.state.originalPixelRings.map(t=>t.map(t=>t.map(t=>ds(t,this.state.pivot,this.state.scaleX,this.state.scaleY)))));this.overlay.update(t,this.state.pivot,this.state.rotation)}),this.map=t,this.mode=n,this.onExit=i;const l=e.getLayers().find(t=>t instanceof a.Polygon);if(!l)throw new Error("FeatureGroup does not contain a polygon");this.polygon=l;const u=this.polygon.getLatLngs();this.normalizedLatLngs=ms(u);const h=function(t,e){const n=[],i=[];for(const r of e){const e=[],o=[];for(const n of r){const i=n.map(e=>hs(t,{lat:e.lat,lng:e.lng}));e.push(i),o.push(n.length)}n.push(e),i.push(o)}return{rings:n,ringLengths:i}}(this.map,this.normalizedLatLngs),c=gs(fs(h.rings));this.state={isActive:!0,originalLatLngs:u,originalPixelRings:h.rings,pivot:c,scaleX:1,scaleY:1,rotation:0,uniformScale:!1,snapRotation:!1,scaleFromPivot:!1},this.overlay=new us(this.map,{onStartHandleDrag:(t,e,n)=>this.onStartDrag(t,e,n),onDragHandle:(t,e)=>this.onDrag(t,e),onEndHandleDrag:()=>{}},this.mode,()=>this.handleCancel(),()=>this.handleConfirm()),this.updateOverlay(),this.map.on("zoom viewreset move",this.updateOverlay,this),this.mapDraggingHandler=this.map.dragging,this.mapDraggingHandler&&("function"==typeof this.mapDraggingHandler.enabled&&(this.wasMapDraggingEnabled=this.mapDraggingHandler.enabled()),null==(s=(r=this.mapDraggingHandler).disable)||s.call(r));const f=this.map.getContainer();this.originalTouchAction=f.style.touchAction||null,f.style.touchAction="none",document.addEventListener("keydown",this.onKeyDown)}destroy(){document.removeEventListener("keydown",this.onKeyDown),this.map.off("zoom viewreset move",this.updateOverlay,this),this.overlay.destroy(),this.state.isActive=!1,this.mapDraggingHandler&&this.wasMapDraggingEnabled&&"function"==typeof this.mapDraggingHandler.enable&&this.mapDraggingHandler.enable();const t=this.map.getContainer();null!==this.originalTouchAction?t.style.touchAction=this.originalTouchAction:t.style.touchAction=""}onStartDrag(t,e,n){const i=navigator.userAgent.toLowerCase().includes("mac")?n.metaKey:n.ctrlKey;if(this.state.uniformScale=!!n.shiftKey,this.state.scaleFromPivot=!!n.altKey,this.state.snapRotation=!!i,t===ls.Rotate){const t=this.state.scaleFromPivot?this.state.pivot:gs(fs(this.state.originalPixelRings)),n=Math.atan2(e.y-t.y,e.x-t.x);this.rotateStartAngle=n,this.rotateBaseRotation=this.state.rotation||0}}onDrag(t,e){const n=fs(this.state.originalPixelRings);switch(t){case ls.Rotate:{const t=this.state.scaleFromPivot?this.state.pivot:gs(n);this.handleRotateDrag(e,t);break}case ls.Pivot:this.handlePivotDrag(e);break;default:{const i=this.state.scaleFromPivot?this.state.pivot:gs(n);this.handleScaleDrag(t,e,n,i);break}}this.preview()}handleRotateDrag(t,e){if("rotate"!==this.mode)return;const n=Math.atan2(t.y-e.y,t.x-e.x);let i;if(null!=this.rotateStartAngle){const t=n-this.rotateStartAngle;i=this.rotateBaseRotation+t}else i=n;this.state.rotation=this.state.snapRotation?function(t,e=15){const n=e*Math.PI/180;return Math.round(t/n)*n}(i,15):i}handlePivotDrag(t){this.state.pivot=t}handleScaleDrag(t,e,n,i){if("scale"!==this.mode)return;const r=n.maxX-n.minX,o=n.maxY-n.minY;let s=this.state.scaleX,a=this.state.scaleY;switch(t){case ls.Left:case ls.TopLeft:case ls.BottomLeft:s=(i.x-e.x)/(i.x-n.minX||1);break;case ls.Right:case ls.TopRight:case ls.BottomRight:s=(e.x-i.x)/(n.maxX-i.x||1)}switch(t){case ls.Top:case ls.TopLeft:case ls.TopRight:a=(i.y-e.y)/(i.y-n.minY||1);break;case ls.Bottom:case ls.BottomLeft:case ls.BottomRight:a=(e.y-i.y)/(n.maxY-i.y||1)}if(t!==ls.Left&&t!==ls.Right||(a=this.state.scaleY),t!==ls.Top&&t!==ls.Bottom||(s=this.state.scaleX),this.state.uniformScale){const t=Math.abs(r)>Math.abs(o)?Math.sign(s)*Math.abs(s):Math.sign(a)*Math.abs(a);s=t,a=t}const l=Number.isFinite(s)&&Math.abs(s)>.001,u=Number.isFinite(a)&&Math.abs(a)>.001;l&&(this.state.scaleX=s),u&&(this.state.scaleY=a)}preview(){const t=ps(this.state.originalPixelRings,this.state.pivot,this.state.scaleX,this.state.scaleY,this.state.rotation),e=function(t,e,n){const i=[];for(let r=0;r<e.length;r++){const o=[];for(let i=0;i<e[r].length;i++){const s=e[r][i].map(e=>cs(t,e)),a=n[r][i],l=a.length>2&&a[0].lat===a[a.length-1].lat&&a[0].lng===a[a.length-1].lng;o.push(l?ys(s):s)}i.push(o)}return i}(this.map,t,this.normalizedLatLngs);this.polygon.setLatLngs(e),this.updateOverlay()}apply(){return ms(this.polygon.getLatLngs())}cancel(){this.polygon.setLatLngs(this.state.originalLatLngs)}handleCancel(){this.cancel(),this.onExit&&this.onExit(!1),this.destroy()}handleConfirm(){this.onExit&&this.onExit(!0),this.destroy()}}class _s{static createMenuButton(t,e,n){const i=document.createElement("div");return i.classList.add("marker-menu-button",...n),i.title=e,i.setAttribute("data-action-id",t),i}static buildMenuPopup(t){const e=document.createElement("div");e.classList.add("alter-marker-outer-wrapper");const n=document.createElement("div");n.classList.add("alter-marker-wrapper");const i=document.createElement("button");i.type="button",i.className="marker-menu-close",i.setAttribute("aria-label","Close menu"),i.innerHTML="&times;",n.appendChild(i);const r=document.createElement("div");r.classList.add("content");const o=document.createElement("div");return o.classList.add("marker-menu-content"),t.forEach(t=>{o.appendChild(t)}),r.appendChild(o),n.appendChild(r),e.appendChild(n),e}static buildInfoPopup(t){const e=document.createElement("div");e.classList.add("info-marker-outer-wrapper");const n=document.createElement("div");n.classList.add("info-marker-wrapper");const i=document.createElement("div");return i.classList.add("content"),i.appendChild(t),n.appendChild(i),e.appendChild(n),e}}class ks{constructor(t,e){o(this,"markerFeatureGroupMap",new WeakMap),o(this,"markerModifierHandlers",new WeakMap),o(this,"markerTouchListeners",new WeakMap),o(this,"markerEdgeDeletionListeners",new WeakMap),o(this,"_activeMarker",null),o(this,"isDraggingMarker",!1),o(this,"turfHelper"),o(this,"polygonInformation"),o(this,"map"),o(this,"config"),o(this,"modeManager"),o(this,"eventManager"),o(this,"saveHistoryState"),o(this,"currentDragPolygon",null),o(this,"currentDragIsClone",!1),o(this,"currentModifierDragMode",!1),o(this,"isModifierKeyHeld",!1),o(this,"currentCloneGhost",null),o(this,"dragCancelHandlersAttached",!1),o(this,"_openMenuPopup",null),o(this,"transformModeActive",!1),o(this,"transformControllers",new WeakMap),o(this,"deleteMarkerSuppressUntil",0),o(this,"getFeatureGroups"),o(this,"removeFeatureGroup"),o(this,"onPolygonMouseMove",t=>{if(!this.currentDragPolygon||!this.currentDragPolygon._polydrawDragData||!this.currentDragPolygon._polydrawDragData.isDragging)return;const e=this.currentDragPolygon,n=e._polydrawDragData;if(!this.currentDragIsClone){const e=t.originalEvent&&"metaKey"in t.originalEvent?t.originalEvent:t;this.detectDragSubtractModifierKey(e)!==this.currentModifierDragMode&&this.handleModifierToggleDuringDrag(e)}const i=n.startPosition,r=t.latlng,o=r.lat-i.lat,s=r.lng-i.lng,a=this.offsetPolygonCoordinates(n.startLatLngs,o,s);e.setLatLngs(a),this.updateMarkersAndHoleLinesDuringDrag(e,o,s)}),o(this,"onPolygonMouseUp",t=>{if(!this.currentDragPolygon||!this.currentDragPolygon._polydrawDragData||!this.currentDragPolygon._polydrawDragData.isDragging)return;const e=this.currentDragPolygon,n=e._polydrawDragData;n.isDragging=!1,this.map.off("mousemove",this.onPolygonMouseMove,this),this.map.off("mouseup",this.onPolygonMouseUp,this),this.map.off("pointermove",this.onPolygonMouseMove,this),this.map.off("pointerup",this.onPolygonMouseUp,this),this.map.dragging&&this.map.dragging.enable(),e._polydrawDragData&&null!=e._polydrawDragData.originalOpacity&&e.setStyle({fillOpacity:e._polydrawDragData.originalOpacity}),this.setMarkerVisibility(e,!0);try{this.map.getContainer().style.cursor=""}catch{}this.clearCloneGhost(),this.detachDragCancelHandlers();const i=this.currentDragIsClone;this.currentDragIsClone=!1,i?this.updatePolygonAfterCloneDrag(e,n):this.updatePolygonAfterDrag(e),e._polydrawOriginalMarkerPositions&&(e._polydrawOriginalMarkerPositions.clear(),delete e._polydrawOriginalMarkerPositions),e._polydrawOriginalHoleLinePositions&&(e._polydrawOriginalHoleLinePositions.clear(),delete e._polydrawOriginalHoleLinePositions),e._polydrawCurrentDragSession&&delete e._polydrawCurrentDragSession,this.currentDragPolygon=null}),o(this,"onPolygonDragCancel",()=>{this.cancelActivePolygonDrag()}),o(this,"onPolygonDragKeyDown",t=>{"Escape"===t.key&&this.cancelActivePolygonDrag()}),o(this,"onMarkerHoverForEdgeDeletionEvent",t=>{if(!this.isModifierKeyHeld)return;const e=t.target;e&&(e.style.backgroundColor=this.config.colors.edgeDeletion.hover,e.style.borderColor=this.config.colors.edgeDeletion.hover,e.classList.add("edge-deletion-hover"))}),o(this,"onMarkerLeaveForEdgeDeletionEvent",t=>{const e=t.target;e&&(e.style.backgroundColor="",e.style.borderColor="",e.classList.remove("edge-deletion-hover"))}),this.turfHelper=t.turfHelper,this.polygonInformation=t.polygonInformation,this.map=t.map,this.config=t.config,this.modeManager=t.modeManager,this.eventManager=t.eventManager,this.saveHistoryState=t.saveHistoryState,this.getFeatureGroups=e.getFeatureGroups,this.removeFeatureGroup=e.removeFeatureGroup,this.eventManager.on("polydraw:mode:change",()=>{(this.currentCloneGhost||this.isPolygonDragActive())&&this.cancelActivePolygonDrag()})}emitPolygonUpdated(t){const e=this.getHistoryActionForOperation(t.operation);e&&this.saveHistoryState&&this.saveHistoryState(e),this.eventManager.emit("polydraw:polygon:updated",t)}getHistoryActionForOperation(t){switch(t){case"addVertex":case"removeVertex":case"removeHole":case"toggleOptimization":return t;case"modifierSubtract":case"modifierSubtractFallback":return"modifierSubtract";default:return null}}getTimestamp(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}shouldSuppressDeleteMarkerClick(){return this.getTimestamp()<this.deleteMarkerSuppressUntil}suppressDeleteMarkerClicks(t){this.deleteMarkerSuppressUntil=this.getTimestamp()+Math.max(0,t)}addMarkers(t,e,n={}){let i=this.getMarkerIndex(t,this.config.markers.markerMenuIcon.position),r=this.getMarkerIndex(t,this.config.markers.markerDeleteIcon.position),o=this.getMarkerIndex(t,this.config.markers.markerInfoIcon.position);const s=this.ensureMarkerSeparation(t.length,{menu:{index:i,enabled:this.config.markers.menuMarker},delete:{index:r,enabled:this.config.markers.deleteMarker},info:{index:o,enabled:this.config.markers.infoMarker}});i=s.menu,r=s.delete,o=s.info;const l=n.optimizationLevel??0,u=this.deriveImportantMarkerIndices(t,{menuIndex:i,deleteIndex:r,infoIndex:o,optimizationLevel:l}),h=t.length>2&&this.latLngEquals(t[0],t[t.length-1]);t.forEach((n,s)=>{let c=this.config.markers.markerIcon.styleClasses;s===i&&this.config.markers.menuMarker&&(c=this.config.markers.markerMenuIcon.styleClasses),s===r&&this.config.markers.deleteMarker&&(c=this.config.markers.markerDeleteIcon.styleClasses),s===o&&this.config.markers.infoMarker&&(c=this.config.markers.markerInfoIcon.styleClasses);const f=Array.isArray(c)?c:[c],g=s===i&&this.config.markers.menuMarker||s===r&&this.config.markers.deleteMarker||s===o&&this.config.markers.infoMarker,d=this.normalizeMarkerIndex(s,t.length,h),p=[...f];l<=0||null===d||u.has(d)||g||p.push("polygon-marker-faded");const y=new a.Marker(n,{icon:this.createDivIcon(p),draggable:this.config.modes.dragElbow,title:this.config.markers.coordsTitle?this.getLatLngInfoString(n):"",zIndexOffset:this.config.markers.markerIcon.zIndexOffset??this.config.markers.zIndexOffset});e.addLayer(y).addTo(this.map),this.markerFeatureGroupMap.set(y,e),y.on("add",()=>{const t=y.getElement();t&&(t.style.pointerEvents="auto")}),y.on("click",t=>{var e,n;this.isDraggingMarker&&(null==(n=null==(e=t.originalEvent)?void 0:e.stopPropagation)||n.call(e),a.DomEvent.stopPropagation(t))}),y.on("dragstart",()=>{this.saveHistoryState&&this.saveHistoryState("markerDrag"),this.isDraggingMarker=!0,this._activeMarker=y}),y.on("dragend",t=>{const e=this.markerFeatureGroupMap.get(y);this.modeManager.canPerformAction("markerDrag")&&e&&this.markerDragEnd(e),this._activeMarker=null,a.DomEvent.stopPropagation(t),setTimeout(()=>{this.isDraggingMarker=!1},10)});const m=y.getElement();if(m){const t=t=>{t.stopPropagation()},e=t=>{if(t.preventDefault(),t.stopPropagation(),y.fire("click"),this.isDraggingMarker&&!g){const t=this.markerFeatureGroupMap.get(y);this.modeManager.canPerformAction("markerDrag")&&t&&this.markerDragEnd(t)}this._activeMarker=null};m.addEventListener("touchstart",t,{passive:!0}),m.addEventListener("touchend",e),this.markerTouchListeners.set(y,{touchstart:t,touchend:e})}if(s===i||s===r||s===o){const t=y.getElement();t&&(t.style.zIndex="10000")}if(this.config.modes.dragElbow){const t=t=>()=>{this.modeManager.canPerformAction("markerDrag")&&this.markerDrag(t)};y.on("drag",t(e))}if(s===i&&this.config.markers.menuMarker&&(y.options.zIndexOffset=this.config.markers.markerMenuIcon.zIndexOffset??this.config.markers.zIndexOffset,y.on("click",()=>{const n=this.getPolygonGeoJSONFromFeatureGroup(e),r=Qo.getCenterOfPolygonByIndexWithOffsetFromCenterOfMass(n,i);this.generateMenuMarkerPopup(t,e).setLatLng(r).openOn(this.map)}),y.on("popupopen",t=>{const e=t.popup.getElement();if(!e)return;setTimeout(()=>{const t=this.map.getContainer(),n=e.getBoundingClientRect(),i=t.getBoundingClientRect();let r=0,o=0;n.left<i.left?r=i.left-n.left:n.right>i.right&&(r=i.right-n.right),n.top<i.top?o=i.top-n.top:n.bottom>i.bottom&&(o=i.bottom-n.bottom),0===r&&0===o||(e.style.transform=`translate(${r}px, ${o}px)`)},0);const n=this.map.getContainer();n&&(n.style.touchAction="manipulation")}),y.on("popupclose",()=>{const t=this.map.getContainer();t&&(t.style.touchAction="")})),s===o&&this.config.markers.infoMarker){const t=this.getPolygonGeoJSONFromFeatureGroup(e),n=this.turfHelper.getPolygonArea(t),i=this.getTotalPolygonPerimeter(t);y.options.zIndexOffset=this.config.markers.markerInfoIcon.zIndexOffset??this.config.markers.zIndexOffset,y.on("click",()=>{const e=this.generateInfoMarkerPopup(n,i),r=Qo.getCenterOfPolygonByIndexWithOffsetFromCenterOfMass(t,o);e.setLatLng(r).openOn(this.map)}),y.on("popupopen",t=>{const e=t.popup.getElement();if(!e)return;setTimeout(()=>{const t=this.map.getContainer().getBoundingClientRect(),n=e.getBoundingClientRect();n.left<t.left?e.style.transform=`translateX(${t.left-n.left}px)`:n.right>t.right&&(e.style.transform=`translateX(${t.right-n.right}px)`)},0);const n=this.map.getContainer();n&&(n.style.touchAction="manipulation")}),y.on("popupclose",()=>{const t=this.map.getContainer();t&&(t.style.touchAction="")})}y.on("mousedown",t=>{this.modeManager.isInOffMode()||(a.DomEvent.stopPropagation(t),this.map.fire("mousedown",t)),this._activeMarker=y}),y.on("click",t=>{var n,i;if(this.modeManager.isInOffMode())if(this.isEdgeDeletionModifierKeyPressed(t.originalEvent)){const n=e.getLayers().find(t=>t instanceof a.Polygon);n&&this.elbowClicked(t,n,y.getLatLng())}else if(s===r&&this.config.markers.deleteMarker){if(this.shouldSuppressDeleteMarkerClick()){const e=t.originalEvent;return null==(n=null==e?void 0:e.preventDefault)||n.call(e),void(null==(i=null==e?void 0:e.stopPropagation)||i.call(e))}this.map.closePopup(),this.saveHistoryState&&this.saveHistoryState("deletePolygon"),this.cleanupFeatureGroup(e),this.removeFeatureGroup(e),this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups()),this.eventManager.emit("polydraw:polygon:deleted",void 0)}}),y.on("mouseover",()=>this.onMarkerHoverForEdgeDeletion(y,!0)),y.on("mouseout",()=>this.onMarkerHoverForEdgeDeletion(y,!1))});const c=this.map.getContainer();c&&(c.style.touchAction="manipulation")}addHoleMarkers(t,e){var n,i,r;const o=(null==(n=this.config.markers.holeMarkers)?void 0:n.menuMarker)??!1,s=(null==(i=this.config.markers.holeMarkers)?void 0:i.deleteMarker)??!1,l=(null==(r=this.config.markers.holeMarkers)?void 0:r.infoMarker)??!1;let u=this.getMarkerIndex(t,this.config.markers.markerMenuIcon.position),h=this.getMarkerIndex(t,this.config.markers.markerDeleteIcon.position),c=this.getMarkerIndex(t,this.config.markers.markerInfoIcon.position);const f=this.ensureMarkerSeparation(t.length,{menu:{index:u,enabled:o},delete:{index:h,enabled:s},info:{index:c,enabled:l}});u=f.menu,h=f.delete,c=f.info,t.forEach((n,i)=>{let r=this.config.markers.holeIcon.styleClasses;i===u&&o&&(r=this.config.markers.markerMenuIcon.styleClasses),i===h&&s&&(r=this.config.markers.markerDeleteIcon.styleClasses),i===c&&l&&(r=this.config.markers.markerInfoIcon.styleClasses);const f=Array.isArray(r)?r:[r],g=i===u&&o||i===h&&s||i===c&&l,d=new a.Marker(n,{icon:this.createDivIcon(f),draggable:this.config.modes.dragElbow,title:this.config.markers.coordsTitle?this.getLatLngInfoString(n):"",zIndexOffset:this.config.markers.holeIcon.zIndexOffset??this.config.markers.zIndexOffset});e.addLayer(d).addTo(this.map),this.markerFeatureGroupMap.set(d,e),d.on("add",()=>{const t=d.getElement();t&&(t.style.pointerEvents="auto")}),d.on("click",t=>{var e,n;this.isDraggingMarker&&(null==(n=null==(e=t.originalEvent)?void 0:e.stopPropagation)||n.call(e),a.DomEvent.stopPropagation(t))}),d.on("dragstart",()=>{this.saveHistoryState&&this.saveHistoryState("markerDrag"),this.isDraggingMarker=!0,this._activeMarker=d}),d.on("dragend",t=>{const e=this.markerFeatureGroupMap.get(d);this.modeManager.canPerformAction("markerDrag")&&e&&this.markerDragEnd(e),this._activeMarker=null,a.DomEvent.stopPropagation(t),setTimeout(()=>{this.isDraggingMarker=!1},10)});const p=d.getElement();if(p){const t=t=>{t.stopPropagation()},e=t=>{if(t.preventDefault(),t.stopPropagation(),d.fire("click"),this.isDraggingMarker&&!g){const t=this.markerFeatureGroupMap.get(d);this.modeManager.canPerformAction("markerDrag")&&t&&this.markerDragEnd(t)}this._activeMarker=null};p.addEventListener("touchstart",t,{passive:!0}),p.addEventListener("touchend",e),this.markerTouchListeners.set(d,{touchstart:t,touchend:e})}if(i===u||i===h||i===c){const t=d.getElement();t&&(t.style.zIndex="10000")}if(this.config.modes.dragElbow){const t=t=>()=>{this.modeManager.canPerformAction("markerDrag")&&this.markerDrag(t)};d.on("drag",t(e))}if(i===u&&o&&(d.options.zIndexOffset=this.config.markers.markerMenuIcon.zIndexOffset??this.config.markers.zIndexOffset,d.on("click",()=>{const n=t.map(t=>[t.lng,t.lat]);n.push(n[0]);const i={type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[n]}},r=Qo.getCenterOfMass(i);this.generateMenuMarkerPopup(t,e).setLatLng(r).openOn(this.map)}),d.on("popupopen",t=>{const e=t.popup.getElement();if(!e)return;setTimeout(()=>{const t=this.map.getContainer().getBoundingClientRect(),n=e.getBoundingClientRect();n.left<t.left?e.style.transform=`translateX(${t.left-n.left}px)`:n.right>t.right&&(e.style.transform=`translateX(${t.right-n.right}px)`)},0);const n=this.map.getContainer();n&&(n.style.touchAction="manipulation")}),d.on("popupclose",()=>{const t=this.map.getContainer();t&&(t.style.touchAction="")})),i===c&&l){const e=t.map(t=>[t.lng,t.lat]);e.push(e[0]);const i={type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[e]}},r=this.turfHelper.getPolygonArea(i),o=1e3*this.turfHelper.getPolygonPerimeter(i);d.options.zIndexOffset=this.config.markers.markerInfoIcon.zIndexOffset??this.config.markers.zIndexOffset,d.on("click",()=>{this.generateInfoMarkerPopup(r,o).setLatLng(n).openOn(this.map)})}d.on("mousedown",t=>{this.modeManager.isInOffMode()||(a.DomEvent.stopPropagation(t),this.map.fire("mousedown",t)),this._activeMarker=d}),d.on("click",t=>{if(this.modeManager.isInOffMode())if(this.isEdgeDeletionModifierKeyPressed(t.originalEvent)){const n=e.getLayers().find(t=>t instanceof a.Polygon);n&&this.elbowClicked(t,n,d.getLatLng())}else if(i===h&&s){this.map.closePopup();const t=e.getLayers().find(t=>t instanceof a.Polygon);if(t){const n=t.getLatLngs();let i=[];if(Array.isArray(n)&&n.length>0)if(Array.isArray(n[0])){const t=n[0];i=Array.isArray(t)&&Array.isArray(t[0])?n[0]:n}else i=[n];const r=d.getLatLng();let o=-1;for(let t=1;t<i.length;t++)if(i[t].some(t=>t.lat===r.lat&&t.lng===r.lng)){o=t;break}if(o>0){const t=i.filter((t,e)=>e!==o).map(t=>{const e=t.map(t=>[t.lng,t.lat]);if(e.length>0){const t=e[0],n=e[e.length-1];t[0]===n[0]&&t[1]===n[1]||e.push([t[0],t[1]])}return e}),{level:n,original:r}=this.getOptimizationMetadataFromFeatureGroup(e),s=this.turfHelper.getMultiPolygon([t]);this.cleanupFeatureGroup(e),this.removeFeatureGroup(e),this.emitPolygonUpdated({operation:"removeHole",polygon:s,optimizationLevel:n,originalOptimizationLevel:r})}}}}),d.on("mouseover",()=>this.onMarkerHoverForEdgeDeletion(d,!0)),d.on("mouseout",()=>this.onMarkerHoverForEdgeDeletion(d,!1))})}addEdgeClickListeners(t,e){const n=t.getLatLngs();let i;if(Array.isArray(n)&&n.length>0){if(Array.isArray(n[0]))if(Array.isArray(n[0][0])&&n[0][0].length>0){n[0][0][0];i=n[0]}else i=n[0][0]&&"object"==typeof n[0][0]&&"lat"in n[0][0]?n:n[0];else i=(n[0]&&"object"==typeof n[0]&&n[0],[n]);i.forEach((n,i)=>{for(let r=0;r<n.length;r++){const o=n[r],s=n[(r+1)%n.length];if(o.lat===s.lat&&o.lng===s.lng)continue;const a=Wo.createPolyline([o,s],{color:"transparent",weight:10,opacity:0,interactive:!0});a._polydrawEdgeInfo={ringIndex:i,edgeIndex:r,startPoint:o,endPoint:s,parentPolygon:t,parentFeatureGroup:e},a.on("click",t=>{this.onEdgeClick(t,a)}),a.on("mouseover",()=>{this.highlightEdgeOnHover(a,!0)}),a.on("mouseout",()=>{this.highlightEdgeOnHover(a,!1)}),e.addLayer(a)}})}}isPolygonDragModeActive(){const t=this.modeManager.getCurrentMode();return t===u.Off||t===u.Clone}isPolygonDragActive(){return!!(this.currentDragPolygon&&this.currentDragPolygon._polydrawDragData&&this.currentDragPolygon._polydrawDragData.isDragging)}enablePolygonDragging(t,e){(this.config.modes.dragPolygons||this.config.modes.clonePolygons)&&(t._polydrawOriginalLatLngs=e,t._polydrawDragData={isDragging:!1,startPosition:null,startLatLngs:null,originalOpacity:t.options.fillOpacity},t.on("mousedown",e=>{if(!this.isPolygonDragModeActive())return a.DomEvent.stopPropagation(e),void this.map.fire("mousedown",e);if(!this.modeManager.canPerformAction("polygonDrag"))return;a.DomEvent.stopPropagation(e.originalEvent),a.DomEvent.preventDefault(e.originalEvent);const n=this.modeManager.getCurrentMode()===u.Clone,i=!n&&this.detectDragSubtractModifierKey(e.originalEvent);this.currentDragIsClone=n,this.currentModifierDragMode=i,this.isModifierKeyHeld=i,this.saveHistoryState&&this.saveHistoryState(n?"polygonClone":"polygonDrag"),t._polydrawDragData.isDragging=!0,t._polydrawDragData.startPosition=e.latlng,t._polydrawDragData.startLatLngs=t.getLatLngs(),t.setStyle({fillOpacity:this.config.dragPolygons.opacity}),n?this.showCloneGhost(t._polydrawDragData.startLatLngs):this.clearCloneGhost(),this.map.dragging&&this.map.dragging.disable(),this.setSubtractVisualMode(t,i),this.setMarkerVisibility(t,!1);try{this.map.getContainer().style.cursor=this.config.dragPolygons.dragCursor||"move"}catch{}this.map.on("mousemove",this.onPolygonMouseMove,this),this.map.on("mouseup",this.onPolygonMouseUp,this),this.map.on("pointermove",this.onPolygonMouseMove,this),this.map.on("pointerup",this.onPolygonMouseUp,this),this.attachDragCancelHandlers(),this.currentDragPolygon=t}),t.on("pointerdown",e=>{const n=e;if(this.transformModeActive)return;if(!this.isPolygonDragModeActive()){const t=n.originalEvent??n;return a.DomEvent.stopPropagation(t),void this.map.fire("pointerdown",n)}if(!this.modeManager.canPerformAction("polygonDrag"))return;const i=n.originalEvent??n;a.DomEvent.stopPropagation(i),a.DomEvent.preventDefault(i);const r=this.modeManager.getCurrentMode()===u.Clone,o=!r&&this.detectDragSubtractModifierKey(i);this.currentDragIsClone=r,this.currentModifierDragMode=o,this.isModifierKeyHeld=o,this.saveHistoryState&&this.saveHistoryState(r?"polygonClone":"polygonDrag"),t._polydrawDragData.isDragging=!0,t._polydrawDragData.startPosition=n.latlng,t._polydrawDragData.startLatLngs=t.getLatLngs(),t.setStyle({fillOpacity:this.config.dragPolygons.opacity}),r?this.showCloneGhost(t._polydrawDragData.startLatLngs):this.clearCloneGhost(),this.map.dragging&&this.map.dragging.disable(),this.setSubtractVisualMode(t,o),this.setMarkerVisibility(t,!1);try{this.map.getContainer().style.cursor=this.config.dragPolygons.dragCursor||"move"}catch{}this.map.on("mousemove",this.onPolygonMouseMove,this),this.map.on("mouseup",this.onPolygonMouseUp,this),this.map.on("pointermove",this.onPolygonMouseMove,this),this.map.on("pointerup",this.onPolygonMouseUp,this),this.attachDragCancelHandlers(),this.currentDragPolygon=t}),t.on("mouseover",()=>{if(!t._polydrawDragData||!t._polydrawDragData.isDragging)try{this.map.getContainer().style.cursor=this.config.dragPolygons.hoverCursor||"grab"}catch{}}),t.on("mouseout",()=>{if(!t._polydrawDragData||!t._polydrawDragData.isDragging)try{this.map.getContainer().style.cursor=""}catch{}}))}updateMarkerDraggableState(){const t=this.modeManager.canPerformAction("markerDrag");this.getFeatureGroups().forEach(e=>{e.eachLayer(e=>{if(e instanceof a.Marker){const n=e;try{n.options.draggable=t,n.dragging&&(t?n.dragging.enable():n.dragging.disable())}catch{}}})})}updateAllMarkersForEdgeDeletion(t){this.getFeatureGroups().forEach(e=>{e.eachLayer(e=>{e instanceof a.Marker&&this.updateMarkerForEdgeDeletion(e,t)})})}updateMarkerForEdgeDeletion(t,e){const n=t.getElement();n&&(e?(n.addEventListener("mouseenter",this.onMarkerHoverForEdgeDeletionEvent),n.addEventListener("mouseleave",this.onMarkerLeaveForEdgeDeletionEvent),this.markerEdgeDeletionListeners.set(t,{mouseenter:this.onMarkerHoverForEdgeDeletionEvent,mouseleave:this.onMarkerLeaveForEdgeDeletionEvent})):(n.removeEventListener("mouseenter",this.onMarkerHoverForEdgeDeletionEvent),n.removeEventListener("mouseleave",this.onMarkerLeaveForEdgeDeletionEvent),n.style.backgroundColor="",n.style.borderColor="",this.markerEdgeDeletionListeners.delete(t)))}setModifierKeyHeld(t){this.isModifierKeyHeld=t}cleanupMarker(t){const e=t.getElement(),n=this.markerModifierHandlers.get(t);n&&(document.removeEventListener("keydown",n),document.removeEventListener("keyup",n),e&&e.removeEventListener("mousemove",n),this.markerModifierHandlers.delete(t));const i=this.markerTouchListeners.get(t);i&&(e&&(e.removeEventListener("touchstart",i.touchstart),e.removeEventListener("touchend",i.touchend)),this.markerTouchListeners.delete(t));const r=this.markerEdgeDeletionListeners.get(t);r&&(e&&(e.removeEventListener("mouseenter",r.mouseenter),e.removeEventListener("mouseleave",r.mouseleave)),this.markerEdgeDeletionListeners.delete(t)),this.markerFeatureGroupMap.delete(t)}cleanupFeatureGroup(t){t.eachLayer(t=>{t instanceof a.Marker&&this.cleanupMarker(t)}),this.destroyTransformController(t)}destroyTransformController(t){const e=this.transformControllers.get(t);e&&(e.destroy(),this.transformControllers.delete(t),this.transformModeActive=!1)}onEdgeClick(t,e){if(!this.config.modes.attachElbow)return;if(!this.modeManager.isInOffMode())return;const n=e._polydrawEdgeInfo;if(!n)return;const i=t.latlng,r=n.parentPolygon,o=n.parentFeatureGroup;if(r&&o)try{if("function"!=typeof r.toGeoJSON)return;const t=r.toGeoJSON();if("MultiPolygon"===t.geometry.type||"Polygon"===t.geometry.type){const e=this.turfHelper.injectPointToPolygon(t,[i.lng,i.lat],n.ringIndex);if(e){const t=r,n=t._polydrawOptimizationLevel||0,i=t._polydrawOptimizationOriginalLevel||n;this.cleanupFeatureGroup(o),this.removeFeatureGroup(o),this.emitPolygonUpdated({operation:"addVertex",polygon:e,optimizationLevel:n,originalOptimizationLevel:i})}}}catch{}a.DomEvent.stopPropagation(t)}highlightEdgeOnHover(t,e){e?t.setStyle({color:this.config.colors.edgeHover,weight:4,opacity:1}):t.setStyle({color:"transparent",weight:10,opacity:0})}deriveImportantMarkerIndices(t,e){const n=new Set;if(!t||0===t.length)return n;const i=Math.min(Math.max(e.optimizationLevel??0,0),10),r=t.length>2&&this.latLngEquals(t[0],t[t.length-1]),o=r?t.slice(0,-1):[...t],s=o.length,a=e=>{if(null==e||e<0)return;let i=e;r&&e===t.length-1&&(i=0),i>=s&&(i=s>0?i%s:0),i>=0&&i<s&&n.add(i)};if(a(0),a(e.menuIndex),a(e.deleteIndex),a(e.infoIndex),0===s||i<=0||s<=3){for(let t=0;t<s;t++)n.add(t);return n}const l=this.getToleranceForOptimizationLevel(i);let u=l>0?this.turfHelper.simplifyLatLngRing(o,l,!0):[...o];if(u.length>1&&this.latLngEquals(u[0],u[u.length-1])&&(u=u.slice(0,-1)),!u||0===u.length){for(let t=0;t<s;t++)n.add(t);return n}if(u.forEach(t=>{const e=this.findClosestVertexIndex(t,o);null!==e&&n.add(e)}),0===n.size)for(let h=0;h<s;h++)n.add(h);return n}normalizeMarkerIndex(t,e,n){if(null==t||t<0)return null;if(n){const n=Math.max(1,e-1);return t===e-1?0:t>=n?t%n:t}return t>=e?e>0?e-1:null:t}latLngEquals(t,e){return!(!t||!e)&&(Math.abs(t.lat-e.lat)<1e-9&&Math.abs(t.lng-e.lng)<1e-9)}isLatLngLiteral(t){return!!t&&"object"==typeof t&&"lat"in t&&"lng"in t&&"number"==typeof t.lat&&"number"==typeof t.lng}getOrderedMarkers(t){const e=[];return t.eachLayer(t=>{t instanceof a.Marker&&e.push(t)}),e.sort((t,e)=>Wo.util.stamp(t)-Wo.util.stamp(e))}countLatLngNodes(t){return Array.isArray(t)?0===t.length?0:this.isLatLngLiteral(t[0])?t.length:t.reduce((t,e)=>t+this.countLatLngNodes(e),0):0}rebuildLatLngStructure(t,e,n){if(!Array.isArray(t))return t;if(t.length>0&&this.isLatLngLiteral(t[0])){const i=t,r=i.length>1&&this.latLngEquals(i[0],i[i.length-1]),o=i.map((t,r)=>{const o=e[n.value]??i[r];return n.value+=1,Wo.createLatLng(o.lat,o.lng)});return r&&o.length>1&&(o[o.length-1]=o[0]),o}return t.map(t=>this.rebuildLatLngStructure(t,e,n))}getOptimizationMetadataFromFeatureGroup(t){let e=0,n=0;return t.eachLayer(t=>{if(t instanceof a.Polygon){const i=t;"number"==typeof i._polydrawOptimizationLevel&&(e=i._polydrawOptimizationLevel||0),"number"==typeof i._polydrawOptimizationOriginalLevel&&(n=i._polydrawOptimizationOriginalLevel||0)}}),!n&&e>0&&(n=e),{level:e,original:n}}getOptimizationMetadataFromPolygonLayer(t){if(!t)return{level:0,original:0};const e=t,n=e._polydrawOptimizationLevel||0;return{level:n,original:e._polydrawOptimizationOriginalLevel||(n>0?n:0)}}getDistanceMeters(t,e){try{const n=Wo.createLatLng(t.lat,t.lng),i=Wo.createLatLng(e.lat,e.lng);if("function"==typeof n.distanceTo)return n.distanceTo(i)}catch{}const n=t=>t*Math.PI/180,i=n(e.lat-t.lat),r=n(e.lng-t.lng),o=n(t.lat),s=n(e.lat),a=Math.sin(i/2)*Math.sin(i/2)+Math.sin(r/2)*Math.sin(r/2)*Math.cos(o)*Math.cos(s);return 6371e3*(2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a)))}findClosestVertexIndex(t,e){if(!e||0===e.length)return null;let n=0,i=Number.POSITIVE_INFINITY;for(let r=0;r<e.length;r++){const o=this.getDistanceMeters(t,e[r]);if(o<i&&(i=o,n=r,0===o))break}return n}getToleranceForOptimizationLevel(t){const e=Math.min(Math.max(t,0),10)/10,n=this.config.markers.visualOptimization??{},i=Math.max(n.toleranceMin??5e-6,0),r=Math.max(n.toleranceMax??.005,i),o=n.curve??1.35;return i+(r-i)*Math.pow(e,o)}elbowClicked(t,e,n){if(!this.config.modes.edgeDeletion)return;if(!this.isEdgeDeletionModifierKeyPressed(t.originalEvent))return;const i=n??t.latlng,r=e.getLatLngs();let o=[];if(!(Array.isArray(r)&&r.length>0))return;if(Array.isArray(r[0])){const t=r[0];o=Array.isArray(t)&&Array.isArray(t[0])?r[0]:r}else o=[r];let s=-1,a=-1;for(let d=0;d<o.length;d++){const t=o[d];for(let e=0;e<t.length;e++){const n=t[e];if(n.lat===i.lat&&n.lng===i.lng){s=d,a=e;break}}if(-1!==s)break}if(-1===s||-1===a)return;if(o[s].length<=this.config.edgeDeletion.minVertices)return;const l=o.map((t,e)=>{if(e!==s)return t.slice();const n=t.slice();return n.splice(a,1),n}).map(t=>{const e=t.map(t=>[t.lng,t.lat]);if(e.length>0){const t=e[0],n=e[e.length-1];t[0]===n[0]&&t[1]===n[1]||e.push([t[0],t[1]])}return e});let u=null;for(const d of this.getFeatureGroups()){let t=!1;if(d.eachLayer(n=>{n===e&&(t=!0)}),t){u=d;break}}const h=u?this.getOptimizationMetadataFromFeatureGroup(u):this.getOptimizationMetadataFromPolygonLayer(e),{level:c,original:f}=h;u&&this.removeFeatureGroup(u);const g=this.turfHelper.getMultiPolygon([l]);this.emitPolygonUpdated({operation:"removeVertex",polygon:g,optimizationLevel:c,originalOptimizationLevel:f})}markerDrag(t){if(!this._activeMarker)return void(Ho()||console.warn("No active marker set for dragging."));const e=t.getLayers().find(t=>t instanceof a.Polygon);if(!e)return void(Ho()||console.warn("No polygon found in feature group for marker drag."));const n=this.getOrderedMarkers(t);if(0===n.length)return;const i=n.map(t=>t.getLatLng()),r=this.countLatLngNodes(e.getLatLngs());if(i.length<r)return void(Ho()||console.warn("Not enough markers to rebuild polygon during drag. Expected:",r,"got:",i.length));const o=this.rebuildLatLngStructure(e.getLatLngs(),i,{value:0});e.setLatLngs(o)}async markerDragEnd(t){this.polygonInformation.deletePolygonInformationStorage();const e=t.toGeoJSON();if(!e.features||0===e.features.length)return;const{level:n,original:i}=this.getOptimizationMetadataFromFeatureGroup(t);this.cleanupFeatureGroup(t),this.removeFeatureGroup(t);const r=(t,e,n)=>{const i=this.turfHelper.removeDuplicateVertices(t),r=[];if(!this.config.kinks)try{const t=this.turfHelper.getKinks(i);t&&t.length>0&&r.push(...t)}catch{}0===r.length&&("MultiPolygon"===i.geometry.type?i.geometry.coordinates.forEach(t=>r.push(this.turfHelper.getMultiPolygon([t]))):r.push(i)),r.forEach(t=>{this.emitPolygonUpdated({operation:"markerDrag",polygon:t,allowMerge:e,optimizationLevel:n.optimizationLevel,originalOptimizationLevel:n.originalOptimizationLevel})})};if("MultiPolygon"===e.features[0].geometry.type)for(const o of e.features[0].geometry.coordinates){r(this.turfHelper.getMultiPolygon([o]),!0,{optimizationLevel:n,originalOptimizationLevel:i})}else{r(this.turfHelper.getMultiPolygon([e.features[0].geometry.coordinates]),!1,{optimizationLevel:n,originalOptimizationLevel:i})}this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups())}attachDragCancelHandlers(){this.dragCancelHandlersAttached||(this.dragCancelHandlersAttached=!0,document.addEventListener("keydown",this.onPolygonDragKeyDown),this.map.on("pointercancel",this.onPolygonDragCancel,this),this.map.on("touchcancel",this.onPolygonDragCancel,this))}detachDragCancelHandlers(){this.dragCancelHandlersAttached&&(this.dragCancelHandlersAttached=!1,document.removeEventListener("keydown",this.onPolygonDragKeyDown),this.map.off("pointercancel",this.onPolygonDragCancel,this),this.map.off("touchcancel",this.onPolygonDragCancel,this))}cancelActivePolygonDrag(){if(!this.currentDragPolygon||!this.currentDragPolygon._polydrawDragData)return void this.clearCloneGhost();const t=this.currentDragPolygon,e=t._polydrawDragData;if(e)if(e.isDragging){e.isDragging=!1,this.map.off("mousemove",this.onPolygonMouseMove,this),this.map.off("mouseup",this.onPolygonMouseUp,this),this.map.off("pointermove",this.onPolygonMouseMove,this),this.map.off("pointerup",this.onPolygonMouseUp,this),this.map.dragging&&this.map.dragging.enable(),e.startLatLngs&&t.setLatLngs(e.startLatLngs),t._polydrawOriginalMarkerPositions&&(t._polydrawOriginalMarkerPositions.forEach((t,e)=>{e.setLatLng(t)}),t._polydrawOriginalMarkerPositions.clear(),delete t._polydrawOriginalMarkerPositions),t._polydrawOriginalHoleLinePositions&&(t._polydrawOriginalHoleLinePositions.forEach((t,e)=>{e.setLatLngs(t)}),t._polydrawOriginalHoleLinePositions.clear(),delete t._polydrawOriginalHoleLinePositions),t._polydrawCurrentDragSession&&delete t._polydrawCurrentDragSession,null!=e.originalOpacity&&t.setStyle({fillOpacity:e.originalOpacity}),this.setSubtractVisualMode(t,!1),this.setMarkerVisibility(t,!0);try{this.map.getContainer().style.cursor=""}catch{}this.clearCloneGhost(),this.detachDragCancelHandlers(),this.currentDragIsClone=!1,this.currentModifierDragMode=!1,this.isModifierKeyHeld=!1,this.currentDragPolygon=null}else this.clearCloneGhost();else this.clearCloneGhost()}offsetPolygonCoordinates(t,e,n){return t?Array.isArray(t[0])?t.map(t=>this.offsetPolygonCoordinates(t,e,n)):t.map(t=>Wo.createLatLng(t.lat+e,t.lng+n)):t}updateMarkersAndHoleLinesDuringDrag(t,e,n){try{let i=null;for(const e of this.getFeatureGroups()){let n=!1;if(e.eachLayer(e=>{e===t&&(n=!0)}),n){i=e;break}}if(!i)return;const r="_polydrawDragSession_"+Date.now()+"_"+Wo.util.stamp(t);t._polydrawCurrentDragSession||(t._polydrawCurrentDragSession=r,t._polydrawOriginalMarkerPositions=new Map,t._polydrawOriginalHoleLinePositions=new Map,i.eachLayer(e=>{if(e instanceof a.Marker)t._polydrawOriginalMarkerPositions.set(e,e.getLatLng());else if(e instanceof a.Polyline&&!(e instanceof a.Polygon)){const n=e.getLatLngs();t._polydrawOriginalHoleLinePositions.set(e,n)}})),i.eachLayer(i=>{if(i instanceof a.Marker){const r=t._polydrawOriginalMarkerPositions.get(i);if(r){const t={lat:r.lat+e,lng:r.lng+n};i.setLatLng(t)}}else if(i instanceof a.Polyline&&!(i instanceof a.Polygon)){const r=t._polydrawOriginalHoleLinePositions.get(i);if(r){let t;t=Array.isArray(r[0])?r.map(t=>t.map(t=>Wo.createLatLng(t.lat+e,t.lng+n))):r.map(t=>Wo.createLatLng(t.lat+e,t.lng+n)),i.setLatLngs(t)}}})}catch(i){console.warn("Error updating markers during drag:",i)}}async updatePolygonAfterDrag(t){try{let e=null;for(const s of this.getFeatureGroups())if(s.eachLayer(n=>{n===t&&(e=s)}),e)break;if(!e)return;const n=t.toGeoJSON();if(this.isModifierDragActive())return this.performModifierSubtract(n,e),this.currentModifierDragMode=!1,void(this.isModifierKeyHeld=!1);const{level:i,original:r}=this.getOptimizationMetadataFromFeatureGroup(e);this.cleanupFeatureGroup(e),this.removeFeatureGroup(e);const o=this.turfHelper.getTurfPolygon(n);this.emitPolygonUpdated({operation:"polygonDrag",polygon:o,allowMerge:!0,optimizationLevel:i,originalOptimizationLevel:r}),this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups())}catch{}}updatePolygonAfterCloneDrag(t,e){try{let n=null;for(const e of this.getFeatureGroups())if(e.eachLayer(i=>{i===t&&(n=e)}),n)break;if(!n)return;const i=t.toGeoJSON(),r=(null==e?void 0:e.startLatLngs)??null,o=r?this.createPolygonFeatureFromLatLngs(r):null,{level:s,original:a}=this.getOptimizationMetadataFromFeatureGroup(n);this.cleanupFeatureGroup(n),this.removeFeatureGroup(n);const l=this.turfHelper.getTurfPolygon(i);if(this.emitPolygonUpdated({operation:"polygonDrag",polygon:l,allowMerge:!0,optimizationLevel:s,originalOptimizationLevel:a}),o){const t=this.turfHelper.getTurfPolygon(o);this.emitPolygonUpdated({operation:"polygonClone",polygon:t,allowMerge:!0,optimizationLevel:s,originalOptimizationLevel:a})}this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups())}catch{}finally{this.currentModifierDragMode=!1,this.isModifierKeyHeld=!1}}showCloneGhost(t){if(this.clearCloneGhost(),t)try{const e=Wo.createPolygon(t,{color:this.config.colors.polygon.border,weight:this.config.polygonOptions.weight,opacity:.9,fill:!1,fillOpacity:0,dashArray:"4,6",interactive:!1});e.addTo(this.map),this.currentCloneGhost=e}catch{}}clearCloneGhost(){if(this.currentCloneGhost){try{this.map.removeLayer(this.currentCloneGhost)}catch{}this.currentCloneGhost=null}}createPolygonFeatureFromLatLngs(t){try{return Wo.createPolygon(t).toGeoJSON()}catch{return null}}getDragSubtractModifierKey(){const{keys:t}=this.config.dragPolygons.modifierSubtract,e=navigator.userAgent.toLowerCase(),n=e.includes("mac"),i=e.includes("windows");return n&&t.mac?t.mac:i&&t.windows?t.windows:t.linux?t.linux:n?"metaKey":"ctrlKey"}detectDragSubtractModifierKey(t){if(zo())return!1;return t[this.getDragSubtractModifierKey()]||!1}setSubtractVisualMode(t,e){if(t&&t.setStyle)try{e?t.setStyle({color:this.config.colors.dragPolygons.subtract}):t.setStyle({color:this.config.colors.polygon.border}),this.updateMarkerColorsForSubtractMode(t,e)}catch{}}updateMarkerColorsForSubtractMode(t,e){try{let n=null;for(const e of this.getFeatureGroups())if(e.eachLayer(i=>{i===t&&(n=e)}),n)break;if(!n)return;const i=n,r=this.config.dragPolygons.modifierSubtract.hideMarkersOnDrag;i.eachLayer(t=>{if(t instanceof a.Marker){const n=t.getElement();n&&(e?r?(n.style.display="none",n.classList.add("subtract-mode-hidden")):(n.style.backgroundColor=this.config.colors.dragPolygons.subtract,n.style.borderColor=this.config.colors.dragPolygons.subtract,n.classList.add("subtract-mode")):r?(n.style.display="",n.classList.remove("subtract-mode-hidden")):(n.style.backgroundColor="",n.style.borderColor="",n.classList.remove("subtract-mode")))}})}catch{}}handleModifierToggleDuringDrag(t){const e=this.detectDragSubtractModifierKey(t);this.currentModifierDragMode=e,this.isModifierKeyHeld=e,this.currentDragPolygon&&this.setSubtractVisualMode(this.currentDragPolygon,e)}isModifierDragActive(){return this.currentModifierDragMode}performModifierSubtract(t,e){try{const n=this.turfHelper.getTurfPolygon(t),i=[];this.getFeatureGroups().forEach(t=>{if(t!==e)try{const e=t.toGeoJSON();if(!e||!e.features||!e.features[0])return;const r=e.features[0];if(!r.geometry||!r.geometry.coordinates)return;const o=this.turfHelper.getTurfPolygon(r);try{const e=this.turfHelper.getIntersection(o,n);if(e&&e.geometry&&"coordinates"in e.geometry){e.geometry.coordinates.length>0&&i.push(t)}}catch{try{this.turfHelper.polygonIntersect(o,n)&&i.push(t)}catch{}}}catch{}}),this.removeFeatureGroup(e),i.forEach(t=>{try{const i=t.toGeoJSON(),r=this.turfHelper.getTurfPolygon(i.features[0]),{level:o,original:s}=this.getOptimizationMetadataFromFeatureGroup(t);this.cleanupFeatureGroup(t),this.removeFeatureGroup(t);try{const t=this.turfHelper.polygonDifference(r,n);if(t&&t.geometry){const e=this.turfHelper.getCoords(t);for(const t of e){const e=this.turfHelper.getMultiPolygon([t]);this.emitPolygonUpdated({operation:"modifierSubtract",polygon:this.turfHelper.getTurfPolygon(e),allowMerge:!1,optimizationLevel:o,originalOptimizationLevel:s})}}}catch(e){Ho()||console.warn("Failed to perform difference operation:",e),this.emitPolygonUpdated({operation:"modifierSubtractFallback",polygon:r,allowMerge:!1,optimizationLevel:o,originalOptimizationLevel:s})}}catch(i){Ho()||console.warn("Error in modifier subtract operation:",i)}}),this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups())}catch(n){Ho()||console.warn("Error in performModifierSubtract:",n)}}getEdgeDeletionModifierKey(){const{keys:t}=this.config.edgeDeletion,e=navigator.userAgent.toLowerCase(),n=e.includes("mac"),i=e.includes("windows");return n&&t.mac?t.mac:i&&t.windows?t.windows:t.linux?t.linux:n?"metaKey":"ctrlKey"}isEdgeDeletionModifierKeyPressed(t){if(zo())return!1;return!!t[this.getEdgeDeletionModifierKey()]}onMarkerHoverForEdgeDeletion(t,e){const n=t.getElement();if(n)if(e){const e=t=>{if(this.isEdgeDeletionModifierKeyPressed(t)){n.style.backgroundColor=this.config.colors.edgeDeletion.hover,n.style.borderColor=this.config.colors.edgeDeletion.hover,n.classList.add("edge-deletion-hover");try{this.map.getContainer().style.cursor="pointer"}catch{}}else{n.style.backgroundColor="",n.style.borderColor="",n.classList.remove("edge-deletion-hover");try{this.map.getContainer().style.cursor=""}catch{}}};e(new MouseEvent("mouseover")),this.markerModifierHandlers.set(t,e),document.addEventListener("keydown",e),document.addEventListener("keyup",e),n.addEventListener("mousemove",e)}else{n.style.backgroundColor="",n.style.borderColor="",n.classList.remove("edge-deletion-hover");try{this.map.getContainer().style.cursor=""}catch{}const e=this.markerModifierHandlers.get(t);e&&(document.removeEventListener("keydown",e),document.removeEventListener("keyup",e),n.removeEventListener("mousemove",e),this.markerModifierHandlers.delete(t))}}getMarkerIndex(t,e){const n=Yo.getBounds(t,Math.sqrt(2)/2),i=new Uo(n.getSouth(),n.getWest(),n.getNorth(),n.getEast()).getDirection(e),r={lat:i.lat,lng:i.lng},o=this.turfHelper.getCoord(r),s=this.turfHelper.getFeaturePointCollection(t);return this.turfHelper.getNearestPointIndex(o,s)}ensureMarkerSeparation(t,e){const n=[];if(e.menu.enabled&&n.push({type:"menu",index:e.menu.index}),e.delete.enabled&&n.push({type:"delete",index:e.delete.index}),e.info.enabled&&n.push({type:"info",index:e.info.index}),n.length<2)return{menu:e.menu.index,delete:e.delete.index,info:e.info.index};const i={...e},r=new Set,o=["info","delete","menu"];for(const s of o){const e=i[s];if(e.enabled)if(r.has(e.index)){const n=this.findAlternativeMarkerPosition(t,e.index,r);i[s].index=n,r.add(n)}else r.add(e.index)}return{menu:i.menu.index,delete:i.delete.index,info:i.info.index}}findAlternativeMarkerPosition(t,e,n){const i=t,r=Math.max(1,Math.floor(t/8));for(let o=1;o<i;o++){const i=[(e+o*r)%t,(e-o*r+t)%t];for(const t of i)if(!n.has(t))return t}for(let o=0;o<t;o++)if(!n.has(o))return o;return e}createDivIcon(t){return as.createDivIcon(t)}getLatLngInfoString(t){return"Latitude: "+t.lat+" Longitude: "+t.lng}setMarkerVisibility(t,e){const n=this.getFeatureGroups().find(e=>e.hasLayer(t));n&&n.eachLayer(t=>{if(t instanceof a.Marker){const n=t.getElement();if(n){const t=this.config.dragPolygons.markerBehavior,i=this.config.dragPolygons.markerAnimationDuration;"hide"===t?n.style.display=e?"":"none":"fade"===t&&(n.style.transition=`opacity ${i}ms ease`,n.style.opacity=e?"1":"0")}}})}generateMenuMarkerPopup(t,e){var n;const i=[],r=this.config.menuOperations;if(r.simplify.enabled&&i.push(_s.createMenuButton("simplify","Simplify",["simplify"])),r.doubleElbows.enabled&&i.push(_s.createMenuButton("doubleElbows","DoubleElbows",["double-elbows"])),r.bbox.enabled&&i.push(_s.createMenuButton("bbox","Bounding box",["bbox"])),r.bezier.enabled&&i.push(_s.createMenuButton("bezier","Curve",["bezier"])),r.scale.enabled&&i.push(_s.createMenuButton("scale","Scale",["transform-scale"])),r.rotate.enabled&&i.push(_s.createMenuButton("rotate","Rotate",["transform-rotate"])),null==(n=r.visualOptimizationToggle)?void 0:n.enabled){const{level:t,original:n}=this.getOptimizationMetadataFromFeatureGroup(e);if(n>0||t>0){const e="number"==typeof t&&t>0,n=["toggle-visual-optimization",e?"visual-optimization-state-hidden":"visual-optimization-state-visible"],r=e?"Show all markers":"Hide extra markers";i.push(_s.createMenuButton("toggleOptimization",r,n))}}const o=_s.buildMenuPopup(i),s=o.querySelector(".marker-menu-close");if(s){const t=t=>{t.stopPropagation(),t.preventDefault(),this._openMenuPopup?(this.map.closePopup(this._openMenuPopup),this._openMenuPopup=null):this.map.closePopup()};s.addEventListener("click",t),s.addEventListener("touchend",t,{passive:!1})}const l=()=>{this._openMenuPopup&&(this.map.closePopup(this._openMenuPopup),this._openMenuPopup=null)},u=(n,i)=>{n.addEventListener("touchend",n=>{n.preventDefault(),n.stopPropagation(),this.eventManager.emit("polydraw:menu:action",{action:i,latLngs:t,featureGroup:e}),l()}),n.onclick=()=>{this.eventManager.emit("polydraw:menu:action",{action:i,latLngs:t,featureGroup:e}),l()}},h=t=>{const n=this.transformControllers.get(e);n&&(n.cancel(),n.destroy(),this.transformControllers.delete(e));try{const n=new vs(this.map,e,t,i=>{this.transformControllers.get(e)===n&&this.transformControllers.delete(e),this.transformModeActive=!1;const r=e.getLayers().find(t=>t instanceof a.Polygon);if(!r)return;if(!i)return void this.setMarkerVisibility(r,!0);this.saveHistoryState&&this.saveHistoryState(t);const o=r.toGeoJSON(),{level:s,original:l}=this.getOptimizationMetadataFromFeatureGroup(e);this.cleanupFeatureGroup(e),this.removeFeatureGroup(e),this.emitPolygonUpdated({operation:"transform",polygon:this.turfHelper.getTurfPolygon(o),allowMerge:!0,optimizationLevel:s,originalOptimizationLevel:l})});this.transformControllers.set(e,n);const i=e.getLayers().find(t=>t instanceof a.Polygon);i&&this.setMarkerVisibility(i,!1),this.transformModeActive=!0}catch{}},c=(t,e)=>{t.addEventListener("touchend",t=>{t.preventDefault(),t.stopPropagation(),h(e),l()}),t.onclick=()=>{h(e),l()}},f=t=>{const n=t=>{t.preventDefault(),t.stopPropagation(),this.toggleOptimizationVisibility(e),l()};t.addEventListener("touchend",n,{passive:!1}),t.onclick=n};i.forEach(t=>{switch(t.getAttribute("data-action-id")){case"simplify":u(t,"simplify");break;case"doubleElbows":u(t,"doubleElbows");break;case"bbox":u(t,"bbox");break;case"bezier":u(t,"bezier");break;case"scale":c(t,"scale");break;case"rotate":c(t,"rotate");break;case"toggleOptimization":f(t)}}),a.DomEvent.disableClickPropagation(o),o.style.pointerEvents="auto",o.querySelectorAll(".marker-menu-button").forEach(t=>{t.style.pointerEvents="auto",t.addEventListener("click",t=>t.stopPropagation())});const g=window.innerWidth<=600,d=Ko.isV1()?" leaflet-v1":" leaflet-v2",p=Wo.createPopup({closeButton:!1,autoClose:!0,className:`menu-popup${g?" mobile-popup":""}${d}`}).setContent(o);return this._openMenuPopup=p,p}toggleOptimizationVisibility(t){const e=t.getLayers().find(t=>t instanceof a.Polygon);if(!e)return;const n=this.getOptimizationMetadataFromFeatureGroup(t);if(!n.original&&!n.level)return;const i=n.level>0?0:n.original>0?n.original:n.level;if(i===n.level)return;const r=e.toGeoJSON();this.cleanupFeatureGroup(t),this.removeFeatureGroup(t),this.emitPolygonUpdated({operation:"toggleOptimization",polygon:this.turfHelper.getTurfPolygon(r),allowMerge:!0,optimizationLevel:i,originalOptimizationLevel:n.original||i})}getPolygonGeoJSONFromFeatureGroup(t){try{const e=t.getLayers().find(t=>t instanceof a.Polygon);if(!e)throw new Error("No polygon found in feature group");return e.toGeoJSON()}catch(e){return Ho()||(e instanceof Error?console.warn("Error getting polygon GeoJSON from feature group:",e.message):console.warn("Error getting polygon GeoJSON from feature group:",e)),{type:"Feature",geometry:{type:"Polygon",coordinates:[[[0,0],[0,1],[1,1],[1,0],[0,0]]]},properties:{}}}}getTotalPolygonPerimeter(t){try{if(!t||!t.geometry)return 0;let e=0;if("Polygon"===t.geometry.type){const n=t.geometry.coordinates;for(const t of n){const n={type:"Feature",geometry:{type:"Polygon",coordinates:[t]},properties:{}};e+=this.turfHelper.getPolygonPerimeter(n)}}else if("MultiPolygon"===t.geometry.type){const n=t.geometry.coordinates;for(const t of n)for(const n of t){const t={type:"Feature",geometry:{type:"Polygon",coordinates:[n]},properties:{}};e+=this.turfHelper.getPolygonPerimeter(t)}}return 1e3*e}catch(e){return Ho()||(e instanceof Error?console.warn("Error calculating total polygon perimeter:",e.message):console.warn("Error calculating total polygon perimeter:",e)),1e3*this.turfHelper.getPolygonPerimeter(t)}}generateInfoMarkerPopup(t,e){var n,i;const r=new Xo(e,this.config),o=new qo(t,this.config),s=this.config.markers.markerInfoIcon??{},l=!1!==s.showArea,u=!1!==s.showPerimeter,h=!1!==s.useMetrics,c=null==(n=s.areaLabel)?void 0:n.trim(),f=null==(i=s.perimeterLabel)?void 0:i.trim(),g=document.createElement("div");g.classList.add("info-marker-outer-wrapper");const d=document.createElement("div");d.classList.add("info-marker-wrapper");const p=document.createElement("div");p.classList.add("content");const y=document.createElement("div");if(y.classList.add("info-marker-content"),l){const t=h?`${o.metricArea} ${o.metricUnit}`:`${o.imperialArea} ${o.imperialUnit}`,e=document.createElement("div");e.classList.add("info-item","area"),e.innerHTML=c&&c.length>0?`<strong>${c}:</strong> ${t}`:t,y.appendChild(e)}if(u){const t=h?`${r.metricLength} ${r.metricUnit}`:`${r.imperialLength} ${r.imperialUnit}`,e=document.createElement("div");e.classList.add("info-item","perimeter"),e.innerHTML=f&&f.length>0?`<strong>${f}:</strong> ${t}`:t,y.appendChild(e)}p.appendChild(y),g.appendChild(d),d.appendChild(p),a.DomEvent.disableClickPropagation(g),g.style.pointerEvents="auto",g.querySelectorAll("button").forEach(t=>{t.style.pointerEvents="auto",t.addEventListener("click",t=>t.stopPropagation())});const m=window.innerWidth<=600;return Wo.createPopup({closeButton:!0,autoClose:!0,className:"info-popup"+(m?" mobile-popup":"")}).setContent(g)}}class xs{constructor(t){o(this,"turfHelper"),o(this,"map"),o(this,"config"),o(this,"eventManager"),o(this,"getFeatureGroups"),o(this,"saveHistoryState"),o(this,"geometryManager"),o(this,"interactionManager"),this.turfHelper=t.turfHelper,this.map=t.map,this.config=t.config,this.eventManager=t.eventManager,this.getFeatureGroups=t.getFeatureGroups,this.saveHistoryState=t.saveHistoryState,this.initializeSpecializedManagers(t)}initializeSpecializedManagers(t){this.geometryManager=new ss({turfHelper:t.turfHelper,config:t.config}),this.interactionManager=new ks({turfHelper:t.turfHelper,polygonInformation:t.polygonInformation,map:t.map,config:t.config,modeManager:t.modeManager,eventManager:this.eventManager,saveHistoryState:t.saveHistoryState},{getFeatureGroups:this.getFeatureGroups,addFeatureGroup:t=>this.addFeatureGroupInternal(t),removeFeatureGroup:t=>this.removeFeatureGroupInternal(t)}),this.setupEventForwarding()}setupEventForwarding(){this.eventManager.on("polydraw:draw:cancel",t=>{this.emit("drawCancelled",t)}),this.eventManager.on("polydraw:polygon:updated",t=>{this.handlePolygonModified(t)}),this.eventManager.on("polydraw:menu:action",t=>{this.handleMenuAction(t)}),this.eventManager.on("polydraw:check:intersection",t=>{const e=this.geometryManager.checkPolygonIntersection(t.polygon1,t.polygon2);t.callback(e)}),this.eventManager.on("polydraw:subtract",t=>{this.subtractPolygon(t.subtractPolygon)}),this.eventManager.on("polydraw:polygon:deleted",()=>{this.emit("polygonDeleted",void 0)})}async handlePolygonModified(t){const e=new Set(["addVertex","markerDrag","polygonDrag","polygonClone","toggleOptimization"]),n=!t.operation||!e.has(t.operation);let i=t.allowMerge;t.intelligentMerge&&"markerDrag"===t.operation&&(i=this.shouldAllowIntelligentMerge(t.polygon));const r={simplify:n,noMerge:!i,visualOptimizationLevel:t.optimizationLevel||0,originalOptimizationLevel:t.originalOptimizationLevel,skipKinkProcessing:"markerDrag"===t.operation};await this.addPolygon(t.polygon,r)}async handleMenuAction(t){var e,n,i,r;this.saveHistoryState&&this.saveHistoryState(t.action);const o=this.getCompletePolygonFromFeatureGroup(t.featureGroup),{level:s,original:l}=this.getOptimizationMetadataFromFeatureGroup(t.featureGroup);let u;switch(this.removeFeatureGroupInternal(t.featureGroup),t.action){case"simplify":u=this.geometryManager.simplifyPolygon(o);break;case"bbox":u=this.geometryManager.convertToBoundingBox(o);break;case"doubleElbows":u=this.geometryManager.doubleElbowsPolygon(o);break;case"bezier":u=this.geometryManager.bezierifyPolygon(o);break;default:return}if(u.success&&u.result){const o="bezier"===t.action?(null==(e=this.config.bezier)?void 0:e.visualOptimizationLevel)??10:s,h="bezier"===t.action?(null==(n=this.config.bezier)?void 0:n.visualOptimizationLevel)??10:l,c=await this.addPolygon(u.result,{simplify:!1,visualOptimizationLevel:o,originalOptimizationLevel:h});if("bezier"===t.action&&(null==(i=this.config.bezier)?void 0:i.ghostMarkers)){const t=.001;null==(r=c.featureGroups)||r.forEach(e=>{e.eachLayer(e=>{if(e instanceof a.Polygon){const n=e;n.setStyle({opacity:t,fillOpacity:t}),n._polydrawDragData&&(n._polydrawDragData.originalOpacity=t)}})})}}}get polygonInteractionManager(){return this.interactionManager}on(t,e){this.eventManager.on(t,e)}emit(t,e){this.eventManager.emit(t,e)}async addPolygon(t,e={}){const{polygons:n,skipMerge:i}=this.preparePolygonsForAddition(t,e),r=[];for(const o of n){const t=await this.addPolygonWithMergeHandling(o,e,i);if(!t.success)return t;t.featureGroups&&t.featureGroups.length>0&&r.push(...t.featureGroups)}return{success:!0,featureGroups:r.length>0?r:void 0}}async addPolygonWithMergeHandling(t,e,n){const{noMerge:i=!1}=e;try{return this.isPolygonInsideExistingHole(t)?await this.addPolygonLayer(t,e):this.config.mergePolygons&&!i&&this.getFeatureGroups().length>0&&!n?await this.mergePolygon(t,e):await this.addPolygonLayer(t,e)}catch(r){return{success:!1,error:r instanceof Error?r.message:"Unknown error in addPolygon"}}}preparePolygonsForAddition(t,e={}){let n=!1;try{n=this.turfHelper.hasKinks(t)}catch(i){Ho()||console.warn("Error detecting polygon kinks:",i instanceof Error?i.message:String(i))}if(!(!0===e.skipKinkProcessing)&&!this.config.kinks&&n)try{const e=this.turfHelper.getKinks(t);if(e.length>0)return{polygons:e,skipMerge:!1}}catch(i){Ho()||console.warn("Error splitting polygon kinks:",i instanceof Error?i.message:String(i))}return{polygons:[t],skipMerge:this.config.kinks&&n}}async subtractPolygon(t,e={}){const{simplify:n=!0,visualOptimizationLevel:i,originalOptimizationLevel:r}=e;try{const e=[];this.getFeatureGroups().forEach(n=>{try{const i=n.toGeoJSON();if(!i||!i.features||!i.features[0])return;const r=i.features[0];if(!r.geometry||!r.geometry.coordinates)return;const o=this.turfHelper.getTurfPolygon(r);this.geometryManager.checkPolygonIntersection(o,t)&&e.push(n)}catch{}});const o=[];for(const s of e)try{const e=s.toGeoJSON(),a=this.turfHelper.getTurfPolygon(e.features[0]),l=this.geometryManager.subtractPolygon(a,t);if(this.removeFeatureGroupInternal(s),l.success&&l.results)for(const t of l.results){const e=await this.addPolygonLayer(t,{simplify:n,visualOptimizationLevel:i,originalOptimizationLevel:r});e.success&&e.featureGroups&&o.push(...e.featureGroups)}}catch{}return this.emit("polygonSubtracted",{subtractedPolygon:t,affectedFeatureGroups:e,resultFeatureGroups:o}),this.emit("polygonOperationComplete",{operation:"subtract",polygon:t,resultFeatureGroups:o}),{success:!0,featureGroups:o}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error in subtractPolygon"}}}async addPolygonLayer(t,e={}){const{simplify:n=!0,dynamicTolerance:i=!1,visualOptimizationLevel:r=0,originalOptimizationLevel:o}=e;try{if(!t||!t.geometry||!t.geometry.coordinates)return{success:!1,error:"Invalid polygon data"};const e=new a.FeatureGroup,s=n?this.turfHelper.getSimplified(t,i):t;let l,u,h=r;try{if(l=this.getPolygon(s),!l)return{success:!1,error:"Failed to create polygon"};l._polydrawOptimizationLevel=r,h=o??l._polydrawOptimizationOriginalLevel??r,l._polydrawOptimizationOriginalLevel=h||0,e.addLayer(l),this.interactionManager.suppressDeleteMarkerClicks(250)}catch{return{success:!1,error:"Failed to create polygon layer"}}try{const t=l.getLatLngs();u=this.normalizePolygonCoordinates(t)}catch{u=[]}try{u.forEach((t,n)=>{if(!t||!Array.isArray(t))return;const i=[];if(t.forEach(t=>{Array.isArray(t)&&t.length>=2?i.push({lat:t[1],lng:t[0]}):"object"==typeof t&&null!==t&&"lat"in t&&"lng"in t&&i.push(t)}),0!==i.length)try{if(0===n)this.interactionManager.addMarkers(i,e,{optimizationLevel:r,originalOptimizationLevel:h});else{const t=Wo.createPolyline(i,{color:this.config.colors.hole.border,weight:this.config.holeOptions.weight||2,opacity:this.config.holeOptions.opacity||1,fillColor:this.config.colors.hole.fill,fillOpacity:this.config.holeOptions.fillOpacity||.5});e.addLayer(t),this.interactionManager.addHoleMarkers(i,e)}}catch{}})}catch{}try{this.interactionManager.addEdgeClickListeners(l,e)}catch{}this.getFeatureGroups().push(e);try{e.addTo(this.map)}catch{}return this.emit("polygonAdded",{polygon:s,featureGroup:e}),this.emit("polygonOperationComplete",{operation:"add",polygon:s,featureGroup:e}),{success:!0,featureGroups:[e]}}catch(s){return{success:!1,error:s instanceof Error?s.message:"Unknown error in addPolygonLayer"}}}async mergePolygon(t,e={}){try{const n=[],i=[];let r=!1;return this.getFeatureGroups().forEach(e=>{try{const o=e.toGeoJSON();if(!o||!o.features||!o.features[0])return;const s=o.features[0];if(!s.geometry||!s.geometry.coordinates)return;if(this.isPositionArrayofArrays(s.geometry.coordinates))s.geometry.coordinates.forEach(o=>{try{const s=this.turfHelper.getMultiPolygon([o]);r=this.geometryManager.checkPolygonIntersection(s,t),r&&(i.push(e),n.push(s))}catch{}});else try{const o=this.turfHelper.getTurfPolygon(s);r=this.geometryManager.checkPolygonIntersection(o,t),r&&(i.push(e),n.push(o))}catch{}}catch{}}),i.length>0?await this.unionPolygons(i,t,n,e):await this.addPolygonLayer(t,e)}catch(n){return{success:!1,error:n instanceof Error?n.message:"Unknown error in mergePolygon"}}}async unionPolygons(t,e,n,i={}){try{t.forEach(t=>{this.removeFeatureGroupInternal(t)});const r=this.geometryManager.unionPolygons(n,e);if(r.success&&r.result){const t=await this.addPolygonLayer(r.result,i);return this.emit("polygonsUnioned",{originalPolygons:n,resultPolygon:r.result,featureGroups:t.featureGroups}),t}return{success:!1,error:r.error||"Failed to union polygons"}}catch(r){return{success:!1,error:r instanceof Error?r.message:"Unknown error in unionPolygons"}}}shouldAllowIntelligentMerge(t){try{for(const e of this.getFeatureGroups())try{const n=e.toGeoJSON();if(!n||!n.features||!n.features[0])continue;const i=n.features[0];if(!i.geometry||!i.geometry.coordinates)continue;const r=this.turfHelper.getTurfPolygon(i);if(this.geometryManager.checkPolygonIntersection(r,t))return!0}catch{continue}return!1}catch{return!1}}isPolygonInsideExistingHole(t){try{for(const e of this.getFeatureGroups())try{const n=e.toGeoJSON();if(!n||!n.features||!n.features[0])continue;const i=n.features[0];if(!i.geometry||!i.geometry.coordinates)continue;let r=!1,o=[];if("Polygon"===i.geometry.type)r=i.geometry.coordinates.length>1,r&&(o=i.geometry.coordinates.slice(1));else if("MultiPolygon"===i.geometry.type)for(const t of i.geometry.coordinates)t.length>1&&(r=!0,o.push(...t.slice(1)));if(r&&o.length>0)for(const e of o)try{const n=this.turfHelper.createPolygon([e]);if(this.turfHelper.isPolygonCompletelyWithin(t,n))return!0}catch{continue}}catch{continue}return!1}catch{return!1}}normalizePolygonCoordinates(t){if(!Array.isArray(t)||0===t.length)return[];const e=t=>null!==t&&"object"==typeof t&&"lat"in t&&"lng"in t&&"number"==typeof t.lat&&"number"==typeof t.lng,n=t=>{if(!Array.isArray(t))return[];if(t.length>0&&e(t[0]))return[t];const i=[];for(const r of t)if(Array.isArray(r))if(r.length>0&&e(r[0]))i.push(r);else{const t=n(r);i.push(...t)}return i};try{return n(t)}catch{return[]}}isPositionArrayofArrays(t){if(!Array.isArray(t)||0===t.length)return!1;const e=t[0];if(!Array.isArray(e)||0===e.length)return!1;const n=e[0];if(!Array.isArray(n)||0===n.length)return!1;const i=n[0];return this.isPosition(i)}isPosition(t){return Array.isArray(t)&&t.length>=2&&t.every(t=>"number"==typeof t)}getPolygon(t){const e=a.GeoJSON.geometryToLayer(t),n={...this.config.polygonOptions,color:this.config.colors.polygon.border,fillColor:this.config.colors.polygon.fill,weight:this.config.polygonOptions.weight||2,opacity:this.config.polygonOptions.opacity||1,fillOpacity:this.config.polygonOptions.fillOpacity||.2};return e.setStyle(n),e._polydrawUniqueId=Wo.util.stamp(e)+"_"+Date.now(),delete e._polydrawDragData,delete e._polydrawOriginalLatLngs,delete e._polydrawCurrentDragSession,delete e._polydrawOriginalMarkerPositions,delete e._polydrawOriginalHoleLinePositions,this.config.modes.dragPolygons&&this.interactionManager.enablePolygonDragging(e,t),e}addFeatureGroupInternal(t){this.getFeatureGroups().push(t)}removeFeatureGroupInternal(t){this.cleanupFeatureGroup(t),t.clearLayers();const e=this.getFeatureGroups(),n=e.indexOf(t);n>-1&&e.splice(n,1),this.map.removeLayer(t)}getCompletePolygonFromFeatureGroup(t){try{let e=null;if(t.eachLayer(t=>{t instanceof a.Polygon&&(e=t)}),!e)throw new Error("No polygon found in feature group");return e.toGeoJSON()}catch(e){return Ho()||e instanceof Error&&console.warn("Error getting complete polygon GeoJSON from feature group:",e.message),{type:"Feature",geometry:{type:"Polygon",coordinates:[[[0,0],[0,1],[1,1],[1,0],[0,0]]]},properties:{}}}}getOptimizationMetadataFromFeatureGroup(t){if(!t)return{level:0,original:0};let e=0,n=0;return t.eachLayer(t=>{if(t instanceof a.Polygon){const i=t;"number"==typeof i._polydrawOptimizationLevel&&(e=i._polydrawOptimizationLevel||0),"number"==typeof i._polydrawOptimizationOriginalLevel&&(n=i._polydrawOptimizationOriginalLevel||0)}}),!n&&e>0&&(n=e),{level:e,original:n}}updateMarkerDraggableState(){this.interactionManager.updateMarkerDraggableState()}updateAllMarkersForEdgeDeletion(t){this.interactionManager.updateAllMarkersForEdgeDeletion(t)}setModifierKeyHeld(t){this.interactionManager.setModifierKeyHeld(t)}checkPolygonIntersection(t,e){return this.geometryManager.checkPolygonIntersection(t,e)}getPolygonCenter(t){try{if(!t||!t.geometry||!t.geometry.coordinates)return null;let e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else{if("MultiPolygon"!==t.geometry.type)return null;e=t.geometry.coordinates[0][0]}if(!Array.isArray(e)||0===e.length)return null;let n=0,i=0,r=0;for(const t of e)if(Array.isArray(t)&&t.length>=2){const e=t[0],o=t[1];"number"!=typeof e||"number"!=typeof o||isNaN(e)||isNaN(o)||(i+=e,n+=o,r++)}return 0===r?null:{lat:n/r,lng:i/r}}catch{return null}}getBoundingBox(t){try{if(!t||!t.geometry||!t.geometry.coordinates)return null;let e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else{if("MultiPolygon"!==t.geometry.type)return null;e=t.geometry.coordinates[0][0]}if(!Array.isArray(e)||0===e.length)return null;let n=1/0,i=-1/0,r=1/0,o=-1/0;for(const t of e)if(Array.isArray(t)&&t.length>=2){const e=t[0],s=t[1];"number"!=typeof e||"number"!=typeof s||isNaN(e)||isNaN(s)||(r=Math.min(r,e),o=Math.max(o,e),n=Math.min(n,s),i=Math.max(i,s))}return n===1/0||i===-1/0||r===1/0||o===-1/0?null:{minLat:n,maxLat:i,minLng:r,maxLng:o}}catch{return null}}addMarker(t,e,n){this.interactionManager.addMarkers(t,e,n)}addHoleMarker(t,e){this.interactionManager.addHoleMarkers(t,e)}addEdgeClickListeners(t,e){this.interactionManager.addEdgeClickListeners(t,e)}enablePolygonDragging(t,e){this.interactionManager.enablePolygonDragging(t,e)}getMarkerIndex(t,e){return 0}ensureMarkerSeparation(t,e){var n,i,r;return{menu:(null==(n=e.menu)?void 0:n.index)??0,delete:(null==(i=e.delete)?void 0:i.index)??1,info:(null==(r=e.info)?void 0:r.index)??2}}findAlternativeMarkerPosition(t,e,n){return(e+1)%t}createDivIcon(t){return Wo.createDivIcon({className:t.join(" ")})}getLatLngInfoString(t){return"Latitude: "+t.lat+" Longitude: "+t.lng}generateMenuMarkerPopup(t,e){const n=document.createElement("div");return n.innerHTML="Menu",n}getPolygonGeoJSONFromFeatureGroup(t){return{type:"Feature",geometry:{type:"Polygon",coordinates:[[[0,0],[0,1],[1,1],[1,0],[0,0]]]},properties:{}}}getTotalPolygonPerimeter(t){return 1e3}generateInfoMarkerPopup(t,e){const n=document.createElement("div");return n.innerHTML=`Area: ${t}, Perimeter: ${e}`,n}onMarkerHoverForEdgeDeletion(t,e){}highlightEdgeOnHover(t,e){}onEdgeClick(t,e){}removeFeatureGroup(t){this.removeFeatureGroupInternal(t)}cleanupFeatureGroup(t){this.interactionManager.cleanupFeatureGroup(t)}onPolygonMouseMove(t){}onPolygonMouseUp(t){}updatePolygonAfterDrag(t){}setSubtractVisualMode(t,e){}performModifierSubtract(t,e){try{const n=this.turfHelper.getTurfPolygon(t),i=[];this.getFeatureGroups().forEach(t=>{if(t!==e)try{const e=t.toGeoJSON();if(!e||!e.features||!e.features[0])return;const r=e.features[0];if(!r.geometry||!r.geometry.coordinates)return;const o=this.turfHelper.getTurfPolygon(r);this.geometryManager.checkPolygonIntersection(o,n)&&i.push(t)}catch{}}),this.removeFeatureGroupInternal(e),i.forEach(t=>{try{const e=t.toGeoJSON(),i=this.turfHelper.getTurfPolygon(e.features[0]);this.removeFeatureGroupInternal(t);const r=this.geometryManager.subtractPolygon(i,n);if(r.success&&r.results)for(const t of r.results)this.addPolygonLayer(t,{simplify:!0})}catch{}})}catch{}}}class Es{constructor(t,e=50){o(this,"undoStack",[]),o(this,"redoStack",[]),o(this,"maxHistorySize",50),o(this,"maxSnapshotSize",5e5),o(this,"maxTotalMemory",5e6),o(this,"currentMemoryUsage",0),o(this,"eventManager"),o(this,"isRestoring",!1),this.eventManager=t,this.maxHistorySize=e}saveState(t,e){if(this.isRestoring)return;const n=this.createSnapshot(t,e),i=this.calculateSnapshotSize(n);n.size=i,this.redoStack=[],i>this.maxSnapshotSize?console.warn(`History snapshot too large (${i} bytes, limit ${this.maxSnapshotSize} bytes). Skipping save.`):(this.undoStack.push(n),this.currentMemoryUsage+=i,this.enforceMemoryBudget(),this.eventManager.emit("polydraw:history:changed",{canUndo:this.canUndo(),canRedo:this.canRedo()}))}calculateSnapshotSize(t){try{return 2*JSON.stringify(t).length}catch(e){return console.warn("Error calculating snapshot size:",e),0}}enforceMemoryBudget(){for(;this.undoStack.length>this.maxHistorySize;){const t=this.undoStack.shift();t&&(this.currentMemoryUsage-=this.getSnapshotSize(t))}for(;this.currentMemoryUsage>this.maxTotalMemory&&this.undoStack.length>0;){const t=this.undoStack.shift();t&&(this.currentMemoryUsage-=this.getSnapshotSize(t))}}enforceRedoMemoryBudget(){const t=Math.floor(this.maxHistorySize/2);for(;this.redoStack.length>t;)this.redoStack.shift()}undo(t){if(!this.canUndo())return null;const e=this.createSnapshot(t,"redo-point"),n=this.calculateSnapshotSize(e);e.size=n,n<=this.maxSnapshotSize?(this.redoStack.push(e),this.enforceRedoMemoryBudget()):console.warn(`Current state too large (${n} bytes) to save to redo stack.`);const i=this.undoStack.pop();return this.currentMemoryUsage-=this.getSnapshotSize(i),this.eventManager.emit("polydraw:history:undo",{canUndo:this.canUndo(),canRedo:this.canRedo(),action:i.action}),i}redo(t){if(!this.canRedo())return null;const e=this.createSnapshot(t,"undo-point"),n=this.calculateSnapshotSize(e);e.size=n,n<=this.maxSnapshotSize?(this.undoStack.push(e),this.currentMemoryUsage+=n,this.enforceMemoryBudget()):console.warn(`Current state too large (${n} bytes) to save to undo stack.`),this.enforceRedoMemoryBudget();const i=this.redoStack.pop();return this.eventManager.emit("polydraw:history:redo",{canUndo:this.canUndo(),canRedo:this.canRedo(),action:i.action}),i}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}clear(){this.undoStack=[],this.redoStack=[],this.currentMemoryUsage=0,this.eventManager.emit("polydraw:history:changed",{canUndo:this.canUndo(),canRedo:this.canRedo()})}setRestoring(t){this.isRestoring=t}createSnapshot(t,e){const n=[];return t.forEach(t=>{t.eachLayer(t=>{var e;const i=t;if(null==i?void 0:i.toGeoJSON)try{const t=i.toGeoJSON();if(!t)return;const r=null==(e=null==t?void 0:t.geometry)?void 0:e.type;"Polygon"!==r&&"MultiPolygon"!==r||n.push(t)}catch(r){console.warn("Error converting polygon to GeoJSON:",r)}})}),{features:n,timestamp:Date.now(),action:e}}getSnapshotSize(t){if("number"==typeof t.size)return t.size;const e=this.calculateSnapshotSize(t);return t.size=e,e}}class ws{static normalizeEvent(t){return Ko.getVersion()===l.V2&&(t.layer&&!t.propagatedFrom&&(t.propagatedFrom=t.layer),"mousedown"!==t.type&&"touchstart"!==t.type||(t._isPointerEvent=!0)),t}static getEventName(t){if(Ko.getVersion()===l.V2)switch(t){case"mousedown":case"touchstart":return"pointerdown";case"mouseup":case"touchend":return"pointerup";case"mousemove":case"touchmove":return"pointermove";default:return t}return t}static shouldUsePointerEvents(){return Ko.getVersion()===l.V2&&"PointerEvent"in window}static extractCoordinates(t,e){if(t.latlng)return t.latlng;if(t.touches&&t.touches.length>0){const n=e.getContainer().getBoundingClientRect();return e.containerPointToLatLng([t.touches[0].clientX-n.x,t.touches[0].clientY-n.y])}if(t.pointerType&&void 0!==t.clientX&&void 0!==t.clientY){const n=e.getContainer().getBoundingClientRect();return e.containerPointToLatLng([t.clientX-n.x,t.clientY-n.y])}if(void 0!==t.clientX&&void 0!==t.clientY){const n=e.getContainer().getBoundingClientRect();return e.containerPointToLatLng([t.clientX-n.x,t.clientY-n.y])}return null}static shouldPreventDefault(t){return!(!t.type||!t.type.startsWith("touch"))||(!t.pointerType||!1!==t.isPrimary)&&!(!("cancelable"in t)||!t.cancelable)}static getEventNames(){return Ko.getVersion()===l.V2&&this.shouldUsePointerEvents()?{start:["pointerdown"],move:["pointermove"],end:["pointerup"]}:{start:["mousedown","touchstart"],move:["mousemove","touchmove"],end:["mouseup","touchend"]}}}class Ms{static calculateAngle(t,e,n){const i=t.lng-e.lng,r=t.lat-e.lat,o=n.lng-e.lng,s=n.lat-e.lat,a=i*o+r*s,l=Math.sqrt(i*i+r*r),u=Math.sqrt(o*o+s*s);if(0===l||0===u)return 0;const h=a/(l*u);return Math.acos(Math.max(-1,Math.min(1,h)))}static calculateDistanceFromLine(t,e,n){const i=e.lng-t.lng,r=e.lat-t.lat,o=n.lng-t.lng,s=n.lat-t.lat,a=i*o+r*s,l=o*o+s*s;if(0===l)return Math.sqrt(i*i+r*r);const u=a/l;let h,c;u<0?(h=t.lng,c=t.lat):u>1?(h=n.lng,c=n.lat):(h=t.lng+u*o,c=t.lat+u*s);const f=e.lng-h,g=e.lat-c;return Math.sqrt(f*f+g*g)}static calculateCentroid(t){return Qo.getCenter(t)}static calculateDistance(t,e){const n=t.lng-e.lng,i=t.lat-e.lat;return Math.sqrt(n*n+i*i)}static offsetPolygonCoordinates(t,e,n){return t?Array.isArray(t[0])?t.map(t=>Ms.offsetPolygonCoordinates(t,e,n)):void 0!==t.lat&&void 0!==t.lng?{lat:t.lat+e,lng:t.lng+n}:t.map(t=>Ms.offsetPolygonCoordinates(t,e,n)):t}}class Ps{static convertToCoords(t,e){const n=[];if(t.length>1&&t.length<3){const i=[];e.isWithin(a.GeoJSON.latLngsToCoords(t[t.length-1]),a.GeoJSON.latLngsToCoords(t[0]))?t.forEach(t=>{i.push(a.GeoJSON.latLngsToCoords(t))}):t.forEach(t=>{n.push([a.GeoJSON.latLngsToCoords(t)])}),i.length>=1&&n.push(i)}else if(t.length>2){const i=[];for(let r=1;r<t.length-1;r++){e.isWithin(a.GeoJSON.latLngsToCoords(t[r]),a.GeoJSON.latLngsToCoords(t[0]))?(t.forEach(t=>{i.push(a.GeoJSON.latLngsToCoords(t))}),n.push(i)):t.forEach(t=>{n.push([a.GeoJSON.latLngsToCoords(t)])})}}else n.push([a.GeoJSON.latLngsToCoords(t[0])]);return n}static offsetPolygonCoordinates(t,e,n){return Ms.offsetPolygonCoordinates(t,e,n)}static getLatLngInfoString(t){return"Latitude: "+t.lat+" Longitude: "+t.lng}static convertToLatLng(t){if("object"==typeof t&&null!==t){if("lat"in t&&"lng"in t)return Wo.createLatLng(t.lat,t.lng);if("latitude"in t&&"longitude"in t)return Wo.createLatLng(t.latitude,t.longitude);if("longitude"in t&&"latitude"in t)return Wo.createLatLng(t.latitude,t.longitude);if("lng"in t&&"lat"in t)return Wo.createLatLng(t.lat,t.lng)}if(Array.isArray(t)&&t.length>=2){const[e,n]=t;if("number"==typeof e&&"number"==typeof n)return e>90||n>90||e>180||n>180?Wo.createLatLng(n,e):Wo.createLatLng(e,n)}if("string"==typeof t){const e=t.trim();if(e.includes(",")&&!e.includes("°")&&!e.includes("'")&&!e.includes('"')){const t=e.split(",").map(t=>parseFloat(t.trim()));if(t.length>=2&&!isNaN(t[0])&&!isNaN(t[1]))return this.convertToLatLng(t)}const n=e.match(/(\d+)°(\d+)'(?:(\d+(?:\.\d+)?)")?([NS])\s*,?\s*(\d+)°(\d+)'(?:(\d+(?:\.\d+)?)")?([EW])/i);if(n){const[,t,e,i,r,o,s,a,l]=n,u=parseFloat(t)+parseFloat(e)/60+parseFloat(i||"0")/3600,h=parseFloat(o)+parseFloat(s)/60+parseFloat(a||"0")/3600,c="S"===r.toUpperCase()?-u:u,f="W"===l.toUpperCase()?-h:h;return Wo.createLatLng(c,f)}const i=e.match(/(\d+)°(\d+(?:\.\d+)?)'([NS])\s*,?\s*(\d+)°(\d+(?:\.\d+)?)'([EW])/i);if(i){const[,t,e,n,r,o,s]=i,a=parseFloat(t)+parseFloat(e)/60,l=parseFloat(r)+parseFloat(o)/60,u="S"===n.toUpperCase()?-a:a,h="W"===s.toUpperCase()?-l:l;return Wo.createLatLng(u,h)}const r=e.match(/(\d+(?:\.\d+)?)°?\s*([NS])\s*,\s*(\d+(?:\.\d+)?)°?\s*([EW])/i);if(r){const[,t,e,n,i]=r,o="S"===e.toUpperCase()?-parseFloat(t):parseFloat(t),s="W"===i.toUpperCase()?-parseFloat(n):parseFloat(n);return Wo.createLatLng(o,s)}const o=e.match(/N\s*(\d+(?:\.\d+)?)\s+E\s*(\d+(?:\.\d+)?)/i);if(o){const[,t,e]=o;return Wo.createLatLng(parseFloat(t),parseFloat(e))}if(e.match(/(?:UTM\s+)?(\d+)([NS])\s+(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)/i))throw new Error(`UTM coordinates detected: ${e}. UTM conversion requires specialized libraries like proj4js. Please convert to decimal degrees first.`);if(e.match(/(\d+)([A-Z])\s+([A-Z]{2})\s+(\d+)\s+(\d+)/i))throw new Error(`MGRS coordinates detected: ${e}. MGRS conversion requires specialized libraries. Please convert to decimal degrees first.`);if(e.match(/^[23456789CFGHJMPQRVWX]{2,3}[23456789CFGHJMPQRVWX]{3,7}\+[23456789CFGHJMPQRVWX]{2,3}$/i))throw new Error(`Plus Code detected: ${e}. Plus Code conversion requires specialized libraries. Please convert to decimal degrees first.`)}throw new Error(`Unable to convert coordinate: ${JSON.stringify(t)}`)}static convertToLatLngArray(t){return t.map(t=>t.map(t=>t.map(t=>this.convertToLatLng(t))))}}function bs(t,...e){if(!e.length)return t;for(const n of e)if(n)for(const e in n){const i=n[e],r=t[e];if(i&&"object"==typeof i&&!Array.isArray(i)){const n=r&&"object"==typeof r&&!Array.isArray(r)?r:{};t[e]=bs(n,i)}else void 0!==i&&(t[e]=i)}return t}class Is extends a.Control{constructor(t){super(t),o(this,"map"),o(this,"tracer",null),o(this,"turfHelper"),o(this,"subContainer"),o(this,"config"),o(this,"mapStateService"),o(this,"eventManager"),o(this,"polygonInformation"),o(this,"modeManager"),o(this,"polygonDrawManager"),o(this,"polygonMutationManager"),o(this,"historyManager"),o(this,"arrayOfFeatureGroups",[]),o(this,"drawMode",u.Off),o(this,"drawModeListeners",[]),o(this,"_boundKeyDownHandler"),o(this,"_boundKeyUpHandler"),o(this,"isModifierKeyHeld",!1),o(this,"modifierModeOverride",null),o(this,"isDrawingInProgress",!1),o(this,"mapEventsAttached",!1),o(this,"drawEventsAttached",!1),o(this,"controlEvents",new WeakSet),o(this,"lastControlPointerDown",null),o(this,"_boundTouchMove"),o(this,"_boundTouchEnd"),o(this,"_boundTouchStart"),o(this,"_boundPointerDown"),o(this,"_boundPointerMove"),o(this,"_boundPointerUp"),o(this,"_lastTapTime",0),o(this,"_tapTimeout",null),o(this,"pointerEventsHandled","undefined"!=typeof window&&"PointerEvent"in window&&Ko.isV2()),o(this,"_handleActivateToggle",()=>{const t=this.getContainer();if(!t)return;const e=t.querySelector(".icon-activate");if(Wo.domUtil.hasClass(e,"active"))Wo.domUtil.removeClass(e,"active"),this.subContainer&&(this.subContainer.style.maxHeight="0px");else if(Wo.domUtil.addClass(e,"active"),this.subContainer){const t=this.subContainer.scrollHeight;this.subContainer.style.maxHeight=`${t||250}px`}this.updateActivateButtonIndicator()}),o(this,"_handleDrawClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.modeManager.getCurrentMode()!==u.Add?(this.setDrawMode(u.Add),this.polygonInformation.saveCurrentState()):this.setDrawMode(u.Off)}),o(this,"_handleSubtractClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.modeManager.getCurrentMode()!==u.Subtract?(this.setDrawMode(u.Subtract),this.polygonInformation.saveCurrentState()):this.setDrawMode(u.Off)}),o(this,"_handleCloneClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.modeManager.getCurrentMode()!==u.Clone?(this.setDrawMode(u.Clone),this.polygonInformation.saveCurrentState()):this.setDrawMode(u.Off)}),o(this,"_handleEraseClick",t=>{this.map.closePopup(),t&&(t.preventDefault(),t.stopPropagation()),0!==this.arrayOfFeatureGroups.length&&(this.saveHistory("eraseAll"),this.removeAllFeatureGroups())}),o(this,"_handlePointToPointClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.modeManager.getCurrentMode()!==u.PointToPoint?(this.setDrawMode(u.PointToPoint),this.polygonInformation.saveCurrentState()):this.setDrawMode(u.Off)}),o(this,"_handlePointToPointSubtractClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.modeManager.getCurrentMode()!==u.PointToPointSubtract?(this.setDrawMode(u.PointToPointSubtract),this.polygonInformation.saveCurrentState()):this.setDrawMode(u.Off)}),o(this,"_handleUndoClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.undo()}),o(this,"_handleRedoClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.redo()}),o(this,"onMarkerHoverForEdgeDeletionEvent",t=>{if(!this.isModifierKeyHeld)return;const e=t.target;e&&(e.style.backgroundColor=this.config.colors.edgeDeletion.hover,e.style.borderColor=this.config.colors.edgeDeletion.hover,e.classList.add("edge-deletion-hover"))}),o(this,"onMarkerLeaveForEdgeDeletionEvent",t=>{const e=t.target;e&&(e.style.backgroundColor="",e.style.borderColor="",e.classList.remove("edge-deletion-hover"))});const e=structuredClone(c);this.config=bs(e,(null==t?void 0:t.config)??{}),this.warnIfUsingDeprecatedConfiguration(null==t?void 0:t.config),(null==t?void 0:t.configPath)?this.loadExternalConfig(t.configPath,null==t?void 0:t.config):this.initializeComponents()}onAdd(t){const e=t,n=a.Browser;e._onResize=()=>{},n.touch&&n.mobile&&(e.tap=!1),this.map=t,this.setupKeyboardHandlers();const i=Wo.domUtil.create("div","leaflet-control leaflet-bar");return this.initializeUI(i),this.createTracer(),this.initializeManagers(),this.setDrawMode(this.config.defaultMode),this.setupEventListeners(),i}onRemove(t){this.comprehensiveCleanup()}comprehensiveCleanup(){this.events(!1),this.drawStartedEvents(!1),this.removeKeyboardHandlers(),this.tracer&&(this.map.removeLayer(this.tracer),this.tracer=null),this.arrayOfFeatureGroups.forEach(t=>{try{this.polygonMutationManager&&this.polygonMutationManager.cleanupFeatureGroup(t),this.map.removeLayer(t)}catch(e){console.warn("Error cleaning up feature group:",e)}}),this.arrayOfFeatureGroups.length=0,this.polygonInformation&&this.polygonInformation.deletePolygonInformationStorage(),this.drawModeListeners.length=0,this._boundKeyDownHandler&&(this._boundKeyDownHandler=void 0),this._boundKeyUpHandler&&(this._boundKeyUpHandler=void 0),this._boundTouchMove&&(this._boundTouchMove=void 0),this._boundTouchEnd&&(this._boundTouchEnd=void 0),this._boundTouchStart&&(this._boundTouchStart=void 0),this._boundPointerDown&&(this._boundPointerDown=void 0),this._boundPointerMove&&(this._boundPointerMove=void 0),this._boundPointerUp&&(this._boundPointerUp=void 0),this._tapTimeout&&(clearTimeout(this._tapTimeout),this._tapTimeout=null),this.drawMode=u.Off,this.isModifierKeyHeld=!1,this._lastTapTime=0,this.subContainer=void 0}addTo(t){return super.addTo(t),this}getFeatureGroups(){return this.arrayOfFeatureGroups}async undo(){if(!this.historyManager.canUndo())return;const t=this.historyManager.undo(this.arrayOfFeatureGroups);t&&await this.restoreFromSnapshot(t)}isPolygonAction(t){return"simplify"===t||"doubleElbows"===t||"bbox"===t||"bezier"===t||"scale"===t||"rotate"===t||"toggleOptimization"===t}shouldCaptureHistory(t){var e,n;const i=null==(e=this.config.history)?void 0:e.capture;return!i||(this.isPolygonAction(t)?!1!==(null==(n=i.polygonActions)?void 0:n[t]):!1!==i[t])}saveHistory(t){this.shouldCaptureHistory(t)&&this.historyManager.saveState(this.arrayOfFeatureGroups,t)}async redo(){if(!this.historyManager.canRedo())return;const t=this.historyManager.redo(this.arrayOfFeatureGroups);t&&await this.restoreFromSnapshot(t)}async addPredefinedPolygon(t,e){const n=Ps.convertToLatLngArray(t);if(!n||0===n.length)throw new Error("Cannot add empty polygon array");if(!this.map)throw new Error("Map not initialized");if(!this.polygonMutationManager)throw new Error("PolygonMutationManager not initialized");const i=(null==e?void 0:e.visualOptimizationLevel)??0;for(const[o,s]of n.entries()){if(!s||!s[0]||s[0].length<4)throw new Error(`Invalid polygon data at index ${o}: A polygon must have at least 3 unique vertices.`);try{const t=s.map(t=>t.map(t=>[t.lng,t.lat])),e=this.turfHelper.getMultiPolygon([t]);this.saveHistory("addPredefinedPolygon");const n=await this.polygonMutationManager.addPolygon(e,{simplify:!1,noMerge:!1,visualOptimizationLevel:i});if(!n.success)throw console.error("Error adding polygon via manager:",n.error),new Error(n.error||"Failed to add polygon");this.polygonInformation.createPolygonInformationStorage(this.arrayOfFeatureGroups)}catch(r){throw console.error("Error adding auto polygon:",r),r}}}async addPredefinedGeoJSONs(t,e){for(const n of t){const{type:t,coordinates:i}=n.geometry;if("MultiPolygon"===t)for(const n of i){const t=n.map(t=>t.map(t=>Wo.createLatLng(t[1],t[0])));await this.addPredefinedPolygon([t],e)}else if("Polygon"===t){const t=i.map(t=>t.map(t=>Wo.createLatLng(t[1],t[0])));await this.addPredefinedPolygon([t],e)}}}setDrawMode(t,e){const n=this.drawMode;this._updateDrawModeState(t);if(!((null==e?void 0:e.preserveActiveDraw)&&this.isDrawingInProgress&&(n===u.Add&&t===u.Subtract||n===u.Subtract&&t===u.Add))){(t===u.PointToPoint||t===u.PointToPointSubtract)&&n!==u.PointToPoint&&n!==u.PointToPointSubtract&&this.isDrawingInProgress&&this.stopDraw(),n!==u.PointToPoint&&n!==u.PointToPointSubtract||t===u.PointToPoint||t===u.PointToPointSubtract?(t===u.Off||t!==u.PointToPoint&&t!==u.PointToPointSubtract)&&this.stopDraw():(this.polygonDrawManager.clearP2pMarkers(),this.stopDraw())}this.map&&(this._updateUIAfterDrawModeChange(t),this._updateMapInteractions())}getDrawMode(){return this.modeManager.getCurrentMode()}on(t,e){this.eventManager.on(t,e)}off(t,e){this.eventManager.off(t,e)}removeAllFeatureGroups(){this.arrayOfFeatureGroups.forEach(t=>{try{this.polygonMutationManager&&this.polygonMutationManager.cleanupFeatureGroup(t),this.map.removeLayer(t)}catch{}}),this.arrayOfFeatureGroups.length=0,this.polygonInformation.deletePolygonInformationStorage(),this.polygonInformation.updatePolygons(),this.updateActivateButtonIndicator()}cleanup(){this.map&&this.comprehensiveCleanup()}initializeUI(t){!function(t){const e=document.createElement("style");e.innerHTML=`\n .leaflet-control a { background-color: ${t.colors.styles.controlButton.backgroundColor}; color: ${t.colors.styles.controlButton.color}; display: flex; align-items: center; justify-content: center; }\n .leaflet-control a:hover { background-color: ${t.colors.styles.controlButtonHover.backgroundColor}; }\n .leaflet-control a.active { background-color: ${t.colors.styles.controlButtonActive.backgroundColor}; color: ${t.colors.styles.controlButtonActive.color}; }\n .polydraw-indicator-active { background-color: ${t.colors.styles.indicatorActive.backgroundColor} !important; }\n .crosshair-cursor-enabled { cursor: crosshair !important; }\n .crosshair-cursor-enabled * { cursor: crosshair !important; }\n .leaflet-polydraw-p2p-marker { background-color: ${t.colors.styles.p2pMarker.backgroundColor}; border: 2px solid ${t.colors.styles.p2pMarker.borderColor}; border-radius: 50%; box-sizing: border-box; }\n .leaflet-polydraw-p2p-first-marker { position: relative; }\n .leaflet-polydraw-p2p-first-marker:hover { transform: scale(1.5); transition: all 0.2s ease; }\n .leaflet-polydraw-p2p-first-marker-ready[data-p2p-mode="add"]:hover { background-color: ${t.colors.p2p.closingMarker}; border-color: ${t.colors.p2p.closingMarker}; cursor: pointer; }\n .leaflet-polydraw-p2p-first-marker-ready[data-p2p-mode="subtract"]:hover { background-color: ${t.colors.dragPolygons.subtract}; border-color: ${t.colors.dragPolygons.subtract}; cursor: pointer; }\n `,document.head.appendChild(e)}(this.config),a.DomEvent.disableClickPropagation(t),a.DomEvent.on(t,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(t,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(t,"pointerdown",a.DomEvent.stopPropagation),a.DomEvent.on(t,"pointerup",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stopPropagation);const e=t=>{this.controlEvents.add(t),this.markControlPointerDown(t)},n=t=>{this.clearControlPointerDown(t)};this.pointerEventsHandled?(t.addEventListener("pointerdown",e,{capture:!0,passive:!0}),t.addEventListener("pointerup",n,{capture:!0,passive:!0}),t.addEventListener("pointercancel",n,{capture:!0,passive:!0})):(t.addEventListener("mousedown",e,{capture:!0,passive:!0}),t.addEventListener("mouseup",n,{capture:!0,passive:!0}),t.addEventListener("touchstart",e,{capture:!0,passive:!0}),t.addEventListener("touchend",n,{capture:!0,passive:!0}),t.addEventListener("touchcancel",n,{capture:!0,passive:!0})),t.style.display="flex",t.style.flexDirection="column-reverse",t.style.pointerEvents="auto",t.style.position="relative",t.style.zIndex="1000",this.subContainer=Wo.domUtil.create("div","sub-buttons",t),this.subContainer.setAttribute("data-polydraw","sub-buttons"),this.subContainer.style.maxHeight="0px",this.subContainer.style.overflow="hidden",this.subContainer.style.transition="max-height 0.3s ease",this.subContainer.style.pointerEvents="auto",this.subContainer.style.position="relative",function(t,e,n,i,r,o,s,l,u,h,c,f,g,d){const p=Wo.domUtil.create("a","icon-activate",t);if(p.href="#",p.title="Activate",p.setAttribute("data-polydraw","activate-button"),$o(p,Jo.activate),p.dataset.activeIcon=Jo.activate,p.dataset.collapsedIcon=Jo.collapse,a.DomEvent.on(p,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(p,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(p,"click",a.DomEvent.stop).on(p,"click",i),n.modes.draw){const t=Wo.domUtil.create("a","icon-draw",e);t.href="#",t.title="Draw",t.setAttribute("data-polydraw","draw-button"),$o(t,Jo.draw),a.DomEvent.on(t,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(t,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stop),a.DomEvent.on(t,"click",r)}if(n.modes.subtract){const t=Wo.domUtil.create("a","icon-subtract",e);t.href="#",t.title="Subtract",t.setAttribute("data-polydraw","subtract-button"),$o(t,Jo.subtract),a.DomEvent.on(t,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(t,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stop),a.DomEvent.on(t,"click",o)}if(n.modes.clonePolygons){const t=Wo.domUtil.create("a","icon-clone",e);t.href="#",t.title="Clone",t.setAttribute("data-polydraw","clone-button"),$o(t,Jo.clone),a.DomEvent.on(t,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(t,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stop),a.DomEvent.on(t,"click",s)}if(n.modes.p2p){const t=Wo.domUtil.create("a","icon-p2p",e);t.href="#",t.title="Point to Point",t.setAttribute("data-polydraw","p2p-button"),$o(t,Jo.p2p),a.DomEvent.on(t,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(t,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stop),a.DomEvent.on(t,"click",u)}if(n.modes.p2pSubtract){const t=Wo.domUtil.create("a","icon-p2p-subtract",e);t.href="#",t.title="Point to Point Subtract",t.setAttribute("data-polydraw","p2p-subtract-button"),$o(t,Jo.p2pSubtract),a.DomEvent.on(t,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(t,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stop),a.DomEvent.on(t,"click",h)}if(n.modes.deleteAll){const t=Wo.domUtil.create("a","icon-erase",e);t.href="#",t.title="Erase All",t.setAttribute("data-polydraw","erase-button"),$o(t,Jo.erase),a.DomEvent.on(t,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(t,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stopPropagation),a.DomEvent.on(t,"click",a.DomEvent.stop),a.DomEvent.on(t,"click",l)}const y=Wo.domUtil.create("a","icon-undo",e);y.href="#",y.title="Undo (Ctrl+Z / Cmd+Z)",$o(y,Jo.undo),a.DomEvent.on(y,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(y,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(y,"click",a.DomEvent.stopPropagation),a.DomEvent.on(y,"click",a.DomEvent.stop),a.DomEvent.on(y,"click",c);const m=Wo.domUtil.create("a","icon-redo",e);m.href="#",m.title="Redo (Ctrl+Y / Cmd+Shift+Z)",$o(m,Jo.redo),a.DomEvent.on(m,"mousedown",a.DomEvent.stopPropagation),a.DomEvent.on(m,"touchstart",a.DomEvent.stopPropagation),a.DomEvent.on(m,"click",a.DomEvent.stopPropagation),a.DomEvent.on(m,"click",a.DomEvent.stop),a.DomEvent.on(m,"click",f);const v=(t,e)=>{t?(y.style.opacity="1",y.style.pointerEvents="auto"):(y.style.opacity="0.3",y.style.pointerEvents="none"),e?(m.style.opacity="1",m.style.pointerEvents="auto"):(m.style.opacity="0.3",m.style.pointerEvents="none")};g.on("polydraw:history:changed",t=>{v(t.canUndo,t.canRedo)}),g.on("polydraw:history:undo",t=>{v(t.canUndo,t.canRedo)}),g.on("polydraw:history:redo",t=>{v(t.canUndo,t.canRedo)}),v(d.canUndo(),d.canRedo())}(t,this.subContainer,this.config,this._handleActivateToggle,this._handleDrawClick,this._handleSubtractClick,this._handleCloneClick,this._handleEraseClick,this._handlePointToPointClick,this._handlePointToPointSubtractClick,this._handleUndoClick,this._handleRedoClick,this.eventManager,this.historyManager),this.ensureButtonTouchResponsiveness(t);this.drawModeListeners.push(e=>{const n=t.querySelector(".icon-draw"),i=t.querySelector(".icon-subtract"),r=t.querySelector(".icon-clone");n&&n.classList.toggle("active",e===u.Add),i&&i.classList.toggle("active",e===u.Subtract),r&&r.classList.toggle("active",e===u.Clone)})}setupEventListeners(){this.polygonMutationManager.on("polygonOperationComplete",()=>{this.updateActivateButtonIndicator(),this.modeManager.updateStateForMode(u.Off),this.drawMode=u.Off,this.emitDrawModeChanged(),this.updateMarkerDraggableState();const t=this.modeManager.shouldShowCrosshairCursor(),e=this.modeManager.canPerformAction("mapDrag"),n=this.modeManager.canPerformAction("mapZoom"),i=this.modeManager.canPerformAction("mapDoubleClickZoom");t?Wo.domUtil.addClass(this.map.getContainer(),"crosshair-cursor-enabled"):Wo.domUtil.removeClass(this.map.getContainer(),"crosshair-cursor-enabled"),this.events(!1),this.setLeafletMapEvents(e,i,n),this.applyTracerStyle(u.Off)}),this.polygonMutationManager.on("polygonDeleted",()=>{this.updateActivateButtonIndicator()}),this.eventManager.on("polydraw:polygon:created",async t=>{this.stopDraw(),t.isPointToPoint?(this.saveHistory("pointToPoint"),t.mode===u.PointToPointSubtract?await this.polygonMutationManager.subtractPolygon(t.polygon,{simplify:!1}):await this.polygonMutationManager.addPolygon(t.polygon,{simplify:!1,noMerge:!1})):await this.handleFreehandDrawCompletion(t.polygon),this.polygonInformation.createPolygonInformationStorage(this.arrayOfFeatureGroups)}),this.eventManager.on("polydraw:draw:cancel",()=>{this.stopDraw(),this.setDrawMode(this.config.defaultMode)})}createTracer(){this.tracer=Wo.createPolyline([],{...this.config.polyLineOptions,color:this.config.colors.polyline});try{this.tracer.addTo(this.map)}catch{}}applyTracerStyle(t){if(this.tracer)try{const e=t===u.Subtract||t===u.PointToPointSubtract,n=this.getTracerBaseStyle(e);let i,r="";switch(t){case u.Add:r=this.config.colors.polyline,i=void 0;break;case u.Subtract:r=this.config.colors.subtractLine,i=void 0;break;case u.PointToPoint:r=this.config.colors.polyline,i="5, 5";break;case u.PointToPointSubtract:r=this.config.colors.subtractLine,i="5, 5";break;case u.Off:default:r="",i=void 0}this.tracer.setStyle({...n,color:r,dashArray:i})}catch{}}getTracerBaseStyle(t){const e=t?this.config.subtractLineOptions:this.config.polyLineOptions;return{weight:e.weight,opacity:e.opacity}}initializeManagers(){this.polygonDrawManager=new os({turfHelper:this.turfHelper,map:this.map,config:this.config,modeManager:this.modeManager,eventManager:this.eventManager,tracer:this.tracer}),this.polygonMutationManager=new xs({turfHelper:this.turfHelper,polygonInformation:this.polygonInformation,map:this.map,config:this.config,modeManager:this.modeManager,eventManager:this.eventManager,getFeatureGroups:()=>this.arrayOfFeatureGroups,saveHistoryState:t=>{this.saveHistory(t)}})}async loadExternalConfig(t,e){try{const n=await fetch(t);if(!n.ok)throw new Error(`Failed to load config from ${t}: ${n.status} ${n.statusText}`);const i=await n.json();this.warnIfUsingDeprecatedConfiguration(i),e&&this.warnIfUsingDeprecatedConfiguration(e),this.config=bs(structuredClone(c),i??{},e??{}),this.initializeComponents()}catch(n){console.warn("Failed to load external config, falling back to default + inline config:",n),this.config=bs(structuredClone(c),e??{}),this.initializeComponents()}}_updateDrawModeState(t){var e;this.drawMode=t,this.modeManager.updateStateForMode(t),this.emitDrawModeChanged(),this.updateMarkerDraggableState(),(null==(e=this.polygonDrawManager)?void 0:e.refreshP2PMarkerState)&&this.polygonDrawManager.refreshP2PMarkerState()}_updateUIAfterDrawModeChange(t){this.modeManager.shouldShowCrosshairCursor()?Wo.domUtil.addClass(this.map.getContainer(),"crosshair-cursor-enabled"):Wo.domUtil.removeClass(this.map.getContainer(),"crosshair-cursor-enabled"),this.applyTracerStyle(t)}shouldEnableDrawEvents(t){return t===u.Add||t===u.Subtract||t===u.PointToPoint||t===u.PointToPointSubtract}_updateMapInteractions(){const t=this.modeManager.canPerformAction("mapDrag"),e=this.modeManager.canPerformAction("mapZoom"),n=this.modeManager.canPerformAction("mapDoubleClickZoom");this.events(this.shouldEnableDrawEvents(this.drawMode)),this.setLeafletMapEvents(t,n,e)}async restoreFromSnapshot(t){this.historyManager.setRestoring(!0);try{this.removeAllFeatureGroups();for(const e of t.features)await this.polygonMutationManager.addPolygon(e,{noMerge:!0,simplify:!1});this.polygonInformation.updatePolygons()}finally{this.historyManager.setRestoring(!1)}}initializeComponents(){this.turfHelper=new Vo(this.config),this.mapStateService=new ns,this.eventManager=new is,this.polygonInformation=new es(this.mapStateService),this.modeManager=new rs(this.config,this.eventManager),this.historyManager=new Es(this.eventManager,this.config.maxHistorySize),this.polygonInformation.onPolygonInfoUpdated(t=>{this.updateActivateButtonIndicator()}),this._boundKeyDownHandler=this.handleKeyDown.bind(this)}emitDrawModeChanged(){this.eventManager.emit("polydraw:mode:change",{mode:this.modeManager.getCurrentMode()});for(const t of this.drawModeListeners)t(this.modeManager.getCurrentMode())}updateMarkerDraggableState(){const t=this.modeManager.canPerformAction("markerDrag");this.arrayOfFeatureGroups.forEach(e=>{e.eachLayer(e=>{if(e instanceof a.Marker){const n=e;try{n.options.draggable=t,n.dragging&&(t?n.dragging.enable():n.dragging.disable())}catch{}}})})}stopDraw(){this.isDrawingInProgress=!1,this.resetTracker(),this.drawStartedEvents(!1)}setLeafletMapEvents(t,e,n){t?this.map.dragging.enable():this.map.dragging.disable(),e?this.map.doubleClickZoom.enable():this.map.doubleClickZoom.disable(),n?this.map.scrollWheelZoom.enable():this.map.scrollWheelZoom.disable()}resetTracker(){var t;null==(t=this.tracer)||t.setLatLngs([])}drawStartedEvents(t){if(this.drawEventsAttached===t)return;this.drawEventsAttached=t;const e=this.pointerEventsHandled,n=t?"on":"off";e||(this.map[n]("mousemove",this.mouseMove,this),this.map[n]("mouseup",this.mouseUpLeave,this)),t?(e||(this._boundTouchMove||(this._boundTouchMove=t=>this.mouseMove(t)),this._boundTouchEnd||(this._boundTouchEnd=t=>this.mouseUpLeave(t)),this.map.getContainer().addEventListener("touchmove",this._boundTouchMove,{passive:!1}),this.map.getContainer().addEventListener("touchend",this._boundTouchEnd,{passive:!1})),e&&(this._boundPointerMove||(this._boundPointerMove=t=>this.mouseMove(t)),this._boundPointerUp||(this._boundPointerUp=t=>this.mouseUpLeave(t)),this.map.getContainer().addEventListener("pointermove",this._boundPointerMove,{passive:!1}),this.map.getContainer().addEventListener("pointerup",this._boundPointerUp,{passive:!1}))):(this._boundTouchMove&&this.map.getContainer().removeEventListener("touchmove",this._boundTouchMove),this._boundTouchEnd&&this.map.getContainer().removeEventListener("touchend",this._boundTouchEnd),this._boundPointerMove&&this.map.getContainer().removeEventListener("pointermove",this._boundPointerMove),this._boundPointerUp&&this.map.getContainer().removeEventListener("pointerup",this._boundPointerUp))}events(t){if(this.mapEventsAttached===t)return;this.mapEventsAttached=t;const e=this.pointerEventsHandled,n=t?"on":"off";e||this.map[n]("mousedown",this.mouseDown,this),this.map[n]("dblclick",this.handleDoubleClick,this),t?(e||(this._boundTouchStart||(this._boundTouchStart=t=>this.handleTouchStart(t)),this.map.getContainer().addEventListener("touchstart",this._boundTouchStart,{passive:!1})),e&&(this._boundPointerDown||(this._boundPointerDown=t=>this.mouseDown(t)),this.map.getContainer().addEventListener("pointerdown",this._boundPointerDown,{passive:!1}))):(this._boundTouchStart&&this.map.getContainer().removeEventListener("touchstart",this._boundTouchStart),this._boundPointerDown&&this.map.getContainer().removeEventListener("pointerdown",this._boundPointerDown))}handleTouchStart(t){const e=Date.now(),n=e-this._lastTapTime;this._tapTimeout&&(clearTimeout(this._tapTimeout),this._tapTimeout=null),n<300&&n>0?(this.handleDoubleTap(t),this._lastTapTime=0):(this._lastTapTime=e,this.pointerEventsHandled||(this._tapTimeout=window.setTimeout(()=>{this.mouseDown(t),this._tapTimeout=null},300)))}handleDoubleTap(t){this.modeManager.getCurrentMode()!==u.PointToPoint&&this.modeManager.getCurrentMode()!==u.PointToPointSubtract||this.polygonDrawManager.handleDoubleTap(t)}mouseDown(t){var e;const n=ws.normalizeEvent(t);if(this.isEventFromControl(n))return;if(ws.shouldPreventDefault(n)&&(null==(e=n.preventDefault)||e.call(n)),this.modeManager.isInOffMode())return;const i=ws.extractCoordinates(n,this.map);i&&(this.modeManager.getCurrentMode()!==u.PointToPoint&&this.modeManager.getCurrentMode()!==u.PointToPointSubtract?this.tracer&&(this.isDrawingInProgress||(this.tracer.setLatLngs([i]),this.startDraw())):this.polygonDrawManager.handlePointToPointClick(i))}isEventFromControl(t){var e,n;const i=this.getContainer();if(!i)return!1;const r=null==t?void 0:t.originalEvent;if(r&&this.controlEvents.has(r))return!0;if(t instanceof Event&&this.controlEvents.has(t))return!0;if(this.isRecentControlPointer(t))return!0;const o=(null==(e=null==r?void 0:r.composedPath)?void 0:e.call(r))??(null==(n=null==t?void 0:t.composedPath)?void 0:n.call(t));if(o&&o.some(t=>t instanceof Node&&i.contains(t)))return!0;const s=(null==r?void 0:r.target)??(null==t?void 0:t.target);if(s instanceof Node&&i.contains(s))return!0;const a=t=>{if(!t||"object"!=typeof t)return null;const e=t;if(e.touches&&e.touches.length>0)return{x:e.touches[0].clientX,y:e.touches[0].clientY};const n=t;if("number"==typeof n.clientX&&"number"==typeof n.clientY)return{x:n.clientX,y:n.clientY};const i=t;if(i.containerPoint&&this.map){const t=this.map.getContainer().getBoundingClientRect();return{x:t.left+i.containerPoint.x,y:t.top+i.containerPoint.y}}const r=t;if(r.latlng&&this.map){const t=this.map.latLngToContainerPoint(r.latlng),e=this.map.getContainer().getBoundingClientRect();return{x:e.left+t.x,y:e.top+t.y}}return null},l=a(null==t?void 0:t.originalEvent)??a(t);if(!l)return!1;const u=i.getBoundingClientRect();if(l.x>=u.left&&l.x<=u.right&&l.y>=u.top&&l.y<=u.bottom)return!0;const h=document.elementFromPoint(l.x,l.y);return!(!h||!i.contains(h))}extractPointerInfo(t){if(!t||"object"!=typeof t)return null;const e=t;if("number"==typeof e.pointerId)return{id:e.pointerId,pointerType:"string"==typeof e.pointerType?e.pointerType:"unknown"};if("string"==typeof e.type){if(e.type.startsWith("touch"))return{id:-2,pointerType:"touch"};if(e.type.startsWith("mouse"))return{id:-1,pointerType:"mouse"}}return null}markControlPointerDown(t){const e=this.extractPointerInfo(t);e&&(this.lastControlPointerDown={...e,time:Date.now()})}clearControlPointerDown(t){if(!this.lastControlPointerDown)return;const e=this.extractPointerInfo(t);e&&e.id===this.lastControlPointerDown.id&&(this.lastControlPointerDown=null)}isRecentControlPointer(t){if(!this.lastControlPointerDown)return!1;const e=null==t?void 0:t.originalEvent,n=this.extractPointerInfo(e)??this.extractPointerInfo(t);if(!n)return!1;const i="touch"===this.lastControlPointerDown.pointerType?450:80;return!(Date.now()-this.lastControlPointerDown.time>i)&&(n.pointerType===this.lastControlPointerDown.pointerType&&("mouse"===n.pointerType||n.id===this.lastControlPointerDown.id))}mouseMove(t){var e;if(!this.isDrawingInProgress)return;const n=ws.normalizeEvent(t);ws.shouldPreventDefault(n)&&(null==(e=n.preventDefault)||e.call(n));const i=ws.extractCoordinates(n,this.map);i&&this.tracer&&this.tracer.addLatLng(i)}async mouseUpLeave(t){var e;if(!this.isDrawingInProgress)return;const n=ws.normalizeEvent(t);if(ws.shouldPreventDefault(n)&&(null==(e=n.preventDefault)||e.call(n)),this.polygonInformation.deletePolygonInformationStorage(),!this.tracer)return void this.stopDraw();const i=this.tracer.toGeoJSON();if(!i||!i.geometry||!i.geometry.coordinates||i.geometry.coordinates.length<3)return void this.stopDraw();let r;try{r=this.turfHelper.createPolygonFromTrace(i)}catch{return void this.stopDraw()}if(r&&r.geometry&&r.geometry.coordinates&&0!==r.geometry.coordinates.length){this.stopDraw();try{switch(this.modeManager.getCurrentMode()){case u.Add:{const t=await this.polygonMutationManager.addPolygon(r,{simplify:!0,noMerge:!1});t.success||console.error("Error adding polygon via manager:",t.error);break}case u.Subtract:{const t=await this.polygonMutationManager.subtractPolygon(r);t.success||console.error("Error subtracting polygon via manager:",t.error);break}}}catch(o){console.error("Error in mouseUpLeave polygon operation:",o)}this.polygonInformation.createPolygonInformationStorage(this.arrayOfFeatureGroups)}else this.stopDraw()}async handleFreehandDrawCompletion(t){try{switch(this.saveHistory("freehand"),this.modeManager.getCurrentMode()){case u.Add:{const e=await this.polygonMutationManager.addPolygon(t,{simplify:!0,noMerge:!1});e.success||console.error("Error adding polygon via manager:",e.error);break}case u.Subtract:{const e=await this.polygonMutationManager.subtractPolygon(t);e.success||console.error("Error subtracting polygon via manager:",e.error);break}}}catch(e){console.error("Error in mouseUpLeave polygon operation:",e)}}startDraw(){this.isDrawingInProgress||(this.isDrawingInProgress=!0,this.drawStartedEvents(!0))}setupKeyboardHandlers(){this._boundKeyDownHandler||(this._boundKeyDownHandler=this.handleKeyDown.bind(this)),this._boundKeyUpHandler||(this._boundKeyUpHandler=this.handleKeyUp.bind(this)),document.addEventListener("keydown",this._boundKeyDownHandler),document.addEventListener("keyup",this._boundKeyUpHandler)}removeKeyboardHandlers(){this._boundKeyDownHandler&&document.removeEventListener("keydown",this._boundKeyDownHandler),this._boundKeyUpHandler&&document.removeEventListener("keyup",this._boundKeyUpHandler)}handleKeyDown(t){const e=t.ctrlKey||t.metaKey;if(e&&"z"===t.key&&!t.shiftKey)return t.preventDefault(),void this.undo();if(e&&("y"===t.key||"z"===t.key&&t.shiftKey))return t.preventDefault(),void this.redo();"Escape"===t.key&&(this.modeManager.getCurrentMode()!==u.PointToPoint&&this.modeManager.getCurrentMode()!==u.PointToPointSubtract||this.polygonDrawManager.cancelPointToPointDrawing());this.isModifierKeyPressed(t)&&!this.isModifierKeyHeld&&(this.isModifierKeyHeld=!0,this.polygonDrawManager.setModifierKey(!0),this.updateAllMarkersForEdgeDeletion(!0),this.applyModifierModeOverride(!0))}handleKeyUp(t){!this.isModifierKeyPressed(t)&&this.isModifierKeyHeld&&(this.isModifierKeyHeld=!1,this.polygonDrawManager.setModifierKey(!1),this.updateAllMarkersForEdgeDeletion(!1),this.applyModifierModeOverride(!1))}applyModifierModeOverride(t){if(t){if(this.modifierModeOverride)return;if(!this.config.modifierSubtractMode)return;const t=this.modeManager.getCurrentMode();return void(t===u.Add?(this.modifierModeOverride={from:t,to:u.Subtract},this.setDrawMode(u.Subtract,{preserveActiveDraw:!0})):t===u.PointToPoint&&(this.modifierModeOverride={from:t,to:u.PointToPointSubtract},this.setDrawMode(u.PointToPointSubtract,{preserveActiveDraw:!0})))}if(!this.modifierModeOverride)return;const{from:e,to:n}=this.modifierModeOverride;this.modifierModeOverride=null,this.modeManager.getCurrentMode()===n&&this.setDrawMode(e,{preserveActiveDraw:!0})}updateAllMarkersForEdgeDeletion(t){this.arrayOfFeatureGroups.forEach(e=>{e.eachLayer(e=>{e instanceof a.Marker&&this.updateMarkerForEdgeDeletion(e,t)})})}updateMarkerForEdgeDeletion(t,e){const n=t.getElement();n&&(e?(n.addEventListener("mouseenter",this.onMarkerHoverForEdgeDeletionEvent),n.addEventListener("mouseleave",this.onMarkerLeaveForEdgeDeletionEvent)):(n.removeEventListener("mouseenter",this.onMarkerHoverForEdgeDeletionEvent),n.removeEventListener("mouseleave",this.onMarkerLeaveForEdgeDeletionEvent),n.style.backgroundColor="",n.style.borderColor=""))}handleDoubleClick(t){this.modeManager.getCurrentMode()!==u.PointToPoint&&this.modeManager.getCurrentMode()!==u.PointToPointSubtract||(a.DomEvent.stop(t),this.polygonDrawManager.handleDoubleClick(t))}isModifierKeyPressed(t){return navigator.userAgent.toLowerCase().includes("mac")?t.metaKey:t.ctrlKey}ensureButtonTouchResponsiveness(t){t.querySelectorAll("a").forEach(t=>{t.style.pointerEvents="auto",t.style.touchAction="manipulation",t.style.position="relative",t.style.zIndex="1";const e=t=>{t.stopPropagation(),t.target.style.pointerEvents="auto"};t.addEventListener("touchstart",e,{passive:!0}),t.addEventListener("touchend",e,{passive:!0})})}updateActivateButtonIndicator(){if("function"!=typeof this.getContainer)return;const t=this.getContainer();if(!t)return;const e=t.querySelector(".icon-activate");if(!e)return;const n=this.arrayOfFeatureGroups.length>0,i=!Wo.domUtil.hasClass(e,"active"),r=Wo.domUtil.hasClass(e,"active")?e.dataset.collapsedIcon:e.dataset.activeIcon;r&&this.applyActivateButtonIcon(e,r);const o=n&&i;o?Wo.domUtil.addClass(e,"polydraw-indicator-active"):Wo.domUtil.removeClass(e,"polydraw-indicator-active");const s=this.config.colors.styles.controlButton.backgroundColor,a=this.config.colors.styles.controlButton.color,l=this.config.colors.styles.indicatorActive.backgroundColor;e.style.backgroundColor=o?l:s,e.style.color=a}applyActivateButtonIcon(t,e){Zo(t,e)}warnIfUsingDeprecatedConfiguration(t){var e,n;if(!t)return;const i=null==(e=t.polygonCreation)?void 0:e.simplification,r=t.simplification,o=!!r&&(Object.prototype.hasOwnProperty.call(r,"simplifyTolerance")||Object.prototype.hasOwnProperty.call(r,"dynamicMode"));(i||o)&&console.warn("[Leaflet.Polydraw] Legacy simplification settings detected. Please migrate to `config.simplification` with `mode`, `simple`, and `dynamic` blocks.");const s=null==(n=t.markers)?void 0:n.visualOptimization;s&&(void 0!==s.useAngles||void 0!==s.useBoundingBox||void 0!==s.useDistance||void 0!==s.thresholdBoundingBox||void 0!==s.thresholdDistance||void 0!==s.sharpAngleThreshold)&&console.warn("[Leaflet.Polydraw] `markers.visualOptimization` is deprecated. Prefer `visualOptimizationLevel` when adding predefined polygons.")}}const Ss=t=>{if(t){if("undefined"!=typeof globalThis){globalThis.L||(globalThis.L=t)}t.control&&(t.control.polydraw=function(t){return new Is(t)}),Ko.reset()}};if("undefined"!=typeof globalThis){const t=globalThis.L;t&&Ss(t)}t.default=Is,t.leafletAdapter=Wo,t.registerWithLeaflet=Ss,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("leaflet")):"function"==typeof define&&define.amd?define(["exports","leaflet"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).LeafletPolydraw={},t.L)}(this,function(t,e){"use strict";var r,o,n=Object.defineProperty,i=(t,e,r)=>((t,e,r)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r)(t,"symbol"!=typeof e?e+"":e,r);function a(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const r in t)if("default"!==r){const o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:()=>t[r]})}return e.default=t,Object.freeze(e)}const s=a(e);var l=(t=>(t.V1="1.x",t.V2="2.x",t))(l||{}),c=(t=>(t[t.Off=0]="Off",t[t.Add=1]="Add",t[t.Edit=2]="Edit",t[t.Subtract=4]="Subtract",t[t.AppendMarker=8]="AppendMarker",t[t.LoadPredefined=16]="LoadPredefined",t[t.PointToPoint=32]="PointToPoint",t[t.PointToPointSubtract=64]="PointToPointSubtract",t[t.Clone=128]="Clone",t))(c||{}),h=(t=>(t[t.SouthWest=0]="SouthWest",t[t.South=1]="South",t[t.SouthEast=2]="SouthEast",t[t.East=3]="East",t[t.NorthEast=4]="NorthEast",t[t.North=5]="North",t[t.NorthWest=6]="NorthWest",t[t.West=7]="West",t[t.Hole=8]="Hole",t))(h||{});const u={mergePolygons:!0,kinks:!1,tools:{default:c.Off,draw:!0,subtract:!0,p2p:!0,p2pSubtract:!0,clone:!0,erase:!0},modes:{attachElbow:!0,dragElbow:!0,dragPolygons:!0,edgeDeletion:!0},modifierSubtractMode:!0,interaction:{drag:{opacity:.7,dragCursor:"move",hoverCursor:"grab",markerBehavior:"hide",markerAnimationDuration:200,modifierSubtract:{keys:{windows:"ctrlKey",mac:"metaKey",linux:"ctrlKey"},hideMarkersOnDrag:!0}},edgeDeletion:{keys:{windows:"ctrlKey",mac:"metaKey",linux:"ctrlKey"},minVertices:3}},markers:{deleteMarker:!0,infoMarker:!0,menuMarker:!0,coordsTitle:!0,zIndexOffset:0,markerIcon:{styleClasses:["polygon-marker"],zIndexOffset:null},holeIcon:{styleClasses:["polygon-marker","hole"],zIndexOffset:null},markerInfoIcon:{position:h.East,showArea:!0,showPerimeter:!0,useMetrics:!0,usePerimeterMinValue:!1,areaLabel:"Area",perimeterLabel:"Perimeter",values:{min:{metric:"50",imperial:"100"},unknown:{metric:"-",imperial:"-"}},units:{unknownUnit:"",metric:{onlyMetrics:!0,perimeter:{m:"m",km:"km"},area:{m2:"m²",km2:"km²",daa:"daa",ha:"ha"}},imperial:{perimeter:{feet:"ft",yards:"yd",miles:"mi"},area:{feet2:"ft²",yards2:"yd²",acres:"ac",miles2:"mi²"}}},styleClasses:["polygon-marker","info"],zIndexOffset:1e4},markerMenuIcon:{position:h.South,styleClasses:["polygon-marker","menu"],zIndexOffset:1e4},markerDeleteIcon:{position:h.North,styleClasses:["polygon-marker","delete"],zIndexOffset:1e4},holeMarkers:{menuMarker:!1,deleteMarker:!0,infoMarker:!1},visualOptimization:{toleranceMin:5e-6,toleranceMax:.005,curve:1.35}},styles:{polyline:{weight:2,opacity:1,color:"#50622b"},subtractLine:{weight:2,opacity:1,color:"#D9460F"},polygon:{weight:2,opacity:1,fillOpacity:.2,smoothFactor:.3,noClip:!0,color:"#50622b",fillColor:"#b4cd8a"},hole:{weight:2,opacity:1,fillOpacity:.5,color:"#aa0000",fillColor:"#ffcccc"},ui:{controlButton:{backgroundColor:"#fff",color:"#000"},controlButtonHover:{backgroundColor:"#f4f4f4"},controlButtonActive:{backgroundColor:"rgb(128, 218, 255)",color:"#fff"},indicatorActive:{backgroundColor:"#ffcc00"},p2pMarker:{backgroundColor:"#fff",borderColor:"#50622b"},p2pClosingMarker:{color:"#4CAF50"},edgeHover:{color:"#7a9441"},edgeDeletion:{color:"#D9460F"},dragSubtract:{color:"#D9460F"}}},polygonCreation:{algorithm:"concaveman"},simplification:{strategy:"simple",simple:{tolerance:1e-4,highQuality:!1},dynamic:{baseTolerance:1e-4,highQuality:!1,fractionGuard:.9,multiplier:2}},polygonTools:{simplify:{enabled:!0,processHoles:!0},doubleElbows:{enabled:!0,processHoles:!0},bbox:{enabled:!0,processHoles:!0,addMidPointMarkers:!0},bezier:{enabled:!0,resolution:1e4,sharpness:.75,resampleMultiplier:10,maxNodes:1e3,visualOptimizationLevel:10,ghostMarkers:!1},scale:{enabled:!0},rotate:{enabled:!0},visualOptimizationToggle:{enabled:!0}},tooltips:{enabled:!0,delayMs:500,direction:"left",backgroundColor:"#645d5d",color:"#ffffff"},history:{capture:{batch:!0,freehand:!0,pointToPoint:!0,addPredefinedPolygon:!0,eraseAll:!0,markerDrag:!0,polygonDrag:!0,polygonClone:!0,addVertex:!0,removeVertex:!0,removeHole:!0,modifierSubtract:!0,deletePolygon:!0,layerDelete:!0,layerReorder:!0,polygonActions:{simplify:!0,doubleElbows:!0,bbox:!0,bezier:!0,scale:!0,rotate:!0,toggleOptimization:!0}},maxSize:50}},g=6371e3,d=6371,p=3959,f=Math.PI/180,y=180/Math.PI;Math.PI;function m(t,e={}){return{type:"Feature",geometry:{type:"Point",coordinates:t},properties:e}}function v(t,e={}){return{type:"Feature",geometry:{type:"LineString",coordinates:t},properties:e}}function M(t,e={}){return{type:"Feature",geometry:{type:"Polygon",coordinates:t},properties:e}}function w(t,e={}){return{type:"Feature",geometry:{type:"MultiPolygon",coordinates:t},properties:e}}function b(t){return{type:"FeatureCollection",features:t}}function P(t){if("Polygon"===t.geometry.type)return[t.geometry.coordinates];if("MultiPolygon"===t.geometry.type)return t.geometry.coordinates;throw new Error("Feature must be a Polygon or MultiPolygon")}function L(t){let e=1/0,r=1/0,o=-1/0,n=-1/0;const i=t=>{if(Array.isArray(t[0]))t.forEach(t=>i(t));else{const[i,a]=t;e=Math.min(e,i),r=Math.min(r,a),o=Math.max(o,i),n=Math.max(n,a)}},a=t=>{if("GeometryCollection"===t.type){return void t.geometries.forEach(a)}i(t.coordinates)};return a(t.geometry),[e,r,o,n]}function k(t,e,r="kilometers"){const o=Array.isArray(t)?t:t.geometry.coordinates,n=Array.isArray(e)?e:e.geometry.coordinates,[i,a]=o,[s,l]=n,c="miles"===r?p:"meters"===r?g:d,h=S(l-a),u=S(s-i),f=Math.sin(h/2)*Math.sin(h/2)+Math.cos(S(a))*Math.cos(S(l))*Math.sin(u/2)*Math.sin(u/2);return c*(2*Math.atan2(Math.sqrt(f),Math.sqrt(1-f)))}function x(t,e){const r=Array.isArray(t)?t:t.geometry.coordinates,o=Array.isArray(e)?e:e.geometry.coordinates,[n,i]=r,[a,s]=o;return m([(n+a)/2,(i+s)/2])}function E(t){const e=P(t);let r=0,o=0,n=0;for(const i of e)for(const t of i)for(const e of t)r+=e[0],o+=e[1],n++;return m([r/n,o/n])}function S(t){return t*f}var D=6371008.8,C={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*D,kilometers:6371.0088,kilometres:6371.0088,meters:D,metres:D,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:D/1852,radians:1,yards:6967335.223679999};function I(t,e,r={}){const o={type:"Feature"};return(0===r.id||r.id)&&(o.id=r.id),r.bbox&&(o.bbox=r.bbox),o.properties=e||{},o.geometry=t,o}function A(t,e,r={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!B(t[0])||!B(t[1]))throw new Error("coordinates must contain numbers");return I({type:"Point",coordinates:t},e,r)}function O(t,e,r={}){for(const o of t){if(o.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(o[o.length-1].length!==o[0].length)throw new Error("First and last Position are not equivalent.");for(let t=0;t<o[o.length-1].length;t++)if(o[o.length-1][t]!==o[0][t])throw new Error("First and last Position are not equivalent.")}return I({type:"Polygon",coordinates:t},e,r)}function F(t,e,r={}){if(t.length<2)throw new Error("coordinates must be an array of two or more positions");return I({type:"LineString",coordinates:t},e,r)}function T(t,e={}){const r={type:"FeatureCollection"};return e.id&&(r.id=e.id),e.bbox&&(r.bbox=e.bbox),r.features=t,r}function _(t,e,r={}){return I({type:"MultiPolygon",coordinates:t},e,r)}function H(t){return 180*(t%(2*Math.PI))/Math.PI}function G(t){return t%360*Math.PI/180}function B(t){return!isNaN(t)&&null!==t&&!Array.isArray(t)}function z(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)}function N(t,e,r){if(null!==t)for(var o,n,i,a,s,l,c,h,u=0,g=0,d=t.type,p="FeatureCollection"===d,f="Feature"===d,y=p?t.features.length:1,m=0;m<y;m++){s=(h=!!(c=p?t.features[m].geometry:f?t.geometry:t)&&"GeometryCollection"===c.type)?c.geometries.length:1;for(var v=0;v<s;v++){var M=0,w=0;if(null!==(a=h?c.geometries[v]:c)){l=a.coordinates;var b=a.type;switch(u=!r||"Polygon"!==b&&"MultiPolygon"!==b?0:1,b){case null:break;case"Point":if(!1===e(l,g,m,M,w))return!1;g++,M++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===e(l[o],g,m,M,w))return!1;g++,"MultiPoint"===b&&M++}"LineString"===b&&M++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(n=0;n<l[o].length-u;n++){if(!1===e(l[o][n],g,m,M,w))return!1;g++}"MultiLineString"===b&&M++,"Polygon"===b&&w++}"Polygon"===b&&M++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(w=0,n=0;n<l[o].length;n++){for(i=0;i<l[o][n].length-u;i++){if(!1===e(l[o][n][i],g,m,M,w))return!1;g++}w++}M++}break;case"GeometryCollection":for(o=0;o<a.geometries.length;o++)if(!1===N(a.geometries[o],e,r))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function U(t,e){if("Feature"===t.type)e(t,0);else if("FeatureCollection"===t.type)for(var r=0;r<t.features.length&&!1!==e(t.features[r],r);r++);}function R(t,e){var r,o,n,i,a,s,l,c,h,u,g=0,d="FeatureCollection"===t.type,p="Feature"===t.type,f=d?t.features.length:1;for(r=0;r<f;r++){for(s=d?t.features[r].geometry:p?t.geometry:t,c=d?t.features[r].properties:p?t.properties:{},h=d?t.features[r].bbox:p?t.bbox:void 0,u=d?t.features[r].id:p?t.id:void 0,a=(l=!!s&&"GeometryCollection"===s.type)?s.geometries.length:1,n=0;n<a;n++)if(null!==(i=l?s.geometries[n]:s))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===e(i,g,c,h,u))return!1;break;case"GeometryCollection":for(o=0;o<i.geometries.length;o++)if(!1===e(i.geometries[o],g,c,h,u))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===e(null,g,c,h,u))return!1;g++}}function X(t,e){R(t,function(t,r,o,n,i){var a,s=null===t?null:t.type;switch(s){case null:case"Point":case"LineString":case"Polygon":return!1!==e(I(t,o,{bbox:n,id:i}),r,0)&&void 0}switch(s){case"MultiPoint":a="Point";break;case"MultiLineString":a="LineString";break;case"MultiPolygon":a="Polygon"}for(var l=0;l<t.coordinates.length;l++){var c=t.coordinates[l];if(!1===e(I({type:a,coordinates:c},o),r,l))return!1}})}function Y(t,e,r){var o=r,n=!1;return function(t,e){X(t,function(t,r,o){var n=0;if(t.geometry){var i=t.geometry.type;if("Point"!==i&&"MultiPoint"!==i){var a,s=0,l=0,c=0;return!1!==N(t,function(i,h,u,g,d){if(void 0===a||r>s||g>l||d>c)return a=i,s=r,l=g,c=d,void(n=0);var p=F([a,i],t.properties);if(!1===e(p,r,o,d,n))return!1;n++,a=i})&&void 0}}})}(t,function(t,i,a,s,l){o=!1===n&&void 0===r?t:e(o,t,i,a,s,l),n=!0}),o}function V(t){return function(t,e,r){var o=r;return R(t,function(t,r,n,i,a){o=e(o,t,r,n,i,a)}),o}(t,(t,e)=>t+function(t){let e,r=0;switch(t.type){case"Polygon":return q(t.coordinates);case"MultiPolygon":for(e=0;e<t.coordinates.length;e++)r+=q(t.coordinates[e]);return r;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}(e),0)}function q(t){let e=0;if(t&&t.length>0){e+=Math.abs($(t[0]));for(let r=1;r<t.length;r++)e-=Math.abs($(t[r]))}return e}var j=20294876564838.72,K=Math.PI/180;function $(t){const e=t.length-1;if(e<=2)return 0;let r=0,o=0;for(;o<e;){const n=t[o],i=t[o+1===e?0:o+1],a=t[o+2>=e?(o+2)%e:o+2],s=n[0]*K,l=i[1]*K;r+=(a[0]*K-s)*Math.sin(l),o++}return r*j}var W=V;function J(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Z(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if("function"==typeof e){var r=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var o=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,o.get?o:{enumerable:!0,get:function(){return t[e]}})}),r}var Q,tt={exports:{}},et={exports:{}};function rt(){return Q||(Q=1,et.exports=function(){function t(t,o,n,i,a){!function t(r,o,n,i,a){for(;i>n;){if(i-n>600){var s=i-n+1,l=o-n+1,c=Math.log(s),h=.5*Math.exp(2*c/3),u=.5*Math.sqrt(c*h*(s-h)/s)*(l-s/2<0?-1:1);t(r,o,Math.max(n,Math.floor(o-l*h/s+u)),Math.min(i,Math.floor(o+(s-l)*h/s+u)),a)}var g=r[o],d=n,p=i;for(e(r,n,o),a(r[i],g)>0&&e(r,n,i);d<p;){for(e(r,d,p),d++,p--;a(r[d],g)<0;)d++;for(;a(r[p],g)>0;)p--}0===a(r[n],g)?e(r,n,p):e(r,++p,i),p<=o&&(n=p+1),o<=p&&(i=p-1)}}(t,o,n||0,i||t.length-1,a||r)}function e(t,e,r){var o=t[e];t[e]=t[r],t[r]=o}function r(t,e){return t<e?-1:t>e?1:0}var o=function(t){void 0===t&&(t=9),this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function n(t,e,r){if(!r)return e.indexOf(t);for(var o=0;o<e.length;o++)if(r(t,e[o]))return o;return-1}function i(t,e){a(t,0,t.children.length,e,t)}function a(t,e,r,o,n){n||(n=p(null)),n.minX=1/0,n.minY=1/0,n.maxX=-1/0,n.maxY=-1/0;for(var i=e;i<r;i++){var a=t.children[i];s(n,t.leaf?o(a):a)}return n}function s(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function l(t,e){return t.minX-e.minX}function c(t,e){return t.minY-e.minY}function h(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function u(t){return t.maxX-t.minX+(t.maxY-t.minY)}function g(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function d(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function p(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function f(e,r,o,n,i){for(var a=[r,o];a.length;)if(!((o=a.pop())-(r=a.pop())<=n)){var s=r+Math.ceil((o-r)/n/2)*n;t(e,s,r,o,i),a.push(r,s,s,o)}}return o.prototype.all=function(){return this._all(this.data,[])},o.prototype.search=function(t){var e=this.data,r=[];if(!d(t,e))return r;for(var o=this.toBBox,n=[];e;){for(var i=0;i<e.children.length;i++){var a=e.children[i],s=e.leaf?o(a):a;d(t,s)&&(e.leaf?r.push(a):g(t,s)?this._all(a,r):n.push(a))}e=n.pop()}return r},o.prototype.collides=function(t){var e=this.data;if(!d(t,e))return!1;for(var r=[];e;){for(var o=0;o<e.children.length;o++){var n=e.children[o],i=e.leaf?this.toBBox(n):n;if(d(t,i)){if(e.leaf||g(t,i))return!0;r.push(n)}}e=r.pop()}return!1},o.prototype.load=function(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(var e=0;e<t.length;e++)this.insert(t[e]);return this}var r=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===r.height)this._splitRoot(this.data,r);else{if(this.data.height<r.height){var o=this.data;this.data=r,r=o}this._insert(r,this.data.height-r.height-1,!0)}else this.data=r;return this},o.prototype.insert=function(t){return t&&this._insert(t,this.data.height-1),this},o.prototype.clear=function(){return this.data=p([]),this},o.prototype.remove=function(t,e){if(!t)return this;for(var r,o,i,a=this.data,s=this.toBBox(t),l=[],c=[];a||l.length;){if(a||(a=l.pop(),o=l[l.length-1],r=c.pop(),i=!0),a.leaf){var h=n(t,a.children,e);if(-1!==h)return a.children.splice(h,1),l.push(a),this._condense(l),this}i||a.leaf||!g(a,s)?o?(r++,a=o.children[r],i=!1):a=null:(l.push(a),c.push(r),r=0,o=a,a=a.children[0])}return this},o.prototype.toBBox=function(t){return t},o.prototype.compareMinX=function(t,e){return t.minX-e.minX},o.prototype.compareMinY=function(t,e){return t.minY-e.minY},o.prototype.toJSON=function(){return this.data},o.prototype.fromJSON=function(t){return this.data=t,this},o.prototype._all=function(t,e){for(var r=[];t;)t.leaf?e.push.apply(e,t.children):r.push.apply(r,t.children),t=r.pop();return e},o.prototype._build=function(t,e,r,o){var n,a=r-e+1,s=this._maxEntries;if(a<=s)return i(n=p(t.slice(e,r+1)),this.toBBox),n;o||(o=Math.ceil(Math.log(a)/Math.log(s)),s=Math.ceil(a/Math.pow(s,o-1))),(n=p([])).leaf=!1,n.height=o;var l=Math.ceil(a/s),c=l*Math.ceil(Math.sqrt(s));f(t,e,r,c,this.compareMinX);for(var h=e;h<=r;h+=c){var u=Math.min(h+c-1,r);f(t,h,u,l,this.compareMinY);for(var g=h;g<=u;g+=l){var d=Math.min(g+l-1,u);n.children.push(this._build(t,g,d,o-1))}}return i(n,this.toBBox),n},o.prototype._chooseSubtree=function(t,e,r,o){for(;o.push(e),!e.leaf&&o.length-1!==r;){for(var n=1/0,i=1/0,a=void 0,s=0;s<e.children.length;s++){var l=e.children[s],c=h(l),u=(g=t,d=l,(Math.max(d.maxX,g.maxX)-Math.min(d.minX,g.minX))*(Math.max(d.maxY,g.maxY)-Math.min(d.minY,g.minY))-c);u<i?(i=u,n=c<n?c:n,a=l):u===i&&c<n&&(n=c,a=l)}e=a||e.children[0]}var g,d;return e},o.prototype._insert=function(t,e,r){var o=r?t:this.toBBox(t),n=[],i=this._chooseSubtree(o,this.data,e,n);for(i.children.push(t),s(i,o);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(o,n,e)},o.prototype._split=function(t,e){var r=t[e],o=r.children.length,n=this._minEntries;this._chooseSplitAxis(r,n,o);var a=this._chooseSplitIndex(r,n,o),s=p(r.children.splice(a,r.children.length-a));s.height=r.height,s.leaf=r.leaf,i(r,this.toBBox),i(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(r,s)},o.prototype._splitRoot=function(t,e){this.data=p([t,e]),this.data.height=t.height+1,this.data.leaf=!1,i(this.data,this.toBBox)},o.prototype._chooseSplitIndex=function(t,e,r){for(var o,n,i,s,l,c,u,g=1/0,d=1/0,p=e;p<=r-e;p++){var f=a(t,0,p,this.toBBox),y=a(t,p,r,this.toBBox),m=(n=f,i=y,s=void 0,l=void 0,c=void 0,u=void 0,s=Math.max(n.minX,i.minX),l=Math.max(n.minY,i.minY),c=Math.min(n.maxX,i.maxX),u=Math.min(n.maxY,i.maxY),Math.max(0,c-s)*Math.max(0,u-l)),v=h(f)+h(y);m<g?(g=m,o=p,d=v<d?v:d):m===g&&v<d&&(d=v,o=p)}return o||r-e},o.prototype._chooseSplitAxis=function(t,e,r){var o=t.leaf?this.compareMinX:l,n=t.leaf?this.compareMinY:c;this._allDistMargin(t,e,r,o)<this._allDistMargin(t,e,r,n)&&t.children.sort(o)},o.prototype._allDistMargin=function(t,e,r,o){t.children.sort(o);for(var n=this.toBBox,i=a(t,0,e,n),l=a(t,r-e,r,n),c=u(i)+u(l),h=e;h<r-e;h++){var g=t.children[h];s(i,t.leaf?n(g):g),c+=u(i)}for(var d=r-e-1;d>=e;d--){var p=t.children[d];s(l,t.leaf?n(p):p),c+=u(l)}return c},o.prototype._adjustParentBBoxes=function(t,e,r){for(var o=r;o>=0;o--)s(e[o],t)},o.prototype._condense=function(t){for(var e=t.length-1,r=void 0;e>=0;e--)0===t[e].children.length?e>0?(r=t[e-1].children).splice(r.indexOf(t[e]),1):this.clear():i(t[e],this.toBBox)},o}()),et.exports}function ot(t,e){return t<e?-1:t>e?1:0}const nt=Z(Object.freeze(Object.defineProperty({__proto__:null,default:class{constructor(t=[],e=ot){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let r=(this.length>>1)-1;r>=0;r--)this._down(r)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:r}=this,o=e[t];for(;t>0;){const n=t-1>>1,i=e[n];if(r(o,i)>=0)break;e[t]=i,t=n}e[t]=o}_down(t){const{data:e,compare:r}=this,o=this.length>>1,n=e[t];for(;t<o;){let o=1+(t<<1),i=e[o];const a=o+1;if(a<this.length&&r(e[a],i)<0&&(o=a,i=e[a]),r(i,n)>=0)break;e[t]=i,t=o}e[t]=n}}},Symbol.toStringTag,{value:"Module"})));var it,at,st,lt,ct,ht={exports:{}};function ut(){if(ct)return ht.exports;ct=1;var t=at?it:(at=1,it=function(t,e,r,o){var n=t[0],i=t[1],a=!1;void 0===r&&(r=0),void 0===o&&(o=e.length);for(var s=(o-r)/2,l=0,c=s-1;l<s;c=l++){var h=e[r+2*l+0],u=e[r+2*l+1],g=e[r+2*c+0],d=e[r+2*c+1];u>i!=d>i&&n<(g-h)*(i-u)/(d-u)+h&&(a=!a)}return a}),e=lt?st:(lt=1,st=function(t,e,r,o){var n=t[0],i=t[1],a=!1;void 0===r&&(r=0),void 0===o&&(o=e.length);for(var s=o-r,l=0,c=s-1;l<s;c=l++){var h=e[l+r][0],u=e[l+r][1],g=e[c+r][0],d=e[c+r][1];u>i!=d>i&&n<(g-h)*(i-u)/(d-u)+h&&(a=!a)}return a});return ht.exports=function(r,o,n,i){return o.length>0&&Array.isArray(o[0])?e(r,o,n,i):t(r,o,n,i)},ht.exports.nested=e,ht.exports.flat=t,ht.exports}var gt,dt,pt={exports:{}};function ft(){return gt||(gt=1,function(t){const e=134217729,r=33306690738754706e-32;function o(t,e,r,o,n){let i,a,s,l,c=e[0],h=o[0],u=0,g=0;h>c==h>-c?(i=c,c=e[++u]):(i=h,h=o[++g]);let d=0;if(u<t&&g<r)for(h>c==h>-c?(s=i-((a=c+i)-c),c=e[++u]):(s=i-((a=h+i)-h),h=o[++g]),i=a,0!==s&&(n[d++]=s);u<t&&g<r;)h>c==h>-c?(s=i-((a=i+c)-(l=a-i))+(c-l),c=e[++u]):(s=i-((a=i+h)-(l=a-i))+(h-l),h=o[++g]),i=a,0!==s&&(n[d++]=s);for(;u<t;)s=i-((a=i+c)-(l=a-i))+(c-l),c=e[++u],i=a,0!==s&&(n[d++]=s);for(;g<r;)s=i-((a=i+h)-(l=a-i))+(h-l),h=o[++g],i=a,0!==s&&(n[d++]=s);return 0===i&&0!==d||(n[d++]=i),d}function n(t){return new Float64Array(t)}const i=33306690738754716e-32,a=22204460492503146e-32,s=11093356479670487e-47,l=n(4),c=n(8),h=n(12),u=n(16),g=n(4);t.orient2d=function(t,n,d,p,f,y){const m=(n-y)*(d-f),v=(t-f)*(p-y),M=m-v;if(0===m||0===v||m>0!=v>0)return M;const w=Math.abs(m+v);return Math.abs(M)>=i*w?M:-function(t,n,i,d,p,f,y){let m,v,M,w,b,P,L,k,x,E,S,D,C,I,A,O,F,T;const _=t-p,H=i-p,G=n-f,B=d-f;b=(A=(k=_-(L=(P=e*_)-(P-_)))*(E=B-(x=(P=e*B)-(P-B)))-((I=_*B)-L*x-k*x-L*E))-(S=A-(F=(k=G-(L=(P=e*G)-(P-G)))*(E=H-(x=(P=e*H)-(P-H)))-((O=G*H)-L*x-k*x-L*E))),l[0]=A-(S+b)+(b-F),b=(C=I-((D=I+S)-(b=D-I))+(S-b))-(S=C-O),l[1]=C-(S+b)+(b-O),b=(T=D+S)-D,l[2]=D-(T-b)+(S-b),l[3]=T;let z=function(t,e){let r=e[0];for(let o=1;o<t;o++)r+=e[o];return r}(4,l),N=a*y;if(z>=N||-z>=N)return z;if(m=t-(_+(b=t-_))+(b-p),M=i-(H+(b=i-H))+(b-p),v=n-(G+(b=n-G))+(b-f),w=d-(B+(b=d-B))+(b-f),0===m&&0===v&&0===M&&0===w)return z;if(N=s*y+r*Math.abs(z),(z+=_*w+B*m-(G*M+H*v))>=N||-z>=N)return z;b=(A=(k=m-(L=(P=e*m)-(P-m)))*(E=B-(x=(P=e*B)-(P-B)))-((I=m*B)-L*x-k*x-L*E))-(S=A-(F=(k=v-(L=(P=e*v)-(P-v)))*(E=H-(x=(P=e*H)-(P-H)))-((O=v*H)-L*x-k*x-L*E))),g[0]=A-(S+b)+(b-F),b=(C=I-((D=I+S)-(b=D-I))+(S-b))-(S=C-O),g[1]=C-(S+b)+(b-O),b=(T=D+S)-D,g[2]=D-(T-b)+(S-b),g[3]=T;const U=o(4,l,4,g,c);b=(A=(k=_-(L=(P=e*_)-(P-_)))*(E=w-(x=(P=e*w)-(P-w)))-((I=_*w)-L*x-k*x-L*E))-(S=A-(F=(k=G-(L=(P=e*G)-(P-G)))*(E=M-(x=(P=e*M)-(P-M)))-((O=G*M)-L*x-k*x-L*E))),g[0]=A-(S+b)+(b-F),b=(C=I-((D=I+S)-(b=D-I))+(S-b))-(S=C-O),g[1]=C-(S+b)+(b-O),b=(T=D+S)-D,g[2]=D-(T-b)+(S-b),g[3]=T;const R=o(U,c,4,g,h);b=(A=(k=m-(L=(P=e*m)-(P-m)))*(E=w-(x=(P=e*w)-(P-w)))-((I=m*w)-L*x-k*x-L*E))-(S=A-(F=(k=v-(L=(P=e*v)-(P-v)))*(E=M-(x=(P=e*M)-(P-M)))-((O=v*M)-L*x-k*x-L*E))),g[0]=A-(S+b)+(b-F),b=(C=I-((D=I+S)-(b=D-I))+(S-b))-(S=C-O),g[1]=C-(S+b)+(b-O),b=(T=D+S)-D,g[2]=D-(T-b)+(S-b),g[3]=T;const X=o(R,h,4,g,u);return u[X-1]}(t,n,d,p,f,y,w)},t.orient2dfast=function(t,e,r,o,n,i){return(e-i)*(r-n)-(t-n)*(o-i)},Object.defineProperty(t,"__esModule",{value:!0})}(pt.exports)),pt.exports}const yt=J(function(){if(dt)return tt.exports;dt=1;var t=rt(),e=nt,r=ut(),o=ft().orient2d;function n(e,o,n){o=Math.max(0,void 0===o?2:o),n=n||0;var a=function(t){for(var e=t[0],o=t[0],n=t[0],i=t[0],a=0;a<t.length;a++){var s=t[a];s[0]<e[0]&&(e=s),s[0]>n[0]&&(n=s),s[1]<o[1]&&(o=s),s[1]>i[1]&&(i=s)}var l=[e,o,n,i],c=l.slice();for(a=0;a<t.length;a++)r(t[a],l)||c.push(t[a]);return function(t){t.sort(m);for(var e=[],r=0;r<t.length;r++){for(;e.length>=2&&h(e[e.length-2],e[e.length-1],t[r])<=0;)e.pop();e.push(t[r])}for(var o=[],n=t.length-1;n>=0;n--){for(;o.length>=2&&h(o[o.length-2],o[o.length-1],t[n])<=0;)o.pop();o.push(t[n])}return o.pop(),e.pop(),e.concat(o)}(c)}(e),s=new t(16);s.toBBox=function(t){return{minX:t[0],minY:t[1],maxX:t[0],maxY:t[1]}},s.compareMinX=function(t,e){return t[0]-e[0]},s.compareMinY=function(t,e){return t[1]-e[1]},s.load(e);for(var l,c=[],u=0;u<a.length;u++){var f=a[u];s.remove(f),l=d(f,l),c.push(l)}var y=new t(16);for(u=0;u<c.length;u++)y.insert(g(c[u]));for(var v=o*o,M=n*n;c.length;){var w=c.shift(),b=w.p,P=w.next.p,L=p(b,P);if(!(L<M)){var k=L/v;(f=i(s,w.prev.p,b,P,w.next.next.p,k,y))&&Math.min(p(f,b),p(f,P))<=k&&(c.push(w),c.push(d(f,w)),s.remove(f),y.remove(w),y.insert(g(w)),y.insert(g(w.next)))}}w=l;var x=[];do{x.push(w.p),w=w.next}while(w!==l);return x.push(w.p),x}function i(t,r,o,n,i,l,h){for(var u=new e([],a),g=t.data;g;){for(var d=0;d<g.children.length;d++){var p=g.children[d],y=g.leaf?f(p,o,n):s(o,n,p);y>l||u.push({node:p,dist:y})}for(;u.length&&!u.peek().node.children;){var m=u.pop(),v=m.node,M=f(v,r,o),w=f(v,n,i);if(m.dist<M&&m.dist<w&&c(o,v,h)&&c(n,v,h))return v}(g=u.pop())&&(g=g.node)}return null}function a(t,e){return t.dist-e.dist}function s(t,e,r){if(l(t,r)||l(e,r))return 0;var o=y(t[0],t[1],e[0],e[1],r.minX,r.minY,r.maxX,r.minY);if(0===o)return 0;var n=y(t[0],t[1],e[0],e[1],r.minX,r.minY,r.minX,r.maxY);if(0===n)return 0;var i=y(t[0],t[1],e[0],e[1],r.maxX,r.minY,r.maxX,r.maxY);if(0===i)return 0;var a=y(t[0],t[1],e[0],e[1],r.minX,r.maxY,r.maxX,r.maxY);return 0===a?0:Math.min(o,n,i,a)}function l(t,e){return t[0]>=e.minX&&t[0]<=e.maxX&&t[1]>=e.minY&&t[1]<=e.maxY}function c(t,e,r){for(var o=Math.min(t[0],e[0]),n=Math.min(t[1],e[1]),i=Math.max(t[0],e[0]),a=Math.max(t[1],e[1]),s=r.search({minX:o,minY:n,maxX:i,maxY:a}),l=0;l<s.length;l++)if(u(s[l].p,s[l].next.p,t,e))return!1;return!0}function h(t,e,r){return o(t[0],t[1],e[0],e[1],r[0],r[1])}function u(t,e,r,o){return t!==o&&e!==r&&h(t,e,r)>0!=h(t,e,o)>0&&h(r,o,t)>0!=h(r,o,e)>0}function g(t){var e=t.p,r=t.next.p;return t.minX=Math.min(e[0],r[0]),t.minY=Math.min(e[1],r[1]),t.maxX=Math.max(e[0],r[0]),t.maxY=Math.max(e[1],r[1]),t}function d(t,e){var r={p:t,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return e?(r.next=e.next,r.prev=e,e.next.prev=r,e.next=r):(r.prev=r,r.next=r),r}function p(t,e){var r=t[0]-e[0],o=t[1]-e[1];return r*r+o*o}function f(t,e,r){var o=e[0],n=e[1],i=r[0]-o,a=r[1]-n;if(0!==i||0!==a){var s=((t[0]-o)*i+(t[1]-n)*a)/(i*i+a*a);s>1?(o=r[0],n=r[1]):s>0&&(o+=i*s,n+=a*s)}return(i=t[0]-o)*i+(a=t[1]-n)*a}function y(t,e,r,o,n,i,a,s){var l,c,h,u,g=r-t,d=o-e,p=a-n,f=s-i,y=t-n,m=e-i,v=g*g+d*d,M=g*p+d*f,w=p*p+f*f,b=g*y+d*m,P=p*y+f*m,L=v*w-M*M,k=L,x=L;0===L?(c=0,k=1,u=P,x=w):(u=v*P-M*b,(c=M*P-w*b)<0?(c=0,u=P,x=w):c>k&&(c=k,u=P+M,x=w)),u<0?(u=0,-b<0?c=0:-b>v?c=k:(c=-b,k=v)):u>x&&(u=x,-b+M<0?c=0:-b+M>v?c=k:(c=-b+M,k=v));var E=(1-(h=0===u?0:u/x))*n+h*a-((1-(l=0===c?0:c/k))*t+l*r),S=(1-h)*i+h*s-((1-l)*e+l*o);return E*E+S*S}function m(t,e){return t[0]===e[0]?t[1]-e[1]:t[0]-e[0]}return e.default&&(e=e.default),tt.exports=n,tt.exports.default=n,tt.exports}());function mt(t,e={}){e.concavity=e.concavity||1/0;const r=[];if(N(t,t=>{r.push([t[0],t[1]])}),!r.length)return null;const o=yt(r,e.concavity);return o.length>3?O([o]):null}var vt=mt;function Mt(t,e={}){let r=0,o=0,n=0;return N(t,function(t){r+=t[0],o+=t[1],n++},!0),A([r/n,o/n],e.properties)}function wt(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if("Feature"===t.type&&null!==t.geometry&&"Point"===t.geometry.type)return[...t.geometry.coordinates];if("Point"===t.type)return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function bt(t){if(Array.isArray(t))return t;if("Feature"===t.type){if(null!==t.geometry)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function Pt(t){return"Feature"===t.type?t.geometry:t}function Lt(t,e){return"FeatureCollection"===t.type?"FeatureCollection":"GeometryCollection"===t.type?"GeometryCollection":"Feature"===t.type&&null!==t.geometry?t.geometry.type:t.type}var kt=function t(e,r={}){switch(Lt(e)){case"Point":return A(wt(e),r.properties);case"Polygon":var o=[];N(e,function(t){o.push(t)});var n,i,a,s,l,c,h,u,g=Mt(e,{properties:r.properties}),d=g.geometry.coordinates,p=0,f=0,y=0,m=o.map(function(t){return[t[0]-d[0],t[1]-d[1]]});for(n=0;n<o.length-1;n++)s=(i=m[n])[0],c=i[1],l=(a=m[n+1])[0],y+=u=s*(h=a[1])-l*c,p+=(s+l)*u,f+=(c+h)*u;if(0===y)return g;var v=1/(6*(.5*y));return A([d[0]+v*p,d[1]+v*f],r.properties);default:var M=mt(e);return M?t(M,{properties:r.properties}):Mt(e,{properties:r.properties})}};let xt=class{constructor(t=[],e=Et){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let r=(this.length>>1)-1;r>=0;r--)this._down(r)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:r}=this,o=e[t];for(;t>0;){const n=t-1>>1,i=e[n];if(r(o,i)>=0)break;e[t]=i,t=n}e[t]=o}_down(t){const{data:e,compare:r}=this,o=this.length>>1,n=e[t];for(;t<o;){let o=1+(t<<1),i=e[o];const a=o+1;if(a<this.length&&r(e[a],i)<0&&(o=a,i=e[a]),r(i,n)>=0)break;e[t]=i,t=o}e[t]=n}};function Et(t,e){return t<e?-1:t>e?1:0}function St(t,e){return t.p.x>e.p.x?1:t.p.x<e.p.x?-1:t.p.y!==e.p.y?t.p.y>e.p.y?1:-1:1}function Dt(t,e){return t.rightSweepEvent.p.x>e.rightSweepEvent.p.x?1:t.rightSweepEvent.p.x<e.rightSweepEvent.p.x?-1:t.rightSweepEvent.p.y!==e.rightSweepEvent.p.y?t.rightSweepEvent.p.y<e.rightSweepEvent.p.y?1:-1:1}let Ct=class{constructor(t,e,r,o){this.p={x:t[0],y:t[1]},this.featureId=e,this.ringId=r,this.eventId=o,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(t){return this.p.x===t.p.x&&this.p.y===t.p.y}};let It=0,At=0,Ot=0;function Ft(t,e){const r="Feature"===t.type?t.geometry:t;let o=r.coordinates;"Polygon"!==r.type&&"MultiLineString"!==r.type||(o=[o]),"LineString"===r.type&&(o=[[o]]);for(let n=0;n<o.length;n++)for(let t=0;t<o[n].length;t++){let r=o[n][t][0],i=null;At+=1;for(let a=0;a<o[n][t].length-1;a++){i=o[n][t][a+1];const s=new Ct(r,It,At,Ot),l=new Ct(i,It,At,Ot+1);s.otherEvent=l,l.otherEvent=s,St(s,l)>0?(l.isLeftEndpoint=!0,s.isLeftEndpoint=!1):(s.isLeftEndpoint=!0,l.isLeftEndpoint=!1),e.push(s),e.push(l),r=i,Ot+=1}}It+=1}let Tt=class{constructor(t){this.leftSweepEvent=t,this.rightSweepEvent=t.otherEvent}};function _t(t,e){if(null===t||null===e)return!1;if(t.leftSweepEvent.ringId===e.leftSweepEvent.ringId&&(t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.rightSweepEvent)||t.leftSweepEvent.isSamePoint(e.leftSweepEvent)||t.leftSweepEvent.isSamePoint(e.rightSweepEvent)))return!1;const r=t.leftSweepEvent.p.x,o=t.leftSweepEvent.p.y,n=t.rightSweepEvent.p.x,i=t.rightSweepEvent.p.y,a=e.leftSweepEvent.p.x,s=e.leftSweepEvent.p.y,l=e.rightSweepEvent.p.x,c=e.rightSweepEvent.p.y,h=(c-s)*(n-r)-(l-a)*(i-o),u=(l-a)*(o-s)-(c-s)*(r-a),g=(n-r)*(o-s)-(i-o)*(r-a);if(0===h)return!1;const d=u/h,p=g/h;if(d>=0&&d<=1&&p>=0&&p<=1){return[r+d*(n-r),o+d*(i-o)]}return!1}var Ht=function(t,e){const r=new xt([],St);return function(t,e){if("FeatureCollection"===t.type){const r=t.features;for(let t=0;t<r.length;t++)Ft(r[t],e)}else Ft(t,e)}(t,r),function(t,e){e=e||!1;const r=[],o=new xt([],Dt);for(;t.length;){const n=t.pop();if(n.isLeftEndpoint){const t=new Tt(n);for(let i=0;i<o.data.length;i++){const a=o.data[i];if(e&&a.leftSweepEvent.featureId===n.featureId)continue;const s=_t(t,a);!1!==s&&r.push(s)}o.push(t)}else!1===n.isLeftEndpoint&&o.pop()}return r}(r,e)};function Gt(t,e,r={}){const{removeDuplicates:o=!0,ignoreSelfIntersections:n=!0}=r;let i=[];"FeatureCollection"===t.type?i=i.concat(t.features):"Feature"===t.type?i.push(t):"LineString"!==t.type&&"Polygon"!==t.type&&"MultiLineString"!==t.type&&"MultiPolygon"!==t.type||i.push(I(t)),"FeatureCollection"===e.type?i=i.concat(e.features):"Feature"===e.type?i.push(e):"LineString"!==e.type&&"Polygon"!==e.type&&"MultiLineString"!==e.type&&"MultiPolygon"!==e.type||i.push(I(e));const a=Ht(T(i),n);let s=[];if(o){const t={};a.forEach(e=>{const r=e.join(",");t[r]||(t[r]=!0,s.push(e))})}else s=a;return T(s.map(t=>A(t)))}var Bt=Gt,zt=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Nt=Math.ceil,Ut=Math.floor,Rt="[BigNumber Error] ",Xt=Rt+"Number primitive has more than 15 significant digits: ",Yt=1e14,Vt=14,qt=9007199254740991,jt=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],Kt=1e7,$t=1e9;function Wt(t){var e=0|t;return t>0||t===e?e:e-1}function Jt(t){for(var e,r,o=1,n=t.length,i=t[0]+"";o<n;){for(e=t[o++]+"",r=Vt-e.length;r--;e="0"+e);i+=e}for(n=i.length;48===i.charCodeAt(--n););return i.slice(0,n+1||1)}function Zt(t,e){var r,o,n=t.c,i=e.c,a=t.s,s=e.s,l=t.e,c=e.e;if(!a||!s)return null;if(r=n&&!n[0],o=i&&!i[0],r||o)return r?o?0:-s:a;if(a!=s)return a;if(r=a<0,o=l==c,!n||!i)return o?0:!n^r?1:-1;if(!o)return l>c^r?1:-1;for(s=(l=n.length)<(c=i.length)?l:c,a=0;a<s;a++)if(n[a]!=i[a])return n[a]>i[a]^r?1:-1;return l==c?0:l>c^r?1:-1}function Qt(t,e,r,o){if(t<e||t>r||t!==Ut(t))throw Error(Rt+(o||"Argument")+("number"==typeof t?t<e||t>r?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function te(t){var e=t.c.length-1;return Wt(t.e/Vt)==e&&t.c[e]%2!=0}function ee(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(e<0?"e":"e+")+e}function re(t,e,r){var o,n;if(e<0){for(n=r+".";++e;n+=r);t=n+t}else if(++e>(o=t.length)){for(n=r,e-=o;--e;n+=r);t+=n}else e<o&&(t=t.slice(0,e)+"."+t.slice(e));return t}var oe=function t(e){var r,o,n,i,a,s=b.prototype={constructor:b,toString:null,valueOf:null},l=new b(1),c=20,h=4,u=-7,g=21,d=-1e7,p=1e7,f=!1,y=1,m=0,v={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},M="0123456789abcdefghijklmnopqrstuvwxyz",w=!0;function b(t,e){var r,i,a,s,l,u,g,f,y=this;if(!(y instanceof b))return new b(t,e);if(null==e){if(t&&!0===t._isBigNumber)return y.s=t.s,void(!t.c||t.e>p?y.c=y.e=null:t.e<d?y.c=[y.e=0]:(y.e=t.e,y.c=t.c.slice()));if((u="number"==typeof t)&&0*t==0){if(y.s=1/t<0?(t=-t,-1):1,t===~~t){for(s=0,l=t;l>=10;l/=10,s++);return void(s>p?y.c=y.e=null:(y.e=s,y.c=[t]))}f=String(t)}else{if(!zt.test(f=String(t)))return n(y,f,u);y.s=45==f.charCodeAt(0)?(f=f.slice(1),-1):1}(s=f.indexOf("."))>-1&&(f=f.replace(".","")),(l=f.search(/e/i))>0?(s<0&&(s=l),s+=+f.slice(l+1),f=f.substring(0,l)):s<0&&(s=f.length)}else{if(Qt(e,2,M.length,"Base"),10==e&&w)return x(y=new b(t),c+y.e+1,h);if(f=String(t),u="number"==typeof t){if(0*t!=0)return n(y,f,u,e);if(y.s=1/t<0?(f=f.slice(1),-1):1,b.DEBUG&&f.replace(/^0\.0*|\./,"").length>15)throw Error(Xt+t)}else y.s=45===f.charCodeAt(0)?(f=f.slice(1),-1):1;for(r=M.slice(0,e),s=l=0,g=f.length;l<g;l++)if(r.indexOf(i=f.charAt(l))<0){if("."==i){if(l>s){s=g;continue}}else if(!a&&(f==f.toUpperCase()&&(f=f.toLowerCase())||f==f.toLowerCase()&&(f=f.toUpperCase()))){a=!0,l=-1,s=0;continue}return n(y,String(t),u,e)}u=!1,(s=(f=o(f,e,10,y.s)).indexOf("."))>-1?f=f.replace(".",""):s=f.length}for(l=0;48===f.charCodeAt(l);l++);for(g=f.length;48===f.charCodeAt(--g););if(f=f.slice(l,++g)){if(g-=l,u&&b.DEBUG&&g>15&&(t>qt||t!==Ut(t)))throw Error(Xt+y.s*t);if((s=s-l-1)>p)y.c=y.e=null;else if(s<d)y.c=[y.e=0];else{if(y.e=s,y.c=[],l=(s+1)%Vt,s<0&&(l+=Vt),l<g){for(l&&y.c.push(+f.slice(0,l)),g-=Vt;l<g;)y.c.push(+f.slice(l,l+=Vt));l=Vt-(f=f.slice(l)).length}else l-=g;for(;l--;f+="0");y.c.push(+f)}}else y.c=[y.e=0]}function P(t,e,r,o){var n,i,a,s,l;if(null==r?r=h:Qt(r,0,8),!t.c)return t.toString();if(n=t.c[0],a=t.e,null==e)l=Jt(t.c),l=1==o||2==o&&(a<=u||a>=g)?ee(l,a):re(l,a,"0");else if(i=(t=x(new b(t),e,r)).e,s=(l=Jt(t.c)).length,1==o||2==o&&(e<=i||i<=u)){for(;s<e;l+="0",s++);l=ee(l,i)}else if(e-=a+(2===o&&i>a),l=re(l,i,"0"),i+1>s){if(--e>0)for(l+=".";e--;l+="0");}else if((e+=i-s)>0)for(i+1==s&&(l+=".");e--;l+="0");return t.s<0&&n?"-"+l:l}function L(t,e){for(var r,o,n=1,i=new b(t[0]);n<t.length;n++)(!(o=new b(t[n])).s||(r=Zt(i,o))===e||0===r&&i.s===e)&&(i=o);return i}function k(t,e,r){for(var o=1,n=e.length;!e[--n];e.pop());for(n=e[0];n>=10;n/=10,o++);return(r=o+r*Vt-1)>p?t.c=t.e=null:r<d?t.c=[t.e=0]:(t.e=r,t.c=e),t}function x(t,e,r,o){var n,i,a,s,l,c,h,u=t.c,g=jt;if(u){t:{for(n=1,s=u[0];s>=10;s/=10,n++);if((i=e-n)<0)i+=Vt,a=e,l=u[c=0],h=Ut(l/g[n-a-1]%10);else if((c=Nt((i+1)/Vt))>=u.length){if(!o)break t;for(;u.length<=c;u.push(0));l=h=0,n=1,a=(i%=Vt)-Vt+1}else{for(l=s=u[c],n=1;s>=10;s/=10,n++);h=(a=(i%=Vt)-Vt+n)<0?0:Ut(l/g[n-a-1]%10)}if(o=o||e<0||null!=u[c+1]||(a<0?l:l%g[n-a-1]),o=r<4?(h||o)&&(0==r||r==(t.s<0?3:2)):h>5||5==h&&(4==r||o||6==r&&(i>0?a>0?l/g[n-a]:0:u[c-1])%10&1||r==(t.s<0?8:7)),e<1||!u[0])return u.length=0,o?(e-=t.e+1,u[0]=g[(Vt-e%Vt)%Vt],t.e=-e||0):u[0]=t.e=0,t;if(0==i?(u.length=c,s=1,c--):(u.length=c+1,s=g[Vt-i],u[c]=a>0?Ut(l/g[n-a]%g[a])*s:0),o)for(;;){if(0==c){for(i=1,a=u[0];a>=10;a/=10,i++);for(a=u[0]+=s,s=1;a>=10;a/=10,s++);i!=s&&(t.e++,u[0]==Yt&&(u[0]=1));break}if(u[c]+=s,u[c]!=Yt)break;u[c--]=0,s=1}for(i=u.length;0===u[--i];u.pop());}t.e>p?t.c=t.e=null:t.e<d&&(t.c=[t.e=0])}return t}function E(t){var e,r=t.e;return null===r?t.toString():(e=Jt(t.c),e=r<=u||r>=g?ee(e,r):re(e,r,"0"),t.s<0?"-"+e:e)}return b.clone=t,b.ROUND_UP=0,b.ROUND_DOWN=1,b.ROUND_CEIL=2,b.ROUND_FLOOR=3,b.ROUND_HALF_UP=4,b.ROUND_HALF_DOWN=5,b.ROUND_HALF_EVEN=6,b.ROUND_HALF_CEIL=7,b.ROUND_HALF_FLOOR=8,b.EUCLID=9,b.config=b.set=function(t){var e,r;if(null!=t){if("object"!=typeof t)throw Error(Rt+"Object expected: "+t);if(t.hasOwnProperty(e="DECIMAL_PLACES")&&(Qt(r=t[e],0,$t,e),c=r),t.hasOwnProperty(e="ROUNDING_MODE")&&(Qt(r=t[e],0,8,e),h=r),t.hasOwnProperty(e="EXPONENTIAL_AT")&&((r=t[e])&&r.pop?(Qt(r[0],-$t,0,e),Qt(r[1],0,$t,e),u=r[0],g=r[1]):(Qt(r,-$t,$t,e),u=-(g=r<0?-r:r))),t.hasOwnProperty(e="RANGE"))if((r=t[e])&&r.pop)Qt(r[0],-$t,-1,e),Qt(r[1],1,$t,e),d=r[0],p=r[1];else{if(Qt(r,-$t,$t,e),!r)throw Error(Rt+e+" cannot be zero: "+r);d=-(p=r<0?-r:r)}if(t.hasOwnProperty(e="CRYPTO")){if((r=t[e])!==!!r)throw Error(Rt+e+" not true or false: "+r);if(r){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw f=!r,Error(Rt+"crypto unavailable");f=r}else f=r}if(t.hasOwnProperty(e="MODULO_MODE")&&(Qt(r=t[e],0,9,e),y=r),t.hasOwnProperty(e="POW_PRECISION")&&(Qt(r=t[e],0,$t,e),m=r),t.hasOwnProperty(e="FORMAT")){if("object"!=typeof(r=t[e]))throw Error(Rt+e+" not an object: "+r);v=r}if(t.hasOwnProperty(e="ALPHABET")){if("string"!=typeof(r=t[e])||/^.?$|[+\-.\s]|(.).*\1/.test(r))throw Error(Rt+e+" invalid: "+r);w="0123456789"==r.slice(0,10),M=r}}return{DECIMAL_PLACES:c,ROUNDING_MODE:h,EXPONENTIAL_AT:[u,g],RANGE:[d,p],CRYPTO:f,MODULO_MODE:y,POW_PRECISION:m,FORMAT:v,ALPHABET:M}},b.isBigNumber=function(t){if(!t||!0!==t._isBigNumber)return!1;if(!b.DEBUG)return!0;var e,r,o=t.c,n=t.e,i=t.s;t:if("[object Array]"=={}.toString.call(o)){if((1===i||-1===i)&&n>=-$t&&n<=$t&&n===Ut(n)){if(0===o[0]){if(0===n&&1===o.length)return!0;break t}if((e=(n+1)%Vt)<1&&(e+=Vt),String(o[0]).length==e){for(e=0;e<o.length;e++)if((r=o[e])<0||r>=Yt||r!==Ut(r))break t;if(0!==r)return!0}}}else if(null===o&&null===n&&(null===i||1===i||-1===i))return!0;throw Error(Rt+"Invalid BigNumber: "+t)},b.maximum=b.max=function(){return L(arguments,-1)},b.minimum=b.min=function(){return L(arguments,1)},b.random=(i=9007199254740992,a=Math.random()*i&2097151?function(){return Ut(Math.random()*i)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(t){var e,r,o,n,i,s=0,h=[],u=new b(l);if(null==t?t=c:Qt(t,0,$t),n=Nt(t/Vt),f)if(crypto.getRandomValues){for(e=crypto.getRandomValues(new Uint32Array(n*=2));s<n;)(i=131072*e[s]+(e[s+1]>>>11))>=9e15?(r=crypto.getRandomValues(new Uint32Array(2)),e[s]=r[0],e[s+1]=r[1]):(h.push(i%1e14),s+=2);s=n/2}else{if(!crypto.randomBytes)throw f=!1,Error(Rt+"crypto unavailable");for(e=crypto.randomBytes(n*=7);s<n;)(i=281474976710656*(31&e[s])+1099511627776*e[s+1]+4294967296*e[s+2]+16777216*e[s+3]+(e[s+4]<<16)+(e[s+5]<<8)+e[s+6])>=9e15?crypto.randomBytes(7).copy(e,s):(h.push(i%1e14),s+=7);s=n/7}if(!f)for(;s<n;)(i=a())<9e15&&(h[s++]=i%1e14);for(n=h[--s],t%=Vt,n&&t&&(i=jt[Vt-t],h[s]=Ut(n/i)*i);0===h[s];h.pop(),s--);if(s<0)h=[o=0];else{for(o=-1;0===h[0];h.splice(0,1),o-=Vt);for(s=1,i=h[0];i>=10;i/=10,s++);s<Vt&&(o-=Vt-s)}return u.e=o,u.c=h,u}),b.sum=function(){for(var t=1,e=arguments,r=new b(e[0]);t<e.length;)r=r.plus(e[t++]);return r},o=function(){var t="0123456789";function e(t,e,r,o){for(var n,i,a=[0],s=0,l=t.length;s<l;){for(i=a.length;i--;a[i]*=e);for(a[0]+=o.indexOf(t.charAt(s++)),n=0;n<a.length;n++)a[n]>r-1&&(null==a[n+1]&&(a[n+1]=0),a[n+1]+=a[n]/r|0,a[n]%=r)}return a.reverse()}return function(o,n,i,a,s){var l,u,g,d,p,f,y,v,w=o.indexOf("."),P=c,L=h;for(w>=0&&(d=m,m=0,o=o.replace(".",""),f=(v=new b(n)).pow(o.length-w),m=d,v.c=e(re(Jt(f.c),f.e,"0"),10,i,t),v.e=v.c.length),g=d=(y=e(o,n,i,s?(l=M,t):(l=t,M))).length;0==y[--d];y.pop());if(!y[0])return l.charAt(0);if(w<0?--g:(f.c=y,f.e=g,f.s=a,y=(f=r(f,v,P,L,i)).c,p=f.r,g=f.e),w=y[u=g+P+1],d=i/2,p=p||u<0||null!=y[u+1],p=L<4?(null!=w||p)&&(0==L||L==(f.s<0?3:2)):w>d||w==d&&(4==L||p||6==L&&1&y[u-1]||L==(f.s<0?8:7)),u<1||!y[0])o=p?re(l.charAt(1),-P,l.charAt(0)):l.charAt(0);else{if(y.length=u,p)for(--i;++y[--u]>i;)y[u]=0,u||(++g,y=[1].concat(y));for(d=y.length;!y[--d];);for(w=0,o="";w<=d;o+=l.charAt(y[w++]));o=re(o,g,l.charAt(0))}return o}}(),r=function(){function t(t,e,r){var o,n,i,a,s=0,l=t.length,c=e%Kt,h=e/Kt|0;for(t=t.slice();l--;)s=((n=c*(i=t[l]%Kt)+(o=h*i+(a=t[l]/Kt|0)*c)%Kt*Kt+s)/r|0)+(o/Kt|0)+h*a,t[l]=n%r;return s&&(t=[s].concat(t)),t}function e(t,e,r,o){var n,i;if(r!=o)i=r>o?1:-1;else for(n=i=0;n<r;n++)if(t[n]!=e[n]){i=t[n]>e[n]?1:-1;break}return i}function r(t,e,r,o){for(var n=0;r--;)t[r]-=n,n=t[r]<e[r]?1:0,t[r]=n*o+t[r]-e[r];for(;!t[0]&&t.length>1;t.splice(0,1));}return function(o,n,i,a,s){var l,c,h,u,g,d,p,f,y,m,v,M,w,P,L,k,E,S=o.s==n.s?1:-1,D=o.c,C=n.c;if(!(D&&D[0]&&C&&C[0]))return new b(o.s&&n.s&&(D?!C||D[0]!=C[0]:C)?D&&0==D[0]||!C?0*S:S/0:NaN);for(y=(f=new b(S)).c=[],S=i+(c=o.e-n.e)+1,s||(s=Yt,c=Wt(o.e/Vt)-Wt(n.e/Vt),S=S/Vt|0),h=0;C[h]==(D[h]||0);h++);if(C[h]>(D[h]||0)&&c--,S<0)y.push(1),u=!0;else{for(P=D.length,k=C.length,h=0,S+=2,(g=Ut(s/(C[0]+1)))>1&&(C=t(C,g,s),D=t(D,g,s),k=C.length,P=D.length),w=k,v=(m=D.slice(0,k)).length;v<k;m[v++]=0);E=C.slice(),E=[0].concat(E),L=C[0],C[1]>=s/2&&L++;do{if(g=0,(l=e(C,m,k,v))<0){if(M=m[0],k!=v&&(M=M*s+(m[1]||0)),(g=Ut(M/L))>1)for(g>=s&&(g=s-1),p=(d=t(C,g,s)).length,v=m.length;1==e(d,m,p,v);)g--,r(d,k<p?E:C,p,s),p=d.length,l=1;else 0==g&&(l=g=1),p=(d=C.slice()).length;if(p<v&&(d=[0].concat(d)),r(m,d,v,s),v=m.length,-1==l)for(;e(C,m,k,v)<1;)g++,r(m,k<v?E:C,v,s),v=m.length}else 0===l&&(g++,m=[0]);y[h++]=g,m[0]?m[v++]=D[w]||0:(m=[D[w]],v=1)}while((w++<P||null!=m[0])&&S--);u=null!=m[0],y[0]||y.splice(0,1)}if(s==Yt){for(h=1,S=y[0];S>=10;S/=10,h++);x(f,i+(f.e=h+c*Vt-1)+1,a,u)}else f.e=c,f.r=+u;return f}}(),n=function(){var t=/^(-?)0([xbo])(?=\w[\w.]*$)/i,e=/^([^.]+)\.$/,r=/^\.([^.]+)$/,o=/^-?(Infinity|NaN)$/,n=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(i,a,s,l){var c,h=s?a:a.replace(n,"");if(o.test(h))i.s=isNaN(h)?null:h<0?-1:1;else{if(!s&&(h=h.replace(t,function(t,e,r){return c="x"==(r=r.toLowerCase())?16:"b"==r?2:8,l&&l!=c?t:e}),l&&(c=l,h=h.replace(e,"$1").replace(r,"0.$1")),a!=h))return new b(h,c);if(b.DEBUG)throw Error(Rt+"Not a"+(l?" base "+l:"")+" number: "+a);i.s=null}i.c=i.e=null}}(),s.absoluteValue=s.abs=function(){var t=new b(this);return t.s<0&&(t.s=1),t},s.comparedTo=function(t,e){return Zt(this,new b(t,e))},s.decimalPlaces=s.dp=function(t,e){var r,o,n,i=this;if(null!=t)return Qt(t,0,$t),null==e?e=h:Qt(e,0,8),x(new b(i),t+i.e+1,e);if(!(r=i.c))return null;if(o=((n=r.length-1)-Wt(this.e/Vt))*Vt,n=r[n])for(;n%10==0;n/=10,o--);return o<0&&(o=0),o},s.dividedBy=s.div=function(t,e){return r(this,new b(t,e),c,h)},s.dividedToIntegerBy=s.idiv=function(t,e){return r(this,new b(t,e),0,1)},s.exponentiatedBy=s.pow=function(t,e){var r,o,n,i,a,s,c,u,g=this;if((t=new b(t)).c&&!t.isInteger())throw Error(Rt+"Exponent not an integer: "+E(t));if(null!=e&&(e=new b(e)),a=t.e>14,!g.c||!g.c[0]||1==g.c[0]&&!g.e&&1==g.c.length||!t.c||!t.c[0])return u=new b(Math.pow(+E(g),a?t.s*(2-te(t)):+E(t))),e?u.mod(e):u;if(s=t.s<0,e){if(e.c?!e.c[0]:!e.s)return new b(NaN);(o=!s&&g.isInteger()&&e.isInteger())&&(g=g.mod(e))}else{if(t.e>9&&(g.e>0||g.e<-1||(0==g.e?g.c[0]>1||a&&g.c[1]>=24e7:g.c[0]<8e13||a&&g.c[0]<=9999975e7)))return i=g.s<0&&te(t)?-0:0,g.e>-1&&(i=1/i),new b(s?1/i:i);m&&(i=Nt(m/Vt+2))}for(a?(r=new b(.5),s&&(t.s=1),c=te(t)):c=(n=Math.abs(+E(t)))%2,u=new b(l);;){if(c){if(!(u=u.times(g)).c)break;i?u.c.length>i&&(u.c.length=i):o&&(u=u.mod(e))}if(n){if(0===(n=Ut(n/2)))break;c=n%2}else if(x(t=t.times(r),t.e+1,1),t.e>14)c=te(t);else{if(0===(n=+E(t)))break;c=n%2}g=g.times(g),i?g.c&&g.c.length>i&&(g.c.length=i):o&&(g=g.mod(e))}return o?u:(s&&(u=l.div(u)),e?u.mod(e):i?x(u,m,h,void 0):u)},s.integerValue=function(t){var e=new b(this);return null==t?t=h:Qt(t,0,8),x(e,e.e+1,t)},s.isEqualTo=s.eq=function(t,e){return 0===Zt(this,new b(t,e))},s.isFinite=function(){return!!this.c},s.isGreaterThan=s.gt=function(t,e){return Zt(this,new b(t,e))>0},s.isGreaterThanOrEqualTo=s.gte=function(t,e){return 1===(e=Zt(this,new b(t,e)))||0===e},s.isInteger=function(){return!!this.c&&Wt(this.e/Vt)>this.c.length-2},s.isLessThan=s.lt=function(t,e){return Zt(this,new b(t,e))<0},s.isLessThanOrEqualTo=s.lte=function(t,e){return-1===(e=Zt(this,new b(t,e)))||0===e},s.isNaN=function(){return!this.s},s.isNegative=function(){return this.s<0},s.isPositive=function(){return this.s>0},s.isZero=function(){return!!this.c&&0==this.c[0]},s.minus=function(t,e){var r,o,n,i,a=this,s=a.s;if(e=(t=new b(t,e)).s,!s||!e)return new b(NaN);if(s!=e)return t.s=-e,a.plus(t);var l=a.e/Vt,c=t.e/Vt,u=a.c,g=t.c;if(!l||!c){if(!u||!g)return u?(t.s=-e,t):new b(g?a:NaN);if(!u[0]||!g[0])return g[0]?(t.s=-e,t):new b(u[0]?a:3==h?-0:0)}if(l=Wt(l),c=Wt(c),u=u.slice(),s=l-c){for((i=s<0)?(s=-s,n=u):(c=l,n=g),n.reverse(),e=s;e--;n.push(0));n.reverse()}else for(o=(i=(s=u.length)<(e=g.length))?s:e,s=e=0;e<o;e++)if(u[e]!=g[e]){i=u[e]<g[e];break}if(i&&(n=u,u=g,g=n,t.s=-t.s),(e=(o=g.length)-(r=u.length))>0)for(;e--;u[r++]=0);for(e=Yt-1;o>s;){if(u[--o]<g[o]){for(r=o;r&&!u[--r];u[r]=e);--u[r],u[o]+=Yt}u[o]-=g[o]}for(;0==u[0];u.splice(0,1),--c);return u[0]?k(t,u,c):(t.s=3==h?-1:1,t.c=[t.e=0],t)},s.modulo=s.mod=function(t,e){var o,n,i=this;return t=new b(t,e),!i.c||!t.s||t.c&&!t.c[0]?new b(NaN):!t.c||i.c&&!i.c[0]?new b(i):(9==y?(n=t.s,t.s=1,o=r(i,t,0,3),t.s=n,o.s*=n):o=r(i,t,0,y),(t=i.minus(o.times(t))).c[0]||1!=y||(t.s=i.s),t)},s.multipliedBy=s.times=function(t,e){var r,o,n,i,a,s,l,c,h,u,g,d,p,f,y,m=this,v=m.c,M=(t=new b(t,e)).c;if(!(v&&M&&v[0]&&M[0]))return!m.s||!t.s||v&&!v[0]&&!M||M&&!M[0]&&!v?t.c=t.e=t.s=null:(t.s*=m.s,v&&M?(t.c=[0],t.e=0):t.c=t.e=null),t;for(o=Wt(m.e/Vt)+Wt(t.e/Vt),t.s*=m.s,(l=v.length)<(u=M.length)&&(p=v,v=M,M=p,n=l,l=u,u=n),n=l+u,p=[];n--;p.push(0));for(f=Yt,y=Kt,n=u;--n>=0;){for(r=0,g=M[n]%y,d=M[n]/y|0,i=n+(a=l);i>n;)r=((c=g*(c=v[--a]%y)+(s=d*c+(h=v[a]/y|0)*g)%y*y+p[i]+r)/f|0)+(s/y|0)+d*h,p[i--]=c%f;p[i]=r}return r?++o:p.splice(0,1),k(t,p,o)},s.negated=function(){var t=new b(this);return t.s=-t.s||null,t},s.plus=function(t,e){var r,o=this,n=o.s;if(e=(t=new b(t,e)).s,!n||!e)return new b(NaN);if(n!=e)return t.s=-e,o.minus(t);var i=o.e/Vt,a=t.e/Vt,s=o.c,l=t.c;if(!i||!a){if(!s||!l)return new b(n/0);if(!s[0]||!l[0])return l[0]?t:new b(s[0]?o:0*n)}if(i=Wt(i),a=Wt(a),s=s.slice(),n=i-a){for(n>0?(a=i,r=l):(n=-n,r=s),r.reverse();n--;r.push(0));r.reverse()}for((n=s.length)-(e=l.length)<0&&(r=l,l=s,s=r,e=n),n=0;e;)n=(s[--e]=s[e]+l[e]+n)/Yt|0,s[e]=Yt===s[e]?0:s[e]%Yt;return n&&(s=[n].concat(s),++a),k(t,s,a)},s.precision=s.sd=function(t,e){var r,o,n,i=this;if(null!=t&&t!==!!t)return Qt(t,1,$t),null==e?e=h:Qt(e,0,8),x(new b(i),t,e);if(!(r=i.c))return null;if(o=(n=r.length-1)*Vt+1,n=r[n]){for(;n%10==0;n/=10,o--);for(n=r[0];n>=10;n/=10,o++);}return t&&i.e+1>o&&(o=i.e+1),o},s.shiftedBy=function(t){return Qt(t,-9007199254740991,qt),this.times("1e"+t)},s.squareRoot=s.sqrt=function(){var t,e,o,n,i,a=this,s=a.c,l=a.s,u=a.e,g=c+4,d=new b("0.5");if(1!==l||!s||!s[0])return new b(!l||l<0&&(!s||s[0])?NaN:s?a:1/0);if(0==(l=Math.sqrt(+E(a)))||l==1/0?(((e=Jt(s)).length+u)%2==0&&(e+="0"),l=Math.sqrt(+e),u=Wt((u+1)/2)-(u<0||u%2),o=new b(e=l==1/0?"5e"+u:(e=l.toExponential()).slice(0,e.indexOf("e")+1)+u)):o=new b(l+""),o.c[0])for((l=(u=o.e)+g)<3&&(l=0);;)if(i=o,o=d.times(i.plus(r(a,i,g,1))),Jt(i.c).slice(0,l)===(e=Jt(o.c)).slice(0,l)){if(o.e<u&&--l,"9999"!=(e=e.slice(l-3,l+1))&&(n||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(x(o,o.e+c+2,1),t=!o.times(o).eq(a));break}if(!n&&(x(i,i.e+c+2,0),i.times(i).eq(a))){o=i;break}g+=4,l+=4,n=1}return x(o,o.e+c+1,h,t)},s.toExponential=function(t,e){return null!=t&&(Qt(t,0,$t),t++),P(this,t,e,1)},s.toFixed=function(t,e){return null!=t&&(Qt(t,0,$t),t=t+this.e+1),P(this,t,e)},s.toFormat=function(t,e,r){var o,n=this;if(null==r)null!=t&&e&&"object"==typeof e?(r=e,e=null):t&&"object"==typeof t?(r=t,t=e=null):r=v;else if("object"!=typeof r)throw Error(Rt+"Argument not an object: "+r);if(o=n.toFixed(t,e),n.c){var i,a=o.split("."),s=+r.groupSize,l=+r.secondaryGroupSize,c=r.groupSeparator||"",h=a[0],u=a[1],g=n.s<0,d=g?h.slice(1):h,p=d.length;if(l&&(i=s,s=l,l=i,p-=i),s>0&&p>0){for(i=p%s||s,h=d.substr(0,i);i<p;i+=s)h+=c+d.substr(i,s);l>0&&(h+=c+d.slice(i)),g&&(h="-"+h)}o=u?h+(r.decimalSeparator||"")+((l=+r.fractionGroupSize)?u.replace(new RegExp("\\d{"+l+"}\\B","g"),"$&"+(r.fractionGroupSeparator||"")):u):h}return(r.prefix||"")+o+(r.suffix||"")},s.toFraction=function(t){var e,o,n,i,a,s,c,u,g,d,f,y,m=this,v=m.c;if(null!=t&&(!(c=new b(t)).isInteger()&&(c.c||1!==c.s)||c.lt(l)))throw Error(Rt+"Argument "+(c.isInteger()?"out of range: ":"not an integer: ")+E(c));if(!v)return new b(m);for(e=new b(l),g=o=new b(l),n=u=new b(l),y=Jt(v),a=e.e=y.length-m.e-1,e.c[0]=jt[(s=a%Vt)<0?Vt+s:s],t=!t||c.comparedTo(e)>0?a>0?e:g:c,s=p,p=1/0,c=new b(y),u.c[0]=0;d=r(c,e,0,1),1!=(i=o.plus(d.times(n))).comparedTo(t);)o=n,n=i,g=u.plus(d.times(i=g)),u=i,e=c.minus(d.times(i=e)),c=i;return i=r(t.minus(o),n,0,1),u=u.plus(i.times(g)),o=o.plus(i.times(n)),u.s=g.s=m.s,f=r(g,n,a*=2,h).minus(m).abs().comparedTo(r(u,o,a,h).minus(m).abs())<1?[g,n]:[u,o],p=s,f},s.toNumber=function(){return+E(this)},s.toPrecision=function(t,e){return null!=t&&Qt(t,1,$t),P(this,t,e,2)},s.toString=function(t){var e,r=this,n=r.s,i=r.e;return null===i?n?(e="Infinity",n<0&&(e="-"+e)):e="NaN":(null==t?e=i<=u||i>=g?ee(Jt(r.c),i):re(Jt(r.c),i,"0"):10===t&&w?e=re(Jt((r=x(new b(r),c+i+1,h)).c),r.e,"0"):(Qt(t,2,M.length,"Base"),e=o(re(Jt(r.c),i,"0"),10,t,n,!0)),n<0&&r.c[0]&&(e="-"+e)),e},s.valueOf=s.toJSON=function(){return E(this)},s._isBigNumber=!0,s[Symbol.toStringTag]="BigNumber",s[Symbol.for("nodejs.util.inspect.custom")]=s.valueOf,null!=e&&b.set(e),b}(),ne=class{constructor(t){i(this,"key"),i(this,"left",null),i(this,"right",null),this.key=t}},ie=class extends ne{constructor(t){super(t)}},ae=class{constructor(){i(this,"size",0),i(this,"modificationCount",0),i(this,"splayCount",0)}splay(t){const e=this.root;if(null==e)return this.compare(t,t),-1;let r=null,o=null,n=null,i=null,a=e;const s=this.compare;let l;for(;;)if(l=s(a.key,t),l>0){let e=a.left;if(null==e)break;if(l=s(e.key,t),l>0&&(a.left=e.right,e.right=a,a=e,e=a.left,null==e))break;null==r?o=a:r.left=a,r=a,a=e}else{if(!(l<0))break;{let e=a.right;if(null==e)break;if(l=s(e.key,t),l<0&&(a.right=e.left,e.left=a,a=e,e=a.right,null==e))break;null==n?i=a:n.right=a,n=a,a=e}}return null!=n&&(n.right=a.left,a.left=i),null!=r&&(r.left=a.right,a.right=o),this.root!==a&&(this.root=a,this.splayCount++),l}splayMin(t){let e=t,r=e.left;for(;null!=r;){const t=r;e.left=t.right,t.right=e,e=t,r=e.left}return e}splayMax(t){let e=t,r=e.right;for(;null!=r;){const t=r;e.right=t.left,t.left=e,e=t,r=e.right}return e}_delete(t){if(null==this.root)return null;if(0!=this.splay(t))return null;let e=this.root;const r=e,o=e.left;if(this.size--,null==o)this.root=e.right;else{const t=e.right;e=this.splayMax(o),e.right=t,this.root=e}return this.modificationCount++,r}addNewRoot(t,e){this.size++,this.modificationCount++;const r=this.root;null!=r?(e<0?(t.left=r,t.right=r.right,r.right=null):(t.right=r,t.left=r.left,r.left=null),this.root=t):this.root=t}_first(){const t=this.root;return null==t?null:(this.root=this.splayMin(t),this.root)}_last(){const t=this.root;return null==t?null:(this.root=this.splayMax(t),this.root)}clear(){this.root=null,this.size=0,this.modificationCount++}has(t){return this.validKey(t)&&0==this.splay(t)}defaultCompare(){return(t,e)=>t<e?-1:t>e?1:0}wrap(){return{getRoot:()=>this.root,setRoot:t=>{this.root=t},getSize:()=>this.size,getModificationCount:()=>this.modificationCount,getSplayCount:()=>this.splayCount,setSplayCount:t=>{this.splayCount=t},splay:t=>this.splay(t),has:t=>this.has(t)}}},se=class t extends ae{constructor(t,e){super(),i(this,"root",null),i(this,"compare"),i(this,"validKey"),i(this,r,"[object Set]"),this.compare=t??this.defaultCompare(),this.validKey=e??(t=>null!=t&&null!=t)}delete(t){return!!this.validKey(t)&&null!=this._delete(t)}deleteAll(t){for(const e of t)this.delete(e)}forEach(t){const e=this[Symbol.iterator]();let r;for(;r=e.next(),!r.done;)t(r.value,r.value,this)}add(t){const e=this.splay(t);return 0!=e&&this.addNewRoot(new ie(t),e),this}addAndReturn(t){const e=this.splay(t);return 0!=e&&this.addNewRoot(new ie(t),e),this.root.key}addAll(t){for(const e of t)this.add(e)}isEmpty(){return null==this.root}isNotEmpty(){return null!=this.root}single(){if(0==this.size)throw"Bad state: No element";if(this.size>1)throw"Bad state: Too many element";return this.root.key}first(){if(0==this.size)throw"Bad state: No element";return this._first().key}last(){if(0==this.size)throw"Bad state: No element";return this._last().key}lastBefore(t){if(null==t)throw"Invalid arguments(s)";if(null==this.root)return null;if(this.splay(t)<0)return this.root.key;let e=this.root.left;if(null==e)return null;let r=e.right;for(;null!=r;)e=r,r=e.right;return e.key}firstAfter(t){if(null==t)throw"Invalid arguments(s)";if(null==this.root)return null;if(this.splay(t)>0)return this.root.key;let e=this.root.right;if(null==e)return null;let r=e.left;for(;null!=r;)e=r,r=e.left;return e.key}retainAll(e){const r=new t(this.compare,this.validKey),o=this.modificationCount;for(const t of e){if(o!=this.modificationCount)throw"Concurrent modification during iteration.";this.validKey(t)&&0==this.splay(t)&&r.add(this.root.key)}r.size!=this.size&&(this.root=r.root,this.size=r.size,this.modificationCount++)}lookup(t){if(!this.validKey(t))return null;return 0!=this.splay(t)?null:this.root.key}intersection(e){const r=new t(this.compare,this.validKey);for(const t of this)e.has(t)&&r.add(t);return r}difference(e){const r=new t(this.compare,this.validKey);for(const t of this)e.has(t)||r.add(t);return r}union(t){const e=this.clone();return e.addAll(t),e}clone(){const e=new t(this.compare,this.validKey);return e.size=this.size,e.root=this.copyNode(this.root),e}copyNode(t){if(null==t)return null;const e=new ie(t.key);return function t(e,r){let o,n;do{if(o=e.left,n=e.right,null!=o){const e=new ie(o.key);r.left=e,t(o,e)}if(null!=n){const t=new ie(n.key);r.right=t,e=n,r=t}}while(null!=n)}(t,e),e}toSet(){return this.clone()}entries(){return new he(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[(o=Symbol.iterator,r=Symbol.toStringTag,o)](){return new ce(this.wrap())}},le=class{constructor(t){i(this,"tree"),i(this,"path",new Array),i(this,"modificationCount",null),i(this,"splayCount"),this.tree=t,this.splayCount=t.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 t=this.path[this.path.length-1];return this.getValue(t)}rebuildPath(t){this.path.splice(0,this.path.length),this.tree.splay(t),this.path.push(this.tree.getRoot()),this.splayCount=this.tree.getSplayCount()}findLeftMostDescendent(t){for(;null!=t;)this.path.push(t),t=t.left}moveNext(){if(this.modificationCount!=this.tree.getModificationCount()){if(null==this.modificationCount){this.modificationCount=this.tree.getModificationCount();let t=this.tree.getRoot();for(;null!=t;)this.path.push(t),t=t.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 t=this.path[this.path.length-1],e=t.right;if(null!=e){for(;null!=e;)this.path.push(e),e=e.left;return!0}for(this.path.pop();this.path.length&&this.path[this.path.length-1].right===t;)t=this.path.pop();return this.path.length>0}},ce=class extends le{getValue(t){return t.key}},he=class extends le{getValue(t){return[t.key,t.key]}},ue=t=>()=>t,ge=t=>{const e=t?(e,r)=>r.minus(e).abs().isLessThanOrEqualTo(t):ue(!1);return(t,r)=>e(t,r)?0:t.comparedTo(r)};function de(t){const e=t?(e,r,o,n,i)=>e.exponentiatedBy(2).isLessThanOrEqualTo(n.minus(r).exponentiatedBy(2).plus(i.minus(o).exponentiatedBy(2)).times(t)):ue(!1);return(t,r,o)=>{const n=t.x,i=t.y,a=o.x,s=o.y,l=i.minus(s).times(r.x.minus(a)).minus(n.minus(a).times(r.y.minus(s)));return e(l,n,i,a,s)?0:l.comparedTo(0)}}var pe=t=>t,fe=t=>{if(t){const e=new se(ge(t)),r=new se(ge(t)),o=(t,e)=>e.addAndReturn(t),n=t=>({x:o(t.x,e),y:o(t.y,r)});return n({x:new oe(0),y:new oe(0)}),n}return pe},ye=t=>({set:t=>{me=ye(t)},reset:()=>ye(t),compare:ge(t),snap:fe(t),orient:de(t)}),me=ye(),ve=(t,e)=>t.ll.x.isLessThanOrEqualTo(e.x)&&e.x.isLessThanOrEqualTo(t.ur.x)&&t.ll.y.isLessThanOrEqualTo(e.y)&&e.y.isLessThanOrEqualTo(t.ur.y),Me=(t,e)=>{if(e.ur.x.isLessThan(t.ll.x)||t.ur.x.isLessThan(e.ll.x)||e.ur.y.isLessThan(t.ll.y)||t.ur.y.isLessThan(e.ll.y))return null;const r=t.ll.x.isLessThan(e.ll.x)?e.ll.x:t.ll.x,o=t.ur.x.isLessThan(e.ur.x)?t.ur.x:e.ur.x;return{ll:{x:r,y:t.ll.y.isLessThan(e.ll.y)?e.ll.y:t.ll.y},ur:{x:o,y:t.ur.y.isLessThan(e.ur.y)?t.ur.y:e.ur.y}}},we=(t,e)=>t.x.times(e.y).minus(t.y.times(e.x)),be=(t,e)=>t.x.times(e.x).plus(t.y.times(e.y)),Pe=t=>be(t,t).sqrt(),Le=(t,e,r)=>{const o={x:e.x.minus(t.x),y:e.y.minus(t.y)},n={x:r.x.minus(t.x),y:r.y.minus(t.y)};return we(n,o).div(Pe(n)).div(Pe(o))},ke=(t,e,r)=>{const o={x:e.x.minus(t.x),y:e.y.minus(t.y)},n={x:r.x.minus(t.x),y:r.y.minus(t.y)};return be(n,o).div(Pe(n)).div(Pe(o))},xe=(t,e,r)=>e.y.isZero()?null:{x:t.x.plus(e.x.div(e.y).times(r.minus(t.y))),y:r},Ee=(t,e,r)=>e.x.isZero()?null:{x:r,y:t.y.plus(e.y.div(e.x).times(r.minus(t.x)))},Se=class t{constructor(t,e){i(this,"point"),i(this,"isLeft"),i(this,"segment"),i(this,"otherSE"),i(this,"consumedBy"),void 0===t.events?t.events=[this]:t.events.push(this),this.point=t,this.isLeft=e}static compare(e,r){const o=t.comparePoints(e.point,r.point);return 0!==o?o:(e.point!==r.point&&e.link(r),e.isLeft!==r.isLeft?e.isLeft?1:-1:_e.compare(e.segment,r.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 r=0,o=e.length;r<o;r++){const t=e[r];this.point.events.push(t),t.point=this.point}this.checkForConsuming()}checkForConsuming(){const t=this.point.events.length;for(let e=0;e<t;e++){const r=this.point.events[e];if(void 0===r.segment.consumedBy)for(let o=e+1;o<t;o++){const t=this.point.events[o];void 0===t.consumedBy&&(r.otherSE.point.events===t.otherSE.point.events&&r.segment.consume(t.segment))}}}getAvailableLinkedEvents(){const t=[];for(let e=0,r=this.point.events.length;e<r;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,r=r=>{const o=r.otherSE;e.set(r,{sine:Le(this.point,t.point,o.point),cosine:ke(this.point,t.point,o.point)})};return(t,o)=>{e.has(t)||r(t),e.has(o)||r(o);const{sine:n,cosine:i}=e.get(t),{sine:a,cosine:s}=e.get(o);return n.isGreaterThanOrEqualTo(0)&&a.isGreaterThanOrEqualTo(0)?i.isLessThan(s)?1:i.isGreaterThan(s)?-1:0:n.isLessThan(0)&&a.isLessThan(0)?i.isLessThan(s)?-1:i.isGreaterThan(s)?1:0:a.isLessThan(n)?-1:a.isGreaterThan(n)?1:0}}},De=class t{constructor(t){i(this,"events"),i(this,"poly"),i(this,"_isExteriorRing"),i(this,"_enclosingRing"),this.events=t;for(let e=0,r=t.length;e<r;e++)t[e].segment.ringOut=this;this.poly=null}static factory(e){const r=[];for(let o=0,n=e.length;o<n;o++){const n=e[o];if(!n.isInResult()||n.ringOut)continue;let i=null,a=n.leftSE,s=n.rightSE;const l=[a],c=a.point,h=[];for(;i=a,a=s,l.push(a),a.point!==c;)for(;;){const e=a.getAvailableLinkedEvents();if(0===e.length){const t=l[0].point,e=l[l.length-1].point;throw new Error(`Unable to complete output ring starting at [${t.x}, ${t.y}]. Last matching segment found ends at [${e.x}, ${e.y}].`)}if(1===e.length){s=e[0].otherSE;break}let o=null;for(let t=0,r=h.length;t<r;t++)if(h[t].point===a.point){o=t;break}if(null!==o){const e=h.splice(o)[0],n=l.splice(e.index);n.unshift(n[0].otherSE),r.push(new t(n.reverse()));continue}h.push({index:l.length,point:a.point});const n=a.getLeftmostComparator(i);s=e.sort(n)[0].otherSE;break}r.push(new t(l))}return r}getGeom(){let t=this.events[0].point;const e=[t];for(let l=1,c=this.events.length-1;l<c;l++){const r=this.events[l].point,o=this.events[l+1].point;0!==me.orient(r,t,o)&&(e.push(r),t=r)}if(1===e.length)return null;const r=e[0],o=e[1];0===me.orient(r,t,o)&&e.shift(),e.push(e[0]);const n=this.isExteriorRing()?1:-1,i=this.isExteriorRing()?0:e.length-1,a=this.isExteriorRing()?e.length:-1,s=[];for(let l=i;l!=a;l+=n)s.push([e[l].x.toNumber(),e[l].y.toNumber()]);return s}isExteriorRing(){if(void 0===this._isExteriorRing){const t=this.enclosingRing();this._isExteriorRing=!t||!t.isExteriorRing()}return this._isExteriorRing}enclosingRing(){return void 0===this._enclosingRing&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){var t,e;let r=this.events[0];for(let i=1,a=this.events.length;i<a;i++){const t=this.events[i];Se.compare(r,t)>0&&(r=t)}let o=r.segment.prevInResult(),n=o?o.prevInResult():null;for(;;){if(!o)return null;if(!n)return o.ringOut;if(n.ringOut!==o.ringOut)return(null==(t=n.ringOut)?void 0:t.enclosingRing())!==o.ringOut?o.ringOut:null==(e=o.ringOut)?void 0:e.enclosingRing();o=n.prevInResult(),n=o?o.prevInResult():null}}},Ce=class{constructor(t){i(this,"exteriorRing"),i(this,"interiorRings"),this.exteriorRing=t,t.poly=this,this.interiorRings=[]}addInterior(t){this.interiorRings.push(t),t.poly=this}getGeom(){const t=this.exteriorRing.getGeom();if(null===t)return null;const e=[t];for(let r=0,o=this.interiorRings.length;r<o;r++){const t=this.interiorRings[r].getGeom();null!==t&&e.push(t)}return e}},Ie=class{constructor(t){i(this,"rings"),i(this,"polys"),this.rings=t,this.polys=this._composePolys(t)}getGeom(){const t=[];for(let e=0,r=this.polys.length;e<r;e++){const r=this.polys[e].getGeom();null!==r&&t.push(r)}return t}_composePolys(t){var e;const r=[];for(let o=0,n=t.length;o<n;o++){const n=t[o];if(!n.poly)if(n.isExteriorRing())r.push(new Ce(n));else{const t=n.enclosingRing();(null==t?void 0:t.poly)||r.push(new Ce(t)),null==(e=null==t?void 0:t.poly)||e.addInterior(n)}}return r}},Ae=class{constructor(t,e=_e.compare){i(this,"queue"),i(this,"tree"),i(this,"segments"),this.queue=t,this.tree=new se(e),this.segments=[]}process(t){const e=t.segment,r=[];if(t.consumedBy)return t.isLeft?this.queue.delete(t.otherSE):this.tree.delete(e),r;t.isLeft&&this.tree.add(e);let o=e,n=e;do{o=this.tree.lastBefore(o)}while(null!=o&&null!=o.consumedBy);do{n=this.tree.firstAfter(n)}while(null!=n&&null!=n.consumedBy);if(t.isLeft){let i=null;if(o){const t=o.getIntersection(e);if(null!==t&&(e.isAnEndpoint(t)||(i=t),!o.isAnEndpoint(t))){const e=this._splitSafely(o,t);for(let t=0,o=e.length;t<o;t++)r.push(e[t])}}let a=null;if(n){const t=n.getIntersection(e);if(null!==t&&(e.isAnEndpoint(t)||(a=t),!n.isAnEndpoint(t))){const e=this._splitSafely(n,t);for(let t=0,o=e.length;t<o;t++)r.push(e[t])}}if(null!==i||null!==a){let t=null;if(null===i)t=a;else if(null===a)t=i;else{t=Se.comparePoints(i,a)<=0?i:a}this.queue.delete(e.rightSE),r.push(e.rightSE);const o=e.split(t);for(let e=0,n=o.length;e<n;e++)r.push(o[e])}r.length>0?(this.tree.delete(e),r.push(t)):(this.segments.push(e),e.prev=o)}else{if(o&&n){const t=o.getIntersection(n);if(null!==t){if(!o.isAnEndpoint(t)){const e=this._splitSafely(o,t);for(let t=0,o=e.length;t<o;t++)r.push(e[t])}if(!n.isAnEndpoint(t)){const e=this._splitSafely(n,t);for(let t=0,o=e.length;t<o;t++)r.push(e[t])}}}this.tree.delete(e)}return r}_splitSafely(t,e){this.tree.delete(t);const r=t.rightSE;this.queue.delete(r);const o=t.split(e);return o.push(r),void 0===t.consumedBy&&this.tree.add(t),o}},Oe=new class{constructor(){i(this,"type"),i(this,"numMultiPolys")}run(t,e,r){Oe.type=t;const o=[new Be(e,!0)];for(let l=0,c=r.length;l<c;l++)o.push(new Be(r[l],!1));if(Oe.numMultiPolys=o.length,"difference"===Oe.type){const t=o[0];let e=1;for(;e<o.length;)null!==Me(o[e].bbox,t.bbox)?e++:o.splice(e,1)}if("intersection"===Oe.type)for(let l=0,c=o.length;l<c;l++){const t=o[l];for(let e=l+1,r=o.length;e<r;e++)if(null===Me(t.bbox,o[e].bbox))return[]}const n=new se(Se.compare);for(let l=0,c=o.length;l<c;l++){const t=o[l].getSweepEvents();for(let e=0,r=t.length;e<r;e++)n.add(t[e])}const i=new Ae(n);let a=null;for(0!=n.size&&(a=n.first(),n.delete(a));a;){const t=i.process(a);for(let e=0,r=t.length;e<r;e++){const r=t[e];void 0===r.consumedBy&&n.add(r)}0!=n.size?(a=n.first(),n.delete(a)):a=null}me.reset();const s=De.factory(i.segments);return new Ie(s).getGeom()}},Fe=Oe,Te=0,_e=class t{constructor(t,e,r,o){i(this,"id"),i(this,"leftSE"),i(this,"rightSE"),i(this,"rings"),i(this,"windings"),i(this,"ringOut"),i(this,"consumedBy"),i(this,"prev"),i(this,"_prevInResult"),i(this,"_beforeState"),i(this,"_afterState"),i(this,"_isInResult"),this.id=++Te,this.leftSE=t,t.segment=this,t.otherSE=e,this.rightSE=e,e.segment=this,e.otherSE=t,this.rings=r,this.windings=o}static compare(t,e){const r=t.leftSE.point.x,o=e.leftSE.point.x,n=t.rightSE.point.x,i=e.rightSE.point.x;if(i.isLessThan(r))return 1;if(n.isLessThan(o))return-1;const a=t.leftSE.point.y,s=e.leftSE.point.y,l=t.rightSE.point.y,c=e.rightSE.point.y;if(r.isLessThan(o)){if(s.isLessThan(a)&&s.isLessThan(l))return 1;if(s.isGreaterThan(a)&&s.isGreaterThan(l))return-1;const r=t.comparePoint(e.leftSE.point);if(r<0)return 1;if(r>0)return-1;const o=e.comparePoint(t.rightSE.point);return 0!==o?o:-1}if(r.isGreaterThan(o)){if(a.isLessThan(s)&&a.isLessThan(c))return-1;if(a.isGreaterThan(s)&&a.isGreaterThan(c))return 1;const r=e.comparePoint(t.leftSE.point);if(0!==r)return r;const o=t.comparePoint(e.rightSE.point);return o<0?1:o>0?-1:1}if(a.isLessThan(s))return-1;if(a.isGreaterThan(s))return 1;if(n.isLessThan(i)){const r=e.comparePoint(t.rightSE.point);if(0!==r)return r}if(n.isGreaterThan(i)){const r=t.comparePoint(e.rightSE.point);if(r<0)return 1;if(r>0)return-1}if(!n.eq(i)){const t=l.minus(a),e=n.minus(r),h=c.minus(s),u=i.minus(o);if(t.isGreaterThan(e)&&h.isLessThan(u))return 1;if(t.isLessThan(e)&&h.isGreaterThan(u))return-1}return n.isGreaterThan(i)?1:n.isLessThan(i)||l.isLessThan(c)?-1:l.isGreaterThan(c)?1:t.id<e.id?-1:t.id>e.id?1:0}static fromRing(e,r,o){let n,i,a;const s=Se.comparePoints(e,r);if(s<0)n=e,i=r,a=1;else{if(!(s>0))throw new Error(`Tried to create degenerate segment at [${e.x}, ${e.y}]`);n=r,i=e,a=-1}const l=new Se(n,!0),c=new Se(i,!1);return new t(l,c,[o],[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 me.orient(this.leftSE.point,t,this.rightSE.point)}getIntersection(t){const e=this.bbox(),r=t.bbox(),o=Me(e,r);if(null===o)return null;const n=this.leftSE.point,i=this.rightSE.point,a=t.leftSE.point,s=t.rightSE.point,l=ve(e,a)&&0===this.comparePoint(a),c=ve(r,n)&&0===t.comparePoint(n),h=ve(e,s)&&0===this.comparePoint(s),u=ve(r,i)&&0===t.comparePoint(i);if(c&&l)return u&&!h?i:!u&&h?s:null;if(c)return h&&n.x.eq(s.x)&&n.y.eq(s.y)?null:n;if(l)return u&&i.x.eq(a.x)&&i.y.eq(a.y)?null:a;if(u&&h)return null;if(u)return i;if(h)return s;const g=((t,e,r,o)=>{if(e.x.isZero())return Ee(r,o,t.x);if(o.x.isZero())return Ee(t,e,r.x);if(e.y.isZero())return xe(r,o,t.y);if(o.y.isZero())return xe(t,e,r.y);const n=we(e,o);if(n.isZero())return null;const i={x:r.x.minus(t.x),y:r.y.minus(t.y)},a=we(i,e).div(n),s=we(i,o).div(n),l=t.x.plus(s.times(e.x)),c=r.x.plus(a.times(o.x)),h=t.y.plus(s.times(e.y)),u=r.y.plus(a.times(o.y));return{x:l.plus(c).div(2),y:h.plus(u).div(2)}})(n,this.vector(),a,t.vector());return null===g?null:ve(o,g)?me.snap(g):null}split(e){const r=[],o=void 0!==e.events,n=new Se(e,!0),i=new Se(e,!1),a=this.rightSE;this.replaceRightSE(i),r.push(i),r.push(n);const s=new t(n,a,this.rings.slice(),this.windings.slice());return Se.comparePoints(s.leftSE.point,s.rightSE.point)>0&&s.swapEvents(),Se.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),o&&(n.checkForConsuming(),i.checkForConsuming()),r}swapEvents(){const t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let e=0,r=this.windings.length;e<r;e++)this.windings[e]*=-1}consume(e){let r=this,o=e;for(;r.consumedBy;)r=r.consumedBy;for(;o.consumedBy;)o=o.consumedBy;const n=t.compare(r,o);if(0!==n){if(n>0){const t=r;r=o,o=t}if(r.prev===o){const t=r;r=o,o=t}for(let t=0,e=o.rings.length;t<e;t++){const e=o.rings[t],n=o.windings[t],i=r.rings.indexOf(e);-1===i?(r.rings.push(e),r.windings.push(n)):r.windings[i]+=n}o.rings=null,o.windings=null,o.consumedBy=r,o.leftSE.consumedBy=r.leftSE,o.rightSE.consumedBy=r.rightSE}}prevInResult(){return 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(void 0!==this._beforeState)return this._beforeState;if(this.prev){const t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}else this._beforeState={rings:[],windings:[],multiPolys:[]};return this._beforeState}afterState(){if(void 0!==this._afterState)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,r=this._afterState.windings,o=this._afterState.multiPolys;for(let a=0,s=this.rings.length;a<s;a++){const t=this.rings[a],o=this.windings[a],n=e.indexOf(t);-1===n?(e.push(t),r.push(o)):r[n]+=o}const n=[],i=[];for(let a=0,s=e.length;a<s;a++){if(0===r[a])continue;const t=e[a],o=t.poly;if(-1===i.indexOf(o))if(t.isExterior)n.push(o);else{-1===i.indexOf(o)&&i.push(o);const e=n.indexOf(t.poly);-1!==e&&n.splice(e,1)}}for(let a=0,s=n.length;a<s;a++){const t=n[a].multiPoly;-1===o.indexOf(t)&&o.push(t)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(void 0!==this._isInResult)return this._isInResult;const t=this.beforeState().multiPolys,e=this.afterState().multiPolys;switch(Fe.type){case"union":{const r=0===t.length,o=0===e.length;this._isInResult=r!==o;break}case"intersection":{let r,o;t.length<e.length?(r=t.length,o=e.length):(r=e.length,o=t.length),this._isInResult=o===Fe.numMultiPolys&&r<o;break}case"xor":{const r=Math.abs(t.length-e.length);this._isInResult=r%2==1;break}case"difference":{const r=t=>1===t.length&&t[0].isSubject;this._isInResult=r(t)!==r(e);break}}return this._isInResult}},He=class{constructor(t,e,r){if(i(this,"poly"),i(this,"isExterior"),i(this,"segments"),i(this,"bbox"),!Array.isArray(t)||0===t.length)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=e,this.isExterior=r,this.segments=[],"number"!=typeof t[0][0]||"number"!=typeof t[0][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const o=me.snap({x:new oe(t[0][0]),y:new oe(t[0][1])});this.bbox={ll:{x:o.x,y:o.y},ur:{x:o.x,y:o.y}};let n=o;for(let i=1,a=t.length;i<a;i++){if("number"!=typeof t[i][0]||"number"!=typeof t[i][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const e=me.snap({x:new oe(t[i][0]),y:new oe(t[i][1])});e.x.eq(n.x)&&e.y.eq(n.y)||(this.segments.push(_e.fromRing(n,e,this)),e.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=e.x),e.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=e.y),e.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=e.x),e.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=e.y),n=e)}o.x.eq(n.x)&&o.y.eq(n.y)||this.segments.push(_e.fromRing(n,o,this))}getSweepEvents(){const t=[];for(let e=0,r=this.segments.length;e<r;e++){const r=this.segments[e];t.push(r.leftSE),t.push(r.rightSE)}return t}},Ge=class{constructor(t,e){if(i(this,"multiPoly"),i(this,"exteriorRing"),i(this,"interiorRings"),i(this,"bbox"),!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new He(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 r=1,o=t.length;r<o;r++){const e=new He(t[r],this,!1);e.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=e.bbox.ll.x),e.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=e.bbox.ll.y),e.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=e.bbox.ur.x),e.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=e.bbox.ur.y),this.interiorRings.push(e)}this.multiPoly=e}getSweepEvents(){const t=this.exteriorRing.getSweepEvents();for(let e=0,r=this.interiorRings.length;e<r;e++){const r=this.interiorRings[e].getSweepEvents();for(let e=0,o=r.length;e<o;e++)t.push(r[e])}return t}},Be=class{constructor(t,e){if(i(this,"isSubject"),i(this,"polys"),i(this,"bbox"),!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{"number"==typeof t[0][0][0]&&(t=[t])}catch(r){}this.polys=[],this.bbox={ll:{x:new oe(Number.POSITIVE_INFINITY),y:new oe(Number.POSITIVE_INFINITY)},ur:{x:new oe(Number.NEGATIVE_INFINITY),y:new oe(Number.NEGATIVE_INFINITY)}};for(let o=0,n=t.length;o<n;o++){const e=new Ge(t[o],this);e.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=e.bbox.ll.x),e.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=e.bbox.ll.y),e.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=e.bbox.ur.x),e.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=e.bbox.ur.y),this.polys.push(e)}this.isSubject=e}getSweepEvents(){const t=[];for(let e=0,r=this.polys.length;e<r;e++){const r=this.polys[e].getSweepEvents();for(let e=0,o=r.length;e<o;e++)t.push(r[e])}return t}};me.set;var ze=function(t,e={}){const r=[];if(R(t,t=>{r.push(t.coordinates)}),r.length<2)throw new Error("Must have at least 2 geometries");const o=((t,...e)=>Fe.run("union",t,e))(r[0],...r.slice(1));return 0===o.length?null:1===o.length?O(o[0],e.properties):_(o,e.properties)};var Ne=function(t,e={}){const r=[];if(R(t,t=>{r.push(t.coordinates)}),r.length<2)throw new Error("Must specify at least 2 geometries");const o=((t,...e)=>Fe.run("intersection",t,e))(r[0],...r.slice(1));return 0===o.length?null:1===o.length?O(o[0],e.properties):_(o,e.properties)};var Ue=function(t){const e=[];if(R(t,t=>{e.push(t.coordinates)}),e.length<2)throw new Error("Must have at least two features");const r=t.features[0].properties||{},o=((t,...e)=>Fe.run("difference",t,e))(e[0],...e.slice(1));return 0===o.length?null:1===o.length?O(o[0],r):_(o,r)};var Re=function(t){const e=[];return"FeatureCollection"===t.type?U(t,function(t){N(t,function(r){e.push(A(r,t.properties))})}):"Feature"===t.type?N(t,function(r){e.push(A(r,t.properties))}):N(t,function(t){e.push(A(t))}),T(e)};function Xe(t,e,r={}){const o=wt(t),n=bt(e);for(let i=0;i<n.length-1;i++){let t=!1;if(r.ignoreEndVertices&&(0===i&&(t="start"),i===n.length-2&&(t="end"),0===i&&i+1===n.length-1&&(t="both")),Ye(n[i],n[i+1],o,t,void 0===r.epsilon?null:r.epsilon))return!0}return!1}function Ye(t,e,r,o,n){const i=r[0],a=r[1],s=t[0],l=t[1],c=e[0],h=e[1],u=c-s,g=h-l,d=(r[0]-s)*g-(r[1]-l)*u;if(null!==n){if(Math.abs(d)>n)return!1}else if(0!==d)return!1;return Math.abs(u)===Math.abs(g)&&0===Math.abs(u)?!o&&(r[0]===t[0]&&r[1]===t[1]):o?"start"===o?Math.abs(u)>=Math.abs(g)?u>0?s<i&&i<=c:c<=i&&i<s:g>0?l<a&&a<=h:h<=a&&a<l:"end"===o?Math.abs(u)>=Math.abs(g)?u>0?s<=i&&i<c:c<i&&i<=s:g>0?l<=a&&a<h:h<a&&a<=l:"both"===o&&(Math.abs(u)>=Math.abs(g)?u>0?s<i&&i<c:c<i&&i<s:g>0?l<a&&a<h:h<a&&a<l):Math.abs(u)>=Math.abs(g)?u>0?s<=i&&i<=c:c<=i&&i<=s:g>0?l<=a&&a<=h:h<=a&&a<=l}function Ve(t,e={}){var r="object"==typeof e?e.mutate:e;if(!t)throw new Error("geojson is required");var o=Lt(t),n=[];switch(o){case"LineString":n=qe(t,o);break;case"MultiLineString":case"Polygon":bt(t).forEach(function(t){n.push(qe(t,o))});break;case"MultiPolygon":bt(t).forEach(function(t){var e=[];t.forEach(function(t){e.push(qe(t,o))}),n.push(e)});break;case"Point":return t;case"MultiPoint":var i={};bt(t).forEach(function(t){var e=t.join("-");Object.prototype.hasOwnProperty.call(i,e)||(n.push(t),i[e]=!0)});break;default:throw new Error(o+" geometry not supported")}return t.coordinates?!0===r?(t.coordinates=n,t):{type:o,coordinates:n}:!0===r?(t.geometry.coordinates=n,t):I({type:o,coordinates:n},t.properties,{bbox:t.bbox,id:t.id})}function qe(t,e){const r=bt(t);if(2===r.length&&!je(r[0],r[1]))return r;const o=[];let n=0,i=1,a=2;for(o.push(r[n]);a<r.length;)Xe(r[i],F([r[n],r[a]]))?i=a:(o.push(r[i]),n=i,i++,a=i),a++;if(o.push(r[i]),"Polygon"===e||"MultiPolygon"===e){if(Xe(o[0],F([o[1],o[o.length-2]]))&&(o.shift(),o.pop(),o.push(o[0])),o.length<4)throw new Error("invalid polygon, fewer than 4 points");if(!je(o[0],o[o.length-1]))throw new Error("invalid polygon, first and last points not equal")}return o}function je(t,e){return t[0]===e[0]&&t[1]===e[1]}function Ke(t){if(!t)throw new Error("geojson is required");switch(t.type){case"Feature":return $e(t);case"FeatureCollection":return function(t){const e={type:"FeatureCollection"};return Object.keys(t).forEach(r=>{switch(r){case"type":case"features":return;default:e[r]=t[r]}}),e.features=t.features.map(t=>$e(t)),e}(t);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return Je(t);default:throw new Error("unknown GeoJSON type")}}function $e(t){const e={type:"Feature"};return Object.keys(t).forEach(r=>{switch(r){case"type":case"properties":case"geometry":return;default:e[r]=t[r]}}),e.properties=We(t.properties),null==t.geometry?e.geometry=null:e.geometry=Je(t.geometry),e}function We(t){const e={};return t?(Object.keys(t).forEach(r=>{const o=t[r];"object"==typeof o?null===o?e[r]=null:Array.isArray(o)?e[r]=o.map(t=>t):e[r]=We(o):e[r]=o}),e):e}function Je(t){const e={type:t.type};return t.bbox&&(e.bbox=t.bbox),"GeometryCollection"===t.type?(e.geometries=t.geometries.map(t=>Je(t)),e):(e.coordinates=Ze(t.coordinates),e)}function Ze(t){const e=t;return"object"!=typeof e[0]?e.slice():e.map(t=>Ze(t))}function Qe(t,e){var r=t[0]-e[0],o=t[1]-e[1];return r*r+o*o}function tr(t,e,r){var o=e[0],n=e[1],i=r[0]-o,a=r[1]-n;if(0!==i||0!==a){var s=((t[0]-o)*i+(t[1]-n)*a)/(i*i+a*a);s>1?(o=r[0],n=r[1]):s>0&&(o+=i*s,n+=a*s)}return(i=t[0]-o)*i+(a=t[1]-n)*a}function er(t,e,r,o,n){for(var i,a=o,s=e+1;s<r;s++){var l=tr(t[s],t[e],t[r]);l>a&&(i=s,a=l)}a>o&&(i-e>1&&er(t,e,i,o,n),n.push(t[i]),r-i>1&&er(t,i,r,o,n))}function rr(t,e){var r=t.length-1,o=[t[0]];return er(t,0,r,e,o),o.push(t[r]),o}function or(t,e,r){if(t.length<=2)return t;var o=void 0!==e?e*e:1;return t=r?t:function(t,e){for(var r,o=t[0],n=[o],i=1,a=t.length;i<a;i++)Qe(r=t[i],o)>e&&(n.push(r),o=r);return o!==r&&n.push(r),n}(t,o),t=rr(t,o)}function nr(t,e,r){return t.map(function(t){if(t.length<4)throw new Error("invalid polygon");let o=e,n=or(t,o,r);for(;!ir(n)&&o>=Number.EPSILON;)o-=.01*o,n=or(t,o,r);return ir(n)?(n[n.length-1][0]===n[0][0]&&n[n.length-1][1]===n[0][1]||n.push(n[0]),n):t})}function ir(t){return!(t.length<3)&&!(3===t.length&&t[2][0]===t[0][0]&&t[2][1]===t[0][1])}var ar=function(t,e={}){var r,o,n;if(!z(e=null!=e?e:{}))throw new Error("options is invalid");const i=null!=(r=e.tolerance)?r:1,a=null!=(o=e.highQuality)&&o,s=null!=(n=e.mutate)&&n;if(!t)throw new Error("geojson is required");if(i&&i<0)throw new Error("invalid tolerance");return!0!==s&&(t=Ke(t)),R(t,function(t){!function(t,e,r){const o=t.type;if("Point"===o||"MultiPoint"===o)return t;if(Ve(t,{mutate:!0}),"GeometryCollection"!==o)switch(o){case"LineString":t.coordinates=or(t.coordinates,e,r);break;case"MultiLineString":t.coordinates=t.coordinates.map(t=>or(t,e,r));break;case"Polygon":t.coordinates=nr(t.coordinates,e,r);break;case"MultiPolygon":t.coordinates=t.coordinates.map(t=>nr(t,e,r))}}(t,i,a)}),t};function sr(t,e,r,o,n,i,a,s){let l,c,h,u,g;const d={x:null,y:null,onLine1:!1,onLine2:!1};return l=(s-i)*(r-t)-(a-n)*(o-e),0===l?null!==d.x&&null!==d.y&&d:(c=e-i,h=t-n,u=(a-n)*c-(s-i)*h,g=(r-t)*c-(o-e)*h,c=u/l,h=g/l,d.x=t+c*(r-t),d.y=e+c*(o-e),c>=0&&c<=1&&(d.onLine1=!0),h>=0&&h<=1&&(d.onLine2=!0),!(!d.onLine1||!d.onLine2)&&[d.x,d.y])}var lr=function(t){let e,r;const o={type:"FeatureCollection",features:[]};if(r="Feature"===t.type?t.geometry:t,"LineString"===r.type)e=[r.coordinates];else if("MultiLineString"===r.type)e=r.coordinates;else if("MultiPolygon"===r.type)e=[].concat(...r.coordinates);else{if("Polygon"!==r.type)throw new Error("Input must be a LineString, MultiLineString, Polygon, or MultiPolygon Feature or Geometry");e=r.coordinates}return e.forEach(t=>{e.forEach(e=>{for(let r=0;r<t.length-1;r++)for(let n=r;n<e.length-1;n++){if(t===e){if(1===Math.abs(r-n))continue;if(0===r&&n===t.length-2&&t[r][0]===t[t.length-1][0]&&t[r][1]===t[t.length-1][1])continue}const i=sr(t[r][0],t[r][1],t[r+1][0],t[r+1][1],e[n][0],e[n][1],e[n+1][0],e[n+1][1]);i&&o.features.push(A([i[0],i[1]]))}})}),o};function cr(t,e,r,o,n){hr(t,e,r||0,o||t.length-1,n||gr)}function hr(t,e,r,o,n){for(;o>r;){if(o-r>600){var i=o-r+1,a=e-r+1,s=Math.log(i),l=.5*Math.exp(2*s/3),c=.5*Math.sqrt(s*l*(i-l)/i)*(a-i/2<0?-1:1);hr(t,e,Math.max(r,Math.floor(e-a*l/i+c)),Math.min(o,Math.floor(e+(i-a)*l/i+c)),n)}var h=t[e],u=r,g=o;for(ur(t,r,e),n(t[o],h)>0&&ur(t,r,o);u<g;){for(ur(t,u,g),u++,g--;n(t[u],h)<0;)u++;for(;n(t[g],h)>0;)g--}0===n(t[r],h)?ur(t,r,g):ur(t,++g,o),g<=e&&(r=g+1),e<=g&&(o=g-1)}}function ur(t,e,r){var o=t[e];t[e]=t[r],t[r]=o}function gr(t,e){return t<e?-1:t>e?1:0}let dr=class{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const r=[];if(!xr(t,e))return r;const o=this.toBBox,n=[];for(;e;){for(let i=0;i<e.children.length;i++){const a=e.children[i],s=e.leaf?o(a):a;xr(t,s)&&(e.leaf?r.push(a):kr(t,s)?this._all(a,r):n.push(a))}e=n.pop()}return r}collides(t){let e=this.data;if(!xr(t,e))return!1;const r=[];for(;e;){for(let o=0;o<e.children.length;o++){const n=e.children[o],i=e.leaf?this.toBBox(n):n;if(xr(t,i)){if(e.leaf||kr(t,i))return!0;r.push(n)}}e=r.pop()}return!1}load(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e;return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Er([]),this}remove(t,e){if(!t)return this;let r=this.data;const o=this.toBBox(t),n=[],i=[];let a,s,l;for(;r||n.length;){if(r||(r=n.pop(),s=n[n.length-1],a=i.pop(),l=!0),r.leaf){const o=pr(t,r.children,e);if(-1!==o)return r.children.splice(o,1),n.push(r),this._condense(n),this}l||r.leaf||!kr(r,o)?s?(a++,r=s.children[a],l=!1):r=null:(n.push(r),i.push(a),a=0,s=r,r=r.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const r=[];for(;t;)t.leaf?e.push(...t.children):r.push(...t.children),t=r.pop();return e}_build(t,e,r,o){const n=r-e+1;let i,a=this._maxEntries;if(n<=a)return i=Er(t.slice(e,r+1)),fr(i,this.toBBox),i;o||(o=Math.ceil(Math.log(n)/Math.log(a)),a=Math.ceil(n/Math.pow(a,o-1))),i=Er([]),i.leaf=!1,i.height=o;const s=Math.ceil(n/a),l=s*Math.ceil(Math.sqrt(a));Sr(t,e,r,l,this.compareMinX);for(let c=e;c<=r;c+=l){const e=Math.min(c+l-1,r);Sr(t,c,e,s,this.compareMinY);for(let r=c;r<=e;r+=s){const n=Math.min(r+s-1,e);i.children.push(this._build(t,r,n,o-1))}}return fr(i,this.toBBox),i}_chooseSubtree(t,e,r,o){for(;o.push(e),!e.leaf&&o.length-1!==r;){let r,o=1/0,n=1/0;for(let i=0;i<e.children.length;i++){const a=e.children[i],s=wr(a),l=Pr(t,a)-s;l<n?(n=l,o=s<o?s:o,r=a):l===n&&s<o&&(o=s,r=a)}e=r||e.children[0]}return e}_insert(t,e,r){const o=r?t:this.toBBox(t),n=[],i=this._chooseSubtree(o,this.data,e,n);for(i.children.push(t),mr(i,o);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(o,n,e)}_split(t,e){const r=t[e],o=r.children.length,n=this._minEntries;this._chooseSplitAxis(r,n,o);const i=this._chooseSplitIndex(r,n,o),a=Er(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,fr(r,this.toBBox),fr(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(r,a)}_splitRoot(t,e){this.data=Er([t,e]),this.data.height=t.height+1,this.data.leaf=!1,fr(this.data,this.toBBox)}_chooseSplitIndex(t,e,r){let o,n=1/0,i=1/0;for(let a=e;a<=r-e;a++){const e=yr(t,0,a,this.toBBox),s=yr(t,a,r,this.toBBox),l=Lr(e,s),c=wr(e)+wr(s);l<n?(n=l,o=a,i=c<i?c:i):l===n&&c<i&&(i=c,o=a)}return o||r-e}_chooseSplitAxis(t,e,r){const o=t.leaf?this.compareMinX:vr,n=t.leaf?this.compareMinY:Mr;this._allDistMargin(t,e,r,o)<this._allDistMargin(t,e,r,n)&&t.children.sort(o)}_allDistMargin(t,e,r,o){t.children.sort(o);const n=this.toBBox,i=yr(t,0,e,n),a=yr(t,r-e,r,n);let s=br(i)+br(a);for(let l=e;l<r-e;l++){const e=t.children[l];mr(i,t.leaf?n(e):e),s+=br(i)}for(let l=r-e-1;l>=e;l--){const e=t.children[l];mr(a,t.leaf?n(e):e),s+=br(a)}return s}_adjustParentBBoxes(t,e,r){for(let o=r;o>=0;o--)mr(e[o],t)}_condense(t){for(let e,r=t.length-1;r>=0;r--)0===t[r].children.length?r>0?(e=t[r-1].children,e.splice(e.indexOf(t[r]),1)):this.clear():fr(t[r],this.toBBox)}};function pr(t,e,r){if(!r)return e.indexOf(t);for(let o=0;o<e.length;o++)if(r(t,e[o]))return o;return-1}function fr(t,e){yr(t,0,t.children.length,e,t)}function yr(t,e,r,o,n){n||(n=Er(null)),n.minX=1/0,n.minY=1/0,n.maxX=-1/0,n.maxY=-1/0;for(let i=e;i<r;i++){const e=t.children[i];mr(n,t.leaf?o(e):e)}return n}function mr(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function vr(t,e){return t.minX-e.minX}function Mr(t,e){return t.minY-e.minY}function wr(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function br(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Pr(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function Lr(t,e){const r=Math.max(t.minX,e.minX),o=Math.max(t.minY,e.minY),n=Math.min(t.maxX,e.maxX),i=Math.min(t.maxY,e.maxY);return Math.max(0,n-r)*Math.max(0,i-o)}function kr(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function xr(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Er(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Sr(t,e,r,o,n){const i=[e,r];for(;i.length;){if((r=i.pop())-(e=i.pop())<=o)continue;const a=e+Math.ceil((r-e)/o/2)*o;cr(t,a,e,r,n),i.push(e,a,a,r)}}const Dr=11102230246251565e-32,Cr=134217729,Ir=(3+8*Dr)*Dr;function Ar(t,e,r,o,n){let i,a,s,l,c=e[0],h=o[0],u=0,g=0;h>c==h>-c?(i=c,c=e[++u]):(i=h,h=o[++g]);let d=0;if(u<t&&g<r)for(h>c==h>-c?(a=c+i,s=i-(a-c),c=e[++u]):(a=h+i,s=i-(a-h),h=o[++g]),i=a,0!==s&&(n[d++]=s);u<t&&g<r;)h>c==h>-c?(a=i+c,l=a-i,s=i-(a-l)+(c-l),c=e[++u]):(a=i+h,l=a-i,s=i-(a-l)+(h-l),h=o[++g]),i=a,0!==s&&(n[d++]=s);for(;u<t;)a=i+c,l=a-i,s=i-(a-l)+(c-l),c=e[++u],i=a,0!==s&&(n[d++]=s);for(;g<r;)a=i+h,l=a-i,s=i-(a-l)+(h-l),h=o[++g],i=a,0!==s&&(n[d++]=s);return 0===i&&0!==d||(n[d++]=i),d}function Or(t){return new Float64Array(t)}const Fr=Or(4),Tr=Or(8),_r=Or(12),Hr=Or(16),Gr=Or(4);function Br(t,e,r,o,n,i){const a=(e-i)*(r-n),s=(t-n)*(o-i),l=a-s,c=Math.abs(a+s);return Math.abs(l)>=33306690738754716e-32*c?l:-function(t,e,r,o,n,i,a){let s,l,c,h,u,g,d,p,f,y,m,v,M,w,b,P,L,k;const x=t-n,E=r-n,S=e-i,D=o-i;w=x*D,g=Cr*x,d=g-(g-x),p=x-d,g=Cr*D,f=g-(g-D),y=D-f,b=p*y-(w-d*f-p*f-d*y),P=S*E,g=Cr*S,d=g-(g-S),p=S-d,g=Cr*E,f=g-(g-E),y=E-f,L=p*y-(P-d*f-p*f-d*y),m=b-L,u=b-m,Fr[0]=b-(m+u)+(u-L),v=w+m,u=v-w,M=w-(v-u)+(m-u),m=M-P,u=M-m,Fr[1]=M-(m+u)+(u-P),k=v+m,u=k-v,Fr[2]=v-(k-u)+(m-u),Fr[3]=k;let C=function(t,e){let r=e[0];for(let o=1;o<t;o++)r+=e[o];return r}(4,Fr),I=22204460492503146e-32*a;if(C>=I||-C>=I)return C;if(u=t-x,s=t-(x+u)+(u-n),u=r-E,c=r-(E+u)+(u-n),u=e-S,l=e-(S+u)+(u-i),u=o-D,h=o-(D+u)+(u-i),0===s&&0===l&&0===c&&0===h)return C;if(I=11093356479670487e-47*a+Ir*Math.abs(C),C+=x*h+D*s-(S*c+E*l),C>=I||-C>=I)return C;w=s*D,g=Cr*s,d=g-(g-s),p=s-d,g=Cr*D,f=g-(g-D),y=D-f,b=p*y-(w-d*f-p*f-d*y),P=l*E,g=Cr*l,d=g-(g-l),p=l-d,g=Cr*E,f=g-(g-E),y=E-f,L=p*y-(P-d*f-p*f-d*y),m=b-L,u=b-m,Gr[0]=b-(m+u)+(u-L),v=w+m,u=v-w,M=w-(v-u)+(m-u),m=M-P,u=M-m,Gr[1]=M-(m+u)+(u-P),k=v+m,u=k-v,Gr[2]=v-(k-u)+(m-u),Gr[3]=k;const A=Ar(4,Fr,4,Gr,Tr);w=x*h,g=Cr*x,d=g-(g-x),p=x-d,g=Cr*h,f=g-(g-h),y=h-f,b=p*y-(w-d*f-p*f-d*y),P=S*c,g=Cr*S,d=g-(g-S),p=S-d,g=Cr*c,f=g-(g-c),y=c-f,L=p*y-(P-d*f-p*f-d*y),m=b-L,u=b-m,Gr[0]=b-(m+u)+(u-L),v=w+m,u=v-w,M=w-(v-u)+(m-u),m=M-P,u=M-m,Gr[1]=M-(m+u)+(u-P),k=v+m,u=k-v,Gr[2]=v-(k-u)+(m-u),Gr[3]=k;const O=Ar(A,Tr,4,Gr,_r);w=s*h,g=Cr*s,d=g-(g-s),p=s-d,g=Cr*h,f=g-(g-h),y=h-f,b=p*y-(w-d*f-p*f-d*y),P=l*c,g=Cr*l,d=g-(g-l),p=l-d,g=Cr*c,f=g-(g-c),y=c-f,L=p*y-(P-d*f-p*f-d*y),m=b-L,u=b-m,Gr[0]=b-(m+u)+(u-L),v=w+m,u=v-w,M=w-(v-u)+(m-u),m=M-P,u=M-m,Gr[1]=M-(m+u)+(u-P),k=v+m,u=k-v,Gr[2]=v-(k-u)+(m-u),Gr[3]=k;const F=Ar(O,_r,4,Gr,Hr);return Hr[F-1]}(t,e,r,o,n,i,c)}function zr(t,e){var r,o,n,i,a,s,l,c,h,u=0,g=t[0],d=t[1],p=e.length;for(r=0;r<p;r++){o=0;var f=e[r],y=f.length-1;if((c=f[0])[0]!==f[y][0]&&c[1]!==f[y][1])throw new Error("First and last coordinates in a ring must be the same");for(i=c[0]-g,a=c[1]-d;o<y;o++){if(s=(h=f[o+1])[0]-g,l=h[1]-d,0===a&&0===l){if(s<=0&&i>=0||i<=0&&s>=0)return 0}else if(l>=0&&a<=0||l<=0&&a>=0){if(0===(n=Br(i,s,a,l,0,0)))return 0;(n>0&&l>0&&a<=0||n<0&&l<=0&&a>0)&&u++}c=h,a=l,i=s}}return u%2!=0}function Nr(t,e,r={}){if(!t)throw new Error("point is required");if(!e)throw new Error("polygon is required");const o=wt(t),n=Pt(e),i=n.type,a=e.bbox;let s=n.coordinates;if(a&&!1===function(t,e){return e[0]<=t[0]&&e[1]<=t[1]&&e[2]>=t[0]&&e[3]>=t[1]}(o,a))return!1;"Polygon"===i&&(s=[s]);let l=!1;for(var c=0;c<s.length;++c){const t=zr(o,s[c]);if(0===t)return!r.ignoreBoundary;t&&(l=!0)}return l}var Ur=Nr;function Rr(t,e){if("Polygon"!==t.geometry.type)throw new Error("The input feature must be a Polygon");for(var r=t.geometry.coordinates,o=[],n={},i=[],a=0;a<r.length;a++)for(var s=0;s<r[a].length-1;s++)i.push(g(a,s));var l=new dr;l.load(i);for(var c=0;c<r.length;c++)for(var h=0;h<r[c].length-1;h++){l.search(g(c,h)).forEach(function(t){var e=t.ring,r=t.edge;u(c,h,e,r)})}return o;function u(t,i,a,s){var l,c,h=r[t][i],u=r[t][i+1],g=r[a][s],d=r[a][s+1],p=function(t,e,r,o){if(Xr(t,r)||Xr(t,o)||Xr(e,r)||Xr(o,r))return null;var n=t[0],i=t[1],a=e[0],s=e[1],l=r[0],c=r[1],h=o[0],u=o[1],g=(n-a)*(c-u)-(i-s)*(l-h);return 0===g?null:[((n*s-i*a)*(l-h)-(n-a)*(l*u-c*h))/g,((n*s-i*a)*(c-u)-(i-s)*(l*u-c*h))/g]}(h,u,g,d);if(null!==p&&(l=u[0]!==h[0]?(p[0]-h[0])/(u[0]-h[0]):(p[1]-h[1])/(u[1]-h[1]),c=d[0]!==g[0]?(p[0]-g[0])/(d[0]-g[0]):(p[1]-g[1])/(d[1]-g[1]),!(l>=1||l<=0||c>=1||c<=0))){var f=p,y=!n[f.toString()];y&&(n[f.toString()]=!0),e&&o.push(e(p,t,i,h,u,l,a,s,g,d,c,y))}}function g(t,e){var o,n,i,a,s=r[t][e],l=r[t][e+1];return s[0]<l[0]?(o=s[0],n=l[0]):(o=l[0],n=s[0]),s[1]<l[1]?(i=s[1],a=l[1]):(i=l[1],a=s[1]),{minX:o,minY:i,maxX:n,maxY:a,ring:t,edge:e}}}function Xr(t,e){if(!t||!e)return!1;if(t.length!==e.length)return!1;for(var r=0,o=t.length;r<o;r++)if(t[r]instanceof Array&&e[r]instanceof Array){if(!Xr(t[r],e[r]))return!1}else if(t[r]!==e[r])return!1;return!0}function Yr(t){if("Feature"!=t.type)throw new Error("The input must a geojson object of type Feature");if(void 0===t.geometry||null==t.geometry)throw new Error("The input must a geojson object with a non-empty geometry");if("Polygon"!=t.geometry.type)throw new Error("The input must be a geojson Polygon");for(var e=t.geometry.coordinates.length,r=[],o=0;o<e;o++){var n=t.geometry.coordinates[o];$r(n[0],n[n.length-1])||n.push(n[0]);for(var i=0;i<n.length-1;i++)r.push(n[i])}if(!function(t){for(var e={},r=1,o=0,n=t.length;o<n;++o){if(Object.prototype.hasOwnProperty.call(e,t[o].toString())){r=0;break}e[t[o].toString()]=1}return r}(r))throw new Error("The input polygon may not have duplicate vertices (except for the first and last vertex of each ring)");var a=r.length,s=Rr(t,function(t,e,r,o,n,i,a,s,l,c,h,u){return[t,e,r,o,n,i,a,s,l,c,h,u]}),l=s.length;if(0==l){var c=[];for(o=0;o<e;o++)c.push(O([t.geometry.coordinates[o]],{parent:-1,winding:Kr(t.geometry.coordinates[o])}));let r=T(c);return G(r),B(r),r}var h=[],u=[];for(o=0;o<e;o++){h.push([]);for(i=0;i<t.geometry.coordinates[o].length-1;i++)h[o].push([new Vr(t.geometry.coordinates[o][Wr(i+1,t.geometry.coordinates[o].length-1)],1,[o,i],[o,Wr(i+1,t.geometry.coordinates[o].length-1)],void 0)]),u.push(new qr(t.geometry.coordinates[o][i],[o,Wr(i-1,t.geometry.coordinates[o].length-1)],[o,i],void 0,void 0,!1,!0))}for(o=0;o<l;o++)h[s[o][1]][s[o][2]].push(new Vr(s[o][0],s[o][5],[s[o][1],s[o][2]],[s[o][6],s[o][7]],void 0)),s[o][11]&&u.push(new qr(s[o][0],[s[o][1],s[o][2]],[s[o][6],s[o][7]],void 0,void 0,!0,!0));var g=u.length;for(o=0;o<h.length;o++)for(i=0;i<h[o].length;i++)h[o][i].sort(function(t,e){return t.param<e.param?-1:1});var d=[];for(o=0;o<g;o++)d.push({minX:u[o].coord[0],minY:u[o].coord[1],maxX:u[o].coord[0],maxY:u[o].coord[1],index:o});var p=new dr;p.load(d);for(o=0;o<h.length;o++)for(i=0;i<h[o].length;i++)for(var f=0;f<h[o][i].length;f++){let e;e=f==h[o][i].length-1?h[o][Wr(i+1,t.geometry.coordinates[o].length-1)][0].coord:h[o][i][f+1].coord;var y=p.search({minX:e[0],minY:e[1],maxX:e[0],maxY:e[1]})[0];h[o][i][f].nxtIsectAlongEdgeIn=y.index}for(o=0;o<h.length;o++)for(i=0;i<h[o].length;i++)for(f=0;f<h[o][i].length;f++){let t=h[o][i][f].coord;var m=(y=p.search({minX:t[0],minY:t[1],maxX:t[0],maxY:t[1]})[0]).index;m<a?u[m].nxtIsectAlongRingAndEdge2=h[o][i][f].nxtIsectAlongEdgeIn:$r(u[m].ringAndEdge1,h[o][i][f].ringAndEdgeIn)?u[m].nxtIsectAlongRingAndEdge1=h[o][i][f].nxtIsectAlongEdgeIn:u[m].nxtIsectAlongRingAndEdge2=h[o][i][f].nxtIsectAlongEdgeIn}var v=[];for(o=0,i=0;i<e;i++){var M=o;for(f=0;f<t.geometry.coordinates[i].length-1;f++)u[o].coord[0]<u[M].coord[0]&&(M=o),o++;var w=u[M].nxtIsectAlongRingAndEdge2;for(f=0;f<u.length;f++)if(u[f].nxtIsectAlongRingAndEdge1==M||u[f].nxtIsectAlongRingAndEdge2==M){var b=f;break}var P=jr([u[b].coord,u[M].coord,u[w].coord],!0)?1:-1;v.push({isect:M,parent:-1,winding:P})}v.sort(function(t,e){return u[t.isect].coord>u[e.isect].coord?-1:1});for(c=[];v.length>0;){var L=v.pop(),k=L.isect,x=L.parent,E=L.winding,S=c.length,D=[u[k].coord],C=k;if(u[k].ringAndEdge1Walkable)var I=u[k].ringAndEdge1,A=u[k].nxtIsectAlongRingAndEdge1;else I=u[k].ringAndEdge2,A=u[k].nxtIsectAlongRingAndEdge2;for(;!$r(u[k].coord,u[A].coord);){D.push(u[A].coord);var F=void 0;for(o=0;o<v.length;o++)if(v[o].isect==A){F=o;break}if(null!=F&&v.splice(F,1),$r(I,u[A].ringAndEdge1)){if(I=u[A].ringAndEdge2,u[A].ringAndEdge2Walkable=!1,u[A].ringAndEdge1Walkable){var _={isect:A};jr([u[C].coord,u[A].coord,u[u[A].nxtIsectAlongRingAndEdge2].coord],1==E)?(_.parent=x,_.winding=-E):(_.parent=S,_.winding=E),v.push(_)}C=A,A=u[A].nxtIsectAlongRingAndEdge2}else{if(I=u[A].ringAndEdge1,u[A].ringAndEdge1Walkable=!1,u[A].ringAndEdge2Walkable){_={isect:A};jr([u[C].coord,u[A].coord,u[u[A].nxtIsectAlongRingAndEdge1].coord],1==E)?(_.parent=x,_.winding=-E):(_.parent=S,_.winding=E),v.push(_)}C=A,A=u[A].nxtIsectAlongRingAndEdge1}}D.push(u[A].coord),c.push(O([D],{index:S,parent:x,winding:E,netWinding:void 0}))}let H=T(c);function G(t){for(var e=[],r=0;r<t.features.length;r++)-1==t.features[r].properties.parent&&e.push(r);if(e.length>1)for(r=0;r<e.length;r++){for(var o=-1,n=1/0,i=0;i<t.features.length;i++)e[r]!=i&&Nr(t.features[e[r]].geometry.coordinates[0][0],t.features[i],{ignoreBoundary:!0})&&V(t.features[i])<n&&(o=i);t.features[e[r]].properties.parent=o}}function B(t){for(var e=0;e<t.features.length;e++)if(-1==t.features[e].properties.parent){var r=t.features[e].properties.winding;t.features[e].properties.netWinding=r,z(t,e,r)}}function z(t,e,r){for(var o=0;o<t.features.length;o++)if(t.features[o].properties.parent==e){var n=r+t.features[o].properties.winding;t.features[o].properties.netWinding=n,z(t,o,n)}}return G(H),B(H),H}var Vr=class{constructor(t,e,r,o,n){this.coord=t,this.param=e,this.ringAndEdgeIn=r,this.ringAndEdgeOut=o,this.nxtIsectAlongEdgeIn=n}},qr=class{constructor(t,e,r,o,n,i,a){this.coord=t,this.ringAndEdge1=e,this.ringAndEdge2=r,this.nxtIsectAlongRingAndEdge1=o,this.nxtIsectAlongRingAndEdge2=n,this.ringAndEdge1Walkable=i,this.ringAndEdge2Walkable=a}};function jr(t,e){if(void 0===e&&(e=!0),3!=t.length)throw new Error("This function requires an array of three points [x,y]");return(t[1][0]-t[0][0])*(t[2][1]-t[0][1])-(t[1][1]-t[0][1])*(t[2][0]-t[0][0])>=0==e}function Kr(t){for(var e=0,r=0;r<t.length-1;r++)t[r][0]<t[e][0]&&(e=r);if(jr([t[Wr(e-1,t.length-1)],t[e],t[Wr(e+1,t.length-1)]],!0))var o=1;else o=-1;return o}function $r(t,e){if(!t||!e)return!1;if(t.length!=e.length)return!1;for(var r=0,o=t.length;r<o;r++)if(t[r]instanceof Array&&e[r]instanceof Array){if(!$r(t[r],e[r]))return!1}else if(t[r]!=e[r])return!1;return!0}function Wr(t,e){return(t%e+e)%e}var Jr=function(t){var e=[];return X(t,function(t){"Polygon"===t.geometry.type&&U(Yr(t),function(r){e.push(O(r.geometry.coordinates,t.properties))})}),T(e)};function Zr(t,e={}){if(null!=t.bbox&&!0!==e.recompute)return t.bbox;const r=[1/0,1/0,-1/0,-1/0];return N(t,t=>{r[0]>t[0]&&(r[0]=t[0]),r[1]>t[1]&&(r[1]=t[1]),r[2]<t[0]&&(r[2]=t[0]),r[3]<t[1]&&(r[3]=t[1])}),r}function Qr(t){var e;if(t.bbox)e=t.bbox;else if(Array.isArray(t)&&4===t.length)e=t;else if(Array.isArray(t)&&6===t.length)e=[t[0],t[1],t[3],t[4]];else if("Feature"===t.type)e=Zr(t);else{if("FeatureCollection"!==t.type)throw new Error("invalid geojson");e=Zr(t)}return{minX:e[0],minY:e[1],maxX:e[2],maxY:e[3]}}var to=class{constructor(t=9){this.tree=new dr(t),this.tree.toBBox=Qr}insert(t){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:Zr(t),this.tree.insert(t),this}load(t){var e=[];return Array.isArray(t)?t.forEach(function(t){if("Feature"!==t.type)throw new Error("invalid features");t.bbox=t.bbox?t.bbox:Zr(t),e.push(t)}):U(t,function(t){if("Feature"!==t.type)throw new Error("invalid features");t.bbox=t.bbox?t.bbox:Zr(t),e.push(t)}),this.tree.load(e),this}remove(t,e){if("Feature"!==t.type)throw new Error("invalid feature");return t.bbox=t.bbox?t.bbox:Zr(t),this.tree.remove(t,e),this}clear(){return this.tree.clear(),this}search(t){return T(this.tree.search(Qr(t)))}collides(t){return this.tree.collides(Qr(t))}all(){return T(this.tree.all())}toJSON(){return this.tree.toJSON()}fromJSON(t){return this.tree.fromJSON(t),this}};function eo(t){return new to(t)}function ro(t,e){if(!z(e=null!=e?e:{}))throw new Error("options is invalid");var r=e.precision,o=e.coordinates,n=e.mutate;if(r=null==r||isNaN(r)?6:r,o=null==o||isNaN(o)?3:o,!t)throw new Error("<geojson> is required");if("number"!=typeof r)throw new Error("<precision> must be a number");if("number"!=typeof o)throw new Error("<coordinates> must be a number");!1!==n&&void 0!==n||(t=JSON.parse(JSON.stringify(t)));var i=Math.pow(10,r);return N(t,function(t){!function(t,e,r){t.length>r&&t.splice(r,t.length);for(var o=0;o<t.length;o++)t[o]=Math.round(t[o]*e)/e}(t,i,o)}),t}function oo(t){if(!t)throw new Error("geojson is required");const e=[];return X(t,t=>{!function(t,e){let r=[];const o=t.geometry;if(null!==o){switch(o.type){case"Polygon":r=bt(o);break;case"LineString":r=[bt(o)]}r.forEach(r=>{const o=function(t,e){const r=[];return t.reduce((t,o)=>{const n=F([t,o],e);return n.bbox=function(t,e){const r=t[0],o=t[1],n=e[0],i=e[1];return[r<n?r:n,o<i?o:i,r>n?r:n,o>i?o:i]}(t,o),r.push(n),o}),r}(r,t.properties);o.forEach(t=>{t.id=e.length,e.push(t)})})}}(t,e)}),T(e)}function no(t,e,r={}){var o=wt(t),n=wt(e),i=G(n[1]-o[1]),a=G(n[0]-o[0]),s=G(o[1]),l=G(n[1]),c=Math.pow(Math.sin(i/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(s)*Math.cos(l);return function(t,e="kilometers"){const r=C[e];if(!r)throw new Error(e+" units is invalid");return t*r}(2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c)),r.units)}var io=Object.defineProperty,ao=Object.defineProperties,so=Object.getOwnPropertyDescriptors,lo=Object.getOwnPropertySymbols,co=Object.prototype.hasOwnProperty,ho=Object.prototype.propertyIsEnumerable,uo=(t,e,r)=>e in t?io(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,go=(t,e)=>{for(var r in e||(e={}))co.call(e,r)&&uo(t,r,e[r]);if(lo)for(var r of lo(e))ho.call(e,r)&&uo(t,r,e[r]);return t},po=(t,e)=>ao(t,so(e));function fo(t,e){const[r,o,n]=t,[i,a,s]=e;return r*i+o*a+n*s}function yo(t,e){const[r,o,n]=t,[i,a,s]=e;return[o*s-n*a,n*i-r*s,r*a-o*i]}function mo(t){const e=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}(t);return[t[0]/e,t[1]/e,t[2]/e]}function vo(t){const e=G(t[1]),r=G(t[0]);return[Math.cos(e)*Math.cos(r),Math.cos(e)*Math.sin(r),Math.sin(e)]}function Mo(t){const[e,r,o]=t,n=Math.min(Math.max(o,-1),1),i=H(Math.asin(n));return[H(Math.atan2(r,e)),i]}function wo(t,e,r){const o=vo(t),n=vo(e),i=vo(r),a=yo(o,n);if(0===a[0]&&0===a[1]&&0===a[2])return fo(o,n)>0?[[...e],!0]:[[...r],!1];const s=yo(a,i);if(0===s[0]&&0===s[1]&&0===s[2])return[[...e],!0];const l=mo(yo(s,a)),c=[-l[0],-l[1],-l[2]],h=fo(i,l)>fo(i,c)?l:c,u=mo(a),g=fo(yo(o,h),u),d=fo(yo(h,n),u);return g>=0&&d>=0?[Mo(h),!1]:fo(o,i)>fo(n,i)?[[...t],!1]:[[...e],!0]}function bo(t,e){if(!t)throw new Error("line is required");if(!e)throw new Error("splitter is required");const r=Lt(t),o=Lt(e);if("LineString"!==r)throw new Error("line must be LineString");if("FeatureCollection"===o)throw new Error("splitter cannot be a FeatureCollection");if("GeometryCollection"===o)throw new Error("splitter cannot be a GeometryCollection");var n=ro(e,{precision:7});switch("Feature"!==t.type&&(t=I(t)),o){case"Point":return Lo(t,n);case"MultiPoint":return Po(t,n);case"LineString":case"MultiLineString":case"Polygon":case"MultiPolygon":return Po(t,Gt(t,n,{ignoreSelfIntersections:!0}))}}function Po(t,e){var r=[],o=eo();return X(e,function(e){if(r.forEach(function(t,e){t.id=e}),r.length){var n=o.search(e);if(n.features.length){var i=ko(e,n);r=r.filter(function(t){return t.id!==i.id}),o.remove(i),U(Lo(i,e),function(t){r.push(t),o.insert(t)})}}else r=Lo(t,e).features,o.load(T(r))}),T(r)}function Lo(t,e){var r=[],o=bt(t)[0],n=bt(t)[t.geometry.coordinates.length-1];if(xo(o,wt(e))||xo(n,wt(e)))return T([t]);var i=eo(),a=oo(t);i.load(a);var s=i.search(e);if(!s.features.length)return T([t]);var l=ko(e,s),c=function(t,e,r){var o=r;return U(t,function(t,n){o=0===n&&void 0===r?t:e(o,t,n)}),o}(a,function(t,o,n){var i=bt(o)[1],a=wt(e);return n===l.id?(t.push(a),r.push(F(t)),xo(a,i)?[a]:[a,i]):(t.push(i),t)},[o]);return c.length>1&&r.push(F(c)),T(r)}function ko(t,e){if(!e.features.length)throw new Error("lines must contain features");if(1===e.features.length)return e.features[0];var r,o=1/0;return U(e,function(e){var n=function(t,e,r={}){if(!t||!e)throw new Error("lines and inputPoint are required arguments");const o=wt(e);let n=A([1/0,1/0],{lineStringIndex:-1,segmentIndex:-1,totalDistance:-1,lineDistance:-1,segmentDistance:-1,pointDistance:1/0,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),i=0,a=0,s=-1;return X(t,function(t,l,c){s!==c&&(s=c,a=0);const h=bt(t);for(let s=0;s<h.length-1;s++){const t=A(h[s]),l=wt(t),u=A(h[s+1]),g=wt(u),d=no(t,u,r);let p,f;g[0]===o[0]&&g[1]===o[1]?[p,f]=[g,!0]:l[0]===o[0]&&l[1]===o[1]?[p,f]=[l,!1]:[p,f]=wo(l,g,o);const y=no(e,p,r);if(y<n.properties.pointDistance){const e=no(t,p,r);n=A(p,{lineStringIndex:c,segmentIndex:f?s+1:s,totalDistance:i+e,lineDistance:a+e,segmentDistance:e,pointDistance:y,multiFeatureIndex:-1,index:-1,location:-1,dist:1/0}),n.properties=po(go({},n.properties),{multiFeatureIndex:n.properties.lineStringIndex,index:n.properties.segmentIndex,location:n.properties.totalDistance,dist:n.properties.pointDistance})}i+=d,a+=d}}),n}(e,t),i=n.properties.dist;i<o&&(r=e,o=i)}),r}function xo(t,e){return t[0]===e[0]&&t[1]===e[1]}function Eo(t,e){return!(t[0]>e[0])&&(!(t[2]<e[2])&&(!(t[1]>e[1])&&!(t[3]<e[3])))}function So(t,e){return t[0]===e[0]&&t[1]===e[1]}function Do(t,e){return[(t[0]+e[0])/2,(t[1]+e[1])/2]}var Co=function(t,e){var r=Pt(t),o=Pt(e),n=r.type,i=o.type;switch(n){case"Point":switch(i){case"MultiPoint":return function(t,e){var r,o=!1;for(r=0;r<e.coordinates.length;r++)if(So(e.coordinates[r],t.coordinates)){o=!0;break}return o}(r,o);case"LineString":return Xe(r,o,{ignoreEndVertices:!0});case"Polygon":case"MultiPolygon":return Nr(r,o,{ignoreBoundary:!0});default:throw new Error("feature2 "+i+" geometry not supported")}case"MultiPoint":switch(i){case"MultiPoint":return function(t,e){for(var r=0;r<t.coordinates.length;r++){for(var o=!1,n=0;n<e.coordinates.length;n++)So(t.coordinates[r],e.coordinates[n])&&(o=!0);if(!o)return!1}return!0}(r,o);case"LineString":return function(t,e){for(var r=!1,o=0;o<t.coordinates.length;o++){if(!Xe(t.coordinates[o],e))return!1;r||(r=Xe(t.coordinates[o],e,{ignoreEndVertices:!0}))}return r}(r,o);case"Polygon":case"MultiPolygon":return function(t,e){for(var r=!0,o=!1,n=0;n<t.coordinates.length;n++){if(!(o=Nr(t.coordinates[n],e))){r=!1;break}o=Nr(t.coordinates[n],e,{ignoreBoundary:!0})}return r&&o}(r,o);default:throw new Error("feature2 "+i+" geometry not supported")}case"LineString":switch(i){case"LineString":return function(t,e){for(var r=0;r<t.coordinates.length;r++)if(!Xe(t.coordinates[r],e))return!1;return!0}(r,o);case"Polygon":case"MultiPolygon":return function(t,e){const r=Zr(e),o=Zr(t);if(!Eo(r,o))return!1;for(const a of t.coordinates)if(!Nr(a,e))return!1;let n=!1;const i=function(t,e){const r=t.coordinates,o=[];for(let n=0;n<r.length-1;n++){const t=F([r[n],r[n+1]]),i=bo(t,I(e));0===i.features.length?o.push(t):o.push(...i.features)}return T(o)}(t,e);for(const a of i.features){const t=Do(a.geometry.coordinates[0],a.geometry.coordinates[1]);if(!Nr(t,e))return!1;!n&&Nr(t,e,{ignoreBoundary:!0})&&(n=!0)}return n}(r,o);default:throw new Error("feature2 "+i+" geometry not supported")}case"Polygon":switch(i){case"Polygon":case"MultiPolygon":return function(t,e){var r=Zr(t);if(!Eo(Zr(e),r))return!1;for(var o=0;o<t.coordinates[0].length;o++)if(!Nr(t.coordinates[0][o],e))return!1;return!0}(r,o);default:throw new Error("feature2 "+i+" geometry not supported")}default:throw new Error("feature1 "+n+" geometry not supported")}},Io=Object.defineProperty,Ao=(t,e)=>Io(t,"name",{value:e,configurable:!0}),Oo=class{constructor(t){var e,r,o;this.direction=!1,this.compareProperties=!0,this.precision=10**-(null!=(e=null==t?void 0:t.precision)?e:17),this.direction=null!=(r=null==t?void 0:t.direction)&&r,this.compareProperties=null==(o=null==t?void 0:t.compareProperties)||o}compare(t,e){if(t.type!==e.type)return!1;if(!To(t,e))return!1;switch(t.type){case"Point":return this.compareCoord(t.coordinates,e.coordinates);case"LineString":return this.compareLine(t.coordinates,e.coordinates);case"Polygon":return this.comparePolygon(t,e);case"GeometryCollection":return this.compareGeometryCollection(t,e);case"Feature":return this.compareFeature(t,e);case"FeatureCollection":return this.compareFeatureCollection(t,e);default:if(t.type.startsWith("Multi")){const r=_o(t),o=_o(e);return r.every(t=>o.some(e=>this.compare(t,e)))}}return!1}compareCoord(t,e){return t.length===e.length&&t.every((t,r)=>Math.abs(t-e[r])<this.precision)}compareLine(t,e,r=0,o=!1){if(!To(t,e))return!1;const n=t;let i=e;if(o&&!this.compareCoord(n[0],i[0])){const t=this.fixStartIndex(i,n);if(!t)return!1;i=t}const a=this.compareCoord(n[r],i[r]);return this.direction||a?this.comparePath(n,i):!!this.compareCoord(n[r],i[i.length-(1+r)])&&this.comparePath(n.slice().reverse(),i)}fixStartIndex(t,e){let r,o=-1;for(let n=0;n<t.length;n++)if(this.compareCoord(t[n],e[0])){o=n;break}return o>=0&&(r=[].concat(t.slice(o,t.length),t.slice(1,o+1))),r}comparePath(t,e){return t.every((t,r)=>this.compareCoord(t,e[r]))}comparePolygon(t,e){if(this.compareLine(t.coordinates[0],e.coordinates[0],1,!0)){const r=t.coordinates.slice(1,t.coordinates.length),o=e.coordinates.slice(1,e.coordinates.length);return r.every(t=>o.some(e=>this.compareLine(t,e,1,!0)))}return!1}compareGeometryCollection(t,e){return To(t.geometries,e.geometries)&&this.compareBBox(t,e)&&t.geometries.every((t,r)=>this.compare(t,e.geometries[r]))}compareFeature(t,e){return t.id===e.id&&(!this.compareProperties||Go(t.properties,e.properties))&&this.compareBBox(t,e)&&this.compare(t.geometry,e.geometry)}compareFeatureCollection(t,e){return To(t.features,e.features)&&this.compareBBox(t,e)&&t.features.every((t,r)=>this.compare(t,e.features[r]))}compareBBox(t,e){return Boolean(!t.bbox&&!e.bbox)||!(!t.bbox||!e.bbox)&&this.compareCoord(t.bbox,e.bbox)}};Ao(Oo,"GeojsonEquality");var Fo=Oo;function To(t,e){return t.coordinates?t.coordinates.length===e.coordinates.length:t.length===e.length}function _o(t){return t.coordinates.map(e=>({type:t.type.replace("Multi",""),coordinates:e}))}function Ho(t,e,r){return new Fo(r).compare(t,e)}function Go(t,e){if(null===t&&null===e)return!0;if(null===t||null===e)return!1;const r=Object.keys(t),o=Object.keys(e);if(r.length!==o.length)return!1;for(var n of r){const r=t[n],o=e[n],i=Bo(r)&&Bo(o);if(i&&!Go(r,o)||!i&&r!==o)return!1}return!0}Ao(To,"sameLength"),Ao(_o,"explode"),Ao(Ho,"geojsonEquality"),Ao(Go,"equal");var Bo=Ao(t=>null!=t&&"object"==typeof t,"isObject");var zo=function(t,e,r={}){let o=r.precision;if(o=null==o||isNaN(o)?6:o,"number"!=typeof o||!(o>=0))throw new Error("precision must be a positive number");return Pt(t).type===Pt(e).type&&Ho(Ve(t),Ve(e),{precision:o})},No=Object.defineProperty,Uo=Object.defineProperties,Ro=Object.getOwnPropertyDescriptors,Xo=Object.getOwnPropertySymbols,Yo=Object.prototype.hasOwnProperty,Vo=Object.prototype.propertyIsEnumerable,qo=(t,e,r)=>e in t?No(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jo=(t,e)=>{for(var r in e||(e={}))Yo.call(e,r)&&qo(t,r,e[r]);if(Xo)for(var r of Xo(e))Vo.call(e,r)&&qo(t,r,e[r]);return t},Ko=(t,e)=>Uo(t,Ro(e));var $o=function(t,e,r={}){if(!t)throw new Error("targetPoint is required");if(!e)throw new Error("points is required");let o=1/0,n=0;U(e,(e,i)=>{const a=no(t,e,r);a<o&&(n=i,o=a)});const i=Ke(e.features[n]);return Ko(jo({},i),{properties:Ko(jo({},i.properties),{featureIndex:n,distanceToPoint:o})})},Wo=class{constructor(t){this.points=t.points||[],this.duration=t.duration||1e4,this.sharpness=t.sharpness||.85,this.centers=[],this.controls=[],this.stepLength=t.stepLength||60,this.length=this.points.length,this.delay=0;for(let e=0;e<this.length;e++)this.points[e].z=this.points[e].z||0;for(let e=0;e<this.length-1;e++){const t=this.points[e],r=this.points[e+1];this.centers.push({x:(t.x+r.x)/2,y:(t.y+r.y)/2,z:(t.z+r.z)/2})}this.controls.push([this.points[0],this.points[0]]);for(let e=0;e<this.centers.length-1;e++){const t=this.points[e+1].x-(this.centers[e].x+this.centers[e+1].x)/2,r=this.points[e+1].y-(this.centers[e].y+this.centers[e+1].y)/2,o=this.points[e+1].z-(this.centers[e].y+this.centers[e+1].z)/2;this.controls.push([{x:(1-this.sharpness)*this.points[e+1].x+this.sharpness*(this.centers[e].x+t),y:(1-this.sharpness)*this.points[e+1].y+this.sharpness*(this.centers[e].y+r),z:(1-this.sharpness)*this.points[e+1].z+this.sharpness*(this.centers[e].z+o)},{x:(1-this.sharpness)*this.points[e+1].x+this.sharpness*(this.centers[e+1].x+t),y:(1-this.sharpness)*this.points[e+1].y+this.sharpness*(this.centers[e+1].y+r),z:(1-this.sharpness)*this.points[e+1].z+this.sharpness*(this.centers[e+1].z+o)}])}return this.controls.push([this.points[this.length-1],this.points[this.length-1]]),this.steps=this.cacheSteps(this.stepLength),this}cacheSteps(t){const e=[];let r=this.pos(0);e.push(0);for(let o=0;o<this.duration;o+=10){const n=this.pos(o);Math.sqrt((n.x-r.x)*(n.x-r.x)+(n.y-r.y)*(n.y-r.y)+(n.z-r.z)*(n.z-r.z))>t&&(e.push(o),r=n)}return e}vector(t){const e=this.pos(t+10),r=this.pos(t-10);return{angle:180*Math.atan2(e.y-r.y,e.x-r.x)/3.14,speed:Math.sqrt((r.x-e.x)*(r.x-e.x)+(r.y-e.y)*(r.y-e.y)+(r.z-e.z)*(r.z-e.z))}}pos(t){let e=t-this.delay;e<0&&(e=0),e>this.duration&&(e=this.duration-1);const r=e/this.duration;if(r>=1)return this.points[this.length-1];const o=Math.floor((this.points.length-1)*r);return function(t,e,r,o,n){const i=function(t){const e=t*t,r=e*t;return[r,3*e*(1-t),3*t*(1-t)*(1-t),(1-t)*(1-t)*(1-t)]}(t);return{x:n.x*i[0]+o.x*i[1]+r.x*i[2]+e.x*i[3],y:n.y*i[0]+o.y*i[1]+r.y*i[2]+e.y*i[3],z:n.z*i[0]+o.z*i[1]+r.z*i[2]+e.z*i[3]}}((this.length-1)*r-o,this.points[o],this.controls[o][1],this.controls[o+1][0],this.points[o+1])}};var Jo=function(t,e={}){const r=e.resolution||1e4,o=e.sharpness||.85,n=[],i=Pt(t).coordinates.map(t=>({x:t[0],y:t[1]})),a=new Wo({duration:r,points:i,sharpness:o}),s=t=>{var e=a.pos(t);Math.floor(t/100)%2==0&&n.push([e.x,e.y])};for(var l=0;l<a.duration;l+=10)s(l);return s(a.duration),F(n,e.properties)};var Zo=function(t,e={}){return Y(t,(t,r)=>{const o=r.geometry.coordinates;return t+no(o[0],o[1],e)},0)};function Qo(t,e,r=0,o=t.length-1,n=en){for(;o>r;){if(o-r>600){const i=o-r+1,a=e-r+1,s=Math.log(i),l=.5*Math.exp(2*s/3),c=.5*Math.sqrt(s*l*(i-l)/i)*(a-i/2<0?-1:1);Qo(t,e,Math.max(r,Math.floor(e-a*l/i+c)),Math.min(o,Math.floor(e+(i-a)*l/i+c)),n)}const i=t[e];let a=r,s=o;for(tn(t,r,e),n(t[o],i)>0&&tn(t,r,o);a<s;){for(tn(t,a,s),a++,s--;n(t[a],i)<0;)a++;for(;n(t[s],i)>0;)s--}0===n(t[r],i)?tn(t,r,s):(s++,tn(t,s,o)),s<=e&&(r=s+1),e<=s&&(o=s-1)}}function tn(t,e,r){const o=t[e];t[e]=t[r],t[r]=o}function en(t,e){return t<e?-1:t>e?1:0}class rn{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(){return this._all(this.data,[])}search(t){let e=this.data;const r=[];if(!fn(t,e))return r;const o=this.toBBox,n=[];for(;e;){for(let i=0;i<e.children.length;i++){const a=e.children[i],s=e.leaf?o(a):a;fn(t,s)&&(e.leaf?r.push(a):pn(t,s)?this._all(a,r):n.push(a))}e=n.pop()}return r}collides(t){let e=this.data;if(!fn(t,e))return!1;const r=[];for(;e;){for(let o=0;o<e.children.length;o++){const n=e.children[o],i=e.leaf?this.toBBox(n):n;if(fn(t,i)){if(e.leaf||pn(t,i))return!0;r.push(n)}}e=r.pop()}return!1}load(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let e=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this._insert(e,this.data.height-e.height-1,!0)}else this.data=e;return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=yn([]),this}remove(t,e){if(!t)return this;let r=this.data;const o=this.toBBox(t),n=[],i=[];let a,s,l;for(;r||n.length;){if(r||(r=n.pop(),s=n[n.length-1],a=i.pop(),l=!0),r.leaf){const o=on(t,r.children,e);if(-1!==o)return r.children.splice(o,1),n.push(r),this._condense(n),this}l||r.leaf||!pn(r,o)?s?(a++,r=s.children[a],l=!1):r=null:(n.push(r),i.push(a),a=0,s=r,r=r.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const r=[];for(;t;)t.leaf?e.push(...t.children):r.push(...t.children),t=r.pop();return e}_build(t,e,r,o){const n=r-e+1;let i,a=this._maxEntries;if(n<=a)return i=yn(t.slice(e,r+1)),nn(i,this.toBBox),i;o||(o=Math.ceil(Math.log(n)/Math.log(a)),a=Math.ceil(n/Math.pow(a,o-1))),i=yn([]),i.leaf=!1,i.height=o;const s=Math.ceil(n/a),l=s*Math.ceil(Math.sqrt(a));mn(t,e,r,l,this.compareMinX);for(let c=e;c<=r;c+=l){const e=Math.min(c+l-1,r);mn(t,c,e,s,this.compareMinY);for(let r=c;r<=e;r+=s){const n=Math.min(r+s-1,e);i.children.push(this._build(t,r,n,o-1))}}return nn(i,this.toBBox),i}_chooseSubtree(t,e,r,o){for(;o.push(e),!e.leaf&&o.length-1!==r;){let r,o=1/0,n=1/0;for(let i=0;i<e.children.length;i++){const a=e.children[i],s=hn(a),l=gn(t,a)-s;l<n?(n=l,o=s<o?s:o,r=a):l===n&&s<o&&(o=s,r=a)}e=r||e.children[0]}return e}_insert(t,e,r){const o=r?t:this.toBBox(t),n=[],i=this._chooseSubtree(o,this.data,e,n);for(i.children.push(t),sn(i,o);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(o,n,e)}_split(t,e){const r=t[e],o=r.children.length,n=this._minEntries;this._chooseSplitAxis(r,n,o);const i=this._chooseSplitIndex(r,n,o),a=yn(r.children.splice(i,r.children.length-i));a.height=r.height,a.leaf=r.leaf,nn(r,this.toBBox),nn(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(r,a)}_splitRoot(t,e){this.data=yn([t,e]),this.data.height=t.height+1,this.data.leaf=!1,nn(this.data,this.toBBox)}_chooseSplitIndex(t,e,r){let o,n=1/0,i=1/0;for(let a=e;a<=r-e;a++){const e=an(t,0,a,this.toBBox),s=an(t,a,r,this.toBBox),l=dn(e,s),c=hn(e)+hn(s);l<n?(n=l,o=a,i=c<i?c:i):l===n&&c<i&&(i=c,o=a)}return o||r-e}_chooseSplitAxis(t,e,r){const o=t.leaf?this.compareMinX:ln,n=t.leaf?this.compareMinY:cn;this._allDistMargin(t,e,r,o)<this._allDistMargin(t,e,r,n)&&t.children.sort(o)}_allDistMargin(t,e,r,o){t.children.sort(o);const n=this.toBBox,i=an(t,0,e,n),a=an(t,r-e,r,n);let s=un(i)+un(a);for(let l=e;l<r-e;l++){const e=t.children[l];sn(i,t.leaf?n(e):e),s+=un(i)}for(let l=r-e-1;l>=e;l--){const e=t.children[l];sn(a,t.leaf?n(e):e),s+=un(a)}return s}_adjustParentBBoxes(t,e,r){for(let o=r;o>=0;o--)sn(e[o],t)}_condense(t){for(let e,r=t.length-1;r>=0;r--)0===t[r].children.length?r>0?(e=t[r-1].children,e.splice(e.indexOf(t[r]),1)):this.clear():nn(t[r],this.toBBox)}}function on(t,e,r){if(!r)return e.indexOf(t);for(let o=0;o<e.length;o++)if(r(t,e[o]))return o;return-1}function nn(t,e){an(t,0,t.children.length,e,t)}function an(t,e,r,o,n){n||(n=yn(null)),n.minX=1/0,n.minY=1/0,n.maxX=-1/0,n.maxY=-1/0;for(let i=e;i<r;i++){const e=t.children[i];sn(n,t.leaf?o(e):e)}return n}function sn(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function ln(t,e){return t.minX-e.minX}function cn(t,e){return t.minY-e.minY}function hn(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function un(t){return t.maxX-t.minX+(t.maxY-t.minY)}function gn(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function dn(t,e){const r=Math.max(t.minX,e.minX),o=Math.max(t.minY,e.minY),n=Math.min(t.maxX,e.maxX),i=Math.min(t.maxY,e.maxY);return Math.max(0,n-r)*Math.max(0,i-o)}function pn(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function fn(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function yn(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function mn(t,e,r,o,n){const i=[e,r];for(;i.length;){if((r=i.pop())-(e=i.pop())<=o)continue;const a=e+Math.ceil((r-e)/o/2)*o;Qo(t,a,e,r,n),i.push(e,a,a,r)}}class vn{constructor(t=[],e=(t,e)=>t<e?-1:t>e?1:0){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let r=(this.length>>1)-1;r>=0;r--)this._down(r)}push(t){this.data.push(t),this._up(this.length++)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return--this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:r}=this,o=e[t];for(;t>0;){const n=t-1>>1,i=e[n];if(r(o,i)>=0)break;e[t]=i,t=n}e[t]=o}_down(t){const{data:e,compare:r}=this,o=this.length>>1,n=e[t];for(;t<o;){let o=1+(t<<1);const i=o+1;if(i<this.length&&r(e[i],e[o])<0&&(o=i),r(e[o],n)>=0)break;e[t]=e[o],t=o}e[t]=n}}const Mn=J(ut());function wn(t,e,r){e=Math.max(0,void 0===e?2:e),r=r||0;const o=function(t){let e=t[0],r=t[0],o=t[0],n=t[0];for(let s=0;s<t.length;s++){const i=t[s];i[0]<e[0]&&(e=i),i[0]>o[0]&&(o=i),i[1]<r[1]&&(r=i),i[1]>n[1]&&(n=i)}const i=[e,r,o,n],a=i.slice();for(let s=0;s<t.length;s++)Mn(t[s],i)||a.push(t[s]);return function(t){t.sort(Fn);const e=[];for(let o=0;o<t.length;o++){for(;e.length>=2&&En(e[e.length-2],e[e.length-1],t[o])<=0;)e.pop();e.push(t[o])}const r=[];for(let o=t.length-1;o>=0;o--){for(;r.length>=2&&En(r[r.length-2],r[r.length-1],t[o])<=0;)r.pop();r.push(t[o])}return r.pop(),e.pop(),e.concat(r)}(a)}(t),n=new rn(16);n.toBBox=function(t){return{minX:t[0],minY:t[1],maxX:t[0],maxY:t[1]}},n.compareMinX=function(t,e){return t[0]-e[0]},n.compareMinY=function(t,e){return t[1]-e[1]},n.load(t);const i=[];let a;for(let g=0;g<o.length;g++){const t=o[g];n.remove(t),a=Cn(t,a),i.push(a)}const s=new rn(16);for(let g=0;g<i.length;g++)s.insert(Dn(i[g]));const l=e*e,c=r*r;for(;i.length;){const t=i.shift(),e=t.p,r=t.next.p,o=In(e,r);if(o<c)continue;const a=o/l,h=bn(n,t.prev.p,e,r,t.next.next.p,a,s);h&&Math.min(In(h,e),In(h,r))<=a&&(i.push(t),i.push(Cn(h,t)),n.remove(h),s.remove(t),s.insert(Dn(t)),s.insert(Dn(t.next)))}let h=a;const u=[];do{u.push(h.p),h=h.next}while(h!==a);return u.push(h.p),u}function bn(t,e,r,o,n,i,a){const s=new vn([],Pn);let l=t.data;for(;l;){for(let t=0;t<l.children.length;t++){const e=l.children[t],n=l.leaf?An(e,r,o):Ln(r,o,e);n>i||s.push({node:e,dist:n})}for(;s.length&&!s.peek().node.children;){const t=s.pop(),i=t.node,l=An(i,e,r),c=An(i,o,n);if(t.dist<l&&t.dist<c&&xn(r,i,a)&&xn(o,i,a))return i}l=s.pop(),l&&(l=l.node)}return null}function Pn(t,e){return t.dist-e.dist}function Ln(t,e,r){if(kn(t,r)||kn(e,r))return 0;const o=On(t[0],t[1],e[0],e[1],r.minX,r.minY,r.maxX,r.minY);if(0===o)return 0;const n=On(t[0],t[1],e[0],e[1],r.minX,r.minY,r.minX,r.maxY);if(0===n)return 0;const i=On(t[0],t[1],e[0],e[1],r.maxX,r.minY,r.maxX,r.maxY);if(0===i)return 0;const a=On(t[0],t[1],e[0],e[1],r.minX,r.maxY,r.maxX,r.maxY);return 0===a?0:Math.min(o,n,i,a)}function kn(t,e){return t[0]>=e.minX&&t[0]<=e.maxX&&t[1]>=e.minY&&t[1]<=e.maxY}function xn(t,e,r){const o=Math.min(t[0],e[0]),n=Math.min(t[1],e[1]),i=Math.max(t[0],e[0]),a=Math.max(t[1],e[1]),s=r.search({minX:o,minY:n,maxX:i,maxY:a});for(let l=0;l<s.length;l++)if(Sn(s[l].p,s[l].next.p,t,e))return!1;return!0}function En(t,e,r){return Br(t[0],t[1],e[0],e[1],r[0],r[1])}function Sn(t,e,r,o){return t!==o&&e!==r&&En(t,e,r)>0!=En(t,e,o)>0&&En(r,o,t)>0!=En(r,o,e)>0}function Dn(t){const e=t.p,r=t.next.p;return t.minX=Math.min(e[0],r[0]),t.minY=Math.min(e[1],r[1]),t.maxX=Math.max(e[0],r[0]),t.maxY=Math.max(e[1],r[1]),t}function Cn(t,e){const r={p:t,prev:null,next:null,minX:0,minY:0,maxX:0,maxY:0};return e?(r.next=e.next,r.prev=e,e.next.prev=r,e.next=r):(r.prev=r,r.next=r),r}function In(t,e){const r=t[0]-e[0],o=t[1]-e[1];return r*r+o*o}function An(t,e,r){let o=e[0],n=e[1],i=r[0]-o,a=r[1]-n;if(0!==i||0!==a){const e=((t[0]-o)*i+(t[1]-n)*a)/(i*i+a*a);e>1?(o=r[0],n=r[1]):e>0&&(o+=i*e,n+=a*e)}return i=t[0]-o,a=t[1]-n,i*i+a*a}function On(t,e,r,o,n,i,a,s){const l=r-t,c=o-e,h=a-n,u=s-i,g=t-n,d=e-i,p=l*l+c*c,f=l*h+c*u,y=h*h+u*u,m=l*g+c*d,v=h*g+u*d,M=p*y-f*f;let w,b,P=M,L=M;0===M?(w=0,P=1,b=v,L=y):(w=f*v-y*m,b=p*v-f*m,w<0?(w=0,b=v,L=y):w>P&&(w=P,b=v+f,L=y)),b<0?(b=0,-m<0?w=0:-m>p?w=P:(w=-m,P=p)):b>L&&(b=L,-m+f<0?w=0:-m+f>p?w=P:(w=-m+f,P=p));const k=0===w?0:w/P,x=0===b?0:b/L,E=(1-x)*n+x*a-((1-k)*t+k*r),S=(1-x)*i+x*s-((1-k)*e+k*o);return E*E+S*S}function Fn(t,e){return t[0]===e[0]?t[1]-e[1]:t[0]-e[0]}const Tn=()=>"ontouchstart"in window||navigator.maxTouchPoints>0;function _n(){return"undefined"!=typeof vitest}class Hn{static getBounds(t,e=0){const r=[];t.forEach(t=>{isNaN(t.lat)||isNaN(t.lng),r.push(t)});const o=new s.Polyline(r).getBounds();return 0!==e?o.pad(e):o}}class Gn{constructor(t=0,e=0,r=0,o=0){i(this,"direction",{East:new s.LatLng(0,0),North:new s.LatLng(0,0),NorthEast:new s.LatLng(0,0),NorthWest:new s.LatLng(0,0),South:new s.LatLng(0,0),SouthEast:new s.LatLng(0,0),SouthWest:new s.LatLng(0,0),West:new s.LatLng(0,0)}),this.direction.North=new s.LatLng(r,(e+o)/2),this.direction.NorthEast=new s.LatLng(r,o),this.direction.East=new s.LatLng((t+r)/2,o),this.direction.SouthEast=new s.LatLng(t,o),this.direction.South=new s.LatLng(t,(e+o)/2),this.direction.SouthWest=new s.LatLng(t,e),this.direction.West=new s.LatLng((t+r)/2,e),this.direction.NorthWest=new s.LatLng(r,e)}getDirection(t){switch(t){case h.SouthWest:return this.direction.SouthWest;case h.West:return this.direction.West;case h.NorthWest:return this.direction.NorthWest;case h.North:return this.direction.North;case h.NorthEast:return this.direction.NorthEast;case h.East:return this.direction.East;case h.SouthEast:return this.direction.SouthEast;case h.South:return this.direction.South;default:throw new Error}}getPositions(t=h.SouthWest,e=!1,r=!0){const o=[],n=this.getPositionAsArray(t,e);return n.forEach(t=>{o.push([t.lng,t.lat])}),r&&o.push([n[0].lng,n[0].lat]),o}getPositionAsArray(t=h.NorthEast,e=!1){const r=[];if(e?(r.push(this.direction.SouthWest),r.push(this.direction.West),r.push(this.direction.NorthWest),r.push(this.direction.North),r.push(this.direction.NorthEast),r.push(this.direction.East),r.push(this.direction.SouthEast),r.push(this.direction.South)):(r.push(this.direction.SouthWest),r.push(this.direction.South),r.push(this.direction.SouthEast),r.push(this.direction.East),r.push(this.direction.NorthEast),r.push(this.direction.North),r.push(this.direction.NorthWest),r.push(this.direction.West)),t!==h.SouthWest){r.splice(0,t).forEach((e,o)=>{r.splice(t+o,0,e)})}return r}}class Bn{constructor(t,e){if(i(this,"metricLength",""),i(this,"metricUnit",""),i(this,"imperialLength",""),i(this,"imperialUnit",""),null!==t||void 0!==t){0===t?e.markers.markerInfoIcon.usePerimeterMinValue?(this.metricLength=e.markers.markerInfoIcon.values.min.metric,this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.m,this.imperialLength=e.markers.markerInfoIcon.values.min.imperial,this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.feet):(this.metricLength=e.markers.markerInfoIcon.values.unknown.metric,this.metricUnit=e.markers.markerInfoIcon.units.unknownUnit,this.imperialLength=e.markers.markerInfoIcon.values.unknown.imperial,this.imperialUnit=e.markers.markerInfoIcon.units.unknownUnit):t<100?(this.metricLength=(10*Math.ceil(t/10)).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.m):t<500?(this.metricLength=(50*Math.ceil(t/50)).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.m):t<1e3?(this.metricLength=(100*Math.ceil(t/100)).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.m):t<1e4?(this.metricLength=(100*Math.ceil(t/100)/1e3).toFixed(1),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.km):(this.metricLength=(1e3*Math.ceil(t/1e3)/1e3).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.perimeter.km);const r=t/.0254/12,o=r/3,n=o/1760;t<1e3/2.54?(this.imperialLength=(10*Math.ceil(r/10)).toString(),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.feet):t<1e3/2.54*3?(this.imperialLength=(10*Math.ceil(o/10)).toString(),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.yards):t<1609?(this.imperialLength=n.toFixed(2),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.miles):t<16093?(this.imperialLength=n.toFixed(1),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.miles):(this.imperialLength=n.toFixed(0),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.perimeter.miles)}}}class zn{constructor(t,e){i(this,"metricArea",""),i(this,"metricUnit",""),i(this,"imperialArea",""),i(this,"imperialUnit","");const r=t,o=e.markers.markerInfoIcon.units.metric.onlyMetrics;if(null!==r||void 0!==r){0===r?(this.metricArea="-",this.metricUnit=e.markers.markerInfoIcon.units.unknownUnit,this.imperialArea="-",this.imperialUnit=e.markers.markerInfoIcon.units.unknownUnit):r<1e4?(this.metricArea=Math.round(r).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.m2):r<1e5?o?(this.metricArea=(r/1e6).toFixed(2),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.km2):(this.metricArea=(r/1e3).toFixed(1),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.daa):r<1e7?o?(this.metricArea=(r/1e6).toFixed(2),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.km2):(this.metricArea=Math.round(r/1e3).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.daa):r<1e8?o?(this.metricArea=(r/1e6).toFixed(1),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.km2):(this.metricArea=Math.round(r/1e4).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.ha):(this.metricArea=Math.round(r/1e6).toString(),this.metricUnit=e.markers.markerInfoIcon.units.metric.area.km2);const t=.0069444*(1550*r),n=.11111*t,i=20661e-8*n,a=3.2283e-7*n;r<92.9?(this.imperialArea=Math.round(t).toString(),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.feet2):r<836.14?(this.imperialArea=n.toFixed(0),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.yards2):r<40469.6?(this.imperialArea=i.toFixed(2),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.acres):r<404696?(this.imperialArea=i.toFixed(1),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.acres):r<4046960?(this.imperialArea=i.toFixed(0),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.acres):r<25900404?(this.imperialArea=a.toFixed(2),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.miles2):r<259004040?(this.imperialArea=a.toFixed(1),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.miles2):(this.imperialArea=a.toFixed(0),this.imperialUnit=e.markers.markerInfoIcon.units.imperial.area.miles2)}}}function Nn(t,...e){if(!e.length)return t;for(const r of e)if(r)for(const e in r){const o=r[e],n=t[e];if(o&&"object"==typeof o&&!Array.isArray(o)){const r=n&&"object"==typeof n&&!Array.isArray(n)?n:{};t[e]=Nn(r,o)}else void 0!==o&&(t[e]=o)}return t}class Un{constructor(t){i(this,"config",u),i(this,"fallbackWarnings",new Set),this.config=Nn(structuredClone(u),t)}warnFallbackOnce(t,e){_n()||this.fallbackWarnings.has(t)||(this.fallbackWarnings.add(t),console.warn(e))}toProjectedTolerance(t,e){if(t<=0)return 0;try{const r=g*f,o=t*r,n=Math.cos(e.lat*f);return 0===n?t:o/(r*n)}catch{return t}}getFeatureDiagonal(t){try{const[e,r,o,n]=L(t);return Math.hypot(o-e,n-r)}catch{return 0}}getRingDiagonal(t){if(!t||0===t.length)return 0;let e=t[0].lat,r=t[0].lat,o=t[0].lng,n=t[0].lng;for(const i of t)e=Math.min(e,i.lat),r=Math.max(r,i.lat),o=Math.min(o,i.lng),n=Math.max(n,i.lng);return Math.hypot(n-o,r-e)}getAdaptiveTolerance(t,e){if(t<=0)return 0;if(e<=0)return t;const r=.02*e;return Math.min(t,r)}union(t,e){try{const r=b([t,e]),o=ze(r);return o?this.getTurfPolygon(o):null}catch(r){return _n()||console.warn("Error in union:",r instanceof Error?r.message:String(r)),null}}createPolygonFromTrace(t){var e;const r=null==(e=this.config.polygonCreation)?void 0:e.algorithm;void 0!==r&&"string"!=typeof r&&this.warnFallbackOnce("polygonCreation.algorithm.type",'[Leaflet.Polydraw] Invalid `polygonCreation.algorithm` type. Using "concaveman" as fallback.');const o="string"==typeof r?r:"concaveman";switch(o){case"concaveman":return this.turfConcaveman(t);case"convex":return this.createConvexPolygon(t);case"direct":return this.createDirectPolygon(t);case"buffer":return this.warnFallbackOnce("polygonCreation.algorithm.buffer",'[Leaflet.Polydraw] `polygonCreation.algorithm: "buffer"` is deprecated. Using "concaveman" as fallback.'),this.turfConcaveman(t);default:return this.warnFallbackOnce(`polygonCreation.algorithm.unknown:${o}`,`[Leaflet.Polydraw] Unknown polygon creation algorithm "${o}". Using "concaveman" as fallback.`),this.turfConcaveman(t)}}turfConcaveman(t){return w([[wn(Re(t).features.map(t=>t.geometry.coordinates))]])}createConvexPolygon(t){const e=Re(t),r=vt(e);return r?this.getTurfPolygon(r):(this.warnFallbackOnce("polygonCreation.algorithm.convex.noHull",'[Leaflet.Polydraw] Convex hull generation failed. Using "direct" polygon creation as fallback.'),this.createDirectPolygon(t))}createDirectPolygon(t){let e;if("LineString"===t.geometry.type)e=t.geometry.coordinates;else if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else{e=Re(t).features.map(t=>t.geometry.coordinates)}if(e.length>0){const t=e[0],r=e[e.length-1];t[0]===r[0]&&t[1]===r[1]||e.push([t[0],t[1]])}return e.length<4?(_n()||console.warn("Not enough points for direct polygon, falling back to concaveman"),this.turfConcaveman(t)):w([[e]])}getSimplified(t,e=!1){const r=this.resolveSimplificationConfig();if("none"===r.strategy)return t;if("simple"===r.strategy){const e=this.getAdaptiveTolerance(r.simple.tolerance,this.getFeatureDiagonal(t));return ar(t,{tolerance:this.toProjectedTolerance(e,this.getReferenceLatLng(t)),highQuality:r.simple.highQuality,mutate:!1})}const o=t.geometry.coordinates[0][0].length,n=r.dynamic.fractionGuard,i=r.dynamic.multiplier,a=this.getAdaptiveTolerance(r.dynamic.baseTolerance,this.getFeatureDiagonal(t)),s={highQuality:r.dynamic.highQuality,mutate:!1},l=e=>ar(t,{...s,tolerance:this.toProjectedTolerance(e,this.getReferenceLatLng(t))});if(!e)return l(a);let c=a,h=l(c);for(;h.geometry.coordinates[0][0].length>4&&h.geometry.coordinates[0][0].length/(o+2)>n;)c*=i,h=l(c);return h}simplifyLatLngRing(t,e,r=!0){var o,n;if(!t||0===t.length||e<=0)return t?[...t]:[];const i=[...t],a=i[0],s=i[i.length-1];s&&a&&s.lat===a.lat&&s.lng===a.lng||i.push({lat:a.lat,lng:a.lng});const l=i.map(t=>[t.lng,t.lat]),c=this.getAdaptiveTolerance(e,this.getRingDiagonal(i));try{const e=M([l]),i=ar(e,{tolerance:this.toProjectedTolerance(c,t[0]),highQuality:r,mutate:!1}),a=null==(n=null==(o=null==i?void 0:i.geometry)?void 0:o.coordinates)?void 0:n[0];return a&&0!==a.length?a.map(t=>({lat:t[1],lng:t[0]})):[...t]}catch(h){return _n()||console.warn("Error simplifying ring:",h instanceof Error?h.message:String(h)),[...t]}}resolveSimplificationConfig(){const t=this.config.simplification,e=null==t?void 0:t.simple,r=null==t?void 0:t.dynamic,o=null==t?void 0:t.strategy,n=(t,e)=>"number"!=typeof t||!Number.isFinite(t)||t<0?(void 0!==t&&this.warnFallbackOnce(`simplification.invalidNumber:${String(t)}`,"[Leaflet.Polydraw] Invalid simplification numeric value. Using fallback default."),e):t,i=(t,e)=>"boolean"!=typeof t?(void 0!==t&&this.warnFallbackOnce(`simplification.invalidBoolean:${String(t)}`,"[Leaflet.Polydraw] Invalid simplification boolean value. Using fallback default."),e):t;let a="simple";"simple"===o||"dynamic"===o||"none"===o?a=o:void 0!==o&&this.warnFallbackOnce(`simplification.invalidStrategy:${String(o)}`,'[Leaflet.Polydraw] Invalid `simplification.strategy`. Using "simple" as fallback.');return{strategy:a,simple:{tolerance:n(null==e?void 0:e.tolerance,1e-4),highQuality:i(null==e?void 0:e.highQuality,!1)},dynamic:{baseTolerance:n(null==r?void 0:r.baseTolerance,1e-4),highQuality:i(null==r?void 0:r.highQuality,!1),fractionGuard:((t,e)=>"number"==typeof t&&Number.isFinite(t)?((t<0||t>1)&&this.warnFallbackOnce(`simplification.outOfRangeFraction:${t}`,"[Leaflet.Polydraw] `simplification.dynamic.fractionGuard` is out of range [0, 1]. Clamping to nearest valid value."),Math.max(0,Math.min(1,t))):(void 0!==t&&this.warnFallbackOnce(`simplification.invalidFraction:${String(t)}`,"[Leaflet.Polydraw] Invalid `simplification.dynamic.fractionGuard`. Using fallback default."),e))(null==r?void 0:r.fractionGuard,.9),multiplier:((t,e)=>"number"!=typeof t||!Number.isFinite(t)||t<=1?(void 0!==t&&this.warnFallbackOnce(`simplification.invalidMultiplier:${String(t)}`,"[Leaflet.Polydraw] Invalid `simplification.dynamic.multiplier` (must be > 1). Using fallback default."),e):t)(null==r?void 0:r.multiplier,2)}}}getTurfPolygon(t){let e;return e="Polygon"===t.geometry.type?w([t.geometry.coordinates]):w(t.geometry.coordinates),e}getMultiPolygon(t){return w(t)}getKinks(t){try{if(!t||!t.geometry||!t.geometry.coordinates)return[t];const e=this.removeDuplicateVertices(t);if(!e||!e.geometry||!e.geometry.coordinates)return _n()||console.warn("Feature became invalid after cleaning in getKinks"),[t];if(this.polygonHasHoles(e))return this.getKinksWithHolePreservation(e);{const t=Jr(e),r=[];return U(t,t=>{r.push(t)}),r}}catch(e){return _n()||console.warn("Error processing kinks:",e instanceof Error?e.message:String(e)),[t]}}getCoords(t){return P(t)}getReferenceLatLng(t){var e,r;try{const o=P(t),n=null==(r=null==(e=null==o?void 0:o[0])?void 0:e[0])?void 0:r[0];if(n&&Array.isArray(n)&&n.length>=2)return{lat:n[1],lng:n[0]}}catch{}return{lat:0,lng:0}}hasKinks(t){return lr(t).features.length>0}getConvexHull(t){try{const e=b([t]);return vt(e)}catch(e){return _n()||console.warn("Error in getConvexHull:",e instanceof Error?e.message:String(e)),null}}getMidpoint(t,e){const r=x(m([t.lng,t.lat]),m([e.lng,e.lat]));return{lat:r.geometry.coordinates[1],lng:r.geometry.coordinates[0]}}polygonIntersect(t,e){try{if(!(t&&t.geometry&&t.geometry.coordinates&&e&&e.geometry&&e.geometry.coordinates))return _n()||console.warn("Invalid features passed to polygonIntersect"),!1;const r=t=>{var e,r;return Array.isArray(null==(r=null==(e=t[0])?void 0:e[0])?void 0:r[0])},o=t=>{if(!Array.isArray(t))return!1;const e=r(t)?t.flat():t;for(const r of e){if(!Array.isArray(r))return!1;for(const t of r){if(!Array.isArray(t)||t.length<2)return!1;if(t.some(t=>null==t||!isFinite(t)))return!1}}return!0};if(!o(t.geometry.coordinates)||!o(e.geometry.coordinates))return!1;try{const r=b([t,e]),o=Ne(r);if(o&&o.geometry&&("Polygon"===o.geometry.type||"MultiPolygon"===o.geometry.type)){if(W(o)>1e-6)return!0}}catch{}try{const r=Re(t),o=Re(e);for(const e of o.features)if(Ur(e,t))return!0;for(const t of r.features)if(Ur(t,e))return!0}catch{}try{const r=P(t),o=P(e);for(const t of r){const e=t[0];if(e&&!(e.length<2))for(let t=0;t<e.length-1;t++){const r=e[t],n=e[t+1];if(!r||!n||!Array.isArray(r)||!Array.isArray(n)||r.length<2||n.length<2||r.some(t=>null==t||!isFinite(t))||n.some(t=>null==t||!isFinite(t)))continue;const i=v([r,n]);for(const t of o){const e=t[0];if(e&&!(e.length<2))for(let t=0;t<e.length-1;t++){const r=e[t],o=e[t+1];if(!r||!o||!Array.isArray(r)||!Array.isArray(o)||r.length<2||o.length<2||r.some(t=>null==t||!isFinite(t))||o.some(t=>null==t||!isFinite(t)))continue;const n=v([r,o]);try{const t=Bt(i,n);if(t&&t.features&&t.features.length>0)return!0}catch{}}}}}}catch{}return!1}catch(r){return _n()||console.warn("Error in polygonIntersect:",r instanceof Error?r.message:String(r)),!1}}getIntersection(t,e){try{const r=b([t,e]),o=Ne(r);return o&&o.geometry&&("Polygon"===o.geometry.type||"MultiPolygon"===o.geometry.type)?o:null}catch(r){return _n()||console.warn("Error in getIntersection:",r instanceof Error?r.message:String(r)),null}}getDistance(t,e){return k(t,e)}isWithin(t,e){return Co(M([t]),M([e]))}isPolygonCompletelyWithin(t,e){try{return Co(t,e)}catch{const r=P(t),o=P(e);for(const t of r)for(const e of t)for(const t of e){const e=m(t);let r=!1;for(const t of o){for(const o of t){const t=M([o]);if(Ur(e,t)){r=!0;break}}if(r)break}if(!r)return!1}return!0}}toPointFeature(t){if((t=>{var e;if(!t||"object"!=typeof t)return!1;const r=t;return"Feature"===r.type&&"Point"===(null==(e=r.geometry)?void 0:e.type)})(t))return t;if(Array.isArray(t)&&t.length>=2&&"number"==typeof t[0]&&"number"==typeof t[1])return m(t);if((e=t)&&"object"==typeof e&&"number"==typeof e.lat&&"number"==typeof e.lng){const e=t;return m([e.lng,e.lat])}var e;if((t=>{if(!t||"object"!=typeof t)return!1;const e=t.geometry;return!!e&&Array.isArray(e.coordinates)})(t))return m(t.geometry.coordinates);throw new Error("Unsupported point format provided to toPointFeature")}isPointInsidePolygon(t,e){try{const r=this.toPointFeature(t);return Ur(r,e)}catch{return!1}}equalPolygons(t,e){return zo(t,e)}convertToBoundingBoxPolygon(t){const e=function(t){const[e,r,o,n]=t;return M([[[e,r],[o,r],[o,n],[e,n],[e,r]]])}(L(t));return e}polygonToMultiPolygon(t){return w([t.geometry.coordinates])}injectPointToPolygon(t,e,r){const o=JSON.parse(JSON.stringify(t));let n;if("MultiPolygon"===o.geometry.type)n=o.geometry.coordinates[0][r];else{if("Polygon"!==o.geometry.type)return o;n=o.geometry.coordinates[r]}if(!n)return o;let i=1/0,a=0;for(let s=0;s<n.length-1;s++){const t=n[s],r=n[s+1],o=this.distanceToLineSegment(e,t,r);o<i&&(i=o,a=s+1)}return n.splice(a,0,e),o}distanceToLineSegment(t,e,r){const o=t[0]-e[0],n=t[1]-e[1],i=r[0]-e[0],a=r[1]-e[1],s=o*i+n*a,l=i*i+a*a;if(0===l)return Math.sqrt(o*o+n*n);const c=s/l;let h,u;c<0?(h=e[0],u=e[1]):c>1?(h=r[0],u=r[1]):(h=e[0]+c*i,u=e[1]+c*a);const g=t[0]-h,d=t[1]-u;return Math.sqrt(g*g+d*d)}polygonDifference(t,e){try{const r=b([t,e]),o=Ue(r);return o?this.getTurfPolygon(o):null}catch(r){return _n()||console.warn("Error in polygonDifference:",r instanceof Error?r.message:String(r)),null}}getBoundingBoxCompassPosition(t,e,r,o){return null}getNearestPointIndex(t,e){return $o(t,e).properties.featureIndex??0}getCoord(t){return[t.lng,t.lat]}createPolygon(t){return M(t)}getFeaturePointCollection(t){const e=[];t.forEach(t=>{const r=m([t.lng,t.lat],{});e.push(r)});return b(e)}getPolygonArea(t){return W(t)}getPolygonPerimeter(t){return Zo(t,{units:"kilometers"})}getCenterOfMass(t){return kt(t)}getDoubleElbowLatLngs(t){const e=[],r=t.length,o=t[0].lat===t[r-1].lat&&t[0].lng===t[r-1].lng?r-1:r;for(let n=0;n<o;n++){const r=t[n],i=t[(n+1)%o];e.push(new s.LatLng(r.lat,r.lng));const a=x(m([r.lng,r.lat]),m([i.lng,i.lat]));e.push(new s.LatLng(a.geometry.coordinates[1],a.geometry.coordinates[0]))}return e}getBezierMultiPolygon(t){const e=t=>{if(!t||0===t.length)return t;const e=t[0],r=t[t.length-1];return e[0]===r[0]&&e[1]===r[1]?t:[...t,[e[0],e[1]]]},r=t.map(t=>t.map(t=>{const r=e(t);try{const t=v(r),o=Jo(t,{resolution:this.config.polygonTools.bezier.resolution,sharpness:this.config.polygonTools.bezier.sharpness}).geometry.coordinates??r,n=Math.max(2,r.length-1),i=Math.max(1,this.config.polygonTools.bezier.resampleMultiplier??10),a=Math.max(4,this.config.polygonTools.bezier.maxNodes??o.length),s=((t,r)=>{const o=e(t);if(!o||o.length<2)return o;const n=(t,e)=>{const r=t[0]-e[0],o=t[1]-e[1];return Math.sqrt(r*r+o*o)};let i=0;for(let e=1;e<o.length;e++)i+=n(o[e-1],o[e]);if(!Number.isFinite(i)||i<=0)return o;const a=i/Math.max(r,4),s=[o[0]];let l=0;for(let e=1;e<o.length;e++){let t=o[e-1];const r=o[e];let i=n(t,r);for(;l+i>=a&&i>0;){const e=(a-l)/i,o=[t[0]+(r[0]-t[0])*e,t[1]+(r[1]-t[1])*e];s.push(o),t=o,i=n(t,r),l=0}l+=i}return e(s)})(o,Math.max(4,Math.min(a,n*i))),l=(t=>{if(!t||0===t.length)return t;const r=1e-6,o=new Set,n=[];for(let e=0;e<t.length;e++){const i=t[e];if(!Array.isArray(i)||i.length<2)continue;const a=`${Math.round(i[0]/r)}:${Math.round(i[1]/r)}`;o.has(a)||(o.add(a),n.push(i))}return e(n)})(s);return l.length>=4?l:r}catch(o){return _n()||console.warn("Bezier smoothing failed for ring, falling back to original:",o),r}}));return this.getMultiPolygon(r)}polygonHasHoles(t){try{return"Polygon"===t.geometry.type?t.geometry.coordinates.length>1:"MultiPolygon"===t.geometry.type&&t.geometry.coordinates.some(t=>t.length>1)}catch(e){return _n()||console.warn("Error checking for holes:",e instanceof Error?e.message:String(e)),!1}}getKinksWithHolePreservation(t){try{if("Polygon"===t.geometry.type){const e=t.geometry.coordinates,r=e[0],o=e.slice(1),n={type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:t.properties||{}},i=this.hasKinks(n),a=this.checkOuterRingHoleIntersection(r,o);if(i||a){if(this.checkIfDragCompletelyThroughHole(r,o))return this.handleCompleteHoleTraversal(n,o);const t=Jr(n),e=[];return U(t,t=>{const r=this.subtractIntersectingHoles(t,o);e.push(r)}),e}return[t]}if("MultiPolygon"===t.geometry.type){const e=[];for(const r of t.geometry.coordinates){const o={type:"Feature",geometry:{type:"Polygon",coordinates:r},properties:t.properties||{}},n=this.getKinksWithHolePreservation(o);e.push(...n)}return e}return[t]}catch(e){return _n()||console.warn("Error in getKinksWithHolePreservation:",e instanceof Error?e.message:String(e)),[t]}}checkIfDragCompletelyThroughHole(t,e){try{if(this.findDuplicatePoints(t).length>0)return!0;const r=this.findSelfIntersectionLine(t);if(r&&e.length>0)for(const t of e)if(this.lineCompletelyTraversesHole(r,t))return!0;if(this.hasKinks({type:"Feature",geometry:{type:"Polygon",coordinates:[t]},properties:{}}))for(const o of e)if(this.holeIsCutByKinks(t,o))return!0;return!1}catch(r){return _n()||console.warn("Error checking complete hole traversal:",r instanceof Error?r.message:String(r)),!1}}findSelfIntersectionLine(t){try{const e=new Map;for(let r=0;r<t.length-1;r++){const o=t[r],n=`${o[0]},${o[1]}`;e.has(n)?e.get(n).indices.push(r):e.set(n,{point:o,indices:[r]})}for(const[,r]of e)if(r.indices.length>=2){const e=r.indices[0],o=r.indices[1],n=[];for(let r=e;r<=o;r++)n.push(t[r]);return n}return null}catch(e){return _n()||console.warn("Error finding self-intersection line:",e instanceof Error?e.message:String(e)),null}}lineCompletelyTraversesHole(t,e){try{if(t.length<2)return!1;const r=t[0],o=t[t.length-1],n=M([e]),i=Ur(m(r),n);return i!==Ur(m(o),n)}catch(r){return _n()||console.warn("Error checking line hole traversal:",r instanceof Error?r.message:String(r)),!1}}holeIsCutByKinks(t,e){try{const r=M([t]),o=M([e]),n=lr(r);if(0===n.features.length)return!1;for(const t of n.features){const e=t.geometry.coordinates;try{if(k(m(e),E(o))<.01)return!0;if(Ur(m(e),o))return!0}catch{if(Ur(m(e),o))return!0}}return!1}catch(r){return _n()||console.warn("Error checking hole cut by kinks:",r.message),!1}}findDuplicatePoints(t){const e=[],r=new Set;for(let o=0;o<t.length-1;o++){const n=t[o],i=`${n[0]},${n[1]}`;r.has(i)?e.push(n):r.add(i)}return e}checkOuterRingHoleIntersection(t,e){try{if(0===e.length)return!1;const r=M([t]);for(const o of e){const e=M([o]);if(this.getIntersection(r,e))return!0;for(let r=0;r<t.length-1;r++){const o=t[r];if(Ur(m(o),e))return!0}}return!1}catch{return!1}}handleCompleteHoleTraversal(t,e){try{const e={type:"Feature",geometry:{type:"Polygon",coordinates:[t.geometry.coordinates[0]]},properties:t.properties||{}},r=Jr(e),o=[];return U(r,t=>{t._polydrawHoleTraversalOccurred=!0,o.push(t)}),o}catch(r){_n()||console.warn("Error handling complete hole traversal:",r instanceof Error?r.message:String(r));try{const e={...t,geometry:{...t.geometry,coordinates:[t.geometry.coordinates[0]]}};return e._polydrawHoleTraversalOccurred=!0,[e]}catch{return[t]}}}subtractIntersectingHoles(t,e){try{let r=t;for(const t of e){const e=M([t]);if(this.getIntersection(e,r)){const t=this.polygonDifference(r,e);if(t)if("Polygon"===t.geometry.type)r=t;else if("MultiPolygon"===t.geometry.type){const e=t;let o=0,n=null;for(const t of e.geometry.coordinates){const e={type:"Feature",geometry:{type:"Polygon",coordinates:t},properties:{}},r=W(e);r>o&&(o=r,n=e)}n&&(r=n)}}}return r}catch(r){return _n()||console.warn("Error subtracting intersecting holes:",r instanceof Error?r.message:String(r)),t}}removeDuplicateVertices(t){if(!t||!t.geometry||!t.geometry.coordinates)return _n()||console.warn("Invalid feature passed to removeDuplicateVertices"),t;const e=t=>{if(!t||t.length<3)return _n()||console.warn("Invalid coordinates array - need at least 3 points for a polygon"),t||[];const e=[],r=1e-6,o=new Set;for(let n=0;n<t.length;n++){const i=t[n],a=t[(n+1)%t.length];if(!i||!Array.isArray(i)||i.length<2||!a||!Array.isArray(a)||a.length<2)continue;const s=Math.abs(i[1]-a[1]),l=Math.abs(i[0]-a[0]),c=`${Math.round(i[0]/r)}:${Math.round(i[1]/r)}`,h=o.has(c);(s>r||l>r)&&!h&&(e.push(i),o.add(c))}if(e.length<3)return _n()||console.warn("After cleaning, polygon has less than 3 points"),t;if(e.length>0){const t=e[0],o=e[e.length-1],n=Math.abs(t[1]-o[1]),i=Math.abs(t[0]-o[0]);(n>r||i>r)&&e.push([t[0],t[1]])}return e};try{if("Polygon"===t.geometry.type){const r=t.geometry.coordinates.map(t=>e(t));return r.some(t=>t.length<4)?(_n()||console.warn("Cleaned polygon has invalid ring with less than 4 coordinates"),t):{...t,geometry:{...t.geometry,coordinates:r}}}if("MultiPolygon"===t.geometry.type){const r=t.geometry.coordinates.map(t=>t.map(t=>e(t)));return r.some(t=>t.some(t=>t.length<4))?(_n()||console.warn("Cleaned multipolygon has invalid ring with less than 4 coordinates"),t):{...t,geometry:{...t.geometry,coordinates:r}}}}catch(r){return _n()||console.warn("Error in removeDuplicateVertices:",r instanceof Error?r.message:String(r)),t}return t}}const Rn=()=>{if("undefined"!=typeof globalThis)return globalThis.L};class Xn{static getVersion(){if(this._detectedVersion)return this._detectedVersion;const t=Rn();return t?(this._detectedVersion=this.detectVersion(t),this._detectedVersion):l.V2}static detectVersion(t){const e=t??Rn();if(!e)return l.V2;if(e.version){if(e.version.startsWith("2."))return l.V2;if(e.version.startsWith("1."))return l.V1}return"function"!=typeof e.marker?l.V2:"function"==typeof e.marker&&"function"==typeof e.polyline&&"function"==typeof e.polygon?l.V1:e.Marker&&"function"==typeof e.Marker&&e.Polyline&&"function"==typeof e.Polyline?l.V2:l.V1}static isV1(){return this.getVersion()===l.V1}static isV2(){return this.getVersion()===l.V2}static reset(){this._detectedVersion=null}static getVersionInfo(){const t=this.getVersion(),e=Rn();return{version:t,leafletVersion:null==e?void 0:e.version,hasFactoryMethods:"function"==typeof(null==e?void 0:e.marker),hasConstructors:!!(null==e?void 0:e.Marker)&&"function"==typeof e.Marker,globalLAvailable:!!e}}}i(Xn,"_detectedVersion",null);const Yn=new class{constructor(){i(this,"domUtil",{create:(t,e,r)=>{if(void 0!==s&&s.DomUtil)return s.DomUtil.create(t,e,r);{const o=document.createElement(t);return e&&(o.className=e),r&&r.appendChild(o),o}},addClass:(t,e)=>{this.version===l.V1?s.DomUtil.addClass(t,e):t.classList.add(e)},removeClass:(t,e)=>{this.version===l.V1?s.DomUtil.removeClass(t,e):t.classList.remove(e)},hasClass:(t,e)=>this.version===l.V1?s.DomUtil.hasClass(t,e):t.classList.contains(e),setPosition:(t,e)=>{s.DomUtil.setPosition(t,e)},getPosition:t=>s.DomUtil.getPosition(t)}),i(this,"domEvent",{on:(t,e,r,o)=>(s.DomEvent.on(t,e,r,o),this),off:(t,e,r,o)=>(s.DomEvent.off(t,e,r,o),this),stopPropagation:t=>(s.DomEvent.stopPropagation(t),this),preventDefault:t=>(s.DomEvent.preventDefault(t),this),stop:t=>(s.DomEvent.stop(t),this),disableClickPropagation:t=>(s.DomEvent.disableClickPropagation(t),this),disableScrollPropagation:t=>(s.DomEvent.disableScrollPropagation(t),this),getMousePosition:(t,e)=>{if(this.version===l.V1)return s.DomEvent.getMousePosition(t,e);{const r=s.DomEvent;return r.getPointerPosition?r.getPointerPosition(t,e):s.DomEvent.getMousePosition(t,e)}}}),i(this,"util",{extend:(t,...e)=>this.version===l.V1?s.Util.extend(t,...e):Object.assign(t,...e),bind:(t,e)=>this.version===l.V1?s.Util.bind(t,e):t.bind(e),stamp:t=>s.Util.stamp(t),throttle:(t,e,r)=>s.Util.throttle(t,e,r),wrapNum:(t,e,r)=>s.Util.wrapNum(t,e,r),falseFn:()=>s.Util.falseFn(),formatNum:(t,e)=>s.Util.formatNum(t,e),trim:t=>this.version===l.V1?s.Util.trim(t):t.trim(),splitWords:t=>s.Util.splitWords(t),setOptions:(t,e)=>s.Util.setOptions(t,e),getParamString:(t,e,r)=>{if(this.version===l.V1)return s.Util.getParamString(t,e,r);{const o=new URLSearchParams;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const n=r?e.toUpperCase():e;o.set(n,String(t[e]))}const n=o.toString();if(e){const t=-1===e.indexOf("?")?"?":"&";return e+t+n}return n?"?"+n:""}},template:(t,e)=>s.Util.template(t,e),isArray:t=>this.version===l.V1?s.Util.isArray(t):Array.isArray(t),indexOf:(t,e)=>s.Util.indexOf(t,e),requestAnimFrame:(t,e,r)=>this.version===l.V1?s.Util.requestAnimFrame(t,e,r):requestAnimationFrame(e?t.bind(e):t),cancelAnimFrame:t=>{this.version===l.V1?s.Util.cancelAnimFrame(t):cancelAnimationFrame(t)}})}get version(){return Xn.getVersion()}createTileLayer(t,e){return new s.TileLayer(t,e)}createMap(t,e){return new s.Map(t,e)}createMarker(t,e){return new s.Marker(t,e)}createPolyline(t,e){return new s.Polyline(t,e)}createPolygon(t,e){return new s.Polygon(t,e)}createDivIcon(t){return new s.DivIcon(t)}createLatLng(t,e,r){return new s.LatLng(t,e,r)}createLatLngBounds(t,e){return t&&e?new s.LatLngBounds(t,e):t?new s.LatLngBounds(t,t):new s.LatLngBounds([])}createPoint(t,e,r){return new s.Point(t,e,r)}createPopup(t,e){return new s.Popup(t,e)}createFeatureGroup(t){return new s.FeatureGroup(t)}createLayerGroup(t){return new s.LayerGroup(t)}getBrowser(){const t=this,e=s.Browser;return{get ie(){return t.version===l.V1&&s.Browser.ie},get ielt9(){return t.version===l.V1&&s.Browser.ielt9},get edge(){return t.version===l.V1&&s.Browser.edge},get webkit(){return t.version===l.V1&&s.Browser.webkit},get android(){return t.version===l.V1?s.Browser.android:/Android/.test(navigator.userAgent)},get android23(){return t.version===l.V1&&s.Browser.android23},get androidStock(){return t.version===l.V1&&s.Browser.androidStock},get opera(){return t.version===l.V1&&s.Browser.opera},get chrome(){return t.version===l.V1?s.Browser.chrome:/Chrome/.test(navigator.userAgent)},get gecko(){return t.version===l.V1&&s.Browser.gecko},get safari(){return t.version===l.V1?s.Browser.safari:/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)},get phantom(){return t.version===l.V1&&(e.phantom??!1)},get opera12(){return t.version===l.V1&&s.Browser.opera12},get win(){return t.version===l.V1?s.Browser.win:/Win/.test(navigator.platform)},get ie3d(){return t.version===l.V1&&s.Browser.ie3d},get webkit3d(){return t.version===l.V1&&s.Browser.webkit3d},get gecko3d(){return t.version===l.V1&&s.Browser.gecko3d},get any3d(){return t.version!==l.V1||s.Browser.any3d},get mobile(){return s.Browser.mobile},get mobileWebkit(){return t.version===l.V1&&s.Browser.mobileWebkit},get mobileWebkit3d(){return t.version===l.V1&&s.Browser.mobileWebkit3d},get msPointer(){return t.version===l.V1&&s.Browser.msPointer},get pointer(){return s.Browser.pointer||!0},get touch(){return s.Browser.touch},get touchNative(){return t.version===l.V1&&(e.touchNative??!1)},get mobileOpera(){return t.version===l.V1&&s.Browser.mobileOpera},get mobileGecko(){return t.version===l.V1&&s.Browser.mobileGecko},get retina(){return s.Browser.retina},get passiveEvents(){return t.version!==l.V1||(e.passiveEvents??!0)},get canvas(){return t.version!==l.V1||s.Browser.canvas},get svg(){return t.version!==l.V1||s.Browser.svg},get vml(){return t.version===l.V1&&s.Browser.vml},get inlineSvg(){return t.version!==l.V1||(e.inlineSvg??!0)}}}getVersion(){return this.version}isV1(){return this.version===l.V1}isV2(){return this.version===l.V2}};function Vn(t,e){t.innerHTML=e;const r=t.querySelector("svg");r&&(!function(t){if(t.hasAttribute("viewBox"))return;const e=t.getAttribute("width"),r=t.getAttribute("height"),o=e?parseFloat(e):NaN,n=r?parseFloat(r):NaN;Number.isFinite(o)&&Number.isFinite(n)&&o>0&&n>0&&t.setAttribute("viewBox",`0 0 ${o} ${n}`)}(r),function(t){const e=Array.from(t.querySelectorAll("style"));if(0===e.length)return;const r=new Set;if(e.forEach(e=>{const o=e.textContent;if(!o)return void e.remove();const n=/([^{]+)\{([^}]*)\}/g;let i;for(;null!==(i=n.exec(o));){const e=i[1].split(",").map(t=>t.trim()).filter(Boolean),o=i[2];e.forEach(e=>{if(!e.startsWith("."))return;const n=e.slice(1);r.add(n),t.querySelectorAll(`.${n}`).forEach(t=>{o.split(";").forEach(e=>{const[r,o]=e.split(":");r&&o&&t.style.setProperty(r.trim(),o.trim())})})})}e.remove()}),0===r.size)return;t.querySelectorAll("[class]").forEach(t=>{const e=Array.from(t.classList).filter(t=>!r.has(t));e.length>0?t.setAttribute("class",e.join(" ")):t.removeAttribute("class")})}(r),r.setAttribute("width","24"),r.setAttribute("height","24"),r.style.pointerEvents="none",r.querySelectorAll("*").forEach(t=>{t.style.pointerEvents="none"}))}const qn='<?xml version="1.0" encoding="utf-8"?>\n<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" id="Layer_1" x="0" y="0" style="enable-background:new 0 0 48 48" version="1.1" viewBox="0 0 48 48">\n <style>\n .st0{fill:#000}\n </style>\n <path d="M0 0h48v48H0z" style="fill:#333;fill-opacity:0"/>\n <path d="M26.6 10V7.8h-5.2V10h-8.8v2.8h22.8V10zM35.4 15.4H12.6v4.3h1.8V37c0 1.1.9 2 2 2h15.2c1.1 0 2-.9 2-2V19.7h1.8v-4.3zM19.7 34.2c0 .5-.4 1-1 1-.5 0-1-.4-1-1V22.6c0-.5.4-1 1-1 .5 0 1 .4 1 1v11.6zm5.6-.4c0 .7-.6 1.3-1.3 1.3-.7 0-1.3-.6-1.3-1.3V23c0-.7.6-1.3 1.3-1.3.7 0 1.3.6 1.3 1.3v10.8zm5 .4c0 .5-.4 1-1 1-.5 0-1-.4-1-1V22.6c0-.5.4-1 1-1 .5 0 1 .4 1 1v11.6z" class="st0"/>\n</svg>',jn={activate:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" id="svg1" width="512" height="512" version="1.1">\n <path id="Shape" fill="#000" fill-rule="evenodd" stroke="none" d="M73.574 425.687c-1.14.188-4.099-.592-6.574-1.735-2.475-1.142-5.513-3.027-6.75-4.188C58 417.65 58 417.65 58 348.144c0-69.506 0-69.506 6.152-80.075a1599.57 1599.57 0 0 1 12.84-21.569c3.677-6.05 12.679-21.125 20.004-33.5 7.324-12.375 15.666-26.325 18.538-31 2.87-4.675 13.163-21.88 22.872-38.233a33686.921 33686.921 0 0 1 34.229-57.5c9.117-15.272 18.261-30.022 20.322-32.777 2.298-3.074 5.78-6.117 9.008-7.874 3.583-1.95 7.22-3.017 11.399-3.342 4.972-.388 7.445.018 13.04 2.137 3.799 1.439 10.999 4.919 16 7.733 5.003 2.814 13.371 7.613 18.596 10.663s13.775 8.134 19 11.297c5.225 3.163 12.061 7.246 15.192 9.073 3.13 1.828 9.402 5.521 13.936 8.208 4.535 2.686 10.397 6.897 13.027 9.357 3.265 3.054 5.457 6.261 6.912 10.115 1.672 4.43 2.036 7.161 1.694 12.704-.324 5.244-1.186 8.511-3.349 12.695-1.601 3.098-9.388 16.57-17.303 29.939-7.915 13.368-16.24 27.326-18.5 31.019a3087.099 3087.099 0 0 0-9.697 16c-3.073 5.107-11.2 18.736-18.061 30.286-6.86 11.55-16.45 27.75-21.312 36-4.86 8.25-11.179 18.825-14.04 23.5-2.862 4.675-8.308 13.83-12.101 20.343-3.794 6.513-10.508 17.762-14.92 24.997-7.721 12.664-8.263 13.29-14.5 16.77-3.563 1.987-15.357 8.416-26.21 14.286-10.851 5.87-28.851 15.66-40 21.756-11.147 6.096-25.86 14.032-32.694 17.638-6.834 3.605-13.359 6.709-14.5 6.897ZM116 376.754c2.096-.21 12.525-5.28 26-12.636 12.375-6.757 23.394-13.153 24.486-14.215 1.495-1.453 1.734-2.331.966-3.548-.56-.889-7.304-5.352-14.986-9.918-7.681-4.565-17.116-10.268-20.966-12.672-3.85-2.405-15.046-9.073-24.88-14.818-9.834-5.746-19.087-10.976-20.561-11.623-1.641-.72-3.24-.831-4.12-.287-.981.606-1.598 3.444-1.939 8.924-.275 4.42-.347 17.312-.16 28.65.341 20.616.341 20.616 3.5 23.908 1.738 1.81 9.01 6.733 16.16 10.94 10.754 6.327 13.605 7.587 16.5 7.295ZM184.98 329c.9 0 2.342-.563 3.204-1.25.86-.688 3.803-4.85 6.537-9.25 2.735-4.4 17.476-28.925 32.759-54.5 15.283-25.575 29.64-49.497 31.904-53.16 2.264-3.662 6.141-10.152 8.616-14.422 2.475-4.27 5.957-10.274 7.738-13.341 1.785-3.075 3.244-7.005 3.25-8.759.011-2.982-.694-3.614-11.238-10.077A2882.894 2882.894 0 0 0 249 152.847c-4.125-2.475-13.245-7.94-20.267-12.145a9841.507 9841.507 0 0 1-20.5-12.309 1566.199 1566.199 0 0 0-14.685-8.73c-3.823-2.238-8.13-4.242-9.57-4.453-1.998-.293-3.333.43-5.64 3.057-1.661 1.893-5.368 7.444-8.237 12.337a2040.256 2040.256 0 0 1-11.477 19.251 5775.594 5775.594 0 0 0-12.325 20.5A7048.542 7048.542 0 0 1 131.47 195c-4.823 7.975-10.898 18.1-13.501 22.5-2.604 4.4-8.45 14.075-12.991 21.5-4.542 7.425-10.268 16.988-12.725 21.252-3.26 5.657-4.304 8.405-3.861 10.168.454 1.81 4.239 4.57 15.1 11.01 7.973 4.726 20.686 12.257 28.252 16.735 7.566 4.477 17.582 10.485 22.257 13.351 4.675 2.866 13.19 7.973 18.921 11.348 5.732 3.375 11.158 6.136 12.059 6.136Zm100.681-194.022c2.318.016 3.852-.798 5.75-3.055 1.497-1.78 2.589-4.313 2.589-6.01 0-2.269-.848-3.508-3.75-5.478-2.063-1.4-6.53-4.29-9.927-6.421-3.398-2.132-9.923-6.015-14.5-8.63-4.578-2.614-10.798-6.408-13.823-8.43-3.025-2.022-7.75-4.873-10.5-6.334-2.75-1.462-8.15-4.689-12-7.171-5.023-3.24-7.838-4.434-9.968-4.232-2.1.2-3.65 1.298-5.297 3.75-1.437 2.14-2.215 4.588-2.032 6.391.254 2.498 1.604 3.72 9.297 8.412 4.95 3.02 15.525 9.427 23.5 14.238a3631.896 3631.896 0 0 1 26 15.848c7.807 4.82 12.515 7.107 14.661 7.122Z"/>\n <path id="path1" fill="#000" fill-rule="evenodd" stroke="none" d="M479.5 119.5c0 34 0 34-7 34.262-3.85.144-11.275.947-16.5 1.785s-12.533 2.42-16.24 3.514c-3.708 1.095-9.416 3.559-12.686 5.475-3.269 1.916-7.401 4.71-9.183 6.209-1.781 1.499-4.926 5.336-6.988 8.526-2.395 3.706-4.41 8.588-5.576 13.515-1.346 5.684-1.817 11.548-1.79 22.282.023 8.902.749 19.208 1.866 26.5 1.006 6.563 2.964 17.107 4.352 23.432 1.388 6.325 3.152 14.2 3.92 17.5.768 3.3 3.14 14.55 5.272 25s4.816 24.901 5.965 32.114c1.57 9.86 2.088 17.705 2.088 31.622 0 16.395-.284 19.635-2.485 28.386-1.367 5.433-4.299 13.56-6.515 18.061-2.832 5.75-6.265 10.559-11.545 16.172-5.308 5.642-10.516 9.846-17.735 14.316-5.62 3.481-13.145 7.611-16.72 9.179-3.575 1.567-10.739 4.4-15.92 6.293-5.181 1.894-13.506 4.308-18.5 5.365-4.994 1.056-13.58 2.637-19.08 3.513-6.633 1.057-18.754 1.716-36 1.958-14.3.201-30.5.01-36-.424s-15.625-1.537-22.5-2.45c-6.875-.912-16.575-2.328-21.557-3.146-4.98-.817-12.406-2.176-16.5-3.02-4.093-.843-9.693-2.157-12.443-2.92-2.75-.763-7.7-2.083-11-2.932-3.3-.85-10.5-2.648-16-3.996-5.5-1.348-15.85-4.3-23-6.56-7.15-2.261-14.912-4.805-17.25-5.653-2.904-1.055-4.25-2.127-4.25-3.386 0-1.228 3.252-3.97 9.75-8.22 5.363-3.507 13.202-8.277 17.421-10.6 7.671-4.225 7.671-4.225 18.5-1.287 5.956 1.616 19.154 4.998 29.329 7.515 10.175 2.517 23.45 5.465 29.5 6.55 6.05 1.087 15.05 2.427 20 2.98 4.95.552 14.85 1.53 22 2.175 8.107.73 21.657.955 36 .598 13.264-.33 27.021-1.234 32.5-2.135 5.225-.86 14-2.963 19.5-4.673s12.925-4.443 16.5-6.073a870.93 870.93 0 0 0 11.5-5.354c2.75-1.314 7.94-4.836 11.535-7.826 3.888-3.234 7.591-7.403 9.142-10.29 1.433-2.668 3.653-8.143 4.932-12.166 1.934-6.082 2.319-9.415 2.283-19.794-.024-7.149-.774-16.627-1.756-22.186-.943-5.339-2.407-13.531-3.253-18.206-.847-4.675-2.454-12.775-3.572-18-1.118-5.225-3.15-14-4.514-19.5-1.365-5.5-3.5-14.725-4.746-20.5-1.246-5.775-2.995-15-3.886-20.5-.892-5.5-2.081-14.08-2.643-19.068-.562-4.987-1.014-13.987-1.005-20 .01-6.012.652-14.799 1.427-19.525.775-4.726 2.12-11.026 2.988-14 .869-2.974 3.04-8.224 4.824-11.668 1.784-3.443 5.256-9.004 7.715-12.356 2.46-3.353 8.084-8.988 12.5-12.523 4.416-3.534 11.629-8.164 16.029-10.287 4.4-2.124 12.05-5.194 17-6.823 4.95-1.63 14.625-3.757 21.5-4.729s16.1-1.824 20.5-1.894l8-.127Z"/>\n <path id="path2" fill="#B6BCC4" fill-rule="evenodd" stroke="none" d="M116 375.743c-2.73.236-5.372-.8-12-4.708-4.675-2.756-11.133-6.704-14.35-8.773-3.218-2.07-6.48-4.977-7.25-6.462-1.094-2.111-1.4-8.348-1.4-28.56 0-21.125.267-26.213 1.461-27.799 1.43-1.9 1.574-1.879 6.75.986 2.909 1.61 8.214 4.584 11.789 6.61 3.575 2.026 9.1 5.209 12.28 7.073 3.179 1.865 10.253 6.09 15.722 9.39 5.468 3.3 13.836 8.245 18.596 10.989 4.76 2.744 10.736 6.348 13.279 8.01 2.568 1.678 4.753 3.927 4.917 5.062.246 1.716-3.42 4.101-23 14.96-14.766 8.189-24.575 13.03-26.794 13.222Z"/>\n <path id="path3" fill="#fff" fill-rule="evenodd" stroke="none" d="M185.256 329c-1.012 0-5.646-2.194-10.298-4.875-4.652-2.68-22.633-13.322-39.958-23.648-17.325-10.325-34.65-20.844-38.5-23.375-6.25-4.109-7.029-4.977-7.268-8.102-.202-2.632.816-5.36 4.106-11 2.407-4.125 21.576-36.075 42.6-71 21.022-34.925 39.47-65.075 40.994-67 2.195-2.772 3.589-3.562 6.699-3.797 3.477-.262 6.271 1.103 24.398 11.925 11.259 6.722 30.146 18.027 41.971 25.123 11.825 7.095 23.075 14.15 25 15.675 2.099 1.664 3.627 3.836 3.816 5.425.19 1.592-1.021 5.145-3.035 8.9-1.844 3.437-21.525 36.528-43.737 73.537-22.211 37.008-41.411 68.395-42.666 69.75-1.256 1.354-3.11 2.462-4.122 2.462Z"/>\n</svg>'.trim(),draw:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" id="svg1" width="512" height="512" version="1.1">\n <path id="Shape" fill="#000" fill-rule="evenodd" stroke="none" d="M73.574 425.687c-1.14.188-4.099-.592-6.574-1.735-2.475-1.142-5.513-3.027-6.75-4.188C58 417.65 58 417.65 58 348.144c0-69.506 0-69.506 6.152-80.075a1599.57 1599.57 0 0 1 12.84-21.569c3.677-6.05 12.679-21.125 20.004-33.5 7.324-12.375 15.666-26.325 18.538-31 2.87-4.675 13.163-21.88 22.872-38.233a33686.921 33686.921 0 0 1 34.229-57.5c9.117-15.272 18.261-30.022 20.322-32.777 2.298-3.074 5.78-6.117 9.008-7.874 3.583-1.95 7.22-3.017 11.399-3.342 4.972-.388 7.445.018 13.04 2.137 3.799 1.439 10.999 4.919 16 7.733 5.003 2.814 13.371 7.613 18.596 10.663s13.775 8.134 19 11.297c5.225 3.163 12.061 7.246 15.192 9.073 3.13 1.828 9.402 5.521 13.936 8.208 4.535 2.686 10.397 6.897 13.027 9.357 3.265 3.054 5.457 6.261 6.912 10.115 1.672 4.43 2.036 7.161 1.694 12.704-.324 5.244-1.186 8.511-3.349 12.695-1.601 3.098-9.388 16.57-17.303 29.939-7.915 13.368-16.24 27.326-18.5 31.019a3087.099 3087.099 0 0 0-9.697 16c-3.073 5.107-11.2 18.736-18.061 30.286-6.86 11.55-16.45 27.75-21.312 36-4.86 8.25-11.179 18.825-14.04 23.5-2.862 4.675-8.308 13.83-12.101 20.343-3.794 6.513-10.508 17.762-14.92 24.997-7.721 12.664-8.263 13.29-14.5 16.77-3.563 1.987-15.357 8.416-26.21 14.286-10.851 5.87-28.851 15.66-40 21.756-11.147 6.096-25.86 14.032-32.694 17.638-6.834 3.605-13.359 6.709-14.5 6.897ZM116 376.754c2.096-.21 12.525-5.28 26-12.636 12.375-6.757 23.394-13.153 24.486-14.215 1.495-1.453 1.734-2.331.966-3.548-.56-.889-7.304-5.352-14.986-9.918-7.681-4.565-17.116-10.268-20.966-12.672-3.85-2.405-15.046-9.073-24.88-14.818-9.834-5.746-19.087-10.976-20.561-11.623-1.641-.72-3.24-.831-4.12-.287-.981.606-1.598 3.444-1.939 8.924-.275 4.42-.347 17.312-.16 28.65.341 20.616.341 20.616 3.5 23.908 1.738 1.81 9.01 6.733 16.16 10.94 10.754 6.327 13.605 7.587 16.5 7.295ZM184.98 329c.9 0 2.342-.563 3.204-1.25.86-.688 3.803-4.85 6.537-9.25 2.735-4.4 17.476-28.925 32.759-54.5 15.283-25.575 29.64-49.497 31.904-53.16 2.264-3.662 6.141-10.152 8.616-14.422 2.475-4.27 5.957-10.274 7.738-13.341 1.785-3.075 3.244-7.005 3.25-8.759.011-2.982-.694-3.614-11.238-10.077A2882.894 2882.894 0 0 0 249 152.847c-4.125-2.475-13.245-7.94-20.267-12.145a9841.507 9841.507 0 0 1-20.5-12.309 1566.199 1566.199 0 0 0-14.685-8.73c-3.823-2.238-8.13-4.242-9.57-4.453-1.998-.293-3.333.43-5.64 3.057-1.661 1.893-5.368 7.444-8.237 12.337a2040.256 2040.256 0 0 1-11.477 19.251 5775.594 5775.594 0 0 0-12.325 20.5A7048.542 7048.542 0 0 1 131.47 195c-4.823 7.975-10.898 18.1-13.501 22.5-2.604 4.4-8.45 14.075-12.991 21.5-4.542 7.425-10.268 16.988-12.725 21.252-3.26 5.657-4.304 8.405-3.861 10.168.454 1.81 4.239 4.57 15.1 11.01 7.973 4.726 20.686 12.257 28.252 16.735 7.566 4.477 17.582 10.485 22.257 13.351 4.675 2.866 13.19 7.973 18.921 11.348 5.732 3.375 11.158 6.136 12.059 6.136Zm100.681-194.022c2.318.016 3.852-.798 5.75-3.055 1.497-1.78 2.589-4.313 2.589-6.01 0-2.269-.848-3.508-3.75-5.478-2.063-1.4-6.53-4.29-9.927-6.421-3.398-2.132-9.923-6.015-14.5-8.63-4.578-2.614-10.798-6.408-13.823-8.43-3.025-2.022-7.75-4.873-10.5-6.334-2.75-1.462-8.15-4.689-12-7.171-5.023-3.24-7.838-4.434-9.968-4.232-2.1.2-3.65 1.298-5.297 3.75-1.437 2.14-2.215 4.588-2.032 6.391.254 2.498 1.604 3.72 9.297 8.412 4.95 3.02 15.525 9.427 23.5 14.238a3631.896 3631.896 0 0 1 26 15.848c7.807 4.82 12.515 7.107 14.661 7.122Z" style="stroke:#000;stroke-opacity:1;stroke-width:20;stroke-dasharray:none"/>\n <path id="path1" fill="#000" fill-rule="evenodd" stroke="none" d="M479.5 119.5c0 34 0 34-7 34.262-3.85.144-11.275.947-16.5 1.785s-12.533 2.42-16.24 3.514c-3.708 1.095-9.416 3.559-12.686 5.475-3.269 1.916-7.401 4.71-9.183 6.209-1.781 1.499-4.926 5.336-6.988 8.526-2.395 3.706-4.41 8.588-5.576 13.515-1.346 5.684-1.817 11.548-1.79 22.282.023 8.902.749 19.208 1.866 26.5 1.006 6.563 2.964 17.107 4.352 23.432 1.388 6.325 3.152 14.2 3.92 17.5.768 3.3 3.14 14.55 5.272 25s4.816 24.901 5.965 32.114c1.57 9.86 2.088 17.705 2.088 31.622 0 16.395-.284 19.635-2.485 28.386-1.367 5.433-4.299 13.56-6.515 18.061-2.832 5.75-6.265 10.559-11.545 16.172-5.308 5.642-10.516 9.846-17.735 14.316-5.62 3.481-13.145 7.611-16.72 9.179-3.575 1.567-10.739 4.4-15.92 6.293-5.181 1.894-13.506 4.308-18.5 5.365-4.994 1.056-13.58 2.637-19.08 3.513-6.633 1.057-18.754 1.716-36 1.958-14.3.201-30.5.01-36-.424s-15.625-1.537-22.5-2.45c-6.875-.912-16.575-2.328-21.557-3.146-4.98-.817-12.406-2.176-16.5-3.02-4.093-.843-9.693-2.157-12.443-2.92-2.75-.763-7.7-2.083-11-2.932-3.3-.85-10.5-2.648-16-3.996-5.5-1.348-15.85-4.3-23-6.56-7.15-2.261-14.912-4.805-17.25-5.653-2.904-1.055-4.25-2.127-4.25-3.386 0-1.228 3.252-3.97 9.75-8.22 5.363-3.507 13.202-8.277 17.421-10.6 7.671-4.225 7.671-4.225 18.5-1.287 5.956 1.616 19.154 4.998 29.329 7.515 10.175 2.517 23.45 5.465 29.5 6.55 6.05 1.087 15.05 2.427 20 2.98 4.95.552 14.85 1.53 22 2.175 8.107.73 21.657.955 36 .598 13.264-.33 27.021-1.234 32.5-2.135 5.225-.86 14-2.963 19.5-4.673s12.925-4.443 16.5-6.073a870.93 870.93 0 0 0 11.5-5.354c2.75-1.314 7.94-4.836 11.535-7.826 3.888-3.234 7.591-7.403 9.142-10.29 1.433-2.668 3.653-8.143 4.932-12.166 1.934-6.082 2.319-9.415 2.283-19.794-.024-7.149-.774-16.627-1.756-22.186-.943-5.339-2.407-13.531-3.253-18.206-.847-4.675-2.454-12.775-3.572-18-1.118-5.225-3.15-14-4.514-19.5-1.365-5.5-3.5-14.725-4.746-20.5-1.246-5.775-2.995-15-3.886-20.5-.892-5.5-2.081-14.08-2.643-19.068-.562-4.987-1.014-13.987-1.005-20 .01-6.012.652-14.799 1.427-19.525.775-4.726 2.12-11.026 2.988-14 .869-2.974 3.04-8.224 4.824-11.668 1.784-3.443 5.256-9.004 7.715-12.356 2.46-3.353 8.084-8.988 12.5-12.523 4.416-3.534 11.629-8.164 16.029-10.287 4.4-2.124 12.05-5.194 17-6.823 4.95-1.63 14.625-3.757 21.5-4.729s16.1-1.824 20.5-1.894l8-.127Z"/>\n <path id="path2" fill="#B6BCC4" fill-rule="evenodd" stroke="none" d="M116 375.743c-2.73.236-5.372-.8-12-4.708-4.675-2.756-11.133-6.704-14.35-8.773-3.218-2.07-6.48-4.977-7.25-6.462-1.094-2.111-1.4-8.348-1.4-28.56 0-21.125.267-26.213 1.461-27.799 1.43-1.9 1.574-1.879 6.75.986 2.909 1.61 8.214 4.584 11.789 6.61 3.575 2.026 9.1 5.209 12.28 7.073 3.179 1.865 10.253 6.09 15.722 9.39 5.468 3.3 13.836 8.245 18.596 10.989 4.76 2.744 10.736 6.348 13.279 8.01 2.568 1.678 4.753 3.927 4.917 5.062.246 1.716-3.42 4.101-23 14.96-14.766 8.189-24.575 13.03-26.794 13.222Z"/>\n</svg>'.trim(),subtract:'<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path fill-rule="evenodd" clip-rule="evenodd" d="M15.0722 3.9967L20.7508 9.83395L17.0544 13.5304L13.0758 17.5H21.0041V19H7.93503L4.00195 15.0669L15.0722 3.9967ZM10.952 17.5L15.4628 12.9994L11.8268 9.3634L6.12327 15.0669L8.55635 17.5H10.952Z" fill="#1F2328"></path> </g></svg>\n'.trim(),clone:'<?xml version="1.0" encoding="UTF-8"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">\n <rect x="88" y="88" width="252" height="252" fill="none" stroke="#000" stroke-width="42"/>\n <rect x="172" y="172" width="252" height="252" fill="none" stroke="#000" stroke-width="42"/>\n</svg>'.trim(),p2p:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" id="svg1" width="512" height="512" version="1.1">\n <path id="path7" d="m155.327 480.616 323.962-.033V45.207L32.68 44.87l.24 35.605 411.103-.882-.338 365.995-169.126-.577Z" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8" cx="460.396" cy="461.547" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8-8" cx="460.775" cy="65.834" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8-8-0" cx="67.176" cy="62.815" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <path id="path2" fill="#000" fill-rule="evenodd" stroke="none" d="M78.983 469.63c-2.155.594-4.661-.186-6.416-1.995-1.755-1.81-2.512-4.396-1.937-6.616.52-2.005 2.036-7.54 3.369-12.298 1.333-4.76 4.302-15.274 6.598-23.365 2.295-8.09 6.159-21.33 8.585-29.421a5326.7 5326.7 0 0 0 9.458-32.018c2.775-9.519 6.848-23.538 9.05-31.153a3424.585 3424.585 0 0 1 8.424-28.556c2.432-8.09 5.74-19.445 7.35-25.23 1.61-5.786 4.963-13.271 7.45-16.634 3.196-4.319 8.828-8.134 19.19-12.998 8.067-3.787 22.221-10.287 31.454-14.445 9.232-4.158 20.186-9.16 24.34-11.116a766.22 766.22 0 0 1 15.108-6.874c4.154-1.824 8.5-4.181 9.657-5.238 1.675-1.53 1.537-3.405-.681-9.226-2.27-5.96-2.436-8.498-.898-13.779 1.221-4.19 5.936-10.614 13.373-18.217 6.772-6.923 13.882-12.502 17.322-13.59 4.562-1.444 7.103-1.28 11.648.752 3.426 1.532 23.389 20.759 48.618 46.826 23.543 24.325 45.072 47.061 47.841 50.525 3.873 4.843 5.036 8.022 5.036 13.76 0 6.664-.988 8.548-9.232 17.594-5.078 5.572-11.81 12.267-14.959 14.876-4.16 3.448-7.614 4.745-12.635 4.745-3.801 0-8.653-1.259-10.783-2.797-2.18-1.574-4.506-2.141-5.322-1.298-.797.824-5.186 10.455-9.754 21.402a5146.966 5146.966 0 0 1-15.335 36.316c-3.866 9.027-10.026 22.886-13.689 30.798-4.617 9.975-8.217 15.361-11.743 17.572-2.796 1.753-10.879 5.156-17.961 7.562-7.083 2.406-20.431 6.749-29.664 9.65-9.232 2.902-25.661 8.033-36.509 11.403-10.847 3.37-31.242 9.76-45.323 14.201-14.08 4.44-32.777 10.286-41.547 12.99-8.771 2.704-17.539 5.355-19.483 5.892zm33.106-25.66c3.124-.525 14.558-3.756 25.407-7.18 10.85-3.424 33.511-10.53 50.36-15.791a27689.101 27689.101 0 0 1 50.776-15.803c14.114-4.37 21.467-7.596 24.568-10.778 2.433-2.497 8.003-13.108 12.378-23.578 4.374-10.471 10.397-24.88 13.384-32.018 2.987-7.14 8.327-19.6 11.866-27.691 3.54-8.091 6.71-17.047 7.046-19.903.555-4.717-2.161-8.042-29.692-36.345-16.667-17.133-31.78-31.396-33.584-31.694-1.804-.298-24.636 9.269-50.737 21.259-26.102 11.99-49.09 23.383-51.087 25.316-1.997 1.934-4.862 7.745-6.369 12.914a7969.157 7969.157 0 0 0-7.086 24.55 5161.998 5161.998 0 0 1-9.204 31.594c-2.67 9.043-9.076 30.85-14.234 48.46-5.158 17.609-10.028 34.72-10.822 38.026-.794 3.304-1.129 6.334-.743 6.731.385.397 3.176-1.24 6.202-3.637 3.026-2.397 17.965-17.532 33.199-33.633 15.233-16.1 31.64-33.573 36.46-38.83 8.522-9.292 8.717-9.73 7.063-15.905-1.163-4.344-1.143-8.487.066-13.114 1.094-4.191 4.275-9.1 8.364-12.909 3.648-3.398 9.265-6.662 12.561-7.3 4.51-.872 7.9-.158 13.92 2.932 4.845 2.486 9.223 6.36 11.188 9.9 1.776 3.2 3.3 9.202 3.385 13.339.09 4.285-1.167 10.058-2.921 13.416-1.693 3.242-6.11 7.651-9.814 9.798-5.669 3.285-8.24 3.73-16.226 2.804-9.49-1.099-9.49-1.099-49.778 40.478-22.158 22.867-40.577 42.47-40.932 43.56-.438 1.349 1.175 1.679 5.036 1.031zm90.33-98.225c3.355 0 6.06-1.502 8.524-4.733 2.602-3.409 3.338-6.138 2.634-9.765-.537-2.768-2.295-6.065-3.908-7.327-1.612-1.262-5.138-2.32-7.835-2.35-2.697-.03-6.285 1.234-7.974 2.81-1.808 1.687-3.07 5.242-3.07 8.653 0 3.481 1.339 7.169 3.358 9.25 1.846 1.904 5.568 3.462 8.271 3.462zm133.61-53.652c1.976 0 7.955-4.72 14.175-11.19 10.066-10.471 10.62-11.455 8.624-15.3-1.174-2.262-22.067-24.651-46.43-49.755-28.883-29.764-45.482-45.645-47.707-45.645-1.918 0-7.85 4.523-13.542 10.323-7.359 7.498-9.997 11.39-9.645 14.229.303 2.438 17.518 21.468 45.796 50.622 29.62 30.538 46.495 46.716 48.73 46.716z" style="stroke:#010101;stroke-width:17.0446;stroke-dasharray:none;stroke-opacity:1"/>\n <path id="path3" d="m243.547 189.376 16.458-15.442 96.745 96.717-16.459 16.256z" style="fill:green;fill-opacity:1;stroke:none;stroke-width:18.6862;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path9" cx="201.178" cy="332.215" r="13.593" style="fill:#fff;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n</svg>'.trim(),p2pSubtract:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" id="svg1" width="512" height="512" version="1.1">\n <path id="path2" fill="#000" fill-rule="evenodd" stroke="none" d="M193.812 478.594c-90.053.005-55.415-.21-62.995-.883-3.109-.277-27.11-21.644-46.82-41.478-19.71-19.834-38.405-39.3-41.545-43.255-3.14-3.957-6.62-10.716-7.734-15.02-1.731-6.696-1.64-9.153.633-17.007 2.63-9.085 3.646-10.163 97.355-103.187 67.82-67.324 96.742-95.006 101.9-97.53 4.693-2.298 10.024-3.498 15.308-3.447 5.932.057 10.337 1.334 16.417 4.757 5.373 3.027 23.906 20.087 52.456 48.29 24.281 23.987 46.739 47.413 49.906 52.058 4.533 6.648 5.893 10.36 6.393 17.444.536 7.598-.072 10.288-3.907 17.275-3.191 5.814-24.3 28.163-70.958 75.126-36.529 36.767-66.373 67.623-66.926 68.174-19.83 19.71-39.71 38.183-39.483 38.683zm84.581-137.331c-68.043-67.49-88.703-86.892-89.81-86.657-1.106.234-27.946 26.117-59.643 57.517-31.698 31.4-57.439 57.94-57.202 58.977.236 1.037 15.757 17.272 34.492 36.078 34.062 34.193 34.062 34.193 53.6 34.193 19.536 0 19.536 0 55.274-35.285 19.656-19.407 41.937-41.932 49.514-50.054zm60.94-60.024c-66.9-66.62-87.289-86.356-88.469-86.837-1.29-.527-8.787 5.684-18.813 15.585l-16.668 16.46 44.408 44.028c24.425 24.215 44.787 44.027 45.249 44.027.461 0 8.366-7.484 17.566-16.632z" style="stroke-width:1.5931"/>\n <path id="path3" d="m214.604 225.766 35.345-32.835 89.308 87.873-34.083 33.773z" style="fill:maroon;fill-opacity:1;stroke:#010101;stroke-width:7.48758"/>\n <path id="path7" d="m238.705 480.616 240.584-.033V45.207L32.68 44.87l.24 35.605 411.103-.882-.338 365.995-169.126-.577Z" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8" cx="460.396" cy="461.547" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8-8" cx="460.775" cy="65.834" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <circle id="path8-8-0" cx="67.176" cy="62.815" r="39.134" style="fill:#000;fill-opacity:1;stroke:none;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n</svg>'.trim(),erase:qn.trim(),collapse:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512">\n <path d="m80.033 292.15 175.755-174.592 175.755 174.591" style="fill:none;stroke:#000;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n <path d="M80.105 394.539 255.86 219.947 431.615 394.54" style="fill:none;stroke:#000;stroke-width:35;stroke-dasharray:none;stroke-opacity:1"/>\n</svg>'.trim(),undo:'<?xml version="1.0" encoding="utf-8"?>\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 48 48" xml:space="preserve">\n<style type="text/css">\n\t.st0{fill:none;stroke:#000000;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;}\n</style>\n<g>\n\t<path class="st0" d="M14,18h10c6.6,0,12,5.4,12,12s-5.4,12-12,12s-12-5.4-12-12"/>\n\t<polyline class="st0" points="18,14 14,18 18,22"/>\n</g>\n</svg>\n'.trim(),redo:'<?xml version="1.0" encoding="utf-8"?>\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 48 48" xml:space="preserve">\n<style type="text/css">\n\t.st0{fill:none;stroke:#000000;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;}\n</style>\n<g>\n\t<path class="st0" d="M34,18H24C17.4,18,12,23.4,12,30s5.4,12,12,12s12-5.4,12-12"/>\n\t<polyline class="st0" points="30,14 34,18 30,22"/>\n</g>\n</svg>\n'.trim()},Kn=(t,e)=>{Vn(t,e)},$n=(t,e)=>{t.setAttribute("data-tooltip",e),t.setAttribute("aria-label",e)};class Wn{static getCenter(t){let e=0,r=0,o=0;t.forEach(t=>{let n=t.lat,i=t.lng;n*=f,i*=f,e+=Math.cos(n)*Math.cos(i),r+=Math.cos(n)*Math.sin(i),o+=Math.sin(n)});let n=Math.atan2(r,e);const i=Math.sqrt(e*e+r*r);let a=Math.atan2(o,i);a*=y,n*=y;return{lat:a,lng:n}}static getSouthWest(t){return this.getBounds(t).getSouthWest()}static getNorthEast(t){return this.getBounds(t).getNorthEast()}static getNorthWest(t){return this.getBounds(t).getNorthWest()}static getSouthEast(t){return this.getBounds(t).getSouthEast()}static getNorth(t){return this.getBounds(t).getNorth()}static getSouth(t){return this.getBounds(t).getSouth()}static getWest(t){return this.getBounds(t).getWest()}static getEast(t){return this.getBounds(t).getEast()}static getSqmArea(t){const e=new s.Polygon(t).toGeoJSON();return this.turfHelper.getPolygonArea(e)}static getPerimeter(t){const e=new s.Polygon(t).toGeoJSON();return 1e3*this.turfHelper.getPolygonPerimeter(e)}static getPolygonChecksum(t){const e=t.filter((t,e,r)=>{const o=r.find(e=>e.lat===t.lat&&e.lng===t.lng);return!!o&&r.indexOf(o)===e});return e.reduce((t,e)=>+t+ +e.lat,0)*e.reduce((t,e)=>+t+ +e.lng,0)}static getMidPoint(t,e){const r=this.turfHelper.getMidpoint(t,e);return{lat:r.lat,lng:r.lng}}static getBounds(t){const e=[];t.forEach(t=>{isNaN(t.lat)||isNaN(t.lng),e.push(t)});return new s.Polyline(e).getBounds()}static getCenterOfMass(t){const e=this.turfHelper.getCenterOfMass(t);return{lat:e.geometry.coordinates[1],lng:e.geometry.coordinates[0]}}static getCenterOfPolygonByIndexWithOffsetFromCenterOfMass(t,e){const r=this.turfHelper.getCenterOfMass(t),o={lat:r.geometry.coordinates[1],lng:r.geometry.coordinates[0]},n=this.getPolygonLatLngAtIndex(t,e)??o,i=n.lat-o.lat,a=n.lng-o.lng,s={geometry:{coordinates:[o.lng+.5*a,o.lat+.5*i]}};return{lat:s.geometry.coordinates[1],lng:s.geometry.coordinates[0]}}static getPolygonLatLngAtIndex(t,e){const r=t.geometry;if(!r)return null;let o;if("Polygon"===r.type)o=r.coordinates[0];else{if("MultiPolygon"!==r.type)return null;o=r.coordinates[0][0]}if(!o||0===o.length)return null;if(o.length>1){const t=o[0],e=o[o.length-1];t[0]===e[0]&&t[1]===e[1]&&(o=o.slice(0,o.length-1))}if(0===o.length)return null;const n=o[(e%o.length+o.length)%o.length];return{lat:n[1],lng:n[0]}}}i(Wn,"turfHelper",new Un(u));class Jn{constructor(t){if(i(this,"polygon",[]),i(this,"trashcanPoint",[]),i(this,"sqmArea",[]),i(this,"perimeter",[]),!Array.isArray(t))return;if(t.length>0&&Array.isArray(t[0])&&t[0].length>0&&"object"==typeof t[0][0]&&"lat"in t[0][0]){const e=t[0];return this.trashcanPoint[0]=this.getTrashcanPoint(e),this.sqmArea[0]=this.calculatePolygonArea(e),this.perimeter[0]=this.calculatePolygonPerimeter(e),void(this.polygon[0]=[e])}if(t.length>0&&t[0]&&"object"==typeof t[0]&&"lat"in t[0]){const e=t,r=[[e]];return this.trashcanPoint[0]=this.getTrashcanPoint(e),this.sqmArea[0]=this.calculatePolygonArea(e),this.perimeter[0]=this.calculatePolygonPerimeter(e),void(this.polygon[0]=r[0])}t.forEach((t,e)=>{t&&Array.isArray(t)&&t[0]&&Array.isArray(t[0])&&(this.trashcanPoint[e]=this.getTrashcanPoint(t[0]),this.sqmArea[e]=this.calculatePolygonArea(t[0]),this.perimeter[e]=this.calculatePolygonPerimeter(t[0]),this.polygon[e]=t)})}setSqmArea(t){this.sqmArea[0]=t}getTrashcanPoint(t){if(!Array.isArray(t)||0===t.length)return console.warn("getTrashcanPoint: Invalid polygon array:",t),{lat:0,lng:0};const e=t.filter(t=>t&&"object"==typeof t&&"number"==typeof t.lat&&"number"==typeof t.lng&&!isNaN(t.lat)&&!isNaN(t.lng));if(0===e.length)return console.warn("getTrashcanPoint: No valid coordinates found:",t),{lat:0,lng:0};const r=Math.max(...e.map(t=>t.lat)),o=e.findIndex(t=>t.lat===r);if(-1===o)return console.warn("getTrashcanPoint: Could not find max lat coordinate"),{lat:0,lng:0};let n,i;if(o>0?(n=e[o-1],i=o<e.length-1?e[o+1]:e[0]):(n=e[e.length-1],i=e[o+1]),!n||!i)return console.warn("getTrashcanPoint: Could not determine previous/next points"),e[o]||{lat:0,lng:0};const a=n.lng<i.lng?n:i;return Wn.getMidPoint(e[o],a)}calculatePolygonArea(t){return Wn.getSqmArea(t)}calculatePolygonPerimeter(t){return Wn.getPerimeter(t)}}class Zn{constructor(t){i(this,"polygonInfoListeners",[]),i(this,"polygonDrawStateListeners",[]),i(this,"polygonInformationStorage",[]),this.mapStateService=t}onPolygonInfoUpdated(t){this.polygonInfoListeners.push(t)}emitPolygonInfoUpdated(){for(const t of this.polygonInfoListeners)t(this.polygonInformationStorage)}onPolygonDrawStateUpdated(t){this.polygonDrawStateListeners.push(t)}updatePolygons(){const t=[];this.polygonInformationStorage.length>0&&this.polygonInformationStorage.forEach(e=>{const r=[];e.polygon.forEach(t=>{t.forEach(t=>{const e=[...t];t.length>0&&t[0].toString()!==t[t.length-1].toString()&&e.push(t[0]),r.push(e)})}),t.push(r)}),this.mapStateService.updatePolygons(t),this.saveCurrentState()}saveCurrentState(){this.emitPolygonInfoUpdated()}deleteTrashcan(t){const e=this.polygonInformationStorage.findIndex(e=>e.polygon[0]===t);-1!==e&&(this.polygonInformationStorage.splice(e,1),this.updatePolygons())}deleteTrashCanOnMulti(t){let e=0;this.polygonInformationStorage.forEach((r,o)=>{const n=r.polygon.findIndex(e=>e.toString()===t.toString());n>=0&&(e=o,r.trashcanPoint.splice(n,1),r.sqmArea.splice(n,1),r.perimeter.splice(n,1),r.polygon.splice(n,1))}),this.updatePolygons(),this.polygonInformationStorage.length>1&&this.polygonInformationStorage.splice(e,1)}deletePolygonInformationStorage(){this.polygonInformationStorage=[]}createPolygonInformationStorage(t){t.length>0&&(t.forEach(t=>{var e;const r=null==(e=t.getLayers)?void 0:e.call(t);if(null==r?void 0:r[0]){const t=r[0].getLatLngs(),e=new Jn(t);this.polygonInformationStorage.push(e)}}),this.updatePolygons())}}class Qn{constructor(){i(this,"map",null),i(this,"mapListeners",[])}onMapUpdated(t){this.map&&t(this.map),this.mapListeners.push(t)}emitMapUpdated(){if(this.map)for(const t of this.mapListeners)t(this.map)}updateMapState(t){this.map=t,this.emitMapUpdated()}updatePolygons(t){}}class ti{constructor(){i(this,"eventListeners",new Map)}on(t,e){this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e)}off(t,e){const r=this.eventListeners.get(t);if(r){const t=r.indexOf(e);t>-1&&r.splice(t,1)}}emit(t,e){var r;this.eventListeners.has(t)&&(null==(r=this.eventListeners.get(t))||r.forEach(t=>{t(e)}))}}class ei{constructor(t,e){i(this,"state"),i(this,"config"),i(this,"eventManager"),this.config=t,this.eventManager=e,this.state=this.createInitialState()}createInitialState(){return{polygonDragging:this.config.modes.dragPolygons??!1,markerDragging:this.config.modes.dragElbow??!1,edgeClicking:!0,polygonClicking:!0,canStartDrawing:!0,canCompletePolygon:!1,mapDragging:!0,mapZooming:!0,mapDoubleClickZoom:!0,currentMode:c.Off,isDrawingActive:!1,isModifierKeyHeld:!1,showCrosshairCursor:!1,showDragCursor:!1}}updateStateForMode(t){switch(this.state.currentMode=t,t){case c.Off:this.setOffModeState();break;case c.Add:case c.Subtract:this.setDrawingModeState();break;case c.PointToPoint:case c.PointToPointSubtract:this.setPointToPointModeState();break;case c.Clone:this.setCloneModeState()}this.state.isDrawingActive=t!==c.Off&&t!==c.Clone,this.eventManager.emit("polydraw:mode:change",{mode:t})}setOffModeState(){this.state.polygonDragging=this.config.modes.dragPolygons??!1,this.state.markerDragging=this.config.modes.dragElbow??!1,this.state.edgeClicking=!0,this.state.polygonClicking=!0,this.state.canStartDrawing=!0,this.state.canCompletePolygon=!1,this.state.mapDragging=!0,this.state.mapZooming=!0,this.state.mapDoubleClickZoom=!0,this.state.showCrosshairCursor=!1,this.state.showDragCursor=!1}setDrawingModeState(){this.state.polygonDragging=!1,this.state.markerDragging=!1,this.state.edgeClicking=!1,this.state.polygonClicking=!1,this.state.canStartDrawing=!0,this.state.canCompletePolygon=!0,this.state.mapDragging=!1,this.state.mapZooming=!1,this.state.mapDoubleClickZoom=!1,this.state.showCrosshairCursor=!0,this.state.showDragCursor=!1}setPointToPointModeState(){this.state.polygonDragging=!1,this.state.markerDragging=!1,this.state.edgeClicking=!1,this.state.polygonClicking=!1,this.state.canStartDrawing=!0,this.state.canCompletePolygon=!0,this.state.mapDragging=!1,this.state.mapZooming=!1,this.state.mapDoubleClickZoom=!1,this.state.showCrosshairCursor=!0,this.state.showDragCursor=!1}setCloneModeState(){this.state.polygonDragging=this.config.tools.clone??!1,this.state.markerDragging=!1,this.state.edgeClicking=!1,this.state.polygonClicking=!1,this.state.canStartDrawing=!1,this.state.canCompletePolygon=!1,this.state.mapDragging=!0,this.state.mapZooming=!0,this.state.mapDoubleClickZoom=!0,this.state.showCrosshairCursor=!1,this.state.showDragCursor=!0}setModifierKeyState(t){this.state.isModifierKeyHeld=t,this.state.currentMode,c.Off}canPerformAction(t){switch(t){case"polygonDrag":return this.state.polygonDragging;case"markerDrag":return this.state.markerDragging;case"edgeClick":return this.state.edgeClicking;case"polygonClick":return this.state.polygonClicking;case"startDrawing":return this.state.canStartDrawing;case"completePolygon":return this.state.canCompletePolygon;case"mapDrag":return this.state.mapDragging;case"mapZoom":return this.state.mapZooming;case"mapDoubleClickZoom":return this.state.mapDoubleClickZoom;default:return!1}}isInDrawingMode(){return this.state.isDrawingActive}isInOffMode(){return this.state.currentMode===c.Off}getCurrentMode(){return this.state.currentMode}getState(){return{...this.state}}shouldShowCrosshairCursor(){return this.state.showCrosshairCursor}shouldShowDragCursor(){return this.state.showDragCursor}updateConfig(t){this.config=t,this.updateStateForMode(this.state.currentMode)}}class ri{constructor(t){i(this,"turfHelper"),i(this,"map"),i(this,"config"),i(this,"modeManager"),i(this,"eventManager"),i(this,"tracer"),i(this,"p2pMarkers",[]),i(this,"isModifierKeyHeld",!1),i(this,"markerModifierHandlers",new WeakMap),this.turfHelper=t.turfHelper,this.map=t.map,this.config=t.config,this.modeManager=t.modeManager,this.eventManager=t.eventManager,this.tracer=t.tracer}mouseMove(t){if("latlng"in t&&t.latlng)this.tracer.addLatLng(t.latlng);else if("touches"in t&&t.touches&&t.touches.length>0){const e=this.map.getContainer().getBoundingClientRect(),r=this.map.containerPointToLatLng([t.touches[0].clientX-e.x,t.touches[0].clientY-e.y]);this.tracer.addLatLng(r)}}async mouseUpLeave(t){const e=this.tracer.toGeoJSON();if(!e||!e.geometry||!e.geometry.coordinates||e.geometry.coordinates.length<3)return{success:!1,error:"Not enough points to form a valid polygon. Event: "+JSON.stringify(t)};let r;try{r=this.turfHelper.createPolygonFromTrace(e)}catch(o){return{success:!1,error:(o instanceof Error?o.message:"Failed to create polygon from trace")+". Event: "+JSON.stringify(t)}}return r&&r.geometry&&r.geometry.coordinates&&0!==r.geometry.coordinates.length?(this.eventManager.emit("polydraw:polygon:created",{polygon:r,mode:this.modeManager.getCurrentMode()}),{success:!0,polygon:r}):{success:!1,error:"Invalid polygon created from trace. Event: "+JSON.stringify(t)}}setModifierKey(t){this.isModifierKeyHeld=t}shouldAllowP2PMarkerDeletion(){if(!this.isModifierKeyHeld||!this.config.modes.edgeDeletion)return!1;if(this.config.modifierSubtractMode){const t=this.modeManager.getCurrentMode();if(t===c.PointToPoint||t===c.PointToPointSubtract)return!1}return!0}handlePointToPointClick(t){if(t){if(this.p2pMarkers.length>=3){const e=this.p2pMarkers[0].getLatLng();if(this.isClickingFirstPoint(t,e))return void this.completePointToPointPolygon()}try{const e=this.isTouchDevice(),r=0===this.p2pMarkers.length,o=r?"leaflet-polydraw-p2p-marker leaflet-polydraw-p2p-first-marker":"leaflet-polydraw-p2p-marker",n=r?e?[24,24]:[20,20]:e?[18,18]:[16,16],i=new s.Marker(t,{icon:Yn.createDivIcon({className:o,iconSize:n}),draggable:this.config.modes.dragElbow}).addTo(this.map);i.on("mousedown",t=>{s.DomEvent.stopPropagation(t)}),i.on("drag",()=>{this.updateP2PTracer()}),i.on("click",t=>{this.shouldAllowP2PMarkerDeletion()&&(this.deleteP2PMarker(i),s.DomEvent.stopPropagation(t))}),i.on("mouseover",()=>this.onMarkerHoverForEdgeDeletion(i,!0)),i.on("mouseout",()=>this.onMarkerHoverForEdgeDeletion(i,!1)),r&&(i.on("mouseover",()=>{if(this.p2pMarkers.length>=3){const t=i.getElement();t&&(t.style.backgroundColor=this.config.styles.ui.p2pClosingMarker.color,t.style.borderColor=this.config.styles.ui.p2pClosingMarker.color,t.style.cursor="pointer",t.title="Click to close polygon")}}),i.on("mouseout",()=>{const t=i.getElement();t&&(t.style.backgroundColor="",t.style.borderColor="",t.style.cursor="",t.title="")}),i.on("click",t=>{if(this.shouldAllowP2PMarkerDeletion())return this.deleteP2PMarker(i),void s.DomEvent.stopPropagation(t);this.p2pMarkers.length>=3&&(s.DomEvent.stopPropagation(t),this.completePointToPointPolygon())})),this.p2pMarkers.push(i),this.updateP2PTracer(),this.updateFirstMarkerReadyState()}catch{}}}handleDoubleClick(t){this.modeManager.getCurrentMode()!==c.PointToPoint&&this.modeManager.getCurrentMode()!==c.PointToPointSubtract||this.p2pMarkers.length>=3&&this.completePointToPointPolygon()}handleDoubleTap(t){this.modeManager.getCurrentMode()!==c.PointToPoint&&this.modeManager.getCurrentMode()!==c.PointToPointSubtract||this.p2pMarkers.length>=3&&this.completePointToPointPolygon()}completePointToPointPolygon(){const t=this.p2pMarkers.map(t=>t.getLatLng());if(t.length<3)return;const e=[...t],r=t[0],o=t[t.length-1];r.lat===o.lat&&r.lng===o.lng||e.push(r);try{const t=e.map(t=>[t.lng,t.lat]),r=this.turfHelper.getMultiPolygon([[t]]);this.clearP2pMarkers(),this.resetTracer(),this.eventManager.emit("polydraw:polygon:created",{polygon:r,mode:this.modeManager.getCurrentMode(),isPointToPoint:!0})}catch(n){_n()||console.warn("Error completing point-to-point polygon:",n),this.clearP2pMarkers(),this.resetTracer()}}cancelPointToPointDrawing(){this.clearP2pMarkers(),this.resetTracer(),this.eventManager.emit("polydraw:draw:cancel",{mode:c.PointToPoint})}clearP2pMarkers(){this.p2pMarkers.forEach(t=>{this.detachMarkerModifierHandler(t);try{this.map.removeLayer(t)}catch{}}),this.p2pMarkers=[]}resetTracer(){this.tracer.setLatLngs([]);try{this.tracer.setStyle({dashArray:void 0})}catch{}}isClickingFirstPoint(t,e){if(!e)return!1;const r=this.map.latLngToLayerPoint(t),o=this.map.latLngToLayerPoint(e);return r.distanceTo(o)<=(this.isTouchDevice()?36:12)}isTouchDevice(){return Tn()}updateP2PTracer(){const t=this.p2pMarkers.map(t=>t.getLatLng());if(this.tracer.setLatLngs(t),this.p2pMarkers.length>=2)try{const t=this.modeManager.getCurrentMode()===c.PointToPointSubtract?this.config.styles.subtractLine.color:this.config.styles.polyline.color;this.tracer.setStyle({color:t,dashArray:"5, 5"})}catch{}else try{this.tracer.setStyle({dashArray:void 0})}catch{}}deleteP2PMarker(t){const e=this.p2pMarkers.findIndex(e=>e===t);if(e>-1){this.p2pMarkers.splice(e,1),this.detachMarkerModifierHandler(t);try{this.map.removeLayer(t)}catch{}this.updateP2PTracer(),0===e&&this.p2pMarkers.length>0&&this.setupFirstMarker(),this.updateFirstMarkerReadyState()}}getP2pMarkers(){return[...this.p2pMarkers]}isInPointToPointMode(){const t=this.modeManager.getCurrentMode();return t===c.PointToPoint||t===c.PointToPointSubtract}getTracerPointsCount(){return this.tracer.getLatLngs().length}setupFirstMarker(){if(0===this.p2pMarkers.length)return;const t=this.p2pMarkers[0],e=t.getElement();e&&(e.classList.add("leaflet-polydraw-p2p-first-marker"),e.classList.remove("leaflet-polydraw-p2p-first-marker-ready"),t.setIcon(Yn.createDivIcon({className:"leaflet-polydraw-p2p-marker leaflet-polydraw-p2p-first-marker",iconSize:[20,20]}))),t.off("mouseover"),t.off("mouseout"),t.off("click"),t.on("mouseover",()=>{if(this.p2pMarkers.length>=3){const e=t.getElement();e&&(e.style.cursor="pointer",e.title="Click to close polygon")}}),t.on("mouseout",()=>{const e=t.getElement();e&&(e.style.backgroundColor="",e.style.borderColor="",e.style.cursor="",e.title="")}),t.on("click",e=>{if(this.shouldAllowP2PMarkerDeletion())return this.deleteP2PMarker(t),void s.DomEvent.stopPropagation(e);this.p2pMarkers.length>=3&&(s.DomEvent.stopPropagation(e),this.completePointToPointPolygon())})}updateFirstMarkerReadyState(){if(0===this.p2pMarkers.length)return;const t=this.p2pMarkers[0].getElement();t&&(this.p2pMarkers.length>=3?(t.classList.add("leaflet-polydraw-p2p-first-marker-ready"),t.setAttribute("data-p2p-mode",this.modeManager.getCurrentMode()===c.PointToPointSubtract?"subtract":"add"),t.style.cursor="pointer",t.title="Click to close polygon"):(t.classList.remove("leaflet-polydraw-p2p-first-marker-ready"),t.removeAttribute("data-p2p-mode"),t.style.cursor="",t.removeAttribute("title")))}refreshP2PMarkerState(){0!==this.p2pMarkers.length&&this.updateFirstMarkerReadyState()}onMarkerHoverForEdgeDeletion(t,e){const r=t.getElement();if(r)if(e){this.detachMarkerModifierHandler(t);const e=t=>{if(this.shouldAllowP2PMarkerDeletion()){r.classList.add("edge-deletion-hover");try{this.map.getContainer().style.cursor="pointer"}catch{}}else{r.classList.remove("edge-deletion-hover");try{this.map.getContainer().style.cursor=""}catch{}}};this.markerModifierHandlers.set(t,e),document.addEventListener("keydown",e),document.addEventListener("keyup",e),r.addEventListener("mousemove",e)}else{r.classList.remove("edge-deletion-hover");try{this.map.getContainer().style.cursor=""}catch{}this.detachMarkerModifierHandler(t)}}detachMarkerModifierHandler(t){const e=this.markerModifierHandlers.get(t);if(!e)return;document.removeEventListener("keydown",e),document.removeEventListener("keyup",e);const r=t.getElement();r&&(r.removeEventListener("mousemove",e),r.classList.remove("edge-deletion-hover")),this.markerModifierHandlers.delete(t)}}class oi{constructor(t){i(this,"turfHelper"),i(this,"config"),this.turfHelper=t.turfHelper,this.config=t.config}checkPolygonIntersection(t,e){if(this.isPolygonInsideHole(t,e)||this.isPolygonInsideHole(e,t))return!1;try{const r=this.turfHelper.isPolygonCompletelyWithin(t,e),o=this.turfHelper.isPolygonCompletelyWithin(e,t);if(r||o)return!0}catch{}try{if(this.turfHelper.polygonIntersect(t,e))return!0}catch{}try{const r=this.turfHelper.getIntersection(t,e);if(r&&r.geometry&&("Polygon"===r.geometry.type||"MultiPolygon"===r.geometry.type)){if(this.turfHelper.getPolygonArea(r)>1e-6)return!0}}catch{}try{const r=this.turfHelper.getCoords(t),o=this.turfHelper.getCoords(e);for(const e of o)for(const r of e[0]){const e={type:"Feature",geometry:{type:"Point",coordinates:r},properties:{}};if(this.turfHelper.isPointInsidePolygon(e,t))return!0}for(const t of r)for(const r of t[0]){const t={type:"Feature",geometry:{type:"Point",coordinates:r},properties:{}};if(this.turfHelper.isPointInsidePolygon(t,e))return!0}}catch{}return!1}isPolygonInsideHole(t,e){try{const r=this.turfHelper.getCoords(e);for(const e of r){if(!e||e.length<=1)continue;const r=e.slice(1);for(const e of r)try{const r=this.turfHelper.createPolygon([e]);if(this.turfHelper.isPolygonCompletelyWithin(t,r))return!0}catch{continue}}}catch{}return!1}unionPolygons(t,e){try{let r=e;for(const e of t){const t=this.turfHelper.union(r,e);t&&(r=t)}return{success:!0,result:r}}catch(r){return{success:!1,error:r instanceof Error?r.message:"Unknown error in unionPolygons"}}}subtractPolygon(t,e){try{const r=this.turfHelper.polygonDifference(t,e);if(r){const t=this.turfHelper.getCoords(r),e=[];for(const r of t)e.push(this.turfHelper.getMultiPolygon([r]));return{success:!0,results:e}}return{success:!0,results:[]}}catch(r){return{success:!1,error:r instanceof Error?r.message:"Unknown error in subtractPolygon"}}}simplifyPolygon(t){var e,r;try{const o=this.turfHelper.getCoords(t);if(!o||0===o.length)return{success:!1,error:"Invalid polygon coordinates"};const n=(null==(r=null==(e=this.config.polygonTools)?void 0:e.simplify)?void 0:r.processHoles)??!0,i=o.map(t=>{const e=[];for(let r=0;r<t.length;r++){const o=t[r];if(0===r||n){if(o.length<=4){e.push(o);continue}const t=[];for(let e=0;e<o.length;e+=2)t.push(o[e]);const r=t[0],n=t[t.length-1];r[0]===n[0]&&r[1]===n[1]||t.push(r),t.length<4?e.push(o):e.push(t)}else e.push(o)}return e}),a=this.turfHelper.getMultiPolygon(i);return{success:!0,result:this.turfHelper.getTurfPolygon(a)}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error in simplifyPolygon"}}}convertToBoundingBox(t){var e,r,o,n;try{const i=this.turfHelper.getCoords(t);if(!i||0===i.length)return{success:!1,error:"Invalid polygon coordinates"};if(!((null==(r=null==(e=this.config.polygonTools)?void 0:e.bbox)?void 0:r.processHoles)??!0)){const e=this.turfHelper.convertToBoundingBoxPolygon(t);return{success:!0,result:this.turfHelper.getTurfPolygon(e)}}const a=i.map(t=>{const e=[];for(let r=0;r<t.length;r++){const o=t[r];let n=1/0,i=-1/0,a=1/0,s=-1/0;for(const t of o)if(Array.isArray(t)&&t.length>=2){const e=t[0],r=t[1];"number"!=typeof e||"number"!=typeof r||isNaN(e)||isNaN(r)||(a=Math.min(a,e),s=Math.max(s,e),n=Math.min(n,r),i=Math.max(i,r))}if(n!==1/0&&i!==-1/0&&a!==1/0&&s!==-1/0){const t=[[a,n],[a,i],[s,i],[s,n],[a,n]];e.push(t)}else e.push(o)}return e}),s=this.turfHelper.getMultiPolygon(a);let l=this.turfHelper.getTurfPolygon(s);if(null==(n=null==(o=this.config.polygonTools)?void 0:o.bbox)?void 0:n.addMidPointMarkers){const t=this.doubleElbowsPolygon(l);t.success&&t.result&&(l=t.result)}return{success:!0,result:l}}catch(i){return{success:!1,error:i instanceof Error?i.message:"Unknown error in convertToBoundingBox"}}}bezierifyPolygon(t){try{const e=this.turfHelper.getCoords(t),r=this.turfHelper.getBezierMultiPolygon(e);return{success:!0,result:this.turfHelper.getTurfPolygon(r)}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Unknown error in bezierifyPolygon"}}}doubleElbowsPolygon(t){var e,r;try{const o=this.turfHelper.getCoords(t);if(!o||0===o.length)return{success:!1,error:"Invalid polygon coordinates"};const n=(null==(r=null==(e=this.config.polygonTools)?void 0:e.doubleElbows)?void 0:r.processHoles)??!0,i=o.map(t=>{const e=[];for(let r=0;r<t.length;r++){const o=t[r];if(0===r||n){const t=o.map(t=>({lat:t[1],lng:t[0]})),r=this.turfHelper.getDoubleElbowLatLngs(t).map(t=>[t.lng,t.lat]);e.push(r)}else e.push(o)}return e}),a=this.turfHelper.getMultiPolygon(i);return{success:!0,result:this.turfHelper.getTurfPolygon(a)}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Unknown error in doubleElbowsPolygon"}}}}class ni{static createDivIcon(t){const e=t.join(" ");return Yn.createDivIcon({className:e})}}class ii{static normalizeEvent(t){return Xn.getVersion()===l.V2&&(t.layer&&!t.propagatedFrom&&(t.propagatedFrom=t.layer),"mousedown"!==t.type&&"touchstart"!==t.type||(t._isPointerEvent=!0)),t}static getEventName(t){if(Xn.getVersion()===l.V2)switch(t){case"mousedown":case"touchstart":return"pointerdown";case"mouseup":case"touchend":return"pointerup";case"mousemove":case"touchmove":return"pointermove";default:return t}return t}static shouldUsePointerEvents(){return Xn.getVersion()===l.V2&&"PointerEvent"in window}static extractCoordinates(t,e){if(t.latlng)return t.latlng;if(t.touches&&t.touches.length>0){const r=e.getContainer().getBoundingClientRect();return e.containerPointToLatLng([t.touches[0].clientX-r.x,t.touches[0].clientY-r.y])}if(t.pointerType&&void 0!==t.clientX&&void 0!==t.clientY){const r=e.getContainer().getBoundingClientRect();return e.containerPointToLatLng([t.clientX-r.x,t.clientY-r.y])}if(void 0!==t.clientX&&void 0!==t.clientY){const r=e.getContainer().getBoundingClientRect();return e.containerPointToLatLng([t.clientX-r.x,t.clientY-r.y])}return null}static shouldPreventDefault(t){return!(!t.type||!t.type.startsWith("touch"))||(!t.pointerType||!1!==t.isPrimary)&&!(!("cancelable"in t)||!t.cancelable)}static getEventNames(){return Xn.getVersion()===l.V2&&this.shouldUsePointerEvents()?{start:["pointerdown"],move:["pointermove"],end:["pointerup"]}:{start:["mousedown","touchstart"],move:["mousemove","touchmove"],end:["mouseup","touchend"]}}}var ai=(t=>(t.TopLeft="top-left",t.Top="top",t.TopRight="top-right",t.Right="right",t.BottomRight="bottom-right",t.Bottom="bottom",t.BottomLeft="bottom-left",t.Left="left",t.Rotate="rotate",t.Pivot="pivot",t))(ai||{});class si{constructor(t,e,r,o,n){var a;i(this,"map"),i(this,"pane"),i(this,"root"),i(this,"draggingHandle",null),i(this,"documentMoveHandler",null),i(this,"documentUpHandler",null),i(this,"pointerCaptureTarget",null),i(this,"activePointerId",null),i(this,"callbacks"),i(this,"rafId",null),i(this,"mode"),i(this,"onCancel"),i(this,"onConfirm"),i(this,"cancelBtn",null),i(this,"confirmBtn",null),i(this,"currentBBox",null),i(this,"currentRotation",0),i(this,"buttonsHidden",!1),i(this,"destroyed",!1),i(this,"supportsPointerEvents","undefined"!=typeof window&&"PointerEvent"in window),this.map=t,this.callbacks=e,this.mode=r,this.onCancel=o,this.onConfirm=n;const s="polydraw-transform",l=this.map;let c=null==(a=l.getPane)?void 0:a.call(l,s);c||(c=this.map.createPane(s)),c.style.zIndex="650",c.style.pointerEvents="auto",this.pane=c,this.root=document.createElement("div"),this.root.className="polydraw-transform-root",this.root.style.position="absolute",this.root.style.left="0px",this.root.style.top="0px",this.root.style.pointerEvents="none",this.pane.appendChild(this.root)}destroy(){this.destroyed||(this.destroyed=!0,null!=this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.draggingHandle=null,this.detachDocumentDragHandlers(),this.root.remove())}update(t,e,r=0){this.destroyed||null==this.rafId&&(this.rafId=requestAnimationFrame(()=>{if(this.rafId=null,!this.destroyed&&(this.render(t,e,r),this.cancelBtn||this.confirmBtn)){this.draggingHandle===ai.Rotate&&"rotate"===this.mode||this.updateButtonPositions(t,r)}}))}render(t,e,r=0){const o=this.cancelBtn,n=this.confirmBtn;this.root.innerHTML="",this.currentBBox=t,this.currentRotation=r,this.cancelBtn=o,this.confirmBtn=n;const i=t.maxX-t.minX,a=t.maxY-t.minY,l=t.minX+i/2,c=t.minY+a/2,h=document.createElement("div");h.className="polydraw-transform-box",Object.assign(h.style,{position:"absolute",left:`${l}px`,top:`${c}px`,width:`${i}px`,height:`${a}px`,marginLeft:-i/2+"px",marginTop:-a/2+"px",border:"1px dashed #2b90d9",pointerEvents:"none",transformOrigin:"center center",transform:`rotate(${180*r/Math.PI}deg)`}),this.root.appendChild(h);const u=(t,e,o)=>{const n=e-l,i=o-c,a=Math.cos(r),h=Math.sin(r),u=l+n*a-i*h,g=c+n*h+i*a,d=document.createElement("div");d.className=`polydraw-transform-handle handle-${t}`,Object.assign(d.style,{position:"absolute",left:u-5+"px",top:g-5+"px",width:"10px",height:"10px",borderRadius:"2px",background:"#2b90d9",boxShadow:"0 0 0 1px #fff",cursor:this.cursorForHandle(t),pointerEvents:"auto",touchAction:"none"}),this.supportsPointerEvents?s.DomEvent.on(d,"pointerdown",e=>this.startDrag(t,{x:u,y:g},e),this):(s.DomEvent.on(d,"mousedown",e=>this.startDrag(t,{x:u,y:g},e),this),s.DomEvent.on(d,"touchstart",e=>this.startDrag(t,{x:u,y:g},e),this)),this.root.appendChild(d)};"scale"===this.mode?(u(ai.TopLeft,t.minX,t.minY),u(ai.TopRight,t.maxX,t.minY),u(ai.BottomRight,t.maxX,t.maxY),u(ai.BottomLeft,t.minX,t.maxY),u(ai.Top,l,t.minY),u(ai.Right,t.maxX,c),u(ai.Bottom,l,t.maxY),u(ai.Left,t.minX,c)):(u(ai.Rotate,t.minX,t.minY),u(ai.Rotate,t.maxX,t.minY),u(ai.Rotate,t.maxX,t.maxY),u(ai.Rotate,t.minX,t.maxY)),this.cancelBtn||this.confirmBtn?(this.updateButtonPositions(t,r),this.cancelBtn&&this.root.appendChild(this.cancelBtn),this.confirmBtn&&this.root.appendChild(this.confirmBtn)):this.updateButtonPositions(t,r)}cursorForHandle(t){switch(t){case ai.Top:case ai.Bottom:return"ns-resize";case ai.Left:case ai.Right:return"ew-resize";case ai.TopLeft:case ai.BottomRight:return"nwse-resize";case ai.TopRight:case ai.BottomLeft:return"nesw-resize";case ai.Rotate:return"grab";case ai.Pivot:return"move";default:return"default"}}startDrag(t,e,r){var o,n;if(this.destroyed)return;s.DomEvent.stop(r),this.draggingHandle=t,this.hideButtons(),this.documentMoveHandler=t=>this.onDrag(t),this.documentUpHandler=t=>this.endDrag(t);const i=document,a=this.documentMoveHandler,l=this.documentUpHandler;if(this.supportsPointerEvents&&r instanceof PointerEvent){this.activePointerId=r.pointerId,this.pointerCaptureTarget=this.map.getContainer();try{null==(n=null==(o=this.pointerCaptureTarget)?void 0:o.setPointerCapture)||n.call(o,r.pointerId)}catch{}s.DomEvent.on(i,"pointermove",a),s.DomEvent.on(i,"pointerup",l),s.DomEvent.on(i,"pointercancel",l)}else s.DomEvent.on(i,"mousemove",a),s.DomEvent.on(i,"mouseup",l),s.DomEvent.on(i,"touchmove",a),s.DomEvent.on(i,"touchend",l),s.DomEvent.on(i,"touchcancel",l);this.callbacks.onStartHandleDrag(t,e,r)}onDrag(t){if(null==this.draggingHandle)return;const e=this.getMouseLayerPoint(t);this.callbacks.onDragHandle(this.draggingHandle,e,t)}endDrag(t){if(null==this.draggingHandle)return;const e=this.draggingHandle;this.draggingHandle=null;try{const r=this.getMouseLayerPoint(t);this.callbacks.onEndHandleDrag(e,r,t),this.currentBBox&&this.updateButtonPositions(this.currentBBox,this.currentRotation),this.showButtons()}finally{this.detachDocumentDragHandlers()}}detachDocumentDragHandlers(){var t,e;if(!this.documentMoveHandler&&!this.documentUpHandler&&!this.pointerCaptureTarget)return;const r=document;if(this.supportsPointerEvents&&this.pointerCaptureTarget){if(null!=this.activePointerId)try{null==(e=(t=this.pointerCaptureTarget).releasePointerCapture)||e.call(t,this.activePointerId)}catch{}if(this.documentMoveHandler){const t=this.documentMoveHandler;s.DomEvent.off(r,"pointermove",t)}if(this.documentUpHandler){const t=this.documentUpHandler;s.DomEvent.off(r,"pointerup",t),s.DomEvent.off(r,"pointercancel",t)}this.pointerCaptureTarget=null,this.activePointerId=null}else{if(this.documentMoveHandler){const t=this.documentMoveHandler;s.DomEvent.off(r,"mousemove",t),s.DomEvent.off(r,"touchmove",t)}if(this.documentUpHandler){const t=this.documentUpHandler;s.DomEvent.off(r,"mouseup",t),s.DomEvent.off(r,"touchend",t),s.DomEvent.off(r,"touchcancel",t)}}this.documentMoveHandler=null,this.documentUpHandler=null}getMouseLayerPoint(t){const e=this.map.getContainer();let r=null,o=null;if(t.touches&&t.touches.length>0){const e=t.touches[0];r=e.clientX,o=e.clientY}else if(t.changedTouches&&t.changedTouches.length>0){const e=t.changedTouches[0];r=e.clientX,o=e.clientY}else null!=t.clientX&&(r=t.clientX,o=t.clientY);null!=r&&null!=o||(r=0,o=0);const n=e.getBoundingClientRect(),i=r-n.left,a=o-n.top,s=Yn.createPoint(i,a),l=this.map.containerPointToLayerPoint(s);return{x:l.x,y:l.y}}updateButtonPositions(t,e){const r=t.maxX-t.minX,o=t.maxY-t.minY,n=t.minX+r/2,i=t.minY+o/2,a=[{x:t.minX,y:t.minY},{x:t.maxX,y:t.minY},{x:t.maxX,y:t.maxY},{x:t.minX,y:t.maxY}],l=Math.cos(e),c=Math.sin(e);let h={x:0,y:1/0},u=1/0;for(const s of a){const t=s.x-n,e=s.y-i,r=n+t*l-e*c,o=i+t*c+e*l,a=o<u,g=Math.abs(o-u)<1,d=r>h.x;(a||g&&d)&&(u=o,h={x:r,y:o})}const g=h.x,d=h.y-28,p=g+5,f=g-29;if(this.onCancel&&!this.cancelBtn&&(this.cancelBtn=document.createElement("div"),this.cancelBtn.className="polydraw-transform-cancel",this.cancelBtn.innerHTML='<?xml version="1.0" encoding="UTF-8"?>\n<svg width="512" height="512" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">\n <circle cx="256" cy="256" r="236" fill="#212A32"/>\n <circle cx="256" cy="256" r="190" fill="#ffffff"/>\n <path id="path2" fill="#800000" fill-rule="evenodd" stroke="none"\n d="M 156 373.906311 C 140.875 373.871002 127.9375 373.615112 127.25 373.337708 C 126.5625 373.060303 126 372.072937 126 371.143555 C 126 370.214203 146.628433 343.53772 171.840973 311.862488 C 197.053513 280.187286 217.991867 253.463562 218.370667 252.47644 C 218.806335 251.341125 218.221786 249.464233 216.779678 247.368073 C 215.525864 245.545563 196.612503 221.361847 174.75 193.626465 C 152.887497 165.891052 135 142.531311 135 141.715881 C 135 140.900421 136.012497 139.961914 137.25 139.63028 C 138.487503 139.298645 152.408203 139.021179 168.184906 139.013641 C 184.588272 139.005859 197.976456 139.420746 199.454529 139.982727 C 201.182831 140.639801 210.486664 152.319733 227.533463 175.232727 C 241.555283 194.079712 253.994949 210.166199 255.177185 210.980438 C 257.208252 212.379272 257.562622 212.186401 261.607452 207.480438 C 263.961853 204.74118 276.052643 189 288.47583 172.5 C 300.899048 156 312.286682 141.714874 313.781738 140.75528 C 316.198669 139.203949 319.554993 139.009949 344.058868 139.00528 C 366.27774 139.001007 371.993561 139.274811 373.557343 140.418274 C 375.458923 141.808746 375.448914 141.90155 373.046875 145.150452 C 371.699341 146.973114 352.828827 170.746307 331.112396 197.979767 C 309.395966 225.213257 291.465973 248.396271 291.267914 249.497589 C 291.012512 250.91803 304.435944 268.61731 337.453918 310.395416 C 363.05426 342.787903 384 370.077271 384 371.038422 C 384 371.999603 383.288208 373.059174 382.418213 373.393005 C 381.548218 373.726868 367.485718 373.993347 351.168213 373.98526 C 329.591888 373.974548 320.854309 373.633606 319.132629 372.73526 C 317.830597 372.055847 302.980591 353.049988 286.132629 330.5 C 260.059052 295.602051 255.12793 289.5 253 289.5 C 250.878326 289.5 245.808807 295.701355 219.5 330.479431 C 202.449997 353.018127 187.375 372.023987 186 372.714691 C 184.165009 373.636475 176.184906 373.95343 156 373.906311 Z"/>\n</svg>',s.DomEvent.on(this.cancelBtn,"mousedown",t=>{t.stopPropagation(),t.preventDefault(),this.onCancel&&this.onCancel()}),s.DomEvent.on(this.cancelBtn,"touchstart",t=>{t.stopPropagation(),t.preventDefault(),this.onCancel&&this.onCancel()}),s.DomEvent.on(this.cancelBtn,"pointerdown",t=>{t.stopPropagation(),t.preventDefault(),this.onCancel&&this.onCancel()}),this.root.appendChild(this.cancelBtn)),this.onConfirm&&!this.confirmBtn&&(this.confirmBtn=document.createElement("div"),this.confirmBtn.className="polydraw-transform-confirm",this.confirmBtn.innerHTML='<?xml version="1.0" encoding="UTF-8"?>\n<svg width="512" height="512" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">\n <circle cx="256" cy="256" r="236" fill="#212A32"/>\n <circle cx="256" cy="256" r="190" fill="#ffffff"/>\n <path id="check" fill="#008000" fill-rule="evenodd" stroke="none"\n d="M 223.844696 360 C 222.79425 360 204.506973 341.170593 178.987274 313.812744 \n C 144.992401 277.369232 135.966232 267.145691 136.201645 265.351257 \n C 136.396179 263.868408 143.092361 257.073425 155.444672 245.824249 \n C 166.363129 235.880859 175.214264 228.571442 176.336426 228.571442 \n C 177.515594 228.571442 181.716553 232.304138 186.987961 238.035706 \n C 191.775406 243.241058 201.629044 254.024994 208.884933 262 \n C 216.140823 269.975006 222.682266 276.635315 223.421478 276.80072 \n C 224.16246 276.966553 247.742722 250.494751 275.976837 217.800751 \n C 304.143097 185.185333 328.050385 157.879608 329.104156 157.121368 \n C 330.785767 155.911316 331.44046 156.0336 334.457672 158.121368 \n C 336.348328 159.429626 345.368622 167.190216 354.502747 175.367126 \n C 367.688812 187.171356 371.047394 190.689819 370.805115 192.445557 \n C 370.635864 193.67218 338.242889 231.469543 298.059082 277.32843 \n C 253.148834 328.581238 224.944153 360 223.844696 360 Z"/>\n</svg>',s.DomEvent.on(this.confirmBtn,"mousedown",t=>{t.stopPropagation(),t.preventDefault(),this.onConfirm&&this.onConfirm()}),s.DomEvent.on(this.confirmBtn,"touchstart",t=>{t.stopPropagation(),t.preventDefault(),this.onConfirm&&this.onConfirm()}),s.DomEvent.on(this.confirmBtn,"pointerdown",t=>{t.stopPropagation(),t.preventDefault(),this.onConfirm&&this.onConfirm()}),this.root.appendChild(this.confirmBtn)),this.cancelBtn){Object.assign(this.cancelBtn.style,{position:"absolute",left:`${f}px`,top:`${d}px`,display:"grid",placeItems:"center",pointerEvents:"auto",width:"28px",height:"28px"});const t=this.cancelBtn.querySelector("svg");t&&(t.setAttribute("width","24"),t.setAttribute("height","24")),this.cancelBtn.style.display=this.buttonsHidden?"none":"grid"}if(this.confirmBtn){Object.assign(this.confirmBtn.style,{position:"absolute",left:`${p}px`,top:`${d}px`,display:"grid",placeItems:"center",pointerEvents:"auto",width:"28px",height:"28px"});const t=this.confirmBtn.querySelector("svg");t&&(t.setAttribute("width","24"),t.setAttribute("height","24")),this.confirmBtn.style.display=this.buttonsHidden?"none":"grid"}}hideButtons(){this.buttonsHidden=!0,this.cancelBtn&&(this.cancelBtn.style.display="none"),this.confirmBtn&&(this.confirmBtn.style.display="none")}showButtons(){this.buttonsHidden=!1,this.cancelBtn&&(this.cancelBtn.style.display="grid"),this.confirmBtn&&(this.confirmBtn.style.display="grid")}}function li(t,e){const r=t.latLngToLayerPoint(e);return{x:r.x,y:r.y}}function ci(t,e){const r=t.layerPointToLatLng(Yn.createPoint(e.x,e.y));return{lat:r.lat,lng:r.lng}}function hi(t){let e=1/0,r=1/0,o=-1/0,n=-1/0;for(const i of t)for(const t of i)for(const i of t)i.x<e&&(e=i.x),i.y<r&&(r=i.y),i.x>o&&(o=i.x),i.y>n&&(n=i.y);return{minX:e,minY:r,maxX:o,maxY:n}}function ui(t){return{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2}}function gi(t,e,r,o){const n=t.x-e.x,i=t.y-e.y;return{x:e.x+n*r,y:e.y+i*o}}function di(t,e,r,o,n){return t.map(t=>t.map(t=>t.map(t=>function(t,e,r){const o=Math.cos(r),n=Math.sin(r),i=t.x-e.x,a=t.y-e.y;return{x:e.x+i*o-a*n,y:e.y+i*n+a*o}}(gi(t,e,r,o),e,n))))}function pi(t){if(0===t.length)return t;const e=t[0],r=t[t.length-1];return e.lat===r.lat&&e.lng===r.lng?t:[...t,{lat:e.lat,lng:e.lng}]}function fi(t){if(!Array.isArray(t))return[[t]];const e=t;return 0===e.length?[]:Array.isArray(e[0])?Array.isArray(e[0][0])?t:[t]:[[t]]}class yi{constructor(t,e,r="scale",o){var n,a;i(this,"map"),i(this,"polygon"),i(this,"overlay"),i(this,"state"),i(this,"normalizedLatLngs"),i(this,"wasMapDraggingEnabled",!1),i(this,"mode"),i(this,"onExit"),i(this,"rotateStartAngle",null),i(this,"rotateBaseRotation",0),i(this,"originalTouchAction",null),i(this,"mapDraggingHandler"),i(this,"onKeyDown",t=>{"Escape"===t.key&&this.handleCancel()}),i(this,"updateOverlay",()=>{const t=hi(this.state.originalPixelRings.map(t=>t.map(t=>t.map(t=>gi(t,this.state.pivot,this.state.scaleX,this.state.scaleY)))));this.overlay.update(t,this.state.pivot,this.state.rotation)}),this.map=t,this.mode=r,this.onExit=o;const l=e.getLayers().find(t=>t instanceof s.Polygon);if(!l)throw new Error("FeatureGroup does not contain a polygon");this.polygon=l;const c=this.polygon.getLatLngs();this.normalizedLatLngs=fi(c);const h=function(t,e){const r=[],o=[];for(const n of e){const e=[],i=[];for(const r of n){const o=r.map(e=>li(t,{lat:e.lat,lng:e.lng}));e.push(o),i.push(r.length)}r.push(e),o.push(i)}return{rings:r,ringLengths:o}}(this.map,this.normalizedLatLngs),u=ui(hi(h.rings));this.state={isActive:!0,originalLatLngs:c,originalPixelRings:h.rings,pivot:u,scaleX:1,scaleY:1,rotation:0,uniformScale:!1,snapRotation:!1,scaleFromPivot:!1},this.overlay=new si(this.map,{onStartHandleDrag:(t,e,r)=>this.onStartDrag(t,e,r),onDragHandle:(t,e)=>this.onDrag(t,e),onEndHandleDrag:()=>{}},this.mode,()=>this.handleCancel(),()=>this.handleConfirm()),this.updateOverlay(),this.map.on("zoom viewreset move",this.updateOverlay,this),this.mapDraggingHandler=this.map.dragging,this.mapDraggingHandler&&("function"==typeof this.mapDraggingHandler.enabled&&(this.wasMapDraggingEnabled=this.mapDraggingHandler.enabled()),null==(a=(n=this.mapDraggingHandler).disable)||a.call(n));const g=this.map.getContainer();this.originalTouchAction=g.style.touchAction||null,g.style.touchAction="none",document.addEventListener("keydown",this.onKeyDown)}destroy(){document.removeEventListener("keydown",this.onKeyDown),this.map.off("zoom viewreset move",this.updateOverlay,this),this.overlay.destroy(),this.state.isActive=!1,this.mapDraggingHandler&&this.wasMapDraggingEnabled&&"function"==typeof this.mapDraggingHandler.enable&&this.mapDraggingHandler.enable();const t=this.map.getContainer();null!==this.originalTouchAction?t.style.touchAction=this.originalTouchAction:t.style.touchAction=""}onStartDrag(t,e,r){const o=navigator.userAgent.toLowerCase().includes("mac")?r.metaKey:r.ctrlKey;if(this.state.uniformScale=!!r.shiftKey,this.state.scaleFromPivot=!!r.altKey,this.state.snapRotation=!!o,t===ai.Rotate){const t=this.state.scaleFromPivot?this.state.pivot:ui(hi(this.state.originalPixelRings)),r=Math.atan2(e.y-t.y,e.x-t.x);this.rotateStartAngle=r,this.rotateBaseRotation=this.state.rotation||0}}onDrag(t,e){const r=hi(this.state.originalPixelRings);switch(t){case ai.Rotate:{const t=this.state.scaleFromPivot?this.state.pivot:ui(r);this.handleRotateDrag(e,t);break}case ai.Pivot:this.handlePivotDrag(e);break;default:{const o=this.state.scaleFromPivot?this.state.pivot:ui(r);this.handleScaleDrag(t,e,r,o);break}}this.preview()}handleRotateDrag(t,e){if("rotate"!==this.mode)return;const r=Math.atan2(t.y-e.y,t.x-e.x);let o;if(null!=this.rotateStartAngle){const t=r-this.rotateStartAngle;o=this.rotateBaseRotation+t}else o=r;this.state.rotation=this.state.snapRotation?function(t,e=15){const r=e*Math.PI/180;return Math.round(t/r)*r}(o,15):o}handlePivotDrag(t){this.state.pivot=t}handleScaleDrag(t,e,r,o){if("scale"!==this.mode)return;const n=r.maxX-r.minX,i=r.maxY-r.minY;let a=this.state.scaleX,s=this.state.scaleY;switch(t){case ai.Left:case ai.TopLeft:case ai.BottomLeft:a=(o.x-e.x)/(o.x-r.minX||1);break;case ai.Right:case ai.TopRight:case ai.BottomRight:a=(e.x-o.x)/(r.maxX-o.x||1)}switch(t){case ai.Top:case ai.TopLeft:case ai.TopRight:s=(o.y-e.y)/(o.y-r.minY||1);break;case ai.Bottom:case ai.BottomLeft:case ai.BottomRight:s=(e.y-o.y)/(r.maxY-o.y||1)}if(t!==ai.Left&&t!==ai.Right||(s=this.state.scaleY),t!==ai.Top&&t!==ai.Bottom||(a=this.state.scaleX),this.state.uniformScale){const t=Math.abs(n)>Math.abs(i)?Math.sign(a)*Math.abs(a):Math.sign(s)*Math.abs(s);a=t,s=t}const l=Number.isFinite(a)&&Math.abs(a)>.001,c=Number.isFinite(s)&&Math.abs(s)>.001;l&&(this.state.scaleX=a),c&&(this.state.scaleY=s)}preview(){const t=di(this.state.originalPixelRings,this.state.pivot,this.state.scaleX,this.state.scaleY,this.state.rotation),e=function(t,e,r){const o=[];for(let n=0;n<e.length;n++){const i=[];for(let o=0;o<e[n].length;o++){const a=e[n][o].map(e=>ci(t,e)),s=r[n][o],l=s.length>2&&s[0].lat===s[s.length-1].lat&&s[0].lng===s[s.length-1].lng;i.push(l?pi(a):a)}o.push(i)}return o}(this.map,t,this.normalizedLatLngs);this.polygon.setLatLngs(e),this.updateOverlay()}apply(){return fi(this.polygon.getLatLngs())}cancel(){this.polygon.setLatLngs(this.state.originalLatLngs)}handleCancel(){this.cancel(),this.onExit&&this.onExit(!1),this.destroy()}handleConfirm(){this.onExit&&this.onExit(!0),this.destroy()}}class mi{static createMenuButton(t,e,r){const o=document.createElement("div");return o.classList.add("marker-menu-button",...r),o.title=e,o.setAttribute("data-action-id",t),o}static buildMenuPopup(t){const e=document.createElement("div");e.classList.add("alter-marker-outer-wrapper");const r=document.createElement("div");r.classList.add("alter-marker-wrapper");const o=document.createElement("button");o.type="button",o.className="marker-menu-close",o.setAttribute("aria-label","Close menu"),o.innerHTML="&times;",r.appendChild(o);const n=document.createElement("div");n.classList.add("content");const i=document.createElement("div");return i.classList.add("marker-menu-content"),t.forEach(t=>{i.appendChild(t)}),n.appendChild(i),r.appendChild(n),e.appendChild(r),e}static buildInfoPopup(t){const e=document.createElement("div");e.classList.add("info-marker-outer-wrapper");const r=document.createElement("div");r.classList.add("info-marker-wrapper");const o=document.createElement("div");return o.classList.add("content"),o.appendChild(t),r.appendChild(o),e.appendChild(r),e}}class vi{constructor(t,e){i(this,"markerFeatureGroupMap",new WeakMap),i(this,"polygonFeatureGroupMap",new WeakMap),i(this,"markerModifierHandlers",new WeakMap),i(this,"markerTouchListeners",new WeakMap),i(this,"markerEdgeDeletionListeners",new WeakMap),i(this,"_activeMarker",null),i(this,"isDraggingMarker",!1),i(this,"turfHelper"),i(this,"polygonInformation"),i(this,"map"),i(this,"config"),i(this,"modeManager"),i(this,"eventManager"),i(this,"saveHistoryState"),i(this,"layerManager"),i(this,"currentDragPolygon",null),i(this,"currentDragIsClone",!1),i(this,"currentModifierDragMode",!1),i(this,"isModifierKeyHeld",!1),i(this,"currentCloneGhost",null),i(this,"dragCancelHandlersAttached",!1),i(this,"_boundDragTouchMove",null),i(this,"_boundDragTouchEnd",null),i(this,"polygonTouchStartListeners",new WeakMap),i(this,"_openMenuPopup",null),i(this,"transformModeActive",!1),i(this,"transformControllers",new WeakMap),i(this,"deleteMarkerSuppressUntil",0),i(this,"onModeChange",()=>{(this.currentCloneGhost||this.isPolygonDragActive())&&this.cancelActivePolygonDrag()}),i(this,"getFeatureGroups"),i(this,"removeFeatureGroup"),i(this,"onPolygonMouseMove",t=>{if(!this.currentDragPolygon||!this.currentDragPolygon._polydrawDragData||!this.currentDragPolygon._polydrawDragData.isDragging)return;const e=this.currentDragPolygon,r=e._polydrawDragData;if(!this.currentDragIsClone){const e=t.originalEvent&&"metaKey"in t.originalEvent?t.originalEvent:t;this.detectDragSubtractModifierKey(e)!==this.currentModifierDragMode&&this.handleModifierToggleDuringDrag(e)}const o=r.startPosition,n=t.latlng,i=n.lat-o.lat,a=n.lng-o.lng,s=this.offsetPolygonCoordinates(r.startLatLngs,i,a);e.setLatLngs(s),this.updateMarkersAndHoleLinesDuringDrag(e,i,a)}),i(this,"onPolygonMouseUp",t=>{if(!this.currentDragPolygon||!this.currentDragPolygon._polydrawDragData||!this.currentDragPolygon._polydrawDragData.isDragging)return;const e=this.currentDragPolygon,r=e._polydrawDragData;r.isDragging=!1,this.map.off("mousemove",this.onPolygonMouseMove,this),this.map.off("mouseup",this.onPolygonMouseUp,this),this.map.off("pointermove",this.onPolygonMouseMove,this),this.map.off("pointerup",this.onPolygonMouseUp,this),this.map.dragging&&this.map.dragging.enable(),e._polydrawDragData&&null!=e._polydrawDragData.originalOpacity&&e.setStyle({fillOpacity:e._polydrawDragData.originalOpacity}),this.setMarkerVisibility(e,!0);try{this.map.getContainer().style.cursor=""}catch{}this.clearCloneGhost(),this.detachDragTouchListeners(),this.detachDragCancelHandlers();const o=this.currentDragIsClone;this.currentDragIsClone=!1,o?this.updatePolygonAfterCloneDrag(e,r):this.updatePolygonAfterDrag(e),e._polydrawOriginalMarkerPositions&&(e._polydrawOriginalMarkerPositions.clear(),delete e._polydrawOriginalMarkerPositions),e._polydrawOriginalHoleLinePositions&&(e._polydrawOriginalHoleLinePositions.clear(),delete e._polydrawOriginalHoleLinePositions),e._polydrawCurrentDragSession&&delete e._polydrawCurrentDragSession,this.currentDragPolygon=null}),i(this,"onPolygonDragCancel",()=>{this.cancelActivePolygonDrag()}),i(this,"onPolygonDragKeyDown",t=>{"Escape"===t.key&&this.cancelActivePolygonDrag()}),i(this,"onDragTouchMove",t=>{t.preventDefault();const e=ii.extractCoordinates(t,this.map);e&&this.onPolygonMouseMove({latlng:e})}),i(this,"onDragTouchEnd",t=>{t.preventDefault(),this.onPolygonMouseUp({latlng:null})}),i(this,"onMarkerHoverForEdgeDeletionEvent",t=>{if(!this.isModifierKeyHeld)return;const e=t.target;e&&(e.style.backgroundColor=this.config.styles.ui.edgeDeletion.color,e.style.borderColor=this.config.styles.ui.edgeDeletion.color,e.classList.add("edge-deletion-hover"))}),i(this,"onMarkerLeaveForEdgeDeletionEvent",t=>{const e=t.target;e&&(e.style.backgroundColor="",e.style.borderColor="",e.classList.remove("edge-deletion-hover"))}),this.turfHelper=t.turfHelper,this.polygonInformation=t.polygonInformation,this.map=t.map,this.config=t.config,this.modeManager=t.modeManager,this.eventManager=t.eventManager,this.saveHistoryState=t.saveHistoryState,this.layerManager=t.layerManager,this.getFeatureGroups=e.getFeatureGroups,this.removeFeatureGroup=e.removeFeatureGroup,this.eventManager.on("polydraw:mode:change",this.onModeChange)}emitPolygonUpdated(t){const e=this.getHistoryActionForOperation(t.operation);e&&this.saveHistoryState&&this.saveHistoryState(e),this.eventManager.emit("polydraw:polygon:updated",t)}getHistoryActionForOperation(t){switch(t){case"addVertex":case"removeVertex":case"removeHole":case"toggleOptimization":return t;case"modifierSubtract":case"modifierSubtractFallback":return"modifierSubtract";default:return null}}dispose(){this.eventManager.off("polydraw:mode:change",this.onModeChange),this.cancelActivePolygonDrag()}getTimestamp(){return"undefined"!=typeof performance&&"function"==typeof performance.now?performance.now():Date.now()}shouldSuppressDeleteMarkerClick(){return this.getTimestamp()<this.deleteMarkerSuppressUntil}suppressDeleteMarkerClicks(t){this.deleteMarkerSuppressUntil=this.getTimestamp()+Math.max(0,t)}addMarkers(t,e,r={}){this.registerPolygonLayerMappings(e);let o=this.getMarkerIndex(t,this.config.markers.markerMenuIcon.position),n=this.getMarkerIndex(t,this.config.markers.markerDeleteIcon.position),i=this.getMarkerIndex(t,this.config.markers.markerInfoIcon.position);const a=this.ensureMarkerSeparation(t.length,{menu:{index:o,enabled:this.config.markers.menuMarker},delete:{index:n,enabled:this.config.markers.deleteMarker},info:{index:i,enabled:this.config.markers.infoMarker}});o=a.menu,n=a.delete,i=a.info;const l=r.optimizationLevel??0,c=this.deriveImportantMarkerIndices(t,{menuIndex:o,deleteIndex:n,infoIndex:i,optimizationLevel:l}),h=t.length>2&&this.latLngEquals(t[0],t[t.length-1]);t.forEach((r,a)=>{let u=this.config.markers.markerIcon.styleClasses;a===o&&this.config.markers.menuMarker&&(u=this.config.markers.markerMenuIcon.styleClasses),a===n&&this.config.markers.deleteMarker&&(u=this.config.markers.markerDeleteIcon.styleClasses),a===i&&this.config.markers.infoMarker&&(u=this.config.markers.markerInfoIcon.styleClasses);const g=Array.isArray(u)?u:[u],d=a===o&&this.config.markers.menuMarker||a===n&&this.config.markers.deleteMarker||a===i&&this.config.markers.infoMarker,p=this.normalizeMarkerIndex(a,t.length,h),f=[...g];l<=0||null===p||c.has(p)||d||f.push("polygon-marker-faded");const y=new s.Marker(r,{icon:this.createDivIcon(f),draggable:this.config.modes.dragElbow,title:this.config.markers.coordsTitle?this.getLatLngInfoString(r):"",zIndexOffset:this.config.markers.markerIcon.zIndexOffset??this.config.markers.zIndexOffset});e.addLayer(y),this.markerFeatureGroupMap.set(y,e),y.on("add",()=>{const t=y.getElement();t&&(t.style.pointerEvents="auto")}),y.on("click",t=>{var e,r;this.isDraggingMarker&&(null==(r=null==(e=t.originalEvent)?void 0:e.stopPropagation)||r.call(e),s.DomEvent.stopPropagation(t))}),y.on("dragstart",()=>{const t=this.markerFeatureGroupMap.get(y);!t||this.isFeatureGroupInActiveLayer(t)?(this.saveHistoryState&&this.saveHistoryState("markerDrag"),this.isDraggingMarker=!0,this._activeMarker=y):y.dragging&&y.dragging.disable()}),y.on("dragend",t=>{const e=this.markerFeatureGroupMap.get(y);if(e&&!this.isFeatureGroupInActiveLayer(e))return this._activeMarker=null,void(this.isDraggingMarker=!1);this.modeManager.canPerformAction("markerDrag")&&e&&this.markerDragEnd(e),this._activeMarker=null,s.DomEvent.stopPropagation(t),setTimeout(()=>{this.isDraggingMarker=!1},10)});const m=y.getElement();if(m){const t=t=>{t.stopPropagation()},e=t=>{if(t.preventDefault(),t.stopPropagation(),y.fire("click"),this.isDraggingMarker&&!d){const t=this.markerFeatureGroupMap.get(y);this.modeManager.canPerformAction("markerDrag")&&t&&this.isFeatureGroupInActiveLayer(t)&&this.markerDragEnd(t)}this._activeMarker=null};m.addEventListener("touchstart",t,{passive:!0}),m.addEventListener("touchend",e),this.markerTouchListeners.set(y,{touchstart:t,touchend:e})}if(a===o||a===n||a===i){const t=y.getElement();t&&(t.style.zIndex="10000")}if(this.config.modes.dragElbow){const t=t=>()=>{this.modeManager.canPerformAction("markerDrag")&&this.isFeatureGroupInActiveLayer(t)&&this.markerDrag(t)};y.on("drag",t(e))}if(a===o&&this.config.markers.menuMarker&&(y.options.zIndexOffset=this.config.markers.markerMenuIcon.zIndexOffset??this.config.markers.zIndexOffset,y.on("click",()=>{if(!this.isFeatureGroupInActiveLayer(e))return;const r=this.getPolygonGeoJSONFromFeatureGroup(e),n=Wn.getCenterOfPolygonByIndexWithOffsetFromCenterOfMass(r,o);this.generateMenuMarkerPopup(t,e).setLatLng(n).openOn(this.map)}),y.on("popupopen",t=>{const e=t.popup.getElement();if(!e)return;setTimeout(()=>{const t=this.map.getContainer(),r=e.getBoundingClientRect(),o=t.getBoundingClientRect();let n=0,i=0;r.left<o.left?n=o.left-r.left:r.right>o.right&&(n=o.right-r.right),r.top<o.top?i=o.top-r.top:r.bottom>o.bottom&&(i=o.bottom-r.bottom),0===n&&0===i||(e.style.transform=`translate(${n}px, ${i}px)`)},0);const r=this.map.getContainer();r&&(r.style.touchAction="manipulation")}),y.on("popupclose",()=>{const t=this.map.getContainer();t&&(t.style.touchAction="")})),a===i&&this.config.markers.infoMarker){const t=this.getPolygonGeoJSONFromFeatureGroup(e),r=this.turfHelper.getPolygonArea(t),o=this.getTotalPolygonPerimeter(t);y.options.zIndexOffset=this.config.markers.markerInfoIcon.zIndexOffset??this.config.markers.zIndexOffset,y.on("click",()=>{if(!this.isFeatureGroupInActiveLayer(e))return;const n=this.generateInfoMarkerPopup(r,o),a=Wn.getCenterOfPolygonByIndexWithOffsetFromCenterOfMass(t,i);n.setLatLng(a).openOn(this.map)}),y.on("popupopen",t=>{const e=t.popup.getElement();if(!e)return;setTimeout(()=>{const t=this.map.getContainer().getBoundingClientRect(),r=e.getBoundingClientRect();r.left<t.left?e.style.transform=`translateX(${t.left-r.left}px)`:r.right>t.right&&(e.style.transform=`translateX(${t.right-r.right}px)`)},0);const r=this.map.getContainer();r&&(r.style.touchAction="manipulation")}),y.on("popupclose",()=>{const t=this.map.getContainer();t&&(t.style.touchAction="")})}y.on("mousedown",t=>{this.modeManager.isInOffMode()||(s.DomEvent.stopPropagation(t),this.map.fire("mousedown",t)),this._activeMarker=y}),y.on("click",t=>{var r,o;if(this.isFeatureGroupInActiveLayer(e)&&this.modeManager.isInOffMode())if(this.isEdgeDeletionModifierKeyPressed(t.originalEvent)){const r=e.getLayers().find(t=>t instanceof s.Polygon);r&&this.elbowClicked(t,r,y.getLatLng())}else if(a===n&&this.config.markers.deleteMarker){if(this.shouldSuppressDeleteMarkerClick()){const e=t.originalEvent;return null==(r=null==e?void 0:e.preventDefault)||r.call(e),void(null==(o=null==e?void 0:e.stopPropagation)||o.call(e))}this.map.closePopup(),this.saveHistoryState&&this.saveHistoryState("deletePolygon"),this.cleanupFeatureGroup(e),this.removeFeatureGroup(e),this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups()),this.eventManager.emit("polydraw:polygon:deleted",void 0)}}),y.on("mouseover",()=>{this.isFeatureGroupInActiveLayer(e)&&this.onMarkerHoverForEdgeDeletion(y,!0)}),y.on("mouseout",()=>{this.onMarkerHoverForEdgeDeletion(y,!1)})});const u=this.map.getContainer();u&&(u.style.touchAction="manipulation")}addHoleMarkers(t,e){var r,o,n;this.registerPolygonLayerMappings(e);const i=(null==(r=this.config.markers.holeMarkers)?void 0:r.menuMarker)??!1,a=(null==(o=this.config.markers.holeMarkers)?void 0:o.deleteMarker)??!1,l=(null==(n=this.config.markers.holeMarkers)?void 0:n.infoMarker)??!1;let c=this.getMarkerIndex(t,this.config.markers.markerMenuIcon.position),h=this.getMarkerIndex(t,this.config.markers.markerDeleteIcon.position),u=this.getMarkerIndex(t,this.config.markers.markerInfoIcon.position);const g=this.ensureMarkerSeparation(t.length,{menu:{index:c,enabled:i},delete:{index:h,enabled:a},info:{index:u,enabled:l}});c=g.menu,h=g.delete,u=g.info,t.forEach((r,o)=>{let n=this.config.markers.holeIcon.styleClasses;o===c&&i&&(n=this.config.markers.markerMenuIcon.styleClasses),o===h&&a&&(n=this.config.markers.markerDeleteIcon.styleClasses),o===u&&l&&(n=this.config.markers.markerInfoIcon.styleClasses);const g=Array.isArray(n)?n:[n],d=o===c&&i||o===h&&a||o===u&&l,p=new s.Marker(r,{icon:this.createDivIcon(g),draggable:this.config.modes.dragElbow,title:this.config.markers.coordsTitle?this.getLatLngInfoString(r):"",zIndexOffset:this.config.markers.holeIcon.zIndexOffset??this.config.markers.zIndexOffset});e.addLayer(p),this.markerFeatureGroupMap.set(p,e),p.on("add",()=>{const t=p.getElement();t&&(t.style.pointerEvents="auto")}),p.on("click",t=>{var e,r;this.isDraggingMarker&&(null==(r=null==(e=t.originalEvent)?void 0:e.stopPropagation)||r.call(e),s.DomEvent.stopPropagation(t))}),p.on("dragstart",()=>{const t=this.markerFeatureGroupMap.get(p);!t||this.isFeatureGroupInActiveLayer(t)?(this.saveHistoryState&&this.saveHistoryState("markerDrag"),this.isDraggingMarker=!0,this._activeMarker=p):p.dragging&&p.dragging.disable()}),p.on("dragend",t=>{const e=this.markerFeatureGroupMap.get(p);if(e&&!this.isFeatureGroupInActiveLayer(e))return this._activeMarker=null,void(this.isDraggingMarker=!1);this.modeManager.canPerformAction("markerDrag")&&e&&this.markerDragEnd(e),this._activeMarker=null,s.DomEvent.stopPropagation(t),setTimeout(()=>{this.isDraggingMarker=!1},10)});const f=p.getElement();if(f){const t=t=>{t.stopPropagation()},e=t=>{if(t.preventDefault(),t.stopPropagation(),p.fire("click"),this.isDraggingMarker&&!d){const t=this.markerFeatureGroupMap.get(p);this.modeManager.canPerformAction("markerDrag")&&t&&this.isFeatureGroupInActiveLayer(t)&&this.markerDragEnd(t)}this._activeMarker=null};f.addEventListener("touchstart",t,{passive:!0}),f.addEventListener("touchend",e),this.markerTouchListeners.set(p,{touchstart:t,touchend:e})}if(o===c||o===h||o===u){const t=p.getElement();t&&(t.style.zIndex="10000")}if(this.config.modes.dragElbow){const t=t=>()=>{this.modeManager.canPerformAction("markerDrag")&&this.isFeatureGroupInActiveLayer(t)&&this.markerDrag(t)};p.on("drag",t(e))}if(o===c&&i&&(p.options.zIndexOffset=this.config.markers.markerMenuIcon.zIndexOffset??this.config.markers.zIndexOffset,p.on("click",()=>{const r=t.map(t=>[t.lng,t.lat]);r.push(r[0]);const o={type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[r]}},n=Wn.getCenterOfMass(o);this.generateMenuMarkerPopup(t,e).setLatLng(n).openOn(this.map)}),p.on("popupopen",t=>{const e=t.popup.getElement();if(!e)return;setTimeout(()=>{const t=this.map.getContainer().getBoundingClientRect(),r=e.getBoundingClientRect();r.left<t.left?e.style.transform=`translateX(${t.left-r.left}px)`:r.right>t.right&&(e.style.transform=`translateX(${t.right-r.right}px)`)},0);const r=this.map.getContainer();r&&(r.style.touchAction="manipulation")}),p.on("popupclose",()=>{const t=this.map.getContainer();t&&(t.style.touchAction="")})),o===u&&l){const o=t.map(t=>[t.lng,t.lat]);o.push(o[0]);const n={type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[o]}},i=this.turfHelper.getPolygonArea(n),a=1e3*this.turfHelper.getPolygonPerimeter(n);p.options.zIndexOffset=this.config.markers.markerInfoIcon.zIndexOffset??this.config.markers.zIndexOffset,p.on("click",()=>{if(!this.isFeatureGroupInActiveLayer(e))return;this.generateInfoMarkerPopup(i,a).setLatLng(r).openOn(this.map)})}p.on("mousedown",t=>{this.modeManager.isInOffMode()||(s.DomEvent.stopPropagation(t),this.map.fire("mousedown",t)),this._activeMarker=p}),p.on("click",t=>{if(this.isFeatureGroupInActiveLayer(e)&&this.modeManager.isInOffMode())if(this.isEdgeDeletionModifierKeyPressed(t.originalEvent)){const r=e.getLayers().find(t=>t instanceof s.Polygon);r&&this.elbowClicked(t,r,p.getLatLng())}else if(o===h&&a){this.map.closePopup();const t=e.getLayers().find(t=>t instanceof s.Polygon);if(t){const r=t.getLatLngs();let o=[];if(Array.isArray(r)&&r.length>0)if(Array.isArray(r[0])){const t=r[0];o=Array.isArray(t)&&Array.isArray(t[0])?r[0]:r}else o=[r];const n=p.getLatLng();let i=-1;for(let t=1;t<o.length;t++)if(o[t].some(t=>t.lat===n.lat&&t.lng===n.lng)){i=t;break}if(i>0){const t=o.filter((t,e)=>e!==i).map(t=>{const e=t.map(t=>[t.lng,t.lat]);if(e.length>0){const t=e[0],r=e[e.length-1];t[0]===r[0]&&t[1]===r[1]||e.push([t[0],t[1]])}return e}),{level:r,original:n}=this.getOptimizationMetadataFromFeatureGroup(e),a=this.getFeatureMetadataState(e),s=this.turfHelper.getMultiPolygon([t]);this.cleanupFeatureGroup(e),this.removeFeatureGroup(e),this.emitPolygonUpdated({operation:"removeHole",polygon:s,optimizationLevel:r,originalOptimizationLevel:n,featureId:a.featureId,featureMetadata:a.metadata,sourceFeatureIds:a.sourceFeatureIds,featureInteractionOverride:a.interactionOverride,featureStyleOverrides:a.styleOverrides,featureCreatedAt:a.createdAt})}}}}),p.on("mouseover",()=>{this.isFeatureGroupInActiveLayer(e)&&this.onMarkerHoverForEdgeDeletion(p,!0)}),p.on("mouseout",()=>{this.onMarkerHoverForEdgeDeletion(p,!1)})})}addEdgeClickListeners(t,e){const r=t.getLatLngs();let o;if(Array.isArray(r)&&r.length>0){if(Array.isArray(r[0]))if(Array.isArray(r[0][0])&&r[0][0].length>0){r[0][0][0];o=r[0]}else o=r[0][0]&&"object"==typeof r[0][0]&&"lat"in r[0][0]?r:r[0];else o=(r[0]&&"object"==typeof r[0]&&r[0],[r]);o.forEach((r,o)=>{for(let n=0;n<r.length;n++){const i=r[n],a=r[(n+1)%r.length];if(i.lat===a.lat&&i.lng===a.lng)continue;const s=Yn.createPolyline([i,a],{color:"transparent",weight:10,opacity:0,interactive:!0});s._polydrawEdgeInfo={ringIndex:o,edgeIndex:n,startPoint:i,endPoint:a,parentPolygon:t,parentFeatureGroup:e},s.on("click",t=>{this.onEdgeClick(t,s)}),s.on("mouseover",()=>{this.highlightEdgeOnHover(s,!0)}),s.on("mouseout",()=>{this.highlightEdgeOnHover(s,!1)}),e.addLayer(s)}})}}isPolygonDragModeActive(){const t=this.modeManager.getCurrentMode();return t===c.Off||t===c.Clone}isPolygonDragActive(){return!!(this.currentDragPolygon&&this.currentDragPolygon._polydrawDragData&&this.currentDragPolygon._polydrawDragData.isDragging)}isPolygonInActiveLayer(t){if(!this.layerManager)return!0;const e=this.polygonFeatureGroupMap.get(t);if(e)return this.layerManager.isInActiveLayer(e)&&this.layerManager.isFeatureGroupEditable(e);const r=this.findFeatureGroupForPolygon(t);return!r||(this.polygonFeatureGroupMap.set(t,r),this.layerManager.isInActiveLayer(r)&&this.layerManager.isFeatureGroupEditable(r))}isFeatureGroupInActiveLayer(t){return!this.layerManager||this.layerManager.isInActiveLayer(t)&&this.layerManager.isFeatureGroupEditable(t)}enablePolygonDragging(t,e){if(this.config.modes.dragPolygons||this.config.tools.clone){if(t._polydrawOriginalLatLngs=e,t._polydrawDragData={isDragging:!1,startPosition:null,startLatLngs:null,originalOpacity:t.options.fillOpacity},t.on("mousedown",e=>{if(this.transformModeActive)return;if(!this.isPolygonInActiveLayer(t))return;if(!this.isPolygonDragModeActive())return s.DomEvent.stopPropagation(e),void this.map.fire("mousedown",e);if(!this.modeManager.canPerformAction("polygonDrag"))return;s.DomEvent.stopPropagation(e.originalEvent),s.DomEvent.preventDefault(e.originalEvent);const r=this.modeManager.getCurrentMode()===c.Clone,o=!r&&this.detectDragSubtractModifierKey(e.originalEvent);this.currentDragIsClone=r,this.currentModifierDragMode=o,this.isModifierKeyHeld=o,this.saveHistoryState&&this.saveHistoryState(r?"polygonClone":"polygonDrag"),t._polydrawDragData.isDragging=!0,t._polydrawDragData.startPosition=e.latlng,t._polydrawDragData.startLatLngs=t.getLatLngs(),t.setStyle({fillOpacity:this.config.interaction.drag.opacity}),r?this.showCloneGhost(t._polydrawDragData.startLatLngs):this.clearCloneGhost(),this.map.dragging&&this.map.dragging.disable(),this.setSubtractVisualMode(t,o),this.setMarkerVisibility(t,!1);try{this.map.getContainer().style.cursor=this.config.interaction.drag.dragCursor||"move"}catch{}this.map.on("mousemove",this.onPolygonMouseMove,this),this.map.on("mouseup",this.onPolygonMouseUp,this),this.map.on("pointermove",this.onPolygonMouseMove,this),this.map.on("pointerup",this.onPolygonMouseUp,this),this.attachDragCancelHandlers(),this.currentDragPolygon=t}),t.on("pointerdown",e=>{const r=e;if(this.transformModeActive)return;if(!this.isPolygonInActiveLayer(t))return;if(!this.isPolygonDragModeActive()){const t=r.originalEvent??r;return s.DomEvent.stopPropagation(t),void this.map.fire("pointerdown",r)}if(!this.modeManager.canPerformAction("polygonDrag"))return;const o=r.originalEvent??r;s.DomEvent.stopPropagation(o),s.DomEvent.preventDefault(o);const n=this.modeManager.getCurrentMode()===c.Clone,i=!n&&this.detectDragSubtractModifierKey(o);this.currentDragIsClone=n,this.currentModifierDragMode=i,this.isModifierKeyHeld=i,this.saveHistoryState&&this.saveHistoryState(n?"polygonClone":"polygonDrag"),t._polydrawDragData.isDragging=!0,t._polydrawDragData.startPosition=r.latlng,t._polydrawDragData.startLatLngs=t.getLatLngs(),t.setStyle({fillOpacity:this.config.interaction.drag.opacity}),n?this.showCloneGhost(t._polydrawDragData.startLatLngs):this.clearCloneGhost(),this.map.dragging&&this.map.dragging.disable(),this.setSubtractVisualMode(t,i),this.setMarkerVisibility(t,!1);try{this.map.getContainer().style.cursor=this.config.interaction.drag.dragCursor||"move"}catch{}this.map.on("mousemove",this.onPolygonMouseMove,this),this.map.on("mouseup",this.onPolygonMouseUp,this),this.map.on("pointermove",this.onPolygonMouseMove,this),this.map.on("pointerup",this.onPolygonMouseUp,this),this.attachDragCancelHandlers(),this.currentDragPolygon=t}),Xn.isV1()){const e=e=>{if(this.transformModeActive)return;if(!this.isPolygonInActiveLayer(t))return;if(!this.isPolygonDragModeActive())return;if(!this.modeManager.canPerformAction("polygonDrag"))return;e.stopPropagation(),e.preventDefault();const r=ii.extractCoordinates(e,this.map);if(!r)return;const o=this.modeManager.getCurrentMode()===c.Clone;this.currentDragIsClone=o,this.currentModifierDragMode=!1,this.isModifierKeyHeld=!1,this.saveHistoryState&&this.saveHistoryState(o?"polygonClone":"polygonDrag"),t._polydrawDragData.isDragging=!0,t._polydrawDragData.startPosition=r,t._polydrawDragData.startLatLngs=t.getLatLngs(),t.setStyle({fillOpacity:this.config.interaction.drag.opacity}),o?this.showCloneGhost(t._polydrawDragData.startLatLngs):this.clearCloneGhost(),this.map.dragging&&this.map.dragging.disable(),this.setSubtractVisualMode(t,!1),this.setMarkerVisibility(t,!1);try{this.map.getContainer().style.cursor=this.config.interaction.drag.dragCursor||"move"}catch{}this.map.on("mousemove",this.onPolygonMouseMove,this),this.map.on("mouseup",this.onPolygonMouseUp,this),this.attachDragTouchListeners(),this.attachDragCancelHandlers(),this.currentDragPolygon=t};this.polygonTouchStartListeners.set(t,e);const r=()=>{const r=t._path;r&&r.addEventListener("touchstart",e,{passive:!1})};t._path?r():t.once("add",r)}t.on("mouseover",()=>{if(this.isPolygonInActiveLayer(t)&&(!t._polydrawDragData||!t._polydrawDragData.isDragging))try{this.map.getContainer().style.cursor=this.config.interaction.drag.hoverCursor||"grab"}catch{}}),t.on("mouseout",()=>{if(!t._polydrawDragData||!t._polydrawDragData.isDragging)try{this.map.getContainer().style.cursor=""}catch{}})}}updateMarkerDraggableState(){const t=this.modeManager.canPerformAction("markerDrag");this.getFeatureGroups().forEach(e=>{const r=this.isFeatureGroupInActiveLayer(e),o=t&&r;e.eachLayer(t=>{if(t instanceof s.Marker){const e=t;try{e.options.draggable=o,e.dragging&&(o?e.dragging.enable():e.dragging.disable())}catch{}}})})}updateAllMarkersForEdgeDeletion(t){this.getFeatureGroups().forEach(e=>{e.eachLayer(e=>{e instanceof s.Marker&&this.updateMarkerForEdgeDeletion(e,t)})})}updateMarkerForEdgeDeletion(t,e){const r=t.getElement();r&&(e?(r.addEventListener("mouseenter",this.onMarkerHoverForEdgeDeletionEvent),r.addEventListener("mouseleave",this.onMarkerLeaveForEdgeDeletionEvent),this.markerEdgeDeletionListeners.set(t,{mouseenter:this.onMarkerHoverForEdgeDeletionEvent,mouseleave:this.onMarkerLeaveForEdgeDeletionEvent})):(r.removeEventListener("mouseenter",this.onMarkerHoverForEdgeDeletionEvent),r.removeEventListener("mouseleave",this.onMarkerLeaveForEdgeDeletionEvent),r.style.backgroundColor="",r.style.borderColor="",this.markerEdgeDeletionListeners.delete(t)))}setModifierKeyHeld(t){this.isModifierKeyHeld=t}cleanupMarker(t){const e=t.getElement(),r=this.markerModifierHandlers.get(t);r&&(document.removeEventListener("keydown",r),document.removeEventListener("keyup",r),e&&e.removeEventListener("mousemove",r),this.markerModifierHandlers.delete(t));const o=this.markerTouchListeners.get(t);o&&(e&&(e.removeEventListener("touchstart",o.touchstart),e.removeEventListener("touchend",o.touchend)),this.markerTouchListeners.delete(t));const n=this.markerEdgeDeletionListeners.get(t);n&&(e&&(e.removeEventListener("mouseenter",n.mouseenter),e.removeEventListener("mouseleave",n.mouseleave)),this.markerEdgeDeletionListeners.delete(t)),this.markerFeatureGroupMap.delete(t)}cleanupFeatureGroup(t){t.eachLayer(t=>{t instanceof s.Marker?this.cleanupMarker(t):t instanceof s.Polygon&&(this.detachPolygonTouchStart(t),this.polygonFeatureGroupMap.delete(t))}),this.destroyTransformController(t)}destroyTransformController(t){const e=this.transformControllers.get(t);e&&(e.destroy(),this.transformControllers.delete(t),this.transformModeActive=!1)}onEdgeClick(t,e){if(!this.config.modes.attachElbow)return;if(!this.modeManager.isInOffMode())return;const r=e._polydrawEdgeInfo;if(!r)return;if(r.parentFeatureGroup&&!this.isFeatureGroupInActiveLayer(r.parentFeatureGroup))return;const o=t.latlng,n=r.parentPolygon,i=r.parentFeatureGroup;if(n&&i)try{if("function"!=typeof n.toGeoJSON)return;const t=n.toGeoJSON();if("MultiPolygon"===t.geometry.type||"Polygon"===t.geometry.type){const e=this.turfHelper.injectPointToPolygon(t,[o.lng,o.lat],r.ringIndex);if(e){const t=n,r=t._polydrawOptimizationLevel||0,o=t._polydrawOptimizationOriginalLevel||r,a=this.getFeatureMetadataState(i);this.cleanupFeatureGroup(i),this.removeFeatureGroup(i),this.emitPolygonUpdated({operation:"addVertex",polygon:e,optimizationLevel:r,originalOptimizationLevel:o,featureId:a.featureId,featureMetadata:a.metadata,sourceFeatureIds:a.sourceFeatureIds,featureInteractionOverride:a.interactionOverride,featureStyleOverrides:a.styleOverrides,featureCreatedAt:a.createdAt})}}}catch{}s.DomEvent.stopPropagation(t)}highlightEdgeOnHover(t,e){e?t.setStyle({color:this.config.styles.ui.edgeHover.color,weight:4,opacity:1}):t.setStyle({color:"transparent",weight:10,opacity:0})}deriveImportantMarkerIndices(t,e){const r=new Set;if(!t||0===t.length)return r;const o=Math.min(Math.max(e.optimizationLevel??0,0),10),n=t.length>2&&this.latLngEquals(t[0],t[t.length-1]),i=n?t.slice(0,-1):[...t],a=i.length,s=e=>{if(null==e||e<0)return;let o=e;n&&e===t.length-1&&(o=0),o>=a&&(o=a>0?o%a:0),o>=0&&o<a&&r.add(o)};if(s(0),s(e.menuIndex),s(e.deleteIndex),s(e.infoIndex),0===a||o<=0||a<=3){for(let t=0;t<a;t++)r.add(t);return r}const l=this.getToleranceForOptimizationLevel(o);let c=l>0?this.turfHelper.simplifyLatLngRing(i,l,!0):[...i];if(c.length>1&&this.latLngEquals(c[0],c[c.length-1])&&(c=c.slice(0,-1)),!c||0===c.length){for(let t=0;t<a;t++)r.add(t);return r}if(c.forEach(t=>{const e=this.findClosestVertexIndex(t,i);null!==e&&r.add(e)}),0===r.size)for(let h=0;h<a;h++)r.add(h);return r}normalizeMarkerIndex(t,e,r){if(null==t||t<0)return null;if(r){const r=Math.max(1,e-1);return t===e-1?0:t>=r?t%r:t}return t>=e?e>0?e-1:null:t}latLngEquals(t,e){return!(!t||!e)&&(Math.abs(t.lat-e.lat)<1e-9&&Math.abs(t.lng-e.lng)<1e-9)}isLatLngLiteral(t){return!!t&&"object"==typeof t&&"lat"in t&&"lng"in t&&"number"==typeof t.lat&&"number"==typeof t.lng}getOrderedMarkers(t){const e=[];return t.eachLayer(t=>{t instanceof s.Marker&&e.push(t)}),e.sort((t,e)=>Yn.util.stamp(t)-Yn.util.stamp(e))}countLatLngNodes(t){return Array.isArray(t)?0===t.length?0:this.isLatLngLiteral(t[0])?t.length:t.reduce((t,e)=>t+this.countLatLngNodes(e),0):0}rebuildLatLngStructure(t,e,r){if(!Array.isArray(t))return t;if(t.length>0&&this.isLatLngLiteral(t[0])){const o=t,n=o.length>1&&this.latLngEquals(o[0],o[o.length-1]),i=o.map((t,n)=>{const i=e[r.value]??o[n];return r.value+=1,Yn.createLatLng(i.lat,i.lng)});return n&&i.length>1&&(i[i.length-1]=i[0]),i}return t.map(t=>this.rebuildLatLngStructure(t,e,r))}getOptimizationMetadataFromFeatureGroup(t){let e=0,r=0;return t.eachLayer(t=>{if(t instanceof s.Polygon){const o=t;"number"==typeof o._polydrawOptimizationLevel&&(e=o._polydrawOptimizationLevel||0),"number"==typeof o._polydrawOptimizationOriginalLevel&&(r=o._polydrawOptimizationOriginalLevel||0)}}),!r&&e>0&&(r=e),{level:e,original:r}}getFeatureMetadataState(t){if(!t)return{};const e=t._polydrawMetadata,r=(null==e?void 0:e.createdAt)instanceof Date&&!Number.isNaN(e.createdAt.getTime())?e.createdAt.toISOString():void 0;return{featureId:null==e?void 0:e.id,metadata:(null==e?void 0:e.metadata)?{...e.metadata}:void 0,sourceFeatureIds:Array.isArray(null==e?void 0:e.sourceFeatureIds)?[...e.sourceFeatureIds]:(null==e?void 0:e.id)?[e.id]:void 0,interactionOverride:null==e?void 0:e.interactionOverride,styleOverrides:(null==e?void 0:e.styleOverrides)?{...e.styleOverrides}:void 0,createdAt:r}}getOptimizationMetadataFromPolygonLayer(t){if(!t)return{level:0,original:0};const e=t,r=e._polydrawOptimizationLevel||0;return{level:r,original:e._polydrawOptimizationOriginalLevel||(r>0?r:0)}}getDistanceMeters(t,e){try{const r=Yn.createLatLng(t.lat,t.lng),o=Yn.createLatLng(e.lat,e.lng);if("function"==typeof r.distanceTo)return r.distanceTo(o)}catch{}const r=t=>t*Math.PI/180,o=r(e.lat-t.lat),n=r(e.lng-t.lng),i=r(t.lat),a=r(e.lat),s=Math.sin(o/2)*Math.sin(o/2)+Math.sin(n/2)*Math.sin(n/2)*Math.cos(i)*Math.cos(a);return 6371e3*(2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s)))}findClosestVertexIndex(t,e){if(!e||0===e.length)return null;let r=0,o=Number.POSITIVE_INFINITY;for(let n=0;n<e.length;n++){const i=this.getDistanceMeters(t,e[n]);if(i<o&&(o=i,r=n,0===i))break}return r}getToleranceForOptimizationLevel(t){const e=Math.min(Math.max(t,0),10)/10,r=this.config.markers.visualOptimization??{},o=Math.max(r.toleranceMin??5e-6,0),n=Math.max(r.toleranceMax??.005,o),i=r.curve??1.35;return o+(n-o)*Math.pow(e,i)}elbowClicked(t,e,r){if(!this.config.modes.edgeDeletion)return;if(!this.isEdgeDeletionModifierKeyPressed(t.originalEvent))return;const o=r??t.latlng,n=e.getLatLngs();let i=[];if(!(Array.isArray(n)&&n.length>0))return;if(Array.isArray(n[0])){const t=n[0];i=Array.isArray(t)&&Array.isArray(t[0])?n[0]:n}else i=[n];let a=-1,s=-1;for(let f=0;f<i.length;f++){const t=i[f];for(let e=0;e<t.length;e++){const r=t[e];if(r.lat===o.lat&&r.lng===o.lng){a=f,s=e;break}}if(-1!==a)break}if(-1===a||-1===s)return;if(i[a].length<=this.config.interaction.edgeDeletion.minVertices)return;const l=i.map((t,e)=>{if(e!==a)return t.slice();const r=t.slice();return r.splice(s,1),r}).map(t=>{const e=t.map(t=>[t.lng,t.lat]);if(e.length>0){const t=e[0],r=e[e.length-1];t[0]===r[0]&&t[1]===r[1]||e.push([t[0],t[1]])}return e});let c=null;for(const f of this.getFeatureGroups()){let t=!1;if(f.eachLayer(r=>{r===e&&(t=!0)}),t){c=f;break}}const h=c?this.getOptimizationMetadataFromFeatureGroup(c):this.getOptimizationMetadataFromPolygonLayer(e),u=this.getFeatureMetadataState(c??void 0),{level:g,original:d}=h;c&&this.removeFeatureGroup(c);const p=this.turfHelper.getMultiPolygon([l]);this.emitPolygonUpdated({operation:"removeVertex",polygon:p,optimizationLevel:g,originalOptimizationLevel:d,featureId:u.featureId,featureMetadata:u.metadata,sourceFeatureIds:u.sourceFeatureIds,featureInteractionOverride:u.interactionOverride,featureStyleOverrides:u.styleOverrides,featureCreatedAt:u.createdAt})}markerDrag(t){if(!this._activeMarker)return void(_n()||console.warn("No active marker set for dragging."));const e=t.getLayers().find(t=>t instanceof s.Polygon);if(!e)return void(_n()||console.warn("No polygon found in feature group for marker drag."));const r=this.getOrderedMarkers(t);if(0===r.length)return;const o=r.map(t=>t.getLatLng()),n=this.countLatLngNodes(e.getLatLngs());if(o.length<n)return void(_n()||console.warn("Not enough markers to rebuild polygon during drag. Expected:",n,"got:",o.length));const i=this.rebuildLatLngStructure(e.getLatLngs(),o,{value:0});e.setLatLngs(i)}async markerDragEnd(t){this.polygonInformation.deletePolygonInformationStorage();const e=t.toGeoJSON();if(!e.features||0===e.features.length)return;const{level:r,original:o}=this.getOptimizationMetadataFromFeatureGroup(t),n=this.getFeatureMetadataState(t);this.cleanupFeatureGroup(t),this.removeFeatureGroup(t);const i=(t,e,r)=>{const o=this.turfHelper.removeDuplicateVertices(t),i=[];if(!this.config.kinks)try{const t=this.turfHelper.getKinks(o);t&&t.length>0&&i.push(...t)}catch{}0===i.length&&("MultiPolygon"===o.geometry.type?o.geometry.coordinates.forEach(t=>i.push(this.turfHelper.getMultiPolygon([t]))):i.push(o)),i.forEach(t=>{this.emitPolygonUpdated({operation:"markerDrag",polygon:t,allowMerge:e,optimizationLevel:r.optimizationLevel,originalOptimizationLevel:r.originalOptimizationLevel,featureId:n.featureId,featureMetadata:n.metadata,sourceFeatureIds:n.sourceFeatureIds,featureInteractionOverride:n.interactionOverride,featureStyleOverrides:n.styleOverrides,featureCreatedAt:n.createdAt})})};if("MultiPolygon"===e.features[0].geometry.type)for(const a of e.features[0].geometry.coordinates){i(this.turfHelper.getMultiPolygon([a]),!0,{optimizationLevel:r,originalOptimizationLevel:o})}else{i(this.turfHelper.getMultiPolygon([e.features[0].geometry.coordinates]),!1,{optimizationLevel:r,originalOptimizationLevel:o})}this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups())}attachDragTouchListeners(){this.detachDragTouchListeners(),this._boundDragTouchMove=this.onDragTouchMove,this._boundDragTouchEnd=this.onDragTouchEnd;const t=this.map.getContainer();t.addEventListener("touchmove",this._boundDragTouchMove,{passive:!1}),t.addEventListener("touchend",this._boundDragTouchEnd,{passive:!1})}detachDragTouchListeners(){const t=this.map.getContainer();this._boundDragTouchMove&&(t.removeEventListener("touchmove",this._boundDragTouchMove),this._boundDragTouchMove=null),this._boundDragTouchEnd&&(t.removeEventListener("touchend",this._boundDragTouchEnd),this._boundDragTouchEnd=null)}detachPolygonTouchStart(t){const e=this.polygonTouchStartListeners.get(t);if(!e)return;const r=t._path;r&&r.removeEventListener("touchstart",e),this.polygonTouchStartListeners.delete(t)}attachDragCancelHandlers(){this.dragCancelHandlersAttached||(this.dragCancelHandlersAttached=!0,document.addEventListener("keydown",this.onPolygonDragKeyDown),this.map.on("pointercancel",this.onPolygonDragCancel,this),this.map.on("touchcancel",this.onPolygonDragCancel,this))}detachDragCancelHandlers(){this.dragCancelHandlersAttached&&(this.dragCancelHandlersAttached=!1,document.removeEventListener("keydown",this.onPolygonDragKeyDown),this.map.off("pointercancel",this.onPolygonDragCancel,this),this.map.off("touchcancel",this.onPolygonDragCancel,this))}cancelActivePolygonDrag(){if(!this.currentDragPolygon||!this.currentDragPolygon._polydrawDragData)return void this.clearCloneGhost();const t=this.currentDragPolygon,e=t._polydrawDragData;if(e)if(e.isDragging){e.isDragging=!1,this.map.off("mousemove",this.onPolygonMouseMove,this),this.map.off("mouseup",this.onPolygonMouseUp,this),this.map.off("pointermove",this.onPolygonMouseMove,this),this.map.off("pointerup",this.onPolygonMouseUp,this),this.map.dragging&&this.map.dragging.enable(),e.startLatLngs&&t.setLatLngs(e.startLatLngs),t._polydrawOriginalMarkerPositions&&(t._polydrawOriginalMarkerPositions.forEach((t,e)=>{e.setLatLng(t)}),t._polydrawOriginalMarkerPositions.clear(),delete t._polydrawOriginalMarkerPositions),t._polydrawOriginalHoleLinePositions&&(t._polydrawOriginalHoleLinePositions.forEach((t,e)=>{e.setLatLngs(t)}),t._polydrawOriginalHoleLinePositions.clear(),delete t._polydrawOriginalHoleLinePositions),t._polydrawCurrentDragSession&&delete t._polydrawCurrentDragSession,null!=e.originalOpacity&&t.setStyle({fillOpacity:e.originalOpacity}),this.setSubtractVisualMode(t,!1),this.setMarkerVisibility(t,!0);try{this.map.getContainer().style.cursor=""}catch{}this.clearCloneGhost(),this.detachDragTouchListeners(),this.detachDragCancelHandlers(),this.currentDragIsClone=!1,this.currentModifierDragMode=!1,this.isModifierKeyHeld=!1,this.currentDragPolygon=null}else this.clearCloneGhost();else this.clearCloneGhost()}offsetPolygonCoordinates(t,e,r){return t?Array.isArray(t[0])?t.map(t=>this.offsetPolygonCoordinates(t,e,r)):t.map(t=>Yn.createLatLng(t.lat+e,t.lng+r)):t}updateMarkersAndHoleLinesDuringDrag(t,e,r){try{let o=null;for(const e of this.getFeatureGroups()){let r=!1;if(e.eachLayer(e=>{e===t&&(r=!0)}),r){o=e;break}}if(!o)return;const n="_polydrawDragSession_"+Date.now()+"_"+Yn.util.stamp(t);t._polydrawCurrentDragSession||(t._polydrawCurrentDragSession=n,t._polydrawOriginalMarkerPositions=new Map,t._polydrawOriginalHoleLinePositions=new Map,o.eachLayer(e=>{if(e instanceof s.Marker)t._polydrawOriginalMarkerPositions.set(e,e.getLatLng());else if(e instanceof s.Polyline&&!(e instanceof s.Polygon)){const r=e.getLatLngs();t._polydrawOriginalHoleLinePositions.set(e,r)}})),o.eachLayer(o=>{if(o instanceof s.Marker){const n=t._polydrawOriginalMarkerPositions.get(o);if(n){const t={lat:n.lat+e,lng:n.lng+r};o.setLatLng(t)}}else if(o instanceof s.Polyline&&!(o instanceof s.Polygon)){const n=t._polydrawOriginalHoleLinePositions.get(o);if(n){let t;t=Array.isArray(n[0])?n.map(t=>t.map(t=>Yn.createLatLng(t.lat+e,t.lng+r))):n.map(t=>Yn.createLatLng(t.lat+e,t.lng+r)),o.setLatLngs(t)}}})}catch(o){console.warn("Error updating markers during drag:",o)}}async updatePolygonAfterDrag(t){try{let e=null;for(const s of this.getFeatureGroups())if(s.eachLayer(r=>{r===t&&(e=s)}),e)break;if(!e)return;const r=t.toGeoJSON();if(this.isModifierDragActive())return this.performModifierSubtract(r,e),this.currentModifierDragMode=!1,void(this.isModifierKeyHeld=!1);const{level:o,original:n}=this.getOptimizationMetadataFromFeatureGroup(e),i=this.getFeatureMetadataState(e);this.cleanupFeatureGroup(e),this.removeFeatureGroup(e);const a=this.turfHelper.getTurfPolygon(r);this.emitPolygonUpdated({operation:"polygonDrag",polygon:a,allowMerge:!0,optimizationLevel:o,originalOptimizationLevel:n,featureId:i.featureId,featureMetadata:i.metadata,sourceFeatureIds:i.sourceFeatureIds,featureInteractionOverride:i.interactionOverride,featureStyleOverrides:i.styleOverrides,featureCreatedAt:i.createdAt}),this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups())}catch{}}updatePolygonAfterCloneDrag(t,e){try{let r=null;for(const e of this.getFeatureGroups())if(e.eachLayer(o=>{o===t&&(r=e)}),r)break;if(!r)return;const o=t.toGeoJSON(),n=(null==e?void 0:e.startLatLngs)??null,i=n?this.createPolygonFeatureFromLatLngs(n):null,{level:a,original:s}=this.getOptimizationMetadataFromFeatureGroup(r),l=this.getFeatureMetadataState(r);this.cleanupFeatureGroup(r),this.removeFeatureGroup(r);const c=this.turfHelper.getTurfPolygon(o);if(this.emitPolygonUpdated({operation:"polygonDrag",polygon:c,allowMerge:!0,optimizationLevel:a,originalOptimizationLevel:s,featureId:l.featureId,featureMetadata:l.metadata,sourceFeatureIds:l.sourceFeatureIds,featureInteractionOverride:l.interactionOverride,featureStyleOverrides:l.styleOverrides,featureCreatedAt:l.createdAt}),i){const t=this.turfHelper.getTurfPolygon(i);this.emitPolygonUpdated({operation:"polygonClone",polygon:t,allowMerge:!0,optimizationLevel:a,originalOptimizationLevel:s,featureId:l.featureId,featureMetadata:l.metadata,sourceFeatureIds:l.sourceFeatureIds,featureInteractionOverride:l.interactionOverride,featureStyleOverrides:l.styleOverrides,featureCreatedAt:l.createdAt})}this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups())}catch{}finally{this.currentModifierDragMode=!1,this.isModifierKeyHeld=!1}}showCloneGhost(t){if(this.clearCloneGhost(),t)try{const e=Yn.createPolygon(t,{color:this.config.styles.polygon.color,weight:this.config.styles.polygon.weight,opacity:.9,fill:!1,fillOpacity:0,dashArray:"4,6",interactive:!1});e.addTo(this.map),this.currentCloneGhost=e}catch{}}clearCloneGhost(){if(this.currentCloneGhost){try{this.map.removeLayer(this.currentCloneGhost)}catch{}this.currentCloneGhost=null}}createPolygonFeatureFromLatLngs(t){try{return Yn.createPolygon(t).toGeoJSON()}catch{return null}}getDragSubtractModifierKey(){const{keys:t}=this.config.interaction.drag.modifierSubtract,e=navigator.userAgent.toLowerCase(),r=e.includes("mac"),o=e.includes("windows");return r&&t.mac?t.mac:o&&t.windows?t.windows:t.linux?t.linux:r?"metaKey":"ctrlKey"}detectDragSubtractModifierKey(t){if(Tn())return!1;return t[this.getDragSubtractModifierKey()]||!1}setSubtractVisualMode(t,e){if(t&&t.setStyle)try{e?t.setStyle({color:this.config.styles.ui.dragSubtract.color}):t.setStyle({color:this.config.styles.polygon.color}),this.updateMarkerColorsForSubtractMode(t,e)}catch{}}updateMarkerColorsForSubtractMode(t,e){try{let r=null;for(const e of this.getFeatureGroups())if(e.eachLayer(o=>{o===t&&(r=e)}),r)break;if(!r)return;const o=r,n=this.config.interaction.drag.modifierSubtract.hideMarkersOnDrag;o.eachLayer(t=>{if(t instanceof s.Marker){const r=t.getElement();r&&(e?n?(r.style.display="none",r.classList.add("subtract-mode-hidden")):(r.style.backgroundColor=this.config.styles.ui.dragSubtract.color,r.style.borderColor=this.config.styles.ui.dragSubtract.color,r.classList.add("subtract-mode")):n?(r.style.display="",r.classList.remove("subtract-mode-hidden")):(r.style.backgroundColor="",r.style.borderColor="",r.classList.remove("subtract-mode")))}})}catch{}}handleModifierToggleDuringDrag(t){const e=this.detectDragSubtractModifierKey(t);this.currentModifierDragMode=e,this.isModifierKeyHeld=e,this.currentDragPolygon&&this.setSubtractVisualMode(this.currentDragPolygon,e)}isModifierDragActive(){return this.currentModifierDragMode}performModifierSubtract(t,e){var r;try{const o=this.turfHelper.getTurfPolygon(t),n=[],i=null==(r=this.layerManager)?void 0:r.getLayerForFeatureGroup(e);this.getFeatureGroups().forEach(t=>{if(t!==e){if(i&&this.layerManager){if(this.layerManager.getLayerForFeatureGroup(t)!==i)return}try{const e=t.toGeoJSON();if(!e||!e.features||!e.features[0])return;const r=e.features[0];if(!r.geometry||!r.geometry.coordinates)return;const i=this.turfHelper.getTurfPolygon(r);try{const e=this.turfHelper.getIntersection(i,o);if(e&&e.geometry&&"coordinates"in e.geometry){e.geometry.coordinates.length>0&&n.push(t)}}catch{try{this.turfHelper.polygonIntersect(i,o)&&n.push(t)}catch{}}}catch{}}}),this.removeFeatureGroup(e),n.forEach(t=>{try{const r=t.toGeoJSON(),n=this.turfHelper.getTurfPolygon(r.features[0]),{level:i,original:a}=this.getOptimizationMetadataFromFeatureGroup(t),s=this.getFeatureMetadataState(t);this.cleanupFeatureGroup(t),this.removeFeatureGroup(t);try{const t=this.turfHelper.polygonDifference(n,o);if(t&&t.geometry){const e=this.turfHelper.getCoords(t);for(const t of e){const e=this.turfHelper.getMultiPolygon([t]);this.emitPolygonUpdated({operation:"modifierSubtract",polygon:this.turfHelper.getTurfPolygon(e),allowMerge:!1,optimizationLevel:i,originalOptimizationLevel:a,featureId:s.featureId,featureMetadata:s.metadata,sourceFeatureIds:s.sourceFeatureIds,featureInteractionOverride:s.interactionOverride,featureStyleOverrides:s.styleOverrides,featureCreatedAt:s.createdAt})}}}catch(e){_n()||console.warn("Failed to perform difference operation:",e),this.emitPolygonUpdated({operation:"modifierSubtractFallback",polygon:n,allowMerge:!1,optimizationLevel:i,originalOptimizationLevel:a,featureId:s.featureId,featureMetadata:s.metadata,sourceFeatureIds:s.sourceFeatureIds,featureInteractionOverride:s.interactionOverride,featureStyleOverrides:s.styleOverrides,featureCreatedAt:s.createdAt})}}catch(r){_n()||console.warn("Error in modifier subtract operation:",r)}}),this.polygonInformation.createPolygonInformationStorage(this.getFeatureGroups())}catch(o){_n()||console.warn("Error in performModifierSubtract:",o)}}getEdgeDeletionModifierKey(){const{keys:t}=this.config.interaction.edgeDeletion,e=navigator.userAgent.toLowerCase(),r=e.includes("mac"),o=e.includes("windows");return r&&t.mac?t.mac:o&&t.windows?t.windows:t.linux?t.linux:r?"metaKey":"ctrlKey"}isEdgeDeletionModifierKeyPressed(t){if(Tn())return!1;return!!t[this.getEdgeDeletionModifierKey()]}registerPolygonLayerMappings(t){t.eachLayer(e=>{e instanceof s.Polygon&&this.polygonFeatureGroupMap.set(e,t)})}findFeatureGroupForPolygon(t){for(const e of this.getFeatureGroups()){let r=!1;if(e.eachLayer(e=>{r||e!==t||(r=!0)}),r)return e}}onMarkerHoverForEdgeDeletion(t,e){const r=t.getElement();if(r)if(e){const e=t=>{if(this.isEdgeDeletionModifierKeyPressed(t)){r.style.backgroundColor=this.config.styles.ui.edgeDeletion.color,r.style.borderColor=this.config.styles.ui.edgeDeletion.color,r.classList.add("edge-deletion-hover");try{this.map.getContainer().style.cursor="pointer"}catch{}}else{r.style.backgroundColor="",r.style.borderColor="",r.classList.remove("edge-deletion-hover");try{this.map.getContainer().style.cursor=""}catch{}}};e(new MouseEvent("mouseover")),this.markerModifierHandlers.set(t,e),document.addEventListener("keydown",e),document.addEventListener("keyup",e),r.addEventListener("mousemove",e)}else{r.style.backgroundColor="",r.style.borderColor="",r.classList.remove("edge-deletion-hover");try{this.map.getContainer().style.cursor=""}catch{}const e=this.markerModifierHandlers.get(t);e&&(document.removeEventListener("keydown",e),document.removeEventListener("keyup",e),r.removeEventListener("mousemove",e),this.markerModifierHandlers.delete(t))}}getMarkerIndex(t,e){const r=Hn.getBounds(t,Math.sqrt(2)/2),o=new Gn(r.getSouth(),r.getWest(),r.getNorth(),r.getEast()).getDirection(e),n={lat:o.lat,lng:o.lng},i=this.turfHelper.getCoord(n),a=this.turfHelper.getFeaturePointCollection(t);return this.turfHelper.getNearestPointIndex(i,a)}ensureMarkerSeparation(t,e){const r=[];if(e.menu.enabled&&r.push({type:"menu",index:e.menu.index}),e.delete.enabled&&r.push({type:"delete",index:e.delete.index}),e.info.enabled&&r.push({type:"info",index:e.info.index}),r.length<2)return{menu:e.menu.index,delete:e.delete.index,info:e.info.index};const o={...e},n=new Set,i=["info","delete","menu"];for(const a of i){const e=o[a];if(e.enabled)if(n.has(e.index)){const r=this.findAlternativeMarkerPosition(t,e.index,n);o[a].index=r,n.add(r)}else n.add(e.index)}return{menu:o.menu.index,delete:o.delete.index,info:o.info.index}}findAlternativeMarkerPosition(t,e,r){const o=t,n=Math.max(1,Math.floor(t/8));for(let i=1;i<o;i++){const o=[(e+i*n)%t,(e-i*n+t)%t];for(const t of o)if(!r.has(t))return t}for(let i=0;i<t;i++)if(!r.has(i))return i;return e}createDivIcon(t){return ni.createDivIcon(t)}getLatLngInfoString(t){return"Latitude: "+t.lat+" Longitude: "+t.lng}setMarkerVisibility(t,e){const r=this.getFeatureGroups().find(e=>e.hasLayer(t));r&&r.eachLayer(t=>{if(t instanceof s.Marker){const r=t.getElement();if(r){const t=this.config.interaction.drag.markerBehavior,o=this.config.interaction.drag.markerAnimationDuration;"hide"===t?r.style.display=e?"":"none":"fade"===t&&(r.style.transition=`opacity ${o}ms ease`,r.style.opacity=e?"1":"0")}}})}generateMenuMarkerPopup(t,e){var r;const o=[],n=this.config.polygonTools;if(n.simplify.enabled&&o.push(mi.createMenuButton("simplify","Simplify",["simplify"])),n.doubleElbows.enabled&&o.push(mi.createMenuButton("doubleElbows","DoubleElbows",["double-elbows"])),n.bbox.enabled&&o.push(mi.createMenuButton("bbox","Bounding box",["bbox"])),n.bezier.enabled&&o.push(mi.createMenuButton("bezier","Curve",["bezier"])),n.scale.enabled&&o.push(mi.createMenuButton("scale","Scale",["transform-scale"])),n.rotate.enabled&&o.push(mi.createMenuButton("rotate","Rotate",["transform-rotate"])),null==(r=n.visualOptimizationToggle)?void 0:r.enabled){const{level:t,original:r}=this.getOptimizationMetadataFromFeatureGroup(e);if(r>0||t>0){const e="number"==typeof t&&t>0,r=["toggle-visual-optimization",e?"visual-optimization-state-hidden":"visual-optimization-state-visible"],n=e?"Show all markers":"Hide extra markers";o.push(mi.createMenuButton("toggleOptimization",n,r))}}const i=mi.buildMenuPopup(o),a=i.querySelector(".marker-menu-close");if(a){const t=t=>{t.stopPropagation(),t.preventDefault(),this._openMenuPopup?(this.map.closePopup(this._openMenuPopup),this._openMenuPopup=null):this.map.closePopup()};a.addEventListener("click",t),a.addEventListener("touchend",t,{passive:!1})}const l=()=>{this._openMenuPopup&&(this.map.closePopup(this._openMenuPopup),this._openMenuPopup=null)},c=(r,o)=>{r.addEventListener("touchend",r=>{r.preventDefault(),r.stopPropagation(),this.eventManager.emit("polydraw:menu:action",{action:o,latLngs:t,featureGroup:e}),l()}),r.onclick=()=>{this.eventManager.emit("polydraw:menu:action",{action:o,latLngs:t,featureGroup:e}),l()}},h=t=>{const r=this.transformControllers.get(e);r&&(r.cancel(),r.destroy(),this.transformControllers.delete(e));try{const r=new yi(this.map,e,t,o=>{this.transformControllers.get(e)===r&&this.transformControllers.delete(e),this.transformModeActive=!1;const n=e.getLayers().find(t=>t instanceof s.Polygon);if(!n)return;if(!o)return void this.setMarkerVisibility(n,!0);this.saveHistoryState&&this.saveHistoryState(t);const i=n.toGeoJSON(),{level:a,original:l}=this.getOptimizationMetadataFromFeatureGroup(e),c=this.getFeatureMetadataState(e);this.cleanupFeatureGroup(e),this.removeFeatureGroup(e),this.emitPolygonUpdated({operation:"transform",polygon:this.turfHelper.getTurfPolygon(i),allowMerge:!0,optimizationLevel:a,originalOptimizationLevel:l,featureId:c.featureId,featureMetadata:c.metadata,sourceFeatureIds:c.sourceFeatureIds,featureInteractionOverride:c.interactionOverride,featureStyleOverrides:c.styleOverrides,featureCreatedAt:c.createdAt})});this.transformControllers.set(e,r);const o=e.getLayers().find(t=>t instanceof s.Polygon);o&&this.setMarkerVisibility(o,!1),this.transformModeActive=!0}catch{}},u=(t,e)=>{t.addEventListener("touchend",t=>{t.preventDefault(),t.stopPropagation(),h(e),l()}),t.onclick=()=>{h(e),l()}},g=t=>{const r=t=>{t.preventDefault(),t.stopPropagation(),this.toggleOptimizationVisibility(e),l()};t.addEventListener("touchend",r,{passive:!1}),t.onclick=r};o.forEach(t=>{switch(t.getAttribute("data-action-id")){case"simplify":c(t,"simplify");break;case"doubleElbows":c(t,"doubleElbows");break;case"bbox":c(t,"bbox");break;case"bezier":c(t,"bezier");break;case"scale":u(t,"scale");break;case"rotate":u(t,"rotate");break;case"toggleOptimization":g(t)}}),s.DomEvent.disableClickPropagation(i),i.style.pointerEvents="auto",i.querySelectorAll(".marker-menu-button").forEach(t=>{t.style.pointerEvents="auto",t.addEventListener("click",t=>t.stopPropagation())});const d=window.innerWidth<=600,p=Xn.isV1()?" leaflet-v1":" leaflet-v2",f=Yn.createPopup({closeButton:!1,autoClose:!0,className:`menu-popup${d?" mobile-popup":""}${p}`}).setContent(i);return this._openMenuPopup=f,f}toggleOptimizationVisibility(t){const e=t.getLayers().find(t=>t instanceof s.Polygon);if(!e)return;const r=this.getOptimizationMetadataFromFeatureGroup(t);if(!r.original&&!r.level)return;const o=r.level>0?0:r.original>0?r.original:r.level;if(o===r.level)return;const n=e.toGeoJSON(),i=this.getFeatureMetadataState(t);this.cleanupFeatureGroup(t),this.removeFeatureGroup(t),this.emitPolygonUpdated({operation:"toggleOptimization",polygon:this.turfHelper.getTurfPolygon(n),allowMerge:!0,optimizationLevel:o,originalOptimizationLevel:r.original||o,featureId:i.featureId,featureMetadata:i.metadata,sourceFeatureIds:i.sourceFeatureIds,featureInteractionOverride:i.interactionOverride,featureStyleOverrides:i.styleOverrides,featureCreatedAt:i.createdAt})}getPolygonGeoJSONFromFeatureGroup(t){try{const e=t.getLayers().find(t=>t instanceof s.Polygon);if(!e)throw new Error("No polygon found in feature group");return e.toGeoJSON()}catch(e){return _n()||(e instanceof Error?console.warn("Error getting polygon GeoJSON from feature group:",e.message):console.warn("Error getting polygon GeoJSON from feature group:",e)),{type:"Feature",geometry:{type:"Polygon",coordinates:[[[0,0],[0,1],[1,1],[1,0],[0,0]]]},properties:{}}}}getTotalPolygonPerimeter(t){try{if(!t||!t.geometry)return 0;let e=0;if("Polygon"===t.geometry.type){const r=t.geometry.coordinates;for(const t of r){const r={type:"Feature",geometry:{type:"Polygon",coordinates:[t]},properties:{}};e+=this.turfHelper.getPolygonPerimeter(r)}}else if("MultiPolygon"===t.geometry.type){const r=t.geometry.coordinates;for(const t of r)for(const r of t){const t={type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}};e+=this.turfHelper.getPolygonPerimeter(t)}}return 1e3*e}catch(e){return _n()||(e instanceof Error?console.warn("Error calculating total polygon perimeter:",e.message):console.warn("Error calculating total polygon perimeter:",e)),1e3*this.turfHelper.getPolygonPerimeter(t)}}generateInfoMarkerPopup(t,e){var r,o;const n=new Bn(e,this.config),i=new zn(t,this.config),a=this.config.markers.markerInfoIcon??{},l=!1!==a.showArea,c=!1!==a.showPerimeter,h=!1!==a.useMetrics,u=null==(r=a.areaLabel)?void 0:r.trim(),g=null==(o=a.perimeterLabel)?void 0:o.trim(),d=document.createElement("div");d.classList.add("info-marker-outer-wrapper");const p=document.createElement("div");p.classList.add("info-marker-wrapper");const f=document.createElement("div");f.classList.add("content");const y=document.createElement("div");if(y.classList.add("info-marker-content"),l){const t=h?`${i.metricArea} ${i.metricUnit}`:`${i.imperialArea} ${i.imperialUnit}`,e=document.createElement("div");e.classList.add("info-item","area"),e.innerHTML=u&&u.length>0?`<strong>${u}:</strong> ${t}`:t,y.appendChild(e)}if(c){const t=h?`${n.metricLength} ${n.metricUnit}`:`${n.imperialLength} ${n.imperialUnit}`,e=document.createElement("div");e.classList.add("info-item","perimeter"),e.innerHTML=g&&g.length>0?`<strong>${g}:</strong> ${t}`:t,y.appendChild(e)}f.appendChild(y),d.appendChild(p),p.appendChild(f),s.DomEvent.disableClickPropagation(d),d.style.pointerEvents="auto",d.querySelectorAll("button").forEach(t=>{t.style.pointerEvents="auto",t.addEventListener("click",t=>t.stopPropagation())});const m=window.innerWidth<=600;return Yn.createPopup({closeButton:!0,autoClose:!0,className:"info-popup"+(m?" mobile-popup":"")}).setContent(d)}}class Mi{constructor(t){i(this,"turfHelper"),i(this,"map"),i(this,"config"),i(this,"eventManager"),i(this,"getFeatureGroups"),i(this,"saveHistoryState"),i(this,"layerManager"),i(this,"geometryManager"),i(this,"interactionManager"),i(this,"onDrawCancel",t=>{this.emit("drawCancelled",t)}),i(this,"onPolygonUpdated",t=>{this.handlePolygonModified(t)}),i(this,"onMenuAction",t=>{this.handleMenuAction(t).catch(t=>{if(!_n()){const e=t instanceof Error?t.message:String(t);console.warn(`Menu action failed: ${e}`)}})}),i(this,"onCheckIntersection",t=>{const e=this.geometryManager.checkPolygonIntersection(t.polygon1,t.polygon2);t.callback(e)}),i(this,"onSubtract",t=>{this.subtractPolygon(t.subtractPolygon)}),i(this,"onPolygonDeleted",()=>{this.emit("polygonDeleted",void 0)}),this.turfHelper=t.turfHelper,this.map=t.map,this.config=t.config,this.eventManager=t.eventManager,this.getFeatureGroups=t.getFeatureGroups,this.saveHistoryState=t.saveHistoryState,this.layerManager=t.layerManager,this.initializeSpecializedManagers(t)}initializeSpecializedManagers(t){this.geometryManager=new oi({turfHelper:t.turfHelper,config:t.config}),this.interactionManager=new vi({turfHelper:t.turfHelper,polygonInformation:t.polygonInformation,map:t.map,config:t.config,modeManager:t.modeManager,eventManager:this.eventManager,saveHistoryState:t.saveHistoryState,layerManager:t.layerManager},{getFeatureGroups:this.getFeatureGroups,addFeatureGroup:t=>this.addFeatureGroupInternal(t),removeFeatureGroup:t=>this.removeFeatureGroupInternal(t)}),this.setupEventForwarding()}setupEventForwarding(){this.eventManager.on("polydraw:draw:cancel",this.onDrawCancel),this.eventManager.on("polydraw:polygon:updated",this.onPolygonUpdated),this.eventManager.on("polydraw:menu:action",this.onMenuAction),this.eventManager.on("polydraw:check:intersection",this.onCheckIntersection),this.eventManager.on("polydraw:subtract",this.onSubtract),this.eventManager.on("polydraw:polygon:deleted",this.onPolygonDeleted)}dispose(){this.eventManager.off("polydraw:draw:cancel",this.onDrawCancel),this.eventManager.off("polydraw:polygon:updated",this.onPolygonUpdated),this.eventManager.off("polydraw:menu:action",this.onMenuAction),this.eventManager.off("polydraw:check:intersection",this.onCheckIntersection),this.eventManager.off("polydraw:subtract",this.onSubtract),this.eventManager.off("polydraw:polygon:deleted",this.onPolygonDeleted),this.interactionManager.dispose()}async handlePolygonModified(t){const e=new Set(["addVertex","markerDrag","polygonDrag","polygonClone","toggleOptimization"]),r=!t.operation||!e.has(t.operation);let o=t.allowMerge;t.intelligentMerge&&"markerDrag"===t.operation&&(o=this.shouldAllowIntelligentMerge(t.polygon));const n={simplify:r,noMerge:!o,visualOptimizationLevel:t.optimizationLevel||0,originalOptimizationLevel:t.originalOptimizationLevel,skipKinkProcessing:"markerDrag"===t.operation,featureId:t.featureId,featureMetadata:t.featureMetadata,sourceFeatureIds:t.sourceFeatureIds,featureInteractionOverride:t.featureInteractionOverride,featureStyleOverrides:t.featureStyleOverrides,featureCreatedAt:t.featureCreatedAt,featureLastModified:t.featureLastModified};await this.addPolygon(t.polygon,n)}async handleMenuAction(t){var e,r,o,n;if(!(null==t?void 0:t.featureGroup))return;if(this.layerManager&&!this.layerManager.isFeatureGroupEditable(t.featureGroup))return;let i;try{i=this.getCompletePolygonFromFeatureGroup(t.featureGroup)}catch(u){if(!_n()){const t=u instanceof Error?u.message:String(u);console.warn(`Menu action skipped: unable to resolve polygon geometry (${t}).`)}return}const{level:a,original:l}=this.getOptimizationMetadataFromFeatureGroup(t.featureGroup),c=this.getFeatureMetadataStateFromFeatureGroup(t.featureGroup);let h;switch(t.action){case"simplify":h=this.geometryManager.simplifyPolygon(i);break;case"bbox":h=this.geometryManager.convertToBoundingBox(i);break;case"doubleElbows":h=this.geometryManager.doubleElbowsPolygon(i);break;case"bezier":h=this.geometryManager.bezierifyPolygon(i);break;default:return}if(h.success&&h.result){this.saveHistoryState&&this.saveHistoryState(t.action),this.removeFeatureGroupInternal(t.featureGroup);const i="bezier"===t.action?(null==(e=this.config.polygonTools.bezier)?void 0:e.visualOptimizationLevel)??10:a,u="bezier"===t.action?(null==(r=this.config.polygonTools.bezier)?void 0:r.visualOptimizationLevel)??10:l,g=await this.addPolygon(h.result,{simplify:!1,visualOptimizationLevel:i,originalOptimizationLevel:u,featureId:c.featureId,featureMetadata:c.metadata,sourceFeatureIds:c.sourceFeatureIds,featureInteractionOverride:c.interactionOverride,featureStyleOverrides:c.styleOverrides,featureCreatedAt:c.createdAt});if("bezier"===t.action&&(null==(o=this.config.polygonTools.bezier)?void 0:o.ghostMarkers)){const t=.001;null==(n=g.featureGroups)||n.forEach(e=>{e.eachLayer(e=>{if(e instanceof s.Polygon){const r=e;r.setStyle({opacity:t,fillOpacity:t}),r._polydrawDragData&&(r._polydrawDragData.originalOpacity=t)}})})}}}get polygonInteractionManager(){return this.interactionManager}on(t,e){this.eventManager.on(t,e)}emit(t,e){this.eventManager.emit(t,e)}async addPolygon(t,e={}){if(this.layerManager&&e.targetLayerId){if(!this.layerManager.getLayer(e.targetLayerId))return{success:!1,error:`Layer "${e.targetLayerId}" does not exist`}}const{polygons:r,skipMerge:o}=this.preparePolygonsForAddition(t,e),n=[];for(const i of r){const t=await this.addPolygonWithMergeHandling(i,e,o);if(!t.success)return t;t.featureGroups&&t.featureGroups.length>0&&n.push(...t.featureGroups)}return{success:!0,featureGroups:n.length>0?n:void 0}}async addPolygonWithMergeHandling(t,e,r){const{noMerge:o=!1}=e;try{return this.isPolygonInsideExistingHole(t)?await this.addPolygonLayer(t,e):this.config.mergePolygons&&!o&&this.getFeatureGroups().length>0&&!r?await this.mergePolygon(t,e):await this.addPolygonLayer(t,e)}catch(n){return{success:!1,error:n instanceof Error?n.message:"Unknown error in addPolygon"}}}preparePolygonsForAddition(t,e={}){let r=!1;try{r=this.turfHelper.hasKinks(t)}catch(o){_n()||console.warn("Error detecting polygon kinks:",o instanceof Error?o.message:String(o))}if(!(!0===e.skipKinkProcessing)&&!this.config.kinks&&r)try{const e=this.turfHelper.getKinks(t);if(e.length>0)return{polygons:e,skipMerge:!1}}catch(o){_n()||console.warn("Error splitting polygon kinks:",o instanceof Error?o.message:String(o))}return{polygons:[t],skipMerge:this.config.kinks&&r}}async subtractPolygon(t,e={}){const{simplify:r=!0,visualOptimizationLevel:o,originalOptimizationLevel:n}=e;try{const a=[],s=this.layerManager;(s?s.getFeatureGroupsForLayer(e.targetLayerId||s.getActiveLayerId()).filter(t=>s.isFeatureGroupEditable(t)):this.getFeatureGroups()).forEach(e=>{try{const r=e.toGeoJSON();if(!r||!r.features||!r.features[0])return;const o=r.features[0];if(!o.geometry||!o.geometry.coordinates)return;const n=this.turfHelper.getTurfPolygon(o);this.geometryManager.checkPolygonIntersection(n,t)&&a.push(e)}catch(r){_n()||console.warn("Skipping feature group during intersection check:",r)}});const l=[];for(const e of a)try{const i=this.getFeatureMetadataStateFromFeatureGroup(e),a=e.toGeoJSON(),s=this.turfHelper.getTurfPolygon(a.features[0]),c=this.geometryManager.subtractPolygon(s,t);if(this.removeFeatureGroupInternal(e),c.success&&c.results)for(const t of c.results){const e=await this.addPolygonLayer(t,{simplify:r,visualOptimizationLevel:o,originalOptimizationLevel:n,featureMetadata:i.metadata,sourceFeatureIds:i.sourceFeatureIds,featureInteractionOverride:i.interactionOverride,featureStyleOverrides:i.styleOverrides,featureCreatedAt:i.createdAt});e.success&&e.featureGroups&&l.push(...e.featureGroups)}}catch(i){_n()||console.warn("Failed subtract operation for one feature group:",i)}return this.emit("polygonSubtracted",{subtractedPolygon:t,affectedFeatureGroups:a,resultFeatureGroups:l}),this.emit("polygonOperationComplete",{operation:"subtract",polygon:t,resultFeatureGroups:l}),{success:!0,featureGroups:l}}catch(i){return{success:!1,error:i instanceof Error?i.message:"Unknown error in subtractPolygon"}}}async addPolygonLayer(t,e={}){const{simplify:r=!0,dynamicTolerance:o=!1,visualOptimizationLevel:n=0,originalOptimizationLevel:i,targetLayerId:a,layerColor:l,featureId:c,featureMetadata:h,sourceFeatureIds:u,featureInteractionOverride:g,featureStyleOverrides:d,featureCreatedAt:p,featureLastModified:f}=e;try{if(!t||!t.geometry||!t.geometry.coordinates)return{success:!1,error:"Invalid polygon data"};const e=this.layerManager?a||this.layerManager.getActiveLayerId():void 0,y=!this.layerManager||!e||this.layerManager.isLayerEditable(e),m=void 0===g?y:"editable"===g;let v=l;if(!v&&this.layerManager&&e){const t=this.layerManager.getLayer(e);t&&(v=t.color)}else if(!v&&this.layerManager){const t=this.layerManager.getActiveLayer();t&&this.layerManager.getLayerCount()>1&&(v=t.color)}const M=new s.FeatureGroup,w=r?this.turfHelper.getSimplified(t,o):t,b=this.normalizeSinglePolygonFeature(w);let P,L,k=n;try{if(P=this.getPolygon(b,v,{enableDragging:m,styleOverrides:d}),!P)return{success:!1,error:"Failed to create polygon"};P._polydrawOptimizationLevel=n,k=i??P._polydrawOptimizationOriginalLevel??n,P._polydrawOptimizationOriginalLevel=k||0,M.addLayer(P),this.interactionManager.suppressDeleteMarkerClicks(250)}catch{return{success:!1,error:"Failed to create polygon layer"}}this.setFeatureGroupMetadata(M,{featureId:c,metadata:h,sourceFeatureIds:u,interactionOverride:g,styleOverrides:d,optimizationLevel:n,originalOptimizationLevel:k,hasHoles:this.featureHasHoles(b),layerId:e,createdAt:p,lastModified:f});try{const t=P.getLatLngs();L=this.normalizePolygonCoordinates(t)}catch{L=[]}if(m){try{L.forEach((t,e)=>{if(!t||!Array.isArray(t))return;const r=[];if(t.forEach(t=>{Array.isArray(t)&&t.length>=2?r.push({lat:t[1],lng:t[0]}):"object"==typeof t&&null!==t&&"lat"in t&&"lng"in t&&r.push(t)}),0!==r.length)try{if(0===e)this.interactionManager.addMarkers(r,M,{optimizationLevel:n,originalOptimizationLevel:k});else{const t=Yn.createPolyline(r,{color:this.config.styles.hole.color,weight:this.config.styles.hole.weight||2,opacity:this.config.styles.hole.opacity||1,fillColor:this.config.styles.hole.fillColor,fillOpacity:this.config.styles.hole.fillOpacity||.5});M.addLayer(t),this.interactionManager.addHoleMarkers(r,M)}}catch{}})}catch{}try{this.interactionManager.addEdgeClickListeners(P,M)}catch{}}if(this.getFeatureGroups().push(M),this.layerManager){const t=e||this.layerManager.getActiveLayerId();if(!this.layerManager.assignFeatureGroupToLayer(M,t))return this.removeFeatureGroupInternal(M),{success:!1,error:`Failed to assign polygon to layer "${t}"`}}try{M.addTo(this.map)}catch{}return this.interactionManager.updateMarkerDraggableState(),this.emit("polygonAdded",{polygon:b,featureGroup:M}),this.emit("polygonOperationComplete",{operation:"add",polygon:b,featureGroup:M}),{success:!0,featureGroups:[M]}}catch(y){return{success:!1,error:y instanceof Error?y.message:"Unknown error in addPolygonLayer"}}}async mergePolygon(t,e={}){try{const r=[],o=[];let n=!1;const i=!1!==e.mergeEditableOnly,a=this.layerManager;return(a?a.getFeatureGroupsForLayer(e.targetLayerId||a.getActiveLayerId()).filter(t=>!i||a.isFeatureGroupEditable(t)):this.getFeatureGroups()).forEach(e=>{try{const i=e.toGeoJSON();if(!i||!i.features||!i.features[0])return;const a=i.features[0];if(!a.geometry||!a.geometry.coordinates)return;if(this.isPositionArrayofArrays(a.geometry.coordinates))a.geometry.coordinates.forEach(i=>{try{const a=this.turfHelper.getMultiPolygon([i]);n=this.geometryManager.checkPolygonIntersection(a,t),n&&(o.push(e),r.push(a))}catch{}});else try{const i=this.turfHelper.getTurfPolygon(a);n=this.geometryManager.checkPolygonIntersection(i,t),n&&(o.push(e),r.push(i))}catch{}}catch{}}),o.length>0?await this.unionPolygons(o,t,r,e):await this.addPolygonLayer(t,e)}catch(r){return{success:!1,error:r instanceof Error?r.message:"Unknown error in mergePolygon"}}}async unionPolygons(t,e,r,o={}){try{const n=this.collectSourceFeatureIds(t,o.sourceFeatureIds),i=o.featureMetadata??this.resolvePrimaryFeatureMetadata(t),a=o.featureInteractionOverride??this.resolvePrimaryFeatureInteractionOverride(t),s=o.featureStyleOverrides??this.resolvePrimaryFeatureStyleOverrides(t);t.forEach(t=>{this.removeFeatureGroupInternal(t)});const l=this.geometryManager.unionPolygons(r,e);if(l.success&&l.result){const t=await this.addPolygonLayer(l.result,{...o,featureMetadata:i,sourceFeatureIds:n,featureInteractionOverride:a,featureStyleOverrides:s});return this.emit("polygonsUnioned",{originalPolygons:r,resultPolygon:l.result,featureGroups:t.featureGroups}),t}return{success:!1,error:l.error||"Failed to union polygons"}}catch(n){return{success:!1,error:n instanceof Error?n.message:"Unknown error in unionPolygons"}}}shouldAllowIntelligentMerge(t){try{const e=this.layerManager,r=e?e.getFeatureGroupsForLayer(e.getActiveLayerId()).filter(t=>e.isFeatureGroupEditable(t)):this.getFeatureGroups();for(const o of r)try{const e=o.toGeoJSON();if(!e||!e.features||!e.features[0])continue;const r=e.features[0];if(!r.geometry||!r.geometry.coordinates)continue;const n=this.turfHelper.getTurfPolygon(r);if(this.geometryManager.checkPolygonIntersection(n,t))return!0}catch{continue}return!1}catch{return!1}}isPolygonInsideExistingHole(t){try{const e=this.layerManager,r=e?e.getFeatureGroupsForLayer(e.getActiveLayerId()).filter(t=>e.isFeatureGroupEditable(t)):this.getFeatureGroups();for(const o of r)try{const e=o.toGeoJSON();if(!e||!e.features||!e.features[0])continue;const r=e.features[0];if(!r.geometry||!r.geometry.coordinates)continue;let n=!1,i=[];if("Polygon"===r.geometry.type)n=r.geometry.coordinates.length>1,n&&(i=r.geometry.coordinates.slice(1));else if("MultiPolygon"===r.geometry.type)for(const t of r.geometry.coordinates)t.length>1&&(n=!0,i.push(...t.slice(1)));if(n&&i.length>0)for(const o of i)try{const e=this.turfHelper.createPolygon([o]);if(this.turfHelper.isPolygonCompletelyWithin(t,e))return!0}catch{continue}}catch{continue}return!1}catch{return!1}}normalizePolygonCoordinates(t){if(!Array.isArray(t)||0===t.length)return[];const e=t=>null!==t&&"object"==typeof t&&"lat"in t&&"lng"in t&&"number"==typeof t.lat&&"number"==typeof t.lng,r=t=>{if(!Array.isArray(t))return[];if(t.length>0&&e(t[0]))return[t];const o=[];for(const n of t)if(Array.isArray(n))if(n.length>0&&e(n[0]))o.push(n);else{const t=r(n);o.push(...t)}return o};try{return r(t)}catch{return[]}}isPositionArrayofArrays(t){if(!Array.isArray(t)||0===t.length)return!1;const e=t[0];if(!Array.isArray(e)||0===e.length)return!1;const r=e[0];if(!Array.isArray(r)||0===r.length)return!1;const o=r[0];return this.isPosition(o)}isPosition(t){return Array.isArray(t)&&t.length>=2&&t.every(t=>"number"==typeof t)}getPolygon(t,e,r={}){const o=s.GeoJSON.geometryToLayer(t),n=e||this.config.styles.polygon.color,i=this.config.styles.polygon.fillColor,{styleOverrides:a}=r,l={...this.config.styles.polygon,color:(null==a?void 0:a.color)??n,fillColor:(null==a?void 0:a.fillColor)??i,weight:(null==a?void 0:a.weight)??this.config.styles.polygon.weight??2,opacity:this.config.styles.polygon.opacity||1,fillOpacity:(null==a?void 0:a.fillOpacity)??this.config.styles.polygon.fillOpacity??.2};o.setStyle(l),o._polydrawUniqueId=Yn.util.stamp(o)+"_"+Date.now(),delete o._polydrawDragData,delete o._polydrawOriginalLatLngs,delete o._polydrawCurrentDragSession,delete o._polydrawOriginalMarkerPositions,delete o._polydrawOriginalHoleLinePositions;return!1!==r.enableDragging&&(this.config.modes.dragPolygons||this.config.tools.clone)&&this.interactionManager.enablePolygonDragging(o,t),o}normalizeSinglePolygonFeature(t){if("MultiPolygon"===t.geometry.type&&1===t.geometry.coordinates.length){const[e]=t.geometry.coordinates;try{return this.turfHelper.createPolygon(e)}catch{return t}}return t}addFeatureGroupInternal(t){this.getFeatureGroups().push(t)}removeFeatureGroupInternal(t){this.cleanupFeatureGroup(t),this.layerManager&&this.layerManager.removeFeatureGroupFromLayer(t);try{t.clearLayers()}catch(o){_n()||console.warn("Error clearing layers from feature group:",o)}const e=this.getFeatureGroups(),r=e.indexOf(t);r>-1&&e.splice(r,1);try{this.map.removeLayer(t)}catch(o){_n()||console.warn("Error removing feature group layer from map:",o)}}getCompletePolygonFromFeatureGroup(t){try{let e=null;if(t.eachLayer(t=>{t instanceof s.Polygon&&(e=t)}),e)return e.toGeoJSON();const r=t.toGeoJSON().features.find(t=>{var e,r;return"Polygon"===(null==(e=t.geometry)?void 0:e.type)||"MultiPolygon"===(null==(r=t.geometry)?void 0:r.type)});if(r)return r;throw new Error("No polygon geometry found in feature group")}catch(e){throw _n()||e instanceof Error&&console.warn("Error getting complete polygon GeoJSON from feature group:",e.message),e instanceof Error?e:new Error("Failed to resolve polygon geometry from feature group")}}getOptimizationMetadataFromFeatureGroup(t){if(!t)return{level:0,original:0};let e=0,r=0;return t.eachLayer(t=>{if(t instanceof s.Polygon){const o=t;"number"==typeof o._polydrawOptimizationLevel&&(e=o._polydrawOptimizationLevel||0),"number"==typeof o._polydrawOptimizationOriginalLevel&&(r=o._polydrawOptimizationOriginalLevel||0)}}),!r&&e>0&&(r=e),{level:e,original:r}}getFeatureMetadataStateFromFeatureGroup(t){if(!t)return{metadata:{},sourceFeatureIds:[]};const e=t._polydrawMetadata,r=null==e?void 0:e.id,o=Array.isArray(null==e?void 0:e.sourceFeatureIds)?[...e.sourceFeatureIds]:r?[r]:[],n=(null==e?void 0:e.createdAt)instanceof Date&&!Number.isNaN(e.createdAt.getTime())?e.createdAt.toISOString():void 0;return{featureId:r,metadata:this.cloneFeatureMetadata(null==e?void 0:e.metadata),sourceFeatureIds:o,interactionOverride:null==e?void 0:e.interactionOverride,styleOverrides:this.cloneStyleOverrides(null==e?void 0:e.styleOverrides),createdAt:n}}collectSourceFeatureIds(t,e){const r=[],o=new Set,n=t=>{t&&!o.has(t)&&(o.add(t),r.push(t))};return t.forEach(t=>{const e=t._polydrawMetadata;Array.isArray(null==e?void 0:e.sourceFeatureIds)&&e.sourceFeatureIds.length>0?e.sourceFeatureIds.forEach(t=>n(t)):n(null==e?void 0:e.id)}),Array.isArray(e)&&e.forEach(t=>n(t)),r}resolvePrimaryFeatureMetadata(t){var e;for(const r of t){const t=null==(e=r._polydrawMetadata)?void 0:e.metadata;if(t&&Object.keys(t).length>0)return this.cloneFeatureMetadata(t)}return{}}resolvePrimaryFeatureInteractionOverride(t){var e;for(const r of t){const t=null==(e=r._polydrawMetadata)?void 0:e.interactionOverride;if(t)return t}}resolvePrimaryFeatureStyleOverrides(t){var e;for(const r of t){const t=null==(e=r._polydrawMetadata)?void 0:e.styleOverrides;if(t)return this.cloneStyleOverrides(t)}}cloneFeatureMetadata(t){return t?{...t}:{}}cloneStyleOverrides(t){if(t)return{...t}}featureHasHoles(t){return!!(null==t?void 0:t.geometry)&&("Polygon"===t.geometry.type?t.geometry.coordinates.length>1:"MultiPolygon"===t.geometry.type&&t.geometry.coordinates.some(t=>t.length>1))}setFeatureGroupMetadata(t,e){const r=new Date,o=e.createdAt?new Date(e.createdAt):r,n=e.lastModified?new Date(e.lastModified):r,i=Number.isNaN(o.getTime())?r:o,a=Number.isNaN(n.getTime())?r:n,s=e.featureId||`fg-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,l=e.sourceFeatureIds&&e.sourceFeatureIds.length>0?[...new Set(e.sourceFeatureIds)]:[s];t._polydrawMetadata={id:s,optimizationLevel:e.optimizationLevel,originalOptimizationLevel:e.originalOptimizationLevel,hasHoles:e.hasHoles,createdAt:i,lastModified:a,layerId:e.layerId,metadata:this.cloneFeatureMetadata(e.metadata),sourceFeatureIds:l,interactionOverride:e.interactionOverride,styleOverrides:this.cloneStyleOverrides(e.styleOverrides)}}updateMarkerDraggableState(){this.interactionManager.updateMarkerDraggableState()}updateAllMarkersForEdgeDeletion(t){this.interactionManager.updateAllMarkersForEdgeDeletion(t)}setModifierKeyHeld(t){this.interactionManager.setModifierKeyHeld(t)}checkPolygonIntersection(t,e){return this.geometryManager.checkPolygonIntersection(t,e)}getPolygonCenter(t){try{if(!t||!t.geometry||!t.geometry.coordinates)return null;let e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else{if("MultiPolygon"!==t.geometry.type)return null;e=t.geometry.coordinates[0][0]}if(!Array.isArray(e)||0===e.length)return null;let r=0,o=0,n=0;for(const t of e)if(Array.isArray(t)&&t.length>=2){const e=t[0],i=t[1];"number"!=typeof e||"number"!=typeof i||isNaN(e)||isNaN(i)||(o+=e,r+=i,n++)}return 0===n?null:{lat:r/n,lng:o/n}}catch{return null}}getBoundingBox(t){try{if(!t||!t.geometry||!t.geometry.coordinates)return null;let e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else{if("MultiPolygon"!==t.geometry.type)return null;e=t.geometry.coordinates[0][0]}if(!Array.isArray(e)||0===e.length)return null;let r=1/0,o=-1/0,n=1/0,i=-1/0;for(const t of e)if(Array.isArray(t)&&t.length>=2){const e=t[0],a=t[1];"number"!=typeof e||"number"!=typeof a||isNaN(e)||isNaN(a)||(n=Math.min(n,e),i=Math.max(i,e),r=Math.min(r,a),o=Math.max(o,a))}return r===1/0||o===-1/0||n===1/0||i===-1/0?null:{minLat:r,maxLat:o,minLng:n,maxLng:i}}catch{return null}}addMarker(t,e,r){this.interactionManager.addMarkers(t,e,r)}addHoleMarker(t,e){this.interactionManager.addHoleMarkers(t,e)}addEdgeClickListeners(t,e){this.interactionManager.addEdgeClickListeners(t,e)}enablePolygonDragging(t,e){this.interactionManager.enablePolygonDragging(t,e)}getMarkerIndex(t,e){return 0}ensureMarkerSeparation(t,e){var r,o,n;return{menu:(null==(r=e.menu)?void 0:r.index)??0,delete:(null==(o=e.delete)?void 0:o.index)??1,info:(null==(n=e.info)?void 0:n.index)??2}}findAlternativeMarkerPosition(t,e,r){return(e+1)%t}createDivIcon(t){return Yn.createDivIcon({className:t.join(" ")})}getLatLngInfoString(t){return"Latitude: "+t.lat+" Longitude: "+t.lng}generateMenuMarkerPopup(t,e){const r=document.createElement("div");return r.innerHTML="Menu",r}getPolygonGeoJSONFromFeatureGroup(t){return{type:"Feature",geometry:{type:"Polygon",coordinates:[[[0,0],[0,1],[1,1],[1,0],[0,0]]]},properties:{}}}getTotalPolygonPerimeter(t){return 1e3}generateInfoMarkerPopup(t,e){const r=document.createElement("div");return r.innerHTML=`Area: ${t}, Perimeter: ${e}`,r}onMarkerHoverForEdgeDeletion(t,e){}highlightEdgeOnHover(t,e){}onEdgeClick(t,e){}removeFeatureGroup(t){this.removeFeatureGroupInternal(t)}cleanupFeatureGroup(t){this.interactionManager.cleanupFeatureGroup(t)}onPolygonMouseMove(t){}onPolygonMouseUp(t){}updatePolygonAfterDrag(t){}setSubtractVisualMode(t,e){}performModifierSubtract(t,e){try{const r=this.turfHelper.getTurfPolygon(t),o=[];this.getFeatureGroups().forEach(t=>{if(t!==e)try{const e=t.toGeoJSON();if(!e||!e.features||!e.features[0])return;const n=e.features[0];if(!n.geometry||!n.geometry.coordinates)return;const i=this.turfHelper.getTurfPolygon(n);this.geometryManager.checkPolygonIntersection(i,r)&&o.push(t)}catch{}}),this.removeFeatureGroupInternal(e),o.forEach(t=>{try{const e=t.toGeoJSON(),o=this.turfHelper.getTurfPolygon(e.features[0]);this.removeFeatureGroupInternal(t);const n=this.geometryManager.subtractPolygon(o,r);if(n.success&&n.results)for(const t of n.results)this.addPolygonLayer(t,{simplify:!0})}catch{}})}catch{}}}class wi{constructor(t,e=50){i(this,"undoStack",[]),i(this,"redoStack",[]),i(this,"maxHistorySize",50),i(this,"maxSnapshotSize",5e5),i(this,"maxTotalMemory",5e6),i(this,"currentMemoryUsage",0),i(this,"eventManager"),i(this,"isRestoring",!1),this.eventManager=t,this.maxHistorySize=e}setMaxHistorySize(t){!Number.isFinite(t)||t<=0||(this.maxHistorySize=Math.floor(t),this.enforceMemoryBudget(),this.enforceRedoMemoryBudget())}saveState(t,e,r){if(this.isRestoring)return;const o=this.createSnapshot(t,e,r),n=this.calculateSnapshotSize(o);o.size=n,n>this.maxSnapshotSize?console.warn(`History snapshot too large (${n} bytes, limit ${this.maxSnapshotSize} bytes). Skipping save.`):(this.redoStack=[],this.undoStack.push(o),this.currentMemoryUsage+=n,this.enforceMemoryBudget(),this.eventManager.emit("polydraw:history:changed",{canUndo:this.canUndo(),canRedo:this.canRedo()}))}calculateSnapshotSize(t){try{return 2*JSON.stringify(t).length}catch(e){return console.warn("Error calculating snapshot size:",e),0}}enforceMemoryBudget(){for(;this.undoStack.length>this.maxHistorySize;){const t=this.undoStack.shift();t&&(this.currentMemoryUsage-=this.getSnapshotSize(t))}for(;this.currentMemoryUsage>this.maxTotalMemory&&this.undoStack.length>0;){const t=this.undoStack.shift();t&&(this.currentMemoryUsage-=this.getSnapshotSize(t))}}enforceRedoMemoryBudget(){const t=Math.floor(this.maxHistorySize/2);for(;this.redoStack.length>t;)this.redoStack.shift()}undo(t,e){if(!this.canUndo())return null;const r=this.createSnapshot(t,"redo-point",e),o=this.calculateSnapshotSize(r);r.size=o,o<=this.maxSnapshotSize?(this.redoStack.push(r),this.enforceRedoMemoryBudget()):console.warn(`Current state too large (${o} bytes) to save to redo stack.`);const n=this.undoStack.pop();return this.currentMemoryUsage-=this.getSnapshotSize(n),this.eventManager.emit("polydraw:history:undo",{canUndo:this.canUndo(),canRedo:this.canRedo(),action:n.action}),n}redo(t,e){if(!this.canRedo())return null;const r=this.createSnapshot(t,"undo-point",e),o=this.calculateSnapshotSize(r);r.size=o,o<=this.maxSnapshotSize?(this.undoStack.push(r),this.currentMemoryUsage+=o,this.enforceMemoryBudget()):console.warn(`Current state too large (${o} bytes) to save to undo stack.`),this.enforceRedoMemoryBudget();const n=this.redoStack.pop();return this.eventManager.emit("polydraw:history:redo",{canUndo:this.canUndo(),canRedo:this.canRedo(),action:n.action}),n}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}clear(){this.undoStack=[],this.redoStack=[],this.currentMemoryUsage=0,this.eventManager.emit("polydraw:history:changed",{canUndo:this.canUndo(),canRedo:this.canRedo()})}setRestoring(t){this.isRestoring=t}createSnapshot(t,e,r){const o=[],n=[];t.forEach(t=>{t.eachLayer(e=>{var r;const i=e;if(null==i?void 0:i.toGeoJSON)try{const a=i.toGeoJSON();if(!a)return;const s=null==(r=null==a?void 0:a.geometry)?void 0:r.type;"Polygon"!==s&&"MultiPolygon"!==s||(o.push(a),n.push(this.captureFeatureMetadataSnapshot(t,e)))}catch(a){console.warn("Error converting polygon to GeoJSON:",a)}})});const i={features:o,timestamp:Date.now(),action:e};return r&&(i.layerSnapshot=r.captureLayerSnapshot(t)),n.length>0&&(i.featureMetadataSnapshot=n),i}captureFeatureMetadataSnapshot(t,e){const r={},o=t._polydrawMetadata;if((null==o?void 0:o.id)&&(r.id=o.id),(null==o?void 0:o.metadata)&&(r.metadata={...o.metadata}),Array.isArray(null==o?void 0:o.sourceFeatureIds)&&(r.sourceFeatureIds=[...o.sourceFeatureIds]),(null==o?void 0:o.interactionOverride)&&(r.interactionOverride=o.interactionOverride),(null==o?void 0:o.styleOverrides)&&(r.styleOverrides={...o.styleOverrides}),"boolean"==typeof(null==o?void 0:o.hasHoles)&&(r.hasHoles=o.hasHoles),"string"==typeof(null==o?void 0:o.layerId)&&(r.layerId=o.layerId),(null==o?void 0:o.createdAt)instanceof Date&&!Number.isNaN(o.createdAt.getTime())&&(r.createdAt=o.createdAt.toISOString()),(null==o?void 0:o.lastModified)instanceof Date&&!Number.isNaN(o.lastModified.getTime())&&(r.lastModified=o.lastModified.toISOString()),e instanceof s.Polygon){const t=e;"number"==typeof t._polydrawOptimizationLevel&&(r.optimizationLevel=t._polydrawOptimizationLevel),"number"==typeof t._polydrawOptimizationOriginalLevel&&(r.originalOptimizationLevel=t._polydrawOptimizationOriginalLevel)}return r}getSnapshotSize(t){if("number"==typeof t.size)return t.size;const e=this.calculateSnapshotSize(t);return t.size=e,e}}class bi{constructor(t,e){i(this,"eventManager"),i(this,"layers",new Map),i(this,"featureGroupToLayer",new WeakMap),i(this,"activeLayerId","default"),i(this,"defaultColor"),this.eventManager=t,this.defaultColor=bi.normalizeColor(e),this.ensureDefaultLayer()}getLayerCount(){return this.layers.size}getAllLayers(){return Array.from(this.layers.values()).map(t=>this.cloneLayerState(t))}getPanelLayers(){return this.getAllLayers().filter(t=>"hidden"!==t.panel)}getPanelLayerCount(){let t=0;for(const e of this.layers.values())"hidden"!==e.panel&&(t+=1);return t}getLayer(t){const e=this.layers.get(this.normalizeLayerId(t));return e?this.cloneLayerState(e):void 0}getActiveLayerId(){return this.activeLayerId}getActiveLayer(){return this.getLayer(this.activeLayerId)}getOrCreateLayer(t,e){const r=this.normalizeLayerId(t);if(this.layers.get(r))return this.cloneLayerState(this.layers.get(r));const o="string"==typeof e?{color:e}:e||{},n={id:r,label:o.label,color:o.color?bi.normalizeColor(o.color,this.defaultColor):this.defaultColor,visible:!1!==o.visible,interaction:this.normalizeInteraction(o.interaction),panel:this.normalizePanel(o.panel),metadata:this.cloneMetadata(o.metadata),featureGroups:[]};return this.layers.set(r,n),this.eventManager.emit("polydraw:layer:created",{layerId:n.id,color:n.color}),this.cloneLayerState(n)}setActiveLayer(t){return"activated"===this.setActiveLayerWithResult(t)}setActiveLayerWithResult(t){const e=this.normalizeLayerId(t),r=this.layers.get(e);if(!r)return"not-found";if(e===this.activeLayerId)return"already-active";if(!r.visible)return"not-visible";const o=this.activeLayerId;return this.activeLayerId=e,this.eventManager.emit("polydraw:layer:activated",{layerId:e,previousLayerId:o}),"activated"}setLayerVisibility(t,e){const r=this.layers.get(this.normalizeLayerId(t));if(!r||r.visible===e)return!1;if(!e&&r.id===this.activeLayerId){const t=this.getFirstVisibleLayerId(r.id);if(!t)return!1;this.setActiveLayer(t)}return r.visible=e,this.eventManager.emit("polydraw:layer:visibility",{layerId:r.id,visible:e}),!0}setLayerColor(t,e){const r=this.layers.get(this.normalizeLayerId(t)),o=bi.normalizeColor(e,(null==r?void 0:r.color)??this.defaultColor);return!(!r||r.color===o)&&(r.color=o,r.featureGroups.forEach(t=>{var e,r;const n=null==(r=null==(e=t._polydrawMetadata)?void 0:e.styleOverrides)?void 0:r.color;t.eachLayer(t=>{t instanceof s.Polygon&&!(t instanceof s.Rectangle)&&t.setStyle({color:n??o})})}),this.eventManager.emit("polydraw:layer:colorChanged",{layerId:r.id,color:r.color}),!0)}setLayerLabel(t,e){const r=this.layers.get(this.normalizeLayerId(t));if(!r)return!1;const o="string"==typeof e?e.trim():void 0,n=o&&o.length>0?o:void 0;return r.label!==n&&(r.label=n,!0)}setLayerInteraction(t,e){const r=this.layers.get(this.normalizeLayerId(t));if(!r)return!1;const o=this.normalizeInteraction(e);return r.interaction!==o&&(r.interaction=o,!0)}setLayerPanelVisibility(t,e){const r=this.layers.get(this.normalizeLayerId(t));if(!r)return!1;const o=this.normalizePanel(e);return r.panel!==o&&(r.panel=o,!0)}setLayerMetadata(t,e){const r=this.layers.get(this.normalizeLayerId(t));return!!r&&(r.metadata=this.cloneMetadata(e),!0)}isLayerEditable(t){const e=this.layers.get(this.normalizeLayerId(t));return!e||"editable"===e.interaction}isFeatureGroupEditable(t){var e;const r=null==(e=t._polydrawMetadata)?void 0:e.interactionOverride;if(r)return"editable"===r;const o=this.getLayerForFeatureGroup(t);return!o||this.isLayerEditable(o)}moveLayer(t,e){const r=this.normalizeLayerId(t),o=this.normalizeLayerId(e);if(r===o)return!1;if("default"===r||"default"===o)return!1;if(!this.layers.has(r)||!this.layers.has(o))return!1;const n=Array.from(this.layers.keys()),i=n.indexOf(r),a=n.indexOf(o);if(i<0||a<0)return!1;const[s]=n.splice(i,1);n.splice(a,0,s);const l=new Map;for(const c of n){const t=this.layers.get(c);t&&l.set(c,t)}return this.layers=l,this.eventManager.emit("polydraw:layer:reordered",{layerId:r,targetLayerId:o,orderedLayerIds:n}),!0}assignFeatureGroupToLayer(t,e){const r=this.normalizeLayerId(e);if(!this.layers.has(r))return!1;const o=this.getLayerForFeatureGroup(t);if(o){const e=this.layers.get(o);e&&(e.featureGroups=e.featureGroups.filter(e=>e!==t))}const n=this.layers.get(r);n.featureGroups.includes(t)||n.featureGroups.push(t),this.featureGroupToLayer.set(t,r);const i=t._polydrawMetadata;return i&&(i.layerId=r),!0}removeFeatureGroupFromLayer(t){const e=this.getLayerForFeatureGroup(t);if(!e)return;const r=this.layers.get(e);r&&(r.featureGroups=r.featureGroups.filter(e=>e!==t)),this.featureGroupToLayer.delete(t)}getLayerForFeatureGroup(t){const e=this.featureGroupToLayer.get(t);if(e)return e;for(const[r,o]of this.layers.entries())if(o.featureGroups.includes(t))return this.featureGroupToLayer.set(t,r),r}getFeatureGroupsForLayer(t){const e=this.layers.get(this.normalizeLayerId(t));return e?[...e.featureGroups]:[]}isInActiveLayer(t){const e=this.getLayerForFeatureGroup(t);return!e||e===this.activeLayerId}deleteLayer(t){const e=this.normalizeLayerId(t);if("default"===e)return[];const r=this.layers.get(e);if(!r)return[];const o=[...r.featureGroups];if(o.forEach(t=>{this.featureGroupToLayer.delete(t)}),this.layers.delete(e),this.activeLayerId===e){const t=this.getFirstVisibleLayerId(e);t?this.setActiveLayer(t):this.activeLayerId="default"}return this.eventManager.emit("polydraw:layer:deleted",{layerId:e,removedFeatureGroups:o}),o}clear(t){t&&(this.defaultColor=bi.normalizeColor(t,this.defaultColor)),this.layers=new Map,this.featureGroupToLayer=new WeakMap,this.activeLayerId="default",this.ensureDefaultLayer()}captureLayerSnapshot(t){const e=new Map;return t.forEach((t,r)=>{e.set(t,r)}),{layers:this.getAllLayers().map(t=>({id:t.id,label:t.label,color:t.color,visible:t.visible,interaction:t.interaction,panel:t.panel,metadata:this.cloneMetadata(t.metadata),featureIndices:t.featureGroups.map(t=>e.get(t)).filter(t=>"number"==typeof t)})),activeLayerId:this.activeLayerId}}restoreFromLayerSnapshot(t,e){if(this.clear(),!t||!Array.isArray(t.layers))return;t.layers.forEach(t=>{const e=this.normalizeLayerId(t.id),r=this.layers.get(e);r?(r.label="string"==typeof t.label?t.label:void 0,r.color=t.color?bi.normalizeColor(t.color):r.color,r.visible=!1!==t.visible,r.interaction=this.normalizeInteraction(t.interaction),r.panel=this.normalizePanel(t.panel),r.metadata=this.cloneMetadata(t.metadata)):this.layers.set(e,{id:e,label:"string"==typeof t.label?t.label:void 0,color:t.color?bi.normalizeColor(t.color):this.defaultColor,visible:!1!==t.visible,interaction:this.normalizeInteraction(t.interaction),panel:this.normalizePanel(t.panel),metadata:this.cloneMetadata(t.metadata),featureGroups:[]})}),this.ensureDefaultLayer(),t.layers.forEach(t=>{const r=this.normalizeLayerId(t.id),o=this.layers.get(r);o&&t.featureIndices.forEach(t=>{const n=e[t];n&&(o.featureGroups.includes(n)||o.featureGroups.push(n),this.featureGroupToLayer.set(n,r))})});const r=this.normalizeLayerId(t.activeLayerId||"default"),o=this.layers.get(r);if(o&&o.visible)return void(this.activeLayerId=r);const n=this.getFirstVisibleLayerId();if(n)return void(this.activeLayerId=n);const i=this.layers.get("default");i&&(i.visible=!0),this.activeLayerId="default"}ensureDefaultLayer(){this.layers.has("default")||this.layers.set("default",{id:"default",color:this.defaultColor,visible:!0,interaction:"editable",panel:"visible",metadata:{},featureGroups:[]})}getFirstVisibleLayerId(t){for(const e of this.layers.values())if(e.id!==t&&e.visible)return e.id}normalizeLayerId(t){const e=(t||"").trim();return e.length>0?e:"default"}cloneLayerState(t){return{id:t.id,label:t.label,color:t.color,visible:t.visible,interaction:t.interaction,panel:t.panel,metadata:this.cloneMetadata(t.metadata),featureGroups:[...t.featureGroups]}}normalizeInteraction(t){return"readonly"===t||"static"===t?t:"editable"}normalizePanel(t){return"hidden"===t?"hidden":"visible"}cloneMetadata(t){return t?{...t}:{}}static normalizeColor(t,e="#50622b"){let r=(t||"").trim().replace(/^#/,"");return 3===r.length&&(r=`${r[0]}${r[0]}${r[1]}${r[1]}${r[2]}${r[2]}`),/^[0-9a-fA-F]{6}$/.test(r)?`#${r.toLowerCase()}`:e}}const Pi=t=>t.replace(/#(?:fff|ffffff)/gi,"currentColor"),Li={grip:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">\n <circle cx="9" cy="5" r="1" />\n <circle cx="9" cy="12" r="1" />\n <circle cx="9" cy="19" r="1" />\n <circle cx="15" cy="5" r="1" />\n <circle cx="15" cy="12" r="1" />\n <circle cx="15" cy="19" r="1" />\n</svg>\n'.trim(),eyeVisible:Pi('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">\n <defs>\n <mask id="pupil-hole-hide">\n <rect width="512" height="512" fill="white"/>\n <circle cx="256" cy="220" r="60" fill="black"/>\n </mask>\n </defs>\n <g fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round">\n \x3c!-- Upper eye contour --\x3e\n <path d="M24 256 C 120 93 392 93 488 256" stroke-width="48"/>\n \x3c!-- Lower eye contour --\x3e\n <path d="M24 256 C 120 419 392 419 488 256" stroke-width="48"/>\n \x3c!-- Iris highlight --\x3e\n <circle cx="256" cy="234" r="108" fill="#fff" stroke="none" mask="url(#pupil-hole-hide)"/>\n </g>\n</svg>\n'.trim()),eyeHidden:Pi('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">\n <g fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round">\n \x3c!-- Upper eye contour --\x3e\n <path d="M24 256 C 120 93 392 93 488 256" stroke-width="48"/>\n \x3c!-- Lower eye contour --\x3e\n <path d="M24 256 C 120 419 392 419 488 256" stroke-width="48"/>\n \x3c!-- Diagonal hide slash --\x3e\n <path d="M48 408 L464 104" stroke-width="48"/>\n </g>\n</svg>\n'.trim()),delete:qn.trim(),toggle:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor">\n <path d="M3 7.5 12 3l9 4.5L12 12 3 7.5Z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />\n <path d="M3 12.5 12 17l9-4.5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />\n <path d="M3 17 12 21l9-4" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />\n <polyline points="14 9.5 17 12 14 14.5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />\n</svg>\n'.trim()};class ki{static calculateAngle(t,e,r){const o=t.lng-e.lng,n=t.lat-e.lat,i=r.lng-e.lng,a=r.lat-e.lat,s=o*i+n*a,l=Math.sqrt(o*o+n*n),c=Math.sqrt(i*i+a*a);if(0===l||0===c)return 0;const h=s/(l*c);return Math.acos(Math.max(-1,Math.min(1,h)))}static calculateDistanceFromLine(t,e,r){const o=e.lng-t.lng,n=e.lat-t.lat,i=r.lng-t.lng,a=r.lat-t.lat,s=o*i+n*a,l=i*i+a*a;if(0===l)return Math.sqrt(o*o+n*n);const c=s/l;let h,u;c<0?(h=t.lng,u=t.lat):c>1?(h=r.lng,u=r.lat):(h=t.lng+c*i,u=t.lat+c*a);const g=e.lng-h,d=e.lat-u;return Math.sqrt(g*g+d*d)}static calculateCentroid(t){return Wn.getCenter(t)}static calculateDistance(t,e){const r=t.lng-e.lng,o=t.lat-e.lat;return Math.sqrt(r*r+o*o)}static offsetPolygonCoordinates(t,e,r){return t?Array.isArray(t[0])?t.map(t=>ki.offsetPolygonCoordinates(t,e,r)):void 0!==t.lat&&void 0!==t.lng?{lat:t.lat+e,lng:t.lng+r}:t.map(t=>ki.offsetPolygonCoordinates(t,e,r)):t}}class xi{static convertToCoords(t,e){const r=[];if(t.length>1&&t.length<3){const o=[];e.isWithin(s.GeoJSON.latLngsToCoords(t[t.length-1]),s.GeoJSON.latLngsToCoords(t[0]))?t.forEach(t=>{o.push(s.GeoJSON.latLngsToCoords(t))}):t.forEach(t=>{r.push([s.GeoJSON.latLngsToCoords(t)])}),o.length>=1&&r.push(o)}else if(t.length>2){const o=[];for(let n=1;n<t.length-1;n++){e.isWithin(s.GeoJSON.latLngsToCoords(t[n]),s.GeoJSON.latLngsToCoords(t[0]))?(t.forEach(t=>{o.push(s.GeoJSON.latLngsToCoords(t))}),r.push(o)):t.forEach(t=>{r.push([s.GeoJSON.latLngsToCoords(t)])})}}else r.push([s.GeoJSON.latLngsToCoords(t[0])]);return r}static offsetPolygonCoordinates(t,e,r){return ki.offsetPolygonCoordinates(t,e,r)}static getLatLngInfoString(t){return"Latitude: "+t.lat+" Longitude: "+t.lng}static convertToLatLng(t){if("object"==typeof t&&null!==t){if("lat"in t&&"lng"in t)return Yn.createLatLng(t.lat,t.lng);if("latitude"in t&&"longitude"in t)return Yn.createLatLng(t.latitude,t.longitude);if("longitude"in t&&"latitude"in t)return Yn.createLatLng(t.latitude,t.longitude);if("lng"in t&&"lat"in t)return Yn.createLatLng(t.lat,t.lng)}if(Array.isArray(t)&&t.length>=2){const[e,r]=t;if("number"==typeof e&&"number"==typeof r){const t=Math.abs(e),o=Math.abs(r);return t>90&&o<=90?Yn.createLatLng(r,e):o>90&&t<=90?Yn.createLatLng(e,r):t>90||o>90?Yn.createLatLng(r,e):Yn.createLatLng(e,r)}}if("string"==typeof t){const e=t.trim();if(e.includes(",")&&!e.includes("°")&&!e.includes("'")&&!e.includes('"')){const t=e.split(",").map(t=>parseFloat(t.trim()));if(t.length>=2&&!isNaN(t[0])&&!isNaN(t[1]))return this.convertToLatLng(t)}const r=e.match(/(\d+)°(\d+)'(?:(\d+(?:\.\d+)?)")?([NS])\s*,?\s*(\d+)°(\d+)'(?:(\d+(?:\.\d+)?)")?([EW])/i);if(r){const[,t,e,o,n,i,a,s,l]=r,c=parseFloat(t)+parseFloat(e)/60+parseFloat(o||"0")/3600,h=parseFloat(i)+parseFloat(a)/60+parseFloat(s||"0")/3600,u="S"===n.toUpperCase()?-c:c,g="W"===l.toUpperCase()?-h:h;return Yn.createLatLng(u,g)}const o=e.match(/(\d+)°(\d+(?:\.\d+)?)'([NS])\s*,?\s*(\d+)°(\d+(?:\.\d+)?)'([EW])/i);if(o){const[,t,e,r,n,i,a]=o,s=parseFloat(t)+parseFloat(e)/60,l=parseFloat(n)+parseFloat(i)/60,c="S"===r.toUpperCase()?-s:s,h="W"===a.toUpperCase()?-l:l;return Yn.createLatLng(c,h)}const n=e.match(/(\d+(?:\.\d+)?)°?\s*([NS])\s*,\s*(\d+(?:\.\d+)?)°?\s*([EW])/i);if(n){const[,t,e,r,o]=n,i="S"===e.toUpperCase()?-parseFloat(t):parseFloat(t),a="W"===o.toUpperCase()?-parseFloat(r):parseFloat(r);return Yn.createLatLng(i,a)}const i=e.match(/N\s*(\d+(?:\.\d+)?)\s+E\s*(\d+(?:\.\d+)?)/i);if(i){const[,t,e]=i;return Yn.createLatLng(parseFloat(t),parseFloat(e))}if(e.match(/(?:UTM\s+)?(\d+)([NS])\s+(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)/i))throw new Error(`UTM coordinates detected: ${e}. UTM conversion requires specialized libraries like proj4js. Please convert to decimal degrees first.`);if(e.match(/(\d+)([A-Z])\s+([A-Z]{2})\s+(\d+)\s+(\d+)/i))throw new Error(`MGRS coordinates detected: ${e}. MGRS conversion requires specialized libraries. Please convert to decimal degrees first.`);if(e.match(/^[23456789CFGHJMPQRVWX]{2,3}[23456789CFGHJMPQRVWX]{3,7}\+[23456789CFGHJMPQRVWX]{2,3}$/i))throw new Error(`Plus Code detected: ${e}. Plus Code conversion requires specialized libraries. Please convert to decimal degrees first.`)}throw new Error(`Unable to convert coordinate: ${JSON.stringify(t)}`)}static convertToLatLngArray(t){return t.map(t=>t.map(t=>t.map(t=>this.convertToLatLng(t))))}}const Ei={draw:"draw",subtract:"subtract",p2p:"p2p",p2pSubtract:"p2pSubtract",deleteAll:"erase",clonePolygons:"clone"};function Si(t){var e,r,o,n;if(!t)return;const i=t,a=t.modes;if(a){const e=Object.keys(Ei).filter(t=>void 0!==a[t]);if(e.length>0){console.warn("[Leaflet.Polydraw] `config.modes.*` tool toggles are deprecated in v2. Use `config.tools.*` (draw/subtract/p2p/clone/erase) instead."),t.tools||(t.tools={});for(const r of e){const e=Ei[r];void 0===t.tools[e]&&(t.tools[e]=a[r])}}}const s=(null==(e=t.markers)?void 0:e.visualOptimization)??{};(Object.prototype.hasOwnProperty.call(s,"useAngles")||Object.prototype.hasOwnProperty.call(s,"useBoundingBox")||Object.prototype.hasOwnProperty.call(s,"useDistance")||Object.prototype.hasOwnProperty.call(s,"thresholdBoundingBox")||Object.prototype.hasOwnProperty.call(s,"thresholdDistance")||Object.prototype.hasOwnProperty.call(s,"sharpAngleThreshold"))&&console.warn("[Leaflet.Polydraw] `markers.visualOptimization` is deprecated. Prefer `visualOptimizationLevel` when adding predefined polygons.");const l=t.maxHistorySize;"number"==typeof l&&(console.warn("[Leaflet.Polydraw] `config.maxHistorySize` is deprecated in v2. Use `config.history.maxSize` instead."),t.history||(t.history={}),void 0===t.history.maxSize&&(t.history.maxSize=l));const c=t.boundingBox;c&&"boolean"==typeof c.addMidPointMarkers&&(console.warn("[Leaflet.Polydraw] `config.boundingBox` is deprecated in v2. Use `config.polygonTools.bbox` instead."),t.polygonTools||(t.polygonTools={}),t.polygonTools.bbox||(t.polygonTools.bbox={}),void 0===t.polygonTools.bbox.addMidPointMarkers&&(t.polygonTools.bbox.addMidPointMarkers=c.addMidPointMarkers));const h=t.bezier;if(h&&(void 0!==h.resolution||void 0!==h.sharpness||void 0!==h.resampleMultiplier||void 0!==h.maxNodes||void 0!==h.visualOptimizationLevel||void 0!==h.ghostMarkers)){console.warn("[Leaflet.Polydraw] `config.bezier` is deprecated in v2. Use `config.polygonTools.bezier` instead."),t.polygonTools||(t.polygonTools={}),t.polygonTools.bezier||(t.polygonTools.bezier={});const e=t.polygonTools.bezier;for(const t of Object.keys(h))void 0!==h[t]&&void 0===e[t]&&(e[t]=h[t])}const u=t.polygonCreation,g=i.polygonCreation;if(void 0!==(null==g?void 0:g.method)){console.warn("[Leaflet.Polydraw] `config.polygonCreation.method` is deprecated in v2. Use `config.polygonCreation.algorithm` instead."),t.polygonCreation||(t.polygonCreation={});const e=t.polygonCreation;void 0===e.algorithm&&(e.algorithm=g.method)}const d=i.simplification;if(void 0!==(null==d?void 0:d.mode)){console.warn("[Leaflet.Polydraw] `config.simplification.mode` is deprecated in v2. Use `config.simplification.strategy` instead."),t.simplification||(t.simplification={});const e=t.simplification;void 0===e.strategy&&(e.strategy=d.mode)}"buffer"===(null==u?void 0:u.algorithm)&&console.warn('[Leaflet.Polydraw] `polygonCreation.algorithm: "buffer"` is deprecated and no longer supported. Falling back to "concaveman". Use "concaveman" or "direct" instead.');const p=void 0!==i.polyLineOptions,f=void 0!==i.subtractLineOptions,y=void 0!==i.polygonOptions,m=void 0!==i.holeOptions,v=void 0!==i.colors;if(p||f||y||m||v){console.warn("[Leaflet.Polydraw] `polyLineOptions`, `subtractLineOptions`, `polygonOptions`, `holeOptions`, and `colors` are deprecated in v2. Use the unified `config.styles` block instead."),t.styles||(t.styles={});const e=t.styles;if(p){e.polyline||(e.polyline={});const t=i.polyLineOptions;void 0!==t.weight&&void 0===e.polyline.weight&&(e.polyline.weight=t.weight),void 0!==t.opacity&&void 0===e.polyline.opacity&&(e.polyline.opacity=t.opacity)}if(f){e.subtractLine||(e.subtractLine={});const t=i.subtractLineOptions;void 0!==t.weight&&void 0===e.subtractLine.weight&&(e.subtractLine.weight=t.weight),void 0!==t.opacity&&void 0===e.subtractLine.opacity&&(e.subtractLine.opacity=t.opacity)}if(y){e.polygon||(e.polygon={});const t=i.polygonOptions;void 0!==t.weight&&void 0===e.polygon.weight&&(e.polygon.weight=t.weight),void 0!==t.opacity&&void 0===e.polygon.opacity&&(e.polygon.opacity=t.opacity),void 0!==t.fillOpacity&&void 0===e.polygon.fillOpacity&&(e.polygon.fillOpacity=t.fillOpacity),void 0!==t.smoothFactor&&void 0===e.polygon.smoothFactor&&(e.polygon.smoothFactor=t.smoothFactor),void 0!==t.noClip&&void 0===e.polygon.noClip&&(e.polygon.noClip=t.noClip)}if(m){e.hole||(e.hole={});const t=i.holeOptions;void 0!==t.weight&&void 0===e.hole.weight&&(e.hole.weight=t.weight),void 0!==t.opacity&&void 0===e.hole.opacity&&(e.hole.opacity=t.opacity),void 0!==t.fillOpacity&&void 0===e.hole.fillOpacity&&(e.hole.fillOpacity=t.fillOpacity)}if(v){const t=i.colors;if(void 0!==t.polyline&&(e.polyline||(e.polyline={}),void 0===e.polyline.color&&(e.polyline.color=t.polyline)),void 0!==t.subtractLine&&(e.subtractLine||(e.subtractLine={}),void 0===e.subtractLine.color&&(e.subtractLine.color=t.subtractLine)),t.polygon&&(e.polygon||(e.polygon={}),void 0!==t.polygon.border&&void 0===e.polygon.color&&(e.polygon.color=t.polygon.border),void 0!==t.polygon.fill&&void 0===e.polygon.fillColor&&(e.polygon.fillColor=t.polygon.fill)),t.hole&&(e.hole||(e.hole={}),void 0!==t.hole.border&&void 0===e.hole.color&&(e.hole.color=t.hole.border),void 0!==t.hole.fill&&void 0===e.hole.fillColor&&(e.hole.fillColor=t.hole.fill)),t.styles){e.ui||(e.ui={});const r=t.styles,o=e.ui;r.controlButton&&!o.controlButton&&(o.controlButton=r.controlButton),r.controlButtonHover&&!o.controlButtonHover&&(o.controlButtonHover=r.controlButtonHover),r.controlButtonActive&&!o.controlButtonActive&&(o.controlButtonActive=r.controlButtonActive),r.indicatorActive&&!o.indicatorActive&&(o.indicatorActive=r.indicatorActive),r.p2pMarker&&!o.p2pMarker&&(o.p2pMarker=r.p2pMarker)}void 0!==(null==(r=t.p2p)?void 0:r.closingMarker)&&(e.ui||(e.ui={}),e.ui.p2pClosingMarker||(e.ui.p2pClosingMarker={color:t.p2p.closingMarker})),void 0!==t.edgeHover&&(e.ui||(e.ui={}),e.ui.edgeHover||(e.ui.edgeHover={color:t.edgeHover})),void 0!==(null==(o=t.edgeDeletion)?void 0:o.hover)&&(e.ui||(e.ui={}),e.ui.edgeDeletion||(e.ui.edgeDeletion={color:t.edgeDeletion.hover})),void 0!==(null==(n=t.dragPolygons)?void 0:n.subtract)&&(e.ui||(e.ui={}),e.ui.dragSubtract||(e.ui.dragSubtract={color:t.dragPolygons.subtract}))}}void 0!==i.defaultMode&&(console.warn("[Leaflet.Polydraw] `config.defaultMode` is deprecated in v2. Use `config.tools.default` instead."),t.tools||(t.tools={}),void 0===t.tools.default&&(t.tools.default=i.defaultMode)),void 0!==i.dragPolygons&&(console.warn("[Leaflet.Polydraw] `config.dragPolygons` is deprecated in v2. Use `config.interaction.drag` instead."),t.interaction||(t.interaction={}),t.interaction.drag||(t.interaction.drag=i.dragPolygons)),void 0!==i.edgeDeletion&&(console.warn("[Leaflet.Polydraw] `config.edgeDeletion` is deprecated in v2. Use `config.interaction.edgeDeletion` instead."),t.interaction||(t.interaction={}),t.interaction.edgeDeletion||(t.interaction.edgeDeletion=i.edgeDeletion)),void 0!==i.menuOperations&&(console.warn("[Leaflet.Polydraw] `config.menuOperations` is deprecated in v2. Use `config.polygonTools` instead."),t.polygonTools||(t.polygonTools=i.menuOperations))}const Di=new Set([h.SouthWest,h.South,h.SouthEast,h.East,h.NorthEast,h.North,h.NorthWest,h.West]);function Ci(t,e,r){return"number"==typeof t&&Number.isFinite(t)&&Di.has(t)?t:(console.warn(`[Leaflet.Polydraw] Invalid \`${r}\` value "${String(t)}". Using "${h[e]}" (${e}) as fallback.`),e)}function Ii(t){t.markers.markerInfoIcon.position=Ci(t.markers.markerInfoIcon.position,u.markers.markerInfoIcon.position,"markers.markerInfoIcon.position"),t.markers.markerMenuIcon.position=Ci(t.markers.markerMenuIcon.position,u.markers.markerMenuIcon.position,"markers.markerMenuIcon.position"),t.markers.markerDeleteIcon.position=Ci(t.markers.markerDeleteIcon.position,u.markers.markerDeleteIcon.position,"markers.markerDeleteIcon.position")}class Ai extends s.Control{constructor(t){super(t),i(this,"map"),i(this,"tracer",null),i(this,"turfHelper"),i(this,"subContainer"),i(this,"config"),i(this,"mapStateService"),i(this,"eventManager"),i(this,"polygonInformation"),i(this,"modeManager"),i(this,"polygonDrawManager"),i(this,"polygonMutationManager"),i(this,"historyManager"),i(this,"layerManager"),i(this,"layerPanel",null),i(this,"arrayOfFeatureGroups",[]),i(this,"drawMode",c.Off),i(this,"drawModeListeners",[]),i(this,"_boundKeyDownHandler"),i(this,"_boundKeyUpHandler"),i(this,"isModifierKeyHeld",!1),i(this,"modifierModeOverride",null),i(this,"isDrawingInProgress",!1),i(this,"mapEventsAttached",!1),i(this,"drawEventsAttached",!1),i(this,"controlEvents",new WeakSet),i(this,"lastControlPointerDown",null),i(this,"_boundTouchMove"),i(this,"_boundTouchEnd"),i(this,"_boundTouchStart"),i(this,"_boundPointerDown"),i(this,"_boundPointerMove"),i(this,"_boundPointerUp"),i(this,"_lastTapTime",0),i(this,"_lastTapLatLng",null),i(this,"_tapTimeout",null),i(this,"pointerEventsHandled","undefined"!=typeof window&&"PointerEvent"in window&&Xn.isV2()),i(this,"_configReady",null),i(this,"_componentsInitialized",!1),i(this,"_isControlMounted",!1),i(this,"_isRestoringSnapshot",!1),i(this,"_coreEventListenersAttached",!1),i(this,"_coreEventSubscriptions",[]),i(this,"_initRequestId",0),i(this,"_historySuppressionDepth",0),i(this,"_lastAppliedVisibleMapOrder",[]),i(this,"_handleActivateToggle",()=>{const t=this.getContainer();if(!t)return;const e=t.querySelector(".icon-activate");if(Yn.domUtil.hasClass(e,"active"))Yn.domUtil.removeClass(e,"active"),this.subContainer&&(this.subContainer.style.maxHeight="0px",this.subContainer.style.overflow="hidden");else if(Yn.domUtil.addClass(e,"active"),this.subContainer){const t=this.subContainer.scrollHeight;this.subContainer.style.maxHeight=`${t||250}px`,this.subContainer.style.overflow="visible"}this.updateActivateButtonIndicator()}),i(this,"_handleDrawClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.modeManager.getCurrentMode()!==c.Add?(this.setDrawMode(c.Add),this.polygonInformation.saveCurrentState()):this.setDrawMode(c.Off)}),i(this,"_handleSubtractClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.modeManager.getCurrentMode()!==c.Subtract?(this.setDrawMode(c.Subtract),this.polygonInformation.saveCurrentState()):this.setDrawMode(c.Off)}),i(this,"_handleCloneClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),0!==this.arrayOfFeatureGroups.length&&(this.modeManager.getCurrentMode()!==c.Clone?(this.setDrawMode(c.Clone),this.polygonInformation.saveCurrentState()):this.setDrawMode(c.Off))}),i(this,"_handleEraseClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),0!==this.arrayOfFeatureGroups.length&&(this.map.closePopup(),this.saveHistory("eraseAll"),this.removeAllFeatureGroups())}),i(this,"_handlePointToPointClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.modeManager.getCurrentMode()!==c.PointToPoint?(this.setDrawMode(c.PointToPoint),this.polygonInformation.saveCurrentState()):this.setDrawMode(c.Off)}),i(this,"_handlePointToPointSubtractClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.modeManager.getCurrentMode()!==c.PointToPointSubtract?(this.setDrawMode(c.PointToPointSubtract),this.polygonInformation.saveCurrentState()):this.setDrawMode(c.Off)}),i(this,"_handleUndoClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.undo()}),i(this,"_handleRedoClick",t=>{t&&(t.preventDefault(),t.stopPropagation()),this.redo()}),i(this,"onMarkerHoverForEdgeDeletionEvent",t=>{if(!this.isModifierKeyHeld)return;const e=t.target;e&&(e.style.backgroundColor=this.config.styles.ui.edgeDeletion.color,e.style.borderColor=this.config.styles.ui.edgeDeletion.color,e.classList.add("edge-deletion-hover"))}),i(this,"onMarkerLeaveForEdgeDeletionEvent",t=>{const e=t.target;e&&(e.style.backgroundColor="",e.style.borderColor="",e.classList.remove("edge-deletion-hover"))});const e=structuredClone(u);(null==t?void 0:t.config)&&Si(t.config),this.config=Nn(e,(null==t?void 0:t.config)??{}),Ii(this.config),(null==t?void 0:t.configPath)?this._configReady=this.loadExternalConfig(t.configPath,null==t?void 0:t.config):(this.initializeComponents(),this._configReady=Promise.resolve())}onAdd(t){const e=t,r=s.Browser;e._onResize=()=>{},r.touch&&r.mobile&&(e.tap=!1),this.map=t,this._isControlMounted=!0;const o=++this._initRequestId;this.setupKeyboardHandlers();const n=Yn.domUtil.create("div","leaflet-control leaflet-bar");return this.initializeUI(n),this.createTracer(),this.completeInitialization(o),n}completeInitialization(t){var e;const r=()=>{this._isControlMounted&&t===this._initRequestId&&(this.initializeManagers(),this.setDrawMode(this.config.tools.default),this.setupEventListeners())};this._componentsInitialized?r():null==(e=this._configReady)||e.then(()=>{r()}).catch(()=>{})}onRemove(t){this._isControlMounted=!1,this._initRequestId+=1,this.comprehensiveCleanup()}comprehensiveCleanup(){if(this.events(!1),this.drawStartedEvents(!1),this.removeKeyboardHandlers(),this.tracer){try{this.map.hasLayer(this.tracer)?this.map.removeLayer(this.tracer):this.tracer.remove()}catch{}this.tracer=null}if(this.arrayOfFeatureGroups.forEach(t=>{try{this.polygonMutationManager&&this.polygonMutationManager.cleanupFeatureGroup(t),this.map.removeLayer(t)}catch(e){console.warn("Error cleaning up feature group:",e)}}),this.arrayOfFeatureGroups.length=0,this._lastAppliedVisibleMapOrder=[],this.polygonMutationManager&&this.polygonMutationManager.dispose(),this.removeCoreEventListeners(),this.polygonInformation&&this.polygonInformation.deletePolygonInformationStorage(),this.drawModeListeners.length=0,this._boundKeyDownHandler&&(this._boundKeyDownHandler=void 0),this._boundKeyUpHandler&&(this._boundKeyUpHandler=void 0),this._boundTouchMove&&(this._boundTouchMove=void 0),this._boundTouchEnd&&(this._boundTouchEnd=void 0),this._boundTouchStart&&(this._boundTouchStart=void 0),this._boundPointerDown&&(this._boundPointerDown=void 0),this._boundPointerMove&&(this._boundPointerMove=void 0),this._boundPointerUp&&(this._boundPointerUp=void 0),this._tapTimeout&&(clearTimeout(this._tapTimeout),this._tapTimeout=null),this.drawMode=c.Off,this.isModifierKeyHeld=!1,this._lastTapTime=0,this.layerPanel){try{this.layerPanel.remove()}catch{}this.layerPanel=null}this.subContainer=void 0,this._componentsInitialized=!1}addTo(t){return super.addTo(t),this}getFeatureGroups(){return this.arrayOfFeatureGroups}async undo(){if(!this.historyManager.canUndo())return;const t=this.historyManager.undo(this.arrayOfFeatureGroups,this.layerManager);t&&await this.restoreFromSnapshot(t)}isPolygonAction(t){return"simplify"===t||"doubleElbows"===t||"bbox"===t||"bezier"===t||"scale"===t||"rotate"===t||"toggleOptimization"===t}shouldCaptureHistory(t){var e,r;const o=null==(e=this.config.history)?void 0:e.capture;return!o||(this.isPolygonAction(t)?!1!==(null==(r=o.polygonActions)?void 0:r[t]):!1!==o[t])}saveHistory(t){this.isHistorySuppressed()||this.shouldCaptureHistory(t)&&this.historyManager.saveState(this.arrayOfFeatureGroups,t,this.layerManager)}isHistorySuppressed(){return this._historySuppressionDepth>0}startHistoryBatch(t){this.isHistorySuppressed()||this.saveHistory(t),this._historySuppressionDepth+=1}endHistoryBatch(){this._historySuppressionDepth>0&&(this._historySuppressionDepth-=1)}async redo(){if(!this.historyManager.canRedo())return;const t=this.historyManager.redo(this.arrayOfFeatureGroups,this.layerManager);t&&await this.restoreFromSnapshot(t)}resolvePredefinedLayerDescriptor(t,e){if(!t)return null;if("string"==typeof t){const r=t.trim();if(!r)throw new Error("Layer id cannot be empty");return{id:r,color:e}}const r=(t.id||"").trim();if(!r)throw new Error("Layer descriptor must include a non-empty id");const o={...t,id:r,color:e??t.color};return"static"===o.interaction&&void 0===o.panel&&(o.panel="hidden"),o}ensureLayerFromDescriptor(t){const e=t.id.trim(),r=this.layerManager.getOrCreateLayer(e,{label:t.label,color:t.color,visible:t.visibility,interaction:t.interaction,panel:t.panel??("static"===t.interaction?"hidden":void 0),metadata:t.metadata});return void 0!==t.label&&this.layerManager.setLayerLabel(e,t.label),t.color&&this.layerManager.setLayerColor(e,t.color),void 0!==t.visibility&&this.layerManager.setLayerVisibility(e,t.visibility),void 0!==t.interaction&&this.layerManager.setLayerInteraction(e,t.interaction),void 0===t.panel&&"static"!==t.interaction||this.layerManager.setLayerPanelVisibility(e,t.panel??("static"===t.interaction?"hidden":"visible")),void 0!==t.metadata&&this.layerManager.setLayerMetadata(e,t.metadata),this.layerManager.getLayer(e)??r}getInteractionTargetLayerId(){if(!this.layerManager)return;const t=this.layerManager.getActiveLayerId();if(this.layerManager.isLayerEditable(t))return t;if(this.layerManager.isLayerEditable("default"))return"default";const e=this.layerManager.getAllLayers().find(t=>"editable"===t.interaction);return null==e?void 0:e.id}ensureFeatureGroupMetadata(t){const e=t;if(e._polydrawMetadata)return e._polydrawMetadata;let r=0,o=0;t.eachLayer(t=>{if(t instanceof s.Polygon&&!(t instanceof s.Rectangle)){const e=t;"number"==typeof e._polydrawOptimizationLevel&&(r=e._polydrawOptimizationLevel),"number"==typeof e._polydrawOptimizationOriginalLevel&&(o=e._polydrawOptimizationOriginalLevel)}});const n=new Date,i=`fg-${Yn.util.stamp(t)}`;return e._polydrawMetadata={id:i,optimizationLevel:r,originalOptimizationLevel:o,hasHoles:!1,createdAt:n,lastModified:n,metadata:{},sourceFeatureIds:[i]},e._polydrawMetadata}async addPredefinedPolygon(t,e){var r,o,n;const i=xi.convertToLatLngArray(t);if(!i||0===i.length)throw new Error("Cannot add empty polygon array");if(!this.map)throw new Error("Map not initialized");if(!this.polygonMutationManager)throw new Error("PolygonMutationManager not initialized");if(!this.layerManager)throw new Error("LayerManager not initialized");for(const[p,f]of i.entries())if(!f||!f[0]||f[0].length<4)throw new Error(`Invalid polygon data at index ${p}: A polygon must have at least 3 unique vertices.`);const a=(null==e?void 0:e.visualOptimizationLevel)??0,s=(null==(r=null==e?void 0:e.overrides)?void 0:r.interaction)&&"inherit"!==e.overrides.interaction?e.overrides.interaction:void 0,l=(null==(o=null==e?void 0:e.overrides)?void 0:o.style)?{...e.overrides.style}:void 0,c=(null==(n=null==e?void 0:e.overrides)?void 0:n.merge)??"inherit";let h,u,g=!1;if(null==e?void 0:e.layer){const t=this.resolvePredefinedLayerDescriptor(e.layer,e.layerColor);if(t){const e=this.ensureLayerFromDescriptor(t);h=e.id,u=e.color,g="editable"!==e.interaction}this.updateLayerPanel()}else(null==e?void 0:e.layerColor)&&(u=e.layerColor);this.startHistoryBatch("addPredefinedPolygon");try{for(const t of i)try{const r=t.map(t=>t.map(t=>[t.lng,t.lat])),o=this.turfHelper.getMultiPolygon([r]),n="allow"!==c&&("block"===c||g),i=await this.polygonMutationManager.addPolygon(o,{simplify:!1,noMerge:n,mergeEditableOnly:"allow"!==c,visualOptimizationLevel:a,targetLayerId:h,layerColor:u,featureMetadata:null==e?void 0:e.metadata,featureInteractionOverride:s,featureStyleOverrides:l});if(!i.success)throw console.error("Error adding polygon via manager:",i.error),new Error(i.error||"Failed to add polygon");this.polygonInformation.createPolygonInformationStorage(this.arrayOfFeatureGroups)}catch(d){throw console.error("Error adding auto polygon:",d),d}}finally{this.endHistoryBatch()}}async addPredefinedGeoJSONs(t,e){if(!Array.isArray(t)||0===t.length)throw new Error("Cannot add empty GeoJSON feature array");this.startHistoryBatch("addPredefinedPolygon");try{for(const r of t){const{type:t,coordinates:o}=r.geometry,n=(null==e?void 0:e.metadata)??(r.properties?{...r.properties}:void 0),i={...e,metadata:n};if("MultiPolygon"===t)for(const e of o){const t=e.map(t=>t.map(t=>Yn.createLatLng(t[1],t[0])));await this.addPredefinedPolygon([t],i)}else if("Polygon"===t){const t=o.map(t=>t.map(t=>Yn.createLatLng(t[1],t[0])));await this.addPredefinedPolygon([t],i)}}}finally{this.endHistoryBatch()}}async addPredefinedPolygonGroups(t){if(!Array.isArray(t)||0===t.length)throw new Error("Cannot add empty polygon group array");if(!this.layerManager)throw new Error("LayerManager not initialized");this.startHistoryBatch("addPredefinedPolygon");try{const e=t.map(t=>{const e=this.resolvePredefinedLayerDescriptor(t.layer);if(!e)throw new Error("Polygon group layer descriptor is missing");return{descriptor:e,polygons:t.polygons,options:t.options}});for(const t of e)this.ensureLayerFromDescriptor(t.descriptor);for(const t of e)for(const e of t.polygons)await this.addPredefinedPolygon(e,{layer:t.descriptor,...t.options})}finally{this.endHistoryBatch()}this.updateLayerPanel()}getLayerManager(){return this.layerManager}getAllLayers(){return this.layerManager.getAllLayers()}getLayerById(t){return this.layerManager.getLayer(t)}hasLayer(t){return!!this.layerManager.getLayer(t)}getActiveLayer(){return this.layerManager.getActiveLayer()}getFeatureGroupsByLayer(t){return this.layerManager.getFeatureGroupsForLayer(t)}createLayer(t){const e=(t.id||"").trim();if(!e)throw new Error("Layer id cannot be empty");if(this.layerManager.getLayer(e))throw new Error(`Layer "${e}" already exists`);return this.ensureLayer(t)}ensureLayer(t){const e=this.ensureLayerFromDescriptor(t);return this.updateLayerPanel(),this.updateMarkerDraggableState(),e}updateLayer(t,e){if(!this.layerManager.getLayer(t))return;let r=!1;return"label"in e&&(r=this.layerManager.setLayerLabel(t,e.label)||r),"string"==typeof e.color&&(r=this.layerManager.setLayerColor(t,e.color)||r),"boolean"==typeof e.visibility&&(r=this.layerManager.setLayerVisibility(t,e.visibility)||r),void 0!==e.interaction&&(r=this.layerManager.setLayerInteraction(t,e.interaction)||r,"static"===e.interaction&&void 0===e.panel&&(r=this.layerManager.setLayerPanelVisibility(t,"hidden")||r)),void 0!==e.panel&&(r=this.layerManager.setLayerPanelVisibility(t,e.panel)||r),void 0!==e.metadata&&(r=this.layerManager.setLayerMetadata(t,e.metadata)||r),r&&(this.updateLayerPanel(),this.updateMarkerDraggableState(),this.syncFeatureGroupOrderWithLayers()),this.layerManager.getLayer(t)}deleteLayer(t){const e=(t||"").trim();if(!e||!this.layerManager.getLayer(e))return{success:!1,layerId:e,removedFeatureGroups:0,reason:"not-found"};if("default"===e)return{success:!1,layerId:e,removedFeatureGroups:0,reason:"default-layer"};this.saveHistory("layerDelete");return{success:!0,layerId:e,removedFeatureGroups:this.layerManager.deleteLayer(e).length}}setActiveLayer(t){return this.layerManager.setActiveLayer(t)}setLayerVisibility(t,e){return this.layerManager.setLayerVisibility(t,e)}showLayer(t){return this.setLayerVisibility(t,!0)}hideLayer(t){return this.setLayerVisibility(t,!1)}setLayerColor(t,e){return this.layerManager.setLayerColor(t,e)}setLayerInteraction(t,e){const r=this.layerManager.setLayerInteraction(t,e);return r&&(this.updateMarkerDraggableState(),this.updateLayerPanel()),r}setLayerPanelVisibility(t,e){const r=this.layerManager.setLayerPanelVisibility(t,e);return r&&this.updateLayerPanel(),r}setLayerMetadata(t,e){return this.layerManager.setLayerMetadata(t,e)}patchLayerMetadata(t,e){const r=this.layerManager.getLayer(t);return!!r&&this.layerManager.setLayerMetadata(t,{...r.metadata,...e})}getFeatureMetadata(t){const e=t._polydrawMetadata;if(null==e?void 0:e.metadata)return{...e.metadata}}setFeatureMetadata(t,e){if(!t)return!1;const r=this.ensureFeatureGroupMetadata(t);return r.metadata={...e},r.lastModified=new Date,!0}patchFeatureMetadata(t,e){if(!t)return!1;const r=this.getFeatureMetadata(t)??{};return this.setFeatureMetadata(t,{...r,...e})}reorderLayer(t,e){if("default"===t||"default"===e)return!1;const r=this.layerManager.getAllLayers().map(t=>t.id),o=r.indexOf(t),n=r.indexOf(e);return!(o<0||n<0||o===n)&&(this.saveHistory("layerReorder"),this.layerManager.moveLayer(t,e))}beginBatch(t="batch"){this.startHistoryBatch(t)}endBatch(){this.endHistoryBatch()}setDrawMode(t,e){const r=this.drawMode;this._updateDrawModeState(t);if(!((null==e?void 0:e.preserveActiveDraw)&&this.isDrawingInProgress&&(r===c.Add&&t===c.Subtract||r===c.Subtract&&t===c.Add))){(t===c.PointToPoint||t===c.PointToPointSubtract)&&r!==c.PointToPoint&&r!==c.PointToPointSubtract&&this.isDrawingInProgress&&this.stopDraw(),r!==c.PointToPoint&&r!==c.PointToPointSubtract||t===c.PointToPoint||t===c.PointToPointSubtract?(t===c.Off||t!==c.PointToPoint&&t!==c.PointToPointSubtract)&&this.stopDraw():(this.polygonDrawManager.clearP2pMarkers(),this.stopDraw())}this.map&&(this._updateUIAfterDrawModeChange(t),this._updateMapInteractions())}getDrawMode(){return this.modeManager.getCurrentMode()}on(t,e){this.eventManager.on(t,e)}off(t,e){this.eventManager.off(t,e)}removeAllFeatureGroups(){this.arrayOfFeatureGroups.forEach(t=>{try{this.polygonMutationManager&&this.polygonMutationManager.cleanupFeatureGroup(t),this.map.removeLayer(t)}catch{}}),this.arrayOfFeatureGroups.length=0,this._lastAppliedVisibleMapOrder=[],this.layerManager&&this.layerManager.clear(this.config.styles.polygon.color),this.polygonInformation.deletePolygonInformationStorage(),this.polygonInformation.updatePolygons(),this.updateActivateButtonIndicator(),this.updateLayerPanel()}cleanup(){this.map&&this.comprehensiveCleanup()}initializeUI(t){!function(t){const e=document.createElement("style");e.innerHTML=`\n .leaflet-control a { background-color: ${t.styles.ui.controlButton.backgroundColor}; color: ${t.styles.ui.controlButton.color}; display: flex; align-items: center; justify-content: center; }\n .leaflet-control a:hover { background-color: ${t.styles.ui.controlButtonHover.backgroundColor}; }\n .leaflet-control a.active { background-color: ${t.styles.ui.controlButtonActive.backgroundColor}; color: ${t.styles.ui.controlButtonActive.color}; }\n .polydraw-indicator-active { background-color: ${t.styles.ui.indicatorActive.backgroundColor} !important; }\n .crosshair-cursor-enabled { cursor: crosshair !important; }\n .crosshair-cursor-enabled * { cursor: crosshair !important; }\n .leaflet-polydraw-p2p-marker { background-color: ${t.styles.ui.p2pMarker.backgroundColor}; border: 2px solid ${t.styles.ui.p2pMarker.borderColor}; border-radius: 50%; box-sizing: border-box; }\n .leaflet-polydraw-p2p-first-marker { position: relative; }\n .leaflet-polydraw-p2p-first-marker:hover { transform: scale(1.5); transition: all 0.2s ease; }\n .leaflet-polydraw-p2p-first-marker-ready[data-p2p-mode="add"]:hover { background-color: ${t.styles.ui.p2pClosingMarker.color}; border-color: ${t.styles.ui.p2pClosingMarker.color}; cursor: pointer; }\n .leaflet-polydraw-p2p-first-marker-ready[data-p2p-mode="subtract"]:hover { background-color: ${t.styles.ui.dragSubtract.color}; border-color: ${t.styles.ui.dragSubtract.color}; cursor: pointer; }\n `,document.head.appendChild(e)}(this.config),s.DomEvent.disableClickPropagation(t),s.DomEvent.on(t,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(t,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(t,"pointerdown",s.DomEvent.stopPropagation),s.DomEvent.on(t,"pointerup",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stopPropagation);const e=t=>{this.controlEvents.add(t),this.markControlPointerDown(t)},r=t=>{this.clearControlPointerDown(t)};this.pointerEventsHandled?(t.addEventListener("pointerdown",e,{capture:!0,passive:!0}),t.addEventListener("pointerup",r,{capture:!0,passive:!0}),t.addEventListener("pointercancel",r,{capture:!0,passive:!0})):(t.addEventListener("mousedown",e,{capture:!0,passive:!0}),t.addEventListener("mouseup",r,{capture:!0,passive:!0}),t.addEventListener("touchstart",e,{capture:!0,passive:!0}),t.addEventListener("touchend",r,{capture:!0,passive:!0}),t.addEventListener("touchcancel",r,{capture:!0,passive:!0})),t.style.display="flex",t.style.flexDirection="column-reverse",t.style.pointerEvents="auto",t.style.position="relative",t.style.zIndex="1000";const o=this.config.tooltips;if(o){const e=Math.max(0,o.delayMs);t.setAttribute("data-tooltip-enabled",o.enabled?"true":"false"),t.setAttribute("data-tooltip-direction",o.direction),t.style.setProperty("--polydraw-tooltip-bg",o.backgroundColor),t.style.setProperty("--polydraw-tooltip-color",o.color),t.style.setProperty("--polydraw-tooltip-delay",`${e}ms`)}this.subContainer=Yn.domUtil.create("div","sub-buttons",t),this.subContainer.setAttribute("data-polydraw","sub-buttons"),this.subContainer.style.maxHeight="0px",this.subContainer.style.overflow="hidden",this.subContainer.style.transition="max-height 0.3s ease",this.subContainer.style.pointerEvents="auto",this.subContainer.style.position="relative",this.eventManager||(this.eventManager=new ti),this.historyManager||(this.historyManager=new wi(this.eventManager,this.config.history.maxSize)),function(t,e,r,o,n,i,a,l,c,h,u,g,d,p){const f=Yn.domUtil.create("a","icon-activate",t);if(f.href="#",$n(f,"Activate"),f.setAttribute("data-polydraw","activate-button"),Kn(f,jn.activate),f.dataset.activeIcon=jn.activate,f.dataset.collapsedIcon=jn.collapse,s.DomEvent.on(f,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(f,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(f,"click",s.DomEvent.stop).on(f,"click",o),r.tools.draw){const t=Yn.domUtil.create("a","icon-draw",e);t.href="#",$n(t,"Draw"),t.setAttribute("data-polydraw","draw-button"),Kn(t,jn.draw),s.DomEvent.on(t,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(t,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stop),s.DomEvent.on(t,"click",n)}if(r.tools.subtract){const t=Yn.domUtil.create("a","icon-subtract",e);t.href="#",$n(t,"Subtract"),t.setAttribute("data-polydraw","subtract-button"),Kn(t,jn.subtract),s.DomEvent.on(t,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(t,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stop),s.DomEvent.on(t,"click",i)}if(r.tools.p2p){const t=Yn.domUtil.create("a","icon-p2p",e);t.href="#",$n(t,"Point to Point"),t.setAttribute("data-polydraw","p2p-button"),Kn(t,jn.p2p),s.DomEvent.on(t,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(t,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stop),s.DomEvent.on(t,"click",c)}if(r.tools.p2pSubtract){const t=Yn.domUtil.create("a","icon-p2p-subtract",e);t.href="#",$n(t,"Point to Point Subtract"),t.setAttribute("data-polydraw","p2p-subtract-button"),Kn(t,jn.p2pSubtract),s.DomEvent.on(t,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(t,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stop),s.DomEvent.on(t,"click",h)}if(r.tools.clone){const t=Yn.domUtil.create("a","icon-clone",e);t.href="#",$n(t,"Clone"),t.setAttribute("data-polydraw","clone-button"),Kn(t,jn.clone),s.DomEvent.on(t,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(t,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stop),s.DomEvent.on(t,"click",a)}if(r.tools.erase){const t=Yn.domUtil.create("a","icon-erase",e);t.href="#",$n(t,"Erase All"),t.setAttribute("data-polydraw","erase-button"),Kn(t,jn.erase),s.DomEvent.on(t,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(t,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stopPropagation),s.DomEvent.on(t,"click",s.DomEvent.stop),s.DomEvent.on(t,"click",l)}const y=Yn.domUtil.create("a","icon-undo",e);y.href="#",$n(y,"Undo (Ctrl+Z / Cmd+Z)"),Kn(y,jn.undo),s.DomEvent.on(y,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(y,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(y,"click",s.DomEvent.stopPropagation),s.DomEvent.on(y,"click",s.DomEvent.stop),s.DomEvent.on(y,"click",u);const m=Yn.domUtil.create("a","icon-redo",e);m.href="#",$n(m,"Redo (Ctrl+Y / Cmd+Shift+Z)"),Kn(m,jn.redo),s.DomEvent.on(m,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(m,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(m,"click",s.DomEvent.stopPropagation),s.DomEvent.on(m,"click",s.DomEvent.stop),s.DomEvent.on(m,"click",g);const v=(t,e)=>{t?(y.style.opacity="1",y.style.pointerEvents="auto"):(y.style.opacity="0.3",y.style.pointerEvents="none"),e?(m.style.opacity="1",m.style.pointerEvents="auto"):(m.style.opacity="0.3",m.style.pointerEvents="none")};d.on("polydraw:history:changed",t=>{v(t.canUndo,t.canRedo)}),d.on("polydraw:history:undo",t=>{v(t.canUndo,t.canRedo)}),d.on("polydraw:history:redo",t=>{v(t.canUndo,t.canRedo)}),v(p.canUndo(),p.canRedo())}(t,this.subContainer,this.config,this._handleActivateToggle,this._handleDrawClick,this._handleSubtractClick,this._handleCloneClick,this._handleEraseClick,this._handlePointToPointClick,this._handlePointToPointSubtractClick,this._handleUndoClick,this._handleRedoClick,this.eventManager,this.historyManager),this.ensureButtonTouchResponsiveness(t),this.updateActivateButtonIndicator();this.drawModeListeners.push(e=>{const r=t.querySelector(".icon-draw"),o=t.querySelector(".icon-subtract"),n=t.querySelector(".icon-p2p"),i=t.querySelector(".icon-p2p-subtract"),a=t.querySelector(".icon-clone");r&&r.classList.toggle("active",e===c.Add),o&&o.classList.toggle("active",e===c.Subtract),n&&n.classList.toggle("active",e===c.PointToPoint),i&&i.classList.toggle("active",e===c.PointToPointSubtract),a&&a.classList.toggle("active",e===c.Clone)})}addCoreEventListener(t,e){this.eventManager.on(t,e),this._coreEventSubscriptions.push({event:t,callback:e})}removeCoreEventListeners(){if(this.eventManager){for(const t of this._coreEventSubscriptions)this.eventManager.off(t.event,t.callback);this._coreEventSubscriptions.length=0,this._coreEventListenersAttached=!1}else this._coreEventListenersAttached=!1}setupEventListeners(){this._coreEventListenersAttached||(this._coreEventListenersAttached=!0,this.addCoreEventListener("polygonOperationComplete",()=>{this.updateActivateButtonIndicator(),this.modeManager.updateStateForMode(c.Off),this.drawMode=c.Off,this.emitDrawModeChanged(),this.updateMarkerDraggableState();const t=this.modeManager.shouldShowCrosshairCursor(),e=this.modeManager.canPerformAction("mapDrag"),r=this.modeManager.canPerformAction("mapZoom"),o=this.modeManager.canPerformAction("mapDoubleClickZoom");t?Yn.domUtil.addClass(this.map.getContainer(),"crosshair-cursor-enabled"):Yn.domUtil.removeClass(this.map.getContainer(),"crosshair-cursor-enabled"),this.events(!1),this.setLeafletMapEvents(e,o,r),this.applyTracerStyle(c.Off),this.syncFeatureGroupOrderWithLayers(),this.cleanupEmptyLayers()}),this.addCoreEventListener("polygonDeleted",()=>{this.updateActivateButtonIndicator(),this.cleanupEmptyLayers()}),this.addCoreEventListener("polydraw:polygon:created",async t=>{this.stopDraw();const e=this.getInteractionTargetLayerId();t.isPointToPoint?(this.saveHistory("pointToPoint"),t.mode===c.PointToPointSubtract?await this.polygonMutationManager.subtractPolygon(t.polygon,{simplify:!1,targetLayerId:e}):await this.polygonMutationManager.addPolygon(t.polygon,{simplify:!1,noMerge:!1,targetLayerId:e})):await this.handleFreehandDrawCompletion(t.polygon),this.polygonInformation.createPolygonInformationStorage(this.arrayOfFeatureGroups)}),this.addCoreEventListener("polydraw:draw:cancel",()=>{this.stopDraw(),this.setDrawMode(this.config.tools.default)}),this.addCoreEventListener("polydraw:layer:visibility",t=>{const e=this.layerManager.getLayer(t.layerId);if(e){for(const r of e.featureGroups)try{t.visible?r.addTo(this.map):this.map.removeLayer(r)}catch{}this.syncFeatureGroupOrderWithLayers(),this.updateLayerPanel()}}),this.addCoreEventListener("polydraw:layer:activated",()=>{this.updateMarkerDraggableState(),this.updateLayerPanel()}),this.addCoreEventListener("polydraw:layer:colorChanged",()=>{this.updateLayerPanel()}),this.addCoreEventListener("polydraw:layer:created",()=>{this.updateLayerPanel()}),this.addCoreEventListener("polydraw:layer:delete-requested",t=>{this.saveHistory("layerDelete"),this.layerManager.deleteLayer(t.layerId)}),this.addCoreEventListener("polydraw:layer:reorder-requested",t=>{this.reorderLayer(t.layerId,t.targetLayerId)}),this.addCoreEventListener("polydraw:layer:reordered",()=>{this.syncFeatureGroupOrderWithLayers(),this.polygonInformation.deletePolygonInformationStorage(),this.polygonInformation.createPolygonInformationStorage(this.arrayOfFeatureGroups),this.updateLayerPanel()}),this.addCoreEventListener("polydraw:layer:deleted",t=>{for(const e of t.removedFeatureGroups){try{this.polygonMutationManager&&this.polygonMutationManager.cleanupFeatureGroup(e),e.clearLayers(),this.map.removeLayer(e)}catch{}const t=this.arrayOfFeatureGroups.indexOf(e);t>-1&&this.arrayOfFeatureGroups.splice(t,1)}this.syncFeatureGroupOrderWithLayers(),this.polygonInformation.updatePolygons(),this.updateActivateButtonIndicator(),this.updateMarkerDraggableState(),this.updateLayerPanel()}))}createTracer(){this.tracer=Yn.createPolyline([],{...this.config.styles.polyline});try{this.tracer.addTo(this.map)}catch{}}applyTracerStyle(t){if(this.tracer)try{const e=t===c.Subtract||t===c.PointToPointSubtract,r=this.getTracerBaseStyle(e);let o,n="";switch(t){case c.Add:n=this.config.styles.polyline.color,o=void 0;break;case c.Subtract:n=this.config.styles.subtractLine.color,o=void 0;break;case c.PointToPoint:n=this.config.styles.polyline.color,o="5, 5";break;case c.PointToPointSubtract:n=this.config.styles.subtractLine.color,o="5, 5";break;case c.Off:default:n="",o=void 0}this.tracer.setStyle({...r,color:n,dashArray:o})}catch{}}getTracerBaseStyle(t){const e=t?this.config.styles.subtractLine:this.config.styles.polyline;return{weight:e.weight,opacity:e.opacity}}initializeManagers(){this.polygonDrawManager=new ri({turfHelper:this.turfHelper,map:this.map,config:this.config,modeManager:this.modeManager,eventManager:this.eventManager,tracer:this.tracer}),this.polygonMutationManager=new Mi({turfHelper:this.turfHelper,polygonInformation:this.polygonInformation,map:this.map,config:this.config,modeManager:this.modeManager,eventManager:this.eventManager,getFeatureGroups:()=>this.arrayOfFeatureGroups,saveHistoryState:t=>{this.saveHistory(t)},layerManager:this.layerManager})}async loadExternalConfig(t,e){try{const r=await fetch(t);if(!r.ok)throw new Error(`Failed to load config from ${t}: ${r.status} ${r.statusText}`);const o=await r.json();Si(o),e&&Si(e),this.config=Nn(structuredClone(u),o??{},e??{}),Ii(this.config),this.initializeComponents()}catch(r){console.warn("Failed to load external config, falling back to default + inline config:",r),this.config=Nn(structuredClone(u),e??{}),Ii(this.config),this.initializeComponents()}}_updateDrawModeState(t){var e;this.drawMode=t,this.modeManager.updateStateForMode(t),this.emitDrawModeChanged(),this.updateMarkerDraggableState(),(null==(e=this.polygonDrawManager)?void 0:e.refreshP2PMarkerState)&&this.polygonDrawManager.refreshP2PMarkerState()}_updateUIAfterDrawModeChange(t){this.modeManager.shouldShowCrosshairCursor()?Yn.domUtil.addClass(this.map.getContainer(),"crosshair-cursor-enabled"):Yn.domUtil.removeClass(this.map.getContainer(),"crosshair-cursor-enabled"),this.applyTracerStyle(t)}shouldEnableDrawEvents(t){return t===c.Add||t===c.Subtract||t===c.PointToPoint||t===c.PointToPointSubtract}_updateMapInteractions(){const t=this.modeManager.canPerformAction("mapDrag"),e=this.modeManager.canPerformAction("mapZoom"),r=this.modeManager.canPerformAction("mapDoubleClickZoom");this.events(this.shouldEnableDrawEvents(this.drawMode)),this.setLeafletMapEvents(t,r,e)}async restoreFromSnapshot(t){var e,r,o;if(t&&Array.isArray(t.features)){this.historyManager.setRestoring(!0),this._isRestoringSnapshot=!0;try{this.removeAllFeatureGroups();for(const[o,n]of t.features.entries()){const i=null==(e=t.featureMetadataSnapshot)?void 0:e[o],a=(null==i?void 0:i.layerId)&&(null==(r=this.layerManager)?void 0:r.getLayer(i.layerId))?i.layerId:void 0;await this.polygonMutationManager.addPolygon(n,{noMerge:!0,simplify:!1,skipKinkProcessing:!0,targetLayerId:a,visualOptimizationLevel:(null==i?void 0:i.optimizationLevel)??0,originalOptimizationLevel:null==i?void 0:i.originalOptimizationLevel,featureId:null==i?void 0:i.id,featureMetadata:null==i?void 0:i.metadata,sourceFeatureIds:null==i?void 0:i.sourceFeatureIds,featureInteractionOverride:null==i?void 0:i.interactionOverride,featureStyleOverrides:null==i?void 0:i.styleOverrides,featureCreatedAt:null==i?void 0:i.createdAt,featureLastModified:null==i?void 0:i.lastModified})}if(t.layerSnapshot&&this.layerManager){this.layerManager.restoreFromLayerSnapshot(t.layerSnapshot,this.arrayOfFeatureGroups);for(const t of this.layerManager.getAllLayers()){for(const e of t.featureGroups){const r=null==(o=e._polydrawMetadata)?void 0:o.styleOverrides;e.eachLayer(e=>{e instanceof s.Polygon&&!(e instanceof s.Rectangle)&&e.setStyle({color:(null==r?void 0:r.color)??t.color,fillColor:(null==r?void 0:r.fillColor)??this.config.styles.polygon.fillColor,fillOpacity:(null==r?void 0:r.fillOpacity)??this.config.styles.polygon.fillOpacity,weight:(null==r?void 0:r.weight)??this.config.styles.polygon.weight})})}if(!t.visible)for(const e of t.featureGroups)try{this.map.removeLayer(e)}catch{}}this.updateLayerPanel()}this.layerManager&&this.syncFeatureGroupOrderWithLayers(),this.polygonInformation.updatePolygons(),this.updateMarkerDraggableState()}finally{this._isRestoringSnapshot=!1,this.historyManager.setRestoring(!1)}}else console.warn("Invalid history snapshot provided for restore; skipping restore operation.")}initializeComponents(){this._componentsInitialized||(this._componentsInitialized=!0,this.turfHelper=new Un(this.config),this.mapStateService=new Qn,this.eventManager=this.eventManager??new ti,this.polygonInformation=new Zn(this.mapStateService),this.modeManager=new ei(this.config,this.eventManager),this.historyManager?this.historyManager.setMaxHistorySize(this.config.history.maxSize):this.historyManager=new wi(this.eventManager,this.config.history.maxSize),this.layerManager=new bi(this.eventManager,this.config.styles.polygon.color),this.polygonInformation.onPolygonInfoUpdated(t=>{this.updateActivateButtonIndicator()}),this._boundKeyDownHandler=this.handleKeyDown.bind(this))}emitDrawModeChanged(){this.eventManager.emit("polydraw:mode:change",{mode:this.modeManager.getCurrentMode()});for(const t of this.drawModeListeners)t(this.modeManager.getCurrentMode())}updateMarkerDraggableState(){this.polygonMutationManager&&this.polygonMutationManager.updateMarkerDraggableState()}updateLayerPanel(){if(!this.map||!this.layerManager)return;if(this.layerManager.getPanelLayerCount()>1){if(!this.layerPanel){const t=function(t,e){let r=!1,o=null,n=null,i=!1;const a=()=>{if(!o)return;if(n)return void(i=!0);o.innerHTML="";const l=t.getPanelLayers(),c=t.getActiveLayerId();n&&!l.some(t=>t.id===n)&&(n=null),o.classList.toggle("polydraw-layer-panel-collapsed",r);const h=s.DomUtil.create("div","polydraw-layer-header",o);s.DomUtil.create("span","polydraw-layer-header-title",h).textContent="Layers",s.DomUtil.create("span","polydraw-layer-header-count",h).textContent=String(l.length);const u=s.DomUtil.create("button","polydraw-layer-header-toggle",h);if(u.setAttribute("type","button"),u.setAttribute("aria-label",r?"Expand layer panel":"Collapse layer panel"),u.setAttribute("title",r?"Expand layers":"Collapse layers"),Vn(u,Li.toggle),u.classList.toggle("is-collapsed",r),u.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),r=!r,a()}),r)return;const g=()=>{o&&o.querySelectorAll(".polydraw-layer-row").forEach(t=>{t.classList.remove("polydraw-layer-row-dragging"),t.classList.remove("polydraw-layer-row-drag-over")})},d=()=>{i&&(i=!1,a())},p=t=>{var e,r;return(null==(r=null==(e=null==t?void 0:t.dataTransfer)?void 0:e.getData("text/plain"))?void 0:r.trim())||n};l.forEach(r=>{var i;const a=(null==(i=r.label)?void 0:i.trim())?r.label:r.id,l=s.DomUtil.create("div","polydraw-layer-row",o??void 0);if(l.setAttribute("tabindex","0"),l.setAttribute("role","button"),l.setAttribute("draggable","default"===r.id?"false":"true"),l.setAttribute("aria-label",`Activate layer ${a}`),l.setAttribute("data-layer-id",r.id),r.id===c&&l.classList.add("polydraw-layer-row-active"),r.visible||l.classList.add("polydraw-layer-hidden"),"default"!==r.id){const t=s.DomUtil.create("span","polydraw-layer-grip",l);t.setAttribute("aria-hidden","true"),Vn(t,Li.grip)}else s.DomUtil.create("span","polydraw-layer-grip-spacer",l).setAttribute("aria-hidden","true");s.DomUtil.create("span","polydraw-layer-color-indicator",l).style.backgroundColor=r.color;const h=s.DomUtil.create("span","polydraw-layer-name",l);h.textContent=a,h.setAttribute("title",a);const u=s.DomUtil.create("button","polydraw-layer-btn polydraw-layer-visibility",l);if(u.setAttribute("type","button"),u.setAttribute("title",r.visible?"Hide layer":"Show layer"),u.setAttribute("aria-label",r.visible?`Hide layer ${a}`:`Show layer ${a}`),Vn(u,r.visible?Li.eyeVisible:Li.eyeHidden),r.visible||u.classList.add("polydraw-layer-visibility-hidden"),u.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),t.setLayerVisibility(r.id,!r.visible)}),"default"!==r.id){const t=s.DomUtil.create("button","polydraw-layer-btn polydraw-layer-delete",l);t.setAttribute("type","button"),t.setAttribute("title","Delete layer"),t.setAttribute("aria-label",`Delete layer ${a}`),Vn(t,Li.delete),t.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),e.emit("polydraw:layer:delete-requested",{layerId:r.id})})}else s.DomUtil.create("span","polydraw-layer-btn-spacer",l).setAttribute("aria-hidden","true");l.addEventListener("click",()=>{t.setActiveLayer(r.id)}),l.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),t.setActiveLayer(r.id))}),"default"!==r.id&&(l.addEventListener("dragstart",t=>{n=r.id,l.classList.add("polydraw-layer-row-dragging"),t.dataTransfer&&(t.dataTransfer.effectAllowed="move",t.dataTransfer.setData("text/plain",r.id))}),l.addEventListener("dragend",()=>{n=null,g(),d()})),l.addEventListener("dragover",t=>{const e=p(t);e&&e!==r.id&&"default"!==r.id&&(t.preventDefault(),l.classList.add("polydraw-layer-row-drag-over"),t.dataTransfer&&(t.dataTransfer.dropEffect="move"))}),l.addEventListener("dragleave",()=>{l.classList.remove("polydraw-layer-row-drag-over")}),l.addEventListener("drop",t=>{const o=p(t);o&&o!==r.id&&"default"!==r.id&&(t.preventDefault(),t.stopPropagation(),e.emit("polydraw:layer:reorder-requested",{layerId:o,targetLayerId:r.id}),n=null,g(),d())})})},l=new(s.Control.extend({options:{position:"topright"},onAdd:()=>(o=s.DomUtil.create("div","leaflet-bar polydraw-layer-panel"),o.setAttribute("data-polydraw","layer-panel"),s.DomEvent.disableClickPropagation(o),s.DomEvent.disableScrollPropagation(o),s.DomEvent.on(o,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.on(o,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.on(o,"dragstart",s.DomEvent.stopPropagation),s.DomEvent.on(o,"dragover",s.DomEvent.stopPropagation),s.DomEvent.on(o,"drop",s.DomEvent.stopPropagation),a(),o),onRemove(){o&&(s.DomEvent.off(o,"mousedown",s.DomEvent.stopPropagation),s.DomEvent.off(o,"touchstart",s.DomEvent.stopPropagation),s.DomEvent.off(o,"dragstart",s.DomEvent.stopPropagation),s.DomEvent.off(o,"dragover",s.DomEvent.stopPropagation),s.DomEvent.off(o,"drop",s.DomEvent.stopPropagation),o=null,n=null,i=!1)}}));return l.refresh=()=>{a()},l}(this.layerManager,this.eventManager);return this.layerPanel=t,void t.addTo(this.map)}this.layerPanel.refresh()}else if(this.layerPanel){try{this.layerPanel.remove()}catch{}this.layerPanel=null}}syncFeatureGroupOrderWithLayers(){if(!this.layerManager)return;const t=this.arrayOfFeatureGroups;if(0===t.length)return;const e=new Set(t),r=new Set,o=[];for(const n of this.layerManager.getAllLayers())for(const t of n.featureGroups)e.has(t)&&!r.has(t)&&(r.add(t),o.push(t));for(const n of t)r.has(n)||o.push(n);this.isSameFeatureGroupOrder(t,o)||t.splice(0,t.length,...o),this.reapplyFeatureGroupMapOrder()}isSameFeatureGroupOrder(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r]!==e[r])return!1;return!0}reapplyFeatureGroupMapOrder(){if(!this.map||!this.layerManager)return;const t=this.arrayOfFeatureGroups.filter(t=>{const e=this.layerManager.getLayerForFeatureGroup(t),r=e?this.layerManager.getLayer(e):void 0;return!r||!1!==r.visible}),e=new Set(t);if(!this.arrayOfFeatureGroups.every(t=>{const r=e.has(t);return this.map.hasLayer(t)===r})||!this.isSameFeatureGroupOrder(this._lastAppliedVisibleMapOrder,t)){for(const t of this.arrayOfFeatureGroups)if(!e.has(t)&&this.map.hasLayer(t))try{this.map.removeLayer(t)}catch{}for(const e of t)try{this.map.hasLayer(e)&&this.map.removeLayer(e),e.addTo(this.map)}catch{}this._lastAppliedVisibleMapOrder=[...t]}}cleanupEmptyLayers(){if(!this.layerManager||this._isRestoringSnapshot)return;const t=[];for(const e of this.layerManager.getAllLayers())"default"!==e.id&&0===e.featureGroups.length&&t.push(e.id);for(const e of t)this.layerManager.deleteLayer(e);t.length>0&&this.updateLayerPanel()}stopDraw(){this.isDrawingInProgress=!1,this.resetTracker(),this.drawStartedEvents(!1)}setLeafletMapEvents(t,e,r){t?this.map.dragging.enable():this.map.dragging.disable(),e?this.map.doubleClickZoom.enable():this.map.doubleClickZoom.disable(),r?this.map.scrollWheelZoom.enable():this.map.scrollWheelZoom.disable()}resetTracker(){var t;null==(t=this.tracer)||t.setLatLngs([])}drawStartedEvents(t){if(this.drawEventsAttached===t)return;this.drawEventsAttached=t;const e=this.pointerEventsHandled,r=t?"on":"off";e||(this.map[r]("mousemove",this.mouseMove,this),this.map[r]("mouseup",this.mouseUpLeave,this)),t?(e||(this._boundTouchMove||(this._boundTouchMove=t=>this.mouseMove(t)),this._boundTouchEnd||(this._boundTouchEnd=t=>this.mouseUpLeave(t)),this.map.getContainer().addEventListener("touchmove",this._boundTouchMove,{passive:!1}),this.map.getContainer().addEventListener("touchend",this._boundTouchEnd,{passive:!1})),e&&(this._boundPointerMove||(this._boundPointerMove=t=>this.mouseMove(t)),this._boundPointerUp||(this._boundPointerUp=t=>this.mouseUpLeave(t)),this.map.getContainer().addEventListener("pointermove",this._boundPointerMove,{passive:!1}),this.map.getContainer().addEventListener("pointerup",this._boundPointerUp,{passive:!1}))):(this._boundTouchMove&&this.map.getContainer().removeEventListener("touchmove",this._boundTouchMove),this._boundTouchEnd&&this.map.getContainer().removeEventListener("touchend",this._boundTouchEnd),this._boundPointerMove&&this.map.getContainer().removeEventListener("pointermove",this._boundPointerMove),this._boundPointerUp&&this.map.getContainer().removeEventListener("pointerup",this._boundPointerUp))}events(t){if(this.mapEventsAttached===t)return;this.mapEventsAttached=t;const e=this.pointerEventsHandled,r=t?"on":"off";e||this.map[r]("mousedown",this.mouseDown,this),this.map[r]("dblclick",this.handleDoubleClick,this),t?(e||(this._boundTouchStart||(this._boundTouchStart=t=>this.handleTouchStart(t)),this.map.getContainer().addEventListener("touchstart",this._boundTouchStart,{passive:!1})),e&&(this._boundPointerDown||(this._boundPointerDown=t=>this.mouseDown(t)),this.map.getContainer().addEventListener("pointerdown",this._boundPointerDown,{passive:!1}))):(this._boundTouchStart&&this.map.getContainer().removeEventListener("touchstart",this._boundTouchStart),this._boundPointerDown&&this.map.getContainer().removeEventListener("pointerdown",this._boundPointerDown))}handleTouchStart(t){const e=Date.now(),r=e-this._lastTapTime;if(this.modeManager.getCurrentMode()===c.PointToPoint||this.modeManager.getCurrentMode()===c.PointToPointSubtract){this._tapTimeout&&(clearTimeout(this._tapTimeout),this._tapTimeout=null);const o=ii.extractCoordinates(t,this.map);return this.isP2PDoubleTapClose(o,r)?(this.handleDoubleTap(t),this._lastTapTime=0,void(this._lastTapLatLng=null)):(this._lastTapTime=e,this._lastTapLatLng=o,void this.mouseDown(t))}this._tapTimeout&&(clearTimeout(this._tapTimeout),this._tapTimeout=null),r<300&&r>0?(this.handleDoubleTap(t),this._lastTapTime=0):(this._lastTapTime=e,this._lastTapLatLng=ii.extractCoordinates(t,this.map),this.pointerEventsHandled||(this._tapTimeout=window.setTimeout(()=>{this.mouseDown(t),this._tapTimeout=null},300)))}isP2PDoubleTapClose(t,e){if(!t||!this._lastTapLatLng)return!1;if(e<=0||e>300)return!1;const r=this.map.latLngToLayerPoint(this._lastTapLatLng),o=this.map.latLngToLayerPoint(t);return r.distanceTo(o)<=36}handleDoubleTap(t){this.modeManager.getCurrentMode()!==c.PointToPoint&&this.modeManager.getCurrentMode()!==c.PointToPointSubtract||this.polygonDrawManager.handleDoubleTap(t)}mouseDown(t){var e;const r=ii.normalizeEvent(t);if(this.isEventFromControl(r))return;if(ii.shouldPreventDefault(r)&&(null==(e=r.preventDefault)||e.call(r)),this.modeManager.isInOffMode())return;const o=ii.extractCoordinates(r,this.map);if(!o)return;const n=this.modeManager.getCurrentMode()===c.PointToPoint||this.modeManager.getCurrentMode()===c.PointToPointSubtract;if(n&&"touch"===r.pointerType){const e=Date.now(),r=e-this._lastTapTime;if(this.isP2PDoubleTapClose(o,r))return this.handleDoubleTap(t),this._lastTapTime=0,void(this._lastTapLatLng=null);this._lastTapTime=e,this._lastTapLatLng=o}n?this.polygonDrawManager.handlePointToPointClick(o):this.tracer&&(this.isDrawingInProgress||(this.tracer.setLatLngs([o]),this.startDraw()))}isEventFromControl(t){var e,r;const o=this.getContainer();if(!o)return!1;const n=null==t?void 0:t.originalEvent;if(n&&this.controlEvents.has(n))return!0;if(t instanceof Event&&this.controlEvents.has(t))return!0;if(this.isRecentControlPointer(t))return!0;const i=(null==(e=null==n?void 0:n.composedPath)?void 0:e.call(n))??(null==(r=null==t?void 0:t.composedPath)?void 0:r.call(t));if(i&&i.some(t=>t instanceof Node&&o.contains(t)))return!0;const a=(null==n?void 0:n.target)??(null==t?void 0:t.target);if(a instanceof Node&&o.contains(a))return!0;const s=t=>{if(!t||"object"!=typeof t)return null;const e=t;if(e.touches&&e.touches.length>0)return{x:e.touches[0].clientX,y:e.touches[0].clientY};const r=t;if("number"==typeof r.clientX&&"number"==typeof r.clientY)return{x:r.clientX,y:r.clientY};const o=t;if(o.containerPoint&&this.map){const t=this.map.getContainer().getBoundingClientRect();return{x:t.left+o.containerPoint.x,y:t.top+o.containerPoint.y}}const n=t;if(n.latlng&&this.map){const t=this.map.latLngToContainerPoint(n.latlng),e=this.map.getContainer().getBoundingClientRect();return{x:e.left+t.x,y:e.top+t.y}}return null},l=s(null==t?void 0:t.originalEvent)??s(t);if(!l)return!1;const c=o.getBoundingClientRect();if(l.x>=c.left&&l.x<=c.right&&l.y>=c.top&&l.y<=c.bottom)return!0;const h=document.elementFromPoint(l.x,l.y);return!(!h||!o.contains(h))}extractPointerInfo(t){if(!t||"object"!=typeof t)return null;const e=t;if("number"==typeof e.pointerId)return{id:e.pointerId,pointerType:"string"==typeof e.pointerType?e.pointerType:"unknown"};if("string"==typeof e.type){if(e.type.startsWith("touch"))return{id:-2,pointerType:"touch"};if(e.type.startsWith("mouse"))return{id:-1,pointerType:"mouse"}}return null}markControlPointerDown(t){const e=this.extractPointerInfo(t);e&&(this.lastControlPointerDown={...e,time:Date.now()})}clearControlPointerDown(t){if(!this.lastControlPointerDown)return;const e=this.extractPointerInfo(t);e&&e.id===this.lastControlPointerDown.id&&(this.lastControlPointerDown=null)}isRecentControlPointer(t){if(!this.lastControlPointerDown)return!1;const e=null==t?void 0:t.originalEvent,r=this.extractPointerInfo(e)??this.extractPointerInfo(t);if(!r)return!1;const o="touch"===this.lastControlPointerDown.pointerType?450:80;return!(Date.now()-this.lastControlPointerDown.time>o)&&(r.pointerType===this.lastControlPointerDown.pointerType&&("mouse"===r.pointerType||r.id===this.lastControlPointerDown.id))}mouseMove(t){var e;if(!this.isDrawingInProgress)return;const r=ii.normalizeEvent(t);ii.shouldPreventDefault(r)&&(null==(e=r.preventDefault)||e.call(r));const o=ii.extractCoordinates(r,this.map);o&&this.tracer&&this.tracer.addLatLng(o)}async mouseUpLeave(t){var e;if(!this.isDrawingInProgress)return;const r=ii.normalizeEvent(t);if(ii.shouldPreventDefault(r)&&(null==(e=r.preventDefault)||e.call(r)),this.polygonInformation.deletePolygonInformationStorage(),!this.tracer)return void this.stopDraw();const o=this.tracer.toGeoJSON();if(!o||!o.geometry||!o.geometry.coordinates||o.geometry.coordinates.length<3)return void this.stopDraw();let n;try{n=this.turfHelper.createPolygonFromTrace(o)}catch{return void this.stopDraw()}if(n&&n.geometry&&n.geometry.coordinates&&0!==n.geometry.coordinates.length){this.stopDraw();try{const t=this.getInteractionTargetLayerId();switch(this.modeManager.getCurrentMode()){case c.Add:{const e=await this.polygonMutationManager.addPolygon(n,{simplify:!0,noMerge:!1,targetLayerId:t});e.success||console.error("Error adding polygon via manager:",e.error);break}case c.Subtract:{const e=await this.polygonMutationManager.subtractPolygon(n,{targetLayerId:t});e.success||console.error("Error subtracting polygon via manager:",e.error);break}}}catch(i){console.error("Error in mouseUpLeave polygon operation:",i)}this.polygonInformation.createPolygonInformationStorage(this.arrayOfFeatureGroups)}else this.stopDraw()}async handleFreehandDrawCompletion(t){try{this.saveHistory("freehand");const e=this.getInteractionTargetLayerId();switch(this.modeManager.getCurrentMode()){case c.Add:{const r=await this.polygonMutationManager.addPolygon(t,{simplify:!0,noMerge:!1,targetLayerId:e});r.success||console.error("Error adding polygon via manager:",r.error);break}case c.Subtract:{const r=await this.polygonMutationManager.subtractPolygon(t,{targetLayerId:e});r.success||console.error("Error subtracting polygon via manager:",r.error);break}}}catch(e){console.error("Error in mouseUpLeave polygon operation:",e)}}startDraw(){this.isDrawingInProgress||(this.isDrawingInProgress=!0,this.drawStartedEvents(!0))}setupKeyboardHandlers(){this._boundKeyDownHandler||(this._boundKeyDownHandler=this.handleKeyDown.bind(this)),this._boundKeyUpHandler||(this._boundKeyUpHandler=this.handleKeyUp.bind(this)),document.addEventListener("keydown",this._boundKeyDownHandler),document.addEventListener("keyup",this._boundKeyUpHandler)}removeKeyboardHandlers(){this._boundKeyDownHandler&&document.removeEventListener("keydown",this._boundKeyDownHandler),this._boundKeyUpHandler&&document.removeEventListener("keyup",this._boundKeyUpHandler)}handleKeyDown(t){const e=t.ctrlKey||t.metaKey;if(e&&"z"===t.key&&!t.shiftKey)return t.preventDefault(),void this.undo();if(e&&("y"===t.key||"z"===t.key&&t.shiftKey))return t.preventDefault(),void this.redo();"Escape"===t.key&&(this.modeManager.getCurrentMode()!==c.PointToPoint&&this.modeManager.getCurrentMode()!==c.PointToPointSubtract||this.polygonDrawManager.cancelPointToPointDrawing());this.isModifierKeyPressed(t)&&!this.isModifierKeyHeld&&(this.isModifierKeyHeld=!0,this.polygonDrawManager.setModifierKey(!0),this.updateAllMarkersForEdgeDeletion(!0),this.applyModifierModeOverride(!0))}handleKeyUp(t){!this.isModifierKeyPressed(t)&&this.isModifierKeyHeld&&(this.isModifierKeyHeld=!1,this.polygonDrawManager.setModifierKey(!1),this.updateAllMarkersForEdgeDeletion(!1),this.applyModifierModeOverride(!1))}applyModifierModeOverride(t){if(t){if(this.modifierModeOverride)return;if(!this.config.modifierSubtractMode)return;const t=this.modeManager.getCurrentMode();return void(t===c.Add?(this.modifierModeOverride={from:t,to:c.Subtract},this.setDrawMode(c.Subtract,{preserveActiveDraw:!0})):t===c.PointToPoint&&(this.modifierModeOverride={from:t,to:c.PointToPointSubtract},this.setDrawMode(c.PointToPointSubtract,{preserveActiveDraw:!0})))}if(!this.modifierModeOverride)return;const{from:e,to:r}=this.modifierModeOverride;this.modifierModeOverride=null,this.modeManager.getCurrentMode()===r&&this.setDrawMode(e,{preserveActiveDraw:!0})}updateAllMarkersForEdgeDeletion(t){this.arrayOfFeatureGroups.forEach(e=>{e.eachLayer(e=>{e instanceof s.Marker&&this.updateMarkerForEdgeDeletion(e,t)})})}updateMarkerForEdgeDeletion(t,e){const r=t.getElement();r&&(e?(r.addEventListener("mouseenter",this.onMarkerHoverForEdgeDeletionEvent),r.addEventListener("mouseleave",this.onMarkerLeaveForEdgeDeletionEvent)):(r.removeEventListener("mouseenter",this.onMarkerHoverForEdgeDeletionEvent),r.removeEventListener("mouseleave",this.onMarkerLeaveForEdgeDeletionEvent),r.style.backgroundColor="",r.style.borderColor=""))}handleDoubleClick(t){this.modeManager.getCurrentMode()!==c.PointToPoint&&this.modeManager.getCurrentMode()!==c.PointToPointSubtract||(s.DomEvent.stop(t),this.polygonDrawManager.handleDoubleClick(t))}isModifierKeyPressed(t){return navigator.userAgent.toLowerCase().includes("mac")?t.metaKey:t.ctrlKey}ensureButtonTouchResponsiveness(t){t.querySelectorAll("a").forEach(t=>{t.style.pointerEvents="auto",t.style.touchAction="manipulation",t.style.position="relative",t.style.zIndex="1";const e=t=>{t.stopPropagation(),t.target.style.pointerEvents="auto"};t.addEventListener("touchstart",e,{passive:!0}),t.addEventListener("touchend",e,{passive:!0})})}updateActivateButtonIndicator(){if("function"!=typeof this.getContainer)return;const t=this.getContainer();if(!t)return;const e=t.querySelector(".icon-activate");if(!e)return;const r=this.arrayOfFeatureGroups.length>0,o=!Yn.domUtil.hasClass(e,"active"),n=Yn.domUtil.hasClass(e,"active")?e.dataset.collapsedIcon:e.dataset.activeIcon;n&&this.applyActivateButtonIcon(e,n);const i=r&&o;i?Yn.domUtil.addClass(e,"polydraw-indicator-active"):Yn.domUtil.removeClass(e,"polydraw-indicator-active");const a=this.config.styles.ui.controlButton.backgroundColor,s=this.config.styles.ui.controlButton.color,l=this.config.styles.ui.indicatorActive.backgroundColor;e.style.backgroundColor=i?l:a,e.style.color=s;const h=(t,e)=>{t&&(e?(t.style.opacity="1",t.style.pointerEvents="auto",t.setAttribute("aria-disabled","false"),t.tabIndex=0):(t.style.opacity="0.3",t.style.pointerEvents="none",t.setAttribute("aria-disabled","true"),t.tabIndex=-1))};h(t.querySelector(".icon-clone"),r),r||this.modeManager.getCurrentMode()!==c.Clone||this.setDrawMode(c.Off);h(t.querySelector(".icon-erase"),r)}applyActivateButtonIcon(t,e){Vn(t,e)}}const Oi=t=>{if(t){if("undefined"!=typeof globalThis){globalThis.L||(globalThis.L=t)}t.control&&(t.control.polydraw=function(t){return new Ai(t)}),Xn.reset()}};if("undefined"!=typeof globalThis){const t=globalThis.L;t&&Oi(t)}t.default=Ai,t.leafletAdapter=Yn,t.registerWithLeaflet=Oi,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
2
2
  //# sourceMappingURL=polydraw.umd.min.js.map