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

@netless/app-iframe-bridge

Package Overview
Dependencies
Maintainers
10
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netless/app-iframe-bridge - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

dist/hardcode.d.ts

4

dist/main.cjs.js

@@ -1,3 +0,3 @@

"use strict";var ee=Object.defineProperty,te=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var H=Object.getOwnPropertySymbols;var se=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var J=(t,e,r)=>e in t?ee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,D=(t,e)=>{for(var r in e||(e={}))se.call(e,r)&&J(t,r,e[r]);if(H)for(var r of H(e))ie.call(e,r)&&J(t,r,e[r]);return t},K=(t,e)=>te(t,re(e));Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";class ne{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,s,i,n=this.genDisposerID()){return this.add(()=>(e.addEventListener(r,s,i),()=>e.removeEventListener(r,s,i)),n),n}setTimeout(e,r,s=this.genDisposerID()){return this.add(()=>{const i=window.setTimeout(()=>{this.remove(s),e()},r);return()=>window.clearTimeout(i)},s)}setInterval(e,r,s=this.genDisposerID()){return this.add(()=>{const i=window.setInterval(e,r);return()=>window.clearInterval(i)},s)}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(s){console.error(s)}}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}`}}function oe(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function ae(t,e){let r=t.getAttributes();if(r||(t.setAttributes(e),r=t.getAttributes()),!r)throw new Error("[NetlessAppMonaco] No attributes");return oe(e)&&Object.keys(e).forEach(s=>{Object.prototype.hasOwnProperty.call(r,s)||t.updateAttributes([s],e[s])}),r}const p=new WeakMap,P=new WeakMap,S=new WeakMap,L=Symbol("anyProducer"),F=Promise.resolve(),k=Symbol("listenerAdded"),v=Symbol("listenerRemoved");let O=!1;function m(t){if(typeof t!="string"&&typeof t!="symbol")throw new TypeError("eventName must be a string or a symbol")}function C(t){if(typeof t!="function")throw new TypeError("listener must be a function")}function w(t,e){const r=P.get(t);return r.has(e)||r.set(e,new Set),r.get(e)}function A(t,e){const r=typeof e=="string"||typeof e=="symbol"?e:L,s=S.get(t);return s.has(r)||s.set(r,new Set),s.get(r)}function de(t,e,r){const s=S.get(t);if(s.has(e))for(const i of s.get(e))i.enqueue(r);if(s.has(L)){const i=Promise.all([e,r]);for(const n of s.get(L))n.enqueue(i)}}function V(t,e){e=Array.isArray(e)?e:[e];let r=!1,s=()=>{},i=[];const n={enqueue(d){i.push(d),s()},finish(){r=!0,s()}};for(const d of e)A(t,d).add(n);return{async next(){return i?i.length===0?r?(i=void 0,this.next()):(await new Promise(d=>{s=d}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(d){i=void 0;for(const o of e)A(t,o).delete(n);return s(),arguments.length>0?{done:!0,value:await d}:{done:!0}},[Symbol.asyncIterator](){return this}}}function _(t){if(t===void 0)return X;if(!Array.isArray(t))throw new TypeError("`methodNames` must be an array of strings");for(const e of t)if(!X.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return t}const T=t=>t===k||t===v;class b{static mixin(e,r){return r=_(r),s=>{if(typeof s!="function")throw new TypeError("`target` must be function");for(const d of r)if(s.prototype[d]!==void 0)throw new Error(`The property \`${d}\` already exists on \`target\``);function i(){return Object.defineProperty(this,e,{enumerable:!1,value:new b}),this[e]}Object.defineProperty(s.prototype,e,{enumerable:!1,get:i});const n=d=>function(...o){return this[e][d](...o)};for(const d of r)Object.defineProperty(s.prototype,d,{enumerable:!1,value:n(d)});return s}}static get isDebugEnabled(){if(typeof process!="object")return O;const{env:e}=process||{env:{}};return e.DEBUG==="emittery"||e.DEBUG==="*"||O}static set isDebugEnabled(e){O=e}constructor(e={}){p.set(this,new Set),P.set(this,new Map),S.set(this,new Map),this.debug=e.debug||{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(r,s,i,n)=>{n=JSON.stringify(n),typeof i=="symbol"&&(i=i.toString());const d=new Date,o=`${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;console.log(`[${o}][emittery:${r}][${s}] Event Name: ${i}
data: ${n}`)})}logIfDebugEnabled(e,r,s){(b.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,r,s)}on(e,r){C(r),e=Array.isArray(e)?e:[e];for(const s of e)m(s),w(this,s).add(r),this.logIfDebugEnabled("subscribe",s,void 0),T(s)||this.emit(k,{eventName:s,listener:r});return this.off.bind(this,e,r)}off(e,r){C(r),e=Array.isArray(e)?e:[e];for(const s of e)m(s),w(this,s).delete(r),this.logIfDebugEnabled("unsubscribe",s,void 0),T(s)||this.emit(v,{eventName:s,listener:r})}once(e){return new Promise(r=>{const s=this.on(e,i=>{s(),r(i)})})}events(e){e=Array.isArray(e)?e:[e];for(const r of e)m(r);return V(this,e)}async emit(e,r){m(e),this.logIfDebugEnabled("emit",e,r),de(this,e,r);const s=w(this,e),i=p.get(this),n=[...s],d=T(e)?[]:[...i];await F,await Promise.all([...n.map(async o=>{if(s.has(o))return o(r)}),...d.map(async o=>{if(i.has(o))return o(e,r)})])}async emitSerial(e,r){m(e),this.logIfDebugEnabled("emitSerial",e,r);const s=w(this,e),i=p.get(this),n=[...s],d=[...i];await F;for(const o of n)s.has(o)&&await o(r);for(const o of d)i.has(o)&&await o(e,r)}onAny(e){return C(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),p.get(this).add(e),this.emit(k,{listener:e}),this.offAny.bind(this,e)}anyEvent(){return V(this)}offAny(e){C(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),this.emit(v,{listener:e}),p.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const r of e)if(this.logIfDebugEnabled("clear",r,void 0),typeof r=="string"||typeof r=="symbol"){w(this,r).clear();const s=A(this,r);for(const i of s)i.finish();s.clear()}else{p.get(this).clear();for(const s of P.get(this).values())s.clear();for(const s of S.get(this).values()){for(const i of s)i.finish();s.clear()}}}listenerCount(e){e=Array.isArray(e)?e:[e];let r=0;for(const s of e){if(typeof s=="string"){r+=p.get(this).size+w(this,s).size+A(this,s).size+A(this).size;continue}typeof s!="undefined"&&m(s),r+=p.get(this).size;for(const i of P.get(this).values())r+=i.size;for(const i of S.get(this).values())r+=i.size}return r}bindMethods(e,r){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");r=_(r);for(const s of r){if(e[s]!==void 0)throw new Error(`The property \`${s}\` already exists on \`target\``);Object.defineProperty(e,s,{enumerable:!1,value:this[s].bind(this)})}}}const X=Object.getOwnPropertyNames(b.prototype).filter(t=>t!=="constructor");Object.defineProperty(b,"listenerAdded",{value:k,writable:!1,enumerable:!0,configurable:!1});Object.defineProperty(b,"listenerRemoved",{value:v,writable:!1,enumerable:!0,configurable:!1});var ce=b;function Q(t,e,r){return{sceneState:{sceneName:`${t}`,scenePath:`${r}/${t}`,contextPath:r,scenes:Y(e),index:t-1}}}function Y(t){const e=[];for(let r=1;r<=t;++r)e.push({name:String(r)});return e}function ue(t){return Math.max(1,t-1)}function le(t,e){return Math.min(e,t+1)}var l;(function(t){t.Init="Init",t.AttributesUpdate="AttributesUpdate",t.SetAttributes="SetAttributes",t.RegisterMagixEvent="RegisterMagixEvent",t.RemoveMagixEvent="RemoveMagixEvent",t.RemoveAllMagixEvent="RemoveAllMagixEvent",t.RoomStateChanged="RoomStateChanged",t.DispatchMagixEvent="DispatchMagixEvent",t.ReceiveMagixEvent="ReciveMagixEvent",t.NextPage="NextPage",t.PrevPage="PrevPage",t.SDKCreate="SDKCreate",t.OnCreate="OnCreate",t.SetPage="SetPage",t.GetAttributes="GetAttributes",t.Ready="Ready",t.Destroy="Destory",t.StartCreate="StartCreate",t.WrapperDidUpdate="WrapperDidUpdate",t.DisplayIframe="DisplayIframe",t.HideIframe="HideIframe",t.PageTo="PageTo"})(l||(l={}));var j;(function(t){t.WrapperDidMount="WrapperDidMount",t.IframeLoad="IframeLoad"})(j||(j={}));const fe=new Set(["clicker","selector"]),ge={kind:"IframeBridge",setup(t){const e=t.getBox(),r=t.getView(),s=t.getDisplayer(),i=t.getRoom(),n=ae(t,{src:"about:blank",displaySceneDir:"/h5",lastEvent:null,state:{},page:0,maxPage:0}),d=document.createElement("div");Object.assign(d.style,{width:"100%",height:"100%",position:"relative"});const o=document.createElement("iframe");Object.assign(o.style,{width:"100%",height:"100%",border:"none",display:"block"}),d.appendChild(o),e.mountContent(d);let I=()=>{};const $=c=>fe.has(c);if(r){const c=document.createElement("div");Object.assign(c.style,{width:"100%",height:"100%",position:"absolute",top:0,left:0}),d.appendChild(c),t.mountView(c),I=u=>{c.style.pointerEvents=u?"none":"auto"},I($(i==null?void 0:i.state.memberState.currentApplianceName))}const R=c=>K(D({},c),{url:n.src,displaySceneDir:n.displaySceneDir,width:o.scrollWidth,height:o.scrollHeight,useClicker:!0,lastEvent:n.lastEvent}),f=new ne,y=new ce,E=new Map,x=()=>{E.forEach((c,u)=>{s.removeMagixEventListener(u,c)}),E.clear()},W=(...c)=>!1,g=c=>{var u;W("[IframeBridge] postMessage %s %O",c.kind,c.payload),(u=o.contentWindow)==null||u.postMessage(JSON.parse(JSON.stringify(c)),"*")},M=(c,u)=>{t.getIsWritable()&&(t.updateAttributes(["lastEvent"],{name:c,payload:u}),i==null||i.dispatchMagixEvent(c,u))},G=()=>{g({kind:l.Init,payload:{attributes:R(n.state),roomState:s.state,currentPage:n.page,observerId:s.observerId}})};let B=n.src.includes("cocos");const U=c=>{G(),y.emit(j.IframeLoad,c),y.on(l.Ready,()=>{var u,a;((u=n.lastEvent)==null?void 0:u.payload)&&g((a=n.lastEvent)==null?void 0:a.payload)}),B&&(setTimeout(()=>{g({kind:l.RoomStateChanged,payload:Q(1,n.maxPage,n.displaySceneDir)})},500),B=!1),o.removeEventListener("load",U)};f.addEventListener(o,"load",U);let Z=0;const N=()=>{Z++<3&&(o.src=n.src)};f.addEventListener(o,"error",N),o.src=n.src,f.add(()=>t.mobxUtils.autorun(()=>{g({kind:l.AttributesUpdate,payload:R(n.state)})})),f.add(()=>t.mobxUtils.autorun(()=>{o.src=n.src})),f.add(()=>t.mobxUtils.autorun(()=>{g({kind:l.RoomStateChanged,payload:Q(n.page,n.maxPage,n.displaySceneDir)})}));const z={emitter:y,postMessage:g,context:t};return y.emit(l.StartCreate),y.emit(l.OnCreate,z),i&&f.add(()=>{const c=u=>{u.memberState&&I($(u.memberState.currentApplianceName))};return i.callbacks.on("onRoomStateChanged",c),()=>i.callbacks.off("onRoomStateChanged",c)}),f.addEventListener(window,"message",c=>{if(c.source!==o.contentWindow)return;const u=c.data;switch(W("[IframeBridge] received",u.kind,u.payload),u.kind){case l.SetAttributes:{t.updateAttributes(["state"],D(D({},n.state),u.payload));break}case l.RegisterMagixEvent:{const a=q=>{q.authorId!==s.observerId&&g({kind:l.ReceiveMagixEvent,payload:q})},h=u.payload;E.set(h,a),s.addMagixEventListener(h,a);break}case l.RemoveMagixEvent:{const a=u.payload,h=E.get(a);s.removeMagixEventListener(a,h);break}case l.DispatchMagixEvent:{const a=u.payload;M(a.event,a.payload);break}case l.RemoveAllMagixEvent:{x();break}case l.NextPage:{if(t.getIsWritable()&&i){const a=le(n.page,n.maxPage);if(a===n.page)break;t.setScenePath([n.displaySceneDir,a].join("/")),t.updateAttributes(["page"],a),M(l.NextPage,{})}break}case l.PrevPage:{if(t.getIsWritable()&&i){const a=ue(n.page);if(a===n.page)break;t.setScenePath([n.displaySceneDir,a].join("/")),t.updateAttributes(["page"],a),M(l.PrevPage,{})}break}case l.SetPage:{const a=Number(u.payload)||0;if(t.getIsWritable()&&i)if(!a)i.removeScenes(n.displaySceneDir);else{const h=i.entireScenes()[n.displaySceneDir];(!h||h.length!==a)&&(i.removeScenes(n.displaySceneDir),i.putScenes(n.displaySceneDir,Y(a))),t.setScenePath(`${n.displaySceneDir}/1`),t.updateAttributes(["maxPage"],a)}break}case l.PageTo:{const a=u.payload;if(t.getIsWritable()&&i){if(!Number.isSafeInteger(a)||a<=0)break;t.setScenePath(`${n.displaySceneDir}/${a}`),t.updateAttributes(["page"],a),M(l.PageTo,a-1)}break}case l.SDKCreate:{G();break}case l.GetAttributes:{g({kind:l.GetAttributes,payload:R(n.state)});break}default:console.warn(`[IframeBridge]: unknown event kind "${u.kind}"`)}}),t.emitter.on("destroy",()=>{console.log("[IframeBridge]: destroy"),y.emit(l.Destroy),f.flushAll(),x(),o.remove()}),z}};exports.default=ge;
"use strict";var ee=Object.defineProperty,te=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var H=Object.getOwnPropertySymbols;var se=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var J=(t,e,r)=>e in t?ee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,P=(t,e)=>{for(var r in e||(e={}))se.call(e,r)&&J(t,r,e[r]);if(H)for(var r of H(e))ie.call(e,r)&&J(t,r,e[r]);return t},K=(t,e)=>te(t,re(e));Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";class ne{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,s,i,n=this.genDisposerID()){return this.add(()=>(e.addEventListener(r,s,i),()=>e.removeEventListener(r,s,i)),n),n}setTimeout(e,r,s=this.genDisposerID()){return this.add(()=>{const i=window.setTimeout(()=>{this.remove(s),e()},r);return()=>window.clearTimeout(i)},s)}setInterval(e,r,s=this.genDisposerID()){return this.add(()=>{const i=window.setInterval(e,r);return()=>window.clearInterval(i)},s)}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(s){console.error(s)}}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}`}}function oe(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function ae(t,e){let r=t.getAttributes();if(r||(t.setAttributes(e),r=t.getAttributes()),!r)throw new Error("[NetlessAppMonaco] No attributes");return oe(e)&&Object.keys(e).forEach(s=>{Object.prototype.hasOwnProperty.call(r,s)||t.updateAttributes([s],e[s])}),r}const h=new WeakMap,v=new WeakMap,S=new WeakMap,T=Symbol("anyProducer"),F=Promise.resolve(),k=Symbol("listenerAdded"),C=Symbol("listenerRemoved");let L=!1;function m(t){if(typeof t!="string"&&typeof t!="symbol")throw new TypeError("eventName must be a string or a symbol")}function R(t){if(typeof t!="function")throw new TypeError("listener must be a function")}function w(t,e){const r=v.get(t);return r.has(e)||r.set(e,new Set),r.get(e)}function A(t,e){const r=typeof e=="string"||typeof e=="symbol"?e:T,s=S.get(t);return s.has(r)||s.set(r,new Set),s.get(r)}function de(t,e,r){const s=S.get(t);if(s.has(e))for(const i of s.get(e))i.enqueue(r);if(s.has(T)){const i=Promise.all([e,r]);for(const n of s.get(T))n.enqueue(i)}}function V(t,e){e=Array.isArray(e)?e:[e];let r=!1,s=()=>{},i=[];const n={enqueue(o){i.push(o),s()},finish(){r=!0,s()}};for(const o of e)A(t,o).add(n);return{async next(){return i?i.length===0?r?(i=void 0,this.next()):(await new Promise(o=>{s=o}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(o){i=void 0;for(const l of e)A(t,l).delete(n);return s(),arguments.length>0?{done:!0,value:await o}:{done:!0}},[Symbol.asyncIterator](){return this}}}function _(t){if(t===void 0)return X;if(!Array.isArray(t))throw new TypeError("`methodNames` must be an array of strings");for(const e of t)if(!X.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return t}const j=t=>t===k||t===C;class b{static mixin(e,r){return r=_(r),s=>{if(typeof s!="function")throw new TypeError("`target` must be function");for(const o of r)if(s.prototype[o]!==void 0)throw new Error(`The property \`${o}\` already exists on \`target\``);function i(){return Object.defineProperty(this,e,{enumerable:!1,value:new b}),this[e]}Object.defineProperty(s.prototype,e,{enumerable:!1,get:i});const n=o=>function(...l){return this[e][o](...l)};for(const o of r)Object.defineProperty(s.prototype,o,{enumerable:!1,value:n(o)});return s}}static get isDebugEnabled(){if(typeof process!="object")return L;const{env:e}=process||{env:{}};return e.DEBUG==="emittery"||e.DEBUG==="*"||L}static set isDebugEnabled(e){L=e}constructor(e={}){h.set(this,new Set),v.set(this,new Map),S.set(this,new Map),this.debug=e.debug||{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(r,s,i,n)=>{n=JSON.stringify(n),typeof i=="symbol"&&(i=i.toString());const o=new Date,l=`${o.getHours()}:${o.getMinutes()}:${o.getSeconds()}.${o.getMilliseconds()}`;console.log(`[${l}][emittery:${r}][${s}] Event Name: ${i}
data: ${n}`)})}logIfDebugEnabled(e,r,s){(b.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,r,s)}on(e,r){R(r),e=Array.isArray(e)?e:[e];for(const s of e)m(s),w(this,s).add(r),this.logIfDebugEnabled("subscribe",s,void 0),j(s)||this.emit(k,{eventName:s,listener:r});return this.off.bind(this,e,r)}off(e,r){R(r),e=Array.isArray(e)?e:[e];for(const s of e)m(s),w(this,s).delete(r),this.logIfDebugEnabled("unsubscribe",s,void 0),j(s)||this.emit(C,{eventName:s,listener:r})}once(e){return new Promise(r=>{const s=this.on(e,i=>{s(),r(i)})})}events(e){e=Array.isArray(e)?e:[e];for(const r of e)m(r);return V(this,e)}async emit(e,r){m(e),this.logIfDebugEnabled("emit",e,r),de(this,e,r);const s=w(this,e),i=h.get(this),n=[...s],o=j(e)?[]:[...i];await F,await Promise.all([...n.map(async l=>{if(s.has(l))return l(r)}),...o.map(async l=>{if(i.has(l))return l(e,r)})])}async emitSerial(e,r){m(e),this.logIfDebugEnabled("emitSerial",e,r);const s=w(this,e),i=h.get(this),n=[...s],o=[...i];await F;for(const l of n)s.has(l)&&await l(r);for(const l of o)i.has(l)&&await l(e,r)}onAny(e){return R(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),h.get(this).add(e),this.emit(k,{listener:e}),this.offAny.bind(this,e)}anyEvent(){return V(this)}offAny(e){R(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),this.emit(C,{listener:e}),h.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const r of e)if(this.logIfDebugEnabled("clear",r,void 0),typeof r=="string"||typeof r=="symbol"){w(this,r).clear();const s=A(this,r);for(const i of s)i.finish();s.clear()}else{h.get(this).clear();for(const s of v.get(this).values())s.clear();for(const s of S.get(this).values()){for(const i of s)i.finish();s.clear()}}}listenerCount(e){e=Array.isArray(e)?e:[e];let r=0;for(const s of e){if(typeof s=="string"){r+=h.get(this).size+w(this,s).size+A(this,s).size+A(this).size;continue}typeof s!="undefined"&&m(s),r+=h.get(this).size;for(const i of v.get(this).values())r+=i.size;for(const i of S.get(this).values())r+=i.size}return r}bindMethods(e,r){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");r=_(r);for(const s of r){if(e[s]!==void 0)throw new Error(`The property \`${s}\` already exists on \`target\``);Object.defineProperty(e,s,{enumerable:!1,value:this[s].bind(this)})}}}const X=Object.getOwnPropertyNames(b.prototype).filter(t=>t!=="constructor");Object.defineProperty(b,"listenerAdded",{value:k,writable:!1,enumerable:!0,configurable:!1});Object.defineProperty(b,"listenerRemoved",{value:C,writable:!1,enumerable:!0,configurable:!1});var ce=b;function Q(t,e,r){return{sceneState:{sceneName:`${t}`,scenePath:`${r}/${t}`,contextPath:r,scenes:Y(e),index:t-1}}}function Y(t){const e=[];for(let r=1;r<=t;++r)e.push({name:String(r)});return e}function ue(t){return Math.max(1,t-1)}function le(t,e){return Math.min(e,t+1)}const fe=350;var u;(function(t){t.Init="Init",t.AttributesUpdate="AttributesUpdate",t.SetAttributes="SetAttributes",t.RegisterMagixEvent="RegisterMagixEvent",t.RemoveMagixEvent="RemoveMagixEvent",t.RemoveAllMagixEvent="RemoveAllMagixEvent",t.RoomStateChanged="RoomStateChanged",t.DispatchMagixEvent="DispatchMagixEvent",t.ReceiveMagixEvent="ReciveMagixEvent",t.NextPage="NextPage",t.PrevPage="PrevPage",t.SDKCreate="SDKCreate",t.OnCreate="OnCreate",t.SetPage="SetPage",t.GetAttributes="GetAttributes",t.Ready="Ready",t.Destroy="Destory",t.StartCreate="StartCreate",t.WrapperDidUpdate="WrapperDidUpdate",t.DisplayIframe="DisplayIframe",t.HideIframe="HideIframe",t.PageTo="PageTo"})(u||(u={}));var $;(function(t){t.WrapperDidMount="WrapperDidMount",t.IframeLoad="IframeLoad"})($||($={}));const ge=new Set(["clicker","selector"]),pe={kind:"IframeBridge",setup(t){const e=t.getBox(),r=t.getView(),s=t.getDisplayer(),i=t.getRoom(),n=ae(t,{src:"about:blank",displaySceneDir:"/h5",lastEvent:null,state:{},page:0,maxPage:0}),o=new ne,l=document.createElement("div");Object.assign(l.style,{width:"100%",height:"100%",position:"relative"});const f=document.createElement("iframe");Object.assign(f.style,{width:"100%",height:"100%",border:"none",display:"block"}),l.appendChild(f),e.mountContent(l);let I=()=>{};const x=c=>ge.has(c);if(r){const c=document.createElement("div");Object.assign(c.style,{width:"100%",height:"100%",position:"absolute",top:0,left:0}),l.appendChild(c),t.mountView(c),r.disableCameraTransform=!0,o.add(()=>{const d=()=>{const D=l.getBoundingClientRect().height/fe;r.moveCamera({scale:D,animationMode:"immediately"})},a=new ResizeObserver(d);return a.observe(l),()=>a.disconnect()}),I=d=>{c.style.pointerEvents=d?"none":"auto"},I(x(i==null?void 0:i.state.memberState.currentApplianceName))}const O=c=>K(P({},c),{url:n.src,displaySceneDir:n.displaySceneDir,width:f.scrollWidth,height:f.scrollHeight,useClicker:!0,lastEvent:n.lastEvent}),y=new ce,E=new Map,W=()=>{E.forEach((c,d)=>{s.removeMagixEventListener(d,c)}),E.clear()},G=(...c)=>!1,g=c=>{var d;G("[IframeBridge] postMessage %s %O",c.kind,c.payload),(d=f.contentWindow)==null||d.postMessage(JSON.parse(JSON.stringify(c)),"*")},M=(c,d)=>{t.getIsWritable()&&(t.updateAttributes(["lastEvent"],{name:c,payload:d}),i==null||i.dispatchMagixEvent(c,d))},B=()=>{g({kind:u.Init,payload:{attributes:O(n.state),roomState:s.state,currentPage:n.page,observerId:s.observerId}})};let U=n.src.includes("cocos");const z=c=>{B(),y.emit($.IframeLoad,c),y.on(u.Ready,()=>{var d,a;((d=n.lastEvent)==null?void 0:d.payload)&&g((a=n.lastEvent)==null?void 0:a.payload)}),U&&(setTimeout(()=>{g({kind:u.RoomStateChanged,payload:Q(1,n.maxPage,n.displaySceneDir)})},500),U=!1),f.removeEventListener("load",z)};o.addEventListener(f,"load",z);let Z=0;const N=()=>{Z++<3&&(f.src=n.src)};o.addEventListener(f,"error",N),f.src=n.src,o.add(()=>t.mobxUtils.autorun(()=>{g({kind:u.AttributesUpdate,payload:O(n.state)})})),o.add(()=>t.mobxUtils.autorun(()=>{f.src=n.src})),o.add(()=>t.mobxUtils.autorun(()=>{g({kind:u.RoomStateChanged,payload:Q(n.page,n.maxPage,n.displaySceneDir)})}));const q={emitter:y,postMessage:g,context:t};return y.emit(u.StartCreate),y.emit(u.OnCreate,q),i&&o.add(()=>{const c=d=>{d.memberState&&I(x(d.memberState.currentApplianceName))};return i.callbacks.on("onRoomStateChanged",c),()=>i.callbacks.off("onRoomStateChanged",c)}),o.addEventListener(window,"message",c=>{if(c.source!==f.contentWindow)return;const d=c.data;switch(G("[IframeBridge] received",d.kind,d.payload),d.kind){case u.SetAttributes:{t.updateAttributes(["state"],P(P({},n.state),d.payload));break}case u.RegisterMagixEvent:{const a=D=>{D.authorId!==s.observerId&&g({kind:u.ReceiveMagixEvent,payload:D})},p=d.payload;E.set(p,a),s.addMagixEventListener(p,a);break}case u.RemoveMagixEvent:{const a=d.payload,p=E.get(a);s.removeMagixEventListener(a,p);break}case u.DispatchMagixEvent:{const a=d.payload;M(a.event,a.payload);break}case u.RemoveAllMagixEvent:{W();break}case u.NextPage:{if(t.getIsWritable()&&i){const a=le(n.page,n.maxPage);if(a===n.page)break;t.setScenePath([n.displaySceneDir,a].join("/")),t.updateAttributes(["page"],a),M(u.NextPage,{})}break}case u.PrevPage:{if(t.getIsWritable()&&i){const a=ue(n.page);if(a===n.page)break;t.setScenePath([n.displaySceneDir,a].join("/")),t.updateAttributes(["page"],a),M(u.PrevPage,{})}break}case u.SetPage:{const a=Number(d.payload)||0;if(t.getIsWritable()&&i)if(!a)i.removeScenes(n.displaySceneDir);else{const p=i.entireScenes()[n.displaySceneDir];(!p||p.length!==a)&&(i.removeScenes(n.displaySceneDir),i.putScenes(n.displaySceneDir,Y(a))),t.setScenePath(`${n.displaySceneDir}/1`),t.updateAttributes(["maxPage"],a)}break}case u.PageTo:{const a=d.payload;if(t.getIsWritable()&&i){if(!Number.isSafeInteger(a)||a<=0)break;t.setScenePath(`${n.displaySceneDir}/${a}`),t.updateAttributes(["page"],a),M(u.PageTo,a-1)}break}case u.SDKCreate:{B();break}case u.GetAttributes:{g({kind:u.GetAttributes,payload:O(n.state)});break}default:console.warn(`[IframeBridge]: unknown event kind "${d.kind}"`)}}),t.emitter.on("destroy",()=>{console.log("[IframeBridge]: destroy"),y.emit(u.Destroy),o.flushAll(),W(),f.remove()}),q}};exports.default=pe;
//# sourceMappingURL=main.cjs.js.map

