ol-contextmenu
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { SingleItem, Options } from './types'; | ||
import { type SingleItem, type Options } from './types'; | ||
export declare const DEFAULT_OPTIONS: Options; | ||
@@ -3,0 +3,0 @@ export declare const CSS_CLASSES: { |
import { TinyEmitter } from 'tiny-emitter'; | ||
import { Item } from '../types'; | ||
import { type Item } from '../types'; | ||
export declare function createFragment(html: string): DocumentFragment; | ||
@@ -4,0 +4,0 @@ export declare function getLineHeight(container: HTMLDivElement): number; |
@@ -1,12 +0,12 @@ | ||
import OlMap from 'ol/Map'; | ||
import type OlMap from 'ol/Map'; | ||
import type { Pixel } from 'ol/pixel'; | ||
import { EventsKey } from 'ol/events'; | ||
import BaseEvent from 'ol/events/Event'; | ||
import { ObjectEvent } from 'ol/Object'; | ||
import type { EventsKey } from 'ol/events'; | ||
import type BaseEvent from 'ol/events/Event'; | ||
import type { ObjectEvent } from 'ol/Object'; | ||
import type { Coordinate } from 'ol/coordinate'; | ||
import type { Types as ObjectEventTypes } from 'ol/ObjectEventType'; | ||
import type { CombinedOnSignature, EventTypes as OlEventTypes, OnSignature } from 'ol/Observable'; | ||
import Control from 'ol/control/Control'; | ||
import { TinyEmitter } from 'tiny-emitter'; | ||
import type { Coordinate } from 'ol/coordinate'; | ||
import { Types as ObjectEventTypes } from 'ol/ObjectEventType'; | ||
import { CombinedOnSignature, EventTypes as OlEventTypes, OnSignature } from 'ol/Observable'; | ||
import { ContextMenuEvent, CustomEventTypes, Item, MenuEntry, Options } from './types'; | ||
import { Item, Options, MenuEntry, ContextMenuEvent, CustomEventTypes } from './types'; | ||
export default class ContextMenu extends Control { | ||
@@ -54,1 +54,2 @@ protected map: OlMap; | ||
} | ||
export { type ItemSeparator, type ItemWithNested, type SingleItem, type Item, type Options, type MenuEntry, type EventTypes, type CallbackObject, type ContextMenuEvent, type CustomEventTypes, } from './types'; |
/*! | ||
* ol-contextmenu - v5.2.1 | ||
* ol-contextmenu - v5.3.0 | ||
* https://github.com/jonataswalker/ol-contextmenu | ||
* Built: Fri Mar 31 2023 20:27:32 GMT-0300 (Brasilia Standard Time) | ||
* Built: Fri Sep 22 2023 13:13:39 GMT-0300 (Brasilia Standard Time) | ||
*/ | ||
var ContextMenu=function(){"use strict";var de=Object.defineProperty;var pe=(v,u,g)=>u in v?de(v,u,{enumerable:!0,configurable:!0,writable:!0,value:g}):v[u]=g;var h=(v,u,g)=>(pe(v,typeof u!="symbol"?u+"":u,g),g);class v{constructor(e){this.propagationStopped,this.defaultPrevented,this.type=e,this.target=null}preventDefault(){this.defaultPrevented=!0}stopPropagation(){this.propagationStopped=!0}}const u=v,g={PROPERTYCHANGE:"propertychange"};class K{constructor(){this.disposed=!1}dispose(){this.disposed||(this.disposed=!0,this.disposeInternal())}disposeInternal(){}}const U=K;function M(){}function D(s){for(const e in s)delete s[e]}function z(s){let e;for(e in s)return!1;return!e}class B extends U{constructor(e){super(),this.eventTarget_=e,this.pendingRemovals_=null,this.dispatching_=null,this.listeners_=null}addEventListener(e,t){if(!e||!t)return;const n=this.listeners_||(this.listeners_={}),r=n[e]||(n[e]=[]);r.includes(t)||r.push(t)}dispatchEvent(e){const t=typeof e=="string",n=t?e:e.type,r=this.listeners_&&this.listeners_[n];if(!r)return;const i=t?new u(e):e;i.target||(i.target=this.eventTarget_||this);const o=this.dispatching_||(this.dispatching_={}),l=this.pendingRemovals_||(this.pendingRemovals_={});n in o||(o[n]=0,l[n]=0),++o[n];let d;for(let c=0,_=r.length;c<_;++c)if("handleEvent"in r[c]?d=r[c].handleEvent(i):d=r[c].call(this,i),d===!1||i.propagationStopped){d=!1;break}if(--o[n]===0){let c=l[n];for(delete l[n];c--;)this.removeEventListener(n,M);delete o[n]}return d}disposeInternal(){this.listeners_&&D(this.listeners_)}getListeners(e){return this.listeners_&&this.listeners_[e]||void 0}hasListener(e){return this.listeners_?e?e in this.listeners_:Object.keys(this.listeners_).length>0:!1}removeEventListener(e,t){const n=this.listeners_&&this.listeners_[e];if(n){const r=n.indexOf(t);r!==-1&&(this.pendingRemovals_&&e in this.pendingRemovals_?(n[r]=M,++this.pendingRemovals_[e]):(n.splice(r,1),n.length===0&&delete this.listeners_[e]))}}}const F=B,V={CHANGE:"change",ERROR:"error",BLUR:"blur",CLEAR:"clear",CONTEXTMENU:"contextmenu",CLICK:"click",DBLCLICK:"dblclick",DRAGENTER:"dragenter",DRAGOVER:"dragover",DROP:"drop",FOCUS:"focus",KEYDOWN:"keydown",KEYPRESS:"keypress",LOAD:"load",RESIZE:"resize",TOUCHMOVE:"touchmove",WHEEL:"wheel"};function b(s,e,t,n,r){if(n&&n!==s&&(t=t.bind(n)),r){const o=t;t=function(){s.removeEventListener(e,t),o.apply(this,arguments)}}const i={target:s,type:e,listener:t};return s.addEventListener(e,t),i}function R(s,e,t,n){return b(s,e,t,n,!0)}function C(s){s&&s.target&&(s.target.removeEventListener(s.type,s.listener),D(s))}class L extends F{constructor(){super(),this.on=this.onInternal,this.once=this.onceInternal,this.un=this.unInternal,this.revision_=0}changed(){++this.revision_,this.dispatchEvent(V.CHANGE)}getRevision(){return this.revision_}onInternal(e,t){if(Array.isArray(e)){const n=e.length,r=new Array(n);for(let i=0;i<n;++i)r[i]=b(this,e[i],t);return r}return b(this,e,t)}onceInternal(e,t){let n;if(Array.isArray(e)){const r=e.length;n=new Array(r);for(let i=0;i<r;++i)n[i]=R(this,e[i],t)}else n=R(this,e,t);return t.ol_key=n,n}unInternal(e,t){const n=t.ol_key;if(n)j(n);else if(Array.isArray(e))for(let r=0,i=e.length;r<i;++r)this.removeEventListener(e[r],t);else this.removeEventListener(e,t)}}L.prototype.on,L.prototype.once,L.prototype.un;function j(s){if(Array.isArray(s))for(let e=0,t=s.length;e<t;++e)C(s[e]);else C(s)}const Y=L;let G=0;function Z(s){return s.ol_uid||(s.ol_uid=String(++G))}class P extends u{constructor(e,t,n){super(e),this.key=t,this.oldValue=n}}class W extends Y{constructor(e){super(),this.on,this.once,this.un,Z(this),this.values_=null,e!==void 0&&this.setProperties(e)}get(e){let t;return this.values_&&this.values_.hasOwnProperty(e)&&(t=this.values_[e]),t}getKeys(){return this.values_&&Object.keys(this.values_)||[]}getProperties(){return this.values_&&Object.assign({},this.values_)||{}}hasProperties(){return!!this.values_}notify(e,t){let n;n=`change:${e}`,this.hasListener(n)&&this.dispatchEvent(new P(n,e,t)),n=g.PROPERTYCHANGE,this.hasListener(n)&&this.dispatchEvent(new P(n,e,t))}addChangeListener(e,t){this.addEventListener(`change:${e}`,t)}removeChangeListener(e,t){this.removeEventListener(`change:${e}`,t)}set(e,t,n){const r=this.values_||(this.values_={});if(n)r[e]=t;else{const i=r[e];r[e]=t,i!==t&&this.notify(e,i)}}setProperties(e,t){for(const n in e)this.set(n,e[n],t)}applyProperties(e){e.values_&&Object.assign(this.values_||(this.values_={}),e.values_)}unset(e,t){if(this.values_&&e in this.values_){const n=this.values_[e];delete this.values_[e],z(this.values_)&&(this.values_=null),t||this.notify(e,n)}}}const X=W,q={POSTRENDER:"postrender",MOVESTART:"movestart",MOVEEND:"moveend",LOADSTART:"loadstart",LOADEND:"loadend"};function $(s){return s&&s.parentNode?s.parentNode.removeChild(s):null}class J extends X{constructor(e){super();const t=e.element;t&&!e.target&&!t.style.pointerEvents&&(t.style.pointerEvents="auto"),this.element=t||null,this.target_=null,this.map_=null,this.listenerKeys=[],e.render&&(this.render=e.render),e.target&&this.setTarget(e.target)}disposeInternal(){$(this.element),super.disposeInternal()}getMap(){return this.map_}setMap(e){this.map_&&$(this.element);for(let t=0,n=this.listenerKeys.length;t<n;++t)C(this.listenerKeys[t]);this.listenerKeys.length=0,this.map_=e,e&&((this.target_?this.target_:e.getOverlayContainerStopEvent()).appendChild(this.element),this.render!==M&&this.listenerKeys.push(b(e,q.POSTRENDER,this.render,this)),e.render())}render(e){}setTarget(e){this.target_=typeof e=="string"?document.getElementById(e):e}}const Q=J;var O={},ee={get exports(){return O},set exports(s){O=s}};function w(){}w.prototype={on:function(s,e,t){var n=this.e||(this.e={});return(n[s]||(n[s]=[])).push({fn:e,ctx:t}),this},once:function(s,e,t){var n=this;function r(){n.off(s,r),e.apply(t,arguments)}return r._=e,this.on(s,r,t)},emit:function(s){var e=[].slice.call(arguments,1),t=((this.e||(this.e={}))[s]||[]).slice(),n=0,r=t.length;for(n;n<r;n++)t[n].fn.apply(t[n].ctx,e);return this},off:function(s,e){var t=this.e||(this.e={}),n=t[s],r=[];if(n&&e)for(var i=0,o=n.length;i<o;i++)n[i].fn!==e&&n[i].fn._!==e&&r.push(n[i]);return r.length?t[s]=r:delete t[s],this}},ee.exports=w;var te=O.TinyEmitter=w;class ne extends u{constructor(e,t,n){super(e),this.map=t,this.frameState=n!==void 0?n:null}}const se=ne;class ie extends se{constructor(e,t,n,r,i,o){super(e,t,i),this.originalEvent=n,this.pixel_=null,this.coordinate_=null,this.dragging=r!==void 0?r:!1,this.activePointers=o}get pixel(){return this.pixel_||(this.pixel_=this.map.getEventPixel(this.originalEvent)),this.pixel_}set pixel(e){this.pixel_=e}get coordinate(){return this.coordinate_||(this.coordinate_=this.map.getCoordinateFromPixel(this.pixel)),this.coordinate_}set coordinate(e){this.coordinate_=e}preventDefault(){super.preventDefault(),"preventDefault"in this.originalEvent&&this.originalEvent.preventDefault()}stopPropagation(){super.stopPropagation(),"stopPropagation"in this.originalEvent&&this.originalEvent.stopPropagation()}}const re=ie;var A=(s=>(s.CONTEXTMENU="contextmenu",s.CLICK="click",s.DBLCLICK="dblclick",s))(A||{}),f=(s=>(s.BEFOREOPEN="beforeopen",s.OPEN="open",s.CLOSE="close",s.ADD_MENU_ENTRY="add-menu-entry",s))(f||{});class I extends re{constructor(e){super(e.type,e.map,e.originalEvent)}}const oe={width:150,scrollAt:4,eventType:A.CONTEXTMENU,defaultItems:!0,items:[]},m="ol-ctx-menu",a={namespace:m,container:`${m}-container`,separator:`${m}-separator`,submenu:`${m}-submenu`,hidden:`${m}-hidden`,icon:`${m}-icon`,zoomIn:`${m}-zoom-in`,zoomOut:`${m}-zoom-out`,unselectable:"ol-unselectable"},H=[{text:"Zoom In",classname:`${a.zoomIn} ${a.icon}`,callback:(s,e)=>{const t=e.getView();t.animate({zoom:Number(t.getZoom())+1,duration:700,center:s.coordinate})}},{text:"Zoom Out",classname:`${a.zoomOut} ${a.icon}`,callback:(s,e)=>{const t=e.getView();t.animate({zoom:Number(t.getZoom())-1,duration:700,center:s.coordinate})}}];function x(s){const e=document.createDocumentFragment(),t=document.createElement("div");for(t.innerHTML=s;t.firstChild;)e.append(t.firstChild);return e}function ae(s){const e=document.importNode(s),t=s.offsetWidth;e.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${t}px`;const n=x("<span>Foo</span>"),r=x("<span>Foo</span>"),i=document.createElement("li"),o=document.createElement("li");i.append(n),o.append(r),e.append(i),e.append(o),s.parentNode?.append(e);const l=e.offsetHeight/2;return s.parentNode?.removeChild(e),l}function k({parentNode:s,item:e,isSubmenu:t=!1,isInsideSubmenu:n=!1,emitter:r}){const i=`_${Math.random().toString(36).slice(2,11)}`;if(typeof e!="string"&&"text"in e){const _=`<span>${e.text}</span>`,y=x(_),E=document.createElement("li");e.classname=e.classname||"",e.icon&&(e.classname===""?e.classname=a.icon:e.classname.includes(a.icon)===!1&&(e.classname+=` ${a.icon}`),E.setAttribute("style",`background-image:url(${e.icon})`)),E.id=i,E.className=e.classname,E.append(y),s.append(E);const T={id:i,isSubmenu:t,isInsideSubmenu:n,isSeparator:!1,callback:"callback"in e?e.callback:null,data:"data"in e?e.data:null};return r.emit(f.ADD_MENU_ENTRY,T,E),E}const o=`<li id="${i}" class="${a.separator}"><hr></li>`,l=x(o);s.append(l);const d=s.lastChild,c={id:i,isSubmenu:!1,isInsideSubmenu:!1,isSeparator:!0,callback:null,data:null};return r.emit(f.ADD_MENU_ENTRY,c,d),d}function N({container:s,items:e,menuWidth:t,isInsideSubmenu:n,emitter:r}){e.forEach(i=>{if(typeof i!="string"&&"items"in i&&Array.isArray(i.items)){const o=k({parentNode:s,item:i,isSubmenu:!0,emitter:r});o.classList.add(a.submenu);const l=document.createElement("ul");l.classList.add(a.container),l.style.width=`${t}px`,o.append(l),N({emitter:r,menuWidth:t,container:l,items:i.items,isInsideSubmenu:!0})}else k({parentNode:s,item:i,isSubmenu:!1,isInsideSubmenu:n,emitter:r})})}const fe="";function S(s,e){if(!s)throw new Error(e)}class le extends Q{constructor(t={}){S(typeof t=="object","@param `opts` should be object type!");const n=document.createElement("div");super({element:n});h(this,"map");h(this,"emitter",new te);h(this,"container");h(this,"coordinate",[]);h(this,"pixel",[]);h(this,"contextMenuEventListener");h(this,"entryCallbackEventListener");h(this,"mapMoveListener");h(this,"lineHeight",0);h(this,"disabled");h(this,"opened");h(this,"items",[]);h(this,"menuEntries",new Map);h(this,"options");this.options={...oe,...t};const r=document.createElement("ul");n.append(r),n.style.width=`${this.options.width}px`,n.classList.add(a.container,a.unselectable,a.hidden),this.container=n,this.contextMenuEventListener=i=>{this.handleContextMenu(i)},this.entryCallbackEventListener=i=>{this.handleEntryCallback(i)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener("beforeunload",()=>{this.removeListeners()},{once:!0})}clear(){for(const t of this.menuEntries.keys())this.removeMenuEntry(t);this.container.replaceChildren(),this.container.append(document.createElement("ul"))}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return H}countItems(){return this.menuEntries.size}extend(t){S(Array.isArray(t),"@param `items` should be an Array."),N({items:t,emitter:this.emitter,menuWidth:this.options.width,container:this.container.firstElementChild})}closeMenu(){this.opened=!1,this.container.classList.add(a.hidden),this.dispatchEvent(f.CLOSE)}isOpen(){return this.opened}updatePosition(t){S(Array.isArray(t),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=t,this.positionContainer())}pop(){const t=Array.from(this.menuEntries.keys()).pop();t&&this.removeMenuEntry(t)}shift(){const t=Array.from(this.menuEntries.keys()).shift();t&&this.removeMenuEntry(t)}push(t){t&&this.extend([t])}setMap(t){if(super.setMap(t),t){this.map=t,t.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),t.on("movestart",()=>{this.handleMapMove()}),this.emitter.on(f.ADD_MENU_ENTRY,(r,i)=>{this.handleAddMenuEntry(r,i)},this),this.items=this.options.defaultItems?this.options.items.concat(H):this.options.items,N({items:this.items,emitter:this.emitter,menuWidth:this.options.width,container:this.container.firstElementChild});const n=this.getMenuEntriesLength();this.lineHeight=n>0?this.container.offsetHeight/n:ae(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.emitter.off(f.ADD_MENU_ENTRY)}removeMenuEntry(t){let n=document.getElementById(t);n?.remove(),n=null,this.menuEntries.delete(t)}handleContextMenu(t){this.coordinate=this.map.getEventCoordinate(t),this.pixel=this.map.getEventPixel(t),this.dispatchEvent(new I({map:this.map,originalEvent:t,type:f.BEFOREOPEN})),!this.disabled&&(this.options.eventType===A.CONTEXTMENU&&(t.stopPropagation(),t.preventDefault()),setTimeout(()=>{this.openMenu(t)}),t.target?.addEventListener("pointerdown",n=>{this.opened&&(n.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(t){this.opened=!0,this.positionContainer(),this.container.classList.remove(a.hidden),this.dispatchEvent(new I({map:this.map,originalEvent:t,type:f.OPEN}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,t])=>t.isSeparator===!1&&t.isSubmenu===!1&&t.isInsideSubmenu===!1).length}positionContainer(){const t=this.map.getSize()||[0,0],n={w:t[0]-this.pixel[0],h:t[1]-this.pixel[1]},r=this.getMenuEntriesLength(),i={w:this.container.offsetWidth,h:Math.round(this.lineHeight*r)},o=n.w>=i.w?this.pixel[0]+5:this.pixel[0]-i.w;this.container.style.left=`${o}px`,this.container.style.top=n.h>=i.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-i.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",n.w-=i.w;const l=_=>Array.from(_.children).filter(y=>y.tagName==="LI"&&y.classList.contains(a.submenu));let d=0;const c=(_,y)=>{d+=1,l(_).forEach(T=>{const he=y>=i.w?i.w-8:(i.w+8)*-1,p=T.querySelector(`ul.${a.container}`),ce=Math.round(this.lineHeight*Array.from(p.children).filter(ue=>ue.tagName==="LI").length);p.style.left=`${he}px`,p.style.right="auto",p.style.top=n.h>=ce+i.h?"0":`-${p.offsetHeight-25}px`,p.style.bottom="auto",p.style.zIndex=String(d),l(p).length>0&&c(p,y-i.w)})};c(this.container.firstElementChild,n.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(t){t.preventDefault(),t.stopPropagation();const n=t.currentTarget,r=this.menuEntries.get(n.id);if(!r)return;const i={data:r.data,coordinate:this.coordinate};this.closeMenu(),r.callback?.(i,this.map)}handleAddMenuEntry(t,n){this.menuEntries.set(t.id,t),this.positionContainer(),"callback"in t&&typeof t.callback=="function"&&n.addEventListener("click",this.entryCallbackEventListener,!1)}}return le}(); | ||
var ContextMenu=function(E,h){"use strict";var P=Object.defineProperty;var H=(E,h,d)=>h in E?P(E,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):E[h]=d;var a=(E,h,d)=>(H(E,typeof h!="symbol"?h+"":h,d),d);var d={exports:{}};function x(){}x.prototype={on:function(s,t,e){var n=this.e||(this.e={});return(n[s]||(n[s]=[])).push({fn:t,ctx:e}),this},once:function(s,t,e){var n=this;function o(){n.off(s,o),t.apply(e,arguments)}return o._=t,this.on(s,o,e)},emit:function(s){var t=[].slice.call(arguments,1),e=((this.e||(this.e={}))[s]||[]).slice(),n=0,o=e.length;for(n;n<o;n++)e[n].fn.apply(e[n].ctx,t);return this},off:function(s,t){var e=this.e||(this.e={}),n=e[s],o=[];if(n&&t)for(var i=0,l=n.length;i<l;i++)n[i].fn!==t&&n[i].fn._!==t&&o.push(n[i]);return o.length?e[s]=o:delete e[s],this}},d.exports=x;var T=d.exports.TinyEmitter=x,L=(s=>(s.CONTEXTMENU="contextmenu",s.CLICK="click",s.DBLCLICK="dblclick",s))(L||{}),p=(s=>(s.BEFOREOPEN="beforeopen",s.OPEN="open",s.CLOSE="close",s.ADD_MENU_ENTRY="add-menu-entry",s))(p||{});class S extends h{constructor(t){super(t.type,t.map,t.originalEvent)}}const k={width:150,scrollAt:4,eventType:L.CONTEXTMENU,defaultItems:!0,items:[]},m="ol-ctx-menu",r={namespace:m,container:`${m}-container`,separator:`${m}-separator`,submenu:`${m}-submenu`,hidden:`${m}-hidden`,icon:`${m}-icon`,zoomIn:`${m}-zoom-in`,zoomOut:`${m}-zoom-out`,unselectable:"ol-unselectable"},A=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(s,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:s.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(s,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:s.coordinate})}}];function b(s){const t=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=s;e.firstChild;)t.append(e.firstChild);return t}function I(s){const t=document.importNode(s),e=s.offsetWidth;t.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const n=b("<span>Foo</span>"),o=b("<span>Foo</span>"),i=document.createElement("li"),l=document.createElement("li");i.append(n),l.append(o),t.append(i),t.append(l),s.parentNode?.append(t);const c=t.offsetHeight/2;return s.parentNode?.removeChild(t),c}function $({parentNode:s,item:t,isSubmenu:e=!1,isInsideSubmenu:n=!1,emitter:o}){const i=`_${Math.random().toString(36).slice(2,11)}`;if(typeof t!="string"&&"text"in t){const v=`<span>${t.text}</span>`,g=b(v),f=document.createElement("li");t.classname=t.classname||"",t.icon&&(t.classname===""?t.classname=r.icon:t.classname.includes(r.icon)===!1&&(t.classname+=` ${r.icon}`),f.setAttribute("style",`background-image:url(${t.icon})`)),f.id=i,f.className=t.classname,f.append(g),s.append(f);const N={id:i,isSubmenu:e,isInsideSubmenu:n,isSeparator:!1,callback:"callback"in t?t.callback:null,data:"data"in t?t.data:null};return o.emit(p.ADD_MENU_ENTRY,N,f),f}const l=`<li id="${i}" class="${r.separator}"><hr></li>`,c=b(l);s.append(c);const y=s.lastChild,M={id:i,isSubmenu:!1,isInsideSubmenu:!1,isSeparator:!0,callback:null,data:null};return o.emit(p.ADD_MENU_ENTRY,M,y),y}function w({container:s,items:t,menuWidth:e,isInsideSubmenu:n,emitter:o}){t.forEach(i=>{if(typeof i!="string"&&"items"in i&&Array.isArray(i.items)){const l=$({parentNode:s,item:i,isSubmenu:!0,emitter:o});l.classList.add(r.submenu);const c=document.createElement("ul");c.classList.add(r.container),c.style.width=`${e}px`,l.append(c),w({emitter:o,menuWidth:e,container:c,items:i.items,isInsideSubmenu:!0})}else $({parentNode:s,item:i,isSubmenu:!1,isInsideSubmenu:n,emitter:o})})}const U="";function C(s,t){if(!s)throw new Error(t)}class O extends E{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const n=document.createElement("div");super({element:n});a(this,"map");a(this,"emitter",new T);a(this,"container");a(this,"coordinate",[]);a(this,"pixel",[]);a(this,"contextMenuEventListener");a(this,"entryCallbackEventListener");a(this,"mapMoveListener");a(this,"lineHeight",0);a(this,"disabled");a(this,"opened");a(this,"items",[]);a(this,"menuEntries",new Map);a(this,"options");this.options={...k,...e};const o=document.createElement("ul");n.append(o),n.style.width=`${this.options.width}px`,n.classList.add(r.container,r.unselectable,r.hidden),this.container=n,this.contextMenuEventListener=i=>{this.handleContextMenu(i)},this.entryCallbackEventListener=i=>{this.handleEntryCallback(i)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener("beforeunload",()=>{this.removeListeners()},{once:!0})}clear(){for(const e of this.menuEntries.keys())this.removeMenuEntry(e);this.container.replaceChildren(),this.container.append(document.createElement("ul"))}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return A}countItems(){return this.menuEntries.size}extend(e){C(Array.isArray(e),"@param `items` should be an Array."),w({items:e,emitter:this.emitter,menuWidth:this.options.width,container:this.container.firstElementChild})}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(p.CLOSE)}isOpen(){return this.opened}updatePosition(e){C(Array.isArray(e),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=e,this.positionContainer())}pop(){const e=Array.from(this.menuEntries.keys()).pop();e&&this.removeMenuEntry(e)}shift(){const e=Array.from(this.menuEntries.keys()).shift();e&&this.removeMenuEntry(e)}push(e){e&&this.extend([e])}setMap(e){if(super.setMap(e),e){this.map=e,e.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),e.on("movestart",()=>{this.handleMapMove()}),this.emitter.on(p.ADD_MENU_ENTRY,(o,i)=>{this.handleAddMenuEntry(o,i)},this),this.items=this.options.defaultItems?this.options.items.concat(A):this.options.items,w({items:this.items,emitter:this.emitter,menuWidth:this.options.width,container:this.container.firstElementChild});const n=this.getMenuEntriesLength();this.lineHeight=n>0?this.container.offsetHeight/n:I(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.emitter.off(p.ADD_MENU_ENTRY)}removeMenuEntry(e){let n=document.getElementById(e);n?.remove(),n=null,this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent(new S({map:this.map,originalEvent:e,type:p.BEFOREOPEN})),!this.disabled&&(this.options.eventType===L.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)}),e.target?.addEventListener("pointerdown",n=>{this.opened&&(n.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new S({map:this.map,originalEvent:e,type:p.OPEN}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1&&e.isSubmenu===!1&&e.isInsideSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],n={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},o=this.getMenuEntriesLength(),i={w:this.container.offsetWidth,h:Math.round(this.lineHeight*o)},l=n.w>=i.w?this.pixel[0]+5:this.pixel[0]-i.w;this.container.style.left=`${l}px`,this.container.style.top=n.h>=i.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-i.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",n.w-=i.w;const c=v=>Array.from(v.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let y=0;const M=(v,g)=>{y+=1,c(v).forEach(N=>{const D=g>=i.w?i.w-8:(i.w+8)*-1,u=N.querySelector(`ul.${r.container}`),_=Math.round(this.lineHeight*Array.from(u.children).filter(z=>z.tagName==="LI").length);u.style.left=`${D}px`,u.style.right="auto",u.style.top=n.h>=_+i.h?"0":`-${u.offsetHeight-25}px`,u.style.bottom="auto",u.style.zIndex=String(y),c(u).length>0&&M(u,g-i.w)})};M(this.container.firstElementChild,n.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const n=e.currentTarget,o=this.menuEntries.get(n.id);if(!o)return;const i={data:o.data,coordinate:this.coordinate};this.closeMenu(),o.callback?.(i,this.map)}handleAddMenuEntry(e,n){this.menuEntries.set(e.id,e),this.positionContainer(),"callback"in e&&typeof e.callback=="function"&&n.addEventListener("click",this.entryCallbackEventListener,!1)}}return O}(ol.control.Control,ol.MapBrowserEvent); |
/*! | ||
* ol-contextmenu - v5.2.1 | ||
* ol-contextmenu - v5.3.0 | ||
* https://github.com/jonataswalker/ol-contextmenu | ||
* Built: Fri Mar 31 2023 20:27:32 GMT-0300 (Brasilia Standard Time) | ||
* Built: Fri Sep 22 2023 13:13:39 GMT-0300 (Brasilia Standard Time) | ||
*/ | ||
var U = Object.defineProperty; | ||
var z = (s, e, t) => e in s ? U(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t; | ||
var h = (s, e, t) => (z(s, typeof e != "symbol" ? e + "" : e, t), t); | ||
class B { | ||
/** | ||
* @param {string} type Type. | ||
*/ | ||
constructor(e) { | ||
this.propagationStopped, this.defaultPrevented, this.type = e, this.target = null; | ||
} | ||
/** | ||
* Prevent default. This means that no emulated `click`, `singleclick` or `doubleclick` events | ||
* will be fired. | ||
* @api | ||
*/ | ||
preventDefault() { | ||
this.defaultPrevented = !0; | ||
} | ||
/** | ||
* Stop event propagation. | ||
* @api | ||
*/ | ||
stopPropagation() { | ||
this.propagationStopped = !0; | ||
} | ||
} | ||
const w = B, F = { | ||
/** | ||
* Triggered when a property is changed. | ||
* @event module:ol/Object.ObjectEvent#propertychange | ||
* @api | ||
*/ | ||
PROPERTYCHANGE: "propertychange" | ||
}; | ||
class V { | ||
constructor() { | ||
this.disposed = !1; | ||
} | ||
/** | ||
* Clean up. | ||
*/ | ||
dispose() { | ||
this.disposed || (this.disposed = !0, this.disposeInternal()); | ||
} | ||
/** | ||
* Extension point for disposable objects. | ||
* @protected | ||
*/ | ||
disposeInternal() { | ||
} | ||
} | ||
const j = V; | ||
var k = Object.defineProperty; | ||
var I = (n, t, e) => t in n ? k(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e; | ||
var a = (n, t, e) => (I(n, typeof t != "symbol" ? t + "" : t, e), e); | ||
import O from "ol/control/Control"; | ||
import D from "ol/MapBrowserEvent"; | ||
var S = { exports: {} }; | ||
function x() { | ||
} | ||
function I(s) { | ||
for (const e in s) | ||
delete s[e]; | ||
} | ||
function Y(s) { | ||
let e; | ||
for (e in s) | ||
return !1; | ||
return !e; | ||
} | ||
class G extends j { | ||
/** | ||
* @param {*} [target] Default event target for dispatched events. | ||
*/ | ||
constructor(e) { | ||
super(), this.eventTarget_ = e, this.pendingRemovals_ = null, this.dispatching_ = null, this.listeners_ = null; | ||
} | ||
/** | ||
* @param {string} type Type. | ||
* @param {import("../events.js").Listener} listener Listener. | ||
*/ | ||
addEventListener(e, t) { | ||
if (!e || !t) | ||
return; | ||
const n = this.listeners_ || (this.listeners_ = {}), r = n[e] || (n[e] = []); | ||
r.includes(t) || r.push(t); | ||
} | ||
/** | ||
* Dispatches an event and calls all listeners listening for events | ||
* of this type. The event parameter can either be a string or an | ||
* Object with a `type` property. | ||
* | ||
* @param {import("./Event.js").default|string} event Event object. | ||
* @return {boolean|undefined} `false` if anyone called preventDefault on the | ||
* event object or if any of the listeners returned false. | ||
* @api | ||
*/ | ||
dispatchEvent(e) { | ||
const t = typeof e == "string", n = t ? e : e.type, r = this.listeners_ && this.listeners_[n]; | ||
if (!r) | ||
return; | ||
const i = t ? new w(e) : ( | ||
/** @type {Event} */ | ||
e | ||
); | ||
i.target || (i.target = this.eventTarget_ || this); | ||
const o = this.dispatching_ || (this.dispatching_ = {}), l = this.pendingRemovals_ || (this.pendingRemovals_ = {}); | ||
n in o || (o[n] = 0, l[n] = 0), ++o[n]; | ||
let u; | ||
for (let c = 0, E = r.length; c < E; ++c) | ||
if ("handleEvent" in r[c] ? u = /** @type {import("../events.js").ListenerObject} */ | ||
r[c].handleEvent(i) : u = /** @type {import("../events.js").ListenerFunction} */ | ||
r[c].call(this, i), u === !1 || i.propagationStopped) { | ||
u = !1; | ||
break; | ||
} | ||
if (--o[n] === 0) { | ||
let c = l[n]; | ||
for (delete l[n]; c--; ) | ||
this.removeEventListener(n, x); | ||
delete o[n]; | ||
} | ||
return u; | ||
} | ||
/** | ||
* Clean up. | ||
*/ | ||
disposeInternal() { | ||
this.listeners_ && I(this.listeners_); | ||
} | ||
/** | ||
* Get the listeners for a specified event type. Listeners are returned in the | ||
* order that they will be called in. | ||
* | ||
* @param {string} type Type. | ||
* @return {Array<import("../events.js").Listener>|undefined} Listeners. | ||
*/ | ||
getListeners(e) { | ||
return this.listeners_ && this.listeners_[e] || void 0; | ||
} | ||
/** | ||
* @param {string} [type] Type. If not provided, | ||
* `true` will be returned if this event target has any listeners. | ||
* @return {boolean} Has listeners. | ||
*/ | ||
hasListener(e) { | ||
return this.listeners_ ? e ? e in this.listeners_ : Object.keys(this.listeners_).length > 0 : !1; | ||
} | ||
/** | ||
* @param {string} type Type. | ||
* @param {import("../events.js").Listener} listener Listener. | ||
*/ | ||
removeEventListener(e, t) { | ||
const n = this.listeners_ && this.listeners_[e]; | ||
if (n) { | ||
const r = n.indexOf(t); | ||
r !== -1 && (this.pendingRemovals_ && e in this.pendingRemovals_ ? (n[r] = x, ++this.pendingRemovals_[e]) : (n.splice(r, 1), n.length === 0 && delete this.listeners_[e])); | ||
} | ||
} | ||
} | ||
const Z = G, W = { | ||
/** | ||
* Generic change event. Triggered when the revision counter is increased. | ||
* @event module:ol/events/Event~BaseEvent#change | ||
* @api | ||
*/ | ||
CHANGE: "change", | ||
/** | ||
* Generic error event. Triggered when an error occurs. | ||
* @event module:ol/events/Event~BaseEvent#error | ||
* @api | ||
*/ | ||
ERROR: "error", | ||
BLUR: "blur", | ||
CLEAR: "clear", | ||
CONTEXTMENU: "contextmenu", | ||
CLICK: "click", | ||
DBLCLICK: "dblclick", | ||
DRAGENTER: "dragenter", | ||
DRAGOVER: "dragover", | ||
DROP: "drop", | ||
FOCUS: "focus", | ||
KEYDOWN: "keydown", | ||
KEYPRESS: "keypress", | ||
LOAD: "load", | ||
RESIZE: "resize", | ||
TOUCHMOVE: "touchmove", | ||
WHEEL: "wheel" | ||
}; | ||
function g(s, e, t, n, r) { | ||
if (n && n !== s && (t = t.bind(n)), r) { | ||
const o = t; | ||
t = function() { | ||
s.removeEventListener(e, t), o.apply(this, arguments); | ||
}; | ||
} | ||
const i = { | ||
target: s, | ||
type: e, | ||
listener: t | ||
}; | ||
return s.addEventListener(e, t), i; | ||
} | ||
function S(s, e, t, n) { | ||
return g(s, e, t, n, !0); | ||
} | ||
function M(s) { | ||
s && s.target && (s.target.removeEventListener(s.type, s.listener), I(s)); | ||
} | ||
class y extends Z { | ||
constructor() { | ||
super(), this.on = /** @type {ObservableOnSignature<import("./events").EventsKey>} */ | ||
this.onInternal, this.once = /** @type {ObservableOnSignature<import("./events").EventsKey>} */ | ||
this.onceInternal, this.un = /** @type {ObservableOnSignature<void>} */ | ||
this.unInternal, this.revision_ = 0; | ||
} | ||
/** | ||
* Increases the revision counter and dispatches a 'change' event. | ||
* @api | ||
*/ | ||
changed() { | ||
++this.revision_, this.dispatchEvent(W.CHANGE); | ||
} | ||
/** | ||
* Get the version number for this object. Each time the object is modified, | ||
* its version number will be incremented. | ||
* @return {number} Revision. | ||
* @api | ||
*/ | ||
getRevision() { | ||
return this.revision_; | ||
} | ||
/** | ||
* @param {string|Array<string>} type Type. | ||
* @param {function((Event|import("./events/Event").default)): ?} listener Listener. | ||
* @return {import("./events.js").EventsKey|Array<import("./events.js").EventsKey>} Event key. | ||
* @protected | ||
*/ | ||
onInternal(e, t) { | ||
if (Array.isArray(e)) { | ||
const n = e.length, r = new Array(n); | ||
for (let i = 0; i < n; ++i) | ||
r[i] = g(this, e[i], t); | ||
return r; | ||
} | ||
return g( | ||
this, | ||
/** @type {string} */ | ||
e, | ||
t | ||
); | ||
} | ||
/** | ||
* @param {string|Array<string>} type Type. | ||
* @param {function((Event|import("./events/Event").default)): ?} listener Listener. | ||
* @return {import("./events.js").EventsKey|Array<import("./events.js").EventsKey>} Event key. | ||
* @protected | ||
*/ | ||
onceInternal(e, t) { | ||
let n; | ||
if (Array.isArray(e)) { | ||
const r = e.length; | ||
n = new Array(r); | ||
for (let i = 0; i < r; ++i) | ||
n[i] = S(this, e[i], t); | ||
} else | ||
n = S( | ||
this, | ||
/** @type {string} */ | ||
e, | ||
t | ||
); | ||
return t.ol_key = n, n; | ||
} | ||
/** | ||
* Unlisten for a certain type of event. | ||
* @param {string|Array<string>} type Type. | ||
* @param {function((Event|import("./events/Event").default)): ?} listener Listener. | ||
* @protected | ||
*/ | ||
unInternal(e, t) { | ||
const n = ( | ||
/** @type {Object} */ | ||
t.ol_key | ||
); | ||
if (n) | ||
X(n); | ||
else if (Array.isArray(e)) | ||
for (let r = 0, i = e.length; r < i; ++r) | ||
this.removeEventListener(e[r], t); | ||
else | ||
this.removeEventListener(e, t); | ||
} | ||
} | ||
y.prototype.on; | ||
y.prototype.once; | ||
y.prototype.un; | ||
function X(s) { | ||
if (Array.isArray(s)) | ||
for (let e = 0, t = s.length; e < t; ++e) | ||
M(s[e]); | ||
else | ||
M( | ||
/** @type {import("./events.js").EventsKey} */ | ||
s | ||
); | ||
} | ||
const q = y; | ||
let J = 0; | ||
function Q(s) { | ||
return s.ol_uid || (s.ol_uid = String(++J)); | ||
} | ||
class T extends w { | ||
/** | ||
* @param {string} type The event type. | ||
* @param {string} key The property name. | ||
* @param {*} oldValue The old value for `key`. | ||
*/ | ||
constructor(e, t, n) { | ||
super(e), this.key = t, this.oldValue = n; | ||
} | ||
} | ||
class ee extends q { | ||
/** | ||
* @param {Object<string, *>} [values] An object with key-value pairs. | ||
*/ | ||
constructor(e) { | ||
super(), this.on, this.once, this.un, Q(this), this.values_ = null, e !== void 0 && this.setProperties(e); | ||
} | ||
/** | ||
* Gets a value. | ||
* @param {string} key Key name. | ||
* @return {*} Value. | ||
* @api | ||
*/ | ||
get(e) { | ||
let t; | ||
return this.values_ && this.values_.hasOwnProperty(e) && (t = this.values_[e]), t; | ||
} | ||
/** | ||
* Get a list of object property names. | ||
* @return {Array<string>} List of property names. | ||
* @api | ||
*/ | ||
getKeys() { | ||
return this.values_ && Object.keys(this.values_) || []; | ||
} | ||
/** | ||
* Get an object of all property names and values. | ||
* @return {Object<string, *>} Object. | ||
* @api | ||
*/ | ||
getProperties() { | ||
return this.values_ && Object.assign({}, this.values_) || {}; | ||
} | ||
/** | ||
* @return {boolean} The object has properties. | ||
*/ | ||
hasProperties() { | ||
return !!this.values_; | ||
} | ||
/** | ||
* @param {string} key Key name. | ||
* @param {*} oldValue Old value. | ||
*/ | ||
notify(e, t) { | ||
let n; | ||
n = `change:${e}`, this.hasListener(n) && this.dispatchEvent(new T(n, e, t)), n = F.PROPERTYCHANGE, this.hasListener(n) && this.dispatchEvent(new T(n, e, t)); | ||
} | ||
/** | ||
* @param {string} key Key name. | ||
* @param {import("./events.js").Listener} listener Listener. | ||
*/ | ||
addChangeListener(e, t) { | ||
this.addEventListener(`change:${e}`, t); | ||
} | ||
/** | ||
* @param {string} key Key name. | ||
* @param {import("./events.js").Listener} listener Listener. | ||
*/ | ||
removeChangeListener(e, t) { | ||
this.removeEventListener(`change:${e}`, t); | ||
} | ||
/** | ||
* Sets a value. | ||
* @param {string} key Key name. | ||
* @param {*} value Value. | ||
* @param {boolean} [silent] Update without triggering an event. | ||
* @api | ||
*/ | ||
set(e, t, n) { | ||
const r = this.values_ || (this.values_ = {}); | ||
if (n) | ||
r[e] = t; | ||
else { | ||
const i = r[e]; | ||
r[e] = t, i !== t && this.notify(e, i); | ||
} | ||
} | ||
/** | ||
* Sets a collection of key-value pairs. Note that this changes any existing | ||
* properties and adds new ones (it does not remove any existing properties). | ||
* @param {Object<string, *>} values Values. | ||
* @param {boolean} [silent] Update without triggering an event. | ||
* @api | ||
*/ | ||
setProperties(e, t) { | ||
for (const n in e) | ||
this.set(n, e[n], t); | ||
} | ||
/** | ||
* Apply any properties from another object without triggering events. | ||
* @param {BaseObject} source The source object. | ||
* @protected | ||
*/ | ||
applyProperties(e) { | ||
e.values_ && Object.assign(this.values_ || (this.values_ = {}), e.values_); | ||
} | ||
/** | ||
* Unsets a property. | ||
* @param {string} key Key name. | ||
* @param {boolean} [silent] Unset without triggering an event. | ||
* @api | ||
*/ | ||
unset(e, t) { | ||
if (this.values_ && e in this.values_) { | ||
const n = this.values_[e]; | ||
delete this.values_[e], Y(this.values_) && (this.values_ = null), t || this.notify(e, n); | ||
} | ||
} | ||
} | ||
const te = ee, ne = { | ||
/** | ||
* Triggered after a map frame is rendered. | ||
* @event module:ol/MapEvent~MapEvent#postrender | ||
* @api | ||
*/ | ||
POSTRENDER: "postrender", | ||
/** | ||
* Triggered when the map starts moving. | ||
* @event module:ol/MapEvent~MapEvent#movestart | ||
* @api | ||
*/ | ||
MOVESTART: "movestart", | ||
/** | ||
* Triggered after the map is moved. | ||
* @event module:ol/MapEvent~MapEvent#moveend | ||
* @api | ||
*/ | ||
MOVEEND: "moveend", | ||
/** | ||
* Triggered when loading of additional map data (tiles, images, features) starts. | ||
* @event module:ol/MapEvent~MapEvent#loadstart | ||
* @api | ||
*/ | ||
LOADSTART: "loadstart", | ||
/** | ||
* Triggered when loading of additional map data has completed. | ||
* @event module:ol/MapEvent~MapEvent#loadend | ||
* @api | ||
*/ | ||
LOADEND: "loadend" | ||
}; | ||
function D(s) { | ||
return s && s.parentNode ? s.parentNode.removeChild(s) : null; | ||
} | ||
class se extends te { | ||
/** | ||
* @param {Options} options Control options. | ||
*/ | ||
constructor(e) { | ||
super(); | ||
const t = e.element; | ||
t && !e.target && !t.style.pointerEvents && (t.style.pointerEvents = "auto"), this.element = t || null, this.target_ = null, this.map_ = null, this.listenerKeys = [], e.render && (this.render = e.render), e.target && this.setTarget(e.target); | ||
} | ||
/** | ||
* Clean up. | ||
*/ | ||
disposeInternal() { | ||
D(this.element), super.disposeInternal(); | ||
} | ||
/** | ||
* Get the map associated with this control. | ||
* @return {import("../Map.js").default|null} Map. | ||
* @api | ||
*/ | ||
getMap() { | ||
return this.map_; | ||
} | ||
/** | ||
* Remove the control from its current map and attach it to the new map. | ||
* Pass `null` to just remove the control from the current map. | ||
* Subclasses may set up event handlers to get notified about changes to | ||
* the map here. | ||
* @param {import("../Map.js").default|null} map Map. | ||
* @api | ||
*/ | ||
setMap(e) { | ||
this.map_ && D(this.element); | ||
for (let t = 0, n = this.listenerKeys.length; t < n; ++t) | ||
M(this.listenerKeys[t]); | ||
this.listenerKeys.length = 0, this.map_ = e, e && ((this.target_ ? this.target_ : e.getOverlayContainerStopEvent()).appendChild(this.element), this.render !== x && this.listenerKeys.push( | ||
g(e, ne.POSTRENDER, this.render, this) | ||
), e.render()); | ||
} | ||
/** | ||
* Renders the control. | ||
* @param {import("../MapEvent.js").default} mapEvent Map event. | ||
* @api | ||
*/ | ||
render(e) { | ||
} | ||
/** | ||
* This function is used to set a target element for the control. It has no | ||
* effect if it is called after the control has been added to the map (i.e. | ||
* after `setMap` is called on the control). If no `target` is set in the | ||
* options passed to the control constructor and if `setTarget` is not called | ||
* then the control is added to the map's overlay container. | ||
* @param {HTMLElement|string} target Target. | ||
* @api | ||
*/ | ||
setTarget(e) { | ||
this.target_ = typeof e == "string" ? document.getElementById(e) : e; | ||
} | ||
} | ||
const ie = se; | ||
var C = {}, re = { | ||
get exports() { | ||
return C; | ||
}, | ||
set exports(s) { | ||
C = s; | ||
} | ||
}; | ||
function A() { | ||
} | ||
A.prototype = { | ||
on: function(s, e, t) { | ||
var n = this.e || (this.e = {}); | ||
return (n[s] || (n[s] = [])).push({ | ||
fn: e, | ||
ctx: t | ||
x.prototype = { | ||
on: function(n, t, e) { | ||
var s = this.e || (this.e = {}); | ||
return (s[n] || (s[n] = [])).push({ | ||
fn: t, | ||
ctx: e | ||
}), this; | ||
}, | ||
once: function(s, e, t) { | ||
var n = this; | ||
function r() { | ||
n.off(s, r), e.apply(t, arguments); | ||
once: function(n, t, e) { | ||
var s = this; | ||
function o() { | ||
s.off(n, o), t.apply(e, arguments); | ||
} | ||
return r._ = e, this.on(s, r, t); | ||
return o._ = t, this.on(n, o, e); | ||
}, | ||
emit: function(s) { | ||
var e = [].slice.call(arguments, 1), t = ((this.e || (this.e = {}))[s] || []).slice(), n = 0, r = t.length; | ||
for (n; n < r; n++) | ||
t[n].fn.apply(t[n].ctx, e); | ||
emit: function(n) { | ||
var t = [].slice.call(arguments, 1), e = ((this.e || (this.e = {}))[n] || []).slice(), s = 0, o = e.length; | ||
for (s; s < o; s++) | ||
e[s].fn.apply(e[s].ctx, t); | ||
return this; | ||
}, | ||
off: function(s, e) { | ||
var t = this.e || (this.e = {}), n = t[s], r = []; | ||
if (n && e) | ||
for (var i = 0, o = n.length; i < o; i++) | ||
n[i].fn !== e && n[i].fn._ !== e && r.push(n[i]); | ||
return r.length ? t[s] = r : delete t[s], this; | ||
off: function(n, t) { | ||
var e = this.e || (this.e = {}), s = e[n], o = []; | ||
if (s && t) | ||
for (var i = 0, l = s.length; i < l; i++) | ||
s[i].fn !== t && s[i].fn._ !== t && o.push(s[i]); | ||
return o.length ? e[n] = o : delete e[n], this; | ||
} | ||
}; | ||
re.exports = A; | ||
var oe = C.TinyEmitter = A; | ||
class ae extends w { | ||
/** | ||
* @param {string} type Event type. | ||
* @param {import("./Map.js").default} map Map. | ||
* @param {?import("./Map.js").FrameState} [frameState] Frame state. | ||
*/ | ||
constructor(e, t, n) { | ||
super(e), this.map = t, this.frameState = n !== void 0 ? n : null; | ||
S.exports = x; | ||
var _ = S.exports.TinyEmitter = x, L = /* @__PURE__ */ ((n) => (n.CONTEXTMENU = "contextmenu", n.CLICK = "click", n.DBLCLICK = "dblclick", n))(L || {}), p = /* @__PURE__ */ ((n) => (n.BEFOREOPEN = "beforeopen", n.OPEN = "open", n.CLOSE = "close", n.ADD_MENU_ENTRY = "add-menu-entry", n))(p || {}); | ||
class w extends D { | ||
constructor(t) { | ||
super(t.type, t.map, t.originalEvent); | ||
} | ||
} | ||
const le = ae; | ||
class he extends le { | ||
/** | ||
* @param {string} type Event type. | ||
* @param {import("./Map.js").default} map Map. | ||
* @param {EVENT} originalEvent Original event. | ||
* @param {boolean} [dragging] Is the map currently being dragged? | ||
* @param {import("./Map.js").FrameState} [frameState] Frame state. | ||
* @param {Array<PointerEvent>} [activePointers] Active pointers. | ||
*/ | ||
constructor(e, t, n, r, i, o) { | ||
super(e, t, i), this.originalEvent = n, this.pixel_ = null, this.coordinate_ = null, this.dragging = r !== void 0 ? r : !1, this.activePointers = o; | ||
} | ||
/** | ||
* The map pixel relative to the viewport corresponding to the original event. | ||
* @type {import("./pixel.js").Pixel} | ||
* @api | ||
*/ | ||
get pixel() { | ||
return this.pixel_ || (this.pixel_ = this.map.getEventPixel(this.originalEvent)), this.pixel_; | ||
} | ||
set pixel(e) { | ||
this.pixel_ = e; | ||
} | ||
/** | ||
* The coordinate corresponding to the original browser event. This will be in the user | ||
* projection if one is set. Otherwise it will be in the view projection. | ||
* @type {import("./coordinate.js").Coordinate} | ||
* @api | ||
*/ | ||
get coordinate() { | ||
return this.coordinate_ || (this.coordinate_ = this.map.getCoordinateFromPixel(this.pixel)), this.coordinate_; | ||
} | ||
set coordinate(e) { | ||
this.coordinate_ = e; | ||
} | ||
/** | ||
* Prevents the default browser action. | ||
* See https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault. | ||
* @api | ||
*/ | ||
preventDefault() { | ||
super.preventDefault(), "preventDefault" in this.originalEvent && this.originalEvent.preventDefault(); | ||
} | ||
/** | ||
* Prevents further propagation of the current event. | ||
* See https://developer.mozilla.org/en-US/docs/Web/API/event.stopPropagation. | ||
* @api | ||
*/ | ||
stopPropagation() { | ||
super.stopPropagation(), "stopPropagation" in this.originalEvent && this.originalEvent.stopPropagation(); | ||
} | ||
} | ||
const ce = he; | ||
var N = /* @__PURE__ */ ((s) => (s.CONTEXTMENU = "contextmenu", s.CLICK = "click", s.DBLCLICK = "dblclick", s))(N || {}), m = /* @__PURE__ */ ((s) => (s.BEFOREOPEN = "beforeopen", s.OPEN = "open", s.CLOSE = "close", s.ADD_MENU_ENTRY = "add-menu-entry", s))(m || {}); | ||
class R extends ce { | ||
constructor(e) { | ||
super(e.type, e.map, e.originalEvent); | ||
} | ||
} | ||
const ue = { | ||
const z = { | ||
width: 150, | ||
scrollAt: 4, | ||
eventType: N.CONTEXTMENU, | ||
eventType: L.CONTEXTMENU, | ||
defaultItems: !0, | ||
items: [] | ||
}, f = "ol-ctx-menu", a = { | ||
namespace: f, | ||
container: `${f}-container`, | ||
separator: `${f}-separator`, | ||
submenu: `${f}-submenu`, | ||
hidden: `${f}-hidden`, | ||
icon: `${f}-icon`, | ||
zoomIn: `${f}-zoom-in`, | ||
zoomOut: `${f}-zoom-out`, | ||
}, d = "ol-ctx-menu", r = { | ||
namespace: d, | ||
container: `${d}-container`, | ||
separator: `${d}-separator`, | ||
submenu: `${d}-submenu`, | ||
hidden: `${d}-hidden`, | ||
icon: `${d}-icon`, | ||
zoomIn: `${d}-zoom-in`, | ||
zoomOut: `${d}-zoom-out`, | ||
unselectable: "ol-unselectable" | ||
}, P = [ | ||
}, C = [ | ||
{ | ||
text: "Zoom In", | ||
classname: `${a.zoomIn} ${a.icon}`, | ||
callback: (s, e) => { | ||
const t = e.getView(); | ||
t.animate({ | ||
zoom: Number(t.getZoom()) + 1, | ||
classname: `${r.zoomIn} ${r.icon}`, | ||
callback: (n, t) => { | ||
const e = t.getView(); | ||
e.animate({ | ||
zoom: Number(e.getZoom()) + 1, | ||
duration: 700, | ||
center: s.coordinate | ||
center: n.coordinate | ||
}); | ||
@@ -670,9 +83,9 @@ } | ||
text: "Zoom Out", | ||
classname: `${a.zoomOut} ${a.icon}`, | ||
callback: (s, e) => { | ||
const t = e.getView(); | ||
t.animate({ | ||
zoom: Number(t.getZoom()) - 1, | ||
classname: `${r.zoomOut} ${r.icon}`, | ||
callback: (n, t) => { | ||
const e = t.getView(); | ||
e.animate({ | ||
zoom: Number(e.getZoom()) - 1, | ||
duration: 700, | ||
center: s.coordinate | ||
center: n.coordinate | ||
}); | ||
@@ -682,40 +95,40 @@ } | ||
]; | ||
function _(s) { | ||
const e = document.createDocumentFragment(), t = document.createElement("div"); | ||
for (t.innerHTML = s; t.firstChild; ) | ||
e.append(t.firstChild); | ||
return e; | ||
function y(n) { | ||
const t = document.createDocumentFragment(), e = document.createElement("div"); | ||
for (e.innerHTML = n; e.firstChild; ) | ||
t.append(e.firstChild); | ||
return t; | ||
} | ||
function de(s) { | ||
const e = document.importNode(s), t = s.offsetWidth; | ||
e.style.cssText = `position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${t}px`; | ||
const n = _("<span>Foo</span>"), r = _("<span>Foo</span>"), i = document.createElement("li"), o = document.createElement("li"); | ||
i.append(n), o.append(r), e.append(i), e.append(o), s.parentNode?.append(e); | ||
const l = e.offsetHeight / 2; | ||
return s.parentNode?.removeChild(e), l; | ||
function P(n) { | ||
const t = document.importNode(n), e = n.offsetWidth; | ||
t.style.cssText = `position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`; | ||
const s = y("<span>Foo</span>"), o = y("<span>Foo</span>"), i = document.createElement("li"), l = document.createElement("li"); | ||
i.append(s), l.append(o), t.append(i), t.append(l), n.parentNode?.append(t); | ||
const c = t.offsetHeight / 2; | ||
return n.parentNode?.removeChild(t), c; | ||
} | ||
function $({ | ||
parentNode: s, | ||
item: e, | ||
isSubmenu: t = !1, | ||
isInsideSubmenu: n = !1, | ||
emitter: r | ||
function N({ | ||
parentNode: n, | ||
item: t, | ||
isSubmenu: e = !1, | ||
isInsideSubmenu: s = !1, | ||
emitter: o | ||
}) { | ||
const i = `_${Math.random().toString(36).slice(2, 11)}`; | ||
if (typeof e != "string" && "text" in e) { | ||
const E = `<span>${e.text}</span>`, v = _(E), p = document.createElement("li"); | ||
e.classname = e.classname || "", e.icon && (e.classname === "" ? e.classname = a.icon : e.classname.includes(a.icon) === !1 && (e.classname += ` ${a.icon}`), p.setAttribute("style", `background-image:url(${e.icon})`)), p.id = i, p.className = e.classname, p.append(v), s.append(p); | ||
const b = { | ||
if (typeof t != "string" && "text" in t) { | ||
const E = `<span>${t.text}</span>`, m = y(E), u = document.createElement("li"); | ||
t.classname = t.classname || "", t.icon && (t.classname === "" ? t.classname = r.icon : t.classname.includes(r.icon) === !1 && (t.classname += ` ${r.icon}`), u.setAttribute("style", `background-image:url(${t.icon})`)), u.id = i, u.className = t.classname, u.append(m), n.append(u); | ||
const v = { | ||
id: i, | ||
isSubmenu: t, | ||
isInsideSubmenu: n, | ||
isSubmenu: e, | ||
isInsideSubmenu: s, | ||
isSeparator: !1, | ||
callback: "callback" in e ? e.callback : null, | ||
data: "data" in e ? e.data : null | ||
callback: "callback" in t ? t.callback : null, | ||
data: "data" in t ? t.data : null | ||
}; | ||
return r.emit(m.ADD_MENU_ENTRY, b, p), p; | ||
return o.emit(p.ADD_MENU_ENTRY, v, u), u; | ||
} | ||
const o = `<li id="${i}" class="${a.separator}"><hr></li>`, l = _(o); | ||
s.append(l); | ||
const u = s.lastChild, c = { | ||
const l = `<li id="${i}" class="${r.separator}"><hr></li>`, c = y(l); | ||
n.append(c); | ||
const f = n.lastChild, g = { | ||
id: i, | ||
@@ -728,20 +141,20 @@ isSubmenu: !1, | ||
}; | ||
return r.emit(m.ADD_MENU_ENTRY, c, u), u; | ||
return o.emit(p.ADD_MENU_ENTRY, g, f), f; | ||
} | ||
function O({ | ||
container: s, | ||
items: e, | ||
menuWidth: t, | ||
isInsideSubmenu: n, | ||
emitter: r | ||
function M({ | ||
container: n, | ||
items: t, | ||
menuWidth: e, | ||
isInsideSubmenu: s, | ||
emitter: o | ||
}) { | ||
e.forEach((i) => { | ||
t.forEach((i) => { | ||
if (typeof i != "string" && "items" in i && Array.isArray(i.items)) { | ||
const o = $({ parentNode: s, item: i, isSubmenu: !0, emitter: r }); | ||
o.classList.add(a.submenu); | ||
const l = document.createElement("ul"); | ||
l.classList.add(a.container), l.style.width = `${t}px`, o.append(l), O({ | ||
emitter: r, | ||
menuWidth: t, | ||
container: l, | ||
const l = N({ parentNode: n, item: i, isSubmenu: !0, emitter: o }); | ||
l.classList.add(r.submenu); | ||
const c = document.createElement("ul"); | ||
c.classList.add(r.container), c.style.width = `${e}px`, l.append(c), M({ | ||
emitter: o, | ||
menuWidth: e, | ||
container: c, | ||
items: i.items, | ||
@@ -751,41 +164,41 @@ isInsideSubmenu: !0 | ||
} else | ||
$({ | ||
parentNode: s, | ||
N({ | ||
parentNode: n, | ||
item: i, | ||
isSubmenu: !1, | ||
isInsideSubmenu: n, | ||
emitter: r | ||
isInsideSubmenu: s, | ||
emitter: o | ||
}); | ||
}); | ||
} | ||
function L(s, e) { | ||
if (!s) | ||
throw new Error(e); | ||
function b(n, t) { | ||
if (!n) | ||
throw new Error(t); | ||
} | ||
class fe extends ie { | ||
constructor(t = {}) { | ||
L(typeof t == "object", "@param `opts` should be object type!"); | ||
const n = document.createElement("div"); | ||
super({ element: n }); | ||
h(this, "map"); | ||
h(this, "emitter", new oe()); | ||
h(this, "container"); | ||
h(this, "coordinate", []); | ||
h(this, "pixel", []); | ||
h(this, "contextMenuEventListener"); | ||
h(this, "entryCallbackEventListener"); | ||
h(this, "mapMoveListener"); | ||
h(this, "lineHeight", 0); | ||
h(this, "disabled"); | ||
h(this, "opened"); | ||
h(this, "items", []); | ||
h(this, "menuEntries", /* @__PURE__ */ new Map()); | ||
h(this, "options"); | ||
this.options = { ...ue, ...t }; | ||
const r = document.createElement("ul"); | ||
n.append(r), n.style.width = `${this.options.width}px`, n.classList.add( | ||
a.container, | ||
a.unselectable, | ||
a.hidden | ||
), this.container = n, this.contextMenuEventListener = (i) => { | ||
class R extends O { | ||
constructor(e = {}) { | ||
b(typeof e == "object", "@param `opts` should be object type!"); | ||
const s = document.createElement("div"); | ||
super({ element: s }); | ||
a(this, "map"); | ||
a(this, "emitter", new _()); | ||
a(this, "container"); | ||
a(this, "coordinate", []); | ||
a(this, "pixel", []); | ||
a(this, "contextMenuEventListener"); | ||
a(this, "entryCallbackEventListener"); | ||
a(this, "mapMoveListener"); | ||
a(this, "lineHeight", 0); | ||
a(this, "disabled"); | ||
a(this, "opened"); | ||
a(this, "items", []); | ||
a(this, "menuEntries", /* @__PURE__ */ new Map()); | ||
a(this, "options"); | ||
this.options = { ...z, ...e }; | ||
const o = document.createElement("ul"); | ||
s.append(o), s.style.width = `${this.options.width}px`, s.classList.add( | ||
r.container, | ||
r.unselectable, | ||
r.hidden | ||
), this.container = s, this.contextMenuEventListener = (i) => { | ||
this.handleContextMenu(i); | ||
@@ -805,4 +218,4 @@ }, this.entryCallbackEventListener = (i) => { | ||
clear() { | ||
for (const t of this.menuEntries.keys()) | ||
this.removeMenuEntry(t); | ||
for (const e of this.menuEntries.keys()) | ||
this.removeMenuEntry(e); | ||
this.container.replaceChildren(), this.container.append(document.createElement("ul")); | ||
@@ -817,3 +230,3 @@ } | ||
getDefaultItems() { | ||
return P; | ||
return C; | ||
} | ||
@@ -823,5 +236,5 @@ countItems() { | ||
} | ||
extend(t) { | ||
L(Array.isArray(t), "@param `items` should be an Array."), O({ | ||
items: t, | ||
extend(e) { | ||
b(Array.isArray(e), "@param `items` should be an Array."), M({ | ||
items: e, | ||
emitter: this.emitter, | ||
@@ -833,3 +246,3 @@ menuWidth: this.options.width, | ||
closeMenu() { | ||
this.opened = !1, this.container.classList.add(a.hidden), this.dispatchEvent(m.CLOSE); | ||
this.opened = !1, this.container.classList.add(r.hidden), this.dispatchEvent(p.CLOSE); | ||
} | ||
@@ -839,31 +252,31 @@ isOpen() { | ||
} | ||
updatePosition(t) { | ||
L(Array.isArray(t), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = t, this.positionContainer()); | ||
updatePosition(e) { | ||
b(Array.isArray(e), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = e, this.positionContainer()); | ||
} | ||
pop() { | ||
const t = Array.from(this.menuEntries.keys()).pop(); | ||
t && this.removeMenuEntry(t); | ||
const e = Array.from(this.menuEntries.keys()).pop(); | ||
e && this.removeMenuEntry(e); | ||
} | ||
shift() { | ||
const t = Array.from(this.menuEntries.keys()).shift(); | ||
t && this.removeMenuEntry(t); | ||
const e = Array.from(this.menuEntries.keys()).shift(); | ||
e && this.removeMenuEntry(e); | ||
} | ||
push(t) { | ||
t && this.extend([t]); | ||
push(e) { | ||
e && this.extend([e]); | ||
} | ||
setMap(t) { | ||
if (super.setMap(t), t) { | ||
this.map = t, t.getViewport().addEventListener( | ||
setMap(e) { | ||
if (super.setMap(e), e) { | ||
this.map = e, e.getViewport().addEventListener( | ||
this.options.eventType, | ||
this.contextMenuEventListener, | ||
!1 | ||
), t.on("movestart", () => { | ||
), e.on("movestart", () => { | ||
this.handleMapMove(); | ||
}), this.emitter.on( | ||
m.ADD_MENU_ENTRY, | ||
(r, i) => { | ||
this.handleAddMenuEntry(r, i); | ||
p.ADD_MENU_ENTRY, | ||
(o, i) => { | ||
this.handleAddMenuEntry(o, i); | ||
}, | ||
this | ||
), this.items = this.options.defaultItems ? this.options.items.concat(P) : this.options.items, O({ | ||
), this.items = this.options.defaultItems ? this.options.items.concat(C) : this.options.items, M({ | ||
items: this.items, | ||
@@ -874,4 +287,4 @@ emitter: this.emitter, | ||
}); | ||
const n = this.getMenuEntriesLength(); | ||
this.lineHeight = n > 0 ? this.container.offsetHeight / n : de(this.container); | ||
const s = this.getMenuEntriesLength(); | ||
this.lineHeight = s > 0 ? this.container.offsetHeight / s : P(this.container); | ||
} else | ||
@@ -881,21 +294,21 @@ this.removeListeners(), this.clear(); | ||
removeListeners() { | ||
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.emitter.off(m.ADD_MENU_ENTRY); | ||
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.emitter.off(p.ADD_MENU_ENTRY); | ||
} | ||
removeMenuEntry(t) { | ||
let n = document.getElementById(t); | ||
n?.remove(), n = null, this.menuEntries.delete(t); | ||
removeMenuEntry(e) { | ||
let s = document.getElementById(e); | ||
s?.remove(), s = null, this.menuEntries.delete(e); | ||
} | ||
handleContextMenu(t) { | ||
this.coordinate = this.map.getEventCoordinate(t), this.pixel = this.map.getEventPixel(t), this.dispatchEvent( | ||
new R({ | ||
handleContextMenu(e) { | ||
this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent( | ||
new w({ | ||
map: this.map, | ||
originalEvent: t, | ||
type: m.BEFOREOPEN | ||
originalEvent: e, | ||
type: p.BEFOREOPEN | ||
}) | ||
), !this.disabled && (this.options.eventType === N.CONTEXTMENU && (t.stopPropagation(), t.preventDefault()), setTimeout(() => { | ||
this.openMenu(t); | ||
}), t.target?.addEventListener( | ||
), !this.disabled && (this.options.eventType === L.CONTEXTMENU && (e.stopPropagation(), e.preventDefault()), setTimeout(() => { | ||
this.openMenu(e); | ||
}), e.target?.addEventListener( | ||
"pointerdown", | ||
(n) => { | ||
this.opened && (n.stopPropagation(), this.closeMenu()); | ||
(s) => { | ||
this.opened && (s.stopPropagation(), this.closeMenu()); | ||
}, | ||
@@ -905,8 +318,8 @@ { once: !0 } | ||
} | ||
openMenu(t) { | ||
this.opened = !0, this.positionContainer(), this.container.classList.remove(a.hidden), this.dispatchEvent( | ||
new R({ | ||
openMenu(e) { | ||
this.opened = !0, this.positionContainer(), this.container.classList.remove(r.hidden), this.dispatchEvent( | ||
new w({ | ||
map: this.map, | ||
originalEvent: t, | ||
type: m.OPEN | ||
originalEvent: e, | ||
type: p.OPEN | ||
}) | ||
@@ -917,31 +330,31 @@ ); | ||
return Array.from(this.menuEntries).filter( | ||
([, t]) => t.isSeparator === !1 && t.isSubmenu === !1 && t.isInsideSubmenu === !1 | ||
([, e]) => e.isSeparator === !1 && e.isSubmenu === !1 && e.isInsideSubmenu === !1 | ||
).length; | ||
} | ||
positionContainer() { | ||
const t = this.map.getSize() || [0, 0], n = { | ||
w: t[0] - this.pixel[0], | ||
h: t[1] - this.pixel[1] | ||
}, r = this.getMenuEntriesLength(), i = { | ||
const e = this.map.getSize() || [0, 0], s = { | ||
w: e[0] - this.pixel[0], | ||
h: e[1] - this.pixel[1] | ||
}, o = this.getMenuEntriesLength(), i = { | ||
w: this.container.offsetWidth, | ||
// a cheap way to recalculate container height | ||
// since offsetHeight is like cached | ||
h: Math.round(this.lineHeight * r) | ||
}, o = n.w >= i.w ? this.pixel[0] + 5 : this.pixel[0] - i.w; | ||
this.container.style.left = `${o}px`, this.container.style.top = n.h >= i.h ? `${this.pixel[1] - 10}px` : `${this.pixel[1] - i.h}px`, this.container.style.right = "auto", this.container.style.bottom = "auto", n.w -= i.w; | ||
const l = (E) => Array.from(E.children).filter( | ||
(v) => v.tagName === "LI" && v.classList.contains(a.submenu) | ||
h: Math.round(this.lineHeight * o) | ||
}, l = s.w >= i.w ? this.pixel[0] + 5 : this.pixel[0] - i.w; | ||
this.container.style.left = `${l}px`, this.container.style.top = s.h >= i.h ? `${this.pixel[1] - 10}px` : `${this.pixel[1] - i.h}px`, this.container.style.right = "auto", this.container.style.bottom = "auto", s.w -= i.w; | ||
const c = (E) => Array.from(E.children).filter( | ||
(m) => m.tagName === "LI" && m.classList.contains(r.submenu) | ||
); | ||
let u = 0; | ||
const c = (E, v) => { | ||
u += 1, l(E).forEach((b) => { | ||
const H = v >= i.w ? i.w - 8 : (i.w + 8) * -1, d = b.querySelector( | ||
`ul.${a.container}` | ||
), k = Math.round( | ||
this.lineHeight * Array.from(d.children).filter((K) => K.tagName === "LI").length | ||
let f = 0; | ||
const g = (E, m) => { | ||
f += 1, c(E).forEach((v) => { | ||
const A = m >= i.w ? i.w - 8 : (i.w + 8) * -1, h = v.querySelector( | ||
`ul.${r.container}` | ||
), $ = Math.round( | ||
this.lineHeight * Array.from(h.children).filter((T) => T.tagName === "LI").length | ||
); | ||
d.style.left = `${H}px`, d.style.right = "auto", d.style.top = n.h >= k + i.h ? "0" : `-${d.offsetHeight - 25}px`, d.style.bottom = "auto", d.style.zIndex = String(u), l(d).length > 0 && c(d, v - i.w); | ||
h.style.left = `${A}px`, h.style.right = "auto", h.style.top = s.h >= $ + i.h ? "0" : `-${h.offsetHeight - 25}px`, h.style.bottom = "auto", h.style.zIndex = String(f), c(h).length > 0 && g(h, m - i.w); | ||
}); | ||
}; | ||
c(this.container.firstElementChild, n.w); | ||
g(this.container.firstElementChild, s.w); | ||
} | ||
@@ -951,19 +364,19 @@ handleMapMove() { | ||
} | ||
handleEntryCallback(t) { | ||
t.preventDefault(), t.stopPropagation(); | ||
const n = t.currentTarget, r = this.menuEntries.get(n.id); | ||
if (!r) | ||
handleEntryCallback(e) { | ||
e.preventDefault(), e.stopPropagation(); | ||
const s = e.currentTarget, o = this.menuEntries.get(s.id); | ||
if (!o) | ||
return; | ||
const i = { | ||
data: r.data, | ||
data: o.data, | ||
coordinate: this.coordinate | ||
}; | ||
this.closeMenu(), r.callback?.(i, this.map); | ||
this.closeMenu(), o.callback?.(i, this.map); | ||
} | ||
handleAddMenuEntry(t, n) { | ||
this.menuEntries.set(t.id, t), this.positionContainer(), "callback" in t && typeof t.callback == "function" && n.addEventListener("click", this.entryCallbackEventListener, !1); | ||
handleAddMenuEntry(e, s) { | ||
this.menuEntries.set(e.id, e), this.positionContainer(), "callback" in e && typeof e.callback == "function" && s.addEventListener("click", this.entryCallbackEventListener, !1); | ||
} | ||
} | ||
export { | ||
fe as default | ||
R as default | ||
}; |
@@ -1,2 +0,2 @@ | ||
import OlMap from 'ol/Map'; | ||
import type OlMap from 'ol/Map'; | ||
import type { Coordinate } from 'ol/coordinate'; | ||
@@ -3,0 +3,0 @@ import MapBrowserEvent from 'ol/MapBrowserEvent'; |
{ | ||
"name": "ol-contextmenu", | ||
"version": "5.2.1", | ||
"version": "5.3.0", | ||
"description": "Custom Context Menu for Openlayers", | ||
@@ -11,11 +11,13 @@ "type": "module", | ||
".": { | ||
"import": "./dist/ol-contextmenu.js", | ||
"require": "./dist/ol-contextmenu.umd.cjs", | ||
"types": "./dist/ol-contextmenu.d.ts" | ||
"import": { | ||
"types": "./dist/ol-contextmenu.d.ts", | ||
"default": "./dist/ol-contextmenu.js" | ||
} | ||
}, | ||
"./ol-contextmenu.css": { | ||
"import": "./dist/ol-contextmenu.css", | ||
"require": "./dist/ol-contextmenu.css", | ||
"style": "./dist/ol-contextmenu.css" | ||
} | ||
"./*": { | ||
"import": "./*", | ||
"require": "./*", | ||
"style": "./*" | ||
}, | ||
"./ol-contextmenu.css": "./dist/ol-contextmenu.css" | ||
}, | ||
@@ -37,3 +39,3 @@ "files": [ | ||
"engines": { | ||
"node": "^16 || ^18", | ||
"node": ">=16", | ||
"npm": ">=8" | ||
@@ -52,25 +54,25 @@ }, | ||
"devDependencies": { | ||
"@swc/core": "^1.3.44", | ||
"@swc/jest": "^0.2.24", | ||
"@types/jest": "^29.5.0", | ||
"eslint": "^8.37.0", | ||
"eslint-config-jwalker": "^8.1.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-jest": "^27.2.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"@swc/core": "^1.3.87", | ||
"@swc/jest": "^0.2.29", | ||
"@types/jest": "^29.5.5", | ||
"eslint": "^8.49.0", | ||
"eslint-config-jwalker": "^8.7.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-jest": "^27.4.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"husky": "^8.0.3", | ||
"identity-obj-proxy": "^3.0.0", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"ol": "^7.3.0", | ||
"prettier": "^2.8.7", | ||
"rimraf": "^4.4.1", | ||
"sass": "^1.60.0", | ||
"typescript": "^5.0.3", | ||
"vite": "^4.2.1", | ||
"vite-plugin-banner": "^0.7.0", | ||
"vite-plugin-dts": "^2.1.0" | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"ol": "^8.1.0", | ||
"prettier": "^3.0.3", | ||
"rimraf": "^5.0.1", | ||
"sass": "^1.68.0", | ||
"typescript": "^5.2.2", | ||
"vite": "^4.4.9", | ||
"vite-plugin-banner": "^0.7.1", | ||
"vite-plugin-dts": "^3.5.4" | ||
}, | ||
"peerDependencies": { | ||
"ol": "^7.1.0" | ||
"ol": "> 7.x <= 8.x" | ||
}, | ||
@@ -77,0 +79,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
49861
-36.17%615
-50.68%1
Infinity%1
Infinity%