ol-contextmenu 5.4.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +141 -171
- package/dist/ol-contextmenu.d.ts +136 -3
- package/dist/ol-contextmenu.iife.js +4 -3
- package/dist/ol-contextmenu.js +256 -241
- package/dist/ol-contextmenu.umd.cjs +4 -3
- package/package.json +49 -39
- package/dist/constants.d.ts +0 -14
- package/dist/helpers/dom.d.ts +0 -18
- package/dist/main.d.ts +0 -55
- package/dist/ol-contextmenu.css +0 -8
- package/dist/types.d.ts +0 -55
package/dist/ol-contextmenu.js
CHANGED
|
@@ -1,205 +1,207 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu -
|
|
3
|
+
* ol-contextmenu - v6.0.0
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built:
|
|
5
|
+
* Built: 2026-01-05T22:44:21.378Z
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return (s[n] || (s[n] = [])).push({
|
|
20
|
-
fn: t,
|
|
21
|
-
ctx: e
|
|
22
|
-
}), this;
|
|
23
|
-
},
|
|
24
|
-
once: function(n, t, e) {
|
|
25
|
-
var s = this;
|
|
26
|
-
function o() {
|
|
27
|
-
s.off(n, o), t.apply(e, arguments);
|
|
28
|
-
}
|
|
29
|
-
return o._ = t, this.on(n, o, e);
|
|
30
|
-
},
|
|
31
|
-
emit: function(n) {
|
|
32
|
-
var t = [].slice.call(arguments, 1), e = ((this.e || (this.e = {}))[n] || []).slice(), s = 0, o = e.length;
|
|
33
|
-
for (s; s < o; s++)
|
|
34
|
-
e[s].fn.apply(e[s].ctx, t);
|
|
35
|
-
return this;
|
|
36
|
-
},
|
|
37
|
-
off: function(n, t) {
|
|
38
|
-
var e = this.e || (this.e = {}), s = e[n], o = [];
|
|
39
|
-
if (s && t)
|
|
40
|
-
for (var i = 0, l = s.length; i < l; i++)
|
|
41
|
-
s[i].fn !== t && s[i].fn._ !== t && o.push(s[i]);
|
|
42
|
-
return o.length ? e[n] = o : delete e[n], this;
|
|
8
|
+
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode('.ol-ctx-menu-container{position:absolute;padding:8px;background:#fff;color:#222;font-size:13px;border-radius:5px;box-shadow:#0003 3px 3px 5px;box-sizing:border-box}.ol-ctx-menu-container div,.ol-ctx-menu-container span,.ol-ctx-menu-container a,.ol-ctx-menu-container img,.ol-ctx-menu-container ul,.ol-ctx-menu-container li{margin:0;padding:0;border:0;font:inherit;font-size:100%;vertical-align:baseline}.ol-ctx-menu-container a img{border:none}.ol-ctx-menu-container *,.ol-ctx-menu-container *:before,.ol-ctx-menu-container *:after{box-sizing:inherit}.ol-ctx-menu-container.ol-ctx-menu-hidden{opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container ul{list-style:none}.ol-ctx-menu-container li{position:relative;line-height:20px;padding:2px 5px;white-space:nowrap}.ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover{cursor:pointer;background-color:#333;color:#eee}.ol-ctx-menu-container li.ol-ctx-menu-submenu .ol-ctx-menu-container{border:1px solid #eee;padding:8px;top:0;opacity:0;visibility:hidden;transition:visibility 0s linear .3s,opacity .3s}.ol-ctx-menu-container li.ol-ctx-menu-submenu:after{position:absolute;top:7px;right:10px;content:"";display:inline-block;width:.6em;height:.6em;border-right:.3em solid #222;border-top:.3em solid #222;transform:rotate(45deg)}.ol-ctx-menu-container li.ol-ctx-menu-submenu:hover:after{border-color:#eee}.ol-ctx-menu-container:not(.ol-ctx-menu-hidden) li.ol-ctx-menu-submenu:hover>.ol-ctx-menu-container{opacity:1;visibility:visible;transition-delay:0s}.ol-ctx-menu-container li.ol-ctx-menu-separator{padding:0}.ol-ctx-menu-container li.ol-ctx-menu-separator hr{border:0;height:1px;background-image:linear-gradient(to left,#0000,#000000bf,#0000)}.ol-ctx-menu-icon{text-indent:20px;background-size:20px auto;background-repeat:no-repeat;background-position:left center}.ol-ctx-menu-zoom-in{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABaUlEQVQ4T72U7VHCQBCGn90GtAMuNGCswFiBWIFQgWMFxg6wArECsQKhArEBiB1Qwa1zgQn5IAYcxv13k71n3919L8KJQ07M47+BzgG9TRfZ/JBuWhS6BJFHRJICYrZGZIz3z5Ct2+B7gG6I6kt+wewdkQVwjtkAkR5mC8yu26A1oItR/cTsOweQBdgutD8G7jGm2PJ2n8oqUKIpIjd4HxTM8gvaT/F+AlmWnyWaIXKF95eNguFzTYFhNsdWu9kFgFlaFMANUH3D8wDLoLgSTSD2il8NCe2ZXQBxWDGwxmyUzzOMBZ7wy7Qb2K0wQfXjMOBuhlFpZtNty5sFaTQBuTusZdymeqs1SpYKcO9HkE3KbTd9WFijMHJQ5hBNEAYNq5Qd0dhyke0GiE4QzjqfW23mHT8Hl4DG4Lce3FPE7AtbBSdsbNqpoJLgYkRnNeUV+xwJDHTnUEkxHGbhBXUs5TjJjew/KPy94g+NRaIVRYmMXwAAAABJRU5ErkJggg==)}.ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-in{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABc0lEQVQ4T71U21ECQRDsJgGdvQDECMQIxAjECMQILCPwzAAjECIQI0AiEDPQAPaWCBhrcKHuCUcV5f7dY3v6tUscefHIePhfwBBCF8CZqRCReRs1tQxDCH1VfQLQz4EsSY4AvIjIsgm8AhhCGKrqa9zwrqoLAKckB5HtguR1E2gBMITQU9VPAD8GICIGtl3e+xHJBwBT59xtHcsCYJZlUwA3kcGHbfDep51OZywi3/acZZm9vyJ5WR5o38uACmDunNt6ZwAkUxFZDwghDFT1jeSjiJinhVUBVNVJkiTDKO8CQA+AsbNQ7s1Ps0VVn5MkSfcCtmBoDZi1Bdx4eJ7zbBolrwPy3o9J3rWSHPs3A1BbjVKlYBaIyDgvu9LDXDU2RTZmXVW1oKyLxRD+OrkOrJLy5mVM0iaftDhuhVbsvBzMglzKUNW6IV/OOWtCM8MmVvEkmbwt83LaB19fdgOtVquUZJeknaDdobTwbOcvBzPcN/AXH1DFFWP7u9oAAAAASUVORK5CYII=)}.ol-ctx-menu-zoom-out{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABU0lEQVQ4T72U7VECMRRFz3sNaAdkacC1AtcKxApcKnCsQOwAK3CtQKxAqEBsANYOqCDPyTIC+8WCw5jfybn33dxEOPGSE/P4b6BzQG89RT47ZJoWhy5B5BGRZAMxWyEyxvtnyFdt8AagS1F9KQ6YvSMyB84xGyDSw2yO2XUbtAJ0MaqfmH0XAPIA2y7tj4F7jAm2uG1yWQZKNEHkBu+Dg2njWBJNEbnC+8uaIFRuWfuG2QxbbrOrUd0A1Tc8D7AIjkur7DAAsVf8MiWMZ3ZR2m02LPIMscATfjHqBnY7TFD9OAy4zTCCPG/MUKMM5O6wkXFr9dZq7FQqqHk/hDzbFa73cFONTZFDdRyiCcKg5rrSiLaXkiI6RjjrfG6VzDs+B5eAxuDXeYpmNRGzL2wZ/wof+du4GNFpBVqqz5HA4MM5VEYYDrOs+1I6Q9u/4Q8O9wN/AGgWjBVqQjjgAAAAAElFTkSuQmCC)}.ol-ctx-menu-container li:hover.ol-ctx-menu-zoom-out{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABYklEQVQ4T72U4VHCQBCF36tA91KAWIFYgViBWIFYgWMFYgdYgVCBWAFSgdiBFpAsFWSdxcDkQoBkhnF/ZjbfvX377ogjF4/Mw/8CVbUD4MynEJF5k2lqFapqz8yeAPRKkCXJEYAXEVnugm8BVXVgZq/FD+9mtgBwSrJfqF2QvN4FjYCq2jWzTwA/DhARh20qTdMRyQcA0xDCbZ3KCJhl2RTATaHgo+6HLMv8+xXJy+qB3l8FGoB5CKHsXcRV1b6ZvZF8FBH3NKotoJlNkiQZFONdlLtJ3rufbouZPSdJMjwIbKDQEzBrClx7eC4i33Uepmk6JnnXaOQifzMAtdGoRApugYiMI1uqKkrRWAfZo9MxM1+UZzFewl8mN4nYdVM83L7BkwbXLUrF3sfBLQDQBbDy08x8vOohXyEE71lVq9emuEk+3gZa3XYroCvwFyjP8yHJDsnxwaU08GxvS2uFhw78BbzWrxXgMbsHAAAAAElFTkSuQmCC)}')),document.head.appendChild(e)}}catch(n){console.error("vite-plugin-css-injected-by-js",n)}})();
|
|
9
|
+
var D = Object.defineProperty;
|
|
10
|
+
var S = (o, i, t) => i in o ? D(o, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[i] = t;
|
|
11
|
+
var c = (o, i, t) => S(o, typeof i != "symbol" ? i + "" : i, t);
|
|
12
|
+
import P from "ol/control/Control";
|
|
13
|
+
import k from "ol/MapBrowserEvent";
|
|
14
|
+
var y = { exports: {} }, w;
|
|
15
|
+
function H() {
|
|
16
|
+
if (w) return y.exports;
|
|
17
|
+
w = 1;
|
|
18
|
+
function o() {
|
|
43
19
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
20
|
+
return o.prototype = {
|
|
21
|
+
on: function(i, t, e) {
|
|
22
|
+
var s = this.e || (this.e = {});
|
|
23
|
+
return (s[i] || (s[i] = [])).push({
|
|
24
|
+
fn: t,
|
|
25
|
+
ctx: e
|
|
26
|
+
}), this;
|
|
27
|
+
},
|
|
28
|
+
once: function(i, t, e) {
|
|
29
|
+
var s = this;
|
|
30
|
+
function n() {
|
|
31
|
+
s.off(i, n), t.apply(e, arguments);
|
|
32
|
+
}
|
|
33
|
+
return n._ = t, this.on(i, n, e);
|
|
34
|
+
},
|
|
35
|
+
emit: function(i) {
|
|
36
|
+
var t = [].slice.call(arguments, 1), e = ((this.e || (this.e = {}))[i] || []).slice(), s = 0, n = e.length;
|
|
37
|
+
for (s; s < n; s++)
|
|
38
|
+
e[s].fn.apply(e[s].ctx, t);
|
|
39
|
+
return this;
|
|
40
|
+
},
|
|
41
|
+
off: function(i, t) {
|
|
42
|
+
var e = this.e || (this.e = {}), s = e[i], n = [];
|
|
43
|
+
if (s && t)
|
|
44
|
+
for (var a = 0, h = s.length; a < h; a++)
|
|
45
|
+
s[a].fn !== t && s[a].fn._ !== t && n.push(s[a]);
|
|
46
|
+
return n.length ? e[i] = n : delete e[i], this;
|
|
47
|
+
}
|
|
48
|
+
}, y.exports = o, y.exports.TinyEmitter = o, y.exports;
|
|
49
|
+
}
|
|
50
|
+
var R = H(), L = /* @__PURE__ */ ((o) => (o.CONTEXTMENU = "contextmenu", o.CLICK = "click", o.DBLCLICK = "dblclick", o))(L || {}), d = /* @__PURE__ */ ((o) => (o.BEFOREOPEN = "beforeopen", o.OPEN = "open", o.CLOSE = "close", o.ADD_MENU_ENTRY = "add-menu-entry", o))(d || {});
|
|
51
|
+
class A extends k {
|
|
52
|
+
constructor(i) {
|
|
53
|
+
super(i.type, i.map, i.originalEvent);
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
|
-
const
|
|
53
|
-
width: 150,
|
|
54
|
-
scrollAt: 4,
|
|
55
|
-
eventType: L.CONTEXTMENU,
|
|
56
|
+
const U = {
|
|
56
57
|
defaultItems: !0,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
hidden: `${
|
|
64
|
-
icon: `${
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
unselectable: "ol-unselectable"
|
|
68
|
-
}
|
|
58
|
+
eventType: L.CONTEXTMENU,
|
|
59
|
+
items: [],
|
|
60
|
+
scrollAt: 4,
|
|
61
|
+
width: 150
|
|
62
|
+
}, p = "ol-ctx-menu", r = {
|
|
63
|
+
container: `${p}-container`,
|
|
64
|
+
hidden: `${p}-hidden`,
|
|
65
|
+
icon: `${p}-icon`,
|
|
66
|
+
separator: `${p}-separator`,
|
|
67
|
+
submenu: `${p}-submenu`,
|
|
68
|
+
unselectable: "ol-unselectable",
|
|
69
|
+
zoomIn: `${p}-zoom-in`,
|
|
70
|
+
zoomOut: `${p}-zoom-out`
|
|
71
|
+
}, F = 8, V = F * 2, B = 10, M = 2, C = [
|
|
69
72
|
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
e.animate({
|
|
75
|
-
zoom: Number(e.getZoom()) + 1,
|
|
73
|
+
callback: (o, i) => {
|
|
74
|
+
const t = i.getView();
|
|
75
|
+
t.animate({
|
|
76
|
+
center: o.coordinate,
|
|
76
77
|
duration: 700,
|
|
77
|
-
|
|
78
|
+
zoom: Number(t.getZoom()) + 1
|
|
78
79
|
});
|
|
79
|
-
}
|
|
80
|
+
},
|
|
81
|
+
classname: `${r.zoomIn} ${r.icon}`,
|
|
82
|
+
text: "Zoom In"
|
|
80
83
|
},
|
|
81
84
|
{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
e.animate({
|
|
87
|
-
zoom: Number(e.getZoom()) - 1,
|
|
85
|
+
callback: (o, i) => {
|
|
86
|
+
const t = i.getView();
|
|
87
|
+
t.animate({
|
|
88
|
+
center: o.coordinate,
|
|
88
89
|
duration: 700,
|
|
89
|
-
|
|
90
|
+
zoom: Number(t.getZoom()) - 1
|
|
90
91
|
});
|
|
91
|
-
}
|
|
92
|
+
},
|
|
93
|
+
classname: `${r.zoomOut} ${r.icon}`,
|
|
94
|
+
text: "Zoom Out"
|
|
92
95
|
}
|
|
93
96
|
];
|
|
94
|
-
function
|
|
95
|
-
const
|
|
96
|
-
for (
|
|
97
|
-
|
|
98
|
-
return
|
|
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;
|
|
99
102
|
}
|
|
100
|
-
function
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
return
|
|
103
|
+
function j(o) {
|
|
104
|
+
const i = document.importNode(o), t = o.offsetWidth;
|
|
105
|
+
i.style.cssText = `position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${t}px`;
|
|
106
|
+
const e = v("<span>Foo</span>"), s = v("<span>Foo</span>"), n = document.createElement("li"), a = document.createElement("li");
|
|
107
|
+
n.append(e), a.append(s), i.append(n), i.append(a), o.parentNode?.append(i);
|
|
108
|
+
const h = i.offsetHeight / 2;
|
|
109
|
+
return o.parentNode?.removeChild(i), h;
|
|
107
110
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
isSubmenu:
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
function T({
|
|
112
|
+
emitter: o,
|
|
113
|
+
isInsideSubmenu: i = !1,
|
|
114
|
+
isSubmenu: t = !1,
|
|
115
|
+
item: e,
|
|
116
|
+
parentNode: s
|
|
114
117
|
}) {
|
|
115
|
-
const
|
|
116
|
-
if (typeof
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
const n = `_${Math.random().toString(36).slice(2, 11)}`;
|
|
119
|
+
if (typeof e != "string" && "text" in e) {
|
|
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,
|
|
123
127
|
isSeparator: !1,
|
|
124
|
-
|
|
125
|
-
data: "data" in t ? t.data : null
|
|
128
|
+
isSubmenu: t
|
|
126
129
|
};
|
|
127
|
-
return o.emit(
|
|
130
|
+
return o.emit(d.ADD_MENU_ENTRY, N, l), l;
|
|
128
131
|
}
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
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,
|
|
134
138
|
isInsideSubmenu: !1,
|
|
135
139
|
isSeparator: !0,
|
|
136
|
-
|
|
137
|
-
data: null
|
|
140
|
+
isSubmenu: !1
|
|
138
141
|
};
|
|
139
|
-
return o.emit(
|
|
142
|
+
return o.emit(d.ADD_MENU_ENTRY, E, m), m;
|
|
140
143
|
}
|
|
141
|
-
function
|
|
142
|
-
container:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
function x({
|
|
145
|
+
container: o,
|
|
146
|
+
emitter: i,
|
|
147
|
+
isInsideSubmenu: t,
|
|
148
|
+
items: e,
|
|
149
|
+
menuWidth: s
|
|
147
150
|
}) {
|
|
148
|
-
|
|
149
|
-
if (typeof
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
items:
|
|
158
|
-
|
|
151
|
+
e.forEach((n) => {
|
|
152
|
+
if (typeof n != "string" && "items" in n && Array.isArray(n.items)) {
|
|
153
|
+
const a = T({ emitter: i, isSubmenu: !0, item: n, parentNode: o });
|
|
154
|
+
a.classList.add(r.submenu);
|
|
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
|
|
159
162
|
});
|
|
160
163
|
} else
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
+
T({
|
|
165
|
+
emitter: i,
|
|
166
|
+
isInsideSubmenu: t,
|
|
164
167
|
isSubmenu: !1,
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
item: n,
|
|
169
|
+
parentNode: o
|
|
167
170
|
});
|
|
168
171
|
});
|
|
169
172
|
}
|
|
170
|
-
function b(
|
|
171
|
-
if (!
|
|
172
|
-
throw new Error(t);
|
|
173
|
+
function b(o, i) {
|
|
174
|
+
if (!o) throw new Error(i);
|
|
173
175
|
}
|
|
174
|
-
class
|
|
175
|
-
constructor(
|
|
176
|
-
b(typeof
|
|
177
|
-
const
|
|
178
|
-
super({ element:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
this.options = { ...
|
|
194
|
-
const
|
|
195
|
-
|
|
176
|
+
class X extends P {
|
|
177
|
+
constructor(t = {}) {
|
|
178
|
+
b(typeof t == "object", "@param `opts` should be object type!");
|
|
179
|
+
const e = document.createElement("div");
|
|
180
|
+
super({ element: e });
|
|
181
|
+
c(this, "map");
|
|
182
|
+
c(this, "emitter", new R.TinyEmitter());
|
|
183
|
+
c(this, "container");
|
|
184
|
+
c(this, "coordinate", []);
|
|
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(
|
|
196
198
|
r.container,
|
|
197
199
|
r.unselectable,
|
|
198
200
|
r.hidden
|
|
199
|
-
), this.container =
|
|
200
|
-
this.handleContextMenu(
|
|
201
|
-
}, this.entryCallbackEventListener = (
|
|
202
|
-
this.handleEntryCallback(
|
|
201
|
+
), this.container = e, this.contextMenuEventListener = (n) => {
|
|
202
|
+
this.handleContextMenu(n);
|
|
203
|
+
}, this.entryCallbackEventListener = (n) => {
|
|
204
|
+
this.handleEntryCallback(n);
|
|
203
205
|
}, this.mapMoveListener = () => {
|
|
204
206
|
this.handleMapMove();
|
|
205
207
|
}, this.disabled = !1, this.opened = !1, window.addEventListener(
|
|
@@ -211,8 +213,8 @@ class R extends O {
|
|
|
211
213
|
);
|
|
212
214
|
}
|
|
213
215
|
clear() {
|
|
214
|
-
for (const
|
|
215
|
-
this.removeMenuEntry(
|
|
216
|
+
for (const t of this.menuEntries.keys())
|
|
217
|
+
this.removeMenuEntry(t);
|
|
216
218
|
this.container.replaceChildren(), this.container.append(document.createElement("ul"));
|
|
217
219
|
}
|
|
218
220
|
enable() {
|
|
@@ -227,120 +229,134 @@ class R extends O {
|
|
|
227
229
|
countItems() {
|
|
228
230
|
return this.menuEntries.size;
|
|
229
231
|
}
|
|
230
|
-
extend(
|
|
231
|
-
b(Array.isArray(
|
|
232
|
-
|
|
232
|
+
extend(t) {
|
|
233
|
+
b(Array.isArray(t), "@param `items` should be an Array."), x({
|
|
234
|
+
container: this.container.firstElementChild,
|
|
233
235
|
emitter: this.emitter,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
items: t,
|
|
237
|
+
menuWidth: this.options.width
|
|
236
238
|
});
|
|
237
239
|
}
|
|
238
240
|
closeMenu() {
|
|
239
|
-
this.opened = !1, this.container.classList.add(r.hidden), this.dispatchEvent(
|
|
241
|
+
this.opened = !1, this.container.classList.add(r.hidden), this.dispatchEvent(d.CLOSE);
|
|
240
242
|
}
|
|
241
243
|
isOpen() {
|
|
242
244
|
return this.opened;
|
|
243
245
|
}
|
|
244
|
-
updatePosition(
|
|
245
|
-
b(Array.isArray(
|
|
246
|
+
updatePosition(t) {
|
|
247
|
+
b(Array.isArray(t), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = t, this.positionContainer());
|
|
246
248
|
}
|
|
247
249
|
pop() {
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
+
const t = Array.from(this.menuEntries.keys()).pop();
|
|
251
|
+
t && this.removeMenuEntry(t);
|
|
250
252
|
}
|
|
251
253
|
shift() {
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
+
const t = Array.from(this.menuEntries.keys()).shift();
|
|
255
|
+
t && this.removeMenuEntry(t);
|
|
254
256
|
}
|
|
255
|
-
push(
|
|
256
|
-
|
|
257
|
+
push(t) {
|
|
258
|
+
t && this.extend([t]);
|
|
257
259
|
}
|
|
258
|
-
setMap(
|
|
259
|
-
if (super.setMap(
|
|
260
|
-
this.map =
|
|
260
|
+
setMap(t) {
|
|
261
|
+
if (super.setMap(t), t) {
|
|
262
|
+
this.map = t, t.getViewport().addEventListener(
|
|
261
263
|
this.options.eventType,
|
|
262
264
|
this.contextMenuEventListener,
|
|
263
265
|
!1
|
|
264
|
-
),
|
|
266
|
+
), t.on("movestart", () => {
|
|
265
267
|
this.handleMapMove();
|
|
266
268
|
}), this.emitter.on(
|
|
267
|
-
|
|
268
|
-
(
|
|
269
|
-
this.handleAddMenuEntry(
|
|
269
|
+
d.ADD_MENU_ENTRY,
|
|
270
|
+
(s, n) => {
|
|
271
|
+
this.handleAddMenuEntry(s, n);
|
|
270
272
|
},
|
|
271
273
|
this
|
|
272
|
-
), this.items = this.options.defaultItems ? this.options.items.concat(C) : this.options.items,
|
|
273
|
-
|
|
274
|
+
), this.items = this.options.defaultItems ? this.options.items.concat(C) : this.options.items, x({
|
|
275
|
+
container: this.container.firstElementChild,
|
|
274
276
|
emitter: this.emitter,
|
|
275
|
-
|
|
276
|
-
|
|
277
|
+
items: this.items,
|
|
278
|
+
menuWidth: this.options.width
|
|
277
279
|
});
|
|
278
|
-
const
|
|
279
|
-
this.lineHeight =
|
|
280
|
+
const e = this.getMenuEntriesLength();
|
|
281
|
+
this.lineHeight = e > 0 ? this.container.offsetHeight / e : j(this.container);
|
|
280
282
|
} else
|
|
281
283
|
this.removeListeners(), this.clear();
|
|
282
284
|
}
|
|
283
285
|
removeListeners() {
|
|
284
|
-
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.emitter.off(
|
|
286
|
+
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.emitter.off(d.ADD_MENU_ENTRY);
|
|
285
287
|
}
|
|
286
|
-
removeMenuEntry(
|
|
287
|
-
let
|
|
288
|
-
|
|
288
|
+
removeMenuEntry(t) {
|
|
289
|
+
let e = document.getElementById(t);
|
|
290
|
+
e?.remove(), e = null, this.menuEntries.delete(t);
|
|
289
291
|
}
|
|
290
|
-
handleContextMenu(
|
|
291
|
-
this.coordinate = this.map.getEventCoordinate(
|
|
292
|
-
new
|
|
292
|
+
handleContextMenu(t) {
|
|
293
|
+
this.coordinate = this.map.getEventCoordinate(t), this.pixel = this.map.getEventPixel(t), this.dispatchEvent(
|
|
294
|
+
new A({
|
|
293
295
|
map: this.map,
|
|
294
|
-
originalEvent:
|
|
295
|
-
type:
|
|
296
|
+
originalEvent: t,
|
|
297
|
+
type: d.BEFOREOPEN
|
|
296
298
|
})
|
|
297
|
-
), !this.disabled && (this.options.eventType === L.CONTEXTMENU && (
|
|
298
|
-
this.openMenu(
|
|
299
|
-
}),
|
|
299
|
+
), !this.disabled && (this.options.eventType === L.CONTEXTMENU && (t.stopPropagation(), t.preventDefault()), setTimeout(() => {
|
|
300
|
+
this.openMenu(t);
|
|
301
|
+
}), t.target?.addEventListener(
|
|
300
302
|
"pointerdown",
|
|
301
|
-
(
|
|
302
|
-
this.opened && (
|
|
303
|
+
(e) => {
|
|
304
|
+
this.opened && (e.stopPropagation(), this.closeMenu());
|
|
303
305
|
},
|
|
304
306
|
{ once: !0 }
|
|
305
307
|
));
|
|
306
308
|
}
|
|
307
|
-
openMenu(
|
|
309
|
+
openMenu(t) {
|
|
308
310
|
this.opened = !0, this.positionContainer(), this.container.classList.remove(r.hidden), this.dispatchEvent(
|
|
309
|
-
new
|
|
311
|
+
new A({
|
|
310
312
|
map: this.map,
|
|
311
|
-
originalEvent:
|
|
312
|
-
type:
|
|
313
|
+
originalEvent: t,
|
|
314
|
+
type: d.OPEN
|
|
313
315
|
})
|
|
314
316
|
);
|
|
315
317
|
}
|
|
316
318
|
getMenuEntriesLength() {
|
|
317
319
|
return Array.from(this.menuEntries).filter(
|
|
318
|
-
([,
|
|
320
|
+
([, t]) => t.isSeparator === !1 && t.isSubmenu === !1 && t.isInsideSubmenu === !1
|
|
319
321
|
).length;
|
|
320
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
|
+
}
|
|
321
340
|
positionContainer() {
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
},
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
this.container.style.left = `${l}px`, this.container.style.top = s.h >= i.h ? `${this.pixel[1] - 10}px` : `${this.pixel[1] - i.h}px`, this.container.style.right = "auto", this.container.style.bottom = "auto", s.w -= i.w;
|
|
332
|
-
const c = (E) => Array.from(E.children).filter(
|
|
333
|
-
(m) => m.tagName === "LI" && m.classList.contains(r.submenu)
|
|
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)
|
|
334
350
|
);
|
|
335
|
-
let
|
|
336
|
-
const g = (
|
|
337
|
-
|
|
338
|
-
const
|
|
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(
|
|
339
355
|
`ul.${r.container}`
|
|
340
356
|
), $ = Math.round(
|
|
341
|
-
this.lineHeight * Array.from(
|
|
357
|
+
this.lineHeight * Array.from(u.children).filter((_) => _.tagName === "LI").length
|
|
342
358
|
);
|
|
343
|
-
|
|
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);
|
|
344
360
|
});
|
|
345
361
|
};
|
|
346
362
|
g(this.container.firstElementChild, s.w);
|
|
@@ -348,21 +364,20 @@ class R extends O {
|
|
|
348
364
|
handleMapMove() {
|
|
349
365
|
this.closeMenu();
|
|
350
366
|
}
|
|
351
|
-
handleEntryCallback(
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
if (!
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
data:
|
|
358
|
-
coordinate: this.coordinate
|
|
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
|
|
359
374
|
};
|
|
360
|
-
this.closeMenu(),
|
|
375
|
+
this.closeMenu(), s.callback?.(n, this.map);
|
|
361
376
|
}
|
|
362
|
-
handleAddMenuEntry(
|
|
363
|
-
this.menuEntries.set(
|
|
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);
|
|
364
379
|
}
|
|
365
380
|
}
|
|
366
381
|
export {
|
|
367
|
-
|
|
382
|
+
X as default
|
|
368
383
|
};
|