ol-contextmenu 6.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ol-contextmenu.iife.js +4 -4
- package/dist/ol-contextmenu.js +342 -369
- package/dist/ol-contextmenu.umd.cjs +4 -4
- package/dist/src/constants.d.ts +18 -0
- package/dist/src/helpers/dom.d.ts +18 -0
- package/dist/src/main.d.ts +69 -0
- package/dist/src/types.d.ts +55 -0
- package/package.json +20 -17
- package/dist/ol-contextmenu.d.ts +0 -136
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v6.0.
|
|
3
|
+
* ol-contextmenu - v6.0.1
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built: 2026-
|
|
5
|
+
* Built: 2026-06-17T21:57:20.658Z
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
(function(){
|
|
9
|
-
var ContextMenu=(function(m,u){"use strict";var B=Object.defineProperty;var j=(m,u,d)=>u in m?B(m,u,{enumerable:!0,configurable:!0,writable:!0,value:d}):m[u]=d;var c=(m,u,d)=>j(m,typeof u!="symbol"?u+"":u,d);var d={exports:{}},A;function $(){if(A)return d.exports;A=1;function o(){}return o.prototype={on:function(i,t,e){var s=this.e||(this.e={});return(s[i]||(s[i]=[])).push({fn:t,ctx:e}),this},once:function(i,t,e){var s=this;function n(){s.off(i,n),t.apply(e,arguments)}return n._=t,this.on(i,n,e)},emit:function(i){var t=[].slice.call(arguments,1),e=((this.e||(this.e={}))[i]||[]).slice(),s=0,n=e.length;for(s;s<n;s++)e[s].fn.apply(e[s].ctx,t);return this},off:function(i,t){var e=this.e||(this.e={}),s=e[i],n=[];if(s&&t)for(var a=0,h=s.length;a<h;a++)s[a].fn!==t&&s[a].fn._!==t&&n.push(s[a]);return n.length?e[i]=n:delete e[i],this}},d.exports=o,d.exports.TinyEmitter=o,d.exports}var _=$(),L=(o=>(o.CONTEXTMENU="contextmenu",o.CLICK="click",o.DBLCLICK="dblclick",o))(L||{}),f=(o=>(o.BEFOREOPEN="beforeopen",o.OPEN="open",o.CLOSE="close",o.ADD_MENU_ENTRY="add-menu-entry",o))(f||{});class C extends u{constructor(i){super(i.type,i.map,i.originalEvent)}}const D={defaultItems:!0,eventType:L.CONTEXTMENU,items:[],scrollAt:4,width:150},E="ol-ctx-menu",r={container:`${E}-container`,hidden:`${E}-hidden`,icon:`${E}-icon`,separator:`${E}-separator`,submenu:`${E}-submenu`,unselectable:"ol-unselectable",zoomIn:`${E}-zoom-in`,zoomOut:`${E}-zoom-out`},P=8*2,S=10,M=2,T=[{callback:(o,i)=>{const t=i.getView();t.animate({center:o.coordinate,duration:700,zoom:Number(t.getZoom())+1})},classname:`${r.zoomIn} ${r.icon}`,text:"Zoom In"},{callback:(o,i)=>{const t=i.getView();t.animate({center:o.coordinate,duration:700,zoom:Number(t.getZoom())-1})},classname:`${r.zoomOut} ${r.icon}`,text:"Zoom Out"}];function v(o){const i=document.createDocumentFragment(),t=document.createElement("div");for(t.innerHTML=o;t.firstChild;)i.append(t.firstChild);return i}function k(o){const i=document.importNode(o),t=o.offsetWidth;i.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${t}px`;const e=v("<span>Foo</span>"),s=v("<span>Foo</span>"),n=document.createElement("li"),a=document.createElement("li");n.append(e),a.append(s),i.append(n),i.append(a),o.parentNode?.append(i);const h=i.offsetHeight/2;return o.parentNode?.removeChild(i),h}function I({emitter:o,isInsideSubmenu:i=!1,isSubmenu:t=!1,item:e,parentNode:s}){const n=`_${Math.random().toString(36).slice(2,11)}`;if(typeof e!="string"&&"text"in e){const x=`<span>${e.text}</span>`,y=v(x),l=document.createElement("li");e.classname=e.classname||"",e.icon&&(e.classname===""?e.classname=r.icon:e.classname.includes(r.icon)===!1&&(e.classname+=` ${r.icon}`),l.setAttribute("style",`background-image:url(${e.icon})`)),l.id=n,l.className=e.classname,l.append(y),s.append(l);const O={callback:"callback"in e?e.callback:null,data:"data"in e?e.data:null,id:n,isInsideSubmenu:i,isSeparator:!1,isSubmenu:t};return o.emit(f.ADD_MENU_ENTRY,O,l),l}const a=`<li id="${n}" class="${r.separator}"><hr></li>`,h=v(a);s.append(h);const g=s.lastChild,b={callback:null,data:null,id:n,isInsideSubmenu:!1,isSeparator:!0,isSubmenu:!1};return o.emit(f.ADD_MENU_ENTRY,b,g),g}function N({container:o,emitter:i,isInsideSubmenu:t,items:e,menuWidth:s}){e.forEach(n=>{if(typeof n!="string"&&"items"in n&&Array.isArray(n.items)){const a=I({emitter:i,isSubmenu:!0,item:n,parentNode:o});a.classList.add(r.submenu);const h=document.createElement("ul");h.classList.add(r.container),h.style.width=`${s}px`,a.append(h),N({container:h,emitter:i,isInsideSubmenu:!0,items:n.items,menuWidth:s})}else I({emitter:i,isInsideSubmenu:t,isSubmenu:!1,item:n,parentNode:o})})}function w(o,i){if(!o)throw new Error(i)}class H extends m{constructor(t={}){w(typeof t=="object","@param `opts` should be object type!");const e=document.createElement("div");super({element:e});c(this,"map");c(this,"emitter",new _.TinyEmitter);c(this,"container");c(this,"coordinate",[]);c(this,"pixel",[]);c(this,"contextMenuEventListener");c(this,"entryCallbackEventListener");c(this,"mapMoveListener");c(this,"lineHeight",0);c(this,"disabled");c(this,"opened");c(this,"items",[]);c(this,"menuEntries",new Map);c(this,"options");this.options={...D,...t};const s=document.createElement("ul");e.append(s),e.style.width=`${this.options.width}px`,e.classList.add(r.container,r.unselectable,r.hidden),this.container=e,this.contextMenuEventListener=n=>{this.handleContextMenu(n)},this.entryCallbackEventListener=n=>{this.handleEntryCallback(n)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener("beforeunload",()=>{this.removeListeners()},{once:!0})}clear(){for(const t of this.menuEntries.keys())this.removeMenuEntry(t);this.container.replaceChildren(),this.container.append(document.createElement("ul"))}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return T}countItems(){return this.menuEntries.size}extend(t){w(Array.isArray(t),"@param `items` should be an Array."),N({container:this.container.firstElementChild,emitter:this.emitter,items:t,menuWidth:this.options.width})}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(f.CLOSE)}isOpen(){return this.opened}updatePosition(t){w(Array.isArray(t),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=t,this.positionContainer())}pop(){const t=Array.from(this.menuEntries.keys()).pop();t&&this.removeMenuEntry(t)}shift(){const t=Array.from(this.menuEntries.keys()).shift();t&&this.removeMenuEntry(t)}push(t){t&&this.extend([t])}setMap(t){if(super.setMap(t),t){this.map=t,t.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),t.on("movestart",()=>{this.handleMapMove()}),this.emitter.on(f.ADD_MENU_ENTRY,(s,n)=>{this.handleAddMenuEntry(s,n)},this),this.items=this.options.defaultItems?this.options.items.concat(T):this.options.items,N({container:this.container.firstElementChild,emitter:this.emitter,items:this.items,menuWidth:this.options.width});const e=this.getMenuEntriesLength();this.lineHeight=e>0?this.container.offsetHeight/e:k(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.emitter.off(f.ADD_MENU_ENTRY)}removeMenuEntry(t){let e=document.getElementById(t);e?.remove(),e=null,this.menuEntries.delete(t)}handleContextMenu(t){this.coordinate=this.map.getEventCoordinate(t),this.pixel=this.map.getEventPixel(t),this.dispatchEvent(new C({map:this.map,originalEvent:t,type:f.BEFOREOPEN})),!this.disabled&&(this.options.eventType===L.CONTEXTMENU&&(t.stopPropagation(),t.preventDefault()),setTimeout(()=>{this.openMenu(t)}),t.target?.addEventListener("pointerdown",e=>{this.opened&&(e.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(t){this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new C({map:this.map,originalEvent:t,type:f.OPEN}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,t])=>t.isSeparator===!1&&t.isSubmenu===!1&&t.isInsideSubmenu===!1).length}calculateMenuSize(){const t=this.getMenuEntriesLength(),s=Math.round(this.lineHeight*t)+P,n=this.container.offsetHeight,a=!this.container.classList.contains(r.hidden);return{h:n>0&&a?n:s,w:this.container.offsetWidth}}calculateVerticalPosition(t,e,s){let n;return e.h>=s.h?(n=this.pixel[1]-S,n+s.h>t[1]&&(n=Math.max(0,t[1]-s.h-M))):(n=this.pixel[1]-s.h,n<0&&(n=s.h<=t[1]?0:Math.max(0,t[1]-s.h)),n+s.h>t[1]&&(n=Math.max(0,t[1]-s.h-M))),Math.max(0,Math.min(n,t[1]-s.h-M))}adjustPositionAfterRender(t,e){if(!this.container.classList.contains(r.hidden)){const s=this.container.offsetHeight;s>0&&s!==e.h&&(Number.parseInt(this.container.style.top,10)||0)+s>t[1]&&(this.container.style.top=`${Math.max(0,t[1]-s-M)}px`)}}positionContainer(){const t=this.map.getSize()||[0,0],e=[t[0]||0,t[1]||0],s={h:e[1]-this.pixel[1],w:e[0]-this.pixel[0]},n=this.calculateMenuSize(),a=s.w>=n.w?this.pixel[0]+5:this.pixel[0]-n.w;this.container.style.left=`${a}px`;const h=this.calculateVerticalPosition(e,s,n);this.container.style.top=`${h}px`,this.container.style.right="auto",this.container.style.bottom="auto",this.adjustPositionAfterRender(e,n),s.w-=n.w;const g=y=>Array.from(y.children).filter(l=>l.tagName==="LI"&&l.classList.contains(r.submenu));let b=0;const x=(y,l)=>{b+=1,g(y).forEach(R=>{const U=l>=n.w?n.w-8:(n.w+8)*-1,p=R.querySelector(`ul.${r.container}`),F=Math.round(this.lineHeight*Array.from(p.children).filter(V=>V.tagName==="LI").length);p.style.left=`${U}px`,p.style.right="auto",p.style.top=s.h>=F+n.h?"0":`-${p.offsetHeight-25}px`,p.style.bottom="auto",p.style.zIndex=String(b),g(p).length>0&&x(p,l-n.w)})};x(this.container.firstElementChild,s.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(t){t.preventDefault(),t.stopPropagation();const e=t.currentTarget,s=this.menuEntries.get(e.id);if(!s)return;const n={coordinate:this.coordinate,data:s.data};this.closeMenu(),s.callback?.(n,this.map)}handleAddMenuEntry(t,e){this.menuEntries.set(t.id,t),this.positionContainer(),"callback"in t&&typeof t.callback=="function"&&e.addEventListener("click",this.entryCallbackEventListener,!1)}}return H})(ol.control.Control,ol.MapBrowserEvent);
|
|
8
|
+
(function(){try{if(typeof document<`u`){var e=document.createElement(`style`);e.appendChild(document.createTextNode(`.ol-ctx-menu-container{color:#222;box-sizing:border-box;background:#fff;border-radius:5px;padding:8px;font-size:13px;position:absolute;box-shadow:3px 3px 5px #0003}.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{font:inherit;vertical-align:baseline;border:0;margin:0;padding:0;font-size:100%}.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{white-space:nowrap;padding:2px 5px;line-height:20px;position:relative}.ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover{cursor:pointer;color:#eee;background-color:#333}.ol-ctx-menu-container li.ol-ctx-menu-submenu .ol-ctx-menu-container{opacity:0;visibility:hidden;border:1px solid #eee;padding:8px;transition:visibility 0s linear .3s,opacity .3s;top:0}.ol-ctx-menu-container li.ol-ctx-menu-submenu:after{content:"";border-top:.3em solid #222;border-right:.3em solid #222;width:.6em;height:.6em;display:inline-block;position:absolute;top:7px;right:10px;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{background-image:linear-gradient(270deg,#0000,#000000bf,#0000);border:0;height:1px}.ol-ctx-menu-icon{text-indent:20px;background-position:0;background-repeat:no-repeat;background-size:20px}.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)}/*$vite$:1*/`)),document.head.appendChild(e)}}catch(e){console.error(`vite-plugin-css-injected-by-js`,e)}})();
|
|
9
|
+
var ContextMenu=(function(e,t){var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},u=(e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e));e=u(e,1),t=u(t,1);var d=c(((e,t)=>{function n(){}n.prototype={on:function(e,t,n){var r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:n}),this},once:function(e,t,n){var r=this;function i(){r.off(e,i),t.apply(n,arguments)}return i._=t,this.on(e,i,n)},emit:function(e){for(var t=[].slice.call(arguments,1),n=((this.e||(this.e={}))[e]||[]).slice(),r=0,i=n.length;r<i;r++)n[r].fn.apply(n[r].ctx,t);return this},off:function(e,t){var n=this.e||(this.e={}),r=n[e],i=[];if(r&&t)for(var a=0,o=r.length;a<o;a++)r[a].fn!==t&&r[a].fn._!==t&&i.push(r[a]);return i.length?n[e]=i:delete n[e],this}},t.exports=n,t.exports.TinyEmitter=n}))(),f=function(e){return e.CONTEXTMENU=`contextmenu`,e.CLICK=`click`,e.DBLCLICK=`dblclick`,e}({}),p=function(e){return e.BEFOREOPEN=`beforeopen`,e.OPEN=`open`,e.CLOSE=`close`,e.ADD_MENU_ENTRY=`add-menu-entry`,e}({}),m=class extends t.default{constructor(e){super(e.type,e.map,e.originalEvent)}},h={defaultItems:!0,eventType:f.CONTEXTMENU,items:[],scrollAt:4,width:150},g=`ol-ctx-menu`,_={container:`${g}-container`,hidden:`${g}-hidden`,icon:`${g}-icon`,namespace:g,separator:`${g}-separator`,submenu:`${g}-submenu`,unselectable:`ol-unselectable`,zoomIn:`${g}-zoom-in`,zoomOut:`${g}-zoom-out`},v=[{callback:(e,t)=>{let n=t.getView();n.animate({center:e.coordinate,duration:700,zoom:Number(n.getZoom())+1})},classname:`${_.zoomIn} ${_.icon}`,text:`Zoom In`},{callback:(e,t)=>{let n=t.getView();n.animate({center:e.coordinate,duration:700,zoom:Number(n.getZoom())-1})},classname:`${_.zoomOut} ${_.icon}`,text:`Zoom Out`}];function y(e){let t=document.createDocumentFragment(),n=document.createElement(`div`);for(n.innerHTML=e;n.firstChild;)t.append(n.firstChild);return t}function b(e){let t=document.importNode(e),n=e.offsetWidth;t.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${n}px`;let r=y(`<span>Foo</span>`),i=y(`<span>Foo</span>`),a=document.createElement(`li`),o=document.createElement(`li`);a.append(r),o.append(i),t.append(a),t.append(o),e.parentNode?.append(t);let s=getComputedStyle(t),c=Number.parseInt(s.paddingTop,10),l=Number.parseInt(s.paddingBottom,10),u=(t.offsetHeight-(c+l))/2;return e.parentNode?.removeChild(t),u}function x({emitter:e,isInsideSubmenu:t=!1,isSubmenu:n=!1,item:r,parentNode:i}){let a=`_${Math.random().toString(36).slice(2,11)}`;if(typeof r!=`string`&&`text`in r){let o=y(`<span>${r.text}</span>`),s=document.createElement(`li`);r.classname=r.classname||``,r.icon&&(r.classname===``?r.classname=_.icon:r.classname.includes(_.icon)===!1&&(r.classname+=` ${_.icon}`),s.setAttribute(`style`,`background-image:url(${r.icon})`)),s.id=a,s.className=r.classname,s.append(o),i.append(s);let c={callback:`callback`in r?r.callback:null,data:`data`in r?r.data:null,id:a,isInsideSubmenu:t,isSeparator:!1,isSubmenu:n};return e.emit(p.ADD_MENU_ENTRY,c,s),s}let o=y(`<li id="${a}" class="${_.separator}"><hr></li>`);i.append(o);let s=i.lastChild,c={callback:null,data:null,id:a,isInsideSubmenu:!1,isSeparator:!0,isSubmenu:!1};return e.emit(p.ADD_MENU_ENTRY,c,s),s}function S({container:e,emitter:t,isInsideSubmenu:n,items:r,menuWidth:i}){r.forEach(r=>{if(typeof r!=`string`&&`items`in r&&Array.isArray(r.items)){let n=x({emitter:t,isSubmenu:!0,item:r,parentNode:e});n.classList.add(_.submenu);let a=document.createElement(`ul`);a.classList.add(_.container),a.style.width=`${i}px`,n.append(a),S({container:a,emitter:t,isInsideSubmenu:!0,items:r.items,menuWidth:i})}else x({emitter:t,isInsideSubmenu:n,isSubmenu:!1,item:r,parentNode:e})})}function C(e){"@babel/helpers - typeof";return C=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function D(e,t){if(!e)throw Error(t)}return class extends e.default{constructor(e={}){D(typeof e==`object`,"@param `opts` should be object type!");let t=document.createElement(`div`);super({element:t}),E(this,`map`,void 0),E(this,`emitter`,new d.TinyEmitter),E(this,`container`,void 0),E(this,`coordinate`,[]),E(this,`pixel`,[]),E(this,`contextMenuEventListener`,void 0),E(this,`entryCallbackEventListener`,void 0),E(this,`mapMoveListener`,void 0),E(this,`lineHeight`,0),E(this,`disabled`,void 0),E(this,`opened`,void 0),E(this,`items`,[]),E(this,`menuEntries`,new Map),E(this,`options`,void 0),this.options={...h,...e};let n=document.createElement(`ul`);t.append(n),t.style.width=`${this.options.width}px`,t.classList.add(_.container,_.unselectable,_.hidden),this.container=t,this.contextMenuEventListener=e=>{this.handleContextMenu(e)},this.entryCallbackEventListener=e=>{this.handleEntryCallback(e)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener(`beforeunload`,()=>{this.removeListeners()},{once:!0})}clear(){for(let 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 v}countItems(){return this.menuEntries.size}extend(e){D(Array.isArray(e),"@param `items` should be an Array."),S({container:this.container.firstElementChild,emitter:this.emitter,items:e,menuWidth:this.options.width})}closeMenu(){this.opened=!1,this.container.classList.add(_.hidden),this.dispatchEvent(p.CLOSE)}isOpen(){return this.opened}updatePosition(e){D(Array.isArray(e),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=e,this.positionContainer())}pop(){let e=Array.from(this.menuEntries.keys()).pop();e&&this.removeMenuEntry(e)}shift(){let e=Array.from(this.menuEntries.keys()).shift();e&&this.removeMenuEntry(e)}push(e){e&&this.extend([e])}setMap(e){if(super.setMap(e),e){this.map=e,e.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,{capture:!1}),e.on(`movestart`,()=>{this.handleMapMove()}),this.emitter.on(p.ADD_MENU_ENTRY,(e,t)=>{this.handleAddMenuEntry(e,t)},this),this.items=this.options.defaultItems?this.options.items.concat(v):this.options.items,S({container:this.container.firstElementChild,emitter:this.emitter,items:this.items,menuWidth:this.options.width});let t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:b(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.emitter.off(p.ADD_MENU_ENTRY)}removeMenuEntry(e){let t=document.getElementById(e);t?.remove(),t=null,this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent(new m({map:this.map,originalEvent:e,type:p.BEFOREOPEN})),!this.disabled&&(this.options.eventType===f.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)},0),e.target?.addEventListener(`pointerdown`,e=>{this.opened&&(e.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.opened=!0,this.positionContainer(),this.container.classList.remove(_.hidden),this.dispatchEvent(new m({map:this.map,originalEvent:e,type:p.OPEN}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1&&e.isSubmenu===!1&&e.isInsideSubmenu===!1).length}calculateMenuSize(){let e=this.getMenuEntriesLength(),t=Math.round(this.lineHeight*e)+16,n=this.container.offsetHeight,r=!this.container.classList.contains(_.hidden);return{h:n>0&&r?n:t,w:this.container.offsetWidth}}calculateVerticalPosition(e,t,n){let r;return t.h>=n.h?(r=this.pixel[1]-10,r+n.h>e[1]&&(r=Math.max(0,e[1]-n.h-2))):(r=this.pixel[1]-n.h,r<0&&(r=n.h<=e[1]?0:Math.max(0,e[1]-n.h)),r+n.h>e[1]&&(r=Math.max(0,e[1]-n.h-2))),Math.max(0,Math.min(r,e[1]-n.h-2))}adjustPositionAfterRender(e,t){if(this.container.classList.contains(_.hidden))return;let n=this.container.offsetHeight;n>0&&n!==t.h&&(Number.parseInt(this.container.style.top,10)||0)+n>e[1]&&(this.container.style.top=`${Math.max(0,e[1]-n-2)}px`)}positionContainer(){let e=this.map.getSize()||[0,0],t=[e[0]||0,e[1]||0],n={h:t[1]-this.pixel[1],w:t[0]-this.pixel[0]},r=this.calculateMenuSize(),i=n.w>=r.w?this.pixel[0]+5:this.pixel[0]-r.w;this.container.style.left=`${i}px`;let a=this.calculateVerticalPosition(t,n,r);this.container.style.top=`${a}px`,this.container.style.right=`auto`,this.container.style.bottom=`auto`,this.adjustPositionAfterRender(t,r),n.w-=r.w;let o=e=>Array.from(e.children).filter(e=>e.tagName===`LI`&&e.classList.contains(_.submenu)),s=0,c=(e,t)=>{s+=1,o(e).forEach(e=>{let i=t>=r.w?r.w-8:(r.w+8)*-1,a=e.querySelector(`ul.${_.container}`),l=Math.round(this.lineHeight*Array.from(a.children).filter(e=>e.tagName===`LI`).length);a.style.left=`${i}px`,a.style.right=`auto`,a.style.top=n.h>=l+r.h?`0`:`-${a.offsetHeight-25}px`,a.style.bottom=`auto`,a.style.zIndex=String(s),o(a).length>0&&c(a,t-r.w)})};c(this.container.firstElementChild,n.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();let t=e.currentTarget,n=this.menuEntries.get(t.id);if(!n)return;let r={coordinate:this.coordinate,data:n.data};this.closeMenu(),n.callback?.(r,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,{capture:!1})}}})(ol.control.Control,ol.MapBrowserEvent);
|
package/dist/ol-contextmenu.js
CHANGED
|
@@ -1,383 +1,356 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v6.0.
|
|
3
|
+
* ol-contextmenu - v6.0.1
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built: 2026-
|
|
5
|
+
* Built: 2026-06-17T21:57:20.658Z
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
(function(){
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
8
|
+
(function(){try{if(typeof document<`u`){var e=document.createElement(`style`);e.appendChild(document.createTextNode(`.ol-ctx-menu-container{color:#222;box-sizing:border-box;background:#fff;border-radius:5px;padding:8px;font-size:13px;position:absolute;box-shadow:3px 3px 5px #0003}.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{font:inherit;vertical-align:baseline;border:0;margin:0;padding:0;font-size:100%}.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{white-space:nowrap;padding:2px 5px;line-height:20px;position:relative}.ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover{cursor:pointer;color:#eee;background-color:#333}.ol-ctx-menu-container li.ol-ctx-menu-submenu .ol-ctx-menu-container{opacity:0;visibility:hidden;border:1px solid #eee;padding:8px;transition:visibility 0s linear .3s,opacity .3s;top:0}.ol-ctx-menu-container li.ol-ctx-menu-submenu:after{content:"";border-top:.3em solid #222;border-right:.3em solid #222;width:.6em;height:.6em;display:inline-block;position:absolute;top:7px;right:10px;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{background-image:linear-gradient(270deg,#0000,#000000bf,#0000);border:0;height:1px}.ol-ctx-menu-icon{text-indent:20px;background-position:0;background-repeat:no-repeat;background-size:20px}.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)}/*$vite$:1*/`)),document.head.appendChild(e)}}catch(e){console.error(`vite-plugin-css-injected-by-js`,e)}})();
|
|
9
|
+
import e from "ol/control/Control";
|
|
10
|
+
import t from "ol/MapBrowserEvent";
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/types.ts
|
|
13
|
+
var n = (/* @__PURE__ */ ((e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports))(((e, t) => {
|
|
14
|
+
function n() {}
|
|
15
|
+
n.prototype = {
|
|
16
|
+
on: function(e, t, n) {
|
|
17
|
+
var r = this.e || (this.e = {});
|
|
18
|
+
return (r[e] || (r[e] = [])).push({
|
|
19
|
+
fn: t,
|
|
20
|
+
ctx: n
|
|
21
|
+
}), this;
|
|
22
|
+
},
|
|
23
|
+
once: function(e, t, n) {
|
|
24
|
+
var r = this;
|
|
25
|
+
function i() {
|
|
26
|
+
r.off(e, i), t.apply(n, arguments);
|
|
27
|
+
}
|
|
28
|
+
return i._ = t, this.on(e, i, n);
|
|
29
|
+
},
|
|
30
|
+
emit: function(e) {
|
|
31
|
+
for (var t = [].slice.call(arguments, 1), n = ((this.e || (this.e = {}))[e] || []).slice(), r = 0, i = n.length; r < i; r++) n[r].fn.apply(n[r].ctx, t);
|
|
32
|
+
return this;
|
|
33
|
+
},
|
|
34
|
+
off: function(e, t) {
|
|
35
|
+
var n = this.e || (this.e = {}), r = n[e], i = [];
|
|
36
|
+
if (r && t) for (var a = 0, o = r.length; a < o; a++) r[a].fn !== t && r[a].fn._ !== t && i.push(r[a]);
|
|
37
|
+
return i.length ? n[e] = i : delete n[e], this;
|
|
38
|
+
}
|
|
39
|
+
}, t.exports = n, t.exports.TinyEmitter = n;
|
|
40
|
+
})))(), r = /* @__PURE__ */ function(e) {
|
|
41
|
+
return e.CONTEXTMENU = "contextmenu", e.CLICK = "click", e.DBLCLICK = "dblclick", e;
|
|
42
|
+
}({}), i = /* @__PURE__ */ function(e) {
|
|
43
|
+
return e.BEFOREOPEN = "beforeopen", e.OPEN = "open", e.CLOSE = "close", e.ADD_MENU_ENTRY = "add-menu-entry", e;
|
|
44
|
+
}({}), a = class extends t {
|
|
45
|
+
constructor(e) {
|
|
46
|
+
super(e.type, e.map, e.originalEvent);
|
|
47
|
+
}
|
|
48
|
+
}, o = {
|
|
49
|
+
defaultItems: !0,
|
|
50
|
+
eventType: r.CONTEXTMENU,
|
|
51
|
+
items: [],
|
|
52
|
+
scrollAt: 4,
|
|
53
|
+
width: 150
|
|
54
|
+
}, s = "ol-ctx-menu", c = {
|
|
55
|
+
container: `${s}-container`,
|
|
56
|
+
hidden: `${s}-hidden`,
|
|
57
|
+
icon: `${s}-icon`,
|
|
58
|
+
namespace: s,
|
|
59
|
+
separator: `${s}-separator`,
|
|
60
|
+
submenu: `${s}-submenu`,
|
|
61
|
+
unselectable: "ol-unselectable",
|
|
62
|
+
zoomIn: `${s}-zoom-in`,
|
|
63
|
+
zoomOut: `${s}-zoom-out`
|
|
64
|
+
}, l = [{
|
|
65
|
+
callback: (e, t) => {
|
|
66
|
+
let n = t.getView();
|
|
67
|
+
n.animate({
|
|
68
|
+
center: e.coordinate,
|
|
69
|
+
duration: 700,
|
|
70
|
+
zoom: Number(n.getZoom()) + 1
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
classname: `${c.zoomIn} ${c.icon}`,
|
|
74
|
+
text: "Zoom In"
|
|
75
|
+
}, {
|
|
76
|
+
callback: (e, t) => {
|
|
77
|
+
let n = t.getView();
|
|
78
|
+
n.animate({
|
|
79
|
+
center: e.coordinate,
|
|
80
|
+
duration: 700,
|
|
81
|
+
zoom: Number(n.getZoom()) - 1
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
classname: `${c.zoomOut} ${c.icon}`,
|
|
85
|
+
text: "Zoom Out"
|
|
86
|
+
}];
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/helpers/dom.ts
|
|
89
|
+
function u(e) {
|
|
90
|
+
let t = document.createDocumentFragment(), n = document.createElement("div");
|
|
91
|
+
for (n.innerHTML = e; n.firstChild;) t.append(n.firstChild);
|
|
92
|
+
return t;
|
|
49
93
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
94
|
+
function d(e) {
|
|
95
|
+
let t = document.importNode(e), n = e.offsetWidth;
|
|
96
|
+
t.style.cssText = `position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${n}px`;
|
|
97
|
+
let r = u("<span>Foo</span>"), i = u("<span>Foo</span>"), a = document.createElement("li"), o = document.createElement("li");
|
|
98
|
+
a.append(r), o.append(i), t.append(a), t.append(o), e.parentNode?.append(t);
|
|
99
|
+
let s = getComputedStyle(t), c = Number.parseInt(s.paddingTop, 10), l = Number.parseInt(s.paddingBottom, 10), d = (t.offsetHeight - (c + l)) / 2;
|
|
100
|
+
return e.parentNode?.removeChild(t), d;
|
|
55
101
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
text: "Zoom In"
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
callback: (o, i) => {
|
|
86
|
-
const t = i.getView();
|
|
87
|
-
t.animate({
|
|
88
|
-
center: o.coordinate,
|
|
89
|
-
duration: 700,
|
|
90
|
-
zoom: Number(t.getZoom()) - 1
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
classname: `${r.zoomOut} ${r.icon}`,
|
|
94
|
-
text: "Zoom Out"
|
|
95
|
-
}
|
|
96
|
-
];
|
|
97
|
-
function v(o) {
|
|
98
|
-
const i = document.createDocumentFragment(), t = document.createElement("div");
|
|
99
|
-
for (t.innerHTML = o; t.firstChild; )
|
|
100
|
-
i.append(t.firstChild);
|
|
101
|
-
return i;
|
|
102
|
+
function f({ emitter: e, isInsideSubmenu: t = !1, isSubmenu: n = !1, item: r, parentNode: a }) {
|
|
103
|
+
let o = `_${Math.random().toString(36).slice(2, 11)}`;
|
|
104
|
+
if (typeof r != "string" && "text" in r) {
|
|
105
|
+
let s = u(`<span>${r.text}</span>`), l = document.createElement("li");
|
|
106
|
+
r.classname = r.classname || "", r.icon && (r.classname === "" ? r.classname = c.icon : r.classname.includes(c.icon) === !1 && (r.classname += ` ${c.icon}`), l.setAttribute("style", `background-image:url(${r.icon})`)), l.id = o, l.className = r.classname, l.append(s), a.append(l);
|
|
107
|
+
let d = {
|
|
108
|
+
callback: "callback" in r ? r.callback : null,
|
|
109
|
+
data: "data" in r ? r.data : null,
|
|
110
|
+
id: o,
|
|
111
|
+
isInsideSubmenu: t,
|
|
112
|
+
isSeparator: !1,
|
|
113
|
+
isSubmenu: n
|
|
114
|
+
};
|
|
115
|
+
return e.emit(i.ADD_MENU_ENTRY, d, l), l;
|
|
116
|
+
}
|
|
117
|
+
let s = u(`<li id="${o}" class="${c.separator}"><hr></li>`);
|
|
118
|
+
a.append(s);
|
|
119
|
+
let l = a.lastChild, d = {
|
|
120
|
+
callback: null,
|
|
121
|
+
data: null,
|
|
122
|
+
id: o,
|
|
123
|
+
isInsideSubmenu: !1,
|
|
124
|
+
isSeparator: !0,
|
|
125
|
+
isSubmenu: !1
|
|
126
|
+
};
|
|
127
|
+
return e.emit(i.ADD_MENU_ENTRY, d, l), l;
|
|
102
128
|
}
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
129
|
+
function p({ container: e, emitter: t, isInsideSubmenu: n, items: r, menuWidth: i }) {
|
|
130
|
+
r.forEach((r) => {
|
|
131
|
+
if (typeof r != "string" && "items" in r && Array.isArray(r.items)) {
|
|
132
|
+
let n = f({
|
|
133
|
+
emitter: t,
|
|
134
|
+
isSubmenu: !0,
|
|
135
|
+
item: r,
|
|
136
|
+
parentNode: e
|
|
137
|
+
});
|
|
138
|
+
n.classList.add(c.submenu);
|
|
139
|
+
let a = document.createElement("ul");
|
|
140
|
+
a.classList.add(c.container), a.style.width = `${i}px`, n.append(a), p({
|
|
141
|
+
container: a,
|
|
142
|
+
emitter: t,
|
|
143
|
+
isInsideSubmenu: !0,
|
|
144
|
+
items: r.items,
|
|
145
|
+
menuWidth: i
|
|
146
|
+
});
|
|
147
|
+
} else f({
|
|
148
|
+
emitter: t,
|
|
149
|
+
isInsideSubmenu: n,
|
|
150
|
+
isSubmenu: !1,
|
|
151
|
+
item: r,
|
|
152
|
+
parentNode: e
|
|
153
|
+
});
|
|
154
|
+
});
|
|
110
155
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const g = `<span>${e.text}</span>`, f = v(g), l = document.createElement("li");
|
|
121
|
-
e.classname = e.classname || "", e.icon && (e.classname === "" ? e.classname = r.icon : e.classname.includes(r.icon) === !1 && (e.classname += ` ${r.icon}`), l.setAttribute("style", `background-image:url(${e.icon})`)), l.id = n, l.className = e.classname, l.append(f), s.append(l);
|
|
122
|
-
const N = {
|
|
123
|
-
callback: "callback" in e ? e.callback : null,
|
|
124
|
-
data: "data" in e ? e.data : null,
|
|
125
|
-
id: n,
|
|
126
|
-
isInsideSubmenu: i,
|
|
127
|
-
isSeparator: !1,
|
|
128
|
-
isSubmenu: t
|
|
129
|
-
};
|
|
130
|
-
return o.emit(d.ADD_MENU_ENTRY, N, l), l;
|
|
131
|
-
}
|
|
132
|
-
const a = `<li id="${n}" class="${r.separator}"><hr></li>`, h = v(a);
|
|
133
|
-
s.append(h);
|
|
134
|
-
const m = s.lastChild, E = {
|
|
135
|
-
callback: null,
|
|
136
|
-
data: null,
|
|
137
|
-
id: n,
|
|
138
|
-
isInsideSubmenu: !1,
|
|
139
|
-
isSeparator: !0,
|
|
140
|
-
isSubmenu: !1
|
|
141
|
-
};
|
|
142
|
-
return o.emit(d.ADD_MENU_ENTRY, E, m), m;
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
158
|
+
function m(e) {
|
|
159
|
+
"@babel/helpers - typeof";
|
|
160
|
+
return m = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
161
|
+
return typeof e;
|
|
162
|
+
} : function(e) {
|
|
163
|
+
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
164
|
+
}, m(e);
|
|
143
165
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const h = document.createElement("ul");
|
|
156
|
-
h.classList.add(r.container), h.style.width = `${s}px`, a.append(h), x({
|
|
157
|
-
container: h,
|
|
158
|
-
emitter: i,
|
|
159
|
-
isInsideSubmenu: !0,
|
|
160
|
-
items: n.items,
|
|
161
|
-
menuWidth: s
|
|
162
|
-
});
|
|
163
|
-
} else
|
|
164
|
-
T({
|
|
165
|
-
emitter: i,
|
|
166
|
-
isInsideSubmenu: t,
|
|
167
|
-
isSubmenu: !1,
|
|
168
|
-
item: n,
|
|
169
|
-
parentNode: o
|
|
170
|
-
});
|
|
171
|
-
});
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
168
|
+
function h(e, t) {
|
|
169
|
+
if (m(e) != "object" || !e) return e;
|
|
170
|
+
var n = e[Symbol.toPrimitive];
|
|
171
|
+
if (n !== void 0) {
|
|
172
|
+
var r = n.call(e, t || "default");
|
|
173
|
+
if (m(r) != "object") return r;
|
|
174
|
+
throw TypeError("@@toPrimitive must return a primitive value.");
|
|
175
|
+
}
|
|
176
|
+
return (t === "string" ? String : Number)(e);
|
|
172
177
|
}
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
180
|
+
function g(e) {
|
|
181
|
+
var t = h(e, "string");
|
|
182
|
+
return m(t) == "symbol" ? t : t + "";
|
|
175
183
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
c(this, "pixel", []);
|
|
186
|
-
c(this, "contextMenuEventListener");
|
|
187
|
-
c(this, "entryCallbackEventListener");
|
|
188
|
-
c(this, "mapMoveListener");
|
|
189
|
-
c(this, "lineHeight", 0);
|
|
190
|
-
c(this, "disabled");
|
|
191
|
-
c(this, "opened");
|
|
192
|
-
c(this, "items", []);
|
|
193
|
-
c(this, "menuEntries", /* @__PURE__ */ new Map());
|
|
194
|
-
c(this, "options");
|
|
195
|
-
this.options = { ...U, ...t };
|
|
196
|
-
const s = document.createElement("ul");
|
|
197
|
-
e.append(s), e.style.width = `${this.options.width}px`, e.classList.add(
|
|
198
|
-
r.container,
|
|
199
|
-
r.unselectable,
|
|
200
|
-
r.hidden
|
|
201
|
-
), this.container = e, this.contextMenuEventListener = (n) => {
|
|
202
|
-
this.handleContextMenu(n);
|
|
203
|
-
}, this.entryCallbackEventListener = (n) => {
|
|
204
|
-
this.handleEntryCallback(n);
|
|
205
|
-
}, this.mapMoveListener = () => {
|
|
206
|
-
this.handleMapMove();
|
|
207
|
-
}, this.disabled = !1, this.opened = !1, window.addEventListener(
|
|
208
|
-
"beforeunload",
|
|
209
|
-
() => {
|
|
210
|
-
this.removeListeners();
|
|
211
|
-
},
|
|
212
|
-
{ once: !0 }
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
clear() {
|
|
216
|
-
for (const t of this.menuEntries.keys())
|
|
217
|
-
this.removeMenuEntry(t);
|
|
218
|
-
this.container.replaceChildren(), this.container.append(document.createElement("ul"));
|
|
219
|
-
}
|
|
220
|
-
enable() {
|
|
221
|
-
this.disabled = !1;
|
|
222
|
-
}
|
|
223
|
-
disable() {
|
|
224
|
-
this.disabled = !0;
|
|
225
|
-
}
|
|
226
|
-
getDefaultItems() {
|
|
227
|
-
return C;
|
|
228
|
-
}
|
|
229
|
-
countItems() {
|
|
230
|
-
return this.menuEntries.size;
|
|
231
|
-
}
|
|
232
|
-
extend(t) {
|
|
233
|
-
b(Array.isArray(t), "@param `items` should be an Array."), x({
|
|
234
|
-
container: this.container.firstElementChild,
|
|
235
|
-
emitter: this.emitter,
|
|
236
|
-
items: t,
|
|
237
|
-
menuWidth: this.options.width
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
closeMenu() {
|
|
241
|
-
this.opened = !1, this.container.classList.add(r.hidden), this.dispatchEvent(d.CLOSE);
|
|
242
|
-
}
|
|
243
|
-
isOpen() {
|
|
244
|
-
return this.opened;
|
|
245
|
-
}
|
|
246
|
-
updatePosition(t) {
|
|
247
|
-
b(Array.isArray(t), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = t, this.positionContainer());
|
|
248
|
-
}
|
|
249
|
-
pop() {
|
|
250
|
-
const t = Array.from(this.menuEntries.keys()).pop();
|
|
251
|
-
t && this.removeMenuEntry(t);
|
|
252
|
-
}
|
|
253
|
-
shift() {
|
|
254
|
-
const t = Array.from(this.menuEntries.keys()).shift();
|
|
255
|
-
t && this.removeMenuEntry(t);
|
|
256
|
-
}
|
|
257
|
-
push(t) {
|
|
258
|
-
t && this.extend([t]);
|
|
259
|
-
}
|
|
260
|
-
setMap(t) {
|
|
261
|
-
if (super.setMap(t), t) {
|
|
262
|
-
this.map = t, t.getViewport().addEventListener(
|
|
263
|
-
this.options.eventType,
|
|
264
|
-
this.contextMenuEventListener,
|
|
265
|
-
!1
|
|
266
|
-
), t.on("movestart", () => {
|
|
267
|
-
this.handleMapMove();
|
|
268
|
-
}), this.emitter.on(
|
|
269
|
-
d.ADD_MENU_ENTRY,
|
|
270
|
-
(s, n) => {
|
|
271
|
-
this.handleAddMenuEntry(s, n);
|
|
272
|
-
},
|
|
273
|
-
this
|
|
274
|
-
), this.items = this.options.defaultItems ? this.options.items.concat(C) : this.options.items, x({
|
|
275
|
-
container: this.container.firstElementChild,
|
|
276
|
-
emitter: this.emitter,
|
|
277
|
-
items: this.items,
|
|
278
|
-
menuWidth: this.options.width
|
|
279
|
-
});
|
|
280
|
-
const e = this.getMenuEntriesLength();
|
|
281
|
-
this.lineHeight = e > 0 ? this.container.offsetHeight / e : j(this.container);
|
|
282
|
-
} else
|
|
283
|
-
this.removeListeners(), this.clear();
|
|
284
|
-
}
|
|
285
|
-
removeListeners() {
|
|
286
|
-
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.emitter.off(d.ADD_MENU_ENTRY);
|
|
287
|
-
}
|
|
288
|
-
removeMenuEntry(t) {
|
|
289
|
-
let e = document.getElementById(t);
|
|
290
|
-
e?.remove(), e = null, this.menuEntries.delete(t);
|
|
291
|
-
}
|
|
292
|
-
handleContextMenu(t) {
|
|
293
|
-
this.coordinate = this.map.getEventCoordinate(t), this.pixel = this.map.getEventPixel(t), this.dispatchEvent(
|
|
294
|
-
new A({
|
|
295
|
-
map: this.map,
|
|
296
|
-
originalEvent: t,
|
|
297
|
-
type: d.BEFOREOPEN
|
|
298
|
-
})
|
|
299
|
-
), !this.disabled && (this.options.eventType === L.CONTEXTMENU && (t.stopPropagation(), t.preventDefault()), setTimeout(() => {
|
|
300
|
-
this.openMenu(t);
|
|
301
|
-
}), t.target?.addEventListener(
|
|
302
|
-
"pointerdown",
|
|
303
|
-
(e) => {
|
|
304
|
-
this.opened && (e.stopPropagation(), this.closeMenu());
|
|
305
|
-
},
|
|
306
|
-
{ once: !0 }
|
|
307
|
-
));
|
|
308
|
-
}
|
|
309
|
-
openMenu(t) {
|
|
310
|
-
this.opened = !0, this.positionContainer(), this.container.classList.remove(r.hidden), this.dispatchEvent(
|
|
311
|
-
new A({
|
|
312
|
-
map: this.map,
|
|
313
|
-
originalEvent: t,
|
|
314
|
-
type: d.OPEN
|
|
315
|
-
})
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
getMenuEntriesLength() {
|
|
319
|
-
return Array.from(this.menuEntries).filter(
|
|
320
|
-
([, t]) => t.isSeparator === !1 && t.isSubmenu === !1 && t.isInsideSubmenu === !1
|
|
321
|
-
).length;
|
|
322
|
-
}
|
|
323
|
-
calculateMenuSize() {
|
|
324
|
-
const t = this.getMenuEntriesLength(), s = Math.round(this.lineHeight * t) + V, n = this.container.offsetHeight, a = !this.container.classList.contains(r.hidden);
|
|
325
|
-
return {
|
|
326
|
-
h: n > 0 && a ? n : s,
|
|
327
|
-
w: this.container.offsetWidth
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
calculateVerticalPosition(t, e, s) {
|
|
331
|
-
let n;
|
|
332
|
-
return e.h >= s.h ? (n = this.pixel[1] - B, n + s.h > t[1] && (n = Math.max(0, t[1] - s.h - M))) : (n = this.pixel[1] - s.h, n < 0 && (n = s.h <= t[1] ? 0 : Math.max(0, t[1] - s.h)), n + s.h > t[1] && (n = Math.max(0, t[1] - s.h - M))), Math.max(0, Math.min(n, t[1] - s.h - M));
|
|
333
|
-
}
|
|
334
|
-
adjustPositionAfterRender(t, e) {
|
|
335
|
-
if (!this.container.classList.contains(r.hidden)) {
|
|
336
|
-
const s = this.container.offsetHeight;
|
|
337
|
-
s > 0 && s !== e.h && (Number.parseInt(this.container.style.top, 10) || 0) + s > t[1] && (this.container.style.top = `${Math.max(0, t[1] - s - M)}px`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
positionContainer() {
|
|
341
|
-
const t = this.map.getSize() || [0, 0], e = [t[0] || 0, t[1] || 0], s = {
|
|
342
|
-
h: e[1] - this.pixel[1],
|
|
343
|
-
w: e[0] - this.pixel[0]
|
|
344
|
-
}, n = this.calculateMenuSize(), a = s.w >= n.w ? this.pixel[0] + 5 : this.pixel[0] - n.w;
|
|
345
|
-
this.container.style.left = `${a}px`;
|
|
346
|
-
const h = this.calculateVerticalPosition(e, s, n);
|
|
347
|
-
this.container.style.top = `${h}px`, this.container.style.right = "auto", this.container.style.bottom = "auto", this.adjustPositionAfterRender(e, n), s.w -= n.w;
|
|
348
|
-
const m = (f) => Array.from(f.children).filter(
|
|
349
|
-
(l) => l.tagName === "LI" && l.classList.contains(r.submenu)
|
|
350
|
-
);
|
|
351
|
-
let E = 0;
|
|
352
|
-
const g = (f, l) => {
|
|
353
|
-
E += 1, m(f).forEach((I) => {
|
|
354
|
-
const O = l >= n.w ? n.w - 8 : (n.w + 8) * -1, u = I.querySelector(
|
|
355
|
-
`ul.${r.container}`
|
|
356
|
-
), $ = Math.round(
|
|
357
|
-
this.lineHeight * Array.from(u.children).filter((_) => _.tagName === "LI").length
|
|
358
|
-
);
|
|
359
|
-
u.style.left = `${O}px`, u.style.right = "auto", u.style.top = s.h >= $ + n.h ? "0" : `-${u.offsetHeight - 25}px`, u.style.bottom = "auto", u.style.zIndex = String(E), m(u).length > 0 && g(u, l - n.w);
|
|
360
|
-
});
|
|
361
|
-
};
|
|
362
|
-
g(this.container.firstElementChild, s.w);
|
|
363
|
-
}
|
|
364
|
-
handleMapMove() {
|
|
365
|
-
this.closeMenu();
|
|
366
|
-
}
|
|
367
|
-
handleEntryCallback(t) {
|
|
368
|
-
t.preventDefault(), t.stopPropagation();
|
|
369
|
-
const e = t.currentTarget, s = this.menuEntries.get(e.id);
|
|
370
|
-
if (!s) return;
|
|
371
|
-
const n = {
|
|
372
|
-
coordinate: this.coordinate,
|
|
373
|
-
data: s.data
|
|
374
|
-
};
|
|
375
|
-
this.closeMenu(), s.callback?.(n, this.map);
|
|
376
|
-
}
|
|
377
|
-
handleAddMenuEntry(t, e) {
|
|
378
|
-
this.menuEntries.set(t.id, t), this.positionContainer(), "callback" in t && typeof t.callback == "function" && e.addEventListener("click", this.entryCallbackEventListener, !1);
|
|
379
|
-
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
186
|
+
function _(e, t, n) {
|
|
187
|
+
return (t = g(t)) in e ? Object.defineProperty(e, t, {
|
|
188
|
+
value: n,
|
|
189
|
+
enumerable: !0,
|
|
190
|
+
configurable: !0,
|
|
191
|
+
writable: !0
|
|
192
|
+
}) : e[t] = n, e;
|
|
380
193
|
}
|
|
381
|
-
|
|
382
|
-
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/main.ts
|
|
196
|
+
function v(e, t) {
|
|
197
|
+
if (!e) throw Error(t);
|
|
198
|
+
}
|
|
199
|
+
var y = class extends e {
|
|
200
|
+
constructor(e = {}) {
|
|
201
|
+
v(typeof e == "object", "@param `opts` should be object type!");
|
|
202
|
+
let t = document.createElement("div");
|
|
203
|
+
super({ element: t }), _(this, "map", void 0), _(this, "emitter", new n.TinyEmitter()), _(this, "container", void 0), _(this, "coordinate", []), _(this, "pixel", []), _(this, "contextMenuEventListener", void 0), _(this, "entryCallbackEventListener", void 0), _(this, "mapMoveListener", void 0), _(this, "lineHeight", 0), _(this, "disabled", void 0), _(this, "opened", void 0), _(this, "items", []), _(this, "menuEntries", /* @__PURE__ */ new Map()), _(this, "options", void 0), this.options = {
|
|
204
|
+
...o,
|
|
205
|
+
...e
|
|
206
|
+
};
|
|
207
|
+
let r = document.createElement("ul");
|
|
208
|
+
t.append(r), t.style.width = `${this.options.width}px`, t.classList.add(c.container, c.unselectable, c.hidden), this.container = t, this.contextMenuEventListener = (e) => {
|
|
209
|
+
this.handleContextMenu(e);
|
|
210
|
+
}, this.entryCallbackEventListener = (e) => {
|
|
211
|
+
this.handleEntryCallback(e);
|
|
212
|
+
}, this.mapMoveListener = () => {
|
|
213
|
+
this.handleMapMove();
|
|
214
|
+
}, this.disabled = !1, this.opened = !1, window.addEventListener("beforeunload", () => {
|
|
215
|
+
this.removeListeners();
|
|
216
|
+
}, { once: !0 });
|
|
217
|
+
}
|
|
218
|
+
clear() {
|
|
219
|
+
for (let e of this.menuEntries.keys()) this.removeMenuEntry(e);
|
|
220
|
+
this.container.replaceChildren(), this.container.append(document.createElement("ul"));
|
|
221
|
+
}
|
|
222
|
+
enable() {
|
|
223
|
+
this.disabled = !1;
|
|
224
|
+
}
|
|
225
|
+
disable() {
|
|
226
|
+
this.disabled = !0;
|
|
227
|
+
}
|
|
228
|
+
getDefaultItems() {
|
|
229
|
+
return l;
|
|
230
|
+
}
|
|
231
|
+
countItems() {
|
|
232
|
+
return this.menuEntries.size;
|
|
233
|
+
}
|
|
234
|
+
extend(e) {
|
|
235
|
+
v(Array.isArray(e), "@param `items` should be an Array."), p({
|
|
236
|
+
container: this.container.firstElementChild,
|
|
237
|
+
emitter: this.emitter,
|
|
238
|
+
items: e,
|
|
239
|
+
menuWidth: this.options.width
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
closeMenu() {
|
|
243
|
+
this.opened = !1, this.container.classList.add(c.hidden), this.dispatchEvent(i.CLOSE);
|
|
244
|
+
}
|
|
245
|
+
isOpen() {
|
|
246
|
+
return this.opened;
|
|
247
|
+
}
|
|
248
|
+
updatePosition(e) {
|
|
249
|
+
v(Array.isArray(e), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = e, this.positionContainer());
|
|
250
|
+
}
|
|
251
|
+
pop() {
|
|
252
|
+
let e = Array.from(this.menuEntries.keys()).pop();
|
|
253
|
+
e && this.removeMenuEntry(e);
|
|
254
|
+
}
|
|
255
|
+
shift() {
|
|
256
|
+
let e = Array.from(this.menuEntries.keys()).shift();
|
|
257
|
+
e && this.removeMenuEntry(e);
|
|
258
|
+
}
|
|
259
|
+
push(e) {
|
|
260
|
+
e && this.extend([e]);
|
|
261
|
+
}
|
|
262
|
+
setMap(e) {
|
|
263
|
+
if (super.setMap(e), e) {
|
|
264
|
+
this.map = e, e.getViewport().addEventListener(this.options.eventType, this.contextMenuEventListener, { capture: !1 }), e.on("movestart", () => {
|
|
265
|
+
this.handleMapMove();
|
|
266
|
+
}), this.emitter.on(i.ADD_MENU_ENTRY, (e, t) => {
|
|
267
|
+
this.handleAddMenuEntry(e, t);
|
|
268
|
+
}, this), this.items = this.options.defaultItems ? this.options.items.concat(l) : this.options.items, p({
|
|
269
|
+
container: this.container.firstElementChild,
|
|
270
|
+
emitter: this.emitter,
|
|
271
|
+
items: this.items,
|
|
272
|
+
menuWidth: this.options.width
|
|
273
|
+
});
|
|
274
|
+
let t = this.getMenuEntriesLength();
|
|
275
|
+
this.lineHeight = t > 0 ? this.container.offsetHeight / t : d(this.container);
|
|
276
|
+
} else this.removeListeners(), this.clear();
|
|
277
|
+
}
|
|
278
|
+
removeListeners() {
|
|
279
|
+
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.emitter.off(i.ADD_MENU_ENTRY);
|
|
280
|
+
}
|
|
281
|
+
removeMenuEntry(e) {
|
|
282
|
+
let t = document.getElementById(e);
|
|
283
|
+
t?.remove(), t = null, this.menuEntries.delete(e);
|
|
284
|
+
}
|
|
285
|
+
handleContextMenu(e) {
|
|
286
|
+
this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent(new a({
|
|
287
|
+
map: this.map,
|
|
288
|
+
originalEvent: e,
|
|
289
|
+
type: i.BEFOREOPEN
|
|
290
|
+
})), !this.disabled && (this.options.eventType === r.CONTEXTMENU && (e.stopPropagation(), e.preventDefault()), setTimeout(() => {
|
|
291
|
+
this.openMenu(e);
|
|
292
|
+
}, 0), e.target?.addEventListener("pointerdown", (e) => {
|
|
293
|
+
this.opened && (e.stopPropagation(), this.closeMenu());
|
|
294
|
+
}, { once: !0 }));
|
|
295
|
+
}
|
|
296
|
+
openMenu(e) {
|
|
297
|
+
this.opened = !0, this.positionContainer(), this.container.classList.remove(c.hidden), this.dispatchEvent(new a({
|
|
298
|
+
map: this.map,
|
|
299
|
+
originalEvent: e,
|
|
300
|
+
type: i.OPEN
|
|
301
|
+
}));
|
|
302
|
+
}
|
|
303
|
+
getMenuEntriesLength() {
|
|
304
|
+
return Array.from(this.menuEntries).filter(([, e]) => e.isSeparator === !1 && e.isSubmenu === !1 && e.isInsideSubmenu === !1).length;
|
|
305
|
+
}
|
|
306
|
+
calculateMenuSize() {
|
|
307
|
+
let e = this.getMenuEntriesLength(), t = Math.round(this.lineHeight * e) + 16, n = this.container.offsetHeight, r = !this.container.classList.contains(c.hidden);
|
|
308
|
+
return {
|
|
309
|
+
h: n > 0 && r ? n : t,
|
|
310
|
+
w: this.container.offsetWidth
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
calculateVerticalPosition(e, t, n) {
|
|
314
|
+
let r;
|
|
315
|
+
return t.h >= n.h ? (r = this.pixel[1] - 10, r + n.h > e[1] && (r = Math.max(0, e[1] - n.h - 2))) : (r = this.pixel[1] - n.h, r < 0 && (r = n.h <= e[1] ? 0 : Math.max(0, e[1] - n.h)), r + n.h > e[1] && (r = Math.max(0, e[1] - n.h - 2))), Math.max(0, Math.min(r, e[1] - n.h - 2));
|
|
316
|
+
}
|
|
317
|
+
adjustPositionAfterRender(e, t) {
|
|
318
|
+
if (this.container.classList.contains(c.hidden)) return;
|
|
319
|
+
let n = this.container.offsetHeight;
|
|
320
|
+
n > 0 && n !== t.h && (Number.parseInt(this.container.style.top, 10) || 0) + n > e[1] && (this.container.style.top = `${Math.max(0, e[1] - n - 2)}px`);
|
|
321
|
+
}
|
|
322
|
+
positionContainer() {
|
|
323
|
+
let e = this.map.getSize() || [0, 0], t = [e[0] || 0, e[1] || 0], n = {
|
|
324
|
+
h: t[1] - this.pixel[1],
|
|
325
|
+
w: t[0] - this.pixel[0]
|
|
326
|
+
}, r = this.calculateMenuSize(), i = n.w >= r.w ? this.pixel[0] + 5 : this.pixel[0] - r.w;
|
|
327
|
+
this.container.style.left = `${i}px`;
|
|
328
|
+
let a = this.calculateVerticalPosition(t, n, r);
|
|
329
|
+
this.container.style.top = `${a}px`, this.container.style.right = "auto", this.container.style.bottom = "auto", this.adjustPositionAfterRender(t, r), n.w -= r.w;
|
|
330
|
+
let o = (e) => Array.from(e.children).filter((e) => e.tagName === "LI" && e.classList.contains(c.submenu)), s = 0, l = (e, t) => {
|
|
331
|
+
s += 1, o(e).forEach((e) => {
|
|
332
|
+
let i = t >= r.w ? r.w - 8 : (r.w + 8) * -1, a = e.querySelector(`ul.${c.container}`), u = Math.round(this.lineHeight * Array.from(a.children).filter((e) => e.tagName === "LI").length);
|
|
333
|
+
a.style.left = `${i}px`, a.style.right = "auto", a.style.top = n.h >= u + r.h ? "0" : `-${a.offsetHeight - 25}px`, a.style.bottom = "auto", a.style.zIndex = String(s), o(a).length > 0 && l(a, t - r.w);
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
l(this.container.firstElementChild, n.w);
|
|
337
|
+
}
|
|
338
|
+
handleMapMove() {
|
|
339
|
+
this.closeMenu();
|
|
340
|
+
}
|
|
341
|
+
handleEntryCallback(e) {
|
|
342
|
+
e.preventDefault(), e.stopPropagation();
|
|
343
|
+
let t = e.currentTarget, n = this.menuEntries.get(t.id);
|
|
344
|
+
if (!n) return;
|
|
345
|
+
let r = {
|
|
346
|
+
coordinate: this.coordinate,
|
|
347
|
+
data: n.data
|
|
348
|
+
};
|
|
349
|
+
this.closeMenu(), n.callback?.(r, this.map);
|
|
350
|
+
}
|
|
351
|
+
handleAddMenuEntry(e, t) {
|
|
352
|
+
this.menuEntries.set(e.id, e), this.positionContainer(), "callback" in e && typeof e.callback == "function" && t.addEventListener("click", this.entryCallbackEventListener, { capture: !1 });
|
|
353
|
+
}
|
|
383
354
|
};
|
|
355
|
+
//#endregion
|
|
356
|
+
export { y as default };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu - v6.0.
|
|
3
|
+
* ol-contextmenu - v6.0.1
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built: 2026-
|
|
5
|
+
* Built: 2026-06-17T21:57:20.658Z
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
(function(){
|
|
9
|
-
(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 V=Object.defineProperty;var j=(c,h,p)=>h in c?V(c,h,{enumerable:!0,configurable:!0,writable:!0,value:p}):c[h]=p;var l=(c,h,p)=>j(c,typeof h!="symbol"?h+"":h,p);var p={exports:{}},C;function $(){if(C)return p.exports;C=1;function o(){}return o.prototype={on:function(i,t,e){var s=this.e||(this.e={});return(s[i]||(s[i]=[])).push({fn:t,ctx:e}),this},once:function(i,t,e){var s=this;function n(){s.off(i,n),t.apply(e,arguments)}return n._=t,this.on(i,n,e)},emit:function(i){var t=[].slice.call(arguments,1),e=((this.e||(this.e={}))[i]||[]).slice(),s=0,n=e.length;for(s;s<n;s++)e[s].fn.apply(e[s].ctx,t);return this},off:function(i,t){var e=this.e||(this.e={}),s=e[i],n=[];if(s&&t)for(var a=0,d=s.length;a<d;a++)s[a].fn!==t&&s[a].fn._!==t&&n.push(s[a]);return n.length?e[i]=n:delete e[i],this}},p.exports=o,p.exports.TinyEmitter=o,p.exports}var _=$(),L=(o=>(o.CONTEXTMENU="contextmenu",o.CLICK="click",o.DBLCLICK="dblclick",o))(L||{}),m=(o=>(o.BEFOREOPEN="beforeopen",o.OPEN="open",o.CLOSE="close",o.ADD_MENU_ENTRY="add-menu-entry",o))(m||{});class A extends h{constructor(i){super(i.type,i.map,i.originalEvent)}}const D={defaultItems:!0,eventType:L.CONTEXTMENU,items:[],scrollAt:4,width:150},E="ol-ctx-menu",r={container:`${E}-container`,hidden:`${E}-hidden`,icon:`${E}-icon`,separator:`${E}-separator`,submenu:`${E}-submenu`,unselectable:"ol-unselectable",zoomIn:`${E}-zoom-in`,zoomOut:`${E}-zoom-out`},P=8*2,S=10,M=2,T=[{callback:(o,i)=>{const t=i.getView();t.animate({center:o.coordinate,duration:700,zoom:Number(t.getZoom())+1})},classname:`${r.zoomIn} ${r.icon}`,text:"Zoom In"},{callback:(o,i)=>{const t=i.getView();t.animate({center:o.coordinate,duration:700,zoom:Number(t.getZoom())-1})},classname:`${r.zoomOut} ${r.icon}`,text:"Zoom Out"}];function v(o){const i=document.createDocumentFragment(),t=document.createElement("div");for(t.innerHTML=o;t.firstChild;)i.append(t.firstChild);return i}function k(o){const i=document.importNode(o),t=o.offsetWidth;i.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${t}px`;const e=v("<span>Foo</span>"),s=v("<span>Foo</span>"),n=document.createElement("li"),a=document.createElement("li");n.append(e),a.append(s),i.append(n),i.append(a),o.parentNode?.append(i);const d=i.offsetHeight/2;return o.parentNode?.removeChild(i),d}function I({emitter:o,isInsideSubmenu:i=!1,isSubmenu:t=!1,item:e,parentNode:s}){const n=`_${Math.random().toString(36).slice(2,11)}`;if(typeof e!="string"&&"text"in e){const b=`<span>${e.text}</span>`,y=v(b),u=document.createElement("li");e.classname=e.classname||"",e.icon&&(e.classname===""?e.classname=r.icon:e.classname.includes(r.icon)===!1&&(e.classname+=` ${r.icon}`),u.setAttribute("style",`background-image:url(${e.icon})`)),u.id=n,u.className=e.classname,u.append(y),s.append(u);const O={callback:"callback"in e?e.callback:null,data:"data"in e?e.data:null,id:n,isInsideSubmenu:i,isSeparator:!1,isSubmenu:t};return o.emit(m.ADD_MENU_ENTRY,O,u),u}const a=`<li id="${n}" class="${r.separator}"><hr></li>`,d=v(a);s.append(d);const g=s.lastChild,x={callback:null,data:null,id:n,isInsideSubmenu:!1,isSeparator:!0,isSubmenu:!1};return o.emit(m.ADD_MENU_ENTRY,x,g),g}function N({container:o,emitter:i,isInsideSubmenu:t,items:e,menuWidth:s}){e.forEach(n=>{if(typeof n!="string"&&"items"in n&&Array.isArray(n.items)){const a=I({emitter:i,isSubmenu:!0,item:n,parentNode:o});a.classList.add(r.submenu);const d=document.createElement("ul");d.classList.add(r.container),d.style.width=`${s}px`,a.append(d),N({container:d,emitter:i,isInsideSubmenu:!0,items:n.items,menuWidth:s})}else I({emitter:i,isInsideSubmenu:t,isSubmenu:!1,item:n,parentNode:o})})}function w(o,i){if(!o)throw new Error(i)}class H extends c{constructor(t={}){w(typeof t=="object","@param `opts` should be object type!");const e=document.createElement("div");super({element:e});l(this,"map");l(this,"emitter",new _.TinyEmitter);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={...D,...t};const s=document.createElement("ul");e.append(s),e.style.width=`${this.options.width}px`,e.classList.add(r.container,r.unselectable,r.hidden),this.container=e,this.contextMenuEventListener=n=>{this.handleContextMenu(n)},this.entryCallbackEventListener=n=>{this.handleEntryCallback(n)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener("beforeunload",()=>{this.removeListeners()},{once:!0})}clear(){for(const t of this.menuEntries.keys())this.removeMenuEntry(t);this.container.replaceChildren(),this.container.append(document.createElement("ul"))}enable(){this.disabled=!1}disable(){this.disabled=!0}getDefaultItems(){return T}countItems(){return this.menuEntries.size}extend(t){w(Array.isArray(t),"@param `items` should be an Array."),N({container:this.container.firstElementChild,emitter:this.emitter,items:t,menuWidth:this.options.width})}closeMenu(){this.opened=!1,this.container.classList.add(r.hidden),this.dispatchEvent(m.CLOSE)}isOpen(){return this.opened}updatePosition(t){w(Array.isArray(t),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=t,this.positionContainer())}pop(){const t=Array.from(this.menuEntries.keys()).pop();t&&this.removeMenuEntry(t)}shift(){const t=Array.from(this.menuEntries.keys()).shift();t&&this.removeMenuEntry(t)}push(t){t&&this.extend([t])}setMap(t){if(super.setMap(t),t){this.map=t,t.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,!1),t.on("movestart",()=>{this.handleMapMove()}),this.emitter.on(m.ADD_MENU_ENTRY,(s,n)=>{this.handleAddMenuEntry(s,n)},this),this.items=this.options.defaultItems?this.options.items.concat(T):this.options.items,N({container:this.container.firstElementChild,emitter:this.emitter,items:this.items,menuWidth:this.options.width});const e=this.getMenuEntriesLength();this.lineHeight=e>0?this.container.offsetHeight/e:k(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.emitter.off(m.ADD_MENU_ENTRY)}removeMenuEntry(t){let e=document.getElementById(t);e?.remove(),e=null,this.menuEntries.delete(t)}handleContextMenu(t){this.coordinate=this.map.getEventCoordinate(t),this.pixel=this.map.getEventPixel(t),this.dispatchEvent(new A({map:this.map,originalEvent:t,type:m.BEFOREOPEN})),!this.disabled&&(this.options.eventType===L.CONTEXTMENU&&(t.stopPropagation(),t.preventDefault()),setTimeout(()=>{this.openMenu(t)}),t.target?.addEventListener("pointerdown",e=>{this.opened&&(e.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(t){this.opened=!0,this.positionContainer(),this.container.classList.remove(r.hidden),this.dispatchEvent(new A({map:this.map,originalEvent:t,type:m.OPEN}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,t])=>t.isSeparator===!1&&t.isSubmenu===!1&&t.isInsideSubmenu===!1).length}calculateMenuSize(){const t=this.getMenuEntriesLength(),s=Math.round(this.lineHeight*t)+P,n=this.container.offsetHeight,a=!this.container.classList.contains(r.hidden);return{h:n>0&&a?n:s,w:this.container.offsetWidth}}calculateVerticalPosition(t,e,s){let n;return e.h>=s.h?(n=this.pixel[1]-S,n+s.h>t[1]&&(n=Math.max(0,t[1]-s.h-M))):(n=this.pixel[1]-s.h,n<0&&(n=s.h<=t[1]?0:Math.max(0,t[1]-s.h)),n+s.h>t[1]&&(n=Math.max(0,t[1]-s.h-M))),Math.max(0,Math.min(n,t[1]-s.h-M))}adjustPositionAfterRender(t,e){if(!this.container.classList.contains(r.hidden)){const s=this.container.offsetHeight;s>0&&s!==e.h&&(Number.parseInt(this.container.style.top,10)||0)+s>t[1]&&(this.container.style.top=`${Math.max(0,t[1]-s-M)}px`)}}positionContainer(){const t=this.map.getSize()||[0,0],e=[t[0]||0,t[1]||0],s={h:e[1]-this.pixel[1],w:e[0]-this.pixel[0]},n=this.calculateMenuSize(),a=s.w>=n.w?this.pixel[0]+5:this.pixel[0]-n.w;this.container.style.left=`${a}px`;const d=this.calculateVerticalPosition(e,s,n);this.container.style.top=`${d}px`,this.container.style.right="auto",this.container.style.bottom="auto",this.adjustPositionAfterRender(e,n),s.w-=n.w;const g=y=>Array.from(y.children).filter(u=>u.tagName==="LI"&&u.classList.contains(r.submenu));let x=0;const b=(y,u)=>{x+=1,g(y).forEach(R=>{const U=u>=n.w?n.w-8:(n.w+8)*-1,f=R.querySelector(`ul.${r.container}`),F=Math.round(this.lineHeight*Array.from(f.children).filter(B=>B.tagName==="LI").length);f.style.left=`${U}px`,f.style.right="auto",f.style.top=s.h>=F+n.h?"0":`-${f.offsetHeight-25}px`,f.style.bottom="auto",f.style.zIndex=String(x),g(f).length>0&&b(f,u-n.w)})};b(this.container.firstElementChild,s.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(t){t.preventDefault(),t.stopPropagation();const e=t.currentTarget,s=this.menuEntries.get(e.id);if(!s)return;const n={coordinate:this.coordinate,data:s.data};this.closeMenu(),s.callback?.(n,this.map)}handleAddMenuEntry(t,e){this.menuEntries.set(t.id,t),this.positionContainer(),"callback"in t&&typeof t.callback=="function"&&e.addEventListener("click",this.entryCallbackEventListener,!1)}}return H}));
|
|
8
|
+
(function(){try{if(typeof document<`u`){var e=document.createElement(`style`);e.appendChild(document.createTextNode(`.ol-ctx-menu-container{color:#222;box-sizing:border-box;background:#fff;border-radius:5px;padding:8px;font-size:13px;position:absolute;box-shadow:3px 3px 5px #0003}.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{font:inherit;vertical-align:baseline;border:0;margin:0;padding:0;font-size:100%}.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{white-space:nowrap;padding:2px 5px;line-height:20px;position:relative}.ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover{cursor:pointer;color:#eee;background-color:#333}.ol-ctx-menu-container li.ol-ctx-menu-submenu .ol-ctx-menu-container{opacity:0;visibility:hidden;border:1px solid #eee;padding:8px;transition:visibility 0s linear .3s,opacity .3s;top:0}.ol-ctx-menu-container li.ol-ctx-menu-submenu:after{content:"";border-top:.3em solid #222;border-right:.3em solid #222;width:.6em;height:.6em;display:inline-block;position:absolute;top:7px;right:10px;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{background-image:linear-gradient(270deg,#0000,#000000bf,#0000);border:0;height:1px}.ol-ctx-menu-icon{text-indent:20px;background-position:0;background-repeat:no-repeat;background-size:20px}.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)}/*$vite$:1*/`)),document.head.appendChild(e)}}catch(e){console.error(`vite-plugin-css-injected-by-js`,e)}})();
|
|
9
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t(require("ol/control/Control"),require("ol/MapBrowserEvent")):typeof define==`function`&&define.amd?define([`ol/control/Control`,`ol/MapBrowserEvent`],t):(e=typeof globalThis<`u`?globalThis:e||self,e.ContextMenu=t(e.ol.control.Control,e.ol.MapBrowserEvent))})(this,function(e,t){var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},u=(e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e));e=u(e,1),t=u(t,1);var d=c(((e,t)=>{function n(){}n.prototype={on:function(e,t,n){var r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:n}),this},once:function(e,t,n){var r=this;function i(){r.off(e,i),t.apply(n,arguments)}return i._=t,this.on(e,i,n)},emit:function(e){for(var t=[].slice.call(arguments,1),n=((this.e||(this.e={}))[e]||[]).slice(),r=0,i=n.length;r<i;r++)n[r].fn.apply(n[r].ctx,t);return this},off:function(e,t){var n=this.e||(this.e={}),r=n[e],i=[];if(r&&t)for(var a=0,o=r.length;a<o;a++)r[a].fn!==t&&r[a].fn._!==t&&i.push(r[a]);return i.length?n[e]=i:delete n[e],this}},t.exports=n,t.exports.TinyEmitter=n}))(),f=function(e){return e.CONTEXTMENU=`contextmenu`,e.CLICK=`click`,e.DBLCLICK=`dblclick`,e}({}),p=function(e){return e.BEFOREOPEN=`beforeopen`,e.OPEN=`open`,e.CLOSE=`close`,e.ADD_MENU_ENTRY=`add-menu-entry`,e}({}),m=class extends t.default{constructor(e){super(e.type,e.map,e.originalEvent)}},h={defaultItems:!0,eventType:f.CONTEXTMENU,items:[],scrollAt:4,width:150},g=`ol-ctx-menu`,_={container:`${g}-container`,hidden:`${g}-hidden`,icon:`${g}-icon`,namespace:g,separator:`${g}-separator`,submenu:`${g}-submenu`,unselectable:`ol-unselectable`,zoomIn:`${g}-zoom-in`,zoomOut:`${g}-zoom-out`},v=[{callback:(e,t)=>{let n=t.getView();n.animate({center:e.coordinate,duration:700,zoom:Number(n.getZoom())+1})},classname:`${_.zoomIn} ${_.icon}`,text:`Zoom In`},{callback:(e,t)=>{let n=t.getView();n.animate({center:e.coordinate,duration:700,zoom:Number(n.getZoom())-1})},classname:`${_.zoomOut} ${_.icon}`,text:`Zoom Out`}];function y(e){let t=document.createDocumentFragment(),n=document.createElement(`div`);for(n.innerHTML=e;n.firstChild;)t.append(n.firstChild);return t}function b(e){let t=document.importNode(e),n=e.offsetWidth;t.style.cssText=`position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${n}px`;let r=y(`<span>Foo</span>`),i=y(`<span>Foo</span>`),a=document.createElement(`li`),o=document.createElement(`li`);a.append(r),o.append(i),t.append(a),t.append(o),e.parentNode?.append(t);let s=getComputedStyle(t),c=Number.parseInt(s.paddingTop,10),l=Number.parseInt(s.paddingBottom,10),u=(t.offsetHeight-(c+l))/2;return e.parentNode?.removeChild(t),u}function x({emitter:e,isInsideSubmenu:t=!1,isSubmenu:n=!1,item:r,parentNode:i}){let a=`_${Math.random().toString(36).slice(2,11)}`;if(typeof r!=`string`&&`text`in r){let o=y(`<span>${r.text}</span>`),s=document.createElement(`li`);r.classname=r.classname||``,r.icon&&(r.classname===``?r.classname=_.icon:r.classname.includes(_.icon)===!1&&(r.classname+=` ${_.icon}`),s.setAttribute(`style`,`background-image:url(${r.icon})`)),s.id=a,s.className=r.classname,s.append(o),i.append(s);let c={callback:`callback`in r?r.callback:null,data:`data`in r?r.data:null,id:a,isInsideSubmenu:t,isSeparator:!1,isSubmenu:n};return e.emit(p.ADD_MENU_ENTRY,c,s),s}let o=y(`<li id="${a}" class="${_.separator}"><hr></li>`);i.append(o);let s=i.lastChild,c={callback:null,data:null,id:a,isInsideSubmenu:!1,isSeparator:!0,isSubmenu:!1};return e.emit(p.ADD_MENU_ENTRY,c,s),s}function S({container:e,emitter:t,isInsideSubmenu:n,items:r,menuWidth:i}){r.forEach(r=>{if(typeof r!=`string`&&`items`in r&&Array.isArray(r.items)){let n=x({emitter:t,isSubmenu:!0,item:r,parentNode:e});n.classList.add(_.submenu);let a=document.createElement(`ul`);a.classList.add(_.container),a.style.width=`${i}px`,n.append(a),S({container:a,emitter:t,isInsideSubmenu:!0,items:r.items,menuWidth:i})}else x({emitter:t,isInsideSubmenu:n,isSubmenu:!1,item:r,parentNode:e})})}function C(e){"@babel/helpers - typeof";return C=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},C(e)}function w(e,t){if(C(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(C(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function T(e){var t=w(e,`string`);return C(t)==`symbol`?t:t+``}function E(e,t,n){return(t=T(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function D(e,t){if(!e)throw Error(t)}return class extends e.default{constructor(e={}){D(typeof e==`object`,"@param `opts` should be object type!");let t=document.createElement(`div`);super({element:t}),E(this,`map`,void 0),E(this,`emitter`,new d.TinyEmitter),E(this,`container`,void 0),E(this,`coordinate`,[]),E(this,`pixel`,[]),E(this,`contextMenuEventListener`,void 0),E(this,`entryCallbackEventListener`,void 0),E(this,`mapMoveListener`,void 0),E(this,`lineHeight`,0),E(this,`disabled`,void 0),E(this,`opened`,void 0),E(this,`items`,[]),E(this,`menuEntries`,new Map),E(this,`options`,void 0),this.options={...h,...e};let n=document.createElement(`ul`);t.append(n),t.style.width=`${this.options.width}px`,t.classList.add(_.container,_.unselectable,_.hidden),this.container=t,this.contextMenuEventListener=e=>{this.handleContextMenu(e)},this.entryCallbackEventListener=e=>{this.handleEntryCallback(e)},this.mapMoveListener=()=>{this.handleMapMove()},this.disabled=!1,this.opened=!1,window.addEventListener(`beforeunload`,()=>{this.removeListeners()},{once:!0})}clear(){for(let 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 v}countItems(){return this.menuEntries.size}extend(e){D(Array.isArray(e),"@param `items` should be an Array."),S({container:this.container.firstElementChild,emitter:this.emitter,items:e,menuWidth:this.options.width})}closeMenu(){this.opened=!1,this.container.classList.add(_.hidden),this.dispatchEvent(p.CLOSE)}isOpen(){return this.opened}updatePosition(e){D(Array.isArray(e),"@param `pixel` should be an Array."),this.isOpen()&&(this.pixel=e,this.positionContainer())}pop(){let e=Array.from(this.menuEntries.keys()).pop();e&&this.removeMenuEntry(e)}shift(){let e=Array.from(this.menuEntries.keys()).shift();e&&this.removeMenuEntry(e)}push(e){e&&this.extend([e])}setMap(e){if(super.setMap(e),e){this.map=e,e.getViewport().addEventListener(this.options.eventType,this.contextMenuEventListener,{capture:!1}),e.on(`movestart`,()=>{this.handleMapMove()}),this.emitter.on(p.ADD_MENU_ENTRY,(e,t)=>{this.handleAddMenuEntry(e,t)},this),this.items=this.options.defaultItems?this.options.items.concat(v):this.options.items,S({container:this.container.firstElementChild,emitter:this.emitter,items:this.items,menuWidth:this.options.width});let t=this.getMenuEntriesLength();this.lineHeight=t>0?this.container.offsetHeight/t:b(this.container)}else this.removeListeners(),this.clear()}removeListeners(){this.map.getViewport().removeEventListener(this.options.eventType,this.contextMenuEventListener,!1),this.emitter.off(p.ADD_MENU_ENTRY)}removeMenuEntry(e){let t=document.getElementById(e);t?.remove(),t=null,this.menuEntries.delete(e)}handleContextMenu(e){this.coordinate=this.map.getEventCoordinate(e),this.pixel=this.map.getEventPixel(e),this.dispatchEvent(new m({map:this.map,originalEvent:e,type:p.BEFOREOPEN})),!this.disabled&&(this.options.eventType===f.CONTEXTMENU&&(e.stopPropagation(),e.preventDefault()),setTimeout(()=>{this.openMenu(e)},0),e.target?.addEventListener(`pointerdown`,e=>{this.opened&&(e.stopPropagation(),this.closeMenu())},{once:!0}))}openMenu(e){this.opened=!0,this.positionContainer(),this.container.classList.remove(_.hidden),this.dispatchEvent(new m({map:this.map,originalEvent:e,type:p.OPEN}))}getMenuEntriesLength(){return Array.from(this.menuEntries).filter(([,e])=>e.isSeparator===!1&&e.isSubmenu===!1&&e.isInsideSubmenu===!1).length}calculateMenuSize(){let e=this.getMenuEntriesLength(),t=Math.round(this.lineHeight*e)+16,n=this.container.offsetHeight,r=!this.container.classList.contains(_.hidden);return{h:n>0&&r?n:t,w:this.container.offsetWidth}}calculateVerticalPosition(e,t,n){let r;return t.h>=n.h?(r=this.pixel[1]-10,r+n.h>e[1]&&(r=Math.max(0,e[1]-n.h-2))):(r=this.pixel[1]-n.h,r<0&&(r=n.h<=e[1]?0:Math.max(0,e[1]-n.h)),r+n.h>e[1]&&(r=Math.max(0,e[1]-n.h-2))),Math.max(0,Math.min(r,e[1]-n.h-2))}adjustPositionAfterRender(e,t){if(this.container.classList.contains(_.hidden))return;let n=this.container.offsetHeight;n>0&&n!==t.h&&(Number.parseInt(this.container.style.top,10)||0)+n>e[1]&&(this.container.style.top=`${Math.max(0,e[1]-n-2)}px`)}positionContainer(){let e=this.map.getSize()||[0,0],t=[e[0]||0,e[1]||0],n={h:t[1]-this.pixel[1],w:t[0]-this.pixel[0]},r=this.calculateMenuSize(),i=n.w>=r.w?this.pixel[0]+5:this.pixel[0]-r.w;this.container.style.left=`${i}px`;let a=this.calculateVerticalPosition(t,n,r);this.container.style.top=`${a}px`,this.container.style.right=`auto`,this.container.style.bottom=`auto`,this.adjustPositionAfterRender(t,r),n.w-=r.w;let o=e=>Array.from(e.children).filter(e=>e.tagName===`LI`&&e.classList.contains(_.submenu)),s=0,c=(e,t)=>{s+=1,o(e).forEach(e=>{let i=t>=r.w?r.w-8:(r.w+8)*-1,a=e.querySelector(`ul.${_.container}`),l=Math.round(this.lineHeight*Array.from(a.children).filter(e=>e.tagName===`LI`).length);a.style.left=`${i}px`,a.style.right=`auto`,a.style.top=n.h>=l+r.h?`0`:`-${a.offsetHeight-25}px`,a.style.bottom=`auto`,a.style.zIndex=String(s),o(a).length>0&&c(a,t-r.w)})};c(this.container.firstElementChild,n.w)}handleMapMove(){this.closeMenu()}handleEntryCallback(e){e.preventDefault(),e.stopPropagation();let t=e.currentTarget,n=this.menuEntries.get(t.id);if(!n)return;let r={coordinate:this.coordinate,data:n.data};this.closeMenu(),n.callback?.(r,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,{capture:!1})}}});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Options, SingleItem } from './types.ts';
|
|
2
|
+
export declare const DEFAULT_OPTIONS: Options;
|
|
3
|
+
export declare const CSS_CLASSES: {
|
|
4
|
+
container: string;
|
|
5
|
+
hidden: string;
|
|
6
|
+
icon: string;
|
|
7
|
+
namespace: string;
|
|
8
|
+
separator: string;
|
|
9
|
+
submenu: string;
|
|
10
|
+
unselectable: string;
|
|
11
|
+
zoomIn: string;
|
|
12
|
+
zoomOut: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const CONTAINER_PADDING = 8;
|
|
15
|
+
export declare const CONTAINER_PADDING_TOTAL: number;
|
|
16
|
+
export declare const MENU_POSITION_OFFSET = 10;
|
|
17
|
+
export declare const MENU_POSITION_BUFFER = 2;
|
|
18
|
+
export declare const DEFAULT_ITEMS: SingleItem[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Item } from '../types.ts';
|
|
2
|
+
import { TinyEmitter } from 'tiny-emitter';
|
|
3
|
+
export declare function createFragment(html: string): DocumentFragment;
|
|
4
|
+
export declare function getLineHeight(container: HTMLDivElement): number;
|
|
5
|
+
export declare function addMenuEntry({ emitter, isInsideSubmenu, isSubmenu, item, parentNode, }: {
|
|
6
|
+
emitter: TinyEmitter;
|
|
7
|
+
isInsideSubmenu?: boolean;
|
|
8
|
+
isSubmenu: boolean;
|
|
9
|
+
item: Item;
|
|
10
|
+
parentNode: HTMLUListElement;
|
|
11
|
+
}): HTMLLIElement;
|
|
12
|
+
export declare function addMenuEntries({ container, emitter, isInsideSubmenu, items, menuWidth, }: {
|
|
13
|
+
container: HTMLUListElement;
|
|
14
|
+
emitter: TinyEmitter;
|
|
15
|
+
isInsideSubmenu?: boolean;
|
|
16
|
+
items: Item[];
|
|
17
|
+
menuWidth: number;
|
|
18
|
+
}): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { default as Control } from 'ol/control/Control';
|
|
2
|
+
import { TinyEmitter } from 'tiny-emitter';
|
|
3
|
+
import { ContextMenuEvent, CustomEventTypes, Item, Options, MenuEntry } from './types.ts';
|
|
4
|
+
import { default as OlMap } from 'ol/Map';
|
|
5
|
+
import { Pixel } from 'ol/pixel';
|
|
6
|
+
import { EventsKey } from 'ol/events';
|
|
7
|
+
import { default as BaseEvent } from 'ol/events/Event';
|
|
8
|
+
import { ObjectEvent } from 'ol/Object';
|
|
9
|
+
import { Coordinate } from 'ol/coordinate';
|
|
10
|
+
import { Types as ObjectEventTypes } from 'ol/ObjectEventType';
|
|
11
|
+
import { OnSignature, CombinedOnSignature, EventTypes as OlEventTypes } from 'ol/Observable';
|
|
12
|
+
export default class ContextMenu extends Control {
|
|
13
|
+
protected map: OlMap;
|
|
14
|
+
protected emitter: TinyEmitter;
|
|
15
|
+
protected container: HTMLDivElement;
|
|
16
|
+
protected coordinate: Coordinate;
|
|
17
|
+
protected pixel: Pixel;
|
|
18
|
+
protected contextMenuEventListener: (evt: MouseEvent) => void;
|
|
19
|
+
protected entryCallbackEventListener: (evt: MouseEvent) => void;
|
|
20
|
+
protected mapMoveListener: () => void;
|
|
21
|
+
protected lineHeight: number;
|
|
22
|
+
protected disabled: boolean;
|
|
23
|
+
protected opened: boolean;
|
|
24
|
+
protected items: Item[];
|
|
25
|
+
protected menuEntries: Map<string, MenuEntry>;
|
|
26
|
+
on: OnSignature<OlEventTypes | `${CustomEventTypes.CLOSE}`, BaseEvent, EventsKey> & OnSignature<`${CustomEventTypes.OPEN}` | `${CustomEventTypes.BEFOREOPEN}`, ContextMenuEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, EventsKey> & CombinedOnSignature<OlEventTypes | ObjectEventTypes | `${CustomEventTypes.OPEN}` | `${CustomEventTypes.CLOSE}` | `${CustomEventTypes.BEFOREOPEN}`, EventsKey>;
|
|
27
|
+
once: OnSignature<OlEventTypes | `${CustomEventTypes.CLOSE}`, BaseEvent, EventsKey> & OnSignature<`${CustomEventTypes.OPEN}` | `${CustomEventTypes.BEFOREOPEN}`, ContextMenuEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, EventsKey> & CombinedOnSignature<OlEventTypes | ObjectEventTypes | `${CustomEventTypes.OPEN}` | `${CustomEventTypes.CLOSE}` | `${CustomEventTypes.BEFOREOPEN}`, EventsKey>;
|
|
28
|
+
un: OnSignature<OlEventTypes | `${CustomEventTypes.CLOSE}`, BaseEvent, void> & OnSignature<`${CustomEventTypes.OPEN}` | `${CustomEventTypes.BEFOREOPEN}`, ContextMenuEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, void> & CombinedOnSignature<OlEventTypes | ObjectEventTypes | `${CustomEventTypes.OPEN}` | `${CustomEventTypes.CLOSE}` | `${CustomEventTypes.BEFOREOPEN}`, void>;
|
|
29
|
+
options: Options;
|
|
30
|
+
constructor(opts?: Partial<Options>);
|
|
31
|
+
clear(): void;
|
|
32
|
+
enable(): void;
|
|
33
|
+
disable(): void;
|
|
34
|
+
getDefaultItems(): import('./types.ts').SingleItem[];
|
|
35
|
+
countItems(): number;
|
|
36
|
+
extend(items: Item[]): void;
|
|
37
|
+
closeMenu(): void;
|
|
38
|
+
isOpen(): boolean;
|
|
39
|
+
updatePosition(pixel: Pixel): void;
|
|
40
|
+
pop(): void;
|
|
41
|
+
shift(): void;
|
|
42
|
+
push(item: Item): void;
|
|
43
|
+
setMap(map: OlMap): void;
|
|
44
|
+
protected removeListeners(): void;
|
|
45
|
+
protected removeMenuEntry(id: string): void;
|
|
46
|
+
protected handleContextMenu(evt: MouseEvent): void;
|
|
47
|
+
protected openMenu(evt: MouseEvent): void;
|
|
48
|
+
protected getMenuEntriesLength(): number;
|
|
49
|
+
protected calculateMenuSize(): {
|
|
50
|
+
h: number;
|
|
51
|
+
w: number;
|
|
52
|
+
};
|
|
53
|
+
protected calculateVerticalPosition(mapSize: [number, number], spaceLeft: {
|
|
54
|
+
h: number;
|
|
55
|
+
w: number;
|
|
56
|
+
}, menuSize: {
|
|
57
|
+
h: number;
|
|
58
|
+
w: number;
|
|
59
|
+
}): number;
|
|
60
|
+
protected adjustPositionAfterRender(mapSize: [number, number], menuSize: {
|
|
61
|
+
h: number;
|
|
62
|
+
w: number;
|
|
63
|
+
}): void;
|
|
64
|
+
protected positionContainer(): void;
|
|
65
|
+
protected handleMapMove(): void;
|
|
66
|
+
protected handleEntryCallback(evt: MouseEvent): void;
|
|
67
|
+
protected handleAddMenuEntry(item: MenuEntry, element: HTMLLIElement): void;
|
|
68
|
+
}
|
|
69
|
+
export { type Item, type Options, type MenuEntry, type SingleItem, type EventTypes, type ItemSeparator, type ItemWithNested, type CallbackObject, type ContextMenuEvent, type CustomEventTypes, } from './types.ts';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { default as MapBrowserEvent } from 'ol/MapBrowserEvent';
|
|
2
|
+
import { default as OlMap } from 'ol/Map';
|
|
3
|
+
import { Coordinate } from 'ol/coordinate';
|
|
4
|
+
export declare enum EventTypes {
|
|
5
|
+
CONTEXTMENU = "contextmenu",
|
|
6
|
+
CLICK = "click",
|
|
7
|
+
DBLCLICK = "dblclick"
|
|
8
|
+
}
|
|
9
|
+
export declare enum CustomEventTypes {
|
|
10
|
+
BEFOREOPEN = "beforeopen",
|
|
11
|
+
OPEN = "open",
|
|
12
|
+
CLOSE = "close",
|
|
13
|
+
ADD_MENU_ENTRY = "add-menu-entry"
|
|
14
|
+
}
|
|
15
|
+
export declare class ContextMenuEvent extends MapBrowserEvent<any> {
|
|
16
|
+
constructor(options: {
|
|
17
|
+
map: OlMap;
|
|
18
|
+
originalEvent: MouseEvent | PointerEvent;
|
|
19
|
+
type: `${CustomEventTypes.OPEN}` | `${CustomEventTypes.BEFOREOPEN}`;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export type CallbackObject = {
|
|
23
|
+
coordinate: Coordinate;
|
|
24
|
+
data: unknown;
|
|
25
|
+
};
|
|
26
|
+
export type ItemSeparator = '-';
|
|
27
|
+
export type SingleItem = {
|
|
28
|
+
callback: (object: CallbackObject, map: OlMap) => void;
|
|
29
|
+
classname?: string;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
icon?: string;
|
|
32
|
+
text: string;
|
|
33
|
+
};
|
|
34
|
+
export type MenuEntry = {
|
|
35
|
+
callback: null | SingleItem['callback'];
|
|
36
|
+
data: unknown;
|
|
37
|
+
id: string;
|
|
38
|
+
isInsideSubmenu: boolean;
|
|
39
|
+
isSeparator: boolean;
|
|
40
|
+
isSubmenu: boolean;
|
|
41
|
+
};
|
|
42
|
+
export type ItemWithNested = {
|
|
43
|
+
classname?: string;
|
|
44
|
+
icon?: string;
|
|
45
|
+
items: Item[];
|
|
46
|
+
text: string;
|
|
47
|
+
};
|
|
48
|
+
export type Item = SingleItem | ItemSeparator | ItemWithNested;
|
|
49
|
+
export type Options = {
|
|
50
|
+
defaultItems: boolean;
|
|
51
|
+
eventType: `${EventTypes}`;
|
|
52
|
+
items: Item[];
|
|
53
|
+
scrollAt: number;
|
|
54
|
+
width: number;
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ol-contextmenu",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Custom Context Menu for Openlayers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openlayers",
|
|
@@ -61,30 +61,33 @@
|
|
|
61
61
|
"release": "release-it --no-npm.publish"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@types/node": "^25.
|
|
65
|
-
"@vitest/browser-webdriverio": "^4.
|
|
66
|
-
"@vitest/coverage-v8": "^4.
|
|
67
|
-
"@vitest/ui": "^4.
|
|
68
|
-
"auto-changelog": "^2.
|
|
69
|
-
"eslint-config-jwalker": "^12.
|
|
64
|
+
"@types/node": "^25.9.3",
|
|
65
|
+
"@vitest/browser-webdriverio": "^4.1.9",
|
|
66
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
67
|
+
"@vitest/ui": "^4.1.9",
|
|
68
|
+
"auto-changelog": "^2.6.0",
|
|
69
|
+
"eslint-config-jwalker": "^12.2.0",
|
|
70
70
|
"husky": "^9.1.7",
|
|
71
|
-
"jsdom": "^
|
|
72
|
-
"ol": "^10.
|
|
71
|
+
"jsdom": "^29.1.1",
|
|
72
|
+
"ol": "^10.9.0",
|
|
73
73
|
"premove": "^4.0.0",
|
|
74
|
-
"release-it": "^
|
|
75
|
-
"sass": "^1.
|
|
76
|
-
"typescript": "^
|
|
77
|
-
"vite": "^
|
|
74
|
+
"release-it": "^20.2.0",
|
|
75
|
+
"sass": "^1.101.0",
|
|
76
|
+
"typescript": "^6.0.3",
|
|
77
|
+
"vite": "^8.0.16",
|
|
78
78
|
"vite-plugin-banner": "^0.8.1",
|
|
79
|
-
"vite-plugin-css-injected-by-js": "^
|
|
80
|
-
"vite-plugin-dts": "^
|
|
81
|
-
"vitest": "^4.
|
|
82
|
-
"webdriverio": "^9.
|
|
79
|
+
"vite-plugin-css-injected-by-js": "^5.0.1",
|
|
80
|
+
"vite-plugin-dts": "^5.0.2",
|
|
81
|
+
"vitest": "^4.1.9",
|
|
82
|
+
"webdriverio": "^9.28.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"ol": "> 7.x <= 10.x"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"tiny-emitter": "^2.1.0"
|
|
89
|
+
},
|
|
90
|
+
"allowScripts": {
|
|
91
|
+
"geckodriver@6.1.0": true
|
|
89
92
|
}
|
|
90
93
|
}
|
package/dist/ol-contextmenu.d.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { CombinedOnSignature } from 'ol/Observable';
|
|
2
|
-
import { Coordinate } from 'ol/coordinate';
|
|
3
|
-
import { default as default_2 } from 'ol/control/Control';
|
|
4
|
-
import { default as default_3 } from 'ol/Map';
|
|
5
|
-
import { default as default_4 } from 'ol/events/Event';
|
|
6
|
-
import { default as default_5 } from 'ol/MapBrowserEvent';
|
|
7
|
-
import { EventsKey } from 'ol/events';
|
|
8
|
-
import { EventTypes as EventTypes_2 } from 'ol/Observable';
|
|
9
|
-
import { ObjectEvent } from 'ol/Object';
|
|
10
|
-
import { OnSignature } from 'ol/Observable';
|
|
11
|
-
import { Pixel } from 'ol/pixel';
|
|
12
|
-
import { TinyEmitter } from 'tiny-emitter';
|
|
13
|
-
import { Types } from 'ol/ObjectEventType';
|
|
14
|
-
|
|
15
|
-
export declare type CallbackObject = {
|
|
16
|
-
coordinate: Coordinate;
|
|
17
|
-
data: unknown;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
declare class ContextMenu extends default_2 {
|
|
21
|
-
protected map: default_3;
|
|
22
|
-
protected emitter: TinyEmitter;
|
|
23
|
-
protected container: HTMLDivElement;
|
|
24
|
-
protected coordinate: Coordinate;
|
|
25
|
-
protected pixel: Pixel;
|
|
26
|
-
protected contextMenuEventListener: (evt: MouseEvent) => void;
|
|
27
|
-
protected entryCallbackEventListener: (evt: MouseEvent) => void;
|
|
28
|
-
protected mapMoveListener: () => void;
|
|
29
|
-
protected lineHeight: number;
|
|
30
|
-
protected disabled: boolean;
|
|
31
|
-
protected opened: boolean;
|
|
32
|
-
protected items: Item[];
|
|
33
|
-
protected menuEntries: Map<string, MenuEntry>;
|
|
34
|
-
on: OnSignature<EventTypes_2 | `${CustomEventTypes.CLOSE}`, default_4, EventsKey> & OnSignature<`${CustomEventTypes.OPEN}` | `${CustomEventTypes.BEFOREOPEN}`, ContextMenuEvent, EventsKey> & OnSignature<Types, ObjectEvent, EventsKey> & CombinedOnSignature<EventTypes_2 | Types | `${CustomEventTypes.OPEN}` | `${CustomEventTypes.CLOSE}` | `${CustomEventTypes.BEFOREOPEN}`, EventsKey>;
|
|
35
|
-
once: OnSignature<EventTypes_2 | `${CustomEventTypes.CLOSE}`, default_4, EventsKey> & OnSignature<`${CustomEventTypes.OPEN}` | `${CustomEventTypes.BEFOREOPEN}`, ContextMenuEvent, EventsKey> & OnSignature<Types, ObjectEvent, EventsKey> & CombinedOnSignature<EventTypes_2 | Types | `${CustomEventTypes.OPEN}` | `${CustomEventTypes.CLOSE}` | `${CustomEventTypes.BEFOREOPEN}`, EventsKey>;
|
|
36
|
-
un: OnSignature<EventTypes_2 | `${CustomEventTypes.CLOSE}`, default_4, void> & OnSignature<`${CustomEventTypes.OPEN}` | `${CustomEventTypes.BEFOREOPEN}`, ContextMenuEvent, EventsKey> & OnSignature<Types, ObjectEvent, void> & CombinedOnSignature<EventTypes_2 | Types | `${CustomEventTypes.OPEN}` | `${CustomEventTypes.CLOSE}` | `${CustomEventTypes.BEFOREOPEN}`, void>;
|
|
37
|
-
options: Options;
|
|
38
|
-
constructor(opts?: Partial<Options>);
|
|
39
|
-
clear(): void;
|
|
40
|
-
enable(): void;
|
|
41
|
-
disable(): void;
|
|
42
|
-
getDefaultItems(): SingleItem[];
|
|
43
|
-
countItems(): number;
|
|
44
|
-
extend(items: Item[]): void;
|
|
45
|
-
closeMenu(): void;
|
|
46
|
-
isOpen(): boolean;
|
|
47
|
-
updatePosition(pixel: Pixel): void;
|
|
48
|
-
pop(): void;
|
|
49
|
-
shift(): void;
|
|
50
|
-
push(item: Item): void;
|
|
51
|
-
setMap(map: default_3): void;
|
|
52
|
-
protected removeListeners(): void;
|
|
53
|
-
protected removeMenuEntry(id: string): void;
|
|
54
|
-
protected handleContextMenu(evt: MouseEvent): void;
|
|
55
|
-
protected openMenu(evt: MouseEvent): void;
|
|
56
|
-
protected getMenuEntriesLength(): number;
|
|
57
|
-
protected calculateMenuSize(): {
|
|
58
|
-
h: number;
|
|
59
|
-
w: number;
|
|
60
|
-
};
|
|
61
|
-
protected calculateVerticalPosition(mapSize: [number, number], spaceLeft: {
|
|
62
|
-
h: number;
|
|
63
|
-
w: number;
|
|
64
|
-
}, menuSize: {
|
|
65
|
-
h: number;
|
|
66
|
-
w: number;
|
|
67
|
-
}): number;
|
|
68
|
-
protected adjustPositionAfterRender(mapSize: [number, number], menuSize: {
|
|
69
|
-
h: number;
|
|
70
|
-
w: number;
|
|
71
|
-
}): void;
|
|
72
|
-
protected positionContainer(): void;
|
|
73
|
-
protected handleMapMove(): void;
|
|
74
|
-
protected handleEntryCallback(evt: MouseEvent): void;
|
|
75
|
-
protected handleAddMenuEntry(item: MenuEntry, element: HTMLLIElement): void;
|
|
76
|
-
}
|
|
77
|
-
export default ContextMenu;
|
|
78
|
-
|
|
79
|
-
export declare class ContextMenuEvent extends default_5<any> {
|
|
80
|
-
constructor(options: {
|
|
81
|
-
map: default_3;
|
|
82
|
-
originalEvent: MouseEvent | PointerEvent;
|
|
83
|
-
type: `${CustomEventTypes.OPEN}` | `${CustomEventTypes.BEFOREOPEN}`;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export declare enum CustomEventTypes {
|
|
88
|
-
BEFOREOPEN = "beforeopen",
|
|
89
|
-
OPEN = "open",
|
|
90
|
-
CLOSE = "close",
|
|
91
|
-
ADD_MENU_ENTRY = "add-menu-entry"
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export declare enum EventTypes {
|
|
95
|
-
CONTEXTMENU = "contextmenu",
|
|
96
|
-
CLICK = "click",
|
|
97
|
-
DBLCLICK = "dblclick"
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export declare type Item = SingleItem | ItemSeparator | ItemWithNested;
|
|
101
|
-
|
|
102
|
-
export declare type ItemSeparator = '-';
|
|
103
|
-
|
|
104
|
-
export declare type ItemWithNested = {
|
|
105
|
-
classname?: string;
|
|
106
|
-
icon?: string;
|
|
107
|
-
items: Item[];
|
|
108
|
-
text: string;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export declare type MenuEntry = {
|
|
112
|
-
callback: null | SingleItem['callback'];
|
|
113
|
-
data: unknown;
|
|
114
|
-
id: string;
|
|
115
|
-
isInsideSubmenu: boolean;
|
|
116
|
-
isSeparator: boolean;
|
|
117
|
-
isSubmenu: boolean;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export declare type Options = {
|
|
121
|
-
defaultItems: boolean;
|
|
122
|
-
eventType: `${EventTypes}`;
|
|
123
|
-
items: Item[];
|
|
124
|
-
scrollAt: number;
|
|
125
|
-
width: number;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export declare type SingleItem = {
|
|
129
|
-
callback: (object: CallbackObject, map: default_3) => void;
|
|
130
|
-
classname?: string;
|
|
131
|
-
data?: unknown;
|
|
132
|
-
icon?: string;
|
|
133
|
-
text: string;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export { }
|