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();let{url:s=!1,ico:n=!1,width:M=!1,height:h=!1,title:a="",origin:o={},minHeight:l=0,minWidth:d=0,minWindow:N=300,maxWindow:I="",custom:g={}}=i;s&&(this.url=s),g||(g={});const{immersion:j=!1,controllerColor:c="#ffffff",minimization:r=1,maximize:m=1,resize:z=1}=g;this.resize=z,(j||/^\//.test(this.url))&&(this.immersion=!0),c&&(this.controllerColor=c),this.minimization=r,this.maximize=m,this.ico=n,M&&(this.width=M),this.minWindow=N,this.maxWindow=I,window.innerWidth<600&&(this.minWindow=!1,this.maxWindow=!1),g&&(this.custom=g),document.querySelector(".footer-component")||(this.footerHeight=0,this.minimization=!1),h&&(this.height=h),d&&(this.minWidth=d),l&&(this.minHeight=l),window.innerWidth<500&&(this.width=window.innerWidth,this.height=window.innerHeight,this.borderRadius="0px"),this.origin=o,this.title=a,e.push(this)}setTitle(i=""){this.immersion||(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))}getTextColor(i){return.299*parseInt(i.substring(1,3),16)+.587*parseInt(i.substring(3,5),16)+.114*parseInt(i.substring(5,7),16)>186?"#000000":"#ffffff"}Frame(){this.frameHandle=document.createElement("div"),this.frameHandle.dataset.drag="move",Object.assign(this.frameHandle.style,{position:"absolute",background:this.immersion?"transparent":this.controllerColor,color:this.getTextColor(this.controllerColor||"#ffffff"),top:"0px",left:"0px",borderRadius:"8px 8px 0px 0px",width:"100%",display:"flex",height:this.immersion?"15px":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.maximize&&this.setFull());this.lastClickTime=(new Date).getTime();const{x:t,y:e,layerX:s,layerY:n}=i;this.movePoint.x=t,this.movePoint.y=e,this.movePoint.layerX=s,this.movePoint.layerY=n,this.iframeHandle.style.pointerEvents="none",this.isMove=!0}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"}),1===parseInt(this.minimization)&&this.miniFrame(i),1===parseInt(this.maximize)&&this.fullFrame(i),this.closeFrame(i),this.frameHandle.appendChild(i),this.frameHandle}closeFrame(i){let t=document.createElement("div");t.className="window-close",t.title="关闭窗口",Object.assign(t.style,{marginTop:this.immersion?"10px":"7px",width:this.controllerSize,height:this.controllerSize,marginRight:"10px"}),t.onclick=i=>{this.close(),i.stopPropagation()},i.appendChild(t)}fullFrame(i){let t=document.createElement("div");t.className="window-full",t.title="最大化窗口",Object.assign(t.style,{marginTop:this.immersion?"10px":"7px",width:this.controllerSize,height:this.controllerSize,display:"flex",userSelect:"none"}),t.onclick=()=>{this.setFull()},i.appendChild(t)}miniFrame(i){let t=document.createElement("div");t.className="window-mini",t.title="最小化",t.onclick=()=>{this.setMineSize()},Object.assign(t.style,{marginTop:this.immersion?"10px":"7px",width:this.controllerSize,height:this.controllerSize,display:"flex",userSelect:"none"}),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:"40px",height:this.px(this.headerHeight),display:"flex",userSelect:"none"}),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))}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.immersion?0:this.px(this.headerHeight),border:"none",outline:"none",transform:"scale(1)",width:"100%",height:this.immersion?"100%":`calc(100% - ${this.px(this.headerHeight)})`}),this.iframeHandle.onload=()=>{setTimeout((()=>{this.immersion&&(this.dialogHandle.style.background="transparent")}),500)},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:this.controllerColor,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:this.resize>0?"auto":"none",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=M;export{s as M,M as a,e as d};