@@ -477,2 +477,3 @@ var __defProp = Object.defineProperty;

}
const height = 350;
var IframeEvents;

@@ -524,2 +525,3 @@ (function(IframeEvents2) {

});
const sideEffectManager = new s();
const container = document.createElement("div");

@@ -552,2 +554,13 @@ Object.assign(container.style, { width: "100%", height: "100%", position: "relative" });

context.mountView(viewBox);
view.disableCameraTransform = true;
sideEffectManager.add(() => {
const onResize = () => {
const clientRect = container.getBoundingClientRect();
const scale = clientRect.height / height;
view.moveCamera({ scale, animationMode: "immediately" });
};
const observer = new ResizeObserver(onResize);
observer.observe(container);
return () => observer.disconnect();
});
toggleClickThrough = (enable) => {

@@ -566,3 +579,2 @@ viewBox.style.pointerEvents = enable ? "none" : "auto";

});
const sideEffectManager = new s();
const emitter = new emittery();

@@ -569,0 +581,0 @@ const magixEventMap = new Map();

@@ -1,3 +0,3 @@

(()=>{var ue=Object.defineProperty,le=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var N=(f,g,p)=>g in f?ue(f,g,{enumerable:!0,configurable:!0,writable:!0,value:p}):f[g]=p,L=(f,g)=>{for(var p in g||(g={}))ge.call(g,p)&&N(f,p,g[p]);if(Z)for(var p of Z(g))pe.call(g,p)&&N(f,p,g[p]);return f},ee=(f,g)=>le(f,fe(g));var be=function(f){"use strict";class g{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,s,i,n=this.genDisposerID()){return this.add(()=>(e.addEventListener(r,s,i),()=>e.removeEventListener(r,s,i)),n),n}setTimeout(e,r,s=this.genDisposerID()){return this.add(()=>{const i=window.setTimeout(()=>{this.remove(s),e()},r);return()=>window.clearTimeout(i)},s)}setInterval(e,r,s=this.genDisposerID()){return this.add(()=>{const i=window.setInterval(e,r);return()=>window.clearInterval(i)},s)}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(s){console.error(s)}}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}`}}function p(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function te(t,e){let r=t.getAttributes();if(r||(t.setAttributes(e),r=t.getAttributes()),!r)throw new Error("[NetlessAppMonaco] No attributes");return p(e)&&Object.keys(e).forEach(s=>{Object.prototype.hasOwnProperty.call(r,s)||t.updateAttributes([s],e[s])}),r}const h=new WeakMap,P=new WeakMap,M=new WeakMap,O=Symbol("anyProducer"),G=Promise.resolve(),k=Symbol("listenerAdded"),v=Symbol("listenerRemoved");let T=!1;function S(t){if(typeof t!="string"&&typeof t!="symbol")throw new TypeError("eventName must be a string or a symbol")}function C(t){if(typeof t!="function")throw new TypeError("listener must be a function")}function A(t,e){const r=P.get(t);return r.has(e)||r.set(e,new Set),r.get(e)}function D(t,e){const r=typeof e=="string"||typeof e=="symbol"?e:O,s=M.get(t);return s.has(r)||s.set(r,new Set),s.get(r)}function re(t,e,r){const s=M.get(t);if(s.has(e))for(const i of s.get(e))i.enqueue(r);if(s.has(O)){const i=Promise.all([e,r]);for(const n of s.get(O))n.enqueue(i)}}function B(t,e){e=Array.isArray(e)?e:[e];let r=!1,s=()=>{},i=[];const n={enqueue(d){i.push(d),s()},finish(){r=!0,s()}};for(const d of e)D(t,d).add(n);return{async next(){return i?i.length===0?r?(i=void 0,this.next()):(await new Promise(d=>{s=d}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(d){i=void 0;for(const o of e)D(t,o).delete(n);return s(),arguments.length>0?{done:!0,value:await d}:{done:!0}},[Symbol.asyncIterator](){return this}}}function U(t){if(t===void 0)return z;if(!Array.isArray(t))throw new TypeError("`methodNames` must be an array of strings");for(const e of t)if(!z.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return t}const j=t=>t===k||t===v;class m{static mixin(e,r){return r=U(r),s=>{if(typeof s!="function")throw new TypeError("`target` must be function");for(const d of r)if(s.prototype[d]!==void 0)throw new Error(`The property \`${d}\` already exists on \`target\``);function i(){return Object.defineProperty(this,e,{enumerable:!1,value:new m}),this[e]}Object.defineProperty(s.prototype,e,{enumerable:!1,get:i});const n=d=>function(...o){return this[e][d](...o)};for(const d of r)Object.defineProperty(s.prototype,d,{enumerable:!1,value:n(d)});return s}}static get isDebugEnabled(){if(typeof process!="object")return T;const{env:e}=process||{env:{}};return e.DEBUG==="emittery"||e.DEBUG==="*"||T}static set isDebugEnabled(e){T=e}constructor(e={}){h.set(this,new Set),P.set(this,new Map),M.set(this,new Map),this.debug=e.debug||{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(r,s,i,n)=>{n=JSON.stringify(n),typeof i=="symbol"&&(i=i.toString());const d=new Date,o=`${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`;console.log(`[${o}][emittery:${r}][${s}] Event Name: ${i}
data: ${n}`)})}logIfDebugEnabled(e,r,s){(m.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,r,s)}on(e,r){C(r),e=Array.isArray(e)?e:[e];for(const s of e)S(s),A(this,s).add(r),this.logIfDebugEnabled("subscribe",s,void 0),j(s)||this.emit(k,{eventName:s,listener:r});return this.off.bind(this,e,r)}off(e,r){C(r),e=Array.isArray(e)?e:[e];for(const s of e)S(s),A(this,s).delete(r),this.logIfDebugEnabled("unsubscribe",s,void 0),j(s)||this.emit(v,{eventName:s,listener:r})}once(e){return new Promise(r=>{const s=this.on(e,i=>{s(),r(i)})})}events(e){e=Array.isArray(e)?e:[e];for(const r of e)S(r);return B(this,e)}async emit(e,r){S(e),this.logIfDebugEnabled("emit",e,r),re(this,e,r);const s=A(this,e),i=h.get(this),n=[...s],d=j(e)?[]:[...i];await G,await Promise.all([...n.map(async o=>{if(s.has(o))return o(r)}),...d.map(async o=>{if(i.has(o))return o(e,r)})])}async emitSerial(e,r){S(e),this.logIfDebugEnabled("emitSerial",e,r);const s=A(this,e),i=h.get(this),n=[...s],d=[...i];await G;for(const o of n)s.has(o)&&await o(r);for(const o of d)i.has(o)&&await o(e,r)}onAny(e){return C(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),h.get(this).add(e),this.emit(k,{listener:e}),this.offAny.bind(this,e)}anyEvent(){return B(this)}offAny(e){C(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),this.emit(v,{listener:e}),h.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const r of e)if(this.logIfDebugEnabled("clear",r,void 0),typeof r=="string"||typeof r=="symbol"){A(this,r).clear();const s=D(this,r);for(const i of s)i.finish();s.clear()}else{h.get(this).clear();for(const s of P.get(this).values())s.clear();for(const s of M.get(this).values()){for(const i of s)i.finish();s.clear()}}}listenerCount(e){e=Array.isArray(e)?e:[e];let r=0;for(const s of e){if(typeof s=="string"){r+=h.get(this).size+A(this,s).size+D(this,s).size+D(this).size;continue}typeof s!="undefined"&&S(s),r+=h.get(this).size;for(const i of P.get(this).values())r+=i.size;for(const i of M.get(this).values())r+=i.size}return r}bindMethods(e,r){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");r=U(r);for(const s of r){if(e[s]!==void 0)throw new Error(`The property \`${s}\` already exists on \`target\``);Object.defineProperty(e,s,{enumerable:!1,value:this[s].bind(this)})}}}const z=Object.getOwnPropertyNames(m.prototype).filter(t=>t!=="constructor");Object.defineProperty(m,"listenerAdded",{value:k,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(m,"listenerRemoved",{value:v,writable:!1,enumerable:!0,configurable:!1});var se=m;function q(t,e,r){return{sceneState:{sceneName:`${t}`,scenePath:`${r}/${t}`,contextPath:r,scenes:H(e),index:t-1}}}function H(t){const e=[];for(let r=1;r<=t;++r)e.push({name:String(r)});return e}function ie(t){return Math.max(1,t-1)}function ne(t,e){return Math.min(e,t+1)}var c;(function(t){t.Init="Init",t.AttributesUpdate="AttributesUpdate",t.SetAttributes="SetAttributes",t.RegisterMagixEvent="RegisterMagixEvent",t.RemoveMagixEvent="RemoveMagixEvent",t.RemoveAllMagixEvent="RemoveAllMagixEvent",t.RoomStateChanged="RoomStateChanged",t.DispatchMagixEvent="DispatchMagixEvent",t.ReceiveMagixEvent="ReciveMagixEvent",t.NextPage="NextPage",t.PrevPage="PrevPage",t.SDKCreate="SDKCreate",t.OnCreate="OnCreate",t.SetPage="SetPage",t.GetAttributes="GetAttributes",t.Ready="Ready",t.Destroy="Destory",t.StartCreate="StartCreate",t.WrapperDidUpdate="WrapperDidUpdate",t.DisplayIframe="DisplayIframe",t.HideIframe="HideIframe",t.PageTo="PageTo"})(c||(c={}));var $;(function(t){t.WrapperDidMount="WrapperDidMount",t.IframeLoad="IframeLoad"})($||($={}));const oe=new Set(["clicker","selector"]),ae={kind:"IframeBridge",setup(t){const e=t.getBox(),r=t.getView(),s=t.getDisplayer(),i=t.getRoom(),n=te(t,{src:"about:blank",displaySceneDir:"/h5",lastEvent:null,state:{},page:0,maxPage:0}),d=document.createElement("div");Object.assign(d.style,{width:"100%",height:"100%",position:"relative"});const o=document.createElement("iframe");Object.assign(o.style,{width:"100%",height:"100%",border:"none",display:"block"}),d.appendChild(o),e.mountContent(d);let x=()=>{};const J=u=>oe.has(u);if(r){const u=document.createElement("div");Object.assign(u.style,{width:"100%",height:"100%",position:"absolute",top:0,left:0}),d.appendChild(u),t.mountView(u),x=l=>{u.style.pointerEvents=l?"none":"auto"},x(J(i==null?void 0:i.state.memberState.currentApplianceName))}const W=u=>ee(L({},u),{url:n.src,displaySceneDir:n.displaySceneDir,width:o.scrollWidth,height:o.scrollHeight,useClicker:!0,lastEvent:n.lastEvent}),b=new g,E=new se,I=new Map,K=()=>{I.forEach((u,l)=>{s.removeMagixEventListener(l,u)}),I.clear()},F=(...u)=>!1,y=u=>{var l;F("[IframeBridge] postMessage %s %O",u.kind,u.payload),(l=o.contentWindow)==null||l.postMessage(JSON.parse(JSON.stringify(u)),"*")},R=(u,l)=>{t.getIsWritable()&&(t.updateAttributes(["lastEvent"],{name:u,payload:l}),i==null||i.dispatchMagixEvent(u,l))},V=()=>{y({kind:c.Init,payload:{attributes:W(n.state),roomState:s.state,currentPage:n.page,observerId:s.observerId}})};let _=n.src.includes("cocos");const X=u=>{V(),E.emit($.IframeLoad,u),E.on(c.Ready,()=>{var l,a;((l=n.lastEvent)==null?void 0:l.payload)&&y((a=n.lastEvent)==null?void 0:a.payload)}),_&&(setTimeout(()=>{y({kind:c.RoomStateChanged,payload:q(1,n.maxPage,n.displaySceneDir)})},500),_=!1),o.removeEventListener("load",X)};b.addEventListener(o,"load",X);let de=0;const ce=()=>{de++<3&&(o.src=n.src)};b.addEventListener(o,"error",ce),o.src=n.src,b.add(()=>t.mobxUtils.autorun(()=>{y({kind:c.AttributesUpdate,payload:W(n.state)})})),b.add(()=>t.mobxUtils.autorun(()=>{o.src=n.src})),b.add(()=>t.mobxUtils.autorun(()=>{y({kind:c.RoomStateChanged,payload:q(n.page,n.maxPage,n.displaySceneDir)})}));const Q={emitter:E,postMessage:y,context:t};return E.emit(c.StartCreate),E.emit(c.OnCreate,Q),i&&b.add(()=>{const u=l=>{l.memberState&&x(J(l.memberState.currentApplianceName))};return i.callbacks.on("onRoomStateChanged",u),()=>i.callbacks.off("onRoomStateChanged",u)}),b.addEventListener(window,"message",u=>{if(u.source!==o.contentWindow)return;const l=u.data;switch(F("[IframeBridge] received",l.kind,l.payload),l.kind){case c.SetAttributes:{t.updateAttributes(["state"],L(L({},n.state),l.payload));break}case c.RegisterMagixEvent:{const a=Y=>{Y.authorId!==s.observerId&&y({kind:c.ReceiveMagixEvent,payload:Y})},w=l.payload;I.set(w,a),s.addMagixEventListener(w,a);break}case c.RemoveMagixEvent:{const a=l.payload,w=I.get(a);s.removeMagixEventListener(a,w);break}case c.DispatchMagixEvent:{const a=l.payload;R(a.event,a.payload);break}case c.RemoveAllMagixEvent:{K();break}case c.NextPage:{if(t.getIsWritable()&&i){const a=ne(n.page,n.maxPage);if(a===n.page)break;t.setScenePath([n.displaySceneDir,a].join("/")),t.updateAttributes(["page"],a),R(c.NextPage,{})}break}case c.PrevPage:{if(t.getIsWritable()&&i){const a=ie(n.page);if(a===n.page)break;t.setScenePath([n.displaySceneDir,a].join("/")),t.updateAttributes(["page"],a),R(c.PrevPage,{})}break}case c.SetPage:{const a=Number(l.payload)||0;if(t.getIsWritable()&&i)if(!a)i.removeScenes(n.displaySceneDir);else{const w=i.entireScenes()[n.displaySceneDir];(!w||w.length!==a)&&(i.removeScenes(n.displaySceneDir),i.putScenes(n.displaySceneDir,H(a))),t.setScenePath(`${n.displaySceneDir}/1`),t.updateAttributes(["maxPage"],a)}break}case c.PageTo:{const a=l.payload;if(t.getIsWritable()&&i){if(!Number.isSafeInteger(a)||a<=0)break;t.setScenePath(`${n.displaySceneDir}/${a}`),t.updateAttributes(["page"],a),R(c.PageTo,a-1)}break}case c.SDKCreate:{V();break}case c.GetAttributes:{y({kind:c.GetAttributes,payload:W(n.state)});break}default:console.warn(`[IframeBridge]: unknown event kind "${l.kind}"`)}}),t.emitter.on("destroy",()=>{console.log("[IframeBridge]: destroy"),E.emit(c.Destroy),b.flushAll(),K(),o.remove()}),Q}};return f.default=ae,Object.defineProperty(f,"__esModule",{value:!0}),f[Symbol.toStringTag]="Module",f}({});})();
(()=>{var le=Object.defineProperty,fe=Object.defineProperties;var ge=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var pe=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable;var N=(f,g,h)=>g in f?le(f,g,{enumerable:!0,configurable:!0,writable:!0,value:h}):f[g]=h,T=(f,g)=>{for(var h in g||(g={}))pe.call(g,h)&&N(f,h,g[h]);if(Z)for(var h of Z(g))he.call(g,h)&&N(f,h,g[h]);return f},ee=(f,g)=>fe(f,ge(g));var ye=function(f){"use strict";class g{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,s,i,n=this.genDisposerID()){return this.add(()=>(e.addEventListener(r,s,i),()=>e.removeEventListener(r,s,i)),n),n}setTimeout(e,r,s=this.genDisposerID()){return this.add(()=>{const i=window.setTimeout(()=>{this.remove(s),e()},r);return()=>window.clearTimeout(i)},s)}setInterval(e,r,s=this.genDisposerID()){return this.add(()=>{const i=window.setInterval(e,r);return()=>window.clearInterval(i)},s)}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(s){console.error(s)}}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}`}}function h(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function te(t,e){let r=t.getAttributes();if(r||(t.setAttributes(e),r=t.getAttributes()),!r)throw new Error("[NetlessAppMonaco] No attributes");return h(e)&&Object.keys(e).forEach(s=>{Object.prototype.hasOwnProperty.call(r,s)||t.updateAttributes([s],e[s])}),r}const b=new WeakMap,P=new WeakMap,M=new WeakMap,L=Symbol("anyProducer"),G=Promise.resolve(),v=Symbol("listenerAdded"),k=Symbol("listenerRemoved");let j=!1;function S(t){if(typeof t!="string"&&typeof t!="symbol")throw new TypeError("eventName must be a string or a symbol")}function C(t){if(typeof t!="function")throw new TypeError("listener must be a function")}function A(t,e){const r=P.get(t);return r.has(e)||r.set(e,new Set),r.get(e)}function D(t,e){const r=typeof e=="string"||typeof e=="symbol"?e:L,s=M.get(t);return s.has(r)||s.set(r,new Set),s.get(r)}function re(t,e,r){const s=M.get(t);if(s.has(e))for(const i of s.get(e))i.enqueue(r);if(s.has(L)){const i=Promise.all([e,r]);for(const n of s.get(L))n.enqueue(i)}}function U(t,e){e=Array.isArray(e)?e:[e];let r=!1,s=()=>{},i=[];const n={enqueue(o){i.push(o),s()},finish(){r=!0,s()}};for(const o of e)D(t,o).add(n);return{async next(){return i?i.length===0?r?(i=void 0,this.next()):(await new Promise(o=>{s=o}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(o){i=void 0;for(const l of e)D(t,l).delete(n);return s(),arguments.length>0?{done:!0,value:await o}:{done:!0}},[Symbol.asyncIterator](){return this}}}function z(t){if(t===void 0)return q;if(!Array.isArray(t))throw new TypeError("`methodNames` must be an array of strings");for(const e of t)if(!q.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return t}const $=t=>t===v||t===k;class w{static mixin(e,r){return r=z(r),s=>{if(typeof s!="function")throw new TypeError("`target` must be function");for(const o of r)if(s.prototype[o]!==void 0)throw new Error(`The property \`${o}\` already exists on \`target\``);function i(){return Object.defineProperty(this,e,{enumerable:!1,value:new w}),this[e]}Object.defineProperty(s.prototype,e,{enumerable:!1,get:i});const n=o=>function(...l){return this[e][o](...l)};for(const o of r)Object.defineProperty(s.prototype,o,{enumerable:!1,value:n(o)});return s}}static get isDebugEnabled(){if(typeof process!="object")return j;const{env:e}=process||{env:{}};return e.DEBUG==="emittery"||e.DEBUG==="*"||j}static set isDebugEnabled(e){j=e}constructor(e={}){b.set(this,new Set),P.set(this,new Map),M.set(this,new Map),this.debug=e.debug||{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(r,s,i,n)=>{n=JSON.stringify(n),typeof i=="symbol"&&(i=i.toString());const o=new Date,l=`${o.getHours()}:${o.getMinutes()}:${o.getSeconds()}.${o.getMilliseconds()}`;console.log(`[${l}][emittery:${r}][${s}] Event Name: ${i}
data: ${n}`)})}logIfDebugEnabled(e,r,s){(w.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,r,s)}on(e,r){C(r),e=Array.isArray(e)?e:[e];for(const s of e)S(s),A(this,s).add(r),this.logIfDebugEnabled("subscribe",s,void 0),$(s)||this.emit(v,{eventName:s,listener:r});return this.off.bind(this,e,r)}off(e,r){C(r),e=Array.isArray(e)?e:[e];for(const s of e)S(s),A(this,s).delete(r),this.logIfDebugEnabled("unsubscribe",s,void 0),$(s)||this.emit(k,{eventName:s,listener:r})}once(e){return new Promise(r=>{const s=this.on(e,i=>{s(),r(i)})})}events(e){e=Array.isArray(e)?e:[e];for(const r of e)S(r);return U(this,e)}async emit(e,r){S(e),this.logIfDebugEnabled("emit",e,r),re(this,e,r);const s=A(this,e),i=b.get(this),n=[...s],o=$(e)?[]:[...i];await G,await Promise.all([...n.map(async l=>{if(s.has(l))return l(r)}),...o.map(async l=>{if(i.has(l))return l(e,r)})])}async emitSerial(e,r){S(e),this.logIfDebugEnabled("emitSerial",e,r);const s=A(this,e),i=b.get(this),n=[...s],o=[...i];await G;for(const l of n)s.has(l)&&await l(r);for(const l of o)i.has(l)&&await l(e,r)}onAny(e){return C(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),b.get(this).add(e),this.emit(v,{listener:e}),this.offAny.bind(this,e)}anyEvent(){return U(this)}offAny(e){C(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),this.emit(k,{listener:e}),b.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const r of e)if(this.logIfDebugEnabled("clear",r,void 0),typeof r=="string"||typeof r=="symbol"){A(this,r).clear();const s=D(this,r);for(const i of s)i.finish();s.clear()}else{b.get(this).clear();for(const s of P.get(this).values())s.clear();for(const s of M.get(this).values()){for(const i of s)i.finish();s.clear()}}}listenerCount(e){e=Array.isArray(e)?e:[e];let r=0;for(const s of e){if(typeof s=="string"){r+=b.get(this).size+A(this,s).size+D(this,s).size+D(this).size;continue}typeof s!="undefined"&&S(s),r+=b.get(this).size;for(const i of P.get(this).values())r+=i.size;for(const i of M.get(this).values())r+=i.size}return r}bindMethods(e,r){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");r=z(r);for(const s of r){if(e[s]!==void 0)throw new Error(`The property \`${s}\` already exists on \`target\``);Object.defineProperty(e,s,{enumerable:!1,value:this[s].bind(this)})}}}const q=Object.getOwnPropertyNames(w.prototype).filter(t=>t!=="constructor");Object.defineProperty(w,"listenerAdded",{value:v,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(w,"listenerRemoved",{value:k,writable:!1,enumerable:!0,configurable:!1});var se=w;function H(t,e,r){return{sceneState:{sceneName:`${t}`,scenePath:`${r}/${t}`,contextPath:r,scenes:J(e),index:t-1}}}function J(t){const e=[];for(let r=1;r<=t;++r)e.push({name:String(r)});return e}function ie(t){return Math.max(1,t-1)}function ne(t,e){return Math.min(e,t+1)}const oe=350;var c;(function(t){t.Init="Init",t.AttributesUpdate="AttributesUpdate",t.SetAttributes="SetAttributes",t.RegisterMagixEvent="RegisterMagixEvent",t.RemoveMagixEvent="RemoveMagixEvent",t.RemoveAllMagixEvent="RemoveAllMagixEvent",t.RoomStateChanged="RoomStateChanged",t.DispatchMagixEvent="DispatchMagixEvent",t.ReceiveMagixEvent="ReciveMagixEvent",t.NextPage="NextPage",t.PrevPage="PrevPage",t.SDKCreate="SDKCreate",t.OnCreate="OnCreate",t.SetPage="SetPage",t.GetAttributes="GetAttributes",t.Ready="Ready",t.Destroy="Destory",t.StartCreate="StartCreate",t.WrapperDidUpdate="WrapperDidUpdate",t.DisplayIframe="DisplayIframe",t.HideIframe="HideIframe",t.PageTo="PageTo"})(c||(c={}));var x;(function(t){t.WrapperDidMount="WrapperDidMount",t.IframeLoad="IframeLoad"})(x||(x={}));const ae=new Set(["clicker","selector"]),de={kind:"IframeBridge",setup(t){const e=t.getBox(),r=t.getView(),s=t.getDisplayer(),i=t.getRoom(),n=te(t,{src:"about:blank",displaySceneDir:"/h5",lastEvent:null,state:{},page:0,maxPage:0}),o=new g,l=document.createElement("div");Object.assign(l.style,{width:"100%",height:"100%",position:"relative"});const p=document.createElement("iframe");Object.assign(p.style,{width:"100%",height:"100%",border:"none",display:"block"}),l.appendChild(p),e.mountContent(l);let W=()=>{};const K=u=>ae.has(u);if(r){const u=document.createElement("div");Object.assign(u.style,{width:"100%",height:"100%",position:"absolute",top:0,left:0}),l.appendChild(u),t.mountView(u),r.disableCameraTransform=!0,o.add(()=>{const d=()=>{const O=l.getBoundingClientRect().height/oe;r.moveCamera({scale:O,animationMode:"immediately"})},a=new ResizeObserver(d);return a.observe(l),()=>a.disconnect()}),W=d=>{u.style.pointerEvents=d?"none":"auto"},W(K(i==null?void 0:i.state.memberState.currentApplianceName))}const B=u=>ee(T({},u),{url:n.src,displaySceneDir:n.displaySceneDir,width:p.scrollWidth,height:p.scrollHeight,useClicker:!0,lastEvent:n.lastEvent}),E=new se,R=new Map,F=()=>{R.forEach((u,d)=>{s.removeMagixEventListener(d,u)}),R.clear()},V=(...u)=>!1,y=u=>{var d;V("[IframeBridge] postMessage %s %O",u.kind,u.payload),(d=p.contentWindow)==null||d.postMessage(JSON.parse(JSON.stringify(u)),"*")},I=(u,d)=>{t.getIsWritable()&&(t.updateAttributes(["lastEvent"],{name:u,payload:d}),i==null||i.dispatchMagixEvent(u,d))},_=()=>{y({kind:c.Init,payload:{attributes:B(n.state),roomState:s.state,currentPage:n.page,observerId:s.observerId}})};let X=n.src.includes("cocos");const Q=u=>{_(),E.emit(x.IframeLoad,u),E.on(c.Ready,()=>{var d,a;((d=n.lastEvent)==null?void 0:d.payload)&&y((a=n.lastEvent)==null?void 0:a.payload)}),X&&(setTimeout(()=>{y({kind:c.RoomStateChanged,payload:H(1,n.maxPage,n.displaySceneDir)})},500),X=!1),p.removeEventListener("load",Q)};o.addEventListener(p,"load",Q);let ce=0;const ue=()=>{ce++<3&&(p.src=n.src)};o.addEventListener(p,"error",ue),p.src=n.src,o.add(()=>t.mobxUtils.autorun(()=>{y({kind:c.AttributesUpdate,payload:B(n.state)})})),o.add(()=>t.mobxUtils.autorun(()=>{p.src=n.src})),o.add(()=>t.mobxUtils.autorun(()=>{y({kind:c.RoomStateChanged,payload:H(n.page,n.maxPage,n.displaySceneDir)})}));const Y={emitter:E,postMessage:y,context:t};return E.emit(c.StartCreate),E.emit(c.OnCreate,Y),i&&o.add(()=>{const u=d=>{d.memberState&&W(K(d.memberState.currentApplianceName))};return i.callbacks.on("onRoomStateChanged",u),()=>i.callbacks.off("onRoomStateChanged",u)}),o.addEventListener(window,"message",u=>{if(u.source!==p.contentWindow)return;const d=u.data;switch(V("[IframeBridge] received",d.kind,d.payload),d.kind){case c.SetAttributes:{t.updateAttributes(["state"],T(T({},n.state),d.payload));break}case c.RegisterMagixEvent:{const a=O=>{O.authorId!==s.observerId&&y({kind:c.ReceiveMagixEvent,payload:O})},m=d.payload;R.set(m,a),s.addMagixEventListener(m,a);break}case c.RemoveMagixEvent:{const a=d.payload,m=R.get(a);s.removeMagixEventListener(a,m);break}case c.DispatchMagixEvent:{const a=d.payload;I(a.event,a.payload);break}case c.RemoveAllMagixEvent:{F();break}case c.NextPage:{if(t.getIsWritable()&&i){const a=ne(n.page,n.maxPage);if(a===n.page)break;t.setScenePath([n.displaySceneDir,a].join("/")),t.updateAttributes(["page"],a),I(c.NextPage,{})}break}case c.PrevPage:{if(t.getIsWritable()&&i){const a=ie(n.page);if(a===n.page)break;t.setScenePath([n.displaySceneDir,a].join("/")),t.updateAttributes(["page"],a),I(c.PrevPage,{})}break}case c.SetPage:{const a=Number(d.payload)||0;if(t.getIsWritable()&&i)if(!a)i.removeScenes(n.displaySceneDir);else{const m=i.entireScenes()[n.displaySceneDir];(!m||m.length!==a)&&(i.removeScenes(n.displaySceneDir),i.putScenes(n.displaySceneDir,J(a))),t.setScenePath(`${n.displaySceneDir}/1`),t.updateAttributes(["maxPage"],a)}break}case c.PageTo:{const a=d.payload;if(t.getIsWritable()&&i){if(!Number.isSafeInteger(a)||a<=0)break;t.setScenePath(`${n.displaySceneDir}/${a}`),t.updateAttributes(["page"],a),I(c.PageTo,a-1)}break}case c.SDKCreate:{_();break}case c.GetAttributes:{y({kind:c.GetAttributes,payload:B(n.state)});break}default:console.warn(`[IframeBridge]: unknown event kind "${d.kind}"`)}}),t.emitter.on("destroy",()=>{console.log("[IframeBridge]: destroy"),E.emit(c.Destroy),o.flushAll(),F(),p.remove()}),Y}};return f.default=de,Object.defineProperty(f,"__esModule",{value:!0}),f[Symbol.toStringTag]="Module",f}({});})();
//# sourceMappingURL=main.iife.js.map
{
"name": "@netless/app-iframe-bridge",
"version": "0.0.1",
"version": "0.0.2",
"main": "dist/main.cjs.js",

@@ -5,0 +5,0 @@ "module": "dist/main.es.js",

@@ -144,3 +144,2 @@ ## @netless/app-iframe-bridge

网络时延在 0.1s - 10s 左右,因此不宜基于此组件制作对同步要求高的应用。\
后续会给出一个同步时间戳接口,可以基于他制作计时器、播放器等对具体时间发生的事件有要求的应用。
网络时延在 0.1s - 10s 左右,因此不宜基于此组件制作对同步要求高的应用。

@@ -6,4 +6,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

import { SideEffectManager } from "side-effect-manager";
import type { ApplianceNames, Event, RoomState } from "white-web-sdk";
import type { AnimationMode, ApplianceNames, Event, RoomState } from "white-web-sdk";
import { fakeRoomStateChanged, nextPage, pageToScenes, prevPage } from "./page";
import { height } from "./hardcode";
import { DomEvents, IframeEvents } from "./typings";

@@ -39,2 +40,4 @@

const sideEffectManager = new SideEffectManager();
const container = document.createElement("div");

@@ -72,2 +75,14 @@ Object.assign(container.style, { width: "100%", height: "100%", position: "relative" });

view.disableCameraTransform = true;
sideEffectManager.add(() => {
const onResize = () => {
const clientRect = container.getBoundingClientRect();
const scale = clientRect.height / height;
view.moveCamera({ scale, animationMode: "immediately" as AnimationMode });
};
const observer = new ResizeObserver(onResize);
observer.observe(container);
return () => observer.disconnect();
});
toggleClickThrough = (enable?: boolean) => {

@@ -91,3 +106,2 @@ viewBox.style.pointerEvents = enable ? "none" : "auto";

const sideEffectManager = new SideEffectManager();
const emitter = new Emittery<Record<IframeEvents | DomEvents, any>>();

@@ -94,0 +108,0 @@ const magixEventMap = new Map<string, (event: Event) => void>();

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

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