ol-contextmenu 5.5.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/README.md +141 -171
- package/dist/ol-contextmenu.iife.js +4 -3
- package/dist/ol-contextmenu.js +342 -352
- package/dist/ol-contextmenu.umd.cjs +4 -3
- package/dist/{constants.d.ts → src/constants.d.ts} +9 -5
- package/dist/{helpers → src/helpers}/dom.d.ts +9 -9
- package/dist/{main.d.ts → src/main.d.ts} +24 -9
- package/dist/{types.d.ts → src/types.d.ts} +14 -14
- package/package.json +51 -38
- package/dist/ol-contextmenu.css +0 -8
- package/dist/ol-contextmenu.d.ts +0 -3
package/dist/ol-contextmenu.js
CHANGED
|
@@ -1,366 +1,356 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
|
-
* ol-contextmenu -
|
|
3
|
+
* ol-contextmenu - v6.0.1
|
|
4
4
|
* https://github.com/jonataswalker/ol-contextmenu
|
|
5
|
-
* Built:
|
|
5
|
+
* Built: 2026-06-17T21:57:20.658Z
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
function
|
|
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;
|
|
15
93
|
}
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
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;
|
|
101
|
+
}
|
|
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;
|
|
51
128
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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 Out",
|
|
83
|
-
classname: `${r.zoomOut} ${r.icon}`,
|
|
84
|
-
callback: (n, t) => {
|
|
85
|
-
const e = t.getView();
|
|
86
|
-
e.animate({
|
|
87
|
-
zoom: Number(e.getZoom()) - 1,
|
|
88
|
-
duration: 700,
|
|
89
|
-
center: n.coordinate
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
];
|
|
94
|
-
function y(n) {
|
|
95
|
-
const t = document.createDocumentFragment(), e = document.createElement("div");
|
|
96
|
-
for (e.innerHTML = n; e.firstChild; )
|
|
97
|
-
t.append(e.firstChild);
|
|
98
|
-
return t;
|
|
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
|
+
});
|
|
99
155
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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);
|
|
107
165
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const v = {
|
|
120
|
-
id: i,
|
|
121
|
-
isSubmenu: e,
|
|
122
|
-
isInsideSubmenu: s,
|
|
123
|
-
isSeparator: !1,
|
|
124
|
-
callback: "callback" in t ? t.callback : null,
|
|
125
|
-
data: "data" in t ? t.data : null
|
|
126
|
-
};
|
|
127
|
-
return o.emit(p.ADD_MENU_ENTRY, v, u), u;
|
|
128
|
-
}
|
|
129
|
-
const l = `<li id="${i}" class="${r.separator}"><hr></li>`, c = y(l);
|
|
130
|
-
n.append(c);
|
|
131
|
-
const f = n.lastChild, g = {
|
|
132
|
-
id: i,
|
|
133
|
-
isSubmenu: !1,
|
|
134
|
-
isInsideSubmenu: !1,
|
|
135
|
-
isSeparator: !0,
|
|
136
|
-
callback: null,
|
|
137
|
-
data: null
|
|
138
|
-
};
|
|
139
|
-
return o.emit(p.ADD_MENU_ENTRY, g, f), f;
|
|
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);
|
|
140
177
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
emitter: o
|
|
147
|
-
}) {
|
|
148
|
-
t.forEach((i) => {
|
|
149
|
-
if (typeof i != "string" && "items" in i && Array.isArray(i.items)) {
|
|
150
|
-
const l = N({ parentNode: n, item: i, isSubmenu: !0, emitter: o });
|
|
151
|
-
l.classList.add(r.submenu);
|
|
152
|
-
const c = document.createElement("ul");
|
|
153
|
-
c.classList.add(r.container), c.style.width = `${e}px`, l.append(c), M({
|
|
154
|
-
emitter: o,
|
|
155
|
-
menuWidth: e,
|
|
156
|
-
container: c,
|
|
157
|
-
items: i.items,
|
|
158
|
-
isInsideSubmenu: !0
|
|
159
|
-
});
|
|
160
|
-
} else
|
|
161
|
-
N({
|
|
162
|
-
parentNode: n,
|
|
163
|
-
item: i,
|
|
164
|
-
isSubmenu: !1,
|
|
165
|
-
isInsideSubmenu: s,
|
|
166
|
-
emitter: o
|
|
167
|
-
});
|
|
168
|
-
});
|
|
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 + "";
|
|
169
183
|
}
|
|
170
|
-
|
|
171
|
-
|
|
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;
|
|
172
193
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
super({ element: s });
|
|
178
|
-
a(this, "map");
|
|
179
|
-
a(this, "emitter", new _());
|
|
180
|
-
a(this, "container");
|
|
181
|
-
a(this, "coordinate", []);
|
|
182
|
-
a(this, "pixel", []);
|
|
183
|
-
a(this, "contextMenuEventListener");
|
|
184
|
-
a(this, "entryCallbackEventListener");
|
|
185
|
-
a(this, "mapMoveListener");
|
|
186
|
-
a(this, "lineHeight", 0);
|
|
187
|
-
a(this, "disabled");
|
|
188
|
-
a(this, "opened");
|
|
189
|
-
a(this, "items", []);
|
|
190
|
-
a(this, "menuEntries", /* @__PURE__ */ new Map());
|
|
191
|
-
a(this, "options");
|
|
192
|
-
this.options = { ...z, ...e };
|
|
193
|
-
const o = document.createElement("ul");
|
|
194
|
-
s.append(o), s.style.width = `${this.options.width}px`, s.classList.add(
|
|
195
|
-
r.container,
|
|
196
|
-
r.unselectable,
|
|
197
|
-
r.hidden
|
|
198
|
-
), this.container = s, this.contextMenuEventListener = (i) => {
|
|
199
|
-
this.handleContextMenu(i);
|
|
200
|
-
}, this.entryCallbackEventListener = (i) => {
|
|
201
|
-
this.handleEntryCallback(i);
|
|
202
|
-
}, this.mapMoveListener = () => {
|
|
203
|
-
this.handleMapMove();
|
|
204
|
-
}, this.disabled = !1, this.opened = !1, window.addEventListener(
|
|
205
|
-
"beforeunload",
|
|
206
|
-
() => {
|
|
207
|
-
this.removeListeners();
|
|
208
|
-
},
|
|
209
|
-
{ once: !0 }
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
clear() {
|
|
213
|
-
for (const e of this.menuEntries.keys())
|
|
214
|
-
this.removeMenuEntry(e);
|
|
215
|
-
this.container.replaceChildren(), this.container.append(document.createElement("ul"));
|
|
216
|
-
}
|
|
217
|
-
enable() {
|
|
218
|
-
this.disabled = !1;
|
|
219
|
-
}
|
|
220
|
-
disable() {
|
|
221
|
-
this.disabled = !0;
|
|
222
|
-
}
|
|
223
|
-
getDefaultItems() {
|
|
224
|
-
return C;
|
|
225
|
-
}
|
|
226
|
-
countItems() {
|
|
227
|
-
return this.menuEntries.size;
|
|
228
|
-
}
|
|
229
|
-
extend(e) {
|
|
230
|
-
b(Array.isArray(e), "@param `items` should be an Array."), M({
|
|
231
|
-
items: e,
|
|
232
|
-
emitter: this.emitter,
|
|
233
|
-
menuWidth: this.options.width,
|
|
234
|
-
container: this.container.firstElementChild
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
closeMenu() {
|
|
238
|
-
this.opened = !1, this.container.classList.add(r.hidden), this.dispatchEvent(p.CLOSE);
|
|
239
|
-
}
|
|
240
|
-
isOpen() {
|
|
241
|
-
return this.opened;
|
|
242
|
-
}
|
|
243
|
-
updatePosition(e) {
|
|
244
|
-
b(Array.isArray(e), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = e, this.positionContainer());
|
|
245
|
-
}
|
|
246
|
-
pop() {
|
|
247
|
-
const e = Array.from(this.menuEntries.keys()).pop();
|
|
248
|
-
e && this.removeMenuEntry(e);
|
|
249
|
-
}
|
|
250
|
-
shift() {
|
|
251
|
-
const e = Array.from(this.menuEntries.keys()).shift();
|
|
252
|
-
e && this.removeMenuEntry(e);
|
|
253
|
-
}
|
|
254
|
-
push(e) {
|
|
255
|
-
e && this.extend([e]);
|
|
256
|
-
}
|
|
257
|
-
setMap(e) {
|
|
258
|
-
if (super.setMap(e), e) {
|
|
259
|
-
this.map = e, e.getViewport().addEventListener(
|
|
260
|
-
this.options.eventType,
|
|
261
|
-
this.contextMenuEventListener,
|
|
262
|
-
!1
|
|
263
|
-
), e.on("movestart", () => {
|
|
264
|
-
this.handleMapMove();
|
|
265
|
-
}), this.emitter.on(
|
|
266
|
-
p.ADD_MENU_ENTRY,
|
|
267
|
-
(o, i) => {
|
|
268
|
-
this.handleAddMenuEntry(o, i);
|
|
269
|
-
},
|
|
270
|
-
this
|
|
271
|
-
), this.items = this.options.defaultItems ? this.options.items.concat(C) : this.options.items, M({
|
|
272
|
-
items: this.items,
|
|
273
|
-
emitter: this.emitter,
|
|
274
|
-
menuWidth: this.options.width,
|
|
275
|
-
container: this.container.firstElementChild
|
|
276
|
-
});
|
|
277
|
-
const s = this.getMenuEntriesLength();
|
|
278
|
-
this.lineHeight = s > 0 ? this.container.offsetHeight / s : P(this.container);
|
|
279
|
-
} else
|
|
280
|
-
this.removeListeners(), this.clear();
|
|
281
|
-
}
|
|
282
|
-
removeListeners() {
|
|
283
|
-
this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.emitter.off(p.ADD_MENU_ENTRY);
|
|
284
|
-
}
|
|
285
|
-
removeMenuEntry(e) {
|
|
286
|
-
let s = document.getElementById(e);
|
|
287
|
-
s?.remove(), s = null, this.menuEntries.delete(e);
|
|
288
|
-
}
|
|
289
|
-
handleContextMenu(e) {
|
|
290
|
-
this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent(
|
|
291
|
-
new w({
|
|
292
|
-
map: this.map,
|
|
293
|
-
originalEvent: e,
|
|
294
|
-
type: p.BEFOREOPEN
|
|
295
|
-
})
|
|
296
|
-
), !this.disabled && (this.options.eventType === L.CONTEXTMENU && (e.stopPropagation(), e.preventDefault()), setTimeout(() => {
|
|
297
|
-
this.openMenu(e);
|
|
298
|
-
}), e.target?.addEventListener(
|
|
299
|
-
"pointerdown",
|
|
300
|
-
(s) => {
|
|
301
|
-
this.opened && (s.stopPropagation(), this.closeMenu());
|
|
302
|
-
},
|
|
303
|
-
{ once: !0 }
|
|
304
|
-
));
|
|
305
|
-
}
|
|
306
|
-
openMenu(e) {
|
|
307
|
-
this.opened = !0, this.positionContainer(), this.container.classList.remove(r.hidden), this.dispatchEvent(
|
|
308
|
-
new w({
|
|
309
|
-
map: this.map,
|
|
310
|
-
originalEvent: e,
|
|
311
|
-
type: p.OPEN
|
|
312
|
-
})
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
getMenuEntriesLength() {
|
|
316
|
-
return Array.from(this.menuEntries).filter(
|
|
317
|
-
([, e]) => e.isSeparator === !1 && e.isSubmenu === !1 && e.isInsideSubmenu === !1
|
|
318
|
-
).length;
|
|
319
|
-
}
|
|
320
|
-
positionContainer() {
|
|
321
|
-
const e = this.map.getSize() || [0, 0], s = {
|
|
322
|
-
w: e[0] - this.pixel[0],
|
|
323
|
-
h: e[1] - this.pixel[1]
|
|
324
|
-
}, o = this.getMenuEntriesLength(), i = {
|
|
325
|
-
w: this.container.offsetWidth,
|
|
326
|
-
// a cheap way to recalculate container height
|
|
327
|
-
// since offsetHeight is like cached
|
|
328
|
-
h: Math.round(this.lineHeight * o)
|
|
329
|
-
}, l = s.w >= i.w ? this.pixel[0] + 5 : this.pixel[0] - i.w;
|
|
330
|
-
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;
|
|
331
|
-
const c = (E) => Array.from(E.children).filter(
|
|
332
|
-
(m) => m.tagName === "LI" && m.classList.contains(r.submenu)
|
|
333
|
-
);
|
|
334
|
-
let f = 0;
|
|
335
|
-
const g = (E, m) => {
|
|
336
|
-
f += 1, c(E).forEach((v) => {
|
|
337
|
-
const A = m >= i.w ? i.w - 8 : (i.w + 8) * -1, h = v.querySelector(
|
|
338
|
-
`ul.${r.container}`
|
|
339
|
-
), $ = Math.round(
|
|
340
|
-
this.lineHeight * Array.from(h.children).filter((T) => T.tagName === "LI").length
|
|
341
|
-
);
|
|
342
|
-
h.style.left = `${A}px`, h.style.right = "auto", h.style.top = s.h >= $ + i.h ? "0" : `-${h.offsetHeight - 25}px`, h.style.bottom = "auto", h.style.zIndex = String(f), c(h).length > 0 && g(h, m - i.w);
|
|
343
|
-
});
|
|
344
|
-
};
|
|
345
|
-
g(this.container.firstElementChild, s.w);
|
|
346
|
-
}
|
|
347
|
-
handleMapMove() {
|
|
348
|
-
this.closeMenu();
|
|
349
|
-
}
|
|
350
|
-
handleEntryCallback(e) {
|
|
351
|
-
e.preventDefault(), e.stopPropagation();
|
|
352
|
-
const s = e.currentTarget, o = this.menuEntries.get(s.id);
|
|
353
|
-
if (!o) return;
|
|
354
|
-
const i = {
|
|
355
|
-
data: o.data,
|
|
356
|
-
coordinate: this.coordinate
|
|
357
|
-
};
|
|
358
|
-
this.closeMenu(), o.callback?.(i, this.map);
|
|
359
|
-
}
|
|
360
|
-
handleAddMenuEntry(e, s) {
|
|
361
|
-
this.menuEntries.set(e.id, e), this.positionContainer(), "callback" in e && typeof e.callback == "function" && s.addEventListener("click", this.entryCallbackEventListener, !1);
|
|
362
|
-
}
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/main.ts
|
|
196
|
+
function v(e, t) {
|
|
197
|
+
if (!e) throw Error(t);
|
|
363
198
|
}
|
|
364
|
-
|
|
365
|
-
|
|
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
|
+
}
|
|
366
354
|
};
|
|
355
|
+
//#endregion
|
|
356
|
+
export { y as default };
|