ol-contextmenu 5.1.4 → 5.1.5

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