simple-window-manager 2.1.2 → 2.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.
Files changed (9) hide show
  1. package/.jsdoc.json +1 -1
  2. package/package.json +14 -14
  3. package/public/simple-window-manager.es.js +352 -338
  4. package/public/simple-window-manager.es.js.map +1 -1
  5. package/public/simple-window-manager.min.js +1 -1
  6. package/public/simple-window-manager.min.js.map +1 -1
  7. package/rollup.config.js +1 -1
  8. package/src/Window.js +2 -0
  9. package/images/src/images.js/export const close = '<?xml version=/"1.0/" encoding=/"UTF-8/" standalone=/"no/"?><!DOCTYPE svg PUBLIC /"-/W3C/DTD SVG 1.1/EN/" /"http:/www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd/"><svg width=/"100%/" height=/"100%/" viewBox=/"0 0 20 20/" version=/"1.1/" xmlns=/"http:/www.w3.org/2000/svg/" xmlns:xlink=/"http:/www.w3.org/1999/xlink/" xml:space=/"preserve/" xmlns:serif=/"http:/www.serif.com//" style=/"fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;/"><rect id=/"close/" x=/"0/" y=/"0/" width=/"20/" height=/"20/" style=/"fill:none;/"/><g><path d=/"M3.5,3.5l13,13/" style=/"fill:none;stroke:#fff;stroke-width:3px;/"/><path d=/"M16.5,3.5l-13,13/" style=/"fill:none;stroke:#fff;stroke-width:3px;/"/></g></svg>';export const minimize = '<?xml version=/"1.0/" encoding=/"UTF-8/" standalone=/"no/"?><!DOCTYPE svg PUBLIC /"-/W3C/DTD SVG 1.1/EN/" /"http:/www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd/"><svg width=/"100%/" height=/"100%/" viewBox=/"0 0 20 20/" version=/"1.1/" xmlns=/"http:/www.w3.org/2000/svg/" xmlns:xlink=/"http:/www.w3.org/1999/xlink/" xml:space=/"preserve/" xmlns:serif=/"http:/www.serif.com//" style=/"fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;/"><rect id=/"minimize/" x=/"0/" y=/"0/" width=/"20/" height=/"20/" style=/"fill:none;/"/><rect x=/"2/" y=/"15.6/" width=/"16/" height=/"3.2/" style=/"fill:#fff;/"/></svg>';export const resize = '<?xml version=/"1.0/" encoding=/"UTF-8/" standalone=/"no/"?><!DOCTYPE svg PUBLIC /"-/W3C/DTD SVG 1.1/EN/" /"http:/www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd/"><svg width=/"100%/" height=/"100%/" viewBox=/"0 0 20 20/" version=/"1.1/" xmlns=/"http:/www.w3.org/2000/svg/" xmlns:xlink=/"http:/www.w3.org/1999/xlink/" xml:space=/"preserve/" xmlns:serif=/"http:/www.serif.com//" style=/"fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;/"><rect id=/"resize/" x=/"0/" y=/"0/" width=/"20/" height=/"20/" style=/"fill:none;/"/><clipPath id=/"_clip1/"><rect x=/"0/" y=/"0/" width=/"20/" height=/"20/"/></clipPath><g clip-path=/"url(#_clip1)/"><rect x=/"0/" y=/"16.8/" width=/"20/" height=/"3.2/" style=/"fill:#fff;/"/><path d=/"M17.737,3.595l-14.142,14.142l2.263,2.263l14.142,-14.142l-2.263,-2.263Z/" style=/"fill:#fff;/"/><path d=/"M16.8,0l0,20l3.2,0l0,-20l-3.2,0Z/" style=/"fill:#fff;/"/><path d=/"M7.099,18.4l11.301,-11.123l0,11.123l-11.301,0Z/" style=/"fill:#fff;/"/></g></svg>';export const restore = '<?xml version=/"1.0/" encoding=/"UTF-8/" standalone=/"no/"?><!DOCTYPE svg PUBLIC /"-/W3C/DTD SVG 1.1/EN/" /"http:/www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd/"><svg width=/"100%/" height=/"100%/" viewBox=/"0 0 20 20/" version=/"1.1/" xmlns=/"http:/www.w3.org/2000/svg/" xmlns:xlink=/"http:/www.w3.org/1999/xlink/" xml:space=/"preserve/" xmlns:serif=/"http:/www.serif.com//" style=/"fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;/"><rect id=/"restore/" x=/"0/" y=/"0/" width=/"20/" height=/"20/" style=/"fill:none;/"/><g><rect x=/"7/" y=/"2.5/" width=/"10/" height=/"10/" style=/"fill:none;stroke:#fff;stroke-width:1.5px;/"/><rect x=/"7/" y=/"2.5/" width=/"10/" height=/"2/" style=/"fill:#fff;/"/></g><g><rect x=/"3/" y=/"7.5/" width=/"10/" height=/"10/" style=/"fill:none;stroke:#fff;stroke-width:1.5px;/"/><g><rect x=/"3/" y=/"7.5/" width=/"10/" height=/"2/" style=/"fill:#fff;/"/></g></g></svg>';" +0 -1
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).WindowManager={})}(this,(function(t){"use strict";function e(t={}){const e=document.createElement(t.type||"div");return t.styles&&Object.assign(e.style,t.styles),t.className&&(e.className=t.className),t.html&&(e.innerHTML=t.html),t.parent&&t.parent.appendChild(e),e}var i=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t){var e=Object.prototype.hasOwnProperty,i="~";function s(){}function o(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function n(t,e,s,n,h){if("function"!=typeof s)throw new TypeError("The listener must be a function");var l=new o(s,n||t,h),r=i?i+e:e;return t._events[r]?t._events[r].fn?t._events[r]=[t._events[r],l]:t._events[r].push(l):(t._events[r]=l,t._eventsCount++),t}function h(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function l(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),l.prototype.eventNames=function(){var t,s,o=[];if(0===this._eventsCount)return o;for(s in t=this._events)e.call(t,s)&&o.push(i?s.slice(1):s);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(t)):o},l.prototype.listeners=function(t){var e=i?i+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var o=0,n=s.length,h=new Array(n);o<n;o++)h[o]=s[o].fn;return h},l.prototype.listenerCount=function(t){var e=i?i+t:t,s=this._events[e];return s?s.fn?1:s.length:0},l.prototype.emit=function(t,e,s,o,n,h){var l=i?i+t:t;if(!this._events[l])return!1;var r,a,d=this._events[l],c=arguments.length;if(d.fn){switch(d.once&&this.removeListener(t,d.fn,void 0,!0),c){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,e),!0;case 3:return d.fn.call(d.context,e,s),!0;case 4:return d.fn.call(d.context,e,s,o),!0;case 5:return d.fn.call(d.context,e,s,o,n),!0;case 6:return d.fn.call(d.context,e,s,o,n,h),!0}for(a=1,r=new Array(c-1);a<c;a++)r[a-1]=arguments[a];d.fn.apply(d.context,r)}else{var p,u=d.length;for(a=0;a<u;a++)switch(d[a].once&&this.removeListener(t,d[a].fn,void 0,!0),c){case 1:d[a].fn.call(d[a].context);break;case 2:d[a].fn.call(d[a].context,e);break;case 3:d[a].fn.call(d[a].context,e,s);break;case 4:d[a].fn.call(d[a].context,e,s,o);break;default:if(!r)for(p=1,r=new Array(c-1);p<c;p++)r[p-1]=arguments[p];d[a].fn.apply(d[a].context,r)}}return!0},l.prototype.on=function(t,e,i){return n(this,t,e,i,!1)},l.prototype.once=function(t,e,i){return n(this,t,e,i,!0)},l.prototype.removeListener=function(t,e,s,o){var n=i?i+t:t;if(!this._events[n])return this;if(!e)return h(this,n),this;var l=this._events[n];if(l.fn)l.fn!==e||o&&!l.once||s&&l.context!==s||h(this,n);else{for(var r=0,a=[],d=l.length;r<d;r++)(l[r].fn!==e||o&&!l[r].once||s&&l[r].context!==s)&&a.push(l[r]);a.length?this._events[n]=1===a.length?a[0]:a:h(this,n)}return this},l.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&h(this,e)):(this._events=new s,this._eventsCount=0),this},l.prototype.off=l.prototype.removeListener,l.prototype.addListener=l.prototype.on,l.prefixed=i,l.EventEmitter=l,t.exports=l}));const s={threshold:10,clicked:!0,doubleClicked:!1,doubleClickedTime:300,longClicked:!1,longClickedTime:500,capture:!1,clickDown:!1};function o(t,e,i){return new n(t,e,i)}class n{constructor(t,e,i){"string"!=typeof t||(t=document.querySelector(t))?(this.options=Object.assign({},s,i),this.events={mousedown:t=>this.mousedown(t),mouseup:t=>this.mouseup(t),mousemove:t=>this.mousemove(t),touchstart:t=>this.touchstart(t),touchmove:t=>this.touchmove(t),touchcancel:t=>this.cancel(t),touchend:t=>this.touchend(t)},t.addEventListener("mousedown",this.events.mousedown,{capture:this.options.capture}),t.addEventListener("mouseup",this.events.mouseup,{capture:this.options.capture}),t.addEventListener("mousemove",this.events.mousemove,{capture:this.options.capture}),t.addEventListener("touchstart",this.events.touchstart,{passive:!0,capture:this.options.capture}),t.addEventListener("touchmove",this.events.touchmove,{passive:!0,capture:this.options.capture}),t.addEventListener("touchcancel",this.events.touchcancel,{capture:this.options.capture}),t.addEventListener("touchend",this.events.touchend,{capture:this.options.capture}),this.element=t,this.callback=e):console.warn(`Unknown element: document.querySelector(${t}) in clicked()`)}destroy(){this.element.removeEventListener("mousedown",this.events.mousedown),this.element.removeEventListener("mouseup",this.events.mouseup),this.element.removeEventListener("mousemove",this.events.mousemove),this.element.removeEventListener("touchstart",this.events.touchstart,{passive:!0}),this.element.removeEventListener("touchmove",this.events.touchmove,{passive:!0}),this.element.removeEventListener("touchcancel",this.events.touchcancel),this.element.removeEventListener("touchend",this.events.touchend)}touchstart(t){!0===this.down?this.cancel():1===t.touches.length&&this.handleDown(t.changedTouches[0].screenX,t.changedTouches[0].screenY)}pastThreshold(t,e){return Math.abs(this.lastX-t)>this.options.threshold||Math.abs(this.lastY-e)>this.options.threshold}touchmove(t){if(this.down)if(1!==t.touches.length)this.cancel();else{const e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY;this.pastThreshold(e,i)&&this.cancel()}}cancel(){this.down=!1,this.doubleClickedTimeout&&(clearTimeout(this.doubleClickedTimeout),this.doubleClickedTimeout=null),this.longClickedTimeout&&(clearTimeout(this.longClickedTimeout),this.longClickedTimeout=null)}touchend(t){this.down&&(t.preventDefault(),this.handleClicks(t,t.pointerId))}handleClicks(t){this.options.doubleClicked?this.doubleClickedTimeout=setTimeout(()=>this.doubleClickedCancel(t),this.options.doubleClickedTime):this.options.clicked&&this.callback({event:t,type:"clicked"}),this.longClickedTimeout&&(clearTimeout(this.longClickedTimeout),this.longClickedTimeout=null),this.down=!1}handleDown(t,e,i){this.doubleClickedTimeout?this.pastThreshold(e,i)?(this.options.clicked&&this.callback({event:t,type:"clicked"}),this.cancel()):(this.callback({event:t,type:"double-clicked"}),this.cancel()):(this.lastX=e,this.lastY=i,this.down=!0,this.options.longClicked&&(this.longClickedTimeout=setTimeout(()=>this.longClicked(t),this.options.longClickedTime)),this.options.clickDown&&this.callback({event:t,type:"click-down"}))}longClicked(t){this.longClikedTimeout=null,this.down=!1,this.callback({event:t,type:"long-clicked"})}doubleClickedCancel(t){this.doubleClickedTimeout=null,this.options.clicked&&this.callback({event:t,type:"double-clicked"})}mousedown(t){!0===this.down?this.down=!1:this.handleDown(t,t.screenX,t.screenY)}mousemove(t){if(this.down){const e=t.screenX,i=t.screenY;this.pastThreshold(e,i)&&this.cancel()}}mouseup(t){this.down&&(t.preventDefault(),this.handleClicks(t))}}const h={ApplicationContainerStyle:{"z-index":999999,position:"absolute",top:0,left:0,"user-select":"none","font-size":"0.85em"},ApplicationMenuStyle:{display:"flex",position:"relative","flex-direction":"row",color:"black",backgroundColor:"rgb(230,230,230)",width:"100vw",border:"none","box-shadow":"unset",outline:"none"},ApplicationMenuRowStyle:{padding:"0.25em 0.5em",margin:0,"line-height":"1em"},MenuStyle:{"flex-direction":"column",position:"absolute","user-select":"none",color:"black","z-index":999999,backgroundColor:"white",border:"1px solid rgba(0,0,0,0.5)",boxShadow:"1px 3px 3px rgba(0,0,0,0.25)"},RowStyle:{display:"flex",padding:"0.25em 1.5em 0.25em","line-height":"1.5em"},AcceleratorStyle:{opacity:.5},SeparatorStyle:{"border-bottom":"1px solid rgba(0,0,0,0.1)",margin:"0.5em 0"},AcceleratorKeyStyle:{"text-decoration":"underline","text-decoration-color":"rgba(0,0,0,0.5)"},MinimumColumnWidth:20,SelectedBackgroundStyle:"rgba(0,0,0,0.1)",Overlap:5,SubmenuOpenDelay:500};const l=new class{init(){this.initialized||(this.menuKeys={},this.keys={},document.body.addEventListener("keydown",t=>this._keydown(t)),document.body.addEventListener("keyup",t=>this._keyup(t)),this.initialized=!0)}clearMenuKeys(){this.menuKeys={}}clearKeys(){this.keys={}}registerMenuShortcut(t,e){if(t){const i=(e.menu.applicationMenu?"alt+":"")+t;this.menuKeys[this._prepareKey(i)]=t=>{e.handleClick(t),t.stopPropagation(),t.preventDefault()}}}registerMenuSpecial(t){this.menuKeys.escape=()=>t.closeAll(),this.menuKeys.enter=e=>t.enter(e),this.menuKeys.space=e=>t.enter(e),this.menuKeys.arrowright=e=>t.move(e,"right"),this.menuKeys.arrowleft=e=>t.move(e,"left"),this.menuKeys.arrowup=e=>t.move(e,"up"),this.menuKeys.arrowdown=e=>t.move(e,"down")}registerAlt(t,e){this.alt={pressed:t,released:e}}unregisterMenuShortcuts(){this.menuKeys={}}_prepareKey(t){const e=[];let i;i=(t+="").length>1&&-1!==t.indexOf("|")?t.split("|"):[t];for(let t of i){let i="",s=[];if(t=t.toLowerCase().replace(" ",""),-1!==t.indexOf("+")){const e=t.split("+");for(let t=0;t<e.length-1;t++){let i=e[t];i=i.replace("commandorcontrol","ctrl"),i=i.replace("command","ctrl"),i=i.replace("control","ctrl"),s.push(i)}s=s.sort((t,e)=>t[0]>e[0]?1:t[0]<e[0]?-1:0);for(let t of s)i+=t+"+";i+=e[e.length-1]}else i=t;e.push(i)}return e}prettifyKey(t){let e="";const i=this._prepareKey(t);for(let t=0;t<i.length;t++){const s=i[t];if(-1!==s.indexOf("+")){const t=s.toLowerCase().split("+");for(let i=0;i<t.length-1;i++){let s=t[i];e+=s[0].toUpperCase()+s.substr(1)+"+"}e+=t[t.length-1].toUpperCase()}else e=s.toUpperCase();t!==i.length-1&&(e+=" or ")}return e}register(t,e){const i=this._prepareKey(t);for(let t of i)this.keys[t]=t=>{e(t),t.preventDefault(),t.stopPropagation()}}_keyup(t){!this.alt||"AltLeft"!==t.code&&"AltRight"!==t.code||(this.alt.released(),this.alt.isPressed=!1)}_keydown(t){!this.alt||this.alt.isPressed||"AltLeft"!==t.code&&"AltRight"!==t.code||(this.alt.pressed(),this.alt.isPressed=!0,t.preventDefault());const e=[];t.altKey&&e.push("alt"),t.ctrlKey&&e.push("ctrl"),t.metaKey&&e.push("meta"),t.shiftKey&&e.push("shift");let i="";for(let t of e)i+=t+"+";let s=t.code.toLowerCase();s=s.replace("digit",""),s=s.replace("key",""),i+=s,this.menuKeys[i]?this.menuKeys[i](t):this.keys[i]&&this.keys[i](t)}};class r{constructor(t){l.init(),t=t||{},this.div=document.createElement("div"),this.styles=t.styles,this.children=[],this.applyConfig(h.MenuStyle),this.div.tabIndex=-1}append(t){t.submenu&&(t.submenu.menu=this),t.menu=this,this.div.appendChild(t.div),"separator"!==t.type&&this.children.push(t)}insert(t,e){t>=this.div.childNodes.length?this.append(e):(e.submenu&&(e.submenu.menu=this),e.menu=this,this.div.insertBefore(e.div,this.div.childNodes[t]),"separator"!==e.type&&this.children.splice(t,0,e))}hide(){let t=this.menu.showing;for(;t&&t.submenu;){t.div.style.backgroundColor="transparent",t.submenu.div.remove();let e=t.submenu.showing;e&&(t.submenu.showing.div.style.backgroundColor="transparent",t.submenu.showing=null),t=e}}show(t){if(l.unregisterMenuShortcuts(),this.menu&&this.menu.showing===t)this.hide(),this.menu.showing=null,this.div.remove(),this.menu.showAccelerators();else{this.menu&&(this.menu.showing&&-1!==this.menu.children.indexOf(t)&&this.hide(),this.menu.showing=t,this.menu.hideAccelerators());const e=t.div,i=this.menu.div;this.menu.applicationMenu?(this.div.style.left=e.offsetLeft+"px",this.div.style.top=e.offsetTop+e.offsetHeight+"px"):(this.div.style.left=i.offsetLeft+i.offsetWidth-h.Overlap+"px",this.div.style.top=i.offsetTop+e.offsetTop-h.Overlap+"px"),this.attached=t,this.showAccelerators(),r.application.appendChild(this.div);let s=0,o=0,n=0,l=0;for(let t of this.children)t.check.style.width="auto",t.label.style.width="auto",t.accelerator.style.width="auto",t.arrow.style.width="auto","checkbox"===t.type&&(l=h.MinimumColumnWidth),t.submenu&&(n=h.MinimumColumnWidth);for(let t of this.children){const e=2*t.label.offsetWidth;s=e>s?e:s;const i=t.accelerator.offsetWidth;o=i>o?i:o,t.submenu&&(n=t.arrow.offsetWidth)}for(let t of this.children)t.check.style.width=l+"px",t.label.style.width=s+"px",t.accelerator.style.width=o+"px",t.arrow.style.width=n+"px";this.div.offsetLeft+this.div.offsetWidth>window.innerWidth&&(this.div.style.left=window.innerWidth-this.div.offsetWidth+"px"),this.div.offsetTop+this.div.offsetHeight>window.innerHeight&&(this.div.style.top=window.innerHeight-this.div.offsetHeight+"px"),r.application.menu.div.focus()}}applyConfig(t){const e={};for(let i in t)e[i]=t[i];if(this.styles)for(let t in this.styles)e[t]=this.styles[t];for(let t in e)this.div.style[t]=e[t]}showAccelerators(){for(let t of this.children)if(t.showShortcut(),"separator"!==t.type){const e=t.text.indexOf("&");-1!==e&&l.registerMenuShortcut(t.text[e+1],t)}this.applicationMenu||l.registerMenuSpecial(this)}hideAccelerators(){for(let t of this.children)t.hideShortcut()}closeAll(){l.unregisterMenuShortcuts();let t=r.application.menu;if(t.showing){let e=t;for(;e.showing;)e=e.showing.submenu;for(;e&&!e.applicationMenu;)e.showing&&(e.showing.div.style.backgroundColor="transparent",e.showing=null),e.div.remove(),e=e.menu;e&&(e.showing.div.style.background="transparent",e.showing=null,e.hideAccelerators())}}moveChild(t){let e;if("left"===t){const t=this.selector.menu.menu;e=t.children.indexOf(t.showing),e--,e=e<0?t.children.length-1:e,t.children[e].handleClick()}else{let t=this.selector.menu.menu,i=t.showing;for(;!t.applicationMenu;)i.handleClick(),i.div.style.backgroundColor="transparent",t=t.menu,i=t.showing;e=t.children.indexOf(i),e++,e=e===t.children.length?0:e,t.children[e].handleClick()}this.selector=null}horizontalSelector(t,e){"right"===e?this.selector.submenu?(this.selector.handleClick(t),this.selector.submenu.selector=this.selector.submenu.children[0],this.selector.submenu.selector.div.style.backgroundColor=h.SelectedBackgroundStyle,this.selector=null):this.moveChild(e):"left"===e&&(this.selector.menu.menu.applicationMenu?this.moveChild(e):(this.selector.menu.attached.handleClick(t),this.selector.menu.menu.selector=this.selector.menu.attached,this.selector=null)),t.stopPropagation(),t.preventDefault()}move(t,e){if(this.selector){this.selector.div.style.backgroundColor="transparent";let i=this.children.indexOf(this.selector);if("down"===e)i++,i=i===this.children.length?0:i;else{if("up"!==e)return this.horizontalSelector(t,e);i--,i=i<0?this.children.length-1:i}this.selector=this.children[i]}else this.selector="up"===e?this.children[this.children.length-1]:this.children[0];this.selector&&(this.selector.div.style.backgroundColor=h.SelectedBackgroundStyle),t.preventDefault(),t.stopPropagation()}enter(t){this.selector&&(this.selector.handleClick(t),t.preventDefault(),t.stopPropagation())}get items(){return this.children}showApplicationAccelerators(){this.hideAccelerators(),l.registerAlt(()=>{this.showing||this.showAccelerators()},()=>{this.hideAccelerators()})}static get config(){return h}static getApplicationHeight(){return r.application?r.application.offsetHeight:0}static setApplicationMenu(t,i=document.body){l.clearMenuKeys(),r.application&&r.application.remove(),r.application=e({parent:i,styles:h.ApplicationContainerStyle}),r.application.menu=t,t.applyConfig(h.ApplicationMenuStyle);for(let e of t.children)e.applyConfig(h.ApplicationMenuRowStyle),e.arrow&&(e.arrow.style.display="none"),t.div.appendChild(e.div);r.application.appendChild(t.div),t.applicationMenu=!0,t.div.tabIndex=-1,t.div.addEventListener("focus",()=>{t.showing||t.div.blur()}),t.div.addEventListener("blur",()=>{t.showing&&t.closeAll()}),t.showApplicationAccelerators()}}class a extends i{constructor(t,e={}){super(),this.wm=t,this.options=e,this.id=void 0===this.options.id?a.id++:this.options.id,this._createWin(),this._createWinBox(),this._createTitlebar(),this._createContent(),this.options.resizable&&this._createResize(),this._createOverlay(),this._buildTransform(),this._listeners(),this.active=!1,this.maximized=!1,this._closed=!0,this._restore=null,this._moving=null,this._resizing=null,this._attachedToScreen={vertical:"",horziontal:""}}open(t){this._closed&&(this.win.style.display="block",this._closed=!1,this.emit("open",this),t||this.focus())}focus(){this.active=!0,this.options.titlebar&&(this.winTitlebar.style.backgroundColor=this.options.backgroundTitlebarActive),this.emit("focus",this)}blur(){this.active=!1,this.options.titlebar&&(this.winTitlebar.style.backgroundColor=this.options.backgroundTitlebarInactive),this.emit("blur",this)}close(){this._closed||(this._closed=!0,this.win.style.display="none",this.emit("close",this))}get closed(){return this._closed}get x(){return this.options.x}set x(t){t!==this.options.x&&(this.options.x=t,this.emit("move-x",this),this._buildTransform())}_buildTransform(){this.win.style.transform=`translate(${this.options.x}px,${this.options.y}px)`}get y(){return this.options.y}set y(t){t!==this.options.y&&(this.options.y=t,this._buildTransform(),this.emit("move-y",this))}get width(){return this.options.width||this.win.offsetWidth}set width(t){t!==this.options.width&&(t?(this.win.style.width=t+"px",this.options.width=this.win.offsetWidth):(this.win.style.width="auto",this.options.width=""),this.emit("resize-width",this))}get height(){return this.options.height||this.win.offsetHeight}set height(t){t!==this.options.height&&(t?(this.win.style.height=t+"px",this.options.height=this.win.offsetHeight):(this.win.style.height="auto",this.options.height=""),this.emit("resize-height",this))}resize(t,e){this.width=t,this.height=e}move(t,e){const i=this.keepInside;if(i){if(!0===i||"horizontal"===i){const e=this.wm.win.offsetWidth;t=(t=t+this.width>e?e-this.width:t)<0?0:t}if(!0===i||"vertical"===i){const t=this.wm.win.offsetHeight;e=e+this.height>t?t-this.height:e;const i=r.getApplicationHeight();e=e<i?i:e}}t!==this.options.x&&(this.options.x=t,this.emit("move-x",this)),e!==this.options.y&&(this.options.y=e,this.emit("move-y",this)),this._buildTransform()}maximize(){if(this.options.maximizable)if(this.maximized)this.x=this.maximized.x,this.y=this.maximized.y,this.width=this.maximized.width,this.height=this.maximized.height,this.maximized=null,this.emit("restore",this),this.buttons.maximize.innerHTML=this.options.maximizeButton;else{const t=this.x,e=this.y,i=this.win.offsetWidth,s=this.win.offsetHeight;this.maximized={x:t,y:e,width:i,height:s},this.x=0,this.y=0,this.width=this.wm.wallpaper.offsetWidth,this.height=this.wm.wallpaper.offsetHeight,this.emit("maximize",this),this.buttons.maximize.innerHTML=this.options.restoreButton}}sendToBack(){this.wm.sendToBack(this)}sendToFront(){this.wm.sendToFront(this)}save(){const t={},e=this.maximized;return e&&(t.maximized={left:e.left,top:e.top,width:e.width,height:e.height}),t.x=this.x,t.y=this.y,void 0!==this.options.width&&(t.width=this.options.width),void 0!==this.options.height&&(t.height=this.options.height),t.closed=this._closed,t}load(t){t.maximized?this.maximized||this.maximize(!0):this.maximized&&this.maximize(!0),void 0!==t.width?this.width=t.width:this.win.style.width="auto",void 0!==t.height?this.height=t.height:this.win.style.height="auto",this.move(t.x,t.y),t.closed?this.close(!0):this.closed&&this.open(!0,!0),this.emit("loaded")}get title(){return this._title}set title(t){this.winTitle.innerText=t,this.emit("title-change",this)}get right(){return this.x+this.width}set right(t){this.x=t-this.width}get bottom(){return this.y+this.height}set bottom(t){this.y=t-this.height}center(t){t?this.move(t.x+t.width/2-this.width/2,t.y+t.height/2-this.height/2):this.move(window.innerWidth/2-this.width/2,window.innerHeight/2-this.height/2)}_createWin(){this.win=e({parent:this.wm.win,styles:{display:"none","border-radius":this.options.borderRadius,"user-select":"none",overflow:"hidden",position:"absolute","min-width":this.options.minWidth,"min-height":this.options.minHeight,"background-color":this.options.backgroundWindow,width:isNaN(this.options.width)?this.options.width:this.options.width+"px",height:isNaN(this.options.height)?this.options.height:this.options.height+"px",...this.options.styles}})}_createWinBox(){this.winBox=e({parent:this.win,styles:{display:"flex","flex-direction":"column",width:"100%",height:"100%","min-height":this.options.minHeight}})}_createContent(){this.content=e({parent:this.winBox,type:"section",styles:{display:"block",flex:1,"min-height":this.options.minHeight,"overflow-x":"hidden","overflow-y":"auto"}})}_createOverlay(){this.overlay=e({parent:this.win,styles:{display:"none",position:"absolute",left:0,top:0,width:"100%",height:"100%"}}),this.overlay.addEventListener("mousedown",t=>{this._downTitlebar(t),t.stopPropagation()}),this.overlay.addEventListener("touchstart",t=>{this._downTitlebar(t),t.stopPropagation()})}_downTitlebar(t){const e=this._convertMoveEvent(t);this._moving={x:e.pageX-this.x,y:e.pageY-this.y},this.emit("move-start",this),this._moved=!1}_createTitlebar(){if(this.options.titlebar){this.winTitlebar=e({parent:this.winBox,type:"header",styles:{"user-select":"none",display:"flex","flex-direction":"row","align-items":"center","justify-content":"center",height:this.options.titlebarHeight,"min-height":this.options.titlebarHeight,border:0,padding:"0 8px",overflow:"hidden"}});const t={"user-select":"none",flex:1,display:"flex","flex-direction":"row","align-items":"center","user-select":"none",cursor:"default",padding:0,margin:0,"font-size":"16px","font-weight":400,color:this.options.foregroundTitle};this.options.titleCenter?t["justify-content"]="center":t["padding-left"]="8px",this.winTitle=e({parent:this.winTitlebar,type:"span",html:this.options.title,styles:t}),this._createButtons(),this.options.movable&&(this.winTitlebar.addEventListener("mousedown",t=>this._downTitlebar(t)),this.winTitlebar.addEventListener("touchstart",t=>this._downTitlebar(t))),this.options.maximizable&&o(this.winTitlebar,()=>this.maximize(),{doubleClicked:!0,clicked:!1})}}_createButtons(){this.winButtonGroup=e({parent:this.winTitlebar,styles:{display:"flex","flex-direction":"row","align-items":"center","padding-left":"10px"}});const t={display:"inline-block",border:0,margin:0,"margin-left":"15px",padding:0,width:"12px",height:"12px","background-color":"transparent","background-size":"cover","background-repeat":"no-repeat",opacity:.7,color:this.options.foregroundButton,outline:0};this.buttons={},this.options.maximizable&&(this.buttons.maximize=e({parent:this.winButtonGroup,html:this.options.maximizeButton,type:"button",styles:t}),o(this.buttons.maximize,()=>this.maximize())),this.options.closable&&(this.buttons.close=e({parent:this.winButtonGroup,html:this.options.closeButton,type:"button",styles:t}),o(this.buttons.close,()=>this.close()));for(let t in this.buttons){const e=this.buttons[t];e.addEventListener("mousemove",()=>{e.style.opacity=1}),e.addEventListener("mouseout",()=>{e.style.opacity=.7})}}_createResize(){this.resizeEdge=e({parent:this.winBox,type:"button",html:this.options.backgroundResize,styles:{position:"absolute",bottom:0,right:"4px",border:0,margin:0,padding:0,cursor:"se-resize","user-select":"none",height:"15px",width:"10px",background:"none"}});const t=t=>{const e=this._convertMoveEvent(t),i=this.width||this.win.offsetWidth,s=this.height||this.win.offsetHeight;this._resizing={width:i-e.pageX,height:s-e.pageY},this.emit("resize-start"),t.preventDefault()};this.resizeEdge.addEventListener("mousedown",t),this.resizeEdge.addEventListener("touchstart",t)}_move(t){const e=this._convertMoveEvent(t);this._isTouchEvent(t)||1===t.which||(this._moving&&this._stopMove(),this._resizing&&this._stopResize()),this._moving&&(this.move(e.pageX-this._moving.x,e.pageY-this._moving.y),this.emit("move",this),t.preventDefault()),this._resizing&&(this.resize(e.pageX+this._resizing.width,e.pageY+this._resizing.height),this.maximized=null,this.emit("resize",this),t.preventDefault())}_up(){this._moving&&this._stopMove(),this._resizing&&this._stopResize()}_listeners(){this.win.addEventListener("mousedown",()=>this.focus()),this.win.addEventListener("touchstart",()=>this.focus())}_stopMove(){this._moving=null,this.emit("move-end",this)}_stopResize(){this._restore=this._resizing=null,this.emit("resize-end",this)}_isTouchEvent(t){return!!window.TouchEvent&&t instanceof window.TouchEvent}_convertMoveEvent(t){return this._isTouchEvent(t)?t.changedTouches[0]:t}attachToScreen(t,e){this._attachedToScreen[t]=e}reposition(t,e){this.bounds=t,this.keepInside=e;let i=this.x,s=this.y;i="right"===this._attachedToScreen.horziontal?t.right-this.width:i,i="left"===this._attachedToScreen.horizontal?t.left:i,s="bottom"===this._attachedToScreen.vertical?t.bottom-this.height:s,s="top"===this._attachedToScreen.vertical?t.top:s,this.move(i,s)}isModal(t){return(t||!this._closed)&&this.options.modal}isClosed(){return this._closed}get z(){return parseInt(this.win.style.zIndex)}set z(t){this.win.style.zIndex=t}}a.id=0;const d={x:0,y:0,width:void 0,height:void 0,modal:!1,openOnCreate:!0,id:null,minWidth:"200px",minHeight:"60px",borderRadius:0,styles:{},movable:!0,resizable:!0,maximizable:!0,closable:!0,noSnap:!1,noMenu:!1,titlebar:!0,titlebarHeight:"2rem",backgroundWindow:"#fefefe",backgroundTitlebarActive:"#365d98",backgroundTitlebarInactive:"#888888",foregroundButton:"#ffffff",foregroundTitle:"#ffffff",closeButton:'<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"><rect id="close" x="0" y="0" width="20" height="20" style="fill:none;"/><g><path d="M3.5,3.5l13,13" style="fill:none;stroke:#fff;stroke-width:3px;"/><path d="M16.5,3.5l-13,13" style="fill:none;stroke:#fff;stroke-width:3px;"/></g></svg>',maximizeButton:'<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"><rect id="maximize" x="0" y="0" width="20" height="20" style="fill:none;"/><rect x="2" y="2" width="16" height="16" style="fill:none;stroke:#fff;stroke-width:2px;"/><rect x="2" y="2" width="16" height="3.2" style="fill:#fff;"/></svg>',restoreButton:'<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"><rect id="restore" x="0" y="0" width="20" height="20" style="fill:none;"/><g><rect x="7" y="2.5" width="10" height="10" style="fill:none;stroke:#fff;stroke-width:1.5px;"/><rect x="7" y="2.5" width="10" height="2" style="fill:#fff;"/></g><g><rect x="3" y="7.5" width="10" height="10" style="fill:none;stroke:#fff;stroke-width:1.5px;"/><g><rect x="3" y="7.5" width="10" height="2" style="fill:#fff;"/></g></g></svg>',backgroundResize:'<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><rect id="resize" x="0" y="0" width="20" height="20" style="fill:none;"/><clipPath id="_clip1"><rect x="0" y="0" width="20" height="20"/></clipPath><g clip-path="url(#_clip1)"><rect x="0" y="16.8" width="20" height="3.2" style="fill:#fff;"/><path d="M17.737,3.595l-14.142,14.142l2.263,2.263l14.142,-14.142l-2.263,-2.263Z" style="fill:#fff;"/><path d="M16.8,0l0,20l3.2,0l0,-20l-3.2,0Z" style="fill:#fff;"/><path d="M7.099,18.4l11.301,-11.123l0,11.123l-11.301,0Z" style="fill:#fff;"/></g></svg>'},c={quiet:!1,keepInside:!0,snap:!0,noAccelerator:!1,menu:!1,styles:{},backgroundModal:"rgba(0, 0, 0, 0.6)"},p={screen:!0,windows:!0,snap:20,color:"#a8f0f4",spacing:0,indicator:10};class u{constructor(t,i={}){this.wm=t,this.options={...p,...i},this.highlights=e({parent:this.wm.wallpaper,styles:{position:"absolute"}}),this.horizontal=e({parent:this.highlights,styles:{display:"none",position:"absolute",height:this.options.indicator+"px",borderRadius:this.options.indicator+"px",backgroundColor:this.options.color}}),this.vertical=e({parent:this.highlights,styles:{display:"none",position:"absolute",width:this.options.indicator+"px",borderRadius:this.options.indicator+"px",backgroundColor:this.options.color}}),this.horizontal,this.showing=[]}stop(){this.highlights.remove(),this.stopped=!0}addWindow(t){t.on("move",()=>this.move(t)),t.on("move-end",()=>this.moveEnd(t))}screenMove(t,e,i){const s=r.getApplicationHeight(),o=this.wm.win.clientWidth,n=this.wm.win.clientHeight;t.left-this.options.snap<=o&&t.right+this.options.snap>=0&&(Math.abs(t.top-s)<=this.options.snap?e.push({distance:Math.abs(t.top-s),left:0,width:o,top:s,side:"top",screen:!0}):Math.abs(t.bottom-n)<=this.options.snap&&e.push({distance:Math.abs(t.bottom-n),left:0,width:o,top:n,side:"bottom",screen:!0})),t.top-this.options.snap<=n&&t.bottom+this.options.snap>=0&&(Math.abs(t.left-0)<=this.options.snap?i.push({distance:Math.abs(t.left-0),top:0,height:n,left:0,side:"left",screen:!0}):Math.abs(t.right-o)<=this.options.snap&&i.push({distance:Math.abs(t.right-o),top:0,height:n,left:o,side:"right",screen:!0}))}windowsMove(t,e,i,s){for(let o of this.wm.windows)if(!o.options.noSnap&&o!==t){const t=o.win.getBoundingClientRect();e.left-this.options.snap<=t.right&&e.right+this.options.snap>=t.left&&(Math.abs(e.top-t.bottom)<=this.options.snap?(i.push({distance:Math.abs(e.top-t.bottom),left:t.left,width:t.width,top:t.bottom,side:"top"}),Math.abs(e.left-t.left)<=this.options.snap?s.push({distance:Math.abs(e.left-t.left),top:t.top,height:t.height,left:t.left,side:"left",noSpacing:!0}):Math.abs(e.right-t.right)<=this.options.snap&&s.push({distance:Math.abs(e.right-t.right),top:t.top,height:t.height,left:t.right,side:"right",noSpacing:!0})):Math.abs(e.bottom-t.top)<=this.options.snap&&(i.push({distance:Math.abs(e.bottom-t.top),left:t.left,width:t.width,top:t.top,side:"bottom"}),Math.abs(e.left-t.left)<=this.options.snap?s.push({distance:Math.abs(e.left-t.left),top:t.top,height:t.height,left:t.left,side:"left",noSpacing:!0}):Math.abs(e.right-t.right)<=this.options.snap&&s.push({distance:Math.abs(e.right-t.right),top:t.top,height:t.height,left:t.right,side:"right",noSpacing:!0}))),e.top-this.options.snap<=t.bottom&&e.bottom+this.options.snap>=t.top&&(Math.abs(e.left-t.right)<=this.options.snap?(s.push({distance:Math.abs(e.left-t.right),top:t.top,height:t.height,left:t.right,side:"left"}),Math.abs(e.top-t.top)<=this.options.snap?i.push({distance:Math.abs(e.top-t.top),left:t.left,width:t.width,top:t.top,side:"top",noSpacing:!0}):Math.abs(e.bottom-t.bottom)<=this.options.snap&&i.push({distance:Math.abs(e.bottom-t.bottom),left:t.left,width:t.width,top:t.bottom,side:"bottom",noSpacing:!0})):Math.abs(e.right-t.left)<=this.options.snap&&(s.push({distance:Math.abs(e.right-t.left),top:t.top,height:t.height,left:t.left,side:"right"}),Math.abs(e.top-t.top)<=this.options.snap?i.push({distance:Math.abs(e.top-t.top),left:t.left,width:t.width,top:t.top,side:"top",noSpacing:!0}):Math.abs(e.bottom-t.bottom)<=this.options.snap&&i.push({distance:Math.abs(e.bottom-t.bottom),left:t.left,width:t.width,top:t.bottom,side:"bottom",noSpacing:!0})))}}move(t){if(this.stopped||t.options.noSnap||t.isModal())return;this.horizontal.style.display="none",this.vertical.style.display="none";const e=[],i=[],s=t.win.getBoundingClientRect();if(this.options.screen&&this.screenMove(s,e,i),this.options.windows&&this.windowsMove(t,s,e,i),e.length){e.sort((t,e)=>t.distance-e.distance);const t=e[0];this.horizontal.style.display="block",this.horizontal.style.width=t.width+"px",this.horizontal.y=t.top-this.options.indicator/2,this.horizontal.yPosition=t.top,this.horizontal.style.transform=`translate(${t.left}px,${this.horizontal.y}px)`,this.horizontal.side=t.side,this.horizontal.noSpacing=t.noSpacing,this.horizontal.screen=t.screen}if(i.length){i.sort((t,e)=>t.distance-e.distance);const t=i[0];this.vertical.style.display="block",this.vertical.style.height=t.height+"px",this.vertical.x=t.left-this.options.indicator/2,this.vertical.xPosition=t.left,this.vertical.style.transform=`translate(${this.vertical.x}px,${t.top}px)`,this.vertical.side=t.side,this.vertical.noSpacing=t.noSpacing,this.vertical.screen=t.screen}}moveEnd(t){if(this.stopped)return;const e=this.wm.bounds,i=r.getApplicationHeight();if("block"===this.horizontal.style.display){const s=this.horizontal.noSpacing?0:this.options.spacing;switch(this.horizontal.side){case"top":t.y=this.horizontal.yPosition+s-e.top+i;break;case"bottom":t.bottom=Math.floor(this.horizontal.yPosition-s-e.top+i)}t.attachToScreen("vertical",this.horizontal.screen?this.horizontal.side:"")}if("block"===this.vertical.style.display){const i=this.vertical.noSpacing?0:this.options.spacing;switch(this.vertical.side){case"left":t.x=this.vertical.xPosition+i-e.left;break;case"right":t.right=Math.floor(this.vertical.xPosition-i-e.left)}t.attachToScreen("horziontal",this.vertical.screen?this.vertical.side:"")}this.horizontal.style.display=this.vertical.style.display="none"}}t.WindowManager=class{constructor(t={},e={}){this.options={...c,...t},this.options.parent=this.options.parent||document.body,this.options.quiet||console.log("%c ☕ simple-window-manager initialized ☕","color: #ff00ff"),this.windows=[],this.active=null,this._setupWin(),this._setupWallpaper(),this._setupModal(),this.options.snap&&this.snap(!0===this.options.snap?{}:this.options.snap),this.windowOptions={...d,...e},window.addEventListener("resize",()=>this.resize()),this.options.noAccelerator||l.init()}createWindow(t={}){const e=new a(this,{...this.windowOptions,...t});return e.on("open",()=>this._open(e)),e.on("focus",()=>this._focus(e)),e.on("blur",()=>this._blur(e)),e.on("close",()=>this._close(e)),e.win.addEventListener("mousemove",t=>this._move(t)),e.win.addEventListener("touchmove",t=>this._move(t)),e.win.addEventListener("mouseup",t=>this._up(t)),e.win.addEventListener("touchend",t=>this._up(t)),this._snap&&!t.noSnap&&this._snap.addWindow(e),e.reposition(this.bounds,this.options.keepInside),e.options.openOnCreate&&e.open(),e}snap(t){this._snap=new u(this,t);for(const t of this.windows)t.options.noSnap||this._snap.addWindow(t)}sendToFront(t){const e=this.windows.indexOf(t);console.assert(-1!==e,"sendToFront should find window in this.windows"),e!==this.windows.length-1&&(this.windows.splice(e,1),this.windows.push(t),this._reorder())}sendToBack(t){const e=this.windows.indexOf(t);console.assert(-1!==e,"sendToFront should find window in this.windows"),0!==e&&(this.windows.splice(e,1),this.windows.unshift(t),this._reorder())}save(){const t={};for(let e=0;e<this.windows.length;e++){const i=this.windows[e];t[i.id]=i.save(),t[i.id].order=e}return t}load(t){for(const e in t){const i=this.getWindowById(e);i&&i.load(t[e])}}closeAll(){for(let t of this.windows)t.close();this.windows=[],this.active=null}_reorder(){let t=0;for(const e of this.windows)e.isClosed()||(e.z=t++)}_setupWin(){this.win=e({parent:this.options.parent,styles:{"user-select":"none",width:"100%",height:"100%",overflow:"hidden","z-index":-1,cursor:"default",...this.options.styles}})}_setupWallpaper(){this.wallpaper=e({parent:this.win,styles:{"user-select":"none",position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden"}}),this.wallpaper.addEventListener("mousemove",t=>this._move(t)),this.wallpaper.addEventListener("touchmove",t=>this._move(t)),this.wallpaper.addEventListener("mouseup",t=>this._up(t)),this.wallpaper.addEventListener("touchend",t=>this._up(t))}_setupModal(){this.modalOverlay=e({parent:this.win,styles:{display:"none","user-select":"none",position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden",background:this.options.backgroundModal}}),this.modalOverlay.addEventListener("mousemove",t=>{this._move(t),t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("touchmove",t=>{this._move(t),t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("mouseup",t=>{this._up(t),t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("touchend",t=>{this._up(t),t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("touchstart",t=>{t.preventDefault(),t.stopPropagation()})}_open(t){this.windows.push(t),this._reorder(),t.options.modal?(this.modalOverlay.style.display="block",this.modalOverlay.style.zIndex=t.z):this.modalOverlay.style.display="none"}_focus(t){if(this.active===t)return;this.active&&this.active.blur();const e=this.windows.indexOf(t);console.assert(-1!==e,"WindowManager._focus should find window in this.windows"),e!==this.windows.length-1&&(this.windows.splice(e,1),this.windows.push(t)),this._reorder(),this.active=this.windows[this.windows.length-1]}_blur(t){this.active===t&&(this.active=null)}_close(t){if(t.isModal(!0)){const t=this.windows[this.windows.length-1];t&&t.isModal()?this.modalOverlay.style.zIndex=t.z:this.modalOverlay.style.display="none"}}_move(t){for(const e in this.windows)this.windows[e]._move(t)}_up(t){for(const e in this.windows)this.windows[e]._up(t)}checkModal(t){return!this.modal||this.modal===t}get bounds(){const t=r.getApplicationHeight();return{top:this.win.offsetTop+t,bottom:this.win.offsetTop+this.win.offsetHeight,left:this.win.offsetLeft,right:this.win.offsetLeft+this.win.offsetWidth}}resize(){const t=this.bounds;for(const e in this.windows)this.windows[e].reposition(t,this.options.keepInside)}getWindowById(t){return this.windows.find(e=>e.id===t)}},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).WindowManager={})}(this,function(t){"use strict";function e(t={}){const e=document.createElement(t.type||"div");return t.styles&&Object.assign(e.style,t.styles),t.className&&(e.className=t.className),t.html&&(e.innerHTML=t.html),t.parent&&t.parent.appendChild(e),e}function i(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var s,o={exports:{}};var n=(s||(s=1,function(t){var e=Object.prototype.hasOwnProperty,i="~";function s(){}function o(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function n(t,e,s,n,h){if("function"!=typeof s)throw new TypeError("The listener must be a function");var l=new o(s,n||t,h),r=i?i+e:e;return t._events[r]?t._events[r].fn?t._events[r]=[t._events[r],l]:t._events[r].push(l):(t._events[r]=l,t._eventsCount++),t}function h(t,e){0===--t._eventsCount?t._events=new s:delete t._events[e]}function l(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),l.prototype.eventNames=function(){var t,s,o=[];if(0===this._eventsCount)return o;for(s in t=this._events)e.call(t,s)&&o.push(i?s.slice(1):s);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(t)):o},l.prototype.listeners=function(t){var e=i?i+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var o=0,n=s.length,h=new Array(n);o<n;o++)h[o]=s[o].fn;return h},l.prototype.listenerCount=function(t){var e=i?i+t:t,s=this._events[e];return s?s.fn?1:s.length:0},l.prototype.emit=function(t,e,s,o,n,h){var l=i?i+t:t;if(!this._events[l])return!1;var r,a,d=this._events[l],c=arguments.length;if(d.fn){switch(d.once&&this.removeListener(t,d.fn,void 0,!0),c){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,e),!0;case 3:return d.fn.call(d.context,e,s),!0;case 4:return d.fn.call(d.context,e,s,o),!0;case 5:return d.fn.call(d.context,e,s,o,n),!0;case 6:return d.fn.call(d.context,e,s,o,n,h),!0}for(a=1,r=new Array(c-1);a<c;a++)r[a-1]=arguments[a];d.fn.apply(d.context,r)}else{var p,u=d.length;for(a=0;a<u;a++)switch(d[a].once&&this.removeListener(t,d[a].fn,void 0,!0),c){case 1:d[a].fn.call(d[a].context);break;case 2:d[a].fn.call(d[a].context,e);break;case 3:d[a].fn.call(d[a].context,e,s);break;case 4:d[a].fn.call(d[a].context,e,s,o);break;default:if(!r)for(p=1,r=new Array(c-1);p<c;p++)r[p-1]=arguments[p];d[a].fn.apply(d[a].context,r)}}return!0},l.prototype.on=function(t,e,i){return n(this,t,e,i,!1)},l.prototype.once=function(t,e,i){return n(this,t,e,i,!0)},l.prototype.removeListener=function(t,e,s,o){var n=i?i+t:t;if(!this._events[n])return this;if(!e)return h(this,n),this;var l=this._events[n];if(l.fn)l.fn!==e||o&&!l.once||s&&l.context!==s||h(this,n);else{for(var r=0,a=[],d=l.length;r<d;r++)(l[r].fn!==e||o&&!l[r].once||s&&l[r].context!==s)&&a.push(l[r]);a.length?this._events[n]=1===a.length?a[0]:a:h(this,n)}return this},l.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&h(this,e)):(this._events=new s,this._eventsCount=0),this},l.prototype.off=l.prototype.removeListener,l.prototype.addListener=l.prototype.on,l.prefixed=i,l.EventEmitter=l,t.exports=l}(o)),o.exports),h=i(n);const l={threshold:10,clicked:!0,doubleClicked:!1,doubleClickedTime:300,longClicked:!1,longClickedTime:500,capture:!1,clickDown:!1};function r(t,e,i){return new a(t,e,i)}class a{constructor(t,e,i){"string"!=typeof t||(t=document.querySelector(t))?(this.options=Object.assign({},l,i),this.events={mousedown:t=>this.mousedown(t),mouseup:t=>this.mouseup(t),mousemove:t=>this.mousemove(t),touchstart:t=>this.touchstart(t),touchmove:t=>this.touchmove(t),touchcancel:t=>this.cancel(t),touchend:t=>this.touchend(t)},t.addEventListener("mousedown",this.events.mousedown,{capture:this.options.capture}),t.addEventListener("mouseup",this.events.mouseup,{capture:this.options.capture}),t.addEventListener("mousemove",this.events.mousemove,{capture:this.options.capture}),t.addEventListener("touchstart",this.events.touchstart,{passive:!0,capture:this.options.capture}),t.addEventListener("touchmove",this.events.touchmove,{passive:!0,capture:this.options.capture}),t.addEventListener("touchcancel",this.events.touchcancel,{capture:this.options.capture}),t.addEventListener("touchend",this.events.touchend,{capture:this.options.capture}),this.element=t,this.callback=e):console.warn(`Unknown element: document.querySelector(${t}) in clicked()`)}destroy(){this.element.removeEventListener("mousedown",this.events.mousedown),this.element.removeEventListener("mouseup",this.events.mouseup),this.element.removeEventListener("mousemove",this.events.mousemove),this.element.removeEventListener("touchstart",this.events.touchstart,{passive:!0}),this.element.removeEventListener("touchmove",this.events.touchmove,{passive:!0}),this.element.removeEventListener("touchcancel",this.events.touchcancel),this.element.removeEventListener("touchend",this.events.touchend)}touchstart(t){!0===this.down?this.cancel():1===t.touches.length&&this.handleDown(t.changedTouches[0].screenX,t.changedTouches[0].screenY)}pastThreshold(t,e){return Math.abs(this.lastX-t)>this.options.threshold||Math.abs(this.lastY-e)>this.options.threshold}touchmove(t){if(this.down)if(1!==t.touches.length)this.cancel();else{const e=t.changedTouches[0].screenX,i=t.changedTouches[0].screenY;this.pastThreshold(e,i)&&this.cancel()}}cancel(){this.down=!1,this.doubleClickedTimeout&&(clearTimeout(this.doubleClickedTimeout),this.doubleClickedTimeout=null),this.longClickedTimeout&&(clearTimeout(this.longClickedTimeout),this.longClickedTimeout=null)}touchend(t){this.down&&(t.preventDefault(),this.handleClicks(t,t.pointerId))}handleClicks(t){this.options.doubleClicked?this.doubleClickedTimeout=setTimeout(()=>this.doubleClickedCancel(t),this.options.doubleClickedTime):this.options.clicked&&this.callback({event:t,type:"clicked"}),this.longClickedTimeout&&(clearTimeout(this.longClickedTimeout),this.longClickedTimeout=null),this.down=!1}handleDown(t,e,i){this.doubleClickedTimeout?this.pastThreshold(e,i)?(this.options.clicked&&this.callback({event:t,type:"clicked"}),this.cancel()):(this.callback({event:t,type:"double-clicked"}),this.cancel()):(this.lastX=e,this.lastY=i,this.down=!0,this.options.longClicked&&(this.longClickedTimeout=setTimeout(()=>this.longClicked(t),this.options.longClickedTime)),this.options.clickDown&&this.callback({event:t,type:"click-down"}))}longClicked(t){this.longClikedTimeout=null,this.down=!1,this.callback({event:t,type:"long-clicked"})}doubleClickedCancel(t){this.doubleClickedTimeout=null,this.options.clicked&&this.callback({event:t,type:"double-clicked"})}mousedown(t){!0===this.down?this.down=!1:this.handleDown(t,t.screenX,t.screenY)}mousemove(t){if(this.down){const e=t.screenX,i=t.screenY;this.pastThreshold(e,i)&&this.cancel()}}mouseup(t){this.down&&(t.preventDefault(),this.handleClicks(t))}}const d={ApplicationContainerStyle:{"z-index":999999,position:"absolute",top:0,left:0,"user-select":"none","font-size":"0.85em"},ApplicationMenuStyle:{display:"flex",position:"relative","flex-direction":"row",color:"black",backgroundColor:"rgb(230,230,230)",width:"100vw",border:"none","box-shadow":"unset",outline:"none"},ApplicationMenuRowStyle:{padding:"0.25em 0.5em",margin:0,"line-height":"1em"},MenuStyle:{"flex-direction":"column",position:"absolute","user-select":"none",color:"black","z-index":999999,backgroundColor:"white",border:"1px solid rgba(0,0,0,0.5)",boxShadow:"1px 3px 3px rgba(0,0,0,0.25)"},RowStyle:{display:"flex",padding:"0.25em 1.5em 0.25em","line-height":"1.5em"},AcceleratorStyle:{opacity:.5},SeparatorStyle:{"border-bottom":"1px solid rgba(0,0,0,0.1)",margin:"0.5em 0"},AcceleratorKeyStyle:{"text-decoration":"underline","text-decoration-color":"rgba(0,0,0,0.5)"},MinimumColumnWidth:20,SelectedBackgroundStyle:"rgba(0,0,0,0.1)",Overlap:5,SubmenuOpenDelay:500};const c=new class{init(){this.initialized||(this.menuKeys={},this.keys={},document.body.addEventListener("keydown",t=>this._keydown(t)),document.body.addEventListener("keyup",t=>this._keyup(t)),this.initialized=!0)}clearMenuKeys(){this.menuKeys={}}clearKeys(){this.keys={}}registerMenuShortcut(t,e){if(t){const i=(e.menu.applicationMenu?"alt+":"")+t;this.menuKeys[this._prepareKey(i)]=t=>{e.handleClick(t),t.stopPropagation(),t.preventDefault()}}}registerMenuSpecial(t){this.menuKeys.escape=()=>t.closeAll(),this.menuKeys.enter=e=>t.enter(e),this.menuKeys.space=e=>t.enter(e),this.menuKeys.arrowright=e=>t.move(e,"right"),this.menuKeys.arrowleft=e=>t.move(e,"left"),this.menuKeys.arrowup=e=>t.move(e,"up"),this.menuKeys.arrowdown=e=>t.move(e,"down")}registerAlt(t,e){this.alt={pressed:t,released:e}}unregisterMenuShortcuts(){this.menuKeys={}}_prepareKey(t){const e=[];let i;i=(t+="").length>1&&-1!==t.indexOf("|")?t.split("|"):[t];for(let t of i){let i="",s=[];if(t=t.toLowerCase().replace(" ",""),-1!==t.indexOf("+")){const e=t.split("+");for(let t=0;t<e.length-1;t++){let i=e[t];i=i.replace("commandorcontrol","ctrl"),i=i.replace("command","ctrl"),i=i.replace("control","ctrl"),s.push(i)}s=s.sort((t,e)=>t[0]>e[0]?1:t[0]<e[0]?-1:0);for(let t of s)i+=t+"+";i+=e[e.length-1]}else i=t;e.push(i)}return e}prettifyKey(t){let e="";const i=this._prepareKey(t);for(let t=0;t<i.length;t++){const s=i[t];if(-1!==s.indexOf("+")){const t=s.toLowerCase().split("+");for(let i=0;i<t.length-1;i++){let s=t[i];e+=s[0].toUpperCase()+s.substr(1)+"+"}e+=t[t.length-1].toUpperCase()}else e=s.toUpperCase();t!==i.length-1&&(e+=" or ")}return e}register(t,e){const i=this._prepareKey(t);for(let t of i)this.keys[t]=t=>{e(t),t.preventDefault(),t.stopPropagation()}}_keyup(t){!this.alt||"AltLeft"!==t.code&&"AltRight"!==t.code||(this.alt.released(),this.alt.isPressed=!1)}_keydown(t){!this.alt||this.alt.isPressed||"AltLeft"!==t.code&&"AltRight"!==t.code||(this.alt.pressed(),this.alt.isPressed=!0,t.preventDefault());const e=[];t.altKey&&e.push("alt"),t.ctrlKey&&e.push("ctrl"),t.metaKey&&e.push("meta"),t.shiftKey&&e.push("shift");let i="";for(let t of e)i+=t+"+";let s=t.code.toLowerCase();s=s.replace("digit",""),s=s.replace("key",""),i+=s,this.menuKeys[i]?this.menuKeys[i](t):this.keys[i]&&this.keys[i](t)}};class p{constructor(t){c.init(),t=t||{},this.div=document.createElement("div"),this.styles=t.styles,this.children=[],this.applyConfig(d.MenuStyle),this.div.tabIndex=-1}append(t){t.submenu&&(t.submenu.menu=this),t.menu=this,this.div.appendChild(t.div),"separator"!==t.type&&this.children.push(t)}insert(t,e){t>=this.div.childNodes.length?this.append(e):(e.submenu&&(e.submenu.menu=this),e.menu=this,this.div.insertBefore(e.div,this.div.childNodes[t]),"separator"!==e.type&&this.children.splice(t,0,e))}hide(){let t=this.menu.showing;for(;t&&t.submenu;){t.div.style.backgroundColor="transparent",t.submenu.div.remove();let e=t.submenu.showing;e&&(t.submenu.showing.div.style.backgroundColor="transparent",t.submenu.showing=null),t=e}}show(t){if(c.unregisterMenuShortcuts(),this.menu&&this.menu.showing===t)this.hide(),this.menu.showing=null,this.div.remove(),this.menu.showAccelerators();else{this.menu&&(this.menu.showing&&-1!==this.menu.children.indexOf(t)&&this.hide(),this.menu.showing=t,this.menu.hideAccelerators());const e=t.div,i=this.menu.div;this.menu.applicationMenu?(this.div.style.left=e.offsetLeft+"px",this.div.style.top=e.offsetTop+e.offsetHeight+"px"):(this.div.style.left=i.offsetLeft+i.offsetWidth-d.Overlap+"px",this.div.style.top=i.offsetTop+e.offsetTop-d.Overlap+"px"),this.attached=t,this.showAccelerators(),p.application.appendChild(this.div);let s=0,o=0,n=0,h=0;for(let t of this.children)t.check.style.width="auto",t.label.style.width="auto",t.accelerator.style.width="auto",t.arrow.style.width="auto","checkbox"===t.type&&(h=d.MinimumColumnWidth),t.submenu&&(n=d.MinimumColumnWidth);for(let t of this.children){const e=2*t.label.offsetWidth;s=e>s?e:s;const i=t.accelerator.offsetWidth;o=i>o?i:o,t.submenu&&(n=t.arrow.offsetWidth)}for(let t of this.children)t.check.style.width=h+"px",t.label.style.width=s+"px",t.accelerator.style.width=o+"px",t.arrow.style.width=n+"px";this.div.offsetLeft+this.div.offsetWidth>window.innerWidth&&(this.div.style.left=window.innerWidth-this.div.offsetWidth+"px"),this.div.offsetTop+this.div.offsetHeight>window.innerHeight&&(this.div.style.top=window.innerHeight-this.div.offsetHeight+"px"),p.application.menu.div.focus()}}applyConfig(t){const e={};for(let i in t)e[i]=t[i];if(this.styles)for(let t in this.styles)e[t]=this.styles[t];for(let t in e)this.div.style[t]=e[t]}showAccelerators(){for(let t of this.children)if(t.showShortcut(),"separator"!==t.type){const e=t.text.indexOf("&");-1!==e&&c.registerMenuShortcut(t.text[e+1],t)}this.applicationMenu||c.registerMenuSpecial(this)}hideAccelerators(){for(let t of this.children)t.hideShortcut()}closeAll(){c.unregisterMenuShortcuts();let t=p.application.menu;if(t.showing){let e=t;for(;e.showing;)e=e.showing.submenu;for(;e&&!e.applicationMenu;)e.showing&&(e.showing.div.style.backgroundColor="transparent",e.showing=null),e.div.remove(),e=e.menu;e&&(e.showing.div.style.background="transparent",e.showing=null,e.hideAccelerators())}}moveChild(t){let e;if("left"===t){const t=this.selector.menu.menu;e=t.children.indexOf(t.showing),e--,e=e<0?t.children.length-1:e,t.children[e].handleClick()}else{let t=this.selector.menu.menu,i=t.showing;for(;!t.applicationMenu;)i.handleClick(),i.div.style.backgroundColor="transparent",t=t.menu,i=t.showing;e=t.children.indexOf(i),e++,e=e===t.children.length?0:e,t.children[e].handleClick()}this.selector=null}horizontalSelector(t,e){"right"===e?this.selector.submenu?(this.selector.handleClick(t),this.selector.submenu.selector=this.selector.submenu.children[0],this.selector.submenu.selector.div.style.backgroundColor=d.SelectedBackgroundStyle,this.selector=null):this.moveChild(e):"left"===e&&(this.selector.menu.menu.applicationMenu?this.moveChild(e):(this.selector.menu.attached.handleClick(t),this.selector.menu.menu.selector=this.selector.menu.attached,this.selector=null)),t.stopPropagation(),t.preventDefault()}move(t,e){if(this.selector){this.selector.div.style.backgroundColor="transparent";let i=this.children.indexOf(this.selector);if("down"===e)i++,i=i===this.children.length?0:i;else{if("up"!==e)return this.horizontalSelector(t,e);i--,i=i<0?this.children.length-1:i}this.selector=this.children[i]}else this.selector="up"===e?this.children[this.children.length-1]:this.children[0];this.selector&&(this.selector.div.style.backgroundColor=d.SelectedBackgroundStyle),t.preventDefault(),t.stopPropagation()}enter(t){this.selector&&(this.selector.handleClick(t),t.preventDefault(),t.stopPropagation())}get items(){return this.children}showApplicationAccelerators(){this.hideAccelerators(),c.registerAlt(()=>{this.showing||this.showAccelerators()},()=>{this.hideAccelerators()})}static get config(){return d}static getApplicationHeight(){return p.application?p.application.offsetHeight:0}static setApplicationMenu(t,i=document.body){c.clearMenuKeys(),p.application&&p.application.remove(),p.application=e({parent:i,styles:d.ApplicationContainerStyle}),p.application.menu=t,t.applyConfig(d.ApplicationMenuStyle);for(let e of t.children)e.applyConfig(d.ApplicationMenuRowStyle),e.arrow&&(e.arrow.style.display="none"),t.div.appendChild(e.div);p.application.appendChild(t.div),t.applicationMenu=!0,t.div.tabIndex=-1,t.div.addEventListener("focus",()=>{t.showing||t.div.blur()}),t.div.addEventListener("blur",()=>{t.showing&&t.closeAll()}),t.showApplicationAccelerators()}}class u extends h{constructor(t,e={}){super(),this.wm=t,this.options=e,this.id=void 0===this.options.id?u.id++:this.options.id,this._createWin(),this._createWinBox(),this._createTitlebar(),this._createContent(),this.options.resizable&&this._createResize(),this._createOverlay(),this._buildTransform(),this._listeners(),this.active=!1,this.maximized=!1,this._closed=!0,this._restore=null,this._moving=null,this._resizing=null,this._attachedToScreen={vertical:"",horziontal:""}}open(t){this._closed&&(this.win.style.display="block",this._closed=!1,this.emit("open",this),t||this.focus())}focus(){this.active=!0,this.options.titlebar&&(this.winTitlebar.style.backgroundColor=this.options.backgroundTitlebarActive),this.emit("focus",this)}blur(){this.active=!1,this.options.titlebar&&(this.winTitlebar.style.backgroundColor=this.options.backgroundTitlebarInactive),this.emit("blur",this)}close(){this._closed||(this._closed=!0,this.win.style.display="none",this.emit("close",this))}get closed(){return this._closed}get x(){return this.options.x}set x(t){t!==this.options.x&&(this.options.x=t,this.emit("move-x",this),this._buildTransform())}_buildTransform(){this.win.style.transform=`translate(${this.options.x}px,${this.options.y}px)`}get y(){return this.options.y}set y(t){t!==this.options.y&&(this.options.y=t,this._buildTransform(),this.emit("move-y",this))}get width(){return this.options.width||this.win.offsetWidth}set width(t){t!==this.options.width&&(t?(this.win.style.width=`${t}px`,this.options.width=this.win.offsetWidth):(this.win.style.width="auto",this.options.width=""),this.emit("resize-width",this))}get height(){return this.options.height||this.win.offsetHeight}set height(t){t!==this.options.height&&(t?(this.win.style.height=`${t}px`,this.options.height=this.win.offsetHeight):(this.win.style.height="auto",this.options.height=""),this.emit("resize-height",this))}resize(t,e){this.width=t,this.height=e}move(t,e){const i=this.keepInside;if(i){if(!0===i||"horizontal"===i){const e=this.wm.win.offsetWidth;t=(t=t+this.width>e?e-this.width:t)<0?0:t}if(!0===i||"vertical"===i){const t=this.wm.win.offsetHeight;e=e+this.height>t?t-this.height:e;const i=p.getApplicationHeight();e=e<i?i:e}}t!==this.options.x&&(this.options.x=t,this.emit("move-x",this)),e!==this.options.y&&(this.options.y=e,this.emit("move-y",this)),this._buildTransform()}maximize(){if(this.options.maximizable)if(this.maximized)this.x=this.maximized.x,this.y=this.maximized.y,this.width=this.maximized.width,this.height=this.maximized.height,this.maximized=null,this.emit("restore",this),this.buttons.maximize.innerHTML=this.options.maximizeButton;else{const t=this.x,e=this.y,i=this.win.offsetWidth,s=this.win.offsetHeight;this.maximized={x:t,y:e,width:i,height:s},this.x=0,this.y=0,this.width=this.wm.wallpaper.offsetWidth,this.height=this.wm.wallpaper.offsetHeight,this.emit("maximize",this),this.buttons.maximize.innerHTML=this.options.restoreButton}}sendToBack(){this.wm.sendToBack(this)}sendToFront(){this.wm.sendToFront(this)}save(){const t={},e=this.maximized;return e&&(t.maximized={left:e.left,top:e.top,width:e.width,height:e.height}),t.x=this.x,t.y=this.y,void 0!==this.options.width&&(t.width=this.options.width),void 0!==this.options.height&&(t.height=this.options.height),t.closed=this._closed,t}load(t){t.maximized?this.maximized||this.maximize(!0):this.maximized&&this.maximize(!0),void 0!==t.width?this.width=t.width:this.win.style.width="auto",void 0!==t.height?this.height=t.height:this.win.style.height="auto",this.move(t.x,t.y),t.closed?this.close(!0):this.closed&&this.open(!0,!0),this.emit("loaded")}get title(){return this._title}set title(t){this.winTitle.innerText=t,this.emit("title-change",this)}get right(){return this.x+this.width}set right(t){this.x=t-this.width}get bottom(){return this.y+this.height}set bottom(t){this.y=t-this.height}center(t){t?this.move(t.x+t.width/2-this.width/2,t.y+t.height/2-this.height/2):this.move(window.innerWidth/2-this.width/2,window.innerHeight/2-this.height/2)}_createWin(){this.win=e({parent:this.wm.win,styles:{display:"none","border-radius":this.options.borderRadius,"user-select":"none",overflow:"hidden",position:"absolute","min-width":this.options.minWidth,"min-height":this.options.minHeight,"background-color":this.options.backgroundWindow,width:isNaN(this.options.width)?this.options.width:this.options.width+"px",height:isNaN(this.options.height)?this.options.height:this.options.height+"px",...this.options.styles}})}_createWinBox(){this.winBox=e({parent:this.win,styles:{display:"flex","flex-direction":"column",width:"100%",height:"100%","min-height":this.options.minHeight}})}_createContent(){this.content=e({parent:this.winBox,type:"section",styles:{display:"block",flex:1,"min-height":this.options.minHeight,"margin-bottom":this.options.resizable?"15px":0,"overflow-x":"hidden","overflow-y":"auto"}})}_createOverlay(){this.overlay=e({parent:this.win,styles:{display:"none",position:"absolute",left:0,top:0,width:"100%",height:"100%"}}),this.overlay.addEventListener("mousedown",t=>{this._downTitlebar(t),t.stopPropagation()}),this.overlay.addEventListener("touchstart",t=>{this._downTitlebar(t),t.stopPropagation()})}_downTitlebar(t){const e=this._convertMoveEvent(t);this._moving={x:e.pageX-this.x,y:e.pageY-this.y},this.emit("move-start",this),this._moved=!1}_createTitlebar(){if(this.options.titlebar){this.winTitlebar=e({parent:this.winBox,type:"header",styles:{"user-select":"none",display:"flex","flex-direction":"row","align-items":"center","justify-content":"center",height:this.options.titlebarHeight,"min-height":this.options.titlebarHeight,border:0,padding:"0 8px",overflow:"hidden"}});const t={"user-select":"none",flex:1,display:"flex","flex-direction":"row","align-items":"center","user-select":"none",cursor:"default",padding:0,margin:0,"font-size":"16px","font-weight":400,color:this.options.foregroundTitle};this.options.titleCenter?t["justify-content"]="center":t["padding-left"]="8px",this.winTitle=e({parent:this.winTitlebar,type:"span",html:this.options.title,styles:t}),this._createButtons(),this.options.movable&&(this.winTitlebar.addEventListener("mousedown",t=>this._downTitlebar(t)),this.winTitlebar.addEventListener("touchstart",t=>this._downTitlebar(t))),this.options.maximizable&&r(this.winTitlebar,()=>this.maximize(),{doubleClicked:!0,clicked:!1})}}_createButtons(){this.winButtonGroup=e({parent:this.winTitlebar,styles:{display:"flex","flex-direction":"row","align-items":"center","padding-left":"10px"}});const t={display:"inline-block",border:0,margin:0,"margin-left":"15px",padding:0,width:"12px",height:"12px","background-color":"transparent","background-size":"cover","background-repeat":"no-repeat",opacity:.7,color:this.options.foregroundButton,outline:0};this.buttons={},this.options.maximizable&&(this.buttons.maximize=e({parent:this.winButtonGroup,html:this.options.maximizeButton,type:"button",styles:t}),r(this.buttons.maximize,()=>this.maximize())),this.options.closable&&(this.buttons.close=e({parent:this.winButtonGroup,html:this.options.closeButton,type:"button",styles:t}),r(this.buttons.close,()=>this.close()));for(let t in this.buttons){const e=this.buttons[t];e.addEventListener("mousemove",()=>{e.style.opacity=1}),e.addEventListener("mouseout",()=>{e.style.opacity=.7})}}_createResize(){this.resizeEdge=e({parent:this.winBox,type:"button",html:this.options.backgroundResize,styles:{position:"absolute",bottom:0,right:"4px",border:0,margin:0,padding:0,cursor:"se-resize","user-select":"none",height:"15px",width:"10px",background:"none"}});const t=t=>{const e=this._convertMoveEvent(t),i=this.width||this.win.offsetWidth,s=this.height||this.win.offsetHeight;this._resizing={width:i-e.pageX,height:s-e.pageY},this.emit("resize-start"),t.preventDefault()};this.resizeEdge.addEventListener("mousedown",t),this.resizeEdge.addEventListener("touchstart",t)}_move(t){const e=this._convertMoveEvent(t);this._isTouchEvent(t)||1===t.which||(this._moving&&this._stopMove(),this._resizing&&this._stopResize()),this._moving&&(this.move(e.pageX-this._moving.x,e.pageY-this._moving.y),this.emit("move",this),t.preventDefault()),this._resizing&&(this.resize(e.pageX+this._resizing.width,e.pageY+this._resizing.height),this.maximized=null,this.emit("resize",this),t.preventDefault())}_up(){this._moving&&this._stopMove(),this._resizing&&this._stopResize()}_listeners(){this.win.addEventListener("mousedown",()=>this.focus()),this.win.addEventListener("touchstart",()=>this.focus())}_stopMove(){this._moving=null,this.emit("move-end",this)}_stopResize(){this._restore=this._resizing=null,this.emit("resize-end",this)}_isTouchEvent(t){return!!window.TouchEvent&&t instanceof window.TouchEvent}_convertMoveEvent(t){return this._isTouchEvent(t)?t.changedTouches[0]:t}attachToScreen(t,e){this._attachedToScreen[t]=e}reposition(t,e){this.bounds=t,this.keepInside=e;let i=this.x,s=this.y;i="right"===this._attachedToScreen.horziontal?t.right-this.width:i,i="left"===this._attachedToScreen.horizontal?t.left:i,s="bottom"===this._attachedToScreen.vertical?t.bottom-this.height:s,s="top"===this._attachedToScreen.vertical?t.top:s,this.move(i,s)}isModal(t){return(t||!this._closed)&&this.options.modal}isClosed(){return this._closed}get z(){return parseInt(this.win.style.zIndex)}set z(t){this.win.style.zIndex=t}}u.id=0;const w={x:0,y:0,width:void 0,height:void 0,modal:!1,openOnCreate:!0,id:null,minWidth:"200px",minHeight:"60px",borderRadius:0,styles:{},movable:!0,resizable:!0,maximizable:!0,closable:!0,noSnap:!1,noMenu:!1,titlebar:!0,titlebarHeight:"2rem",backgroundWindow:"#fefefe",backgroundTitlebarActive:"#365d98",backgroundTitlebarInactive:"#888888",foregroundButton:"#ffffff",foregroundTitle:"#ffffff",closeButton:'<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"><rect id="close" x="0" y="0" width="20" height="20" style="fill:none;"/><g><path d="M3.5,3.5l13,13" style="fill:none;stroke:#fff;stroke-width:3px;"/><path d="M16.5,3.5l-13,13" style="fill:none;stroke:#fff;stroke-width:3px;"/></g></svg>',maximizeButton:'<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"><rect id="maximize" x="0" y="0" width="20" height="20" style="fill:none;"/><rect x="2" y="2" width="16" height="16" style="fill:none;stroke:#fff;stroke-width:2px;"/><rect x="2" y="2" width="16" height="3.2" style="fill:#fff;"/></svg>',restoreButton:'<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"><rect id="restore" x="0" y="0" width="20" height="20" style="fill:none;"/><g><rect x="7" y="2.5" width="10" height="10" style="fill:none;stroke:#fff;stroke-width:1.5px;"/><rect x="7" y="2.5" width="10" height="2" style="fill:#fff;"/></g><g><rect x="3" y="7.5" width="10" height="10" style="fill:none;stroke:#fff;stroke-width:1.5px;"/><g><rect x="3" y="7.5" width="10" height="2" style="fill:#fff;"/></g></g></svg>',backgroundResize:'<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><rect id="resize" x="0" y="0" width="20" height="20" style="fill:none;"/><clipPath id="_clip1"><rect x="0" y="0" width="20" height="20"/></clipPath><g clip-path="url(#_clip1)"><rect x="0" y="16.8" width="20" height="3.2" style="fill:#fff;"/><path d="M17.737,3.595l-14.142,14.142l2.263,2.263l14.142,-14.142l-2.263,-2.263Z" style="fill:#fff;"/><path d="M16.8,0l0,20l3.2,0l0,-20l-3.2,0Z" style="fill:#fff;"/><path d="M7.099,18.4l11.301,-11.123l0,11.123l-11.301,0Z" style="fill:#fff;"/></g></svg>'},f={quiet:!1,keepInside:!0,snap:!0,noAccelerator:!1,menu:!1,styles:{},backgroundModal:"rgba(0, 0, 0, 0.6)"},m={screen:!0,windows:!0,snap:20,color:"#a8f0f4",spacing:0,indicator:10};class g{constructor(t,i={}){this.wm=t,this.options={...m,...i},this.highlights=e({parent:this.wm.wallpaper,styles:{position:"absolute"}}),this.horizontal=e({parent:this.highlights,styles:{display:"none",position:"absolute",height:`${this.options.indicator}px`,borderRadius:`${this.options.indicator}px`,backgroundColor:this.options.color}}),this.vertical=e({parent:this.highlights,styles:{display:"none",position:"absolute",width:`${this.options.indicator}px`,borderRadius:`${this.options.indicator}px`,backgroundColor:this.options.color}}),this.horizontal,this.showing=[]}stop(){this.highlights.remove(),this.stopped=!0}addWindow(t){t.on("move",()=>this.move(t)),t.on("move-end",()=>this.moveEnd(t))}screenMove(t,e,i){const s=p.getApplicationHeight(),o=this.wm.win.clientWidth,n=this.wm.win.clientHeight;t.left-this.options.snap<=o&&t.right+this.options.snap>=0&&(Math.abs(t.top-s)<=this.options.snap?e.push({distance:Math.abs(t.top-s),left:0,width:o,top:s,side:"top",screen:!0}):Math.abs(t.bottom-n)<=this.options.snap&&e.push({distance:Math.abs(t.bottom-n),left:0,width:o,top:n,side:"bottom",screen:!0})),t.top-this.options.snap<=n&&t.bottom+this.options.snap>=0&&(Math.abs(t.left-0)<=this.options.snap?i.push({distance:Math.abs(t.left-0),top:0,height:n,left:0,side:"left",screen:!0}):Math.abs(t.right-o)<=this.options.snap&&i.push({distance:Math.abs(t.right-o),top:0,height:n,left:o,side:"right",screen:!0}))}windowsMove(t,e,i,s){for(let o of this.wm.windows)if(!o.options.noSnap&&o!==t){const t=o.win.getBoundingClientRect();e.left-this.options.snap<=t.right&&e.right+this.options.snap>=t.left&&(Math.abs(e.top-t.bottom)<=this.options.snap?(i.push({distance:Math.abs(e.top-t.bottom),left:t.left,width:t.width,top:t.bottom,side:"top"}),Math.abs(e.left-t.left)<=this.options.snap?s.push({distance:Math.abs(e.left-t.left),top:t.top,height:t.height,left:t.left,side:"left",noSpacing:!0}):Math.abs(e.right-t.right)<=this.options.snap&&s.push({distance:Math.abs(e.right-t.right),top:t.top,height:t.height,left:t.right,side:"right",noSpacing:!0})):Math.abs(e.bottom-t.top)<=this.options.snap&&(i.push({distance:Math.abs(e.bottom-t.top),left:t.left,width:t.width,top:t.top,side:"bottom"}),Math.abs(e.left-t.left)<=this.options.snap?s.push({distance:Math.abs(e.left-t.left),top:t.top,height:t.height,left:t.left,side:"left",noSpacing:!0}):Math.abs(e.right-t.right)<=this.options.snap&&s.push({distance:Math.abs(e.right-t.right),top:t.top,height:t.height,left:t.right,side:"right",noSpacing:!0}))),e.top-this.options.snap<=t.bottom&&e.bottom+this.options.snap>=t.top&&(Math.abs(e.left-t.right)<=this.options.snap?(s.push({distance:Math.abs(e.left-t.right),top:t.top,height:t.height,left:t.right,side:"left"}),Math.abs(e.top-t.top)<=this.options.snap?i.push({distance:Math.abs(e.top-t.top),left:t.left,width:t.width,top:t.top,side:"top",noSpacing:!0}):Math.abs(e.bottom-t.bottom)<=this.options.snap&&i.push({distance:Math.abs(e.bottom-t.bottom),left:t.left,width:t.width,top:t.bottom,side:"bottom",noSpacing:!0})):Math.abs(e.right-t.left)<=this.options.snap&&(s.push({distance:Math.abs(e.right-t.left),top:t.top,height:t.height,left:t.left,side:"right"}),Math.abs(e.top-t.top)<=this.options.snap?i.push({distance:Math.abs(e.top-t.top),left:t.left,width:t.width,top:t.top,side:"top",noSpacing:!0}):Math.abs(e.bottom-t.bottom)<=this.options.snap&&i.push({distance:Math.abs(e.bottom-t.bottom),left:t.left,width:t.width,top:t.bottom,side:"bottom",noSpacing:!0})))}}move(t){if(this.stopped||t.options.noSnap||t.isModal())return;this.horizontal.style.display="none",this.vertical.style.display="none";const e=[],i=[],s=t.win.getBoundingClientRect();if(this.options.screen&&this.screenMove(s,e,i),this.options.windows&&this.windowsMove(t,s,e,i),e.length){e.sort((t,e)=>t.distance-e.distance);const t=e[0];this.horizontal.style.display="block",this.horizontal.style.width=t.width+"px",this.horizontal.y=t.top-this.options.indicator/2,this.horizontal.yPosition=t.top,this.horizontal.style.transform=`translate(${t.left}px,${this.horizontal.y}px)`,this.horizontal.side=t.side,this.horizontal.noSpacing=t.noSpacing,this.horizontal.screen=t.screen}if(i.length){i.sort((t,e)=>t.distance-e.distance);const t=i[0];this.vertical.style.display="block",this.vertical.style.height=t.height+"px",this.vertical.x=t.left-this.options.indicator/2,this.vertical.xPosition=t.left,this.vertical.style.transform=`translate(${this.vertical.x}px,${t.top}px)`,this.vertical.side=t.side,this.vertical.noSpacing=t.noSpacing,this.vertical.screen=t.screen}}moveEnd(t){if(this.stopped)return;const e=this.wm.bounds,i=p.getApplicationHeight();if("block"===this.horizontal.style.display){const s=this.horizontal.noSpacing?0:this.options.spacing;switch(this.horizontal.side){case"top":t.y=this.horizontal.yPosition+s-e.top+i;break;case"bottom":t.bottom=Math.floor(this.horizontal.yPosition-s-e.top+i)}t.attachToScreen("vertical",this.horizontal.screen?this.horizontal.side:"")}if("block"===this.vertical.style.display){const i=this.vertical.noSpacing?0:this.options.spacing;switch(this.vertical.side){case"left":t.x=this.vertical.xPosition+i-e.left;break;case"right":t.right=Math.floor(this.vertical.xPosition-i-e.left)}t.attachToScreen("horziontal",this.vertical.screen?this.vertical.side:"")}this.horizontal.style.display=this.vertical.style.display="none"}}t.WindowManager=class{constructor(t={},e={}){this.options={...f,...t},this.options.parent=this.options.parent||document.body,this.options.quiet||console.log("%c ☕ simple-window-manager initialized ☕","color: #ff00ff"),this.windows=[],this.active=null,this._setupWin(),this._setupWallpaper(),this._setupModal(),this.options.snap&&this.snap(!0===this.options.snap?{}:this.options.snap),this.windowOptions={...w,...e},window.addEventListener("resize",()=>this.resize()),this.options.noAccelerator||c.init()}createWindow(t={}){const e=new u(this,{...this.windowOptions,...t});return e.on("open",()=>this._open(e)),e.on("focus",()=>this._focus(e)),e.on("blur",()=>this._blur(e)),e.on("close",()=>this._close(e)),e.win.addEventListener("mousemove",t=>this._move(t)),e.win.addEventListener("touchmove",t=>this._move(t)),e.win.addEventListener("mouseup",t=>this._up(t)),e.win.addEventListener("touchend",t=>this._up(t)),this._snap&&!t.noSnap&&this._snap.addWindow(e),e.reposition(this.bounds,this.options.keepInside),e.options.openOnCreate&&e.open(),e}snap(t){this._snap=new g(this,t);for(const t of this.windows)t.options.noSnap||this._snap.addWindow(t)}sendToFront(t){const e=this.windows.indexOf(t);console.assert(-1!==e,"sendToFront should find window in this.windows"),e!==this.windows.length-1&&(this.windows.splice(e,1),this.windows.push(t),this._reorder())}sendToBack(t){const e=this.windows.indexOf(t);console.assert(-1!==e,"sendToFront should find window in this.windows"),0!==e&&(this.windows.splice(e,1),this.windows.unshift(t),this._reorder())}save(){const t={};for(let e=0;e<this.windows.length;e++){const i=this.windows[e];t[i.id]=i.save(),t[i.id].order=e}return t}load(t){for(const e in t){const i=this.getWindowById(e);i&&i.load(t[e])}}closeAll(){for(let t of this.windows)t.close();this.windows=[],this.active=null}_reorder(){let t=0;for(const e of this.windows)e.isClosed()||(e.z=t++)}_setupWin(){this.win=e({parent:this.options.parent,styles:{"user-select":"none",width:"100%",height:"100%",overflow:"hidden","z-index":-1,cursor:"default",...this.options.styles}})}_setupWallpaper(){this.wallpaper=e({parent:this.win,styles:{"user-select":"none",position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden"}}),this.wallpaper.addEventListener("mousemove",t=>this._move(t)),this.wallpaper.addEventListener("touchmove",t=>this._move(t)),this.wallpaper.addEventListener("mouseup",t=>this._up(t)),this.wallpaper.addEventListener("touchend",t=>this._up(t))}_setupModal(){this.modalOverlay=e({parent:this.win,styles:{display:"none","user-select":"none",position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden",background:this.options.backgroundModal}}),this.modalOverlay.addEventListener("mousemove",t=>{this._move(t),t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("touchmove",t=>{this._move(t),t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("mouseup",t=>{this._up(t),t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("touchend",t=>{this._up(t),t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation()}),this.modalOverlay.addEventListener("touchstart",t=>{t.preventDefault(),t.stopPropagation()})}_open(t){this.windows.push(t),this._reorder(),t.options.modal?(this.modalOverlay.style.display="block",this.modalOverlay.style.zIndex=t.z):this.modalOverlay.style.display="none"}_focus(t){if(this.active===t)return;this.active&&this.active.blur();const e=this.windows.indexOf(t);console.assert(-1!==e,"WindowManager._focus should find window in this.windows"),e!==this.windows.length-1&&(this.windows.splice(e,1),this.windows.push(t)),this._reorder(),this.active=this.windows[this.windows.length-1]}_blur(t){this.active===t&&(this.active=null)}_close(t){if(t.isModal(!0)){const t=this.windows[this.windows.length-1];t&&t.isModal()?this.modalOverlay.style.zIndex=t.z:this.modalOverlay.style.display="none"}}_move(t){for(const e in this.windows)this.windows[e]._move(t)}_up(t){for(const e in this.windows)this.windows[e]._up(t)}checkModal(t){return!this.modal||this.modal===t}get bounds(){const t=p.getApplicationHeight();return{top:this.win.offsetTop+t,bottom:this.win.offsetTop+this.win.offsetHeight,left:this.win.offsetLeft,right:this.win.offsetLeft+this.win.offsetWidth}}resize(){const t=this.bounds;for(const e in this.windows)this.windows[e].reposition(t,this.options.keepInside)}getWindowById(t){return this.windows.find(e=>e.id===t)}}});
2
2
  //# sourceMappingURL=simple-window-manager.min.js.map