signalk-binnacle 0.6.2 → 0.7.0

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.
@@ -0,0 +1 @@
1
+ import{d as e,f as t,l as n,n as r,u as i}from"./index-BOkTPq1w.js";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a.apply(null,arguments)}var o=`draw`,s=`edit`,c=`deleteCoordinate`,l=`insertMidpoint`,u;(function(e){e.Commit=`commit`,e.Provisional=`provisional`,e.Finish=`finish`})(u||={});var d=`https://raw.githubusercontent.com/JamesLMilner/terra-draw/refs/heads/main/assets/markers/marker-blue.png`,f={SELECTED:`selected`,MID_POINT:`midPoint`,SELECTION_POINT_FEATURE_ID:`selectionPointFeatureId`,SELECTION_POINT:`selectionPoint`},p={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`},m=10;function h(e){return!!(e&&typeof e==`object`&&e&&!Array.isArray(e))}function g(e){return!!(e&&typeof e==`object`&&`properties`in e&&typeof e.properties==`object`&&e.properties!==null&&`mode`in e.properties)}function _(e){return!!function(e){return typeof e==`number`&&!isNaN(new Date(e).valueOf())}(e)}var v=`Feature mode property does not match the mode being added to`,y;(function(e){e.Drawing=`drawing`,e.Select=`select`,e.Static=`static`,e.Render=`render`})(y||={});var ee={rightClick:!0,contextMenu:!1,leftClick:!0,onDragStart:!0,onDrag:!0,onDragEnd:!0},b=class{get state(){return this._state}set state(e){throw Error(`Please use the modes lifecycle methods`)}get styles(){return this._styles}set styles(e){if(typeof e!=`object`)throw Error(`Styling must be an object`);this.onStyleChange&&this.onStyleChange([],`styling`),this._styles=e}registerBehaviors(e){}constructor(e,t=!1){this._state=`unregistered`,this._styles={},this.pointerEvents=ee,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=y.Drawing,this.mode=`base`,t?this.isInitialUpdate=!0:this.updateOptions(a({},e))}updateOptions(e){e!=null&&e.styles&&(this.styles=a({},this._styles,e.styles)),e?.pointerDistance!==void 0&&(this.pointerDistance=e.pointerDistance),e!=null&&e.validation&&(this.validate=e&&e.validation),e!=null&&e.projection&&(this.projection=e.projection),e?.pointerEvents!==void 0&&(this.pointerEvents=e.pointerEvents),e!=null&&e.modeName&&!0===this.isInitialUpdate&&(this.mode=e.modeName),this.isInitialUpdate=!1}allowPointerEvent(e,t){return typeof e==`boolean`?e:typeof e!=`function`||e(t)}setDrawing(){if(this._state!==`started`)throw Error(`Mode must be unregistered or stopped to start`);this._state=`drawing`}setStarted(){if(this._state!==`stopped`&&this._state!==`registered`&&this._state!==`drawing`&&this._state!==`selecting`)throw Error(`Mode must be unregistered or stopped to start`);this._state=`started`,this.setDoubleClickToZoom(!1)}setStopped(){if(this._state!==`started`)throw Error(`Mode must be started to be stopped`);this._state=`stopped`,this.setDoubleClickToZoom(!0)}register(e){if(this._state!==`unregistered`)throw Error(`Can not register unless mode is unregistered`);this._state=`registered`,this.store=e.store,this.store.registerOnChange(e.onChange),this.setDoubleClickToZoom=e.setDoubleClickToZoom,this.project=e.project,this.unproject=e.unproject,this.onSelect=e.onSelect,this.onDeselect=e.onDeselect,this.setCursor=e.setCursor,this.onStyleChange=e.onChange,this.onFinish=e.onFinish,this.coordinatePrecision=e.coordinatePrecision,this.undoRedoMaxStackSize=e.undoRedoMaxStackSize,this.registerBehaviors({mode:e.mode,store:this.store,project:this.project,unproject:this.unproject,pointerDistance:this.pointerDistance,coordinatePrecision:e.coordinatePrecision,projection:this.projection,undoRedoMaxStackSize:e.undoRedoMaxStackSize})}validateFeature(e){return this.performFeatureValidation(e)}afterFeatureAdded(e){}afterFeatureUpdated(e){}performFeatureValidation(e){if(this._state===`unregistered`)throw Error(`Mode must be registered`);let t=function(e,t){let n;if(h(e))if(e.id==null)n=`Feature has no id`;else if(typeof e.id!=`string`&&typeof e.id!=`number`)n=`Feature must be string or number as per GeoJSON spec`;else if(t(e.id))if(h(e.geometry))if(h(e.properties))if(typeof e.geometry.type==`string`&&[`Polygon`,`LineString`,`Point`].includes(e.geometry.type))if(Array.isArray(e.geometry.coordinates)){if(!e.properties.mode||typeof e.properties.mode!=`string`)return{valid:!1,reason:`Feature does not have a valid mode property`}}else n=`Feature coordinates is not an array`;else n=`Feature is not Point, LineString or Polygon`;else n=`Feature has no properties`;else n=`Feature has no geometry`;else n=`Feature must match the id strategy (default is UUID4)`;else n=`Feature is not object`;return n?{valid:!1,reason:n}:{valid:!0}}(e,this.store.idStrategy.isValidId);if(!t.valid)return t;if(this.validate){let n=this.validate(e,{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:u.Provisional});return{valid:t.valid&&n.valid,reason:n.reason}}return{valid:t.valid,reason:t.reason}}validateModeFeature(e,t){let n=this.performFeatureValidation(e);return n.valid?e.properties.mode===this.mode?t(e):{valid:!1,reason:v}:{valid:!1,reason:n.reason}}onFinish(e,t){}onDeselect(e){}onSelect(e){}onKeyDown(e){}onKeyUp(e){}undo(){}clearHistory(){}undoSize(){return 0}redoSize(){return 0}redo(){}onMouseMove(e){}onClick(e){}onDragStart(e,t){}onDrag(e,t){}onDragEnd(e,t){}getHexColorStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getNumericStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getUrlStylingValue(e,t,n){return this.getStylingValue(e,t,n)}getStylingValue(e,t,n){return e===void 0?t:typeof e==`function`?(r=e(n))??t:e;var r}},x=class extends b{constructor(...e){super(...e),this.type=y.Select}};function S(e,t){let n=e=>e*Math.PI/180,r=n(e[1]),i=n(e[0]),a=n(t[1]),o=a-r,s=n(t[0])-i,c=Math.sin(o/2)*Math.sin(o/2)+Math.cos(r)*Math.cos(a)*Math.sin(s/2)*Math.sin(s/2);return 2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c))*6371e3/1e3}var C=6371008.8;function w(e){return e%360*Math.PI/180}function T(e){return e/6371.0088}function E(e){return e%(2*Math.PI)*180/Math.PI}function D(e,t=9){let n=10**t;return Math.round(e*n)/n}var te=57.29577951308232,ne=.017453292519943295,O=6378137,k=(e,t)=>({x:e===0?0:e*ne*O,y:t===0?0:Math.log(Math.tan(Math.PI/4+t*ne/2))*O}),A=(e,t)=>({lng:e===0?0:e/O*te,lat:t===0?0:(2*Math.atan(Math.exp(t/O))-Math.PI/2)*te});function re(e){let t;if(e.geometry.type===`Polygon`)t=e.geometry.coordinates;else{if(e.geometry.type!==`LineString`)throw Error(`Self intersects only accepts Polygons and LineStrings`);t=[e.geometry.coordinates]}let n=[];for(let e=0;e<t.length;e++)for(let n=0;n<t[e].length-1;n++)for(let r=0;r<t.length;r++)for(let a=0;a<t[r].length-1;a++)i(e,n,r,a);return n.length>0;function r(e){return e<0||e>1}function i(e,i,a,o){let s=t[e][i],c=t[e][i+1],l=t[a][o],u=t[a][o+1],d=function(e,t,n,r){if(j(e,n)||j(e,r)||j(t,n)||j(r,n))return null;let i=e[0],a=e[1],o=t[0],s=t[1],c=n[0],l=n[1],u=r[0],d=r[1],f=(i-o)*(l-d)-(a-s)*(c-u);return f===0?null:[((i*s-a*o)*(c-u)-(i-o)*(c*d-l*u))/f,((i*s-a*o)*(l-d)-(a-s)*(c*d-l*u))/f]}(s,c,l,u);if(d===null)return;let f,p;f=c[0]===s[0]?(d[1]-s[1])/(c[1]-s[1]):(d[0]-s[0])/(c[0]-s[0]),p=u[0]===l[0]?(d[1]-l[1])/(u[1]-l[1]):(d[0]-l[0])/(u[0]-l[0]),r(f)||r(p)||(d.toString(),n.push(d))}}function j(e,t){return e[0]===t[0]&&e[1]===t[1]}function ie(e,t){return oe(e[0])<=t&&oe(e[1])<=t}function ae(e){return e.length===2&&typeof e[0]==`number`&&typeof e[1]==`number`&&e[0]!==1/0&&e[1]!==1/0&&(n=e[0])>=-180&&n<=180&&(t=e[1])>=-90&&t<=90;var t,n}function oe(e){let t=1,n=0;for(;Math.round(e*t)/t!==e;)t*=10,n++;return n}var M=class{constructor({store:e,mode:t,project:n,unproject:r,pointerDistance:i,coordinatePrecision:a,projection:o,undoRedoMaxStackSize:s}){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=t,this.project=n,this.unproject=r,this.pointerDistance=i,this.coordinatePrecision=a,this.projection=o,this.undoRedoMaxStackSize=s}};function se(e){if(!function(e){let t=e.coordinates[0],n=0;for(let e=0;e<t.length-1;e++){let[r,i]=t[e],[a,o]=t[e+1];n+=(a-r)*(o+i)}return n<0}(e))return{type:`Polygon`,coordinates:[e.coordinates[0].reverse()]}}var ce=`insert-before`,N=`insert-after`,le=`update`,ue=`delete`,P=`replace`,de=class extends M{constructor(e,t){super(e),this.options=void 0,this.options=t}createPoint({coordinates:e,properties:t,context:n}){if(n?.updateType!==u.Finish||this.validateGeometryWithUpdateType({geometry:{type:`Point`,coordinates:e},properties:t,updateType:u.Finish}))return this.handleCreateFeature({geometry:{type:`Point`,coordinates:e},properties:t})}createLineString({coordinates:e,properties:t}){return this.handleCreateFeature({geometry:{type:`LineString`,coordinates:e},properties:t})}createPolygon({coordinates:e,properties:t,context:n}){let r=se({type:`Polygon`,coordinates:[e]}),i={type:`Polygon`,coordinates:r?r.coordinates:[e]};if(n?.updateType!==u.Finish||this.validateGeometryWithUpdateType({geometry:i,properties:t,updateType:u.Finish}))return this.handleCreateFeature({geometry:i,properties:t})}createGuidancePoint({coordinate:e,type:t}){return this.createGuidancePoints({coordinates:[e],type:t})[0]}createGuidancePoints({coordinates:e,type:t,additionalProperties:n}){let r=e.map((e,r)=>({type:`Feature`,geometry:{type:`Point`,coordinates:e},properties:a({mode:this.mode,[t]:!0},n?n(r):{})}));return this.createFeatures(r)}updatePoint({featureId:e,coordinateMutations:t,propertyMutations:n,context:r}){return this.handleMutateFeature({type:`Point`,featureId:e,coordinateMutations:t,propertyMutations:n,context:r})}updatePolygon({featureId:e,coordinateMutations:t,context:n,propertyMutations:r}){return this.handleMutateFeature({type:`Polygon`,featureId:e,coordinateMutations:t,propertyMutations:r,context:n})}updateLineString({featureId:e,coordinateMutations:t,context:n,propertyMutations:r}){return this.handleMutateFeature({type:`LineString`,featureId:e,coordinateMutations:t,propertyMutations:r,context:n})}deleteFeatureIfPresent(e){e&&this.store.has(e)&&this.store.delete([e])}deleteFeaturesIfPresent(e){if(e.length===0)return;let t=e.filter(e=>this.store.has(e));t.length&&this.store.delete(t)}setDeselected(e){let t=e.filter(e=>this.store.has(e)).map(e=>({featureId:e,properties:{[f.SELECTED]:!1}}));this.updateFeatureProperties(t)}setSelected(e){let{type:t}=this.store.getGeometryCopy(e),n={featureId:e,propertyMutations:{[f.SELECTED]:!0},context:{updateType:u.Commit}};t===`Polygon`?this.updatePolygon(n):t===`LineString`?this.updateLineString(n):t===`Point`&&this.updatePoint(n)}updateGuidancePoints(e){this.updateFeatureGeometries(e.map(({featureId:e,coordinate:t})=>({id:e,geometry:{type:`Point`,coordinates:t}})))}handleCreateFeature({geometry:e,properties:t}){return this.createFeatureWithGeometry({geometry:e,properties:t})}handleMutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i}){if(!this.mutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i.updateType===u.Finish?a({},i,{correctRightHandRule:!0}):a({},i)}))return null;let o=this.buildFeatureWithGeometry(t);return i.updateType!==u.Finish||n||this.validateGeometryWithUpdateType({geometry:o.geometry,properties:o.properties,updateType:i.updateType})?o:null}mutateFeature({type:e,featureId:t,coordinateMutations:n,propertyMutations:r,context:i}){if(!t)return!1;let a=this.store.getGeometryCopy(t),o=this.store.getPropertiesCopy(t);if(a.type!==e)throw Error(`${e} geometries cannot be updated on features with ${a.type} geometries`);if(n){let e=this.applyCoordinateMutations(a,n);if(i.correctRightHandRule&&e.type===`Polygon`){let t=se(e);t&&(e=t)}if(!this.validateGeometryWithUpdateType({geometry:e,properties:o,updateType:i.updateType}))return!1;this.updateFeatureGeometries([{id:t,geometry:e}])}return r&&this.updateFeatureProperties([{featureId:t,properties:r}]),!0}applyCoordinateMutations(e,t){if(this.isReplaceMutation(t))return a({},e,{coordinates:t.coordinates});if(e.type===`Point`)throw Error(`Coordinate mutations are not supported for Point geometries`);let n=e.type===`Polygon`,r=n?e.coordinates[0].slice():e.coordinates.slice(),i=r.length,o=e=>{let t=e<0?i+e:e;if(t<0||t>=i)throw RangeError(`Index ${e} (normalized to ${t}) is out of bounds`);return t},s=Array(i).fill(void 0),c=Array.from({length:i},()=>[]),l=Array.from({length:i},()=>[]),u=[];for(let e of t){if(e.type===ce||e.type===N){let t=e.index,n=t<0?i+t:t;if(n<0||n>i)throw RangeError(`Index ${e.index} (normalized to ${n}) is out of bounds`);if(e.type===ce){if(n>=i)throw RangeError(`INSERT_BEFORE index ${e.index} (normalized to ${n}) is out of bounds for length ${i}`);c[n].push(e)}else n===i?u.push(e):l[n].push(e);continue}let t=o(e.index);s[t]=a({},e,{index:t})}let d=[];for(let e=0;e<i;e++){let t=c[e];for(let e of t)d.push(e.coordinate);let n=s[e];n?n.type===ue||d.push(n.coordinate):d.push(r[e]);let i=l[e];for(let e of i)d.push(e.coordinate)}for(let e of u)d.push(e.coordinate);return a({},e,n?{coordinates:[d,...e.coordinates.slice(1)]}:{coordinates:d})}isReplaceMutation(e){return e.type===P}createFeatureWithGeometry({geometry:e,properties:t}){let[n]=this.createFeatures([{type:`Feature`,geometry:e,properties:t}]);return{id:n,type:`Feature`,properties:this.store.getPropertiesCopy(n),geometry:this.store.getGeometryCopy(n)}}validateGeometryWithUpdateType({geometry:e,properties:t,updateType:n}){return!this.options.validate||this.options.validate({type:`Feature`,geometry:e,properties:t||{}},{project:this.project,unproject:this.unproject,coordinatePrecision:this.coordinatePrecision,updateType:n}).valid}buildFeatureWithGeometry(e){return{id:e,type:`Feature`,properties:this.store.getPropertiesCopy(e),geometry:this.store.getGeometryCopy(e)}}createFeatures(e){return this.store.create(e)}updateFeatureGeometries(e){this.store.updateGeometry(e)}updateFeatureProperties(e){let t=e.map(({featureId:e,properties:t})=>Object.entries(t).map(([t,n])=>({id:e,property:t,value:n}))).flat();this.store.updateProperty(t)}},F=(e,t)=>{let{x:n,y:r}=e,{x:i,y:a}=t,o=i-n,s=a-r;return Math.sqrt(s*s+o*o)};function fe(e,t){return e[0]===t[0]&&e[1]===t[1]}var pe=class extends M{constructor(e){super(e)}getGeometryType(e){return this.store.getGeometryCopy(e).type}coordinateAtIndexIsIdentical({featureId:e,newCoordinate:t,index:n}){let r=this.store.getGeometryCopy(e),i;if(r.type===`Polygon`)i=r.coordinates[0][n];else if(r.type===`LineString`)i=r.coordinates[n];else{if(n!==0)throw Error(`Point geometries only have one coordinate at index 0`);i=r.coordinates}return fe(t,i)}getGeometry(e){return this.store.getGeometryCopy(e)}getCoordinates(e){let{type:t,coordinates:n}=this.store.getGeometryCopy(e);return t===`Polygon`?n[0]:n}getCoordinate(e,t){let n=this.getCoordinates(e),r=t<0?n.length+t:t;if(r<0||r>=n.length)throw RangeError(`Index ${t} (normalized to ${r}) is out of bounds`);return n[r]}getProperties(e){return this.store.getPropertiesCopy(e)}hasFeature(e){return this.store.has(e)}getAllFeatureIdsWhere(e){return this.store.copyAllWhere(e).map(({id:e})=>e)}};function me({unproject:e,point:t,pointerDistance:n}){let r=n/2,{x:i,y:a}=t;return{type:`Feature`,properties:{},geometry:{type:`Polygon`,coordinates:[[e(i-r,a-r),e(i+r,a-r),e(i+r,a+r),e(i-r,a+r),e(i-r,a-r)].map(e=>[e.lng,e.lat])]}}}var he=class extends M{constructor(e){super(e)}create(e){let{containerX:t,containerY:n}=e;return me({unproject:this.unproject,point:{x:t,y:n},pointerDistance:this.pointerDistance})}},ge=class extends M{constructor(e){super(e)}measure(e,t){let{x:n,y:r}=this.project(t[0],t[1]);return F({x:n,y:r},{x:e.containerX,y:e.containerY})}},_e=class extends M{constructor(e,t,n){super(e),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=e=>this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode)).coordinate,this.getSnappableCoordinate=(e,t)=>this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode&&e.id!==t)).coordinate,this.config=e,this.pixelDistance=t,this.clickBoundingBox=n}getSnappable(e,t){let n=this.clickBoundingBox.create(e),r=this.store.search(n,t),i={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDist:1/0};return r.forEach(t=>{let n;if(t.geometry.type===`Polygon`)n=t.geometry.coordinates[0];else{if(t.geometry.type!==`LineString`)return;n=t.geometry.coordinates}n.forEach((n,r)=>{let a=this.pixelDistance.measure(e,n);a<i.minDist&&a<this.pointerDistance&&(i.coordinate=n,i.minDist=a,i.featureId=t.id,i.featureCoordinateIndex=r)})}),i}};function ve(e,t,n){let r=w(e[0]),i=w(e[1]),a=w(n),o=T(t),s=Math.asin(Math.sin(i)*Math.cos(o)+Math.cos(i)*Math.sin(o)*Math.cos(a));return[E(r+Math.atan2(Math.sin(a)*Math.sin(o)*Math.cos(i),Math.cos(o)-Math.sin(i)*Math.sin(s))),E(s)]}function ye(e,t){let n=w(e[0]),r=w(t[0]),i=w(e[1]),a=w(t[1]),o=Math.sin(r-n)*Math.cos(a),s=Math.cos(i)*Math.sin(a)-Math.sin(i)*Math.cos(a)*Math.cos(r-n);return E(Math.atan2(o,s))}function be({x:e,y:t},{x:n,y:r}){let i=n-e,a=r-t;if(i===0&&a===0)return 0;let o=Math.atan2(a,i);return o*=180/Math.PI,o>180?o-=360:o<-180&&(o+=360),o}function xe(e,t,n){let r=[],i=e.length,a,o,s,c=0;for(let i=0;i<e.length&&!(t>=c&&i===e.length-1);i++){if(c>t&&r.length===0){if(a=t-c,!a)return r.push(e[i]),r;o=ye(e[i],e[i-1])-180,s=ve(e[i],a,o),r.push(s)}if(c>=n)return a=n-c,a?(o=ye(e[i],e[i-1])-180,s=ve(e[i],a,o),r.push(s),r):(r.push(e[i]),r);if(c>=t&&r.push(e[i]),i===e.length-1)return r;c+=S(e[i],e[i+1])}if(c<t&&e.length===i)throw Error(`Start position is beyond line`);let l=e[e.length-1];return[l,l]}function I(e){return Math.PI/180*e}function Se(e){return 180/Math.PI*e}var Ce=class extends M{constructor(e){super(e),this.config=void 0,this.config=e}generateInsertionCoordinates(e,t,n){let r=[e,t],i=0;for(let e=0;e<r.length-1;e++)i+=S(r[0],r[1]);if(i<=n)return r;let a=i/n-1;Number.isInteger(a)||(a=Math.floor(a)+1);let o=[];for(let e=0;e<a;e++){let t=xe(r,n*e,n*(e+1));o.push(t)}let s=[];for(let e=0;e<o.length;e++)s.push(o[e][1]);return this.limitCoordinates(s)}generateInsertionGeodesicCoordinates(e,t,n){let r=S(e,t),i=function(e,t,n){let r=[],i=I(e[1]),a=I(e[0]),o=I(t[1]),s=I(t[0]);n+=1;let c=2*Math.asin(Math.sqrt(Math.sin((o-i)/2)**2+Math.cos(i)*Math.cos(o)*Math.sin((s-a)/2)**2));if(c===0||isNaN(c))return r;for(let e=0;e<=n;e++){let t=e/n,l=Math.sin((1-t)*c)/Math.sin(c),u=Math.sin(t*c)/Math.sin(c),d=l*Math.cos(i)*Math.cos(a)+u*Math.cos(o)*Math.cos(s),f=l*Math.cos(i)*Math.sin(a)+u*Math.cos(o)*Math.sin(s),p=l*Math.sin(i)+u*Math.sin(o);if(isNaN(d)||isNaN(f)||isNaN(p))continue;let m=Math.atan2(p,Math.sqrt(d**2+f**2)),h=Math.atan2(f,d);isNaN(m)||isNaN(h)||r.push([Se(h),Se(m)])}return r.slice(1,-1)}(e,t,Math.floor(r/n));return this.limitCoordinates(i)}limitCoordinates(e){return e.map(e=>[D(e[0],this.config.coordinatePrecision),D(e[1],this.config.coordinatePrecision)])}};function we(e,t){if(e.geometry.type!==`LineString`)return{valid:!1,reason:`Feature is not a LineString`};if(e.geometry.coordinates.length<2)return{valid:!1,reason:`Feature has less than 2 coordinates`};for(let n=0;n<e.geometry.coordinates.length;n++){if(!ae(e.geometry.coordinates[n]))return{valid:!1,reason:`Feature has invalid coordinates`};if(!ie(e.geometry.coordinates[n],t))return{valid:!1,reason:`Feature has coordinates with excessive precision`}}return{valid:!0}}function Te(e){return Math.sqrt(e[0]**2+e[1]**2+e[2]**2)}function L(e,t){let n=function(e,t){let[n,r,i]=e,[a,o,s]=t;return n*a+r*o+i*s}(e,t)/(Te(e)*Te(t));return Math.acos(Math.min(Math.max(n,-1),1))}function R(e){let t=w(e[1]),n=w(e[0]);return[Math.cos(t)*Math.cos(n),Math.cos(t)*Math.sin(n),Math.sin(t)]}function z(e){let[t,n,r]=e,i=E(Math.asin(r));return[E(Math.atan2(n,t)),i]}function Ee(e,t,n){let r=R(e),i=R(t),[a,o,s]=R(n),[c,l,u]=function(e,t){let[n,r,i]=e,[a,o,s]=t;return[r*s-i*o,i*a-n*s,n*o-r*a]}(r,i),d=l*s-u*o,f=u*a-c*s,p=c*o-l*a,m=p*l-f*u,h=d*u-p*c,g=f*c-d*l,_=1/Math.sqrt(m**2+h**2+g**2),v=[m*_,h*_,g*_],y=[-1*m*_,-1*h*_,-1*g*_],ee=L(r,i),b=L(r,v),x=L(i,v),C=L(r,y),w=L(i,y),T;return T=b<C&&b<w||x<C&&x<w?v:y,L(r,T)>ee||L(i,T)>ee?S(z(T),z(r))<=S(z(T),z(i))?[z(r),!0,!1]:[z(i),!1,!0]:[z(T),!1,!1]}function De(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=Math.max(0,Math.min(1,((n.x-e.x)*r+(n.y-e.y)*i)/(r*r+i*i)));return{x:e.x+a*r,y:e.y+a*i}}var Oe=class extends M{constructor(e,t,n){super(e),this.config=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.getSnappableCoordinateFirstClick=e=>{let t=this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode));return t.coordinate?[D(t.coordinate[0],this.config.coordinatePrecision),D(t.coordinate[1],this.config.coordinatePrecision)]:void 0},this.getSnappableCoordinate=(e,t)=>{let n=this.getSnappable(e,e=>!!(e.properties&&e.properties.mode===this.mode&&e.id!==t));return n.coordinate?[D(n.coordinate[0],this.config.coordinatePrecision),D(n.coordinate[1],this.config.coordinatePrecision)]:void 0},this.config=e,this.pixelDistance=t,this.clickBoundingBox=n}getSnappable(e,t){let n=this.clickBoundingBox.create(e),r=this.store.search(n,t),i={featureId:void 0,featureCoordinateIndex:void 0,coordinate:void 0,minDistance:1/0};return r.forEach(t=>{let n;if(t.geometry.type===`Polygon`)n=t.geometry.coordinates[0];else{if(t.geometry.type!==`LineString`)return;n=t.geometry.coordinates}let r=[];for(let e=0;e<n.length-1;e++)r.push([n[e],n[e+1]]);let a,o=[e.lng,e.lat];if(this.config.projection===`web-mercator`?a=function(e,t){let n=[1/0,1/0],r=1/0,i=0;for(let a of t){let o=a[0],s=a[1],c,l=1/0,u=k(o[0],o[1]),d=k(s[0],s[1]),f=k(e[0],e[1]);if(o[0]===e[0]&&o[1]===e[1])c=o;else if(s[0]===e[0]&&s[1]===e[1])c=s;else{let{x:e,y:t}=De(u,d,f),{lng:n,lat:r}=A(e,t);c=[n,r]}c&&(l=F(f,k(c[0],c[1])),l<r&&(n=c,r=l,i=t.indexOf(a)))}return r===1/0?void 0:{coordinate:n,lineIndex:i,distance:r}}(o,r):this.config.projection===`globe`&&(a=function(e,t){let n=[1/0,1/0],r=1/0,i=0;for(let a of t){let o=a[0],s=a[1],c,l=1/0;o[0]===e[0]&&o[1]===e[1]?c=o:s[0]===e[0]&&s[1]===e[1]?c=s:[c]=Ee(o,s,e),c&&(l=S(e,c),l<r&&(n=c,r=l,i=t.indexOf(a)))}return r===1/0?void 0:{coordinate:n,distance:r,lineIndex:i}}(o,r)),!a)return;let s=this.pixelDistance.measure(e,a.coordinate);s<i.minDistance&&s<this.pointerDistance&&(i.featureId=t.id,i.coordinate=[D(a.coordinate[0],this.config.coordinatePrecision),D(a.coordinate[1],this.config.coordinatePrecision)],i.featureCoordinateIndex=a.lineIndex,i.minDistance=s)}),i}};function B(e){return Array.isArray(e)&&e.length>0&&Array.isArray(e[0])&&Array.isArray(e[0][0])}var V=e=>B(e)?e[0].slice(0,-1):e,H=e=>B(e)?e[0]:e,ke=class extends M{constructor(e,t,n,r){super(e),this.config=void 0,this.pixelDistance=void 0,this.mutateFeatureBehavior=void 0,this.readFeatureBehavior=void 0,this._startEndPoints=[],this.config=e,this.pixelDistance=t,this.mutateFeatureBehavior=n,this.readFeatureBehavior=r}get ids(){return this._startEndPoints.concat()}set ids(e){}create(e){if(this.ids.length)throw Error(`Opening and closing points already created`);let t=B(e),n=H(e);if(t){if(n.length<=3)throw Error(`Requires at least 4 coordinates`);this._startEndPoints=this.mutateFeatureBehavior.createGuidancePoints({coordinates:[n[0],n[n.length-2]],type:p.CLOSING_POINT})}else this._startEndPoints=[this.mutateFeatureBehavior.createGuidancePoint({coordinate:n[n.length-2],type:p.CLOSING_POINT})]}delete(){this.ids.length&&(this.mutateFeatureBehavior.deleteFeaturesIfPresent(this.ids),this._startEndPoints=[])}updateOne(e,t){this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[e],coordinate:t}])}update(e){let t=H(e);this.ids.length===1?this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:t[t.length-2]}]):this.ids.length===2&&this.mutateFeatureBehavior.updateGuidancePoints([{featureId:this.ids[0],coordinate:t[0]},{featureId:this.ids[1],coordinate:t[t.length-3]}])}isLineStringClosingPoint(e){if(this.ids.length!==1)return{isClosing:!1};let t=this.readFeatureBehavior.getGeometry(this.ids[0]);return{isClosing:this.pixelDistance.measure(e,t.coordinates)<this.pointerDistance}}isPolygonClosingPoints(e){if(this.ids.length!==2)return{isClosing:!1,isPreviousClosing:!1};let t=this.readFeatureBehavior.getGeometry(this.ids[0]),n=this.readFeatureBehavior.getGeometry(this.ids[1]),r=this.pixelDistance.measure(e,t.coordinates),i=this.pixelDistance.measure(e,n.coordinates);return{isClosing:r<this.pointerDistance,isPreviousClosing:i<this.pointerDistance}}},Ae=class extends M{constructor(e,t,n){super(e),this.readFeature=void 0,this.mutateFeature=void 0,this.readFeature=t,this.mutateFeature=n}createOrUpdate({featureId:e,featureCoordinates:t}){if(!this.readFeature.hasFeature(e))return void this.deleteOrphanedPoints(e);let n=V(t),r=this.readFeature.getProperties(e),i=r.coordinatePointIds;if(i)if(i&&i.every(e=>this.readFeature.hasFeature(e))){let t=r.coordinatePointIds,i=t.map(e=>this.readFeature.getGeometry(e).coordinates);if(t.length!==n.length){this.deleteCoordinatePoints(t);let i=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,i)}else{let e=[];n.forEach((n,r)=>{n[0]===i[r][0]&&n[1]===i[r][1]||e.push({featureId:t[r],coordinate:n})}),this.mutateFeature.updateGuidancePoints(e)}}else{let t=i.filter(e=>this.readFeature.hasFeature(e));t.length&&this.deleteCoordinatePoints(t);let a=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,a)}else{let t=this.createPoints(n,r.mode,e);this.setFeatureCoordinatePoints(e,t)}}deletePointsByFeatureIds(e){for(let t of e)this.deleteIfPresent(t)}updateOneAtIndex(e,t,n){let r=this.readFeature.getProperties(e).coordinatePointIds;r&&r.length!==0&&r[t]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:r[t],coordinate:n}])}updateAllInPlace({featureId:e,featureCoordinates:t}){let n=this.readFeature.getProperties(e);if(!n.coordinatePointIds)return;let r=V(t);r.length===n.coordinatePointIds.length&&this.mutateFeature.updateGuidancePoints(n.coordinatePointIds.map((e,t)=>({featureId:e,coordinate:r[t]})))}createPoints(e,t,n){return this.mutateFeature.createGuidancePoints({coordinates:e,type:p.COORDINATE_POINT,additionalProperties:e=>({mode:t,[p.COORDINATE_POINT]:!0,[p.COORDINATE_POINT_FEATURE_ID]:n,index:e})})}setFeatureCoordinatePoints(e,t,n=u.Commit){let r=this.readFeature.getGeometryType(e),i={featureId:e,propertyMutations:{[p.COORDINATE_POINT_IDS]:t},context:{updateType:n}};if(r===`Polygon`)this.mutateFeature.updatePolygon(i);else{if(r!==`LineString`)throw Error(`Unsupported geometry type for coordinate points`);this.mutateFeature.updateLineString(i)}}deleteCoordinatePoints(e){this.mutateFeature.deleteFeaturesIfPresent(e)}deleteIfPresent(e){if(!this.readFeature.hasFeature(e))return;let t=this.readFeature.getProperties(e).coordinatePointIds;t&&(this.deleteCoordinatePoints(t),this.setFeatureCoordinatePoints(e,null))}deleteOrphanedPoints(e){let t=this.readFeature.getAllFeatureIdsWhere(t=>t[p.COORDINATE_POINT_FEATURE_ID]===e);this.mutateFeature.deleteFeaturesIfPresent(t)}},je=class{constructor(e){this.undoHistory=[],this.redoHistory=[],this.cloneCoordinatesFunction=void 0,this.maxStackSize=void 0,this.cloneCoordinatesFunction=e=>this.cloneRecursively(e);let t=e?.maxStackSize;this.maxStackSize=t!==void 0&&Number.isFinite(t)?Math.max(0,Math.floor(t)):1/0}setMaxStackSize(e){Number.isFinite(e)?(this.maxStackSize=Math.max(0,Math.floor(e)),this.trimHistoryToMax(this.undoHistory),this.trimHistoryToMax(this.redoHistory)):this.maxStackSize=1/0}trimHistoryToMax(e){if(Number.isFinite(this.maxStackSize))for(;e.length>this.maxStackSize;)e.shift()}pushUndoEntry(e){this.maxStackSize!==0&&(this.undoHistory.push(e),this.trimHistoryToMax(this.undoHistory))}pushRedoEntry(e){this.maxStackSize!==0&&(this.redoHistory.push(e),this.trimHistoryToMax(this.redoHistory))}cloneRecursively(e){return Array.isArray(e)?e.map(e=>this.cloneRecursively(e)):typeof e==`object`&&e?a({},e):e}cloneCoordinates(e){return this.cloneCoordinatesFunction(e)}cloneEntry(e){return{featureCoordinates:this.cloneCoordinates(e.featureCoordinates),currentCoordinate:e.currentCoordinate}}clear(){this.undoHistory=[],this.redoHistory=[]}undoSize(){return this.undoHistory.length}redoSize(){return this.redoHistory.length}recordSnapshot(e){this.pushUndoEntry(this.cloneEntry(e)),this.redoHistory=[]}beginUndo(){let e=this.undoHistory.pop();if(!e)return;let t=this.cloneEntry(e);this.pushRedoEntry(t);let n=this.undoHistory[this.undoHistory.length-1];return{undoneEntry:t,previousEntry:n?this.cloneEntry(n):void 0}}takeRedo(){let e=this.redoHistory.pop();if(e)return this.cloneEntry(e)}commitRedo(e){this.pushUndoEntry(this.cloneEntry(e))}},Me={cancel:`Escape`,finish:`Enter`},Ne={start:`crosshair`,close:`pointer`,dragStart:`grabbing`,dragEnd:`crosshair`},Pe=class extends b{constructor(e){super(e,!0),this.mode=`linestring`,this.currentCoordinate=0,this.currentId=void 0,this.keyEvents=Me,this.snapping=void 0,this.cursors=Ne,this.mouseMove=!1,this.insertCoordinates=void 0,this.lastCommittedCoordinates=void 0,this.snappedPointId=void 0,this.lastMouseMoveEvent=void 0,this.showCoordinatePoints=!1,this.finishOnNthCoordinate=void 0,this.editable=!1,this.editedFeatureId=void 0,this.editedFeatureCoordinateIndex=void 0,this.editedSnapType=void 0,this.editedInsertIndex=void 0,this.editedPointId=void 0,this.coordinateSnapping=void 0,this.insertPoint=void 0,this.lineSnapping=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.closingPoints=void 0,this.coordinatePoints=void 0,this.undoRedo=void 0,this.updateOptions(e)}updateOptions(e){if(super.updateOptions(e),e?.finishOnNthCoordinate!==void 0&&Number.isInteger(e.finishOnNthCoordinate)&&e.finishOnNthCoordinate>1&&(this.finishOnNthCoordinate=Math.floor(e.finishOnNthCoordinate)),e!=null&&e.cursors&&(this.cursors=a({},this.cursors,e.cursors)),e!=null&&e.snapping&&(this.snapping=e.snapping),e?.keyEvents===null?this.keyEvents={cancel:null,finish:null}:e!=null&&e.keyEvents&&(this.keyEvents=a({},this.keyEvents,e.keyEvents)),e!=null&&e.insertCoordinates&&(this.insertCoordinates=e.insertCoordinates),e&&e.editable&&(this.editable=e.editable),e?.showCoordinatePoints!==void 0){if(this.showCoordinatePoints=e.showCoordinatePoints,this.coordinatePoints&&!0===e.showCoordinatePoints)this.store.copyAllWhere(e=>e.mode===this.mode).forEach(e=>{this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})});else if(this.coordinatePoints&&!1===this.showCoordinatePoints){let e=this.store.copyAllWhere(e=>e.mode===this.mode&&!!e[p.COORDINATE_POINT_IDS]?.length);this.coordinatePoints.deletePointsByFeatureIds(e.map(e=>e.id))}}}shouldFinishOnCommit(e){return!!this.finishOnNthCoordinate&&Math.max(0,e.coordinates.length-1)>=this.finishOnNthCoordinate}updateSnappedCoordinate(e){let t=this.snapCoordinate(e);return t?(this.snappedPointId?this.mutateFeature.updateGuidancePoints([{featureId:this.snappedPointId,coordinate:t}]):this.snappedPointId=this.mutateFeature.createGuidancePoint({coordinate:t,type:p.SNAPPING_POINT}),e.lng=t[0],e.lat=t[1]):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0),t}close(){if(this.currentId===void 0)return;let e=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:u.Finish,action:o},coordinateMutations:[{type:ue,index:-1}],propertyMutations:{[p.CURRENTLY_DRAWING]:void 0}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:e.geometry.coordinates});let t=this.currentId;this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),this.closingPoints.delete(),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(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(t,{mode:this.mode,action:o})}generateInsertCoordinates(e,t){if(!this.insertCoordinates||!this.lastCommittedCoordinates)throw Error(`Not able to insert coordinates`);if(this.insertCoordinates.strategy!==`amount`)throw Error(`Strategy does not exist`);let n=S(e,t)/(this.insertCoordinates.value+1),r=[];return this.projection===`globe`?r=this.insertPoint.generateInsertionGeodesicCoordinates(e,t,n):this.projection===`web-mercator`&&(r=this.insertPoint.generateInsertionCoordinates(e,t,n)),r}createLine(e){let t=this.mutateFeature.createLineString({coordinates:[e,e],properties:{mode:this.mode,[p.CURRENTLY_DRAWING]:!0}});this.lastCommittedCoordinates=t.geometry.coordinates,this.currentId=t.id,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.setDrawing(),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}firstUpdateToLine(e){if(!this.currentId)return;this.setCursor(this.cursors.close);let t=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:u.Commit},coordinateMutations:[{type:N,index:-1,coordinate:e}]});t&&(this.closingPoints.create(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates}),this.lastCommittedCoordinates=t.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(t.geometry)&&this.close())}updateToLine(e,t){if(!this.currentId)return;let{isClosing:n}=this.closingPoints.isLineStringClosingPoint(e);if(n)return void this.close();this.setCursor(this.cursors.close);let r=this.mutateFeature.updateLineString({featureId:this.currentId,context:{updateType:u.Commit},coordinateMutations:[{type:N,index:-1,coordinate:t}]});r&&(this.closingPoints.update(r.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:r.geometry.coordinates}),this.lastCommittedCoordinates=r.geometry.coordinates,this.currentCoordinate++,this.pushHistorySnapshot(this.currentId,this.currentCoordinate),this.shouldFinishOnCommit(r.geometry)&&this.close())}undoSize(){return this.undoRedo.undoSize()}clearHistory(){this.undoRedo.clear()}pushHistorySnapshot(e,t){let n=this.readFeature.getGeometry(e);this.undoRedo.recordSnapshot({featureCoordinates:n.coordinates,currentCoordinate:t})}updateSnappedGuidancePointFromLastMouseMove(){this.snapping&&this.lastMouseMoveEvent?this.updateSnappedCoordinate(this.lastMouseMoveEvent):this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0)}syncClosingPoints(e){this.currentCoordinate>=2?this.closingPoints.ids.length?this.closingPoints.update(e):this.closingPoints.create(e):this.closingPoints.delete()}undo(){if(this.state!==`drawing`||!this.currentId)return;let e=this.undoRedo.beginUndo();if(!e)return;let{previousEntry:t}=e;if(!t){let e=this.currentId;this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.closingPoints.delete(),this.state===`drawing`&&this.setStarted(),this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.updateSnappedGuidancePointFromLastMouseMove();return}let n=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:P,coordinates:t.featureCoordinates},propertyMutations:{[p.CURRENTLY_DRAWING]:!0},context:{updateType:u.Commit}});n&&(this.currentCoordinate=t.currentCoordinate,this.lastCommittedCoordinates=n.geometry.coordinates,this.syncClosingPoints(n.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:n.geometry.coordinates}),this.updateSnappedGuidancePointFromLastMouseMove())}redoSize(){return this.undoRedo.redoSize()}redo(){let e=this.undoRedo.takeRedo();if(e){if(this.currentId){let t=this.mutateFeature.updateLineString({featureId:this.currentId,coordinateMutations:{type:P,coordinates:e.featureCoordinates},propertyMutations:{[p.CURRENTLY_DRAWING]:!0},context:{updateType:u.Commit}});if(!t)return;this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=t.geometry.coordinates,this.syncClosingPoints(t.geometry.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:t.geometry.coordinates})}else{let{id:t,geometry:n}=this.mutateFeature.createLineString({coordinates:e.featureCoordinates,properties:{mode:this.mode,[p.CURRENTLY_DRAWING]:!0}});this.currentId=t,this.currentCoordinate=e.currentCoordinate,this.lastCommittedCoordinates=n.coordinates,this.state===`started`&&this.setDrawing(),this.syncClosingPoints(n.coordinates),this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:n.coordinates})}this.undoRedo.commitRedo(e),this.updateSnappedGuidancePointFromLastMouseMove()}}registerBehaviors(e){this.insertPoint=new Ce(e),this.clickBoundingBox=new he(e),this.pixelDistance=new ge(e),this.lineSnapping=new Oe(e,this.pixelDistance,this.clickBoundingBox),this.coordinateSnapping=new _e(e,this.pixelDistance,this.clickBoundingBox),this.readFeature=new pe(e),this.mutateFeature=new de(e,{validate:this.validate}),this.closingPoints=new ke(e,this.pixelDistance,this.mutateFeature,this.readFeature),this.coordinatePoints=new Ae(e,this.readFeature,this.mutateFeature),this.undoRedo=new je({maxStackSize:e.undoRedoMaxStackSize})}start(){this.setStarted(),this.setCursor(this.cursors.start)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onMouseMove(e){this.mouseMove=!0,this.setCursor(this.cursors.start),this.lastMouseMoveEvent=e;let t=this.updateSnappedCoordinate(e)||[e.lng,e.lat];if(this.currentId===void 0||this.currentCoordinate===0)return;let{isClosing:n}=this.closingPoints.isLineStringClosingPoint(e);n&&this.setCursor(this.cursors.close);let r=[{type:le,index:-1,coordinate:t}];if(this.insertCoordinates){let e=this.getInsertCoordinates(t);e&&(r={type:P,coordinates:e})}let i=this.mutateFeature.updateLineString({coordinateMutations:r,featureId:this.currentId,context:{updateType:u.Provisional}});i&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.currentId,featureCoordinates:i.geometry.coordinates})}getInsertCoordinates(e){if(!this.lastCommittedCoordinates)return;let t=this.lastCommittedCoordinates[this.lastCommittedCoordinates.length-1];if(fe(t,e))return;let n=this.generateInsertCoordinates(t,e);return[...this.lastCommittedCoordinates.slice(0,-1),...n,e]}onRightClick(e){if(!this.editable||this.state!==`started`)return;let{featureId:t,featureCoordinateIndex:n}=this.coordinateSnapping.getSnappable(e,e=>this.lineStringFilter(e));if(!t||n===void 0)return;let r=this.readFeature.getGeometry(t),i;if(r.type!==`LineString`||(i=r.coordinates,i.length<=2))return;let a=this.mutateFeature.updateLineString({featureId:t,coordinateMutations:[{type:ue,index:n}],context:{updateType:u.Finish,action:s}});a&&this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:t,featureCoordinates:a.geometry.coordinates}),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(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(t,{mode:this.mode,action:c})}onLeftClick(e){this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(this.snappedPointId),void 0);let t=this.snapCoordinate(e)||[e.lng,e.lat];this.currentCoordinate===0?this.createLine(t):this.currentCoordinate===1&&this.currentId?this.firstUpdateToLine(t):this.currentId&&this.updateToLine(e,t)}onClick(e){this.currentId===void 0||this.readFeature.hasFeature(this.currentId)||this.cleanUp(),(e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e))&&(this.currentCoordinate>0&&!this.mouseMove&&this.onMouseMove(e),this.mouseMove=!1,e.button===`right`?this.onRightClick(e):e.button===`left`&&this.onLeftClick(e))}onKeyDown(){}onKeyUp(e){e.key===this.keyEvents.cancel&&this.cleanUp(),e.key===this.keyEvents.finish&&this.close()}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e)||!this.editable)return;let n;if(this.state===`started`){let t=this.lineSnapping.getSnappable(e,e=>this.lineStringFilter(e));t.coordinate&&(this.editedSnapType=`line`,this.editedFeatureCoordinateIndex=t.featureCoordinateIndex,this.editedFeatureId=t.featureId,n=t.coordinate);let r=this.coordinateSnapping.getSnappable(e,e=>this.lineStringFilter(e));r.coordinate&&(this.editedSnapType=`coordinate`,this.editedFeatureCoordinateIndex=r.featureCoordinateIndex,this.editedFeatureId=r.featureId,n=r.coordinate)}this.editedFeatureId&&n&&(this.editedPointId||=this.mutateFeature.createGuidancePoint({coordinate:n,type:p.EDITED}),this.setCursor(this.cursors.dragStart),t(!1))}onDrag(e,t){if(this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.editedFeatureCoordinateIndex!==void 0){if(this.editedSnapType===`coordinate`||this.editedSnapType===`line`&&this.editedInsertIndex!==void 0){let t=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:u.Provisional},coordinateMutations:[{type:le,index:this.editedFeatureCoordinateIndex,coordinate:[e.lng,e.lat]}]});if(!t)return;this.showCoordinatePoints&&(this.editedInsertIndex===void 0?this.coordinatePoints.updateOneAtIndex(this.editedFeatureId,this.editedFeatureCoordinateIndex,[e.lng,e.lat]):this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:t.geometry.coordinates}))}else if(this.editedSnapType===`line`&&this.editedInsertIndex===void 0){this.editedInsertIndex=this.editedFeatureCoordinateIndex+1;let e=this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:u.Provisional}});if(!e)return;this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:this.editedFeatureId,featureCoordinates:e.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:[e.lng,e.lat]}]),this.mutateFeature.updateLineString({featureId:this.editedFeatureId,context:{updateType:u.Provisional},propertyMutations:{[p.EDITED]:!0}})}}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||(this.setCursor(this.cursors.dragEnd),!this.mutateFeature.updateLineString({featureId:this.editedFeatureId,propertyMutations:{[p.EDITED]:!1},context:{updateType:u.Finish,action:s}})))return;let n=this.editedFeatureId;t(!0),this.snappedPointId&&=(this.mutateFeature.deleteFeatureIfPresent(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:s})}cleanUp(){let e=this.currentId,t=this.snappedPointId;this.snappedPointId=void 0,this.currentId=void 0,this.currentCoordinate=0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted(),e&&this.showCoordinatePoints&&this.coordinatePoints.deletePointsByFeatureIds([e]),this.mutateFeature.deleteFeatureIfPresent(e),this.mutateFeature.deleteFeatureIfPresent(t),this.closingPoints.delete()}styleFeature(e){let t=a({},{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,lineStringDash:void 0});if(e.type===`Feature`&&e.geometry.type===`LineString`&&e.properties.mode===this.mode)return t.lineStringDash=this.styles.lineStringDash,t.lineStringColor=this.getHexColorStylingValue(this.styles.lineStringColor,t.lineStringColor,e),t.lineStringOpacity=this.getNumericStylingValue(this.styles.lineStringOpacity,t.lineStringOpacity===void 0?1:t.lineStringOpacity,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.lineStringWidth,t.lineStringWidth,e),t.zIndex=m,t;if(e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode){let n=e.properties[p.COORDINATE_POINT],r=e.properties[p.CLOSING_POINT]?`closingPoint`:e.properties[p.SNAPPING_POINT]?`snappingPoint`:n?`coordinatePoint`:void 0;if(!r)return t;let i={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 t.pointWidth=this.getNumericStylingValue(i[r].width,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(i[r].opacity,1,e),t.pointColor=this.getHexColorStylingValue(i[r].color,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(i[r].outlineColor,`#ffffff`,e),t.pointOutlineWidth=this.getNumericStylingValue(i[r].outlineWidth,2,e),t.pointOutlineOpacity=this.getNumericStylingValue(i[r].outlineOpacity,1,e),t.zIndex=n?20:50,t}return t}validateFeature(e){return this.validateModeFeature(e,e=>we(e,this.coordinatePrecision))}lineStringFilter(e){return!!(e.geometry.type===`LineString`&&e.properties&&e.properties.mode===this.mode)}snapCoordinate(e){var t,n,r;let i;if((t=this.snapping)!=null&&t.toLine){let t;t=this.currentId?this.lineSnapping.getSnappableCoordinate(e,this.currentId):this.lineSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((n=this.snapping)!=null&&n.toCoordinate){let t;t=this.currentId?this.coordinateSnapping.getSnappableCoordinate(e,this.currentId):this.coordinateSnapping.getSnappableCoordinateFirstClick(e),t&&(i=t)}if((r=this.snapping)!=null&&r.toCustom){let t=this.snapping.toCustom(e,{currentCoordinate:this.currentCoordinate,currentId:this.currentId,getCurrentGeometrySnapshot:this.currentId?()=>this.readFeature.getGeometry(this.currentId):()=>null,project:this.project,unproject:this.unproject});t&&(i=t)}return i}afterFeatureUpdated(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates}),this.editedFeatureId===e.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===e.id&&(this.closingPoints.delete(),this.currentCoordinate=0,this.currentId=void 0,this.lastCommittedCoordinates=void 0,this.undoRedo.clear(),this.state===`drawing`&&this.setStarted())}afterFeatureAdded(e){this.showCoordinatePoints&&this.coordinatePoints.createOrUpdate({featureId:e.id,featureCoordinates:e.geometry.coordinates})}},Fe=`Feature is not a Point`,Ie=`Feature has invalid coordinates`,Le=`Feature has coordinates with excessive precision`;function Re(e,t){return e.geometry.type===`Point`?ae(e.geometry.coordinates)?ie(e.geometry.coordinates,t)?{valid:!0}:{valid:!1,reason:Le}:{valid:!1,reason:Ie}:{valid:!1,reason:Fe}}var ze=class extends M{constructor(e,t,n){super(e),this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pixelDistance=t,this.clickBoundingBox=n}getNearestPointFeature(e){let t=this.clickBoundingBox.create(e),n=this.store.search(t),r,i=1/0;for(let t=0;t<n.length;t++){let a=n[t];if(a.geometry.type!==`Point`||a.properties.mode!==this.mode)continue;let o=this.pixelDistance.measure(e,a.geometry.coordinates);o>i||o>this.pointerDistance||(i=o,r=a)}return r}},Be={create:`crosshair`,dragStart:`grabbing`,dragEnd:`crosshair`},Ve=class extends b{constructor(e){super(e,!0),this.mode=`point`,this.cursors=Be,this.editable=!1,this.editedFeatureId=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.pointSearch=void 0,this.mutateFeature=void 0,this.updateOptions(e)}updateOptions(e){super.updateOptions(e),e!=null&&e.cursors&&(this.cursors=a({},this.cursors,e.cursors)),e!=null&&e.editable&&(this.editable=e.editable)}start(){this.setStarted(),this.setCursor(this.cursors.create)}stop(){this.cleanUp(),this.setStopped(),this.setCursor(`unset`)}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}onMouseMove(){}onKeyDown(){}onKeyUp(){}cleanUp(){this.editedFeatureId=void 0}onDragStart(e,t){if(this.allowPointerEvent(this.pointerEvents.onDragStart,e)){if(this.editable){let t=this.pointSearch.getNearestPointFeature(e);this.editedFeatureId=t?.id}this.editedFeatureId&&(this.setCursor(this.cursors.dragStart),t(!1))}}onDrag(e,t){this.allowPointerEvent(this.pointerEvents.onDrag,e)&&this.editedFeatureId!==void 0&&this.mutateFeature.updatePoint({featureId:this.editedFeatureId,coordinateMutations:{type:P,coordinates:[e.lng,e.lat]},propertyMutations:{[p.EDITED]:!0},context:{updateType:u.Provisional}})}onDragEnd(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragEnd,e)||this.editedFeatureId===void 0||!this.mutateFeature.updatePoint({featureId:this.editedFeatureId,propertyMutations:{mode:this.mode,[p.EDITED]:!1},context:{updateType:u.Finish,action:`edit`}}))return;let n=this.editedFeatureId;this.setCursor(this.cursors.dragEnd),this.editedFeatureId=void 0,t(!0),this.onFinish(n,{mode:this.mode,action:o})}registerBehaviors(e){this.pixelDistance=new ge(e),this.clickBoundingBox=new he(e),this.pointSearch=new ze(e,this.pixelDistance,this.clickBoundingBox),this.mutateFeature=new de(e,{validate:this.validate})}styleFeature(e){let t=a({},{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,lineStringDash:void 0});if(e.type===`Feature`&&e.geometry.type===`Point`&&e.properties.mode===this.mode){let n=!!(e.id&&this.editedFeatureId===e.id);t.pointWidth=this.getNumericStylingValue(n?this.styles.editedPointWidth:this.styles.pointWidth,t.pointWidth,e),t.pointOpacity=this.getNumericStylingValue(this.styles.pointOpacity,t.pointOpacity===void 0?1:t.pointOpacity,e),t.pointColor=this.getHexColorStylingValue(n?this.styles.editedPointColor:this.styles.pointColor,t.pointColor,e),t.pointOutlineColor=this.getHexColorStylingValue(n?this.styles.editedPointOutlineColor:this.styles.pointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.pointOutlineOpacity,t.pointOutlineOpacity===void 0?1:t.pointOutlineOpacity,e),t.pointOutlineWidth=this.getNumericStylingValue(n?this.styles.editedPointOutlineWidth:this.styles.pointOutlineWidth,2,e),t.zIndex=30}return t}validateFeature(e){return this.validateModeFeature(e,e=>Re(e,this.coordinatePrecision))}onLeftClick(e){let t=this.mutateFeature.createPoint({coordinates:[e.lng,e.lat],properties:{mode:this.mode},context:{updateType:u.Finish,action:o}});t&&this.onFinish(t.id,{mode:this.mode,action:o})}onRightClick(e){if(!this.editable)return;let t=this.pointSearch.getNearestPointFeature(e);t&&this.mutateFeature.deleteFeatureIfPresent(t.id)}afterFeatureUpdated(e){this.editedFeatureId===e.id&&(this.editedFeatureId=void 0,this.setCursor(this.cursors.create))}};function U(e,t){let n=e,r=t,i=w(n[1]),a=w(r[1]),o=w(r[0]-n[0]);o>Math.PI&&(o-=2*Math.PI),o<-Math.PI&&(o+=2*Math.PI);let s=Math.log(Math.tan(a/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),c=(E(Math.atan2(o,s))+360)%360;return c>180?-(360-c):c}function He(e,t,n){let r=t;t<0&&(r=-Math.abs(r));let i=r/C,a=e[0]*Math.PI/180,o=w(e[1]),s=w(n),c=i*Math.cos(s),l=o+c;Math.abs(l)>Math.PI/2&&(l=l>0?Math.PI-l:-Math.PI-l);let u=Math.log(Math.tan(l/2+Math.PI/4)/Math.tan(o/2+Math.PI/4)),d=Math.abs(u)>1e-11?c/u:Math.cos(o),f=[(180*(a+i*Math.sin(s)/d)/Math.PI+540)%360-180,180*l/Math.PI];return f[0]+=f[0]-e[0]>180?-360:e[0]-f[0]>180?360:0,f}function Ue(e,t,n,r,i){let a=r(e[0],e[1]),o=r(t[0],t[1]),{lng:s,lat:c}=i((a.x+o.x)/2,(a.y+o.y)/2);return[D(s,n),D(c,n)]}function We(e,t,n){let r=He(e,1e3*S(e,t)/2,U(e,t));return[D(r[0],n),D(r[1],n)]}function W({featureCoords:e,precision:t,unproject:n,project:r,projection:i}){let a=[];for(let o=0;o<e.length-1;o++){let s;if(i===`web-mercator`)s=Ue(e[o],e[o+1],t,r,n);else{if(i!==`globe`)throw Error(`Invalid projection`);s=We(e[o],e[o+1],t)}a.push(s)}return a}var Ge=class extends M{constructor(e,t,n,r,i,a){super(e),this.config=void 0,this.selectionPointBehavior=void 0,this.coordinatePointBehavior=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.pixelDistance=void 0,this._midPoints=[],this.config=e,this.selectionPointBehavior=t,this.coordinatePointBehavior=n,this.mutateFeature=r,this.readFeature=i,this.pixelDistance=a}getMidpointConfig(e){return{featureCoords:e,precision:this.coordinatePrecision,project:this.config.project,unproject:this.config.unproject,projection:this.config.projection}}get ids(){return this._midPoints.concat()}set ids(e){}getNearestMidPoint(e){let t,n=1/0;return this.ids.forEach(r=>{let i=this.readFeature.getGeometry(r),a=this.pixelDistance.measure(e,i.coordinates);a<this.pointerDistance&&a<n&&(n=a,t=r)}),t}insert({featureId:e,midPointId:t}){let n=this.readFeature.getGeometry(t),{midPointFeatureId:r,midPointSegment:i}=this.readFeature.getProperties(t),a=this.readFeature.getGeometry(r),o={featureId:r,coordinateMutations:[{type:N,index:i,coordinate:n.coordinates}],context:{updateType:u.Commit}},s=null;if(a.type===`Polygon`)s=this.mutateFeature.updatePolygon(o);else{if(a.type!==`LineString`)throw Error(`Midpoints can only be added to polygons or linestrings`);s=this.mutateFeature.updateLineString(o)}if(!s)throw Error(`Failed to insert midpoint coordinate`);let c=s.geometry.coordinates;this.readFeature.getProperties(e)[p.COORDINATE_POINT_IDS]&&this.coordinatePointBehavior.createOrUpdate({featureId:e,featureCoordinates:c}),this.mutateFeature.deleteFeaturesIfPresent([...this.selectionPointBehavior.ids,...this._midPoints]),this.create({featureCoordinates:c,featureId:r}),this.selectionPointBehavior.create({featureCoordinates:c,featureId:e})}create({featureCoordinates:e,featureId:t}){if(!this.readFeature.hasFeature(t))throw Error(`Store does not have feature with this id`);let n=H(e),r=W(this.getMidpointConfig(n));this._midPoints=this.mutateFeature.createGuidancePoints({additionalProperties:e=>({mode:this.mode,midPointSegment:e,midPointFeatureId:t,[f.MID_POINT]:!0}),coordinates:r,type:f.MID_POINT})}delete(){this._midPoints.length&&(this.mutateFeature.deleteFeaturesIfPresent(this._midPoints),this._midPoints=[])}updateAllInPlace({featureCoordinates:e}){if(this._midPoints.length===0)return;let t=H(e),n=W(this.getMidpointConfig(t));this.mutateFeature.updateGuidancePoints(this._midPoints.map((e,t)=>({featureId:e,coordinate:n[t]})))}updateOneAtIndex(e,t){if(e<0&&(e=this._midPoints.length+e),this._midPoints[e]===void 0)return;let n=H(t),r=W(this.getMidpointConfig(n));this.mutateFeature.updateGuidancePoints([{featureId:this._midPoints[e],coordinate:r[e]}])}},Ke=class extends M{constructor(e,t){super(e),this.mutateFeature=void 0,this._selectionPoints=[],this.mutateFeature=t}get ids(){return this._selectionPoints.concat()}set ids(e){}create({featureId:e,featureCoordinates:t}){let n=V(t);this._selectionPoints=this.mutateFeature.createGuidancePoints({coordinates:n,type:f.SELECTION_POINT,additionalProperties:t=>({[f.SELECTION_POINT_FEATURE_ID]:e,index:t})})}delete(){this.ids.length&&(this.mutateFeature.deleteFeaturesIfPresent(this.ids),this._selectionPoints=[])}updateAllInPlace({featureCoordinates:e}){if(this._selectionPoints.length===0)return;let t=V(e);t.length===this._selectionPoints.length&&this.mutateFeature.updateGuidancePoints(this._selectionPoints.map((e,n)=>({featureId:e,coordinate:t[n]})))}updateOneAtIndex(e,t){this._selectionPoints[e]!==void 0&&this.mutateFeature.updateGuidancePoints([{featureId:this._selectionPoints[e],coordinate:t}])}};function qe(e,t){let n=!1;for(let o=0,s=t.length;o<s;o++){let s=t[o];for(let t=0,o=s.length,c=o-1;t<o;c=t++)(i=s[t])[1]>(r=e)[1]!=(a=s[c])[1]>r[1]&&r[0]<(a[0]-i[0])*(r[1]-i[1])/(a[1]-i[1])+i[0]&&(n=!n)}var r,i,a;return n}var Je=(e,t,n)=>{let r=e=>e*e,i=(e,t)=>r(e.x-t.x)+r(e.y-t.y);return Math.sqrt(((e,t,n)=>{let r=i(t,n);if(r===0)return i(e,t);let a=((e.x-t.x)*(n.x-t.x)+(e.y-t.y)*(n.y-t.y))/r;return a=Math.max(0,Math.min(1,a)),i(e,{x:t.x+a*(n.x-t.x),y:t.y+a*(n.y-t.y)})})(e,t,n))},Ye=class extends M{constructor(e,t,n){super(e),this.config=void 0,this.createClickBoundingBox=void 0,this.pixelDistance=void 0,this.config=e,this.createClickBoundingBox=t,this.pixelDistance=n}find(e,t){let n,r,i,a=1/0,o=1/0,s=this.createClickBoundingBox.create(e),c=this.store.search(s);for(let s=0;s<c.length;s++){let l=c[s],u=l.geometry;if(u.type===`Point`){if(l.properties.selectionPoint||l.properties.coordinatePoint||!t&&l.properties[f.MID_POINT])continue;let r=this.pixelDistance.measure(e,u.coordinates);!l.properties[f.MID_POINT]&&r<this.pointerDistance&&r<a&&(a=r,n=l)}else if(u.type===`LineString`){if(n)continue;for(let t=0;t<u.coordinates.length-1;t++){let n=u.coordinates[t],i=u.coordinates[t+1],a=Je({x:e.containerX,y:e.containerY},this.project(n[0],n[1]),this.project(i[0],i[1]));a<this.pointerDistance&&a<o&&(o=a,r=l)}}else if(u.type===`Polygon`){if(n||r)continue;qe([e.lng,e.lat],u.coordinates)&&(i=l)}}return{clickedFeature:n||r||i}}},Xe=class extends M{constructor(e,t,n,r,i,a,o){super(e),this.config=void 0,this.featuresAtCursorEvent=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.draggedFeatureId=null,this.dragPosition=void 0,this.config=e,this.featuresAtCursorEvent=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.readFeature=a,this.mutateFeature=o}startDragging(e,t){this.draggedFeatureId=t,this.dragPosition=[e.lng,e.lat]}stopDragging(){this.draggedFeatureId=null,this.dragPosition=void 0}isDragging(){return this.draggedFeatureId!==null}canDrag(e,t){let{clickedFeature:n}=this.featuresAtCursorEvent.find(e,!0);return!(!n||n.id!==t)}drag(e){if(!this.draggedFeatureId)return;let t=this.readFeature.getGeometry(this.draggedFeatureId),n=[e.lng,e.lat];if(t.type===`Polygon`||t.type===`LineString`){let r,i;if(t.type===`Polygon`?(r=t.coordinates[0],i=r.length-1):(r=t.coordinates,i=r.length),!this.dragPosition)return!1;for(let e=0;e<i;e++){let t=r[e],i,a;if(this.config.projection===`web-mercator`){let e=k(this.dragPosition[0],this.dragPosition[1]),r=k(n[0],n[1]),o=k(t[0],t[1]),s={x:e.x-r.x,y:e.y-r.y},{lng:c,lat:l}=A(o.x-s.x,o.y-s.y);i=c,a=l}else{let e=[this.dragPosition[0]-n[0],this.dragPosition[1]-n[1]];i=t[0]-e[0],a=t[1]-e[1]}if(i=D(i,this.config.coordinatePrecision),a=D(a,this.config.coordinatePrecision),i>180||i<-180||a>90||a<-90)return!1;r[e]=[i,a]}t.type===`Polygon`&&(r[r.length-1]=[r[0][0],r[0][1]]);let a=this.draggedFeatureId,o=null;if(t.type===`Polygon`)o=this.mutateFeature.updatePolygon({featureId:a,coordinateMutations:{type:P,coordinates:[r]},context:{updateType:u.Provisional}});else{if(t.type!==`LineString`)return;o=this.mutateFeature.updateLineString({featureId:a,coordinateMutations:{type:P,coordinates:r},context:{updateType:u.Provisional}})}if(!o)return!1;let s=o.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:s}),this.selectionPoints.updateAllInPlace({featureCoordinates:s}),this.coordinatePoints.updateAllInPlace({featureId:a,featureCoordinates:s}),this.dragPosition=[e.lng,e.lat]}else t.type===`Point`&&(this.mutateFeature.updatePoint({featureId:this.draggedFeatureId,coordinateMutations:{type:P,coordinates:n},context:{updateType:u.Provisional}}),this.dragPosition=[e.lng,e.lat])}},Ze=class extends M{constructor(e,t,n,r,i,a,o,s,c){super(e),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.coordinateSnapping=void 0,this.lineSnapping=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.draggedCoordinate={id:null,index:-1},this.config=e,this.pixelDistance=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.coordinateSnapping=a,this.lineSnapping=o,this.readFeature=s,this.mutateFeature=c}getClosestCoordinate(e,t){let n={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1},r;if(t.type===`LineString`)r=t.coordinates;else{if(t.type!==`Polygon`)return n;r=t.coordinates[0]}for(let i=0;i<r.length;i++){let a=this.pixelDistance.measure(e,r[i]);if(a<this.pointerDistance&&a<n.dist){let e=t.type===`Polygon`&&(i===r.length-1||i===0);n.dist=a,n.index=e?0:i,n.isFirstOrLastPolygonCoord=e}}return n}getDraggable(e,t){let n=this.readFeature.getGeometry(t);return this.getClosestCoordinate(e,n)}getDraggableIndex(e,t){let n=this.readFeature.getGeometry(t),r=this.getClosestCoordinate(e,n);return r.index===-1?-1:r.index}snapCoordinate(e,t,n){let r=[e.lng,e.lat],i=e=>!!(e.properties&&e.properties.mode===n.properties.mode&&e.id!==this.draggedCoordinate.id);if(t!=null&&t.toLine){let t;t=this.lineSnapping.getSnappable(e,i).coordinate,t&&(r=t)}if(t.toCoordinate){let t;t=this.coordinateSnapping.getSnappable(e,i).coordinate,t&&(r=t)}if(t!=null&&t.toCustom){let i;i=t.toCustom(e,{currentCoordinate:this.draggedCoordinate.index,currentId:n.id,getCurrentGeometrySnapshot:n.id?()=>this.readFeature.getGeometry(n.id):()=>null,project:this.project,unproject:this.unproject}),i&&(r=i)}return r}drag(e,t,n){let r=this.draggedCoordinate.id;if(r===null)return!1;let i=this.draggedCoordinate.index,a=this.readFeature.getGeometry(r),o=this.readFeature.getProperties(r),s=a.type===`LineString`?a.coordinates:a.coordinates[0],c=a.type===`Polygon`&&(i===s.length-1||i===0),l=this.snapCoordinate(e,n,{type:`Feature`,id:r,geometry:a,properties:o});if(e.lng>180||e.lng<-180||e.lat>90||e.lat<-90)return!1;if(c){let e=s.length-1;s[0]=l,s[e]=l}else s[i]=l;if(a.type!==`Point`&&!t&&re({type:`Feature`,geometry:a,properties:{}}))return!1;let d=r,f=null;return a.type===`Polygon`?f=this.mutateFeature.updatePolygon({featureId:d,coordinateMutations:{type:P,coordinates:[s]},context:{updateType:u.Provisional}}):a.type===`LineString`&&(f=this.mutateFeature.updateLineString({featureId:d,coordinateMutations:{type:P,coordinates:s},context:{updateType:u.Provisional}})),!!f&&(this.midPoints.updateOneAtIndex(i>0?i-1:-1,s),this.midPoints.updateOneAtIndex(i,s),this.selectionPoints.updateOneAtIndex(i,l),this.coordinatePoints.updateOneAtIndex(d,i,l),!0)}isDragging(){return this.draggedCoordinate.id!==null}startDragging(e,t){this.draggedCoordinate={id:e,index:t}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}};function Qe(e){let t=0,n=0,r=0;return(e.geometry.type===`Polygon`?e.geometry.coordinates[0].slice(0,-1):e.geometry.coordinates).forEach(e=>{t+=e[0],n+=e[1],r++},!0),[t/r,n/r]}var $e=(e,t)=>{if(t===0||t===360||t===-360)return e;let n=.017453292519943295*t,r=(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).map(([e,t])=>k(e,t)),i=r.reduce((e,t)=>({x:e.x+t.x,y:e.y+t.y}),{x:0,y:0});i.x/=r.length,i.y/=r.length;let a=r.map(e=>({x:i.x+(e.x-i.x)*Math.cos(n)-(e.y-i.y)*Math.sin(n),y:i.y+(e.x-i.x)*Math.sin(n)+(e.y-i.y)*Math.cos(n)})).map(({x:e,y:t})=>[A(e,t).lng,A(e,t).lat]);return e.geometry.type===`Polygon`?e.geometry.coordinates[0]=a:e.geometry.coordinates=a,e};function et(e){let t=(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).map(e=>{let{x:t,y:n}=k(e[0],e[1]);return[t,n]});return e.geometry.type===`Polygon`?function(e){let t=0,n=0,r=0,i=e.length;for(let a=0;a<i-1;a++){let[i,o]=e[a],[s,c]=e[a+1],l=i*c-s*o;t+=l,n+=(i+s)*l,r+=(o+c)*l}return t/=2,n/=6*t,r/=6*t,{x:n,y:r}}(t):function(e){let t=e.length,n=0,r=0;for(let i=0;i<t;i++){let[t,a]=e[i];n+=t,r+=a}return{x:n/t,y:r/t}}(t)}var tt=class extends M{constructor(e,t,n,r,i,a){super(e),this.config=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryCentroid=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.config=e,this.selectionPoints=t,this.midPoints=n,this.coordinatePoints=r,this.readFeature=i,this.mutateFeature=a}reset(){this.lastBearing=void 0,this.selectedGeometry=void 0,this.selectedGeometryWebMercatorCentroid=void 0,this.selectedGeometryCentroid=void 0}rotate(e,t){this.selectedGeometry||=this.readFeature.getGeometry(t);let n=this.selectedGeometry;if(n.type!==`Polygon`&&n.type!==`LineString`)return;let r=[e.lng,e.lat],i,a={type:`Feature`,geometry:n,properties:{}};if(this.config.projection===`web-mercator`){this.selectedGeometryWebMercatorCentroid||=et(a);let t=k(e.lng,e.lat);if(i=be(this.selectedGeometryWebMercatorCentroid,t),i===0)return;if(!this.lastBearing)return void(this.lastBearing=i);$e(a,-(this.lastBearing-i))}else{if(this.config.projection!==`globe`)throw Error(`Unsupported projection`);if(this.selectedGeometryCentroid||=Qe({type:`Feature`,geometry:n,properties:{}}),i=U(this.selectedGeometryCentroid,r),!this.lastBearing)return void(this.lastBearing=i+180);(function(e,t){if(t===0||t===360||t===-360)return e;let n=Qe(e);(e.geometry.type===`Polygon`?e.geometry.coordinates[0]:e.geometry.coordinates).forEach(e=>{let r=U(n,e)+t,i=He(n,function(e,t){e[0]+=e[0]-t[0]>180?-360:t[0]-e[0]>180?360:0;let n=C,r=t[1]*Math.PI/180,i=e[1]*Math.PI/180,a=i-r,o=Math.abs(e[0]-t[0])*Math.PI/180;o>Math.PI&&(o-=2*Math.PI);let s=Math.log(Math.tan(i/2+Math.PI/4)/Math.tan(r/2+Math.PI/4)),c=Math.abs(s)>1e-11?a/s:Math.cos(r);return Math.sqrt(a*a+c*c*o*o)*n}(n,e),r);e[0]=i[0],e[1]=i[1]})})(a,-(this.lastBearing-(i+180)))}let o=n.type===`Polygon`?n.coordinates[0]:n.coordinates;o.forEach(e=>{e[0]=D(e[0],this.coordinatePrecision),e[1]=D(e[1],this.coordinatePrecision)});let s={featureId:t,coordinateMutations:{type:P,coordinates:n.type===`Polygon`?[o]:o},context:{updateType:u.Provisional}},c=null;if(a.geometry.type===`Polygon`)c=this.mutateFeature.updatePolygon(s);else{if(a.geometry.type!==`LineString`)return;c=this.mutateFeature.updateLineString(s)}if(!c)return!1;let l=c.geometry.coordinates;this.midPoints.updateAllInPlace({featureCoordinates:l}),this.selectionPoints.updateAllInPlace({featureCoordinates:l}),this.coordinatePoints.updateAllInPlace({featureId:t,featureCoordinates:l}),this.projection===`web-mercator`?this.lastBearing=i:this.projection===`globe`&&(this.lastBearing=i+180)}},nt=class extends M{constructor(e,t){super(e),this.config=void 0,this.dragCoordinateResizeBehavior=void 0,this.config=e,this.dragCoordinateResizeBehavior=t}scale(e,t){if(!this.dragCoordinateResizeBehavior.isDragging()){let n=this.dragCoordinateResizeBehavior.getDraggableIndex(e,t);this.dragCoordinateResizeBehavior.startDragging(t,n)}this.dragCoordinateResizeBehavior.drag(e,`center-fixed`)}reset(){this.dragCoordinateResizeBehavior.stopDragging()}};function rt({coordinates:e,originX:t,originY:n,xScale:r,yScale:i}){r===1&&i===1||e.forEach(e=>{let{x:a,y:o}=k(e[0],e[1]),{lng:s,lat:c}=A(t+(a-t)*r,n+(o-n)*i);e[0]=s,e[1]=c})}var it=class extends M{constructor(e,t,n,r,i,a,o){super(e),this.config=void 0,this.pixelDistance=void 0,this.selectionPoints=void 0,this.midPoints=void 0,this.coordinatePoints=void 0,this.readFeature=void 0,this.mutateFeature=void 0,this.minimumScale=1e-4,this.draggedCoordinate={id:null,index:-1},this.boundingBoxMaps={opposite:{0:4,1:5,2:6,3:7,4:0,5:1,6:2,7:3}},this.config=e,this.pixelDistance=t,this.selectionPoints=n,this.midPoints=r,this.coordinatePoints=i,this.readFeature=a,this.mutateFeature=o}getClosestCoordinate(e,t){let n={dist:1/0,index:-1,isFirstOrLastPolygonCoord:!1},r;if(t.type===`LineString`)r=t.coordinates;else{if(t.type!==`Polygon`)return n;r=t.coordinates[0]}for(let i=0;i<r.length;i++){let a=this.pixelDistance.measure(e,r[i]);if(a<this.pointerDistance&&a<n.dist){let e=t.type===`Polygon`&&(i===r.length-1||i===0);n.dist=a,n.index=e?0:i,n.isFirstOrLastPolygonCoord=e}}return n}isValidDragWebMercator(e,t,n){switch(e){case 0:if(t<=0||n>=0)return!1;break;case 1:if(n>=0)return!1;break;case 2:if(t>=0||n>=0)return!1;break;case 3:if(t>=0)return!1;break;case 4:if(t>=0||n<=0)return!1;break;case 5:if(n<=0)return!1;break;case 6:if(t<=0||n<=0)return!1;break;case 7:if(t<=0)return!1}return!0}getSelectedFeatureDataWebMercator(){if(!this.draggedCoordinate.id||this.draggedCoordinate.index===-1)return null;let e=this.getFeature(this.draggedCoordinate.id);if(!e)return null;let t=this.getNormalisedCoordinates(e.geometry);return{boundingBox:this.getBBoxWebMercator(t),feature:e,updatedCoords:t,selectedCoordinate:t[this.draggedCoordinate.index]}}centerWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{feature:n,boundingBox:r,updatedCoords:i,selectedCoordinate:a}=t,o=et(n);if(!o)return null;let s=k(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=k(e.lng,e.lat);return this.scaleWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),i}centerFixedWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{feature:n,boundingBox:r,updatedCoords:i,selectedCoordinate:a}=t,o=et(n);if(!o)return null;let s=k(a[0],a[1]),{closestBBoxIndex:c}=this.getIndexesWebMercator(r,s),l=k(e.lng,e.lat);return this.scaleFixedWebMercator({closestBBoxIndex:c,updatedCoords:i,webMercatorCursor:l,webMercatorSelected:s,webMercatorOrigin:o}),i}scaleFixedWebMercator({closestBBoxIndex:e,webMercatorOrigin:t,webMercatorSelected:n,webMercatorCursor:r,updatedCoords:i}){if(!this.isValidDragWebMercator(e,t.x-r.x,t.y-r.y))return null;let a=F(t,r)/F(t,n);return a<0&&(a=this.minimumScale),rt({coordinates:i,originX:t.x,originY:t.y,xScale:a,yScale:a}),i}oppositeFixedWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{boundingBox:n,updatedCoords:r,selectedCoordinate:i}=t,a=k(i[0],i[1]),{oppositeBboxIndex:o,closestBBoxIndex:s}=this.getIndexesWebMercator(n,a),c={x:n[o][0],y:n[o][1]},l=k(e.lng,e.lat);return this.scaleFixedWebMercator({closestBBoxIndex:s,updatedCoords:r,webMercatorCursor:l,webMercatorSelected:a,webMercatorOrigin:c}),r}oppositeWebMercatorDrag(e){let t=this.getSelectedFeatureDataWebMercator();if(!t)return null;let{boundingBox:n,updatedCoords:r,selectedCoordinate:i}=t,a=k(i[0],i[1]),{oppositeBboxIndex:o,closestBBoxIndex:s}=this.getIndexesWebMercator(n,a),c={x:n[o][0],y:n[o][1]},l=k(e.lng,e.lat);return this.scaleWebMercator({closestBBoxIndex:s,updatedCoords:r,webMercatorCursor:l,webMercatorSelected:a,webMercatorOrigin:c}),r}scaleWebMercator({closestBBoxIndex:e,webMercatorOrigin:t,webMercatorSelected:n,webMercatorCursor:r,updatedCoords:i}){let a=t.x-r.x,o=t.y-r.y;if(!this.isValidDragWebMercator(e,a,o))return null;let s=1;a!==0&&e!==1&&e!==5&&(s=1-(t.x-n.x-a)/a);let c=1;return o!==0&&e!==3&&e!==7&&(c=1-(t.y-n.y-o)/o),this.validateScale(s,c)?(s<0&&(s=this.minimumScale),c<0&&(c=this.minimumScale),this.performWebMercatorScale(i,t.x,t.y,s,c),i):null}getFeature(e){if(this.draggedCoordinate.id===null)return null;let t=this.readFeature.getGeometry(e);return t.type!==`Polygon`&&t.type!==`LineString`?null:{id:e,type:`Feature`,geometry:t,properties:{}}}getNormalisedCoordinates(e){return e.type===`Polygon`?e.coordinates[0]:e.coordinates}validateScale(e,t){return!isNaN(e)&&t<2**53-1&&!isNaN(t)&&t<2**53-1}performWebMercatorScale(e,t,n,r,i){e.forEach(e=>{let{x:a,y:o}=k(e[0],e[1]),{lng:s,lat:c}=A(t+(a-t)*r,n+(o-n)*i);e[0]=s,e[1]=c})}getBBoxWebMercator(e){let t=[1/0,1/0,-1/0,-1/0];(e=e.map(e=>{let{x:t,y:n}=k(e[0],e[1]);return[t,n]})).forEach(([e,n])=>{e<t[0]&&(t[0]=e),n<t[1]&&(t[1]=n),e>t[2]&&(t[2]=e),n>t[3]&&(t[3]=n)});let[n,r,i,a]=t;return[[n,a],[(n+i)/2,a],[i,a],[i,a+(r-a)/2],[i,r],[(n+i)/2,r],[n,r],[n,a+(r-a)/2]]}getIndexesWebMercator(e,t){let n,r=1/0;for(let i=0;i<e.length;i++){let a=F({x:t.x,y:t.y},{x:e[i][0],y:e[i][1]});a<r&&(n=i,r=a)}if(n===void 0)throw Error(`No closest coordinate found`);return{oppositeBboxIndex:this.boundingBoxMaps.opposite[n],closestBBoxIndex:n}}isDragging(){return this.draggedCoordinate.id!==null}startDragging(e,t){this.draggedCoordinate={id:e,index:t}}stopDragging(){this.draggedCoordinate={id:null,index:-1}}getDraggableIndex(e,t){let n=this.readFeature.getGeometry(t),r=this.getClosestCoordinate(e,n);return r.index===-1?-1:r.index}drag(e,t){if(!this.draggedCoordinate.id)return!1;let n=this.getFeature(this.draggedCoordinate.id);if(!n)return!1;let r=null;if(t===`center`?r=this.centerWebMercatorDrag(e):t===`opposite`?r=this.oppositeWebMercatorDrag(e):t===`center-fixed`?r=this.centerFixedWebMercatorDrag(e):t===`opposite-fixed`&&(r=this.oppositeFixedWebMercatorDrag(e)),!r)return!1;for(let e=0;e<r.length;e++){let t=r[e];if(t[0]=D(t[0],this.coordinatePrecision),t[1]=D(t[1],this.coordinatePrecision),!ie(t,this.coordinatePrecision))return!1}let i=n.id,a=null;if(n.geometry.type===`Polygon`?a=this.mutateFeature.updatePolygon({featureId:i,coordinateMutations:{type:P,coordinates:[r]},context:{updateType:u.Provisional}}):n.geometry.type===`LineString`&&(a=this.mutateFeature.updateLineString({featureId:i,coordinateMutations:{type:P,coordinates:r},context:{updateType:u.Provisional}})),!a)return!1;let o=a.geometry.coordinates;return this.midPoints.updateAllInPlace({featureCoordinates:o}),this.selectionPoints.updateAllInPlace({featureCoordinates:o}),this.coordinatePoints.updateAllInPlace({featureId:i,featureCoordinates:o}),!0}},at={deselect:`Escape`,delete:`Delete`,rotate:[`Control`,`r`],scale:[`Control`,`s`]},ot={pointerOver:`move`,dragStart:`move`,dragEnd:`move`,insertMidpoint:`crosshair`},st=class extends x{getPointerOverFeatureCursor(){return this.cursors.pointerOverFeature??this.cursors.pointerOver}getPointerOverCoordinateCursor(){return this.cursors.pointerOverCoordinate??this.cursors.pointerOver}getPointerOverResizeHandleCursor(){return this.cursors.pointerOverResizeHandle??this.cursors.pointerOver}constructor(e){super(e,!0),this.mode=`select`,this.allowManualDeselection=!0,this.allowManualSelection=!0,this.dragEventThrottle=5,this.dragEventCount=0,this.selected=[],this.flags={},this.keyEvents=at,this.cursors=ot,this.validations={},this.dragTarget={type:`none`},this.selectionPoints=void 0,this.midPoints=void 0,this.coordinateSnap=void 0,this.featuresAtMouseEvent=void 0,this.pixelDistance=void 0,this.clickBoundingBox=void 0,this.dragFeature=void 0,this.dragCoordinate=void 0,this.rotateFeature=void 0,this.scaleFeature=void 0,this.dragCoordinateResizeFeature=void 0,this.coordinatePoints=void 0,this.lineSnap=void 0,this.mutateFeature=void 0,this.readFeature=void 0,this.updateOptions(e)}updateOptions(e){if(super.updateOptions(e),this.cursors=e&&e.cursors?a({},this.cursors,e.cursors):ot,e?.keyEvents===null?this.keyEvents={deselect:null,delete:null,rotate:null,scale:null}:e!=null&&e.keyEvents&&(this.keyEvents=a({},this.keyEvents,e.keyEvents)),e?.dragEventThrottle!==void 0&&(this.dragEventThrottle=e.dragEventThrottle),e?.allowManualDeselection!==void 0&&(this.allowManualDeselection=e.allowManualDeselection),e?.allowManualSelection!==void 0&&(this.allowManualSelection=e.allowManualSelection),e!=null&&e.flags){this.flags=a({},this.flags,e.flags),this.validations={};for(let e in this.flags){let t=this.flags[e].feature;t&&t.validation&&(this.validations[e]=t.validation)}}}selectFeature(e){this.select(e,!1)}setSelecting(){if(this._state!==`started`)throw Error(`Mode must be started to move to selecting state`);this._state=`selecting`}registerBehaviors(e){this.readFeature=new pe(e),this.mutateFeature=new de(e,{validate:(e,t)=>{let n=e.properties.mode;return this.validations&&this.validations[n]?this.validations[n](e,t):{valid:!0}}}),this.pixelDistance=new ge(e),this.clickBoundingBox=new he(e),this.featuresAtMouseEvent=new Ye(e,this.clickBoundingBox,this.pixelDistance),this.selectionPoints=new Ke(e,this.mutateFeature),this.coordinatePoints=new Ae(e,this.readFeature,this.mutateFeature),this.midPoints=new Ge(e,this.selectionPoints,this.coordinatePoints,this.mutateFeature,this.readFeature,this.pixelDistance),this.coordinateSnap=new _e(e,this.pixelDistance,this.clickBoundingBox),this.lineSnap=new Oe(e,this.pixelDistance,this.clickBoundingBox),this.rotateFeature=new tt(e,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragFeature=new Xe(e,this.featuresAtMouseEvent,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.dragCoordinate=new Ze(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.coordinateSnap,this.lineSnap,this.readFeature,this.mutateFeature),this.dragCoordinateResizeFeature=new it(e,this.pixelDistance,this.selectionPoints,this.midPoints,this.coordinatePoints,this.readFeature,this.mutateFeature),this.scaleFeature=new nt(e,this.dragCoordinateResizeFeature)}deselectFeature(e){this.deselect(e)}deselect(e){this.selected.includes(e)&&(this.mutateFeature.setDeselected(this.selected),this.onDeselect(this.selected[0]),this.selected=[],this.selectionPoints.delete(),this.midPoints.delete(),this.dragTarget={type:`none`})}deleteSelected(){this.selected.length&&this.mutateFeature.deleteFeaturesIfPresent(this.selected),this.selected=[],this.dragTarget={type:`none`}}clearDragTargetAndCursor(){this.dragTarget={type:`none`},this.setCursor(`unset`)}getSelectedFlags(e){let t=this.readFeature.getProperties(e),n=this.flags[t.mode]?.feature,r=n?.coordinates;return{featureFlags:n,coordinatesFlags:r,hasDraggableFlags:n&&(n.draggable||r?.draggable||r?.resizable||typeof r?.midpoints==`object`&&r.midpoints.draggable)}}onRightClick(e){if(!this.selectionPoints.ids.length)return;let t,n=1/0;if(this.selectionPoints.ids.forEach(r=>{let i=this.readFeature.getGeometry(r),a=this.pixelDistance.measure(e,i.coordinates);a<this.pointerDistance&&a<n&&(n=a,t=this.readFeature.getProperties(r))}),!t)return;let r=t.selectionPointFeatureId,i=t.index,a=this.readFeature.getProperties(r),o=this.flags[a.mode];if(!(o&&o.feature&&o.feature.coordinates&&o.feature.coordinates.deletable))return;let s=this.readFeature.getGeometry(r),l;if(s.type===`Polygon`){if(l=s.coordinates[0],l.length<=4)return}else if(s.type!==`LineString`||(l=s.coordinates,l.length<=2))return;s.type!==`Polygon`||i!==0&&i!==l.length-1?l.splice(i,1):(l.shift(),l.pop(),l.push([l[0][0],l[0][1]]));let d=null;if(s.type===`Polygon`?d=this.mutateFeature.updatePolygon({featureId:r,coordinateMutations:{type:P,coordinates:[l]},context:{updateType:u.Commit}}):s.type===`LineString`&&(d=this.mutateFeature.updateLineString({featureId:r,coordinateMutations:{type:P,coordinates:l},context:{updateType:u.Commit}})),!d)return;let f=d.geometry.coordinates;this.mutateFeature.deleteFeaturesIfPresent([...this.midPoints.ids,...this.selectionPoints.ids]),a.coordinatePointIds&&this.coordinatePoints.createOrUpdate({featureId:r,featureCoordinates:f}),this.selectionPoints.create({featureCoordinates:f,featureId:r}),o&&o.feature&&o.feature.coordinates&&o.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:f,featureId:r}),this.onFinish(r,{action:c,mode:this.mode})}select(e,t=!0){if(this.selected[0]===e)return;let{mode:n}=this.readFeature.getProperties(e),r=this.flags[n];if(!r||!r.feature)return;let i=this.selected[0];if(i){if(i===e)return;this.deselect(i)}t&&this.setCursor(this.getPointerOverFeatureCursor()),this.selected=[e],this.mutateFeature.setSelected(e),this.onSelect(e);let{type:a,coordinates:o}=this.readFeature.getGeometry(e);a!==`LineString`&&a!==`Polygon`||o&&r&&r.feature.coordinates&&(this.selectionPoints.create({featureCoordinates:o,featureId:e}),r.feature.coordinates.midpoints&&this.midPoints.create({featureCoordinates:o,featureId:e}))}onLeftClick(e){let{clickedFeature:t}=this.featuresAtMouseEvent.find(e,this.selected.length>0),n=this.midPoints.getNearestMidPoint(e),r=this.selected[0];if(r){var i;let{featureFlags:t}=this.getSelectedFlags(r);if(t!=null&&(i=t.coordinates)!=null&&i.midpoints&&n){if(t.coordinates.draggable){let t=this.pixelDistance.measure(e,this.readFeature.getGeometry(n).coordinates),{dist:i}=this.dragCoordinate.getDraggable(e,r);if(i!==void 0&&t>i)return}this.midPoints.insert({featureId:r,midPointId:n}),this.onFinish(this.selected[0],{action:l,mode:this.mode});return}}if(t!=null&&t.id)this.allowManualSelection&&this.select(t.id,!0);else if(this.selected.length&&this.allowManualDeselection)return void this.deselect(this.selected[0])}start(){this.setStarted(),this.setSelecting()}stop(){this.cleanUp(),this.setStarted(),this.setStopped()}onClick(e){e.button===`right`&&this.allowPointerEvent(this.pointerEvents.rightClick,e)||e.isContextMenu&&this.allowPointerEvent(this.pointerEvents.contextMenu,e)?this.onRightClick(e):e.button===`left`&&this.allowPointerEvent(this.pointerEvents.leftClick,e)&&this.onLeftClick(e)}canScale(e){return this.keyEvents.scale&&this.keyEvents.scale.every(t=>e.heldKeys.includes(t))}canRotate(e){return this.keyEvents.rotate&&this.keyEvents.rotate.every(t=>e.heldKeys.includes(t))}preventDefaultKeyEvent(e){let t=this.canRotate(e),n=this.canScale(e);(t||n)&&e.preventDefault()}onKeyDown(e){this.preventDefaultKeyEvent(e)}onKeyUp(e){if(this.preventDefaultKeyEvent(e),this.keyEvents.delete&&e.key===this.keyEvents.delete){if(!this.selected.length)return;let 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&&e.key===this.keyEvents.deselect&&this.cleanUp()}cleanUp(){this.selected.length&&this.deselect(this.selected[0])}onDragStart(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDragStart,e))return;let n=this.selected[0];if(!n)return;let{featureFlags:r,coordinatesFlags:i,hasDraggableFlags:a}=this.getSelectedFlags(n);if(!a)return;this.dragEventCount=0;let o=this.dragTarget.type!==`none`&&this.dragTarget.featureId===n?this.dragTarget:{type:`none`},s=o.type===`coordinate`?o.coordinateIndex:this.dragCoordinate.getDraggableIndex(e,n),c=o.type===`resize`?o.coordinateIndex:this.dragCoordinateResizeFeature.getDraggableIndex(e,n),u=i?.resizable&&c!==-1,d=i?.draggable&&s!==-1,f=i&&typeof i.midpoints==`object`&&i.midpoints.draggable,p=r?.draggable&&(o.type===`feature`||this.dragFeature.canDrag(e,n));if(u)return this.setCursor(this.cursors.dragStart),this.dragCoordinateResizeFeature.startDragging(n,c),void t(!1);if(d)return this.setCursor(this.cursors.dragStart),this.dragCoordinate.startDragging(n,s),void t(!1);if(f){let r=o.type===`midpoint`?o.midPointId:this.midPoints.getNearestMidPoint(e);if(this.selected.length&&r){this.midPoints.insert({featureId:n,midPointId:r}),this.onFinish(this.selected[0],{action:l,mode:this.mode});let i=this.dragCoordinate.getDraggableIndex(e,n);this.dragCoordinate.startDragging(n,i),t(!1);return}}if(p)return this.setCursor(this.cursors.dragStart),this.dragFeature.startDragging(e,n),void t(!1);this.setCursor(`unset`)}onDrag(e,t){if(!this.allowPointerEvent(this.pointerEvents.onDrag,e))return;let n=this.selected[0];if(!n)return;let r=this.readFeature.getProperties(n),i=this.flags[r.mode],a=!0===(i&&i.feature&&i.feature.selfIntersectable);if(this.dragEventCount++,this.dragEventCount%this.dragEventThrottle!=0){if(i&&i.feature&&i.feature.rotateable&&this.canRotate(e))return t(!1),void this.rotateFeature.rotate(e,n);if(i&&i.feature&&i.feature.scaleable&&this.canScale(e))return t(!1),void this.scaleFeature.scale(e,n);if(this.dragCoordinateResizeFeature.isDragging()&&i.feature&&i.feature.coordinates&&i.feature.coordinates.resizable){if(this.projection===`globe`)throw Error(`Globe is currently unsupported projection for resizable`);t(!1),this.dragCoordinateResizeFeature.drag(e,i.feature.coordinates.resizable);return}if(this.dragCoordinate.isDragging()){var o;let t=(o=i.feature)==null||(o=o.coordinates)==null?void 0:o.snappable,n={toCoordinate:!1};!0===t?n={toCoordinate:!0}:typeof t==`object`&&(n=t),this.dragCoordinate.drag(e,a,n);return}this.dragFeature.isDragging()?this.dragFeature.drag(e):t(!0)}}onDragEnd(e,t){this.allowPointerEvent(this.pointerEvents.onDragEnd,e)&&(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(),t(!0))}onMouseMove(e){let t=this.selected[0];if(!t)return void this.clearDragTargetAndCursor();if(this.dragFeature.isDragging()||this.dragCoordinate.isDragging()||this.dragCoordinateResizeFeature.isDragging())return;let{featureFlags:n}=this.getSelectedFlags(t);if(!n)return void this.clearDragTargetAndCursor();let r,i=n.coordinates;if(i!=null&&i.midpoints&&(r=this.midPoints.getNearestMidPoint(e),r&&(this.dragTarget={type:`midpoint`,featureId:t,midPointId:r},this.setCursor(this.cursors.insertMidpoint))),i&&i.draggable){let{index:n,dist:i}=this.dragCoordinate.getDraggable(e,t);if(n>-1){if(r&&this.pixelDistance.measure(e,this.readFeature.getGeometry(r).coordinates)<i)return;this.dragTarget={type:`coordinate`,featureId:t,coordinateIndex:n},this.setCursor(this.getPointerOverCoordinateCursor());return}}if(i&&i.resizable){let n=this.dragCoordinateResizeFeature.getDraggableIndex(e,t);if(n>-1)return this.dragTarget={type:`resize`,featureId:t,coordinateIndex:n},void this.setCursor(this.getPointerOverResizeHandleCursor())}if(n.draggable&&this.dragFeature.canDrag(e,t)){if(r)return;this.dragTarget={type:`feature`,featureId:t},this.setCursor(this.getPointerOverFeatureCursor());return}r||this.clearDragTargetAndCursor()}styleFeature(e){let t=a({},{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,lineStringDash:void 0});if(e.properties.mode===this.mode&&e.geometry.type===`Point`){if(e.properties[f.SELECTION_POINT])return t.pointColor=this.getHexColorStylingValue(this.styles.selectionPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.selectionPointOpacity,1,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectionPointOutlineColor,t.pointOutlineColor,e),t.pointWidth=this.getNumericStylingValue(this.styles.selectionPointWidth,t.pointWidth,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectionPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectionPointOutlineWidth,2,e),t.zIndex=30,t;if(e.properties[f.MID_POINT])return t.pointColor=this.getHexColorStylingValue(this.styles.midPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.midPointOpacity,1,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.midPointOutlineColor,t.pointOutlineColor,e),t.pointWidth=this.getNumericStylingValue(this.styles.midPointWidth,4,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.midPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.midPointOutlineWidth,2,e),t.zIndex=50,t}else if(e.properties[f.SELECTED]){if(e.geometry.type===`Point`&&e.properties[p.MARKER])return t.markerUrl=this.getUrlStylingValue(this.styles.selectedMarkerUrl,d,e),t.markerHeight=this.getNumericStylingValue(this.styles.selectedMarkerHeight,40,e),t.markerWidth=this.getNumericStylingValue(this.styles.selectedMarkerWidth,32,e),t;if(e.geometry.type===`Polygon`)return t.polygonFillColor=this.getHexColorStylingValue(this.styles.selectedPolygonColor,t.polygonFillColor,e),t.polygonOutlineWidth=this.getNumericStylingValue(this.styles.selectedPolygonOutlineWidth,t.polygonOutlineWidth,e),t.polygonOutlineColor=this.getHexColorStylingValue(this.styles.selectedPolygonOutlineColor,t.polygonOutlineColor,e),t.polygonOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPolygonOutlineOpacity,1,e),t.polygonFillOpacity=this.getNumericStylingValue(this.styles.selectedPolygonFillOpacity,t.polygonFillOpacity,e),t.zIndex=m,t;if(e.geometry.type===`LineString`)return t.lineStringColor=this.getHexColorStylingValue(this.styles.selectedLineStringColor,t.lineStringColor,e),t.lineStringWidth=this.getNumericStylingValue(this.styles.selectedLineStringWidth,t.lineStringWidth,e),t.zIndex=m,t;if(e.geometry.type===`Point`)return t.pointWidth=this.getNumericStylingValue(this.styles.selectedPointWidth,t.pointWidth,e),t.pointColor=this.getHexColorStylingValue(this.styles.selectedPointColor,t.pointColor,e),t.pointOpacity=this.getNumericStylingValue(this.styles.selectedPointOpacity,1,e),t.pointOutlineColor=this.getHexColorStylingValue(this.styles.selectedPointOutlineColor,t.pointOutlineColor,e),t.pointOutlineOpacity=this.getNumericStylingValue(this.styles.selectedPointOutlineOpacity,1,e),t.pointOutlineWidth=this.getNumericStylingValue(this.styles.selectedPointOutlineWidth,t.pointOutlineWidth,e),t.zIndex=m,t}return t}afterFeatureUpdated(e){if(this.selected.length&&e.id===this.selected[0]){var t,n;let r=this.flags[e.properties.mode];if(r==null||(t=r.feature)==null||!t.coordinates)return;let i=e.geometry.type,a=e.id;if(this.selectionPoints.delete(),this.midPoints.delete(),i!==`LineString`&&i!==`Polygon`)return;let o=e.geometry.coordinates;this.selectionPoints.create({featureCoordinates:o,featureId:a}),r!=null&&(n=r.feature)!=null&&(n=n.coordinates)!=null&&n.midpoints&&this.midPoints.create({featureCoordinates:o,featureId:a})}}},ct=class extends b{constructor(...e){super(...e),this.type=y.Static,this.mode=`static`}start(){}stop(){}onKeyUp(){}onKeyDown(){}onClick(){}onDragStart(){}onDrag(){}onDragEnd(){}onMouseMove(){}cleanUp(){}styleFeature(){return a({},{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,lineStringDash:void 0})}};function lt(e,t,n,r,i){for(;r>n;){if(r-n>600){let a=r-n+1,o=t-n+1,s=Math.log(a),c=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*c*(a-c)/a)*(o-a/2<0?-1:1);lt(e,t,Math.max(n,Math.floor(t-o*c/a+l)),Math.min(r,Math.floor(t+(a-o)*c/a+l)),i)}let a=e[t],o=n,s=r;for(G(e,n,t),i(e[r],a)>0&&G(e,n,r);o<s;){for(G(e,o,s),o++,s--;i(e[o],a)<0;)o++;for(;i(e[s],a)>0;)s--}i(e[n],a)===0?G(e,n,s):(s++,G(e,s,r)),s<=t&&(n=s+1),t<=s&&(r=s-1)}}function G(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}function K(e,t){q(e,0,e.children.length,t,e)}function q(e,t,n,r,i){i||=Z([]),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let a=t;a<n;a++){let t=e.children[a];J(i,e.leaf?r(t):t)}return i}function J(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function ut(e,t){return e.minX-t.minX}function dt(e,t){return e.minY-t.minY}function ft(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Y(e){return e.maxX-e.minX+(e.maxY-e.minY)}function pt(e,t){let n=Math.max(e.minX,t.minX),r=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),a=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,a-r)}function mt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function X(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Z(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ht(e,t,n,r,i){let a=[t,n];for(;a.length;){if((n=a.pop())-(t=a.pop())<=r)continue;let o=t+Math.ceil((n-t)/r/2)*r;lt(e,o,t,n,i),a.push(t,o,o,n)}}var gt=class{constructor(e){this._maxEntries=void 0,this._minEntries=void 0,this.data=void 0,this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}search(e){let t=this.data,n=[];if(!X(e,t))return n;let r=this.toBBox,i=[];for(;t;){for(let a=0;a<t.children.length;a++){let o=t.children[a],s=t.leaf?r(o):o;X(e,s)&&(t.leaf?n.push(o):mt(e,s)?this._all(o,n):i.push(o))}t=i.pop()}return n}collides(e){let t=this.data;if(X(e,t)){let n=[];for(;t;){for(let r=0;r<t.children.length;r++){let i=t.children[r],a=t.leaf?this.toBBox(i):i;if(X(e,a)){if(t.leaf||mt(e,a))return!0;n.push(i)}}t=n.pop()}}return!1}load(e){if(e.length<this._minEntries){for(let t=0;t<e.length;t++)this.insert(e[t]);return}let t=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===t.height)this._splitRoot(this.data,t);else{if(this.data.height<t.height){let e=this.data;this.data=t,t=e}this._insert(t,this.data.height-t.height-1,!0)}else this.data=t}insert(e){this._insert(e,this.data.height-1)}clear(){this.data=Z([])}remove(e){let t=this.data,n=this.toBBox(e),r=[],i=[],a,o,s=!1;for(;t||r.length;){if(t||(t=r.pop(),o=r[r.length-1],a=i.pop(),s=!0),t.leaf){let n=t.children.indexOf(e);n!==-1&&(t.children.splice(n,1),r.push(t),this._condense(r))}s||t.leaf||!mt(t,n)?o?(a++,t=o.children[a],s=!1):t=null:(r.push(t),i.push(a),a=0,o=t,t=t.children[0])}}toBBox(e){return e}compareMinX(e,t){return e.minX-t.minX}compareMinY(e,t){return e.minY-t.minY}_all(e,t){let n=[];for(;e;)e.leaf?t.push(...e.children):n.push(...e.children),e=n.pop();return t}_build(e,t,n,r){let i=n-t+1,a,o=this._maxEntries;if(i<=o)return a=Z(e.slice(t,n+1)),K(a,this.toBBox),a;r||(r=Math.ceil(Math.log(i)/Math.log(o)),o=Math.ceil(i/o**(r-1))),a=Z([]),a.leaf=!1,a.height=r;let s=Math.ceil(i/o),c=s*Math.ceil(Math.sqrt(o));ht(e,t,n,c,this.compareMinX);for(let i=t;i<=n;i+=c){let t=Math.min(i+c-1,n);ht(e,i,t,s,this.compareMinY);for(let n=i;n<=t;n+=s){let i=Math.min(n+s-1,t);a.children.push(this._build(e,n,i,r-1))}}return K(a,this.toBBox),a}_chooseSubtree(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let s=0;s<t.children.length;s++){let c=t.children[s],l=ft(c),u=(i=e,a=c,(Math.max(a.maxX,i.maxX)-Math.min(a.minX,i.minX))*(Math.max(a.maxY,i.maxY)-Math.min(a.minY,i.minY))-l);u<o?(o=u,r=l<r?l:r,n=c):u===o&&l<r&&(r=l,n=c)}t=n||t.children[0]}var i,a;return t}_insert(e,t,n){let r=n?e:this.toBBox(e),i=[],a=this._chooseSubtree(r,this.data,t,i);for(a.children.push(e),J(a,r);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)}_split(e,t){let n=e[t],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);let a=this._chooseSplitIndex(n,i,r),o=Z(n.children.splice(a,n.children.length-a));o.height=n.height,o.leaf=n.leaf,K(n,this.toBBox),K(o,this.toBBox),t?e[t-1].children.push(o):this._splitRoot(n,o)}_splitRoot(e,t){this.data=Z([e,t]),this.data.height=e.height+1,this.data.leaf=!1,K(this.data,this.toBBox)}_chooseSplitIndex(e,t,n){let r,i=1/0,a=1/0;for(let o=t;o<=n-t;o++){let t=q(e,0,o,this.toBBox),s=q(e,o,n,this.toBBox),c=pt(t,s),l=ft(t)+ft(s);c<i?(i=c,r=o,a=l<a?l:a):c===i&&l<a&&(a=l,r=o)}return r||n-t}_chooseSplitAxis(e,t,n){let r=e.leaf?this.compareMinX:ut,i=e.leaf?this.compareMinY:dt;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,i)&&e.children.sort(r)}_allDistMargin(e,t,n,r){e.children.sort(r);let i=this.toBBox,a=q(e,0,t,i),o=q(e,n-t,n,i),s=Y(a)+Y(o);for(let r=t;r<n-t;r++){let t=e.children[r];J(a,e.leaf?i(t):t),s+=Y(a)}for(let r=n-t-1;r>=t;r--){let t=e.children[r];J(o,e.leaf?i(t):t),s+=Y(o)}return s}_adjustParentBBoxes(e,t,n){for(let r=n;r>=0;r--)J(t[r],e)}_condense(e){for(let t,n=e.length-1;n>=0;n--)e[n].children.length===0?n>0?(t=e[n-1].children,t.splice(t.indexOf(e[n]),1)):this.clear():K(e[n],this.toBBox)}},_t=class{constructor(e){this.tree=void 0,this.idToNode=void 0,this.nodeToId=void 0,this.tree=new gt(e&&e.maxEntries?e.maxEntries:9),this.idToNode=new Map,this.nodeToId=new Map}setMaps(e,t){this.idToNode.set(e.id,t),this.nodeToId.set(t,e.id)}toBBox(e){let t=[],n=[],r;if(e.geometry.type===`Polygon`)r=e.geometry.coordinates[0];else if(e.geometry.type===`LineString`)r=e.geometry.coordinates;else{if(e.geometry.type!==`Point`)throw Error(`Not a valid feature to turn into a bounding box`);r=[e.geometry.coordinates]}for(let e=0;e<r.length;e++)n.push(r[e][1]),t.push(r[e][0]);let i=Math.min(...n),a=Math.max(...n);return{minX:Math.min(...t),minY:i,maxX:Math.max(...t),maxY:a}}insert(e){if(this.idToNode.get(String(e.id)))throw Error(`Feature already exists`);let t=this.toBBox(e);this.setMaps(e,t),this.tree.insert(t)}load(e){let t=[],n=new Set;e.forEach(e=>{let r=this.toBBox(e);if(this.setMaps(e,r),n.has(String(e.id)))throw Error(`Duplicate feature ID found ${e.id}`);n.add(String(e.id)),t.push(r)}),this.tree.load(t)}update(e){this.remove(e.id);let t=this.toBBox(e);this.setMaps(e,t),this.tree.insert(t)}remove(e){let t=this.idToNode.get(e);if(!t)throw Error(`${e} not inserted into the spatial index`);this.tree.remove(t)}clear(){this.tree.clear()}search(e){return this.tree.search(this.toBBox(e)).map(e=>this.nodeToId.get(e))}collides(e){return this.tree.collides(this.toBBox(e))}},vt={getId:()=>`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,function(e){let t=16*Math.random()|0;return(e==`x`?t:3&t|8).toString(16)}),isValidId:e=>typeof e==`string`&&e.length===36},yt={target:`geometry`},bt={target:`properties`},xt=class{constructor(e){this.idStrategy=void 0,this.tracked=void 0,this.spatialIndex=void 0,this.store=void 0,this._onChange=()=>{},this.store={},this.spatialIndex=new _t,this.tracked=!e||!1!==e.tracked,this.idStrategy=e&&e.idStrategy?e.idStrategy:vt}clone(e){return JSON.parse(JSON.stringify(e))}getId(){return this.idStrategy.getId()}has(e){return!!this.store[e]}load(e,t,n,r){if(e.length===0)return[];let i=this.clone(e),a=[],o=[];i=i.filter(e=>{e.id??=this.idStrategy.getId();let n=e.id;if(t){let r=t(e);if(!r.valid)return a.push({id:n,valid:!1,reason:r.reason}),!1}if(this.tracked){if(e.properties.createdAt){if(!_(e.properties.createdAt))return a.push({id:e.id,valid:!1,reason:`createdAt is not a valid numeric timestamp`}),!1}else e.properties.createdAt=+new Date;if(e.properties.updatedAt){if(!_(e.properties.updatedAt))return a.push({id:e.id,valid:!1,reason:`updatedAt is not a valid numeric timestamp`}),!1}else e.properties.updatedAt=+new Date}return this.has(n)?(a.push({id:n,valid:!1,reason:`Feature already exists with this id: ${n}`}),!1):(this.store[n]=e,o.push(e),a.push({id:n,valid:!0}),!0)}),this.spatialIndex.load(i);let s=o.map(({id:e})=>e);return s.length>0&&(this._onChange(s,`create`,r),n&&o.forEach(e=>{n(e)})),a}search(e,t){let n=this.spatialIndex.search(e).map(e=>this.store[e]);return this.clone(t?n.filter(t):n)}registerOnChange(e){this._onChange=(t,n,r)=>{e(t,n,r)}}getGeometryCopy(e){let t=this.store[e];if(!t)throw Error(`No feature with this id (${e}), can not get geometry copy`);return this.clone(t.geometry)}getPropertiesCopy(e){let t=this.store[e];if(!t)throw Error(`No feature with this id (${e}), can not get properties copy`);return this.clone(t.properties)}updateProperty(e,t){let n=new Set;e.forEach(({id:e,property:t,value:r})=>{let i=this.store[e];if(!i)throw Error(`No feature with this (${e}), can not update geometry`);i.properties[t]!==r&&(n.add(e),r===void 0?delete i.properties[t]:i.properties[t]=r,this.tracked&&(i.properties.updatedAt=+new Date))}),this._onChange&&n.size>0&&this._onChange(Array.from(n),`update`,t?a({},t,bt):bt)}updateGeometry(e,t){let n=new Set;e.forEach(({id:e,geometry:t})=>{n.add(e);let r=this.store[e];if(!r)throw Error(`No feature with this (${e}), can not update geometry`);r.geometry=this.clone(t),this.spatialIndex.update(r),this.tracked&&(r.properties.updatedAt=+new Date)}),this._onChange&&n.size>0&&this._onChange(Array.from(n),`update`,t?a({},t,yt):yt)}create(e,t){let n=[];return e.forEach(({geometry:e,properties:t})=>{let r,i=a({},t);this.tracked&&(r=+new Date,t?(i.createdAt=typeof t.createdAt==`number`?t.createdAt:r,i.updatedAt=typeof t.updatedAt==`number`?t.updatedAt:r):i={createdAt:r,updatedAt:r});let o=this.getId(),s={id:o,type:`Feature`,geometry:e,properties:i};this.store[o]=s,this.spatialIndex.insert(s),n.push(o)}),this._onChange&&this._onChange([...n],`create`,t),n}delete(e,t){e.forEach(e=>{if(!this.store[e])throw Error(`No feature with id ${e}, can not delete`);delete this.store[e],this.spatialIndex.remove(e)}),this._onChange&&this._onChange([...e],`delete`,t)}copy(e){return this.clone(this.store[e])}copyAll(){return this.clone(Object.keys(this.store).map(e=>this.store[e]))}copyAllWhere(e){return this.clone(Object.keys(this.store).map(e=>this.store[e]).filter(t=>t.properties&&e(t.properties)))}clear(e){let t=Object.keys(this.store);this.store={},this.spatialIndex.clear(),this._onChange(t,`delete`,e)}size(){return Object.keys(this.store).length}};Math.PI/180;var Q=class{constructor({name:e,callback:t,unregister:n,register:r}){this.name=void 0,this.callback=void 0,this.registered=!1,this.register=void 0,this.unregister=void 0,this.name=e,this.register=()=>{this.registered||(this.registered=!0,r(t))},this.unregister=()=>{this.register&&(this.registered=!1,n(t))},this.callback=t}},St={__proto__:null,GeoJSONStore:xt,TerraDrawBaseDrawMode:b,TerraDrawBaseSelectMode:x,TerraDrawBaseAdapter:class{constructor(e){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=typeof e.ignoreMismatchedPointerEvents==`boolean`&&e.ignoreMismatchedPointerEvents,this._minPixelDragDistance=typeof e.minPixelDragDistance==`number`?e.minPixelDragDistance:1,this._minPixelDragDistanceSelecting=typeof e.minPixelDragDistanceSelecting==`number`?e.minPixelDragDistanceSelecting:1,this._minPixelDragDistanceDrawing=typeof e.minPixelDragDistanceDrawing==`number`?e.minPixelDragDistanceDrawing:8,this._coordinatePrecision=typeof e.coordinatePrecision==`number`?e.coordinatePrecision:9}getButton(e){return e.button===-1?`neither`:e.button===0?`left`:e.button===1?`middle`:e.button===2?`right`:`neither`}getMapElementXYPosition(e){let{left:t,top:n}=this.getMapEventElement(e.type).getBoundingClientRect();return{containerX:e.clientX-t,containerY:e.clientY-n}}getDrawEventFromEvent(e,t=!1){let n=this.getLngLatFromEvent(e);if(!n)return null;let{lng:r,lat:i}=n,{containerX:a,containerY:o}=this.getMapElementXYPosition(e),s=this.getButton(e),c=Array.from(this._heldKeys);return{lng:D(r,this._coordinatePrecision),lat:D(i,this._coordinatePrecision),containerX:a,containerY:o,button:s,heldKeys:c,isContextMenu:t}}register(e){this._currentModeCallbacks=e,this._listeners=this.getAdapterListeners(),this._listeners.forEach(e=>{e.register()})}getCoordinatePrecision(){return this._coordinatePrecision}getAdapterListeners(){return[new Q({name:`pointerdown`,callback:e=>{if(!this._currentModeCallbacks||!e.isPrimary)return;let t=this.getDrawEventFromEvent(e);t&&(this._dragState=`pre-dragging`,this._lastDrawEvent=t,this._lastPointerDownEventTarget=e.target?e.target:void 0)},register:e=>{this.getMapEventElement(`pointerdown`).addEventListener(`pointerdown`,e)},unregister:e=>{this.getMapEventElement(`pointerdown`).removeEventListener(`pointerdown`,e)}}),new Q({name:`pointermove`,callback:e=>{if(!this._currentModeCallbacks||!e.isPrimary)return;e.preventDefault();let t=this.getDrawEventFromEvent(e);if(t)if(this._dragState===`not-dragging`)this._currentModeCallbacks.onMouseMove(t),this._lastDrawEvent=t;else if(this._dragState===`pre-dragging`){if(!this._lastDrawEvent)return;let e={x:this._lastDrawEvent.containerX,y:this._lastDrawEvent.containerY},n={x:t.containerX,y:t.containerY},r=this._currentModeCallbacks.getState(),i=F(e,n),a=!1;if(a=r===`drawing`?i<this._minPixelDragDistanceDrawing:r===`selecting`?i<this._minPixelDragDistanceSelecting:i<this._minPixelDragDistance,a)return;this._nextKeyUpIsContextMenu=!1,this._dragState=`dragging`,this._currentModeCallbacks.onDragStart(t,e=>{this.setDraggability.bind(this)(e)})}else this._dragState===`dragging`&&this._currentModeCallbacks.onDrag(t,e=>{this.setDraggability.bind(this)(e)})},register:e=>{this.getMapEventElement(`pointermove`).addEventListener(`pointermove`,e)},unregister:e=>{this.getMapEventElement(`pointermove`).removeEventListener(`pointermove`,e)}}),new Q({name:`contextmenu`,callback:e=>{this._currentModeCallbacks&&(e.preventDefault(),this._nextKeyUpIsContextMenu=!0)},register:e=>{this.getMapEventElement(`contextmenu`).addEventListener(`contextmenu`,e)},unregister:e=>{this.getMapEventElement(`contextmenu`).removeEventListener(`contextmenu`,e)}}),new Q({name:`pointerup`,callback:e=>{if(!this._currentModeCallbacks||e.target!==this.getMapEventElement(`pointerup`)||this._ignoreMismatchedPointerEvents&&this._lastPointerDownEventTarget!==e.target||(this._lastPointerDownEventTarget=void 0,!e.isPrimary))return;let t=this.getDrawEventFromEvent(e);t&&(this._dragState===`dragging`?this._currentModeCallbacks.onDragEnd(t,e=>{this.setDraggability.bind(this)(e)}):this._dragState!==`not-dragging`&&this._dragState!==`pre-dragging`||(this._nextKeyUpIsContextMenu&&=(t.isContextMenu=!0,!1),this._currentModeCallbacks.onClick(t)),this._dragState=`not-dragging`,this.setDraggability(!0))},register:e=>{this.getMapEventElement(`pointerup`).addEventListener(`pointerup`,e)},unregister:e=>{this.getMapEventElement(`pointerup`).removeEventListener(`pointerup`,e)}}),new Q({name:`keyup`,callback:e=>{this._currentModeCallbacks&&(this._heldKeys.delete(e.key),this._currentModeCallbacks.onKeyUp({key:e.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>e.preventDefault()}))},register:e=>{this.getMapEventElement(`keyup`).addEventListener(`keyup`,e)},unregister:e=>{this.getMapEventElement(`keyup`).removeEventListener(`keyup`,e)}}),new Q({name:`keydown`,callback:e=>{this._currentModeCallbacks&&(this._heldKeys.add(e.key),this._currentModeCallbacks.onKeyDown({key:e.key,heldKeys:Array.from(this._heldKeys),preventDefault:()=>e.preventDefault()}))},register:e=>{this.getMapEventElement(`keydown`).addEventListener(`keydown`,e)},unregister:e=>{this.getMapEventElement(`keydown`).removeEventListener(`keydown`,e)}})]}unregister(){this._listeners.forEach(e=>{e.unregister()}),this.clear(),this._currentModeCallbacks=void 0,this._lastDrawEvent=void 0,this._lastPointerDownEventTarget=void 0,this._nextKeyUpIsContextMenu=!1}},getDefaultStyling:()=>({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,lineStringDash:void 0}),SELECT_PROPERTIES:f};function Ct(e){if(e===null||typeof e==`boolean`||typeof e==`string`)return!0;if(e===void 0)return!1;if(typeof e==`number`)return Number.isFinite(e);if(typeof e==`bigint`||typeof e==`symbol`||typeof e==`function`||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Date)return!1;if(typeof e==`object`&&e&&!Array.isArray(e)){let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)return!1}if(ArrayBuffer.isView(e)&&!(e instanceof DataView))return!1;if(Array.isArray(e)){for(let t of e)if(!Ct(t))return!1}return typeof e==`object`&&Object.keys(e).every(t=>typeof t==`string`&&Ct(e[t]))}var wt=`push`,$=`mode`,Tt=`session`,Et=class{constructor(e){this.modeLevel=void 0,this.sessionLevel=void 0,this.shouldPreferMode=void 0,this.onHistoryChange=void 0,this.shouldEmitHistoryChange=void 0,this.modeLevel=e.modeLevel,this.sessionLevel=e.sessionLevel,this.shouldPreferMode=e.shouldPreferMode,this.onHistoryChange=e.onHistoryChange,this.shouldEmitHistoryChange=e.shouldEmitHistoryChange??(()=>!0)}emitStackHistoryChange(e){this.shouldEmitHistoryChange()&&this.onHistoryChange&&this.onHistoryChange({cause:e.cause,stack:e.stack,undoSize:e.undoStackSize,redoSize:e.redoStackSize})}hasSessionUndo(){return!!(this.sessionLevel&&this.sessionLevel.canUndo())}hasSessionRedo(){return!!(this.sessionLevel&&this.sessionLevel.canRedo())}activeStackForUndo(){var e,t;return this.shouldPreferMode()&&(e=this.modeLevel)!=null&&e.canUndo()?$:this.hasSessionUndo()?Tt:(t=this.modeLevel)!=null&&t.canUndo()?$:void 0}activeStackForRedo(){var e,t;return this.shouldPreferMode()&&(e=this.modeLevel)!=null&&e.canRedo()?$:this.hasSessionRedo()?Tt:(t=this.modeLevel)!=null&&t.canRedo()?$:void 0}canUndo(){return this.activeStackForUndo()!==void 0}canRedo(){return this.activeStackForRedo()!==void 0}undo(){let e=this.activeStackForUndo();return!!e&&(e===$?!!this.modeLevel&&this.modeLevel.undo():!(!this.sessionLevel||!this.sessionLevel.canUndo())&&this.sessionLevel.undo())}redo(){let e=this.activeStackForRedo();return!!e&&(e===$?!!this.modeLevel&&this.modeLevel.redo():!(!this.sessionLevel||!this.sessionLevel.canRedo())&&this.sessionLevel.redo())}clearHistory(){this.modeLevel&&this.modeLevel.clearHistory(),this.sessionLevel&&this.sessionLevel.clearHistory()}emitHistoryPushForCompletedAction(){this.sessionLevel?this.emitStackHistoryChange({cause:wt,undoStackSize:this.sessionLevel.undoSize(),redoStackSize:this.sessionLevel.redoSize(),stack:Tt}):this.modeLevel&&this.emitStackHistoryChange({cause:wt,undoStackSize:this.modeLevel.undoSize(),redoStackSize:this.modeLevel.redoSize(),stack:$})}},Dt=class{constructor(e){var t,n,r,i;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=e.adapter,this._instanceSelectModes=[];let o=e==null||(t=e.undoRedo)==null?void 0:t.modeLevel;o&&(this.drawingUndoRedo=o);let s=e==null||(n=e.undoRedo)==null?void 0:n.keyboardShortcuts;s&&(this.keyboardShortcutsMatcher=s),this.sessionUndoRedoEnabled=!!(!(e==null||(r=e.undoRedo)==null)&&r.sessionLevel);let c=e==null||(i=e.undoRedo)==null?void 0:i.sessionLevel;this._mode=new ct;let l=new Set,u=e.modes.reduce((e,t)=>{if(l.has(t.mode))throw Error(`There is already a ${t.mode} mode provided`);return l.add(t.mode),e[t.mode]=t,e},{}),d=Object.keys(u);if(d.length===0)throw Error(`No modes provided`);d.forEach(e=>{u[e].type===y.Select&&this._instanceSelectModes.push(e)}),this._modes=a({},u,{static:this._mode}),this._eventListeners={change:[],select:[],deselect:[],finish:[],ready:[],history:[]},this._store=new xt({tracked:!!e.tracked,idStrategy:e.idStrategy?e.idStrategy:void 0});let f=e=>{let t=[];return{changed:t,unchanged:this._store.copyAll().filter(n=>!e.includes(n.id)||(t.push(n),!1))}},p=(e,t)=>{var n;this._enabled&&(this._eventListeners.finish.forEach(n=>{n(e,t)}),(n=this.undoRedoCoordinator)==null||n.emitHistoryPushForCompletedAction())},m=(e,t,n)=>{if(!this._enabled)return;this._eventListeners.change.forEach(r=>{r(e,t,n)}),this.emitDrawingPushIfHistoryChangedFromLastSnapshot();let{changed:r,unchanged:i}=f(e);t===`create`?this._adapter.render({created:r,deletedIds:[],unchanged:i,updated:[]},this.getModeStyles()):t===`update`?this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:r},this.getModeStyles()):t===`delete`?this._adapter.render({created:[],deletedIds:e,unchanged:i,updated:[]},this.getModeStyles()):t===`styling`&&this._adapter.render({created:[],deletedIds:[],unchanged:i,updated:[]},this.getModeStyles())},h=e=>{if(!this._enabled)return;this._eventListeners.select.forEach(t=>{t(e)});let{changed:t,unchanged:n}=f([e]);this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:t},this.getModeStyles())},g=e=>{if(!this._enabled)return;this._eventListeners.deselect.forEach(t=>{t(e)});let{changed:t,unchanged:n}=f([e]);t&&this._adapter.render({created:[],deletedIds:[],unchanged:n,updated:t},this.getModeStyles())};Object.keys(this._modes).forEach(e=>{var t;this._modes[e].register({mode:e,store:this._store,setCursor:this._adapter.setCursor.bind(this._adapter),project:this._adapter.project.bind(this._adapter),unproject:this._adapter.unproject.bind(this._adapter),setDoubleClickToZoom:this._adapter.setDoubleClickToZoom.bind(this._adapter),onChange:m,onSelect:h,onDeselect:g,onFinish:p,coordinatePrecision:this._adapter.getCoordinatePrecision(),undoRedoMaxStackSize:(t=this.drawingUndoRedo)==null||t.getMaxStackSize==null?void 0:t.getMaxStackSize()})}),this.sessionUndoRedoEnabled&&c&&(this.sessionUndoRedo=c,c.register({draw:this,onHistoryChange:e=>{var t;(t=this.undoRedoCoordinator)==null||t.emitStackHistoryChange(e)}})),this.drawingUndoRedo&&this.drawingUndoRedo.register({getModeState:()=>this.getModeState(),getModeHistorySizes:()=>this.getDrawingHistorySizes(),undoMode:()=>{this._mode.undo&&this._mode.undo()},redoMode:()=>{this._mode.redo&&this._mode.redo()},clearModeHistory:()=>{let e=this._mode;e.clearHistory&&e.clearHistory()},onHistoryChange:e=>{var t;(t=this.undoRedoCoordinator)==null||t.emitStackHistoryChange(e)}}),this.undoRedoCoordinator=new Et({modeLevel:this.drawingUndoRedo,sessionLevel:this.sessionUndoRedo,shouldPreferMode:()=>this.getModeState()===`drawing`,onHistoryChange:e=>{this._eventListeners.history.forEach(t=>{t(e)})},shouldEmitHistoryChange:()=>this._enabled})}checkEnabled(){if(!this._enabled)throw Error(`Terra Draw is not enabled`)}handleUndoRedoKeyboardShortcut(e){if(!this.drawingUndoRedo&&!this.sessionUndoRedoEnabled||!this.keyboardShortcutsMatcher)return!1;let t=this.keyboardShortcutsMatcher.isUndoKeyboardShortcut(e),n=this.keyboardShortcutsMatcher.isRedoKeyboardShortcut(e);if(t){if(!this.canUndo())return!1;let t=this.undo();return t&&e.preventDefault(),t}if(n){if(!this.canRedo())return!1;let t=this.redo();return t&&e.preventDefault(),t}return!1}getDrawingHistorySizes(){return{undoSize:this._mode.undoSize&&typeof this._mode.undoSize==`function`?this._mode.undoSize():0,redoSize:this._mode.redoSize&&typeof this._mode.redoSize==`function`?this._mode.redoSize():0}}emitDrawingPushIfHistoryChangedFromLastSnapshot(){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChangedFromLastSnapshot()}emitDrawingPushIfHistoryChanged(e){this.drawingUndoRedo&&this.drawingUndoRedo.emitPushIfHistoryChanged(e)}getModeStyles(){let e={},t=this._instanceSelectModes.includes(this._mode.mode)?this._mode.mode:void 0;return Object.keys(this._modes).forEach(n=>{e[n]=e=>t&&e.properties[f.SELECTED]?this._modes[t].styleFeature.bind(this._modes[t])(e):this._modes[n].styleFeature.bind(this._modes[n])(e)}),e}featuresAtLocation({lng:e,lat:t},n){let r=n&&n.pointerDistance!==void 0?n.pointerDistance:30,i=!n||n.ignoreSelectFeatures===void 0||n.ignoreSelectFeatures,a=!(!n||n.ignoreCoordinatePoints===void 0)&&n.ignoreCoordinatePoints,o=!(!n||n.ignoreCurrentlyDrawing===void 0)&&n.ignoreCurrentlyDrawing,s=!(!n||n.ignoreClosingPoints===void 0)&&n.ignoreClosingPoints,c=!(!n||n.ignoreSnappingPoints===void 0)&&n.ignoreSnappingPoints,l=this._adapter.unproject.bind(this._adapter),u=this._adapter.project.bind(this._adapter),d=u(e,t),m=me({unproject:l,point:d,pointerDistance:r});return this._store.search(m).filter(l=>{if(i&&(l.properties[f.MID_POINT]||l.properties[f.SELECTION_POINT])||a&&l.properties[p.COORDINATE_POINT]||s&&l.properties[p.CLOSING_POINT]||o&&l.properties[p.CURRENTLY_DRAWING]||c&&l.properties[p.SNAPPING_POINT])return!1;if(l.geometry.type===`Point`){let e=l.geometry.coordinates;return F(d,u(e[0],e[1]))<r}if(l.geometry.type===`LineString`){let e=l.geometry.coordinates;for(let t=0;t<e.length-1;t++){let n=e[t],i=e[t+1];if(Je(d,u(n[0],n[1]),u(i[0],i[1]))<r)return!0}return!1}if(qe([e,t],l.geometry.coordinates))return!0;if(n!=null&&n.includePolygonsWithinPointerDistance){let e=l.geometry.coordinates;for(let t of e)for(let e=0;e<t.length-1;e++){let n=t[e],i=t[e+1];if(Je(d,u(n[0],n[1]),u(i[0],i[1]))<r)return!0}}return!1}).map(r=>{if(n==null||!n.addClosestCoordinateInfoToProperties)return r;let i;if(r.geometry.type===`Polygon`)i=r.geometry.coordinates[0].slice(0,-1);else{if(r.geometry.type!==`LineString`)return r;i=r.geometry.coordinates}let a,o=-1,s=1/0;for(let e=0;e<i.length;e++){let t=i[e],n=F(u(t[0],t[1]),d);n<s&&(o=e,s=n,a=t)}return r.properties.closestCoordinateIndexToEvent=o,r.properties.closestCoordinatePixelDistanceToEvent=s,r.properties.closestCoordinateDistanceKmToEvent=S(a,[e,t]),r})}getSelectModeOrThrow(e=void 0){let t=this.getSelectMode({switchToSelectMode:!0,selectMode:e});if(!t)throw Error(`No select mode defined in instance`);return t}getSelectMode({switchToSelectMode:e,selectMode:t}){this.checkEnabled();let n=this.getMode();if(this._instanceSelectModes.length===0)return null;if(t!==void 0&&!this._instanceSelectModes.includes(t))throw Error(`No select mode with this name present: ${t}`);let r;return r=t===void 0?this._instanceSelectModes.includes(n)?n:this._instanceSelectModes[0]:t,e&&n!==r&&this.setMode(r),this._modes[r]}isGuidanceFeature(e){return!!(e.properties[f.MID_POINT]||e.properties[f.SELECTION_POINT]||e.properties[p.COORDINATE_POINT]||e.properties[p.SNAPPING_POINT])}setModeStyles(e,t){if(this.checkEnabled(),!this._modes[e])throw Error(`No mode with this name present`);this._modes[e].styles=t}updateModeOptions(e,t){if(this.checkEnabled(),!this._modes[e])throw Error(`No mode with this name present`);this._modes[e].updateOptions(t)}getSnapshot(){return this._store.copyAll()}getSnapshotFeature(e){if(this._store.has(e))return this._store.copy(e)}clear(){this.checkEnabled(),this._adapter.clear()}get enabled(){return this._enabled}set enabled(e){throw Error(`Enabled is read only`)}getMode(){return this._mode.mode}getModeState(){return this._mode.state}setMode(e){if(this.checkEnabled(),!this._modes[e])throw Error(`No mode with this name present`);this._mode.stop(),this._mode=this._modes[e],this._mode.start()}removeFeatures(e){this.checkEnabled();let t=[],n=[],r;e.forEach(e=>{if(!this._store.has(e))throw Error(`No feature with id ${e}, can not delete`);let i=this._store.getPropertiesCopy(e);i[f.SELECTED]&&this.deselectFeature(e),i[p.CURRENTLY_DRAWING]&&this._modes[i.mode]?r=i.mode:(i[p.COORDINATE_POINT_IDS]&&t.push(...i[p.COORDINATE_POINT_IDS]),n.push(e))}),this._store.delete([...n,...t],{origin:`api`}),r&&this._modes[r]&&this._modes[r].cleanUp()&&this._modes[r].cleanUp()}selectFeature(e,t){this.getSelectModeOrThrow(t).selectFeature(e)}deselectFeature(e){this.getSelectModeOrThrow().deselectFeature(e)}getFeatureId(){return this._store.getId()}hasFeature(e){return this._store.has(e)}checkIsReservedProperty(e){return![...Object.values(f),...Object.values(p)].includes(e)}updateFeatureProperties(e,t){var n;if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let r=this._store.copy(e);if(this.isGuidanceFeature(r))throw Error(`Guidance features are not allowed to be updated directly.`);let i=r.properties.mode;if(!this._modes[i])throw Error(`No mode with name ${i} present in instance`);let a=Object.entries(t);a.forEach(([e,t])=>{if(!this.checkIsReservedProperty(e))throw Error(`You are trying to update a reserved property name: ${e}. Please choose another name.`);if(t!==void 0&&!Ct(t))throw Error(`Invalid JSON value provided for property ${e}`)}),this._store.updateProperty(a.map(([e,t])=>({id:r.id,property:e,value:t})),{origin:`api`}),(n=this.undoRedoCoordinator)==null||n.emitHistoryPushForCompletedAction()}updateFeatureGeometry(e,t){var n;if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let r=this._store.copy(e);if(this.isGuidanceFeature(r))throw Error(`Guidance features are not allowed to be updated directly.`);if(!(r&&t&&t.type&&t.coordinates))throw Error(`Invalid geometry provided`);if(t.type!==r.geometry.type)throw Error(`Geometry type mismatch: expected ${r.geometry.type}, got ${t.type}`);let i=r.properties.mode,o=this._modes[i];if(!o)throw Error(`No mode with name ${i} present in instance`);let s=a({},r,{geometry:t}),c=o.validateFeature(s);if(!c.valid)throw Error(`Feature validation failed: ${c.reason||`Unknown reason`}`);if(this._store.updateGeometry([{id:r.id,geometry:t}],{origin:`api`}),o.afterFeatureUpdated){o.afterFeatureUpdated(s);let e=s.properties[f.SELECTED],t=this.getSelectMode({switchToSelectMode:!1});t&&e&&t.afterFeatureUpdated(s)}(n=this.undoRedoCoordinator)==null||n.emitHistoryPushForCompletedAction()}transformFeatureGeometry(e,t){var n;if(!this._store.has(e))throw Error(`No feature with id ${e} present in store`);let r=this._store.copy(e);if(this.isGuidanceFeature(r))throw Error(`Guidance features are not allowed to be updated directly.`);let i=r.properties.mode,a=this._modes[i];if(!a)throw Error(`No mode with name ${i} present in instance`);let o;if(r.geometry.type===`Polygon`)o=r.geometry.coordinates[0];else{if(r.geometry.type!==`LineString`)throw Error(`Feature geometry type ${r.geometry.type} is not supported for transformation`);o=r.geometry.coordinates}if(t.projection!=`web-mercator`)throw Error(`Projection ${t.projection} is not currently supported for transformation`);if(t.type===`scale`){let{x:e,y:n}=k(t.origin[0],t.origin[1]);rt({coordinates:o,originX:e,originY:n,xScale:t.options.xScale||1,yScale:t.options.yScale||1})}else t.type===`rotate`&&(r=$e(r,t.options.angle||0),o=r.geometry.type===`Polygon`?r.geometry.coordinates[0]:r.geometry.coordinates);if(o=o.map(e=>[D(e[0],this._adapter.getCoordinatePrecision()),D(e[1],this._adapter.getCoordinatePrecision())]),r.geometry.coordinates=r.geometry.type===`Polygon`?[o]:o,this._store.updateGeometry([{id:r.id,geometry:r.geometry}],{origin:`api`}),a.afterFeatureUpdated){a.afterFeatureUpdated(r);let e=r.properties[f.SELECTED],t=this.getSelectMode({switchToSelectMode:!1});t&&e&&t.afterFeatureUpdated(r)}(n=this.undoRedoCoordinator)==null||n.emitHistoryPushForCompletedAction()}undo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.undo()}canUndo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canUndo()}canRedo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.canRedo()}redo(){return this.checkEnabled(),!!this.undoRedoCoordinator&&this.undoRedoCoordinator.redo()}clearUndoRedoHistory(){this.checkEnabled(),this.undoRedoCoordinator&&this.undoRedoCoordinator.clearHistory()}addFeatures(e){return this.checkEnabled(),e.length===0?[]:this._store.load(e,e=>{if(g(e)){let t=e.properties.mode,n=this._modes[t];if(!n)return{id:e.id,valid:!1,reason:`${t} mode is not in the list of instantiated modes`};let r=n.validateFeature.bind(n)(e);return{id:e.id,valid:r.valid,reason:r.reason?r.reason:r.valid?void 0:`Feature is invalid`}}return{id:e.id,valid:!1,reason:`Mode property does not exist`}},e=>{if(g(e)){let t=this._modes[e.properties.mode];t&&t.afterFeatureAdded&&t.afterFeatureAdded(e)}},{origin:`api`})}start(){this._enabled||(this._enabled=!0,this._adapter.register({onReady:()=>{this._eventListeners.ready.forEach(e=>{e()})},getState:()=>this._mode.state,onClick:e=>{let t=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onClick(e),this.emitDrawingPushIfHistoryChanged(t)},onMouseMove:e=>{this._mode.onMouseMove(e)},onKeyDown:e=>{this.handleUndoRedoKeyboardShortcut(e)||this._mode.onKeyDown(e)},onKeyUp:e=>{let t=this.drawingUndoRedo?this.drawingUndoRedo.getHistorySizes():{undoSize:0,redoSize:0};this._mode.onKeyUp(e),this.emitDrawingPushIfHistoryChanged(t)},onDragStart:(e,t)=>{this._mode.onDragStart(e,t)},onDrag:(e,t)=>{this._mode.onDrag(e,t)},onDragEnd:(e,t)=>{this._mode.onDragEnd(e,t)},onClear:()=>{this._mode.cleanUp(),this._store.clear({origin:`api`})}}))}getFeaturesAtLngLat(e,t){let{lng:n,lat:r}=e;return this.featuresAtLocation({lng:n,lat:r},t)}getFeaturesAtPointerEvent(e,t){let n=this._adapter.getLngLatFromEvent.bind(this._adapter)(e);return n===null?[]:this.featuresAtLocation(n,t)}stop(){this._enabled&&(this._enabled=!1,this._adapter.unregister())}on(e,t){let n=this._eventListeners[e];n.includes(t)||n.push(t)}off(e,t){let n=this._eventListeners[e];n.includes(t)&&n.splice(n.indexOf(t),1)}};function Ot(){return Ot=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ot.apply(null,arguments)}var kt=class extends St.TerraDrawBaseAdapter{constructor(e){super(e),this._renderBeforeLayerId=void 0,this._prefixId=void 0,this._initialDragPan=void 0,this._initialDragRotate=void 0,this._nextRender=void 0,this._map=void 0,this._container=void 0,this.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},this._map=e.map,this._container=this._map.getContainer(),this._initialDragRotate=this._map.dragRotate.isEnabled(),this._initialDragPan=this._map.dragPan.isEnabled(),this._renderBeforeLayerId=e.renderBelowLayerId,this._prefixId=e.prefixId||`td`}hashCode(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return Math.abs(t)}resizeImage(e,t,n,r){let i=new Image;i.crossOrigin=`anonymous`,i.onload=()=>{let e=document.createElement(`canvas`);e.width=t,e.height=n;let a=e.getContext(`2d`);if(!a)throw Error(`Could not get canvas context`);a.drawImage(i,0,0,t,n),r(e.toDataURL())},i.src=e}toGlDashArrayFromPixels(e,t){if(!e)return null;let[n,r]=e;if(!Number.isFinite(n)||!Number.isFinite(r)||n<0||r<0)return null;let i=Math.max(1e-4,t);return[n/i,r/i]}isMapLibreAtLeast(e){let t=this._map.version;if(!t)return!1;let n=e=>{let t=e.match(/(\d+)\.(\d+)\.(\d+)/);return t?[parseInt(t[1],10),parseInt(t[2],10),parseInt(t[3],10)]:null},r=n(t),i=n(e);if(!r||!i)return!0;let[a,o,s]=r,[c,l,u]=i;return a===c?o===l?s>=u:o>l:a>c}_addGeoJSONSource(e,t){this._map.addSource(e,{type:`geojson`,data:{type:`FeatureCollection`,features:t},tolerance:0})}_addFillLayer(e){return this._map.addLayer({id:e,source:e,type:`fill`,layout:{"fill-sort-key":[`get`,`zIndex`]},paint:{"fill-color":[`get`,`polygonFillColor`],"fill-opacity":[`get`,`polygonFillOpacity`]}})}_addFillOutlineLayer(e){return this._map.addLayer({id:e+`-outline`,source:e,type:`line`,layout:{"line-sort-key":[`get`,`zIndex`]},paint:{"line-width":[`get`,`polygonOutlineWidth`],"line-color":[`get`,`polygonOutlineColor`],"line-opacity":[`get`,`polygonOutlineOpacity`]}})}_addLineLayer(e){let t={};return this.isMapLibreAtLeast(`5.8.0`)&&(t[`line-dasharray`]=[`coalesce`,[`get`,`lineStringDash`],[`literal`,[1,0]]]),this._map.addLayer({id:e,source:e,type:`line`,layout:{"line-sort-key":[`get`,`zIndex`]},paint:Ot({},t,{"line-width":[`get`,`lineStringWidth`],"line-color":[`get`,`lineStringColor`],"line-opacity":[`get`,`lineStringOpacity`]})})}_addPointLayer(e){return this._map.addLayer({id:e,source:e,type:`circle`,layout:{"circle-sort-key":[`get`,`zIndex`]},paint:{"circle-stroke-color":[`get`,`pointOutlineColor`],"circle-stroke-width":[`get`,`pointOutlineWidth`],"circle-stroke-opacity":[`get`,`pointOutlineOpacity`],"circle-radius":[`get`,`pointWidth`],"circle-color":[`get`,`pointColor`],"circle-opacity":[`get`,`pointOpacity`]}})}_addMarkerLayer(e){return this._map.addLayer({id:e+`-marker`,source:e,type:`symbol`,filter:[`has`,`markerId`],layout:{"icon-image":[`image`,[`get`,`markerId`]],"icon-anchor":`bottom`,"icon-allow-overlap":!0}})}_addLayer(e,t){t===`Point`&&(this._addPointLayer(e),this._addMarkerLayer(e)),t===`LineString`&&this._addLineLayer(e),t===`Polygon`&&(this._addFillLayer(e),this._addFillOutlineLayer(e))}_addGeoJSONLayer(e,t){let n=`${this._prefixId}-${e.toLowerCase()}`;return this._addGeoJSONSource(n,t),this._addLayer(n,e),n}_setGeoJSONLayerData(e,t){let n=`${this._prefixId}-${e.toLowerCase()}`;return this._map.getSource(n).setData({type:`FeatureCollection`,features:t}),n}updateChangedIds(e){[...e.updated,...e.created].forEach(e=>{e.geometry.type===`Point`?this.changedIds.points=!0:e.geometry.type===`LineString`?this.changedIds.linestrings=!0:e.geometry.type===`Polygon`&&(this.changedIds.polygons=!0)}),e.deletedIds.length>0&&(this.changedIds.deletion=!0),e.created.length===0&&e.updated.length===0&&e.deletedIds.length===0&&(this.changedIds.styling=!0)}getLngLatFromEvent(e){let{left:t,top:n}=this._container.getBoundingClientRect();return this.unproject(e.clientX-t,e.clientY-n)}getMapEventElement(){return this._map.getCanvas()}setDraggability(e){e?(this._initialDragRotate&&this._map.dragRotate.enable(),this._initialDragPan&&this._map.dragPan.enable()):(this._initialDragRotate&&this._map.dragRotate.disable(),this._initialDragPan&&this._map.dragPan.disable())}project(e,t){let{x:n,y:r}=this._map.project({lng:e,lat:t});return{x:n,y:r}}unproject(e,t){let{lng:n,lat:r}=this._map.unproject({x:e,y:t});return{lng:n,lat:r}}setCursor(e){let t=this._map.getCanvas();e===`unset`?t.style.removeProperty(`cursor`):t.style.cursor=e}setDoubleClickToZoom(e){e?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()}render(e,t){this.updateChangedIds(e),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame(()=>{if(!this._currentModeCallbacks)return;let n=[...e.created,...e.updated,...e.unchanged],r=[],i=[],a=[];for(let e=0;e<n.length;e++){let o=n[e],{properties:s}=o,c=t[s.mode](o);if(s.zIndex=c.zIndex,s.zIndex=c.zIndex,o.geometry.type===`Point`){s.pointColor=c.pointColor,s.pointOutlineColor=c.pointOutlineColor,s.pointOutlineWidth=c.pointOutlineWidth;let e=c.pointOutlineOpacity;s.pointOutlineOpacity=e===void 0?1:e,s.pointWidth=c.pointWidth;let t=c.pointOpacity;if(s.pointOpacity=t===void 0?1:t,c.markerUrl&&c.markerWidth&&c.markerHeight){let e=`marker-${this.hashCode(c.markerUrl)}`;this._map.hasImage(e)||this.resizeImage(c.markerUrl,c.markerWidth,c.markerHeight,t=>{this._map.loadImage(t).then(t=>{this._map.hasImage(e)||this._map.addImage(e,t.data)})}),s.markerId=e,s.pointWidth=0}r.push(o)}else if(o.geometry.type===`LineString`){s.lineStringDash=this.toGlDashArrayFromPixels(c.lineStringDash,c.lineStringWidth),s.lineStringColor=c.lineStringColor,s.lineStringWidth=c.lineStringWidth;let e=c.lineStringOpacity;s.lineStringOpacity=e===void 0?1:e,i.push(o)}else if(o.geometry.type===`Polygon`){let e=c.polygonOutlineOpacity;s.polygonFillColor=c.polygonFillColor,s.polygonFillOpacity=c.polygonFillOpacity,s.polygonOutlineOpacity=e===void 0?1:e,s.polygonOutlineColor=c.polygonOutlineColor,s.polygonOutlineWidth=c.polygonOutlineWidth,a.push(o)}}let o=this.changedIds.deletion||this.changedIds.styling,s=o||this.changedIds.linestrings,c=o||this.changedIds.polygons;(o||this.changedIds.points)&&this._setGeoJSONLayerData(`Point`,r),s&&this._setGeoJSONLayerData(`LineString`,i),c&&this._setGeoJSONLayerData(`Polygon`,a),this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1}})}clear(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this._nextRender&&=(cancelAnimationFrame(this._nextRender),void 0),this._setGeoJSONLayerData(`Point`,[]),this._setGeoJSONLayerData(`LineString`,[]),this._setGeoJSONLayerData(`Polygon`,[]))}getCoordinatePrecision(){return super.getCoordinatePrecision()}unregister(){super.unregister(),this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1},this._map.removeLayer(`${this._prefixId}-point`),this._map.removeLayer(`${this._prefixId}-point-marker`),this._map.removeSource(`${this._prefixId}-point`),this._map.removeLayer(`${this._prefixId}-linestring`),this._map.removeSource(`${this._prefixId}-linestring`),this._map.removeLayer(`${this._prefixId}-polygon`),this._map.removeLayer(`${this._prefixId}-polygon-outline`),this._map.removeSource(`${this._prefixId}-polygon`)}register(e){var t;super.register(e);let n=this._addGeoJSONLayer(`Polygon`,[]),r=this._addGeoJSONLayer(`LineString`,[]),i=this._addGeoJSONLayer(`Point`,[]);var a;this._renderBeforeLayerId&&(this._map.moveLayer(i,this._renderBeforeLayerId),this._map.moveLayer(r,i),this._map.moveLayer(`${n}-outline`,r),this._map.moveLayer(n,`${n}-outline`)),(t=this._currentModeCallbacks)!=null&&t.onReady&&((a=this._currentModeCallbacks)==null||a.onReady())}},At=`linestring`;function jt(e){return r(e).select}function Mt(t){let r=t.geometry;return r.type===`LineString`?r.coordinates.filter(n).map(t=>({position:e(t)})):[]}var Nt=1e-9,Pt=9;function Ft(e,t){return Math.abs(e.latitude-t.latitude)<=Nt&&Math.abs(e.longitude-t.longitude)<=Nt}function It(e){return{type:`Feature`,properties:{mode:At},geometry:{type:`LineString`,coordinates:e.waypoints.map(e=>i(t(e.position,Pt)))}}}function Lt(e){let t=jt(e.theme),n=new Dt({adapter:new kt({map:e.map,prefixId:`binnacle-route-draw`,renderBelowLayerId:e.beforeId}),modes:[new Ve({styles:{pointColor:t,pointWidth:6}}),new Pe({styles:{lineStringColor:t,lineStringWidth:4}}),new st({styles:{selectionPointColor:t,midPointColor:t},flags:{linestring:{feature:{draggable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}}}})]}),r=[],i=!1,a=e=>{r=e,i=e.some(e=>e.name!=null)},o=!1,s=!1,c=[],l=e=>i?(c.length=r.length,c.fill(!1),e.map(e=>{for(let t=0;t<r.length;t+=1){if(c[t]||!Ft(r[t].position,e.position))continue;c[t]=!0;let n=r[t].name;return n==null?e:{...e,name:n}}return e})):e,u=()=>n.getSnapshot().filter(e=>e.properties.mode===At&&e.geometry.type===`LineString`),d=!1,f=!1,p=e=>({line:e[e.length-1],extraIds:e.slice(0,-1).map(e=>e.id).filter(e=>e!=null)}),m=()=>{f=!1;let e=u();if(e.length<=1)return;let{extraIds:t}=p(e);if(t.length!==0){d=!0;try{n.removeFeatures(t)}finally{d=!1}}},h=()=>{let e=u();if(e.length===0)return[];let{line:t,extraIds:n}=p(e);n.length>0&&!f&&(f=!0,queueMicrotask(m));let r=Mt(t);return l(o?r.slice(0,-1):r)};n.on(`change`,()=>{if(d)return;let t=h();a(t),e.onChange(t),s||e.onUserEdit?.()}),n.on(`finish`,()=>{o=!1});let g=t=>{queueMicrotask(()=>{let n=e.map.getCanvas(),r=n.getBoundingClientRect(),{x:i,y:a}=e.map.project([t.longitude,t.latitude]),o={clientX:r.left+i,clientY:r.top+a,bubbles:!0,cancelable:!0,pointerId:1,pointerType:`mouse`,isPrimary:!0,button:0};n.dispatchEvent(new PointerEvent(`pointerdown`,o)),n.dispatchEvent(new PointerEvent(`pointerup`,o))})};return{start(e,t){a(e?e.waypoints.slice():[]),n.start(),e&&e.waypoints.length>0?(o=!1,s=!0,n.addFeatures([It(e)]),n.setMode(`select`),queueMicrotask(()=>{s=!1})):(o=!0,n.setMode(At),t&&g(t))},setTheme(e){let t=jt(e);n.updateModeOptions(`point`,{styles:{pointColor:t,pointWidth:6}}),n.updateModeOptions(`linestring`,{styles:{lineStringColor:t,lineStringWidth:4}}),n.updateModeOptions(`select`,{styles:{selectionPointColor:t,midPointColor:t}})},stop(){n.stop()}}}export{Lt as createRouteEditor};
@@ -4,4 +4,4 @@
4
4
  * Copyright 2019 Google LLC
5
5
  * SPDX-License-Identifier: Apache-2.0
6
6
  */
7
- let e=Symbol(`Comlink.proxy`),t=Symbol(`Comlink.endpoint`),n=Symbol(`Comlink.releaseProxy`),r=Symbol(`Comlink.finalizer`),i=Symbol(`Comlink.thrown`),a=e=>typeof e==`object`&&!!e||typeof e==`function`,o=new Map([[`proxy`,{canHandle:t=>a(t)&&t[e],serialize(e){let{port1:t,port2:n}=new MessageChannel;return c(e,t),[n,[n]]},deserialize(e){return e.start(),d(e)}}],[`throw`,{canHandle:e=>a(e)&&i in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(Error(e.value.message),e.value):e.value}}]]);function s(e,t){for(let n of e)if(t===n||n===`*`||n instanceof RegExp&&n.test(t))return!0;return!1}function c(e,t=globalThis,n=[`*`]){t.addEventListener(`message`,function a(o){if(!o||!o.data)return;if(!s(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}let{id:l,type:d,path:f}=Object.assign({path:[]},o.data),p=(o.data.argumentList||[]).map(T),m;try{let t=f.slice(0,-1).reduce((e,t)=>e[t],e),n=f.reduce((e,t)=>e[t],e);switch(d){case`GET`:m=n;break;case`SET`:t[f.slice(-1)[0]]=T(o.data.value),m=!0;break;case`APPLY`:m=n.apply(t,p);break;case`CONSTRUCT`:m=C(new n(...p));break;case`ENDPOINT`:{let{port1:t,port2:n}=new MessageChannel;c(e,n),m=S(t,[t])}break;case`RELEASE`:m=void 0;break;default:return}}catch(e){m={value:e,[i]:0}}Promise.resolve(m).catch(e=>({value:e,[i]:0})).then(n=>{let[i,o]=w(n);t.postMessage(Object.assign(Object.assign({},i),{id:l}),o),d===`RELEASE`&&(t.removeEventListener(`message`,a),u(t),r in e&&typeof e[r]==`function`&&e[r]())}).catch(e=>{let[n,r]=w({value:TypeError(`Unserializable return value`),[i]:0});t.postMessage(Object.assign(Object.assign({},n),{id:l}),r)})}),t.start&&t.start()}function l(e){return e.constructor.name===`MessagePort`}function u(e){l(e)&&e.close()}function d(e,t){let n=new Map;return e.addEventListener(`message`,function(e){let{data:t}=e;if(!t||!t.id)return;let r=n.get(t.id);if(r)try{r(t)}finally{n.delete(t.id)}}),v(e,n,[],t)}function f(e){if(e)throw Error(`Proxy has been released and is not useable`)}function p(e){return E(e,new Map,{type:`RELEASE`}).then(()=>{u(e)})}let m=new WeakMap,h=`FinalizationRegistry`in globalThis&&new FinalizationRegistry(e=>{let t=(m.get(e)||0)-1;m.set(e,t),t===0&&p(e)});function g(e,t){let n=(m.get(t)||0)+1;m.set(t,n),h&&h.register(e,t,e)}function _(e){h&&h.unregister(e)}function v(e,r,i=[],a=function(){}){let o=!1,s=new Proxy(a,{get(t,a){if(f(o),a===n)return()=>{_(s),p(e),r.clear(),o=!0};if(a===`then`){if(i.length===0)return{then:()=>s};let t=E(e,r,{type:`GET`,path:i.map(e=>e.toString())}).then(T);return t.then.bind(t)}return v(e,r,[...i,a])},set(t,n,a){f(o);let[s,c]=w(a);return E(e,r,{type:`SET`,path:[...i,n].map(e=>e.toString()),value:s},c).then(T)},apply(n,a,s){f(o);let c=i[i.length-1];if(c===t)return E(e,r,{type:`ENDPOINT`}).then(T);if(c===`bind`)return v(e,r,i.slice(0,-1));let[l,u]=b(s);return E(e,r,{type:`APPLY`,path:i.map(e=>e.toString()),argumentList:l},u).then(T)},construct(t,n){f(o);let[a,s]=b(n);return E(e,r,{type:`CONSTRUCT`,path:i.map(e=>e.toString()),argumentList:a},s).then(T)}});return g(s,e),s}function y(e){return Array.prototype.concat.apply([],e)}function b(e){let t=e.map(w);return[t.map(e=>e[0]),y(t.map(e=>e[1]))]}let x=new WeakMap;function S(e,t){return x.set(e,t),e}function C(t){return Object.assign(t,{[e]:!0})}function w(e){for(let[t,n]of o)if(n.canHandle(e)){let[r,i]=n.serialize(e);return[{type:`HANDLER`,name:t,value:r},i]}return[{type:`RAW`,value:e},x.get(e)||[]]}function T(e){switch(e.type){case`HANDLER`:return o.get(e.name).deserialize(e.value);case`RAW`:return e.value}}function E(e,t,n,r){return new Promise(i=>{let a=D();t.set(a,i),e.start&&e.start(),e.postMessage(Object.assign({id:a},n),r)})}function D(){return[,,,,].fill(0).map(()=>Math.floor(Math.random()*(2**53-1)).toString(16)).join(`-`)}let O=typeof document<`u`&&typeof requestAnimationFrame==`function`?e=>{let t=requestAnimationFrame(()=>e(Date.now()));return()=>cancelAnimationFrame(t)}:e=>{let t=setTimeout(()=>e(Date.now()),16);return()=>clearTimeout(t)};var k=class{onFlush;#e=new Map;#t=new Map;#n=!1;#r;#i;constructor(e=O){this.#i=e}put(e,t){this.#e.set(e,t),this.#a()}putVessel(e,t,n){let r=this.#t.get(e);r||(r=new Map,this.#t.set(e,r)),r.set(t,n),this.#a()}reset(){this.#r?.(),this.#r=void 0,this.#n=!1,this.#e.clear(),this.#t.clear()}#a(){this.#n||(this.#n=!0,this.#r=this.#i(e=>this.#o(e)))}#o(e){if(this.#n=!1,this.#r=void 0,this.#e.size===0&&this.#t.size===0)return;let t=this.#e,n=this.#t;this.#e=new Map,this.#t=new Map,this.onFlush?.(t,n,e)}};function A(e,t=500,n=3e4){let r=Math.min(n,t*2**e);return Math.random()*r}function j(e,t){return e.includes(`?`)?`${e}&${t}`:`${e}?${t}`}var M=class{#e;#t;#n;#r=0;#i=!1;#a;constructor(e,t){this.#e=e,this.#t=t}connect(){this.#i=!1,this.#a&&clearTimeout(this.#a),this.#n?.close(),this.#s(`connecting`);let e=new WebSocket(j(this.#e,`subscribe=none`));this.#n=e,e.onopen=()=>{this.#n===e&&(this.#r=0,this.#s(`open`),this.#t.onOpen?.())},e.onmessage=t=>{this.#n===e&&this.#t.onDelta(t.data)},e.onclose=()=>{this.#n!==e||this.#i||this.#o()},e.onerror=()=>{this.#n===e&&e.close()}}send(e){this.#n?.readyState===WebSocket.OPEN&&this.#n.send(JSON.stringify(e))}disconnect(){this.#i=!0,this.#r=0,this.#a&&clearTimeout(this.#a);let e=this.#n!==void 0;this.#n?.close(),this.#n=void 0,e&&this.#s(`closed`)}#o(){this.#s(`reconnecting`);let e=A(this.#r);this.#r+=1,this.#a=setTimeout(()=>{this.#i||this.connect()},e)}#s(e){this.#t.onState({phase:e,attempt:this.#r})}};let N={phase:`connecting`,attempt:0};function P(e,t){let n=e.context??`vessels.self`;for(let r of e.updates??[]){let e=r.values;if(Array.isArray(e))for(let r of e)t(n,r.path,r.value)}}var F=class{#e=new Map;#t;constructor(e){this.#t=e}add(e){let t=[];for(let n of e){let e=this.#i(n),r=`${e.context}|${e.path}`,i=this.#e.get(r);i?i.count+=1:(this.#e.set(r,{count:1,entry:e}),this.#o(e)),t.push(r)}return()=>this.#n(t)}remove(e,t){let n=t??`vessels.self`;for(let t of e)this.#r(`${n}|${t}`)}resubscribeAll(){let e=new Map;for(let{entry:t}of this.#e.values()){let n=e.get(t.context);n?n.push(this.#a(t)):e.set(t.context,[this.#a(t)])}for(let[t,n]of e)this.#t({context:t,subscribe:n})}#n(e){for(let t of e)this.#r(t)}#r(e){let t=this.#e.get(e);t&&(--t.count,!(t.count>0)&&(this.#e.delete(e),this.#t({context:t.entry.context,unsubscribe:[{path:t.entry.path}]})))}#i(e){return{context:e.context??`vessels.self`,path:e.path,period:e.period??1e3,minPeriod:e.minPeriod,policy:e.policy??`ideal`}}#a(e){let t={path:e.path,period:e.period,policy:e.policy};return e.minPeriod!==void 0&&(t.minPeriod=e.minPeriod),t}#o(e){this.#t({context:e.context,subscribe:[this.#a(e)]})}},I=class{#e;#t;#n=new k;#r;#i=N;#a;connect(e,t){this.#r=t,this.#e=new M(e,{onState:e=>{this.#i=e,this.#r?.({self:new Map,connection:e,epoch:Date.now()})},onDelta:e=>this.#c(e),onOpen:()=>this.#t?.resubscribeAll()}),this.#t=new F(e=>this.#e?.send(e)),this.#n.onFlush=(e,t,n)=>{this.#r?.({self:e,ais:t,connection:this.#i,epoch:n,selfContext:this.#a})},this.#e.connect()}subscribe(e){this.#t?.add(e)}unsubscribe(e,t){this.#t?.remove(e,t)}publish(e){this.#e?.send(e)}reconnect(){this.#e?.connect()}disconnect(){this.#n.reset(),this.#e?.disconnect()}#o(e){return e===`vessels.self`||e===this.#a}#s=(e,t,n)=>{this.#o(e)?this.#n.put(t,n):this.#n.putVessel(e,t,n)};#c(e){let t;try{t=JSON.parse(e)}catch{return}if(!t.updates){typeof t.self==`string`&&(this.#a=t.self);return}P(t,this.#s)}};c(new class{#e=new I;async connect(e,t){this.#e.connect(e,t)}async subscribe(e){this.#e.subscribe(e)}async unsubscribe(e,t){this.#e.unsubscribe(e,t)}async publish(e){this.#e.publish(e)}async reconnect(){this.#e.reconnect()}async disconnect(){this.#e.disconnect()}})})();
7
+ let e=Symbol(`Comlink.proxy`),t=Symbol(`Comlink.endpoint`),n=Symbol(`Comlink.releaseProxy`),r=Symbol(`Comlink.finalizer`),i=Symbol(`Comlink.thrown`),a=e=>typeof e==`object`&&!!e||typeof e==`function`,o=new Map([[`proxy`,{canHandle:t=>a(t)&&t[e],serialize(e){let{port1:t,port2:n}=new MessageChannel;return c(e,t),[n,[n]]},deserialize(e){return e.start(),d(e)}}],[`throw`,{canHandle:e=>a(e)&&i in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(Error(e.value.message),e.value):e.value}}]]);function s(e,t){for(let n of e)if(t===n||n===`*`||n instanceof RegExp&&n.test(t))return!0;return!1}function c(e,t=globalThis,n=[`*`]){t.addEventListener(`message`,function a(o){if(!o||!o.data)return;if(!s(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}let{id:l,type:d,path:f}=Object.assign({path:[]},o.data),p=(o.data.argumentList||[]).map(T),m;try{let t=f.slice(0,-1).reduce((e,t)=>e[t],e),n=f.reduce((e,t)=>e[t],e);switch(d){case`GET`:m=n;break;case`SET`:t[f.slice(-1)[0]]=T(o.data.value),m=!0;break;case`APPLY`:m=n.apply(t,p);break;case`CONSTRUCT`:m=C(new n(...p));break;case`ENDPOINT`:{let{port1:t,port2:n}=new MessageChannel;c(e,n),m=S(t,[t])}break;case`RELEASE`:m=void 0;break;default:return}}catch(e){m={value:e,[i]:0}}Promise.resolve(m).catch(e=>({value:e,[i]:0})).then(n=>{let[i,o]=w(n);t.postMessage(Object.assign(Object.assign({},i),{id:l}),o),d===`RELEASE`&&(t.removeEventListener(`message`,a),u(t),r in e&&typeof e[r]==`function`&&e[r]())}).catch(e=>{let[n,r]=w({value:TypeError(`Unserializable return value`),[i]:0});t.postMessage(Object.assign(Object.assign({},n),{id:l}),r)})}),t.start&&t.start()}function l(e){return e.constructor.name===`MessagePort`}function u(e){l(e)&&e.close()}function d(e,t){let n=new Map;return e.addEventListener(`message`,function(e){let{data:t}=e;if(!t||!t.id)return;let r=n.get(t.id);if(r)try{r(t)}finally{n.delete(t.id)}}),v(e,n,[],t)}function f(e){if(e)throw Error(`Proxy has been released and is not useable`)}function p(e){return E(e,new Map,{type:`RELEASE`}).then(()=>{u(e)})}let m=new WeakMap,h=`FinalizationRegistry`in globalThis&&new FinalizationRegistry(e=>{let t=(m.get(e)||0)-1;m.set(e,t),t===0&&p(e)});function g(e,t){let n=(m.get(t)||0)+1;m.set(t,n),h&&h.register(e,t,e)}function _(e){h&&h.unregister(e)}function v(e,r,i=[],a=function(){}){let o=!1,s=new Proxy(a,{get(t,a){if(f(o),a===n)return()=>{_(s),p(e),r.clear(),o=!0};if(a===`then`){if(i.length===0)return{then:()=>s};let t=E(e,r,{type:`GET`,path:i.map(e=>e.toString())}).then(T);return t.then.bind(t)}return v(e,r,[...i,a])},set(t,n,a){f(o);let[s,c]=w(a);return E(e,r,{type:`SET`,path:[...i,n].map(e=>e.toString()),value:s},c).then(T)},apply(n,a,s){f(o);let c=i[i.length-1];if(c===t)return E(e,r,{type:`ENDPOINT`}).then(T);if(c===`bind`)return v(e,r,i.slice(0,-1));let[l,u]=b(s);return E(e,r,{type:`APPLY`,path:i.map(e=>e.toString()),argumentList:l},u).then(T)},construct(t,n){f(o);let[a,s]=b(n);return E(e,r,{type:`CONSTRUCT`,path:i.map(e=>e.toString()),argumentList:a},s).then(T)}});return g(s,e),s}function y(e){return Array.prototype.concat.apply([],e)}function b(e){let t=e.map(w);return[t.map(e=>e[0]),y(t.map(e=>e[1]))]}let x=new WeakMap;function S(e,t){return x.set(e,t),e}function C(t){return Object.assign(t,{[e]:!0})}function w(e){for(let[t,n]of o)if(n.canHandle(e)){let[r,i]=n.serialize(e);return[{type:`HANDLER`,name:t,value:r},i]}return[{type:`RAW`,value:e},x.get(e)||[]]}function T(e){switch(e.type){case`HANDLER`:return o.get(e.name).deserialize(e.value);case`RAW`:return e.value}}function E(e,t,n,r){return new Promise(i=>{let a=D();t.set(a,i),e.start&&e.start(),e.postMessage(Object.assign({id:a},n),r)})}function D(){return[,,,,].fill(0).map(()=>Math.floor(Math.random()*(2**53-1)).toString(16)).join(`-`)}let O=typeof document<`u`&&typeof requestAnimationFrame==`function`?e=>{let t=requestAnimationFrame(()=>e(Date.now()));return()=>cancelAnimationFrame(t)}:e=>{let t=setTimeout(()=>e(Date.now()),16);return()=>clearTimeout(t)};var k=class{onFlush;#e=new Map;#t=new Map;#n=!1;#r;#i;constructor(e=O){this.#i=e}put(e,t){this.#e.set(e,t),this.#a()}putVessel(e,t,n){let r=this.#t.get(e);r||(r=new Map,this.#t.set(e,r)),r.set(t,n),this.#a()}reset(){this.#r?.(),this.#r=void 0,this.#n=!1,this.#e.clear(),this.#t.clear()}#a(){this.#n||(this.#n=!0,this.#r=this.#i(e=>this.#o(e)))}#o(e){if(this.#n=!1,this.#r=void 0,this.#e.size===0&&this.#t.size===0)return;let t=this.#e,n=this.#t;this.#e=new Map,this.#t=new Map,this.onFlush?.(t,n,e)}};function A(e,t=500,n=3e4){let r=Math.min(n,t*2**e);return Math.random()*r}function j(e,t){return e.includes(`?`)?`${e}&${t}`:`${e}?${t}`}var M=class{#e;#t;#n;#r=0;#i=!1;#a;constructor(e,t){this.#e=e,this.#t=t}connect(){this.#i=!1,this.#a&&clearTimeout(this.#a),this.#n?.close(),this.#s(`connecting`);let e=new WebSocket(j(this.#e,`subscribe=none`));this.#n=e,e.onopen=()=>{this.#n===e&&(this.#r=0,this.#s(`open`),this.#t.onOpen?.())},e.onmessage=t=>{this.#n===e&&this.#t.onDelta(t.data)},e.onclose=()=>{this.#n!==e||this.#i||this.#o()},e.onerror=()=>{this.#n===e&&e.close()}}send(e){this.#n?.readyState===WebSocket.OPEN&&this.#n.send(JSON.stringify(e))}disconnect(){this.#i=!0,this.#r=0,this.#a&&clearTimeout(this.#a);let e=this.#n!==void 0;this.#n?.close(),this.#n=void 0,e&&this.#s(`closed`)}#o(){this.#s(`reconnecting`);let e=A(this.#r);this.#r+=1,this.#a=setTimeout(()=>{this.#i||this.connect()},e)}#s(e){this.#t.onState({phase:e,attempt:this.#r})}};let N={phase:`connecting`,attempt:0};function P(e,t){let n=e.context??`vessels.self`;for(let r of e.updates??[]){let e=r.values;if(Array.isArray(e))for(let r of e)!r||typeof r.path!=`string`||t(n,r.path,r.value)}}var F=class{#e=new Map;#t;constructor(e){this.#t=e}add(e){let t=[];for(let n of e){let e=this.#i(n),r=`${e.context}|${e.path}`,i=this.#e.get(r);i?i.count+=1:(this.#e.set(r,{count:1,entry:e}),this.#o(e)),t.push(r)}return()=>this.#n(t)}remove(e,t){let n=t??`vessels.self`;for(let t of e)this.#r(`${n}|${t}`)}resubscribeAll(){let e=new Map;for(let{entry:t}of this.#e.values()){let n=e.get(t.context);n?n.push(this.#a(t)):e.set(t.context,[this.#a(t)])}for(let[t,n]of e)this.#t({context:t,subscribe:n})}#n(e){for(let t of e)this.#r(t)}#r(e){let t=this.#e.get(e);t&&(--t.count,!(t.count>0)&&(this.#e.delete(e),this.#t({context:t.entry.context,unsubscribe:[{path:t.entry.path}]})))}#i(e){return{context:e.context??`vessels.self`,path:e.path,period:e.period??1e3,minPeriod:e.minPeriod,policy:e.policy??`ideal`}}#a(e){let t={path:e.path,period:e.period,policy:e.policy};return e.minPeriod!==void 0&&(t.minPeriod=e.minPeriod),t}#o(e){this.#t({context:e.context,subscribe:[this.#a(e)]})}},I=class{#e;#t;#n=new k;#r;#i=N;#a;connect(e,t){this.#r=t,this.#e=new M(e,{onState:e=>{this.#i=e,this.#r?.({self:new Map,connection:e,epoch:Date.now()})},onDelta:e=>this.#c(e),onOpen:()=>this.#t?.resubscribeAll()}),this.#t=new F(e=>this.#e?.send(e)),this.#n.onFlush=(e,t,n)=>{this.#r?.({self:e,ais:t,connection:this.#i,epoch:n,selfContext:this.#a})},this.#e.connect()}subscribe(e){this.#t?.add(e)}unsubscribe(e,t){this.#t?.remove(e,t)}publish(e){this.#e?.send(e)}reconnect(){this.#e?.connect()}disconnect(){this.#n.reset(),this.#e?.disconnect()}#o(e){return e===`vessels.self`||e===this.#a}#s=(e,t,n)=>{this.#o(e)?this.#n.put(t,n):this.#n.putVessel(e,t,n)};#c(e){let t;try{t=JSON.parse(e)}catch{return}if(!t.updates){typeof t.self==`string`&&(this.#a=t.self);return}P(t,this.#s)}};c(new class{#e=new I;async connect(e,t){this.#e.connect(e,t)}async subscribe(e){this.#e.subscribe(e)}async unsubscribe(e,t){this.#e.unsubscribe(e,t)}async publish(e){this.#e.publish(e)}async reconnect(){this.#e.reconnect()}async disconnect(){this.#e.disconnect()}})})();
package/public/index.html CHANGED
@@ -4,8 +4,8 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Binnacle</title>
7
- <script type="module" crossorigin src="/signalk-binnacle/assets/index-DtddKTWH.js"></script>
8
- <link rel="stylesheet" crossorigin href="/signalk-binnacle/assets/index-CfdWfyly.css">
7
+ <script type="module" crossorigin src="/signalk-binnacle/assets/index-BOkTPq1w.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/signalk-binnacle/assets/index-s5RpGU9e.css">
9
9
  <link rel="manifest" href="/signalk-binnacle/manifest.webmanifest"></head>
10
10
  <body>
11
11
  <div id="app"></div>
package/public/sw.js CHANGED
@@ -1 +1 @@
1
- if(!self.define){let e,n={};const s=(s,r)=>(s=new URL(s+".js",r).href,n[s]||new Promise(n=>{if("document"in self){const e=document.createElement("script");e.src=s,e.onload=n,document.head.appendChild(e)}else e=s,importScripts(s),n()}).then(()=>{let e=n[s];if(!e)throw new Error(`Module ${s} didn’t register its module`);return e}));self.define=(r,i)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(n[t])return;let l={};const a=e=>s(e,t),o={module:{uri:t},exports:l,require:a};n[t]=Promise.all(r.map(e=>o[e]||a(e))).then(e=>(i(...e),l))}}define(["./workbox-362dab98"],function(e){"use strict";self.addEventListener("message",e=>{e.data&&"SKIP_WAITING"===e.data.type&&self.skipWaiting()}),e.precacheAndRoute([{url:"index.html",revision:"b8d0f6c6467c7c87a7d64f394dfc5328"},{url:"binnacle-icon.svg",revision:"d946b900583be73bebf7eaa282b4b026"},{url:"assets/workbox-window.prod.es5-Bd17z0YL.js",revision:null},{url:"assets/sk.worker-C09pYRNp.js",revision:null},{url:"assets/route-edit-BUtpY0B2.js",revision:null},{url:"assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2",revision:null},{url:"assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2",revision:null},{url:"assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2",revision:null},{url:"assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2",revision:null},{url:"assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2",revision:null},{url:"assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2",revision:null},{url:"assets/inter-latin-wght-normal-Dx4kXJAl.woff2",revision:null},{url:"assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2",revision:null},{url:"assets/inter-greek-wght-normal-CkhJZR-_.woff2",revision:null},{url:"assets/inter-greek-ext-wght-normal-DlzME5K_.woff2",revision:null},{url:"assets/inter-cyrillic-wght-normal-DqGufNeO.woff2",revision:null},{url:"assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2",revision:null},{url:"assets/index-DtddKTWH.js",revision:null},{url:"assets/index-CfdWfyly.css",revision:null},{url:"assets/TrendCharts-DHXnahl6.css",revision:null},{url:"assets/TrendCharts-BOY6SI0k.js",revision:null},{url:"binnacle-icon.svg",revision:"d946b900583be73bebf7eaa282b4b026"},{url:"manifest.webmanifest",revision:"08464a0863acdeeb8449227eb27917a9"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("/signalk-binnacle/index.html"))),e.registerRoute(({url:e})=>"https://tiles.openfreemap.org"===e.origin&&e.pathname.startsWith("/styles/"),new e.StaleWhileRevalidate({cacheName:"binnacle-basemap-style",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>"https://tiles.openfreemap.org"===e.origin,new e.CacheFirst({cacheName:"binnacle-basemap",plugins:[new e.ExpirationPlugin({maxEntries:4e3,maxAgeSeconds:2592e3,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e,sameOrigin:n})=>n&&CHART_TILE_PATH.test(e.pathname),new e.CacheFirst({cacheName:"binnacle-chart-tiles",plugins:[new e.ExpirationPlugin({maxEntries:2e3,maxAgeSeconds:2592e3,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>OVERLAY_TILE_HOSTS.has(e.hostname),new e.CacheFirst({cacheName:"binnacle-overlay-tiles",plugins:[new e.ExpirationPlugin({maxEntries:1500,maxAgeSeconds:604800,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>"api.tidesandcurrents.noaa.gov"===e.hostname,new e.NetworkFirst({cacheName:"binnacle-tides",networkTimeoutSeconds:8,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:129600}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>isHost(e.hostname,"open-meteo.com"),new e.NetworkFirst({cacheName:"binnacle-weather",networkTimeoutSeconds:8,plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:21600}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>isHost(e.hostname,"rainviewer.com")&&e.pathname.endsWith(".json"),new e.NetworkFirst({cacheName:"binnacle-radar-index",networkTimeoutSeconds:6,plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:7200}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>isHost(e.hostname,"rainviewer.com")&&e.pathname.endsWith(".png"),new e.CacheFirst({cacheName:"binnacle-radar-tiles",plugins:[new e.ExpirationPlugin({maxEntries:600,maxAgeSeconds:7200}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET")});
1
+ if(!self.define){let e,n={};const s=(s,r)=>(s=new URL(s+".js",r).href,n[s]||new Promise(n=>{if("document"in self){const e=document.createElement("script");e.src=s,e.onload=n,document.head.appendChild(e)}else e=s,importScripts(s),n()}).then(()=>{let e=n[s];if(!e)throw new Error(`Module ${s} didn’t register its module`);return e}));self.define=(r,a)=>{const i=e||("document"in self?document.currentScript.src:"")||location.href;if(n[i])return;let t={};const o=e=>s(e,i),l={module:{uri:i},exports:t,require:o};n[i]=Promise.all(r.map(e=>l[e]||o(e))).then(e=>(a(...e),t))}}define(["./workbox-362dab98"],function(e){"use strict";self.addEventListener("message",e=>{e.data&&"SKIP_WAITING"===e.data.type&&self.skipWaiting()}),e.precacheAndRoute([{url:"index.html",revision:"76fb3dba28d40a9ab4a0bc02ed41000f"},{url:"binnacle-icon.svg",revision:"d946b900583be73bebf7eaa282b4b026"},{url:"assets/workbox-window.prod.es5-Bd17z0YL.js",revision:null},{url:"assets/sk.worker-CQq_KzCx.js",revision:null},{url:"assets/route-edit-B05i0oxQ.js",revision:null},{url:"assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2",revision:null},{url:"assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2",revision:null},{url:"assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2",revision:null},{url:"assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2",revision:null},{url:"assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2",revision:null},{url:"assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2",revision:null},{url:"assets/inter-latin-wght-normal-Dx4kXJAl.woff2",revision:null},{url:"assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2",revision:null},{url:"assets/inter-greek-wght-normal-CkhJZR-_.woff2",revision:null},{url:"assets/inter-greek-ext-wght-normal-DlzME5K_.woff2",revision:null},{url:"assets/inter-cyrillic-wght-normal-DqGufNeO.woff2",revision:null},{url:"assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2",revision:null},{url:"assets/index-s5RpGU9e.css",revision:null},{url:"assets/index-BOkTPq1w.js",revision:null},{url:"assets/TrendCharts-DHXnahl6.css",revision:null},{url:"assets/TrendCharts-CiUGeOLI.js",revision:null},{url:"binnacle-icon.svg",revision:"d946b900583be73bebf7eaa282b4b026"},{url:"manifest.webmanifest",revision:"08464a0863acdeeb8449227eb27917a9"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("/signalk-binnacle/index.html"))),e.registerRoute(({url:e})=>"https://tiles.openfreemap.org"===e.origin&&e.pathname.startsWith("/styles/"),new e.StaleWhileRevalidate({cacheName:"binnacle-basemap-style",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>"https://tiles.openfreemap.org"===e.origin,new e.CacheFirst({cacheName:"binnacle-basemap",plugins:[new e.ExpirationPlugin({maxEntries:4e3,maxAgeSeconds:2592e3,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e,sameOrigin:n})=>n&&/^\/charts\/[^/]+\/\d+\/\d+\/\d+(?:@2x)?(?:\.\w+)?$/.test(e.pathname),new e.CacheFirst({cacheName:"binnacle-chart-tiles",plugins:[new e.ExpirationPlugin({maxEntries:2e3,maxAgeSeconds:2592e3,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>"gis.charttools.noaa.gov"===e.hostname||"nowcoast.noaa.gov"===e.hostname||"wms.gebco.net"===e.hostname||"ows.emodnet-bathymetry.eu"===e.hostname||"ows.emodnet-humanactivities.eu"===e.hostname||"geo.vliz.be"===e.hostname||"tiles.openseamap.org"===e.hostname||"gibs.earthdata.nasa.gov"===e.hostname,new e.CacheFirst({cacheName:"binnacle-overlay-tiles",plugins:[new e.ExpirationPlugin({maxEntries:1500,maxAgeSeconds:604800,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>"api.tidesandcurrents.noaa.gov"===e.hostname,new e.NetworkFirst({cacheName:"binnacle-tides",networkTimeoutSeconds:8,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:129600,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>"open-meteo.com"===e.hostname||e.hostname.endsWith(".open-meteo.com"),new e.NetworkFirst({cacheName:"binnacle-weather",networkTimeoutSeconds:8,plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:21600,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>("rainviewer.com"===e.hostname||e.hostname.endsWith(".rainviewer.com"))&&e.pathname.endsWith(".json"),new e.NetworkFirst({cacheName:"binnacle-radar-index",networkTimeoutSeconds:6,plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:7200,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET"),e.registerRoute(({url:e})=>("rainviewer.com"===e.hostname||e.hostname.endsWith(".rainviewer.com"))&&e.pathname.endsWith(".png"),new e.CacheFirst({cacheName:"binnacle-radar-tiles",plugins:[new e.ExpirationPlugin({maxEntries:600,maxAgeSeconds:7200,purgeOnQuotaError:!0}),new e.CacheableResponsePlugin({statuses:[200]})]}),"GET")});