diff --git a/docs/ctxmenu.js b/docs/ctxmenu.js index 11842ec..52163e2 100644 --- a/docs/ctxmenu.js +++ b/docs/ctxmenu.js @@ -109,11 +109,13 @@ this.hdir = "r"; this.vdir = "d"; window.addEventListener("click", function (ev) { - var item = ev.target && ev.target.parentElement; + var item = ev.target instanceof Element && ev.target.parentElement; - if (item && item.className !== "interactive") { - _this.closeMenu(); + if (item && item.className === "interactive") { + return; } + + _this.closeMenu(); }); window.addEventListener("resize", function () { return _this.closeMenu(); diff --git a/docs/ctxmenu.min.js b/docs/ctxmenu.min.js index 4f4a462..ed23616 100644 --- a/docs/ctxmenu.min.js +++ b/docs/ctxmenu.min.js @@ -1 +1 @@ -"use strict";(function(){function b(d,e,g){function a(j,i){if(!e[j]){if(!d[j]){var f="function"==typeof require&&require;if(!i&&f)return f(j,!0);if(h)return h(j,!0);var c=new Error("Cannot find module '"+j+"'");throw c.code="MODULE_NOT_FOUND",c}var k=e[j]={exports:{}};d[j][0].call(k.exports,function(b){var c=d[j][1][b];return a(c||b)},k,k.exports,b,d,e,g)}return e[j].exports}for(var h="function"==typeof require&&require,c=0;ca.length)&&(b=a.length);for(var c=0,d=Array(b);c".concat(b.getProp(c.text),""),i=b.getProp(c.element);if(i?f.append(i):f.innerHTML=g?g:h,f.title=b.getProp(c.tooltip)||"",!b.itemIsInteractive(c))f.style.fontWeight="bold",f.style.marginLeft="-5px";else if(!!b.getProp(c.disabled))f.classList.add("disabled"),b.itemIsSubMenu(c)&&f.classList.add("submenu");else if(f.classList.add("interactive"),b.itemIsAction(c))f.addEventListener("click",function(a){c.action(a),d.closeMenu()});else if(b.itemIsAnchor(c)){var j=document.createElement("a");i?j.append(i):j.innerHTML=g?g:h,j.onclick=function(){return d.closeMenu()},j.href=b.getProp(c.href),c.hasOwnProperty("download")&&(j.download=b.getProp(c.download)),c.hasOwnProperty("target")&&(j.target=b.getProp(c.target)),f.childNodes.forEach(function(a){return a.remove()}),f.append(j)}else b.itemIsSubMenu(c)&&(0===b.getProp(c.subMenu).length?f.classList.add("disabled"):(f.classList.add("submenu"),d.debounce(f,function(a){var e=f.querySelector("ul");e||d.openSubMenu(a,b.getProp(c.subMenu),f)})));b.getProp(c.icon)&&(f.classList.add("icon"),f.innerHTML+=""))}e.appendChild(f)}),e.style.position="fixed",e.className="ctxmenu";var f=b.getBounding(e),g={x:0,y:0};if(c instanceof Element){var h=c.getBoundingClientRect();g={x:"r"===this.hdir?h.left+h.width:h.left-f.width,y:h.top+("d"===this.vdir?4:-12)};var i=this.getPosition(f,g);g.x!==i.x&&(this.hdir="r"===this.hdir?"l":"r",g.x="r"===this.hdir?h.left+h.width:h.left-f.width),g.y!==i.y&&(this.vdir="u"===this.vdir?"d":"u",g.y=i.y),g=this.getPosition(f,g)}else g=this.getPosition(f,{x:c.clientX,y:c.clientY});return e.style.left=g.x+"px",e.style.top=g.y+"px",e.addEventListener("contextmenu",function(a){a.stopPropagation(),a.preventDefault()}),e.addEventListener("click",function(a){var b=a.target&&a.target.parentElement;b&&"interactive"!==b.className&&a.stopPropagation()}),e}},{key:"openSubMenu",value:function(a,b,c){var d=c.parentElement&&c.parentElement.querySelector("li > ul");d&&d.parentElement!==c&&this.closeMenu(d),c.appendChild(this.generateDOM(b,c))}},{key:"getPosition",value:function(a,b){return{x:"r"===this.hdir?b.x+a.width>window.innerWidth?window.innerWidth-a.width:b.x:0>b.x?0:b.x,y:"d"===this.vdir?b.y+a.height>window.innerHeight?window.innerHeight-a.height:b.y:0>b.y?0:b.y}}}],[{key:"getInstance",value:function(){return b.instance||(b.instance=new b),b.instance}},{key:"getBounding",value:function(a){var b=a.cloneNode(!0);b.style.visibility="hidden",document.body.appendChild(b);var c=b.getBoundingClientRect();return document.body.removeChild(b),c}},{key:"getProp",value:function(a){return"function"==typeof a?a():a}},{key:"itemIsInteractive",value:function(a){return this.itemIsAction(a)||this.itemIsAnchor(a)||this.itemIsSubMenu(a)||this.itemIsCustom(a)}},{key:"itemIsAction",value:function(a){return a.hasOwnProperty("action")}},{key:"itemIsAnchor",value:function(a){return a.hasOwnProperty("href")}},{key:"itemIsDivider",value:function(a){return a.hasOwnProperty("isDivider")}},{key:"itemIsSubMenu",value:function(a){return a.hasOwnProperty("subMenu")}},{key:"itemIsCustom",value:function(a){return a.hasOwnProperty("html")||a.hasOwnProperty("element")}},{key:"addStylesToDom",value:function(){var a=function(){var b=Object.entries({".ctxmenu":{border:"1px solid #999",padding:"2px 0",boxShadow:"3px 3px 3px #aaa",background:"#fff",margin:"0",fontSize:"15px",fontFamily:"Verdana, sans-serif",zIndex:"9999"},".ctxmenu li":{margin:"1px 0",display:"block",position:"relative"},".ctxmenu li span":{display:"block",padding:"2px 20px",cursor:"default"},".ctxmenu li a":{color:"inherit",textDecoration:"none"},".ctxmenu li.icon":{paddingLeft:"15px"},".ctxmenu img.icon":{position:"absolute",width:"18px",left:"10px",top:"2px"},".ctxmenu li.disabled":{color:"#ccc"},".ctxmenu li.divider":{borderBottom:"1px solid #aaa",margin:"5px 0"},".ctxmenu li.interactive:hover":{background:"rgba(0,0,0,0.1)"},".ctxmenu li.submenu::after":{content:"''",position:"absolute",display:"block",top:"0",bottom:"0",right:"0.4em",margin:"auto",borderRight:"1px solid #000",borderTop:"1px solid #000",transform:"rotate(45deg)",width:"0.3rem",height:"0.3rem",marginRight:"0.1rem"},".ctxmenu li.submenu.disabled::after":{borderColor:"#ccc"}}).map(function(a){return"".concat(a[0]," { ").concat(Object.assign(document.createElement("p").style,a[1]).cssText," }")}),c=document.head.insertBefore(document.createElement("style"),document.head.childNodes[0]);b.forEach(function(a){var b;return null===(b=c.sheet)||void 0===b?void 0:b.insertRule(a)}),a=function(){}};"loading"===document.readyState?document.addEventListener("readystatechange",function(){"loading"!==document.readyState&&a()}):a()}}]),b}();c.ctxmenu=m.getInstance()},{}],2:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0});var d=a("./ctxmenu");window.ctxmenu=d.ctxmenu},{"./ctxmenu":1}]},{},[2]); +"use strict";(function(){function b(d,e,g){function a(j,i){if(!e[j]){if(!d[j]){var f="function"==typeof require&&require;if(!i&&f)return f(j,!0);if(h)return h(j,!0);var c=new Error("Cannot find module '"+j+"'");throw c.code="MODULE_NOT_FOUND",c}var k=e[j]={exports:{}};d[j][0].call(k.exports,function(b){var c=d[j][1][b];return a(c||b)},k,k.exports,b,d,e,g)}return e[j].exports}for(var h="function"==typeof require&&require,c=0;ca.length)&&(b=a.length);for(var c=0,d=Array(b);c".concat(b.getProp(c.text),""),i=b.getProp(c.element);if(i?f.append(i):f.innerHTML=g?g:h,f.title=b.getProp(c.tooltip)||"",!b.itemIsInteractive(c))f.style.fontWeight="bold",f.style.marginLeft="-5px";else if(!!b.getProp(c.disabled))f.classList.add("disabled"),b.itemIsSubMenu(c)&&f.classList.add("submenu");else if(f.classList.add("interactive"),b.itemIsAction(c))f.addEventListener("click",function(a){c.action(a),d.closeMenu()});else if(b.itemIsAnchor(c)){var j=document.createElement("a");i?j.append(i):j.innerHTML=g?g:h,j.onclick=function(){return d.closeMenu()},j.href=b.getProp(c.href),c.hasOwnProperty("download")&&(j.download=b.getProp(c.download)),c.hasOwnProperty("target")&&(j.target=b.getProp(c.target)),f.childNodes.forEach(function(a){return a.remove()}),f.append(j)}else b.itemIsSubMenu(c)&&(0===b.getProp(c.subMenu).length?f.classList.add("disabled"):(f.classList.add("submenu"),d.debounce(f,function(a){var e=f.querySelector("ul");e||d.openSubMenu(a,b.getProp(c.subMenu),f)})));b.getProp(c.icon)&&(f.classList.add("icon"),f.innerHTML+=""))}e.appendChild(f)}),e.style.position="fixed",e.className="ctxmenu";var f=b.getBounding(e),g={x:0,y:0};if(c instanceof Element){var h=c.getBoundingClientRect();g={x:"r"===this.hdir?h.left+h.width:h.left-f.width,y:h.top+("d"===this.vdir?4:-12)};var i=this.getPosition(f,g);g.x!==i.x&&(this.hdir="r"===this.hdir?"l":"r",g.x="r"===this.hdir?h.left+h.width:h.left-f.width),g.y!==i.y&&(this.vdir="u"===this.vdir?"d":"u",g.y=i.y),g=this.getPosition(f,g)}else g=this.getPosition(f,{x:c.clientX,y:c.clientY});return e.style.left=g.x+"px",e.style.top=g.y+"px",e.addEventListener("contextmenu",function(a){a.stopPropagation(),a.preventDefault()}),e.addEventListener("click",function(a){var b=a.target&&a.target.parentElement;b&&"interactive"!==b.className&&a.stopPropagation()}),e}},{key:"openSubMenu",value:function(a,b,c){var d=c.parentElement&&c.parentElement.querySelector("li > ul");d&&d.parentElement!==c&&this.closeMenu(d),c.appendChild(this.generateDOM(b,c))}},{key:"getPosition",value:function(a,b){return{x:"r"===this.hdir?b.x+a.width>window.innerWidth?window.innerWidth-a.width:b.x:0>b.x?0:b.x,y:"d"===this.vdir?b.y+a.height>window.innerHeight?window.innerHeight-a.height:b.y:0>b.y?0:b.y}}}],[{key:"getInstance",value:function(){return b.instance||(b.instance=new b),b.instance}},{key:"getBounding",value:function(a){var b=a.cloneNode(!0);b.style.visibility="hidden",document.body.appendChild(b);var c=b.getBoundingClientRect();return document.body.removeChild(b),c}},{key:"getProp",value:function(a){return"function"==typeof a?a():a}},{key:"itemIsInteractive",value:function(a){return this.itemIsAction(a)||this.itemIsAnchor(a)||this.itemIsSubMenu(a)||this.itemIsCustom(a)}},{key:"itemIsAction",value:function(a){return a.hasOwnProperty("action")}},{key:"itemIsAnchor",value:function(a){return a.hasOwnProperty("href")}},{key:"itemIsDivider",value:function(a){return a.hasOwnProperty("isDivider")}},{key:"itemIsSubMenu",value:function(a){return a.hasOwnProperty("subMenu")}},{key:"itemIsCustom",value:function(a){return a.hasOwnProperty("html")||a.hasOwnProperty("element")}},{key:"addStylesToDom",value:function(){var a=function(){var b=Object.entries({".ctxmenu":{border:"1px solid #999",padding:"2px 0",boxShadow:"3px 3px 3px #aaa",background:"#fff",margin:"0",fontSize:"15px",fontFamily:"Verdana, sans-serif",zIndex:"9999"},".ctxmenu li":{margin:"1px 0",display:"block",position:"relative"},".ctxmenu li span":{display:"block",padding:"2px 20px",cursor:"default"},".ctxmenu li a":{color:"inherit",textDecoration:"none"},".ctxmenu li.icon":{paddingLeft:"15px"},".ctxmenu img.icon":{position:"absolute",width:"18px",left:"10px",top:"2px"},".ctxmenu li.disabled":{color:"#ccc"},".ctxmenu li.divider":{borderBottom:"1px solid #aaa",margin:"5px 0"},".ctxmenu li.interactive:hover":{background:"rgba(0,0,0,0.1)"},".ctxmenu li.submenu::after":{content:"''",position:"absolute",display:"block",top:"0",bottom:"0",right:"0.4em",margin:"auto",borderRight:"1px solid #000",borderTop:"1px solid #000",transform:"rotate(45deg)",width:"0.3rem",height:"0.3rem",marginRight:"0.1rem"},".ctxmenu li.submenu.disabled::after":{borderColor:"#ccc"}}).map(function(a){return"".concat(a[0]," { ").concat(Object.assign(document.createElement("p").style,a[1]).cssText," }")}),c=document.head.insertBefore(document.createElement("style"),document.head.childNodes[0]);b.forEach(function(a){var b;return null===(b=c.sheet)||void 0===b?void 0:b.insertRule(a)}),a=function(){}};"loading"===document.readyState?document.addEventListener("readystatechange",function(){"loading"!==document.readyState&&a()}):a()}}]),b}();c.ctxmenu=m.getInstance()},{}],2:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0});var d=a("./ctxmenu");window.ctxmenu=d.ctxmenu},{"./ctxmenu":1}]},{},[2]); diff --git a/index.js b/index.js index b21913b..f7d8a0d 100644 --- a/index.js +++ b/index.js @@ -34,11 +34,13 @@ var ContextMenu = /*#__PURE__*/function () { this.hdir = "r"; this.vdir = "d"; window.addEventListener("click", function (ev) { - var item = ev.target && ev.target.parentElement; + var item = ev.target instanceof Element && ev.target.parentElement; - if (item && item.className !== "interactive") { - _this.closeMenu(); + if (item && item.className === "interactive") { + return; } + + _this.closeMenu(); }); window.addEventListener("resize", function () { return _this.closeMenu(); diff --git a/src/ctxmenu.ts b/src/ctxmenu.ts index 081090f..eaaec00 100644 --- a/src/ctxmenu.ts +++ b/src/ctxmenu.ts @@ -124,10 +124,11 @@ class ContextMenu implements CTXMenuSingleton { private vdir: "u" | "d" = "d"; private constructor() { window.addEventListener("click", ev => { - const item = ev.target && (ev.target as Element).parentElement; - if (item && item.className !== "interactive") { - this.closeMenu(); + const item = ev.target instanceof Element && ev.target.parentElement; + if (item && item.className === "interactive") { + return; } + this.closeMenu(); }); window.addEventListener("resize", () => this.closeMenu()); window.addEventListener("scroll", () => this.closeMenu()); @@ -340,7 +341,7 @@ class ContextMenu implements CTXMenuSingleton { ev.preventDefault(); }); container.addEventListener("click", ev => { - const item = ev.target && (ev.target as Element).parentElement; + const item = ev.target instanceof Element && ev.target.parentElement; if (item && item.className !== "interactive") { ev.stopPropagation(); } diff --git a/standalone/ctxmenu.js b/standalone/ctxmenu.js index 82ae2e8..272cd6c 100644 --- a/standalone/ctxmenu.js +++ b/standalone/ctxmenu.js @@ -35,11 +35,13 @@ var ContextMenu = /*#__PURE__*/function () { this.hdir = "r"; this.vdir = "d"; window.addEventListener("click", function (ev) { - var item = ev.target && ev.target.parentElement; + var item = ev.target instanceof Element && ev.target.parentElement; - if (item && item.className !== "interactive") { - _this.closeMenu(); + if (item && item.className === "interactive") { + return; } + + _this.closeMenu(); }); window.addEventListener("resize", function () { return _this.closeMenu(); diff --git a/standalone/ctxmenu.min.js b/standalone/ctxmenu.min.js index 4f4a462..ed23616 100644 --- a/standalone/ctxmenu.min.js +++ b/standalone/ctxmenu.min.js @@ -1 +1 @@ -"use strict";(function(){function b(d,e,g){function a(j,i){if(!e[j]){if(!d[j]){var f="function"==typeof require&&require;if(!i&&f)return f(j,!0);if(h)return h(j,!0);var c=new Error("Cannot find module '"+j+"'");throw c.code="MODULE_NOT_FOUND",c}var k=e[j]={exports:{}};d[j][0].call(k.exports,function(b){var c=d[j][1][b];return a(c||b)},k,k.exports,b,d,e,g)}return e[j].exports}for(var h="function"==typeof require&&require,c=0;ca.length)&&(b=a.length);for(var c=0,d=Array(b);c".concat(b.getProp(c.text),""),i=b.getProp(c.element);if(i?f.append(i):f.innerHTML=g?g:h,f.title=b.getProp(c.tooltip)||"",!b.itemIsInteractive(c))f.style.fontWeight="bold",f.style.marginLeft="-5px";else if(!!b.getProp(c.disabled))f.classList.add("disabled"),b.itemIsSubMenu(c)&&f.classList.add("submenu");else if(f.classList.add("interactive"),b.itemIsAction(c))f.addEventListener("click",function(a){c.action(a),d.closeMenu()});else if(b.itemIsAnchor(c)){var j=document.createElement("a");i?j.append(i):j.innerHTML=g?g:h,j.onclick=function(){return d.closeMenu()},j.href=b.getProp(c.href),c.hasOwnProperty("download")&&(j.download=b.getProp(c.download)),c.hasOwnProperty("target")&&(j.target=b.getProp(c.target)),f.childNodes.forEach(function(a){return a.remove()}),f.append(j)}else b.itemIsSubMenu(c)&&(0===b.getProp(c.subMenu).length?f.classList.add("disabled"):(f.classList.add("submenu"),d.debounce(f,function(a){var e=f.querySelector("ul");e||d.openSubMenu(a,b.getProp(c.subMenu),f)})));b.getProp(c.icon)&&(f.classList.add("icon"),f.innerHTML+=""))}e.appendChild(f)}),e.style.position="fixed",e.className="ctxmenu";var f=b.getBounding(e),g={x:0,y:0};if(c instanceof Element){var h=c.getBoundingClientRect();g={x:"r"===this.hdir?h.left+h.width:h.left-f.width,y:h.top+("d"===this.vdir?4:-12)};var i=this.getPosition(f,g);g.x!==i.x&&(this.hdir="r"===this.hdir?"l":"r",g.x="r"===this.hdir?h.left+h.width:h.left-f.width),g.y!==i.y&&(this.vdir="u"===this.vdir?"d":"u",g.y=i.y),g=this.getPosition(f,g)}else g=this.getPosition(f,{x:c.clientX,y:c.clientY});return e.style.left=g.x+"px",e.style.top=g.y+"px",e.addEventListener("contextmenu",function(a){a.stopPropagation(),a.preventDefault()}),e.addEventListener("click",function(a){var b=a.target&&a.target.parentElement;b&&"interactive"!==b.className&&a.stopPropagation()}),e}},{key:"openSubMenu",value:function(a,b,c){var d=c.parentElement&&c.parentElement.querySelector("li > ul");d&&d.parentElement!==c&&this.closeMenu(d),c.appendChild(this.generateDOM(b,c))}},{key:"getPosition",value:function(a,b){return{x:"r"===this.hdir?b.x+a.width>window.innerWidth?window.innerWidth-a.width:b.x:0>b.x?0:b.x,y:"d"===this.vdir?b.y+a.height>window.innerHeight?window.innerHeight-a.height:b.y:0>b.y?0:b.y}}}],[{key:"getInstance",value:function(){return b.instance||(b.instance=new b),b.instance}},{key:"getBounding",value:function(a){var b=a.cloneNode(!0);b.style.visibility="hidden",document.body.appendChild(b);var c=b.getBoundingClientRect();return document.body.removeChild(b),c}},{key:"getProp",value:function(a){return"function"==typeof a?a():a}},{key:"itemIsInteractive",value:function(a){return this.itemIsAction(a)||this.itemIsAnchor(a)||this.itemIsSubMenu(a)||this.itemIsCustom(a)}},{key:"itemIsAction",value:function(a){return a.hasOwnProperty("action")}},{key:"itemIsAnchor",value:function(a){return a.hasOwnProperty("href")}},{key:"itemIsDivider",value:function(a){return a.hasOwnProperty("isDivider")}},{key:"itemIsSubMenu",value:function(a){return a.hasOwnProperty("subMenu")}},{key:"itemIsCustom",value:function(a){return a.hasOwnProperty("html")||a.hasOwnProperty("element")}},{key:"addStylesToDom",value:function(){var a=function(){var b=Object.entries({".ctxmenu":{border:"1px solid #999",padding:"2px 0",boxShadow:"3px 3px 3px #aaa",background:"#fff",margin:"0",fontSize:"15px",fontFamily:"Verdana, sans-serif",zIndex:"9999"},".ctxmenu li":{margin:"1px 0",display:"block",position:"relative"},".ctxmenu li span":{display:"block",padding:"2px 20px",cursor:"default"},".ctxmenu li a":{color:"inherit",textDecoration:"none"},".ctxmenu li.icon":{paddingLeft:"15px"},".ctxmenu img.icon":{position:"absolute",width:"18px",left:"10px",top:"2px"},".ctxmenu li.disabled":{color:"#ccc"},".ctxmenu li.divider":{borderBottom:"1px solid #aaa",margin:"5px 0"},".ctxmenu li.interactive:hover":{background:"rgba(0,0,0,0.1)"},".ctxmenu li.submenu::after":{content:"''",position:"absolute",display:"block",top:"0",bottom:"0",right:"0.4em",margin:"auto",borderRight:"1px solid #000",borderTop:"1px solid #000",transform:"rotate(45deg)",width:"0.3rem",height:"0.3rem",marginRight:"0.1rem"},".ctxmenu li.submenu.disabled::after":{borderColor:"#ccc"}}).map(function(a){return"".concat(a[0]," { ").concat(Object.assign(document.createElement("p").style,a[1]).cssText," }")}),c=document.head.insertBefore(document.createElement("style"),document.head.childNodes[0]);b.forEach(function(a){var b;return null===(b=c.sheet)||void 0===b?void 0:b.insertRule(a)}),a=function(){}};"loading"===document.readyState?document.addEventListener("readystatechange",function(){"loading"!==document.readyState&&a()}):a()}}]),b}();c.ctxmenu=m.getInstance()},{}],2:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0});var d=a("./ctxmenu");window.ctxmenu=d.ctxmenu},{"./ctxmenu":1}]},{},[2]); +"use strict";(function(){function b(d,e,g){function a(j,i){if(!e[j]){if(!d[j]){var f="function"==typeof require&&require;if(!i&&f)return f(j,!0);if(h)return h(j,!0);var c=new Error("Cannot find module '"+j+"'");throw c.code="MODULE_NOT_FOUND",c}var k=e[j]={exports:{}};d[j][0].call(k.exports,function(b){var c=d[j][1][b];return a(c||b)},k,k.exports,b,d,e,g)}return e[j].exports}for(var h="function"==typeof require&&require,c=0;ca.length)&&(b=a.length);for(var c=0,d=Array(b);c".concat(b.getProp(c.text),""),i=b.getProp(c.element);if(i?f.append(i):f.innerHTML=g?g:h,f.title=b.getProp(c.tooltip)||"",!b.itemIsInteractive(c))f.style.fontWeight="bold",f.style.marginLeft="-5px";else if(!!b.getProp(c.disabled))f.classList.add("disabled"),b.itemIsSubMenu(c)&&f.classList.add("submenu");else if(f.classList.add("interactive"),b.itemIsAction(c))f.addEventListener("click",function(a){c.action(a),d.closeMenu()});else if(b.itemIsAnchor(c)){var j=document.createElement("a");i?j.append(i):j.innerHTML=g?g:h,j.onclick=function(){return d.closeMenu()},j.href=b.getProp(c.href),c.hasOwnProperty("download")&&(j.download=b.getProp(c.download)),c.hasOwnProperty("target")&&(j.target=b.getProp(c.target)),f.childNodes.forEach(function(a){return a.remove()}),f.append(j)}else b.itemIsSubMenu(c)&&(0===b.getProp(c.subMenu).length?f.classList.add("disabled"):(f.classList.add("submenu"),d.debounce(f,function(a){var e=f.querySelector("ul");e||d.openSubMenu(a,b.getProp(c.subMenu),f)})));b.getProp(c.icon)&&(f.classList.add("icon"),f.innerHTML+=""))}e.appendChild(f)}),e.style.position="fixed",e.className="ctxmenu";var f=b.getBounding(e),g={x:0,y:0};if(c instanceof Element){var h=c.getBoundingClientRect();g={x:"r"===this.hdir?h.left+h.width:h.left-f.width,y:h.top+("d"===this.vdir?4:-12)};var i=this.getPosition(f,g);g.x!==i.x&&(this.hdir="r"===this.hdir?"l":"r",g.x="r"===this.hdir?h.left+h.width:h.left-f.width),g.y!==i.y&&(this.vdir="u"===this.vdir?"d":"u",g.y=i.y),g=this.getPosition(f,g)}else g=this.getPosition(f,{x:c.clientX,y:c.clientY});return e.style.left=g.x+"px",e.style.top=g.y+"px",e.addEventListener("contextmenu",function(a){a.stopPropagation(),a.preventDefault()}),e.addEventListener("click",function(a){var b=a.target&&a.target.parentElement;b&&"interactive"!==b.className&&a.stopPropagation()}),e}},{key:"openSubMenu",value:function(a,b,c){var d=c.parentElement&&c.parentElement.querySelector("li > ul");d&&d.parentElement!==c&&this.closeMenu(d),c.appendChild(this.generateDOM(b,c))}},{key:"getPosition",value:function(a,b){return{x:"r"===this.hdir?b.x+a.width>window.innerWidth?window.innerWidth-a.width:b.x:0>b.x?0:b.x,y:"d"===this.vdir?b.y+a.height>window.innerHeight?window.innerHeight-a.height:b.y:0>b.y?0:b.y}}}],[{key:"getInstance",value:function(){return b.instance||(b.instance=new b),b.instance}},{key:"getBounding",value:function(a){var b=a.cloneNode(!0);b.style.visibility="hidden",document.body.appendChild(b);var c=b.getBoundingClientRect();return document.body.removeChild(b),c}},{key:"getProp",value:function(a){return"function"==typeof a?a():a}},{key:"itemIsInteractive",value:function(a){return this.itemIsAction(a)||this.itemIsAnchor(a)||this.itemIsSubMenu(a)||this.itemIsCustom(a)}},{key:"itemIsAction",value:function(a){return a.hasOwnProperty("action")}},{key:"itemIsAnchor",value:function(a){return a.hasOwnProperty("href")}},{key:"itemIsDivider",value:function(a){return a.hasOwnProperty("isDivider")}},{key:"itemIsSubMenu",value:function(a){return a.hasOwnProperty("subMenu")}},{key:"itemIsCustom",value:function(a){return a.hasOwnProperty("html")||a.hasOwnProperty("element")}},{key:"addStylesToDom",value:function(){var a=function(){var b=Object.entries({".ctxmenu":{border:"1px solid #999",padding:"2px 0",boxShadow:"3px 3px 3px #aaa",background:"#fff",margin:"0",fontSize:"15px",fontFamily:"Verdana, sans-serif",zIndex:"9999"},".ctxmenu li":{margin:"1px 0",display:"block",position:"relative"},".ctxmenu li span":{display:"block",padding:"2px 20px",cursor:"default"},".ctxmenu li a":{color:"inherit",textDecoration:"none"},".ctxmenu li.icon":{paddingLeft:"15px"},".ctxmenu img.icon":{position:"absolute",width:"18px",left:"10px",top:"2px"},".ctxmenu li.disabled":{color:"#ccc"},".ctxmenu li.divider":{borderBottom:"1px solid #aaa",margin:"5px 0"},".ctxmenu li.interactive:hover":{background:"rgba(0,0,0,0.1)"},".ctxmenu li.submenu::after":{content:"''",position:"absolute",display:"block",top:"0",bottom:"0",right:"0.4em",margin:"auto",borderRight:"1px solid #000",borderTop:"1px solid #000",transform:"rotate(45deg)",width:"0.3rem",height:"0.3rem",marginRight:"0.1rem"},".ctxmenu li.submenu.disabled::after":{borderColor:"#ccc"}}).map(function(a){return"".concat(a[0]," { ").concat(Object.assign(document.createElement("p").style,a[1]).cssText," }")}),c=document.head.insertBefore(document.createElement("style"),document.head.childNodes[0]);b.forEach(function(a){var b;return null===(b=c.sheet)||void 0===b?void 0:b.insertRule(a)}),a=function(){}};"loading"===document.readyState?document.addEventListener("readystatechange",function(){"loading"!==document.readyState&&a()}):a()}}]),b}();c.ctxmenu=m.getInstance()},{}],2:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0});var d=a("./ctxmenu");window.ctxmenu=d.ctxmenu},{"./ctxmenu":1}]},{},[2]);