@netless/window-manager 0.4.0-canary.15 → 0.4.0-canary.16

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/index.es.js CHANGED
@@ -1,2 +1,3845 @@
1
- var e,t,i=Object.defineProperty,s=Object.defineProperties,a=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,h=(e,t,s)=>t in e?i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,c=(e,t)=>{for(var i in t||(t={}))n.call(t,i)&&h(e,i,t[i]);if(r)for(var i of r(t))o.call(t,i)&&h(e,i,t[i]);return e},d=(e,t)=>s(e,a(t));import l from"emittery";import p from"p-retry";import{ResizeObserver as g}from"@juggle/resize-observer";import{debounce as u,isObject as M,has as m,get as w,size as I,mapValues as A,noop as x,pick as C,isEqual as y,isEmpty as b,isInteger as v,sortBy as S,maxBy as N,omit as D,compact as f,uniq as j,isFunction as T,isNull as E}from"lodash";import{TELE_BOX_MANAGER_EVENT as L,TELE_BOX_STATE as z,TeleBoxManager as P,TeleBoxCollector as B}from"@netless/telebox-insider";import{UpdateEventKind as V,listenUpdated as U,unlistenUpdated as k,reaction as O,autorun as R,toJS as Z,listenDisposed as Q,unlistenDisposed as G,AnimationMode as W,isPlayer as Y,isRoom as F,ScenePathType as H,ApplianceNames as X,RoomPhase as J,InvisiblePlugin as K,ViewMode as _,WhiteVersion as q}from"white-web-sdk";import{v4 as $}from"uuid";import{genUID as ee,SideEffectManager as te}from"side-effect-manager";import ie from"@netless/app-docs-viewer";import se,{setOptions as ae}from"@netless/app-media-player";(t=e||(e={})).AppMove="AppMove",t.AppFocus="AppFocus",t.AppResize="AppResize",t.AppBoxStateChange="AppBoxStateChange",t.GetAttributes="GetAttributes",t.UpdateWindowManagerWrapper="UpdateWindowManagerWrapper",t.InitReplay="InitReplay",t.WindowCreated="WindowCreated",t.SetMainViewScenePath="SetMainViewScenePath",t.SetMainViewSceneIndex="SetMainViewSceneIndex",t.SwitchViewsToFreedom="SwitchViewsToFreedom",t.MoveCameraToContain="MoveCameraToContain";var re,ne,oe,he,ce,de,le;(ne=re||(re={})).Size="size",ne.Position="position",ne.SceneIndex="SceneIndex",ne.ZIndex="zIndex",(he=oe||(oe={})).setBoxSize="setBoxSize",he.setBoxMinSize="setBoxMinSize",he.destroy="destroy",(ce||(ce={})).StartCreate="StartCreate",(le=de||(de={})).Leave="leave",le.Normal="normal";const pe=340/720,ge=340/720;let ue,Me;const me=async()=>{ue=await new Promise(((e,t)=>{const i=indexedDB.open("__WindowManagerAppCache",2);i.onerror=e=>{t(e)},i.onupgradeneeded=e=>{const t=e.target.result;t.objectStoreNames.contains("apps")||(Me=t.createObjectStore("apps",{keyPath:"kind"}),Me.createIndex("kind","kind",{unique:!0}))},i.onsuccess=()=>{const t=i.result;e(t)}}))},we=(e,t)=>{var i,s;if(ue)return i=ue,s={kind:e,sourceCode:t},new Promise(((e,t)=>{const a=i.transaction(["apps"],"readwrite").objectStore("apps").add(s);a.onsuccess=()=>e(),a.onerror=()=>t()}))},Ie=async e=>{return ue?await(t=ue,i=e,new Promise(((e,s)=>{const a=t.transaction(["apps"]).objectStore("apps").index("kind").get(i);a.onerror=e=>s(e),a.onsuccess=()=>{a.result?e(a.result):e(null)}}))):null;var t,i};const Ae=async e=>{const t=await Ie(e);if(t)return t;{const t=await async function(e,t){const{timeout:i=1e4}=t,s=new AbortController,a=setTimeout((()=>s.abort()),i),r=await fetch(e,d(c({},t),{signal:s.signal,headers:{"content-type":"text/plain"}}));return clearTimeout(a),r}(e,{timeout:1e4}),i=await t.text();return await we(e,i),i}},xe=(e,t)=>{let i=Function(e+`;return ${t}`)();return void 0===i&&(i=window[t]),i};const Ce=new class{constructor(){this.kindEmitters=new Map,this.registered=new Map,this.appClassesCache=new Map,this.appClasses=new Map}async register(e){this.registered.set(e.kind,e);const t=e.src;let i;if(i="string"==typeof t?async()=>{const i=await(async(e,t,i)=>{const s=i||"NetlessApp"+t,a=await Ae(e);try{return xe(a,s)}catch(r){if(r.message.includes("Can only have one anonymous define call per script file")){const e=window.define;return"function"==typeof e&&e.amd&&delete e.amd,xe(a,s)}}})(t,e.kind);if(i)return i;throw new Error(`[WindowManager]: load remote script failed, ${t}`)}:"function"==typeof t?t:async()=>t,this.appClasses.set(e.kind,(async()=>{let t=this.appClassesCache.get(e.kind);return t||(t=i(),this.appClassesCache.set(e.kind,t)),t})),e.addHooks){const t=this.createKindEmitter(e.kind);t&&e.addHooks(t)}}async notifyApp(e,t,i){const s=this.kindEmitters.get(e);await(null==s?void 0:s.emit(t,i))}createKindEmitter(e){if(!this.kindEmitters.has(e)){const t=new l;this.kindEmitters.set(e,t)}return this.kindEmitters.get(e)}},ye=(e,t)=>{if(e.focusScenePath!==t)return e.focusScenePath=t,e},be=(e,t)=>{e&&e.isWritable&&e.state.sceneState.scenePath!==t&&e.setScenePath(t)};u(((e,t)=>{e.emit("mainViewModeChange",t)}),200);const ve=(e,t,i=0)=>{const s=Se(e)[t];if(!s)return;const a=s[i];if(!a)return;const r=a.name;return"/"===t?`/${r}`:`${t}/${r}`},Se=e=>e.entireScenes(),Ne=e=>{const t=e.split("/");t.pop();let i=t.join("/");return""===i&&(i="/"),i},De=e=>{const t=e.split(".").map((e=>e.padStart(2,"0"))).join("");return parseInt(t)},fe=e=>new Promise((t=>setTimeout(t,e)));class je{constructor(t){this.manager=t,this.displayer=this.manager.displayer,this.mainMagixEventListener=t=>{if(t.authorId!==this.displayer.observerId){const i=t.payload;switch(i.eventName){case e.AppMove:this.appMoveHandler(i.payload);break;case e.AppResize:this.appResizeHandler(i.payload);break;case e.AppBoxStateChange:this.boxStateChangeHandler(i.payload);break;case e.SetMainViewScenePath:this.setMainViewScenePathHandler(i.payload);break;case e.MoveCameraToContain:this.moveCameraToContainHandler(i.payload)}}},this.appMoveHandler=e=>{var t;null==(t=this.boxManager)||t.moveBox(e)},this.appResizeHandler=e=>{var t,i;null==(t=this.boxManager)||t.resizeBox(Object.assign(e,{skipUpdate:!0})),null==(i=this.manager.room)||i.refreshViewSize()},this.boxStateChangeHandler=e=>{qt.emit("boxStateChange",e)},this.setMainViewScenePathHandler=({nextScenePath:e})=>{ye(this.manager.mainView,e),qt.emit("mainViewScenePathChange",e)},this.moveCameraToContainHandler=e=>{this.manager.mainView.moveCameraToContain(e)}}get boxManager(){return this.manager.boxManager}addListeners(){this.displayer.addMagixEventListener("__WindowManger",this.mainMagixEventListener)}removeListeners(){this.displayer.removeMagixEventListener("__WindowManger",this.mainMagixEventListener)}}class Te extends Error{constructor(){super(...arguments),this.message="[WindowManager]: app duplicate exists and cannot be created again"}}class Ee extends Error{constructor(){super(...arguments),this.message="[WindowManager]: AppManager must be initialized"}}class Le extends Error{constructor(e){super(`[WindowManager]: white-web-sdk version must large than ${e}`)}}class ze extends Error{constructor(){super(...arguments),this.message="[WindowManager]: kind must be a valid string"}}class Pe extends Error{constructor(){super(...arguments),this.message="[WindowManager]: box need created"}}class Be extends Error{constructor(){super(...arguments),this.message='[WindowManager]: ScenePath should start with "/"'}}class Ve extends Error{constructor(){super(...arguments),this.message="[WindowManager]: boxManager not found"}}const Ue=e=>(t,i)=>{if(void 0!==t){if(U){const s=t=>{t.map((e=>e.kind)).includes(e)&&i()};return U(t,s),i(),()=>k(t,s)}return O((()=>t),(()=>{i()}),{fireImmediately:!0})}},ke=(e,t,i)=>{let s=null;const a=O(e,(()=>{s&&(s(),s=null);const a=e();M(a)?(s=()=>k(a,t),U(a,t)):null==i||i(a)}),{fireImmediately:!0});return()=>{null==s||s(),a()}},Oe=Ue(V.Removed),Re=Ue(V.Inserted),Ze=Object.keys;function Qe(e){return Boolean(m(e,"__isRef"))}class Ge{constructor(){this.listeners=new Set}get length(){return this.listeners.size}dispatch(e){this.listeners.forEach((t=>t(e)))}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}}const We="_WM-STORAGE_";class Ye{constructor(e,t,i){if(this._sideEffect=new te,this._destroyed=!1,this._refMap=new WeakMap,this._lastValue=new Map,this.onStateChanged=new Ge,i&&!M(i))throw new Error(`Default state for Storage ${t} is not an object.`);this._context=e,this.id=t||null,this._state={};const s=this._getRawState(this._state);null!==this.id&&this._context.getIsWritable()&&(s!==this._state&&M(s)||(w(this._context.getAttributes(),[We])||this._context.updateAttributes([We],{}),this._context.updateAttributes([We,this.id],this._state)),i&&this.setState(i)),Ze(s).forEach((e=>{if(null!==this.id||e!==We)try{const t=M(s[e])?JSON.parse(JSON.stringify(s[e])):s[e];Qe(t)?(this._state[e]=t.v,M(t.v)&&this._refMap.set(t.v,t)):this._state[e]=t}catch(t){console.error(t)}})),this._sideEffect.addDisposer(ke((()=>null===this.id?e.getAttributes():w(e.getAttributes(),[We,this.id])),this._updateProperties.bind(this),this.destroy.bind(this)))}get state(){return this._destroyed&&console.warn(`Accessing state on destroyed Storage "${this.id}"`),this._state}addStateChangedListener(e){return this.onStateChanged.addListener(e),()=>this.onStateChanged.removeListener(e)}ensureState(e){return this.setState(Ze(e).reduce(((t,i)=>(m(this._state,i)||(t[i]=e[i]),t)),{}))}setState(e){if(this._destroyed)return void console.error(new Error(`Cannot call setState on destroyed Storage "${this.id}".`));if(!this._context.getIsWritable())return void console.error(new Error(`Cannot setState on Storage "${this.id}" without writable access`),e);const t=Ze(e);t.length>0&&t.forEach((t=>{const i=e[t];var s;if(i!==this._state[t])if(void 0===i)this._lastValue.set(t,this._state[t]),delete this._state[t],this._setRawState(t,i);else{this._lastValue.set(t,this._state[t]),this._state[t]=i;let e=i;if(M(i)){let t=this._refMap.get(i);t||(s=i,t={k:ee(),v:s,__isRef:!0},this._refMap.set(i,t)),e=t}this._setRawState(t,e)}}))}emptyStorage(){I(this._state)<=0||(this._destroyed?console.error(new Error(`Cannot empty destroyed Storage "${this.id}".`)):this._context.getIsWritable()?this.setState(A(this._state,x)):console.error(new Error(`Cannot empty Storage "${this.id}" without writable access.`)))}deleteStorage(){if(null===this.id)throw new Error("Cannot delete main Storage");this._context.getIsWritable()?(this.destroy(),this._context.updateAttributes([We,this.id],void 0)):console.error(new Error(`Cannot delete Storage "${this.id}" without writable access.`))}get destroyed(){return this._destroyed}destroy(){this._destroyed=!0,this._sideEffect.flushAll()}_getRawState(e){return null===this.id?w(this._context.getAttributes(),[],e):w(this._context.getAttributes(),[We,this.id],e)}_setRawState(e,t){if(null===this.id){if(e===We)throw new Error('Cannot set attribute internal filed "_WM-STORAGE_"');return this._context.updateAttributes([e],t)}return this._context.updateAttributes([We,this.id,e],t)}_updateProperties(e){var t;if(this._destroyed)console.error(new Error(`Cannot call _updateProperties on destroyed Storage "${this.id}".`));else if(e.length>0){const s={};for(let a=0;a<e.length;a++)try{const i=e[a],r=i.key;if(null===this.id&&r===We)continue;const n=M(i.value)?JSON.parse(JSON.stringify(i.value)):i.value;let o;switch(this._lastValue.has(r)&&(o=this._lastValue.get(r),this._lastValue.delete(r)),i.kind){case 2:m(this._state,r)&&(o=this._state[r],delete this._state[r]),s[r]={oldValue:o};break;default:{let e=n;if(Qe(n)){const{k:i,v:s}=n,a=this._state[r];M(a)&&(null==(t=this._refMap.get(a))?void 0:t.k)===i?e=a:(e=s,M(s)&&this._refMap.set(s,n))}e!==this._state[r]&&(o=this._state[r],this._state[r]=e),s[r]={newValue:e,oldValue:o};break}}}catch(i){console.error(i)}this.onStateChanged.dispatch(s)}}}class Fe{constructor(e,t,i,s,a){this.manager=e,this.boxManager=t,this.appId=i,this.appProxy=s,this.appOptions=a,this.mobxUtils={autorun:R,reaction:O,toJS:Z},this.objectUtils={listenUpdated:U,unlistenUpdated:k,listenDisposed:Q,unlistenDisposed:G},this.store=this.manager.store,this.isReplay=this.manager.isReplay,this.getDisplayer=()=>this.manager.displayer,this.getAttributes=()=>this.appProxy.attributes,this.getScenes=()=>{const e=this.store.getAppAttributes(this.appId);if(!(null==e?void 0:e.isDynamicPPT))return null==e?void 0:e.options.scenes;{const e=this.manager.appProxies.get(this.appId);if(e)return e.scenes}},this.getView=()=>this.appProxy.view,this.getInitScenePath=()=>this.manager.getAppInitPath(this.appId),this.getIsWritable=()=>this.manager.canOperate,this.getBox=()=>{const e=this.boxManager.getBox(this.appId);if(e)return e;throw new Pe},this.getRoom=()=>this.manager.room,this.setAttributes=e=>{this.manager.safeSetAttributes({[this.appId]:e})},this.updateAttributes=(e,t)=>{this.manager.attributes[this.appId]&&this.manager.safeUpdateAttributes([this.appId,...e],t)},this.setScenePath=async e=>{var t;this.appProxy.box&&(this.appProxy.setFullPath(e),null==(t=this.getRoom())||t.setScenePath(e))},this.mountView=e=>{const t=this.getView();t&&(t.divElement=e,setTimeout((()=>{var e;null==(e=this.getRoom())||e.refreshViewSize()}),1e3))},this.getAppOptions=()=>"function"==typeof this.appOptions?this.appOptions():this.appOptions,this.createStorage=(e,t)=>{const i=new Ye(this,e,t);return this.emitter.on("destroy",(()=>{i.destroy()})),i},this.dispatchMagixEvent=this.manager.displayer.dispatchMagixEvent.bind(this.manager.displayer),this.addMagixEventListener=(e,t,i)=>(this.manager.displayer.addMagixEventListener(e,t,i),()=>this.manager.displayer.removeMagixEventListener(e,t)),this.removeMagixEventListener=this.manager.displayer.removeMagixEventListener.bind(this.manager.displayer),this.emitter=s.appEmitter,this.isAddApp=s.isAddApp}get storage(){return this._storage||(this._storage=new Ye(this)),this._storage}}var He,Xe;(Xe=He||(He={})).Apps="apps",Xe.Focus="focus",Xe.State="state",Xe.BoxState="boxState",Xe.MainViewCamera="mainViewCamera",Xe.MainViewSize="mainViewSize",Xe.Broadcaster="broadcaster",Xe.Cursors="cursors",Xe.Position="position",Xe.CursorState="cursorState",Xe.FullPath="fullPath";const Je=new class{constructor(e){this.context=e}setContext(e){this.context=e}get attributes(){return this.context.getAttributes()}apps(){return w(this.attributes,[He.Apps])}get focus(){return w(this.attributes,[He.Focus])}getAppAttributes(e){return w(this.apps(),[e])}getAppState(e){return w(this.apps(),[e,He.State])}getMaximized(){return w(this.attributes,["maximized"])}getMinimized(){return w(this.attributes,["minimized"])}setupAppAttributes(e,t,i){this.attributes.apps||this.context.safeSetAttributes({apps:{}});const s=["scenePath","title"];i||s.push("scenes");const a=C(e.options,s),r={kind:e.kind,options:a,isDynamicPPT:i};"string"==typeof e.src&&(r.src=e.src),r.createdAt=Date.now(),this.context.safeUpdateAttributes([He.Apps,t],r),this.context.safeUpdateAttributes([He.Apps,t,He.State],{[re.Size]:{},[re.Position]:{},[re.SceneIndex]:0})}updateAppState(e,t,i){w(this.attributes,[He.Apps,e,He.State])&&this.context.safeUpdateAttributes([He.Apps,e,He.State,t],i)}cleanAppAttributes(e){this.context.safeUpdateAttributes([He.Apps,e],void 0),this.context.safeSetAttributes({[e]:void 0});this.attributes[He.Focus]===e&&this.cleanFocus()}cleanFocus(){this.context.safeSetAttributes({[He.Focus]:void 0})}getAppSceneIndex(e){var t;return null==(t=this.getAppState(e))?void 0:t[re.SceneIndex]}getAppScenePath(e){var t,i;return null==(i=null==(t=this.getAppAttributes(e))?void 0:t.options)?void 0:i.scenePath}getMainViewScenePath(){return this.attributes._mainScenePath}getMainViewSceneIndex(){return this.attributes._mainSceneIndex}getBoxState(){return this.attributes[He.BoxState]}setMainViewScenePath(e){this.context.safeSetAttributes({_mainScenePath:e})}setMainViewSceneIndex(e){this.context.safeSetAttributes({_mainSceneIndex:e})}getMainViewCamera(){return w(this.attributes,[He.MainViewCamera])}getMainViewSize(){return w(this.attributes,[He.MainViewSize])}setMainViewCamera(e){this.context.safeSetAttributes({[He.MainViewCamera]:c({},e)})}setMainViewSize(e){this.context.safeSetAttributes({[He.MainViewSize]:c({},e)})}setAppFocus(e,t){t?this.context.safeSetAttributes({[He.Focus]:e}):this.context.safeSetAttributes({[He.Focus]:void 0})}updateCursor(e,t){w(this.attributes,[He.Cursors])||this.context.safeUpdateAttributes([He.Cursors],{}),w(this.attributes,[He.Cursors,e])||this.context.safeUpdateAttributes([He.Cursors,e],{}),this.context.safeUpdateAttributes([He.Cursors,e,He.Position],t)}updateCursorState(e,t){w(this.attributes,[He.Cursors,e])||this.context.safeUpdateAttributes([He.Cursors,e],{}),this.context.safeUpdateAttributes([He.Cursors,e,He.CursorState],t)}getCursorState(e){return w(this.attributes,[He.Cursors,e,He.CursorState])}cleanCursor(e){this.context.safeUpdateAttributes([He.Cursors,e],void 0)}setMainViewFocusPath(e){const t=this.getMainViewScenePath();t&&ye(e,t)}}({getAttributes:()=>{throw new Error("getAttributes not implemented")},safeSetAttributes:()=>{throw new Error("safeSetAttributes not implemented")},safeUpdateAttributes:()=>{throw new Error("safeUpdateAttributes not implemented")}}),Ke=(...e)=>{ti.debug&&console.log("[WindowManager]:",...e)};class _e{constructor(e){this.manager=e,this.findMember=e=>{var t;const i=null==(t=this.manager.room)?void 0:t.state.roomMembers;return null==i?void 0:i.find((t=>t.memberId===e))},this.findMemberByUid=e=>{var t;const i=null==(t=this.manager.room)?void 0:t.state.roomMembers;return null==i?void 0:i.find((t=>{var i;return(null==(i=t.payload)?void 0:i.uid)===e}))},this.observerId=e.displayer.observerId,_t.on("observerIdChange",(e=>{this.observerId=e}))}get uid(){var e;return(null==(e=this.manager.room)?void 0:e.uid)||""}updateManagerRect(){var e;null==(e=this.manager.boxManager)||e.updateManagerRect()}blurFocusBox(){var e;null==(e=this.manager.boxManager)||e.blurAllBox()}}let qe;class $e{constructor(e){this.manager=e,this.store=Je,this.context=(e=>(qe||(qe=new _e(e)),qe))(this.manager)}}class et extends $e{constructor(e,t,i,s){var a;super(t),this.params=e,this.boxManager=this.manager.boxManager,this.appProxies=this.manager.appProxies,this.viewManager=this.manager.viewManager,this.status="normal",this.getAppInitState=e=>{var t,i;const s=this.store.getAppState(e);if(!s)return;const a=null==s?void 0:s[re.Position],r=this.store.focus,n=null==s?void 0:s[re.Size],o=null==s?void 0:s[re.SceneIndex];let h={maximized:null==(t=this.attributes)?void 0:t.maximized,minimized:null==(i=this.attributes)?void 0:i.minimized,zIndex:null==s?void 0:s.zIndex};return a&&(h=d(c({},h),{id:e,x:a.x,y:a.y})),r===e&&(h=d(c({},h),{focus:!0})),n&&(h=d(c({},h),{width:n.width,height:n.height})),o&&(h=d(c({},h),{sceneIndex:o})),h},this.appAttributesUpdateListener=e=>{var t,i,s;null==(t=this.manager.refresher)||t.add(e,(()=>R((()=>{const t=this.manager.attributes[e];t&&this.appEmitter.emit("attributesUpdate",t)})))),null==(i=this.manager.refresher)||i.add(this.stateKey,(()=>R((()=>{var t,i,s;const a=null==(t=this.appAttributes)?void 0:t.state;(null==a?void 0:a.zIndex)>0&&a.zIndex!==(null==(i=this.box)?void 0:i.zIndex)&&(null==(s=this.boxManager)||s.setZIndex(e,a.zIndex))})))),null==(s=this.manager.refresher)||s.add(`${e}-fullPath`,(()=>R((()=>{var e;const t=null==(e=this.appAttributes)?void 0:e.fullPath;this.setFocusScenePathHandler(t)}))))},this.setFocusScenePathHandler=u((e=>{var t;this.view&&e&&e!==(null==(t=this.view)?void 0:t.focusScenePath)&&ye(this.view,e)}),50),this.kind=e.kind,this.id=i,this.stateKey=`${this.id}_state`,this.appProxies.set(this.id,this),this.appEmitter=new l,this.appListener=this.makeAppEventListener(this.id),this.isAddApp=s,this.initScenes(),(null==(a=this.params.options)?void 0:a.scenePath)&&this.createView()}initScenes(){var e;const t=this.params.options;t&&(this.scenePath=t.scenePath,(null==(e=this.appAttributes)?void 0:e.isDynamicPPT)&&this.scenePath?this.scenes=this.manager.displayer.entireScenes()[this.scenePath]:this.scenes=t.scenes)}get view(){return this.manager.viewManager.getView(this.id)}get isWritable(){var e;return this.manager.canOperate&&!(null==(e=this.box)?void 0:e.readonly)}get attributes(){return this.manager.attributes[this.id]}get appAttributes(){return this.store.getAppAttributes(this.id)}getFullScenePath(){if(this.scenePath)return w(this.appAttributes,[He.FullPath],this.getFullScenePathFromScenes())}getFullScenePathFromScenes(){const e=w(this.appAttributes,["state","SceneIndex"],0),t=((e,t,i)=>{var s;if(e&&t){const a=null==(s=Se(e)[t])?void 0:s[i];if(a)return`${t}/${a.name}`}})(this.manager.room,this.scenePath,e);return t&&this.setFullPath(t),t}setFullPath(e){this.manager.safeUpdateAttributes(["apps",this.id,He.FullPath],e)}async baseInsertApp(e=!1){var t;const i=this.params;if(!i.kind)throw new Error("[WindowManager]: kind require");const s=await(null==(t=Ce.appClasses.get(i.kind))?void 0:t()),a=Ce.registered.get(i.kind);if(!s)throw new Error(`[WindowManager]: app load failed ${i.kind} ${i.src}`);return await this.setupApp(this.id,e,s,i.options,null==a?void 0:a.appOptions),this.context.updateManagerRect(),{appId:this.id,app:s}}focusApp(){this.focusBox(),this.store.setMainViewFocusPath(this.manager.mainView)}get box(){var e;return null==(e=this.boxManager)?void 0:e.getBox(this.id)}focusBox(){var e;null==(e=this.boxManager)||e.focusBox({appId:this.id})}async setupApp(t,i,s,a,r){var n;if(Ke("setupApp",t,s,a),!this.boxManager)throw new Ve;const o=new Fe(this.manager,this.boxManager,t,this,r);this.appContext=o;try{_t.once(`${t}${e.WindowCreated}`).then((async()=>{var e;let a;i||(a=this.getAppInitState(t),null==(e=this.boxManager)||e.updateBoxState(a)),this.appEmitter.onAny(this.appListener),this.appAttributesUpdateListener(t),this.setViewFocusScenePath(),setTimeout((async()=>{const e=await s.setup(o);this.appResult=e,Ce.notifyApp(s.kind,"created",{appId:t,result:e}),this.afterSetupApp(a),this.fixMobileSize()}),50)})),null==(n=this.boxManager)||n.createBox({appId:t,app:s,options:a,canOperate:this.manager.canOperate,smartPosition:this.isAddApp})}catch(h){throw console.error(h),new Error(`[WindowManager]: app setup error: ${h.message}`)}}fixMobileSize(){var e,t;const i=null==(e=this.boxManager)?void 0:e.getBox(this.id);i&&(null==(t=this.boxManager)||t.resizeBox({appId:this.id,width:i.intrinsicWidth+.001,height:i.intrinsicHeight+.001,skipUpdate:!0}))}afterSetupApp(e){var t;e&&((null==e?void 0:e.x)&&e.y||null==(t=this.boxManager)||t.setBoxInitState(this.id))}onSeek(e){var t;this.appEmitter.emit("seek",e);const i=this.getAppInitState(this.id);null==(t=this.boxManager)||t.updateBoxState(i)}async onReconnected(){var e;this.appEmitter.emit("reconnected",void 0);const t=this.getAppInitState(this.id);await this.destroy(!0,!1,!0);const i=this.params,s=new et(i,this.manager,this.id,this.isAddApp);await s.baseInsertApp(!0),null==(e=this.boxManager)||e.updateBoxState(t)}emitAppSceneStateChange(e){this.appEmitter.emit("sceneStateChange",e)}emitAppIsWritableChange(){this.appEmitter.emit("writableChange",this.isWritable)}makeAppEventListener(e){return(t,i)=>{var s,a,r,n;if(this.manager.canOperate)switch(t){case"setBoxSize":null==(s=this.boxManager)||s.resizeBox({appId:e,width:i.width,height:i.height,skipUpdate:!1});break;case"setBoxMinSize":null==(a=this.boxManager)||a.setBoxMinSize({appId:e,minWidth:i.minwidth,minHeight:i.minheight});break;case"setBoxTitle":null==(r=this.boxManager)||r.setBoxTitle({appId:e,title:i.title});break;case oe.destroy:if("destroyed"===this.status)return;this.destroy(!0,!1,!0,null==i?void 0:i.error),(null==i?void 0:i.error)&&console.error(null==i?void 0:i.error);break;case"focus":null==(n=this.boxManager)||n.focusBox({appId:this.id}),_t.emit("focus",{appId:this.id})}}}setScenePath(){if(!this.manager.canOperate)return;const e=this.getFullScenePath();this.manager.room&&e&&this.view&&be(this.manager.room,e)}setViewFocusScenePath(){const e=this.getFullScenePath();e&&this.view&&ye(this.view,e)}async createView(){const e=await this.viewManager.createView(this.id);return this.setViewFocusScenePath(),e}async destroy(e,t,i,s){var a,r,n,o;"destroyed"!==this.status&&(this.status="destroyed",await Ce.notifyApp(this.kind,"destroy",{appId:this.id}),await this.appEmitter.emit("destroy",{error:s}),this.appEmitter.clearListeners(),_t.emit(`destroy-${this.id}`,{error:s}),e&&(null==(a=this.boxManager)||a.closeBox(this.id,i)),t&&this.store.cleanAppAttributes(this.id),this.appProxies.delete(this.id),this.viewManager.destroyView(this.id),this.manager.appStatus.delete(this.id),null==(r=this.manager.refresher)||r.remove(this.id),null==(n=this.manager.refresher)||n.remove(this.stateKey),null==(o=this.manager.refresher)||o.remove(`${this.id}-fullPath`))}close(){return this.destroy(!0,!0,!1)}}class tt{constructor(e){this.displayer=e,this.views=new Map}createView(e){const t=it(this.displayer);return this.views.set(e,t),t}getView(e){return this.views.get(e)}destroyView(e){const t=this.views.get(e);t&&(t.release(),this.views.delete(e))}setViewScenePath(e,t){const i=this.views.get(e);i&&(i.focusScenePath=t)}destroy(){this.views.forEach((e=>{e.release()})),this.views.clear()}}const it=e=>{const t=e.views.createView();return st(t),t},st=e=>{e.setCameraBound({maxContentMode:()=>10,minContentMode:()=>.1})};class at extends $e{constructor(e){super(e),this.started=!1,this.mainViewIsAddListener=!1,this.viewId="mainView",this.sideEffectManager=new te,this.cameraReaction=()=>O((()=>this.mainViewCamera),(e=>{e&&e.id!==this.context.uid&&(this.moveCameraToContian(this.mainViewSize),this.moveCamera(e))}),{fireImmediately:!0}),this.sizeChangeHandler=u((e=>{e&&(this.moveCameraToContian(e),this.moveCamera(this.mainViewCamera))}),30),this.onCameraUpdatedByDevice=e=>{this.store.setMainViewCamera(d(c({},e),{id:this.context.uid})),y(this.mainViewSize,d(c({},this.mainView.size),{id:this.context.uid}))||this.setMainViewSize(this.view.size)},this.mainViewClickListener=()=>{this.mainViewClickHandler()},this.setMainViewSize=u((e=>{this.store.setMainViewSize(d(c({},e),{id:this.context.uid}))}),50),this.onCameraOrSizeUpdated=()=>{qt.emit("cameraStateChange",this.cameraState)},this.mainView=this.createMainView(),this.moveCameraSizeByAttributes(),_t.once("mainViewMounted").then((()=>{this.addMainViewListener(),setTimeout((()=>{this.start(),this.mainViewCamera&&this.mainViewSize||this.setCameraAndSize()}),200)}));const t=()=>{this.sizeChangeHandler(this.mainViewSize)};this.sideEffectManager.add((()=>(_t.on("playgroundSizeChange",t),()=>_t.off("playgroundSizeChange",t))))}get mainViewCamera(){return this.store.getMainViewCamera()}get mainViewSize(){return this.store.getMainViewSize()}moveCameraSizeByAttributes(){this.moveCameraToContian(this.mainViewSize),this.moveCamera(this.mainViewCamera)}start(){var e;this.started||(this.sizeChangeHandler(this.mainViewSize),this.addCameraListener(),null==(e=this.manager.refresher)||e.add(He.MainViewCamera,this.cameraReaction),this.started=!0)}setCameraAndSize(){this.store.setMainViewCamera(d(c({},this.mainView.camera),{id:this.context.uid})),this.store.setMainViewSize(d(c({},this.mainView.size),{id:this.context.uid}))}get view(){return this.mainView}get cameraState(){return c(c({},this.view.camera),this.view.size)}createMainView(){const e=it(this.manager.displayer),t=this.store.getMainViewScenePath();return t&&ye(e,t),e}addMainViewListener(){this.mainViewIsAddListener||this.view.divElement&&(this.view.divElement.addEventListener("click",this.mainViewClickListener),this.view.divElement.addEventListener("touchend",this.mainViewClickListener),this.mainViewIsAddListener=!0)}removeMainViewListener(){this.view.divElement&&(this.view.divElement.removeEventListener("click",this.mainViewClickListener),this.view.divElement.removeEventListener("touchend",this.mainViewClickListener))}async mainViewClickHandler(){this.manager.canOperate&&(this.store.cleanFocus(),this.context.blurFocusBox())}addCameraListener(){this.view.callbacks.on("onCameraUpdatedByDevice",this.onCameraUpdatedByDevice),this.view.callbacks.on("onCameraUpdated",this.onCameraOrSizeUpdated),this.view.callbacks.on("onSizeUpdated",this.onCameraOrSizeUpdated)}removeCameraListener(){this.view.callbacks.off("onCameraUpdatedByDevice",this.onCameraUpdatedByDevice),this.view.callbacks.off("onCameraUpdated",this.onCameraOrSizeUpdated),this.view.callbacks.off("onSizeUpdated",this.onCameraOrSizeUpdated)}moveCameraToContian(e){b(e)||(this.view.moveCameraToContain({width:e.width,height:e.height,originX:-e.width/2,originY:-e.height/2,animationMode:W.Immediately}),this.scale=this.view.camera.scale)}moveCamera(e){if(!b(e)){if(y(e,this.view.camera))return;const{centerX:t,centerY:i,scale:s}=e,a=s*(this.scale||1);this.view.moveCamera({centerX:t,centerY:i,scale:a,animationMode:W.Immediately})}}stop(){var e,t;this.removeMainViewListener(),this.removeCameraListener(),null==(e=this.manager.refresher)||e.remove(He.MainViewCamera),null==(t=this.manager.refresher)||t.remove(He.MainViewSize),this.started=!1}destroy(){this.stop(),this.sideEffectManager.flushAll()}}class rt{constructor(t){this.windowManger=t,this.appProxies=new Map,this.appStatus=new Map,this.store=Je,this.isReplay=this.windowManger.isReplay,this.onAppDelete=e=>{const t=Object.keys(e);this.appProxies.forEach(((e,i)=>{t.includes(i)||e.destroy(!0,!1,!0)}))},this.displayerStateListener=e=>{var t,i;const s=e.sceneState;if(s){const e=s.scenePath;this.appProxies.forEach((t=>{t.scenePath&&e.startsWith(t.scenePath)&&(t.emitAppSceneStateChange(s),t.setFullPath(e))}))}e.roomMembers&&(null==(t=this.windowManger.cursorManager)||t.setRoomMembers(e.roomMembers),null==(i=this.windowManger.cursorManager)||i.cleanMemberAttributes(e.roomMembers)),this.appProxies.forEach((t=>{t.appEmitter.emit("roomStateChange",e)})),_t.emit("observerIdChange",this.displayer.observerId)},this.displayerWritableListener=e=>{var t,i;const s=!e,a=void 0===this.windowManger.readonly||!1===this.windowManger.readonly;void 0===this.windowManger.readonly?null==(t=this.boxManager)||t.setReadonly(e):null==(i=this.boxManager)||i.setReadonly(!(s&&a)),this.appProxies.forEach((e=>{e.emitAppIsWritableChange()})),!0===s?(this.mainView.disableCameraTransform=!1,this.room&&!0===this.room.disableSerialization&&(this.room.disableSerialization=!1)):this.mainView.disableCameraTransform=!0},this.updateSceneIndex=()=>{const e=this.store.getMainViewScenePath(),t=Ne(e),i=Se(this.displayer)[t];if(i.length){const s=e.replace(t,"").replace("/",""),a=i.findIndex((e=>e.name===s));console.log("updateSceneIndex",t,s,a),v(a)&&a>=0&&this.safeSetAttributes({_mainSceneIndex:a})}},this.boxEventListener=(t,i)=>{switch(t){case"move":this.dispatchInternalEvent(e.AppMove,i),this.store.updateAppState(i.appId,re.Position,{x:i.x,y:i.y});break;case"focus":this.windowManger.safeSetAttributes({focus:i.appId});break;case"resize":i.width&&i.height&&(this.dispatchInternalEvent(e.AppResize,i),this.store.updateAppState(i.appId,re.Size,{width:i.width,height:i.height}));break;case"close":{const e=this.appProxies.get(i.appId);e&&e.destroy(!1,!0,i.error);break}case"boxStateChange":this.dispatchInternalEvent(e.AppBoxStateChange,i)}},this.displayer=t.displayer,this.store.setContext({getAttributes:()=>this.attributes,safeSetAttributes:e=>this.safeSetAttributes(e),safeUpdateAttributes:(e,t)=>this.safeUpdateAttributes(e,t)}),this.mainViewProxy=new at(this),this.viewManager=new tt(this.displayer),this.appListeners=new je(this),this.displayer.callbacks.on(this.eventName,this.displayerStateListener),this.appListeners.addListeners(),this.refresher=$t,this.refresher.setRoom(this.room),this.refresher.setContext({emitter:_t}),_t.once("onCreated").then((()=>this.onCreated())),_t.on("onReconnected",(()=>this.onReconnected())),Y(this.displayer)&&_t.on("seek",(e=>{this.appProxies.forEach((t=>{t.onSeek(e)})),this.attributesUpdateCallback(this.attributes.apps),this.onAppDelete(this.attributes.apps)}))}async onCreated(){var e,t,i,s,a,r,n,o;if(await this.attributesUpdateCallback(this.attributes.apps),null==(e=this.boxManager)||e.updateManagerRect(),_t.onAny(this.boxEventListener),null==(t=this.refresher)||t.add("apps",(()=>ke((()=>this.attributes.apps),(()=>{this.attributesUpdateCallback(this.attributes.apps)})))),null==(i=this.refresher)||i.add("appsClose",(()=>Oe(this.attributes.apps,(()=>{this.onAppDelete(this.attributes.apps)})))),null==(s=this.refresher)||s.add("maximized",(()=>R((()=>{var e;const t=this.attributes.maximized;null==(e=this.boxManager)||e.setMaximized(Boolean(t))})))),null==(a=this.refresher)||a.add("minimized",(()=>R((()=>{var e,t;const i=this.attributes.minimized;(null==(e=this.boxManager)?void 0:e.minimized)!==i&&(!0===i&&(null==(t=this.boxManager)||t.blurAllBox()),setTimeout((()=>{var e;null==(e=this.boxManager)||e.setMinimized(Boolean(i))}),0))})))),null==(r=this.refresher)||r.add("mainViewIndex",(()=>R((()=>{const e=w(this.attributes,"_mainSceneIndex");void 0!==e&&this._prevSceneIndex!==e&&(qt.emit("mainViewSceneIndexChange",e),this._prevSceneIndex=e)})))),null==(n=this.refresher)||n.add("focusedChange",(()=>R((()=>{const e=w(this.attributes,"focus");this._prevFocused!==e&&(qt.emit("focusedChange",e),this._prevFocused=e)})))),!this.attributes.apps||0===Object.keys(this.attributes.apps).length){const e=this.store.getMainViewScenePath();if(!e)return;this.displayer.state.sceneState.scenePath!==e&&be(this.room,e)}this.displayerWritableListener(!(null==(o=this.room)?void 0:o.isWritable)),this.displayer.callbacks.on("onEnableWriteNowChanged",this.displayerWritableListener),this._prevFocused=this.attributes.focus}async attributesUpdateCallback(e){if(e&&ti.container){const t=Object.keys(e).map((t=>({id:t,createdAt:e[t].createdAt})));for(const{id:i}of S(t,"createdAt"))if(!this.appProxies.has(i)&&!this.appStatus.has(i)){const t=e[i];p((async()=>{this.appStatus.set(i,ce.StartCreate);if(!this.attributes[i])throw new Error("appAttributes is undefined");await this.baseInsertApp({kind:t.kind,options:t.options,isDynamicPPT:t.isDynamicPPT},i,!1),this.focusByAttributes(e)}),{retries:3}).catch((e=>{console.warn("[WindowManager]: Insert App Error",e),this.appStatus.delete(i)}))}}}refresh(){this.attributesUpdateCallback(this.attributes.apps)}setBoxManager(e){this.boxManager=e}resetMaximized(){var e;null==(e=this.boxManager)||e.setMaximized(Boolean(this.store.getMaximized()))}resetMinimized(){var e;null==(e=this.boxManager)||e.setMinimized(Boolean(this.store.getMinimized()))}bindMainView(e,t){const i=this.mainViewProxy.view;i.disableCameraTransform=t,i.divElement=e,i.focusScenePath||this.setMainViewFocusPath(),_t.emit("mainViewMounted")}setMainViewFocusPath(e){const t=e||this.store.getMainViewScenePath();if(t){const e=ye(this.mainView,t);return(null==e?void 0:e.focusScenePath)===t}}async addApp(e,t){Ke("addApp",e);const{appId:i,needFocus:s}=await this.beforeAddApp(e,t),a=await this.baseInsertApp(e,i,!0,s);return this.afterAddApp(a),null==a?void 0:a.id}async beforeAddApp(e,t){var i,s;const a=await(async e=>{var t,i;const s=await(null==(t=Ce.appClasses.get(e))?void 0:t());return s&&(null==(i=s.config)?void 0:i.singleton)?e:`${e}-${$().replace("-","").slice(0,8)}`})(e.kind);this.appStatus.set(a,ce.StartCreate);const r=null!=(i=e.attributes)?i:{};this.safeUpdateAttributes([a],r),this.store.setupAppAttributes(e,a,t);const n=!(null==(s=this.boxManager)?void 0:s.minimized);return n&&this.store.setAppFocus(a,!0),{appId:a,needFocus:n}}afterAddApp(e){var t,i;if(e&&e.box){const t=e.box;_t.emit("move",{appId:e.id,x:null==t?void 0:t.intrinsicX,y:null==t?void 0:t.intrinsicY}),this.store.updateAppState(e.id,re.ZIndex,t.zIndex)}(null==(t=this.boxManager)?void 0:t.minimized)&&(null==(i=this.boxManager)||i.setMinimized(!1,!1))}async closeApp(e){const t=this.appProxies.get(e);t&&t.destroy(!0,!0,!1)}async baseInsertApp(e,t,i,s){if(this.appProxies.has(t))return void console.warn("[WindowManager]: app duplicate exists and cannot be created again");const a=new et(e,this,t,i);if(a)return await a.baseInsertApp(s),this.appStatus.delete(t),a;throw this.appStatus.delete(t),new Error("[WindowManger]: initialize AppProxy failed")}get eventName(){return F(this.displayer)?"onRoomStateChanged":"onPlayerStateChanged"}get attributes(){return this.windowManger.attributes}get canOperate(){return this.windowManger.canOperate}get room(){return F(this.displayer)?this.displayer:void 0}get mainView(){return this.mainViewProxy.view}get focusApp(){if(this.store.focus)return this.appProxies.get(this.store.focus)}safeSetAttributes(e){this.windowManger.safeSetAttributes(e)}safeUpdateAttributes(e,t){this.windowManger.safeUpdateAttributes(e,t)}async setMainViewScenePath(e){if(this.room){const t=this.displayer.scenePathType(e);if(t===H.None)throw new Error(`[WindowManager]: ${e} not valid scene`);if(t===H.Page)await this._setMainViewScenePath(e);else if(t===H.Dir){const t=ve(this.displayer,e);t&&await this._setMainViewScenePath(t)}}}async _setMainViewScenePath(t){this.setMainViewFocusPath(t)&&(this.safeSetAttributes({_mainScenePath:t}),this.store.setMainViewFocusPath(this.mainView),this.updateSceneIndex(),this.dispatchInternalEvent(e.SetMainViewScenePath,{nextScenePath:t}))}async setMainViewSceneIndex(e){if(this.room){if(this.store.getMainViewSceneIndex()===e)return;const t=this.store.getMainViewScenePath();if(t){const i=Ne(t),s=ve(this.displayer,i,e);if(!s)throw new Error(`[WindowManager]: ${i}: ${e} not valid index`);this.setMainViewFocusPath(s)&&(this.store.setMainViewScenePath(s),this.safeSetAttributes({_mainSceneIndex:e}))}}}getAppInitPath(e){var t;const i=this.store.getAppAttributes(e);if(i)return null==(t=null==i?void 0:i.options)?void 0:t.scenePath}safeDispatchMagixEvent(e,t){this.canOperate&&this.displayer.dispatchMagixEvent(e,t)}focusByAttributes(e){var t;if(e&&Object.keys(e).length===(null==(t=this.boxManager)?void 0:t.boxSize)){const e=this.store.focus;e&&this.boxManager.focusBox({appId:e})}}async onReconnected(){const e=Array.from(this.appProxies.values()).map((e=>e.onReconnected()));await Promise.all(e)}notifyContainerRectUpdate(e){this.appProxies.forEach((t=>{t.appEmitter.emit("containerRectUpdate",e)}))}dispatchInternalEvent(e,t){this.safeDispatchMagixEvent("__WindowManger",{eventName:e,payload:t})}destroy(){var e,t;this.displayer.callbacks.off(this.eventName,this.displayerStateListener),this.displayer.callbacks.off("onEnableWriteNowChanged",this.displayerWritableListener),this.appListeners.removeListeners(),_t.offAny(this.boxEventListener),_t.clearListeners(),this.appProxies.size&&this.appProxies.forEach((e=>{e.destroy(!0,!1,!0)})),this.viewManager.destroy(),null==(e=this.boxManager)||e.destroy(),null==(t=this.refresher)||t.destroy(),this.mainViewProxy.destroy(),qt.clearListeners(),this._prevSceneIndex=void 0}}const nt=window.ResizeObserver||g;class ot{constructor(e){this.emitter=e}static create(e,t,i,s){const a=new ot(s);return a.observePlaygroundSize(e,t,i),a}observePlaygroundSize(e,t,i){this.updateSizer(e.getBoundingClientRect(),t,i),this.containerResizeObserver=new nt((e=>{var s;const a=null==(s=e[0])?void 0:s.contentRect;a&&(this.updateSizer(a,t,i),this.emitter.emit("playgroundSizeChange",a))})),this.containerResizeObserver.observe(e)}updateSizer({width:e,height:t},i,s){e&&t&&(t/e>ti.containerSizeRatio?(t=e*ti.containerSizeRatio,i.classList.toggle("netless-window-manager-sizer-horizontal",!0)):(e=t/ti.containerSizeRatio,i.classList.toggle("netless-window-manager-sizer-horizontal",!1)),s.style.width=`${e}px`,s.style.height=`${t}px`)}disconnect(){var e;null==(e=this.containerResizeObserver)||e.disconnect()}}class ht{constructor(e,t){this.context=e,this.createTeleBoxManagerConfig=t,this.playgroundSizeChangeListener=()=>{this.updateManagerRect()};const{emitter:i,callbacks:s}=e;this.teleBoxManager=this.setupBoxManager(t),this.teleBoxManager.events.on(L.State,(e=>{e&&(this.context.callbacks.emit("boxStateChange",e),this.context.emitter.emit("boxStateChange",e))})),this.teleBoxManager.events.on("minimized",(e=>{this.context.safeSetAttributes({minimized:e}),e&&(this.context.cleanFocus(),this.blurAllBox())})),this.teleBoxManager.events.on("maximized",(e=>{this.context.safeSetAttributes({maximized:e})})),this.teleBoxManager.events.on("removed",(e=>{e.forEach((e=>{i.emit("close",{appId:e.id})}))})),this.teleBoxManager.events.on("intrinsic_move",u((e=>{i.emit("move",{appId:e.id,x:e.intrinsicX,y:e.intrinsicY})}),50)),this.teleBoxManager.events.on("intrinsic_resize",u((e=>{i.emit("resize",{appId:e.id,width:e.intrinsicWidth,height:e.intrinsicHeight})}),200)),this.teleBoxManager.events.on("focused",(e=>{e&&(this.canOperate?i.emit("focus",{appId:e.id}):this.teleBoxManager.blurBox(e.id))})),this.teleBoxManager.events.on("dark_mode",(e=>{s.emit("darkModeChange",e)})),this.teleBoxManager.events.on("prefers_color_scheme",(e=>{s.emit("prefersColorSchemeChange",e)})),this.teleBoxManager.events.on("z_index",(e=>{this.context.updateAppState(e.id,re.ZIndex,e.zIndex)})),i.on("playgroundSizeChange",this.playgroundSizeChangeListener)}get mainView(){return this.context.getMainView()}get canOperate(){return this.context.canOperate()}get boxState(){return this.teleBoxManager.state}get maximized(){return this.teleBoxManager.maximized}get minimized(){return this.teleBoxManager.minimized}get darkMode(){return this.teleBoxManager.darkMode}get prefersColorScheme(){return this.teleBoxManager.prefersColorScheme}get boxSize(){return this.teleBoxManager.boxes.length}createBox(t){var i,s,a;if(!this.teleBoxManager)return;let{minwidth:r=pe,minheight:n=ge}=null!=(i=t.app.config)?i:{};const{width:o,height:h}=null!=(s=t.app.config)?s:{},c=(null==(a=t.options)?void 0:a.title)||t.appId,d=this.teleBoxManager.containerRect;r>1&&(r/=d.width),n>1&&(n/=d.height);const l={title:c,minWidth:r,minHeight:n,width:o,height:h,id:t.appId};this.teleBoxManager.create(l,t.smartPosition),this.context.emitter.emit(`${t.appId}${e.WindowCreated}`)}setBoxInitState(e){const t=this.teleBoxManager.queryOne({id:e});t&&t.state===z.Maximized&&this.context.emitter.emit("resize",{appId:e,x:t.x,y:t.y,width:t.intrinsicWidth,height:t.intrinsicHeight})}setupBoxManager(e){const t=ti.wrapper?ti.wrapper:document.body,i=t.getBoundingClientRect(),s={root:t,containerRect:{x:0,y:0,width:i.width,height:i.height},fence:!1,prefersColorScheme:null==e?void 0:e.prefersColorScheme},a=new P(s);this.teleBoxManager&&this.teleBoxManager.destroy(),this.teleBoxManager=a;const r=(null==e?void 0:e.collectorContainer)||ti.wrapper;return r&&this.setCollectorContainer(r),a}setCollectorContainer(e){var t;const i=new B({styles:null==(t=this.createTeleBoxManagerConfig)?void 0:t.collectorStyles}).mount(e);this.teleBoxManager.setCollector(i)}getBox(e){return this.teleBoxManager.queryOne({id:e})}closeBox(e,t=!1){return this.teleBoxManager.remove(e,t)}boxIsFocus(e){const t=this.getBox(e);return null==t?void 0:t.focus}getFocusBox(){return this.teleBoxManager.query({focus:!0})[0]}getTopBox(){const e=this.teleBoxManager.query();return N(e,"zIndex")}updateBoxState(e){if(!e)return;const t=this.getBox(e.id);t&&(this.teleBoxManager.update(t.id,{x:e.x,y:e.y,width:e.width||.5,height:e.height||.5,zIndex:e.zIndex},!0),setTimeout((()=>{e.focus&&this.teleBoxManager.focusBox(t.id,!0),null!=e.maximized&&this.teleBoxManager.setMaximized(Boolean(e.maximized),!0),null!=e.minimized&&this.teleBoxManager.setMinimized(Boolean(e.minimized),!0)}),50),this.context.callbacks.emit("boxStateChange",this.teleBoxManager.state))}updateManagerRect(){var e;const t=null==(e=this.mainView.divElement)?void 0:e.getBoundingClientRect();if(t&&t.width>0&&t.height>0){const e={x:0,y:0,width:t.width,height:t.height};this.teleBoxManager.setContainerRect(e),this.context.notifyContainerRectUpdate(this.teleBoxManager.containerRect)}}moveBox({appId:e,x:t,y:i}){this.teleBoxManager.update(e,{x:t,y:i},!0)}focusBox({appId:e},t=!0){this.teleBoxManager.focusBox(e,t)}resizeBox({appId:e,width:t,height:i,skipUpdate:s}){this.teleBoxManager.update(e,{width:t,height:i},s)}setBoxMinSize(e){this.teleBoxManager.update(e.appId,{minWidth:e.minWidth,minHeight:e.minHeight},!0)}setBoxTitle(e){this.teleBoxManager.update(e.appId,{title:e.title},!0)}blurAllBox(){this.teleBoxManager.blurAll()}updateAll(e){this.teleBoxManager.updateAll(e)}setMaximized(e){e!==this.maximized&&this.teleBoxManager.setMaximized(e,!0)}setMinimized(e,t=!0){this.teleBoxManager.setMinimized(e,t)}focusTopBox(){if(this.teleBoxManager.query().length>=1){const e=this.getTopBox();e&&this.focusBox({appId:e.id},!1)}}setReadonly(e){this.teleBoxManager.setReadonly(e)}setPrefersColorScheme(e){this.teleBoxManager.setPrefersColorScheme(e)}setZIndex(e,t,i=!0){this.teleBoxManager.update(e,{zIndex:t},i)}destroy(){_t.off("playgroundSizeChange",this.playgroundSizeChangeListener),this.teleBoxManager.destroy()}}function ct(){}function dt(e){return e()}function lt(){return Object.create(null)}function pt(e){e.forEach(dt)}function gt(e){return"function"==typeof e}function ut(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}let Mt,mt;function wt(e,t){return Mt||(Mt=document.createElement("a")),Mt.href=t,e===Mt.href}function It(e,t){e.appendChild(t)}function At(e,t,i){e.insertBefore(t,i||null)}function xt(e){e.parentNode.removeChild(e)}function Ct(e){return document.createElement(e)}function yt(e){return document.createTextNode(e)}function bt(){return yt(" ")}function vt(e,t,i){null==i?e.removeAttribute(t):e.getAttribute(t)!==i&&e.setAttribute(t,i)}function St(e,t){t=""+t,e.wholeText!==t&&(e.data=t)}function Nt(e,t,i,s){e.style.setProperty(t,i,s?"important":"")}function Dt(e){mt=e}const ft=[],jt=[],Tt=[],Et=[],Lt=Promise.resolve();let zt=!1;function Pt(e){Tt.push(e)}let Bt=!1;const Vt=new Set;function Ut(){if(!Bt){Bt=!0;do{for(let e=0;e<ft.length;e+=1){const t=ft[e];Dt(t),kt(t.$$)}for(Dt(null),ft.length=0;jt.length;)jt.pop()();for(let e=0;e<Tt.length;e+=1){const t=Tt[e];Vt.has(t)||(Vt.add(t),t())}Tt.length=0}while(ft.length);for(;Et.length;)Et.pop()();zt=!1,Bt=!1,Vt.clear()}}function kt(e){if(null!==e.fragment){e.update(),pt(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Pt)}}const Ot=new Set;function Rt(e,t){-1===e.$$.dirty[0]&&(ft.push(e),zt||(zt=!0,Lt.then(Ut)),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function Zt(e,t,i,s,a,r,n,o=[-1]){const h=mt;Dt(e);const c=e.$$={fragment:null,ctx:null,props:r,update:ct,not_equal:a,bound:lt(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(h?h.$$.context:t.context||[]),callbacks:lt(),dirty:o,skip_bound:!1,root:t.target||h.$$.root};n&&n(c.root);let d=!1;if(c.ctx=i?i(e,t.props||{},((t,i,...s)=>{const r=s.length?s[0]:i;return c.ctx&&a(c.ctx[t],c.ctx[t]=r)&&(!c.skip_bound&&c.bound[t]&&c.bound[t](r),d&&Rt(e,t)),i})):[],c.update(),d=!0,pt(c.before_update),c.fragment=!!s&&s(c.ctx),t.target){if(t.hydrate){const e=(g=t.target,Array.from(g.childNodes));c.fragment&&c.fragment.l(e),e.forEach(xt)}else c.fragment&&c.fragment.c();t.intro&&((l=e.$$.fragment)&&l.i&&(Ot.delete(l),l.i(p))),function(e,t,i,s){const{fragment:a,on_mount:r,on_destroy:n,after_update:o}=e.$$;a&&a.m(t,i),s||Pt((()=>{const t=r.map(dt).filter(gt);n?n.push(...t):pt(t),e.$$.on_mount=[]})),o.forEach(Pt)}(e,t.target,t.anchor,t.customElement),Ut()}var l,p,g;Dt(h)}function Qt(e){let t,i,s;return{c(){t=Ct("img"),vt(t,"class","netless-window-manager-cursor-selector-avatar"),vt(t,"style",i=e[15]()),wt(t.src,s=e[7])||vt(t,"src",s),vt(t,"alt","avatar")},m(e,i){At(e,t,i)},p(e,i){128&i&&!wt(t.src,s=e[7])&&vt(t,"src",s)},d(e){e&&xt(t)}}}function Gt(e){let t,i;return{c(){t=Ct("span"),i=yt(e[1]),vt(t,"class","netless-window-manager-cursor-tag-name"),Nt(t,"background-color",e[10])},m(e,s){At(e,t,s),It(t,i)},p(e,s){2&s&&St(i,e[1]),1024&s&&Nt(t,"background-color",e[10])},d(e){e&&xt(t)}}}function Wt(e){let t,i,s,a,r,n,o,h,c,d,l,p,g=e[13]&&Qt(e),u=e[14]&&Gt(e);return{c(){t=Ct("div"),i=Ct("div"),s=Ct("div"),g&&g.c(),a=bt(),r=Ct("span"),n=yt(e[0]),o=bt(),u&&u.c(),h=bt(),c=Ct("div"),d=Ct("img"),Nt(r,"overflow","hidden"),Nt(r,"white-space","nowrap"),Nt(r,"text-overflow","ellipsis"),Nt(r,"max-width","80px"),vt(s,"class",e[8]),Nt(s,"background-color",e[2]),Nt(s,"color",e[9]),Nt(s,"opacity",e[11]),vt(i,"class","netless-window-manager-cursor-name"),vt(d,"class",l="netless-window-manager-cursor-"+e[3]+"-image"),wt(d.src,p=e[6])||vt(d,"src",p),vt(d,"alt",e[3]),vt(c,"class","cursor-image-wrapper"),vt(t,"class","netless-window-manager-cursor-mid"),Nt(t,"transform","translateX("+e[4]+"px) translateY("+e[5]+"px)"),Nt(t,"display",e[12])},m(e,l){At(e,t,l),It(t,i),It(i,s),g&&g.m(s,null),It(s,a),It(s,r),It(r,n),It(s,o),u&&u.m(s,null),It(t,h),It(t,c),It(c,d)},p(e,[i]){e[13]?g?g.p(e,i):(g=Qt(e),g.c(),g.m(s,a)):g&&(g.d(1),g=null),1&i&&St(n,e[0]),e[14]?u?u.p(e,i):(u=Gt(e),u.c(),u.m(s,null)):u&&(u.d(1),u=null),256&i&&vt(s,"class",e[8]),4&i&&Nt(s,"background-color",e[2]),512&i&&Nt(s,"color",e[9]),2048&i&&Nt(s,"opacity",e[11]),8&i&&l!==(l="netless-window-manager-cursor-"+e[3]+"-image")&&vt(d,"class",l),64&i&&!wt(d.src,p=e[6])&&vt(d,"src",p),8&i&&vt(d,"alt",e[3]),48&i&&Nt(t,"transform","translateX("+e[4]+"px) translateY("+e[5]+"px)"),4096&i&&Nt(t,"display",e[12])},i:ct,o:ct,d(e){e&&xt(t),g&&g.d(),u&&u.d()}}}function Yt(e,t,i){let s,a,r,n,{cursorName:o}=t,{tagName:h}=t,{backgroundColor:c}=t,{appliance:d}=t,{x:l}=t,{y:p}=t,{src:g}=t,{visible:u}=t,{avatar:M}=t,{theme:m}=t,{color:w}=t,{cursorTagBackgroundColor:I}=t,{opacity:A}=t;return e.$$set=e=>{"cursorName"in e&&i(0,o=e.cursorName),"tagName"in e&&i(1,h=e.tagName),"backgroundColor"in e&&i(2,c=e.backgroundColor),"appliance"in e&&i(3,d=e.appliance),"x"in e&&i(4,l=e.x),"y"in e&&i(5,p=e.y),"src"in e&&i(6,g=e.src),"visible"in e&&i(16,u=e.visible),"avatar"in e&&i(7,M=e.avatar),"theme"in e&&i(8,m=e.theme),"color"in e&&i(9,w=e.color),"cursorTagBackgroundColor"in e&&i(10,I=e.cursorTagBackgroundColor),"opacity"in e&&i(11,A=e.opacity)},e.$$.update=()=>{1&e.$$.dirty&&(s=!b(o)),2&e.$$.dirty&&i(14,a=!b(h)),128&e.$$.dirty&&i(13,r=!b(M)),65536&e.$$.dirty&&i(12,n=u?"initial":"none")},[o,h,c,d,l,p,g,M,m,w,I,A,n,r,a,()=>Object.entries({width:(s?19:28)+"px",height:(s?19:28)+"px",position:s?"initial":"absolute","border-color":s?"white":c,"margin-right":(s?4:0)+"px"}).map((([e,t])=>`${e}: ${t}`)).join(";"),u]}class Ft extends class{$destroy(){!function(e,t){const i=e.$$;null!==i.fragment&&(pt(i.on_destroy),i.fragment&&i.fragment.d(t),i.on_destroy=i.fragment=null,i.ctx=[])}(this,1),this.$destroy=ct}$on(e,t){const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(t),()=>{const e=i.indexOf(t);-1!==e&&i.splice(e,1)}}$set(e){var t;this.$$set&&(t=e,0!==Object.keys(t).length)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}{constructor(e){super(),Zt(this,e,Yt,Wt,ut,{cursorName:0,tagName:1,backgroundColor:2,appliance:3,x:4,y:5,src:6,visible:16,avatar:7,theme:8,color:9,cursorTagBackgroundColor:10,opacity:11})}}const Ht={[X.pencil]:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAYAAADFeBvrAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAYISURBVHgB7ZpNSCtXFIBPEuvz+dMGpYUKD/sWFX+Qti6kK7Hqpm6e9q0rIoIUFUShPLV10VZx4+JZqa9v20LBhdq9fyBUCtKNPH8qYl2IOw3G38Rkek4y15y5uTOZJDOWggcOSSYzN/ebc+45554JwIM8iBCPyTEP+86T4vyMfsRN4b+nQTKIJp0vzuGvlpID7os8EQNEIBD4oKio6Bm9DwaDv/v9/n/076JgbtWUYPchwrW8qD7UnOvr6wFNkpubm+/wu7f0c7y6mrnlvQufxB0Iau7V1dX3BDA/P6/V1dVpzc3N2uLiIofK1c8VYHys/wRKBUN3/hGHqaysNOjc3FwMis6hc0FtLTHuvYLxCCZgci8uLn4wg5Gh6F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2Ljg5ODA4NSAyNC4xMzQ1MTIzLDI2Ljk4OTk0NzkgTDI0LDI3IEwxNiwyNyBDMTUuNDQ3NzE1MywyNyAxNSwyNi41NTIyODQ3IDE1LDI2IEMxNSwyNS41MTQ1ODk3IDE1LjM0Nzk5OTMsMjUuMTAxOTE1IDE1Ljg2NTQ4NzcsMjUuMDEwMDUyMSBMMTYsMjUgTDE5LDI1IFoiIGZpbGw9IiMyMTIzMjQiIGZpbGwtcnVsZT0iZXZlbm9kZCI+PC9wYXRoPgogICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICA8L2c+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4="};class Xt extends $e{constructor(e,t,i,s,a,r){super(e),this.cursors=i,this.memberId=s,this.cursorManager=a,this.wrapper=r,this.onCursorChange=(e,t)=>{var i;if("main"===e.type){const t=this.cursorManager.wrapperRect;this.component&&t&&(this.autoHidden(),this.moveCursor(e,t,this.manager.mainView))}else{const t=this.cursorManager.focusView,s=null==(i=null==t?void 0:t.divElement)?void 0:i.getBoundingClientRect(),a=null==t?void 0:t.camera;t&&s&&a&&this.component&&(this.autoHidden(),this.moveCursor(e,s,t))}t&&t===de.Leave&&this.hide()},this.setMember(),this.createCursor(),t(this.memberId,this.onCursorChange),this.autoHidden()}moveCursor(e,t,i){var s,a;const{x:r,y:n,type:o}=e,h=null==i?void 0:i.screen.convertPointToScreen(r,n);if(h){let e=h.x-2,i=h.y-18;if("app"===o){const s=this.cursorManager.wrapperRect;s&&(e=e+t.x-s.x,i=i+t.y-s.y)}h.x<0||h.x>t.width||h.y<0||h.y>t.height?null==(s=this.component)||s.$set({visible:!1,x:e,y:i}):null==(a=this.component)||a.$set({visible:!0,x:e,y:i})}}get memberApplianceName(){var e,t;return null==(t=null==(e=this.member)?void 0:e.memberState)?void 0:t.currentApplianceName}get memberColor(){var e,t;return`rgb(${null==(t=null==(e=this.member)?void 0:e.memberState)?void 0:t.strokeColor.join(",")})`}get payload(){var e;return null==(e=this.member)?void 0:e.payload}get memberCursorName(){var e,t;return(null==(e=this.payload)?void 0:e.nickName)||(null==(t=this.payload)?void 0:t.cursorName)||this.memberId}get memberTheme(){var e;return(null==(e=this.payload)?void 0:e.theme)?"netless-window-manager-cursor-inner-mellow":"netless-window-manager-cursor-inner"}get memberCursorTextColor(){var e;return(null==(e=this.payload)?void 0:e.cursorTextColor)||"#FFFFFF"}get memberCursorTagBackgroundColor(){var e;return(null==(e=this.payload)?void 0:e.cursorTagBackgroundColor)||this.memberColor}get memberAvatar(){var e;return null==(e=this.payload)?void 0:e.avatar}get memberOpacity(){return this.memberCursorName||this.memberAvatar?1:0}get cursorState(){return w(this.cursors,[this.memberId,He.CursorState])}get cursorPosition(){return w(this.cursors,[this.memberId,He.Position])}autoHidden(){this.timer&&clearTimeout(this.timer),this.timer=window.setTimeout((()=>{this.hide(),this.store.updateCursorState(this.memberId,de.Leave)}),1e4)}async createCursor(){this.member&&this.wrapper&&(this.component=new Ft({target:this.wrapper,props:this.initProps()}))}initProps(){return{x:0,y:0,appliance:this.memberApplianceName,avatar:this.memberAvatar,src:this.getIcon(),visible:!1,backgroundColor:this.memberColor,cursorName:this.memberCursorName,theme:this.memberTheme,color:this.memberCursorTextColor,cursorTagBackgroundColor:this.memberCursorTagBackgroundColor,opacity:this.memberOpacity}}getIcon(){if(this.member){return Ht[this.memberApplianceName||X.shape]||Ht[X.shape]}}setMember(){this.member=this.context.findMemberByUid(this.memberId),this.updateComponent()}updateComponent(){var e;null==(e=this.component)||e.$set(D(this.initProps(),["x","y"]))}destroy(){var e;this.component&&this.component.$destroy(),null==(e=this.manager.refresher)||e.remove(this.memberId),this.cursorManager.cursorInstances.delete(this.memberId)}hide(){this.component&&this.component.$set({visible:!1})}}class Jt extends $e{constructor(e){var t;super(e),this.appManager=e,this.cursorInstances=new Map,this.sideEffectManager=new te,this.getUids=e=>f(j(null==e?void 0:e.map((e=>{var t;return null==(t=e.payload)?void 0:t.uid})))),this.handleRoomMembersChange=u((e=>{const t=this.getUids(this.roomMembers),i=Object.keys(this.cursors);(null==t?void 0:t.length)&&i.map((i=>{if(t.includes(i)&&!this.cursorInstances.has(i)){if(i===this.context.uid)return;const t=new Xt(this.appManager,this.addCursorChangeListener,this.cursors,i,this,e);this.cursorInstances.set(i,t)}}))}),100),this.mouseMoveListener=u((e=>{this.updateCursor(this.getType(e),e.clientX,e.clientY)}),5),this.getPoint=(e,t,i)=>{var s;const a=null==(s=null==e?void 0:e.divElement)?void 0:s.getBoundingClientRect();if(a){return null==e?void 0:e.convertToPointInWorld({x:t-a.x,y:i-a.y})}},this.getType=e=>{var t;const i=e.target,s=this.appManager.focusApp;switch(i.parentElement){case this.mainViewElement:return{type:"main"};case null==(t=null==s?void 0:s.view)?void 0:t.divElement:return{type:"app"};default:return{type:"main"}}},this.mouseLeaveListener=()=>{this.hideCursor(this.context.uid),this.store.updateCursorState(this.context.uid,de.Leave)},this.addCursorChangeListener=(e,t)=>{var i;null==(i=this.manager.refresher)||i.add(e,(()=>R((()=>{const i=w(this.cursors,[e,He.Position]),s=w(this.cursors,[e,He.CursorState]);i&&t(i,s)}))))},this.roomMembers=null==(t=this.appManager.room)?void 0:t.state.roomMembers;const i=ti.wrapper;i&&this.setupWrapper(i),_t.on("onReconnected",(()=>{this.onReconnect()}))}setupWrapper(e){var t;(null==(t=this.manager.refresher)?void 0:t.hasReactor("cursors"))&&this.destroy(),this.sideEffectManager.add((()=>(e.addEventListener("pointerenter",this.mouseMoveListener),e.addEventListener("pointermove",this.mouseMoveListener),e.addEventListener("pointerleave",this.mouseLeaveListener),()=>{e.removeEventListener("pointerenter",this.mouseMoveListener),e.removeEventListener("pointermove",this.mouseMoveListener),e.removeEventListener("pointerleave",this.mouseLeaveListener)}))),this.initCursorAttributes(),this.wrapperRect=e.getBoundingClientRect(),this.startReaction(e)}setMainViewDivElement(e){this.mainViewElement=e}startReaction(e){var t;null==(t=this.manager.refresher)||t.add("cursors",(()=>Re(this.cursors,(()=>{this.handleRoomMembersChange(e)}))))}get cursors(){var e;return null==(e=this.manager.attributes)?void 0:e[He.Cursors]}get boxState(){return this.store.getBoxState()}get focusView(){var e;return null==(e=this.appManager.focusApp)?void 0:e.view}updateCursor(e,t,i){if(this.wrapperRect&&this.manager.canOperate){const s="main"===e.type?this.appManager.mainView:this.focusView,a=this.getPoint(s,t,i);a&&(this.setNormalCursorState(),this.store.updateCursor(this.context.uid,c({x:a.x,y:a.y},e)))}}initCursorAttributes(){this.store.updateCursor(this.context.uid,{x:0,y:0,type:"main"}),this.store.updateCursorState(this.context.uid,de.Leave)}setNormalCursorState(){this.store.getCursorState(this.context.uid)!==de.Normal&&this.store.updateCursorState(this.context.uid,de.Normal)}updateContainerRect(){var e,t;this.containerRect=null==(e=ti.container)?void 0:e.getBoundingClientRect(),this.wrapperRect=null==(t=ti.wrapper)?void 0:t.getBoundingClientRect()}setRoomMembers(e){this.roomMembers=e,this.cursorInstances.forEach((e=>{e.setMember()})),ti.wrapper&&this.handleRoomMembersChange(ti.wrapper)}deleteCursor(e){this.store.cleanCursor(e);const t=this.cursorInstances.get(e);t&&t.destroy()}hideCursor(e){const t=this.cursorInstances.get(e);t&&t.hide()}cleanMemberAttributes(e){const t=this.getUids(e),i=[];Object.keys(this.cursors).map((e=>{-1===t.findIndex((t=>t===e))&&i.push(e)})),i.forEach((e=>{this.deleteCursor(e)}))}onReconnect(){var e;this.cursorInstances.size&&(this.cursorInstances.forEach((e=>e.destroy())),this.cursorInstances.clear()),this.roomMembers=null==(e=this.appManager.room)?void 0:e.state.roomMembers,ti.wrapper&&this.handleRoomMembersChange(ti.wrapper)}destroy(){var e;this.sideEffectManager.flushAll(),this.cursorInstances.size&&(this.cursorInstances.forEach((e=>{e.destroy()})),this.cursorInstances.clear()),null==(e=this.manager.refresher)||e.remove("cursors")}}const Kt={DocsViewer:ie.kind,MediaPlayer:se.kind};const _t=new l,qt=new l,$t=new class{constructor(e){this.ctx=e,this.reactors=new Map,this.disposers=new Map,this.onPhaseChanged=e=>{e===J.Connected&&this.phase===J.Reconnecting&&this.onReconnected(),this.phase=e},this.onReconnected=u((()=>{Ke("onReconnected refresh reactors"),this.releaseDisposers(),this.reactors.forEach(((e,t)=>{T(e)&&this.disposers.set(t,e())})),this.ctx.emitter.emit("onReconnected",void 0)}),3e3)}setRoom(e){this.room=e,this.phase=null==e?void 0:e.phase,null==e||e.callbacks.off("onPhaseChanged",this.onPhaseChanged),null==e||e.callbacks.on("onPhaseChanged",this.onPhaseChanged)}setContext(e){this.ctx=e}releaseDisposers(){this.disposers.forEach((e=>{T(e)&&e()})),this.disposers.clear()}add(e,t){T(t)&&(this.reactors.set(e,t),this.disposers.set(e,t()))}remove(e){this.reactors.has(e)&&this.reactors.delete(e);const t=this.disposers.get(e);t&&(T(t)&&t(),this.disposers.delete(e))}hasReactor(e){return this.reactors.has(e)}destroy(){var e;null==(e=this.room)||e.callbacks.off("onPhaseChanged",this.onPhaseChanged),this.releaseDisposers()}}({emitter:_t}),ei=class extends K{constructor(e){super(e),this.version="0.4.0-canary.14",this.emitter=qt,this.viewMode=_.Broadcaster,this.isReplay=Y(this.displayer),ei.displayer=e.displayer}static async mount(e){const t=e.room;ei.container=e.container;const i=e.containerSizeRatio,s=e.debug,a=e.cursor;if(ei.params=e,this.checkVersion(),F(t)){if(t.phase!==J.Connected)throw new Error("[WindowManager]: Room only Connected can be mount");t.phase===J.Connected&&t.isWritable&&(t.disableSerialization=!1)}if(ei.isCreated)throw new Error("[WindowManager]: Already created cannot be created again");let r=await this.initManager(t);if(this.debug=Boolean(s),Ke("Already insert room",r),F(this.displayer)){if(!r)throw new Error("[WindowManager]: init InvisiblePlugin failed")}else await p((async e=>{if(r=await this.initManager(t),!r)throw Ke(`manager is empty. retrying ${e}`),new Error}),{retries:10});i&&(ei.containerSizeRatio=i),await r.ensureAttributes(),r.appManager=new rt(r),a&&(r.cursorManager=new Jt(r.appManager)),e.container&&r.bindContainer(e.container),((e,t)=>{if(Y(e)){const t=e,i=t.seekToProgressTime;t.seekToProgressTime=async function(e){const s=await i.call(t,e);return"success"===s&&_t.emit("seek",e),s}}else{if(Object.getOwnPropertyDescriptor(e,"disableCameraTransform"))return;Object.defineProperty(e,"disableCameraTransform",{get:()=>t.mainView.disableCameraTransform,set(e){t.mainView.disableCameraTransform=e}}),Object.defineProperty(e,"canUndoSteps",{get:()=>t.mainView.canUndoSteps}),Object.defineProperty(e,"canRedoSteps",{get:()=>t.mainView.canRedoSteps}),e.moveCamera=e=>t.mainView.moveCamera(e),e.moveCameraToContain=(...e)=>t.moveCameraToContain(...e),e.convertToPointInWorld=(...e)=>t.mainView.convertToPointInWorld(...e),e.setCameraBound=(...e)=>t.mainView.setCameraBound(...e),e.scenePreview=(...e)=>t.mainView.scenePreview(...e),e.fillSceneSnapshot=(...e)=>t.mainView.fillSceneSnapshot(...e),e.generateScreenshot=(...e)=>t.mainView.generateScreenshot(...e),e.setMemberState=(...e)=>t.mainView.setMemberState(...e),e.redo=()=>t.mainView.redo(),e.undo=()=>t.mainView.undo(),e.cleanCurrentScene=()=>t.mainView.cleanCurrentScene()}})(t,r),_t.emit("onCreated"),ei.isCreated=!0;try{await me()}catch(n){console.warn("[WindowManager]: indexedDB open failed"),console.log(n)}return r}static async initManager(e){let t=e.getInvisiblePlugin(ei.kind);if(!t&&F(e))if(!1===e.isWritable){try{await e.setWritable(!0)}catch(i){throw new Error("[WindowManger]: room must be switched to be writable")}t=await e.createInvisiblePlugin(ei,{}),t.ensureAttributes(),await fe(500),await e.setWritable(!1)}else t=await e.createInvisiblePlugin(ei,{});return t}static initContainer(e,t,i,s){ei.container||(ei.container=t);const{playground:a,wrapper:r,sizer:n,mainViewElement:o}=(e=>{const t=document.createElement("div");t.className="netless-window-manager-playground";const i=document.createElement("div");i.className="netless-window-manager-sizer";const s=document.createElement("div");s.className="netless-window-manager-wrapper";const a=document.createElement("div");return a.className="netless-window-manager-main-view",t.appendChild(i),i.appendChild(s),s.appendChild(a),e.appendChild(t),ti.wrapper=s,{playground:t,wrapper:s,sizer:i,mainViewElement:a}})(t);if(ei.playground=a,i&&n.classList.add("netless-window-manager-chess-sizer"),s){const e=document.createElement("style");e.textContent=s,a.appendChild(e)}return e.containerResizeObserver=ot.create(a,n,r,_t),ei.wrapper=r,o}bindContainer(e){var t,i,s,a,r,n,o,h,c,d;if(ei.isCreated&&ei.container)ei.container.firstChild&&e.appendChild(ei.container.firstChild);else if(ei.params){const s=ei.params,a=ei.initContainer(this,e,s.chessboard,s.overwriteStyles),r=(o=this,h=qt,c=_t,d={collectorContainer:s.collectorContainer,collectorStyles:s.collectorStyles,prefersColorScheme:s.prefersColorScheme},new ht({safeSetAttributes:e=>o.safeSetAttributes(e),getMainView:()=>o.mainView,updateAppState:(...e)=>{var t;return null==(t=o.appManager)?void 0:t.store.updateAppState(...e)},canOperate:()=>o.canOperate,notifyContainerRectUpdate:e=>{var t;return null==(t=o.appManager)?void 0:t.notifyContainerRectUpdate(e)},cleanFocus:()=>{var e;return null==(e=o.appManager)?void 0:e.store.cleanFocus()},callbacks:h,emitter:c},d));this.boxManager=r,null==(t=this.appManager)||t.setBoxManager(r),this.bindMainView(a,s.disableCameraTransform),ei.wrapper&&(null==(i=this.cursorManager)||i.setupWrapper(ei.wrapper))}null==(s=this.boxManager)||s.updateManagerRect(),null==(a=this.appManager)||a.refresh(),null==(r=this.appManager)||r.resetMaximized(),null==(n=this.appManager)||n.resetMinimized(),ei.container=e}bindCollectorContainer(e){ei.isCreated&&this.boxManager?this.boxManager.setCollectorContainer(e):ei.params&&(ei.params.collectorContainer=e)}static register(e){return Ce.register(e)}async addApp(e){var t,i,s,a;if(this.appManager){if(!e.kind||"string"!=typeof e.kind)throw new ze;const r=await(null==(t=Ce.appClasses.get(e.kind))?void 0:t());if(r&&(null==(i=r.config)?void 0:i.singleton)&&this.appManager.appProxies.has(e.kind))throw new Te;const n=this.setupScenePath(e,this.appManager);if(void 0===n)return;(null==(s=null==e?void 0:e.options)?void 0:s.scenePath)&&(e.options.scenePath=(a=e.options.scenePath).endsWith("/")?a.slice(0,-1):a);return await this.appManager.addApp(e,Boolean(n))}throw new Ee}setupScenePath(e,t){var i,s,a;let r=!1;if(e.options){const{scenePath:n,scenes:o}=e.options;if(n){if(!(e=>e.startsWith("/"))(n))throw new Be;const e=Object.keys(this.apps||{});for(const i of e){const e=t.store.getAppScenePath(i);if(e&&e===n)return void console.warn(`[WindowManager]: ScenePath ${n} Already opened`)}}n&&o&&o.length>0&&(this.isDynamicPPT(o)?(r=!0,this.displayer.entireScenes()[n]||null==(i=this.room)||i.putScenes(n,o)):this.displayer.entireScenes()[n]||null==(s=this.room)||s.putScenes(n,[{name:o[0].name}])),n&&void 0===o&&(null==(a=this.room)||a.putScenes(n,[{}]))}return r}async setMainViewScenePath(e){this.appManager&&await this.appManager.setMainViewScenePath(e)}async setMainViewSceneIndex(e){this.appManager&&await this.appManager.setMainViewSceneIndex(e)}getMainViewScenePath(){var e;return null==(e=this.appManager)?void 0:e.store.getMainViewScenePath()}getMainViewSceneIndex(){var e;return null==(e=this.appManager)?void 0:e.store.getMainViewSceneIndex()}setReadonly(e){var t;this.readonly=e,null==(t=this.boxManager)||t.setReadonly(e)}switchMainViewToWriter(){var e;return null==(e=this.appManager)?void 0:e.mainViewProxy.mainViewClickHandler()}onAppDestroy(e,t){((e,t)=>{_t.once(e).then(t)})(`destroy-${e}`,t)}setViewMode(e){var t,i,s;this.canOperate&&(e===_.Broadcaster&&(null==(t=this.appManager)||t.mainViewProxy.setCameraAndSize(),null==(i=this.appManager)||i.mainViewProxy.start()),e===_.Freedom&&(null==(s=this.appManager)||s.mainViewProxy.stop()),this.viewMode=e)}get mainView(){if(this.appManager)return this.appManager.mainViewProxy.view;throw new Ee}get camera(){if(this.appManager)return this.appManager.mainViewProxy.view.camera;throw new Ee}get cameraState(){if(this.appManager)return this.appManager.mainViewProxy.cameraState;throw new Ee}get apps(){var e;return null==(e=this.appManager)?void 0:e.store.apps()}get boxState(){var e;if(this.appManager)return null==(e=this.appManager.boxManager)?void 0:e.boxState;throw new Ee}get darkMode(){var e,t;return Boolean(null==(t=null==(e=this.appManager)?void 0:e.boxManager)?void 0:t.darkMode)}get prefersColorScheme(){var e;if(this.appManager)return null==(e=this.appManager.boxManager)?void 0:e.prefersColorScheme;throw new Ee}get focused(){return this.attributes.focus}get mainViewSceneIndex(){var e;return null==(e=this.appManager)?void 0:e.store.getMainViewSceneIndex()}get mainViewSceneDir(){var e;const t=null==(e=this.appManager)?void 0:e.store.getMainViewScenePath();if(t)return Ne(t);throw new Error("[WindowManager]: mainViewSceneDir not found")}queryAll(){var e;return Array.from((null==(e=this.appManager)?void 0:e.appProxies.values())||[])}queryOne(e){var t;return null==(t=this.appManager)?void 0:t.appProxies.get(e)}async closeApp(e){var t;return null==(t=this.appManager)?void 0:t.closeApp(e)}moveCamera(e){this.mainView.moveCamera(e)}moveCameraToContain(t){var i;this.mainView.moveCameraToContain(t),null==(i=this.appManager)||i.dispatchInternalEvent(e.MoveCameraToContain,t),setTimeout((()=>{var e;null==(e=this.appManager)||e.mainViewProxy.setCameraAndSize()}),1e3)}convertToPointInWorld(e){return this.mainView.convertToPointInWorld(e)}setCameraBound(e){this.mainView.setCameraBound(e)}onDestroy(){this._destroy()}destroy(){this._destroy()}_destroy(){var e,t,i,s;null==(e=this.containerResizeObserver)||e.disconnect(),null==(t=this.appManager)||t.destroy(),null==(i=this.cursorManager)||i.destroy(),ei.container=void 0,ei.wrapper=void 0,ei.isCreated=!1,ei.playground&&(null==(s=ei.playground.parentNode)||s.removeChild(ei.playground)),ei.params=void 0,Ke("Destroyed")}bindMainView(e,t){var i;this.appManager&&(this.appManager.bindMainView(e,Boolean(t)),null==(i=this.cursorManager)||i.setMainViewDivElement(e))}get canOperate(){return!!F(this.displayer)&&(this.displayer.isWritable&&this.displayer.phase===J.Connected)}get room(){return this.displayer}safeSetAttributes(e){this.canOperate&&this.setAttributes(e)}safeUpdateAttributes(e,t){this.canOperate&&this.updateAttributes(e,t)}setPrefersColorScheme(e){var t,i;null==(i=null==(t=this.appManager)?void 0:t.boxManager)||i.setPrefersColorScheme(e)}isDynamicPPT(e){var t,i;const s=null==(i=null==(t=e[0])?void 0:t.ppt)?void 0:i.src;return null==s?void 0:s.startsWith("pptx://")}static checkVersion(){if(De(q)<De("2.16.0"))throw new Le("2.16.0")}async ensureAttributes(){if(E(this.attributes)&&await fe(50),M(this.attributes)){this.attributes[He.Apps]||this.safeSetAttributes({[He.Apps]:{}}),this.attributes[He.Cursors]||this.safeSetAttributes({[He.Cursors]:{}});const e=this.displayer.state.sceneState;this.attributes._mainScenePath||this.safeSetAttributes({_mainScenePath:e.scenePath}),this.attributes._mainSceneIndex||this.safeSetAttributes({_mainSceneIndex:e.index})}}};let ti=ei;ti.kind="WindowManager",ti.debug=!1,ti.containerSizeRatio=9/16,ti.isCreated=!1,ti.debug&&ae({verbose:!0}),ti.register({kind:ie.kind,src:ie}),ti.register({kind:se.kind,src:se});export{Kt as BuiltinApps,ti as WindowManager,qt as callbacks,_t as emitter,$t as reconnectRefresher};
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import Emittery from "emittery";
21
+ import pRetry from "p-retry";
22
+ import { ResizeObserver as ResizeObserver$1 } from "@juggle/resize-observer";
23
+ import { debounce, isObject, has, get, size, mapValues, noop as noop$1, pick, isEqual, isEmpty, isInteger, sortBy, maxBy, omit, compact, uniq, isFunction, isNull } from "lodash";
24
+ import { TELE_BOX_MANAGER_EVENT, TELE_BOX_STATE, TeleBoxManager, TeleBoxCollector } from "@netless/telebox-insider";
25
+ import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin, ViewMode, WhiteVersion } from "white-web-sdk";
26
+ import { v4 } from "uuid";
27
+ import { genUID, SideEffectManager } from "side-effect-manager";
28
+ import AppDocsViewer from "@netless/app-docs-viewer";
29
+ import AppMediaPlayer, { setOptions } from "@netless/app-media-player";
30
+ var Events;
31
+ (function(Events2) {
32
+ Events2["AppMove"] = "AppMove";
33
+ Events2["AppFocus"] = "AppFocus";
34
+ Events2["AppResize"] = "AppResize";
35
+ Events2["AppBoxStateChange"] = "AppBoxStateChange";
36
+ Events2["GetAttributes"] = "GetAttributes";
37
+ Events2["UpdateWindowManagerWrapper"] = "UpdateWindowManagerWrapper";
38
+ Events2["InitReplay"] = "InitReplay";
39
+ Events2["WindowCreated"] = "WindowCreated";
40
+ Events2["SetMainViewScenePath"] = "SetMainViewScenePath";
41
+ Events2["SetMainViewSceneIndex"] = "SetMainViewSceneIndex";
42
+ Events2["SwitchViewsToFreedom"] = "SwitchViewsToFreedom";
43
+ Events2["MoveCameraToContain"] = "MoveCameraToContain";
44
+ })(Events || (Events = {}));
45
+ const MagixEventName = "__WindowManger";
46
+ var AppAttributes;
47
+ (function(AppAttributes2) {
48
+ AppAttributes2["Size"] = "size";
49
+ AppAttributes2["Position"] = "position";
50
+ AppAttributes2["SceneIndex"] = "SceneIndex";
51
+ AppAttributes2["ZIndex"] = "zIndex";
52
+ })(AppAttributes || (AppAttributes = {}));
53
+ var AppEvents;
54
+ (function(AppEvents2) {
55
+ AppEvents2["setBoxSize"] = "setBoxSize";
56
+ AppEvents2["setBoxMinSize"] = "setBoxMinSize";
57
+ AppEvents2["destroy"] = "destroy";
58
+ })(AppEvents || (AppEvents = {}));
59
+ var AppStatus;
60
+ (function(AppStatus2) {
61
+ AppStatus2["StartCreate"] = "StartCreate";
62
+ })(AppStatus || (AppStatus = {}));
63
+ var CursorState;
64
+ (function(CursorState2) {
65
+ CursorState2["Leave"] = "leave";
66
+ CursorState2["Normal"] = "normal";
67
+ })(CursorState || (CursorState = {}));
68
+ const REQUIRE_VERSION = "2.16.0";
69
+ const MIN_WIDTH = 340 / 720;
70
+ const MIN_HEIGHT = 340 / 720;
71
+ const DEFAULT_CONTAINER_RATIO = 9 / 16;
72
+ const DatabaseName = "__WindowManagerAppCache";
73
+ let db;
74
+ let store$1;
75
+ const initDb = async () => {
76
+ db = await createDb();
77
+ };
78
+ const setItem = (key, val) => {
79
+ if (!db)
80
+ return;
81
+ return addRecord(db, { kind: key, sourceCode: val });
82
+ };
83
+ const getItem = async (key) => {
84
+ if (!db)
85
+ return null;
86
+ return await query(db, key);
87
+ };
88
+ function createDb() {
89
+ return new Promise((resolve, reject) => {
90
+ const request = indexedDB.open(DatabaseName, 2);
91
+ request.onerror = (e) => {
92
+ reject(e);
93
+ };
94
+ request.onupgradeneeded = (event) => {
95
+ const db2 = event.target.result;
96
+ if (!db2.objectStoreNames.contains("apps")) {
97
+ store$1 = db2.createObjectStore("apps", { keyPath: "kind" });
98
+ store$1.createIndex("kind", "kind", { unique: true });
99
+ }
100
+ };
101
+ request.onsuccess = () => {
102
+ const db2 = request.result;
103
+ resolve(db2);
104
+ };
105
+ });
106
+ }
107
+ function query(db2, val) {
108
+ return new Promise((resolve, reject) => {
109
+ const index = db2.transaction(["apps"]).objectStore("apps").index("kind");
110
+ const request = index.get(val);
111
+ request.onerror = (e) => reject(e);
112
+ request.onsuccess = () => {
113
+ if (request.result) {
114
+ resolve(request.result);
115
+ } else {
116
+ resolve(null);
117
+ }
118
+ };
119
+ });
120
+ }
121
+ function addRecord(db2, payload) {
122
+ return new Promise((resolve, reject) => {
123
+ const request = db2.transaction(["apps"], "readwrite").objectStore("apps").add(payload);
124
+ request.onsuccess = () => resolve();
125
+ request.onerror = () => reject();
126
+ });
127
+ }
128
+ const Prefix = "NetlessApp";
129
+ const TIMEOUT = 1e4;
130
+ const getScript = async (url) => {
131
+ const item = await getItem(url);
132
+ if (item) {
133
+ return item.sourceCode;
134
+ } else {
135
+ const result = await fetchWithTimeout(url, { timeout: TIMEOUT });
136
+ const text2 = await result.text();
137
+ await setItem(url, text2);
138
+ return text2;
139
+ }
140
+ };
141
+ const executeScript = (text2, appName) => {
142
+ let result = Function(text2 + `;return ${appName}`)();
143
+ if (typeof result === "undefined") {
144
+ result = window[appName];
145
+ }
146
+ return result;
147
+ };
148
+ const loadApp = async (url, key, name) => {
149
+ const appName = name || Prefix + key;
150
+ const text2 = await getScript(url);
151
+ try {
152
+ return executeScript(text2, appName);
153
+ } catch (error) {
154
+ if (error.message.includes("Can only have one anonymous define call per script file")) {
155
+ const define = window.define;
156
+ if (typeof define == "function" && define.amd) {
157
+ delete define.amd;
158
+ }
159
+ return executeScript(text2, appName);
160
+ }
161
+ }
162
+ };
163
+ async function fetchWithTimeout(resource, options) {
164
+ const { timeout = 1e4 } = options;
165
+ const controller = new AbortController();
166
+ const id = setTimeout(() => controller.abort(), timeout);
167
+ const response = await fetch(resource, __spreadProps(__spreadValues({}, options), {
168
+ signal: controller.signal,
169
+ headers: {
170
+ "content-type": "text/plain"
171
+ }
172
+ }));
173
+ clearTimeout(id);
174
+ return response;
175
+ }
176
+ class AppRegister {
177
+ constructor() {
178
+ this.kindEmitters = new Map();
179
+ this.registered = new Map();
180
+ this.appClassesCache = new Map();
181
+ this.appClasses = new Map();
182
+ }
183
+ async register(params) {
184
+ this.registered.set(params.kind, params);
185
+ const srcOrAppOrFunction = params.src;
186
+ let downloadApp;
187
+ if (typeof srcOrAppOrFunction === "string") {
188
+ downloadApp = async () => {
189
+ let appClass = await loadApp(srcOrAppOrFunction, params.kind);
190
+ if (appClass) {
191
+ if (appClass.__esModule) {
192
+ appClass = appClass.default;
193
+ }
194
+ return appClass;
195
+ } else {
196
+ throw new Error(`[WindowManager]: load remote script failed, ${srcOrAppOrFunction}`);
197
+ }
198
+ };
199
+ } else if (typeof srcOrAppOrFunction === "function") {
200
+ downloadApp = srcOrAppOrFunction;
201
+ } else {
202
+ downloadApp = async () => srcOrAppOrFunction;
203
+ }
204
+ this.appClasses.set(params.kind, async () => {
205
+ let app = this.appClassesCache.get(params.kind);
206
+ if (!app) {
207
+ app = downloadApp();
208
+ this.appClassesCache.set(params.kind, app);
209
+ }
210
+ return app;
211
+ });
212
+ if (params.addHooks) {
213
+ const emitter2 = this.createKindEmitter(params.kind);
214
+ if (emitter2) {
215
+ params.addHooks(emitter2);
216
+ }
217
+ }
218
+ }
219
+ async notifyApp(kind, event, payload) {
220
+ const emitter2 = this.kindEmitters.get(kind);
221
+ await (emitter2 == null ? void 0 : emitter2.emit(event, payload));
222
+ }
223
+ createKindEmitter(kind) {
224
+ if (!this.kindEmitters.has(kind)) {
225
+ const emitter2 = new Emittery();
226
+ this.kindEmitters.set(kind, emitter2);
227
+ }
228
+ return this.kindEmitters.get(kind);
229
+ }
230
+ }
231
+ const appRegister = new AppRegister();
232
+ const genAppId = async (kind) => {
233
+ var _a, _b;
234
+ const impl = await ((_a = appRegister.appClasses.get(kind)) == null ? void 0 : _a());
235
+ if (impl && ((_b = impl.config) == null ? void 0 : _b.singleton)) {
236
+ return kind;
237
+ }
238
+ return `${kind}-${v4().replace("-", "").slice(0, 8)}`;
239
+ };
240
+ const setViewFocusScenePath = (view, focusScenePath) => {
241
+ if (view.focusScenePath !== focusScenePath) {
242
+ view.focusScenePath = focusScenePath;
243
+ return view;
244
+ }
245
+ };
246
+ const setScenePath = (room, scenePath) => {
247
+ if (room && room.isWritable) {
248
+ if (room.state.sceneState.scenePath !== scenePath) {
249
+ room.setScenePath(scenePath);
250
+ }
251
+ }
252
+ };
253
+ const getScenePath = (room, dir, index) => {
254
+ var _a;
255
+ if (room && dir) {
256
+ const scenes = entireScenes(room);
257
+ const scene = (_a = scenes[dir]) == null ? void 0 : _a[index];
258
+ if (scene) {
259
+ return `${dir}/${scene.name}`;
260
+ }
261
+ }
262
+ };
263
+ const removeScenes = (room, scenePath) => {
264
+ if (room) {
265
+ const type = room.scenePathType(scenePath);
266
+ if (type !== ScenePathType.None) {
267
+ room.removeScenes(scenePath);
268
+ }
269
+ }
270
+ };
271
+ const addEmitterOnceListener = (event, listener) => {
272
+ emitter.once(event).then(listener);
273
+ };
274
+ debounce((callbacks2, mode) => {
275
+ callbacks2.emit("mainViewModeChange", mode);
276
+ }, 200);
277
+ const makeValidScenePath = (displayer, scenePath, index = 0) => {
278
+ const scenes = entireScenes(displayer)[scenePath];
279
+ if (!scenes)
280
+ return;
281
+ const scene = scenes[index];
282
+ if (!scene)
283
+ return;
284
+ const firstSceneName = scene.name;
285
+ if (scenePath === "/") {
286
+ return `/${firstSceneName}`;
287
+ } else {
288
+ return `${scenePath}/${firstSceneName}`;
289
+ }
290
+ };
291
+ const entireScenes = (displayer) => {
292
+ return displayer.entireScenes();
293
+ };
294
+ const isValidScenePath = (scenePath) => {
295
+ return scenePath.startsWith("/");
296
+ };
297
+ const parseSceneDir = (scenePath) => {
298
+ const sceneList = scenePath.split("/");
299
+ sceneList.pop();
300
+ let sceneDir = sceneList.join("/");
301
+ if (sceneDir === "") {
302
+ sceneDir = "/";
303
+ }
304
+ return sceneDir;
305
+ };
306
+ const ensureValidScenePath = (scenePath) => {
307
+ if (scenePath.endsWith("/")) {
308
+ return scenePath.slice(0, -1);
309
+ } else {
310
+ return scenePath;
311
+ }
312
+ };
313
+ const getVersionNumber = (version) => {
314
+ const versionString = version.split(".").map((s) => s.padStart(2, "0")).join("");
315
+ return parseInt(versionString);
316
+ };
317
+ const wait = (time) => new Promise((resolve) => setTimeout(resolve, time));
318
+ class AppListeners {
319
+ constructor(manager) {
320
+ this.manager = manager;
321
+ this.displayer = this.manager.displayer;
322
+ this.mainMagixEventListener = (event) => {
323
+ if (event.authorId !== this.displayer.observerId) {
324
+ const data = event.payload;
325
+ switch (data.eventName) {
326
+ case Events.AppMove: {
327
+ this.appMoveHandler(data.payload);
328
+ break;
329
+ }
330
+ case Events.AppResize: {
331
+ this.appResizeHandler(data.payload);
332
+ break;
333
+ }
334
+ case Events.AppBoxStateChange: {
335
+ this.boxStateChangeHandler(data.payload);
336
+ break;
337
+ }
338
+ case Events.SetMainViewScenePath: {
339
+ this.setMainViewScenePathHandler(data.payload);
340
+ break;
341
+ }
342
+ case Events.MoveCameraToContain: {
343
+ this.moveCameraToContainHandler(data.payload);
344
+ break;
345
+ }
346
+ }
347
+ }
348
+ };
349
+ this.appMoveHandler = (payload) => {
350
+ var _a;
351
+ (_a = this.boxManager) == null ? void 0 : _a.moveBox(payload);
352
+ };
353
+ this.appResizeHandler = (payload) => {
354
+ var _a, _b;
355
+ (_a = this.boxManager) == null ? void 0 : _a.resizeBox(Object.assign(payload, { skipUpdate: true }));
356
+ (_b = this.manager.room) == null ? void 0 : _b.refreshViewSize();
357
+ };
358
+ this.boxStateChangeHandler = (state) => {
359
+ callbacks.emit("boxStateChange", state);
360
+ };
361
+ this.setMainViewScenePathHandler = ({ nextScenePath }) => {
362
+ setViewFocusScenePath(this.manager.mainView, nextScenePath);
363
+ callbacks.emit("mainViewScenePathChange", nextScenePath);
364
+ };
365
+ this.moveCameraToContainHandler = (payload) => {
366
+ this.manager.mainView.moveCameraToContain(payload);
367
+ };
368
+ }
369
+ get boxManager() {
370
+ return this.manager.boxManager;
371
+ }
372
+ addListeners() {
373
+ this.displayer.addMagixEventListener(MagixEventName, this.mainMagixEventListener);
374
+ }
375
+ removeListeners() {
376
+ this.displayer.removeMagixEventListener(MagixEventName, this.mainMagixEventListener);
377
+ }
378
+ }
379
+ class AppCreateError extends Error {
380
+ constructor() {
381
+ super(...arguments);
382
+ this.message = "[WindowManager]: app duplicate exists and cannot be created again";
383
+ }
384
+ }
385
+ class AppManagerNotInitError extends Error {
386
+ constructor() {
387
+ super(...arguments);
388
+ this.message = "[WindowManager]: AppManager must be initialized";
389
+ }
390
+ }
391
+ class WhiteWebSDKInvalidError extends Error {
392
+ constructor(version) {
393
+ super(`[WindowManager]: white-web-sdk version must large than ${version}`);
394
+ }
395
+ }
396
+ class ParamsInvalidError extends Error {
397
+ constructor() {
398
+ super(...arguments);
399
+ this.message = "[WindowManager]: kind must be a valid string";
400
+ }
401
+ }
402
+ class BoxNotCreatedError extends Error {
403
+ constructor() {
404
+ super(...arguments);
405
+ this.message = "[WindowManager]: box need created";
406
+ }
407
+ }
408
+ class InvalidScenePath extends Error {
409
+ constructor() {
410
+ super(...arguments);
411
+ this.message = `[WindowManager]: ScenePath should start with "/"`;
412
+ }
413
+ }
414
+ class BoxManagerNotFoundError extends Error {
415
+ constructor() {
416
+ super(...arguments);
417
+ this.message = "[WindowManager]: boxManager not found";
418
+ }
419
+ }
420
+ const onObjectByEvent = (event) => {
421
+ return (object, func) => {
422
+ if (object === void 0)
423
+ return;
424
+ if (listenUpdated) {
425
+ const listener = (events) => {
426
+ const kinds = events.map((e) => e.kind);
427
+ if (kinds.includes(event)) {
428
+ func();
429
+ }
430
+ };
431
+ listenUpdated(object, listener);
432
+ func();
433
+ return () => unlistenUpdated(object, listener);
434
+ } else {
435
+ return reaction(() => object, () => {
436
+ func();
437
+ }, {
438
+ fireImmediately: true
439
+ });
440
+ }
441
+ };
442
+ };
443
+ const safeListenPropsUpdated = (getProps, callback, onDestroyed) => {
444
+ let disposeListenUpdated = null;
445
+ const disposeReaction = reaction(getProps, () => {
446
+ if (disposeListenUpdated) {
447
+ disposeListenUpdated();
448
+ disposeListenUpdated = null;
449
+ }
450
+ const props = getProps();
451
+ if (isObject(props)) {
452
+ disposeListenUpdated = () => unlistenUpdated(props, callback);
453
+ listenUpdated(props, callback);
454
+ } else {
455
+ onDestroyed == null ? void 0 : onDestroyed(props);
456
+ }
457
+ }, { fireImmediately: true });
458
+ return () => {
459
+ disposeListenUpdated == null ? void 0 : disposeListenUpdated();
460
+ disposeReaction();
461
+ };
462
+ };
463
+ const onObjectRemoved = onObjectByEvent(UpdateEventKind.Removed);
464
+ const onObjectInserted = onObjectByEvent(UpdateEventKind.Inserted);
465
+ const plainObjectKeys = Object.keys;
466
+ function isRef(e) {
467
+ return Boolean(has(e, "__isRef"));
468
+ }
469
+ function makeRef(v) {
470
+ return { k: genUID(), v, __isRef: true };
471
+ }
472
+ class StorageEvent {
473
+ constructor() {
474
+ this.listeners = new Set();
475
+ }
476
+ get length() {
477
+ return this.listeners.size;
478
+ }
479
+ dispatch(message) {
480
+ this.listeners.forEach((callback) => callback(message));
481
+ }
482
+ addListener(listener) {
483
+ this.listeners.add(listener);
484
+ }
485
+ removeListener(listener) {
486
+ this.listeners.delete(listener);
487
+ }
488
+ }
489
+ const STORAGE_NS = "_WM-STORAGE_";
490
+ class Storage {
491
+ constructor(context2, id, defaultState) {
492
+ this._sideEffect = new SideEffectManager();
493
+ this._destroyed = false;
494
+ this._refMap = new WeakMap();
495
+ this._lastValue = new Map();
496
+ this.onStateChanged = new StorageEvent();
497
+ if (defaultState && !isObject(defaultState)) {
498
+ throw new Error(`Default state for Storage ${id} is not an object.`);
499
+ }
500
+ this._context = context2;
501
+ this.id = id || null;
502
+ this._state = {};
503
+ const rawState = this._getRawState(this._state);
504
+ if (this.id !== null && this._context.getIsWritable()) {
505
+ if (rawState === this._state || !isObject(rawState)) {
506
+ if (!get(this._context.getAttributes(), [STORAGE_NS])) {
507
+ this._context.updateAttributes([STORAGE_NS], {});
508
+ }
509
+ this._context.updateAttributes([STORAGE_NS, this.id], this._state);
510
+ }
511
+ if (defaultState) {
512
+ this.setState(defaultState);
513
+ }
514
+ }
515
+ plainObjectKeys(rawState).forEach((key) => {
516
+ if (this.id === null && key === STORAGE_NS) {
517
+ return;
518
+ }
519
+ try {
520
+ const rawValue = isObject(rawState[key]) ? JSON.parse(JSON.stringify(rawState[key])) : rawState[key];
521
+ if (isRef(rawValue)) {
522
+ this._state[key] = rawValue.v;
523
+ if (isObject(rawValue.v)) {
524
+ this._refMap.set(rawValue.v, rawValue);
525
+ }
526
+ } else {
527
+ this._state[key] = rawValue;
528
+ }
529
+ } catch (e) {
530
+ console.error(e);
531
+ }
532
+ });
533
+ this._sideEffect.addDisposer(safeListenPropsUpdated(() => this.id === null ? context2.getAttributes() : get(context2.getAttributes(), [STORAGE_NS, this.id]), this._updateProperties.bind(this), this.destroy.bind(this)));
534
+ }
535
+ get state() {
536
+ if (this._destroyed) {
537
+ console.warn(`Accessing state on destroyed Storage "${this.id}"`);
538
+ }
539
+ return this._state;
540
+ }
541
+ addStateChangedListener(handler) {
542
+ this.onStateChanged.addListener(handler);
543
+ return () => this.onStateChanged.removeListener(handler);
544
+ }
545
+ ensureState(state) {
546
+ return this.setState(plainObjectKeys(state).reduce((payload, key) => {
547
+ if (!has(this._state, key)) {
548
+ payload[key] = state[key];
549
+ }
550
+ return payload;
551
+ }, {}));
552
+ }
553
+ setState(state) {
554
+ if (this._destroyed) {
555
+ console.error(new Error(`Cannot call setState on destroyed Storage "${this.id}".`));
556
+ return;
557
+ }
558
+ if (!this._context.getIsWritable()) {
559
+ console.error(new Error(`Cannot setState on Storage "${this.id}" without writable access`), state);
560
+ return;
561
+ }
562
+ const keys = plainObjectKeys(state);
563
+ if (keys.length > 0) {
564
+ keys.forEach((key) => {
565
+ const value = state[key];
566
+ if (value === this._state[key]) {
567
+ return;
568
+ }
569
+ if (value === void 0) {
570
+ this._lastValue.set(key, this._state[key]);
571
+ delete this._state[key];
572
+ this._setRawState(key, value);
573
+ } else {
574
+ this._lastValue.set(key, this._state[key]);
575
+ this._state[key] = value;
576
+ let payload = value;
577
+ if (isObject(value)) {
578
+ let refValue = this._refMap.get(value);
579
+ if (!refValue) {
580
+ refValue = makeRef(value);
581
+ this._refMap.set(value, refValue);
582
+ }
583
+ payload = refValue;
584
+ }
585
+ this._setRawState(key, payload);
586
+ }
587
+ });
588
+ }
589
+ }
590
+ emptyStorage() {
591
+ if (size(this._state) <= 0) {
592
+ return;
593
+ }
594
+ if (this._destroyed) {
595
+ console.error(new Error(`Cannot empty destroyed Storage "${this.id}".`));
596
+ return;
597
+ }
598
+ if (!this._context.getIsWritable()) {
599
+ console.error(new Error(`Cannot empty Storage "${this.id}" without writable access.`));
600
+ return;
601
+ }
602
+ this.setState(mapValues(this._state, noop$1));
603
+ }
604
+ deleteStorage() {
605
+ if (this.id === null) {
606
+ throw new Error(`Cannot delete main Storage`);
607
+ }
608
+ if (!this._context.getIsWritable()) {
609
+ console.error(new Error(`Cannot delete Storage "${this.id}" without writable access.`));
610
+ return;
611
+ }
612
+ this.destroy();
613
+ this._context.updateAttributes([STORAGE_NS, this.id], void 0);
614
+ }
615
+ get destroyed() {
616
+ return this._destroyed;
617
+ }
618
+ destroy() {
619
+ this._destroyed = true;
620
+ this._sideEffect.flushAll();
621
+ }
622
+ _getRawState(defaultValue) {
623
+ if (this.id === null) {
624
+ return get(this._context.getAttributes(), [], defaultValue);
625
+ } else {
626
+ return get(this._context.getAttributes(), [STORAGE_NS, this.id], defaultValue);
627
+ }
628
+ }
629
+ _setRawState(key, value) {
630
+ if (this.id === null) {
631
+ if (key === STORAGE_NS) {
632
+ throw new Error(`Cannot set attribute internal filed "${STORAGE_NS}"`);
633
+ }
634
+ return this._context.updateAttributes([key], value);
635
+ } else {
636
+ return this._context.updateAttributes([STORAGE_NS, this.id, key], value);
637
+ }
638
+ }
639
+ _updateProperties(actions) {
640
+ var _a;
641
+ if (this._destroyed) {
642
+ console.error(new Error(`Cannot call _updateProperties on destroyed Storage "${this.id}".`));
643
+ return;
644
+ }
645
+ if (actions.length > 0) {
646
+ const diffs = {};
647
+ for (let i = 0; i < actions.length; i++) {
648
+ try {
649
+ const action = actions[i];
650
+ const key = action.key;
651
+ if (this.id === null && key === STORAGE_NS) {
652
+ continue;
653
+ }
654
+ const value = isObject(action.value) ? JSON.parse(JSON.stringify(action.value)) : action.value;
655
+ let oldValue;
656
+ if (this._lastValue.has(key)) {
657
+ oldValue = this._lastValue.get(key);
658
+ this._lastValue.delete(key);
659
+ }
660
+ switch (action.kind) {
661
+ case 2: {
662
+ if (has(this._state, key)) {
663
+ oldValue = this._state[key];
664
+ delete this._state[key];
665
+ }
666
+ diffs[key] = { oldValue };
667
+ break;
668
+ }
669
+ default: {
670
+ let newValue = value;
671
+ if (isRef(value)) {
672
+ const { k, v } = value;
673
+ const curValue = this._state[key];
674
+ if (isObject(curValue) && ((_a = this._refMap.get(curValue)) == null ? void 0 : _a.k) === k) {
675
+ newValue = curValue;
676
+ } else {
677
+ newValue = v;
678
+ if (isObject(v)) {
679
+ this._refMap.set(v, value);
680
+ }
681
+ }
682
+ }
683
+ if (newValue !== this._state[key]) {
684
+ oldValue = this._state[key];
685
+ this._state[key] = newValue;
686
+ }
687
+ diffs[key] = { newValue, oldValue };
688
+ break;
689
+ }
690
+ }
691
+ } catch (e) {
692
+ console.error(e);
693
+ }
694
+ }
695
+ this.onStateChanged.dispatch(diffs);
696
+ }
697
+ }
698
+ }
699
+ class AppContext {
700
+ constructor(manager, boxManager, appId, appProxy, appOptions) {
701
+ this.manager = manager;
702
+ this.boxManager = boxManager;
703
+ this.appId = appId;
704
+ this.appProxy = appProxy;
705
+ this.appOptions = appOptions;
706
+ this.mobxUtils = {
707
+ autorun,
708
+ reaction,
709
+ toJS
710
+ };
711
+ this.objectUtils = {
712
+ listenUpdated,
713
+ unlistenUpdated,
714
+ listenDisposed,
715
+ unlistenDisposed
716
+ };
717
+ this.store = this.manager.store;
718
+ this.isReplay = this.manager.isReplay;
719
+ this.getDisplayer = () => {
720
+ return this.manager.displayer;
721
+ };
722
+ this.getAttributes = () => {
723
+ return this.appProxy.attributes;
724
+ };
725
+ this.getScenes = () => {
726
+ const appAttr = this.store.getAppAttributes(this.appId);
727
+ if (appAttr == null ? void 0 : appAttr.isDynamicPPT) {
728
+ return this.appProxy.scenes;
729
+ } else {
730
+ return appAttr == null ? void 0 : appAttr.options["scenes"];
731
+ }
732
+ };
733
+ this.getView = () => {
734
+ return this.appProxy.view;
735
+ };
736
+ this.getInitScenePath = () => {
737
+ return this.manager.getAppInitPath(this.appId);
738
+ };
739
+ this.getIsWritable = () => {
740
+ return this.manager.canOperate;
741
+ };
742
+ this.getBox = () => {
743
+ const box = this.boxManager.getBox(this.appId);
744
+ if (box) {
745
+ return box;
746
+ } else {
747
+ throw new BoxNotCreatedError();
748
+ }
749
+ };
750
+ this.getRoom = () => {
751
+ return this.manager.room;
752
+ };
753
+ this.setAttributes = (attributes) => {
754
+ this.manager.safeSetAttributes({ [this.appId]: attributes });
755
+ };
756
+ this.updateAttributes = (keys, value) => {
757
+ if (this.manager.attributes[this.appId]) {
758
+ this.manager.safeUpdateAttributes([this.appId, ...keys], value);
759
+ }
760
+ };
761
+ this.setScenePath = async (scenePath) => {
762
+ var _a;
763
+ if (!this.appProxy.box)
764
+ return;
765
+ this.appProxy.setFullPath(scenePath);
766
+ (_a = this.getRoom()) == null ? void 0 : _a.setScenePath(scenePath);
767
+ };
768
+ this.mountView = (dom) => {
769
+ const view = this.getView();
770
+ if (view) {
771
+ view.divElement = dom;
772
+ setTimeout(() => {
773
+ var _a;
774
+ (_a = this.getRoom()) == null ? void 0 : _a.refreshViewSize();
775
+ }, 1e3);
776
+ }
777
+ };
778
+ this.getAppOptions = () => {
779
+ return typeof this.appOptions === "function" ? this.appOptions() : this.appOptions;
780
+ };
781
+ this.createStorage = (storeId, defaultState) => {
782
+ const storage = new Storage(this, storeId, defaultState);
783
+ this.emitter.on("destroy", () => {
784
+ storage.destroy();
785
+ });
786
+ return storage;
787
+ };
788
+ this.dispatchMagixEvent = this.manager.displayer.dispatchMagixEvent.bind(this.manager.displayer);
789
+ this.addMagixEventListener = (event, handler, options) => {
790
+ this.manager.displayer.addMagixEventListener(event, handler, options);
791
+ return () => this.manager.displayer.removeMagixEventListener(event, handler);
792
+ };
793
+ this.removeMagixEventListener = this.manager.displayer.removeMagixEventListener.bind(this.manager.displayer);
794
+ this.emitter = appProxy.appEmitter;
795
+ this.isAddApp = appProxy.isAddApp;
796
+ }
797
+ get storage() {
798
+ if (!this._storage) {
799
+ this._storage = new Storage(this);
800
+ }
801
+ return this._storage;
802
+ }
803
+ }
804
+ var Fields;
805
+ (function(Fields2) {
806
+ Fields2["Apps"] = "apps";
807
+ Fields2["Focus"] = "focus";
808
+ Fields2["State"] = "state";
809
+ Fields2["BoxState"] = "boxState";
810
+ Fields2["MainViewCamera"] = "mainViewCamera";
811
+ Fields2["MainViewSize"] = "mainViewSize";
812
+ Fields2["Broadcaster"] = "broadcaster";
813
+ Fields2["Cursors"] = "cursors";
814
+ Fields2["Position"] = "position";
815
+ Fields2["CursorState"] = "cursorState";
816
+ Fields2["FullPath"] = "fullPath";
817
+ })(Fields || (Fields = {}));
818
+ class AttributesDelegate {
819
+ constructor(context2) {
820
+ this.context = context2;
821
+ }
822
+ setContext(context2) {
823
+ this.context = context2;
824
+ }
825
+ get attributes() {
826
+ return this.context.getAttributes();
827
+ }
828
+ apps() {
829
+ return get(this.attributes, [Fields.Apps]);
830
+ }
831
+ get focus() {
832
+ return get(this.attributes, [Fields.Focus]);
833
+ }
834
+ getAppAttributes(id) {
835
+ return get(this.apps(), [id]);
836
+ }
837
+ getAppState(id) {
838
+ return get(this.apps(), [id, Fields.State]);
839
+ }
840
+ getMaximized() {
841
+ return get(this.attributes, ["maximized"]);
842
+ }
843
+ getMinimized() {
844
+ return get(this.attributes, ["minimized"]);
845
+ }
846
+ setupAppAttributes(params, id, isDynamicPPT) {
847
+ const attributes = this.attributes;
848
+ if (!attributes.apps) {
849
+ this.context.safeSetAttributes({ apps: {} });
850
+ }
851
+ const attrNames = ["scenePath", "title"];
852
+ if (!isDynamicPPT) {
853
+ attrNames.push("scenes");
854
+ }
855
+ const options = pick(params.options, attrNames);
856
+ const attrs = { kind: params.kind, options, isDynamicPPT };
857
+ if (typeof params.src === "string") {
858
+ attrs.src = params.src;
859
+ }
860
+ attrs.createdAt = Date.now();
861
+ this.context.safeUpdateAttributes([Fields.Apps, id], attrs);
862
+ this.context.safeUpdateAttributes([Fields.Apps, id, Fields.State], {
863
+ [AppAttributes.Size]: {},
864
+ [AppAttributes.Position]: {},
865
+ [AppAttributes.SceneIndex]: 0
866
+ });
867
+ }
868
+ updateAppState(appId, stateName, state) {
869
+ if (get(this.attributes, [Fields.Apps, appId, Fields.State])) {
870
+ this.context.safeUpdateAttributes([Fields.Apps, appId, Fields.State, stateName], state);
871
+ }
872
+ }
873
+ cleanAppAttributes(id) {
874
+ this.context.safeUpdateAttributes([Fields.Apps, id], void 0);
875
+ this.context.safeSetAttributes({ [id]: void 0 });
876
+ const focus = this.attributes[Fields.Focus];
877
+ if (focus === id) {
878
+ this.cleanFocus();
879
+ }
880
+ }
881
+ cleanFocus() {
882
+ this.context.safeSetAttributes({ [Fields.Focus]: void 0 });
883
+ }
884
+ getAppSceneIndex(id) {
885
+ var _a;
886
+ return (_a = this.getAppState(id)) == null ? void 0 : _a[AppAttributes.SceneIndex];
887
+ }
888
+ getAppScenePath(id) {
889
+ var _a, _b;
890
+ return (_b = (_a = this.getAppAttributes(id)) == null ? void 0 : _a.options) == null ? void 0 : _b.scenePath;
891
+ }
892
+ getMainViewScenePath() {
893
+ return this.attributes["_mainScenePath"];
894
+ }
895
+ getMainViewSceneIndex() {
896
+ return this.attributes["_mainSceneIndex"];
897
+ }
898
+ getBoxState() {
899
+ return this.attributes[Fields.BoxState];
900
+ }
901
+ setMainViewScenePath(scenePath) {
902
+ this.context.safeSetAttributes({ _mainScenePath: scenePath });
903
+ }
904
+ setMainViewSceneIndex(index) {
905
+ this.context.safeSetAttributes({ _mainSceneIndex: index });
906
+ }
907
+ getMainViewCamera() {
908
+ return get(this.attributes, [Fields.MainViewCamera]);
909
+ }
910
+ getMainViewSize() {
911
+ return get(this.attributes, [Fields.MainViewSize]);
912
+ }
913
+ setMainViewCamera(camera) {
914
+ this.context.safeSetAttributes({ [Fields.MainViewCamera]: __spreadValues({}, camera) });
915
+ }
916
+ setMainViewSize(size2) {
917
+ this.context.safeSetAttributes({ [Fields.MainViewSize]: __spreadValues({}, size2) });
918
+ }
919
+ setAppFocus(appId, focus) {
920
+ if (focus) {
921
+ this.context.safeSetAttributes({ [Fields.Focus]: appId });
922
+ } else {
923
+ this.context.safeSetAttributes({ [Fields.Focus]: void 0 });
924
+ }
925
+ }
926
+ updateCursor(uid, position) {
927
+ if (!get(this.attributes, [Fields.Cursors])) {
928
+ this.context.safeUpdateAttributes([Fields.Cursors], {});
929
+ }
930
+ if (!get(this.attributes, [Fields.Cursors, uid])) {
931
+ this.context.safeUpdateAttributes([Fields.Cursors, uid], {});
932
+ }
933
+ this.context.safeUpdateAttributes([Fields.Cursors, uid, Fields.Position], position);
934
+ }
935
+ updateCursorState(uid, cursorState) {
936
+ if (!get(this.attributes, [Fields.Cursors, uid])) {
937
+ this.context.safeUpdateAttributes([Fields.Cursors, uid], {});
938
+ }
939
+ this.context.safeUpdateAttributes([Fields.Cursors, uid, Fields.CursorState], cursorState);
940
+ }
941
+ getCursorState(uid) {
942
+ return get(this.attributes, [Fields.Cursors, uid, Fields.CursorState]);
943
+ }
944
+ cleanCursor(uid) {
945
+ this.context.safeUpdateAttributes([Fields.Cursors, uid], void 0);
946
+ }
947
+ setMainViewFocusPath(mainView) {
948
+ const scenePath = this.getMainViewScenePath();
949
+ if (scenePath) {
950
+ setViewFocusScenePath(mainView, scenePath);
951
+ }
952
+ }
953
+ }
954
+ const store = new AttributesDelegate({
955
+ getAttributes: () => {
956
+ throw new Error("getAttributes not implemented");
957
+ },
958
+ safeSetAttributes: () => {
959
+ throw new Error("safeSetAttributes not implemented");
960
+ },
961
+ safeUpdateAttributes: () => {
962
+ throw new Error("safeUpdateAttributes not implemented");
963
+ }
964
+ });
965
+ const log = (...args) => {
966
+ if (WindowManager.debug) {
967
+ console.log(`[WindowManager]:`, ...args);
968
+ }
969
+ };
970
+ class Context {
971
+ constructor(manager) {
972
+ this.manager = manager;
973
+ this.findMember = (memberId) => {
974
+ var _a;
975
+ const roomMembers = (_a = this.manager.room) == null ? void 0 : _a.state.roomMembers;
976
+ return roomMembers == null ? void 0 : roomMembers.find((member) => member.memberId === memberId);
977
+ };
978
+ this.findMemberByUid = (uid) => {
979
+ var _a;
980
+ const roomMembers = (_a = this.manager.room) == null ? void 0 : _a.state.roomMembers;
981
+ return roomMembers == null ? void 0 : roomMembers.find((member) => {
982
+ var _a2;
983
+ return ((_a2 = member.payload) == null ? void 0 : _a2.uid) === uid;
984
+ });
985
+ };
986
+ this.observerId = manager.displayer.observerId;
987
+ emitter.on("observerIdChange", (id) => {
988
+ this.observerId = id;
989
+ });
990
+ }
991
+ get uid() {
992
+ var _a;
993
+ return ((_a = this.manager.room) == null ? void 0 : _a.uid) || "";
994
+ }
995
+ updateManagerRect() {
996
+ var _a;
997
+ (_a = this.manager.boxManager) == null ? void 0 : _a.updateManagerRect();
998
+ }
999
+ blurFocusBox() {
1000
+ var _a;
1001
+ (_a = this.manager.boxManager) == null ? void 0 : _a.blurAllBox();
1002
+ }
1003
+ }
1004
+ let context;
1005
+ const createContext = (manager) => {
1006
+ if (!context) {
1007
+ context = new Context(manager);
1008
+ }
1009
+ return context;
1010
+ };
1011
+ class Base {
1012
+ constructor(manager) {
1013
+ this.manager = manager;
1014
+ this.store = store;
1015
+ this.context = createContext(this.manager);
1016
+ }
1017
+ }
1018
+ class AppProxy extends Base {
1019
+ constructor(params, manager, appId, isAddApp) {
1020
+ super(manager);
1021
+ var _a;
1022
+ this.params = params;
1023
+ this.boxManager = this.manager.boxManager;
1024
+ this.appProxies = this.manager.appProxies;
1025
+ this.viewManager = this.manager.viewManager;
1026
+ this.status = "normal";
1027
+ this.getAppInitState = (id) => {
1028
+ var _a2, _b;
1029
+ const attrs = this.store.getAppState(id);
1030
+ if (!attrs)
1031
+ return;
1032
+ const position = attrs == null ? void 0 : attrs[AppAttributes.Position];
1033
+ const focus = this.store.focus;
1034
+ const size2 = attrs == null ? void 0 : attrs[AppAttributes.Size];
1035
+ const sceneIndex = attrs == null ? void 0 : attrs[AppAttributes.SceneIndex];
1036
+ const maximized = (_a2 = this.attributes) == null ? void 0 : _a2["maximized"];
1037
+ const minimized = (_b = this.attributes) == null ? void 0 : _b["minimized"];
1038
+ const zIndex = attrs == null ? void 0 : attrs.zIndex;
1039
+ let payload = { maximized, minimized, zIndex };
1040
+ if (position) {
1041
+ payload = __spreadProps(__spreadValues({}, payload), { id, x: position.x, y: position.y });
1042
+ }
1043
+ if (focus === id) {
1044
+ payload = __spreadProps(__spreadValues({}, payload), { focus: true });
1045
+ }
1046
+ if (size2) {
1047
+ payload = __spreadProps(__spreadValues({}, payload), { width: size2.width, height: size2.height });
1048
+ }
1049
+ if (sceneIndex) {
1050
+ payload = __spreadProps(__spreadValues({}, payload), { sceneIndex });
1051
+ }
1052
+ return payload;
1053
+ };
1054
+ this.appAttributesUpdateListener = (appId2) => {
1055
+ var _a2, _b, _c;
1056
+ (_a2 = this.manager.refresher) == null ? void 0 : _a2.add(appId2, () => {
1057
+ return autorun(() => {
1058
+ const attrs = this.manager.attributes[appId2];
1059
+ if (attrs) {
1060
+ this.appEmitter.emit("attributesUpdate", attrs);
1061
+ }
1062
+ });
1063
+ });
1064
+ (_b = this.manager.refresher) == null ? void 0 : _b.add(this.stateKey, () => {
1065
+ return autorun(() => {
1066
+ var _a3, _b2, _c2;
1067
+ const appState = (_a3 = this.appAttributes) == null ? void 0 : _a3.state;
1068
+ if ((appState == null ? void 0 : appState.zIndex) > 0 && appState.zIndex !== ((_b2 = this.box) == null ? void 0 : _b2.zIndex)) {
1069
+ (_c2 = this.boxManager) == null ? void 0 : _c2.setZIndex(appId2, appState.zIndex);
1070
+ }
1071
+ });
1072
+ });
1073
+ (_c = this.manager.refresher) == null ? void 0 : _c.add(`${appId2}-fullPath`, () => {
1074
+ return autorun(() => {
1075
+ var _a3;
1076
+ const fullPath = (_a3 = this.appAttributes) == null ? void 0 : _a3.fullPath;
1077
+ this.setFocusScenePathHandler(fullPath);
1078
+ });
1079
+ });
1080
+ };
1081
+ this.setFocusScenePathHandler = debounce((fullPath) => {
1082
+ var _a2;
1083
+ if (this.view && fullPath && fullPath !== ((_a2 = this.view) == null ? void 0 : _a2.focusScenePath)) {
1084
+ setViewFocusScenePath(this.view, fullPath);
1085
+ }
1086
+ }, 50);
1087
+ this.kind = params.kind;
1088
+ this.id = appId;
1089
+ this.stateKey = `${this.id}_state`;
1090
+ this.appProxies.set(this.id, this);
1091
+ this.appEmitter = new Emittery();
1092
+ this.appListener = this.makeAppEventListener(this.id);
1093
+ this.isAddApp = isAddApp;
1094
+ this.initScenes();
1095
+ if ((_a = this.params.options) == null ? void 0 : _a.scenePath) {
1096
+ this.createView();
1097
+ }
1098
+ }
1099
+ initScenes() {
1100
+ var _a;
1101
+ const options = this.params.options;
1102
+ if (options) {
1103
+ this.scenePath = options.scenePath;
1104
+ if (((_a = this.appAttributes) == null ? void 0 : _a.isDynamicPPT) && this.scenePath) {
1105
+ this.scenes = this.manager.displayer.entireScenes()[this.scenePath];
1106
+ } else {
1107
+ this.scenes = options.scenes;
1108
+ }
1109
+ }
1110
+ }
1111
+ get view() {
1112
+ return this.manager.viewManager.getView(this.id);
1113
+ }
1114
+ get isWritable() {
1115
+ var _a;
1116
+ return this.manager.canOperate && !((_a = this.box) == null ? void 0 : _a.readonly);
1117
+ }
1118
+ get attributes() {
1119
+ return this.manager.attributes[this.id];
1120
+ }
1121
+ get appAttributes() {
1122
+ return this.store.getAppAttributes(this.id);
1123
+ }
1124
+ getFullScenePath() {
1125
+ if (this.scenePath) {
1126
+ return get(this.appAttributes, [Fields.FullPath], this.getFullScenePathFromScenes());
1127
+ }
1128
+ }
1129
+ getFullScenePathFromScenes() {
1130
+ const sceneIndex = get(this.appAttributes, ["state", "SceneIndex"], 0);
1131
+ const fullPath = getScenePath(this.manager.room, this.scenePath, sceneIndex);
1132
+ if (fullPath) {
1133
+ this.setFullPath(fullPath);
1134
+ }
1135
+ return fullPath;
1136
+ }
1137
+ setFullPath(path) {
1138
+ this.manager.safeUpdateAttributes(["apps", this.id, Fields.FullPath], path);
1139
+ }
1140
+ async baseInsertApp(skipUpdate = false) {
1141
+ var _a;
1142
+ const params = this.params;
1143
+ if (!params.kind) {
1144
+ throw new Error("[WindowManager]: kind require");
1145
+ }
1146
+ const appImpl = await ((_a = appRegister.appClasses.get(params.kind)) == null ? void 0 : _a());
1147
+ const appParams = appRegister.registered.get(params.kind);
1148
+ if (appImpl) {
1149
+ await this.setupApp(this.id, skipUpdate, appImpl, params.options, appParams == null ? void 0 : appParams.appOptions);
1150
+ } else {
1151
+ throw new Error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
1152
+ }
1153
+ this.context.updateManagerRect();
1154
+ return {
1155
+ appId: this.id,
1156
+ app: appImpl
1157
+ };
1158
+ }
1159
+ focusApp() {
1160
+ this.focusBox();
1161
+ this.store.setMainViewFocusPath(this.manager.mainView);
1162
+ }
1163
+ get box() {
1164
+ var _a;
1165
+ return (_a = this.boxManager) == null ? void 0 : _a.getBox(this.id);
1166
+ }
1167
+ focusBox() {
1168
+ var _a;
1169
+ (_a = this.boxManager) == null ? void 0 : _a.focusBox({ appId: this.id });
1170
+ }
1171
+ async setupApp(appId, skipUpdate, app, options, appOptions) {
1172
+ var _a;
1173
+ log("setupApp", appId, app, options);
1174
+ if (!this.boxManager) {
1175
+ throw new BoxManagerNotFoundError();
1176
+ }
1177
+ const context2 = new AppContext(this.manager, this.boxManager, appId, this, appOptions);
1178
+ this.appContext = context2;
1179
+ try {
1180
+ emitter.once(`${appId}${Events.WindowCreated}`).then(async () => {
1181
+ var _a2;
1182
+ let boxInitState;
1183
+ if (!skipUpdate) {
1184
+ boxInitState = this.getAppInitState(appId);
1185
+ (_a2 = this.boxManager) == null ? void 0 : _a2.updateBoxState(boxInitState);
1186
+ }
1187
+ this.appEmitter.onAny(this.appListener);
1188
+ this.appAttributesUpdateListener(appId);
1189
+ this.setViewFocusScenePath();
1190
+ setTimeout(async () => {
1191
+ const result = await app.setup(context2);
1192
+ this.appResult = result;
1193
+ appRegister.notifyApp(app.kind, "created", { appId, result });
1194
+ this.afterSetupApp(boxInitState);
1195
+ this.fixMobileSize();
1196
+ }, 50);
1197
+ });
1198
+ (_a = this.boxManager) == null ? void 0 : _a.createBox({
1199
+ appId,
1200
+ app,
1201
+ options,
1202
+ canOperate: this.manager.canOperate,
1203
+ smartPosition: this.isAddApp
1204
+ });
1205
+ } catch (error) {
1206
+ console.error(error);
1207
+ throw new Error(`[WindowManager]: app setup error: ${error.message}`);
1208
+ }
1209
+ }
1210
+ fixMobileSize() {
1211
+ var _a, _b;
1212
+ const box = (_a = this.boxManager) == null ? void 0 : _a.getBox(this.id);
1213
+ if (box) {
1214
+ (_b = this.boxManager) == null ? void 0 : _b.resizeBox({
1215
+ appId: this.id,
1216
+ width: box.intrinsicWidth + 1e-3,
1217
+ height: box.intrinsicHeight + 1e-3,
1218
+ skipUpdate: true
1219
+ });
1220
+ }
1221
+ }
1222
+ afterSetupApp(boxInitState) {
1223
+ var _a;
1224
+ if (boxInitState) {
1225
+ if (!(boxInitState == null ? void 0 : boxInitState.x) || !boxInitState.y) {
1226
+ (_a = this.boxManager) == null ? void 0 : _a.setBoxInitState(this.id);
1227
+ }
1228
+ }
1229
+ }
1230
+ onSeek(time) {
1231
+ var _a;
1232
+ this.appEmitter.emit("seek", time);
1233
+ const boxInitState = this.getAppInitState(this.id);
1234
+ (_a = this.boxManager) == null ? void 0 : _a.updateBoxState(boxInitState);
1235
+ }
1236
+ async onReconnected() {
1237
+ var _a;
1238
+ this.appEmitter.emit("reconnected", void 0);
1239
+ const currentAppState = this.getAppInitState(this.id);
1240
+ await this.destroy(true, false, true);
1241
+ const params = this.params;
1242
+ const appProxy = new AppProxy(params, this.manager, this.id, this.isAddApp);
1243
+ await appProxy.baseInsertApp(true);
1244
+ (_a = this.boxManager) == null ? void 0 : _a.updateBoxState(currentAppState);
1245
+ }
1246
+ emitAppSceneStateChange(sceneState) {
1247
+ this.appEmitter.emit("sceneStateChange", sceneState);
1248
+ }
1249
+ emitAppIsWritableChange() {
1250
+ this.appEmitter.emit("writableChange", this.isWritable);
1251
+ }
1252
+ makeAppEventListener(appId) {
1253
+ return (eventName, data) => {
1254
+ var _a, _b, _c, _d;
1255
+ if (!this.manager.canOperate)
1256
+ return;
1257
+ switch (eventName) {
1258
+ case "setBoxSize": {
1259
+ (_a = this.boxManager) == null ? void 0 : _a.resizeBox({
1260
+ appId,
1261
+ width: data.width,
1262
+ height: data.height,
1263
+ skipUpdate: false
1264
+ });
1265
+ break;
1266
+ }
1267
+ case "setBoxMinSize": {
1268
+ (_b = this.boxManager) == null ? void 0 : _b.setBoxMinSize({
1269
+ appId,
1270
+ minWidth: data.minwidth,
1271
+ minHeight: data.minheight
1272
+ });
1273
+ break;
1274
+ }
1275
+ case "setBoxTitle": {
1276
+ (_c = this.boxManager) == null ? void 0 : _c.setBoxTitle({ appId, title: data.title });
1277
+ break;
1278
+ }
1279
+ case AppEvents.destroy: {
1280
+ if (this.status === "destroyed")
1281
+ return;
1282
+ this.destroy(true, false, true, data == null ? void 0 : data.error);
1283
+ if (data == null ? void 0 : data.error) {
1284
+ console.error(data == null ? void 0 : data.error);
1285
+ }
1286
+ break;
1287
+ }
1288
+ case "focus": {
1289
+ (_d = this.boxManager) == null ? void 0 : _d.focusBox({ appId: this.id });
1290
+ emitter.emit("focus", { appId: this.id });
1291
+ break;
1292
+ }
1293
+ }
1294
+ };
1295
+ }
1296
+ setScenePath() {
1297
+ if (!this.manager.canOperate)
1298
+ return;
1299
+ const fullScenePath = this.getFullScenePath();
1300
+ if (this.manager.room && fullScenePath && this.view) {
1301
+ setScenePath(this.manager.room, fullScenePath);
1302
+ }
1303
+ }
1304
+ setViewFocusScenePath() {
1305
+ const fullPath = this.getFullScenePath();
1306
+ if (fullPath && this.view) {
1307
+ setViewFocusScenePath(this.view, fullPath);
1308
+ }
1309
+ }
1310
+ async createView() {
1311
+ const view = await this.viewManager.createView(this.id);
1312
+ this.setViewFocusScenePath();
1313
+ return view;
1314
+ }
1315
+ async destroy(needCloseBox, cleanAttrs, skipUpdate, error) {
1316
+ var _a, _b, _c, _d;
1317
+ if (this.status === "destroyed")
1318
+ return;
1319
+ this.status = "destroyed";
1320
+ await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
1321
+ await this.appEmitter.emit("destroy", { error });
1322
+ this.appEmitter.clearListeners();
1323
+ emitter.emit(`destroy-${this.id}`, { error });
1324
+ if (needCloseBox) {
1325
+ (_a = this.boxManager) == null ? void 0 : _a.closeBox(this.id, skipUpdate);
1326
+ }
1327
+ if (cleanAttrs) {
1328
+ this.store.cleanAppAttributes(this.id);
1329
+ if (this.scenePath) {
1330
+ removeScenes(this.manager.room, this.scenePath);
1331
+ }
1332
+ }
1333
+ this.appProxies.delete(this.id);
1334
+ this.viewManager.destroyView(this.id);
1335
+ this.manager.appStatus.delete(this.id);
1336
+ (_b = this.manager.refresher) == null ? void 0 : _b.remove(this.id);
1337
+ (_c = this.manager.refresher) == null ? void 0 : _c.remove(this.stateKey);
1338
+ (_d = this.manager.refresher) == null ? void 0 : _d.remove(`${this.id}-fullPath`);
1339
+ }
1340
+ close() {
1341
+ return this.destroy(true, true, false);
1342
+ }
1343
+ }
1344
+ class ViewManager {
1345
+ constructor(displayer) {
1346
+ this.displayer = displayer;
1347
+ this.views = new Map();
1348
+ }
1349
+ createView(id) {
1350
+ const view = createView(this.displayer);
1351
+ this.views.set(id, view);
1352
+ return view;
1353
+ }
1354
+ getView(id) {
1355
+ return this.views.get(id);
1356
+ }
1357
+ destroyView(id) {
1358
+ const view = this.views.get(id);
1359
+ if (view) {
1360
+ view.release();
1361
+ this.views.delete(id);
1362
+ }
1363
+ }
1364
+ setViewScenePath(id, scenePath) {
1365
+ const view = this.views.get(id);
1366
+ if (view) {
1367
+ view.focusScenePath = scenePath;
1368
+ }
1369
+ }
1370
+ destroy() {
1371
+ this.views.forEach((view) => {
1372
+ view.release();
1373
+ });
1374
+ this.views.clear();
1375
+ }
1376
+ }
1377
+ const createView = (displayer) => {
1378
+ const view = displayer.views.createView();
1379
+ setDefaultCameraBound(view);
1380
+ return view;
1381
+ };
1382
+ const setDefaultCameraBound = (view) => {
1383
+ view.setCameraBound({
1384
+ maxContentMode: () => 10,
1385
+ minContentMode: () => 0.1
1386
+ });
1387
+ };
1388
+ class MainViewProxy extends Base {
1389
+ constructor(manager) {
1390
+ super(manager);
1391
+ this.started = false;
1392
+ this.mainViewIsAddListener = false;
1393
+ this.viewId = "mainView";
1394
+ this.sideEffectManager = new SideEffectManager();
1395
+ this.cameraReaction = () => {
1396
+ return reaction(() => this.mainViewCamera, (camera) => {
1397
+ if (camera && camera.id !== this.context.uid) {
1398
+ this.moveCameraToContian(this.mainViewSize);
1399
+ this.moveCamera(camera);
1400
+ }
1401
+ }, {
1402
+ fireImmediately: true
1403
+ });
1404
+ };
1405
+ this.sizeChangeHandler = debounce((size2) => {
1406
+ if (size2) {
1407
+ this.moveCameraToContian(size2);
1408
+ this.moveCamera(this.mainViewCamera);
1409
+ }
1410
+ }, 30);
1411
+ this.onCameraUpdatedByDevice = (camera) => {
1412
+ this.store.setMainViewCamera(__spreadProps(__spreadValues({}, camera), { id: this.context.uid }));
1413
+ if (!isEqual(this.mainViewSize, __spreadProps(__spreadValues({}, this.mainView.size), { id: this.context.uid }))) {
1414
+ this.setMainViewSize(this.view.size);
1415
+ }
1416
+ };
1417
+ this.mainViewClickListener = () => {
1418
+ this.mainViewClickHandler();
1419
+ };
1420
+ this.setMainViewSize = debounce((size2) => {
1421
+ this.store.setMainViewSize(__spreadProps(__spreadValues({}, size2), { id: this.context.uid }));
1422
+ }, 50);
1423
+ this.onCameraOrSizeUpdated = () => {
1424
+ callbacks.emit("cameraStateChange", this.cameraState);
1425
+ };
1426
+ this.mainView = this.createMainView();
1427
+ this.moveCameraSizeByAttributes();
1428
+ emitter.once("mainViewMounted").then(() => {
1429
+ this.addMainViewListener();
1430
+ setTimeout(() => {
1431
+ this.start();
1432
+ if (!this.mainViewCamera || !this.mainViewSize) {
1433
+ this.setCameraAndSize();
1434
+ }
1435
+ }, 200);
1436
+ });
1437
+ const playgroundSizeChangeListener = () => {
1438
+ this.sizeChangeHandler(this.mainViewSize);
1439
+ };
1440
+ this.sideEffectManager.add(() => {
1441
+ emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
1442
+ return () => emitter.off("playgroundSizeChange", playgroundSizeChangeListener);
1443
+ });
1444
+ }
1445
+ get mainViewCamera() {
1446
+ return this.store.getMainViewCamera();
1447
+ }
1448
+ get mainViewSize() {
1449
+ return this.store.getMainViewSize();
1450
+ }
1451
+ moveCameraSizeByAttributes() {
1452
+ this.moveCameraToContian(this.mainViewSize);
1453
+ this.moveCamera(this.mainViewCamera);
1454
+ }
1455
+ start() {
1456
+ var _a;
1457
+ if (this.started)
1458
+ return;
1459
+ this.sizeChangeHandler(this.mainViewSize);
1460
+ this.addCameraListener();
1461
+ (_a = this.manager.refresher) == null ? void 0 : _a.add(Fields.MainViewCamera, this.cameraReaction);
1462
+ this.started = true;
1463
+ }
1464
+ setCameraAndSize() {
1465
+ this.store.setMainViewCamera(__spreadProps(__spreadValues({}, this.mainView.camera), { id: this.context.uid }));
1466
+ this.store.setMainViewSize(__spreadProps(__spreadValues({}, this.mainView.size), { id: this.context.uid }));
1467
+ }
1468
+ get view() {
1469
+ return this.mainView;
1470
+ }
1471
+ get cameraState() {
1472
+ return __spreadValues(__spreadValues({}, this.view.camera), this.view.size);
1473
+ }
1474
+ createMainView() {
1475
+ const mainView = createView(this.manager.displayer);
1476
+ const mainViewScenePath = this.store.getMainViewScenePath();
1477
+ if (mainViewScenePath) {
1478
+ setViewFocusScenePath(mainView, mainViewScenePath);
1479
+ }
1480
+ return mainView;
1481
+ }
1482
+ addMainViewListener() {
1483
+ if (this.mainViewIsAddListener)
1484
+ return;
1485
+ if (this.view.divElement) {
1486
+ this.view.divElement.addEventListener("click", this.mainViewClickListener);
1487
+ this.view.divElement.addEventListener("touchend", this.mainViewClickListener);
1488
+ this.mainViewIsAddListener = true;
1489
+ }
1490
+ }
1491
+ removeMainViewListener() {
1492
+ if (this.view.divElement) {
1493
+ this.view.divElement.removeEventListener("click", this.mainViewClickListener);
1494
+ this.view.divElement.removeEventListener("touchend", this.mainViewClickListener);
1495
+ }
1496
+ }
1497
+ async mainViewClickHandler() {
1498
+ if (!this.manager.canOperate)
1499
+ return;
1500
+ this.store.cleanFocus();
1501
+ this.context.blurFocusBox();
1502
+ }
1503
+ addCameraListener() {
1504
+ this.view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
1505
+ this.view.callbacks.on("onCameraUpdated", this.onCameraOrSizeUpdated);
1506
+ this.view.callbacks.on("onSizeUpdated", this.onCameraOrSizeUpdated);
1507
+ }
1508
+ removeCameraListener() {
1509
+ this.view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
1510
+ this.view.callbacks.off("onCameraUpdated", this.onCameraOrSizeUpdated);
1511
+ this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
1512
+ }
1513
+ moveCameraToContian(size2) {
1514
+ if (!isEmpty(size2)) {
1515
+ this.view.moveCameraToContain({
1516
+ width: size2.width,
1517
+ height: size2.height,
1518
+ originX: -size2.width / 2,
1519
+ originY: -size2.height / 2,
1520
+ animationMode: AnimationMode.Immediately
1521
+ });
1522
+ this.scale = this.view.camera.scale;
1523
+ }
1524
+ }
1525
+ moveCamera(camera) {
1526
+ if (!isEmpty(camera)) {
1527
+ if (isEqual(camera, this.view.camera))
1528
+ return;
1529
+ const { centerX, centerY, scale } = camera;
1530
+ const needScale = scale * (this.scale || 1);
1531
+ this.view.moveCamera({
1532
+ centerX,
1533
+ centerY,
1534
+ scale: needScale,
1535
+ animationMode: AnimationMode.Immediately
1536
+ });
1537
+ }
1538
+ }
1539
+ stop() {
1540
+ var _a, _b;
1541
+ this.removeMainViewListener();
1542
+ this.removeCameraListener();
1543
+ (_a = this.manager.refresher) == null ? void 0 : _a.remove(Fields.MainViewCamera);
1544
+ (_b = this.manager.refresher) == null ? void 0 : _b.remove(Fields.MainViewSize);
1545
+ this.started = false;
1546
+ }
1547
+ destroy() {
1548
+ this.stop();
1549
+ this.sideEffectManager.flushAll();
1550
+ }
1551
+ }
1552
+ class AppManager {
1553
+ constructor(windowManger) {
1554
+ this.windowManger = windowManger;
1555
+ this.appProxies = new Map();
1556
+ this.appStatus = new Map();
1557
+ this.store = store;
1558
+ this.isReplay = this.windowManger.isReplay;
1559
+ this.onAppDelete = (apps) => {
1560
+ const ids = Object.keys(apps);
1561
+ this.appProxies.forEach((appProxy, id) => {
1562
+ if (!ids.includes(id)) {
1563
+ appProxy.destroy(true, false, true);
1564
+ }
1565
+ });
1566
+ };
1567
+ this.displayerStateListener = (state) => {
1568
+ var _a, _b;
1569
+ const sceneState = state.sceneState;
1570
+ if (sceneState) {
1571
+ const scenePath = sceneState.scenePath;
1572
+ this.appProxies.forEach((appProxy) => {
1573
+ if (appProxy.scenePath && scenePath.startsWith(appProxy.scenePath)) {
1574
+ appProxy.emitAppSceneStateChange(sceneState);
1575
+ appProxy.setFullPath(scenePath);
1576
+ }
1577
+ });
1578
+ }
1579
+ if (state.roomMembers) {
1580
+ (_a = this.windowManger.cursorManager) == null ? void 0 : _a.setRoomMembers(state.roomMembers);
1581
+ (_b = this.windowManger.cursorManager) == null ? void 0 : _b.cleanMemberAttributes(state.roomMembers);
1582
+ }
1583
+ this.appProxies.forEach((appProxy) => {
1584
+ appProxy.appEmitter.emit("roomStateChange", state);
1585
+ });
1586
+ emitter.emit("observerIdChange", this.displayer.observerId);
1587
+ };
1588
+ this.displayerWritableListener = (isReadonly) => {
1589
+ var _a, _b;
1590
+ const isWritable = !isReadonly;
1591
+ const isManualWritable = this.windowManger.readonly === void 0 || this.windowManger.readonly === false;
1592
+ if (this.windowManger.readonly === void 0) {
1593
+ (_a = this.boxManager) == null ? void 0 : _a.setReadonly(isReadonly);
1594
+ } else {
1595
+ (_b = this.boxManager) == null ? void 0 : _b.setReadonly(!(isWritable && isManualWritable));
1596
+ }
1597
+ this.appProxies.forEach((appProxy) => {
1598
+ appProxy.emitAppIsWritableChange();
1599
+ });
1600
+ if (isWritable === true) {
1601
+ this.mainView.disableCameraTransform = false;
1602
+ if (this.room && this.room.disableSerialization === true) {
1603
+ this.room.disableSerialization = false;
1604
+ }
1605
+ } else {
1606
+ this.mainView.disableCameraTransform = true;
1607
+ }
1608
+ };
1609
+ this.updateSceneIndex = () => {
1610
+ const scenePath = this.store.getMainViewScenePath();
1611
+ const sceneDir = parseSceneDir(scenePath);
1612
+ const scenes = entireScenes(this.displayer)[sceneDir];
1613
+ if (scenes.length) {
1614
+ const pageName = scenePath.replace(sceneDir, "").replace("/", "");
1615
+ const index = scenes.findIndex((scene) => scene.name === pageName);
1616
+ if (isInteger(index) && index >= 0) {
1617
+ this.safeSetAttributes({ _mainSceneIndex: index });
1618
+ }
1619
+ }
1620
+ };
1621
+ this.boxEventListener = (eventName, payload) => {
1622
+ switch (eventName) {
1623
+ case "move": {
1624
+ this.dispatchInternalEvent(Events.AppMove, payload);
1625
+ this.store.updateAppState(payload.appId, AppAttributes.Position, {
1626
+ x: payload.x,
1627
+ y: payload.y
1628
+ });
1629
+ break;
1630
+ }
1631
+ case "focus": {
1632
+ this.windowManger.safeSetAttributes({ focus: payload.appId });
1633
+ break;
1634
+ }
1635
+ case "resize": {
1636
+ if (payload.width && payload.height) {
1637
+ this.dispatchInternalEvent(Events.AppResize, payload);
1638
+ this.store.updateAppState(payload.appId, AppAttributes.Size, {
1639
+ width: payload.width,
1640
+ height: payload.height
1641
+ });
1642
+ }
1643
+ break;
1644
+ }
1645
+ case "close": {
1646
+ const appProxy = this.appProxies.get(payload.appId);
1647
+ if (appProxy) {
1648
+ appProxy.destroy(false, true, payload.error);
1649
+ }
1650
+ break;
1651
+ }
1652
+ case "boxStateChange": {
1653
+ this.dispatchInternalEvent(Events.AppBoxStateChange, payload);
1654
+ break;
1655
+ }
1656
+ }
1657
+ };
1658
+ this.displayer = windowManger.displayer;
1659
+ this.store.setContext({
1660
+ getAttributes: () => this.attributes,
1661
+ safeSetAttributes: (attributes) => this.safeSetAttributes(attributes),
1662
+ safeUpdateAttributes: (keys, val) => this.safeUpdateAttributes(keys, val)
1663
+ });
1664
+ this.mainViewProxy = new MainViewProxy(this);
1665
+ this.viewManager = new ViewManager(this.displayer);
1666
+ this.appListeners = new AppListeners(this);
1667
+ this.displayer.callbacks.on(this.eventName, this.displayerStateListener);
1668
+ this.appListeners.addListeners();
1669
+ this.refresher = reconnectRefresher;
1670
+ this.refresher.setRoom(this.room);
1671
+ this.refresher.setContext({ emitter });
1672
+ emitter.once("onCreated").then(() => this.onCreated());
1673
+ emitter.on("onReconnected", () => this.onReconnected());
1674
+ if (isPlayer(this.displayer)) {
1675
+ emitter.on("seek", (time) => {
1676
+ this.appProxies.forEach((appProxy) => {
1677
+ appProxy.onSeek(time);
1678
+ });
1679
+ this.attributesUpdateCallback(this.attributes.apps);
1680
+ this.onAppDelete(this.attributes.apps);
1681
+ });
1682
+ }
1683
+ }
1684
+ async onCreated() {
1685
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1686
+ await this.attributesUpdateCallback(this.attributes.apps);
1687
+ (_a = this.boxManager) == null ? void 0 : _a.updateManagerRect();
1688
+ emitter.onAny(this.boxEventListener);
1689
+ (_b = this.refresher) == null ? void 0 : _b.add("apps", () => {
1690
+ return safeListenPropsUpdated(() => this.attributes.apps, () => {
1691
+ this.attributesUpdateCallback(this.attributes.apps);
1692
+ });
1693
+ });
1694
+ (_c = this.refresher) == null ? void 0 : _c.add("appsClose", () => {
1695
+ return onObjectRemoved(this.attributes.apps, () => {
1696
+ this.onAppDelete(this.attributes.apps);
1697
+ });
1698
+ });
1699
+ (_d = this.refresher) == null ? void 0 : _d.add("maximized", () => {
1700
+ return autorun(() => {
1701
+ var _a2;
1702
+ const maximized = this.attributes.maximized;
1703
+ (_a2 = this.boxManager) == null ? void 0 : _a2.setMaximized(Boolean(maximized));
1704
+ });
1705
+ });
1706
+ (_e = this.refresher) == null ? void 0 : _e.add("minimized", () => {
1707
+ return autorun(() => {
1708
+ var _a2, _b2;
1709
+ const minimized = this.attributes.minimized;
1710
+ if (((_a2 = this.boxManager) == null ? void 0 : _a2.minimized) !== minimized) {
1711
+ if (minimized === true) {
1712
+ (_b2 = this.boxManager) == null ? void 0 : _b2.blurAllBox();
1713
+ }
1714
+ setTimeout(() => {
1715
+ var _a3;
1716
+ (_a3 = this.boxManager) == null ? void 0 : _a3.setMinimized(Boolean(minimized));
1717
+ }, 0);
1718
+ }
1719
+ });
1720
+ });
1721
+ (_f = this.refresher) == null ? void 0 : _f.add("mainViewIndex", () => {
1722
+ return autorun(() => {
1723
+ const mainSceneIndex = get(this.attributes, "_mainSceneIndex");
1724
+ if (mainSceneIndex !== void 0 && this._prevSceneIndex !== mainSceneIndex) {
1725
+ callbacks.emit("mainViewSceneIndexChange", mainSceneIndex);
1726
+ this._prevSceneIndex = mainSceneIndex;
1727
+ }
1728
+ });
1729
+ });
1730
+ (_g = this.refresher) == null ? void 0 : _g.add("focusedChange", () => {
1731
+ return autorun(() => {
1732
+ const focused = get(this.attributes, "focus");
1733
+ if (this._prevFocused !== focused) {
1734
+ callbacks.emit("focusedChange", focused);
1735
+ this._prevFocused = focused;
1736
+ }
1737
+ });
1738
+ });
1739
+ if (!this.attributes.apps || Object.keys(this.attributes.apps).length === 0) {
1740
+ const mainScenePath = this.store.getMainViewScenePath();
1741
+ if (!mainScenePath)
1742
+ return;
1743
+ const sceneState = this.displayer.state.sceneState;
1744
+ if (sceneState.scenePath !== mainScenePath) {
1745
+ setScenePath(this.room, mainScenePath);
1746
+ }
1747
+ }
1748
+ this.displayerWritableListener(!((_h = this.room) == null ? void 0 : _h.isWritable));
1749
+ this.displayer.callbacks.on("onEnableWriteNowChanged", this.displayerWritableListener);
1750
+ this._prevFocused = this.attributes.focus;
1751
+ }
1752
+ async attributesUpdateCallback(apps) {
1753
+ if (apps && WindowManager.container) {
1754
+ const appIds = Object.keys(apps);
1755
+ const appsWithCreatedAt = appIds.map((appId) => {
1756
+ return {
1757
+ id: appId,
1758
+ createdAt: apps[appId].createdAt
1759
+ };
1760
+ });
1761
+ for (const { id } of sortBy(appsWithCreatedAt, "createdAt")) {
1762
+ if (!this.appProxies.has(id) && !this.appStatus.has(id)) {
1763
+ const app = apps[id];
1764
+ pRetry(async () => {
1765
+ this.appStatus.set(id, AppStatus.StartCreate);
1766
+ const appAttributes = this.attributes[id];
1767
+ if (!appAttributes) {
1768
+ throw new Error("appAttributes is undefined");
1769
+ }
1770
+ await this.baseInsertApp({
1771
+ kind: app.kind,
1772
+ options: app.options,
1773
+ isDynamicPPT: app.isDynamicPPT
1774
+ }, id, false);
1775
+ this.focusByAttributes(apps);
1776
+ }, { retries: 3 }).catch((err) => {
1777
+ console.warn(`[WindowManager]: Insert App Error`, err);
1778
+ this.appStatus.delete(id);
1779
+ });
1780
+ }
1781
+ }
1782
+ }
1783
+ }
1784
+ refresh() {
1785
+ this.attributesUpdateCallback(this.attributes.apps);
1786
+ }
1787
+ setBoxManager(boxManager) {
1788
+ this.boxManager = boxManager;
1789
+ }
1790
+ resetMaximized() {
1791
+ var _a;
1792
+ (_a = this.boxManager) == null ? void 0 : _a.setMaximized(Boolean(this.store.getMaximized()));
1793
+ }
1794
+ resetMinimized() {
1795
+ var _a;
1796
+ (_a = this.boxManager) == null ? void 0 : _a.setMinimized(Boolean(this.store.getMinimized()));
1797
+ }
1798
+ bindMainView(divElement, disableCameraTransform) {
1799
+ const mainView = this.mainViewProxy.view;
1800
+ mainView.disableCameraTransform = disableCameraTransform;
1801
+ mainView.divElement = divElement;
1802
+ if (!mainView.focusScenePath) {
1803
+ this.setMainViewFocusPath();
1804
+ }
1805
+ emitter.emit("mainViewMounted");
1806
+ }
1807
+ setMainViewFocusPath(scenePath) {
1808
+ const focusScenePath = scenePath || this.store.getMainViewScenePath();
1809
+ if (focusScenePath) {
1810
+ const view = setViewFocusScenePath(this.mainView, focusScenePath);
1811
+ return (view == null ? void 0 : view.focusScenePath) === focusScenePath;
1812
+ }
1813
+ }
1814
+ async addApp(params, isDynamicPPT) {
1815
+ log("addApp", params);
1816
+ const { appId, needFocus } = await this.beforeAddApp(params, isDynamicPPT);
1817
+ const appProxy = await this.baseInsertApp(params, appId, true, needFocus);
1818
+ this.afterAddApp(appProxy);
1819
+ return appProxy == null ? void 0 : appProxy.id;
1820
+ }
1821
+ async beforeAddApp(params, isDynamicPPT) {
1822
+ var _a, _b;
1823
+ const appId = await genAppId(params.kind);
1824
+ this.appStatus.set(appId, AppStatus.StartCreate);
1825
+ const attrs = (_a = params.attributes) != null ? _a : {};
1826
+ this.safeUpdateAttributes([appId], attrs);
1827
+ this.store.setupAppAttributes(params, appId, isDynamicPPT);
1828
+ const needFocus = !((_b = this.boxManager) == null ? void 0 : _b.minimized);
1829
+ if (needFocus) {
1830
+ this.store.setAppFocus(appId, true);
1831
+ }
1832
+ return { appId, needFocus };
1833
+ }
1834
+ afterAddApp(appProxy) {
1835
+ var _a, _b;
1836
+ if (appProxy && appProxy.box) {
1837
+ const box = appProxy.box;
1838
+ emitter.emit("move", {
1839
+ appId: appProxy.id,
1840
+ x: box == null ? void 0 : box.intrinsicX,
1841
+ y: box == null ? void 0 : box.intrinsicY
1842
+ });
1843
+ this.store.updateAppState(appProxy.id, AppAttributes.ZIndex, box.zIndex);
1844
+ }
1845
+ if ((_a = this.boxManager) == null ? void 0 : _a.minimized) {
1846
+ (_b = this.boxManager) == null ? void 0 : _b.setMinimized(false, false);
1847
+ }
1848
+ }
1849
+ async closeApp(appId) {
1850
+ const appProxy = this.appProxies.get(appId);
1851
+ if (appProxy) {
1852
+ appProxy.destroy(true, true, false);
1853
+ }
1854
+ }
1855
+ async baseInsertApp(params, appId, isAddApp, focus) {
1856
+ if (this.appProxies.has(appId)) {
1857
+ console.warn("[WindowManager]: app duplicate exists and cannot be created again");
1858
+ return;
1859
+ }
1860
+ const appProxy = new AppProxy(params, this, appId, isAddApp);
1861
+ if (appProxy) {
1862
+ await appProxy.baseInsertApp(focus);
1863
+ this.appStatus.delete(appId);
1864
+ return appProxy;
1865
+ } else {
1866
+ this.appStatus.delete(appId);
1867
+ throw new Error("[WindowManger]: initialize AppProxy failed");
1868
+ }
1869
+ }
1870
+ get eventName() {
1871
+ return isRoom(this.displayer) ? "onRoomStateChanged" : "onPlayerStateChanged";
1872
+ }
1873
+ get attributes() {
1874
+ return this.windowManger.attributes;
1875
+ }
1876
+ get canOperate() {
1877
+ return this.windowManger.canOperate;
1878
+ }
1879
+ get room() {
1880
+ return isRoom(this.displayer) ? this.displayer : void 0;
1881
+ }
1882
+ get mainView() {
1883
+ return this.mainViewProxy.view;
1884
+ }
1885
+ get focusApp() {
1886
+ if (this.store.focus) {
1887
+ return this.appProxies.get(this.store.focus);
1888
+ }
1889
+ }
1890
+ safeSetAttributes(attributes) {
1891
+ this.windowManger.safeSetAttributes(attributes);
1892
+ }
1893
+ safeUpdateAttributes(keys, value) {
1894
+ this.windowManger.safeUpdateAttributes(keys, value);
1895
+ }
1896
+ async setMainViewScenePath(scenePath) {
1897
+ if (this.room) {
1898
+ const scenePathType = this.displayer.scenePathType(scenePath);
1899
+ if (scenePathType === ScenePathType.None) {
1900
+ throw new Error(`[WindowManager]: ${scenePath} not valid scene`);
1901
+ } else if (scenePathType === ScenePathType.Page) {
1902
+ await this._setMainViewScenePath(scenePath);
1903
+ } else if (scenePathType === ScenePathType.Dir) {
1904
+ const validScenePath = makeValidScenePath(this.displayer, scenePath);
1905
+ if (validScenePath) {
1906
+ await this._setMainViewScenePath(validScenePath);
1907
+ }
1908
+ }
1909
+ }
1910
+ }
1911
+ async _setMainViewScenePath(scenePath) {
1912
+ const success = this.setMainViewFocusPath(scenePath);
1913
+ if (success) {
1914
+ this.safeSetAttributes({ _mainScenePath: scenePath });
1915
+ this.store.setMainViewFocusPath(this.mainView);
1916
+ this.updateSceneIndex();
1917
+ this.dispatchInternalEvent(Events.SetMainViewScenePath, { nextScenePath: scenePath });
1918
+ }
1919
+ }
1920
+ async setMainViewSceneIndex(index) {
1921
+ if (this.room) {
1922
+ if (this.store.getMainViewSceneIndex() === index)
1923
+ return;
1924
+ const mainViewScenePath = this.store.getMainViewScenePath();
1925
+ if (mainViewScenePath) {
1926
+ const sceneDir = parseSceneDir(mainViewScenePath);
1927
+ const scenePath = makeValidScenePath(this.displayer, sceneDir, index);
1928
+ if (scenePath) {
1929
+ const success = this.setMainViewFocusPath(scenePath);
1930
+ if (success) {
1931
+ this.store.setMainViewScenePath(scenePath);
1932
+ this.safeSetAttributes({ _mainSceneIndex: index });
1933
+ }
1934
+ } else {
1935
+ throw new Error(`[WindowManager]: ${sceneDir}: ${index} not valid index`);
1936
+ }
1937
+ }
1938
+ }
1939
+ }
1940
+ getAppInitPath(appId) {
1941
+ var _a;
1942
+ const attrs = this.store.getAppAttributes(appId);
1943
+ if (attrs) {
1944
+ return (_a = attrs == null ? void 0 : attrs.options) == null ? void 0 : _a.scenePath;
1945
+ }
1946
+ }
1947
+ safeDispatchMagixEvent(event, payload) {
1948
+ if (this.canOperate) {
1949
+ this.displayer.dispatchMagixEvent(event, payload);
1950
+ }
1951
+ }
1952
+ focusByAttributes(apps) {
1953
+ var _a;
1954
+ if (apps && Object.keys(apps).length === ((_a = this.boxManager) == null ? void 0 : _a.boxSize)) {
1955
+ const focusAppId = this.store.focus;
1956
+ if (focusAppId) {
1957
+ this.boxManager.focusBox({ appId: focusAppId });
1958
+ }
1959
+ }
1960
+ }
1961
+ async onReconnected() {
1962
+ const appProxies = Array.from(this.appProxies.values());
1963
+ const reconnected = appProxies.map((appProxy) => {
1964
+ return appProxy.onReconnected();
1965
+ });
1966
+ await Promise.all(reconnected);
1967
+ }
1968
+ notifyContainerRectUpdate(rect) {
1969
+ this.appProxies.forEach((appProxy) => {
1970
+ appProxy.appEmitter.emit("containerRectUpdate", rect);
1971
+ });
1972
+ }
1973
+ dispatchInternalEvent(event, payload) {
1974
+ this.safeDispatchMagixEvent(MagixEventName, {
1975
+ eventName: event,
1976
+ payload
1977
+ });
1978
+ }
1979
+ destroy() {
1980
+ var _a, _b;
1981
+ this.displayer.callbacks.off(this.eventName, this.displayerStateListener);
1982
+ this.displayer.callbacks.off("onEnableWriteNowChanged", this.displayerWritableListener);
1983
+ this.appListeners.removeListeners();
1984
+ emitter.offAny(this.boxEventListener);
1985
+ emitter.clearListeners();
1986
+ if (this.appProxies.size) {
1987
+ this.appProxies.forEach((appProxy) => {
1988
+ appProxy.destroy(true, false, true);
1989
+ });
1990
+ }
1991
+ this.viewManager.destroy();
1992
+ (_a = this.boxManager) == null ? void 0 : _a.destroy();
1993
+ (_b = this.refresher) == null ? void 0 : _b.destroy();
1994
+ this.mainViewProxy.destroy();
1995
+ callbacks.clearListeners();
1996
+ this._prevSceneIndex = void 0;
1997
+ }
1998
+ }
1999
+ const ResizeObserver = window.ResizeObserver || ResizeObserver$1;
2000
+ class ContainerResizeObserver {
2001
+ constructor(emitter2) {
2002
+ this.emitter = emitter2;
2003
+ }
2004
+ static create(container, sizer, wrapper, emitter2) {
2005
+ const containerResizeObserver = new ContainerResizeObserver(emitter2);
2006
+ containerResizeObserver.observePlaygroundSize(container, sizer, wrapper);
2007
+ return containerResizeObserver;
2008
+ }
2009
+ observePlaygroundSize(container, sizer, wrapper) {
2010
+ this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
2011
+ this.containerResizeObserver = new ResizeObserver((entries) => {
2012
+ var _a;
2013
+ const containerRect = (_a = entries[0]) == null ? void 0 : _a.contentRect;
2014
+ if (containerRect) {
2015
+ this.updateSizer(containerRect, sizer, wrapper);
2016
+ this.emitter.emit("playgroundSizeChange", containerRect);
2017
+ }
2018
+ });
2019
+ this.containerResizeObserver.observe(container);
2020
+ }
2021
+ updateSizer({ width, height }, sizer, wrapper) {
2022
+ if (width && height) {
2023
+ if (height / width > WindowManager.containerSizeRatio) {
2024
+ height = width * WindowManager.containerSizeRatio;
2025
+ sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
2026
+ } else {
2027
+ width = height / WindowManager.containerSizeRatio;
2028
+ sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
2029
+ }
2030
+ wrapper.style.width = `${width}px`;
2031
+ wrapper.style.height = `${height}px`;
2032
+ }
2033
+ }
2034
+ disconnect() {
2035
+ var _a;
2036
+ (_a = this.containerResizeObserver) == null ? void 0 : _a.disconnect();
2037
+ }
2038
+ }
2039
+ const createBoxManager = (manager, callbacks2, emitter2, options) => {
2040
+ return new BoxManager({
2041
+ safeSetAttributes: (attributes) => manager.safeSetAttributes(attributes),
2042
+ getMainView: () => manager.mainView,
2043
+ updateAppState: (...args) => {
2044
+ var _a;
2045
+ return (_a = manager.appManager) == null ? void 0 : _a.store.updateAppState(...args);
2046
+ },
2047
+ canOperate: () => manager.canOperate,
2048
+ notifyContainerRectUpdate: (rect) => {
2049
+ var _a;
2050
+ return (_a = manager.appManager) == null ? void 0 : _a.notifyContainerRectUpdate(rect);
2051
+ },
2052
+ cleanFocus: () => {
2053
+ var _a;
2054
+ return (_a = manager.appManager) == null ? void 0 : _a.store.cleanFocus();
2055
+ },
2056
+ callbacks: callbacks2,
2057
+ emitter: emitter2
2058
+ }, options);
2059
+ };
2060
+ class BoxManager {
2061
+ constructor(context2, createTeleBoxManagerConfig) {
2062
+ this.context = context2;
2063
+ this.createTeleBoxManagerConfig = createTeleBoxManagerConfig;
2064
+ this.playgroundSizeChangeListener = () => {
2065
+ this.updateManagerRect();
2066
+ };
2067
+ const { emitter: emitter2, callbacks: callbacks2 } = context2;
2068
+ this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
2069
+ this.teleBoxManager.events.on(TELE_BOX_MANAGER_EVENT.State, (state) => {
2070
+ if (state) {
2071
+ this.context.callbacks.emit("boxStateChange", state);
2072
+ this.context.emitter.emit("boxStateChange", state);
2073
+ }
2074
+ });
2075
+ this.teleBoxManager.events.on("minimized", (minimized) => {
2076
+ this.context.safeSetAttributes({ minimized });
2077
+ if (minimized) {
2078
+ this.context.cleanFocus();
2079
+ this.blurAllBox();
2080
+ }
2081
+ });
2082
+ this.teleBoxManager.events.on("maximized", (maximized) => {
2083
+ this.context.safeSetAttributes({ maximized });
2084
+ });
2085
+ this.teleBoxManager.events.on("removed", (boxes) => {
2086
+ boxes.forEach((box) => {
2087
+ emitter2.emit("close", { appId: box.id });
2088
+ });
2089
+ });
2090
+ this.teleBoxManager.events.on("intrinsic_move", debounce((box) => {
2091
+ emitter2.emit("move", { appId: box.id, x: box.intrinsicX, y: box.intrinsicY });
2092
+ }, 50));
2093
+ this.teleBoxManager.events.on("intrinsic_resize", debounce((box) => {
2094
+ emitter2.emit("resize", {
2095
+ appId: box.id,
2096
+ width: box.intrinsicWidth,
2097
+ height: box.intrinsicHeight
2098
+ });
2099
+ }, 200));
2100
+ this.teleBoxManager.events.on("focused", (box) => {
2101
+ if (box) {
2102
+ if (this.canOperate) {
2103
+ emitter2.emit("focus", { appId: box.id });
2104
+ } else {
2105
+ this.teleBoxManager.blurBox(box.id);
2106
+ }
2107
+ }
2108
+ });
2109
+ this.teleBoxManager.events.on("dark_mode", (darkMode) => {
2110
+ callbacks2.emit("darkModeChange", darkMode);
2111
+ });
2112
+ this.teleBoxManager.events.on("prefers_color_scheme", (colorScheme) => {
2113
+ callbacks2.emit("prefersColorSchemeChange", colorScheme);
2114
+ });
2115
+ this.teleBoxManager.events.on("z_index", (box) => {
2116
+ this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
2117
+ });
2118
+ emitter2.on("playgroundSizeChange", this.playgroundSizeChangeListener);
2119
+ }
2120
+ get mainView() {
2121
+ return this.context.getMainView();
2122
+ }
2123
+ get canOperate() {
2124
+ return this.context.canOperate();
2125
+ }
2126
+ get boxState() {
2127
+ return this.teleBoxManager.state;
2128
+ }
2129
+ get maximized() {
2130
+ return this.teleBoxManager.maximized;
2131
+ }
2132
+ get minimized() {
2133
+ return this.teleBoxManager.minimized;
2134
+ }
2135
+ get darkMode() {
2136
+ return this.teleBoxManager.darkMode;
2137
+ }
2138
+ get prefersColorScheme() {
2139
+ return this.teleBoxManager.prefersColorScheme;
2140
+ }
2141
+ get boxSize() {
2142
+ return this.teleBoxManager.boxes.length;
2143
+ }
2144
+ createBox(params) {
2145
+ var _a, _b, _c;
2146
+ if (!this.teleBoxManager)
2147
+ return;
2148
+ let { minwidth = MIN_WIDTH, minheight = MIN_HEIGHT } = (_a = params.app.config) != null ? _a : {};
2149
+ const { width, height } = (_b = params.app.config) != null ? _b : {};
2150
+ const title = ((_c = params.options) == null ? void 0 : _c.title) || params.appId;
2151
+ const rect = this.teleBoxManager.containerRect;
2152
+ if (minwidth > 1) {
2153
+ minwidth = minwidth / rect.width;
2154
+ }
2155
+ if (minheight > 1) {
2156
+ minheight = minheight / rect.height;
2157
+ }
2158
+ const createBoxConfig = {
2159
+ title,
2160
+ minWidth: minwidth,
2161
+ minHeight: minheight,
2162
+ width,
2163
+ height,
2164
+ id: params.appId
2165
+ };
2166
+ this.teleBoxManager.create(createBoxConfig, params.smartPosition);
2167
+ this.context.emitter.emit(`${params.appId}${Events.WindowCreated}`);
2168
+ }
2169
+ setBoxInitState(appId) {
2170
+ const box = this.teleBoxManager.queryOne({ id: appId });
2171
+ if (box) {
2172
+ if (box.state === TELE_BOX_STATE.Maximized) {
2173
+ this.context.emitter.emit("resize", {
2174
+ appId,
2175
+ x: box.x,
2176
+ y: box.y,
2177
+ width: box.intrinsicWidth,
2178
+ height: box.intrinsicHeight
2179
+ });
2180
+ }
2181
+ }
2182
+ }
2183
+ setupBoxManager(createTeleBoxManagerConfig) {
2184
+ const root = WindowManager.wrapper ? WindowManager.wrapper : document.body;
2185
+ const rect = root.getBoundingClientRect();
2186
+ const initManagerState = {
2187
+ root,
2188
+ containerRect: {
2189
+ x: 0,
2190
+ y: 0,
2191
+ width: rect.width,
2192
+ height: rect.height
2193
+ },
2194
+ fence: false,
2195
+ prefersColorScheme: createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.prefersColorScheme
2196
+ };
2197
+ const manager = new TeleBoxManager(initManagerState);
2198
+ if (this.teleBoxManager) {
2199
+ this.teleBoxManager.destroy();
2200
+ }
2201
+ this.teleBoxManager = manager;
2202
+ const container = (createTeleBoxManagerConfig == null ? void 0 : createTeleBoxManagerConfig.collectorContainer) || WindowManager.wrapper;
2203
+ if (container) {
2204
+ this.setCollectorContainer(container);
2205
+ }
2206
+ return manager;
2207
+ }
2208
+ setCollectorContainer(container) {
2209
+ var _a;
2210
+ const collector = new TeleBoxCollector({
2211
+ styles: (_a = this.createTeleBoxManagerConfig) == null ? void 0 : _a.collectorStyles
2212
+ }).mount(container);
2213
+ this.teleBoxManager.setCollector(collector);
2214
+ }
2215
+ getBox(appId) {
2216
+ return this.teleBoxManager.queryOne({ id: appId });
2217
+ }
2218
+ closeBox(appId, skipUpdate = false) {
2219
+ return this.teleBoxManager.remove(appId, skipUpdate);
2220
+ }
2221
+ boxIsFocus(appId) {
2222
+ const box = this.getBox(appId);
2223
+ return box == null ? void 0 : box.focus;
2224
+ }
2225
+ getFocusBox() {
2226
+ const boxes = this.teleBoxManager.query({ focus: true });
2227
+ return boxes[0];
2228
+ }
2229
+ getTopBox() {
2230
+ const boxes = this.teleBoxManager.query();
2231
+ return maxBy(boxes, "zIndex");
2232
+ }
2233
+ updateBoxState(state) {
2234
+ if (!state)
2235
+ return;
2236
+ const box = this.getBox(state.id);
2237
+ if (box) {
2238
+ this.teleBoxManager.update(box.id, {
2239
+ x: state.x,
2240
+ y: state.y,
2241
+ width: state.width || 0.5,
2242
+ height: state.height || 0.5,
2243
+ zIndex: state.zIndex
2244
+ }, true);
2245
+ setTimeout(() => {
2246
+ if (state.focus) {
2247
+ this.teleBoxManager.focusBox(box.id, true);
2248
+ }
2249
+ if (state.maximized != null) {
2250
+ this.teleBoxManager.setMaximized(Boolean(state.maximized), true);
2251
+ }
2252
+ if (state.minimized != null) {
2253
+ this.teleBoxManager.setMinimized(Boolean(state.minimized), true);
2254
+ }
2255
+ }, 50);
2256
+ this.context.callbacks.emit("boxStateChange", this.teleBoxManager.state);
2257
+ }
2258
+ }
2259
+ updateManagerRect() {
2260
+ var _a;
2261
+ const rect = (_a = this.mainView.divElement) == null ? void 0 : _a.getBoundingClientRect();
2262
+ if (rect && rect.width > 0 && rect.height > 0) {
2263
+ const containerRect = { x: 0, y: 0, width: rect.width, height: rect.height };
2264
+ this.teleBoxManager.setContainerRect(containerRect);
2265
+ this.context.notifyContainerRectUpdate(this.teleBoxManager.containerRect);
2266
+ }
2267
+ }
2268
+ moveBox({ appId, x, y }) {
2269
+ this.teleBoxManager.update(appId, { x, y }, true);
2270
+ }
2271
+ focusBox({ appId }, skipUpdate = true) {
2272
+ this.teleBoxManager.focusBox(appId, skipUpdate);
2273
+ }
2274
+ resizeBox({ appId, width, height, skipUpdate }) {
2275
+ this.teleBoxManager.update(appId, { width, height }, skipUpdate);
2276
+ }
2277
+ setBoxMinSize(params) {
2278
+ this.teleBoxManager.update(params.appId, {
2279
+ minWidth: params.minWidth,
2280
+ minHeight: params.minHeight
2281
+ }, true);
2282
+ }
2283
+ setBoxTitle(params) {
2284
+ this.teleBoxManager.update(params.appId, { title: params.title }, true);
2285
+ }
2286
+ blurAllBox() {
2287
+ this.teleBoxManager.blurAll();
2288
+ }
2289
+ updateAll(config) {
2290
+ this.teleBoxManager.updateAll(config);
2291
+ }
2292
+ setMaximized(maximized) {
2293
+ if (maximized !== this.maximized) {
2294
+ this.teleBoxManager.setMaximized(maximized, true);
2295
+ }
2296
+ }
2297
+ setMinimized(minimized, skipUpdate = true) {
2298
+ this.teleBoxManager.setMinimized(minimized, skipUpdate);
2299
+ }
2300
+ focusTopBox() {
2301
+ const boxes = this.teleBoxManager.query();
2302
+ if (boxes.length >= 1) {
2303
+ const box = this.getTopBox();
2304
+ if (box) {
2305
+ this.focusBox({ appId: box.id }, false);
2306
+ }
2307
+ }
2308
+ }
2309
+ updateBox(id, payload, skipUpdate = true) {
2310
+ this.teleBoxManager.update(id, payload, skipUpdate);
2311
+ }
2312
+ setReadonly(readonly) {
2313
+ this.teleBoxManager.setReadonly(readonly);
2314
+ }
2315
+ setPrefersColorScheme(colorScheme) {
2316
+ this.teleBoxManager.setPrefersColorScheme(colorScheme);
2317
+ }
2318
+ setZIndex(id, zIndex, skipUpdate = true) {
2319
+ this.teleBoxManager.update(id, { zIndex }, skipUpdate);
2320
+ }
2321
+ destroy() {
2322
+ emitter.off("playgroundSizeChange", this.playgroundSizeChangeListener);
2323
+ this.teleBoxManager.destroy();
2324
+ }
2325
+ }
2326
+ function noop() {
2327
+ }
2328
+ function run(fn) {
2329
+ return fn();
2330
+ }
2331
+ function blank_object() {
2332
+ return Object.create(null);
2333
+ }
2334
+ function run_all(fns) {
2335
+ fns.forEach(run);
2336
+ }
2337
+ function is_function(thing) {
2338
+ return typeof thing === "function";
2339
+ }
2340
+ function safe_not_equal(a, b) {
2341
+ return a != a ? b == b : a !== b || (a && typeof a === "object" || typeof a === "function");
2342
+ }
2343
+ let src_url_equal_anchor;
2344
+ function src_url_equal(element_src, url) {
2345
+ if (!src_url_equal_anchor) {
2346
+ src_url_equal_anchor = document.createElement("a");
2347
+ }
2348
+ src_url_equal_anchor.href = url;
2349
+ return element_src === src_url_equal_anchor.href;
2350
+ }
2351
+ function is_empty(obj) {
2352
+ return Object.keys(obj).length === 0;
2353
+ }
2354
+ function append(target, node) {
2355
+ target.appendChild(node);
2356
+ }
2357
+ function insert(target, node, anchor) {
2358
+ target.insertBefore(node, anchor || null);
2359
+ }
2360
+ function detach(node) {
2361
+ node.parentNode.removeChild(node);
2362
+ }
2363
+ function element(name) {
2364
+ return document.createElement(name);
2365
+ }
2366
+ function text$1(data) {
2367
+ return document.createTextNode(data);
2368
+ }
2369
+ function space() {
2370
+ return text$1(" ");
2371
+ }
2372
+ function attr(node, attribute, value) {
2373
+ if (value == null)
2374
+ node.removeAttribute(attribute);
2375
+ else if (node.getAttribute(attribute) !== value)
2376
+ node.setAttribute(attribute, value);
2377
+ }
2378
+ function children(element2) {
2379
+ return Array.from(element2.childNodes);
2380
+ }
2381
+ function set_data(text2, data) {
2382
+ data = "" + data;
2383
+ if (text2.wholeText !== data)
2384
+ text2.data = data;
2385
+ }
2386
+ function set_style(node, key, value, important) {
2387
+ if (value === null) {
2388
+ node.style.removeProperty(key);
2389
+ } else {
2390
+ node.style.setProperty(key, value, important ? "important" : "");
2391
+ }
2392
+ }
2393
+ let current_component;
2394
+ function set_current_component(component) {
2395
+ current_component = component;
2396
+ }
2397
+ const dirty_components = [];
2398
+ const binding_callbacks = [];
2399
+ const render_callbacks = [];
2400
+ const flush_callbacks = [];
2401
+ const resolved_promise = Promise.resolve();
2402
+ let update_scheduled = false;
2403
+ function schedule_update() {
2404
+ if (!update_scheduled) {
2405
+ update_scheduled = true;
2406
+ resolved_promise.then(flush);
2407
+ }
2408
+ }
2409
+ function add_render_callback(fn) {
2410
+ render_callbacks.push(fn);
2411
+ }
2412
+ const seen_callbacks = new Set();
2413
+ let flushidx = 0;
2414
+ function flush() {
2415
+ const saved_component = current_component;
2416
+ do {
2417
+ while (flushidx < dirty_components.length) {
2418
+ const component = dirty_components[flushidx];
2419
+ flushidx++;
2420
+ set_current_component(component);
2421
+ update(component.$$);
2422
+ }
2423
+ set_current_component(null);
2424
+ dirty_components.length = 0;
2425
+ flushidx = 0;
2426
+ while (binding_callbacks.length)
2427
+ binding_callbacks.pop()();
2428
+ for (let i = 0; i < render_callbacks.length; i += 1) {
2429
+ const callback = render_callbacks[i];
2430
+ if (!seen_callbacks.has(callback)) {
2431
+ seen_callbacks.add(callback);
2432
+ callback();
2433
+ }
2434
+ }
2435
+ render_callbacks.length = 0;
2436
+ } while (dirty_components.length);
2437
+ while (flush_callbacks.length) {
2438
+ flush_callbacks.pop()();
2439
+ }
2440
+ update_scheduled = false;
2441
+ seen_callbacks.clear();
2442
+ set_current_component(saved_component);
2443
+ }
2444
+ function update($$) {
2445
+ if ($$.fragment !== null) {
2446
+ $$.update();
2447
+ run_all($$.before_update);
2448
+ const dirty = $$.dirty;
2449
+ $$.dirty = [-1];
2450
+ $$.fragment && $$.fragment.p($$.ctx, dirty);
2451
+ $$.after_update.forEach(add_render_callback);
2452
+ }
2453
+ }
2454
+ const outroing = new Set();
2455
+ function transition_in(block, local) {
2456
+ if (block && block.i) {
2457
+ outroing.delete(block);
2458
+ block.i(local);
2459
+ }
2460
+ }
2461
+ function mount_component(component, target, anchor, customElement) {
2462
+ const { fragment, on_mount, on_destroy, after_update } = component.$$;
2463
+ fragment && fragment.m(target, anchor);
2464
+ if (!customElement) {
2465
+ add_render_callback(() => {
2466
+ const new_on_destroy = on_mount.map(run).filter(is_function);
2467
+ if (on_destroy) {
2468
+ on_destroy.push(...new_on_destroy);
2469
+ } else {
2470
+ run_all(new_on_destroy);
2471
+ }
2472
+ component.$$.on_mount = [];
2473
+ });
2474
+ }
2475
+ after_update.forEach(add_render_callback);
2476
+ }
2477
+ function destroy_component(component, detaching) {
2478
+ const $$ = component.$$;
2479
+ if ($$.fragment !== null) {
2480
+ run_all($$.on_destroy);
2481
+ $$.fragment && $$.fragment.d(detaching);
2482
+ $$.on_destroy = $$.fragment = null;
2483
+ $$.ctx = [];
2484
+ }
2485
+ }
2486
+ function make_dirty(component, i) {
2487
+ if (component.$$.dirty[0] === -1) {
2488
+ dirty_components.push(component);
2489
+ schedule_update();
2490
+ component.$$.dirty.fill(0);
2491
+ }
2492
+ component.$$.dirty[i / 31 | 0] |= 1 << i % 31;
2493
+ }
2494
+ function init(component, options, instance2, create_fragment2, not_equal, props, append_styles, dirty = [-1]) {
2495
+ const parent_component = current_component;
2496
+ set_current_component(component);
2497
+ const $$ = component.$$ = {
2498
+ fragment: null,
2499
+ ctx: null,
2500
+ props,
2501
+ update: noop,
2502
+ not_equal,
2503
+ bound: blank_object(),
2504
+ on_mount: [],
2505
+ on_destroy: [],
2506
+ on_disconnect: [],
2507
+ before_update: [],
2508
+ after_update: [],
2509
+ context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
2510
+ callbacks: blank_object(),
2511
+ dirty,
2512
+ skip_bound: false,
2513
+ root: options.target || parent_component.$$.root
2514
+ };
2515
+ append_styles && append_styles($$.root);
2516
+ let ready = false;
2517
+ $$.ctx = instance2 ? instance2(component, options.props || {}, (i, ret, ...rest) => {
2518
+ const value = rest.length ? rest[0] : ret;
2519
+ if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
2520
+ if (!$$.skip_bound && $$.bound[i])
2521
+ $$.bound[i](value);
2522
+ if (ready)
2523
+ make_dirty(component, i);
2524
+ }
2525
+ return ret;
2526
+ }) : [];
2527
+ $$.update();
2528
+ ready = true;
2529
+ run_all($$.before_update);
2530
+ $$.fragment = create_fragment2 ? create_fragment2($$.ctx) : false;
2531
+ if (options.target) {
2532
+ if (options.hydrate) {
2533
+ const nodes = children(options.target);
2534
+ $$.fragment && $$.fragment.l(nodes);
2535
+ nodes.forEach(detach);
2536
+ } else {
2537
+ $$.fragment && $$.fragment.c();
2538
+ }
2539
+ if (options.intro)
2540
+ transition_in(component.$$.fragment);
2541
+ mount_component(component, options.target, options.anchor, options.customElement);
2542
+ flush();
2543
+ }
2544
+ set_current_component(parent_component);
2545
+ }
2546
+ class SvelteComponent {
2547
+ $destroy() {
2548
+ destroy_component(this, 1);
2549
+ this.$destroy = noop;
2550
+ }
2551
+ $on(type, callback) {
2552
+ const callbacks2 = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
2553
+ callbacks2.push(callback);
2554
+ return () => {
2555
+ const index = callbacks2.indexOf(callback);
2556
+ if (index !== -1)
2557
+ callbacks2.splice(index, 1);
2558
+ };
2559
+ }
2560
+ $set($$props) {
2561
+ if (this.$$set && !is_empty($$props)) {
2562
+ this.$$.skip_bound = true;
2563
+ this.$$set($$props);
2564
+ this.$$.skip_bound = false;
2565
+ }
2566
+ }
2567
+ }
2568
+ function create_if_block_1(ctx) {
2569
+ let img;
2570
+ let img_style_value;
2571
+ let img_src_value;
2572
+ return {
2573
+ c() {
2574
+ img = element("img");
2575
+ attr(img, "class", "netless-window-manager-cursor-selector-avatar");
2576
+ attr(img, "style", img_style_value = ctx[15]());
2577
+ if (!src_url_equal(img.src, img_src_value = ctx[7]))
2578
+ attr(img, "src", img_src_value);
2579
+ attr(img, "alt", "avatar");
2580
+ },
2581
+ m(target, anchor) {
2582
+ insert(target, img, anchor);
2583
+ },
2584
+ p(ctx2, dirty) {
2585
+ if (dirty & 128 && !src_url_equal(img.src, img_src_value = ctx2[7])) {
2586
+ attr(img, "src", img_src_value);
2587
+ }
2588
+ },
2589
+ d(detaching) {
2590
+ if (detaching)
2591
+ detach(img);
2592
+ }
2593
+ };
2594
+ }
2595
+ function create_if_block(ctx) {
2596
+ let span;
2597
+ let t;
2598
+ return {
2599
+ c() {
2600
+ span = element("span");
2601
+ t = text$1(ctx[1]);
2602
+ attr(span, "class", "netless-window-manager-cursor-tag-name");
2603
+ set_style(span, "background-color", ctx[10]);
2604
+ },
2605
+ m(target, anchor) {
2606
+ insert(target, span, anchor);
2607
+ append(span, t);
2608
+ },
2609
+ p(ctx2, dirty) {
2610
+ if (dirty & 2)
2611
+ set_data(t, ctx2[1]);
2612
+ if (dirty & 1024) {
2613
+ set_style(span, "background-color", ctx2[10]);
2614
+ }
2615
+ },
2616
+ d(detaching) {
2617
+ if (detaching)
2618
+ detach(span);
2619
+ }
2620
+ };
2621
+ }
2622
+ function create_fragment(ctx) {
2623
+ let div3;
2624
+ let div1;
2625
+ let div0;
2626
+ let t0;
2627
+ let span;
2628
+ let t1;
2629
+ let t2;
2630
+ let t3;
2631
+ let div2;
2632
+ let img;
2633
+ let img_class_value;
2634
+ let img_src_value;
2635
+ let if_block0 = ctx[13] && create_if_block_1(ctx);
2636
+ let if_block1 = ctx[14] && create_if_block(ctx);
2637
+ return {
2638
+ c() {
2639
+ div3 = element("div");
2640
+ div1 = element("div");
2641
+ div0 = element("div");
2642
+ if (if_block0)
2643
+ if_block0.c();
2644
+ t0 = space();
2645
+ span = element("span");
2646
+ t1 = text$1(ctx[0]);
2647
+ t2 = space();
2648
+ if (if_block1)
2649
+ if_block1.c();
2650
+ t3 = space();
2651
+ div2 = element("div");
2652
+ img = element("img");
2653
+ set_style(span, "overflow", "hidden");
2654
+ set_style(span, "white-space", "nowrap");
2655
+ set_style(span, "text-overflow", "ellipsis");
2656
+ set_style(span, "max-width", "80px");
2657
+ attr(div0, "class", ctx[8]);
2658
+ set_style(div0, "background-color", ctx[2]);
2659
+ set_style(div0, "color", ctx[9]);
2660
+ set_style(div0, "opacity", ctx[11]);
2661
+ attr(div1, "class", "netless-window-manager-cursor-name");
2662
+ attr(img, "class", img_class_value = "netless-window-manager-cursor-" + ctx[3] + "-image");
2663
+ if (!src_url_equal(img.src, img_src_value = ctx[6]))
2664
+ attr(img, "src", img_src_value);
2665
+ attr(img, "alt", ctx[3]);
2666
+ attr(div2, "class", "cursor-image-wrapper");
2667
+ attr(div3, "class", "netless-window-manager-cursor-mid");
2668
+ set_style(div3, "transform", "translateX(" + ctx[4] + "px) translateY(" + ctx[5] + "px)");
2669
+ set_style(div3, "display", ctx[12]);
2670
+ },
2671
+ m(target, anchor) {
2672
+ insert(target, div3, anchor);
2673
+ append(div3, div1);
2674
+ append(div1, div0);
2675
+ if (if_block0)
2676
+ if_block0.m(div0, null);
2677
+ append(div0, t0);
2678
+ append(div0, span);
2679
+ append(span, t1);
2680
+ append(div0, t2);
2681
+ if (if_block1)
2682
+ if_block1.m(div0, null);
2683
+ append(div3, t3);
2684
+ append(div3, div2);
2685
+ append(div2, img);
2686
+ },
2687
+ p(ctx2, [dirty]) {
2688
+ if (ctx2[13]) {
2689
+ if (if_block0) {
2690
+ if_block0.p(ctx2, dirty);
2691
+ } else {
2692
+ if_block0 = create_if_block_1(ctx2);
2693
+ if_block0.c();
2694
+ if_block0.m(div0, t0);
2695
+ }
2696
+ } else if (if_block0) {
2697
+ if_block0.d(1);
2698
+ if_block0 = null;
2699
+ }
2700
+ if (dirty & 1)
2701
+ set_data(t1, ctx2[0]);
2702
+ if (ctx2[14]) {
2703
+ if (if_block1) {
2704
+ if_block1.p(ctx2, dirty);
2705
+ } else {
2706
+ if_block1 = create_if_block(ctx2);
2707
+ if_block1.c();
2708
+ if_block1.m(div0, null);
2709
+ }
2710
+ } else if (if_block1) {
2711
+ if_block1.d(1);
2712
+ if_block1 = null;
2713
+ }
2714
+ if (dirty & 256) {
2715
+ attr(div0, "class", ctx2[8]);
2716
+ }
2717
+ if (dirty & 4) {
2718
+ set_style(div0, "background-color", ctx2[2]);
2719
+ }
2720
+ if (dirty & 512) {
2721
+ set_style(div0, "color", ctx2[9]);
2722
+ }
2723
+ if (dirty & 2048) {
2724
+ set_style(div0, "opacity", ctx2[11]);
2725
+ }
2726
+ if (dirty & 8 && img_class_value !== (img_class_value = "netless-window-manager-cursor-" + ctx2[3] + "-image")) {
2727
+ attr(img, "class", img_class_value);
2728
+ }
2729
+ if (dirty & 64 && !src_url_equal(img.src, img_src_value = ctx2[6])) {
2730
+ attr(img, "src", img_src_value);
2731
+ }
2732
+ if (dirty & 8) {
2733
+ attr(img, "alt", ctx2[3]);
2734
+ }
2735
+ if (dirty & 48) {
2736
+ set_style(div3, "transform", "translateX(" + ctx2[4] + "px) translateY(" + ctx2[5] + "px)");
2737
+ }
2738
+ if (dirty & 4096) {
2739
+ set_style(div3, "display", ctx2[12]);
2740
+ }
2741
+ },
2742
+ i: noop,
2743
+ o: noop,
2744
+ d(detaching) {
2745
+ if (detaching)
2746
+ detach(div3);
2747
+ if (if_block0)
2748
+ if_block0.d();
2749
+ if (if_block1)
2750
+ if_block1.d();
2751
+ }
2752
+ };
2753
+ }
2754
+ function instance($$self, $$props, $$invalidate) {
2755
+ let hasName;
2756
+ let hasTagName;
2757
+ let hasAvatar;
2758
+ let display;
2759
+ let { cursorName } = $$props;
2760
+ let { tagName } = $$props;
2761
+ let { backgroundColor } = $$props;
2762
+ let { appliance } = $$props;
2763
+ let { x } = $$props;
2764
+ let { y } = $$props;
2765
+ let { src } = $$props;
2766
+ let { visible } = $$props;
2767
+ let { avatar } = $$props;
2768
+ let { theme } = $$props;
2769
+ let { color } = $$props;
2770
+ let { cursorTagBackgroundColor } = $$props;
2771
+ let { opacity } = $$props;
2772
+ const computedAvatarStyle = () => {
2773
+ return Object.entries({
2774
+ width: (hasName ? 19 : 28) + "px",
2775
+ height: (hasName ? 19 : 28) + "px",
2776
+ position: hasName ? "initial" : "absolute",
2777
+ "border-color": hasName ? "white" : backgroundColor,
2778
+ "margin-right": (hasName ? 4 : 0) + "px"
2779
+ }).map(([key, v]) => `${key}: ${v}`).join(";");
2780
+ };
2781
+ $$self.$$set = ($$props2) => {
2782
+ if ("cursorName" in $$props2)
2783
+ $$invalidate(0, cursorName = $$props2.cursorName);
2784
+ if ("tagName" in $$props2)
2785
+ $$invalidate(1, tagName = $$props2.tagName);
2786
+ if ("backgroundColor" in $$props2)
2787
+ $$invalidate(2, backgroundColor = $$props2.backgroundColor);
2788
+ if ("appliance" in $$props2)
2789
+ $$invalidate(3, appliance = $$props2.appliance);
2790
+ if ("x" in $$props2)
2791
+ $$invalidate(4, x = $$props2.x);
2792
+ if ("y" in $$props2)
2793
+ $$invalidate(5, y = $$props2.y);
2794
+ if ("src" in $$props2)
2795
+ $$invalidate(6, src = $$props2.src);
2796
+ if ("visible" in $$props2)
2797
+ $$invalidate(16, visible = $$props2.visible);
2798
+ if ("avatar" in $$props2)
2799
+ $$invalidate(7, avatar = $$props2.avatar);
2800
+ if ("theme" in $$props2)
2801
+ $$invalidate(8, theme = $$props2.theme);
2802
+ if ("color" in $$props2)
2803
+ $$invalidate(9, color = $$props2.color);
2804
+ if ("cursorTagBackgroundColor" in $$props2)
2805
+ $$invalidate(10, cursorTagBackgroundColor = $$props2.cursorTagBackgroundColor);
2806
+ if ("opacity" in $$props2)
2807
+ $$invalidate(11, opacity = $$props2.opacity);
2808
+ };
2809
+ $$self.$$.update = () => {
2810
+ if ($$self.$$.dirty & 1) {
2811
+ hasName = !isEmpty(cursorName);
2812
+ }
2813
+ if ($$self.$$.dirty & 2) {
2814
+ $$invalidate(14, hasTagName = !isEmpty(tagName));
2815
+ }
2816
+ if ($$self.$$.dirty & 128) {
2817
+ $$invalidate(13, hasAvatar = !isEmpty(avatar));
2818
+ }
2819
+ if ($$self.$$.dirty & 65536) {
2820
+ $$invalidate(12, display = visible ? "initial" : "none");
2821
+ }
2822
+ };
2823
+ return [
2824
+ cursorName,
2825
+ tagName,
2826
+ backgroundColor,
2827
+ appliance,
2828
+ x,
2829
+ y,
2830
+ src,
2831
+ avatar,
2832
+ theme,
2833
+ color,
2834
+ cursorTagBackgroundColor,
2835
+ opacity,
2836
+ display,
2837
+ hasAvatar,
2838
+ hasTagName,
2839
+ computedAvatarStyle,
2840
+ visible
2841
+ ];
2842
+ }
2843
+ class Cursor$1 extends SvelteComponent {
2844
+ constructor(options) {
2845
+ super();
2846
+ init(this, options, instance, create_fragment, safe_not_equal, {
2847
+ cursorName: 0,
2848
+ tagName: 1,
2849
+ backgroundColor: 2,
2850
+ appliance: 3,
2851
+ x: 4,
2852
+ y: 5,
2853
+ src: 6,
2854
+ visible: 16,
2855
+ avatar: 7,
2856
+ theme: 8,
2857
+ color: 9,
2858
+ cursorTagBackgroundColor: 10,
2859
+ opacity: 11
2860
+ });
2861
+ }
2862
+ }
2863
+ var pencil = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAYAAADFeBvrAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAYISURBVHgB7ZpNSCtXFIBPEuvz+dMGpYUKD/sWFX+Qti6kK7Hqpm6e9q0rIoIUFUShPLV10VZx4+JZqa9v20LB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AxNS44NjU0ODc3LDEzLjAxMDA1MjEgTDE2LDEzIEwyNCwxMyBDMjQuNTUyMjg0NywxMyAyNSwxMy40NDc3MTUzIDI1LDE0IEMyNSwxNC40ODU0MTAzIDI0LjY1MjAwMDcsMTQuODk4MDg1IDI0LjEzNDUxMjMsMTQuOTg5OTQ3OSBMMjQsMTUgTDIxLDE1IEwyMSwyNSBMMjQsMjUgQzI0LjU1MjI4NDcsMjUgMjUsMjUuNDQ3NzE1MyAyNSwyNiBDMjUsMjYuNDg1NDEwMyAyNC42NTIwMDA3LDI2Ljg5ODA4NSAyNC4xMzQ1MTIzLDI2Ljk4OTk0NzkgTDI0LDI3IEwxNiwyNyBDMTUuNDQ3NzE1MywyNyAxNSwyNi41NTIyODQ3IDE1LDI2IEMxNSwyNS41MTQ1ODk3IDE1LjM0Nzk5OTMsMjUuMTAxOTE1IDE1Ljg2NTQ4NzcsMjUuMDEwMDUyMSBMMTYsMjUgTDE5LDI1IFoiIGZpbGw9IiMyMTIzMjQiIGZpbGwtcnVsZT0iZXZlbm9kZCI+PC9wYXRoPgogICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICA8L2c+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4=";
2868
+ const ApplianceMap = {
2869
+ [ApplianceNames.pencil]: pencil,
2870
+ [ApplianceNames.selector]: selector,
2871
+ [ApplianceNames.eraser]: eraser,
2872
+ [ApplianceNames.shape]: shape,
2873
+ [ApplianceNames.text]: text
2874
+ };
2875
+ class Cursor extends Base {
2876
+ constructor(manager, addCursorChangeListener, cursors, memberId, cursorManager, wrapper) {
2877
+ super(manager);
2878
+ this.cursors = cursors;
2879
+ this.memberId = memberId;
2880
+ this.cursorManager = cursorManager;
2881
+ this.wrapper = wrapper;
2882
+ this.onCursorChange = (position, state) => {
2883
+ var _a;
2884
+ if (position.type === "main") {
2885
+ const rect = this.cursorManager.wrapperRect;
2886
+ if (this.component && rect) {
2887
+ this.autoHidden();
2888
+ this.moveCursor(position, rect, this.manager.mainView);
2889
+ }
2890
+ } else {
2891
+ const focusView = this.cursorManager.focusView;
2892
+ const viewRect = (_a = focusView == null ? void 0 : focusView.divElement) == null ? void 0 : _a.getBoundingClientRect();
2893
+ const viewCamera = focusView == null ? void 0 : focusView.camera;
2894
+ if (focusView && viewRect && viewCamera && this.component) {
2895
+ this.autoHidden();
2896
+ this.moveCursor(position, viewRect, focusView);
2897
+ }
2898
+ }
2899
+ if (state && state === CursorState.Leave) {
2900
+ this.hide();
2901
+ }
2902
+ };
2903
+ this.setMember();
2904
+ this.createCursor();
2905
+ addCursorChangeListener(this.memberId, this.onCursorChange);
2906
+ this.autoHidden();
2907
+ }
2908
+ moveCursor(cursor, rect, view) {
2909
+ var _a, _b;
2910
+ const { x, y, type } = cursor;
2911
+ const point = view == null ? void 0 : view.screen.convertPointToScreen(x, y);
2912
+ if (point) {
2913
+ let translateX = point.x - 2;
2914
+ let translateY = point.y - 18;
2915
+ if (type === "app") {
2916
+ const wrapperRect = this.cursorManager.wrapperRect;
2917
+ if (wrapperRect) {
2918
+ translateX = translateX + rect.x - wrapperRect.x;
2919
+ translateY = translateY + rect.y - wrapperRect.y;
2920
+ }
2921
+ }
2922
+ if (point.x < 0 || point.x > rect.width || point.y < 0 || point.y > rect.height) {
2923
+ (_a = this.component) == null ? void 0 : _a.$set({ visible: false, x: translateX, y: translateY });
2924
+ } else {
2925
+ (_b = this.component) == null ? void 0 : _b.$set({ visible: true, x: translateX, y: translateY });
2926
+ }
2927
+ }
2928
+ }
2929
+ get memberApplianceName() {
2930
+ var _a, _b;
2931
+ return (_b = (_a = this.member) == null ? void 0 : _a.memberState) == null ? void 0 : _b.currentApplianceName;
2932
+ }
2933
+ get memberColor() {
2934
+ var _a, _b;
2935
+ const rgb = (_b = (_a = this.member) == null ? void 0 : _a.memberState) == null ? void 0 : _b.strokeColor.join(",");
2936
+ return `rgb(${rgb})`;
2937
+ }
2938
+ get payload() {
2939
+ var _a;
2940
+ return (_a = this.member) == null ? void 0 : _a.payload;
2941
+ }
2942
+ get memberCursorName() {
2943
+ var _a, _b;
2944
+ return ((_a = this.payload) == null ? void 0 : _a.nickName) || ((_b = this.payload) == null ? void 0 : _b.cursorName) || this.memberId;
2945
+ }
2946
+ get memberTheme() {
2947
+ var _a;
2948
+ if ((_a = this.payload) == null ? void 0 : _a.theme) {
2949
+ return "netless-window-manager-cursor-inner-mellow";
2950
+ } else {
2951
+ return "netless-window-manager-cursor-inner";
2952
+ }
2953
+ }
2954
+ get memberCursorTextColor() {
2955
+ var _a;
2956
+ return ((_a = this.payload) == null ? void 0 : _a.cursorTextColor) || "#FFFFFF";
2957
+ }
2958
+ get memberCursorTagBackgroundColor() {
2959
+ var _a;
2960
+ return ((_a = this.payload) == null ? void 0 : _a.cursorTagBackgroundColor) || this.memberColor;
2961
+ }
2962
+ get memberAvatar() {
2963
+ var _a;
2964
+ return (_a = this.payload) == null ? void 0 : _a.avatar;
2965
+ }
2966
+ get memberOpacity() {
2967
+ if (!this.memberCursorName && !this.memberAvatar) {
2968
+ return 0;
2969
+ } else {
2970
+ return 1;
2971
+ }
2972
+ }
2973
+ get cursorState() {
2974
+ return get(this.cursors, [this.memberId, Fields.CursorState]);
2975
+ }
2976
+ get cursorPosition() {
2977
+ return get(this.cursors, [this.memberId, Fields.Position]);
2978
+ }
2979
+ autoHidden() {
2980
+ if (this.timer) {
2981
+ clearTimeout(this.timer);
2982
+ }
2983
+ this.timer = window.setTimeout(() => {
2984
+ this.hide();
2985
+ this.store.updateCursorState(this.memberId, CursorState.Leave);
2986
+ }, 1e3 * 10);
2987
+ }
2988
+ async createCursor() {
2989
+ if (this.member && this.wrapper) {
2990
+ this.component = new Cursor$1({
2991
+ target: this.wrapper,
2992
+ props: this.initProps()
2993
+ });
2994
+ }
2995
+ }
2996
+ initProps() {
2997
+ return {
2998
+ x: 0,
2999
+ y: 0,
3000
+ appliance: this.memberApplianceName,
3001
+ avatar: this.memberAvatar,
3002
+ src: this.getIcon(),
3003
+ visible: false,
3004
+ backgroundColor: this.memberColor,
3005
+ cursorName: this.memberCursorName,
3006
+ theme: this.memberTheme,
3007
+ color: this.memberCursorTextColor,
3008
+ cursorTagBackgroundColor: this.memberCursorTagBackgroundColor,
3009
+ opacity: this.memberOpacity
3010
+ };
3011
+ }
3012
+ getIcon() {
3013
+ if (this.member) {
3014
+ const applianceSrc = ApplianceMap[this.memberApplianceName || ApplianceNames.shape];
3015
+ return applianceSrc || ApplianceMap[ApplianceNames.shape];
3016
+ }
3017
+ }
3018
+ setMember() {
3019
+ this.member = this.context.findMemberByUid(this.memberId);
3020
+ this.updateComponent();
3021
+ }
3022
+ updateComponent() {
3023
+ var _a;
3024
+ (_a = this.component) == null ? void 0 : _a.$set(omit(this.initProps(), ["x", "y"]));
3025
+ }
3026
+ destroy() {
3027
+ var _a;
3028
+ if (this.component) {
3029
+ this.component.$destroy();
3030
+ }
3031
+ (_a = this.manager.refresher) == null ? void 0 : _a.remove(this.memberId);
3032
+ this.cursorManager.cursorInstances.delete(this.memberId);
3033
+ }
3034
+ hide() {
3035
+ if (this.component) {
3036
+ this.component.$set({ visible: false });
3037
+ }
3038
+ }
3039
+ }
3040
+ class CursorManager extends Base {
3041
+ constructor(appManager) {
3042
+ super(appManager);
3043
+ var _a;
3044
+ this.appManager = appManager;
3045
+ this.cursorInstances = new Map();
3046
+ this.sideEffectManager = new SideEffectManager();
3047
+ this.getUids = (members) => {
3048
+ return compact(uniq(members == null ? void 0 : members.map((member) => {
3049
+ var _a2;
3050
+ return (_a2 = member.payload) == null ? void 0 : _a2.uid;
3051
+ })));
3052
+ };
3053
+ this.handleRoomMembersChange = debounce((wrapper2) => {
3054
+ const uids = this.getUids(this.roomMembers);
3055
+ const cursors = Object.keys(this.cursors);
3056
+ if (uids == null ? void 0 : uids.length) {
3057
+ cursors.map((uid) => {
3058
+ if (uids.includes(uid) && !this.cursorInstances.has(uid)) {
3059
+ if (uid === this.context.uid) {
3060
+ return;
3061
+ }
3062
+ const component = new Cursor(this.appManager, this.addCursorChangeListener, this.cursors, uid, this, wrapper2);
3063
+ this.cursorInstances.set(uid, component);
3064
+ }
3065
+ });
3066
+ }
3067
+ }, 100);
3068
+ this.mouseMoveListener = debounce((event) => {
3069
+ this.updateCursor(this.getType(event), event.clientX, event.clientY);
3070
+ }, 5);
3071
+ this.getPoint = (view, clientX, clientY) => {
3072
+ var _a2;
3073
+ const rect = (_a2 = view == null ? void 0 : view.divElement) == null ? void 0 : _a2.getBoundingClientRect();
3074
+ if (rect) {
3075
+ const point = view == null ? void 0 : view.convertToPointInWorld({
3076
+ x: clientX - rect.x,
3077
+ y: clientY - rect.y
3078
+ });
3079
+ return point;
3080
+ }
3081
+ };
3082
+ this.getType = (event) => {
3083
+ var _a2;
3084
+ const target = event.target;
3085
+ const focusApp = this.appManager.focusApp;
3086
+ switch (target.parentElement) {
3087
+ case this.mainViewElement: {
3088
+ return { type: "main" };
3089
+ }
3090
+ case ((_a2 = focusApp == null ? void 0 : focusApp.view) == null ? void 0 : _a2.divElement): {
3091
+ return { type: "app" };
3092
+ }
3093
+ default: {
3094
+ return { type: "main" };
3095
+ }
3096
+ }
3097
+ };
3098
+ this.mouseLeaveListener = () => {
3099
+ this.hideCursor(this.context.uid);
3100
+ this.store.updateCursorState(this.context.uid, CursorState.Leave);
3101
+ };
3102
+ this.addCursorChangeListener = (uid, callback) => {
3103
+ var _a2;
3104
+ (_a2 = this.manager.refresher) == null ? void 0 : _a2.add(uid, () => {
3105
+ const disposer = autorun(() => {
3106
+ const position = get(this.cursors, [uid, Fields.Position]);
3107
+ const state = get(this.cursors, [uid, Fields.CursorState]);
3108
+ if (position) {
3109
+ callback(position, state);
3110
+ }
3111
+ });
3112
+ return disposer;
3113
+ });
3114
+ };
3115
+ this.roomMembers = (_a = this.appManager.room) == null ? void 0 : _a.state.roomMembers;
3116
+ const wrapper = WindowManager.wrapper;
3117
+ if (wrapper) {
3118
+ this.setupWrapper(wrapper);
3119
+ }
3120
+ emitter.on("onReconnected", () => {
3121
+ this.onReconnect();
3122
+ });
3123
+ }
3124
+ setupWrapper(wrapper) {
3125
+ var _a;
3126
+ if ((_a = this.manager.refresher) == null ? void 0 : _a.hasReactor("cursors")) {
3127
+ this.destroy();
3128
+ }
3129
+ this.sideEffectManager.add(() => {
3130
+ wrapper.addEventListener("pointerenter", this.mouseMoveListener);
3131
+ wrapper.addEventListener("pointermove", this.mouseMoveListener);
3132
+ wrapper.addEventListener("pointerleave", this.mouseLeaveListener);
3133
+ return () => {
3134
+ wrapper.removeEventListener("pointerenter", this.mouseMoveListener);
3135
+ wrapper.removeEventListener("pointermove", this.mouseMoveListener);
3136
+ wrapper.removeEventListener("pointerleave", this.mouseLeaveListener);
3137
+ };
3138
+ });
3139
+ this.initCursorAttributes();
3140
+ this.wrapperRect = wrapper.getBoundingClientRect();
3141
+ this.startReaction(wrapper);
3142
+ }
3143
+ setMainViewDivElement(div) {
3144
+ this.mainViewElement = div;
3145
+ }
3146
+ startReaction(wrapper) {
3147
+ var _a;
3148
+ (_a = this.manager.refresher) == null ? void 0 : _a.add("cursors", () => {
3149
+ return onObjectInserted(this.cursors, () => {
3150
+ this.handleRoomMembersChange(wrapper);
3151
+ });
3152
+ });
3153
+ }
3154
+ get cursors() {
3155
+ var _a;
3156
+ return (_a = this.manager.attributes) == null ? void 0 : _a[Fields.Cursors];
3157
+ }
3158
+ get boxState() {
3159
+ return this.store.getBoxState();
3160
+ }
3161
+ get focusView() {
3162
+ var _a;
3163
+ return (_a = this.appManager.focusApp) == null ? void 0 : _a.view;
3164
+ }
3165
+ updateCursor(event, clientX, clientY) {
3166
+ if (this.wrapperRect && this.manager.canOperate) {
3167
+ const view = event.type === "main" ? this.appManager.mainView : this.focusView;
3168
+ const point = this.getPoint(view, clientX, clientY);
3169
+ if (point) {
3170
+ this.setNormalCursorState();
3171
+ this.store.updateCursor(this.context.uid, __spreadValues({
3172
+ x: point.x,
3173
+ y: point.y
3174
+ }, event));
3175
+ }
3176
+ }
3177
+ }
3178
+ initCursorAttributes() {
3179
+ this.store.updateCursor(this.context.uid, {
3180
+ x: 0,
3181
+ y: 0,
3182
+ type: "main"
3183
+ });
3184
+ this.store.updateCursorState(this.context.uid, CursorState.Leave);
3185
+ }
3186
+ setNormalCursorState() {
3187
+ const cursorState = this.store.getCursorState(this.context.uid);
3188
+ if (cursorState !== CursorState.Normal) {
3189
+ this.store.updateCursorState(this.context.uid, CursorState.Normal);
3190
+ }
3191
+ }
3192
+ updateContainerRect() {
3193
+ var _a, _b;
3194
+ this.containerRect = (_a = WindowManager.container) == null ? void 0 : _a.getBoundingClientRect();
3195
+ this.wrapperRect = (_b = WindowManager.wrapper) == null ? void 0 : _b.getBoundingClientRect();
3196
+ }
3197
+ setRoomMembers(members) {
3198
+ this.roomMembers = members;
3199
+ this.cursorInstances.forEach((cursor) => {
3200
+ cursor.setMember();
3201
+ });
3202
+ if (WindowManager.wrapper) {
3203
+ this.handleRoomMembersChange(WindowManager.wrapper);
3204
+ }
3205
+ }
3206
+ deleteCursor(uid) {
3207
+ this.store.cleanCursor(uid);
3208
+ const cursor = this.cursorInstances.get(uid);
3209
+ if (cursor) {
3210
+ cursor.destroy();
3211
+ }
3212
+ }
3213
+ hideCursor(uid) {
3214
+ const cursor = this.cursorInstances.get(uid);
3215
+ if (cursor) {
3216
+ cursor.hide();
3217
+ }
3218
+ }
3219
+ cleanMemberAttributes(members) {
3220
+ const uids = this.getUids(members);
3221
+ const needDeleteIds = [];
3222
+ const cursors = Object.keys(this.cursors);
3223
+ cursors.map((cursorId) => {
3224
+ const index = uids.findIndex((id) => id === cursorId);
3225
+ if (index === -1) {
3226
+ needDeleteIds.push(cursorId);
3227
+ }
3228
+ });
3229
+ needDeleteIds.forEach((uid) => {
3230
+ this.deleteCursor(uid);
3231
+ });
3232
+ }
3233
+ onReconnect() {
3234
+ var _a;
3235
+ if (this.cursorInstances.size) {
3236
+ this.cursorInstances.forEach((cursor) => cursor.destroy());
3237
+ this.cursorInstances.clear();
3238
+ }
3239
+ this.roomMembers = (_a = this.appManager.room) == null ? void 0 : _a.state.roomMembers;
3240
+ if (WindowManager.wrapper) {
3241
+ this.handleRoomMembersChange(WindowManager.wrapper);
3242
+ }
3243
+ }
3244
+ destroy() {
3245
+ var _a;
3246
+ this.sideEffectManager.flushAll();
3247
+ if (this.cursorInstances.size) {
3248
+ this.cursorInstances.forEach((cursor) => {
3249
+ cursor.destroy();
3250
+ });
3251
+ this.cursorInstances.clear();
3252
+ }
3253
+ (_a = this.manager.refresher) == null ? void 0 : _a.remove("cursors");
3254
+ }
3255
+ }
3256
+ class ReconnectRefresher {
3257
+ constructor(ctx) {
3258
+ this.ctx = ctx;
3259
+ this.reactors = new Map();
3260
+ this.disposers = new Map();
3261
+ this.onPhaseChanged = (phase) => {
3262
+ if (phase === RoomPhase.Connected && this.phase === RoomPhase.Reconnecting) {
3263
+ this.onReconnected();
3264
+ }
3265
+ this.phase = phase;
3266
+ };
3267
+ this.onReconnected = debounce(() => {
3268
+ log("onReconnected refresh reactors");
3269
+ this.releaseDisposers();
3270
+ this.reactors.forEach((func, id) => {
3271
+ if (isFunction(func)) {
3272
+ this.disposers.set(id, func());
3273
+ }
3274
+ });
3275
+ this.ctx.emitter.emit("onReconnected", void 0);
3276
+ }, 3e3);
3277
+ }
3278
+ setRoom(room) {
3279
+ this.room = room;
3280
+ this.phase = room == null ? void 0 : room.phase;
3281
+ room == null ? void 0 : room.callbacks.off("onPhaseChanged", this.onPhaseChanged);
3282
+ room == null ? void 0 : room.callbacks.on("onPhaseChanged", this.onPhaseChanged);
3283
+ }
3284
+ setContext(ctx) {
3285
+ this.ctx = ctx;
3286
+ }
3287
+ releaseDisposers() {
3288
+ this.disposers.forEach((disposer) => {
3289
+ if (isFunction(disposer)) {
3290
+ disposer();
3291
+ }
3292
+ });
3293
+ this.disposers.clear();
3294
+ }
3295
+ add(id, func) {
3296
+ if (isFunction(func)) {
3297
+ this.reactors.set(id, func);
3298
+ this.disposers.set(id, func());
3299
+ }
3300
+ }
3301
+ remove(id) {
3302
+ if (this.reactors.has(id)) {
3303
+ this.reactors.delete(id);
3304
+ }
3305
+ const disposer = this.disposers.get(id);
3306
+ if (disposer) {
3307
+ if (isFunction(disposer)) {
3308
+ disposer();
3309
+ }
3310
+ this.disposers.delete(id);
3311
+ }
3312
+ }
3313
+ hasReactor(id) {
3314
+ return this.reactors.has(id);
3315
+ }
3316
+ destroy() {
3317
+ var _a;
3318
+ (_a = this.room) == null ? void 0 : _a.callbacks.off("onPhaseChanged", this.onPhaseChanged);
3319
+ this.releaseDisposers();
3320
+ }
3321
+ }
3322
+ const replaceRoomFunction = (room, manager) => {
3323
+ if (isPlayer(room)) {
3324
+ const player = room;
3325
+ const originSeek = player.seekToProgressTime;
3326
+ async function newSeek(time) {
3327
+ const seekResult = await originSeek.call(player, time);
3328
+ if (seekResult === "success") {
3329
+ emitter.emit("seek", time);
3330
+ }
3331
+ return seekResult;
3332
+ }
3333
+ player.seekToProgressTime = newSeek;
3334
+ } else {
3335
+ const descriptor = Object.getOwnPropertyDescriptor(room, "disableCameraTransform");
3336
+ if (descriptor)
3337
+ return;
3338
+ Object.defineProperty(room, "disableCameraTransform", {
3339
+ get() {
3340
+ return manager.mainView.disableCameraTransform;
3341
+ },
3342
+ set(disable) {
3343
+ manager.mainView.disableCameraTransform = disable;
3344
+ }
3345
+ });
3346
+ Object.defineProperty(room, "canUndoSteps", {
3347
+ get() {
3348
+ return manager.mainView.canUndoSteps;
3349
+ }
3350
+ });
3351
+ Object.defineProperty(room, "canRedoSteps", {
3352
+ get() {
3353
+ return manager.mainView.canRedoSteps;
3354
+ }
3355
+ });
3356
+ room.moveCamera = (camera) => manager.mainView.moveCamera(camera);
3357
+ room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
3358
+ room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
3359
+ room.setCameraBound = (...args) => manager.mainView.setCameraBound(...args);
3360
+ room.scenePreview = (...args) => manager.mainView.scenePreview(...args);
3361
+ room.fillSceneSnapshot = (...args) => manager.mainView.fillSceneSnapshot(...args);
3362
+ room.generateScreenshot = (...args) => manager.mainView.generateScreenshot(...args);
3363
+ room.setMemberState = (...args) => manager.mainView.setMemberState(...args);
3364
+ room.redo = () => manager.mainView.redo();
3365
+ room.undo = () => manager.mainView.undo();
3366
+ room.cleanCurrentScene = () => manager.mainView.cleanCurrentScene();
3367
+ }
3368
+ };
3369
+ var style$2 = "";
3370
+ const setupBuiltin = () => {
3371
+ if (WindowManager.debug) {
3372
+ setOptions({ verbose: true });
3373
+ }
3374
+ WindowManager.register({
3375
+ kind: AppDocsViewer.kind,
3376
+ src: AppDocsViewer
3377
+ });
3378
+ WindowManager.register({
3379
+ kind: AppMediaPlayer.kind,
3380
+ src: AppMediaPlayer
3381
+ });
3382
+ };
3383
+ const BuiltinApps = {
3384
+ DocsViewer: AppDocsViewer.kind,
3385
+ MediaPlayer: AppMediaPlayer.kind
3386
+ };
3387
+ const setupWrapper = (root) => {
3388
+ const playground = document.createElement("div");
3389
+ playground.className = "netless-window-manager-playground";
3390
+ const sizer = document.createElement("div");
3391
+ sizer.className = "netless-window-manager-sizer";
3392
+ const wrapper = document.createElement("div");
3393
+ wrapper.className = "netless-window-manager-wrapper";
3394
+ const mainViewElement = document.createElement("div");
3395
+ mainViewElement.className = "netless-window-manager-main-view";
3396
+ playground.appendChild(sizer);
3397
+ sizer.appendChild(wrapper);
3398
+ wrapper.appendChild(mainViewElement);
3399
+ root.appendChild(playground);
3400
+ WindowManager.wrapper = wrapper;
3401
+ return { playground, wrapper, sizer, mainViewElement };
3402
+ };
3403
+ var style$1 = "";
3404
+ var style = "";
3405
+ const emitter = new Emittery();
3406
+ const callbacks = new Emittery();
3407
+ const reconnectRefresher = new ReconnectRefresher({ emitter });
3408
+ const _WindowManager = class extends InvisiblePlugin {
3409
+ constructor(context2) {
3410
+ super(context2);
3411
+ this.version = "0.4.0-canary.16";
3412
+ this.emitter = callbacks;
3413
+ this.viewMode = ViewMode.Broadcaster;
3414
+ this.isReplay = isPlayer(this.displayer);
3415
+ _WindowManager.displayer = context2.displayer;
3416
+ }
3417
+ static async mount(params) {
3418
+ const room = params.room;
3419
+ _WindowManager.container = params.container;
3420
+ const containerSizeRatio = params.containerSizeRatio;
3421
+ const debug = params.debug;
3422
+ const cursor = params.cursor;
3423
+ _WindowManager.params = params;
3424
+ this.checkVersion();
3425
+ if (isRoom(room)) {
3426
+ if (room.phase !== RoomPhase.Connected) {
3427
+ throw new Error("[WindowManager]: Room only Connected can be mount");
3428
+ }
3429
+ if (room.phase === RoomPhase.Connected && room.isWritable) {
3430
+ room.disableSerialization = false;
3431
+ }
3432
+ }
3433
+ if (_WindowManager.isCreated) {
3434
+ throw new Error("[WindowManager]: Already created cannot be created again");
3435
+ }
3436
+ let manager = await this.initManager(room);
3437
+ this.debug = Boolean(debug);
3438
+ log("Already insert room", manager);
3439
+ if (isRoom(this.displayer)) {
3440
+ if (!manager) {
3441
+ throw new Error("[WindowManager]: init InvisiblePlugin failed");
3442
+ }
3443
+ } else {
3444
+ await pRetry(async (count) => {
3445
+ manager = await this.initManager(room);
3446
+ if (!manager) {
3447
+ log(`manager is empty. retrying ${count}`);
3448
+ throw new Error();
3449
+ }
3450
+ }, { retries: 10 });
3451
+ }
3452
+ if (containerSizeRatio) {
3453
+ _WindowManager.containerSizeRatio = containerSizeRatio;
3454
+ }
3455
+ await manager.ensureAttributes();
3456
+ manager.appManager = new AppManager(manager);
3457
+ if (cursor) {
3458
+ manager.cursorManager = new CursorManager(manager.appManager);
3459
+ }
3460
+ if (params.container) {
3461
+ manager.bindContainer(params.container);
3462
+ }
3463
+ replaceRoomFunction(room, manager);
3464
+ emitter.emit("onCreated");
3465
+ _WindowManager.isCreated = true;
3466
+ try {
3467
+ await initDb();
3468
+ } catch (error) {
3469
+ console.warn("[WindowManager]: indexedDB open failed");
3470
+ console.log(error);
3471
+ }
3472
+ return manager;
3473
+ }
3474
+ static async initManager(room) {
3475
+ let manager = room.getInvisiblePlugin(_WindowManager.kind);
3476
+ if (!manager) {
3477
+ if (isRoom(room)) {
3478
+ if (room.isWritable === false) {
3479
+ try {
3480
+ await room.setWritable(true);
3481
+ } catch (error) {
3482
+ throw new Error("[WindowManger]: room must be switched to be writable");
3483
+ }
3484
+ manager = await room.createInvisiblePlugin(_WindowManager, {});
3485
+ manager.ensureAttributes();
3486
+ await wait(500);
3487
+ await room.setWritable(false);
3488
+ } else {
3489
+ manager = await room.createInvisiblePlugin(_WindowManager, {});
3490
+ }
3491
+ }
3492
+ }
3493
+ return manager;
3494
+ }
3495
+ static initContainer(manager, container, chessboard, overwriteStyles) {
3496
+ if (!_WindowManager.container) {
3497
+ _WindowManager.container = container;
3498
+ }
3499
+ const { playground, wrapper, sizer, mainViewElement } = setupWrapper(container);
3500
+ _WindowManager.playground = playground;
3501
+ if (chessboard) {
3502
+ sizer.classList.add("netless-window-manager-chess-sizer");
3503
+ }
3504
+ if (overwriteStyles) {
3505
+ const style2 = document.createElement("style");
3506
+ style2.textContent = overwriteStyles;
3507
+ playground.appendChild(style2);
3508
+ }
3509
+ manager.containerResizeObserver = ContainerResizeObserver.create(playground, sizer, wrapper, emitter);
3510
+ _WindowManager.wrapper = wrapper;
3511
+ return mainViewElement;
3512
+ }
3513
+ bindContainer(container) {
3514
+ var _a, _b, _c, _d, _e, _f;
3515
+ if (_WindowManager.isCreated && _WindowManager.container) {
3516
+ if (_WindowManager.container.firstChild) {
3517
+ container.appendChild(_WindowManager.container.firstChild);
3518
+ }
3519
+ } else {
3520
+ if (_WindowManager.params) {
3521
+ const params = _WindowManager.params;
3522
+ const mainViewElement = _WindowManager.initContainer(this, container, params.chessboard, params.overwriteStyles);
3523
+ const boxManager = createBoxManager(this, callbacks, emitter, {
3524
+ collectorContainer: params.collectorContainer,
3525
+ collectorStyles: params.collectorStyles,
3526
+ prefersColorScheme: params.prefersColorScheme
3527
+ });
3528
+ this.boxManager = boxManager;
3529
+ (_a = this.appManager) == null ? void 0 : _a.setBoxManager(boxManager);
3530
+ this.bindMainView(mainViewElement, params.disableCameraTransform);
3531
+ if (_WindowManager.wrapper) {
3532
+ (_b = this.cursorManager) == null ? void 0 : _b.setupWrapper(_WindowManager.wrapper);
3533
+ }
3534
+ }
3535
+ }
3536
+ (_c = this.boxManager) == null ? void 0 : _c.updateManagerRect();
3537
+ (_d = this.appManager) == null ? void 0 : _d.refresh();
3538
+ (_e = this.appManager) == null ? void 0 : _e.resetMaximized();
3539
+ (_f = this.appManager) == null ? void 0 : _f.resetMinimized();
3540
+ _WindowManager.container = container;
3541
+ }
3542
+ bindCollectorContainer(container) {
3543
+ if (_WindowManager.isCreated && this.boxManager) {
3544
+ this.boxManager.setCollectorContainer(container);
3545
+ } else {
3546
+ if (_WindowManager.params) {
3547
+ _WindowManager.params.collectorContainer = container;
3548
+ }
3549
+ }
3550
+ }
3551
+ static register(params) {
3552
+ return appRegister.register(params);
3553
+ }
3554
+ async addApp(params) {
3555
+ var _a, _b, _c;
3556
+ if (this.appManager) {
3557
+ if (!params.kind || typeof params.kind !== "string") {
3558
+ throw new ParamsInvalidError();
3559
+ }
3560
+ const appImpl = await ((_a = appRegister.appClasses.get(params.kind)) == null ? void 0 : _a());
3561
+ if (appImpl && ((_b = appImpl.config) == null ? void 0 : _b.singleton)) {
3562
+ if (this.appManager.appProxies.has(params.kind)) {
3563
+ throw new AppCreateError();
3564
+ }
3565
+ }
3566
+ const isDynamicPPT = this.setupScenePath(params, this.appManager);
3567
+ if (isDynamicPPT === void 0) {
3568
+ return;
3569
+ }
3570
+ if ((_c = params == null ? void 0 : params.options) == null ? void 0 : _c.scenePath) {
3571
+ params.options.scenePath = ensureValidScenePath(params.options.scenePath);
3572
+ }
3573
+ const appId = await this.appManager.addApp(params, Boolean(isDynamicPPT));
3574
+ return appId;
3575
+ } else {
3576
+ throw new AppManagerNotInitError();
3577
+ }
3578
+ }
3579
+ setupScenePath(params, appManager) {
3580
+ var _a, _b, _c;
3581
+ let isDynamicPPT = false;
3582
+ if (params.options) {
3583
+ const { scenePath, scenes } = params.options;
3584
+ if (scenePath) {
3585
+ if (!isValidScenePath(scenePath)) {
3586
+ throw new InvalidScenePath();
3587
+ }
3588
+ const apps = Object.keys(this.apps || {});
3589
+ for (const appId of apps) {
3590
+ const appScenePath = appManager.store.getAppScenePath(appId);
3591
+ if (appScenePath && appScenePath === scenePath) {
3592
+ console.warn(`[WindowManager]: ScenePath ${scenePath} Already opened`);
3593
+ if (this.boxManager) {
3594
+ const topBox = this.boxManager.getTopBox();
3595
+ if (topBox) {
3596
+ this.boxManager.setZIndex(appId, topBox.zIndex + 1, false);
3597
+ }
3598
+ }
3599
+ return;
3600
+ }
3601
+ }
3602
+ }
3603
+ if (scenePath && scenes && scenes.length > 0) {
3604
+ if (this.isDynamicPPT(scenes)) {
3605
+ isDynamicPPT = true;
3606
+ if (!this.displayer.entireScenes()[scenePath]) {
3607
+ (_a = this.room) == null ? void 0 : _a.putScenes(scenePath, scenes);
3608
+ }
3609
+ } else {
3610
+ if (!this.displayer.entireScenes()[scenePath]) {
3611
+ (_b = this.room) == null ? void 0 : _b.putScenes(scenePath, [{ name: scenes[0].name }]);
3612
+ }
3613
+ }
3614
+ }
3615
+ if (scenePath && scenes === void 0) {
3616
+ (_c = this.room) == null ? void 0 : _c.putScenes(scenePath, [{}]);
3617
+ }
3618
+ }
3619
+ return isDynamicPPT;
3620
+ }
3621
+ async setMainViewScenePath(scenePath) {
3622
+ if (this.appManager) {
3623
+ await this.appManager.setMainViewScenePath(scenePath);
3624
+ }
3625
+ }
3626
+ async setMainViewSceneIndex(index) {
3627
+ if (this.appManager) {
3628
+ await this.appManager.setMainViewSceneIndex(index);
3629
+ }
3630
+ }
3631
+ getMainViewScenePath() {
3632
+ var _a;
3633
+ return (_a = this.appManager) == null ? void 0 : _a.store.getMainViewScenePath();
3634
+ }
3635
+ getMainViewSceneIndex() {
3636
+ var _a;
3637
+ return (_a = this.appManager) == null ? void 0 : _a.store.getMainViewSceneIndex();
3638
+ }
3639
+ setReadonly(readonly) {
3640
+ var _a;
3641
+ this.readonly = readonly;
3642
+ (_a = this.boxManager) == null ? void 0 : _a.setReadonly(readonly);
3643
+ }
3644
+ switchMainViewToWriter() {
3645
+ var _a;
3646
+ return (_a = this.appManager) == null ? void 0 : _a.mainViewProxy.mainViewClickHandler();
3647
+ }
3648
+ onAppDestroy(kind, listener) {
3649
+ addEmitterOnceListener(`destroy-${kind}`, listener);
3650
+ }
3651
+ setViewMode(mode) {
3652
+ var _a, _b, _c;
3653
+ if (!this.canOperate)
3654
+ return;
3655
+ if (mode === ViewMode.Broadcaster) {
3656
+ (_a = this.appManager) == null ? void 0 : _a.mainViewProxy.setCameraAndSize();
3657
+ (_b = this.appManager) == null ? void 0 : _b.mainViewProxy.start();
3658
+ }
3659
+ if (mode === ViewMode.Freedom) {
3660
+ (_c = this.appManager) == null ? void 0 : _c.mainViewProxy.stop();
3661
+ }
3662
+ this.viewMode = mode;
3663
+ }
3664
+ get mainView() {
3665
+ if (this.appManager) {
3666
+ return this.appManager.mainViewProxy.view;
3667
+ } else {
3668
+ throw new AppManagerNotInitError();
3669
+ }
3670
+ }
3671
+ get camera() {
3672
+ if (this.appManager) {
3673
+ return this.appManager.mainViewProxy.view.camera;
3674
+ } else {
3675
+ throw new AppManagerNotInitError();
3676
+ }
3677
+ }
3678
+ get cameraState() {
3679
+ if (this.appManager) {
3680
+ return this.appManager.mainViewProxy.cameraState;
3681
+ } else {
3682
+ throw new AppManagerNotInitError();
3683
+ }
3684
+ }
3685
+ get apps() {
3686
+ var _a;
3687
+ return (_a = this.appManager) == null ? void 0 : _a.store.apps();
3688
+ }
3689
+ get boxState() {
3690
+ var _a;
3691
+ if (this.appManager) {
3692
+ return (_a = this.appManager.boxManager) == null ? void 0 : _a.boxState;
3693
+ } else {
3694
+ throw new AppManagerNotInitError();
3695
+ }
3696
+ }
3697
+ get darkMode() {
3698
+ var _a, _b;
3699
+ return Boolean((_b = (_a = this.appManager) == null ? void 0 : _a.boxManager) == null ? void 0 : _b.darkMode);
3700
+ }
3701
+ get prefersColorScheme() {
3702
+ var _a;
3703
+ if (this.appManager) {
3704
+ return (_a = this.appManager.boxManager) == null ? void 0 : _a.prefersColorScheme;
3705
+ } else {
3706
+ throw new AppManagerNotInitError();
3707
+ }
3708
+ }
3709
+ get focused() {
3710
+ return this.attributes.focus;
3711
+ }
3712
+ get mainViewSceneIndex() {
3713
+ var _a;
3714
+ return (_a = this.appManager) == null ? void 0 : _a.store.getMainViewSceneIndex();
3715
+ }
3716
+ get mainViewSceneDir() {
3717
+ var _a;
3718
+ const scenePath = (_a = this.appManager) == null ? void 0 : _a.store.getMainViewScenePath();
3719
+ if (scenePath) {
3720
+ return parseSceneDir(scenePath);
3721
+ } else {
3722
+ throw new Error("[WindowManager]: mainViewSceneDir not found");
3723
+ }
3724
+ }
3725
+ queryAll() {
3726
+ var _a;
3727
+ return Array.from(((_a = this.appManager) == null ? void 0 : _a.appProxies.values()) || []);
3728
+ }
3729
+ queryOne(appId) {
3730
+ var _a;
3731
+ return (_a = this.appManager) == null ? void 0 : _a.appProxies.get(appId);
3732
+ }
3733
+ async closeApp(appId) {
3734
+ var _a;
3735
+ return (_a = this.appManager) == null ? void 0 : _a.closeApp(appId);
3736
+ }
3737
+ moveCamera(camera) {
3738
+ this.mainView.moveCamera(camera);
3739
+ }
3740
+ moveCameraToContain(rectangle) {
3741
+ var _a;
3742
+ this.mainView.moveCameraToContain(rectangle);
3743
+ (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
3744
+ setTimeout(() => {
3745
+ var _a2;
3746
+ (_a2 = this.appManager) == null ? void 0 : _a2.mainViewProxy.setCameraAndSize();
3747
+ }, 1e3);
3748
+ }
3749
+ convertToPointInWorld(point) {
3750
+ return this.mainView.convertToPointInWorld(point);
3751
+ }
3752
+ setCameraBound(cameraBound) {
3753
+ this.mainView.setCameraBound(cameraBound);
3754
+ }
3755
+ onDestroy() {
3756
+ this._destroy();
3757
+ }
3758
+ destroy() {
3759
+ this._destroy();
3760
+ }
3761
+ _destroy() {
3762
+ var _a, _b, _c, _d;
3763
+ (_a = this.containerResizeObserver) == null ? void 0 : _a.disconnect();
3764
+ (_b = this.appManager) == null ? void 0 : _b.destroy();
3765
+ (_c = this.cursorManager) == null ? void 0 : _c.destroy();
3766
+ _WindowManager.container = void 0;
3767
+ _WindowManager.wrapper = void 0;
3768
+ _WindowManager.isCreated = false;
3769
+ if (_WindowManager.playground) {
3770
+ (_d = _WindowManager.playground.parentNode) == null ? void 0 : _d.removeChild(_WindowManager.playground);
3771
+ }
3772
+ _WindowManager.params = void 0;
3773
+ log("Destroyed");
3774
+ }
3775
+ bindMainView(divElement, disableCameraTransform) {
3776
+ var _a;
3777
+ if (this.appManager) {
3778
+ this.appManager.bindMainView(divElement, Boolean(disableCameraTransform));
3779
+ (_a = this.cursorManager) == null ? void 0 : _a.setMainViewDivElement(divElement);
3780
+ }
3781
+ }
3782
+ get canOperate() {
3783
+ if (isRoom(this.displayer)) {
3784
+ return this.displayer.isWritable && this.displayer.phase === RoomPhase.Connected;
3785
+ } else {
3786
+ return false;
3787
+ }
3788
+ }
3789
+ get room() {
3790
+ return this.displayer;
3791
+ }
3792
+ safeSetAttributes(attributes) {
3793
+ if (this.canOperate) {
3794
+ this.setAttributes(attributes);
3795
+ }
3796
+ }
3797
+ safeUpdateAttributes(keys, value) {
3798
+ if (this.canOperate) {
3799
+ this.updateAttributes(keys, value);
3800
+ }
3801
+ }
3802
+ setPrefersColorScheme(scheme) {
3803
+ var _a, _b;
3804
+ (_b = (_a = this.appManager) == null ? void 0 : _a.boxManager) == null ? void 0 : _b.setPrefersColorScheme(scheme);
3805
+ }
3806
+ isDynamicPPT(scenes) {
3807
+ var _a, _b;
3808
+ const sceneSrc = (_b = (_a = scenes[0]) == null ? void 0 : _a.ppt) == null ? void 0 : _b.src;
3809
+ return sceneSrc == null ? void 0 : sceneSrc.startsWith("pptx://");
3810
+ }
3811
+ static checkVersion() {
3812
+ const version = getVersionNumber(WhiteVersion);
3813
+ if (version < getVersionNumber(REQUIRE_VERSION)) {
3814
+ throw new WhiteWebSDKInvalidError(REQUIRE_VERSION);
3815
+ }
3816
+ }
3817
+ async ensureAttributes() {
3818
+ if (isNull(this.attributes)) {
3819
+ await wait(50);
3820
+ }
3821
+ if (isObject(this.attributes)) {
3822
+ if (!this.attributes[Fields.Apps]) {
3823
+ this.safeSetAttributes({ [Fields.Apps]: {} });
3824
+ }
3825
+ if (!this.attributes[Fields.Cursors]) {
3826
+ this.safeSetAttributes({ [Fields.Cursors]: {} });
3827
+ }
3828
+ const sceneState = this.displayer.state.sceneState;
3829
+ if (!this.attributes["_mainScenePath"]) {
3830
+ this.safeSetAttributes({ _mainScenePath: sceneState.scenePath });
3831
+ }
3832
+ if (!this.attributes["_mainSceneIndex"]) {
3833
+ this.safeSetAttributes({ _mainSceneIndex: sceneState.index });
3834
+ }
3835
+ }
3836
+ }
3837
+ };
3838
+ let WindowManager = _WindowManager;
3839
+ WindowManager.kind = "WindowManager";
3840
+ WindowManager.debug = false;
3841
+ WindowManager.containerSizeRatio = DEFAULT_CONTAINER_RATIO;
3842
+ WindowManager.isCreated = false;
3843
+ setupBuiltin();
3844
+ export { BuiltinApps, WindowManager, callbacks, emitter, reconnectRefresher };
2
3845
  //# sourceMappingURL=index.es.js.map