@netless/app-embedded-page-sdk
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -50,9 +50,7 @@ import type { CameraState, DefaultState, Diff, DiffOne, FromSDKMessage, FromSDKMessageKey, InitData, MetaData, RoomMember, ToSDKMessage, ToSDKMessageKey } from "@netless/app-embedded-page"; | ||
private _stores; | ||
connectStore<S>(id: string, ensureState: S): Store<S>; | ||
hasStore(id: string): boolean; | ||
connectStore<S>(storeId: string, ensureState?: S): Store<S>; | ||
isStoreConnected(id: string): boolean; | ||
removeStore(id: string): void; | ||
private _handleMsgStoreChanged; | ||
private storeNSPrefix; | ||
private mainStoreId; | ||
getStoreNamespace(id: string): string; | ||
get state(): TState; | ||
@@ -59,0 +57,0 @@ private _mainStore; |
@@ -1,2 +0,2 @@ | ||
"use strict";var H=Object.defineProperty;var K=(u,e,s)=>e in u?H(u,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):u[e]=s;var A=(u,e,s)=>(K(u,typeof e!="symbol"?e+"":e,s),s);Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";class X{constructor(){this.disposers=new Map,this.disposerIDGenCount=-1}add(e,s=this.genDisposerID()){return this.flush(s),this.disposers.set(s,e()),s}addEventListener(e,s,r,o,l=this.genDisposerID()){return this.add(()=>(e.addEventListener(s,r,o),()=>e.removeEventListener(s,r,o)),l),l}setTimeout(e,s,r=this.genDisposerID()){return this.add(()=>{const o=window.setTimeout(()=>{this.remove(r),e()},s);return()=>window.clearTimeout(o)},r)}setInterval(e,s,r=this.genDisposerID()){return this.add(()=>{const o=window.setInterval(e,s);return()=>window.clearInterval(o)},r)}remove(e){const s=this.disposers.get(e);return this.disposers.delete(e),s}flush(e){const s=this.remove(e);if(s)try{s()}catch(r){console.error(r)}}flushAll(){this.disposers.forEach(e=>{try{e()}catch(s){console.error(s)}}),this.disposers.clear()}genDisposerID(){const{MAX_SAFE_INTEGER:e=9007199254740991}=Number;return this.disposerIDGenCount=(this.disposerIDGenCount+1)%e,`disposer-${this.disposerIDGenCount}`}}var q=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},P={exports:{}};(function(u,e){(function(s,r){{var o=r();u&&u.exports&&(e=u.exports=o),e.randomColor=o}})(q,function(){var s=null,r={};O();var o=[],l=function(t){if(t=t||{},t.seed!==void 0&&t.seed!==null&&t.seed===parseInt(t.seed,10))s=t.seed;else if(typeof t.seed=="string")s=F(t.seed);else{if(t.seed!==void 0&&t.seed!==null)throw new TypeError("The seed value must be an integer or string");s=null}var n,a,i;if(t.count!==null&&t.count!==void 0){for(var h=t.count,g=[],c=0;c<t.count;c++)o.push(!1);for(t.count=null;h>g.length;){var w=l(t);s!==null&&(t.seed=s),g.push(w)}return t.count=h,g}return n=d(t),a=f(n,t),i=_(n,a,t),m([n,a,i],t)};function d(t){if(o.length>0){var n=j(t.hue),a=R(n),i=(n[1]-n[0])/o.length,h=parseInt((a-n[0])/i);o[h]===!0?h=(h+2)%o.length:o[h]=!0;var g=(n[0]+h*i)%359,c=(n[0]+(h+1)*i)%359;return n=[g,c],a=R(n),a<0&&(a=360+a),a}else{var n=L(t.hue);return a=R(n),a<0&&(a=360+a),a}}function f(t,n){if(n.hue==="monochrome")return 0;if(n.luminosity==="random")return R([0,100]);var a=W(t),i=a[0],h=a[1];switch(n.luminosity){case"bright":i=55;break;case"dark":i=h-10;break;case"light":h=55;break}return R([i,h])}function _(t,n,a){var i=x(t,n),h=100;switch(a.luminosity){case"dark":h=i+20;break;case"light":i=(h+i)/2;break;case"random":i=0,h=100;break}return R([i,h])}function m(t,n){switch(n.format){case"hsvArray":return t;case"hslArray":return V(t);case"hsl":var a=V(t);return"hsl("+a[0]+", "+a[1]+"%, "+a[2]+"%)";case"hsla":var i=V(t),h=n.alpha||Math.random();return"hsla("+i[0]+", "+i[1]+"%, "+i[2]+"%, "+h+")";case"rgbArray":return y(t);case"rgb":var g=y(t);return"rgb("+g.join(", ")+")";case"rgba":var c=y(t),h=n.alpha||Math.random();return"rgba("+c.join(", ")+", "+h+")";default:return G(t)}}function x(t,n){for(var a=D(t).lowerBounds,i=0;i<a.length-1;i++){var h=a[i][0],g=a[i][1],c=a[i+1][0],w=a[i+1][1];if(n>=h&&n<=c){var C=(w-g)/(c-h),p=g-C*h;return C*n+p}}return 0}function L(t){if(typeof parseInt(t)=="number"){var n=parseInt(t);if(n<360&&n>0)return[n,n]}if(typeof t=="string"){if(r[t]){var a=r[t];if(a.hueRange)return a.hueRange}else if(t.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)){var i=T(t)[0];return[i,i]}}return[0,360]}function W(t){return D(t).saturationRange}function D(t){t>=334&&t<=360&&(t-=360);for(var n in r){var a=r[n];if(a.hueRange&&t>=a.hueRange[0]&&t<=a.hueRange[1])return r[n]}return"Color not found"}function R(t){if(s===null){var n=.618033988749895,a=Math.random();return a+=n,a%=1,Math.floor(t[0]+a*(t[1]+1-t[0]))}else{var i=t[1]||1,h=t[0]||0;s=(s*9301+49297)%233280;var g=s/233280;return Math.floor(h+g*(i-h))}}function G(t){var n=y(t);function a(h){var g=h.toString(16);return g.length==1?"0"+g:g}var i="#"+a(n[0])+a(n[1])+a(n[2]);return i}function v(t,n,a){var i=a[0][0],h=a[a.length-1][0],g=a[a.length-1][1],c=a[0][1];r[t]={hueRange:n,lowerBounds:a,saturationRange:[i,h],brightnessRange:[g,c]}}function O(){v("monochrome",null,[[0,0],[100,0]]),v("red",[-26,18],[[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]),v("orange",[18,46],[[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]),v("yellow",[46,62],[[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]),v("green",[62,178],[[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]),v("blue",[178,257],[[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]),v("purple",[257,282],[[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]),v("pink",[282,334],[[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]])}function y(t){var n=t[0];n===0&&(n=1),n===360&&(n=359),n=n/360;var a=t[1]/100,i=t[2]/100,h=Math.floor(n*6),g=n*6-h,c=i*(1-a),w=i*(1-g*a),C=i*(1-(1-g)*a),p=256,M=256,S=256;switch(h){case 0:p=i,M=C,S=c;break;case 1:p=w,M=i,S=c;break;case 2:p=c,M=i,S=C;break;case 3:p=c,M=w,S=i;break;case 4:p=C,M=c,S=i;break;case 5:p=i,M=c,S=w;break}var B=[Math.floor(p*255),Math.floor(M*255),Math.floor(S*255)];return B}function T(t){t=t.replace(/^#/,""),t=t.length===3?t.replace(/(.)/g,"$1$1"):t;var n=parseInt(t.substr(0,2),16)/255,a=parseInt(t.substr(2,2),16)/255,i=parseInt(t.substr(4,2),16)/255,h=Math.max(n,a,i),g=h-Math.min(n,a,i),c=h?g/h:0;switch(h){case n:return[60*((a-i)/g%6)||0,c,h];case a:return[60*((i-n)/g+2)||0,c,h];case i:return[60*((n-a)/g+4)||0,c,h]}}function V(t){var n=t[0],a=t[1]/100,i=t[2]/100,h=(2-a)*i;return[n,Math.round(a*i/(h<1?h:2-h)*1e4)/100,h/2*100]}function F(t){for(var n=0,a=0;a!==t.length&&!(n>=Number.MAX_SAFE_INTEGER);a++)n+=t.charCodeAt(a);return n}function j(t){if(isNaN(t)){if(typeof t=="string"){if(r[t]){var a=r[t];if(a.hueRange)return a.hueRange}else if(t.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)){var i=T(t)[0];return D(i).hueRange}}}else{var n=parseInt(t);if(n<360&&n>0)return D(t).hueRange}return[0,360]}return l})})(P,P.exports);var z=P.exports;class J{constructor(e="NetlessApp",s="error"){A(this,"kind");A(this,"debug");A(this,"color",z({luminosity:"dark"}));this.kind=e,this.debug=s}log(...e){if(this.debug===!0||this.debug==="log")return this._log("log",e)}warn(...e){if(this.debug&&this.debug!=="error")return this._log("warn",e)}error(...e){if(this.debug)return this._log("error",e)}_log(e,s){console[e](`%c[${this.kind}]:`,`color: ${this.color}; font-weight: bold;`,...s)}}class E{constructor(){this.listeners=new Set}get length(){return this.listeners.size}dispatch(e){this.listeners.forEach(s=>s(e))}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}}const k=(u,e)=>Object.prototype.hasOwnProperty.call(u,e),N=Object.keys;function b(u){return typeof u=="object"&&u!==null}const Q=b;function $(u){return Boolean(b(u)&&u.__isRef)}function U(u){return{k:Y(),v:u,__isRef:!0}}function Y(){return Date.now().toString().slice(6)+Math.random().toString().slice(2,8)}class Z{constructor({id:e,state:s,onSetState:r,getIsWritable:o,logger:l=console}){this.onStateChanged=new E,this._destroyed=!1,this.onDestroyed=new E,this._kMap=new WeakMap,this._lastValue=new Map,this.id=e,this._onSetState=r,this.getIsWritable=o,this._logger=l,this._state={},s&&N(s).forEach(d=>{const f=s[d];if($(f)){const{k:_,v:m}=f;this._state[d]=m,b(m)&&this._kMap.set(m,_)}else this._state[d]=f})}get state(){return this._state}ensureState(e){return this.setState(N(e).reduce((s,r)=>(k(this._state,r)||(s[r]=e[r]),s),{}))}setState(e){if(this._destroyed){this._logger.error(`Cannot call setState on Store ${this.id} which is destroyed.`);return}if(!this.getIsWritable()){this._logger.error(`Cannot setState on store ${this.id} without writable access`,e);return}const s=N(e);if(s.length>0){const r={};s.forEach(o=>{const l=e[o];if(l===void 0)this._lastValue.set(o,this._state[o]),delete this._state[o],r[o]=l;else if(l!==this._state[o])if(this._lastValue.set(o,this._state[o]),this._state[o]=l,b(l)){const d=U(l);this._kMap.set(d.v,d.k),r[o]=d}else r[o]=l}),Object.keys(r).length>0&&this._onSetState(r)}}get destroyed(){return this._destroyed}_destroy(){this._destroyed=!0,this.onDestroyed.dispatch()}_updateProperties(e){if(this._destroyed){this._logger.error(`Cannot call _updateProperties on Store ${this.id} which is destroyed.`);return}if(e.length>0){const s={};e.forEach(({key:r,value:o,kind:l})=>{switch(l){case 2:{k(this._state,r)&&(this._lastValue.set(r,this._state[r]),delete this._state[r]),s[r]={oldValue:this._lastValue.get(r)};break}default:{let d=o;if($(o)){const{k:f,v:_}=o,m=this._state[r];b(m)&&this._kMap.get(m)===f?d=m:(d=_,b(_)&&this._kMap.set(_,f))}d!==this._state[r]&&(this._lastValue.set(r,this._state[r]),this._state[r]=d),s[r]={newValue:d,oldValue:this._lastValue.get(r)};break}}}),this.onStateChanged.dispatch(s)}}}class ee{constructor(e,s,r,o,l){this.onRoomMembersChanged=new E,this.onMessage=new E,this.onWritableChanged=new E,this.onPageChanged=new E,this._stores=new Map,this.sideEffect=new X,this.postMessage=r,this.storeNSPrefix=e.storeConfig.nsPrefix,this.mainStoreId=e.storeConfig.mainId,this._storeRawData=e.store||{[this.getStoreNamespace(this.mainStoreId)]:{}},this._writable=e.writable,this._page=e.page,this._meta=e.meta,this._roomMembers=e.roomMembers,this.logger=l,this.sideEffect.add(()=>o(d=>{const{type:f,payload:_}=d;if(f){const m=`_handleMsg${f}`;this[m]&&this[m](_)}})),this._mainStore=this.connectStore(e.storeConfig.mainId,s),this.onStateChanged=this._mainStore.onStateChanged}get meta(){return this._meta}get roomMembers(){return this._roomMembers}_handleMsgRoomMembersChanged(e){if(e==null||Array.isArray(e)){const s=this._roomMembers;this._roomMembers=e,this.onRoomMembersChanged.dispatch({newValue:this._roomMembers,oldValue:s})}}moveCamera(e){this.postMessage({type:"MoveCamera",payload:e})}sendMessage(e){this.postMessage({type:"SendMagixMessage",payload:e})}_handleMsgReceiveMagixMessage(e){this.onMessage.dispatch(e)}get isWritable(){return this._writable}_handleMsgWritableChanged(e){const s=Boolean(e),r=this._writable;s!==r&&(this._writable=s,this.onWritableChanged.dispatch({oldValue:r,newValue:s}))}get page(){return this._page}setPage(e){this._page=e,this.postMessage({type:"SetPage",payload:e})}_handleMsgPageChanged(e){Q(e)&&(this._page=e.newValue,this.onPageChanged.dispatch(e))}connectStore(e,s){const r=this.getStoreNamespace(e);let o=this._stores.get(r);if(!o){if(!k(this._storeRawData,r)){const l={};this.postMessage({type:"SetStore",payload:{[r]:l}}),this._storeRawData[r]=l}o=new Z({id:e,state:this._storeRawData[r],logger:this.logger,getIsWritable:()=>this._writable,onSetState:l=>this.postMessage({type:"SetState",payload:{namespace:r,state:l}})}),this._stores.set(r,o)}return s&&o.ensureState(s),o}hasStore(e){return this._stores.has(this.getStoreNamespace(e))}removeStore(e){if(e===this.mainStoreId){this.logger.error(`Store "${e}" is not removable.`);return}const s=this.getStoreNamespace(e),r=this._stores.get(s);r&&(this._stores.delete(s),r._destroy()),this._storeRawData[s]&&this.postMessage({type:"SetStore",payload:{[s]:void 0}})}_handleMsgStoreChanged(e){Array.isArray(e)&&e.length>0&&e.forEach(({key:r,value:o,kind:l})=>{switch(l){case 2:{delete this._storeRawData[r];const d=this._stores.get(r);d&&(this._stores.delete(r),d._destroy());break}default:{this._storeRawData[r]=o;break}}})}getStoreNamespace(e){return this.storeNSPrefix+e}get state(){return this._mainStore.state}ensureState(e){return this._mainStore.ensureState(e)}setState(e){return this._mainStore.setState(e)}_handleMsgStateChanged(e){if(b(e)&&e.namespace&&Array.isArray(e.actions)&&e.actions.length>0){const{namespace:s,actions:r}=e;r.forEach(({key:l,value:d,kind:f})=>{switch(f){case 2:{const _=this._storeRawData[s];b(_)&&delete _[l];break}default:{const _=this._storeRawData[s];b(_)&&(_[l]=d);break}}});const o=this._stores.get(s);o&&o._updateProperties(r)}}destroy(){this.sideEffect.flushAll()}}let I;function te(u={}){if(!parent)throw new Error("[EmbeddedPageSDK]: SDK is not running in a iframe.");if(I)return Promise.resolve(I);const e=new J("EmbeddedPageSDK",u.debug),s=o=>{e.log("Message to parent",o),parent.postMessage(o,"*")},r=(o,l)=>{const d=({data:f,source:_})=>{if(!(!parent||_!==parent)){if(!b(f)){console.warn("window message data should be object, instead got",f);return}e.log("Message from parent",f),o(f)}};return window.addEventListener("message",d,l),()=>{window.removeEventListener("message",d,l)}};return s({type:"Init"}),new Promise(o=>{const l=r(d=>{if(I){l(),o(I);return}if(d.type==="Init"){l();const f=new ee(d.payload,u.ensureState||{},s,r,e);I=f,o(f)}})})}exports.createEmbeddedApp=te; | ||
"use strict";var H=Object.defineProperty;var K=(u,e,r)=>e in u?H(u,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):u[e]=r;var I=(u,e,r)=>(K(u,typeof e!="symbol"?e+"":e,r),r);Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";class X{constructor(){this.disposers=new Map,this.disposerIDGenCount=-1}add(e,r=this.genDisposerID()){return this.flush(r),this.disposers.set(r,e()),r}addEventListener(e,r,n,o,l=this.genDisposerID()){return this.add(()=>(e.addEventListener(r,n,o),()=>e.removeEventListener(r,n,o)),l),l}setTimeout(e,r,n=this.genDisposerID()){return this.add(()=>{const o=window.setTimeout(()=>{this.remove(n),e()},r);return()=>window.clearTimeout(o)},n)}setInterval(e,r,n=this.genDisposerID()){return this.add(()=>{const o=window.setInterval(e,r);return()=>window.clearInterval(o)},n)}remove(e){const r=this.disposers.get(e);return this.disposers.delete(e),r}flush(e){const r=this.remove(e);if(r)try{r()}catch(n){console.error(n)}}flushAll(){this.disposers.forEach(e=>{try{e()}catch(r){console.error(r)}}),this.disposers.clear()}genDisposerID(){const{MAX_SAFE_INTEGER:e=9007199254740991}=Number;return this.disposerIDGenCount=(this.disposerIDGenCount+1)%e,`disposer-${this.disposerIDGenCount}`}}var q=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},P={exports:{}};(function(u,e){(function(r,n){{var o=n();u&&u.exports&&(e=u.exports=o),e.randomColor=o}})(q,function(){var r=null,n={};F();var o=[],l=function(t){if(t=t||{},t.seed!==void 0&&t.seed!==null&&t.seed===parseInt(t.seed,10))r=t.seed;else if(typeof t.seed=="string")r=j(t.seed);else{if(t.seed!==void 0&&t.seed!==null)throw new TypeError("The seed value must be an integer or string");r=null}var a,s,i;if(t.count!==null&&t.count!==void 0){for(var h=t.count,g=[],c=0;c<t.count;c++)o.push(!1);for(t.count=null;h>g.length;){var w=l(t);r!==null&&(t.seed=r),g.push(w)}return t.count=h,g}return a=d(t),s=f(a,t),i=_(a,s,t),b([a,s,i],t)};function d(t){if(o.length>0){var a=N(t.hue),s=R(a),i=(a[1]-a[0])/o.length,h=parseInt((s-a[0])/i);o[h]===!0?h=(h+2)%o.length:o[h]=!0;var g=(a[0]+h*i)%359,c=(a[0]+(h+1)*i)%359;return a=[g,c],s=R(a),s<0&&(s=360+s),s}else{var a=W(t.hue);return s=R(a),s<0&&(s=360+s),s}}function f(t,a){if(a.hue==="monochrome")return 0;if(a.luminosity==="random")return R([0,100]);var s=G(t),i=s[0],h=s[1];switch(a.luminosity){case"bright":i=55;break;case"dark":i=h-10;break;case"light":h=55;break}return R([i,h])}function _(t,a,s){var i=x(t,a),h=100;switch(s.luminosity){case"dark":h=i+20;break;case"light":i=(h+i)/2;break;case"random":i=0,h=100;break}return R([i,h])}function b(t,a){switch(a.format){case"hsvArray":return t;case"hslArray":return V(t);case"hsl":var s=V(t);return"hsl("+s[0]+", "+s[1]+"%, "+s[2]+"%)";case"hsla":var i=V(t),h=a.alpha||Math.random();return"hsla("+i[0]+", "+i[1]+"%, "+i[2]+"%, "+h+")";case"rgbArray":return A(t);case"rgb":var g=A(t);return"rgb("+g.join(", ")+")";case"rgba":var c=A(t),h=a.alpha||Math.random();return"rgba("+c.join(", ")+", "+h+")";default:return O(t)}}function x(t,a){for(var s=y(t).lowerBounds,i=0;i<s.length-1;i++){var h=s[i][0],g=s[i][1],c=s[i+1][0],w=s[i+1][1];if(a>=h&&a<=c){var C=(w-g)/(c-h),p=g-C*h;return C*a+p}}return 0}function W(t){if(typeof parseInt(t)=="number"){var a=parseInt(t);if(a<360&&a>0)return[a,a]}if(typeof t=="string"){if(n[t]){var s=n[t];if(s.hueRange)return s.hueRange}else if(t.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)){var i=$(t)[0];return[i,i]}}return[0,360]}function G(t){return y(t).saturationRange}function y(t){t>=334&&t<=360&&(t-=360);for(var a in n){var s=n[a];if(s.hueRange&&t>=s.hueRange[0]&&t<=s.hueRange[1])return n[a]}return"Color not found"}function R(t){if(r===null){var a=.618033988749895,s=Math.random();return s+=a,s%=1,Math.floor(t[0]+s*(t[1]+1-t[0]))}else{var i=t[1]||1,h=t[0]||0;r=(r*9301+49297)%233280;var g=r/233280;return Math.floor(h+g*(i-h))}}function O(t){var a=A(t);function s(h){var g=h.toString(16);return g.length==1?"0"+g:g}var i="#"+s(a[0])+s(a[1])+s(a[2]);return i}function v(t,a,s){var i=s[0][0],h=s[s.length-1][0],g=s[s.length-1][1],c=s[0][1];n[t]={hueRange:a,lowerBounds:s,saturationRange:[i,h],brightnessRange:[g,c]}}function F(){v("monochrome",null,[[0,0],[100,0]]),v("red",[-26,18],[[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]),v("orange",[18,46],[[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]),v("yellow",[46,62],[[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]),v("green",[62,178],[[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]),v("blue",[178,257],[[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]),v("purple",[257,282],[[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]),v("pink",[282,334],[[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]])}function A(t){var a=t[0];a===0&&(a=1),a===360&&(a=359),a=a/360;var s=t[1]/100,i=t[2]/100,h=Math.floor(a*6),g=a*6-h,c=i*(1-s),w=i*(1-g*s),C=i*(1-(1-g)*s),p=256,M=256,S=256;switch(h){case 0:p=i,M=C,S=c;break;case 1:p=w,M=i,S=c;break;case 2:p=c,M=i,S=C;break;case 3:p=c,M=w,S=i;break;case 4:p=C,M=c,S=i;break;case 5:p=i,M=c,S=w;break}var B=[Math.floor(p*255),Math.floor(M*255),Math.floor(S*255)];return B}function $(t){t=t.replace(/^#/,""),t=t.length===3?t.replace(/(.)/g,"$1$1"):t;var a=parseInt(t.substr(0,2),16)/255,s=parseInt(t.substr(2,2),16)/255,i=parseInt(t.substr(4,2),16)/255,h=Math.max(a,s,i),g=h-Math.min(a,s,i),c=h?g/h:0;switch(h){case a:return[60*((s-i)/g%6)||0,c,h];case s:return[60*((i-a)/g+2)||0,c,h];case i:return[60*((a-s)/g+4)||0,c,h]}}function V(t){var a=t[0],s=t[1]/100,i=t[2]/100,h=(2-s)*i;return[a,Math.round(s*i/(h<1?h:2-h)*1e4)/100,h/2*100]}function j(t){for(var a=0,s=0;s!==t.length&&!(a>=Number.MAX_SAFE_INTEGER);s++)a+=t.charCodeAt(s);return a}function N(t){if(isNaN(t)){if(typeof t=="string"){if(n[t]){var s=n[t];if(s.hueRange)return s.hueRange}else if(t.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)){var i=$(t)[0];return y(i).hueRange}}}else{var a=parseInt(t);if(a<360&&a>0)return y(t).hueRange}return[0,360]}return l})})(P,P.exports);var z=P.exports;class J{constructor(e="NetlessApp",r="error"){I(this,"kind");I(this,"debug");I(this,"color",z({luminosity:"dark"}));this.kind=e,this.debug=r}log(...e){if(this.debug===!0||this.debug==="log")return this._log("log",e)}warn(...e){if(this.debug&&this.debug!=="error")return this._log("warn",e)}error(...e){if(this.debug)return this._log("error",e)}_log(e,r){console[e](`%c[${this.kind}]:`,`color: ${this.color}; font-weight: bold;`,...r)}}class E{constructor(){this.listeners=new Set}get length(){return this.listeners.size}dispatch(e){this.listeners.forEach(r=>r(e))}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}}const k=(u,e)=>Object.prototype.hasOwnProperty.call(u,e),T=Object.keys;function m(u){return typeof u=="object"&&u!==null}const Q=m;function L(u){return Boolean(m(u)&&u.__isRef)}function U(u){return{k:Y(),v:u,__isRef:!0}}function Y(){return Date.now().toString().slice(6)+Math.random().toString().slice(2,8)}class Z{constructor({id:e,state:r,onSetState:n,getIsWritable:o,logger:l=console}){this.onStateChanged=new E,this._destroyed=!1,this.onDestroyed=new E,this._kMap=new WeakMap,this._lastValue=new Map,this.id=e,this._onSetState=n,this.getIsWritable=o,this._logger=l,this._state={},r&&T(r).forEach(d=>{const f=r[d];if(L(f)){const{k:_,v:b}=f;this._state[d]=b,m(b)&&this._kMap.set(b,_)}else this._state[d]=f})}get state(){return this._state}ensureState(e){return this.setState(T(e).reduce((r,n)=>(k(this._state,n)||(r[n]=e[n]),r),{}))}setState(e){if(this._destroyed){this._logger.error(`Cannot call setState on Store ${this.id} which is destroyed.`);return}if(!this.getIsWritable()){this._logger.error(`Cannot setState on store ${this.id} without writable access`,e);return}const r=T(e);if(r.length>0){const n={};r.forEach(o=>{const l=e[o];if(l===void 0)this._lastValue.set(o,this._state[o]),delete this._state[o],n[o]=l;else if(l!==this._state[o])if(this._lastValue.set(o,this._state[o]),this._state[o]=l,m(l)){const d=U(l);this._kMap.set(d.v,d.k),n[o]=d}else n[o]=l}),Object.keys(n).length>0&&this._onSetState(n)}}get destroyed(){return this._destroyed}_destroy(){this._destroyed=!0,this.onDestroyed.dispatch()}_updateProperties(e){if(this._destroyed){this._logger.error(`Cannot call _updateProperties on Store ${this.id} which is destroyed.`);return}if(e.length>0){const r={};e.forEach(({key:n,value:o,kind:l})=>{switch(l){case 2:{k(this._state,n)&&(this._lastValue.set(n,this._state[n]),delete this._state[n]),r[n]={oldValue:this._lastValue.get(n)};break}default:{let d=o;if(L(o)){const{k:f,v:_}=o,b=this._state[n];m(b)&&this._kMap.get(b)===f?d=b:(d=_,m(_)&&this._kMap.set(_,f))}d!==this._state[n]&&(this._lastValue.set(n,this._state[n]),this._state[n]=d),r[n]={newValue:d,oldValue:this._lastValue.get(n)};break}}}),this.onStateChanged.dispatch(r)}}}class ee{constructor(e,r,n,o,l){this.onRoomMembersChanged=new E,this.onMessage=new E,this.onWritableChanged=new E,this.onPageChanged=new E,this._stores=new Map,this.sideEffect=new X,this.postMessage=n,this.mainStoreId=e.mainStoreId,this._storeRawData=e.store||{[this.mainStoreId]:{}},this._writable=e.writable,this._page=e.page,this._meta=e.meta,this._roomMembers=e.roomMembers,this.logger=l,this.sideEffect.add(()=>o(d=>{const{type:f,payload:_}=d;if(f){const b=`_handleMsg${f}`;this[b]&&this[b](_)}})),this._mainStore=this.connectStore(e.mainStoreId,r),this.onStateChanged=this._mainStore.onStateChanged}get meta(){return this._meta}get roomMembers(){return this._roomMembers}_handleMsgRoomMembersChanged(e){if(e==null||Array.isArray(e)){const r=this._roomMembers;this._roomMembers=e,this.onRoomMembersChanged.dispatch({newValue:this._roomMembers,oldValue:r})}}moveCamera(e){this.postMessage({type:"MoveCamera",payload:e})}sendMessage(e){this.postMessage({type:"SendMagixMessage",payload:e})}_handleMsgReceiveMagixMessage(e){this.onMessage.dispatch(e)}get isWritable(){return this._writable}_handleMsgWritableChanged(e){const r=Boolean(e),n=this._writable;r!==n&&(this._writable=r,this.onWritableChanged.dispatch({oldValue:n,newValue:r}))}get page(){return this._page}setPage(e){this._page=e,this.postMessage({type:"SetPage",payload:e})}_handleMsgPageChanged(e){Q(e)&&(this._page=e.newValue,this.onPageChanged.dispatch(e))}connectStore(e,r){let n=this._stores.get(e);if(!n){if(!k(this._storeRawData,e)){const o={};this.postMessage({type:"SetStore",payload:{[e]:o}}),this._storeRawData[e]=o}n=new Z({id:e,state:this._storeRawData[e],logger:this.logger,getIsWritable:()=>this._writable,onSetState:o=>this.postMessage({type:"SetState",payload:{storeId:e,state:o}})}),this._stores.set(e,n)}return r&&n.ensureState(r),n}isStoreConnected(e){return this._stores.has(e)}removeStore(e){if(e===this.mainStoreId){this.logger.error(`Store "${e}" is not removable.`);return}const r=this._stores.get(e);r&&(this._stores.delete(e),r._destroy()),this._storeRawData[e]&&this.postMessage({type:"SetStore",payload:{[e]:void 0}})}_handleMsgStoreChanged(e){Array.isArray(e)&&e.length>0&&e.forEach(({key:n,value:o,kind:l})=>{switch(l){case 2:{delete this._storeRawData[n];const d=this._stores.get(n);d&&(this._stores.delete(n),d._destroy());break}default:{this._storeRawData[n]=o;break}}})}get state(){return this._mainStore.state}ensureState(e){return this._mainStore.ensureState(e)}setState(e){return this._mainStore.setState(e)}_handleMsgStateChanged(e){if(m(e)&&e.storeId&&Array.isArray(e.actions)&&e.actions.length>0){const{storeId:r,actions:n}=e;n.forEach(({key:l,value:d,kind:f})=>{switch(f){case 2:{const _=this._storeRawData[r];m(_)&&delete _[l];break}default:{const _=this._storeRawData[r];m(_)&&(_[l]=d);break}}});const o=this._stores.get(r);o&&o._updateProperties(n)}}destroy(){this.sideEffect.flushAll()}}let D;function te(u={}){if(!parent)throw new Error("[EmbeddedPageSDK]: SDK is not running in a iframe.");if(D)return Promise.resolve(D);const e=new J("EmbeddedPageSDK",u.debug),r=o=>{e.log("Message to parent",o),parent.postMessage(o,"*")},n=(o,l)=>{const d=({data:f,source:_})=>{if(!(!parent||_!==parent)){if(!m(f)){console.warn("window message data should be object, instead got",f);return}e.log("Message from parent",f),o(f)}};return window.addEventListener("message",d,l),()=>{window.removeEventListener("message",d,l)}};return r({type:"Init"}),new Promise(o=>{const l=n(d=>{if(D){l(),o(D);return}if(d.type==="Init"){l();const f=new ee(d.payload,u.ensureState||{},r,n,e);D=f,o(f)}})})}exports.createEmbeddedApp=te; | ||
//# sourceMappingURL=main.cjs.js.map |
@@ -580,7 +580,4 @@ var __defProp = Object.defineProperty; | ||
this.postMessage = postMessage; | ||
this.storeNSPrefix = initData.storeConfig.nsPrefix; | ||
this.mainStoreId = initData.storeConfig.mainId; | ||
this._storeRawData = initData.store || { | ||
[this.getStoreNamespace(this.mainStoreId)]: {} | ||
}; | ||
this.mainStoreId = initData.mainStoreId; | ||
this._storeRawData = initData.store || { [this.mainStoreId]: {} }; | ||
this._writable = initData.writable; | ||
@@ -600,3 +597,3 @@ this._page = initData.page; | ||
})); | ||
this._mainStore = this.connectStore(initData.storeConfig.mainId, ensureState); | ||
this._mainStore = this.connectStore(initData.mainStoreId, ensureState); | ||
this.onStateChanged = this._mainStore.onStateChanged; | ||
@@ -653,19 +650,18 @@ } | ||
} | ||
connectStore(id, ensureState) { | ||
const namespace = this.getStoreNamespace(id); | ||
let store = this._stores.get(namespace); | ||
connectStore(storeId, ensureState) { | ||
let store = this._stores.get(storeId); | ||
if (!store) { | ||
if (!has(this._storeRawData, namespace)) { | ||
if (!has(this._storeRawData, storeId)) { | ||
const storeState = {}; | ||
this.postMessage({ type: "SetStore", payload: { [namespace]: storeState } }); | ||
this._storeRawData[namespace] = storeState; | ||
this.postMessage({ type: "SetStore", payload: { [storeId]: storeState } }); | ||
this._storeRawData[storeId] = storeState; | ||
} | ||
store = new StoreImpl({ | ||
id, | ||
state: this._storeRawData[namespace], | ||
id: storeId, | ||
state: this._storeRawData[storeId], | ||
logger: this.logger, | ||
getIsWritable: () => this._writable, | ||
onSetState: (state) => this.postMessage({ type: "SetState", payload: { namespace, state } }) | ||
onSetState: (state) => this.postMessage({ type: "SetState", payload: { storeId, state } }) | ||
}); | ||
this._stores.set(namespace, store); | ||
this._stores.set(storeId, store); | ||
} | ||
@@ -677,4 +673,4 @@ if (ensureState) { | ||
} | ||
hasStore(id) { | ||
return this._stores.has(this.getStoreNamespace(id)); | ||
isStoreConnected(id) { | ||
return this._stores.has(id); | ||
} | ||
@@ -686,10 +682,9 @@ removeStore(id) { | ||
} | ||
const namespace = this.getStoreNamespace(id); | ||
const store = this._stores.get(namespace); | ||
const store = this._stores.get(id); | ||
if (store) { | ||
this._stores.delete(namespace); | ||
this._stores.delete(id); | ||
store._destroy(); | ||
} | ||
if (this._storeRawData[namespace]) { | ||
this.postMessage({ type: "SetStore", payload: { [namespace]: void 0 } }); | ||
if (this._storeRawData[id]) { | ||
this.postMessage({ type: "SetStore", payload: { [id]: void 0 } }); | ||
} | ||
@@ -719,5 +714,2 @@ } | ||
} | ||
getStoreNamespace(id) { | ||
return this.storeNSPrefix + id; | ||
} | ||
get state() { | ||
@@ -733,8 +725,8 @@ return this._mainStore.state; | ||
_handleMsgStateChanged(payload) { | ||
if (isObj(payload) && payload.namespace && Array.isArray(payload.actions) && payload.actions.length > 0) { | ||
const { namespace, actions } = payload; | ||
if (isObj(payload) && payload.storeId && Array.isArray(payload.actions) && payload.actions.length > 0) { | ||
const { storeId, actions } = payload; | ||
actions.forEach(({ key, value, kind }) => { | ||
switch (kind) { | ||
case 2: { | ||
const storeData = this._storeRawData[namespace]; | ||
const storeData = this._storeRawData[storeId]; | ||
if (isObj(storeData)) { | ||
@@ -746,3 +738,3 @@ delete storeData[key]; | ||
default: { | ||
const storeData = this._storeRawData[namespace]; | ||
const storeData = this._storeRawData[storeId]; | ||
if (isObj(storeData)) { | ||
@@ -755,3 +747,3 @@ storeData[key] = value; | ||
}); | ||
const store = this._stores.get(namespace); | ||
const store = this._stores.get(storeId); | ||
if (store) { | ||
@@ -758,0 +750,0 @@ store._updateProperties(actions); |
@@ -1,2 +0,2 @@ | ||
(()=>{var te=Object.defineProperty;var se=(b,v,S)=>v in b?te(b,v,{enumerable:!0,configurable:!0,writable:!0,value:S}):b[v]=S;var k=(b,v,S)=>(se(b,typeof v!="symbol"?v+"":v,S),S);var ae=function(b){"use strict";class v{constructor(){this.disposers=new Map,this.disposerIDGenCount=-1}add(e,a=this.genDisposerID()){return this.flush(a),this.disposers.set(a,e()),a}addEventListener(e,a,s,o,l=this.genDisposerID()){return this.add(()=>(e.addEventListener(a,s,o),()=>e.removeEventListener(a,s,o)),l),l}setTimeout(e,a,s=this.genDisposerID()){return this.add(()=>{const o=window.setTimeout(()=>{this.remove(s),e()},a);return()=>window.clearTimeout(o)},s)}setInterval(e,a,s=this.genDisposerID()){return this.add(()=>{const o=window.setInterval(e,a);return()=>window.clearInterval(o)},s)}remove(e){const a=this.disposers.get(e);return this.disposers.delete(e),a}flush(e){const a=this.remove(e);if(a)try{a()}catch(s){console.error(s)}}flushAll(){this.disposers.forEach(e=>{try{e()}catch(a){console.error(a)}}),this.disposers.clear()}genDisposerID(){const{MAX_SAFE_INTEGER:e=9007199254740991}=Number;return this.disposerIDGenCount=(this.disposerIDGenCount+1)%e,`disposer-${this.disposerIDGenCount}`}}var S=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},N={exports:{}};(function(c,e){(function(a,s){{var o=s();c&&c.exports&&(e=c.exports=o),e.randomColor=o}})(S,function(){var a=null,s={};U();var o=[],l=function(t){if(t=t||{},t.seed!==void 0&&t.seed!==null&&t.seed===parseInt(t.seed,10))a=t.seed;else if(typeof t.seed=="string")a=Y(t.seed);else{if(t.seed!==void 0&&t.seed!==null)throw new TypeError("The seed value must be an integer or string");a=null}var n,r,i;if(t.count!==null&&t.count!==void 0){for(var h=t.count,u=[],g=0;g<t.count;g++)o.push(!1);for(t.count=null;h>u.length;){var R=l(t);a!==null&&(t.seed=a),u.push(R)}return t.count=h,u}return n=d(t),r=f(n,t),i=_(n,r,t),m([n,r,i],t)};function d(t){if(o.length>0){var n=Z(t.hue),r=A(n),i=(n[1]-n[0])/o.length,h=parseInt((r-n[0])/i);o[h]===!0?h=(h+2)%o.length:o[h]=!0;var u=(n[0]+h*i)%359,g=(n[0]+(h+1)*i)%359;return n=[u,g],r=A(n),r<0&&(r=360+r),r}else{var n=z(t.hue);return r=A(n),r<0&&(r=360+r),r}}function f(t,n){if(n.hue==="monochrome")return 0;if(n.luminosity==="random")return A([0,100]);var r=J(t),i=r[0],h=r[1];switch(n.luminosity){case"bright":i=55;break;case"dark":i=h-10;break;case"light":h=55;break}return A([i,h])}function _(t,n,r){var i=q(t,n),h=100;switch(r.luminosity){case"dark":h=i+20;break;case"light":i=(h+i)/2;break;case"random":i=0,h=100;break}return A([i,h])}function m(t,n){switch(n.format){case"hsvArray":return t;case"hslArray":return L(t);case"hsl":var r=L(t);return"hsl("+r[0]+", "+r[1]+"%, "+r[2]+"%)";case"hsla":var i=L(t),h=n.alpha||Math.random();return"hsla("+i[0]+", "+i[1]+"%, "+i[2]+"%, "+h+")";case"rgbArray":return P(t);case"rgb":var u=P(t);return"rgb("+u.join(", ")+")";case"rgba":var g=P(t),h=n.alpha||Math.random();return"rgba("+g.join(", ")+", "+h+")";default:return Q(t)}}function q(t,n){for(var r=V(t).lowerBounds,i=0;i<r.length-1;i++){var h=r[i][0],u=r[i][1],g=r[i+1][0],R=r[i+1][1];if(n>=h&&n<=g){var D=(R-u)/(g-h),w=u-D*h;return D*n+w}}return 0}function z(t){if(typeof parseInt(t)=="number"){var n=parseInt(t);if(n<360&&n>0)return[n,n]}if(typeof t=="string"){if(s[t]){var r=s[t];if(r.hueRange)return r.hueRange}else if(t.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)){var i=W(t)[0];return[i,i]}}return[0,360]}function J(t){return V(t).saturationRange}function V(t){t>=334&&t<=360&&(t-=360);for(var n in s){var r=s[n];if(r.hueRange&&t>=r.hueRange[0]&&t<=r.hueRange[1])return s[n]}return"Color not found"}function A(t){if(a===null){var n=.618033988749895,r=Math.random();return r+=n,r%=1,Math.floor(t[0]+r*(t[1]+1-t[0]))}else{var i=t[1]||1,h=t[0]||0;a=(a*9301+49297)%233280;var u=a/233280;return Math.floor(h+u*(i-h))}}function Q(t){var n=P(t);function r(h){var u=h.toString(16);return u.length==1?"0"+u:u}var i="#"+r(n[0])+r(n[1])+r(n[2]);return i}function M(t,n,r){var i=r[0][0],h=r[r.length-1][0],u=r[r.length-1][1],g=r[0][1];s[t]={hueRange:n,lowerBounds:r,saturationRange:[i,h],brightnessRange:[u,g]}}function U(){M("monochrome",null,[[0,0],[100,0]]),M("red",[-26,18],[[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]),M("orange",[18,46],[[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]),M("yellow",[46,62],[[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]),M("green",[62,178],[[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]),M("blue",[178,257],[[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]),M("purple",[257,282],[[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]),M("pink",[282,334],[[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]])}function P(t){var n=t[0];n===0&&(n=1),n===360&&(n=359),n=n/360;var r=t[1]/100,i=t[2]/100,h=Math.floor(n*6),u=n*6-h,g=i*(1-r),R=i*(1-u*r),D=i*(1-(1-u)*r),w=256,C=256,E=256;switch(h){case 0:w=i,C=D,E=g;break;case 1:w=R,C=i,E=g;break;case 2:w=g,C=i,E=D;break;case 3:w=g,C=R,E=i;break;case 4:w=D,C=g,E=i;break;case 5:w=i,C=g,E=R;break}var ee=[Math.floor(w*255),Math.floor(C*255),Math.floor(E*255)];return ee}function W(t){t=t.replace(/^#/,""),t=t.length===3?t.replace(/(.)/g,"$1$1"):t;var n=parseInt(t.substr(0,2),16)/255,r=parseInt(t.substr(2,2),16)/255,i=parseInt(t.substr(4,2),16)/255,h=Math.max(n,r,i),u=h-Math.min(n,r,i),g=h?u/h:0;switch(h){case n:return[60*((r-i)/u%6)||0,g,h];case r:return[60*((i-n)/u+2)||0,g,h];case i:return[60*((n-r)/u+4)||0,g,h]}}function L(t){var n=t[0],r=t[1]/100,i=t[2]/100,h=(2-r)*i;return[n,Math.round(r*i/(h<1?h:2-h)*1e4)/100,h/2*100]}function Y(t){for(var n=0,r=0;r!==t.length&&!(n>=Number.MAX_SAFE_INTEGER);r++)n+=t.charCodeAt(r);return n}function Z(t){if(isNaN(t)){if(typeof t=="string"){if(s[t]){var r=s[t];if(r.hueRange)return r.hueRange}else if(t.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)){var i=W(t)[0];return V(i).hueRange}}}else{var n=parseInt(t);if(n<360&&n>0)return V(t).hueRange}return[0,360]}return l})})(N,N.exports);var G=N.exports;class O{constructor(e="NetlessApp",a="error"){k(this,"kind");k(this,"debug");k(this,"color",G({luminosity:"dark"}));this.kind=e,this.debug=a}log(...e){if(this.debug===!0||this.debug==="log")return this._log("log",e)}warn(...e){if(this.debug&&this.debug!=="error")return this._log("warn",e)}error(...e){if(this.debug)return this._log("error",e)}_log(e,a){console[e](`%c[${this.kind}]:`,`color: ${this.color}; font-weight: bold;`,...a)}}class I{constructor(){this.listeners=new Set}get length(){return this.listeners.size}dispatch(e){this.listeners.forEach(a=>a(e))}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}}const T=(c,e)=>Object.prototype.hasOwnProperty.call(c,e),$=Object.keys;function p(c){return typeof c=="object"&&c!==null}const F=p;function x(c){return Boolean(p(c)&&c.__isRef)}function j(c){return{k:B(),v:c,__isRef:!0}}function B(){return Date.now().toString().slice(6)+Math.random().toString().slice(2,8)}class H{constructor({id:e,state:a,onSetState:s,getIsWritable:o,logger:l=console}){this.onStateChanged=new I,this._destroyed=!1,this.onDestroyed=new I,this._kMap=new WeakMap,this._lastValue=new Map,this.id=e,this._onSetState=s,this.getIsWritable=o,this._logger=l,this._state={},a&&$(a).forEach(d=>{const f=a[d];if(x(f)){const{k:_,v:m}=f;this._state[d]=m,p(m)&&this._kMap.set(m,_)}else this._state[d]=f})}get state(){return this._state}ensureState(e){return this.setState($(e).reduce((a,s)=>(T(this._state,s)||(a[s]=e[s]),a),{}))}setState(e){if(this._destroyed){this._logger.error(`Cannot call setState on Store ${this.id} which is destroyed.`);return}if(!this.getIsWritable()){this._logger.error(`Cannot setState on store ${this.id} without writable access`,e);return}const a=$(e);if(a.length>0){const s={};a.forEach(o=>{const l=e[o];if(l===void 0)this._lastValue.set(o,this._state[o]),delete this._state[o],s[o]=l;else if(l!==this._state[o])if(this._lastValue.set(o,this._state[o]),this._state[o]=l,p(l)){const d=j(l);this._kMap.set(d.v,d.k),s[o]=d}else s[o]=l}),Object.keys(s).length>0&&this._onSetState(s)}}get destroyed(){return this._destroyed}_destroy(){this._destroyed=!0,this.onDestroyed.dispatch()}_updateProperties(e){if(this._destroyed){this._logger.error(`Cannot call _updateProperties on Store ${this.id} which is destroyed.`);return}if(e.length>0){const a={};e.forEach(({key:s,value:o,kind:l})=>{switch(l){case 2:{T(this._state,s)&&(this._lastValue.set(s,this._state[s]),delete this._state[s]),a[s]={oldValue:this._lastValue.get(s)};break}default:{let d=o;if(x(o)){const{k:f,v:_}=o,m=this._state[s];p(m)&&this._kMap.get(m)===f?d=m:(d=_,p(_)&&this._kMap.set(_,f))}d!==this._state[s]&&(this._lastValue.set(s,this._state[s]),this._state[s]=d),a[s]={newValue:d,oldValue:this._lastValue.get(s)};break}}}),this.onStateChanged.dispatch(a)}}}class K{constructor(e,a,s,o,l){this.onRoomMembersChanged=new I,this.onMessage=new I,this.onWritableChanged=new I,this.onPageChanged=new I,this._stores=new Map,this.sideEffect=new v,this.postMessage=s,this.storeNSPrefix=e.storeConfig.nsPrefix,this.mainStoreId=e.storeConfig.mainId,this._storeRawData=e.store||{[this.getStoreNamespace(this.mainStoreId)]:{}},this._writable=e.writable,this._page=e.page,this._meta=e.meta,this._roomMembers=e.roomMembers,this.logger=l,this.sideEffect.add(()=>o(d=>{const{type:f,payload:_}=d;if(f){const m=`_handleMsg${f}`;this[m]&&this[m](_)}})),this._mainStore=this.connectStore(e.storeConfig.mainId,a),this.onStateChanged=this._mainStore.onStateChanged}get meta(){return this._meta}get roomMembers(){return this._roomMembers}_handleMsgRoomMembersChanged(e){if(e==null||Array.isArray(e)){const a=this._roomMembers;this._roomMembers=e,this.onRoomMembersChanged.dispatch({newValue:this._roomMembers,oldValue:a})}}moveCamera(e){this.postMessage({type:"MoveCamera",payload:e})}sendMessage(e){this.postMessage({type:"SendMagixMessage",payload:e})}_handleMsgReceiveMagixMessage(e){this.onMessage.dispatch(e)}get isWritable(){return this._writable}_handleMsgWritableChanged(e){const a=Boolean(e),s=this._writable;a!==s&&(this._writable=a,this.onWritableChanged.dispatch({oldValue:s,newValue:a}))}get page(){return this._page}setPage(e){this._page=e,this.postMessage({type:"SetPage",payload:e})}_handleMsgPageChanged(e){F(e)&&(this._page=e.newValue,this.onPageChanged.dispatch(e))}connectStore(e,a){const s=this.getStoreNamespace(e);let o=this._stores.get(s);if(!o){if(!T(this._storeRawData,s)){const l={};this.postMessage({type:"SetStore",payload:{[s]:l}}),this._storeRawData[s]=l}o=new H({id:e,state:this._storeRawData[s],logger:this.logger,getIsWritable:()=>this._writable,onSetState:l=>this.postMessage({type:"SetState",payload:{namespace:s,state:l}})}),this._stores.set(s,o)}return a&&o.ensureState(a),o}hasStore(e){return this._stores.has(this.getStoreNamespace(e))}removeStore(e){if(e===this.mainStoreId){this.logger.error(`Store "${e}" is not removable.`);return}const a=this.getStoreNamespace(e),s=this._stores.get(a);s&&(this._stores.delete(a),s._destroy()),this._storeRawData[a]&&this.postMessage({type:"SetStore",payload:{[a]:void 0}})}_handleMsgStoreChanged(e){Array.isArray(e)&&e.length>0&&e.forEach(({key:s,value:o,kind:l})=>{switch(l){case 2:{delete this._storeRawData[s];const d=this._stores.get(s);d&&(this._stores.delete(s),d._destroy());break}default:{this._storeRawData[s]=o;break}}})}getStoreNamespace(e){return this.storeNSPrefix+e}get state(){return this._mainStore.state}ensureState(e){return this._mainStore.ensureState(e)}setState(e){return this._mainStore.setState(e)}_handleMsgStateChanged(e){if(p(e)&&e.namespace&&Array.isArray(e.actions)&&e.actions.length>0){const{namespace:a,actions:s}=e;s.forEach(({key:l,value:d,kind:f})=>{switch(f){case 2:{const _=this._storeRawData[a];p(_)&&delete _[l];break}default:{const _=this._storeRawData[a];p(_)&&(_[l]=d);break}}});const o=this._stores.get(a);o&&o._updateProperties(s)}}destroy(){this.sideEffect.flushAll()}}let y;function X(c={}){if(!parent)throw new Error("[EmbeddedPageSDK]: SDK is not running in a iframe.");if(y)return Promise.resolve(y);const e=new O("EmbeddedPageSDK",c.debug),a=o=>{e.log("Message to parent",o),parent.postMessage(o,"*")},s=(o,l)=>{const d=({data:f,source:_})=>{if(!(!parent||_!==parent)){if(!p(f)){console.warn("window message data should be object, instead got",f);return}e.log("Message from parent",f),o(f)}};return window.addEventListener("message",d,l),()=>{window.removeEventListener("message",d,l)}};return a({type:"Init"}),new Promise(o=>{const l=s(d=>{if(y){l(),o(y);return}if(d.type==="Init"){l();const f=new K(d.payload,c.ensureState||{},a,s,e);y=f,o(f)}})})}return b.createEmbeddedApp=X,Object.defineProperty(b,"__esModule",{value:!0}),b[Symbol.toStringTag]="Module",b}({});})(); | ||
(()=>{var te=Object.defineProperty;var re=(m,v,S)=>v in m?te(m,v,{enumerable:!0,configurable:!0,writable:!0,value:S}):m[v]=S;var k=(m,v,S)=>(re(m,typeof v!="symbol"?v+"":v,S),S);var ae=function(m){"use strict";class v{constructor(){this.disposers=new Map,this.disposerIDGenCount=-1}add(e,s=this.genDisposerID()){return this.flush(s),this.disposers.set(s,e()),s}addEventListener(e,s,n,o,l=this.genDisposerID()){return this.add(()=>(e.addEventListener(s,n,o),()=>e.removeEventListener(s,n,o)),l),l}setTimeout(e,s,n=this.genDisposerID()){return this.add(()=>{const o=window.setTimeout(()=>{this.remove(n),e()},s);return()=>window.clearTimeout(o)},n)}setInterval(e,s,n=this.genDisposerID()){return this.add(()=>{const o=window.setInterval(e,s);return()=>window.clearInterval(o)},n)}remove(e){const s=this.disposers.get(e);return this.disposers.delete(e),s}flush(e){const s=this.remove(e);if(s)try{s()}catch(n){console.error(n)}}flushAll(){this.disposers.forEach(e=>{try{e()}catch(s){console.error(s)}}),this.disposers.clear()}genDisposerID(){const{MAX_SAFE_INTEGER:e=9007199254740991}=Number;return this.disposerIDGenCount=(this.disposerIDGenCount+1)%e,`disposer-${this.disposerIDGenCount}`}}var S=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},T={exports:{}};(function(c,e){(function(s,n){{var o=n();c&&c.exports&&(e=c.exports=o),e.randomColor=o}})(S,function(){var s=null,n={};U();var o=[],l=function(t){if(t=t||{},t.seed!==void 0&&t.seed!==null&&t.seed===parseInt(t.seed,10))s=t.seed;else if(typeof t.seed=="string")s=Y(t.seed);else{if(t.seed!==void 0&&t.seed!==null)throw new TypeError("The seed value must be an integer or string");s=null}var a,r,i;if(t.count!==null&&t.count!==void 0){for(var h=t.count,u=[],g=0;g<t.count;g++)o.push(!1);for(t.count=null;h>u.length;){var R=l(t);s!==null&&(t.seed=s),u.push(R)}return t.count=h,u}return a=d(t),r=f(a,t),i=_(a,r,t),b([a,r,i],t)};function d(t){if(o.length>0){var a=Z(t.hue),r=A(a),i=(a[1]-a[0])/o.length,h=parseInt((r-a[0])/i);o[h]===!0?h=(h+2)%o.length:o[h]=!0;var u=(a[0]+h*i)%359,g=(a[0]+(h+1)*i)%359;return a=[u,g],r=A(a),r<0&&(r=360+r),r}else{var a=z(t.hue);return r=A(a),r<0&&(r=360+r),r}}function f(t,a){if(a.hue==="monochrome")return 0;if(a.luminosity==="random")return A([0,100]);var r=J(t),i=r[0],h=r[1];switch(a.luminosity){case"bright":i=55;break;case"dark":i=h-10;break;case"light":h=55;break}return A([i,h])}function _(t,a,r){var i=q(t,a),h=100;switch(r.luminosity){case"dark":h=i+20;break;case"light":i=(h+i)/2;break;case"random":i=0,h=100;break}return A([i,h])}function b(t,a){switch(a.format){case"hsvArray":return t;case"hslArray":return W(t);case"hsl":var r=W(t);return"hsl("+r[0]+", "+r[1]+"%, "+r[2]+"%)";case"hsla":var i=W(t),h=a.alpha||Math.random();return"hsla("+i[0]+", "+i[1]+"%, "+i[2]+"%, "+h+")";case"rgbArray":return P(t);case"rgb":var u=P(t);return"rgb("+u.join(", ")+")";case"rgba":var g=P(t),h=a.alpha||Math.random();return"rgba("+g.join(", ")+", "+h+")";default:return Q(t)}}function q(t,a){for(var r=V(t).lowerBounds,i=0;i<r.length-1;i++){var h=r[i][0],u=r[i][1],g=r[i+1][0],R=r[i+1][1];if(a>=h&&a<=g){var y=(R-u)/(g-h),w=u-y*h;return y*a+w}}return 0}function z(t){if(typeof parseInt(t)=="number"){var a=parseInt(t);if(a<360&&a>0)return[a,a]}if(typeof t=="string"){if(n[t]){var r=n[t];if(r.hueRange)return r.hueRange}else if(t.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)){var i=O(t)[0];return[i,i]}}return[0,360]}function J(t){return V(t).saturationRange}function V(t){t>=334&&t<=360&&(t-=360);for(var a in n){var r=n[a];if(r.hueRange&&t>=r.hueRange[0]&&t<=r.hueRange[1])return n[a]}return"Color not found"}function A(t){if(s===null){var a=.618033988749895,r=Math.random();return r+=a,r%=1,Math.floor(t[0]+r*(t[1]+1-t[0]))}else{var i=t[1]||1,h=t[0]||0;s=(s*9301+49297)%233280;var u=s/233280;return Math.floor(h+u*(i-h))}}function Q(t){var a=P(t);function r(h){var u=h.toString(16);return u.length==1?"0"+u:u}var i="#"+r(a[0])+r(a[1])+r(a[2]);return i}function M(t,a,r){var i=r[0][0],h=r[r.length-1][0],u=r[r.length-1][1],g=r[0][1];n[t]={hueRange:a,lowerBounds:r,saturationRange:[i,h],brightnessRange:[u,g]}}function U(){M("monochrome",null,[[0,0],[100,0]]),M("red",[-26,18],[[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]),M("orange",[18,46],[[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]),M("yellow",[46,62],[[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]),M("green",[62,178],[[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]),M("blue",[178,257],[[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]),M("purple",[257,282],[[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]),M("pink",[282,334],[[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]])}function P(t){var a=t[0];a===0&&(a=1),a===360&&(a=359),a=a/360;var r=t[1]/100,i=t[2]/100,h=Math.floor(a*6),u=a*6-h,g=i*(1-r),R=i*(1-u*r),y=i*(1-(1-u)*r),w=256,E=256,C=256;switch(h){case 0:w=i,E=y,C=g;break;case 1:w=R,E=i,C=g;break;case 2:w=g,E=i,C=y;break;case 3:w=g,E=R,C=i;break;case 4:w=y,E=g,C=i;break;case 5:w=i,E=g,C=R;break}var ee=[Math.floor(w*255),Math.floor(E*255),Math.floor(C*255)];return ee}function O(t){t=t.replace(/^#/,""),t=t.length===3?t.replace(/(.)/g,"$1$1"):t;var a=parseInt(t.substr(0,2),16)/255,r=parseInt(t.substr(2,2),16)/255,i=parseInt(t.substr(4,2),16)/255,h=Math.max(a,r,i),u=h-Math.min(a,r,i),g=h?u/h:0;switch(h){case a:return[60*((r-i)/u%6)||0,g,h];case r:return[60*((i-a)/u+2)||0,g,h];case i:return[60*((a-r)/u+4)||0,g,h]}}function W(t){var a=t[0],r=t[1]/100,i=t[2]/100,h=(2-r)*i;return[a,Math.round(r*i/(h<1?h:2-h)*1e4)/100,h/2*100]}function Y(t){for(var a=0,r=0;r!==t.length&&!(a>=Number.MAX_SAFE_INTEGER);r++)a+=t.charCodeAt(r);return a}function Z(t){if(isNaN(t)){if(typeof t=="string"){if(n[t]){var r=n[t];if(r.hueRange)return r.hueRange}else if(t.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)){var i=O(t)[0];return V(i).hueRange}}}else{var a=parseInt(t);if(a<360&&a>0)return V(t).hueRange}return[0,360]}return l})})(T,T.exports);var F=T.exports;class N{constructor(e="NetlessApp",s="error"){k(this,"kind");k(this,"debug");k(this,"color",F({luminosity:"dark"}));this.kind=e,this.debug=s}log(...e){if(this.debug===!0||this.debug==="log")return this._log("log",e)}warn(...e){if(this.debug&&this.debug!=="error")return this._log("warn",e)}error(...e){if(this.debug)return this._log("error",e)}_log(e,s){console[e](`%c[${this.kind}]:`,`color: ${this.color}; font-weight: bold;`,...s)}}class D{constructor(){this.listeners=new Set}get length(){return this.listeners.size}dispatch(e){this.listeners.forEach(s=>s(e))}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}}const $=(c,e)=>Object.prototype.hasOwnProperty.call(c,e),L=Object.keys;function p(c){return typeof c=="object"&&c!==null}const j=p;function G(c){return Boolean(p(c)&&c.__isRef)}function x(c){return{k:B(),v:c,__isRef:!0}}function B(){return Date.now().toString().slice(6)+Math.random().toString().slice(2,8)}class H{constructor({id:e,state:s,onSetState:n,getIsWritable:o,logger:l=console}){this.onStateChanged=new D,this._destroyed=!1,this.onDestroyed=new D,this._kMap=new WeakMap,this._lastValue=new Map,this.id=e,this._onSetState=n,this.getIsWritable=o,this._logger=l,this._state={},s&&L(s).forEach(d=>{const f=s[d];if(G(f)){const{k:_,v:b}=f;this._state[d]=b,p(b)&&this._kMap.set(b,_)}else this._state[d]=f})}get state(){return this._state}ensureState(e){return this.setState(L(e).reduce((s,n)=>($(this._state,n)||(s[n]=e[n]),s),{}))}setState(e){if(this._destroyed){this._logger.error(`Cannot call setState on Store ${this.id} which is destroyed.`);return}if(!this.getIsWritable()){this._logger.error(`Cannot setState on store ${this.id} without writable access`,e);return}const s=L(e);if(s.length>0){const n={};s.forEach(o=>{const l=e[o];if(l===void 0)this._lastValue.set(o,this._state[o]),delete this._state[o],n[o]=l;else if(l!==this._state[o])if(this._lastValue.set(o,this._state[o]),this._state[o]=l,p(l)){const d=x(l);this._kMap.set(d.v,d.k),n[o]=d}else n[o]=l}),Object.keys(n).length>0&&this._onSetState(n)}}get destroyed(){return this._destroyed}_destroy(){this._destroyed=!0,this.onDestroyed.dispatch()}_updateProperties(e){if(this._destroyed){this._logger.error(`Cannot call _updateProperties on Store ${this.id} which is destroyed.`);return}if(e.length>0){const s={};e.forEach(({key:n,value:o,kind:l})=>{switch(l){case 2:{$(this._state,n)&&(this._lastValue.set(n,this._state[n]),delete this._state[n]),s[n]={oldValue:this._lastValue.get(n)};break}default:{let d=o;if(G(o)){const{k:f,v:_}=o,b=this._state[n];p(b)&&this._kMap.get(b)===f?d=b:(d=_,p(_)&&this._kMap.set(_,f))}d!==this._state[n]&&(this._lastValue.set(n,this._state[n]),this._state[n]=d),s[n]={newValue:d,oldValue:this._lastValue.get(n)};break}}}),this.onStateChanged.dispatch(s)}}}class K{constructor(e,s,n,o,l){this.onRoomMembersChanged=new D,this.onMessage=new D,this.onWritableChanged=new D,this.onPageChanged=new D,this._stores=new Map,this.sideEffect=new v,this.postMessage=n,this.mainStoreId=e.mainStoreId,this._storeRawData=e.store||{[this.mainStoreId]:{}},this._writable=e.writable,this._page=e.page,this._meta=e.meta,this._roomMembers=e.roomMembers,this.logger=l,this.sideEffect.add(()=>o(d=>{const{type:f,payload:_}=d;if(f){const b=`_handleMsg${f}`;this[b]&&this[b](_)}})),this._mainStore=this.connectStore(e.mainStoreId,s),this.onStateChanged=this._mainStore.onStateChanged}get meta(){return this._meta}get roomMembers(){return this._roomMembers}_handleMsgRoomMembersChanged(e){if(e==null||Array.isArray(e)){const s=this._roomMembers;this._roomMembers=e,this.onRoomMembersChanged.dispatch({newValue:this._roomMembers,oldValue:s})}}moveCamera(e){this.postMessage({type:"MoveCamera",payload:e})}sendMessage(e){this.postMessage({type:"SendMagixMessage",payload:e})}_handleMsgReceiveMagixMessage(e){this.onMessage.dispatch(e)}get isWritable(){return this._writable}_handleMsgWritableChanged(e){const s=Boolean(e),n=this._writable;s!==n&&(this._writable=s,this.onWritableChanged.dispatch({oldValue:n,newValue:s}))}get page(){return this._page}setPage(e){this._page=e,this.postMessage({type:"SetPage",payload:e})}_handleMsgPageChanged(e){j(e)&&(this._page=e.newValue,this.onPageChanged.dispatch(e))}connectStore(e,s){let n=this._stores.get(e);if(!n){if(!$(this._storeRawData,e)){const o={};this.postMessage({type:"SetStore",payload:{[e]:o}}),this._storeRawData[e]=o}n=new H({id:e,state:this._storeRawData[e],logger:this.logger,getIsWritable:()=>this._writable,onSetState:o=>this.postMessage({type:"SetState",payload:{storeId:e,state:o}})}),this._stores.set(e,n)}return s&&n.ensureState(s),n}isStoreConnected(e){return this._stores.has(e)}removeStore(e){if(e===this.mainStoreId){this.logger.error(`Store "${e}" is not removable.`);return}const s=this._stores.get(e);s&&(this._stores.delete(e),s._destroy()),this._storeRawData[e]&&this.postMessage({type:"SetStore",payload:{[e]:void 0}})}_handleMsgStoreChanged(e){Array.isArray(e)&&e.length>0&&e.forEach(({key:n,value:o,kind:l})=>{switch(l){case 2:{delete this._storeRawData[n];const d=this._stores.get(n);d&&(this._stores.delete(n),d._destroy());break}default:{this._storeRawData[n]=o;break}}})}get state(){return this._mainStore.state}ensureState(e){return this._mainStore.ensureState(e)}setState(e){return this._mainStore.setState(e)}_handleMsgStateChanged(e){if(p(e)&&e.storeId&&Array.isArray(e.actions)&&e.actions.length>0){const{storeId:s,actions:n}=e;n.forEach(({key:l,value:d,kind:f})=>{switch(f){case 2:{const _=this._storeRawData[s];p(_)&&delete _[l];break}default:{const _=this._storeRawData[s];p(_)&&(_[l]=d);break}}});const o=this._stores.get(s);o&&o._updateProperties(n)}}destroy(){this.sideEffect.flushAll()}}let I;function X(c={}){if(!parent)throw new Error("[EmbeddedPageSDK]: SDK is not running in a iframe.");if(I)return Promise.resolve(I);const e=new N("EmbeddedPageSDK",c.debug),s=o=>{e.log("Message to parent",o),parent.postMessage(o,"*")},n=(o,l)=>{const d=({data:f,source:_})=>{if(!(!parent||_!==parent)){if(!p(f)){console.warn("window message data should be object, instead got",f);return}e.log("Message from parent",f),o(f)}};return window.addEventListener("message",d,l),()=>{window.removeEventListener("message",d,l)}};return s({type:"Init"}),new Promise(o=>{const l=n(d=>{if(I){l(),o(I);return}if(d.type==="Init"){l();const f=new K(d.payload,c.ensureState||{},s,n,e);I=f,o(f)}})})}return m.createEmbeddedApp=X,Object.defineProperty(m,"__esModule",{value:!0}),m[Symbol.toStringTag]="Module",m}({});})(); | ||
//# sourceMappingURL=main.iife.js.map |
{ | ||
"name": "@netless/app-embedded-page-sdk", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"main": "dist/main.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/main.es.js", |
@@ -49,7 +49,4 @@ import type { | ||
this.storeNSPrefix = initData.storeConfig.nsPrefix; | ||
this.mainStoreId = initData.storeConfig.mainId; | ||
this._storeRawData = initData.store || { | ||
[this.getStoreNamespace(this.mainStoreId)]: {}, | ||
}; | ||
this.mainStoreId = initData.mainStoreId; | ||
this._storeRawData = initData.store || { [this.mainStoreId]: {} }; | ||
@@ -79,3 +76,3 @@ this._writable = initData.writable; | ||
this._mainStore = this.connectStore(initData.storeConfig.mainId, ensureState); | ||
this._mainStore = this.connectStore(initData.mainStoreId, ensureState); | ||
this.onStateChanged = this._mainStore.onStateChanged; | ||
@@ -187,23 +184,20 @@ } | ||
connectStore<S>(id: string, ensureState: S): Store<S> { | ||
const namespace = this.getStoreNamespace(id); | ||
let store = this._stores.get(namespace) as Store<S> | undefined; | ||
connectStore<S>(storeId: string, ensureState?: S): Store<S> { | ||
let store = this._stores.get(storeId) as Store<S> | undefined; | ||
if (!store) { | ||
if (!has(this._storeRawData, namespace)) { | ||
if (!has(this._storeRawData, storeId)) { | ||
const storeState = {}; | ||
this.postMessage({ type: "SetStore", payload: { [namespace]: storeState } }); | ||
this._storeRawData[namespace] = storeState; | ||
this.postMessage({ type: "SetStore", payload: { [storeId]: storeState } }); | ||
this._storeRawData[storeId] = storeState; | ||
} | ||
store = new StoreImpl<S>({ | ||
id, | ||
state: this._storeRawData[namespace] as S, | ||
id: storeId, | ||
state: this._storeRawData[storeId] as S, | ||
logger: this.logger, | ||
getIsWritable: () => this._writable, | ||
onSetState: state => | ||
this.postMessage<S>({ type: "SetState", payload: { namespace, state } }), | ||
onSetState: state => this.postMessage<S>({ type: "SetState", payload: { storeId, state } }), | ||
}) as Store<S>; | ||
this._stores.set(namespace, store); | ||
this._stores.set(storeId, store); | ||
} | ||
@@ -218,4 +212,4 @@ | ||
hasStore(id: string): boolean { | ||
return this._stores.has(this.getStoreNamespace(id)); | ||
isStoreConnected(id: string): boolean { | ||
return this._stores.has(id); | ||
} | ||
@@ -228,10 +222,9 @@ | ||
} | ||
const namespace = this.getStoreNamespace(id); | ||
const store = this._stores.get(namespace) as StoreImpl<TState>; | ||
const store = this._stores.get(id) as StoreImpl<TState>; | ||
if (store) { | ||
this._stores.delete(namespace); | ||
this._stores.delete(id); | ||
store._destroy(); | ||
} | ||
if (this._storeRawData[namespace]) { | ||
this.postMessage({ type: "SetStore", payload: { [namespace]: void 0 } }); | ||
if (this._storeRawData[id]) { | ||
this.postMessage({ type: "SetStore", payload: { [id]: void 0 } }); | ||
} | ||
@@ -265,9 +258,4 @@ } | ||
private storeNSPrefix: string; | ||
private mainStoreId: string; | ||
getStoreNamespace(id: string): string { | ||
return this.storeNSPrefix + id; | ||
} | ||
get state() { | ||
@@ -292,7 +280,7 @@ return this._mainStore.state; | ||
isObj(payload) && | ||
payload.namespace && | ||
payload.storeId && | ||
Array.isArray(payload.actions) && | ||
payload.actions.length > 0 | ||
) { | ||
const { namespace, actions } = payload as ToSDKMessagePayloads< | ||
const { storeId, actions } = payload as ToSDKMessagePayloads< | ||
TState, | ||
@@ -306,3 +294,3 @@ TMessage | ||
case 2: { | ||
const storeData = this._storeRawData[namespace]; | ||
const storeData = this._storeRawData[storeId]; | ||
if (isObj(storeData)) { | ||
@@ -314,3 +302,3 @@ delete storeData[key]; | ||
default: { | ||
const storeData = this._storeRawData[namespace]; | ||
const storeData = this._storeRawData[storeId]; | ||
if (isObj(storeData)) { | ||
@@ -324,3 +312,3 @@ storeData[key] = value; | ||
const store = this._stores.get(namespace) as StoreImpl<TState> | undefined; | ||
const store = this._stores.get(storeId) as StoreImpl<TState> | undefined; | ||
if (store) { | ||
@@ -327,0 +315,0 @@ store._updateProperties(actions); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
230571
1626