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