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);import{q as e}from"./index.34872ab0.1730902649514.js";let s=[],n=null;const h={subject:[],closeLast(){const i=s.pop();return i?(i.close(),!0):(this.emit("refresh",s),!1)},closeAll(){let i=this.closeLast();for(;i;)i=this.closeLast();this.emit("refresh",s)},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:n=!1,ico:h=!1,width:a=!1,height:o=!1,title:M="",origin:l={},minHeight:d=0,minWidth:N=0,minWindow:g=300,maxWindow:I="",custom:j={}}=i;n&&(this.url=n),j||(j={});const{immersion:c=!1,controllerColor:r="#ffffff",minimization:m=1,maximize:z=1,resize:u=1}=j;this.resize=u,(c||/^\//.test(this.url))&&(this.immersion=!0),this.url=e(this.url),r&&(this.controllerColor=r),this.minimization=m,this.maximize=z,this.ico=e(h),a&&(this.width=a),j&&(this.custom=j),document.querySelector(".footer-component")||(this.footerHeight=0,this.minimization=!1),o&&(this.height=o,this.height>window.innerHeight&&(this.height=window.innerHeight)),this.minWindow=g,this.maxWindow=I,N&&(this.minWidth=N),d&&(this.minHeight=d,this.minHeight>window.innerHeight&&(this.minHeight=window.innerHeight)),window.innerWidth<500&&(this.width=window.innerWidth,this.height=window.innerHeight,this.minimization=!1,this.maximize=!1,this.borderRadius="0px"),this.origin=l,this.title=M,s.push(this)}setTitle(i=""){this.immersion||(this.title=i.length>0?i:this.title,this.titleHandle=document.createElement("div"),this.titleHandle.innerHTML=`${/^txt:/.test(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":"8px",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":"8px",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":"8px",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;s.forEach((e=>{e.zIndex>i&&(i=e.zIndex,t=e)})),t.uid!==this.uid&&(n=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,this.iframeHandle.className="WebAppEngine",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,n=Math.floor((e-i)/2);let h=Math.floor((s-(document.querySelector(".footer-component")?77:0)-t)/2);return this.height>=window.innerHeight-77&&(h=0),{x:n,y:h}}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),h.emit("refresh",s)}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),s.forEach(((i,t)=>{i.uid===this.uid&&s.splice(t,1)})),document.body.removeChild(this.dialogHandle),h.emit("refresh",s)}}window.MtabManager=h,window.WebAppEngineTime&&clearInterval(window.WebAppEngineTime),window.WebAppEngineTime=setInterval((()=>{if(s.length>0){const i=function(){const i=document.activeElement;return i&&"WebAppEngine"===i.className?i:null}();if(i){let t=i.dataset.uid;if(t!==n){const i=s.find((i=>i.uid===t));i&&(n=t,i.resetIndex())}}}}),200),window.MtabUi=o;export{o as M,s as d};