terra-draw 1.28.0 → 1.28.2

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.
@@ -1,2 +1,2 @@
1
- function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);i<e;i++)n[i]=t[i];return n}function e(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,a(n.key),n)}}function i(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(e,i){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,i){if(e){if("string"==typeof e)return t(e,i);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,i):void 0}}(e))||i&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)({}).hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},o.apply(null,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function a(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}var d,u="draw",h="edit",l="deleteCoordinate",c="insertMidpoint";!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(d||(d={}));var p="https://raw.githubusercontent.com/JamesLMilner/terra-draw/refs/heads/main/assets/markers/marker-blue.png",g={SELECTED:"selected",MID_POINT:"midPoint",SELECTION_POINT_FEATURE_ID:"selectionPointFeatureId",SELECTION_POINT:"selectionPoint"},f={MODE:"mode",CURRENTLY_DRAWING:"currentlyDrawing",EDITED:"edited",CLOSING_POINT:"closingPoint",SNAPPING_POINT:"snappingPoint",COORDINATE_POINT:"coordinatePoint",COORDINATE_POINT_FEATURE_ID:"coordinatePointFeatureId",COORDINATE_POINT_IDS:"coordinatePointIds",PROVISIONAL_COORDINATE_COUNT:"provisionalCoordinateCount",COMMITTED_COORDINATE_COUNT:"committedCoordinateCount",MARKER:"marker"},y=10;function v(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function m(t){return Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}function C(t){return!!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}var P,I="Feature is not a Polygon",S="Feature mode property does not match the mode being added to";!function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render"}(P||(P={}));var F={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},x=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=!1),this._state="unregistered",this._styles={},this.pointerEvents=F,this.behaviors=[],this.validate=void 0,this.pointerDistance=40,this.coordinatePrecision=void 0,this.undoRedoMaxStackSize=void 0,this.onStyleChange=void 0,this.store=void 0,this.projection="web-mercator",this.setDoubleClickToZoom=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.isInitialUpdate=!1,this.type=P.Drawing,this.mode="base",e?this.isInitialUpdate=!0:this.updateOptions(o({},t))}var e=t.prototype;return e.registerBehaviors=function(t){},e.updateOptions=function(t){null!=t&&t.styles&&(this.styles=o({},this._styles,t.styles)),null!=t&&t.pointerDistance&&(this.pointerDistance=t.pointerDistance),null!=t&&t.validation&&(this.validate=t&&t.validation),null!=t&&t.projection&&(this.projection=t.projection),void 0!==(null==t?void 0:t.pointerEvents)&&(this.pointerEvents=t.pointerEvents),null!=t&&t.modeName&&!0===this.isInitialUpdate&&(this.mode=t.modeName),this.isInitialUpdate=!1},e.allowPointerEvent=function(t,e){return"boolean"==typeof t?t:"function"!=typeof t||t(e)},e.setDrawing=function(){if("started"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="drawing"},e.setStarted=function(){if("stopped"!==this._state&&"registered"!==this._state&&"drawing"!==this._state&&"selecting"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="started",this.setDoubleClickToZoom(!1)},e.setStopped=function(){if("started"!==this._state)throw new Error("Mode must be started to be stopped");this._state="stopped",this.setDoubleClickToZoom(!0)},e.register=function(t){if("unregistered"!==this._state)throw new Error("Can not register unless mode is unregistered");this._state="registered",this.store=t.store,this.store.registerOnChange(t.onChange),this.setDoubleClickToZoom=t.setDoubleClickToZoom,this.project=t.project,this.unproject=t.unproject,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect,this.setCursor=t.setCursor,this.onStyleChange=t.onChange,this.onFinish=t.onFinish,this.coordinatePrecision=t.coordinatePrecision,this.undoRedoMaxStackSize=t.undoRedoMaxStackSize,this.registerBehaviors({mode:t.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:t.coordinatePrecision,projection:this.projection,undoRedoMaxStackSize:t.undoRedoMaxStackSize})},e.validateFeature=function(t){return this.performFeatureValidation(t)},e.afterFeatureAdded=function(t){},e.afterFeatureUpdated=function(t){},e.performFeatureValidation=function(t){if("unregistered"===this._state)throw new Error("Mode must be registered");var e=function(t,e){var i;if(v(t))if(null==t.id)i="Feature has no id";else if("string"!=typeof t.id&&"number"!=typeof t.id)i="Feature must be string or number as per GeoJSON spec";else if(e(t.id))if(v(t.geometry))if(v(t.properties))if("string"==typeof t.geometry.type&&["Polygon","LineString","Point"].includes(t.geometry.type))if(Array.isArray(t.geometry.coordinates)){if(!t.properties.mode||"string"!=typeof t.properties.mode)return{valid:!1,reason:"Feature does not have a valid mode property"}}else i="Feature coordinates is not an array";else i="Feature is not Point, LineString or Polygon";else i="Feature has no properties";else i="Feature has no geometry";else i="Feature must match the id strategy (default is UUID4)";else i="Feature is not object";return i?{valid:!1,reason:i}:{valid:!0}}(t,this.store.idStrategy.isValidId);if(!e.valid)return e;if(this.validate){var i=this.validate(t,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Provisional});return{valid:e.valid&&i.valid,reason:i.reason}}return{valid:e.valid,reason:e.reason}},e.validateModeFeature=function(t,e){var i=this.performFeatureValidation(t);return i.valid?t.properties.mode===this.mode?e(t):{valid:!1,reason:S}:{valid:!1,reason:i.reason}},e.onFinish=function(t,e){},e.onDeselect=function(t){},e.onSelect=function(t){},e.onKeyDown=function(t){},e.onKeyUp=function(t){},e.undo=function(){},e.clearHistory=function(){},e.undoSize=function(){return 0},e.redoSize=function(){return 0},e.redo=function(){},e.onMouseMove=function(t){},e.onClick=function(t){},e.onDragStart=function(t,e){},e.onDrag=function(t,e){},e.onDragEnd=function(t,e){},e.getHexColorStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getNumericStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getUrlStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getStylingValue=function(t,e,i){return void 0===t?e:"function"==typeof t?null!=(n=t(i))?n:e:t;var n},i(t,[{key:"state",get:function(){return this._state},set:function(t){throw new Error("Please use the modes lifecycle methods")}},{key:"styles",get:function(){return this._styles},set:function(t){if("object"!=typeof t)throw new Error("Styling must be an object");this.onStyleChange&&this.onStyleChange([],"styling"),this._styles=t}}])}(),M=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).type=P.Select,e}return r(e,t),e}(x);function w(t,e){var i=function(t){return t*Math.PI/180},n=i(t[1]),o=i(t[0]),r=i(e[1]),s=r-n,a=i(e[0])-o,d=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d))*6371e3/1e3}var O=6371008.8;function E(t){return t%360*Math.PI/180}function D(t){return t/6371.0088}function k(t){return t%(2*Math.PI)*180/Math.PI}function b(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var _=57.29577951308232,T=.017453292519943295,N=6378137,R=function(t,e){return{x:0===t?0:t*T*N,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*T/2))*N}},U=function(t,e){return{lng:0===t?0:_*(t/N),lat:0===e?0:(2*Math.atan(Math.exp(e/N))-Math.PI/2)*_}};function W(t,e,i){var n=E(t[0]),o=E(t[1]),r=E(i),s=D(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[k(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),k(a)]}function L(t){for(var e=t.center,i=t.radiusKilometers,n=t.coordinatePrecision,o=t.steps?t.steps:64,r=[],s=0;s<o;s++){var a=W(e,i,-360*s/o);r.push([b(a[0],n),b(a[1],n)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function A(t){var e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}for(var i=[],n=0;n<e.length;n++)for(var o=0;o<e[n].length-1;o++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)d(n,o,r,s);return i.length>0;function a(t){return t<0||t>1}function d(t,n,o,r){var s,d=e[t][n],u=e[t][n+1],h=e[o][r],l=e[o][r+1],c=function(t,e,i,n){if(B(t,i)||B(t,n)||B(e,i)||B(n,i))return null;var o=t[0],r=t[1],s=e[0],a=e[1],d=i[0],u=i[1],h=n[0],l=n[1],c=(o-s)*(u-l)-(r-a)*(d-h);return 0===c?null:[((o*a-r*s)*(d-h)-(o-s)*(d*l-u*h))/c,((o*a-r*s)*(u-l)-(r-a)*(d*l-u*h))/c]}(d,u,h,l);null!==c&&(s=l[0]!==h[0]?(c[0]-h[0])/(l[0]-h[0]):(c[1]-h[1])/(l[1]-h[1]),a(u[0]!==d[0]?(c[0]-d[0])/(u[0]-d[0]):(c[1]-d[1])/(u[1]-d[1]))||a(s)||(c.toString(),i.push(c)))}}function B(t,e){return t[0]===e[0]&&t[1]===e[1]}function z(t,e){return G(t[0])<=e&&G(t[1])<=e}function H(t){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(i=t[0])>=-180&&i<=180&&(e=t[1])>=-90&&e<=90;var e,i}function G(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var V="Feature has holes",j="Feature has less than 4 coordinates",K="Feature has invalid coordinates",Y="Feature coordinates are not closed";function X(t,e){if("Polygon"!==t.geometry.type)return{valid:!1,reason:"Feature is not a Polygon"};if(1!==t.geometry.coordinates.length)return{valid:!1,reason:V};if(t.geometry.coordinates[0].length<4)return{valid:!1,reason:j};for(var i=0;i<t.geometry.coordinates[0].length;i++){if(!H(t.geometry.coordinates[0][i]))return{valid:!1,reason:K};if(!z(t.geometry.coordinates[0][i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return(n=t.geometry.coordinates[0][0])[0]!==(o=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]||n[1]!==o[1]?{valid:!1,reason:Y}:{valid:!0};var n,o}function q(t,e){var i=X(t,e);return i.valid?A(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}var Z=function(t){var e=t.store,i=t.mode,n=t.project,o=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision,a=t.projection,d=t.undoRedoMaxStackSize;this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.undoRedoMaxStackSize=void 0,this.store=e,this.mode=i,this.project=n,this.unproject=o,this.pointerDistance=r,this.coordinatePrecision=s,this.projection=a,this.undoRedoMaxStackSize=d};function J(t){var e=function(t){for(var e=t.coordinates[0],i=0,n=0;n<e.length-1;n++){var o=e[n],r=e[n+1];i+=(r[0]-o[0])*(r[1]+o[1])}return i<0}(t);if(!e)return{type:"Polygon",coordinates:[t.coordinates[0].reverse()]}}var $="insert-before",Q="insert-after",tt="update",et="delete",it="replace",nt=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).options=void 0,n.options=i,n}r(e,t);var i=e.prototype;return i.createPoint=function(t){var e=t.coordinates,i=t.properties,n=t.context;if((null==n?void 0:n.updateType)!==d.Finish||this.validateGeometryWithUpdateType({geometry:{type:"Point",coordinates:e},properties:i,updateType:d.Finish}))return this.handleCreateFeature({geometry:{type:"Point",coordinates:e},properties:i})},i.createLineString=function(t){return this.handleCreateFeature({geometry:{type:"LineString",coordinates:t.coordinates},properties:t.properties})},i.createPolygon=function(t){var e=t.coordinates,i=t.properties,n=J({type:"Polygon",coordinates:[e]});return this.handleCreateFeature({geometry:{type:"Polygon",coordinates:n?n.coordinates:[e]},properties:i})},i.createGuidancePoint=function(t){return this.createGuidancePoints({coordinates:[t.coordinate],type:t.type})[0]},i.createGuidancePoints=function(t){var e=this,i=t.type,n=t.additionalProperties,r=t.coordinates.map(function(t,r){var s;return{type:"Feature",geometry:{type:"Point",coordinates:t},properties:o((s={mode:e.mode},s[i]=!0,s),n?n(r):{})}});return this.createFeatures(r)},i.updatePoint=function(t){return this.handleMutateFeature({type:"Point",featureId:t.featureId,coordinateMutations:t.coordinateMutations,propertyMutations:t.propertyMutations,context:t.context})},i.updatePolygon=function(t){return this.handleMutateFeature({type:"Polygon",featureId:t.featureId,coordinateMutations:t.coordinateMutations,propertyMutations:t.propertyMutations,context:t.context})},i.updateLineString=function(t){return this.handleMutateFeature({type:"LineString",featureId:t.featureId,coordinateMutations:t.coordinateMutations,propertyMutations:t.propertyMutations,context:t.context})},i.deleteFeatureIfPresent=function(t){t&&this.store.has(t)&&this.store.delete([t])},i.deleteFeaturesIfPresent=function(t){var e=this;if(0!==t.length){var i=t.filter(function(t){return e.store.has(t)});i.length&&this.store.delete(i)}},i.setDeselected=function(t){var e=this,i=t.filter(function(t){return e.store.has(t)}).map(function(t){var e;return{featureId:t,properties:(e={},e[g.SELECTED]=!1,e)}});this.updateFeatureProperties(i)},i.setSelected=function(t){var e,i=this.store.getGeometryCopy(t).type,n={featureId:t,propertyMutations:(e={},e[g.SELECTED]=!0,e),context:{updateType:d.Commit}};"Polygon"===i?this.updatePolygon(n):"LineString"===i?this.updateLineString(n):"Point"===i&&this.updatePoint(n)},i.updateGuidancePoints=function(t){this.updateFeatureGeometries(t.map(function(t){return{id:t.featureId,geometry:{type:"Point",coordinates:t.coordinate}}}))},i.handleCreateFeature=function(t){return this.createFeatureWithGeometry({geometry:t.geometry,properties:t.properties})},i.handleMutateFeature=function(t){var e=t.featureId,i=t.coordinateMutations,n=t.context;if(!this.mutateFeature({type:t.type,featureId:e,coordinateMutations:i,propertyMutations:t.propertyMutations,context:n.updateType===d.Finish?o({},n,{correctRightHandRule:!0}):o({},n)}))return null;var r=this.buildFeatureWithGeometry(e);return n.updateType!==d.Finish||i||this.validateGeometryWithUpdateType({geometry:r.geometry,properties:r.properties,updateType:n.updateType})?r:null},i.mutateFeature=function(t){var e=t.type,i=t.featureId,n=t.coordinateMutations,o=t.propertyMutations,r=t.context;if(!i)return!1;var s=this.store.getGeometryCopy(i),a=this.store.getPropertiesCopy(i);if(s.type!==e)throw new Error(e+" geometries cannot be updated on features with "+s.type+" geometries");if(n){var d=this.applyCoordinateMutations(s,n);if(r.correctRightHandRule&&"Polygon"===d.type){var u=J(d);u&&(d=u)}if(!this.validateGeometryWithUpdateType({geometry:d,properties:a,updateType:r.updateType}))return!1;this.updateFeatureGeometries([{id:i,geometry:d}])}return o&&this.updateFeatureProperties([{featureId:i,properties:o}]),!0},i.applyCoordinateMutations=function(t,e){if(this.isReplaceMutation(e))return o({},t,{coordinates:e.coordinates});if("Point"===t.type)throw new Error("Coordinate mutations are not supported for Point geometries");for(var i,r="Polygon"===t.type,s=r?t.coordinates[0].slice():t.coordinates.slice(),a=s.length,d=function(t){var e=t<0?a+t:t;if(e<0||e>=a)throw new RangeError("Index "+t+" (normalized to "+e+") is out of bounds");return e},u=new Array(a).fill(void 0),h=Array.from({length:a},function(){return[]}),l=Array.from({length:a},function(){return[]}),c=[],p=n(e);!(i=p()).done;){var g=i.value;if(g.type!==$&&g.type!==Q){var f=d(g.index);u[f]=o({},g,{index:f})}else{var y=g.index,v=y<0?a+y:y;if(v<0||v>a)throw new RangeError("Index "+g.index+" (normalized to "+v+") is out of bounds");if(g.type===$){if(v>=a)throw new RangeError("INSERT_BEFORE index "+g.index+" (normalized to "+v+") is out of bounds for length "+a);h[v].push(g)}else v===a?c.push(g):l[v].push(g)}}for(var m=[],C=0;C<a;C++){for(var P,I=n(h[C]);!(P=I()).done;)m.push(P.value.coordinate);var S=u[C];S?S.type===et||m.push(S.coordinate):m.push(s[C]);for(var F,x=n(l[C]);!(F=x()).done;)m.push(F.value.coordinate)}for(var M=0,w=c;M<w.length;M++)m.push(w[M].coordinate);return o({},t,r?{coordinates:[m].concat(t.coordinates.slice(1))}:{coordinates:m})},i.isReplaceMutation=function(t){return t.type===it},i.createFeatureWithGeometry=function(t){var e=this.createFeatures([{type:"Feature",geometry:t.geometry,properties:t.properties}])[0];return{id:e,type:"Feature",properties:this.store.getPropertiesCopy(e),geometry:this.store.getGeometryCopy(e)}},i.validateGeometryWithUpdateType=function(t){return!this.options.validate||this.options.validate({type:"Feature",geometry:t.geometry,properties:t.properties||{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:t.updateType}).valid},i.buildFeatureWithGeometry=function(t){return{id:t,type:"Feature",properties:this.store.getPropertiesCopy(t),geometry:this.store.getGeometryCopy(t)}},i.createFeatures=function(t){return this.store.create(t)},i.updateFeatureGeometries=function(t){this.store.updateGeometry(t)},i.updateFeatureProperties=function(t){var e=t.map(function(t){var e=t.featureId;return Object.entries(t.properties).map(function(t){return{id:e,property:t[0],value:t[1]}})}).flat();this.store.updateProperty(e)},e}(Z),ot={cancel:"Escape",finish:"Enter"},rt={start:"crosshair"},st=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="circle",i.center=void 0,i.endPosition=void 0,i.segments=64,i.currentCircleId=void 0,i.keyEvents=ot,i.cursors=rt,i.startingRadiusKilometers=1e-5,i.cursorMovedAfterInitialCursorDown=!1,i.drawInteraction="click-move",i.drawType=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.startingRadiusKilometers&&(this.startingRadiusKilometers=e.startingRadiusKilometers),null!=e&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction),null!=e&&e.segments&&(this.segments=e.segments<3?3:e.segments)},i.close=function(){if(void 0!==this.currentCircleId&&void 0!==this.endPosition&&this.updateCircle(this.endPosition,d.Finish)){var t=this.currentCircleId;this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:u})}},i.beginDrawing=function(t,e){var i;void 0===e&&(e="click"),this.center=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];var n=L({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),o=this.mutateFeature.createPolygon({coordinates:n.geometry.coordinates[0],properties:(i={mode:this.mode,radiusKilometers:this.startingRadiusKilometers},i[f.CURRENTLY_DRAWING]=!0,i)});o&&(this.currentCircleId=o.id,this.cursorMovedAfterInitialCursorDown=!1,this.drawType=e,this.setDrawing())},i.dragDrawAllowed=function(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.moveDrawAllowed=function(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.center?this.center&&void 0!==this.currentCircleId&&(this.endPosition=[t.lng,t.lat],this.close()):this.beginDrawing(t))},i.onMouseMove=function(t){this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(this.endPosition,d.Provisional)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(t,e){"drawing"!==this.state&&this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1))},i.onDrag=function(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(this.endPosition,d.Provisional))},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.close(),e(!0))},i.cleanUp=function(){var t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.updateCircle=function(t,e){if(void 0!==this.currentCircleId&&void 0!==this.center){var i,n,o=e===d.Finish;if(this.cursorMovedAfterInitialCursorDown)if(n=w(this.center,t),"web-mercator"===this.projection){var r=function(t,e){var i=1e3*w(t,e);if(0===i)return 1;var n=R(t[0],t[1]),o=n.x,r=n.y,s=R(e[0],e[1]),a=s.y;return Math.sqrt(Math.pow(s.x-o,2)+Math.pow(a-r,2))/i}(this.center,t);i=function(t){for(var e=t.center,i=t.coordinatePrecision,n=t.steps?t.steps:64,o=1e3*t.radiusKilometers,r=R(e[0],e[1]),s=r.x,a=r.y,d=[],u=0;u<n;u++){var h=360*u/n*Math.PI/180,l=o*Math.cos(h),c=o*Math.sin(h),p=U(s+l,a+c),g=p.lat;d.push([b(p.lng,i),b(g,i)])}return d.push(d[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[d]},properties:{}}}({center:this.center,radiusKilometers:n*r,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}else{if("globe"!==this.projection)throw new Error("Invalid projection");i=L({center:this.center,radiusKilometers:n,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}var s={};return i&&n&&(s.radiusKilometers=n),o&&(s[f.CURRENTLY_DRAWING]=void 0),this.mutateFeature.updatePolygon({featureId:this.currentCircleId,coordinateMutations:i?{type:it,coordinates:i.geometry.coordinates}:void 0,propertyMutations:s,context:o?{updateType:e,action:u}:{updateType:e}})}},i.afterFeatureUpdated=function(t){this.currentCircleId===t.id&&(this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.mutateFeature=new nt(t,{validate:this.validate})},e}(x),at=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.sqrt(n*n+i*i)};function dt(t,e){return t[0]===e[0]&&t[1]===e[1]}var ut=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}r(e,t);var i=e.prototype;return i.getGeometryType=function(t){return this.store.getGeometryCopy(t).type},i.coordinateAtIndexIsIdentical=function(t){var e,i=t.newCoordinate,n=t.index,o=this.store.getGeometryCopy(t.featureId);if("Polygon"===o.type)e=o.coordinates[0][n];else if("LineString"===o.type)e=o.coordinates[n];else{if(0!==n)throw new Error("Point geometries only have one coordinate at index 0");e=o.coordinates}return dt(i,e)},i.getGeometry=function(t){return this.store.getGeometryCopy(t)},i.getCoordinates=function(t){var e=this.store.getGeometryCopy(t),i=e.coordinates;return"Polygon"===e.type?i[0]:i},i.getCoordinate=function(t,e){var i=this.getCoordinates(t),n=e<0?i.length+e:e;if(n<0||n>=i.length)throw new RangeError("Index "+e+" (normalized to "+n+") is out of bounds");return i[n]},i.getProperties=function(t){return this.store.getPropertiesCopy(t)},i.hasFeature=function(t){return this.store.has(t)},i.getAllFeatureIdsWhere=function(t){return this.store.copyAllWhere(t).map(function(t){return t.id})},e}(Z),ht={cancel:"Escape",finish:"Enter"},lt={start:"crosshair",close:"pointer"},ct=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="freehand",i.canClose=!1,i.currentId=void 0,i.closingPointId=void 0,i.minDistance=20,i.keyEvents=ht,i.cursors=lt,i.preventPointsNearClose=!0,i.autoClose=!1,i.autoCloseTimeout=500,i.hasLeftStartingPoint=!1,i.preventNewFeature=!1,i.drawInteraction="click-move",i.drawType=void 0,i.smoothing=0,i.mutateFeature=void 0,i.readFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.minDistance&&(this.minDistance=e.minDistance),void 0!==(null==e?void 0:e.smoothing)&&(this.smoothing=Math.min(Math.max(e.smoothing,0),.999)),void 0!==(null==e?void 0:e.preventPointsNearClose)&&(this.preventPointsNearClose=e.preventPointsNearClose),void 0!==(null==e?void 0:e.autoClose)&&(this.autoClose=e.autoClose),null!=e&&e.autoCloseTimeout&&(this.autoCloseTimeout=e.autoCloseTimeout),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null!=e&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction)},i.moveDrawAllowed=function(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.dragDrawAllowed=function(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.beginDrawing=function(t,e){var i;void 0===e&&(e="click");var n=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(i={mode:this.mode},i[f.CURRENTLY_DRAWING]=!0,i)});this.currentId=n.id,this.drawType=e,this.closingPointId=this.mutateFeature.createGuidancePoint({coordinate:[t.lng,t.lat],type:f.CLOSING_POINT}),this.canClose=!0,"drawing"!==this.state&&this.setDrawing()},i.addCoordinate=function(t){var e=this;if(void 0!==this.currentId&&!1!==this.canClose){var i=this.readFeature.getCoordinate(this.currentId,-2),n=i[0],o=i[1],r=this.project(n,o),s=at({x:r.x,y:r.y},{x:t.containerX,y:t.containerY}),a=this.readFeature.getCoordinate(this.currentId,0),u=this.project(a[0],a[1]);if(at({x:u.x,y:u.y},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.autoClose&&this.hasLeftStartingPoint&&(this.preventNewFeature=!0,setTimeout(function(){e.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(!(s<this.minDistance)){var h=this.getSmoothedCoordinate([n,o],[t.lng,t.lat]);this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:$,index:-1,coordinate:h}],context:{updateType:d.Provisional}})}}else this.setCursor(this.cursors.start)},i.getSmoothedCoordinate=function(t,e){return 0===this.smoothing?e:[t[0]*this.smoothing+e[0]*(1-this.smoothing),t[1]*this.smoothing+e[1]*(1-this.smoothing)]},i.close=function(){var t;if(void 0!==this.currentId&&this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),context:{updateType:d.Finish,action:u}})){var e=this.currentId;this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:u})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.moveDrawAllowed()&&"click"===this.drawType&&this.addCoordinate(t)},i.onClick=function(t){if(this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))){if(this.preventNewFeature)return;if(!1===this.canClose)return void this.beginDrawing(t);this.close()}},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&!0===this.canClose&&this.close()},i.onDragStart=function(t,e){"drawing"!==this.state&&(this.preventNewFeature||this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1)))},i.onDrag=function(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&this.addCoordinate(t)},i.onDragEnd=function(t,e){var i=this;this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.preventNewFeature=!0,setTimeout(function(){i.preventNewFeature=!1},this.autoCloseTimeout),this.close(),e(!0))},i.cleanUp=function(){var t=this.currentId,e=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.canClose=!1,this.hasLeftStartingPoint=!1,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,void 0===e.pointOpacity?1:e.pointOpacity,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,void 0===e.pointOutlineOpacity?1:e.pointOutlineOpacity,t),e.zIndex=50,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return X(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},e}(x);function pt(t){var e=t.unproject,i=t.point,n=t.pointerDistance/2,o=i.x,r=i.y;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[e(o-n,r-n),e(o+n,r-n),e(o+n,r+n),e(o-n,r+n),e(o-n,r-n)].map(function(t){return[t.lng,t.lat]})]}}}var gt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.create=function(t){return pt({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(Z),ft=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.measure=function(t,e){var i=this.project(e[0],e[1]);return at({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(Z),yt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinateFirstClick=function(t){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)}).coordinate},o.getSnappableCoordinate=function(t,e){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)}).coordinate},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),o=this.store.search(n,e),r={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDist:Infinity};return o.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}n.forEach(function(n,o){var s=i.pixelDistance.measure(t,n);s<r.minDist&&s<i.pointerDistance&&(r.coordinate=n,r.minDist=s,r.featureId=e.id,r.featureCoordinateIndex=o)})}),r},e}(Z);function vt(t,e,i){var n=E(t[0]),o=E(t[1]),r=E(i),s=D(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[k(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),k(a)]}function mt(t,e,i){var n=t.x,o=t.y,r=E(i);return{x:n+e*Math.cos(r),y:o+e*Math.sin(r)}}function Ct(t,e){var i=E(t[0]),n=E(e[0]),o=E(t[1]),r=E(e[1]),s=Math.sin(n-i)*Math.cos(r),a=Math.cos(o)*Math.sin(r)-Math.sin(o)*Math.cos(r)*Math.cos(n-i);return k(Math.atan2(s,a))}function Pt(t,e){var i=e.x-t.x,n=e.y-t.y;if(0===i&&0===n)return 0;var o=Math.atan2(n,i);return(o*=180/Math.PI)>180?o-=360:o<-180&&(o+=360),o}function It(t){return(t+360)%360}function St(t,e,i){for(var n,o,r,s=[],a=t.length,d=0,u=0;u<t.length&&!(e>=d&&u===t.length-1);u++){if(d>e&&0===s.length){if(!(n=e-d))return s.push(t[u]),s;o=Ct(t[u],t[u-1])-180,r=vt(t[u],n,o),s.push(r)}if(d>=i)return(n=i-d)?(o=Ct(t[u],t[u-1])-180,r=vt(t[u],n,o),s.push(r),s):(s.push(t[u]),s);if(d>=e&&s.push(t[u]),u===t.length-1)return s;d+=w(t[u],t[u+1])}if(d<e&&t.length===a)throw new Error("Start position is beyond line");var h=t[t.length-1];return[h,h]}function Ft(t){return t*(Math.PI/180)}function xt(t){return t*(180/Math.PI)}var Mt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.config=e,i}r(e,t);var i=e.prototype;return i.generateInsertionCoordinates=function(t,e,i){for(var n=[t,e],o=0,r=0;r<n.length-1;r++)o+=w(n[0],n[1]);if(o<=i)return n;var s=o/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);for(var a=[],d=0;d<s;d++){var u=St(n,i*d,i*(d+1));a.push(u)}for(var h=[],l=0;l<a.length;l++)h.push(a[l][1]);return this.limitCoordinates(h)},i.generateInsertionGeodesicCoordinates=function(t,e,i){var n=w(t,e),o=function(t,e,i){var n=[],o=Ft(t[1]),r=Ft(t[0]),s=Ft(e[1]),a=Ft(e[0]);i+=1;var d=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-o)/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin((a-r)/2),2)));if(0===d||isNaN(d))return n;for(var u=0;u<=i;u++){var h=u/i,l=Math.sin((1-h)*d)/Math.sin(d),c=Math.sin(h*d)/Math.sin(d),p=l*Math.cos(o)*Math.cos(r)+c*Math.cos(s)*Math.cos(a),g=l*Math.cos(o)*Math.sin(r)+c*Math.cos(s)*Math.sin(a),f=l*Math.sin(o)+c*Math.sin(s);if(!(isNaN(p)||isNaN(g)||isNaN(f))){var y=Math.atan2(f,Math.sqrt(Math.pow(p,2)+Math.pow(g,2))),v=Math.atan2(g,p);isNaN(y)||isNaN(v)||n.push([xt(v),xt(y)])}}return n.slice(1,-1)}(t,e,Math.floor(n/i));return this.limitCoordinates(o)},i.limitCoordinates=function(t){var e=this;return t.map(function(t){return[b(t[0],e.config.coordinatePrecision),b(t[1],e.config.coordinatePrecision)]})},e}(Z);function wt(t,e){if("LineString"!==t.geometry.type)return{valid:!1,reason:"Feature is not a LineString"};if(t.geometry.coordinates.length<2)return{valid:!1,reason:"Feature has less than 2 coordinates"};for(var i=0;i<t.geometry.coordinates.length;i++){if(!H(t.geometry.coordinates[i]))return{valid:!1,reason:"Feature has invalid coordinates"};if(!z(t.geometry.coordinates[i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return{valid:!0}}function Ot(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function Et(t,e){var i=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}(t,e)/(Ot(t)*Ot(e));return Math.acos(Math.min(Math.max(i,-1),1))}function Dt(t){var e=E(t[1]),i=E(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function kt(t){var e=t[0],i=t[1],n=k(Math.asin(t[2]));return[k(Math.atan2(i,e)),n]}var bt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinateFirstClick=function(t){var e=o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)});return e.coordinate?[b(e.coordinate[0],o.config.coordinatePrecision),b(e.coordinate[1],o.config.coordinatePrecision)]:void 0},o.getSnappableCoordinate=function(t,e){var i=o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)});return i.coordinate?[b(i.coordinate[0],o.config.coordinatePrecision),b(i.coordinate[1],o.config.coordinatePrecision)]:void 0},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getSnappable=function(t,e){var i=this,o=this.clickBoundingBox.create(t),r=this.store.search(o,e),s={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:Infinity};return r.forEach(function(e){var o;if("Polygon"===e.geometry.type)o=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;o=e.geometry.coordinates}for(var r,a=[],d=0;d<o.length-1;d++)a.push([o[d],o[d+1]]);var u=[t.lng,t.lat];if("web-mercator"===i.config.projection?r=function(t,e){for(var i,o,r,s,a,d,u,h,l=[Infinity,Infinity],c=Infinity,p=0,g=n(e);!(i=g()).done;){var f=i.value,y=f[0],v=f[1],m=void 0,C=Infinity,P=R(y[0],y[1]),I=R(v[0],v[1]),S=R(t[0],t[1]);if(y[0]===t[0]&&y[1]===t[1])m=y;else if(v[0]===t[0]&&v[1]===t[1])m=v;else{var F=(u=(d={x:(s=S).x-(o=P).x,y:s.y-o.y}).x*(a={x:(r=I).x-o.x,y:r.y-o.y}).x+d.y*a.y,h=Math.max(0,Math.min(1,u/(a.x*a.x+a.y*a.y))),{x:o.x+h*a.x,y:o.y+h*a.y}),x=U(F.x,F.y);m=[x.lng,x.lat]}m&&(C=at(S,R(m[0],m[1])))<c&&(l=m,c=C,p=e.indexOf(f))}return Infinity===c?void 0:{coordinate:l,lineIndex:p,distance:c}}(u,a):"globe"===i.config.projection&&(r=function(t,e){for(var i,o=[Infinity,Infinity],r=Infinity,s=0,a=n(e);!(i=a()).done;){var d,u=i.value,h=u[0],l=u[1],c=Infinity;(d=h[0]===t[0]&&h[1]===t[1]?h:l[0]===t[0]&&l[1]===t[1]?l:(p=h,g=l,f=t,M=Dt(p),O=Dt(g),E=Dt(f),D=E[0],k=E[1],b=E[2],_=[(C=(y=M)[1])*(F=(v=O)[2])-(P=y[2])*(S=v[1]),P*(I=v[0])-(m=y[0])*F,m*S-C*I],T=_[0],N=_[1],R=_[2],U=N*b-R*k,W=R*D-T*b,L=T*k-N*D,A=L*N-W*R,B=U*R-L*T,z=W*T-U*N,H=1/Math.sqrt(Math.pow(A,2)+Math.pow(B,2)+Math.pow(z,2)),G=[A*H,B*H,z*H],V=[-1*A*H,-1*B*H,-1*z*H],j=Et(M,O),K=Et(M,G),Y=Et(O,G),X=Et(M,V),q=Et(O,V),Et(M,x=K<X&&K<q||Y<X&&Y<q?G:V)>j||Et(O,x)>j?w(kt(x),kt(M))<=w(kt(x),kt(O))?[kt(M),!0,!1]:[kt(O),!1,!0]:[kt(x),!1,!1])[0])&&(c=w(t,d))<r&&(o=d,r=c,s=e.indexOf(u))}var p,g,f,y,v,m,C,P,I,S,F,x,M,O,E,D,k,b,_,T,N,R,U,W,L,A,B,z,H,G,V,j,K,Y,X,q;return Infinity===r?void 0:{coordinate:o,distance:r,lineIndex:s}}(u,a)),r){var h=i.pixelDistance.measure(t,r.coordinate);h<s.minDistance&&h<i.pointerDistance&&(s.featureId=e.id,s.coordinate=[b(r.coordinate[0],i.config.coordinatePrecision),b(r.coordinate[1],i.config.coordinatePrecision)],s.featureCoordinateIndex=r.lineIndex,s.minDistance=h)}}),s},e}(Z);function _t(t){return Array.isArray(t)&&t.length>0&&Array.isArray(t[0])&&Array.isArray(t[0][0])}var Tt=function(t){return _t(t)?t[0].slice(0,-1):t},Nt=function(t){return _t(t)?t[0]:t},Rt=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.mutateFeatureBehavior=void 0,r.readFeatureBehavior=void 0,r._startEndPoints=[],r.config=e,r.pixelDistance=i,r.mutateFeatureBehavior=n,r.readFeatureBehavior=o,r}r(e,t);var n=e.prototype;return n.create=function(t){if(this.ids.length)throw new Error("Opening and closing points already created");var e=_t(t),i=Nt(t);if(e){if(i.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.mutateFeatureBehavior.createGuidancePoints({coordinates:[i[0],i[i.length-2]],type:f.CLOSING_POINT})}else this._startEndPoints=[this.mutateFeatureBehavior.createGuidancePoint({coordinate:i[i.length-2],type:f.CLOSING_POINT})]},n.delete=function(){this.ids.length&&(this.mutateFeatureBehavior.deleteFeaturesIfPresent(this.ids),this._startEndPoints=[])},n.updateOne=function(t,e){this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[t],coordinate:e}])},n.update=function(t){var e=Nt(t);1!==this.ids.length?2===this.ids.length&&this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[0]},{featureId:this.ids[1],coordinate:e[e.length-3]}]):this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[e.length-2]}])},n.isLineStringClosingPoint=function(t){if(1!==this.ids.length)return{isClosing:!1};var e=this.readFeatureBehavior.getGeometry(this.ids[0]);return{isClosing:this.pixelDistance.measure(t,e.coordinates)<this.pointerDistance}},n.isPolygonClosingPoints=function(t){if(2!==this.ids.length)return{isClosing:!1,isPreviousClosing:!1};var e=this.readFeatureBehavior.getGeometry(this.ids[0]),i=this.readFeatureBehavior.getGeometry(this.ids[1]),n=this.pixelDistance.measure(t,e.coordinates),o=this.pixelDistance.measure(t,i.coordinates);return{isClosing:n<this.pointerDistance,isPreviousClosing:o<this.pointerDistance}},i(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}])}(Z),Ut=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).readFeature=void 0,o.mutateFeature=void 0,o.readFeature=i,o.mutateFeature=n,o}r(e,t);var i=e.prototype;return i.createOrUpdate=function(t){var e=this,i=t.featureId,n=t.featureCoordinates;if(this.readFeature.hasFeature(i)){var o=Tt(n),r=this.readFeature.getProperties(i),s=r.coordinatePointIds;if(s)if(s&&s.every(function(t){return e.readFeature.hasFeature(t)})){var a=r.coordinatePointIds,d=a.map(function(t){return e.readFeature.getGeometry(t).coordinates});if(a.length!==o.length){this.deleteCoordinatePoints(a);var u=this.createPoints(o,r.mode,i);this.setFeatureCoordinatePoints(i,u)}else{var h=[];o.forEach(function(t,e){t[0]===d[e][0]&&t[1]===d[e][1]||h.push({featureId:a[e],coordinate:t})}),this.mutateFeature.updateGuidancePoints(h)}}else{var l=s.filter(function(t){return e.readFeature.hasFeature(t)});l.length&&this.deleteCoordinatePoints(l);var c=this.createPoints(o,r.mode,i);this.setFeatureCoordinatePoints(i,c)}else{var p=this.createPoints(o,r.mode,i);this.setFeatureCoordinatePoints(i,p)}}else this.deleteOrphanedPoints(i)},i.deletePointsByFeatureIds=function(t){for(var e,i=n(t);!(e=i()).done;)this.deleteIfPresent(e.value)},i.updateOneAtIndex=function(t,e,i){var n=this.readFeature.getProperties(t).coordinatePointIds;n&&0!==n.length&&void 0!==n[e]&&this.mutateFeature.updateGuidancePoints([{featureId:n[e],coordinate:i}])},i.updateAllInPlace=function(t){var e=t.featureCoordinates,i=this.readFeature.getProperties(t.featureId);if(i.coordinatePointIds){var n=Tt(e);n.length===i.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(i.coordinatePointIds.map(function(t,e){return{featureId:t,coordinate:n[e]}}))}},i.createPoints=function(t,e,i){return this.mutateFeature.createGuidancePoints({coordinates:t,type:f.COORDINATE_POINT,additionalProperties:function(t){var n;return(n={mode:e})[f.COORDINATE_POINT]=!0,n[f.COORDINATE_POINT_FEATURE_ID]=i,n.index=t,n}})},i.setFeatureCoordinatePoints=function(t,e,i){var n;void 0===i&&(i=d.Commit);var o=this.readFeature.getGeometryType(t),r={featureId:t,propertyMutations:(n={},n[f.COORDINATE_POINT_IDS]=e,n),context:{updateType:i}};if("Polygon"===o)this.mutateFeature.updatePolygon(r);else{if("LineString"!==o)throw new Error("Unsupported geometry type for coordinate points");this.mutateFeature.updateLineString(r)}},i.deleteCoordinatePoints=function(t){this.mutateFeature.deleteFeaturesIfPresent(t)},i.deleteIfPresent=function(t){if(this.readFeature.hasFeature(t)){var e=this.readFeature.getProperties(t).coordinatePointIds;e&&(this.deleteCoordinatePoints(e),this.setFeatureCoordinatePoints(t,null))}},i.deleteOrphanedPoints=function(t){var e=this.readFeature.getAllFeatureIdsWhere(function(e){return e[f.COORDINATE_POINT_FEATURE_ID]===t});this.mutateFeature.deleteFeaturesIfPresent(e)},e}(Z),Wt=/*#__PURE__*/function(){function t(t){var e=this;this.undoHistory=[],this.redoHistory=[],this.cloneCoordinatesFunction=void 0,this.maxStackSize=void 0,this.cloneCoordinatesFunction=function(t){return e.cloneRecursively(t)};var i=null==t?void 0:t.maxStackSize;this.maxStackSize=void 0!==i&&Number.isFinite(i)?Math.max(0,Math.floor(i)):Number.POSITIVE_INFINITY}var e=t.prototype;return e.setMaxStackSize=function(t){Number.isFinite(t)?(this.maxStackSize=Math.max(0,Math.floor(t)),this.trimHistoryToMax(this.undoHistory),this.trimHistoryToMax(this.redoHistory)):this.maxStackSize=Number.POSITIVE_INFINITY},e.trimHistoryToMax=function(t){if(Number.isFinite(this.maxStackSize))for(;t.length>this.maxStackSize;)t.shift()},e.pushUndoEntry=function(t){0!==this.maxStackSize&&(this.undoHistory.push(t),this.trimHistoryToMax(this.undoHistory))},e.pushRedoEntry=function(t){0!==this.maxStackSize&&(this.redoHistory.push(t),this.trimHistoryToMax(this.redoHistory))},e.cloneRecursively=function(t){var e=this;return Array.isArray(t)?t.map(function(t){return e.cloneRecursively(t)}):null!==t&&"object"==typeof t?o({},t):t},e.cloneCoordinates=function(t){return this.cloneCoordinatesFunction(t)},e.cloneEntry=function(t){return{featureCoordinates:this.cloneCoordinates(t.featureCoordinates),currentCoordinate:t.currentCoordinate}},e.clear=function(){this.undoHistory=[],this.redoHistory=[]},e.undoSize=function(){return this.undoHistory.length},e.redoSize=function(){return this.redoHistory.length},e.recordSnapshot=function(t){this.pushUndoEntry(this.cloneEntry(t)),this.redoHistory=[]},e.beginUndo=function(){var t=this.undoHistory.pop();if(t){var e=this.cloneEntry(t);this.pushRedoEntry(e);var i=this.undoHistory[this.undoHistory.length-1];return{undoneEntry:e,previousEntry:i?this.cloneEntry(i):void 0}}},e.takeRedo=function(){var t=this.redoHistory.pop();if(t)return this.cloneEntry(t)},e.commitRedo=function(t){this.pushUndoEntry(this.cloneEntry(t))},t}(),Lt={cancel:"Escape",finish:"Enter"},At={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},Bt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="linestring",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Lt,i.snapping=void 0,i.cursors=At,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommittedCoordinates=void 0,i.snappedPointId=void 0,i.lastMouseMoveEvent=void 0,i.showCoordinatePoints=!1,i.finishOnNthCoordinate=void 0,i.editable=!1,i.editedFeatureId=void 0,i.editedFeatureCoordinateIndex=void 0,i.editedSnapType=void 0,i.editedInsertIndex=void 0,i.editedPointId=void 0,i.coordinateSnapping=void 0,i.insertPoint=void 0,i.lineSnapping=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.mutateFeature=void 0,i.readFeature=void 0,i.closingPoints=void 0,i.coordinatePoints=void 0,i.undoRedo=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i=this;if(t.prototype.updateOptions.call(this,e),void 0!==(null==e?void 0:e.finishOnNthCoordinate)&&Number.isInteger(e.finishOnNthCoordinate)&&e.finishOnNthCoordinate>1&&(this.finishOnNthCoordinate=Math.floor(e.finishOnNthCoordinate)),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null!=e&&e.snapping&&(this.snapping=e.snapping),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.insertCoordinates&&(this.insertCoordinates=e.insertCoordinates),e&&e.editable&&(this.editable=e.editable),void 0!==(null==e?void 0:e.showCoordinatePoints))if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(function(t){return t.mode===i.mode}).forEach(function(t){i.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){var n=this.store.copyAllWhere(function(t){var e;return t.mode===i.mode&&Boolean(null==(e=t[f.COORDINATE_POINT_IDS])?void 0:e.length)});this.coordinatePoints.deletePointsByFeatureIds(n.map(function(t){return t.id}))}},i.shouldFinishOnCommit=function(t){return!!this.finishOnNthCoordinate&&Math.max(0,t.coordinates.length-1)>=this.finishOnNthCoordinate},i.updateSnappedCoordinate=function(t){var e=this.snapCoordinate(t);return e?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:e}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:e,type:f.SNAPPING_POINT}),t.lng=e[0],t.lat=e[1]):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),e},i.close=function(){var t;if(void 0!==this.currentId){var e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Finish,action:u},coordinateMutations:[{type:et,index:-1}],propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t)});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});var i=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted(),this.closingPoints.delete(),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.onFinish(i,{mode:this.mode,action:u})}}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=w(t,e)/(this.insertCoordinates.value+1),n=[];return"globe"===this.projection?n=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(n=this.insertPoint.generateInsertionCoordinates(t,e,i)),n},i.createLine=function(t){var e,i=this.mutateFeature.createLineString({coordinates:[t,t],properties:(e={mode:this.mode},e[f.CURRENTLY_DRAWING]=!0,e)});this.lastCommittedCoordinates=i.geometry.coordinates,this.currentId=i.id,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing(),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})},i.firstUpdateToLine=function(t){if(this.currentId){this.setCursor(this.cursors.close);var e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Commit},coordinateMutations:[{type:Q,index:-1,coordinate:t}]});e&&(this.closingPoints.create(e.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.lastCommittedCoordinates=e.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(e.geometry)&&this.close())}},i.updateToLine=function(t,e){if(this.currentId)if(this.closingPoints.isLineStringClosingPoint(t).isClosing)this.close();else{this.setCursor(this.cursors.close);var i=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Commit},coordinateMutations:[{type:Q,index:-1,coordinate:e}]});i&&(this.closingPoints.update(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates}),this.lastCommittedCoordinates=i.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(i.geometry)&&this.close())}},i.undoSize=function(){return this.undoRedo.undoSize()},i.clearHistory=function(){this.undoRedo.clear()},i.pushHistorySnapshot=function(t,e){var i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})},i.updateSnappedGuidancePointFromLastMouseMove=function(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.syncClosingPoints=function(t){this.currentCoordinate>=2?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()},i.undo=function(){var t;if("drawing"===this.state&&this.currentId){var e=this.undoRedo.beginUndo();if(e){var i=e.previousEntry;if(!i){var n=this.currentId;return this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([n]),this.mutateFeature.deleteFeatureIfPresent(n),void this.updateSnappedGuidancePointFromLastMouseMove()}var o=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:it,coordinates:i.featureCoordinates},propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=!0,t),context:{updateType:d.Commit}});o&&(this.currentCoordinate=i.currentCoordinate,this.lastCommittedCoordinates=o.geometry.coordinates,this.syncClosingPoints(o.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}}},i.redoSize=function(){return this.undoRedo.redoSize()},i.redo=function(){var t=this.undoRedo.takeRedo();if(t){if(this.currentId){var e,i=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:it,coordinates:t.featureCoordinates},propertyMutations:(e={},e[f.CURRENTLY_DRAWING]=!0,e),context:{updateType:d.Commit}});if(!i)return;this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=i.geometry.coordinates,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}else{var n,o=this.mutateFeature.createLineString({coordinates:t.featureCoordinates,properties:(n={mode:this.mode},n[f.CURRENTLY_DRAWING]=!0,n)}),r=o.id,s=o.geometry;this.currentId=r,this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=s.coordinates,"started"===this.state&&this.setDrawing(),this.syncClosingPoints(s.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:r,featureCoordinates:s.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}},i.registerBehaviors=function(t){this.insertPoint=new Mt(t),this.clickBoundingBox=new gt(t),this.pixelDistance=new ft(t),this.lineSnapping=new bt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new yt(t,this.pixelDistance,this.clickBoundingBox),this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate}),this.closingPoints=new Rt(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Ut(t,this.readFeature,this.mutateFeature),this.undoRedo=new Wt({maxStackSize:t.undoRedoMaxStackSize})},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t;var e=this.updateSnappedCoordinate(t)||[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){this.closingPoints.isLineStringClosingPoint(t).isClosing&&this.setCursor(this.cursors.close);var i=[{type:tt,index:-1,coordinate:e}];if(this.insertCoordinates){var n=this.getInsertCoordinates(e);n&&(i={type:it,coordinates:n})}var o=this.mutateFeature.updateLineString({coordinateMutations:i,featureId:this.currentId,context:{updateType:d.Provisional}});o&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates})}},i.getInsertCoordinates=function(t){if(this.lastCommittedCoordinates){var e=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1];if(!dt(e,t)){var i=this.generateInsertCoordinates(e,t),n=this.lastCommittedCoordinates.slice(0,-1);return[].concat(n,i,[t])}}},i.onRightClick=function(t){var e=this;if(this.editable&&"started"===this.state){var i=this.coordinateSnapping.getSnappable(t,function(t){return e.lineStringFilter(t)}),n=i.featureId,o=i.featureCoordinateIndex;if(n&&void 0!==o){var r=this.readFeature.getGeometry(n);if("LineString"===r.type&&!(r.coordinates.length<=2)){var s=this.mutateFeature.updateLineString({featureId:n,coordinateMutations:[{type:et,index:o}],context:{updateType:d.Finish,action:h}});s&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n,featureCoordinates:s.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(n,{mode:this.mode,action:l})}}}},i.onLeftClick=function(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);var e=this.snapCoordinate(t)||[t.lng,t.lat];0===this.currentCoordinate?this.createLine(e):1===this.currentCoordinate&&this.currentId?this.firstUpdateToLine(e):this.currentId&&this.updateToLine(t,e)},i.onClick=function(t){void 0===this.currentId||this.readFeature.hasFeature(this.currentId)||this.cleanUp(),("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,"right"===t.button?this.onRightClick(t):"left"===t.button&&this.onLeftClick(t))},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(t,e){var i=this;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){var n=void 0;if("started"===this.state){var o=this.lineSnapping.getSnappable(t,function(t){return i.lineStringFilter(t)});o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,n=o.coordinate);var r=this.coordinateSnapping.getSnappable(t,function(t){return i.lineStringFilter(t)});r.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:n,type:f.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&void 0!==this.editedFeatureCoordinateIndex){if("coordinate"===this.editedSnapType||"line"===this.editedSnapType&&void 0!==this.editedInsertIndex){var n=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:d.Provisional},coordinateMutations:[{type:tt,index:this.editedFeatureCoordinateIndex,coordinate:[t.lng,t.lat]}]});if(!n)return;this.showCoordinatePoints&&(void 0!==this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:n.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,[t.lng,t.lat]))}else if("line"===this.editedSnapType&&void 0===this.editedInsertIndex){this.editedInsertIndex=this.editedFeatureCoordinateIndex+1;var o=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:d.Provisional}});if(!o)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:o.geometry.coordinates}),this.editedFeatureCoordinateIndex++}this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:[t.lng,t.lat]}]),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:d.Provisional},propertyMutations:(i={},i[f.EDITED]=!0,i)})}},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&(this.setCursor(this.cursors.dragEnd),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,propertyMutations:(i={},i[f.EDITED]=!1,i),context:{updateType:d.Finish,action:h}}))){var n=this.editedFeatureId;e(!0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(n,{mode:this.mode,action:h})}},i.cleanUp=function(){var t=this.currentId,e=this.snappedPointId;this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted(),t&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.delete()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if("Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode)return e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,void 0===e.lineStringOpacity?1:e.lineStringOpacity,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=y,e;if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=t.properties[f.COORDINATE_POINT],n=t.properties[f.CLOSING_POINT]?"closingPoint":t.properties[f.SNAPPING_POINT]?"snappingPoint":i?"coordinatePoint":void 0;if(!n)return e;var r={closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return e.pointWidth=this.getNumericStylingValue(r[n].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(r[n].opacity,1,t),e.pointColor=this.getHexColorStylingValue(r[n].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(r[n].outlineColor,"#ffffff",t),e.pointOutlineWidth=this.getNumericStylingValue(r[n].outlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(r[n].outlineOpacity,1,t),e.zIndex=i?20:50,e}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return wt(t,e.coordinatePrecision)})},i.lineStringFilter=function(t){return Boolean("LineString"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)},i.snapCoordinate=function(t){var e,i,n,o,r,s,a=this;if(null!=(e=this.snapping)&&e.toLine&&(r=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(o=r),null!=(i=this.snapping)&&i.toCoordinate&&(s=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(o=s),null!=(n=this.snapping)&&n.toCustom){var d=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?function(){return a.readFeature.getGeometry(a.currentId)}:function(){return null},project:this.project,unproject:this.unproject});d&&(o=d)}return o},i.afterFeatureUpdated=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.editedFeatureId===t.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.closingPoints.delete(),this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted())},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},e}(x),zt="Feature is not a Point",Ht="Feature has invalid coordinates",Gt="Feature has coordinates with excessive precision";function Vt(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:zt}:H(t.geometry.coordinates)?z(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:Gt}:{valid:!1,reason:Ht}}var jt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).pixelDistance=void 0,o.clickBoundingBox=void 0,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getNearestPointFeature=function(t){for(var e=this.clickBoundingBox.create(t),i=this.store.search(e),n=Infinity,o=void 0,r=0;r<i.length;r++){var s=i[r];if("Point"===s.geometry.type&&s.properties.mode===this.mode){var a=this.pixelDistance.measure(t,s.geometry.coordinates);a>n||a>this.pointerDistance||(n=a,o=s)}}return o},e}(Z),Kt={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},Yt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="point",i.cursors=Kt,i.editable=!1,i.editedFeatureId=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.pointSearch=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null!=e&&e.editable&&(this.editable=e.editable)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.create)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.onMouseMove=function(){},i.onKeyDown=function(){},i.onKeyUp=function(){},i.cleanUp=function(){this.editedFeatureId=void 0},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){if(this.editable){var i=this.pointSearch.getNearestPointFeature(t);this.editedFeatureId=null==i?void 0:i.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:it,coordinates:[t.lng,t.lat]},propertyMutations:(i={},i[f.EDITED]=!0,i),context:{updateType:d.Provisional}})},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:(i={mode:this.mode},i[f.EDITED]=!1,i),context:{updateType:d.Finish,action:"edit"}})){var n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,e(!0),this.onFinish(n,{mode:this.mode,action:u})}},i.registerBehaviors=function(t){this.pixelDistance=new ft(t),this.clickBoundingBox=new gt(t),this.pointSearch=new jt(t,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new nt(t,{validate:this.validate})},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=Boolean(t.id&&this.editedFeatureId===t.id);e.pointWidth=this.getNumericStylingValue(i?this.styles.editedPointWidth:this.styles.pointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(this.styles.pointOpacity,void 0===e.pointOpacity?1:e.pointOpacity,t),e.pointColor=this.getHexColorStylingValue(i?this.styles.editedPointColor:this.styles.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.pointOutlineOpacity,void 0===e.pointOutlineOpacity?1:e.pointOutlineOpacity,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,t),e.zIndex=30}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Vt(t,e.coordinatePrecision)})},i.onLeftClick=function(t){var e=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:{mode:this.mode},context:{updateType:d.Finish,action:u}});e&&this.onFinish(e.id,{mode:this.mode,action:u})},i.onRightClick=function(t){if(this.editable){var e=this.pointSearch.getNearestPointFeature(t);e&&this.mutateFeature.deleteFeatureIfPresent(e.id)}},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))},e}(x),Xt={cancel:"Escape",finish:"Enter"},qt={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},Zt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Xt,i.cursors=qt,i.mouseMove=!1,i.showCoordinatePoints=!1,i.lastMouseMoveEvent=void 0,i.snapping=void 0,i.snappedPointId=void 0,i.editable=!1,i.editedFeatureId=void 0,i.editedFeatureCoordinateIndex=void 0,i.editedSnapType=void 0,i.editedInsertIndex=void 0,i.editedPointId=void 0,i.coordinatePoints=void 0,i.lineSnapping=void 0,i.coordinateSnapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.clickBoundingBox=void 0,i.mutateFeature=void 0,i.readFeature=void 0,i.undoRedo=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i=this;if(t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.snapping&&(this.snapping=e.snapping),void 0!==(null==e?void 0:e.editable)&&(this.editable=e.editable),void 0!==(null==e?void 0:e.pointerEvents)&&(this.pointerEvents=e.pointerEvents),void 0!==(null==e?void 0:e.showCoordinatePoints))if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(function(t){return t.mode===i.mode}).filter(function(t){return"Polygon"===t.geometry.type}).forEach(function(t){i.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){var n=this.store.copyAllWhere(function(t){return t.mode===i.mode&&Boolean(t[f.COORDINATE_POINT_IDS])}).filter(function(t){return"Polygon"===t.geometry.type});this.coordinatePoints.deletePointsByFeatureIds(n.map(function(t){return t.id}))}},i.close=function(){var t;if(void 0!==this.currentId&&!(this.readFeature.getCoordinates(this.currentId).length<5)){var e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:et,index:-2}],propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t[f.COMMITTED_COORDINATE_COUNT]=void 0,t[f.PROVISIONAL_COORDINATE_COUNT]=void 0,t),context:{updateType:d.Finish,action:u}});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),"drawing"===this.state&&this.setStarted(),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.closingPoints.delete();var i=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.onFinish(i,{mode:this.mode,action:u})}}},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate}),this.clickBoundingBox=new gt(t),this.pixelDistance=new ft(t),this.lineSnapping=new bt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new yt(t,this.pixelDistance,this.clickBoundingBox),this.closingPoints=new Rt(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Ut(t,this.readFeature,this.mutateFeature),this.undoRedo=new Wt({maxStackSize:t.undoRedoMaxStackSize})},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.updateSnappedCoordinate=function(t){var e=this.snapCoordinate(t);e?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:e}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:e,type:f.SNAPPING_POINT}),t.lng=e[0],t.lat=e[1]):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.undoSize=function(){return this.undoRedo.undoSize()},i.clearHistory=function(){this.undoRedo.clear()},i.pushHistorySnapshot=function(t,e){var i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})},i.updateSnappedGuidancePointFromLastMouseMove=function(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.syncClosingPoints=function(t){this.currentCoordinate>=3?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()},i.undo=function(){var t;if("drawing"===this.state&&this.currentId){var e=this.undoRedo.beginUndo();if(e){var i=e.previousEntry;if(!i){var n=this.currentId;return this.currentId=void 0,this.currentCoordinate=0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([n]),this.mutateFeature.deleteFeatureIfPresent(n),void this.updateSnappedGuidancePointFromLastMouseMove()}var o=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:it,coordinates:i.featureCoordinates},propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=!0,t[f.COMMITTED_COORDINATE_COUNT]=i.currentCoordinate,t[f.PROVISIONAL_COORDINATE_COUNT]=i.currentCoordinate,t),context:{updateType:d.Commit}});o&&(this.currentCoordinate=i.currentCoordinate,this.syncClosingPoints(o.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}}},i.redoSize=function(){return this.undoRedo.redoSize()},i.redo=function(){var t=this.undoRedo.takeRedo();if(t){if(this.currentId){var e,i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:it,coordinates:t.featureCoordinates},propertyMutations:(e={},e[f.CURRENTLY_DRAWING]=!0,e[f.COMMITTED_COORDINATE_COUNT]=t.currentCoordinate,e[f.PROVISIONAL_COORDINATE_COUNT]=t.currentCoordinate,e),context:{updateType:d.Commit}});if(!i)return;this.currentCoordinate=t.currentCoordinate,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}else{var n,o=this.undoRedo.cloneCoordinates(t.featureCoordinates)[0],r=this.mutateFeature.createPolygon({coordinates:o,properties:(n={mode:this.mode},n[f.CURRENTLY_DRAWING]=!0,n[f.COMMITTED_COORDINATE_COUNT]=t.currentCoordinate,n[f.PROVISIONAL_COORDINATE_COUNT]=t.currentCoordinate,n)}),s=r.id,a=r.geometry;this.currentId=s,this.currentCoordinate=t.currentCoordinate,"started"===this.state&&this.setDrawing(),this.syncClosingPoints(a.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:s,featureCoordinates:a.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}},i.onMouseMove=function(t){var e;if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t,this.updateSnappedCoordinate(t),void 0!==this.currentId&&0!==this.currentCoordinate){var i,n=this.readFeature.getCoordinate(this.currentId,0),o=[t.lng,t.lat];if(1===this.currentCoordinate)i=[{type:tt,index:1,coordinate:o},{type:tt,index:2,coordinate:[t.lng,t.lat]}];else if(2===this.currentCoordinate)i=[{type:tt,index:2,coordinate:o}];else{var r=this.closingPoints.isPolygonClosingPoints(t);r.isPreviousClosing||r.isClosing?(this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.setCursor(this.cursors.close),i=[{type:tt,index:-1,coordinate:n},{type:tt,index:-2,coordinate:n}]):i=[{type:tt,index:-2,coordinate:o},{type:tt,index:-1,coordinate:n}]}var s=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:i,propertyMutations:(e={},e[f.PROVISIONAL_COORDINATE_COUNT]=this.currentCoordinate+1,e),context:{updateType:d.Provisional}});s&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:s.geometry.coordinates})}},i.snapCoordinate=function(t){var e,i,n,o,r,s=this,a=void 0;if(null!=(e=this.snapping)&&e.toLine&&(o=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(a=o),null!=(i=this.snapping)&&i.toCoordinate&&(r=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(a=r),null!=(n=this.snapping)&&n.toCustom){var d=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?function(){return s.readFeature.getGeometry(s.currentId)}:function(){return null},project:this.project,unproject:this.unproject});d&&(a=d)}return a},i.polygonFilter=function(t){return Boolean("Polygon"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)},i.onRightClick=function(t){var e=this;if(this.editable&&"started"===this.state){var i=this.coordinateSnapping.getSnappable(t,function(t){return e.polygonFilter(t)}),n=i.featureId,o=i.featureCoordinateIndex;if(n&&void 0!==o){var r=this.readFeature.getGeometry(n);if("Polygon"===r.type){var s=r.coordinates[0];if(!(s.length<=4)){var a=this.mutateFeature.updatePolygon({featureId:n,coordinateMutations:0===o||o===s.length-1?[{type:et,index:0},{type:et,index:-1},{type:Q,index:-1,coordinate:s[1]}]:[{type:et,index:o}],context:{updateType:d.Finish,action:h}});if(a){if(this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n,featureCoordinates:a.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.snapping)){var u=this.snapCoordinate(t);if(u){var l=this.mutateFeature.createGuidancePoints({type:f.SNAPPING_POINT,coordinates:[u]});this.snappedPointId=l[0]}}this.onFinish(n,{mode:this.mode,action:h})}}}}}},i.onLeftClick=function(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);var e=this.snapCoordinate(t)||[t.lng,t.lat];if(0===this.currentCoordinate){var i,n=this.mutateFeature.createPolygon({coordinates:[e,e,e,e],properties:(i={mode:this.mode},i[f.CURRENTLY_DRAWING]=!0,i[f.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,i[f.PROVISIONAL_COORDINATE_COUNT]=this.currentCoordinate+1,i)}),o=n.id;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:o,featureCoordinates:n.geometry.coordinates}),this.currentId=o,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var r;if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:0}))return;var s=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:tt,index:1,coordinate:e},{type:tt,index:2,coordinate:e}],propertyMutations:(r={},r[f.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,r),context:{updateType:d.Commit}});if(!s)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:s.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(2===this.currentCoordinate&&this.currentId){var a;if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:1}))return;var u=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:tt,index:2,coordinate:e},{type:Q,index:2,coordinate:e}],propertyMutations:(a={},a[f.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,a),context:{updateType:d.Commit}});if(!u)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:u.geometry.coordinates}),2===this.currentCoordinate&&this.closingPoints.create(u.geometry.coordinates),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentId){var h=this.closingPoints.isPolygonClosingPoints(t);if(h.isPreviousClosing||h.isClosing)this.close();else{var l;if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:this.currentCoordinate-1}))return;var c=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:$,index:-1,coordinate:e}],propertyMutations:(l={},l[f.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,l),context:{updateType:d.Commit}});if(!c)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:c.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.closingPoints.ids.length&&this.closingPoints.update(c.geometry.coordinates)}}},i.onClick=function(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(t,e){var i=this;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){var n=void 0;if("started"===this.state){var o=this.lineSnapping.getSnappable(t,function(t){return i.polygonFilter(t)});o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,n=o.coordinate);var r=this.coordinateSnapping.getSnappable(t,function(t){return i.polygonFilter(t)});r.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:n,type:f.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&void 0!==this.editedFeatureCoordinateIndex){var n=this.readFeature.getGeometry(this.editedFeatureId),o=[t.lng,t.lat],r=[];if("coordinate"===this.editedSnapType||"line"===this.editedSnapType&&void 0!==this.editedInsertIndex?r=0===this.editedFeatureCoordinateIndex||this.editedFeatureCoordinateIndex===n.coordinates[0].length-1?[{type:tt,index:0,coordinate:o},{type:tt,index:-1,coordinate:o}]:[{type:tt,index:this.editedFeatureCoordinateIndex,coordinate:o}]:"line"===this.editedSnapType&&void 0===this.editedInsertIndex&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,r=[{type:$,index:this.editedInsertIndex,coordinate:o}],this.editedFeatureCoordinateIndex++),0!==r.length){var s=this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,coordinateMutations:r,propertyMutations:(i={},i[f.EDITED]=!0,i),context:{updateType:d.Provisional}});s&&(this.showCoordinatePoints&&(this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:s.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,s.geometry.coordinates[0][this.editedFeatureCoordinateIndex])),this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:o}]))}}},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&(this.setCursor(this.cursors.dragEnd),this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,propertyMutations:(i={},i[f.EDITED]=!1,i),context:{updateType:d.Finish,action:h}}))){var n=this.editedFeatureId;this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,e(!0),this.onFinish(n,{mode:this.mode,action:h})}},i.cleanUp=function(){var t=this.currentId,e=this.snappedPointId,i=this.editedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,this.currentCoordinate=0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted(),t&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(i),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.ids.length&&this.closingPoints.delete()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(t.properties.mode===this.mode){if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.zIndex=y,e;if("Point"===t.geometry.type){var i=t.properties[f.EDITED],n=t.properties[f.COORDINATE_POINT],r=i?"editedPoint":t.properties[f.CLOSING_POINT]?"closingPoint":t.properties[f.SNAPPING_POINT]?"snappingPoint":n?"coordinatePoint":void 0;if(!r)return e;var s={editedPoint:{width:this.styles.editedPointOutlineWidth,color:this.styles.editedPointColor,opacity:this.styles.editedPointOpacity,outlineColor:this.styles.editedPointOutlineColor,outlineWidth:this.styles.editedPointOutlineWidth,outlineOpacity:this.styles.editedPointOutlineOpacity},closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return e.pointWidth=this.getNumericStylingValue(s[r].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(s[r].opacity,1,t),e.pointColor=this.getHexColorStylingValue(s[r].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(s[r].outlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(s[r].outlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(s[r].outlineWidth,2,t),e.zIndex=i?40:n?20:30,e}}return e},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},i.afterFeatureUpdated=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.editedFeatureId===t.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.closingPoints.delete(),"drawing"===this.state&&this.setStarted())},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return X(t,e.coordinatePrecision)})},e}(x),Jt={cancel:"Escape",finish:"Enter"},$t={start:"crosshair"},Qt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="rectangle",i.startPosition=void 0,i.endPosition=void 0,i.currentRectangleId=void 0,i.keyEvents=Jt,i.cursors=$t,i.drawInteraction="click-move",i.drawType=void 0,i.mutateFeature=void 0,i.readFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction)},i.updateRectangle=function(t,e){var i;if(this.startPosition&&this.currentRectangleId){var n=e===d.Finish;return this.mutateFeature.updatePolygon({featureId:this.currentRectangleId,coordinateMutations:[{type:tt,index:1,coordinate:[t[0],this.startPosition[1]]},{type:tt,index:2,coordinate:t},{type:tt,index:3,coordinate:[this.startPosition[0],t[1]]}],propertyMutations:n?(i={},i[f.CURRENTLY_DRAWING]=void 0,i):{},context:n?{updateType:e,action:u}:{updateType:e}})}},i.close=function(){if(this.currentRectangleId&&this.endPosition&&this.updateRectangle(this.endPosition,d.Finish)){var t=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:u})}},i.beginDrawing=function(t,e){var i;void 0===e&&(e="click"),this.startPosition=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];var n=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(i={mode:this.mode},i[f.CURRENTLY_DRAWING]=!0,i)});this.currentRectangleId=n.id,this.drawType=e,this.setDrawing()},i.moveDrawAllowed=function(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.dragDrawAllowed=function(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.startPosition?(this.endPosition=[t.lng,t.lat],this.close()):this.beginDrawing(t))},i.onMouseMove=function(t){this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,d.Provisional)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(t,e){"drawing"!==this.state&&this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1))},i.onDrag=function(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,d.Provisional))},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.close(),e(!0))},i.cleanUp=function(){var t=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentRectangleId===t.id&&(this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},e}(x),te=/*#__PURE__*/function(t){function e(e){var i;if(!e.modeName)throw new Error("Mode name is required for TerraDrawRenderMode");return(i=t.call(this,e,!0)||this).type=P.Render,i.mode="render",i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e)},i.registerBehaviors=function(t){this.mode=t.mode},i.start=function(){this.setStarted()},i.stop=function(){this.setStopped()},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(t){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,"#3f97e0",t),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,t),pointOpacity:this.getNumericStylingValue(this.styles.pointOpacity,1,t),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,"#ffffff",t),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,t),pointOutlineOpacity:this.getNumericStylingValue(this.styles.pointOutlineOpacity,1,t),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,"#3f97e0",t),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,t),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,"#3f97e0",t),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,t),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,t),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,"#3f97e0",t),lineStringOpacity:this.getNumericStylingValue(this.styles.lineStringOpacity,1,t),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,t)}},i.validateFeature=function(e){var i=t.prototype.validateFeature.call(this,e);if(i.valid){var n=e,o=Vt(n,this.coordinatePrecision).valid||X(n,this.coordinatePrecision).valid||wt(n,this.coordinatePrecision).valid;return o?{valid:!0}:{valid:o,reason:"Feature is not a valid Point, Polygon or LineString feature"}}return i},e}(x);function ee(t,e){var i=t,n=e,o=E(i[1]),r=E(n[1]),s=E(n[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=(k(Math.atan2(s,a))+360)%360;return d>180?-(360-d):d}function ie(t,e,i){var n=e;e<0&&(n=-Math.abs(n));var o=n/O,r=t[0]*Math.PI/180,s=E(t[1]),a=E(i),d=o*Math.cos(a),u=s+d;Math.abs(u)>Math.PI/2&&(u=u>0?Math.PI-u:-Math.PI-u);var h=Math.log(Math.tan(u/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),l=Math.abs(h)>1e-11?d/h:Math.cos(s),c=[(180*(r+o*Math.sin(a)/l)/Math.PI+540)%360-180,180*u/Math.PI];return c[0]+=c[0]-t[0]>180?-360:t[0]-c[0]>180?360:0,c}function ne(t,e,i,n,o){var r=n(t[0],t[1]),s=n(e[0],e[1]),a=o((r.x+s.x)/2,(r.y+s.y)/2),d=a.lat;return[b(a.lng,i),b(d,i)]}function oe(t,e,i){var n=ie(t,1e3*w(t,e)/2,ee(t,e));return[b(n[0],i),b(n[1],i)]}function re(t){for(var e=t.featureCoords,i=t.precision,n=t.unproject,o=t.project,r=t.projection,s=[],a=0;a<e.length-1;a++){var d=void 0;if("web-mercator"===r)d=ne(e[a],e[a+1],i,o,n);else{if("globe"!==r)throw new Error("Invalid projection");d=oe(e[a],e[a+1],i)}s.push(d)}return s}var se=/*#__PURE__*/function(t){function e(e,i,n,o,r,s){var a;return(a=t.call(this,e)||this).config=void 0,a.selectionPointBehavior=void 0,a.coordinatePointBehavior=void 0,a.mutateFeature=void 0,a.readFeature=void 0,a.pixelDistance=void 0,a._midPoints=[],a.config=e,a.selectionPointBehavior=i,a.coordinatePointBehavior=n,a.mutateFeature=o,a.readFeature=r,a.pixelDistance=s,a}r(e,t);var n=e.prototype;return n.getMidpointConfig=function(t){return{featureCoords:t,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}},n.getNearestMidPoint=function(t){var e=this,i=Infinity,n=void 0;return this.ids.forEach(function(o){var r=e.readFeature.getGeometry(o),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<i&&(i=s,n=o)}),n},n.insert=function(t){var e=t.featureId,i=t.midPointId,n=this.readFeature.getGeometry(i),o=this.readFeature.getProperties(i),r=o.midPointFeatureId,s=o.midPointSegment,a=this.readFeature.getGeometry(r),u={featureId:r,coordinateMutations:[{type:Q,index:s,coordinate:n.coordinates}],context:{updateType:d.Commit}},h=null;if("Polygon"===a.type)h=this.mutateFeature.updatePolygon(u);else{if("LineString"!==a.type)throw new Error("Midpoints can only be added to polygons or linestrings");h=this.mutateFeature.updateLineString(u)}if(!h)throw new Error("Failed to insert midpoint coordinate");var l=h.geometry.coordinates;this.readFeature.getProperties(e)[f.COORDINATE_POINT_IDS]&&this.coordinatePointBehavior.createOrUpdate({featureId:e,featureCoordinates:l}),this.mutateFeature.deleteFeaturesIfPresent([].concat(this.selectionPointBehavior.ids,this._midPoints)),this.create({featureCoordinates:l,featureId:r}),this.selectionPointBehavior.create({featureCoordinates:l,featureId:e})},n.create=function(t){var e=this,i=t.featureCoordinates,n=t.featureId;if(!this.readFeature.hasFeature(n))throw new Error("Store does not have feature with this id");var o=Nt(i),r=re(this.getMidpointConfig(o));this._midPoints=this.mutateFeature.createGuidancePoints({additionalProperties:function(t){var i;return(i={mode:e.mode,midPointSegment:t,midPointFeatureId:n})[g.MID_POINT]=!0,i},coordinates:r,type:g.MID_POINT})},n.delete=function(){this._midPoints.length&&(this.mutateFeature.deleteFeaturesIfPresent(this._midPoints),this._midPoints=[])},n.updateAllInPlace=function(t){if(0!==this._midPoints.length){var e=Nt(t.featureCoordinates),i=re(this.getMidpointConfig(e));this.mutateFeature.updateGuidancePoints(this._midPoints.map(function(t,e){return{featureId:t,coordinate:i[e]}}))}},n.updateOneAtIndex=function(t,e){if(t<0&&(t=this._midPoints.length+t),void 0!==this._midPoints[t]){var i=Nt(e),n=re(this.getMidpointConfig(i));this.mutateFeature.updateGuidancePoints([{featureId:this._midPoints[t],coordinate:n[t]}])}},i(e,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}])}(Z),ae=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).mutateFeature=void 0,n._selectionPoints=[],n.mutateFeature=i,n}r(e,t);var n=e.prototype;return n.create=function(t){var e=t.featureId,i=Tt(t.featureCoordinates);this._selectionPoints=this.mutateFeature.createGuidancePoints({coordinates:i,type:g.SELECTION_POINT,additionalProperties:function(t){var i;return(i={})[g.SELECTION_POINT_FEATURE_ID]=e,i.index=t,i}})},n.delete=function(){this.ids.length&&(this.mutateFeature.deleteFeaturesIfPresent(this.ids),this._selectionPoints=[])},n.updateAllInPlace=function(t){if(0!==this._selectionPoints.length){var e=Tt(t.featureCoordinates);e.length===this._selectionPoints.length&&this.mutateFeature.updateGuidancePoints(this._selectionPoints.map(function(t,i){return{featureId:t,coordinate:e[i]}}))}},n.updateOneAtIndex=function(t,e){void 0!==this._selectionPoints[t]&&this.mutateFeature.updateGuidancePoints([{featureId:this._selectionPoints[t],coordinate:e}])},i(e,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}])}(Z);function de(t,e){for(var i,n,o,r=!1,s=0,a=e.length;s<a;s++)for(var d=e[s],u=0,h=d.length,l=h-1;u<h;l=u++)(n=d[u])[1]>(i=t)[1]!=(o=d[l])[1]>i[1]&&i[0]<(o[0]-n[0])*(i[1]-n[1])/(o[1]-n[1])+n[0]&&(r=!r);return r}var ue=function(t,e,i){var n=function(t){return t*t},o=function(t,e){return n(t.x-e.x)+n(t.y-e.y)};return Math.sqrt(function(t,e,i){var n=o(e,i);if(0===n)return o(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/n;return r=Math.max(0,Math.min(1,r)),o(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},he=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.createClickBoundingBox=void 0,o.pixelDistance=void 0,o.config=e,o.createClickBoundingBox=i,o.pixelDistance=n,o}return r(e,t),e.prototype.find=function(t,e){for(var i=void 0,n=Infinity,o=void 0,r=Infinity,s=void 0,a=this.createClickBoundingBox.create(t),d=this.store.search(a),u=0;u<d.length;u++){var h=d[u],l=h.geometry;if("Point"===l.type){if(h.properties.selectionPoint||h.properties.coordinatePoint||!e&&h.properties[g.MID_POINT])continue;var c=this.pixelDistance.measure(t,l.coordinates);!h.properties[g.MID_POINT]&&c<this.pointerDistance&&c<n&&(n=c,i=h)}else if("LineString"===l.type){if(i)continue;for(var p=0;p<l.coordinates.length-1;p++){var f=l.coordinates[p],y=l.coordinates[p+1],v=ue({x:t.containerX,y:t.containerY},this.project(f[0],f[1]),this.project(y[0],y[1]));v<this.pointerDistance&&v<r&&(r=v,o=h)}}else if("Polygon"===l.type){if(i||o)continue;de([t.lng,t.lat],l.coordinates)&&(s=h)}}return{clickedFeature:i||o||s}},e}(Z),le=/*#__PURE__*/function(t){function e(e,i,n,o,r,s,a){var d;return(d=t.call(this,e)||this).config=void 0,d.featuresAtCursorEvent=void 0,d.selectionPoints=void 0,d.midPoints=void 0,d.coordinatePoints=void 0,d.readFeature=void 0,d.mutateFeature=void 0,d.draggedFeatureId=null,d.dragPosition=void 0,d.config=e,d.featuresAtCursorEvent=i,d.selectionPoints=n,d.midPoints=o,d.coordinatePoints=r,d.readFeature=s,d.mutateFeature=a,d}r(e,t);var i=e.prototype;return i.startDragging=function(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]},i.stopDragging=function(){this.draggedFeatureId=null,this.dragPosition=void 0},i.isDragging=function(){return null!==this.draggedFeatureId},i.canDrag=function(t,e){var i=this.featuresAtCursorEvent.find(t,!0).clickedFeature;return!(!i||i.id!==e)},i.drag=function(t){if(this.draggedFeatureId){var e=this.readFeature.getGeometry(this.draggedFeatureId),i=[t.lng,t.lat];if("Polygon"===e.type||"LineString"===e.type){var n,o;if(o="Polygon"===e.type?(n=e.coordinates[0]).length-1:(n=e.coordinates).length,!this.dragPosition)return!1;for(var r=0;r<o;r++){var s=n[r],a=void 0,u=void 0;if("web-mercator"===this.config.projection){var h=R(this.dragPosition[0],this.dragPosition[1]),l=R(i[0],i[1]),c=R(s[0],s[1]),p={x:h.x-l.x,y:h.y-l.y},g=U(c.x-p.x,c.y-p.y);a=g.lng,u=g.lat}else{var f=[this.dragPosition[0]-i[0],this.dragPosition[1]-i[1]];a=s[0]-f[0],u=s[1]-f[1]}if(a=b(a,this.config.coordinatePrecision),u=b(u,this.config.coordinatePrecision),a>180||a<-180||u>90||u<-90)return!1;n[r]=[a,u]}"Polygon"===e.type&&(n[n.length-1]=[n[0][0],n[0][1]]);var y=this.draggedFeatureId,v=null;if("Polygon"===e.type)v=this.mutateFeature.updatePolygon({featureId:y,coordinateMutations:{type:it,coordinates:[n]},context:{updateType:d.Provisional}});else{if("LineString"!==e.type)return;v=this.mutateFeature.updateLineString({featureId:y,coordinateMutations:{type:it,coordinates:n},context:{updateType:d.Provisional}})}if(!v)return!1;var m=v.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:m}),this.selectionPoints.updateAllInPlace({featureCoordinates:m}),this.coordinatePoints.updateAllInPlace({featureId:y,featureCoordinates:m}),this.dragPosition=[t.lng,t.lat]}else"Point"===e.type&&(this.mutateFeature.updatePoint({featureId:this.draggedFeatureId,coordinateMutations:{type:it,coordinates:i},context:{updateType:d.Provisional}}),this.dragPosition=[t.lng,t.lat])}},e}(Z),ce=/*#__PURE__*/function(t){function e(e,i,n,o,r,s,a,d,u){var h;return(h=t.call(this,e)||this).config=void 0,h.pixelDistance=void 0,h.selectionPoints=void 0,h.midPoints=void 0,h.coordinatePoints=void 0,h.coordinateSnapping=void 0,h.lineSnapping=void 0,h.readFeature=void 0,h.mutateFeature=void 0,h.draggedCoordinate={id:null,index:-1},h.config=e,h.pixelDistance=i,h.selectionPoints=n,h.midPoints=o,h.coordinatePoints=r,h.coordinateSnapping=s,h.lineSnapping=a,h.readFeature=d,h.mutateFeature=u,h}r(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o<i.length;o++){var r=this.pixelDistance.measure(t,i[o]);if(r<this.pointerDistance&&r<n.dist){var s="Polygon"===e.type&&(o===i.length-1||0===o);n.dist=r,n.index=s?0:o,n.isFirstOrLastPolygonCoord=s}}return n},i.getDraggable=function(t,e){var i=this.readFeature.getGeometry(e);return this.getClosestCoordinate(t,i)},i.getDraggableIndex=function(t,e){var i=this.readFeature.getGeometry(e),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.snapCoordinate=function(t,e,i){var n,o,r,s=this,a=[t.lng,t.lat],d=function(t){return Boolean(t.properties&&t.properties.mode===i.properties.mode&&t.id!==s.draggedCoordinate.id)};return null!=e&&e.toLine&&(n=this.lineSnapping.getSnappable(t,d).coordinate)&&(a=n),e.toCoordinate&&(o=this.coordinateSnapping.getSnappable(t,d).coordinate)&&(a=o),null!=e&&e.toCustom&&(r=e.toCustom(t,{currentCoordinate:this.draggedCoordinate.index,currentId:i.id,getCurrentGeometrySnapshot:i.id?function(){return s.readFeature.getGeometry(i.id)}:function(){return null},project:this.project,unproject:this.unproject}))&&(a=r),a},i.drag=function(t,e,i){var n=this.draggedCoordinate.id;if(null===n)return!1;var o=this.draggedCoordinate.index,r=this.readFeature.getGeometry(n),s=this.readFeature.getProperties(n),a="LineString"===r.type?r.coordinates:r.coordinates[0],u="Polygon"===r.type&&(o===a.length-1||0===o),h=this.snapCoordinate(t,i,{type:"Feature",id:n,geometry:r,properties:s});if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if(u){var l=a.length-1;a[0]=h,a[l]=h}else a[o]=h;if("Point"!==r.type&&!e&&A({type:"Feature",geometry:r,properties:{}}))return!1;var c=n,p=null;return"Polygon"===r.type?p=this.mutateFeature.updatePolygon({featureId:c,coordinateMutations:{type:it,coordinates:[a]},context:{updateType:d.Provisional}}):"LineString"===r.type&&(p=this.mutateFeature.updateLineString({featureId:c,coordinateMutations:{type:it,coordinates:a},context:{updateType:d.Provisional}})),!!p&&(this.midPoints.updateOneAtIndex(o>0?o-1:-1,a),this.midPoints.updateOneAtIndex(o,a),this.selectionPoints.updateOneAtIndex(o,h),this.coordinatePoints.updateOneAtIndex(c,o,h),!0)},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},e}(Z);function pe(t){var e=0,i=0,n=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],n++},!0),[e/n,i/n]}var ge=function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,n=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return R(t[0],t[1])}),o=n.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});o.x/=n.length,o.y/=n.length;var r=n.map(function(t){return{x:o.x+(t.x-o.x)*Math.cos(i)-(t.y-o.y)*Math.sin(i),y:o.y+(t.x-o.x)*Math.sin(i)+(t.y-o.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[U(e,i).lng,U(e,i).lat]});return"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r,t};function fe(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=R(t[0],t[1]);return[e.x,e.y]});return"Polygon"===t.geometry.type?function(t){for(var e=0,i=0,n=0,o=t.length,r=0;r<o-1;r++){var s=t[r],a=s[0],d=s[1],u=t[r+1],h=u[0],l=u[1],c=a*l-h*d;e+=c,i+=(a+h)*c,n+=(d+l)*c}return{x:i/=6*(e/=2),y:n/=6*e}}(e):function(t){for(var e=t.length,i=0,n=0,o=0;o<e;o++){var r=t[o];i+=r[0],n+=r[1]}return{x:i/e,y:n/e}}(e)}var ye=/*#__PURE__*/function(t){function e(e,i,n,o,r,s){var a;return(a=t.call(this,e)||this).config=void 0,a.selectionPoints=void 0,a.midPoints=void 0,a.coordinatePoints=void 0,a.readFeature=void 0,a.mutateFeature=void 0,a.lastBearing=void 0,a.selectedGeometry=void 0,a.selectedGeometryCentroid=void 0,a.selectedGeometryWebMercatorCentroid=void 0,a.config=e,a.selectionPoints=i,a.midPoints=n,a.coordinatePoints=o,a.readFeature=r,a.mutateFeature=s,a}r(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.selectedGeometryCentroid=void 0},i.rotate=function(t,e){var i=this;this.selectedGeometry||(this.selectedGeometry=this.readFeature.getGeometry(e));var n=this.selectedGeometry;if("Polygon"===n.type||"LineString"===n.type){var o,r=[t.lng,t.lat],s={type:"Feature",geometry:n,properties:{}};if("web-mercator"===this.config.projection){this.selectedGeometryWebMercatorCentroid||(this.selectedGeometryWebMercatorCentroid=fe(s));var a=R(t.lng,t.lat);if(0===(o=Pt(this.selectedGeometryWebMercatorCentroid,a)))return;if(!this.lastBearing)return void(this.lastBearing=o);ge(s,-(this.lastBearing-o))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(this.selectedGeometryCentroid||(this.selectedGeometryCentroid=pe({type:"Feature",geometry:n,properties:{}})),o=ee(this.selectedGeometryCentroid,r),!this.lastBearing)return void(this.lastBearing=o+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=pe(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=ee(i,t)+e,o=function(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=O,n=e[1]*Math.PI/180,o=t[1]*Math.PI/180,r=o-n,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),d=Math.abs(a)>1e-11?r/a:Math.cos(n);return Math.sqrt(r*r+d*d*s*s)*i}(i,t),r=ie(i,o,n);t[0]=r[0],t[1]=r[1]})}(s,-(this.lastBearing-(o+180)))}var u="Polygon"===n.type?n.coordinates[0]:n.coordinates;u.forEach(function(t){t[0]=b(t[0],i.coordinatePrecision),t[1]=b(t[1],i.coordinatePrecision)});var h={featureId:e,coordinateMutations:{type:it,coordinates:"Polygon"===n.type?[u]:u},context:{updateType:d.Provisional}},l=null;if("Polygon"===s.geometry.type)l=this.mutateFeature.updatePolygon(h);else{if("LineString"!==s.geometry.type)return;l=this.mutateFeature.updateLineString(h)}if(!l)return!1;var c=l.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:c}),this.selectionPoints.updateAllInPlace({featureCoordinates:c}),this.coordinatePoints.updateAllInPlace({featureId:e,featureCoordinates:c}),"web-mercator"===this.projection?this.lastBearing=o:"globe"===this.projection&&(this.lastBearing=o+180)}},e}(Z),ve=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.dragCoordinateResizeBehavior=void 0,n.config=e,n.dragCoordinateResizeBehavior=i,n}r(e,t);var i=e.prototype;return i.scale=function(t,e){if(!this.dragCoordinateResizeBehavior.isDragging()){var i=this.dragCoordinateResizeBehavior.getDraggableIndex(t,e);this.dragCoordinateResizeBehavior.startDragging(e,i)}this.dragCoordinateResizeBehavior.drag(t,"center-fixed")},i.reset=function(){this.dragCoordinateResizeBehavior.stopDragging()},e}(Z);function me(t){var e=t.originX,i=t.originY,n=t.xScale,o=t.yScale;1===n&&1===o||t.coordinates.forEach(function(t){var r=R(t[0],t[1]),s=U(e+(r.x-e)*n,i+(r.y-i)*o),a=s.lat;t[0]=s.lng,t[1]=a})}var Ce=/*#__PURE__*/function(t){function e(e,i,n,o,r,s,a){var d;return(d=t.call(this,e)||this).config=void 0,d.pixelDistance=void 0,d.selectionPoints=void 0,d.midPoints=void 0,d.coordinatePoints=void 0,d.readFeature=void 0,d.mutateFeature=void 0,d.minimumScale=1e-4,d.draggedCoordinate={id:null,index:-1},d.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},d.config=e,d.pixelDistance=i,d.selectionPoints=n,d.midPoints=o,d.coordinatePoints=r,d.readFeature=s,d.mutateFeature=a,d}r(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o<i.length;o++){var r=this.pixelDistance.measure(t,i[o]);if(r<this.pointerDistance&&r<n.dist){var s="Polygon"===e.type&&(o===i.length-1||0===o);n.dist=r,n.index=s?0:o,n.isFirstOrLastPolygonCoord=s}}return n},i.isValidDragWebMercator=function(t,e,i){switch(t){case 0:if(e<=0||i>=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0},i.getSelectedFeatureDataWebMercator=function(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;var t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;var e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}},i.centerWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=fe(e.feature);if(!r)return null;var s=R(o[0],o[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=R(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:d,webMercatorSelected:s,webMercatorOrigin:r}),n},i.centerFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=fe(e.feature);if(!r)return null;var s=R(o[0],o[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=R(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:d,webMercatorSelected:s,webMercatorOrigin:r}),n},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,n=t.webMercatorCursor,o=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-n.x,e.y-n.y))return null;var r=at(e,n)/at(e,i);return r<0&&(r=this.minimumScale),me({coordinates:o,originX:e.x,originY:e.y,xScale:r,yScale:r}),o},i.oppositeFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=R(o[0],o[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,d=s.closestBBoxIndex,u={x:i[a][0],y:i[a][1]},h=R(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:d,updatedCoords:n,webMercatorCursor:h,webMercatorSelected:r,webMercatorOrigin:u}),n},i.oppositeWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=R(o[0],o[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,d=s.closestBBoxIndex,u={x:i[a][0],y:i[a][1]},h=R(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:d,updatedCoords:n,webMercatorCursor:h,webMercatorSelected:r,webMercatorOrigin:u}),n},i.scaleWebMercator=function(t){var e=t.closestBBoxIndex,i=t.webMercatorOrigin,n=t.webMercatorSelected,o=t.webMercatorCursor,r=t.updatedCoords,s=i.x-o.x,a=i.y-o.y;if(!this.isValidDragWebMercator(e,s,a))return null;var d=1;0!==s&&1!==e&&5!==e&&(d=1-(i.x-n.x-s)/s);var u=1;return 0!==a&&3!==e&&7!==e&&(u=1-(i.y-n.y-a)/a),this.validateScale(d,u)?(d<0&&(d=this.minimumScale),u<0&&(u=this.minimumScale),this.performWebMercatorScale(r,i.x,i.y,d,u),r):null},i.getFeature=function(t){if(null===this.draggedCoordinate.id)return null;var e=this.readFeature.getGeometry(t);return"Polygon"!==e.type&&"LineString"!==e.type?null:{id:t,type:"Feature",geometry:e,properties:{}}},i.getNormalisedCoordinates=function(t){return"Polygon"===t.type?t.coordinates[0]:t.coordinates},i.validateScale=function(t,e){var i=!isNaN(t)&&e<Number.MAX_SAFE_INTEGER,n=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&n},i.performWebMercatorScale=function(t,e,i,n,o){t.forEach(function(t){var r=R(t[0],t[1]),s=U(e+(r.x-e)*n,i+(r.y-i)*o),a=s.lat;t[0]=s.lng,t[1]=a})},i.getBBoxWebMercator=function(t){var e=[Infinity,Infinity,-Infinity,-Infinity];(t=t.map(function(t){var e=R(t[0],t[1]);return[e.x,e.y]})).forEach(function(t){var i=t[0],n=t[1];i<e[0]&&(e[0]=i),n<e[1]&&(e[1]=n),i>e[2]&&(e[2]=i),n>e[3]&&(e[3]=n)});var i=e[0],n=e[1],o=e[2],r=e[3];return[[i,r],[(i+o)/2,r],[o,r],[o,r+(n-r)/2],[o,n],[(i+o)/2,n],[i,n],[i,r+(n-r)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,n=Infinity,o=0;o<t.length;o++){var r=at({x:e.x,y:e.y},{x:t[o][0],y:t[o][1]});r<n&&(i=o,n=r)}if(void 0===i)throw new Error("No closest coordinate found");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},i.getDraggableIndex=function(t,e){var i=this.readFeature.getGeometry(e),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.drag=function(t,e){if(!this.draggedCoordinate.id)return!1;var i=this.getFeature(this.draggedCoordinate.id);if(!i)return!1;var n=null;if("center"===e?n=this.centerWebMercatorDrag(t):"opposite"===e?n=this.oppositeWebMercatorDrag(t):"center-fixed"===e?n=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(n=this.oppositeFixedWebMercatorDrag(t)),!n)return!1;for(var o=0;o<n.length;o++){var r=n[o];if(r[0]=b(r[0],this.coordinatePrecision),r[1]=b(r[1],this.coordinatePrecision),!z(r,this.coordinatePrecision))return!1}var s=i.id,a=null;if("Polygon"===i.geometry.type?a=this.mutateFeature.updatePolygon({featureId:s,coordinateMutations:{type:it,coordinates:[n]},context:{updateType:d.Provisional}}):"LineString"===i.geometry.type&&(a=this.mutateFeature.updateLineString({featureId:s,coordinateMutations:{type:it,coordinates:n},context:{updateType:d.Provisional}})),!a)return!1;var u=a.geometry.coordinates;return this.midPoints.updateAllInPlace({featureCoordinates:u}),this.selectionPoints.updateAllInPlace({featureCoordinates:u}),this.coordinatePoints.updateAllInPlace({featureId:s,featureCoordinates:u}),!0},e}(Z),Pe={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]},Ie={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"},Se=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="select",i.allowManualDeselection=!0,i.allowManualSelection=!0,i.dragEventThrottle=5,i.dragEventCount=0,i.selected=[],i.flags={},i.keyEvents=Pe,i.cursors=Ie,i.validations={},i.dragTarget={type:"none"},i.selectionPoints=void 0,i.midPoints=void 0,i.coordinateSnap=void 0,i.featuresAtMouseEvent=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.dragFeature=void 0,i.dragCoordinate=void 0,i.rotateFeature=void 0,i.scaleFeature=void 0,i.dragCoordinateResizeFeature=void 0,i.coordinatePoints=void 0,i.lineSnap=void 0,i.mutateFeature=void 0,i.readFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){if(t.prototype.updateOptions.call(this,e),this.cursors=e&&e.cursors?o({},this.cursors,e.cursors):Ie,null===(null==e?void 0:e.keyEvents)?this.keyEvents={deselect:null,delete:null,rotate:null,scale:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),void 0!==(null==e?void 0:e.dragEventThrottle)&&(this.dragEventThrottle=e.dragEventThrottle),void 0!==(null==e?void 0:e.allowManualDeselection)&&(this.allowManualDeselection=e.allowManualDeselection),void 0!==(null==e?void 0:e.allowManualSelection)&&(this.allowManualSelection=e.allowManualSelection),null!=e&&e.flags)for(var i in this.flags=o({},this.flags,e.flags),this.validations={},this.flags){var n=this.flags[i].feature;n&&n.validation&&(this.validations[i]=n.validation)}},i.selectFeature=function(t){this.select(t,!1)},i.setSelecting=function(){if("started"!==this._state)throw new Error("Mode must be started to move to selecting state");this._state="selecting"},i.registerBehaviors=function(t){var e=this;this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:function(t,i){var n=t.properties.mode;return e.validations&&e.validations[n]?e.validations[n](t,i):{valid:!0}}}),this.pixelDistance=new ft(t),this.clickBoundingBox=new gt(t),this.featuresAtMouseEvent=new he(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new ae(t,this.mutateFeature),this.coordinatePoints=new Ut(t,this.readFeature,this.mutateFeature),this.midPoints=new se(t,this.selectionPoints,this.coordinatePoints,this.mutateFeature,this.readFeature,this.pixelDistance),this.coordinateSnap=new yt(t,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new bt(t,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new ye(t,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragFeature=new le(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragCoordinate=new ce(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap,this.readFeature,this.mutateFeature),this.dragCoordinateResizeFeature=new Ce(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.scaleFeature=new ve(t,this.dragCoordinateResizeFeature)},i.deselectFeature=function(t){this.deselect(t)},i.deselect=function(t){this.selected.includes(t)&&(this.mutateFeature.setDeselected(this.selected),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete(),this.dragTarget={type:"none"})},i.deleteSelected=function(){this.selected.length&&this.mutateFeature.deleteFeaturesIfPresent(this.selected),this.selected=[],this.dragTarget={type:"none"}},i.clearDragTargetAndCursor=function(){this.dragTarget={type:"none"},this.setCursor("unset")},i.getSelectedFlags=function(t){var e=this.readFeature.getProperties(t),i=this.flags[e.mode],n=null==i?void 0:i.feature,o=null==n?void 0:n.coordinates;return{featureFlags:n,coordinatesFlags:o,hasDraggableFlags:n&&(n.draggable||(null==o?void 0:o.draggable)||(null==o?void 0:o.resizable)||"object"==typeof(null==o?void 0:o.midpoints)&&o.midpoints.draggable)}},i.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,n=Infinity;if(this.selectionPoints.ids.forEach(function(o){var r=e.readFeature.getGeometry(o),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<n&&(n=s,i=e.readFeature.getProperties(o))}),i){var o=i.selectionPointFeatureId,r=i.index,s=this.readFeature.getProperties(o),a=this.flags[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var u,h=this.readFeature.getGeometry(o);if("Polygon"===h.type){if((u=h.coordinates[0]).length<=4)return}else{if("LineString"!==h.type)return;if((u=h.coordinates).length<=2)return}"Polygon"!==h.type||0!==r&&r!==u.length-1?u.splice(r,1):(u.shift(),u.pop(),u.push([u[0][0],u[0][1]]));var c=null;if("Polygon"===h.type?c=this.mutateFeature.updatePolygon({featureId:o,coordinateMutations:{type:it,coordinates:[u]},context:{updateType:d.Commit}}):"LineString"===h.type&&(c=this.mutateFeature.updateLineString({featureId:o,coordinateMutations:{type:it,coordinates:u},context:{updateType:d.Commit}})),c){var p=c.geometry.coordinates;this.mutateFeature.deleteFeaturesIfPresent([].concat(this.midPoints.ids,this.selectionPoints.ids)),s.coordinatePointIds&&this.coordinatePoints.createOrUpdate({featureId:o,featureCoordinates:p}),this.selectionPoints.create({featureCoordinates:p,featureId:o}),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:p,featureId:o}),this.onFinish(o,{action:l,mode:this.mode})}}}}},i.select=function(t,e){if(void 0===e&&(e=!0),this.selected[0]!==t){var i=this.readFeature.getProperties(t),n=this.flags[i.mode];if(n&&n.feature){var o=this.selected[0];if(o){if(o===t)return;this.deselect(o)}e&&this.setCursor(this.cursors.pointerOver),this.selected=[t],this.mutateFeature.setSelected(t),this.onSelect(t);var r=this.readFeature.getGeometry(t),s=r.type,a=r.coordinates;"LineString"!==s&&"Polygon"!==s||a&&n&&n.feature.coordinates&&(this.selectionPoints.create({featureCoordinates:a,featureId:t}),n.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:a,featureId:t}))}}},i.onLeftClick=function(t){var e=this.featuresAtMouseEvent.find(t,this.selected.length>0).clickedFeature,i=this.midPoints.getNearestMidPoint(t),n=this.selected[0];if(n){var o,r=this.getSelectedFlags(n).featureFlags;if(null!=r&&null!=(o=r.coordinates)&&o.midpoints&&i){if(r.coordinates.draggable){var s=this.pixelDistance.measure(t,this.readFeature.getGeometry(i).coordinates),a=this.dragCoordinate.getDraggable(t,n).dist;if(void 0!==a&&s>a)return}return this.midPoints.insert({featureId:n,midPointId:i}),void this.onFinish(this.selected[0],{action:c,mode:this.mode})}}if(null!=e&&e.id)this.allowManualSelection&&this.select(e.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect(this.selected[0])},i.start=function(){this.setStarted(),this.setSelecting()},i.stop=function(){this.cleanUp(),this.setStarted(),this.setStopped()},i.onClick=function(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.canScale=function(t){return this.keyEvents.scale&&this.keyEvents.scale.every(function(e){return t.heldKeys.includes(e)})},i.canRotate=function(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(function(e){return t.heldKeys.includes(e)})},i.preventDefaultKeyEvent=function(t){var e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()},i.onKeyDown=function(t){this.preventDefaultKeyEvent(t)},i.onKeyUp=function(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;var e=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([e]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()},i.cleanUp=function(){this.selected.length&&this.deselect(this.selected[0])},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){var i=this.selected[0];if(i){var n=this.getSelectedFlags(i),o=n.featureFlags,r=n.coordinatesFlags;if(n.hasDraggableFlags){this.dragEventCount=0;var s="none"!==this.dragTarget.type&&this.dragTarget.featureId===i?this.dragTarget:{type:"none"},a="coordinate"===s.type?s.coordinateIndex:this.dragCoordinate.getDraggableIndex(t,i),d="resize"===s.type?s.coordinateIndex:this.dragCoordinateResizeFeature.getDraggableIndex(t,i),u=(null==r?void 0:r.resizable)&&-1!==d,h=(null==r?void 0:r.draggable)&&-1!==a,l=r&&"object"==typeof r.midpoints&&r.midpoints.draggable,p=(null==o?void 0:o.draggable)&&("feature"===s.type||this.dragFeature.canDrag(t,i));if(u)return this.setCursor(this.cursors.dragStart),this.dragCoordinateResizeFeature.startDragging(i,d),void e(!1);if(h)return this.setCursor(this.cursors.dragStart),this.dragCoordinate.startDragging(i,a),void e(!1);if(l){var g="midpoint"===s.type?s.midPointId:this.midPoints.getNearestMidPoint(t);if(this.selected.length&&g){this.midPoints.insert({featureId:i,midPointId:g}),this.onFinish(this.selected[0],{action:c,mode:this.mode});var f=this.dragCoordinate.getDraggableIndex(t,i);return this.dragCoordinate.startDragging(i,f),void e(!1)}}if(p)return this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,i),void e(!1);this.setCursor("unset")}}}},i.onDrag=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDrag,t)){var i=this.selected[0];if(i){var n=this.readFeature.getProperties(i),o=this.flags[n.mode],r=!0===(o&&o.feature&&o.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){if(o&&o.feature&&o.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i);if(o&&o.feature&&o.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i);if(this.dragCoordinateResizeFeature.isDragging()&&o.feature&&o.feature.coordinates&&o.feature.coordinates.resizable){if("globe"===this.projection)throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,o.feature.coordinates.resizable)}if(this.dragCoordinate.isDragging()){var s,a=null==(s=o.feature)||null==(s=s.coordinates)?void 0:s.snappable,d={toCoordinate:!1};return!0===a?d={toCoordinate:!0}:"object"==typeof a&&(d=a),void this.dragCoordinate.drag(t,r,d)}this.dragFeature.isDragging()?this.dragFeature.drag(t):e(!0)}}}},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&(this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0))},i.onMouseMove=function(t){var e=this.selected[0];if(e){if(!(this.dragFeature.isDragging()||this.dragCoordinate.isDragging()||this.dragCoordinateResizeFeature.isDragging())){var i=this.getSelectedFlags(e).featureFlags;if(i){var n=void 0,o=i.coordinates;if(null!=o&&o.midpoints&&(n=this.midPoints.getNearestMidPoint(t))&&(this.dragTarget={type:"midpoint",featureId:e,midPointId:n},this.setCursor(this.cursors.insertMidpoint)),o&&o.draggable){var r=this.dragCoordinate.getDraggable(t,e),s=r.index,a=r.dist;if(s>-1){if(n&&this.pixelDistance.measure(t,this.readFeature.getGeometry(n).coordinates)<a)return;return this.dragTarget={type:"coordinate",featureId:e,coordinateIndex:s},void this.setCursor(this.cursors.pointerOver)}}if(o&&o.resizable){var d=this.dragCoordinateResizeFeature.getDraggableIndex(t,e);if(d>-1)return this.dragTarget={type:"resize",featureId:e,coordinateIndex:d},void this.setCursor(this.cursors.pointerOver)}if(i.draggable&&this.dragFeature.canDrag(t,e)){if(n)return;return this.dragTarget={type:"feature",featureId:e},void this.setCursor(this.cursors.pointerOver)}n||this.clearDragTargetAndCursor()}else this.clearDragTargetAndCursor()}}else this.clearDragTargetAndCursor()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(t.properties.mode===this.mode&&"Point"===t.geometry.type){if(t.properties[g.SELECTION_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.selectionPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,e.pointWidth,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectionPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,t),e.zIndex=30,e;if(t.properties[g.MID_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.midPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.midPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,t),e.zIndex=50,e}else if(t.properties[g.SELECTED]){if("Point"===t.geometry.type&&t.properties[f.MARKER])return e.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,p,t),e.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,t),e.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,t),e;if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,e.polygonFillColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPolygonOutlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.zIndex=y,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.selectedPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=y,e}return e},i.afterFeatureUpdated=function(t){if(this.selected.length&&t.id===this.selected[0]){var e,i,n=this.flags[t.properties.mode];if(null==n||null==(e=n.feature)||!e.coordinates)return;var o=t.geometry.type,r=t.id;if(this.selectionPoints.delete(),this.midPoints.delete(),"LineString"!==o&&"Polygon"!==o)return;var s=t.geometry.coordinates;this.selectionPoints.create({featureCoordinates:s,featureId:r}),null!=n&&null!=(i=n.feature)&&null!=(i=i.coordinates)&&i.midpoints&&this.midPoints.create({featureCoordinates:s,featureId:r})}},e}(M),Fe=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).type=P.Static,e.mode="static",e}r(e,t);var i=e.prototype;return i.start=function(){},i.stop=function(){},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(){return o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0})},e}(x);function xe(t,e,i,n,o){for(;n>i;){if(n-i>600){var r=n-i+1,s=e-i+1,a=Math.log(r),d=.5*Math.exp(2*a/3),u=.5*Math.sqrt(a*d*(r-d)/r)*(s-r/2<0?-1:1);xe(t,e,Math.max(i,Math.floor(e-s*d/r+u)),Math.min(n,Math.floor(e+(r-s)*d/r+u)),o)}var h=t[e],l=i,c=n;for(Me(t,i,e),o(t[n],h)>0&&Me(t,i,n);l<c;){for(Me(t,l,c),l++,c--;o(t[l],h)<0;)l++;for(;o(t[c],h)>0;)c--}0===o(t[i],h)?Me(t,i,c):Me(t,++c,n),c<=e&&(i=c+1),e<=c&&(n=c-1)}}function Me(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function we(t,e){Oe(t,0,t.children.length,e,t)}function Oe(t,e,i,n,o){o||(o=Re([])),o.minX=Infinity,o.minY=Infinity,o.maxX=-Infinity,o.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];Ee(o,t.leaf?n(s):s)}return o}function Ee(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 De(t,e){return t.minX-e.minX}function ke(t,e){return t.minY-e.minY}function be(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function _e(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Te(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Ne(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Re(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function Ue(t,e,i,n,o){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=n)){var s=e+Math.ceil((i-e)/n/2)*n;xe(t,s,e,i,o),r.push(e,s,s,i)}}var We=/*#__PURE__*/function(){function t(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}var e=t.prototype;return e.search=function(t){var e=this.data,i=[];if(!Ne(t,e))return i;for(var n=this.toBBox,o=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?n(s):s;Ne(t,a)&&(e.leaf?i.push(s):Te(t,a)?this._all(s,i):o.push(s))}e=o.pop()}return i},e.collides=function(t){var e=this.data;if(Ne(t,e))for(var i=[];e;){for(var n=0;n<e.children.length;n++){var o=e.children[n],r=e.leaf?this.toBBox(o):o;if(Ne(t,r)){if(e.leaf||Te(t,r))return!0;i.push(o)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var n=this.data;this.data=i,i=n}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=Re([])},e.remove=function(t){for(var e,i,n=this.data,o=this.toBBox(t),r=[],s=[],a=!1;n||r.length;){if(n||(n=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),n.leaf){var d=n.children.indexOf(t);-1!==d&&(n.children.splice(d,1),r.push(n),this._condense(r))}a||n.leaf||!Te(n,o)?i?(e++,n=i.children[e],a=!1):n=null:(r.push(n),s.push(e),e=0,i=n,n=n.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,n){var o,r=i-e+1,s=this._maxEntries;if(r<=s)return we(o=Re(t.slice(e,i+1)),this.toBBox),o;n||(n=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,n-1))),(o=Re([])).leaf=!1,o.height=n;var a=Math.ceil(r/s),d=a*Math.ceil(Math.sqrt(s));Ue(t,e,i,d,this.compareMinX);for(var u=e;u<=i;u+=d){var h=Math.min(u+d-1,i);Ue(t,u,h,a,this.compareMinY);for(var l=u;l<=h;l+=a){var c=Math.min(l+a-1,h);o.children.push(this._build(t,l,c,n-1))}}return we(o,this.toBBox),o},e._chooseSubtree=function(t,e,i,n){for(;n.push(e),!e.leaf&&n.length-1!==i;){for(var o=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var d=e.children[a],u=be(d),h=(l=t,c=d,(Math.max(c.maxX,l.maxX)-Math.min(c.minX,l.minX))*(Math.max(c.maxY,l.maxY)-Math.min(c.minY,l.minY))-u);h<r?(r=h,o=u<o?u:o,s=d):h===r&&u<o&&(o=u,s=d)}e=s||e.children[0]}var l,c;return e},e._insert=function(t,e,i){var n=i?t:this.toBBox(t),o=[],r=this._chooseSubtree(n,this.data,e,o);for(r.children.push(t),Ee(r,n);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)},e._split=function(t,e){var i=t[e],n=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,n);var r=this._chooseSplitIndex(i,o,n),s=Re(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,we(i,this.toBBox),we(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=Re([t,e]),this.data.height=t.height+1,this.data.leaf=!1,we(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var n,o,r,s,a,d,u,h=Infinity,l=Infinity,c=e;c<=i-e;c++){var p=Oe(t,0,c,this.toBBox),g=Oe(t,c,i,this.toBBox),f=(o=p,r=g,s=Math.max(o.minX,r.minX),a=Math.max(o.minY,r.minY),d=Math.min(o.maxX,r.maxX),u=Math.min(o.maxY,r.maxY),Math.max(0,d-s)*Math.max(0,u-a)),y=be(p)+be(g);f<h?(h=f,n=c,l=y<l?y:l):f===h&&y<l&&(l=y,n=c)}return n||i-e},e._chooseSplitAxis=function(t,e,i){var n=t.leaf?this.compareMinX:De,o=t.leaf?this.compareMinY:ke;this._allDistMargin(t,e,i,n)<this._allDistMargin(t,e,i,o)&&t.children.sort(n)},e._allDistMargin=function(t,e,i,n){t.children.sort(n);for(var o=this.toBBox,r=Oe(t,0,e,o),s=Oe(t,i-e,i,o),a=_e(r)+_e(s),d=e;d<i-e;d++){var u=t.children[d];Ee(r,t.leaf?o(u):u),a+=_e(r)}for(var h=i-e-1;h>=e;h--){var l=t.children[h];Ee(s,t.leaf?o(l):l),a+=_e(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var n=i;n>=0;n--)Ee(e[n],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():we(t[i],this.toBBox)},t}(),Le=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new We(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}var e=t.prototype;return e.setMaps=function(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)},e.toBBox=function(t){var e,i=[],n=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var o=0;o<e.length;o++)n.push(e[o][1]),i.push(e[o][0]);var r=Math.min.apply(Math,n),s=Math.max.apply(Math,n);return{minX:Math.min.apply(Math,i),minY:r,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],n=new Set;t.forEach(function(t){var o=e.toBBox(t);if(e.setMaps(t,o),n.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);n.add(String(t.id)),i.push(o)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),Ae={getId:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},isValidId:function(t){return"string"==typeof t&&36===t.length}},Be={target:"geometry"},ze={target:"properties"},He=/*#__PURE__*/function(){function t(t){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=function(){},this.store={},this.spatialIndex=new Le,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:Ae}var e=t.prototype;return e.clone=function(t){return JSON.parse(JSON.stringify(t))},e.getId=function(){return this.idStrategy.getId()},e.has=function(t){return Boolean(this.store[t])},e.load=function(t,e,i,n){var o=this;if(0===t.length)return[];var r=this.clone(t),s=[],a=[];r=r.filter(function(t){null==t.id&&(t.id=o.idStrategy.getId());var i=t.id;if(e){var n=e(t);if(!n.valid)return s.push({id:i,valid:!1,reason:n.reason}),!1}if(o.tracked){if(t.properties.createdAt){if(!C(t.properties.createdAt))return s.push({id:t.id,valid:!1,reason:"createdAt is not a valid numeric timestamp"}),!1}else t.properties.createdAt=+new Date;if(t.properties.updatedAt){if(!C(t.properties.updatedAt))return s.push({id:t.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else t.properties.updatedAt=+new Date}return o.has(i)?(s.push({id:i,valid:!1,reason:"Feature already exists with this id: "+i}),!1):(o.store[i]=t,a.push(t),s.push({id:i,valid:!0}),!0)}),this.spatialIndex.load(r);var d=a.map(function(t){return t.id});return d.length>0&&(this._onChange(d,"create",n),i&&a.forEach(function(t){i(t)})),s},e.search=function(t,e){var i=this,n=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?n.filter(e):n)},e.registerOnChange=function(t){this._onChange=function(e,i,n){t(e,i,n)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t,e){var i=this,n=new Set;t.forEach(function(t){var e=t.id,o=t.property,r=t.value,s=i.store[e];if(!s)throw new Error("No feature with this ("+e+"), can not update geometry");s.properties[o]!==r&&(n.add(e),void 0===r?delete s.properties[o]:s.properties[o]=r,i.tracked&&(s.properties.updatedAt=+new Date))}),this._onChange&&n.size>0&&this._onChange(Array.from(n),"update",e?o({},e,ze):ze)},e.updateGeometry=function(t,e){var i=this,n=new Set;t.forEach(function(t){var e=t.id,o=t.geometry;n.add(e);var r=i.store[e];if(!r)throw new Error("No feature with this ("+e+"), can not update geometry");r.geometry=i.clone(o),i.spatialIndex.update(r),i.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&n.size>0&&this._onChange(Array.from(n),"update",e?o({},e,Be):Be)},e.create=function(t,e){var i=this,n=[];return t.forEach(function(t){var e,r=t.geometry,s=t.properties,a=o({},s);i.tracked&&(e=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:e,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:e):a={createdAt:e,updatedAt:e});var d=i.getId(),u={id:d,type:"Feature",geometry:r,properties:a};i.store[d]=u,i.spatialIndex.insert(u),n.push(d)}),this._onChange&&this._onChange([].concat(n),"create",e),n},e.delete=function(t,e){var i=this;t.forEach(function(t){if(!i.store[t])throw new Error("No feature with id "+t+", can not delete");delete i.store[t],i.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete",e)},e.copy=function(t){return this.clone(this.store[t])},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},e.copyAllWhere=function(t){var e=this;return this.clone(Object.keys(this.store).map(function(t){return e.store[t]}).filter(function(e){return e.properties&&t(e.properties)}))},e.clear=function(t){var e=Object.keys(this.store);this.store={},this.spatialIndex.clear(),this._onChange(e,"delete",t)},e.size=function(){return Object.keys(this.store).length},t}();function Ge(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(Ke(e[0]));for(var n=1;n<e.length;n++)i-=Math.abs(Ke(e[n]))}return i}var Ve=20294876564838.72,je=Math.PI/180;function Ke(t){var e=t.length;if(e<=2)return 0;for(var i=0,n=0;n<e;)i+=(t[n+2>=e?(n+2)%e:n+2][0]*je-t[n][0]*je)*Math.sin(t[n+1===e?0:n+1][1]*je),n++;return i*Ve}var Ye="Feature is smaller than the minimum area",Xe="Feature is not a Polygon or LineString",qe="Feature intersects itself";function Ze(t,e,i){var n=Pt(t,e),o=Pt(e,i)-n;return o<0&&(o+=360),180-Math.abs(o-90-90)}var Je={cancel:"Escape",finish:"Enter"},$e={start:"crosshair",close:"pointer"},Qe=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="angled-rectangle",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Je,i.cursors=$e,i.mouseMove=!1,i.mutateFeature=void 0,i.readFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents))},i.close=function(){var t;if(void 0!==this.currentId&&this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),context:{updateType:d.Finish,action:u}})){var e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:u})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e=[];if(1===this.currentCoordinate)e=this.getUpdateForSecondCoordinate(t);else{if(2!==this.currentCoordinate)return;e=this.getNewSecondAndThirdCoordinates(t)}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:e,context:{updateType:d.Provisional}})}},i.getUpdateForSecondCoordinate=function(t){return[{type:tt,index:1,coordinate:[t.lng,t.lat]},{type:tt,index:2,coordinate:[t.lng,t.lat]}]},i.getNewSecondAndThirdCoordinates=function(t){if(!this.currentId)throw new Error("No current feature being drawn");var e,i,n,o,r=this.readFeature.getCoordinate(this.currentId,0),s=this.readFeature.getCoordinate(this.currentId,1),a=ne(r,s,this.coordinatePrecision,this.project,this.unproject),d=R(r[0],r[1]),u=R(a[0],a[1]),h=R(s[0],s[1]),l=R(t.lng,t.lat),c=at(l,d)<at(l,h),p=Ze(d,u,l),g=c?90-p:Ze(d,u,l)-90,f=at(u,l),y=Math.cos(E(g))*f,v=Pt(d,h)+("right"==((o=((n=l).x-(i=h).x)*((e=d).y-i.y)-(n.y-i.y)*(e.x-i.x))>1e-10?"left":o<-1e-10?"right":"left")?-90:90),m=mt(d,y,v),C=mt(h,y,v),P=U(m.x,m.y),I=U(C.x,C.y);return[{type:tt,index:2,coordinate:[b(I.lng,this.coordinatePrecision),b(I.lat,this.coordinatePrecision)]},{type:tt,index:3,coordinate:[b(P.lng,this.coordinatePrecision),b(P.lat,this.coordinatePrecision)]}]},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e,i=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(e={mode:this.mode},e[f.CURRENTLY_DRAWING]=!0,e)});this.currentId=i.id,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var n=this.readFeature.getCoordinate(this.currentId,0);if(dt([t.lng,t.lat],n))return;if(!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:tt,index:1,coordinate:[t.lng,t.lat]},{type:Q,index:1,coordinate:[t.lng,t.lat]}],context:{updateType:d.Commit}}))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){if(t.key===this.keyEvents.cancel)this.cleanUp();else if(t.key===this.keyEvents.finish){if(this.currentCoordinate<2)return void this.cleanUp();this.close()}},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},e}(x);function ti(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var ei={cancel:"Escape",finish:"Enter"},ii={start:"crosshair",close:"pointer"},ni=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sector",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=ei,i.direction=void 0,i.arcPoints=64,i.cursors=ii,i.mouseMove=!1,i.readFeature=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.arcPoints&&(this.arcPoints=e.arcPoints)},i.close=function(){var t;if(void 0!==this.currentId&&this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:it},context:{updateType:d.Finish,action:u}})){var e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:u})}},i.getSectorCoordinates=function(t){var e=this.readFeature.getCoordinates(this.currentId),i=e[0],n=e[1],o=[t.lng,t.lat],r=R(i[0],i[1]),s=R(n[0],n[1]),a=R(o[0],o[1]);if(void 0===this.direction){var d=ti(r,s,a);this.direction=d?"clockwise":"anticlockwise"}var u,h=at(r,s),l=Pt(r,s),c=Pt(r,a),p=this.arcPoints,g=[i],f=It(l),y=It(c);"anticlockwise"===this.direction?(u=y-f)<0&&(u+=360):(u=f-y)<0&&(u+=360);var v=("anticlockwise"===this.direction?1:-1)*u/p;g.push(n);for(var m=0;m<=p;m++){var C=mt(r,h,f+m*v),P=U(C.x,C.y),I=P.lat,S=[b(P.lng,this.coordinatePrecision),b(I,this.coordinatePrecision)];S[0]!==g[g.length-1][0]&&S[1]!==g[g.length-1][1]&&g.push(S)}return g.push(i),g},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e;if(1===this.currentCoordinate)e=[{type:tt,index:1,coordinate:[t.lng,t.lat]},{type:tt,index:2,coordinate:[t.lng,t.lat]}];else{if(2!==this.currentCoordinate)return;var i=this.getSectorCoordinates(t);if(!i)return;e={type:it,coordinates:[i]}}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:e,context:{updateType:d.Provisional}})}},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e,i=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(e={mode:this.mode},e[f.CURRENTLY_DRAWING]=!0,e)});this.currentId=null==i?void 0:i.id,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,index:0,newCoordinate:[t.lng,t.lat]}))return;if(!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:tt,index:1,coordinate:[t.lng,t.lat]},{type:tt,index:2,coordinate:[t.lng,t.lat]}],context:{updateType:d.Provisional}}))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId;this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},e}(x),oi={cancel:"Escape",finish:"Enter"},ri={start:"crosshair",close:"pointer"},si=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sensor",i.currentCoordinate=0,i.currentId=void 0,i.currentInitialArcId=void 0,i.currentStartingPointId=void 0,i.keyEvents=oi,i.direction=void 0,i.arcPoints=64,i.cursors=ri,i.mouseMove=!1,i.readFeature=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.arcPoints&&(this.arcPoints=e.arcPoints)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentInitialArcId&&void 0!==this.currentStartingPointId&&0!==this.currentCoordinate)if(2===this.currentCoordinate){var e=this.getUpdatedLineStringCoordinates(t);if(!e)return;this.mutateFeature.updateLineString({featureId:this.currentInitialArcId,coordinateMutations:{type:it,coordinates:e},context:{updateType:d.Provisional}})}else if(3===this.currentCoordinate){var i=this.getUpdatedPolygonCoordinates(t);if(!i)return;if(this.currentId)this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:it,coordinates:[i]},context:{updateType:d.Provisional}});else{var n,o=this.mutateFeature.createPolygon({coordinates:i,properties:(n={mode:this.mode},n[f.CURRENTLY_DRAWING]=!0,n)});if(!o)return;this.currentId=o.id}}},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:{mode:this.mode}});if(!e)return;this.currentStartingPointId=e.id,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentStartingPointId){var i=this.mutateFeature.createLineString({coordinates:[[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode}});if(!i)return;this.currentInitialArcId=i.id,this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.mutateFeature.deleteFeatureIfPresent(this.currentId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&("Polygon"===t.geometry.type?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y):"LineString"===t.geometry.type?(e.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.zIndex=y):"Point"===t.geometry.type&&(e.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.centerPointOpacity,1,t),e.pointWidth=this.getNumericStylingValue(this.styles.centerPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.centerPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.centerPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.centerPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=20)),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},i.close=function(){if(void 0!==this.currentStartingPointId){var t,e=this.currentStartingPointId,i=this.currentInitialArcId;if(this.currentId&&!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:it},context:{updateType:d.Finish,action:u}}))return;var n=this.currentId;this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(i),this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),n&&this.onFinish(n,{mode:this.mode,action:u})}},i.getUpdatedPolygonCoordinates=function(t){if(!(void 0===this.currentInitialArcId||void 0===this.currentStartingPointId||this.currentCoordinate<3)){var e=this.readFeature.getCoordinates(this.currentInitialArcId);if(!(e.length<2)&&this.direction){var i=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,n=e[0],o=e[e.length-1],r=R(t.lng,t.lat),s=R(n[0],n[1]),a=R(o[0],o[1]),d=R(i[0],i[1]),u=at(d,s),h=at(d,r)<u?s:r,l=Pt(d,r),c=Pt(d,s),p=Pt(d,a),g=It(c),f=It(p),y=It(l);if(!this.notInSector({normalizedCursor:y,normalizedStart:g,normalizedEnd:f,direction:this.direction})){for(var v=this.getDeltaBearing(this.direction,g,f),m=this.arcPoints,C=("anticlockwise"===this.direction?1:-1)*v/m,P=at(d,h),I=[],S=0;S<=m;S++){var F=mt(d,P,g+S*C),x=U(F.x,F.y),M=x.lat,w=[b(x.lng,this.coordinatePrecision),b(M,this.coordinatePrecision)];w[0]!==e[e.length-1][0]&&w[1]!==e[e.length-1][1]&&I.unshift(w)}return e.push.apply(e,I),e.push(e[0]),e}}}},i.getUpdatedLineStringCoordinates=function(t){if(!(void 0===this.currentInitialArcId||void 0===this.currentStartingPointId||this.currentCoordinate<2)){var e=this.readFeature.getGeometry(this.currentInitialArcId).coordinates,i=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,n=e[0],o=[t.lng,t.lat],r=R(n[0],n[1]),s=R(o[0],o[1]),a=R(i[0],i[1]),d=at(a,r);if(void 0===this.direction){var u=ti(a,r,s);this.direction=u?"clockwise":"anticlockwise"}var h,l=Pt(a,r),c=Pt(a,s),p=this.arcPoints,g=[n],f=It(l),y=It(c);"anticlockwise"===this.direction?(h=y-f)<0&&(h+=360):(h=f-y)<0&&(h+=360);for(var v=("anticlockwise"===this.direction?1:-1)*h/p,m=0;m<=p;m++){var C=mt(a,d,f+m*v),P=U(C.x,C.y),I=P.lat,S=[b(P.lng,this.coordinatePrecision),b(I,this.coordinatePrecision)];S[0]!==g[g.length-1][0]&&S[1]!==g[g.length-1][1]&&g.push(S)}return g}},i.getDeltaBearing=function(t,e,i){var n;return"anticlockwise"===t?(n=i-e)<0&&(n+=360):(n=e-i)<0&&(n+=360),n},i.notInSector=function(t){var e=t.normalizedCursor,i=t.normalizedStart,n=t.normalizedEnd;return"clockwise"===t.direction?i<=n?e>=i&&e<=n:e>=i||e<=n:i>=n?e<=i&&e>=n:e<=i||e>=n},e}(x),ai=function(t){var e=this,i=t.name,n=t.callback,o=t.unregister,r=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=i,this.register=function(){e.registered||(e.registered=!0,r(n))},this.unregister=function(){e.register&&(e.registered=!1,o(n))},this.callback=n},di={__proto__:null,GeoJSONStore:He,TerraDrawBaseDrawMode:x,TerraDrawBaseSelectMode:M,TerraDrawBaseAdapter:/*#__PURE__*/function(){function t(t){this._nextKeyUpIsContextMenu=!1,this._lastPointerDownEventTarget=void 0,this._ignoreMismatchedPointerEvents=!1,this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState="not-dragging",this._currentModeCallbacks=void 0,this._ignoreMismatchedPointerEvents="boolean"==typeof t.ignoreMismatchedPointerEvents&&t.ignoreMismatchedPointerEvents,this._minPixelDragDistance="number"==typeof t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9}var e=t.prototype;return e.getButton=function(t){return-1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"},e.getMapElementXYPosition=function(t){var e=this.getMapEventElement(t.type).getBoundingClientRect();return{containerX:t.clientX-e.left,containerY:t.clientY-e.top}},e.getDrawEventFromEvent=function(t,e){void 0===e&&(e=!1);var i=this.getLngLatFromEvent(t);if(!i)return null;var n=i.lng,o=i.lat,r=this.getMapElementXYPosition(t),s=r.containerX,a=r.containerY,d=this.getButton(t),u=Array.from(this._heldKeys);return{lng:b(n,this._coordinatePrecision),lat:b(o,this._coordinatePrecision),containerX:s,containerY:a,button:d,heldKeys:u,isContextMenu:e}},e.register=function(t){this._currentModeCallbacks=t,this._listeners=this.getAdapterListeners(),this._listeners.forEach(function(t){t.register()})},e.getCoordinatePrecision=function(){return this._coordinatePrecision},e.getAdapterListeners=function(){var t=this;return[new ai({name:"pointerdown",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){var i=t.getDrawEventFromEvent(e);i&&(t._dragState="pre-dragging",t._lastDrawEvent=i,t._lastPointerDownEventTarget=e.target?e.target:void 0)}},register:function(e){t.getMapEventElement("pointerdown").addEventListener("pointerdown",e)},unregister:function(e){t.getMapEventElement("pointerdown").removeEventListener("pointerdown",e)}}),new ai({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var i=t.getDrawEventFromEvent(e);if(i)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(i),t._lastDrawEvent=i;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var n={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},o={x:i.containerX,y:i.containerY},r=t._currentModeCallbacks.getState(),s=at(n,o);if("drawing"===r?s<t._minPixelDragDistanceDrawing:"selecting"===r?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;t._nextKeyUpIsContextMenu=!1,t._dragState="dragging",t._currentModeCallbacks.onDragStart(i,function(e){t.setDraggability.bind(t)(e)})}else"dragging"===t._dragState&&t._currentModeCallbacks.onDrag(i,function(e){t.setDraggability.bind(t)(e)})}},register:function(e){t.getMapEventElement("pointermove").addEventListener("pointermove",e)},unregister:function(e){t.getMapEventElement("pointermove").removeEventListener("pointermove",e)}}),new ai({name:"contextmenu",callback:function(e){t._currentModeCallbacks&&(e.preventDefault(),t._nextKeyUpIsContextMenu=!0)},register:function(e){t.getMapEventElement("contextmenu").addEventListener("contextmenu",e)},unregister:function(e){t.getMapEventElement("contextmenu").removeEventListener("contextmenu",e)}}),new ai({name:"pointerup",callback:function(e){if(t._currentModeCallbacks&&e.target===t.getMapEventElement("pointerup")&&(!t._ignoreMismatchedPointerEvents||t._lastPointerDownEventTarget===e.target)&&(t._lastPointerDownEventTarget=void 0,e.isPrimary)){var i=t.getDrawEventFromEvent(e);i&&("dragging"===t._dragState?t._currentModeCallbacks.onDragEnd(i,function(e){t.setDraggability.bind(t)(e)}):"not-dragging"!==t._dragState&&"pre-dragging"!==t._dragState||(t._nextKeyUpIsContextMenu&&(i.isContextMenu=!0,t._nextKeyUpIsContextMenu=!1),t._currentModeCallbacks.onClick(i)),t._dragState="not-dragging",t.setDraggability(!0))}},register:function(e){t.getMapEventElement("pointerup").addEventListener("pointerup",e)},unregister:function(e){t.getMapEventElement("pointerup").removeEventListener("pointerup",e)}}),new ai({name:"keyup",callback:function(e){t._currentModeCallbacks&&(t._heldKeys.delete(e.key),t._currentModeCallbacks.onKeyUp({key:e.key,heldKeys:Array.from(t._heldKeys),preventDefault:function(){return e.preventDefault()}}))},register:function(e){t.getMapEventElement("keyup").addEventListener("keyup",e)},unregister:function(e){t.getMapEventElement("keyup").removeEventListener("keyup",e)}}),new ai({name:"keydown",callback:function(e){t._currentModeCallbacks&&(t._heldKeys.add(e.key),t._currentModeCallbacks.onKeyDown({key:e.key,heldKeys:Array.from(t._heldKeys),preventDefault:function(){return e.preventDefault()}}))},register:function(e){t.getMapEventElement("keydown").addEventListener("keydown",e)},unregister:function(e){t.getMapEventElement("keydown").removeEventListener("keydown",e)}})]},e.unregister=function(){this._listeners.forEach(function(t){t.unregister()}),this.clear(),this._currentModeCallbacks=void 0,this._lastDrawEvent=void 0,this._lastPointerDownEventTarget=void 0,this._nextKeyUpIsContextMenu=!1},t}(),getDefaultStyling:function(){return{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0}},SELECT_PROPERTIES:g},ui={ValidationReasonFeatureNotPoint:zt,ValidationReasonFeatureInvalidCoordinates:Ht,ValidationReasonFeatureInvalidCoordinatePrecision:Gt,ValidationReasonFeatureNotPolygon:I,ValidationReasonFeatureHasHoles:V,ValidationReasonFeatureLessThanFourCoordinates:j,ValidationReasonFeatureHasInvalidCoordinates:K,ValidationReasonFeatureCoordinatesNotClosed:Y,ValidationReasonFeatureNotPolygonOrLineString:Xe,ValidationReasonFeatureSelfIntersects:qe,ValidationReasonFeatureLessThanMinSize:Ye,ValidationReasonModeMismatch:S},hi={cancel:"Escape",finish:"Enter"},li={start:"crosshair",close:"pointer"},ci=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="freehand-linestring",i.canClose=!1,i.currentId=void 0,i.minDistance=20,i.keyEvents=hi,i.cursors=li,i.preventNewFeature=!1,i.mutateFeature=void 0,i.readFeature=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.minDistance&&(this.minDistance=e.minDistance),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors))},i.close=function(){var t;if(void 0!==this.currentId&&this.mutateFeature.updateLineString({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),context:{updateType:d.Finish,action:u}})){var e=this.currentId;this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:u})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(void 0!==this.currentId&&!1!==this.canClose){var e=this.readFeature.getCoordinate(this.currentId,-2),i=this.project(e[0],e[1]),n=at({x:i.x,y:i.y},{x:t.containerX,y:t.containerY}),o=this.readFeature.getCoordinate(this.currentId,-1),r=this.project(o[0],o[1]),s=at({x:r.x,y:r.y},{x:t.containerX,y:t.containerY});if(this.setCursor(s<this.pointerDistance?this.cursors.close:this.cursors.start),!(n<this.minDistance)){var a=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:[{type:Q,index:-1,coordinate:[t.lng,t.lat]}],context:{updateType:d.Provisional}});a&&this.closingPoints.update(a.geometry.coordinates)}}else this.setCursor(this.cursors.start)},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)){if(this.preventNewFeature)return;if(!1===this.canClose){var e,i=this.mutateFeature.createLineString({coordinates:[[t.lng,t.lat],[t.lng,t.lat]],properties:(e={mode:this.mode},e[f.CURRENTLY_DRAWING]=!0,e)}),n=i.id;return this.closingPoints.create(i.geometry.coordinates),this.currentId=n,this.canClose=!0,void("drawing"!==this.state&&this.setDrawing())}this.close()}},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&!0===this.canClose&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId;this.currentId=void 0,this.canClose=!1,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.delete()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode?(e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,void 0===e.lineStringOpacity?1:e.lineStringOpacity,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=y,e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,1,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.zIndex=50,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return wt(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0)},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate}),this.pixelDistance=new ft(t),this.closingPoints=new Rt(t,this.pixelDistance,this.mutateFeature,this.readFeature)},e}(x);function pi(t){if(null===t)return!0;if("boolean"==typeof t)return!0;if("string"==typeof t)return!0;if(void 0===t)return!1;if("number"==typeof t)return Number.isFinite(t);if("bigint"==typeof t)return!1;if("symbol"==typeof t)return!1;if("function"==typeof t)return!1;if(t instanceof RegExp)return!1;if(t instanceof Map)return!1;if(t instanceof Set)return!1;if(t instanceof Date)return!1;if("object"==typeof t&&null!==t&&!Array.isArray(t)){var e=Object.getPrototypeOf(t);if(e!==Object.prototype&&null!==e)return!1}if(ArrayBuffer.isView(t)&&!(t instanceof DataView))return!1;if(Array.isArray(t))for(var i,o=n(t);!(i=o()).done;)if(!pi(i.value))return!1;return"object"==typeof t&&Object.keys(t).every(function(e){return"string"==typeof e&&pi(t[e])})}var gi={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},fi=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="marker",i.cursors=gi,i.editable=!1,i.editedFeatureId=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.pointSearch=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null!=e&&e.editable&&(this.editable=e.editable)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.create)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.onMouseMove=function(){},i.onKeyDown=function(){},i.onKeyUp=function(){},i.cleanUp=function(){this.editedFeatureId=void 0},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){if(this.editable){var i=this.pointSearch.getNearestPointFeature(t);this.editedFeatureId=null==i?void 0:i.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:it,coordinates:[t.lng,t.lat]},propertyMutations:(i={},i[f.EDITED]=!0,i),context:{updateType:d.Provisional}})},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:(i={mode:this.mode},i[f.EDITED]=!1,i),context:{updateType:d.Finish,action:"edit"}})){var n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,e(!0),this.onFinish(n,{mode:this.mode,action:u})}},i.registerBehaviors=function(t){this.pixelDistance=new ft(t),this.clickBoundingBox=new gt(t),this.pointSearch=new jt(t,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new nt(t,{validate:this.validate})},i.styleFeature=function(t){var e,i,n,r=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(r.zIndex=30,r.markerHeight=this.getNumericStylingValue(null==(e=this.styles)?void 0:e.markerHeight,40,t),r.markerWidth=this.getNumericStylingValue(null==(i=this.styles)?void 0:i.markerWidth,32,t),r.markerUrl=this.getUrlStylingValue(null==(n=this.styles)?void 0:n.markerUrl,p,t)),r},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Vt(t,e.coordinatePrecision)})},i.onLeftClick=function(t){var e,i=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:(e={mode:this.mode},e[f.MARKER]=!0,e),context:{updateType:d.Finish,action:u}});i&&this.onFinish(i.id,{mode:this.mode,action:u})},i.onRightClick=function(t){if(this.editable){var e=this.pointSearch.getNearestPointFeature(t);e&&this.mutateFeature.deleteFeatureIfPresent(e.id)}},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))},e}(x),yi=[{key:"z",heldKeys:["meta"]},{key:"z",heldKeys:["control"]}],vi=[{key:"z",heldKeys:["meta","shift"]},{key:"z",heldKeys:["control","shift"]},{key:"y",heldKeys:["control"]}],mi=function(t,e){var i=t.key.toLowerCase(),o=new Set(t.heldKeys.map(function(t){return t.toLowerCase()}).filter(function(t){return t!==i}));if(e.key.toLowerCase()!==i)return!1;var r=new Set(e.heldKeys.map(function(t){return t.toLowerCase()}));if(o.size!==r.size)return!1;for(var s,a=n(r);!(s=a()).done;)if(!o.has(s.value))return!1;return!0},Ci=/*#__PURE__*/function(){function t(t){var e,i;this.undoKeyboardShortcuts=void 0,this.redoKeyboardShortcuts=void 0,this.undoKeyboardShortcuts=null!=(e=null==t?void 0:t.undo)?e:yi,this.redoKeyboardShortcuts=null!=(i=null==t?void 0:t.redo)?i:vi}var e=t.prototype;return e.isUndoKeyboardShortcut=function(t){return this.undoKeyboardShortcuts.some(function(e){return mi(t,e)})},e.isRedoKeyboardShortcut=function(t){return this.redoKeyboardShortcuts.some(function(e){return mi(t,e)})},t}();function Pi(t){return void 0!==t&&Number.isFinite(t)?Math.max(0,Math.floor(t)):Number.POSITIVE_INFINITY}var Ii="undo",Si="redo",Fi="push",xi="mode",Mi="session",wi=/*#__PURE__*/function(){function t(t){this.getModeState=void 0,this.getModeHistorySizes=void 0,this.undoMode=void 0,this.redoMode=void 0,this.clearModeHistory=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.lastHistorySizes={undoSize:0,redoSize:0},this.maxStackSize=Pi(null==t?void 0:t.maxStackSize)}var e=t.prototype;return e.getMaxStackSize=function(){return this.maxStackSize},e.register=function(t){this.getModeState=t.getModeState,this.getModeHistorySizes=t.getModeHistorySizes,this.undoMode=t.undoMode,this.redoMode=t.redoMode,this.clearModeHistory=t.clearModeHistory,this.onHistoryChange=t.onHistoryChange},e.inDrawingState=function(){return!!this.getModeState&&"drawing"===this.getModeState()},e.canUndo=function(){return!!this.inDrawingState()&&this.getHistorySizes().undoSize>0},e.canRedo=function(){return!!this.inDrawingState()&&this.getHistorySizes().redoSize>0},e.undo=function(){return!(!this.canUndo()||!this.undoMode||(this.undoMode(),this.emitHistoryChange(Ii),0))},e.redo=function(){return!(!this.canRedo()||!this.redoMode||(this.redoMode(),this.emitHistoryChange(Si),0))},e.clearHistory=function(){this.clearModeHistory&&this.clearModeHistory(),this.lastHistorySizes={undoSize:0,redoSize:0}},e.getHistorySizes=function(){return this.getModeHistorySizes?this.getModeHistorySizes():{undoSize:0,redoSize:0}},e.undoSize=function(){return this.getHistorySizes().undoSize},e.redoSize=function(){return this.getHistorySizes().redoSize},e.emitPushIfHistoryChangedFromLastSnapshot=function(){if(this.inDrawingState()){var t=this.getHistorySizes();t.undoSize===this.lastHistorySizes.undoSize&&t.redoSize===this.lastHistorySizes.redoSize||this.emitHistoryChange(Fi)}},e.emitPushIfHistoryChanged=function(t){if(this.inDrawingState()){var e=this.getHistorySizes();e.undoSize===t.undoSize&&e.redoSize===t.redoSize||this.emitHistoryChange(Fi)}},e.emitHistoryChange=function(t){if(this.onHistoryChange){var e=this.getHistorySizes(),i=e.undoSize,n=e.redoSize;this.lastHistorySizes={undoSize:i,redoSize:n},this.onHistoryChange({cause:t,stack:xi,undoStackSize:i,redoStackSize:n})}},t}(),Oi=/*#__PURE__*/function(){function t(t){var e=this;this.draw=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.historyById={},this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[],this.emitStackChange=function(t){e.onHistoryChange&&e.onHistoryChange({cause:t,stack:Mi,undoStackSize:e.undoStack.length,redoStackSize:e.redoStack.length})},this.handleChange=function(t,i,o){if(e.draw&&!e.isDrawing()&&0!==e.maxStackSize&&("delete"===i||"create"===i))if("create"!==i){for(var r,s=!1,a=[],d=n(Array.isArray(t)?t:[t]);!(r=d()).done;){var u=r.value,h=String(u);if(e.ignoreProgrammaticDelete[u])delete e.ignoreProgrammaticDelete[u];else if(e.historyById[h]){var l=e.historyById[h].length-1;if(l>=0){var c=e.historyById[h][l];if(!c)continue;a.push({id:u,toIndex:l,snapshot:c}),e.deletedFeatureIds[u]=!0,s=!0}}}if(a.length>1)e.pushUndoStackEntry({id:a[0].id,toIndex:a[0].toIndex,action:"batch-delete",metadata:{entries:a}});else if(1===a.length){var p=a[0];e.pushUndoStackEntry({id:p.id,toIndex:p.toIndex,action:"single"})}s&&(e.redoStack.length=0,e.emitStackChange(Fi))}else{if(void 0===o||!("origin"in o)||"api"!==o.origin)return;for(var g,f=!1,y=[],v=n(Array.isArray(t)?t:[t]);!(g=v()).done;){var m=g.value;if(e.ignoreProgrammaticCreate[m])delete e.ignoreProgrammaticCreate[m],delete e.deletedFeatureIds[m];else{var C=String(m),P=e.draw.getSnapshotFeature(m);P&&(e.deletedFeatureIds[m]&&(e.historyById[C]=[],delete e.deletedFeatureIds[m]),e.historyById[C]||(e.historyById[C]=[]),e.historyById[C].push(P),y.push({id:m,toIndex:e.historyById[C].length-1,snapshot:P}),f=!0)}}if(y.length>1)e.pushUndoStackEntry({id:y[0].id,toIndex:y[0].toIndex,action:"batch-create",metadata:{entries:y}});else if(1===y.length){var I=y[0];e.pushUndoStackEntry({id:I.id,toIndex:I.toIndex,action:"single"})}f&&(e.redoStack.length=0,e.emitStackChange(Fi))}},this.handleFinish=function(t){if(e.draw&&0!==e.maxStackSize)for(var i,o=!1,r=n(Array.isArray(t)?t:[t]);!(i=r()).done;){var s=i.value;if(null!=s){var a=String(s),d=e.draw.getSnapshotFeature(s);d&&(e.historyById[a]||(e.historyById[a]=[]),e.historyById[a].push(d),o||(e.redoStack.length=0,o=!0),e.pushUndoStackEntry({id:s,toIndex:e.historyById[a].length-1,action:"single"}),e.emitStackChange(Fi))}}},this.maxStackSize=Pi(null==t?void 0:t.maxStackSize)}var e=t.prototype;return e.register=function(t){this.draw!==t.draw?(this.draw&&(this.draw.off("change",this.handleChange),this.draw.off("finish",this.handleFinish)),this.draw=t.draw,this.draw.on("change",this.handleChange),this.draw.on("finish",this.handleFinish),this.onHistoryChange=t.onHistoryChange):this.onHistoryChange=t.onHistoryChange},e.pushUndoStackEntry=function(t){0!==this.maxStackSize&&(this.undoStack.push(t),this.undoStack.length>this.maxStackSize&&this.undoStack.shift())},e.pushRedoStackEntry=function(t){0!==this.maxStackSize&&(this.redoStack.push(t),this.redoStack.length>this.maxStackSize&&this.redoStack.shift())},e.isDrawing=function(){return!!this.draw&&"drawing"===this.draw.getModeState()},e.canUndo=function(){return!(!this.draw||this.isDrawing())&&this.undoStack.length>0},e.canRedo=function(){return!(!this.draw||this.isDrawing())&&this.redoStack.length>0},e.undo=function(){var t=this;if(!this.canUndo())return!1;if(!this.draw)return!1;var e=this.undoStack.pop();if(!e)return this.emitStackChange(Ii),!1;if("batch-create"===e.action){var i,n=(null==(i=e.metadata)?void 0:i.entries)||[];if(0===n.length)return this.emitStackChange(Ii),!1;var o=n.map(function(t){return t.id});return o.forEach(function(e){t.ignoreProgrammaticDelete[e]=!0,t.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(o),this.pushRedoStackEntry({id:n[0].id,toIndex:n[0].toIndex,action:"batch-create",metadata:{entries:n}}),this.emitStackChange(Ii),!0}if("batch-delete"===e.action){var r,s=(null==(r=e.metadata)?void 0:r.entries)||[];if(0===s.length)return this.emitStackChange(Ii),!1;var a=s.map(function(t){return t.snapshot}).filter(function(t){return void 0!==t});return a.length>0&&(s.forEach(function(e){t.ignoreProgrammaticCreate[e.id]=!0,delete t.deletedFeatureIds[e.id]}),this.draw.addFeatures(a)),this.pushRedoStackEntry({id:s[0].id,toIndex:s[0].toIndex,action:"batch-delete",metadata:{entries:s}}),this.emitStackChange(Ii),!0}var d=e.id,u=e.toIndex,h=String(d),l=this.historyById[h];if(!l||0===l.length)return this.emitStackChange(Ii),!1;var c=Math.min(u,l.length-1);if(!this.draw.hasFeature(d)){var p=l[c];return p?(this.ignoreProgrammaticCreate[d]=!0,delete this.deletedFeatureIds[d],this.draw.addFeatures([p]),this.pushRedoStackEntry({id:d,toIndex:c,action:"delete",snapshot:p}),this.emitStackChange(Ii),!0):(this.emitStackChange(Ii),!1)}if(c<=0)return this.pushRedoStackEntry({id:d,toIndex:0,action:"create"}),this.ignoreProgrammaticDelete[d]=!0,this.deletedFeatureIds[d]=!0,this.draw.removeFeatures([d]),this.undoStack=this.undoStack.filter(function(t){return t.id!==d}),this.emitStackChange(Ii),!0;var g=l[c],f=l[c-1];return g&&this.pushRedoStackEntry({id:d,toIndex:c,snapshot:g,action:"update"}),this.draw.updateFeatureGeometry(d,f.geometry),l.length=c,this.emitStackChange(Ii),!0},e.redo=function(){var t=this;if(!this.canRedo())return!1;if(!this.draw)return!1;var e=this.redoStack.pop(),i=e.id,n=e.toIndex,o=e.snapshot,r=e.action,s=e.metadata;if("batch-create"===r){var a=(null==s?void 0:s.entries)||[];if(0===a.length)return this.emitStackChange(Si),!1;var d=a.map(function(t){return t.snapshot}).filter(function(t){return void 0!==t});return d.length>0&&(a.forEach(function(e){t.ignoreProgrammaticCreate[e.id]=!0}),this.draw.addFeatures(d)),this.pushUndoStackEntry({id:a[0].id,toIndex:a[0].toIndex,action:"batch-create",metadata:{entries:a}}),this.emitStackChange(Si),!0}if("batch-delete"===r){var u=(null==s?void 0:s.entries)||[];if(0===u.length)return this.emitStackChange(Si),!1;var h=u.map(function(t){return t.id});return h.forEach(function(e){t.ignoreProgrammaticDelete[e]=!0,t.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(h),this.pushUndoStackEntry({id:u[0].id,toIndex:u[0].toIndex,action:"batch-delete",metadata:{entries:u}}),this.emitStackChange(Si),!0}var l=String(i),c=this.historyById[l]||(this.historyById[l]=[]);if("delete"===r)return this.ignoreProgrammaticDelete[i]=!0,this.deletedFeatureIds[i]=!0,this.draw.removeFeatures([i]),this.pushUndoStackEntry({id:i,toIndex:n,action:"single"}),this.emitStackChange(Si),!0;if(n<=0){var p=c[0];return!!p&&(this.ignoreProgrammaticCreate[i]=!0,this.draw.addFeatures([p]),this.pushUndoStackEntry({id:i,toIndex:0,action:"single"}),this.emitStackChange(Si),!0)}var g=o||c[n];return!!g&&(c.length===n?c.push(g):(c[n]=g,c.length=n+1),this.draw.updateFeatureGeometry(i,g.geometry),this.pushUndoStackEntry({id:i,toIndex:n,action:"single"}),this.emitStackChange(Si),!0)},e.clearHistory=function(){this.historyById={},this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[]},e.undoSize=function(){return this.undoStack.length},e.redoSize=function(){return this.redoStack.length},t}(),Ei=/*#__PURE__*/function(){function t(t){var e;this.modeLevel=void 0,this.sessionLevel=void 0,this.shouldPreferMode=void 0,this.onHistoryChange=void 0,this.shouldEmitHistoryChange=void 0,this.modeLevel=t.modeLevel,this.sessionLevel=t.sessionLevel,this.shouldPreferMode=t.shouldPreferMode,this.onHistoryChange=t.onHistoryChange,this.shouldEmitHistoryChange=null!=(e=t.shouldEmitHistoryChange)?e:function(){return!0}}var e=t.prototype;return e.emitStackHistoryChange=function(t){this.shouldEmitHistoryChange()&&this.onHistoryChange&&this.onHistoryChange({cause:t.cause,stack:t.stack,undoSize:t.undoStackSize,redoSize:t.redoStackSize})},e.hasSessionUndo=function(){return Boolean(this.sessionLevel&&this.sessionLevel.canUndo())},e.hasSessionRedo=function(){return Boolean(this.sessionLevel&&this.sessionLevel.canRedo())},e.activeStackForUndo=function(){var t,e;return this.shouldPreferMode()&&null!=(t=this.modeLevel)&&t.canUndo()?xi:this.hasSessionUndo()?Mi:null!=(e=this.modeLevel)&&e.canUndo()?xi:void 0},e.activeStackForRedo=function(){var t,e;return this.shouldPreferMode()&&null!=(t=this.modeLevel)&&t.canRedo()?xi:this.hasSessionRedo()?Mi:null!=(e=this.modeLevel)&&e.canRedo()?xi:void 0},e.canUndo=function(){return void 0!==this.activeStackForUndo()},e.canRedo=function(){return void 0!==this.activeStackForRedo()},e.undo=function(){var t=this.activeStackForUndo();return!!t&&(t===xi?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())},e.redo=function(){var t=this.activeStackForRedo();return!!t&&(t===xi?!!this.modeLevel&&this.modeLevel.redo():!(!this.sessionLevel||!this.sessionLevel.canRedo())&&this.sessionLevel.redo())},e.clearHistory=function(){this.modeLevel&&this.modeLevel.clearHistory(),this.sessionLevel&&this.sessionLevel.clearHistory()},e.emitPushAfterFinish=function(){this.sessionLevel?this.emitStackHistoryChange({cause:Fi,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:Mi}):this.modeLevel&&this.emitStackHistoryChange({cause:Fi,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:xi})},t}();exports.TerraDraw=/*#__PURE__*/function(){function t(t){var e,i,n,r,s=this;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectModes=void 0,this.sessionUndoRedoEnabled=!1,this.keyboardShortcutsMatcher=void 0,this.drawingUndoRedo=void 0,this.sessionUndoRedo=void 0,this.undoRedoCoordinator=void 0,this._adapter=t.adapter,this._instanceSelectModes=[];var a=null==t||null==(e=t.undoRedo)?void 0:e.modeLevel;a&&(this.drawingUndoRedo=a);var d=null==t||null==(i=t.undoRedo)?void 0:i.keyboardShortcuts;d&&(this.keyboardShortcutsMatcher=d),this.sessionUndoRedoEnabled=Boolean(null==t||null==(n=t.undoRedo)?void 0:n.sessionLevel);var u=null==t||null==(r=t.undoRedo)?void 0:r.sessionLevel;this._mode=new Fe;var h=new Set,l=t.modes.reduce(function(t,e){if(h.has(e.mode))throw new Error("There is already a "+e.mode+" mode provided");return h.add(e.mode),t[e.mode]=e,t},{}),c=Object.keys(l);if(0===c.length)throw new Error("No modes provided");c.forEach(function(t){l[t].type===P.Select&&s._instanceSelectModes.push(t)}),this._modes=o({},l,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new He({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var p=function(t){var e=[],i=s._store.copyAll().filter(function(i){return!t.includes(i.id)||(e.push(i),!1)});return{changed:e,unchanged:i}},g=function(t,e){s._enabled&&(s._eventListeners.finish.forEach(function(i){i(t,e)}),s.emitHistoryChangeAfterFinish())},f=function(t,e,i){if(s._enabled){s._eventListeners.change.forEach(function(n){n(t,e,i)}),s.emitDrawingPushIfHistoryChangedFromLastSnapshot();var n=p(t),o=n.changed,r=n.unchanged;"create"===e?s._adapter.render({created:o,deletedIds:[],unchanged:r,updated:[]},s.getModeStyles()):"update"===e?s._adapter.render({created:[],deletedIds:[],unchanged:r,updated:o},s.getModeStyles()):"delete"===e?s._adapter.render({created:[],deletedIds:t,unchanged:r,updated:[]},s.getModeStyles()):"styling"===e&&s._adapter.render({created:[],deletedIds:[],unchanged:r,updated:[]},s.getModeStyles())}},y=function(t){if(s._enabled){s._eventListeners.select.forEach(function(e){e(t)});var e=p([t]);s._adapter.render({created:[],deletedIds:[],unchanged:e.unchanged,updated:e.changed},s.getModeStyles())}},v=function(t){if(s._enabled){s._eventListeners.deselect.forEach(function(e){e(t)});var e=p([t]),i=e.changed;i&&s._adapter.render({created:[],deletedIds:[],unchanged:e.unchanged,updated:i},s.getModeStyles())}};Object.keys(this._modes).forEach(function(t){var e;s._modes[t].register({mode:t,store:s._store,setCursor:s._adapter.setCursor.bind(s._adapter),project:s._adapter.project.bind(s._adapter),unproject:s._adapter.unproject.bind(s._adapter),setDoubleClickToZoom:s._adapter.setDoubleClickToZoom.bind(s._adapter),onChange:f,onSelect:y,onDeselect:v,onFinish:g,coordinatePrecision:s._adapter.getCoordinatePrecision(),undoRedoMaxStackSize:null==(e=s.drawingUndoRedo)||null==e.getMaxStackSize?void 0:e.getMaxStackSize()})}),this.sessionUndoRedoEnabled&&u&&(this.sessionUndoRedo=u,u.register({draw:this,onHistoryChange:function(t){var e;null==(e=s.undoRedoCoordinator)||e.emitStackHistoryChange(t)}})),this.drawingUndoRedo&&this.drawingUndoRedo.register({getModeState:function(){return s.getModeState()},getModeHistorySizes:function(){return s.getDrawingHistorySizes()},undoMode:function(){s._mode.undo&&s._mode.undo()},redoMode:function(){s._mode.redo&&s._mode.redo()},clearModeHistory:function(){var t=s._mode;t.clearHistory&&t.clearHistory()},onHistoryChange:function(t){var e;null==(e=s.undoRedoCoordinator)||e.emitStackHistoryChange(t)}}),this.undoRedoCoordinator=new Ei({modeLevel:this.drawingUndoRedo,sessionLevel:this.sessionUndoRedo,shouldPreferMode:function(){return"drawing"===s.getModeState()},onHistoryChange:function(t){s._eventListeners.history.forEach(function(e){e(t)})},shouldEmitHistoryChange:function(){return s._enabled}})}var e=t.prototype;return e.checkEnabled=function(){if(!this._enabled)throw new Error("Terra Draw is not enabled")},e.handleUndoRedoKeyboardShortcut=function(t){if(!this.drawingUndoRedo&&!this.sessionUndoRedoEnabled)return!1;if(!this.keyboardShortcutsMatcher)return!1;var e=this.keyboardShortcutsMatcher.isUndoKeyboardShortcut(t),i=this.keyboardShortcutsMatcher.isRedoKeyboardShortcut(t);if(e){if(!this.canUndo())return!1;var n=this.undo();return n&&t.preventDefault(),n}if(i){if(!this.canRedo())return!1;var o=this.redo();return o&&t.preventDefault(),o}return!1},e.getDrawingHistorySizes=function(){return{undoSize:this._mode.undoSize&&"function"==typeof this._mode.undoSize?this._mode.undoSize():0,redoSize:this._mode.redoSize&&"function"==typeof this._mode.redoSize?this._mode.redoSize():0}},e.emitDrawingPushIfHistoryChangedFromLastSnapshot=function(){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChangedFromLastSnapshot()},e.emitDrawingPushIfHistoryChanged=function(t){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChanged(t)},e.emitHistoryChangeAfterFinish=function(){var t;null==(t=this.undoRedoCoordinator)||t.emitPushAfterFinish()},e.getModeStyles=function(){var t=this,e={},i=this._instanceSelectModes.includes(this._mode.mode)?this._mode.mode:void 0;return Object.keys(this._modes).forEach(function(n){e[n]=function(e){return i&&e.properties[g.SELECTED]?t._modes[i].styleFeature.bind(t._modes[i])(e):t._modes[n].styleFeature.bind(t._modes[n])(e)}}),e},e.featuresAtLocation=function(t,e){var i=t.lng,o=t.lat,r=e&&void 0!==e.pointerDistance?e.pointerDistance:30,s=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,a=!(!e||void 0===e.ignoreCoordinatePoints)&&e.ignoreCoordinatePoints,d=!(!e||void 0===e.ignoreCurrentlyDrawing)&&e.ignoreCurrentlyDrawing,u=!(!e||void 0===e.ignoreClosingPoints)&&e.ignoreClosingPoints,h=!(!e||void 0===e.ignoreSnappingPoints)&&e.ignoreSnappingPoints,l=this._adapter.unproject.bind(this._adapter),c=this._adapter.project.bind(this._adapter),p=c(i,o),y=pt({unproject:l,point:p,pointerDistance:r});return this._store.search(y).filter(function(t){if(s&&(t.properties[g.MID_POINT]||t.properties[g.SELECTION_POINT]))return!1;if(a&&t.properties[f.COORDINATE_POINT])return!1;if(u&&t.properties[f.CLOSING_POINT])return!1;if(d&&t.properties[f.CURRENTLY_DRAWING])return!1;if(h&&t.properties[f.SNAPPING_POINT])return!1;if("Point"===t.geometry.type){var l=t.geometry.coordinates,y=c(l[0],l[1]);return at(p,y)<r}if("LineString"===t.geometry.type){for(var v=t.geometry.coordinates,m=0;m<v.length-1;m++){var C=v[m],P=v[m+1];if(ue(p,c(C[0],C[1]),c(P[0],P[1]))<r)return!0}return!1}if(de([i,o],t.geometry.coordinates))return!0;if(null!=e&&e.includePolygonsWithinPointerDistance)for(var I,S=n(t.geometry.coordinates);!(I=S()).done;)for(var F=I.value,x=0;x<F.length-1;x++){var M=F[x],w=F[x+1],O=c(M[0],M[1]),E=c(w[0],w[1]);if(ue(p,O,E)<r)return!0}return!1}).map(function(t){if(null==e||!e.addClosestCoordinateInfoToProperties)return t;var n;if("Polygon"===t.geometry.type)n=t.geometry.coordinates[0].slice(0,-1);else{if("LineString"!==t.geometry.type)return t;n=t.geometry.coordinates}for(var r,s=-1,a=Infinity,d=0;d<n.length;d++){var u=n[d],h=at(c(u[0],u[1]),p);h<a&&(s=d,a=h,r=u)}return t.properties.closestCoordinateIndexToEvent=s,t.properties.closestCoordinatePixelDistanceToEvent=a,t.properties.closestCoordinateDistanceKmToEvent=w(r,[i,o]),t})},e.getSelectModeOrThrow=function(t){void 0===t&&(t=void 0);var e=this.getSelectMode({switchToSelectMode:!0,selectMode:t});if(!e)throw new Error("No select mode defined in instance");return e},e.getSelectMode=function(t){var e=t.switchToSelectMode,i=t.selectMode;this.checkEnabled();var n,o=this.getMode();if(0===this._instanceSelectModes.length)return null;if(void 0!==i&&!this._instanceSelectModes.includes(i))throw new Error("No select mode with this name present: "+i);return n=void 0!==i?i:this._instanceSelectModes.includes(o)?o:this._instanceSelectModes[0],e&&o!==n&&this.setMode(n),this._modes[n]},e.isGuidanceFeature=function(t){return Boolean(t.properties[g.MID_POINT]||t.properties[g.SELECTION_POINT]||t.properties[f.COORDINATE_POINT]||t.properties[f.SNAPPING_POINT])},e.setModeStyles=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e},e.updateModeOptions=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].updateOptions(e)},e.getSnapshot=function(){return this._store.copyAll()},e.getSnapshotFeature=function(t){if(this._store.has(t))return this._store.copy(t)},e.clear=function(){this.checkEnabled(),this._adapter.clear()},e.getMode=function(){return this._mode.mode},e.getModeState=function(){return this._mode.state},e.setMode=function(t){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()},e.removeFeatures=function(t){var e=this;this.checkEnabled();var i=[],n=[],o=void 0;t.forEach(function(t){if(!e._store.has(t))throw new Error("No feature with id "+t+", can not delete");var r=e._store.getPropertiesCopy(t);r[g.SELECTED]&&e.deselectFeature(t),r[f.CURRENTLY_DRAWING]&&e._modes[r.mode]?o=r.mode:(r[f.COORDINATE_POINT_IDS]&&i.push.apply(i,r[f.COORDINATE_POINT_IDS]),n.push(t))}),this._store.delete([].concat(n,i),{origin:"api"}),o&&this._modes[o]&&this._modes[o].cleanUp()&&this._modes[o].cleanUp()},e.selectFeature=function(t,e){this.getSelectModeOrThrow(e).selectFeature(t)},e.deselectFeature=function(t){this.getSelectModeOrThrow().deselectFeature(t)},e.getFeatureId=function(){return this._store.getId()},e.hasFeature=function(t){return this._store.has(t)},e.checkIsReservedProperty=function(t){return![].concat(Object.values(g),Object.values(f)).includes(t)},e.updateFeatureProperties=function(t,e){var i=this;if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var n=this._store.copy(t);if(this.isGuidanceFeature(n))throw new Error("Guidance features are not allowed to be updated directly.");var o=n.properties.mode;if(!this._modes[o])throw new Error("No mode with name "+o+" present in instance");var r=Object.entries(e);r.forEach(function(t){var e=t[0],n=t[1];if(!i.checkIsReservedProperty(e))throw new Error("You are trying to update a reserved property name: "+e+". Please choose another name.");if(void 0!==n&&!pi(n))throw new Error("Invalid JSON value provided for property "+e)}),this._store.updateProperty(r.map(function(t){return{id:n.id,property:t[0],value:t[1]}}),{origin:"api"})},e.updateFeatureGeometry=function(t,e){if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var i=this._store.copy(t);if(this.isGuidanceFeature(i))throw new Error("Guidance features are not allowed to be updated directly.");if(!(i&&e&&e.type&&e.coordinates))throw new Error("Invalid geometry provided");if(e.type!==i.geometry.type)throw new Error("Geometry type mismatch: expected "+i.geometry.type+", got "+e.type);var n=i.properties.mode,r=this._modes[n];if(!r)throw new Error("No mode with name "+n+" present in instance");var s=o({},i,{geometry:e}),a=r.validateFeature(s);if(!a.valid)throw new Error("Feature validation failed: "+(a.reason||"Unknown reason"));if(this._store.updateGeometry([{id:i.id,geometry:e}],{origin:"api"}),r.afterFeatureUpdated){r.afterFeatureUpdated(s);var d=s.properties[g.SELECTED],u=this.getSelectMode({switchToSelectMode:!1});u&&d&&u.afterFeatureUpdated(s)}},e.transformFeatureGeometry=function(t,e){var i=this;if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var n=this._store.copy(t);if(this.isGuidanceFeature(n))throw new Error("Guidance features are not allowed to be updated directly.");var o,r=n.properties.mode,s=this._modes[r];if(!s)throw new Error("No mode with name "+r+" present in instance");if("Polygon"===n.geometry.type)o=n.geometry.coordinates[0];else{if("LineString"!==n.geometry.type)throw new Error("Feature geometry type "+n.geometry.type+" is not supported for transformation");o=n.geometry.coordinates}if("web-mercator"!=e.projection)throw new Error("Projection "+e.projection+" is not currently supported for transformation");if("scale"===e.type){var a=R(e.origin[0],e.origin[1]);me({coordinates:o,originX:a.x,originY:a.y,xScale:e.options.xScale||1,yScale:e.options.yScale||1})}else"rotate"===e.type&&(o="Polygon"===(n=ge(n,e.options.angle||0)).geometry.type?n.geometry.coordinates[0]:n.geometry.coordinates);if(o=o.map(function(t){return[b(t[0],i._adapter.getCoordinatePrecision()),b(t[1],i._adapter.getCoordinatePrecision())]}),n.geometry.coordinates="Polygon"===n.geometry.type?[o]:o,this._store.updateGeometry([{id:n.id,geometry:n.geometry}],{origin:"api"}),s.afterFeatureUpdated){s.afterFeatureUpdated(n);var d=n.properties[g.SELECTED],u=this.getSelectMode({switchToSelectMode:!1});u&&d&&u.afterFeatureUpdated(n)}},e.undo=function(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.undo()},e.canUndo=function(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canUndo()},e.canRedo=function(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canRedo()},e.redo=function(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.redo()},e.clearUndoRedoHistory=function(){this.checkEnabled(),this.undoRedoCoordinator&&this.undoRedoCoordinator.clearHistory()},e.addFeatures=function(t){var e=this;return this.checkEnabled(),0===t.length?[]:this._store.load(t,function(t){if(m(t)){var i=t.properties.mode,n=e._modes[i];if(!n)return{id:t.id,valid:!1,reason:i+" mode is not in the list of instantiated modes"};var o=n.validateFeature.bind(n)(t);return{id:t.id,valid:o.valid,reason:o.reason?o.reason:o.valid?void 0:"Feature is invalid"}}return{id:t.id,valid:!1,reason:"Mode property does not exist"}},function(t){if(m(t)){var i=e._modes[t.properties.mode];i&&i.afterFeatureAdded&&i.afterFeatureAdded(t)}},{origin:"api"})},e.start=function(){var t=this;this._enabled||(this._enabled=!0,this._adapter.register({onReady:function(){t._eventListeners.ready.forEach(function(t){t()})},getState:function(){return t._mode.state},onClick:function(e){var i=t.drawingUndoRedo?t.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};t._mode.onClick(e),t.emitDrawingPushIfHistoryChanged(i)},onMouseMove:function(e){t._mode.onMouseMove(e)},onKeyDown:function(e){t.handleUndoRedoKeyboardShortcut(e)||t._mode.onKeyDown(e)},onKeyUp:function(e){var i=t.drawingUndoRedo?t.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};t._mode.onKeyUp(e),t.emitDrawingPushIfHistoryChanged(i)},onDragStart:function(e,i){t._mode.onDragStart(e,i)},onDrag:function(e,i){t._mode.onDrag(e,i)},onDragEnd:function(e,i){t._mode.onDragEnd(e,i)},onClear:function(){t._mode.cleanUp(),t._store.clear({origin:"api"})}}))},e.getFeaturesAtLngLat=function(t,e){return this.featuresAtLocation({lng:t.lng,lat:t.lat},e)},e.getFeaturesAtPointerEvent=function(t,e){var i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)},e.stop=function(){this._enabled&&(this._enabled=!1,this._adapter.unregister())},e.on=function(t,e){var i=this._eventListeners[t];i.includes(e)||i.push(e)},e.off=function(t,e){var i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)},i(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}])}(),exports.TerraDrawAngledRectangleMode=Qe,exports.TerraDrawCircleMode=st,exports.TerraDrawExtend=di,exports.TerraDrawFreehandLineStringMode=ci,exports.TerraDrawFreehandMode=ct,exports.TerraDrawLineStringMode=Bt,exports.TerraDrawMarkerMode=fi,exports.TerraDrawModeUndoRedo=wi,exports.TerraDrawPointMode=Yt,exports.TerraDrawPolygonMode=Zt,exports.TerraDrawRectangleMode=Qt,exports.TerraDrawRenderMode=te,exports.TerraDrawSectorMode=ni,exports.TerraDrawSelectMode=Se,exports.TerraDrawSensorMode=si,exports.TerraDrawSessionUndoRedo=Oi,exports.TerraDrawUndoRedoKeyboardShortcuts=Ci,exports.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:I}:Ge(t.geometry)>e?{valid:!1,reason:"Feature is larger than the maximum area"}:{valid:!0}},exports.ValidateMinAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:I}:Ge(t.geometry)<e?{valid:!1,reason:Ye}:{valid:!0}},exports.ValidateNotSelfIntersecting=function(t){return"Polygon"!==t.geometry.type&&"LineString"!==t.geometry.type?{valid:!1,reason:Xe}:A(t)?{valid:!1,reason:qe}:{valid:!0}},exports.ValidationReasons=ui;
1
+ function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);i<e;i++)n[i]=t[i];return n}function e(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,a(n.key),n)}}function i(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(e,i){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,i){if(e){if("string"==typeof e)return t(e,i);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,i):void 0}}(e))||i&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)({}).hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},o.apply(null,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function a(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}var d,u="draw",h="edit",l="deleteCoordinate",c="insertMidpoint";!function(t){t.Commit="commit",t.Provisional="provisional",t.Finish="finish"}(d||(d={}));var p="https://raw.githubusercontent.com/JamesLMilner/terra-draw/refs/heads/main/assets/markers/marker-blue.png",g={SELECTED:"selected",MID_POINT:"midPoint",SELECTION_POINT_FEATURE_ID:"selectionPointFeatureId",SELECTION_POINT:"selectionPoint"},f={MODE:"mode",CURRENTLY_DRAWING:"currentlyDrawing",EDITED:"edited",CLOSING_POINT:"closingPoint",SNAPPING_POINT:"snappingPoint",COORDINATE_POINT:"coordinatePoint",COORDINATE_POINT_FEATURE_ID:"coordinatePointFeatureId",COORDINATE_POINT_IDS:"coordinatePointIds",PROVISIONAL_COORDINATE_COUNT:"provisionalCoordinateCount",COMMITTED_COORDINATE_COUNT:"committedCoordinateCount",MARKER:"marker"},y=10;function v(t){return Boolean(t&&"object"==typeof t&&null!==t&&!Array.isArray(t))}function m(t){return Boolean(t&&"object"==typeof t&&"properties"in t&&"object"==typeof t.properties&&null!==t.properties&&"mode"in t.properties)}function C(t){return!!function(t){return"number"==typeof t&&!isNaN(new Date(t).valueOf())}(t)}var P,I="Feature is not a Polygon",S="Feature mode property does not match the mode being added to";!function(t){t.Drawing="drawing",t.Select="select",t.Static="static",t.Render="render"}(P||(P={}));var F={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},x=/*#__PURE__*/function(){function t(t,e){void 0===e&&(e=!1),this._state="unregistered",this._styles={},this.pointerEvents=F,this.behaviors=[],this.validate=void 0,this.pointerDistance=40,this.coordinatePrecision=void 0,this.undoRedoMaxStackSize=void 0,this.onStyleChange=void 0,this.store=void 0,this.projection="web-mercator",this.setDoubleClickToZoom=void 0,this.unproject=void 0,this.project=void 0,this.setCursor=void 0,this.isInitialUpdate=!1,this.type=P.Drawing,this.mode="base",e?this.isInitialUpdate=!0:this.updateOptions(o({},t))}var e=t.prototype;return e.registerBehaviors=function(t){},e.updateOptions=function(t){null!=t&&t.styles&&(this.styles=o({},this._styles,t.styles)),null!=t&&t.pointerDistance&&(this.pointerDistance=t.pointerDistance),null!=t&&t.validation&&(this.validate=t&&t.validation),null!=t&&t.projection&&(this.projection=t.projection),void 0!==(null==t?void 0:t.pointerEvents)&&(this.pointerEvents=t.pointerEvents),null!=t&&t.modeName&&!0===this.isInitialUpdate&&(this.mode=t.modeName),this.isInitialUpdate=!1},e.allowPointerEvent=function(t,e){return"boolean"==typeof t?t:"function"!=typeof t||t(e)},e.setDrawing=function(){if("started"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="drawing"},e.setStarted=function(){if("stopped"!==this._state&&"registered"!==this._state&&"drawing"!==this._state&&"selecting"!==this._state)throw new Error("Mode must be unregistered or stopped to start");this._state="started",this.setDoubleClickToZoom(!1)},e.setStopped=function(){if("started"!==this._state)throw new Error("Mode must be started to be stopped");this._state="stopped",this.setDoubleClickToZoom(!0)},e.register=function(t){if("unregistered"!==this._state)throw new Error("Can not register unless mode is unregistered");this._state="registered",this.store=t.store,this.store.registerOnChange(t.onChange),this.setDoubleClickToZoom=t.setDoubleClickToZoom,this.project=t.project,this.unproject=t.unproject,this.onSelect=t.onSelect,this.onDeselect=t.onDeselect,this.setCursor=t.setCursor,this.onStyleChange=t.onChange,this.onFinish=t.onFinish,this.coordinatePrecision=t.coordinatePrecision,this.undoRedoMaxStackSize=t.undoRedoMaxStackSize,this.registerBehaviors({mode:t.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:t.coordinatePrecision,projection:this.projection,undoRedoMaxStackSize:t.undoRedoMaxStackSize})},e.validateFeature=function(t){return this.performFeatureValidation(t)},e.afterFeatureAdded=function(t){},e.afterFeatureUpdated=function(t){},e.performFeatureValidation=function(t){if("unregistered"===this._state)throw new Error("Mode must be registered");var e=function(t,e){var i;if(v(t))if(null==t.id)i="Feature has no id";else if("string"!=typeof t.id&&"number"!=typeof t.id)i="Feature must be string or number as per GeoJSON spec";else if(e(t.id))if(v(t.geometry))if(v(t.properties))if("string"==typeof t.geometry.type&&["Polygon","LineString","Point"].includes(t.geometry.type))if(Array.isArray(t.geometry.coordinates)){if(!t.properties.mode||"string"!=typeof t.properties.mode)return{valid:!1,reason:"Feature does not have a valid mode property"}}else i="Feature coordinates is not an array";else i="Feature is not Point, LineString or Polygon";else i="Feature has no properties";else i="Feature has no geometry";else i="Feature must match the id strategy (default is UUID4)";else i="Feature is not object";return i?{valid:!1,reason:i}:{valid:!0}}(t,this.store.idStrategy.isValidId);if(!e.valid)return e;if(this.validate){var i=this.validate(t,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:d.Provisional});return{valid:e.valid&&i.valid,reason:i.reason}}return{valid:e.valid,reason:e.reason}},e.validateModeFeature=function(t,e){var i=this.performFeatureValidation(t);return i.valid?t.properties.mode===this.mode?e(t):{valid:!1,reason:S}:{valid:!1,reason:i.reason}},e.onFinish=function(t,e){},e.onDeselect=function(t){},e.onSelect=function(t){},e.onKeyDown=function(t){},e.onKeyUp=function(t){},e.undo=function(){},e.clearHistory=function(){},e.undoSize=function(){return 0},e.redoSize=function(){return 0},e.redo=function(){},e.onMouseMove=function(t){},e.onClick=function(t){},e.onDragStart=function(t,e){},e.onDrag=function(t,e){},e.onDragEnd=function(t,e){},e.getHexColorStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getNumericStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getUrlStylingValue=function(t,e,i){return this.getStylingValue(t,e,i)},e.getStylingValue=function(t,e,i){return void 0===t?e:"function"==typeof t?null!=(n=t(i))?n:e:t;var n},i(t,[{key:"state",get:function(){return this._state},set:function(t){throw new Error("Please use the modes lifecycle methods")}},{key:"styles",get:function(){return this._styles},set:function(t){if("object"!=typeof t)throw new Error("Styling must be an object");this.onStyleChange&&this.onStyleChange([],"styling"),this._styles=t}}])}(),M=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).type=P.Select,e}return r(e,t),e}(x);function w(t,e){var i=function(t){return t*Math.PI/180},n=i(t[1]),o=i(t[0]),r=i(e[1]),s=r-n,a=i(e[0])-o,d=Math.sin(s/2)*Math.sin(s/2)+Math.cos(n)*Math.cos(r)*Math.sin(a/2)*Math.sin(a/2);return 2*Math.atan2(Math.sqrt(d),Math.sqrt(1-d))*6371e3/1e3}var O=6371008.8;function E(t){return t%360*Math.PI/180}function D(t){return t/6371.0088}function k(t){return t%(2*Math.PI)*180/Math.PI}function b(t,e){void 0===e&&(e=9);var i=Math.pow(10,e);return Math.round(t*i)/i}var _=57.29577951308232,T=.017453292519943295,N=6378137,R=function(t,e){return{x:0===t?0:t*T*N,y:0===e?0:Math.log(Math.tan(Math.PI/4+e*T/2))*N}},U=function(t,e){return{lng:0===t?0:_*(t/N),lat:0===e?0:(2*Math.atan(Math.exp(e/N))-Math.PI/2)*_}};function W(t,e,i){var n=E(t[0]),o=E(t[1]),r=E(i),s=D(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[k(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),k(a)]}function L(t){for(var e=t.center,i=t.radiusKilometers,n=t.coordinatePrecision,o=t.steps?t.steps:64,r=[],s=0;s<o;s++){var a=W(e,i,-360*s/o);r.push([b(a[0],n),b(a[1],n)])}return r.push(r[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[r]},properties:{}}}function A(t){var e;if("Polygon"===t.geometry.type)e=t.geometry.coordinates;else{if("LineString"!==t.geometry.type)throw new Error("Self intersects only accepts Polygons and LineStrings");e=[t.geometry.coordinates]}for(var i=[],n=0;n<e.length;n++)for(var o=0;o<e[n].length-1;o++)for(var r=0;r<e.length;r++)for(var s=0;s<e[r].length-1;s++)d(n,o,r,s);return i.length>0;function a(t){return t<0||t>1}function d(t,n,o,r){var s,d=e[t][n],u=e[t][n+1],h=e[o][r],l=e[o][r+1],c=function(t,e,i,n){if(B(t,i)||B(t,n)||B(e,i)||B(n,i))return null;var o=t[0],r=t[1],s=e[0],a=e[1],d=i[0],u=i[1],h=n[0],l=n[1],c=(o-s)*(u-l)-(r-a)*(d-h);return 0===c?null:[((o*a-r*s)*(d-h)-(o-s)*(d*l-u*h))/c,((o*a-r*s)*(u-l)-(r-a)*(d*l-u*h))/c]}(d,u,h,l);null!==c&&(s=l[0]!==h[0]?(c[0]-h[0])/(l[0]-h[0]):(c[1]-h[1])/(l[1]-h[1]),a(u[0]!==d[0]?(c[0]-d[0])/(u[0]-d[0]):(c[1]-d[1])/(u[1]-d[1]))||a(s)||(c.toString(),i.push(c)))}}function B(t,e){return t[0]===e[0]&&t[1]===e[1]}function z(t,e){return G(t[0])<=e&&G(t[1])<=e}function H(t){return 2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1]&&Infinity!==t[0]&&Infinity!==t[1]&&(i=t[0])>=-180&&i<=180&&(e=t[1])>=-90&&e<=90;var e,i}function G(t){for(var e=1,i=0;Math.round(t*e)/e!==t;)e*=10,i++;return i}var V="Feature has holes",j="Feature has less than 4 coordinates",K="Feature has invalid coordinates",Y="Feature coordinates are not closed";function X(t,e){if("Polygon"!==t.geometry.type)return{valid:!1,reason:"Feature is not a Polygon"};if(1!==t.geometry.coordinates.length)return{valid:!1,reason:V};if(t.geometry.coordinates[0].length<4)return{valid:!1,reason:j};for(var i=0;i<t.geometry.coordinates[0].length;i++){if(!H(t.geometry.coordinates[0][i]))return{valid:!1,reason:K};if(!z(t.geometry.coordinates[0][i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return(n=t.geometry.coordinates[0][0])[0]!==(o=t.geometry.coordinates[0][t.geometry.coordinates[0].length-1])[0]||n[1]!==o[1]?{valid:!1,reason:Y}:{valid:!0};var n,o}function q(t,e){var i=X(t,e);return i.valid?A(t)?{valid:!1,reason:"Feature intersects itself"}:{valid:!0}:i}var Z=function(t){var e=t.store,i=t.mode,n=t.project,o=t.unproject,r=t.pointerDistance,s=t.coordinatePrecision,a=t.projection,d=t.undoRedoMaxStackSize;this.store=void 0,this.mode=void 0,this.project=void 0,this.unproject=void 0,this.pointerDistance=void 0,this.coordinatePrecision=void 0,this.projection=void 0,this.undoRedoMaxStackSize=void 0,this.store=e,this.mode=i,this.project=n,this.unproject=o,this.pointerDistance=r,this.coordinatePrecision=s,this.projection=a,this.undoRedoMaxStackSize=d};function J(t){var e=function(t){for(var e=t.coordinates[0],i=0,n=0;n<e.length-1;n++){var o=e[n],r=e[n+1];i+=(r[0]-o[0])*(r[1]+o[1])}return i<0}(t);if(!e)return{type:"Polygon",coordinates:[t.coordinates[0].reverse()]}}var $="insert-before",Q="insert-after",tt="update",et="delete",it="replace",nt=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).options=void 0,n.options=i,n}r(e,t);var i=e.prototype;return i.createPoint=function(t){var e=t.coordinates,i=t.properties,n=t.context;if((null==n?void 0:n.updateType)!==d.Finish||this.validateGeometryWithUpdateType({geometry:{type:"Point",coordinates:e},properties:i,updateType:d.Finish}))return this.handleCreateFeature({geometry:{type:"Point",coordinates:e},properties:i})},i.createLineString=function(t){return this.handleCreateFeature({geometry:{type:"LineString",coordinates:t.coordinates},properties:t.properties})},i.createPolygon=function(t){var e=t.coordinates,i=t.properties,n=J({type:"Polygon",coordinates:[e]});return this.handleCreateFeature({geometry:{type:"Polygon",coordinates:n?n.coordinates:[e]},properties:i})},i.createGuidancePoint=function(t){return this.createGuidancePoints({coordinates:[t.coordinate],type:t.type})[0]},i.createGuidancePoints=function(t){var e=this,i=t.type,n=t.additionalProperties,r=t.coordinates.map(function(t,r){var s;return{type:"Feature",geometry:{type:"Point",coordinates:t},properties:o((s={mode:e.mode},s[i]=!0,s),n?n(r):{})}});return this.createFeatures(r)},i.updatePoint=function(t){return this.handleMutateFeature({type:"Point",featureId:t.featureId,coordinateMutations:t.coordinateMutations,propertyMutations:t.propertyMutations,context:t.context})},i.updatePolygon=function(t){return this.handleMutateFeature({type:"Polygon",featureId:t.featureId,coordinateMutations:t.coordinateMutations,propertyMutations:t.propertyMutations,context:t.context})},i.updateLineString=function(t){return this.handleMutateFeature({type:"LineString",featureId:t.featureId,coordinateMutations:t.coordinateMutations,propertyMutations:t.propertyMutations,context:t.context})},i.deleteFeatureIfPresent=function(t){t&&this.store.has(t)&&this.store.delete([t])},i.deleteFeaturesIfPresent=function(t){var e=this;if(0!==t.length){var i=t.filter(function(t){return e.store.has(t)});i.length&&this.store.delete(i)}},i.setDeselected=function(t){var e=this,i=t.filter(function(t){return e.store.has(t)}).map(function(t){var e;return{featureId:t,properties:(e={},e[g.SELECTED]=!1,e)}});this.updateFeatureProperties(i)},i.setSelected=function(t){var e,i=this.store.getGeometryCopy(t).type,n={featureId:t,propertyMutations:(e={},e[g.SELECTED]=!0,e),context:{updateType:d.Commit}};"Polygon"===i?this.updatePolygon(n):"LineString"===i?this.updateLineString(n):"Point"===i&&this.updatePoint(n)},i.updateGuidancePoints=function(t){this.updateFeatureGeometries(t.map(function(t){return{id:t.featureId,geometry:{type:"Point",coordinates:t.coordinate}}}))},i.handleCreateFeature=function(t){return this.createFeatureWithGeometry({geometry:t.geometry,properties:t.properties})},i.handleMutateFeature=function(t){var e=t.featureId,i=t.coordinateMutations,n=t.context;if(!this.mutateFeature({type:t.type,featureId:e,coordinateMutations:i,propertyMutations:t.propertyMutations,context:n.updateType===d.Finish?o({},n,{correctRightHandRule:!0}):o({},n)}))return null;var r=this.buildFeatureWithGeometry(e);return n.updateType!==d.Finish||i||this.validateGeometryWithUpdateType({geometry:r.geometry,properties:r.properties,updateType:n.updateType})?r:null},i.mutateFeature=function(t){var e=t.type,i=t.featureId,n=t.coordinateMutations,o=t.propertyMutations,r=t.context;if(!i)return!1;var s=this.store.getGeometryCopy(i),a=this.store.getPropertiesCopy(i);if(s.type!==e)throw new Error(e+" geometries cannot be updated on features with "+s.type+" geometries");if(n){var d=this.applyCoordinateMutations(s,n);if(r.correctRightHandRule&&"Polygon"===d.type){var u=J(d);u&&(d=u)}if(!this.validateGeometryWithUpdateType({geometry:d,properties:a,updateType:r.updateType}))return!1;this.updateFeatureGeometries([{id:i,geometry:d}])}return o&&this.updateFeatureProperties([{featureId:i,properties:o}]),!0},i.applyCoordinateMutations=function(t,e){if(this.isReplaceMutation(e))return o({},t,{coordinates:e.coordinates});if("Point"===t.type)throw new Error("Coordinate mutations are not supported for Point geometries");for(var i,r="Polygon"===t.type,s=r?t.coordinates[0].slice():t.coordinates.slice(),a=s.length,d=function(t){var e=t<0?a+t:t;if(e<0||e>=a)throw new RangeError("Index "+t+" (normalized to "+e+") is out of bounds");return e},u=new Array(a).fill(void 0),h=Array.from({length:a},function(){return[]}),l=Array.from({length:a},function(){return[]}),c=[],p=n(e);!(i=p()).done;){var g=i.value;if(g.type!==$&&g.type!==Q){var f=d(g.index);u[f]=o({},g,{index:f})}else{var y=g.index,v=y<0?a+y:y;if(v<0||v>a)throw new RangeError("Index "+g.index+" (normalized to "+v+") is out of bounds");if(g.type===$){if(v>=a)throw new RangeError("INSERT_BEFORE index "+g.index+" (normalized to "+v+") is out of bounds for length "+a);h[v].push(g)}else v===a?c.push(g):l[v].push(g)}}for(var m=[],C=0;C<a;C++){for(var P,I=n(h[C]);!(P=I()).done;)m.push(P.value.coordinate);var S=u[C];S?S.type===et||m.push(S.coordinate):m.push(s[C]);for(var F,x=n(l[C]);!(F=x()).done;)m.push(F.value.coordinate)}for(var M=0,w=c;M<w.length;M++)m.push(w[M].coordinate);return o({},t,r?{coordinates:[m].concat(t.coordinates.slice(1))}:{coordinates:m})},i.isReplaceMutation=function(t){return t.type===it},i.createFeatureWithGeometry=function(t){var e=this.createFeatures([{type:"Feature",geometry:t.geometry,properties:t.properties}])[0];return{id:e,type:"Feature",properties:this.store.getPropertiesCopy(e),geometry:this.store.getGeometryCopy(e)}},i.validateGeometryWithUpdateType=function(t){return!this.options.validate||this.options.validate({type:"Feature",geometry:t.geometry,properties:t.properties||{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:t.updateType}).valid},i.buildFeatureWithGeometry=function(t){return{id:t,type:"Feature",properties:this.store.getPropertiesCopy(t),geometry:this.store.getGeometryCopy(t)}},i.createFeatures=function(t){return this.store.create(t)},i.updateFeatureGeometries=function(t){this.store.updateGeometry(t)},i.updateFeatureProperties=function(t){var e=t.map(function(t){var e=t.featureId;return Object.entries(t.properties).map(function(t){return{id:e,property:t[0],value:t[1]}})}).flat();this.store.updateProperty(e)},e}(Z),ot={cancel:"Escape",finish:"Enter"},rt={start:"crosshair"},st=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="circle",i.center=void 0,i.endPosition=void 0,i.segments=64,i.currentCircleId=void 0,i.keyEvents=ot,i.cursors=rt,i.startingRadiusKilometers=1e-5,i.cursorMovedAfterInitialCursorDown=!1,i.drawInteraction="click-move",i.drawType=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.startingRadiusKilometers&&(this.startingRadiusKilometers=e.startingRadiusKilometers),null!=e&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction),null!=e&&e.segments&&(this.segments=e.segments<3?3:e.segments)},i.close=function(){if(void 0!==this.currentCircleId&&void 0!==this.endPosition&&this.updateCircle(this.endPosition,d.Finish)){var t=this.currentCircleId;this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:u})}},i.beginDrawing=function(t,e){var i;void 0===e&&(e="click"),this.center=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];var n=L({center:this.center,radiusKilometers:this.startingRadiusKilometers,coordinatePrecision:this.coordinatePrecision}),o=this.mutateFeature.createPolygon({coordinates:n.geometry.coordinates[0],properties:(i={mode:this.mode,radiusKilometers:this.startingRadiusKilometers},i[f.CURRENTLY_DRAWING]=!0,i)});o&&(this.currentCircleId=o.id,this.cursorMovedAfterInitialCursorDown=!1,this.drawType=e,this.setDrawing())},i.dragDrawAllowed=function(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.moveDrawAllowed=function(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.center?this.center&&void 0!==this.currentCircleId&&(this.endPosition=[t.lng,t.lat],this.close()):this.beginDrawing(t))},i.onMouseMove=function(t){this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(this.endPosition,d.Provisional)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(t,e){"drawing"!==this.state&&this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1))},i.onDrag=function(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.cursorMovedAfterInitialCursorDown=!0,this.endPosition=[t.lng,t.lat],this.updateCircle(this.endPosition,d.Provisional))},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.close(),e(!0))},i.cleanUp=function(){var t=this.currentCircleId;this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.updateCircle=function(t,e){if(void 0!==this.currentCircleId&&void 0!==this.center){var i,n,o=e===d.Finish;if(this.cursorMovedAfterInitialCursorDown)if(n=w(this.center,t),"web-mercator"===this.projection){var r=function(t,e){var i=1e3*w(t,e);if(0===i)return 1;var n=R(t[0],t[1]),o=n.x,r=n.y,s=R(e[0],e[1]),a=s.y;return Math.sqrt(Math.pow(s.x-o,2)+Math.pow(a-r,2))/i}(this.center,t);i=function(t){for(var e=t.center,i=t.coordinatePrecision,n=t.steps?t.steps:64,o=1e3*t.radiusKilometers,r=R(e[0],e[1]),s=r.x,a=r.y,d=[],u=0;u<n;u++){var h=360*u/n*Math.PI/180,l=o*Math.cos(h),c=o*Math.sin(h),p=U(s+l,a+c),g=p.lat;d.push([b(p.lng,i),b(g,i)])}return d.push(d[0]),{type:"Feature",geometry:{type:"Polygon",coordinates:[d]},properties:{}}}({center:this.center,radiusKilometers:n*r,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}else{if("globe"!==this.projection)throw new Error("Invalid projection");i=L({center:this.center,radiusKilometers:n,coordinatePrecision:this.coordinatePrecision,steps:this.segments})}var s={};return i&&n&&(s.radiusKilometers=n),o&&(s[f.CURRENTLY_DRAWING]=void 0),this.mutateFeature.updatePolygon({featureId:this.currentCircleId,coordinateMutations:i?{type:it,coordinates:i.geometry.coordinates}:void 0,propertyMutations:s,context:o?{updateType:e,action:u}:{updateType:e}})}},i.afterFeatureUpdated=function(t){this.currentCircleId===t.id&&(this.cursorMovedAfterInitialCursorDown=!1,this.center=void 0,this.currentCircleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.mutateFeature=new nt(t,{validate:this.validate})},e}(x),at=function(t,e){var i=e.x-t.x,n=e.y-t.y;return Math.sqrt(n*n+i*i)};function dt(t,e){return t[0]===e[0]&&t[1]===e[1]}var ut=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}r(e,t);var i=e.prototype;return i.getGeometryType=function(t){return this.store.getGeometryCopy(t).type},i.coordinateAtIndexIsIdentical=function(t){var e,i=t.newCoordinate,n=t.index,o=this.store.getGeometryCopy(t.featureId);if("Polygon"===o.type)e=o.coordinates[0][n];else if("LineString"===o.type)e=o.coordinates[n];else{if(0!==n)throw new Error("Point geometries only have one coordinate at index 0");e=o.coordinates}return dt(i,e)},i.getGeometry=function(t){return this.store.getGeometryCopy(t)},i.getCoordinates=function(t){var e=this.store.getGeometryCopy(t),i=e.coordinates;return"Polygon"===e.type?i[0]:i},i.getCoordinate=function(t,e){var i=this.getCoordinates(t),n=e<0?i.length+e:e;if(n<0||n>=i.length)throw new RangeError("Index "+e+" (normalized to "+n+") is out of bounds");return i[n]},i.getProperties=function(t){return this.store.getPropertiesCopy(t)},i.hasFeature=function(t){return this.store.has(t)},i.getAllFeatureIdsWhere=function(t){return this.store.copyAllWhere(t).map(function(t){return t.id})},e}(Z),ht={cancel:"Escape",finish:"Enter"},lt={start:"crosshair",close:"pointer"},ct=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="freehand",i.canClose=!1,i.currentId=void 0,i.closingPointId=void 0,i.minDistance=20,i.keyEvents=ht,i.cursors=lt,i.preventPointsNearClose=!0,i.autoClose=!1,i.autoCloseTimeout=500,i.hasLeftStartingPoint=!1,i.preventNewFeature=!1,i.drawInteraction="click-move",i.drawType=void 0,i.smoothing=0,i.mutateFeature=void 0,i.readFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.minDistance&&(this.minDistance=e.minDistance),void 0!==(null==e?void 0:e.smoothing)&&(this.smoothing=Math.min(Math.max(e.smoothing,0),.999)),void 0!==(null==e?void 0:e.preventPointsNearClose)&&(this.preventPointsNearClose=e.preventPointsNearClose),void 0!==(null==e?void 0:e.autoClose)&&(this.autoClose=e.autoClose),null!=e&&e.autoCloseTimeout&&(this.autoCloseTimeout=e.autoCloseTimeout),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null!=e&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction)},i.moveDrawAllowed=function(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.dragDrawAllowed=function(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.beginDrawing=function(t,e){var i;void 0===e&&(e="click");var n=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(i={mode:this.mode},i[f.CURRENTLY_DRAWING]=!0,i)});this.currentId=n.id,this.drawType=e,this.closingPointId=this.mutateFeature.createGuidancePoint({coordinate:[t.lng,t.lat],type:f.CLOSING_POINT}),this.canClose=!0,"drawing"!==this.state&&this.setDrawing()},i.addCoordinate=function(t){var e=this;if(void 0!==this.currentId&&!1!==this.canClose){var i=this.readFeature.getCoordinate(this.currentId,-2),n=i[0],o=i[1],r=this.project(n,o),s=at({x:r.x,y:r.y},{x:t.containerX,y:t.containerY}),a=this.readFeature.getCoordinate(this.currentId,0),u=this.project(a[0],a[1]);if(at({x:u.x,y:u.y},{x:t.containerX,y:t.containerY})<this.pointerDistance){if(this.autoClose&&this.hasLeftStartingPoint&&(this.preventNewFeature=!0,setTimeout(function(){e.preventNewFeature=!1},this.autoCloseTimeout),this.close()),this.setCursor(this.cursors.close),this.preventPointsNearClose)return}else this.hasLeftStartingPoint=!0,this.setCursor(this.cursors.start);if(!(s<this.minDistance)){var h=this.getSmoothedCoordinate([n,o],[t.lng,t.lat]);this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:$,index:-1,coordinate:h}],context:{updateType:d.Provisional}})}}else this.setCursor(this.cursors.start)},i.getSmoothedCoordinate=function(t,e){return 0===this.smoothing?e:[t[0]*this.smoothing+e[0]*(1-this.smoothing),t[1]*this.smoothing+e[1]*(1-this.smoothing)]},i.close=function(){var t;if(void 0!==this.currentId&&this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),context:{updateType:d.Finish,action:u}})){var e=this.currentId;this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:u})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.moveDrawAllowed()&&"click"===this.drawType&&this.addCoordinate(t)},i.onClick=function(t){if(this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))){if(this.preventNewFeature)return;if(!1===this.canClose)return void this.beginDrawing(t);this.close()}},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&!0===this.canClose&&this.close()},i.onDragStart=function(t,e){"drawing"!==this.state&&(this.preventNewFeature||this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1)))},i.onDrag=function(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&this.addCoordinate(t)},i.onDragEnd=function(t,e){var i=this;this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.preventNewFeature=!0,setTimeout(function(){i.preventNewFeature=!1},this.autoCloseTimeout),this.close(),e(!0))},i.cleanUp=function(){var t=this.currentId,e=this.closingPointId;this.closingPointId=void 0,this.currentId=void 0,this.canClose=!1,this.hasLeftStartingPoint=!1,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,void 0===e.pointOpacity?1:e.pointOpacity,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,void 0===e.pointOutlineOpacity?1:e.pointOutlineOpacity,t),e.zIndex=50,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return X(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.mutateFeature.deleteFeatureIfPresent(this.closingPointId),this.canClose=!1,this.currentId=void 0,this.closingPointId=void 0,this.hasLeftStartingPoint=!1)},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},e}(x);function pt(t){var e=t.unproject,i=t.point,n=t.pointerDistance/2,o=i.x,r=i.y;return{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[e(o-n,r-n),e(o+n,r-n),e(o+n,r+n),e(o-n,r+n),e(o-n,r-n)].map(function(t){return[t.lng,t.lat]})]}}}var gt=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.create=function(t){return pt({unproject:this.unproject,point:{x:t.containerX,y:t.containerY},pointerDistance:this.pointerDistance})},e}(Z),ft=/*#__PURE__*/function(t){function e(e){return t.call(this,e)||this}return r(e,t),e.prototype.measure=function(t,e){var i=this.project(e[0],e[1]);return at({x:i.x,y:i.y},{x:t.containerX,y:t.containerY})},e}(Z),yt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinateFirstClick=function(t){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)}).coordinate},o.getSnappableCoordinate=function(t,e){return o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)}).coordinate},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getSnappable=function(t,e){var i=this,n=this.clickBoundingBox.create(t),o=this.store.search(n,e),r={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDist:Infinity};return o.forEach(function(e){var n;if("Polygon"===e.geometry.type)n=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;n=e.geometry.coordinates}n.forEach(function(n,o){var s=i.pixelDistance.measure(t,n);s<r.minDist&&s<i.pointerDistance&&(r.coordinate=n,r.minDist=s,r.featureId=e.id,r.featureCoordinateIndex=o)})}),r},e}(Z);function vt(t,e,i){var n=E(t[0]),o=E(t[1]),r=E(i),s=D(e),a=Math.asin(Math.sin(o)*Math.cos(s)+Math.cos(o)*Math.sin(s)*Math.cos(r));return[k(n+Math.atan2(Math.sin(r)*Math.sin(s)*Math.cos(o),Math.cos(s)-Math.sin(o)*Math.sin(a))),k(a)]}function mt(t,e,i){var n=t.x,o=t.y,r=E(i);return{x:n+e*Math.cos(r),y:o+e*Math.sin(r)}}function Ct(t,e){var i=E(t[0]),n=E(e[0]),o=E(t[1]),r=E(e[1]),s=Math.sin(n-i)*Math.cos(r),a=Math.cos(o)*Math.sin(r)-Math.sin(o)*Math.cos(r)*Math.cos(n-i);return k(Math.atan2(s,a))}function Pt(t,e){var i=e.x-t.x,n=e.y-t.y;if(0===i&&0===n)return 0;var o=Math.atan2(n,i);return(o*=180/Math.PI)>180?o-=360:o<-180&&(o+=360),o}function It(t){return(t+360)%360}function St(t,e,i){for(var n,o,r,s=[],a=t.length,d=0,u=0;u<t.length&&!(e>=d&&u===t.length-1);u++){if(d>e&&0===s.length){if(!(n=e-d))return s.push(t[u]),s;o=Ct(t[u],t[u-1])-180,r=vt(t[u],n,o),s.push(r)}if(d>=i)return(n=i-d)?(o=Ct(t[u],t[u-1])-180,r=vt(t[u],n,o),s.push(r),s):(s.push(t[u]),s);if(d>=e&&s.push(t[u]),u===t.length-1)return s;d+=w(t[u],t[u+1])}if(d<e&&t.length===a)throw new Error("Start position is beyond line");var h=t[t.length-1];return[h,h]}function Ft(t){return t*(Math.PI/180)}function xt(t){return t*(180/Math.PI)}var Mt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e)||this).config=void 0,i.config=e,i}r(e,t);var i=e.prototype;return i.generateInsertionCoordinates=function(t,e,i){for(var n=[t,e],o=0,r=0;r<n.length-1;r++)o+=w(n[0],n[1]);if(o<=i)return n;var s=o/i-1;Number.isInteger(s)||(s=Math.floor(s)+1);for(var a=[],d=0;d<s;d++){var u=St(n,i*d,i*(d+1));a.push(u)}for(var h=[],l=0;l<a.length;l++)h.push(a[l][1]);return this.limitCoordinates(h)},i.generateInsertionGeodesicCoordinates=function(t,e,i){var n=w(t,e),o=function(t,e,i){var n=[],o=Ft(t[1]),r=Ft(t[0]),s=Ft(e[1]),a=Ft(e[0]);i+=1;var d=2*Math.asin(Math.sqrt(Math.pow(Math.sin((s-o)/2),2)+Math.cos(o)*Math.cos(s)*Math.pow(Math.sin((a-r)/2),2)));if(0===d||isNaN(d))return n;for(var u=0;u<=i;u++){var h=u/i,l=Math.sin((1-h)*d)/Math.sin(d),c=Math.sin(h*d)/Math.sin(d),p=l*Math.cos(o)*Math.cos(r)+c*Math.cos(s)*Math.cos(a),g=l*Math.cos(o)*Math.sin(r)+c*Math.cos(s)*Math.sin(a),f=l*Math.sin(o)+c*Math.sin(s);if(!(isNaN(p)||isNaN(g)||isNaN(f))){var y=Math.atan2(f,Math.sqrt(Math.pow(p,2)+Math.pow(g,2))),v=Math.atan2(g,p);isNaN(y)||isNaN(v)||n.push([xt(v),xt(y)])}}return n.slice(1,-1)}(t,e,Math.floor(n/i));return this.limitCoordinates(o)},i.limitCoordinates=function(t){var e=this;return t.map(function(t){return[b(t[0],e.config.coordinatePrecision),b(t[1],e.config.coordinatePrecision)]})},e}(Z);function wt(t,e){if("LineString"!==t.geometry.type)return{valid:!1,reason:"Feature is not a LineString"};if(t.geometry.coordinates.length<2)return{valid:!1,reason:"Feature has less than 2 coordinates"};for(var i=0;i<t.geometry.coordinates.length;i++){if(!H(t.geometry.coordinates[i]))return{valid:!1,reason:"Feature has invalid coordinates"};if(!z(t.geometry.coordinates[i],e))return{valid:!1,reason:"Feature has coordinates with excessive precision"}}return{valid:!0}}function Ot(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2))}function Et(t,e){var i=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}(t,e)/(Ot(t)*Ot(e));return Math.acos(Math.min(Math.max(i,-1),1))}function Dt(t){var e=E(t[1]),i=E(t[0]);return[Math.cos(e)*Math.cos(i),Math.cos(e)*Math.sin(i),Math.sin(e)]}function kt(t){var e=t[0],i=t[1],n=k(Math.asin(t[2]));return[k(Math.atan2(i,e)),n]}var bt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.pixelDistance=void 0,o.clickBoundingBox=void 0,o.getSnappableCoordinateFirstClick=function(t){var e=o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode)});return e.coordinate?[b(e.coordinate[0],o.config.coordinatePrecision),b(e.coordinate[1],o.config.coordinatePrecision)]:void 0},o.getSnappableCoordinate=function(t,e){var i=o.getSnappable(t,function(t){return Boolean(t.properties&&t.properties.mode===o.mode&&t.id!==e)});return i.coordinate?[b(i.coordinate[0],o.config.coordinatePrecision),b(i.coordinate[1],o.config.coordinatePrecision)]:void 0},o.config=e,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getSnappable=function(t,e){var i=this,o=this.clickBoundingBox.create(t),r=this.store.search(o,e),s={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:Infinity};return r.forEach(function(e){var o;if("Polygon"===e.geometry.type)o=e.geometry.coordinates[0];else{if("LineString"!==e.geometry.type)return;o=e.geometry.coordinates}for(var r,a=[],d=0;d<o.length-1;d++)a.push([o[d],o[d+1]]);var u=[t.lng,t.lat];if("web-mercator"===i.config.projection?r=function(t,e){for(var i,o,r,s,a,d,u,h,l=[Infinity,Infinity],c=Infinity,p=0,g=n(e);!(i=g()).done;){var f=i.value,y=f[0],v=f[1],m=void 0,C=Infinity,P=R(y[0],y[1]),I=R(v[0],v[1]),S=R(t[0],t[1]);if(y[0]===t[0]&&y[1]===t[1])m=y;else if(v[0]===t[0]&&v[1]===t[1])m=v;else{var F=(u=(d={x:(s=S).x-(o=P).x,y:s.y-o.y}).x*(a={x:(r=I).x-o.x,y:r.y-o.y}).x+d.y*a.y,h=Math.max(0,Math.min(1,u/(a.x*a.x+a.y*a.y))),{x:o.x+h*a.x,y:o.y+h*a.y}),x=U(F.x,F.y);m=[x.lng,x.lat]}m&&(C=at(S,R(m[0],m[1])))<c&&(l=m,c=C,p=e.indexOf(f))}return Infinity===c?void 0:{coordinate:l,lineIndex:p,distance:c}}(u,a):"globe"===i.config.projection&&(r=function(t,e){for(var i,o=[Infinity,Infinity],r=Infinity,s=0,a=n(e);!(i=a()).done;){var d,u=i.value,h=u[0],l=u[1],c=Infinity;(d=h[0]===t[0]&&h[1]===t[1]?h:l[0]===t[0]&&l[1]===t[1]?l:(p=h,g=l,f=t,M=Dt(p),O=Dt(g),E=Dt(f),D=E[0],k=E[1],b=E[2],_=[(C=(y=M)[1])*(F=(v=O)[2])-(P=y[2])*(S=v[1]),P*(I=v[0])-(m=y[0])*F,m*S-C*I],T=_[0],N=_[1],R=_[2],U=N*b-R*k,W=R*D-T*b,L=T*k-N*D,A=L*N-W*R,B=U*R-L*T,z=W*T-U*N,H=1/Math.sqrt(Math.pow(A,2)+Math.pow(B,2)+Math.pow(z,2)),G=[A*H,B*H,z*H],V=[-1*A*H,-1*B*H,-1*z*H],j=Et(M,O),K=Et(M,G),Y=Et(O,G),X=Et(M,V),q=Et(O,V),Et(M,x=K<X&&K<q||Y<X&&Y<q?G:V)>j||Et(O,x)>j?w(kt(x),kt(M))<=w(kt(x),kt(O))?[kt(M),!0,!1]:[kt(O),!1,!0]:[kt(x),!1,!1])[0])&&(c=w(t,d))<r&&(o=d,r=c,s=e.indexOf(u))}var p,g,f,y,v,m,C,P,I,S,F,x,M,O,E,D,k,b,_,T,N,R,U,W,L,A,B,z,H,G,V,j,K,Y,X,q;return Infinity===r?void 0:{coordinate:o,distance:r,lineIndex:s}}(u,a)),r){var h=i.pixelDistance.measure(t,r.coordinate);h<s.minDistance&&h<i.pointerDistance&&(s.featureId=e.id,s.coordinate=[b(r.coordinate[0],i.config.coordinatePrecision),b(r.coordinate[1],i.config.coordinatePrecision)],s.featureCoordinateIndex=r.lineIndex,s.minDistance=h)}}),s},e}(Z);function _t(t){return Array.isArray(t)&&t.length>0&&Array.isArray(t[0])&&Array.isArray(t[0][0])}var Tt=function(t){return _t(t)?t[0].slice(0,-1):t},Nt=function(t){return _t(t)?t[0]:t},Rt=/*#__PURE__*/function(t){function e(e,i,n,o){var r;return(r=t.call(this,e)||this).config=void 0,r.pixelDistance=void 0,r.mutateFeatureBehavior=void 0,r.readFeatureBehavior=void 0,r._startEndPoints=[],r.config=e,r.pixelDistance=i,r.mutateFeatureBehavior=n,r.readFeatureBehavior=o,r}r(e,t);var n=e.prototype;return n.create=function(t){if(this.ids.length)throw new Error("Opening and closing points already created");var e=_t(t),i=Nt(t);if(e){if(i.length<=3)throw new Error("Requires at least 4 coordinates");this._startEndPoints=this.mutateFeatureBehavior.createGuidancePoints({coordinates:[i[0],i[i.length-2]],type:f.CLOSING_POINT})}else this._startEndPoints=[this.mutateFeatureBehavior.createGuidancePoint({coordinate:i[i.length-2],type:f.CLOSING_POINT})]},n.delete=function(){this.ids.length&&(this.mutateFeatureBehavior.deleteFeaturesIfPresent(this.ids),this._startEndPoints=[])},n.updateOne=function(t,e){this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[t],coordinate:e}])},n.update=function(t){var e=Nt(t);1!==this.ids.length?2===this.ids.length&&this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[0]},{featureId:this.ids[1],coordinate:e[e.length-3]}]):this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:e[e.length-2]}])},n.isLineStringClosingPoint=function(t){if(1!==this.ids.length)return{isClosing:!1};var e=this.readFeatureBehavior.getGeometry(this.ids[0]);return{isClosing:this.pixelDistance.measure(t,e.coordinates)<this.pointerDistance}},n.isPolygonClosingPoints=function(t){if(2!==this.ids.length)return{isClosing:!1,isPreviousClosing:!1};var e=this.readFeatureBehavior.getGeometry(this.ids[0]),i=this.readFeatureBehavior.getGeometry(this.ids[1]),n=this.pixelDistance.measure(t,e.coordinates),o=this.pixelDistance.measure(t,i.coordinates);return{isClosing:n<this.pointerDistance,isPreviousClosing:o<this.pointerDistance}},i(e,[{key:"ids",get:function(){return this._startEndPoints.concat()},set:function(t){}}])}(Z),Ut=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).readFeature=void 0,o.mutateFeature=void 0,o.readFeature=i,o.mutateFeature=n,o}r(e,t);var i=e.prototype;return i.createOrUpdate=function(t){var e=this,i=t.featureId,n=t.featureCoordinates;if(this.readFeature.hasFeature(i)){var o=Tt(n),r=this.readFeature.getProperties(i),s=r.coordinatePointIds;if(s)if(s&&s.every(function(t){return e.readFeature.hasFeature(t)})){var a=r.coordinatePointIds,d=a.map(function(t){return e.readFeature.getGeometry(t).coordinates});if(a.length!==o.length){this.deleteCoordinatePoints(a);var u=this.createPoints(o,r.mode,i);this.setFeatureCoordinatePoints(i,u)}else{var h=[];o.forEach(function(t,e){t[0]===d[e][0]&&t[1]===d[e][1]||h.push({featureId:a[e],coordinate:t})}),this.mutateFeature.updateGuidancePoints(h)}}else{var l=s.filter(function(t){return e.readFeature.hasFeature(t)});l.length&&this.deleteCoordinatePoints(l);var c=this.createPoints(o,r.mode,i);this.setFeatureCoordinatePoints(i,c)}else{var p=this.createPoints(o,r.mode,i);this.setFeatureCoordinatePoints(i,p)}}else this.deleteOrphanedPoints(i)},i.deletePointsByFeatureIds=function(t){for(var e,i=n(t);!(e=i()).done;)this.deleteIfPresent(e.value)},i.updateOneAtIndex=function(t,e,i){var n=this.readFeature.getProperties(t).coordinatePointIds;n&&0!==n.length&&void 0!==n[e]&&this.mutateFeature.updateGuidancePoints([{featureId:n[e],coordinate:i}])},i.updateAllInPlace=function(t){var e=t.featureCoordinates,i=this.readFeature.getProperties(t.featureId);if(i.coordinatePointIds){var n=Tt(e);n.length===i.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(i.coordinatePointIds.map(function(t,e){return{featureId:t,coordinate:n[e]}}))}},i.createPoints=function(t,e,i){return this.mutateFeature.createGuidancePoints({coordinates:t,type:f.COORDINATE_POINT,additionalProperties:function(t){var n;return(n={mode:e})[f.COORDINATE_POINT]=!0,n[f.COORDINATE_POINT_FEATURE_ID]=i,n.index=t,n}})},i.setFeatureCoordinatePoints=function(t,e,i){var n;void 0===i&&(i=d.Commit);var o=this.readFeature.getGeometryType(t),r={featureId:t,propertyMutations:(n={},n[f.COORDINATE_POINT_IDS]=e,n),context:{updateType:i}};if("Polygon"===o)this.mutateFeature.updatePolygon(r);else{if("LineString"!==o)throw new Error("Unsupported geometry type for coordinate points");this.mutateFeature.updateLineString(r)}},i.deleteCoordinatePoints=function(t){this.mutateFeature.deleteFeaturesIfPresent(t)},i.deleteIfPresent=function(t){if(this.readFeature.hasFeature(t)){var e=this.readFeature.getProperties(t).coordinatePointIds;e&&(this.deleteCoordinatePoints(e),this.setFeatureCoordinatePoints(t,null))}},i.deleteOrphanedPoints=function(t){var e=this.readFeature.getAllFeatureIdsWhere(function(e){return e[f.COORDINATE_POINT_FEATURE_ID]===t});this.mutateFeature.deleteFeaturesIfPresent(e)},e}(Z),Wt=/*#__PURE__*/function(){function t(t){var e=this;this.undoHistory=[],this.redoHistory=[],this.cloneCoordinatesFunction=void 0,this.maxStackSize=void 0,this.cloneCoordinatesFunction=function(t){return e.cloneRecursively(t)};var i=null==t?void 0:t.maxStackSize;this.maxStackSize=void 0!==i&&Number.isFinite(i)?Math.max(0,Math.floor(i)):Number.POSITIVE_INFINITY}var e=t.prototype;return e.setMaxStackSize=function(t){Number.isFinite(t)?(this.maxStackSize=Math.max(0,Math.floor(t)),this.trimHistoryToMax(this.undoHistory),this.trimHistoryToMax(this.redoHistory)):this.maxStackSize=Number.POSITIVE_INFINITY},e.trimHistoryToMax=function(t){if(Number.isFinite(this.maxStackSize))for(;t.length>this.maxStackSize;)t.shift()},e.pushUndoEntry=function(t){0!==this.maxStackSize&&(this.undoHistory.push(t),this.trimHistoryToMax(this.undoHistory))},e.pushRedoEntry=function(t){0!==this.maxStackSize&&(this.redoHistory.push(t),this.trimHistoryToMax(this.redoHistory))},e.cloneRecursively=function(t){var e=this;return Array.isArray(t)?t.map(function(t){return e.cloneRecursively(t)}):null!==t&&"object"==typeof t?o({},t):t},e.cloneCoordinates=function(t){return this.cloneCoordinatesFunction(t)},e.cloneEntry=function(t){return{featureCoordinates:this.cloneCoordinates(t.featureCoordinates),currentCoordinate:t.currentCoordinate}},e.clear=function(){this.undoHistory=[],this.redoHistory=[]},e.undoSize=function(){return this.undoHistory.length},e.redoSize=function(){return this.redoHistory.length},e.recordSnapshot=function(t){this.pushUndoEntry(this.cloneEntry(t)),this.redoHistory=[]},e.beginUndo=function(){var t=this.undoHistory.pop();if(t){var e=this.cloneEntry(t);this.pushRedoEntry(e);var i=this.undoHistory[this.undoHistory.length-1];return{undoneEntry:e,previousEntry:i?this.cloneEntry(i):void 0}}},e.takeRedo=function(){var t=this.redoHistory.pop();if(t)return this.cloneEntry(t)},e.commitRedo=function(t){this.pushUndoEntry(this.cloneEntry(t))},t}(),Lt={cancel:"Escape",finish:"Enter"},At={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},Bt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="linestring",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Lt,i.snapping=void 0,i.cursors=At,i.mouseMove=!1,i.insertCoordinates=void 0,i.lastCommittedCoordinates=void 0,i.snappedPointId=void 0,i.lastMouseMoveEvent=void 0,i.showCoordinatePoints=!1,i.finishOnNthCoordinate=void 0,i.editable=!1,i.editedFeatureId=void 0,i.editedFeatureCoordinateIndex=void 0,i.editedSnapType=void 0,i.editedInsertIndex=void 0,i.editedPointId=void 0,i.coordinateSnapping=void 0,i.insertPoint=void 0,i.lineSnapping=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.mutateFeature=void 0,i.readFeature=void 0,i.closingPoints=void 0,i.coordinatePoints=void 0,i.undoRedo=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i=this;if(t.prototype.updateOptions.call(this,e),void 0!==(null==e?void 0:e.finishOnNthCoordinate)&&Number.isInteger(e.finishOnNthCoordinate)&&e.finishOnNthCoordinate>1&&(this.finishOnNthCoordinate=Math.floor(e.finishOnNthCoordinate)),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null!=e&&e.snapping&&(this.snapping=e.snapping),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.insertCoordinates&&(this.insertCoordinates=e.insertCoordinates),e&&e.editable&&(this.editable=e.editable),void 0!==(null==e?void 0:e.showCoordinatePoints))if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(function(t){return t.mode===i.mode}).forEach(function(t){i.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){var n=this.store.copyAllWhere(function(t){var e;return t.mode===i.mode&&Boolean(null==(e=t[f.COORDINATE_POINT_IDS])?void 0:e.length)});this.coordinatePoints.deletePointsByFeatureIds(n.map(function(t){return t.id}))}},i.shouldFinishOnCommit=function(t){return!!this.finishOnNthCoordinate&&Math.max(0,t.coordinates.length-1)>=this.finishOnNthCoordinate},i.updateSnappedCoordinate=function(t){var e=this.snapCoordinate(t);return e?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:e}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:e,type:f.SNAPPING_POINT}),t.lng=e[0],t.lat=e[1]):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),e},i.close=function(){var t;if(void 0!==this.currentId){var e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Finish,action:u},coordinateMutations:[{type:et,index:-1}],propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t)});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});var i=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted(),this.closingPoints.delete(),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.onFinish(i,{mode:this.mode,action:u})}}},i.generateInsertCoordinates=function(t,e){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw new Error("Not able to insert coordinates");if("amount"!==this.insertCoordinates.strategy)throw new Error("Strategy does not exist");var i=w(t,e)/(this.insertCoordinates.value+1),n=[];return"globe"===this.projection?n=this.insertPoint.generateInsertionGeodesicCoordinates(t,e,i):"web-mercator"===this.projection&&(n=this.insertPoint.generateInsertionCoordinates(t,e,i)),n},i.createLine=function(t){var e,i=this.mutateFeature.createLineString({coordinates:[t,t],properties:(e={mode:this.mode},e[f.CURRENTLY_DRAWING]=!0,e)});this.lastCommittedCoordinates=i.geometry.coordinates,this.currentId=i.id,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing(),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})},i.firstUpdateToLine=function(t){if(this.currentId){this.setCursor(this.cursors.close);var e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Commit},coordinateMutations:[{type:Q,index:-1,coordinate:t}]});e&&(this.closingPoints.create(e.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),this.lastCommittedCoordinates=e.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(e.geometry)&&this.close())}},i.updateToLine=function(t,e){if(this.currentId)if(this.closingPoints.isLineStringClosingPoint(t).isClosing)this.close();else{this.setCursor(this.cursors.close);var i=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:d.Commit},coordinateMutations:[{type:Q,index:-1,coordinate:e}]});i&&(this.closingPoints.update(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates}),this.lastCommittedCoordinates=i.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(i.geometry)&&this.close())}},i.undoSize=function(){return this.undoRedo.undoSize()},i.clearHistory=function(){this.undoRedo.clear()},i.pushHistorySnapshot=function(t,e){var i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})},i.updateSnappedGuidancePointFromLastMouseMove=function(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.syncClosingPoints=function(t){this.currentCoordinate>=2?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()},i.undo=function(){var t;if("drawing"===this.state&&this.currentId){var e=this.undoRedo.beginUndo();if(e){var i=e.previousEntry;if(!i){var n=this.currentId;return this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([n]),this.mutateFeature.deleteFeatureIfPresent(n),void this.updateSnappedGuidancePointFromLastMouseMove()}var o=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:it,coordinates:i.featureCoordinates},propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=!0,t),context:{updateType:d.Commit}});o&&(this.currentCoordinate=i.currentCoordinate,this.lastCommittedCoordinates=o.geometry.coordinates,this.syncClosingPoints(o.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}}},i.redoSize=function(){return this.undoRedo.redoSize()},i.redo=function(){var t=this.undoRedo.takeRedo();if(t){if(this.currentId){var e,i=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:it,coordinates:t.featureCoordinates},propertyMutations:(e={},e[f.CURRENTLY_DRAWING]=!0,e),context:{updateType:d.Commit}});if(!i)return;this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=i.geometry.coordinates,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}else{var n,o=this.mutateFeature.createLineString({coordinates:t.featureCoordinates,properties:(n={mode:this.mode},n[f.CURRENTLY_DRAWING]=!0,n)}),r=o.id,s=o.geometry;this.currentId=r,this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=s.coordinates,"started"===this.state&&this.setDrawing(),this.syncClosingPoints(s.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:r,featureCoordinates:s.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}},i.registerBehaviors=function(t){this.insertPoint=new Mt(t),this.clickBoundingBox=new gt(t),this.pixelDistance=new ft(t),this.lineSnapping=new bt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new yt(t,this.pixelDistance,this.clickBoundingBox),this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate}),this.closingPoints=new Rt(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Ut(t,this.readFeature,this.mutateFeature),this.undoRedo=new Wt({maxStackSize:t.undoRedoMaxStackSize})},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t;var e=this.updateSnappedCoordinate(t)||[t.lng,t.lat];if(void 0!==this.currentId&&0!==this.currentCoordinate){this.closingPoints.isLineStringClosingPoint(t).isClosing&&this.setCursor(this.cursors.close);var i=[{type:tt,index:-1,coordinate:e}];if(this.insertCoordinates){var n=this.getInsertCoordinates(e);n&&(i={type:it,coordinates:n})}var o=this.mutateFeature.updateLineString({coordinateMutations:i,featureId:this.currentId,context:{updateType:d.Provisional}});o&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates})}},i.getInsertCoordinates=function(t){if(this.lastCommittedCoordinates){var e=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1];if(!dt(e,t)){var i=this.generateInsertCoordinates(e,t),n=this.lastCommittedCoordinates.slice(0,-1);return[].concat(n,i,[t])}}},i.onRightClick=function(t){var e=this;if(this.editable&&"started"===this.state){var i=this.coordinateSnapping.getSnappable(t,function(t){return e.lineStringFilter(t)}),n=i.featureId,o=i.featureCoordinateIndex;if(n&&void 0!==o){var r=this.readFeature.getGeometry(n);if("LineString"===r.type&&!(r.coordinates.length<=2)){var s=this.mutateFeature.updateLineString({featureId:n,coordinateMutations:[{type:et,index:o}],context:{updateType:d.Finish,action:h}});s&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n,featureCoordinates:s.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(n,{mode:this.mode,action:l})}}}},i.onLeftClick=function(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);var e=this.snapCoordinate(t)||[t.lng,t.lat];0===this.currentCoordinate?this.createLine(e):1===this.currentCoordinate&&this.currentId?this.firstUpdateToLine(e):this.currentId&&this.updateToLine(t,e)},i.onClick=function(t){void 0===this.currentId||this.readFeature.hasFeature(this.currentId)||this.cleanUp(),("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,"right"===t.button?this.onRightClick(t):"left"===t.button&&this.onLeftClick(t))},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel&&this.cleanUp(),t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(t,e){var i=this;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){var n=void 0;if("started"===this.state){var o=this.lineSnapping.getSnappable(t,function(t){return i.lineStringFilter(t)});o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,n=o.coordinate);var r=this.coordinateSnapping.getSnappable(t,function(t){return i.lineStringFilter(t)});r.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:n,type:f.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&void 0!==this.editedFeatureCoordinateIndex){if("coordinate"===this.editedSnapType||"line"===this.editedSnapType&&void 0!==this.editedInsertIndex){var n=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:d.Provisional},coordinateMutations:[{type:tt,index:this.editedFeatureCoordinateIndex,coordinate:[t.lng,t.lat]}]});if(!n)return;this.showCoordinatePoints&&(void 0!==this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:n.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,[t.lng,t.lat]))}else if("line"===this.editedSnapType&&void 0===this.editedInsertIndex){this.editedInsertIndex=this.editedFeatureCoordinateIndex+1;var o=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:d.Provisional}});if(!o)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:o.geometry.coordinates}),this.editedFeatureCoordinateIndex++}this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:[t.lng,t.lat]}]),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:d.Provisional},propertyMutations:(i={},i[f.EDITED]=!0,i)})}},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&(this.setCursor(this.cursors.dragEnd),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,propertyMutations:(i={},i[f.EDITED]=!1,i),context:{updateType:d.Finish,action:h}}))){var n=this.editedFeatureId;e(!0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0),this.closingPoints.delete(),this.onFinish(n,{mode:this.mode,action:h})}},i.cleanUp=function(){var t=this.currentId,e=this.snappedPointId;this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted(),t&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.delete()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if("Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode)return e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,void 0===e.lineStringOpacity?1:e.lineStringOpacity,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=y,e;if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=t.properties[f.COORDINATE_POINT],n=t.properties[f.CLOSING_POINT]?"closingPoint":t.properties[f.SNAPPING_POINT]?"snappingPoint":i?"coordinatePoint":void 0;if(!n)return e;var r={closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return e.pointWidth=this.getNumericStylingValue(r[n].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(r[n].opacity,1,t),e.pointColor=this.getHexColorStylingValue(r[n].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(r[n].outlineColor,"#ffffff",t),e.pointOutlineWidth=this.getNumericStylingValue(r[n].outlineWidth,2,t),e.pointOutlineOpacity=this.getNumericStylingValue(r[n].outlineOpacity,1,t),e.zIndex=i?20:50,e}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return wt(t,e.coordinatePrecision)})},i.lineStringFilter=function(t){return Boolean("LineString"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)},i.snapCoordinate=function(t){var e,i,n,o,r,s,a=this;if(null!=(e=this.snapping)&&e.toLine&&(r=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(o=r),null!=(i=this.snapping)&&i.toCoordinate&&(s=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(o=s),null!=(n=this.snapping)&&n.toCustom){var d=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?function(){return a.readFeature.getGeometry(a.currentId)}:function(){return null},project:this.project,unproject:this.unproject});d&&(o=d)}return o},i.afterFeatureUpdated=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.editedFeatureId===t.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.closingPoints.delete(),this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted())},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},e}(x),zt="Feature is not a Point",Ht="Feature has invalid coordinates",Gt="Feature has coordinates with excessive precision";function Vt(t,e){return"Point"!==t.geometry.type?{valid:!1,reason:zt}:H(t.geometry.coordinates)?z(t.geometry.coordinates,e)?{valid:!0}:{valid:!1,reason:Gt}:{valid:!1,reason:Ht}}var jt=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).pixelDistance=void 0,o.clickBoundingBox=void 0,o.pixelDistance=i,o.clickBoundingBox=n,o}return r(e,t),e.prototype.getNearestPointFeature=function(t){for(var e=this.clickBoundingBox.create(t),i=this.store.search(e),n=Infinity,o=void 0,r=0;r<i.length;r++){var s=i[r];if("Point"===s.geometry.type&&s.properties.mode===this.mode){var a=this.pixelDistance.measure(t,s.geometry.coordinates);a>n||a>this.pointerDistance||(n=a,o=s)}}return o},e}(Z),Kt={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},Yt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="point",i.cursors=Kt,i.editable=!1,i.editedFeatureId=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.pointSearch=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null!=e&&e.editable&&(this.editable=e.editable)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.create)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.onMouseMove=function(){},i.onKeyDown=function(){},i.onKeyUp=function(){},i.cleanUp=function(){this.editedFeatureId=void 0},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){if(this.editable){var i=this.pointSearch.getNearestPointFeature(t);this.editedFeatureId=null==i?void 0:i.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:it,coordinates:[t.lng,t.lat]},propertyMutations:(i={},i[f.EDITED]=!0,i),context:{updateType:d.Provisional}})},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:(i={mode:this.mode},i[f.EDITED]=!1,i),context:{updateType:d.Finish,action:"edit"}})){var n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,e(!0),this.onFinish(n,{mode:this.mode,action:u})}},i.registerBehaviors=function(t){this.pixelDistance=new ft(t),this.clickBoundingBox=new gt(t),this.pointSearch=new jt(t,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new nt(t,{validate:this.validate})},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if("Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode){var i=Boolean(t.id&&this.editedFeatureId===t.id);e.pointWidth=this.getNumericStylingValue(i?this.styles.editedPointWidth:this.styles.pointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(this.styles.pointOpacity,void 0===e.pointOpacity?1:e.pointOpacity,t),e.pointColor=this.getHexColorStylingValue(i?this.styles.editedPointColor:this.styles.pointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(i?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.pointOutlineOpacity,void 0===e.pointOutlineOpacity?1:e.pointOutlineOpacity,t),e.pointOutlineWidth=this.getNumericStylingValue(i?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,t),e.zIndex=30}return e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Vt(t,e.coordinatePrecision)})},i.onLeftClick=function(t){var e=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:{mode:this.mode},context:{updateType:d.Finish,action:u}});e&&this.onFinish(e.id,{mode:this.mode,action:u})},i.onRightClick=function(t){if(this.editable){var e=this.pointSearch.getNearestPointFeature(t);e&&this.mutateFeature.deleteFeatureIfPresent(e.id)}},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))},e}(x),Xt={cancel:"Escape",finish:"Enter"},qt={start:"crosshair",close:"pointer",dragStart:"grabbing",dragEnd:"crosshair"},Zt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="polygon",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Xt,i.cursors=qt,i.mouseMove=!1,i.showCoordinatePoints=!1,i.lastMouseMoveEvent=void 0,i.snapping=void 0,i.snappedPointId=void 0,i.editable=!1,i.editedFeatureId=void 0,i.editedFeatureCoordinateIndex=void 0,i.editedSnapType=void 0,i.editedInsertIndex=void 0,i.editedPointId=void 0,i.coordinatePoints=void 0,i.lineSnapping=void 0,i.coordinateSnapping=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.clickBoundingBox=void 0,i.mutateFeature=void 0,i.readFeature=void 0,i.undoRedo=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){var i=this;if(t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.snapping&&(this.snapping=e.snapping),void 0!==(null==e?void 0:e.editable)&&(this.editable=e.editable),void 0!==(null==e?void 0:e.pointerEvents)&&(this.pointerEvents=e.pointerEvents),void 0!==(null==e?void 0:e.showCoordinatePoints))if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(function(t){return t.mode===i.mode}).filter(function(t){return"Polygon"===t.geometry.type}).forEach(function(t){i.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){var n=this.store.copyAllWhere(function(t){return t.mode===i.mode&&Boolean(t[f.COORDINATE_POINT_IDS])}).filter(function(t){return"Polygon"===t.geometry.type});this.coordinatePoints.deletePointsByFeatureIds(n.map(function(t){return t.id}))}},i.close=function(){var t;if(void 0!==this.currentId&&!(this.readFeature.getCoordinates(this.currentId).length<5)){var e=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:et,index:-2}],propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t[f.COMMITTED_COORDINATE_COUNT]=void 0,t[f.PROVISIONAL_COORDINATE_COUNT]=void 0,t),context:{updateType:d.Finish,action:u}});if(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates}),"drawing"===this.state&&this.setStarted(),this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.closingPoints.delete();var i=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.onFinish(i,{mode:this.mode,action:u})}}},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate}),this.clickBoundingBox=new gt(t),this.pixelDistance=new ft(t),this.lineSnapping=new bt(t,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new yt(t,this.pixelDistance,this.clickBoundingBox),this.closingPoints=new Rt(t,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Ut(t,this.readFeature,this.mutateFeature),this.undoRedo=new Wt({maxStackSize:t.undoRedoMaxStackSize})},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.updateSnappedCoordinate=function(t){var e=this.snapCoordinate(t);e?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:e}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:e,type:f.SNAPPING_POINT}),t.lng=e[0],t.lat=e[1]):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.undoSize=function(){return this.undoRedo.undoSize()},i.clearHistory=function(){this.undoRedo.clear()},i.pushHistorySnapshot=function(t,e){var i=this.readFeature.getGeometry(t);this.undoRedo.recordSnapshot({featureCoordinates:i.coordinates,currentCoordinate:e})},i.updateSnappedGuidancePointFromLastMouseMove=function(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0)},i.syncClosingPoints=function(t){this.currentCoordinate>=3?this.closingPoints.ids.length?this.closingPoints.update(t):this.closingPoints.create(t):this.closingPoints.delete()},i.undo=function(){var t;if("drawing"===this.state&&this.currentId){var e=this.undoRedo.beginUndo();if(e){var i=e.previousEntry;if(!i){var n=this.currentId;return this.currentId=void 0,this.currentCoordinate=0,this.closingPoints.delete(),"drawing"===this.state&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([n]),this.mutateFeature.deleteFeatureIfPresent(n),void this.updateSnappedGuidancePointFromLastMouseMove()}var o=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:it,coordinates:i.featureCoordinates},propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=!0,t[f.COMMITTED_COORDINATE_COUNT]=i.currentCoordinate,t[f.PROVISIONAL_COORDINATE_COUNT]=i.currentCoordinate,t),context:{updateType:d.Commit}});o&&(this.currentCoordinate=i.currentCoordinate,this.syncClosingPoints(o.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:o.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}}},i.redoSize=function(){return this.undoRedo.redoSize()},i.redo=function(){var t=this.undoRedo.takeRedo();if(t){if(this.currentId){var e,i=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:it,coordinates:t.featureCoordinates},propertyMutations:(e={},e[f.CURRENTLY_DRAWING]=!0,e[f.COMMITTED_COORDINATE_COUNT]=t.currentCoordinate,e[f.PROVISIONAL_COORDINATE_COUNT]=t.currentCoordinate,e),context:{updateType:d.Commit}});if(!i)return;this.currentCoordinate=t.currentCoordinate,this.syncClosingPoints(i.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}else{var n,o=this.undoRedo.cloneCoordinates(t.featureCoordinates)[0],r=this.mutateFeature.createPolygon({coordinates:o,properties:(n={mode:this.mode},n[f.CURRENTLY_DRAWING]=!0,n[f.COMMITTED_COORDINATE_COUNT]=t.currentCoordinate,n[f.PROVISIONAL_COORDINATE_COUNT]=t.currentCoordinate,n)}),s=r.id,a=r.geometry;this.currentId=s,this.currentCoordinate=t.currentCoordinate,"started"===this.state&&this.setDrawing(),this.syncClosingPoints(a.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:s,featureCoordinates:a.coordinates})}this.undoRedo.commitRedo(t),this.updateSnappedGuidancePointFromLastMouseMove()}},i.onMouseMove=function(t){var e;if(this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=t,this.updateSnappedCoordinate(t),void 0!==this.currentId&&0!==this.currentCoordinate){var i,n=this.readFeature.getCoordinate(this.currentId,0),o=[t.lng,t.lat];if(1===this.currentCoordinate)i=[{type:tt,index:1,coordinate:o},{type:tt,index:2,coordinate:[t.lng,t.lat]}];else if(2===this.currentCoordinate)i=[{type:tt,index:2,coordinate:o}];else{var r=this.closingPoints.isPolygonClosingPoints(t);r.isPreviousClosing||r.isClosing?(this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.setCursor(this.cursors.close),i=[{type:tt,index:-1,coordinate:n},{type:tt,index:-2,coordinate:n}]):i=[{type:tt,index:-2,coordinate:o},{type:tt,index:-1,coordinate:n}]}var s=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:i,propertyMutations:(e={},e[f.PROVISIONAL_COORDINATE_COUNT]=this.currentCoordinate+1,e),context:{updateType:d.Provisional}});s&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:s.geometry.coordinates})}},i.snapCoordinate=function(t){var e,i,n,o,r,s=this,a=void 0;if(null!=(e=this.snapping)&&e.toLine&&(o=this.currentId?this.lineSnapping.getSnappableCoordinate(t,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(t))&&(a=o),null!=(i=this.snapping)&&i.toCoordinate&&(r=this.currentId?this.coordinateSnapping.getSnappableCoordinate(t,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(t))&&(a=r),null!=(n=this.snapping)&&n.toCustom){var d=this.snapping.toCustom(t,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?function(){return s.readFeature.getGeometry(s.currentId)}:function(){return null},project:this.project,unproject:this.unproject});d&&(a=d)}return a},i.polygonFilter=function(t){return Boolean("Polygon"===t.geometry.type&&t.properties&&t.properties.mode===this.mode)},i.onRightClick=function(t){var e=this;if(this.editable&&"started"===this.state){var i=this.coordinateSnapping.getSnappable(t,function(t){return e.polygonFilter(t)}),n=i.featureId,o=i.featureCoordinateIndex;if(n&&void 0!==o){var r=this.readFeature.getGeometry(n);if("Polygon"===r.type){var s=r.coordinates[0];if(!(s.length<=4)){var a=this.mutateFeature.updatePolygon({featureId:n,coordinateMutations:0===o||o===s.length-1?[{type:et,index:0},{type:et,index:-1},{type:Q,index:-1,coordinate:s[1]}]:[{type:et,index:o}],context:{updateType:d.Finish,action:h}});if(a){if(this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:n,featureCoordinates:a.geometry.coordinates}),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0,this.snapping)){var u=this.snapCoordinate(t);if(u){var l=this.mutateFeature.createGuidancePoints({type:f.SNAPPING_POINT,coordinates:[u]});this.snappedPointId=l[0]}}this.onFinish(n,{mode:this.mode,action:h})}}}}}},i.onLeftClick=function(t){this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0);var e=this.snapCoordinate(t)||[t.lng,t.lat];if(0===this.currentCoordinate){var i,n=this.mutateFeature.createPolygon({coordinates:[e,e,e,e],properties:(i={mode:this.mode},i[f.CURRENTLY_DRAWING]=!0,i[f.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,i[f.PROVISIONAL_COORDINATE_COUNT]=this.currentCoordinate+1,i)}),o=n.id;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:o,featureCoordinates:n.geometry.coordinates}),this.currentId=o,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var r;if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:0}))return;var s=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:tt,index:1,coordinate:e},{type:tt,index:2,coordinate:e}],propertyMutations:(r={},r[f.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,r),context:{updateType:d.Commit}});if(!s)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:s.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(2===this.currentCoordinate&&this.currentId){var a;if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:1}))return;var u=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:tt,index:2,coordinate:e},{type:Q,index:2,coordinate:e}],propertyMutations:(a={},a[f.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,a),context:{updateType:d.Commit}});if(!u)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:u.geometry.coordinates}),2===this.currentCoordinate&&this.closingPoints.create(u.geometry.coordinates),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate)}else if(this.currentId){var h=this.closingPoints.isPolygonClosingPoints(t);if(h.isPreviousClosing||h.isClosing)this.close();else{var l;if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,newCoordinate:e,index:this.currentCoordinate-1}))return;var c=this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:$,index:-1,coordinate:e}],propertyMutations:(l={},l[f.COMMITTED_COORDINATE_COUNT]=this.currentCoordinate+1,l),context:{updateType:d.Commit}});if(!c)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:c.geometry.coordinates}),this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.closingPoints.ids.length&&this.closingPoints.update(c.geometry.coordinates)}}},i.onClick=function(t){this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(t,e){var i=this;if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.editable){var n=void 0;if("started"===this.state){var o=this.lineSnapping.getSnappable(t,function(t){return i.polygonFilter(t)});o.coordinate&&(this.editedSnapType="line",this.editedFeatureCoordinateIndex=o.featureCoordinateIndex,this.editedFeatureId=o.featureId,n=o.coordinate);var r=this.coordinateSnapping.getSnappable(t,function(t){return i.polygonFilter(t)});r.coordinate&&(this.editedSnapType="coordinate",this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||(this.editedPointId=this.mutateFeature.createGuidancePoint({coordinate:n,type:f.EDITED})),this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&void 0!==this.editedFeatureCoordinateIndex){var n=this.readFeature.getGeometry(this.editedFeatureId),o=[t.lng,t.lat],r=[];if("coordinate"===this.editedSnapType||"line"===this.editedSnapType&&void 0!==this.editedInsertIndex?r=0===this.editedFeatureCoordinateIndex||this.editedFeatureCoordinateIndex===n.coordinates[0].length-1?[{type:tt,index:0,coordinate:o},{type:tt,index:-1,coordinate:o}]:[{type:tt,index:this.editedFeatureCoordinateIndex,coordinate:o}]:"line"===this.editedSnapType&&void 0===this.editedInsertIndex&&(this.editedInsertIndex=this.editedFeatureCoordinateIndex+1,r=[{type:$,index:this.editedInsertIndex,coordinate:o}],this.editedFeatureCoordinateIndex++),0!==r.length){var s=this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,coordinateMutations:r,propertyMutations:(i={},i[f.EDITED]=!0,i),context:{updateType:d.Provisional}});s&&(this.showCoordinatePoints&&(this.editedInsertIndex?this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:s.geometry.coordinates}):this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,s.geometry.coordinates[0][this.editedFeatureCoordinateIndex])),this.snapping&&this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedPointId&&this.mutateFeature.updateGuidancePoints([{featureId:this.editedPointId,coordinate:o}]))}}},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&(this.setCursor(this.cursors.dragEnd),this.mutateFeature.updatePolygon({featureId:this.editedFeatureId,propertyMutations:(i={},i[f.EDITED]=!1,i),context:{updateType:d.Finish,action:h}}))){var n=this.editedFeatureId;this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0),this.snappedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),this.snappedPointId=void 0),this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,e(!0),this.onFinish(n,{mode:this.mode,action:h})}},i.cleanUp=function(){var t=this.currentId,e=this.snappedPointId,i=this.editedPointId;this.currentId=void 0,this.snappedPointId=void 0,this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedInsertIndex=void 0,this.editedSnapType=void 0,this.currentCoordinate=0,this.undoRedo.clear(),"drawing"===this.state&&this.setStarted(),t&&this.coordinatePoints.deletePointsByFeatureIds([t]),this.mutateFeature.deleteFeatureIfPresent(t),this.mutateFeature.deleteFeatureIfPresent(i),this.mutateFeature.deleteFeatureIfPresent(e),this.closingPoints.ids.length&&this.closingPoints.delete()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(t.properties.mode===this.mode){if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.zIndex=y,e;if("Point"===t.geometry.type){var i=t.properties[f.EDITED],n=t.properties[f.COORDINATE_POINT],r=i?"editedPoint":t.properties[f.CLOSING_POINT]?"closingPoint":t.properties[f.SNAPPING_POINT]?"snappingPoint":n?"coordinatePoint":void 0;if(!r)return e;var s={editedPoint:{width:this.styles.editedPointOutlineWidth,color:this.styles.editedPointColor,opacity:this.styles.editedPointOpacity,outlineColor:this.styles.editedPointOutlineColor,outlineWidth:this.styles.editedPointOutlineWidth,outlineOpacity:this.styles.editedPointOutlineOpacity},closingPoint:{width:this.styles.closingPointWidth,color:this.styles.closingPointColor,opacity:this.styles.closingPointOpacity,outlineColor:this.styles.closingPointOutlineColor,outlineWidth:this.styles.closingPointOutlineWidth,outlineOpacity:this.styles.closingPointOutlineOpacity},snappingPoint:{width:this.styles.snappingPointWidth,color:this.styles.snappingPointColor,opacity:this.styles.snappingPointOpacity,outlineColor:this.styles.snappingPointOutlineColor,outlineWidth:this.styles.snappingPointOutlineWidth,outlineOpacity:this.styles.snappingPointOutlineOpacity},coordinatePoint:{width:this.styles.coordinatePointWidth,color:this.styles.coordinatePointColor,opacity:this.styles.coordinatePointOpacity,outlineColor:this.styles.coordinatePointOutlineColor,outlineWidth:this.styles.coordinatePointOutlineWidth,outlineOpacity:this.styles.coordinatePointOutlineOpacity}};return e.pointWidth=this.getNumericStylingValue(s[r].width,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(s[r].opacity,1,t),e.pointColor=this.getHexColorStylingValue(s[r].color,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(s[r].outlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(s[r].outlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(s[r].outlineWidth,2,t),e.zIndex=i?40:n?20:30,e}}return e},i.afterFeatureAdded=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates})},i.afterFeatureUpdated=function(t){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t.id,featureCoordinates:t.geometry.coordinates}),this.editedFeatureId===t.id&&this.editedPointId&&(this.mutateFeature.deleteFeatureIfPresent(this.editedPointId),this.editedPointId=void 0,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0),this.snappedPointId&&this.lastMouseMoveEvent&&this.updateSnappedCoordinate(this.lastMouseMoveEvent),this.currentId===t.id&&(this.currentCoordinate=0,this.currentId=void 0,this.undoRedo.clear(),this.closingPoints.delete(),"drawing"===this.state&&this.setStarted())},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return X(t,e.coordinatePrecision)})},e}(x),Jt={cancel:"Escape",finish:"Enter"},$t={start:"crosshair"},Qt=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="rectangle",i.startPosition=void 0,i.endPosition=void 0,i.currentRectangleId=void 0,i.keyEvents=Jt,i.cursors=$t,i.drawInteraction="click-move",i.drawType=void 0,i.mutateFeature=void 0,i.readFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.drawInteraction&&(this.drawInteraction=e.drawInteraction)},i.updateRectangle=function(t,e){var i;if(this.startPosition&&this.currentRectangleId){var n=e===d.Finish;return this.mutateFeature.updatePolygon({featureId:this.currentRectangleId,coordinateMutations:[{type:tt,index:1,coordinate:[t[0],this.startPosition[1]]},{type:tt,index:2,coordinate:t},{type:tt,index:3,coordinate:[this.startPosition[0],t[1]]}],propertyMutations:n?(i={},i[f.CURRENTLY_DRAWING]=void 0,i):{},context:n?{updateType:e,action:u}:{updateType:e}})}},i.close=function(){if(this.currentRectangleId&&this.endPosition&&this.updateRectangle(this.endPosition,d.Finish)){var t=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(t,{mode:this.mode,action:u})}},i.beginDrawing=function(t,e){var i;void 0===e&&(e="click"),this.startPosition=[t.lng,t.lat],this.endPosition=[t.lng,t.lat];var n=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(i={mode:this.mode},i[f.CURRENTLY_DRAWING]=!0,i)});this.currentRectangleId=n.id,this.drawType=e,this.setDrawing()},i.moveDrawAllowed=function(){return"click-move"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.dragDrawAllowed=function(){return"click-drag"===this.drawInteraction||"click-move-or-drag"===this.drawInteraction},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){this.moveDrawAllowed()&&("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))&&(this.startPosition?(this.endPosition=[t.lng,t.lat],this.close()):this.beginDrawing(t))},i.onMouseMove=function(t){this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,d.Provisional)},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onDragStart=function(t,e){"drawing"!==this.state&&this.allowPointerEvent(this.pointerEvents.onDragStart,t)&&this.dragDrawAllowed()&&(this.beginDrawing(t,"drag"),e(!1))},i.onDrag=function(t,e){this.allowPointerEvent(this.pointerEvents.onDrag,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.updateRectangle(this.endPosition,d.Provisional))},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&this.dragDrawAllowed()&&"drag"===this.drawType&&(this.endPosition=[t.lng,t.lat],this.close(),e(!0))},i.cleanUp=function(){var t=this.currentRectangleId;this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Polygon"===t.geometry.type&&t.properties.mode===this.mode?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentRectangleId===t.id&&(this.startPosition=void 0,this.currentRectangleId=void 0,this.drawType=void 0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},e}(x),te=/*#__PURE__*/function(t){function e(e){var i;if(!e.modeName)throw new Error("Mode name is required for TerraDrawRenderMode");return(i=t.call(this,e,!0)||this).type=P.Render,i.mode="render",i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e)},i.registerBehaviors=function(t){this.mode=t.mode},i.start=function(){this.setStarted()},i.stop=function(){this.setStopped()},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(t){return{pointColor:this.getHexColorStylingValue(this.styles.pointColor,"#3f97e0",t),pointWidth:this.getNumericStylingValue(this.styles.pointWidth,6,t),pointOpacity:this.getNumericStylingValue(this.styles.pointOpacity,1,t),pointOutlineColor:this.getHexColorStylingValue(this.styles.pointOutlineColor,"#ffffff",t),pointOutlineWidth:this.getNumericStylingValue(this.styles.pointOutlineWidth,0,t),pointOutlineOpacity:this.getNumericStylingValue(this.styles.pointOutlineOpacity,1,t),polygonFillColor:this.getHexColorStylingValue(this.styles.polygonFillColor,"#3f97e0",t),polygonFillOpacity:this.getNumericStylingValue(this.styles.polygonFillOpacity,.3,t),polygonOutlineColor:this.getHexColorStylingValue(this.styles.polygonOutlineColor,"#3f97e0",t),polygonOutlineWidth:this.getNumericStylingValue(this.styles.polygonOutlineWidth,4,t),lineStringWidth:this.getNumericStylingValue(this.styles.lineStringWidth,4,t),lineStringColor:this.getHexColorStylingValue(this.styles.lineStringColor,"#3f97e0",t),lineStringOpacity:this.getNumericStylingValue(this.styles.lineStringOpacity,1,t),zIndex:this.getNumericStylingValue(this.styles.zIndex,0,t)}},i.validateFeature=function(e){var i=t.prototype.validateFeature.call(this,e);if(i.valid){var n=e,o=Vt(n,this.coordinatePrecision).valid||X(n,this.coordinatePrecision).valid||wt(n,this.coordinatePrecision).valid;return o?{valid:!0}:{valid:o,reason:"Feature is not a valid Point, Polygon or LineString feature"}}return i},e}(x);function ee(t,e){var i=t,n=e,o=E(i[1]),r=E(n[1]),s=E(n[0]-i[0]);s>Math.PI&&(s-=2*Math.PI),s<-Math.PI&&(s+=2*Math.PI);var a=Math.log(Math.tan(r/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=(k(Math.atan2(s,a))+360)%360;return d>180?-(360-d):d}function ie(t,e,i){var n=e;e<0&&(n=-Math.abs(n));var o=n/O,r=t[0]*Math.PI/180,s=E(t[1]),a=E(i),d=o*Math.cos(a),u=s+d;Math.abs(u)>Math.PI/2&&(u=u>0?Math.PI-u:-Math.PI-u);var h=Math.log(Math.tan(u/2+Math.PI/4)/Math.tan(s/2+Math.PI/4)),l=Math.abs(h)>1e-11?d/h:Math.cos(s),c=[(180*(r+o*Math.sin(a)/l)/Math.PI+540)%360-180,180*u/Math.PI];return c[0]+=c[0]-t[0]>180?-360:t[0]-c[0]>180?360:0,c}function ne(t,e,i,n,o){var r=n(t[0],t[1]),s=n(e[0],e[1]),a=o((r.x+s.x)/2,(r.y+s.y)/2),d=a.lat;return[b(a.lng,i),b(d,i)]}function oe(t,e,i){var n=ie(t,1e3*w(t,e)/2,ee(t,e));return[b(n[0],i),b(n[1],i)]}function re(t){for(var e=t.featureCoords,i=t.precision,n=t.unproject,o=t.project,r=t.projection,s=[],a=0;a<e.length-1;a++){var d=void 0;if("web-mercator"===r)d=ne(e[a],e[a+1],i,o,n);else{if("globe"!==r)throw new Error("Invalid projection");d=oe(e[a],e[a+1],i)}s.push(d)}return s}var se=/*#__PURE__*/function(t){function e(e,i,n,o,r,s){var a;return(a=t.call(this,e)||this).config=void 0,a.selectionPointBehavior=void 0,a.coordinatePointBehavior=void 0,a.mutateFeature=void 0,a.readFeature=void 0,a.pixelDistance=void 0,a._midPoints=[],a.config=e,a.selectionPointBehavior=i,a.coordinatePointBehavior=n,a.mutateFeature=o,a.readFeature=r,a.pixelDistance=s,a}r(e,t);var n=e.prototype;return n.getMidpointConfig=function(t){return{featureCoords:t,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}},n.getNearestMidPoint=function(t){var e=this,i=Infinity,n=void 0;return this.ids.forEach(function(o){var r=e.readFeature.getGeometry(o),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<i&&(i=s,n=o)}),n},n.insert=function(t){var e=t.featureId,i=t.midPointId,n=this.readFeature.getGeometry(i),o=this.readFeature.getProperties(i),r=o.midPointFeatureId,s=o.midPointSegment,a=this.readFeature.getGeometry(r),u={featureId:r,coordinateMutations:[{type:Q,index:s,coordinate:n.coordinates}],context:{updateType:d.Commit}},h=null;if("Polygon"===a.type)h=this.mutateFeature.updatePolygon(u);else{if("LineString"!==a.type)throw new Error("Midpoints can only be added to polygons or linestrings");h=this.mutateFeature.updateLineString(u)}if(!h)throw new Error("Failed to insert midpoint coordinate");var l=h.geometry.coordinates;this.readFeature.getProperties(e)[f.COORDINATE_POINT_IDS]&&this.coordinatePointBehavior.createOrUpdate({featureId:e,featureCoordinates:l}),this.mutateFeature.deleteFeaturesIfPresent([].concat(this.selectionPointBehavior.ids,this._midPoints)),this.create({featureCoordinates:l,featureId:r}),this.selectionPointBehavior.create({featureCoordinates:l,featureId:e})},n.create=function(t){var e=this,i=t.featureCoordinates,n=t.featureId;if(!this.readFeature.hasFeature(n))throw new Error("Store does not have feature with this id");var o=Nt(i),r=re(this.getMidpointConfig(o));this._midPoints=this.mutateFeature.createGuidancePoints({additionalProperties:function(t){var i;return(i={mode:e.mode,midPointSegment:t,midPointFeatureId:n})[g.MID_POINT]=!0,i},coordinates:r,type:g.MID_POINT})},n.delete=function(){this._midPoints.length&&(this.mutateFeature.deleteFeaturesIfPresent(this._midPoints),this._midPoints=[])},n.updateAllInPlace=function(t){if(0!==this._midPoints.length){var e=Nt(t.featureCoordinates),i=re(this.getMidpointConfig(e));this.mutateFeature.updateGuidancePoints(this._midPoints.map(function(t,e){return{featureId:t,coordinate:i[e]}}))}},n.updateOneAtIndex=function(t,e){if(t<0&&(t=this._midPoints.length+t),void 0!==this._midPoints[t]){var i=Nt(e),n=re(this.getMidpointConfig(i));this.mutateFeature.updateGuidancePoints([{featureId:this._midPoints[t],coordinate:n[t]}])}},i(e,[{key:"ids",get:function(){return this._midPoints.concat()},set:function(t){}}])}(Z),ae=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).mutateFeature=void 0,n._selectionPoints=[],n.mutateFeature=i,n}r(e,t);var n=e.prototype;return n.create=function(t){var e=t.featureId,i=Tt(t.featureCoordinates);this._selectionPoints=this.mutateFeature.createGuidancePoints({coordinates:i,type:g.SELECTION_POINT,additionalProperties:function(t){var i;return(i={})[g.SELECTION_POINT_FEATURE_ID]=e,i.index=t,i}})},n.delete=function(){this.ids.length&&(this.mutateFeature.deleteFeaturesIfPresent(this.ids),this._selectionPoints=[])},n.updateAllInPlace=function(t){if(0!==this._selectionPoints.length){var e=Tt(t.featureCoordinates);e.length===this._selectionPoints.length&&this.mutateFeature.updateGuidancePoints(this._selectionPoints.map(function(t,i){return{featureId:t,coordinate:e[i]}}))}},n.updateOneAtIndex=function(t,e){void 0!==this._selectionPoints[t]&&this.mutateFeature.updateGuidancePoints([{featureId:this._selectionPoints[t],coordinate:e}])},i(e,[{key:"ids",get:function(){return this._selectionPoints.concat()},set:function(t){}}])}(Z);function de(t,e){for(var i,n,o,r=!1,s=0,a=e.length;s<a;s++)for(var d=e[s],u=0,h=d.length,l=h-1;u<h;l=u++)(n=d[u])[1]>(i=t)[1]!=(o=d[l])[1]>i[1]&&i[0]<(o[0]-n[0])*(i[1]-n[1])/(o[1]-n[1])+n[0]&&(r=!r);return r}var ue=function(t,e,i){var n=function(t){return t*t},o=function(t,e){return n(t.x-e.x)+n(t.y-e.y)};return Math.sqrt(function(t,e,i){var n=o(e,i);if(0===n)return o(t,e);var r=((t.x-e.x)*(i.x-e.x)+(t.y-e.y)*(i.y-e.y))/n;return r=Math.max(0,Math.min(1,r)),o(t,{x:e.x+r*(i.x-e.x),y:e.y+r*(i.y-e.y)})}(t,e,i))},he=/*#__PURE__*/function(t){function e(e,i,n){var o;return(o=t.call(this,e)||this).config=void 0,o.createClickBoundingBox=void 0,o.pixelDistance=void 0,o.config=e,o.createClickBoundingBox=i,o.pixelDistance=n,o}return r(e,t),e.prototype.find=function(t,e){for(var i=void 0,n=Infinity,o=void 0,r=Infinity,s=void 0,a=this.createClickBoundingBox.create(t),d=this.store.search(a),u=0;u<d.length;u++){var h=d[u],l=h.geometry;if("Point"===l.type){if(h.properties.selectionPoint||h.properties.coordinatePoint||!e&&h.properties[g.MID_POINT])continue;var c=this.pixelDistance.measure(t,l.coordinates);!h.properties[g.MID_POINT]&&c<this.pointerDistance&&c<n&&(n=c,i=h)}else if("LineString"===l.type){if(i)continue;for(var p=0;p<l.coordinates.length-1;p++){var f=l.coordinates[p],y=l.coordinates[p+1],v=ue({x:t.containerX,y:t.containerY},this.project(f[0],f[1]),this.project(y[0],y[1]));v<this.pointerDistance&&v<r&&(r=v,o=h)}}else if("Polygon"===l.type){if(i||o)continue;de([t.lng,t.lat],l.coordinates)&&(s=h)}}return{clickedFeature:i||o||s}},e}(Z),le=/*#__PURE__*/function(t){function e(e,i,n,o,r,s,a){var d;return(d=t.call(this,e)||this).config=void 0,d.featuresAtCursorEvent=void 0,d.selectionPoints=void 0,d.midPoints=void 0,d.coordinatePoints=void 0,d.readFeature=void 0,d.mutateFeature=void 0,d.draggedFeatureId=null,d.dragPosition=void 0,d.config=e,d.featuresAtCursorEvent=i,d.selectionPoints=n,d.midPoints=o,d.coordinatePoints=r,d.readFeature=s,d.mutateFeature=a,d}r(e,t);var i=e.prototype;return i.startDragging=function(t,e){this.draggedFeatureId=e,this.dragPosition=[t.lng,t.lat]},i.stopDragging=function(){this.draggedFeatureId=null,this.dragPosition=void 0},i.isDragging=function(){return null!==this.draggedFeatureId},i.canDrag=function(t,e){var i=this.featuresAtCursorEvent.find(t,!0).clickedFeature;return!(!i||i.id!==e)},i.drag=function(t){if(this.draggedFeatureId){var e=this.readFeature.getGeometry(this.draggedFeatureId),i=[t.lng,t.lat];if("Polygon"===e.type||"LineString"===e.type){var n,o;if(o="Polygon"===e.type?(n=e.coordinates[0]).length-1:(n=e.coordinates).length,!this.dragPosition)return!1;for(var r=0;r<o;r++){var s=n[r],a=void 0,u=void 0;if("web-mercator"===this.config.projection){var h=R(this.dragPosition[0],this.dragPosition[1]),l=R(i[0],i[1]),c=R(s[0],s[1]),p={x:h.x-l.x,y:h.y-l.y},g=U(c.x-p.x,c.y-p.y);a=g.lng,u=g.lat}else{var f=[this.dragPosition[0]-i[0],this.dragPosition[1]-i[1]];a=s[0]-f[0],u=s[1]-f[1]}if(a=b(a,this.config.coordinatePrecision),u=b(u,this.config.coordinatePrecision),a>180||a<-180||u>90||u<-90)return!1;n[r]=[a,u]}"Polygon"===e.type&&(n[n.length-1]=[n[0][0],n[0][1]]);var y=this.draggedFeatureId,v=null;if("Polygon"===e.type)v=this.mutateFeature.updatePolygon({featureId:y,coordinateMutations:{type:it,coordinates:[n]},context:{updateType:d.Provisional}});else{if("LineString"!==e.type)return;v=this.mutateFeature.updateLineString({featureId:y,coordinateMutations:{type:it,coordinates:n},context:{updateType:d.Provisional}})}if(!v)return!1;var m=v.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:m}),this.selectionPoints.updateAllInPlace({featureCoordinates:m}),this.coordinatePoints.updateAllInPlace({featureId:y,featureCoordinates:m}),this.dragPosition=[t.lng,t.lat]}else"Point"===e.type&&(this.mutateFeature.updatePoint({featureId:this.draggedFeatureId,coordinateMutations:{type:it,coordinates:i},context:{updateType:d.Provisional}}),this.dragPosition=[t.lng,t.lat])}},e}(Z),ce=/*#__PURE__*/function(t){function e(e,i,n,o,r,s,a,d,u){var h;return(h=t.call(this,e)||this).config=void 0,h.pixelDistance=void 0,h.selectionPoints=void 0,h.midPoints=void 0,h.coordinatePoints=void 0,h.coordinateSnapping=void 0,h.lineSnapping=void 0,h.readFeature=void 0,h.mutateFeature=void 0,h.draggedCoordinate={id:null,index:-1},h.config=e,h.pixelDistance=i,h.selectionPoints=n,h.midPoints=o,h.coordinatePoints=r,h.coordinateSnapping=s,h.lineSnapping=a,h.readFeature=d,h.mutateFeature=u,h}r(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o<i.length;o++){var r=this.pixelDistance.measure(t,i[o]);if(r<this.pointerDistance&&r<n.dist){var s="Polygon"===e.type&&(o===i.length-1||0===o);n.dist=r,n.index=s?0:o,n.isFirstOrLastPolygonCoord=s}}return n},i.getDraggable=function(t,e){var i=this.readFeature.getGeometry(e);return this.getClosestCoordinate(t,i)},i.getDraggableIndex=function(t,e){var i=this.readFeature.getGeometry(e),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.snapCoordinate=function(t,e,i){var n,o,r,s=this,a=[t.lng,t.lat],d=function(t){return Boolean(t.properties&&t.properties.mode===i.properties.mode&&t.id!==s.draggedCoordinate.id)};return null!=e&&e.toLine&&(n=this.lineSnapping.getSnappable(t,d).coordinate)&&(a=n),e.toCoordinate&&(o=this.coordinateSnapping.getSnappable(t,d).coordinate)&&(a=o),null!=e&&e.toCustom&&(r=e.toCustom(t,{currentCoordinate:this.draggedCoordinate.index,currentId:i.id,getCurrentGeometrySnapshot:i.id?function(){return s.readFeature.getGeometry(i.id)}:function(){return null},project:this.project,unproject:this.unproject}))&&(a=r),a},i.drag=function(t,e,i){var n=this.draggedCoordinate.id;if(null===n)return!1;var o=this.draggedCoordinate.index,r=this.readFeature.getGeometry(n),s=this.readFeature.getProperties(n),a="LineString"===r.type?r.coordinates:r.coordinates[0],u="Polygon"===r.type&&(o===a.length-1||0===o),h=this.snapCoordinate(t,i,{type:"Feature",id:n,geometry:r,properties:s});if(t.lng>180||t.lng<-180||t.lat>90||t.lat<-90)return!1;if(u){var l=a.length-1;a[0]=h,a[l]=h}else a[o]=h;if("Point"!==r.type&&!e&&A({type:"Feature",geometry:r,properties:{}}))return!1;var c=n,p=null;return"Polygon"===r.type?p=this.mutateFeature.updatePolygon({featureId:c,coordinateMutations:{type:it,coordinates:[a]},context:{updateType:d.Provisional}}):"LineString"===r.type&&(p=this.mutateFeature.updateLineString({featureId:c,coordinateMutations:{type:it,coordinates:a},context:{updateType:d.Provisional}})),!!p&&(this.midPoints.updateOneAtIndex(o>0?o-1:-1,a),this.midPoints.updateOneAtIndex(o,a),this.selectionPoints.updateOneAtIndex(o,h),this.coordinatePoints.updateOneAtIndex(c,o,h),!0)},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},e}(Z);function pe(t){var e=0,i=0,n=0;return("Polygon"===t.geometry.type?t.geometry.coordinates[0].slice(0,-1):t.geometry.coordinates).forEach(function(t){e+=t[0],i+=t[1],n++},!0),[e/n,i/n]}var ge=function(t,e){if(0===e||360===e||-360===e)return t;var i=.017453292519943295*e,n=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){return R(t[0],t[1])}),o=n.reduce(function(t,e){return{x:t.x+e.x,y:t.y+e.y}},{x:0,y:0});o.x/=n.length,o.y/=n.length;var r=n.map(function(t){return{x:o.x+(t.x-o.x)*Math.cos(i)-(t.y-o.y)*Math.sin(i),y:o.y+(t.x-o.x)*Math.sin(i)+(t.y-o.y)*Math.cos(i)}}).map(function(t){var e=t.x,i=t.y;return[U(e,i).lng,U(e,i).lat]});return"Polygon"===t.geometry.type?t.geometry.coordinates[0]=r:t.geometry.coordinates=r,t};function fe(t){var e=("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).map(function(t){var e=R(t[0],t[1]);return[e.x,e.y]});return"Polygon"===t.geometry.type?function(t){for(var e=0,i=0,n=0,o=t.length,r=0;r<o-1;r++){var s=t[r],a=s[0],d=s[1],u=t[r+1],h=u[0],l=u[1],c=a*l-h*d;e+=c,i+=(a+h)*c,n+=(d+l)*c}return{x:i/=6*(e/=2),y:n/=6*e}}(e):function(t){for(var e=t.length,i=0,n=0,o=0;o<e;o++){var r=t[o];i+=r[0],n+=r[1]}return{x:i/e,y:n/e}}(e)}var ye=/*#__PURE__*/function(t){function e(e,i,n,o,r,s){var a;return(a=t.call(this,e)||this).config=void 0,a.selectionPoints=void 0,a.midPoints=void 0,a.coordinatePoints=void 0,a.readFeature=void 0,a.mutateFeature=void 0,a.lastBearing=void 0,a.selectedGeometry=void 0,a.selectedGeometryCentroid=void 0,a.selectedGeometryWebMercatorCentroid=void 0,a.config=e,a.selectionPoints=i,a.midPoints=n,a.coordinatePoints=o,a.readFeature=r,a.mutateFeature=s,a}r(e,t);var i=e.prototype;return i.reset=function(){this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.selectedGeometryCentroid=void 0},i.rotate=function(t,e){var i=this;this.selectedGeometry||(this.selectedGeometry=this.readFeature.getGeometry(e));var n=this.selectedGeometry;if("Polygon"===n.type||"LineString"===n.type){var o,r=[t.lng,t.lat],s={type:"Feature",geometry:n,properties:{}};if("web-mercator"===this.config.projection){this.selectedGeometryWebMercatorCentroid||(this.selectedGeometryWebMercatorCentroid=fe(s));var a=R(t.lng,t.lat);if(0===(o=Pt(this.selectedGeometryWebMercatorCentroid,a)))return;if(!this.lastBearing)return void(this.lastBearing=o);ge(s,-(this.lastBearing-o))}else{if("globe"!==this.config.projection)throw new Error("Unsupported projection");if(this.selectedGeometryCentroid||(this.selectedGeometryCentroid=pe({type:"Feature",geometry:n,properties:{}})),o=ee(this.selectedGeometryCentroid,r),!this.lastBearing)return void(this.lastBearing=o+180);!function(t,e){if(0===e||360===e||-360===e)return t;var i=pe(t);("Polygon"===t.geometry.type?t.geometry.coordinates[0]:t.geometry.coordinates).forEach(function(t){var n=ee(i,t)+e,o=function(t,e){t[0]+=t[0]-e[0]>180?-360:e[0]-t[0]>180?360:0;var i=O,n=e[1]*Math.PI/180,o=t[1]*Math.PI/180,r=o-n,s=Math.abs(t[0]-e[0])*Math.PI/180;s>Math.PI&&(s-=2*Math.PI);var a=Math.log(Math.tan(o/2+Math.PI/4)/Math.tan(n/2+Math.PI/4)),d=Math.abs(a)>1e-11?r/a:Math.cos(n);return Math.sqrt(r*r+d*d*s*s)*i}(i,t),r=ie(i,o,n);t[0]=r[0],t[1]=r[1]})}(s,-(this.lastBearing-(o+180)))}var u="Polygon"===n.type?n.coordinates[0]:n.coordinates;u.forEach(function(t){t[0]=b(t[0],i.coordinatePrecision),t[1]=b(t[1],i.coordinatePrecision)});var h={featureId:e,coordinateMutations:{type:it,coordinates:"Polygon"===n.type?[u]:u},context:{updateType:d.Provisional}},l=null;if("Polygon"===s.geometry.type)l=this.mutateFeature.updatePolygon(h);else{if("LineString"!==s.geometry.type)return;l=this.mutateFeature.updateLineString(h)}if(!l)return!1;var c=l.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:c}),this.selectionPoints.updateAllInPlace({featureCoordinates:c}),this.coordinatePoints.updateAllInPlace({featureId:e,featureCoordinates:c}),"web-mercator"===this.projection?this.lastBearing=o:"globe"===this.projection&&(this.lastBearing=o+180)}},e}(Z),ve=/*#__PURE__*/function(t){function e(e,i){var n;return(n=t.call(this,e)||this).config=void 0,n.dragCoordinateResizeBehavior=void 0,n.config=e,n.dragCoordinateResizeBehavior=i,n}r(e,t);var i=e.prototype;return i.scale=function(t,e){if(!this.dragCoordinateResizeBehavior.isDragging()){var i=this.dragCoordinateResizeBehavior.getDraggableIndex(t,e);this.dragCoordinateResizeBehavior.startDragging(e,i)}this.dragCoordinateResizeBehavior.drag(t,"center-fixed")},i.reset=function(){this.dragCoordinateResizeBehavior.stopDragging()},e}(Z);function me(t){var e=t.originX,i=t.originY,n=t.xScale,o=t.yScale;1===n&&1===o||t.coordinates.forEach(function(t){var r=R(t[0],t[1]),s=U(e+(r.x-e)*n,i+(r.y-i)*o),a=s.lat;t[0]=s.lng,t[1]=a})}var Ce=/*#__PURE__*/function(t){function e(e,i,n,o,r,s,a){var d;return(d=t.call(this,e)||this).config=void 0,d.pixelDistance=void 0,d.selectionPoints=void 0,d.midPoints=void 0,d.coordinatePoints=void 0,d.readFeature=void 0,d.mutateFeature=void 0,d.minimumScale=1e-4,d.draggedCoordinate={id:null,index:-1},d.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},d.config=e,d.pixelDistance=i,d.selectionPoints=n,d.midPoints=o,d.coordinatePoints=r,d.readFeature=s,d.mutateFeature=a,d}r(e,t);var i=e.prototype;return i.getClosestCoordinate=function(t,e){var i,n={dist:Infinity,index:-1,isFirstOrLastPolygonCoord:!1};if("LineString"===e.type)i=e.coordinates;else{if("Polygon"!==e.type)return n;i=e.coordinates[0]}for(var o=0;o<i.length;o++){var r=this.pixelDistance.measure(t,i[o]);if(r<this.pointerDistance&&r<n.dist){var s="Polygon"===e.type&&(o===i.length-1||0===o);n.dist=r,n.index=s?0:o,n.isFirstOrLastPolygonCoord=s}}return n},i.isValidDragWebMercator=function(t,e,i){switch(t){case 0:if(e<=0||i>=0)return!1;break;case 1:if(i>=0)return!1;break;case 2:if(e>=0||i>=0)return!1;break;case 3:if(e>=0)return!1;break;case 4:if(e>=0||i<=0)return!1;break;case 5:if(i<=0)return!1;break;case 6:if(e<=0||i<=0)return!1;break;case 7:if(e<=0)return!1}return!0},i.getSelectedFeatureDataWebMercator=function(){if(!this.draggedCoordinate.id||-1===this.draggedCoordinate.index)return null;var t=this.getFeature(this.draggedCoordinate.id);if(!t)return null;var e=this.getNormalisedCoordinates(t.geometry);return{boundingBox:this.getBBoxWebMercator(e),feature:t,updatedCoords:e,selectedCoordinate:e[this.draggedCoordinate.index]}},i.centerWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=fe(e.feature);if(!r)return null;var s=R(o[0],o[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=R(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:d,webMercatorSelected:s,webMercatorOrigin:r}),n},i.centerFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=fe(e.feature);if(!r)return null;var s=R(o[0],o[1]),a=this.getIndexesWebMercator(i,s).closestBBoxIndex,d=R(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:a,updatedCoords:n,webMercatorCursor:d,webMercatorSelected:s,webMercatorOrigin:r}),n},i.scaleFixedWebMercator=function(t){var e=t.webMercatorOrigin,i=t.webMercatorSelected,n=t.webMercatorCursor,o=t.updatedCoords;if(!this.isValidDragWebMercator(t.closestBBoxIndex,e.x-n.x,e.y-n.y))return null;var r=at(e,n)/at(e,i);return r<0&&(r=this.minimumScale),me({coordinates:o,originX:e.x,originY:e.y,xScale:r,yScale:r}),o},i.oppositeFixedWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=R(o[0],o[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,d=s.closestBBoxIndex,u={x:i[a][0],y:i[a][1]},h=R(t.lng,t.lat);return this.scaleFixedWebMercator({closestBBoxIndex:d,updatedCoords:n,webMercatorCursor:h,webMercatorSelected:r,webMercatorOrigin:u}),n},i.oppositeWebMercatorDrag=function(t){var e=this.getSelectedFeatureDataWebMercator();if(!e)return null;var i=e.boundingBox,n=e.updatedCoords,o=e.selectedCoordinate,r=R(o[0],o[1]),s=this.getIndexesWebMercator(i,r),a=s.oppositeBboxIndex,d=s.closestBBoxIndex,u={x:i[a][0],y:i[a][1]},h=R(t.lng,t.lat);return this.scaleWebMercator({closestBBoxIndex:d,updatedCoords:n,webMercatorCursor:h,webMercatorSelected:r,webMercatorOrigin:u}),n},i.scaleWebMercator=function(t){var e=t.closestBBoxIndex,i=t.webMercatorOrigin,n=t.webMercatorSelected,o=t.webMercatorCursor,r=t.updatedCoords,s=i.x-o.x,a=i.y-o.y;if(!this.isValidDragWebMercator(e,s,a))return null;var d=1;0!==s&&1!==e&&5!==e&&(d=1-(i.x-n.x-s)/s);var u=1;return 0!==a&&3!==e&&7!==e&&(u=1-(i.y-n.y-a)/a),this.validateScale(d,u)?(d<0&&(d=this.minimumScale),u<0&&(u=this.minimumScale),this.performWebMercatorScale(r,i.x,i.y,d,u),r):null},i.getFeature=function(t){if(null===this.draggedCoordinate.id)return null;var e=this.readFeature.getGeometry(t);return"Polygon"!==e.type&&"LineString"!==e.type?null:{id:t,type:"Feature",geometry:e,properties:{}}},i.getNormalisedCoordinates=function(t){return"Polygon"===t.type?t.coordinates[0]:t.coordinates},i.validateScale=function(t,e){var i=!isNaN(t)&&e<Number.MAX_SAFE_INTEGER,n=!isNaN(e)&&e<Number.MAX_SAFE_INTEGER;return i&&n},i.performWebMercatorScale=function(t,e,i,n,o){t.forEach(function(t){var r=R(t[0],t[1]),s=U(e+(r.x-e)*n,i+(r.y-i)*o),a=s.lat;t[0]=s.lng,t[1]=a})},i.getBBoxWebMercator=function(t){var e=[Infinity,Infinity,-Infinity,-Infinity];(t=t.map(function(t){var e=R(t[0],t[1]);return[e.x,e.y]})).forEach(function(t){var i=t[0],n=t[1];i<e[0]&&(e[0]=i),n<e[1]&&(e[1]=n),i>e[2]&&(e[2]=i),n>e[3]&&(e[3]=n)});var i=e[0],n=e[1],o=e[2],r=e[3];return[[i,r],[(i+o)/2,r],[o,r],[o,r+(n-r)/2],[o,n],[(i+o)/2,n],[i,n],[i,r+(n-r)/2]]},i.getIndexesWebMercator=function(t,e){for(var i,n=Infinity,o=0;o<t.length;o++){var r=at({x:e.x,y:e.y},{x:t[o][0],y:t[o][1]});r<n&&(i=o,n=r)}if(void 0===i)throw new Error("No closest coordinate found");return{oppositeBboxIndex:this.boundingBoxMaps.opposite[i],closestBBoxIndex:i}},i.isDragging=function(){return null!==this.draggedCoordinate.id},i.startDragging=function(t,e){this.draggedCoordinate={id:t,index:e}},i.stopDragging=function(){this.draggedCoordinate={id:null,index:-1}},i.getDraggableIndex=function(t,e){var i=this.readFeature.getGeometry(e),n=this.getClosestCoordinate(t,i);return-1===n.index?-1:n.index},i.drag=function(t,e){if(!this.draggedCoordinate.id)return!1;var i=this.getFeature(this.draggedCoordinate.id);if(!i)return!1;var n=null;if("center"===e?n=this.centerWebMercatorDrag(t):"opposite"===e?n=this.oppositeWebMercatorDrag(t):"center-fixed"===e?n=this.centerFixedWebMercatorDrag(t):"opposite-fixed"===e&&(n=this.oppositeFixedWebMercatorDrag(t)),!n)return!1;for(var o=0;o<n.length;o++){var r=n[o];if(r[0]=b(r[0],this.coordinatePrecision),r[1]=b(r[1],this.coordinatePrecision),!z(r,this.coordinatePrecision))return!1}var s=i.id,a=null;if("Polygon"===i.geometry.type?a=this.mutateFeature.updatePolygon({featureId:s,coordinateMutations:{type:it,coordinates:[n]},context:{updateType:d.Provisional}}):"LineString"===i.geometry.type&&(a=this.mutateFeature.updateLineString({featureId:s,coordinateMutations:{type:it,coordinates:n},context:{updateType:d.Provisional}})),!a)return!1;var u=a.geometry.coordinates;return this.midPoints.updateAllInPlace({featureCoordinates:u}),this.selectionPoints.updateAllInPlace({featureCoordinates:u}),this.coordinatePoints.updateAllInPlace({featureId:s,featureCoordinates:u}),!0},e}(Z),Pe={deselect:"Escape",delete:"Delete",rotate:["Control","r"],scale:["Control","s"]},Ie={pointerOver:"move",dragStart:"move",dragEnd:"move",insertMidpoint:"crosshair"},Se=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="select",i.allowManualDeselection=!0,i.allowManualSelection=!0,i.dragEventThrottle=5,i.dragEventCount=0,i.selected=[],i.flags={},i.keyEvents=Pe,i.cursors=Ie,i.validations={},i.dragTarget={type:"none"},i.selectionPoints=void 0,i.midPoints=void 0,i.coordinateSnap=void 0,i.featuresAtMouseEvent=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.dragFeature=void 0,i.dragCoordinate=void 0,i.rotateFeature=void 0,i.scaleFeature=void 0,i.dragCoordinateResizeFeature=void 0,i.coordinatePoints=void 0,i.lineSnap=void 0,i.mutateFeature=void 0,i.readFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){if(t.prototype.updateOptions.call(this,e),this.cursors=e&&e.cursors?o({},this.cursors,e.cursors):Ie,null===(null==e?void 0:e.keyEvents)?this.keyEvents={deselect:null,delete:null,rotate:null,scale:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),void 0!==(null==e?void 0:e.dragEventThrottle)&&(this.dragEventThrottle=e.dragEventThrottle),void 0!==(null==e?void 0:e.allowManualDeselection)&&(this.allowManualDeselection=e.allowManualDeselection),void 0!==(null==e?void 0:e.allowManualSelection)&&(this.allowManualSelection=e.allowManualSelection),null!=e&&e.flags)for(var i in this.flags=o({},this.flags,e.flags),this.validations={},this.flags){var n=this.flags[i].feature;n&&n.validation&&(this.validations[i]=n.validation)}},i.selectFeature=function(t){this.select(t,!1)},i.setSelecting=function(){if("started"!==this._state)throw new Error("Mode must be started to move to selecting state");this._state="selecting"},i.registerBehaviors=function(t){var e=this;this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:function(t,i){var n=t.properties.mode;return e.validations&&e.validations[n]?e.validations[n](t,i):{valid:!0}}}),this.pixelDistance=new ft(t),this.clickBoundingBox=new gt(t),this.featuresAtMouseEvent=new he(t,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new ae(t,this.mutateFeature),this.coordinatePoints=new Ut(t,this.readFeature,this.mutateFeature),this.midPoints=new se(t,this.selectionPoints,this.coordinatePoints,this.mutateFeature,this.readFeature,this.pixelDistance),this.coordinateSnap=new yt(t,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new bt(t,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new ye(t,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragFeature=new le(t,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragCoordinate=new ce(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap,this.readFeature,this.mutateFeature),this.dragCoordinateResizeFeature=new Ce(t,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.scaleFeature=new ve(t,this.dragCoordinateResizeFeature)},i.deselectFeature=function(t){this.deselect(t)},i.deselect=function(t){this.selected.includes(t)&&(this.mutateFeature.setDeselected(this.selected),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete(),this.dragTarget={type:"none"})},i.deleteSelected=function(){this.selected.length&&this.mutateFeature.deleteFeaturesIfPresent(this.selected),this.selected=[],this.dragTarget={type:"none"}},i.clearDragTargetAndCursor=function(){this.dragTarget={type:"none"},this.setCursor("unset")},i.getSelectedFlags=function(t){var e=this.readFeature.getProperties(t),i=this.flags[e.mode],n=null==i?void 0:i.feature,o=null==n?void 0:n.coordinates;return{featureFlags:n,coordinatesFlags:o,hasDraggableFlags:n&&(n.draggable||(null==o?void 0:o.draggable)||(null==o?void 0:o.resizable)||"object"==typeof(null==o?void 0:o.midpoints)&&o.midpoints.draggable)}},i.onRightClick=function(t){var e=this;if(this.selectionPoints.ids.length){var i,n=Infinity;if(this.selectionPoints.ids.forEach(function(o){var r=e.readFeature.getGeometry(o),s=e.pixelDistance.measure(t,r.coordinates);s<e.pointerDistance&&s<n&&(n=s,i=e.readFeature.getProperties(o))}),i){var o=i.selectionPointFeatureId,r=i.index,s=this.readFeature.getProperties(o),a=this.flags[s.mode];if(a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.deletable){var u,h=this.readFeature.getGeometry(o);if("Polygon"===h.type){if((u=h.coordinates[0]).length<=4)return}else{if("LineString"!==h.type)return;if((u=h.coordinates).length<=2)return}"Polygon"!==h.type||0!==r&&r!==u.length-1?u.splice(r,1):(u.shift(),u.pop(),u.push([u[0][0],u[0][1]]));var c=null;if("Polygon"===h.type?c=this.mutateFeature.updatePolygon({featureId:o,coordinateMutations:{type:it,coordinates:[u]},context:{updateType:d.Commit}}):"LineString"===h.type&&(c=this.mutateFeature.updateLineString({featureId:o,coordinateMutations:{type:it,coordinates:u},context:{updateType:d.Commit}})),c){var p=c.geometry.coordinates;this.mutateFeature.deleteFeaturesIfPresent([].concat(this.midPoints.ids,this.selectionPoints.ids)),s.coordinatePointIds&&this.coordinatePoints.createOrUpdate({featureId:o,featureCoordinates:p}),this.selectionPoints.create({featureCoordinates:p,featureId:o}),a&&a.feature&&a.feature.coordinates&&a.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:p,featureId:o}),this.onFinish(o,{action:l,mode:this.mode})}}}}},i.select=function(t,e){if(void 0===e&&(e=!0),this.selected[0]!==t){var i=this.readFeature.getProperties(t),n=this.flags[i.mode];if(n&&n.feature){var o=this.selected[0];if(o){if(o===t)return;this.deselect(o)}e&&this.setCursor(this.cursors.pointerOver),this.selected=[t],this.mutateFeature.setSelected(t),this.onSelect(t);var r=this.readFeature.getGeometry(t),s=r.type,a=r.coordinates;"LineString"!==s&&"Polygon"!==s||a&&n&&n.feature.coordinates&&(this.selectionPoints.create({featureCoordinates:a,featureId:t}),n.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:a,featureId:t}))}}},i.onLeftClick=function(t){var e=this.featuresAtMouseEvent.find(t,this.selected.length>0).clickedFeature,i=this.midPoints.getNearestMidPoint(t),n=this.selected[0];if(n){var o,r=this.getSelectedFlags(n).featureFlags;if(null!=r&&null!=(o=r.coordinates)&&o.midpoints&&i){if(r.coordinates.draggable){var s=this.pixelDistance.measure(t,this.readFeature.getGeometry(i).coordinates),a=this.dragCoordinate.getDraggable(t,n).dist;if(void 0!==a&&s>a)return}return this.midPoints.insert({featureId:n,midPointId:i}),void this.onFinish(this.selected[0],{action:c,mode:this.mode})}}if(null!=e&&e.id)this.allowManualSelection&&this.select(e.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect(this.selected[0])},i.start=function(){this.setStarted(),this.setSelecting()},i.stop=function(){this.cleanUp(),this.setStarted(),this.setStopped()},i.onClick=function(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.canScale=function(t){return this.keyEvents.scale&&this.keyEvents.scale.every(function(e){return t.heldKeys.includes(e)})},i.canRotate=function(t){return this.keyEvents.rotate&&this.keyEvents.rotate.every(function(e){return t.heldKeys.includes(e)})},i.preventDefaultKeyEvent=function(t){var e=this.canRotate(t),i=this.canScale(t);(e||i)&&t.preventDefault()},i.onKeyDown=function(t){this.preventDefaultKeyEvent(t)},i.onKeyUp=function(t){if(this.preventDefaultKeyEvent(t),this.keyEvents.delete&&t.key===this.keyEvents.delete){if(!this.selected.length)return;var e=this.selected[0];this.onDeselect(this.selected[0]),this.coordinatePoints.deletePointsByFeatureIds([e]),this.deleteSelected(),this.selectionPoints.delete(),this.midPoints.delete()}else this.keyEvents.deselect&&t.key===this.keyEvents.deselect&&this.cleanUp()},i.cleanUp=function(){this.selected.length&&this.deselect(this.selected[0])},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){var i=this.selected[0];if(i){var n=this.getSelectedFlags(i),o=n.featureFlags,r=n.coordinatesFlags;if(n.hasDraggableFlags){this.dragEventCount=0;var s="none"!==this.dragTarget.type&&this.dragTarget.featureId===i?this.dragTarget:{type:"none"},a="coordinate"===s.type?s.coordinateIndex:this.dragCoordinate.getDraggableIndex(t,i),d="resize"===s.type?s.coordinateIndex:this.dragCoordinateResizeFeature.getDraggableIndex(t,i),u=(null==r?void 0:r.resizable)&&-1!==d,h=(null==r?void 0:r.draggable)&&-1!==a,l=r&&"object"==typeof r.midpoints&&r.midpoints.draggable,p=(null==o?void 0:o.draggable)&&("feature"===s.type||this.dragFeature.canDrag(t,i));if(u)return this.setCursor(this.cursors.dragStart),this.dragCoordinateResizeFeature.startDragging(i,d),void e(!1);if(h)return this.setCursor(this.cursors.dragStart),this.dragCoordinate.startDragging(i,a),void e(!1);if(l){var g="midpoint"===s.type?s.midPointId:this.midPoints.getNearestMidPoint(t);if(this.selected.length&&g){this.midPoints.insert({featureId:i,midPointId:g}),this.onFinish(this.selected[0],{action:c,mode:this.mode});var f=this.dragCoordinate.getDraggableIndex(t,i);return this.dragCoordinate.startDragging(i,f),void e(!1)}}if(p)return this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(t,i),void e(!1);this.setCursor("unset")}}}},i.onDrag=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDrag,t)){var i=this.selected[0];if(i){var n=this.readFeature.getProperties(i),o=this.flags[n.mode],r=!0===(o&&o.feature&&o.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){if(o&&o.feature&&o.feature.rotateable&&this.canRotate(t))return e(!1),void this.rotateFeature.rotate(t,i);if(o&&o.feature&&o.feature.scaleable&&this.canScale(t))return e(!1),void this.scaleFeature.scale(t,i);if(this.dragCoordinateResizeFeature.isDragging()&&o.feature&&o.feature.coordinates&&o.feature.coordinates.resizable){if("globe"===this.projection)throw new Error("Globe is currently unsupported projection for resizable");return e(!1),void this.dragCoordinateResizeFeature.drag(t,o.feature.coordinates.resizable)}if(this.dragCoordinate.isDragging()){var s,a=null==(s=o.feature)||null==(s=s.coordinates)?void 0:s.snappable,d={toCoordinate:!1};return!0===a?d={toCoordinate:!0}:"object"==typeof a&&(d=a),void this.dragCoordinate.drag(t,r,d)}this.dragFeature.isDragging()?this.dragFeature.drag(t):e(!0)}}}},i.onDragEnd=function(t,e){this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&(this.setCursor(this.cursors.dragEnd),this.dragCoordinate.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinate"}):this.dragFeature.isDragging()?this.onFinish(this.selected[0],{mode:this.mode,action:"dragFeature"}):this.dragCoordinateResizeFeature.isDragging()&&this.onFinish(this.selected[0],{mode:this.mode,action:"dragCoordinateResize"}),this.dragCoordinate.stopDragging(),this.dragFeature.stopDragging(),this.dragCoordinateResizeFeature.stopDragging(),this.rotateFeature.reset(),this.scaleFeature.reset(),e(!0))},i.onMouseMove=function(t){var e=this.selected[0];if(e){if(!(this.dragFeature.isDragging()||this.dragCoordinate.isDragging()||this.dragCoordinateResizeFeature.isDragging())){var i=this.getSelectedFlags(e).featureFlags;if(i){var n=void 0,o=i.coordinates;if(null!=o&&o.midpoints&&(n=this.midPoints.getNearestMidPoint(t))&&(this.dragTarget={type:"midpoint",featureId:e,midPointId:n},this.setCursor(this.cursors.insertMidpoint)),o&&o.draggable){var r=this.dragCoordinate.getDraggable(t,e),s=r.index,a=r.dist;if(s>-1){if(n&&this.pixelDistance.measure(t,this.readFeature.getGeometry(n).coordinates)<a)return;return this.dragTarget={type:"coordinate",featureId:e,coordinateIndex:s},void this.setCursor(this.cursors.pointerOver)}}if(o&&o.resizable){var d=this.dragCoordinateResizeFeature.getDraggableIndex(t,e);if(d>-1)return this.dragTarget={type:"resize",featureId:e,coordinateIndex:d},void this.setCursor(this.cursors.pointerOver)}if(i.draggable&&this.dragFeature.canDrag(t,e)){if(n)return;return this.dragTarget={type:"feature",featureId:e},void this.setCursor(this.cursors.pointerOver)}n||this.clearDragTargetAndCursor()}else this.clearDragTargetAndCursor()}}else this.clearDragTargetAndCursor()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});if(t.properties.mode===this.mode&&"Point"===t.geometry.type){if(t.properties[g.SELECTION_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.selectionPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,e.pointWidth,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectionPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,t),e.zIndex=30,e;if(t.properties[g.MID_POINT])return e.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.midPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,e.pointOutlineColor,t),e.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.midPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,t),e.zIndex=50,e}else if(t.properties[g.SELECTED]){if("Point"===t.geometry.type&&t.properties[f.MARKER])return e.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,p,t),e.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,t),e.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,t),e;if("Polygon"===t.geometry.type)return e.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,e.polygonFillColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,e.polygonOutlineColor,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPolygonOutlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,e.polygonFillOpacity,t),e.zIndex=y,e;if("LineString"===t.geometry.type)return e.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,e.lineStringColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,e.lineStringWidth,t),e.zIndex=y,e;if("Point"===t.geometry.type)return e.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,e.pointWidth,t),e.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.selectedPointOpacity,1,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=y,e}return e},i.afterFeatureUpdated=function(t){if(this.selected.length&&t.id===this.selected[0]){var e,i,n=this.flags[t.properties.mode];if(null==n||null==(e=n.feature)||!e.coordinates)return;var o=t.geometry.type,r=t.id;if(this.selectionPoints.delete(),this.midPoints.delete(),"LineString"!==o&&"Polygon"!==o)return;var s=t.geometry.coordinates;this.selectionPoints.create({featureCoordinates:s,featureId:r}),null!=n&&null!=(i=n.feature)&&null!=(i=i.coordinates)&&i.midpoints&&this.midPoints.create({featureCoordinates:s,featureId:r})}},e}(M),Fe=/*#__PURE__*/function(t){function e(){for(var e,i=arguments.length,n=new Array(i),o=0;o<i;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).type=P.Static,e.mode="static",e}r(e,t);var i=e.prototype;return i.start=function(){},i.stop=function(){},i.onKeyUp=function(){},i.onKeyDown=function(){},i.onClick=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.onMouseMove=function(){},i.cleanUp=function(){},i.styleFeature=function(){return o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0})},e}(x);function xe(t,e,i,n,o){for(;n>i;){if(n-i>600){var r=n-i+1,s=e-i+1,a=Math.log(r),d=.5*Math.exp(2*a/3),u=.5*Math.sqrt(a*d*(r-d)/r)*(s-r/2<0?-1:1);xe(t,e,Math.max(i,Math.floor(e-s*d/r+u)),Math.min(n,Math.floor(e+(r-s)*d/r+u)),o)}var h=t[e],l=i,c=n;for(Me(t,i,e),o(t[n],h)>0&&Me(t,i,n);l<c;){for(Me(t,l,c),l++,c--;o(t[l],h)<0;)l++;for(;o(t[c],h)>0;)c--}0===o(t[i],h)?Me(t,i,c):Me(t,++c,n),c<=e&&(i=c+1),e<=c&&(n=c-1)}}function Me(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function we(t,e){Oe(t,0,t.children.length,e,t)}function Oe(t,e,i,n,o){o||(o=Re([])),o.minX=Infinity,o.minY=Infinity,o.maxX=-Infinity,o.maxY=-Infinity;for(var r=e;r<i;r++){var s=t.children[r];Ee(o,t.leaf?n(s):s)}return o}function Ee(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 De(t,e){return t.minX-e.minX}function ke(t,e){return t.minY-e.minY}function be(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function _e(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Te(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Ne(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Re(t){return{children:t,height:1,leaf:!0,minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}}function Ue(t,e,i,n,o){for(var r=[e,i];r.length;)if(!((i=r.pop())-(e=r.pop())<=n)){var s=e+Math.ceil((i-e)/n/2)*n;xe(t,s,e,i,o),r.push(e,s,s,i)}}var We=/*#__PURE__*/function(){function t(t){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}var e=t.prototype;return e.search=function(t){var e=this.data,i=[];if(!Ne(t,e))return i;for(var n=this.toBBox,o=[];e;){for(var r=0;r<e.children.length;r++){var s=e.children[r],a=e.leaf?n(s):s;Ne(t,a)&&(e.leaf?i.push(s):Te(t,a)?this._all(s,i):o.push(s))}e=o.pop()}return i},e.collides=function(t){var e=this.data;if(Ne(t,e))for(var i=[];e;){for(var n=0;n<e.children.length;n++){var o=e.children[n],r=e.leaf?this.toBBox(o):o;if(Ne(t,r)){if(e.leaf||Te(t,r))return!0;i.push(o)}}e=i.pop()}return!1},e.load=function(t){if(t.length<this._minEntries)for(var e=0;e<t.length;e++)this.insert(t[e]);else{var i=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===i.height)this._splitRoot(this.data,i);else{if(this.data.height<i.height){var n=this.data;this.data=i,i=n}this._insert(i,this.data.height-i.height-1,!0)}else this.data=i}},e.insert=function(t){this._insert(t,this.data.height-1)},e.clear=function(){this.data=Re([])},e.remove=function(t){for(var e,i,n=this.data,o=this.toBBox(t),r=[],s=[],a=!1;n||r.length;){if(n||(n=r.pop(),i=r[r.length-1],e=s.pop(),a=!0),n.leaf){var d=n.children.indexOf(t);-1!==d&&(n.children.splice(d,1),r.push(n),this._condense(r))}a||n.leaf||!Te(n,o)?i?(e++,n=i.children[e],a=!1):n=null:(r.push(n),s.push(e),e=0,i=n,n=n.children[0])}},e.toBBox=function(t){return t},e.compareMinX=function(t,e){return t.minX-e.minX},e.compareMinY=function(t,e){return t.minY-e.minY},e._all=function(t,e){for(var i=[];t;)t.leaf?e.push.apply(e,t.children):i.push.apply(i,t.children),t=i.pop();return e},e._build=function(t,e,i,n){var o,r=i-e+1,s=this._maxEntries;if(r<=s)return we(o=Re(t.slice(e,i+1)),this.toBBox),o;n||(n=Math.ceil(Math.log(r)/Math.log(s)),s=Math.ceil(r/Math.pow(s,n-1))),(o=Re([])).leaf=!1,o.height=n;var a=Math.ceil(r/s),d=a*Math.ceil(Math.sqrt(s));Ue(t,e,i,d,this.compareMinX);for(var u=e;u<=i;u+=d){var h=Math.min(u+d-1,i);Ue(t,u,h,a,this.compareMinY);for(var l=u;l<=h;l+=a){var c=Math.min(l+a-1,h);o.children.push(this._build(t,l,c,n-1))}}return we(o,this.toBBox),o},e._chooseSubtree=function(t,e,i,n){for(;n.push(e),!e.leaf&&n.length-1!==i;){for(var o=Infinity,r=Infinity,s=void 0,a=0;a<e.children.length;a++){var d=e.children[a],u=be(d),h=(l=t,c=d,(Math.max(c.maxX,l.maxX)-Math.min(c.minX,l.minX))*(Math.max(c.maxY,l.maxY)-Math.min(c.minY,l.minY))-u);h<r?(r=h,o=u<o?u:o,s=d):h===r&&u<o&&(o=u,s=d)}e=s||e.children[0]}var l,c;return e},e._insert=function(t,e,i){var n=i?t:this.toBBox(t),o=[],r=this._chooseSubtree(n,this.data,e,o);for(r.children.push(t),Ee(r,n);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)},e._split=function(t,e){var i=t[e],n=i.children.length,o=this._minEntries;this._chooseSplitAxis(i,o,n);var r=this._chooseSplitIndex(i,o,n),s=Re(i.children.splice(r,i.children.length-r));s.height=i.height,s.leaf=i.leaf,we(i,this.toBBox),we(s,this.toBBox),e?t[e-1].children.push(s):this._splitRoot(i,s)},e._splitRoot=function(t,e){this.data=Re([t,e]),this.data.height=t.height+1,this.data.leaf=!1,we(this.data,this.toBBox)},e._chooseSplitIndex=function(t,e,i){for(var n,o,r,s,a,d,u,h=Infinity,l=Infinity,c=e;c<=i-e;c++){var p=Oe(t,0,c,this.toBBox),g=Oe(t,c,i,this.toBBox),f=(o=p,r=g,s=Math.max(o.minX,r.minX),a=Math.max(o.minY,r.minY),d=Math.min(o.maxX,r.maxX),u=Math.min(o.maxY,r.maxY),Math.max(0,d-s)*Math.max(0,u-a)),y=be(p)+be(g);f<h?(h=f,n=c,l=y<l?y:l):f===h&&y<l&&(l=y,n=c)}return n||i-e},e._chooseSplitAxis=function(t,e,i){var n=t.leaf?this.compareMinX:De,o=t.leaf?this.compareMinY:ke;this._allDistMargin(t,e,i,n)<this._allDistMargin(t,e,i,o)&&t.children.sort(n)},e._allDistMargin=function(t,e,i,n){t.children.sort(n);for(var o=this.toBBox,r=Oe(t,0,e,o),s=Oe(t,i-e,i,o),a=_e(r)+_e(s),d=e;d<i-e;d++){var u=t.children[d];Ee(r,t.leaf?o(u):u),a+=_e(r)}for(var h=i-e-1;h>=e;h--){var l=t.children[h];Ee(s,t.leaf?o(l):l),a+=_e(s)}return a},e._adjustParentBBoxes=function(t,e,i){for(var n=i;n>=0;n--)Ee(e[n],t)},e._condense=function(t){for(var e,i=t.length-1;i>=0;i--)0===t[i].children.length?i>0?(e=t[i-1].children).splice(e.indexOf(t[i]),1):this.clear():we(t[i],this.toBBox)},t}(),Le=/*#__PURE__*/function(){function t(t){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new We(t&&t.maxEntries?t.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}var e=t.prototype;return e.setMaps=function(t,e){this.idToNode.set(t.id,e),this.nodeToId.set(e,t.id)},e.toBBox=function(t){var e,i=[],n=[];if("Polygon"===t.geometry.type)e=t.geometry.coordinates[0];else if("LineString"===t.geometry.type)e=t.geometry.coordinates;else{if("Point"!==t.geometry.type)throw new Error("Not a valid feature to turn into a bounding box");e=[t.geometry.coordinates]}for(var o=0;o<e.length;o++)n.push(e[o][1]),i.push(e[o][0]);var r=Math.min.apply(Math,n),s=Math.max.apply(Math,n);return{minX:Math.min.apply(Math,i),minY:r,maxX:Math.max.apply(Math,i),maxY:s}},e.insert=function(t){if(this.idToNode.get(String(t.id)))throw new Error("Feature already exists");var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.load=function(t){var e=this,i=[],n=new Set;t.forEach(function(t){var o=e.toBBox(t);if(e.setMaps(t,o),n.has(String(t.id)))throw new Error("Duplicate feature ID found "+t.id);n.add(String(t.id)),i.push(o)}),this.tree.load(i)},e.update=function(t){this.remove(t.id);var e=this.toBBox(t);this.setMaps(t,e),this.tree.insert(e)},e.remove=function(t){var e=this.idToNode.get(t);if(!e)throw new Error(t+" not inserted into the spatial index");this.tree.remove(e)},e.clear=function(){this.tree.clear()},e.search=function(t){var e=this;return this.tree.search(this.toBBox(t)).map(function(t){return e.nodeToId.get(t)})},e.collides=function(t){return this.tree.collides(this.toBBox(t))},t}(),Ae={getId:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},isValidId:function(t){return"string"==typeof t&&36===t.length}},Be={target:"geometry"},ze={target:"properties"},He=/*#__PURE__*/function(){function t(t){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=function(){},this.store={},this.spatialIndex=new Le,this.tracked=!t||!1!==t.tracked,this.idStrategy=t&&t.idStrategy?t.idStrategy:Ae}var e=t.prototype;return e.clone=function(t){return JSON.parse(JSON.stringify(t))},e.getId=function(){return this.idStrategy.getId()},e.has=function(t){return Boolean(this.store[t])},e.load=function(t,e,i,n){var o=this;if(0===t.length)return[];var r=this.clone(t),s=[],a=[];r=r.filter(function(t){null==t.id&&(t.id=o.idStrategy.getId());var i=t.id;if(e){var n=e(t);if(!n.valid)return s.push({id:i,valid:!1,reason:n.reason}),!1}if(o.tracked){if(t.properties.createdAt){if(!C(t.properties.createdAt))return s.push({id:t.id,valid:!1,reason:"createdAt is not a valid numeric timestamp"}),!1}else t.properties.createdAt=+new Date;if(t.properties.updatedAt){if(!C(t.properties.updatedAt))return s.push({id:t.id,valid:!1,reason:"updatedAt is not a valid numeric timestamp"}),!1}else t.properties.updatedAt=+new Date}return o.has(i)?(s.push({id:i,valid:!1,reason:"Feature already exists with this id: "+i}),!1):(o.store[i]=t,a.push(t),s.push({id:i,valid:!0}),!0)}),this.spatialIndex.load(r);var d=a.map(function(t){return t.id});return d.length>0&&(this._onChange(d,"create",n),i&&a.forEach(function(t){i(t)})),s},e.search=function(t,e){var i=this,n=this.spatialIndex.search(t).map(function(t){return i.store[t]});return this.clone(e?n.filter(e):n)},e.registerOnChange=function(t){this._onChange=function(e,i,n){t(e,i,n)}},e.getGeometryCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get geometry copy");return this.clone(e.geometry)},e.getPropertiesCopy=function(t){var e=this.store[t];if(!e)throw new Error("No feature with this id ("+t+"), can not get properties copy");return this.clone(e.properties)},e.updateProperty=function(t,e){var i=this,n=new Set;t.forEach(function(t){var e=t.id,o=t.property,r=t.value,s=i.store[e];if(!s)throw new Error("No feature with this ("+e+"), can not update geometry");s.properties[o]!==r&&(n.add(e),void 0===r?delete s.properties[o]:s.properties[o]=r,i.tracked&&(s.properties.updatedAt=+new Date))}),this._onChange&&n.size>0&&this._onChange(Array.from(n),"update",e?o({},e,ze):ze)},e.updateGeometry=function(t,e){var i=this,n=new Set;t.forEach(function(t){var e=t.id,o=t.geometry;n.add(e);var r=i.store[e];if(!r)throw new Error("No feature with this ("+e+"), can not update geometry");r.geometry=i.clone(o),i.spatialIndex.update(r),i.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&n.size>0&&this._onChange(Array.from(n),"update",e?o({},e,Be):Be)},e.create=function(t,e){var i=this,n=[];return t.forEach(function(t){var e,r=t.geometry,s=t.properties,a=o({},s);i.tracked&&(e=+new Date,s?(a.createdAt="number"==typeof s.createdAt?s.createdAt:e,a.updatedAt="number"==typeof s.updatedAt?s.updatedAt:e):a={createdAt:e,updatedAt:e});var d=i.getId(),u={id:d,type:"Feature",geometry:r,properties:a};i.store[d]=u,i.spatialIndex.insert(u),n.push(d)}),this._onChange&&this._onChange([].concat(n),"create",e),n},e.delete=function(t,e){var i=this;t.forEach(function(t){if(!i.store[t])throw new Error("No feature with id "+t+", can not delete");delete i.store[t],i.spatialIndex.remove(t)}),this._onChange&&this._onChange([].concat(t),"delete",e)},e.copy=function(t){return this.clone(this.store[t])},e.copyAll=function(){var t=this;return this.clone(Object.keys(this.store).map(function(e){return t.store[e]}))},e.copyAllWhere=function(t){var e=this;return this.clone(Object.keys(this.store).map(function(t){return e.store[t]}).filter(function(e){return e.properties&&t(e.properties)}))},e.clear=function(t){var e=Object.keys(this.store);this.store={},this.spatialIndex.clear(),this._onChange(e,"delete",t)},e.size=function(){return Object.keys(this.store).length},t}();function Ge(t){var e=t.coordinates,i=0;if(e&&e.length>0){i+=Math.abs(Ke(e[0]));for(var n=1;n<e.length;n++)i-=Math.abs(Ke(e[n]))}return i}var Ve=20294876564838.72,je=Math.PI/180;function Ke(t){var e=t.length;if(e<=2)return 0;for(var i=0,n=0;n<e;)i+=(t[n+2>=e?(n+2)%e:n+2][0]*je-t[n][0]*je)*Math.sin(t[n+1===e?0:n+1][1]*je),n++;return i*Ve}var Ye="Feature is smaller than the minimum area",Xe="Feature is not a Polygon or LineString",qe="Feature intersects itself";function Ze(t,e,i){var n=Pt(t,e),o=Pt(e,i)-n;return o<0&&(o+=360),180-Math.abs(o-90-90)}var Je={cancel:"Escape",finish:"Enter"},$e={start:"crosshair",close:"pointer"},Qe=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="angled-rectangle",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=Je,i.cursors=$e,i.mouseMove=!1,i.mutateFeature=void 0,i.readFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents))},i.close=function(){var t;if(void 0!==this.currentId&&this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),context:{updateType:d.Finish,action:u}})){var e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:u})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e=[];if(1===this.currentCoordinate)e=this.getUpdateForSecondCoordinate(t);else{if(2!==this.currentCoordinate)return;e=this.getNewSecondAndThirdCoordinates(t)}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:e,context:{updateType:d.Provisional}})}},i.getUpdateForSecondCoordinate=function(t){return[{type:tt,index:1,coordinate:[t.lng,t.lat]},{type:tt,index:2,coordinate:[t.lng,t.lat]}]},i.getNewSecondAndThirdCoordinates=function(t){if(!this.currentId)throw new Error("No current feature being drawn");var e,i,n,o,r=this.readFeature.getCoordinate(this.currentId,0),s=this.readFeature.getCoordinate(this.currentId,1),a=ne(r,s,this.coordinatePrecision,this.project,this.unproject),d=R(r[0],r[1]),u=R(a[0],a[1]),h=R(s[0],s[1]),l=R(t.lng,t.lat),c=at(l,d)<at(l,h),p=Ze(d,u,l),g=c?90-p:Ze(d,u,l)-90,f=at(u,l),y=Math.cos(E(g))*f,v=Pt(d,h)+("right"==((o=((n=l).x-(i=h).x)*((e=d).y-i.y)-(n.y-i.y)*(e.x-i.x))>1e-10?"left":o<-1e-10?"right":"left")?-90:90),m=mt(d,y,v),C=mt(h,y,v),P=U(m.x,m.y),I=U(C.x,C.y);return[{type:tt,index:2,coordinate:[b(I.lng,this.coordinatePrecision),b(I.lat,this.coordinatePrecision)]},{type:tt,index:3,coordinate:[b(P.lng,this.coordinatePrecision),b(P.lat,this.coordinatePrecision)]}]},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e,i=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(e={mode:this.mode},e[f.CURRENTLY_DRAWING]=!0,e)});this.currentId=i.id,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){var n=this.readFeature.getCoordinate(this.currentId,0);if(dt([t.lng,t.lat],n))return;if(!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:tt,index:1,coordinate:[t.lng,t.lat]},{type:Q,index:1,coordinate:[t.lng,t.lat]}],context:{updateType:d.Commit}}))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){if(t.key===this.keyEvents.cancel)this.cleanUp();else if(t.key===this.keyEvents.finish){if(this.currentCoordinate<2)return void this.cleanUp();this.close()}},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId;this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},e}(x);function ti(t,e,i){return(e.x-t.x)*(i.y-t.y)-(e.y-t.y)*(i.x-t.x)<=0}var ei={cancel:"Escape",finish:"Enter"},ii={start:"crosshair",close:"pointer"},ni=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sector",i.currentCoordinate=0,i.currentId=void 0,i.keyEvents=ei,i.direction=void 0,i.arcPoints=64,i.cursors=ii,i.mouseMove=!1,i.readFeature=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.arcPoints&&(this.arcPoints=e.arcPoints)},i.close=function(){var t;if(void 0!==this.currentId&&this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:it},context:{updateType:d.Finish,action:u}})){var e=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:u})}},i.getSectorCoordinates=function(t){var e=this.readFeature.getCoordinates(this.currentId),i=e[0],n=e[1],o=[t.lng,t.lat],r=R(i[0],i[1]),s=R(n[0],n[1]),a=R(o[0],o[1]);if(void 0===this.direction){var d=ti(r,s,a);this.direction=d?"clockwise":"anticlockwise"}var u,h=at(r,s),l=Pt(r,s),c=Pt(r,a),p=this.arcPoints,g=[i],f=It(l),y=It(c);"anticlockwise"===this.direction?(u=y-f)<0&&(u+=360):(u=f-y)<0&&(u+=360);var v=("anticlockwise"===this.direction?1:-1)*u/p;g.push(n);for(var m=0;m<=p;m++){var C=mt(r,h,f+m*v),P=U(C.x,C.y),I=P.lat,S=[b(P.lng,this.coordinatePrecision),b(I,this.coordinatePrecision)];S[0]!==g[g.length-1][0]&&S[1]!==g[g.length-1][1]&&g.push(S)}return g.push(i),g},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentId&&0!==this.currentCoordinate){var e;if(1===this.currentCoordinate)e=[{type:tt,index:1,coordinate:[t.lng,t.lat]},{type:tt,index:2,coordinate:[t.lng,t.lat]}];else{if(2!==this.currentCoordinate)return;var i=this.getSectorCoordinates(t);if(!i)return;e={type:it,coordinates:[i]}}this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:e,context:{updateType:d.Provisional}})}},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e,i=this.mutateFeature.createPolygon({coordinates:[[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat],[t.lng,t.lat]],properties:(e={mode:this.mode},e[f.CURRENTLY_DRAWING]=!0,e)});this.currentId=null==i?void 0:i.id,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentId){if(this.readFeature.coordinateAtIndexIsIdentical({featureId:this.currentId,index:0,newCoordinate:[t.lng,t.lat]}))return;if(!this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:[{type:tt,index:1,coordinate:[t.lng,t.lat]},{type:tt,index:2,coordinate:[t.lng,t.lat]}],context:{updateType:d.Provisional}}))return;this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId;this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t)},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&"Polygon"===t.geometry.type&&(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.currentId=void 0,this.direction=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},e}(x),oi={cancel:"Escape",finish:"Enter"},ri={start:"crosshair",close:"pointer"},si=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="sensor",i.currentCoordinate=0,i.currentId=void 0,i.currentInitialArcId=void 0,i.currentStartingPointId=void 0,i.keyEvents=oi,i.direction=void 0,i.arcPoints=64,i.cursors=ri,i.mouseMove=!1,i.readFeature=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.arcPoints&&(this.arcPoints=e.arcPoints)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(this.mouseMove=!0,this.setCursor(this.cursors.start),void 0!==this.currentInitialArcId&&void 0!==this.currentStartingPointId&&0!==this.currentCoordinate)if(2===this.currentCoordinate){var e=this.getUpdatedLineStringCoordinates(t);if(!e)return;this.mutateFeature.updateLineString({featureId:this.currentInitialArcId,coordinateMutations:{type:it,coordinates:e},context:{updateType:d.Provisional}})}else if(3===this.currentCoordinate){var i=this.getUpdatedPolygonCoordinates(t);if(!i)return;if(this.currentId)this.mutateFeature.updatePolygon({featureId:this.currentId,coordinateMutations:{type:it,coordinates:[i]},context:{updateType:d.Provisional}});else{var n,o=this.mutateFeature.createPolygon({coordinates:i,properties:(n={mode:this.mode},n[f.CURRENTLY_DRAWING]=!0,n)});if(!o)return;this.currentId=o.id}}},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t))if(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(t),this.mouseMove=!1,0===this.currentCoordinate){var e=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:{mode:this.mode}});if(!e)return;this.currentStartingPointId=e.id,this.currentCoordinate++,this.setDrawing()}else if(1===this.currentCoordinate&&this.currentStartingPointId){var i=this.mutateFeature.createLineString({coordinates:[[t.lng,t.lat],[t.lng,t.lat]],properties:{mode:this.mode}});if(!i)return;this.currentInitialArcId=i.id,this.currentCoordinate++}else 2===this.currentCoordinate&&this.currentStartingPointId?this.currentCoordinate++:3===this.currentCoordinate&&this.currentStartingPointId&&this.close()},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&this.close()},i.onKeyDown=function(){},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.mutateFeature.deleteFeatureIfPresent(this.currentId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return t.properties.mode===this.mode&&("Polygon"===t.geometry.type?(e.polygonFillColor=this.getHexColorStylingValue(this.styles.fillColor,e.polygonFillColor,t),e.polygonOutlineColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.polygonOutlineWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.outlineOpacity,1,t),e.polygonFillOpacity=this.getNumericStylingValue(this.styles.fillOpacity,e.polygonFillOpacity,t),e.zIndex=y):"LineString"===t.geometry.type?(e.lineStringColor=this.getHexColorStylingValue(this.styles.outlineColor,e.polygonOutlineColor,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.outlineWidth,e.polygonOutlineWidth,t),e.zIndex=y):"Point"===t.geometry.type&&(e.pointColor=this.getHexColorStylingValue(this.styles.centerPointColor,e.pointColor,t),e.pointOpacity=this.getNumericStylingValue(this.styles.centerPointOpacity,1,t),e.pointWidth=this.getNumericStylingValue(this.styles.centerPointWidth,e.pointWidth,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.centerPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.centerPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.centerPointOutlineWidth,e.pointOutlineWidth,t),e.zIndex=20)),e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return q(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.mutateFeature.deleteFeatureIfPresent(this.currentStartingPointId),this.mutateFeature.deleteFeatureIfPresent(this.currentInitialArcId),this.currentStartingPointId=void 0,this.direction=void 0,this.currentId=void 0,this.currentCoordinate=0,"drawing"===this.state&&this.setStarted())},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate})},i.close=function(){if(void 0!==this.currentStartingPointId){var t,e=this.currentStartingPointId,i=this.currentInitialArcId;if(this.currentId&&!this.mutateFeature.updatePolygon({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),coordinateMutations:{coordinates:this.readFeature.getGeometry(this.currentId).coordinates,type:it},context:{updateType:d.Finish,action:u}}))return;var n=this.currentId;this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(i),this.currentCoordinate=0,this.currentStartingPointId=void 0,this.currentInitialArcId=void 0,this.currentId=void 0,this.direction=void 0,"drawing"===this.state&&this.setStarted(),n&&this.onFinish(n,{mode:this.mode,action:u})}},i.getUpdatedPolygonCoordinates=function(t){if(!(void 0===this.currentInitialArcId||void 0===this.currentStartingPointId||this.currentCoordinate<3)){var e=this.readFeature.getCoordinates(this.currentInitialArcId);if(!(e.length<2)&&this.direction){var i=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,n=e[0],o=e[e.length-1],r=R(t.lng,t.lat),s=R(n[0],n[1]),a=R(o[0],o[1]),d=R(i[0],i[1]),u=at(d,s),h=at(d,r)<u?s:r,l=Pt(d,r),c=Pt(d,s),p=Pt(d,a),g=It(c),f=It(p),y=It(l);if(!this.notInSector({normalizedCursor:y,normalizedStart:g,normalizedEnd:f,direction:this.direction})){for(var v=this.getDeltaBearing(this.direction,g,f),m=this.arcPoints,C=("anticlockwise"===this.direction?1:-1)*v/m,P=at(d,h),I=[],S=0;S<=m;S++){var F=mt(d,P,g+S*C),x=U(F.x,F.y),M=x.lat,w=[b(x.lng,this.coordinatePrecision),b(M,this.coordinatePrecision)];w[0]!==e[e.length-1][0]&&w[1]!==e[e.length-1][1]&&I.unshift(w)}return e.push.apply(e,I),e.push(e[0]),e}}}},i.getUpdatedLineStringCoordinates=function(t){if(!(void 0===this.currentInitialArcId||void 0===this.currentStartingPointId||this.currentCoordinate<2)){var e=this.readFeature.getGeometry(this.currentInitialArcId).coordinates,i=this.readFeature.getGeometry(this.currentStartingPointId).coordinates,n=e[0],o=[t.lng,t.lat],r=R(n[0],n[1]),s=R(o[0],o[1]),a=R(i[0],i[1]),d=at(a,r);if(void 0===this.direction){var u=ti(a,r,s);this.direction=u?"clockwise":"anticlockwise"}var h,l=Pt(a,r),c=Pt(a,s),p=this.arcPoints,g=[n],f=It(l),y=It(c);"anticlockwise"===this.direction?(h=y-f)<0&&(h+=360):(h=f-y)<0&&(h+=360);for(var v=("anticlockwise"===this.direction?1:-1)*h/p,m=0;m<=p;m++){var C=mt(a,d,f+m*v),P=U(C.x,C.y),I=P.lat,S=[b(P.lng,this.coordinatePrecision),b(I,this.coordinatePrecision)];S[0]!==g[g.length-1][0]&&S[1]!==g[g.length-1][1]&&g.push(S)}return g}},i.getDeltaBearing=function(t,e,i){var n;return"anticlockwise"===t?(n=i-e)<0&&(n+=360):(n=e-i)<0&&(n+=360),n},i.notInSector=function(t){var e=t.normalizedCursor,i=t.normalizedStart,n=t.normalizedEnd;return"clockwise"===t.direction?i<=n?e>=i&&e<=n:e>=i||e<=n:i>=n?e<=i&&e>=n:e<=i||e>=n},e}(x),ai=function(t){var e=this,i=t.name,n=t.callback,o=t.unregister,r=t.register;this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=i,this.register=function(){e.registered||(e.registered=!0,r(n))},this.unregister=function(){e.register&&(e.registered=!1,o(n))},this.callback=n},di={__proto__:null,GeoJSONStore:He,TerraDrawBaseDrawMode:x,TerraDrawBaseSelectMode:M,TerraDrawBaseAdapter:/*#__PURE__*/function(){function t(t){this._nextKeyUpIsContextMenu=!1,this._lastPointerDownEventTarget=void 0,this._ignoreMismatchedPointerEvents=!1,this._minPixelDragDistance=void 0,this._minPixelDragDistanceDrawing=void 0,this._minPixelDragDistanceSelecting=void 0,this._lastDrawEvent=void 0,this._coordinatePrecision=void 0,this._heldKeys=new Set,this._listeners=[],this._dragState="not-dragging",this._currentModeCallbacks=void 0,this._ignoreMismatchedPointerEvents="boolean"==typeof t.ignoreMismatchedPointerEvents&&t.ignoreMismatchedPointerEvents,this._minPixelDragDistance="number"==typeof t.minPixelDragDistance?t.minPixelDragDistance:1,this._minPixelDragDistanceSelecting="number"==typeof t.minPixelDragDistanceSelecting?t.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing="number"==typeof t.minPixelDragDistanceDrawing?t.minPixelDragDistanceDrawing:8,this._coordinatePrecision="number"==typeof t.coordinatePrecision?t.coordinatePrecision:9}var e=t.prototype;return e.getButton=function(t){return-1===t.button?"neither":0===t.button?"left":1===t.button?"middle":2===t.button?"right":"neither"},e.getMapElementXYPosition=function(t){var e=this.getMapEventElement(t.type).getBoundingClientRect();return{containerX:t.clientX-e.left,containerY:t.clientY-e.top}},e.getDrawEventFromEvent=function(t,e){void 0===e&&(e=!1);var i=this.getLngLatFromEvent(t);if(!i)return null;var n=i.lng,o=i.lat,r=this.getMapElementXYPosition(t),s=r.containerX,a=r.containerY,d=this.getButton(t),u=Array.from(this._heldKeys);return{lng:b(n,this._coordinatePrecision),lat:b(o,this._coordinatePrecision),containerX:s,containerY:a,button:d,heldKeys:u,isContextMenu:e}},e.register=function(t){this._currentModeCallbacks=t,this._listeners=this.getAdapterListeners(),this._listeners.forEach(function(t){t.register()})},e.getCoordinatePrecision=function(){return this._coordinatePrecision},e.getAdapterListeners=function(){var t=this;return[new ai({name:"pointerdown",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){var i=t.getDrawEventFromEvent(e);i&&(t._dragState="pre-dragging",t._lastDrawEvent=i,t._lastPointerDownEventTarget=e.target?e.target:void 0)}},register:function(e){t.getMapEventElement("pointerdown").addEventListener("pointerdown",e)},unregister:function(e){t.getMapEventElement("pointerdown").removeEventListener("pointerdown",e)}}),new ai({name:"pointermove",callback:function(e){if(t._currentModeCallbacks&&e.isPrimary){e.preventDefault();var i=t.getDrawEventFromEvent(e);if(i)if("not-dragging"===t._dragState)t._currentModeCallbacks.onMouseMove(i),t._lastDrawEvent=i;else if("pre-dragging"===t._dragState){if(!t._lastDrawEvent)return;var n={x:t._lastDrawEvent.containerX,y:t._lastDrawEvent.containerY},o={x:i.containerX,y:i.containerY},r=t._currentModeCallbacks.getState(),s=at(n,o);if("drawing"===r?s<t._minPixelDragDistanceDrawing:"selecting"===r?s<t._minPixelDragDistanceSelecting:s<t._minPixelDragDistance)return;t._nextKeyUpIsContextMenu=!1,t._dragState="dragging",t._currentModeCallbacks.onDragStart(i,function(e){t.setDraggability.bind(t)(e)})}else"dragging"===t._dragState&&t._currentModeCallbacks.onDrag(i,function(e){t.setDraggability.bind(t)(e)})}},register:function(e){t.getMapEventElement("pointermove").addEventListener("pointermove",e)},unregister:function(e){t.getMapEventElement("pointermove").removeEventListener("pointermove",e)}}),new ai({name:"contextmenu",callback:function(e){t._currentModeCallbacks&&(e.preventDefault(),t._nextKeyUpIsContextMenu=!0)},register:function(e){t.getMapEventElement("contextmenu").addEventListener("contextmenu",e)},unregister:function(e){t.getMapEventElement("contextmenu").removeEventListener("contextmenu",e)}}),new ai({name:"pointerup",callback:function(e){if(t._currentModeCallbacks&&e.target===t.getMapEventElement("pointerup")&&(!t._ignoreMismatchedPointerEvents||t._lastPointerDownEventTarget===e.target)&&(t._lastPointerDownEventTarget=void 0,e.isPrimary)){var i=t.getDrawEventFromEvent(e);i&&("dragging"===t._dragState?t._currentModeCallbacks.onDragEnd(i,function(e){t.setDraggability.bind(t)(e)}):"not-dragging"!==t._dragState&&"pre-dragging"!==t._dragState||(t._nextKeyUpIsContextMenu&&(i.isContextMenu=!0,t._nextKeyUpIsContextMenu=!1),t._currentModeCallbacks.onClick(i)),t._dragState="not-dragging",t.setDraggability(!0))}},register:function(e){t.getMapEventElement("pointerup").addEventListener("pointerup",e)},unregister:function(e){t.getMapEventElement("pointerup").removeEventListener("pointerup",e)}}),new ai({name:"keyup",callback:function(e){t._currentModeCallbacks&&(t._heldKeys.delete(e.key),t._currentModeCallbacks.onKeyUp({key:e.key,heldKeys:Array.from(t._heldKeys),preventDefault:function(){return e.preventDefault()}}))},register:function(e){t.getMapEventElement("keyup").addEventListener("keyup",e)},unregister:function(e){t.getMapEventElement("keyup").removeEventListener("keyup",e)}}),new ai({name:"keydown",callback:function(e){t._currentModeCallbacks&&(t._heldKeys.add(e.key),t._currentModeCallbacks.onKeyDown({key:e.key,heldKeys:Array.from(t._heldKeys),preventDefault:function(){return e.preventDefault()}}))},register:function(e){t.getMapEventElement("keydown").addEventListener("keydown",e)},unregister:function(e){t.getMapEventElement("keydown").removeEventListener("keydown",e)}})]},e.unregister=function(){this._listeners.forEach(function(t){t.unregister()}),this.clear(),this._currentModeCallbacks=void 0,this._lastDrawEvent=void 0,this._lastPointerDownEventTarget=void 0,this._nextKeyUpIsContextMenu=!1},t}(),getDefaultStyling:function(){return{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0}},SELECT_PROPERTIES:g},ui={ValidationReasonFeatureNotPoint:zt,ValidationReasonFeatureInvalidCoordinates:Ht,ValidationReasonFeatureInvalidCoordinatePrecision:Gt,ValidationReasonFeatureNotPolygon:I,ValidationReasonFeatureHasHoles:V,ValidationReasonFeatureLessThanFourCoordinates:j,ValidationReasonFeatureHasInvalidCoordinates:K,ValidationReasonFeatureCoordinatesNotClosed:Y,ValidationReasonFeatureNotPolygonOrLineString:Xe,ValidationReasonFeatureSelfIntersects:qe,ValidationReasonFeatureLessThanMinSize:Ye,ValidationReasonModeMismatch:S},hi={cancel:"Escape",finish:"Enter"},li={start:"crosshair",close:"pointer"},ci=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="freehand-linestring",i.canClose=!1,i.currentId=void 0,i.minDistance=20,i.keyEvents=hi,i.cursors=li,i.preventNewFeature=!1,i.mutateFeature=void 0,i.readFeature=void 0,i.pixelDistance=void 0,i.closingPoints=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.minDistance&&(this.minDistance=e.minDistance),null===(null==e?void 0:e.keyEvents)?this.keyEvents={cancel:null,finish:null}:null!=e&&e.keyEvents&&(this.keyEvents=o({},this.keyEvents,e.keyEvents)),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors))},i.close=function(){var t;if(void 0!==this.currentId&&this.mutateFeature.updateLineString({featureId:this.currentId,propertyMutations:(t={},t[f.CURRENTLY_DRAWING]=void 0,t),context:{updateType:d.Finish,action:u}})){var e=this.currentId;this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0,"drawing"===this.state&&this.setStarted(),this.onFinish(e,{mode:this.mode,action:u})}},i.start=function(){this.setStarted(),this.setCursor(this.cursors.start)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onMouseMove=function(t){if(void 0!==this.currentId&&!1!==this.canClose){var e=this.readFeature.getCoordinate(this.currentId,-2),i=this.project(e[0],e[1]),n=at({x:i.x,y:i.y},{x:t.containerX,y:t.containerY}),o=this.readFeature.getCoordinate(this.currentId,-1),r=this.project(o[0],o[1]),s=at({x:r.x,y:r.y},{x:t.containerX,y:t.containerY});if(this.setCursor(s<this.pointerDistance?this.cursors.close:this.cursors.start),!(n<this.minDistance)){var a=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:[{type:Q,index:-1,coordinate:[t.lng,t.lat]}],context:{updateType:d.Provisional}});a&&this.closingPoints.update(a.geometry.coordinates)}}else this.setCursor(this.cursors.start)},i.onClick=function(t){if("right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)){if(this.preventNewFeature)return;if(!1===this.canClose){var e,i=this.mutateFeature.createLineString({coordinates:[[t.lng,t.lat],[t.lng,t.lat]],properties:(e={mode:this.mode},e[f.CURRENTLY_DRAWING]=!0,e)}),n=i.id;return this.closingPoints.create(i.geometry.coordinates),this.currentId=n,this.canClose=!0,void("drawing"!==this.state&&this.setDrawing())}this.close()}},i.onKeyDown=function(){},i.onKeyUp=function(t){t.key===this.keyEvents.cancel?this.cleanUp():t.key===this.keyEvents.finish&&!0===this.canClose&&this.close()},i.onDragStart=function(){},i.onDrag=function(){},i.onDragEnd=function(){},i.cleanUp=function(){var t=this.currentId;this.currentId=void 0,this.canClose=!1,"drawing"===this.state&&this.setStarted(),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.delete()},i.styleFeature=function(t){var e=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"LineString"===t.geometry.type&&t.properties.mode===this.mode?(e.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,e.lineStringColor,t),e.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,void 0===e.lineStringOpacity?1:e.lineStringOpacity,t),e.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,e.lineStringWidth,t),e.zIndex=y,e):"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode?(e.pointWidth=this.getNumericStylingValue(this.styles.closingPointWidth,e.pointWidth,t),e.pointOpacity=this.getNumericStylingValue(this.styles.closingPointOpacity,1,t),e.pointColor=this.getHexColorStylingValue(this.styles.closingPointColor,e.pointColor,t),e.pointOutlineColor=this.getHexColorStylingValue(this.styles.closingPointOutlineColor,e.pointOutlineColor,t),e.pointOutlineOpacity=this.getNumericStylingValue(this.styles.closingPointOutlineOpacity,1,t),e.pointOutlineWidth=this.getNumericStylingValue(this.styles.closingPointOutlineWidth,2,t),e.zIndex=50,e):e},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return wt(t,e.coordinatePrecision)})},i.afterFeatureUpdated=function(t){this.currentId===t.id&&(this.closingPoints.delete(),this.canClose=!1,this.currentId=void 0)},i.registerBehaviors=function(t){this.readFeature=new ut(t),this.mutateFeature=new nt(t,{validate:this.validate}),this.pixelDistance=new ft(t),this.closingPoints=new Rt(t,this.pixelDistance,this.mutateFeature,this.readFeature)},e}(x);function pi(t){if(null===t)return!0;if("boolean"==typeof t)return!0;if("string"==typeof t)return!0;if(void 0===t)return!1;if("number"==typeof t)return Number.isFinite(t);if("bigint"==typeof t)return!1;if("symbol"==typeof t)return!1;if("function"==typeof t)return!1;if(t instanceof RegExp)return!1;if(t instanceof Map)return!1;if(t instanceof Set)return!1;if(t instanceof Date)return!1;if("object"==typeof t&&null!==t&&!Array.isArray(t)){var e=Object.getPrototypeOf(t);if(e!==Object.prototype&&null!==e)return!1}if(ArrayBuffer.isView(t)&&!(t instanceof DataView))return!1;if(Array.isArray(t))for(var i,o=n(t);!(i=o()).done;)if(!pi(i.value))return!1;return"object"==typeof t&&Object.keys(t).every(function(e){return"string"==typeof e&&pi(t[e])})}var gi={create:"crosshair",dragStart:"grabbing",dragEnd:"crosshair"},fi=/*#__PURE__*/function(t){function e(e){var i;return(i=t.call(this,e,!0)||this).mode="marker",i.cursors=gi,i.editable=!1,i.editedFeatureId=void 0,i.pixelDistance=void 0,i.clickBoundingBox=void 0,i.pointSearch=void 0,i.mutateFeature=void 0,i.updateOptions(e),i}r(e,t);var i=e.prototype;return i.updateOptions=function(e){t.prototype.updateOptions.call(this,e),null!=e&&e.cursors&&(this.cursors=o({},this.cursors,e.cursors)),null!=e&&e.editable&&(this.editable=e.editable)},i.start=function(){this.setStarted(),this.setCursor(this.cursors.create)},i.stop=function(){this.cleanUp(),this.setStopped(),this.setCursor("unset")},i.onClick=function(t){"right"===t.button&&this.allowPointerEvent(this.pointerEvents.rightClick,t)||t.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,t)?this.onRightClick(t):"left"===t.button&&this.allowPointerEvent(this.pointerEvents.leftClick,t)&&this.onLeftClick(t)},i.onMouseMove=function(){},i.onKeyDown=function(){},i.onKeyUp=function(){},i.cleanUp=function(){this.editedFeatureId=void 0},i.onDragStart=function(t,e){if(this.allowPointerEvent(this.pointerEvents.onDragStart,t)){if(this.editable){var i=this.pointSearch.getNearestPointFeature(t);this.editedFeatureId=null==i?void 0:i.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),e(!1))}},i.onDrag=function(t,e){var i;this.allowPointerEvent(this.pointerEvents.onDrag,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:it,coordinates:[t.lng,t.lat]},propertyMutations:(i={},i[f.EDITED]=!0,i),context:{updateType:d.Provisional}})},i.onDragEnd=function(t,e){var i;if(this.allowPointerEvent(this.pointerEvents.onDragEnd,t)&&void 0!==this.editedFeatureId&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:(i={mode:this.mode},i[f.EDITED]=!1,i),context:{updateType:d.Finish,action:"edit"}})){var n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,e(!0),this.onFinish(n,{mode:this.mode,action:u})}},i.registerBehaviors=function(t){this.pixelDistance=new ft(t),this.clickBoundingBox=new gt(t),this.pointSearch=new jt(t,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new nt(t,{validate:this.validate})},i.styleFeature=function(t){var e,i,n,r=o({},{polygonFillColor:"#3f97e0",polygonOutlineColor:"#3f97e0",polygonOutlineWidth:4,polygonOutlineOpacity:1,polygonFillOpacity:.3,pointColor:"#3f97e0",pointOpacity:1,pointOutlineColor:"#ffffff",pointOutlineOpacity:1,pointOutlineWidth:0,pointWidth:6,lineStringColor:"#3f97e0",lineStringWidth:4,lineStringOpacity:1,zIndex:0,markerUrl:void 0,markerHeight:void 0,markerWidth:void 0});return"Feature"===t.type&&"Point"===t.geometry.type&&t.properties.mode===this.mode&&(r.zIndex=30,r.markerHeight=this.getNumericStylingValue(null==(e=this.styles)?void 0:e.markerHeight,40,t),r.markerWidth=this.getNumericStylingValue(null==(i=this.styles)?void 0:i.markerWidth,32,t),r.markerUrl=this.getUrlStylingValue(null==(n=this.styles)?void 0:n.markerUrl,p,t)),r},i.validateFeature=function(t){var e=this;return this.validateModeFeature(t,function(t){return Vt(t,e.coordinatePrecision)})},i.onLeftClick=function(t){var e,i=this.mutateFeature.createPoint({coordinates:[t.lng,t.lat],properties:(e={mode:this.mode},e[f.MARKER]=!0,e),context:{updateType:d.Finish,action:u}});i&&this.onFinish(i.id,{mode:this.mode,action:u})},i.onRightClick=function(t){if(this.editable){var e=this.pointSearch.getNearestPointFeature(t);e&&this.mutateFeature.deleteFeatureIfPresent(e.id)}},i.afterFeatureUpdated=function(t){this.editedFeatureId===t.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))},e}(x),yi=[{key:"z",heldKeys:["meta"]},{key:"z",heldKeys:["control"]}],vi=[{key:"z",heldKeys:["meta","shift"]},{key:"z",heldKeys:["control","shift"]},{key:"y",heldKeys:["control"]}],mi=function(t,e){var i=t.key.toLowerCase(),o=new Set(t.heldKeys.map(function(t){return t.toLowerCase()}).filter(function(t){return t!==i}));if(e.key.toLowerCase()!==i)return!1;var r=new Set(e.heldKeys.map(function(t){return t.toLowerCase()}));if(o.size!==r.size)return!1;for(var s,a=n(r);!(s=a()).done;)if(!o.has(s.value))return!1;return!0},Ci=/*#__PURE__*/function(){function t(t){var e,i;this.undoKeyboardShortcuts=void 0,this.redoKeyboardShortcuts=void 0,this.undoKeyboardShortcuts=null!=(e=null==t?void 0:t.undo)?e:yi,this.redoKeyboardShortcuts=null!=(i=null==t?void 0:t.redo)?i:vi}var e=t.prototype;return e.isUndoKeyboardShortcut=function(t){return this.undoKeyboardShortcuts.some(function(e){return mi(t,e)})},e.isRedoKeyboardShortcut=function(t){return this.redoKeyboardShortcuts.some(function(e){return mi(t,e)})},t}();function Pi(t){return void 0!==t&&Number.isFinite(t)?Math.max(0,Math.floor(t)):Number.POSITIVE_INFINITY}var Ii="undo",Si="redo",Fi="push",xi="mode",Mi="session",wi=/*#__PURE__*/function(){function t(t){this.getModeState=void 0,this.getModeHistorySizes=void 0,this.undoMode=void 0,this.redoMode=void 0,this.clearModeHistory=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.lastHistorySizes={undoSize:0,redoSize:0},this.maxStackSize=Pi(null==t?void 0:t.maxStackSize)}var e=t.prototype;return e.getMaxStackSize=function(){return this.maxStackSize},e.register=function(t){this.getModeState=t.getModeState,this.getModeHistorySizes=t.getModeHistorySizes,this.undoMode=t.undoMode,this.redoMode=t.redoMode,this.clearModeHistory=t.clearModeHistory,this.onHistoryChange=t.onHistoryChange},e.inDrawingState=function(){return!!this.getModeState&&"drawing"===this.getModeState()},e.canUndo=function(){return!!this.inDrawingState()&&this.getHistorySizes().undoSize>0},e.canRedo=function(){return!!this.inDrawingState()&&this.getHistorySizes().redoSize>0},e.undo=function(){return!(!this.canUndo()||!this.undoMode||(this.undoMode(),this.emitHistoryChange(Ii),0))},e.redo=function(){return!(!this.canRedo()||!this.redoMode||(this.redoMode(),this.emitHistoryChange(Si),0))},e.clearHistory=function(){this.clearModeHistory&&this.clearModeHistory(),this.lastHistorySizes={undoSize:0,redoSize:0}},e.getHistorySizes=function(){return this.getModeHistorySizes?this.getModeHistorySizes():{undoSize:0,redoSize:0}},e.undoSize=function(){return this.getHistorySizes().undoSize},e.redoSize=function(){return this.getHistorySizes().redoSize},e.emitPushIfHistoryChangedFromLastSnapshot=function(){if(this.inDrawingState()){var t=this.getHistorySizes();t.undoSize===this.lastHistorySizes.undoSize&&t.redoSize===this.lastHistorySizes.redoSize||this.emitHistoryChange(Fi)}},e.emitPushIfHistoryChanged=function(t){if(this.inDrawingState()){var e=this.getHistorySizes();e.undoSize===t.undoSize&&e.redoSize===t.redoSize||this.emitHistoryChange(Fi)}},e.emitHistoryChange=function(t){if(this.onHistoryChange){var e=this.getHistorySizes(),i=e.undoSize,n=e.redoSize;this.lastHistorySizes={undoSize:i,redoSize:n},this.onHistoryChange({cause:t,stack:xi,undoStackSize:i,redoStackSize:n})}},t}(),Oi=/*#__PURE__*/function(){function t(t){var e=this;this.draw=void 0,this.onHistoryChange=void 0,this.maxStackSize=void 0,this.historyById={},this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[],this.emitStackChange=function(t){e.onHistoryChange&&e.onHistoryChange({cause:t,stack:Mi,undoStackSize:e.undoStack.length,redoStackSize:e.redoStack.length})},this.handleChange=function(t,i,o){if(e.draw&&!e.isDrawing()&&0!==e.maxStackSize&&("delete"===i||"create"===i))if("create"!==i){for(var r,s=!1,a=[],d=n(Array.isArray(t)?t:[t]);!(r=d()).done;){var u=r.value,h=String(u);if(e.ignoreProgrammaticDelete[u])delete e.ignoreProgrammaticDelete[u];else if(e.historyById[h]){var l=e.historyById[h].length-1;if(l>=0){var c=e.historyById[h][l];if(!c)continue;a.push({id:u,toIndex:l,snapshot:c}),e.deletedFeatureIds[u]=!0,s=!0}}}if(a.length>1)e.pushUndoStackEntry({id:a[0].id,toIndex:a[0].toIndex,action:"batch-delete",metadata:{entries:a}});else if(1===a.length){var p=a[0];e.pushUndoStackEntry({id:p.id,toIndex:p.toIndex,action:"single"})}s&&(e.redoStack.length=0,e.emitStackChange(Fi))}else{if(void 0===o||!("origin"in o)||"api"!==o.origin)return;for(var g,f=!1,y=[],v=n(Array.isArray(t)?t:[t]);!(g=v()).done;){var m=g.value;if(e.ignoreProgrammaticCreate[m])delete e.ignoreProgrammaticCreate[m],delete e.deletedFeatureIds[m];else{var C=String(m),P=e.draw.getSnapshotFeature(m);P&&(e.deletedFeatureIds[m]&&(e.historyById[C]=[],delete e.deletedFeatureIds[m]),e.historyById[C]||(e.historyById[C]=[]),e.historyById[C].push(P),y.push({id:m,toIndex:e.historyById[C].length-1,snapshot:P}),f=!0)}}if(y.length>1)e.pushUndoStackEntry({id:y[0].id,toIndex:y[0].toIndex,action:"batch-create",metadata:{entries:y}});else if(1===y.length){var I=y[0];e.pushUndoStackEntry({id:I.id,toIndex:I.toIndex,action:"single"})}f&&(e.redoStack.length=0,e.emitStackChange(Fi))}},this.handleFinish=function(t){if(e.draw&&0!==e.maxStackSize)for(var i,o=!1,r=n(Array.isArray(t)?t:[t]);!(i=r()).done;){var s=i.value;if(null!=s){var a=String(s),d=e.draw.getSnapshotFeature(s);d&&(e.historyById[a]||(e.historyById[a]=[]),e.historyById[a].push(d),o||(e.redoStack.length=0,o=!0),e.pushUndoStackEntry({id:s,toIndex:e.historyById[a].length-1,action:"single"}),e.emitStackChange(Fi))}}},this.maxStackSize=Pi(null==t?void 0:t.maxStackSize)}var e=t.prototype;return e.register=function(t){this.draw!==t.draw?(this.draw&&(this.draw.off("change",this.handleChange),this.draw.off("finish",this.handleFinish)),this.draw=t.draw,this.draw.on("change",this.handleChange),this.draw.on("finish",this.handleFinish),this.onHistoryChange=t.onHistoryChange):this.onHistoryChange=t.onHistoryChange},e.pushUndoStackEntry=function(t){0!==this.maxStackSize&&(this.undoStack.push(t),this.undoStack.length>this.maxStackSize&&this.undoStack.shift())},e.pushRedoStackEntry=function(t){0!==this.maxStackSize&&(this.redoStack.push(t),this.redoStack.length>this.maxStackSize&&this.redoStack.shift())},e.isDrawing=function(){return!!this.draw&&"drawing"===this.draw.getModeState()},e.canUndo=function(){return!(!this.draw||this.isDrawing())&&this.undoStack.length>0},e.canRedo=function(){return!(!this.draw||this.isDrawing())&&this.redoStack.length>0},e.undo=function(){var t=this;if(!this.canUndo())return!1;if(!this.draw)return!1;var e=this.undoStack.pop();if(!e)return this.emitStackChange(Ii),!1;if("batch-create"===e.action){var i,n=(null==(i=e.metadata)?void 0:i.entries)||[];if(0===n.length)return this.emitStackChange(Ii),!1;var o=n.map(function(t){return t.id});return o.forEach(function(e){t.ignoreProgrammaticDelete[e]=!0,t.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(o),this.pushRedoStackEntry({id:n[0].id,toIndex:n[0].toIndex,action:"batch-create",metadata:{entries:n}}),this.emitStackChange(Ii),!0}if("batch-delete"===e.action){var r,s=(null==(r=e.metadata)?void 0:r.entries)||[];if(0===s.length)return this.emitStackChange(Ii),!1;var a=s.map(function(t){return t.snapshot}).filter(function(t){return void 0!==t});return a.length>0&&(s.forEach(function(e){t.ignoreProgrammaticCreate[e.id]=!0,delete t.deletedFeatureIds[e.id]}),this.draw.addFeatures(a)),this.pushRedoStackEntry({id:s[0].id,toIndex:s[0].toIndex,action:"batch-delete",metadata:{entries:s}}),this.emitStackChange(Ii),!0}var d=e.id,u=e.toIndex,h=String(d),l=this.historyById[h];if(!l||0===l.length)return this.emitStackChange(Ii),!1;var c=Math.min(u,l.length-1);if(!this.draw.hasFeature(d)){var p=l[c];return p?(this.ignoreProgrammaticCreate[d]=!0,delete this.deletedFeatureIds[d],this.draw.addFeatures([p]),this.pushRedoStackEntry({id:d,toIndex:c,action:"delete",snapshot:p}),this.emitStackChange(Ii),!0):(this.emitStackChange(Ii),!1)}if(c<=0)return this.pushRedoStackEntry({id:d,toIndex:0,action:"create"}),this.ignoreProgrammaticDelete[d]=!0,this.deletedFeatureIds[d]=!0,this.draw.removeFeatures([d]),this.undoStack=this.undoStack.filter(function(t){return t.id!==d}),this.emitStackChange(Ii),!0;var g=l[c],f=l[c-1];return g&&this.pushRedoStackEntry({id:d,toIndex:c,snapshot:g,action:"update"}),this.draw.updateFeatureGeometry(d,f.geometry),l.length=c,this.emitStackChange(Ii),!0},e.redo=function(){var t=this;if(!this.canRedo())return!1;if(!this.draw)return!1;var e=this.redoStack.pop(),i=e.id,n=e.toIndex,o=e.snapshot,r=e.action,s=e.metadata;if("batch-create"===r){var a=(null==s?void 0:s.entries)||[];if(0===a.length)return this.emitStackChange(Si),!1;var d=a.map(function(t){return t.snapshot}).filter(function(t){return void 0!==t});return d.length>0&&(a.forEach(function(e){t.ignoreProgrammaticCreate[e.id]=!0}),this.draw.addFeatures(d)),this.pushUndoStackEntry({id:a[0].id,toIndex:a[0].toIndex,action:"batch-create",metadata:{entries:a}}),this.emitStackChange(Si),!0}if("batch-delete"===r){var u=(null==s?void 0:s.entries)||[];if(0===u.length)return this.emitStackChange(Si),!1;var h=u.map(function(t){return t.id});return h.forEach(function(e){t.ignoreProgrammaticDelete[e]=!0,t.deletedFeatureIds[e]=!0}),this.draw.removeFeatures(h),this.pushUndoStackEntry({id:u[0].id,toIndex:u[0].toIndex,action:"batch-delete",metadata:{entries:u}}),this.emitStackChange(Si),!0}var l=String(i),c=this.historyById[l]||(this.historyById[l]=[]);if("delete"===r)return this.ignoreProgrammaticDelete[i]=!0,this.deletedFeatureIds[i]=!0,this.draw.removeFeatures([i]),this.pushUndoStackEntry({id:i,toIndex:n,action:"single"}),this.emitStackChange(Si),!0;if(n<=0){var p=c[0];return!!p&&(this.ignoreProgrammaticCreate[i]=!0,this.draw.addFeatures([p]),this.pushUndoStackEntry({id:i,toIndex:0,action:"single"}),this.emitStackChange(Si),!0)}var g=o||c[n];return!!g&&(c.length===n?c.push(g):(c[n]=g,c.length=n+1),this.draw.updateFeatureGeometry(i,g.geometry),this.pushUndoStackEntry({id:i,toIndex:n,action:"single"}),this.emitStackChange(Si),!0)},e.clearHistory=function(){var t={};if(this.draw&&!this.isDrawing())for(var e,i=n(this.draw.getSnapshot());!(e=i()).done;){var o=e.value;t[String(o.id)]=[o]}this.historyById=t,this.undoStack=[],this.ignoreProgrammaticCreate={},this.ignoreProgrammaticDelete={},this.deletedFeatureIds={},this.redoStack=[]},e.undoSize=function(){return this.undoStack.length},e.redoSize=function(){return this.redoStack.length},t}(),Ei=/*#__PURE__*/function(){function t(t){var e;this.modeLevel=void 0,this.sessionLevel=void 0,this.shouldPreferMode=void 0,this.onHistoryChange=void 0,this.shouldEmitHistoryChange=void 0,this.modeLevel=t.modeLevel,this.sessionLevel=t.sessionLevel,this.shouldPreferMode=t.shouldPreferMode,this.onHistoryChange=t.onHistoryChange,this.shouldEmitHistoryChange=null!=(e=t.shouldEmitHistoryChange)?e:function(){return!0}}var e=t.prototype;return e.emitStackHistoryChange=function(t){this.shouldEmitHistoryChange()&&this.onHistoryChange&&this.onHistoryChange({cause:t.cause,stack:t.stack,undoSize:t.undoStackSize,redoSize:t.redoStackSize})},e.hasSessionUndo=function(){return Boolean(this.sessionLevel&&this.sessionLevel.canUndo())},e.hasSessionRedo=function(){return Boolean(this.sessionLevel&&this.sessionLevel.canRedo())},e.activeStackForUndo=function(){var t,e;return this.shouldPreferMode()&&null!=(t=this.modeLevel)&&t.canUndo()?xi:this.hasSessionUndo()?Mi:null!=(e=this.modeLevel)&&e.canUndo()?xi:void 0},e.activeStackForRedo=function(){var t,e;return this.shouldPreferMode()&&null!=(t=this.modeLevel)&&t.canRedo()?xi:this.hasSessionRedo()?Mi:null!=(e=this.modeLevel)&&e.canRedo()?xi:void 0},e.canUndo=function(){return void 0!==this.activeStackForUndo()},e.canRedo=function(){return void 0!==this.activeStackForRedo()},e.undo=function(){var t=this.activeStackForUndo();return!!t&&(t===xi?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())},e.redo=function(){var t=this.activeStackForRedo();return!!t&&(t===xi?!!this.modeLevel&&this.modeLevel.redo():!(!this.sessionLevel||!this.sessionLevel.canRedo())&&this.sessionLevel.redo())},e.clearHistory=function(){this.modeLevel&&this.modeLevel.clearHistory(),this.sessionLevel&&this.sessionLevel.clearHistory()},e.emitPushAfterFinish=function(){this.sessionLevel?this.emitStackHistoryChange({cause:Fi,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:Mi}):this.modeLevel&&this.emitStackHistoryChange({cause:Fi,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:xi})},t}();exports.TerraDraw=/*#__PURE__*/function(){function t(t){var e,i,n,r,s=this;this._modes=void 0,this._mode=void 0,this._adapter=void 0,this._enabled=!1,this._store=void 0,this._eventListeners=void 0,this._instanceSelectModes=void 0,this.sessionUndoRedoEnabled=!1,this.keyboardShortcutsMatcher=void 0,this.drawingUndoRedo=void 0,this.sessionUndoRedo=void 0,this.undoRedoCoordinator=void 0,this._adapter=t.adapter,this._instanceSelectModes=[];var a=null==t||null==(e=t.undoRedo)?void 0:e.modeLevel;a&&(this.drawingUndoRedo=a);var d=null==t||null==(i=t.undoRedo)?void 0:i.keyboardShortcuts;d&&(this.keyboardShortcutsMatcher=d),this.sessionUndoRedoEnabled=Boolean(null==t||null==(n=t.undoRedo)?void 0:n.sessionLevel);var u=null==t||null==(r=t.undoRedo)?void 0:r.sessionLevel;this._mode=new Fe;var h=new Set,l=t.modes.reduce(function(t,e){if(h.has(e.mode))throw new Error("There is already a "+e.mode+" mode provided");return h.add(e.mode),t[e.mode]=e,t},{}),c=Object.keys(l);if(0===c.length)throw new Error("No modes provided");c.forEach(function(t){l[t].type===P.Select&&s._instanceSelectModes.push(t)}),this._modes=o({},l,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new He({tracked:!!t.tracked,idStrategy:t.idStrategy?t.idStrategy:void 0});var p=function(t){var e=[],i=s._store.copyAll().filter(function(i){return!t.includes(i.id)||(e.push(i),!1)});return{changed:e,unchanged:i}},g=function(t,e){s._enabled&&(s._eventListeners.finish.forEach(function(i){i(t,e)}),s.emitHistoryChangeAfterFinish())},f=function(t,e,i){if(s._enabled){s._eventListeners.change.forEach(function(n){n(t,e,i)}),s.emitDrawingPushIfHistoryChangedFromLastSnapshot();var n=p(t),o=n.changed,r=n.unchanged;"create"===e?s._adapter.render({created:o,deletedIds:[],unchanged:r,updated:[]},s.getModeStyles()):"update"===e?s._adapter.render({created:[],deletedIds:[],unchanged:r,updated:o},s.getModeStyles()):"delete"===e?s._adapter.render({created:[],deletedIds:t,unchanged:r,updated:[]},s.getModeStyles()):"styling"===e&&s._adapter.render({created:[],deletedIds:[],unchanged:r,updated:[]},s.getModeStyles())}},y=function(t){if(s._enabled){s._eventListeners.select.forEach(function(e){e(t)});var e=p([t]);s._adapter.render({created:[],deletedIds:[],unchanged:e.unchanged,updated:e.changed},s.getModeStyles())}},v=function(t){if(s._enabled){s._eventListeners.deselect.forEach(function(e){e(t)});var e=p([t]),i=e.changed;i&&s._adapter.render({created:[],deletedIds:[],unchanged:e.unchanged,updated:i},s.getModeStyles())}};Object.keys(this._modes).forEach(function(t){var e;s._modes[t].register({mode:t,store:s._store,setCursor:s._adapter.setCursor.bind(s._adapter),project:s._adapter.project.bind(s._adapter),unproject:s._adapter.unproject.bind(s._adapter),setDoubleClickToZoom:s._adapter.setDoubleClickToZoom.bind(s._adapter),onChange:f,onSelect:y,onDeselect:v,onFinish:g,coordinatePrecision:s._adapter.getCoordinatePrecision(),undoRedoMaxStackSize:null==(e=s.drawingUndoRedo)||null==e.getMaxStackSize?void 0:e.getMaxStackSize()})}),this.sessionUndoRedoEnabled&&u&&(this.sessionUndoRedo=u,u.register({draw:this,onHistoryChange:function(t){var e;null==(e=s.undoRedoCoordinator)||e.emitStackHistoryChange(t)}})),this.drawingUndoRedo&&this.drawingUndoRedo.register({getModeState:function(){return s.getModeState()},getModeHistorySizes:function(){return s.getDrawingHistorySizes()},undoMode:function(){s._mode.undo&&s._mode.undo()},redoMode:function(){s._mode.redo&&s._mode.redo()},clearModeHistory:function(){var t=s._mode;t.clearHistory&&t.clearHistory()},onHistoryChange:function(t){var e;null==(e=s.undoRedoCoordinator)||e.emitStackHistoryChange(t)}}),this.undoRedoCoordinator=new Ei({modeLevel:this.drawingUndoRedo,sessionLevel:this.sessionUndoRedo,shouldPreferMode:function(){return"drawing"===s.getModeState()},onHistoryChange:function(t){s._eventListeners.history.forEach(function(e){e(t)})},shouldEmitHistoryChange:function(){return s._enabled}})}var e=t.prototype;return e.checkEnabled=function(){if(!this._enabled)throw new Error("Terra Draw is not enabled")},e.handleUndoRedoKeyboardShortcut=function(t){if(!this.drawingUndoRedo&&!this.sessionUndoRedoEnabled)return!1;if(!this.keyboardShortcutsMatcher)return!1;var e=this.keyboardShortcutsMatcher.isUndoKeyboardShortcut(t),i=this.keyboardShortcutsMatcher.isRedoKeyboardShortcut(t);if(e){if(!this.canUndo())return!1;var n=this.undo();return n&&t.preventDefault(),n}if(i){if(!this.canRedo())return!1;var o=this.redo();return o&&t.preventDefault(),o}return!1},e.getDrawingHistorySizes=function(){return{undoSize:this._mode.undoSize&&"function"==typeof this._mode.undoSize?this._mode.undoSize():0,redoSize:this._mode.redoSize&&"function"==typeof this._mode.redoSize?this._mode.redoSize():0}},e.emitDrawingPushIfHistoryChangedFromLastSnapshot=function(){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChangedFromLastSnapshot()},e.emitDrawingPushIfHistoryChanged=function(t){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChanged(t)},e.emitHistoryChangeAfterFinish=function(){var t;null==(t=this.undoRedoCoordinator)||t.emitPushAfterFinish()},e.getModeStyles=function(){var t=this,e={},i=this._instanceSelectModes.includes(this._mode.mode)?this._mode.mode:void 0;return Object.keys(this._modes).forEach(function(n){e[n]=function(e){return i&&e.properties[g.SELECTED]?t._modes[i].styleFeature.bind(t._modes[i])(e):t._modes[n].styleFeature.bind(t._modes[n])(e)}}),e},e.featuresAtLocation=function(t,e){var i=t.lng,o=t.lat,r=e&&void 0!==e.pointerDistance?e.pointerDistance:30,s=!e||void 0===e.ignoreSelectFeatures||e.ignoreSelectFeatures,a=!(!e||void 0===e.ignoreCoordinatePoints)&&e.ignoreCoordinatePoints,d=!(!e||void 0===e.ignoreCurrentlyDrawing)&&e.ignoreCurrentlyDrawing,u=!(!e||void 0===e.ignoreClosingPoints)&&e.ignoreClosingPoints,h=!(!e||void 0===e.ignoreSnappingPoints)&&e.ignoreSnappingPoints,l=this._adapter.unproject.bind(this._adapter),c=this._adapter.project.bind(this._adapter),p=c(i,o),y=pt({unproject:l,point:p,pointerDistance:r});return this._store.search(y).filter(function(t){if(s&&(t.properties[g.MID_POINT]||t.properties[g.SELECTION_POINT]))return!1;if(a&&t.properties[f.COORDINATE_POINT])return!1;if(u&&t.properties[f.CLOSING_POINT])return!1;if(d&&t.properties[f.CURRENTLY_DRAWING])return!1;if(h&&t.properties[f.SNAPPING_POINT])return!1;if("Point"===t.geometry.type){var l=t.geometry.coordinates,y=c(l[0],l[1]);return at(p,y)<r}if("LineString"===t.geometry.type){for(var v=t.geometry.coordinates,m=0;m<v.length-1;m++){var C=v[m],P=v[m+1];if(ue(p,c(C[0],C[1]),c(P[0],P[1]))<r)return!0}return!1}if(de([i,o],t.geometry.coordinates))return!0;if(null!=e&&e.includePolygonsWithinPointerDistance)for(var I,S=n(t.geometry.coordinates);!(I=S()).done;)for(var F=I.value,x=0;x<F.length-1;x++){var M=F[x],w=F[x+1],O=c(M[0],M[1]),E=c(w[0],w[1]);if(ue(p,O,E)<r)return!0}return!1}).map(function(t){if(null==e||!e.addClosestCoordinateInfoToProperties)return t;var n;if("Polygon"===t.geometry.type)n=t.geometry.coordinates[0].slice(0,-1);else{if("LineString"!==t.geometry.type)return t;n=t.geometry.coordinates}for(var r,s=-1,a=Infinity,d=0;d<n.length;d++){var u=n[d],h=at(c(u[0],u[1]),p);h<a&&(s=d,a=h,r=u)}return t.properties.closestCoordinateIndexToEvent=s,t.properties.closestCoordinatePixelDistanceToEvent=a,t.properties.closestCoordinateDistanceKmToEvent=w(r,[i,o]),t})},e.getSelectModeOrThrow=function(t){void 0===t&&(t=void 0);var e=this.getSelectMode({switchToSelectMode:!0,selectMode:t});if(!e)throw new Error("No select mode defined in instance");return e},e.getSelectMode=function(t){var e=t.switchToSelectMode,i=t.selectMode;this.checkEnabled();var n,o=this.getMode();if(0===this._instanceSelectModes.length)return null;if(void 0!==i&&!this._instanceSelectModes.includes(i))throw new Error("No select mode with this name present: "+i);return n=void 0!==i?i:this._instanceSelectModes.includes(o)?o:this._instanceSelectModes[0],e&&o!==n&&this.setMode(n),this._modes[n]},e.isGuidanceFeature=function(t){return Boolean(t.properties[g.MID_POINT]||t.properties[g.SELECTION_POINT]||t.properties[f.COORDINATE_POINT]||t.properties[f.SNAPPING_POINT])},e.setModeStyles=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].styles=e},e.updateModeOptions=function(t,e){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._modes[t].updateOptions(e)},e.getSnapshot=function(){return this._store.copyAll()},e.getSnapshotFeature=function(t){if(this._store.has(t))return this._store.copy(t)},e.clear=function(){this.checkEnabled(),this._adapter.clear()},e.getMode=function(){return this._mode.mode},e.getModeState=function(){return this._mode.state},e.setMode=function(t){if(this.checkEnabled(),!this._modes[t])throw new Error("No mode with this name present");this._mode.stop(),this._mode=this._modes[t],this._mode.start()},e.removeFeatures=function(t){var e=this;this.checkEnabled();var i=[],n=[],o=void 0;t.forEach(function(t){if(!e._store.has(t))throw new Error("No feature with id "+t+", can not delete");var r=e._store.getPropertiesCopy(t);r[g.SELECTED]&&e.deselectFeature(t),r[f.CURRENTLY_DRAWING]&&e._modes[r.mode]?o=r.mode:(r[f.COORDINATE_POINT_IDS]&&i.push.apply(i,r[f.COORDINATE_POINT_IDS]),n.push(t))}),this._store.delete([].concat(n,i),{origin:"api"}),o&&this._modes[o]&&this._modes[o].cleanUp()&&this._modes[o].cleanUp()},e.selectFeature=function(t,e){this.getSelectModeOrThrow(e).selectFeature(t)},e.deselectFeature=function(t){this.getSelectModeOrThrow().deselectFeature(t)},e.getFeatureId=function(){return this._store.getId()},e.hasFeature=function(t){return this._store.has(t)},e.checkIsReservedProperty=function(t){return![].concat(Object.values(g),Object.values(f)).includes(t)},e.updateFeatureProperties=function(t,e){var i=this;if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var n=this._store.copy(t);if(this.isGuidanceFeature(n))throw new Error("Guidance features are not allowed to be updated directly.");var o=n.properties.mode;if(!this._modes[o])throw new Error("No mode with name "+o+" present in instance");var r=Object.entries(e);r.forEach(function(t){var e=t[0],n=t[1];if(!i.checkIsReservedProperty(e))throw new Error("You are trying to update a reserved property name: "+e+". Please choose another name.");if(void 0!==n&&!pi(n))throw new Error("Invalid JSON value provided for property "+e)}),this._store.updateProperty(r.map(function(t){return{id:n.id,property:t[0],value:t[1]}}),{origin:"api"})},e.updateFeatureGeometry=function(t,e){if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var i=this._store.copy(t);if(this.isGuidanceFeature(i))throw new Error("Guidance features are not allowed to be updated directly.");if(!(i&&e&&e.type&&e.coordinates))throw new Error("Invalid geometry provided");if(e.type!==i.geometry.type)throw new Error("Geometry type mismatch: expected "+i.geometry.type+", got "+e.type);var n=i.properties.mode,r=this._modes[n];if(!r)throw new Error("No mode with name "+n+" present in instance");var s=o({},i,{geometry:e}),a=r.validateFeature(s);if(!a.valid)throw new Error("Feature validation failed: "+(a.reason||"Unknown reason"));if(this._store.updateGeometry([{id:i.id,geometry:e}],{origin:"api"}),r.afterFeatureUpdated){r.afterFeatureUpdated(s);var d=s.properties[g.SELECTED],u=this.getSelectMode({switchToSelectMode:!1});u&&d&&u.afterFeatureUpdated(s)}},e.transformFeatureGeometry=function(t,e){var i=this;if(!this._store.has(t))throw new Error("No feature with id "+t+" present in store");var n=this._store.copy(t);if(this.isGuidanceFeature(n))throw new Error("Guidance features are not allowed to be updated directly.");var o,r=n.properties.mode,s=this._modes[r];if(!s)throw new Error("No mode with name "+r+" present in instance");if("Polygon"===n.geometry.type)o=n.geometry.coordinates[0];else{if("LineString"!==n.geometry.type)throw new Error("Feature geometry type "+n.geometry.type+" is not supported for transformation");o=n.geometry.coordinates}if("web-mercator"!=e.projection)throw new Error("Projection "+e.projection+" is not currently supported for transformation");if("scale"===e.type){var a=R(e.origin[0],e.origin[1]);me({coordinates:o,originX:a.x,originY:a.y,xScale:e.options.xScale||1,yScale:e.options.yScale||1})}else"rotate"===e.type&&(o="Polygon"===(n=ge(n,e.options.angle||0)).geometry.type?n.geometry.coordinates[0]:n.geometry.coordinates);if(o=o.map(function(t){return[b(t[0],i._adapter.getCoordinatePrecision()),b(t[1],i._adapter.getCoordinatePrecision())]}),n.geometry.coordinates="Polygon"===n.geometry.type?[o]:o,this._store.updateGeometry([{id:n.id,geometry:n.geometry}],{origin:"api"}),s.afterFeatureUpdated){s.afterFeatureUpdated(n);var d=n.properties[g.SELECTED],u=this.getSelectMode({switchToSelectMode:!1});u&&d&&u.afterFeatureUpdated(n)}},e.undo=function(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.undo()},e.canUndo=function(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canUndo()},e.canRedo=function(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canRedo()},e.redo=function(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.redo()},e.clearUndoRedoHistory=function(){this.checkEnabled(),this.undoRedoCoordinator&&this.undoRedoCoordinator.clearHistory()},e.addFeatures=function(t){var e=this;return this.checkEnabled(),0===t.length?[]:this._store.load(t,function(t){if(m(t)){var i=t.properties.mode,n=e._modes[i];if(!n)return{id:t.id,valid:!1,reason:i+" mode is not in the list of instantiated modes"};var o=n.validateFeature.bind(n)(t);return{id:t.id,valid:o.valid,reason:o.reason?o.reason:o.valid?void 0:"Feature is invalid"}}return{id:t.id,valid:!1,reason:"Mode property does not exist"}},function(t){if(m(t)){var i=e._modes[t.properties.mode];i&&i.afterFeatureAdded&&i.afterFeatureAdded(t)}},{origin:"api"})},e.start=function(){var t=this;this._enabled||(this._enabled=!0,this._adapter.register({onReady:function(){t._eventListeners.ready.forEach(function(t){t()})},getState:function(){return t._mode.state},onClick:function(e){var i=t.drawingUndoRedo?t.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};t._mode.onClick(e),t.emitDrawingPushIfHistoryChanged(i)},onMouseMove:function(e){t._mode.onMouseMove(e)},onKeyDown:function(e){t.handleUndoRedoKeyboardShortcut(e)||t._mode.onKeyDown(e)},onKeyUp:function(e){var i=t.drawingUndoRedo?t.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};t._mode.onKeyUp(e),t.emitDrawingPushIfHistoryChanged(i)},onDragStart:function(e,i){t._mode.onDragStart(e,i)},onDrag:function(e,i){t._mode.onDrag(e,i)},onDragEnd:function(e,i){t._mode.onDragEnd(e,i)},onClear:function(){t._mode.cleanUp(),t._store.clear({origin:"api"})}}))},e.getFeaturesAtLngLat=function(t,e){return this.featuresAtLocation({lng:t.lng,lat:t.lat},e)},e.getFeaturesAtPointerEvent=function(t,e){var i=this._adapter.getLngLatFromEvent.bind(this._adapter)(t);return null===i?[]:this.featuresAtLocation(i,e)},e.stop=function(){this._enabled&&(this._enabled=!1,this._adapter.unregister())},e.on=function(t,e){var i=this._eventListeners[t];i.includes(e)||i.push(e)},e.off=function(t,e){var i=this._eventListeners[t];i.includes(e)&&i.splice(i.indexOf(e),1)},i(t,[{key:"enabled",get:function(){return this._enabled},set:function(t){throw new Error("Enabled is read only")}}])}(),exports.TerraDrawAngledRectangleMode=Qe,exports.TerraDrawCircleMode=st,exports.TerraDrawExtend=di,exports.TerraDrawFreehandLineStringMode=ci,exports.TerraDrawFreehandMode=ct,exports.TerraDrawLineStringMode=Bt,exports.TerraDrawMarkerMode=fi,exports.TerraDrawModeUndoRedo=wi,exports.TerraDrawPointMode=Yt,exports.TerraDrawPolygonMode=Zt,exports.TerraDrawRectangleMode=Qt,exports.TerraDrawRenderMode=te,exports.TerraDrawSectorMode=ni,exports.TerraDrawSelectMode=Se,exports.TerraDrawSensorMode=si,exports.TerraDrawSessionUndoRedo=Oi,exports.TerraDrawUndoRedoKeyboardShortcuts=Ci,exports.ValidateMaxAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:I}:Ge(t.geometry)>e?{valid:!1,reason:"Feature is larger than the maximum area"}:{valid:!0}},exports.ValidateMinAreaSquareMeters=function(t,e){return"Polygon"!==t.geometry.type?{valid:!1,reason:I}:Ge(t.geometry)<e?{valid:!1,reason:Ye}:{valid:!0}},exports.ValidateNotSelfIntersecting=function(t){return"Polygon"!==t.geometry.type&&"LineString"!==t.geometry.type?{valid:!1,reason:Xe}:A(t)?{valid:!1,reason:qe}:{valid:!0}},exports.ValidationReasons=ui;
2
2
  //# sourceMappingURL=terra-draw.cjs.map