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

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 +53 -35
  2. package/dist/TeleBox/typings.d.ts +22 -10
  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 +1647 -1
  13. package/dist/telebox-insider.cjs.js.map +1 -1
  14. package/dist/telebox-insider.es.js +1629 -1
  15. package/dist/telebox-insider.es.js.map +1 -1
  16. package/dist/utils.d.ts +0 -1
  17. package/package.json +3 -3
  18. package/src/TeleBox/index.ts +403 -290
  19. package/src/TeleBox/style.scss +13 -25
  20. package/src/TeleBox/style.shadow.scss +77 -0
  21. package/src/TeleBox/typings.ts +22 -10
  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 +184 -77
  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,1630 @@
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
+ minimized$,
268
+ maximized$,
269
+ readonly$,
270
+ root,
271
+ rootRect$,
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 state$ = combine([minimized$, maximized$], ([minimized, maximized]) => minimized ? TELE_BOX_STATE.Minimized : maximized ? TELE_BOX_STATE.Maximized : TELE_BOX_STATE.Normal);
298
+ const minSize$ = new Val({
299
+ width: clamp(minWidth, 0, 1),
300
+ height: clamp(minHeight, 0, 1)
301
+ }, { compare: shallowequal });
302
+ const pxMinSize$ = combine([minSize$, managerStageRect$], ([minSize, managerStageRect]) => ({
303
+ width: minSize.width * managerStageRect.width,
304
+ height: minSize.height * managerStageRect.height
305
+ }), { compare: shallowequal });
306
+ const intrinsicSize$ = new Val({ width, height }, { compare: shallowequal });
307
+ this._sideEffect.addDisposer(minSize$.reaction((minSize, skipUpdate) => {
308
+ intrinsicSize$.setValue({
309
+ width: Math.max(width, minSize.width),
310
+ height: Math.max(height, minSize.height)
311
+ }, skipUpdate);
312
+ }));
313
+ const intrinsicCoord$ = new Val({ x, y }, { compare: shallowequal });
314
+ const pxIntrinsicSize$ = combine([intrinsicSize$, managerStageRect$], ([size, managerStageRect]) => ({
315
+ width: managerStageRect.width * size.width,
316
+ height: managerStageRect.height * size.height
317
+ }), { compare: shallowequal });
318
+ const pxIntrinsicCoord$ = combine([intrinsicCoord$, managerStageRect$], ([intrinsicCoord, managerStageRect]) => ({
319
+ x: intrinsicCoord.x * managerStageRect.width,
320
+ y: intrinsicCoord.y * managerStageRect.height
321
+ }), { compare: shallowequal });
322
+ const bodyStyle$ = new Val(bodyStyle);
323
+ const stageStyle$ = new Val(stageStyle);
324
+ const contentRoot$ = new Val(null);
325
+ const bodyRect$ = new Val(managerStageRect$.value, {
326
+ compare: shallowequal
327
+ });
328
+ const stageRatio$ = new Val(stageRatio);
329
+ const finalStageRatio$ = combine([stageRatio$, managerStageRatio$], ([stageRatio2, managerStageRatio]) => stageRatio2 != null ? stageRatio2 : managerStageRatio);
330
+ const stageRect$ = combine([bodyRect$, finalStageRatio$], calcStageRect, { compare: shallowequal });
331
+ const propsValConfig = {
332
+ darkMode: darkMode$,
333
+ fence: fence$,
334
+ minimized: minimized$,
335
+ maximized: maximized$,
336
+ readonly: readonly$,
337
+ rootRect: rootRect$,
338
+ managerStageRect: managerStageRect$,
339
+ managerStageRatio: managerStageRatio$,
340
+ defaultBoxBodyStyle: defaultBoxBodyStyle$,
341
+ defaultBoxStageStyle: defaultBoxStageStyle$,
342
+ collectorRect: collectorRect$
343
+ };
344
+ withReadonlyValueEnhancer(this, propsValConfig);
345
+ const myReadonlyValConfig = {
346
+ zIndex: zIndex$,
347
+ focus: focus$,
348
+ state: state$,
349
+ minSize: minSize$,
350
+ pxMinSize: pxMinSize$,
351
+ intrinsicSize: intrinsicSize$,
352
+ intrinsicCoord: intrinsicCoord$,
353
+ pxIntrinsicSize: pxIntrinsicSize$,
354
+ pxIntrinsicCoord: pxIntrinsicCoord$,
355
+ bodyRect: bodyRect$,
356
+ stageRect: stageRect$
357
+ };
358
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
359
+ const valConfig = {
360
+ title: title$,
361
+ visible: visible$,
362
+ resizable: resizable$,
363
+ draggable: draggable$,
364
+ boxRatio: boxRatio$,
365
+ stageRatio: stageRatio$,
366
+ bodyStyle: bodyStyle$,
367
+ stageStyle: stageStyle$
368
+ };
369
+ withValueEnhancer(this, valConfig, valManager);
370
+ this.titleBar = titleBar || new DefaultTitleBar({
371
+ readonly$,
372
+ state$,
373
+ title$,
374
+ namespace: this.namespace,
375
+ onDragStart: (event) => {
376
+ var _a;
377
+ return (_a = this._handleTrackStart) == null ? void 0 : _a.call(this, event);
378
+ },
379
+ onEvent: (event) => this._delegateEvents.emit(event.type)
380
+ });
381
+ this._sideEffect.addDisposer(boxRatio$.subscribe((boxRatio2) => {
382
+ if (boxRatio2 > 0) {
383
+ this.transform(pxIntrinsicCoord$.value.x, pxIntrinsicCoord$.value.y, pxIntrinsicSize$.value.width, pxIntrinsicSize$.value.height);
384
+ }
385
+ }));
386
+ this._sideEffect.addDisposer(fence$.subscribe((fence) => {
387
+ if (fence) {
388
+ this.move(pxIntrinsicCoord$.value.x, pxIntrinsicCoord$.value.y);
389
+ }
390
+ }));
391
+ this.$box = this._render();
392
+ contentRoot$.setValue(this.$content.parentElement);
393
+ content && this.mountContent(content);
394
+ stage && this.mountStage(stage);
395
+ footer && this.mountFooter(footer);
396
+ styles && this.mountStyles(styles);
397
+ userStyles && this.mountUserStyles(userStyles);
398
+ root.appendChild(this.$box);
399
+ const watchValEvent = (val, event) => {
400
+ this._sideEffect.addDisposer(val.reaction((v, skipUpdate) => {
401
+ if (!skipUpdate) {
402
+ this.events.emit(event, v);
403
+ }
404
+ }));
405
+ };
406
+ watchValEvent(darkMode$, TELE_BOX_EVENT.DarkMode);
407
+ watchValEvent(readonly$, TELE_BOX_EVENT.Readonly);
408
+ watchValEvent(zIndex$, TELE_BOX_EVENT.ZIndex);
409
+ watchValEvent(minimized$, TELE_BOX_EVENT.Minimized);
410
+ watchValEvent(maximized$, TELE_BOX_EVENT.Maximized);
411
+ watchValEvent(state$, TELE_BOX_EVENT.State);
412
+ watchValEvent(intrinsicSize$, TELE_BOX_EVENT.IntrinsicResize);
413
+ watchValEvent(intrinsicCoord$, TELE_BOX_EVENT.IntrinsicMove);
414
+ this._sideEffect.addDisposer([
415
+ visible$.reaction((visible2, skipUpdate) => {
416
+ if (!skipUpdate && !visible2) {
417
+ this.events.emit(TELE_BOX_EVENT.Close);
418
+ }
419
+ }),
420
+ focus$.reaction((focus2, skipUpdate) => {
421
+ if (!skipUpdate) {
422
+ this.events.emit(focus2 ? TELE_BOX_EVENT.Focus : TELE_BOX_EVENT.Blur);
423
+ }
424
+ })
425
+ ]);
426
+ }
427
+ get minWidth() {
428
+ return this._minSize$.value.width;
429
+ }
430
+ get minHeight() {
431
+ return this._minSize$.value.height;
432
+ }
433
+ setMinWidth(minWidth, skipUpdate = false) {
434
+ this._minSize$.setValue({ width: minWidth, height: this.minHeight }, skipUpdate);
435
+ }
436
+ setMinHeight(minHeight, skipUpdate = false) {
437
+ this._minSize$.setValue({ width: this.minWidth, height: minHeight }, skipUpdate);
438
+ }
439
+ resize(width, height, skipUpdate = false) {
440
+ this._intrinsicSize$.setValue({
441
+ width: Math.max(width, this.minWidth),
442
+ height: Math.max(height, this.minHeight)
443
+ }, skipUpdate);
444
+ }
445
+ get intrinsicX() {
446
+ return this._intrinsicCoord$.value.x;
447
+ }
448
+ get intrinsicY() {
449
+ return this._intrinsicCoord$.value.y;
450
+ }
451
+ get intrinsicWidth() {
452
+ return this._intrinsicSize$.value.width;
453
+ }
454
+ get intrinsicHeight() {
455
+ return this._intrinsicSize$.value.height;
456
+ }
457
+ move(x, y, skipUpdate = false) {
458
+ let safeX;
459
+ let safeY;
460
+ const managerStageRect = this.managerStageRect;
461
+ const pxIntrinsicSize = this.pxIntrinsicSize;
462
+ if (this.fence) {
463
+ safeX = clamp(x, 0, managerStageRect.width - pxIntrinsicSize.width);
464
+ safeY = clamp(y, 0, managerStageRect.height - pxIntrinsicSize.height);
465
+ } else {
466
+ safeX = clamp(x, -(pxIntrinsicSize.width - 120), 0 + managerStageRect.width - 20);
467
+ safeY = clamp(y, 0, 0 + managerStageRect.height - 20);
468
+ }
469
+ this._intrinsicCoord$.setValue({
470
+ x: safeX / managerStageRect.width,
471
+ y: safeY / managerStageRect.height
472
+ }, skipUpdate);
473
+ }
474
+ transform(x, y, width, height, skipUpdate = false) {
475
+ const managerStageRect = this.managerStageRect;
476
+ width = Math.max(width, this.pxMinSize.width);
477
+ height = Math.max(height, this.pxMinSize.height);
478
+ if (this.boxRatio > 0) {
479
+ const newHeight = this.boxRatio * width;
480
+ if (y !== this.pxIntrinsicCoord.y) {
481
+ y -= newHeight - height;
482
+ }
483
+ height = newHeight;
484
+ }
485
+ if (y < 0) {
486
+ y = 0;
487
+ height = this.pxIntrinsicSize.height;
488
+ }
489
+ this.move(x, y, skipUpdate);
490
+ this._intrinsicSize$.setValue({
491
+ width: width / managerStageRect.width,
492
+ height: height / managerStageRect.height
493
+ }, skipUpdate);
494
+ }
495
+ mountContent(content) {
496
+ var _a;
497
+ (_a = this.$authorContent) == null ? void 0 : _a.remove();
498
+ this.$authorContent = content;
499
+ this.$content.appendChild(content);
500
+ }
501
+ unmountContent() {
502
+ if (this.$authorContent) {
503
+ this.$authorContent.remove();
504
+ this.$authorContent = void 0;
505
+ }
506
+ }
507
+ mountStage(stage) {
508
+ var _a;
509
+ (_a = this.$authorStage) == null ? void 0 : _a.remove();
510
+ this.$authorStage = stage;
511
+ if (!this.$stage) {
512
+ this.$stage = this._renderStage();
513
+ }
514
+ this.$stage.appendChild(stage);
515
+ if (!this.$stage.parentElement) {
516
+ this.$body.appendChild(this.$stage);
517
+ }
518
+ }
519
+ unmountStage() {
520
+ var _a;
521
+ if (this.$authorStage) {
522
+ this.$authorStage.remove();
523
+ this.$authorStage = void 0;
524
+ }
525
+ (_a = this.$stage) == null ? void 0 : _a.remove();
526
+ }
527
+ mountFooter(footer) {
528
+ var _a;
529
+ (_a = this.$authorFooter) == null ? void 0 : _a.remove();
530
+ this.$authorFooter = footer;
531
+ this.$footer.appendChild(footer);
532
+ }
533
+ unmountFooter() {
534
+ if (this.$authorFooter) {
535
+ this.$authorFooter.remove();
536
+ this.$authorFooter = void 0;
537
+ }
538
+ }
539
+ mountStyles(styles) {
540
+ this.$styles.textContent = styles;
541
+ }
542
+ unmountStyles() {
543
+ this.$styles.textContent = "";
544
+ }
545
+ mountUserStyles(styles) {
546
+ this.$userStyles.textContent = styles;
547
+ }
548
+ unmountUserStyles() {
549
+ this.$userStyles.textContent = "";
550
+ }
551
+ _render() {
552
+ if (this.$box) {
553
+ return this.$box;
554
+ }
555
+ const bindBoxStates = (el, disposerID) => {
556
+ return this._sideEffect.addDisposer([
557
+ this._readonly$.subscribe((readonly) => el.classList.toggle(this.wrapClassName("readonly"), readonly)),
558
+ this._draggable$.subscribe((draggable) => el.classList.toggle(this.wrapClassName("no-drag"), !draggable)),
559
+ this._resizable$.subscribe((resizable) => el.classList.toggle(this.wrapClassName("no-resize"), !resizable)),
560
+ this._focus$.subscribe((focus) => el.classList.toggle(this.wrapClassName("blur"), !focus)),
561
+ this._darkMode$.subscribe((darkMode) => {
562
+ el.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
563
+ el.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
564
+ })
565
+ ], disposerID);
566
+ };
567
+ this.$box = document.createElement("div");
568
+ this.$box.classList.add(this.wrapClassName("box"));
569
+ bindBoxStates(this.$box, "bind-box-state");
570
+ this._sideEffect.add(() => {
571
+ const minimizedClassName = this.wrapClassName("minimized");
572
+ const maximizedClassName = this.wrapClassName("maximized");
573
+ const MAXIMIZED_TIMER_ID = "box-maximized-timer";
574
+ return this._state$.subscribe((state) => {
575
+ this.$box.classList.toggle(minimizedClassName, state === TELE_BOX_STATE.Minimized);
576
+ if (state === TELE_BOX_STATE.Maximized) {
577
+ this._sideEffect.flush(MAXIMIZED_TIMER_ID);
578
+ this.$box.classList.toggle(maximizedClassName, true);
579
+ } else {
580
+ this._sideEffect.setTimeout(() => {
581
+ this.$box.classList.toggle(maximizedClassName, false);
582
+ }, 0, MAXIMIZED_TIMER_ID);
583
+ }
584
+ });
585
+ });
586
+ this._sideEffect.addDisposer(this._visible$.subscribe((visible) => {
587
+ this.$box.style.display = visible ? "block" : "none";
588
+ }));
589
+ this._sideEffect.addDisposer(this._zIndex$.subscribe((zIndex) => {
590
+ this.$box.style.zIndex = String(zIndex);
591
+ }));
592
+ this.$box.dataset.teleBoxID = this.id;
593
+ const boxStyler = styler(this.$box);
594
+ const boxStyles$ = combine([
595
+ this._maximized$,
596
+ this._minimized$,
597
+ this._pxIntrinsicSize$,
598
+ this._pxIntrinsicCoord$,
599
+ this._collectorRect$,
600
+ this._rootRect$,
601
+ this._managerStageRect$
602
+ ], ([
603
+ maximized,
604
+ minimized,
605
+ pxIntrinsicSize,
606
+ pxIntrinsicCoord,
607
+ collectorRect,
608
+ rootRect,
609
+ managerStageRect
610
+ ]) => {
611
+ const styles = maximized ? {
612
+ x: -managerStageRect.x,
613
+ y: -managerStageRect.y,
614
+ width: rootRect.width,
615
+ height: rootRect.height,
616
+ scaleX: 1,
617
+ scaleY: 1
618
+ } : {
619
+ x: pxIntrinsicCoord.x,
620
+ y: pxIntrinsicCoord.y,
621
+ width: pxIntrinsicSize.width,
622
+ height: pxIntrinsicSize.height,
623
+ scaleX: 1,
624
+ scaleY: 1
625
+ };
626
+ if (minimized && collectorRect) {
627
+ const { width: boxWidth, height: boxHeight } = maximized ? this.rootRect : pxIntrinsicSize;
628
+ styles.x = collectorRect.x - boxWidth / 2 + collectorRect.width / 2 - managerStageRect.x;
629
+ styles.y = collectorRect.y - boxHeight / 2 + collectorRect.height / 2 - managerStageRect.y;
630
+ styles.scaleX = collectorRect.width / boxWidth;
631
+ styles.scaleY = collectorRect.height / boxHeight;
632
+ }
633
+ return styles;
634
+ }, { compare: shallowequal });
635
+ const boxStyles = boxStyles$.value;
636
+ this.$box.style.width = boxStyles.width + "px";
637
+ this.$box.style.height = boxStyles.height + "px";
638
+ this.$box.style.transform = `translate(${boxStyles.x - 10}px,${boxStyles.y - 10}px)`;
639
+ this._sideEffect.addDisposer(boxStyles$.subscribe((styles) => {
640
+ boxStyler.set(styles);
641
+ }));
642
+ const $boxMain = document.createElement("div");
643
+ $boxMain.className = this.wrapClassName("box-main");
644
+ this.$box.appendChild($boxMain);
645
+ const $titleBar = document.createElement("div");
646
+ $titleBar.className = this.wrapClassName("titlebar-wrap");
647
+ $titleBar.appendChild(this.titleBar.render());
648
+ this.$titleBar = $titleBar;
649
+ const $body = document.createElement("div");
650
+ $body.className = this.wrapClassName("body-wrap");
651
+ this.$body = $body;
652
+ const $styles = document.createElement("style");
653
+ this.$styles = $styles;
654
+ $body.appendChild($styles);
655
+ const $userStyles = document.createElement("style");
656
+ this.$userStyles = $userStyles;
657
+ $body.appendChild($userStyles);
658
+ const $content = document.createElement("div");
659
+ $content.className = this.wrapClassName("content") + " tele-fancy-scrollbar";
660
+ this.$content = $content;
661
+ this._sideEffect.addDisposer(combine([this._bodyStyle$, this._defaultBoxBodyStyle$], ([bodyStyle, defaultBoxBodyStyle]) => bodyStyle != null ? bodyStyle : defaultBoxBodyStyle).subscribe((style2) => $content.style.cssText = style2 || ""));
662
+ $body.appendChild($content);
663
+ const $footer = document.createElement("div");
664
+ $footer.className = this.wrapClassName("footer-wrap");
665
+ this.$footer = $footer;
666
+ $boxMain.appendChild($titleBar);
667
+ const $main = document.createElement("div");
668
+ $main.className = this.wrapClassName("main");
669
+ this.$main = $main;
670
+ $boxMain.appendChild($main);
671
+ const $quarantineOuter = document.createElement("div");
672
+ $quarantineOuter.className = this.wrapClassName("quarantine-outer");
673
+ $main.appendChild($quarantineOuter);
674
+ const $quarantine = document.createElement("div");
675
+ $quarantine.className = this.wrapClassName("quarantine");
676
+ $quarantine.appendChild($body);
677
+ $quarantine.appendChild($footer);
678
+ if (this.enableShadowDOM) {
679
+ bindBoxStates($quarantine, "bind-quarantine-state");
680
+ const $shadowStyle = document.createElement("style");
681
+ $shadowStyle.textContent = shadowStyles;
682
+ $quarantine.insertBefore($shadowStyle, $quarantine.firstChild);
683
+ const shadow = $quarantineOuter.attachShadow({ mode: "open" });
684
+ shadow.appendChild($quarantine);
685
+ } else {
686
+ $quarantineOuter.appendChild($quarantine);
687
+ }
688
+ this._renderResizeHandlers();
689
+ const updateBodyRect = () => {
690
+ const rect = $body.getBoundingClientRect();
691
+ this._bodyRect$.setValue({
692
+ x: 0,
693
+ y: 0,
694
+ width: rect.width,
695
+ height: rect.height
696
+ });
697
+ };
698
+ this._sideEffect.add(() => {
699
+ const observer = new ResizeObserver$1(() => {
700
+ if (!this.minimized) {
701
+ updateBodyRect();
702
+ }
703
+ });
704
+ observer.observe($body);
705
+ return () => observer.disconnect();
706
+ });
707
+ this._sideEffect.addDisposer(this._minimized$.reaction((minimized) => {
708
+ if (!minimized) {
709
+ this._sideEffect.setTimeout(updateBodyRect, 400, "minimized-content-rect-fix");
710
+ }
711
+ }));
712
+ return this.$box;
713
+ }
714
+ _renderStage() {
715
+ const $stage = document.createElement("div");
716
+ $stage.className = this.wrapClassName("box-stage");
717
+ const updateStageRect = (stageRect) => {
718
+ $stage.style.top = stageRect.y + "px";
719
+ $stage.style.left = stageRect.x + "px";
720
+ $stage.style.width = stageRect.width + "px";
721
+ $stage.style.height = stageRect.height + "px";
722
+ };
723
+ this._sideEffect.addDisposer([
724
+ combine([this._stageStyle$, this._defaultBoxStageStyle$], ([stageStyle, defaultBoxStageStyle]) => stageStyle != null ? stageStyle : defaultBoxStageStyle).subscribe((styles) => {
725
+ $stage.style.cssText = styles || "";
726
+ updateStageRect(this._stageRect$.value);
727
+ }),
728
+ this._stageRect$.subscribe(updateStageRect)
729
+ ], "box-stage-styles");
730
+ return $stage;
731
+ }
732
+ _renderResizeHandlers() {
733
+ const $resizeHandles = document.createElement("div");
734
+ $resizeHandles.className = this.wrapClassName("resize-handles");
735
+ Object.values(TELE_BOX_RESIZE_HANDLE).forEach((handleType) => {
736
+ const $handle = document.createElement("div");
737
+ $handle.className = this.wrapClassName(handleType) + " " + this.wrapClassName("resize-handle");
738
+ $handle.dataset.teleBoxHandle = handleType;
739
+ $resizeHandles.appendChild($handle);
740
+ });
741
+ this.$box.appendChild($resizeHandles);
742
+ const TRACKING_DISPOSER_ID = "handle-tracking-listener";
743
+ const transformingClassName = this.wrapClassName("transforming");
744
+ let $trackMask;
745
+ let trackStartX = 0;
746
+ let trackStartY = 0;
747
+ let trackStartWidth = 0;
748
+ let trackStartHeight = 0;
749
+ let trackStartPageX = 0;
750
+ let trackStartPageY = 0;
751
+ let trackingHandle;
752
+ const handleTracking = (ev) => {
753
+ if (!ev.isPrimary || this.state !== TELE_BOX_STATE.Normal) {
754
+ return;
755
+ }
756
+ preventEvent(ev);
757
+ let { pageX, pageY } = ev;
758
+ if (pageY < 0) {
759
+ pageY = 0;
760
+ }
761
+ const offsetX = pageX - trackStartPageX;
762
+ const offsetY = pageY - trackStartPageY;
763
+ let { x: newX, y: newY } = this.pxIntrinsicCoord;
764
+ let { width: newWidth, height: newHeight } = this.pxIntrinsicSize;
765
+ switch (trackingHandle) {
766
+ case TELE_BOX_RESIZE_HANDLE.North: {
767
+ newY = trackStartY + offsetY;
768
+ newHeight = trackStartHeight - offsetY;
769
+ break;
770
+ }
771
+ case TELE_BOX_RESIZE_HANDLE.South: {
772
+ newHeight = trackStartHeight + offsetY;
773
+ break;
774
+ }
775
+ case TELE_BOX_RESIZE_HANDLE.West: {
776
+ newX = trackStartX + offsetX;
777
+ newWidth = trackStartWidth - offsetX;
778
+ break;
779
+ }
780
+ case TELE_BOX_RESIZE_HANDLE.East: {
781
+ newWidth = trackStartWidth + offsetX;
782
+ break;
783
+ }
784
+ case TELE_BOX_RESIZE_HANDLE.NorthWest: {
785
+ newX = trackStartX + offsetX;
786
+ newY = trackStartY + offsetY;
787
+ newWidth = trackStartWidth - offsetX;
788
+ newHeight = trackStartHeight - offsetY;
789
+ break;
790
+ }
791
+ case TELE_BOX_RESIZE_HANDLE.NorthEast: {
792
+ newY = trackStartY + offsetY;
793
+ newWidth = trackStartWidth + offsetX;
794
+ newHeight = trackStartHeight - offsetY;
795
+ break;
796
+ }
797
+ case TELE_BOX_RESIZE_HANDLE.SouthEast: {
798
+ newWidth = trackStartWidth + offsetX;
799
+ newHeight = trackStartHeight + offsetY;
800
+ break;
801
+ }
802
+ case TELE_BOX_RESIZE_HANDLE.SouthWest: {
803
+ newX = trackStartX + offsetX;
804
+ newWidth = trackStartWidth - offsetX;
805
+ newHeight = trackStartHeight + offsetY;
806
+ break;
807
+ }
808
+ default: {
809
+ this.move(trackStartX + offsetX, trackStartY + offsetY);
810
+ return;
811
+ }
812
+ }
813
+ this.transform(newX, newY, newWidth, newHeight);
814
+ };
815
+ const handleTrackEnd = (ev) => {
816
+ if (!ev.isPrimary) {
817
+ return;
818
+ }
819
+ trackingHandle = void 0;
820
+ if (!$trackMask) {
821
+ return;
822
+ }
823
+ preventEvent(ev);
824
+ this.$box.classList.toggle(transformingClassName, false);
825
+ this._sideEffect.flush(TRACKING_DISPOSER_ID);
826
+ $trackMask.remove();
827
+ };
828
+ const handleTrackStart = (ev) => {
829
+ var _a;
830
+ if (!ev.isPrimary || this.readonly) {
831
+ return;
832
+ }
833
+ if (ev.button != null && ev.button !== 0) {
834
+ return;
835
+ }
836
+ if (!this.draggable || trackingHandle || this.state !== TELE_BOX_STATE.Normal) {
837
+ return;
838
+ }
839
+ const target = ev.target;
840
+ if ((_a = target.dataset) == null ? void 0 : _a.teleBoxHandle) {
841
+ preventEvent(ev);
842
+ ({ x: trackStartX, y: trackStartY } = this.pxIntrinsicCoord);
843
+ ({ width: trackStartWidth, height: trackStartHeight } = this.pxIntrinsicSize);
844
+ ({ pageX: trackStartPageX, pageY: trackStartPageY } = ev);
845
+ trackingHandle = target.dataset.teleBoxHandle;
846
+ if (!$trackMask) {
847
+ $trackMask = document.createElement("div");
848
+ }
849
+ const cursor = trackingHandle ? this.wrapClassName(`cursor-${trackingHandle}`) : "";
850
+ $trackMask.className = this.wrapClassName(`track-mask${cursor ? ` ${cursor}` : ""}`);
851
+ this.$box.appendChild($trackMask);
852
+ this.$box.classList.add(transformingClassName);
853
+ this._sideEffect.add(() => {
854
+ window.addEventListener("pointermove", handleTracking, {
855
+ passive: false
856
+ });
857
+ window.addEventListener("pointerup", handleTrackEnd, {
858
+ passive: false
859
+ });
860
+ window.addEventListener("pointercancel", handleTrackEnd, {
861
+ passive: false
862
+ });
863
+ return () => {
864
+ window.removeEventListener("pointermove", handleTracking);
865
+ window.removeEventListener("pointerup", handleTrackEnd);
866
+ window.removeEventListener("pointercancel", handleTrackEnd);
867
+ };
868
+ }, TRACKING_DISPOSER_ID);
869
+ }
870
+ };
871
+ this._handleTrackStart = handleTrackStart;
872
+ this._sideEffect.addEventListener($resizeHandles, "pointerdown", handleTrackStart, {}, "box-resizeHandles-pointerdown");
873
+ }
874
+ async destroy() {
875
+ this.$box.remove();
876
+ this._sideEffect.flushAll();
877
+ this._sideEffect.flushAll();
878
+ await this.events.emit(TELE_BOX_EVENT.Destroyed);
879
+ this.events.clearListeners();
880
+ this._delegateEvents.clearListeners();
881
+ }
882
+ wrapClassName(className) {
883
+ return `${this.namespace}-${className}`;
884
+ }
885
+ }
886
+ 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}")();
887
+ 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}")();
888
+ var collectorSVG = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxOCAxNiI+CiAgICA8ZyBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxwYXRoIHN0cm9rZT0iIzdCODhBMCIgc3Ryb2tlLXdpZHRoPSIxLjQiIGQ9Ik0uNyAxLjJoMTYuNnYxMy42SC43eiIgLz4KICAgICAgICA8cGF0aCBmaWxsPSIjN0I4OEEwIiBkPSJNNCA1LjVoNnYxLjRINHpNNCA5LjVoMTB2MS40SDR6IiAvPgogICAgPC9nPgo8L3N2Zz4K";
889
+ class TeleBoxCollector {
890
+ constructor({
891
+ minimized$,
892
+ readonly$,
893
+ darkMode$,
894
+ namespace = "telebox",
895
+ styles = {},
896
+ root,
897
+ onClick
898
+ }) {
899
+ this._sideEffect = new SideEffectManager();
900
+ this.namespace = namespace;
901
+ const valManager = new ValManager();
902
+ this._sideEffect.addDisposer(() => valManager.destroy());
903
+ const rect$ = new Val(void 0);
904
+ const visible$ = derive(minimized$);
905
+ const styles$ = new Val(styles);
906
+ const el$ = new Val(document.createElement("button"));
907
+ const valConfig = {
908
+ styles: styles$,
909
+ $collector: el$
910
+ };
911
+ withValueEnhancer(this, valConfig, valManager);
912
+ const myReadonlyValConfig = {
913
+ rect: rect$,
914
+ visible: visible$
915
+ };
916
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
917
+ el$.value.className = this.wrapClassName("collector");
918
+ el$.value.style.backgroundImage = `url('${collectorSVG}')`;
919
+ this._sideEffect.addDisposer(el$.subscribe(($collector) => {
920
+ this._sideEffect.add(() => {
921
+ root.appendChild($collector);
922
+ return () => $collector.remove();
923
+ }, "telebox-collector-mount");
924
+ this._sideEffect.addEventListener($collector, "click", () => {
925
+ if (!readonly$.value) {
926
+ onClick == null ? void 0 : onClick();
927
+ }
928
+ }, {}, "telebox-collector-click");
929
+ this._sideEffect.addDisposer([
930
+ visible$.subscribe((visible) => {
931
+ $collector.classList.toggle(this.wrapClassName("collector-visible"), visible);
932
+ }),
933
+ readonly$.subscribe((readonly) => {
934
+ $collector.classList.toggle(this.wrapClassName("collector-readonly"), readonly);
935
+ }),
936
+ darkMode$.subscribe((darkMode) => {
937
+ $collector.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
938
+ $collector.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
939
+ }),
940
+ styles$.subscribe((styles2) => {
941
+ Object.keys(styles2).forEach((key) => {
942
+ const value = styles2[key];
943
+ if (value != null) {
944
+ $collector.style[key] = value;
945
+ }
946
+ });
947
+ }),
948
+ minimized$.subscribe((minimized) => {
949
+ if (minimized) {
950
+ const { x, y, width, height } = $collector.getBoundingClientRect();
951
+ const rootRect = root.getBoundingClientRect();
952
+ rect$.setValue({
953
+ x: x - rootRect.x,
954
+ y: y - rootRect.y,
955
+ width,
956
+ height
957
+ });
958
+ }
959
+ })
960
+ ], "telebox-collector-el");
961
+ }));
962
+ }
963
+ destroy() {
964
+ this._sideEffect.flushAll();
965
+ }
966
+ wrapClassName(className) {
967
+ return `${this.namespace}-${className}`;
968
+ }
969
+ }
970
+ var TELE_BOX_MANAGER_EVENT = /* @__PURE__ */ ((TELE_BOX_MANAGER_EVENT2) => {
971
+ TELE_BOX_MANAGER_EVENT2["Focused"] = "focused";
972
+ TELE_BOX_MANAGER_EVENT2["Blurred"] = "blurred";
973
+ TELE_BOX_MANAGER_EVENT2["Created"] = "created";
974
+ TELE_BOX_MANAGER_EVENT2["Removed"] = "removed";
975
+ TELE_BOX_MANAGER_EVENT2["State"] = "state";
976
+ TELE_BOX_MANAGER_EVENT2["Maximized"] = "maximized";
977
+ TELE_BOX_MANAGER_EVENT2["Minimized"] = "minimized";
978
+ TELE_BOX_MANAGER_EVENT2["IntrinsicMove"] = "intrinsic_move";
979
+ TELE_BOX_MANAGER_EVENT2["IntrinsicResize"] = "intrinsic_resize";
980
+ TELE_BOX_MANAGER_EVENT2["ZIndex"] = "z_index";
981
+ TELE_BOX_MANAGER_EVENT2["PrefersColorScheme"] = "prefers_color_scheme";
982
+ TELE_BOX_MANAGER_EVENT2["DarkMode"] = "dark_mode";
983
+ return TELE_BOX_MANAGER_EVENT2;
984
+ })(TELE_BOX_MANAGER_EVENT || {});
985
+ 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}")();
986
+ class MaxTitleBar extends DefaultTitleBar {
987
+ constructor(config) {
988
+ super(config);
989
+ this.boxes$ = config.boxes$;
990
+ this.rootRect$ = config.rootRect$;
991
+ this.darkMode$ = config.darkMode$;
992
+ config.root.appendChild(this.render());
993
+ }
994
+ focusBox(box) {
995
+ var _a;
996
+ if (this.focusedBox && this.focusedBox === box) {
997
+ return;
998
+ }
999
+ if (this.$titles && this.state$.value === TELE_BOX_STATE.Maximized) {
1000
+ const { children } = this.$titles.firstElementChild;
1001
+ for (let i = children.length - 1; i >= 0; i -= 1) {
1002
+ const $tab = children[i];
1003
+ const id = (_a = $tab.dataset) == null ? void 0 : _a.teleBoxID;
1004
+ if (id) {
1005
+ if (box && id === box.id) {
1006
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), true);
1007
+ } else if (this.focusedBox && id === this.focusedBox.id) {
1008
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), false);
1009
+ }
1010
+ }
1011
+ }
1012
+ }
1013
+ this.focusedBox = box;
1014
+ }
1015
+ render() {
1016
+ if (this.$titleBar) {
1017
+ return this.$titleBar;
1018
+ }
1019
+ const $titleBar = super.render();
1020
+ $titleBar.classList.add(this.wrapClassName("max-titlebar"));
1021
+ this.sideEffect.addDisposer([
1022
+ this.state$.subscribe((state) => {
1023
+ $titleBar.classList.toggle(this.wrapClassName("max-titlebar-maximized"), state === TELE_BOX_STATE.Maximized);
1024
+ }),
1025
+ this.readonly$.subscribe((readonly) => {
1026
+ $titleBar.classList.toggle(this.wrapClassName("readonly"), readonly);
1027
+ }),
1028
+ combine([this.state$, this.boxes$]).subscribe(([state, titles]) => {
1029
+ if (state === TELE_BOX_STATE.Maximized) {
1030
+ $titleBar.classList.toggle(this.wrapClassName("max-titlebar-single-title"), titles.length === 1);
1031
+ if (titles.length !== 1) {
1032
+ $titleBar.replaceChild(this.renderTitles(), $titleBar.firstElementChild);
1033
+ }
1034
+ }
1035
+ })
1036
+ ], "max-render");
1037
+ const $titlesArea = document.createElement("div");
1038
+ $titlesArea.classList.add(this.wrapClassName("titles-area"));
1039
+ $titleBar.insertBefore($titlesArea, $titleBar.firstElementChild);
1040
+ return $titleBar;
1041
+ }
1042
+ destroy() {
1043
+ super.destroy();
1044
+ this.$titles = void 0;
1045
+ this.focusedBox = void 0;
1046
+ }
1047
+ renderTitles() {
1048
+ this.$titles = document.createElement("div");
1049
+ this.$titles.className = this.wrapClassName("titles");
1050
+ this.sideEffect.addEventListener(this.$titles, "wheel", (ev) => {
1051
+ ev.currentTarget.scrollBy({
1052
+ left: ev.deltaY > 0 ? 250 : -250,
1053
+ behavior: "smooth"
1054
+ });
1055
+ }, { passive: false }, "max-render-wheel-titles");
1056
+ const $content = document.createElement("div");
1057
+ $content.className = this.wrapClassName("titles-content");
1058
+ this.$titles.appendChild($content);
1059
+ const disposers = this.boxes$.value.map((box) => {
1060
+ const $tab = document.createElement("button");
1061
+ $tab.className = this.wrapClassName("titles-tab");
1062
+ $tab.textContent = box.title;
1063
+ $tab.dataset.teleBoxID = box.id;
1064
+ $tab.dataset.teleTitleBarNoDblClick = "true";
1065
+ if (this.focusedBox && box.id === this.focusedBox.id) {
1066
+ $tab.classList.add(this.wrapClassName("titles-tab-focus"));
1067
+ }
1068
+ $content.appendChild($tab);
1069
+ return box._title$.reaction((title) => $tab.textContent = title);
1070
+ });
1071
+ this.sideEffect.addDisposer(() => disposers.forEach((disposer) => disposer()), "max-render-tab-titles");
1072
+ return this.$titles;
1073
+ }
1074
+ }
1075
+ const ResizeObserver = window.ResizeObserver || ResizeObserver$2;
1076
+ class TeleBoxManager {
1077
+ constructor({
1078
+ root = null,
1079
+ fullscreen = false,
1080
+ prefersColorScheme = TELE_BOX_COLOR_SCHEME.Light,
1081
+ minimized = false,
1082
+ maximized = false,
1083
+ fence = true,
1084
+ collector,
1085
+ namespace = "telebox",
1086
+ readonly = false,
1087
+ stageRatio = -1,
1088
+ containerStyle = "",
1089
+ stageStyle = "",
1090
+ defaultBoxBodyStyle = null,
1091
+ defaultBoxStageStyle = null,
1092
+ theme = {}
1093
+ } = {}) {
1094
+ this.events = new Emittery();
1095
+ this._sideEffect = new SideEffectManager();
1096
+ this.namespace = namespace;
1097
+ const valManager = new ValManager();
1098
+ this._sideEffect.addDisposer(() => valManager.destroy());
1099
+ const root$ = new Val(root);
1100
+ const readonly$ = new Val(readonly);
1101
+ const fence$ = new Val(fence);
1102
+ const containerStyle$ = new Val(containerStyle);
1103
+ const stageStyle$ = new Val(stageStyle);
1104
+ const stageRatio$ = new Val(stageRatio);
1105
+ const defaultBoxBodyStyle$ = new Val(defaultBoxBodyStyle);
1106
+ const defaultBoxStageStyle$ = new Val(defaultBoxStageStyle);
1107
+ const fullscreen$ = new Val(fullscreen);
1108
+ const input_minimized$ = new Val(minimized);
1109
+ const input_maximized$ = new Val(maximized);
1110
+ const maximized$ = combine([input_maximized$, fullscreen$], ([maximized2, fullscreen2]) => fullscreen2 ? true : maximized2);
1111
+ const minimized$ = combine([input_minimized$, fullscreen$], ([minimized2, fullscreen2]) => fullscreen2 ? false : minimized2);
1112
+ this.setMaximized = (maximized2, skipUpdate) => input_maximized$.setValue(maximized2, skipUpdate);
1113
+ this.setMinimized = (minimized2, skipUpdate) => input_minimized$.setValue(minimized2, skipUpdate);
1114
+ const rootRect$ = new Val({
1115
+ x: 0,
1116
+ y: 0,
1117
+ width: window.innerWidth,
1118
+ height: window.innerHeight
1119
+ }, { compare: shallowequal });
1120
+ this._sideEffect.addDisposer(root$.subscribe((root2) => {
1121
+ this._sideEffect.add(() => {
1122
+ if (!root2) {
1123
+ return () => void 0;
1124
+ }
1125
+ const observer = new ResizeObserver(() => {
1126
+ const rect = root2.getBoundingClientRect();
1127
+ rootRect$.setValue({
1128
+ x: 0,
1129
+ y: 0,
1130
+ width: rect.width,
1131
+ height: rect.height
1132
+ });
1133
+ });
1134
+ observer.observe(root2);
1135
+ return () => observer.disconnect();
1136
+ }, "calc-root-rect");
1137
+ }));
1138
+ const stageRect$ = combine([rootRect$, stageRatio$], calcStageRect, {
1139
+ compare: shallowequal
1140
+ });
1141
+ this.boxes$ = new Val([]);
1142
+ this.topBox$ = new Val(void 0);
1143
+ this._sideEffect.addDisposer(this.boxes$.subscribe((boxes) => {
1144
+ if (boxes.length > 0) {
1145
+ const topBox = boxes.reduce((topBox2, box) => topBox2.zIndex > box.zIndex ? topBox2 : box);
1146
+ this.topBox$.setValue(topBox);
1147
+ } else {
1148
+ this.topBox$.setValue(void 0);
1149
+ }
1150
+ }));
1151
+ const prefersDarkMatch = window.matchMedia("(prefers-color-scheme: dark)");
1152
+ const prefersDark$ = new Val(false);
1153
+ if (prefersDarkMatch) {
1154
+ prefersDark$.setValue(prefersDarkMatch.matches);
1155
+ this._sideEffect.add(() => {
1156
+ const handler = (evt) => {
1157
+ prefersDark$.setValue(evt.matches);
1158
+ };
1159
+ prefersDarkMatch.addEventListener("change", handler);
1160
+ return () => prefersDarkMatch.removeEventListener("change", handler);
1161
+ });
1162
+ }
1163
+ const prefersColorScheme$ = new Val(prefersColorScheme);
1164
+ this._sideEffect.addDisposer(prefersColorScheme$.reaction((prefersColorScheme2, skipUpdate) => {
1165
+ if (!skipUpdate) {
1166
+ this.events.emit(TELE_BOX_MANAGER_EVENT.PrefersColorScheme, prefersColorScheme2);
1167
+ }
1168
+ }));
1169
+ const darkMode$ = combine([prefersDark$, prefersColorScheme$], ([prefersDark, prefersColorScheme2]) => prefersColorScheme2 === "auto" ? prefersDark : prefersColorScheme2 === "dark");
1170
+ const state$ = combine([minimized$, maximized$], ([minimized2, maximized2]) => minimized2 ? TELE_BOX_STATE.Minimized : maximized2 ? TELE_BOX_STATE.Maximized : TELE_BOX_STATE.Normal);
1171
+ const readonlyValConfig = {
1172
+ darkMode: darkMode$,
1173
+ state: state$,
1174
+ root: root$,
1175
+ rootRect: rootRect$,
1176
+ stageRect: stageRect$,
1177
+ minimized: minimized$,
1178
+ maximized: maximized$
1179
+ };
1180
+ withReadonlyValueEnhancer(this, readonlyValConfig, valManager);
1181
+ const valConfig = {
1182
+ fullscreen: fullscreen$,
1183
+ prefersColorScheme: prefersColorScheme$,
1184
+ readonly: readonly$,
1185
+ fence: fence$,
1186
+ stageRatio: stageRatio$,
1187
+ containerStyle: containerStyle$,
1188
+ stageStyle: stageStyle$,
1189
+ defaultBoxBodyStyle: defaultBoxBodyStyle$,
1190
+ defaultBoxStageStyle: defaultBoxStageStyle$
1191
+ };
1192
+ withValueEnhancer(this, valConfig, valManager);
1193
+ const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
1194
+ const checkFocusBox = (ev) => {
1195
+ var _a;
1196
+ if (!ev.isPrimary || readonly$.value) {
1197
+ return;
1198
+ }
1199
+ const target = ev.target;
1200
+ if (!target.tagName) {
1201
+ return;
1202
+ }
1203
+ for (let el = target; el; el = el.parentElement) {
1204
+ if (el.classList && el.classList.contains(closeBtnClassName)) {
1205
+ return;
1206
+ }
1207
+ const id = (_a = el.dataset) == null ? void 0 : _a.teleBoxID;
1208
+ if (id) {
1209
+ const box = this.getBox(id);
1210
+ if (box) {
1211
+ this.focusBox(box);
1212
+ this.makeBoxTop(box);
1213
+ return;
1214
+ }
1215
+ }
1216
+ }
1217
+ };
1218
+ this._sideEffect.addEventListener(window, "pointerdown", checkFocusBox, true);
1219
+ this.$container = document.createElement("div");
1220
+ this.$container.className = this.wrapClassName("manager-container");
1221
+ this.setTheme(theme);
1222
+ this.$stage = document.createElement("div");
1223
+ this.$stage.className = this.wrapClassName("manager-stage");
1224
+ this.$container.appendChild(this.$stage);
1225
+ this._sideEffect.addDisposer([
1226
+ darkMode$.subscribe((darkMode) => {
1227
+ this.$container.classList.toggle(this.wrapClassName("color-scheme-dark"), darkMode);
1228
+ this.$container.classList.toggle(this.wrapClassName("color-scheme-light"), !darkMode);
1229
+ }),
1230
+ fullscreen$.subscribe((fullscreen2) => {
1231
+ this.$container.classList.toggle(this.wrapClassName("is-fullscreen"), Boolean(fullscreen2));
1232
+ }),
1233
+ combine([this.boxes$, fullscreen$], ([boxes, fullscreen2]) => fullscreen2 === "no-titlebar" || fullscreen2 === true && boxes.length <= 1).subscribe((hideSingleTabTitlebar) => {
1234
+ this.$container.classList.toggle(this.wrapClassName("hide-fullscreen-titlebar"), hideSingleTabTitlebar);
1235
+ }),
1236
+ maximized$.subscribe((maximized2) => {
1237
+ this.$container.classList.toggle(this.wrapClassName("is-maximized"), maximized2);
1238
+ }),
1239
+ minimized$.subscribe((minimized2) => {
1240
+ this.$container.classList.toggle(this.wrapClassName("is-minimized"), minimized2);
1241
+ }),
1242
+ containerStyle$.subscribe((containerStyle2) => {
1243
+ this.$container.style.cssText = containerStyle2;
1244
+ }),
1245
+ stageStyle$.subscribe((stageStyle2) => {
1246
+ this.$stage.style.cssText = stageStyle2;
1247
+ this.$stage.style.width = stageRect$.value.width + "px";
1248
+ this.$stage.style.height = stageRect$.value.height + "px";
1249
+ }),
1250
+ stageRect$.subscribe((stageRect) => {
1251
+ this.$stage.style.width = stageRect.width + "px";
1252
+ this.$stage.style.height = stageRect.height + "px";
1253
+ }),
1254
+ root$.subscribe((root2) => {
1255
+ if (root2) {
1256
+ root2.appendChild(this.$container);
1257
+ } else if (this.$container.parentElement) {
1258
+ this.$container.remove();
1259
+ }
1260
+ })
1261
+ ]);
1262
+ this.collector = collector != null ? collector : new TeleBoxCollector({
1263
+ minimized$,
1264
+ readonly$,
1265
+ darkMode$,
1266
+ namespace,
1267
+ root: this.$container,
1268
+ onClick: () => input_minimized$.setValue(false)
1269
+ });
1270
+ this.titleBar = new MaxTitleBar({
1271
+ namespace: this.namespace,
1272
+ title$: derive(this.topBox$, (topBox) => (topBox == null ? void 0 : topBox.title) || ""),
1273
+ boxes$: this.boxes$,
1274
+ darkMode$,
1275
+ readonly$,
1276
+ state$,
1277
+ rootRect$,
1278
+ root: this.$container,
1279
+ onEvent: (event) => {
1280
+ switch (event.type) {
1281
+ case TELE_BOX_DELEGATE_EVENT.Maximize: {
1282
+ this.setMaximized(!maximized$.value);
1283
+ break;
1284
+ }
1285
+ case TELE_BOX_DELEGATE_EVENT.Minimize: {
1286
+ this.setMinimized(true);
1287
+ break;
1288
+ }
1289
+ case TELE_BOX_EVENT.Close: {
1290
+ this.removeTopBox();
1291
+ this.focusTopBox();
1292
+ break;
1293
+ }
1294
+ }
1295
+ }
1296
+ });
1297
+ this._sideEffect.addDisposer([
1298
+ state$.reaction((state, skipUpdate) => {
1299
+ if (!skipUpdate) {
1300
+ this.events.emit(TELE_BOX_MANAGER_EVENT.State, state);
1301
+ }
1302
+ }),
1303
+ maximized$.reaction((maximized2, skipUpdate) => {
1304
+ if (!skipUpdate) {
1305
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Maximized, maximized2);
1306
+ }
1307
+ }),
1308
+ minimized$.reaction((minimized2, skipUpdate) => {
1309
+ if (!skipUpdate) {
1310
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Minimized, minimized2);
1311
+ }
1312
+ }),
1313
+ darkMode$.reaction((darkMode, skipUpdate) => {
1314
+ if (!skipUpdate) {
1315
+ this.events.emit(TELE_BOX_MANAGER_EVENT.DarkMode, darkMode);
1316
+ }
1317
+ })
1318
+ ]);
1319
+ }
1320
+ get boxes() {
1321
+ return this.boxes$.value;
1322
+ }
1323
+ get topBox() {
1324
+ return this.topBox$.value;
1325
+ }
1326
+ setState(state, skipUpdate = false) {
1327
+ switch (state) {
1328
+ case TELE_BOX_STATE.Maximized: {
1329
+ this.setMinimized(false, skipUpdate);
1330
+ this.setMaximized(true, skipUpdate);
1331
+ break;
1332
+ }
1333
+ case TELE_BOX_STATE.Minimized: {
1334
+ this.setMinimized(true, skipUpdate);
1335
+ this.setMaximized(false, skipUpdate);
1336
+ break;
1337
+ }
1338
+ default: {
1339
+ this.setMinimized(false, skipUpdate);
1340
+ this.setMaximized(false, skipUpdate);
1341
+ break;
1342
+ }
1343
+ }
1344
+ return this;
1345
+ }
1346
+ create(config = {}, smartPosition = true) {
1347
+ const box = new TeleBox({
1348
+ zIndex: this.topBox ? this.topBox.zIndex + 1 : 100,
1349
+ ...config,
1350
+ ...smartPosition ? this.smartPosition(config) : {},
1351
+ namespace: this.namespace,
1352
+ root: this.$stage,
1353
+ darkMode$: this._darkMode$,
1354
+ maximized$: this._maximized$,
1355
+ minimized$: this._minimized$,
1356
+ fence$: this._fence$,
1357
+ rootRect$: this._rootRect$,
1358
+ managerStageRect$: this._stageRect$,
1359
+ managerStageRatio$: this._stageRatio$,
1360
+ readonly$: this._readonly$,
1361
+ collectorRect$: this.collector._rect$,
1362
+ defaultBoxBodyStyle$: this._defaultBoxBodyStyle$,
1363
+ defaultBoxStageStyle$: this._defaultBoxStageStyle$
1364
+ });
1365
+ if (box.focus) {
1366
+ this.focusBox(box);
1367
+ if (smartPosition) {
1368
+ this.makeBoxTop(box);
1369
+ }
1370
+ }
1371
+ this.boxes$.setValue([...this.boxes, box]);
1372
+ this._sideEffect.addDisposer([
1373
+ box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
1374
+ this.setMaximized(!this.maximized);
1375
+ }),
1376
+ box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Minimize, () => {
1377
+ this.setMinimized(true);
1378
+ }),
1379
+ box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
1380
+ this.remove(box);
1381
+ this.focusTopBox();
1382
+ }),
1383
+ box._intrinsicCoord$.reaction((_, skipUpdate) => {
1384
+ if (!skipUpdate) {
1385
+ this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicMove, box);
1386
+ }
1387
+ }),
1388
+ box._intrinsicSize$.reaction((_, skipUpdate) => {
1389
+ if (!skipUpdate) {
1390
+ this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicResize, box);
1391
+ }
1392
+ }),
1393
+ box._zIndex$.reaction((_, skipUpdate) => {
1394
+ if (this.boxes.length > 0) {
1395
+ const topBox = this.boxes.reduce((topBox2, box2) => topBox2.zIndex > box2.zIndex ? topBox2 : box2);
1396
+ this.topBox$.setValue(topBox);
1397
+ }
1398
+ if (!skipUpdate) {
1399
+ this.events.emit(TELE_BOX_MANAGER_EVENT.ZIndex, box);
1400
+ }
1401
+ })
1402
+ ]);
1403
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Created, box);
1404
+ return box;
1405
+ }
1406
+ query(config) {
1407
+ return config ? this.boxes.filter(this.teleBoxMatcher(config)) : [...this.boxes];
1408
+ }
1409
+ queryOne(config) {
1410
+ return config ? this.boxes.find(this.teleBoxMatcher(config)) : this.boxes[0];
1411
+ }
1412
+ update(boxID, config, skipUpdate = false) {
1413
+ const box = this.boxes.find((box2) => box2.id === boxID);
1414
+ if (box) {
1415
+ return this.updateBox(box, config, skipUpdate);
1416
+ }
1417
+ }
1418
+ updateAll(config, skipUpdate = false) {
1419
+ this.boxes.forEach((box) => {
1420
+ this.updateBox(box, config, skipUpdate);
1421
+ });
1422
+ }
1423
+ remove(boxOrID, skipUpdate = false) {
1424
+ const index = this.getBoxIndex(boxOrID);
1425
+ if (index >= 0) {
1426
+ const boxes = this.boxes.slice();
1427
+ const deletedBoxes = boxes.splice(index, 1);
1428
+ this.boxes$.setValue(boxes);
1429
+ deletedBoxes.forEach((box) => box.destroy());
1430
+ if (!skipUpdate) {
1431
+ if (this.boxes.length <= 0) {
1432
+ this.setMaximized(false);
1433
+ this.setMinimized(false);
1434
+ }
1435
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
1436
+ }
1437
+ return deletedBoxes[0];
1438
+ }
1439
+ return;
1440
+ }
1441
+ removeTopBox() {
1442
+ if (this.topBox) {
1443
+ return this.remove(this.topBox);
1444
+ }
1445
+ return;
1446
+ }
1447
+ removeAll(skipUpdate = false) {
1448
+ const deletedBoxes = this.boxes$.value;
1449
+ this.boxes$.setValue([]);
1450
+ deletedBoxes.forEach((box) => box.destroy());
1451
+ if (!skipUpdate) {
1452
+ if (this.boxes.length <= 0) {
1453
+ this.setMaximized(false);
1454
+ this.setMinimized(false);
1455
+ }
1456
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Removed, deletedBoxes);
1457
+ }
1458
+ return deletedBoxes;
1459
+ }
1460
+ setTheme(theme) {
1461
+ Object.keys(theme).forEach((key) => {
1462
+ var _a;
1463
+ this.$container.style.setProperty(`--tele-${key}`, (_a = theme[key]) != null ? _a : null);
1464
+ });
1465
+ }
1466
+ mount(root) {
1467
+ this._root$.setValue(root);
1468
+ }
1469
+ unmount() {
1470
+ this._root$.setValue(null);
1471
+ }
1472
+ destroy(skipUpdate = false) {
1473
+ this.events.clearListeners();
1474
+ this._sideEffect.flushAll();
1475
+ this.removeAll(skipUpdate);
1476
+ this.collector.destroy();
1477
+ this.titleBar.destroy();
1478
+ }
1479
+ wrapClassName(className) {
1480
+ return `${this.namespace}-${className}`;
1481
+ }
1482
+ focusBox(boxOrID, skipUpdate = false) {
1483
+ const targetBox = this.getBox(boxOrID);
1484
+ if (targetBox) {
1485
+ this.boxes.forEach((box) => {
1486
+ if (targetBox === box) {
1487
+ let focusChanged = false;
1488
+ if (!targetBox.focus) {
1489
+ focusChanged = true;
1490
+ targetBox._focus$.setValue(true, skipUpdate);
1491
+ }
1492
+ if (focusChanged && !skipUpdate) {
1493
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Focused, targetBox);
1494
+ }
1495
+ } else if (box.focus) {
1496
+ this.blurBox(box, skipUpdate);
1497
+ }
1498
+ });
1499
+ this.titleBar.focusBox(targetBox);
1500
+ }
1501
+ }
1502
+ focusTopBox() {
1503
+ if (this.topBox && !this.topBox.focus) {
1504
+ return this.focusBox(this.topBox);
1505
+ }
1506
+ }
1507
+ blurBox(boxOrID, skipUpdate = false) {
1508
+ const targetBox = this.getBox(boxOrID);
1509
+ if (targetBox) {
1510
+ if (targetBox.focus) {
1511
+ targetBox._focus$.setValue(false, skipUpdate);
1512
+ if (!skipUpdate) {
1513
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, targetBox);
1514
+ }
1515
+ }
1516
+ if (this.titleBar.focusedBox === targetBox) {
1517
+ this.titleBar.focusBox();
1518
+ }
1519
+ }
1520
+ }
1521
+ blurAll(skipUpdate = false) {
1522
+ this.boxes.forEach((box) => {
1523
+ if (box.focus) {
1524
+ box._focus$.setValue(false, skipUpdate);
1525
+ if (!skipUpdate) {
1526
+ this.events.emit(TELE_BOX_MANAGER_EVENT.Blurred, box);
1527
+ }
1528
+ }
1529
+ });
1530
+ if (this.titleBar.focusedBox) {
1531
+ this.titleBar.focusBox();
1532
+ }
1533
+ }
1534
+ teleBoxMatcher(config) {
1535
+ const keys = Object.keys(config);
1536
+ return (box) => keys.every((key) => config[key] === box[key]);
1537
+ }
1538
+ updateBox(box, config, skipUpdate = false) {
1539
+ var _a, _b, _c, _d, _e, _f;
1540
+ if (config.x != null || config.y != null) {
1541
+ box._intrinsicCoord$.setValue({
1542
+ x: (_a = config.x) != null ? _a : box.intrinsicX,
1543
+ y: (_b = config.y) != null ? _b : box.intrinsicY
1544
+ }, skipUpdate);
1545
+ }
1546
+ if (config.width != null || config.height != null) {
1547
+ box._intrinsicSize$.setValue({
1548
+ width: (_c = config.width) != null ? _c : box.intrinsicWidth,
1549
+ height: (_d = config.height) != null ? _d : box.intrinsicHeight
1550
+ }, skipUpdate);
1551
+ }
1552
+ if (config.title != null) {
1553
+ box._title$.setValue(config.title);
1554
+ }
1555
+ if (config.visible != null) {
1556
+ box._visible$.setValue(config.visible, skipUpdate);
1557
+ }
1558
+ if (config.resizable != null) {
1559
+ box._resizable$.setValue(config.resizable, skipUpdate);
1560
+ }
1561
+ if (config.draggable != null) {
1562
+ box._draggable$.setValue(config.draggable, skipUpdate);
1563
+ }
1564
+ if (config.boxRatio != null) {
1565
+ box._boxRatio$.setValue(config.boxRatio, skipUpdate);
1566
+ }
1567
+ if (config.zIndex != null) {
1568
+ box._zIndex$.setValue(config.zIndex, skipUpdate);
1569
+ }
1570
+ if (config.stageRatio !== void 0) {
1571
+ box.setStageRatio(config.stageRatio, skipUpdate);
1572
+ }
1573
+ if (config.content != null) {
1574
+ box.mountContent(config.content);
1575
+ }
1576
+ if (config.footer != null) {
1577
+ box.mountFooter(config.footer);
1578
+ }
1579
+ if (config.minHeight != null || config.minWidth != null) {
1580
+ box._minSize$.setValue({
1581
+ width: (_e = config.minWidth) != null ? _e : box.minWidth,
1582
+ height: (_f = config.minHeight) != null ? _f : box.minHeight
1583
+ }, skipUpdate);
1584
+ }
1585
+ }
1586
+ smartPosition(rect) {
1587
+ let { x, y } = rect;
1588
+ const { width = 0.5, height = 0.5 } = rect;
1589
+ const stageRect = this.stageRect;
1590
+ const topBox = this.topBox;
1591
+ if (x == null) {
1592
+ let pxX = 20;
1593
+ if (topBox) {
1594
+ const pxPreferredX = topBox.pxIntrinsicCoord.x + 20;
1595
+ const pxIntrinsicWidth = width * stageRect.width;
1596
+ if (pxPreferredX + pxIntrinsicWidth <= stageRect.width) {
1597
+ pxX = pxPreferredX;
1598
+ }
1599
+ }
1600
+ x = pxX / stageRect.width;
1601
+ }
1602
+ if (y == null) {
1603
+ let pxY = 20;
1604
+ if (topBox) {
1605
+ const pxPreferredY = topBox.pxIntrinsicCoord.y + 20;
1606
+ const pxIntrinsicHeight = height * stageRect.height;
1607
+ if (pxPreferredY + pxIntrinsicHeight <= stageRect.height) {
1608
+ pxY = pxPreferredY;
1609
+ }
1610
+ }
1611
+ y = pxY / stageRect.height;
1612
+ }
1613
+ return { x, y, width, height };
1614
+ }
1615
+ makeBoxTop(box, skipUpdate = false) {
1616
+ if (this.topBox) {
1617
+ if (box !== this.topBox) {
1618
+ box._zIndex$.setValue(this.topBox.zIndex + 1, skipUpdate);
1619
+ }
1620
+ }
1621
+ }
1622
+ getBoxIndex(boxOrID) {
1623
+ return typeof boxOrID === "string" ? this.boxes.findIndex((box) => box.id === boxOrID) : this.boxes.findIndex((box) => box === boxOrID);
1624
+ }
1625
+ getBox(boxOrID) {
1626
+ return typeof boxOrID === "string" ? this.boxes.find((box) => box.id === boxOrID) : boxOrID;
1627
+ }
1628
+ }
1629
+ 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
1630
  //# sourceMappingURL=telebox-insider.es.js.map