draw-libre 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var q=class{_isHidden=!0;_anchor={dx:0,dy:0};_pendingCoord=null;_rafId=0;_listenersActive=!1;get isHidden(){return this._isHidden}set isHidden(e){this._isHidden=e;}get anchor(){return {...this._anchor}}set anchor(e){this._anchor={...e};}get pendingCoord(){return this._pendingCoord}set pendingCoord(e){this._pendingCoord=e;}get rafId(){return this._rafId}set rafId(e){this._rafId=e;}get listenersActive(){return this._listenersActive}set listenersActive(e){this._listenersActive=e;}reset(){this._isHidden=!0,this._anchor={dx:0,dy:0},this._pendingCoord=null,this._rafId=0,this._listenersActive=!1;}};var l=class{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 addEventListener(e,t,i,n={}){e&&e.addEventListener(t,i,n);}static removeEventListener(e,t,i,n={}){e&&e.removeEventListener(t,i,n);}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);}static setPressed(e,t){e&&(e.classList.toggle("control-button-active",t),e.setAttribute("aria-pressed",String(t)));}static disableButton=e=>{e&&(e.setAttribute("disabled","true"),e.setAttribute("aria-disabled","true"));};static enableButton=e=>{e&&(e.removeAttribute("disabled"),e.removeAttribute("aria-disabled"));}};var Y=class{constructor(e){this.ctx=e;this.root=l.create("div","mdl-dashboard-container"),this.root.setAttribute("data-type","panel"),this.buttonContainer=l.create("div","mdl-dashboard",this.root),this.renderButtons(),this.hasButtons()&&e.map.getContainer().appendChild(this.root);}root;buttonContainer;buttons={};createButton(e,t,i,n){let s=l.create("button",`mdl-panel-button mdl-panel-button-${i}`,n);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`icon ${e} icon-${i}`,s),s}renderButtons(){let{panel:e,locale:t}=this.ctx.options,{buttons:i,size:n}=e;Object.keys(i).forEach(s=>{if(!i[s].visible)return;let a=this.createButton(s,t[s],n,this.buttonContainer);(s==="undo"||s==="redo")&&l.disableButton(a),this.buttons[s]=a;});}getButton=e=>this.buttons[e]??null;hasButtons=()=>Object.keys(this.buttons).length>0;getRoot=()=>this.root;show=()=>{this.root.classList.remove("hidden"),this.root.removeAttribute("aria-hidden");};hide=()=>{this.root.classList.add("hidden"),this.root.setAttribute("aria-hidden","true");};setTransform=(e,t)=>{this.root.style.transform=`translate(${e}px, ${t}px)`;};observeResize=e=>{let t=new ResizeObserver(e);return t.observe(this.root),t};destroy=()=>{this.root.remove();}};var ft=8,Ze=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};activateAnimation=()=>{!this.label?.classList.value.includes("popup-text-active")&&this.label?.classList.add("popup-text-active");};getLabelDimensions=()=>this.label?{width:this.label.clientWidth,height:this.label.clientHeight}:{width:0,height:0};getLeftPosition=e=>{let{bottom:t,left:i,right:n}=e.target.getBoundingClientRect(),{width:s,height:a}=this.getLabelDimensions(),p=i-Ze-s,u=t-a-2;return p<0?{x:n+Ze,y:u}:{x:p,y:u}};getBottomPosition=e=>{let{bottom:t,left:i,right:n}=e.target.getBoundingClientRect(),{width:s}=this.getLabelDimensions();return {x:(n-i)/2+i-s/2,y:t+ft}};getPosition=(e,t)=>t==="left"?this.getLeftPosition(e):this.getBottomPosition(e);setPosition=e=>{let{x:t,y:i}=e;this.container&&(this.container.style.left=`${t}px`,this.container.style.top=`${i}px`),this.activateAnimation();};remove=()=>{this.container&&l.remove(this.container);}};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 j=class{constructor(e,t,i=[]){this.type=e;this.payload=t;this.commands=i;}add(e){this.commands.push(e);}execute(){if(this.commands)for(let e of this.commands)e.execute();}undo(){if(this.commands)for(let e=this.commands.length-1;e>=0;e--)this.commands[e]?.undo();}};var Ge=class o extends x{transaction=null;undoStack=[];redoStack=[];static instance=null;static getInstance(){return o.instance||(o.instance=new o),o.instance}commit=e=>{e.execute(),this.transaction?this.transaction.add(e):this.undoStack.push(e),this.redoStack.length=0,this.pingConsumers();};undo=()=>{let e=this.undoStack.pop();if(e)return e.undo(),this.redoStack.push(e),this.pingConsumers(),e};redo=()=>{let e=this.redoStack.pop();return e?(e.execute(),this.undoStack.push(e),this.pingConsumers(),e):null};beginTransaction=(e="compound",t=null)=>{this.transaction||(this.transaction=new j(e,t));};commitTransaction=()=>{if(!this.transaction)return;let e=this.transaction;this.transaction=null,this.undoStack.push(e),this.pingConsumers();};getRedoStackLength=()=>this.redoStack.length;getUndoStackLength=()=>this.undoStack.length;resetStacks=()=>{this.transaction=null,this.undoStack=[],this.redoStack=[],this.pingConsumers();};pingConsumers=()=>{this.notify({type:"REDO_STACK_CHANGED",data:this.redoStack.length}),this.notify({type:"UNDO_STACK_CHANGED",data:this.undoStack.length});}},h=Ge.getInstance();var b=()=>{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("-")},A=(o,e)=>{let t=0,i=(...n)=>{window.clearTimeout(t),t=window.setTimeout(()=>{t=0,o(...n);},e);};return i.cancel=()=>{window.clearTimeout(t),t=0;},i},C=o=>{let e=null,t=0,i=()=>{t=0;let s=e;e=null,s&&o(...s);},n=(...s)=>{e=s,t===0&&(t=window.requestAnimationFrame(i));};return n.cancel=()=>{t!==0&&window.cancelAnimationFrame(t),t=0,e=null;},n};var Xe={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",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",AuxiliaryPointLayer:"mdl-auxiliary-point-layer",PointsHitLayer:"mdl-points-hit-layer",FirstPointHitLayer:"mdl-first-point-hit-layer",AuxiliaryPointHitLayer:"mdl-auxiliary-point-hit-layer"},P={points:["all",["==",["geometry-type"],"Point"],["==",["get","isFirst"],!1],["==",["get","isAuxiliary"],!1]],pointsWhenClosed:["all",["==",["geometry-type"],"Point"],["==",["get","isAuxiliary"],!1]],firstPoint:["==",["get","isFirst"],!0],auxiliaryPoint:["==",["get","isAuxiliary"],!0]},c={UnifiedSource:"mdl-unified-source",LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",SinglePointSource:"mdl-single-point-source"},O={large:6.5,default:5.5},K={large:"#FF6464",default:"#666666"},N={"circle-radius":O.default,"circle-color":"#FEFFFE","circle-stroke-color":K.default,"circle-stroke-width":3},D={"circle-radius":O.default-1.5,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":2},k={"circle-radius":O.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},F={"fill-color":"grey","fill-opacity":.4},R={"line-width":3,"line-color":"grey","line-opacity":.7},I={"circle-radius":O.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},J={...R,"line-dasharray":[4.5,2.5]},B={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},yt=.18,Et={"circle-color":"#666666","circle-opacity":["case",["boolean",["feature-state","hover"],!1],yt,0]},Qe=o=>{let e={...Et,"circle-radius":o.interaction.pointHitRadius,"circle-pitch-scale":"viewport"};return [{id:r.SinglePointLayer,source:c.SinglePointSource,type:"circle",paint:o.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:c.UnifiedSource,type:"fill",paint:o.layersPaint.polygon,layout:{visibility:"none"},filter:["==",["geometry-type"],"Polygon"]},{id:r.LineDynamicLayer,source:c.LineDynamicSource,type:"line",paint:o.layersPaint.dynamicLine,layout:{visibility:"none"}},{id:r.LineLayer,source:c.UnifiedSource,type:"line",paint:o.layersPaint.line,layout:{visibility:"visible"},filter:["==",["geometry-type"],"LineString"]},{id:r.LineLayerTransparent,source:c.UnifiedSource,type:"line",paint:{"line-width":o.interaction.lineHitRadius*2,"line-color":"transparent"},filter:["==",["geometry-type"],"LineString"]},{id:r.LineLayerBreak,source:c.LineSourceBreak,type:"line",paint:o.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:c.UnifiedSource,type:"circle",paint:o.layersPaint.points,filter:P.points},{id:r.FirstPointLayer,source:c.UnifiedSource,type:"circle",paint:o.layersPaint.firstPoint,filter:P.firstPoint,layout:{visibility:"none"}},{id:r.AuxiliaryPointLayer,source:c.UnifiedSource,type:"circle",paint:o.layersPaint.auxiliaryPoint,filter:P.auxiliaryPoint},{id:r.PointsHitLayer,source:c.UnifiedSource,type:"circle",paint:{...e},filter:P.points},{id:r.FirstPointHitLayer,source:c.UnifiedSource,type:"circle",paint:{...e},filter:P.firstPoint,layout:{visibility:"none"}},{id:r.AuxiliaryPointHitLayer,source:c.UnifiedSource,type:"circle",paint:{...e},filter:P.auxiliaryPoint}]};var v={getMidpoint(o,e){return {lat:(o.lat+e.lat)/2,lng:(o.lng+e.lng)/2}},createAuxiliaryPoint(o,e){let t=v.getMidpoint(o,e);return {lat:t.lat,lng:t.lng,isAuxiliary:!0,id:b()}}},et=[r.FirstPointLayer,r.FirstPointHitLayer],tt=[r.PointsLayer,r.PointsHitLayer],gt=33,U=null,Fe=()=>{U!==null&&(clearTimeout(U),U=null);},y={cancelSinglePointHiding:Fe,setFirstPointVisible(o){for(let e of et)o.setLayoutProperty(e,"visibility","visible");},setFirstPointHidden(o){for(let e of et)o.setLayoutProperty(e,"visibility","none");},setSinglePointVisible(o){Fe(),o.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");},setSinglePointHidden(o){let e=o.target;Fe(),U=setTimeout(()=>{U=null,e.setLayoutProperty(r.SinglePointLayer,"visibility","none");},gt);}},Ue={default(o){for(let e of tt)o.setFilter(e,P.points);},closedGeometry(o){for(let e of tt)o.setFilter(e,P.pointsWhenClosed);}};var W=class{constructor(e,t){this.store=e;this.options=t;this.store=e;}isCircular=()=>{let{head:e,tail:t}=this.store;return !e||!t?!1:e===t.next&&t===e.prev};canBreak=()=>{let{size:e}=this.store,t=this.options?.pointGeneration==="auto"?3:2;return e<=t};canClose=()=>{let{size:e}=this.store;return (this.options?.pointGeneration==="auto"?e>3:e>2)&&!this.isCircular()};break=e=>{if(this.store.head)if(this.options?.pointGeneration==="auto")if(e.val?.isAuxiliary){let t=e.val?.id;this.store.head=e.next,this.store.tail=e.prev,this.store.removeNodeById(t),this.store.head.prev=null,this.store.tail.next=null;}else {let t=e.next?.val?.id;this.store.head=e.next?.next,this.store.tail=e,this.store.removeNodeById(t),this.store.head.prev=null,this.store.tail.next=null;}else this.store.head=e.next,this.store.head.prev=null,this.store.tail=e,this.store.tail.next=null;};close=()=>{let{head:e,tail:t}=this.store;!e||!t||(t.next=e,e.prev=t);}};var z=class{val;prev;next;constructor(e=null,t=null,i=null){this.val=e,this.prev=i,this.next=t;}},_=class extends x{constructor(t){super();this.options=t;let i=it(this.options);this.circular=new W(this,this.options),this.map=i?i.map:new Map,this.head=i?i.head:null,this.tail=i?i.tail:null,this.size=i?i.size:0;}head;tail;size;map;circular;push=t=>{let i=new z(t);return this.head?this.tail&&(i.prev=this.tail,this.tail.next=i,this.tail=i):this.head=this.tail=i,this.map.set(t.id,i),this.size++,this.pingConsumers(),i};unshift=t=>{let i=new z(t);i.next=this.head,this.head=i,this.circular.isCircular()&&this.tail&&(this.tail.next=i,i.prev=this.tail),this.map.set(t.id,i),this.size++,this.pingConsumers();};insertAfter=(t,i)=>{if(!t)return null;let n=new z(i);return n.prev=t,n.next=t.next,this.tail===t&&this.head===t.next&&(this.tail=n,this.head.prev=n),t.next&&(t.next.prev=n),t.next=n,this.map.set(i.id,n),this.size++,this.pingConsumers(),n};removeNodeById(t){let i=this.map.get(t);return i?(this.size===1?(this.head=null,this.tail=null):(i.prev&&(i.prev.next=i.next),i.next&&(i.next.prev=i.prev),i===this.head&&(this.head=i.next,this.head?.prev&&this.tail&&(this.tail.next=this.head)),i===this.tail&&(this.tail=i.prev,this.head&&this.tail?.next&&(this.head.prev=this.tail))),this.map.delete(t),this.size--,this.pingConsumers(),i):null}findStepById(t){let i=this.map.get(t);return i?i.val:null}findNodeById(t){let i=this.map.get(t);return i||null}isLastPoint=(t,i)=>t.pointGeneration==="auto"&&this.tail?.next===this.head?this.tail?.prev?.val?.id===i:this.tail?.val?.id===i;reset=()=>{this.head=null,this.tail=null,this.size=0,this.map.clear(),this.notify({type:"STORE_CLEARED"});};pingConsumers=()=>{this.notify({type:"STORE_MUTATED",data:{head:this.head,tail:this.tail,size:this.size}});}};var L={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.",NOT_ADDED_TO_MAP:"DrawLibre is not added to a map. Call map.addControl(draw) before using this method.",ALREADY_ADDED_TO_MAP:"DrawLibre is already added to a map. Call map.removeControl(draw) before adding it again.",REENTRANT_LIFECYCLE:"DrawLibre is in the middle of being added or removed. Do not call map.addControl or map.removeControl from a listener that runs during addControl or removeControl.",INVALID_STEPS_ARGUMENT:"Invalid argument. Expected an array of steps.",INVALID_STEPS_TYPE:"Invalid type specified. Use 'array' or 'linkedlist'."};function ot(o,e,t,i){let n=t?e.slice(0,-1):e;return n.forEach((s,a)=>{if(o.push(s),i==="auto"){if(n[a+1]){let u=v.createAuxiliaryPoint(s,n[a+1]);o.push(u);}else if(t){let u=v.createAuxiliaryPoint(s,n[0]);o.push(u);}}}),o}function nt(o){return o.map((e,t)=>{let i="id"in e&&e.id!==void 0?e.id:b();return {...e,isAuxiliary:!1,isFirst:t===0,id:i}})}function Lt(o,e){let{steps:t,closeGeometry:i}=o,n=nt(t),s=ot(new _,n,i,e);return i&&s.tail&&s.head&&(s.tail.next=s.head,s.head.prev=s.tail),s}function st(o,e,t){ot(o,nt(e),!1,t);}function it(o){if(!o?.initial)return null;if(o&&o.initial&&!o.initial.steps.length)throw new Error(L.EMPTY_INITIAL_STATE);return o&&o.initial.steps?Lt(o.initial,o.pointGeneration):null}function $(o){if(!o)return [];let e=new Set,t=[],i=o;for(;i!==null&&!e.has(i);)e.add(i),t.push(i.val),i=i.next;return t}var g={POINT_REMOVE:"mdl:pointremove",POINTENTER:"mdl:pointenter",POINT_LEAVE:"mdl:pointleave",MOVE_END:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REDO:"mdl:redo",REMOVE_ALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",MODE_CHANGED:"mdl:modechanged",UNDO_STACK_CHANGED:"mdl:undostackchanged",REDO_STACK_CHANGED:"mdl:redostackchanged"};var d=class o{static emitter=null;static queue=[];static delivering=!1;static bind(e){o.emitter=e;}static unbind(e){o.emitter===e&&(o.emitter=null);}static dispatch(e,t,i){let n={...i,type:t,target:e};if(o.queue.push({map:e,type:t,payload:n,emitter:o.emitter}),!o.delivering){o.delivering=!0;try{let s=o.queue.shift();for(;s;)s.map.fire(s.type,s.payload),s.emitter?.emit(s.type,s.payload),s=o.queue.shift();}finally{o.queue=[],o.delivering=!1;}}}static addPoint(e,t,i){o.dispatch(t,g.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){o.dispatch(t,g.MOVE_END,{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 removePoint(e,t){o.dispatch(t,g.POINT_REMOVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){o.dispatch(t,g.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){o.dispatch(t,g.POINT_LEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undo(e,t,i){o.dispatch(t,g.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static redo(e,t,i){o.dispatch(t,g.REDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static modeChanged(e,t){o.dispatch(e,g.MODE_CHANGED,{mode:t});}static removeAllPoints(e,t){o.dispatch(e,g.REMOVE_ALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:n,mode:s}=e;o.dispatch(n,g.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onLineBreak(e){o.dispatch(e,g.BREAK,{});}static onUndoStackChange=(e,t)=>{o.dispatch(e,g.UNDO_STACK_CHANGED,{length:t});};static onRedoStackChange=(e,t)=>{o.dispatch(e,g.REDO_STACK_CHANGED,{length:t});}};function xt(o){let e=[],t=o.head,i=new Set;for(;t!==null;){if(i.has(t.val?.id)){o.head&&o.head.val&&e.push([o.head.val.lng,o.head.val.lat]);break}i.add(t.val?.id),t.val&&e.push([t.val.lng,t.val.lat]),t=t.next;}return e}function Z(o,e){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[o,e]}}]}}function bt(o){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:o}}]}}function Ct(o){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[o]}}]}}function Pt(o){let e=o.head,t=[],i=new Set;for(;e!==null&&!i.has(e.val?.id);){if(e.val){let n=e.val,s=e.val.id===o.head?.val?.id;t.push({type:"Feature",properties:{id:n.id,lat:n.lat,lng:n.lng,isFirst:s,isAuxiliary:n.isAuxiliary},geometry:{type:"Point",coordinates:[n.lng,n.lat]}});}i.add(e.val?.id),e=e.next;}return {type:"FeatureCollection",features:t}}function ze(o){let e=Pt(o).features,t=xt(o),i=bt(t).features,n=Ct(t).features;return {type:"FeatureCollection",features:[...e,...i,...n]}}var Ve=class o{static instance=null;ctx=null;unifiedGeoJSON;constructor(){this.unifiedGeoJSON={type:"FeatureCollection",features:[]};}initialize(e){return this.ctx=e,this.unifiedGeoJSON=ze(this.ctx.store),this.execute(),o.instance}static getInstance(){return o.instance||(o.instance=new o),o.instance}getContext(){if(!this.ctx)throw new Error("Somehow trolled with Renderer.getContext, check the Renderer.initialize");return this.ctx}updateLine(e,t){let{mode:i}=this.getContext(),n=this.unifiedGeoJSON.features.at(-2)?.geometry.coordinates;n&&(n[e]=[t.lng,t.lat],i.getClosedGeometry()&&e===0&&(n[n.length-1]=[t.lng,t.lat]));}updatePolygon(e,t){let{mode:i}=this.getContext(),n=this.unifiedGeoJSON.features.at(-1)?.geometry.coordinates[0];n&&(n[e]=[t.lng,t.lat],i.getClosedGeometry()&&e===0&&(n[n.length-1]=[t.lng,t.lat]));}updatePoint(e,t){let i=this.unifiedGeoJSON?.features?.[e];i?.geometry?.coordinates&&(i.geometry.coordinates=[t.lng,t.lat]);}executeOnMouseMove=(e,t,i)=>{let{map:n,mode:s,options:a,store:p}=this.getContext(),u=e===0?p.size-1:e-1;this.updatePoint(e,t),i&&i.prev&&this.updatePoint(u,i.prev),i&&i.next&&this.updatePoint(e+1,i.next),this.updateLine(e,t),i&&i.prev&&this.updateLine(u,i.prev),i&&i.next&&this.updateLine(e+1,i.next),a.modes.polygon.visible&&s.isPolygon()&&(this.updatePolygon(e,t),i&&i.prev&&this.updatePolygon(u,i.prev),i&&i.next&&this.updatePolygon(e+1,i.next));let M=n.getSource(c.UnifiedSource);M&&M.setData(this.unifiedGeoJSON);};execute(){let{map:e,store:t}=this.getContext();this.unifiedGeoJSON=ze(t);let i=e.getSource(c.UnifiedSource);i&&i.setData(this.unifiedGeoJSON);}resetGeometries=()=>{let{map:e}=this.getContext(),t=e.getSource(c.UnifiedSource);t&&t.setData({type:"FeatureCollection",features:[]});}},f=Ve.getInstance();var X=class{constructor(e){this.ctx=e;}clear=e=>{let{mode:t,view:i,store:n,map:s}=this.ctx;n.reset(),i.hide(),t.reset(),h.resetStacks(),f.resetGeometries(),d.removeAllPoints(s,e),f.execute();};undo=e=>{let{store:t,map:i}=this.ctx;h.undo(),d.undo({...t.tail?.val,total:t.size},i,e),f.execute();};redo=e=>{let{store:t,map:i}=this.ctx;h.redo(),d.redo({...t.tail?.val,total:t.size},i,e),f.execute();};save=e=>{let{store:t,options:i}=this.ctx;d.onSaveClick(this.ctx,$(t.head),e),i.panel.buttons.save.clearOnSave&&this.clear(e),f.execute();}};var Q=class{constructor(e){this.ctx=e;this.tooltip=new S,this.actions=new X(this.ctx);}tooltip;actions;addButtonListeners(e,t){let i=this.ctx.view.getButton(e);i&&(l.addEventListener(i,"click",t),l.addEventListener(i,"mouseenter",this.onMouseEnter),l.addEventListener(i,"mouseleave",this.onMouseLeave));}removeButtonListeners(e,t){let i=this.ctx.view.getButton(e);i&&(l.removeEventListener(i,"click",t),l.removeEventListener(i,"mouseenter",this.onMouseEnter),l.removeEventListener(i,"mouseleave",this.onMouseLeave));}initEvents(){this.addButtonListeners("undo",this.onUndoClick),this.addButtonListeners("redo",this.onRedoClick),this.addButtonListeners("delete",this.onClearClick),this.addButtonListeners("save",this.onSaveClick);}removeEvents(){this.removeButtonListeners("undo",this.onUndoClick),this.removeButtonListeners("redo",this.onRedoClick),this.removeButtonListeners("delete",this.onClearClick),this.removeButtonListeners("save",this.onSaveClick);}getButtonLabel=e=>{let{options:t}=this.ctx;return {undo:t.locale.undo,redo:t.locale.redo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let i=e.target.getAttribute("data-type");if(i){let n=this.getButtonLabel(i);this.tooltip.create({label:n,placement:"bottom"}).setPosition(this.tooltip.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.tooltip.remove();};onUndoClick=e=>{this.actions.undo(e),this.tooltip.remove();};onRedoClick=e=>{this.actions.redo(e),this.tooltip.remove();};onClearClick=e=>{this.actions.clear(e),this.tooltip.remove();};onSaveClick=e=>{this.actions.save(e),this.tooltip.remove();};api(){return this.actions}};var ee=class{constructor(e){this.ctx=e;}initConsumers(){this.ctx.store.addObserver(this.onStoreChangeConsumer),this.ctx.mode?.addObserver(this.onMapModeConsumer),h.addObserver(this.onTimelineChangeConsumer);}removeConsumers(){this.ctx.store.removeObserver(this.onStoreChangeConsumer),this.ctx.mode?.removeObserver(this.onMapModeConsumer),h.removeObserver(this.onTimelineChangeConsumer);}onTimelineChangeConsumer=e=>{let{type:t,data:i}=e;t==="REDO_STACK_CHANGED"&&(i?l.enableButton(this.ctx.view.getButton("redo")):l.disableButton(this.ctx.view.getButton("redo"))),t==="UNDO_STACK_CHANGED"&&(i?l.enableButton(this.ctx.view.getButton("undo")):l.disableButton(this.ctx.view.getButton("undo")));};onStoreChangeConsumer=e=>{if(e.type==="STORE_MUTATED"){let{data:t}=e;if(t?.size===0)this.ctx.view.hide();else {let i=Object.assign({},t);for(;i.tail;)if(i.tail?.val?.isAuxiliary)i.tail=i.tail?.prev;else {i.tail?.val&&this.ctx.setPanelLocation({lat:i.tail.val.lat,lng:i.tail.val.lng});break}}}};onMapModeConsumer=e=>{let{store:t}=this.ctx,{type:i,data:n}=e;i==="MODE_CHANGED"&&!n&&this.ctx.view.hide(),i==="MODE_CHANGED"&&n&&(this.ctx.store.circular.isCircular()?this.ctx.options.pointGeneration==="auto"?t.tail?.prev?.val&&this.ctx.setPanelLocation({lat:t.tail.prev.val.lat,lng:t.tail.prev.val.lng}):t.tail?.val&&this.ctx.setPanelLocation({lat:t.tail.val.lat,lng:t.tail.val.lng}):t.tail?.val&&this.ctx.setPanelLocation({lat:t.tail.val.lat,lng:t.tail.val.lng}));}};var Mt=20,te=class{constructor(e){this.ctx=e;this.view=new Y(e),this.events=new Q({...e,view:this.view}),this.observer=new ee({...e,view:this.view,setPanelLocation:this.setPanelLocation}),this.init();}view;state=new q;events;observer;resizeObserver;onMapMove=()=>this.schedulePositionUpdate();init(){let{store:e}=this.ctx;this.resizeObserver=this.view.observeResize(this.measureAnchor),this.measureAnchor(),e.tail?.val&&this.setPanelLocation(e.tail.val),this.events.initEvents(),this.observer.initConsumers();}destroy(){this.observer.removeConsumers(),this.events.removeEvents(),this.state.listenersActive&&this.disableListeners(),this.resizeObserver.disconnect(),cancelAnimationFrame(this.state.rafId),this.view.destroy();}enableListeners(){if(this.state.listenersActive)return;let e=this.ctx.map;e.on("move",this.onMapMove),e.on("zoom",this.onMapMove),this.state.listenersActive=!0;}disableListeners(){if(!this.state.listenersActive)return;let e=this.ctx.map;e.off("move",this.onMapMove),e.off("zoom",this.onMapMove),this.state.listenersActive=!1;}setPanelLocation=e=>{this.view.hasButtons()&&(this.state.pendingCoord=e,this.enableListeners(),this.schedulePositionUpdate(),this.show());};measureAnchor=()=>{let{width:e,height:t}=this.view.getRoot().getBoundingClientRect();this.state.anchor={dx:-e/2,dy:-t-Mt},this.schedulePositionUpdate();};schedulePositionUpdate=()=>{this.state.rafId||(this.state.rafId=requestAnimationFrame(()=>{if(this.state.rafId=0,this.state.pendingCoord){let e=this.ctx.map.project(this.state.pendingCoord),{dx:t,dy:i}=this.state.anchor;this.view.setTransform(e.x+t,e.y+i);}}));};setVisible(e){this.state.isHidden=!e,e?this.view.show():this.view.hide();}show=()=>this.setVisible(!0);hide=()=>this.setVisible(!1);api=()=>this.events.api()};var E={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var rt=(o,e)=>{let t=e.locale.line,i=e.locale.polygon,n=e.locale.break;return {line:t,polygon:i,break:n}[o]};var ie=class{constructor(e){this.ctx=e;this.tooltip=new S,this.initEvents();}tooltip;initEvents(){let{lineButton:e,breakButton:t,polygonButton:i}=this.ctx.view;e&&(l.addEventListener(e,"click",this.onLineClick),l.addEventListener(e,"mouseenter",this.onButtonEnter),l.addEventListener(e,"mouseleave",this.onButtonLeave)),i&&(l.addEventListener(i,"click",this.onPolygonClick),l.addEventListener(i,"mouseenter",this.onButtonEnter),l.addEventListener(i,"mouseleave",this.onButtonLeave)),t&&(l.addEventListener(t,"click",this.onBreakClick),l.addEventListener(t,"mouseenter",this.onButtonEnter),l.addEventListener(t,"mouseleave",this.onButtonLeave));}removeEvents(){let{lineButton:e,breakButton:t,polygonButton:i}=this.ctx.view;e&&(l.removeEventListener(e,"click",this.onLineClick),l.removeEventListener(e,"mouseenter",this.onButtonEnter),l.removeEventListener(e,"mouseleave",this.onButtonLeave)),i&&(l.removeEventListener(i,"click",this.onPolygonClick),l.removeEventListener(i,"mouseenter",this.onButtonEnter),l.removeEventListener(i,"mouseleave",this.onButtonLeave)),t&&(l.removeEventListener(t,"click",this.onBreakClick),l.removeEventListener(t,"mouseenter",this.onButtonEnter),l.removeEventListener(t,"mouseleave",this.onButtonLeave));}remove(){this.removeEvents(),this.tooltip.remove();}onButtonEnter=e=>{let{options:t}=this.ctx,i=e.target.getAttribute("data-type");if(i){let n=rt(i,t),s="left";this.tooltip.create({label:n,placement:s}).setPosition(this.tooltip.getPosition(e,s));}};onButtonLeave=()=>{this.tooltip.remove();};removeActiveClass=()=>{let{lineButton:e,breakButton:t,polygonButton:i}=this.ctx.view;l.setPressed(e,!1),l.setPressed(i,!1),l.setPressed(t,!1);};onLineClick=()=>{this.tooltip.remove();let{mode:e}=this.ctx,{lineButton:t}=this.ctx.view;if(e.getMode()==="line"&&!e.getBreak()){e.setMode(null),this.removeActiveClass();return}this.removeActiveClass(),l.setPressed(t,!0),e.setMode("line"),console.log(e.getMode());};onPolygonClick=()=>{this.tooltip.remove();let{mode:e}=this.ctx,{polygonButton:t}=this.ctx.view;if(e.getMode()==="polygon"&&!e.getBreak()){e.setMode(null),this.removeActiveClass();return}this.removeActiveClass(),l.setPressed(t,!0),e.setMode("polygon");};onBreakClick=()=>{this.tooltip.remove();let{map:e,mode:t}=this.ctx,{breakButton:i}=this.ctx.view;this.removeActiveClass(),l.setPressed(i,!0),t.setBreak(!0),e.getCanvasContainer().style.cursor=E.POINTER;}};var oe=class{constructor(e){this.ctx=e;this.initConsumers();}announced=void 0;initConsumers=()=>{this.ctx.mode.addObserver(this.mapModeConsumer);};remove=()=>{this.ctx.mode.removeObserver(this.mapModeConsumer);};resetAllState=()=>{let{lineButton:e,breakButton:t,polygonButton:i}=this.ctx.view;l.setPressed(e,!1),l.setPressed(i,!1),l.setPressed(t,!1);};announce=e=>{e!==this.announced&&(this.announced=e,d.modeChanged(this.ctx.map,e));};checkActive=e=>{this.resetAllState(),l.setPressed(e,!0);};observeModeChange=e=>{let{data:t}=e,{lineButton:i,breakButton:n,polygonButton:s}=this.ctx.view,{mode:a}=this.ctx;this.announce(t),(t==="line"||t==="polygon")&&(this.resetAllState(),l.setPressed(t==="line"?i:s,!0)),n&&(t?a.getClosedGeometry()&&l.enableButton(n):l.disableButton(n));};observeGeometryChange=e=>{let{data:t}=e,{lineButton:i,breakButton:n,polygonButton:s}=this.ctx.view,{mode:a}=this.ctx,p=a.getMode();n&&(t?l.enableButton(n):l.disableButton(n)),p==="polygon"&&i&&(t?l.disableButton(i):l.enableButton(i)),p==="line"&&s&&(t?l.disableButton(s):l.enableButton(s));};mapModeConsumer=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.observeModeChange(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.observeGeometryChange(e),t==="BREAK_CHANGED"&&i){let{breakButton:n}=this.ctx.view;this.checkActive(n),this.announce("break");}}};var ne=class{constructor(e){this.ctx=e;this.root=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl();}root;lineButton;polygonButton;breakButton;createControlButton=(e,t,i,n)=>{let s=this.ctx.options.panel.size,a=l.create("button",`control-button control-button-${s}`,this.root);return a.setAttribute("aria-label",t),a.setAttribute("data-type",e),l.setPressed(a,i),n&&l.disableButton(a),l.create("span",`icon ${e} icon-medium`,a),a};createLineButton=()=>{let{mode:e,options:t}=this.ctx,i=this.ctx.options.modes.line.visible,n=t.locale.line;i&&(this.lineButton=this.createControlButton("line",n,e.getMode()==="line"));};createPolygonButton=()=>{let{mode:e,options:t}=this.ctx,i=this.ctx.options.modes.polygon.visible,n=t.locale.polygon;i&&(this.polygonButton=this.createControlButton("polygon",n,e.getMode()==="polygon"));};createBreakButton=()=>{let{mode:e,options:t}=this.ctx,i=this.ctx.options.modes.breakGeometry.visible,n=t.locale.break;if(i){let a=!this.ctx.options.initial?.closeGeometry,p=e.getBreak();this.breakButton=this.createControlButton("break",n,p,a);}};createControl=()=>{this.createLineButton(),this.createPolygonButton(),this.createBreakButton();};getContainer=()=>this.root;destroy=()=>{this.root.remove();}};var se=class{constructor(e){this.ctx=e;this.view=new ne(e);let t={...e,view:this.view};this.events=new ie(t),this.observer=new oe(t),this.init();}view;events;observer;init(){let e=this.view.getContainer();this.ctx.map.getContainer().appendChild(e);}getContainer(){return this.view.getContainer()}destroy(){this.events.remove(),this.observer.remove(),this.view.destroy();}};function St(o){return o.initial?.geometry?o.initial?.geometry:o.modes.initial?o.modes.initial:null}var re=class extends x{mode;break;closedGeometry;constructor(e){super(),this.mode=St(e),this.break=!1,this.closedGeometry=e.initial?.closeGeometry??!1;}getMode=()=>this.mode;setMode=e=>{this.mode=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.break;setBreak=e=>{this.break=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.closedGeometry;setClosedGeometry=e=>{this.closedGeometry=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.closedGeometry});};isPolygon=()=>this.mode==="polygon"&&this.getClosedGeometry();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 ae=class{constructor(e){this.ctx=e;this.#e=this.ctx.map.getCanvasContainer(),this.#e.style.cursor=e.mode.getMode()?E.CROSSHAIR:E.AUTO,this.#t();}#e;set=e=>{this.#e.style.cursor=e;};get=()=>this.#e.style.cursor;handleMouseLeave=A(()=>{let{mouseEvents:e,mode:t}=this.ctx;if(!e.pointMouseDown){if(!t.getMode()){this.set(E.AUTO);return}t.getClosedGeometry()?this.set(E.AUTO):this.set(E.CROSSHAIR);}},10);handleFirstPointMouseEnter=A(()=>{let{store:e}=this.ctx;e.circular.canClose()&&this.set(E.POINTER);},10);#t(){let{mouseEvents:e,mode:t}=this.ctx;e.addObserver(this.#i),t.addObserver(this.#o);}remove(){let{mouseEvents:e,mode:t}=this.ctx;e.removeObserver(this.#i),t.removeObserver(this.#o),this.handleMouseLeave.cancel(),this.handleFirstPointMouseEnter.cancel();}#o=e=>{let{mode:t}=this.ctx;t.getBreak()||e.type==="CLOSED_GEOMETRY_CHANGED"&&e.data||this.set(t.getMode()&&!t.getClosedGeometry()?E.CROSSHAIR:E.AUTO);};#i=e=>{let{mode:t,mouseEvents:i,store:n,options:s}=this.ctx;if(t.getBreak())return;let{type:a,data:p}=e;if(p)switch(a){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":n.circular.isCircular()||this.set(E.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var qe=class{constructor(e,t){this.source=e;this.project=t;}#e=!0;#t=[];#o=[];invalidate=()=>{this.#e=!0;};read=()=>{if(this.#e){let{head:e,isCircular:t}=this.source();this.#t=wt(e,t),this.#o=this.#t.map(i=>this.project(i.val)),this.#e=!1;}return {nodes:this.#t,pixels:this.#o}}},wt=(o,e)=>{let t=[],i=new Set,n=o;for(;n&&!i.has(n);)i.add(n),n.val&&t.push(n),n=n.next;return e&&o?.val&&t.length>1&&t.push(o),t},le=(o,e)=>{let t=null;for(let i=0;i<o.length;i++){let n=o[i];if(!n)continue;let s=Math.hypot(e.x-n.x,e.y-n.y);(!t||s<t.distance)&&(t={index:i,distance:s});}return t},at=(o,e)=>{let t=null;for(let i=0;i<o.length-1;i++){let n=o[i],s=o[i+1];if(!n||!s)continue;let a=s.x-n.x,p=s.y-n.y,u=a*a+p*p,T=u===0?0:((e.x-n.x)*a+(e.y-n.y)*p)/u,M=Math.min(1,Math.max(0,T)),G={x:n.x+a*M,y:n.y+p*M},$e=Math.hypot(e.x-G.x,e.y-G.y);(!t||$e<t.distance)&&(t={index:i,projected:G,t:M,distance:$e});}return t},Tt=2,pe=class{constructor(e){this.ctx=e;this.#e=new qe(()=>({head:e.store.head,isCircular:e.store.circular.isCircular()}),t=>e.map.project(t)),e.store.addObserver(this.#e.invalidate),e.map.on("move",this.#e.invalidate);}#e;remove=()=>{this.ctx.store.removeObserver(this.#e.invalidate),this.ctx.map.off("move",this.#e.invalidate);};#t=(e,t)=>{let{map:i}=this.ctx,n=Math.round((i.unproject([e.x,e.y]).lng-t.lng)/360);if(n===0)return e;let s=i.project(t),a=i.project({lng:t.lng+360,lat:t.lat});return {x:e.x-(a.x-s.x)*n,y:e.y-(a.y-s.y)*n}};hit=e=>{let{nodes:t,pixels:i}=this.#e.read(),n=t[0]?.val;if(!n)return null;let s=this.#t(e,n),a=at(i,s);if(!a||a.distance>this.ctx.options.interaction.lineHitRadius*Tt)return null;let p=t[a.index];if(!p)return null;let u=le(i,s),T=this.ctx.map.unproject([a.projected.x,a.projected.y]);return {segmentStart:p,projected:{lat:T.lat,lng:T.lng},distance:a.distance,vertexDistance:u?u.distance:1/0}};isNearGeometry=e=>{let{nodes:t,pixels:i}=this.#e.read(),n=t[0]?.val;if(!n)return !1;let s=this.#t(e,n),a=le(i,s);if(a&&a.distance<=this.ctx.options.interaction.pointHitRadius)return !0;let p=at(i,s);return p!==null&&p.distance<=this.ctx.options.interaction.lineHitRadius}};var ce=class extends x{#e;#t;#o;#i;#n;#s;#r;#a;#l;#p;#c;#d;constructor(){super(),this.#e=!1,this.#t=!1,this.#o=!1,this.#i=!1,this.#n=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#l=!1,this.#p=!1,this.#c=!1,this.#d=!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.#o}set lastPointMouseClick(e){this.#o=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#i}set lastPointMouseUp(e){this.#i=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.#p}set pointMouseLeave(e){this.#p=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#c}set lineMouseEnter(e){this.#c=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#d}set lineMouseLeave(e){this.#d=e,this.notify({type:"lineMouseLeave",data:e});}};var Ye=o=>o?{lineHitRadius:12,pointHitRadius:20}:{lineHitRadius:7,pointHitRadius:14},m={pointGeneration:"manual",panel:{size:"medium",buttons:{undo:{visible:!1},redo:{visible:!1},delete:{visible:!1},save:{visible:!1,clearOnSave:!0}}},modes:{initial:null,line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{auxiliaryPoint:D,onLinePoint:k,firstPoint:N,points:I,line:R,dynamicLine:J,polygon:F,breakLine:B},interaction:Ye(!1),initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",redo:"Redo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close the line",createPolygon:"Create a polygon",removePoint:"Remove point"}};function At(o){return o.every(e=>"id"in e&&e.id!==void 0)}function Ot(o,e){let t=!e,i=!At(o);if(t&&i)throw new Error(L.MISSING_IDS)}function Nt(o){if(!o.length)throw new Error(L.EMPTY_INITIAL_STATE)}function Dt(o,e){let i=new Set(o.map(n=>`${n.lng},${n.lat}`)).size;if(e&&i<3)throw new Error(L.NOT_ENOUGH_POINTS_TO_CLOSE)}function kt(o){let{closeGeometry:e,steps:t}=o;if(t){let i=t[0]?.lng,n=t[t.length-1]?.lng,s=t[0]?.lat,a=t[t.length-1]?.lat;if((i!==n||s!==a)&&e)throw new Error(L.FIRST_LAST_POINT_NOT_EQUAL)}}function pt(o){let{closeGeometry:e,generateId:t,steps:i}=o;Nt(i),Ot(i,t),Dt(i,e),kt(o);}function ct(o){let e=Ye(lt("(pointer: coarse)")),t=!lt("(hover: none)");return o?{pointGeneration:o.pointGeneration??m.pointGeneration,panel:Rt(o),modes:It(o),layersPaint:Bt(o),interaction:e,initial:o.initial||m.initial,locale:_t(o),dynamicLine:(o.dynamicLine??m.dynamicLine)&&t}:{...m,interaction:e,dynamicLine:t}}var lt=o=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(o).matches:!1;function Rt(o){return {size:o.panel?.size||m.panel.size,buttons:{undo:{visible:o.panel?.buttons?.undo?.visible??m.panel.buttons.undo.visible},redo:{visible:o.panel?.buttons?.redo?.visible??m.panel.buttons.redo.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 It(o){return {initial:o.modes?.initial||m.modes.initial,line:{visible:o?.modes?.line?.visible!==void 0?o.modes.line.visible:o?.initial?.geometry==="line"||m.modes.line.visible,closeGeometry:o?.modes?.line?.closeGeometry??m.modes.line.closeGeometry},polygon:{visible:o?.modes?.polygon?.visible!==void 0?o.modes.polygon.visible:o?.initial?.geometry==="polygon"||m.modes.polygon.visible},breakGeometry:{visible:o?.modes?.breakGeometry?.visible??m.modes.breakGeometry.visible}}}function Bt(o){let e=o.layersPaint,t={"line-width":e?.line?.["line-width"]||R["line-width"],"line-color":e?.line?.["line-color"]||R["line-color"],"line-opacity":e?.line?.["line-opacity"]||R["line-opacity"],...e?.line};return {onLinePoint:{"circle-radius":e?.onLinePoint?.["circle-radius"]||k["circle-radius"],"circle-color":e?.onLinePoint?.["circle-color"]||k["circle-color"],"circle-stroke-color":e?.onLinePoint?.["circle-stroke-color"]||k["circle-stroke-color"],"circle-stroke-width":e?.onLinePoint?.["circle-stroke-width"]||k["circle-stroke-width"],...e?.onLinePoint},firstPoint:{"circle-radius":e?.firstPoint?.["circle-radius"]||N["circle-radius"],"circle-color":e?.firstPoint?.["circle-color"]||N["circle-color"],"circle-stroke-color":e?.firstPoint?.["circle-stroke-color"]||N["circle-stroke-color"],"circle-stroke-width":e?.firstPoint?.["circle-stroke-width"]||N["circle-stroke-width"],...e?.firstPoint},points:{"circle-radius":e?.points?.["circle-radius"]||I["circle-radius"],"circle-color":e?.points?.["circle-color"]||I["circle-color"],"circle-stroke-color":e?.points?.["circle-stroke-color"]||I["circle-stroke-color"],"circle-stroke-width":e?.points?.["circle-stroke-width"]||I["circle-stroke-width"],...e?.points},auxiliaryPoint:{"circle-radius":e?.auxiliaryPoint?.["circle-radius"]||D["circle-radius"],"circle-color":e?.auxiliaryPoint?.["circle-color"]||D["circle-color"],"circle-stroke-color":e?.auxiliaryPoint?.["circle-stroke-color"]||D["circle-stroke-color"],"circle-stroke-width":e?.auxiliaryPoint?.["circle-stroke-width"]||D["circle-stroke-width"],...e?.auxiliaryPoint},line:t,dynamicLine:{...t,"line-dasharray":J["line-dasharray"],...e?.dynamicLine},polygon:{"fill-color":e?.polygon?.["fill-color"]||F["fill-color"],"fill-opacity":e?.polygon?.["fill-opacity"]||F["fill-opacity"],...e?.polygon},breakLine:{"line-width":e?.breakLine?.["line-width"]||B["line-width"],"line-color":e?.breakLine?.["line-color"]||B["line-color"],"line-dasharray":e?.breakLine?.["line-dasharray"]||B["line-dasharray"],...e?.breakLine}}}function _t(o){return {save:o.locale?.save??m.locale.save,delete:o.locale?.delete??m.locale.delete,undo:o.locale?.undo??m.locale.undo,redo:o.locale?.redo??m.locale.redo,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,removePoint:o.locale?.removePoint??m.locale.removePoint}}var de=class{constructor(e,t,i,n,s){this.store=e;this.options=t;this.mode=i;this.current=n;this.clickCoords=s;}type="STORE_BREAK_GEOMETRY";snapshot={originalHead:null,originalTail:null,newHead:null,newTail:null,newAuxBetweenHeadTail:null};makeSnapshot=()=>{this.snapshot.originalHead=this.store.head,this.snapshot.originalTail=this.store.tail,this.snapshot.newAuxBetweenHeadTail=this.current.val?.isAuxiliary?this.current:this.current.next;};execute=()=>{this.makeSnapshot(),this.store.circular.break(this.current),this.mode.setClosedGeometry(!1),this.snapshot.newHead=this.store.head,this.snapshot.newTail=this.store.tail,this.store.notify({type:"STORE_BREAK_GEOMETRY",data:{coords:this.clickCoords}});};restoreOriginalHeadTail=()=>{let{originalHead:e,originalTail:t}=this.snapshot;this.store.head=e,this.store.tail=t,this.store.head&&(this.store.head.prev=this.store.tail),this.store.tail&&(this.store.tail.next=this.store.head);};restoreAuxBetweenNewHeadTail=()=>{let{newHead:e,newTail:t,newAuxBetweenHeadTail:i}=this.snapshot;e&&t&&(t.next=i,i.prev=t,i.next=e,e.prev=i,i?.val&&(this.store.map.set(i?.val.id,i),this.store.size+=1));};undo=()=>{this.restoreOriginalHeadTail(),this.store.circular.close(),this.store.notify({type:"STORE_CLOSE_GEOMETRY"});let{newHead:e,newTail:t}=this.snapshot;e&&t&&(this.options.pointGeneration==="auto"?this.restoreAuxBetweenNewHeadTail():(t.next=e,e.prev=t)),this.mode.setClosedGeometry(!0),this.store.pingConsumers();}};var ue=class{constructor(e){this.ctx=e;this.current=null;}current;renderBreakSegment=C(e=>{this.onLineEnterBreak(e);});initBreakEvents=()=>{this.ctx.map.on("click",r.LineLayer,this.geometryBreakOnClick),this.ctx.map.on("mouseenter",r.LineLayer,this.renderBreakSegment),this.ctx.map.on("mousemove",r.LineLayer,this.renderBreakSegment),this.ctx.map.on("mouseleave",r.LineLayer,this.onLineLeave);};removeBreakEvents=()=>{this.ctx.map.off("click",r.LineLayer,this.geometryBreakOnClick),this.ctx.map.off("mouseenter",r.LineLayer,this.renderBreakSegment),this.ctx.map.off("mousemove",r.LineLayer,this.renderBreakSegment),this.ctx.map.off("mouseleave",r.LineLayer,this.onLineLeave),this.renderBreakSegment.cancel();};hideBreakLine=()=>{this.ctx.map.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&this.ctx.map.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{this.ctx.map.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&this.ctx.map.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};geometryBreakOnClick=e=>{let{store:t,mode:i,map:n,options:s}=this.ctx;this.current&&(h.commit(new de(t,s,i,this.current,e.lngLat)),this.onLineLeave(),i.reset(),f.execute(),d.onLineBreak(n));};getAutoGenerationPoints=e=>{let t=null,i=null;return e?.val?.isAuxiliary?(t=[e?.prev?.val?.lng,e?.prev?.val?.lat],i=[e?.next?.val?.lng,e?.next?.val?.lat]):(t=[e?.val?.lng,e?.val?.lat],i=[e?.next?.next?.val?.lng,e?.next?.next?.val?.lat]),{current:t,next:i}};getLinePoints=e=>{if(this.ctx.options.pointGeneration==="manual"){let t=[e?.val?.lng,e?.val?.lat],i=[e?.next?.val?.lng,e?.next?.val?.lat];return {current:t,next:i}}return this.getAutoGenerationPoints(e)};onLineEnterBreak=e=>{let{map:t}=this.ctx,i=this.ctx.projection.hit(e.point)?.segmentStart??null;i?.val?.id!==this.current?.val?.id&&(this.current=i);let n=t.getSource(c.LineSourceBreak),{current:s,next:a}=this.getLinePoints(this.current),p=Z(s,a);p&&(n.setData(p),this.showBreakLine());};onLineLeave=()=>{this.renderBreakSegment.cancel(),this.hideBreakLine();}};var V=[r.PointsHitLayer,r.FirstPointHitLayer,r.AuxiliaryPointHitLayer],H=(o,e)=>o.target.queryRenderedFeatures(o.point,{layers:e}).some(i=>e.includes(i.layer.id)),w=(o,e)=>Ht(o,e)?.properties.id,Ht=(o,e)=>{let t=o.queryRenderedFeatures(e,{layers:V});if(t.length<2)return t[0];let i=o.unproject(e).lng,n=t.map(a=>{let[p,u]=a.geometry.coordinates;return o.project({lng:p+360*Math.round((i-p)/360),lat:u})}),s=le(n,e);return s?t[s.index]:void 0},dt=(o,e)=>{let t=o.head,i=0,n=new Set;for(;t!==null&&!n.has(t.val?.id);){if(t.val?.id===e)return i;n.add(t.val?.id),i++,t=t.next;}return -1};function he(o){return o.originalEvent.button===2}var me=class{constructor(e,t,i){this.store=e;this.segmentStart=i;this.step={id:b(),isAuxiliary:!1,...t},this.payload={node:this.step};}type="STORE_POINT_INSERTED";payload;step;snapshot={insertedNode:null};restoreInsertedNode=e=>{let t=e.prev,i=e.next;t?t.next=e:this.store.head=e,i?i.prev=e:this.store.tail=e,this.store.tail===t&&this.store.head===i&&(this.store.tail=e,this.store.head&&(this.store.head.prev=e)),e.val&&!this.store.map.has(e.val.id)&&(this.store.map.set(e.val.id,e),this.store.size++,this.store.pingConsumers());};execute=()=>{this.snapshot.insertedNode?this.restoreInsertedNode(this.snapshot.insertedNode):this.snapshot.insertedNode=this.store.insertAfter(this.segmentStart,this.step),this.store.notify({type:"STORE_POINT_INSERTED"});};undo=()=>{this.store.removeNodeById(this.step.id);}};var ut=(o,e)=>{let{store:t,options:i,projection:n}=e,s=n.hit(o.point);if(!s||s.vertexDistance<i.interaction.pointHitRadius)return null;let a={...s.projected,isAuxiliary:!1,id:b()};return h.commit(new me(t,a,s.segmentStart)),a},ht=(o,e)=>{let{store:t}=e;t.tail?.val&&(y.setSinglePointHidden(o),f.execute());},mt=o=>H(o,V),vt=o=>{let e=o.getSource(c.LineDynamicSource);e&&e.setData(Xe),o.getLayer(r.LineDynamicLayer)&&o.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};var ve=class{constructor(e){this.ctx=e;this.visible=!0,this.onStoreEventsDebounced=A(this.onStoreEventsConsumer,10),this.initConsumers(),this.initDynamicEvents();}visible;firstPoint=null;secondPoint=null;pointer=null;lineFeature;subscriptions=[];onStoreEventsDebounced;renderFreeEnd=C(e=>{this.renderLineOnMouseMove(e.lngLat);});initConsumers(){this.ctx.store.addObserver(this.onStoreEventsDebounced),this.ctx.mouseEvents.addObserver(this.onMouseEventsConsumer),this.ctx.mode.addObserver(this.mapModeConsumer);}removeConsumers=()=>{this.ctx.store.removeObserver(this.onStoreEventsDebounced),this.onStoreEventsDebounced.cancel(),this.ctx.mouseEvents.removeObserver(this.onMouseEventsConsumer),this.ctx.mode.removeObserver(this.mapModeConsumer);};mapModeConsumer=e=>{e.type==="MODE_CHANGED"&&!e.data&&this.hide();};onMouseEventsConsumer=e=>{let{store:t}=this.ctx;if(this.ctx.mode.getMode()===null)return;if(t.circular.isCircular()){this.hide();return}if(e.type==="lastPointMouseClick"&&e.data&&(this.hide(),this.visible=!1),!this.visible)return;if(["pointMouseEnter","lineMouseEnter","pointMouseDown"].includes(e.type)&&e.data&&this.hide(),e.type==="pointMouseLeave"||e.type==="lineMouseLeave"){let{store:n}=this.ctx;if(n.circular.isCircular())return;e.data&&(this.firstPoint=n.tail?.val,this.secondPoint=n.tail?.val,this.show());}};onStoreEventsConsumer=e=>{let{store:t}=this.ctx;if(this.ctx.mode.getMode()!==null){if(t.circular.isCircular()){this.hide();return}if(e.type==="STORE_CLOSE_GEOMETRY"||e.type==="STORE_CLEARED")this.hide();else if(e.type==="STORE_BREAK_GEOMETRY")this.firstPoint=t.tail?.val,this.secondPoint=e.data?.coords,this.show(),this.visible=!0;else if(e.type==="STORE_POINT_ADD")t.size>0&&(this.firstPoint=t.tail?.val,this.secondPoint=this.freeEnd(),this.show(),this.visible=!0);else if(e.type==="STORE_MUTATED"){if(this.ctx.mouseEvents.pointMouseDown||t.size===0||(this.firstPoint=t.tail?.val,this.ctx.mouseEvents.pointMouseEnter))return;this.secondPoint=this.freeEnd(),this.show(),this.visible=!0;}}};initDynamicEvents=()=>{let{map:e,events:t}=this.ctx;e.on("click",this.onMapClick),e.on("mousemove",this.renderFreeEnd),this.subscriptions=[t.on("mdl:removeall",this.hide),t.on("mdl:undo",this.onUndoRedoClick),t.on("mdl:redo",this.onUndoRedoClick),t.on("mdl:pointremove",this.onPointRemove)],l.addEventListener(e.getContainer(),"pointermove",this.onPointerMove);};removeEvents=()=>{let{map:e}=this.ctx;e.off("click",this.onMapClick),e.off("mousemove",this.renderFreeEnd),this.renderFreeEnd.cancel();for(let t of this.subscriptions)t.unsubscribe();this.subscriptions=[],l.removeEventListener(e.getContainer(),"pointermove",this.onPointerMove);};hide=()=>{let{map:e}=this.ctx;this.firstPoint=null,this.secondPoint=null,this.lineFeature=null,e.off("mousemove",this.renderFreeEnd),this.renderFreeEnd.cancel(),vt(e);};show=()=>{let{map:e,store:t}=this.ctx;if(t.size&&this.firstPoint?.lat&&this.firstPoint.lng&&this.secondPoint?.lng&&this.secondPoint?.lat){let i=[this.firstPoint.lng,this.firstPoint.lat],n=[this.secondPoint.lng,this.secondPoint.lat];this.lineFeature=Z(i,n),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.secondPoint&&this.renderLineOnMouseMove({lng:this.secondPoint?.lng,lat:this.secondPoint?.lat});}e.on("mousemove",this.renderFreeEnd);};renderLineOnMouseMove=e=>{if(!this.lineFeature)return;let{map:t}=this.ctx;this.lineFeature.features[0].geometry.coordinates[1]=[e.lng,e.lat];let i=t.getSource(c.LineDynamicSource);i&&i.setData(this.lineFeature);};onPointerMove=e=>{let{map:t}=this.ctx,{clientX:i,clientY:n}=e,s=t.getContainer().getBoundingClientRect(),a=t.unproject([i-s.left,n-s.top]);this.pointer={lng:a.lng,lat:a.lat};};freeEnd=()=>{let{store:e}=this.ctx;return this.pointer??e.tail?.val};onMapClick=e=>{let{mode:t}=this.ctx,i=H(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.secondPoint={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hide();};onUndoRedoClick=()=>{let{store:e}=this.ctx;e.circular.isCircular()||(this.firstPoint=e.tail?.val,this.secondPoint=this.freeEnd(),this.show()),e.size===0&&this.hide();};onPointRemove=()=>{let{store:e}=this.ctx;e.circular.isCircular()||(this.firstPoint=e.tail?.val,this.secondPoint=this.freeEnd(),this.show()),e.size===0&&this.hide();}};var fe=class{constructor(e){this.ctx=e;this.initConsumers();}eventsInited=!1;initConsumers=()=>{this.ctx.mode.addObserver(this.mapModeConsumer);};removeConsumers=()=>{this.ctx.mode.removeObserver(this.mapModeConsumer);};mapModeConsumer=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&!i?this.eventsInited&&this.removeEvents():t==="MODE_CHANGED"&&i&&(this.eventsInited||this.initEvents());};initEvents(){this.eventsInited||(this.ctx.map.on("click",r.LineLayerTransparent,this.onLineClick),this.ctx.map.on("mousemove",r.LineLayerTransparent,this.onLineMove),this.ctx.map.on("mouseenter",r.LineLayerTransparent,this.onLineEnter),this.ctx.map.on("mouseleave",r.LineLayerTransparent,this.onLineLeave),this.eventsInited=!0);}removeEvents(){this.ctx.map.off("click",r.LineLayerTransparent,this.onLineClick),this.ctx.map.off("mousemove",r.LineLayerTransparent,this.onLineMove),this.ctx.map.off("mouseenter",r.LineLayerTransparent,this.onLineEnter),this.ctx.map.off("mouseleave",r.LineLayerTransparent,this.onLineLeave),this.renderGhostPoint.cancel(),this.eventsInited=!1;}onLineClick=e=>{let{store:t,map:i,mode:n}=this.ctx;if(mt(e))return;let s=ut(e,this.ctx);s&&(ht(e,this.ctx),d.addPoint({...s,total:t.size},i,n));};hitClearOfVertices=e=>{let t=this.ctx.projection.hit(e.point);return !t||t.vertexDistance<this.ctx.options.interaction.pointHitRadius?null:t};processMouseMove=e=>{let t=this.hitClearOfVertices(e);if(!t){y.setSinglePointHidden(e);return}if(y.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)){let n=e.target.getSource(c.SinglePointSource);n&&n.setData({type:"Feature",geometry:{type:"Point",coordinates:[t.projected.lng,t.projected.lat]},properties:{}});}};onLineMove=e=>{this.ctx.mouseEvents.pointMouseDown||this.ctx.mouseEvents.pointMouseEnter||this.renderGhostPoint(e);};renderGhostPoint=C(e=>{this.processMouseMove(e);});onLineEnter=e=>{this.ctx.mouseEvents.pointMouseDown||this.ctx.mouseEvents.pointMouseEnter||this.hitClearOfVertices(e)&&(this.ctx.mouseEvents.lineMouseEnter=!0,y.setSinglePointVisible(e));};onLineLeave=e=>{this.renderGhostPoint.cancel(),!(this.ctx.mouseEvents.pointMouseDown||this.ctx.mouseEvents.pointMouseEnter)&&(this.ctx.mouseEvents.lineMouseLeave=!0,y.setSinglePointHidden(e));}};var ye=class{constructor(e){this.ctx=e;this.break=new ue(e),this.transparent=e.options.pointGeneration==="manual"?new fe(e):null,this.dynamic=null,this.type="default";}break;transparent;dynamic;type;init(){this.initDynamicLine(),this.initEvents(),this.initConsumers();}initDynamicLine=()=>{this.ctx.options.dynamicLine&&(this.dynamic=new ve(this.ctx));};initEvents(){!this.ctx.mode.getBreak()&&this.transparent?.initEvents();}initConsumers(){this.ctx.mode.addObserver(this.mapModeConsumer),this.ctx.mouseEvents.addObserver(this.mouseEventsConsumer);}remove(){this.removeConsumers(),this.removeEvents();}removeConsumers(){this.ctx.mode.removeObserver(this.mapModeConsumer),this.ctx.mouseEvents.removeObserver(this.mouseEventsConsumer),this.transparent?.removeConsumers(),this.ctx.options.dynamicLine&&this.dynamic?.removeConsumers();}removeEvents(){this.break.removeBreakEvents(),this.transparent?.removeEvents(),this.ctx.options.dynamicLine&&(this.dynamic?.removeEvents(),this.dynamic?.hide());}mouseEventsConsumer=e=>{let{type:t,data:i}=e,{mode:n}=this.ctx;if(!(!i||!n.getBreak()||n.getMode()===null))switch(t){case"pointMouseDown":this.break.removeBreakEvents(),this.break.hideBreakLine();break;case"pointMouseUp":this.break.initBreakEvents();break;}};mapModeConsumer=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.type==="break"&&(this.break.removeBreakEvents(),i&&this.transparent?.initEvents(),this.type="default"),t==="BREAK_CHANGED"&&i&&this.type==="default"&&(this.transparent?.removeEvents(),this.break.initBreakEvents(),this.type="break");}};var Gt=(o,e)=>{let t=e?.["circle-radius"];o.setPaintProperty(r.FirstPointLayer,"circle-radius",typeof t=="number"?t+1:t??O.large),o.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",K.large);},Ft=(o,e)=>{o.setPaintProperty(r.FirstPointLayer,"circle-radius",e?.["circle-radius"]??O.default),o.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",e?.["circle-stroke-color"]??K.default);},je=(o,e,t)=>{e==="large"?Gt(o,t):Ft(o,t);};var Ee=class{constructor(e,t,i){this.store=e;this.mode=t;this.options=i;this.type="STORE_CLOSE_GEOMETRY";}type="STORE_CLOSE_GEOMETRY";auxPointSnapshot=null;restoreAuxPoint=()=>{this.auxPointSnapshot?.val&&(this.store.head.prev=this.auxPointSnapshot,this.store.tail.next=this.auxPointSnapshot,this.auxPointSnapshot.prev=this.store.tail,this.auxPointSnapshot.next=this.store.head,this.store.tail=this.auxPointSnapshot,this.store.map.set(this.auxPointSnapshot.val.id,this.auxPointSnapshot),this.store.size++,this.store.pingConsumers());};execute=()=>{if(this.options.pointGeneration==="auto"&&this.store.tail?.val)if(this.auxPointSnapshot)this.restoreAuxPoint();else {let e=v.createAuxiliaryPoint(this.store.tail?.val,this.store.head?.val);this.auxPointSnapshot=this.store.push(e);}this.store.circular.close(),this.mode.setClosedGeometry(!0),this.store.notify({type:this.type});};undo=()=>{this.options.pointGeneration==="auto"&&this.store.removeNodeById(this.store.tail?.val?.id),this.store.tail?.val&&this.store.head?.val&&(this.store.tail.next=null,this.store.head.prev=null),this.mode.setClosedGeometry(!1),this.store.notify({type:"STORE_BREAK_GEOMETRY"});}};var ge=class{constructor(e,t){this.ctx=e;this.baseEvents=t;this.mouseDown=!1,this.tooltip=new S,this.initLayer(),this.init();}mouseDown;tooltip;eventsInited=!1;initConsumers=()=>{let{mode:e,store:t}=this.ctx;e.addObserver(this.onMapModeChangeConsumer),t.addObserver(this.onStoreChangeConsumer);};removeConsumers=()=>{let{mode:e,store:t}=this.ctx;e.removeObserver(this.onMapModeChangeConsumer),t.removeObserver(this.onStoreChangeConsumer);};initLayer(){let{map:e}=this.ctx;e.getLayer(r.FirstPointLayer)&&y.setFirstPointVisible(e);}initBaseEvents=()=>{let{map:e}=this.ctx;e.on("mouseenter",r.FirstPointHitLayer,this.baseEvents.onPointMouseEnter),e.on("mouseleave",r.FirstPointHitLayer,this.baseEvents.onPointMouseLeave),e.on("mousedown",r.FirstPointHitLayer,this.baseEvents.onPointMouseDown),e.on("touchstart",r.FirstPointHitLayer,this.baseEvents.onPointMouseDown);};initEvents=()=>{let{map:e}=this.ctx;e.on("click",r.FirstPointHitLayer,this.onFirstPointClick),e.on("mouseenter",r.FirstPointHitLayer,this.onFirstPointMouseEnter),e.on("mouseleave",r.FirstPointHitLayer,this.onFirstPointMouseLeave),e.on("mousedown",r.FirstPointHitLayer,this.onFirstPointMouseDown),e.on("mouseup",this.onFirstPointMouseUp),this.initBaseEvents(),this.eventsInited=!0;};init(){this.initEvents(),this.initConsumers();}removeBaseEvents=()=>{let{map:e}=this.ctx;e.off("mouseenter",r.FirstPointHitLayer,this.baseEvents.onPointMouseEnter),e.off("mouseleave",r.FirstPointHitLayer,this.baseEvents.onPointMouseLeave),e.off("mousedown",r.FirstPointHitLayer,this.baseEvents.onPointMouseDown),e.off("touchstart",r.FirstPointHitLayer,this.baseEvents.onPointMouseDown);};removeEvents(){let{map:e}=this.ctx;e.off("click",r.FirstPointHitLayer,this.onFirstPointClick),e.off("mouseenter",r.FirstPointHitLayer,this.onFirstPointMouseEnter),e.off("mouseleave",r.FirstPointHitLayer,this.onFirstPointMouseLeave),e.off("mousedown",r.FirstPointHitLayer,this.onFirstPointMouseDown),e.off("mouseup",this.onFirstPointMouseUp),this.removeBaseEvents(),this.eventsInited=!1;}remove(){this.removeEvents(),this.removeConsumers();}onMapModeChangeConsumer=e=>{let{map:t,options:i}=this.ctx,{type:n,data:s}=e;n==="MODE_CHANGED"&&!s?this.eventsInited&&this.removeEvents():n==="MODE_CHANGED"&&s&&(this.eventsInited||this.initEvents()),n==="MODE_CHANGED"&&(s==="line"&&!i.modes.line.closeGeometry?(y.setFirstPointHidden(t),Ue.closedGeometry(t)):(y.setFirstPointVisible(t),Ue.default(t)));};onStoreChangeConsumer=e=>{let{map:t,store:i}=this.ctx,{type:n}=e;if(["STORE_MUTATED","STORE_POINT_INSERTED","STORE_CLOSE_GEOMETRY","STORE_BREAK_GEOMETRY","STORE_CLEARED"].includes(n)){let a=this.ctx.options.layersPaint.firstPoint;i.circular.canClose()?je(t,"large",a):je(t,"default",a);}};onFirstPointClick=()=>{let{store:e,mode:t,options:i}=this.ctx;e.circular.canClose()&&(h.commit(new Ee(e,t,i)),f.execute());};onFirstPointMouseDown=()=>{this.mouseDown=!0,this.tooltip.remove();};onFirstPointMouseUp=()=>{this.mouseDown=!1;};onFirstPointMouseLeave=()=>{let{mouseEvents:e}=this.ctx;this.mouseDown||(e.firstPointMouseLeave=!0,this.tooltip.remove());};getTitle=()=>{let{mode:e,options:t}=this.ctx;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};onFirstPointMouseEnter=e=>{let{mode:t,mouseEvents:i,store:n}=this.ctx;if(i.firstPointMouseEnter=!0,!(t.getClosedGeometry()||this.mouseDown)&&n.circular.canClose()){let{x:s,y:a}=e.originalEvent;if(s&&a){this.tooltip.create({label:this.getTitle(),placement:"bottom"});let u=this.tooltip.label?this.tooltip.label.clientWidth/2:0;this.tooltip.setPosition({x:s-u,y:a+14});}}}};var Ut=3,zt=[r.LineLayerTransparent,r.PointsHitLayer,r.FirstPointHitLayer,r.AuxiliaryPointHitLayer],Le=class{constructor(e){this.map=e;}pressPoint=null;saved=null;press=e=>{this.pressPoint={x:e.x,y:e.y};};move=e=>{!this.pressPoint||this.saved||Math.hypot(e.x-this.pressPoint.x,e.y-this.pressPoint.y)<=Ut||this.hide();};release=()=>{if(this.pressPoint=null,!!this.saved){for(let[e,t]of this.saved)this.map.getLayer(e)&&this.map.setLayoutProperty(e,"visibility",t);this.saved=null;}};hide(){this.saved=new Map;for(let e of zt){if(!this.map.getLayer(e))continue;let t=this.map.getLayoutProperty(e,"visibility")??"visible";this.saved.set(e,t),this.map.setLayoutProperty(e,"visibility","none");}}};var xe=class{constructor(e,t){this.store=e;this.clickedNode=t;this.snapshot=this.makeSnapshot(this.clickedNode);}type="STORE_AUX_TO_PRIMARY";snapshot=null;makeSnapshot(e){let t=e.prev,i=e.next;return {clickedNode:e,prevPrimaryNode:t,nextPrimaryNode:i,prevAuxNode:null,nextAuxNode:null}}restorePreviousAux=e=>{if(!this.snapshot)return;let{prevPrimaryNode:t,prevAuxNode:i}=this.snapshot;t&&(t.next=i),i&&(i.prev=t),e.prev=i,i&&(i.next=e),i?.val?.id&&!this.store.map.has(i.val.id)&&(this.store.map.set(i?.val?.id,i),this.store.size++);};restoreNextAux=e=>{if(!this.snapshot)return;let{nextPrimaryNode:t,nextAuxNode:i}=this.snapshot;if(e.next=i,i&&(i.prev=e,i.next=t),t&&(t.prev=i),e.next?.next===this.store.head){let s=e.next;this.store.tail=s,this.store.head&&(this.store.head.prev=s),this.store.tail&&(this.store.tail.next=this.store.head);}i?.val?.id&&(this.store.map.set(i.val?.id,i),this.store.size++);};addTwoAuxiliaryPoints=e=>{if(!this.snapshot)return;let{nextPrimaryNode:t,prevPrimaryNode:i}=this.snapshot;if(i)if(this.snapshot.prevAuxNode)this.restorePreviousAux(e);else {let n=v.createAuxiliaryPoint(i.val,e.val);this.snapshot.prevAuxNode=this.store.insertAfter(i,n);}if(t)if(this.snapshot.nextAuxNode)this.restoreNextAux(e);else {let n=v.createAuxiliaryPoint(e.val,t.val);this.snapshot.nextAuxNode=this.store.insertAfter(e,n);}};execute=()=>{if(!this.snapshot)return;let{clickedNode:e}=this.snapshot;e&&e.val&&(e.val.isAuxiliary=!1,this.addTwoAuxiliaryPoints(e));};removeTwoAuxiliaryPoints=e=>{if(!e||!this.snapshot)return;let{prevAuxNode:t,nextAuxNode:i}=this.snapshot;t?.val?.isAuxiliary&&this.store.removeNodeById(t.val?.id),i?.val?.isAuxiliary&&this.store.removeNodeById(i?.val.id);};undo=()=>{if(!this.snapshot)return;let{clickedNode:e}=this.snapshot;e&&e.val&&(e.val.isAuxiliary=!0,this.removeTwoAuxiliaryPoints(e));}};var be=class{constructor(e,t){this.ctx=e;this.baseEvents=t;this.initEvents(),this.initConsumers();}eventsInited=!1;initBaseEvents=()=>{let{map:e}=this.ctx;e.on("mouseenter",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseEnter),e.on("mouseleave",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseLeave),e.on("mousedown",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseDown),e.on("touchstart",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseDown);};removeBaseEvents=()=>{let{map:e}=this.ctx;e.off("mouseenter",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseEnter),e.off("mouseleave",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseLeave),e.off("mousedown",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseDown),e.off("touchstart",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseDown);};initConsumers=()=>{this.ctx.mode.addObserver(this.onMapModeChangeConsumer);};removeConsumers=()=>{this.ctx.mode.removeObserver(this.onMapModeChangeConsumer);};onMapModeChangeConsumer=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&!i?this.eventsInited&&this.removeEvents():t==="MODE_CHANGED"&&i&&(this.eventsInited||this.initEvents());};initEvents(){let{map:e}=this.ctx;e.on("mousedown",r.AuxiliaryPointHitLayer,this.onMouseDown),e.on("touchstart",r.AuxiliaryPointHitLayer,this.onMouseDown),this.initBaseEvents(),this.eventsInited=!0;}removeEvents(){let{map:e}=this.ctx;e.off("mousedown",r.AuxiliaryPointHitLayer,this.onMouseDown),e.off("touchstart",r.AuxiliaryPointHitLayer,this.onMouseDown),this.removeBaseEvents(),this.eventsInited=!1;}onMouseDown=e=>{let{store:t,map:i}=this.ctx;if(he(e))return;let n=w(i,e.point),s=t.findNodeById(n);s&&(h.beginTransaction("PointCompound"),h.commit(new xe(t,s)),f.execute());}};var Ce=class{selectedNode=null;selectedIdx=null;startCoordinates=null;enteredStep=null;lastEvent=null;moved=!1;getSelectedNode(){return this.selectedNode}isMoved(){return this.moved}getSelectedIdx(){return this.selectedIdx}getStartCoordinates(){return this.startCoordinates}getEnteredStep(){return this.enteredStep}getLastEvent(){return this.lastEvent}setSelectedNode(e){this.selectedNode=e;}setSelectedIdx(e){this.selectedIdx=e;}setStartCoordinates(e){this.startCoordinates=e;}setEnteredStep(e){this.enteredStep=e;}setLastEvent(e){this.lastEvent=e;}setMoved(e){this.moved=e;}clearLastEvent(){this.lastEvent=null;}reset(){this.selectedNode=null,this.selectedIdx=null,this.startCoordinates=null,this.enteredStep=null,this.lastEvent=null,this.moved=!1;}partialReset(){this.selectedNode=null,this.selectedIdx=null,this.startCoordinates=null,this.lastEvent=null,this.moved=!1;}};var Pe=class{constructor(e,t,i){this.store=e;this.options=t;this.step={id:b(),isAuxiliary:!1,...i};}type="STORE_MUTATED";snapshot={addedNode:null,auxNode:null};step;restoreAddedNode=e=>{e.prev?e.prev.next=e:this.store.head=e,e.next?e.next.prev=e:this.store.tail=e,this.snapshot.addedNode=e,e.val&&(this.store.map.set(e.val.id,e),this.store.size++,this.store.pingConsumers());};restoreAuxNode=e=>{e.prev?e.prev.next=e:this.store.head=e,e.next?e.next.prev=e:this.store.tail=e,this.snapshot.auxNode=e,e.val&&(this.store.map.set(e.val.id,e),this.store.size++,this.store.pingConsumers());};execute=()=>{if(this.snapshot.addedNode?this.restoreAddedNode(this.snapshot.addedNode):this.snapshot.addedNode=this.store.push(this.step),this.options.pointGeneration==="auto"&&this.store.tail?.prev?.val)if(this.snapshot?.auxNode?.val)this.restoreAuxNode(this.snapshot.auxNode);else {let e=v.createAuxiliaryPoint(this.store.tail?.val,this.store.tail?.prev?.val);this.snapshot.auxNode=this.store.insertAfter(this.store.tail.prev,e);}this.store.notify({type:"STORE_POINT_ADD"});};undo=()=>{this.store.removeNodeById(this.step.id),this.options.pointGeneration==="auto"&&this?.snapshot.auxNode?.val&&this.store.removeNodeById(this?.snapshot.auxNode.val.id);};getStep=()=>this.step};var Me=class{constructor(e){this.ctx=e;}type="STORE_INBETWEEN_POINT_REMOVED";snapshot=null;makeSnapshot(e){let{store:t,nodeId:i}=this.ctx,n=t.circular.isCircular(),s=t.head?.val?.id===i,p=(n?t.tail?.prev:t.tail)?.val?.id===i,u=e.prev,T=e.next,M=e.prev?.prev??null,G=e.next?.next??null;return {removedNode:e,wasCircular:n,wasRemovedHead:s,wasRemovedTail:p,beforePrimary:M,afterPrimary:G,beforeAux:u,afterAux:T,newAux:null}}restoreNodeAfter=(e,t)=>{!e||!t||!t.val||(t.prev=e,t.next=e.next,e.next&&(e.next.prev=t),e.next=t,this.ctx.store.map.has(t.val.id)||(this.ctx.store.map.set(t.val.id,t),this.ctx.store.size++,this.ctx.store.pingConsumers()));};recalculateInBetweenRemoved(e){if(!e||!this.snapshot)return;let{store:t}=this.ctx,i=e.prev,n=e.next,s=i?.prev,a=n?.next;i?.val?.isAuxiliary&&t.removeNodeById(i.val.id),n?.val?.isAuxiliary&&t.removeNodeById(n.val.id);let p=t.circular.isCircular()?t.size>=5:t.size>=3;if(s?.val&&a?.val&&p)if(this.snapshot.newAux){let u=t.tail===s&&t.head===s.next;this.restoreNodeAfter(s,this.snapshot.newAux),u&&(t.tail=this.snapshot.newAux);}else {let u=v.createAuxiliaryPoint(s.val,a.val);this.snapshot.newAux=t.insertAfter(s,u);}}breakGeometryIfNeeded=e=>{let{store:t}=e;if(t.circular.canBreak()&&t.circular.isCircular()){if(t.tail?.val?.isAuxiliary){let i=t.tail;if(t.removeNodeById(t.tail.val.id),t.tail=i?.prev,this.snapshot?.newAux)this.restoreNodeAfter(t.head,this.snapshot.newAux);else {let n=v.createAuxiliaryPoint(t.tail?.val,t.head?.val);this.snapshot&&(this.snapshot.newAux=t.insertAfter(t.head,n));}}return t.head&&(t.head.prev=null),t.tail&&(t.tail.next=null),!0}return !1};execute=()=>{let e=this.ctx.store.findNodeById(this.ctx.nodeId),t=e?.val?.isAuxiliary;if(!e||t)return;this.snapshot||(this.snapshot=this.makeSnapshot(e)),this.recalculateInBetweenRemoved(e),this.ctx.store.removeNodeById(this.ctx.nodeId),this.breakGeometryIfNeeded(this.ctx)&&this.ctx.mode.reset(),d.removePoint({...e?.val,total:this.ctx.store.size},this.ctx.map),this.ctx.store.pingConsumers();};restoreRemovedMiddleNode=e=>{if(!this.snapshot||!e.val)return;let{beforePrimary:t,afterPrimary:i,wasCircular:n}=this.snapshot,{store:s,mode:a}=this.ctx;if(t&&(t.next=e,e.prev=t),i&&(e.next=i,i.prev=e),n&&!this.ctx.store.circular.isCircular()){let p=v.createAuxiliaryPoint(s.tail?.val,s.head?.val);s.push(p),s.circular.close(),a.setClosedGeometry(!0);}};restoreRemovedHeadNode=e=>{if(!this.snapshot||!e?.val)return;let{wasCircular:t}=this.snapshot,{store:i,mode:n}=this.ctx,s=this.ctx.store.head;s?(e.next=s,s.prev=e):i.tail=e,i.head=e;let a=!i.circular.isCircular();t&&a&&(i.circular.close(),n.setClosedGeometry(!0));};restoreRemovedTailNode=e=>{let{store:t,mode:i}=this.ctx;if(!this.snapshot)return;let{wasCircular:n}=this.snapshot,s=t.tail;s&&(s.next=e,e.prev=s,t.tail=e);let a=!t.circular.isCircular();n&&a&&(t.circular.close(),i.setClosedGeometry(!0));};restoreAuxiliaryPoints(e){this.snapshot&&(e.prev?.val&&e.val&&this.snapshot?.beforeAux&&(this.restoreNodeAfter(e.prev,this.snapshot?.beforeAux),this.snapshot.wasRemovedHead&&this.snapshot.wasCircular&&(this.ctx.store.tail=this.snapshot.beforeAux)),e.next?.val&&e.val&&this.snapshot?.afterAux&&(this.restoreNodeAfter(e,this.snapshot?.afterAux),this.snapshot.wasRemovedTail&&this.snapshot.wasCircular&&(this.ctx.store.tail=this.snapshot.afterAux)),this.snapshot.wasCircular&&this.ctx.store.circular.close());}undo=()=>{let{store:e}=this.ctx;if(!this.snapshot)return;let{removedNode:t,wasRemovedHead:i,wasRemovedTail:n,wasCircular:s}=this.snapshot;t?.val&&(i?(e.removeNodeById(e.head?.prev?.val?.id),this.restoreRemovedHeadNode(t)):n?(this.restoreRemovedTailNode(t),s&&e.tail?.prev?.val?.isAuxiliary&&e.removeNodeById(e.tail?.prev?.val?.id)):(this.snapshot.newAux?.val?.id&&e.removeNodeById(this.snapshot.newAux?.val?.id),this.restoreRemovedMiddleNode(t)),e.map.has(this.ctx.nodeId)||(e.map.set(this.ctx.nodeId,t),e.size++),this.restoreAuxiliaryPoints(t),e.pingConsumers());}};var Se=class{constructor(e){this.ctx=e;}type="STORE_INBETWEEN_POINT_REMOVED";snapshot=null;makeSnapshot(e){let t=this.ctx.store.head?.val?.id===this.ctx.nodeId,i=this.ctx.store.tail?.val?.id===this.ctx.nodeId,n=this.ctx.store.circular.isCircular();return {removedNode:e,wasCircular:n,wasRemovedHead:t,wasRemovedTail:i}}breakGeometryIfNeeded=e=>{let{store:t}=e;return t.circular.canBreak()&&t.circular.isCircular()?(t.head&&(t.head.prev=null),t.tail&&(t.tail.next=null),!0):!1};execute=()=>{let e=this.ctx.store.findNodeById(this.ctx.nodeId);if(!e?.val)return;this.snapshot=this.makeSnapshot(e),this.ctx.store.removeNodeById(this.ctx.nodeId),this.breakGeometryIfNeeded(this.ctx)&&this.ctx.mode.reset(),d.removePoint({...e?.val,total:this.ctx.store.size},this.ctx.map),this.ctx.store.pingConsumers();};closeGeometryIfNeeded=()=>{let{store:e,mode:t}=this.ctx,i=!this.ctx.store.circular.isCircular();this.snapshot?.wasCircular&&i&&(e.circular.close(),t.setClosedGeometry(!0));};restoreRemovedMiddleNode=e=>{if(!e?.val)return;let{prev:t,next:i}=e;t?(t.next=e,e.prev=t):this.ctx.store.head=e,i?(i.prev=e,e.next=i):this.ctx.store.tail=e;};restoreRemovedHeadNode=e=>{let t=this.ctx.store.head;e?.val&&(t?(e.next=t,t.prev=e):this.ctx.store.tail=e,this.ctx.store.head=e);};restoreRemovedTailNode=e=>{let t=this.ctx.store.tail;t&&(t.next=e,e.prev=t),this.ctx.store.tail=e;};undo=()=>{if(!this.snapshot)return;let{removedNode:e,wasRemovedHead:t,wasRemovedTail:i}=this.snapshot;t?this.restoreRemovedHeadNode(e):i?this.restoreRemovedTailNode(e):this.restoreRemovedMiddleNode(e),this.closeGeometryIfNeeded(),this.ctx.store.map.has(this.ctx.nodeId)||(this.ctx.store.map.set(this.ctx.nodeId,e),this.ctx.store.size++),this.ctx.store.pingConsumers();}};var we=class{constructor(e){this.ctx=e;this.manualPointRemove=new Se(this.ctx),this.autoPointRemove=new Me(this.ctx);}type="STORE_INBETWEEN_POINT_REMOVED";manualPointRemove=null;autoPointRemove=null;execute=()=>{this.ctx.options.pointGeneration==="auto"?this.autoPointRemove?.execute():this.manualPointRemove?.execute();};undo=()=>{this.ctx.options.pointGeneration==="auto"?this.autoPointRemove?.undo():this.manualPointRemove?.undo();}};var Te=class{constructor(e,t){this.ctx=e;this.state=t;}updateMainPoint(e,t){e.val&&(e.val.lat=t.lngLat.lat,e.val.lng=t.lngLat.lng);}updateAuxiliaryPoints(e,t){let i=this.getAuxPointsLatLng(t);i&&(this.updatePrevAuxPoint(e,i.prev),this.updateNextAuxPoint(e,i.next));}updatePrevAuxPoint(e,t){e.prev?.val&&t&&(e.prev.val.lat=t.lat,e.prev.val.lng=t.lng);}updateNextAuxPoint(e,t){e.next?.val&&t&&(e.next.val.lat=t.lat,e.next.val.lng=t.lng);}updateStore=()=>{let e=this.state.getLastEvent(),t=this.state.getSelectedNode();!e||!t?.val||(this.updateMainPoint(t,e),this.updateAuxiliaryPoints(t,e));};getAuxPointsLatLng=e=>{let t=this.state.getSelectedNode();if(!t)return null;let{options:i}=this.ctx,n=t?.prev?.prev,s=t?.next?.next;return i.pointGeneration==="auto"?{next:s?.val?v.getMidpoint(s.val,e.lngLat):null,prev:n?.val?v.getMidpoint(e.lngLat,n.val):null}:null};addPoint(e){let{store:t,options:i}=this.ctx,n=new Pe(t,i,e.lngLat);return h.commit(n),n.getStep()}removePoint(e){let{store:t,options:i,mode:n,map:s}=this.ctx;h.commit(new we({store:t,options:i,mode:n,map:s,nodeId:e}));}};var Ae=class{constructor(e,t,i,n){this.store=e;this.selectedNode=t;this.start=i;this.map=n;this.end={lat:t.val.lat,lng:t.val.lng};}type="STORE_POINT_MOVED";end;updateNeighbors=e=>{let t=e.prev,i=e.next;if(!t?.val?.isAuxiliary&&!i?.val?.isAuxiliary)return;let n=e.prev?.prev,s=e.next?.next;if(n?.val&&this.selectedNode?.val&&t){let a=v.getMidpoint(this.selectedNode?.val,n?.val);t.val&&(t.val.lat=a.lat,t.val.lng=a.lng);}if(s?.val&&this.selectedNode?.val&&i){let a=v.getMidpoint(this.selectedNode?.val,s?.val);i.val&&(i.val.lat=a.lat,i.val.lng=a.lng);}};execute=()=>{if(!this.selectedNode.val)return;let e=this.store.findStepById(this.selectedNode.val?.id);e&&(e.lat=this.end.lat,e.lng=this.end.lng,this.updateNeighbors(this.selectedNode),this.store.notify({type:"STORE_MUTATED",data:this.store}),d.movePoint({id:this.selectedNode.val.id,total:this.store.size,end:{lat:this.selectedNode.val.lat,lng:this.selectedNode.val.lng},start:this.start},this.map));};undo=()=>{if(!this.selectedNode.val)return;let e=this.store.findStepById(this.selectedNode.val?.id);e&&(e.lat=this.start.lat,e.lng=this.start.lng,this.updateNeighbors(this.selectedNode),this.store.notify({type:"STORE_MUTATED",data:this.store}),d.movePoint({id:this.selectedNode.val.id,total:this.store.size,end:this.start,start:this.end},this.map));}};var Vt="mdl-point-remove",Ke="hidden",Oe=class{button;constructor(e,t){this.button=l.create("button",`${Vt} ${Ke}`,e),this.button.type="button",this.button.setAttribute("data-type","remove-point"),this.button.setAttribute("aria-label",t);}getElement=()=>this.button;getWidth=()=>this.button.offsetWidth;setPosition=(e,t,i)=>{let n=i==="right"?"0, -50%":"-100%, -50%";this.button.style.transform=`translate(${e}px, ${t}px) translate(${n})`,this.button.dataset.side=i;};show=()=>l.removeClassName(this.button,Ke);hide=()=>l.addClassName(this.button,Ke);destroy=()=>l.remove(this.button)};var Je=12,Ne=class{constructor(e){this.ctx=e;this.view=new Oe(e.map.getContainer(),e.options.locale.removePoint);let t=this.view.getElement();l.addEventListener(t,"mouseleave",this.onButtonMouseLeave),l.addEventListener(t,"click",this.onButtonClick);}view;anchor=null;rafId=0;listenersActive=!1;show=e=>{this.anchor=e,this.enableListeners(),this.updatePosition(),this.view.show();};hide=()=>{this.cancelFrame(),this.disableListeners(),this.anchor=null,this.view.hide();};destroy=()=>{this.hide();let e=this.view.getElement();l.removeEventListener(e,"mouseleave",this.onButtonMouseLeave),l.removeEventListener(e,"click",this.onButtonClick),this.view.destroy();};cancelFrame=()=>{this.rafId&&(window.cancelAnimationFrame(this.rafId),this.rafId=0);};enableListeners=()=>{if(this.listenersActive)return;let{map:e}=this.ctx;e.on("move",this.onMapMove),e.on("zoom",this.onMapMove),l.addEventListener(e.getCanvasContainer(),"pointerdown",this.hide),this.listenersActive=!0;};disableListeners=()=>{if(!this.listenersActive)return;let{map:e}=this.ctx;e.off("move",this.onMapMove),e.off("zoom",this.onMapMove),l.removeEventListener(e.getCanvasContainer(),"pointerdown",this.hide),this.listenersActive=!1;};onMapMove=()=>{this.rafId||(this.rafId=window.requestAnimationFrame(()=>{this.rafId=0,this.updatePosition();}));};updatePosition=()=>{if(!this.anchor)return;let{map:e}=this.ctx,t=e.project({lng:this.anchor.lng,lat:this.anchor.lat}),i=e.getContainer().clientWidth;t.x+Je+this.view.getWidth()>i?this.view.setPosition(t.x-Je,t.y,"left"):this.view.setPosition(t.x+Je,t.y,"right");};onButtonMouseLeave=()=>this.hide();onButtonClick=e=>{e.stopPropagation();let t=this.anchor;this.hide(),t&&this.ctx.onRemove(t.id);}};var De=class{constructor(e){this.ctx=e;this.pointState=new Ce,this.topologyManager=new Te(e,this.pointState),this.dragLayers=new Le(this.ctx.map),this.events={onPointMouseEnter:this.onPointMouseEnter,onPointMouseLeave:this.onPointMouseLeave,onPointMouseDown:this.onPointMouseDown,onMapMouseMove:this.onMapMouseMove},this.firstPoint=new ge(this.ctx,this.events),this.auxPoints=new be(this.ctx,this.events),this.removeButton=new Ne({map:this.ctx.map,options:this.ctx.options,onRemove:this.onPointRemove});}eventsInited=!1;events;firstPoint;auxPoints;pointState;topologyManager;removeButton;dragLayers;pressedStep=null;pressActive=!1;suppressedStepId=null;highlightedStepId=null;pointAdded=null;initConsumers=()=>{this.ctx.mode.addObserver(this.mapModeConsumer),this.ctx.store.addObserver(this.storeEventsConsumer);};removeConsumers=()=>{this.ctx.mode.removeObserver(this.mapModeConsumer),this.ctx.store.removeObserver(this.storeEventsConsumer),this.auxPoints?.removeConsumers();};initEvents=()=>{let{map:e}=this.ctx;e.on("click",this.onMapClick),e.on("dblclick",this.onMapDblClick),e.on("mousemove",this.onPointerHover),l.addEventListener(e.getContainer(),"mouseleave",this.onPointerLeaveMap),this.pointAdded=this.ctx.events.on("mdl:add",this.onPointAdded),e.on("mouseenter",r.PointsHitLayer,this.onPointMouseEnter),e.on("mouseleave",r.PointsHitLayer,this.onPointMouseLeave),e.on("mousedown",r.PointsHitLayer,this.onPointMouseDown),e.on("click",r.PointsHitLayer,this.onPointClick),e.on("touchstart",r.PointsHitLayer,this.onPointMouseDown),this.eventsInited=!0;};init=()=>{this.initEvents(),this.initConsumers();};removeEvents=()=>{let{map:e}=this.ctx;this.highlight(null),e.off("click",this.onMapClick),e.off("dblclick",this.onMapDblClick),e.off("mousemove",this.onPointerHover),l.removeEventListener(e.getContainer(),"mouseleave",this.onPointerLeaveMap),e.off("mousemove",this.onMapMouseMove),this.renderDraggedPoint.cancel(),this.onPointerHover.cancel(),this.dragLayers.release(),this.pointAdded?.unsubscribe(),this.pointAdded=null,e.off("mouseenter",r.PointsHitLayer,this.onPointMouseEnter),e.off("mouseleave",r.PointsHitLayer,this.onPointMouseLeave),e.off("mousedown",r.PointsHitLayer,this.onPointMouseDown),e.off("click",r.PointsHitLayer,this.onPointClick),e.off("touchstart",r.PointsHitLayer,this.onPointMouseDown),this.eventsInited=!1;};unbindPress=()=>{let{map:e}=this.ctx;e.off("mousemove",this.onMapMouseMove),e.off("touchmove",this.onMapMouseMove),e.off("mouseup",this.onPointMouseUp),e.off("touchend",this.onPointMouseUp);};cancelPress=()=>{this.unbindPress(),this.pressActive=!1,this.pressedStep=null,this.pointState.reset();};remove=()=>{this.cancelPress(),this.removeEvents(),this.firstPoint?.remove(),this.auxPoints?.removeEvents(),this.removeConsumers(),this.removeButton.destroy();};onPointClick=e=>{let{mouseEvents:t,store:i,map:n,options:s}=this.ctx,a=w(n,e.point);i.isLastPoint(s,a)&&(t.lastPointMouseClick=!0,t.lastPointMouseUp=!1);};onMapDblClick=e=>{e.preventDefault();};onPointRemove=e=>{let{store:t}=this.ctx;t.findStepById(e)&&(this.topologyManager.removePoint(e),f.execute());};onOwnGeometryClick=e=>H(e,[...V,r.LineLayerTransparent,r.LineLayerBreak])?!0:this.ctx.projection.isNearGeometry(e.point);onMapClick=e=>{let{mode:t,mouseEvents:i,map:n,store:s}=this.ctx;if(t.getClosedGeometry()||this.onOwnGeometryClick(e))return;i.lastPointMouseClick&&(i.lastPointMouseClick=!1),n.getCanvasContainer().style.cursor="grab";let a=this.topologyManager.addPoint(e);d.addPoint({...a,total:s.size},n,t),y.setSinglePointHidden(e),f.execute();};onPointAdded=e=>{this.onPointerHover.cancel(),this.suppressedStepId=e.id;};onMoveLeftClickUp=e=>{e.originalEvent.buttons===0&&this.onPointMouseUp();};onMapMouseMove=e=>{if(!this.ctx.mouseEvents.pointMouseDown)return;let t=e;this.pointState.setLastEvent(t),this.pointState.getSelectedNode()&&(this.onMoveLeftClickUp(t),this.pressActive&&(this.pointState.setMoved(!0),this.dragLayers.move(t.point),this.renderDraggedPoint()));};renderDraggedPoint=C(()=>{let e=this.pointState.getLastEvent(),t=this.pointState.getSelectedIdx();!e||t===null||!this.pointState.getSelectedNode()||f.executeOnMouseMove(t,e.lngLat,this.topologyManager.getAuxPointsLatLng(e));});highlight=e=>{let{map:t}=this.ctx;this.highlightedStepId!==e&&(this.highlightedStepId!==null&&t.removeFeatureState({source:c.UnifiedSource,id:this.highlightedStepId}),this.highlightedStepId=e,e!==null&&t.setFeatureState({source:c.UnifiedSource,id:e},{hover:!0}));};onPointerLeaveMap=()=>{this.onPointerHover.cancel(),this.highlight(null);};onPointerHover=C(e=>{let{mouseEvents:t,map:i,store:n}=this.ctx;if(!this.eventsInited||t.pointMouseDown)return;let s=w(i,e.point);if(this.highlight(s??null),s!==this.suppressedStepId)this.suppressedStepId=null;else if(s){this.removeButton.hide();return}let a=s?n.findStepById(s):null;a&&!a.isAuxiliary?this.removeButton.show(a):this.removeButton.hide();});onPointMouseEnter=e=>{let{mouseEvents:t,map:i,store:n,options:s}=this.ctx;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;y.setSinglePointHidden(e);let a=w(i,e.point);n.isLastPoint(s,a)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let p=n.findStepById(a);if(p){let u=this.pointState.getEnteredStep()?.id===p.id;this.pointState.setEnteredStep(p),u||d.enterPoint(Object.assign({},p,{total:n.size}),i);}};onPointMouseLeave=e=>{let{mouseEvents:t,store:i,map:n,options:s}=this.ctx;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let a=w(n,e.point);i.isLastPoint(s,a)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),d.leavePoint(Object.assign({},this.pointState.getEnteredStep(),{total:i.size}),n),this.pointState.setEnteredStep(null);};dismissButton=()=>{this.suppressedStepId=null,this.removeButton.hide();};storeEventsConsumer=e=>{if(e.type==="STORE_CLEARED"){this.pointState.reset(),this.dismissButton();return}e.type==="STORE_MUTATED"&&e.data?.size===0&&(this.pointState.reset(),this.dismissButton());};mapModeConsumer=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&!i?this.eventsInited&&this.removeEvents():t==="MODE_CHANGED"&&i&&(this.eventsInited||this.initEvents()),(t==="BREAK_CHANGED"||t==="MODE_CHANGED")&&(this.pointState.reset(),this.dismissButton());};hideLastPointPanel=()=>{let{store:e,panel:t,options:i}=this.ctx,n=this.pointState.getSelectedNode();n?.val&&e.isLastPoint(i,n.val.id)&&t.hide();};onPointMouseDown=e=>{e.preventDefault(),this.pointState.clearLastEvent();let{mouseEvents:t,map:i,store:n}=this.ctx;if(he(e))return;this.suppressedStepId=null;let s=w(i,e.point),a=n.findNodeById(s);a&&this.pointState.setSelectedNode(a),this.pressedStep=a?.val??null,this.pressActive=!0,this.dragLayers.press(e.point),this.hideLastPointPanel(),this.pointState.setSelectedIdx(dt(n,s)),t&&(t.pointMouseDown=!0),this.pointState.setStartCoordinates(this.pressedStep?{lat:this.pressedStep.lat,lng:this.pressedStep.lng}:e.lngLat),i.on("mousemove",this.onMapMouseMove),i.on("touchmove",this.onMapMouseMove),i.on("mouseup",this.onPointMouseUp),i.on("touchend",this.onPointMouseUp);};onPointMouseUp=()=>{let{mouseEvents:e,store:t,panel:i,map:n}=this.ctx;if(!this.pressActive)return;this.pressActive=!1,this.unbindPress(),this.renderDraggedPoint.cancel(),e.pointMouseUp=!0;let s=this.pointState.getSelectedNode(),a=this.pointState.getLastEvent(),p=this.pointState.getStartCoordinates();s?.val&&(a&&(this.topologyManager.updateStore(),this.pointState.clearLastEvent()),i?.show(),this.pointState.isMoved()&&h.commit(new Ae(t,s,p,n)),this.pointState.partialReset()),h.commitTransaction(),e&&(e.pointMouseDown=!1),this.dragLayers.release(),f.execute(),this.showButtonForPressedStep();};showButtonForPressedStep=()=>{let{store:e}=this.ctx,t=this.pressedStep;this.pressedStep=null,!(!t||t.isAuxiliary)&&e.findStepById(t.id)&&this.removeButton.show(t);}};var ke=class{constructor(e){this.ctx=e;this.pointEvents=new De(this.ctx),this.lineEvents=new ye(this.ctx),this.initEvents();}pointEvents;lineEvents;initEvents=()=>{this.lineEvents.init(),this.pointEvents?.init();};remove=()=>{this.pointEvents?.remove(),this.lineEvents?.remove(),y.cancelSinglePointHiding();}};var Re=class{constructor(e){this.ctx=e;}init(){this.add(),this.swap(r.LineLayer,r.SinglePointLayer),this.swap(r.LineLayerTransparent,r.SinglePointLayer),this.swap(r.LineLayerTransparent,r.FirstPointLayer),this.swap(r.LineLayerTransparent,r.PointsLayer),this.swap(r.PolygonLayer,r.LineLayer),this.swap(r.PointsHitLayer,r.PointsLayer),this.swap(r.FirstPointHitLayer,r.FirstPointLayer),this.swap(r.AuxiliaryPointHitLayer,r.AuxiliaryPointLayer),this.initConsumers();}initConsumers=()=>{this.ctx.store.addObserver(this.onStoreChange);};removeConsumers=()=>{this.ctx.store.removeObserver(this.onStoreChange);};onStoreChange=A(e=>{if(["STORE_MUTATED","STORE_CLOSE_GEOMETRY","STORE_BREAK_GEOMETRY","STORE_CLEARED"].includes(e.type)){let{map:i,store:n,mode:s}=this.ctx;s.getMode()==="polygon"&&n.circular.isCircular()?i.setLayoutProperty(r.PolygonLayer,"visibility","visible"):i.setLayoutProperty(r.PolygonLayer,"visibility","none");}},10);add=()=>{let e=Qe(this.ctx.options);for(let t of e)this.ctx.map.getLayer(t.id)||this.ctx.map.addLayer(t);};swap=(e,t)=>{let i=this.ctx.map.getLayer(e),n=this.ctx.map.getLayer(t);i&&n&&this.ctx.map.moveLayer(e,t);};removeLayers=()=>{for(let e of Object.values(r))this.ctx.map.getLayer(e)&&this.ctx.map.removeLayer(e);};remove=()=>{this.removeConsumers(),this.onStoreChange.cancel(),this.removeLayers();}};var Ie=class{constructor(e){this.ctx=e;}init(){for(let e of Object.values(c))this.ctx.map.getSource(e)||this.ctx.map.addSource(e,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});}remove(){for(let e of Object.values(c))this.ctx.map.getSource(e)&&this.ctx.map.removeSource(e);}};var Be=class{constructor(e){this.ctx=e;this.sources=new Ie(this.ctx),this.layers=new Re(this.ctx),this.events=new ke(this.ctx),this.init();}sources;layers;events;init=()=>{this.sources.init(),this.layers.init();};remove=()=>{this.events?.remove(),this.layers.remove(),this.sources.remove();}};var _e=class{constructor(e){this.map=e;this.init();}init(){h.addObserver(this.onTimelineEvent);}destroy(){h.removeObserver(this.onTimelineEvent);}onTimelineEvent=e=>{switch(e.type){case"UNDO_STACK_CHANGED":d.onUndoStackChange(this.map,e.data);break;case"REDO_STACK_CHANGED":d.onRedoStackChange(this.map,e.data);break}}};var He=class{listeners=new Map;on=(e,t)=>this.add(e,t,!1);once=(e,t)=>this.add(e,t,!0);off=(e,t)=>{this.listeners.get(e)?.delete(t);};emit=(e,t)=>{let i=this.listeners.get(e);if(i)for(let n of [...i.values()])n.delivered||(n.once&&(n.delivered=!0,i.get(n.listener)===n&&i.delete(n.listener)),n.listener(t));};add(e,t,i){let n=this.listeners.get(e);n||(n=new Map,this.listeners.set(e,n));let s=t;return (!n.get(s)||!i)&&n.set(s,{listener:s,once:i,delivered:!1}),{unsubscribe:()=>this.off(e,t)}}};var We=class o{static#e=null;static#t=!1;container;store;mode;defaultOptions;tiles;panel;control;cursor;mouseEvents;timelineAdapter;projection;events=new He;renderer=null;constructor(e){this.defaultOptions=ct(e),this.defaultOptions.initial&&pt(this.defaultOptions.initial);}onAdd=e=>{if(o.#t)throw new Error(L.REENTRANT_LIFECYCLE);if(o.#e)throw new Error(L.ALREADY_ADDED_TO_MAP);o.#t=!0,o.#e=this;try{let t=e;return d.bind(this.events),this.store=new _(this.defaultOptions),this.mode=new re(this.defaultOptions),this.renderer=f.initialize({map:t,store:this.store,options:this.defaultOptions,mode:this.mode}),this.projection=new pe({map:t,store:this.store,options:this.defaultOptions}),this.mouseEvents=new ce,this.panel=new te({map:t,mode:this.mode,options:this.defaultOptions,store:this.store}),this.control=new se({options:this.defaultOptions,map:t,mode:this.mode}),this.tiles=new Be({map:t,store:this.store,mode:this.mode,options:this.defaultOptions,control:this.control,panel:this.panel,mouseEvents:this.mouseEvents,projection:this.projection,events:this.events}),this.renderer?.execute(),this.cursor=new ae({map:t,mode:this.mode,mouseEvents:this.mouseEvents,store:this.store,options:this.defaultOptions}),this.timelineAdapter=new _e(t),this.mode.pingConsumers(),this.store.pingConsumers(),this.container=this.control.getContainer(),this.container}catch(t){throw o.#e=null,this.#o(),t}finally{o.#t=!1;}};#o=()=>{this.projection?.remove(),this.cursor?.remove(),this.tiles?.remove(),this.panel?.destroy(),this.store?.reset(),this.mode?.unsubscribe(),this.control?.destroy(),this.timelineAdapter?.destroy(),h.resetStacks(),this.container&&l.remove(this.container),d.unbind(this.events),this.container=void 0,this.store=void 0,this.mode=void 0,this.tiles=void 0,this.panel=void 0,this.control=void 0,this.cursor=void 0,this.mouseEvents=void 0,this.timelineAdapter=void 0,this.projection=void 0,this.renderer=null;};#i=()=>{let{store:e,mode:t,panel:i}=this;if(o.#e!==this||!e||!t||!i)throw new Error(L.NOT_ADDED_TO_MAP);return {store:e,mode:t,panel:i}};onRemove=()=>{if(o.#t)throw new Error(L.REENTRANT_LIFECYCLE);if(o.#e===this){o.#t=!0;try{this.#o();}finally{o.#e=null,o.#t=!1;}}};setSteps=e=>{if(!Array.isArray(e))throw new Error(L.INVALID_STEPS_ARGUMENT);let{store:t,mode:i,panel:n}=this.#i();t.reset(),n.hide(),i.reset(),h.resetStacks(),this.renderer?.resetGeometries(),st(t,e,this.defaultOptions.pointGeneration),this.renderer?.execute();};findStepById=e=>this.#i().store.findStepById(e);findNodeById=e=>this.#i().store.findNodeById(e);getAllSteps=(e="array")=>{let{store:t}=this.#i();if(e==="array")return $(t.head);if(e==="linkedlist")return {head:t.head,tail:t.tail,size:t.size};throw new Error(L.INVALID_STEPS_TYPE)};undo=e=>{this.#i().panel.api().undo(e);};redo=e=>{this.#i().panel.api().redo(e);};clear=e=>{this.#i().panel.api().clear(e);};save=e=>{this.#i().panel.api().save(e);};removeAllSteps=e=>{this.clear(e);};on=(e,t)=>this.events.on(e,t);once=(e,t)=>this.events.once(e,t);off=(e,t)=>{this.events.off(e,t);}};
1
+ var q=class{_isHidden=!0;_anchor={dx:0,dy:0};_pendingCoord=null;_rafId=0;_listenersActive=!1;get isHidden(){return this._isHidden}set isHidden(e){this._isHidden=e;}get anchor(){return {...this._anchor}}set anchor(e){this._anchor={...e};}get pendingCoord(){return this._pendingCoord}set pendingCoord(e){this._pendingCoord=e;}get rafId(){return this._rafId}set rafId(e){this._rafId=e;}get listenersActive(){return this._listenersActive}set listenersActive(e){this._listenersActive=e;}reset(){this._isHidden=!0,this._anchor={dx:0,dy:0},this._pendingCoord=null,this._rafId=0,this._listenersActive=!1;}};var l=class{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 addEventListener(e,t,i,n={}){e&&e.addEventListener(t,i,n);}static removeEventListener(e,t,i,n={}){e&&e.removeEventListener(t,i,n);}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);}static setPressed(e,t){e&&(e.classList.toggle("mdl-control-button-active",t),e.setAttribute("aria-pressed",String(t)));}static disableButton=e=>{e&&(e.setAttribute("disabled","true"),e.setAttribute("aria-disabled","true"));};static enableButton=e=>{e&&(e.removeAttribute("disabled"),e.removeAttribute("aria-disabled"));}};var Y=class{constructor(e){this.ctx=e;this.root=l.create("div","mdl-dashboard-container"),this.root.setAttribute("data-type","panel"),this.buttonContainer=l.create("div","mdl-dashboard",this.root),this.renderButtons(),this.hasButtons()&&e.map.getContainer().appendChild(this.root);}root;buttonContainer;buttons={};createButton(e,t,i,n){let s=l.create("button",`mdl-panel-button mdl-panel-button-${i}`,n);return s.setAttribute("data-type",e),s.setAttribute("aria-label",t),l.create("span",`mdl-icon mdl-icon-${e} mdl-icon-${i}`,s),s}renderButtons(){let{panel:e,locale:t}=this.ctx.options,{buttons:i,size:n}=e;Object.keys(i).forEach(s=>{if(!i[s].visible)return;let a=this.createButton(s,t[s],n,this.buttonContainer);(s==="undo"||s==="redo")&&l.disableButton(a),this.buttons[s]=a;});}getButton=e=>this.buttons[e]??null;hasButtons=()=>Object.keys(this.buttons).length>0;getRoot=()=>this.root;show=()=>{this.root.classList.remove("mdl-hidden"),this.root.removeAttribute("aria-hidden");};hide=()=>{this.root.classList.add("mdl-hidden"),this.root.setAttribute("aria-hidden","true");};setTransform=(e,t)=>{this.root.style.transform=`translate(${e}px, ${t}px)`;};observeResize=e=>{let t=new ResizeObserver(e);return t.observe(this.root),t};destroy=()=>{this.root.remove();}};var ft=8,Xe=8,S=class{container;label;constructor(){this.container=void 0;}create=e=>{let t=l.create("div","mdl-tooltip",document.body),i=l.create("span",`mdl-tooltip-text mdl-tooltip-text-${e.placement}`,t);return i.textContent=e.label,this.container=t,this.label=i,this};activateAnimation=()=>{this.label?.classList.add("mdl-tooltip-text-active");};getLabelDimensions=()=>this.label?{width:this.label.clientWidth,height:this.label.clientHeight}:{width:0,height:0};getSidePosition=(e,t)=>{let{bottom:i,left:n,right:s}=e.target.getBoundingClientRect(),{width:a,height:p}=this.getLabelDimensions(),u=i-p-2;return t==="right"?{x:s+Xe,y:u}:{x:n-Xe-a,y:u}};getBottomPosition=e=>{let{bottom:t,left:i,right:n}=e.target.getBoundingClientRect(),{width:s}=this.getLabelDimensions();return {x:(n-i)/2+i-s/2,y:t+ft}};getPosition=(e,t)=>t!=="bottom"?this.getSidePosition(e,t):this.getBottomPosition(e);setPosition=e=>{let{x:t,y:i}=e;this.container&&(this.container.style.left=`${t}px`,this.container.style.top=`${i}px`),this.activateAnimation();};remove=()=>{this.container&&l.remove(this.container);}};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 j=class{constructor(e,t,i=[]){this.type=e;this.payload=t;this.commands=i;}add(e){this.commands.push(e);}execute(){if(this.commands)for(let e of this.commands)e.execute();}undo(){if(this.commands)for(let e=this.commands.length-1;e>=0;e--)this.commands[e]?.undo();}};var Ge=class o extends x{transaction=null;undoStack=[];redoStack=[];static instance=null;static getInstance(){return o.instance||(o.instance=new o),o.instance}commit=e=>{e.execute(),this.transaction?this.transaction.add(e):this.undoStack.push(e),this.redoStack.length=0,this.pingConsumers();};undo=()=>{let e=this.undoStack.pop();if(e)return e.undo(),this.redoStack.push(e),this.pingConsumers(),e};redo=()=>{let e=this.redoStack.pop();return e?(e.execute(),this.undoStack.push(e),this.pingConsumers(),e):null};beginTransaction=(e="compound",t=null)=>{this.transaction||(this.transaction=new j(e,t));};commitTransaction=()=>{if(!this.transaction)return;let e=this.transaction;this.transaction=null,this.undoStack.push(e),this.pingConsumers();};getRedoStackLength=()=>this.redoStack.length;getUndoStackLength=()=>this.undoStack.length;resetStacks=()=>{this.transaction=null,this.undoStack=[],this.redoStack=[],this.pingConsumers();};pingConsumers=()=>{this.notify({type:"REDO_STACK_CHANGED",data:this.redoStack.length}),this.notify({type:"UNDO_STACK_CHANGED",data:this.undoStack.length});}},h=Ge.getInstance();var b=()=>{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("-")},A=(o,e)=>{let t=0,i=(...n)=>{window.clearTimeout(t),t=window.setTimeout(()=>{t=0,o(...n);},e);};return i.cancel=()=>{window.clearTimeout(t),t=0;},i},C=o=>{let e=null,t=0,i=()=>{t=0;let s=e;e=null,s&&o(...s);},n=(...s)=>{e=s,t===0&&(t=window.requestAnimationFrame(i));};return n.cancel=()=>{t!==0&&window.cancelAnimationFrame(t),t=0,e=null;},n};var Ze={type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",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",AuxiliaryPointLayer:"mdl-auxiliary-point-layer",PointsHitLayer:"mdl-points-hit-layer",FirstPointHitLayer:"mdl-first-point-hit-layer",AuxiliaryPointHitLayer:"mdl-auxiliary-point-hit-layer"},P={points:["all",["==",["geometry-type"],"Point"],["==",["get","isFirst"],!1],["==",["get","isAuxiliary"],!1]],pointsWhenClosed:["all",["==",["geometry-type"],"Point"],["==",["get","isAuxiliary"],!1]],firstPoint:["==",["get","isFirst"],!0],auxiliaryPoint:["==",["get","isAuxiliary"],!0]},c={UnifiedSource:"mdl-unified-source",LineDynamicSource:"mdl-line-dynamic-source",LineSourceBreak:"mdl-line-source-break",SinglePointSource:"mdl-single-point-source"},O={large:6.5,default:5.5},K={large:"#FF6464",default:"#666666"},N={"circle-radius":O.default,"circle-color":"#FEFFFE","circle-stroke-color":K.default,"circle-stroke-width":3},D={"circle-radius":O.default-1.5,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":2},k={"circle-radius":O.large,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},F={"fill-color":"grey","fill-opacity":.4},R={"line-width":3,"line-color":"grey","line-opacity":.7},I={"circle-radius":O.default,"circle-color":"#FEFFFE","circle-stroke-color":"#666666","circle-stroke-width":3},J={...R,"line-dasharray":[4.5,2.5]},B={"line-width":3,"line-color":"#FF6464","line-dasharray":[3,3]},yt=.18,gt={"circle-color":"#666666","circle-opacity":["case",["boolean",["feature-state","hover"],!1],yt,0]},Qe=o=>{let e={...gt,"circle-radius":o.interaction.pointHitRadius,"circle-pitch-scale":"viewport"};return [{id:r.SinglePointLayer,source:c.SinglePointSource,type:"circle",paint:o.layersPaint.onLinePoint,layout:{visibility:"none"}},{id:r.PolygonLayer,source:c.UnifiedSource,type:"fill",paint:o.layersPaint.polygon,layout:{visibility:"none"},filter:["==",["geometry-type"],"Polygon"]},{id:r.LineDynamicLayer,source:c.LineDynamicSource,type:"line",paint:o.layersPaint.dynamicLine,layout:{visibility:"none"}},{id:r.LineLayer,source:c.UnifiedSource,type:"line",paint:o.layersPaint.line,layout:{visibility:"visible"},filter:["==",["geometry-type"],"LineString"]},{id:r.LineLayerTransparent,source:c.UnifiedSource,type:"line",paint:{"line-width":o.interaction.lineHitRadius*2,"line-color":"transparent"},filter:["==",["geometry-type"],"LineString"]},{id:r.LineLayerBreak,source:c.LineSourceBreak,type:"line",paint:o.layersPaint.breakLine,layout:{visibility:"none"}},{id:r.PointsLayer,source:c.UnifiedSource,type:"circle",paint:o.layersPaint.points,filter:P.points},{id:r.FirstPointLayer,source:c.UnifiedSource,type:"circle",paint:o.layersPaint.firstPoint,filter:P.firstPoint,layout:{visibility:"none"}},{id:r.AuxiliaryPointLayer,source:c.UnifiedSource,type:"circle",paint:o.layersPaint.auxiliaryPoint,filter:P.auxiliaryPoint},{id:r.PointsHitLayer,source:c.UnifiedSource,type:"circle",paint:{...e},filter:P.points},{id:r.FirstPointHitLayer,source:c.UnifiedSource,type:"circle",paint:{...e},filter:P.firstPoint,layout:{visibility:"none"}},{id:r.AuxiliaryPointHitLayer,source:c.UnifiedSource,type:"circle",paint:{...e},filter:P.auxiliaryPoint}]};var v={getMidpoint(o,e){return {lat:(o.lat+e.lat)/2,lng:(o.lng+e.lng)/2}},createAuxiliaryPoint(o,e){let t=v.getMidpoint(o,e);return {lat:t.lat,lng:t.lng,isAuxiliary:!0,id:b()}}},et=[r.FirstPointLayer,r.FirstPointHitLayer],tt=[r.PointsLayer,r.PointsHitLayer],Et=33,U=null,Fe=()=>{U!==null&&(clearTimeout(U),U=null);},y={cancelSinglePointHiding:Fe,setFirstPointVisible(o){for(let e of et)o.setLayoutProperty(e,"visibility","visible");},setFirstPointHidden(o){for(let e of et)o.setLayoutProperty(e,"visibility","none");},setSinglePointVisible(o){Fe(),o.target.setLayoutProperty(r.SinglePointLayer,"visibility","visible");},setSinglePointHidden(o){let e=o.target;Fe(),U=setTimeout(()=>{U=null,e.setLayoutProperty(r.SinglePointLayer,"visibility","none");},Et);}},Ue={default(o){for(let e of tt)o.setFilter(e,P.points);},closedGeometry(o){for(let e of tt)o.setFilter(e,P.pointsWhenClosed);}};var W=class{constructor(e,t){this.store=e;this.options=t;this.store=e;}isCircular=()=>{let{head:e,tail:t}=this.store;return !e||!t?!1:e===t.next&&t===e.prev};canBreak=()=>{let{size:e}=this.store,t=this.options?.pointGeneration==="auto"?3:2;return e<=t};canClose=()=>{let{size:e}=this.store;return (this.options?.pointGeneration==="auto"?e>3:e>2)&&!this.isCircular()};break=e=>{if(this.store.head)if(this.options?.pointGeneration==="auto")if(e.val?.isAuxiliary){let t=e.val?.id;this.store.head=e.next,this.store.tail=e.prev,this.store.removeNodeById(t),this.store.head.prev=null,this.store.tail.next=null;}else {let t=e.next?.val?.id;this.store.head=e.next?.next,this.store.tail=e,this.store.removeNodeById(t),this.store.head.prev=null,this.store.tail.next=null;}else this.store.head=e.next,this.store.head.prev=null,this.store.tail=e,this.store.tail.next=null;};close=()=>{let{head:e,tail:t}=this.store;!e||!t||(t.next=e,e.prev=t);}};var z=class{val;prev;next;constructor(e=null,t=null,i=null){this.val=e,this.prev=i,this.next=t;}},_=class extends x{constructor(t){super();this.options=t;let i=it(this.options);this.circular=new W(this,this.options),this.map=i?i.map:new Map,this.head=i?i.head:null,this.tail=i?i.tail:null,this.size=i?i.size:0;}head;tail;size;map;circular;push=t=>{let i=new z(t);return this.head?this.tail&&(i.prev=this.tail,this.tail.next=i,this.tail=i):this.head=this.tail=i,this.map.set(t.id,i),this.size++,this.pingConsumers(),i};unshift=t=>{let i=new z(t);i.next=this.head,this.head=i,this.circular.isCircular()&&this.tail&&(this.tail.next=i,i.prev=this.tail),this.map.set(t.id,i),this.size++,this.pingConsumers();};insertAfter=(t,i)=>{if(!t)return null;let n=new z(i);return n.prev=t,n.next=t.next,this.tail===t&&this.head===t.next&&(this.tail=n,this.head.prev=n),t.next&&(t.next.prev=n),t.next=n,this.map.set(i.id,n),this.size++,this.pingConsumers(),n};removeNodeById(t){let i=this.map.get(t);return i?(this.size===1?(this.head=null,this.tail=null):(i.prev&&(i.prev.next=i.next),i.next&&(i.next.prev=i.prev),i===this.head&&(this.head=i.next,this.head?.prev&&this.tail&&(this.tail.next=this.head)),i===this.tail&&(this.tail=i.prev,this.head&&this.tail?.next&&(this.head.prev=this.tail))),this.map.delete(t),this.size--,this.pingConsumers(),i):null}findStepById(t){let i=this.map.get(t);return i?i.val:null}findNodeById(t){let i=this.map.get(t);return i||null}isLastPoint=(t,i)=>t.pointGeneration==="auto"&&this.tail?.next===this.head?this.tail?.prev?.val?.id===i:this.tail?.val?.id===i;reset=()=>{this.head=null,this.tail=null,this.size=0,this.map.clear(),this.notify({type:"STORE_CLEARED"});};pingConsumers=()=>{this.notify({type:"STORE_MUTATED",data:{head:this.head,tail:this.tail,size:this.size}});}};var L={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.",NOT_ADDED_TO_MAP:"DrawLibre is not added to a map. Call map.addControl(draw) before using this method.",ALREADY_ADDED_TO_MAP:"DrawLibre is already added to a map. Call map.removeControl(draw) before adding it again.",REENTRANT_LIFECYCLE:"DrawLibre is in the middle of being added or removed. Do not call map.addControl or map.removeControl from a listener that runs during addControl or removeControl.",INVALID_STEPS_ARGUMENT:"Invalid argument. Expected an array of steps.",INVALID_STEPS_TYPE:"Invalid type specified. Use 'array' or 'linkedlist'."};function ot(o,e,t,i){let n=t?e.slice(0,-1):e;return n.forEach((s,a)=>{if(o.push(s),i==="auto"){if(n[a+1]){let u=v.createAuxiliaryPoint(s,n[a+1]);o.push(u);}else if(t){let u=v.createAuxiliaryPoint(s,n[0]);o.push(u);}}}),o}function nt(o){return o.map((e,t)=>{let i="id"in e&&e.id!==void 0?e.id:b();return {...e,isAuxiliary:!1,isFirst:t===0,id:i}})}function Lt(o,e){let{steps:t,closeGeometry:i}=o,n=nt(t),s=ot(new _,n,i,e);return i&&s.tail&&s.head&&(s.tail.next=s.head,s.head.prev=s.tail),s}function st(o,e,t){ot(o,nt(e),!1,t);}function it(o){if(!o?.initial)return null;if(o&&o.initial&&!o.initial.steps.length)throw new Error(L.EMPTY_INITIAL_STATE);return o&&o.initial.steps?Lt(o.initial,o.pointGeneration):null}function $(o){if(!o)return [];let e=new Set,t=[],i=o;for(;i!==null&&!e.has(i);)e.add(i),t.push(i.val),i=i.next;return t}var E={POINT_REMOVE:"mdl:pointremove",POINTENTER:"mdl:pointenter",POINT_LEAVE:"mdl:pointleave",MOVE_END:"mdl:moveend",ADD:"mdl:add",UNDO:"mdl:undo",REDO:"mdl:redo",REMOVE_ALL:"mdl:removeall",SAVE:"mdl:save",BREAK:"mdl:break",MODE_CHANGED:"mdl:modechanged",UNDO_STACK_CHANGED:"mdl:undostackchanged",REDO_STACK_CHANGED:"mdl:redostackchanged"};var d=class o{static emitter=null;static queue=[];static delivering=!1;static bind(e){o.emitter=e;}static unbind(e){o.emitter===e&&(o.emitter=null);}static dispatch(e,t,i){let n={...i,type:t,target:e};if(o.queue.push({map:e,type:t,payload:n,emitter:o.emitter}),!o.delivering){o.delivering=!0;try{let s=o.queue.shift();for(;s;)s.map.fire(s.type,s.payload),s.emitter?.emit(s.type,s.payload),s=o.queue.shift();}finally{o.queue=[],o.delivering=!1;}}}static addPoint(e,t,i){o.dispatch(t,E.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){o.dispatch(t,E.MOVE_END,{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 removePoint(e,t){o.dispatch(t,E.POINT_REMOVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static enterPoint(e,t){o.dispatch(t,E.POINTENTER,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static leavePoint(e,t){o.dispatch(t,E.POINT_LEAVE,{id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static undo(e,t,i){o.dispatch(t,E.UNDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static redo(e,t,i){o.dispatch(t,E.REDO,{originalEvent:i,id:e.id,coordinates:{lat:e.lat,lng:e.lng},total:e.total,timestamp:Date.now()});}static modeChanged(e,t){o.dispatch(e,E.MODE_CHANGED,{mode:t});}static removeAllPoints(e,t){o.dispatch(e,E.REMOVE_ALL,{originalEvent:t});}static onSaveClick(e,t,i){let{map:n,mode:s}=e;o.dispatch(n,E.SAVE,{originalEvent:i,timestamp:Date.now(),steps:t,mode:{geometry:s.getMode(),closedGeometry:s.getClosedGeometry()}});}static onLineBreak(e){o.dispatch(e,E.BREAK,{});}static onUndoStackChange=(e,t)=>{o.dispatch(e,E.UNDO_STACK_CHANGED,{length:t});};static onRedoStackChange=(e,t)=>{o.dispatch(e,E.REDO_STACK_CHANGED,{length:t});}};function xt(o){let e=[],t=o.head,i=new Set;for(;t!==null;){if(i.has(t.val?.id)){o.head&&o.head.val&&e.push([o.head.val.lng,o.head.val.lat]);break}i.add(t.val?.id),t.val&&e.push([t.val.lng,t.val.lat]),t=t.next;}return e}function X(o,e){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:[o,e]}}]}}function bt(o){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:o}}]}}function Ct(o){return {type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[o]}}]}}function Pt(o){let e=o.head,t=[],i=new Set;for(;e!==null&&!i.has(e.val?.id);){if(e.val){let n=e.val,s=e.val.id===o.head?.val?.id;t.push({type:"Feature",properties:{id:n.id,lat:n.lat,lng:n.lng,isFirst:s,isAuxiliary:n.isAuxiliary},geometry:{type:"Point",coordinates:[n.lng,n.lat]}});}i.add(e.val?.id),e=e.next;}return {type:"FeatureCollection",features:t}}function ze(o){let e=Pt(o).features,t=xt(o),i=bt(t).features,n=Ct(t).features;return {type:"FeatureCollection",features:[...e,...i,...n]}}var Ve=class o{static instance=null;ctx=null;unifiedGeoJSON;constructor(){this.unifiedGeoJSON={type:"FeatureCollection",features:[]};}initialize(e){return this.ctx=e,this.unifiedGeoJSON=ze(this.ctx.store),this.execute(),o.instance}static getInstance(){return o.instance||(o.instance=new o),o.instance}getContext(){if(!this.ctx)throw new Error("Somehow trolled with Renderer.getContext, check the Renderer.initialize");return this.ctx}updateLine(e,t){let{mode:i}=this.getContext(),n=this.unifiedGeoJSON.features.at(-2)?.geometry.coordinates;n&&(n[e]=[t.lng,t.lat],i.getClosedGeometry()&&e===0&&(n[n.length-1]=[t.lng,t.lat]));}updatePolygon(e,t){let{mode:i}=this.getContext(),n=this.unifiedGeoJSON.features.at(-1)?.geometry.coordinates[0];n&&(n[e]=[t.lng,t.lat],i.getClosedGeometry()&&e===0&&(n[n.length-1]=[t.lng,t.lat]));}updatePoint(e,t){let i=this.unifiedGeoJSON?.features?.[e];i?.geometry?.coordinates&&(i.geometry.coordinates=[t.lng,t.lat]);}executeOnMouseMove=(e,t,i)=>{let{map:n,mode:s,options:a,store:p}=this.getContext(),u=e===0?p.size-1:e-1;this.updatePoint(e,t),i&&i.prev&&this.updatePoint(u,i.prev),i&&i.next&&this.updatePoint(e+1,i.next),this.updateLine(e,t),i&&i.prev&&this.updateLine(u,i.prev),i&&i.next&&this.updateLine(e+1,i.next),a.modes.polygon.visible&&s.isPolygon()&&(this.updatePolygon(e,t),i&&i.prev&&this.updatePolygon(u,i.prev),i&&i.next&&this.updatePolygon(e+1,i.next));let M=n.getSource(c.UnifiedSource);M&&M.setData(this.unifiedGeoJSON);};execute(){let{map:e,store:t}=this.getContext();this.unifiedGeoJSON=ze(t);let i=e.getSource(c.UnifiedSource);i&&i.setData(this.unifiedGeoJSON);}resetGeometries=()=>{let{map:e}=this.getContext(),t=e.getSource(c.UnifiedSource);t&&t.setData({type:"FeatureCollection",features:[]});}},f=Ve.getInstance();var Z=class{constructor(e){this.ctx=e;}clear=e=>{let{mode:t,view:i,store:n,map:s}=this.ctx;n.reset(),i.hide(),t.reset(),h.resetStacks(),f.resetGeometries(),d.removeAllPoints(s,e),f.execute();};undo=e=>{let{store:t,map:i}=this.ctx;h.undo(),d.undo({...t.tail?.val,total:t.size},i,e),f.execute();};redo=e=>{let{store:t,map:i}=this.ctx;h.redo(),d.redo({...t.tail?.val,total:t.size},i,e),f.execute();};save=e=>{let{store:t,options:i}=this.ctx;d.onSaveClick(this.ctx,$(t.head),e),i.panel.buttons.save.clearOnSave&&this.clear(e),f.execute();}};var Q=class{constructor(e){this.ctx=e;this.tooltip=new S,this.actions=new Z(this.ctx);}tooltip;actions;addButtonListeners(e,t){let i=this.ctx.view.getButton(e);i&&(l.addEventListener(i,"click",t),l.addEventListener(i,"mouseenter",this.onMouseEnter),l.addEventListener(i,"mouseleave",this.onMouseLeave));}removeButtonListeners(e,t){let i=this.ctx.view.getButton(e);i&&(l.removeEventListener(i,"click",t),l.removeEventListener(i,"mouseenter",this.onMouseEnter),l.removeEventListener(i,"mouseleave",this.onMouseLeave));}initEvents(){this.addButtonListeners("undo",this.onUndoClick),this.addButtonListeners("redo",this.onRedoClick),this.addButtonListeners("delete",this.onClearClick),this.addButtonListeners("save",this.onSaveClick);}removeEvents(){this.removeButtonListeners("undo",this.onUndoClick),this.removeButtonListeners("redo",this.onRedoClick),this.removeButtonListeners("delete",this.onClearClick),this.removeButtonListeners("save",this.onSaveClick);}getButtonLabel=e=>{let{options:t}=this.ctx;return {undo:t.locale.undo,redo:t.locale.redo,delete:t.locale.delete,save:t.locale.save}[e]};onMouseEnter=e=>{let i=e.target.getAttribute("data-type");if(i){let n=this.getButtonLabel(i);this.tooltip.create({label:n,placement:"bottom"}).setPosition(this.tooltip.getPosition(e,"bottom"));}};onMouseLeave=()=>{this.tooltip.remove();};onUndoClick=e=>{this.actions.undo(e),this.tooltip.remove();};onRedoClick=e=>{this.actions.redo(e),this.tooltip.remove();};onClearClick=e=>{this.actions.clear(e),this.tooltip.remove();};onSaveClick=e=>{this.actions.save(e),this.tooltip.remove();};api(){return this.actions}};var ee=class{constructor(e){this.ctx=e;}initConsumers(){this.ctx.store.addObserver(this.onStoreChangeConsumer),this.ctx.mode?.addObserver(this.onMapModeConsumer),h.addObserver(this.onTimelineChangeConsumer);}removeConsumers(){this.ctx.store.removeObserver(this.onStoreChangeConsumer),this.ctx.mode?.removeObserver(this.onMapModeConsumer),h.removeObserver(this.onTimelineChangeConsumer);}onTimelineChangeConsumer=e=>{let{type:t,data:i}=e;t==="REDO_STACK_CHANGED"&&(i?l.enableButton(this.ctx.view.getButton("redo")):l.disableButton(this.ctx.view.getButton("redo"))),t==="UNDO_STACK_CHANGED"&&(i?l.enableButton(this.ctx.view.getButton("undo")):l.disableButton(this.ctx.view.getButton("undo")));};onStoreChangeConsumer=e=>{if(e.type==="STORE_MUTATED"){let{data:t}=e;if(t?.size===0)this.ctx.view.hide();else {let i=Object.assign({},t);for(;i.tail;)if(i.tail?.val?.isAuxiliary)i.tail=i.tail?.prev;else {i.tail?.val&&this.ctx.setPanelLocation({lat:i.tail.val.lat,lng:i.tail.val.lng});break}}}};onMapModeConsumer=e=>{let{store:t}=this.ctx,{type:i,data:n}=e;i==="MODE_CHANGED"&&!n&&this.ctx.view.hide(),i==="MODE_CHANGED"&&n&&(this.ctx.store.circular.isCircular()?this.ctx.options.pointGeneration==="auto"?t.tail?.prev?.val&&this.ctx.setPanelLocation({lat:t.tail.prev.val.lat,lng:t.tail.prev.val.lng}):t.tail?.val&&this.ctx.setPanelLocation({lat:t.tail.val.lat,lng:t.tail.val.lng}):t.tail?.val&&this.ctx.setPanelLocation({lat:t.tail.val.lat,lng:t.tail.val.lng}));}};var Mt=20,te=class{constructor(e){this.ctx=e;this.view=new Y(e),this.events=new Q({...e,view:this.view}),this.observer=new ee({...e,view:this.view,setPanelLocation:this.setPanelLocation}),this.init();}view;state=new q;events;observer;resizeObserver;onMapMove=()=>this.schedulePositionUpdate();init(){let{store:e}=this.ctx;this.resizeObserver=this.view.observeResize(this.measureAnchor),this.measureAnchor(),e.tail?.val&&this.setPanelLocation(e.tail.val),this.events.initEvents(),this.observer.initConsumers();}destroy(){this.observer.removeConsumers(),this.events.removeEvents(),this.state.listenersActive&&this.disableListeners(),this.resizeObserver.disconnect(),cancelAnimationFrame(this.state.rafId),this.view.destroy();}enableListeners(){if(this.state.listenersActive)return;let e=this.ctx.map;e.on("move",this.onMapMove),e.on("zoom",this.onMapMove),this.state.listenersActive=!0;}disableListeners(){if(!this.state.listenersActive)return;let e=this.ctx.map;e.off("move",this.onMapMove),e.off("zoom",this.onMapMove),this.state.listenersActive=!1;}setPanelLocation=e=>{this.view.hasButtons()&&(this.state.pendingCoord=e,this.enableListeners(),this.schedulePositionUpdate(),this.show());};measureAnchor=()=>{let{width:e,height:t}=this.view.getRoot().getBoundingClientRect();this.state.anchor={dx:-e/2,dy:-t-Mt},this.schedulePositionUpdate();};schedulePositionUpdate=()=>{this.state.rafId||(this.state.rafId=requestAnimationFrame(()=>{if(this.state.rafId=0,this.state.pendingCoord){let e=this.ctx.map.project(this.state.pendingCoord),{dx:t,dy:i}=this.state.anchor;this.view.setTransform(e.x+t,e.y+i);}}));};setVisible(e){this.state.isHidden=!e,e?this.view.show():this.view.hide();}show=()=>this.setVisible(!0);hide=()=>this.setVisible(!1);api=()=>this.events.api()};var g={AUTO:"auto",DEFAULT:"default",POINTER:"pointer",CROSSHAIR:"crosshair",MOVE:"move",HELP:"help",GRAB:"grab",GRABBING:"grabbing"};var rt=(o,e)=>{let t=e.locale.line,i=e.locale.polygon,n=e.locale.break;return {line:t,polygon:i,break:n}[o]};var ie=class{constructor(e){this.ctx=e;this.tooltip=new S,this.initEvents();}tooltip;initEvents(){let{lineButton:e,breakButton:t,polygonButton:i}=this.ctx.view;e&&(l.addEventListener(e,"click",this.onLineClick),l.addEventListener(e,"mouseenter",this.onButtonEnter),l.addEventListener(e,"mouseleave",this.onButtonLeave)),i&&(l.addEventListener(i,"click",this.onPolygonClick),l.addEventListener(i,"mouseenter",this.onButtonEnter),l.addEventListener(i,"mouseleave",this.onButtonLeave)),t&&(l.addEventListener(t,"click",this.onBreakClick),l.addEventListener(t,"mouseenter",this.onButtonEnter),l.addEventListener(t,"mouseleave",this.onButtonLeave));}removeEvents(){let{lineButton:e,breakButton:t,polygonButton:i}=this.ctx.view;e&&(l.removeEventListener(e,"click",this.onLineClick),l.removeEventListener(e,"mouseenter",this.onButtonEnter),l.removeEventListener(e,"mouseleave",this.onButtonLeave)),i&&(l.removeEventListener(i,"click",this.onPolygonClick),l.removeEventListener(i,"mouseenter",this.onButtonEnter),l.removeEventListener(i,"mouseleave",this.onButtonLeave)),t&&(l.removeEventListener(t,"click",this.onBreakClick),l.removeEventListener(t,"mouseenter",this.onButtonEnter),l.removeEventListener(t,"mouseleave",this.onButtonLeave));}remove(){this.removeEvents(),this.tooltip.remove();}getPlacement=e=>{let t=this.ctx.map.getContainer().getBoundingClientRect(),i=e.getBoundingClientRect(),n=i.left+i.width/2,s=t.left+t.width/2;return n<s?"right":"left"};onButtonEnter=e=>{let{options:t}=this.ctx,i=e.target.getAttribute("data-type");if(i){let n=rt(i,t),s=this.getPlacement(e.target);this.tooltip.create({label:n,placement:s}).setPosition(this.tooltip.getPosition(e,s));}};onButtonLeave=()=>{this.tooltip.remove();};removeActiveClass=()=>{let{lineButton:e,breakButton:t,polygonButton:i}=this.ctx.view;l.setPressed(e,!1),l.setPressed(i,!1),l.setPressed(t,!1);};onLineClick=()=>{this.tooltip.remove();let{mode:e}=this.ctx,{lineButton:t}=this.ctx.view;if(e.getMode()==="line"&&!e.getBreak()){e.setMode(null),this.removeActiveClass();return}this.removeActiveClass(),l.setPressed(t,!0),e.setMode("line");};onPolygonClick=()=>{this.tooltip.remove();let{mode:e}=this.ctx,{polygonButton:t}=this.ctx.view;if(e.getMode()==="polygon"&&!e.getBreak()){e.setMode(null),this.removeActiveClass();return}this.removeActiveClass(),l.setPressed(t,!0),e.setMode("polygon");};onBreakClick=()=>{this.tooltip.remove();let{map:e,mode:t}=this.ctx,{breakButton:i}=this.ctx.view;this.removeActiveClass(),l.setPressed(i,!0),t.setBreak(!0),e.getCanvasContainer().style.cursor=g.POINTER;}};var oe=class{constructor(e){this.ctx=e;this.initConsumers();}announced=void 0;initConsumers=()=>{this.ctx.mode.addObserver(this.mapModeConsumer);};remove=()=>{this.ctx.mode.removeObserver(this.mapModeConsumer);};resetAllState=()=>{let{lineButton:e,breakButton:t,polygonButton:i}=this.ctx.view;l.setPressed(e,!1),l.setPressed(i,!1),l.setPressed(t,!1);};announce=e=>{e!==this.announced&&(this.announced=e,d.modeChanged(this.ctx.map,e));};checkActive=e=>{this.resetAllState(),l.setPressed(e,!0);};observeModeChange=e=>{let{data:t}=e,{lineButton:i,breakButton:n,polygonButton:s}=this.ctx.view,{mode:a}=this.ctx;this.announce(t),(t==="line"||t==="polygon")&&(this.resetAllState(),l.setPressed(t==="line"?i:s,!0)),n&&(t?a.getClosedGeometry()&&l.enableButton(n):l.disableButton(n));};observeGeometryChange=e=>{let{data:t}=e,{lineButton:i,breakButton:n,polygonButton:s}=this.ctx.view,{mode:a}=this.ctx,p=a.getMode();n&&(t?l.enableButton(n):l.disableButton(n)),p==="polygon"&&i&&(t?l.disableButton(i):l.enableButton(i)),p==="line"&&s&&(t?l.disableButton(s):l.enableButton(s));};mapModeConsumer=e=>{let{type:t,data:i}=e;if(t==="MODE_CHANGED"&&this.observeModeChange(e),t==="CLOSED_GEOMETRY_CHANGED"&&this.observeGeometryChange(e),t==="BREAK_CHANGED"&&i){let{breakButton:n}=this.ctx.view;this.checkActive(n),this.announce("break");}}};var ne=class{constructor(e){this.ctx=e;this.root=l.create("div","mapboxgl-ctrl mapboxgl-ctrl-group maplibregl-ctrl maplibregl-ctrl-group"),this.createControl();}root;lineButton;polygonButton;breakButton;createControlButton=(e,t,i,n)=>{let s=l.create("button","mdl-control-button",this.root);return s.setAttribute("aria-label",t),s.setAttribute("data-type",e),l.setPressed(s,i),n&&l.disableButton(s),l.create("span",`mdl-icon mdl-icon-${e} mdl-icon-medium`,s),s};createLineButton=()=>{let{mode:e,options:t}=this.ctx,i=this.ctx.options.modes.line.visible,n=t.locale.line;i&&(this.lineButton=this.createControlButton("line",n,e.getMode()==="line"));};createPolygonButton=()=>{let{mode:e,options:t}=this.ctx,i=this.ctx.options.modes.polygon.visible,n=t.locale.polygon;i&&(this.polygonButton=this.createControlButton("polygon",n,e.getMode()==="polygon"));};createBreakButton=()=>{let{mode:e,options:t}=this.ctx,i=this.ctx.options.modes.breakGeometry.visible,n=t.locale.break;if(i){let a=!this.ctx.options.initial?.closeGeometry,p=e.getBreak();this.breakButton=this.createControlButton("break",n,p,a);}};createControl=()=>{this.createLineButton(),this.createPolygonButton(),this.createBreakButton();};getContainer=()=>this.root;destroy=()=>{this.root.remove();}};var se=class{constructor(e){this.ctx=e;this.view=new ne(e);let t={...e,view:this.view};this.events=new ie(t),this.observer=new oe(t),this.init();}view;events;observer;init(){let e=this.view.getContainer();this.ctx.map.getContainer().appendChild(e);}getContainer(){return this.view.getContainer()}destroy(){this.events.remove(),this.observer.remove(),this.view.destroy();}};function St(o){return o.initial?.geometry?o.initial?.geometry:o.modes.initial?o.modes.initial:null}var re=class extends x{mode;break;closedGeometry;constructor(e){super(),this.mode=St(e),this.break=!1,this.closedGeometry=e.initial?.closeGeometry??!1;}getMode=()=>this.mode;setMode=e=>{this.mode=e,this.setBreak(!1),this.notify({type:"MODE_CHANGED",data:e});};getBreak=()=>this.break;setBreak=e=>{this.break=e,this.notify({type:"BREAK_CHANGED",data:e});};getClosedGeometry=()=>this.closedGeometry;setClosedGeometry=e=>{this.closedGeometry=e,this.notify({type:"CLOSED_GEOMETRY_CHANGED",data:this.closedGeometry});};isPolygon=()=>this.mode==="polygon"&&this.getClosedGeometry();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 ae=class{constructor(e){this.ctx=e;this.#e=this.ctx.map.getCanvasContainer(),this.#e.style.cursor=e.mode.getMode()?g.CROSSHAIR:g.AUTO,this.#t();}#e;set=e=>{this.#e.style.cursor=e;};get=()=>this.#e.style.cursor;handleMouseLeave=A(()=>{let{mouseEvents:e,mode:t}=this.ctx;if(!e.pointMouseDown){if(!t.getMode()){this.set(g.AUTO);return}t.getClosedGeometry()?this.set(g.AUTO):this.set(g.CROSSHAIR);}},10);handleFirstPointMouseEnter=A(()=>{let{store:e}=this.ctx;e.circular.canClose()&&this.set(g.POINTER);},10);#t(){let{mouseEvents:e,mode:t}=this.ctx;e.addObserver(this.#i),t.addObserver(this.#o);}remove(){let{mouseEvents:e,mode:t}=this.ctx;e.removeObserver(this.#i),t.removeObserver(this.#o),this.handleMouseLeave.cancel(),this.handleFirstPointMouseEnter.cancel();}#o=e=>{let{mode:t}=this.ctx;t.getBreak()||e.type==="CLOSED_GEOMETRY_CHANGED"&&e.data||this.set(t.getMode()&&!t.getClosedGeometry()?g.CROSSHAIR:g.AUTO);};#i=e=>{let{mode:t,mouseEvents:i,store:n,options:s}=this.ctx;if(t.getBreak())return;let{type:a,data:p}=e;if(p)switch(a){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":n.circular.isCircular()||this.set(g.POINTER);break;case"lastPointMouseLeave":this.handleMouseLeave();break;}}};var qe=class{constructor(e,t){this.source=e;this.project=t;}#e=!0;#t=[];#o=[];invalidate=()=>{this.#e=!0;};read=()=>{if(this.#e){let{head:e,isCircular:t}=this.source();this.#t=wt(e,t),this.#o=this.#t.map(i=>this.project(i.val)),this.#e=!1;}return {nodes:this.#t,pixels:this.#o}}},wt=(o,e)=>{let t=[],i=new Set,n=o;for(;n&&!i.has(n);)i.add(n),n.val&&t.push(n),n=n.next;return e&&o?.val&&t.length>1&&t.push(o),t},le=(o,e)=>{let t=null;for(let i=0;i<o.length;i++){let n=o[i];if(!n)continue;let s=Math.hypot(e.x-n.x,e.y-n.y);(!t||s<t.distance)&&(t={index:i,distance:s});}return t},at=(o,e)=>{let t=null;for(let i=0;i<o.length-1;i++){let n=o[i],s=o[i+1];if(!n||!s)continue;let a=s.x-n.x,p=s.y-n.y,u=a*a+p*p,T=u===0?0:((e.x-n.x)*a+(e.y-n.y)*p)/u,M=Math.min(1,Math.max(0,T)),G={x:n.x+a*M,y:n.y+p*M},$e=Math.hypot(e.x-G.x,e.y-G.y);(!t||$e<t.distance)&&(t={index:i,projected:G,t:M,distance:$e});}return t},Tt=2,pe=class{constructor(e){this.ctx=e;this.#e=new qe(()=>({head:e.store.head,isCircular:e.store.circular.isCircular()}),t=>e.map.project(t)),e.store.addObserver(this.#e.invalidate),e.map.on("move",this.#e.invalidate);}#e;remove=()=>{this.ctx.store.removeObserver(this.#e.invalidate),this.ctx.map.off("move",this.#e.invalidate);};#t=(e,t)=>{let{map:i}=this.ctx,n=Math.round((i.unproject([e.x,e.y]).lng-t.lng)/360);if(n===0)return e;let s=i.project(t),a=i.project({lng:t.lng+360,lat:t.lat});return {x:e.x-(a.x-s.x)*n,y:e.y-(a.y-s.y)*n}};hit=e=>{let{nodes:t,pixels:i}=this.#e.read(),n=t[0]?.val;if(!n)return null;let s=this.#t(e,n),a=at(i,s);if(!a||a.distance>this.ctx.options.interaction.lineHitRadius*Tt)return null;let p=t[a.index];if(!p)return null;let u=le(i,s),T=this.ctx.map.unproject([a.projected.x,a.projected.y]);return {segmentStart:p,projected:{lat:T.lat,lng:T.lng},distance:a.distance,vertexDistance:u?u.distance:1/0}};isNearGeometry=e=>{let{nodes:t,pixels:i}=this.#e.read(),n=t[0]?.val;if(!n)return !1;let s=this.#t(e,n),a=le(i,s);if(a&&a.distance<=this.ctx.options.interaction.pointHitRadius)return !0;let p=at(i,s);return p!==null&&p.distance<=this.ctx.options.interaction.lineHitRadius}};var ce=class extends x{#e;#t;#o;#i;#n;#s;#r;#a;#l;#p;#c;#d;constructor(){super(),this.#e=!1,this.#t=!1,this.#o=!1,this.#i=!1,this.#n=!1,this.#s=!1,this.#r=!1,this.#a=!1,this.#l=!1,this.#p=!1,this.#c=!1,this.#d=!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.#o}set lastPointMouseClick(e){this.#o=e,this.notify({type:"lastPointMouseClick",data:e});}get lastPointMouseUp(){return this.#i}set lastPointMouseUp(e){this.#i=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.#p}set pointMouseLeave(e){this.#p=e,this.notify({type:"pointMouseLeave",data:e});}get lineMouseEnter(){return this.#c}set lineMouseEnter(e){this.#c=e,this.notify({type:"lineMouseEnter",data:e});}get lineMouseLeave(){return this.#d}set lineMouseLeave(e){this.#d=e,this.notify({type:"lineMouseLeave",data:e});}};var Ye=o=>o?{lineHitRadius:12,pointHitRadius:20}:{lineHitRadius:7,pointHitRadius:14},m={pointGeneration:"manual",panel:{size:"medium",buttons:{undo:{visible:!1},redo:{visible:!1},delete:{visible:!1},save:{visible:!1,clearOnSave:!0}}},modes:{initial:null,line:{visible:!0,closeGeometry:!0},polygon:{visible:!0},breakGeometry:{visible:!0}},layersPaint:{auxiliaryPoint:D,onLinePoint:k,firstPoint:N,points:I,line:R,dynamicLine:J,polygon:F,breakLine:B},interaction:Ye(!1),initial:null,dynamicLine:!0,locale:{save:"Save",delete:"Delete all",undo:"Undo",redo:"Redo",line:"Line",polygon:"Polygon",break:"Split",closeLine:"Close the line",createPolygon:"Create a polygon",removePoint:"Remove point"}};function At(o){return o.every(e=>"id"in e&&e.id!==void 0)}function Ot(o,e){let t=!e,i=!At(o);if(t&&i)throw new Error(L.MISSING_IDS)}function Nt(o){if(!o.length)throw new Error(L.EMPTY_INITIAL_STATE)}function Dt(o,e){let i=new Set(o.map(n=>`${n.lng},${n.lat}`)).size;if(e&&i<3)throw new Error(L.NOT_ENOUGH_POINTS_TO_CLOSE)}function kt(o){let{closeGeometry:e,steps:t}=o;if(t){let i=t[0]?.lng,n=t[t.length-1]?.lng,s=t[0]?.lat,a=t[t.length-1]?.lat;if((i!==n||s!==a)&&e)throw new Error(L.FIRST_LAST_POINT_NOT_EQUAL)}}function pt(o){let{closeGeometry:e,generateId:t,steps:i}=o;Nt(i),Ot(i,t),Dt(i,e),kt(o);}function ct(o){let e=Ye(lt("(pointer: coarse)")),t=!lt("(hover: none)");return o?{pointGeneration:o.pointGeneration??m.pointGeneration,panel:Rt(o),modes:It(o),layersPaint:Bt(o),interaction:e,initial:o.initial||m.initial,locale:_t(o),dynamicLine:(o.dynamicLine??m.dynamicLine)&&t}:{...m,interaction:e,dynamicLine:t}}var lt=o=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(o).matches:!1;function Rt(o){return {size:o.panel?.size||m.panel.size,buttons:{undo:{visible:o.panel?.buttons?.undo?.visible??m.panel.buttons.undo.visible},redo:{visible:o.panel?.buttons?.redo?.visible??m.panel.buttons.redo.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 It(o){return {initial:o.modes?.initial||m.modes.initial,line:{visible:o?.modes?.line?.visible!==void 0?o.modes.line.visible:o?.initial?.geometry==="line"||m.modes.line.visible,closeGeometry:o?.modes?.line?.closeGeometry??m.modes.line.closeGeometry},polygon:{visible:o?.modes?.polygon?.visible!==void 0?o.modes.polygon.visible:o?.initial?.geometry==="polygon"||m.modes.polygon.visible},breakGeometry:{visible:o?.modes?.breakGeometry?.visible??m.modes.breakGeometry.visible}}}function Bt(o){let e=o.layersPaint,t={"line-width":e?.line?.["line-width"]||R["line-width"],"line-color":e?.line?.["line-color"]||R["line-color"],"line-opacity":e?.line?.["line-opacity"]||R["line-opacity"],...e?.line};return {onLinePoint:{"circle-radius":e?.onLinePoint?.["circle-radius"]||k["circle-radius"],"circle-color":e?.onLinePoint?.["circle-color"]||k["circle-color"],"circle-stroke-color":e?.onLinePoint?.["circle-stroke-color"]||k["circle-stroke-color"],"circle-stroke-width":e?.onLinePoint?.["circle-stroke-width"]||k["circle-stroke-width"],...e?.onLinePoint},firstPoint:{"circle-radius":e?.firstPoint?.["circle-radius"]||N["circle-radius"],"circle-color":e?.firstPoint?.["circle-color"]||N["circle-color"],"circle-stroke-color":e?.firstPoint?.["circle-stroke-color"]||N["circle-stroke-color"],"circle-stroke-width":e?.firstPoint?.["circle-stroke-width"]||N["circle-stroke-width"],...e?.firstPoint},points:{"circle-radius":e?.points?.["circle-radius"]||I["circle-radius"],"circle-color":e?.points?.["circle-color"]||I["circle-color"],"circle-stroke-color":e?.points?.["circle-stroke-color"]||I["circle-stroke-color"],"circle-stroke-width":e?.points?.["circle-stroke-width"]||I["circle-stroke-width"],...e?.points},auxiliaryPoint:{"circle-radius":e?.auxiliaryPoint?.["circle-radius"]||D["circle-radius"],"circle-color":e?.auxiliaryPoint?.["circle-color"]||D["circle-color"],"circle-stroke-color":e?.auxiliaryPoint?.["circle-stroke-color"]||D["circle-stroke-color"],"circle-stroke-width":e?.auxiliaryPoint?.["circle-stroke-width"]||D["circle-stroke-width"],...e?.auxiliaryPoint},line:t,dynamicLine:{...t,"line-dasharray":J["line-dasharray"],...e?.dynamicLine},polygon:{"fill-color":e?.polygon?.["fill-color"]||F["fill-color"],"fill-opacity":e?.polygon?.["fill-opacity"]||F["fill-opacity"],...e?.polygon},breakLine:{"line-width":e?.breakLine?.["line-width"]||B["line-width"],"line-color":e?.breakLine?.["line-color"]||B["line-color"],"line-dasharray":e?.breakLine?.["line-dasharray"]||B["line-dasharray"],...e?.breakLine}}}function _t(o){return {save:o.locale?.save??m.locale.save,delete:o.locale?.delete??m.locale.delete,undo:o.locale?.undo??m.locale.undo,redo:o.locale?.redo??m.locale.redo,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,removePoint:o.locale?.removePoint??m.locale.removePoint}}var de=class{constructor(e,t,i,n,s){this.store=e;this.options=t;this.mode=i;this.current=n;this.clickCoords=s;}type="STORE_BREAK_GEOMETRY";snapshot={originalHead:null,originalTail:null,newHead:null,newTail:null,newAuxBetweenHeadTail:null};makeSnapshot=()=>{this.snapshot.originalHead=this.store.head,this.snapshot.originalTail=this.store.tail,this.snapshot.newAuxBetweenHeadTail=this.current.val?.isAuxiliary?this.current:this.current.next;};execute=()=>{this.makeSnapshot(),this.store.circular.break(this.current),this.mode.setClosedGeometry(!1),this.snapshot.newHead=this.store.head,this.snapshot.newTail=this.store.tail,this.store.notify({type:"STORE_BREAK_GEOMETRY",data:{coords:this.clickCoords}});};restoreOriginalHeadTail=()=>{let{originalHead:e,originalTail:t}=this.snapshot;this.store.head=e,this.store.tail=t,this.store.head&&(this.store.head.prev=this.store.tail),this.store.tail&&(this.store.tail.next=this.store.head);};restoreAuxBetweenNewHeadTail=()=>{let{newHead:e,newTail:t,newAuxBetweenHeadTail:i}=this.snapshot;e&&t&&(t.next=i,i.prev=t,i.next=e,e.prev=i,i?.val&&(this.store.map.set(i?.val.id,i),this.store.size+=1));};undo=()=>{this.restoreOriginalHeadTail(),this.store.circular.close(),this.store.notify({type:"STORE_CLOSE_GEOMETRY"});let{newHead:e,newTail:t}=this.snapshot;e&&t&&(this.options.pointGeneration==="auto"?this.restoreAuxBetweenNewHeadTail():(t.next=e,e.prev=t)),this.mode.setClosedGeometry(!0),this.store.pingConsumers();}};var ue=class{constructor(e){this.ctx=e;this.current=null;}current;renderBreakSegment=C(e=>{this.onLineEnterBreak(e);});initBreakEvents=()=>{this.ctx.map.on("click",r.LineLayer,this.geometryBreakOnClick),this.ctx.map.on("mouseenter",r.LineLayer,this.renderBreakSegment),this.ctx.map.on("mousemove",r.LineLayer,this.renderBreakSegment),this.ctx.map.on("mouseleave",r.LineLayer,this.onLineLeave);};removeBreakEvents=()=>{this.ctx.map.off("click",r.LineLayer,this.geometryBreakOnClick),this.ctx.map.off("mouseenter",r.LineLayer,this.renderBreakSegment),this.ctx.map.off("mousemove",r.LineLayer,this.renderBreakSegment),this.ctx.map.off("mouseleave",r.LineLayer,this.onLineLeave),this.renderBreakSegment.cancel();};hideBreakLine=()=>{this.ctx.map.getLayoutProperty(r.LineLayerBreak,"visibility")!=="none"&&this.ctx.map.setLayoutProperty(r.LineLayerBreak,"visibility","none");};showBreakLine=()=>{this.ctx.map.getLayoutProperty(r.LineLayerBreak,"visibility")!=="visible"&&this.ctx.map.setLayoutProperty(r.LineLayerBreak,"visibility","visible");};geometryBreakOnClick=e=>{let{store:t,mode:i,map:n,options:s}=this.ctx;this.current&&(h.commit(new de(t,s,i,this.current,e.lngLat)),this.onLineLeave(),i.reset(),f.execute(),d.onLineBreak(n));};getAutoGenerationPoints=e=>{let t=null,i=null;return e?.val?.isAuxiliary?(t=[e?.prev?.val?.lng,e?.prev?.val?.lat],i=[e?.next?.val?.lng,e?.next?.val?.lat]):(t=[e?.val?.lng,e?.val?.lat],i=[e?.next?.next?.val?.lng,e?.next?.next?.val?.lat]),{current:t,next:i}};getLinePoints=e=>{if(this.ctx.options.pointGeneration==="manual"){let t=[e?.val?.lng,e?.val?.lat],i=[e?.next?.val?.lng,e?.next?.val?.lat];return {current:t,next:i}}return this.getAutoGenerationPoints(e)};onLineEnterBreak=e=>{let{map:t}=this.ctx,i=this.ctx.projection.hit(e.point)?.segmentStart??null;i?.val?.id!==this.current?.val?.id&&(this.current=i);let n=t.getSource(c.LineSourceBreak),{current:s,next:a}=this.getLinePoints(this.current),p=X(s,a);p&&(n.setData(p),this.showBreakLine());};onLineLeave=()=>{this.renderBreakSegment.cancel(),this.hideBreakLine();}};var V=[r.PointsHitLayer,r.FirstPointHitLayer,r.AuxiliaryPointHitLayer],H=(o,e)=>o.target.queryRenderedFeatures(o.point,{layers:e}).some(i=>e.includes(i.layer.id)),w=(o,e)=>Ht(o,e)?.properties.id,Ht=(o,e)=>{let t=o.queryRenderedFeatures(e,{layers:V});if(t.length<2)return t[0];let i=o.unproject(e).lng,n=t.map(a=>{let[p,u]=a.geometry.coordinates;return o.project({lng:p+360*Math.round((i-p)/360),lat:u})}),s=le(n,e);return s?t[s.index]:void 0},dt=(o,e)=>{let t=o.head,i=0,n=new Set;for(;t!==null&&!n.has(t.val?.id);){if(t.val?.id===e)return i;n.add(t.val?.id),i++,t=t.next;}return -1};function he(o){return o.originalEvent.button===2}var me=class{constructor(e,t,i){this.store=e;this.segmentStart=i;this.step={id:b(),isAuxiliary:!1,...t},this.payload={node:this.step};}type="STORE_POINT_INSERTED";payload;step;snapshot={insertedNode:null};restoreInsertedNode=e=>{let t=e.prev,i=e.next;t?t.next=e:this.store.head=e,i?i.prev=e:this.store.tail=e,this.store.tail===t&&this.store.head===i&&(this.store.tail=e,this.store.head&&(this.store.head.prev=e)),e.val&&!this.store.map.has(e.val.id)&&(this.store.map.set(e.val.id,e),this.store.size++,this.store.pingConsumers());};execute=()=>{this.snapshot.insertedNode?this.restoreInsertedNode(this.snapshot.insertedNode):this.snapshot.insertedNode=this.store.insertAfter(this.segmentStart,this.step),this.store.notify({type:"STORE_POINT_INSERTED"});};undo=()=>{this.store.removeNodeById(this.step.id);}};var ut=(o,e)=>{let{store:t,options:i,projection:n}=e,s=n.hit(o.point);if(!s||s.vertexDistance<i.interaction.pointHitRadius)return null;let a={...s.projected,isAuxiliary:!1,id:b()};return h.commit(new me(t,a,s.segmentStart)),a},ht=(o,e)=>{let{store:t}=e;t.tail?.val&&(y.setSinglePointHidden(o),f.execute());},mt=o=>H(o,V),vt=o=>{let e=o.getSource(c.LineDynamicSource);e&&e.setData(Ze),o.getLayer(r.LineDynamicLayer)&&o.setLayoutProperty(r.LineDynamicLayer,"visibility","none");};var ve=class{constructor(e){this.ctx=e;this.visible=!0,this.onStoreEventsDebounced=A(this.onStoreEventsConsumer,10),this.initConsumers(),this.initDynamicEvents();}visible;firstPoint=null;secondPoint=null;pointer=null;lineFeature;subscriptions=[];onStoreEventsDebounced;renderFreeEnd=C(e=>{this.renderLineOnMouseMove(e.lngLat);});initConsumers(){this.ctx.store.addObserver(this.onStoreEventsDebounced),this.ctx.mouseEvents.addObserver(this.onMouseEventsConsumer),this.ctx.mode.addObserver(this.mapModeConsumer);}removeConsumers=()=>{this.ctx.store.removeObserver(this.onStoreEventsDebounced),this.onStoreEventsDebounced.cancel(),this.ctx.mouseEvents.removeObserver(this.onMouseEventsConsumer),this.ctx.mode.removeObserver(this.mapModeConsumer);};mapModeConsumer=e=>{e.type==="MODE_CHANGED"&&!e.data&&this.hide();};onMouseEventsConsumer=e=>{let{store:t}=this.ctx;if(this.ctx.mode.getMode()===null)return;if(t.circular.isCircular()){this.hide();return}if(e.type==="lastPointMouseClick"&&e.data&&(this.hide(),this.visible=!1),!this.visible)return;if(["pointMouseEnter","lineMouseEnter","pointMouseDown"].includes(e.type)&&e.data&&this.hide(),e.type==="pointMouseLeave"||e.type==="lineMouseLeave"){let{store:n}=this.ctx;if(n.circular.isCircular())return;e.data&&(this.firstPoint=n.tail?.val,this.secondPoint=n.tail?.val,this.show());}};onStoreEventsConsumer=e=>{let{store:t}=this.ctx;if(this.ctx.mode.getMode()!==null){if(t.circular.isCircular()){this.hide();return}if(e.type==="STORE_CLOSE_GEOMETRY"||e.type==="STORE_CLEARED")this.hide();else if(e.type==="STORE_BREAK_GEOMETRY")this.firstPoint=t.tail?.val,this.secondPoint=e.data?.coords,this.show(),this.visible=!0;else if(e.type==="STORE_POINT_ADD")t.size>0&&(this.firstPoint=t.tail?.val,this.secondPoint=this.freeEnd(),this.show(),this.visible=!0);else if(e.type==="STORE_MUTATED"){if(this.ctx.mouseEvents.pointMouseDown||t.size===0||(this.firstPoint=t.tail?.val,this.ctx.mouseEvents.pointMouseEnter))return;this.secondPoint=this.freeEnd(),this.show(),this.visible=!0;}}};initDynamicEvents=()=>{let{map:e,events:t}=this.ctx;e.on("click",this.onMapClick),e.on("mousemove",this.renderFreeEnd),this.subscriptions=[t.on("mdl:removeall",this.hide),t.on("mdl:undo",this.onUndoRedoClick),t.on("mdl:redo",this.onUndoRedoClick),t.on("mdl:pointremove",this.onPointRemove)],l.addEventListener(e.getContainer(),"pointermove",this.onPointerMove);};removeEvents=()=>{let{map:e}=this.ctx;e.off("click",this.onMapClick),e.off("mousemove",this.renderFreeEnd),this.renderFreeEnd.cancel();for(let t of this.subscriptions)t.unsubscribe();this.subscriptions=[],l.removeEventListener(e.getContainer(),"pointermove",this.onPointerMove);};hide=()=>{let{map:e}=this.ctx;this.firstPoint=null,this.secondPoint=null,this.lineFeature=null,e.off("mousemove",this.renderFreeEnd),this.renderFreeEnd.cancel(),vt(e);};show=()=>{let{map:e,store:t}=this.ctx;if(t.size&&this.firstPoint?.lat&&this.firstPoint.lng&&this.secondPoint?.lng&&this.secondPoint?.lat){let i=[this.firstPoint.lng,this.firstPoint.lat],n=[this.secondPoint.lng,this.secondPoint.lat];this.lineFeature=X(i,n),e.setLayoutProperty(r.LineDynamicLayer,"visibility","visible"),this.secondPoint&&this.renderLineOnMouseMove({lng:this.secondPoint?.lng,lat:this.secondPoint?.lat});}e.on("mousemove",this.renderFreeEnd);};renderLineOnMouseMove=e=>{if(!this.lineFeature)return;let{map:t}=this.ctx;this.lineFeature.features[0].geometry.coordinates[1]=[e.lng,e.lat];let i=t.getSource(c.LineDynamicSource);i&&i.setData(this.lineFeature);};onPointerMove=e=>{let{map:t}=this.ctx,{clientX:i,clientY:n}=e,s=t.getContainer().getBoundingClientRect(),a=t.unproject([i-s.left,n-s.top]);this.pointer={lng:a.lng,lat:a.lat};};freeEnd=()=>{let{store:e}=this.ctx;return this.pointer??e.tail?.val};onMapClick=e=>{let{mode:t}=this.ctx,i=H(e,[r.LineLayerTransparent,r.LineLayer]);i&&t.getBreak()&&(this.secondPoint={lng:e.lngLat.lng,lat:e.lngLat.lat}),!i&&this.hide();};onUndoRedoClick=()=>{let{store:e}=this.ctx;e.circular.isCircular()||(this.firstPoint=e.tail?.val,this.secondPoint=this.freeEnd(),this.show()),e.size===0&&this.hide();};onPointRemove=()=>{let{store:e}=this.ctx;e.circular.isCircular()||(this.firstPoint=e.tail?.val,this.secondPoint=this.freeEnd(),this.show()),e.size===0&&this.hide();}};var fe=class{constructor(e){this.ctx=e;this.initConsumers();}eventsInited=!1;initConsumers=()=>{this.ctx.mode.addObserver(this.mapModeConsumer);};removeConsumers=()=>{this.ctx.mode.removeObserver(this.mapModeConsumer);};mapModeConsumer=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&!i?this.eventsInited&&this.removeEvents():t==="MODE_CHANGED"&&i&&(this.eventsInited||this.initEvents());};initEvents(){this.eventsInited||(this.ctx.map.on("click",r.LineLayerTransparent,this.onLineClick),this.ctx.map.on("mousemove",r.LineLayerTransparent,this.onLineMove),this.ctx.map.on("mouseenter",r.LineLayerTransparent,this.onLineEnter),this.ctx.map.on("mouseleave",r.LineLayerTransparent,this.onLineLeave),this.eventsInited=!0);}removeEvents(){this.ctx.map.off("click",r.LineLayerTransparent,this.onLineClick),this.ctx.map.off("mousemove",r.LineLayerTransparent,this.onLineMove),this.ctx.map.off("mouseenter",r.LineLayerTransparent,this.onLineEnter),this.ctx.map.off("mouseleave",r.LineLayerTransparent,this.onLineLeave),this.renderGhostPoint.cancel(),this.eventsInited=!1;}onLineClick=e=>{let{store:t,map:i,mode:n}=this.ctx;if(mt(e))return;let s=ut(e,this.ctx);s&&(ht(e,this.ctx),d.addPoint({...s,total:t.size},i,n));};hitClearOfVertices=e=>{let t=this.ctx.projection.hit(e.point);return !t||t.vertexDistance<this.ctx.options.interaction.pointHitRadius?null:t};processMouseMove=e=>{let t=this.hitClearOfVertices(e);if(!t){y.setSinglePointHidden(e);return}if(y.setSinglePointVisible(e),e.target.getLayer(r.SinglePointLayer)){let n=e.target.getSource(c.SinglePointSource);n&&n.setData({type:"Feature",geometry:{type:"Point",coordinates:[t.projected.lng,t.projected.lat]},properties:{}});}};onLineMove=e=>{this.ctx.mouseEvents.pointMouseDown||this.ctx.mouseEvents.pointMouseEnter||this.renderGhostPoint(e);};renderGhostPoint=C(e=>{this.processMouseMove(e);});onLineEnter=e=>{this.ctx.mouseEvents.pointMouseDown||this.ctx.mouseEvents.pointMouseEnter||this.hitClearOfVertices(e)&&(this.ctx.mouseEvents.lineMouseEnter=!0,y.setSinglePointVisible(e));};onLineLeave=e=>{this.renderGhostPoint.cancel(),!(this.ctx.mouseEvents.pointMouseDown||this.ctx.mouseEvents.pointMouseEnter)&&(this.ctx.mouseEvents.lineMouseLeave=!0,y.setSinglePointHidden(e));}};var ye=class{constructor(e){this.ctx=e;this.break=new ue(e),this.transparent=e.options.pointGeneration==="manual"?new fe(e):null,this.dynamic=null,this.type="default";}break;transparent;dynamic;type;init(){this.initDynamicLine(),this.initEvents(),this.initConsumers();}initDynamicLine=()=>{this.ctx.options.dynamicLine&&(this.dynamic=new ve(this.ctx));};initEvents(){!this.ctx.mode.getBreak()&&this.transparent?.initEvents();}initConsumers(){this.ctx.mode.addObserver(this.mapModeConsumer),this.ctx.mouseEvents.addObserver(this.mouseEventsConsumer);}remove(){this.removeConsumers(),this.removeEvents();}removeConsumers(){this.ctx.mode.removeObserver(this.mapModeConsumer),this.ctx.mouseEvents.removeObserver(this.mouseEventsConsumer),this.transparent?.removeConsumers(),this.ctx.options.dynamicLine&&this.dynamic?.removeConsumers();}removeEvents(){this.break.removeBreakEvents(),this.transparent?.removeEvents(),this.ctx.options.dynamicLine&&(this.dynamic?.removeEvents(),this.dynamic?.hide());}mouseEventsConsumer=e=>{let{type:t,data:i}=e,{mode:n}=this.ctx;if(!(!i||!n.getBreak()||n.getMode()===null))switch(t){case"pointMouseDown":this.break.removeBreakEvents(),this.break.hideBreakLine();break;case"pointMouseUp":this.break.initBreakEvents();break;}};mapModeConsumer=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&this.type==="break"&&(this.break.removeBreakEvents(),i&&this.transparent?.initEvents(),this.type="default"),t==="BREAK_CHANGED"&&i&&this.type==="default"&&(this.transparent?.removeEvents(),this.break.initBreakEvents(),this.type="break");}};var Gt=(o,e)=>{let t=e?.["circle-radius"];o.setPaintProperty(r.FirstPointLayer,"circle-radius",typeof t=="number"?t+1:t??O.large),o.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",K.large);},Ft=(o,e)=>{o.setPaintProperty(r.FirstPointLayer,"circle-radius",e?.["circle-radius"]??O.default),o.setPaintProperty(r.FirstPointLayer,"circle-stroke-color",e?.["circle-stroke-color"]??K.default);},je=(o,e,t)=>{e==="large"?Gt(o,t):Ft(o,t);};var ge=class{constructor(e,t,i){this.store=e;this.mode=t;this.options=i;this.type="STORE_CLOSE_GEOMETRY";}type="STORE_CLOSE_GEOMETRY";auxPointSnapshot=null;restoreAuxPoint=()=>{this.auxPointSnapshot?.val&&(this.store.head.prev=this.auxPointSnapshot,this.store.tail.next=this.auxPointSnapshot,this.auxPointSnapshot.prev=this.store.tail,this.auxPointSnapshot.next=this.store.head,this.store.tail=this.auxPointSnapshot,this.store.map.set(this.auxPointSnapshot.val.id,this.auxPointSnapshot),this.store.size++,this.store.pingConsumers());};execute=()=>{if(this.options.pointGeneration==="auto"&&this.store.tail?.val)if(this.auxPointSnapshot)this.restoreAuxPoint();else {let e=v.createAuxiliaryPoint(this.store.tail?.val,this.store.head?.val);this.auxPointSnapshot=this.store.push(e);}this.store.circular.close(),this.mode.setClosedGeometry(!0),this.store.notify({type:this.type});};undo=()=>{this.options.pointGeneration==="auto"&&this.store.removeNodeById(this.store.tail?.val?.id),this.store.tail?.val&&this.store.head?.val&&(this.store.tail.next=null,this.store.head.prev=null),this.mode.setClosedGeometry(!1),this.store.notify({type:"STORE_BREAK_GEOMETRY"});}};var Ee=class{constructor(e,t){this.ctx=e;this.baseEvents=t;this.mouseDown=!1,this.tooltip=new S,this.initLayer(),this.init();}mouseDown;tooltip;eventsInited=!1;initConsumers=()=>{let{mode:e,store:t}=this.ctx;e.addObserver(this.onMapModeChangeConsumer),t.addObserver(this.onStoreChangeConsumer);};removeConsumers=()=>{let{mode:e,store:t}=this.ctx;e.removeObserver(this.onMapModeChangeConsumer),t.removeObserver(this.onStoreChangeConsumer);};initLayer(){let{map:e}=this.ctx;e.getLayer(r.FirstPointLayer)&&y.setFirstPointVisible(e);}initBaseEvents=()=>{let{map:e}=this.ctx;e.on("mouseenter",r.FirstPointHitLayer,this.baseEvents.onPointMouseEnter),e.on("mouseleave",r.FirstPointHitLayer,this.baseEvents.onPointMouseLeave),e.on("mousedown",r.FirstPointHitLayer,this.baseEvents.onPointMouseDown),e.on("touchstart",r.FirstPointHitLayer,this.baseEvents.onPointMouseDown);};initEvents=()=>{let{map:e}=this.ctx;e.on("click",r.FirstPointHitLayer,this.onFirstPointClick),e.on("mouseenter",r.FirstPointHitLayer,this.onFirstPointMouseEnter),e.on("mouseleave",r.FirstPointHitLayer,this.onFirstPointMouseLeave),e.on("mousedown",r.FirstPointHitLayer,this.onFirstPointMouseDown),e.on("mouseup",this.onFirstPointMouseUp),this.initBaseEvents(),this.eventsInited=!0;};init(){this.initEvents(),this.initConsumers();}removeBaseEvents=()=>{let{map:e}=this.ctx;e.off("mouseenter",r.FirstPointHitLayer,this.baseEvents.onPointMouseEnter),e.off("mouseleave",r.FirstPointHitLayer,this.baseEvents.onPointMouseLeave),e.off("mousedown",r.FirstPointHitLayer,this.baseEvents.onPointMouseDown),e.off("touchstart",r.FirstPointHitLayer,this.baseEvents.onPointMouseDown);};removeEvents(){let{map:e}=this.ctx;e.off("click",r.FirstPointHitLayer,this.onFirstPointClick),e.off("mouseenter",r.FirstPointHitLayer,this.onFirstPointMouseEnter),e.off("mouseleave",r.FirstPointHitLayer,this.onFirstPointMouseLeave),e.off("mousedown",r.FirstPointHitLayer,this.onFirstPointMouseDown),e.off("mouseup",this.onFirstPointMouseUp),this.removeBaseEvents(),this.eventsInited=!1;}remove(){this.removeEvents(),this.removeConsumers();}onMapModeChangeConsumer=e=>{let{map:t,options:i}=this.ctx,{type:n,data:s}=e;n==="MODE_CHANGED"&&!s?this.eventsInited&&this.removeEvents():n==="MODE_CHANGED"&&s&&(this.eventsInited||this.initEvents()),n==="MODE_CHANGED"&&(s==="line"&&!i.modes.line.closeGeometry?(y.setFirstPointHidden(t),Ue.closedGeometry(t)):(y.setFirstPointVisible(t),Ue.default(t)));};onStoreChangeConsumer=e=>{let{map:t,store:i}=this.ctx,{type:n}=e;if(["STORE_MUTATED","STORE_POINT_INSERTED","STORE_CLOSE_GEOMETRY","STORE_BREAK_GEOMETRY","STORE_CLEARED"].includes(n)){let a=this.ctx.options.layersPaint.firstPoint;i.circular.canClose()?je(t,"large",a):je(t,"default",a);}};onFirstPointClick=()=>{let{store:e,mode:t,options:i}=this.ctx;e.circular.canClose()&&(h.commit(new ge(e,t,i)),f.execute());};onFirstPointMouseDown=()=>{this.mouseDown=!0,this.tooltip.remove();};onFirstPointMouseUp=()=>{this.mouseDown=!1;};onFirstPointMouseLeave=()=>{let{mouseEvents:e}=this.ctx;this.mouseDown||(e.firstPointMouseLeave=!0,this.tooltip.remove());};getTitle=()=>{let{mode:e,options:t}=this.ctx;return e.getMode()==="line"&&t.modes.line.closeGeometry?t.locale.closeLine:e.getMode()==="polygon"?t.locale.createPolygon:""};onFirstPointMouseEnter=e=>{let{mode:t,mouseEvents:i,store:n}=this.ctx;if(i.firstPointMouseEnter=!0,!(t.getClosedGeometry()||this.mouseDown)&&n.circular.canClose()){let{x:s,y:a}=e.originalEvent;if(s&&a){this.tooltip.create({label:this.getTitle(),placement:"bottom"});let u=this.tooltip.label?this.tooltip.label.clientWidth/2:0;this.tooltip.setPosition({x:s-u,y:a+14});}}}};var Ut=3,zt=[r.LineLayerTransparent,r.PointsHitLayer,r.FirstPointHitLayer,r.AuxiliaryPointHitLayer],Le=class{constructor(e){this.map=e;}pressPoint=null;saved=null;press=e=>{this.pressPoint={x:e.x,y:e.y};};move=e=>{!this.pressPoint||this.saved||Math.hypot(e.x-this.pressPoint.x,e.y-this.pressPoint.y)<=Ut||this.hide();};release=()=>{if(this.pressPoint=null,!!this.saved){for(let[e,t]of this.saved)this.map.getLayer(e)&&this.map.setLayoutProperty(e,"visibility",t);this.saved=null;}};hide(){this.saved=new Map;for(let e of zt){if(!this.map.getLayer(e))continue;let t=this.map.getLayoutProperty(e,"visibility")??"visible";this.saved.set(e,t),this.map.setLayoutProperty(e,"visibility","none");}}};var xe=class{constructor(e,t){this.store=e;this.clickedNode=t;this.snapshot=this.makeSnapshot(this.clickedNode);}type="STORE_AUX_TO_PRIMARY";snapshot=null;makeSnapshot(e){let t=e.prev,i=e.next;return {clickedNode:e,prevPrimaryNode:t,nextPrimaryNode:i,prevAuxNode:null,nextAuxNode:null}}restorePreviousAux=e=>{if(!this.snapshot)return;let{prevPrimaryNode:t,prevAuxNode:i}=this.snapshot;t&&(t.next=i),i&&(i.prev=t),e.prev=i,i&&(i.next=e),i?.val?.id&&!this.store.map.has(i.val.id)&&(this.store.map.set(i?.val?.id,i),this.store.size++);};restoreNextAux=e=>{if(!this.snapshot)return;let{nextPrimaryNode:t,nextAuxNode:i}=this.snapshot;if(e.next=i,i&&(i.prev=e,i.next=t),t&&(t.prev=i),e.next?.next===this.store.head){let s=e.next;this.store.tail=s,this.store.head&&(this.store.head.prev=s),this.store.tail&&(this.store.tail.next=this.store.head);}i?.val?.id&&(this.store.map.set(i.val?.id,i),this.store.size++);};addTwoAuxiliaryPoints=e=>{if(!this.snapshot)return;let{nextPrimaryNode:t,prevPrimaryNode:i}=this.snapshot;if(i)if(this.snapshot.prevAuxNode)this.restorePreviousAux(e);else {let n=v.createAuxiliaryPoint(i.val,e.val);this.snapshot.prevAuxNode=this.store.insertAfter(i,n);}if(t)if(this.snapshot.nextAuxNode)this.restoreNextAux(e);else {let n=v.createAuxiliaryPoint(e.val,t.val);this.snapshot.nextAuxNode=this.store.insertAfter(e,n);}};execute=()=>{if(!this.snapshot)return;let{clickedNode:e}=this.snapshot;e&&e.val&&(e.val.isAuxiliary=!1,this.addTwoAuxiliaryPoints(e));};removeTwoAuxiliaryPoints=e=>{if(!e||!this.snapshot)return;let{prevAuxNode:t,nextAuxNode:i}=this.snapshot;t?.val?.isAuxiliary&&this.store.removeNodeById(t.val?.id),i?.val?.isAuxiliary&&this.store.removeNodeById(i?.val.id);};undo=()=>{if(!this.snapshot)return;let{clickedNode:e}=this.snapshot;e&&e.val&&(e.val.isAuxiliary=!0,this.removeTwoAuxiliaryPoints(e));}};var be=class{constructor(e,t){this.ctx=e;this.baseEvents=t;this.initEvents(),this.initConsumers();}eventsInited=!1;initBaseEvents=()=>{let{map:e}=this.ctx;e.on("mouseenter",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseEnter),e.on("mouseleave",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseLeave),e.on("mousedown",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseDown),e.on("touchstart",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseDown);};removeBaseEvents=()=>{let{map:e}=this.ctx;e.off("mouseenter",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseEnter),e.off("mouseleave",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseLeave),e.off("mousedown",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseDown),e.off("touchstart",r.AuxiliaryPointHitLayer,this.baseEvents.onPointMouseDown);};initConsumers=()=>{this.ctx.mode.addObserver(this.onMapModeChangeConsumer);};removeConsumers=()=>{this.ctx.mode.removeObserver(this.onMapModeChangeConsumer);};onMapModeChangeConsumer=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&!i?this.eventsInited&&this.removeEvents():t==="MODE_CHANGED"&&i&&(this.eventsInited||this.initEvents());};initEvents(){let{map:e}=this.ctx;e.on("mousedown",r.AuxiliaryPointHitLayer,this.onMouseDown),e.on("touchstart",r.AuxiliaryPointHitLayer,this.onMouseDown),this.initBaseEvents(),this.eventsInited=!0;}removeEvents(){let{map:e}=this.ctx;e.off("mousedown",r.AuxiliaryPointHitLayer,this.onMouseDown),e.off("touchstart",r.AuxiliaryPointHitLayer,this.onMouseDown),this.removeBaseEvents(),this.eventsInited=!1;}onMouseDown=e=>{let{store:t,map:i}=this.ctx;if(he(e))return;let n=w(i,e.point),s=t.findNodeById(n);s&&(h.beginTransaction("PointCompound"),h.commit(new xe(t,s)),f.execute());}};var Ce=class{selectedNode=null;selectedIdx=null;startCoordinates=null;enteredStep=null;lastEvent=null;moved=!1;getSelectedNode(){return this.selectedNode}isMoved(){return this.moved}getSelectedIdx(){return this.selectedIdx}getStartCoordinates(){return this.startCoordinates}getEnteredStep(){return this.enteredStep}getLastEvent(){return this.lastEvent}setSelectedNode(e){this.selectedNode=e;}setSelectedIdx(e){this.selectedIdx=e;}setStartCoordinates(e){this.startCoordinates=e;}setEnteredStep(e){this.enteredStep=e;}setLastEvent(e){this.lastEvent=e;}setMoved(e){this.moved=e;}clearLastEvent(){this.lastEvent=null;}reset(){this.selectedNode=null,this.selectedIdx=null,this.startCoordinates=null,this.enteredStep=null,this.lastEvent=null,this.moved=!1;}partialReset(){this.selectedNode=null,this.selectedIdx=null,this.startCoordinates=null,this.lastEvent=null,this.moved=!1;}};var Pe=class{constructor(e,t,i){this.store=e;this.options=t;this.step={id:b(),isAuxiliary:!1,...i};}type="STORE_MUTATED";snapshot={addedNode:null,auxNode:null};step;restoreAddedNode=e=>{e.prev?e.prev.next=e:this.store.head=e,e.next?e.next.prev=e:this.store.tail=e,this.snapshot.addedNode=e,e.val&&(this.store.map.set(e.val.id,e),this.store.size++,this.store.pingConsumers());};restoreAuxNode=e=>{e.prev?e.prev.next=e:this.store.head=e,e.next?e.next.prev=e:this.store.tail=e,this.snapshot.auxNode=e,e.val&&(this.store.map.set(e.val.id,e),this.store.size++,this.store.pingConsumers());};execute=()=>{if(this.snapshot.addedNode?this.restoreAddedNode(this.snapshot.addedNode):this.snapshot.addedNode=this.store.push(this.step),this.options.pointGeneration==="auto"&&this.store.tail?.prev?.val)if(this.snapshot?.auxNode?.val)this.restoreAuxNode(this.snapshot.auxNode);else {let e=v.createAuxiliaryPoint(this.store.tail?.val,this.store.tail?.prev?.val);this.snapshot.auxNode=this.store.insertAfter(this.store.tail.prev,e);}this.store.notify({type:"STORE_POINT_ADD"});};undo=()=>{this.store.removeNodeById(this.step.id),this.options.pointGeneration==="auto"&&this?.snapshot.auxNode?.val&&this.store.removeNodeById(this?.snapshot.auxNode.val.id);};getStep=()=>this.step};var Me=class{constructor(e){this.ctx=e;}type="STORE_INBETWEEN_POINT_REMOVED";snapshot=null;makeSnapshot(e){let{store:t,nodeId:i}=this.ctx,n=t.circular.isCircular(),s=t.head?.val?.id===i,p=(n?t.tail?.prev:t.tail)?.val?.id===i,u=e.prev,T=e.next,M=e.prev?.prev??null,G=e.next?.next??null;return {removedNode:e,wasCircular:n,wasRemovedHead:s,wasRemovedTail:p,beforePrimary:M,afterPrimary:G,beforeAux:u,afterAux:T,newAux:null}}restoreNodeAfter=(e,t)=>{!e||!t||!t.val||(t.prev=e,t.next=e.next,e.next&&(e.next.prev=t),e.next=t,this.ctx.store.map.has(t.val.id)||(this.ctx.store.map.set(t.val.id,t),this.ctx.store.size++,this.ctx.store.pingConsumers()));};recalculateInBetweenRemoved(e){if(!e||!this.snapshot)return;let{store:t}=this.ctx,i=e.prev,n=e.next,s=i?.prev,a=n?.next;i?.val?.isAuxiliary&&t.removeNodeById(i.val.id),n?.val?.isAuxiliary&&t.removeNodeById(n.val.id);let p=t.circular.isCircular()?t.size>=5:t.size>=3;if(s?.val&&a?.val&&p)if(this.snapshot.newAux){let u=t.tail===s&&t.head===s.next;this.restoreNodeAfter(s,this.snapshot.newAux),u&&(t.tail=this.snapshot.newAux);}else {let u=v.createAuxiliaryPoint(s.val,a.val);this.snapshot.newAux=t.insertAfter(s,u);}}breakGeometryIfNeeded=e=>{let{store:t}=e;if(t.circular.canBreak()&&t.circular.isCircular()){if(t.tail?.val?.isAuxiliary){let i=t.tail;if(t.removeNodeById(t.tail.val.id),t.tail=i?.prev,this.snapshot?.newAux)this.restoreNodeAfter(t.head,this.snapshot.newAux);else {let n=v.createAuxiliaryPoint(t.tail?.val,t.head?.val);this.snapshot&&(this.snapshot.newAux=t.insertAfter(t.head,n));}}return t.head&&(t.head.prev=null),t.tail&&(t.tail.next=null),!0}return !1};execute=()=>{let e=this.ctx.store.findNodeById(this.ctx.nodeId),t=e?.val?.isAuxiliary;if(!e||t)return;this.snapshot||(this.snapshot=this.makeSnapshot(e)),this.recalculateInBetweenRemoved(e),this.ctx.store.removeNodeById(this.ctx.nodeId),this.breakGeometryIfNeeded(this.ctx)&&this.ctx.mode.reset(),d.removePoint({...e?.val,total:this.ctx.store.size},this.ctx.map),this.ctx.store.pingConsumers();};restoreRemovedMiddleNode=e=>{if(!this.snapshot||!e.val)return;let{beforePrimary:t,afterPrimary:i,wasCircular:n}=this.snapshot,{store:s,mode:a}=this.ctx;if(t&&(t.next=e,e.prev=t),i&&(e.next=i,i.prev=e),n&&!this.ctx.store.circular.isCircular()){let p=v.createAuxiliaryPoint(s.tail?.val,s.head?.val);s.push(p),s.circular.close(),a.setClosedGeometry(!0);}};restoreRemovedHeadNode=e=>{if(!this.snapshot||!e?.val)return;let{wasCircular:t}=this.snapshot,{store:i,mode:n}=this.ctx,s=this.ctx.store.head;s?(e.next=s,s.prev=e):i.tail=e,i.head=e;let a=!i.circular.isCircular();t&&a&&(i.circular.close(),n.setClosedGeometry(!0));};restoreRemovedTailNode=e=>{let{store:t,mode:i}=this.ctx;if(!this.snapshot)return;let{wasCircular:n}=this.snapshot,s=t.tail;s&&(s.next=e,e.prev=s,t.tail=e);let a=!t.circular.isCircular();n&&a&&(t.circular.close(),i.setClosedGeometry(!0));};restoreAuxiliaryPoints(e){this.snapshot&&(e.prev?.val&&e.val&&this.snapshot?.beforeAux&&(this.restoreNodeAfter(e.prev,this.snapshot?.beforeAux),this.snapshot.wasRemovedHead&&this.snapshot.wasCircular&&(this.ctx.store.tail=this.snapshot.beforeAux)),e.next?.val&&e.val&&this.snapshot?.afterAux&&(this.restoreNodeAfter(e,this.snapshot?.afterAux),this.snapshot.wasRemovedTail&&this.snapshot.wasCircular&&(this.ctx.store.tail=this.snapshot.afterAux)),this.snapshot.wasCircular&&this.ctx.store.circular.close());}undo=()=>{let{store:e}=this.ctx;if(!this.snapshot)return;let{removedNode:t,wasRemovedHead:i,wasRemovedTail:n,wasCircular:s}=this.snapshot;t?.val&&(i?(e.removeNodeById(e.head?.prev?.val?.id),this.restoreRemovedHeadNode(t)):n?(this.restoreRemovedTailNode(t),s&&e.tail?.prev?.val?.isAuxiliary&&e.removeNodeById(e.tail?.prev?.val?.id)):(this.snapshot.newAux?.val?.id&&e.removeNodeById(this.snapshot.newAux?.val?.id),this.restoreRemovedMiddleNode(t)),e.map.has(this.ctx.nodeId)||(e.map.set(this.ctx.nodeId,t),e.size++),this.restoreAuxiliaryPoints(t),e.pingConsumers());}};var Se=class{constructor(e){this.ctx=e;}type="STORE_INBETWEEN_POINT_REMOVED";snapshot=null;makeSnapshot(e){let t=this.ctx.store.head?.val?.id===this.ctx.nodeId,i=this.ctx.store.tail?.val?.id===this.ctx.nodeId,n=this.ctx.store.circular.isCircular();return {removedNode:e,wasCircular:n,wasRemovedHead:t,wasRemovedTail:i}}breakGeometryIfNeeded=e=>{let{store:t}=e;return t.circular.canBreak()&&t.circular.isCircular()?(t.head&&(t.head.prev=null),t.tail&&(t.tail.next=null),!0):!1};execute=()=>{let e=this.ctx.store.findNodeById(this.ctx.nodeId);if(!e?.val)return;this.snapshot=this.makeSnapshot(e),this.ctx.store.removeNodeById(this.ctx.nodeId),this.breakGeometryIfNeeded(this.ctx)&&this.ctx.mode.reset(),d.removePoint({...e?.val,total:this.ctx.store.size},this.ctx.map),this.ctx.store.pingConsumers();};closeGeometryIfNeeded=()=>{let{store:e,mode:t}=this.ctx,i=!this.ctx.store.circular.isCircular();this.snapshot?.wasCircular&&i&&(e.circular.close(),t.setClosedGeometry(!0));};restoreRemovedMiddleNode=e=>{if(!e?.val)return;let{prev:t,next:i}=e;t?(t.next=e,e.prev=t):this.ctx.store.head=e,i?(i.prev=e,e.next=i):this.ctx.store.tail=e;};restoreRemovedHeadNode=e=>{let t=this.ctx.store.head;e?.val&&(t?(e.next=t,t.prev=e):this.ctx.store.tail=e,this.ctx.store.head=e);};restoreRemovedTailNode=e=>{let t=this.ctx.store.tail;t&&(t.next=e,e.prev=t),this.ctx.store.tail=e;};undo=()=>{if(!this.snapshot)return;let{removedNode:e,wasRemovedHead:t,wasRemovedTail:i}=this.snapshot;t?this.restoreRemovedHeadNode(e):i?this.restoreRemovedTailNode(e):this.restoreRemovedMiddleNode(e),this.closeGeometryIfNeeded(),this.ctx.store.map.has(this.ctx.nodeId)||(this.ctx.store.map.set(this.ctx.nodeId,e),this.ctx.store.size++),this.ctx.store.pingConsumers();}};var we=class{constructor(e){this.ctx=e;this.manualPointRemove=new Se(this.ctx),this.autoPointRemove=new Me(this.ctx);}type="STORE_INBETWEEN_POINT_REMOVED";manualPointRemove=null;autoPointRemove=null;execute=()=>{this.ctx.options.pointGeneration==="auto"?this.autoPointRemove?.execute():this.manualPointRemove?.execute();};undo=()=>{this.ctx.options.pointGeneration==="auto"?this.autoPointRemove?.undo():this.manualPointRemove?.undo();}};var Te=class{constructor(e,t){this.ctx=e;this.state=t;}updateMainPoint(e,t){e.val&&(e.val.lat=t.lngLat.lat,e.val.lng=t.lngLat.lng);}updateAuxiliaryPoints(e,t){let i=this.getAuxPointsLatLng(t);i&&(this.updatePrevAuxPoint(e,i.prev),this.updateNextAuxPoint(e,i.next));}updatePrevAuxPoint(e,t){e.prev?.val&&t&&(e.prev.val.lat=t.lat,e.prev.val.lng=t.lng);}updateNextAuxPoint(e,t){e.next?.val&&t&&(e.next.val.lat=t.lat,e.next.val.lng=t.lng);}updateStore=()=>{let e=this.state.getLastEvent(),t=this.state.getSelectedNode();!e||!t?.val||(this.updateMainPoint(t,e),this.updateAuxiliaryPoints(t,e));};getAuxPointsLatLng=e=>{let t=this.state.getSelectedNode();if(!t)return null;let{options:i}=this.ctx,n=t?.prev?.prev,s=t?.next?.next;return i.pointGeneration==="auto"?{next:s?.val?v.getMidpoint(s.val,e.lngLat):null,prev:n?.val?v.getMidpoint(e.lngLat,n.val):null}:null};addPoint(e){let{store:t,options:i}=this.ctx,n=new Pe(t,i,e.lngLat);return h.commit(n),n.getStep()}removePoint(e){let{store:t,options:i,mode:n,map:s}=this.ctx;h.commit(new we({store:t,options:i,mode:n,map:s,nodeId:e}));}};var Ae=class{constructor(e,t,i,n){this.store=e;this.selectedNode=t;this.start=i;this.map=n;this.end={lat:t.val.lat,lng:t.val.lng};}type="STORE_POINT_MOVED";end;updateNeighbors=e=>{let t=e.prev,i=e.next;if(!t?.val?.isAuxiliary&&!i?.val?.isAuxiliary)return;let n=e.prev?.prev,s=e.next?.next;if(n?.val&&this.selectedNode?.val&&t){let a=v.getMidpoint(this.selectedNode?.val,n?.val);t.val&&(t.val.lat=a.lat,t.val.lng=a.lng);}if(s?.val&&this.selectedNode?.val&&i){let a=v.getMidpoint(this.selectedNode?.val,s?.val);i.val&&(i.val.lat=a.lat,i.val.lng=a.lng);}};execute=()=>{if(!this.selectedNode.val)return;let e=this.store.findStepById(this.selectedNode.val?.id);e&&(e.lat=this.end.lat,e.lng=this.end.lng,this.updateNeighbors(this.selectedNode),this.store.notify({type:"STORE_MUTATED",data:this.store}),d.movePoint({id:this.selectedNode.val.id,total:this.store.size,end:{lat:this.selectedNode.val.lat,lng:this.selectedNode.val.lng},start:this.start},this.map));};undo=()=>{if(!this.selectedNode.val)return;let e=this.store.findStepById(this.selectedNode.val?.id);e&&(e.lat=this.start.lat,e.lng=this.start.lng,this.updateNeighbors(this.selectedNode),this.store.notify({type:"STORE_MUTATED",data:this.store}),d.movePoint({id:this.selectedNode.val.id,total:this.store.size,end:this.start,start:this.end},this.map));}};var Vt="mdl-point-remove",Ke="mdl-hidden",Oe=class{button;constructor(e,t){this.button=l.create("button",`${Vt} ${Ke}`,e),this.button.type="button",this.button.setAttribute("data-type","remove-point"),this.button.setAttribute("aria-label",t);}getElement=()=>this.button;getWidth=()=>this.button.offsetWidth;setPosition=(e,t,i)=>{let n=i==="right"?"0, -50%":"-100%, -50%";this.button.style.transform=`translate(${e}px, ${t}px) translate(${n})`,this.button.dataset.side=i;};show=()=>l.removeClassName(this.button,Ke);hide=()=>l.addClassName(this.button,Ke);destroy=()=>l.remove(this.button)};var Je=12,Ne=class{constructor(e){this.ctx=e;this.view=new Oe(e.map.getContainer(),e.options.locale.removePoint);let t=this.view.getElement();l.addEventListener(t,"mouseleave",this.onButtonMouseLeave),l.addEventListener(t,"click",this.onButtonClick);}view;anchor=null;rafId=0;listenersActive=!1;show=e=>{this.anchor=e,this.enableListeners(),this.updatePosition(),this.view.show();};hide=()=>{this.cancelFrame(),this.disableListeners(),this.anchor=null,this.view.hide();};destroy=()=>{this.hide();let e=this.view.getElement();l.removeEventListener(e,"mouseleave",this.onButtonMouseLeave),l.removeEventListener(e,"click",this.onButtonClick),this.view.destroy();};cancelFrame=()=>{this.rafId&&(window.cancelAnimationFrame(this.rafId),this.rafId=0);};enableListeners=()=>{if(this.listenersActive)return;let{map:e}=this.ctx;e.on("move",this.onMapMove),e.on("zoom",this.onMapMove),l.addEventListener(e.getCanvasContainer(),"pointerdown",this.hide),this.listenersActive=!0;};disableListeners=()=>{if(!this.listenersActive)return;let{map:e}=this.ctx;e.off("move",this.onMapMove),e.off("zoom",this.onMapMove),l.removeEventListener(e.getCanvasContainer(),"pointerdown",this.hide),this.listenersActive=!1;};onMapMove=()=>{this.rafId||(this.rafId=window.requestAnimationFrame(()=>{this.rafId=0,this.updatePosition();}));};updatePosition=()=>{if(!this.anchor)return;let{map:e}=this.ctx,t=e.project({lng:this.anchor.lng,lat:this.anchor.lat}),i=e.getContainer().clientWidth;t.x+Je+this.view.getWidth()>i?this.view.setPosition(t.x-Je,t.y,"left"):this.view.setPosition(t.x+Je,t.y,"right");};onButtonMouseLeave=()=>this.hide();onButtonClick=e=>{e.stopPropagation();let t=this.anchor;this.hide(),t&&this.ctx.onRemove(t.id);}};var De=class{constructor(e){this.ctx=e;this.pointState=new Ce,this.topologyManager=new Te(e,this.pointState),this.dragLayers=new Le(this.ctx.map),this.events={onPointMouseEnter:this.onPointMouseEnter,onPointMouseLeave:this.onPointMouseLeave,onPointMouseDown:this.onPointMouseDown,onMapMouseMove:this.onMapMouseMove},this.firstPoint=new Ee(this.ctx,this.events),this.auxPoints=new be(this.ctx,this.events),this.removeButton=new Ne({map:this.ctx.map,options:this.ctx.options,onRemove:this.onPointRemove});}eventsInited=!1;events;firstPoint;auxPoints;pointState;topologyManager;removeButton;dragLayers;pressedStep=null;pressActive=!1;suppressedStepId=null;highlightedStepId=null;pointAdded=null;initConsumers=()=>{this.ctx.mode.addObserver(this.mapModeConsumer),this.ctx.store.addObserver(this.storeEventsConsumer);};removeConsumers=()=>{this.ctx.mode.removeObserver(this.mapModeConsumer),this.ctx.store.removeObserver(this.storeEventsConsumer),this.auxPoints?.removeConsumers();};initEvents=()=>{let{map:e}=this.ctx;e.on("click",this.onMapClick),e.on("dblclick",this.onMapDblClick),e.on("mousemove",this.onPointerHover),l.addEventListener(e.getContainer(),"mouseleave",this.onPointerLeaveMap),this.pointAdded=this.ctx.events.on("mdl:add",this.onPointAdded),e.on("mouseenter",r.PointsHitLayer,this.onPointMouseEnter),e.on("mouseleave",r.PointsHitLayer,this.onPointMouseLeave),e.on("mousedown",r.PointsHitLayer,this.onPointMouseDown),e.on("click",r.PointsHitLayer,this.onPointClick),e.on("touchstart",r.PointsHitLayer,this.onPointMouseDown),this.eventsInited=!0;};init=()=>{this.initEvents(),this.initConsumers();};removeEvents=()=>{let{map:e}=this.ctx;this.highlight(null),e.off("click",this.onMapClick),e.off("dblclick",this.onMapDblClick),e.off("mousemove",this.onPointerHover),l.removeEventListener(e.getContainer(),"mouseleave",this.onPointerLeaveMap),e.off("mousemove",this.onMapMouseMove),this.renderDraggedPoint.cancel(),this.onPointerHover.cancel(),this.dragLayers.release(),this.pointAdded?.unsubscribe(),this.pointAdded=null,e.off("mouseenter",r.PointsHitLayer,this.onPointMouseEnter),e.off("mouseleave",r.PointsHitLayer,this.onPointMouseLeave),e.off("mousedown",r.PointsHitLayer,this.onPointMouseDown),e.off("click",r.PointsHitLayer,this.onPointClick),e.off("touchstart",r.PointsHitLayer,this.onPointMouseDown),this.eventsInited=!1;};unbindPress=()=>{let{map:e}=this.ctx;e.off("mousemove",this.onMapMouseMove),e.off("touchmove",this.onMapMouseMove),e.off("mouseup",this.onPointMouseUp),e.off("touchend",this.onPointMouseUp);};cancelPress=()=>{this.unbindPress(),this.pressActive=!1,this.pressedStep=null,this.pointState.reset();};remove=()=>{this.cancelPress(),this.removeEvents(),this.firstPoint?.remove(),this.auxPoints?.removeEvents(),this.removeConsumers(),this.removeButton.destroy();};onPointClick=e=>{let{mouseEvents:t,store:i,map:n,options:s}=this.ctx,a=w(n,e.point);i.isLastPoint(s,a)&&(t.lastPointMouseClick=!0,t.lastPointMouseUp=!1);};onMapDblClick=e=>{e.preventDefault();};onPointRemove=e=>{let{store:t}=this.ctx;t.findStepById(e)&&(this.topologyManager.removePoint(e),f.execute());};onOwnGeometryClick=e=>H(e,[...V,r.LineLayerTransparent,r.LineLayerBreak])?!0:this.ctx.projection.isNearGeometry(e.point);onMapClick=e=>{let{mode:t,mouseEvents:i,map:n,store:s}=this.ctx;if(t.getClosedGeometry()||this.onOwnGeometryClick(e))return;i.lastPointMouseClick&&(i.lastPointMouseClick=!1),n.getCanvasContainer().style.cursor="grab";let a=this.topologyManager.addPoint(e);d.addPoint({...a,total:s.size},n,t),y.setSinglePointHidden(e),f.execute();};onPointAdded=e=>{this.onPointerHover.cancel(),this.suppressedStepId=e.id;};onMoveLeftClickUp=e=>{e.originalEvent.buttons===0&&this.onPointMouseUp();};onMapMouseMove=e=>{if(!this.ctx.mouseEvents.pointMouseDown)return;let t=e;this.pointState.setLastEvent(t),this.pointState.getSelectedNode()&&(this.onMoveLeftClickUp(t),this.pressActive&&(this.pointState.setMoved(!0),this.dragLayers.move(t.point),this.renderDraggedPoint()));};renderDraggedPoint=C(()=>{let e=this.pointState.getLastEvent(),t=this.pointState.getSelectedIdx();!e||t===null||!this.pointState.getSelectedNode()||f.executeOnMouseMove(t,e.lngLat,this.topologyManager.getAuxPointsLatLng(e));});highlight=e=>{let{map:t}=this.ctx;this.highlightedStepId!==e&&(this.highlightedStepId!==null&&t.removeFeatureState({source:c.UnifiedSource,id:this.highlightedStepId}),this.highlightedStepId=e,e!==null&&t.setFeatureState({source:c.UnifiedSource,id:e},{hover:!0}));};onPointerLeaveMap=()=>{this.onPointerHover.cancel(),this.highlight(null);};onPointerHover=C(e=>{let{mouseEvents:t,map:i,store:n}=this.ctx;if(!this.eventsInited||t.pointMouseDown)return;let s=w(i,e.point);if(this.highlight(s??null),s!==this.suppressedStepId)this.suppressedStepId=null;else if(s){this.removeButton.hide();return}let a=s?n.findStepById(s):null;a&&!a.isAuxiliary?this.removeButton.show(a):this.removeButton.hide();});onPointMouseEnter=e=>{let{mouseEvents:t,map:i,store:n,options:s}=this.ctx;if(t&&(t.pointMouseEnter=!0,t.pointMouseDown))return;y.setSinglePointHidden(e);let a=w(i,e.point);n.isLastPoint(s,a)&&(t.lastPointMouseEnter=!0,t.lastPointMouseLeave=!1);let p=n.findStepById(a);if(p){let u=this.pointState.getEnteredStep()?.id===p.id;this.pointState.setEnteredStep(p),u||d.enterPoint(Object.assign({},p,{total:n.size}),i);}};onPointMouseLeave=e=>{let{mouseEvents:t,store:i,map:n,options:s}=this.ctx;if(t&&(t.pointMouseEnter=!1,e.originalEvent.buttons===0&&(t.pointMouseLeave=!0),t.pointMouseDown))return;let a=w(n,e.point);i.isLastPoint(s,a)&&(t.lastPointMouseEnter=!1,t.lastPointMouseLeave=!0),d.leavePoint(Object.assign({},this.pointState.getEnteredStep(),{total:i.size}),n),this.pointState.setEnteredStep(null);};dismissButton=()=>{this.suppressedStepId=null,this.removeButton.hide();};storeEventsConsumer=e=>{if(e.type==="STORE_CLEARED"){this.pointState.reset(),this.dismissButton();return}e.type==="STORE_MUTATED"&&e.data?.size===0&&(this.pointState.reset(),this.dismissButton());};mapModeConsumer=e=>{let{type:t,data:i}=e;t==="MODE_CHANGED"&&!i?this.eventsInited&&this.removeEvents():t==="MODE_CHANGED"&&i&&(this.eventsInited||this.initEvents()),(t==="BREAK_CHANGED"||t==="MODE_CHANGED")&&(this.pointState.reset(),this.dismissButton());};hideLastPointPanel=()=>{let{store:e,panel:t,options:i}=this.ctx,n=this.pointState.getSelectedNode();n?.val&&e.isLastPoint(i,n.val.id)&&t.hide();};onPointMouseDown=e=>{e.preventDefault(),this.pointState.clearLastEvent();let{mouseEvents:t,map:i,store:n}=this.ctx;if(he(e))return;this.suppressedStepId=null;let s=w(i,e.point),a=n.findNodeById(s);a&&this.pointState.setSelectedNode(a),this.pressedStep=a?.val??null,this.pressActive=!0,this.dragLayers.press(e.point),this.hideLastPointPanel(),this.pointState.setSelectedIdx(dt(n,s)),t&&(t.pointMouseDown=!0),this.pointState.setStartCoordinates(this.pressedStep?{lat:this.pressedStep.lat,lng:this.pressedStep.lng}:e.lngLat),i.on("mousemove",this.onMapMouseMove),i.on("touchmove",this.onMapMouseMove),i.on("mouseup",this.onPointMouseUp),i.on("touchend",this.onPointMouseUp);};onPointMouseUp=()=>{let{mouseEvents:e,store:t,panel:i,map:n}=this.ctx;if(!this.pressActive)return;this.pressActive=!1,this.unbindPress(),this.renderDraggedPoint.cancel(),e.pointMouseUp=!0;let s=this.pointState.getSelectedNode(),a=this.pointState.getLastEvent(),p=this.pointState.getStartCoordinates();s?.val&&(a&&(this.topologyManager.updateStore(),this.pointState.clearLastEvent()),i?.show(),this.pointState.isMoved()&&h.commit(new Ae(t,s,p,n)),this.pointState.partialReset()),h.commitTransaction(),e&&(e.pointMouseDown=!1),this.dragLayers.release(),f.execute(),this.showButtonForPressedStep();};showButtonForPressedStep=()=>{let{store:e}=this.ctx,t=this.pressedStep;this.pressedStep=null,!(!t||t.isAuxiliary)&&e.findStepById(t.id)&&this.removeButton.show(t);}};var ke=class{constructor(e){this.ctx=e;this.pointEvents=new De(this.ctx),this.lineEvents=new ye(this.ctx),this.initEvents();}pointEvents;lineEvents;initEvents=()=>{this.lineEvents.init(),this.pointEvents?.init();};remove=()=>{this.pointEvents?.remove(),this.lineEvents?.remove(),y.cancelSinglePointHiding();}};var Re=class{constructor(e){this.ctx=e;}init(){this.add(),this.swap(r.LineLayer,r.SinglePointLayer),this.swap(r.LineLayerTransparent,r.SinglePointLayer),this.swap(r.LineLayerTransparent,r.FirstPointLayer),this.swap(r.LineLayerTransparent,r.PointsLayer),this.swap(r.PolygonLayer,r.LineLayer),this.swap(r.PointsHitLayer,r.PointsLayer),this.swap(r.FirstPointHitLayer,r.FirstPointLayer),this.swap(r.AuxiliaryPointHitLayer,r.AuxiliaryPointLayer),this.initConsumers();}initConsumers=()=>{this.ctx.store.addObserver(this.onStoreChange);};removeConsumers=()=>{this.ctx.store.removeObserver(this.onStoreChange);};onStoreChange=A(e=>{if(["STORE_MUTATED","STORE_CLOSE_GEOMETRY","STORE_BREAK_GEOMETRY","STORE_CLEARED"].includes(e.type)){let{map:i,store:n,mode:s}=this.ctx;s.getMode()==="polygon"&&n.circular.isCircular()?i.setLayoutProperty(r.PolygonLayer,"visibility","visible"):i.setLayoutProperty(r.PolygonLayer,"visibility","none");}},10);add=()=>{let e=Qe(this.ctx.options);for(let t of e)this.ctx.map.getLayer(t.id)||this.ctx.map.addLayer(t);};swap=(e,t)=>{let i=this.ctx.map.getLayer(e),n=this.ctx.map.getLayer(t);i&&n&&this.ctx.map.moveLayer(e,t);};removeLayers=()=>{for(let e of Object.values(r))this.ctx.map.getLayer(e)&&this.ctx.map.removeLayer(e);};remove=()=>{this.removeConsumers(),this.onStoreChange.cancel(),this.removeLayers();}};var Ie=class{constructor(e){this.ctx=e;}init(){for(let e of Object.values(c))this.ctx.map.getSource(e)||this.ctx.map.addSource(e,{type:"geojson",data:{type:"FeatureCollection",features:[]},promoteId:"id"});}remove(){for(let e of Object.values(c))this.ctx.map.getSource(e)&&this.ctx.map.removeSource(e);}};var Be=class{constructor(e){this.ctx=e;this.sources=new Ie(this.ctx),this.layers=new Re(this.ctx),this.events=new ke(this.ctx),this.init();}sources;layers;events;init=()=>{this.sources.init(),this.layers.init();};remove=()=>{this.events?.remove(),this.layers.remove(),this.sources.remove();}};var _e=class{constructor(e){this.map=e;this.init();}init(){h.addObserver(this.onTimelineEvent);}destroy(){h.removeObserver(this.onTimelineEvent);}onTimelineEvent=e=>{switch(e.type){case"UNDO_STACK_CHANGED":d.onUndoStackChange(this.map,e.data);break;case"REDO_STACK_CHANGED":d.onRedoStackChange(this.map,e.data);break}}};var He=class{listeners=new Map;on=(e,t)=>this.add(e,t,!1);once=(e,t)=>this.add(e,t,!0);off=(e,t)=>{this.listeners.get(e)?.delete(t);};emit=(e,t)=>{let i=this.listeners.get(e);if(i)for(let n of [...i.values()])n.delivered||(n.once&&(n.delivered=!0,i.get(n.listener)===n&&i.delete(n.listener)),n.listener(t));};add(e,t,i){let n=this.listeners.get(e);n||(n=new Map,this.listeners.set(e,n));let s=t;return (!n.get(s)||!i)&&n.set(s,{listener:s,once:i,delivered:!1}),{unsubscribe:()=>this.off(e,t)}}};var We=class o{static#e=null;static#t=!1;container;store;mode;defaultOptions;tiles;panel;control;cursor;mouseEvents;timelineAdapter;projection;events=new He;renderer=null;constructor(e){this.defaultOptions=ct(e),this.defaultOptions.initial&&pt(this.defaultOptions.initial);}onAdd=e=>{if(o.#t)throw new Error(L.REENTRANT_LIFECYCLE);if(o.#e)throw new Error(L.ALREADY_ADDED_TO_MAP);o.#t=!0,o.#e=this;try{let t=e;return d.bind(this.events),this.store=new _(this.defaultOptions),this.mode=new re(this.defaultOptions),this.renderer=f.initialize({map:t,store:this.store,options:this.defaultOptions,mode:this.mode}),this.projection=new pe({map:t,store:this.store,options:this.defaultOptions}),this.mouseEvents=new ce,this.panel=new te({map:t,mode:this.mode,options:this.defaultOptions,store:this.store}),this.control=new se({options:this.defaultOptions,map:t,mode:this.mode}),this.tiles=new Be({map:t,store:this.store,mode:this.mode,options:this.defaultOptions,control:this.control,panel:this.panel,mouseEvents:this.mouseEvents,projection:this.projection,events:this.events}),this.renderer?.execute(),this.cursor=new ae({map:t,mode:this.mode,mouseEvents:this.mouseEvents,store:this.store,options:this.defaultOptions}),this.timelineAdapter=new _e(t),this.mode.pingConsumers(),this.store.pingConsumers(),this.container=this.control.getContainer(),this.container}catch(t){throw o.#e=null,this.#o(),t}finally{o.#t=!1;}};#o=()=>{this.projection?.remove(),this.cursor?.remove(),this.tiles?.remove(),this.panel?.destroy(),this.store?.reset(),this.mode?.unsubscribe(),this.control?.destroy(),this.timelineAdapter?.destroy(),h.resetStacks(),this.container&&l.remove(this.container),d.unbind(this.events),this.container=void 0,this.store=void 0,this.mode=void 0,this.tiles=void 0,this.panel=void 0,this.control=void 0,this.cursor=void 0,this.mouseEvents=void 0,this.timelineAdapter=void 0,this.projection=void 0,this.renderer=null;};#i=()=>{let{store:e,mode:t,panel:i}=this;if(o.#e!==this||!e||!t||!i)throw new Error(L.NOT_ADDED_TO_MAP);return {store:e,mode:t,panel:i}};onRemove=()=>{if(o.#t)throw new Error(L.REENTRANT_LIFECYCLE);if(o.#e===this){o.#t=!0;try{this.#o();}finally{o.#e=null,o.#t=!1;}}};setSteps=e=>{if(!Array.isArray(e))throw new Error(L.INVALID_STEPS_ARGUMENT);let{store:t,mode:i,panel:n}=this.#i();t.reset(),n.hide(),i.reset(),h.resetStacks(),this.renderer?.resetGeometries(),st(t,e,this.defaultOptions.pointGeneration),this.renderer?.execute();};findStepById=e=>this.#i().store.findStepById(e);findNodeById=e=>this.#i().store.findNodeById(e);getAllSteps=(e="array")=>{let{store:t}=this.#i();if(e==="array")return $(t.head);if(e==="linkedlist")return {head:t.head,tail:t.tail,size:t.size};throw new Error(L.INVALID_STEPS_TYPE)};undo=e=>{this.#i().panel.api().undo(e);};redo=e=>{this.#i().panel.api().redo(e);};clear=e=>{this.#i().panel.api().clear(e);};save=e=>{this.#i().panel.api().save(e);};removeAllSteps=e=>{this.clear(e);};on=(e,t)=>this.events.on(e,t);once=(e,t)=>this.events.once(e,t);off=(e,t)=>{this.events.off(e,t);}};
2
2
 
3
3
  export { We as default };
4
4
  //# sourceMappingURL=index.js.map