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