mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
9 lines
52 KiB
JavaScript
Vendored
9 lines
52 KiB
JavaScript
Vendored
const ht="0.8.11",we=typeof window!="undefined",dt=typeof global!="undefined"?global:typeof window!="undefined"?window:typeof self!="undefined"?self:Function("return this")();function mt(t){return t===void 0}function M(t){return typeof t=="string"}function Ne(t){return typeof t=="boolean"}function _(t){return typeof t=="function"}const k=Array.isArray;function v(t){return toString.call(t)==="[object Object]"}function Ae(t){return toString.call(t)==="[object Promise]"}function ge(t){return _(t)&&t.name.indexOf("bound ")===0&&!t.hasOwnProperty("prototype")}function ft(t){return typeof ShadowRoot!="undefined"&&t instanceof ShadowRoot}const G=Object.defineProperty,pt=Object.defineProperties,$=Object.prototype.hasOwnProperty;function m(t,e=null,...n){const s=e&&M(e)?` app ${e}:`:"";M(t)?console.error(`[micro-app]${s} ${t}`,...n):console.error(`[micro-app]${s}`,t,...n)}function te(t,e=null,...n){const s=e&&M(e)?` app ${e}:`:"";M(t)?console.warn(`[micro-app]${s} ${t}`,...n):console.warn(`[micro-app]${s}`,t,...n)}function I(t,...e){Promise.resolve().then(t.bind(null,...e))}function Re(t){return t.startsWith("//")?`${location.protocol}${t}`:t}function Ee(t,e=null){if(!M(t)||!t)return"";try{const{origin:n,pathname:s,search:r}=new URL(Re(t));if(/\.(\w+)$/.test(s))return`${n}${s}${r}`;const i=`${n}${s}/`.replace(/\/\/$/,"/");return/^https?:\/\//.test(i)?`${i}${r}`:""}catch(n){return m(n,e),""}}function C(t){return!M(t)||!t?"":t.replace(/(^\d+)|([^\w\d-_])/gi,"")}function je(t){const{origin:e,pathname:n}=new URL(t);if(/\.(\w+)$/.test(n)){const r=`${e}${n}`.split("/");return r.pop(),r.join("/")+"/"}return`${e}${n}/`.replace(/\/\/$/,"/")}function L(t,e){return!t||/^((((ht|f)tps?)|file):)?\/\//.test(t)||/^(data|blob):/.test(t)?t:new URL(t,je(Re(e))).toString()}function _t(t){const e=t.split("/");return e.pop(),Re(e.join("/")+"/")}function me(t,e,n,s){let r=0;function i(){++r===t.length&&s&&s()}t.forEach((o,c)=>{Ae(o)?o.then(u=>{e({data:u,index:c}),i()}).catch(u=>{n({error:u,index:c}),i()}):(e({data:o,index:c}),i())})}function bt(){const t=document.createElement("script");return"noModule"in t}function At(){return"inline-"+Math.random().toString(36).substr(2,15)}function gt(t){return t.filter(function(e){return e in this?!1:this[e]=!0},Object.create(null))}const Pe=dt.requestIdleCallback||function(t){const e=Date.now();return setTimeout(function(){t({didTimeout:!1,timeRemaining(){return Math.max(0,50-(Date.now()-e))}})},50)};let Ce=null;function q(t){Ce=t}function ce(t){Ce!==t&&(q(t),I(()=>{q(null)}))}function w(){return Ce}function fe(){q(null)}function K(t,e){const n=document.createElement(t,e);return n.__MICRO_APP_NAME__&&delete n.__MICRO_APP_NAME__,n}function le(t,e,n){if(e.innerHTML="",n){const s=t.cloneNode(!0),r=document.createDocumentFragment();Array.from(s.childNodes).forEach(i=>{r.appendChild(i)}),e.appendChild(r)}else Array.from(t.childNodes).forEach(s=>{e.appendChild(s)})}function ue(t){return!t||/(^\d)|([^\w\d-_\u4e00-\u9fa5])/gi.test(t)}function pe(t){return/^body$/i.test(t)||/^head$/i.test(t)||/^html$/i.test(t)}function ne(t){return ft(t)?t.host:t}function _e(t){return t?t.replace(/^\s+|\s+$/g,""):""}function Le(){return navigator.userAgent.indexOf("Firefox")>-1}var Q;(function(t){t.NAME="name",t.URL="url"})(Q||(Q={}));var b;(function(t){t.NOT_LOADED="NOT_LOADED",t.LOADING_SOURCE_CODE="LOADING_SOURCE_CODE",t.LOAD_SOURCE_FINISHED="LOAD_SOURCE_FINISHED",t.LOAD_SOURCE_ERROR="LOAD_SOURCE_ERROR",t.MOUNTING="MOUNTING",t.MOUNTED="MOUNTED",t.UNMOUNT="UNMOUNT"})(b||(b={}));var S;(function(t){t.CREATED="created",t.BEFOREMOUNT="beforemount",t.MOUNTED="mounted",t.UNMOUNT="unmount",t.ERROR="error",t.BEFORESHOW="beforeshow",t.AFTERSHOW="aftershow",t.AFTERHIDDEN="afterhidden"})(S||(S={}));var y;(function(t){t.KEEP_ALIVE_SHOW="KEEP_ALIVE_SHOW",t.KEEP_ALIVE_HIDDEN="KEEP_ALIVE_HIDDEN"})(y||(y={}));const Ue="window,self,globalThis,Array,Object,String,Boolean,Math,Number,Symbol,Date,Promise,Function,Proxy,WeakMap,WeakSet,Set,Map,Reflect,Element,Node,Document,RegExp,Error,TypeError,JSON,isNaN,parseFloat,parseInt,performance,console,decodeURI,encodeURI,decodeURIComponent,encodeURIComponent,location,navigator,undefined";function j(t,e=null,n={}){return _(p.fetch)?p.fetch(t,n,e):fetch(t,n).then(s=>s.text())}class De{static getInstance(){return this.instance||(this.instance=new De),this.instance}run(e,n){const s=e.name,r=e.ssrUrl||e.url;j(r,s,{cache:"no-cache"}).then(i=>{if(!i){const o="html is empty, please check in detail";return e.onerror(new Error(o)),m(o,s)}i=this.formatHTML(r,i,s),n(i,e)}).catch(i=>{m(`Failed to fetch data from ${e.url}, micro-app stop rendering`,s,i),e.onLoadError(i)})}formatHTML(e,n,s){return this.processHtml(e,n,s,p.plugins).replace(/<head[^>]*>[\s\S]*?<\/head>/i,r=>r.replace(/<head/i,"<micro-app-head").replace(/<\/head>/i,"</micro-app-head>")).replace(/<body[^>]*>[\s\S]*?<\/body>/i,r=>r.replace(/<body/i,"<micro-app-body").replace(/<\/body>/i,"</micro-app-body>"))}processHtml(e,n,s,r){var i;if(!r)return n;const o=[];return r.global&&o.push(...r.global),!((i=r.modules)===null||i===void 0)&&i[s]&&o.push(...r.modules[s]),o.length>0?o.reduce((c,u)=>v(u)&&_(u.processHtml)?u.processHtml(c,e,u.options):c,n):n}}const Et=/(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/,xe=/(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/;function P(t,e){t=e?`${e} ${t}`:t;const n=new Error(t);throw n.reason=t,e&&(n.filename=e),n}class vt{constructor(){this.cssText="",this.prefix="",this.baseURI="",this.linkPath="",this.result="",this.scopecssDisable=!1,this.scopecssDisableSelectors=[],this.scopecssDisableNextLine=!1,this.mediaRule=this.createMatcherForAtRuleWithChildRule(/^@media *([^{]+)/,"media"),this.supportsRule=this.createMatcherForAtRuleWithChildRule(/^@supports *([^{]+)/,"supports"),this.documentRule=this.createMatcherForAtRuleWithChildRule(/^@([-\w]+)?document *([^{]+)/,"document"),this.hostRule=this.createMatcherForAtRuleWithChildRule(/^@host\s*/,"host"),this.importRule=this.createMatcherForNoneBraceAtRule("import"),this.charsetRule=this.createMatcherForNoneBraceAtRule("charset"),this.namespaceRule=this.createMatcherForNoneBraceAtRule("namespace")}exec(e,n,s,r){return this.cssText=e,this.prefix=n,this.baseURI=s,this.linkPath=r||"",this.matchRules(),Le()?decodeURIComponent(this.result):this.result}reset(){this.cssText=this.prefix=this.baseURI=this.linkPath=this.result="",this.scopecssDisable=this.scopecssDisableNextLine=!1,this.scopecssDisableSelectors=[]}matchRules(){for(this.matchLeadingSpaces(),this.matchComments();this.cssText.length&&this.cssText.charAt(0)!=="}"&&(this.matchAtRule()||this.matchStyleRule());)this.matchComments()}matchStyleRule(){const e=this.formatSelector(!0);return this.scopecssDisableNextLine=!1,e?(this.recordResult(e),this.matchComments(),this.styleDeclarations(),this.matchLeadingSpaces(),!0):P("selector missing",this.linkPath)}formatSelector(e){const n=this.commonMatch(/^([^{]+)/,e);return n?n[0].replace(/(^|,[\n\s]*)([^,]+)/g,(s,r,i)=>(i=_e(i),this.scopecssDisableNextLine||this.scopecssDisable&&(!this.scopecssDisableSelectors.length||this.scopecssDisableSelectors.includes(i))||Et.test(i)||(xe.test(i)?i=i.replace(xe,this.prefix+" micro-app-body"):i=this.prefix+" "+i),r+i)):!1}styleDeclarations(){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?!0:P("Declaration missing '}'",this.linkPath)):P("Declaration missing '{'",this.linkPath)}matchAllDeclarations(){let e=this.commonMatch(/^(?:url\(["']?(?:[^)"'}]+)["']?\)|[^}/])*/,!0)[0];if(e&&(!this.scopecssDisableNextLine&&(!this.scopecssDisable||this.scopecssDisableSelectors.length)&&(e=e.replace(/url\(["']?([^)"']+)["']?\)/gm,(n,s)=>/^((data|blob):|#)/.test(s)||/^(https?:)?\/\//.test(s)?n:(/^((\.\.?\/)|[^/])/.test(s)&&this.linkPath&&(this.baseURI=_t(this.linkPath)),`url("${L(s,this.baseURI)}")`))),this.recordResult(e)),this.scopecssDisableNextLine=!1,!(!this.cssText||this.cssText.charAt(0)==="}"))return this.cssText.charAt(0)==="/"&&this.cssText.charAt(1)==="*"?this.matchComments():this.commonMatch(/\/+/),this.matchAllDeclarations()}matchAtRule(){return this.cssText[0]!=="@"?!1:(this.scopecssDisableNextLine=!1,this.keyframesRule()||this.mediaRule()||this.customMediaRule()||this.supportsRule()||this.importRule()||this.charsetRule()||this.namespaceRule()||this.documentRule()||this.pageRule()||this.hostRule()||this.fontFaceRule())}keyframesRule(){if(!this.commonMatch(/^@([-\w]+)?keyframes\s*/))return!1;if(!this.commonMatch(/^([-\w]+)\s*/))return P("@keyframes missing name",this.linkPath);if(this.matchComments(),!this.matchOpenBrace())return P("@keyframes missing '{'",this.linkPath);for(this.matchComments();this.keyframeRule();)this.matchComments();return this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):P("@keyframes missing '}'",this.linkPath)}keyframeRule(){let e;const n=[];for(;e=this.commonMatch(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)n.push(e[1]),this.commonMatch(/^,\s*/);return n.length?(this.styleDeclarations(),this.matchLeadingSpaces(),!0):!1}customMediaRule(){return this.commonMatch(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/)?(this.matchLeadingSpaces(),!0):!1}pageRule(){return this.commonMatch(/^@page */)?(this.formatSelector(!1),this.scopecssDisableNextLine=!1,this.commonHandlerForAtRuleWithSelfRule("page")):!1}fontFaceRule(){return this.commonMatch(/^@font-face\s*/)?this.commonHandlerForAtRuleWithSelfRule("font-face"):!1}createMatcherForAtRuleWithChildRule(e,n){return()=>this.commonMatch(e)?this.matchOpenBrace()?(this.matchComments(),this.matchRules(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):P(`@${n} missing '}'`,this.linkPath)):P(`@${n} missing '{'`,this.linkPath):!1}createMatcherForNoneBraceAtRule(e){const n=new RegExp("^@"+e+"\\s*([^;]+);");return()=>this.commonMatch(n)?(this.matchLeadingSpaces(),!0):!1}commonHandlerForAtRuleWithSelfRule(e){return this.matchOpenBrace()?(this.matchAllDeclarations(),this.matchCloseBrace()?(this.matchLeadingSpaces(),!0):P(`@${e} missing '}'`,this.linkPath)):P(`@${e} missing '{'`,this.linkPath)}matchComments(){for(;this.matchComment(););}matchComment(){if(this.cssText.charAt(0)!=="/"||this.cssText.charAt(1)!=="*")return!1;this.scopecssDisableNextLine=!1;let e=2;for(;this.cssText.charAt(e)!==""&&(this.cssText.charAt(e)!=="*"||this.cssText.charAt(e+1)!=="/");)++e;if(e+=2,this.cssText.charAt(e-1)==="")return P("End of comment missing",this.linkPath);let n=this.cssText.slice(2,e-2);return this.recordResult(`/*${n}*/`),n=_e(n.replace(/^\s*!/,"")),n==="scopecss-disable-next-line"?this.scopecssDisableNextLine=!0:/^scopecss-disable/.test(n)?n==="scopecss-disable"?this.scopecssDisable=!0:(this.scopecssDisable=!0,n.replace("scopecss-disable","").split(",").forEach(r=>{this.scopecssDisableSelectors.push(_e(r))})):n==="scopecss-enable"&&(this.scopecssDisable=!1,this.scopecssDisableSelectors=[]),this.cssText=this.cssText.slice(e),this.matchLeadingSpaces(),!0}commonMatch(e,n=!1){const s=e.exec(this.cssText);if(!s)return;const r=s[0];return this.cssText=this.cssText.slice(r.length),n||this.recordResult(r),s}matchOpenBrace(){return this.commonMatch(/^{\s*/)}matchCloseBrace(){return this.commonMatch(/^}/)}matchLeadingSpaces(){this.commonMatch(/^\s*/)}recordResult(e){Le()?this.result+=encodeURIComponent(e):this.result+=e}}function Te(t,e,n,s,r){if(!t.__MICRO_APP_HAS_SCOPED__){t.__MICRO_APP_HAS_SCOPED__=!0;let i=null;try{i=J.exec(t.textContent,n,s,r),J.reset()}catch(o){J.reset(),m(`An error occurred while parsing CSS:
|
|
`,e,o)}i&&(t.textContent=i)}}let J;function W(t,e){if(e.scopecss){const n=`${p.tagName}[name=${e.name}]`;if(J||(J=new vt),t.textContent)Te(t,e.name,n,e.url,t.__MICRO_APP_LINK_PATH__);else{const s=new MutationObserver(function(){s.disconnect(),t.textContent&&!t.hasAttribute("data-styled")&&Te(t,e.name,n,e.url,t.__MICRO_APP_LINK_PATH__)});s.observe(t,{childList:!0})}}return t}function Ge(t,e){Object.defineProperties(t,{currentTarget:{get(){return e}},srcElement:{get(){return e}},target:{get(){return e}}})}function X(t){const e=new CustomEvent("load");Ge(e,t),_(t.onload)?t.onload(e):t.dispatchEvent(e)}function ke(t){const e=new CustomEvent("error");Ge(e,t),_(t.onerror)?t.onerror(e):t.dispatchEvent(e)}const F=new Map;function qe(t,e,n,s=!1){const r=t.getAttribute("rel");let i=t.getAttribute("href"),o=null;if(r==="stylesheet"&&i)if(i=L(i,n.url),!s)o=document.createComment(`link element with href=${i} move to micro-app-head as style element`),n.source.links.set(i,{code:"",placeholder:o,isGlobal:t.hasAttribute("global")});else return{url:i,info:{code:"",isGlobal:t.hasAttribute("global")}};else r&&["prefetch","preload","prerender","icon","apple-touch-icon"].includes(r)?s?o=document.createComment(`link element with rel=${r}${i?" & href="+i:""} removed by micro-app`):e.removeChild(t):i&&t.setAttribute("href",L(i,n.url));if(s)return{replaceComment:o};if(o)return e.replaceChild(o,t)}function wt(t,e,n){const s=Array.from(e.source.links.entries()),r=s.map(([i])=>F.has(i)?F.get(i):j(i,e.name));me(r,i=>{Nt(s[i.index][0],s[i.index][1],i.data,n,e)},i=>{m(i,e.name)},()=>{e.onLoad(t)})}function Nt(t,e,n,s,r){e.isGlobal&&!F.has(t)&&F.set(t,n);const i=K("style");i.textContent=n,i.__MICRO_APP_LINK_PATH__=t,i.setAttribute("data-origin-href",t),e.placeholder.parentNode?e.placeholder.parentNode.replaceChild(W(i,r),e.placeholder):s.appendChild(W(i,r)),e.placeholder=null,e.code=n}function Rt(t,e,n,s,r){if(n.source.links.has(t)){r.textContent=n.source.links.get(t).code,W(r,n),I(()=>X(s));return}if(F.has(t)){const i=F.get(t);e.code=i,n.source.links.set(t,e),r.textContent=i,W(r,n),I(()=>X(s));return}j(t,n.name).then(i=>{e.code=i,n.source.links.set(t,e),e.isGlobal&&F.set(t,i),r.textContent=i,W(r,n),X(s)}).catch(i=>{m(i,n.name),ke(s)})}const U=new WeakMap;function Pt(t,e,n){if(e instanceof HTMLStyleElement){if(e.hasAttribute("exclude")){const s=document.createComment("style element with exclude attribute ignored by micro-app");return U.set(e,s),s}else if(n.scopecss&&!e.hasAttribute("ignore"))return W(e,n);return e}else if(e instanceof HTMLLinkElement){if(e.hasAttribute("exclude")||Me(e.getAttribute("href"),n.name)){const o=document.createComment("link element with exclude attribute ignored by micro-app");return U.set(e,o),o}else if(e.hasAttribute("ignore")||Se(e.getAttribute("href"),n.name)||e.href&&_(p.excludeAssetFilter)&&p.excludeAssetFilter(e.href))return e;const{url:s,info:r,replaceComment:i}=qe(e,t,n,!0);if(s&&r){const o=K("style");return o.__MICRO_APP_LINK_PATH__=s,Rt(s,r,n,e,o),U.set(e,o),o}else if(i)return U.set(e,i),i;return e}else if(e instanceof HTMLScriptElement){if(e.src&&_(p.excludeAssetFilter)&&p.excludeAssetFilter(e.src))return e;const{replaceComment:s,url:r,info:i}=Xe(e,t,n,!0)||{};if(r&&i)if(i.isExternal){const o=Wt(r,i,n,e);return U.set(e,o),o}else{const o=Z(r,n,i,!0);return U.set(e,o),o}else if(s)return U.set(e,s),s;return e}return e}function Ve(t,e,n,s,r){const i=Dt(n,t);return i?r&&!i.contains(r)?a.rawAppendChild.call(i,s):e===a.rawRemoveChild&&!i.contains(s)?n.contains(s)?e.call(n,s):s:Fe(e,i,s,r):Fe(e,n,s,r)}function Fe(t,e,n,s){return Ct(t)?t.call(e,n):t.call(e,n,s)}function Ct(t){return t===a.rawAppend||t===a.rawPrepend}function Dt(t,e){var n,s;return t===document.head?(n=e==null?void 0:e.container)===null||n===void 0?void 0:n.querySelector("micro-app-head"):t===document.body?(s=e==null?void 0:e.container)===null||s===void 0?void 0:s.querySelector("micro-app-body"):null}function ze(t){var e;return(e=U.get(t))!==null&&e!==void 0?e:t}function z(t,e,n,s){if(e!=null&&e.__MICRO_APP_NAME__){const r=f.get(e.__MICRO_APP_NAME__);return r!=null&&r.container?Ve(r,s,t,Pt(t,e,r),n&&ze(n)):s===a.rawAppend||s===a.rawPrepend?s.call(t,e):s.call(t,e,n)}else if(s===a.rawAppend||s===a.rawPrepend){const r=w();if(!(e instanceof Node)&&r){const i=f.get(r);if(i!=null&&i.container){if(t===document.head)return s.call(i.container.querySelector("micro-app-head"),e);if(t===document.body)return s.call(i.container.querySelector("micro-app-body"),e)}}return s.call(t,e)}return s.call(t,e,n)}function Mt(){St(),Element.prototype.appendChild=function(e){return z(this,e,null,a.rawAppendChild)},Element.prototype.insertBefore=function(e,n){return z(this,e,n,a.rawInsertBefore)},Element.prototype.replaceChild=function(e,n){return z(this,e,n,a.rawReplaceChild)},Element.prototype.append=function(...e){let n=0;const s=e.length;for(;n<s;)z(this,e[n],null,a.rawAppend),n++},Element.prototype.prepend=function(...e){let n=e.length;for(;n>0;)z(this,e[n-1],null,a.rawPrepend),n--},Element.prototype.removeChild=function(e){if(e!=null&&e.__MICRO_APP_NAME__){const n=f.get(e.__MICRO_APP_NAME__);return n!=null&&n.container?Ve(n,a.rawRemoveChild,this,ze(e)):a.rawRemoveChild.call(this,e)}return a.rawRemoveChild.call(this,e)},Element.prototype.cloneNode=function(e){const n=a.rawCloneNode.call(this,e);return this.__MICRO_APP_NAME__&&(n.__MICRO_APP_NAME__=this.__MICRO_APP_NAME__),n}}function be(t){const e=w();return e&&(t.__MICRO_APP_NAME__=e),t}function St(){const t=a.rawDocument;Document.prototype.createElement=function(r,i){const o=a.rawCreateElement.call(this,r,i);return be(o)},Document.prototype.createElementNS=function(r,i,o){const c=a.rawCreateElementNS.call(this,r,i,o);return be(c)},Document.prototype.createDocumentFragment=function(){const r=a.rawCreateDocumentFragment.call(this);return be(r)};function e(s){var r,i,o;const c=w();return!c||!s||pe(s)||t!==this?a.rawQuerySelector.call(this,s):(o=(i=(r=f.get(c))===null||r===void 0?void 0:r.container)===null||i===void 0?void 0:i.querySelector(s))!==null&&o!==void 0?o:null}function n(s){var r,i,o;const c=w();return!c||!s||pe(s)||t!==this?a.rawQuerySelectorAll.call(this,s):(o=(i=(r=f.get(c))===null||r===void 0?void 0:r.container)===null||i===void 0?void 0:i.querySelectorAll(s))!==null&&o!==void 0?o:[]}Document.prototype.querySelector=e,Document.prototype.querySelectorAll=n,Document.prototype.getElementById=function(r){if(!w()||ue(r))return a.rawGetElementById.call(this,r);try{return e.call(this,`#${r}`)}catch{return a.rawGetElementById.call(this,r)}},Document.prototype.getElementsByClassName=function(r){if(!w()||ue(r))return a.rawGetElementsByClassName.call(this,r);try{return n.call(this,`.${r}`)}catch{return a.rawGetElementsByClassName.call(this,r)}},Document.prototype.getElementsByTagName=function(r){var i;const o=w();if(!o||pe(r)||ue(r)||!(!((i=f.get(o))===null||i===void 0)&&i.inline)&&/^script$/i.test(r))return a.rawGetElementsByTagName.call(this,r);try{return n.call(this,r)}catch{return a.rawGetElementsByTagName.call(this,r)}},Document.prototype.getElementsByName=function(r){if(!w()||ue(r))return a.rawGetElementsByName.call(this,r);try{return n.call(this,`[name=${r}]`)}catch{return a.rawGetElementsByName.call(this,r)}}}let ve=!1;function yt(){ve||(ve=!0,Element.prototype.setAttribute=function(e,n){if(/^micro-app(-\S+)?/i.test(this.tagName)&&e==="data")if(v(n)){const s={};Object.getOwnPropertyNames(n).forEach(r=>{M(r)&&r.indexOf("__")===0||(s[r]=n[r])}),this.data=s}else n!=="[object Object]"&&te("property data must be an object",this.getAttribute("name"));else if(((e==="src"||e==="srcset")&&/^(img|script)$/i.test(this.tagName)||e==="href"&&/^link$/i.test(this.tagName))&&this.__MICRO_APP_NAME__&&f.has(this.__MICRO_APP_NAME__)){const s=f.get(this.__MICRO_APP_NAME__);a.rawSetAttribute.call(this,e,L(n,s.url))}else a.rawSetAttribute.call(this,e,n)})}function Ot(){ve=!1,Element.prototype.setAttribute=a.rawSetAttribute}function It(){Document.prototype.createElement=a.rawCreateElement,Document.prototype.createElementNS=a.rawCreateElementNS,Document.prototype.createDocumentFragment=a.rawCreateDocumentFragment,Document.prototype.querySelector=a.rawQuerySelector,Document.prototype.querySelectorAll=a.rawQuerySelectorAll,Document.prototype.getElementById=a.rawGetElementById,Document.prototype.getElementsByClassName=a.rawGetElementsByClassName,Document.prototype.getElementsByTagName=a.rawGetElementsByTagName,Document.prototype.getElementsByName=a.rawGetElementsByName}function Lt(){q(null),It(),Element.prototype.appendChild=a.rawAppendChild,Element.prototype.insertBefore=a.rawInsertBefore,Element.prototype.replaceChild=a.rawReplaceChild,Element.prototype.removeChild=a.rawRemoveChild,Element.prototype.append=a.rawAppend,Element.prototype.prepend=a.rawPrepend,Element.prototype.cloneNode=a.rawCloneNode}let Be=!1;function Ut(){if(!Be){Be=!0;const t=K("style");a.rawSetAttribute.call(t,"type","text/css"),t.textContent=`
|
|
${p.tagName}, micro-app-body { display: block; }
|
|
micro-app-head { display: none; }`,a.rawDocument.head.appendChild(t)}}class de{constructor(){this.appInstanceMap=f}static getInstance(){return this.instance||(this.instance=new de),this.instance}get(e){return this.appInstanceMap.get(e)}set(e,n){this.appInstanceMap.set(e,n)}getAll(){return Array.from(this.appInstanceMap.values())}clear(){this.appInstanceMap.clear()}}function Qe(){Je(),de.getInstance().getAll().forEach(t=>{t.container&&ne(t.container).disconnectedCallback()}),!window.__MICRO_APP_UMD_MODE__&&de.getInstance().clear()}function xt(){window.__MICRO_APP_ENVIRONMENT__&&window.addEventListener("unmount",Qe,!1)}function Je(){window.__MICRO_APP_ENVIRONMENT__&&window.removeEventListener("unmount",Qe,!1)}const a={};function Tt(){if(we){const t=Element.prototype.setAttribute,e=Element.prototype.appendChild,n=Element.prototype.insertBefore,s=Element.prototype.replaceChild,r=Element.prototype.removeChild,i=Element.prototype.append,o=Element.prototype.prepend,c=Element.prototype.cloneNode,u=Document.prototype.createElement,E=Document.prototype.createElementNS,N=Document.prototype.createDocumentFragment,O=Document.prototype.querySelector,B=Document.prototype.querySelectorAll,V=Document.prototype.getElementById,se=Document.prototype.getElementsByClassName,re=Document.prototype.getElementsByTagName,ie=Document.prototype.getElementsByName,oe=new Proxy(Image,{construct(lt,ut){const Ie=new lt(...ut);return Ie.__MICRO_APP_NAME__=w(),Ie}}),R=Function("return window")(),ae=Function("return document")(),ye=bt(),Oe=R.addEventListener,l=R.removeEventListener,d=R.setInterval,h=R.setTimeout,A=R.clearInterval,ot=R.clearTimeout,at=ae.addEventListener,ct=ae.removeEventListener;window.__MICRO_APP_BASE_APPLICATION__=!0,Object.assign(a,{rawSetAttribute:t,rawAppendChild:e,rawInsertBefore:n,rawReplaceChild:s,rawRemoveChild:r,rawAppend:i,rawPrepend:o,rawCloneNode:c,rawCreateElement:u,rawCreateElementNS:E,rawCreateDocumentFragment:N,rawQuerySelector:O,rawQuerySelectorAll:B,rawGetElementById:V,rawGetElementsByClassName:se,rawGetElementsByTagName:re,rawGetElementsByName:ie,ImageProxy:oe,rawWindow:R,rawDocument:ae,supportModuleScript:ye,rawWindowAddEventListener:Oe,rawWindowRemoveEventListener:l,rawSetInterval:d,rawSetTimeout:h,rawClearInterval:A,rawClearTimeout:ot,rawDocumentAddEventListener:at,rawDocumentRemoveEventListener:ct}),Ut(),Je(),xt()}}const H=new Map;function Xe(t,e,n,s=!1){let r=null,i=t.getAttribute("src");if(i&&(i=L(i,n.url)),t.hasAttribute("exclude")||Me(i,n.name))r=document.createComment("script element with exclude attribute removed by micro-app");else{if(t.type&&!["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module","systemjs-module","systemjs-importmap"].includes(t.type)||t.hasAttribute("ignore")||Se(i,n.name))return null;if(a.supportModuleScript&&t.noModule||!a.supportModuleScript&&t.type==="module")r=document.createComment(`${t.noModule?"noModule":"module"} script ignored by micro-app`);else if(i){const o={code:"",isExternal:!0,isDynamic:s,async:t.hasAttribute("async"),defer:t.defer||t.type==="module",module:t.type==="module",isGlobal:t.hasAttribute("global")};if(!s)n.source.scripts.set(i,o),r=document.createComment(`script with src='${i}' extract by micro-app`);else return{url:i,info:o}}else if(t.textContent){const o=At(),c={code:t.textContent,isExternal:!1,isDynamic:s,async:!1,defer:t.type==="module",module:t.type==="module"};if(!s)n.source.scripts.set(o,c),r=document.createComment("inline script extract by micro-app");else return{url:o,info:c}}else s||(r=document.createComment("script element removed by micro-app"))}return s?{replaceComment:r}:e.replaceChild(r,t)}function Ye(t){var e,n,s;const r=((e=p.plugins)===null||e===void 0?void 0:e.global)||[],i=((s=(n=p.plugins)===null||n===void 0?void 0:n.modules)===null||s===void 0?void 0:s[t])||[];return[...r,...i]}function Me(t,e){return t?(Ye(e)||[]).some(s=>s.excludeChecker?s.excludeChecker(t):!1):!1}function Se(t,e){return t?(Ye(e)||[]).some(s=>s.ignoreChecker?s.ignoreChecker(t):!1):!1}function Ft(t,e){const n=Array.from(e.source.scripts.entries()),s=[],r=[];for(const[i,o]of n)if(o.isExternal){const c=H.get(i);c?o.code=c:(!o.defer&&!o.async||e.isPrefetch)&&(s.push(j(i,e.name)),r.push([i,o]))}s.length?me(s,i=>{Bt(r[i.index][0],r[i.index][1],i.data)},i=>{m(i,e.name)},()=>{e.onLoad(t)}):e.onLoad(t)}function Bt(t,e,n){e.isGlobal&&!H.has(t)&&H.set(t,n),e.code=n}function $t(t,e,n){const s=Array.from(t.entries()),r=[],i=[];for(const[o,c]of s)c.isDynamic||(c.defer||c.async?(c.isExternal&&!c.code?r.push(j(o,e.name)):r.push(c.code),i.push([o,c]),c.module&&(n.moduleCount=n.moduleCount?++n.moduleCount:1)):(Z(o,e,c,!1),n(!1)));r.length?me(r,o=>{const c=i[o.index][1];c.code=c.code||o.data},o=>{n.errorCount=n.errorCount?++n.errorCount:1,m(o,e.name)},()=>{i.forEach(([o,c])=>{c.code&&(Z(o,e,c,!1,n),!c.module&&n(!1))}),n(mt(n.moduleCount)||n.errorCount===r.length)}):n(!0)}function Z(t,e,n,s,r){var i;try{const o=tt(t,e,n.code,n);if(e.inline||n.module){const c=K("script");if(Ze(t,o,n.module,c,r),s)return c;(i=e.container)===null||i===void 0||i.querySelector("micro-app-body").appendChild(c)}else if(et(o,n),s)return document.createComment("dynamic script extract by micro-app")}catch(o){console.error(`[micro-app from runScript] app ${e.name}: `,o)}}function Wt(t,e,n,s){const r=()=>X(s);if(n.source.scripts.has(t)){const o=n.source.scripts.get(t);return!o.module&&I(r),Z(t,n,o,!0,r)}if(H.has(t)){const o=H.get(t);return e.code=o,n.source.scripts.set(t,e),!e.module&&I(r),Z(t,n,e,!0,r)}let i;return n.inline||e.module?i=K("script"):i=document.createComment(`dynamic script with src='${t}' extract by micro-app`),j(t,n.name).then(o=>{e.code=o,n.source.scripts.set(t,e),e.isGlobal&&H.set(t,o);try{o=tt(t,n,o,e),n.inline||e.module?Ze(t,o,e.module,i,r):et(o,e)}catch(c){console.error(`[micro-app from runDynamicScript] app ${n.name}: `,c,t)}!e.module&&X(s)}).catch(o=>{m(o,n.name),ke(s)}),i}function Ze(t,e,n,s,r){if(n){const i=new Blob([e],{type:"text/javascript"});s.src=URL.createObjectURL(i),s.setAttribute("type","module"),r&&(r.moduleCount&&r.moduleCount--,s.onload=r.bind(s,r.moduleCount===0))}else s.textContent=e;t.startsWith("inline-")||s.setAttribute("data-origin-src",t)}function et(t,e){e.code2Function||(e.code2Function=new Function(t)),e.code2Function.call(window)}function tt(t,e,n,s){return v(p.plugins)&&(n=Ht(t,n,e.name,p.plugins,s)),e.sandBox&&!s.module?(a.rawWindow.__MICRO_APP_PROXY_WINDOW__=e.sandBox.proxyWindow,`;(function(proxyWindow){with(proxyWindow.__MICRO_APP_WINDOW__){(function(${Ue}){;${n}
|
|
}).call(proxyWindow,${Ue})}})(window.__MICRO_APP_PROXY_WINDOW__);`):n}function Ht(t,e,n,s,r){var i;const o=$e(s.global,e,t,r);return $e((i=s.modules)===null||i===void 0?void 0:i[n],o,t,r)}function $e(t,e,n,s){return k(t)?t.reduce((r,i)=>v(i)&&_(i.loader)?i.loader(r,n,i.options,s):r,e):e}function Kt(t){const e=K("div");return e.innerHTML=t,e}function nt(t,e,n){const s=Array.from(t.children);s.length&&s.forEach(r=>{nt(r,e)});for(const r of s)r instanceof HTMLLinkElement?r.hasAttribute("exclude")||Me(r.getAttribute("href"),e.name)?t.replaceChild(document.createComment("link element with exclude attribute ignored by micro-app"),r):r.hasAttribute("ignore")||Se(r.getAttribute("href"),e.name)?r.hasAttribute("href")&&r.setAttribute("href",L(r.getAttribute("href"),e.url)):qe(r,t,e):r instanceof HTMLStyleElement?r.hasAttribute("exclude")?t.replaceChild(document.createComment("style element with exclude attribute ignored by micro-app"),r):e.scopecss&&!r.hasAttribute("ignore")&&W(r,e):r instanceof HTMLScriptElement?Xe(r,t,e):r instanceof HTMLMetaElement||r instanceof HTMLTitleElement?t.removeChild(r):r instanceof HTMLImageElement&&r.hasAttribute("src")&&r.setAttribute("src",L(r.getAttribute("src"),e.url))}function jt(t,e){const n=Kt(t),s=n.querySelector("micro-app-head"),r=n.querySelector("micro-app-body");if(!s||!r){const i=`element ${s?"body":"head"} is missing`;return e.onerror(new Error(i)),m(i,e.name)}nt(n,e),e.source.links.size?wt(n,e,s):e.onLoad(n),e.source.scripts.size?Ft(n,e):e.onLoad(n)}class Gt{constructor(){this.eventList=new Map}isLegalName(e){return e?!0:(m("event-center: Invalid name"),!1)}on(e,n,s=!1){if(this.isLegalName(e)){if(!_(n))return m("event-center: Invalid callback function");let r=this.eventList.get(e);r?s&&Object.getOwnPropertyNames(r.data).length&&n(r.data):(r={data:{},callbacks:new Set},this.eventList.set(e,r)),r.callbacks.add(n)}}off(e,n){if(this.isLegalName(e)){const s=this.eventList.get(e);s&&(_(n)?s.callbacks.delete(n):s.callbacks.clear())}}dispatch(e,n){if(this.isLegalName(e)){if(!v(n))return m("event-center: data must be object");let s=this.eventList.get(e);if(s){if(s.data!==n){s.data=n;for(const r of s.callbacks)r(n)}}else s={data:n,callbacks:new Set},this.eventList.set(e,s)}}getData(e){var n;const s=this.eventList.get(e);return(n=s==null?void 0:s.data)!==null&&n!==void 0?n:null}}const g=new Gt;function D(t,e){return!M(t)||!t?"":e?`__from_base_app_${t}__`:`__from_micro_app_${t}__`}class st{addGlobalDataListener(e,n){const s=this.appName;s&&(e.__APP_NAME__=s,e.__AUTO_TRIGGER__=n),g.on("global",e,n)}removeGlobalDataListener(e){_(e)&&g.off("global",e)}setGlobalData(e){fe(),g.dispatch("global",e)}getGlobalData(){return g.getData("global")}clearGlobalDataListener(){const e=this.appName,n=g.eventList.get("global");if(n)for(const s of n.callbacks)(e&&e===s.__APP_NAME__||!(e||s.__APP_NAME__))&&n.callbacks.delete(s)}}class kt extends st{addDataListener(e,n,s){g.on(D(C(e),!1),n,s)}removeDataListener(e,n){_(n)&&g.off(D(C(e),!1),n)}getData(e,n=!1){return g.getData(D(C(e),n))}setData(e,n){g.dispatch(D(C(e),!0),n)}clearDataListener(e){g.off(D(C(e),!1))}}class qt extends st{constructor(e){super(),this.appName=C(e),!this.appName&&m(`Invalid appName ${e}`)}addDataListener(e,n){e.__AUTO_TRIGGER__=n,g.on(D(this.appName,!0),e,n)}removeDataListener(e){_(e)&&g.off(D(this.appName,!0),e)}getData(){return g.getData(D(this.appName,!0))}dispatch(e){fe(),g.dispatch(D(this.appName,!1),e);const n=f.get(this.appName);if((n==null?void 0:n.container)&&v(e)){const s=new CustomEvent("datachange",{detail:{data:e}});ne(n.container).dispatchEvent(s)}}clearDataListener(){g.off(D(this.appName,!0))}}function Vt(t){const e=t.appName;t.umdDataListeners={global:new Set,normal:new Set};const n=g.eventList.get("global");if(n)for(const r of n.callbacks)e===r.__APP_NAME__&&t.umdDataListeners.global.add(r);const s=g.eventList.get(D(e,!0));s&&(t.umdDataListeners.normal=new Set(s.callbacks))}function zt(t){for(const e of t.umdDataListeners.global)t.addGlobalDataListener(e,e.__AUTO_TRIGGER__);for(const e of t.umdDataListeners.normal)t.addDataListener(e,e.__AUTO_TRIGGER__)}function Qt(t){return Ne(t.__MICRO_APP_IS_BOUND_FUNCTION__)?t.__MICRO_APP_IS_BOUND_FUNCTION__:t.__MICRO_APP_IS_BOUND_FUNCTION__=ge(t)}function Jt(t){var e;if(Ne(t.__MICRO_APP_IS_CONSTRUCTOR__))return t.__MICRO_APP_IS_CONSTRUCTOR__;const n=t.toString(),s=((e=t.prototype)===null||e===void 0?void 0:e.constructor)===t&&Object.getOwnPropertyNames(t.prototype).length>1||/^function\s+[A-Z]/.test(n)||/^class\s+/.test(n);return t.__MICRO_APP_IS_CONSTRUCTOR__=s}function Xt(t,e){if(e.__MICRO_APP_BOUND_WINDOW_FUNCTION__)return e.__MICRO_APP_BOUND_WINDOW_FUNCTION__;if(!Jt(e)&&!Qt(e)){const n=e.bind(t);for(const s in e)n[s]=e[s];return e.hasOwnProperty("prototype")&&G(n,"prototype",{value:e.prototype,configurable:!0,enumerable:!1,writable:!0}),e.__MICRO_APP_BOUND_WINDOW_FUNCTION__=n}return e}const T=new Map;let rt=!1;function Yt(){if(rt=!0,Object.getOwnPropertyDescriptor(document,"onclick"))return te("Cannot redefine document property onclick");const t=document.onclick;document.onclick=null;let e=!1;function n(s){T.forEach(r=>{_(r)&&r.call(document,s)})}G(document,"onclick",{configurable:!0,enumerable:!0,get(){const s=w();return s?T.get(s):T.get("base")},set(s){const r=w();r?T.set(r,s):T.set("base",s),!e&&_(s)&&(e=!0,a.rawDocumentAddEventListener.call(a.rawDocument,"click",n,!1))}}),t&&(document.onclick=t)}const Y=new Map;function Zt(){const{rawDocument:t,rawDocumentAddEventListener:e,rawDocumentRemoveEventListener:n}=a;!rt&&Yt(),document.addEventListener=function(s,r,i){var o;const c=w();if(c&&!(((o=f.get(c))===null||o===void 0?void 0:o.umdMode)&&ge(r))){const u=Y.get(c);if(u){const E=u.get(s);E?E.add(r):u.set(s,new Set([r]))}else Y.set(c,new Map([[s,new Set([r])]]));r&&(r.__MICRO_APP_MARK_OPTIONS__=i)}e.call(t,s,r,i)},document.removeEventListener=function(s,r,i){var o;const c=w();if(c&&!(((o=f.get(c))===null||o===void 0?void 0:o.umdMode)&&ge(r))){const u=Y.get(c);if(u){const E=u.get(s);(E==null?void 0:E.size)&&E.has(r)&&E.delete(r)}}n.call(t,s,r,i)}}function en(){document.addEventListener=a.rawDocumentAddEventListener,document.removeEventListener=a.rawDocumentRemoveEventListener}const tn=["unmount","appstate-change"];function We(t,e){return tn.includes(t)?`${t}-${e.__MICRO_APP_NAME__}`:t}function nn(t){const e=t.__MICRO_APP_NAME__,n=new Map,s=new Map,r=new Map,{rawWindow:i,rawDocument:o,rawWindowAddEventListener:c,rawWindowRemoveEventListener:u,rawSetInterval:E,rawSetTimeout:N,rawClearInterval:O,rawClearTimeout:B,rawDocumentRemoveEventListener:V}=a;t.addEventListener=function(l,d,h){l=We(l,t);const A=n.get(l);A?A.add(d):n.set(l,new Set([d])),d&&(d.__MICRO_APP_MARK_OPTIONS__=h),c.call(i,l,d,h)},t.removeEventListener=function(l,d,h){l=We(l,t);const A=n.get(l);(A==null?void 0:A.size)&&A.has(d)&&A.delete(d),u.call(i,l,d,h)},t.setInterval=function(l,d,...h){const A=E.call(i,l,d,...h);return s.set(A,{handler:l,timeout:d,args:h}),A},t.setTimeout=function(l,d,...h){const A=N.call(i,l,d,...h);return r.set(A,{handler:l,timeout:d,args:h}),A},t.clearInterval=function(l){s.delete(l),O.call(i,l)},t.clearTimeout=function(l){r.delete(l),B.call(i,l)};const se=new Map,re=new Map;let ie=new Map,oe=new Map,R;return{recordUmdEffect:()=>{n.forEach((d,h)=>{d.size&&se.set(h,new Set(d))}),s.size&&(ie=new Map(s)),r.size&&(oe=new Map(r)),R=T.get(e);const l=Y.get(e);l&&l.forEach((d,h)=>{d.size&&re.set(h,new Set(d))})},rebuildUmdEffect:()=>{se.forEach((l,d)=>{for(const h of l)t.addEventListener(d,h,h==null?void 0:h.__MICRO_APP_MARK_OPTIONS__)}),ie.forEach(l=>{t.setInterval(l.handler,l.timeout,...l.args)}),oe.forEach(l=>{t.setTimeout(l.handler,l.timeout,...l.args)}),R&&T.set(e,R),q(e),re.forEach((l,d)=>{for(const h of l)document.addEventListener(d,h,h==null?void 0:h.__MICRO_APP_MARK_OPTIONS__)}),q(null)},releaseEffect:()=>{n.size&&(n.forEach((d,h)=>{for(const A of d)u.call(i,h,A)}),n.clear()),s.size&&(s.forEach((d,h)=>{O.call(i,h)}),s.clear()),r.size&&(r.forEach((d,h)=>{B.call(i,h)}),r.clear()),T.delete(e);const l=Y.get(e);l&&(l.forEach((d,h)=>{for(const A of d)V.call(o,h,A)}),l.clear())}}}const sn=["System","__cjsWrapper"],rn=["location"],on=["window","self","globalThis"];class ee{constructor(e,n){this.scopeProperties=["webpackJsonp","Vue"],this.escapeProperties=[],this.injectedKeys=new Set,this.escapeKeys=new Set,this.active=!1,this.microAppWindow={},this.getSpecialProperties(e),this.proxyWindow=this.createProxyWindow(e),this.initMicroAppWindow(this.microAppWindow,e,n),Object.assign(this,nn(this.microAppWindow))}start(e){this.active||(this.active=!0,this.microAppWindow.__MICRO_APP_BASE_ROUTE__=this.microAppWindow.__MICRO_APP_BASE_URL__=e,a.rawWindow._babelPolyfill&&(a.rawWindow._babelPolyfill=!1),++ee.activeCount===1&&(Zt(),Mt()))}stop(e){this.active&&(this.active=!1,this.releaseEffect(),this.microAppWindow.microApp.clearDataListener(),this.microAppWindow.microApp.clearGlobalDataListener(),e||(this.injectedKeys.forEach(n=>{Reflect.deleteProperty(this.microAppWindow,n)}),this.injectedKeys.clear(),this.escapeKeys.forEach(n=>{Reflect.deleteProperty(a.rawWindow,n)}),this.escapeKeys.clear()),--ee.activeCount===0&&(en(),Lt()))}recordUmdSnapshot(){this.microAppWindow.__MICRO_APP_UMD_MODE__=!0,this.recordUmdEffect(),Vt(this.microAppWindow.microApp),this.recordUmdInjectedValues=new Map,this.injectedKeys.forEach(e=>{this.recordUmdInjectedValues.set(e,Reflect.get(this.microAppWindow,e))})}rebuildUmdSnapshot(){this.recordUmdInjectedValues.forEach((e,n)=>{Reflect.set(this.proxyWindow,n,e)}),this.rebuildUmdEffect(),zt(this.microAppWindow.microApp)}getSpecialProperties(e){var n;!v(p.plugins)||(this.commonActionForSpecialProperties(p.plugins.global),this.commonActionForSpecialProperties((n=p.plugins.modules)===null||n===void 0?void 0:n[e]))}commonActionForSpecialProperties(e){if(k(e))for(const n of e)v(n)&&(k(n.scopeProperties)&&(this.scopeProperties=this.scopeProperties.concat(n.scopeProperties)),k(n.escapeProperties)&&(this.escapeProperties=this.escapeProperties.concat(n.escapeProperties)))}createProxyWindow(e){const n=a.rawWindow,s=new Map;return new Proxy(this.microAppWindow,{get:(r,i)=>{if(ce(e),Reflect.has(r,i)||M(i)&&/^__MICRO_APP_/.test(i)||this.scopeProperties.includes(i))return Reflect.get(r,i);const o=Reflect.get(n,i);return _(o)?Xt(n,o):o},set:(r,i,o)=>{if(this.active){if(rn.includes(i))Reflect.set(n,i,o);else if(!$.call(r,i)&&$.call(n,i)&&!this.scopeProperties.includes(i)){const c=Object.getOwnPropertyDescriptor(n,i),{configurable:u,enumerable:E,writable:N,set:O}=c;G(r,i,{value:o,configurable:u,enumerable:E,writable:N!=null?N:!!O}),this.injectedKeys.add(i)}else Reflect.set(r,i,o),this.injectedKeys.add(i);(this.escapeProperties.includes(i)||sn.includes(i)&&!Reflect.has(n,i))&&!this.scopeProperties.includes(i)&&(Reflect.set(n,i,o),this.escapeKeys.add(i))}return!0},has:(r,i)=>this.scopeProperties.includes(i)?i in r:i in r||i in n,getOwnPropertyDescriptor:(r,i)=>{if($.call(r,i))return s.set(i,"target"),Object.getOwnPropertyDescriptor(r,i);if($.call(n,i)){s.set(i,"rawWindow");const o=Object.getOwnPropertyDescriptor(n,i);return o&&!o.configurable&&(o.configurable=!0),o}},defineProperty:(r,i,o)=>s.get(i)==="rawWindow"?Reflect.defineProperty(n,i,o):Reflect.defineProperty(r,i,o),ownKeys:r=>gt(Reflect.ownKeys(n).concat(Reflect.ownKeys(r))),deleteProperty:(r,i)=>$.call(r,i)?(this.injectedKeys.has(i)&&this.injectedKeys.delete(i),this.escapeKeys.has(i)&&Reflect.deleteProperty(n,i),Reflect.deleteProperty(r,i)):!0})}initMicroAppWindow(e,n,s){e.__MICRO_APP_ENVIRONMENT__=!0,e.__MICRO_APP_NAME__=n,e.__MICRO_APP_PUBLIC_PATH__=je(s),e.__MICRO_APP_WINDOW__=e,e.microApp=Object.assign(new qt(n),{removeDomScope:fe,pureCreateElement:K}),e.rawWindow=a.rawWindow,e.rawDocument=a.rawDocument,e.hasOwnProperty=r=>$.call(e,r)||$.call(a.rawWindow,r),this.setMappingPropertiesWithRawDescriptor(e),this.setHijackProperties(e,n)}setMappingPropertiesWithRawDescriptor(e){let n,s;const r=a.rawWindow;r===r.parent?n=s=this.proxyWindow:(n=r.top,s=r.parent),G(e,"top",this.createDescriptorForMicroAppWindow("top",n)),G(e,"parent",this.createDescriptorForMicroAppWindow("parent",s)),on.forEach(i=>{G(e,i,this.createDescriptorForMicroAppWindow(i,this.proxyWindow))})}createDescriptorForMicroAppWindow(e,n){const{configurable:s=!0,enumerable:r=!0,writable:i,set:o}=Object.getOwnPropertyDescriptor(a.rawWindow,e)||{writable:!0};return{value:n,configurable:s,enumerable:r,writable:i!=null?i:!!o}}setHijackProperties(e,n){let s,r;pt(e,{document:{get(){return ce(n),a.rawDocument},configurable:!1,enumerable:!0},eval:{get(){return ce(n),s||eval},set:i=>{s=i},configurable:!0,enumerable:!1},Image:{get(){return ce(n),r||a.ImageProxy},set:i=>{r=i},configurable:!0,enumerable:!1}})}}ee.activeCount=0;function an(t,e){Object.defineProperties(t,{currentTarget:{get(){return e}},target:{get(){return e}}})}function x(t,e,n,s){var r;if(!t)return m(`element does not exist in lifecycle ${n}`,e);t=ne(t),fe();const i=Object.assign({name:e,container:t},s&&{error:s}),o=new CustomEvent(n,{detail:i});an(o,t),_((r=p.lifeCycles)===null||r===void 0?void 0:r[n])&&p.lifeCycles[n](o),t.dispatchEvent(o)}function he(t,e,n={}){const s=new CustomEvent(`${t}-${e}`,{detail:n});window.dispatchEvent(s)}const f=new Map;class it{constructor({name:e,url:n,ssrUrl:s,container:r,inline:i,scopecss:o,useSandbox:c,baseroute:u}){this.state=b.NOT_LOADED,this.keepAliveState=null,this.keepAliveContainer=null,this.loadSourceLevel=0,this.umdHookMount=null,this.umdHookUnmount=null,this.libraryName=null,this.umdMode=!1,this.isPrefetch=!1,this.prefetchResolve=null,this.container=null,this.baseroute="",this.sandBox=null,this.container=r!=null?r:null,this.inline=i!=null?i:!1,this.baseroute=u!=null?u:"",this.ssrUrl=s!=null?s:"",this.name=e,this.url=n,this.useSandbox=c,this.scopecss=this.useSandbox&&o,this.source={links:new Map,scripts:new Map},this.loadSourceCode(),this.useSandbox&&(this.sandBox=new ee(e,n))}loadSourceCode(){this.state=b.LOADING_SOURCE_CODE,De.getInstance().run(this,jt)}onLoad(e){var n;++this.loadSourceLevel===2&&(this.source.html=e,this.isPrefetch?((n=this.prefetchResolve)===null||n===void 0||n.call(this),this.prefetchResolve=null):b.UNMOUNT!==this.state&&(this.state=b.LOAD_SOURCE_FINISHED,this.mount()))}onLoadError(e){this.loadSourceLevel=-1,this.prefetchResolve&&(this.prefetchResolve(),this.prefetchResolve=null),b.UNMOUNT!==this.state&&(this.onerror(e),this.state=b.LOAD_SOURCE_ERROR)}mount(e,n,s){var r,i,o;if(Ne(n)&&n!==this.inline&&(this.inline=n),this.container=(r=this.container)!==null&&r!==void 0?r:e,this.baseroute=s!=null?s:this.baseroute,this.loadSourceLevel!==2){this.state=b.LOADING_SOURCE_CODE;return}x(this.container,this.name,S.BEFOREMOUNT),this.state=b.MOUNTING,le(this.source.html,this.container,!this.umdMode),(i=this.sandBox)===null||i===void 0||i.start(this.baseroute);let c;if(this.umdMode){(o=this.sandBox)===null||o===void 0||o.rebuildUmdSnapshot();try{c=this.umdHookMount()}catch(u){m(`an error occurred in the mount function
|
|
`,this.name,u)}this.handleMounted(c)}else{let u=!1;$t(this.source.scripts,this,E=>{var N;if(!this.umdMode){const{mount:O,unmount:B}=this.getUmdLibraryHooks();if(_(O)&&_(B)){this.umdHookMount=O,this.umdHookUnmount=B,this.umdMode=!0,(N=this.sandBox)===null||N===void 0||N.recordUmdSnapshot();try{c=this.umdHookMount()}catch(V){m(`an error occurred in the mount function
|
|
`,this.name,V)}}}!u&&(E===!0||this.umdMode)&&(u=!0,this.handleMounted(c))})}}handleMounted(e){Ae(e)?e.then(()=>this.dispatchMountedEvent()).catch(n=>this.onerror(n)):this.dispatchMountedEvent()}dispatchMountedEvent(){b.UNMOUNT!==this.state&&(this.state=b.MOUNTED,x(this.container,this.name,S.MOUNTED))}unmount(e,n){this.state===b.LOAD_SOURCE_ERROR&&(e=!0),this.state=b.UNMOUNT,this.keepAliveState=null,this.keepAliveContainer=null;let s;if(this.umdHookUnmount)try{s=this.umdHookUnmount()}catch(r){m(`an error occurred in the unmount function
|
|
`,this.name,r)}he("unmount",this.name),this.handleUnmounted(e,s,n)}handleUnmounted(e,n,s){Ae(n)?n.then(()=>this.actionsForUnmount(e,s)).catch(()=>this.actionsForUnmount(e,s)):this.actionsForUnmount(e,s)}actionsForUnmount(e,n){var s;e?this.actionsForCompletelyDestroy():this.umdMode&&this.container.childElementCount&&le(this.container,this.source.html,!1),(s=this.sandBox)===null||s===void 0||s.stop(this.umdMode),hn().length||Ot(),x(this.container,this.name,S.UNMOUNT),this.container.innerHTML="",this.container=null,n&&n()}actionsForCompletelyDestroy(){!this.useSandbox&&this.umdMode&&delete window[this.libraryName],f.delete(this.name)}hiddenKeepAliveApp(){const e=this.container;le(this.container,this.keepAliveContainer?this.keepAliveContainer:this.keepAliveContainer=document.createElement("div"),!1),this.container=this.keepAliveContainer,this.keepAliveState=y.KEEP_ALIVE_HIDDEN,he("appstate-change",this.name,{appState:"afterhidden"}),x(e,this.name,S.AFTERHIDDEN)}showKeepAliveApp(e){he("appstate-change",this.name,{appState:"beforeshow"}),x(e,this.name,S.BEFORESHOW),le(this.container,e,!1),this.container=e,this.keepAliveState=y.KEEP_ALIVE_SHOW,he("appstate-change",this.name,{appState:"aftershow"}),x(this.container,this.name,S.AFTERSHOW)}onerror(e){x(this.container,this.name,S.ERROR,e)}getAppState(){return this.state}getKeepAliveState(){return this.keepAliveState}getUmdLibraryHooks(){var e,n;if(b.UNMOUNT!==this.state){const s=(n=(e=this.sandBox)===null||e===void 0?void 0:e.proxyWindow)!==null&&n!==void 0?n:a.rawWindow;return this.libraryName=ne(this.container).getAttribute("library")||`micro-app-${this.name}`,typeof s[this.libraryName]=="object"?s[this.libraryName]:{}}return{}}}function cn(t){class e extends HTMLElement{constructor(){super(),this.isWaiting=!1,this.cacheData=null,this.hasConnected=!1,this.appName="",this.appUrl="",this.ssrUrl="",this.version=ht,this.handleAttributeUpdate=()=>{this.isWaiting=!1;const s=C(this.getAttribute("name")),r=Ee(this.getAttribute("url"),this.appName);if(this.legalAttribute("name",s)&&this.legalAttribute("url",r)){const i=f.get(s);if(s!==this.appName&&i&&b.UNMOUNT!==i.getAppState()&&y.KEEP_ALIVE_HIDDEN!==i.getKeepAliveState()&&!i.isPrefetch)return this.setAttribute("name",this.appName),m(`app name conflict, an app named ${s} is running`,this.appName);(s!==this.appName||r!==this.appUrl)&&(s===this.appName?this.handleUnmount(!0,()=>{this.actionsForAttributeChange(s,r,i)}):this.getKeepAliveModeResult()?(this.handleHiddenKeepAliveApp(),this.actionsForAttributeChange(s,r,i)):this.handleUnmount(this.getDestroyCompatibleResult(),()=>{this.actionsForAttributeChange(s,r,i)}))}else s!==this.appName&&this.setAttribute("name",this.appName)},yt()}static get observedAttributes(){return["name","url"]}connectedCallback(){this.hasConnected=!0,I(()=>x(this,this.appName,S.CREATED)),this.initialMount()}disconnectedCallback(){this.hasConnected=!1,this.getKeepAliveModeResult()?this.handleHiddenKeepAliveApp():this.handleUnmount(this.getDestroyCompatibleResult())}attributeChangedCallback(s,r,i){if(this.legalAttribute(s,i)&&this[s===Q.NAME?"appName":"appUrl"]!==i)if(s===Q.URL&&!this.appUrl){if(i=Ee(i,this.appName),!i)return m(`Invalid attribute url ${i}`,this.appName);this.appUrl=i,this.handleInitialNameAndUrl()}else if(s===Q.NAME&&!this.appName){const o=C(i);if(!o)return m(`Invalid attribute name ${i}`,this.appName);this.cacheData&&(p.setData(o,this.cacheData),this.cacheData=null),this.appName=o,o!==i&&this.setAttribute("name",this.appName),this.handleInitialNameAndUrl()}else this.isWaiting||(this.isWaiting=!0,I(this.handleAttributeUpdate))}handleInitialNameAndUrl(){this.hasConnected&&this.initialMount()}initialMount(){if(!(!this.appName||!this.appUrl))if(this.getDisposeResult("shadowDOM")&&!this.shadowRoot&&_(this.attachShadow)&&this.attachShadow({mode:"open"}),this.getDisposeResult("ssr")?this.ssrUrl=L(a.rawWindow.location.pathname,this.appUrl):this.ssrUrl&&(this.ssrUrl=""),f.has(this.appName)){const s=f.get(this.appName),r=s.ssrUrl||s.url,i=this.ssrUrl||this.appUrl;s.getKeepAliveState()===y.KEEP_ALIVE_HIDDEN&&s.url===this.appUrl?this.handleShowKeepAliveApp(s):r===i&&(s.isPrefetch||s.getAppState()===b.UNMOUNT)?this.handleAppMount(s):s.isPrefetch||s.getAppState()===b.UNMOUNT?(te(`the ${s.isPrefetch?"prefetch":"unmounted"} app with url: ${r} is replaced by a new app`,this.appName),this.handleCreateApp()):m(`app name conflict, an app named ${this.appName} is running`,this.appName)}else this.handleCreateApp()}actionsForAttributeChange(s,r,i){var o;this.getDisposeResult("ssr")?this.ssrUrl=L(a.rawWindow.location.pathname,r):this.ssrUrl&&(this.ssrUrl=""),this.appName=s,this.appUrl=r,((o=this.shadowRoot)!==null&&o!==void 0?o:this).innerHTML="",s!==this.getAttribute("name")&&this.setAttribute("name",this.appName),i?i.getKeepAliveState()===y.KEEP_ALIVE_HIDDEN?i.url===this.appUrl?this.handleShowKeepAliveApp(i):m(`app name conflict, an app named ${this.appName} is running`,this.appName):i.url===this.appUrl&&i.ssrUrl===this.ssrUrl?this.handleAppMount(i):this.handleCreateApp():this.handleCreateApp()}legalAttribute(s,r){return!M(r)||!r?(m(`unexpected attribute ${s}, please check again`,this.appName),!1):!0}handleAppMount(s){s.isPrefetch=!1,I(()=>{var r;return s.mount((r=this.shadowRoot)!==null&&r!==void 0?r:this,this.getDisposeResult("inline"),this.getBaseRouteCompatible())})}handleCreateApp(){var s;f.has(this.appName)&&f.get(this.appName).actionsForCompletelyDestroy();const r=new it({name:this.appName,url:this.appUrl,ssrUrl:this.ssrUrl,container:(s=this.shadowRoot)!==null&&s!==void 0?s:this,inline:this.getDisposeResult("inline"),scopecss:!(this.getDisposeResult("disableScopecss")||this.getDisposeResult("shadowDOM")),useSandbox:!this.getDisposeResult("disableSandbox"),baseroute:this.getBaseRouteCompatible()});f.set(this.appName,r)}handleUnmount(s,r){const i=f.get(this.appName);i&&i.getAppState()!==b.UNMOUNT&&i.unmount(s,r)}handleHiddenKeepAliveApp(){const s=f.get(this.appName);s&&s.getAppState()!==b.UNMOUNT&&s.getKeepAliveState()!==y.KEEP_ALIVE_HIDDEN&&s.hiddenKeepAliveApp()}handleShowKeepAliveApp(s){I(()=>{var r;return s.showKeepAliveApp((r=this.shadowRoot)!==null&&r!==void 0?r:this)})}getDisposeResult(s){return(this.compatibleSpecialProperties(s)||p[s])&&this.compatibleDisableSpecialProperties(s)}compatibleSpecialProperties(s){return s==="disableScopecss"?this.hasAttribute("disableScopecss")||this.hasAttribute("disable-scopecss"):s==="disableSandbox"?this.hasAttribute("disableSandbox")||this.hasAttribute("disable-sandbox"):this.hasAttribute(s)}compatibleDisableSpecialProperties(s){return s==="disableScopecss"?this.getAttribute("disableScopecss")!=="false"&&this.getAttribute("disable-scopecss")!=="false":s==="disableSandbox"?this.getAttribute("disableSandbox")!=="false"&&this.getAttribute("disable-sandbox")!=="false":this.getAttribute(s)!=="false"}getBaseRouteCompatible(){var s,r;return(r=(s=this.getAttribute("baseroute"))!==null&&s!==void 0?s:this.getAttribute("baseurl"))!==null&&r!==void 0?r:""}getDestroyCompatibleResult(){return this.getDisposeResult("destroy")||this.getDisposeResult("destory")}getKeepAliveModeResult(){return this.getDisposeResult("keep-alive")&&!this.getDestroyCompatibleResult()}set data(s){this.appName?p.setData(this.appName,s):this.cacheData=s}get data(){return this.appName?p.getData(this.appName,!0):this.cacheData?this.cacheData:null}}window.customElements.define(t,e)}function He(t){if(!we)return m("preFetch is only supported in browser environment");Pe(()=>{_(t)&&(t=t()),k(t)&&t.reduce((e,n)=>e.then(()=>ln(n)),Promise.resolve())})}function ln(t){return new Promise(e=>{Pe(()=>{var n,s;if(v(t)&&navigator.onLine)if(t.name=C(t.name),t.url=Ee(t.url,t.name),t.name&&t.url&&!f.has(t.name)){const r=new it({name:t.name,url:t.url,scopecss:!((n=t.disableScopecss)!==null&&n!==void 0?n:p.disableScopecss),useSandbox:!((s=t.disableSandbox)!==null&&s!==void 0?s:p.disableSandbox)});r.isPrefetch=!0,r.prefetchResolve=e,f.set(t.name,r)}else e();else e()})})}function un(t){v(t)&&Pe(()=>{Ke(t.js,"js",H),Ke(t.css,"css",F)})}function Ke(t,e,n){if(k(t)){const s=t.filter(i=>M(i)&&i.includes(`.${e}`)&&!n.has(i)),r=s.map(i=>j(i));me(r,i=>{const o=s[i.index];n.has(o)||n.set(o,i.data)},i=>{m(i)})}}function hn(t){const e=[];return f.forEach((n,s)=>{b.UNMOUNT!==n.getAppState()&&!n.isPrefetch&&(!t||y.KEEP_ALIVE_HIDDEN!==n.getKeepAliveState())&&e.push(s)}),e}function dn(t,e){const n=f.get(C(t));return new Promise(s=>{if(n)if(n.getAppState()===b.UNMOUNT||n.isPrefetch)e!=null&&e.destroy&&n.actionsForCompletelyDestroy(),s();else if(n.getKeepAliveState()===y.KEEP_ALIVE_HIDDEN)e!=null&&e.destroy?n.unmount(!0,s):e!=null&&e.clearAliveState?n.unmount(!1,s):s();else{const r=ne(n.container),i=()=>{r.removeEventListener("unmount",i),r.removeEventListener("afterhidden",o),s()},o=()=>{r.removeEventListener("unmount",i),r.removeEventListener("afterhidden",o),s()};if(r.addEventListener("unmount",i),r.addEventListener("afterhidden",o),e!=null&&e.destroy){let c,u;r.hasAttribute("destroy")&&(c=r.getAttribute("destroy")),r.hasAttribute("destory")&&(u=r.getAttribute("destory")),r.setAttribute("destroy","true"),r.parentNode.removeChild(r),r.removeAttribute("destroy"),typeof c=="string"&&r.setAttribute("destroy",c),typeof u=="string"&&r.setAttribute("destory",u)}else if((e==null?void 0:e.clearAliveState)&&r.hasAttribute("keep-alive")){const c=r.getAttribute("keep-alive");r.removeAttribute("keep-alive"),r.parentNode.removeChild(r),r.setAttribute("keep-alive",c)}else r.parentNode.removeChild(r)}else te(`app ${t} does not exist`),s()})}function fn(t){return Array.from(f.keys()).reduce((e,n)=>e.then(()=>dn(n,t)),Promise.resolve())}class mn extends kt{constructor(){super(...arguments),this.tagName="micro-app",this.preFetch=He}start(e){if(!we||!window.customElements)return m("micro-app is not supported in this environment");if(e!=null&&e.tagName)if(/^micro-app(-\S+)?/.test(e.tagName))this.tagName=e.tagName;else return m(`${e.tagName} is invalid tagName`);if(window.customElements.get(this.tagName))return te(`element ${this.tagName} is already defined`);if(Tt(),e&&v(e)&&(this.shadowDOM=e.shadowDOM,this.destroy=e.destroy,this.destory=e.destory,this.inline=e.inline,this.disableScopecss=e.disableScopecss,this.disableSandbox=e.disableSandbox,this.ssr=e.ssr,_(e.fetch)&&(this.fetch=e.fetch),v(e.lifeCycles)&&(this.lifeCycles=e.lifeCycles),e.preFetchApps&&He(e.preFetchApps),e.globalAssets&&un(e.globalAssets),_(e.excludeAssetFilter)&&(this.excludeAssetFilter=e.excludeAssetFilter),v(e.plugins))){const n=e.plugins.modules;if(v(n))for(const s in n){const r=C(s);r&&s!==r&&(n[r]=n[s],delete n[s])}this.plugins=e.plugins}cn(this.tagName)}}var p=new mn;export{qt as E,p as m,fn as u};
|