@netless/telebox-insider 1.0.0-alpha.3 → 1.0.0-alpha.32

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 (38) hide show
  1. package/dist/TeleBox/index.d.ts +62 -38
  2. package/dist/TeleBox/typings.d.ts +28 -16
  3. package/dist/TeleBox/utils.d.ts +5 -0
  4. package/dist/TeleBoxCollector/index.d.ts +7 -8
  5. package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +1 -1
  6. package/dist/TeleBoxManager/index.d.ts +15 -5
  7. package/dist/TeleBoxManager/typings.d.ts +50 -6
  8. package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +4 -12
  9. package/dist/TeleTitleBar/typings.d.ts +2 -2
  10. package/dist/index.d.ts +0 -1
  11. package/dist/style.css +650 -1
  12. package/dist/telebox-insider.cjs.js +1659 -1
  13. package/dist/telebox-insider.cjs.js.map +1 -1
  14. package/dist/telebox-insider.es.js +1641 -1
  15. package/dist/telebox-insider.es.js.map +1 -1
  16. package/dist/utils.d.ts +0 -1
  17. package/package.json +67 -67
  18. package/src/TeleBox/index.ts +443 -300
  19. package/src/TeleBox/style.scss +13 -25
  20. package/src/TeleBox/style.shadow.scss +77 -0
  21. package/src/TeleBox/typings.ts +28 -16
  22. package/src/TeleBox/utils.ts +32 -0
  23. package/src/TeleBoxCollector/index.ts +41 -38
  24. package/src/TeleBoxCollector/style.scss +6 -4
  25. package/src/TeleBoxManager/MaxTitleBar/index.ts +3 -28
  26. package/src/TeleBoxManager/MaxTitleBar/style.scss +18 -16
  27. package/src/TeleBoxManager/index.ts +187 -80
  28. package/src/TeleBoxManager/style.scss +55 -0
  29. package/src/TeleBoxManager/typings.ts +69 -7
  30. package/src/TeleTitleBar/DefaultTitleBar/index.ts +47 -61
  31. package/src/TeleTitleBar/DefaultTitleBar/style.scss +30 -10
  32. package/src/TeleTitleBar/typings.ts +2 -2
  33. package/src/index.ts +0 -2
  34. package/src/scss/variables.scss +72 -0
  35. package/src/utils.ts +0 -6
  36. package/dist/TeleStage/index.d.ts +0 -21
  37. package/src/TeleStage/index.ts +0 -178
  38. package/src/TeleStage/style.scss +0 -49
