var i=Object.defineProperty,t=(t,e,s)=>(((t,e,s)=>{e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(t,"symbol"!=typeof e?e+"":e,s),s),e=[];const s={subject:[],closeLast(){const i=e.pop();return i?(i.close(),!0):(this.emit("refresh",e),!1)},closeAll(){let i=this.closeLast();for(;i;)i=this.closeLast();this.emit("refresh",e)},on(i,t){this.subject.push({event:i,callback:t})},off(i,t){if(i)for(let e=0;e"xxxxxxxx-xxx-xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(i){const t=16*Math.random()|0;return("x"===i?t:3&t|8).toString(16)})))),t(this,"windowMove",(i=>{if(this.isMove){const{x:t,y:e}=i;this.isFull||this.setPosition(t-this.movePoint.layerX,e-this.movePoint.layerY)}})),t(this,"windowMouseUp",(()=>{this.isMove=!1,this.iframeHandle.style.pointerEvents="",this.frameHandle.style.cursor=""})),this.lastClickTime=(new Date).getTime(),this.uid=this.uuid();const{url:s=!1,ico:h=!1,width:n=!1,height:M=!1,top:a=!1,left:l=!1,title:d="",origin:o={},minHeight:g=0,minWidth:c=0,minWindow:j=!0,maxWindow:r=!0}=i;s&&(this.url=s),this.ico=h,n&&(this.width=n),this.minWindow=j,this.maxWindow=r,M&&(this.height=M),c&&(this.minWidth=c),g&&(this.minHeight=g),window.innerWidth<500&&(this.width=window.innerWidth,this.height=window.innerHeight,this.borderRadius="0px"),this.origin=o,this.title=d,e.push(this)}setTitle(i=""){this.title=i.length>0?i:this.title,this.titleHandle=document.createElement("div"),this.titleHandle.innerHTML=`${this.ico?`ico`:""}${this.title}`,Object.assign(this.titleHandle.style,{marginLeft:"5px",display:"flex",fontSize:"15px",pointerEvents:"none",alignItems:"center",height:this.px(this.headerHeight)}),this.frameHandle.appendChild(this.titleHandle)}Frame(){this.frameHandle=document.createElement("div"),this.frameHandle.dataset.drag="move",Object.assign(this.frameHandle.style,{position:"absolute",background:"rgba(255,255,255,1)",top:"0px",left:"0px",borderRadius:"8px 8px 0px 0px",width:"100%",display:"flex",height:this.px(this.headerHeight),userSelect:"none"}),this.frameHandle.onmousedown=i=>{const{drag:t=""}=i.target.dataset;if("move"===t){if(this.lastClickTime>(new Date).getTime()-500)return void(this.maxWindow&&this.setFull());this.lastClickTime=(new Date).getTime();const{x:t,y:e,layerX:s,layerY:h}=i;this.movePoint.x=t,this.movePoint.y=e,this.movePoint.layerX=s,this.movePoint.layerY=h,this.iframeHandle.style.pointerEvents="none",this.isMove=!0,this.frameHandle.style.cursor="move"}this.resetIndex()},this.setTitle(this.title);const i=document.createElement("div");return Object.assign(i.style,{marginLeft:"auto",width:"max-content",height:"100%",display:"flex"}),this.refreshFrame(i),this.minWindow&&this.miniFrame(i),this.maxWindow&&this.fullFrame(i),this.closeFrame(i),this.frameHandle.appendChild(i),this.frameHandle}closeFrame(i){let t=document.createElement("div");t.className="window-close",t.innerHTML='close',t.title="关闭窗口",Object.assign(t.style,{width:"50px",height:this.px(this.headerHeight),display:"flex",marginLeft:"auto"}),t.onclick=i=>{this.close(),i.stopPropagation()},i.appendChild(t)}fullFrame(i){let t=document.createElement("div");t.className="window-full",t.innerHTML='close',t.title="最大化窗口",Object.assign(t.style,{width:"50px",height:this.px(this.headerHeight),display:"flex",userSelect:"none",marginLeft:"auto"}),t.onclick=()=>{this.setFull()},i.appendChild(t)}refreshFrame(i){if(/^http/.test(this.url))return!1;let t=document.createElement("div");t.className="window-refresh",t.innerHTML='refresh',t.title="刷新",Object.assign(t.style,{width:"50px",height:this.px(this.headerHeight),display:"flex",userSelect:"none",marginLeft:"auto"}),t.onclick=()=>{this.iframeHandle.contentWindow.location.reload()},i.appendChild(t)}setFull(){this.tmpTime&&this.tmpTime>(new Date).getTime()-500||(this.tmpTime=(new Date).getTime(),this.isFull?(Object.assign(this.dialogHandle.style,{width:this.px(this.lastSize.width),height:this.px(this.lastSize.height),left:this.px(this.lastSize.left),top:this.px(this.lastSize.top)}),setTimeout((()=>{Object.assign(this.dialogHandle.style,{transition:"none"})}),300),this.isFull=!1):(Object.assign(this.dialogHandle.style,{transition:"all .3s"}),Object.assign(this.dialogHandle.style,{width:"100%",height:`calc(100% - ${this.footerHeight}px)`,left:"0px",top:"0px"}),this.lastSize={left:this.left,top:this.top,width:this.width,height:this.height},this.isFull=!0))}miniFrame(i){let t=document.createElement("div");t.className="window-mini",t.innerHTML='close',t.title="最小化",t.onclick=()=>{this.setMineSize()},Object.assign(t.style,{width:"50px",height:this.px(this.headerHeight),display:"flex",userSelect:"none",marginLeft:"auto"}),i.appendChild(t)}resetIndex(){let i=0,t=null;e.forEach((e=>{e.zIndex>i&&(i=e.zIndex,t=e)})),t.uid!==this.uid&&(i+=1),this.setZIndex(i)}Iframe(){return this.iframeHandle=document.createElement("iframe"),this.iframeHandle.src=this.url,this.iframeHandle.dataset.uid=this.uid,Object.assign(this.iframeHandle.style,{position:"absolute",top:this.px(this.headerHeight),border:"none",outline:"none",transform:"scale(1)",width:"100%",height:`calc(100% - ${this.px(this.headerHeight)})`}),this.iframeHandle}px(i){return i+"px"}getElementCenterPosition(i,t){const e=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,s=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;return{x:Math.floor((e-i)/2),y:Math.floor((s-t)/2)}}setPosition(i=0,t=0){i<0&&(i=0),i>window.innerWidth-this.width&&(i=window.innerWidth-this.width),t<0&&(t=0),t>window.innerHeight-this.height&&(t=window.innerHeight-this.height),this.left=i,this.top=t,Object.assign(this.dialogHandle.style,{left:this.px(i),top:this.px(t)})}setZIndex(i=1e3){this.zIndex=i,this.dialogHandle.style.zIndex=this.zIndex}append(){document.body.appendChild(this.dialogHandle),s.emit("refresh",e)}setMineSize(){!0===this.isMinimize?(this.dialogHandle.style.display="block",this.isMinimize=!1):(this.dialogHandle.style.display="none",this.isMinimize=!0)}open(){this.dialogHandle=document.createElement("div");const{x:i,y:t}=this.getElementCenterPosition(this.width,this.height);this.left=i,this.top=t,this.dialogHandle.className="mtabUi-dialog",Object.assign(this.dialogHandle.style,{position:"fixed",background:"#fff",width:this.px(this.width),height:this.px(this.height),left:this.px(i),top:this.px(t),minWidth:this.px(this.minWidth),minHeight:this.px(this.minHeight),resize:"auto",borderRadius:this.borderRadius}),this.dialogHandle.appendChild(this.Iframe()),this.dialogHandle.appendChild(this.Frame()),this.append(),this.bindEvent(),this.resetIndex()}bindEvent(){window.addEventListener("mousemove",this.windowMove),window.addEventListener("mouseup",this.windowMouseUp);new MutationObserver((i=>{i.forEach((i=>{this.width=this.dialogHandle.clientWidth,this.height=this.dialogHandle.clientHeight}))})).observe(this.dialogHandle,{attributes:!0,childList:!1,subtree:!1})}close(){window.removeEventListener("mousemove",this.windowMove),window.removeEventListener("mouseup",this.windowMouseUp),e.forEach(((i,t)=>{i.uid===this.uid&&e.splice(t,1)})),document.body.removeChild(this.dialogHandle),s.emit("refresh",e)}}window.MtabManager=s,window.MtabUi=n;export{s as M,n as a,e as d};