@blueking/bk-weweb 0.0.2-5.beta.2 → 0.0.2-5.beta.3

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/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=document.createElement("style");r.setAttribute("id","SCOPED_CSS_STYLE_ID"),document.body.appendChild(r),r.sheet.disabled=!0;const i=r,s=new Map;Object.getOwnPropertyNames(window).forEach((e=>{!s.has(e)&&e.match(/^[A-Z]/)&&"function"==typeof window[e]&&window[e].toString().includes("[native code]")&&s.set(e,!0)}));const c="id";var a;!function(e){e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.STYLE_RULE=1]="STYLE_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(a||(a={}));const l=e=>Promise.resolve().then(e);function d(e){return e.startsWith("//")?`${location.protocol}${e}`:e.startsWith("http")?e:`${location.protocol}//${e}`}function u(e,t){if(!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e))return e;const{origin:n,pathname:o}=new URL(d(t));return new URL(e,`${n}${o}`.replace(/\.(\w+)$/,"/")).toString()}function h(){return`inline-${f(16)}`}const p=window.requestIdleCallback||function(e){const t=Date.now();return setTimeout((()=>{e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)},f=(e,t="abcdefghijklmnopqrstuvwxyz0123456789")=>{let n="";for(let o=0;o<e;o++)n+=t[parseInt((Math.random()*t.length).toString(),10)];return n},m=e=>{if(!e)return!1;if(e.match(/\.js$/))return!1;const{pathname:t}=new URL(d(e));return!t.match(/\.js$/)},y=["currentTarget","srcElement","target"];function w(e,t="custom"){return Object.defineProperties(new CustomEvent(t),y.reduce(((t,n)=>(t[n]={get:()=>e},t)),{}))}function E(e){const t=w(e,"load");"function"!=typeof e.onload?e.dispatchEvent(t):e.onload(t)}function A(e){const t=w(e,"error");"function"!=typeof e.onerror?e.dispatchEvent(t):e.onerror(t)}function _(e,t={}){return Pe.fetchSource?Pe.fetchSource(e,t):window.fetch(e,t).then((e=>e.text()))}class S{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,n){if(!n.scopeCss||n.container instanceof ShadowRoot){const o=this.resetUrlHost(t.textContent||e.textContent||"",n.url,this.url);if(o&&n.container instanceof ShadowRoot){let e="";o.match(/@font-face\s*\{[^}]+\}/g)?.forEach((t=>{e+=`${t}\n`}));const t=n.sandBox?.rawDocument;if(t&&e){const n=t.createElement("style");n.setAttribute("type","text/css"),n.setAttribute("powered-by","bk-weweb"),n.textContent=e,t?.head?.append(n)}}t.textContent=o}else{const o=Array.from(e.sheet?.cssRules??[]),r=`#${n.name}`,i=this.scopeRule(o,r),s=this.resetUrlHost(i,n.url,this.url);t.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&&be.getCacheStyle(this.url)){const e=be.getCacheStyle(this.url);t=e?.code||""}return t||(t=await _(this.url).catch((()=>""))),this.code=t,t}linkedBaseStyle(e,t){return!(t.container instanceof ShadowRoot||!e.textContent||!be.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=d(`${e.join("/")}/`)}return`url("${u(o,t)}")`}))}scopeRule(e,t){let n="";for(const o of e)switch(o.type){case a.STYLE_RULE:n+=this.scopeStyleRule(o,t);break;case a.MEDIA_RULE:n+=this.resetPackRule(o,t,"media");break;case a.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);H(n,e,o);const r=o?document.head:e.container;try{if(this.code)i.textContent=n.textContent||this.code,this.commonScoped(i,n,e),r?.prepend(n),t&&E(t),i.textContent="";else if(t.getAttribute("href"))this.url=u(t.getAttribute("href"),e.url),this.getCode(e).then((()=>{this.scopedStyleCSS(e,n),t.remove(),r?.prepend(n),t&&E(t),this.scoped=!0}));else{const o=new MutationObserver((()=>{t.href&&(o.disconnect(),this.url=u(t.getAttribute("href"),e.url),this.getCode(e).then((()=>{this.scopedStyleCSS(e,n),t.remove(),r?.prepend(n),t&&E(t),this.scoped=!0})))}));o.observe(t,{attributeFilter:["href"],childList:!1,subtree:!1})}}catch{t&&A(t)}return n}scopedStyleCSS(e,t){const n=!(!e.keepAlive||e.container instanceof ShadowRoot);if(H(t,e,n),this.code||t.textContent){if(t.textContent&&(t.textContent="",t.innerHTML=""),this.linkedBaseStyle(t,e))return t;i.textContent=this.code,this.commonScoped(i,t,e),i.textContent=""}else{const n=new MutationObserver((()=>{(t.textContent||t.sheet?.cssRules?.length)&&(n.disconnect(),this.linkedBaseStyle(t,e)||this.commonScoped(t,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 b(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 g{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:f(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 ye(this))}activated(t,n){if(this.isPreLoad=!1,this.state=e.ACTIVATED,this.container&&t){t instanceof Element&&t.setAttribute(c,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(c,this.name),this.container.innerHTML="";const o=document.createElement("div"),r=`${this.name}-wrapper`;o.setAttribute("id",r),this.source?.styles.size&&b(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 Se(this.url),await this.source.importEntery(this))}unmount(t){this.state=e.UNMOUNT,this.sandBox?.deactivated(),t&&be.deleteApp(this.url),this.container.innerHTML="",this.container=void 0}set status(e){this.state=e}get status(){return this.state}}let C,v,L;class T{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 g){!function(e){v=void 0,C=v;for(const t in e)x(e,t)||(C?v||(v=t):C=t,L=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;H(o,e,r),i.appendChild(o)}else if(this.executeMemoryScript(e,n),t)return document.createComment("【bk-weweb】dynamic script");if(e instanceof g){const t=e.scopeJs&&e.sandBox?.proxyWindow||window,n=function(e,t){let n,o,r=0;for(const i in e)if(!x(e,i)){if(0===r&&i!==C||1===r&&i!==v)return i;n?(L=i,o=t&&o||i):n=i===L,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 Ee&&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){if(this.isModule){if(this.url?.match(/\.ts$/))e.src=this.url;else{const n=new Blob([t],{type:"text/javascript"});e.src=URL.createObjectURL(n)}e.setAttribute("type","module")}else 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&&be.getCacheScript(this.url)&&(t=be.getCacheScript(this.url)?.code||""),t||(t=await _(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?e.showSourceCode||this.isModule?`;(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 x(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.initial));t.length&&await Promise.all(t.map((t=>t.excuteCode(e))));const n=Array.from(e.source.scripts.values()).filter((e=>e.fromHtml&&!e.initial)),o=n.filter((e=>!e.async&&!e.defer||e.isModule));let r=0;for(;r<o.length&&o[r];)await o[r].excuteCode(e),r++;const i=[],s=[];n.forEach((t=>{(t.defer||t.async)&&(!t.code&&t.defer?i.push(t.excuteCode(e)):s.push(t.excuteCode(e)))})),await Promise.all([...s,...i]).catch((e=>{console.error(e)}))}const{appendChild:B}=HTMLBodyElement.prototype;function M(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)&&be.getBaseAppStyle(t.textContent))return document.createComment("【bk-weweb】style is effective in base app");if(!t.hasAttribute("ignore")){const e=new S({code:t.textContent||"",fromHtml:!1,url:""});n.source?.setStyle(h(),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&&B.call(n.container,r.replace),m(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 T({async:!1,code:t.textContent,defer:"module"===t.type,fromHtml:!1,isModule:"module"===t.type});n.source.scripts.set(h(),e);try{e.excuteCode(n)}catch(e){console.error(e)}finally{!e.isModule&&E(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 R(e){return e instanceof HTMLScriptElement||e instanceof HTMLStyleElement||e instanceof HTMLLinkElement}function W(e,t,n){if(t.__BK_WEWEB_APP_KEY__){const o=be.getApp(t.__BK_WEWEB_APP_KEY__);if(o?.container){const r=M(e,t,o),i=R(t)&&!!o.keepAlive&&!(o.container instanceof ShadowRoot),s=i?document.head:o?.container;return H(r,o,i),n.call(s,r)}}return n.call(e,t)}function O(e,t,n,o){if(t.__BK_WEWEB_APP_KEY__){const r=be.getApp(t.__BK_WEWEB_APP_KEY__);if(r?.container){const i=R(t)&&r.keepAlive&&!(r.container instanceof ShadowRoot),s=i?document.head:r?.container,c=M(e,t,r);return i&&H(c,r,i),n&&!s.contains(n)?B.call(s,c):o.call(s,c,n)}}return o.call(e,t,n)}function H(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:k}=Element.prototype,{append:D,appendChild:K,insertBefore:N,removeChild:U}=HTMLBodyElement.prototype,{appendChild:I,insertBefore:$,removeChild:j}=HTMLHeadElement.prototype,V=document.head;let Y=!1;function J(){o(null),Element.prototype.setAttribute=k,HTMLBodyElement.prototype.appendChild=K,HTMLBodyElement.prototype.append=D,HTMLBodyElement.prototype.removeChild=U,HTMLBodyElement.prototype.insertBefore=N,HTMLHeadElement.prototype.appendChild=I,HTMLHeadElement.prototype.insertBefore=$,HTMLHeadElement.prototype.removeChild=j,Y=!1}function F(){Y||(Y=!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__&&be.getApp(this.__BK_WEWEB_APP_KEY__||"")?k.call(this,e,u(t,be.getApp(this.__BK_WEWEB_APP_KEY__).url)):k.call(this,e,t)},HTMLBodyElement.prototype.appendChild=function(e){return e.__KEEP_ALIVE__&&R(e)?I.call(V,e):W(this,e,K)},HTMLBodyElement.prototype.append=function(...e){e.forEach((e=>{if(e.__KEEP_ALIVE__&&R(e))return I.call(V,e);W(this,e,K)}))},HTMLHeadElement.prototype.appendChild=HTMLBodyElement.prototype.appendChild,HTMLHeadElement.prototype.insertBefore=function(e,t){return O(this,e,t,$)},HTMLBodyElement.prototype.insertBefore=function(e,t){return O(this,e,t,$)},HTMLBodyElement.prototype.removeChild=function(e){const t=be.getApp(e.__BK_WEWEB_APP_KEY__);return t?.container?.contains(e)?U.call(t.container,e):this.contains(e)?U.call(this,e):e},HTMLHeadElement.prototype.removeChild=HTMLBodyElement.prototype.removeChild)}function G(t,n,o){const r=be.getApp(t);r?.status===e.DEACTIVATED&&r.keepAlive?l((()=>{F(),r.activated(n,o)})):r&&l((()=>{F(),r.mount(n,o)}))}function q(t){const n=be.getApp(t);n&&[e.ACTIVATED,e.MOUNTED].includes(n.status)&&(n.keepAlive?n.deactivated():n.unmount()),be.hasActiveApp||J()}async function z(e){return F(),e.mode===exports.WewebMode.INSTANCE?await Q(e):await Z(e)}async function Z(e){F();let t=be.getApp(e.id);return t||(t=new Ee(e),be.setApp(t)),await t.start(),t}function Q(t){return F(),new Promise((n=>{let o=be.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 g(t),be.setApp(o),o.start().then((()=>n(o)))}))}function X(t){const n=be.getApp(t);n&&n.status!==e.UNMOUNT&&n.unmount(),be.hasActiveApp||J()}var ee,te;!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"}(ee||(ee={}));class ne extends HTMLElement{appUrl="";connected=!1;static get observedAttributes(){return[ee.url]}getBooleanAttr(e){return this.hasAttribute(e)?"false"!==this.getAttribute(e):void 0}async handleAttributeChanged(){if(!this.appKey)return;this.getBooleanAttr(ee.setShodowDom)&&this.attachShadow({mode:"open"});const t=be.getApp(this.appKey);!t||t.url!==this.appUrl||!t.isPreLoad&&t.status!==e.UNMOUNT?await z(this.appProps):G(this.appKey,this.shadowRoot??this)}attributeChangedCallback(e,t,n){if(e!==ee.url||this[e]===n||!this.connected)return;this.appUrl=n;const o=be.getApp(this.appKey);(this.connected||o)&&this.handleAttributeChanged()}async connectedCallback(){this.getBooleanAttr(ee.setShodowDom)&&!this.shadowRoot&&this.attachShadow({delegatesFocus:!1,mode:"open"}),await z(this.appProps),G(this.appKey,this.shadowRoot??this),this.connected=!0}disconnectedCallback(){this.connected=!1,this.appProps.keepAlive?q(this.appKey):X(this.appKey)}get appData(){if(this.hasAttribute(ee.data))try{return JSON.parse(this.getAttribute(ee.data))}catch{}return{}}get appKey(){return this.getAttribute(ee.id)||this.getAttribute(ee.url)}get appProps(){return this.getAttribute("mode")===exports.WewebMode.INSTANCE?{container:this.shadowRoot??this,data:this.appData,id:this.appKey,keepAlive:this.getBooleanAttr(ee.keepAlive),mode:exports.WewebMode.INSTANCE,scopeCss:this.getBooleanAttr(ee.scopeCss)&&!this.getBooleanAttr(ee.setShodowDom),scopeJs:this.getBooleanAttr(ee.scopeJs),showSourceCode:this.getBooleanAttr(ee.showSourceCode),url:this.getAttribute(ee.url)}:{container:this.shadowRoot??this,data:this.appData,id:this.appKey,keepAlive:this.getBooleanAttr(ee.keepAlive),mode:exports.WewebMode.APP,scopeCss:!this.getBooleanAttr(ee.setShodowDom),scopeJs:!this.getBooleanAttr(ee.scopeJs),scopeLocation:this.getBooleanAttr(ee.scopeLocation),showSourceCode:this.getBooleanAttr(ee.showSourceCode),url:this.getAttribute(ee.url)}}}exports.WewebMode=void 0,(te=exports.WewebMode||(exports.WewebMode={})).APP="app",te.CONFIG="config",te.INSTANCE="js";const oe=["System","__cjsWrapper","production"!==process.env.NODE_ENV?"__REACT_DEVTOOLS_GLOBAL_HOOK__":""],re=["__POWERED_BY_BK_WEWEB__","__BK_WEWEB_APP_KEY__","__BK_WEWEB_DATA__"],ie=["window","self","globalThis"],se=["location","history"],ce={__bk_pop_manager:!0,__bk_zIndex_manager:!0,i18n:!0},ae="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,...ce}:ce,le=["body","html","head"],de=(e,t)=>{const n=new Proxy({},{get(n,o){if("querySelector"===o)return t.container instanceof ShadowRoot?t.container.querySelector.bind(t.container):r.bind(e.body);if("querySelectorAll"===o)return t.container instanceof ShadowRoot?t.container.querySelectorAll.bind(t.container):i.bind(e.body);if("insertAdjacentElement"===o)return e.body.insertAdjacentElement.bind(e.body);const s=Reflect.get(e.body,o);return"function"==typeof s?s.bind(e.body):s}});function o(n,o){const r=e.createElement(n,o);return r.__BK_WEWEB_APP_KEY__=t.appCacheKey,r}function r(o){return o===n?t.container instanceof ShadowRoot?t.container:e.body:le.includes(o)?t?.container instanceof ShadowRoot?t?.container:e.querySelector.call(this,o):t?.container?.querySelector(o)??null}function i(n){return le.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 le.includes(n)||!t?.showSourceCode&&"script"===n.toLocaleLowerCase()?e.getElementsByName(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 ue=/^class\b/,he=/^function\b\s[A-Z].*/,pe=new WeakMap;const fe=new WeakMap;function me(e,t){if(fe.has(t))return fe.get(t);if("function"==typeof t&&!function(e){if(e.prototype?.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1)return!0;if(pe.has(e))return pe.get(e);const t=he.test(e.toString())||ue.test(e.toString());return pe.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 fe.set(t,n),n}return t}class ye{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.fakeWindow.__POWERED_BY_BK_WEWEB__=!0,this.fakeWindow.__BK_WEWEB_APP_KEY__=e.appCacheKey,this.rawWindow=n,this.rawDocument=de(document,e),this.fakeWindow.rawWindow=n,this.fakeWindow.rawDocument=document;const{resetWindowFunction:o}=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=o,this.windowSymbolKey=`__${(e.name||e.appCacheKey).replace(/(-|,|:|~|'|")/gim,"_")}_${f(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(s.has(o)||o===Symbol.unscopables)return n[o];if(ae[o])return this.fakeWindow[o];if(ie.includes(o))return this.proxyWindow;if("document"===o)return e.registerRunningApp(),this.rawDocument;if("eval"===o)return e.registerRunningApp(),eval;if(se.includes(o)&&this.app instanceof Ee&&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)||re.includes(o))return Reflect.get(t,o);const r=Reflect.get(n,o);return me(n,r)},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)=>s.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(se.includes(t)&&this.app instanceof Ee&&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)||re.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))}!oe.includes(t)||Reflect.has(n,t)||re.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=de(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 we="about:blank";class Ee{state=e.UNSET;container;data;iframe=null;initSource;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:f(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 ye(this)),this.container instanceof HTMLElement&&this.container.setAttribute(c,this.name)}activated(t,n){if(this.isPreLoad=!1,this.state=e.ACTIVATED,t&&this.container){t instanceof Element&&t.setAttribute(c,this.name);const e=document.createDocumentFragment();Array.from(this.container.childNodes).forEach((t=>{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(d(this.url)),o=navigator.userAgent.indexOf("Chrome")>-1;if(t.setAttribute("src",`${o?we: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!==we&&(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){if(this.isPreLoad=!1,this.container=t??this.container,this.state=e.MOUNTING,this.container){this.container instanceof Element&&this.container.setAttribute(c,this.name);const t=this.source.html.cloneNode(!0),o=document.createDocumentFragment();Array.from(t.childNodes).forEach((e=>{o.appendChild(e)})),this.container.innerHTML="",this.container.appendChild(o),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){const e=await this.createIframe();this.iframe=e}this.source=new Se(this.url),await this.source.importEntery(this)}}unmount(t=!1){this.state=e.UNMOUNT,this.sandBox?.deactivated(),t&&be.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 Ae(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=be.getCacheScript(e);n.set(e,new T({async:!1,code:t?.code||"",defer:!1,fromHtml:!1,initial:!0,isModule:!1,url:e}))}else if(t.pathname.match(/\.css$/)){const t=be.getCacheStyle(e);o.set(e,new S({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 _e=["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"];class Se{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=u(i,this.url),r=document.createComment(`【bk-weweb】style with href=${i}`);let o=this.getStyle(i);return o||(o=new S({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",u(i,this.url)),{replace:e})}collectScript(e,t,n=!1){if(e.hasAttribute("ignore")||m(e.getAttribute("src"))||e.hasAttribute("type")&&!_e.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=u(r,this.url);let i=this.getScript(r);return i||(i=new T({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=h(),i=new T({async:!1,code:e.textContent,defer:"module"===e.type,fromHtml:!n,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,t){const n=Array.from(e.children);n.length&&n.forEach((e=>{this.collectScriptAndStyle(e,t)})),n?.forEach((t=>{t instanceof HTMLLinkElement?this.collectLink(t,e):t instanceof HTMLStyleElement?t.hasAttribute("exclude")||t.hasAttribute("ignore")||(this.styles.set(h(),new S({code:t.textContent||"",fromHtml:!0,url:""})),t.remove()):t instanceof HTMLScriptElement?this.collectScript(t,e):t instanceof HTMLMetaElement||t instanceof HTMLTitleElement?e.removeChild(t):t instanceof HTMLImageElement&&t.hasAttribute("src")&&t.setAttribute("src",u(t.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 Ae(e.initSource);t&&(this.scripts=t),n&&(this.styles=n)}e instanceof Ee?await this.importHtmlEntry(e):e instanceof g&&await this.importInstanceEntry()}async importHtmlEntry(e){let t=be.getCacheHtml(this.url);if(!t&&(t=await _(d(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,e),await b(e,n),this.html=n}async importInstanceEntry(){let e=be.getCacheScript(this.url)?.code;if(e||(e=await _(this.url,{cache:"no-cache"})),!e)return console.error("load app entry error, pleace check"),Promise.reject();this.scripts.set(this.url,new T({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 T?t:new T(t))}setStyle(e,t){this.styles.set(e,t)}}const be=new class{baseSource;cache;constructor(){this.cache=new Map,this.baseSource=new Se(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 ge(e){if(e instanceof HTMLLinkElement){const t=e.getAttribute("rel");let n=e.getAttribute("href");if("stylesheet"===t&&n){n=u(n,location.origin);const t=document.createElement("style");return function(e,t,n){const o=document.createElement("style");H(o),_(e).then((r=>{t.code=r,be.setBaseAppStyle(e,t),o.textContent=r,E(n)})).catch((e=>{console.error(e),A(n)}))}(n,new S({code:"",fromHtml:!1,url:n}),e),t}}if(e instanceof HTMLScriptElement){let t=e.getAttribute("src");if(t&&"module"!==e.type){t=u(t,location.origin);const n=new T({async:e.hasAttribute("async"),code:"",defer:e.defer||"module"===e.type,fromHtml:!1,isModule:!1});be.setBaseAppScript(t,n);const o=function(e,t,n){const o=document.createElement("script");return H(o),_(e).then((r=>{t.setCode(r);try{o.textContent=r,e.startsWith("inline-")||n.setAttribute("origin-src",e)}catch(t){console.error(t,e)}E(n)})).catch((e=>{console.error(e),A(n)})),o}(t,n,e);return o||e}}return e}function Ce(e){return e instanceof HTMLLinkElement||e instanceof HTMLScriptElement}function ve(e,t,n){if(Ce(t)){const o=ge(t);return n.call(e,o)}return n.call(e,t)}function Le(){const e=HTMLBodyElement.prototype.appendChild,t=HTMLHeadElement.prototype.appendChild,n=HTMLHeadElement.prototype.appendChild;HTMLBodyElement.prototype.appendChild=function(t){return ve(this,t,e)},HTMLHeadElement.prototype.appendChild=function(e){return ve(this,e,t)},HTMLHeadElement.prototype.insertBefore=function(e,t){return function(e,t,n,o){if(Ce(t)){const r=ge(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&&be.setBaseAppStyle(h(),new S({code:e.textContent,fromHtml:!1,url:""}))}))}))}window.__getAppOrInstance__=function(e){return e?be.getApp(e):be};const Te="bk-weweb";class xe{fetchSource;webcomponentTag=Te;constructor(){window.customElements.get(Te)||window.customElements.define(Te,ne)}setWebComponentTag(){window.customElements.get(this.webcomponentTag)||window.customElements.define(this.webcomponentTag,ne)}start(e){e?.collectBaseSource&&Le(),"function"==typeof e?.fetchSource&&(this.fetchSource=e.fetchSource),this.webcomponentTag=e?.webcomponentTag||Te,this.setWebComponentTag()}}const Pe=new xe;exports.WeWeb=xe,exports.activated=G,exports.deactivated=q,exports.default=Pe,exports.load=z,exports.loadApp=Z,exports.loadInstance=Q,exports.mount=function(e,t,n){const o=be.getApp(e);o&&l((()=>{F(),o.mount(t,n)}))},exports.preLoadApp=function(e){p((()=>Z({...e,isPreLoad:!0})))},exports.preLoadInstance=function(e){p((()=>Q({...e,isPreLoad:!0})))},exports.preLoadSource=function(e){p((()=>{!async function(e){const{collectScript:t,collectStyle:n}=await Ae(e),o=[];t&&Array.from(t.entries()).forEach((e=>{o.push(e[1].getCode()),be.setBaseAppScript(...e)})),n&&Array.from(n.entries()).forEach((e=>{o.push(e[1].getCode()),be.setBaseAppStyle(...e)})),await Promise.all(o).catch((e=>{throw e}))}(e)}))},exports.unload=function(e){be.deleteApp(e)},exports.unmount=X;
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=document.createElement("style");r.setAttribute("id","SCOPED_CSS_STYLE_ID"),document.body.appendChild(r),r.sheet.disabled=!0;const i=r,s=new Map;Object.getOwnPropertyNames(window).forEach((e=>{!s.has(e)&&e.match(/^[A-Z]/)&&"function"==typeof window[e]&&window[e].toString().includes("[native code]")&&s.set(e,!0)}));const c="id";var a;!function(e){e[e.MEDIA_RULE=4]="MEDIA_RULE",e[e.STYLE_RULE=1]="STYLE_RULE",e[e.SUPPORTS_RULE=12]="SUPPORTS_RULE"}(a||(a={}));const l=e=>Promise.resolve().then(e);function d(e){return e.startsWith("//")?`${location.protocol}${e}`:e.startsWith("http")?e:`${location.protocol}//${e}`}function u(e,t){if(!e||/^((((ht|f)tps?)|file):)?\/\//.test(e)||/^(data|blob):/.test(e))return e;const{origin:n,pathname:o}=new URL(d(t));return new URL(e,`${n}${o}`.replace(/\.(\w+)$/,"/")).toString()}function h(){return`inline-${f(16)}`}const p=window.requestIdleCallback||function(e){const t=Date.now();return setTimeout((()=>{e({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-t))})}),1)},f=(e,t="abcdefghijklmnopqrstuvwxyz0123456789")=>{let n="";for(let o=0;o<e;o++)n+=t[parseInt((Math.random()*t.length).toString(),10)];return n},m=e=>{if(!e)return!1;if(e.match(/\.js$/))return!1;const{pathname:t}=new URL(d(e));return!t.match(/\.js$/)},y=["currentTarget","srcElement","target"];function w(e,t="custom"){return Object.defineProperties(new CustomEvent(t),y.reduce(((t,n)=>(t[n]={get:()=>e},t)),{}))}function E(e){const t=w(e,"load");"function"!=typeof e.onload?e.dispatchEvent(t):e.onload(t)}function A(e){const t=w(e,"error");"function"!=typeof e.onerror?e.dispatchEvent(t):e.onerror(t)}function _(e,t={}){return Pe.fetchSource?Pe.fetchSource(e,t):window.fetch(e,t).then((e=>e.text()))}class S{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,n){if(!n.scopeCss||n.container instanceof ShadowRoot){const o=this.resetUrlHost(t.textContent||e.textContent||"",n.url,this.url);if(o&&n.container instanceof ShadowRoot){let e="";o.match(/@font-face\s*\{[^}]+\}/g)?.forEach((t=>{e+=`${t}\n`}));const t=n.sandBox?.rawDocument;if(t&&e){const n=t.createElement("style");n.setAttribute("type","text/css"),n.setAttribute("powered-by","bk-weweb"),n.textContent=e,t?.head?.append(n)}}t.textContent=o}else{const o=Array.from(e.sheet?.cssRules??[]),r=`#${n.name}`,i=this.scopeRule(o,r),s=this.resetUrlHost(i,n.url,this.url);t.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&&be.getCacheStyle(this.url)){const e=be.getCacheStyle(this.url);t=e?.code||""}return t||(t=await _(this.url).catch((()=>""))),this.code=t,t}linkedBaseStyle(e,t){return!(t.container instanceof ShadowRoot||!e.textContent||!be.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=d(`${e.join("/")}/`)}return`url("${u(o,t)}")`}))}scopeRule(e,t){let n="";for(const o of e)switch(o.type){case a.STYLE_RULE:n+=this.scopeStyleRule(o,t);break;case a.MEDIA_RULE:n+=this.resetPackRule(o,t,"media");break;case a.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);H(n,e,o);const r=o?document.head:e.container;try{if(this.code)i.textContent=n.textContent||this.code,this.commonScoped(i,n,e),r?.prepend(n),t&&E(t),i.textContent="";else if(t.getAttribute("href"))this.url=u(t.getAttribute("href"),e.url),this.getCode(e).then((()=>{this.scopedStyleCSS(e,n),t.remove(),r?.prepend(n),t&&E(t),this.scoped=!0}));else{const o=new MutationObserver((()=>{t.href&&(o.disconnect(),this.url=u(t.getAttribute("href"),e.url),this.getCode(e).then((()=>{this.scopedStyleCSS(e,n),t.remove(),r?.prepend(n),t&&E(t),this.scoped=!0})))}));o.observe(t,{attributeFilter:["href"],childList:!1,subtree:!1})}}catch{t&&A(t)}return n}scopedStyleCSS(e,t){const n=!(!e.keepAlive||e.container instanceof ShadowRoot);if(H(t,e,n),this.code||t.textContent){if(t.textContent&&(t.textContent="",t.innerHTML=""),this.linkedBaseStyle(t,e))return t;i.textContent=this.code,this.commonScoped(i,t,e),i.textContent=""}else{const n=new MutationObserver((()=>{(t.textContent||t.sheet?.cssRules?.length)&&(n.disconnect(),this.linkedBaseStyle(t,e)||this.commonScoped(t,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 b(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 g{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:f(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 ye(this))}activated(t,n){if(this.isPreLoad=!1,this.state=e.ACTIVATED,this.container&&t){t instanceof Element&&t.setAttribute(c,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(c,this.name),this.container.innerHTML="";const o=document.createElement("div"),r=`${this.name}-wrapper`;o.setAttribute("id",r),this.source?.styles.size&&b(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 Se(this.url),await this.source.importEntery(this))}unmount(t){this.state=e.UNMOUNT,this.sandBox?.deactivated(),t&&be.deleteApp(this.url),this.container.innerHTML="",this.container=void 0}set status(e){this.state=e}get status(){return this.state}}let C,v,L;class T{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 g){!function(e){v=void 0,C=v;for(const t in e)x(e,t)||(C?v||(v=t):C=t,L=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;H(o,e,r),i.appendChild(o)}else if(this.executeMemoryScript(e,n),t)return document.createComment("【bk-weweb】dynamic script");if(e instanceof g){const t=e.scopeJs&&e.sandBox?.proxyWindow||window,n=function(e,t){let n,o,r=0;for(const i in e)if(!x(e,i)){if(0===r&&i!==C||1===r&&i!==v)return i;n?(L=i,o=t&&o||i):n=i===L,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 Ee&&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){if(this.isModule){if(this.url?.match(/\.ts$/))e.src=this.url;else{const n=new Blob([t],{type:"text/javascript"});e.src=URL.createObjectURL(n)}e.setAttribute("type","module")}else 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&&be.getCacheScript(this.url)&&(t=be.getCacheScript(this.url)?.code||""),t||(t=await _(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?e.showSourceCode||this.isModule?`;(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 x(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.initial));t.length&&await Promise.all(t.map((t=>t.excuteCode(e))));const n=Array.from(e.source.scripts.values()).filter((e=>e.fromHtml&&!e.initial)),o=n.filter((e=>!e.async&&!e.defer||e.isModule));await Promise.all(o.map((t=>t.getCode(e)))),await Promise.all(o.map((t=>t.excuteCode(e))));const r=[],i=[];n.forEach((t=>{(t.defer||t.async)&&(!t.code&&t.defer?r.push(t.excuteCode(e)):i.push(t.excuteCode(e)))})),await Promise.all([...i,...r]).catch((e=>{console.error(e)}))}const{appendChild:B}=HTMLBodyElement.prototype;function M(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)&&be.getBaseAppStyle(t.textContent))return document.createComment("【bk-weweb】style is effective in base app");if(!t.hasAttribute("ignore")){const e=new S({code:t.textContent||"",fromHtml:!1,url:""});n.source?.setStyle(h(),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&&B.call(n.container,r.replace),m(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 T({async:!1,code:t.textContent,defer:"module"===t.type,fromHtml:!1,isModule:"module"===t.type});n.source.scripts.set(h(),e);try{e.excuteCode(n)}catch(e){console.error(e)}finally{!e.isModule&&E(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 R(e){return e instanceof HTMLScriptElement||e instanceof HTMLStyleElement||e instanceof HTMLLinkElement}function W(e,t,n){if(t.__BK_WEWEB_APP_KEY__){const o=be.getApp(t.__BK_WEWEB_APP_KEY__);if(o?.container){const r=M(e,t,o),i=R(t)&&!!o.keepAlive&&!(o.container instanceof ShadowRoot),s=i?document.head:o?.container;return H(r,o,i),n.call(s,r)}}return n.call(e,t)}function O(e,t,n,o){if(t.__BK_WEWEB_APP_KEY__){const r=be.getApp(t.__BK_WEWEB_APP_KEY__);if(r?.container){const i=R(t)&&r.keepAlive&&!(r.container instanceof ShadowRoot),s=i?document.head:r?.container,c=M(e,t,r);return i&&H(c,r,i),n&&!s.contains(n)?B.call(s,c):o.call(s,c,n)}}return o.call(e,t,n)}function H(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:k}=Element.prototype,{append:D,appendChild:K,insertBefore:N,removeChild:U}=HTMLBodyElement.prototype,{appendChild:I,insertBefore:$,removeChild:j}=HTMLHeadElement.prototype,V=document.head;let Y=!1;function J(){o(null),Element.prototype.setAttribute=k,HTMLBodyElement.prototype.appendChild=K,HTMLBodyElement.prototype.append=D,HTMLBodyElement.prototype.removeChild=U,HTMLBodyElement.prototype.insertBefore=N,HTMLHeadElement.prototype.appendChild=I,HTMLHeadElement.prototype.insertBefore=$,HTMLHeadElement.prototype.removeChild=j,Y=!1}function F(){Y||(Y=!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__&&be.getApp(this.__BK_WEWEB_APP_KEY__||"")?k.call(this,e,u(t,be.getApp(this.__BK_WEWEB_APP_KEY__).url)):k.call(this,e,t)},HTMLBodyElement.prototype.appendChild=function(e){return e.__KEEP_ALIVE__&&R(e)?I.call(V,e):W(this,e,K)},HTMLBodyElement.prototype.append=function(...e){e.forEach((e=>{if(e.__KEEP_ALIVE__&&R(e))return I.call(V,e);W(this,e,K)}))},HTMLHeadElement.prototype.appendChild=HTMLBodyElement.prototype.appendChild,HTMLHeadElement.prototype.insertBefore=function(e,t){return O(this,e,t,$)},HTMLBodyElement.prototype.insertBefore=function(e,t){return O(this,e,t,$)},HTMLBodyElement.prototype.removeChild=function(e){const t=be.getApp(e.__BK_WEWEB_APP_KEY__);return t?.container?.contains(e)?U.call(t.container,e):this.contains(e)?U.call(this,e):e},HTMLHeadElement.prototype.removeChild=HTMLBodyElement.prototype.removeChild)}function G(t,n,o){const r=be.getApp(t);r?.status===e.DEACTIVATED&&r.keepAlive?l((()=>{F(),r.activated(n,o)})):r&&l((()=>{F(),r.mount(n,o)}))}function q(t){const n=be.getApp(t);n&&[e.ACTIVATED,e.MOUNTED].includes(n.status)&&(n.keepAlive?n.deactivated():n.unmount()),be.hasActiveApp||J()}async function z(e){return F(),e.mode===exports.WewebMode.INSTANCE?await Q(e):await Z(e)}async function Z(e){F();let t=be.getApp(e.id);return t||(t=new Ee(e),be.setApp(t)),await t.start(),t}function Q(t){return F(),new Promise((n=>{let o=be.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 g(t),be.setApp(o),o.start().then((()=>n(o)))}))}function X(t){const n=be.getApp(t);n&&n.status!==e.UNMOUNT&&n.unmount(),be.hasActiveApp||J()}var ee,te;!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"}(ee||(ee={}));class ne extends HTMLElement{appUrl="";connected=!1;static get observedAttributes(){return[ee.url]}getBooleanAttr(e){return this.hasAttribute(e)?"false"!==this.getAttribute(e):void 0}async handleAttributeChanged(){if(!this.appKey)return;this.getBooleanAttr(ee.setShodowDom)&&this.attachShadow({mode:"open"});const t=be.getApp(this.appKey);!t||t.url!==this.appUrl||!t.isPreLoad&&t.status!==e.UNMOUNT?await z(this.appProps):G(this.appKey,this.shadowRoot??this)}attributeChangedCallback(e,t,n){if(e!==ee.url||this[e]===n||!this.connected)return;this.appUrl=n;const o=be.getApp(this.appKey);(this.connected||o)&&this.handleAttributeChanged()}async connectedCallback(){this.getBooleanAttr(ee.setShodowDom)&&!this.shadowRoot&&this.attachShadow({delegatesFocus:!1,mode:"open"}),await z(this.appProps),G(this.appKey,this.shadowRoot??this),this.connected=!0}disconnectedCallback(){this.connected=!1,this.appProps.keepAlive?q(this.appKey):X(this.appKey)}get appData(){if(this.hasAttribute(ee.data))try{return JSON.parse(this.getAttribute(ee.data))}catch{}return{}}get appKey(){return this.getAttribute(ee.id)||this.getAttribute(ee.url)}get appProps(){return this.getAttribute("mode")===exports.WewebMode.INSTANCE?{container:this.shadowRoot??this,data:this.appData,id:this.appKey,keepAlive:this.getBooleanAttr(ee.keepAlive),mode:exports.WewebMode.INSTANCE,scopeCss:this.getBooleanAttr(ee.scopeCss)&&!this.getBooleanAttr(ee.setShodowDom),scopeJs:this.getBooleanAttr(ee.scopeJs),showSourceCode:this.getBooleanAttr(ee.showSourceCode),url:this.getAttribute(ee.url)}:{container:this.shadowRoot??this,data:this.appData,id:this.appKey,keepAlive:this.getBooleanAttr(ee.keepAlive),mode:exports.WewebMode.APP,scopeCss:!this.getBooleanAttr(ee.setShodowDom),scopeJs:!this.getBooleanAttr(ee.scopeJs),scopeLocation:this.getBooleanAttr(ee.scopeLocation),showSourceCode:this.getBooleanAttr(ee.showSourceCode),url:this.getAttribute(ee.url)}}}exports.WewebMode=void 0,(te=exports.WewebMode||(exports.WewebMode={})).APP="app",te.CONFIG="config",te.INSTANCE="js";const oe=["System","__cjsWrapper","production"!==process.env.NODE_ENV?"__REACT_DEVTOOLS_GLOBAL_HOOK__":""],re=["__POWERED_BY_BK_WEWEB__","__BK_WEWEB_APP_KEY__","__BK_WEWEB_DATA__"],ie=["window","self","globalThis"],se=["location","history"],ce={__bk_pop_manager:!0,__bk_zIndex_manager:!0,i18n:!0},ae="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,...ce}:ce,le=["body","html","head"],de=(e,t)=>{const n=new Proxy({},{get(n,o){if("querySelector"===o)return t.container instanceof ShadowRoot?t.container.querySelector.bind(t.container):r.bind(e.body);if("querySelectorAll"===o)return t.container instanceof ShadowRoot?t.container.querySelectorAll.bind(t.container):i.bind(e.body);if("insertAdjacentElement"===o)return e.body.insertAdjacentElement.bind(e.body);const s=Reflect.get(e.body,o);return"function"==typeof s?s.bind(e.body):s}});function o(n,o){const r=e.createElement(n,o);return r.__BK_WEWEB_APP_KEY__=t.appCacheKey,r}function r(o){return o===n?t.container instanceof ShadowRoot?t.container:e.body:le.includes(o)?t?.container instanceof ShadowRoot?t?.container:e.querySelector.call(this,o):t?.container?.querySelector(o)??null}function i(n){return le.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 le.includes(n)||!t?.showSourceCode&&"script"===n.toLocaleLowerCase()?e.getElementsByName(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 ue=/^class\b/,he=/^function\b\s[A-Z].*/,pe=new WeakMap;const fe=new WeakMap;function me(e,t){if(fe.has(t))return fe.get(t);if("function"==typeof t&&!function(e){if(e.prototype?.constructor===e&&Object.getOwnPropertyNames(e.prototype).length>1)return!0;if(pe.has(e))return pe.get(e);const t=he.test(e.toString())||ue.test(e.toString());return pe.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 fe.set(t,n),n}return t}class ye{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.fakeWindow.__POWERED_BY_BK_WEWEB__=!0,this.fakeWindow.__BK_WEWEB_APP_KEY__=e.appCacheKey,this.rawWindow=n,this.rawDocument=de(document,e),this.fakeWindow.rawWindow=n,this.fakeWindow.rawDocument=document;const{resetWindowFunction:o}=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=o,this.windowSymbolKey=`__${(e.name||e.appCacheKey).replace(/(-|,|:|~|'|")/gim,"_")}_${f(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(s.has(o)||o===Symbol.unscopables)return n[o];if(ae[o])return this.fakeWindow[o];if(ie.includes(o))return this.proxyWindow;if("document"===o)return e.registerRunningApp(),this.rawDocument;if("eval"===o)return e.registerRunningApp(),eval;if(se.includes(o)&&this.app instanceof Ee&&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)||re.includes(o))return Reflect.get(t,o);const r=Reflect.get(n,o);return me(n,r)},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)=>s.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(se.includes(t)&&this.app instanceof Ee&&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)||re.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))}!oe.includes(t)||Reflect.has(n,t)||re.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=de(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 we="about:blank";class Ee{state=e.UNSET;container;data;iframe=null;initSource;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:f(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 ye(this)),this.container instanceof HTMLElement&&this.container.setAttribute(c,this.name)}activated(t,n){if(this.isPreLoad=!1,this.state=e.ACTIVATED,t&&this.container){t instanceof Element&&t.setAttribute(c,this.name);const e=document.createDocumentFragment();Array.from(this.container.childNodes).forEach((t=>{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(d(this.url)),o=navigator.userAgent.indexOf("Chrome")>-1;if(t.setAttribute("src",`${o?we: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!==we&&(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){if(this.isPreLoad=!1,this.container=t??this.container,this.state=e.MOUNTING,this.container){this.container instanceof Element&&this.container.setAttribute(c,this.name);const t=this.source.html.cloneNode(!0),o=document.createDocumentFragment();Array.from(t.childNodes).forEach((e=>{o.appendChild(e)})),this.container.innerHTML="",this.container.appendChild(o),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){const e=await this.createIframe();this.iframe=e}this.source=new Se(this.url),await this.source.importEntery(this)}}unmount(t=!1){this.state=e.UNMOUNT,this.sandBox?.deactivated(),t&&be.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 Ae(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=be.getCacheScript(e);n.set(e,new T({async:!1,code:t?.code||"",defer:!1,fromHtml:!1,initial:!0,isModule:!1,url:e}))}else if(t.pathname.match(/\.css$/)){const t=be.getCacheStyle(e);o.set(e,new S({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 _e=["text/javascript","text/ecmascript","application/javascript","application/ecmascript","module"];class Se{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=u(i,this.url),r=document.createComment(`【bk-weweb】style with href=${i}`);let o=this.getStyle(i);return o||(o=new S({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",u(i,this.url)),{replace:e})}collectScript(e,t,n=!1){if(e.hasAttribute("ignore")||m(e.getAttribute("src"))||e.hasAttribute("type")&&!_e.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=u(r,this.url);let i=this.getScript(r);return i||(i=new T({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=h(),i=new T({async:!1,code:e.textContent,defer:"module"===e.type,fromHtml:!n,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,t){const n=Array.from(e.children);n.length&&n.forEach((e=>{this.collectScriptAndStyle(e,t)})),n?.forEach((t=>{t instanceof HTMLLinkElement?this.collectLink(t,e):t instanceof HTMLStyleElement?t.hasAttribute("exclude")||t.hasAttribute("ignore")||(this.styles.set(h(),new S({code:t.textContent||"",fromHtml:!0,url:""})),t.remove()):t instanceof HTMLScriptElement?this.collectScript(t,e):t instanceof HTMLMetaElement||t instanceof HTMLTitleElement?e.removeChild(t):t instanceof HTMLImageElement&&t.hasAttribute("src")&&t.setAttribute("src",u(t.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 Ae(e.initSource);t&&(this.scripts=t),n&&(this.styles=n)}e instanceof Ee?await this.importHtmlEntry(e):e instanceof g&&await this.importInstanceEntry()}async importHtmlEntry(e){let t=be.getCacheHtml(this.url);if(!t&&(t=await _(d(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,e),await b(e,n),this.html=n}async importInstanceEntry(){let e=be.getCacheScript(this.url)?.code;if(e||(e=await _(this.url,{cache:"no-cache"})),!e)return console.error("load app entry error, pleace check"),Promise.reject();this.scripts.set(this.url,new T({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 T?t:new T(t))}setStyle(e,t){this.styles.set(e,t)}}const be=new class{baseSource;cache;constructor(){this.cache=new Map,this.baseSource=new Se(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 ge(e){if(e instanceof HTMLLinkElement){const t=e.getAttribute("rel");let n=e.getAttribute("href");if("stylesheet"===t&&n){n=u(n,location.origin);const t=document.createElement("style");return function(e,t,n){const o=document.createElement("style");H(o),_(e).then((r=>{t.code=r,be.setBaseAppStyle(e,t),o.textContent=r,E(n)})).catch((e=>{console.error(e),A(n)}))}(n,new S({code:"",fromHtml:!1,url:n}),e),t}}if(e instanceof HTMLScriptElement){let t=e.getAttribute("src");if(t&&"module"!==e.type){t=u(t,location.origin);const n=new T({async:e.hasAttribute("async"),code:"",defer:e.defer||"module"===e.type,fromHtml:!1,isModule:!1});be.setBaseAppScript(t,n);const o=function(e,t,n){const o=document.createElement("script");return H(o),_(e).then((r=>{t.setCode(r);try{o.textContent=r,e.startsWith("inline-")||n.setAttribute("origin-src",e)}catch(t){console.error(t,e)}E(n)})).catch((e=>{console.error(e),A(n)})),o}(t,n,e);return o||e}}return e}function Ce(e){return e instanceof HTMLLinkElement||e instanceof HTMLScriptElement}function ve(e,t,n){if(Ce(t)){const o=ge(t);return n.call(e,o)}return n.call(e,t)}function Le(){const e=HTMLBodyElement.prototype.appendChild,t=HTMLHeadElement.prototype.appendChild,n=HTMLHeadElement.prototype.appendChild;HTMLBodyElement.prototype.appendChild=function(t){return ve(this,t,e)},HTMLHeadElement.prototype.appendChild=function(e){return ve(this,e,t)},HTMLHeadElement.prototype.insertBefore=function(e,t){return function(e,t,n,o){if(Ce(t)){const r=ge(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&&be.setBaseAppStyle(h(),new S({code:e.textContent,fromHtml:!1,url:""}))}))}))}window.__getAppOrInstance__=function(e){return e?be.getApp(e):be};const Te="bk-weweb";class xe{fetchSource;webcomponentTag=Te;constructor(){window.customElements.get(Te)||window.customElements.define(Te,ne)}setWebComponentTag(){window.customElements.get(this.webcomponentTag)||window.customElements.define(this.webcomponentTag,ne)}start(e){e?.collectBaseSource&&Le(),"function"==typeof e?.fetchSource&&(this.fetchSource=e.fetchSource),this.webcomponentTag=e?.webcomponentTag||Te,this.setWebComponentTag()}}const Pe=new xe;exports.WeWeb=xe,exports.activated=G,exports.deactivated=q,exports.default=Pe,exports.load=z,exports.loadApp=Z,exports.loadInstance=Q,exports.mount=function(e,t,n){const o=be.getApp(e);o&&l((()=>{F(),o.mount(t,n)}))},exports.preLoadApp=function(e){p((()=>Z({...e,isPreLoad:!0})))},exports.preLoadInstance=function(e){p((()=>Q({...e,isPreLoad:!0})))},exports.preLoadSource=function(e){p((()=>{!async function(e){const{collectScript:t,collectStyle:n}=await Ae(e),o=[];t&&Array.from(t.entries()).forEach((e=>{o.push(e[1].getCode()),be.setBaseAppScript(...e)})),n&&Array.from(n.entries()).forEach((e=>{o.push(e[1].getCode()),be.setBaseAppStyle(...e)})),await Promise.all(o).catch((e=>{throw e}))}(e)}))},exports.unload=function(e){be.deleteApp(e)},exports.unmount=X;
2
2
  //# sourceMappingURL=index.min.js.map