ol-contextmenu 5.1.5 → 5.2.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/README.md CHANGED
@@ -21,7 +21,8 @@ A `contextmenu` extension for [OpenLayers](http://openlayers.org/). **Requires**
21
21
 
22
22
  ## Demo
23
23
 
24
- [JSFiddle](https://jsfiddle.net/jonataswalker/ooxs1w5d/).
24
+ [JSFiddle](https://jsfiddle.net/jonataswalker/ooxs1w5d/)
25
+ [CodeSandbox](https://codesandbox.io/s/openlayers-custom-context-menu-5s99kb?file=/src/index.js)
25
26
 
26
27
  ## How to use it?
27
28
 
@@ -54,7 +55,7 @@ Download [latest release](https://github.com/jonataswalker/ol-contextmenu/releas
54
55
  ##### Instantiate with some options and add the Control
55
56
 
56
57
  ```javascript
57
- var contextmenu = new ContextMenu({
58
+ const contextmenu = new ContextMenu({
58
59
  width: 170,
59
60
  defaultItems: true, // defaultItems are (for now) Zoom In/Zoom Out
60
61
  items: [
@@ -81,7 +82,7 @@ map.addControl(contextmenu);
81
82
  If you provide `items {Array}` a submenu will be created as a child of the current item.
82
83
 
83
84
  ```javascript
84
- var all_items = [
85
+ const all_items = [
85
86
  {
86
87
  text: 'Some Actions',
87
88
  items: [
@@ -108,18 +109,18 @@ var all_items = [
108
109
  ##### Would you like to propagate custom data to the callback handler?
109
110
 
110
111
  ```javascript
111
- var removeMarker = function (obj) {
112
+ const removeMarker = function (obj) {
112
113
  vectorLayer.getSource().removeFeature(obj.data.marker);
113
114
  };
114
- var removeMarkerItem = {
115
+ const removeMarkerItem = {
115
116
  text: 'Remove this Marker',
116
117
  icon: 'img/marker.png',
117
118
  callback: removeMarker,
118
119
  };
119
120
 
120
- var restore = false;
121
+ let restore = false;
121
122
  contextmenu.on('open', function (evt) {
122
- var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
123
+ const feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
123
124
  return ft;
124
125
  });
125
126
  if (feature) {
@@ -168,10 +169,10 @@ Add items to the menu. This pushes each item in the provided array to the end of
168
169
  Example:
169
170
 
170
171
  ```js
171
- var contextmenu = new ContextMenu();
172
+ const contextmenu = new ContextMenu();
172
173
  map.addControl(contextmenu);
173
174
 
174
- var add_later = [
175
+ const add_later = [
175
176
  '-', // this is a separator
176
177
  {
177
178
  text: 'Add a Marker',
@@ -216,7 +217,7 @@ Update menu's position.
216
217
 
217
218
  ```javascript
218
219
  contextmenu.on('beforeopen', function (evt) {
219
- var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
220
+ const feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
220
221
  return ft;
221
222
  });
222
223
 
@@ -233,7 +234,7 @@ contextmenu.on('beforeopen', function (evt) {
233
234
 
234
235
  ```javascript
235
236
  contextmenu.on('open', function (evt) {
236
- var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
237
+ const feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
237
238
  return ft;
238
239
  });
239
240
 
@@ -1,5 +1,18 @@
1
+ import { TinyEmitter } from 'tiny-emitter';
1
2
  import { Item } from '../types';
2
3
  export declare function createFragment(html: string): DocumentFragment;
3
4
  export declare function getLineHeight(container: HTMLDivElement): number;
4
- export declare function addMenuEntry(parentNode: HTMLUListElement, item: Item, isSubmenu?: boolean, isInsideSubmenu?: boolean): HTMLLIElement;
5
- export declare function addMenuEntries(container: HTMLUListElement, items: Item[], menuWidth: number, isInsideSubmenu?: boolean): void;
5
+ export declare function addMenuEntry({ parentNode, item, isSubmenu, isInsideSubmenu, emitter, }: {
6
+ parentNode: HTMLUListElement;
7
+ item: Item;
8
+ isSubmenu: boolean;
9
+ isInsideSubmenu?: boolean;
10
+ emitter: TinyEmitter;
11
+ }): HTMLLIElement;
12
+ export declare function addMenuEntries({ container, items, menuWidth, isInsideSubmenu, emitter, }: {
13
+ container: HTMLUListElement;
14
+ items: Item[];
15
+ menuWidth: number;
16
+ isInsideSubmenu?: boolean;
17
+ emitter: TinyEmitter;
18
+ }): void;
package/dist/main.d.ts CHANGED
@@ -1,15 +1,17 @@
1
- import type { Pixel } from 'ol/pixel';
2
- import type { Coordinate } from 'ol/coordinate';
3
1
  import OlMap from 'ol/Map';
4
- import Control from 'ol/control/Control';
5
- import BaseEvent from 'ol/events/Event';
2
+ import type { Pixel } from 'ol/pixel';
6
3
  import { EventsKey } from 'ol/events';
4
+ import BaseEvent from 'ol/events/Event';
5
+ import { ObjectEvent } from 'ol/Object';
6
+ import Control from 'ol/control/Control';
7
+ import { TinyEmitter } from 'tiny-emitter';
8
+ import type { Coordinate } from 'ol/coordinate';
7
9
  import { Types as ObjectEventTypes } from 'ol/ObjectEventType';
8
10
  import { CombinedOnSignature, EventTypes as OlEventTypes, OnSignature } from 'ol/Observable';
9
- import { ObjectEvent } from 'ol/Object';
10
11
  import { ContextMenuEvent, CustomEventTypes, Item, MenuEntry, Options } from './types';
11
12
  export default class ContextMenu extends Control {
12
13
  protected map: OlMap;
14
+ protected emitter: TinyEmitter;
13
15
  protected container: HTMLDivElement;
14
16
  protected coordinate: Coordinate;
15
17
  protected pixel: Pixel;
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
- * ol-contextmenu - v5.1.5
3
+ * ol-contextmenu - v5.2.1
4
4
  * https://github.com/jonataswalker/ol-contextmenu
5
- * Built: Sat Mar 11 2023 15:05:27 GMT-0300 (Brasilia Standard Time)
5
+ * Built: Fri Mar 31 2023 20:27:32 GMT-0300 (Brasilia Standard Time)
6
6
  */
7
7
 
8
8
  .ol-ctx-menu-container{position:absolute;padding:8px;background:#fff;color:#222;font-size:13px;border-radius:5px;box-shadow:#0003 3px 3px 5px;box-sizing:border-box}.ol-ctx-menu-container div,.ol-ctx-menu-container span,.ol-ctx-menu-container a,.ol-ctx-menu-container img,.ol-ctx-menu-container ul,.ol-ctx-menu-container li{margin:0;padding:0;border:0;font:inherit;font-size:100%;vertical-align:baseline}.ol-ctx-menu-container a img{border:none}.ol-ctx-menu-container *,.ol-ctx-menu-container *:before,.ol-ctx-menu-container *:after{box-sizing:inherit}.ol-ctx-menu-container.ol-ctx-menu-hidden{opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container ul{list-style:none}.ol-ctx-menu-container li{position:relative;line-height:20px;padding:2px 5px;white-space:nowrap}.ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover{cursor:pointer;background-color:#333;color:#eee}.ol-ctx-menu-container li.ol-ctx-menu-submenu .ol-ctx-menu-container{border:1px solid #eee;padding:8px;top:0;opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container li.ol-ctx-menu-submenu:after{position:absolute;top:7px;right:10px;content:"";display:inline-block;width:.6em;height:.6em;border-right:.3em solid #222;border-top:.3em solid #222;transform:rotate(45deg)}.ol-ctx-menu-container li.ol-ctx-menu-submenu:hover:after{border-color:#eee}.ol-ctx-menu-container:not(.ol-ctx-menu-hidden) li.ol-ctx-menu-submenu:hover>.ol-ctx-menu-container{opacity:1;visibility:visible;transition-delay:0s}.ol-ctx-menu-container li.ol-ctx-menu-separator{padding:0}.ol-ctx-menu-container li.ol-ctx-menu-separator hr{border:0;height:1px;background-image:linear-gradient(to left,rgba(0,0,0,0),rgba(0,0,0,.75),rgba(0,0,0,0))}.ol-ctx-menu-icon{text-indent:20px;background-size:20px auto;background-repeat:no-repeat;background-position:left center}.ol-ctx-menu-zoom-in{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABaUlEQVQ4T72U7VHCQBCGn90GtAMuNGCswFiBWIFQgWMFxg6wArECsQKhArEBiB1Qwa1zgQn5IAYcxv13k71n3919L8KJQ07M47+BzgG9TRfZ/JBuWhS6BJFHRJICYrZGZIz3z5Ct2+B7gG6I6kt+wewdkQVwjtkAkR5mC8yu26A1oItR/cTsOweQBdgutD8G7jGm2PJ2n8oqUKIpIjd4HxTM8gvaT/F+AlmWnyWaIXKF95eNguFzTYFhNsdWu9kFgFlaFMANUH3D8wDLoLgSTSD2il8NCe2ZXQBxWDGwxmyUzzOMBZ7wy7Qb2K0wQfXjMOBuhlFpZtNty5sFaTQBuTusZdymeqs1SpYKcO9HkE3KbTd9WFijMHJQ5hBNEAYNq5Qd0dhyke0GiE4QzjqfW23mHT8Hl4DG4Lce3FPE7AtbBSdsbNqpoJLgYkRnNeUV+xwJDHTnUEkxHGbhBXUs5TjJjew/KPy94g+NRaIVRYmMXwAAAABJRU5ErkJggg==)}.ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-in{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABc0lEQVQ4T71U21ECQRDsJgGdvQDECMQIxAjECMQILCPwzAAjECIQI0AiEDPQAPaWCBhrcKHuCUcV5f7dY3v6tUscefHIePhfwBBCF8CZqRCReRs1tQxDCH1VfQLQz4EsSY4AvIjIsgm8AhhCGKrqa9zwrqoLAKckB5HtguR1E2gBMITQU9VPAD8GICIGtl3e+xHJBwBT59xtHcsCYJZlUwA3kcGHbfDep51OZywi3/acZZm9vyJ5WR5o38uACmDunNt6ZwAkUxFZDwghDFT1jeSjiJinhVUBVNVJkiTDKO8CQA+AsbNQ7s1Ps0VVn5MkSfcCtmBoDZi1Bdx4eJ7zbBolrwPy3o9J3rWSHPs3A1BbjVKlYBaIyDgvu9LDXDU2RTZmXVW1oKyLxRD+OrkOrJLy5mVM0iaftDhuhVbsvBzMglzKUNW6IV/OOWtCM8MmVvEkmbwt83LaB19fdgOtVquUZJeknaDdobTwbOcvBzPcN/AXH1DFFWP7u9oAAAAASUVORK5CYII=)}.ol-ctx-menu-zoom-out{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABU0lEQVQ4T72U7VECMRRFz3sNaAdkacC1AtcKxApcKnCsQOwAK3CtQKxAqEBsANYOqCDPyTIC+8WCw5jfybn33dxEOPGSE/P4b6BzQG89RT47ZJoWhy5B5BGRZAMxWyEyxvtnyFdt8AagS1F9KQ6YvSMyB84xGyDSw2yO2XUbtAJ0MaqfmH0XAPIA2y7tj4F7jAm2uG1yWQZKNEHkBu+Dg2njWBJNEbnC+8uaIFRuWfuG2QxbbrOrUd0A1Tc8D7AIjkur7DAAsVf8MiWMZ3ZR2m02LPIMscATfjHqBnY7TFD9OAy4zTCCPG/MUKMM5O6wkXFr9dZq7FQqqHk/hDzbFa73cFONTZFDdRyiCcKg5rrSiLaXkiI6RjjrfG6VzDs+B5eAxuDXeYpmNRGzL2wZ/wof+du4GNFpBVqqz5HA4MM5VEYYDrOs+1I6Q9u/4Q8O9wN/AGgWjBVqQjjgAAAAAElFTkSuQmCC)}.ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-out{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABYklEQVQ4T72U4VHCQBCF36tA91KAWIFYgViBWIFYgWMFYgdYgVCBWAFSgdiBFpAsFWSdxcDkQoBkhnF/ZjbfvX377ogjF4/Mw/8CVbUD4MynEJF5k2lqFapqz8yeAPRKkCXJEYAXEVnugm8BVXVgZq/FD+9mtgBwSrJfqF2QvN4FjYCq2jWzTwA/DhARh20qTdMRyQcA0xDCbZ3KCJhl2RTATaHgo+6HLMv8+xXJy+qB3l8FGoB5CKHsXcRV1b6ZvZF8FBH3NKotoJlNkiQZFONdlLtJ3rufbouZPSdJMjwIbKDQEzBrClx7eC4i33Uepmk6JnnXaOQifzMAtdGoRApugYiMI1uqKkrRWAfZo9MxM1+UZzFewl8mN4nYdVM83L7BkwbXLUrF3sfBLQDQBbDy08x8vOohXyEE71lVq9emuEk+3gZa3XYroCvwFyjP8yHJDsnxwaU08GxvS2uFhw78BbzWrxXgMbsHAAAAAElFTkSuQmCC)}
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
- * ol-contextmenu - v5.1.5
3
+ * ol-contextmenu - v5.2.1
4
4
  * https://github.com/jonataswalker/ol-contextmenu
5
- * Built: Sat Mar 11 2023 15:05:27 GMT-0300 (Brasilia Standard Time)
5
+ * Built: Fri Mar 31 2023 20:27:32 GMT-0300 (Brasilia Standard Time)
6
6
  */
7
7
 
8
- var ContextMenu=function(f,h){"use strict";var U=Object.defineProperty;var F=(f,h,u)=>h in f?U(f,h,{enumerable:!0,configurable:!0,writable:!0,value:u}):f[h]=u;var a=(f,h,u)=>(F(f,typeof h!="symbol"?h+"":h,u),u);var u=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(u||{}),p=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(p||{});class A extends h.MapBrowserEvent{constructor(t){super(t.type,t.map,t.originalEvent)}}const k={width:150,scrollAt:4,eventType:u.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"},N=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(n,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(n,t)=>{const e=t.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var x={},T={get exports(){return x},set exports(n){x=n}};function L(){}L.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(n,t,e){var s=this;function i(){s.off(n,i),t.apply(e,arguments)}return i._=t,this.on(n,i,e)},emit:function(n){var t=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),s=0,i=e.length;for(s;s<i;s++)e[s].fn.apply(e[s].ctx,t);return this},off:function(n,t){var e=this.e||(this.e={}),s=e[n],i=[];if(s&&t)for(var o=0,l=s.length;o<l;o++)s[o].fn!==t&&s[o].fn._!==t&&i.push(s[o]);return i.length?e[n]=i:delete e[n],this}},T.exports=L;var O=x.TinyEmitter=L;const y=new O;function v(n){const t=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)t.append(e.firstChild);return t}function D(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=v("<span>Foo</span>"),i=v("<span>Foo</span>"),o=document.createElement("li"),l=document.createElement("li");o.append(s),l.append(i),t.append(o),t.append(l),n.parentNode?.append(t);const E=t.offsetHeight/2;return n.parentNode?.removeChild(t),E}function S(n,t,e=!1,s=!1){const i=`_${Math.random().toString(36).slice(2,11)}`;if(typeof t!="string"&&"text"in t){const b=`<span>${t.text}</span>`,g=v(b),c=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}`),c.setAttribute("style",`background-image:url(${t.icon})`)),c.id=i,c.className=t.classname,c.append(g),n.append(c);const $={id:i,isSubmenu:e,isInsideSubmenu:s,isSeparator:!1,callback:"callback"in t?t.callback:null,data:"data"in t?t.data:null};return y.emit(p.ADD_MENU_ENTRY,$,c),c}const o=`<li id="${i}" class="${r.separator}"><hr></li>`,l=v(o);n.append(l);const E=n.lastChild,M={id:i,isSubmenu:!1,isInsideSubmenu:!1,isSeparator:!0,callback:null,data:null};return y.emit(p.ADD_MENU_ENTRY,M,E),E}function w(n,t,e,s){t.forEach(i=>{if(typeof i!="string"&&"items"in i&&Array.isArray(i.items)){const o=S(n,i,!0);o.classList.add(r.submenu);const l=document.createElement("ul");l.classList.add(r.container),l.style.width=`${e}px`,o.append(l),w(l,i.items,e,!0)}else S(n,i,!1,s)})}const R="";function C(n,t){if(!n)throw new Error(t)}class I extends f{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const s=document.createElement("div");super({element:s});a(this,"map");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 i=document.createElement("ul");s.append(i),s.style.width=`${this.options.width}px`,s.classList.add(r.container,r.unselectable,r.hidden),this.container=s,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},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 N}countItems(){return this.menuEntries.size}extend(e){C(Array.isArray(e),"@param `items` should be an Array."),w(this.container.firstElementChild,e,this.options.width)}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,this.map.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.map.on("movestart",()=>{this.handleMapMove()}),y.on(p.ADD_MENU_ENTRY,(i,o)=>{this.handleAddMenuEntry(i,o)},this),this.items=this.options.defaultItems?this.options.items.concat(N):this.options.items,w(this.container.firstElementChild,this.items,this.options.width);const s=this.getMenuEntriesLength();this.lineHeight=s>0?this.container.offsetHeight/s:D(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),y.off(p.ADD_MENU_ENTRY)}removeMenuEntry(e){const s=document.getElementById(e);s?.remove(),s?.removeEventListener("click",this.entryCallbackEventListener),this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent(new A({type:p.BEFOREOPEN,map:this.map,originalEvent:e})),!this.disabled&&(this.options.eventType===u.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)}),e.target?.addEventListener("pointerdown",s=>{this.opened&&(s.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new A({type:p.OPEN,map:this.map,originalEvent:e}))}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],s={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},i=this.getMenuEntriesLength(),o={w:this.container.offsetWidth,h:Math.round(this.lineHeight*i)},l=s.w>=o.w?this.pixel[0]+5:this.pixel[0]-o.w;this.container.style.left=`${l}px`,this.container.style.top=s.h>=o.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-o.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",s.w-=o.w;const E=g=>Array.from(g.children).filter(c=>c.tagName==="LI"&&c.classList.contains(r.submenu));let M=0;const b=(g,c)=>{M+=1,E(g).forEach(_=>{const z=c>=o.w?o.w-8:(o.w+8)*-1,d=_.querySelector(`ul.${r.container}`),P=Math.round(this.lineHeight*Array.from(d.children).filter(H=>H.tagName==="LI").length);d.style.left=`${z}px`,d.style.right="auto",d.style.top=s.h>=P+o.h?"0":`-${d.offsetHeight-25}px`,d.style.bottom="auto",d.style.zIndex=String(M),E(d).length>0&&b(d,c-o.w)})};b(this.container.firstElementChild,s.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const s=e.currentTarget,i=this.menuEntries.get(s.id);if(!i)return;const o={coordinate:this.coordinate,data:i.data};this.closeMenu(),i.callback?.(o,this.map)}handleAddMenuEntry(e,s){this.menuEntries.set(e.id,e),this.positionContainer(),"callback"in e&&typeof e.callback=="function"&&s.addEventListener("click",this.entryCallbackEventListener,!1)}}return I}(ol.control.Control,ol);
8
+ 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}();