draw-libre 0.1.0 → 0.2.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.
- package/README.md +1 -1
- package/dist/index.d.mts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.global.js +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@ map.on("load", (event) => {
|
|
|
42
42
|
```javascript
|
|
43
43
|
const draw = DrawLibre.getInstance({
|
|
44
44
|
modes: {
|
|
45
|
+
initial: null, // default value; can be "line" or "polygon". Initial mode for drawing
|
|
45
46
|
breakGeometry: { visible: true }, // Controls visibility of the break geometry button
|
|
46
47
|
line: {
|
|
47
48
|
closeGeometry: true, // Enables/disables ability to close a LineString
|
|
@@ -120,7 +121,6 @@ Available events:
|
|
|
120
121
|
- `UNDO`: "mdl:undo" (UndoEvent)
|
|
121
122
|
- `REMOVEALL`: "mdl:removeall" (RemoveAllEvent)
|
|
122
123
|
- `SAVE`: "mdl:save" (SaveEvent)
|
|
123
|
-
- `MODECHANGE`: "mdl:modechange" (ModeChangeEvent)
|
|
124
124
|
|
|
125
125
|
### Methods
|
|
126
126
|
|
package/dist/index.d.mts
CHANGED
|
@@ -20,7 +20,7 @@ declare class Observable<T> {
|
|
|
20
20
|
notify(args: T): void;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
type Mode = "line" | "polygon";
|
|
23
|
+
type Mode = "line" | "polygon" | null;
|
|
24
24
|
|
|
25
25
|
interface EventData {
|
|
26
26
|
STORE_CHANGED: {
|
|
@@ -112,6 +112,7 @@ interface DrawOptions {
|
|
|
112
112
|
buttons?: PanelImpl["buttons"];
|
|
113
113
|
};
|
|
114
114
|
modes?: {
|
|
115
|
+
initial?: Mode;
|
|
115
116
|
line?: {
|
|
116
117
|
visible?: boolean;
|
|
117
118
|
closeGeometry?: boolean;
|
|
@@ -144,7 +145,6 @@ declare const EVENTS: {
|
|
|
144
145
|
readonly BREAK: "mdl:break";
|
|
145
146
|
readonly LINE: "mdl:line";
|
|
146
147
|
readonly POLYGON: "mdl:polygon";
|
|
147
|
-
readonly MODECHANGE: "mdl:modechange";
|
|
148
148
|
};
|
|
149
149
|
|
|
150
150
|
interface BaseEvent {
|
|
@@ -187,6 +187,10 @@ interface PointEnterEvent extends BaseEvent {
|
|
|
187
187
|
interface PointLeaveEvent extends BaseEvent {
|
|
188
188
|
coordinates: LatLng;
|
|
189
189
|
}
|
|
190
|
+
interface ModeChangeEvent {
|
|
191
|
+
timestamp: number;
|
|
192
|
+
mode: ModeEvent;
|
|
193
|
+
}
|
|
190
194
|
|
|
191
195
|
declare class DrawLibre implements IControl {
|
|
192
196
|
#private;
|
|
@@ -254,4 +258,4 @@ declare class DrawLibre implements IControl {
|
|
|
254
258
|
removeAllSteps: () => void;
|
|
255
259
|
}
|
|
256
260
|
|
|
257
|
-
export { EVENTS as DRAW_LIBRE_EVENTS, type PointAddEvent, type PointDoubleClickEvent, type PointEnterEvent, type PointLeaveEvent, type PointMoveEvent, type RemoveAllEvent, type RequiredDrawOptions, type SaveEvent, type UndoEvent, DrawLibre as default };
|
|
261
|
+
export { EVENTS as DRAW_LIBRE_EVENTS, type ModeChangeEvent, type PointAddEvent, type PointDoubleClickEvent, type PointEnterEvent, type PointLeaveEvent, type PointMoveEvent, type RemoveAllEvent, type RequiredDrawOptions, type SaveEvent, type UndoEvent, DrawLibre as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare class Observable<T> {
|
|
|
20
20
|
notify(args: T): void;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
type Mode = "line" | "polygon";
|
|
23
|
+
type Mode = "line" | "polygon" | null;
|
|
24
24
|
|
|
25
25
|
interface EventData {
|
|
26
26
|
STORE_CHANGED: {
|
|
@@ -112,6 +112,7 @@ interface DrawOptions {
|
|
|
112
112
|
buttons?: PanelImpl["buttons"];
|
|
113
113
|
};
|
|
114
114
|
modes?: {
|
|
115
|
+
initial?: Mode;
|
|
115
116
|
line?: {
|
|
116
117
|
visible?: boolean;
|
|
117
118
|
closeGeometry?: boolean;
|
|
@@ -144,7 +145,6 @@ declare const EVENTS: {
|
|
|
144
145
|
readonly BREAK: "mdl:break";
|
|
145
146
|
readonly LINE: "mdl:line";
|
|
146
147
|
readonly POLYGON: "mdl:polygon";
|
|
147
|
-
readonly MODECHANGE: "mdl:modechange";
|
|
148
148
|
};
|
|
149
149
|
|
|
150
150
|
interface BaseEvent {
|
|
@@ -187,6 +187,10 @@ interface PointEnterEvent extends BaseEvent {
|
|
|
187
187
|
interface PointLeaveEvent extends BaseEvent {
|
|
188
188
|
coordinates: LatLng;
|
|
189
189
|
}
|
|
190
|
+
interface ModeChangeEvent {
|
|
191
|
+
timestamp: number;
|
|
192
|
+
mode: ModeEvent;
|
|
193
|
+
}
|
|
190
194
|
|
|
191
195
|
declare class DrawLibre implements IControl {
|
|
192
196
|
#private;
|
|
@@ -254,4 +258,4 @@ declare class DrawLibre implements IControl {
|
|
|
254
258
|
removeAllSteps: () => void;
|
|
255
259
|
}
|
|
256
260
|
|
|
257
|
-
export { EVENTS as DRAW_LIBRE_EVENTS, type PointAddEvent, type PointDoubleClickEvent, type PointEnterEvent, type PointLeaveEvent, type PointMoveEvent, type RemoveAllEvent, type RequiredDrawOptions, type SaveEvent, type UndoEvent, DrawLibre as default };
|
|
261
|
+
export { EVENTS as DRAW_LIBRE_EVENTS, type ModeChangeEvent, type PointAddEvent, type PointDoubleClickEvent, type PointEnterEvent, type PointLeaveEvent, type PointMoveEvent, type RemoveAllEvent, type RequiredDrawOptions, type SaveEvent, type UndoEvent, DrawLibre as default };
|
package/dist/index.global.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var DrawLibre = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var l=class o{static docStyle=typeof window<"u"&&window.document&&window.document.documentElement.style;static transformProp=o.testProp(["transform","WebkitTransform"]);static testProp(e){if(!o.docStyle)return e[0];for(let t=0;t<e.length;t++)if(e[t]in o.docStyle)return e[t];return e[0]}static create(e,t,i){let n=window.document.createElement(e);return t!==void 0&&(n.className=t),i&&i.appendChild(n),n}static remove(e){e.parentNode&&e.parentNode.removeChild(e);}static setTransform(e,t){o.transformProp&&e.style&&(e.style[o.transformProp]=t);}static manageEventListener(e,t,i,n,s={}){if(!t)return;let a=e==="add"?"addEventListener":"removeEventListener";"passive"in s?t[a](i,n,s):t[a](i,n,s.capture);}static mouseButton(e){return e.button}static addClassName(e,t){e.classList.contains(t)||e.classList.add(t);}static removeClassName(e,t){e.classList.contains(t)&&e.classList.remove(t);}};var _=class o{lng;lat;constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,this.lat>90||this.lat<-90)throw new Error("Invalid LngLat latitude value: must be between -90 and 90")}static convert(e){if(e instanceof o)return e;if(Array.isArray(e)&&(e.length===2||e.length===3))return new o(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null)return new o(Number("lng"in e?e.lng:e.lon),Number(e.lat));throw new Error("`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]")}};function F(o,...e){for(let t of e)for(let i in t)o[i]=t[i];return o}function fe(o,e,t){let i=new _(o.lng,o.lat);if(o=new _(o.lng,o.lat),e){let n=new _(o.lng-360,o.lat),s=new _(o.lng+360,o.lat),a=t.locationPoint(o).distSqr(e);t.locationPoint(n).distSqr(e)<a?o=n:t.locationPoint(s).distSqr(e)<a&&(o=s);}for(;Math.abs(o.lng-t.center.lng)>180;){let n=t.locationPoint(o);if(n.x>=0&&n.y>=0&&n.x<=t.width&&n.y<=t.height)break;o.lng>t.center.lng?o.lng-=360:o.lng+=360;}return o.lng!==i.lng&&t.locationPoint(o).y>t.height/2-t.getHorizon()?o:i}var ue={center:"translate(-50%,-50%)",top:"translate(-50%,0)","top-left":"translate(0,0)","top-right":"translate(-100%,0)",bottom:"translate(-50%,-100%)","bottom-left":"translate(0,-100%)","bottom-right":"translate(-100%,-100%)",left:"translate(0,-50%)",right:"translate(-100%,-50%)"};function ve(o,e,t){let i=o.classList;for(let n in ue)i.remove(`maplibregl-${t}-anchor-${n}`);i.add(`maplibregl-${t}-anchor-${e}`);}function Le(o,e,t){t[o]&&t[o].indexOf(e)!==-1||(t[o]=t[o]||[],t[o].push(e));}function de(o,e,t){if(t&&t[o]){let i=t[o].indexOf(e);i!==-1&&t[o].splice(i,1);}}var q=class{_listeners;_oneTimeListeners;_eventedParent;_eventedParentData;on(e,t){return this._listeners=this._listeners||{},Le(e,t,this._listeners),this}off(e,t){return de(e,t,this._listeners),de(e,t,this._oneTimeListeners),this}once(e,t){return t?(this._oneTimeListeners=this._oneTimeListeners||{},Le(e,t,this._oneTimeListeners),this):new Promise(i=>this.once(e,i))}fire(e,t){typeof e=="string"&&(e=new D(e,t||{}));let i=e.type;if(this.listens(i)){e.target=this;let n=this._listeners&&this._listeners[i]?this._listeners[i].slice():[];for(let c of n)c.call(this,e);let s=this._oneTimeListeners&&this._oneTimeListeners[i]?this._oneTimeListeners[i].slice():[];for(let c of s)de(i,c,this._oneTimeListeners),c.call(this,e);let a=this._eventedParent;a&&(F(e,typeof this._eventedParentData=="function"?this._eventedParentData():this._eventedParentData),a.fire(e));}else e instanceof ErrorEvent&&console.error(e.error);return this}listens(e){return this._listeners&&this._listeners[e]&&this._listeners[e].length>0||this._oneTimeListeners&&this._oneTimeListeners[e]&&this._oneTimeListeners[e].length>0||this._eventedParent&&this._eventedParent.listens(e)}setEventedParent(e,t){return this._eventedParent=e,this._eventedParentData=t,this}},D=class{type;constructor(e,t={}){F(this,t),this.type=e;}};var p=class o{x;y;constructor(e,t){this.x=e,this.y=t;}mag(){return Math.sqrt(this.x*this.x+this.y*this.y)}equals(e){return this.x===e.x&&this.y===e.y}dist(e){return Math.sqrt(this.distSqr(e))}distSqr(e){let t=e.x-this.x,i=e.y-this.y;return t*t+i*i}angle(){return Math.atan2(this.y,this.x)}angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)}angleWith(e){return this.angleWithSep(e.x,e.y)}angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)}_matMult(e){let t=e[0]*this.x+e[1]*this.y,i=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=i,this}_add(e){return this.x+=e.x,this.y+=e.y,this}_sub(e){return this.x-=e.x,this.y-=e.y,this}_mult(e){return this.x*=e,this.y*=e,this}_div(e){return this.x/=e,this.y/=e,this}_multByPoint(e){return this.x*=e.x,this.y*=e.y,this}_divByPoint(e){return this.x/=e.x,this.y/=e.y,this}_unit(){return this._div(this.mag()),this}_perp(){let e=this.y;return this.y=this.x,this.x=-e,this}_rotate(e){let t=Math.cos(e),i=Math.sin(e),n=t*this.x-i*this.y,s=i*this.x+t*this.y;return this.x=n,this.y=s,this}_rotateAround(e,t){let i=Math.cos(e),n=Math.sin(e),s=t.x+i*(this.x-t.x)-n*(this.y-t.y),a=t.y+n*(this.x-t.x)+i*(this.y-t.y);return this.x=s,this.y=a,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}static convert(e){if(e instanceof o)return e;if(Array.isArray(e))return new o(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new o(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")}};var Se={closeButton:!0,closeOnClick:!0,focusAfterOpen:!0,className:"",maxWidth:"240px",subpixelPositioning:!1},Oe=["a[href]","[tabindex]:not([tabindex='-1'])","[contenteditable]:not([contenteditable='false'])","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])"].join(", "),z=class extends q{_map;options;_content;_container;_closeButton;_tip;_lngLat;_trackPointer;_pos;_flatPos;constructor(e){super(),this.options=F(Object.create(Se),e);}addTo(e){return this._map&&this.remove(),this._map=e,this.options.closeOnClick&&this._map.on("click",this._onClose),this.options.closeOnMove&&this._map.on("move",this._onClose),this._map.on("remove",this.remove),this._update(),this._focusFirstElement(),this._trackPointer?(this._map.on("mousemove",this._onMouseMove),this._map.on("mouseup",this._onMouseUp),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")):this._map.on("move",this._update),this.fire(new D("open")),this}isOpen(){return !!this._map}remove=()=>(this._content&&l.remove(this._content),this._container&&(l.remove(this._container),delete this._container),this._map&&(this._map.off("move",this._update),this._map.off("move",this._onClose),this._map.off("click",this._onClose),this._map.off("remove",this.remove),this._map.off("mousemove",this._onMouseMove),this._map.off("mouseup",this._onMouseUp),this._map.off("drag",this._onDrag),this._map._canvasContainer.classList.remove("maplibregl-track-pointer"),delete this._map,this.fire(new D("close"))),this);getLngLat(){return this._lngLat}setLngLat(e){return this._lngLat=_.convert(e),this._pos=null,this._flatPos=null,this._trackPointer=!1,this._update(),this._map&&(this._map.on("move",this._update),this._map.off("mousemove",this._onMouseMove),this._container&&this._container.classList.remove("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.remove("maplibregl-track-pointer")),this}trackPointer(){return this._trackPointer=!0,this._pos=null,this._flatPos=null,this._update(),this._map&&(this._map.off("move",this._update),this._map.on("mousemove",this._onMouseMove),this._map.on("drag",this._onDrag),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")),this}getElement(){return this._container}setText(e){return this.setDOMContent(document.createTextNode(e))}setHTML(e){let t=document.createDocumentFragment(),i=document.createElement("body"),n;for(i.innerHTML=e;n=i.firstChild,!!n;)t.appendChild(n);return this.setDOMContent(t)}getMaxWidth(){return this._container?.style.maxWidth}setMaxWidth(e){return this.options.maxWidth=e,this._update(),this}setDOMContent(e){if(this._content)for(;this._content.hasChildNodes();)this._content.firstChild&&this._content.removeChild(this._content.firstChild);else this._content=l.create("div","maplibregl-popup-content",this._container);return this._content.appendChild(e),this._createCloseButton(),this._update(),this._focusFirstElement(),this}addClassName(e){return this._container&&this._container.classList.add(e),this}removeClassName(e){return this._container&&this._container.classList.remove(e),this}setOffset(e){return this.options.offset=e,this._update(),this}toggleClassName(e){if(this._container)return this._container.classList.toggle(e)}setSubpixelPositioning(e){this.options.subpixelPositioning=e;}_createCloseButton(){this.options.closeButton&&(this._closeButton=l.create("button","maplibregl-popup-close-button",this._content),this._closeButton.type="button",this._closeButton.innerHTML="×",this._closeButton.addEventListener("click",this._onClose));}_onMouseUp=e=>{this._update(e.point);};_onMouseMove=e=>{this._update(e.point);};_onDrag=e=>{this._update(e.point);};_update=e=>{let t=this._lngLat||this._trackPointer;if(!this._map||!t||!this._content)return;if(!this._container){if(this._container=l.create("div","maplibregl-popup",this._map.getContainer()),this._tip=l.create("div","maplibregl-popup-tip",this._container),this._container.appendChild(this._content),this.options.className)for(let c of this.options.className.split(" "))this._container.classList.add(c);this._closeButton&&this._closeButton.setAttribute("aria-label",this._map._getUIString("Popup.Close")),this._trackPointer&&this._container.classList.add("maplibregl-popup-track-pointer");}if(this.options.maxWidth&&this._container.style.maxWidth!==this.options.maxWidth&&(this._container.style.maxWidth=this.options.maxWidth),this._map.transform.renderWorldCopies&&!this._trackPointer?this._lngLat=fe(this._lngLat,this._flatPos,this._map.transform):this._lngLat=this._lngLat?.wrap(),this._trackPointer&&!e)return;let i=this._flatPos=this._pos=this._trackPointer&&e?e:this._map.project(this._lngLat);this._map.terrain&&(this._flatPos=this._trackPointer&&e?e:this._map.transform.locationPoint(this._lngLat));let n=this.options.anchor,s=ge(this.options.offset);if(!n){let c=this._container.offsetWidth,v=this._container.offsetHeight,x;i.y+s.bottom.y<v?x=["top"]:i.y>this._map.transform.height-v?x=["bottom"]:x=[],i.x<c/2?x.push("left"):i.x>this._map.transform.width-c/2&&x.push("right"),x.length===0?n="bottom":n=x.join("-");}let a=i.add(s[n]);this.options.subpixelPositioning||(a=a.round()),l.setTransform(this._container,`${ue[n]} translate(${a.x}px,${a.y}px)`),ve(this._container,n,"popup");};_focusFirstElement(){if(!this.options.focusAfterOpen||!this._container)return;let e=this._container.querySelector(Oe);e&&e.focus();}_onClose=()=>{this.remove();}};function ge(o){if(o)if(typeof o=="number"){let e=Math.round(Math.abs(o)/Math.SQRT2);return {center:new p(0,0),top:new p(0,o),"top-left":new p(e,e),"top-right":new p(-e,e),bottom:new p(0,-o),"bottom-left":new p(e,-e),"bottom-right":new p(-e,-e),left:new p(o,0),right:new p(-o,0)}}else if(o instanceof p||Array.isArray(o)){let e=p.convert(o);return {center:e,top:e,"top-left":e,"top-right":e,bottom:e,"bottom-left":e,"bottom-right":e,left:e,right:e}}else return {center:p.convert(o.center||[0,0]),top:p.convert(o.top||[0,0]),"top-left":p.convert(o["top-left"]||[0,0]),"top-right":p.convert(o["top-right"]||[0,0]),bottom:p.convert(o.bottom||[0,0]),"bottom-left":p.convert(o["bottom-left"]||[0,0]),"bottom-right":p.convert(o["bottom-right"]||[0,0]),left:p.convert(o.left||[0,0]),right:p.convert(o.right||[0,0])};else return ge(new p(0,0))}var Y=class{#e;#t;#i;_undoButton;_deleteButton;_saveButton;_container;constructor(e){this.#e=e,this._container=void 0,this.#i=!1,this.#n().then(()=>{this.#o(),e.map.fire("panel:ready");});}#n=async()=>{this.#e;try{this.#t=new z({offset:16,closeButton:!1,closeOnClick:!1,closeOnMove:!1,anchor:"bottom"});}catch(t){console.error("POPUP LOAD ERROR",t);}};#o=()=>{let{store:e}=this.#e;this.createPanel(),e.tail?.val&&this.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng});};setPanelLocation=e=>{let{map:t}=this.#e;this.#i&&(this.#i=!1,this.showPanel()),this._container&&this.#t&&this.#t.setLngLat(e).setDOMContent(this._container).addTo(t);};hidePanel=()=>{!this.#i&&(this.#t?.addClassName("hide-panel"),this.#i=!0);};showPanel=()=>{this.#t?.removeClassName("hide-panel"),this.#i=!1;};onPointRemove=e=>{e?this.setPanelLocation(e):this.hidePanel();};removePanel=()=>{this._container&&l.remove(this._container),this.#t?.remove();};createButton=(e,t,i,n)=>{let s=l.create("button",`panel-button panel-button-${i}`,n);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`icon ${e} icon-${i}`,s),s};createPanel=()=>{let{options:e}=this.#e,{locale:t}=e,{undo:i,delete:n,save:s}=e.panel.buttons,a=e.panel.size,c=document.querySelector(".maplibregl-popup-content"),v=l.create("div","dashboard",c);i.visible&&(this._undoButton=this.createButton("undo",t.undo,a,v)),n.visible&&(this._deleteButton=this.createButton("delete",t.delete,a,v)),s.visible&&(this._saveButton=this.createButton("save",t.save,a,v)),this._container=v;}};var j={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[]}}]},W={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[]}}]},Ee={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}}]},r={LineDynamicLayer:"mdl-line-dynamic-layer",LineLayer:"mdl-line-layer",LineLayerTransparent:"mdl-line-layer-transparent",LineLayerBreak:"mdl-line-break-layer",PolygonLayer:"mdl-polygon-layer",PointsLayer:"mdl-points-layer",SinglePointLayer:"mdl-single-point-layer",FirstPointLayer:"mdl-first-point-layer"},h={LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",LineSource:"mdl-line-source",PolygonSource:"mdl-polygon-source",PointsSource:"mdl-points-source",SinglePointSource:"mdl-single-point-source"},A={large:6.5,default:5.5},V={large:"#FF6464",default:"#666666"},k={"circle-radius":A.default,"circle-color":"#FEFFFE","circle-stroke-color":V.default,"circle-stroke-width":3},T={"circle-radius":A.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},G={"fill-color":"grey","fill-opacity":.4},I={"line-width":3,"line-color":"grey","line-opacity":.7},w={"circle-radius":A.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},B={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},K=o=>[{id:r.SinglePointLayer,source:h.SinglePointSource,type:"circle",paint:o.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:h.PolygonSource,type:"fill",paint:o.layersPaint.polygon,layout:{visibility:"none"}},{id:r.LineDynamicLayer,source:h.LineDynamicSource,type:"line",paint:o.layersPaint.line,layout:{visibility:"none"}},{id:r.LineLayer,source:h.LineSource,type:"line",paint:o.layersPaint.line,layout:{visibility:"visible"}},{id:r.LineLayerTransparent,source:h.LineSource,type:"line",paint:{"line-width":4,"line-color":"transparent"}},{id:r.LineLayerBreak,source:h.LineSourceBreak,type:"line",paint:o.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:h.PointsSource,type:"circle",paint:o.layersPaint.points,filter:["==",["get","isFirst"],!1]},{id:r.FirstPointLayer,source:h.PointsSource,type:"circle",paint:o.layersPaint.firstPoint,filter:["==",["get","isFirst"],!0]}];var L=class{static#e=0;static#t=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",A.large),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",V.large);};static#i=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",A.default),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",V.default);};static togglePointCircleRadius=(e,t)=>{t==="large"?this.#t(e):this.#i(e);};static removeTransparentLine=e=>{e.removeLayer(r.LineLayerTransparent);};static addTransparentLine=(e,t)=>{if(e.getLayer(r.LineLayerTransparent))return;let n=K(t).find(s=>s.id===r.LineLayerTransparent);n&&e.addLayer(n);};static isDoubleClick(){let t=Date.now();return t-this.#e<=400?(this.#e=t,!0):(this.#e=t,!1)}};var m=class{static isFeatureTriggered(e,t){return e.target.queryRenderedFeatures(e.point,{layers:t}).some(n=>t.includes(n.layer.id))}static getPixelCoordinates=(e,t)=>{let{lat:i,lng:n}=t;return e.project([n,i])};static queryPointId=(e,t)=>e.queryRenderedFeatures(t,{layers:[r.PointsLayer,r.FirstPointLayer]})?.[0]?.properties.id},b=class{static#e(e){let t=[],i=e.head,n=new Set;for(;i!==null;){if(n.has(i.val?.id)){e.head&&e.head.val&&t.push([e.head.val.lng,e.head.val.lat]);break}n.add(i.val?.id),i.val&&t.push([i.val.lng,i.val.lat]),i=i.next;}return t}static getAllLines(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}]}}static getLine(e,t){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e,t]}}]}}static getPolygon(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[t]}}]}}static getPoints(e){let t=e.head,i=[],n=new Set;for(;t!==null&&!n.has(t.val?.id);){if(t.val){let s=t.val,a=t.val.id===e.head?.val?.id;i.push({type:"Feature",properties:{id:s.id,lat:s.lat,lng:s.lng,isFirst:a},geometry:{type:"Point",coordinates:[s.lng,s.lat]}});}n.add(t.val?.id),t=t.next;}return {type:"FeatureCollection",features:i}}},u=class o{static getGeometryIndex=(e,t)=>{let i=e.head,n=0;for(;i!==null;){if(i.val?.id===t)return n;n++,i=i.next;}return -1};static isFirstPoint(e){let t=e.target,i=e.point;return !!t.queryRenderedFeatures(i,{layers:[r.FirstPointLayer]}).length}static distance=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2);static checkIfPointIsOnLine=(e,t,i)=>{let s=this.distance(e,t),a=this.distance(e,i),c=this.distance(i,t);return Math.abs(a+c-s)<.1};static isClosedGeometry=e=>e.tail?.next===e.head;static breakGeometry=(e,t)=>{if(!e.head)return;let i=e.head,n=e.tail;do{if(i?.val?.id===t){i!==e.head&&(n.next=i.next,e.head=i,e.tail=n),e.tail.next=null;return}n=i,i=i.next;}while(i!==e.head)};static closeGeometry=(e,t)=>{e.tail&&(e.tail.next=e.head),t.setClosedGeometry(!0);};static canCloseGeometry=e=>e.size>2&&!this.isClosedGeometry(e);static canBreakClosedGeometry=e=>e.size<=2;static switchToLineModeIfCan=e=>{let{mode:t,store:i,tiles:n,map:s}=e;o.canBreakClosedGeometry(i)&&(i.tail&&i.tail.val&&(i.tail.next=null),t.reset(),L.togglePointCircleRadius(s,"default"),n.renderPolygon(j));}},M=()=>{if("crypto"in window&&"randomUUID"in window.crypto)return window.crypto.randomUUID();function o(){return "0123456789abcdef"[Math.floor(Math.random()*16)]}function e(n){let s="";for(let a=0;a<n;a++)s+=o();return s}function t(n){let s=n===0,a=n===4;return s?8:a?12:4}let i=[];for(let n=0;n<5;n++)i.push(e(t(n)));return i.join("-")},C=(o,e)=>{let t,i=!0;function n(){i&&t&&(o(...t),t=null,i=!1,setTimeout(()=>{i=!0,n();},e));}return function(...s){t=s,n();}};var N=class{#e;#t;#i;#n;constructor(e){this.#e=e,this.#o(),this.render();}#o(){this.#s(),this.#r(),this.#a(r.LineLayer,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.FirstPointLayer),this.#a(r.LineLayerTransparent,r.PointsLayer),this.#a(r.PolygonLayer,r.LineLayer);}#s=()=>{let{map:e}=this.#e;Object.values(h).forEach(t=>{e.getSource(t)||e.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});});};#r=()=>{let{map:e,mode:t,options:i}=this.#e;K(i).forEach(a=>{e.getLayer(a.id)||e.addLayer(a);});let s=e.getLayoutProperty(r.PolygonLayer,"visibility")==="none";t.getMode()==="polygon"&&s&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible");};#a=(e,t)=>{let{map:i}=this.#e,n=i.getLayer(e),s=i.getLayer(t);n&&s&&i.moveLayer(e,t);};#c=()=>{let{map:e}=this.#e;Object.values(h).forEach(t=>{e.getSource(t)&&e.removeSource(t);});};#l=()=>{let{map:e}=this.#e;Object.values(r).forEach(t=>{e.getLayer(t)&&e.removeLayer(t);});};removeTiles=()=>{this.#l(),this.#c();};renderPoints=e=>{let{map:t}=this.#e,i=t.getSource(h.PointsSource);i&&i.setData(e);};renderLines=(e,t)=>{let{map:i}=this.#e,n=i.getSource(t);n&&n.setData(e);};renderPolygon=e=>{let{map:t}=this.#e,i=t.getSource(h.PolygonSource);i&&i.setData(e);};render=()=>{let{mode:e,options:t,store:i}=this.#e,n=b.getPoints(i),s=b.getAllLines(i);if(this.#t=n,this.#i=s,this.renderPoints(n),this.renderLines(s,h.LineSource),t.modes.polygon.visible&&e.isPolygon()){let c=b.getPolygon(i);this.#n=c,this.renderPolygon(c);}};#p=(e,t)=>{if(this.#n.features[0].geometry.coordinates[0][e]=[t.lng,t.lat],e===0){let n=this.#n.features[0].geometry.coordinates[0]?.length-1;this.#n.features[0].geometry.coordinates[0][n]=[t.lng,t.lat];}this.renderPolygon(this.#n);};#h=(e,t)=>{let{mode:i}=this.#e;this.#i.features[0].geometry.coordinates[e]=[t.lng,t.lat];let n=e===0;if(this.#i&&i.getClosedGeometry()&&n){let a=this.#i.features[0].geometry.coordinates?.length-1;this.#i.features[0].geometry.coordinates[a]=[t.lng,t.lat];}this.renderLines(this.#i,h.LineSource);};renderOnMouseMove=(e,t)=>{let{mode:i,options:n}=this.#e;this.#t.features[e].geometry.coordinates=[t.lng,t.lat],this.renderPoints(this.#t),this.#h(e,t),n.modes.polygon.visible&&i.isPolygon()&&this.#p(e,t);};resetGeometries=()=>{this.renderPoints(Ee),this.renderLines(W,h.LineSource),this.renderPolygon(j);}};var xe=8,ke=8,S=class{_container;_label;constructor(){this._container=void 0;}create=e=>{let t=l.create("div","popup-container",document.body),i=l.create("span",`popup-text popup-text-${e.placement}`,t);return i.textContent=e.label,this._container=t,this._label=i,this};#e=()=>{!this._label?.classList.value.includes("popup-text-active")&&this._label?.classList.add("popup-text-active");};#t=()=>this._label?{width:this._label.clientWidth,height:this._label.clientHeight}:{width:0,height:0};#i=e=>{let{bottom:t,left:i}=e.target.getBoundingClientRect(),{width:n,height:s}=this.#t();return {x:i-ke-n,y:t-s-2}};#n=e=>{let{bottom:t,left:i,right:n}=e.target.getBoundingClientRect(),{width:s}=this.#t();return {x:(n-i)/2+i-s/2,y:t+xe}};getPosition=(e,t)=>t==="left"?this.#i(e):this.#n(e);setPosition=e=>{let{x:t,y:i}=e;this._container&&(this._container.style.left=`${t}px`,this._container.style.top=`${i}px`),this.#e();};remove=()=>{this._container&&l.remove(this._container);}};var E={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var $=(o,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("add",o,t,i);},Z=(o,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("remove",o,t,i);},Pe=(o,e)=>{let t=e.locale.line,i=e.locale.polygon,n=e.locale.break;return {line:t,polygon:i,break:n}[o]};var J=class{#e;constructor(e){this.#e=e,this.#t();}#t=()=>{this.#e.mode.addObserver(this.#r);};removeConsumers=()=>{this.#e.mode.removeObserver(this.#r);};#i=()=>{let{_line:e,_polygon:t,_break:i}=this.#e.control;e?.classList.remove("control-button-active"),t?.classList.remove("control-button-active"),i?.classList.remove("control-button-active");};#n=e=>{this.#i(),e.classList.add("control-button-active");};#o=e=>{let{data:t}=e,{_line:i,_polygon:n,_break:s}=this.#e.control;if(!(!i||!n||!s))switch(t){case"line":this.#n(i);break;case"polygon":this.#n(n);break;}};#s=e=>{let{data:t}=e,{_break:i}=this.#e.control;t?(i?.removeAttribute("disabled"),i?.removeAttribute("aria-disabled")):(i?.setAttribute("disabled","true"),i?.setAttribute("aria-disabled","true"));};#r=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.#o(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.#s(e),t==="BREAK_CHANGED"&&i){let{_break:n}=this.#e.control;this.#n(n);}}};var X=class{#e;#t;#i;constructor(e){this.#e=e,this.#i=new J(e),this.#t=new S;}initEvents(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&$(e._line,{...t,click:this.onLineClick}),e._polygon&&$(e._polygon,{...t,click:this.onPolygonClick}),e._break&&$(e._break,{...t,click:this.onBreakClick});}}#n(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&Z(e._line,{...t,click:this.onLineClick}),e._polygon&&Z(e._polygon,{...t,click:this.onPolygonClick}),e._break&&Z(e._break,{...t,click:this.onBreakClick});}}remove(){this.#i.removeConsumers(),this.#n(),this.#t.remove();}onButtonEnter=e=>{let{options:t}=this.#e,i=e.target.getAttribute("data-type");if(i){let n=Pe(i,t);this.#t.create({label:n,placement:"left"}).setPosition(this.#t.getPosition(e,"left"));}};onButtonLeave=()=>{this.#t.remove();};onLineClick=()=>{let{mode:e,tiles:t}=this.#e;e.setMode("line"),t.resetGeometries(),t.render();};onPolygonClick=()=>{let{map:e,mode:t,tiles:i}=this.#e;t.setMode("polygon"),t.isPolygon()&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible"),i.resetGeometries(),i.render();};onBreakClick=()=>{let{map:e,mode:t}=this.#e;t.setBreak(!0),e.getCanvasContainer().style.cursor=E.POINTER;}};var O=class{observers;constructor(){this.observers=new Set;}addObserver(e){this.observers.add(e);}removeObserver(e){this.observers.delete(e);}unsubscribe(){this.observers.clear();}notify(e){this.observers.forEach(t=>t(e));}};var R={EMPTY_INITIAL_STATE:"You passed an empty initial array in the options. Please either remove the 'initial' property or include at least one element in the array.",MISSING_IDS:"You set 'generateId' to false but did not provide IDs for all steps. Please ensure all steps have IDs or set 'generateId' to true.",NOT_ENOUGH_POINTS_TO_CLOSE:"At least three points are required to close a polygon or a line. Please add more points or set 'closeGeometry' to false.",FIRST_LAST_POINT_NOT_EQUAL:"The first and last points of a polygon or a closed linestring must be the same. Please ensure the first and last points are equal or set 'closeGeometry' to false."};var Q=class{val;next;constructor(e=null,t=null){this.val=e,this.next=t;}},H=class extends O{head;tail;size;constructor(e){super();let t=P.initStore(e);this.head=t?t.head:null,this.tail=t?t.tail:null,this.size=t?t.size:0;}push(e){let t=new Q(e);this.head?this.tail&&(this.tail.next=t,this.tail=t):this.head=this.tail=t,this.size++,this.pingConsumers();}insert(e,t){let i=new Q(e,t.next);this.tail===t&&this.head===t.next&&(this.tail=i),t.next=i,this.size++;}findStepById(e){let t=this.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.val&&t.val.id===e)return t.val;i.add(t),t=t.next;}return null}removeStepById(e){if(!this.head)return null;let t=this.head,i=null;for(;t!==null;){if(t?.val?.id===e)return t===this.head?(this.head=t.next,this.tail&&(this.tail.next=t.next)):i.next=t.next,t===this.tail&&(this.tail=i),this.size--,this.pingConsumers(),t;i=t,t.next&&(t=t.next);}return null}reset(){this.head=null,this.tail=null,this.size=0,this.pingConsumers();}pingConsumers=()=>{this.notify({type:"STORE_CHANGED",data:{head:this.head,tail:this.tail,size:this.size}});}},P=class o{static isLastPoint=(e,t)=>e.tail?.val?.id===t;static initStore(e){if(!e?.initial)return null;if(e&&e.initial&&!e.initial.steps.length)throw new Error(R.EMPTY_INITIAL_STATE);if(e&&e.initial.steps){let{steps:n,closeGeometry:s,generateId:a}=e.initial;return o.fromArray(n,s,a)}return null}static#e=e=>e.map(t=>({...t,id:M()}));static buildStepSequence(e){let t=new H;return e.forEach(i=>{t.push(i);}),t}static fromArray(e,t,i){let n=i?this.#e(e):e,s=this.buildStepSequence(n);return t&&s.tail&&(s.tail.next=s.head),s}static toArray(e){if(!e)return [];let t=new Set,i=[],n=e;for(;n!==null&&!t.has(n);)t.add(n),i.push(n.val),n=n.next;return i}};var y={DOUBLECLICK:"mdl:doubleclick",POINTENTER:"mdl:pointenter",POINTLEAVE:"mdl:pointleave",MOVEEND:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REMOVEALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",LINE:"mdl:line",POLYGON:"mdl:polygon",MODECHANGE:"mdl:modechange"};var d={panel:{size:"medium",buttons:{undo:{visible:!0},delete:{visible:!0},save:{visible:!0,clearOnSave:!0}}},modes:{line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{onLinePoint:T,firstPoint:k,points:w,line:I,polygon:G,breakLine:B},initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close line",createPolygon:"Create polygon"}};var f=class{static addPoint(e,t,i){t.fire(y.ADD,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static movePoint(e,t){t.fire(y.MOVEEND,{id:e.id,start_coordinates:{lat:e.start.lat,lng:e.start.lng},end_coordinates:{lat:e.end.lat,lng:e.end.lng},total:e.total,timestamp:Date.now()});}static pointDoubleClick(e,t){t.fire(y.DOUBLECLICK,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){t.fire(y.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){t.fire(y.POINTLEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undoPoint(e,t,i){t.fire(y.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static removeAllPoints(e,t){e.fire(y.REMOVEALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:n,mode:s}=e;n.fire(y.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onModeChange(e){let{map:t,mode:i}=e;t.fire(y.MODECHANGE,{timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static onLineBreak(e){e.fire(y.BREAK);}};var ee=class{#e;#t;constructor(e){this.#e=e,this.#t=new S;}initEvents(){let{panel:e}=this.#e;e&&(l.manageEventListener("add",e?._undoButton,"click",this.#o),l.manageEventListener("add",e?._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._undoButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._deleteButton,"click",this.#n),l.manageEventListener("add",e?._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._deleteButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._saveButton,"click",this.onSaveClick),l.manageEventListener("add",e?._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._saveButton,"mouseleave",this.onMouseLeave));}removeEvents(){let{panel:e}=this.#e;e&&e._undoButton&&(l.manageEventListener("remove",e._undoButton,"click",this.#o),l.manageEventListener("remove",e._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._undoButton,"mouseleave",this.onMouseLeave)),e&&e._deleteButton&&(l.manageEventListener("remove",e._deleteButton,"click",this.#n),l.manageEventListener("remove",e._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._deleteButton,"mouseleave",this.onMouseLeave)),e&&e._saveButton&&(l.manageEventListener("remove",e._saveButton,"click",this.onSaveClick),l.manageEventListener("remove",e._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._saveButton,"mouseleave",this.onMouseLeave));}#i=e=>{let{options:t}=this.#e;return {undo:t.locale.undo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let t=e.target.getAttribute("data-type");if(t){let i=this.#i(t);this.#t.create({label:i,placement:"bottom"}).setPosition(this.#t.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.#t.remove();};#n=e=>{let{tiles:t,mode:i,panel:n,store:s,map:a}=this.#e;s.reset(),n.hidePanel(),i.reset(),L.togglePointCircleRadius(a,"default"),this.#t.remove(),t.resetGeometries(),f.removeAllPoints(a,e);};#o=e=>{let{store:t,panel:i,map:n,tiles:s}=this.#e,a=t.tail?.val;t.removeStepById(a.id);let c={...a,total:t.size};f.undoPoint(c,n,e),u.switchToLineModeIfCan(this.#e),i?.onPointRemove(t.tail?.val),this.#t.remove(),requestAnimationFrame(s.render);};onSaveClick=e=>{let{store:t,options:i}=this.#e;f.onSaveClick(this.#e,P.toArray(t.head),e),this.#t.remove(),i.panel.buttons.save.clearOnSave&&this.#n(e);}};var g=class{static updatePointsData(e){let i=e.target.getSource(h.SinglePointSource);i&&i.setData({type:"Feature",geometry:{type:"Point",coordinates:[e.lngLat.lng,e.lngLat.lat]},properties:{}});}static setSinglePointVisible(e){e.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");}static setSinglePointHidden(e){let t=e.target;setTimeout(()=>{t.setLayoutProperty(r.SinglePointLayer,"visibility","none");},33);}static triggerPostPointAddition(e,t){let{panel:i,tiles:n,store:s,map:a}=t;u.canCloseGeometry(s)&&L.togglePointCircleRadius(a,"large"),i?.setPanelLocation(e.lngLat),n.render();}static addPointToMap=(e,t)=>{let{store:i,map:n,mode:s}=t,a={...e.lngLat,id:M()};i.push(a),f.addPoint({...a,total:i.size},n,s),this.triggerPostPointAddition(e,t);};static updateSelectedStepLatLng=(e,t)=>{t.lat=e.lngLat.lat,t.lng=e.lngLat.lng;}};var me=(o,e)=>{let t=e.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.next&&t.next.val&&t.val){let n=o.target,s=m.getPixelCoordinates(n,t.val),a=m.getPixelCoordinates(n,t.next.val),c=m.getPixelCoordinates(n,o.lngLat);if(u.checkIfPointIsOnLine(s,a,c))return t}i.add(t),t=t.next;}return null},be=(o,e)=>{let t=me(o,e);if(t){let i={...o.lngLat,id:M()};return e.insert(i,t),i}return null},Me=(o,e)=>{let{store:t,tiles:i,panel:n}=e;t.tail?.val&&(n?.setPanelLocation(t.tail.val),g.setSinglePointHidden(o),i.render());},_e=o=>m.isFeatureTriggered(o,[r.PointsLayer,r.FirstPointLayer]);var Ce=15,te=class{props;#e;#t;constructor(e){this.props=e,this.#e=null,this.#t=C(this.#n,Ce);}initBreakEvents=()=>{let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mouseenter",r.LineLayerTransparent,this.#t),e.on("mousemove",r.LineLayerTransparent,this.#t),e.on("mouseleave",r.LineLayerTransparent,this.#o);};removeBreakEvents=()=>{let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mouseenter",r.LineLayerTransparent,this.#t),e.off("mousemove",r.LineLayerTransparent,this.#t),e.off("mouseleave",r.LineLayerTransparent,this.#o);};hideBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};#i=()=>{let{store:e,mode:t,panel:i,map:n,tiles:s}=this.props,a=this.#e?.next?.val?.id;u.breakGeometry(e,a),e.tail?.val&&i.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng}),this.#o(),n.setLayoutProperty(r.PolygonLayer,"visibility","none"),t.reset(),s.render(),f.onLineBreak(n);};#n=e=>{let{map:t,store:i}=this.props,n=me(e,i);n?.val?.id!==this.#e?.val?.id&&(this.#e=n);let s=t.getSource(h.LineSourceBreak),a=[n?.val?.lng,n?.val?.lat],c=[n?.next?.val?.lng,n?.next?.val?.lat],v=b.getLine(a,c);v&&(s.setData(v),this.showBreakLine());};#o=()=>{setTimeout(()=>{this.hideBreakLine();},Ce+10);}};var Te=10,ie=class{#e;#t;#i;#n;#o;#s;constructor(e){this.#e=e,this.#t=e.options.dynamicLine,this.#i=null,this.#n=null,this.#r(),this.#s=C(this.#h,Te);}#r(){this.#e.store.addObserver(this.#c),this.#e.mode.addObserver(this.#l),this.#e.mouseEvents.addObserver(this.#a);}removeConsumers=()=>{this.#e.store.removeObserver(this.#c),this.#e.mode.removeObserver(this.#l),this.#e.mouseEvents.removeObserver(this.#a);};#a=e=>{let{mode:t}=this.#e;if(!t.getClosedGeometry()&&(e.type==="lastPointMouseClick"&&e.data?(this.hideDynamicLine(),this.#t=!1):e.type==="lastPointMouseClick"&&!e.data&&(this.#t=!0),!!this.#t&&((e.type==="pointMouseEnter"||e.type==="lineMouseEnter")&&e.data&&this.hideDynamicLine(),(e.type==="pointMouseLeave"||e.type==="lineMouseLeave")&&e.data))){let{store:i}=this.#e;this.#i=i.tail?.val,this.#n=i.tail?.val,this.showDynamicLine();}};#c=e=>{let{store:t}=this.#e;switch(e.type){case"STORE_CHANGED":e.data.tail?.val&&!u.isClosedGeometry(t)&&(this.#i=e.data.tail?.val,this.showDynamicLine());break;}};#l=e=>{let{store:t}=this.#e;e.type==="CLOSED_GEOMETRY_CHANGED"&&(e.data&&this.hideDynamicLine(),!e.data&&t?.tail?.val&&(this.#i=t?.tail?.val,this.showDynamicLine()));};initDynamicEvents=()=>{let{map:e}=this.#e;e.on("click",this.#f),e.on("mousemove",this.#s),e.on(y.REMOVEALL,this.hideDynamicLine),e.on(y.UNDO,this.#m),e.on(y.DOUBLECLICK,this.#v);};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#f),e.off("mousemove",this.#s),e.off(y.REMOVEALL,this.hideDynamicLine),e.off(y.UNDO,this.#m),e.off(y.DOUBLECLICK,this.#v);};hideDynamicLine=()=>{let{map:e,tiles:t}=this.#e;this.#i=null,this.#n=null,this.#o=null,e.off("mousemove",this.#s),t.renderLines(W,h.LineDynamicSource),e.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};showDynamicLine=()=>{let{map:e}=this.#e,t=[this.#i?.lng,this.#i?.lat],i=[this.#n?.lng,this.#n?.lat];this.#o=b.getLine(t,i),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.#n&&this.#p({lng:this.#n?.lng,lat:this.#n?.lat}),e.on("mousemove",this.#s);};#p=e=>{if(!this.#o)return;let{tiles:t}=this.#e;this.#o.features[0].geometry.coordinates[1]=[e.lng,e.lat],t.renderLines(this.#o,h.LineDynamicSource);};#h=e=>{this.#p(e.lngLat);};#f=e=>{let{mode:t}=this.#e,i=m.isFeatureTriggered(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.#n={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hideDynamicLine();};#m=e=>{let{store:t,mode:i}=this.#e;if(!i.getClosedGeometry()){let n=e.target.unproject({x:e.originalEvent.x,y:e.originalEvent.y});this.#n={lng:n.lng,lat:n.lat},this.#i=t.tail?.val,this.showDynamicLine();}};#v=e=>{let{store:t,mode:i}=this.#e;i.getClosedGeometry()||(this.#n={lng:e.coordinates.lng,lat:e.coordinates.lat},this.#i=t.tail?.val,this.showDynamicLine());}};var we=22,ne=class{props;#e;#t;constructor(e){this.props=e,this.#e=!1,this.#t=null;}initEvents(){let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mousemove",r.LineLayerTransparent,this.#o),e.on("mouseenter",r.LineLayerTransparent,this.#s),e.on("mouseleave",r.LineLayerTransparent,this.#r);}removeEvents(){let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mousemove",r.LineLayerTransparent,this.#o),e.off("mouseenter",r.LineLayerTransparent,this.#s),e.off("mouseleave",r.LineLayerTransparent,this.#r);}#i=e=>{let{store:t,map:i,mode:n}=this.props;if(_e(e))return;let s=be(e,t);s&&(f.addPoint({...s,total:t.size},i,n),Me(e,this.props));};#n=e=>{g.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)&&g.updatePointsData(e);};#o=C(e=>{if(m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer]))return;let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(this.#t=e,!this.#e&&(this.#e=!0,requestAnimationFrame(()=>{this.#t&&(this.#n(this.#t),this.#e=!1);})));},we);#s=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer])||(t.lineMouseEnter=!0,g.setSinglePointVisible(e));};#r=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(t.lineMouseLeave=!0,g.setSinglePointHidden(e));}};var oe=class{props;#e;#t;#i;#n;constructor(e){this.props=e,this.#e=new te(e),this.#t=new ne(e),this.#i=null,this.#n="default",this.#o(),this.#s(),this.#r();}#o=()=>{window.innerWidth<=768||this.props.options.dynamicLine&&(this.#i=new ie(this.props));};#s(){!this.props.mode.getBreak()&&(this.#t.initEvents(),this.props.options.dynamicLine&&this.#i?.initDynamicEvents());}#r(){this.props.mode.addObserver(this.#p),this.props.mouseEvents.addObserver(this.#l);}remove(){this.#a(),this.#c();}#a(){this.props.mode.removeObserver(this.#p),this.props.mouseEvents.removeObserver(this.#l),this.props.options.dynamicLine&&this.#i?.removeConsumers();}#c(){this.#e.removeBreakEvents(),this.#t.removeEvents(),this.props.options.dynamicLine&&this.#i?.removeEvents();}#l=e=>{let{type:t,data:i}=e,{mode:n}=this.props;if(!(!i||!n.getBreak()))switch(t){case"pointMouseDown":this.#e.removeBreakEvents(),this.#e.hideBreakLine();break;case"pointMouseUp":this.#e.initBreakEvents();break;}};#p=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.#n==="break"&&(this.#e.removeBreakEvents(),this.#t.initEvents(),this.#n="default"),t==="BREAK_CHANGED"&&i&&this.#n==="default"&&(this.#t.removeEvents(),this.#e.initBreakEvents(),this.#n="break");}};var se=class{#e;#t;#i;constructor(e){this.#t=e,this.#e=!1,this.#i=new S,e.mode.addObserver(this.#n);}initEvents(){let{map:e}=this.#t;e.on("click",r.FirstPointLayer,this.#o),e.on("mouseenter",r.FirstPointLayer,this.#l),e.on("mouseleave",r.FirstPointLayer,this.#a),e.on("mouseup",r.FirstPointLayer,this.#r),e.on("mousedown",r.FirstPointLayer,this.#s);}removeEvents(){let{map:e}=this.#t;e.off("click",r.FirstPointLayer,this.#o),e.off("mouseenter",r.FirstPointLayer,this.#l),e.off("mouseleave",r.FirstPointLayer,this.#a),e.off("mouseup",r.FirstPointLayer,this.#r);}#n=e=>{let{map:t,store:i}=this.#t,{type:n,data:s}=e;n==="MODE_CHANGED"&&(s==="line"||s==="polygon"?t.on("click",r.FirstPointLayer,this.#o):t.off("click",r.FirstPointLayer,this.#o),u.canCloseGeometry(i)&&L.togglePointCircleRadius(t,"large"));};#o=()=>{let{store:e,map:t,mode:i,tiles:n}=this.#t;if(i.getMode()==="polygon"&&t.setLayoutProperty(r.PolygonLayer,"visibility","visible"),u.canCloseGeometry(e)){u.closeGeometry(e,i);let s=Object.assign({},e.head?.val,{id:M(),total:e.size});f.addPoint(s,t,i),L.togglePointCircleRadius(t,"default"),n.render();}};#s=()=>{this.#e=!0,this.#i.remove();};#r=()=>{this.#e=!1;};#a=()=>{let{mouseEvents:e}=this.#t;this.#e||(e.firstPointMouseLeave=!0,this.#i.remove());};#c=()=>{let{mode:e,options:t}=this.#t;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};#l=e=>{let{mode:t,mouseEvents:i,store:n}=this.#t;if(!(t.getClosedGeometry()||this.#e)&&(i.firstPointMouseEnter=!0,u.canCloseGeometry(n))){let{x:s,y:a}=e.originalEvent;if(s&&a){this.#i.create({label:this.#c(),placement:"bottom"});let v=this.#i._label?this.#i._label.clientWidth/2:0;this.#i.setPosition({x:s-v,y:a+14});}}}};var re=class{#e;#t;#i;#n;#o;#s;#r;#a;constructor(e){this.#e=e,this.#t=void 0,this.#i=null,this.#n=null,this.#o=null,this.#s=new se(e),this.#r=!1,this.#a=null;}#c=()=>{let{map:e}=this.#e;e.on("click",r.FirstPointLayer,this.#h),e.on("mouseenter",r.FirstPointLayer,this.#L),e.on("mouseleave",r.FirstPointLayer,this.#g),e.on("mousedown",r.FirstPointLayer,this.#d),e.on("mouseup",r.FirstPointLayer,this.#u),e.on("touchend",r.FirstPointLayer,this.#u),e.on("touchstart",r.FirstPointLayer,this.#d),this.#s.initEvents();};initEvents=()=>{let{map:e}=this.#e;e.on("click",this.#m),e.on("dblclick",this.#p),e.on("click",r.PointsLayer,this.#h),e.on("mouseenter",r.PointsLayer,this.#L),e.on("mouseleave",r.PointsLayer,this.#g),e.on("mousedown",r.PointsLayer,this.#d),e.on("mouseup",r.PointsLayer,this.#u),e.on("touchend",r.PointsLayer,this.#u),e.on("touchstart",r.PointsLayer,this.#d),this.#c();};#l=()=>{let{map:e}=this.#e;e.off("click",r.FirstPointLayer,this.#h),e.off("mouseenter",r.FirstPointLayer,this.#L),e.off("mouseleave",r.FirstPointLayer,this.#g),e.off("mousedown",r.FirstPointLayer,this.#d),e.off("mouseup",r.FirstPointLayer,this.#u),e.off("touchend",r.PointsLayer,this.#u),e.off("touchstart",r.PointsLayer,this.#d),this.#s.removeEvents();};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#m),e.off("dblclick",this.#p),e.off("mousemove",this.#y),e.off("click",r.PointsLayer,this.#h),e.off("mouseenter",r.PointsLayer,this.#L),e.off("mouseleave",r.PointsLayer,this.#g),e.off("mousedown",r.PointsLayer,this.#d),e.off("mouseup",r.PointsLayer,this.#u),this.#l();};#p=e=>{e.preventDefault();};#h=e=>{let{store:t,tiles:i,panel:n,map:s,mouseEvents:a}=this.#e;L.isDoubleClick()&&this.#n&&(t.removeStepById(this.#n.id),n.onPointRemove(t.tail?.val),f.pointDoubleClick({...this.#n,total:t.size},this.#e.map),u.switchToLineModeIfCan(this.#e));let c=m.queryPointId(s,e.point);P.isLastPoint(t,c)&&(a.lastPointMouseClick=!0,a.lastPointMouseUp=!1),i.render();};#f=e=>m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer,r.LineLayerTransparent,r.LineLayerBreak]);#m=e=>{let{mode:t,mouseEvents:i,map:n}=this.#e;t.getClosedGeometry()||this.#f(e)||(i.lastPointMouseClick&&(i.lastPointMouseClick=!1),n.getCanvasContainer().style.cursor="grab",g.addPointToMap(e,this.#e),g.setSinglePointHidden(e));};#v=e=>{e.originalEvent.buttons===0&&this.#u();};#E=e=>{let{tiles:t}=this.#e;t.renderOnMouseMove(this.#o,e.lngLat);};#y=C(e=>{this.#a=e,this.#r||(this.#r=!0,requestAnimationFrame(()=>{!this.#n||!this.#a||(g.updateSelectedStepLatLng(this.#a,this.#n),this.#v(this.#a),this.#E(this.#a),this.#r=!1);}));},15);#L=e=>{let{mouseEvents:t,map:i,store:n}=this.#e;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;g.setSinglePointHidden(e);let s=m.queryPointId(i,e.point);P.isLastPoint(n,s)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let a=n.findStepById(s);a&&(this.#i=a,f.enterPoint(Object.assign({},a,{total:n.size}),i));};#g=e=>{let{mouseEvents:t,store:i,map:n}=this.#e;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let s=m.queryPointId(n,e.point);P.isLastPoint(i,s)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),f.leavePoint(Object.assign({},this.#i,{total:i.size}),n);};#P=()=>{let{store:e,panel:t}=this.#e;this.#n&&P.isLastPoint(e,this.#n.id)&&t.hidePanel();};#b=e=>{let{store:t,map:i}=this.#e,n=m.queryPointId(i,e.point),s=t.findStepById(n);s&&(this.#n=s);};#d=e=>{e.preventDefault();let{mouseEvents:t,map:i,store:n}=this.#e;L.removeTransparentLine(i),this.#b(e),this.#P();let s=m.queryPointId(i,e.point);this.#o=u.getGeometryIndex(n,s),t&&(t.pointMouseDown=!0),this.#t=e.lngLat,i.on("mousemove",this.#y),i.on("touchmove",this.#y);};#u=()=>{let{mouseEvents:e,store:t,panel:i,map:n,options:s}=this.#e;e.pointMouseUp=!0,this.#n&&(P.isLastPoint(t,this.#n.id)&&t.tail?.val&&i?.setPanelLocation(t.tail.val),i?.showPanel(),f.movePoint({id:this.#n.id,total:t.size,end:{lat:this.#n.lat,lng:this.#n.lng},start:this.#t},n)),e&&(e.pointMouseDown=!1),L.addTransparentLine(n,s),n.off("mousemove",this.#y),n.off("touchmove",this.#y);}};var ae=class extends N{#e;#t;#i;#n;#o;constructor(e){super({...e}),this.#e=e,this.#t=new ee(e),this.#i=new X(e),this.#n=new re(e),this.#o=new oe(e),e.map.on("panel:ready",this.#s);}#s=()=>{this.#t?.initEvents(),this.#i?.initEvents(),this.#n?.initEvents();};removeMapEventsAndConsumers=()=>{this.#t?.removeEvents(),this.#n?.removeEvents(),this.#i?.remove(),this.#o?.remove(),this.#e.map.off("panel:ready",this.#s);}};var le=class{#e;_line;_polygon;_break;_container;constructor(e){this.#e=e.options,this._line=void 0,this._polygon=void 0,this._break=void 0,this._container=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl(e);}createControlButton=(e,t,i,n)=>{let s=this.#e.panel.size,a=l.create("button",`control-button control-button-${s}`,this._container);return a.setAttribute("aria-label",t),a.setAttribute("data-type",e),i&&a.classList.add("control-button-active"),n&&(a.setAttribute("disabled","true"),a.setAttribute("aria-disabled","true")),l.create("span",`icon ${e} icon-${s}`,a),a};#t=e=>{let{mode:t,options:i}=e,n=this.#e.modes.line.visible,s=i.locale.line;if(n){let a=t.getMode()==="line";this._line=this.createControlButton("line",s,a);}};#i=e=>{let{mode:t,options:i}=e,n=this.#e.modes.polygon.visible,s=i.locale.polygon;n&&(this._polygon=this.createControlButton("polygon",s,t.isPolygon()));};#n=e=>{let{mode:t,options:i}=e,n=this.#e.modes.breakGeometry.visible,s=i.locale.break;if(n){let c=!this.#e?.initial?.closeGeometry,v=t.getBreak();this._break=this.createControlButton("break",s,v,c);}};createControl=e=>{this.#t(e),this.#i(e),this.#n(e);};getContainer=()=>this._container};var ce=class extends O{#e;#t;#i;constructor(e){super(),this.#e=e.initial?.geometry??"line",this.#t=!1,this.#i=e.initial?.closeGeometry??!1;}getMode=()=>this.#e;setMode=e=>{this.#e=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.#t;setBreak=e=>{this.#t=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.#i;setClosedGeometry=e=>{this.#i=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.#i});};isPolygon=()=>this.#e.includes("polygon")&&this.#i;reset=()=>{this.setMode(this.getMode()),this.setClosedGeometry(!1);};pingConsumers=()=>{this.notify({type:"MODE_CHANGED",data:this.getMode()}),this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.getClosedGeometry()});}};var pe=class{#e;#t;constructor(e){this.#e=e,this.#t=this.#e.map.getCanvasContainer(),this.#t.style.cursor=E.CROSSHAIR,this.#i();}set=e=>{this.#t.style.cursor=e;};get=()=>this.#t.style.cursor;handleMouseLeave=()=>{let{mouseEvents:e,mode:t}=this.#e;e.pointMouseDown||(t.getClosedGeometry()?this.set(E.AUTO):this.set(E.CROSSHAIR));};handleFirstPointMouseEnter=()=>{let{mode:e,store:t}=this.#e;e.getClosedGeometry()&&this.set(E.MOVE),u.canCloseGeometry(t)&&this.set(E.POINTER);};#i(){let{mouseEvents:e}=this.#e;e.addObserver(this.#n);}removeConsumers(){let{mouseEvents:e}=this.#e;e.removeObserver(this.#n);}#n=e=>{let{mode:t,mouseEvents:i}=this.#e;if(t.getBreak())return;let{type:n,data:s}=e;if(s)switch(n){case"pointMouseDown":this.set(E.GRABBING);break;case"pointMouseUp":this.set(E.GRAB);break;case"pointMouseEnter":if(i.pointMouseDown)return;this.set(E.GRAB);break;case"pointMouseLeave":this.handleMouseLeave();break;case"lineMouseEnter":if(i.pointMouseDown)return;this.set(E.POINTER);break;case"lineMouseLeave":this.handleMouseLeave();break;case"firstPointMouseEnter":this.handleFirstPointMouseEnter();break;case"firstPointMouseLeave":this.handleMouseLeave();break;case"lastPointMouseEnter":this.set(E.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var he=class extends O{#e;#t;#i;#n;#o;#s;#r;#a;#c;#l;#p;#h;constructor(){super(),this.#e=!1,this.#t=!1,this.#i=!1,this.#n=!1,this.#o=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#c=!1,this.#l=!1,this.#p=!1,this.#h=!1;}get firstPointMouseEnter(){return this.#e}set firstPointMouseEnter(e){this.#e=e,this.notify({type:"firstPointMouseEnter",data:e});}get firstPointMouseLeave(){return this.#t}set firstPointMouseLeave(e){this.#t=e,this.notify({type:"firstPointMouseLeave",data:e});}get lastPointMouseClick(){return this.#i}set lastPointMouseClick(e){this.#i=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#n}set lastPointMouseUp(e){this.#n=e,this.notify({type:"lastPointMouseUp",data:e});}get lastPointMouseEnter(){return this.#o}set lastPointMouseEnter(e){this.#o=e,this.notify({type:"lastPointMouseEnter",data:e});}get lastPointMouseLeave(){return this.#s}set lastPointMouseLeave(e){this.#s=e,this.notify({type:"lastPointMouseLeave",data:e});}get pointMouseDown(){return this.#r}set pointMouseDown(e){this.#r=e,this.notify({type:"pointMouseDown",data:e});}get pointMouseUp(){return this.#a}set pointMouseUp(e){this.#a=e,this.notify({type:"pointMouseUp",data:e});}get pointMouseEnter(){return this.#c}set pointMouseEnter(e){this.#c=e,this.notify({type:"pointMouseEnter",data:e});}get pointMouseLeave(){return this.#l}set pointMouseLeave(e){this.#l=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#p}set lineMouseEnter(e){this.#p=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#h}set lineMouseLeave(e){this.#h=e,this.notify({type:"lineMouseLeave",data:e});}};var U=class{static allStepsHaveIds(e){return e.every(t=>"id"in t&&t.id!==void 0)}static checkIfMissingIds(e,t){let i=!t,n=!this.allStepsHaveIds(e);if(i&&n)throw new Error(R.MISSING_IDS)}static checkIfEnoughPointsToClose(e,t){if(t&&e.length<3)throw new Error(R.NOT_ENOUGH_POINTS_TO_CLOSE)}static checkIfPolygonIsClosed(e){let{closeGeometry:t,steps:i}=e;if(i){let n=i[0]?.lng,s=i[i.length-1]?.lng,a=i[0]?.lat,c=i[i.length-1]?.lat;if((n!==s||a!==c)&&t)throw new Error(R.FIRST_LAST_POINT_NOT_EQUAL)}}static checkInitialStepsOption(e){let{closeGeometry:t,generateId:i,steps:n}=e;this.checkIfMissingIds(n,i),this.checkIfEnoughPointsToClose(n,t),this.checkIfPolygonIsClosed(e);}static init(e){return e?{panel:De(e),modes:Ae(e),layersPaint:Ie(e),initial:e.initial||d.initial,locale:Be(e),dynamicLine:e.dynamicLine??d.dynamicLine}:d}};function De(o){return {size:o.panel?.size||d.panel.size,buttons:{undo:{visible:o.panel?.buttons?.undo?.visible??d.panel.buttons.undo.visible},delete:{visible:o.panel?.buttons?.delete?.visible??d.panel.buttons.delete.visible},save:{visible:o.panel?.buttons?.save?.visible??d.panel.buttons.save.visible,clearOnSave:o.panel?.buttons?.save?.clearOnSave??d.panel.buttons.save.clearOnSave}}}}function Ae(o){return {line:{visible:o?.modes?.line?.visible||o?.initial?.geometry==="line"||d.modes.line.visible,closeGeometry:o?.modes?.line?.closeGeometry||o?.initial?.closeGeometry||d.modes.line.closeGeometry},polygon:{visible:o?.modes?.polygon?.visible||o?.initial?.geometry==="polygon"||d.modes.polygon.visible},breakGeometry:{visible:o?.modes?.breakGeometry?.visible??d.modes.breakGeometry.visible}}}function Ie(o){return {onLinePoint:{"circle-radius":o.layersPaint?.onLinePoint?.["circle-radius"]||T["circle-radius"],"circle-color":o.layersPaint?.onLinePoint?.["circle-color"]||T["circle-color"],"circle-stroke-color":o.layersPaint?.onLinePoint?.["circle-stroke-color"]||T["circle-stroke-color"],"circle-stroke-width":o.layersPaint?.onLinePoint?.["circle-stroke-width"]||T["circle-stroke-width"],...o.layersPaint?.onLinePoint},firstPoint:{"circle-radius":o.layersPaint?.firstPoint?.["circle-radius"]||k["circle-radius"],"circle-color":o.layersPaint?.firstPoint?.["circle-color"]||k["circle-color"],"circle-stroke-color":o.layersPaint?.firstPoint?.["circle-stroke-color"]||k["circle-stroke-color"],"circle-stroke-width":o.layersPaint?.firstPoint?.["circle-stroke-width"]||k["circle-stroke-width"],...o.layersPaint?.firstPoint},points:{"circle-radius":o.layersPaint?.points?.["circle-radius"]||w["circle-radius"],"circle-color":o.layersPaint?.points?.["circle-color"]||w["circle-color"],"circle-stroke-color":o.layersPaint?.points?.["circle-stroke-color"]||w["circle-stroke-color"],"circle-stroke-width":o.layersPaint?.points?.["circle-stroke-width"]||w["circle-stroke-width"],...o.layersPaint?.points},line:{"line-width":o.layersPaint?.line?.["line-width"]||I["line-width"],"line-color":o.layersPaint?.line?.["line-color"]||I["line-color"],"line-opacity":o.layersPaint?.line?.["line-opacity"]||I["line-opacity"],...o.layersPaint?.line},polygon:{"fill-color":o.layersPaint?.polygon?.["fill-color"]||G["fill-color"],"fill-opacity":o.layersPaint?.polygon?.["fill-opacity"]||G["fill-opacity"],...o.layersPaint?.polygon},breakLine:{"line-width":o.layersPaint?.breakLine?.["line-width"]||B["line-width"],"line-color":o.layersPaint?.breakLine?.["line-color"]||B["line-color"],"line-dasharray":o.layersPaint?.breakLine?.["line-dasharray"]||B["line-dasharray"],...o.layersPaint?.breakLine}}}function Be(o){return {save:o.locale?.save??d.locale.save,delete:o.locale?.delete??d.locale.delete,undo:o.locale?.undo??d.locale.undo,line:o.locale?.line??d.locale.line,polygon:o.locale?.polygon??d.locale.polygon,break:o.locale?.break??d.locale.break,closeLine:o.locale?.closeLine??d.locale.closeLine,createPolygon:o.locale?.createPolygon??d.locale.createPolygon}}var ye=class o{#e;#t;#i;#n;#o;#s;#r;#a;#c;static#l=null;static#p=!1;constructor(e){if(this.#n=U.init(e),this.#n.initial&&U.checkInitialStepsOption(this.#n.initial),o.#p)throw new Error("Use 'DrawLibre.getInstance()' instead of 'new DrawLibre()'.");o.#p=!0,this.#t=void 0,this.#i=void 0,this.#o=void 0,this.#s=void 0,this.#r=void 0,this.#c=void 0,this.#a=void 0;}static getInstance(e){return o.#l||(o.#l=new o(e)),o.#l}onAdd(e){this.#t=new H(this.#n),this.#r=new Y({map:e,options:this.#n,store:this.#t}),this.#i=new ce(this.#n),this.#s=new N({map:e,store:this.#t,options:this.#n,mode:this.#i});let t=new le({options:this.#n,mode:this.#i});return this.#c=new he,this.#a=new pe({map:e,mode:this.#i,mouseEvents:this.#c,store:this.#t}),this.#o=new ae({map:e,store:this.#t,options:this.#n,panel:this.#r,control:t,mode:this.#i,tiles:this.#s,mouseEvents:this.#c}),this.#i.pingConsumers(),this.#e=t.getContainer(),this.#e}onRemove(){this.#a?.removeConsumers(),this.#s?.removeTiles(),this.#o?.removeMapEventsAndConsumers(),this.#r?.removePanel(),this.#t?.reset(),this.#i?.unsubscribe(),this.#e&&l.remove(this.#e);}setSteps=e=>{if(Array.isArray(e))e.forEach(t=>{let i={...t,id:t.id||M()};this.#t?.push(i);});else throw new Error("Invalid argument. Expected an array of steps.");this.#s?.render();};findStepById=e=>this.#t?.findStepById(e);getAllSteps=(e="array")=>{if(e==="array"&&this.#t)return P.toArray(this.#t.head);if(e==="linkedlist")return this.#t;throw new Error("Invalid type specified. Use 'array' or 'linkedlist'.")};setOptions=e=>{this.#n=e(this.#n);};removeAllSteps=()=>{this.#t?.reset(),this.#r?.removePanel(),this.#s?.render();}};
|
|
4
|
+
var l=class n{static docStyle=typeof window<"u"&&window.document&&window.document.documentElement.style;static transformProp=n.testProp(["transform","WebkitTransform"]);static testProp(e){if(!n.docStyle)return e[0];for(let t=0;t<e.length;t++)if(e[t]in n.docStyle)return e[t];return e[0]}static create(e,t,i){let o=window.document.createElement(e);return t!==void 0&&(o.className=t),i&&i.appendChild(o),o}static remove(e){e.parentNode&&e.parentNode.removeChild(e);}static setTransform(e,t){n.transformProp&&e.style&&(e.style[n.transformProp]=t);}static manageEventListener(e,t,i,o,s={}){if(!t)return;let a=e==="add"?"addEventListener":"removeEventListener";"passive"in s?t[a](i,o,s):t[a](i,o,s.capture);}static mouseButton(e){return e.button}static addClassName(e,t){e.classList.contains(t)||e.classList.add(t);}static removeClassName(e,t){e.classList.contains(t)&&e.classList.remove(t);}};var _=class n{lng;lat;constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,this.lat>90||this.lat<-90)throw new Error("Invalid LngLat latitude value: must be between -90 and 90")}static convert(e){if(e instanceof n)return e;if(Array.isArray(e)&&(e.length===2||e.length===3))return new n(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null)return new n(Number("lng"in e?e.lng:e.lon),Number(e.lat));throw new Error("`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]")}};function F(n,...e){for(let t of e)for(let i in t)n[i]=t[i];return n}function fe(n,e,t){let i=new _(n.lng,n.lat);if(n=new _(n.lng,n.lat),e){let o=new _(n.lng-360,n.lat),s=new _(n.lng+360,n.lat),a=t.locationPoint(n).distSqr(e);t.locationPoint(o).distSqr(e)<a?n=o:t.locationPoint(s).distSqr(e)<a&&(n=s);}for(;Math.abs(n.lng-t.center.lng)>180;){let o=t.locationPoint(n);if(o.x>=0&&o.y>=0&&o.x<=t.width&&o.y<=t.height)break;n.lng>t.center.lng?n.lng-=360:n.lng+=360;}return n.lng!==i.lng&&t.locationPoint(n).y>t.height/2-t.getHorizon()?n:i}var ue={center:"translate(-50%,-50%)",top:"translate(-50%,0)","top-left":"translate(0,0)","top-right":"translate(-100%,0)",bottom:"translate(-50%,-100%)","bottom-left":"translate(0,-100%)","bottom-right":"translate(-100%,-100%)",left:"translate(0,-50%)",right:"translate(-100%,-50%)"};function ve(n,e,t){let i=n.classList;for(let o in ue)i.remove(`maplibregl-${t}-anchor-${o}`);i.add(`maplibregl-${t}-anchor-${e}`);}function Le(n,e,t){t[n]&&t[n].indexOf(e)!==-1||(t[n]=t[n]||[],t[n].push(e));}function de(n,e,t){if(t&&t[n]){let i=t[n].indexOf(e);i!==-1&&t[n].splice(i,1);}}var q=class{_listeners;_oneTimeListeners;_eventedParent;_eventedParentData;on(e,t){return this._listeners=this._listeners||{},Le(e,t,this._listeners),this}off(e,t){return de(e,t,this._listeners),de(e,t,this._oneTimeListeners),this}once(e,t){return t?(this._oneTimeListeners=this._oneTimeListeners||{},Le(e,t,this._oneTimeListeners),this):new Promise(i=>this.once(e,i))}fire(e,t){typeof e=="string"&&(e=new D(e,t||{}));let i=e.type;if(this.listens(i)){e.target=this;let o=this._listeners&&this._listeners[i]?this._listeners[i].slice():[];for(let c of o)c.call(this,e);let s=this._oneTimeListeners&&this._oneTimeListeners[i]?this._oneTimeListeners[i].slice():[];for(let c of s)de(i,c,this._oneTimeListeners),c.call(this,e);let a=this._eventedParent;a&&(F(e,typeof this._eventedParentData=="function"?this._eventedParentData():this._eventedParentData),a.fire(e));}else e instanceof ErrorEvent&&console.error(e.error);return this}listens(e){return this._listeners&&this._listeners[e]&&this._listeners[e].length>0||this._oneTimeListeners&&this._oneTimeListeners[e]&&this._oneTimeListeners[e].length>0||this._eventedParent&&this._eventedParent.listens(e)}setEventedParent(e,t){return this._eventedParent=e,this._eventedParentData=t,this}},D=class{type;constructor(e,t={}){F(this,t),this.type=e;}};var h=class n{x;y;constructor(e,t){this.x=e,this.y=t;}mag(){return Math.sqrt(this.x*this.x+this.y*this.y)}equals(e){return this.x===e.x&&this.y===e.y}dist(e){return Math.sqrt(this.distSqr(e))}distSqr(e){let t=e.x-this.x,i=e.y-this.y;return t*t+i*i}angle(){return Math.atan2(this.y,this.x)}angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)}angleWith(e){return this.angleWithSep(e.x,e.y)}angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)}_matMult(e){let t=e[0]*this.x+e[1]*this.y,i=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=i,this}_add(e){return this.x+=e.x,this.y+=e.y,this}_sub(e){return this.x-=e.x,this.y-=e.y,this}_mult(e){return this.x*=e,this.y*=e,this}_div(e){return this.x/=e,this.y/=e,this}_multByPoint(e){return this.x*=e.x,this.y*=e.y,this}_divByPoint(e){return this.x/=e.x,this.y/=e.y,this}_unit(){return this._div(this.mag()),this}_perp(){let e=this.y;return this.y=this.x,this.x=-e,this}_rotate(e){let t=Math.cos(e),i=Math.sin(e),o=t*this.x-i*this.y,s=i*this.x+t*this.y;return this.x=o,this.y=s,this}_rotateAround(e,t){let i=Math.cos(e),o=Math.sin(e),s=t.x+i*(this.x-t.x)-o*(this.y-t.y),a=t.y+o*(this.x-t.x)+i*(this.y-t.y);return this.x=s,this.y=a,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}static convert(e){if(e instanceof n)return e;if(Array.isArray(e))return new n(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new n(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")}};var Se={closeButton:!0,closeOnClick:!0,focusAfterOpen:!0,className:"",maxWidth:"240px",subpixelPositioning:!1},Oe=["a[href]","[tabindex]:not([tabindex='-1'])","[contenteditable]:not([contenteditable='false'])","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])"].join(", "),z=class extends q{_map;options;_content;_container;_closeButton;_tip;_lngLat;_trackPointer;_pos;_flatPos;constructor(e){super(),this.options=F(Object.create(Se),e);}addTo(e){return this._map&&this.remove(),this._map=e,this.options.closeOnClick&&this._map.on("click",this._onClose),this.options.closeOnMove&&this._map.on("move",this._onClose),this._map.on("remove",this.remove),this._update(),this._focusFirstElement(),this._trackPointer?(this._map.on("mousemove",this._onMouseMove),this._map.on("mouseup",this._onMouseUp),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")):this._map.on("move",this._update),this.fire(new D("open")),this}isOpen(){return !!this._map}remove=()=>(this._content&&l.remove(this._content),this._container&&(l.remove(this._container),delete this._container),this._map&&(this._map.off("move",this._update),this._map.off("move",this._onClose),this._map.off("click",this._onClose),this._map.off("remove",this.remove),this._map.off("mousemove",this._onMouseMove),this._map.off("mouseup",this._onMouseUp),this._map.off("drag",this._onDrag),this._map._canvasContainer.classList.remove("maplibregl-track-pointer"),delete this._map,this.fire(new D("close"))),this);getLngLat(){return this._lngLat}setLngLat(e){return this._lngLat=_.convert(e),this._pos=null,this._flatPos=null,this._trackPointer=!1,this._update(),this._map&&(this._map.on("move",this._update),this._map.off("mousemove",this._onMouseMove),this._container&&this._container.classList.remove("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.remove("maplibregl-track-pointer")),this}trackPointer(){return this._trackPointer=!0,this._pos=null,this._flatPos=null,this._update(),this._map&&(this._map.off("move",this._update),this._map.on("mousemove",this._onMouseMove),this._map.on("drag",this._onDrag),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")),this}getElement(){return this._container}setText(e){return this.setDOMContent(document.createTextNode(e))}setHTML(e){let t=document.createDocumentFragment(),i=document.createElement("body"),o;for(i.innerHTML=e;o=i.firstChild,!!o;)t.appendChild(o);return this.setDOMContent(t)}getMaxWidth(){return this._container?.style.maxWidth}setMaxWidth(e){return this.options.maxWidth=e,this._update(),this}setDOMContent(e){if(this._content)for(;this._content.hasChildNodes();)this._content.firstChild&&this._content.removeChild(this._content.firstChild);else this._content=l.create("div","maplibregl-popup-content",this._container);return this._content.appendChild(e),this._createCloseButton(),this._update(),this._focusFirstElement(),this}addClassName(e){return this._container&&this._container.classList.add(e),this}removeClassName(e){return this._container&&this._container.classList.remove(e),this}setOffset(e){return this.options.offset=e,this._update(),this}toggleClassName(e){if(this._container)return this._container.classList.toggle(e)}setSubpixelPositioning(e){this.options.subpixelPositioning=e;}_createCloseButton(){this.options.closeButton&&(this._closeButton=l.create("button","maplibregl-popup-close-button",this._content),this._closeButton.type="button",this._closeButton.innerHTML="×",this._closeButton.addEventListener("click",this._onClose));}_onMouseUp=e=>{this._update(e.point);};_onMouseMove=e=>{this._update(e.point);};_onDrag=e=>{this._update(e.point);};_update=e=>{let t=this._lngLat||this._trackPointer;if(!this._map||!t||!this._content)return;if(!this._container){if(this._container=l.create("div","maplibregl-popup",this._map.getContainer()),this._tip=l.create("div","maplibregl-popup-tip",this._container),this._container.appendChild(this._content),this.options.className)for(let c of this.options.className.split(" "))this._container.classList.add(c);this._closeButton&&this._closeButton.setAttribute("aria-label",this._map._getUIString("Popup.Close")),this._trackPointer&&this._container.classList.add("maplibregl-popup-track-pointer");}if(this.options.maxWidth&&this._container.style.maxWidth!==this.options.maxWidth&&(this._container.style.maxWidth=this.options.maxWidth),this._map.transform.renderWorldCopies&&!this._trackPointer?this._lngLat=fe(this._lngLat,this._flatPos,this._map.transform):this._lngLat=this._lngLat?.wrap(),this._trackPointer&&!e)return;let i=this._flatPos=this._pos=this._trackPointer&&e?e:this._map.project(this._lngLat);this._map.terrain&&(this._flatPos=this._trackPointer&&e?e:this._map.transform.locationPoint(this._lngLat));let o=this.options.anchor,s=ge(this.options.offset);if(!o){let c=this._container.offsetWidth,v=this._container.offsetHeight,x;i.y+s.bottom.y<v?x=["top"]:i.y>this._map.transform.height-v?x=["bottom"]:x=[],i.x<c/2?x.push("left"):i.x>this._map.transform.width-c/2&&x.push("right"),x.length===0?o="bottom":o=x.join("-");}let a=i.add(s[o]);this.options.subpixelPositioning||(a=a.round()),l.setTransform(this._container,`${ue[o]} translate(${a.x}px,${a.y}px)`),ve(this._container,o,"popup");};_focusFirstElement(){if(!this.options.focusAfterOpen||!this._container)return;let e=this._container.querySelector(Oe);e&&e.focus();}_onClose=()=>{this.remove();}};function ge(n){if(n)if(typeof n=="number"){let e=Math.round(Math.abs(n)/Math.SQRT2);return {center:new h(0,0),top:new h(0,n),"top-left":new h(e,e),"top-right":new h(-e,e),bottom:new h(0,-n),"bottom-left":new h(e,-e),"bottom-right":new h(-e,-e),left:new h(n,0),right:new h(-n,0)}}else if(n instanceof h||Array.isArray(n)){let e=h.convert(n);return {center:e,top:e,"top-left":e,"top-right":e,bottom:e,"bottom-left":e,"bottom-right":e,left:e,right:e}}else return {center:h.convert(n.center||[0,0]),top:h.convert(n.top||[0,0]),"top-left":h.convert(n["top-left"]||[0,0]),"top-right":h.convert(n["top-right"]||[0,0]),bottom:h.convert(n.bottom||[0,0]),"bottom-left":h.convert(n["bottom-left"]||[0,0]),"bottom-right":h.convert(n["bottom-right"]||[0,0]),left:h.convert(n.left||[0,0]),right:h.convert(n.right||[0,0])};else return ge(new h(0,0))}var Y=class{#e;#t;#i;_undoButton;_deleteButton;_saveButton;_container;constructor(e){this.#e=e,this._container=void 0,this.#i=!1,this.#s().then(()=>{this.#r(),this.#o();});}#o(){this.#e.mode?.addObserver(this.#n);}#n=e=>{let{store:t}=this.#e,{type:i,data:o}=e;i==="MODE_CHANGED"&&!o&&this.hidePanel(),i==="MODE_CHANGED"&&o&&t.tail?.val&&this.setPanelLocation({lat:t.tail?.val?.lat,lng:t.tail?.val?.lng});};#s=async()=>{try{this.#t=new z({offset:16,closeButton:!1,closeOnClick:!1,closeOnMove:!1,anchor:"bottom"});}catch(e){console.error("POPUP LOAD ERROR",e);}};#r=()=>{let{store:e}=this.#e;this.createPanel(),e.tail?.val&&this.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng});};setPanelLocation=e=>{let{map:t}=this.#e;this.#i&&(this.#i=!1,this.showPanel()),this._container&&this.#t&&this.#t.setLngLat(e).setDOMContent(this._container).addTo(t);};hidePanel=()=>{!this.#i&&(this.#t?.addClassName("hide-panel"),this.#i=!0);};showPanel=()=>{this.#t?.removeClassName("hide-panel"),this.#i=!1;};onPointRemove=e=>{e?this.setPanelLocation(e):this.hidePanel();};removePanel=()=>{this._container&&l.remove(this._container),this.#t?.remove();};createButton=(e,t,i,o)=>{let s=l.create("button",`panel-button panel-button-${i}`,o);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`icon ${e} icon-${i}`,s),s};createPanel=()=>{let{options:e}=this.#e,{locale:t}=e,{undo:i,delete:o,save:s}=e.panel.buttons,a=e.panel.size,c=document.querySelector(".maplibregl-popup-content"),v=l.create("div","dashboard",c);i.visible&&(this._undoButton=this.createButton("undo",t.undo,a,v)),o.visible&&(this._deleteButton=this.createButton("delete",t.delete,a,v)),s.visible&&(this._saveButton=this.createButton("save",t.save,a,v)),this._container=v;}};var j={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[]}}]},W={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[]}}]},Ee={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}}]},r={LineDynamicLayer:"mdl-line-dynamic-layer",LineLayer:"mdl-line-layer",LineLayerTransparent:"mdl-line-layer-transparent",LineLayerBreak:"mdl-line-break-layer",PolygonLayer:"mdl-polygon-layer",PointsLayer:"mdl-points-layer",SinglePointLayer:"mdl-single-point-layer",FirstPointLayer:"mdl-first-point-layer"},p={LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",LineSource:"mdl-line-source",PolygonSource:"mdl-polygon-source",PointsSource:"mdl-points-source",SinglePointSource:"mdl-single-point-source"},A={large:6.5,default:5.5},V={large:"#FF6464",default:"#666666"},k={"circle-radius":A.default,"circle-color":"#FEFFFE","circle-stroke-color":V.default,"circle-stroke-width":3},T={"circle-radius":A.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},G={"fill-color":"grey","fill-opacity":.4},I={"line-width":3,"line-color":"grey","line-opacity":.7},w={"circle-radius":A.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},B={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},K=n=>[{id:r.SinglePointLayer,source:p.SinglePointSource,type:"circle",paint:n.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:p.PolygonSource,type:"fill",paint:n.layersPaint.polygon,layout:{visibility:"none"}},{id:r.LineDynamicLayer,source:p.LineDynamicSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"none"}},{id:r.LineLayer,source:p.LineSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"visible"}},{id:r.LineLayerTransparent,source:p.LineSource,type:"line",paint:{"line-width":4,"line-color":"transparent"}},{id:r.LineLayerBreak,source:p.LineSourceBreak,type:"line",paint:n.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:p.PointsSource,type:"circle",paint:n.layersPaint.points,filter:["==",["get","isFirst"],!1]},{id:r.FirstPointLayer,source:p.PointsSource,type:"circle",paint:n.layersPaint.firstPoint,filter:["==",["get","isFirst"],!0]}];var L=class{static#e=0;static#t=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",A.large),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",V.large);};static#i=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",A.default),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",V.default);};static togglePointCircleRadius=(e,t)=>{t==="large"?this.#t(e):this.#i(e);};static removeTransparentLine=e=>{e.removeLayer(r.LineLayerTransparent);};static addTransparentLine=(e,t)=>{if(e.getLayer(r.LineLayerTransparent))return;let o=K(t).find(s=>s.id===r.LineLayerTransparent);o&&e.addLayer(o);};static isDoubleClick(){let t=Date.now();return t-this.#e<=400?(this.#e=t,!0):(this.#e=t,!1)}};var m=class{static isFeatureTriggered(e,t){return e.target.queryRenderedFeatures(e.point,{layers:t}).some(o=>t.includes(o.layer.id))}static getPixelCoordinates=(e,t)=>{let{lat:i,lng:o}=t;return e.project([o,i])};static queryPointId=(e,t)=>e.queryRenderedFeatures(t,{layers:[r.PointsLayer,r.FirstPointLayer]})?.[0]?.properties.id},M=class{static#e(e){let t=[],i=e.head,o=new Set;for(;i!==null;){if(o.has(i.val?.id)){e.head&&e.head.val&&t.push([e.head.val.lng,e.head.val.lat]);break}o.add(i.val?.id),i.val&&t.push([i.val.lng,i.val.lat]),i=i.next;}return t}static getAllLines(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}]}}static getLine(e,t){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e,t]}}]}}static getPolygon(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[t]}}]}}static getPoints(e){let t=e.head,i=[],o=new Set;for(;t!==null&&!o.has(t.val?.id);){if(t.val){let s=t.val,a=t.val.id===e.head?.val?.id;i.push({type:"Feature",properties:{id:s.id,lat:s.lat,lng:s.lng,isFirst:a},geometry:{type:"Point",coordinates:[s.lng,s.lat]}});}o.add(t.val?.id),t=t.next;}return {type:"FeatureCollection",features:i}}},u=class n{static getGeometryIndex=(e,t)=>{let i=e.head,o=0;for(;i!==null;){if(i.val?.id===t)return o;o++,i=i.next;}return -1};static isFirstPoint(e){let t=e.target,i=e.point;return !!t.queryRenderedFeatures(i,{layers:[r.FirstPointLayer]}).length}static distance=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2);static checkIfPointIsOnLine=(e,t,i)=>{let s=this.distance(e,t),a=this.distance(e,i),c=this.distance(i,t);return Math.abs(a+c-s)<.1};static isClosedGeometry=e=>e.tail?.next===e.head;static breakGeometry=(e,t)=>{if(!e.head)return;let i=e.head,o=e.tail;do{if(i?.val?.id===t){i!==e.head&&(o.next=i.next,e.head=i,e.tail=o),e.tail.next=null;return}o=i,i=i.next;}while(i!==e.head)};static closeGeometry=(e,t)=>{e.tail&&(e.tail.next=e.head),t.setClosedGeometry(!0);};static canCloseGeometry=e=>e.size>2&&!this.isClosedGeometry(e);static canBreakClosedGeometry=e=>e.size<=2;static switchToLineModeIfCan=e=>{let{mode:t,store:i,tiles:o,map:s}=e;n.canBreakClosedGeometry(i)&&(i.tail&&i.tail.val&&(i.tail.next=null),t.reset(),L.togglePointCircleRadius(s,"default"),o.renderPolygon(j));}},b=()=>{if("crypto"in window&&"randomUUID"in window.crypto)return window.crypto.randomUUID();function n(){return "0123456789abcdef"[Math.floor(Math.random()*16)]}function e(o){let s="";for(let a=0;a<o;a++)s+=n();return s}function t(o){let s=o===0,a=o===4;return s?8:a?12:4}let i=[];for(let o=0;o<5;o++)i.push(e(t(o)));return i.join("-")},C=(n,e)=>{let t,i=!0;function o(){i&&t&&(n(...t),t=null,i=!1,setTimeout(()=>{i=!0,o();},e));}return function(...s){t=s,o();}};var N=class{#e;#t;#i;#o;constructor(e){this.#e=e,this.#n(),this.render();}#n(){this.#s(),this.#r(),this.#a(r.LineLayer,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.FirstPointLayer),this.#a(r.LineLayerTransparent,r.PointsLayer),this.#a(r.PolygonLayer,r.LineLayer);}#s=()=>{let{map:e}=this.#e;Object.values(p).forEach(t=>{e.getSource(t)||e.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});});};#r=()=>{let{map:e,mode:t,options:i}=this.#e;K(i).forEach(a=>{e.getLayer(a.id)||e.addLayer(a);});let s=e.getLayoutProperty(r.PolygonLayer,"visibility")==="none";t.getMode()==="polygon"&&s&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible");};#a=(e,t)=>{let{map:i}=this.#e,o=i.getLayer(e),s=i.getLayer(t);o&&s&&i.moveLayer(e,t);};#l=()=>{let{map:e}=this.#e;Object.values(p).forEach(t=>{e.getSource(t)&&e.removeSource(t);});};#c=()=>{let{map:e}=this.#e;Object.values(r).forEach(t=>{e.getLayer(t)&&e.removeLayer(t);});};removeTiles=()=>{this.#c(),this.#l();};renderPoints=e=>{let{map:t}=this.#e,i=t.getSource(p.PointsSource);i&&i.setData(e);};renderLines=(e,t)=>{let{map:i}=this.#e,o=i.getSource(t);o&&o.setData(e);};renderPolygon=e=>{let{map:t}=this.#e,i=t.getSource(p.PolygonSource);i&&i.setData(e);};render=()=>{let{mode:e,options:t,store:i}=this.#e,o=M.getPoints(i),s=M.getAllLines(i);if(this.#t=o,this.#i=s,this.renderPoints(o),this.renderLines(s,p.LineSource),t.modes.polygon.visible&&e.isPolygon()){let c=M.getPolygon(i);this.#o=c,this.renderPolygon(c);}};#h=(e,t)=>{if(this.#o.features[0].geometry.coordinates[0][e]=[t.lng,t.lat],e===0){let o=this.#o.features[0].geometry.coordinates[0]?.length-1;this.#o.features[0].geometry.coordinates[0][o]=[t.lng,t.lat];}this.renderPolygon(this.#o);};#p=(e,t)=>{let{mode:i}=this.#e;this.#i.features[0].geometry.coordinates[e]=[t.lng,t.lat];let o=e===0;if(this.#i&&i.getClosedGeometry()&&o){let a=this.#i.features[0].geometry.coordinates?.length-1;this.#i.features[0].geometry.coordinates[a]=[t.lng,t.lat];}this.renderLines(this.#i,p.LineSource);};renderOnMouseMove=(e,t)=>{let{mode:i,options:o}=this.#e;this.#t.features[e].geometry.coordinates=[t.lng,t.lat],this.renderPoints(this.#t),this.#p(e,t),o.modes.polygon.visible&&i.isPolygon()&&this.#h(e,t);};resetGeometries=()=>{this.renderPoints(Ee),this.renderLines(W,p.LineSource),this.renderPolygon(j);}};var xe=8,ke=8,S=class{_container;_label;constructor(){this._container=void 0;}create=e=>{let t=l.create("div","popup-container",document.body),i=l.create("span",`popup-text popup-text-${e.placement}`,t);return i.textContent=e.label,this._container=t,this._label=i,this};#e=()=>{!this._label?.classList.value.includes("popup-text-active")&&this._label?.classList.add("popup-text-active");};#t=()=>this._label?{width:this._label.clientWidth,height:this._label.clientHeight}:{width:0,height:0};#i=e=>{let{bottom:t,left:i}=e.target.getBoundingClientRect(),{width:o,height:s}=this.#t();return {x:i-ke-o,y:t-s-2}};#o=e=>{let{bottom:t,left:i,right:o}=e.target.getBoundingClientRect(),{width:s}=this.#t();return {x:(o-i)/2+i-s/2,y:t+xe}};getPosition=(e,t)=>t==="left"?this.#i(e):this.#o(e);setPosition=e=>{let{x:t,y:i}=e;this._container&&(this._container.style.left=`${t}px`,this._container.style.top=`${i}px`),this.#e();};remove=()=>{this._container&&l.remove(this._container);}};var g={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var $=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("add",n,t,i);},Z=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("remove",n,t,i);},Pe=(n,e)=>{let t=e.locale.line,i=e.locale.polygon,o=e.locale.break;return {line:t,polygon:i,break:o}[n]};var J=class{#e;constructor(e){this.#e=e,this.#t();}#t=()=>{this.#e.mode.addObserver(this.#l);};removeConsumers=()=>{this.#e.mode.removeObserver(this.#l);};#i=()=>{let{_line:e,_polygon:t,_break:i}=this.#e.control;e?.classList.remove("control-button-active"),t?.classList.remove("control-button-active"),i?.classList.remove("control-button-active");};#o=e=>{this.#i(),e.classList.add("control-button-active");};#n=e=>{let{data:t}=e,{_line:i,_polygon:o,_break:s}=this.#e.control,{mode:a}=this.#e;if(!(!i||!o||!s)){switch(t){case"line":this.#o(i);break;case"polygon":this.#o(o);break;}t?a.getClosedGeometry()&&this.#r(s):this.#s(s);}};#s=e=>{e.setAttribute("disabled","true"),e.setAttribute("aria-disabled","true");};#r=e=>{e.removeAttribute("disabled"),e.removeAttribute("aria-disabled");};#a=e=>{let{data:t,type:i}=e,{_break:o,_line:s,_polygon:a}=this.#e.control,{mode:c}=this.#e;t?(o&&this.#r(o),c.getMode()==="polygon"&&s&&this.#s(s),c.getMode()==="line"&&a&&this.#s(a)):(o&&this.#s(o),c.getMode()==="polygon"&&s&&this.#r(s),c.getMode()==="line"&&a&&this.#r(a));};#l=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.#n(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.#a(e),t==="BREAK_CHANGED"&&i){let{_break:o}=this.#e.control;this.#o(o);}}};var X=class{#e;#t;#i;constructor(e){this.#e=e,this.#i=new J(e),this.#t=new S,this.#o();}#o(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&$(e._line,{...t,click:this.onLineClick}),e._polygon&&$(e._polygon,{...t,click:this.onPolygonClick}),e._break&&$(e._break,{...t,click:this.onBreakClick});}}#n(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&Z(e._line,{...t,click:this.onLineClick}),e._polygon&&Z(e._polygon,{...t,click:this.onPolygonClick}),e._break&&Z(e._break,{...t,click:this.onBreakClick});}}remove(){this.#i.removeConsumers(),this.#n(),this.#t.remove();}onButtonEnter=e=>{let{options:t}=this.#e,i=e.target.getAttribute("data-type");if(i){let o=Pe(i,t),s="left";this.#t.create({label:o,placement:s}).setPosition(this.#t.getPosition(e,s));}};onButtonLeave=()=>{this.#t.remove();};#s=()=>{let{control:e}=this.#e;e._line?.classList.remove("control-button-active"),e._polygon?.classList.remove("control-button-active"),e._break?.classList.remove("control-button-active");};#r=()=>{let{map:e,mode:t}=this.#e;t.getMode()||e.fire("mode:initialize");};onLineClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="line"?(t.setMode(null),e.fire("mode:remove"),i.resetGeometries()):(o._line?.classList.add("control-button-active"),t.setMode("line"),i.render());};onPolygonClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="polygon"?(t.setMode(null),e.fire("mode:remove"),e.setLayoutProperty(r.PolygonLayer,"visibility","visible"),i.resetGeometries()):(o._polygon?.classList.add("control-button-active"),t.setMode("polygon"),i.render());};onBreakClick=()=>{let{map:e,mode:t,control:i}=this.#e;t.getBreak()&&(t.setMode(null),e.fire("mode:remove")),this.#s(),i._break?.classList.add("control-button-active"),t.setBreak(!0),e.getCanvasContainer().style.cursor=g.POINTER;}};var O=class{observers;constructor(){this.observers=new Set;}addObserver(e){this.observers.add(e);}removeObserver(e){this.observers.delete(e);}unsubscribe(){this.observers.clear();}notify(e){this.observers.forEach(t=>t(e));}};var R={EMPTY_INITIAL_STATE:"You passed an empty initial array in the options. Please either remove the 'initial' property or include at least one element in the array.",MISSING_IDS:"You set 'generateId' to false but did not provide IDs for all steps. Please ensure all steps have IDs or set 'generateId' to true.",NOT_ENOUGH_POINTS_TO_CLOSE:"At least three points are required to close a polygon or a line. Please add more points or set 'closeGeometry' to false.",FIRST_LAST_POINT_NOT_EQUAL:"The first and last points of a polygon or a closed linestring must be the same. Please ensure the first and last points are equal or set 'closeGeometry' to false."};var Q=class{val;next;constructor(e=null,t=null){this.val=e,this.next=t;}},H=class extends O{head;tail;size;constructor(e){super();let t=P.initStore(e);this.head=t?t.head:null,this.tail=t?t.tail:null,this.size=t?t.size:0;}push(e){let t=new Q(e);this.head?this.tail&&(this.tail.next=t,this.tail=t):this.head=this.tail=t,this.size++,this.pingConsumers();}insert(e,t){let i=new Q(e,t.next);this.tail===t&&this.head===t.next&&(this.tail=i),t.next=i,this.size++;}findStepById(e){let t=this.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.val&&t.val.id===e)return t.val;i.add(t),t=t.next;}return null}removeStepById(e){if(!this.head)return null;let t=this.head,i=null;for(;t!==null;){if(t?.val?.id===e)return t===this.head?(this.head=t.next,this.tail&&(this.tail.next=t.next)):i.next=t.next,t===this.tail&&(this.tail=i),this.size--,this.pingConsumers(),t;i=t,t.next&&(t=t.next);}return null}reset(){this.head=null,this.tail=null,this.size=0,this.pingConsumers();}pingConsumers=()=>{this.notify({type:"STORE_CHANGED",data:{head:this.head,tail:this.tail,size:this.size}});}},P=class n{static isLastPoint=(e,t)=>e.tail?.val?.id===t;static initStore(e){if(!e?.initial)return null;if(e&&e.initial&&!e.initial.steps.length)throw new Error(R.EMPTY_INITIAL_STATE);if(e&&e.initial.steps){let{steps:o,closeGeometry:s,generateId:a}=e.initial;return n.fromArray(o,s,a)}return null}static#e=e=>e.map(t=>({...t,id:b()}));static buildStepSequence(e){let t=new H;return e.forEach(i=>{t.push(i);}),t}static fromArray(e,t,i){let o=i?this.#e(e):e,s=this.buildStepSequence(o);return t&&s.tail&&(s.tail.next=s.head),s}static toArray(e){if(!e)return [];let t=new Set,i=[],o=e;for(;o!==null&&!t.has(o);)t.add(o),i.push(o.val),o=o.next;return i}};var f={DOUBLECLICK:"mdl:doubleclick",POINTENTER:"mdl:pointenter",POINTLEAVE:"mdl:pointleave",MOVEEND:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REMOVEALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",LINE:"mdl:line",POLYGON:"mdl:polygon"};var d={panel:{size:"medium",buttons:{undo:{visible:!0},delete:{visible:!0},save:{visible:!0,clearOnSave:!0}}},modes:{initial:null,line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{onLinePoint:T,firstPoint:k,points:w,line:I,polygon:G,breakLine:B},initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close line",createPolygon:"Create polygon"}};var y=class{static addPoint(e,t,i){t.fire(f.ADD,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static movePoint(e,t){t.fire(f.MOVEEND,{id:e.id,start_coordinates:{lat:e.start.lat,lng:e.start.lng},end_coordinates:{lat:e.end.lat,lng:e.end.lng},total:e.total,timestamp:Date.now()});}static pointDoubleClick(e,t){t.fire(f.DOUBLECLICK,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){t.fire(f.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){t.fire(f.POINTLEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undoPoint(e,t,i){t.fire(f.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static removeAllPoints(e,t){e.fire(f.REMOVEALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:o,mode:s}=e;o.fire(f.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onLineBreak(e){e.fire(f.BREAK);}};var ee=class{#e;#t;constructor(e){this.#e=e,this.#t=new S;}initEvents(){let{panel:e}=this.#e;e&&(l.manageEventListener("add",e?._undoButton,"click",this.#n),l.manageEventListener("add",e?._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._undoButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._deleteButton,"click",this.#o),l.manageEventListener("add",e?._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._deleteButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._saveButton,"click",this.onSaveClick),l.manageEventListener("add",e?._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._saveButton,"mouseleave",this.onMouseLeave));}removeEvents(){let{panel:e}=this.#e;e&&e._undoButton&&(l.manageEventListener("remove",e._undoButton,"click",this.#n),l.manageEventListener("remove",e._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._undoButton,"mouseleave",this.onMouseLeave)),e&&e._deleteButton&&(l.manageEventListener("remove",e._deleteButton,"click",this.#o),l.manageEventListener("remove",e._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._deleteButton,"mouseleave",this.onMouseLeave)),e&&e._saveButton&&(l.manageEventListener("remove",e._saveButton,"click",this.onSaveClick),l.manageEventListener("remove",e._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._saveButton,"mouseleave",this.onMouseLeave));}#i=e=>{let{options:t}=this.#e;return {undo:t.locale.undo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let t=e.target.getAttribute("data-type");if(t){let i=this.#i(t);this.#t.create({label:i,placement:"bottom"}).setPosition(this.#t.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.#t.remove();};#o=e=>{let{tiles:t,mode:i,panel:o,store:s,map:a}=this.#e;s.reset(),o.hidePanel(),i.reset(),L.togglePointCircleRadius(a,"default"),this.#t.remove(),t.resetGeometries(),y.removeAllPoints(a,e);};#n=e=>{let{store:t,panel:i,map:o,tiles:s}=this.#e,a=t.tail?.val;t.removeStepById(a.id);let c={...a,total:t.size};y.undoPoint(c,o,e),u.switchToLineModeIfCan(this.#e),i?.onPointRemove(t.tail?.val),this.#t.remove(),requestAnimationFrame(s.render);};onSaveClick=e=>{let{store:t,options:i}=this.#e;y.onSaveClick(this.#e,P.toArray(t.head),e),this.#t.remove(),i.panel.buttons.save.clearOnSave&&this.#o(e);}};var E=class{static updatePointsData(e){let i=e.target.getSource(p.SinglePointSource);i&&i.setData({type:"Feature",geometry:{type:"Point",coordinates:[e.lngLat.lng,e.lngLat.lat]},properties:{}});}static setSinglePointVisible(e){e.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");}static setSinglePointHidden(e){let t=e.target;setTimeout(()=>{t.setLayoutProperty(r.SinglePointLayer,"visibility","none");},33);}static triggerPostPointAddition(e,t){let{panel:i,tiles:o,store:s,map:a}=t;u.canCloseGeometry(s)&&L.togglePointCircleRadius(a,"large"),i?.setPanelLocation(e.lngLat),o.render();}static addPointToMap=(e,t)=>{let{store:i,map:o,mode:s}=t,a={...e.lngLat,id:b()};i.push(a),y.addPoint({...a,total:i.size},o,s),this.triggerPostPointAddition(e,t);};static updateSelectedStepLatLng=(e,t)=>{t.lat=e.lngLat.lat,t.lng=e.lngLat.lng;}};var me=(n,e)=>{let t=e.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.next&&t.next.val&&t.val){let o=n.target,s=m.getPixelCoordinates(o,t.val),a=m.getPixelCoordinates(o,t.next.val),c=m.getPixelCoordinates(o,n.lngLat);if(u.checkIfPointIsOnLine(s,a,c))return t}i.add(t),t=t.next;}return null},Me=(n,e)=>{let t=me(n,e);if(t){let i={...n.lngLat,id:b()};return e.insert(i,t),i}return null},be=(n,e)=>{let{store:t,tiles:i,panel:o}=e;t.tail?.val&&(o?.setPanelLocation(t.tail.val),E.setSinglePointHidden(n),i.render());},_e=n=>m.isFeatureTriggered(n,[r.PointsLayer,r.FirstPointLayer]);var Ce=15,te=class{props;#e;#t;constructor(e){this.props=e,this.#e=null,this.#t=C(this.#o,Ce);}initBreakEvents=()=>{let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mouseenter",r.LineLayerTransparent,this.#t),e.on("mousemove",r.LineLayerTransparent,this.#t),e.on("mouseleave",r.LineLayerTransparent,this.#n);};removeBreakEvents=()=>{let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mouseenter",r.LineLayerTransparent,this.#t),e.off("mousemove",r.LineLayerTransparent,this.#t),e.off("mouseleave",r.LineLayerTransparent,this.#n);};hideBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};#i=()=>{let{store:e,mode:t,panel:i,map:o,tiles:s}=this.props,a=this.#e?.next?.val?.id;u.breakGeometry(e,a),e.tail?.val&&i.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng}),this.#n(),o.setLayoutProperty(r.PolygonLayer,"visibility","none"),t.reset(),s.render(),y.onLineBreak(o);};#o=e=>{let{map:t,store:i}=this.props,o=me(e,i);o?.val?.id!==this.#e?.val?.id&&(this.#e=o);let s=t.getSource(p.LineSourceBreak),a=[o?.val?.lng,o?.val?.lat],c=[o?.next?.val?.lng,o?.next?.val?.lat],v=M.getLine(a,c);v&&(s.setData(v),this.showBreakLine());};#n=()=>{setTimeout(()=>{this.hideBreakLine();},Ce+10);}};var Te=10,ie=class{#e;#t;#i;#o;#n;#s;constructor(e){this.#e=e,this.#t=e.options.dynamicLine,this.#i=null,this.#o=null,this.#r(),this.#s=C(this.#p,Te);}#r(){this.#e.store.addObserver(this.#l),this.#e.mode.addObserver(this.#c),this.#e.mouseEvents.addObserver(this.#a);}removeLine=()=>{this.hideDynamicLine();};removeConsumers=()=>{this.#e.store.removeObserver(this.#l),this.#e.mode.removeObserver(this.#c),this.#e.mouseEvents.removeObserver(this.#a);};#a=e=>{let{mode:t}=this.#e;if(!t.getClosedGeometry()&&(e.type==="lastPointMouseClick"&&e.data?(this.hideDynamicLine(),this.#t=!1):e.type==="lastPointMouseClick"&&!e.data&&(this.#t=!0),!!this.#t&&((e.type==="pointMouseEnter"||e.type==="lineMouseEnter")&&e.data&&this.hideDynamicLine(),(e.type==="pointMouseLeave"||e.type==="lineMouseLeave")&&e.data))){let{store:i}=this.#e;this.#i=i.tail?.val,this.#o=i.tail?.val,this.showDynamicLine();}};#l=e=>{let{store:t}=this.#e;switch(e.type){case"STORE_CHANGED":e.data.tail?.val&&!u.isClosedGeometry(t)&&(this.#i=e.data.tail?.val,this.showDynamicLine());break;}};#c=e=>{let{store:t}=this.#e;e.type==="CLOSED_GEOMETRY_CHANGED"&&(e.data&&this.hideDynamicLine(),!e.data&&t?.tail?.val&&(this.#i=t?.tail?.val,this.showDynamicLine()));};initDynamicEvents=()=>{let{map:e}=this.#e;e.on("click",this.#f),e.on("mousemove",this.#s),e.on(f.REMOVEALL,this.hideDynamicLine),e.on(f.UNDO,this.#m),e.on(f.DOUBLECLICK,this.#v);};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#f),e.off("mousemove",this.#s),e.off(f.REMOVEALL,this.hideDynamicLine),e.off(f.UNDO,this.#m),e.off(f.DOUBLECLICK,this.#v);};hideDynamicLine=()=>{let{map:e,tiles:t}=this.#e;this.#i=null,this.#o=null,this.#n=null,e.off("mousemove",this.#s),t.renderLines(W,p.LineDynamicSource),e.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};showDynamicLine=()=>{let{map:e}=this.#e,t=[this.#i?.lng,this.#i?.lat],i=[this.#o?.lng,this.#o?.lat];this.#n=M.getLine(t,i),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.#o&&this.#h({lng:this.#o?.lng,lat:this.#o?.lat}),e.on("mousemove",this.#s);};#h=e=>{if(!this.#n)return;let{tiles:t}=this.#e;this.#n.features[0].geometry.coordinates[1]=[e.lng,e.lat],t.renderLines(this.#n,p.LineDynamicSource);};#p=e=>{this.#h(e.lngLat);};#f=e=>{let{mode:t}=this.#e,i=m.isFeatureTriggered(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.#o={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hideDynamicLine();};#m=e=>{let{store:t,mode:i}=this.#e;if(!i.getClosedGeometry()){let o=e.target.unproject({x:e.originalEvent.x,y:e.originalEvent.y});this.#o={lng:o.lng,lat:o.lat},this.#i=t.tail?.val,this.showDynamicLine();}};#v=e=>{let{store:t,mode:i}=this.#e;i.getClosedGeometry()||(this.#o={lng:e.coordinates.lng,lat:e.coordinates.lat},this.#i=t.tail?.val,this.showDynamicLine());}};var we=22,oe=class{props;#e;#t;constructor(e){this.props=e,this.#e=!1,this.#t=null;}initEvents(){let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mousemove",r.LineLayerTransparent,this.#n),e.on("mouseenter",r.LineLayerTransparent,this.#s),e.on("mouseleave",r.LineLayerTransparent,this.#r);}removeEvents(){let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mousemove",r.LineLayerTransparent,this.#n),e.off("mouseenter",r.LineLayerTransparent,this.#s),e.off("mouseleave",r.LineLayerTransparent,this.#r);}#i=e=>{let{store:t,map:i,mode:o}=this.props;if(_e(e))return;let s=Me(e,t);s&&(y.addPoint({...s,total:t.size},i,o),be(e,this.props));};#o=e=>{E.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)&&E.updatePointsData(e);};#n=C(e=>{if(m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer]))return;let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(this.#t=e,!this.#e&&(this.#e=!0,requestAnimationFrame(()=>{this.#t&&(this.#o(this.#t),this.#e=!1);})));},we);#s=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer])||(t.lineMouseEnter=!0,E.setSinglePointVisible(e));};#r=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(t.lineMouseLeave=!0,E.setSinglePointHidden(e));}};var ne=class{props;#e;#t;#i;#o;constructor(e){this.props=e,this.#e=new te(e),this.#t=new oe(e),this.#i=null,this.#o="default";}init(){this.#n(),this.#s(),this.#r();}#n=()=>{window.innerWidth<=768||this.props.options.dynamicLine&&(this.#i=new ie(this.props));};#s(){!this.props.mode.getBreak()&&(this.#t.initEvents(),this.props.options.dynamicLine&&this.#i?.initDynamicEvents());}#r(){this.props.mode.addObserver(this.#h),this.props.mouseEvents.addObserver(this.#c);}remove(){this.#a(),this.#l();}#a(){this.props.mode.removeObserver(this.#h),this.props.mouseEvents.removeObserver(this.#c),this.props.options.dynamicLine&&this.#i?.removeConsumers();}#l(){this.#e.removeBreakEvents(),this.#t.removeEvents(),this.props.options.dynamicLine&&(this.#i?.removeEvents(),this.#i?.removeLine());}#c=e=>{let{type:t,data:i}=e,{mode:o}=this.props;if(!(!i||!o.getBreak()))switch(t){case"pointMouseDown":this.#e.removeBreakEvents(),this.#e.hideBreakLine();break;case"pointMouseUp":this.#e.initBreakEvents();break;}};#h=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.#o==="break"&&(this.#e.removeBreakEvents(),this.#t.initEvents(),this.#o="default"),t==="BREAK_CHANGED"&&i&&this.#o==="default"&&(this.#t.removeEvents(),this.#e.initBreakEvents(),this.#o="break");}};var se=class{#e;#t;#i;constructor(e){this.#t=e,this.#e=!1,this.#i=new S,e.mode.addObserver(this.#o);}initEvents(){let{map:e}=this.#t;e.on("click",r.FirstPointLayer,this.#n),e.on("mouseenter",r.FirstPointLayer,this.#c),e.on("mouseleave",r.FirstPointLayer,this.#a),e.on("mouseup",r.FirstPointLayer,this.#r),e.on("mousedown",r.FirstPointLayer,this.#s);}removeEvents(){let{map:e}=this.#t;e.off("click",r.FirstPointLayer,this.#n),e.off("mouseenter",r.FirstPointLayer,this.#c),e.off("mouseleave",r.FirstPointLayer,this.#a),e.off("mouseup",r.FirstPointLayer,this.#r);}#o=e=>{let{map:t,store:i}=this.#t,{type:o,data:s}=e;o==="MODE_CHANGED"&&(s==="line"||s==="polygon"?t.on("click",r.FirstPointLayer,this.#n):t.off("click",r.FirstPointLayer,this.#n),u.canCloseGeometry(i)&&L.togglePointCircleRadius(t,"large"));};#n=()=>{let{store:e,map:t,mode:i,tiles:o}=this.#t;if(i.getMode()==="polygon"&&t.setLayoutProperty(r.PolygonLayer,"visibility","visible"),u.canCloseGeometry(e)){u.closeGeometry(e,i);let s=Object.assign({},e.head?.val,{id:b(),total:e.size});y.addPoint(s,t,i),L.togglePointCircleRadius(t,"default"),o.render();}};#s=()=>{this.#e=!0,this.#i.remove();};#r=()=>{this.#e=!1;};#a=()=>{let{mouseEvents:e}=this.#t;this.#e||(e.firstPointMouseLeave=!0,this.#i.remove());};#l=()=>{let{mode:e,options:t}=this.#t;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};#c=e=>{let{mode:t,mouseEvents:i,store:o}=this.#t;if(!(t.getClosedGeometry()||this.#e)&&(i.firstPointMouseEnter=!0,u.canCloseGeometry(o))){let{x:s,y:a}=e.originalEvent;if(s&&a){this.#i.create({label:this.#l(),placement:"bottom"});let v=this.#i._label?this.#i._label.clientWidth/2:0;this.#i.setPosition({x:s-v,y:a+14});}}}};var re=class{#e;#t;#i;#o;#n;#s;#r;#a;constructor(e){this.#e=e,this.#t=void 0,this.#i=null,this.#o=null,this.#n=null,this.#s=new se(e),this.#r=!1,this.#a=null;}#l=()=>{let{map:e}=this.#e;e.on("click",r.FirstPointLayer,this.#p),e.on("mouseenter",r.FirstPointLayer,this.#L),e.on("mouseleave",r.FirstPointLayer,this.#g),e.on("mousedown",r.FirstPointLayer,this.#d),e.on("mouseup",r.FirstPointLayer,this.#u),e.on("touchend",r.FirstPointLayer,this.#u),e.on("touchstart",r.FirstPointLayer,this.#d),this.#s.initEvents();};initEvents=()=>{let{map:e}=this.#e;e.on("click",this.#m),e.on("dblclick",this.#h),e.on("click",r.PointsLayer,this.#p),e.on("mouseenter",r.PointsLayer,this.#L),e.on("mouseleave",r.PointsLayer,this.#g),e.on("mousedown",r.PointsLayer,this.#d),e.on("mouseup",r.PointsLayer,this.#u),e.on("touchend",r.PointsLayer,this.#u),e.on("touchstart",r.PointsLayer,this.#d),this.#l();};#c=()=>{let{map:e}=this.#e;e.off("click",r.FirstPointLayer,this.#p),e.off("mouseenter",r.FirstPointLayer,this.#L),e.off("mouseleave",r.FirstPointLayer,this.#g),e.off("mousedown",r.FirstPointLayer,this.#d),e.off("mouseup",r.FirstPointLayer,this.#u),e.off("touchend",r.PointsLayer,this.#u),e.off("touchstart",r.PointsLayer,this.#d),this.#s.removeEvents();};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#m),e.off("dblclick",this.#h),e.off("mousemove",this.#y),e.off("click",r.PointsLayer,this.#p),e.off("mouseenter",r.PointsLayer,this.#L),e.off("mouseleave",r.PointsLayer,this.#g),e.off("mousedown",r.PointsLayer,this.#d),e.off("mouseup",r.PointsLayer,this.#u),this.#c();};#h=e=>{e.preventDefault();};#p=e=>{let{store:t,tiles:i,panel:o,map:s,mouseEvents:a}=this.#e;L.isDoubleClick()&&this.#o&&(t.removeStepById(this.#o.id),o.onPointRemove(t.tail?.val),y.pointDoubleClick({...this.#o,total:t.size},this.#e.map),u.switchToLineModeIfCan(this.#e));let c=m.queryPointId(s,e.point);P.isLastPoint(t,c)&&(a.lastPointMouseClick=!0,a.lastPointMouseUp=!1),i.render();};#f=e=>m.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer,r.LineLayerTransparent,r.LineLayerBreak]);#m=e=>{let{mode:t,mouseEvents:i,map:o}=this.#e;t.getClosedGeometry()||this.#f(e)||(i.lastPointMouseClick&&(i.lastPointMouseClick=!1),o.getCanvasContainer().style.cursor="grab",E.addPointToMap(e,this.#e),E.setSinglePointHidden(e));};#v=e=>{e.originalEvent.buttons===0&&this.#u();};#E=e=>{let{tiles:t}=this.#e;t.renderOnMouseMove(this.#n,e.lngLat);};#y=C(e=>{this.#a=e,this.#r||(this.#r=!0,requestAnimationFrame(()=>{!this.#o||!this.#a||(E.updateSelectedStepLatLng(this.#a,this.#o),this.#v(this.#a),this.#E(this.#a),this.#r=!1);}));},15);#L=e=>{let{mouseEvents:t,map:i,store:o}=this.#e;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;E.setSinglePointHidden(e);let s=m.queryPointId(i,e.point);P.isLastPoint(o,s)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let a=o.findStepById(s);a&&(this.#i=a,y.enterPoint(Object.assign({},a,{total:o.size}),i));};#g=e=>{let{mouseEvents:t,store:i,map:o}=this.#e;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let s=m.queryPointId(o,e.point);P.isLastPoint(i,s)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),y.leavePoint(Object.assign({},this.#i,{total:i.size}),o);};#P=()=>{let{store:e,panel:t}=this.#e;this.#o&&P.isLastPoint(e,this.#o.id)&&t.hidePanel();};#M=e=>{let{store:t,map:i}=this.#e,o=m.queryPointId(i,e.point),s=t.findStepById(o);s&&(this.#o=s);};#d=e=>{e.preventDefault();let{mouseEvents:t,map:i,store:o}=this.#e;L.removeTransparentLine(i),this.#M(e),this.#P();let s=m.queryPointId(i,e.point);this.#n=u.getGeometryIndex(o,s),t&&(t.pointMouseDown=!0),this.#t=e.lngLat,i.on("mousemove",this.#y),i.on("touchmove",this.#y);};#u=()=>{let{mouseEvents:e,store:t,panel:i,map:o,options:s}=this.#e;e.pointMouseUp=!0,this.#o&&(P.isLastPoint(t,this.#o.id)&&t.tail?.val&&i?.setPanelLocation(t.tail.val),i?.showPanel(),y.movePoint({id:this.#o.id,total:t.size,end:{lat:this.#o.lat,lng:this.#o.lng},start:this.#t},o)),e&&(e.pointMouseDown=!1),L.addTransparentLine(o,s),o.off("mousemove",this.#y),o.off("touchmove",this.#y);}};var ae=class extends N{#e;#t;#i;#o;#n;constructor(e){super({...e}),this.#e=e,this.#t=new ee(e),this.#i=new X(e),this.#o=new re(e),this.#n=new ne(e),e.map.on("mode:initialize",this.#s),e.map.on("mode:remove",this.#r);}#s=()=>{this.#n.init(),this.#t?.initEvents(),this.#o?.initEvents();};#r=()=>{this.#t?.removeEvents(),this.#o?.removeEvents(),this.#n?.remove();};removeMapEventsAndConsumers=()=>{this.#t?.removeEvents(),this.#o?.removeEvents(),this.#i?.remove(),this.#n?.remove(),this.#e.map.off("mode:initialize",this.#s);}};var le=class{#e;_line;_polygon;_break;_container;constructor(e){this.#e=e.options,this._line=void 0,this._polygon=void 0,this._break=void 0,this._container=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl(e);}createControlButton=(e,t,i,o)=>{let s=this.#e.panel.size,a=l.create("button",`control-button control-button-${s}`,this._container);return a.setAttribute("aria-label",t),a.setAttribute("data-type",e),i&&a.classList.add("control-button-active"),o&&(a.setAttribute("disabled","true"),a.setAttribute("aria-disabled","true")),l.create("span",`icon ${e} icon-${s}`,a),a};#t=e=>{let{mode:t,options:i}=e,o=this.#e.modes.line.visible,s=i.locale.line;o&&(this._line=this.createControlButton("line",s,t.getMode()==="line"));};#i=e=>{let{mode:t,options:i}=e,o=this.#e.modes.polygon.visible,s=i.locale.polygon;o&&(this._polygon=this.createControlButton("polygon",s,t.getMode()==="polygon"));};#o=e=>{let{mode:t,options:i}=e,o=this.#e.modes.breakGeometry.visible,s=i.locale.break;if(o){let c=!this.#e?.initial?.closeGeometry,v=t.getBreak();this._break=this.createControlButton("break",s,v,c);}};createControl=e=>{this.#t(e),this.#i(e),this.#o(e);};getContainer=()=>this._container};function De(n){return n.initial?.geometry?n.initial?.geometry:n.modes.initial?n.modes.initial:null}var ce=class extends O{#e;#t;#i;constructor(e){super(),this.#e=De(e),this.#t=!1,this.#i=e.initial?.closeGeometry??!1;}getMode=()=>this.#e;setMode=e=>{this.#e=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.#t;setBreak=e=>{this.#t=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.#i;setClosedGeometry=e=>{this.#i=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.#i});};isPolygon=()=>this.#e==="polygon"&&this.#i;reset=()=>{this.setMode(this.getMode()),this.setClosedGeometry(!1);};pingConsumers=()=>{this.notify({type:"MODE_CHANGED",data:this.getMode()}),this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.getClosedGeometry()});}};var he=class{#e;#t;constructor(e){this.#e=e,this.#t=this.#e.map.getCanvasContainer(),this.#t.style.cursor=e.mode.getMode()?g.CROSSHAIR:g.AUTO,this.#i();}set=e=>{this.#t.style.cursor=e;};get=()=>this.#t.style.cursor;handleMouseLeave=()=>{let{mouseEvents:e,mode:t}=this.#e;if(!e.pointMouseDown){if(!t.getMode()){this.set(g.AUTO);return}t.getClosedGeometry()?this.set(g.AUTO):this.set(g.CROSSHAIR);}};handleFirstPointMouseEnter=()=>{let{mode:e,store:t}=this.#e;e.getClosedGeometry()&&this.set(g.MOVE),u.canCloseGeometry(t)&&this.set(g.POINTER);};#i(){let{mouseEvents:e}=this.#e;e.addObserver(this.#o);}removeConsumers(){let{mouseEvents:e}=this.#e;e.removeObserver(this.#o);}#o=e=>{let{mode:t,mouseEvents:i}=this.#e;if(t.getBreak())return;let{type:o,data:s}=e;if(s)switch(o){case"pointMouseDown":this.set(g.GRABBING);break;case"pointMouseUp":this.set(g.GRAB);break;case"pointMouseEnter":if(i.pointMouseDown)return;this.set(g.GRAB);break;case"pointMouseLeave":this.handleMouseLeave();break;case"lineMouseEnter":if(i.pointMouseDown)return;this.set(g.POINTER);break;case"lineMouseLeave":this.handleMouseLeave();break;case"firstPointMouseEnter":this.handleFirstPointMouseEnter();break;case"firstPointMouseLeave":this.handleMouseLeave();break;case"lastPointMouseEnter":this.set(g.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var pe=class extends O{#e;#t;#i;#o;#n;#s;#r;#a;#l;#c;#h;#p;constructor(){super(),this.#e=!1,this.#t=!1,this.#i=!1,this.#o=!1,this.#n=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#l=!1,this.#c=!1,this.#h=!1,this.#p=!1;}get firstPointMouseEnter(){return this.#e}set firstPointMouseEnter(e){this.#e=e,this.notify({type:"firstPointMouseEnter",data:e});}get firstPointMouseLeave(){return this.#t}set firstPointMouseLeave(e){this.#t=e,this.notify({type:"firstPointMouseLeave",data:e});}get lastPointMouseClick(){return this.#i}set lastPointMouseClick(e){this.#i=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#o}set lastPointMouseUp(e){this.#o=e,this.notify({type:"lastPointMouseUp",data:e});}get lastPointMouseEnter(){return this.#n}set lastPointMouseEnter(e){this.#n=e,this.notify({type:"lastPointMouseEnter",data:e});}get lastPointMouseLeave(){return this.#s}set lastPointMouseLeave(e){this.#s=e,this.notify({type:"lastPointMouseLeave",data:e});}get pointMouseDown(){return this.#r}set pointMouseDown(e){this.#r=e,this.notify({type:"pointMouseDown",data:e});}get pointMouseUp(){return this.#a}set pointMouseUp(e){this.#a=e,this.notify({type:"pointMouseUp",data:e});}get pointMouseEnter(){return this.#l}set pointMouseEnter(e){this.#l=e,this.notify({type:"pointMouseEnter",data:e});}get pointMouseLeave(){return this.#c}set pointMouseLeave(e){this.#c=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#h}set lineMouseEnter(e){this.#h=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#p}set lineMouseLeave(e){this.#p=e,this.notify({type:"lineMouseLeave",data:e});}};var U=class{static allStepsHaveIds(e){return e.every(t=>"id"in t&&t.id!==void 0)}static checkIfMissingIds(e,t){let i=!t,o=!this.allStepsHaveIds(e);if(i&&o)throw new Error(R.MISSING_IDS)}static checkIfEnoughPointsToClose(e,t){if(t&&e.length<3)throw new Error(R.NOT_ENOUGH_POINTS_TO_CLOSE)}static checkIfPolygonIsClosed(e){let{closeGeometry:t,steps:i}=e;if(i){let o=i[0]?.lng,s=i[i.length-1]?.lng,a=i[0]?.lat,c=i[i.length-1]?.lat;if((o!==s||a!==c)&&t)throw new Error(R.FIRST_LAST_POINT_NOT_EQUAL)}}static checkInitialStepsOption(e){let{closeGeometry:t,generateId:i,steps:o}=e;this.checkIfMissingIds(o,i),this.checkIfEnoughPointsToClose(o,t),this.checkIfPolygonIsClosed(e);}static init(e){return e?{panel:Ae(e),modes:Ie(e),layersPaint:Be(e),initial:e.initial||d.initial,locale:Ne(e),dynamicLine:e.dynamicLine??d.dynamicLine}:d}};function Ae(n){return {size:n.panel?.size||d.panel.size,buttons:{undo:{visible:n.panel?.buttons?.undo?.visible??d.panel.buttons.undo.visible},delete:{visible:n.panel?.buttons?.delete?.visible??d.panel.buttons.delete.visible},save:{visible:n.panel?.buttons?.save?.visible??d.panel.buttons.save.visible,clearOnSave:n.panel?.buttons?.save?.clearOnSave??d.panel.buttons.save.clearOnSave}}}}function Ie(n){return {initial:n.modes?.initial||d.modes.initial,line:{visible:n?.modes?.line?.visible!==void 0?n.modes.line.visible:n?.initial?.geometry==="line"||d.modes.line.visible,closeGeometry:n?.modes?.line?.closeGeometry??n?.initial?.closeGeometry??d.modes.line.closeGeometry},polygon:{visible:n?.modes?.polygon?.visible!==void 0?n.modes.polygon.visible:n?.initial?.geometry==="polygon"||d.modes.polygon.visible},breakGeometry:{visible:n?.modes?.breakGeometry?.visible??d.modes.breakGeometry.visible}}}function Be(n){return {onLinePoint:{"circle-radius":n.layersPaint?.onLinePoint?.["circle-radius"]||T["circle-radius"],"circle-color":n.layersPaint?.onLinePoint?.["circle-color"]||T["circle-color"],"circle-stroke-color":n.layersPaint?.onLinePoint?.["circle-stroke-color"]||T["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.onLinePoint?.["circle-stroke-width"]||T["circle-stroke-width"],...n.layersPaint?.onLinePoint},firstPoint:{"circle-radius":n.layersPaint?.firstPoint?.["circle-radius"]||k["circle-radius"],"circle-color":n.layersPaint?.firstPoint?.["circle-color"]||k["circle-color"],"circle-stroke-color":n.layersPaint?.firstPoint?.["circle-stroke-color"]||k["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.firstPoint?.["circle-stroke-width"]||k["circle-stroke-width"],...n.layersPaint?.firstPoint},points:{"circle-radius":n.layersPaint?.points?.["circle-radius"]||w["circle-radius"],"circle-color":n.layersPaint?.points?.["circle-color"]||w["circle-color"],"circle-stroke-color":n.layersPaint?.points?.["circle-stroke-color"]||w["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.points?.["circle-stroke-width"]||w["circle-stroke-width"],...n.layersPaint?.points},line:{"line-width":n.layersPaint?.line?.["line-width"]||I["line-width"],"line-color":n.layersPaint?.line?.["line-color"]||I["line-color"],"line-opacity":n.layersPaint?.line?.["line-opacity"]||I["line-opacity"],...n.layersPaint?.line},polygon:{"fill-color":n.layersPaint?.polygon?.["fill-color"]||G["fill-color"],"fill-opacity":n.layersPaint?.polygon?.["fill-opacity"]||G["fill-opacity"],...n.layersPaint?.polygon},breakLine:{"line-width":n.layersPaint?.breakLine?.["line-width"]||B["line-width"],"line-color":n.layersPaint?.breakLine?.["line-color"]||B["line-color"],"line-dasharray":n.layersPaint?.breakLine?.["line-dasharray"]||B["line-dasharray"],...n.layersPaint?.breakLine}}}function Ne(n){return {save:n.locale?.save??d.locale.save,delete:n.locale?.delete??d.locale.delete,undo:n.locale?.undo??d.locale.undo,line:n.locale?.line??d.locale.line,polygon:n.locale?.polygon??d.locale.polygon,break:n.locale?.break??d.locale.break,closeLine:n.locale?.closeLine??d.locale.closeLine,createPolygon:n.locale?.createPolygon??d.locale.createPolygon}}var ye=class n{#e;#t;#i;#o;#n;#s;#r;#a;#l;static#c=null;static#h=!1;constructor(e){if(this.#o=U.init(e),this.#o.initial&&U.checkInitialStepsOption(this.#o.initial),n.#h)throw new Error("Use 'DrawLibre.getInstance()' instead of 'new DrawLibre()'.");n.#h=!0,this.#t=void 0,this.#i=void 0,this.#n=void 0,this.#s=void 0,this.#r=void 0,this.#l=void 0,this.#a=void 0;}static getInstance(e){return n.#c||(n.#c=new n(e)),n.#c}onAdd(e){this.#t=new H(this.#o),this.#i=new ce(this.#o),this.#r=new Y({map:e,mode:this.#i,options:this.#o,store:this.#t}),this.#s=new N({map:e,store:this.#t,options:this.#o,mode:this.#i});let t=new le({options:this.#o,mode:this.#i});return this.#l=new pe,this.#a=new he({map:e,mode:this.#i,mouseEvents:this.#l,store:this.#t}),this.#n=new ae({map:e,store:this.#t,options:this.#o,panel:this.#r,control:t,mode:this.#i,tiles:this.#s,mouseEvents:this.#l}),this.#i.getMode()&&e.fire("mode:initialize"),this.#i.pingConsumers(),this.#e=t.getContainer(),this.#e}onRemove(){this.#a?.removeConsumers(),this.#s?.removeTiles(),this.#n?.removeMapEventsAndConsumers(),this.#r?.removePanel(),this.#t?.reset(),this.#i?.unsubscribe(),this.#e&&l.remove(this.#e);}setSteps=e=>{if(Array.isArray(e))e.forEach(t=>{let i={...t,id:t.id||b()};this.#t?.push(i);});else throw new Error("Invalid argument. Expected an array of steps.");this.#s?.render();};findStepById=e=>this.#t?.findStepById(e);getAllSteps=(e="array")=>{if(e==="array"&&this.#t)return P.toArray(this.#t.head);if(e==="linkedlist")return this.#t;throw new Error("Invalid type specified. Use 'array' or 'linkedlist'.")};setOptions=e=>{this.#o=e(this.#o);};removeAllSteps=()=>{this.#t?.reset(),this.#r?.removePanel(),this.#s?.render();}};
|
|
5
5
|
|
|
6
|
-
exports.DRAW_LIBRE_EVENTS =
|
|
6
|
+
exports.DRAW_LIBRE_EVENTS = f;
|
|
7
7
|
exports.default = ye;
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, '__esModule', { value: true });
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var l=class o{static docStyle=typeof window<"u"&&window.document&&window.document.documentElement.style;static transformProp=o.testProp(["transform","WebkitTransform"]);static testProp(e){if(!o.docStyle)return e[0];for(let t=0;t<e.length;t++)if(e[t]in o.docStyle)return e[t];return e[0]}static create(e,t,i){let n=window.document.createElement(e);return t!==void 0&&(n.className=t),i&&i.appendChild(n),n}static remove(e){e.parentNode&&e.parentNode.removeChild(e);}static setTransform(e,t){o.transformProp&&e.style&&(e.style[o.transformProp]=t);}static manageEventListener(e,t,i,n,s={}){if(!t)return;let a=e==="add"?"addEventListener":"removeEventListener";"passive"in s?t[a](i,n,s):t[a](i,n,s.capture);}static mouseButton(e){return e.button}static addClassName(e,t){e.classList.contains(t)||e.classList.add(t);}static removeClassName(e,t){e.classList.contains(t)&&e.classList.remove(t);}};var C=class o{lng;lat;constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,this.lat>90||this.lat<-90)throw new Error("Invalid LngLat latitude value: must be between -90 and 90")}static convert(e){if(e instanceof o)return e;if(Array.isArray(e)&&(e.length===2||e.length===3))return new o(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null)return new o(Number("lng"in e?e.lng:e.lon),Number(e.lat));throw new Error("`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]")}};function G(o,...e){for(let t of e)for(let i in t)o[i]=t[i];return o}function ve(o,e,t){let i=new C(o.lng,o.lat);if(o=new C(o.lng,o.lat),e){let n=new C(o.lng-360,o.lat),s=new C(o.lng+360,o.lat),a=t.locationPoint(o).distSqr(e);t.locationPoint(n).distSqr(e)<a?o=n:t.locationPoint(s).distSqr(e)<a&&(o=s);}for(;Math.abs(o.lng-t.center.lng)>180;){let n=t.locationPoint(o);if(n.x>=0&&n.y>=0&&n.x<=t.width&&n.y<=t.height)break;o.lng>t.center.lng?o.lng-=360:o.lng+=360;}return o.lng!==i.lng&&t.locationPoint(o).y>t.height/2-t.getHorizon()?o:i}var de={center:"translate(-50%,-50%)",top:"translate(-50%,0)","top-left":"translate(0,0)","top-right":"translate(-100%,0)",bottom:"translate(-50%,-100%)","bottom-left":"translate(0,-100%)","bottom-right":"translate(-100%,-100%)",left:"translate(0,-50%)",right:"translate(-100%,-50%)"};function Le(o,e,t){let i=o.classList;for(let n in de)i.remove(`maplibregl-${t}-anchor-${n}`);i.add(`maplibregl-${t}-anchor-${e}`);}function ge(o,e,t){t[o]&&t[o].indexOf(e)!==-1||(t[o]=t[o]||[],t[o].push(e));}function me(o,e,t){if(t&&t[o]){let i=t[o].indexOf(e);i!==-1&&t[o].splice(i,1);}}var z=class{_listeners;_oneTimeListeners;_eventedParent;_eventedParentData;on(e,t){return this._listeners=this._listeners||{},ge(e,t,this._listeners),this}off(e,t){return me(e,t,this._listeners),me(e,t,this._oneTimeListeners),this}once(e,t){return t?(this._oneTimeListeners=this._oneTimeListeners||{},ge(e,t,this._oneTimeListeners),this):new Promise(i=>this.once(e,i))}fire(e,t){typeof e=="string"&&(e=new A(e,t||{}));let i=e.type;if(this.listens(i)){e.target=this;let n=this._listeners&&this._listeners[i]?this._listeners[i].slice():[];for(let p of n)p.call(this,e);let s=this._oneTimeListeners&&this._oneTimeListeners[i]?this._oneTimeListeners[i].slice():[];for(let p of s)me(i,p,this._oneTimeListeners),p.call(this,e);let a=this._eventedParent;a&&(G(e,typeof this._eventedParentData=="function"?this._eventedParentData():this._eventedParentData),a.fire(e));}else e instanceof ErrorEvent&&console.error(e.error);return this}listens(e){return this._listeners&&this._listeners[e]&&this._listeners[e].length>0||this._oneTimeListeners&&this._oneTimeListeners[e]&&this._oneTimeListeners[e].length>0||this._eventedParent&&this._eventedParent.listens(e)}setEventedParent(e,t){return this._eventedParent=e,this._eventedParentData=t,this}},A=class{type;constructor(e,t={}){G(this,t),this.type=e;}};var h=class o{x;y;constructor(e,t){this.x=e,this.y=t;}mag(){return Math.sqrt(this.x*this.x+this.y*this.y)}equals(e){return this.x===e.x&&this.y===e.y}dist(e){return Math.sqrt(this.distSqr(e))}distSqr(e){let t=e.x-this.x,i=e.y-this.y;return t*t+i*i}angle(){return Math.atan2(this.y,this.x)}angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)}angleWith(e){return this.angleWithSep(e.x,e.y)}angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)}_matMult(e){let t=e[0]*this.x+e[1]*this.y,i=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=i,this}_add(e){return this.x+=e.x,this.y+=e.y,this}_sub(e){return this.x-=e.x,this.y-=e.y,this}_mult(e){return this.x*=e,this.y*=e,this}_div(e){return this.x/=e,this.y/=e,this}_multByPoint(e){return this.x*=e.x,this.y*=e.y,this}_divByPoint(e){return this.x/=e.x,this.y/=e.y,this}_unit(){return this._div(this.mag()),this}_perp(){let e=this.y;return this.y=this.x,this.x=-e,this}_rotate(e){let t=Math.cos(e),i=Math.sin(e),n=t*this.x-i*this.y,s=i*this.x+t*this.y;return this.x=n,this.y=s,this}_rotateAround(e,t){let i=Math.cos(e),n=Math.sin(e),s=t.x+i*(this.x-t.x)-n*(this.y-t.y),a=t.y+n*(this.x-t.x)+i*(this.y-t.y);return this.x=s,this.y=a,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}static convert(e){if(e instanceof o)return e;if(Array.isArray(e))return new o(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new o(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")}};var Oe={closeButton:!0,closeOnClick:!0,focusAfterOpen:!0,className:"",maxWidth:"240px",subpixelPositioning:!1},xe=["a[href]","[tabindex]:not([tabindex='-1'])","[contenteditable]:not([contenteditable='false'])","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])"].join(", "),Y=class extends z{_map;options;_content;_container;_closeButton;_tip;_lngLat;_trackPointer;_pos;_flatPos;constructor(e){super(),this.options=G(Object.create(Oe),e);}addTo(e){return this._map&&this.remove(),this._map=e,this.options.closeOnClick&&this._map.on("click",this._onClose),this.options.closeOnMove&&this._map.on("move",this._onClose),this._map.on("remove",this.remove),this._update(),this._focusFirstElement(),this._trackPointer?(this._map.on("mousemove",this._onMouseMove),this._map.on("mouseup",this._onMouseUp),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")):this._map.on("move",this._update),this.fire(new A("open")),this}isOpen(){return !!this._map}remove=()=>(this._content&&l.remove(this._content),this._container&&(l.remove(this._container),delete this._container),this._map&&(this._map.off("move",this._update),this._map.off("move",this._onClose),this._map.off("click",this._onClose),this._map.off("remove",this.remove),this._map.off("mousemove",this._onMouseMove),this._map.off("mouseup",this._onMouseUp),this._map.off("drag",this._onDrag),this._map._canvasContainer.classList.remove("maplibregl-track-pointer"),delete this._map,this.fire(new A("close"))),this);getLngLat(){return this._lngLat}setLngLat(e){return this._lngLat=C.convert(e),this._pos=null,this._flatPos=null,this._trackPointer=!1,this._update(),this._map&&(this._map.on("move",this._update),this._map.off("mousemove",this._onMouseMove),this._container&&this._container.classList.remove("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.remove("maplibregl-track-pointer")),this}trackPointer(){return this._trackPointer=!0,this._pos=null,this._flatPos=null,this._update(),this._map&&(this._map.off("move",this._update),this._map.on("mousemove",this._onMouseMove),this._map.on("drag",this._onDrag),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")),this}getElement(){return this._container}setText(e){return this.setDOMContent(document.createTextNode(e))}setHTML(e){let t=document.createDocumentFragment(),i=document.createElement("body"),n;for(i.innerHTML=e;n=i.firstChild,!!n;)t.appendChild(n);return this.setDOMContent(t)}getMaxWidth(){return this._container?.style.maxWidth}setMaxWidth(e){return this.options.maxWidth=e,this._update(),this}setDOMContent(e){if(this._content)for(;this._content.hasChildNodes();)this._content.firstChild&&this._content.removeChild(this._content.firstChild);else this._content=l.create("div","maplibregl-popup-content",this._container);return this._content.appendChild(e),this._createCloseButton(),this._update(),this._focusFirstElement(),this}addClassName(e){return this._container&&this._container.classList.add(e),this}removeClassName(e){return this._container&&this._container.classList.remove(e),this}setOffset(e){return this.options.offset=e,this._update(),this}toggleClassName(e){if(this._container)return this._container.classList.toggle(e)}setSubpixelPositioning(e){this.options.subpixelPositioning=e;}_createCloseButton(){this.options.closeButton&&(this._closeButton=l.create("button","maplibregl-popup-close-button",this._content),this._closeButton.type="button",this._closeButton.innerHTML="×",this._closeButton.addEventListener("click",this._onClose));}_onMouseUp=e=>{this._update(e.point);};_onMouseMove=e=>{this._update(e.point);};_onDrag=e=>{this._update(e.point);};_update=e=>{let t=this._lngLat||this._trackPointer;if(!this._map||!t||!this._content)return;if(!this._container){if(this._container=l.create("div","maplibregl-popup",this._map.getContainer()),this._tip=l.create("div","maplibregl-popup-tip",this._container),this._container.appendChild(this._content),this.options.className)for(let p of this.options.className.split(" "))this._container.classList.add(p);this._closeButton&&this._closeButton.setAttribute("aria-label",this._map._getUIString("Popup.Close")),this._trackPointer&&this._container.classList.add("maplibregl-popup-track-pointer");}if(this.options.maxWidth&&this._container.style.maxWidth!==this.options.maxWidth&&(this._container.style.maxWidth=this.options.maxWidth),this._map.transform.renderWorldCopies&&!this._trackPointer?this._lngLat=ve(this._lngLat,this._flatPos,this._map.transform):this._lngLat=this._lngLat?.wrap(),this._trackPointer&&!e)return;let i=this._flatPos=this._pos=this._trackPointer&&e?e:this._map.project(this._lngLat);this._map.terrain&&(this._flatPos=this._trackPointer&&e?e:this._map.transform.locationPoint(this._lngLat));let n=this.options.anchor,s=Ee(this.options.offset);if(!n){let p=this._container.offsetWidth,L=this._container.offsetHeight,k;i.y+s.bottom.y<L?k=["top"]:i.y>this._map.transform.height-L?k=["bottom"]:k=[],i.x<p/2?k.push("left"):i.x>this._map.transform.width-p/2&&k.push("right"),k.length===0?n="bottom":n=k.join("-");}let a=i.add(s[n]);this.options.subpixelPositioning||(a=a.round()),l.setTransform(this._container,`${de[n]} translate(${a.x}px,${a.y}px)`),Le(this._container,n,"popup");};_focusFirstElement(){if(!this.options.focusAfterOpen||!this._container)return;let e=this._container.querySelector(xe);e&&e.focus();}_onClose=()=>{this.remove();}};function Ee(o){if(o)if(typeof o=="number"){let e=Math.round(Math.abs(o)/Math.SQRT2);return {center:new h(0,0),top:new h(0,o),"top-left":new h(e,e),"top-right":new h(-e,e),bottom:new h(0,-o),"bottom-left":new h(e,-e),"bottom-right":new h(-e,-e),left:new h(o,0),right:new h(-o,0)}}else if(o instanceof h||Array.isArray(o)){let e=h.convert(o);return {center:e,top:e,"top-left":e,"top-right":e,bottom:e,"bottom-left":e,"bottom-right":e,left:e,right:e}}else return {center:h.convert(o.center||[0,0]),top:h.convert(o.top||[0,0]),"top-left":h.convert(o["top-left"]||[0,0]),"top-right":h.convert(o["top-right"]||[0,0]),bottom:h.convert(o.bottom||[0,0]),"bottom-left":h.convert(o["bottom-left"]||[0,0]),"bottom-right":h.convert(o["bottom-right"]||[0,0]),left:h.convert(o.left||[0,0]),right:h.convert(o.right||[0,0])};else return Ee(new h(0,0))}var j=class{#e;#t;#i;_undoButton;_deleteButton;_saveButton;_container;constructor(e){this.#e=e,this._container=void 0,this.#i=!1,this.#n().then(()=>{this.#o(),e.map.fire("panel:ready");});}#n=async()=>{this.#e;try{this.#t=new Y({offset:16,closeButton:!1,closeOnClick:!1,closeOnMove:!1,anchor:"bottom"});}catch(t){console.error("POPUP LOAD ERROR",t);}};#o=()=>{let{store:e}=this.#e;this.createPanel(),e.tail?.val&&this.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng});};setPanelLocation=e=>{let{map:t}=this.#e;this.#i&&(this.#i=!1,this.showPanel()),this._container&&this.#t&&this.#t.setLngLat(e).setDOMContent(this._container).addTo(t);};hidePanel=()=>{!this.#i&&(this.#t?.addClassName("hide-panel"),this.#i=!0);};showPanel=()=>{this.#t?.removeClassName("hide-panel"),this.#i=!1;};onPointRemove=e=>{e?this.setPanelLocation(e):this.hidePanel();};removePanel=()=>{this._container&&l.remove(this._container),this.#t?.remove();};createButton=(e,t,i,n)=>{let s=l.create("button",`panel-button panel-button-${i}`,n);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`icon ${e} icon-${i}`,s),s};createPanel=()=>{let{options:e}=this.#e,{locale:t}=e,{undo:i,delete:n,save:s}=e.panel.buttons,a=e.panel.size,p=document.querySelector(".maplibregl-popup-content"),L=l.create("div","dashboard",p);i.visible&&(this._undoButton=this.createButton("undo",t.undo,a,L)),n.visible&&(this._deleteButton=this.createButton("delete",t.delete,a,L)),s.visible&&(this._saveButton=this.createButton("save",t.save,a,L)),this._container=L;}};var W={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[]}}]},V={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[]}}]},Pe={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}}]},r={LineDynamicLayer:"mdl-line-dynamic-layer",LineLayer:"mdl-line-layer",LineLayerTransparent:"mdl-line-layer-transparent",LineLayerBreak:"mdl-line-break-layer",PolygonLayer:"mdl-polygon-layer",PointsLayer:"mdl-points-layer",SinglePointLayer:"mdl-single-point-layer",FirstPointLayer:"mdl-first-point-layer"},u={LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",LineSource:"mdl-line-source",PolygonSource:"mdl-polygon-source",PointsSource:"mdl-points-source",SinglePointSource:"mdl-single-point-source"},I={large:6.5,default:5.5},K={large:"#FF6464",default:"#666666"},T={"circle-radius":I.default,"circle-color":"#FEFFFE","circle-stroke-color":K.default,"circle-stroke-width":3},w={"circle-radius":I.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},H={"fill-color":"grey","fill-opacity":.4},B={"line-width":3,"line-color":"grey","line-opacity":.7},D={"circle-radius":I.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},N={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},$=o=>[{id:r.SinglePointLayer,source:u.SinglePointSource,type:"circle",paint:o.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:u.PolygonSource,type:"fill",paint:o.layersPaint.polygon,layout:{visibility:"none"}},{id:r.LineDynamicLayer,source:u.LineDynamicSource,type:"line",paint:o.layersPaint.line,layout:{visibility:"none"}},{id:r.LineLayer,source:u.LineSource,type:"line",paint:o.layersPaint.line,layout:{visibility:"visible"}},{id:r.LineLayerTransparent,source:u.LineSource,type:"line",paint:{"line-width":4,"line-color":"transparent"}},{id:r.LineLayerBreak,source:u.LineSourceBreak,type:"line",paint:o.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:u.PointsSource,type:"circle",paint:o.layersPaint.points,filter:["==",["get","isFirst"],!1]},{id:r.FirstPointLayer,source:u.PointsSource,type:"circle",paint:o.layersPaint.firstPoint,filter:["==",["get","isFirst"],!0]}];var g=class{static#e=0;static#t=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",I.large),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",K.large);};static#i=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",I.default),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",K.default);};static togglePointCircleRadius=(e,t)=>{t==="large"?this.#t(e):this.#i(e);};static removeTransparentLine=e=>{e.removeLayer(r.LineLayerTransparent);};static addTransparentLine=(e,t)=>{if(e.getLayer(r.LineLayerTransparent))return;let n=$(t).find(s=>s.id===r.LineLayerTransparent);n&&e.addLayer(n);};static isDoubleClick(){let t=Date.now();return t-this.#e<=400?(this.#e=t,!0):(this.#e=t,!1)}};var y=class{static isFeatureTriggered(e,t){return e.target.queryRenderedFeatures(e.point,{layers:t}).some(n=>t.includes(n.layer.id))}static getPixelCoordinates=(e,t)=>{let{lat:i,lng:n}=t;return e.project([n,i])};static queryPointId=(e,t)=>e.queryRenderedFeatures(t,{layers:[r.PointsLayer,r.FirstPointLayer]})?.[0]?.properties.id},M=class{static#e(e){let t=[],i=e.head,n=new Set;for(;i!==null;){if(n.has(i.val?.id)){e.head&&e.head.val&&t.push([e.head.val.lng,e.head.val.lat]);break}n.add(i.val?.id),i.val&&t.push([i.val.lng,i.val.lat]),i=i.next;}return t}static getAllLines(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}]}}static getLine(e,t){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e,t]}}]}}static getPolygon(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[t]}}]}}static getPoints(e){let t=e.head,i=[],n=new Set;for(;t!==null&&!n.has(t.val?.id);){if(t.val){let s=t.val,a=t.val.id===e.head?.val?.id;i.push({type:"Feature",properties:{id:s.id,lat:s.lat,lng:s.lng,isFirst:a},geometry:{type:"Point",coordinates:[s.lng,s.lat]}});}n.add(t.val?.id),t=t.next;}return {type:"FeatureCollection",features:i}}},d=class o{static getGeometryIndex=(e,t)=>{let i=e.head,n=0;for(;i!==null;){if(i.val?.id===t)return n;n++,i=i.next;}return -1};static isFirstPoint(e){let t=e.target,i=e.point;return !!t.queryRenderedFeatures(i,{layers:[r.FirstPointLayer]}).length}static distance=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2);static checkIfPointIsOnLine=(e,t,i)=>{let s=this.distance(e,t),a=this.distance(e,i),p=this.distance(i,t);return Math.abs(a+p-s)<.1};static isClosedGeometry=e=>e.tail?.next===e.head;static breakGeometry=(e,t)=>{if(!e.head)return;let i=e.head,n=e.tail;do{if(i?.val?.id===t){i!==e.head&&(n.next=i.next,e.head=i,e.tail=n),e.tail.next=null;return}n=i,i=i.next;}while(i!==e.head)};static closeGeometry=(e,t)=>{e.tail&&(e.tail.next=e.head),t.setClosedGeometry(!0);};static canCloseGeometry=e=>e.size>2&&!this.isClosedGeometry(e);static canBreakClosedGeometry=e=>e.size<=2;static switchToLineModeIfCan=e=>{let{mode:t,store:i,tiles:n,map:s}=e;o.canBreakClosedGeometry(i)&&(i.tail&&i.tail.val&&(i.tail.next=null),t.reset(),g.togglePointCircleRadius(s,"default"),n.renderPolygon(W));}},_=()=>{if("crypto"in window&&"randomUUID"in window.crypto)return window.crypto.randomUUID();function o(){return "0123456789abcdef"[Math.floor(Math.random()*16)]}function e(n){let s="";for(let a=0;a<n;a++)s+=o();return s}function t(n){let s=n===0,a=n===4;return s?8:a?12:4}let i=[];for(let n=0;n<5;n++)i.push(e(t(n)));return i.join("-")},S=(o,e)=>{let t,i=!0;function n(){i&&t&&(o(...t),t=null,i=!1,setTimeout(()=>{i=!0,n();},e));}return function(...s){t=s,n();}};var R=class{#e;#t;#i;#n;constructor(e){this.#e=e,this.#o(),this.render();}#o(){this.#s(),this.#r(),this.#a(r.LineLayer,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.FirstPointLayer),this.#a(r.LineLayerTransparent,r.PointsLayer),this.#a(r.PolygonLayer,r.LineLayer);}#s=()=>{let{map:e}=this.#e;Object.values(u).forEach(t=>{e.getSource(t)||e.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});});};#r=()=>{let{map:e,mode:t,options:i}=this.#e;$(i).forEach(a=>{e.getLayer(a.id)||e.addLayer(a);});let s=e.getLayoutProperty(r.PolygonLayer,"visibility")==="none";t.getMode()==="polygon"&&s&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible");};#a=(e,t)=>{let{map:i}=this.#e,n=i.getLayer(e),s=i.getLayer(t);n&&s&&i.moveLayer(e,t);};#c=()=>{let{map:e}=this.#e;Object.values(u).forEach(t=>{e.getSource(t)&&e.removeSource(t);});};#l=()=>{let{map:e}=this.#e;Object.values(r).forEach(t=>{e.getLayer(t)&&e.removeLayer(t);});};removeTiles=()=>{this.#l(),this.#c();};renderPoints=e=>{let{map:t}=this.#e,i=t.getSource(u.PointsSource);i&&i.setData(e);};renderLines=(e,t)=>{let{map:i}=this.#e,n=i.getSource(t);n&&n.setData(e);};renderPolygon=e=>{let{map:t}=this.#e,i=t.getSource(u.PolygonSource);i&&i.setData(e);};render=()=>{let{mode:e,options:t,store:i}=this.#e,n=M.getPoints(i),s=M.getAllLines(i);if(this.#t=n,this.#i=s,this.renderPoints(n),this.renderLines(s,u.LineSource),t.modes.polygon.visible&&e.isPolygon()){let p=M.getPolygon(i);this.#n=p,this.renderPolygon(p);}};#p=(e,t)=>{if(this.#n.features[0].geometry.coordinates[0][e]=[t.lng,t.lat],e===0){let n=this.#n.features[0].geometry.coordinates[0]?.length-1;this.#n.features[0].geometry.coordinates[0][n]=[t.lng,t.lat];}this.renderPolygon(this.#n);};#h=(e,t)=>{let{mode:i}=this.#e;this.#i.features[0].geometry.coordinates[e]=[t.lng,t.lat];let n=e===0;if(this.#i&&i.getClosedGeometry()&&n){let a=this.#i.features[0].geometry.coordinates?.length-1;this.#i.features[0].geometry.coordinates[a]=[t.lng,t.lat];}this.renderLines(this.#i,u.LineSource);};renderOnMouseMove=(e,t)=>{let{mode:i,options:n}=this.#e;this.#t.features[e].geometry.coordinates=[t.lng,t.lat],this.renderPoints(this.#t),this.#h(e,t),n.modes.polygon.visible&&i.isPolygon()&&this.#p(e,t);};resetGeometries=()=>{this.renderPoints(Pe),this.renderLines(V,u.LineSource),this.renderPolygon(W);}};var ke=8,Te=8,O=class{_container;_label;constructor(){this._container=void 0;}create=e=>{let t=l.create("div","popup-container",document.body),i=l.create("span",`popup-text popup-text-${e.placement}`,t);return i.textContent=e.label,this._container=t,this._label=i,this};#e=()=>{!this._label?.classList.value.includes("popup-text-active")&&this._label?.classList.add("popup-text-active");};#t=()=>this._label?{width:this._label.clientWidth,height:this._label.clientHeight}:{width:0,height:0};#i=e=>{let{bottom:t,left:i}=e.target.getBoundingClientRect(),{width:n,height:s}=this.#t();return {x:i-Te-n,y:t-s-2}};#n=e=>{let{bottom:t,left:i,right:n}=e.target.getBoundingClientRect(),{width:s}=this.#t();return {x:(n-i)/2+i-s/2,y:t+ke}};getPosition=(e,t)=>t==="left"?this.#i(e):this.#n(e);setPosition=e=>{let{x:t,y:i}=e;this._container&&(this._container.style.left=`${t}px`,this._container.style.top=`${i}px`),this.#e();};remove=()=>{this._container&&l.remove(this._container);}};var P={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var Z=(o,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("add",o,t,i);},J=(o,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("remove",o,t,i);},be=(o,e)=>{let t=e.locale.line,i=e.locale.polygon,n=e.locale.break;return {line:t,polygon:i,break:n}[o]};var X=class{#e;constructor(e){this.#e=e,this.#t();}#t=()=>{this.#e.mode.addObserver(this.#r);};removeConsumers=()=>{this.#e.mode.removeObserver(this.#r);};#i=()=>{let{_line:e,_polygon:t,_break:i}=this.#e.control;e?.classList.remove("control-button-active"),t?.classList.remove("control-button-active"),i?.classList.remove("control-button-active");};#n=e=>{this.#i(),e.classList.add("control-button-active");};#o=e=>{let{data:t}=e,{_line:i,_polygon:n,_break:s}=this.#e.control;if(!(!i||!n||!s))switch(t){case"line":this.#n(i);break;case"polygon":this.#n(n);break;}};#s=e=>{let{data:t}=e,{_break:i}=this.#e.control;t?(i?.removeAttribute("disabled"),i?.removeAttribute("aria-disabled")):(i?.setAttribute("disabled","true"),i?.setAttribute("aria-disabled","true"));};#r=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.#o(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.#s(e),t==="BREAK_CHANGED"&&i){let{_break:n}=this.#e.control;this.#n(n);}}};var Q=class{#e;#t;#i;constructor(e){this.#e=e,this.#i=new X(e),this.#t=new O;}initEvents(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&Z(e._line,{...t,click:this.onLineClick}),e._polygon&&Z(e._polygon,{...t,click:this.onPolygonClick}),e._break&&Z(e._break,{...t,click:this.onBreakClick});}}#n(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&J(e._line,{...t,click:this.onLineClick}),e._polygon&&J(e._polygon,{...t,click:this.onPolygonClick}),e._break&&J(e._break,{...t,click:this.onBreakClick});}}remove(){this.#i.removeConsumers(),this.#n(),this.#t.remove();}onButtonEnter=e=>{let{options:t}=this.#e,i=e.target.getAttribute("data-type");if(i){let n=be(i,t);this.#t.create({label:n,placement:"left"}).setPosition(this.#t.getPosition(e,"left"));}};onButtonLeave=()=>{this.#t.remove();};onLineClick=()=>{let{mode:e,tiles:t}=this.#e;e.setMode("line"),t.resetGeometries(),t.render();};onPolygonClick=()=>{let{map:e,mode:t,tiles:i}=this.#e;t.setMode("polygon"),t.isPolygon()&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible"),i.resetGeometries(),i.render();};onBreakClick=()=>{let{map:e,mode:t}=this.#e;t.setBreak(!0),e.getCanvasContainer().style.cursor=P.POINTER;}};var x=class{observers;constructor(){this.observers=new Set;}addObserver(e){this.observers.add(e);}removeObserver(e){this.observers.delete(e);}unsubscribe(){this.observers.clear();}notify(e){this.observers.forEach(t=>t(e));}};var F={EMPTY_INITIAL_STATE:"You passed an empty initial array in the options. Please either remove the 'initial' property or include at least one element in the array.",MISSING_IDS:"You set 'generateId' to false but did not provide IDs for all steps. Please ensure all steps have IDs or set 'generateId' to true.",NOT_ENOUGH_POINTS_TO_CLOSE:"At least three points are required to close a polygon or a line. Please add more points or set 'closeGeometry' to false.",FIRST_LAST_POINT_NOT_EQUAL:"The first and last points of a polygon or a closed linestring must be the same. Please ensure the first and last points are equal or set 'closeGeometry' to false."};var ee=class{val;next;constructor(e=null,t=null){this.val=e,this.next=t;}},U=class extends x{head;tail;size;constructor(e){super();let t=b.initStore(e);this.head=t?t.head:null,this.tail=t?t.tail:null,this.size=t?t.size:0;}push(e){let t=new ee(e);this.head?this.tail&&(this.tail.next=t,this.tail=t):this.head=this.tail=t,this.size++,this.pingConsumers();}insert(e,t){let i=new ee(e,t.next);this.tail===t&&this.head===t.next&&(this.tail=i),t.next=i,this.size++;}findStepById(e){let t=this.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.val&&t.val.id===e)return t.val;i.add(t),t=t.next;}return null}removeStepById(e){if(!this.head)return null;let t=this.head,i=null;for(;t!==null;){if(t?.val?.id===e)return t===this.head?(this.head=t.next,this.tail&&(this.tail.next=t.next)):i.next=t.next,t===this.tail&&(this.tail=i),this.size--,this.pingConsumers(),t;i=t,t.next&&(t=t.next);}return null}reset(){this.head=null,this.tail=null,this.size=0,this.pingConsumers();}pingConsumers=()=>{this.notify({type:"STORE_CHANGED",data:{head:this.head,tail:this.tail,size:this.size}});}},b=class o{static isLastPoint=(e,t)=>e.tail?.val?.id===t;static initStore(e){if(!e?.initial)return null;if(e&&e.initial&&!e.initial.steps.length)throw new Error(F.EMPTY_INITIAL_STATE);if(e&&e.initial.steps){let{steps:n,closeGeometry:s,generateId:a}=e.initial;return o.fromArray(n,s,a)}return null}static#e=e=>e.map(t=>({...t,id:_()}));static buildStepSequence(e){let t=new U;return e.forEach(i=>{t.push(i);}),t}static fromArray(e,t,i){let n=i?this.#e(e):e,s=this.buildStepSequence(n);return t&&s.tail&&(s.tail.next=s.head),s}static toArray(e){if(!e)return [];let t=new Set,i=[],n=e;for(;n!==null&&!t.has(n);)t.add(n),i.push(n.val),n=n.next;return i}};var f={DOUBLECLICK:"mdl:doubleclick",POINTENTER:"mdl:pointenter",POINTLEAVE:"mdl:pointleave",MOVEEND:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REMOVEALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",LINE:"mdl:line",POLYGON:"mdl:polygon",MODECHANGE:"mdl:modechange"};var m={panel:{size:"medium",buttons:{undo:{visible:!0},delete:{visible:!0},save:{visible:!0,clearOnSave:!0}}},modes:{line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{onLinePoint:w,firstPoint:T,points:D,line:B,polygon:H,breakLine:N},initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close line",createPolygon:"Create polygon"}};var v=class{static addPoint(e,t,i){t.fire(f.ADD,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static movePoint(e,t){t.fire(f.MOVEEND,{id:e.id,start_coordinates:{lat:e.start.lat,lng:e.start.lng},end_coordinates:{lat:e.end.lat,lng:e.end.lng},total:e.total,timestamp:Date.now()});}static pointDoubleClick(e,t){t.fire(f.DOUBLECLICK,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){t.fire(f.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){t.fire(f.POINTLEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undoPoint(e,t,i){t.fire(f.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static removeAllPoints(e,t){e.fire(f.REMOVEALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:n,mode:s}=e;n.fire(f.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onModeChange(e){let{map:t,mode:i}=e;t.fire(f.MODECHANGE,{timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static onLineBreak(e){e.fire(f.BREAK);}};var te=class{#e;#t;constructor(e){this.#e=e,this.#t=new O;}initEvents(){let{panel:e}=this.#e;e&&(l.manageEventListener("add",e?._undoButton,"click",this.#o),l.manageEventListener("add",e?._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._undoButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._deleteButton,"click",this.#n),l.manageEventListener("add",e?._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._deleteButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._saveButton,"click",this.onSaveClick),l.manageEventListener("add",e?._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._saveButton,"mouseleave",this.onMouseLeave));}removeEvents(){let{panel:e}=this.#e;e&&e._undoButton&&(l.manageEventListener("remove",e._undoButton,"click",this.#o),l.manageEventListener("remove",e._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._undoButton,"mouseleave",this.onMouseLeave)),e&&e._deleteButton&&(l.manageEventListener("remove",e._deleteButton,"click",this.#n),l.manageEventListener("remove",e._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._deleteButton,"mouseleave",this.onMouseLeave)),e&&e._saveButton&&(l.manageEventListener("remove",e._saveButton,"click",this.onSaveClick),l.manageEventListener("remove",e._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._saveButton,"mouseleave",this.onMouseLeave));}#i=e=>{let{options:t}=this.#e;return {undo:t.locale.undo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let t=e.target.getAttribute("data-type");if(t){let i=this.#i(t);this.#t.create({label:i,placement:"bottom"}).setPosition(this.#t.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.#t.remove();};#n=e=>{let{tiles:t,mode:i,panel:n,store:s,map:a}=this.#e;s.reset(),n.hidePanel(),i.reset(),g.togglePointCircleRadius(a,"default"),this.#t.remove(),t.resetGeometries(),v.removeAllPoints(a,e);};#o=e=>{let{store:t,panel:i,map:n,tiles:s}=this.#e,a=t.tail?.val;t.removeStepById(a.id);let p={...a,total:t.size};v.undoPoint(p,n,e),d.switchToLineModeIfCan(this.#e),i?.onPointRemove(t.tail?.val),this.#t.remove(),requestAnimationFrame(s.render);};onSaveClick=e=>{let{store:t,options:i}=this.#e;v.onSaveClick(this.#e,b.toArray(t.head),e),this.#t.remove(),i.panel.buttons.save.clearOnSave&&this.#n(e);}};var E=class{static updatePointsData(e){let i=e.target.getSource(u.SinglePointSource);i&&i.setData({type:"Feature",geometry:{type:"Point",coordinates:[e.lngLat.lng,e.lngLat.lat]},properties:{}});}static setSinglePointVisible(e){e.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");}static setSinglePointHidden(e){let t=e.target;setTimeout(()=>{t.setLayoutProperty(r.SinglePointLayer,"visibility","none");},33);}static triggerPostPointAddition(e,t){let{panel:i,tiles:n,store:s,map:a}=t;d.canCloseGeometry(s)&&g.togglePointCircleRadius(a,"large"),i?.setPanelLocation(e.lngLat),n.render();}static addPointToMap=(e,t)=>{let{store:i,map:n,mode:s}=t,a={...e.lngLat,id:_()};i.push(a),v.addPoint({...a,total:i.size},n,s),this.triggerPostPointAddition(e,t);};static updateSelectedStepLatLng=(e,t)=>{t.lat=e.lngLat.lat,t.lng=e.lngLat.lng;}};var ye=(o,e)=>{let t=e.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.next&&t.next.val&&t.val){let n=o.target,s=y.getPixelCoordinates(n,t.val),a=y.getPixelCoordinates(n,t.next.val),p=y.getPixelCoordinates(n,o.lngLat);if(d.checkIfPointIsOnLine(s,a,p))return t}i.add(t),t=t.next;}return null},Me=(o,e)=>{let t=ye(o,e);if(t){let i={...o.lngLat,id:_()};return e.insert(i,t),i}return null},_e=(o,e)=>{let{store:t,tiles:i,panel:n}=e;t.tail?.val&&(n?.setPanelLocation(t.tail.val),E.setSinglePointHidden(o),i.render());},Ce=o=>y.isFeatureTriggered(o,[r.PointsLayer,r.FirstPointLayer]);var Se=15,ie=class{props;#e;#t;constructor(e){this.props=e,this.#e=null,this.#t=S(this.#n,Se);}initBreakEvents=()=>{let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mouseenter",r.LineLayerTransparent,this.#t),e.on("mousemove",r.LineLayerTransparent,this.#t),e.on("mouseleave",r.LineLayerTransparent,this.#o);};removeBreakEvents=()=>{let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mouseenter",r.LineLayerTransparent,this.#t),e.off("mousemove",r.LineLayerTransparent,this.#t),e.off("mouseleave",r.LineLayerTransparent,this.#o);};hideBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};#i=()=>{let{store:e,mode:t,panel:i,map:n,tiles:s}=this.props,a=this.#e?.next?.val?.id;d.breakGeometry(e,a),e.tail?.val&&i.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng}),this.#o(),n.setLayoutProperty(r.PolygonLayer,"visibility","none"),t.reset(),s.render(),v.onLineBreak(n);};#n=e=>{let{map:t,store:i}=this.props,n=ye(e,i);n?.val?.id!==this.#e?.val?.id&&(this.#e=n);let s=t.getSource(u.LineSourceBreak),a=[n?.val?.lng,n?.val?.lat],p=[n?.next?.val?.lng,n?.next?.val?.lat],L=M.getLine(a,p);L&&(s.setData(L),this.showBreakLine());};#o=()=>{setTimeout(()=>{this.hideBreakLine();},Se+10);}};var we=10,ne=class{#e;#t;#i;#n;#o;#s;constructor(e){this.#e=e,this.#t=e.options.dynamicLine,this.#i=null,this.#n=null,this.#r(),this.#s=S(this.#h,we);}#r(){this.#e.store.addObserver(this.#c),this.#e.mode.addObserver(this.#l),this.#e.mouseEvents.addObserver(this.#a);}removeConsumers=()=>{this.#e.store.removeObserver(this.#c),this.#e.mode.removeObserver(this.#l),this.#e.mouseEvents.removeObserver(this.#a);};#a=e=>{let{mode:t}=this.#e;if(!t.getClosedGeometry()&&(e.type==="lastPointMouseClick"&&e.data?(this.hideDynamicLine(),this.#t=!1):e.type==="lastPointMouseClick"&&!e.data&&(this.#t=!0),!!this.#t&&((e.type==="pointMouseEnter"||e.type==="lineMouseEnter")&&e.data&&this.hideDynamicLine(),(e.type==="pointMouseLeave"||e.type==="lineMouseLeave")&&e.data))){let{store:i}=this.#e;this.#i=i.tail?.val,this.#n=i.tail?.val,this.showDynamicLine();}};#c=e=>{let{store:t}=this.#e;switch(e.type){case"STORE_CHANGED":e.data.tail?.val&&!d.isClosedGeometry(t)&&(this.#i=e.data.tail?.val,this.showDynamicLine());break;}};#l=e=>{let{store:t}=this.#e;e.type==="CLOSED_GEOMETRY_CHANGED"&&(e.data&&this.hideDynamicLine(),!e.data&&t?.tail?.val&&(this.#i=t?.tail?.val,this.showDynamicLine()));};initDynamicEvents=()=>{let{map:e}=this.#e;e.on("click",this.#f),e.on("mousemove",this.#s),e.on(f.REMOVEALL,this.hideDynamicLine),e.on(f.UNDO,this.#m),e.on(f.DOUBLECLICK,this.#v);};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#f),e.off("mousemove",this.#s),e.off(f.REMOVEALL,this.hideDynamicLine),e.off(f.UNDO,this.#m),e.off(f.DOUBLECLICK,this.#v);};hideDynamicLine=()=>{let{map:e,tiles:t}=this.#e;this.#i=null,this.#n=null,this.#o=null,e.off("mousemove",this.#s),t.renderLines(V,u.LineDynamicSource),e.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};showDynamicLine=()=>{let{map:e}=this.#e,t=[this.#i?.lng,this.#i?.lat],i=[this.#n?.lng,this.#n?.lat];this.#o=M.getLine(t,i),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.#n&&this.#p({lng:this.#n?.lng,lat:this.#n?.lat}),e.on("mousemove",this.#s);};#p=e=>{if(!this.#o)return;let{tiles:t}=this.#e;this.#o.features[0].geometry.coordinates[1]=[e.lng,e.lat],t.renderLines(this.#o,u.LineDynamicSource);};#h=e=>{this.#p(e.lngLat);};#f=e=>{let{mode:t}=this.#e,i=y.isFeatureTriggered(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.#n={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hideDynamicLine();};#m=e=>{let{store:t,mode:i}=this.#e;if(!i.getClosedGeometry()){let n=e.target.unproject({x:e.originalEvent.x,y:e.originalEvent.y});this.#n={lng:n.lng,lat:n.lat},this.#i=t.tail?.val,this.showDynamicLine();}};#v=e=>{let{store:t,mode:i}=this.#e;i.getClosedGeometry()||(this.#n={lng:e.coordinates.lng,lat:e.coordinates.lat},this.#i=t.tail?.val,this.showDynamicLine());}};var De=22,oe=class{props;#e;#t;constructor(e){this.props=e,this.#e=!1,this.#t=null;}initEvents(){let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mousemove",r.LineLayerTransparent,this.#o),e.on("mouseenter",r.LineLayerTransparent,this.#s),e.on("mouseleave",r.LineLayerTransparent,this.#r);}removeEvents(){let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mousemove",r.LineLayerTransparent,this.#o),e.off("mouseenter",r.LineLayerTransparent,this.#s),e.off("mouseleave",r.LineLayerTransparent,this.#r);}#i=e=>{let{store:t,map:i,mode:n}=this.props;if(Ce(e))return;let s=Me(e,t);s&&(v.addPoint({...s,total:t.size},i,n),_e(e,this.props));};#n=e=>{E.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)&&E.updatePointsData(e);};#o=S(e=>{if(y.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer]))return;let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(this.#t=e,!this.#e&&(this.#e=!0,requestAnimationFrame(()=>{this.#t&&(this.#n(this.#t),this.#e=!1);})));},De);#s=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||y.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer])||(t.lineMouseEnter=!0,E.setSinglePointVisible(e));};#r=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(t.lineMouseLeave=!0,E.setSinglePointHidden(e));}};var se=class{props;#e;#t;#i;#n;constructor(e){this.props=e,this.#e=new ie(e),this.#t=new oe(e),this.#i=null,this.#n="default",this.#o(),this.#s(),this.#r();}#o=()=>{window.innerWidth<=768||this.props.options.dynamicLine&&(this.#i=new ne(this.props));};#s(){!this.props.mode.getBreak()&&(this.#t.initEvents(),this.props.options.dynamicLine&&this.#i?.initDynamicEvents());}#r(){this.props.mode.addObserver(this.#p),this.props.mouseEvents.addObserver(this.#l);}remove(){this.#a(),this.#c();}#a(){this.props.mode.removeObserver(this.#p),this.props.mouseEvents.removeObserver(this.#l),this.props.options.dynamicLine&&this.#i?.removeConsumers();}#c(){this.#e.removeBreakEvents(),this.#t.removeEvents(),this.props.options.dynamicLine&&this.#i?.removeEvents();}#l=e=>{let{type:t,data:i}=e,{mode:n}=this.props;if(!(!i||!n.getBreak()))switch(t){case"pointMouseDown":this.#e.removeBreakEvents(),this.#e.hideBreakLine();break;case"pointMouseUp":this.#e.initBreakEvents();break;}};#p=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.#n==="break"&&(this.#e.removeBreakEvents(),this.#t.initEvents(),this.#n="default"),t==="BREAK_CHANGED"&&i&&this.#n==="default"&&(this.#t.removeEvents(),this.#e.initBreakEvents(),this.#n="break");}};var re=class{#e;#t;#i;constructor(e){this.#t=e,this.#e=!1,this.#i=new O,e.mode.addObserver(this.#n);}initEvents(){let{map:e}=this.#t;e.on("click",r.FirstPointLayer,this.#o),e.on("mouseenter",r.FirstPointLayer,this.#l),e.on("mouseleave",r.FirstPointLayer,this.#a),e.on("mouseup",r.FirstPointLayer,this.#r),e.on("mousedown",r.FirstPointLayer,this.#s);}removeEvents(){let{map:e}=this.#t;e.off("click",r.FirstPointLayer,this.#o),e.off("mouseenter",r.FirstPointLayer,this.#l),e.off("mouseleave",r.FirstPointLayer,this.#a),e.off("mouseup",r.FirstPointLayer,this.#r);}#n=e=>{let{map:t,store:i}=this.#t,{type:n,data:s}=e;n==="MODE_CHANGED"&&(s==="line"||s==="polygon"?t.on("click",r.FirstPointLayer,this.#o):t.off("click",r.FirstPointLayer,this.#o),d.canCloseGeometry(i)&&g.togglePointCircleRadius(t,"large"));};#o=()=>{let{store:e,map:t,mode:i,tiles:n}=this.#t;if(i.getMode()==="polygon"&&t.setLayoutProperty(r.PolygonLayer,"visibility","visible"),d.canCloseGeometry(e)){d.closeGeometry(e,i);let s=Object.assign({},e.head?.val,{id:_(),total:e.size});v.addPoint(s,t,i),g.togglePointCircleRadius(t,"default"),n.render();}};#s=()=>{this.#e=!0,this.#i.remove();};#r=()=>{this.#e=!1;};#a=()=>{let{mouseEvents:e}=this.#t;this.#e||(e.firstPointMouseLeave=!0,this.#i.remove());};#c=()=>{let{mode:e,options:t}=this.#t;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};#l=e=>{let{mode:t,mouseEvents:i,store:n}=this.#t;if(!(t.getClosedGeometry()||this.#e)&&(i.firstPointMouseEnter=!0,d.canCloseGeometry(n))){let{x:s,y:a}=e.originalEvent;if(s&&a){this.#i.create({label:this.#c(),placement:"bottom"});let L=this.#i._label?this.#i._label.clientWidth/2:0;this.#i.setPosition({x:s-L,y:a+14});}}}};var ae=class{#e;#t;#i;#n;#o;#s;#r;#a;constructor(e){this.#e=e,this.#t=void 0,this.#i=null,this.#n=null,this.#o=null,this.#s=new re(e),this.#r=!1,this.#a=null;}#c=()=>{let{map:e}=this.#e;e.on("click",r.FirstPointLayer,this.#h),e.on("mouseenter",r.FirstPointLayer,this.#L),e.on("mouseleave",r.FirstPointLayer,this.#g),e.on("mousedown",r.FirstPointLayer,this.#d),e.on("mouseup",r.FirstPointLayer,this.#u),e.on("touchend",r.FirstPointLayer,this.#u),e.on("touchstart",r.FirstPointLayer,this.#d),this.#s.initEvents();};initEvents=()=>{let{map:e}=this.#e;e.on("click",this.#m),e.on("dblclick",this.#p),e.on("click",r.PointsLayer,this.#h),e.on("mouseenter",r.PointsLayer,this.#L),e.on("mouseleave",r.PointsLayer,this.#g),e.on("mousedown",r.PointsLayer,this.#d),e.on("mouseup",r.PointsLayer,this.#u),e.on("touchend",r.PointsLayer,this.#u),e.on("touchstart",r.PointsLayer,this.#d),this.#c();};#l=()=>{let{map:e}=this.#e;e.off("click",r.FirstPointLayer,this.#h),e.off("mouseenter",r.FirstPointLayer,this.#L),e.off("mouseleave",r.FirstPointLayer,this.#g),e.off("mousedown",r.FirstPointLayer,this.#d),e.off("mouseup",r.FirstPointLayer,this.#u),e.off("touchend",r.PointsLayer,this.#u),e.off("touchstart",r.PointsLayer,this.#d),this.#s.removeEvents();};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#m),e.off("dblclick",this.#p),e.off("mousemove",this.#y),e.off("click",r.PointsLayer,this.#h),e.off("mouseenter",r.PointsLayer,this.#L),e.off("mouseleave",r.PointsLayer,this.#g),e.off("mousedown",r.PointsLayer,this.#d),e.off("mouseup",r.PointsLayer,this.#u),this.#l();};#p=e=>{e.preventDefault();};#h=e=>{let{store:t,tiles:i,panel:n,map:s,mouseEvents:a}=this.#e;g.isDoubleClick()&&this.#n&&(t.removeStepById(this.#n.id),n.onPointRemove(t.tail?.val),v.pointDoubleClick({...this.#n,total:t.size},this.#e.map),d.switchToLineModeIfCan(this.#e));let p=y.queryPointId(s,e.point);b.isLastPoint(t,p)&&(a.lastPointMouseClick=!0,a.lastPointMouseUp=!1),i.render();};#f=e=>y.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer,r.LineLayerTransparent,r.LineLayerBreak]);#m=e=>{let{mode:t,mouseEvents:i,map:n}=this.#e;t.getClosedGeometry()||this.#f(e)||(i.lastPointMouseClick&&(i.lastPointMouseClick=!1),n.getCanvasContainer().style.cursor="grab",E.addPointToMap(e,this.#e),E.setSinglePointHidden(e));};#v=e=>{e.originalEvent.buttons===0&&this.#u();};#E=e=>{let{tiles:t}=this.#e;t.renderOnMouseMove(this.#o,e.lngLat);};#y=S(e=>{this.#a=e,this.#r||(this.#r=!0,requestAnimationFrame(()=>{!this.#n||!this.#a||(E.updateSelectedStepLatLng(this.#a,this.#n),this.#v(this.#a),this.#E(this.#a),this.#r=!1);}));},15);#L=e=>{let{mouseEvents:t,map:i,store:n}=this.#e;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;E.setSinglePointHidden(e);let s=y.queryPointId(i,e.point);b.isLastPoint(n,s)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let a=n.findStepById(s);a&&(this.#i=a,v.enterPoint(Object.assign({},a,{total:n.size}),i));};#g=e=>{let{mouseEvents:t,store:i,map:n}=this.#e;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let s=y.queryPointId(n,e.point);b.isLastPoint(i,s)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),v.leavePoint(Object.assign({},this.#i,{total:i.size}),n);};#P=()=>{let{store:e,panel:t}=this.#e;this.#n&&b.isLastPoint(e,this.#n.id)&&t.hidePanel();};#b=e=>{let{store:t,map:i}=this.#e,n=y.queryPointId(i,e.point),s=t.findStepById(n);s&&(this.#n=s);};#d=e=>{e.preventDefault();let{mouseEvents:t,map:i,store:n}=this.#e;g.removeTransparentLine(i),this.#b(e),this.#P();let s=y.queryPointId(i,e.point);this.#o=d.getGeometryIndex(n,s),t&&(t.pointMouseDown=!0),this.#t=e.lngLat,i.on("mousemove",this.#y),i.on("touchmove",this.#y);};#u=()=>{let{mouseEvents:e,store:t,panel:i,map:n,options:s}=this.#e;e.pointMouseUp=!0,this.#n&&(b.isLastPoint(t,this.#n.id)&&t.tail?.val&&i?.setPanelLocation(t.tail.val),i?.showPanel(),v.movePoint({id:this.#n.id,total:t.size,end:{lat:this.#n.lat,lng:this.#n.lng},start:this.#t},n)),e&&(e.pointMouseDown=!1),g.addTransparentLine(n,s),n.off("mousemove",this.#y),n.off("touchmove",this.#y);}};var le=class extends R{#e;#t;#i;#n;#o;constructor(e){super({...e}),this.#e=e,this.#t=new te(e),this.#i=new Q(e),this.#n=new ae(e),this.#o=new se(e),e.map.on("panel:ready",this.#s);}#s=()=>{this.#t?.initEvents(),this.#i?.initEvents(),this.#n?.initEvents();};removeMapEventsAndConsumers=()=>{this.#t?.removeEvents(),this.#n?.removeEvents(),this.#i?.remove(),this.#o?.remove(),this.#e.map.off("panel:ready",this.#s);}};var ce=class{#e;_line;_polygon;_break;_container;constructor(e){this.#e=e.options,this._line=void 0,this._polygon=void 0,this._break=void 0,this._container=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl(e);}createControlButton=(e,t,i,n)=>{let s=this.#e.panel.size,a=l.create("button",`control-button control-button-${s}`,this._container);return a.setAttribute("aria-label",t),a.setAttribute("data-type",e),i&&a.classList.add("control-button-active"),n&&(a.setAttribute("disabled","true"),a.setAttribute("aria-disabled","true")),l.create("span",`icon ${e} icon-${s}`,a),a};#t=e=>{let{mode:t,options:i}=e,n=this.#e.modes.line.visible,s=i.locale.line;if(n){let a=t.getMode()==="line";this._line=this.createControlButton("line",s,a);}};#i=e=>{let{mode:t,options:i}=e,n=this.#e.modes.polygon.visible,s=i.locale.polygon;n&&(this._polygon=this.createControlButton("polygon",s,t.isPolygon()));};#n=e=>{let{mode:t,options:i}=e,n=this.#e.modes.breakGeometry.visible,s=i.locale.break;if(n){let p=!this.#e?.initial?.closeGeometry,L=t.getBreak();this._break=this.createControlButton("break",s,L,p);}};createControl=e=>{this.#t(e),this.#i(e),this.#n(e);};getContainer=()=>this._container};var pe=class extends x{#e;#t;#i;constructor(e){super(),this.#e=e.initial?.geometry??"line",this.#t=!1,this.#i=e.initial?.closeGeometry??!1;}getMode=()=>this.#e;setMode=e=>{this.#e=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.#t;setBreak=e=>{this.#t=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.#i;setClosedGeometry=e=>{this.#i=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.#i});};isPolygon=()=>this.#e.includes("polygon")&&this.#i;reset=()=>{this.setMode(this.getMode()),this.setClosedGeometry(!1);};pingConsumers=()=>{this.notify({type:"MODE_CHANGED",data:this.getMode()}),this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.getClosedGeometry()});}};var he=class{#e;#t;constructor(e){this.#e=e,this.#t=this.#e.map.getCanvasContainer(),this.#t.style.cursor=P.CROSSHAIR,this.#i();}set=e=>{this.#t.style.cursor=e;};get=()=>this.#t.style.cursor;handleMouseLeave=()=>{let{mouseEvents:e,mode:t}=this.#e;e.pointMouseDown||(t.getClosedGeometry()?this.set(P.AUTO):this.set(P.CROSSHAIR));};handleFirstPointMouseEnter=()=>{let{mode:e,store:t}=this.#e;e.getClosedGeometry()&&this.set(P.MOVE),d.canCloseGeometry(t)&&this.set(P.POINTER);};#i(){let{mouseEvents:e}=this.#e;e.addObserver(this.#n);}removeConsumers(){let{mouseEvents:e}=this.#e;e.removeObserver(this.#n);}#n=e=>{let{mode:t,mouseEvents:i}=this.#e;if(t.getBreak())return;let{type:n,data:s}=e;if(s)switch(n){case"pointMouseDown":this.set(P.GRABBING);break;case"pointMouseUp":this.set(P.GRAB);break;case"pointMouseEnter":if(i.pointMouseDown)return;this.set(P.GRAB);break;case"pointMouseLeave":this.handleMouseLeave();break;case"lineMouseEnter":if(i.pointMouseDown)return;this.set(P.POINTER);break;case"lineMouseLeave":this.handleMouseLeave();break;case"firstPointMouseEnter":this.handleFirstPointMouseEnter();break;case"firstPointMouseLeave":this.handleMouseLeave();break;case"lastPointMouseEnter":this.set(P.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var ue=class extends x{#e;#t;#i;#n;#o;#s;#r;#a;#c;#l;#p;#h;constructor(){super(),this.#e=!1,this.#t=!1,this.#i=!1,this.#n=!1,this.#o=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#c=!1,this.#l=!1,this.#p=!1,this.#h=!1;}get firstPointMouseEnter(){return this.#e}set firstPointMouseEnter(e){this.#e=e,this.notify({type:"firstPointMouseEnter",data:e});}get firstPointMouseLeave(){return this.#t}set firstPointMouseLeave(e){this.#t=e,this.notify({type:"firstPointMouseLeave",data:e});}get lastPointMouseClick(){return this.#i}set lastPointMouseClick(e){this.#i=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#n}set lastPointMouseUp(e){this.#n=e,this.notify({type:"lastPointMouseUp",data:e});}get lastPointMouseEnter(){return this.#o}set lastPointMouseEnter(e){this.#o=e,this.notify({type:"lastPointMouseEnter",data:e});}get lastPointMouseLeave(){return this.#s}set lastPointMouseLeave(e){this.#s=e,this.notify({type:"lastPointMouseLeave",data:e});}get pointMouseDown(){return this.#r}set pointMouseDown(e){this.#r=e,this.notify({type:"pointMouseDown",data:e});}get pointMouseUp(){return this.#a}set pointMouseUp(e){this.#a=e,this.notify({type:"pointMouseUp",data:e});}get pointMouseEnter(){return this.#c}set pointMouseEnter(e){this.#c=e,this.notify({type:"pointMouseEnter",data:e});}get pointMouseLeave(){return this.#l}set pointMouseLeave(e){this.#l=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#p}set lineMouseEnter(e){this.#p=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#h}set lineMouseLeave(e){this.#h=e,this.notify({type:"lineMouseLeave",data:e});}};var q=class{static allStepsHaveIds(e){return e.every(t=>"id"in t&&t.id!==void 0)}static checkIfMissingIds(e,t){let i=!t,n=!this.allStepsHaveIds(e);if(i&&n)throw new Error(F.MISSING_IDS)}static checkIfEnoughPointsToClose(e,t){if(t&&e.length<3)throw new Error(F.NOT_ENOUGH_POINTS_TO_CLOSE)}static checkIfPolygonIsClosed(e){let{closeGeometry:t,steps:i}=e;if(i){let n=i[0]?.lng,s=i[i.length-1]?.lng,a=i[0]?.lat,p=i[i.length-1]?.lat;if((n!==s||a!==p)&&t)throw new Error(F.FIRST_LAST_POINT_NOT_EQUAL)}}static checkInitialStepsOption(e){let{closeGeometry:t,generateId:i,steps:n}=e;this.checkIfMissingIds(n,i),this.checkIfEnoughPointsToClose(n,t),this.checkIfPolygonIsClosed(e);}static init(e){return e?{panel:Ae(e),modes:Ie(e),layersPaint:Be(e),initial:e.initial||m.initial,locale:Ne(e),dynamicLine:e.dynamicLine??m.dynamicLine}:m}};function Ae(o){return {size:o.panel?.size||m.panel.size,buttons:{undo:{visible:o.panel?.buttons?.undo?.visible??m.panel.buttons.undo.visible},delete:{visible:o.panel?.buttons?.delete?.visible??m.panel.buttons.delete.visible},save:{visible:o.panel?.buttons?.save?.visible??m.panel.buttons.save.visible,clearOnSave:o.panel?.buttons?.save?.clearOnSave??m.panel.buttons.save.clearOnSave}}}}function Ie(o){return {line:{visible:o?.modes?.line?.visible||o?.initial?.geometry==="line"||m.modes.line.visible,closeGeometry:o?.modes?.line?.closeGeometry||o?.initial?.closeGeometry||m.modes.line.closeGeometry},polygon:{visible:o?.modes?.polygon?.visible||o?.initial?.geometry==="polygon"||m.modes.polygon.visible},breakGeometry:{visible:o?.modes?.breakGeometry?.visible??m.modes.breakGeometry.visible}}}function Be(o){return {onLinePoint:{"circle-radius":o.layersPaint?.onLinePoint?.["circle-radius"]||w["circle-radius"],"circle-color":o.layersPaint?.onLinePoint?.["circle-color"]||w["circle-color"],"circle-stroke-color":o.layersPaint?.onLinePoint?.["circle-stroke-color"]||w["circle-stroke-color"],"circle-stroke-width":o.layersPaint?.onLinePoint?.["circle-stroke-width"]||w["circle-stroke-width"],...o.layersPaint?.onLinePoint},firstPoint:{"circle-radius":o.layersPaint?.firstPoint?.["circle-radius"]||T["circle-radius"],"circle-color":o.layersPaint?.firstPoint?.["circle-color"]||T["circle-color"],"circle-stroke-color":o.layersPaint?.firstPoint?.["circle-stroke-color"]||T["circle-stroke-color"],"circle-stroke-width":o.layersPaint?.firstPoint?.["circle-stroke-width"]||T["circle-stroke-width"],...o.layersPaint?.firstPoint},points:{"circle-radius":o.layersPaint?.points?.["circle-radius"]||D["circle-radius"],"circle-color":o.layersPaint?.points?.["circle-color"]||D["circle-color"],"circle-stroke-color":o.layersPaint?.points?.["circle-stroke-color"]||D["circle-stroke-color"],"circle-stroke-width":o.layersPaint?.points?.["circle-stroke-width"]||D["circle-stroke-width"],...o.layersPaint?.points},line:{"line-width":o.layersPaint?.line?.["line-width"]||B["line-width"],"line-color":o.layersPaint?.line?.["line-color"]||B["line-color"],"line-opacity":o.layersPaint?.line?.["line-opacity"]||B["line-opacity"],...o.layersPaint?.line},polygon:{"fill-color":o.layersPaint?.polygon?.["fill-color"]||H["fill-color"],"fill-opacity":o.layersPaint?.polygon?.["fill-opacity"]||H["fill-opacity"],...o.layersPaint?.polygon},breakLine:{"line-width":o.layersPaint?.breakLine?.["line-width"]||N["line-width"],"line-color":o.layersPaint?.breakLine?.["line-color"]||N["line-color"],"line-dasharray":o.layersPaint?.breakLine?.["line-dasharray"]||N["line-dasharray"],...o.layersPaint?.breakLine}}}function Ne(o){return {save:o.locale?.save??m.locale.save,delete:o.locale?.delete??m.locale.delete,undo:o.locale?.undo??m.locale.undo,line:o.locale?.line??m.locale.line,polygon:o.locale?.polygon??m.locale.polygon,break:o.locale?.break??m.locale.break,closeLine:o.locale?.closeLine??m.locale.closeLine,createPolygon:o.locale?.createPolygon??m.locale.createPolygon}}var fe=class o{#e;#t;#i;#n;#o;#s;#r;#a;#c;static#l=null;static#p=!1;constructor(e){if(this.#n=q.init(e),this.#n.initial&&q.checkInitialStepsOption(this.#n.initial),o.#p)throw new Error("Use 'DrawLibre.getInstance()' instead of 'new DrawLibre()'.");o.#p=!0,this.#t=void 0,this.#i=void 0,this.#o=void 0,this.#s=void 0,this.#r=void 0,this.#c=void 0,this.#a=void 0;}static getInstance(e){return o.#l||(o.#l=new o(e)),o.#l}onAdd(e){this.#t=new U(this.#n),this.#r=new j({map:e,options:this.#n,store:this.#t}),this.#i=new pe(this.#n),this.#s=new R({map:e,store:this.#t,options:this.#n,mode:this.#i});let t=new ce({options:this.#n,mode:this.#i});return this.#c=new ue,this.#a=new he({map:e,mode:this.#i,mouseEvents:this.#c,store:this.#t}),this.#o=new le({map:e,store:this.#t,options:this.#n,panel:this.#r,control:t,mode:this.#i,tiles:this.#s,mouseEvents:this.#c}),this.#i.pingConsumers(),this.#e=t.getContainer(),this.#e}onRemove(){this.#a?.removeConsumers(),this.#s?.removeTiles(),this.#o?.removeMapEventsAndConsumers(),this.#r?.removePanel(),this.#t?.reset(),this.#i?.unsubscribe(),this.#e&&l.remove(this.#e);}setSteps=e=>{if(Array.isArray(e))e.forEach(t=>{let i={...t,id:t.id||_()};this.#t?.push(i);});else throw new Error("Invalid argument. Expected an array of steps.");this.#s?.render();};findStepById=e=>this.#t?.findStepById(e);getAllSteps=(e="array")=>{if(e==="array"&&this.#t)return b.toArray(this.#t.head);if(e==="linkedlist")return this.#t;throw new Error("Invalid type specified. Use 'array' or 'linkedlist'.")};setOptions=e=>{this.#n=e(this.#n);};removeAllSteps=()=>{this.#t?.reset(),this.#r?.removePanel(),this.#s?.render();}};
|
|
5
|
+
var l=class n{static docStyle=typeof window<"u"&&window.document&&window.document.documentElement.style;static transformProp=n.testProp(["transform","WebkitTransform"]);static testProp(e){if(!n.docStyle)return e[0];for(let t=0;t<e.length;t++)if(e[t]in n.docStyle)return e[t];return e[0]}static create(e,t,i){let o=window.document.createElement(e);return t!==void 0&&(o.className=t),i&&i.appendChild(o),o}static remove(e){e.parentNode&&e.parentNode.removeChild(e);}static setTransform(e,t){n.transformProp&&e.style&&(e.style[n.transformProp]=t);}static manageEventListener(e,t,i,o,s={}){if(!t)return;let a=e==="add"?"addEventListener":"removeEventListener";"passive"in s?t[a](i,o,s):t[a](i,o,s.capture);}static mouseButton(e){return e.button}static addClassName(e,t){e.classList.contains(t)||e.classList.add(t);}static removeClassName(e,t){e.classList.contains(t)&&e.classList.remove(t);}};var C=class n{lng;lat;constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,this.lat>90||this.lat<-90)throw new Error("Invalid LngLat latitude value: must be between -90 and 90")}static convert(e){if(e instanceof n)return e;if(Array.isArray(e)&&(e.length===2||e.length===3))return new n(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null)return new n(Number("lng"in e?e.lng:e.lon),Number(e.lat));throw new Error("`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]")}};function G(n,...e){for(let t of e)for(let i in t)n[i]=t[i];return n}function ve(n,e,t){let i=new C(n.lng,n.lat);if(n=new C(n.lng,n.lat),e){let o=new C(n.lng-360,n.lat),s=new C(n.lng+360,n.lat),a=t.locationPoint(n).distSqr(e);t.locationPoint(o).distSqr(e)<a?n=o:t.locationPoint(s).distSqr(e)<a&&(n=s);}for(;Math.abs(n.lng-t.center.lng)>180;){let o=t.locationPoint(n);if(o.x>=0&&o.y>=0&&o.x<=t.width&&o.y<=t.height)break;n.lng>t.center.lng?n.lng-=360:n.lng+=360;}return n.lng!==i.lng&&t.locationPoint(n).y>t.height/2-t.getHorizon()?n:i}var de={center:"translate(-50%,-50%)",top:"translate(-50%,0)","top-left":"translate(0,0)","top-right":"translate(-100%,0)",bottom:"translate(-50%,-100%)","bottom-left":"translate(0,-100%)","bottom-right":"translate(-100%,-100%)",left:"translate(0,-50%)",right:"translate(-100%,-50%)"};function Le(n,e,t){let i=n.classList;for(let o in de)i.remove(`maplibregl-${t}-anchor-${o}`);i.add(`maplibregl-${t}-anchor-${e}`);}function ge(n,e,t){t[n]&&t[n].indexOf(e)!==-1||(t[n]=t[n]||[],t[n].push(e));}function me(n,e,t){if(t&&t[n]){let i=t[n].indexOf(e);i!==-1&&t[n].splice(i,1);}}var z=class{_listeners;_oneTimeListeners;_eventedParent;_eventedParentData;on(e,t){return this._listeners=this._listeners||{},ge(e,t,this._listeners),this}off(e,t){return me(e,t,this._listeners),me(e,t,this._oneTimeListeners),this}once(e,t){return t?(this._oneTimeListeners=this._oneTimeListeners||{},ge(e,t,this._oneTimeListeners),this):new Promise(i=>this.once(e,i))}fire(e,t){typeof e=="string"&&(e=new A(e,t||{}));let i=e.type;if(this.listens(i)){e.target=this;let o=this._listeners&&this._listeners[i]?this._listeners[i].slice():[];for(let h of o)h.call(this,e);let s=this._oneTimeListeners&&this._oneTimeListeners[i]?this._oneTimeListeners[i].slice():[];for(let h of s)me(i,h,this._oneTimeListeners),h.call(this,e);let a=this._eventedParent;a&&(G(e,typeof this._eventedParentData=="function"?this._eventedParentData():this._eventedParentData),a.fire(e));}else e instanceof ErrorEvent&&console.error(e.error);return this}listens(e){return this._listeners&&this._listeners[e]&&this._listeners[e].length>0||this._oneTimeListeners&&this._oneTimeListeners[e]&&this._oneTimeListeners[e].length>0||this._eventedParent&&this._eventedParent.listens(e)}setEventedParent(e,t){return this._eventedParent=e,this._eventedParentData=t,this}},A=class{type;constructor(e,t={}){G(this,t),this.type=e;}};var p=class n{x;y;constructor(e,t){this.x=e,this.y=t;}mag(){return Math.sqrt(this.x*this.x+this.y*this.y)}equals(e){return this.x===e.x&&this.y===e.y}dist(e){return Math.sqrt(this.distSqr(e))}distSqr(e){let t=e.x-this.x,i=e.y-this.y;return t*t+i*i}angle(){return Math.atan2(this.y,this.x)}angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)}angleWith(e){return this.angleWithSep(e.x,e.y)}angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)}_matMult(e){let t=e[0]*this.x+e[1]*this.y,i=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=i,this}_add(e){return this.x+=e.x,this.y+=e.y,this}_sub(e){return this.x-=e.x,this.y-=e.y,this}_mult(e){return this.x*=e,this.y*=e,this}_div(e){return this.x/=e,this.y/=e,this}_multByPoint(e){return this.x*=e.x,this.y*=e.y,this}_divByPoint(e){return this.x/=e.x,this.y/=e.y,this}_unit(){return this._div(this.mag()),this}_perp(){let e=this.y;return this.y=this.x,this.x=-e,this}_rotate(e){let t=Math.cos(e),i=Math.sin(e),o=t*this.x-i*this.y,s=i*this.x+t*this.y;return this.x=o,this.y=s,this}_rotateAround(e,t){let i=Math.cos(e),o=Math.sin(e),s=t.x+i*(this.x-t.x)-o*(this.y-t.y),a=t.y+o*(this.x-t.x)+i*(this.y-t.y);return this.x=s,this.y=a,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}static convert(e){if(e instanceof n)return e;if(Array.isArray(e))return new n(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new n(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")}};var Oe={closeButton:!0,closeOnClick:!0,focusAfterOpen:!0,className:"",maxWidth:"240px",subpixelPositioning:!1},xe=["a[href]","[tabindex]:not([tabindex='-1'])","[contenteditable]:not([contenteditable='false'])","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])"].join(", "),Y=class extends z{_map;options;_content;_container;_closeButton;_tip;_lngLat;_trackPointer;_pos;_flatPos;constructor(e){super(),this.options=G(Object.create(Oe),e);}addTo(e){return this._map&&this.remove(),this._map=e,this.options.closeOnClick&&this._map.on("click",this._onClose),this.options.closeOnMove&&this._map.on("move",this._onClose),this._map.on("remove",this.remove),this._update(),this._focusFirstElement(),this._trackPointer?(this._map.on("mousemove",this._onMouseMove),this._map.on("mouseup",this._onMouseUp),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")):this._map.on("move",this._update),this.fire(new A("open")),this}isOpen(){return !!this._map}remove=()=>(this._content&&l.remove(this._content),this._container&&(l.remove(this._container),delete this._container),this._map&&(this._map.off("move",this._update),this._map.off("move",this._onClose),this._map.off("click",this._onClose),this._map.off("remove",this.remove),this._map.off("mousemove",this._onMouseMove),this._map.off("mouseup",this._onMouseUp),this._map.off("drag",this._onDrag),this._map._canvasContainer.classList.remove("maplibregl-track-pointer"),delete this._map,this.fire(new A("close"))),this);getLngLat(){return this._lngLat}setLngLat(e){return this._lngLat=C.convert(e),this._pos=null,this._flatPos=null,this._trackPointer=!1,this._update(),this._map&&(this._map.on("move",this._update),this._map.off("mousemove",this._onMouseMove),this._container&&this._container.classList.remove("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.remove("maplibregl-track-pointer")),this}trackPointer(){return this._trackPointer=!0,this._pos=null,this._flatPos=null,this._update(),this._map&&(this._map.off("move",this._update),this._map.on("mousemove",this._onMouseMove),this._map.on("drag",this._onDrag),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")),this}getElement(){return this._container}setText(e){return this.setDOMContent(document.createTextNode(e))}setHTML(e){let t=document.createDocumentFragment(),i=document.createElement("body"),o;for(i.innerHTML=e;o=i.firstChild,!!o;)t.appendChild(o);return this.setDOMContent(t)}getMaxWidth(){return this._container?.style.maxWidth}setMaxWidth(e){return this.options.maxWidth=e,this._update(),this}setDOMContent(e){if(this._content)for(;this._content.hasChildNodes();)this._content.firstChild&&this._content.removeChild(this._content.firstChild);else this._content=l.create("div","maplibregl-popup-content",this._container);return this._content.appendChild(e),this._createCloseButton(),this._update(),this._focusFirstElement(),this}addClassName(e){return this._container&&this._container.classList.add(e),this}removeClassName(e){return this._container&&this._container.classList.remove(e),this}setOffset(e){return this.options.offset=e,this._update(),this}toggleClassName(e){if(this._container)return this._container.classList.toggle(e)}setSubpixelPositioning(e){this.options.subpixelPositioning=e;}_createCloseButton(){this.options.closeButton&&(this._closeButton=l.create("button","maplibregl-popup-close-button",this._content),this._closeButton.type="button",this._closeButton.innerHTML="×",this._closeButton.addEventListener("click",this._onClose));}_onMouseUp=e=>{this._update(e.point);};_onMouseMove=e=>{this._update(e.point);};_onDrag=e=>{this._update(e.point);};_update=e=>{let t=this._lngLat||this._trackPointer;if(!this._map||!t||!this._content)return;if(!this._container){if(this._container=l.create("div","maplibregl-popup",this._map.getContainer()),this._tip=l.create("div","maplibregl-popup-tip",this._container),this._container.appendChild(this._content),this.options.className)for(let h of this.options.className.split(" "))this._container.classList.add(h);this._closeButton&&this._closeButton.setAttribute("aria-label",this._map._getUIString("Popup.Close")),this._trackPointer&&this._container.classList.add("maplibregl-popup-track-pointer");}if(this.options.maxWidth&&this._container.style.maxWidth!==this.options.maxWidth&&(this._container.style.maxWidth=this.options.maxWidth),this._map.transform.renderWorldCopies&&!this._trackPointer?this._lngLat=ve(this._lngLat,this._flatPos,this._map.transform):this._lngLat=this._lngLat?.wrap(),this._trackPointer&&!e)return;let i=this._flatPos=this._pos=this._trackPointer&&e?e:this._map.project(this._lngLat);this._map.terrain&&(this._flatPos=this._trackPointer&&e?e:this._map.transform.locationPoint(this._lngLat));let o=this.options.anchor,s=Ee(this.options.offset);if(!o){let h=this._container.offsetWidth,L=this._container.offsetHeight,k;i.y+s.bottom.y<L?k=["top"]:i.y>this._map.transform.height-L?k=["bottom"]:k=[],i.x<h/2?k.push("left"):i.x>this._map.transform.width-h/2&&k.push("right"),k.length===0?o="bottom":o=k.join("-");}let a=i.add(s[o]);this.options.subpixelPositioning||(a=a.round()),l.setTransform(this._container,`${de[o]} translate(${a.x}px,${a.y}px)`),Le(this._container,o,"popup");};_focusFirstElement(){if(!this.options.focusAfterOpen||!this._container)return;let e=this._container.querySelector(xe);e&&e.focus();}_onClose=()=>{this.remove();}};function Ee(n){if(n)if(typeof n=="number"){let e=Math.round(Math.abs(n)/Math.SQRT2);return {center:new p(0,0),top:new p(0,n),"top-left":new p(e,e),"top-right":new p(-e,e),bottom:new p(0,-n),"bottom-left":new p(e,-e),"bottom-right":new p(-e,-e),left:new p(n,0),right:new p(-n,0)}}else if(n instanceof p||Array.isArray(n)){let e=p.convert(n);return {center:e,top:e,"top-left":e,"top-right":e,bottom:e,"bottom-left":e,"bottom-right":e,left:e,right:e}}else return {center:p.convert(n.center||[0,0]),top:p.convert(n.top||[0,0]),"top-left":p.convert(n["top-left"]||[0,0]),"top-right":p.convert(n["top-right"]||[0,0]),bottom:p.convert(n.bottom||[0,0]),"bottom-left":p.convert(n["bottom-left"]||[0,0]),"bottom-right":p.convert(n["bottom-right"]||[0,0]),left:p.convert(n.left||[0,0]),right:p.convert(n.right||[0,0])};else return Ee(new p(0,0))}var j=class{#e;#t;#i;_undoButton;_deleteButton;_saveButton;_container;constructor(e){this.#e=e,this._container=void 0,this.#i=!1,this.#s().then(()=>{this.#r(),this.#o();});}#o(){this.#e.mode?.addObserver(this.#n);}#n=e=>{let{store:t}=this.#e,{type:i,data:o}=e;i==="MODE_CHANGED"&&!o&&this.hidePanel(),i==="MODE_CHANGED"&&o&&t.tail?.val&&this.setPanelLocation({lat:t.tail?.val?.lat,lng:t.tail?.val?.lng});};#s=async()=>{try{this.#t=new Y({offset:16,closeButton:!1,closeOnClick:!1,closeOnMove:!1,anchor:"bottom"});}catch(e){console.error("POPUP LOAD ERROR",e);}};#r=()=>{let{store:e}=this.#e;this.createPanel(),e.tail?.val&&this.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng});};setPanelLocation=e=>{let{map:t}=this.#e;this.#i&&(this.#i=!1,this.showPanel()),this._container&&this.#t&&this.#t.setLngLat(e).setDOMContent(this._container).addTo(t);};hidePanel=()=>{!this.#i&&(this.#t?.addClassName("hide-panel"),this.#i=!0);};showPanel=()=>{this.#t?.removeClassName("hide-panel"),this.#i=!1;};onPointRemove=e=>{e?this.setPanelLocation(e):this.hidePanel();};removePanel=()=>{this._container&&l.remove(this._container),this.#t?.remove();};createButton=(e,t,i,o)=>{let s=l.create("button",`panel-button panel-button-${i}`,o);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`icon ${e} icon-${i}`,s),s};createPanel=()=>{let{options:e}=this.#e,{locale:t}=e,{undo:i,delete:o,save:s}=e.panel.buttons,a=e.panel.size,h=document.querySelector(".maplibregl-popup-content"),L=l.create("div","dashboard",h);i.visible&&(this._undoButton=this.createButton("undo",t.undo,a,L)),o.visible&&(this._deleteButton=this.createButton("delete",t.delete,a,L)),s.visible&&(this._saveButton=this.createButton("save",t.save,a,L)),this._container=L;}};var W={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[]}}]},V={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[]}}]},Pe={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}}]},r={LineDynamicLayer:"mdl-line-dynamic-layer",LineLayer:"mdl-line-layer",LineLayerTransparent:"mdl-line-layer-transparent",LineLayerBreak:"mdl-line-break-layer",PolygonLayer:"mdl-polygon-layer",PointsLayer:"mdl-points-layer",SinglePointLayer:"mdl-single-point-layer",FirstPointLayer:"mdl-first-point-layer"},u={LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",LineSource:"mdl-line-source",PolygonSource:"mdl-polygon-source",PointsSource:"mdl-points-source",SinglePointSource:"mdl-single-point-source"},I={large:6.5,default:5.5},K={large:"#FF6464",default:"#666666"},T={"circle-radius":I.default,"circle-color":"#FEFFFE","circle-stroke-color":K.default,"circle-stroke-width":3},w={"circle-radius":I.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},H={"fill-color":"grey","fill-opacity":.4},B={"line-width":3,"line-color":"grey","line-opacity":.7},D={"circle-radius":I.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},N={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},$=n=>[{id:r.SinglePointLayer,source:u.SinglePointSource,type:"circle",paint:n.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:u.PolygonSource,type:"fill",paint:n.layersPaint.polygon,layout:{visibility:"none"}},{id:r.LineDynamicLayer,source:u.LineDynamicSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"none"}},{id:r.LineLayer,source:u.LineSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"visible"}},{id:r.LineLayerTransparent,source:u.LineSource,type:"line",paint:{"line-width":4,"line-color":"transparent"}},{id:r.LineLayerBreak,source:u.LineSourceBreak,type:"line",paint:n.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:u.PointsSource,type:"circle",paint:n.layersPaint.points,filter:["==",["get","isFirst"],!1]},{id:r.FirstPointLayer,source:u.PointsSource,type:"circle",paint:n.layersPaint.firstPoint,filter:["==",["get","isFirst"],!0]}];var g=class{static#e=0;static#t=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",I.large),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",K.large);};static#i=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",I.default),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",K.default);};static togglePointCircleRadius=(e,t)=>{t==="large"?this.#t(e):this.#i(e);};static removeTransparentLine=e=>{e.removeLayer(r.LineLayerTransparent);};static addTransparentLine=(e,t)=>{if(e.getLayer(r.LineLayerTransparent))return;let o=$(t).find(s=>s.id===r.LineLayerTransparent);o&&e.addLayer(o);};static isDoubleClick(){let t=Date.now();return t-this.#e<=400?(this.#e=t,!0):(this.#e=t,!1)}};var y=class{static isFeatureTriggered(e,t){return e.target.queryRenderedFeatures(e.point,{layers:t}).some(o=>t.includes(o.layer.id))}static getPixelCoordinates=(e,t)=>{let{lat:i,lng:o}=t;return e.project([o,i])};static queryPointId=(e,t)=>e.queryRenderedFeatures(t,{layers:[r.PointsLayer,r.FirstPointLayer]})?.[0]?.properties.id},b=class{static#e(e){let t=[],i=e.head,o=new Set;for(;i!==null;){if(o.has(i.val?.id)){e.head&&e.head.val&&t.push([e.head.val.lng,e.head.val.lat]);break}o.add(i.val?.id),i.val&&t.push([i.val.lng,i.val.lat]),i=i.next;}return t}static getAllLines(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}]}}static getLine(e,t){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e,t]}}]}}static getPolygon(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[t]}}]}}static getPoints(e){let t=e.head,i=[],o=new Set;for(;t!==null&&!o.has(t.val?.id);){if(t.val){let s=t.val,a=t.val.id===e.head?.val?.id;i.push({type:"Feature",properties:{id:s.id,lat:s.lat,lng:s.lng,isFirst:a},geometry:{type:"Point",coordinates:[s.lng,s.lat]}});}o.add(t.val?.id),t=t.next;}return {type:"FeatureCollection",features:i}}},d=class n{static getGeometryIndex=(e,t)=>{let i=e.head,o=0;for(;i!==null;){if(i.val?.id===t)return o;o++,i=i.next;}return -1};static isFirstPoint(e){let t=e.target,i=e.point;return !!t.queryRenderedFeatures(i,{layers:[r.FirstPointLayer]}).length}static distance=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2);static checkIfPointIsOnLine=(e,t,i)=>{let s=this.distance(e,t),a=this.distance(e,i),h=this.distance(i,t);return Math.abs(a+h-s)<.1};static isClosedGeometry=e=>e.tail?.next===e.head;static breakGeometry=(e,t)=>{if(!e.head)return;let i=e.head,o=e.tail;do{if(i?.val?.id===t){i!==e.head&&(o.next=i.next,e.head=i,e.tail=o),e.tail.next=null;return}o=i,i=i.next;}while(i!==e.head)};static closeGeometry=(e,t)=>{e.tail&&(e.tail.next=e.head),t.setClosedGeometry(!0);};static canCloseGeometry=e=>e.size>2&&!this.isClosedGeometry(e);static canBreakClosedGeometry=e=>e.size<=2;static switchToLineModeIfCan=e=>{let{mode:t,store:i,tiles:o,map:s}=e;n.canBreakClosedGeometry(i)&&(i.tail&&i.tail.val&&(i.tail.next=null),t.reset(),g.togglePointCircleRadius(s,"default"),o.renderPolygon(W));}},_=()=>{if("crypto"in window&&"randomUUID"in window.crypto)return window.crypto.randomUUID();function n(){return "0123456789abcdef"[Math.floor(Math.random()*16)]}function e(o){let s="";for(let a=0;a<o;a++)s+=n();return s}function t(o){let s=o===0,a=o===4;return s?8:a?12:4}let i=[];for(let o=0;o<5;o++)i.push(e(t(o)));return i.join("-")},S=(n,e)=>{let t,i=!0;function o(){i&&t&&(n(...t),t=null,i=!1,setTimeout(()=>{i=!0,o();},e));}return function(...s){t=s,o();}};var R=class{#e;#t;#i;#o;constructor(e){this.#e=e,this.#n(),this.render();}#n(){this.#s(),this.#r(),this.#a(r.LineLayer,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.FirstPointLayer),this.#a(r.LineLayerTransparent,r.PointsLayer),this.#a(r.PolygonLayer,r.LineLayer);}#s=()=>{let{map:e}=this.#e;Object.values(u).forEach(t=>{e.getSource(t)||e.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});});};#r=()=>{let{map:e,mode:t,options:i}=this.#e;$(i).forEach(a=>{e.getLayer(a.id)||e.addLayer(a);});let s=e.getLayoutProperty(r.PolygonLayer,"visibility")==="none";t.getMode()==="polygon"&&s&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible");};#a=(e,t)=>{let{map:i}=this.#e,o=i.getLayer(e),s=i.getLayer(t);o&&s&&i.moveLayer(e,t);};#l=()=>{let{map:e}=this.#e;Object.values(u).forEach(t=>{e.getSource(t)&&e.removeSource(t);});};#c=()=>{let{map:e}=this.#e;Object.values(r).forEach(t=>{e.getLayer(t)&&e.removeLayer(t);});};removeTiles=()=>{this.#c(),this.#l();};renderPoints=e=>{let{map:t}=this.#e,i=t.getSource(u.PointsSource);i&&i.setData(e);};renderLines=(e,t)=>{let{map:i}=this.#e,o=i.getSource(t);o&&o.setData(e);};renderPolygon=e=>{let{map:t}=this.#e,i=t.getSource(u.PolygonSource);i&&i.setData(e);};render=()=>{let{mode:e,options:t,store:i}=this.#e,o=b.getPoints(i),s=b.getAllLines(i);if(this.#t=o,this.#i=s,this.renderPoints(o),this.renderLines(s,u.LineSource),t.modes.polygon.visible&&e.isPolygon()){let h=b.getPolygon(i);this.#o=h,this.renderPolygon(h);}};#h=(e,t)=>{if(this.#o.features[0].geometry.coordinates[0][e]=[t.lng,t.lat],e===0){let o=this.#o.features[0].geometry.coordinates[0]?.length-1;this.#o.features[0].geometry.coordinates[0][o]=[t.lng,t.lat];}this.renderPolygon(this.#o);};#p=(e,t)=>{let{mode:i}=this.#e;this.#i.features[0].geometry.coordinates[e]=[t.lng,t.lat];let o=e===0;if(this.#i&&i.getClosedGeometry()&&o){let a=this.#i.features[0].geometry.coordinates?.length-1;this.#i.features[0].geometry.coordinates[a]=[t.lng,t.lat];}this.renderLines(this.#i,u.LineSource);};renderOnMouseMove=(e,t)=>{let{mode:i,options:o}=this.#e;this.#t.features[e].geometry.coordinates=[t.lng,t.lat],this.renderPoints(this.#t),this.#p(e,t),o.modes.polygon.visible&&i.isPolygon()&&this.#h(e,t);};resetGeometries=()=>{this.renderPoints(Pe),this.renderLines(V,u.LineSource),this.renderPolygon(W);}};var ke=8,Te=8,O=class{_container;_label;constructor(){this._container=void 0;}create=e=>{let t=l.create("div","popup-container",document.body),i=l.create("span",`popup-text popup-text-${e.placement}`,t);return i.textContent=e.label,this._container=t,this._label=i,this};#e=()=>{!this._label?.classList.value.includes("popup-text-active")&&this._label?.classList.add("popup-text-active");};#t=()=>this._label?{width:this._label.clientWidth,height:this._label.clientHeight}:{width:0,height:0};#i=e=>{let{bottom:t,left:i}=e.target.getBoundingClientRect(),{width:o,height:s}=this.#t();return {x:i-Te-o,y:t-s-2}};#o=e=>{let{bottom:t,left:i,right:o}=e.target.getBoundingClientRect(),{width:s}=this.#t();return {x:(o-i)/2+i-s/2,y:t+ke}};getPosition=(e,t)=>t==="left"?this.#i(e):this.#o(e);setPosition=e=>{let{x:t,y:i}=e;this._container&&(this._container.style.left=`${t}px`,this._container.style.top=`${i}px`),this.#e();};remove=()=>{this._container&&l.remove(this._container);}};var E={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var Z=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("add",n,t,i);},J=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("remove",n,t,i);},Me=(n,e)=>{let t=e.locale.line,i=e.locale.polygon,o=e.locale.break;return {line:t,polygon:i,break:o}[n]};var X=class{#e;constructor(e){this.#e=e,this.#t();}#t=()=>{this.#e.mode.addObserver(this.#l);};removeConsumers=()=>{this.#e.mode.removeObserver(this.#l);};#i=()=>{let{_line:e,_polygon:t,_break:i}=this.#e.control;e?.classList.remove("control-button-active"),t?.classList.remove("control-button-active"),i?.classList.remove("control-button-active");};#o=e=>{this.#i(),e.classList.add("control-button-active");};#n=e=>{let{data:t}=e,{_line:i,_polygon:o,_break:s}=this.#e.control,{mode:a}=this.#e;if(!(!i||!o||!s)){switch(t){case"line":this.#o(i);break;case"polygon":this.#o(o);break;}t?a.getClosedGeometry()&&this.#r(s):this.#s(s);}};#s=e=>{e.setAttribute("disabled","true"),e.setAttribute("aria-disabled","true");};#r=e=>{e.removeAttribute("disabled"),e.removeAttribute("aria-disabled");};#a=e=>{let{data:t,type:i}=e,{_break:o,_line:s,_polygon:a}=this.#e.control,{mode:h}=this.#e;t?(o&&this.#r(o),h.getMode()==="polygon"&&s&&this.#s(s),h.getMode()==="line"&&a&&this.#s(a)):(o&&this.#s(o),h.getMode()==="polygon"&&s&&this.#r(s),h.getMode()==="line"&&a&&this.#r(a));};#l=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.#n(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.#a(e),t==="BREAK_CHANGED"&&i){let{_break:o}=this.#e.control;this.#o(o);}}};var Q=class{#e;#t;#i;constructor(e){this.#e=e,this.#i=new X(e),this.#t=new O,this.#o();}#o(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&Z(e._line,{...t,click:this.onLineClick}),e._polygon&&Z(e._polygon,{...t,click:this.onPolygonClick}),e._break&&Z(e._break,{...t,click:this.onBreakClick});}}#n(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&J(e._line,{...t,click:this.onLineClick}),e._polygon&&J(e._polygon,{...t,click:this.onPolygonClick}),e._break&&J(e._break,{...t,click:this.onBreakClick});}}remove(){this.#i.removeConsumers(),this.#n(),this.#t.remove();}onButtonEnter=e=>{let{options:t}=this.#e,i=e.target.getAttribute("data-type");if(i){let o=Me(i,t),s="left";this.#t.create({label:o,placement:s}).setPosition(this.#t.getPosition(e,s));}};onButtonLeave=()=>{this.#t.remove();};#s=()=>{let{control:e}=this.#e;e._line?.classList.remove("control-button-active"),e._polygon?.classList.remove("control-button-active"),e._break?.classList.remove("control-button-active");};#r=()=>{let{map:e,mode:t}=this.#e;t.getMode()||e.fire("mode:initialize");};onLineClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="line"?(t.setMode(null),e.fire("mode:remove"),i.resetGeometries()):(o._line?.classList.add("control-button-active"),t.setMode("line"),i.render());};onPolygonClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="polygon"?(t.setMode(null),e.fire("mode:remove"),e.setLayoutProperty(r.PolygonLayer,"visibility","visible"),i.resetGeometries()):(o._polygon?.classList.add("control-button-active"),t.setMode("polygon"),i.render());};onBreakClick=()=>{let{map:e,mode:t,control:i}=this.#e;t.getBreak()&&(t.setMode(null),e.fire("mode:remove")),this.#s(),i._break?.classList.add("control-button-active"),t.setBreak(!0),e.getCanvasContainer().style.cursor=E.POINTER;}};var x=class{observers;constructor(){this.observers=new Set;}addObserver(e){this.observers.add(e);}removeObserver(e){this.observers.delete(e);}unsubscribe(){this.observers.clear();}notify(e){this.observers.forEach(t=>t(e));}};var F={EMPTY_INITIAL_STATE:"You passed an empty initial array in the options. Please either remove the 'initial' property or include at least one element in the array.",MISSING_IDS:"You set 'generateId' to false but did not provide IDs for all steps. Please ensure all steps have IDs or set 'generateId' to true.",NOT_ENOUGH_POINTS_TO_CLOSE:"At least three points are required to close a polygon or a line. Please add more points or set 'closeGeometry' to false.",FIRST_LAST_POINT_NOT_EQUAL:"The first and last points of a polygon or a closed linestring must be the same. Please ensure the first and last points are equal or set 'closeGeometry' to false."};var ee=class{val;next;constructor(e=null,t=null){this.val=e,this.next=t;}},U=class extends x{head;tail;size;constructor(e){super();let t=M.initStore(e);this.head=t?t.head:null,this.tail=t?t.tail:null,this.size=t?t.size:0;}push(e){let t=new ee(e);this.head?this.tail&&(this.tail.next=t,this.tail=t):this.head=this.tail=t,this.size++,this.pingConsumers();}insert(e,t){let i=new ee(e,t.next);this.tail===t&&this.head===t.next&&(this.tail=i),t.next=i,this.size++;}findStepById(e){let t=this.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.val&&t.val.id===e)return t.val;i.add(t),t=t.next;}return null}removeStepById(e){if(!this.head)return null;let t=this.head,i=null;for(;t!==null;){if(t?.val?.id===e)return t===this.head?(this.head=t.next,this.tail&&(this.tail.next=t.next)):i.next=t.next,t===this.tail&&(this.tail=i),this.size--,this.pingConsumers(),t;i=t,t.next&&(t=t.next);}return null}reset(){this.head=null,this.tail=null,this.size=0,this.pingConsumers();}pingConsumers=()=>{this.notify({type:"STORE_CHANGED",data:{head:this.head,tail:this.tail,size:this.size}});}},M=class n{static isLastPoint=(e,t)=>e.tail?.val?.id===t;static initStore(e){if(!e?.initial)return null;if(e&&e.initial&&!e.initial.steps.length)throw new Error(F.EMPTY_INITIAL_STATE);if(e&&e.initial.steps){let{steps:o,closeGeometry:s,generateId:a}=e.initial;return n.fromArray(o,s,a)}return null}static#e=e=>e.map(t=>({...t,id:_()}));static buildStepSequence(e){let t=new U;return e.forEach(i=>{t.push(i);}),t}static fromArray(e,t,i){let o=i?this.#e(e):e,s=this.buildStepSequence(o);return t&&s.tail&&(s.tail.next=s.head),s}static toArray(e){if(!e)return [];let t=new Set,i=[],o=e;for(;o!==null&&!t.has(o);)t.add(o),i.push(o.val),o=o.next;return i}};var v={DOUBLECLICK:"mdl:doubleclick",POINTENTER:"mdl:pointenter",POINTLEAVE:"mdl:pointleave",MOVEEND:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REMOVEALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",LINE:"mdl:line",POLYGON:"mdl:polygon"};var m={panel:{size:"medium",buttons:{undo:{visible:!0},delete:{visible:!0},save:{visible:!0,clearOnSave:!0}}},modes:{initial:null,line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{onLinePoint:w,firstPoint:T,points:D,line:B,polygon:H,breakLine:N},initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close line",createPolygon:"Create polygon"}};var f=class{static addPoint(e,t,i){t.fire(v.ADD,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static movePoint(e,t){t.fire(v.MOVEEND,{id:e.id,start_coordinates:{lat:e.start.lat,lng:e.start.lng},end_coordinates:{lat:e.end.lat,lng:e.end.lng},total:e.total,timestamp:Date.now()});}static pointDoubleClick(e,t){t.fire(v.DOUBLECLICK,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){t.fire(v.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){t.fire(v.POINTLEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undoPoint(e,t,i){t.fire(v.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static removeAllPoints(e,t){e.fire(v.REMOVEALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:o,mode:s}=e;o.fire(v.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onLineBreak(e){e.fire(v.BREAK);}};var te=class{#e;#t;constructor(e){this.#e=e,this.#t=new O;}initEvents(){let{panel:e}=this.#e;e&&(l.manageEventListener("add",e?._undoButton,"click",this.#n),l.manageEventListener("add",e?._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._undoButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._deleteButton,"click",this.#o),l.manageEventListener("add",e?._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._deleteButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._saveButton,"click",this.onSaveClick),l.manageEventListener("add",e?._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._saveButton,"mouseleave",this.onMouseLeave));}removeEvents(){let{panel:e}=this.#e;e&&e._undoButton&&(l.manageEventListener("remove",e._undoButton,"click",this.#n),l.manageEventListener("remove",e._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._undoButton,"mouseleave",this.onMouseLeave)),e&&e._deleteButton&&(l.manageEventListener("remove",e._deleteButton,"click",this.#o),l.manageEventListener("remove",e._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._deleteButton,"mouseleave",this.onMouseLeave)),e&&e._saveButton&&(l.manageEventListener("remove",e._saveButton,"click",this.onSaveClick),l.manageEventListener("remove",e._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._saveButton,"mouseleave",this.onMouseLeave));}#i=e=>{let{options:t}=this.#e;return {undo:t.locale.undo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let t=e.target.getAttribute("data-type");if(t){let i=this.#i(t);this.#t.create({label:i,placement:"bottom"}).setPosition(this.#t.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.#t.remove();};#o=e=>{let{tiles:t,mode:i,panel:o,store:s,map:a}=this.#e;s.reset(),o.hidePanel(),i.reset(),g.togglePointCircleRadius(a,"default"),this.#t.remove(),t.resetGeometries(),f.removeAllPoints(a,e);};#n=e=>{let{store:t,panel:i,map:o,tiles:s}=this.#e,a=t.tail?.val;t.removeStepById(a.id);let h={...a,total:t.size};f.undoPoint(h,o,e),d.switchToLineModeIfCan(this.#e),i?.onPointRemove(t.tail?.val),this.#t.remove(),requestAnimationFrame(s.render);};onSaveClick=e=>{let{store:t,options:i}=this.#e;f.onSaveClick(this.#e,M.toArray(t.head),e),this.#t.remove(),i.panel.buttons.save.clearOnSave&&this.#o(e);}};var P=class{static updatePointsData(e){let i=e.target.getSource(u.SinglePointSource);i&&i.setData({type:"Feature",geometry:{type:"Point",coordinates:[e.lngLat.lng,e.lngLat.lat]},properties:{}});}static setSinglePointVisible(e){e.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");}static setSinglePointHidden(e){let t=e.target;setTimeout(()=>{t.setLayoutProperty(r.SinglePointLayer,"visibility","none");},33);}static triggerPostPointAddition(e,t){let{panel:i,tiles:o,store:s,map:a}=t;d.canCloseGeometry(s)&&g.togglePointCircleRadius(a,"large"),i?.setPanelLocation(e.lngLat),o.render();}static addPointToMap=(e,t)=>{let{store:i,map:o,mode:s}=t,a={...e.lngLat,id:_()};i.push(a),f.addPoint({...a,total:i.size},o,s),this.triggerPostPointAddition(e,t);};static updateSelectedStepLatLng=(e,t)=>{t.lat=e.lngLat.lat,t.lng=e.lngLat.lng;}};var ye=(n,e)=>{let t=e.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.next&&t.next.val&&t.val){let o=n.target,s=y.getPixelCoordinates(o,t.val),a=y.getPixelCoordinates(o,t.next.val),h=y.getPixelCoordinates(o,n.lngLat);if(d.checkIfPointIsOnLine(s,a,h))return t}i.add(t),t=t.next;}return null},be=(n,e)=>{let t=ye(n,e);if(t){let i={...n.lngLat,id:_()};return e.insert(i,t),i}return null},_e=(n,e)=>{let{store:t,tiles:i,panel:o}=e;t.tail?.val&&(o?.setPanelLocation(t.tail.val),P.setSinglePointHidden(n),i.render());},Ce=n=>y.isFeatureTriggered(n,[r.PointsLayer,r.FirstPointLayer]);var Se=15,ie=class{props;#e;#t;constructor(e){this.props=e,this.#e=null,this.#t=S(this.#o,Se);}initBreakEvents=()=>{let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mouseenter",r.LineLayerTransparent,this.#t),e.on("mousemove",r.LineLayerTransparent,this.#t),e.on("mouseleave",r.LineLayerTransparent,this.#n);};removeBreakEvents=()=>{let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mouseenter",r.LineLayerTransparent,this.#t),e.off("mousemove",r.LineLayerTransparent,this.#t),e.off("mouseleave",r.LineLayerTransparent,this.#n);};hideBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};#i=()=>{let{store:e,mode:t,panel:i,map:o,tiles:s}=this.props,a=this.#e?.next?.val?.id;d.breakGeometry(e,a),e.tail?.val&&i.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng}),this.#n(),o.setLayoutProperty(r.PolygonLayer,"visibility","none"),t.reset(),s.render(),f.onLineBreak(o);};#o=e=>{let{map:t,store:i}=this.props,o=ye(e,i);o?.val?.id!==this.#e?.val?.id&&(this.#e=o);let s=t.getSource(u.LineSourceBreak),a=[o?.val?.lng,o?.val?.lat],h=[o?.next?.val?.lng,o?.next?.val?.lat],L=b.getLine(a,h);L&&(s.setData(L),this.showBreakLine());};#n=()=>{setTimeout(()=>{this.hideBreakLine();},Se+10);}};var we=10,oe=class{#e;#t;#i;#o;#n;#s;constructor(e){this.#e=e,this.#t=e.options.dynamicLine,this.#i=null,this.#o=null,this.#r(),this.#s=S(this.#p,we);}#r(){this.#e.store.addObserver(this.#l),this.#e.mode.addObserver(this.#c),this.#e.mouseEvents.addObserver(this.#a);}removeLine=()=>{this.hideDynamicLine();};removeConsumers=()=>{this.#e.store.removeObserver(this.#l),this.#e.mode.removeObserver(this.#c),this.#e.mouseEvents.removeObserver(this.#a);};#a=e=>{let{mode:t}=this.#e;if(!t.getClosedGeometry()&&(e.type==="lastPointMouseClick"&&e.data?(this.hideDynamicLine(),this.#t=!1):e.type==="lastPointMouseClick"&&!e.data&&(this.#t=!0),!!this.#t&&((e.type==="pointMouseEnter"||e.type==="lineMouseEnter")&&e.data&&this.hideDynamicLine(),(e.type==="pointMouseLeave"||e.type==="lineMouseLeave")&&e.data))){let{store:i}=this.#e;this.#i=i.tail?.val,this.#o=i.tail?.val,this.showDynamicLine();}};#l=e=>{let{store:t}=this.#e;switch(e.type){case"STORE_CHANGED":e.data.tail?.val&&!d.isClosedGeometry(t)&&(this.#i=e.data.tail?.val,this.showDynamicLine());break;}};#c=e=>{let{store:t}=this.#e;e.type==="CLOSED_GEOMETRY_CHANGED"&&(e.data&&this.hideDynamicLine(),!e.data&&t?.tail?.val&&(this.#i=t?.tail?.val,this.showDynamicLine()));};initDynamicEvents=()=>{let{map:e}=this.#e;e.on("click",this.#f),e.on("mousemove",this.#s),e.on(v.REMOVEALL,this.hideDynamicLine),e.on(v.UNDO,this.#m),e.on(v.DOUBLECLICK,this.#v);};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#f),e.off("mousemove",this.#s),e.off(v.REMOVEALL,this.hideDynamicLine),e.off(v.UNDO,this.#m),e.off(v.DOUBLECLICK,this.#v);};hideDynamicLine=()=>{let{map:e,tiles:t}=this.#e;this.#i=null,this.#o=null,this.#n=null,e.off("mousemove",this.#s),t.renderLines(V,u.LineDynamicSource),e.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};showDynamicLine=()=>{let{map:e}=this.#e,t=[this.#i?.lng,this.#i?.lat],i=[this.#o?.lng,this.#o?.lat];this.#n=b.getLine(t,i),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.#o&&this.#h({lng:this.#o?.lng,lat:this.#o?.lat}),e.on("mousemove",this.#s);};#h=e=>{if(!this.#n)return;let{tiles:t}=this.#e;this.#n.features[0].geometry.coordinates[1]=[e.lng,e.lat],t.renderLines(this.#n,u.LineDynamicSource);};#p=e=>{this.#h(e.lngLat);};#f=e=>{let{mode:t}=this.#e,i=y.isFeatureTriggered(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.#o={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hideDynamicLine();};#m=e=>{let{store:t,mode:i}=this.#e;if(!i.getClosedGeometry()){let o=e.target.unproject({x:e.originalEvent.x,y:e.originalEvent.y});this.#o={lng:o.lng,lat:o.lat},this.#i=t.tail?.val,this.showDynamicLine();}};#v=e=>{let{store:t,mode:i}=this.#e;i.getClosedGeometry()||(this.#o={lng:e.coordinates.lng,lat:e.coordinates.lat},this.#i=t.tail?.val,this.showDynamicLine());}};var De=22,ne=class{props;#e;#t;constructor(e){this.props=e,this.#e=!1,this.#t=null;}initEvents(){let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mousemove",r.LineLayerTransparent,this.#n),e.on("mouseenter",r.LineLayerTransparent,this.#s),e.on("mouseleave",r.LineLayerTransparent,this.#r);}removeEvents(){let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mousemove",r.LineLayerTransparent,this.#n),e.off("mouseenter",r.LineLayerTransparent,this.#s),e.off("mouseleave",r.LineLayerTransparent,this.#r);}#i=e=>{let{store:t,map:i,mode:o}=this.props;if(Ce(e))return;let s=be(e,t);s&&(f.addPoint({...s,total:t.size},i,o),_e(e,this.props));};#o=e=>{P.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)&&P.updatePointsData(e);};#n=S(e=>{if(y.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer]))return;let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(this.#t=e,!this.#e&&(this.#e=!0,requestAnimationFrame(()=>{this.#t&&(this.#o(this.#t),this.#e=!1);})));},De);#s=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||y.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer])||(t.lineMouseEnter=!0,P.setSinglePointVisible(e));};#r=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(t.lineMouseLeave=!0,P.setSinglePointHidden(e));}};var se=class{props;#e;#t;#i;#o;constructor(e){this.props=e,this.#e=new ie(e),this.#t=new ne(e),this.#i=null,this.#o="default";}init(){this.#n(),this.#s(),this.#r();}#n=()=>{window.innerWidth<=768||this.props.options.dynamicLine&&(this.#i=new oe(this.props));};#s(){!this.props.mode.getBreak()&&(this.#t.initEvents(),this.props.options.dynamicLine&&this.#i?.initDynamicEvents());}#r(){this.props.mode.addObserver(this.#h),this.props.mouseEvents.addObserver(this.#c);}remove(){this.#a(),this.#l();}#a(){this.props.mode.removeObserver(this.#h),this.props.mouseEvents.removeObserver(this.#c),this.props.options.dynamicLine&&this.#i?.removeConsumers();}#l(){this.#e.removeBreakEvents(),this.#t.removeEvents(),this.props.options.dynamicLine&&(this.#i?.removeEvents(),this.#i?.removeLine());}#c=e=>{let{type:t,data:i}=e,{mode:o}=this.props;if(!(!i||!o.getBreak()))switch(t){case"pointMouseDown":this.#e.removeBreakEvents(),this.#e.hideBreakLine();break;case"pointMouseUp":this.#e.initBreakEvents();break;}};#h=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.#o==="break"&&(this.#e.removeBreakEvents(),this.#t.initEvents(),this.#o="default"),t==="BREAK_CHANGED"&&i&&this.#o==="default"&&(this.#t.removeEvents(),this.#e.initBreakEvents(),this.#o="break");}};var re=class{#e;#t;#i;constructor(e){this.#t=e,this.#e=!1,this.#i=new O,e.mode.addObserver(this.#o);}initEvents(){let{map:e}=this.#t;e.on("click",r.FirstPointLayer,this.#n),e.on("mouseenter",r.FirstPointLayer,this.#c),e.on("mouseleave",r.FirstPointLayer,this.#a),e.on("mouseup",r.FirstPointLayer,this.#r),e.on("mousedown",r.FirstPointLayer,this.#s);}removeEvents(){let{map:e}=this.#t;e.off("click",r.FirstPointLayer,this.#n),e.off("mouseenter",r.FirstPointLayer,this.#c),e.off("mouseleave",r.FirstPointLayer,this.#a),e.off("mouseup",r.FirstPointLayer,this.#r);}#o=e=>{let{map:t,store:i}=this.#t,{type:o,data:s}=e;o==="MODE_CHANGED"&&(s==="line"||s==="polygon"?t.on("click",r.FirstPointLayer,this.#n):t.off("click",r.FirstPointLayer,this.#n),d.canCloseGeometry(i)&&g.togglePointCircleRadius(t,"large"));};#n=()=>{let{store:e,map:t,mode:i,tiles:o}=this.#t;if(i.getMode()==="polygon"&&t.setLayoutProperty(r.PolygonLayer,"visibility","visible"),d.canCloseGeometry(e)){d.closeGeometry(e,i);let s=Object.assign({},e.head?.val,{id:_(),total:e.size});f.addPoint(s,t,i),g.togglePointCircleRadius(t,"default"),o.render();}};#s=()=>{this.#e=!0,this.#i.remove();};#r=()=>{this.#e=!1;};#a=()=>{let{mouseEvents:e}=this.#t;this.#e||(e.firstPointMouseLeave=!0,this.#i.remove());};#l=()=>{let{mode:e,options:t}=this.#t;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};#c=e=>{let{mode:t,mouseEvents:i,store:o}=this.#t;if(!(t.getClosedGeometry()||this.#e)&&(i.firstPointMouseEnter=!0,d.canCloseGeometry(o))){let{x:s,y:a}=e.originalEvent;if(s&&a){this.#i.create({label:this.#l(),placement:"bottom"});let L=this.#i._label?this.#i._label.clientWidth/2:0;this.#i.setPosition({x:s-L,y:a+14});}}}};var ae=class{#e;#t;#i;#o;#n;#s;#r;#a;constructor(e){this.#e=e,this.#t=void 0,this.#i=null,this.#o=null,this.#n=null,this.#s=new re(e),this.#r=!1,this.#a=null;}#l=()=>{let{map:e}=this.#e;e.on("click",r.FirstPointLayer,this.#p),e.on("mouseenter",r.FirstPointLayer,this.#L),e.on("mouseleave",r.FirstPointLayer,this.#g),e.on("mousedown",r.FirstPointLayer,this.#d),e.on("mouseup",r.FirstPointLayer,this.#u),e.on("touchend",r.FirstPointLayer,this.#u),e.on("touchstart",r.FirstPointLayer,this.#d),this.#s.initEvents();};initEvents=()=>{let{map:e}=this.#e;e.on("click",this.#m),e.on("dblclick",this.#h),e.on("click",r.PointsLayer,this.#p),e.on("mouseenter",r.PointsLayer,this.#L),e.on("mouseleave",r.PointsLayer,this.#g),e.on("mousedown",r.PointsLayer,this.#d),e.on("mouseup",r.PointsLayer,this.#u),e.on("touchend",r.PointsLayer,this.#u),e.on("touchstart",r.PointsLayer,this.#d),this.#l();};#c=()=>{let{map:e}=this.#e;e.off("click",r.FirstPointLayer,this.#p),e.off("mouseenter",r.FirstPointLayer,this.#L),e.off("mouseleave",r.FirstPointLayer,this.#g),e.off("mousedown",r.FirstPointLayer,this.#d),e.off("mouseup",r.FirstPointLayer,this.#u),e.off("touchend",r.PointsLayer,this.#u),e.off("touchstart",r.PointsLayer,this.#d),this.#s.removeEvents();};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#m),e.off("dblclick",this.#h),e.off("mousemove",this.#y),e.off("click",r.PointsLayer,this.#p),e.off("mouseenter",r.PointsLayer,this.#L),e.off("mouseleave",r.PointsLayer,this.#g),e.off("mousedown",r.PointsLayer,this.#d),e.off("mouseup",r.PointsLayer,this.#u),this.#c();};#h=e=>{e.preventDefault();};#p=e=>{let{store:t,tiles:i,panel:o,map:s,mouseEvents:a}=this.#e;g.isDoubleClick()&&this.#o&&(t.removeStepById(this.#o.id),o.onPointRemove(t.tail?.val),f.pointDoubleClick({...this.#o,total:t.size},this.#e.map),d.switchToLineModeIfCan(this.#e));let h=y.queryPointId(s,e.point);M.isLastPoint(t,h)&&(a.lastPointMouseClick=!0,a.lastPointMouseUp=!1),i.render();};#f=e=>y.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer,r.LineLayerTransparent,r.LineLayerBreak]);#m=e=>{let{mode:t,mouseEvents:i,map:o}=this.#e;t.getClosedGeometry()||this.#f(e)||(i.lastPointMouseClick&&(i.lastPointMouseClick=!1),o.getCanvasContainer().style.cursor="grab",P.addPointToMap(e,this.#e),P.setSinglePointHidden(e));};#v=e=>{e.originalEvent.buttons===0&&this.#u();};#E=e=>{let{tiles:t}=this.#e;t.renderOnMouseMove(this.#n,e.lngLat);};#y=S(e=>{this.#a=e,this.#r||(this.#r=!0,requestAnimationFrame(()=>{!this.#o||!this.#a||(P.updateSelectedStepLatLng(this.#a,this.#o),this.#v(this.#a),this.#E(this.#a),this.#r=!1);}));},15);#L=e=>{let{mouseEvents:t,map:i,store:o}=this.#e;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;P.setSinglePointHidden(e);let s=y.queryPointId(i,e.point);M.isLastPoint(o,s)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let a=o.findStepById(s);a&&(this.#i=a,f.enterPoint(Object.assign({},a,{total:o.size}),i));};#g=e=>{let{mouseEvents:t,store:i,map:o}=this.#e;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let s=y.queryPointId(o,e.point);M.isLastPoint(i,s)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),f.leavePoint(Object.assign({},this.#i,{total:i.size}),o);};#P=()=>{let{store:e,panel:t}=this.#e;this.#o&&M.isLastPoint(e,this.#o.id)&&t.hidePanel();};#M=e=>{let{store:t,map:i}=this.#e,o=y.queryPointId(i,e.point),s=t.findStepById(o);s&&(this.#o=s);};#d=e=>{e.preventDefault();let{mouseEvents:t,map:i,store:o}=this.#e;g.removeTransparentLine(i),this.#M(e),this.#P();let s=y.queryPointId(i,e.point);this.#n=d.getGeometryIndex(o,s),t&&(t.pointMouseDown=!0),this.#t=e.lngLat,i.on("mousemove",this.#y),i.on("touchmove",this.#y);};#u=()=>{let{mouseEvents:e,store:t,panel:i,map:o,options:s}=this.#e;e.pointMouseUp=!0,this.#o&&(M.isLastPoint(t,this.#o.id)&&t.tail?.val&&i?.setPanelLocation(t.tail.val),i?.showPanel(),f.movePoint({id:this.#o.id,total:t.size,end:{lat:this.#o.lat,lng:this.#o.lng},start:this.#t},o)),e&&(e.pointMouseDown=!1),g.addTransparentLine(o,s),o.off("mousemove",this.#y),o.off("touchmove",this.#y);}};var le=class extends R{#e;#t;#i;#o;#n;constructor(e){super({...e}),this.#e=e,this.#t=new te(e),this.#i=new Q(e),this.#o=new ae(e),this.#n=new se(e),e.map.on("mode:initialize",this.#s),e.map.on("mode:remove",this.#r);}#s=()=>{this.#n.init(),this.#t?.initEvents(),this.#o?.initEvents();};#r=()=>{this.#t?.removeEvents(),this.#o?.removeEvents(),this.#n?.remove();};removeMapEventsAndConsumers=()=>{this.#t?.removeEvents(),this.#o?.removeEvents(),this.#i?.remove(),this.#n?.remove(),this.#e.map.off("mode:initialize",this.#s);}};var ce=class{#e;_line;_polygon;_break;_container;constructor(e){this.#e=e.options,this._line=void 0,this._polygon=void 0,this._break=void 0,this._container=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl(e);}createControlButton=(e,t,i,o)=>{let s=this.#e.panel.size,a=l.create("button",`control-button control-button-${s}`,this._container);return a.setAttribute("aria-label",t),a.setAttribute("data-type",e),i&&a.classList.add("control-button-active"),o&&(a.setAttribute("disabled","true"),a.setAttribute("aria-disabled","true")),l.create("span",`icon ${e} icon-${s}`,a),a};#t=e=>{let{mode:t,options:i}=e,o=this.#e.modes.line.visible,s=i.locale.line;o&&(this._line=this.createControlButton("line",s,t.getMode()==="line"));};#i=e=>{let{mode:t,options:i}=e,o=this.#e.modes.polygon.visible,s=i.locale.polygon;o&&(this._polygon=this.createControlButton("polygon",s,t.getMode()==="polygon"));};#o=e=>{let{mode:t,options:i}=e,o=this.#e.modes.breakGeometry.visible,s=i.locale.break;if(o){let h=!this.#e?.initial?.closeGeometry,L=t.getBreak();this._break=this.createControlButton("break",s,L,h);}};createControl=e=>{this.#t(e),this.#i(e),this.#o(e);};getContainer=()=>this._container};function Ae(n){return n.initial?.geometry?n.initial?.geometry:n.modes.initial?n.modes.initial:null}var he=class extends x{#e;#t;#i;constructor(e){super(),this.#e=Ae(e),this.#t=!1,this.#i=e.initial?.closeGeometry??!1;}getMode=()=>this.#e;setMode=e=>{this.#e=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.#t;setBreak=e=>{this.#t=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.#i;setClosedGeometry=e=>{this.#i=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.#i});};isPolygon=()=>this.#e==="polygon"&&this.#i;reset=()=>{this.setMode(this.getMode()),this.setClosedGeometry(!1);};pingConsumers=()=>{this.notify({type:"MODE_CHANGED",data:this.getMode()}),this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.getClosedGeometry()});}};var pe=class{#e;#t;constructor(e){this.#e=e,this.#t=this.#e.map.getCanvasContainer(),this.#t.style.cursor=e.mode.getMode()?E.CROSSHAIR:E.AUTO,this.#i();}set=e=>{this.#t.style.cursor=e;};get=()=>this.#t.style.cursor;handleMouseLeave=()=>{let{mouseEvents:e,mode:t}=this.#e;if(!e.pointMouseDown){if(!t.getMode()){this.set(E.AUTO);return}t.getClosedGeometry()?this.set(E.AUTO):this.set(E.CROSSHAIR);}};handleFirstPointMouseEnter=()=>{let{mode:e,store:t}=this.#e;e.getClosedGeometry()&&this.set(E.MOVE),d.canCloseGeometry(t)&&this.set(E.POINTER);};#i(){let{mouseEvents:e}=this.#e;e.addObserver(this.#o);}removeConsumers(){let{mouseEvents:e}=this.#e;e.removeObserver(this.#o);}#o=e=>{let{mode:t,mouseEvents:i}=this.#e;if(t.getBreak())return;let{type:o,data:s}=e;if(s)switch(o){case"pointMouseDown":this.set(E.GRABBING);break;case"pointMouseUp":this.set(E.GRAB);break;case"pointMouseEnter":if(i.pointMouseDown)return;this.set(E.GRAB);break;case"pointMouseLeave":this.handleMouseLeave();break;case"lineMouseEnter":if(i.pointMouseDown)return;this.set(E.POINTER);break;case"lineMouseLeave":this.handleMouseLeave();break;case"firstPointMouseEnter":this.handleFirstPointMouseEnter();break;case"firstPointMouseLeave":this.handleMouseLeave();break;case"lastPointMouseEnter":this.set(E.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var ue=class extends x{#e;#t;#i;#o;#n;#s;#r;#a;#l;#c;#h;#p;constructor(){super(),this.#e=!1,this.#t=!1,this.#i=!1,this.#o=!1,this.#n=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#l=!1,this.#c=!1,this.#h=!1,this.#p=!1;}get firstPointMouseEnter(){return this.#e}set firstPointMouseEnter(e){this.#e=e,this.notify({type:"firstPointMouseEnter",data:e});}get firstPointMouseLeave(){return this.#t}set firstPointMouseLeave(e){this.#t=e,this.notify({type:"firstPointMouseLeave",data:e});}get lastPointMouseClick(){return this.#i}set lastPointMouseClick(e){this.#i=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#o}set lastPointMouseUp(e){this.#o=e,this.notify({type:"lastPointMouseUp",data:e});}get lastPointMouseEnter(){return this.#n}set lastPointMouseEnter(e){this.#n=e,this.notify({type:"lastPointMouseEnter",data:e});}get lastPointMouseLeave(){return this.#s}set lastPointMouseLeave(e){this.#s=e,this.notify({type:"lastPointMouseLeave",data:e});}get pointMouseDown(){return this.#r}set pointMouseDown(e){this.#r=e,this.notify({type:"pointMouseDown",data:e});}get pointMouseUp(){return this.#a}set pointMouseUp(e){this.#a=e,this.notify({type:"pointMouseUp",data:e});}get pointMouseEnter(){return this.#l}set pointMouseEnter(e){this.#l=e,this.notify({type:"pointMouseEnter",data:e});}get pointMouseLeave(){return this.#c}set pointMouseLeave(e){this.#c=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#h}set lineMouseEnter(e){this.#h=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#p}set lineMouseLeave(e){this.#p=e,this.notify({type:"lineMouseLeave",data:e});}};var q=class{static allStepsHaveIds(e){return e.every(t=>"id"in t&&t.id!==void 0)}static checkIfMissingIds(e,t){let i=!t,o=!this.allStepsHaveIds(e);if(i&&o)throw new Error(F.MISSING_IDS)}static checkIfEnoughPointsToClose(e,t){if(t&&e.length<3)throw new Error(F.NOT_ENOUGH_POINTS_TO_CLOSE)}static checkIfPolygonIsClosed(e){let{closeGeometry:t,steps:i}=e;if(i){let o=i[0]?.lng,s=i[i.length-1]?.lng,a=i[0]?.lat,h=i[i.length-1]?.lat;if((o!==s||a!==h)&&t)throw new Error(F.FIRST_LAST_POINT_NOT_EQUAL)}}static checkInitialStepsOption(e){let{closeGeometry:t,generateId:i,steps:o}=e;this.checkIfMissingIds(o,i),this.checkIfEnoughPointsToClose(o,t),this.checkIfPolygonIsClosed(e);}static init(e){return e?{panel:Ie(e),modes:Be(e),layersPaint:Ne(e),initial:e.initial||m.initial,locale:Re(e),dynamicLine:e.dynamicLine??m.dynamicLine}:m}};function Ie(n){return {size:n.panel?.size||m.panel.size,buttons:{undo:{visible:n.panel?.buttons?.undo?.visible??m.panel.buttons.undo.visible},delete:{visible:n.panel?.buttons?.delete?.visible??m.panel.buttons.delete.visible},save:{visible:n.panel?.buttons?.save?.visible??m.panel.buttons.save.visible,clearOnSave:n.panel?.buttons?.save?.clearOnSave??m.panel.buttons.save.clearOnSave}}}}function Be(n){return {initial:n.modes?.initial||m.modes.initial,line:{visible:n?.modes?.line?.visible!==void 0?n.modes.line.visible:n?.initial?.geometry==="line"||m.modes.line.visible,closeGeometry:n?.modes?.line?.closeGeometry??n?.initial?.closeGeometry??m.modes.line.closeGeometry},polygon:{visible:n?.modes?.polygon?.visible!==void 0?n.modes.polygon.visible:n?.initial?.geometry==="polygon"||m.modes.polygon.visible},breakGeometry:{visible:n?.modes?.breakGeometry?.visible??m.modes.breakGeometry.visible}}}function Ne(n){return {onLinePoint:{"circle-radius":n.layersPaint?.onLinePoint?.["circle-radius"]||w["circle-radius"],"circle-color":n.layersPaint?.onLinePoint?.["circle-color"]||w["circle-color"],"circle-stroke-color":n.layersPaint?.onLinePoint?.["circle-stroke-color"]||w["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.onLinePoint?.["circle-stroke-width"]||w["circle-stroke-width"],...n.layersPaint?.onLinePoint},firstPoint:{"circle-radius":n.layersPaint?.firstPoint?.["circle-radius"]||T["circle-radius"],"circle-color":n.layersPaint?.firstPoint?.["circle-color"]||T["circle-color"],"circle-stroke-color":n.layersPaint?.firstPoint?.["circle-stroke-color"]||T["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.firstPoint?.["circle-stroke-width"]||T["circle-stroke-width"],...n.layersPaint?.firstPoint},points:{"circle-radius":n.layersPaint?.points?.["circle-radius"]||D["circle-radius"],"circle-color":n.layersPaint?.points?.["circle-color"]||D["circle-color"],"circle-stroke-color":n.layersPaint?.points?.["circle-stroke-color"]||D["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.points?.["circle-stroke-width"]||D["circle-stroke-width"],...n.layersPaint?.points},line:{"line-width":n.layersPaint?.line?.["line-width"]||B["line-width"],"line-color":n.layersPaint?.line?.["line-color"]||B["line-color"],"line-opacity":n.layersPaint?.line?.["line-opacity"]||B["line-opacity"],...n.layersPaint?.line},polygon:{"fill-color":n.layersPaint?.polygon?.["fill-color"]||H["fill-color"],"fill-opacity":n.layersPaint?.polygon?.["fill-opacity"]||H["fill-opacity"],...n.layersPaint?.polygon},breakLine:{"line-width":n.layersPaint?.breakLine?.["line-width"]||N["line-width"],"line-color":n.layersPaint?.breakLine?.["line-color"]||N["line-color"],"line-dasharray":n.layersPaint?.breakLine?.["line-dasharray"]||N["line-dasharray"],...n.layersPaint?.breakLine}}}function Re(n){return {save:n.locale?.save??m.locale.save,delete:n.locale?.delete??m.locale.delete,undo:n.locale?.undo??m.locale.undo,line:n.locale?.line??m.locale.line,polygon:n.locale?.polygon??m.locale.polygon,break:n.locale?.break??m.locale.break,closeLine:n.locale?.closeLine??m.locale.closeLine,createPolygon:n.locale?.createPolygon??m.locale.createPolygon}}var fe=class n{#e;#t;#i;#o;#n;#s;#r;#a;#l;static#c=null;static#h=!1;constructor(e){if(this.#o=q.init(e),this.#o.initial&&q.checkInitialStepsOption(this.#o.initial),n.#h)throw new Error("Use 'DrawLibre.getInstance()' instead of 'new DrawLibre()'.");n.#h=!0,this.#t=void 0,this.#i=void 0,this.#n=void 0,this.#s=void 0,this.#r=void 0,this.#l=void 0,this.#a=void 0;}static getInstance(e){return n.#c||(n.#c=new n(e)),n.#c}onAdd(e){this.#t=new U(this.#o),this.#i=new he(this.#o),this.#r=new j({map:e,mode:this.#i,options:this.#o,store:this.#t}),this.#s=new R({map:e,store:this.#t,options:this.#o,mode:this.#i});let t=new ce({options:this.#o,mode:this.#i});return this.#l=new ue,this.#a=new pe({map:e,mode:this.#i,mouseEvents:this.#l,store:this.#t}),this.#n=new le({map:e,store:this.#t,options:this.#o,panel:this.#r,control:t,mode:this.#i,tiles:this.#s,mouseEvents:this.#l}),this.#i.getMode()&&e.fire("mode:initialize"),this.#i.pingConsumers(),this.#e=t.getContainer(),this.#e}onRemove(){this.#a?.removeConsumers(),this.#s?.removeTiles(),this.#n?.removeMapEventsAndConsumers(),this.#r?.removePanel(),this.#t?.reset(),this.#i?.unsubscribe(),this.#e&&l.remove(this.#e);}setSteps=e=>{if(Array.isArray(e))e.forEach(t=>{let i={...t,id:t.id||_()};this.#t?.push(i);});else throw new Error("Invalid argument. Expected an array of steps.");this.#s?.render();};findStepById=e=>this.#t?.findStepById(e);getAllSteps=(e="array")=>{if(e==="array"&&this.#t)return M.toArray(this.#t.head);if(e==="linkedlist")return this.#t;throw new Error("Invalid type specified. Use 'array' or 'linkedlist'.")};setOptions=e=>{this.#o=e(this.#o);};removeAllSteps=()=>{this.#t?.reset(),this.#r?.removePanel(),this.#s?.render();}};
|
|
6
6
|
|
|
7
|
-
exports.DRAW_LIBRE_EVENTS =
|
|
7
|
+
exports.DRAW_LIBRE_EVENTS = v;
|
|
8
8
|
exports.default = fe;
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var l=class o{static docStyle=typeof window<"u"&&window.document&&window.document.documentElement.style;static transformProp=o.testProp(["transform","WebkitTransform"]);static testProp(e){if(!o.docStyle)return e[0];for(let t=0;t<e.length;t++)if(e[t]in o.docStyle)return e[t];return e[0]}static create(e,t,i){let n=window.document.createElement(e);return t!==void 0&&(n.className=t),i&&i.appendChild(n),n}static remove(e){e.parentNode&&e.parentNode.removeChild(e);}static setTransform(e,t){o.transformProp&&e.style&&(e.style[o.transformProp]=t);}static manageEventListener(e,t,i,n,s={}){if(!t)return;let a=e==="add"?"addEventListener":"removeEventListener";"passive"in s?t[a](i,n,s):t[a](i,n,s.capture);}static mouseButton(e){return e.button}static addClassName(e,t){e.classList.contains(t)||e.classList.add(t);}static removeClassName(e,t){e.classList.contains(t)&&e.classList.remove(t);}};var S=class o{lng;lat;constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,this.lat>90||this.lat<-90)throw new Error("Invalid LngLat latitude value: must be between -90 and 90")}static convert(e){if(e instanceof o)return e;if(Array.isArray(e)&&(e.length===2||e.length===3))return new o(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null)return new o(Number("lng"in e?e.lng:e.lon),Number(e.lat));throw new Error("`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]")}};function H(o,...e){for(let t of e)for(let i in t)o[i]=t[i];return o}function Le(o,e,t){let i=new S(o.lng,o.lat);if(o=new S(o.lng,o.lat),e){let n=new S(o.lng-360,o.lat),s=new S(o.lng+360,o.lat),a=t.locationPoint(o).distSqr(e);t.locationPoint(n).distSqr(e)<a?o=n:t.locationPoint(s).distSqr(e)<a&&(o=s);}for(;Math.abs(o.lng-t.center.lng)>180;){let n=t.locationPoint(o);if(n.x>=0&&n.y>=0&&n.x<=t.width&&n.y<=t.height)break;o.lng>t.center.lng?o.lng-=360:o.lng+=360;}return o.lng!==i.lng&&t.locationPoint(o).y>t.height/2-t.getHorizon()?o:i}var me={center:"translate(-50%,-50%)",top:"translate(-50%,0)","top-left":"translate(0,0)","top-right":"translate(-100%,0)",bottom:"translate(-50%,-100%)","bottom-left":"translate(0,-100%)","bottom-right":"translate(-100%,-100%)",left:"translate(0,-50%)",right:"translate(-100%,-50%)"};function ge(o,e,t){let i=o.classList;for(let n in me)i.remove(`maplibregl-${t}-anchor-${n}`);i.add(`maplibregl-${t}-anchor-${e}`);}function Ee(o,e,t){t[o]&&t[o].indexOf(e)!==-1||(t[o]=t[o]||[],t[o].push(e));}function ye(o,e,t){if(t&&t[o]){let i=t[o].indexOf(e);i!==-1&&t[o].splice(i,1);}}var Y=class{_listeners;_oneTimeListeners;_eventedParent;_eventedParentData;on(e,t){return this._listeners=this._listeners||{},Ee(e,t,this._listeners),this}off(e,t){return ye(e,t,this._listeners),ye(e,t,this._oneTimeListeners),this}once(e,t){return t?(this._oneTimeListeners=this._oneTimeListeners||{},Ee(e,t,this._oneTimeListeners),this):new Promise(i=>this.once(e,i))}fire(e,t){typeof e=="string"&&(e=new I(e,t||{}));let i=e.type;if(this.listens(i)){e.target=this;let n=this._listeners&&this._listeners[i]?this._listeners[i].slice():[];for(let h of n)h.call(this,e);let s=this._oneTimeListeners&&this._oneTimeListeners[i]?this._oneTimeListeners[i].slice():[];for(let h of s)ye(i,h,this._oneTimeListeners),h.call(this,e);let a=this._eventedParent;a&&(H(e,typeof this._eventedParentData=="function"?this._eventedParentData():this._eventedParentData),a.fire(e));}else e instanceof ErrorEvent&&console.error(e.error);return this}listens(e){return this._listeners&&this._listeners[e]&&this._listeners[e].length>0||this._oneTimeListeners&&this._oneTimeListeners[e]&&this._oneTimeListeners[e].length>0||this._eventedParent&&this._eventedParent.listens(e)}setEventedParent(e,t){return this._eventedParent=e,this._eventedParentData=t,this}},I=class{type;constructor(e,t={}){H(this,t),this.type=e;}};var u=class o{x;y;constructor(e,t){this.x=e,this.y=t;}mag(){return Math.sqrt(this.x*this.x+this.y*this.y)}equals(e){return this.x===e.x&&this.y===e.y}dist(e){return Math.sqrt(this.distSqr(e))}distSqr(e){let t=e.x-this.x,i=e.y-this.y;return t*t+i*i}angle(){return Math.atan2(this.y,this.x)}angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)}angleWith(e){return this.angleWithSep(e.x,e.y)}angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)}_matMult(e){let t=e[0]*this.x+e[1]*this.y,i=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=i,this}_add(e){return this.x+=e.x,this.y+=e.y,this}_sub(e){return this.x-=e.x,this.y-=e.y,this}_mult(e){return this.x*=e,this.y*=e,this}_div(e){return this.x/=e,this.y/=e,this}_multByPoint(e){return this.x*=e.x,this.y*=e.y,this}_divByPoint(e){return this.x/=e.x,this.y/=e.y,this}_unit(){return this._div(this.mag()),this}_perp(){let e=this.y;return this.y=this.x,this.x=-e,this}_rotate(e){let t=Math.cos(e),i=Math.sin(e),n=t*this.x-i*this.y,s=i*this.x+t*this.y;return this.x=n,this.y=s,this}_rotateAround(e,t){let i=Math.cos(e),n=Math.sin(e),s=t.x+i*(this.x-t.x)-n*(this.y-t.y),a=t.y+n*(this.x-t.x)+i*(this.y-t.y);return this.x=s,this.y=a,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}static convert(e){if(e instanceof o)return e;if(Array.isArray(e))return new o(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new o(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")}};var xe={closeButton:!0,closeOnClick:!0,focusAfterOpen:!0,className:"",maxWidth:"240px",subpixelPositioning:!1},ke=["a[href]","[tabindex]:not([tabindex='-1'])","[contenteditable]:not([contenteditable='false'])","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])"].join(", "),j=class extends Y{_map;options;_content;_container;_closeButton;_tip;_lngLat;_trackPointer;_pos;_flatPos;constructor(e){super(),this.options=H(Object.create(xe),e);}addTo(e){return this._map&&this.remove(),this._map=e,this.options.closeOnClick&&this._map.on("click",this._onClose),this.options.closeOnMove&&this._map.on("move",this._onClose),this._map.on("remove",this.remove),this._update(),this._focusFirstElement(),this._trackPointer?(this._map.on("mousemove",this._onMouseMove),this._map.on("mouseup",this._onMouseUp),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")):this._map.on("move",this._update),this.fire(new I("open")),this}isOpen(){return !!this._map}remove=()=>(this._content&&l.remove(this._content),this._container&&(l.remove(this._container),delete this._container),this._map&&(this._map.off("move",this._update),this._map.off("move",this._onClose),this._map.off("click",this._onClose),this._map.off("remove",this.remove),this._map.off("mousemove",this._onMouseMove),this._map.off("mouseup",this._onMouseUp),this._map.off("drag",this._onDrag),this._map._canvasContainer.classList.remove("maplibregl-track-pointer"),delete this._map,this.fire(new I("close"))),this);getLngLat(){return this._lngLat}setLngLat(e){return this._lngLat=S.convert(e),this._pos=null,this._flatPos=null,this._trackPointer=!1,this._update(),this._map&&(this._map.on("move",this._update),this._map.off("mousemove",this._onMouseMove),this._container&&this._container.classList.remove("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.remove("maplibregl-track-pointer")),this}trackPointer(){return this._trackPointer=!0,this._pos=null,this._flatPos=null,this._update(),this._map&&(this._map.off("move",this._update),this._map.on("mousemove",this._onMouseMove),this._map.on("drag",this._onDrag),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")),this}getElement(){return this._container}setText(e){return this.setDOMContent(document.createTextNode(e))}setHTML(e){let t=document.createDocumentFragment(),i=document.createElement("body"),n;for(i.innerHTML=e;n=i.firstChild,!!n;)t.appendChild(n);return this.setDOMContent(t)}getMaxWidth(){return this._container?.style.maxWidth}setMaxWidth(e){return this.options.maxWidth=e,this._update(),this}setDOMContent(e){if(this._content)for(;this._content.hasChildNodes();)this._content.firstChild&&this._content.removeChild(this._content.firstChild);else this._content=l.create("div","maplibregl-popup-content",this._container);return this._content.appendChild(e),this._createCloseButton(),this._update(),this._focusFirstElement(),this}addClassName(e){return this._container&&this._container.classList.add(e),this}removeClassName(e){return this._container&&this._container.classList.remove(e),this}setOffset(e){return this.options.offset=e,this._update(),this}toggleClassName(e){if(this._container)return this._container.classList.toggle(e)}setSubpixelPositioning(e){this.options.subpixelPositioning=e;}_createCloseButton(){this.options.closeButton&&(this._closeButton=l.create("button","maplibregl-popup-close-button",this._content),this._closeButton.type="button",this._closeButton.innerHTML="×",this._closeButton.addEventListener("click",this._onClose));}_onMouseUp=e=>{this._update(e.point);};_onMouseMove=e=>{this._update(e.point);};_onDrag=e=>{this._update(e.point);};_update=e=>{let t=this._lngLat||this._trackPointer;if(!this._map||!t||!this._content)return;if(!this._container){if(this._container=l.create("div","maplibregl-popup",this._map.getContainer()),this._tip=l.create("div","maplibregl-popup-tip",this._container),this._container.appendChild(this._content),this.options.className)for(let h of this.options.className.split(" "))this._container.classList.add(h);this._closeButton&&this._closeButton.setAttribute("aria-label",this._map._getUIString("Popup.Close")),this._trackPointer&&this._container.classList.add("maplibregl-popup-track-pointer");}if(this.options.maxWidth&&this._container.style.maxWidth!==this.options.maxWidth&&(this._container.style.maxWidth=this.options.maxWidth),this._map.transform.renderWorldCopies&&!this._trackPointer?this._lngLat=Le(this._lngLat,this._flatPos,this._map.transform):this._lngLat=this._lngLat?.wrap(),this._trackPointer&&!e)return;let i=this._flatPos=this._pos=this._trackPointer&&e?e:this._map.project(this._lngLat);this._map.terrain&&(this._flatPos=this._trackPointer&&e?e:this._map.transform.locationPoint(this._lngLat));let n=this.options.anchor,s=Pe(this.options.offset);if(!n){let h=this._container.offsetWidth,g=this._container.offsetHeight,T;i.y+s.bottom.y<g?T=["top"]:i.y>this._map.transform.height-g?T=["bottom"]:T=[],i.x<h/2?T.push("left"):i.x>this._map.transform.width-h/2&&T.push("right"),T.length===0?n="bottom":n=T.join("-");}let a=i.add(s[n]);this.options.subpixelPositioning||(a=a.round()),l.setTransform(this._container,`${me[n]} translate(${a.x}px,${a.y}px)`),ge(this._container,n,"popup");};_focusFirstElement(){if(!this.options.focusAfterOpen||!this._container)return;let e=this._container.querySelector(ke);e&&e.focus();}_onClose=()=>{this.remove();}};function Pe(o){if(o)if(typeof o=="number"){let e=Math.round(Math.abs(o)/Math.SQRT2);return {center:new u(0,0),top:new u(0,o),"top-left":new u(e,e),"top-right":new u(-e,e),bottom:new u(0,-o),"bottom-left":new u(e,-e),"bottom-right":new u(-e,-e),left:new u(o,0),right:new u(-o,0)}}else if(o instanceof u||Array.isArray(o)){let e=u.convert(o);return {center:e,top:e,"top-left":e,"top-right":e,bottom:e,"bottom-left":e,"bottom-right":e,left:e,right:e}}else return {center:u.convert(o.center||[0,0]),top:u.convert(o.top||[0,0]),"top-left":u.convert(o["top-left"]||[0,0]),"top-right":u.convert(o["top-right"]||[0,0]),bottom:u.convert(o.bottom||[0,0]),"bottom-left":u.convert(o["bottom-left"]||[0,0]),"bottom-right":u.convert(o["bottom-right"]||[0,0]),left:u.convert(o.left||[0,0]),right:u.convert(o.right||[0,0])};else return Pe(new u(0,0))}var W=class{#e;#t;#i;_undoButton;_deleteButton;_saveButton;_container;constructor(e){this.#e=e,this._container=void 0,this.#i=!1,this.#n().then(()=>{this.#o(),e.map.fire("panel:ready");});}#n=async()=>{this.#e;try{this.#t=new j({offset:16,closeButton:!1,closeOnClick:!1,closeOnMove:!1,anchor:"bottom"});}catch(t){console.error("POPUP LOAD ERROR",t);}};#o=()=>{let{store:e}=this.#e;this.createPanel(),e.tail?.val&&this.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng});};setPanelLocation=e=>{let{map:t}=this.#e;this.#i&&(this.#i=!1,this.showPanel()),this._container&&this.#t&&this.#t.setLngLat(e).setDOMContent(this._container).addTo(t);};hidePanel=()=>{!this.#i&&(this.#t?.addClassName("hide-panel"),this.#i=!0);};showPanel=()=>{this.#t?.removeClassName("hide-panel"),this.#i=!1;};onPointRemove=e=>{e?this.setPanelLocation(e):this.hidePanel();};removePanel=()=>{this._container&&l.remove(this._container),this.#t?.remove();};createButton=(e,t,i,n)=>{let s=l.create("button",`panel-button panel-button-${i}`,n);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`icon ${e} icon-${i}`,s),s};createPanel=()=>{let{options:e}=this.#e,{locale:t}=e,{undo:i,delete:n,save:s}=e.panel.buttons,a=e.panel.size,h=document.querySelector(".maplibregl-popup-content"),g=l.create("div","dashboard",h);i.visible&&(this._undoButton=this.createButton("undo",t.undo,a,g)),n.visible&&(this._deleteButton=this.createButton("delete",t.delete,a,g)),s.visible&&(this._saveButton=this.createButton("save",t.save,a,g)),this._container=g;}};var V={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[]}}]},K={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[]}}]},be={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}}]},r={LineDynamicLayer:"mdl-line-dynamic-layer",LineLayer:"mdl-line-layer",LineLayerTransparent:"mdl-line-layer-transparent",LineLayerBreak:"mdl-line-break-layer",PolygonLayer:"mdl-polygon-layer",PointsLayer:"mdl-points-layer",SinglePointLayer:"mdl-single-point-layer",FirstPointLayer:"mdl-first-point-layer"},d={LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",LineSource:"mdl-line-source",PolygonSource:"mdl-polygon-source",PointsSource:"mdl-points-source",SinglePointSource:"mdl-single-point-source"},B={large:6.5,default:5.5},$={large:"#FF6464",default:"#666666"},w={"circle-radius":B.default,"circle-color":"#FEFFFE","circle-stroke-color":$.default,"circle-stroke-width":3},D={"circle-radius":B.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},U={"fill-color":"grey","fill-opacity":.4},N={"line-width":3,"line-color":"grey","line-opacity":.7},A={"circle-radius":B.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},R={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},Z=o=>[{id:r.SinglePointLayer,source:d.SinglePointSource,type:"circle",paint:o.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:d.PolygonSource,type:"fill",paint:o.layersPaint.polygon,layout:{visibility:"none"}},{id:r.LineDynamicLayer,source:d.LineDynamicSource,type:"line",paint:o.layersPaint.line,layout:{visibility:"none"}},{id:r.LineLayer,source:d.LineSource,type:"line",paint:o.layersPaint.line,layout:{visibility:"visible"}},{id:r.LineLayerTransparent,source:d.LineSource,type:"line",paint:{"line-width":4,"line-color":"transparent"}},{id:r.LineLayerBreak,source:d.LineSourceBreak,type:"line",paint:o.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:d.PointsSource,type:"circle",paint:o.layersPaint.points,filter:["==",["get","isFirst"],!1]},{id:r.FirstPointLayer,source:d.PointsSource,type:"circle",paint:o.layersPaint.firstPoint,filter:["==",["get","isFirst"],!0]}];var E=class{static#e=0;static#t=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",B.large),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",$.large);};static#i=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",B.default),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",$.default);};static togglePointCircleRadius=(e,t)=>{t==="large"?this.#t(e):this.#i(e);};static removeTransparentLine=e=>{e.removeLayer(r.LineLayerTransparent);};static addTransparentLine=(e,t)=>{if(e.getLayer(r.LineLayerTransparent))return;let n=Z(t).find(s=>s.id===r.LineLayerTransparent);n&&e.addLayer(n);};static isDoubleClick(){let t=Date.now();return t-this.#e<=400?(this.#e=t,!0):(this.#e=t,!1)}};var f=class{static isFeatureTriggered(e,t){return e.target.queryRenderedFeatures(e.point,{layers:t}).some(n=>t.includes(n.layer.id))}static getPixelCoordinates=(e,t)=>{let{lat:i,lng:n}=t;return e.project([n,i])};static queryPointId=(e,t)=>e.queryRenderedFeatures(t,{layers:[r.PointsLayer,r.FirstPointLayer]})?.[0]?.properties.id},_=class{static#e(e){let t=[],i=e.head,n=new Set;for(;i!==null;){if(n.has(i.val?.id)){e.head&&e.head.val&&t.push([e.head.val.lng,e.head.val.lat]);break}n.add(i.val?.id),i.val&&t.push([i.val.lng,i.val.lat]),i=i.next;}return t}static getAllLines(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}]}}static getLine(e,t){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e,t]}}]}}static getPolygon(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[t]}}]}}static getPoints(e){let t=e.head,i=[],n=new Set;for(;t!==null&&!n.has(t.val?.id);){if(t.val){let s=t.val,a=t.val.id===e.head?.val?.id;i.push({type:"Feature",properties:{id:s.id,lat:s.lat,lng:s.lng,isFirst:a},geometry:{type:"Point",coordinates:[s.lng,s.lat]}});}n.add(t.val?.id),t=t.next;}return {type:"FeatureCollection",features:i}}},m=class o{static getGeometryIndex=(e,t)=>{let i=e.head,n=0;for(;i!==null;){if(i.val?.id===t)return n;n++,i=i.next;}return -1};static isFirstPoint(e){let t=e.target,i=e.point;return !!t.queryRenderedFeatures(i,{layers:[r.FirstPointLayer]}).length}static distance=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2);static checkIfPointIsOnLine=(e,t,i)=>{let s=this.distance(e,t),a=this.distance(e,i),h=this.distance(i,t);return Math.abs(a+h-s)<.1};static isClosedGeometry=e=>e.tail?.next===e.head;static breakGeometry=(e,t)=>{if(!e.head)return;let i=e.head,n=e.tail;do{if(i?.val?.id===t){i!==e.head&&(n.next=i.next,e.head=i,e.tail=n),e.tail.next=null;return}n=i,i=i.next;}while(i!==e.head)};static closeGeometry=(e,t)=>{e.tail&&(e.tail.next=e.head),t.setClosedGeometry(!0);};static canCloseGeometry=e=>e.size>2&&!this.isClosedGeometry(e);static canBreakClosedGeometry=e=>e.size<=2;static switchToLineModeIfCan=e=>{let{mode:t,store:i,tiles:n,map:s}=e;o.canBreakClosedGeometry(i)&&(i.tail&&i.tail.val&&(i.tail.next=null),t.reset(),E.togglePointCircleRadius(s,"default"),n.renderPolygon(V));}},C=()=>{if("crypto"in window&&"randomUUID"in window.crypto)return window.crypto.randomUUID();function o(){return "0123456789abcdef"[Math.floor(Math.random()*16)]}function e(n){let s="";for(let a=0;a<n;a++)s+=o();return s}function t(n){let s=n===0,a=n===4;return s?8:a?12:4}let i=[];for(let n=0;n<5;n++)i.push(e(t(n)));return i.join("-")},O=(o,e)=>{let t,i=!0;function n(){i&&t&&(o(...t),t=null,i=!1,setTimeout(()=>{i=!0,n();},e));}return function(...s){t=s,n();}};var F=class{#e;#t;#i;#n;constructor(e){this.#e=e,this.#o(),this.render();}#o(){this.#s(),this.#r(),this.#a(r.LineLayer,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.FirstPointLayer),this.#a(r.LineLayerTransparent,r.PointsLayer),this.#a(r.PolygonLayer,r.LineLayer);}#s=()=>{let{map:e}=this.#e;Object.values(d).forEach(t=>{e.getSource(t)||e.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});});};#r=()=>{let{map:e,mode:t,options:i}=this.#e;Z(i).forEach(a=>{e.getLayer(a.id)||e.addLayer(a);});let s=e.getLayoutProperty(r.PolygonLayer,"visibility")==="none";t.getMode()==="polygon"&&s&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible");};#a=(e,t)=>{let{map:i}=this.#e,n=i.getLayer(e),s=i.getLayer(t);n&&s&&i.moveLayer(e,t);};#c=()=>{let{map:e}=this.#e;Object.values(d).forEach(t=>{e.getSource(t)&&e.removeSource(t);});};#l=()=>{let{map:e}=this.#e;Object.values(r).forEach(t=>{e.getLayer(t)&&e.removeLayer(t);});};removeTiles=()=>{this.#l(),this.#c();};renderPoints=e=>{let{map:t}=this.#e,i=t.getSource(d.PointsSource);i&&i.setData(e);};renderLines=(e,t)=>{let{map:i}=this.#e,n=i.getSource(t);n&&n.setData(e);};renderPolygon=e=>{let{map:t}=this.#e,i=t.getSource(d.PolygonSource);i&&i.setData(e);};render=()=>{let{mode:e,options:t,store:i}=this.#e,n=_.getPoints(i),s=_.getAllLines(i);if(this.#t=n,this.#i=s,this.renderPoints(n),this.renderLines(s,d.LineSource),t.modes.polygon.visible&&e.isPolygon()){let h=_.getPolygon(i);this.#n=h,this.renderPolygon(h);}};#p=(e,t)=>{if(this.#n.features[0].geometry.coordinates[0][e]=[t.lng,t.lat],e===0){let n=this.#n.features[0].geometry.coordinates[0]?.length-1;this.#n.features[0].geometry.coordinates[0][n]=[t.lng,t.lat];}this.renderPolygon(this.#n);};#h=(e,t)=>{let{mode:i}=this.#e;this.#i.features[0].geometry.coordinates[e]=[t.lng,t.lat];let n=e===0;if(this.#i&&i.getClosedGeometry()&&n){let a=this.#i.features[0].geometry.coordinates?.length-1;this.#i.features[0].geometry.coordinates[a]=[t.lng,t.lat];}this.renderLines(this.#i,d.LineSource);};renderOnMouseMove=(e,t)=>{let{mode:i,options:n}=this.#e;this.#t.features[e].geometry.coordinates=[t.lng,t.lat],this.renderPoints(this.#t),this.#h(e,t),n.modes.polygon.visible&&i.isPolygon()&&this.#p(e,t);};resetGeometries=()=>{this.renderPoints(be),this.renderLines(K,d.LineSource),this.renderPolygon(V);}};var Te=8,we=8,x=class{_container;_label;constructor(){this._container=void 0;}create=e=>{let t=l.create("div","popup-container",document.body),i=l.create("span",`popup-text popup-text-${e.placement}`,t);return i.textContent=e.label,this._container=t,this._label=i,this};#e=()=>{!this._label?.classList.value.includes("popup-text-active")&&this._label?.classList.add("popup-text-active");};#t=()=>this._label?{width:this._label.clientWidth,height:this._label.clientHeight}:{width:0,height:0};#i=e=>{let{bottom:t,left:i}=e.target.getBoundingClientRect(),{width:n,height:s}=this.#t();return {x:i-we-n,y:t-s-2}};#n=e=>{let{bottom:t,left:i,right:n}=e.target.getBoundingClientRect(),{width:s}=this.#t();return {x:(n-i)/2+i-s/2,y:t+Te}};getPosition=(e,t)=>t==="left"?this.#i(e):this.#n(e);setPosition=e=>{let{x:t,y:i}=e;this._container&&(this._container.style.left=`${t}px`,this._container.style.top=`${i}px`),this.#e();};remove=()=>{this._container&&l.remove(this._container);}};var b={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var J=(o,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("add",o,t,i);},X=(o,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("remove",o,t,i);},Me=(o,e)=>{let t=e.locale.line,i=e.locale.polygon,n=e.locale.break;return {line:t,polygon:i,break:n}[o]};var Q=class{#e;constructor(e){this.#e=e,this.#t();}#t=()=>{this.#e.mode.addObserver(this.#r);};removeConsumers=()=>{this.#e.mode.removeObserver(this.#r);};#i=()=>{let{_line:e,_polygon:t,_break:i}=this.#e.control;e?.classList.remove("control-button-active"),t?.classList.remove("control-button-active"),i?.classList.remove("control-button-active");};#n=e=>{this.#i(),e.classList.add("control-button-active");};#o=e=>{let{data:t}=e,{_line:i,_polygon:n,_break:s}=this.#e.control;if(!(!i||!n||!s))switch(t){case"line":this.#n(i);break;case"polygon":this.#n(n);break;}};#s=e=>{let{data:t}=e,{_break:i}=this.#e.control;t?(i?.removeAttribute("disabled"),i?.removeAttribute("aria-disabled")):(i?.setAttribute("disabled","true"),i?.setAttribute("aria-disabled","true"));};#r=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.#o(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.#s(e),t==="BREAK_CHANGED"&&i){let{_break:n}=this.#e.control;this.#n(n);}}};var ee=class{#e;#t;#i;constructor(e){this.#e=e,this.#i=new Q(e),this.#t=new x;}initEvents(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&J(e._line,{...t,click:this.onLineClick}),e._polygon&&J(e._polygon,{...t,click:this.onPolygonClick}),e._break&&J(e._break,{...t,click:this.onBreakClick});}}#n(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&X(e._line,{...t,click:this.onLineClick}),e._polygon&&X(e._polygon,{...t,click:this.onPolygonClick}),e._break&&X(e._break,{...t,click:this.onBreakClick});}}remove(){this.#i.removeConsumers(),this.#n(),this.#t.remove();}onButtonEnter=e=>{let{options:t}=this.#e,i=e.target.getAttribute("data-type");if(i){let n=Me(i,t);this.#t.create({label:n,placement:"left"}).setPosition(this.#t.getPosition(e,"left"));}};onButtonLeave=()=>{this.#t.remove();};onLineClick=()=>{let{mode:e,tiles:t}=this.#e;e.setMode("line"),t.resetGeometries(),t.render();};onPolygonClick=()=>{let{map:e,mode:t,tiles:i}=this.#e;t.setMode("polygon"),t.isPolygon()&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible"),i.resetGeometries(),i.render();};onBreakClick=()=>{let{map:e,mode:t}=this.#e;t.setBreak(!0),e.getCanvasContainer().style.cursor=b.POINTER;}};var k=class{observers;constructor(){this.observers=new Set;}addObserver(e){this.observers.add(e);}removeObserver(e){this.observers.delete(e);}unsubscribe(){this.observers.clear();}notify(e){this.observers.forEach(t=>t(e));}};var G={EMPTY_INITIAL_STATE:"You passed an empty initial array in the options. Please either remove the 'initial' property or include at least one element in the array.",MISSING_IDS:"You set 'generateId' to false but did not provide IDs for all steps. Please ensure all steps have IDs or set 'generateId' to true.",NOT_ENOUGH_POINTS_TO_CLOSE:"At least three points are required to close a polygon or a line. Please add more points or set 'closeGeometry' to false.",FIRST_LAST_POINT_NOT_EQUAL:"The first and last points of a polygon or a closed linestring must be the same. Please ensure the first and last points are equal or set 'closeGeometry' to false."};var te=class{val;next;constructor(e=null,t=null){this.val=e,this.next=t;}},q=class extends k{head;tail;size;constructor(e){super();let t=M.initStore(e);this.head=t?t.head:null,this.tail=t?t.tail:null,this.size=t?t.size:0;}push(e){let t=new te(e);this.head?this.tail&&(this.tail.next=t,this.tail=t):this.head=this.tail=t,this.size++,this.pingConsumers();}insert(e,t){let i=new te(e,t.next);this.tail===t&&this.head===t.next&&(this.tail=i),t.next=i,this.size++;}findStepById(e){let t=this.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.val&&t.val.id===e)return t.val;i.add(t),t=t.next;}return null}removeStepById(e){if(!this.head)return null;let t=this.head,i=null;for(;t!==null;){if(t?.val?.id===e)return t===this.head?(this.head=t.next,this.tail&&(this.tail.next=t.next)):i.next=t.next,t===this.tail&&(this.tail=i),this.size--,this.pingConsumers(),t;i=t,t.next&&(t=t.next);}return null}reset(){this.head=null,this.tail=null,this.size=0,this.pingConsumers();}pingConsumers=()=>{this.notify({type:"STORE_CHANGED",data:{head:this.head,tail:this.tail,size:this.size}});}},M=class o{static isLastPoint=(e,t)=>e.tail?.val?.id===t;static initStore(e){if(!e?.initial)return null;if(e&&e.initial&&!e.initial.steps.length)throw new Error(G.EMPTY_INITIAL_STATE);if(e&&e.initial.steps){let{steps:n,closeGeometry:s,generateId:a}=e.initial;return o.fromArray(n,s,a)}return null}static#e=e=>e.map(t=>({...t,id:C()}));static buildStepSequence(e){let t=new q;return e.forEach(i=>{t.push(i);}),t}static fromArray(e,t,i){let n=i?this.#e(e):e,s=this.buildStepSequence(n);return t&&s.tail&&(s.tail.next=s.head),s}static toArray(e){if(!e)return [];let t=new Set,i=[],n=e;for(;n!==null&&!t.has(n);)t.add(n),i.push(n.val),n=n.next;return i}};var v={DOUBLECLICK:"mdl:doubleclick",POINTENTER:"mdl:pointenter",POINTLEAVE:"mdl:pointleave",MOVEEND:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REMOVEALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",LINE:"mdl:line",POLYGON:"mdl:polygon",MODECHANGE:"mdl:modechange"};var y={panel:{size:"medium",buttons:{undo:{visible:!0},delete:{visible:!0},save:{visible:!0,clearOnSave:!0}}},modes:{line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{onLinePoint:D,firstPoint:w,points:A,line:N,polygon:U,breakLine:R},initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close line",createPolygon:"Create polygon"}};var L=class{static addPoint(e,t,i){t.fire(v.ADD,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static movePoint(e,t){t.fire(v.MOVEEND,{id:e.id,start_coordinates:{lat:e.start.lat,lng:e.start.lng},end_coordinates:{lat:e.end.lat,lng:e.end.lng},total:e.total,timestamp:Date.now()});}static pointDoubleClick(e,t){t.fire(v.DOUBLECLICK,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){t.fire(v.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){t.fire(v.POINTLEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undoPoint(e,t,i){t.fire(v.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static removeAllPoints(e,t){e.fire(v.REMOVEALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:n,mode:s}=e;n.fire(v.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onModeChange(e){let{map:t,mode:i}=e;t.fire(v.MODECHANGE,{timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static onLineBreak(e){e.fire(v.BREAK);}};var ie=class{#e;#t;constructor(e){this.#e=e,this.#t=new x;}initEvents(){let{panel:e}=this.#e;e&&(l.manageEventListener("add",e?._undoButton,"click",this.#o),l.manageEventListener("add",e?._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._undoButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._deleteButton,"click",this.#n),l.manageEventListener("add",e?._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._deleteButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._saveButton,"click",this.onSaveClick),l.manageEventListener("add",e?._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._saveButton,"mouseleave",this.onMouseLeave));}removeEvents(){let{panel:e}=this.#e;e&&e._undoButton&&(l.manageEventListener("remove",e._undoButton,"click",this.#o),l.manageEventListener("remove",e._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._undoButton,"mouseleave",this.onMouseLeave)),e&&e._deleteButton&&(l.manageEventListener("remove",e._deleteButton,"click",this.#n),l.manageEventListener("remove",e._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._deleteButton,"mouseleave",this.onMouseLeave)),e&&e._saveButton&&(l.manageEventListener("remove",e._saveButton,"click",this.onSaveClick),l.manageEventListener("remove",e._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._saveButton,"mouseleave",this.onMouseLeave));}#i=e=>{let{options:t}=this.#e;return {undo:t.locale.undo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let t=e.target.getAttribute("data-type");if(t){let i=this.#i(t);this.#t.create({label:i,placement:"bottom"}).setPosition(this.#t.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.#t.remove();};#n=e=>{let{tiles:t,mode:i,panel:n,store:s,map:a}=this.#e;s.reset(),n.hidePanel(),i.reset(),E.togglePointCircleRadius(a,"default"),this.#t.remove(),t.resetGeometries(),L.removeAllPoints(a,e);};#o=e=>{let{store:t,panel:i,map:n,tiles:s}=this.#e,a=t.tail?.val;t.removeStepById(a.id);let h={...a,total:t.size};L.undoPoint(h,n,e),m.switchToLineModeIfCan(this.#e),i?.onPointRemove(t.tail?.val),this.#t.remove(),requestAnimationFrame(s.render);};onSaveClick=e=>{let{store:t,options:i}=this.#e;L.onSaveClick(this.#e,M.toArray(t.head),e),this.#t.remove(),i.panel.buttons.save.clearOnSave&&this.#n(e);}};var P=class{static updatePointsData(e){let i=e.target.getSource(d.SinglePointSource);i&&i.setData({type:"Feature",geometry:{type:"Point",coordinates:[e.lngLat.lng,e.lngLat.lat]},properties:{}});}static setSinglePointVisible(e){e.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");}static setSinglePointHidden(e){let t=e.target;setTimeout(()=>{t.setLayoutProperty(r.SinglePointLayer,"visibility","none");},33);}static triggerPostPointAddition(e,t){let{panel:i,tiles:n,store:s,map:a}=t;m.canCloseGeometry(s)&&E.togglePointCircleRadius(a,"large"),i?.setPanelLocation(e.lngLat),n.render();}static addPointToMap=(e,t)=>{let{store:i,map:n,mode:s}=t,a={...e.lngLat,id:C()};i.push(a),L.addPoint({...a,total:i.size},n,s),this.triggerPostPointAddition(e,t);};static updateSelectedStepLatLng=(e,t)=>{t.lat=e.lngLat.lat,t.lng=e.lngLat.lng;}};var fe=(o,e)=>{let t=e.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.next&&t.next.val&&t.val){let n=o.target,s=f.getPixelCoordinates(n,t.val),a=f.getPixelCoordinates(n,t.next.val),h=f.getPixelCoordinates(n,o.lngLat);if(m.checkIfPointIsOnLine(s,a,h))return t}i.add(t),t=t.next;}return null},_e=(o,e)=>{let t=fe(o,e);if(t){let i={...o.lngLat,id:C()};return e.insert(i,t),i}return null},Ce=(o,e)=>{let{store:t,tiles:i,panel:n}=e;t.tail?.val&&(n?.setPanelLocation(t.tail.val),P.setSinglePointHidden(o),i.render());},Se=o=>f.isFeatureTriggered(o,[r.PointsLayer,r.FirstPointLayer]);var Oe=15,ne=class{props;#e;#t;constructor(e){this.props=e,this.#e=null,this.#t=O(this.#n,Oe);}initBreakEvents=()=>{let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mouseenter",r.LineLayerTransparent,this.#t),e.on("mousemove",r.LineLayerTransparent,this.#t),e.on("mouseleave",r.LineLayerTransparent,this.#o);};removeBreakEvents=()=>{let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mouseenter",r.LineLayerTransparent,this.#t),e.off("mousemove",r.LineLayerTransparent,this.#t),e.off("mouseleave",r.LineLayerTransparent,this.#o);};hideBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};#i=()=>{let{store:e,mode:t,panel:i,map:n,tiles:s}=this.props,a=this.#e?.next?.val?.id;m.breakGeometry(e,a),e.tail?.val&&i.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng}),this.#o(),n.setLayoutProperty(r.PolygonLayer,"visibility","none"),t.reset(),s.render(),L.onLineBreak(n);};#n=e=>{let{map:t,store:i}=this.props,n=fe(e,i);n?.val?.id!==this.#e?.val?.id&&(this.#e=n);let s=t.getSource(d.LineSourceBreak),a=[n?.val?.lng,n?.val?.lat],h=[n?.next?.val?.lng,n?.next?.val?.lat],g=_.getLine(a,h);g&&(s.setData(g),this.showBreakLine());};#o=()=>{setTimeout(()=>{this.hideBreakLine();},Oe+10);}};var De=10,oe=class{#e;#t;#i;#n;#o;#s;constructor(e){this.#e=e,this.#t=e.options.dynamicLine,this.#i=null,this.#n=null,this.#r(),this.#s=O(this.#h,De);}#r(){this.#e.store.addObserver(this.#c),this.#e.mode.addObserver(this.#l),this.#e.mouseEvents.addObserver(this.#a);}removeConsumers=()=>{this.#e.store.removeObserver(this.#c),this.#e.mode.removeObserver(this.#l),this.#e.mouseEvents.removeObserver(this.#a);};#a=e=>{let{mode:t}=this.#e;if(!t.getClosedGeometry()&&(e.type==="lastPointMouseClick"&&e.data?(this.hideDynamicLine(),this.#t=!1):e.type==="lastPointMouseClick"&&!e.data&&(this.#t=!0),!!this.#t&&((e.type==="pointMouseEnter"||e.type==="lineMouseEnter")&&e.data&&this.hideDynamicLine(),(e.type==="pointMouseLeave"||e.type==="lineMouseLeave")&&e.data))){let{store:i}=this.#e;this.#i=i.tail?.val,this.#n=i.tail?.val,this.showDynamicLine();}};#c=e=>{let{store:t}=this.#e;switch(e.type){case"STORE_CHANGED":e.data.tail?.val&&!m.isClosedGeometry(t)&&(this.#i=e.data.tail?.val,this.showDynamicLine());break;}};#l=e=>{let{store:t}=this.#e;e.type==="CLOSED_GEOMETRY_CHANGED"&&(e.data&&this.hideDynamicLine(),!e.data&&t?.tail?.val&&(this.#i=t?.tail?.val,this.showDynamicLine()));};initDynamicEvents=()=>{let{map:e}=this.#e;e.on("click",this.#f),e.on("mousemove",this.#s),e.on(v.REMOVEALL,this.hideDynamicLine),e.on(v.UNDO,this.#m),e.on(v.DOUBLECLICK,this.#v);};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#f),e.off("mousemove",this.#s),e.off(v.REMOVEALL,this.hideDynamicLine),e.off(v.UNDO,this.#m),e.off(v.DOUBLECLICK,this.#v);};hideDynamicLine=()=>{let{map:e,tiles:t}=this.#e;this.#i=null,this.#n=null,this.#o=null,e.off("mousemove",this.#s),t.renderLines(K,d.LineDynamicSource),e.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};showDynamicLine=()=>{let{map:e}=this.#e,t=[this.#i?.lng,this.#i?.lat],i=[this.#n?.lng,this.#n?.lat];this.#o=_.getLine(t,i),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.#n&&this.#p({lng:this.#n?.lng,lat:this.#n?.lat}),e.on("mousemove",this.#s);};#p=e=>{if(!this.#o)return;let{tiles:t}=this.#e;this.#o.features[0].geometry.coordinates[1]=[e.lng,e.lat],t.renderLines(this.#o,d.LineDynamicSource);};#h=e=>{this.#p(e.lngLat);};#f=e=>{let{mode:t}=this.#e,i=f.isFeatureTriggered(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.#n={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hideDynamicLine();};#m=e=>{let{store:t,mode:i}=this.#e;if(!i.getClosedGeometry()){let n=e.target.unproject({x:e.originalEvent.x,y:e.originalEvent.y});this.#n={lng:n.lng,lat:n.lat},this.#i=t.tail?.val,this.showDynamicLine();}};#v=e=>{let{store:t,mode:i}=this.#e;i.getClosedGeometry()||(this.#n={lng:e.coordinates.lng,lat:e.coordinates.lat},this.#i=t.tail?.val,this.showDynamicLine());}};var Ae=22,se=class{props;#e;#t;constructor(e){this.props=e,this.#e=!1,this.#t=null;}initEvents(){let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mousemove",r.LineLayerTransparent,this.#o),e.on("mouseenter",r.LineLayerTransparent,this.#s),e.on("mouseleave",r.LineLayerTransparent,this.#r);}removeEvents(){let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mousemove",r.LineLayerTransparent,this.#o),e.off("mouseenter",r.LineLayerTransparent,this.#s),e.off("mouseleave",r.LineLayerTransparent,this.#r);}#i=e=>{let{store:t,map:i,mode:n}=this.props;if(Se(e))return;let s=_e(e,t);s&&(L.addPoint({...s,total:t.size},i,n),Ce(e,this.props));};#n=e=>{P.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)&&P.updatePointsData(e);};#o=O(e=>{if(f.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer]))return;let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(this.#t=e,!this.#e&&(this.#e=!0,requestAnimationFrame(()=>{this.#t&&(this.#n(this.#t),this.#e=!1);})));},Ae);#s=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||f.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer])||(t.lineMouseEnter=!0,P.setSinglePointVisible(e));};#r=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(t.lineMouseLeave=!0,P.setSinglePointHidden(e));}};var re=class{props;#e;#t;#i;#n;constructor(e){this.props=e,this.#e=new ne(e),this.#t=new se(e),this.#i=null,this.#n="default",this.#o(),this.#s(),this.#r();}#o=()=>{window.innerWidth<=768||this.props.options.dynamicLine&&(this.#i=new oe(this.props));};#s(){!this.props.mode.getBreak()&&(this.#t.initEvents(),this.props.options.dynamicLine&&this.#i?.initDynamicEvents());}#r(){this.props.mode.addObserver(this.#p),this.props.mouseEvents.addObserver(this.#l);}remove(){this.#a(),this.#c();}#a(){this.props.mode.removeObserver(this.#p),this.props.mouseEvents.removeObserver(this.#l),this.props.options.dynamicLine&&this.#i?.removeConsumers();}#c(){this.#e.removeBreakEvents(),this.#t.removeEvents(),this.props.options.dynamicLine&&this.#i?.removeEvents();}#l=e=>{let{type:t,data:i}=e,{mode:n}=this.props;if(!(!i||!n.getBreak()))switch(t){case"pointMouseDown":this.#e.removeBreakEvents(),this.#e.hideBreakLine();break;case"pointMouseUp":this.#e.initBreakEvents();break;}};#p=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.#n==="break"&&(this.#e.removeBreakEvents(),this.#t.initEvents(),this.#n="default"),t==="BREAK_CHANGED"&&i&&this.#n==="default"&&(this.#t.removeEvents(),this.#e.initBreakEvents(),this.#n="break");}};var ae=class{#e;#t;#i;constructor(e){this.#t=e,this.#e=!1,this.#i=new x,e.mode.addObserver(this.#n);}initEvents(){let{map:e}=this.#t;e.on("click",r.FirstPointLayer,this.#o),e.on("mouseenter",r.FirstPointLayer,this.#l),e.on("mouseleave",r.FirstPointLayer,this.#a),e.on("mouseup",r.FirstPointLayer,this.#r),e.on("mousedown",r.FirstPointLayer,this.#s);}removeEvents(){let{map:e}=this.#t;e.off("click",r.FirstPointLayer,this.#o),e.off("mouseenter",r.FirstPointLayer,this.#l),e.off("mouseleave",r.FirstPointLayer,this.#a),e.off("mouseup",r.FirstPointLayer,this.#r);}#n=e=>{let{map:t,store:i}=this.#t,{type:n,data:s}=e;n==="MODE_CHANGED"&&(s==="line"||s==="polygon"?t.on("click",r.FirstPointLayer,this.#o):t.off("click",r.FirstPointLayer,this.#o),m.canCloseGeometry(i)&&E.togglePointCircleRadius(t,"large"));};#o=()=>{let{store:e,map:t,mode:i,tiles:n}=this.#t;if(i.getMode()==="polygon"&&t.setLayoutProperty(r.PolygonLayer,"visibility","visible"),m.canCloseGeometry(e)){m.closeGeometry(e,i);let s=Object.assign({},e.head?.val,{id:C(),total:e.size});L.addPoint(s,t,i),E.togglePointCircleRadius(t,"default"),n.render();}};#s=()=>{this.#e=!0,this.#i.remove();};#r=()=>{this.#e=!1;};#a=()=>{let{mouseEvents:e}=this.#t;this.#e||(e.firstPointMouseLeave=!0,this.#i.remove());};#c=()=>{let{mode:e,options:t}=this.#t;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};#l=e=>{let{mode:t,mouseEvents:i,store:n}=this.#t;if(!(t.getClosedGeometry()||this.#e)&&(i.firstPointMouseEnter=!0,m.canCloseGeometry(n))){let{x:s,y:a}=e.originalEvent;if(s&&a){this.#i.create({label:this.#c(),placement:"bottom"});let g=this.#i._label?this.#i._label.clientWidth/2:0;this.#i.setPosition({x:s-g,y:a+14});}}}};var le=class{#e;#t;#i;#n;#o;#s;#r;#a;constructor(e){this.#e=e,this.#t=void 0,this.#i=null,this.#n=null,this.#o=null,this.#s=new ae(e),this.#r=!1,this.#a=null;}#c=()=>{let{map:e}=this.#e;e.on("click",r.FirstPointLayer,this.#h),e.on("mouseenter",r.FirstPointLayer,this.#L),e.on("mouseleave",r.FirstPointLayer,this.#g),e.on("mousedown",r.FirstPointLayer,this.#d),e.on("mouseup",r.FirstPointLayer,this.#u),e.on("touchend",r.FirstPointLayer,this.#u),e.on("touchstart",r.FirstPointLayer,this.#d),this.#s.initEvents();};initEvents=()=>{let{map:e}=this.#e;e.on("click",this.#m),e.on("dblclick",this.#p),e.on("click",r.PointsLayer,this.#h),e.on("mouseenter",r.PointsLayer,this.#L),e.on("mouseleave",r.PointsLayer,this.#g),e.on("mousedown",r.PointsLayer,this.#d),e.on("mouseup",r.PointsLayer,this.#u),e.on("touchend",r.PointsLayer,this.#u),e.on("touchstart",r.PointsLayer,this.#d),this.#c();};#l=()=>{let{map:e}=this.#e;e.off("click",r.FirstPointLayer,this.#h),e.off("mouseenter",r.FirstPointLayer,this.#L),e.off("mouseleave",r.FirstPointLayer,this.#g),e.off("mousedown",r.FirstPointLayer,this.#d),e.off("mouseup",r.FirstPointLayer,this.#u),e.off("touchend",r.PointsLayer,this.#u),e.off("touchstart",r.PointsLayer,this.#d),this.#s.removeEvents();};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#m),e.off("dblclick",this.#p),e.off("mousemove",this.#y),e.off("click",r.PointsLayer,this.#h),e.off("mouseenter",r.PointsLayer,this.#L),e.off("mouseleave",r.PointsLayer,this.#g),e.off("mousedown",r.PointsLayer,this.#d),e.off("mouseup",r.PointsLayer,this.#u),this.#l();};#p=e=>{e.preventDefault();};#h=e=>{let{store:t,tiles:i,panel:n,map:s,mouseEvents:a}=this.#e;E.isDoubleClick()&&this.#n&&(t.removeStepById(this.#n.id),n.onPointRemove(t.tail?.val),L.pointDoubleClick({...this.#n,total:t.size},this.#e.map),m.switchToLineModeIfCan(this.#e));let h=f.queryPointId(s,e.point);M.isLastPoint(t,h)&&(a.lastPointMouseClick=!0,a.lastPointMouseUp=!1),i.render();};#f=e=>f.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer,r.LineLayerTransparent,r.LineLayerBreak]);#m=e=>{let{mode:t,mouseEvents:i,map:n}=this.#e;t.getClosedGeometry()||this.#f(e)||(i.lastPointMouseClick&&(i.lastPointMouseClick=!1),n.getCanvasContainer().style.cursor="grab",P.addPointToMap(e,this.#e),P.setSinglePointHidden(e));};#v=e=>{e.originalEvent.buttons===0&&this.#u();};#E=e=>{let{tiles:t}=this.#e;t.renderOnMouseMove(this.#o,e.lngLat);};#y=O(e=>{this.#a=e,this.#r||(this.#r=!0,requestAnimationFrame(()=>{!this.#n||!this.#a||(P.updateSelectedStepLatLng(this.#a,this.#n),this.#v(this.#a),this.#E(this.#a),this.#r=!1);}));},15);#L=e=>{let{mouseEvents:t,map:i,store:n}=this.#e;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;P.setSinglePointHidden(e);let s=f.queryPointId(i,e.point);M.isLastPoint(n,s)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let a=n.findStepById(s);a&&(this.#i=a,L.enterPoint(Object.assign({},a,{total:n.size}),i));};#g=e=>{let{mouseEvents:t,store:i,map:n}=this.#e;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let s=f.queryPointId(n,e.point);M.isLastPoint(i,s)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),L.leavePoint(Object.assign({},this.#i,{total:i.size}),n);};#P=()=>{let{store:e,panel:t}=this.#e;this.#n&&M.isLastPoint(e,this.#n.id)&&t.hidePanel();};#b=e=>{let{store:t,map:i}=this.#e,n=f.queryPointId(i,e.point),s=t.findStepById(n);s&&(this.#n=s);};#d=e=>{e.preventDefault();let{mouseEvents:t,map:i,store:n}=this.#e;E.removeTransparentLine(i),this.#b(e),this.#P();let s=f.queryPointId(i,e.point);this.#o=m.getGeometryIndex(n,s),t&&(t.pointMouseDown=!0),this.#t=e.lngLat,i.on("mousemove",this.#y),i.on("touchmove",this.#y);};#u=()=>{let{mouseEvents:e,store:t,panel:i,map:n,options:s}=this.#e;e.pointMouseUp=!0,this.#n&&(M.isLastPoint(t,this.#n.id)&&t.tail?.val&&i?.setPanelLocation(t.tail.val),i?.showPanel(),L.movePoint({id:this.#n.id,total:t.size,end:{lat:this.#n.lat,lng:this.#n.lng},start:this.#t},n)),e&&(e.pointMouseDown=!1),E.addTransparentLine(n,s),n.off("mousemove",this.#y),n.off("touchmove",this.#y);}};var ce=class extends F{#e;#t;#i;#n;#o;constructor(e){super({...e}),this.#e=e,this.#t=new ie(e),this.#i=new ee(e),this.#n=new le(e),this.#o=new re(e),e.map.on("panel:ready",this.#s);}#s=()=>{this.#t?.initEvents(),this.#i?.initEvents(),this.#n?.initEvents();};removeMapEventsAndConsumers=()=>{this.#t?.removeEvents(),this.#n?.removeEvents(),this.#i?.remove(),this.#o?.remove(),this.#e.map.off("panel:ready",this.#s);}};var pe=class{#e;_line;_polygon;_break;_container;constructor(e){this.#e=e.options,this._line=void 0,this._polygon=void 0,this._break=void 0,this._container=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl(e);}createControlButton=(e,t,i,n)=>{let s=this.#e.panel.size,a=l.create("button",`control-button control-button-${s}`,this._container);return a.setAttribute("aria-label",t),a.setAttribute("data-type",e),i&&a.classList.add("control-button-active"),n&&(a.setAttribute("disabled","true"),a.setAttribute("aria-disabled","true")),l.create("span",`icon ${e} icon-${s}`,a),a};#t=e=>{let{mode:t,options:i}=e,n=this.#e.modes.line.visible,s=i.locale.line;if(n){let a=t.getMode()==="line";this._line=this.createControlButton("line",s,a);}};#i=e=>{let{mode:t,options:i}=e,n=this.#e.modes.polygon.visible,s=i.locale.polygon;n&&(this._polygon=this.createControlButton("polygon",s,t.isPolygon()));};#n=e=>{let{mode:t,options:i}=e,n=this.#e.modes.breakGeometry.visible,s=i.locale.break;if(n){let h=!this.#e?.initial?.closeGeometry,g=t.getBreak();this._break=this.createControlButton("break",s,g,h);}};createControl=e=>{this.#t(e),this.#i(e),this.#n(e);};getContainer=()=>this._container};var he=class extends k{#e;#t;#i;constructor(e){super(),this.#e=e.initial?.geometry??"line",this.#t=!1,this.#i=e.initial?.closeGeometry??!1;}getMode=()=>this.#e;setMode=e=>{this.#e=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.#t;setBreak=e=>{this.#t=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.#i;setClosedGeometry=e=>{this.#i=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.#i});};isPolygon=()=>this.#e.includes("polygon")&&this.#i;reset=()=>{this.setMode(this.getMode()),this.setClosedGeometry(!1);};pingConsumers=()=>{this.notify({type:"MODE_CHANGED",data:this.getMode()}),this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.getClosedGeometry()});}};var ue=class{#e;#t;constructor(e){this.#e=e,this.#t=this.#e.map.getCanvasContainer(),this.#t.style.cursor=b.CROSSHAIR,this.#i();}set=e=>{this.#t.style.cursor=e;};get=()=>this.#t.style.cursor;handleMouseLeave=()=>{let{mouseEvents:e,mode:t}=this.#e;e.pointMouseDown||(t.getClosedGeometry()?this.set(b.AUTO):this.set(b.CROSSHAIR));};handleFirstPointMouseEnter=()=>{let{mode:e,store:t}=this.#e;e.getClosedGeometry()&&this.set(b.MOVE),m.canCloseGeometry(t)&&this.set(b.POINTER);};#i(){let{mouseEvents:e}=this.#e;e.addObserver(this.#n);}removeConsumers(){let{mouseEvents:e}=this.#e;e.removeObserver(this.#n);}#n=e=>{let{mode:t,mouseEvents:i}=this.#e;if(t.getBreak())return;let{type:n,data:s}=e;if(s)switch(n){case"pointMouseDown":this.set(b.GRABBING);break;case"pointMouseUp":this.set(b.GRAB);break;case"pointMouseEnter":if(i.pointMouseDown)return;this.set(b.GRAB);break;case"pointMouseLeave":this.handleMouseLeave();break;case"lineMouseEnter":if(i.pointMouseDown)return;this.set(b.POINTER);break;case"lineMouseLeave":this.handleMouseLeave();break;case"firstPointMouseEnter":this.handleFirstPointMouseEnter();break;case"firstPointMouseLeave":this.handleMouseLeave();break;case"lastPointMouseEnter":this.set(b.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var de=class extends k{#e;#t;#i;#n;#o;#s;#r;#a;#c;#l;#p;#h;constructor(){super(),this.#e=!1,this.#t=!1,this.#i=!1,this.#n=!1,this.#o=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#c=!1,this.#l=!1,this.#p=!1,this.#h=!1;}get firstPointMouseEnter(){return this.#e}set firstPointMouseEnter(e){this.#e=e,this.notify({type:"firstPointMouseEnter",data:e});}get firstPointMouseLeave(){return this.#t}set firstPointMouseLeave(e){this.#t=e,this.notify({type:"firstPointMouseLeave",data:e});}get lastPointMouseClick(){return this.#i}set lastPointMouseClick(e){this.#i=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#n}set lastPointMouseUp(e){this.#n=e,this.notify({type:"lastPointMouseUp",data:e});}get lastPointMouseEnter(){return this.#o}set lastPointMouseEnter(e){this.#o=e,this.notify({type:"lastPointMouseEnter",data:e});}get lastPointMouseLeave(){return this.#s}set lastPointMouseLeave(e){this.#s=e,this.notify({type:"lastPointMouseLeave",data:e});}get pointMouseDown(){return this.#r}set pointMouseDown(e){this.#r=e,this.notify({type:"pointMouseDown",data:e});}get pointMouseUp(){return this.#a}set pointMouseUp(e){this.#a=e,this.notify({type:"pointMouseUp",data:e});}get pointMouseEnter(){return this.#c}set pointMouseEnter(e){this.#c=e,this.notify({type:"pointMouseEnter",data:e});}get pointMouseLeave(){return this.#l}set pointMouseLeave(e){this.#l=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#p}set lineMouseEnter(e){this.#p=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#h}set lineMouseLeave(e){this.#h=e,this.notify({type:"lineMouseLeave",data:e});}};var z=class{static allStepsHaveIds(e){return e.every(t=>"id"in t&&t.id!==void 0)}static checkIfMissingIds(e,t){let i=!t,n=!this.allStepsHaveIds(e);if(i&&n)throw new Error(G.MISSING_IDS)}static checkIfEnoughPointsToClose(e,t){if(t&&e.length<3)throw new Error(G.NOT_ENOUGH_POINTS_TO_CLOSE)}static checkIfPolygonIsClosed(e){let{closeGeometry:t,steps:i}=e;if(i){let n=i[0]?.lng,s=i[i.length-1]?.lng,a=i[0]?.lat,h=i[i.length-1]?.lat;if((n!==s||a!==h)&&t)throw new Error(G.FIRST_LAST_POINT_NOT_EQUAL)}}static checkInitialStepsOption(e){let{closeGeometry:t,generateId:i,steps:n}=e;this.checkIfMissingIds(n,i),this.checkIfEnoughPointsToClose(n,t),this.checkIfPolygonIsClosed(e);}static init(e){return e?{panel:Ie(e),modes:Be(e),layersPaint:Ne(e),initial:e.initial||y.initial,locale:Re(e),dynamicLine:e.dynamicLine??y.dynamicLine}:y}};function Ie(o){return {size:o.panel?.size||y.panel.size,buttons:{undo:{visible:o.panel?.buttons?.undo?.visible??y.panel.buttons.undo.visible},delete:{visible:o.panel?.buttons?.delete?.visible??y.panel.buttons.delete.visible},save:{visible:o.panel?.buttons?.save?.visible??y.panel.buttons.save.visible,clearOnSave:o.panel?.buttons?.save?.clearOnSave??y.panel.buttons.save.clearOnSave}}}}function Be(o){return {line:{visible:o?.modes?.line?.visible||o?.initial?.geometry==="line"||y.modes.line.visible,closeGeometry:o?.modes?.line?.closeGeometry||o?.initial?.closeGeometry||y.modes.line.closeGeometry},polygon:{visible:o?.modes?.polygon?.visible||o?.initial?.geometry==="polygon"||y.modes.polygon.visible},breakGeometry:{visible:o?.modes?.breakGeometry?.visible??y.modes.breakGeometry.visible}}}function Ne(o){return {onLinePoint:{"circle-radius":o.layersPaint?.onLinePoint?.["circle-radius"]||D["circle-radius"],"circle-color":o.layersPaint?.onLinePoint?.["circle-color"]||D["circle-color"],"circle-stroke-color":o.layersPaint?.onLinePoint?.["circle-stroke-color"]||D["circle-stroke-color"],"circle-stroke-width":o.layersPaint?.onLinePoint?.["circle-stroke-width"]||D["circle-stroke-width"],...o.layersPaint?.onLinePoint},firstPoint:{"circle-radius":o.layersPaint?.firstPoint?.["circle-radius"]||w["circle-radius"],"circle-color":o.layersPaint?.firstPoint?.["circle-color"]||w["circle-color"],"circle-stroke-color":o.layersPaint?.firstPoint?.["circle-stroke-color"]||w["circle-stroke-color"],"circle-stroke-width":o.layersPaint?.firstPoint?.["circle-stroke-width"]||w["circle-stroke-width"],...o.layersPaint?.firstPoint},points:{"circle-radius":o.layersPaint?.points?.["circle-radius"]||A["circle-radius"],"circle-color":o.layersPaint?.points?.["circle-color"]||A["circle-color"],"circle-stroke-color":o.layersPaint?.points?.["circle-stroke-color"]||A["circle-stroke-color"],"circle-stroke-width":o.layersPaint?.points?.["circle-stroke-width"]||A["circle-stroke-width"],...o.layersPaint?.points},line:{"line-width":o.layersPaint?.line?.["line-width"]||N["line-width"],"line-color":o.layersPaint?.line?.["line-color"]||N["line-color"],"line-opacity":o.layersPaint?.line?.["line-opacity"]||N["line-opacity"],...o.layersPaint?.line},polygon:{"fill-color":o.layersPaint?.polygon?.["fill-color"]||U["fill-color"],"fill-opacity":o.layersPaint?.polygon?.["fill-opacity"]||U["fill-opacity"],...o.layersPaint?.polygon},breakLine:{"line-width":o.layersPaint?.breakLine?.["line-width"]||R["line-width"],"line-color":o.layersPaint?.breakLine?.["line-color"]||R["line-color"],"line-dasharray":o.layersPaint?.breakLine?.["line-dasharray"]||R["line-dasharray"],...o.layersPaint?.breakLine}}}function Re(o){return {save:o.locale?.save??y.locale.save,delete:o.locale?.delete??y.locale.delete,undo:o.locale?.undo??y.locale.undo,line:o.locale?.line??y.locale.line,polygon:o.locale?.polygon??y.locale.polygon,break:o.locale?.break??y.locale.break,closeLine:o.locale?.closeLine??y.locale.closeLine,createPolygon:o.locale?.createPolygon??y.locale.createPolygon}}var ve=class o{#e;#t;#i;#n;#o;#s;#r;#a;#c;static#l=null;static#p=!1;constructor(e){if(this.#n=z.init(e),this.#n.initial&&z.checkInitialStepsOption(this.#n.initial),o.#p)throw new Error("Use 'DrawLibre.getInstance()' instead of 'new DrawLibre()'.");o.#p=!0,this.#t=void 0,this.#i=void 0,this.#o=void 0,this.#s=void 0,this.#r=void 0,this.#c=void 0,this.#a=void 0;}static getInstance(e){return o.#l||(o.#l=new o(e)),o.#l}onAdd(e){this.#t=new q(this.#n),this.#r=new W({map:e,options:this.#n,store:this.#t}),this.#i=new he(this.#n),this.#s=new F({map:e,store:this.#t,options:this.#n,mode:this.#i});let t=new pe({options:this.#n,mode:this.#i});return this.#c=new de,this.#a=new ue({map:e,mode:this.#i,mouseEvents:this.#c,store:this.#t}),this.#o=new ce({map:e,store:this.#t,options:this.#n,panel:this.#r,control:t,mode:this.#i,tiles:this.#s,mouseEvents:this.#c}),this.#i.pingConsumers(),this.#e=t.getContainer(),this.#e}onRemove(){this.#a?.removeConsumers(),this.#s?.removeTiles(),this.#o?.removeMapEventsAndConsumers(),this.#r?.removePanel(),this.#t?.reset(),this.#i?.unsubscribe(),this.#e&&l.remove(this.#e);}setSteps=e=>{if(Array.isArray(e))e.forEach(t=>{let i={...t,id:t.id||C()};this.#t?.push(i);});else throw new Error("Invalid argument. Expected an array of steps.");this.#s?.render();};findStepById=e=>this.#t?.findStepById(e);getAllSteps=(e="array")=>{if(e==="array"&&this.#t)return M.toArray(this.#t.head);if(e==="linkedlist")return this.#t;throw new Error("Invalid type specified. Use 'array' or 'linkedlist'.")};setOptions=e=>{this.#n=e(this.#n);};removeAllSteps=()=>{this.#t?.reset(),this.#r?.removePanel(),this.#s?.render();}};
|
|
1
|
+
var l=class n{static docStyle=typeof window<"u"&&window.document&&window.document.documentElement.style;static transformProp=n.testProp(["transform","WebkitTransform"]);static testProp(e){if(!n.docStyle)return e[0];for(let t=0;t<e.length;t++)if(e[t]in n.docStyle)return e[t];return e[0]}static create(e,t,i){let o=window.document.createElement(e);return t!==void 0&&(o.className=t),i&&i.appendChild(o),o}static remove(e){e.parentNode&&e.parentNode.removeChild(e);}static setTransform(e,t){n.transformProp&&e.style&&(e.style[n.transformProp]=t);}static manageEventListener(e,t,i,o,s={}){if(!t)return;let a=e==="add"?"addEventListener":"removeEventListener";"passive"in s?t[a](i,o,s):t[a](i,o,s.capture);}static mouseButton(e){return e.button}static addClassName(e,t){e.classList.contains(t)||e.classList.add(t);}static removeClassName(e,t){e.classList.contains(t)&&e.classList.remove(t);}};var S=class n{lng;lat;constructor(e,t){if(isNaN(e)||isNaN(t))throw new Error(`Invalid LngLat object: (${e}, ${t})`);if(this.lng=+e,this.lat=+t,this.lat>90||this.lat<-90)throw new Error("Invalid LngLat latitude value: must be between -90 and 90")}static convert(e){if(e instanceof n)return e;if(Array.isArray(e)&&(e.length===2||e.length===3))return new n(Number(e[0]),Number(e[1]));if(!Array.isArray(e)&&typeof e=="object"&&e!==null)return new n(Number("lng"in e?e.lng:e.lon),Number(e.lat));throw new Error("`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]")}};function H(n,...e){for(let t of e)for(let i in t)n[i]=t[i];return n}function Le(n,e,t){let i=new S(n.lng,n.lat);if(n=new S(n.lng,n.lat),e){let o=new S(n.lng-360,n.lat),s=new S(n.lng+360,n.lat),a=t.locationPoint(n).distSqr(e);t.locationPoint(o).distSqr(e)<a?n=o:t.locationPoint(s).distSqr(e)<a&&(n=s);}for(;Math.abs(n.lng-t.center.lng)>180;){let o=t.locationPoint(n);if(o.x>=0&&o.y>=0&&o.x<=t.width&&o.y<=t.height)break;n.lng>t.center.lng?n.lng-=360:n.lng+=360;}return n.lng!==i.lng&&t.locationPoint(n).y>t.height/2-t.getHorizon()?n:i}var me={center:"translate(-50%,-50%)",top:"translate(-50%,0)","top-left":"translate(0,0)","top-right":"translate(-100%,0)",bottom:"translate(-50%,-100%)","bottom-left":"translate(0,-100%)","bottom-right":"translate(-100%,-100%)",left:"translate(0,-50%)",right:"translate(-100%,-50%)"};function ge(n,e,t){let i=n.classList;for(let o in me)i.remove(`maplibregl-${t}-anchor-${o}`);i.add(`maplibregl-${t}-anchor-${e}`);}function Ee(n,e,t){t[n]&&t[n].indexOf(e)!==-1||(t[n]=t[n]||[],t[n].push(e));}function ye(n,e,t){if(t&&t[n]){let i=t[n].indexOf(e);i!==-1&&t[n].splice(i,1);}}var Y=class{_listeners;_oneTimeListeners;_eventedParent;_eventedParentData;on(e,t){return this._listeners=this._listeners||{},Ee(e,t,this._listeners),this}off(e,t){return ye(e,t,this._listeners),ye(e,t,this._oneTimeListeners),this}once(e,t){return t?(this._oneTimeListeners=this._oneTimeListeners||{},Ee(e,t,this._oneTimeListeners),this):new Promise(i=>this.once(e,i))}fire(e,t){typeof e=="string"&&(e=new I(e,t||{}));let i=e.type;if(this.listens(i)){e.target=this;let o=this._listeners&&this._listeners[i]?this._listeners[i].slice():[];for(let p of o)p.call(this,e);let s=this._oneTimeListeners&&this._oneTimeListeners[i]?this._oneTimeListeners[i].slice():[];for(let p of s)ye(i,p,this._oneTimeListeners),p.call(this,e);let a=this._eventedParent;a&&(H(e,typeof this._eventedParentData=="function"?this._eventedParentData():this._eventedParentData),a.fire(e));}else e instanceof ErrorEvent&&console.error(e.error);return this}listens(e){return this._listeners&&this._listeners[e]&&this._listeners[e].length>0||this._oneTimeListeners&&this._oneTimeListeners[e]&&this._oneTimeListeners[e].length>0||this._eventedParent&&this._eventedParent.listens(e)}setEventedParent(e,t){return this._eventedParent=e,this._eventedParentData=t,this}},I=class{type;constructor(e,t={}){H(this,t),this.type=e;}};var u=class n{x;y;constructor(e,t){this.x=e,this.y=t;}mag(){return Math.sqrt(this.x*this.x+this.y*this.y)}equals(e){return this.x===e.x&&this.y===e.y}dist(e){return Math.sqrt(this.distSqr(e))}distSqr(e){let t=e.x-this.x,i=e.y-this.y;return t*t+i*i}angle(){return Math.atan2(this.y,this.x)}angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)}angleWith(e){return this.angleWithSep(e.x,e.y)}angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)}_matMult(e){let t=e[0]*this.x+e[1]*this.y,i=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=i,this}_add(e){return this.x+=e.x,this.y+=e.y,this}_sub(e){return this.x-=e.x,this.y-=e.y,this}_mult(e){return this.x*=e,this.y*=e,this}_div(e){return this.x/=e,this.y/=e,this}_multByPoint(e){return this.x*=e.x,this.y*=e.y,this}_divByPoint(e){return this.x/=e.x,this.y/=e.y,this}_unit(){return this._div(this.mag()),this}_perp(){let e=this.y;return this.y=this.x,this.x=-e,this}_rotate(e){let t=Math.cos(e),i=Math.sin(e),o=t*this.x-i*this.y,s=i*this.x+t*this.y;return this.x=o,this.y=s,this}_rotateAround(e,t){let i=Math.cos(e),o=Math.sin(e),s=t.x+i*(this.x-t.x)-o*(this.y-t.y),a=t.y+o*(this.x-t.x)+i*(this.y-t.y);return this.x=s,this.y=a,this}_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}static convert(e){if(e instanceof n)return e;if(Array.isArray(e))return new n(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new n(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")}};var xe={closeButton:!0,closeOnClick:!0,focusAfterOpen:!0,className:"",maxWidth:"240px",subpixelPositioning:!1},ke=["a[href]","[tabindex]:not([tabindex='-1'])","[contenteditable]:not([contenteditable='false'])","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])"].join(", "),j=class extends Y{_map;options;_content;_container;_closeButton;_tip;_lngLat;_trackPointer;_pos;_flatPos;constructor(e){super(),this.options=H(Object.create(xe),e);}addTo(e){return this._map&&this.remove(),this._map=e,this.options.closeOnClick&&this._map.on("click",this._onClose),this.options.closeOnMove&&this._map.on("move",this._onClose),this._map.on("remove",this.remove),this._update(),this._focusFirstElement(),this._trackPointer?(this._map.on("mousemove",this._onMouseMove),this._map.on("mouseup",this._onMouseUp),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")):this._map.on("move",this._update),this.fire(new I("open")),this}isOpen(){return !!this._map}remove=()=>(this._content&&l.remove(this._content),this._container&&(l.remove(this._container),delete this._container),this._map&&(this._map.off("move",this._update),this._map.off("move",this._onClose),this._map.off("click",this._onClose),this._map.off("remove",this.remove),this._map.off("mousemove",this._onMouseMove),this._map.off("mouseup",this._onMouseUp),this._map.off("drag",this._onDrag),this._map._canvasContainer.classList.remove("maplibregl-track-pointer"),delete this._map,this.fire(new I("close"))),this);getLngLat(){return this._lngLat}setLngLat(e){return this._lngLat=S.convert(e),this._pos=null,this._flatPos=null,this._trackPointer=!1,this._update(),this._map&&(this._map.on("move",this._update),this._map.off("mousemove",this._onMouseMove),this._container&&this._container.classList.remove("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.remove("maplibregl-track-pointer")),this}trackPointer(){return this._trackPointer=!0,this._pos=null,this._flatPos=null,this._update(),this._map&&(this._map.off("move",this._update),this._map.on("mousemove",this._onMouseMove),this._map.on("drag",this._onDrag),this._container&&this._container.classList.add("maplibregl-popup-track-pointer"),this._map._canvasContainer.classList.add("maplibregl-track-pointer")),this}getElement(){return this._container}setText(e){return this.setDOMContent(document.createTextNode(e))}setHTML(e){let t=document.createDocumentFragment(),i=document.createElement("body"),o;for(i.innerHTML=e;o=i.firstChild,!!o;)t.appendChild(o);return this.setDOMContent(t)}getMaxWidth(){return this._container?.style.maxWidth}setMaxWidth(e){return this.options.maxWidth=e,this._update(),this}setDOMContent(e){if(this._content)for(;this._content.hasChildNodes();)this._content.firstChild&&this._content.removeChild(this._content.firstChild);else this._content=l.create("div","maplibregl-popup-content",this._container);return this._content.appendChild(e),this._createCloseButton(),this._update(),this._focusFirstElement(),this}addClassName(e){return this._container&&this._container.classList.add(e),this}removeClassName(e){return this._container&&this._container.classList.remove(e),this}setOffset(e){return this.options.offset=e,this._update(),this}toggleClassName(e){if(this._container)return this._container.classList.toggle(e)}setSubpixelPositioning(e){this.options.subpixelPositioning=e;}_createCloseButton(){this.options.closeButton&&(this._closeButton=l.create("button","maplibregl-popup-close-button",this._content),this._closeButton.type="button",this._closeButton.innerHTML="×",this._closeButton.addEventListener("click",this._onClose));}_onMouseUp=e=>{this._update(e.point);};_onMouseMove=e=>{this._update(e.point);};_onDrag=e=>{this._update(e.point);};_update=e=>{let t=this._lngLat||this._trackPointer;if(!this._map||!t||!this._content)return;if(!this._container){if(this._container=l.create("div","maplibregl-popup",this._map.getContainer()),this._tip=l.create("div","maplibregl-popup-tip",this._container),this._container.appendChild(this._content),this.options.className)for(let p of this.options.className.split(" "))this._container.classList.add(p);this._closeButton&&this._closeButton.setAttribute("aria-label",this._map._getUIString("Popup.Close")),this._trackPointer&&this._container.classList.add("maplibregl-popup-track-pointer");}if(this.options.maxWidth&&this._container.style.maxWidth!==this.options.maxWidth&&(this._container.style.maxWidth=this.options.maxWidth),this._map.transform.renderWorldCopies&&!this._trackPointer?this._lngLat=Le(this._lngLat,this._flatPos,this._map.transform):this._lngLat=this._lngLat?.wrap(),this._trackPointer&&!e)return;let i=this._flatPos=this._pos=this._trackPointer&&e?e:this._map.project(this._lngLat);this._map.terrain&&(this._flatPos=this._trackPointer&&e?e:this._map.transform.locationPoint(this._lngLat));let o=this.options.anchor,s=Pe(this.options.offset);if(!o){let p=this._container.offsetWidth,g=this._container.offsetHeight,T;i.y+s.bottom.y<g?T=["top"]:i.y>this._map.transform.height-g?T=["bottom"]:T=[],i.x<p/2?T.push("left"):i.x>this._map.transform.width-p/2&&T.push("right"),T.length===0?o="bottom":o=T.join("-");}let a=i.add(s[o]);this.options.subpixelPositioning||(a=a.round()),l.setTransform(this._container,`${me[o]} translate(${a.x}px,${a.y}px)`),ge(this._container,o,"popup");};_focusFirstElement(){if(!this.options.focusAfterOpen||!this._container)return;let e=this._container.querySelector(ke);e&&e.focus();}_onClose=()=>{this.remove();}};function Pe(n){if(n)if(typeof n=="number"){let e=Math.round(Math.abs(n)/Math.SQRT2);return {center:new u(0,0),top:new u(0,n),"top-left":new u(e,e),"top-right":new u(-e,e),bottom:new u(0,-n),"bottom-left":new u(e,-e),"bottom-right":new u(-e,-e),left:new u(n,0),right:new u(-n,0)}}else if(n instanceof u||Array.isArray(n)){let e=u.convert(n);return {center:e,top:e,"top-left":e,"top-right":e,bottom:e,"bottom-left":e,"bottom-right":e,left:e,right:e}}else return {center:u.convert(n.center||[0,0]),top:u.convert(n.top||[0,0]),"top-left":u.convert(n["top-left"]||[0,0]),"top-right":u.convert(n["top-right"]||[0,0]),bottom:u.convert(n.bottom||[0,0]),"bottom-left":u.convert(n["bottom-left"]||[0,0]),"bottom-right":u.convert(n["bottom-right"]||[0,0]),left:u.convert(n.left||[0,0]),right:u.convert(n.right||[0,0])};else return Pe(new u(0,0))}var W=class{#e;#t;#i;_undoButton;_deleteButton;_saveButton;_container;constructor(e){this.#e=e,this._container=void 0,this.#i=!1,this.#s().then(()=>{this.#r(),this.#o();});}#o(){this.#e.mode?.addObserver(this.#n);}#n=e=>{let{store:t}=this.#e,{type:i,data:o}=e;i==="MODE_CHANGED"&&!o&&this.hidePanel(),i==="MODE_CHANGED"&&o&&t.tail?.val&&this.setPanelLocation({lat:t.tail?.val?.lat,lng:t.tail?.val?.lng});};#s=async()=>{try{this.#t=new j({offset:16,closeButton:!1,closeOnClick:!1,closeOnMove:!1,anchor:"bottom"});}catch(e){console.error("POPUP LOAD ERROR",e);}};#r=()=>{let{store:e}=this.#e;this.createPanel(),e.tail?.val&&this.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng});};setPanelLocation=e=>{let{map:t}=this.#e;this.#i&&(this.#i=!1,this.showPanel()),this._container&&this.#t&&this.#t.setLngLat(e).setDOMContent(this._container).addTo(t);};hidePanel=()=>{!this.#i&&(this.#t?.addClassName("hide-panel"),this.#i=!0);};showPanel=()=>{this.#t?.removeClassName("hide-panel"),this.#i=!1;};onPointRemove=e=>{e?this.setPanelLocation(e):this.hidePanel();};removePanel=()=>{this._container&&l.remove(this._container),this.#t?.remove();};createButton=(e,t,i,o)=>{let s=l.create("button",`panel-button panel-button-${i}`,o);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`icon ${e} icon-${i}`,s),s};createPanel=()=>{let{options:e}=this.#e,{locale:t}=e,{undo:i,delete:o,save:s}=e.panel.buttons,a=e.panel.size,p=document.querySelector(".maplibregl-popup-content"),g=l.create("div","dashboard",p);i.visible&&(this._undoButton=this.createButton("undo",t.undo,a,g)),o.visible&&(this._deleteButton=this.createButton("delete",t.delete,a,g)),s.visible&&(this._saveButton=this.createButton("save",t.save,a,g)),this._container=g;}};var V={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[]}}]},K={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[]}}]},Me={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}}]},r={LineDynamicLayer:"mdl-line-dynamic-layer",LineLayer:"mdl-line-layer",LineLayerTransparent:"mdl-line-layer-transparent",LineLayerBreak:"mdl-line-break-layer",PolygonLayer:"mdl-polygon-layer",PointsLayer:"mdl-points-layer",SinglePointLayer:"mdl-single-point-layer",FirstPointLayer:"mdl-first-point-layer"},d={LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",LineSource:"mdl-line-source",PolygonSource:"mdl-polygon-source",PointsSource:"mdl-points-source",SinglePointSource:"mdl-single-point-source"},B={large:6.5,default:5.5},$={large:"#FF6464",default:"#666666"},w={"circle-radius":B.default,"circle-color":"#FEFFFE","circle-stroke-color":$.default,"circle-stroke-width":3},D={"circle-radius":B.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},U={"fill-color":"grey","fill-opacity":.4},N={"line-width":3,"line-color":"grey","line-opacity":.7},A={"circle-radius":B.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},R={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},Z=n=>[{id:r.SinglePointLayer,source:d.SinglePointSource,type:"circle",paint:n.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:d.PolygonSource,type:"fill",paint:n.layersPaint.polygon,layout:{visibility:"none"}},{id:r.LineDynamicLayer,source:d.LineDynamicSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"none"}},{id:r.LineLayer,source:d.LineSource,type:"line",paint:n.layersPaint.line,layout:{visibility:"visible"}},{id:r.LineLayerTransparent,source:d.LineSource,type:"line",paint:{"line-width":4,"line-color":"transparent"}},{id:r.LineLayerBreak,source:d.LineSourceBreak,type:"line",paint:n.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:d.PointsSource,type:"circle",paint:n.layersPaint.points,filter:["==",["get","isFirst"],!1]},{id:r.FirstPointLayer,source:d.PointsSource,type:"circle",paint:n.layersPaint.firstPoint,filter:["==",["get","isFirst"],!0]}];var E=class{static#e=0;static#t=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",B.large),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",$.large);};static#i=e=>{e.setPaintProperty(r.FirstPointLayer,"circle-radius",B.default),e.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",$.default);};static togglePointCircleRadius=(e,t)=>{t==="large"?this.#t(e):this.#i(e);};static removeTransparentLine=e=>{e.removeLayer(r.LineLayerTransparent);};static addTransparentLine=(e,t)=>{if(e.getLayer(r.LineLayerTransparent))return;let o=Z(t).find(s=>s.id===r.LineLayerTransparent);o&&e.addLayer(o);};static isDoubleClick(){let t=Date.now();return t-this.#e<=400?(this.#e=t,!0):(this.#e=t,!1)}};var f=class{static isFeatureTriggered(e,t){return e.target.queryRenderedFeatures(e.point,{layers:t}).some(o=>t.includes(o.layer.id))}static getPixelCoordinates=(e,t)=>{let{lat:i,lng:o}=t;return e.project([o,i])};static queryPointId=(e,t)=>e.queryRenderedFeatures(t,{layers:[r.PointsLayer,r.FirstPointLayer]})?.[0]?.properties.id},_=class{static#e(e){let t=[],i=e.head,o=new Set;for(;i!==null;){if(o.has(i.val?.id)){e.head&&e.head.val&&t.push([e.head.val.lng,e.head.val.lat]);break}o.add(i.val?.id),i.val&&t.push([i.val.lng,i.val.lat]),i=i.next;}return t}static getAllLines(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}]}}static getLine(e,t){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[e,t]}}]}}static getPolygon(e){let t=this.#e(e);return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[t]}}]}}static getPoints(e){let t=e.head,i=[],o=new Set;for(;t!==null&&!o.has(t.val?.id);){if(t.val){let s=t.val,a=t.val.id===e.head?.val?.id;i.push({type:"Feature",properties:{id:s.id,lat:s.lat,lng:s.lng,isFirst:a},geometry:{type:"Point",coordinates:[s.lng,s.lat]}});}o.add(t.val?.id),t=t.next;}return {type:"FeatureCollection",features:i}}},m=class n{static getGeometryIndex=(e,t)=>{let i=e.head,o=0;for(;i!==null;){if(i.val?.id===t)return o;o++,i=i.next;}return -1};static isFirstPoint(e){let t=e.target,i=e.point;return !!t.queryRenderedFeatures(i,{layers:[r.FirstPointLayer]}).length}static distance=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2);static checkIfPointIsOnLine=(e,t,i)=>{let s=this.distance(e,t),a=this.distance(e,i),p=this.distance(i,t);return Math.abs(a+p-s)<.1};static isClosedGeometry=e=>e.tail?.next===e.head;static breakGeometry=(e,t)=>{if(!e.head)return;let i=e.head,o=e.tail;do{if(i?.val?.id===t){i!==e.head&&(o.next=i.next,e.head=i,e.tail=o),e.tail.next=null;return}o=i,i=i.next;}while(i!==e.head)};static closeGeometry=(e,t)=>{e.tail&&(e.tail.next=e.head),t.setClosedGeometry(!0);};static canCloseGeometry=e=>e.size>2&&!this.isClosedGeometry(e);static canBreakClosedGeometry=e=>e.size<=2;static switchToLineModeIfCan=e=>{let{mode:t,store:i,tiles:o,map:s}=e;n.canBreakClosedGeometry(i)&&(i.tail&&i.tail.val&&(i.tail.next=null),t.reset(),E.togglePointCircleRadius(s,"default"),o.renderPolygon(V));}},C=()=>{if("crypto"in window&&"randomUUID"in window.crypto)return window.crypto.randomUUID();function n(){return "0123456789abcdef"[Math.floor(Math.random()*16)]}function e(o){let s="";for(let a=0;a<o;a++)s+=n();return s}function t(o){let s=o===0,a=o===4;return s?8:a?12:4}let i=[];for(let o=0;o<5;o++)i.push(e(t(o)));return i.join("-")},O=(n,e)=>{let t,i=!0;function o(){i&&t&&(n(...t),t=null,i=!1,setTimeout(()=>{i=!0,o();},e));}return function(...s){t=s,o();}};var F=class{#e;#t;#i;#o;constructor(e){this.#e=e,this.#n(),this.render();}#n(){this.#s(),this.#r(),this.#a(r.LineLayer,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.SinglePointLayer),this.#a(r.LineLayerTransparent,r.FirstPointLayer),this.#a(r.LineLayerTransparent,r.PointsLayer),this.#a(r.PolygonLayer,r.LineLayer);}#s=()=>{let{map:e}=this.#e;Object.values(d).forEach(t=>{e.getSource(t)||e.addSource(t,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});});};#r=()=>{let{map:e,mode:t,options:i}=this.#e;Z(i).forEach(a=>{e.getLayer(a.id)||e.addLayer(a);});let s=e.getLayoutProperty(r.PolygonLayer,"visibility")==="none";t.getMode()==="polygon"&&s&&e.setLayoutProperty(r.PolygonLayer,"visibility","visible");};#a=(e,t)=>{let{map:i}=this.#e,o=i.getLayer(e),s=i.getLayer(t);o&&s&&i.moveLayer(e,t);};#l=()=>{let{map:e}=this.#e;Object.values(d).forEach(t=>{e.getSource(t)&&e.removeSource(t);});};#c=()=>{let{map:e}=this.#e;Object.values(r).forEach(t=>{e.getLayer(t)&&e.removeLayer(t);});};removeTiles=()=>{this.#c(),this.#l();};renderPoints=e=>{let{map:t}=this.#e,i=t.getSource(d.PointsSource);i&&i.setData(e);};renderLines=(e,t)=>{let{map:i}=this.#e,o=i.getSource(t);o&&o.setData(e);};renderPolygon=e=>{let{map:t}=this.#e,i=t.getSource(d.PolygonSource);i&&i.setData(e);};render=()=>{let{mode:e,options:t,store:i}=this.#e,o=_.getPoints(i),s=_.getAllLines(i);if(this.#t=o,this.#i=s,this.renderPoints(o),this.renderLines(s,d.LineSource),t.modes.polygon.visible&&e.isPolygon()){let p=_.getPolygon(i);this.#o=p,this.renderPolygon(p);}};#h=(e,t)=>{if(this.#o.features[0].geometry.coordinates[0][e]=[t.lng,t.lat],e===0){let o=this.#o.features[0].geometry.coordinates[0]?.length-1;this.#o.features[0].geometry.coordinates[0][o]=[t.lng,t.lat];}this.renderPolygon(this.#o);};#p=(e,t)=>{let{mode:i}=this.#e;this.#i.features[0].geometry.coordinates[e]=[t.lng,t.lat];let o=e===0;if(this.#i&&i.getClosedGeometry()&&o){let a=this.#i.features[0].geometry.coordinates?.length-1;this.#i.features[0].geometry.coordinates[a]=[t.lng,t.lat];}this.renderLines(this.#i,d.LineSource);};renderOnMouseMove=(e,t)=>{let{mode:i,options:o}=this.#e;this.#t.features[e].geometry.coordinates=[t.lng,t.lat],this.renderPoints(this.#t),this.#p(e,t),o.modes.polygon.visible&&i.isPolygon()&&this.#h(e,t);};resetGeometries=()=>{this.renderPoints(Me),this.renderLines(K,d.LineSource),this.renderPolygon(V);}};var Te=8,we=8,x=class{_container;_label;constructor(){this._container=void 0;}create=e=>{let t=l.create("div","popup-container",document.body),i=l.create("span",`popup-text popup-text-${e.placement}`,t);return i.textContent=e.label,this._container=t,this._label=i,this};#e=()=>{!this._label?.classList.value.includes("popup-text-active")&&this._label?.classList.add("popup-text-active");};#t=()=>this._label?{width:this._label.clientWidth,height:this._label.clientHeight}:{width:0,height:0};#i=e=>{let{bottom:t,left:i}=e.target.getBoundingClientRect(),{width:o,height:s}=this.#t();return {x:i-we-o,y:t-s-2}};#o=e=>{let{bottom:t,left:i,right:o}=e.target.getBoundingClientRect(),{width:s}=this.#t();return {x:(o-i)/2+i-s/2,y:t+Te}};getPosition=(e,t)=>t==="left"?this.#i(e):this.#o(e);setPosition=e=>{let{x:t,y:i}=e;this._container&&(this._container.style.left=`${t}px`,this._container.style.top=`${i}px`),this.#e();};remove=()=>{this._container&&l.remove(this._container);}};var P={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var J=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("add",n,t,i);},X=(n,e)=>{for(let[t,i]of Object.entries(e))l.manageEventListener("remove",n,t,i);},be=(n,e)=>{let t=e.locale.line,i=e.locale.polygon,o=e.locale.break;return {line:t,polygon:i,break:o}[n]};var Q=class{#e;constructor(e){this.#e=e,this.#t();}#t=()=>{this.#e.mode.addObserver(this.#l);};removeConsumers=()=>{this.#e.mode.removeObserver(this.#l);};#i=()=>{let{_line:e,_polygon:t,_break:i}=this.#e.control;e?.classList.remove("control-button-active"),t?.classList.remove("control-button-active"),i?.classList.remove("control-button-active");};#o=e=>{this.#i(),e.classList.add("control-button-active");};#n=e=>{let{data:t}=e,{_line:i,_polygon:o,_break:s}=this.#e.control,{mode:a}=this.#e;if(!(!i||!o||!s)){switch(t){case"line":this.#o(i);break;case"polygon":this.#o(o);break;}t?a.getClosedGeometry()&&this.#r(s):this.#s(s);}};#s=e=>{e.setAttribute("disabled","true"),e.setAttribute("aria-disabled","true");};#r=e=>{e.removeAttribute("disabled"),e.removeAttribute("aria-disabled");};#a=e=>{let{data:t,type:i}=e,{_break:o,_line:s,_polygon:a}=this.#e.control,{mode:p}=this.#e;t?(o&&this.#r(o),p.getMode()==="polygon"&&s&&this.#s(s),p.getMode()==="line"&&a&&this.#s(a)):(o&&this.#s(o),p.getMode()==="polygon"&&s&&this.#r(s),p.getMode()==="line"&&a&&this.#r(a));};#l=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.#n(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.#a(e),t==="BREAK_CHANGED"&&i){let{_break:o}=this.#e.control;this.#o(o);}}};var ee=class{#e;#t;#i;constructor(e){this.#e=e,this.#i=new Q(e),this.#t=new x,this.#o();}#o(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&J(e._line,{...t,click:this.onLineClick}),e._polygon&&J(e._polygon,{...t,click:this.onPolygonClick}),e._break&&J(e._break,{...t,click:this.onBreakClick});}}#n(){let{control:e}=this.#e;if(e){let t={mouseenter:this.onButtonEnter,mouseleave:this.onButtonLeave};e._line&&X(e._line,{...t,click:this.onLineClick}),e._polygon&&X(e._polygon,{...t,click:this.onPolygonClick}),e._break&&X(e._break,{...t,click:this.onBreakClick});}}remove(){this.#i.removeConsumers(),this.#n(),this.#t.remove();}onButtonEnter=e=>{let{options:t}=this.#e,i=e.target.getAttribute("data-type");if(i){let o=be(i,t),s="left";this.#t.create({label:o,placement:s}).setPosition(this.#t.getPosition(e,s));}};onButtonLeave=()=>{this.#t.remove();};#s=()=>{let{control:e}=this.#e;e._line?.classList.remove("control-button-active"),e._polygon?.classList.remove("control-button-active"),e._break?.classList.remove("control-button-active");};#r=()=>{let{map:e,mode:t}=this.#e;t.getMode()||e.fire("mode:initialize");};onLineClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="line"?(t.setMode(null),e.fire("mode:remove"),i.resetGeometries()):(o._line?.classList.add("control-button-active"),t.setMode("line"),i.render());};onPolygonClick=()=>{let{map:e,mode:t,tiles:i,control:o}=this.#e;this.#r(),this.#s(),t.getMode()==="polygon"?(t.setMode(null),e.fire("mode:remove"),e.setLayoutProperty(r.PolygonLayer,"visibility","visible"),i.resetGeometries()):(o._polygon?.classList.add("control-button-active"),t.setMode("polygon"),i.render());};onBreakClick=()=>{let{map:e,mode:t,control:i}=this.#e;t.getBreak()&&(t.setMode(null),e.fire("mode:remove")),this.#s(),i._break?.classList.add("control-button-active"),t.setBreak(!0),e.getCanvasContainer().style.cursor=P.POINTER;}};var k=class{observers;constructor(){this.observers=new Set;}addObserver(e){this.observers.add(e);}removeObserver(e){this.observers.delete(e);}unsubscribe(){this.observers.clear();}notify(e){this.observers.forEach(t=>t(e));}};var G={EMPTY_INITIAL_STATE:"You passed an empty initial array in the options. Please either remove the 'initial' property or include at least one element in the array.",MISSING_IDS:"You set 'generateId' to false but did not provide IDs for all steps. Please ensure all steps have IDs or set 'generateId' to true.",NOT_ENOUGH_POINTS_TO_CLOSE:"At least three points are required to close a polygon or a line. Please add more points or set 'closeGeometry' to false.",FIRST_LAST_POINT_NOT_EQUAL:"The first and last points of a polygon or a closed linestring must be the same. Please ensure the first and last points are equal or set 'closeGeometry' to false."};var te=class{val;next;constructor(e=null,t=null){this.val=e,this.next=t;}},q=class extends k{head;tail;size;constructor(e){super();let t=b.initStore(e);this.head=t?t.head:null,this.tail=t?t.tail:null,this.size=t?t.size:0;}push(e){let t=new te(e);this.head?this.tail&&(this.tail.next=t,this.tail=t):this.head=this.tail=t,this.size++,this.pingConsumers();}insert(e,t){let i=new te(e,t.next);this.tail===t&&this.head===t.next&&(this.tail=i),t.next=i,this.size++;}findStepById(e){let t=this.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.val&&t.val.id===e)return t.val;i.add(t),t=t.next;}return null}removeStepById(e){if(!this.head)return null;let t=this.head,i=null;for(;t!==null;){if(t?.val?.id===e)return t===this.head?(this.head=t.next,this.tail&&(this.tail.next=t.next)):i.next=t.next,t===this.tail&&(this.tail=i),this.size--,this.pingConsumers(),t;i=t,t.next&&(t=t.next);}return null}reset(){this.head=null,this.tail=null,this.size=0,this.pingConsumers();}pingConsumers=()=>{this.notify({type:"STORE_CHANGED",data:{head:this.head,tail:this.tail,size:this.size}});}},b=class n{static isLastPoint=(e,t)=>e.tail?.val?.id===t;static initStore(e){if(!e?.initial)return null;if(e&&e.initial&&!e.initial.steps.length)throw new Error(G.EMPTY_INITIAL_STATE);if(e&&e.initial.steps){let{steps:o,closeGeometry:s,generateId:a}=e.initial;return n.fromArray(o,s,a)}return null}static#e=e=>e.map(t=>({...t,id:C()}));static buildStepSequence(e){let t=new q;return e.forEach(i=>{t.push(i);}),t}static fromArray(e,t,i){let o=i?this.#e(e):e,s=this.buildStepSequence(o);return t&&s.tail&&(s.tail.next=s.head),s}static toArray(e){if(!e)return [];let t=new Set,i=[],o=e;for(;o!==null&&!t.has(o);)t.add(o),i.push(o.val),o=o.next;return i}};var L={DOUBLECLICK:"mdl:doubleclick",POINTENTER:"mdl:pointenter",POINTLEAVE:"mdl:pointleave",MOVEEND:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REMOVEALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",LINE:"mdl:line",POLYGON:"mdl:polygon"};var y={panel:{size:"medium",buttons:{undo:{visible:!0},delete:{visible:!0},save:{visible:!0,clearOnSave:!0}}},modes:{initial:null,line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{onLinePoint:D,firstPoint:w,points:A,line:N,polygon:U,breakLine:R},initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close line",createPolygon:"Create polygon"}};var v=class{static addPoint(e,t,i){t.fire(L.ADD,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now(),mode:{geometry:i.getMode(),closedGeometry:i.getClosedGeometry()}});}static movePoint(e,t){t.fire(L.MOVEEND,{id:e.id,start_coordinates:{lat:e.start.lat,lng:e.start.lng},end_coordinates:{lat:e.end.lat,lng:e.end.lng},total:e.total,timestamp:Date.now()});}static pointDoubleClick(e,t){t.fire(L.DOUBLECLICK,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){t.fire(L.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){t.fire(L.POINTLEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undoPoint(e,t,i){t.fire(L.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static removeAllPoints(e,t){e.fire(L.REMOVEALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:o,mode:s}=e;o.fire(L.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onLineBreak(e){e.fire(L.BREAK);}};var ie=class{#e;#t;constructor(e){this.#e=e,this.#t=new x;}initEvents(){let{panel:e}=this.#e;e&&(l.manageEventListener("add",e?._undoButton,"click",this.#n),l.manageEventListener("add",e?._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._undoButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._deleteButton,"click",this.#o),l.manageEventListener("add",e?._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._deleteButton,"mouseleave",this.onMouseLeave)),e&&(l.manageEventListener("add",e?._saveButton,"click",this.onSaveClick),l.manageEventListener("add",e?._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("add",e?._saveButton,"mouseleave",this.onMouseLeave));}removeEvents(){let{panel:e}=this.#e;e&&e._undoButton&&(l.manageEventListener("remove",e._undoButton,"click",this.#n),l.manageEventListener("remove",e._undoButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._undoButton,"mouseleave",this.onMouseLeave)),e&&e._deleteButton&&(l.manageEventListener("remove",e._deleteButton,"click",this.#o),l.manageEventListener("remove",e._deleteButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._deleteButton,"mouseleave",this.onMouseLeave)),e&&e._saveButton&&(l.manageEventListener("remove",e._saveButton,"click",this.onSaveClick),l.manageEventListener("remove",e._saveButton,"mouseenter",this.onMouseEnter),l.manageEventListener("remove",e._saveButton,"mouseleave",this.onMouseLeave));}#i=e=>{let{options:t}=this.#e;return {undo:t.locale.undo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let t=e.target.getAttribute("data-type");if(t){let i=this.#i(t);this.#t.create({label:i,placement:"bottom"}).setPosition(this.#t.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.#t.remove();};#o=e=>{let{tiles:t,mode:i,panel:o,store:s,map:a}=this.#e;s.reset(),o.hidePanel(),i.reset(),E.togglePointCircleRadius(a,"default"),this.#t.remove(),t.resetGeometries(),v.removeAllPoints(a,e);};#n=e=>{let{store:t,panel:i,map:o,tiles:s}=this.#e,a=t.tail?.val;t.removeStepById(a.id);let p={...a,total:t.size};v.undoPoint(p,o,e),m.switchToLineModeIfCan(this.#e),i?.onPointRemove(t.tail?.val),this.#t.remove(),requestAnimationFrame(s.render);};onSaveClick=e=>{let{store:t,options:i}=this.#e;v.onSaveClick(this.#e,b.toArray(t.head),e),this.#t.remove(),i.panel.buttons.save.clearOnSave&&this.#o(e);}};var M=class{static updatePointsData(e){let i=e.target.getSource(d.SinglePointSource);i&&i.setData({type:"Feature",geometry:{type:"Point",coordinates:[e.lngLat.lng,e.lngLat.lat]},properties:{}});}static setSinglePointVisible(e){e.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");}static setSinglePointHidden(e){let t=e.target;setTimeout(()=>{t.setLayoutProperty(r.SinglePointLayer,"visibility","none");},33);}static triggerPostPointAddition(e,t){let{panel:i,tiles:o,store:s,map:a}=t;m.canCloseGeometry(s)&&E.togglePointCircleRadius(a,"large"),i?.setPanelLocation(e.lngLat),o.render();}static addPointToMap=(e,t)=>{let{store:i,map:o,mode:s}=t,a={...e.lngLat,id:C()};i.push(a),v.addPoint({...a,total:i.size},o,s),this.triggerPostPointAddition(e,t);};static updateSelectedStepLatLng=(e,t)=>{t.lat=e.lngLat.lat,t.lng=e.lngLat.lng;}};var fe=(n,e)=>{let t=e.head,i=new Set;for(;t!==null&&!i.has(t);){if(t.next&&t.next.val&&t.val){let o=n.target,s=f.getPixelCoordinates(o,t.val),a=f.getPixelCoordinates(o,t.next.val),p=f.getPixelCoordinates(o,n.lngLat);if(m.checkIfPointIsOnLine(s,a,p))return t}i.add(t),t=t.next;}return null},_e=(n,e)=>{let t=fe(n,e);if(t){let i={...n.lngLat,id:C()};return e.insert(i,t),i}return null},Ce=(n,e)=>{let{store:t,tiles:i,panel:o}=e;t.tail?.val&&(o?.setPanelLocation(t.tail.val),M.setSinglePointHidden(n),i.render());},Se=n=>f.isFeatureTriggered(n,[r.PointsLayer,r.FirstPointLayer]);var Oe=15,oe=class{props;#e;#t;constructor(e){this.props=e,this.#e=null,this.#t=O(this.#o,Oe);}initBreakEvents=()=>{let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mouseenter",r.LineLayerTransparent,this.#t),e.on("mousemove",r.LineLayerTransparent,this.#t),e.on("mouseleave",r.LineLayerTransparent,this.#n);};removeBreakEvents=()=>{let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mouseenter",r.LineLayerTransparent,this.#t),e.off("mousemove",r.LineLayerTransparent,this.#t),e.off("mouseleave",r.LineLayerTransparent,this.#n);};hideBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{let{map:e}=this.props;e.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&e.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};#i=()=>{let{store:e,mode:t,panel:i,map:o,tiles:s}=this.props,a=this.#e?.next?.val?.id;m.breakGeometry(e,a),e.tail?.val&&i.setPanelLocation({lat:e.tail?.val?.lat,lng:e.tail?.val?.lng}),this.#n(),o.setLayoutProperty(r.PolygonLayer,"visibility","none"),t.reset(),s.render(),v.onLineBreak(o);};#o=e=>{let{map:t,store:i}=this.props,o=fe(e,i);o?.val?.id!==this.#e?.val?.id&&(this.#e=o);let s=t.getSource(d.LineSourceBreak),a=[o?.val?.lng,o?.val?.lat],p=[o?.next?.val?.lng,o?.next?.val?.lat],g=_.getLine(a,p);g&&(s.setData(g),this.showBreakLine());};#n=()=>{setTimeout(()=>{this.hideBreakLine();},Oe+10);}};var De=10,ne=class{#e;#t;#i;#o;#n;#s;constructor(e){this.#e=e,this.#t=e.options.dynamicLine,this.#i=null,this.#o=null,this.#r(),this.#s=O(this.#p,De);}#r(){this.#e.store.addObserver(this.#l),this.#e.mode.addObserver(this.#c),this.#e.mouseEvents.addObserver(this.#a);}removeLine=()=>{this.hideDynamicLine();};removeConsumers=()=>{this.#e.store.removeObserver(this.#l),this.#e.mode.removeObserver(this.#c),this.#e.mouseEvents.removeObserver(this.#a);};#a=e=>{let{mode:t}=this.#e;if(!t.getClosedGeometry()&&(e.type==="lastPointMouseClick"&&e.data?(this.hideDynamicLine(),this.#t=!1):e.type==="lastPointMouseClick"&&!e.data&&(this.#t=!0),!!this.#t&&((e.type==="pointMouseEnter"||e.type==="lineMouseEnter")&&e.data&&this.hideDynamicLine(),(e.type==="pointMouseLeave"||e.type==="lineMouseLeave")&&e.data))){let{store:i}=this.#e;this.#i=i.tail?.val,this.#o=i.tail?.val,this.showDynamicLine();}};#l=e=>{let{store:t}=this.#e;switch(e.type){case"STORE_CHANGED":e.data.tail?.val&&!m.isClosedGeometry(t)&&(this.#i=e.data.tail?.val,this.showDynamicLine());break;}};#c=e=>{let{store:t}=this.#e;e.type==="CLOSED_GEOMETRY_CHANGED"&&(e.data&&this.hideDynamicLine(),!e.data&&t?.tail?.val&&(this.#i=t?.tail?.val,this.showDynamicLine()));};initDynamicEvents=()=>{let{map:e}=this.#e;e.on("click",this.#f),e.on("mousemove",this.#s),e.on(L.REMOVEALL,this.hideDynamicLine),e.on(L.UNDO,this.#m),e.on(L.DOUBLECLICK,this.#v);};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#f),e.off("mousemove",this.#s),e.off(L.REMOVEALL,this.hideDynamicLine),e.off(L.UNDO,this.#m),e.off(L.DOUBLECLICK,this.#v);};hideDynamicLine=()=>{let{map:e,tiles:t}=this.#e;this.#i=null,this.#o=null,this.#n=null,e.off("mousemove",this.#s),t.renderLines(K,d.LineDynamicSource),e.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};showDynamicLine=()=>{let{map:e}=this.#e,t=[this.#i?.lng,this.#i?.lat],i=[this.#o?.lng,this.#o?.lat];this.#n=_.getLine(t,i),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.#o&&this.#h({lng:this.#o?.lng,lat:this.#o?.lat}),e.on("mousemove",this.#s);};#h=e=>{if(!this.#n)return;let{tiles:t}=this.#e;this.#n.features[0].geometry.coordinates[1]=[e.lng,e.lat],t.renderLines(this.#n,d.LineDynamicSource);};#p=e=>{this.#h(e.lngLat);};#f=e=>{let{mode:t}=this.#e,i=f.isFeatureTriggered(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.#o={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hideDynamicLine();};#m=e=>{let{store:t,mode:i}=this.#e;if(!i.getClosedGeometry()){let o=e.target.unproject({x:e.originalEvent.x,y:e.originalEvent.y});this.#o={lng:o.lng,lat:o.lat},this.#i=t.tail?.val,this.showDynamicLine();}};#v=e=>{let{store:t,mode:i}=this.#e;i.getClosedGeometry()||(this.#o={lng:e.coordinates.lng,lat:e.coordinates.lat},this.#i=t.tail?.val,this.showDynamicLine());}};var Ae=22,se=class{props;#e;#t;constructor(e){this.props=e,this.#e=!1,this.#t=null;}initEvents(){let{map:e}=this.props;e.on("click",r.LineLayerTransparent,this.#i),e.on("mousemove",r.LineLayerTransparent,this.#n),e.on("mouseenter",r.LineLayerTransparent,this.#s),e.on("mouseleave",r.LineLayerTransparent,this.#r);}removeEvents(){let{map:e}=this.props;e.off("click",r.LineLayerTransparent,this.#i),e.off("mousemove",r.LineLayerTransparent,this.#n),e.off("mouseenter",r.LineLayerTransparent,this.#s),e.off("mouseleave",r.LineLayerTransparent,this.#r);}#i=e=>{let{store:t,map:i,mode:o}=this.props;if(Se(e))return;let s=_e(e,t);s&&(v.addPoint({...s,total:t.size},i,o),Ce(e,this.props));};#o=e=>{M.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)&&M.updatePointsData(e);};#n=O(e=>{if(f.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer]))return;let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(this.#t=e,!this.#e&&(this.#e=!0,requestAnimationFrame(()=>{this.#t&&(this.#o(this.#t),this.#e=!1);})));},Ae);#s=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||f.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer])||(t.lineMouseEnter=!0,M.setSinglePointVisible(e));};#r=e=>{let{mouseEvents:t}=this.props;t.pointMouseDown||t.pointMouseEnter||(t.lineMouseLeave=!0,M.setSinglePointHidden(e));}};var re=class{props;#e;#t;#i;#o;constructor(e){this.props=e,this.#e=new oe(e),this.#t=new se(e),this.#i=null,this.#o="default";}init(){this.#n(),this.#s(),this.#r();}#n=()=>{window.innerWidth<=768||this.props.options.dynamicLine&&(this.#i=new ne(this.props));};#s(){!this.props.mode.getBreak()&&(this.#t.initEvents(),this.props.options.dynamicLine&&this.#i?.initDynamicEvents());}#r(){this.props.mode.addObserver(this.#h),this.props.mouseEvents.addObserver(this.#c);}remove(){this.#a(),this.#l();}#a(){this.props.mode.removeObserver(this.#h),this.props.mouseEvents.removeObserver(this.#c),this.props.options.dynamicLine&&this.#i?.removeConsumers();}#l(){this.#e.removeBreakEvents(),this.#t.removeEvents(),this.props.options.dynamicLine&&(this.#i?.removeEvents(),this.#i?.removeLine());}#c=e=>{let{type:t,data:i}=e,{mode:o}=this.props;if(!(!i||!o.getBreak()))switch(t){case"pointMouseDown":this.#e.removeBreakEvents(),this.#e.hideBreakLine();break;case"pointMouseUp":this.#e.initBreakEvents();break;}};#h=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.#o==="break"&&(this.#e.removeBreakEvents(),this.#t.initEvents(),this.#o="default"),t==="BREAK_CHANGED"&&i&&this.#o==="default"&&(this.#t.removeEvents(),this.#e.initBreakEvents(),this.#o="break");}};var ae=class{#e;#t;#i;constructor(e){this.#t=e,this.#e=!1,this.#i=new x,e.mode.addObserver(this.#o);}initEvents(){let{map:e}=this.#t;e.on("click",r.FirstPointLayer,this.#n),e.on("mouseenter",r.FirstPointLayer,this.#c),e.on("mouseleave",r.FirstPointLayer,this.#a),e.on("mouseup",r.FirstPointLayer,this.#r),e.on("mousedown",r.FirstPointLayer,this.#s);}removeEvents(){let{map:e}=this.#t;e.off("click",r.FirstPointLayer,this.#n),e.off("mouseenter",r.FirstPointLayer,this.#c),e.off("mouseleave",r.FirstPointLayer,this.#a),e.off("mouseup",r.FirstPointLayer,this.#r);}#o=e=>{let{map:t,store:i}=this.#t,{type:o,data:s}=e;o==="MODE_CHANGED"&&(s==="line"||s==="polygon"?t.on("click",r.FirstPointLayer,this.#n):t.off("click",r.FirstPointLayer,this.#n),m.canCloseGeometry(i)&&E.togglePointCircleRadius(t,"large"));};#n=()=>{let{store:e,map:t,mode:i,tiles:o}=this.#t;if(i.getMode()==="polygon"&&t.setLayoutProperty(r.PolygonLayer,"visibility","visible"),m.canCloseGeometry(e)){m.closeGeometry(e,i);let s=Object.assign({},e.head?.val,{id:C(),total:e.size});v.addPoint(s,t,i),E.togglePointCircleRadius(t,"default"),o.render();}};#s=()=>{this.#e=!0,this.#i.remove();};#r=()=>{this.#e=!1;};#a=()=>{let{mouseEvents:e}=this.#t;this.#e||(e.firstPointMouseLeave=!0,this.#i.remove());};#l=()=>{let{mode:e,options:t}=this.#t;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};#c=e=>{let{mode:t,mouseEvents:i,store:o}=this.#t;if(!(t.getClosedGeometry()||this.#e)&&(i.firstPointMouseEnter=!0,m.canCloseGeometry(o))){let{x:s,y:a}=e.originalEvent;if(s&&a){this.#i.create({label:this.#l(),placement:"bottom"});let g=this.#i._label?this.#i._label.clientWidth/2:0;this.#i.setPosition({x:s-g,y:a+14});}}}};var le=class{#e;#t;#i;#o;#n;#s;#r;#a;constructor(e){this.#e=e,this.#t=void 0,this.#i=null,this.#o=null,this.#n=null,this.#s=new ae(e),this.#r=!1,this.#a=null;}#l=()=>{let{map:e}=this.#e;e.on("click",r.FirstPointLayer,this.#p),e.on("mouseenter",r.FirstPointLayer,this.#L),e.on("mouseleave",r.FirstPointLayer,this.#g),e.on("mousedown",r.FirstPointLayer,this.#d),e.on("mouseup",r.FirstPointLayer,this.#u),e.on("touchend",r.FirstPointLayer,this.#u),e.on("touchstart",r.FirstPointLayer,this.#d),this.#s.initEvents();};initEvents=()=>{let{map:e}=this.#e;e.on("click",this.#m),e.on("dblclick",this.#h),e.on("click",r.PointsLayer,this.#p),e.on("mouseenter",r.PointsLayer,this.#L),e.on("mouseleave",r.PointsLayer,this.#g),e.on("mousedown",r.PointsLayer,this.#d),e.on("mouseup",r.PointsLayer,this.#u),e.on("touchend",r.PointsLayer,this.#u),e.on("touchstart",r.PointsLayer,this.#d),this.#l();};#c=()=>{let{map:e}=this.#e;e.off("click",r.FirstPointLayer,this.#p),e.off("mouseenter",r.FirstPointLayer,this.#L),e.off("mouseleave",r.FirstPointLayer,this.#g),e.off("mousedown",r.FirstPointLayer,this.#d),e.off("mouseup",r.FirstPointLayer,this.#u),e.off("touchend",r.PointsLayer,this.#u),e.off("touchstart",r.PointsLayer,this.#d),this.#s.removeEvents();};removeEvents=()=>{let{map:e}=this.#e;e.off("click",this.#m),e.off("dblclick",this.#h),e.off("mousemove",this.#y),e.off("click",r.PointsLayer,this.#p),e.off("mouseenter",r.PointsLayer,this.#L),e.off("mouseleave",r.PointsLayer,this.#g),e.off("mousedown",r.PointsLayer,this.#d),e.off("mouseup",r.PointsLayer,this.#u),this.#c();};#h=e=>{e.preventDefault();};#p=e=>{let{store:t,tiles:i,panel:o,map:s,mouseEvents:a}=this.#e;E.isDoubleClick()&&this.#o&&(t.removeStepById(this.#o.id),o.onPointRemove(t.tail?.val),v.pointDoubleClick({...this.#o,total:t.size},this.#e.map),m.switchToLineModeIfCan(this.#e));let p=f.queryPointId(s,e.point);b.isLastPoint(t,p)&&(a.lastPointMouseClick=!0,a.lastPointMouseUp=!1),i.render();};#f=e=>f.isFeatureTriggered(e,[r.PointsLayer,r.FirstPointLayer,r.LineLayerTransparent,r.LineLayerBreak]);#m=e=>{let{mode:t,mouseEvents:i,map:o}=this.#e;t.getClosedGeometry()||this.#f(e)||(i.lastPointMouseClick&&(i.lastPointMouseClick=!1),o.getCanvasContainer().style.cursor="grab",M.addPointToMap(e,this.#e),M.setSinglePointHidden(e));};#v=e=>{e.originalEvent.buttons===0&&this.#u();};#E=e=>{let{tiles:t}=this.#e;t.renderOnMouseMove(this.#n,e.lngLat);};#y=O(e=>{this.#a=e,this.#r||(this.#r=!0,requestAnimationFrame(()=>{!this.#o||!this.#a||(M.updateSelectedStepLatLng(this.#a,this.#o),this.#v(this.#a),this.#E(this.#a),this.#r=!1);}));},15);#L=e=>{let{mouseEvents:t,map:i,store:o}=this.#e;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;M.setSinglePointHidden(e);let s=f.queryPointId(i,e.point);b.isLastPoint(o,s)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let a=o.findStepById(s);a&&(this.#i=a,v.enterPoint(Object.assign({},a,{total:o.size}),i));};#g=e=>{let{mouseEvents:t,store:i,map:o}=this.#e;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let s=f.queryPointId(o,e.point);b.isLastPoint(i,s)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),v.leavePoint(Object.assign({},this.#i,{total:i.size}),o);};#P=()=>{let{store:e,panel:t}=this.#e;this.#o&&b.isLastPoint(e,this.#o.id)&&t.hidePanel();};#M=e=>{let{store:t,map:i}=this.#e,o=f.queryPointId(i,e.point),s=t.findStepById(o);s&&(this.#o=s);};#d=e=>{e.preventDefault();let{mouseEvents:t,map:i,store:o}=this.#e;E.removeTransparentLine(i),this.#M(e),this.#P();let s=f.queryPointId(i,e.point);this.#n=m.getGeometryIndex(o,s),t&&(t.pointMouseDown=!0),this.#t=e.lngLat,i.on("mousemove",this.#y),i.on("touchmove",this.#y);};#u=()=>{let{mouseEvents:e,store:t,panel:i,map:o,options:s}=this.#e;e.pointMouseUp=!0,this.#o&&(b.isLastPoint(t,this.#o.id)&&t.tail?.val&&i?.setPanelLocation(t.tail.val),i?.showPanel(),v.movePoint({id:this.#o.id,total:t.size,end:{lat:this.#o.lat,lng:this.#o.lng},start:this.#t},o)),e&&(e.pointMouseDown=!1),E.addTransparentLine(o,s),o.off("mousemove",this.#y),o.off("touchmove",this.#y);}};var ce=class extends F{#e;#t;#i;#o;#n;constructor(e){super({...e}),this.#e=e,this.#t=new ie(e),this.#i=new ee(e),this.#o=new le(e),this.#n=new re(e),e.map.on("mode:initialize",this.#s),e.map.on("mode:remove",this.#r);}#s=()=>{this.#n.init(),this.#t?.initEvents(),this.#o?.initEvents();};#r=()=>{this.#t?.removeEvents(),this.#o?.removeEvents(),this.#n?.remove();};removeMapEventsAndConsumers=()=>{this.#t?.removeEvents(),this.#o?.removeEvents(),this.#i?.remove(),this.#n?.remove(),this.#e.map.off("mode:initialize",this.#s);}};var he=class{#e;_line;_polygon;_break;_container;constructor(e){this.#e=e.options,this._line=void 0,this._polygon=void 0,this._break=void 0,this._container=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl(e);}createControlButton=(e,t,i,o)=>{let s=this.#e.panel.size,a=l.create("button",`control-button control-button-${s}`,this._container);return a.setAttribute("aria-label",t),a.setAttribute("data-type",e),i&&a.classList.add("control-button-active"),o&&(a.setAttribute("disabled","true"),a.setAttribute("aria-disabled","true")),l.create("span",`icon ${e} icon-${s}`,a),a};#t=e=>{let{mode:t,options:i}=e,o=this.#e.modes.line.visible,s=i.locale.line;o&&(this._line=this.createControlButton("line",s,t.getMode()==="line"));};#i=e=>{let{mode:t,options:i}=e,o=this.#e.modes.polygon.visible,s=i.locale.polygon;o&&(this._polygon=this.createControlButton("polygon",s,t.getMode()==="polygon"));};#o=e=>{let{mode:t,options:i}=e,o=this.#e.modes.breakGeometry.visible,s=i.locale.break;if(o){let p=!this.#e?.initial?.closeGeometry,g=t.getBreak();this._break=this.createControlButton("break",s,g,p);}};createControl=e=>{this.#t(e),this.#i(e),this.#o(e);};getContainer=()=>this._container};function Ie(n){return n.initial?.geometry?n.initial?.geometry:n.modes.initial?n.modes.initial:null}var pe=class extends k{#e;#t;#i;constructor(e){super(),this.#e=Ie(e),this.#t=!1,this.#i=e.initial?.closeGeometry??!1;}getMode=()=>this.#e;setMode=e=>{this.#e=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.#t;setBreak=e=>{this.#t=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.#i;setClosedGeometry=e=>{this.#i=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.#i});};isPolygon=()=>this.#e==="polygon"&&this.#i;reset=()=>{this.setMode(this.getMode()),this.setClosedGeometry(!1);};pingConsumers=()=>{this.notify({type:"MODE_CHANGED",data:this.getMode()}),this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.getClosedGeometry()});}};var ue=class{#e;#t;constructor(e){this.#e=e,this.#t=this.#e.map.getCanvasContainer(),this.#t.style.cursor=e.mode.getMode()?P.CROSSHAIR:P.AUTO,this.#i();}set=e=>{this.#t.style.cursor=e;};get=()=>this.#t.style.cursor;handleMouseLeave=()=>{let{mouseEvents:e,mode:t}=this.#e;if(!e.pointMouseDown){if(!t.getMode()){this.set(P.AUTO);return}t.getClosedGeometry()?this.set(P.AUTO):this.set(P.CROSSHAIR);}};handleFirstPointMouseEnter=()=>{let{mode:e,store:t}=this.#e;e.getClosedGeometry()&&this.set(P.MOVE),m.canCloseGeometry(t)&&this.set(P.POINTER);};#i(){let{mouseEvents:e}=this.#e;e.addObserver(this.#o);}removeConsumers(){let{mouseEvents:e}=this.#e;e.removeObserver(this.#o);}#o=e=>{let{mode:t,mouseEvents:i}=this.#e;if(t.getBreak())return;let{type:o,data:s}=e;if(s)switch(o){case"pointMouseDown":this.set(P.GRABBING);break;case"pointMouseUp":this.set(P.GRAB);break;case"pointMouseEnter":if(i.pointMouseDown)return;this.set(P.GRAB);break;case"pointMouseLeave":this.handleMouseLeave();break;case"lineMouseEnter":if(i.pointMouseDown)return;this.set(P.POINTER);break;case"lineMouseLeave":this.handleMouseLeave();break;case"firstPointMouseEnter":this.handleFirstPointMouseEnter();break;case"firstPointMouseLeave":this.handleMouseLeave();break;case"lastPointMouseEnter":this.set(P.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var de=class extends k{#e;#t;#i;#o;#n;#s;#r;#a;#l;#c;#h;#p;constructor(){super(),this.#e=!1,this.#t=!1,this.#i=!1,this.#o=!1,this.#n=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#l=!1,this.#c=!1,this.#h=!1,this.#p=!1;}get firstPointMouseEnter(){return this.#e}set firstPointMouseEnter(e){this.#e=e,this.notify({type:"firstPointMouseEnter",data:e});}get firstPointMouseLeave(){return this.#t}set firstPointMouseLeave(e){this.#t=e,this.notify({type:"firstPointMouseLeave",data:e});}get lastPointMouseClick(){return this.#i}set lastPointMouseClick(e){this.#i=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#o}set lastPointMouseUp(e){this.#o=e,this.notify({type:"lastPointMouseUp",data:e});}get lastPointMouseEnter(){return this.#n}set lastPointMouseEnter(e){this.#n=e,this.notify({type:"lastPointMouseEnter",data:e});}get lastPointMouseLeave(){return this.#s}set lastPointMouseLeave(e){this.#s=e,this.notify({type:"lastPointMouseLeave",data:e});}get pointMouseDown(){return this.#r}set pointMouseDown(e){this.#r=e,this.notify({type:"pointMouseDown",data:e});}get pointMouseUp(){return this.#a}set pointMouseUp(e){this.#a=e,this.notify({type:"pointMouseUp",data:e});}get pointMouseEnter(){return this.#l}set pointMouseEnter(e){this.#l=e,this.notify({type:"pointMouseEnter",data:e});}get pointMouseLeave(){return this.#c}set pointMouseLeave(e){this.#c=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#h}set lineMouseEnter(e){this.#h=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#p}set lineMouseLeave(e){this.#p=e,this.notify({type:"lineMouseLeave",data:e});}};var z=class{static allStepsHaveIds(e){return e.every(t=>"id"in t&&t.id!==void 0)}static checkIfMissingIds(e,t){let i=!t,o=!this.allStepsHaveIds(e);if(i&&o)throw new Error(G.MISSING_IDS)}static checkIfEnoughPointsToClose(e,t){if(t&&e.length<3)throw new Error(G.NOT_ENOUGH_POINTS_TO_CLOSE)}static checkIfPolygonIsClosed(e){let{closeGeometry:t,steps:i}=e;if(i){let o=i[0]?.lng,s=i[i.length-1]?.lng,a=i[0]?.lat,p=i[i.length-1]?.lat;if((o!==s||a!==p)&&t)throw new Error(G.FIRST_LAST_POINT_NOT_EQUAL)}}static checkInitialStepsOption(e){let{closeGeometry:t,generateId:i,steps:o}=e;this.checkIfMissingIds(o,i),this.checkIfEnoughPointsToClose(o,t),this.checkIfPolygonIsClosed(e);}static init(e){return e?{panel:Be(e),modes:Ne(e),layersPaint:Re(e),initial:e.initial||y.initial,locale:Fe(e),dynamicLine:e.dynamicLine??y.dynamicLine}:y}};function Be(n){return {size:n.panel?.size||y.panel.size,buttons:{undo:{visible:n.panel?.buttons?.undo?.visible??y.panel.buttons.undo.visible},delete:{visible:n.panel?.buttons?.delete?.visible??y.panel.buttons.delete.visible},save:{visible:n.panel?.buttons?.save?.visible??y.panel.buttons.save.visible,clearOnSave:n.panel?.buttons?.save?.clearOnSave??y.panel.buttons.save.clearOnSave}}}}function Ne(n){return {initial:n.modes?.initial||y.modes.initial,line:{visible:n?.modes?.line?.visible!==void 0?n.modes.line.visible:n?.initial?.geometry==="line"||y.modes.line.visible,closeGeometry:n?.modes?.line?.closeGeometry??n?.initial?.closeGeometry??y.modes.line.closeGeometry},polygon:{visible:n?.modes?.polygon?.visible!==void 0?n.modes.polygon.visible:n?.initial?.geometry==="polygon"||y.modes.polygon.visible},breakGeometry:{visible:n?.modes?.breakGeometry?.visible??y.modes.breakGeometry.visible}}}function Re(n){return {onLinePoint:{"circle-radius":n.layersPaint?.onLinePoint?.["circle-radius"]||D["circle-radius"],"circle-color":n.layersPaint?.onLinePoint?.["circle-color"]||D["circle-color"],"circle-stroke-color":n.layersPaint?.onLinePoint?.["circle-stroke-color"]||D["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.onLinePoint?.["circle-stroke-width"]||D["circle-stroke-width"],...n.layersPaint?.onLinePoint},firstPoint:{"circle-radius":n.layersPaint?.firstPoint?.["circle-radius"]||w["circle-radius"],"circle-color":n.layersPaint?.firstPoint?.["circle-color"]||w["circle-color"],"circle-stroke-color":n.layersPaint?.firstPoint?.["circle-stroke-color"]||w["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.firstPoint?.["circle-stroke-width"]||w["circle-stroke-width"],...n.layersPaint?.firstPoint},points:{"circle-radius":n.layersPaint?.points?.["circle-radius"]||A["circle-radius"],"circle-color":n.layersPaint?.points?.["circle-color"]||A["circle-color"],"circle-stroke-color":n.layersPaint?.points?.["circle-stroke-color"]||A["circle-stroke-color"],"circle-stroke-width":n.layersPaint?.points?.["circle-stroke-width"]||A["circle-stroke-width"],...n.layersPaint?.points},line:{"line-width":n.layersPaint?.line?.["line-width"]||N["line-width"],"line-color":n.layersPaint?.line?.["line-color"]||N["line-color"],"line-opacity":n.layersPaint?.line?.["line-opacity"]||N["line-opacity"],...n.layersPaint?.line},polygon:{"fill-color":n.layersPaint?.polygon?.["fill-color"]||U["fill-color"],"fill-opacity":n.layersPaint?.polygon?.["fill-opacity"]||U["fill-opacity"],...n.layersPaint?.polygon},breakLine:{"line-width":n.layersPaint?.breakLine?.["line-width"]||R["line-width"],"line-color":n.layersPaint?.breakLine?.["line-color"]||R["line-color"],"line-dasharray":n.layersPaint?.breakLine?.["line-dasharray"]||R["line-dasharray"],...n.layersPaint?.breakLine}}}function Fe(n){return {save:n.locale?.save??y.locale.save,delete:n.locale?.delete??y.locale.delete,undo:n.locale?.undo??y.locale.undo,line:n.locale?.line??y.locale.line,polygon:n.locale?.polygon??y.locale.polygon,break:n.locale?.break??y.locale.break,closeLine:n.locale?.closeLine??y.locale.closeLine,createPolygon:n.locale?.createPolygon??y.locale.createPolygon}}var ve=class n{#e;#t;#i;#o;#n;#s;#r;#a;#l;static#c=null;static#h=!1;constructor(e){if(this.#o=z.init(e),this.#o.initial&&z.checkInitialStepsOption(this.#o.initial),n.#h)throw new Error("Use 'DrawLibre.getInstance()' instead of 'new DrawLibre()'.");n.#h=!0,this.#t=void 0,this.#i=void 0,this.#n=void 0,this.#s=void 0,this.#r=void 0,this.#l=void 0,this.#a=void 0;}static getInstance(e){return n.#c||(n.#c=new n(e)),n.#c}onAdd(e){this.#t=new q(this.#o),this.#i=new pe(this.#o),this.#r=new W({map:e,mode:this.#i,options:this.#o,store:this.#t}),this.#s=new F({map:e,store:this.#t,options:this.#o,mode:this.#i});let t=new he({options:this.#o,mode:this.#i});return this.#l=new de,this.#a=new ue({map:e,mode:this.#i,mouseEvents:this.#l,store:this.#t}),this.#n=new ce({map:e,store:this.#t,options:this.#o,panel:this.#r,control:t,mode:this.#i,tiles:this.#s,mouseEvents:this.#l}),this.#i.getMode()&&e.fire("mode:initialize"),this.#i.pingConsumers(),this.#e=t.getContainer(),this.#e}onRemove(){this.#a?.removeConsumers(),this.#s?.removeTiles(),this.#n?.removeMapEventsAndConsumers(),this.#r?.removePanel(),this.#t?.reset(),this.#i?.unsubscribe(),this.#e&&l.remove(this.#e);}setSteps=e=>{if(Array.isArray(e))e.forEach(t=>{let i={...t,id:t.id||C()};this.#t?.push(i);});else throw new Error("Invalid argument. Expected an array of steps.");this.#s?.render();};findStepById=e=>this.#t?.findStepById(e);getAllSteps=(e="array")=>{if(e==="array"&&this.#t)return b.toArray(this.#t.head);if(e==="linkedlist")return this.#t;throw new Error("Invalid type specified. Use 'array' or 'linkedlist'.")};setOptions=e=>{this.#o=e(this.#o);};removeAllSteps=()=>{this.#t?.reset(),this.#r?.removePanel(),this.#s?.render();}};
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { L as DRAW_LIBRE_EVENTS, ve as default };
|