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.
@@ -1,205 +1,207 @@
1
1
 
2
2
  /*!
3
- * ol-contextmenu - v5.4.0
3
+ * ol-contextmenu - v6.0.0
4
4
  * https://github.com/jonataswalker/ol-contextmenu
5
- * Built: Fri Mar 08 2024 12:11:47 GMT+0000 (Coordinated Universal Time)
5
+ * Built: 2026-01-05T22:44:21.378Z
6
6
  */
7
7
 
8
- var k = Object.defineProperty;
9
- var I = (n, t, e) => t in n ? k(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
10
- var a = (n, t, e) => (I(n, typeof t != "symbol" ? t + "" : t, e), e);
11
- import O from "ol/control/Control";
12
- import D from "ol/MapBrowserEvent";
13
- var S = { exports: {} };
14
- function x() {
15
- }
16
- x.prototype = {
17
- on: function(n, t, e) {
18
- var s = this.e || (this.e = {});
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
- S.exports = x;
46
- var _ = S.exports.TinyEmitter = x, L = /* @__PURE__ */ ((n) => (n.CONTEXTMENU = "contextmenu", n.CLICK = "click", n.DBLCLICK = "dblclick", n))(L || {}), p = /* @__PURE__ */ ((n) => (n.BEFOREOPEN = "beforeopen", n.OPEN = "open", n.CLOSE = "close", n.ADD_MENU_ENTRY = "add-menu-entry", n))(p || {});
47
- class w extends D {
48
- constructor(t) {
49
- super(t.type, t.map, t.originalEvent);
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 z = {
53
- width: 150,
54
- scrollAt: 4,
55
- eventType: L.CONTEXTMENU,
56
+ const U = {
56
57
  defaultItems: !0,
57
- items: []
58
- }, d = "ol-ctx-menu", r = {
59
- namespace: d,
60
- container: `${d}-container`,
61
- separator: `${d}-separator`,
62
- submenu: `${d}-submenu`,
63
- hidden: `${d}-hidden`,
64
- icon: `${d}-icon`,
65
- zoomIn: `${d}-zoom-in`,
66
- zoomOut: `${d}-zoom-out`,
67
- unselectable: "ol-unselectable"
68
- }, C = [
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
- text: "Zoom In",
71
- classname: `${r.zoomIn} ${r.icon}`,
72
- callback: (n, t) => {
73
- const e = t.getView();
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
- center: n.coordinate
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
- 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,
85
+ callback: (o, i) => {
86
+ const t = i.getView();
87
+ t.animate({
88
+ center: o.coordinate,
88
89
  duration: 700,
89
- center: n.coordinate
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 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;
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 P(n) {
101
- const t = document.importNode(n), e = n.offsetWidth;
102
- t.style.cssText = `position: fixed; top: 0; left: 0; overflow: auto; visibility: hidden; pointer-events: none; height: unset; max-height: unset; width: ${e}px`;
103
- const s = y("<span>Foo</span>"), o = y("<span>Foo</span>"), i = document.createElement("li"), l = document.createElement("li");
104
- i.append(s), l.append(o), t.append(i), t.append(l), n.parentNode?.append(t);
105
- const c = t.offsetHeight / 2;
106
- return n.parentNode?.removeChild(t), c;
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 N({
109
- parentNode: n,
110
- item: t,
111
- isSubmenu: e = !1,
112
- isInsideSubmenu: s = !1,
113
- emitter: o
111
+ function T({
112
+ emitter: o,
113
+ isInsideSubmenu: i = !1,
114
+ isSubmenu: t = !1,
115
+ item: e,
116
+ parentNode: s
114
117
  }) {
115
- const i = `_${Math.random().toString(36).slice(2, 11)}`;
116
- if (typeof t != "string" && "text" in t) {
117
- const E = `<span>${t.text}</span>`, m = y(E), u = document.createElement("li");
118
- t.classname = t.classname || "", t.icon && (t.classname === "" ? t.classname = r.icon : t.classname.includes(r.icon) === !1 && (t.classname += ` ${r.icon}`), u.setAttribute("style", `background-image:url(${t.icon})`)), u.id = i, u.className = t.classname, u.append(m), n.append(u);
119
- const v = {
120
- id: i,
121
- isSubmenu: e,
122
- isInsideSubmenu: s,
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
- callback: "callback" in t ? t.callback : null,
125
- data: "data" in t ? t.data : null
128
+ isSubmenu: t
126
129
  };
127
- return o.emit(p.ADD_MENU_ENTRY, v, u), u;
130
+ return o.emit(d.ADD_MENU_ENTRY, N, l), l;
128
131
  }
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,
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
- callback: null,
137
- data: null
140
+ isSubmenu: !1
138
141
  };
139
- return o.emit(p.ADD_MENU_ENTRY, g, f), f;
142
+ return o.emit(d.ADD_MENU_ENTRY, E, m), m;
140
143
  }
141
- function M({
142
- container: n,
143
- items: t,
144
- menuWidth: e,
145
- isInsideSubmenu: s,
146
- emitter: o
144
+ function x({
145
+ container: o,
146
+ emitter: i,
147
+ isInsideSubmenu: t,
148
+ items: e,
149
+ menuWidth: s
147
150
  }) {
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
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
- N({
162
- parentNode: n,
163
- item: i,
164
+ T({
165
+ emitter: i,
166
+ isInsideSubmenu: t,
164
167
  isSubmenu: !1,
165
- isInsideSubmenu: s,
166
- emitter: o
168
+ item: n,
169
+ parentNode: o
167
170
  });
168
171
  });
169
172
  }
170
- function b(n, t) {
171
- if (!n)
172
- throw new Error(t);
173
+ function b(o, i) {
174
+ if (!o) throw new Error(i);
173
175
  }
174
- class R extends O {
175
- constructor(e = {}) {
176
- b(typeof e == "object", "@param `opts` should be object type!");
177
- const s = document.createElement("div");
178
- super({ element: s });
179
- a(this, "map");
180
- a(this, "emitter", new _());
181
- a(this, "container");
182
- a(this, "coordinate", []);
183
- a(this, "pixel", []);
184
- a(this, "contextMenuEventListener");
185
- a(this, "entryCallbackEventListener");
186
- a(this, "mapMoveListener");
187
- a(this, "lineHeight", 0);
188
- a(this, "disabled");
189
- a(this, "opened");
190
- a(this, "items", []);
191
- a(this, "menuEntries", /* @__PURE__ */ new Map());
192
- a(this, "options");
193
- this.options = { ...z, ...e };
194
- const o = document.createElement("ul");
195
- s.append(o), s.style.width = `${this.options.width}px`, s.classList.add(
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 = s, this.contextMenuEventListener = (i) => {
200
- this.handleContextMenu(i);
201
- }, this.entryCallbackEventListener = (i) => {
202
- this.handleEntryCallback(i);
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 e of this.menuEntries.keys())
215
- this.removeMenuEntry(e);
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(e) {
231
- b(Array.isArray(e), "@param `items` should be an Array."), M({
232
- items: e,
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
- menuWidth: this.options.width,
235
- container: this.container.firstElementChild
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(p.CLOSE);
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(e) {
245
- b(Array.isArray(e), "@param `pixel` should be an Array."), this.isOpen() && (this.pixel = e, this.positionContainer());
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 e = Array.from(this.menuEntries.keys()).pop();
249
- e && this.removeMenuEntry(e);
250
+ const t = Array.from(this.menuEntries.keys()).pop();
251
+ t && this.removeMenuEntry(t);
250
252
  }
251
253
  shift() {
252
- const e = Array.from(this.menuEntries.keys()).shift();
253
- e && this.removeMenuEntry(e);
254
+ const t = Array.from(this.menuEntries.keys()).shift();
255
+ t && this.removeMenuEntry(t);
254
256
  }
255
- push(e) {
256
- e && this.extend([e]);
257
+ push(t) {
258
+ t && this.extend([t]);
257
259
  }
258
- setMap(e) {
259
- if (super.setMap(e), e) {
260
- this.map = e, e.getViewport().addEventListener(
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
- ), e.on("movestart", () => {
266
+ ), t.on("movestart", () => {
265
267
  this.handleMapMove();
266
268
  }), this.emitter.on(
267
- p.ADD_MENU_ENTRY,
268
- (o, i) => {
269
- this.handleAddMenuEntry(o, i);
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, M({
273
- items: this.items,
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
- menuWidth: this.options.width,
276
- container: this.container.firstElementChild
277
+ items: this.items,
278
+ menuWidth: this.options.width
277
279
  });
278
- const s = this.getMenuEntriesLength();
279
- this.lineHeight = s > 0 ? this.container.offsetHeight / s : P(this.container);
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(p.ADD_MENU_ENTRY);
286
+ this.map.getViewport().removeEventListener(this.options.eventType, this.contextMenuEventListener, !1), this.emitter.off(d.ADD_MENU_ENTRY);
285
287
  }
286
- removeMenuEntry(e) {
287
- let s = document.getElementById(e);
288
- s?.remove(), s = null, this.menuEntries.delete(e);
288
+ removeMenuEntry(t) {
289
+ let e = document.getElementById(t);
290
+ e?.remove(), e = null, this.menuEntries.delete(t);
289
291
  }
290
- handleContextMenu(e) {
291
- this.coordinate = this.map.getEventCoordinate(e), this.pixel = this.map.getEventPixel(e), this.dispatchEvent(
292
- new w({
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: e,
295
- type: p.BEFOREOPEN
296
+ originalEvent: t,
297
+ type: d.BEFOREOPEN
296
298
  })
297
- ), !this.disabled && (this.options.eventType === L.CONTEXTMENU && (e.stopPropagation(), e.preventDefault()), setTimeout(() => {
298
- this.openMenu(e);
299
- }), e.target?.addEventListener(
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
- (s) => {
302
- this.opened && (s.stopPropagation(), this.closeMenu());
303
+ (e) => {
304
+ this.opened && (e.stopPropagation(), this.closeMenu());
303
305
  },
304
306
  { once: !0 }
305
307
  ));
306
308
  }
307
- openMenu(e) {
309
+ openMenu(t) {
308
310
  this.opened = !0, this.positionContainer(), this.container.classList.remove(r.hidden), this.dispatchEvent(
309
- new w({
311
+ new A({
310
312
  map: this.map,
311
- originalEvent: e,
312
- type: p.OPEN
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
- ([, e]) => e.isSeparator === !1 && e.isSubmenu === !1 && e.isInsideSubmenu === !1
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 e = this.map.getSize() || [0, 0], s = {
323
- w: e[0] - this.pixel[0],
324
- h: e[1] - this.pixel[1]
325
- }, o = this.getMenuEntriesLength(), i = {
326
- w: this.container.offsetWidth,
327
- // a cheap way to recalculate container height
328
- // since offsetHeight is like cached
329
- h: Math.round(this.lineHeight * o)
330
- }, l = s.w >= i.w ? this.pixel[0] + 5 : this.pixel[0] - i.w;
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 f = 0;
336
- const g = (E, m) => {
337
- f += 1, c(E).forEach((v) => {
338
- const A = m >= i.w ? i.w - 8 : (i.w + 8) * -1, h = v.querySelector(
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(h.children).filter((T) => T.tagName === "LI").length
357
+ this.lineHeight * Array.from(u.children).filter((_) => _.tagName === "LI").length
342
358
  );
343
- 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);
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(e) {
352
- e.preventDefault(), e.stopPropagation();
353
- const s = e.currentTarget, o = this.menuEntries.get(s.id);
354
- if (!o)
355
- return;
356
- const i = {
357
- data: o.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(), o.callback?.(i, this.map);
375
+ this.closeMenu(), s.callback?.(n, this.map);
361
376
  }
362
- handleAddMenuEntry(e, s) {
363
- this.menuEntries.set(e.id, e), this.positionContainer(), "callback" in e && typeof e.callback == "function" && s.addEventListener("click", this.entryCallbackEventListener, !1);
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
- R as default
382
+ X as default
368
383
  };