@@ -1,2 +1,1642 @@
1
- var e=Object.defineProperty,t=Object.defineProperties,i=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,n=(t,i,s)=>i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[i]=s,o=(e,t)=>{for(var i in t||(t={}))a.call(t,i)&&n(e,i,t[i]);if(s)for(var i of s(t))r.call(t,i)&&n(e,i,t[i]);return e};import h from"emittery";import l from"stylefire";import d from"shallowequal";import{SideEffectManager as c,genUID as m}from"side-effect-manager";import{Val as u,combine as x,withReadonlyValueEnhancer as g,withValueEnhancer as p}from"value-enhancer";import{ResizeObserver as f}from"@juggle/resize-observer";var $,b,v,w,C,y,E,z,B,_;(b=$||($={})).Light="light",b.Dark="dark",b.Auto="auto",(w=v||(v={})).Normal="normal",w.Minimized="minimized",w.Maximized="maximized",(y=C||(C={})).DarkMode="dark_mode",y.PrefersColorScheme="prefers_color_scheme",y.Close="close",y.Focus="focus",y.Blur="blur",y.IntrinsicMove="intrinsic_move",y.IntrinsicResize="intrinsic_resize",y.ZIndex="z_index",y.State="state",y.Minimized="minimized",y.Maximized="maximized",y.Readonly="readonly",y.Destroyed="destroyed",(z=E||(E={})).Close="close",z.Maximize="maximize",z.Minimize="minimize",(_=B||(B={})).North="n",_.South="s",_.West="w",_.East="e",_.NorthWest="nw",_.NorthEast="ne",_.SouthEast="se",_.SouthWest="sw";const N="dh";function M(e,t,i){return Math.min(Math.max(e,t),i)}function S(e){e.stopPropagation(),e.cancelable&&e.preventDefault()}function I(e){return e.touches?e.touches[0]:e}let k=1;function R(){return"New Box "+k++}function L(e){return Boolean(e)}function D(e){return!e}class T{constructor({readonly$:e,state$:t,title:i="",buttons:s,onEvent:a,onDragStart:r,namespace:n="telebox"}){this.sideEffect=new c,this.lastTitleBarClick={timestamp:0,clientX:-100,clientY:-100},this.handleTitleBarClick=e=>{var t;if(this.readonly$.value)return;if(0!==e.button)return;if(null==(t=e.target.dataset)?void 0:t.teleTitleBarNoDblClick)return;S(e);const i=Date.now();i-this.lastTitleBarClick.timestamp<=500?Math.abs(e.clientX-this.lastTitleBarClick.clientX)<=5&&Math.abs(e.clientY-this.lastTitleBarClick.clientY)<=5&&this.onEvent&&this.onEvent({type:E.Maximize}):this.onDragStart&&this.onDragStart(e),this.lastTitleBarClick.timestamp=i,this.lastTitleBarClick.clientX=e.clientX,this.lastTitleBarClick.clientY=e.clientY},this.lastTitleBarTouch={timestamp:0,clientX:-100,clientY:-100},this.handleTitleBarTouch=e=>{var t;if(this.readonly$.value)return;if(null==(t=e.target.dataset)?void 0:t.teleTitleBarNoDblClick)return;S(e);const i=Date.now(),{clientX:s=this.lastTitleBarTouch.clientX+100,clientY:a=this.lastTitleBarTouch.clientY+100}=e.touches[0]||{};i-this.lastTitleBarTouch.timestamp<=500?Math.abs(s-this.lastTitleBarTouch.clientX)<=10&&Math.abs(a-this.lastTitleBarTouch.clientY)<=10&&this.onEvent&&this.onEvent({type:E.Maximize}):this.onDragStart&&this.onDragStart(e),this.lastTitleBarTouch.timestamp=i,this.lastTitleBarTouch.clientX=s,this.lastTitleBarTouch.clientY=a},this.readonly$=e,this.state$=t,this.title$=new u(i),this.onEvent=a,this.onDragStart=r,this.namespace=n,this.buttons=s||[{type:E.Minimize,iconClassName:this.wrapClassName("titlebar-icon-minimize")},{type:E.Maximize,iconClassName:this.wrapClassName("titlebar-icon-maximize"),isActive:e=>e===v.Maximized},{type:E.Close,iconClassName:this.wrapClassName("titlebar-icon-close")}],this.$dragArea=this.renderDragArea()}get title(){return this.title$.value}setTitle(e){this.title$.setValue(e)}render(){if(!this.$titleBar){this.$titleBar=document.createElement("div"),this.$titleBar.className=this.wrapClassName("titlebar");const e=document.createElement("div");e.className=this.wrapClassName("title-area"),e.dataset.teleBoxHandle="dh";const t=document.createElement("h1");t.className=this.wrapClassName("title"),t.dataset.teleBoxHandle="dh",e.appendChild(t),e.appendChild(this.$dragArea);const i=document.createElement("div");i.className=this.wrapClassName("titlebar-btns"),this.buttons.forEach((({iconClassName:e},t)=>{const s=String(t),a=document.createElement("button");a.className=`${this.wrapClassName("titlebar-btn")} ${e}`,a.dataset.teleTitleBarBtnIndex=s,a.dataset.teleTitleBarNoDblClick="true",i.appendChild(a)})),this.sideEffect.addDisposer(this.title$.subscribe((e=>{t.textContent=e,t.title=e})),"render-title"),this.sideEffect.addDisposer(this.state$.subscribe((e=>{this.buttons.forEach(((t,s)=>{var a;t.isActive&&(null==(a=i.children[s])||a.classList.toggle("is-active",t.isActive(e)))}))})),"render-state-btns"),this.sideEffect.addEventListener(i,"click",(e=>{var t;if(this.readonly$.value)return;const i=e.target,s=Number(null==(t=i.dataset)?void 0:t.teleTitleBarBtnIndex);if(!Number.isNaN(s)&&s<this.buttons.length){S(e);const t=this.buttons[s];this.onEvent&&this.onEvent({type:t.type,value:t.value})}}),{},"render-btns-container-click"),this.$titleBar.appendChild(e),this.$titleBar.appendChild(i)}return this.$titleBar}renderDragArea(){const e=document.createElement("div");return e.className=this.wrapClassName("drag-area"),e.dataset.teleBoxHandle="dh",this.sideEffect.addEventListener(e,"mousedown",this.handleTitleBarClick),this.sideEffect.addEventListener(e,"touchstart",this.handleTitleBarTouch,{passive:!0}),e}dragHandle(){return this.$titleBar}wrapClassName(e){return`${this.namespace}-${e}`}destroy(){this.sideEffect.flushAll(),this.$titleBar&&(this.$titleBar=void 0,this.onDragStart=void 0,this.onEvent=void 0)}}class V{constructor({namespace:e,rootRect$:t,ratio$:i,highlightStage$:s,root$:a}){this._sideEffect=new c,this.namespace=e,this.highlightStage$=s,this.stageRect$=x([t,s,i],(([e,t,i])=>{if(!t)return e;if(i<=0||e.width<=0||e.height<=0)return e;const s=e.width*i;if(s===e.height)return e;if(s<e.height)return{x:0,y:(e.height-s)/2,width:e.width,height:s};const a=e.height/i;return{x:(e.width-a)/2,y:0,width:a,height:e.height}}),{compare:d}),this._sideEffect.addDisposer(x([a,s]).subscribe((([e,t])=>{var i;e&&t?e.appendChild(this.render()):(null==(i=this.$boxStage)?void 0:i.parentNode)&&this.$boxStage.remove()})))}render(){if(this.$boxStage)return this.$boxStage;const e=document.createElement("div");e.className=this.wrapClassName("box-stage-container");const t=document.createElement("div");t.className=this.wrapClassName("box-stage-mask");const i=document.createElement("div");i.className=this.wrapClassName("box-stage-mask");const s=document.createElement("div");s.className=this.wrapClassName("box-stage-frame");const[a,r,n,o]=["M0 8V0h8v2H2v6H0Z","M8 8V0H0v2h6v6h2Z","M0 0v8h8V6H2V0H0Z","M8 0v8H0V6h6V0h2Z"].map(((e,t)=>{const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 8 8"),i.setAttribute("class",`${this.wrapClassName("box-stage-frame-corner")} is-${t}`);const s=document.createElementNS("http://www.w3.org/2000/svg","path");return s.setAttribute("d",e),s.setAttribute("fill","#3381FF"),i.appendChild(s),i}));return s.appendChild(a),s.appendChild(n),s.appendChild(r),s.appendChild(o),e.appendChild(t),e.appendChild(s),e.appendChild(i),this._sideEffect.addDisposer(this.highlightStage$.subscribe((t=>{e.classList.toggle("is-active",t)}))),this._sideEffect.addDisposer(x([this.highlightStage$,this.stageRect$]).subscribe((([s,a])=>{s&&(a.x>0?(e.style.flexDirection="row",t.style.width=`${a.x}px`,t.style.height="",i.style.width=`${a.x}px`,i.style.height=""):a.y>0&&(e.style.flexDirection="column",t.style.width="",t.style.height=`${a.y}px`,i.style.width="",i.style.height=`${a.y}px`))}))),this.$boxStage=e,e}destroy(){this._sideEffect.flushAll()}wrapClassName(e){return`${this.namespace}-${e}`}}const H=window.ResizeObserver||f;class A{constructor({id:e=m(),title:t=R(),namespace:i="telebox",visible:s=!0,width:a=.5,height:r=.5,minWidth:n=0,minHeight:o=0,x:l=.1,y:f=.1,resizable:$=!0,draggable:b=!0,ratio:w=-1,focus:y=!1,zIndex:E=100,titleBar:z,content:B,footer:_,styles:N,highlightStage:S=null,darkMode$:I,fence$:k,minimized$:L,maximized$:D,readonly$:H,root$:A,rootRect$:W,managerStageRect$:Y,stageRatio$:X,collectorRect$:P,managerHighlightStage$:O}){this.events=new h,this._delegateEvents=new h,this.handleTrackStart=e=>{var t;return null==(t=this._handleTrackStart)?void 0:t.call(this,e)},this._sideEffect=new c,this.id=e,this.namespace=i;const j=new u(t),Z=new u(s),F=new u($),G=new u(b),J=new u(w),q=new u(E),Q=new u(y),K=new u(B),U=new u(_),ee=new u(N),te=x([L,D],(([e,t])=>e?v.Minimized:t?v.Maximized:v.Normal)),ie=new u({width:M(n,0,1),height:M(o,0,1)},{compare:d}),se=x([ie,Y],(([e,t])=>({width:e.width*t.width,height:e.height*t.height})),{compare:d}),ae=new u({width:a,height:r},{compare:d});this._sideEffect.addDisposer(ie.reaction(((e,t)=>{ae.setValue({width:Math.max(a,e.width),height:Math.max(r,e.height)},t)})));const re=new u({x:l,y:f},{compare:d}),ne=x([ae,Y],(([e,t])=>({width:t.width*e.width,height:t.height*e.height})),{compare:d}),oe=x([re,Y],(([e,t])=>({x:e.x*t.width+t.x,y:e.y*t.height+t.y})),{compare:d}),he=new u(S),le=x([D,he,O],(([e,t,i])=>null===t?i&&e:t)),de=new u(null),ce=new u(W.value,{compare:d}),me=new V({namespace:i,root$:de,rootRect$:ce,ratio$:X,highlightStage$:le});this._sideEffect.addDisposer((()=>me.destroy()));const ue={darkMode:I,fence:k,minimized:L,maximized:D,readonly:H,rootRect:W,managerStageRect:Y,collectorRect:P,zIndex:q,focus:Q,$userContent:K,$userFooter:U,$userStyles:ee,state:te,minSize:ie,pxMinSize:se,intrinsicSize:ae,intrinsicCoord:re,pxIntrinsicSize:ne,pxIntrinsicCoord:oe,highlightStage:le,boxHighlightStage:he,contentRect:ce,contentStageRect:me.stageRect$};g(this,ue);p(this,{title:j,visible:Z,resizable:F,draggable:G,ratio:J}),this.titleBar=z||new T({readonly$:H,state$:te,title:j.value,namespace:this.namespace,onDragStart:e=>{var t;return null==(t=this._handleTrackStart)?void 0:t.call(this,e)},onEvent:e=>this._delegateEvents.emit(e.type)}),this._sideEffect.addDisposer(J.subscribe((e=>{e>0&&this.transform(oe.value.x,oe.value.y,ne.value.width,ne.value.height,!0)}))),this._sideEffect.addDisposer(k.subscribe((e=>{e&&this.move(oe.value.x,oe.value.y,!0)}))),this.$box=this.render(),de.setValue(this.$content.parentElement);const xe=(e,t)=>{this._sideEffect.addDisposer(e.reaction(((e,i)=>{i||this.events.emit(t,e)})))};xe(I,C.DarkMode),xe(H,C.Readonly),xe(q,C.ZIndex),xe(L,C.Minimized),xe(D,C.Maximized),xe(te,C.State),xe(ae,C.IntrinsicResize),xe(re,C.IntrinsicMove),this._sideEffect.addDisposer([Z.reaction(((e,t)=>{t||e||this.events.emit(C.Close)})),Q.reaction(((e,t)=>{t||this.events.emit(e?C.Focus:C.Blur)})),A.subscribe((e=>{e?e.appendChild(this.$box):this.$box.parentNode&&this.$box.remove()}))])}get minWidth(){return this._minSize$.value.width}get minHeight(){return this._minSize$.value.height}setMinWidth(e,t=!1){this._minSize$.setValue({width:e,height:this.minHeight},t)}setMinHeight(e,t=!1){this._minSize$.setValue({width:this.minWidth,height:e},t)}resize(e,t,i=!1){this._intrinsicSize$.setValue({width:Math.max(e,this.minWidth),height:Math.max(t,this.minHeight)},i)}get intrinsicX(){return this._intrinsicCoord$.value.x}get intrinsicY(){return this._intrinsicCoord$.value.y}get intrinsicWidth(){return this._intrinsicSize$.value.width}get intrinsicHeight(){return this._intrinsicSize$.value.height}move(e,t,i=!1){let s,a;const r=this.managerStageRect,n=this.pxIntrinsicSize;if(this.fence)s=M(e,r.x,r.x+r.width-n.width),a=M(t,r.y,r.y+r.height-n.height);else{const i=this.rootRect;s=M(e,i.x-n.width+20,i.x+i.width-20),a=M(t,i.y,i.y+i.height-20)}this._intrinsicCoord$.setValue({x:(s-r.x)/r.width,y:(a-r.y)/r.height},i)}transform(e,t,i,s,a=!1){const r=this.managerStageRect,n=this.rootRect;if(i=Math.max(i,this.pxMinSize.width),s=Math.max(s,this.pxMinSize.height),this.ratio>0){const e=this.ratio*i;t!==this.pxIntrinsicCoord.y&&(t-=e-s),s=e}t<n.y&&(t=n.y,s=this.pxIntrinsicSize.height),this.move(e,t,a),this._intrinsicSize$.setValue({width:i/r.width,height:s/r.height},a)}mountContent(e){this._$userContent$.setValue(e)}unmountContent(){this._$userContent$.setValue(void 0)}mountFooter(e){this._$userFooter$.setValue(e)}unmountFooter(){this._$userFooter$.setValue(void 0)}getUserStyles(){return this.$userStyles}mountStyles(e){let t;"string"==typeof e?(t=document.createElement("style"),t.textContent=e):t=e,this._$userStyles$.setValue(t)}unmountStyles(){this._$userStyles$.setValue(void 0)}setHighlightStage(e){this._boxHighlightStage$.setValue(e)}render(){if(this.$box)return this.$box;this.$box=document.createElement("div"),this.$box.classList.add(this.wrapClassName("box"));const e=(e,t,i,s=L)=>this._sideEffect.add((()=>{const a=this.wrapClassName(i);return t.subscribe((t=>{e.classList.toggle(a,s(t))}))}));e(this.$box,this._readonly$,"readonly"),e(this.$box,this._draggable$,"no-drag",D),e(this.$box,this._resizable$,"no-resize",D),e(this.$box,this._focus$,"blur",D),e(this.$box,this._darkMode$,"color-scheme-dark"),e(this.$box,this._darkMode$,"color-scheme-light",D),this._sideEffect.add((()=>{const e=this.wrapClassName("minimized"),t=this.wrapClassName("maximized"),i="box-maximized-timer";return this._state$.subscribe((s=>{this.$box.classList.toggle(e,s===v.Minimized),s===v.Maximized?(this._sideEffect.flush(i),this.$box.classList.toggle(t,!0)):this._sideEffect.setTimeout((()=>{this.$box.classList.toggle(t,!1)}),0,i)}))})),this._sideEffect.addDisposer(this._visible$.subscribe((e=>{this.$box.style.display=e?"block":"none"}))),this._sideEffect.addDisposer(this._zIndex$.subscribe((e=>{this.$box.style.zIndex=String(e)}))),this.$box.dataset.teleBoxID=this.id;const t=l(this.$box),i=x([this._maximized$,this._minimized$,this._pxIntrinsicSize$,this._pxIntrinsicCoord$,this._collectorRect$],(([e,t,i,s,a])=>t&&a?{x:a.x+a.width/2,y:a.y+a.height/2,width:i.width+"px",height:i.height+"px",scaleX:a.width/i.width,scaleY:a.height/i.height}:e?{x:0,y:0,width:"100%",height:"100%",scaleX:1,scaleY:1}:{x:s.x,y:s.y,width:i.width+"px",height:i.height+"px",scaleX:1,scaleY:1}),{compare:d}),s=i.value;this.$box.style.width=s.width,this.$box.style.height=s.height,this.$box.style.transform=`translate(${s.x-10}px,${s.y-10}px)`,this._sideEffect.addDisposer(i.subscribe((e=>{t.set(e)})));const a=document.createElement("div");a.className=this.wrapClassName("box-main"),this.$box.appendChild(a);const r=document.createElement("div");r.className=this.wrapClassName("titlebar-wrap"),r.appendChild(this.titleBar.render()),this.$titleBar=r;const n=document.createElement("div");n.className=this.wrapClassName("content-wrap");const o=document.createElement("div");o.className=this.wrapClassName("content")+" tele-fancy-scrollbar",this.$content=o,this._sideEffect.add((()=>{const e=new H((e=>{var t;const i=null==(t=e[0])?void 0:t.contentRect;i&&this._contentRect$.setValue({x:i.x,y:i.y,width:i.width,height:i.height})}));return e.observe(o),()=>e.disconnect()})),this._sideEffect.add((()=>{let e;return this._$userStyles$.subscribe((t=>{e&&e.remove(),e=t,t&&n.appendChild(t)}))})),this._sideEffect.add((()=>{let e;return this._$userContent$.subscribe((t=>{e&&e.remove(),e=t,t&&o.appendChild(t)}))})),n.appendChild(o);const h=document.createElement("div");return h.className=this.wrapClassName("footer-wrap"),this.$footer=h,this._sideEffect.add((()=>{let e;return this._$userFooter$.subscribe((t=>{e&&e.remove(),e=t,t&&h.appendChild(t)}))})),a.appendChild(r),a.appendChild(n),a.appendChild(h),this._renderResizeHandlers(),this.$box}_renderResizeHandlers(){const e=document.createElement("div");e.className=this.wrapClassName("resize-handles"),Object.values(B).forEach((t=>{const i=document.createElement("div");i.className=this.wrapClassName(t)+" "+this.wrapClassName("resize-handle"),i.dataset.teleBoxHandle=t,e.appendChild(i)})),this.$box.appendChild(e);const t="handle-tracking-listener",i=this.wrapClassName("transforming");let s,a,r=0,n=0,o=0,h=0,l=0,d=0;const c=e=>{if(this.state!==v.Normal)return;S(e);let{pageX:t,pageY:i}=I(e);i<this.rootRect.y&&(i=this.rootRect.y);const s=t-l,c=i-d;let{x:m,y:u}=this.pxIntrinsicCoord,{width:x,height:g}=this.pxIntrinsicSize;switch(a){case B.North:u=n+c,g=h-c;break;case B.South:g=h+c;break;case B.West:m=r+s,x=o-s;break;case B.East:x=o+s;break;case B.NorthWest:m=r+s,u=n+c,x=o-s,g=h-c;break;case B.NorthEast:u=n+c,x=o+s,g=h-c;break;case B.SouthEast:x=o+s,g=h+c;break;case B.SouthWest:m=r+s,x=o-s,g=h+c;break;default:return void this.move(r+s,n+c)}this.transform(m,u,x,g)},m=e=>{a=void 0,s&&(S(e),this.$box.classList.toggle(i,!1),this._sideEffect.flush(t),s.remove())},u=e=>{var u;if(this.readonly)return;if(null!=e.button&&0!==e.button)return;if(!this.draggable||a||this.state!==v.Normal)return;const x=e.target;if(null==(u=x.dataset)?void 0:u.teleBoxHandle){S(e),({x:r,y:n}=this.pxIntrinsicCoord),({width:o,height:h}=this.pxIntrinsicSize),({pageX:l,pageY:d}=I(e)),a=x.dataset.teleBoxHandle,s||(s=document.createElement("div"));const u=a?this.wrapClassName(`cursor-${a}`):"";s.className=this.wrapClassName("track-mask"+(u?` ${u}`:"")),this.$box.appendChild(s),this.$box.classList.add(i),this._sideEffect.add((()=>(window.addEventListener("mousemove",c),window.addEventListener("touchmove",c,{passive:!1}),window.addEventListener("mouseup",m),window.addEventListener("touchend",m,{passive:!1}),window.addEventListener("touchcancel",m,{passive:!1}),()=>{window.removeEventListener("mousemove",c),window.removeEventListener("touchmove",c),window.removeEventListener("mouseup",m),window.removeEventListener("touchend",m),window.removeEventListener("touchcancel",m)})),t)}};this._handleTrackStart=u,this._sideEffect.addEventListener(e,"mousedown",u,{},"box-resizeHandles-mousedown"),this._sideEffect.addEventListener(e,"touchstart",u,{passive:!1},"box-resizeHandles-touchstart")}async destroy(){this.$box.remove(),this._sideEffect.flushAll(),this._sideEffect.flushAll(),await this.events.emit(C.Destroyed),this.events.clearListeners(),this._delegateEvents.clearListeners()}wrapClassName(e){return`${this.namespace}-${e}`}}var W,Y;class X{constructor({minimized$:e,readonly$:t,darkMode$:i,rootRect$:s,namespace:a="telebox",styles:r={},root$:n}){this._sideEffect=new c,this.namespace=a;const o=new u(void 0),h=e,l=new u(r),d=new u(document.createElement("button"));p(this,{styles:l,el:d});g(this,{rect:o,visible:h,root:n}),d.value.className=this.wrapClassName("collector"),d.value.style.backgroundImage="url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxOCAxNiI+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxwYXRoIHN0cm9rZT0iIzdCODhBMCIgc3Ryb2tlLXdpZHRoPSIxLjQiIGQ9Ik0uNyAxLjJoMTYuNnYxMy42SC43eiIgLz4KICAgICAgICA8cGF0aCBmaWxsPSIjN0I4OEEwIiBkPSJNNCA1LjVoNnYxLjRINHpNNCA5LjVoMTB2MS40SDR6IiAvPgogICAgPC9nPgo8L3N2Zz4K')",this._sideEffect.addDisposer(d.subscribe((a=>{this._sideEffect.addEventListener(a,"click",(()=>{t.value||e.setValue(!1)}),{},"telebox-collector-click"),this._sideEffect.addDisposer([h.subscribe((e=>{a.classList.toggle(this.wrapClassName("collector-visible"),e)})),t.subscribe((e=>{a.classList.toggle(this.wrapClassName("collector-readonly"),e)})),i.subscribe((e=>{a.classList.toggle(this.wrapClassName("color-scheme-dark"),e),a.classList.toggle(this.wrapClassName("color-scheme-light"),!e)})),l.subscribe((e=>{Object.keys(e).forEach((t=>{const i=e[t];null!=i&&(a.style[t]=i)}))})),n.subscribe((e=>{e&&e.appendChild(a)})),x([e,s,n]).subscribe((([e,t,i])=>{if(e&&i){const{x:e,y:i,width:s,height:r}=a.getBoundingClientRect();o.setValue({x:e-t.x,y:i-t.y,width:s,height:r})}}))],"telebox-collector-el")})))}destroy(){this._sideEffect.flushAll()}wrapClassName(e){return`${this.namespace}-${e}`}}(Y=W||(W={})).Focused="focused",Y.Blurred="blurred",Y.Created="created",Y.Removed="removed",Y.State="state",Y.Maximized="maximized",Y.Minimized="minimized",Y.IntrinsicMove="intrinsic_move",Y.IntrinsicResize="intrinsic_resize",Y.ZIndex="z_index",Y.PrefersColorScheme="prefers_color_scheme",Y.DarkMode="dark_mode";class P extends T{constructor(e){super(e),this.boxes$=e.boxes$,this.rootRect$=e.rootRect$,this.darkMode$=e.darkMode$,this.sideEffect.addDisposer(e.root$.subscribe((e=>{var t;e?e.appendChild(this.render()):(null==(t=this.$titleBar)?void 0:t.parentNode)&&this.$titleBar.remove()})))}focusBox(e){var t;if(!this.focusedBox||this.focusedBox!==e){if(this.$titles&&this.state$.value===v.Maximized){const{children:i}=this.$titles.firstElementChild;for(let s=i.length-1;s>=0;s-=1){const a=i[s],r=null==(t=a.dataset)?void 0:t.teleBoxID;r&&(e&&r===e.id?a.classList.toggle(this.wrapClassName("titles-tab-focus"),!0):this.focusedBox&&r===this.focusedBox.id&&a.classList.toggle(this.wrapClassName("titles-tab-focus"),!1))}}this.focusedBox=e}}render(){if(this.$titleBar)return this.$titleBar;const e=super.render();e.classList.add(this.wrapClassName("max-titlebar")),this.sideEffect.addDisposer([this.rootRect$.subscribe((t=>{const{x:i,y:s,width:a}=t;e.style.transform=`translate(${i}px, ${s}px)`,e.style.width=a+"px"})),this.state$.subscribe((t=>{e.classList.toggle(this.wrapClassName("max-titlebar-maximized"),t===v.Maximized)})),this.readonly$.subscribe((t=>{e.classList.toggle(this.wrapClassName("readonly"),t)})),this.darkMode$.subscribe((t=>{e.classList.toggle(this.wrapClassName("color-scheme-dark"),t),e.classList.toggle(this.wrapClassName("color-scheme-light"),!t)})),x([this.state$,this.boxes$]).subscribe((([t,i])=>{t===v.Maximized&&(e.classList.toggle(this.wrapClassName("max-titlebar-single-title"),1===i.length),1===i.length?this.setTitle(i[0].title):e.replaceChild(this.renderTitles(),e.firstElementChild))}))],"max-render");const t=document.createElement("div");return t.classList.add(this.wrapClassName("titles-area")),e.insertBefore(t,e.firstElementChild),e}destroy(){super.destroy(),this.$titles=void 0,this.focusedBox=void 0}renderTitles(){this.$titles=document.createElement("div"),this.$titles.className=this.wrapClassName("titles"),this.sideEffect.addEventListener(this.$titles,"wheel",(e=>{e.currentTarget.scrollBy({left:e.deltaY>0?250:-250,behavior:"smooth"})}),{passive:!1},"max-render-wheel-titles");const e=document.createElement("div");e.className=this.wrapClassName("titles-content"),this.$titles.appendChild(e);const t=this.boxes$.value.map((t=>{const i=document.createElement("button");return i.className=this.wrapClassName("titles-tab"),i.textContent=t.title,i.dataset.teleBoxID=t.id,i.dataset.teleTitleBarNoDblClick="true",this.focusedBox&&t.id===this.focusedBox.id&&i.classList.add(this.wrapClassName("titles-tab-focus")),e.appendChild(i),t._title$.reaction((e=>i.textContent=e))}));return this.sideEffect.addDisposer((()=>t.forEach((e=>e()))),"max-render-tab-titles"),this.$titles}}const O=window.ResizeObserver||f;class j{constructor({root:e=null,prefersColorScheme:t=$.Light,minimized:i=!1,maximized:s=!1,fence:a=!1,collector:r,namespace:n="telebox",readonly:o=!1,stageRatio:l=-1,highlightStage:m=!0}={}){this.events=new h,this._sideEffect=new c,this.namespace=n;const f=new u(e),b=new u(o),w=new u(i),y=new u(s),z=new u(a),B=new u(l),_=new u(m),N=new u({x:0,y:0,width:window.innerWidth,height:window.innerHeight},{compare:d});this._sideEffect.addDisposer(f.subscribe((e=>{this._sideEffect.add((()=>{if(!e)return()=>{};const t=new O((e=>{var t;const i=null==(t=e[0])?void 0:t.contentRect;i&&N.setValue({x:i.x,y:i.y,width:i.width,height:i.height})}));return t.observe(e),()=>t.disconnect()}),"calc-root-rect")}))),this.boxes$=new u([]),this.topBox$=new u(void 0),this._sideEffect.addDisposer(this.boxes$.subscribe((e=>{if(e.length>0){const t=e.reduce(((e,t)=>e.zIndex>t.zIndex?e:t));this.topBox$.setValue(t)}else this.topBox$.setValue(void 0)})));const M=window.matchMedia("(prefers-color-scheme: dark)"),S=new u(!1);M&&(S.setValue(M.matches),this._sideEffect.add((()=>{const e=e=>{S.setValue(e.matches)};return M.addEventListener("change",e),()=>M.removeEventListener("change",e)})));const I=new u(t);this._sideEffect.addDisposer(I.reaction(((e,t)=>{t||this.events.emit(W.PrefersColorScheme,e)})));const k=x([S,I],(([e,t])=>"auto"===t?e:"dark"===t)),R=x([w,y],(([e,t])=>e?v.Minimized:t?v.Maximized:v.Normal));this.collector=null!=r?r:new X({minimized$:w,readonly$:b,darkMode$:k,namespace:n,root$:f,rootRect$:N});const L=new V({namespace:n,rootRect$:N,ratio$:B,root$:f,highlightStage$:x([_,y],(([e,t])=>e&&!t))});this._sideEffect.addDisposer((()=>L.destroy()));const D={darkMode:k,state:R,root:f,rootRect:N,stageRect:L.stageRect$};g(this,D);p(this,{prefersColorScheme:I,readonly:b,fence:z,minimized:w,maximized:y,stageRatio:B,highlightStage:_});const T=this.wrapClassName("titlebar-icon-close"),H=e=>{var t;if(b.value)return;const i=e.target;if(i.tagName)for(let s=i;s;s=s.parentElement){if(s.classList&&s.classList.contains(T))return;const e=null==(t=s.dataset)?void 0:t.teleBoxID;if(e){const t=this.getBox(e);if(t)return this.focusBox(t),void this.makeBoxTop(t)}}};this._sideEffect.addEventListener(window,"mousedown",H,!0),this._sideEffect.addEventListener(window,"touchstart",H,!0),this.titleBar=new P({namespace:this.namespace,boxes$:this.boxes$,darkMode$:k,readonly$:b,state$:R,root$:f,rootRect$:N,onEvent:e=>{switch(e.type){case E.Maximize:y.setValue(!y.value);break;case E.Minimize:w.setValue(!0);break;case C.Close:this.removeTopBox(),this.focusTopBox()}}}),this._sideEffect.addDisposer([R.reaction(((e,t)=>{t||this.events.emit(W.State,e)})),y.reaction(((e,t)=>{t||this.events.emit(W.Maximized,e)})),w.reaction(((e,t)=>{t||this.events.emit(W.Minimized,e)})),k.reaction(((e,t)=>{t||this.events.emit(W.DarkMode,e)}))])}get boxes(){return this.boxes$.value}get topBox(){return this.topBox$.value}setState(e,t=!1){switch(e){case v.Maximized:this.setMinimized(!1,t),this.setMaximized(!0,t);break;case v.Minimized:this.setMinimized(!0,t),this.setMaximized(!1,t);break;default:this.setMinimized(!1,t),this.setMaximized(!1,t)}return this}create(e={},s=!0){const a=new A((r=o(o({zIndex:this.topBox?this.topBox.zIndex+1:100},e),s?this.smartPosition(e):{}),n={namespace:this.namespace,root$:this._root$,darkMode$:this._darkMode$,maximized$:this._maximized$,minimized$:this._minimized$,fence$:this._fence$,rootRect$:this._rootRect$,managerStageRect$:this._stageRect$,stageRatio$:this._stageRatio$,readonly$:this._readonly$,collectorRect$:this.collector._rect$,managerHighlightStage$:this._highlightStage$},t(r,i(n))));var r,n;return a.focus&&(this.focusBox(a),s&&this.makeBoxTop(a)),this.boxes$.setValue([...this.boxes,a]),this._sideEffect.addDisposer([a._delegateEvents.on(E.Maximize,(()=>{this.setMaximized(!this.maximized)})),a._delegateEvents.on(E.Minimize,(()=>{this.setMinimized(!0)})),a._delegateEvents.on(E.Close,(()=>{this.remove(a),this.focusTopBox()})),a._intrinsicCoord$.reaction(((e,t)=>{t||this.events.emit(W.IntrinsicMove,a)})),a._intrinsicSize$.reaction(((e,t)=>{t||this.events.emit(W.IntrinsicResize,a)})),a._zIndex$.reaction(((e,t)=>{if(this.boxes.length>0){const e=this.boxes.reduce(((e,t)=>e.zIndex>t.zIndex?e:t));this.topBox$.setValue(e)}t||this.events.emit(W.ZIndex,a)}))]),this.events.emit(W.Created,a),a}query(e){return e?this.boxes.filter(this.teleBoxMatcher(e)):[...this.boxes]}queryOne(e){return e?this.boxes.find(this.teleBoxMatcher(e)):this.boxes[0]}update(e,t,i=!1){const s=this.boxes.find((t=>t.id===e));if(s)return this.updateBox(s,t,i)}updateAll(e,t=!1){this.boxes.forEach((i=>{this.updateBox(i,e,t)}))}remove(e,t=!1){const i=this.getBoxIndex(e);if(i>=0){const e=this.boxes.slice(),s=e.splice(i,1);return this.boxes$.setValue(e),s.forEach((e=>e.destroy())),t||(this.boxes.length<=0&&(this.setMaximized(!1),this.setMinimized(!1)),this.events.emit(W.Removed,s)),s[0]}}removeTopBox(){if(this.topBox)return this.remove(this.topBox)}removeAll(e=!1){const t=this.boxes$.value;return this.boxes$.setValue([]),t.forEach((e=>e.destroy())),e||(this.boxes.length<=0&&(this.setMaximized(!1),this.setMinimized(!1)),this.events.emit(W.Removed,t)),t}mount(e){this._root$.setValue(e)}unmount(){this._root$.setValue(null)}destroy(e=!1){this.events.clearListeners(),this._sideEffect.flushAll(),this.removeAll(e),this.collector.destroy(),this.titleBar.destroy()}wrapClassName(e){return`${this.namespace}-${e}`}focusBox(e,t=!1){const i=this.getBox(e);i&&(this.boxes.forEach((e=>{if(i===e){let e=!1;i.focus||(e=!0,i._focus$.setValue(!0,t)),e&&!t&&this.events.emit(W.Focused,i)}else e.focus&&this.blurBox(e,t)})),this.titleBar.focusBox(i))}focusTopBox(){if(this.topBox&&!this.topBox.focus)return this.focusBox(this.topBox)}blurBox(e,t=!1){const i=this.getBox(e);i&&(i.focus&&(i._focus$.setValue(!1,t),t||this.events.emit(W.Blurred,i)),this.titleBar.focusedBox===i&&this.titleBar.focusBox())}blurAll(e=!1){this.boxes.forEach((t=>{t.focus&&(t._focus$.setValue(!1,e),e||this.events.emit(W.Blurred,t))})),this.titleBar.focusedBox&&this.titleBar.focusBox()}teleBoxMatcher(e){const t=Object.keys(e);return i=>t.every((t=>e[t]===i[t]))}updateBox(e,t,i=!1){var s,a,r,n,o,h;null==t.x&&null==t.y||e._intrinsicCoord$.setValue({x:null!=(s=t.x)?s:e.intrinsicX,y:null!=(a=t.y)?a:e.intrinsicY},i),null==t.width&&null==t.height||e._intrinsicSize$.setValue({width:null!=(r=t.width)?r:e.intrinsicWidth,height:null!=(n=t.height)?n:e.intrinsicHeight},i),null!=t.title&&e._title$.setValue(t.title),null!=t.visible&&e._visible$.setValue(t.visible,i),null!=t.resizable&&e._resizable$.setValue(t.resizable,i),null!=t.draggable&&e._draggable$.setValue(t.draggable,i),null!=t.ratio&&e._ratio$.setValue(t.ratio,i),null!=t.zIndex&&e._zIndex$.setValue(t.zIndex,i),null!=t.content&&e.mountContent(t.content),null!=t.footer&&e.mountFooter(t.footer),null==t.minHeight&&null==t.minWidth||e._minSize$.setValue({width:null!=(o=t.minWidth)?o:e.minWidth,height:null!=(h=t.minHeight)?h:e.minHeight},i)}smartPosition(e){let{x:t,y:i}=e;const{width:s=.5,height:a=.5}=e,r=this.stageRect,n=this.topBox;if(null==t){let e=r.x+20;if(n){const t=n.pxIntrinsicCoord.x+20;t+s*r.width<=r.x+r.width&&(e=t)}t=(e-r.x)/r.width}if(null==i){let e=r.y+20;if(n){const t=n.pxIntrinsicCoord.y+20;t+a*r.height<=r.y+r.height&&(e=t)}i=(e-r.y)/r.height}return{x:t,y:i,width:s,height:a}}makeBoxTop(e,t=!1){this.topBox&&e!==this.topBox&&e._zIndex$.setValue(this.topBox.zIndex+1,t)}getBoxIndex(e){return"string"==typeof e?this.boxes.findIndex((t=>t.id===e)):this.boxes.findIndex((t=>t===e))}getBox(e){return"string"==typeof e?this.boxes.find((t=>t.id===e)):e}}export{T as DefaultTitleBar,$ as TELE_BOX_COLOR_SCHEME,E as TELE_BOX_DELEGATE_EVENT,C as TELE_BOX_EVENT,W as TELE_BOX_MANAGER_EVENT,B as TELE_BOX_RESIZE_HANDLE,v as TELE_BOX_STATE,A as TeleBox,X as TeleBoxCollector,N as TeleBoxDragHandleType,j as TeleBoxManager};
1
+ import Emittery from "emittery";
2
+ import styler from "stylefire";
3
+ import shallowequal from "shallowequal";
4
+ import { SideEffectManager, genUID } from "side-effect-manager";
5
+ import { ValManager, Val, combine, withReadonlyValueEnhancer, withValueEnhancer, derive } from "value-enhancer";
6
+ import { ResizeObserver as ResizeObserver$2 } from "@juggle/resize-observer";
7
+ var style$4 = /* @__PURE__ */ (() => '.tele-fancy-scrollbar {\n overscroll-behavior: contain;\n overflow: auto;\n overflow-y: scroll;\n overflow-y: overlay;\n -webkit-overflow-scrolling: touch;\n -ms-overflow-style: -ms-autohiding-scrollbar;\n scrollbar-width: auto;\n}\n.tele-fancy-scrollbar::-webkit-scrollbar {\n height: 8px;\n width: 8px;\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-track {\n background-color: transparent;\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb {\n background-color: rgba(68, 78, 96, 0.1);\n background-color: transparent;\n border-radius: 4px;\n transition: background-color 0.4s;\n}\n.tele-fancy-scrollbar:hover::-webkit-scrollbar-thumb {\n background-color: rgba(68, 78, 96, 0.1);\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb:hover {\n background-color: rgba(68, 78, 96, 0.2);\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb:active {\n background-color: rgba(68, 78, 96, 0.2);\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb:vertical {\n min-height: 50px;\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb:horizontal {\n min-width: 50px;\n}\n.telebox-quarantine {\n all: initial;\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n}\n.telebox-body-wrap {\n color: #191919;\n color: var(--tele-boxColor, #191919);\n flex: 1;\n width: 100%;\n overflow: hidden;\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n}\n.telebox-content {\n width: 100%;\n height: 100%;\n position: relative;\n background-color: #f9f9f9;\n background-color: var(--tele-boxContainerBackground, #f9f9f9);\n}\n.telebox-box-stage {\n position: absolute;\n z-index: 1;\n overflow: hidden;\n background-color: #fff;\n background-color: var(--tele-boxStageBackground, #fff);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);\n box-shadow: var(--tele-boxStageShadow, 0px 0px 16px rgba(0, 0, 0, 0.08));\n}\n.telebox-footer-wrap {\n flex-shrink: 0;\n display: flex;\n flex-direction: column;\n color: #191919;\n color: var(--tele-boxFooterColor, #191919);\n background-color: #fff;\n background-color: var(--tele-boxFooterBackground, #fff);\n}\n.telebox-footer-wrap::before {\n content: "";\n display: block;\n flex: 1;\n}\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n.telebox-color-scheme-dark .telebox-body-wrap {\n color: #e9e9e9;\n color: var(--tele-boxColor, #e9e9e9);\n}\n.telebox-color-scheme-dark .telebox-content {\n background-color: #25282e;\n background-color: var(--tele-boxContainerBackground, #25282e);\n}\n.telebox-color-scheme-dark .telebox-box-stage {\n background-color: #272a30;\n background-color: var(--tele-boxStageBackground, #272a30);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.24);\n box-shadow: var(--tele-boxStageShadow, 0px 0px 16px rgba(0, 0, 0, 0.24));\n}\n.telebox-color-scheme-dark .telebox-footer-wrap {\n color: #e9e9e9;\n color: var(--tele-boxFooterColor, #e9e9e9);\n background-color: #383b42;\n background-color: var(--tele-boxFooterBackground, #383b42);\n}\n.telebox-box {\n position: absolute;\n top: 0;\n left: 0;\n z-index: 100;\n transition: width 0.4s cubic-bezier(0.4, 0.9, 0.71, 1.02), height 0.4s cubic-bezier(0.55, 0.82, 0.63, 0.95), opacity 0.6s cubic-bezier(0.7, 0, 0.84, 0), transform 0.4s ease;\n}\n.telebox-box-main {\n border: 1px solid #e3e3ec;\n border: var(--tele-boxBorder, 1px solid #e3e3ec);\n box-shadow: 0px 4px 10px 0px rgba(47, 65, 146, 0.15);\n box-shadow: var(--tele-boxShadow, 0px 4px 10px 0px rgba(47, 65, 146, 0.15));\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n border-radius: 6px;\n}\n.telebox-titlebar-wrap {\n flex-shrink: 0;\n position: relative;\n z-index: 1;\n}\n.telebox-main {\n position: relative;\n flex: 1;\n width: 100%;\n overflow: hidden;\n}\n.telebox-quarantine-outer {\n width: 100%;\n height: 100%;\n overflow: hidden;\n}\n.telebox-resize-handle {\n user-select: none;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n position: absolute;\n z-index: 2147483647;\n touch-action: none;\n}\n.telebox-n {\n width: 100%;\n height: 5px;\n left: 0;\n top: -5px;\n cursor: n-resize;\n}\n.telebox-s {\n width: 100%;\n height: 5px;\n left: 0;\n bottom: -5px;\n cursor: s-resize;\n}\n.telebox-w {\n width: 5px;\n height: 100%;\n left: -5px;\n top: 0;\n cursor: w-resize;\n}\n.telebox-e {\n width: 5px;\n height: 100%;\n right: -5px;\n top: 0;\n cursor: e-resize;\n}\n.telebox-nw {\n width: 15px;\n height: 15px;\n top: -5px;\n left: -5px;\n cursor: nw-resize;\n}\n.telebox-ne {\n width: 15px;\n height: 15px;\n top: -5px;\n right: -5px;\n cursor: ne-resize;\n}\n.telebox-se {\n width: 15px;\n height: 15px;\n bottom: -5px;\n right: -5px;\n cursor: se-resize;\n}\n.telebox-sw {\n width: 15px;\n height: 15px;\n bottom: -5px;\n left: -5px;\n cursor: sw-resize;\n}\n.telebox-track-mask {\n user-select: none;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n position: fixed;\n top: 0;\n left: 0;\n z-index: 2147483647;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.0001);\n cursor: move;\n}\n.telebox-cursor-n {\n cursor: n-resize;\n}\n.telebox-cursor-s {\n cursor: s-resize;\n}\n.telebox-cursor-w {\n cursor: w-resize;\n}\n.telebox-cursor-e {\n cursor: e-resize;\n}\n.telebox-cursor-nw {\n cursor: nw-resize;\n}\n.telebox-cursor-ne {\n cursor: ne-resize;\n}\n.telebox-cursor-se {\n cursor: se-resize;\n}\n.telebox-cursor-sw {\n cursor: sw-resize;\n}\n.telebox-maximized .telebox-resize-handles,\n.telebox-no-resize .telebox-resize-handles {\n display: none;\n}\n.telebox-maximized {\n box-shadow: none;\n transition: none;\n}\n.telebox-minimized {\n transition: width 0.05s cubic-bezier(0.4, 0.9, 0.71, 1.02), height 0.05s cubic-bezier(0.55, 0.82, 0.63, 0.95), opacity 0.6s cubic-bezier(0.7, 0, 0.84, 0), transform 0.6s ease;\n opacity: 0;\n pointer-events: none;\n user-select: none;\n}\n.telebox-transforming {\n will-change: transform;\n transition: opacity 0.6s cubic-bezier(0.7, 0, 0.84, 0);\n}\n.telebox-readonly .telebox-resize-handle {\n cursor: initial !important;\n pointer-events: none !important;\n}\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n.telebox-color-scheme-dark .telebox-box-main {\n border: 1px solid #383b42;\n border: var(--tele-boxBorder, 1px solid #383b42);\n box-shadow: 0px 4px 10px 0px rgba(56, 59, 66, 0.15);\n box-shadow: var(--tele-boxShadow, 0px 4px 10px 0px rgba(56, 59, 66, 0.15));\n}')();
8
+ var shadowStyles = /* @__PURE__ */ (() => '.tele-fancy-scrollbar {\n overscroll-behavior: contain;\n overflow: auto;\n overflow-y: scroll;\n overflow-y: overlay;\n -webkit-overflow-scrolling: touch;\n -ms-overflow-style: -ms-autohiding-scrollbar;\n scrollbar-width: auto;\n}\n.tele-fancy-scrollbar::-webkit-scrollbar {\n height: 8px;\n width: 8px;\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-track {\n background-color: transparent;\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb {\n background-color: rgba(68, 78, 96, 0.1);\n background-color: transparent;\n border-radius: 4px;\n transition: background-color 0.4s;\n}\n.tele-fancy-scrollbar:hover::-webkit-scrollbar-thumb {\n background-color: rgba(68, 78, 96, 0.1);\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb:hover {\n background-color: rgba(68, 78, 96, 0.2);\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb:active {\n background-color: rgba(68, 78, 96, 0.2);\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb:vertical {\n min-height: 50px;\n}\n.tele-fancy-scrollbar::-webkit-scrollbar-thumb:horizontal {\n min-width: 50px;\n}\n.telebox-quarantine {\n all: initial;\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n}\n.telebox-body-wrap {\n color: #191919;\n color: var(--tele-boxColor, #191919);\n flex: 1;\n width: 100%;\n overflow: hidden;\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n}\n.telebox-content {\n width: 100%;\n height: 100%;\n position: relative;\n background-color: #f9f9f9;\n background-color: var(--tele-boxContainerBackground, #f9f9f9);\n}\n.telebox-box-stage {\n position: absolute;\n z-index: 1;\n overflow: hidden;\n background-color: #fff;\n background-color: var(--tele-boxStageBackground, #fff);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);\n box-shadow: var(--tele-boxStageShadow, 0px 0px 16px rgba(0, 0, 0, 0.08));\n}\n.telebox-footer-wrap {\n flex-shrink: 0;\n display: flex;\n flex-direction: column;\n color: #191919;\n color: var(--tele-boxFooterColor, #191919);\n background-color: #fff;\n background-color: var(--tele-boxFooterBackground, #fff);\n}\n.telebox-footer-wrap::before {\n content: "";\n display: block;\n flex: 1;\n}\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n.telebox-color-scheme-dark .telebox-body-wrap {\n color: #e9e9e9;\n color: var(--tele-boxColor, #e9e9e9);\n}\n.telebox-color-scheme-dark .telebox-content {\n background-color: #25282e;\n background-color: var(--tele-boxContainerBackground, #25282e);\n}\n.telebox-color-scheme-dark .telebox-box-stage {\n background-color: #272a30;\n background-color: var(--tele-boxStageBackground, #272a30);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.24);\n box-shadow: var(--tele-boxStageShadow, 0px 0px 16px rgba(0, 0, 0, 0.24));\n}\n.telebox-color-scheme-dark .telebox-footer-wrap {\n color: #e9e9e9;\n color: var(--tele-boxFooterColor, #e9e9e9);\n background-color: #383b42;\n background-color: var(--tele-boxFooterBackground, #383b42);\n}')();
9
+ var style$3 = /* @__PURE__ */ (() => '.telebox-titlebar {\n user-select: none;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n box-sizing: border-box;\n height: 26px;\n display: flex;\n align-items: center;\n user-select: none;\n touch-action: manipulation;\n color: #191919;\n color: var(--tele-titlebarColor, #191919);\n background-color: #fff;\n background-color: var(--tele-titlebarBackground, #fff);\n border-bottom: 1px solid #eeeef7;\n border-bottom: var(--tele-titlebarBorderBottom, 1px solid #eeeef7);\n}\n\n.telebox-title-area {\n padding-left: 16px;\n overflow: hidden;\n position: relative;\n height: 100%;\n flex: 1;\n display: flex;\n align-items: center;\n}\n\n.telebox-title {\n user-select: none;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n color: #191919;\n color: var(--tele-titlebarColor, #191919);\n overflow: hidden;\n margin: 0;\n padding: 0;\n font-size: 14px;\n font-weight: 400;\n font-family: PingFangSC-Regular, PingFang SC;\n white-space: nowrap;\n word-break: keep-all;\n text-overflow: ellipsis;\n}\n\n.telebox-drag-area {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n margin: auto;\n z-index: 10;\n touch-action: none;\n}\n\n.telebox-titlebar-btns {\n padding-right: 16px;\n white-space: nowrap;\n word-break: keep-all;\n margin-left: auto;\n font-size: 0;\n}\n\n.telebox-titlebar-btn {\n user-select: none;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n width: 22px;\n height: 22px;\n padding: 0;\n outline: none;\n border: none;\n background: transparent;\n cursor: pointer;\n}\n\n.telebox-titlebar-btn ~ .telebox-titlebar-btn {\n margin-left: 10px;\n}\n\n.telebox-titlebar-btn-icon {\n width: 22px;\n height: 22px;\n}\n\n.telebox-readonly .telebox-titlebar-btn {\n cursor: not-allowed;\n}\n\n.telebox-titlebar-icon-minimize {\n background: center/cover no-repeat;\n background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgMjggMjgiPgogICAgPGRlZnM+CiAgICAgICAgPHBhdGggaWQ9ImEiIGQ9Ik0wIDBoMjh2MjhIMHoiIC8+CiAgICA8L2RlZnM+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxtYXNrIGlkPSJiIiBmaWxsPSIjZmZmIj4KICAgICAgICAgICAgPHVzZSB4bGluazpocmVmPSIjYSIgLz4KICAgICAgICA8L21hc2s+CiAgICAgICAgPHBhdGggZmlsbD0iI0E3QTdDQSIgZmlsbC1ydWxlPSJub256ZXJvIiBkPSJNOSAxM2gxMHYxLjZIOXoiIG1hc2s9InVybCgjYikiIC8+CiAgICA8L2c+Cjwvc3ZnPgo=");\n background-image: var(--tele-titlebarIconMinimize, url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgMjggMjgiPgogICAgPGRlZnM+CiAgICAgICAgPHBhdGggaWQ9ImEiIGQ9Ik0wIDBoMjh2MjhIMHoiIC8+CiAgICA8L2RlZnM+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxtYXNrIGlkPSJiIiBmaWxsPSIjZmZmIj4KICAgICAgICAgICAgPHVzZSB4bGluazpocmVmPSIjYSIgLz4KICAgICAgICA8L21hc2s+CiAgICAgICAgPHBhdGggZmlsbD0iI0E3QTdDQSIgZmlsbC1ydWxlPSJub256ZXJvIiBkPSJNOSAxM2gxMHYxLjZIOXoiIG1hc2s9InVybCgjYikiIC8+CiAgICA8L2c+Cjwvc3ZnPgo="));\n}\n\n.telebox-titlebar-icon-maximize {\n background: center/cover no-repeat;\n background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgMjggMjgiPgogICAgPGRlZnM+CiAgICAgICAgPHBhdGggaWQ9ImEiIGQ9Ik0wIDBoMjh2MjhIMHoiIC8+CiAgICA8L2RlZnM+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxtYXNrIGlkPSJiIiBmaWxsPSIjZmZmIj4KICAgICAgICAgICAgPHVzZSB4bGluazpocmVmPSIjYSIgLz4KICAgICAgICA8L21hc2s+CiAgICAgICAgPGcgZmlsbD0iI0E3QTdDQSIgZmlsbC1ydWxlPSJub256ZXJvIiBtYXNrPSJ1cmwoI2IpIj4KICAgICAgICAgICAgPHBhdGgKICAgICAgICAgICAgICAgIGQ9Ik0yMC40ODEgMTcuMWgxLjJ2NC41ODFIMTcuMXYtMS4yaDMuMzgxVjE3LjF6bS0xNC4xOTA1LS4wMDloMS4ydjMuMzgxaDMuMzgwOXYxLjJoLTQuNTgxdi00LjU4MXpNMTcuMSA2LjE5MDVoNC41ODF2NC41ODA5aC0xLjJ2LTMuMzgxSDE3LjF2LTEuMnptLTEwLjcwMDguMTA4N2g0Ljc5ODV2MS4ySDcuNTk5MnYzLjU5ODVoLTEuMlY2LjI5OTJ6IiAvPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+Cg==");\n background-image: var(--tele-titlebarIconMaximize, url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgMjggMjgiPgogICAgPGRlZnM+CiAgICAgICAgPHBhdGggaWQ9ImEiIGQ9Ik0wIDBoMjh2MjhIMHoiIC8+CiAgICA8L2RlZnM+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxtYXNrIGlkPSJiIiBmaWxsPSIjZmZmIj4KICAgICAgICAgICAgPHVzZSB4bGluazpocmVmPSIjYSIgLz4KICAgICAgICA8L21hc2s+CiAgICAgICAgPGcgZmlsbD0iI0E3QTdDQSIgZmlsbC1ydWxlPSJub256ZXJvIiBtYXNrPSJ1cmwoI2IpIj4KICAgICAgICAgICAgPHBhdGgKICAgICAgICAgICAgICAgIGQ9Ik0yMC40ODEgMTcuMWgxLjJ2NC41ODFIMTcuMXYtMS4yaDMuMzgxVjE3LjF6bS0xNC4xOTA1LS4wMDloMS4ydjMuMzgxaDMuMzgwOXYxLjJoLTQuNTgxdi00LjU4MXpNMTcuMSA2LjE5MDVoNC41ODF2NC41ODA5aC0xLjJ2LTMuMzgxSDE3LjF2LTEuMnptLTEwLjcwMDguMTA4N2g0Ljc5ODV2MS4ySDcuNTk5MnYzLjU5ODVoLTEuMlY2LjI5OTJ6IiAvPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+Cg=="));\n}\n\n.telebox-titlebar-icon-maximize.is-active {\n background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgMjggMjgiPgogICAgPGRlZnM+CiAgICAgICAgPHBhdGggaWQ9ImEiIGQ9Ik0wIDBoMjZ2MjZIMHoiIC8+CiAgICAgICAgPHBhdGggaWQ9ImMiIGQ9Ik0yNi44NjkgMEwyOCAxLjEzMVYyNi44N0wyNi44NjkgMjhIMS4xM0wwIDI2Ljg3VjEuMTMxTDEuMTMgMHoiIC8+CiAgICA8L2RlZnM+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxnIHRyYW5zZm9ybT0idHJhbnNsYXRlKDEgMSkiPgogICAgICAgICAgICA8bWFzayBpZD0iYiIgZmlsbD0iI2ZmZiI+CiAgICAgICAgICAgICAgICA8dXNlIHhsaW5rOmhyZWY9IiNhIiAvPgogICAgICAgICAgICA8L21hc2s+CiAgICAgICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIGQ9Ik0tNC42NDI5LTQuNjQyOWgzNS4yODU4djM1LjI4NThILTQuNjQyOXoiIG1hc2s9InVybCgjYikiIC8+CiAgICAgICAgPC9nPgogICAgICAgIDxnPgogICAgICAgICAgICA8bWFzayBpZD0iZCIgZmlsbD0iI2ZmZiI+CiAgICAgICAgICAgICAgICA8dXNlIHhsaW5rOmhyZWY9IiNjIiAvPgogICAgICAgICAgICA8L21hc2s+CiAgICAgICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIGQ9Ik0tMTcuNTE2OCAxNEwxNC0xNy41MTY4IDQ1LjUxNjggMTQgMTQgNDUuNTE2OHoiIG1hc2s9InVybCgjZCkiIC8+CiAgICAgICAgPC9nPgogICAgICAgIDxwYXRoIHN0cm9rZT0iI0E3QTdDQSIgc3Ryb2tlLXdpZHRoPSIxLjIiCiAgICAgICAgICAgIGQ9Ik0xMC4wODg2IDIxLjQ4NjV2LTMuNjk2Nkg2LjM5Mk0yMS4zODU1IDEwLjE4OTVoLTMuNjk2NlY2LjQ5M00yMS40MDIgMTcuNzk4M2gtMy42OTY2djMuNjk2Nk0xMC4yNTAzIDYuMTQ5OHYzLjg5ODVINi4zNTE3IiAvPgogICAgPC9nPgo8L3N2Zz4K");\n background-image: var(--tele-titlebarIconMaximizeActive, url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgMjggMjgiPgogICAgPGRlZnM+CiAgICAgICAgPHBhdGggaWQ9ImEiIGQ9Ik0wIDBoMjZ2MjZIMHoiIC8+CiAgICAgICAgPHBhdGggaWQ9ImMiIGQ9Ik0yNi44NjkgMEwyOCAxLjEzMVYyNi44N0wyNi44NjkgMjhIMS4xM0wwIDI2Ljg3VjEuMTMxTDEuMTMgMHoiIC8+CiAgICA8L2RlZnM+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxnIHRyYW5zZm9ybT0idHJhbnNsYXRlKDEgMSkiPgogICAgICAgICAgICA8bWFzayBpZD0iYiIgZmlsbD0iI2ZmZiI+CiAgICAgICAgICAgICAgICA8dXNlIHhsaW5rOmhyZWY9IiNhIiAvPgogICAgICAgICAgICA8L21hc2s+CiAgICAgICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIGQ9Ik0tNC42NDI5LTQuNjQyOWgzNS4yODU4djM1LjI4NThILTQuNjQyOXoiIG1hc2s9InVybCgjYikiIC8+CiAgICAgICAgPC9nPgogICAgICAgIDxnPgogICAgICAgICAgICA8bWFzayBpZD0iZCIgZmlsbD0iI2ZmZiI+CiAgICAgICAgICAgICAgICA8dXNlIHhsaW5rOmhyZWY9IiNjIiAvPgogICAgICAgICAgICA8L21hc2s+CiAgICAgICAgICAgIDxwYXRoIGZpbGw9Im5vbmUiIGQ9Ik0tMTcuNTE2OCAxNEwxNC0xNy41MTY4IDQ1LjUxNjggMTQgMTQgNDUuNTE2OHoiIG1hc2s9InVybCgjZCkiIC8+CiAgICAgICAgPC9nPgogICAgICAgIDxwYXRoIHN0cm9rZT0iI0E3QTdDQSIgc3Ryb2tlLXdpZHRoPSIxLjIiCiAgICAgICAgICAgIGQ9Ik0xMC4wODg2IDIxLjQ4NjV2LTMuNjk2Nkg2LjM5Mk0yMS4zODU1IDEwLjE4OTVoLTMuNjk2NlY2LjQ5M00yMS40MDIgMTcuNzk4M2gtMy42OTY2djMuNjk2Nk0xMC4yNTAzIDYuMTQ5OHYzLjg5ODVINi4zNTE3IiAvPgogICAgPC9nPgo8L3N2Zz4K"));\n}\n\n.telebox-titlebar-icon-close {\n background: center/cover no-repeat;\n background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyOCAyOCI+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZT0iI0E3QTdDQSIgc3Ryb2tlLXdpZHRoPSIxLjQiPgogICAgICAgIDxwYXRoIGQ9Ik04LjM1MyAyMC4zMzIxTDIwLjMzMiA4LjM1M00yMC4zMzIyIDIwLjMzMjFMOC4zNTMgOC4zNTMiIC8+CiAgICA8L2c+Cjwvc3ZnPgo=");\n background-image: var(--tele-titlebarIconClose, url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyOCAyOCI+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZT0iI0E3QTdDQSIgc3Ryb2tlLXdpZHRoPSIxLjQiPgogICAgICAgIDxwYXRoIGQ9Ik04LjM1MyAyMC4zMzIxTDIwLjMzMiA4LjM1M00yMC4zMzIyIDIwLjMzMjFMOC4zNTMgOC4zNTMiIC8+CiAgICA8L2c+Cjwvc3ZnPgo="));\n}\n\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n\n.telebox-color-scheme-dark .telebox-title {\n color: #e9e9e9;\n color: var(--tele-titlebarColor, #e9e9e9);\n}\n\n.telebox-color-scheme-dark .telebox-titlebar {\n color: #e9e9e9;\n color: var(--tele-titlebarColor, #e9e9e9);\n background-color: #383b42;\n background-color: var(--tele-titlebarBackground, #383b42);\n border-bottom: none;\n border-bottom: var(--tele-titlebarBorderBottom, none);\n}')();
10
+ var TELE_BOX_COLOR_SCHEME = /* @__PURE__ */ ((TELE_BOX_COLOR_SCHEME2) => {
11
+ TELE_BOX_COLOR_SCHEME2["Light"] = "light";
12
+ TELE_BOX_COLOR_SCHEME2["Dark"] = "dark";
13
+ TELE_BOX_COLOR_SCHEME2["Auto"] = "auto";
14
+ return TELE_BOX_COLOR_SCHEME2;
15
+ })(TELE_BOX_COLOR_SCHEME || {});
16
+ var TELE_BOX_STATE = /* @__PURE__ */ ((TELE_BOX_STATE2) => {
17
+ TELE_BOX_STATE2["Normal"] = "normal";
18
+ TELE_BOX_STATE2["Minimized"] = "minimized";
19
+ TELE_BOX_STATE2["Maximized"] = "maximized";
20
+ return TELE_BOX_STATE2;
21
+ })(TELE_BOX_STATE || {});
22
+ var TELE_BOX_EVENT = /* @__PURE__ */ ((TELE_BOX_EVENT2) => {
23
+ TELE_BOX_EVENT2["DarkMode"] = "dark_mode";
24
+ TELE_BOX_EVENT2["PrefersColorScheme"] = "prefers_color_scheme";
25
+ TELE_BOX_EVENT2["Close"] = "close";
26
+ TELE_BOX_EVENT2["Focus"] = "focus";
27
+ TELE_BOX_EVENT2["Blur"] = "blur";
28
+ TELE_BOX_EVENT2["IntrinsicMove"] = "intrinsic_move";
29
+ TELE_BOX_EVENT2["IntrinsicResize"] = "intrinsic_resize";
30
+ TELE_BOX_EVENT2["ZIndex"] = "z_index";
31
+ TELE_BOX_EVENT2["State"] = "state";
32
+ TELE_BOX_EVENT2["Minimized"] = "minimized";
33
+ TELE_BOX_EVENT2["Maximized"] = "maximized";
34
+ TELE_BOX_EVENT2["Readonly"] = "readonly";
35
+ TELE_BOX_EVENT2["Destroyed"] = "destroyed";
36
+ return TELE_BOX_EVENT2;
37
+ })(TELE_BOX_EVENT || {});
38
+ var TELE_BOX_DELEGATE_EVENT = /* @__PURE__ */ ((TELE_BOX_DELEGATE_EVENT2) => {
39
+ TELE_BOX_DELEGATE_EVENT2["Close"] = "close";
40
+ TELE_BOX_DELEGATE_EVENT2["Maximize"] = "maximize";
41
+ TELE_BOX_DELEGATE_EVENT2["Minimize"] = "minimize";
42
+ return TELE_BOX_DELEGATE_EVENT2;
43
+ })(TELE_BOX_DELEGATE_EVENT || {});
44
+ var TELE_BOX_RESIZE_HANDLE = /* @__PURE__ */ ((TELE_BOX_RESIZE_HANDLE2) => {
45
+ TELE_BOX_RESIZE_HANDLE2["North"] = "n";
46
+ TELE_BOX_RESIZE_HANDLE2["South"] = "s";
47
+ TELE_BOX_RESIZE_HANDLE2["West"] = "w";
48
+ TELE_BOX_RESIZE_HANDLE2["East"] = "e";
49
+ TELE_BOX_RESIZE_HANDLE2["NorthWest"] = "nw";
50
+ TELE_BOX_RESIZE_HANDLE2["NorthEast"] = "ne";
51
+ TELE_BOX_RESIZE_HANDLE2["SouthEast"] = "se";
52
+ TELE_BOX_RESIZE_HANDLE2["SouthWest"] = "sw";
53
+ return TELE_BOX_RESIZE_HANDLE2;
54
+ })(TELE_BOX_RESIZE_HANDLE || {});
55
+ const TeleBoxDragHandleType = "dh";
56
+ function clamp(value, min, max) {
57
+ return Math.min(Math.max(value, min), max);
58
+ }
59
+ function preventEvent(ev) {
60
+ ev.stopPropagation();
61
+ if (ev.cancelable) {
62
+ ev.preventDefault();
63
+ }
64
+ }
65
+ let defaultBoxCount = 1;
66
+ function getBoxDefaultName() {
67
+ return `New Box ${defaultBoxCount++}`;
68
+ }
69
+ class DefaultTitleBar {
70
+ constructor({
71
+ readonly$,
72
+ state$,
73
+ title$,
74
+ buttons,
75
+ onEvent,
76
+ onDragStart,
77
+ namespace = "telebox"
78
+ }) {
79
+ this.sideEffect = new SideEffectManager();
80
+ this.lastTitleBarClick = {
81
+ timestamp: 0,
82
+ clientX: -100,
83
+ clientY: -100
84
+ };
85
+ this.handleTitleBarClick = (ev) => {
86
+ var _a;
87
+ if (!ev.isPrimary || this.readonly$.value) {
88
+ return;
89
+ }
90
+ if (ev.button !== 0) {
91
+ return;
92
+ }
93
+ if ((_a = ev.target.dataset) == null ? void 0 : _a.teleTitleBarNoDblClick) {
94
+ return;
95
+ }
96
+ preventEvent(ev);
97
+ const now = Date.now();
98
+ if (now - this.lastTitleBarClick.timestamp <= 500) {
99
+ if (Math.abs(ev.clientX - this.lastTitleBarClick.clientX) <= 5 && Math.abs(ev.clientY - this.lastTitleBarClick.clientY) <= 5) {
100
+ if (this.onEvent) {
101
+ this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
102
+ }
103
+ }
104
+ } else if (this.onDragStart) {
105
+ this.onDragStart(ev);
106
+ }
107
+ this.lastTitleBarClick.timestamp = now;
108
+ this.lastTitleBarClick.clientX = ev.clientX;
109
+ this.lastTitleBarClick.clientY = ev.clientY;
110
+ };
111
+ this.readonly$ = readonly$;
112
+ this.state$ = state$;
113
+ this.title$ = title$;
114
+ this.onEvent = onEvent;
115
+ this.onDragStart = onDragStart;
116
+ this.namespace = namespace;
117
+ this.buttons = buttons || [
118
+ {
119
+ type: TELE_BOX_DELEGATE_EVENT.Minimize,
120
+ iconClassName: this.wrapClassName("titlebar-icon-minimize")
121
+ },
122
+ {
123
+ type: TELE_BOX_DELEGATE_EVENT.Maximize,
124
+ iconClassName: this.wrapClassName("titlebar-icon-maximize"),
125
+ isActive: (state) => state === TELE_BOX_STATE.Maximized
126
+ },
127
+ {
128
+ type: TELE_BOX_DELEGATE_EVENT.Close,
129
+ iconClassName: this.wrapClassName("titlebar-icon-close")
130
+ }
131
+ ];
132
+ this.$dragArea = this.renderDragArea();
133
+ }
134
+ render() {
135
+ if (!this.$titleBar) {
136
+ this.$titleBar = document.createElement("div");
137
+ this.$titleBar.className = this.wrapClassName("titlebar");
138
+ const $titleArea = document.createElement("div");
139
+ $titleArea.className = this.wrapClassName("title-area");
140
+ $titleArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
141
+ const $title = document.createElement("h1");
142
+ $title.className = this.wrapClassName("title");
143
+ $title.dataset.teleBoxHandle = TeleBoxDragHandleType;
144
+ $titleArea.appendChild($title);
145
+ $titleArea.appendChild(this.$dragArea);
146
+ const $buttonsContainer = document.createElement("div");
147
+ $buttonsContainer.className = this.wrapClassName("titlebar-btns");
148
+ this.buttons.forEach(({ iconClassName }, i) => {
149
+ const teleTitleBarBtnIndex = String(i);
150
+ const $btn = document.createElement("button");
151
+ $btn.className = `${this.wrapClassName("titlebar-btn")} ${iconClassName}`;
152
+ $btn.dataset.teleTitleBarBtnIndex = teleTitleBarBtnIndex;
153
+ $btn.dataset.teleTitleBarNoDblClick = "true";
154
+ $buttonsContainer.appendChild($btn);
155
+ });
156
+ this.sideEffect.addDisposer(this.title$.subscribe((title) => {
157
+ $title.textContent = title;
158
+ $title.title = title;
159
+ }), "render-title");
160
+ this.sideEffect.addDisposer(this.state$.subscribe((state) => {
161
+ this.buttons.forEach((btn, i) => {
162
+ var _a;
163
+ if (btn.isActive) {
164
+ (_a = $buttonsContainer.children[i]) == null ? void 0 : _a.classList.toggle("is-active", btn.isActive(state));
165
+ }
166
+ });
167
+ }), "render-state-btns");
168
+ this.sideEffect.addEventListener($buttonsContainer, "click", (ev) => {
169
+ var _a;
170
+ if (this.readonly$.value) {
171
+ return;
172
+ }
173
+ const target = ev.target;
174
+ const teleTitleBarBtnIndex = Number((_a = target.dataset) == null ? void 0 : _a.teleTitleBarBtnIndex);
175
+ if (!Number.isNaN(teleTitleBarBtnIndex) && teleTitleBarBtnIndex < this.buttons.length) {
176
+ preventEvent(ev);
177
+ const btn = this.buttons[teleTitleBarBtnIndex];
178
+ if (this.onEvent) {
179
+ this.onEvent({
180
+ type: btn.type,
181
+ value: btn.value
182
+ });
183
+ }
184
+ }
185
+ }, {}, "render-btns-container-click");
186
+ this.$titleBar.appendChild($titleArea);
187
+ this.$titleBar.appendChild($buttonsContainer);
188
+ }
189
+ return this.$titleBar;
190
+ }
191
+ renderDragArea() {
192
+ const $dragArea = document.createElement("div");
193
+ $dragArea.className = this.wrapClassName("drag-area");
194
+ $dragArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
195
+ this.sideEffect.addEventListener($dragArea, "pointerdown", this.handleTitleBarClick);
196
+ return $dragArea;
197
+ }
198
+ dragHandle() {
199
+ return this.$titleBar;
200
+ }
201
+ wrapClassName(className) {
202
+ return `${this.namespace}-${className}`;
203
+ }
204
+ destroy() {
205
+ this.sideEffect.flushAll();
206
+ if (this.$titleBar) {
207
+ this.$titleBar = void 0;
208
+ this.onDragStart = void 0;
209
+ this.onEvent = void 0;
210
+ }
211
+ }
212
+ }
213
+ function calcStageRect([rootRect, ratio]) {
214
+ if (ratio <= 0 || rootRect.width <= 0 || rootRect.height <= 0) {
215
+ return rootRect;
216
+ }
217
+ const preferredHeight = rootRect.width * ratio;
218
+ if (preferredHeight === rootRect.height) {
219
+ return rootRect;
220
+ }
221
+ if (preferredHeight < rootRect.height) {
222
+ return {
223
+ x: 0,
224
+ y: (rootRect.height - preferredHeight) / 2,
225
+ width: rootRect.width,
226
+ height: preferredHeight
227
+ };
228
+ }
229
+ const preferredWidth = rootRect.height / ratio;
230
+ return {
231
+ x: (rootRect.width - preferredWidth) / 2,
232
+ y: 0,
233
+ width: preferredWidth,
234
+ height: rootRect.height
235
+ };
236
+ }
237
+ const ResizeObserver$1 = window.ResizeObserver || ResizeObserver$2;
238
+ class TeleBox {
239
+ constructor({
240
+ id = genUID(),
241
+ title = getBoxDefaultName(),
242
+ namespace = "telebox",
243
+ visible = true,
244
+ width = 0.5,
245
+ height = 0.5,
246
+ minWidth = 0,
247
+ minHeight = 0,
248
+ x = 0.1,
249
+ y = 0.1,
250
+ resizable = true,
251
+ draggable = true,
252
+ boxRatio = -1,
253
+ focus = false,
254
+ zIndex = 100,
255
+ stageRatio = null,
256
+ enableShadowDOM = true,
257
+ titleBar,
258
+ content,
259
+ stage,
260
+ footer,
261
+ styles,
262
+ userStyles,
263
+ bodyStyle = null,
264
+ stageStyle = null,
265
+ darkMode$,
266
+ fence$,
267
+ root,
268
+ rootRect$,
269
+ managerMinimized$,
270
+ managerMaximized$,
271
+ managerReadonly$,
272
+ managerStageRect$,
273
+ managerStageRatio$,
274
+ defaultBoxBodyStyle$,
275
+ defaultBoxStageStyle$,
276
+ collectorRect$
277
+ }) {
278
+ this.events = new Emittery();
279
+ this._delegateEvents = new Emittery();
280
+ this.handleTrackStart = (ev) => {
281
+ var _a;
282
+ return (_a = this._handleTrackStart) == null ? void 0 : _a.call(this, ev);
283
+ };
284
+ this._sideEffect = new SideEffectManager();
285
+ this.id = id;
286
+ this.namespace = namespace;
287
+ this.enableShadowDOM = enableShadowDOM;
288
+ const valManager = new ValManager();
289
+ this._sideEffect.addDisposer(() => valManager.destroy());
290
+ const title$ = new Val(title);
291
+ const visible$ = new Val(visible);
292
+ const resizable$ = new Val(resizable);
293
+ const draggable$ = new Val(draggable);
294
+ const boxRatio$ = new Val(boxRatio);
295
+ const zIndex$ = new Val(zIndex);
296
+ const focus$ = new Val(focus);
297
+ const boxMaximized$ = new Val(null);
298
+ const boxMinimized$ = new Val(null);
299
+ const boxReadonly$ = new Val(null);
300
+ const maximized$ = combine([boxMaximized$, managerMaximized$], ([boxMaximized, managerMaximized]) => boxMaximized != null ? boxMaximized : managerMaximized);
301
+ const minimized$ = combine([boxMinimized$, managerMinimized$], ([boxMinimized, managerMinimized]) => boxMinimized != null ? boxMinimized : managerMinimized);
302
+ const readonly$ = combine([boxReadonly$, managerReadonly$], ([boxReadonly, managerReadonly]) => boxReadonly != null ? boxReadonly : managerReadonly);
303
+ const state$ = combine([minimized$, maximized$], ([minimized, maximized]) => minimized ? TELE_BOX_STATE.Minimized : maximized ? TELE_BOX_STATE.Maximized : TELE_BOX_STATE.Normal);
304
+ const minSize$ = new Val({
305
+ width: clamp(minWidth, 0, 1),
306
+ height: clamp(minHeight, 0, 1)
307
+ }, { compare: shallowequal });
308
+ const pxMinSize$ = combine([minSize$, managerStageRect$], ([minSize, managerStageRect]) => ({
309
+ width: minSize.width * managerStageRect.width,
310
+ height: minSize.height * managerStageRect.height
311
+ }), { compare: shallowequal });
312
+ const intrinsicSize$ = new Val({ width, height }, { compare: shallowequal });
313
+ this._sideEffect.addDisposer(minSize$.reaction((minSize, skipUpdate) => {
314
+ intrinsicSize$.setValue({
315
+ width: Math.max(width, minSize.width),
316
+ height: Math.max(height, minSize.height)
317
+ }, skipUpdate);
318
+ }));
319
+ const intrinsicCoord$ = new Val({ x, y }, { compare: shallowequal });
320
+ const pxIntrinsicSize$ = combine([intrinsicSize$, managerStageRect$], ([size, managerStageRect]) => ({
321
+ width: managerStageRect.width * size.width,
322
+ height: managerStageRect.height * size.height
323
+ }), { compare: shallowequal });
324
+ const pxIntrinsicCoord$ = combine([intrinsicCoord$, managerStageRect$], ([intrinsicCoord, managerStageRect]) => ({
325
+ x: intrinsicCoord.x * managerStageRect.width,
326
+ y: intrinsicCoord.y * managerStageRect.height
327
+ }), { compare: shallowequal });
328
+ const bodyStyle$ = new Val(bodyStyle);
329
+ const stageStyle$ = new Val(stageStyle);
330
+ const contentRoot$ = new Val(null);
331
+ const bodyRect$ = new Val(managerStageRect$.value, {
332
+ compare: shallowequal
333
+ });
334
+ const stageRatio$ = new Val(stageRatio);
335
+ const finalStageRatio$ = combine([stageRatio$, managerStageRatio$], ([stageRatio2, managerStageRatio]) => stageRatio2 != null ? stageRatio2 : managerStageRatio);
336
+ const stageRect$ = combine([bodyRect$, finalStageRatio$], calcStageRect, { compare: shallowequal });
337
+ const propsValConfig = {
338
+ darkMode: darkMode$,
339
+ fence: fence$,
340
+ rootRect: rootRect$,
341
+ managerMinimized: managerMinimized$,
342
+ managerMaximized: managerMaximized$,
343
+ managerReadonly: managerReadonly$,
344
+ managerStageRect: managerStageRect$,
345
+ managerStageRatio: managerStageRatio$,
346
+ defaultBoxBodyStyle: defaultBoxBodyStyle$,
347
+ defaultBoxStageStyle: defaultBoxStageStyle$,
348
+ collectorRect: collectorRect$
349
+ };
350
+ withReadonlyValueEnhancer(this, propsValConfig);
351
+ const myReadonlyValConfig = {
352
+ zIndex: zIndex$,
353
+ focus: focus$,
354
+ state: state$,
355
+ minSize: minSize$,
356
+ pxMinSize: pxMinSize$,
357
+ intrinsicSize: intrinsicSize$,
358
+ intrinsicCoord: intrinsicCoord$,
359
+ pxIntrinsicSize: pxIntrinsicSize$,
360
+ pxIntrinsicCoord: pxIntrinsicCoord$,
361
+ bodyRect: bodyRect$,
362
+ stageRect: stageRect$,
363
+ minimized: minimized$,
364
+ maximized: maximized$,
365
+ readonly: readonly$
366
+ };
367
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
368
+ const valConfig = {
369
+ title: title$,
370
+ visible: visible$,
371
+ resizable: resizable$,
372
+ draggable: draggable$,
373
+ boxRatio: boxRatio$,
374
+ boxMinimized: boxMinimized$,
375
+ boxMaximized: boxMaximized$,
376
+ boxReadonly: boxReadonly$,
377
+ stageRatio: stageRatio$,
378
+ bodyStyle: bodyStyle$,
379
+ stageStyle: stageStyle$
380
+ };
381
+ withValueEnhancer(this, valConfig, valManager);
382
+ this.titleBar = titleBar || new DefaultTitleBar({
383
+ readonly$,
384
+ state$,
385
+ title$,
386
+ namespace: this.namespace,
387
+ onDragStart: (event) => {
388
+ var _a;
389
+ return (_a = this._handleTrackStart) == null ? void 0 : _a.call(this, event);
390
+ },
391
+ onEvent: (event) => this._delegateEvents.emit(event.type)
392
+ });
393
+ this._sideEffect.addDisposer(boxRatio$.subscribe((boxRatio2) => {
394
+ if (boxRatio2 > 0) {
395
+ this.transform(pxIntrinsicCoord$.value.x, pxIntrinsicCoord$.value.y, pxIntrinsicSize$.value.width, pxIntrinsicSize$.value.height);
396
+ }
397
+ }));
398
+ this._sideEffect.addDisposer(fence$.subscribe((fence) => {
399
+ if (fence) {
400
+ this.move(pxIntrinsicCoord$.value.x, pxIntrinsicCoord$.value.y);
401
+ }
402
+ }));
403
+ this.$box = this._render();
404
+ contentRoot$.setValue(this.$content.parentElement);
405
+ content && this.mountContent(content);
406
+ stage && this.mountStage(stage);
407
+ footer && this.mountFooter(footer);
408
+ styles && this.mountStyles(styles);
409
+ userStyles && this.mountUserStyles(userStyles);
410
+ root.appendChild(this.$box);
411
+ const watchValEvent = (val, event) => {
412
+ this._sideEffect.addDisposer(val.reaction((v, skipUpdate) => {
413
+ if (!skipUpdate) {
414
+ this.events.emit(event, v);
415
+ }
416
+ }));
417
+ };
418
+ watchValEvent(darkMode$, TELE_BOX_EVENT.DarkMode);
419
+ watchValEvent(readonly$, TELE_BOX_EVENT.Readonly);
420
+ watchValEvent(zIndex$, TELE_BOX_EVENT.ZIndex);
421
+ watchValEvent(minimized$, TELE_BOX_EVENT.Minimized);
422
+ watchValEvent(maximized$, TELE_BOX_EVENT.Maximized);
423
+ watchValEvent(state$, TELE_BOX_EVENT.State);
424
+ watchValEvent(intrinsicSize$, TELE_BOX_EVENT.IntrinsicResize);
425
+ watchValEvent(intrinsicCoord$, TELE_BOX_EVENT.IntrinsicMove);
426
+ this._sideEffect.addDisposer([
427
+ visible$.reaction((visible2, skipUpdate) => {
428
+ if (!skipUpdate && !visible2) {
429
+ this.events.emit(TELE_BOX_EVENT.Close);
430
+ }
431
+ }),
432
+ focus$.reaction((focus2, skipUpdate) => {
433
+ if (!skipUpdate) {
434
+ this.events.emit(focus2 ? TELE_BOX_EVENT.Focus : TELE_BOX_EVENT.Blur);
435
+ }
436
+ })
437
+ ]);
438
+ }
439
+ get minWidth() {
440
+ return this._minSize$.value.width;
441
+ }
442
+ get minHeight() {
443
+ return this._minSize$.value.height;
444
+ }
445
+ setMinWidth(minWidth, skipUpdate = false) {
446
+ this._minSize$.setValue({ width: minWidth, height: this.minHeight }, skipUpdate);
447
+ }
448
+ setMinHeight(minHeight, skipUpdate = false) {
449
+ this._minSize$.setValue({ width: this.minWidth, height: minHeight }, skipUpdate);
450
+ }
451
+ resize(width, height, skipUpdate = false) {
452
+ this._intrinsicSize$.setValue({
453
+ width: Math.max(width, this.minWidth),
454
+ height: Math.max(height, this.minHeight)
455
+ }, skipUpdate);
456
+ }
457
+ get intrinsicX() {
458
+ return this._intrinsicCoord$.value.x;
459
+ }
460
+ get intrinsicY() {
461
+ return this._intrinsicCoord$.value.y;
462
+ }
463
+ get intrinsicWidth() {
464
+ return this._intrinsicSize$.value.width;
465
+ }
466
+ get intrinsicHeight() {
467
+ return this._intrinsicSize$.value.height;
468
+ }
469
+ move(x, y, skipUpdate = false) {
470
+ let safeX;
471
+ let safeY;
472
+ const managerStageRect = this.managerStageRect;
473
+ const pxIntrinsicSize = this.pxIntrinsicSize;
474
+ if (this.fence) {
475
+ safeX = clamp(x, 0, managerStageRect.width - pxIntrinsicSize.width);
476
+ safeY = clamp(y, 0, managerStageRect.height - pxIntrinsicSize.height);
477
+ } else {
478
+ safeX = clamp(x, -(pxIntrinsicSize.width - 120), 0 + managerStageRect.width - 20);
479
+ safeY = clamp(y, 0, 0 + managerStageRect.height - 20);
480
+ }
481
+ this._intrinsicCoord$.setValue({
482
+ x: safeX / managerStageRect.width,
483
+ y: safeY / managerStageRect.height
484
+ }, skipUpdate);
485
+ }
486
+ transform(x, y, width, height, skipUpdate = false) {
487
+ const managerStageRect = this.managerStageRect;
488
+ width = Math.max(width, this.pxMinSize.width);
489
+ height = Math.max(height, this.pxMinSize.height);
490
+ if (this.boxRatio > 0) {
491
+ const newHeight = this.boxRatio * width;
492
+ if (y !== this.pxIntrinsicCoord.y) {
493
+ y -= newHeight - height;
494
+ }
495
+ height = newHeight;
496
+ }
497
+ if (y < 0) {
498
+ y = 0;
499
+ height = this.pxIntrinsicSize.height;
500
+ }
501
+ this.move(x, y, skipUpdate);
502
+ this._intrinsicSize$.setValue({
503
+ width: width / managerStageRect.width,
504
+ height: height / managerStageRect.height
505
+ }, skipUpdate);
506
+ }
507
+ mountContent(content) {
508
+ var _a;
509
+ (_a = this.$authorContent) == null ? void 0 : _a.remove();
510
+ this.$authorContent = content;
511
+ this.$content.appendChild(content);
512
+ }
513
+ unmountContent() {
514
+ if (this.$authorContent) {
515
+ this.$authorContent.remove();
516
+ this.$authorContent = void 0;
517
+ }
518
+ }
519
+ mountStage(stage) {
520
+ var _a;
521
+ (_a = this.$authorStage) == null ? void 0 : _a.remove();
522
+ this.$authorStage = stage;
523
+ if (!this.$stage) {
524
+ this.$stage = this._renderStage();
525
+ }
526
+ this.$stage.appendChild(stage);
527
+ if (!this.$stage.parentElement) {
528
+ this.$body.appendChild(this.$stage);
529
+ }
530
+ }
531
+ unmountStage() {
532
+ var _a;
533
+ if (this.$authorStage) {
534
+ this.$authorStage.remove();
535
+ this.$authorStage = void 0;
536
+ }
537
+ (_a = this.$stage) == null ? void 0 : _a.remove();
538
+ }
539
+ mountFooter(footer) {
540
+ var _a;
541
+ (_a = this.$authorFooter) == null ? void 0 : _a.remove();
542
+ this.$authorFooter = footer;
543
+ this.$footer.appendChild(footer);
544
+ }
545
+ unmountFooter() {
546
+ if (this.$authorFooter) {
547
+ this.$authorFooter.remove();
548
+ this.$authorFooter = void 0;
549
+ }
550
+ }
551
+ mountStyles(styles) {
552
+ this.$styles.textContent = styles;
553
+ }
554
+ unmountStyles() {
555
+ this.$styles.textContent = "";
556
+ }
557
+ mountUserStyles(styles) {
558
+ this.$userStyles.textContent = styles;
559
+ }
560
+ unmountUserStyles() {
561
+ this.$userStyles.textContent = "";
562
+ }
563
+ _render() {
564
+ if (this.$box) {
565
+ return this.$box;
566
+ }
567
+ const bindBoxStates = (el, disposerID) => {
568
+ return this._sideEffect.addDisposer([
569
+ this._readonly$.subscribe((readonly) => el.classList.toggle(this.wrapClassName("readonly"), readonly)),
570
+ this._draggable$.subscribe((draggable) => el.classList.toggle(this.wrapClassName("no-drag"), !draggable)),
571
+ this._resizable$.subscribe((resizable) => el.classList.toggle(this.wrapClassName("no-resize"), !resizable)),
572
+ this._focus$.subscribe((focus) => el.classList.toggle(this.wrapClassName("blur"), !focus)),
573
+ this._darkMode$.subscribe((darkMode) => {
574
+ el.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
575
+ el.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
576
+ })
577
+ ], disposerID);
578
+ };
579
+ this.$box = document.createElement("div");
580
+ this.$box.classList.add(this.wrapClassName("box"));
581
+ bindBoxStates(this.$box, "bind-box-state");
582
+ this._sideEffect.add(() => {
583
+ const minimizedClassName = this.wrapClassName("minimized");
584
+ const maximizedClassName = this.wrapClassName("maximized");
585
+ const MAXIMIZED_TIMER_ID = "box-maximized-timer";
586
+ return this._state$.subscribe((state) => {
587
+ this.$box.classList.toggle(minimizedClassName, state === TELE_BOX_STATE.Minimized);
588
+ if (state === TELE_BOX_STATE.Maximized) {
589
+ this._sideEffect.flush(MAXIMIZED_TIMER_ID);
590
+ this.$box.classList.toggle(maximizedClassName, true);
591
+ } else {
592
+ this._sideEffect.setTimeout(() => {
593
+ this.$box.classList.toggle(maximizedClassName, false);
594
+ }, 0, MAXIMIZED_TIMER_ID);
595
+ }
596
+ });
597
+ });
598
+ this._sideEffect.addDisposer(this._visible$.subscribe((visible) => {
599
+ this.$box.style.display = visible ? "block" : "none";
600
+ }));
601
+ this._sideEffect.addDisposer(this._zIndex$.subscribe((zIndex) => {
602
+ this.$box.style.zIndex = String(zIndex);
603
+ }));
604
+ this.$box.dataset.teleBoxID = this.id;
605
+ const boxStyler = styler(this.$box);
606
+ const boxStyles$ = combine([
607
+ this._maximized$,
608
+ this._minimized$,
609
+ this._pxIntrinsicSize$,
610
+ this._pxIntrinsicCoord$,
611
+ this._collectorRect$,
612
+ this._rootRect$,
613
+ this._managerStageRect$
614
+ ], ([
615
+ maximized,
616
+ minimized,
617
+ pxIntrinsicSize,
618
+ pxIntrinsicCoord,
619
+ collectorRect,
620
+ rootRect,
621
+ managerStageRect
622
+ ]) => {
623
+ const styles = maximized ? {
624
+ x: -managerStageRect.x,
625
+ y: -managerStageRect.y,
626
+ width: rootRect.width,
627
+ height: rootRect.height,
628
+ scaleX: 1,
629
+ scaleY: 1
630
+ } : {
631
+ x: pxIntrinsicCoord.x,
632
+ y: pxIntrinsicCoord.y,
633
+ width: pxIntrinsicSize.width,
634
+ height: pxIntrinsicSize.height,
635
+ scaleX: 1,
636
+ scaleY: 1
637
+ };
638
+ if (minimized && collectorRect) {
639
+ const { width: boxWidth, height: boxHeight } = maximized ? this.rootRect : pxIntrinsicSize;
640
+ styles.x = collectorRect.x - boxWidth / 2 + collectorRect.width / 2 - managerStageRect.x;
641
+ styles.y = collectorRect.y - boxHeight / 2 + collectorRect.height / 2 - managerStageRect.y;
642
+ styles.scaleX = collectorRect.width / boxWidth;
643
+ styles.scaleY = collectorRect.height / boxHeight;
644
+ }
645
+ return styles;
646
+ }, { compare: shallowequal });
647
+ const boxStyles = boxStyles$.value;
648
+ this.$box.style.width = boxStyles.width + "px";
649
+ this.$box.style.height = boxStyles.height + "px";
650
+ this.$box.style.transform = `translate(${boxStyles.x - 10}px,${boxStyles.y - 10}px)`;
651
+ this._sideEffect.addDisposer(boxStyles$.subscribe((styles) => {
652
+ boxStyler.set(styles);
653
+ }));
654
+ const $boxMain = document.createElement("div");
655
+ $boxMain.className = this.wrapClassName("box-main");
656
+ this.$box.appendChild($boxMain);
657
+ const $titleBar = document.createElement("div");
658
+ $titleBar.className = this.wrapClassName("titlebar-wrap");
659
+ $titleBar.appendChild(this.titleBar.render());
660
+ this.$titleBar = $titleBar;
661
+ const $body = document.createElement("div");
662
+ $body.className = this.wrapClassName("body-wrap");
663
+ this.$body = $body;
664
+ const $styles = document.createElement("style");
665
+ this.$styles = $styles;
666
+ $body.appendChild($styles);
667
+ const $userStyles = document.createElement("style");
668
+ this.$userStyles = $userStyles;
669
+ $body.appendChild($userStyles);
670
+ const $content = document.createElement("div");
671
+ $content.className = this.wrapClassName("content") + " tele-fancy-scrollbar";
672
+ this.$content = $content;
673
+ this._sideEffect.addDisposer(combine([this._bodyStyle$, this._defaultBoxBodyStyle$], ([bodyStyle, defaultBoxBodyStyle]) => bodyStyle != null ? bodyStyle : defaultBoxBodyStyle).subscribe((style2) => $content.style.cssText = style2 || ""));
674
+ $body.appendChild($content);
675
+ const $footer = document.createElement("div");
676
+ $footer.className = this.wrapClassName("footer-wrap");
677
+ this.$footer = $footer;
678
+ $boxMain.appendChild($titleBar);
679
+ const $main = document.createElement("div");
680
+ $main.className = this.wrapClassName("main");
681
+ this.$main = $main;
682
+ $boxMain.appendChild($main);
683
+ const $quarantineOuter = document.createElement("div");
684
+ $quarantineOuter.className = this.wrapClassName("quarantine-outer");
685
+ $main.appendChild($quarantineOuter);
686
+ const $quarantine = document.createElement("div");
687
+ $quarantine.className = this.wrapClassName("quarantine");
688
+ $quarantine.appendChild($body);
689
+ $quarantine.appendChild($footer);
690
+ if (this.enableShadowDOM) {
691
+ bindBoxStates($quarantine, "bind-quarantine-state");
692
+ const $shadowStyle = document.createElement("style");
693
+ $shadowStyle.textContent = shadowStyles;
694
+ $quarantine.insertBefore($shadowStyle, $quarantine.firstChild);
695
+ const shadow = $quarantineOuter.attachShadow({ mode: "open" });
696
+ shadow.appendChild($quarantine);
697
+ } else {
698
+ $quarantineOuter.appendChild($quarantine);
699
+ }
700
+ this._renderResizeHandlers();
701
+ const updateBodyRect = () => {
702
+ const rect = $body.getBoundingClientRect();
703
+ this._bodyRect$.setValue({
704
+ x: 0,
705
+ y: 0,
706
+ width: rect.width,
707
+ height: rect.height
708
+ });
709
+ };
710
+ this._sideEffect.add(() => {
711
+ const observer = new ResizeObserver$1(() => {
712
+ if (!this.minimized) {
713
+ updateBodyRect();
714
+ }
715
+ });
716
+ observer.observe($body);
717
+ return () => observer.disconnect();
718
+ });
719
+ this._sideEffect.addDisposer(this._minimized$.reaction((minimized) => {
720
+ if (!minimized) {
721
+ this._sideEffect.setTimeout(updateBodyRect, 400, "minimized-content-rect-fix");
722
+ }
723
+ }));
724
+ return this.$box;
725
+ }
726
+ _renderStage() {
727
+ const $stage = document.createElement("div");
728
+ $stage.className = this.wrapClassName("box-stage");
729
+ const updateStageRect = (stageRect) => {
730
+ $stage.style.top = stageRect.y + "px";
731
+ $stage.style.left = stageRect.x + "px";
732
+ $stage.style.width = stageRect.width + "px";
733
+ $stage.style.height = stageRect.height + "px";
734
+ };
735
+ this._sideEffect.addDisposer([
736
+ combine([this._stageStyle$, this._defaultBoxStageStyle$], ([stageStyle, defaultBoxStageStyle]) => stageStyle != null ? stageStyle : defaultBoxStageStyle).subscribe((styles) => {
737
+ $stage.style.cssText = styles || "";
738
+ updateStageRect(this._stageRect$.value);
739
+ }),
740
+ this._stageRect$.subscribe(updateStageRect)
741
+ ], "box-stage-styles");
742
+ return $stage;
743
+ }
744
+ _renderResizeHandlers() {
745
+ const $resizeHandles = document.createElement("div");
746
+ $resizeHandles.className = this.wrapClassName("resize-handles");
747
+ Object.values(TELE_BOX_RESIZE_HANDLE).forEach((handleType) => {
748
+ const $handle = document.createElement("div");
749
+ $handle.className = this.wrapClassName(handleType) + " " + this.wrapClassName("resize-handle");
750
+ $handle.dataset.teleBoxHandle = handleType;
751
+ $resizeHandles.appendChild($handle);
752
+ });
753
+ this.$box.appendChild($resizeHandles);
754
+ const TRACKING_DISPOSER_ID = "handle-tracking-listener";
755
+ const transformingClassName = this.wrapClassName("transforming");
756
+ let $trackMask;
757
+ let trackStartX = 0;
758
+ let trackStartY = 0;
759
+ let trackStartWidth = 0;
760
+ let trackStartHeight = 0;
761
+ let trackStartPageX = 0;
762
+ let trackStartPageY = 0;
763
+ let trackingHandle;
764
+ const handleTracking = (ev) => {
765
+ if (!ev.isPrimary || this.state !== TELE_BOX_STATE.Normal) {
766
+ return;
767
+ }
768
+ preventEvent(ev);
769
+ let { pageX, pageY } = ev;
770
+ if (pageY < 0) {
771
+ pageY = 0;
772
+ }
773
+ const offsetX = pageX - trackStartPageX;
774
+ const offsetY = pageY - trackStartPageY;
775
+ let { x: newX, y: newY } = this.pxIntrinsicCoord;
776
+ let { width: newWidth, height: newHeight } = this.pxIntrinsicSize;
777
+ switch (trackingHandle) {
778
+ case TELE_BOX_RESIZE_HANDLE.North: {
779
+ newY = trackStartY + offsetY;
780
+ newHeight = trackStartHeight - offsetY;
781
+ break;
782
+ }
783
+ case TELE_BOX_RESIZE_HANDLE.South: {
784
+ newHeight = trackStartHeight + offsetY;
785
+ break;
786
+ }
787
+ case TELE_BOX_RESIZE_HANDLE.West: {
788
+ newX = trackStartX + offsetX;
789
+ newWidth = trackStartWidth - offsetX;
790
+ break;
791
+ }
792
+ case TELE_BOX_RESIZE_HANDLE.East: {
793
+ newWidth = trackStartWidth + offsetX;
794
+ break;
795
+ }
796
+ case TELE_BOX_RESIZE_HANDLE.NorthWest: {
797
+ newX = trackStartX + offsetX;
798
+ newY = trackStartY + offsetY;
799
+ newWidth = trackStartWidth - offsetX;
800
+ newHeight = trackStartHeight - offsetY;
801
+ break;
802
+ }
803
+ case TELE_BOX_RESIZE_HANDLE.NorthEast: {
804
+ newY = trackStartY + offsetY;
805
+ newWidth = trackStartWidth + offsetX;
806
+ newHeight = trackStartHeight - offsetY;
807
+ break;
808
+ }
809
+ case TELE_BOX_RESIZE_HANDLE.SouthEast: {
810
+ newWidth = trackStartWidth + offsetX;
811
+ newHeight = trackStartHeight + offsetY;
812
+ break;
813
+ }
814
+ case TELE_BOX_RESIZE_HANDLE.SouthWest: {
815
+ newX = trackStartX + offsetX;
816
+ newWidth = trackStartWidth - offsetX;
817
+ newHeight = trackStartHeight + offsetY;
818
+ break;
819
+ }
820
+ default: {
821
+ this.move(trackStartX + offsetX, trackStartY + offsetY);
822
+ return;
823
+ }
824
+ }
825
+ this.transform(newX, newY, newWidth, newHeight);
826
+ };
827
+ const handleTrackEnd = (ev) => {
828
+ if (!ev.isPrimary) {
829
+ return;
830
+ }
831
+ trackingHandle = void 0;
832
+ if (!$trackMask) {
833
+ return;
834
+ }
835
+ preventEvent(ev);
836
+ this.$box.classList.toggle(transformingClassName, false);
837
+ this._sideEffect.flush(TRACKING_DISPOSER_ID);
838
+ $trackMask.remove();
839
+ };
840
+ const handleTrackStart = (ev) => {
841
+ var _a;
842
+ if (!ev.isPrimary || this.readonly) {
843
+ return;
844
+ }
845
+ if (ev.button != null && ev.button !== 0) {
846
+ return;
847
+ }
848
+ if (!this.draggable || trackingHandle || this.state !== TELE_BOX_STATE.Normal) {
849
+ return;
850
+ }
851
+ const target = ev.target;
852
+ if ((_a = target.dataset) == null ? void 0 : _a.teleBoxHandle) {
853
+ preventEvent(ev);
854
+ ({ x: trackStartX, y: trackStartY } = this.pxIntrinsicCoord);
855
+ ({ width: trackStartWidth, height: trackStartHeight } = this.pxIntrinsicSize);
856
+ ({ pageX: trackStartPageX, pageY: trackStartPageY } = ev);
857
+ trackingHandle = target.dataset.teleBoxHandle;
858
+ if (!$trackMask) {
859
+ $trackMask = document.createElement("div");
860
+ }
861
+ const cursor = trackingHandle ? this.wrapClassName(`cursor-${trackingHandle}`) : "";
862
+ $trackMask.className = this.wrapClassName(`track-mask${cursor ? ` ${cursor}` : ""}`);
863
+ this.$box.appendChild($trackMask);
864
+ this.$box.classList.add(transformingClassName);
865
+ this._sideEffect.add(() => {
866
+ window.addEventListener("pointermove", handleTracking, {
867
+ passive: false
868
+ });
869
+ window.addEventListener("pointerup", handleTrackEnd, {
870
+ passive: false
871
+ });
872
+ window.addEventListener("pointercancel", handleTrackEnd, {
873
+ passive: false
874
+ });
875
+ return () => {
876
+ window.removeEventListener("pointermove", handleTracking);
877
+ window.removeEventListener("pointerup", handleTrackEnd);
878
+ window.removeEventListener("pointercancel", handleTrackEnd);
879
+ };
880
+ }, TRACKING_DISPOSER_ID);
881
+ }
882
+ };
883
+ this._handleTrackStart = handleTrackStart;
884
+ this._sideEffect.addEventListener($resizeHandles, "pointerdown", handleTrackStart, {}, "box-resizeHandles-pointerdown");
885
+ }
886
+ async destroy() {
887
+ this.$box.remove();
888
+ this._sideEffect.flushAll();
889
+ this._sideEffect.flushAll();
890
+ await this.events.emit(TELE_BOX_EVENT.Destroyed);
891
+ this.events.clearListeners();
892
+ this._delegateEvents.clearListeners();
893
+ }
894
+ wrapClassName(className) {
895
+ return `${this.namespace}-${className}`;
896
+ }
897
+ }
898
+ var style$2 = /* @__PURE__ */ (() => ".telebox-manager-container {\n position: relative;\n overflow: hidden;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n --tele-managerContainerBackground: #f9f9f9;\n --tele-managerStageBackground: #fff;\n --tele-managerStageShadow: 0px 0px 16px rgba(0, 0, 0, 0.08);\n --tele-boxContainerBackground: #f9f9f9;\n --tele-boxStageBackground: #fff;\n --tele-boxStageShadow: 0px 0px 16px rgba(0, 0, 0, 0.08);\n --tele-boxColor: #191919;\n --tele-boxBorder: 1px solid #e3e3ec;\n --tele-boxShadow: 0px 4px 10px 0px rgba(47, 65, 146, 0.15);\n --tele-boxFooterColor: #191919;\n --tele-boxFooterBackground: #fff;\n --tele-titlebarColor: #191919;\n --tele-titlebarBackground: #fff;\n --tele-titlebarBorderBottom: 1px solid #eeeef7;\n --tele-titlebarTabColor: #7b88a0;\n --tele-titlebarTabFocusColor: #357bf6;\n --tele-titlebarTabBackground: transparent;\n --tele-titlebarTabDividerColor: #e5e5f0;\n --tele-collectorBackground: #fff;\n --tele-collectorShadow: 0px 2px 6px 0px rgba(47, 65, 146, 0.15);\n background: #f9f9f9;\n background: var(--tele-managerContainerBackground, #f9f9f9);\n}\n.telebox-manager-container.telebox-is-maximized > .telebox-manager-stage, .telebox-manager-container.telebox-is-minimized > .telebox-manager-stage {\n overflow: visible;\n}\n.telebox-manager-container.telebox-is-fullscreen .telebox-titlebar-icon-maximize,\n.telebox-manager-container.telebox-is-fullscreen .telebox-titlebar-icon-minimize {\n display: none !important;\n}\n.telebox-manager-container.telebox-hide-fullscreen-titlebar .telebox-titlebar {\n display: none !important;\n}\n.telebox-manager-stage {\n position: relative;\n overflow: hidden;\n background: #fff;\n background: var(--tele-managerStageBackground, #fff);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);\n box-shadow: var(--tele-managerStageShadow, 0px 0px 16px rgba(0, 0, 0, 0.08));\n}\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n.telebox-color-scheme-dark.telebox-manager-container {\n --tele-managerContainerBackground: #25282e;\n --tele-managerStageBackground: #272a30;\n --tele-managerStageShadow: 0px 0px 16px rgba(0, 0, 0, 0.24);\n --tele-boxContainerBackground: #25282e;\n --tele-boxStageBackground: #272a30;\n --tele-boxStageShadow: 0px 0px 16px rgba(0, 0, 0, 0.24);\n --tele-boxColor: #e9e9e9;\n --tele-boxBorder: 1px solid #383b42;\n --tele-boxShadow: 0px 4px 10px 0px rgba(56, 59, 66, 0.15);\n --tele-boxFooterColor: #e9e9e9;\n --tele-boxFooterBackground: #383b42;\n --tele-titlebarColor: #e9e9e9;\n --tele-titlebarBackground: #383b42;\n --tele-titlebarBorderBottom: none;\n --tele-titlebarTabColor: #e9e9e9;\n --tele-titlebarTabFocusColor: #357bf6;\n --tele-titlebarTabBackground: transparent;\n --tele-titlebarTabDividerColor: #7b88a0;\n --tele-collectorBackground: #383b42;\n --tele-collectorShadow: 0px 2px 6px 0px rgba(47, 65, 146, 0.15);\n background: #25282e;\n background: var(--tele-managerContainerBackground, #25282e);\n}\n.telebox-color-scheme-dark.telebox-manager-container > .telebox-manager-stage {\n background: #272a30;\n background: var(--tele-managerStageBackground, #272a30);\n box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.24);\n box-shadow: var(--tele-managerStageShadow, 0px 0px 16px rgba(0, 0, 0, 0.24));\n}")();
899
+ var style$1 = /* @__PURE__ */ (() => ".telebox-collector {\n user-select: none;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n visibility: hidden;\n display: block;\n position: absolute;\n z-index: 5120;\n width: 40px;\n height: 40px;\n margin: 0;\n padding: 0;\n border: none;\n outline: none;\n font-size: 0;\n border-radius: 50%;\n cursor: pointer;\n user-select: none;\n pointer-events: none;\n background-repeat: no-repeat;\n background-size: 18px 16px;\n background-position: center;\n -webkit-tap-highlight-color: transparent;\n background-color: #fff;\n background-color: var(--tele-collectorBackground, #fff);\n box-shadow: 0px 2px 6px 0px rgba(47, 65, 146, 0.15);\n box-shadow: var(--tele-collectorShadow, 0px 2px 6px 0px rgba(47, 65, 146, 0.15));\n}\n\n.telebox-collector-visible {\n visibility: visible;\n pointer-events: initial;\n}\n\n.telebox-collector-readonly {\n cursor: not-allowed;\n}\n\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n\n.telebox-color-scheme-dark.telebox-collector {\n background-color: #383b42;\n background-color: var(--tele-collectorBackground, #383b42);\n box-shadow: 0px 2px 6px 0px rgba(47, 65, 146, 0.15);\n box-shadow: var(--tele-collectorShadow, 0px 2px 6px 0px rgba(47, 65, 146, 0.15));\n}")();
900
+ var collectorSVG = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxOCAxNiI+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxwYXRoIHN0cm9rZT0iIzdCODhBMCIgc3Ryb2tlLXdpZHRoPSIxLjQiIGQ9Ik0uNyAxLjJoMTYuNnYxMy42SC43eiIgLz4KICAgICAgICA8cGF0aCBmaWxsPSIjN0I4OEEwIiBkPSJNNCA1LjVoNnYxLjRINHpNNCA5LjVoMTB2MS40SDR6IiAvPgogICAgPC9nPgo8L3N2Zz4K";
901
+ class TeleBoxCollector {
902
+ constructor({
903
+ minimized$,
904
+ readonly$,
905
+ darkMode$,
906
+ namespace = "telebox",
907
+ styles = {},
908
+ root,
909
+ onClick
910
+ }) {
911
+ this._sideEffect = new SideEffectManager();
912
+ this.namespace = namespace;
913
+ const valManager = new ValManager();
914
+ this._sideEffect.addDisposer(() => valManager.destroy());
915
+ const rect$ = new Val(void 0);
916
+ const visible$ = derive(minimized$);
917
+ const styles$ = new Val(styles);
918
+ const el$ = new Val(document.createElement("button"));
919
+ const valConfig = {
920
+ styles: styles$,
921
+ $collector: el$
922
+ };
923
+ withValueEnhancer(this, valConfig, valManager);
924
+ const myReadonlyValConfig = {
925
+ rect: rect$,
926
+ visible: visible$
927
+ };
928
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
929
+ el$.value.className = this.wrapClassName("collector");
930
+ el$.value.style.backgroundImage = `url('${collectorSVG}')`;
931
+ this._sideEffect.addDisposer(el$.subscribe(($collector) => {
932
+ this._sideEffect.add(() => {
933
+ root.appendChild($collector);
934
+ return () => $collector.remove();
935
+ }, "telebox-collector-mount");
936
+ this._sideEffect.addEventListener($collector, "click", () => {
937
+ if (!readonly$.value) {
938
+ onClick == null ? void 0 : onClick();
939
+ }
940
+ }, {}, "telebox-collector-click");
941
+ this._sideEffect.addDisposer([
942
+ visible$.subscribe((visible) => {
943
+ $collector.classList.toggle(this.wrapClassName("collector-visible"), visible);
944
+ }),
945
+ readonly$.subscribe((readonly) => {
946
+ $collector.classList.toggle(this.wrapClassName("collector-readonly"), readonly);
947
+ }),
948
+ darkMode$.subscribe((darkMode) => {
949
+ $collector.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
950
+ $collector.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
951
+ }),
952
+ styles$.subscribe((styles2) => {
953
+ Object.keys(styles2).forEach((key) => {
954
+ const value = styles2[key];
955
+ if (value != null) {
956
+ $collector.style[key] = value;
957
+ }
958
+ });
959
+ }),
960
+ minimized$.subscribe((minimized) => {
961
+ if (minimized) {
962
+ const { x, y, width, height } = $collector.getBoundingClientRect();
963
+ const rootRect = root.getBoundingClientRect();
964
+ rect$.setValue({
965
+ x: x - rootRect.x,
966
+ y: y - rootRect.y,
967
+ width,
968
+ height
969
+ });
970
+ }
971
+ })
972
+ ], "telebox-collector-el");
973
+ }));
974
+ }
975
+ destroy() {
976
+ this._sideEffect.flushAll();
977
+ }
978
+ wrapClassName(className) {
979
+ return `${this.namespace}-${className}`;
980
+ }
981
+ }
982
+ var TELE_BOX_MANAGER_EVENT = /* @__PURE__ */ ((TELE_BOX_MANAGER_EVENT2) => {
983
+ TELE_BOX_MANAGER_EVENT2["Focused"] = "focused";
984
+ TELE_BOX_MANAGER_EVENT2["Blurred"] = "blurred";
985
+ TELE_BOX_MANAGER_EVENT2["Created"] = "created";
986
+ TELE_BOX_MANAGER_EVENT2["Removed"] = "removed";
987
+ TELE_BOX_MANAGER_EVENT2["State"] = "state";
988
+ TELE_BOX_MANAGER_EVENT2["Maximized"] = "maximized";
989
+ TELE_BOX_MANAGER_EVENT2["Minimized"] = "minimized";
990
+ TELE_BOX_MANAGER_EVENT2["IntrinsicMove"] = "intrinsic_move";
991
+ TELE_BOX_MANAGER_EVENT2["IntrinsicResize"] = "intrinsic_resize";
992
+ TELE_BOX_MANAGER_EVENT2["ZIndex"] = "z_index";
993
+ TELE_BOX_MANAGER_EVENT2["PrefersColorScheme"] = "prefers_color_scheme";
994
+ TELE_BOX_MANAGER_EVENT2["DarkMode"] = "dark_mode";
995
+ return TELE_BOX_MANAGER_EVENT2;
996
+ })(TELE_BOX_MANAGER_EVENT || {});
997
+ var style = /* @__PURE__ */ (() => ".telebox-max-titlebar {\n user-select: none;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n display: none;\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n z-index: 5100;\n border-top-left-radius: 6px;\n border-top-right-radius: 6px;\n}\n.telebox-max-titlebar .telebox-title {\n display: none;\n}\n.telebox-max-titlebar.telebox-max-titlebar-single-title .telebox-titles {\n display: none;\n}\n.telebox-max-titlebar.telebox-max-titlebar-single-title .telebox-title {\n display: block;\n}\n.telebox-max-titlebar-maximized {\n display: flex;\n}\n.telebox-titles {\n height: 100%;\n margin: 0;\n overflow-y: hidden;\n overflow-x: scroll;\n overflow-x: overlay;\n -webkit-overflow-scrolling: touch;\n -ms-overflow-style: -ms-autohiding-scrollbar;\n scrollbar-width: auto;\n}\n.telebox-titles::-webkit-scrollbar {\n height: 4px;\n width: 4px;\n}\n.telebox-titles::-webkit-scrollbar-track {\n background-color: transparent;\n}\n.telebox-titles::-webkit-scrollbar-thumb {\n background-color: rgba(238, 238, 247, 0.8);\n background-color: transparent;\n border-radius: 2px;\n transition: background-color 0.4s;\n}\n.telebox-titles:hover::-webkit-scrollbar-thumb {\n background-color: rgba(238, 238, 247, 0.8);\n}\n.telebox-titles::-webkit-scrollbar-thumb:hover {\n background-color: #eeeef7;\n}\n.telebox-titles::-webkit-scrollbar-thumb:active {\n background-color: #eeeef7;\n}\n.telebox-titles::-webkit-scrollbar-thumb:vertical {\n min-height: 50px;\n}\n.telebox-titles::-webkit-scrollbar-thumb:horizontal {\n min-width: 50px;\n}\n.telebox-titles-content {\n height: 100%;\n display: flex;\n flex-wrap: nowrap;\n align-items: center;\n padding: 0;\n}\n.telebox-titles-tab {\n height: 100%;\n overflow: hidden;\n max-width: 182px;\n min-width: 150px;\n padding: 0 26px 0 16px;\n outline: none;\n font-size: 13px;\n font-family: PingFangSC-Regular, PingFang SC;\n font-weight: 400;\n text-overflow: ellipsis;\n white-space: nowrap;\n word-break: keep-all;\n border: none;\n border-right-width: 1px;\n border-right-style: solid;\n cursor: pointer;\n user-select: none;\n color: #7b88a0;\n color: var(--tele-titlebarTabColor, #7b88a0);\n background-color: transparent;\n background-color: var(--tele-titlebarTabBackground, transparent);\n border-right-color: #e5e5f0;\n border-right-color: var(--tele-titlebarTabDividerColor, #e5e5f0);\n}\n.telebox-titles-tab-focus {\n color: #357bf6;\n color: var(--tele-titlebarTabFocusColor, #357bf6);\n}\n.telebox-readonly .telebox-titles-tab {\n cursor: not-allowed;\n}\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n.telebox-color-scheme-dark .telebox-titles-tab {\n color: #e9e9e9;\n color: var(--tele-titlebarTabColor, #e9e9e9);\n background-color: transparent;\n background-color: var(--tele-titlebarTabBackground, transparent);\n border-right-color: #7b88a0;\n border-right-color: var(--tele-titlebarTabDividerColor, #7b88a0);\n}\n.telebox-color-scheme-dark .telebox-titles-tab-focus {\n color: #357bf6;\n color: var(--tele-titlebarTabFocusColor, #357bf6);\n}")();
998
+ class MaxTitleBar extends DefaultTitleBar {
999
+ constructor(config) {
1000
+ super(config);
1001
+ this.boxes$ = config.boxes$;
1002
+ this.rootRect$ = config.rootRect$;
1003
+ this.darkMode$ = config.darkMode$;
1004
+ config.root.appendChild(this.render());
1005
+ }
1006
+ focusBox(box) {
1007
+ var _a;
1008
+ if (this.focusedBox && this.focusedBox === box) {
1009
+ return;
1010
+ }
1011
+ if (this.$titles && this.state$.value === TELE_BOX_STATE.Maximized) {
1012
+ const { children } = this.$titles.firstElementChild;
1013
+ for (let i = children.length - 1; i >= 0; i -= 1) {
1014
+ const $tab = children[i];
1015
+ const id = (_a = $tab.dataset) == null ? void 0 : _a.teleBoxID;
1016
+ if (id) {
1017
+ if (box && id === box.id) {
1018
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), true);
1019
+ } else if (this.focusedBox && id === this.focusedBox.id) {
1020
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), false);
1021
+ }
1022
+ }
1023
+ }
1024
+ }
1025
+ this.focusedBox = box;
1026
+ }
1027
+ render() {
1028
+ if (this.$titleBar) {
1029
+ return this.$titleBar;
1030
+ }
1031
+ const $titleBar = super.render();
1032
+ $titleBar.classList.add(this.wrapClassName("max-titlebar"));
1033
+ this.sideEffect.addDisposer([
1034
+ this.state$.subscribe((state) => {
1035
+ $titleBar.classList.toggle(this.wrapClassName("max-titlebar-maximized"), state === TELE_BOX_STATE.Maximized);
1036
+ }),
1037
+ this.readonly$.subscribe((readonly) => {
1038
+ $titleBar.classList.toggle(this.wrapClassName("readonly"), readonly);
1039
+ }),
1040
+ combine([this.state$, this.boxes$]).subscribe(([state, titles]) => {
1041
+ if (state === TELE_BOX_STATE.Maximized) {
1042
+ $titleBar.classList.toggle(this.wrapClassName("max-titlebar-single-title"), titles.length === 1);
1043
+ if (titles.length !== 1) {
1044
+ $titleBar.replaceChild(this.renderTitles(), $titleBar.firstElementChild);
1045
+ }
1046
+ }
1047
+ })
1048
+ ], "max-render");
1049
+ const $titlesArea = document.createElement("div");
1050
+ $titlesArea.classList.add(this.wrapClassName("titles-area"));
1051
+ $titleBar.insertBefore($titlesArea, $titleBar.firstElementChild);
1052
+ return $titleBar;
1053
+ }
1054
+ destroy() {
1055
+ super.destroy();
1056
+ this.$titles = void 0;
1057
+ this.focusedBox = void 0;
1058
+ }
1059
+ renderTitles() {
1060
+ this.$titles = document.createElement("div");
1061
+ this.$titles.className = this.wrapClassName("titles");
1062
+ this.sideEffect.addEventListener(this.$titles, "wheel", (ev) => {
1063
+ ev.currentTarget.scrollBy({
1064
+ left: ev.deltaY > 0 ? 250 : -250,
1065
+ behavior: "smooth"
1066
+ });
1067
+ }, { passive: false }, "max-render-wheel-titles");
1068
+ const $content = document.createElement("div");
1069
+ $content.className = this.wrapClassName("titles-content");
1070
+ this.$titles.appendChild($content);
1071
+ const disposers = this.boxes$.value.map((box) => {
1072
+ const $tab = document.createElement("button");
1073
+ $tab.className = this.wrapClassName("titles-tab");
1074
+ $tab.textContent = box.title;
1075
+ $tab.dataset.teleBoxID = box.id;
1076
+ $tab.dataset.teleTitleBarNoDblClick = "true";
1077
+ if (this.focusedBox && box.id === this.focusedBox.id) {
1078
+ $tab.classList.add(this.wrapClassName("titles-tab-focus"));
1079
+ }
1080
+ $content.appendChild($tab);
1081
+ return box._title$.reaction((title) => $tab.textContent = title);
1082
+ });
1083
+ this.sideEffect.addDisposer(() => disposers.forEach((disposer) => disposer()), "max-render-tab-titles");
1084
+ return this.$titles;
1085
+ }
1086
+ }
1087
+ const ResizeObserver = window.ResizeObserver || ResizeObserver$2;
1088
+ class TeleBoxManager {
1089
+ constructor({
1090
+ root = null,
1091
+ fullscreen = false,
1092
+ prefersColorScheme = TELE_BOX_COLOR_SCHEME.Light,
1093
+ minimized = false,
1094
+ maximized = false,
1095
+ fence = true,
1096
+ collector,
1097
+ namespace = "telebox",
1098
+ readonly = false,
1099
+ stageRatio = -1,
1100
+ containerStyle = "",
1101
+ stageStyle = "",
1102
+ defaultBoxBodyStyle = null,
1103
+ defaultBoxStageStyle = null,
1104
+ theme = {}
1105
+ } = {}) {
1106
+ this.events = new Emittery();
1107
+ this._sideEffect = new SideEffectManager();
1108
+ this.namespace = namespace;
1109
+ const valManager = new ValManager();
1110
+ this._sideEffect.addDisposer(() => valManager.destroy());
1111
+ const root$ = new Val(root);
1112
+ const readonly$ = new Val(readonly);
1113
+ const fence$ = new Val(fence);
1114
+ const containerStyle$ = new Val(containerStyle);
1115
+ const stageStyle$ = new Val(stageStyle);
1116
+ const stageRatio$ = new Val(stageRatio);
1117
+ const defaultBoxBodyStyle$ = new Val(defaultBoxBodyStyle);
1118
+ const defaultBoxStageStyle$ = new Val(defaultBoxStageStyle);
1119
+ const fullscreen$ = new Val(fullscreen);
1120
+ const input_minimized$ = new Val(minimized);
1121
+ const input_maximized$ = new Val(maximized);
1122
+ const maximized$ = combine([input_maximized$, fullscreen$], ([maximized2, fullscreen2]) => fullscreen2 ? true : maximized2);
1123
+ const minimized$ = combine([input_minimized$, fullscreen$], ([minimized2, fullscreen2]) => fullscreen2 ? false : minimized2);
1124
+ this.setMaximized = (maximized2, skipUpdate) => input_maximized$.setValue(maximized2, skipUpdate);
1125
+ this.setMinimized = (minimized2, skipUpdate) => input_minimized$.setValue(minimized2, skipUpdate);
1126
+ const rootRect$ = new Val({
1127
+ x: 0,
1128
+ y: 0,
1129
+ width: window.innerWidth,
1130
+ height: window.innerHeight
1131
+ }, { compare: shallowequal });
1132
+ this._sideEffect.addDisposer(root$.subscribe((root2) => {
1133
+ this._sideEffect.add(() => {
1134
+ if (!root2) {
1135
+ return () => void 0;
1136
+ }
1137
+ const observer = new ResizeObserver(() => {
1138
+ const rect = root2.getBoundingClientRect();
1139
+ rootRect$.setValue({
1140
+ x: 0,
1141
+ y: 0,
1142
+ width: rect.width,
1143
+ height: rect.height
1144
+ });
1145
+ });
1146
+ observer.observe(root2);
1147
+ return () => observer.disconnect();
1148
+ }, "calc-root-rect");
1149
+ }));
1150
+ const stageRect$ = combine([rootRect$, stageRatio$], calcStageRect, {
1151
+ compare: shallowequal
1152
+ });
1153
+ this.boxes$ = new Val([]);
1154
+ this.topBox$ = new Val(void 0);
1155
+ this._sideEffect.addDisposer(this.boxes$.subscribe((boxes) => {
1156
+ if (boxes.length > 0) {
1157
+ const topBox = boxes.reduce((topBox2, box) => topBox2.zIndex > box.zIndex ? topBox2 : box);
1158
+ this.topBox$.setValue(topBox);
1159
+ } else {
1160
+ this.topBox$.setValue(void 0);
1161
+ }
1162
+ }));
1163
+ const prefersDarkMatch = window.matchMedia("(prefers-color-scheme: dark)");
1164
+ const prefersDark$ = new Val(false);
1165
+ if (prefersDarkMatch) {
1166
+ prefersDark$.setValue(prefersDarkMatch.matches);
1167
+ this._sideEffect.add(() => {
1168
+ const handler = (evt) => {
1169
+ prefersDark$.setValue(evt.matches);
1170
+ };
1171
+ prefersDarkMatch.addEventListener("change", handler);
1172
+ return () => prefersDarkMatch.removeEventListener("change", handler);
1173
+ });
1174
+ }
1175
+ const prefersColorScheme$ = new Val(prefersColorScheme);
1176
+ this._sideEffect.addDisposer(prefersColorScheme$.reaction((prefersColorScheme2, skipUpdate) => {
1177
+ if (!skipUpdate) {
1178
+ this.events.emit(TELE_BOX_MANAGER_EVENT.PrefersColorScheme, prefersColorScheme2);
1179
+ }
1180
+ }));
1181
+ const darkMode$ = combine([prefersDark$, prefersColorScheme$], ([prefersDark, prefersColorScheme2]) => prefersColorScheme2 === "auto" ? prefersDark : prefersColorScheme2 === "dark");
1182
+ const state$ = combine([minimized$, maximized$], ([minimized2, maximized2]) => minimized2 ? TELE_BOX_STATE.Minimized : maximized2 ? TELE_BOX_STATE.Maximized : TELE_BOX_STATE.Normal);
1183
+ const readonlyValConfig = {
1184
+ darkMode: darkMode$,
1185
+ state: state$,
1186
+ root: root$,
1187
+ rootRect: rootRect$,
1188
+ stageRect: stageRect$,
1189
+ minimized: minimized$,
1190
+ maximized: maximized$
1191
+ };
1192
+ withReadonlyValueEnhancer(this, readonlyValConfig, valManager);
1193
+ const valConfig = {
1194
+ fullscreen: fullscreen$,
1195
+ prefersColorScheme: prefersColorScheme$,
1196
+ readonly: readonly$,
1197
+ fence: fence$,
1198
+ stageRatio: stageRatio$,
1199
+ containerStyle: containerStyle$,
1200
+ stageStyle: stageStyle$,
1201
+ defaultBoxBodyStyle: defaultBoxBodyStyle$,
1202
+ defaultBoxStageStyle: defaultBoxStageStyle$
1203
+ };
1204
+ withValueEnhancer(this, valConfig, valManager);
1205
+ const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
1206
+ const checkFocusBox = (ev) => {
1207
+ var _a;
1208
+ if (!ev.isPrimary || readonly$.value) {
1209
+ return;
1210
+ }
1211
+ const target = ev.target;
1212
+ if (!target.tagName) {
1213
+ return;
1214
+ }
1215
+ for (let el = target; el; el = el.parentElement) {
1216
+ if (el.classList && el.classList.contains(closeBtnClassName)) {
1217
+ return;
1218
+ }
1219
+ const id = (_a = el.dataset) == null ? void 0 : _a.teleBoxID;
1220
+ if (id) {
1221
+ const box = this.getBox(id);
1222
+ if (box) {
1223
+ this.focusBox(box);
1224
+ this.makeBoxTop(box);
1225
+ return;
1226
+ }
1227
+ }
1228
+ }
1229
+ };
1230
+ this._sideEffect.addEventListener(window, "pointerdown", checkFocusBox, true);
1231
+ this.$container = document.createElement("div");
1232
+ this.$container.className = this.wrapClassName("manager-container");
1233
+ this.setTheme(theme);
1234
+ this.$stage = document.createElement("div");
1235
+ this.$stage.className = this.wrapClassName("manager-stage");
1236
+ this.$container.appendChild(this.$stage);
1237
+ this._sideEffect.addDisposer([
1238
+ darkMode$.subscribe((darkMode) => {
1239
+ this.$container.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
1240
+ this.$container.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
1241
+ }),
1242
+ fullscreen$.subscribe((fullscreen2) => {
1243
+ this.$container.classList.toggle(this.wrapClassName("is-fullscreen"), Boolean(fullscreen2));
1244
+ }),
1245
+ combine([this.boxes$, fullscreen$], ([boxes, fullscreen2]) => fullscreen2 === "no-titlebar" || fullscreen2 === true && boxes.length <= 1).subscribe((hideSingleTabTitlebar) => {
1246
+ this.$container.classList.toggle(this.wrapClassName("hide-fullscreen-titlebar"), hideSingleTabTitlebar);
1247
+ }),
1248
+ maximized$.subscribe((maximized2) => {
1249
+ this.$container.classList.toggle(this.wrapClassName("is-maximized"), maximized2);
1250
+ }),
1251
+ minimized$.subscribe((minimized2) => {
1252
+ this.$container.classList.toggle(this.wrapClassName("is-minimized"), minimized2);
1253
+ }),
1254
+ containerStyle$.subscribe((containerStyle2) => {
1255
+ this.$container.style.cssText = containerStyle2;
1256
+ }),
1257
+ stageStyle$.subscribe((stageStyle2) => {
1258
+ this.$stage.style.cssText = stageStyle2;
1259
+ this.$stage.style.width = stageRect$.value.width + "px";
1260
+ this.$stage.style.height = stageRect$.value.height + "px";
1261
+ }),
1262
+ stageRect$.subscribe((stageRect) => {
1263
+ this.$stage.style.width = stageRect.width + "px";
1264
+ this.$stage.style.height = stageRect.height + "px";
1265
+ }),
1266
+ root$.subscribe((root2) => {
1267
+ if (root2) {
1268
+ root2.appendChild(this.$container);
1269
+ } else if (this.$container.parentElement) {
1270
+ this.$container.remove();
1271
+ }
1272
+ })
1273
+ ]);
1274
+ this.collector = collector != null ? collector : new TeleBoxCollector({
1275
+ minimized$,
1276
+ readonly$,
1277
+ darkMode$,
1278
+ namespace,
1279
+ root: this.$container,
1280
+ onClick: () => input_minimized$.setValue(false)
1281
+ });
1282
+ this.titleBar = new MaxTitleBar({
1283
+ namespace: this.namespace,
1284
+ title$: derive(this.topBox$, (topBox) => (topBox == null ? void 0 : topBox.title) || ""),
1285
+ boxes$: this.boxes$,
1286
+ darkMode$,
1287
+ readonly$,
1288
+ state$,
1289
+ rootRect$,
1290
+ root: this.$container,
1291
+ onEvent: (event) => {
1292
+ switch (event.type) {
1293
+ case TELE_BOX_DELEGATE_EVENT.Maximize: {
1294
+ this.setMaximized(!maximized$.value);
1295
+ break;
1296
+ }
1297
+ case TELE_BOX_DELEGATE_EVENT.Minimize: {
1298
+ this.setMinimized(true);
1299
+ break;
1300
+ }
1301
+ case TELE_BOX_EVENT.Close: {
1302
+ this.removeTopBox();
1303
+ this.focusTopBox();
1304
+ break;
1305
+ }
1306
+ }
1307
+ }
1308
+ });
1309
+ this._sideEffect.addDisposer([
1310
+ state$.reaction((state, skipUpdate) => {
1311
+ if (!skipUpdate) {
1312
+ this.events.emit(TELE_BOX_MANAGER_EVENT.State, state);
1313
+ }
1314
+ }),
1315
+ maximized$.reaction((maximized2, skipUpdate) => {
1316
+ if (!skipUpdate) {
1317
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Maximized, maximized2);
1318
+ }
1319
+ }),
1320
+ minimized$.reaction((minimized2, skipUpdate) => {
1321
+ if (!skipUpdate) {
1322
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Minimized, minimized2);
1323
+ }
1324
+ }),
1325
+ darkMode$.reaction((darkMode, skipUpdate) => {
1326
+ if (!skipUpdate) {
1327
+ this.events.emit(TELE_BOX_MANAGER_EVENT.DarkMode, darkMode);
1328
+ }
1329
+ })
1330
+ ]);
1331
+ }
1332
+ get boxes() {
1333
+ return this.boxes$.value;
1334
+ }
1335
+ get topBox() {
1336
+ return this.topBox$.value;
1337
+ }
1338
+ setState(state, skipUpdate = false) {
1339
+ switch (state) {
1340
+ case TELE_BOX_STATE.Maximized: {
1341
+ this.setMinimized(false, skipUpdate);
1342
+ this.setMaximized(true, skipUpdate);
1343
+ break;
1344
+ }
1345
+ case TELE_BOX_STATE.Minimized: {
1346
+ this.setMinimized(true, skipUpdate);
1347
+ this.setMaximized(false, skipUpdate);
1348
+ break;
1349
+ }
1350
+ default: {
1351
+ this.setMinimized(false, skipUpdate);
1352
+ this.setMaximized(false, skipUpdate);
1353
+ break;
1354
+ }
1355
+ }
1356
+ return this;
1357
+ }
1358
+ create(config = {}, smartPosition = true) {
1359
+ const box = new TeleBox({
1360
+ zIndex: this.topBox ? this.topBox.zIndex + 1 : 100,
1361
+ ...config,
1362
+ ...smartPosition ? this.smartPosition(config) : {},
1363
+ namespace: this.namespace,
1364
+ root: this.$stage,
1365
+ darkMode$: this._darkMode$,
1366
+ fence$: this._fence$,
1367
+ rootRect$: this._rootRect$,
1368
+ managerStageRect$: this._stageRect$,
1369
+ managerStageRatio$: this._stageRatio$,
1370
+ managerMaximized$: this._maximized$,
1371
+ managerMinimized$: this._minimized$,
1372
+ managerReadonly$: this._readonly$,
1373
+ collectorRect$: this.collector._rect$,
1374
+ defaultBoxBodyStyle$: this._defaultBoxBodyStyle$,
1375
+ defaultBoxStageStyle$: this._defaultBoxStageStyle$
1376
+ });
1377
+ if (box.focus) {
1378
+ this.focusBox(box);
1379
+ if (smartPosition) {
1380
+ this.makeBoxTop(box);
1381
+ }
1382
+ }
1383
+ this.boxes$.setValue([...this.boxes, box]);
1384
+ this._sideEffect.addDisposer([
1385
+ box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
1386
+ this.setMaximized(!this.maximized);
1387
+ }),
1388
+ box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Minimize, () => {
1389
+ this.setMinimized(true);
1390
+ }),
1391
+ box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
1392
+ this.remove(box);
1393
+ this.focusTopBox();
1394
+ }),
1395
+ box._intrinsicCoord$.reaction((_, skipUpdate) => {
1396
+ if (!skipUpdate) {
1397
+ this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicMove, box);
1398
+ }
1399
+ }),
1400
+ box._intrinsicSize$.reaction((_, skipUpdate) => {
1401
+ if (!skipUpdate) {
1402
+ this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicResize, box);
1403
+ }
1404
+ }),
1405
+ box._zIndex$.reaction((_, skipUpdate) => {
1406
+ if (this.boxes.length > 0) {
1407
+ const topBox = this.boxes.reduce((topBox2, box2) => topBox2.zIndex > box2.zIndex ? topBox2 : box2);
1408
+ this.topBox$.setValue(topBox);
1409
+ }
1410
+ if (!skipUpdate) {
1411
+ this.events.emit(TELE_BOX_MANAGER_EVENT.ZIndex, box);
1412
+ }
1413
+ })
1414
+ ]);
1415
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Created, box);
1416
+ return box;
1417
+ }
1418
+ query(config) {
1419
+ return config ? this.boxes.filter(this.teleBoxMatcher(config)) : [...this.boxes];
1420
+ }
1421
+ queryOne(config) {
1422
+ return config ? this.boxes.find(this.teleBoxMatcher(config)) : this.boxes[0];
1423
+ }
1424
+ update(boxID, config, skipUpdate = false) {
1425
+ const box = this.boxes.find((box2) => box2.id === boxID);
1426
+ if (box) {
1427
+ return this.updateBox(box, config, skipUpdate);
1428
+ }
1429
+ }
1430
+ updateAll(config, skipUpdate = false) {
1431
+ this.boxes.forEach((box) => {
1432
+ this.updateBox(box, config, skipUpdate);
1433
+ });
1434
+ }
1435
+ remove(boxOrID, skipUpdate = false) {
1436
+ const index = this.getBoxIndex(boxOrID);
1437
+ if (index >= 0) {
1438
+ const boxes = this.boxes.slice();
1439
+ const deletedBoxes = boxes.splice(index, 1);
1440
+ this.boxes$.setValue(boxes);
1441
+ deletedBoxes.forEach((box) => box.destroy());
1442
+ if (!skipUpdate) {
1443
+ if (this.boxes.length <= 0) {
1444
+ this.setMaximized(false);
1445
+ this.setMinimized(false);
1446
+ }
1447
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
1448
+ }
1449
+ return deletedBoxes[0];
1450
+ }
1451
+ return;
1452
+ }
1453
+ removeTopBox() {
1454
+ if (this.topBox) {
1455
+ return this.remove(this.topBox);
1456
+ }
1457
+ return;
1458
+ }
1459
+ removeAll(skipUpdate = false) {
1460
+ const deletedBoxes = this.boxes$.value;
1461
+ this.boxes$.setValue([]);
1462
+ deletedBoxes.forEach((box) => box.destroy());
1463
+ if (!skipUpdate) {
1464
+ if (this.boxes.length <= 0) {
1465
+ this.setMaximized(false);
1466
+ this.setMinimized(false);
1467
+ }
1468
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
1469
+ }
1470
+ return deletedBoxes;
1471
+ }
1472
+ setTheme(theme) {
1473
+ Object.keys(theme).forEach((key) => {
1474
+ var _a;
1475
+ this.$container.style.setProperty(`--tele-${key}`, (_a = theme[key]) != null ? _a : null);
1476
+ });
1477
+ }
1478
+ mount(root) {
1479
+ this._root$.setValue(root);
1480
+ }
1481
+ unmount() {
1482
+ this._root$.setValue(null);
1483
+ }
1484
+ destroy(skipUpdate = false) {
1485
+ this.events.clearListeners();
1486
+ this._sideEffect.flushAll();
1487
+ this.removeAll(skipUpdate);
1488
+ this.collector.destroy();
1489
+ this.titleBar.destroy();
1490
+ }
1491
+ wrapClassName(className) {
1492
+ return `${this.namespace}-${className}`;
1493
+ }
1494
+ focusBox(boxOrID, skipUpdate = false) {
1495
+ const targetBox = this.getBox(boxOrID);
1496
+ if (targetBox) {
1497
+ this.boxes.forEach((box) => {
1498
+ if (targetBox === box) {
1499
+ let focusChanged = false;
1500
+ if (!targetBox.focus) {
1501
+ focusChanged = true;
1502
+ targetBox._focus$.setValue(true, skipUpdate);
1503
+ }
1504
+ if (focusChanged && !skipUpdate) {
1505
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Focused, targetBox);
1506
+ }
1507
+ } else if (box.focus) {
1508
+ this.blurBox(box, skipUpdate);
1509
+ }
1510
+ });
1511
+ this.titleBar.focusBox(targetBox);
1512
+ }
1513
+ }
1514
+ focusTopBox() {
1515
+ if (this.topBox && !this.topBox.focus) {
1516
+ return this.focusBox(this.topBox);
1517
+ }
1518
+ }
1519
+ blurBox(boxOrID, skipUpdate = false) {
1520
+ const targetBox = this.getBox(boxOrID);
1521
+ if (targetBox) {
1522
+ if (targetBox.focus) {
1523
+ targetBox._focus$.setValue(false, skipUpdate);
1524
+ if (!skipUpdate) {
1525
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, targetBox);
1526
+ }
1527
+ }
1528
+ if (this.titleBar.focusedBox === targetBox) {
1529
+ this.titleBar.focusBox();
1530
+ }
1531
+ }
1532
+ }
1533
+ blurAll(skipUpdate = false) {
1534
+ this.boxes.forEach((box) => {
1535
+ if (box.focus) {
1536
+ box._focus$.setValue(false, skipUpdate);
1537
+ if (!skipUpdate) {
1538
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, box);
1539
+ }
1540
+ }
1541
+ });
1542
+ if (this.titleBar.focusedBox) {
1543
+ this.titleBar.focusBox();
1544
+ }
1545
+ }
1546
+ teleBoxMatcher(config) {
1547
+ const keys = Object.keys(config);
1548
+ return (box) => keys.every((key) => config[key] === box[key]);
1549
+ }
1550
+ updateBox(box, config, skipUpdate = false) {
1551
+ var _a, _b, _c, _d, _e, _f;
1552
+ if (config.x != null || config.y != null) {
1553
+ box._intrinsicCoord$.setValue({
1554
+ x: (_a = config.x) != null ? _a : box.intrinsicX,
1555
+ y: (_b = config.y) != null ? _b : box.intrinsicY
1556
+ }, skipUpdate);
1557
+ }
1558
+ if (config.width != null || config.height != null) {
1559
+ box._intrinsicSize$.setValue({
1560
+ width: (_c = config.width) != null ? _c : box.intrinsicWidth,
1561
+ height: (_d = config.height) != null ? _d : box.intrinsicHeight
1562
+ }, skipUpdate);
1563
+ }
1564
+ if (config.title != null) {
1565
+ box._title$.setValue(config.title);
1566
+ }
1567
+ if (config.visible != null) {
1568
+ box._visible$.setValue(config.visible, skipUpdate);
1569
+ }
1570
+ if (config.resizable != null) {
1571
+ box._resizable$.setValue(config.resizable, skipUpdate);
1572
+ }
1573
+ if (config.draggable != null) {
1574
+ box._draggable$.setValue(config.draggable, skipUpdate);
1575
+ }
1576
+ if (config.boxRatio != null) {
1577
+ box._boxRatio$.setValue(config.boxRatio, skipUpdate);
1578
+ }
1579
+ if (config.zIndex != null) {
1580
+ box._zIndex$.setValue(config.zIndex, skipUpdate);
1581
+ }
1582
+ if (config.stageRatio !== void 0) {
1583
+ box.setStageRatio(config.stageRatio, skipUpdate);
1584
+ }
1585
+ if (config.content != null) {
1586
+ box.mountContent(config.content);
1587
+ }
1588
+ if (config.footer != null) {
1589
+ box.mountFooter(config.footer);
1590
+ }
1591
+ if (config.minHeight != null || config.minWidth != null) {
1592
+ box._minSize$.setValue({
1593
+ width: (_e = config.minWidth) != null ? _e : box.minWidth,
1594
+ height: (_f = config.minHeight) != null ? _f : box.minHeight
1595
+ }, skipUpdate);
1596
+ }
1597
+ }
1598
+ smartPosition(rect) {
1599
+ let { x, y } = rect;
1600
+ const { width = 0.5, height = 0.5 } = rect;
1601
+ const stageRect = this.stageRect;
1602
+ const topBox = this.topBox;
1603
+ if (x == null) {
1604
+ let pxX = 20;
1605
+ if (topBox) {
1606
+ const pxPreferredX = topBox.pxIntrinsicCoord.x + 20;
1607
+ const pxIntrinsicWidth = width * stageRect.width;
1608
+ if (pxPreferredX + pxIntrinsicWidth <= stageRect.width) {
1609
+ pxX = pxPreferredX;
1610
+ }
1611
+ }
1612
+ x = pxX / stageRect.width;
1613
+ }
1614
+ if (y == null) {
1615
+ let pxY = 20;
1616
+ if (topBox) {
1617
+ const pxPreferredY = topBox.pxIntrinsicCoord.y + 20;
1618
+ const pxIntrinsicHeight = height * stageRect.height;
1619
+ if (pxPreferredY + pxIntrinsicHeight <= stageRect.height) {
1620
+ pxY = pxPreferredY;
1621
+ }
1622
+ }
1623
+ y = pxY / stageRect.height;
1624
+ }
1625
+ return { x, y, width, height };
1626
+ }
1627
+ makeBoxTop(box, skipUpdate = false) {
1628
+ if (this.topBox) {
1629
+ if (box !== this.topBox) {
1630
+ box._zIndex$.setValue(this.topBox.zIndex + 1, skipUpdate);
1631
+ }
1632
+ }
1633
+ }
1634
+ getBoxIndex(boxOrID) {
1635
+ return typeof boxOrID === "string" ? this.boxes.findIndex((box) => box.id === boxOrID) : this.boxes.findIndex((box) => box === boxOrID);
1636
+ }
1637
+ getBox(boxOrID) {
1638
+ return typeof boxOrID === "string" ? this.boxes.find((box) => box.id === boxOrID) : boxOrID;
1639
+ }
1640
+ }
1641
+ export { DefaultTitleBar, TELE_BOX_COLOR_SCHEME, TELE_BOX_DELEGATE_EVENT, TELE_BOX_EVENT, TELE_BOX_MANAGER_EVENT, TELE_BOX_RESIZE_HANDLE, TELE_BOX_STATE, TeleBox, TeleBoxCollector, TeleBoxDragHandleType, TeleBoxManager };
2
1642
  //# sourceMappingURL=telebox-insider.es.js.map