ol-contextmenu 5.1.0 → 5.1.2

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,9 @@ A `contextmenu` extension for [OpenLayers](http://openlayers.org/). **Requires**
21
21
 
22
22
  ## Demo
23
23
 
24
- [JSFiddle](https://jsfiddle.net/jonataswalker/ooxs1w5d/).
24
+ [CodeSandbox](https://codesandbox.io/s/openlayers-custom-context-menu-5s99kb?file=/src/index.js)
25
+
26
+ [JSFiddle](https://jsfiddle.net/jonataswalker/ooxs1w5d/)
25
27
 
26
28
  ## How to use it?
27
29
 
package/dist/main.d.ts CHANGED
@@ -2,7 +2,12 @@ import type { Pixel } from 'ol/pixel';
2
2
  import type { Coordinate } from 'ol/coordinate';
3
3
  import OlMap from 'ol/Map';
4
4
  import Control from 'ol/control/Control';
5
- import { Item, MenuEntry, Options } from './types';
5
+ import BaseEvent from 'ol/events/Event';
6
+ import { EventsKey } from 'ol/events';
7
+ import { Types as ObjectEventTypes } from 'ol/ObjectEventType';
8
+ import { CombinedOnSignature, EventTypes as OlEventTypes, OnSignature } from 'ol/Observable';
9
+ import { ObjectEvent } from 'ol/Object';
10
+ import { ContextMenuEvent, CustomEventTypes, Item, MenuEntry, Options } from './types';
6
11
  export default class ContextMenu extends Control {
7
12
  protected map: OlMap;
8
13
  protected container: HTMLDivElement;
@@ -16,6 +21,9 @@ export default class ContextMenu extends Control {
16
21
  protected opened: boolean;
17
22
  protected items: Item[];
18
23
  protected menuEntries: Map<string, MenuEntry>;
24
+ on: OnSignature<OlEventTypes | `${CustomEventTypes.CLOSE}`, BaseEvent, EventsKey> & OnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}`, ContextMenuEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, EventsKey> & CombinedOnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}` | ObjectEventTypes | `${CustomEventTypes.CLOSE}` | OlEventTypes, EventsKey>;
25
+ once: OnSignature<OlEventTypes | `${CustomEventTypes.CLOSE}`, BaseEvent, EventsKey> & OnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}`, ContextMenuEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, EventsKey> & CombinedOnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}` | ObjectEventTypes | `${CustomEventTypes.CLOSE}` | OlEventTypes, EventsKey>;
26
+ un: OnSignature<OlEventTypes | `${CustomEventTypes.CLOSE}`, BaseEvent, void> & OnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}`, ContextMenuEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, void> & CombinedOnSignature<`${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}` | ObjectEventTypes | `${CustomEventTypes.CLOSE}` | OlEventTypes, void>;
19
27
  options: Options;
20
28
  constructor(opts?: Partial<Options>);
21
29
  clear(): void;
@@ -34,7 +42,7 @@ export default class ContextMenu extends Control {
34
42
  protected removeListeners(): void;
35
43
  protected removeMenuEntry(id: string): void;
36
44
  protected handleContextMenu(evt: MouseEvent): void;
37
- protected openMenu(): void;
45
+ protected openMenu(evt: MouseEvent): void;
38
46
  protected getMenuEntriesLength(): number;
39
47
  protected positionContainer(): void;
40
48
  protected handleMapMove(): void;
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
- * ol-contextmenu - v5.1.0
3
+ * ol-contextmenu - v5.1.2
4
4
  * https://github.com/jonataswalker/ol-contextmenu
5
- * Built: Sat Sep 24 2022 09:56:34 GMT-0300 (Brasilia Standard Time)
5
+ * Built: Mon Dec 26 2022 19:24:15 GMT-0300 (Brasilia Standard Time)
6
6
  */
7
7
 
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)}
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.0
3
+ * ol-contextmenu - v5.1.2
4
4
  * https://github.com/jonataswalker/ol-contextmenu
5
- * Built: Sat Sep 24 2022 09:56:34 GMT-0300 (Brasilia Standard Time)
5
+ * Built: Mon Dec 26 2022 19:24:15 GMT-0300 (Brasilia Standard Time)
6
6
  */
7
7
 
8
- var ContextMenu=function(p){"use strict";var z=Object.defineProperty;var H=(p,u,m)=>u in p?z(p,u,{enumerable:!0,configurable:!0,writable:!0,value:m}):p[u]=m;var r=(p,u,m)=>(H(p,typeof u!="symbol"?u+"":u,m),m);const m=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(p);var M=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(M||{}),f=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(f||{});const N={width:150,scrollAt:4,eventType:M.CONTEXTMENU,defaultItems:!0,items:[]},d="ol-ctx-menu",a={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"},w=[{text:"Zoom In",classname:`${a.zoomIn} ${a.icon}`,callback:(n,s)=>{const e=s.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${a.zoomOut} ${a.icon}`,callback:(n,s)=>{const e=s.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var A={exports:{}};function b(){}b.prototype={on:function(n,s,e){var t=this.e||(this.e={});return(t[n]||(t[n]=[])).push({fn:s,ctx:e}),this},once:function(n,s,e){var t=this;function i(){t.off(n,i),s.apply(e,arguments)}return i._=s,this.on(n,i,e)},emit:function(n){var s=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),t=0,i=e.length;for(t;t<i;t++)e[t].fn.apply(e[t].ctx,s);return this},off:function(n,s){var e=this.e||(this.e={}),t=e[n],i=[];if(t&&s)for(var o=0,l=t.length;o<l;o++)t[o].fn!==s&&t[o].fn._!==s&&i.push(t[o]);return i.length?e[n]=i:delete e[n],this}},A.exports=b;var S=A.exports.TinyEmitter=b;const x=new S;function y(n){const s=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)s.append(e.firstChild);return s}function k(n){const s=document.importNode(n),e=n.offsetWidth;s.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const t=y("<span>Foo</span>"),i=y("<span>Foo</span>"),o=document.createElement("li"),l=document.createElement("li");o.append(t),l.append(i),s.append(o),s.append(l),n.parentNode?.append(s);const E=s.offsetHeight/2;return n.parentNode?.removeChild(s),E}function $(n,s,e=!1){const t=`_${Math.random().toString(36).slice(2,11)}`;if(typeof s!="string"&&"text"in s){const E=`<span>${s.text}</span>`,v=y(E),c=document.createElement("li");return s.classname=s.classname||"",s.icon&&(s.classname===""?s.classname=a.icon:s.classname.includes(a.icon)===!1&&(s.classname+=` ${a.icon}`),c.setAttribute("style",`background-image:url(${s.icon})`)),c.id=t,c.className=s.classname,c.append(v),n.append(c),x.emit(f.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!1,callback:"callback"in s?s.callback:null,data:"data"in s?s.data:null},c),c}const i=`<li id="${t}" class="${a.separator}"><hr></li>`,o=y(i);n.append(o);const l=n.lastChild;return x.emit(f.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!0,callback:null,data:null},l),l}function L(n,s,e){s.forEach(t=>{if(typeof t!="string"&&"items"in t&&Array.isArray(t.items)){const i=$(n,t,!0);i.classList.add(a.submenu);const o=document.createElement("ul");o.classList.add(a.container),o.style.width=`${e}px`,i.append(o),L(o,t.items,e)}else $(n,t)})}const P="";function C(n,s){if(!n)throw new Error(s)}class T extends m.default{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const t=document.createElement("div");super({element:t});r(this,"map");r(this,"container");r(this,"coordinate",[]);r(this,"pixel",[]);r(this,"contextMenuEventListener");r(this,"entryCallbackEventListener");r(this,"mapMoveListener");r(this,"lineHeight",0);r(this,"disabled");r(this,"opened");r(this,"items",[]);r(this,"menuEntries",new Map);r(this,"options");this.options={...N,...e};const i=document.createElement("ul");t.append(i),t.style.width=`${this.options.width}px`,t.classList.add(a.container,a.unselectable,a.hidden),this.container=t,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,x.on(f.ADD_MENU_ENTRY,(o,l)=>{this.handleAddMenuEntry(o,l)},this)}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 w}countItems(){return this.menuEntries.size}extend(e){C(Array.isArray(e),"@param `items` should be an Array."),L(this.container.firstElementChild,e,this.options.width)}closeMenu(){this.opened=!1,this.container.classList.add(a.hidden),this.dispatchEvent(f.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()}),this.items=this.options.defaultItems?this.options.items.concat(w):this.options.items,L(this.container.firstElementChild,this.items,this.options.width);const t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:k(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1)}removeMenuEntry(e){const t=document.getElementById(e);t?.remove(),t?.removeEventListener("click",this.entryCallbackEventListener),this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent({type:f.BEFOREOPEN,pixel:this.pixel,coordinate:this.coordinate}),!this.disabled&&(this.options.eventType===M.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),this.openMenu(),e.target?.addEventListener("pointerdown",t=>{this.opened&&(t.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(){this.menuEntries.size!==0&&(this.opened=!0,this.positionContainer(),this.container.classList.remove(a.hidden))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1||e.isSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],t={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},i={w:this.container.offsetWidth,h:Math.round(this.lineHeight*this.getMenuEntriesLength())},o=t.w>=i.w?this.pixel[0]+5:this.pixel[0]-i.w;this.container.style.left=`${o}px`,this.container.style.top=t.h>=i.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-i.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",t.w-=i.w;const l=c=>Array.from(c.children).filter(g=>g.tagName==="LI"&&g.classList.contains(a.submenu));let E=0;const v=(c,g)=>{E+=1,l(c).forEach(_=>{const D=g>=i.w?i.w-8:(i.w+8)*-1,h=_.querySelector(`ul.${a.container}`),O=Math.round(this.lineHeight*Array.from(h.children).filter(I=>I.tagName==="LI").length);h.style.left=`${D}px`,h.style.right="auto",h.style.top=t.h>=O+i.h?"0":`-${h.offsetHeight-25}px`,h.style.bottom="auto",h.style.zIndex=String(E),l(h).length>0&&v(h,g-i.w)})};v(this.container.firstElementChild,t.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,i=this.menuEntries.get(t.id);if(!i)return;const o={coordinate:this.coordinate,data:i.data};this.closeMenu(),i.callback?.(o,this.map)}handleAddMenuEntry(e,t){this.menuEntries.set(e.id,e),"callback"in e&&typeof e.callback=="function"&&t.addEventListener("click",this.entryCallbackEventListener,!1)}}return T}(ol.control.Control);
8
+ var ContextMenu=function(f,h){"use strict";var P=Object.defineProperty;var H=(f,h,u)=>h in f?P(f,h,{enumerable:!0,configurable:!0,writable:!0,value:u}):f[h]=u;var a=(f,h,u)=>(H(f,typeof h!="symbol"?h+"":h,u),u);var u=(s=>(s.CONTEXTMENU="contextmenu",s.CLICK="click",s.DBLCLICK="dblclick",s))(u||{}),p=(s=>(s.BEFOREOPEN="beforeopen",s.OPEN="open",s.CLOSE="close",s.ADD_MENU_ENTRY="add-menu-entry",s))(p||{});class C extends h.MapBrowserEvent{constructor(n){super(n.type,n.map,n.originalEvent)}}const $={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"},A=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(s,n)=>{const e=n.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:s.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(s,n)=>{const e=n.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:s.coordinate})}}];var b={},S={get exports(){return b},set exports(s){b=s}};function x(){}x.prototype={on:function(s,n,e){var t=this.e||(this.e={});return(t[s]||(t[s]=[])).push({fn:n,ctx:e}),this},once:function(s,n,e){var t=this;function i(){t.off(s,i),n.apply(e,arguments)}return i._=n,this.on(s,i,e)},emit:function(s){var n=[].slice.call(arguments,1),e=((this.e||(this.e={}))[s]||[]).slice(),t=0,i=e.length;for(t;t<i;t++)e[t].fn.apply(e[t].ctx,n);return this},off:function(s,n){var e=this.e||(this.e={}),t=e[s],i=[];if(t&&n)for(var o=0,c=t.length;o<c;o++)t[o].fn!==n&&t[o].fn._!==n&&i.push(t[o]);return i.length?e[s]=i:delete e[s],this}},S.exports=x;var k=b.TinyEmitter=x;const v=new k;function y(s){const n=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=s;e.firstChild;)n.append(e.firstChild);return n}function T(s){const n=document.importNode(s),e=s.offsetWidth;n.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const t=y("<span>Foo</span>"),i=y("<span>Foo</span>"),o=document.createElement("li"),c=document.createElement("li");o.append(t),c.append(i),n.append(o),n.append(c),s.parentNode?.append(n);const E=n.offsetHeight/2;return s.parentNode?.removeChild(n),E}function N(s,n,e=!1){const t=`_${Math.random().toString(36).slice(2,11)}`;if(typeof n!="string"&&"text"in n){const E=`<span>${n.text}</span>`,M=y(E),l=document.createElement("li");return n.classname=n.classname||"",n.icon&&(n.classname===""?n.classname=r.icon:n.classname.includes(r.icon)===!1&&(n.classname+=` ${r.icon}`),l.setAttribute("style",`background-image:url(${n.icon})`)),l.id=t,l.className=n.classname,l.append(M),s.append(l),v.emit(p.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!1,callback:"callback"in n?n.callback:null,data:"data"in n?n.data:null},l),l}const i=`<li id="${t}" class="${r.separator}"><hr></li>`,o=y(i);s.append(o);const c=s.lastChild;return v.emit(p.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!0,callback:null,data:null},c),c}function L(s,n,e){n.forEach(t=>{if(typeof t!="string"&&"items"in t&&Array.isArray(t.items)){const i=N(s,t,!0);i.classList.add(r.submenu);const o=document.createElement("ul");o.classList.add(r.container),o.style.width=`${e}px`,i.append(o),L(o,t.items,e)}else N(s,t)})}const U="";function w(s,n){if(!s)throw new Error(n)}class O extends f{constructor(e={}){w(typeof e=="object","@param `opts` should be object type!");const t=document.createElement("div");super({element:t});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={...$,...e};const i=document.createElement("ul");t.append(i),t.style.width=`${this.options.width}px`,t.classList.add(r.container,r.unselectable,r.hidden),this.container=t,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1}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){w(Array.isArray(e),"@param `items` should be an Array."),L(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){w(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()}),v.on(p.ADD_MENU_ENTRY,(i,o)=>{this.handleAddMenuEntry(i,o)},this),this.items=this.options.defaultItems?this.options.items.concat(A):this.options.items,L(this.container.firstElementChild,this.items,this.options.width);const t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:T(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),v.off(p.ADD_MENU_ENTRY)}removeMenuEntry(e){const t=document.getElementById(e);t?.remove(),t?.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 C({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",t=>{this.opened&&(t.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.menuEntries.size!==0&&(this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new C({type:p.OPEN,map:this.map,originalEvent:e})))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1||e.isSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],t={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},i={w:this.container.offsetWidth,h:Math.round(this.lineHeight*this.getMenuEntriesLength())},o=t.w>=i.w?this.pixel[0]+5:this.pixel[0]-i.w;this.container.style.left=`${o}px`,this.container.style.top=t.h>=i.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-i.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",t.w-=i.w;const c=l=>Array.from(l.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let E=0;const M=(l,g)=>{E+=1,c(l).forEach(D=>{const _=g>=i.w?i.w-8:(i.w+8)*-1,d=D.querySelector(`ul.${r.container}`),I=Math.round(this.lineHeight*Array.from(d.children).filter(z=>z.tagName==="LI").length);d.style.left=`${_}px`,d.style.right="auto",d.style.top=t.h>=I+i.h?"0":`-${d.offsetHeight-25}px`,d.style.bottom="auto",d.style.zIndex=String(E),c(d).length>0&&M(d,g-i.w)})};M(this.container.firstElementChild,t.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,i=this.menuEntries.get(t.id);if(!i)return;const o={coordinate:this.coordinate,data:i.data};this.closeMenu(),i.callback?.(o,this.map)}handleAddMenuEntry(e,t){this.menuEntries.set(e.id,e),this.positionContainer(),"callback"in e&&typeof e.callback=="function"&&t.addEventListener("click",this.entryCallbackEventListener,!1)}}return O}(ol.control.Control,ol);
@@ -1,35 +1,41 @@
1
1
 
2
2
  /*!
3
- * ol-contextmenu - v5.1.0
3
+ * ol-contextmenu - v5.1.2
4
4
  * https://github.com/jonataswalker/ol-contextmenu
5
- * Built: Sat Sep 24 2022 09:56:34 GMT-0300 (Brasilia Standard Time)
5
+ * Built: Mon Dec 26 2022 19:24:15 GMT-0300 (Brasilia Standard Time)
6
6
  */
7
7
 
8
- var S = Object.defineProperty;
9
- var k = (s, t, e) => t in s ? S(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
10
- var r = (s, t, e) => (k(s, typeof t != "symbol" ? t + "" : t, e), e);
11
- import T from "ol/control/Control";
12
- var M = /* @__PURE__ */ ((s) => (s.CONTEXTMENU = "contextmenu", s.CLICK = "click", s.DBLCLICK = "dblclick", s))(M || {}), p = /* @__PURE__ */ ((s) => (s.BEFOREOPEN = "beforeopen", s.OPEN = "open", s.CLOSE = "close", s.ADD_MENU_ENTRY = "add-menu-entry", s))(p || {});
13
- const O = {
8
+ var k = Object.defineProperty;
9
+ var T = (s, t, e) => t in s ? k(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
10
+ var a = (s, t, e) => (T(s, typeof t != "symbol" ? t + "" : t, e), e);
11
+ import O from "ol/control/Control";
12
+ import { MapBrowserEvent as D } from "ol";
13
+ var b = /* @__PURE__ */ ((s) => (s.CONTEXTMENU = "contextmenu", s.CLICK = "click", s.DBLCLICK = "dblclick", s))(b || {}), p = /* @__PURE__ */ ((s) => (s.BEFOREOPEN = "beforeopen", s.OPEN = "open", s.CLOSE = "close", s.ADD_MENU_ENTRY = "add-menu-entry", s))(p || {});
14
+ class L extends D {
15
+ constructor(t) {
16
+ super(t.type, t.map, t.originalEvent);
17
+ }
18
+ }
19
+ const _ = {
14
20
  width: 150,
15
21
  scrollAt: 4,
16
- eventType: M.CONTEXTMENU,
22
+ eventType: b.CONTEXTMENU,
17
23
  defaultItems: !0,
18
24
  items: []
19
- }, d = "ol-ctx-menu", a = {
20
- namespace: d,
21
- container: `${d}-container`,
22
- separator: `${d}-separator`,
23
- submenu: `${d}-submenu`,
24
- hidden: `${d}-hidden`,
25
- icon: `${d}-icon`,
26
- zoomIn: `${d}-zoom-in`,
27
- zoomOut: `${d}-zoom-out`,
25
+ }, u = "ol-ctx-menu", r = {
26
+ namespace: u,
27
+ container: `${u}-container`,
28
+ separator: `${u}-separator`,
29
+ submenu: `${u}-submenu`,
30
+ hidden: `${u}-hidden`,
31
+ icon: `${u}-icon`,
32
+ zoomIn: `${u}-zoom-in`,
33
+ zoomOut: `${u}-zoom-out`,
28
34
  unselectable: "ol-unselectable"
29
- }, x = [
35
+ }, w = [
30
36
  {
31
37
  text: "Zoom In",
32
- classname: `${a.zoomIn} ${a.icon}`,
38
+ classname: `${r.zoomIn} ${r.icon}`,
33
39
  callback: (s, t) => {
34
40
  const e = t.getView();
35
41
  e.animate({
@@ -41,7 +47,7 @@ const O = {
41
47
  },
42
48
  {
43
49
  text: "Zoom Out",
44
- classname: `${a.zoomOut} ${a.icon}`,
50
+ classname: `${r.zoomOut} ${r.icon}`,
45
51
  callback: (s, t) => {
46
52
  const e = t.getView();
47
53
  e.animate({
@@ -52,10 +58,17 @@ const O = {
52
58
  }
53
59
  }
54
60
  ];
55
- var w = { exports: {} };
56
- function b() {
61
+ var v = {}, I = {
62
+ get exports() {
63
+ return v;
64
+ },
65
+ set exports(s) {
66
+ v = s;
67
+ }
68
+ };
69
+ function x() {
57
70
  }
58
- b.prototype = {
71
+ x.prototype = {
59
72
  on: function(s, t, e) {
60
73
  var n = this.e || (this.e = {});
61
74
  return (n[s] || (n[s] = [])).push({
@@ -79,33 +92,33 @@ b.prototype = {
79
92
  off: function(s, t) {
80
93
  var e = this.e || (this.e = {}), n = e[s], i = [];
81
94
  if (n && t)
82
- for (var o = 0, l = n.length; o < l; o++)
95
+ for (var o = 0, c = n.length; o < c; o++)
83
96
  n[o].fn !== t && n[o].fn._ !== t && i.push(n[o]);
84
97
  return i.length ? e[s] = i : delete e[s], this;
85
98
  }
86
99
  };
87
- w.exports = b;
88
- var D = w.exports.TinyEmitter = b;
89
- const y = new D();
90
- function E(s) {
100
+ I.exports = x;
101
+ var z = v.TinyEmitter = x;
102
+ const E = new z();
103
+ function g(s) {
91
104
  const t = document.createDocumentFragment(), e = document.createElement("div");
92
105
  for (e.innerHTML = s; e.firstChild; )
93
106
  t.append(e.firstChild);
94
107
  return t;
95
108
  }
96
- function I(s) {
109
+ function P(s) {
97
110
  const t = document.importNode(s), e = s.offsetWidth;
98
111
  t.style.cssText = `position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;
99
- const n = E("<span>Foo</span>"), i = E("<span>Foo</span>"), o = document.createElement("li"), l = document.createElement("li");
100
- o.append(n), l.append(i), t.append(o), t.append(l), s.parentNode?.append(t);
101
- const u = t.offsetHeight / 2;
102
- return s.parentNode?.removeChild(t), u;
112
+ const n = g("<span>Foo</span>"), i = g("<span>Foo</span>"), o = document.createElement("li"), c = document.createElement("li");
113
+ o.append(n), c.append(i), t.append(o), t.append(c), s.parentNode?.append(t);
114
+ const d = t.offsetHeight / 2;
115
+ return s.parentNode?.removeChild(t), d;
103
116
  }
104
- function L(s, t, e = !1) {
117
+ function C(s, t, e = !1) {
105
118
  const n = `_${Math.random().toString(36).slice(2, 11)}`;
106
119
  if (typeof t != "string" && "text" in t) {
107
- const u = `<span>${t.text}</span>`, f = E(u), c = document.createElement("li");
108
- return t.classname = t.classname || "", t.icon && (t.classname === "" ? t.classname = a.icon : t.classname.includes(a.icon) === !1 && (t.classname += ` ${a.icon}`), c.setAttribute("style", `background-image:url(${t.icon})`)), c.id = n, c.className = t.classname, c.append(f), s.append(c), y.emit(
120
+ const d = `<span>${t.text}</span>`, f = g(d), l = document.createElement("li");
121
+ return t.classname = t.classname || "", t.icon && (t.classname === "" ? t.classname = r.icon : t.classname.includes(r.icon) === !1 && (t.classname += ` ${r.icon}`), l.setAttribute("style", `background-image:url(${t.icon})`)), l.id = n, l.className = t.classname, l.append(f), s.append(l), E.emit(
109
122
  p.ADD_MENU_ENTRY,
110
123
  {
111
124
  id: n,
@@ -114,13 +127,13 @@ function L(s, t, e = !1) {
114
127
  callback: "callback" in t ? t.callback : null,
115
128
  data: "data" in t ? t.data : null
116
129
  },
117
- c
118
- ), c;
130
+ l
131
+ ), l;
119
132
  }
120
- const i = `<li id="${n}" class="${a.separator}"><hr></li>`, o = E(i);
133
+ const i = `<li id="${n}" class="${r.separator}"><hr></li>`, o = g(i);
121
134
  s.append(o);
122
- const l = s.lastChild;
123
- return y.emit(
135
+ const c = s.lastChild;
136
+ return E.emit(
124
137
  p.ADD_MENU_ENTRY,
125
138
  {
126
139
  id: n,
@@ -129,61 +142,55 @@ function L(s, t, e = !1) {
129
142
  callback: null,
130
143
  data: null
131
144
  },
132
- l
133
- ), l;
145
+ c
146
+ ), c;
134
147
  }
135
- function v(s, t, e) {
148
+ function M(s, t, e) {
136
149
  t.forEach((n) => {
137
150
  if (typeof n != "string" && "items" in n && Array.isArray(n.items)) {
138
- const i = L(s, n, !0);
139
- i.classList.add(a.submenu);
151
+ const i = C(s, n, !0);
152
+ i.classList.add(r.submenu);
140
153
  const o = document.createElement("ul");
141
- o.classList.add(a.container), o.style.width = `${e}px`, i.append(o), v(o, n.items, e);
154
+ o.classList.add(r.container), o.style.width = `${e}px`, i.append(o), M(o, n.items, e);
142
155
  } else
143
- L(s, n);
156
+ C(s, n);
144
157
  });
145
158
  }
146
- function g(s, t) {
159
+ function y(s, t) {
147
160
  if (!s)
148
161
  throw new Error(t);
149
162
  }
150
- class P extends T {
163
+ class B extends O {
151
164
  constructor(e = {}) {
152
- g(typeof e == "object", "@param `opts` should be object type!");
165
+ y(typeof e == "object", "@param `opts` should be object type!");
153
166
  const n = document.createElement("div");
154
167
  super({ element: n });
155
- r(this, "map");
156
- r(this, "container");
157
- r(this, "coordinate", []);
158
- r(this, "pixel", []);
159
- r(this, "contextMenuEventListener");
160
- r(this, "entryCallbackEventListener");
161
- r(this, "mapMoveListener");
162
- r(this, "lineHeight", 0);
163
- r(this, "disabled");
164
- r(this, "opened");
165
- r(this, "items", []);
166
- r(this, "menuEntries", /* @__PURE__ */ new Map());
167
- r(this, "options");
168
- this.options = { ...O, ...e };
168
+ a(this, "map");
169
+ a(this, "container");
170
+ a(this, "coordinate", []);
171
+ a(this, "pixel", []);
172
+ a(this, "contextMenuEventListener");
173
+ a(this, "entryCallbackEventListener");
174
+ a(this, "mapMoveListener");
175
+ a(this, "lineHeight", 0);
176
+ a(this, "disabled");
177
+ a(this, "opened");
178
+ a(this, "items", []);
179
+ a(this, "menuEntries", /* @__PURE__ */ new Map());
180
+ a(this, "options");
181
+ this.options = { ..._, ...e };
169
182
  const i = document.createElement("ul");
170
183
  n.append(i), n.style.width = `${this.options.width}px`, n.classList.add(
171
- a.container,
172
- a.unselectable,
173
- a.hidden
184
+ r.container,
185
+ r.unselectable,
186
+ r.hidden
174
187
  ), this.container = n, this.contextMenuEventListener = (o) => {
175
188
  this.handleContextMenu(o);
176
189
  }, this.entryCallbackEventListener = (o) => {
177
190
  this.handleEntryCallback(o);
178
191
  }, this.mapMoveListener = () => {
179
192
  this.handleMapMove();
180
- }, this.disabled = !1, this.opened = !1, y.on(
181
- p.ADD_MENU_ENTRY,
182
- (o, l) => {
183
- this.handleAddMenuEntry(o, l);
184
- },
185
- this
186
- );
193
+ }, this.disabled = !1, this.opened = !1;
187
194
  }
188
195
  clear() {
189
196
  for (const e of this.menuEntries.keys())
@@ -197,26 +204,26 @@ class P extends T {
197
204
  this.disabled = !0;
198
205
  }
199
206
  getDefaultItems() {
200
- return x;
207
+ return w;
201
208
  }
202
209
  countItems() {
203
210
  return this.menuEntries.size;
204
211
  }
205
212
  extend(e) {
206
- g(Array.isArray(e), "@param `items` should be an Array."), v(
213
+ y(Array.isArray(e), "@param `items` should be an Array."), M(
207
214
  this.container.firstElementChild,
208
215
  e,
209
216
  this.options.width
210
217
  );
211
218
  }
212
219
  closeMenu() {
213
- this.opened = !1, this.container.classList.add(a.hidden), this.dispatchEvent(p.CLOSE);
220
+ this.opened = !1, this.container.classList.add(r.hidden), this.dispatchEvent(p.CLOSE);
214
221
  }
215
222
  isOpen() {
216
223
  return this.opened;
217
224
  }
218
225
  updatePosition(e) {
219
- g(Array.isArray(e), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = e, this.positionContainer());
226
+ y(Array.isArray(e), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = e, this.positionContainer());
220
227
  }
221
228
  pop() {
222
229
  const e = Array.from(this.menuEntries.keys()).pop();
@@ -233,29 +240,39 @@ class P extends T {
233
240
  if (super.setMap(e), e) {
234
241
  this.map = e, this.map.getViewport().addEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.map.on("movestart", () => {
235
242
  this.handleMapMove();
236
- }), this.items = this.options.defaultItems ? this.options.items.concat(x) : this.options.items, v(
243
+ }), E.on(
244
+ p.ADD_MENU_ENTRY,
245
+ (i, o) => {
246
+ this.handleAddMenuEntry(i, o);
247
+ },
248
+ this
249
+ ), this.items = this.options.defaultItems ? this.options.items.concat(w) : this.options.items, M(
237
250
  this.container.firstElementChild,
238
251
  this.items,
239
252
  this.options.width
240
253
  );
241
254
  const n = this.getMenuEntriesLength();
242
- this.lineHeight = n > 0 ? this.container.offsetHeight / n : I(this.container);
255
+ this.lineHeight = n > 0 ? this.container.offsetHeight / n : P(this.container);
243
256
  } else
244
257
  this.removeListeners(), this.clear();
245
258
  }
246
259
  removeListeners() {
247
- this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1);
260
+ this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), E.off(p.ADD_MENU_ENTRY);
248
261
  }
249
262
  removeMenuEntry(e) {
250
263
  const n = document.getElementById(e);
251
264
  n?.remove(), n?.removeEventListener("click", this.entryCallbackEventListener), this.menuEntries.delete(e);
252
265
  }
253
266
  handleContextMenu(e) {
254
- this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent({
255
- type: p.BEFOREOPEN,
256
- pixel: this.pixel,
257
- coordinate: this.coordinate
258
- }), !this.disabled && (this.options.eventType === M.CONTEXTMENU && (e.stopPropagation(), e.preventDefault()), this.openMenu(), e.target?.addEventListener(
267
+ this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent(
268
+ new L({
269
+ type: p.BEFOREOPEN,
270
+ map: this.map,
271
+ originalEvent: e
272
+ })
273
+ ), !this.disabled && (this.options.eventType === b.CONTEXTMENU && (e.stopPropagation(), e.preventDefault()), setTimeout(() => {
274
+ this.openMenu(e);
275
+ }), e.target?.addEventListener(
259
276
  "pointerdown",
260
277
  (n) => {
261
278
  this.opened && (n.stopPropagation(), this.closeMenu());
@@ -263,8 +280,14 @@ class P extends T {
263
280
  { once: !0 }
264
281
  ));
265
282
  }
266
- openMenu() {
267
- this.menuEntries.size !== 0 && (this.opened = !0, this.positionContainer(), this.container.classList.remove(a.hidden));
283
+ openMenu(e) {
284
+ this.menuEntries.size !== 0 && (this.opened = !0, this.positionContainer(), this.container.classList.remove(r.hidden), this.dispatchEvent(
285
+ new L({
286
+ type: p.OPEN,
287
+ map: this.map,
288
+ originalEvent: e
289
+ })
290
+ ));
268
291
  }
269
292
  getMenuEntriesLength() {
270
293
  return Array.from(this.menuEntries).filter(
@@ -280,18 +303,18 @@ class P extends T {
280
303
  h: Math.round(this.lineHeight * this.getMenuEntriesLength())
281
304
  }, o = n.w >= i.w ? this.pixel[0] + 5 : this.pixel[0] - i.w;
282
305
  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;
283
- const l = (c) => Array.from(c.children).filter(
284
- (m) => m.tagName === "LI" && m.classList.contains(a.submenu)
306
+ const c = (l) => Array.from(l.children).filter(
307
+ (m) => m.tagName === "LI" && m.classList.contains(r.submenu)
285
308
  );
286
- let u = 0;
287
- const f = (c, m) => {
288
- u += 1, l(c).forEach((C) => {
289
- const A = m >= i.w ? i.w - 8 : (i.w + 8) * -1, h = C.querySelector(
290
- `ul.${a.container}`
309
+ let d = 0;
310
+ const f = (l, m) => {
311
+ d += 1, c(l).forEach((A) => {
312
+ const N = m >= i.w ? i.w - 8 : (i.w + 8) * -1, h = A.querySelector(
313
+ `ul.${r.container}`
291
314
  ), $ = Math.round(
292
- this.lineHeight * Array.from(h.children).filter((N) => N.tagName === "LI").length
315
+ this.lineHeight * Array.from(h.children).filter((S) => S.tagName === "LI").length
293
316
  );
294
- h.style.left = `${A}px`, h.style.right = "auto", h.style.top = n.h >= $ + i.h ? "0" : `-${h.offsetHeight - 25}px`, h.style.bottom = "auto", h.style.zIndex = String(u), l(h).length > 0 && f(h, m - i.w);
317
+ h.style.left = `${N}px`, h.style.right = "auto", h.style.top = n.h >= $ + i.h ? "0" : `-${h.offsetHeight - 25}px`, h.style.bottom = "auto", h.style.zIndex = String(d), c(h).length > 0 && f(h, m - i.w);
295
318
  });
296
319
  };
297
320
  f(this.container.firstElementChild, n.w);
@@ -311,9 +334,9 @@ class P extends T {
311
334
  this.closeMenu(), i.callback?.(o, this.map);
312
335
  }
313
336
  handleAddMenuEntry(e, n) {
314
- this.menuEntries.set(e.id, e), "callback" in e && typeof e.callback == "function" && n.addEventListener("click", this.entryCallbackEventListener, !1);
337
+ this.menuEntries.set(e.id, e), this.positionContainer(), "callback" in e && typeof e.callback == "function" && n.addEventListener("click", this.entryCallbackEventListener, !1);
315
338
  }
316
339
  }
317
340
  export {
318
- P as default
341
+ B as default
319
342
  };
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
- * ol-contextmenu - v5.1.0
3
+ * ol-contextmenu - v5.1.2
4
4
  * https://github.com/jonataswalker/ol-contextmenu
5
- * Built: Sat Sep 24 2022 09:56:34 GMT-0300 (Brasilia Standard Time)
5
+ * Built: Mon Dec 26 2022 19:24:15 GMT-0300 (Brasilia Standard Time)
6
6
  */
7
7
 
8
- (function(l,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("ol/control/Control")):typeof define=="function"&&define.amd?define(["ol/control/Control"],c):(l=typeof globalThis<"u"?globalThis:l||self,l.ContextMenu=c(l.ol.control.Control))})(this,function(l){"use strict";var z=Object.defineProperty;var H=(l,c,f)=>c in l?z(l,c,{enumerable:!0,configurable:!0,writable:!0,value:f}):l[c]=f;var a=(l,c,f)=>(H(l,typeof c!="symbol"?c+"":c,f),f);const f=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(l);var M=(n=>(n.CONTEXTMENU="contextmenu",n.CLICK="click",n.DBLCLICK="dblclick",n))(M||{}),m=(n=>(n.BEFOREOPEN="beforeopen",n.OPEN="open",n.CLOSE="close",n.ADD_MENU_ENTRY="add-menu-entry",n))(m||{});const N={width:150,scrollAt:4,eventType:M.CONTEXTMENU,defaultItems:!0,items:[]},p="ol-ctx-menu",r={namespace:p,container:`${p}-container`,separator:`${p}-separator`,submenu:`${p}-submenu`,hidden:`${p}-hidden`,icon:`${p}-icon`,zoomIn:`${p}-zoom-in`,zoomOut:`${p}-zoom-out`,unselectable:"ol-unselectable"},w=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(n,i)=>{const e=i.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:n.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(n,i)=>{const e=i.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:n.coordinate})}}];var A={exports:{}};function b(){}b.prototype={on:function(n,i,e){var t=this.e||(this.e={});return(t[n]||(t[n]=[])).push({fn:i,ctx:e}),this},once:function(n,i,e){var t=this;function s(){t.off(n,s),i.apply(e,arguments)}return s._=i,this.on(n,s,e)},emit:function(n){var i=[].slice.call(arguments,1),e=((this.e||(this.e={}))[n]||[]).slice(),t=0,s=e.length;for(t;t<s;t++)e[t].fn.apply(e[t].ctx,i);return this},off:function(n,i){var e=this.e||(this.e={}),t=e[n],s=[];if(t&&i)for(var o=0,h=t.length;o<h;o++)t[o].fn!==i&&t[o].fn._!==i&&s.push(t[o]);return s.length?e[n]=s:delete e[n],this}},A.exports=b;var S=A.exports.TinyEmitter=b;const x=new S;function y(n){const i=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=n;e.firstChild;)i.append(e.firstChild);return i}function k(n){const i=document.importNode(n),e=n.offsetWidth;i.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const t=y("<span>Foo</span>"),s=y("<span>Foo</span>"),o=document.createElement("li"),h=document.createElement("li");o.append(t),h.append(s),i.append(o),i.append(h),n.parentNode?.append(i);const E=i.offsetHeight/2;return n.parentNode?.removeChild(i),E}function $(n,i,e=!1){const t=`_${Math.random().toString(36).slice(2,11)}`;if(typeof i!="string"&&"text"in i){const E=`<span>${i.text}</span>`,v=y(E),u=document.createElement("li");return i.classname=i.classname||"",i.icon&&(i.classname===""?i.classname=r.icon:i.classname.includes(r.icon)===!1&&(i.classname+=` ${r.icon}`),u.setAttribute("style",`background-image:url(${i.icon})`)),u.id=t,u.className=i.classname,u.append(v),n.append(u),x.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!1,callback:"callback"in i?i.callback:null,data:"data"in i?i.data:null},u),u}const s=`<li id="${t}" class="${r.separator}"><hr></li>`,o=y(s);n.append(o);const h=n.lastChild;return x.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!0,callback:null,data:null},h),h}function L(n,i,e){i.forEach(t=>{if(typeof t!="string"&&"items"in t&&Array.isArray(t.items)){const s=$(n,t,!0);s.classList.add(r.submenu);const o=document.createElement("ul");o.classList.add(r.container),o.style.width=`${e}px`,s.append(o),L(o,t.items,e)}else $(n,t)})}const P="";function C(n,i){if(!n)throw new Error(i)}class T extends f.default{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const t=document.createElement("div");super({element:t});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={...N,...e};const s=document.createElement("ul");t.append(s),t.style.width=`${this.options.width}px`,t.classList.add(r.container,r.unselectable,r.hidden),this.container=t,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,x.on(m.ADD_MENU_ENTRY,(o,h)=>{this.handleAddMenuEntry(o,h)},this)}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 w}countItems(){return this.menuEntries.size}extend(e){C(Array.isArray(e),"@param `items` should be an Array."),L(this.container.firstElementChild,e,this.options.width)}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(m.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()}),this.items=this.options.defaultItems?this.options.items.concat(w):this.options.items,L(this.container.firstElementChild,this.items,this.options.width);const t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:k(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1)}removeMenuEntry(e){const t=document.getElementById(e);t?.remove(),t?.removeEventListener("click",this.entryCallbackEventListener),this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent({type:m.BEFOREOPEN,pixel:this.pixel,coordinate:this.coordinate}),!this.disabled&&(this.options.eventType===M.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),this.openMenu(),e.target?.addEventListener("pointerdown",t=>{this.opened&&(t.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(){this.menuEntries.size!==0&&(this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1||e.isSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],t={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},s={w:this.container.offsetWidth,h:Math.round(this.lineHeight*this.getMenuEntriesLength())},o=t.w>=s.w?this.pixel[0]+5:this.pixel[0]-s.w;this.container.style.left=`${o}px`,this.container.style.top=t.h>=s.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-s.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",t.w-=s.w;const h=u=>Array.from(u.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let E=0;const v=(u,g)=>{E+=1,h(u).forEach(_=>{const D=g>=s.w?s.w-8:(s.w+8)*-1,d=_.querySelector(`ul.${r.container}`),O=Math.round(this.lineHeight*Array.from(d.children).filter(I=>I.tagName==="LI").length);d.style.left=`${D}px`,d.style.right="auto",d.style.top=t.h>=O+s.h?"0":`-${d.offsetHeight-25}px`,d.style.bottom="auto",d.style.zIndex=String(E),h(d).length>0&&v(d,g-s.w)})};v(this.container.firstElementChild,t.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,s=this.menuEntries.get(t.id);if(!s)return;const o={coordinate:this.coordinate,data:s.data};this.closeMenu(),s.callback?.(o,this.map)}handleAddMenuEntry(e,t){this.menuEntries.set(e.id,e),"callback"in e&&typeof e.callback=="function"&&t.addEventListener("click",this.entryCallbackEventListener,!1)}}return T});
8
+ (function(l,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("ol/control/Control"),require("ol")):typeof define=="function"&&define.amd?define(["ol/control/Control","ol"],c):(l=typeof globalThis<"u"?globalThis:l||self,l.ContextMenu=c(l.ol.control.Control,l.ol))})(this,function(l,c){"use strict";var P=Object.defineProperty;var H=(l,c,d)=>c in l?P(l,c,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[c]=d;var a=(l,c,d)=>(H(l,typeof c!="symbol"?c+"":c,d),d);var d=(s=>(s.CONTEXTMENU="contextmenu",s.CLICK="click",s.DBLCLICK="dblclick",s))(d||{}),m=(s=>(s.BEFOREOPEN="beforeopen",s.OPEN="open",s.CLOSE="close",s.ADD_MENU_ENTRY="add-menu-entry",s))(m||{});class w extends c.MapBrowserEvent{constructor(n){super(n.type,n.map,n.originalEvent)}}const $={width:150,scrollAt:4,eventType:d.CONTEXTMENU,defaultItems:!0,items:[]},f="ol-ctx-menu",r={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`,unselectable:"ol-unselectable"},A=[{text:"Zoom In",classname:`${r.zoomIn} ${r.icon}`,callback:(s,n)=>{const e=n.getView();e.animate({zoom:Number(e.getZoom())+1,duration:700,center:s.coordinate})}},{text:"Zoom Out",classname:`${r.zoomOut} ${r.icon}`,callback:(s,n)=>{const e=n.getView();e.animate({zoom:Number(e.getZoom())-1,duration:700,center:s.coordinate})}}];var x={},S={get exports(){return x},set exports(s){x=s}};function b(){}b.prototype={on:function(s,n,e){var t=this.e||(this.e={});return(t[s]||(t[s]=[])).push({fn:n,ctx:e}),this},once:function(s,n,e){var t=this;function i(){t.off(s,i),n.apply(e,arguments)}return i._=n,this.on(s,i,e)},emit:function(s){var n=[].slice.call(arguments,1),e=((this.e||(this.e={}))[s]||[]).slice(),t=0,i=e.length;for(t;t<i;t++)e[t].fn.apply(e[t].ctx,n);return this},off:function(s,n){var e=this.e||(this.e={}),t=e[s],i=[];if(t&&n)for(var o=0,u=t.length;o<u;o++)t[o].fn!==n&&t[o].fn._!==n&&i.push(t[o]);return i.length?e[s]=i:delete e[s],this}},S.exports=b;var T=x.TinyEmitter=b;const y=new T;function v(s){const n=document.createDocumentFragment(),e=document.createElement("div");for(e.innerHTML=s;e.firstChild;)n.append(e.firstChild);return n}function k(s){const n=document.importNode(s),e=s.offsetWidth;n.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;const t=v("<span>Foo</span>"),i=v("<span>Foo</span>"),o=document.createElement("li"),u=document.createElement("li");o.append(t),u.append(i),n.append(o),n.append(u),s.parentNode?.append(n);const E=n.offsetHeight/2;return s.parentNode?.removeChild(n),E}function N(s,n,e=!1){const t=`_${Math.random().toString(36).slice(2,11)}`;if(typeof n!="string"&&"text"in n){const E=`<span>${n.text}</span>`,M=v(E),h=document.createElement("li");return n.classname=n.classname||"",n.icon&&(n.classname===""?n.classname=r.icon:n.classname.includes(r.icon)===!1&&(n.classname+=` ${r.icon}`),h.setAttribute("style",`background-image:url(${n.icon})`)),h.id=t,h.className=n.classname,h.append(M),s.append(h),y.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!1,callback:"callback"in n?n.callback:null,data:"data"in n?n.data:null},h),h}const i=`<li id="${t}" class="${r.separator}"><hr></li>`,o=v(i);s.append(o);const u=s.lastChild;return y.emit(m.ADD_MENU_ENTRY,{id:t,isSubmenu:e,isSeparator:!0,callback:null,data:null},u),u}function L(s,n,e){n.forEach(t=>{if(typeof t!="string"&&"items"in t&&Array.isArray(t.items)){const i=N(s,t,!0);i.classList.add(r.submenu);const o=document.createElement("ul");o.classList.add(r.container),o.style.width=`${e}px`,i.append(o),L(o,t.items,e)}else N(s,t)})}const U="";function C(s,n){if(!s)throw new Error(n)}class O extends l{constructor(e={}){C(typeof e=="object","@param `opts` should be object type!");const t=document.createElement("div");super({element:t});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={...$,...e};const i=document.createElement("ul");t.append(i),t.style.width=`${this.options.width}px`,t.classList.add(r.container,r.unselectable,r.hidden),this.container=t,this.contextMenuEventListener=o=>{this.handleContextMenu(o)},this.entryCallbackEventListener=o=>{this.handleEntryCallback(o)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1}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."),L(this.container.firstElementChild,e,this.options.width)}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(m.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(m.ADD_MENU_ENTRY,(i,o)=>{this.handleAddMenuEntry(i,o)},this),this.items=this.options.defaultItems?this.options.items.concat(A):this.options.items,L(this.container.firstElementChild,this.items,this.options.width);const t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:k(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),y.off(m.ADD_MENU_ENTRY)}removeMenuEntry(e){const t=document.getElementById(e);t?.remove(),t?.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 w({type:m.BEFOREOPEN,map:this.map,originalEvent:e})),!this.disabled&&(this.options.eventType===d.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)}),e.target?.addEventListener("pointerdown",t=>{this.opened&&(t.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.menuEntries.size!==0&&(this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new w({type:m.OPEN,map:this.map,originalEvent:e})))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1||e.isSubmenu===!1).length}positionContainer(){const e=this.map.getSize()||[0,0],t={w:e[0]-this.pixel[0],h:e[1]-this.pixel[1]},i={w:this.container.offsetWidth,h:Math.round(this.lineHeight*this.getMenuEntriesLength())},o=t.w>=i.w?this.pixel[0]+5:this.pixel[0]-i.w;this.container.style.left=`${o}px`,this.container.style.top=t.h>=i.h?`${this.pixel[1]-10}px`:`${this.pixel[1]-i.h}px`,this.container.style.right="auto",this.container.style.bottom="auto",t.w-=i.w;const u=h=>Array.from(h.children).filter(g=>g.tagName==="LI"&&g.classList.contains(r.submenu));let E=0;const M=(h,g)=>{E+=1,u(h).forEach(D=>{const _=g>=i.w?i.w-8:(i.w+8)*-1,p=D.querySelector(`ul.${r.container}`),I=Math.round(this.lineHeight*Array.from(p.children).filter(z=>z.tagName==="LI").length);p.style.left=`${_}px`,p.style.right="auto",p.style.top=t.h>=I+i.h?"0":`-${p.offsetHeight-25}px`,p.style.bottom="auto",p.style.zIndex=String(E),u(p).length>0&&M(p,g-i.w)})};M(this.container.firstElementChild,t.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();const t=e.currentTarget,i=this.menuEntries.get(t.id);if(!i)return;const o={coordinate:this.coordinate,data:i.data};this.closeMenu(),i.callback?.(o,this.map)}handleAddMenuEntry(e,t){this.menuEntries.set(e.id,e),this.positionContainer(),"callback"in e&&typeof e.callback=="function"&&t.addEventListener("click",this.entryCallbackEventListener,!1)}}return O});
package/dist/types.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import type { Coordinate } from 'ol/coordinate';
2
- import type { Pixel } from 'ol/pixel';
3
- import { Map as OlMap } from 'ol';
4
- import BaseEvent from 'ol/events/Event';
2
+ import { Map as OlMap, MapBrowserEvent } from 'ol';
5
3
  export declare enum EventTypes {
6
4
  CONTEXTMENU = "contextmenu",
7
5
  CLICK = "click",
@@ -13,9 +11,12 @@ export declare enum CustomEventTypes {
13
11
  CLOSE = "close",
14
12
  ADD_MENU_ENTRY = "add-menu-entry"
15
13
  }
16
- export interface ContextMenuEvent extends BaseEvent {
17
- coordinate: Coordinate;
18
- pixel: Pixel;
14
+ export declare class ContextMenuEvent extends MapBrowserEvent<MouseEvent> {
15
+ constructor(options: {
16
+ type: `${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}`;
17
+ map: OlMap;
18
+ originalEvent: MouseEvent;
19
+ });
19
20
  }
20
21
  export declare type CallbackObject = {
21
22
  coordinate: Coordinate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol-contextmenu",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "description": "Custom Context Menu for Openlayers",
5
5
  "type": "module",
6
6
  "main": "./dist/ol-contextmenu.umd.cjs",
@@ -42,27 +42,29 @@
42
42
  "lint": "eslint --cache --ext .js .",
43
43
  "lint:fix": "npm run lint -- --fix",
44
44
  "test": "jest",
45
- "prepublishOnly": "npm run lint && npm test && npm run build"
45
+ "prepublishOnly": "npm run lint && npm test && npm run build",
46
+ "prepare": "husky install"
46
47
  },
47
48
  "devDependencies": {
48
- "@swc/core": "^1.3.3",
49
- "@swc/jest": "^0.2.22",
50
- "@types/jest": "^29.0.3",
51
- "eslint": "^8.24.0",
52
- "eslint-config-jwalker": "^7.9.2",
49
+ "@swc/core": "^1.3.24",
50
+ "@swc/jest": "^0.2.24",
51
+ "@types/jest": "^29.2.4",
52
+ "eslint": "^8.30.0",
53
+ "eslint-config-jwalker": "^7.10.0",
53
54
  "eslint-config-prettier": "^8.5.0",
54
- "eslint-plugin-jest": "^27.0.4",
55
+ "eslint-plugin-jest": "^27.1.7",
55
56
  "eslint-plugin-prettier": "^4.2.1",
57
+ "husky": "^8.0.2",
56
58
  "identity-obj-proxy": "^3.0.0",
57
- "jest": "^29.0.3",
58
- "jest-environment-jsdom": "^29.0.3",
59
- "ol": "^7.1.0",
60
- "prettier": "^2.7.1",
59
+ "jest": "^29.3.1",
60
+ "jest-environment-jsdom": "^29.3.1",
61
+ "ol": "^7.2.2",
62
+ "prettier": "^2.8.1",
61
63
  "rimraf": "^3.0.2",
62
- "typescript": "^4.8.3",
63
- "vite": "^3.1.3",
64
- "vite-plugin-banner": "^0.5.0",
65
- "vite-plugin-dts": "^1.5.0"
64
+ "typescript": "^4.9.4",
65
+ "vite": "^4.0.3",
66
+ "vite-plugin-banner": "^0.7.0",
67
+ "vite-plugin-dts": "^1.7.1"
66
68
  },
67
69
  "peerDependencies": {
68
70
  "ol": "^7.1.0"