Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@netless/app-embedded-page-sdk

Package Overview
Dependencies
Maintainers
10
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netless/app-embedded-page-sdk - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

LICENSE

2

dist/main.iife.js

@@ -1,2 +0,2 @@

(()=>{var ne=Object.defineProperty;var ie=(b,p,E)=>p in b?ne(b,p,{enumerable:!0,configurable:!0,writable:!0,value:E}):b[p]=E;var L=(b,p,E)=>(ie(b,typeof p!="symbol"?p+"":p,E),E);var he=function(b){"use strict";const p="!#%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",E=p.length,j=Array(20),I=()=>{for(let l=0;l<20;l++)j[l]=p.charAt(Math.random()*E);return j.join("")};class x{constructor(){this.disposers=new Map}add(e,r=I()){return this.flush(r),this.disposers.set(r,e()),r}addDisposer(e,r=I()){return this.flush(r),this.disposers.set(r,e),r}addEventListener(e,r,n,o,d=I()){return this.add(()=>(e.addEventListener(r,n,o),()=>e.removeEventListener(r,n,o)),d),d}setTimeout(e,r,n=I()){return this.add(()=>{const o=window.setTimeout(()=>{this.remove(n),e()},r);return()=>window.clearTimeout(o)},n)}setInterval(e,r,n=I()){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()}}var K=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},$={exports:{}};(function(l,e){(function(r,n){{var o=n();l&&l.exports&&(e=l.exports=o),e.randomColor=o}})(K,function(){var r=null,n={};te();var o=[],d=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=re(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=[],f=0;f<t.count;f++)o.push(!1);for(t.count=null;h>g.length;){var R=d(t);r!==null&&(t.seed=r),g.push(R)}return t.count=h,g}return a=u(t),s=c(a,t),i=_(a,s,t),m([a,s,i],t)};function u(t){if(o.length>0){var a=se(t.hue),s=T(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,f=(a[0]+(h+1)*i)%359;return a=[g,f],s=T(a),s<0&&(s=360+s),s}else{var a=Y(t.hue);return s=T(a),s<0&&(s=360+s),s}}function c(t,a){if(a.hue==="monochrome")return 0;if(a.luminosity==="random")return T([0,100]);var s=Z(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 T([i,h])}function _(t,a,s){var i=w(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 T([i,h])}function m(t,a){switch(a.format){case"hsvArray":return t;case"hslArray":return O(t);case"hsl":var s=O(t);return"hsl("+s[0]+", "+s[1]+"%, "+s[2]+"%)";case"hsla":var i=O(t),h=a.alpha||Math.random();return"hsla("+i[0]+", "+i[1]+"%, "+i[2]+"%, "+h+")";case"rgbArray":return D(t);case"rgb":var g=D(t);return"rgb("+g.join(", ")+")";case"rgba":var f=D(t),h=a.alpha||Math.random();return"rgba("+f.join(", ")+", "+h+")";default:return ee(t)}}function w(t,a){for(var s=N(t).lowerBounds,i=0;i<s.length-1;i++){var h=s[i][0],g=s[i][1],f=s[i+1][0],R=s[i+1][1];if(a>=h&&a<=f){var V=(R-g)/(f-h),M=g-V*h;return V*a+M}}return 0}function Y(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=H(t)[0];return[i,i]}}return[0,360]}function Z(t){return N(t).saturationRange}function N(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 T(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 ee(t){var a=D(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 S(t,a,s){var i=s[0][0],h=s[s.length-1][0],g=s[s.length-1][1],f=s[0][1];n[t]={hueRange:a,lowerBounds:s,saturationRange:[i,h],brightnessRange:[g,f]}}function te(){S("monochrome",null,[[0,0],[100,0]]),S("red",[-26,18],[[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]),S("orange",[18,46],[[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]),S("yellow",[46,62],[[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]),S("green",[62,178],[[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]),S("blue",[178,257],[[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]),S("purple",[257,282],[[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]),S("pink",[282,334],[[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]])}function D(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,f=i*(1-s),R=i*(1-g*s),V=i*(1-(1-g)*s),M=256,y=256,C=256;switch(h){case 0:M=i,y=V,C=f;break;case 1:M=R,y=i,C=f;break;case 2:M=f,y=i,C=V;break;case 3:M=f,y=R,C=i;break;case 4:M=V,y=f,C=i;break;case 5:M=i,y=f,C=R;break}var ae=[Math.floor(M*255),Math.floor(y*255),Math.floor(C*255)];return ae}function H(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),f=h?g/h:0;switch(h){case a:return[60*((s-i)/g%6)||0,f,h];case s:return[60*((i-a)/g+2)||0,f,h];case i:return[60*((a-s)/g+4)||0,f,h]}}function O(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 re(t){for(var a=0,s=0;s!==t.length&&!(a>=Number.MAX_SAFE_INTEGER);s++)a+=t.charCodeAt(s);return a}function se(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=H(t)[0];return N(i).hueRange}}}else{var a=parseInt(t);if(a<360&&a>0)return N(t).hueRange}return[0,360]}return d})})($,$.exports);var G=$.exports;class q{constructor(e="NetlessApp",r="error"){L(this,"kind");L(this,"debug");L(this,"color",G({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 A{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=(l,e)=>Object.prototype.hasOwnProperty.call(l,e),W=Object.keys;function v(l){return typeof l=="object"&&l!==null}const z=v;function B(l){return Boolean(v(l)&&l.__isRef)}function X(l){return{k:J(),v:l,__isRef:!0}}function J(){return Date.now().toString().slice(6)+Math.random().toString().slice(2,8)}class Q{constructor({id:e,state:r,onSetState:n,getIsWritable:o,logger:d=console}){this.onStateChanged=new A,this._destroyed=!1,this.onDestroyed=new A,this._kMap=new WeakMap,this._lastValue=new Map,this.id=e,this._onSetState=n,this.getIsWritable=o,this._logger=d,this._state={},r&&W(r).forEach(u=>{const c=r[u];if(B(c)){const{k:_,v:m}=c;this._state[u]=m,v(m)&&this._kMap.set(m,_)}else this._state[u]=c})}get state(){return this._state}ensureState(e){return this.setState(W(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=W(e);if(r.length>0){const n={};r.forEach(o=>{const d=e[o];if(d===void 0)this._lastValue.set(o,this._state[o]),delete this._state[o],n[o]=d;else if(d!==this._state[o])if(this._lastValue.set(o,this._state[o]),this._state[o]=d,v(d)){const u=X(d);this._kMap.set(u.v,u.k),n[o]=u}else n[o]=d}),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:d})=>{let u;switch(this._lastValue.has(n)&&(u=this._lastValue.get(n),this._lastValue.delete(n)),d){case 2:{k(this._state,n)&&(u=this._state[n],delete this._state[n]),r[n]={oldValue:u};break}default:{let c=o;if(B(o)){const{k:_,v:m}=o,w=this._state[n];v(w)&&this._kMap.get(w)===_?c=w:(c=m,v(m)&&this._kMap.set(m,_))}c!==this._state[n]&&(u=this._state[n],this._state[n]=c),r[n]={newValue:c,oldValue:u};break}}}),this.onStateChanged.dispatch(r)}}}class F{constructor(e,r,n,o,d,u){this.onRoomMembersChanged=new A,this.onMessage=new A,this.onWritableChanged=new A,this.onPageChanged=new A,this._stores=new Map,this._sideEffect=new x,this.appId=e.appId,this.debug=n,this._postMessage=o,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=u,this._sideEffect.add(()=>d(c=>{const{NEAType:_,payload:m}=c;if(_){const w=`_handleMsg${_}`;this[w]&&this[w](m)}})),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({NEAType:"MoveCamera",payload:e})}sendMessage(e){this._postMessage({NEAType:"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({NEAType:"SetPage",payload:e})}_handleMsgPageChanged(e){z(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({NEAType:"SetStore",payload:{[e]:o}}),this._storeRawData[e]=o}n=new Q({id:e,state:this._storeRawData[e],logger:this._logger,getIsWritable:()=>this._writable,onSetState:o=>this._postMessage({NEAType:"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({NEAType:"SetStore",payload:{[e]:void 0}})}_handleMsgStoreChanged(e){Array.isArray(e)&&e.length>0&&e.forEach(({key:n,value:o,kind:d})=>{switch(d){case 2:{delete this._storeRawData[n];const u=this._stores.get(n);u&&(this._stores.delete(n),u._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(v(e)&&e.storeId&&Array.isArray(e.actions)&&e.actions.length>0){const{storeId:r,actions:n}=e;n.forEach(({key:d,value:u,kind:c})=>{switch(c){case 2:{const _=this._storeRawData[r];v(_)&&delete _[d];break}default:{const _=this._storeRawData[r];v(_)&&(_[d]=u);break}}});const o=this._stores.get(r);o&&o._updateProperties(n)}}destroy(){this._sideEffect.flushAll()}}let P;function U(l={}){if(!parent)throw new Error("[EmbeddedPageSDK]: SDK is not running in a iframe.");if(P)return Promise.resolve(P);const e=new q("EmbeddedPageSDK",l.debug),r=l.postMessage||(o=>{e.log("Message to parent",o),parent.postMessage(o,"*")}),n=l.addMessageListener||((o,d)=>{const u=({data:c,source:_})=>{!parent||_!==parent||!v(c)||!c.NEAType||(e.log("Message from parent",c),o(c))};return window.addEventListener("message",u,d),()=>{window.removeEventListener("message",u,d)}});return r({NEAType:"Init"}),new Promise(o=>{const d=n(u=>{if(P){d(),o(P);return}if(u.NEAType==="Init"){d();const c=new F(u.payload,l.ensureState||{},Boolean(k(l,"debug")?l.debug:u.payload||!1),r,n,e);P=c,o(c)}})})}return b.EmbeddedApp=F,b.EmbeddedPageEvent=A,b.createEmbeddedApp=U,Object.defineProperty(b,"__esModule",{value:!0}),b[Symbol.toStringTag]="Module",b}({});})();
var ne=Object.defineProperty;var ie=(b,p,E)=>p in b?ne(b,p,{enumerable:!0,configurable:!0,writable:!0,value:E}):b[p]=E;var L=(b,p,E)=>(ie(b,typeof p!="symbol"?p+"":p,E),E);var NetlessAppEmbeddedPageSdk=function(b){"use strict";const p="!#%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",E=p.length,j=Array(20),I=()=>{for(let l=0;l<20;l++)j[l]=p.charAt(Math.random()*E);return j.join("")};class x{constructor(){this.disposers=new Map}add(e,r=I()){return this.flush(r),this.disposers.set(r,e()),r}addDisposer(e,r=I()){return this.flush(r),this.disposers.set(r,e),r}addEventListener(e,r,n,o,d=I()){return this.add(()=>(e.addEventListener(r,n,o),()=>e.removeEventListener(r,n,o)),d),d}setTimeout(e,r,n=I()){return this.add(()=>{const o=window.setTimeout(()=>{this.remove(n),e()},r);return()=>window.clearTimeout(o)},n)}setInterval(e,r,n=I()){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()}}var K=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},$={exports:{}};(function(l,e){(function(r,n){{var o=n();l&&l.exports&&(e=l.exports=o),e.randomColor=o}})(K,function(){var r=null,n={};te();var o=[],d=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=re(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=[],f=0;f<t.count;f++)o.push(!1);for(t.count=null;h>g.length;){var R=d(t);r!==null&&(t.seed=r),g.push(R)}return t.count=h,g}return a=u(t),s=c(a,t),i=_(a,s,t),m([a,s,i],t)};function u(t){if(o.length>0){var a=se(t.hue),s=T(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,f=(a[0]+(h+1)*i)%359;return a=[g,f],s=T(a),s<0&&(s=360+s),s}else{var a=Y(t.hue);return s=T(a),s<0&&(s=360+s),s}}function c(t,a){if(a.hue==="monochrome")return 0;if(a.luminosity==="random")return T([0,100]);var s=Z(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 T([i,h])}function _(t,a,s){var i=w(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 T([i,h])}function m(t,a){switch(a.format){case"hsvArray":return t;case"hslArray":return O(t);case"hsl":var s=O(t);return"hsl("+s[0]+", "+s[1]+"%, "+s[2]+"%)";case"hsla":var i=O(t),h=a.alpha||Math.random();return"hsla("+i[0]+", "+i[1]+"%, "+i[2]+"%, "+h+")";case"rgbArray":return D(t);case"rgb":var g=D(t);return"rgb("+g.join(", ")+")";case"rgba":var f=D(t),h=a.alpha||Math.random();return"rgba("+f.join(", ")+", "+h+")";default:return ee(t)}}function w(t,a){for(var s=N(t).lowerBounds,i=0;i<s.length-1;i++){var h=s[i][0],g=s[i][1],f=s[i+1][0],R=s[i+1][1];if(a>=h&&a<=f){var V=(R-g)/(f-h),M=g-V*h;return V*a+M}}return 0}function Y(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=H(t)[0];return[i,i]}}return[0,360]}function Z(t){return N(t).saturationRange}function N(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 T(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 ee(t){var a=D(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 S(t,a,s){var i=s[0][0],h=s[s.length-1][0],g=s[s.length-1][1],f=s[0][1];n[t]={hueRange:a,lowerBounds:s,saturationRange:[i,h],brightnessRange:[g,f]}}function te(){S("monochrome",null,[[0,0],[100,0]]),S("red",[-26,18],[[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]),S("orange",[18,46],[[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]),S("yellow",[46,62],[[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]),S("green",[62,178],[[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]),S("blue",[178,257],[[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]),S("purple",[257,282],[[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]),S("pink",[282,334],[[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]])}function D(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,f=i*(1-s),R=i*(1-g*s),V=i*(1-(1-g)*s),M=256,y=256,C=256;switch(h){case 0:M=i,y=V,C=f;break;case 1:M=R,y=i,C=f;break;case 2:M=f,y=i,C=V;break;case 3:M=f,y=R,C=i;break;case 4:M=V,y=f,C=i;break;case 5:M=i,y=f,C=R;break}var ae=[Math.floor(M*255),Math.floor(y*255),Math.floor(C*255)];return ae}function H(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),f=h?g/h:0;switch(h){case a:return[60*((s-i)/g%6)||0,f,h];case s:return[60*((i-a)/g+2)||0,f,h];case i:return[60*((a-s)/g+4)||0,f,h]}}function O(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 re(t){for(var a=0,s=0;s!==t.length&&!(a>=Number.MAX_SAFE_INTEGER);s++)a+=t.charCodeAt(s);return a}function se(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=H(t)[0];return N(i).hueRange}}}else{var a=parseInt(t);if(a<360&&a>0)return N(t).hueRange}return[0,360]}return d})})($,$.exports);var G=$.exports;class q{constructor(e="NetlessApp",r="error"){L(this,"kind");L(this,"debug");L(this,"color",G({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 A{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=(l,e)=>Object.prototype.hasOwnProperty.call(l,e),W=Object.keys;function v(l){return typeof l=="object"&&l!==null}const z=v;function B(l){return Boolean(v(l)&&l.__isRef)}function X(l){return{k:J(),v:l,__isRef:!0}}function J(){return Date.now().toString().slice(6)+Math.random().toString().slice(2,8)}class Q{constructor({id:e,state:r,onSetState:n,getIsWritable:o,logger:d=console}){this.onStateChanged=new A,this._destroyed=!1,this.onDestroyed=new A,this._kMap=new WeakMap,this._lastValue=new Map,this.id=e,this._onSetState=n,this.getIsWritable=o,this._logger=d,this._state={},r&&W(r).forEach(u=>{const c=r[u];if(B(c)){const{k:_,v:m}=c;this._state[u]=m,v(m)&&this._kMap.set(m,_)}else this._state[u]=c})}get state(){return this._state}ensureState(e){return this.setState(W(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=W(e);if(r.length>0){const n={};r.forEach(o=>{const d=e[o];if(d===void 0)this._lastValue.set(o,this._state[o]),delete this._state[o],n[o]=d;else if(d!==this._state[o])if(this._lastValue.set(o,this._state[o]),this._state[o]=d,v(d)){const u=X(d);this._kMap.set(u.v,u.k),n[o]=u}else n[o]=d}),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:d})=>{let u;switch(this._lastValue.has(n)&&(u=this._lastValue.get(n),this._lastValue.delete(n)),d){case 2:{k(this._state,n)&&(u=this._state[n],delete this._state[n]),r[n]={oldValue:u};break}default:{let c=o;if(B(o)){const{k:_,v:m}=o,w=this._state[n];v(w)&&this._kMap.get(w)===_?c=w:(c=m,v(m)&&this._kMap.set(m,_))}c!==this._state[n]&&(u=this._state[n],this._state[n]=c),r[n]={newValue:c,oldValue:u};break}}}),this.onStateChanged.dispatch(r)}}}class F{constructor(e,r,n,o,d,u){this.onRoomMembersChanged=new A,this.onMessage=new A,this.onWritableChanged=new A,this.onPageChanged=new A,this._stores=new Map,this._sideEffect=new x,this.appId=e.appId,this.debug=n,this._postMessage=o,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=u,this._sideEffect.add(()=>d(c=>{const{NEAType:_,payload:m}=c;if(_){const w=`_handleMsg${_}`;this[w]&&this[w](m)}})),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({NEAType:"MoveCamera",payload:e})}sendMessage(e){this._postMessage({NEAType:"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({NEAType:"SetPage",payload:e})}_handleMsgPageChanged(e){z(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({NEAType:"SetStore",payload:{[e]:o}}),this._storeRawData[e]=o}n=new Q({id:e,state:this._storeRawData[e],logger:this._logger,getIsWritable:()=>this._writable,onSetState:o=>this._postMessage({NEAType:"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({NEAType:"SetStore",payload:{[e]:void 0}})}_handleMsgStoreChanged(e){Array.isArray(e)&&e.length>0&&e.forEach(({key:n,value:o,kind:d})=>{switch(d){case 2:{delete this._storeRawData[n];const u=this._stores.get(n);u&&(this._stores.delete(n),u._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(v(e)&&e.storeId&&Array.isArray(e.actions)&&e.actions.length>0){const{storeId:r,actions:n}=e;n.forEach(({key:d,value:u,kind:c})=>{switch(c){case 2:{const _=this._storeRawData[r];v(_)&&delete _[d];break}default:{const _=this._storeRawData[r];v(_)&&(_[d]=u);break}}});const o=this._stores.get(r);o&&o._updateProperties(n)}}destroy(){this._sideEffect.flushAll()}}let P;function U(l={}){if(!parent)throw new Error("[EmbeddedPageSDK]: SDK is not running in a iframe.");if(P)return Promise.resolve(P);const e=new q("EmbeddedPageSDK",l.debug),r=l.postMessage||(o=>{e.log("Message to parent",o),parent.postMessage(o,"*")}),n=l.addMessageListener||((o,d)=>{const u=({data:c,source:_})=>{!parent||_!==parent||!v(c)||!c.NEAType||(e.log("Message from parent",c),o(c))};return window.addEventListener("message",u,d),()=>{window.removeEventListener("message",u,d)}});return r({NEAType:"Init"}),new Promise(o=>{const d=n(u=>{if(P){d(),o(P);return}if(u.NEAType==="Init"){d();const c=new F(u.payload,l.ensureState||{},Boolean(k(l,"debug")?l.debug:u.payload||!1),r,n,e);P=c,o(c)}})})}return b.EmbeddedApp=F,b.EmbeddedPageEvent=A,b.createEmbeddedApp=U,Object.defineProperty(b,"__esModule",{value:!0}),b[Symbol.toStringTag]="Module",b}({});
//# sourceMappingURL=main.iife.js.map
{
"name": "@netless/app-embedded-page-sdk",
"version": "0.1.0",
"version": "0.1.1",
"main": "dist/main.cjs.js",
"module": "dist/main.es.js",
"types": "src/index.ts",
"devDependencies": {
"@netless/app-embedded-page": "0.1.0",
"@netless/app-shared": "0.1.2",
"side-effect-manager": "^0.1.5"
},
"scripts": {

@@ -13,7 +18,3 @@ "types": "cross-env NODE_ENV=production tsc --declaration --emitDeclarationOnly --outDir dist",

},
"devDependencies": {
"@netless/app-embedded-page": "workspace:*",
"@netless/app-shared": "workspace:*",
"side-effect-manager": "^0.1.5"
}
}
"readme": "## @netless/app-embedded-page-sdk\n\nSDK for storing shared replayable states and sending/receiving replayable events inside [`@netless/app-embedded-page`](https://github.com/netless-io/netless-app/tree/master/packages/app-embedded-page).\n\n[中文](./README-zh.md)\n\n### Install\n\n```bash\nnpm add @netless/app-embedded-page-sdk\n```\n\n### Example\n\n[More examples here](https://github.com/netless-io/netless-app/blob/master/packages/app-embedded-page).\n\n```ts\nimport { createEmbeddedApp } from \"@netless/app-embedded-page-sdk\";\n\ninterface State {\n count: number;\n}\n\ntype Message = {\n type: \"click\";\n payload: { id: string };\n};\n\nconst app = await createEmbeddedApp<State, Message>();\n\napp.ensureState({ count: 0 });\n\napp.state; // => { count: 0 }\napp.setState({ count: 2 });\napp.onStateChanged.addListener(diff => {\n if (diff.count) {\n // count: 0 -> 2\n console.log(\"count:\", diff.count.oldValue, \"->\", diff.count.newValue);\n console.log(diff.count.newValue === app.state.count);\n }\n});\n\napp.sendMessage({ type: \"click\", payload: { id: \"item1\" } });\napp.onMessage.addListener(({ type, payload }) => {\n if (type === \"click\") {\n click(payload.id);\n }\n});\n```\n\n### API\n\n- **createEmbeddedApp()**\n\n Creates an embedded app instance.\n\n Returns: `Promise<EmbeddedApp<State, Message>>`\n\n ```js\n const app = await createEmbeddedApp();\n ```\n\n- **app.appId**\n\n Type: `string`\n\n App ID. Each app is assigned with a unique ID on creation and will keep the same ID until destroyed.\n\n- **app.state**\n\n Type: `State`\\\n Default: `initialState`\n\n The synchronized state across all clients. To change it, call `app.setState()`.\n\n- **app.page**\n\n Type: `string | undefined`\n\n Current whiteboard scene. It works only if `scenePath` has been set when calling `addApp`.\n To switch between pages, call `app.setPage()`\n\n- **app.isWritable**\n\n Type: `boolean`\n\n When it is `false`, calling `app.setState()`, `app.setPage()`, `app.sendMessage()` has no effect.\n\n- **app.meta**\n\n Type: `{ sessionUID: number; uid: string; roomUUID?: string; userPayload: unknown }`\n\n Room information, including\n\n - `sessionUID`: a unique number of current session. will change after refreshing.\n - `uid`: a unique id of current user passed in when calling `joinRoom()`.\n - `roomUUID`: current room's UUID.\n - `userPayload`: the object passed in when calling `joinRoom()`.\n\n- **app.roomMembers**\n\n Type: `ReadonlyArray<{ sessionUID: number; uid: string; userPayload: unknown }>`\n\n All members in the room.\n\n - `sessionUID`: a unique number of current session. will change after refreshing.\n - `uid`: a unique id of current user passed in when calling `joinRoom()`.\n - `userPayload`: the object passed in when calling `joinRoom()`.\n\n- **app.ensureState(partialState)**\n\n Make sure `app.state` has some initial values, work as if:\n\n ```js\n // this code won't work because app.state is readonly\n app.state = { ...partialState, ...app.state };\n ```\n\n **partialState**\n\n Type: `Partial<State>`\n\n ```js\n app.state; // { a: 1 }\n app.ensureState({ a: 0, b: 0 });\n app.state; // { a: 1, b: 0 }\n ```\n\n- **app.setState(partialState)**\n\n Works like React's `setState`, it updates `app.state` and synchronize it to other clients.\n\n When some field's value is `undefined`, it will be removed from `app.state`.\n\n > **Important:** Do not rely on the order of state changes:\n >\n > - `app.setState()` alters `app.state` synchronously but `onStateChanged` will wait until the data is successfully synced.\n > - State syncing time span varies due to network status and data size. It is recommended to store only necessary data in the store.\n\n **partialState**\n\n Type: `Partial<State>`\n\n ```js\n app.state; //=> { count: 0, a: 1 }\n app.setState({ count: app.state.count + 1, a: undefined, b: 2 });\n app.state; //=> { count: 1, b: 2 }\n ```\n\n- **app.setPage(page)**\n\n Change the whiteboard scene on top of your page.\n\n **page**\n\n Type: `string`\n\n > **Important:** This argument must not include `/`.\n\n ```js\n app.setPage(\"1\");\n ```\n\n- **app.sendMessage(message)**\n\n Broadcast a message to other clients.\n\n **message**\n\n Type: anything that can be serialized in JSON.\n\n ```js\n app.sendMessage(\"hello, world!\");\n ```\n\n- **app.moveCamera(partialCameraState)**\n\n Change the whiteboard scene's position on top of your page.\n\n **partialCameraState**\n\n Type: `Partial<{ x: number, y: number, scale: number }>`\n\n The default camera state is `{ x: 0, y: 0, scale: 1 }`, at the center of your page.\n\n ```js\n app.moveCamera({ scale: 0.5 });\n ```\n\n- **app.onStateChanged**\n\n It fires after someone called `app.setState()` (including the app itself).\n\n Type: `Emitter<{ [key: string]: { oldValue?, newValue? } }>`\n\n ```js\n app.onStateChanged.addListener(diff => {\n console.log(\"state changed\", app.state);\n });\n ```\n\n- **app.onPageChanged**\n\n It fires after someone called `app.setPage()` (including the app itself).\n\n Type: `Emitter<{ oldValue?: string, newValue?: string }>`\n\n ```js\n app.onPageChanged.addListener(diff => {\n console.log(\"switch page to\", app.page);\n });\n ```\n\n- **app.onWritableChanged**\n\n It fires when app writable state changes.\n\n Type: `Emitter<{ oldValue?: boolean, newValue?: boolean }>`\n\n ```js\n app.onWritableChanged.addListener(diff => {\n console.log(\"my writable becomes\", app.isWritable);\n });\n ```\n\n- **app.onRoomMembersChanged**\n\n It fires when room members changes.\n\n Type: `Emitter<{ oldValue?: RoomMember[], newValue?: RoomMember[] }>`\n\n ```ts\n interface RoomMember {\n sessionUID: number;\n uid: string;\n userPayload: unknown;\n }\n ```\n\n ```js\n app.onRoomMembersChanged.addListener(diff => {\n console.log(\"room members changed\", app.roomMembers);\n });\n ```\n\n- **app.onMessage**\n\n It fires when receiving messages from other clients (when other clients called `app.sendMessage()`).\n\n > **Note:** Won't receive `app.sendMessage()` messages sent by itself.\n\n Type: `Emitter<any>`\n\n ```js\n app.onMessage.addListener(message => {\n console.log(\"received message\", message);\n });\n ```\n\n### Licence\n\nMIT @ [netless](https://github.com/netless-io)\n"
}

@@ -51,8 +51,2 @@ ## @netless/app-embedded-page-sdk

- **app.appId**
类型: `string`
App ID. 每个 App 在创建的时候会分配一个独立的 ID 并保持不变直到 App 被销毁。
- **createEmbeddedApp()**

@@ -68,2 +62,8 @@

- **app.appId**
类型: `string`
App ID. 每个 App 在创建的时候会分配一个独立的 ID 并保持不变直到 App 被销毁。
- **app.state**

@@ -70,0 +70,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc