@elliemae/pui-app-bridge 2.26.0-alpha.0 → 2.26.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/appBridge.js +4 -0
- package/dist/esm/appBridge.js +4 -0
- package/dist/public/e2e-host.html +1 -1
- package/dist/public/e2e-index.html +1 -1
- package/dist/public/frame.html +1 -1
- package/dist/public/index.html +1 -1
- package/dist/public/js/{emuiAppBridge.dc4dbeb6feea171656da.js → emuiAppBridge.2cb0198671d2a7602aaa.js} +2 -2
- package/dist/public/js/emuiAppBridge.2cb0198671d2a7602aaa.js.br +0 -0
- package/dist/public/js/{emuiAppBridge.dc4dbeb6feea171656da.js.gz → emuiAppBridge.2cb0198671d2a7602aaa.js.gz} +0 -0
- package/dist/public/js/emuiAppBridge.2cb0198671d2a7602aaa.js.map +1 -0
- package/dist/types/lib/typings/window.d.ts +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.br +0 -0
- package/dist/umd/index.js.gz +0 -0
- package/dist/umd/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/public/js/emuiAppBridge.dc4dbeb6feea171656da.js.br +0 -0
- package/dist/public/js/emuiAppBridge.dc4dbeb6feea171656da.js.map +0 -1
package/dist/umd/index.js
CHANGED
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
@media (max-width: ${r[n]}) {
|
|
13
13
|
${mt(s,...c)};
|
|
14
14
|
}
|
|
15
|
-
`,t),{}),bn=r=>({space:{...r.spaces,xxxs:r.spaces[1],xxs:r.spaces[2],xxs2:r.spaces[3],xs:r.spaces[4],s:r.spaces[5],m:r.spaces[6],l:r.spaces[7],xl:r.spaces[8],xxl:r.spaces[9]},fontSizes:{...r.fontSizes,title:{500:r.fontSizes[3],600:r.fontSizes[4],700:r.fontSizes[5],800:r.fontSizes[6],900:r.fontSizes[7]},subTitle:{300:r.fontSizes[1],400:r.fontSizes[2]},label:{200:r.fontSizes[0],300:r.fontSizes[1],400:r.fontSizes[2]},value:{300:r.fontSizes[1],400:r.fontSizes[2],500:r.fontSizes[3],600:r.fontSizes[4]},hyperlink:{200:r.fontSizes[0],300:r.fontSizes[1],400:r.fontSizes[2]},microText:{200:r.fontSizes[0]}},fontWeights:{...r.fontWeights,thin:r.fontWeights[0],light:r.fontWeights[1],regular:r.fontWeights[3],semibold:r.fontWeights[5],bold:r.fontWeights[8]},lineHeights:{...r.lineHeights,r:r.lineHeights[0],m:r.lineHeights[1],l:r.lineHeights[2],xl:r.lineHeights[3]},letterSpacings:{normal:r.letterSpacings[0],tracked:r.letterSpacings[1],tight:r.letterSpacings[2],mega:r.letterSpacings[3]},fonts:{...r.fonts,default:r.fonts[0]},colors:{neutral:{"000":r.colors.neutral[0],"050":r.colors.neutral[1],"080":r.colors.neutral[2],100:r.colors.neutral[3],200:r.colors.neutral[4],300:r.colors.neutral[5],400:r.colors.neutral[6],500:r.colors.neutral[7],600:r.colors.neutral[8],700:r.colors.neutral[9],800:r.colors.neutral[10]},brand:{100:r.colors.brand[0],200:r.colors.brand[1],250:r.colors.brand[8],300:r.colors.brand[2],400:r.colors.brand[3],500:r.colors.brand[4],600:r.colors.brand[5],700:r.colors.brand[6],800:r.colors.brand[7]},success:{300:r.colors.success[0],400:r.colors.success[1],600:r.colors.success[2],900:r.colors.success[3],950:r.colors.success[4]},warning:{400:r.colors.warning[0],500:r.colors.warning[1],600:r.colors.warning[1],900:r.colors.warning[2],950:r.colors.warning[3]},danger:{200:r.colors.danger[0],400:r.colors.danger[1],600:r.colors.danger[2],900:r.colors.danger[3],950:r.colors.danger[4]}},shadows:{xs:r.shadows[0],s:r.shadows[1],m:r.shadows[2],l:r.shadows[3],xl:r.shadows[4]},breakpoints:{...r.breakpoints,xsmall:r.breakpoints[3],small:r.breakpoints[0],medium:r.breakpoints[1],large:r.breakpoints[2]},media:yn({xsmall:r.breakpoints[3],small:r.breakpoints[0],medium:r.breakpoints[1],large:r.breakpoints[2]}),zIndex:{dialog:r.zIndex[0],popper:r.zIndex[1],tooltip:r.zIndex[2],backdrop:r.zIndex[3],loader:r.zIndex[4]},states:{_:r.states[0],motionSafe:r.states[1],motionReduce:r.states[2],first:r.states[3],last:r.states[4],odd:r.states[5],even:r.states[6],visited:r.states[7],checked:r.states[8],focusWithin:r.states[9],hover:r.states[10],focus:r.states[11],focusVisible:r.states[12],active:r.states[13],disabled:r.states[14],placeholder:r.states[15]}}),wn=((r=_())=>()=>bn(r))(),ts=()=>{try{return window.parent.document,window.parent}catch{return window}},lr=()=>({width:Math.max(document.documentElement.clientWidth||0,window.innerWidth||0),height:Math.max(document.documentElement.clientHeight||0,window.innerHeight||0)}),Mr=r=>Number(r.replace("px","")),$r=()=>{const{width:r}=lr(),{breakpoints:t}=wn();return r<=Mr(t.small)?"small":r<=Mr(t.medium)?"medium":"large"},xn="microFrontendApps",Sn=()=>!0,An=r=>Sn()?!0:String(r).toLowerCase()===z.PRODUCTION.toLowerCase(),En=r=>r?new URL(r).pathname:"",Cn=r=>{const t=document.createElement("a");return t.href=r,t.href},On=(r,t)=>{const n=t.match(/^(?:\d+\.\d+)*/g);return r.replace(/{SYSTEM_VERSION}/,n&&n[0]||x)},Fr=r=>!r||!r.length?!1:r.every(t=>typeof t=="string"),Tn=(r,t)=>{const{mode:n=z.PRODUCTION}=t;if(String(n).toLowerCase()!==z.PRODUCTION.toLowerCase()&&String(n).toLowerCase()!==z.DEVELOPMENT.toLowerCase())throw new Error(`invalid mode '${String(n)}' for ${r}`);const{production:s,development:c,microappManager:h=ie.APPSDK}=t;if(String(h).toLowerCase()===ie.APPSDK.toLowerCase()){if(String(n).toLowerCase()===z.PRODUCTION.toLowerCase()){if(!s)throw new Error(`microFrontendApps.${r} is missing production section in app.config.json`);if(!Fr(s.files))throw new Error("invalid value for production.files")}if(String(n).toLowerCase()===z.DEVELOPMENT.toLowerCase()){if(!c)throw new Error(`microFrontendApps.${r} is missing development section in app.config.json`);if(!Fr(c.files))throw new Error("invalid value for development.files")}}},Pn=({id:r,config:t,version:n="latest"})=>{const{mode:s=z.PRODUCTION,production:c,development:h,...m}=t,b=An(s)?c:h,S=v()({id:r},{name:r,mode:z.PRODUCTION,manifestPath:"./{SYSTEM_VERSION}/",securityContext:o.USER,isJsModule:!0},m,{mode:s},b);return S.hostUrl=F(Cn(S.hostUrl||"")),S.homeRoute=F(S.homeRoute)||En(S.hostUrl),S.manifestPath=F(On(S.manifestPath,n)),S};class In{#e=[];init=({version:t,appConfig:n})=>{const s=n.get(xn);s&&(this.#e=Object.keys(s).map(c=>(Tn(c,s[c]),Pn({id:c,config:s[c],version:t}))))};getConfigById=t=>this.#e.find(n=>n.id===t)}const jn="ice-script-";class Lr{#e;constructor(t){this.#e=t}#t=({href:t,isESMModule:n=!0,documentEle:s})=>{const c=s.createElement("link");c.rel=n?"modulepreload":"preload",c.href=t,c.crossOrigin="anonymous",n||(c.as="script"),s.head.appendChild(c)};#r=({id:t,href:n,documentEle:s,isESMModule:c=!0})=>new Promise((h,m)=>{const b=s.createElement("script");b.id=t,b.src=O(n),b.crossOrigin="anonymous",b.nonce="__CSP_NONCE__",!L()&&c?b.type="module":b.async=!1,b.onload=h.bind(null,b.id),b.onerror=S=>{this.#e.error({message:`Error loading script ${b.src}`,exception:new Error(S)}),m(new Error(`Unable to load script ${b.src}`,{cause:new Error(S)}))},s.head.appendChild(b)});load=async(t,n)=>{const{documentEle:s,isESMModule:c}=n,h=/^https?:\/\//i,{cdnAssets:m,nonCdnAssets:b}=t.reduce((E,T,I)=>{const k=`${jn}${n.name.toLowerCase()}-${I}`;if(h.test(T))E.cdnAssets.push({id:k,href:T}),this.#t({href:T,documentEle:s,isESMModule:c});else{const K=new URL(T,n.hostUrl);E.nonCdnAssets.push({id:k,href:K.href}),this.#t({href:K.href,documentEle:s,isESMModule:c})}return E},{cdnAssets:[],nonCdnAssets:[]}),S=[...m,...b];return await Promise.all(S.map(({id:E,href:T})=>this.#r({id:E,href:T,documentEle:s,isESMModule:c}))),S.map(E=>E.id)};remove=(t="",n=document)=>new Promise(s=>{const c=n.getElementById(t);if(!c){this.#e.warn(`script with id ${t} not found`),s();return}c.remove(),s()});removeDynamicImportedScripts=(t,n)=>{const s=new RegExp(B(t),"i"),c=n.getElementsByTagName("script");for(let h=c.length-1;h>=0;h-=1){const m=c[h],{src:b}=m;s.test(b)&&m.remove()}};removePrefetchLinks=(t,n)=>{const s=new RegExp(B(t),"i"),c=n.querySelectorAll('[rel="prefetch"]');for(let h=c.length-1;h>=0;h-=1){const m=c[h],{href:b}=m;s.test(b)&&m.remove()}}}const Rn="ice-style-";class Dr{#e;constructor(t){this.#e=t}#t=({id:t,href:n,documentEle:s})=>new Promise((c,h)=>{const m=s.createElement("link");m.id=t,m.nonce="__CSP_NONCE__",m.rel="stylesheet",m.href=O(n),m.onload=c.bind(null,m.id),m.onerror=b=>{this.#e.error({message:`Error loading stylesheet ${m.href}`,exception:new Error(b)}),h(new Error(`Unable to load stylesheet ${m.href}`,{cause:new Error(b)}))},s.head.appendChild(m)});load=async(t,n)=>{const s=[],c=t.map((h,m)=>{const b=new URL(h,n.hostUrl),S=`${Rn}${n.name.toLowerCase()}-${m}`;return s.push(S),this.#t({id:S,href:b.href,documentEle:n.documentEle})});return await Promise.all(c),s};remove=(t="",n=document)=>new Promise(s=>{const c=n.getElementById(t);if(!c){this.#e.warn(`style with id ${t} not found`),s();return}c.remove(),s()});removeDynamicImportedStyles=(t,n)=>{const s=new RegExp(B(t),"i"),c=n.querySelectorAll('[rel="stylesheet"]');for(let h=c.length-1;h>=0;h-=1){const m=c[h],{href:b}=m;s.test(b)&&m.remove()}}}const Mn=r=>r.replace(/\/\d+\.\d+/,"/latest"),$n=r=>{let t;try{t=new URL(r)}catch{return!1}return t.protocol==="http:"||t.protocol==="https:"},ur=new Map,Dt={get:async({hostUrl:r,manifestPath:t})=>{const n=new URL(`${t}manifest.json`,r),s=O(n.href),c=ur.get(s);if(c)return c;const h=async m=>{const b=await fetch(m);if(!b.ok)throw new Error(`unable to get manifest ${m}`);if(!(b.headers?.get?.("content-type")??"").includes("application/json"))throw new Error(`manifest ${m} is not a valid json`);const E=await b.json();return ur.set(m,E),E};try{return await h(s)}catch(m){const b=Mn(t);if(t!==b){const S=O(new URL(`${b}manifest.json`,r).href);return await h(S)}throw m}},getFullFileNameofAssets:(r,t=[])=>t.reduce((n,s)=>{const c=r[s];if(c)n.push(c);else if($n(s))n.push(s);else throw new Error(`unable to locate ${s} in manifest`);return n},[]),clearCache:()=>ur.clear()};class Nr{#e;#t;#r;#o;#n;constructor(t){this.#t=t.guest,this.#e=t.containerId,this.#r=t?.version||x,this.#o=t.soManager,this.#n=t.eventManager}get version(){return this.#r}getObject=t=>{try{const n=this.#o.getObject(t,this.#t);if(!n)return Promise.resolve(null);const s=new Gt(n.id,n.objectType);return Object.keys(n).forEach(c=>{const h=n[c];h instanceof ae?Object.defineProperty(s,c,{value:new ae({name:c,objectId:n.id}),enumerable:!0}):re(h,c)&&Object.defineProperty(s,c,{value:(...m)=>{const b=s[c]?.callContext?.callChain;return Object.defineProperty(h,"callContext",{value:{guest:this.#t,...b?.length?{callChain:b}:{}},configurable:!0,enumerable:!0,writable:!0}),n[c](...m)},enumerable:!0})}),Promise.resolve(s)}catch(n){return Promise.reject(n)}};setAppWindowSize=t=>{if(!this.#e)return;const{size:n}=t,s=document.getElementById(this.#e);s&&(s.style.height=`${n.height}px`,s.style.width=`${n.width}px`)};subscribe=t=>this.#n.subscribe(t);unsubscribe=t=>{this.#n.unsubscribe(t)}}class Fn{constructor(){window.emui||(window.emui={}),window.emui.registerApp=this.#e}#e=({appId:t,app:n})=>{if(!t)throw new Error("appId is required");if(t==="__proto__"||t==="constructor"||t==="prototype")throw new Error(`Invalid appId: ${t}`);if(!n?.uuid)throw new Error("application uuid is required");if(window.emui[t]=window.emui[t]||[],Array.isArray(window.emui[t])){const s=window.emui[t].findIndex(c=>c.uuid===n.uuid);s>-1?window.emui[t][s]=n:window.emui[t].push(n)}else{let s=window.emui[t];s?.uuid===n.uuid?(s={...s,...n},window.emui[t]=[s]):typeof s.init>"u"?window.emui[t]=[{...s,...n}]:window.emui[t]=[window.emui[t],n]}};get=({id:t,instanceId:n})=>{const s=window.emui?.[t];return Array.isArray(s)?s.find(h=>h.uuid===n)??null:s?.uuid===n?s:null};add=({id:t,instanceId:n,documentEle:s})=>{if(!n)throw new Error(`instanceId (uuid) is required to register application ${t}`);const c={uuid:n,init:null,mount:null,unmount:null},h=window.emui[t];h?Array.isArray(h)?h.push(c):window.emui[t]=[h,c]:window.emui[t]=[c],s.defaultView&&(s.defaultView.emui=s.defaultView.emui??{},s.defaultView.emui.uuid=n)};delete=({id:t,instanceId:n})=>{if(Array.isArray(window.emui[t])){const s=window.emui[t].findIndex(c=>c.uuid===n);s>-1&&window.emui[t].splice(s,1),window.emui[t].length===0&&delete window.emui[t]}else delete window.emui[t]}}const Ln=12e4,kr=["click","scroll","keypress","touchstart"],Dn=/\.css$/,Ur=r=>Dn.test(r);class Nn{#e;#t;#r;#o;#n;#i=new In;#s;#l;#a=new Map;#u=new Map;#c=new Fn;#p=!0;constructor(t){const{logger:n}=t;if(!n)throw new Error("logger is required");this.#e=t.logger,this.#t=t.version,this.#p=t.extendSession??!0,this.#n=new R({version:t.version,baseUrl:t.appConfigBaseUrl}),this.#r=new Lr(n),this.#o=new Dr(n),this.#s=new Vt,this.#l=new Ht(this.#e)}#g(t){return typeof t=="function"}#m=t=>t instanceof A||typeof t?.subscribe=="function";#v=(t,n)=>`Application ${t} with instance id ${n} is not found. Most probably the appId property of app.config.json is not set to ${t}`;#y=(t,n=document)=>{const{elementIds:s}=this.#a.get(t)||{};s&&s.forEach(c=>{const h=n.getElementById(c);h&&h.remove()})};#b=({id:t,instanceId:n,documentEle:s,elementIds:c,microFEHost:h})=>{const m=this.#c.get({id:t,instanceId:n});if(!m)throw new Error(this.#v(t,n));this.#a.set(n,{id:t,instanceId:n,elementIds:c,guest:{guestWindow:s?.defaultView,...m},microFEHost:h})};#w=async({id:t,instanceId:n,containerId:s,hostUrl:c,manifestPath:h,homeRoute:m,initialRoute:b,history:S,theme:E,microFEHost:T})=>{const I=this.#c.get({id:t,instanceId:n});if(!I)throw new Error(`Application ${t} with instance id ${n} is not found. Most probably the appId property of app.config.json is not set to ${t}`);if(!I.init||typeof I.init!="function")throw new Error(`Application ${t} with instance id ${n} doesn't expose init method`);const k=T??new Nr({guest:{id:t},version:this.#t,containerId:s,logger:this.#e,soManager:this.#s,eventManager:this.#l});return I.init({host:k,hostUrl:c,manifestPath:h,homeRoute:m,initialRoute:b,prevState:null,history:S,theme:E,hostBreakpoint:$r(),hostViewportSize:lr(),logger:this.#e})};#x=async t=>{try{const{id:n,instanceId:s,files:c,name:h,hostUrl:m,documentEle:b,isJsModule:S}=t;this.#e.debug(`Application ${n} with instance id ${s} is loading...`);let E=c;const T=t.manifest??await Dt.get(t);E=Dt.getFullFileNameofAssets(T,c);const I=E.filter(D=>Ur(D)),k=E.filter(D=>!Ur(D)),K={name:h,hostUrl:m,documentEle:b,isESMModule:S},[V,X]=await Promise.all([this.#o.load(I,K),this.#r.load(k,K)]);this.#b({id:n,instanceId:s,documentEle:b,elementIds:[...V,...X],microFEHost:t.microFEHost}),t.selfInitialize||await this.#w(t),this.#e.audit(`Application ${n} with instance id ${s} loaded`)}catch(n){const s=`Application load failed. Unable to load one or more resources for ${t.id} with instance id ${t.instanceId}. ${n.message}`;throw this.#e.error({message:s,appId:t.id,exception:n}),new Error(s)}};#d=({id:t,instanceId:n,hostUrl:s,documentEle:c})=>{this.#e.debug(`Application ${t} with instance id ${n} unloading...`),this.#c.get({id:t,instanceId:n})&&(this.#y(n,c),this.#r.removeDynamicImportedScripts(s,c),this.#r.removePrefetchLinks(s,c),this.#o.removeDynamicImportedStyles(s,c),this.#c.delete({id:t,instanceId:n}),this.#e.audit(`Application ${t} with instance id ${n} unloaded`))};#f=async({id:t,instanceId:n})=>{const s=this.#c.get({id:t,instanceId:n});if(!s?.mount||typeof s?.mount!="function")throw new Error(`Application ${t} with instance id ${n} doesn't expose mount method`);return s.mount({containerId:`${ft}${t}`,hostBreakpoint:$r(),hostViewportSize:lr()})};#h=({id:t,instanceId:n})=>{const s=this.#c.get({id:t,instanceId:n});if(!s?.unmount)return null;if(typeof s.unmount!="function")throw new Error(`Application ${t} with instance id ${n} doesn't expose unmount method`);return s.unmount({containerId:`${ft}${t}`})};#S=({id:t,instanceId:n})=>{if(this.#p)try{const s=this.#s.getObject(nt.Application);if(!s){this.#e.warn({message:`Application scripting object not available for ${t} to manage session`});return}const c=this.#a.get(n);if(!c)return;c.keepAlive=W()(async()=>{try{await s.keepSessionAlive()}catch(m){this.#e.error(`Error keeping session alive. ${m.message}`)}},Ln);const h=Re.get(n);kr.forEach(m=>{h?.contentDocument?.addEventListener(m,c.keepAlive)})}catch(s){this.#e.warn({message:`Application scripting object not available for ${t} to manage session`,exception:s})}};#A=(t,n)=>{const h=this.#s.getObject(nt.Module,{id:t})?._setUnloadHandler;typeof h=="function"&&h(()=>this.closeApp(n))};#E=async t=>{const n=this.#s.getObject(nt.Module,{id:t});if(!n)return!0;try{const s=await this.#l.dispatchEvent(n,{event:{id:"module.unloading",name:"unloading"},eventParams:{moduleId:t},eventOptions:{timeout:1e3}});if(Array.isArray(s)&&s.some(c=>c===!1))return this.#e.info(`Unload denied by guest ${t} via module.unloading event`),!1}catch(s){this.#e.warn({message:`Error dispatching module.unloading event for ${t}`,exception:s})}return!0};#C=t=>{if(!this.#p||!t)return;const{keepAlive:n,instanceId:s}=t;if(n){const h=Re.get(s)?.contentDocument;h&&kr.forEach(m=>{h.removeEventListener(m,n)}),t.keepAlive?.cancel()}};addScriptingObject=(t,n)=>{if(Ot(t)){const s=this.cloneScriptingObject(t);this.#s.addScriptingObject(s,n)}else this.#s.addScriptingObject(t,n)};cloneScriptingObject=t=>{if(!t)throw new Error("proxy is required");const n=new fe(t.id,t.objectType);let s=[];return Object.keys(t).forEach(c=>{const h=t[c];if(this.#m(h)){const m=new ae({name:h.name||c,objectId:n.id});Object.defineProperty(n,c,{value:m,enumerable:!0});const b=({eventParams:E,eventOptions:T})=>this.dispatchEvent({event:m,eventParams:E,eventOptions:T}),S=h.subscribe(b);s.push(()=>{h.unsubscribe(S)})}else if(this.#g(h)&&(Object.defineProperty(n,c,{value:async(...m)=>{const b=n[c]?.callContext;if(b?.guest){const E=b.callChain??[],T=b.guest.id,I=this.#u.get(T),k={id:T};I&&(k.metadata=I),Object.defineProperty(h,"callContext",{value:{callChain:[...E,k]},configurable:!0,enumerable:!0,writable:!0})}const S=await h(...m);return Ot(S)?this.cloneScriptingObject(S):S},enumerable:!0}),c==="dispose")){const m=n.dispose;Object.defineProperty(n,c,{value:()=>(n._dispose(),m.apply(n)),enumerable:!0})}}),n._dispose=()=>{s.forEach(c=>{c?.()}),s=[]},n};closeAllApps=async()=>{await Promise.all([...this.#a.keys()].map(this.closeApp))};closeApp=async t=>{if(!t)throw new Error("instanceId is required");const n=this.#a.get(t);if(!n){this.#e.warn(`Application with instance id ${t} is not found`);return}const{id:s}=n;if(!await this.#E(s))return;const c=this.#i.getConfigById(s);if(!c){this.#e.warn(`Configuration for application ${s} is not found`),this.#a.delete(t),Re.remove(t);return}const{hostUrl:h}=c;try{this.#C(n),await this.#h({id:s,instanceId:t})}finally{const m=Re.get(t);m?.contentDocument&&this.#d({id:s,instanceId:t,hostUrl:h,documentEle:m.contentDocument}),this.#a.delete(t),this.#u.delete(s),Re.remove(t)}};dispatchEvent=async t=>{const{event:{id:n,name:s},eventOptions:c={}}=t,{guestId:h}=c;if(!n)throw new Error("Event Id is required");const m=n.split(".")?.[0],b=h?this.#s.getObject(m,{id:h}):this.#s.getObject(m);return b?this.#l.dispatchEvent(b,t):(this.#e.warn(`Attempt to dispatch event ${s} on unknown object ${m}`),Promise.resolve())};getApp=t=>this.#a.get(t)?.guest;getApps=()=>[...this.#a.values()].map(t=>t.guest);init=async t=>{t?this.#n.setPreloadedConfig(t):await this.#n.load(),this.#i.init({version:this.#t,appConfig:this.#n}),this.#O()};#O=()=>{const t=this.#n.get("microFrontendApps")??{},n=new Set;Object.keys(t).forEach(s=>{const c=this.#i.getConfigById(s);if(c?.hostUrl)try{n.add(new URL(c.hostUrl).origin)}catch{}}),n.forEach(s=>{const c=document.createElement("link");c.rel="preconnect",c.href=s,c.crossOrigin="anonymous",document.head.appendChild(c)})};mountApp=async t=>{if(!t)throw new Error("instanceId is required");const{id:n}=this.#a.get(t)||{};if(!n)throw new Error(`Application with instance id ${t} is not found`);const s=this.#i.getConfigById(n);if(!s)throw new Error(`Application with id ${n} is not found`);await this.#f({...s,instanceId:t})};#T=(t,n,s)=>{const c=new Nr({guest:{id:s.id},version:this.#t,containerId:s.containerId,logger:this.#e,soManager:this.#s,eventManager:this.#l}),h=t.defaultView;h&&(h.emui=h.emui??{},h.emui.__host=c);const m=t.createElement("link");return m.rel="preconnect",m.href=n.hostUrl,m.crossOrigin="anonymous",t.head.appendChild(m),c};openApp=async t=>{const{id:n,frameOptions:s,history:c,theme:h,homeRoute:m,initialRoute:b,metadata:S,selfInitialize:E}=t,T=Et();S&&this.#u.set(n,S);const I=this.#i.getConfigById(n);if(!I)throw new Error(`Application ${n} is not found in app config`);const k=Dt.get(I);k.catch(()=>{});const K=await Re.create({id:n,instanceId:T,manifestPath:I.manifestPath,hostUrl:I.hostUrl,options:{title:I.name,...s}});if(!K?.contentDocument)throw new Error("unable to create iframe for the microapp");try{this.#c.add({id:n,instanceId:T,documentEle:K.contentDocument});const V=this.#T(K.contentDocument,I,{id:n,containerId:s?.containerId}),X=await k;return await this.#x({instanceId:T,history:c,theme:h,documentEle:K.contentDocument,containerId:s?.containerId,...I,homeRoute:m??I.homeRoute,initialRoute:b,microFEHost:V,selfInitialize:E,manifest:X}),E||await this.#f({instanceId:T,...I}),this.#S({id:n,instanceId:T}),this.#A(n,T),T}catch(V){throw this.#d({id:n,instanceId:T,hostUrl:I.hostUrl,documentEle:K.contentDocument}),Re.remove(T),V}};removeAllEventSubscriptions=()=>{this.#l.unsubscribeAll()};removeAllScriptingObjects=t=>{this.#s.removeAllScriptingObjects(t)};removeScriptingObject=(t,n)=>{this.#s.removeScriptingObject(t,n)};warmUp=t=>{const n=this.#i.getConfigById(t);n&&Dt.get(n).catch(()=>{})};unmountApp=async t=>{if(!t)throw new Error("instanceId is required");const{id:n}=this.#a.get(t)||{};if(!n)throw new Error(`Application with instance id ${t} is not found`);const s=this.#i.getConfigById(n);if(!s)throw new Error(`Application with id ${n} is not found`);await this.#h({...s,instanceId:t})}}})(),kt})());
|
|
15
|
+
`,t),{}),bn=r=>({space:{...r.spaces,xxxs:r.spaces[1],xxs:r.spaces[2],xxs2:r.spaces[3],xs:r.spaces[4],s:r.spaces[5],m:r.spaces[6],l:r.spaces[7],xl:r.spaces[8],xxl:r.spaces[9]},fontSizes:{...r.fontSizes,title:{500:r.fontSizes[3],600:r.fontSizes[4],700:r.fontSizes[5],800:r.fontSizes[6],900:r.fontSizes[7]},subTitle:{300:r.fontSizes[1],400:r.fontSizes[2]},label:{200:r.fontSizes[0],300:r.fontSizes[1],400:r.fontSizes[2]},value:{300:r.fontSizes[1],400:r.fontSizes[2],500:r.fontSizes[3],600:r.fontSizes[4]},hyperlink:{200:r.fontSizes[0],300:r.fontSizes[1],400:r.fontSizes[2]},microText:{200:r.fontSizes[0]}},fontWeights:{...r.fontWeights,thin:r.fontWeights[0],light:r.fontWeights[1],regular:r.fontWeights[3],semibold:r.fontWeights[5],bold:r.fontWeights[8]},lineHeights:{...r.lineHeights,r:r.lineHeights[0],m:r.lineHeights[1],l:r.lineHeights[2],xl:r.lineHeights[3]},letterSpacings:{normal:r.letterSpacings[0],tracked:r.letterSpacings[1],tight:r.letterSpacings[2],mega:r.letterSpacings[3]},fonts:{...r.fonts,default:r.fonts[0]},colors:{neutral:{"000":r.colors.neutral[0],"050":r.colors.neutral[1],"080":r.colors.neutral[2],100:r.colors.neutral[3],200:r.colors.neutral[4],300:r.colors.neutral[5],400:r.colors.neutral[6],500:r.colors.neutral[7],600:r.colors.neutral[8],700:r.colors.neutral[9],800:r.colors.neutral[10]},brand:{100:r.colors.brand[0],200:r.colors.brand[1],250:r.colors.brand[8],300:r.colors.brand[2],400:r.colors.brand[3],500:r.colors.brand[4],600:r.colors.brand[5],700:r.colors.brand[6],800:r.colors.brand[7]},success:{300:r.colors.success[0],400:r.colors.success[1],600:r.colors.success[2],900:r.colors.success[3],950:r.colors.success[4]},warning:{400:r.colors.warning[0],500:r.colors.warning[1],600:r.colors.warning[1],900:r.colors.warning[2],950:r.colors.warning[3]},danger:{200:r.colors.danger[0],400:r.colors.danger[1],600:r.colors.danger[2],900:r.colors.danger[3],950:r.colors.danger[4]}},shadows:{xs:r.shadows[0],s:r.shadows[1],m:r.shadows[2],l:r.shadows[3],xl:r.shadows[4]},breakpoints:{...r.breakpoints,xsmall:r.breakpoints[3],small:r.breakpoints[0],medium:r.breakpoints[1],large:r.breakpoints[2]},media:yn({xsmall:r.breakpoints[3],small:r.breakpoints[0],medium:r.breakpoints[1],large:r.breakpoints[2]}),zIndex:{dialog:r.zIndex[0],popper:r.zIndex[1],tooltip:r.zIndex[2],backdrop:r.zIndex[3],loader:r.zIndex[4]},states:{_:r.states[0],motionSafe:r.states[1],motionReduce:r.states[2],first:r.states[3],last:r.states[4],odd:r.states[5],even:r.states[6],visited:r.states[7],checked:r.states[8],focusWithin:r.states[9],hover:r.states[10],focus:r.states[11],focusVisible:r.states[12],active:r.states[13],disabled:r.states[14],placeholder:r.states[15]}}),wn=((r=_())=>()=>bn(r))(),ts=()=>{try{return window.parent.document,window.parent}catch{return window}},lr=()=>({width:Math.max(document.documentElement.clientWidth||0,window.innerWidth||0),height:Math.max(document.documentElement.clientHeight||0,window.innerHeight||0)}),Mr=r=>Number(r.replace("px","")),$r=()=>{const{width:r}=lr(),{breakpoints:t}=wn();return r<=Mr(t.small)?"small":r<=Mr(t.medium)?"medium":"large"},xn="microFrontendApps",Sn=()=>!0,An=r=>Sn()?!0:String(r).toLowerCase()===z.PRODUCTION.toLowerCase(),En=r=>r?new URL(r).pathname:"",Cn=r=>{const t=document.createElement("a");return t.href=r,t.href},On=(r,t)=>{const n=t.match(/^(?:\d+\.\d+)*/g);return r.replace(/{SYSTEM_VERSION}/,n&&n[0]||x)},Fr=r=>!r||!r.length?!1:r.every(t=>typeof t=="string"),Tn=(r,t)=>{const{mode:n=z.PRODUCTION}=t;if(String(n).toLowerCase()!==z.PRODUCTION.toLowerCase()&&String(n).toLowerCase()!==z.DEVELOPMENT.toLowerCase())throw new Error(`invalid mode '${String(n)}' for ${r}`);const{production:s,development:c,microappManager:h=ie.APPSDK}=t;if(String(h).toLowerCase()===ie.APPSDK.toLowerCase()){if(String(n).toLowerCase()===z.PRODUCTION.toLowerCase()){if(!s)throw new Error(`microFrontendApps.${r} is missing production section in app.config.json`);if(!Fr(s.files))throw new Error("invalid value for production.files")}if(String(n).toLowerCase()===z.DEVELOPMENT.toLowerCase()){if(!c)throw new Error(`microFrontendApps.${r} is missing development section in app.config.json`);if(!Fr(c.files))throw new Error("invalid value for development.files")}}},Pn=({id:r,config:t,version:n="latest"})=>{const{mode:s=z.PRODUCTION,production:c,development:h,...m}=t,b=An(s)?c:h,S=v()({id:r},{name:r,mode:z.PRODUCTION,manifestPath:"./{SYSTEM_VERSION}/",securityContext:o.USER,isJsModule:!0},m,{mode:s},b);return S.hostUrl=F(Cn(S.hostUrl||"")),S.homeRoute=F(S.homeRoute)||En(S.hostUrl),S.manifestPath=F(On(S.manifestPath,n)),S};class In{#e=[];init=({version:t,appConfig:n})=>{const s=n.get(xn);s&&(this.#e=Object.keys(s).map(c=>(Tn(c,s[c]),Pn({id:c,config:s[c],version:t}))))};getConfigById=t=>this.#e.find(n=>n.id===t)}const jn="ice-script-";class Lr{#e;constructor(t){this.#e=t}#t=({href:t,isESMModule:n=!0,documentEle:s})=>{const c=s.createElement("link");c.rel=n?"modulepreload":"preload",c.href=t,c.crossOrigin="anonymous",n||(c.as="script"),s.head.appendChild(c)};#r=({id:t,href:n,documentEle:s,isESMModule:c=!0})=>new Promise((h,m)=>{const b=s.createElement("script");b.id=t,b.src=O(n),b.crossOrigin="anonymous",b.nonce="__CSP_NONCE__",!L()&&c?b.type="module":b.async=!1,b.onload=h.bind(null,b.id),b.onerror=S=>{this.#e.error({message:`Error loading script ${b.src}`,exception:new Error(S)}),m(new Error(`Unable to load script ${b.src}`,{cause:new Error(S)}))},s.head.appendChild(b)});load=async(t,n)=>{const{documentEle:s,isESMModule:c}=n,h=/^https?:\/\//i,{cdnAssets:m,nonCdnAssets:b}=t.reduce((E,T,I)=>{const k=`${jn}${n.name.toLowerCase()}-${I}`;if(h.test(T))E.cdnAssets.push({id:k,href:T}),this.#t({href:T,documentEle:s,isESMModule:c});else{const K=new URL(T,n.hostUrl);E.nonCdnAssets.push({id:k,href:K.href}),this.#t({href:K.href,documentEle:s,isESMModule:c})}return E},{cdnAssets:[],nonCdnAssets:[]}),S=[...m,...b];return await Promise.all(S.map(({id:E,href:T})=>this.#r({id:E,href:T,documentEle:s,isESMModule:c}))),S.map(E=>E.id)};remove=(t="",n=document)=>new Promise(s=>{const c=n.getElementById(t);if(!c){this.#e.warn(`script with id ${t} not found`),s();return}c.remove(),s()});removeDynamicImportedScripts=(t,n)=>{const s=new RegExp(B(t),"i"),c=n.getElementsByTagName("script");for(let h=c.length-1;h>=0;h-=1){const m=c[h],{src:b}=m;s.test(b)&&m.remove()}};removePrefetchLinks=(t,n)=>{const s=new RegExp(B(t),"i"),c=n.querySelectorAll('[rel="prefetch"]');for(let h=c.length-1;h>=0;h-=1){const m=c[h],{href:b}=m;s.test(b)&&m.remove()}}}const Rn="ice-style-";class Dr{#e;constructor(t){this.#e=t}#t=({id:t,href:n,documentEle:s})=>new Promise((c,h)=>{const m=s.createElement("link");m.id=t,m.nonce="__CSP_NONCE__",m.rel="stylesheet",m.href=O(n),m.onload=c.bind(null,m.id),m.onerror=b=>{this.#e.error({message:`Error loading stylesheet ${m.href}`,exception:new Error(b)}),h(new Error(`Unable to load stylesheet ${m.href}`,{cause:new Error(b)}))},s.head.appendChild(m)});load=async(t,n)=>{const s=[],c=t.map((h,m)=>{const b=new URL(h,n.hostUrl),S=`${Rn}${n.name.toLowerCase()}-${m}`;return s.push(S),this.#t({id:S,href:b.href,documentEle:n.documentEle})});return await Promise.all(c),s};remove=(t="",n=document)=>new Promise(s=>{const c=n.getElementById(t);if(!c){this.#e.warn(`style with id ${t} not found`),s();return}c.remove(),s()});removeDynamicImportedStyles=(t,n)=>{const s=new RegExp(B(t),"i"),c=n.querySelectorAll('[rel="stylesheet"]');for(let h=c.length-1;h>=0;h-=1){const m=c[h],{href:b}=m;s.test(b)&&m.remove()}}}const Mn=r=>r.replace(/\/\d+\.\d+/,"/latest"),$n=r=>{let t;try{t=new URL(r)}catch{return!1}return t.protocol==="http:"||t.protocol==="https:"},ur=new Map,Dt={get:async({hostUrl:r,manifestPath:t})=>{const n=new URL(`${t}manifest.json`,r),s=O(n.href),c=ur.get(s);if(c)return c;const h=async m=>{const b=await fetch(m);if(!b.ok)throw new Error(`unable to get manifest ${m}`);if(!(b.headers?.get?.("content-type")??"").includes("application/json"))throw new Error(`manifest ${m} is not a valid json`);const E=await b.json();return ur.set(m,E),E};try{return await h(s)}catch(m){const b=Mn(t);if(t!==b){const S=O(new URL(`${b}manifest.json`,r).href);return await h(S)}throw m}},getFullFileNameofAssets:(r,t=[])=>t.reduce((n,s)=>{const c=r[s];if(c)n.push(c);else if($n(s))n.push(s);else throw new Error(`unable to locate ${s} in manifest`);return n},[]),clearCache:()=>ur.clear()};class Nr{#e;#t;#r;#o;#n;constructor(t){this.#t=t.guest,this.#e=t.containerId,this.#r=t?.version||x,this.#o=t.soManager,this.#n=t.eventManager}get version(){return this.#r}getObject=t=>{try{const n=this.#o.getObject(t,this.#t);if(!n)return Promise.resolve(null);const s=new Gt(n.id,n.objectType);return Object.keys(n).forEach(c=>{const h=n[c];h instanceof ae?Object.defineProperty(s,c,{value:new ae({name:c,objectId:n.id}),enumerable:!0}):re(h,c)&&Object.defineProperty(s,c,{value:(...m)=>{const b=s[c]?.callContext?.callChain;return Object.defineProperty(h,"callContext",{value:{guest:this.#t,...b?.length?{callChain:b}:{}},configurable:!0,enumerable:!0,writable:!0}),n[c](...m)},enumerable:!0})}),Promise.resolve(s)}catch(n){return Promise.reject(n)}};setAppWindowSize=t=>{if(!this.#e)return;const{size:n}=t,s=document.getElementById(this.#e);s&&(s.style.height=`${n.height}px`,s.style.width=`${n.width}px`)};subscribe=t=>this.#n.subscribe(t);unsubscribe=t=>{this.#n.unsubscribe(t)}}class Fn{constructor(){window.emui||(window.emui={}),window.emui.registerApp=this.#e}#e=({appId:t,app:n})=>{if(!t)throw new Error("appId is required");if(t==="__proto__"||t==="constructor"||t==="prototype")throw new Error(`Invalid appId: ${t}`);if(!n?.uuid)throw new Error("application uuid is required");if(window.emui[t]=window.emui[t]||[],Array.isArray(window.emui[t])){const s=window.emui[t].findIndex(c=>c.uuid===n.uuid);s>-1?window.emui[t][s]=n:window.emui[t].push(n)}else{let s=window.emui[t];s?.uuid===n.uuid?(s={...s,...n},window.emui[t]=[s]):typeof s.init>"u"?window.emui[t]=[{...s,...n}]:window.emui[t]=[window.emui[t],n]}};get=({id:t,instanceId:n})=>{const s=window.emui?.[t];return Array.isArray(s)?s.find(h=>h.uuid===n)??null:s?.uuid===n?s:null};add=({id:t,instanceId:n,documentEle:s})=>{if(!n)throw new Error(`instanceId (uuid) is required to register application ${t}`);const c={uuid:n,init:null,mount:null,unmount:null},h=window.emui[t];h?Array.isArray(h)?h.push(c):window.emui[t]=[h,c]:window.emui[t]=[c],s.defaultView&&(s.defaultView.emui=s.defaultView.emui??{},s.defaultView.emui.uuid=n)};delete=({id:t,instanceId:n})=>{if(Array.isArray(window.emui[t])){const s=window.emui[t].findIndex(c=>c.uuid===n);s>-1&&window.emui[t].splice(s,1),window.emui[t].length===0&&delete window.emui[t]}else delete window.emui[t]}}const Ln=12e4,kr=["click","scroll","keypress","touchstart"],Dn=/\.css$/,Ur=r=>Dn.test(r);class Nn{#e;#t;#r;#o;#n;#i=new In;#s;#l;#a=new Map;#u=new Map;#c=new Fn;#p=!0;constructor(t){const{logger:n}=t;if(!n)throw new Error("logger is required");this.#e=t.logger,this.#t=t.version,this.#p=t.extendSession??!0,this.#n=new R({version:t.version,baseUrl:t.appConfigBaseUrl}),this.#r=new Lr(n),this.#o=new Dr(n),this.#s=new Vt,this.#l=new Ht(this.#e)}#g(t){return typeof t=="function"}#m=t=>t instanceof A||typeof t?.subscribe=="function";#v=(t,n)=>`Application ${t} with instance id ${n} is not found. Most probably the appId property of app.config.json is not set to ${t}`;#y=(t,n=document)=>{const{elementIds:s}=this.#a.get(t)||{};s&&s.forEach(c=>{const h=n.getElementById(c);h&&h.remove()})};#b=({id:t,instanceId:n,documentEle:s,elementIds:c,microFEHost:h})=>{const m=this.#c.get({id:t,instanceId:n});if(!m)throw new Error(this.#v(t,n));this.#a.set(n,{id:t,instanceId:n,elementIds:c,guest:{guestWindow:s?.defaultView,...m},microFEHost:h})};#w=async({id:t,instanceId:n,containerId:s,hostUrl:c,manifestPath:h,homeRoute:m,initialRoute:b,history:S,theme:E,microFEHost:T})=>{const I=this.#c.get({id:t,instanceId:n});if(!I)throw new Error(`Application ${t} with instance id ${n} is not found. Most probably the appId property of app.config.json is not set to ${t}`);if(!I.init||typeof I.init!="function")throw new Error(`Application ${t} with instance id ${n} doesn't expose init method`);const k=T??new Nr({guest:{id:t},version:this.#t,containerId:s,logger:this.#e,soManager:this.#s,eventManager:this.#l});return I.init({host:k,hostUrl:c,manifestPath:h,homeRoute:m,initialRoute:b,prevState:null,history:S,theme:E,hostBreakpoint:$r(),hostViewportSize:lr(),logger:this.#e})};#x=async t=>{try{const{id:n,instanceId:s,files:c,name:h,hostUrl:m,documentEle:b,isJsModule:S}=t;this.#e.debug(`Application ${n} with instance id ${s} is loading...`);let E=c;const T=t.manifest??await Dt.get(t);E=Dt.getFullFileNameofAssets(T,c);const I=E.filter(D=>Ur(D)),k=E.filter(D=>!Ur(D)),K={name:h,hostUrl:m,documentEle:b,isESMModule:S},[V,X]=await Promise.all([this.#o.load(I,K),this.#r.load(k,K)]);this.#b({id:n,instanceId:s,documentEle:b,elementIds:[...V,...X],microFEHost:t.microFEHost}),t.selfInitialize||await this.#w(t),this.#e.audit(`Application ${n} with instance id ${s} loaded`)}catch(n){const s=`Application load failed. Unable to load one or more resources for ${t.id} with instance id ${t.instanceId}. ${n.message}`;throw this.#e.error({message:s,appId:t.id,exception:n}),new Error(s)}};#d=({id:t,instanceId:n,hostUrl:s,documentEle:c})=>{this.#e.debug(`Application ${t} with instance id ${n} unloading...`),this.#c.get({id:t,instanceId:n})&&(this.#y(n,c),this.#r.removeDynamicImportedScripts(s,c),this.#r.removePrefetchLinks(s,c),this.#o.removeDynamicImportedStyles(s,c),this.#c.delete({id:t,instanceId:n}),this.#e.audit(`Application ${t} with instance id ${n} unloaded`))};#f=async({id:t,instanceId:n})=>{const s=this.#c.get({id:t,instanceId:n});if(!s?.mount||typeof s?.mount!="function")throw new Error(`Application ${t} with instance id ${n} doesn't expose mount method`);return s.mount({containerId:`${ft}${t}`,hostBreakpoint:$r(),hostViewportSize:lr()})};#h=({id:t,instanceId:n})=>{const s=this.#c.get({id:t,instanceId:n});if(!s?.unmount)return null;if(typeof s.unmount!="function")throw new Error(`Application ${t} with instance id ${n} doesn't expose unmount method`);return s.unmount({containerId:`${ft}${t}`})};#S=({id:t,instanceId:n})=>{if(this.#p)try{const s=this.#s.getObject(nt.Application);if(!s){this.#e.warn({message:`Application scripting object not available for ${t} to manage session`});return}const c=this.#a.get(n);if(!c)return;c.keepAlive=W()(async()=>{try{await s.keepSessionAlive()}catch(m){this.#e.error(`Error keeping session alive. ${m.message}`)}},Ln);const h=Re.get(n);kr.forEach(m=>{h?.contentDocument?.addEventListener(m,c.keepAlive)})}catch(s){this.#e.warn({message:`Application scripting object not available for ${t} to manage session`,exception:s})}};#A=(t,n)=>{const h=this.#s.getObject(nt.Module,{id:t})?._setUnloadHandler;typeof h=="function"&&h(()=>this.closeApp(n))};#E=async t=>{const n=this.#s.getObject(nt.Module,{id:t});if(!n)return!0;try{const s=await this.#l.dispatchEvent(n,{event:{id:"module.unloading",name:"unloading"},eventParams:{moduleId:t},eventOptions:{timeout:1e3}});if(Array.isArray(s)&&s.some(c=>c===!1))return this.#e.info(`Unload denied by guest ${t} via module.unloading event`),!1}catch(s){this.#e.warn({message:`Error dispatching module.unloading event for ${t}`,exception:s})}return!0};#C=t=>{if(!this.#p||!t)return;const{keepAlive:n,instanceId:s}=t;if(n){const h=Re.get(s)?.contentDocument;h&&kr.forEach(m=>{h.removeEventListener(m,n)}),t.keepAlive?.cancel()}};addScriptingObject=(t,n)=>{if(Ot(t)){const s=this.cloneScriptingObject(t);this.#s.addScriptingObject(s,n)}else this.#s.addScriptingObject(t,n)};cloneScriptingObject=t=>{if(!t)throw new Error("proxy is required");const n=new fe(t.id,t.objectType);let s=[];return Object.keys(t).forEach(c=>{const h=t[c];if(this.#m(h)){const m=new ae({name:h.name||c,objectId:n.id});Object.defineProperty(n,c,{value:m,enumerable:!0});const b=({eventParams:E,eventOptions:T})=>this.dispatchEvent({event:m,eventParams:E,eventOptions:T}),S=h.subscribe(b);s.push(()=>{h.unsubscribe(S)})}else if(this.#g(h)&&(Object.defineProperty(n,c,{value:async(...m)=>{const b=n[c]?.callContext;if(b?.guest){const E=b.callChain??[],T=b.guest.id,I=this.#u.get(T),k={id:T};I&&(k.metadata=I),Object.defineProperty(h,"callContext",{value:{callChain:[...E,k]},configurable:!0,enumerable:!0,writable:!0})}const S=await h(...m);return Ot(S)?this.cloneScriptingObject(S):S},enumerable:!0}),c==="dispose")){const m=n.dispose;Object.defineProperty(n,c,{value:()=>(n._dispose(),m.apply(n)),enumerable:!0})}}),n._dispose=()=>{s.forEach(c=>{c?.()}),s=[]},n};closeAllApps=async()=>{await Promise.all([...this.#a.keys()].map(this.closeApp))};closeApp=async t=>{if(!t)throw new Error("instanceId is required");const n=this.#a.get(t);if(!n){this.#e.warn(`Application with instance id ${t} is not found`);return}const{id:s}=n;if(!await this.#E(s))return;const c=this.#i.getConfigById(s);if(!c){this.#e.warn(`Configuration for application ${s} is not found`),this.#a.delete(t),Re.remove(t);return}const{hostUrl:h}=c;try{this.#C(n),await this.#h({id:s,instanceId:t})}finally{const m=Re.get(t);m?.contentDocument&&this.#d({id:s,instanceId:t,hostUrl:h,documentEle:m.contentDocument}),this.#a.delete(t),this.#u.delete(s),Re.remove(t)}};dispatchEvent=async t=>{const{event:{id:n,name:s},eventOptions:c={}}=t,{guestId:h}=c;if(!n)throw new Error("Event Id is required");const m=n.split(".")?.[0],b=h?this.#s.getObject(m,{id:h}):this.#s.getObject(m);return b?this.#l.dispatchEvent(b,t):(this.#e.warn(`Attempt to dispatch event ${s} on unknown object ${m}`),Promise.resolve())};getApp=t=>this.#a.get(t)?.guest;getApps=()=>[...this.#a.values()].map(t=>t.guest);init=async t=>{t?this.#n.setPreloadedConfig(t):await this.#n.load(),this.#i.init({version:this.#t,appConfig:this.#n}),this.#O()};#O=()=>{const t=this.#n.get("microFrontendApps")??{},n=new Set;Object.keys(t).forEach(s=>{const c=this.#i.getConfigById(s);if(c?.hostUrl)try{n.add(new URL(c.hostUrl).origin)}catch{}}),n.forEach(s=>{const c=document.createElement("link");c.rel="preconnect",c.href=s,c.crossOrigin="anonymous",document.head.appendChild(c)})};mountApp=async t=>{if(!t)throw new Error("instanceId is required");const{id:n}=this.#a.get(t)||{};if(!n)throw new Error(`Application with instance id ${t} is not found`);const s=this.#i.getConfigById(n);if(!s)throw new Error(`Application with id ${n} is not found`);await this.#f({...s,instanceId:t})};#T=(t,n,s)=>{const c=new Nr({guest:{id:s.id},version:this.#t,containerId:s.containerId,logger:this.#e,soManager:this.#s,eventManager:this.#l}),h=t.defaultView;h&&(h.emui=h.emui??{},h.emui.__host=c,h.emui.getHost=()=>h.emui?.__host??null);const m=t.createElement("link");return m.rel="preconnect",m.href=n.hostUrl,m.crossOrigin="anonymous",t.head.appendChild(m),c};openApp=async t=>{const{id:n,frameOptions:s,history:c,theme:h,homeRoute:m,initialRoute:b,metadata:S,selfInitialize:E}=t,T=Et();S&&this.#u.set(n,S);const I=this.#i.getConfigById(n);if(!I)throw new Error(`Application ${n} is not found in app config`);const k=Dt.get(I);k.catch(()=>{});const K=await Re.create({id:n,instanceId:T,manifestPath:I.manifestPath,hostUrl:I.hostUrl,options:{title:I.name,...s}});if(!K?.contentDocument)throw new Error("unable to create iframe for the microapp");try{this.#c.add({id:n,instanceId:T,documentEle:K.contentDocument});const V=this.#T(K.contentDocument,I,{id:n,containerId:s?.containerId}),X=await k;return await this.#x({instanceId:T,history:c,theme:h,documentEle:K.contentDocument,containerId:s?.containerId,...I,homeRoute:m??I.homeRoute,initialRoute:b,microFEHost:V,selfInitialize:E,manifest:X}),E||await this.#f({instanceId:T,...I}),this.#S({id:n,instanceId:T}),this.#A(n,T),T}catch(V){throw this.#d({id:n,instanceId:T,hostUrl:I.hostUrl,documentEle:K.contentDocument}),Re.remove(T),V}};removeAllEventSubscriptions=()=>{this.#l.unsubscribeAll()};removeAllScriptingObjects=t=>{this.#s.removeAllScriptingObjects(t)};removeScriptingObject=(t,n)=>{this.#s.removeScriptingObject(t,n)};warmUp=t=>{const n=this.#i.getConfigById(t);n&&Dt.get(n).catch(()=>{})};unmountApp=async t=>{if(!t)throw new Error("instanceId is required");const{id:n}=this.#a.get(t)||{};if(!n)throw new Error(`Application with instance id ${t} is not found`);const s=this.#i.getConfigById(n);if(!s)throw new Error(`Application with id ${n} is not found`);await this.#h({...s,instanceId:t})}}})(),kt})());
|
|
16
16
|
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
package/dist/umd/index.js.br
CHANGED
|
Binary file
|
package/dist/umd/index.js.gz
CHANGED
|
Binary file
|