@blueking/bk-weweb 0.0.2-5.beta.13 → 0.0.2-5.beta.14
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/collect-source.js +13 -0
- package/dist/collect-source.js.map +1 -1
- package/dist/index.esm.js +13 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/typings/mode/app.d.ts +1 -0
package/dist/index.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e;Object.defineProperty(exports,"__esModule",{value:!0}),function(e){e.ACTIVATED="ACTIVATED",e.DEACTIVATED="DEACTIVATED",e.ERROR="ERROR",e.LOADED="LOADED",e.LOADING="LOADING",e.MOUNTED="MOUNTED",e.MOUNTING="MOUNTING",e.UNMOUNT="UNMOUNT",e.UNSET="UNSET"}(e||(e={}));let t=null;function n(){return t}function o(e){t=e}const r=new Map;Object.getOwnPropertyNames(window).forEach((e=>{!r.has(e)&&e.match(/^[A-Z]/)&&"function"==typeof window[e]&&window[e].toString().includes("[native code]")&&r.set(e,!0)}));const s="id";var i;!function(e){e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.STYLE_RULE=1]="STYLE_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(i||(i={}));const c=e=>Promise.resolve().then(e);function a(e){return e.startsWith("//")?`${location.protocol}${e}`:e.startsWith("http")?e:`${location.protocol}//${e}`}function l(e,t){if(!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e))return e;const{origin:n,pathname:o}=new URL(a(t));return new URL(e,`${n}${o}`.replace(/\.(\w+)$/,"/")).toString()}function d(){return`inline-${p(16)}`}const u=window.requestIdleCallback||function(e){const t=Date.now();return setTimeout((()=>{e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)},p=(e,t="abcdefghijklmnopqrstuvwxyz0123456789")=>{let n="";for(let o=0;o<e;o++)n+=t[parseInt((Math.random()*t.length).toString(),10)];return n},h=e=>{if(!e)return!1;if(e.match(/\.js$/))return!1;const{pathname:t}=new URL(a(e));return!t.match(/\.js$/)},f=["currentTarget","srcElement","target"];function m(e,t="custom"){return Object.defineProperties(new CustomEvent(t),f.reduce(((t,n)=>(t[n]={get:()=>e},t)),{}))}function y(e){const t=m(e,"load");"function"!=typeof e.onload?e.dispatchEvent(t):e.onload(t)}function w(e){const t=m(e,"error");"function"!=typeof e.onerror?e.dispatchEvent(t):e.onerror(t)}function E(e,t={}){return xe.fetchSource?xe.fetchSource(e,t):window.fetch(e,t).then((e=>e.text()))}class _{code="";fromHtml;initial;prefetch=!1;preload=!1;scoped;scopedCode="";url;constructor({code:e,fromHtml:t,initial:n,prefetch:o,preload:r,url:s}){this.scoped=!1,this.code=e,this.prefetch=o??!1,this.preload=r??!1,this.url=s,this.fromHtml=t,this.initial=n??!1}commonScoped(e,t){if(!t.scopeCss||t.container instanceof ShadowRoot){const n=this.resetUrlHost(e.textContent||this.code||"",t.url,this.url);if(n&&t.container instanceof ShadowRoot){let e="";n.match(/@font-face\s*\{[^}]+\}/g)?.forEach((t=>{e+=`${t}\n`}));const o=t.sandBox?.rawDocument;if(o&&e){const t=o.createElement("style");t.setAttribute("type","text/css"),t.setAttribute("powered-by","bk-weweb"),t.textContent=e,o?.head?.append(t)}}e.textContent=n}else{const n=new CSSStyleSheet({disabled:!0});n.replaceSync(e.textContent||this.code);const o=Array.from(n?.cssRules??[]),r=`#${t.name}`,s=this.scopeRule(o,r),i=this.resetUrlHost(s,t.url,this.url);e.textContent=i,this.scopedCode=i}this.scoped=!0}createStyleElement(){const e=document.createElement("style");return e.__BK_WEWEB_APP_KEY__&&delete e.__BK_WEWEB_APP_KEY__,e}async excuteCode(e){e.registerRunningApp();let t=this.createStyleElement();t.setAttribute("type","text/css"),t.textContent=this.code;try{this.code||await this.getCode(e),t=this.scopedStyleCSS(e,t),this.scoped=!0}catch(e){console.error("scoped style error",e)}return t}async getCode(e){if(this.code.length||!this.url)return this.code;let t="";if(e?.source?.styles?.has(this.url)&&(t=e.source.styles.get(this.url)?.code||""),!t&&Ae.getCacheStyle(this.url)){const e=Ae.getCacheStyle(this.url);t=e?.code||""}return t||(t=await E(this.url).catch((()=>""))),this.code=t,t}linkedBaseStyle(e,t){return!(t.container instanceof ShadowRoot||!e.textContent||!Ae.getBaseAppStyle(e.textContent))&&(e.textContent="",e.innerHTML="",e.setAttribute("linked-from-base","true"),!0)}resetPackRule(e,t,n){const o=this.scopeRule(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}resetUrlHost(e,t,n){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,o)=>{if(/^(data|blob):/.test(o)||/^(https?:)?\/\//.test(o))return e;if(/^((\.\.?\/)|[^/])/.test(o)&&n){const e=n.split("/");e.pop(),t=a(`${e.join("/")}/`)}return`url("${l(o,t)}")`}))}scopeRule(e,t){let n="";for(const o of e)switch(o.type){case i.STYLE_RULE:n+=this.scopeStyleRule(o,t);break;case i.MEDIA_RULE:n+=this.resetPackRule(o,t,"media");break;case i.SUPPORTS_RULE:n+=this.resetPackRule(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}scopeStyleRule(e,t){const{cssText:n,selectorText:o}=e;if(/^((html[\s>~,]+body)|(html|body|:root))$/.test(o))return n.replace(/^((html[\s>~,]+body)|(html|body|:root))/,t);if("*"===o)return n.replace("*",`${t} *`);const r=/(^|\s+)((html[\s>~]+body)|(html|body|:root))(?=[\s>~]+|$)/;return n.replace(/^[\s\S]+{/,(e=>e.replace(/(^|,)([^,]+)/g,((e,n,o)=>r.test(o)?e.replace(r,t):`${n} ${t} ${o.replace(/^\s*/,"")}`))))}scopedLinkCSS(e,t){const n=this.createStyleElement();n.setAttribute("type","text/css");const o=!(!e.keepAlive||e.container instanceof ShadowRoot);W(n,e,o);const r=o?document.head:e.container;try{if(this.code)this.commonScoped(n,e),r?.prepend(n),t&&y(t);else if(t.getAttribute("href"))this.url=l(t.getAttribute("href"),e.url),this.getCode(e).then((()=>{this.scopedStyleCSS(e,n),t.remove(),r?.prepend(n),t&&y(t),this.scoped=!0}));else{const o=new MutationObserver((()=>{t.href&&(o.disconnect(),this.url=l(t.getAttribute("href"),e.url),this.getCode(e).then((()=>{this.scopedStyleCSS(e,n),t.remove(),r?.prepend(n),t&&y(t),this.scoped=!0})))}));o.observe(t,{attributeFilter:["href"],childList:!1,subtree:!1})}}catch{t&&w(t)}return n}scopedStyleCSS(e,t){const n=!(!e.keepAlive||e.container instanceof ShadowRoot);if(W(t,e,n),this.code||t.textContent){if(t.textContent&&(t.textContent="",t.innerHTML=""),this.linkedBaseStyle(t,e))return t;this.commonScoped(t,e)}else{const n=new MutationObserver((()=>{(t.textContent||t.sheet?.cssRules?.length)&&(n.disconnect(),this.linkedBaseStyle(t,e)||this.commonScoped(t,e))}));n.observe(t,{attributes:!1,characterData:!0,childList:!0,subtree:!0})}return this.url&&t.setAttribute("origin-src",this.url),t}}async function A(e,t){const n=Array.from(e.source.styles.values()),o=[];n.forEach((t=>{o.push(t.excuteCode(e))})),await Promise.all(o).then((n=>{const o=t||e.container;!e.keepAlive||o instanceof ShadowRoot?o?.append(...n):document.head.append(...n)}))}class S{state=e.UNSET;appCacheKey;container;data;initSource;isPreLoad=!1;keepAlive;name;sandBox;scopeCss=!0;scopeJs=!1;showSourceCode=!0;source;url;constructor(e){this.name=e.id!==e.url?e.id:p(5),this.appCacheKey=e.id||this.name,this.url=e.url,this.container=e.container??void 0,this.scopeJs=e.scopeJs??!0,this.showSourceCode=e.showSourceCode??!0,this.scopeCss=e.scopeCss??!0,this.keepAlive=e.keepAlive??!1,this.data=e.data??{},this.initSource=e.initSource??[],this.scopeJs&&(this.sandBox=new fe(this))}activated(t,n){if(this.isPreLoad=!1,this.state=e.ACTIVATED,this.container&&t){t instanceof Element&&t.setAttribute(s,this.name);const e=document.createDocumentFragment();Array.from(this.container.childNodes).forEach((t=>{e.appendChild(t)})),t.appendChild(e),this.container=t,this.sandBox?.activeated();const o=this.source?.getScript(this.url);n?.(this,o?.exportInstance)}}deactivated(){this.state=e.DEACTIVATED,this.sandBox?.deactivated()}mount(t,n){this.isPreLoad=!1,this.container=t??this.container,this.state=e.MOUNTING,this.container instanceof HTMLElement&&this.container.setAttribute(s,this.name),this.container.innerHTML="";const o=document.createElement("div"),r=`${this.name}-wrapper`;o.setAttribute("id",r),this.source?.styles.size&&A(this,this.container),this.container.appendChild(o),this.sandBox?.activeated(),x(this).finally((()=>{this.state=e.MOUNTED;const t=this.source?.getScript(this.url);"function"==typeof t?.exportInstance?.render&&t.exportInstance.render(o,this.data),n?.(this,t?.exportInstance)}))}onError(){this.state=e.ERROR}onMount(){this.isPreLoad||(this.state=e.LOADED,this.mount())}registerRunningApp(){o(this),Promise.resolve().then((()=>o(null)))}async start(){this.source&&![e.ERROR,e.UNSET].includes(this.status)||(this.source=new _e(this.url),await this.source.importEntery(this))}unmount(t){this.state=e.UNMOUNT,this.sandBox?.deactivated(),t&&Ae.deleteApp(this.url),this.container.innerHTML="",this.container=void 0}set status(e){this.state=e}get status(){return this.state}}let b,g,C;class v{async=!1;code="";defer=!1;exportInstance;fromHtml;initial;isModule=!1;scoped;url;constructor({async:e,code:t,defer:n,fromHtml:o,initial:r,isModule:s,url:i}){this.code=t,this.async=e,this.defer=n,this.isModule=s,this.url=i,this.scoped=!1,this.fromHtml=o??!1,this.initial=r??!1}async excuteCode(e,t=!1){try{if(this.code||await this.getCode(e),e instanceof S){!function(e){g=void 0,b=g;for(const t in e)L(e,t)||(b?g||(g=t):b=t,C=t)}(e.scopeJs&&e.sandBox?.proxyWindow||window)}let n=this.code;if(n=this.transformCode(e),e.showSourceCode||this.isModule){const o=document.createElement("script");if(o.__BK_WEWEB_APP_KEY__&&delete o.__BK_WEWEB_APP_KEY__,e.registerRunningApp(),this.executeSourceScript(o,n),t)return o;const r=!(!e.keepAlive||e.container instanceof ShadowRoot),s=r?document.head:e.container;W(o,e,r),s.appendChild(o)}else if(this.executeMemoryScript(e,n),t)return document.createComment("【bk-weweb】dynamic script");if(e instanceof S){const t=e.scopeJs&&e.sandBox?.proxyWindow||window,n=function(e,t){let n,o,r=0;for(const s in e)if(!L(e,s)){if(0===r&&s!==b||1===r&&s!==g)return s;n?(C=s,o=t&&o||s):n=s===C,r+=1}return o}(t);n&&(this.exportInstance=t[n],e.scopeJs||delete t[n])}}catch(e){console.error("execute script code error",e)}}executeMemoryScript(e,t){try{const n=e instanceof ye&&e.scopeLocation;e.registerRunningApp(),new Function("window","location","history",t)(e.sandBox.proxyWindow,n?e.iframe.contentWindow.location:window.location,n?e.iframe.contentWindow.history:window.history)}catch(e){console.error(e)}}executeSourceScript(e,t){this.isModule?(e.src=this.url+"?key="+Date.now(),e.setAttribute("type","module")):e.textContent=t,this.url&&e.setAttribute("origin-src",this.url)}async getCode(e){if(this.code.length||!this.url)return this.code;let t="";return e?.source?.getScript(this.url)&&(t=e.source.getScript(this.url)?.code||""),!t&&Ae.getCacheScript(this.url)&&(t=Ae.getCacheScript(this.url)?.code||""),t||(t=await E(this.url).catch((e=>(console.error(`fetch script ${this.url} error`,e),"")))),this.code=t,t}setCode(e){this.code=e}transformCode(e){return e.sandBox?this.isModule?` with(window.${e.sandBox.windowSymbolKey}){\n ;${this.code}\n\n }`:e.showSourceCode?`;(function(window, self){\n with(window){\n ;${this.code}\n\n }\n }).call(window.${e.sandBox.windowSymbolKey},\n window.${e.sandBox.windowSymbolKey});`:`\n with(window) {\n try {\n ${this.code}\n }\n catch(e) {\n console.error(e)\n }\n }\n `:this.code}}function L(e,t){return!e.hasOwnProperty(t)||!isNaN(t)&&t<e.length||"undefined"!=typeof navigator&&-1!==navigator.userAgent.indexOf("Trident")&&e[t]&&"undefined"!=typeof window&&e[t].parent===window}async function x(e){const t=Array.from(e.source.scripts.values()).filter((e=>e.fromHtml||e.initial)),n=t.filter((e=>!e.async&&!e.defer||e.isModule));await Promise.all(n.map((t=>t.getCode(e)))),await Promise.all(n.map((t=>t.excuteCode(e))));const o=[],r=[];t.forEach((t=>{(t.defer||t.async)&&(!t.code&&t.defer?o.push(t.excuteCode(e)):r.push(t.excuteCode(e)))})),await Promise.all([...r,...o]).catch((e=>{console.error(e)}))}const{appendChild:P}=HTMLBodyElement.prototype;function T(e,t,n){if(t instanceof HTMLStyleElement){if(t.hasAttribute("exclude"))return document.createComment("【bk-weweb】style with exclude attribute is ignored");if(t.textContent&&!(n.container instanceof ShadowRoot)&&Ae.getBaseAppStyle(t.textContent))return document.createComment("【bk-weweb】style is effective in base app");if(!t.hasAttribute("ignore")){const e=new _({code:t.textContent||"",fromHtml:!1,url:""});n.source?.setStyle(d(),e),e.scopedStyleCSS(n,t)}return t}if(t instanceof HTMLLinkElement){const o=n.source?.collectLink(t,e,!0);return o?(o.style&&o.style.scopedLinkCSS(n,t),o.replace!==t?o.replace:t):t}if(t instanceof HTMLScriptElement){const o=n.source.collectScript(t,e,!0);if(!o)return t;if(o.script&&o.script.excuteCode(n),o.replace!==t)return o.replace;if(n.scopeJs&&!t.getAttribute("src")&&!t.textContent){const o=new MutationObserver((()=>{if(t.getAttribute("src")){o.disconnect();const r=n.source.collectScript(t,e,!0);if(r?.replace&&P.call(n.container,r.replace),h(t.getAttribute("src")))return void n.container?.append(t);r?.script&&r.script.excuteCode(n),t.remove()}else if(t.textContent){o.disconnect();const e=new v({async:!1,code:t.textContent,defer:"module"===t.type,fromHtml:!1,isModule:"module"===t.type});n.source.scripts.set(d(),e);try{e.excuteCode(n)}catch(e){console.error(e)}finally{!e.isModule&&y(t),t.remove()}}}));return o.observe(t,{attributeFilter:["src"],childList:!0,subtree:!1}),document.createComment("【bk-weweb】dynamic script or module")}return t}return t}function B(e){return e instanceof HTMLScriptElement||e instanceof HTMLStyleElement||e instanceof HTMLLinkElement}function M(e,t,n){if(t.__BK_WEWEB_APP_KEY__){const o=Ae.getApp(t.__BK_WEWEB_APP_KEY__);if(o?.container){const r=T(e,t,o),s=B(t)&&!!o.keepAlive&&!(o.container instanceof ShadowRoot),i=s?document.head:o?.container;return W(r,o,s),n.call(i,r)}}return n.call(e,t)}function R(e,t,n,o){if(t.__BK_WEWEB_APP_KEY__){const r=Ae.getApp(t.__BK_WEWEB_APP_KEY__);if(r?.container){const s=B(t)&&r.keepAlive&&!(r.container instanceof ShadowRoot),i=s?document.head:r?.container,c=T(e,t,r);return s&&W(c,r,s),n&&!i.contains(n)?P.call(i,c):o.call(i,c,n)}}return o.call(e,t,n)}function W(e,t,n){return n&&t&&(e.__KEEP_ALIVE__=t.appCacheKey,e.setAttribute("data-from",t.name),e.setAttribute("data-keep-alive","true")),e.setAttribute?.("powered-by","bk-weweb"),e}const{setAttribute:O}=Element.prototype,{append:H,appendChild:K,insertBefore:k,removeChild:D}=HTMLBodyElement.prototype,{appendChild:N,insertBefore:U,removeChild:I}=HTMLHeadElement.prototype,$=document.head;let j=!1;function V(){o(null),Element.prototype.setAttribute=O,HTMLBodyElement.prototype.appendChild=K,HTMLBodyElement.prototype.append=H,HTMLBodyElement.prototype.removeChild=D,HTMLBodyElement.prototype.insertBefore=k,HTMLHeadElement.prototype.appendChild=N,HTMLHeadElement.prototype.insertBefore=U,HTMLHeadElement.prototype.removeChild=I,j=!1}function Y(){j||(j=!0,Element.prototype.setAttribute=function(e,t){const n=this.tagName.toLocaleUpperCase();(["src","srcset"].includes(e)&&["IMG","SCRIPT"].includes(n)||"href"===e&&["LINK"].includes(n))&&this.__BK_WEWEB_APP_KEY__&&Ae.getApp(this.__BK_WEWEB_APP_KEY__||"")?O.call(this,e,l(t,Ae.getApp(this.__BK_WEWEB_APP_KEY__).url)):O.call(this,e,t)},HTMLBodyElement.prototype.appendChild=function(e){return e.__KEEP_ALIVE__&&B(e)?N.call($,e):M(this,e,K)},HTMLBodyElement.prototype.append=function(...e){e.forEach((e=>{if(e.__KEEP_ALIVE__&&B(e))return N.call($,e);M(this,e,K)}))},HTMLHeadElement.prototype.appendChild=HTMLBodyElement.prototype.appendChild,HTMLHeadElement.prototype.insertBefore=function(e,t){return R(this,e,t,U)},HTMLBodyElement.prototype.insertBefore=function(e,t){return R(this,e,t,U)},HTMLBodyElement.prototype.removeChild=function(e){const t=Ae.getApp(e.__BK_WEWEB_APP_KEY__);return t?.container?.contains(e)?D.call(t.container,e):this.contains(e)?D.call(this,e):e},HTMLHeadElement.prototype.removeChild=HTMLBodyElement.prototype.removeChild)}function J(t,n,o){const r=Ae.getApp(t);r?.status===e.DEACTIVATED&&r.keepAlive?c((()=>{Y(),r.activated(n,o)})):r&&c((()=>{Y(),r.mount(n,o)}))}function F(t){const n=Ae.getApp(t);n&&[e.ACTIVATED,e.MOUNTED].includes(n.status)&&(n.keepAlive?n.deactivated():n.unmount()),Ae.hasActiveApp||V()}async function q(e){return Y(),e.mode===exports.WewebMode.INSTANCE?await z(e):await G(e)}async function G(e){Y();let t=Ae.getApp(e.id);return t||(t=new ye(e),Ae.setApp(t)),await t.start(),t}function z(t){return Y(),new Promise((n=>{let o=Ae.getApp(t.id);if(o)if([e.MOUNTING,e.UNSET].includes(o.status)){const t=setInterval((()=>{[e.ERROR,e.MOUNTED].includes(o.status)&&(n(o),clearInterval(t))}),300)}else n(o);else o=new S(t),Ae.setApp(o),o.start().then((()=>n(o)))}))}function Z(t){const n=Ae.getApp(t);n&&n.status!==e.UNMOUNT&&n.unmount(),Ae.hasActiveApp||V()}var Q,X;!function(e){e.data="data",e.id="id",e.keepAlive="keepAlive",e.mode="mode",e.scopeCss="scopeCss",e.scopeJs="scopeJs",e.scopeLocation="scopeLocation",e.setShodowDom="setShodowDom",e.showSourceCode="showSourceCode",e.url="url"}(Q||(Q={}));class ee extends HTMLElement{appUrl="";connected=!1;static get observedAttributes(){return[Q.url]}getBooleanAttr(e){return this.hasAttribute(e)||this.hasAttribute(e.replace(/([A-Z])/g,"-$1").toLocaleLowerCase())?"false"!==this.getAttribute(e):void 0}async handleAttributeChanged(){if(!this.appKey)return;this.getBooleanAttr(Q.setShodowDom)&&this.attachShadow({mode:"open"});const t=Ae.getApp(this.appKey);!t||t.url!==this.appUrl||!t.isPreLoad&&t.status!==e.UNMOUNT?await q(this.appProps):J(this.appKey,this.shadowRoot??this)}attributeChangedCallback(e,t,n){if(e!==Q.url||this[e]===n||!this.connected)return;this.appUrl=n;const o=Ae.getApp(this.appKey);(this.connected||o)&&this.handleAttributeChanged()}async connectedCallback(){this.getBooleanAttr(Q.setShodowDom)&&!this.shadowRoot&&this.attachShadow({delegatesFocus:!1,mode:"open"}),await q(this.appProps),J(this.appKey,this.shadowRoot??this),this.connected=!0}disconnectedCallback(){this.connected=!1,this.appProps.keepAlive?F(this.appKey):Z(this.appKey)}get appData(){if(this.hasAttribute(Q.data))try{return JSON.parse(this.getAttribute(Q.data))}catch{}return{}}get appKey(){return this.getAttribute(Q.id)||this.getAttribute(Q.url)}get appProps(){return this.getAttribute("mode")===exports.WewebMode.INSTANCE?{container:this.shadowRoot??this,data:this.appData,id:this.appKey,keepAlive:this.getBooleanAttr(Q.keepAlive),mode:exports.WewebMode.INSTANCE,scopeCss:this.getBooleanAttr(Q.scopeCss)&&!this.getBooleanAttr(Q.setShodowDom),scopeJs:this.getBooleanAttr(Q.scopeJs),showSourceCode:this.getBooleanAttr(Q.showSourceCode),url:this.getAttribute(Q.url)}:{container:this.shadowRoot??this,data:this.appData,id:this.appKey,keepAlive:this.getBooleanAttr(Q.keepAlive),mode:exports.WewebMode.APP,scopeCss:!this.getBooleanAttr(Q.setShodowDom),scopeJs:!this.getBooleanAttr(Q.scopeJs),scopeLocation:this.getBooleanAttr(Q.scopeLocation),showSourceCode:this.getBooleanAttr(Q.showSourceCode),url:this.getAttribute(Q.url)}}}exports.WewebMode=void 0,(X=exports.WewebMode||(exports.WewebMode={})).APP="app",X.CONFIG="config",X.INSTANCE="js";const te=["System","__cjsWrapper","production"!==process.env.NODE_ENV?"__REACT_DEVTOOLS_GLOBAL_HOOK__":""],ne=["__POWERED_BY_BK_WEWEB__","__BK_WEWEB_APP_KEY__","__BK_WEWEB_DATA__"],oe=["window","self","globalThis"],re=["location","history"],se={__bk_pop_manager:!0,__bk_zIndex_manager:!0,i18n:!0},ie="production"!==process.env.NODE_ENV?{__DEV__:!0,__VUE_DEVTOOLS_GLOBAL_HOOK__:!0,__VUE_DEVTOOLS_HOOK_REPLAY__:!0,__VUE_DEVTOOLS_PLUGINS__:!0,__VUE_I18N_FULL_INSTALL__:!0,__VUE_I18N_LEGACY_API__:!0,__VUE_OPTIONS_API__:!0,"__core-js_shared__":!0,webpackChunkapm:!0,webpackChunkpc:!0,webpackChunktrace:!0,webpackJsonp:!0,...se}:se,ce=["body","html","head"],ae=(e,t)=>{const n=new Proxy({},{get(n,o){if(t.container instanceof ShadowRoot){const e=t.container[o];if("function"==typeof e)return e.bind(t.container);if(void 0!==e)return e}const r=Reflect.get(e.body,o);return"function"==typeof r?r.bind(e.body):r},set:(n,o,r)=>t.container instanceof ShadowRoot?(t.container[o]=r,!0):(Reflect.set(e.body,o,r),!0)});function o(n,o){const r=e.createElement(n,o);return r.__BK_WEWEB_APP_KEY__=t.appCacheKey,r}function r(o){if(o===n)return t.container instanceof ShadowRoot?t.container:e.body;if(ce.includes(o))return t?.container instanceof ShadowRoot?t?.container:e.querySelector.call(this,o);try{return t?.container?.querySelector(o)??null}catch{return null}}function s(n){return ce.includes(n)?t?.container instanceof ShadowRoot?t?.container:e.querySelector(n):t?.container?.querySelectorAll(n)??[]}function i(t){return r.call(e,`#${t}`)}function c(e){return s(`.${e}`)}function a(n){return ce.includes(n)||!t?.showSourceCode&&"script"===n.toLocaleLowerCase()?e.getElementsByTagName(n):s(n)}function l(e){return s(`[name=${e}]`)}return new Proxy({},{get(t,d){if("createElement"===d)return o.bind(e);if("querySelector"===d)return r.bind(e);if("querySelectorAll"===d)return s.bind(e);if("getElementById"===d)return i.bind(e);if("getElementsByClassName"===d)return c.bind(e);if("getElementsByTagName"===d)return a.bind(e);if("getElementsByName"===d)return l.bind(e);if("body"===d)return n;const u=Reflect.get(e,d);return"function"==typeof u?u.bind(e):u}})};const le=/^class\b/,de=/^function\b\s[A-Z].*/,ue=new WeakMap;const pe=new WeakMap;function he(e,t){if(pe.has(t))return pe.get(t);if("function"==typeof t&&!function(e){if(e.prototype?.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1)return!0;if(ue.has(e))return ue.get(e);const t=de.test(e.toString())||le.test(e.toString());return ue.set(e,t),t}(t)){const n=Function.prototype.bind.call(t,e);for(const e in t)n[e]=t[e];if(t.hasOwnProperty("prototype")&&!n.hasOwnProperty("prototype")&&Object.defineProperty(n,"prototype",{enumerable:!1,value:t.prototype,writable:!0}),"function"==typeof t.toString){const e=t.hasOwnProperty("toString")&&!n.hasOwnProperty("toString"),o=n.toString===Function.prototype.toString;if(e||o){const o=Object.getOwnPropertyDescriptor(e?t:Function.prototype,"toString");Object.defineProperty(n,"toString",{...o,...o?.get?null:{value:()=>t.toString()}})}}return pe.set(t,n),n}return t}class fe{app;active=!1;inRawWindowKeySet=new Set;resetDocumentAndBodyEvent;resetWindowFunction;sameRawWindowKeySet=new Set;fakeWindow;proxyDocument;proxyWindow;rawDocument;rawWindow;windowSymbolKey;constructor(e){this.app=e;const t=new Set,n=window;this.rawWindow=n,this.rawDocument=ae(document,e);const o=Object.create({});o.__BK_WEWEB_APP_KEY__=e.appCacheKey,o.__POWERED_BY_BK_WEWEB__=!0,o.rawDocument=document,o.rawWindow=n,o.__proto__=Window,this.fakeWindow=o;const{resetWindowFunction:s}=function(e){const t=new Map,n=[],o=window,{addEventListener:r,clearInterval:s,removeEventListener:i,setInterval:c}=window;return e.addEventListener=function(e,n,s){t.set(e,[...t.get(e)||[],n]),r.call(o,e,n,s)},e.removeEventListener=function(e,n,r){const s=t.get(e);if(s?.length){const e=s.indexOf(n);e>-1&&s.splice(e,1)}i.call(o,e,n,r)},e.setInterval=function(e,t,...r){const s=c.call(o,e,t,...r);return n.push(s),s},e.clearInterval=function(e){const t=n.indexOf(e);t>-1&&n.splice(t,1),s.call(o,e)},{resetWindowFunction:function(){t.size&&(t.forEach(((e,t)=>{e.forEach((e=>i.call(o,t,e)))})),t.clear()),n.length&&n.forEach((e=>{s.call(o,e)}))}}}(this.fakeWindow);this.resetWindowFunction=s,this.windowSymbolKey=`__${(e.name||e.appCacheKey).replace(/(-|,|:|~|'|")/gim,"_")}_${p(10)}__`,this.proxyWindow=new Proxy(this.fakeWindow,{defineProperty:(e,o,r)=>t.has(o)?Reflect.defineProperty(n,o,r):Reflect.defineProperty(e,o,r),deleteProperty:(e,t)=>!e.hasOwnProperty(t)||(this.sameRawWindowKeySet.has(t)&&this.sameRawWindowKeySet.delete(t),this.inRawWindowKeySet.has(t)&&Reflect.deleteProperty(n,t),Reflect.deleteProperty(e,t)),get:(t,o)=>{if(r.has(o)||o===Symbol.unscopables)return n[o];if(ie[o])return this.fakeWindow[o];if(oe.includes(o))return this.proxyWindow;if("document"===o)return e.registerRunningApp(),this.rawDocument;if("eval"===o)return e.registerRunningApp(),eval;if(re.includes(o)&&this.app instanceof ye&&this.app.iframe&&this.app.scopeLocation)return this.app.iframe.contentWindow?.[o];if("hasOwnProperty"===o)return e=>this.fakeWindow.hasOwnProperty(e)||n.hasOwnProperty(e);if("top"===o||"parent"===o)return n===n.parent?this.proxyWindow:Reflect.get(n,o);if("getComputedStyle"===o)return(e,t)=>e instanceof Element?n.getComputedStyle(e,t):n.getComputedStyle(document.body,t);if(Reflect.has(t,o)||ne.includes(o))return Reflect.get(t,o);const s=Reflect.get(n,o);return he(n,s)},getOwnPropertyDescriptor:(e,o)=>{if(e.hasOwnProperty(o))return Object.getOwnPropertyDescriptor(e,o);if(n.hasOwnProperty(o)){t.add(o);const e=Object.getOwnPropertyDescriptor(n,o);return e&&!e.configurable&&(e.configurable=!0),e}},has:(e,t)=>r.has(t)||t in e||t in n,ownKeys:e=>Array.from(new Set(Reflect.ownKeys(n).concat(Reflect.ownKeys(e)))),set:(e,t,o)=>{if(this.active){if(re.includes(t)&&this.app instanceof ye&&this.app.iframe&&this.app.scopeLocation)return Reflect.set(this.app.iframe.contentWindow,t,o);if("location"===t)Reflect.set(n,t,o);else if(e.hasOwnProperty(t)||!n.hasOwnProperty(t)||ne.includes(t))Reflect.set(e,t,o),this.sameRawWindowKeySet.add(t);else{const r=Object.getOwnPropertyDescriptor(n,t),{configurable:s,enumerable:i,writable:c}=r;c&&(Object.defineProperty(e,t,{configurable:s,enumerable:i,value:o,writable:c}),this.sameRawWindowKeySet.add(t))}!te.includes(t)||Reflect.has(n,t)||ne.includes(t)||(Reflect.set(n,t,o),this.inRawWindowKeySet.add(t))}return!0}}),e.showSourceCode&&(n[this.windowSymbolKey]=this.proxyWindow)}activeated(e){if(!this.active){this.active=!0,this.rawDocument=ae(document,this.app),this.fakeWindow.__BK_WEWEB_DATA__=e??{};const{resetDocumentAndBodyEvent:t}=function(){const{addEventListener:e,removeEventListener:t}=window.document,{addEventListener:o,removeEventListener:r}=window.document.body,s=new Map;return document.addEventListener=function(t,o,r){const i=n();if(i?.keepAlive){const e=s.get(t)||[];s.set(t,[...e,o])}e.call(i?.container instanceof ShadowRoot?i.container:this,t,o,r)},document.body.addEventListener=document.addEventListener,document.removeEventListener=function(e,o,r){const i=n();if(i?.keepAlive){const t=s.get(e)||[];t.length&&t.some((e=>e===o))&&t.splice(t.indexOf(o),1)}t.call(i?.container instanceof ShadowRoot?i.container:this,e,o,r)},document.body.removeEventListener=document.removeEventListener,{resetDocumentAndBodyEvent:function(){const i=n();i?.keepAlive&&s.values()&&Array.from(s.entries()).forEach((([e,t])=>{t?.forEach((t=>{document.removeEventListener.call(document,e,t)}))})),document.addEventListener=e,document.body.addEventListener=o,document.removeEventListener=t,document.body.removeEventListener=r,s.clear()}}}();this.resetDocumentAndBodyEvent=t}}deactivated(){this.active&&(this.active=!1,this.resetWindowFunction(),this.inRawWindowKeySet.forEach((e=>Reflect.deleteProperty(window,e))),this.inRawWindowKeySet.clear(),this.resetDocumentAndBodyEvent?.())}}const me="about:blank";class ye{state=e.UNSET;container;data;iframe=null;initSource;isModuleApp=!1;isPreLoad=!1;keepAlive;mode=exports.WewebMode.APP;name;sandBox;scopeCss;scopeJs;scopeLocation;showSourceCode;source;url;constructor(e){this.name=e.id!==e.url?e.id:p(5),this.mode=e.mode??exports.WewebMode.APP,this.container=e.container??void 0,this.showSourceCode=e.showSourceCode??!1,this.url=e.url,this.data=e.data||{},this.scopeJs=e.scopeJs??!0,this.scopeCss=e.scopeCss??!0,this.scopeLocation=e.scopeLocation??!1,this.isPreLoad=e.isPreLoad??!1,this.keepAlive=e.keepAlive??!1,this.initSource=e.initSource??[],this.scopeJs&&(this.sandBox=new fe(this)),this.container instanceof HTMLElement&&this.container.setAttribute(s,this.name)}activated(t,n){this.isPreLoad=!1,this.state=e.ACTIVATED;const o=this;if(t&&this.container){t instanceof Element&&t.setAttribute(s,this.name);const e=document.createDocumentFragment();Array.from(this.container.childNodes).forEach((t=>{t.__BK_WEWEB_APP_KEY__=this.appCacheKey,Object.defineProperties(t,{ownerDocument:{get:()=>o.sandBox?.rawDocument}}),e.appendChild(t)})),t.innerHTML="",t.appendChild(e),this.container=t,this.sandBox?.activeated(this.data),n?.(this)}}createIframe(){return new Promise((e=>{const t=document.createElement("iframe"),n=new URL(a(this.url)),o=navigator.userAgent.indexOf("Chrome")>-1;if(t.setAttribute("src",`${o?me:location.origin}${n.pathname||"/"}${n.search}${n.hash}`),t.style.cssText="display: none;",document.body.appendChild(t),o)setTimeout((()=>e(t)),0);else{const n=setInterval((()=>{t.contentWindow&&t.contentWindow.location.href!==me&&(t.contentWindow.stop(),t.contentDocument.body.parentElement.innerHTML="<head></head><body></body>",clearInterval(n),e(t))}),0)}}))}deactivated(){this.state=e.DEACTIVATED,this.sandBox?.deactivated()}mount(t,n){this.isPreLoad=!1,this.container=t??this.container,this.state=e.MOUNTING;const o=this;if(this.container){this.container instanceof Element&&this.container.setAttribute(s,this.name);const t=this.source.html.cloneNode(!0),r=document.createDocumentFragment();Array.from(t.childNodes).forEach((e=>{e.__BK_WEWEB_APP_KEY__=this.appCacheKey,Object.defineProperties(e,{ownerDocument:{get:()=>o.sandBox?.rawDocument}}),r.appendChild(e)})),this.container.innerHTML="",this.container.appendChild(r),this.sandBox?.activeated(this.data),x(this).finally((()=>{this.state=e.MOUNTED,n?.(this)}))}}onError(){this.state=e.ERROR}onMount(){this.isPreLoad||(this.state=e.LOADED,this.mount())}registerRunningApp(){o(this),Promise.resolve().then((()=>o(null)))}async start(){if(!this.source||[e.ERROR,e.UNSET].includes(this.status)){if(this.state=e.LOADING,this.scopeLocation||this.isModuleApp){const e=await this.createIframe();this.iframe=e}this.source=new _e(this.url),await this.source.importEntery(this)}}unmount(t=!1){this.state=e.UNMOUNT,this.sandBox?.deactivated(),t&&Ae.deleteApp(this.url),this.container.innerHTML="",this.container=void 0}get appCacheKey(){return this.url}get status(){return this.state}set status(e){this.state=e}}async function we(e){let t=[];if(t="function"==typeof e?await e():e||[],!t.length)return{};const n=new Map,o=new Map;return t.forEach((e=>{try{const t=new URL(e);if(t.pathname.match(/\.js$/)){const t=Ae.getCacheScript(e);n.set(e,new v({async:!1,code:t?.code||"",defer:!1,fromHtml:!1,initial:!0,isModule:!1,url:e}))}else if(t.pathname.match(/\.css$/)){const t=Ae.getCacheStyle(e);o.set(e,new _({code:t?.code||"",fromHtml:!0,initial:!0,prefetch:!1,preload:!1,url:e}))}}catch{console.error(`【bk-weweb】: ${e} is invalid URL`)}})),{collectScript:n,collectStyle:o}}const Ee=["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"];class _e{url;html=null;rawHtml;scripts;styles;constructor(e){this.url=e,this.scripts=new Map,this.styles=new Map}collectLink(e,t,n=!1){if(e.hasAttribute("exclude"))return{replace:document.createComment("【bk-weweb】style with exclude attribute is ignored")};if(e.hasAttribute("ignore"))return{replace:e};const o=e.getAttribute("rel");let r,s=e.getAttribute("href");if("stylesheet"===o&&s){s=l(s,this.url),r=document.createComment(`【bk-weweb】style with href=${s}`);let o=this.getStyle(s);return o||(o=new _({code:"",fromHtml:!n,prefetch:!!e.getAttribute("prefetch"),preload:!!e.getAttribute("preload"),url:s}),this.styles.set(s,o)),!n&&t.replaceChild(r,e),{replace:r,style:o}}return o&&["apple-touch-icon","icon","prefetch","preload","prerender"].includes(o)?(r=document.createComment(`【bk-weweb】style with rel=${o}${s?` & href=${s}`:""}`),!n&&t.removeChild(e),{replace:r}):(s&&e.setAttribute("href",l(s,this.url)),{replace:e})}collectScript(e,t,n=!1){if(e.hasAttribute("ignore")||"module"!==e.type&&h(e.getAttribute("src"))||e.hasAttribute("type")&&!Ee.includes(e.type))return;let o=null;if(e.hasAttribute("exclude"))return o=document.createComment("【bk-weweb】script element with exclude attribute is removed"),!n&&t.replaceChild(o,e),{replace:o};let r=e.getAttribute("src");if(r){r=l(r,this.url);let s=this.getScript(r);return s||(s=new v({async:e.hasAttribute("async"),code:"",defer:e.defer||"module"===e.type,fromHtml:!n,isModule:"module"===e.type,url:r}),this.scripts.set(r,s)),o=document.createComment(`【bk-weweb】script with src='${r}'`),!n&&t.replaceChild(o,e),{replace:o,script:s}}if(e.textContent){const r=d(),s=new v({async:!1,code:e.textContent,defer:"module"===e.type,fromHtml:!n,initial:!1,isModule:"module"===e.type,url:r});return this.scripts.set(r,s),o=document.createComment("【bk-weweb】script with texcontent"),!n&&t.replaceChild(o,e),{replace:o,script:s}}return{replace:e}}collectScriptAndStyle(e){const t=Array.from(e.querySelectorAll("link"));t?.forEach((e=>{this.collectLink(e,e.parentElement)}));const n=Array.from(e.querySelectorAll("style"));n?.forEach((e=>{e.hasAttribute("exclude")||e.hasAttribute("ignore")||(this.styles.set(d(),new _({code:e.textContent||"",fromHtml:!0,url:""})),e.remove())}));const o=Array.from(e.querySelectorAll("script"));o?.forEach((e=>{this.collectScript(e,e.parentElement)}));const r=Array.from(e.querySelectorAll("meta"));r?.forEach((e=>{e.parentElement.removeChild(e)}));const s=Array.from(e.querySelectorAll("img"));s?.forEach((e=>{e.hasAttribute("src")&&e.setAttribute("src",l(e.getAttribute("src"),this.url))}))}getScript(e){return this.scripts.get(e)}getStyle(e){return this.styles.get(e)||Array.from(this.styles.values()).find((t=>t.code===e))}async importEntery(e){if(e.initSource?.length){const{collectScript:t,collectStyle:n}=await we(e.initSource);t&&(this.scripts=t),n&&(this.styles=n)}e instanceof ye?await this.importHtmlEntry(e):e instanceof S&&await this.importInstanceEntry()}async importHtmlEntry(e){let t=Ae.getCacheHtml(this.url);if(!t&&(t=await E(a(this.url),{cache:"no-cache"}),!t))return console.error("load app entry error, pleace check"),Promise.reject();this.rawHtml=t;const n=document.createElement("div");n.__BK_WEWEB_APP_KEY__&&delete n.__BK_WEWEB_APP_KEY__,n.innerHTML=t.replace(/<\/?head>/gim,"").replace(/<\/?body>/i,""),this.collectScriptAndStyle(n),await A(e,n),this.html=n}async importInstanceEntry(){let e=Ae.getCacheScript(this.url)?.code;if(e||(e=await E(this.url,{cache:"no-cache"})),!e)return console.error("load app entry error, pleace check"),Promise.reject();this.scripts.set(this.url,new v({async:!1,code:e,defer:!1,fromHtml:!0,isModule:!!this.url.match(/\.ts$/),url:this.url}))}setScript(e,t){this.scripts.set(e,t instanceof v?t:new v(t))}setStyle(e,t){this.styles.set(e,t)}}const Ae=new class{baseSource;cache;constructor(){this.cache=new Map,this.baseSource=new _e(location.href)}deleteApp(e){this.cache.delete(e)}getApp(e){if(!e)return;const t=this.cache.get(e);return t||Array.from(this.cache.values()).find((t=>t.name===e))}getBaseAppStyle(e){return this.baseSource.getStyle(e)}getCacheHtml(e){const t=Array.from(this.cache.values()).find((t=>t.url===e));return t&&t.source?.rawHtml||""}getCacheScript(e){let t=this.baseSource.getScript(e);if(t)return;return Array.from(this.cache.values()).some((n=>(t=n.source?.getScript(e),!!t))),t}getCacheStyle(e){let t=this.baseSource.getStyle(e);if(t)return;return Array.from(this.cache.values()).some((n=>(t=n.source?.getStyle(e),!!t))),t}setApp(e){this.cache.set(e.appCacheKey,e)}setBaseAppScript(e,t){this.baseSource.setScript(e,t)}setBaseAppStyle(e,t){this.baseSource.setStyle(e,t)}get hasActiveApp(){return Array.from(this.cache.values()).some((t=>t.status!==e.UNMOUNT))}};function Se(e){if(e instanceof HTMLLinkElement){const t=e.getAttribute("rel");let n=e.getAttribute("href");if("stylesheet"===t&&n){n=l(n,location.origin);const t=document.createElement("style");return function(e,t,n){const o=document.createElement("style");W(o),E(e).then((r=>{t.code=r,Ae.setBaseAppStyle(e,t),o.textContent=r,y(n)})).catch((e=>{console.error(e),w(n)}))}(n,new _({code:"",fromHtml:!1,url:n}),e),t}}if(e instanceof HTMLScriptElement){let t=e.getAttribute("src");if(t&&"module"!==e.type){t=l(t,location.origin);const n=new v({async:e.hasAttribute("async"),code:"",defer:e.defer||"module"===e.type,fromHtml:!1,isModule:!1});Ae.setBaseAppScript(t,n);const o=function(e,t,n){const o=document.createElement("script");return W(o),E(e).then((r=>{t.setCode(r);try{o.textContent=r,e.startsWith("inline-")||n.setAttribute("origin-src",e)}catch(t){console.error(t,e)}y(n)})).catch((e=>{console.error(e),w(n)})),o}(t,n,e);return o||e}}return e}function be(e){return e instanceof HTMLLinkElement||e instanceof HTMLScriptElement}function ge(e,t,n){if(be(t)){const o=Se(t);return n.call(e,o)}return n.call(e,t)}function Ce(){const e=HTMLBodyElement.prototype.appendChild,t=HTMLHeadElement.prototype.appendChild,n=HTMLHeadElement.prototype.appendChild;HTMLBodyElement.prototype.appendChild=function(t){return ge(this,t,e)},HTMLHeadElement.prototype.appendChild=function(e){return ge(this,e,t)},HTMLHeadElement.prototype.insertBefore=function(e,t){return function(e,t,n,o){if(be(t)){const r=Se(t);return o.call(e,r,n)}return o.call(e,t,n)}(this,e,t,n)},window.addEventListener("load",(()=>{document.head.querySelectorAll("style").forEach((e=>{e.textContent&&Ae.setBaseAppStyle(d(),new _({code:e.textContent,fromHtml:!1,url:""}))}))}))}window.__getAppOrInstance__=function(e){return e?Ae.getApp(e):Ae};const ve="bk-weweb";class Le{fetchSource;webcomponentTag=ve;constructor(){window.customElements.get(ve)||window.customElements.define(ve,ee)}setWebComponentTag(){window.customElements.get(this.webcomponentTag)||window.customElements.define(this.webcomponentTag,ee)}start(e){e?.collectBaseSource&&Ce(),"function"==typeof e?.fetchSource&&(this.fetchSource=e.fetchSource),this.webcomponentTag=e?.webcomponentTag||ve,this.setWebComponentTag()}}const xe=new Le;exports.WeWeb=Le,exports.activated=J,exports.deactivated=F,exports.default=xe,exports.load=q,exports.loadApp=G,exports.loadInstance=z,exports.mount=function(e,t,n){const o=Ae.getApp(e);o&&c((()=>{Y(),o.mount(t,n)}))},exports.preLoadApp=function(e){u((()=>G({...e,isPreLoad:!0})))},exports.preLoadInstance=function(e){u((()=>z({...e,isPreLoad:!0})))},exports.preLoadSource=function(e){u((()=>{!async function(e){const{collectScript:t,collectStyle:n}=await we(e),o=[];t&&Array.from(t.entries()).forEach((e=>{o.push(e[1].getCode()),Ae.setBaseAppScript(...e)})),n&&Array.from(n.entries()).forEach((e=>{o.push(e[1].getCode()),Ae.setBaseAppStyle(...e)})),await Promise.all(o).catch((e=>{throw e}))}(e)}))},exports.unload=function(e){Ae.deleteApp(e)},exports.unmount=Z;
|
|
1
|
+
"use strict";var e;Object.defineProperty(exports,"__esModule",{value:!0}),function(e){e.ACTIVATED="ACTIVATED",e.DEACTIVATED="DEACTIVATED",e.ERROR="ERROR",e.LOADED="LOADED",e.LOADING="LOADING",e.MOUNTED="MOUNTED",e.MOUNTING="MOUNTING",e.UNMOUNT="UNMOUNT",e.UNSET="UNSET"}(e||(e={}));let t=null;function n(){return t}function o(e){t=e}const r=new Map;Object.getOwnPropertyNames(window).forEach((e=>{!r.has(e)&&e.match(/^[A-Z]/)&&"function"==typeof window[e]&&window[e].toString().includes("[native code]")&&r.set(e,!0)}));const i="id";var s;!function(e){e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.STYLE_RULE=1]="STYLE_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(s||(s={}));const c=e=>Promise.resolve().then(e);function a(e){return e.startsWith("//")?`${location.protocol}${e}`:e.startsWith("http")?e:`${location.protocol}//${e}`}function l(e,t){if(!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e))return e;const{origin:n,pathname:o}=new URL(a(t));return new URL(e,`${n}${o}`.replace(/\.(\w+)$/,"/")).toString()}function d(){return`inline-${h(16)}`}const u=window.requestIdleCallback||function(e){const t=Date.now();return setTimeout((()=>{e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)},h=(e,t="abcdefghijklmnopqrstuvwxyz0123456789")=>{let n="";for(let o=0;o<e;o++)n+=t[parseInt((Math.random()*t.length).toString(),10)];return n},p=e=>{if(!e)return!1;if(e.match(/\.js$/))return!1;const{pathname:t}=new URL(a(e));return!t.match(/\.js$/)},f=["currentTarget","srcElement","target"];function m(e,t="custom"){return Object.defineProperties(new CustomEvent(t),f.reduce(((t,n)=>(t[n]={get:()=>e},t)),{}))}function y(e){const t=m(e,"load");"function"!=typeof e.onload?e.dispatchEvent(t):e.onload(t)}function w(e){const t=m(e,"error");"function"!=typeof e.onerror?e.dispatchEvent(t):e.onerror(t)}function E(e,t={}){return Pe.fetchSource?Pe.fetchSource(e,t):window.fetch(e,t).then((e=>e.text()))}class _{code="";fromHtml;initial;prefetch=!1;preload=!1;scoped;scopedCode="";url;constructor({code:e,fromHtml:t,initial:n,prefetch:o,preload:r,url:i}){this.scoped=!1,this.code=e,this.prefetch=o??!1,this.preload=r??!1,this.url=i,this.fromHtml=t,this.initial=n??!1}commonScoped(e,t){if(!t.scopeCss||t.container instanceof ShadowRoot){const n=this.resetUrlHost(e.textContent||this.code||"",t.url,this.url);if(n&&t.container instanceof ShadowRoot){let e="";n.match(/@font-face\s*\{[^}]+\}/g)?.forEach((t=>{e+=`${t}\n`}));const o=t.sandBox?.rawDocument;if(o&&e){const t=o.createElement("style");t.setAttribute("type","text/css"),t.setAttribute("powered-by","bk-weweb"),t.textContent=e,o?.head?.append(t)}}e.textContent=n}else{const n=new CSSStyleSheet({disabled:!0});n.replaceSync(e.textContent||this.code);const o=Array.from(n?.cssRules??[]),r=`#${t.name}`,i=this.scopeRule(o,r),s=this.resetUrlHost(i,t.url,this.url);e.textContent=s,this.scopedCode=s}this.scoped=!0}createStyleElement(){const e=document.createElement("style");return e.__BK_WEWEB_APP_KEY__&&delete e.__BK_WEWEB_APP_KEY__,e}async excuteCode(e){e.registerRunningApp();let t=this.createStyleElement();t.setAttribute("type","text/css"),t.textContent=this.code;try{this.code||await this.getCode(e),t=this.scopedStyleCSS(e,t),this.scoped=!0}catch(e){console.error("scoped style error",e)}return t}async getCode(e){if(this.code.length||!this.url)return this.code;let t="";if(e?.source?.styles?.has(this.url)&&(t=e.source.styles.get(this.url)?.code||""),!t&&Ae.getCacheStyle(this.url)){const e=Ae.getCacheStyle(this.url);t=e?.code||""}return t||(t=await E(this.url).catch((()=>""))),this.code=t,t}linkedBaseStyle(e,t){return!(t.container instanceof ShadowRoot||!e.textContent||!Ae.getBaseAppStyle(e.textContent))&&(e.textContent="",e.innerHTML="",e.setAttribute("linked-from-base","true"),!0)}resetPackRule(e,t,n){const o=this.scopeRule(Array.from(e.cssRules),t);return`@${n} ${e.conditionText} {${o}}`}resetUrlHost(e,t,n){return e.replace(/url\(["']?([^)"']+)["']?\)/gm,((e,o)=>{if(/^(data|blob):/.test(o)||/^(https?:)?\/\//.test(o))return e;if(/^((\.\.?\/)|[^/])/.test(o)&&n){const e=n.split("/");e.pop(),t=a(`${e.join("/")}/`)}return`url("${l(o,t)}")`}))}scopeRule(e,t){let n="";for(const o of e)switch(o.type){case s.STYLE_RULE:n+=this.scopeStyleRule(o,t);break;case s.MEDIA_RULE:n+=this.resetPackRule(o,t,"media");break;case s.SUPPORTS_RULE:n+=this.resetPackRule(o,t,"supports");break;default:n+=o.cssText}return n.replace(/^\s+/,"")}scopeStyleRule(e,t){const{cssText:n,selectorText:o}=e;if(/^((html[\s>~,]+body)|(html|body|:root))$/.test(o))return n.replace(/^((html[\s>~,]+body)|(html|body|:root))/,t);if("*"===o)return n.replace("*",`${t} *`);const r=/(^|\s+)((html[\s>~]+body)|(html|body|:root))(?=[\s>~]+|$)/;return n.replace(/^[\s\S]+{/,(e=>e.replace(/(^|,)([^,]+)/g,((e,n,o)=>r.test(o)?e.replace(r,t):`${n} ${t} ${o.replace(/^\s*/,"")}`))))}scopedLinkCSS(e,t){const n=this.createStyleElement();n.setAttribute("type","text/css");const o=!(!e.keepAlive||e.container instanceof ShadowRoot);W(n,e,o);const r=o?document.head:e.container;try{if(this.code)this.commonScoped(n,e),r?.prepend(n),t&&y(t);else if(t.getAttribute("href"))this.url=l(t.getAttribute("href"),e.url),this.getCode(e).then((()=>{this.scopedStyleCSS(e,n),t.remove(),r?.prepend(n),t&&y(t),this.scoped=!0}));else{const o=new MutationObserver((()=>{t.href&&(o.disconnect(),this.url=l(t.getAttribute("href"),e.url),this.getCode(e).then((()=>{this.scopedStyleCSS(e,n),t.remove(),r?.prepend(n),t&&y(t),this.scoped=!0})))}));o.observe(t,{attributeFilter:["href"],childList:!1,subtree:!1})}}catch{t&&w(t)}return n}scopedStyleCSS(e,t){const n=!(!e.keepAlive||e.container instanceof ShadowRoot);if(W(t,e,n),this.code||t.textContent){if(t.textContent&&(t.textContent="",t.innerHTML=""),this.linkedBaseStyle(t,e))return t;this.commonScoped(t,e)}else{const n=new MutationObserver((()=>{(t.textContent||t.sheet?.cssRules?.length)&&(n.disconnect(),this.linkedBaseStyle(t,e)||this.commonScoped(t,e))}));n.observe(t,{attributes:!1,characterData:!0,childList:!0,subtree:!0})}return this.url&&t.setAttribute("origin-src",this.url),t}}async function A(e,t){const n=Array.from(e.source.styles.values()),o=[];n.forEach((t=>{o.push(t.excuteCode(e))})),await Promise.all(o).then((n=>{const o=t||e.container;!e.keepAlive||o instanceof ShadowRoot?o?.append(...n):document.head.append(...n)}))}class S{state=e.UNSET;appCacheKey;container;data;initSource;isPreLoad=!1;keepAlive;name;sandBox;scopeCss=!0;scopeJs=!1;showSourceCode=!0;source;url;constructor(e){this.name=e.id!==e.url?e.id:h(5),this.appCacheKey=e.id||this.name,this.url=e.url,this.container=e.container??void 0,this.scopeJs=e.scopeJs??!0,this.showSourceCode=e.showSourceCode??!0,this.scopeCss=e.scopeCss??!0,this.keepAlive=e.keepAlive??!1,this.data=e.data??{},this.initSource=e.initSource??[],this.scopeJs&&(this.sandBox=new fe(this))}activated(t,n){if(this.isPreLoad=!1,this.state=e.ACTIVATED,this.container&&t){t instanceof Element&&t.setAttribute(i,this.name);const e=document.createDocumentFragment();Array.from(this.container.childNodes).forEach((t=>{e.appendChild(t)})),t.appendChild(e),this.container=t,this.sandBox?.activeated();const o=this.source?.getScript(this.url);n?.(this,o?.exportInstance)}}deactivated(){this.state=e.DEACTIVATED,this.sandBox?.deactivated()}mount(t,n){this.isPreLoad=!1,this.container=t??this.container,this.state=e.MOUNTING,this.container instanceof HTMLElement&&this.container.setAttribute(i,this.name),this.container.innerHTML="";const o=document.createElement("div"),r=`${this.name}-wrapper`;o.setAttribute("id",r),this.source?.styles.size&&A(this,this.container),this.container.appendChild(o),this.sandBox?.activeated(),P(this).finally((()=>{this.state=e.MOUNTED;const t=this.source?.getScript(this.url);"function"==typeof t?.exportInstance?.render&&t.exportInstance.render(o,this.data),n?.(this,t?.exportInstance)}))}onError(){this.state=e.ERROR}onMount(){this.isPreLoad||(this.state=e.LOADED,this.mount())}registerRunningApp(){o(this),Promise.resolve().then((()=>o(null)))}async start(){this.source&&![e.ERROR,e.UNSET].includes(this.status)||(this.source=new _e(this.url),await this.source.importEntery(this))}unmount(t){this.state=e.UNMOUNT,this.sandBox?.deactivated(),t&&Ae.deleteApp(this.url),this.container.innerHTML="",this.container=void 0}set status(e){this.state=e}get status(){return this.state}}let g,b,C;class v{async=!1;code="";defer=!1;exportInstance;fromHtml;initial;isModule=!1;scoped;url;constructor({async:e,code:t,defer:n,fromHtml:o,initial:r,isModule:i,url:s}){this.code=t,this.async=e,this.defer=n,this.isModule=i,this.url=s,this.scoped=!1,this.fromHtml=o??!1,this.initial=r??!1}async excuteCode(e,t=!1){try{if(this.code||await this.getCode(e),e instanceof S){!function(e){b=void 0,g=b;for(const t in e)L(e,t)||(g?b||(b=t):g=t,C=t)}(e.scopeJs&&e.sandBox?.proxyWindow||window)}let n=this.code;if(n=this.transformCode(e),e.showSourceCode||this.isModule){const o=document.createElement("script");if(o.__BK_WEWEB_APP_KEY__&&delete o.__BK_WEWEB_APP_KEY__,e.registerRunningApp(),this.executeSourceScript(o,n),t)return o;const r=!(!e.keepAlive||e.container instanceof ShadowRoot),i=r?document.head:e.container;W(o,e,r),i.appendChild(o)}else if(this.executeMemoryScript(e,n),t)return document.createComment("【bk-weweb】dynamic script");if(e instanceof S){const t=e.scopeJs&&e.sandBox?.proxyWindow||window,n=function(e,t){let n,o,r=0;for(const i in e)if(!L(e,i)){if(0===r&&i!==g||1===r&&i!==b)return i;n?(C=i,o=t&&o||i):n=i===C,r+=1}return o}(t);n&&(this.exportInstance=t[n],e.scopeJs||delete t[n])}}catch(e){console.error("execute script code error",e)}}executeMemoryScript(e,t){try{const n=e instanceof ye&&e.scopeLocation;e.registerRunningApp(),new Function("window","location","history",t)(e.sandBox.proxyWindow,n?e.iframe.contentWindow.location:window.location,n?e.iframe.contentWindow.history:window.history)}catch(e){console.error(e)}}executeSourceScript(e,t){this.isModule?(e.src=this.url+"?key="+Date.now(),e.setAttribute("type","module")):e.textContent=t,this.url&&e.setAttribute("origin-src",this.url)}async getCode(e){if(this.code.length||!this.url)return this.code;let t="";return e?.source?.getScript(this.url)&&(t=e.source.getScript(this.url)?.code||""),!t&&Ae.getCacheScript(this.url)&&(t=Ae.getCacheScript(this.url)?.code||""),t||(t=await E(this.url).catch((e=>(console.error(`fetch script ${this.url} error`,e),"")))),this.code=t,t}setCode(e){this.code=e}transformCode(e){return e.sandBox?this.isModule?` with(window.${e.sandBox.windowSymbolKey}){\n ;${this.code}\n\n }`:e.showSourceCode?`;(function(window, self){\n with(window){\n ;${this.code}\n\n }\n }).call(window.${e.sandBox.windowSymbolKey},\n window.${e.sandBox.windowSymbolKey});`:`\n with(window) {\n try {\n ${this.code}\n }\n catch(e) {\n console.error(e)\n }\n }\n `:this.code}}function L(e,t){return!e.hasOwnProperty(t)||!isNaN(t)&&t<e.length||"undefined"!=typeof navigator&&-1!==navigator.userAgent.indexOf("Trident")&&e[t]&&"undefined"!=typeof window&&e[t].parent===window}async function P(e){const t=Array.from(e.source.scripts.values()).filter((e=>e.fromHtml||e.initial)),n=t.filter((e=>!e.async&&!e.defer||e.isModule));await Promise.all(n.map((t=>t.getCode(e)))),await Promise.all(n.map((t=>t.excuteCode(e))));const o=[],r=[];t.forEach((t=>{(t.defer||t.async)&&(!t.code&&t.defer?o.push(t.excuteCode(e)):r.push(t.excuteCode(e)))})),await Promise.all([...r,...o]).catch((e=>{console.error(e)}))}const{appendChild:x}=HTMLBodyElement.prototype;function B(e,t,n){if(t instanceof HTMLStyleElement){if(t.hasAttribute("exclude"))return document.createComment("【bk-weweb】style with exclude attribute is ignored");if(t.textContent&&!(n.container instanceof ShadowRoot)&&Ae.getBaseAppStyle(t.textContent))return document.createComment("【bk-weweb】style is effective in base app");if(!t.hasAttribute("ignore")){const e=new _({code:t.textContent||"",fromHtml:!1,url:""});n.source?.setStyle(d(),e),e.scopedStyleCSS(n,t)}return t}if(t instanceof HTMLLinkElement){const o=n.source?.collectLink(t,e,!0);return o?(o.style&&o.style.scopedLinkCSS(n,t),o.replace!==t?o.replace:t):t}if(t instanceof HTMLScriptElement){const o=n.source.collectScript(t,e,!0);if(!o)return t;if(o.script&&o.script.excuteCode(n),o.replace!==t)return o.replace;if(n.scopeJs&&!t.getAttribute("src")&&!t.textContent){const o=new MutationObserver((()=>{if(t.getAttribute("src")){o.disconnect();const r=n.source.collectScript(t,e,!0);if(r?.replace&&x.call(n.container,r.replace),p(t.getAttribute("src")))return void n.container?.append(t);r?.script&&r.script.excuteCode(n),t.remove()}else if(t.textContent){o.disconnect();const e=new v({async:!1,code:t.textContent,defer:"module"===t.type,fromHtml:!1,isModule:"module"===t.type});n.source.scripts.set(d(),e);try{e.excuteCode(n)}catch(e){console.error(e)}finally{!e.isModule&&y(t),t.remove()}}}));return o.observe(t,{attributeFilter:["src"],childList:!0,subtree:!1}),document.createComment("【bk-weweb】dynamic script or module")}return t}return t}function T(e){return e instanceof HTMLScriptElement||e instanceof HTMLStyleElement||e instanceof HTMLLinkElement}function R(e,t,n){if(t.__BK_WEWEB_APP_KEY__){const o=Ae.getApp(t.__BK_WEWEB_APP_KEY__);if(o?.container){const r=B(e,t,o),i=T(t)&&!!o.keepAlive&&!(o.container instanceof ShadowRoot),s=i?document.head:o?.container;return W(r,o,i),n.call(s,r)}}return n.call(e,t)}function M(e,t,n,o){if(t.__BK_WEWEB_APP_KEY__){const r=Ae.getApp(t.__BK_WEWEB_APP_KEY__);if(r?.container){const i=T(t)&&r.keepAlive&&!(r.container instanceof ShadowRoot),s=i?document.head:r?.container,c=B(e,t,r);return i&&W(c,r,i),n&&!s.contains(n)?x.call(s,c):o.call(s,c,n)}}return o.call(e,t,n)}function W(e,t,n){return n&&t&&(e.__KEEP_ALIVE__=t.appCacheKey,e.setAttribute("data-from",t.name),e.setAttribute("data-keep-alive","true")),e.setAttribute?.("powered-by","bk-weweb"),e}const{setAttribute:O}=Element.prototype,{append:H,appendChild:K,insertBefore:k,removeChild:D}=HTMLBodyElement.prototype,{appendChild:N,insertBefore:U,removeChild:I}=HTMLHeadElement.prototype,$=document.head;let j=!1;function V(){o(null),Element.prototype.setAttribute=O,HTMLBodyElement.prototype.appendChild=K,HTMLBodyElement.prototype.append=H,HTMLBodyElement.prototype.removeChild=D,HTMLBodyElement.prototype.insertBefore=k,HTMLHeadElement.prototype.appendChild=N,HTMLHeadElement.prototype.insertBefore=U,HTMLHeadElement.prototype.removeChild=I,j=!1}function Y(){j||(j=!0,Element.prototype.setAttribute=function(e,t){const n=this.tagName.toLocaleUpperCase();(["src","srcset"].includes(e)&&["IMG","SCRIPT"].includes(n)||"href"===e&&["LINK"].includes(n))&&this.__BK_WEWEB_APP_KEY__&&Ae.getApp(this.__BK_WEWEB_APP_KEY__||"")?O.call(this,e,l(t,Ae.getApp(this.__BK_WEWEB_APP_KEY__).url)):O.call(this,e,t)},HTMLBodyElement.prototype.appendChild=function(e){return e.__KEEP_ALIVE__&&T(e)?N.call($,e):R(this,e,K)},HTMLBodyElement.prototype.append=function(...e){e.forEach((e=>{if(e.__KEEP_ALIVE__&&T(e))return N.call($,e);R(this,e,K)}))},HTMLHeadElement.prototype.appendChild=HTMLBodyElement.prototype.appendChild,HTMLHeadElement.prototype.insertBefore=function(e,t){return M(this,e,t,U)},HTMLBodyElement.prototype.insertBefore=function(e,t){return M(this,e,t,U)},HTMLBodyElement.prototype.removeChild=function(e){const t=Ae.getApp(e.__BK_WEWEB_APP_KEY__);return t?.container?.contains(e)?D.call(t.container,e):this.contains(e)?D.call(this,e):e},HTMLHeadElement.prototype.removeChild=HTMLBodyElement.prototype.removeChild)}function J(t,n,o){const r=Ae.getApp(t);r?.status===e.DEACTIVATED&&r.keepAlive?c((()=>{Y(),r.activated(n,o)})):r&&c((()=>{Y(),r.mount(n,o)}))}function F(t){const n=Ae.getApp(t);n&&[e.ACTIVATED,e.MOUNTED].includes(n.status)&&(n.keepAlive?n.deactivated():n.unmount()),Ae.hasActiveApp||V()}async function q(e){return Y(),e.mode===exports.WewebMode.INSTANCE?await z(e):await G(e)}async function G(e){Y();let t=Ae.getApp(e.id);return t||(t=new ye(e),Ae.setApp(t)),await t.start(),t}function z(t){return Y(),new Promise((n=>{let o=Ae.getApp(t.id);if(o)if([e.MOUNTING,e.UNSET].includes(o.status)){const t=setInterval((()=>{[e.ERROR,e.MOUNTED].includes(o.status)&&(n(o),clearInterval(t))}),300)}else n(o);else o=new S(t),Ae.setApp(o),o.start().then((()=>n(o)))}))}function Z(t){const n=Ae.getApp(t);n&&n.status!==e.UNMOUNT&&n.unmount(),Ae.hasActiveApp||V()}var Q,X;!function(e){e.data="data",e.id="id",e.keepAlive="keepAlive",e.mode="mode",e.scopeCss="scopeCss",e.scopeJs="scopeJs",e.scopeLocation="scopeLocation",e.setShodowDom="setShodowDom",e.showSourceCode="showSourceCode",e.url="url"}(Q||(Q={}));class ee extends HTMLElement{appUrl="";connected=!1;static get observedAttributes(){return[Q.url]}getBooleanAttr(e){return this.hasAttribute(e)||this.hasAttribute(e.replace(/([A-Z])/g,"-$1").toLocaleLowerCase())?"false"!==this.getAttribute(e):void 0}async handleAttributeChanged(){if(!this.appKey)return;this.getBooleanAttr(Q.setShodowDom)&&this.attachShadow({mode:"open"});const t=Ae.getApp(this.appKey);!t||t.url!==this.appUrl||!t.isPreLoad&&t.status!==e.UNMOUNT?await q(this.appProps):J(this.appKey,this.shadowRoot??this)}attributeChangedCallback(e,t,n){if(e!==Q.url||this[e]===n||!this.connected)return;this.appUrl=n;const o=Ae.getApp(this.appKey);(this.connected||o)&&this.handleAttributeChanged()}async connectedCallback(){this.getBooleanAttr(Q.setShodowDom)&&!this.shadowRoot&&this.attachShadow({delegatesFocus:!1,mode:"open"}),await q(this.appProps),J(this.appKey,this.shadowRoot??this),this.connected=!0}disconnectedCallback(){this.connected=!1,this.appProps.keepAlive?F(this.appKey):Z(this.appKey)}get appData(){if(this.hasAttribute(Q.data))try{return JSON.parse(this.getAttribute(Q.data))}catch{}return{}}get appKey(){return this.getAttribute(Q.id)||this.getAttribute(Q.url)}get appProps(){return this.getAttribute("mode")===exports.WewebMode.INSTANCE?{container:this.shadowRoot??this,data:this.appData,id:this.appKey,keepAlive:this.getBooleanAttr(Q.keepAlive),mode:exports.WewebMode.INSTANCE,scopeCss:this.getBooleanAttr(Q.scopeCss)&&!this.getBooleanAttr(Q.setShodowDom),scopeJs:this.getBooleanAttr(Q.scopeJs),showSourceCode:this.getBooleanAttr(Q.showSourceCode),url:this.getAttribute(Q.url)}:{container:this.shadowRoot??this,data:this.appData,id:this.appKey,keepAlive:this.getBooleanAttr(Q.keepAlive),mode:exports.WewebMode.APP,scopeCss:!this.getBooleanAttr(Q.setShodowDom),scopeJs:!this.getBooleanAttr(Q.scopeJs),scopeLocation:this.getBooleanAttr(Q.scopeLocation),showSourceCode:this.getBooleanAttr(Q.showSourceCode),url:this.getAttribute(Q.url)}}}exports.WewebMode=void 0,(X=exports.WewebMode||(exports.WewebMode={})).APP="app",X.CONFIG="config",X.INSTANCE="js";const te=["System","__cjsWrapper","production"!==process.env.NODE_ENV?"__REACT_DEVTOOLS_GLOBAL_HOOK__":""],ne=["__POWERED_BY_BK_WEWEB__","__BK_WEWEB_APP_KEY__","__BK_WEWEB_DATA__"],oe=["window","self","globalThis"],re=["location","history"],ie={__bk_pop_manager:!0,__bk_zIndex_manager:!0,i18n:!0},se="production"!==process.env.NODE_ENV?{__DEV__:!0,__VUE_DEVTOOLS_GLOBAL_HOOK__:!0,__VUE_DEVTOOLS_HOOK_REPLAY__:!0,__VUE_DEVTOOLS_PLUGINS__:!0,__VUE_I18N_FULL_INSTALL__:!0,__VUE_I18N_LEGACY_API__:!0,__VUE_OPTIONS_API__:!0,"__core-js_shared__":!0,webpackChunkapm:!0,webpackChunkpc:!0,webpackChunktrace:!0,webpackJsonp:!0,...ie}:ie,ce=["body","html","head"],ae=(e,t)=>{const n=new Proxy({},{get(n,o){if(t.container instanceof ShadowRoot){const e=t.container[o];if("function"==typeof e)return e.bind(t.container);if(void 0!==e)return e}const r=Reflect.get(e.body,o);return"function"==typeof r?r.bind(e.body):r},set:(n,o,r)=>t.container instanceof ShadowRoot?(t.container[o]=r,!0):(Reflect.set(e.body,o,r),!0)});function o(n,o){const r=e.createElement(n,o);return r.__BK_WEWEB_APP_KEY__=t.appCacheKey,r}function r(o){if(o===n)return t.container instanceof ShadowRoot?t.container:e.body;if(ce.includes(o))return t?.container instanceof ShadowRoot?t?.container:e.querySelector.call(this,o);try{return t?.container?.querySelector(o)??null}catch{return null}}function i(n){return ce.includes(n)?t?.container instanceof ShadowRoot?t?.container:e.querySelector(n):t?.container?.querySelectorAll(n)??[]}function s(t){return r.call(e,`#${t}`)}function c(e){return i(`.${e}`)}function a(n){return ce.includes(n)||!t?.showSourceCode&&"script"===n.toLocaleLowerCase()?e.getElementsByTagName(n):i(n)}function l(e){return i(`[name=${e}]`)}return new Proxy({},{get(t,d){if("createElement"===d)return o.bind(e);if("querySelector"===d)return r.bind(e);if("querySelectorAll"===d)return i.bind(e);if("getElementById"===d)return s.bind(e);if("getElementsByClassName"===d)return c.bind(e);if("getElementsByTagName"===d)return a.bind(e);if("getElementsByName"===d)return l.bind(e);if("body"===d)return n;const u=Reflect.get(e,d);return"function"==typeof u?u.bind(e):u}})};const le=/^class\b/,de=/^function\b\s[A-Z].*/,ue=new WeakMap;const he=new WeakMap;function pe(e,t){if(he.has(t))return he.get(t);if("function"==typeof t&&!function(e){if(e.prototype?.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1)return!0;if(ue.has(e))return ue.get(e);const t=de.test(e.toString())||le.test(e.toString());return ue.set(e,t),t}(t)){const n=Function.prototype.bind.call(t,e);for(const e in t)n[e]=t[e];if(t.hasOwnProperty("prototype")&&!n.hasOwnProperty("prototype")&&Object.defineProperty(n,"prototype",{enumerable:!1,value:t.prototype,writable:!0}),"function"==typeof t.toString){const e=t.hasOwnProperty("toString")&&!n.hasOwnProperty("toString"),o=n.toString===Function.prototype.toString;if(e||o){const o=Object.getOwnPropertyDescriptor(e?t:Function.prototype,"toString");Object.defineProperty(n,"toString",{...o,...o?.get?null:{value:()=>t.toString()}})}}return he.set(t,n),n}return t}class fe{app;active=!1;inRawWindowKeySet=new Set;resetDocumentAndBodyEvent;resetWindowFunction;sameRawWindowKeySet=new Set;fakeWindow;proxyDocument;proxyWindow;rawDocument;rawWindow;windowSymbolKey;constructor(e){this.app=e;const t=new Set,n=window;this.rawWindow=n,this.rawDocument=ae(document,e);const o=Object.create({});o.__BK_WEWEB_APP_KEY__=e.appCacheKey,o.__POWERED_BY_BK_WEWEB__=!0,o.rawDocument=document,o.rawWindow=n,o.__proto__=Window,this.fakeWindow=o;const{resetWindowFunction:i}=function(e){const t=new Map,n=[],o=window,{addEventListener:r,clearInterval:i,removeEventListener:s,setInterval:c}=window;return e.addEventListener=function(e,n,i){t.set(e,[...t.get(e)||[],n]),r.call(o,e,n,i)},e.removeEventListener=function(e,n,r){const i=t.get(e);if(i?.length){const e=i.indexOf(n);e>-1&&i.splice(e,1)}s.call(o,e,n,r)},e.setInterval=function(e,t,...r){const i=c.call(o,e,t,...r);return n.push(i),i},e.clearInterval=function(e){const t=n.indexOf(e);t>-1&&n.splice(t,1),i.call(o,e)},{resetWindowFunction:function(){t.size&&(t.forEach(((e,t)=>{e.forEach((e=>s.call(o,t,e)))})),t.clear()),n.length&&n.forEach((e=>{i.call(o,e)}))}}}(this.fakeWindow);this.resetWindowFunction=i,this.windowSymbolKey=`__${(e.name||e.appCacheKey).replace(/(-|,|:|~|'|")/gim,"_")}_${h(10)}__`,this.proxyWindow=new Proxy(this.fakeWindow,{defineProperty:(e,o,r)=>t.has(o)?Reflect.defineProperty(n,o,r):Reflect.defineProperty(e,o,r),deleteProperty:(e,t)=>!e.hasOwnProperty(t)||(this.sameRawWindowKeySet.has(t)&&this.sameRawWindowKeySet.delete(t),this.inRawWindowKeySet.has(t)&&Reflect.deleteProperty(n,t),Reflect.deleteProperty(e,t)),get:(t,o)=>{if(r.has(o)||o===Symbol.unscopables)return n[o];if(se[o])return this.fakeWindow[o];if(oe.includes(o))return this.proxyWindow;if("document"===o)return e.registerRunningApp(),this.rawDocument;if("eval"===o)return e.registerRunningApp(),eval;if(re.includes(o)&&this.app instanceof ye&&this.app.iframe&&this.app.scopeLocation)return this.app.iframe.contentWindow?.[o];if("hasOwnProperty"===o)return e=>this.fakeWindow.hasOwnProperty(e)||n.hasOwnProperty(e);if("top"===o||"parent"===o)return n===n.parent?this.proxyWindow:Reflect.get(n,o);if("getComputedStyle"===o)return(e,t)=>e instanceof Element?n.getComputedStyle(e,t):n.getComputedStyle(document.body,t);if(Reflect.has(t,o)||ne.includes(o))return Reflect.get(t,o);const i=Reflect.get(n,o);return pe(n,i)},getOwnPropertyDescriptor:(e,o)=>{if(e.hasOwnProperty(o))return Object.getOwnPropertyDescriptor(e,o);if(n.hasOwnProperty(o)){t.add(o);const e=Object.getOwnPropertyDescriptor(n,o);return e&&!e.configurable&&(e.configurable=!0),e}},has:(e,t)=>r.has(t)||t in e||t in n,ownKeys:e=>Array.from(new Set(Reflect.ownKeys(n).concat(Reflect.ownKeys(e)))),set:(e,t,o)=>{if(this.active){if(re.includes(t)&&this.app instanceof ye&&this.app.iframe&&this.app.scopeLocation)return Reflect.set(this.app.iframe.contentWindow,t,o);if("location"===t)Reflect.set(n,t,o);else if(e.hasOwnProperty(t)||!n.hasOwnProperty(t)||ne.includes(t))Reflect.set(e,t,o),this.sameRawWindowKeySet.add(t);else{const r=Object.getOwnPropertyDescriptor(n,t),{configurable:i,enumerable:s,writable:c}=r;c&&(Object.defineProperty(e,t,{configurable:i,enumerable:s,value:o,writable:c}),this.sameRawWindowKeySet.add(t))}!te.includes(t)||Reflect.has(n,t)||ne.includes(t)||(Reflect.set(n,t,o),this.inRawWindowKeySet.add(t))}return!0}}),e.showSourceCode&&(n[this.windowSymbolKey]=this.proxyWindow)}activeated(e){if(!this.active){this.active=!0,this.rawDocument=ae(document,this.app),this.fakeWindow.__BK_WEWEB_DATA__=e??{};const{resetDocumentAndBodyEvent:t}=function(){const{addEventListener:e,removeEventListener:t}=window.document,{addEventListener:o,removeEventListener:r}=window.document.body,i=new Map;return document.addEventListener=function(t,o,r){const s=n();if(s?.keepAlive){const e=i.get(t)||[];i.set(t,[...e,o])}e.call(s?.container instanceof ShadowRoot?s.container:this,t,o,r)},document.body.addEventListener=document.addEventListener,document.removeEventListener=function(e,o,r){const s=n();if(s?.keepAlive){const t=i.get(e)||[];t.length&&t.some((e=>e===o))&&t.splice(t.indexOf(o),1)}t.call(s?.container instanceof ShadowRoot?s.container:this,e,o,r)},document.body.removeEventListener=document.removeEventListener,{resetDocumentAndBodyEvent:function(){const s=n();s?.keepAlive&&i.values()&&Array.from(i.entries()).forEach((([e,t])=>{t?.forEach((t=>{document.removeEventListener.call(document,e,t)}))})),document.addEventListener=e,document.body.addEventListener=o,document.removeEventListener=t,document.body.removeEventListener=r,i.clear()}}}();this.resetDocumentAndBodyEvent=t}}deactivated(){this.active&&(this.active=!1,this.resetWindowFunction(),this.inRawWindowKeySet.forEach((e=>Reflect.deleteProperty(window,e))),this.inRawWindowKeySet.clear(),this.resetDocumentAndBodyEvent?.())}}const me="about:blank";class ye{state=e.UNSET;container;data;iframe=null;initSource;isModuleApp=!1;isPreLoad=!1;keepAlive;mode=exports.WewebMode.APP;name;sandBox;scopeCss;scopeJs;scopeLocation;showSourceCode;source;url;constructor(e){this.name=e.id!==e.url?e.id:h(5),this.mode=e.mode??exports.WewebMode.APP,this.container=e.container??void 0,this.showSourceCode=e.showSourceCode??!1,this.url=e.url,this.data=e.data||{},this.scopeJs=e.scopeJs??!0,this.scopeCss=e.scopeCss??!0,this.scopeLocation=e.scopeLocation??!1,this.isPreLoad=e.isPreLoad??!1,this.keepAlive=e.keepAlive??!1,this.initSource=e.initSource??[],this.scopeJs&&(this.sandBox=new fe(this)),this.container instanceof HTMLElement&&this.container.setAttribute(i,this.name)}activated(t,n){this.isPreLoad=!1,this.state=e.ACTIVATED;const o=this;if(t&&this.container){t instanceof Element&&t.setAttribute(i,this.name);const e=document.createDocumentFragment();Array.from(this.container.childNodes).forEach((t=>{t.__BK_WEWEB_APP_KEY__=this.appCacheKey,Object.defineProperties(t,{ownerDocument:{get:()=>o.sandBox?.rawDocument}}),e.appendChild(t)})),t.innerHTML="",t.appendChild(e),this.container=t,this.initShadowRootContainer(),this.sandBox?.activeated(this.data),n?.(this)}}createIframe(){return new Promise((e=>{const t=document.createElement("iframe"),n=new URL(a(this.url)),o=navigator.userAgent.indexOf("Chrome")>-1;if(t.setAttribute("src",`${o?me:location.origin}${n.pathname||"/"}${n.search}${n.hash}`),t.style.cssText="display: none;",document.body.appendChild(t),o)setTimeout((()=>e(t)),0);else{const n=setInterval((()=>{t.contentWindow&&t.contentWindow.location.href!==me&&(t.contentWindow.stop(),t.contentDocument.body.parentElement.innerHTML="<head></head><body></body>",clearInterval(n),e(t))}),0)}}))}deactivated(){this.state=e.DEACTIVATED,this.sandBox?.deactivated()}initShadowRootContainer(){this.container instanceof ShadowRoot&&Object.defineProperties(this.container,{getBoundingClientRect:{get(){return this.container.host.getBoundingClientRect}}})}mount(t,n){this.isPreLoad=!1,this.container=t??this.container,this.initShadowRootContainer(),this.state=e.MOUNTING;const o=this;if(this.container){this.container instanceof Element&&this.container.setAttribute(i,this.name);const t=this.source.html.cloneNode(!0),r=document.createDocumentFragment();Array.from(t.childNodes).forEach((e=>{e.__BK_WEWEB_APP_KEY__=this.appCacheKey,Object.defineProperties(e,{ownerDocument:{get:()=>o.sandBox?.rawDocument}}),r.appendChild(e)})),this.container.innerHTML="",this.container.appendChild(r),this.sandBox?.activeated(this.data),P(this).finally((()=>{this.state=e.MOUNTED,n?.(this)}))}}onError(){this.state=e.ERROR}onMount(){this.isPreLoad||(this.state=e.LOADED,this.mount())}registerRunningApp(){o(this),Promise.resolve().then((()=>o(null)))}async start(){if(!this.source||[e.ERROR,e.UNSET].includes(this.status)){if(this.state=e.LOADING,this.scopeLocation||this.isModuleApp){const e=await this.createIframe();this.iframe=e}this.source=new _e(this.url),await this.source.importEntery(this)}}unmount(t=!1){this.state=e.UNMOUNT,this.sandBox?.deactivated(),t&&Ae.deleteApp(this.url),this.container.innerHTML="",this.container=void 0}get appCacheKey(){return this.url}get status(){return this.state}set status(e){this.state=e}}async function we(e){let t=[];if(t="function"==typeof e?await e():e||[],!t.length)return{};const n=new Map,o=new Map;return t.forEach((e=>{try{const t=new URL(e);if(t.pathname.match(/\.js$/)){const t=Ae.getCacheScript(e);n.set(e,new v({async:!1,code:t?.code||"",defer:!1,fromHtml:!1,initial:!0,isModule:!1,url:e}))}else if(t.pathname.match(/\.css$/)){const t=Ae.getCacheStyle(e);o.set(e,new _({code:t?.code||"",fromHtml:!0,initial:!0,prefetch:!1,preload:!1,url:e}))}}catch{console.error(`【bk-weweb】: ${e} is invalid URL`)}})),{collectScript:n,collectStyle:o}}const Ee=["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"];class _e{url;html=null;rawHtml;scripts;styles;constructor(e){this.url=e,this.scripts=new Map,this.styles=new Map}collectLink(e,t,n=!1){if(e.hasAttribute("exclude"))return{replace:document.createComment("【bk-weweb】style with exclude attribute is ignored")};if(e.hasAttribute("ignore"))return{replace:e};const o=e.getAttribute("rel");let r,i=e.getAttribute("href");if("stylesheet"===o&&i){i=l(i,this.url),r=document.createComment(`【bk-weweb】style with href=${i}`);let o=this.getStyle(i);return o||(o=new _({code:"",fromHtml:!n,prefetch:!!e.getAttribute("prefetch"),preload:!!e.getAttribute("preload"),url:i}),this.styles.set(i,o)),!n&&t.replaceChild(r,e),{replace:r,style:o}}return o&&["apple-touch-icon","icon","prefetch","preload","prerender"].includes(o)?(r=document.createComment(`【bk-weweb】style with rel=${o}${i?` & href=${i}`:""}`),!n&&t.removeChild(e),{replace:r}):(i&&e.setAttribute("href",l(i,this.url)),{replace:e})}collectScript(e,t,n=!1){if(e.hasAttribute("ignore")||"module"!==e.type&&p(e.getAttribute("src"))||e.hasAttribute("type")&&!Ee.includes(e.type))return;let o=null;if(e.hasAttribute("exclude"))return o=document.createComment("【bk-weweb】script element with exclude attribute is removed"),!n&&t.replaceChild(o,e),{replace:o};let r=e.getAttribute("src");if(r){r=l(r,this.url);let i=this.getScript(r);return i||(i=new v({async:e.hasAttribute("async"),code:"",defer:e.defer||"module"===e.type,fromHtml:!n,isModule:"module"===e.type,url:r}),this.scripts.set(r,i)),o=document.createComment(`【bk-weweb】script with src='${r}'`),!n&&t.replaceChild(o,e),{replace:o,script:i}}if(e.textContent){const r=d(),i=new v({async:!1,code:e.textContent,defer:"module"===e.type,fromHtml:!n,initial:!1,isModule:"module"===e.type,url:r});return this.scripts.set(r,i),o=document.createComment("【bk-weweb】script with texcontent"),!n&&t.replaceChild(o,e),{replace:o,script:i}}return{replace:e}}collectScriptAndStyle(e){const t=Array.from(e.querySelectorAll("link"));t?.forEach((e=>{this.collectLink(e,e.parentElement)}));const n=Array.from(e.querySelectorAll("style"));n?.forEach((e=>{e.hasAttribute("exclude")||e.hasAttribute("ignore")||(this.styles.set(d(),new _({code:e.textContent||"",fromHtml:!0,url:""})),e.remove())}));const o=Array.from(e.querySelectorAll("script"));o?.forEach((e=>{this.collectScript(e,e.parentElement)}));const r=Array.from(e.querySelectorAll("meta"));r?.forEach((e=>{e.parentElement.removeChild(e)}));const i=Array.from(e.querySelectorAll("img"));i?.forEach((e=>{e.hasAttribute("src")&&e.setAttribute("src",l(e.getAttribute("src"),this.url))}))}getScript(e){return this.scripts.get(e)}getStyle(e){return this.styles.get(e)||Array.from(this.styles.values()).find((t=>t.code===e))}async importEntery(e){if(e.initSource?.length){const{collectScript:t,collectStyle:n}=await we(e.initSource);t&&(this.scripts=t),n&&(this.styles=n)}e instanceof ye?await this.importHtmlEntry(e):e instanceof S&&await this.importInstanceEntry()}async importHtmlEntry(e){let t=Ae.getCacheHtml(this.url);if(!t&&(t=await E(a(this.url),{cache:"no-cache"}),!t))return console.error("load app entry error, pleace check"),Promise.reject();this.rawHtml=t;const n=document.createElement("div");n.__BK_WEWEB_APP_KEY__&&delete n.__BK_WEWEB_APP_KEY__,n.innerHTML=t.replace(/<\/?head>/gim,"").replace(/<\/?body>/i,""),this.collectScriptAndStyle(n),await A(e,n),this.html=n}async importInstanceEntry(){let e=Ae.getCacheScript(this.url)?.code;if(e||(e=await E(this.url,{cache:"no-cache"})),!e)return console.error("load app entry error, pleace check"),Promise.reject();this.scripts.set(this.url,new v({async:!1,code:e,defer:!1,fromHtml:!0,isModule:!!this.url.match(/\.ts$/),url:this.url}))}setScript(e,t){this.scripts.set(e,t instanceof v?t:new v(t))}setStyle(e,t){this.styles.set(e,t)}}const Ae=new class{baseSource;cache;constructor(){this.cache=new Map,this.baseSource=new _e(location.href)}deleteApp(e){this.cache.delete(e)}getApp(e){if(!e)return;const t=this.cache.get(e);return t||Array.from(this.cache.values()).find((t=>t.name===e))}getBaseAppStyle(e){return this.baseSource.getStyle(e)}getCacheHtml(e){const t=Array.from(this.cache.values()).find((t=>t.url===e));return t&&t.source?.rawHtml||""}getCacheScript(e){let t=this.baseSource.getScript(e);if(t)return;return Array.from(this.cache.values()).some((n=>(t=n.source?.getScript(e),!!t))),t}getCacheStyle(e){let t=this.baseSource.getStyle(e);if(t)return;return Array.from(this.cache.values()).some((n=>(t=n.source?.getStyle(e),!!t))),t}setApp(e){this.cache.set(e.appCacheKey,e)}setBaseAppScript(e,t){this.baseSource.setScript(e,t)}setBaseAppStyle(e,t){this.baseSource.setStyle(e,t)}get hasActiveApp(){return Array.from(this.cache.values()).some((t=>t.status!==e.UNMOUNT))}};function Se(e){if(e instanceof HTMLLinkElement){const t=e.getAttribute("rel");let n=e.getAttribute("href");if("stylesheet"===t&&n){n=l(n,location.origin);const t=document.createElement("style");return function(e,t,n){const o=document.createElement("style");W(o),E(e).then((r=>{t.code=r,Ae.setBaseAppStyle(e,t),o.textContent=r,y(n)})).catch((e=>{console.error(e),w(n)}))}(n,new _({code:"",fromHtml:!1,url:n}),e),t}}if(e instanceof HTMLScriptElement){let t=e.getAttribute("src");if(t&&"module"!==e.type){t=l(t,location.origin);const n=new v({async:e.hasAttribute("async"),code:"",defer:e.defer||"module"===e.type,fromHtml:!1,isModule:!1});Ae.setBaseAppScript(t,n);const o=function(e,t,n){const o=document.createElement("script");return W(o),E(e).then((r=>{t.setCode(r);try{o.textContent=r,e.startsWith("inline-")||n.setAttribute("origin-src",e)}catch(t){console.error(t,e)}y(n)})).catch((e=>{console.error(e),w(n)})),o}(t,n,e);return o||e}}return e}function ge(e){return e instanceof HTMLLinkElement||e instanceof HTMLScriptElement}function be(e,t,n){if(ge(t)){const o=Se(t);return n.call(e,o)}return n.call(e,t)}function Ce(){const e=HTMLBodyElement.prototype.appendChild,t=HTMLHeadElement.prototype.appendChild,n=HTMLHeadElement.prototype.appendChild;HTMLBodyElement.prototype.appendChild=function(t){return be(this,t,e)},HTMLHeadElement.prototype.appendChild=function(e){return be(this,e,t)},HTMLHeadElement.prototype.insertBefore=function(e,t){return function(e,t,n,o){if(ge(t)){const r=Se(t);return o.call(e,r,n)}return o.call(e,t,n)}(this,e,t,n)},window.addEventListener("load",(()=>{document.head.querySelectorAll("style").forEach((e=>{e.textContent&&Ae.setBaseAppStyle(d(),new _({code:e.textContent,fromHtml:!1,url:""}))}))}))}window.__getAppOrInstance__=function(e){return e?Ae.getApp(e):Ae};const ve="bk-weweb";class Le{fetchSource;webcomponentTag=ve;constructor(){window.customElements.get(ve)||window.customElements.define(ve,ee)}setWebComponentTag(){window.customElements.get(this.webcomponentTag)||window.customElements.define(this.webcomponentTag,ee)}start(e){e?.collectBaseSource&&Ce(),"function"==typeof e?.fetchSource&&(this.fetchSource=e.fetchSource),this.webcomponentTag=e?.webcomponentTag||ve,this.setWebComponentTag()}}const Pe=new Le;exports.WeWeb=Le,exports.activated=J,exports.deactivated=F,exports.default=Pe,exports.load=q,exports.loadApp=G,exports.loadInstance=z,exports.mount=function(e,t,n){const o=Ae.getApp(e);o&&c((()=>{Y(),o.mount(t,n)}))},exports.preLoadApp=function(e){u((()=>G({...e,isPreLoad:!0})))},exports.preLoadInstance=function(e){u((()=>z({...e,isPreLoad:!0})))},exports.preLoadSource=function(e){u((()=>{!async function(e){const{collectScript:t,collectStyle:n}=await we(e),o=[];t&&Array.from(t.entries()).forEach((e=>{o.push(e[1].getCode()),Ae.setBaseAppScript(...e)})),n&&Array.from(n.entries()).forEach((e=>{o.push(e[1].getCode()),Ae.setBaseAppStyle(...e)})),await Promise.all(o).catch((e=>{throw e}))}(e)}))},exports.unload=function(e){Ae.deleteApp(e)},exports.unmount=Z;
|
|
2
2
|
//# sourceMappingURL=index.min.js.map
|