-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.min.js
2 lines (2 loc) · 7.84 KB
/
index.min.js
1
2
"use strict";function n(n){return"function"==typeof n?n():n}function t(n){return!r(n)&&(e(n)||i(n)||u(n))}function e(n){return n.hasOwnProperty("action")}function i(n){return n.hasOwnProperty("href")}function o(n){return n.hasOwnProperty("isDivider")}function u(n){return n.hasOwnProperty("subMenu")}function r(n){return n.hasOwnProperty("html")||n.hasOwnProperty("element")}function c(n){return!t(n)&&!o(n)&&!r(n)}function a(e){return t(e)&&n(e.disabled)||u(e)&&0===n(e.subMenu).length}function d(n,t){var e;n.addEventListener("mouseenter",(function(n){e=setTimeout((function(){return t(n)}),150)})),n.addEventListener("mouseleave",(function(){return clearTimeout(e)}))}function s(n){var e=document.createElement("li");return function(n,t,e){n.filter((function(n){return(0,n[0])(t)})).every((function(n){n[0];var t=n[1],i=n[2];return!void e.classList.add(t)&&i}))}([[o,"divider",!1],[function(n){return n.icon},"icon",!0],[c,"heading",!1],[u,"submenu",!0],[a,"disabled",!1],[t,"interactive",!0]],n,e),o(n)||[l,f,v,m,h].forEach((function(t){return t.call(null,n,e)})),e}function l(t,e){var i,o=t.html,u=t.text,r=n(t.element);r?e.append(r):e.innerHTML=null!==(i=n(o))&&void 0!==i?i:"<span>".concat(n(u),"</span>")}function f(t,e){var i=t.tooltip,o=t.style,u=t.attributes;e.title=n(i)||"",o&&e.setAttribute("style",n(o)),u&&Object.entries(n(u)).forEach((function(n){var t=n[0],i=n[1];e.setAttribute(t,i)}))}function v(t,e){var i=t.icon;i&&(e.innerHTML+='<img class="icon" src="'.concat(n(i),'" />'))}function m(i,o){for(var r=0,c=Object.entries(n(i.events)||{});r<c.length;r++){var d=c[r],s=d[0],l=d[1],f="function"==typeof l?{listener:l,options:{}}:l,v=f.listener,m=f.options;o.addEventListener(s,v,m)}o.addEventListener("click",(function(n){a(i)||u(i)||(e(i)&&i.action(n),t(i)&&k.hide())}))}function h(t,e){if(i(t)&&!a(t)){var o=t.href,u=t.download,r=t.target,c=document.createElement("a");c.innerHTML=e.innerHTML,c.href=n(o),void 0!==u&&(c.download=n(u)),r&&(c.target=n(r)),e.replaceChildren(c)}}Object.defineProperty(exports,"t",{value:!0});var x="r",p="d";function b(n,t){var e=y(),i=window.visualViewport,o=i.width,u=i.height;Object.assign(n.style,{maxHeight:u/e.y+"px",maxWidth:o/e.x+"px"});var r=function(n){var t=n.cloneNode(!0);t.style.visibility="hidden",document.body.appendChild(t);var e=w(t);return document.body.removeChild(t),e}(n);r.width=Math.trunc(r.width)+1,r.height=Math.trunc(r.height)+1;var c={x:0,y:0};if(t instanceof Element){var a=w(t),d=a.x,s=a.width,l=a.y;c={x:"r"===x?d+s:d-r.width,y:l},t.className.includes("submenu")&&(c.y+="d"===p?4:-12);var f=g(r,c);c.x!==f.x&&(x="r"===x?"l":"r",c.x="r"===x?d+s:d-r.width),c.y!==f.y&&(p="u"===p?"d":"u",c.y=f.y),c=g(r,c)}else{var v=""!==document.body.style.transform?document.body.getBoundingClientRect():{x:0,y:0};c=g(r,{x:(t.clientX-v.x)/e.x,y:(t.clientY-v.y)/e.y})}Object.assign(n.style,{left:c.x+"px",top:c.y+"px",width:r.width+"px",height:r.height+"px"})}function g(n,t){var e=window.visualViewport,i=e.width,o=e.height,u=""!==document.body.style.transform?document.body.getBoundingClientRect():{left:0,top:0},r=u.left,c=u.top,a=y(),d=-r/a.x,s=-c/a.y,l=(i-r)/a.x,f=(o-c)/a.y;return{x:"r"===x?t.x+n.width>l?l-n.width:t.x:t.x<d?d:t.x,y:"d"===p?t.y+n.height>f?f-n.height:t.y:t.y<s?s:t.y+n.height>f?f-n.height:t.y}}function w(n){var t=n.offsetLeft,e=n.offsetTop,i=n.offsetHeight,o=n.offsetWidth;if(n.offsetParent instanceof HTMLElement){var u=w(n.offsetParent);return{x:t+u.x,y:e+u.y,width:o,height:i}}return{x:t,y:e,width:o,height:i}}function y(){var n=document.body,t=n.getBoundingClientRect();return{x:t.width/n.offsetWidth,y:t.height/n.offsetHeight}}var k=function(){function t(){var n=this;this.cache={},this.o=!1,window.addEventListener("click",(function(){n.hide()})),window.addEventListener("resize",(function(){n.hide()}));var e=0;window.addEventListener("wheel",(function(){clearTimeout(e),e=setTimeout((function(){n.o?n.o=!1:n.hide()}))}),{passive:!0}),window.addEventListener("keydown",(function(t){"Escape"===t.key&&n.hide()})),t.u()}return t.i=function(){t.l||(t.l=new t);var n=t.l;return{attach:n.v.bind(n),delete:n.delete.bind(n),hide:n.hide.bind(n),show:n.show.bind(n),update:n.update.bind(n)}},t.prototype.v=function(n,t,e){var i=this;void 0===e&&(e={});var o=document.querySelector(n);if(void 0===this.cache[n])if(o){var u=function(n){i.show(t,n,e)};this.cache[n]={m:t,h:u,p:e},o.addEventListener("contextmenu",u)}else console.error("target element ".concat(n," not found"));else console.error("target element ".concat(n," already has a context menu assigned. Use ContextMenu.update() intstead."))},t.prototype.update=function(n,t,e){void 0===e&&(e={});var i=this.cache[n],o=Object.assign({},null==i?void 0:i.p,e),u=document.querySelector(n);i&&(null==u||u.removeEventListener("contextmenu",i.h)),delete this.cache[n],this.v(n,t||(null==i?void 0:i.m)||[],o)},t.prototype.delete=function(n){var t=this.cache[n];if(!t)return console.error("no context menu for target element ".concat(n," found"));delete this.cache[n];var e=document.querySelector(n);if(!e)return console.error("target element ".concat(n," does not exist (anymore)"));e.removeEventListener("contextmenu",t.h)},t.prototype.show=function(n,t,e){var i,o,u,r=this;void 0===e&&(e={}),t instanceof MouseEvent&&(t.stopImmediatePropagation(),t.preventDefault()),this.hide(),this.onHide=e.onHide,this.onBeforeHide=e.onBeforeHide;var c=null!==(o=null===(i=e.onBeforeShow)||void 0===i?void 0:i.call(e,n.slice(),t instanceof MouseEvent?t:void 0))&&void 0!==o?o:n;this.g=this.k(c,t,e.attributes),document.body.appendChild(this.g),null===(u=e.onShow)||void 0===u||u.call(e,this.g),this.g.addEventListener("wheel",(function(){r.o=!0}),{passive:!0})},t.prototype.hide=function(){this.M(this.g)},t.prototype.M=function(n){var t,e;null===(t=this.onBeforeHide)||void 0===t||t.call(this,n),x="r",p="d",n&&(n.remove(),null===(e=this.onHide)||void 0===e||e.call(this,n),n===this.g&&(delete this.g,this.onBeforeHide=void 0,this.onHide=void 0))},t.prototype.k=function(t,e,i){var o=this;void 0===i&&(i={});var r=function(n){var t=document.createElement("ul");t.className="ctxmenu",t.append.apply(t,n.map(s)),n.length||(t.style.display="none");var e=function(n){n.stopPropagation(),n.preventDefault()};return t.addEventListener("contextmenu",e),t.addEventListener("click",e),t}(t);return b(r,e),t.forEach((function(t,e){var i=r.children[e];d(i,(function(){var n,t=null===(n=i.parentElement)||void 0===n?void 0:n.querySelector("ul");t&&t.parentElement!==i&&o.M(t)})),a(t)||u(t)&&d(i,(function(){i.querySelector("ul")||i.appendChild(o.k(n(t.subMenu),i,n(t.subMenuAttributes)))}))})),Object.entries(i).forEach((function(n){var t=n[0],e=n[1];return r.setAttribute(t,e)})),r},t.u=function(){if("loading"===document.readyState)return document.addEventListener("readystatechange",this.u,{once:!0});var n=document.createElement("style");n.innerHTML='html{min-height:100%}.ctxmenu{position:fixed;border:1px solid #999;padding:2px 0;box-shadow:#aaa 3px 3px 3px;background:#fff;margin:0;z-index:9999;overflow-y:auto;font:15px Verdana,sans-serif;box-sizing:border-box}.ctxmenu li{margin:1px 0;display:block;position:relative;user-select:none}.ctxmenu li.heading{font-weight:bold;margin-left:-5px}.ctxmenu li span{display:block;padding:2px 20px;cursor:default}.ctxmenu li a{color:inherit;text-decoration:none}.ctxmenu li.icon{padding-left:15px}.ctxmenu img.icon{position:absolute;width:18px;left:10px;top:2px}.ctxmenu li.disabled{color:#ccc}.ctxmenu li.divider{border-bottom:1px solid #aaa;margin:5px 0}.ctxmenu li.interactive:hover{background:rgba(0,0,0,.1)}.ctxmenu li.submenu::after{content:"";position:absolute;display:block;top:0;bottom:0;right:.4em;margin:auto .1rem auto auto;border:solid #000;border-width:1px 1px 0 0;transform:rotate(45deg);width:.3rem;height:.3rem}.ctxmenu li.submenu.disabled::after{border-color:#ccc}',document.head.insertBefore(n,document.head.childNodes[0])},t}().i();
/*! ctxMenu v2.0.0 | (c) Nikolaj Kappler | https://github.com/nkappler/ctxmenu/blob/master/LICENSE !*/exports.ctxmenu=k;