@rallie/block
Advanced tools
Comparing version 0.15.0 to 0.15.1
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RallieBlock={})}(this,(function(e){"use strict";function t(e,t,n,s){return new(n||(n=Promise))((function(i,r){function o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))}function n(e,t,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(e):s?s.value:t.get(e)}function s(e,t,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,n):i?i.value=n:t.set(e,n),n}function i(e,t,n,s){return new(n||(n=Promise))((function(i,r){function o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))}function r(e,t,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(e):s?s.value:t.get(e)}function o(e,t,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,n):i?i.value=n:t.set(e,n),n}"production"===process.env.NODE_ENV||Object.freeze({}),"production"===process.env.NODE_ENV||Object.freeze([]);const a=Object.assign,c=Object.prototype.hasOwnProperty,l=(e,t)=>c.call(e,t),h=Array.isArray,f=e=>"[object Map]"===w(e),u=e=>"symbol"==typeof e,d=e=>null!==e&&"object"==typeof e,p=Object.prototype.toString,w=e=>p.call(e),v=e=>w(e).slice(8,-1),y=e=>"string"==typeof e&&"NaN"!==e&&"-"!==e[0]&&""+parseInt(e,10)===e,g=(e=>{const t=Object.create(null);return e=>t[e]||(t[e]=(e=>e.charAt(0).toUpperCase()+e.slice(1))(e))})(),m=(e,t)=>!Object.is(e,t),E=e=>{const t=parseFloat(e);return isNaN(t)?e:t};function b(e,...t){console.warn(`[Vue warn] ${e}`,...t)}let _;function S(e,t=_){t&&t.active&&t.effects.push(e)}const k=e=>{const t=new Set(e);return t.w=0,t.n=0,t},O=e=>(e.w&$)>0,N=e=>(e.n&$)>0,A=new WeakMap;let R=0,$=1;const j=30;let M;const x=Symbol("production"!==process.env.NODE_ENV?"iterate":""),P=Symbol("production"!==process.env.NODE_ENV?"Map key iterate":"");class W{constructor(e,t=null,n){this.fn=e,this.scheduler=t,this.active=!0,this.deps=[],this.parent=void 0,S(this,n)}run(){if(!this.active)return this.fn();let e=M,t=T;for(;e;){if(e===this)return;e=e.parent}try{return this.parent=M,M=this,T=!0,$=1<<++R,R<=j?(({deps:e})=>{if(e.length)for(let t=0;t<e.length;t++)e[t].w|=$})(this):B(this),this.fn()}finally{R<=j&&(e=>{const{deps:t}=e;if(t.length){let n=0;for(let s=0;s<t.length;s++){const i=t[s];O(i)&&!N(i)?i.delete(e):t[n++]=i,i.w&=~$,i.n&=~$}t.length=n}})(this),$=1<<--R,M=this.parent,T=t,this.parent=void 0,this.deferStop&&this.stop()}}stop(){M===this?this.deferStop=!0:this.active&&(B(this),this.onStop&&this.onStop(),this.active=!1)}}function B(e){const{deps:t}=e;if(t.length){for(let n=0;n<t.length;n++)t[n].delete(e);t.length=0}}let T=!0;const L=[];function z(e,t,n){if(T&&M){let s=A.get(e);s||A.set(e,s=new Map);let i=s.get(n);i||s.set(n,i=k()),function(e,t){let n=!1;R<=j?N(e)||(e.n|=$,n=!O(e)):n=!e.has(M),n&&(e.add(M),M.deps.push(e),"production"!==process.env.NODE_ENV&&M.onTrack&&M.onTrack(Object.assign({effect:M},t)))}(i,"production"!==process.env.NODE_ENV?{effect:M,target:e,type:t,key:n}:void 0)}}function V(e,t,n,s,i,r){const o=A.get(e);if(!o)return;let a=[];if("clear"===t)a=[...o.values()];else if("length"===n&&h(e)){const e=E(s);o.forEach(((t,n)=>{("length"===n||n>=e)&&a.push(t)}))}else switch(void 0!==n&&a.push(o.get(n)),t){case"add":h(e)?y(n)&&a.push(o.get("length")):(a.push(o.get(x)),f(e)&&a.push(o.get(P)));break;case"delete":h(e)||(a.push(o.get(x)),f(e)&&a.push(o.get(P)));break;case"set":f(e)&&a.push(o.get(x))}const c="production"!==process.env.NODE_ENV?{target:e,type:t,key:n,newValue:s,oldValue:i,oldTarget:r}:void 0;if(1===a.length)a[0]&&("production"!==process.env.NODE_ENV?U(a[0],c):U(a[0]));else{const e=[];for(const t of a)t&&e.push(...t);"production"!==process.env.NODE_ENV?U(k(e),c):U(k(e))}}function U(e,t){const n=h(e)?e:[...e];for(const e of n)e.computed&&D(e,t);for(const e of n)e.computed||D(e,t)}function D(e,t){(e!==M||e.allowRecurse)&&("production"!==process.env.NODE_ENV&&e.onTrigger&&e.onTrigger(a({effect:e},t)),e.scheduler?e.scheduler():e.run())}const I=function(e,t){const n=Object.create(null),s=e.split(",");for(let e=0;e<s.length;e++)n[s[e]]=!0;return t?e=>!!n[e.toLowerCase()]:e=>!!n[e]}("__proto__,__v_isRef,__isVue"),C=new Set(Object.getOwnPropertyNames(Symbol).filter((e=>"arguments"!==e&&"caller"!==e)).map((e=>Symbol[e])).filter(u)),G=J(),F=J(!0),H=function(){const e={};return["includes","indexOf","lastIndexOf"].forEach((t=>{e[t]=function(...e){const n=ke(this);for(let e=0,t=this.length;e<t;e++)z(n,"get",e+"");const s=n[t](...e);return-1===s||!1===s?n[t](...e.map(ke)):s}})),["push","pop","shift","unshift","splice"].forEach((t=>{e[t]=function(...e){L.push(T),T=!1;const n=ke(this)[t].apply(this,e);return function(){const e=L.pop();T=void 0===e||e}(),n}})),e}();function J(e=!1,t=!1){return function(n,s,i){if("__v_isReactive"===s)return!e;if("__v_isReadonly"===s)return e;if("__v_isShallow"===s)return t;if("__v_raw"===s&&i===(e?t?me:ge:t?ye:ve).get(n))return n;const r=h(n);if(!e&&r&&l(H,s))return Reflect.get(H,s,i);const o=Reflect.get(n,s,i);return(u(s)?C.has(s):I(s))?o:(e||z(n,"get",s),t?o:Ae(o)?r&&y(s)?o:o.value:d(o)?e?be(o):Ee(o):o)}}const K={get:G,set:function(e=!1){return function(t,n,s,i){let r=t[n];if(Se(r)&&Ae(r)&&!Ae(s))return!1;if(!e&&(function(e){return!(!e||!e.__v_isShallow)}(s)||Se(s)||(r=ke(r),s=ke(s)),!h(t)&&Ae(r)&&!Ae(s)))return r.value=s,!0;const o=h(t)&&y(n)?Number(n)<t.length:l(t,n),a=Reflect.set(t,n,s,i);return t===ke(i)&&(o?m(s,r)&&V(t,"set",n,s,r):V(t,"add",n,s)),a}}(),deleteProperty:function(e,t){const n=l(e,t),s=e[t],i=Reflect.deleteProperty(e,t);return i&&n&&V(e,"delete",t,void 0,s),i},has:function(e,t){const n=Reflect.has(e,t);return u(t)&&C.has(t)||z(e,"has",t),n},ownKeys:function(e){return z(e,"iterate",h(e)?"length":x),Reflect.ownKeys(e)}},q={get:F,set:(e,t)=>("production"!==process.env.NODE_ENV&&b(`Set operation on key "${String(t)}" failed: target is readonly.`,e),!0),deleteProperty:(e,t)=>("production"!==process.env.NODE_ENV&&b(`Delete operation on key "${String(t)}" failed: target is readonly.`,e),!0)},Q=e=>e,X=e=>Reflect.getPrototypeOf(e);function Y(e,t,n=!1,s=!1){const i=ke(e=e.__v_raw),r=ke(t);n||(t!==r&&z(i,"get",t),z(i,"get",r));const{has:o}=X(i),a=s?Q:n?Ne:Oe;return o.call(i,t)?a(e.get(t)):o.call(i,r)?a(e.get(r)):void(e!==i&&e.get(t))}function Z(e,t=!1){const n=this.__v_raw,s=ke(n),i=ke(e);return t||(e!==i&&z(s,"has",e),z(s,"has",i)),e===i?n.has(e):n.has(e)||n.has(i)}function ee(e,t=!1){return e=e.__v_raw,!t&&z(ke(e),"iterate",x),Reflect.get(e,"size",e)}function te(e){e=ke(e);const t=ke(this);return X(t).has.call(t,e)||(t.add(e),V(t,"add",e,e)),this}function ne(e,t){t=ke(t);const n=ke(this),{has:s,get:i}=X(n);let r=s.call(n,e);r?"production"!==process.env.NODE_ENV&&we(n,s,e):(e=ke(e),r=s.call(n,e));const o=i.call(n,e);return n.set(e,t),r?m(t,o)&&V(n,"set",e,t,o):V(n,"add",e,t),this}function se(e){const t=ke(this),{has:n,get:s}=X(t);let i=n.call(t,e);i?"production"!==process.env.NODE_ENV&&we(t,n,e):(e=ke(e),i=n.call(t,e));const r=s?s.call(t,e):void 0,o=t.delete(e);return i&&V(t,"delete",e,void 0,r),o}function ie(){const e=ke(this),t=0!==e.size,n="production"!==process.env.NODE_ENV?f(e)?new Map(e):new Set(e):void 0,s=e.clear();return t&&V(e,"clear",void 0,void 0,n),s}function re(e,t){return function(n,s){const i=this,r=i.__v_raw,o=ke(r),a=t?Q:e?Ne:Oe;return!e&&z(o,"iterate",x),r.forEach(((e,t)=>n.call(s,a(e),a(t),i)))}}function oe(e,t,n){return function(...s){const i=this.__v_raw,r=ke(i),o=f(r),a="entries"===e||e===Symbol.iterator&&o,c="keys"===e&&o,l=i[e](...s),h=n?Q:t?Ne:Oe;return!t&&z(r,"iterate",c?P:x),{next(){const{value:e,done:t}=l.next();return t?{value:e,done:t}:{value:a?[h(e[0]),h(e[1])]:h(e),done:t}},[Symbol.iterator](){return this}}}}function ae(e){return function(...t){if("production"!==process.env.NODE_ENV){const n=t[0]?`on key "${t[0]}" `:"";console.warn(`${g(e)} operation ${n}failed: target is readonly.`,ke(this))}return"delete"!==e&&this}}const[ce,le,he,fe]=function(){const e={get(e){return Y(this,e)},get size(){return ee(this)},has:Z,add:te,set:ne,delete:se,clear:ie,forEach:re(!1,!1)},t={get(e){return Y(this,e,!1,!0)},get size(){return ee(this)},has:Z,add:te,set:ne,delete:se,clear:ie,forEach:re(!1,!0)},n={get(e){return Y(this,e,!0)},get size(){return ee(this,!0)},has(e){return Z.call(this,e,!0)},add:ae("add"),set:ae("set"),delete:ae("delete"),clear:ae("clear"),forEach:re(!0,!1)},s={get(e){return Y(this,e,!0,!0)},get size(){return ee(this,!0)},has(e){return Z.call(this,e,!0)},add:ae("add"),set:ae("set"),delete:ae("delete"),clear:ae("clear"),forEach:re(!0,!0)};return["keys","values","entries",Symbol.iterator].forEach((i=>{e[i]=oe(i,!1,!1),n[i]=oe(i,!0,!1),t[i]=oe(i,!1,!0),s[i]=oe(i,!0,!0)})),[e,n,t,s]}();function ue(e,t){const n=t?e?fe:he:e?le:ce;return(t,s,i)=>"__v_isReactive"===s?!e:"__v_isReadonly"===s?e:"__v_raw"===s?t:Reflect.get(l(n,s)&&s in t?n:t,s,i)}const de={get:ue(!1,!1)},pe={get:ue(!0,!1)};function we(e,t,n){const s=ke(n);if(s!==n&&t.call(e,s)){const t=v(e);console.warn(`Reactive ${t} contains both the raw and reactive versions of the same object${"Map"===t?" as keys":""}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`)}}const ve=new WeakMap,ye=new WeakMap,ge=new WeakMap,me=new WeakMap;function Ee(e){return Se(e)?e:_e(e,!1,K,de,ve)}function be(e){return _e(e,!0,q,pe,ge)}function _e(e,t,n,s,i){if(!d(e))return"production"!==process.env.NODE_ENV&&console.warn(`value cannot be made reactive: ${String(e)}`),e;if(e.__v_raw&&(!t||!e.__v_isReactive))return e;const r=i.get(e);if(r)return r;const o=(a=e).__v_skip||!Object.isExtensible(a)?0:function(e){switch(e){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(v(a));var a;if(0===o)return e;const c=new Proxy(e,2===o?s:n);return i.set(e,c),c}function Se(e){return!(!e||!e.__v_isReadonly)}function ke(e){const t=e&&e.__v_raw;return t?ke(t):e}const Oe=e=>d(e)?Ee(e):e,Ne=e=>d(e)?be(e):e;function Ae(e){return!(!e||!0!==e.__v_isRef)}const Re=e=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${e}, but ${e} hasn't been registed as a broadcast event`,$e=e=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${e}, but the listener hasn't been registed`,je=e=>`[@rallie/core] one of the callbacks of the broadcast event ${e} throws an uncaught error`,Me=e=>`[@rallie/core] you are trying to remove a listener of the unicast event ${e}, but ${e} hasn't been registed as a unicast event`,xe=e=>`[@rallie/core] you are trying to register a unicast event ${e}, but it has been registered before`,Pe=e=>`[@rallie/core] you have emitted ${e} unicast, but there is no listener of this event`,We=e=>`[@rallie/core] ${e} is existing, you are not allowed to create it again`,Be=(e,t)=>`[@rallie/core] can not find any assets of the app ${e} on the bus ${t}`,Te=e=>`[@rallie/core] you are trying to activate app ${e}, but it was not created`,Le=e=>`[@rallie/core] state ${e} is private, you are not allowed to set it`,ze=e=>`[@rallie/core] please describe your action when you modify the state ${e}`,Ve=e=>`[@rallie/core] it's not allowed to set or watch state ${e} before it is initialized`,Ue=e=>`[@rallie/core] duplicated initialized state ${e}`,De=e=>`[@rallie/core] it's not allowed to initialized state ${e} to a primitive value`,Ie=e=>`[@rallie/core] the bus named ${e} has been defined before, please rename your bus`,Ce=(e,t)=>`[@rallie/core] There is a circular dependency when activating the app ${e}, and the circular path is ${t.join("->")}`,Ge=()=>"[@rallie/core] next() called multiple times in the middleware",Fe=()=>"[@rallie/core] the middleware must be a function",He=(e,t)=>`[@rallie/core] the event ${e} is not in the events pool that you specified when calling on${t?"Unicast":"Broadcast"}`,Je=e=>(t,n)=>{let s=-1;const i=r=>{if(r<=s)return Promise.reject(new Error(Ge()));s=r;let o=e[r];if(r===e.length&&(o=n),!o)return Promise.resolve();try{return Promise.resolve(o(t,i.bind(null,r+1)))}catch(e){return Promise.reject(e)}};return i(0)};var Ke,qe,Qe,Xe,Ye,Ze,et,tt,nt;class st{constructor(){Ke.set(this,{}),qe.set(this,{})}addBroadcastEventListener(e,t){r(this,Ke,"f")[e]=r(this,Ke,"f")[e]||new Set,r(this,Ke,"f")[e].add(t)}addUnicastEventListener(e,t){if(r(this,qe,"f")[e])throw new Error(xe(e));r(this,qe,"f")[e]=t}removeBroadcastEventListener(e,t){const n=r(this,Ke,"f")[e];if(!n){const t=Re(e);throw new Error(t)}if(!n.has(t)){const t=$e(e);throw new Error(t)}n.delete(t)}removeUnicastEventListener(e){if(!r(this,qe,"f")[e]){const t=Me(e);throw new Error(t)}delete r(this,qe,"f")[e]}emitBroadcast(e,...t){r(this,Ke,"f")[e]=r(this,Ke,"f")[e]||new Set,r(this,Ke,"f")[e].forEach((n=>{try{n(...t)}catch(n){console.error(je(e)),console.error(n)}}))}emitUnicast(e,...t){const n=r(this,qe,"f")[e];if(n)return n(...t);throw new Error(Pe(e))}}Ke=new WeakMap,qe=new WeakMap;class it{constructor(e,t){Qe.set(this,void 0),Xe.set(this,void 0),o(this,Qe,e,"f"),o(this,Xe,t,"f"),r(this,Xe,"f")[e].watchers.add(this)}do(e){return this.handler=e,()=>this.unwatch()}unwatch(){null==this||this.stopEffect(),this.handler=null;const e=r(this,Xe,"f")[r(this,Qe,"f")].watchers;e.has(this)&&e.delete(this)}}Qe=new WeakMap,Xe=new WeakMap;class rt{constructor(e,t){Ye.add(this),Ze.set(this,void 0),et.set(this,void 0),o(this,Ze,e,"f"),o(this,et,t,"f")}onBroadcast(e){return Object.entries(e).forEach((([e,t])=>{r(this,Ze,"f").addBroadcastEventListener(e,t)})),t=>{r(this,Ye,"m",tt).call(this,e,!1,t)}}onUnicast(e){return Object.entries(e).forEach((([e,t])=>{try{r(this,Ze,"f").addUnicastEventListener(e,t)}catch(e){console.error(e)}})),t=>{r(this,Ye,"m",tt).call(this,e,!0,t)}}createBroadcaster(e){return new Proxy({},{get:(t,n)=>(...t)=>(null==e||e(n),r(this,Ze,"f").emitBroadcast(n,...t)),set:()=>!1})}createUnicaster(e){return new Proxy({},{get:(t,n)=>(...t)=>(null==e||e(n),r(this,Ze,"f").emitUnicast(n,...t)),set:()=>!1})}existState(e){return!!r(this,et,"f")[e]}initState(e,t,n=!1){if(this.existState(e))throw new Error(Ue(e));if(["string","number","boolean","undefined"].includes(typeof t))throw new Error(De(e));return r(this,et,"f")[e]={state:Ee(t),owner:n?this:null,watchers:new Set},r(this,Ze,"f").emitBroadcast("$state-initialized",e),this.getState(e)}getState(e,t){if(this.existState(e)){const n=be(r(this,et,"f")[e].state);return t?t(n):n}return null}setState(e,t,n){return i(this,void 0,void 0,(function*(){const s=r(this,Ye,"m",nt).call(this,e);if(!t)throw new Error(ze(e));{const e=n(s);yield Promise.resolve(e)}}))}watchState(e,t){if(!this.existState(e)){const t=Ve(e);throw new Error(t)}let n=!1;const s=be(r(this,et,"f")[e].state),i=new it(e,r(this,et,"f")),o=function(e,t){e.effect&&(e=e.effect.fn);const n=new W(e);t&&(a(n,t),t.scope&&S(n,t.scope)),t&&t.lazy||n.run();const s=n.run.bind(n);return s.effect=n,s}((()=>t(s)),{lazy:!0,scheduler:()=>{n||(n=!0,Promise.resolve().then((()=>{var e;const r=ke(t(s));null===(e=i.handler)||void 0===e||e.call(i,r,i.oldWatchingStates),i.oldWatchingStates=ke(r),n=!1})))}});return i.oldWatchingStates=o(),i.stopEffect=()=>o.effect.stop(),i}}Ze=new WeakMap,et=new WeakMap,Ye=new WeakSet,tt=function(e,t,n){let s=t?r(this,Ze,"f").removeUnicastEventListener:r(this,Ze,"f").removeBroadcastEventListener;s=s.bind(r(this,Ze,"f")),n?e[n]?(s(n,e[n]),delete e[n]):console.warn(He(n,t)):Object.entries(e).forEach((([e,t])=>{s(e,t)}))},nt=function(e){if(!this.existState(e)){const t=Ve(e);throw new Error(t)}const t=r(this,et,"f")[e].owner;if(t!==this&&null!==t){const t=Le(e);throw new Error(t)}return r(this,et,"f")[e].state};class ot{constructor(e){this.name=e,this.activated=null,this.dependencies=[],this.relatedApps=[],this.name=e,this.isRallieCoreApp=!0}relateTo(e){return this.relatedApps=Array.from(new Set([...this.relatedApps,...e])),this}relyOn(e){return this.relateTo(e),this.dependencies=Array.from(new Set([...this.dependencies,...e])),this}onActivate(e){return this.doActivate=e,this}}var at,ct,lt,ht,ft,ut,dt,pt,wt,vt,yt,gt,mt,Et,bt={loadScript:e=>i(void 0,void 0,void 0,(function*(){return new Promise((t=>{let n=null;if(e instanceof HTMLScriptElement)n=e;else{n=document.createElement("script");const t="string"!=typeof e?e:{type:"text/javascript",src:e};Object.entries(t).forEach((([e,t])=>{n.setAttribute(e,t)}))}n.src&&(n.onload=n.onerror=()=>{t()}),document.body.appendChild(n),n.src||t()}))})),loadLink:e=>{let t=null;if(e instanceof HTMLLinkElement)t=e;else{const n="string"!=typeof e?e:{rel:"stylesheet",type:"text/css",href:e};t=document.createElement("link"),Object.entries(n).forEach((([e,n])=>{t.setAttribute(e,n)}))}document.head.appendChild(t)}};class _t{constructor(e){at.add(this),ct.set(this,void 0),lt.set(this,new st),ht.set(this,{}),ft.set(this,{}),ut.set(this,{}),this.conf=be({assets:{}}),dt.set(this,[]),pt.set(this,void 0),o(this,ct,e,"f"),o(this,pt,Je(r(this,dt,"f")),"f")}createSocket(){return new rt(r(this,lt,"f"),r(this,ht,"f"))}existApp(e){return!!r(this,ft,"f")[e]}createApp(e){if(this.existApp(e))throw new Error(We(e));const t=new ot(e);return r(this,ft,"f")[e]=t,t}loadApp(e){return i(this,void 0,void 0,(function*(){r(this,ft,"f")[e]||(r(this,ut,"f")[e]||(r(this,ut,"f")[e]=new Promise(((t,n)=>{const s=r(this,at,"m",vt).call(this,e);r(this,pt,"f").call(this,s,r(this,at,"m",yt).bind(this)).then((()=>{e.startsWith("lib:")&&!r(this,ft,"f")[e]&&(r(this,ft,"f")[e]=!0),r(this,ft,"f")[e]||n(new Error(Te(e))),t()})).catch((e=>{n(e)}))}))),yield r(this,ut,"f")[e])}))}activateApp(e){return i(this,void 0,void 0,(function*(){yield r(this,at,"m",gt).call(this,e,[])}))}config(e){return this.conf=Object.assign(Object.assign(Object.assign({},this.conf),e),{assets:Object.assign(Object.assign({},this.conf.assets),(null==e?void 0:e.assets)||{})}),this}use(e){if("function"!=typeof e)throw new Error(Fe());return r(this,dt,"f").push(e),o(this,pt,Je(r(this,dt,"f")),"f"),this}}ct=new WeakMap,lt=new WeakMap,ht=new WeakMap,ft=new WeakMap,ut=new WeakMap,dt=new WeakMap,pt=new WeakMap,at=new WeakSet,wt=function(e){return r(this,ft,"f")[e]&&"boolean"!=typeof r(this,ft,"f")[e]},vt=function(e){return{name:e,loadScript:bt.loadScript,loadLink:bt.loadLink}},yt=function(e){return i(this,void 0,void 0,(function*(){const{name:t,loadScript:n=bt.loadScript,loadLink:s=bt.loadLink}=e,{assets:i}=this.conf;if(!i[t])throw new Error(Be(t,r(this,ct,"f")));if(i[t].css&&i[t].css.forEach((e=>{s(e)})),i[t].js)for(const e of i[t].js)yield n(e)}))},gt=function(e,t){return i(this,void 0,void 0,(function*(){if(yield this.loadApp(e),r(this,at,"m",wt).call(this,e)){const n=r(this,ft,"f")[e];if(yield r(this,at,"m",Et).call(this,n),t.includes(e)){const n=t.indexOf(e),s=[...t.slice(n),e];throw new Error(Ce(e,s))}if(t.push(e),!n.activated){const e=()=>i(this,void 0,void 0,(function*(){yield r(this,at,"m",mt).call(this,n,t),n.doActivate&&(yield Promise.resolve(n.doActivate()))}));n.activated=e()}yield n.activated,t.pop()}}))},mt=function(e,t){return i(this,void 0,void 0,(function*(){if(0!==e.dependencies.length)for(const n of e.dependencies)yield r(this,at,"m",gt).call(this,n,t)}))},Et=function(e){return i(this,void 0,void 0,(function*(){yield Promise.all(e.relatedApps.map((e=>this.loadApp(e))))}))};const St={},kt="DEFAULT_BUS",Ot=(e=kt)=>{let t=null,n=!1;const s=((e=kt)=>window.RALLIE_BUS_STORE&&window.RALLIE_BUS_STORE[e])(e);return s?(t=s,n=!1):(t=((e=kt)=>{if(void 0===window.RALLIE_BUS_STORE&&Reflect.defineProperty(window,"RALLIE_BUS_STORE",{value:St,writable:!1}),window.RALLIE_BUS_STORE[e])throw new Error(Ie(e));{const t=new _t(e);return Reflect.defineProperty(window.RALLIE_BUS_STORE,e,{value:t,writable:!1}),t}})(e),n=!0),[t,n]},Nt={privateBus:e=>`${e}.bus`,stateNamespace:e=>`${e}.state`,isGlobalBusAccessible:"isGlobalBusAccessible",exportMethodName:"__RallieInnerExport__"},At=e=>`[rallie] ${e}`,Rt={stateNotInitialized:e=>At(` the block ${e}'s state is not initialized, please check:\n1. whether the block ${e} is loaded.\n2. whether the block ${e} has initialized the state`),duplicatedBlockName:e=>At(`the block ${e} is already registered before, please rename your block`),stateIsReadonly:e=>At(`the state of ${e} is readonly`)},$t=(e,t)=>new Proxy(e,{get:(e,n)=>(...s)=>(0,e[n])(s,t),set:()=>!1}),jt=e=>{const t={};return Object.entries(e).forEach((([e,n])=>{t[e]=(e,t)=>n.call({trigger:t},...e)})),t};var Mt,xt,Pt,Wt,Bt,Tt,Lt;class zt{constructor(e,t,i){Mt.set(this,void 0),this.name=e,s(this,Mt,i,"f");const r=n(this,Mt,"f").createBroadcaster(),o=n(this,Mt,"f").createUnicaster();this.events=$t(r,t),this.methods=$t(o,t),Reflect.defineProperty(this,"state",{get:()=>n(this,Mt,"f").getState(Nt.stateNamespace(this.name)),set:()=>{throw new Error(Rt.stateIsReadonly(this.name))}})}setState(e,t){if(n(this,Mt,"f").existState(Nt.stateNamespace(this.name)))return n(this,Mt,"f").setState(Nt.stateNamespace(this.name),e,t);throw new Error(Rt.stateNotInitialized(this.name))}watchState(e){if(n(this,Mt,"f").existState(Nt.stateNamespace(this.name)))return n(this,Mt,"f").watchState(Nt.stateNamespace(this.name),e);throw new Error(Rt.stateNotInitialized(this.name))}listenEvents(e){return n(this,Mt,"f").onBroadcast(jt(e))}}Mt=new WeakMap;class Vt extends zt{constructor(e,t,n,i){const[r]=Ot(Nt.privateBus(e)),o=r.createSocket();super(e,e,o),xt.set(this,void 0),Pt.set(this,void 0),Wt.set(this,void 0),Bt.set(this,void 0),Tt.set(this,void 0),Lt.set(this,{}),s(this,Bt,o,"f"),s(this,xt,t,"f"),s(this,Pt,n,"f"),s(this,Tt,t.createApp(e),"f"),s(this,Wt,i,"f")}initState(e,t){return n(this,Bt,"f").initState(Nt.stateNamespace(this.name),e,t),this}addMethods(e){return n(this,Bt,"f").onUnicast(jt(e))}relyOn(e){return n(this,Tt,"f").relyOn(e),this}relateTo(e){return n(this,Tt,"f").relateTo(e),this}onActivate(e){return n(this,Tt,"f").onActivate(e),this}connect(e){if(!n(this,Lt,"f")[e]){const[t]=Ot(Nt.privateBus(e)),s=t.createSocket();n(this,Lt,"f")[e]=new zt(e,this.name,s)}return n(this,Lt,"f")[e]}load(e){return n(this,xt,"f").loadApp(e)}activate(e){return n(this,xt,"f").activateApp(e)}run(e){var s;return t(this,void 0,void 0,(function*(){const t=n(this,Wt,"f")||(null===(s=n(this,Pt,"f").getState(Nt.isGlobalBusAccessible))||void 0===s?void 0:s.value),i=e=>{n(this,Wt,"f")&&n(this,Pt,"f").setState(Nt.isGlobalBusAccessible,e?"unfreeze the enviroment":"freeze the enviroment",(t=>{t.value=e}))},r={isEntry:n(this,Wt,"f"),use:e=>{t&&n(this,xt,"f").use(e)},config:e=>{t&&n(this,xt,"f").config(e)},freeze:()=>{i(!1)},unfreeze:()=>{i(!0)}},o=e(new Proxy(r,{get:(e,t,s)=>"conf"===t?JSON.parse(JSON.stringify(n(this,xt,"f").conf)):Reflect.get(e,t,s),set:()=>!1}));yield Promise.resolve(o)}))}}xt=new WeakMap,Pt=new WeakMap,Wt=new WeakMap,Bt=new WeakMap,Tt=new WeakMap,Lt=new WeakMap,e.createBlock=function(e){const[t,n]=Ot();if(t.existApp(e))throw new Error(Rt.duplicatedBlockName(e));const s=t.createSocket();return n&&s.initState(Nt.isGlobalBusAccessible,{value:!0},!0),new Vt(e,t,s,n)}})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RallieBlock={})}(this,(function(t){"use strict";function e(t,e,n,s){return new(n||(n=Promise))((function(i,r){function o(t){try{c(s.next(t))}catch(t){r(t)}}function a(t){try{c(s.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((s=s.apply(t,e||[])).next())}))}function n(t,e,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(t):s?s.value:e.get(t)}function s(t,e,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(t,n):i?i.value=n:e.set(t,n),n}function i(t,e,n,s){return new(n||(n=Promise))((function(i,r){function o(t){try{c(s.next(t))}catch(t){r(t)}}function a(t){try{c(s.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((s=s.apply(t,e||[])).next())}))}function r(t,e,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(t):s?s.value:e.get(t)}function o(t,e,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(t,n):i?i.value=n:e.set(t,n),n}const a=Object.assign,c=Object.prototype.hasOwnProperty,l=(t,e)=>c.call(t,e),h=Array.isArray,f=t=>"[object Map]"===w(t),u=t=>"symbol"==typeof t,d=t=>null!==t&&"object"==typeof t,p=Object.prototype.toString,w=t=>p.call(t),v=t=>w(t).slice(8,-1),y=t=>"string"==typeof t&&"NaN"!==t&&"-"!==t[0]&&""+parseInt(t,10)===t,m=(t,e)=>!Object.is(t,e),g=t=>{const e=parseFloat(t);return isNaN(e)?t:e};let b;function _(t,e=b){e&&e.active&&e.effects.push(t)}const E=t=>{const e=new Set(t);return e.w=0,e.n=0,e},S=t=>(t.w&O)>0,k=t=>(t.n&O)>0,A=new WeakMap;let R=0,O=1;const x=30;let M;const P=Symbol(""),W=Symbol("");class j{constructor(t,e=null,n){this.fn=t,this.scheduler=e,this.active=!0,this.deps=[],this.parent=void 0,_(this,n)}run(){if(!this.active)return this.fn();let t=M,e=$;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=M,M=this,$=!0,O=1<<++R,R<=x?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=O})(this):B(this),this.fn()}finally{R<=x&&(t=>{const{deps:e}=t;if(e.length){let n=0;for(let s=0;s<e.length;s++){const i=e[s];S(i)&&!k(i)?i.delete(t):e[n++]=i,i.w&=~O,i.n&=~O}e.length=n}})(this),O=1<<--R,M=this.parent,$=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){M===this?this.deferStop=!0:this.active&&(B(this),this.onStop&&this.onStop(),this.active=!1)}}function B(t){const{deps:e}=t;if(e.length){for(let n=0;n<e.length;n++)e[n].delete(t);e.length=0}}let $=!0;const L=[];function T(t,e,n){if($&&M){let e=A.get(t);e||A.set(t,e=new Map);let s=e.get(n);s||e.set(n,s=E()),function(t,e){let n=!1;R<=x?k(t)||(t.n|=O,n=!S(t)):n=!t.has(M),n&&(t.add(M),M.deps.push(t))}(s)}}function z(t,e,n,s,i,r){const o=A.get(t);if(!o)return;let a=[];if("clear"===e)a=[...o.values()];else if("length"===n&&h(t)){const t=g(s);o.forEach(((e,n)=>{("length"===n||n>=t)&&a.push(e)}))}else switch(void 0!==n&&a.push(o.get(n)),e){case"add":h(t)?y(n)&&a.push(o.get("length")):(a.push(o.get(P)),f(t)&&a.push(o.get(W)));break;case"delete":h(t)||(a.push(o.get(P)),f(t)&&a.push(o.get(W)));break;case"set":f(t)&&a.push(o.get(P))}if(1===a.length)a[0]&&N(a[0]);else{const t=[];for(const e of a)e&&t.push(...e);N(E(t))}}function N(t,e){const n=h(t)?t:[...t];for(const t of n)t.computed&&U(t);for(const t of n)t.computed||U(t)}function U(t,e){(t!==M||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}const I=function(t,e){const n=Object.create(null),s=t.split(",");for(let t=0;t<s.length;t++)n[s[t]]=!0;return e?t=>!!n[t.toLowerCase()]:t=>!!n[t]}("__proto__,__v_isRef,__isVue"),C=new Set(Object.getOwnPropertyNames(Symbol).filter((t=>"arguments"!==t&&"caller"!==t)).map((t=>Symbol[t])).filter(u)),G=J(),F=J(!0),H=function(){const t={};return["includes","indexOf","lastIndexOf"].forEach((e=>{t[e]=function(...t){const n=_t(this);for(let t=0,e=this.length;t<e;t++)T(n,0,t+"");const s=n[e](...t);return-1===s||!1===s?n[e](...t.map(_t)):s}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){L.push($),$=!1;const n=_t(this)[e].apply(this,t);return function(){const t=L.pop();$=void 0===t||t}(),n}})),t}();function J(t=!1,e=!1){return function(n,s,i){if("__v_isReactive"===s)return!t;if("__v_isReadonly"===s)return t;if("__v_isShallow"===s)return e;if("__v_raw"===s&&i===(t?e?vt:wt:e?pt:dt).get(n))return n;const r=h(n);if(!t&&r&&l(H,s))return Reflect.get(H,s,i);const o=Reflect.get(n,s,i);return(u(s)?C.has(s):I(s))?o:(t||T(n,0,s),e?o:kt(o)?r&&y(s)?o:o.value:d(o)?t?mt(o):yt(o):o)}}const K={get:G,set:function(t=!1){return function(e,n,s,i){let r=e[n];if(bt(r)&&kt(r)&&!kt(s))return!1;if(!t&&(function(t){return!(!t||!t.__v_isShallow)}(s)||bt(s)||(r=_t(r),s=_t(s)),!h(e)&&kt(r)&&!kt(s)))return r.value=s,!0;const o=h(e)&&y(n)?Number(n)<e.length:l(e,n),a=Reflect.set(e,n,s,i);return e===_t(i)&&(o?m(s,r)&&z(e,"set",n,s):z(e,"add",n,s)),a}}(),deleteProperty:function(t,e){const n=l(t,e);t[e];const s=Reflect.deleteProperty(t,e);return s&&n&&z(t,"delete",e,void 0),s},has:function(t,e){const n=Reflect.has(t,e);return u(e)&&C.has(e)||T(t,0,e),n},ownKeys:function(t){return T(t,0,h(t)?"length":P),Reflect.ownKeys(t)}},D={get:F,set:(t,e)=>!0,deleteProperty:(t,e)=>!0},V=t=>t,q=t=>Reflect.getPrototypeOf(t);function Q(t,e,n=!1,s=!1){const i=_t(t=t.__v_raw),r=_t(e);n||(e!==r&&T(i,0,e),T(i,0,r));const{has:o}=q(i),a=s?V:n?St:Et;return o.call(i,e)?a(t.get(e)):o.call(i,r)?a(t.get(r)):void(t!==i&&t.get(e))}function X(t,e=!1){const n=this.__v_raw,s=_t(n),i=_t(t);return e||(t!==i&&T(s,0,t),T(s,0,i)),t===i?n.has(t):n.has(t)||n.has(i)}function Y(t,e=!1){return t=t.__v_raw,!e&&T(_t(t),0,P),Reflect.get(t,"size",t)}function Z(t){t=_t(t);const e=_t(this);return q(e).has.call(e,t)||(e.add(t),z(e,"add",t,t)),this}function tt(t,e){e=_t(e);const n=_t(this),{has:s,get:i}=q(n);let r=s.call(n,t);r||(t=_t(t),r=s.call(n,t));const o=i.call(n,t);return n.set(t,e),r?m(e,o)&&z(n,"set",t,e):z(n,"add",t,e),this}function et(t){const e=_t(this),{has:n,get:s}=q(e);let i=n.call(e,t);i||(t=_t(t),i=n.call(e,t)),s&&s.call(e,t);const r=e.delete(t);return i&&z(e,"delete",t,void 0),r}function nt(){const t=_t(this),e=0!==t.size,n=t.clear();return e&&z(t,"clear",void 0,void 0),n}function st(t,e){return function(n,s){const i=this,r=i.__v_raw,o=_t(r),a=e?V:t?St:Et;return!t&&T(o,0,P),r.forEach(((t,e)=>n.call(s,a(t),a(e),i)))}}function it(t,e,n){return function(...s){const i=this.__v_raw,r=_t(i),o=f(r),a="entries"===t||t===Symbol.iterator&&o,c="keys"===t&&o,l=i[t](...s),h=n?V:e?St:Et;return!e&&T(r,0,c?W:P),{next(){const{value:t,done:e}=l.next();return e?{value:t,done:e}:{value:a?[h(t[0]),h(t[1])]:h(t),done:e}},[Symbol.iterator](){return this}}}}function rt(t){return function(...e){return"delete"!==t&&this}}const[ot,at,ct,lt]=function(){const t={get(t){return Q(this,t)},get size(){return Y(this)},has:X,add:Z,set:tt,delete:et,clear:nt,forEach:st(!1,!1)},e={get(t){return Q(this,t,!1,!0)},get size(){return Y(this)},has:X,add:Z,set:tt,delete:et,clear:nt,forEach:st(!1,!0)},n={get(t){return Q(this,t,!0)},get size(){return Y(this,!0)},has(t){return X.call(this,t,!0)},add:rt("add"),set:rt("set"),delete:rt("delete"),clear:rt("clear"),forEach:st(!0,!1)},s={get(t){return Q(this,t,!0,!0)},get size(){return Y(this,!0)},has(t){return X.call(this,t,!0)},add:rt("add"),set:rt("set"),delete:rt("delete"),clear:rt("clear"),forEach:st(!0,!0)};return["keys","values","entries",Symbol.iterator].forEach((i=>{t[i]=it(i,!1,!1),n[i]=it(i,!0,!1),e[i]=it(i,!1,!0),s[i]=it(i,!0,!0)})),[t,n,e,s]}();function ht(t,e){const n=e?t?lt:ct:t?at:ot;return(e,s,i)=>"__v_isReactive"===s?!t:"__v_isReadonly"===s?t:"__v_raw"===s?e:Reflect.get(l(n,s)&&s in e?n:e,s,i)}const ft={get:ht(!1,!1)},ut={get:ht(!0,!1)},dt=new WeakMap,pt=new WeakMap,wt=new WeakMap,vt=new WeakMap;function yt(t){return bt(t)?t:gt(t,!1,K,ft,dt)}function mt(t){return gt(t,!0,D,ut,wt)}function gt(t,e,n,s,i){if(!d(t))return t;if(t.__v_raw&&(!e||!t.__v_isReactive))return t;const r=i.get(t);if(r)return r;const o=(a=t).__v_skip||!Object.isExtensible(a)?0:function(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(v(a));var a;if(0===o)return t;const c=new Proxy(t,2===o?s:n);return i.set(t,c),c}function bt(t){return!(!t||!t.__v_isReadonly)}function _t(t){const e=t&&t.__v_raw;return e?_t(e):t}const Et=t=>d(t)?yt(t):t,St=t=>d(t)?mt(t):t;function kt(t){return!(!t||!0!==t.__v_isRef)}const At=t=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${t}, but ${t} hasn't been registed as a broadcast event`,Rt=t=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${t}, but the listener hasn't been registed`,Ot=t=>`[@rallie/core] one of the callbacks of the broadcast event ${t} throws an uncaught error`,xt=t=>`[@rallie/core] you are trying to remove a listener of the unicast event ${t}, but ${t} hasn't been registed as a unicast event`,Mt=t=>`[@rallie/core] you are trying to register a unicast event ${t}, but it has been registered before`,Pt=t=>`[@rallie/core] you have emitted ${t} unicast, but there is no listener of this event`,Wt=t=>`[@rallie/core] ${t} is existing, you are not allowed to create it again`,jt=(t,e)=>`[@rallie/core] can not find any assets of the app ${t} on the bus ${e}`,Bt=t=>`[@rallie/core] you are trying to activate app ${t}, but it was not created`,$t=t=>`[@rallie/core] state ${t} is private, you are not allowed to set it`,Lt=t=>`[@rallie/core] please describe your action when you modify the state ${t}`,Tt=t=>`[@rallie/core] it's not allowed to set or watch state ${t} before it is initialized`,zt=t=>`[@rallie/core] duplicated initialized state ${t}`,Nt=t=>`[@rallie/core] it's not allowed to initialized state ${t} to a primitive value`,Ut=t=>`[@rallie/core] the bus named ${t} has been defined before, please rename your bus`,It=(t,e)=>`[@rallie/core] There is a circular dependency when activating the app ${t}, and the circular path is ${e.join("->")}`,Ct=()=>"[@rallie/core] next() called multiple times in the middleware",Gt=()=>"[@rallie/core] the middleware must be a function",Ft=(t,e)=>`[@rallie/core] the event ${t} is not in the events pool that you specified when calling on${e?"Unicast":"Broadcast"}`,Ht=t=>(e,n)=>{let s=-1;const i=r=>{if(r<=s)return Promise.reject(new Error(Ct()));s=r;let o=t[r];if(r===t.length&&(o=n),!o)return Promise.resolve();try{return Promise.resolve(o(e,i.bind(null,r+1)))}catch(t){return Promise.reject(t)}};return i(0)};var Jt,Kt,Dt,Vt,qt,Qt,Xt,Yt,Zt;class te{constructor(){Jt.set(this,{}),Kt.set(this,{})}addBroadcastEventListener(t,e){r(this,Jt,"f")[t]=r(this,Jt,"f")[t]||new Set,r(this,Jt,"f")[t].add(e)}addUnicastEventListener(t,e){if(r(this,Kt,"f")[t])throw new Error(Mt(t));r(this,Kt,"f")[t]=e}removeBroadcastEventListener(t,e){const n=r(this,Jt,"f")[t];if(!n){const e=At(t);throw new Error(e)}if(!n.has(e)){const e=Rt(t);throw new Error(e)}n.delete(e)}removeUnicastEventListener(t){if(!r(this,Kt,"f")[t]){const e=xt(t);throw new Error(e)}delete r(this,Kt,"f")[t]}emitBroadcast(t,...e){r(this,Jt,"f")[t]=r(this,Jt,"f")[t]||new Set,r(this,Jt,"f")[t].forEach((n=>{try{n(...e)}catch(n){console.error(Ot(t)),console.error(n)}}))}emitUnicast(t,...e){const n=r(this,Kt,"f")[t];if(n)return n(...e);throw new Error(Pt(t))}}Jt=new WeakMap,Kt=new WeakMap;class ee{constructor(t,e){Dt.set(this,void 0),Vt.set(this,void 0),o(this,Dt,t,"f"),o(this,Vt,e,"f"),r(this,Vt,"f")[t].watchers.add(this)}do(t){return this.handler=t,()=>this.unwatch()}unwatch(){null==this||this.stopEffect(),this.handler=null;const t=r(this,Vt,"f")[r(this,Dt,"f")].watchers;t.has(this)&&t.delete(this)}}Dt=new WeakMap,Vt=new WeakMap;class ne{constructor(t,e){qt.add(this),Qt.set(this,void 0),Xt.set(this,void 0),o(this,Qt,t,"f"),o(this,Xt,e,"f")}onBroadcast(t){return Object.entries(t).forEach((([t,e])=>{r(this,Qt,"f").addBroadcastEventListener(t,e)})),e=>{r(this,qt,"m",Yt).call(this,t,!1,e)}}onUnicast(t){return Object.entries(t).forEach((([t,e])=>{try{r(this,Qt,"f").addUnicastEventListener(t,e)}catch(t){console.error(t)}})),e=>{r(this,qt,"m",Yt).call(this,t,!0,e)}}createBroadcaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),r(this,Qt,"f").emitBroadcast(n,...e)),set:()=>!1})}createUnicaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),r(this,Qt,"f").emitUnicast(n,...e)),set:()=>!1})}existState(t){return!!r(this,Xt,"f")[t]}initState(t,e,n=!1){if(this.existState(t))throw new Error(zt(t));if(["string","number","boolean","undefined"].includes(typeof e))throw new Error(Nt(t));return r(this,Xt,"f")[t]={state:yt(e),owner:n?this:null,watchers:new Set},r(this,Qt,"f").emitBroadcast("$state-initialized",t),this.getState(t)}getState(t,e){if(this.existState(t)){const n=mt(r(this,Xt,"f")[t].state);return e?e(n):n}return null}setState(t,e,n){return i(this,void 0,void 0,(function*(){const s=r(this,qt,"m",Zt).call(this,t);if(!e)throw new Error(Lt(t));{const t=n(s);yield Promise.resolve(t)}}))}watchState(t,e){if(!this.existState(t)){const e=Tt(t);throw new Error(e)}let n=!1;const s=mt(r(this,Xt,"f")[t].state),i=new ee(t,r(this,Xt,"f")),o=function(t,e){t.effect&&(t=t.effect.fn);const n=new j(t);e&&(a(n,e),e.scope&&_(n,e.scope)),e&&e.lazy||n.run();const s=n.run.bind(n);return s.effect=n,s}((()=>e(s)),{lazy:!0,scheduler:()=>{n||(n=!0,Promise.resolve().then((()=>{var t;const r=_t(e(s));null===(t=i.handler)||void 0===t||t.call(i,r,i.oldWatchingStates),i.oldWatchingStates=_t(r),n=!1})))}});return i.oldWatchingStates=o(),i.stopEffect=()=>o.effect.stop(),i}}Qt=new WeakMap,Xt=new WeakMap,qt=new WeakSet,Yt=function(t,e,n){let s=e?r(this,Qt,"f").removeUnicastEventListener:r(this,Qt,"f").removeBroadcastEventListener;s=s.bind(r(this,Qt,"f")),n?t[n]?(s(n,t[n]),delete t[n]):console.warn(Ft(n,e)):Object.entries(t).forEach((([t,e])=>{s(t,e)}))},Zt=function(t){if(!this.existState(t)){const e=Tt(t);throw new Error(e)}const e=r(this,Xt,"f")[t].owner;if(e!==this&&null!==e){const e=$t(t);throw new Error(e)}return r(this,Xt,"f")[t].state};class se{constructor(t){this.name=t,this.activated=null,this.dependencies=[],this.relatedApps=[],this.name=t,this.isRallieCoreApp=!0}relateTo(t){return this.relatedApps=Array.from(new Set([...this.relatedApps,...t])),this}relyOn(t){return this.relateTo(t),this.dependencies=Array.from(new Set([...this.dependencies,...t])),this}onActivate(t){return this.doActivate=t,this}}var ie,re,oe,ae,ce,le,he,fe,ue,de,pe,we,ve,ye,me={loadScript:t=>i(void 0,void 0,void 0,(function*(){return new Promise((e=>{let n=null;if(t instanceof HTMLScriptElement)n=t;else{n=document.createElement("script");const e="string"!=typeof t?t:{type:"text/javascript",src:t};Object.entries(e).forEach((([t,e])=>{n.setAttribute(t,e)}))}n.src&&(n.onload=n.onerror=()=>{e()}),document.body.appendChild(n),n.src||e()}))})),loadLink:t=>{let e=null;if(t instanceof HTMLLinkElement)e=t;else{const n="string"!=typeof t?t:{rel:"stylesheet",type:"text/css",href:t};e=document.createElement("link"),Object.entries(n).forEach((([t,n])=>{e.setAttribute(t,n)}))}document.head.appendChild(e)}};class ge{constructor(t){ie.add(this),re.set(this,void 0),oe.set(this,new te),ae.set(this,{}),ce.set(this,{}),le.set(this,{}),this.conf=mt({assets:{}}),he.set(this,[]),fe.set(this,void 0),o(this,re,t,"f"),o(this,fe,Ht(r(this,he,"f")),"f")}createSocket(){return new ne(r(this,oe,"f"),r(this,ae,"f"))}existApp(t){return!!r(this,ce,"f")[t]}createApp(t){if(this.existApp(t))throw new Error(Wt(t));const e=new se(t);return r(this,ce,"f")[t]=e,e}loadApp(t){return i(this,void 0,void 0,(function*(){r(this,ce,"f")[t]||(r(this,le,"f")[t]||(r(this,le,"f")[t]=new Promise(((e,n)=>{const s=r(this,ie,"m",de).call(this,t);r(this,fe,"f").call(this,s,r(this,ie,"m",pe).bind(this)).then((()=>{t.startsWith("lib:")&&!r(this,ce,"f")[t]&&(r(this,ce,"f")[t]=!0),r(this,ce,"f")[t]||n(new Error(Bt(t))),e()})).catch((t=>{n(t)}))}))),yield r(this,le,"f")[t])}))}activateApp(t){return i(this,void 0,void 0,(function*(){yield r(this,ie,"m",we).call(this,t,[])}))}config(t){return this.conf=Object.assign(Object.assign(Object.assign({},this.conf),t),{assets:Object.assign(Object.assign({},this.conf.assets),(null==t?void 0:t.assets)||{})}),this}use(t){if("function"!=typeof t)throw new Error(Gt());return r(this,he,"f").push(t),o(this,fe,Ht(r(this,he,"f")),"f"),this}}re=new WeakMap,oe=new WeakMap,ae=new WeakMap,ce=new WeakMap,le=new WeakMap,he=new WeakMap,fe=new WeakMap,ie=new WeakSet,ue=function(t){return r(this,ce,"f")[t]&&"boolean"!=typeof r(this,ce,"f")[t]},de=function(t){return{name:t,loadScript:me.loadScript,loadLink:me.loadLink}},pe=function(t){return i(this,void 0,void 0,(function*(){const{name:e,loadScript:n=me.loadScript,loadLink:s=me.loadLink}=t,{assets:i}=this.conf;if(!i[e])throw new Error(jt(e,r(this,re,"f")));if(i[e].css&&i[e].css.forEach((t=>{s(t)})),i[e].js)for(const t of i[e].js)yield n(t)}))},we=function(t,e){return i(this,void 0,void 0,(function*(){if(yield this.loadApp(t),r(this,ie,"m",ue).call(this,t)){const n=r(this,ce,"f")[t];if(yield r(this,ie,"m",ye).call(this,n),e.includes(t)){const n=e.indexOf(t),s=[...e.slice(n),t];throw new Error(It(t,s))}if(e.push(t),!n.activated){const t=()=>i(this,void 0,void 0,(function*(){yield r(this,ie,"m",ve).call(this,n,e),n.doActivate&&(yield Promise.resolve(n.doActivate()))}));n.activated=t()}yield n.activated,e.pop()}}))},ve=function(t,e){return i(this,void 0,void 0,(function*(){if(0!==t.dependencies.length)for(const n of t.dependencies)yield r(this,ie,"m",we).call(this,n,e)}))},ye=function(t){return i(this,void 0,void 0,(function*(){yield Promise.all(t.relatedApps.map((t=>this.loadApp(t))))}))};const be={},_e="DEFAULT_BUS",Ee=(t=_e)=>{let e=null,n=!1;const s=((t=_e)=>window.RALLIE_BUS_STORE&&window.RALLIE_BUS_STORE[t])(t);return s?(e=s,n=!1):(e=((t=_e)=>{if(void 0===window.RALLIE_BUS_STORE&&Reflect.defineProperty(window,"RALLIE_BUS_STORE",{value:be,writable:!1}),window.RALLIE_BUS_STORE[t])throw new Error(Ut(t));{const e=new ge(t);return Reflect.defineProperty(window.RALLIE_BUS_STORE,t,{value:e,writable:!1}),e}})(t),n=!0),[e,n]},Se={privateBus:t=>`${t}.bus`,stateNamespace:t=>`${t}.state`,isGlobalBusAccessible:"isGlobalBusAccessible",exportMethodName:"__RallieInnerExport__"},ke=t=>`[rallie] ${t}`,Ae={stateNotInitialized:t=>ke(` the block ${t}'s state is not initialized, please check:\n1. whether the block ${t} is loaded.\n2. whether the block ${t} has initialized the state`),duplicatedBlockName:t=>ke(`the block ${t} is already registered before, please rename your block`),stateIsReadonly:t=>ke(`the state of ${t} is readonly`)},Re=(t,e)=>new Proxy(t,{get:(t,n)=>(...s)=>(0,t[n])(s,e),set:()=>!1}),Oe=t=>{const e={};return Object.entries(t).forEach((([t,n])=>{e[t]=(t,e)=>n.call({trigger:e},...t)})),e};var xe,Me,Pe,We,je,Be,$e;class Le{constructor(t,e,i){xe.set(this,void 0),this.name=t,s(this,xe,i,"f");const r=n(this,xe,"f").createBroadcaster(),o=n(this,xe,"f").createUnicaster();this.events=Re(r,e),this.methods=Re(o,e),Reflect.defineProperty(this,"state",{get:()=>n(this,xe,"f").getState(Se.stateNamespace(this.name)),set:()=>{throw new Error(Ae.stateIsReadonly(this.name))}})}setState(t,e){if(n(this,xe,"f").existState(Se.stateNamespace(this.name)))return n(this,xe,"f").setState(Se.stateNamespace(this.name),t,e);throw new Error(Ae.stateNotInitialized(this.name))}watchState(t){if(n(this,xe,"f").existState(Se.stateNamespace(this.name)))return n(this,xe,"f").watchState(Se.stateNamespace(this.name),t);throw new Error(Ae.stateNotInitialized(this.name))}listenEvents(t){return n(this,xe,"f").onBroadcast(Oe(t))}}xe=new WeakMap;class Te extends Le{constructor(t,e,n,i){const[r]=Ee(Se.privateBus(t)),o=r.createSocket();super(t,t,o),Me.set(this,void 0),Pe.set(this,void 0),We.set(this,void 0),je.set(this,void 0),Be.set(this,void 0),$e.set(this,{}),s(this,je,o,"f"),s(this,Me,e,"f"),s(this,Pe,n,"f"),s(this,Be,e.createApp(t),"f"),s(this,We,i,"f")}initState(t,e){return n(this,je,"f").initState(Se.stateNamespace(this.name),t,e),this}addMethods(t){return n(this,je,"f").onUnicast(Oe(t))}relyOn(t){return n(this,Be,"f").relyOn(t),this}relateTo(t){return n(this,Be,"f").relateTo(t),this}onActivate(t){return n(this,Be,"f").onActivate(t),this}connect(t){if(!n(this,$e,"f")[t]){const[e]=Ee(Se.privateBus(t)),s=e.createSocket();n(this,$e,"f")[t]=new Le(t,this.name,s)}return n(this,$e,"f")[t]}load(t){return n(this,Me,"f").loadApp(t)}activate(t){return n(this,Me,"f").activateApp(t)}run(t){var s;return e(this,void 0,void 0,(function*(){const e=n(this,We,"f")||(null===(s=n(this,Pe,"f").getState(Se.isGlobalBusAccessible))||void 0===s?void 0:s.value),i=t=>{n(this,We,"f")&&n(this,Pe,"f").setState(Se.isGlobalBusAccessible,t?"unfreeze the enviroment":"freeze the enviroment",(e=>{e.value=t}))},r={isEntry:n(this,We,"f"),use:t=>{e&&n(this,Me,"f").use(t)},config:t=>{e&&n(this,Me,"f").config(t)},freeze:()=>{i(!1)},unfreeze:()=>{i(!0)}},o=t(new Proxy(r,{get:(t,e,s)=>"conf"===e?JSON.parse(JSON.stringify(n(this,Me,"f").conf)):Reflect.get(t,e,s),set:()=>!1}));yield Promise.resolve(o)}))}}Me=new WeakMap,Pe=new WeakMap,We=new WeakMap,je=new WeakMap,Be=new WeakMap,$e=new WeakMap,t.createBlock=function(t){const[e,n]=Ee();if(e.existApp(t))throw new Error(Ae.duplicatedBlockName(t));const s=e.createSocket();return n&&s.initState(Se.isGlobalBusAccessible,{value:!0},!0),new Te(t,e,s,n)}})); |
@@ -1,1 +0,1 @@ | ||
function e(e,t,n,s){return new(n||(n=Promise))((function(r,i){function o(e){try{c(s.next(e))}catch(e){i(e)}}function a(e){try{c(s.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))}function t(e,t,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(e):s?s.value:t.get(e)}function n(e,t,n,s,r){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?r.call(e,n):r?r.value=n:t.set(e,n),n}function s(e,t,n,s){return new(n||(n=Promise))((function(r,i){function o(e){try{c(s.next(e))}catch(e){i(e)}}function a(e){try{c(s.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))}function r(e,t,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(e):s?s.value:t.get(e)}function i(e,t,n,s,r){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?r.call(e,n):r?r.value=n:t.set(e,n),n}"production"===process.env.NODE_ENV||Object.freeze({}),"production"===process.env.NODE_ENV||Object.freeze([]);const o=Object.assign,a=Object.prototype.hasOwnProperty,c=(e,t)=>a.call(e,t),l=Array.isArray,h=e=>"[object Map]"===p(e),f=e=>"symbol"==typeof e,u=e=>null!==e&&"object"==typeof e,d=Object.prototype.toString,p=e=>d.call(e),w=e=>p(e).slice(8,-1),v=e=>"string"==typeof e&&"NaN"!==e&&"-"!==e[0]&&""+parseInt(e,10)===e,y=(e=>{const t=Object.create(null);return e=>t[e]||(t[e]=(e=>e.charAt(0).toUpperCase()+e.slice(1))(e))})(),g=(e,t)=>!Object.is(e,t),m=e=>{const t=parseFloat(e);return isNaN(t)?e:t};function E(e,...t){console.warn(`[Vue warn] ${e}`,...t)}let b;function _(e,t=b){t&&t.active&&t.effects.push(e)}const S=e=>{const t=new Set(e);return t.w=0,t.n=0,t},k=e=>(e.w&$)>0,O=e=>(e.n&$)>0,N=new WeakMap;let A=0,$=1;const R=30;let j;const M=Symbol("production"!==process.env.NODE_ENV?"iterate":""),x=Symbol("production"!==process.env.NODE_ENV?"Map key iterate":"");class P{constructor(e,t=null,n){this.fn=e,this.scheduler=t,this.active=!0,this.deps=[],this.parent=void 0,_(this,n)}run(){if(!this.active)return this.fn();let e=j,t=L;for(;e;){if(e===this)return;e=e.parent}try{return this.parent=j,j=this,L=!0,$=1<<++A,A<=R?(({deps:e})=>{if(e.length)for(let t=0;t<e.length;t++)e[t].w|=$})(this):W(this),this.fn()}finally{A<=R&&(e=>{const{deps:t}=e;if(t.length){let n=0;for(let s=0;s<t.length;s++){const r=t[s];k(r)&&!O(r)?r.delete(e):t[n++]=r,r.w&=~$,r.n&=~$}t.length=n}})(this),$=1<<--A,j=this.parent,L=t,this.parent=void 0,this.deferStop&&this.stop()}}stop(){j===this?this.deferStop=!0:this.active&&(W(this),this.onStop&&this.onStop(),this.active=!1)}}function W(e){const{deps:t}=e;if(t.length){for(let n=0;n<t.length;n++)t[n].delete(e);t.length=0}}let L=!0;const B=[];function T(e,t,n){if(L&&j){let s=N.get(e);s||N.set(e,s=new Map);let r=s.get(n);r||s.set(n,r=S()),function(e,t){let n=!1;A<=R?O(e)||(e.n|=$,n=!k(e)):n=!e.has(j),n&&(e.add(j),j.deps.push(e),"production"!==process.env.NODE_ENV&&j.onTrack&&j.onTrack(Object.assign({effect:j},t)))}(r,"production"!==process.env.NODE_ENV?{effect:j,target:e,type:t,key:n}:void 0)}}function z(e,t,n,s,r,i){const o=N.get(e);if(!o)return;let a=[];if("clear"===t)a=[...o.values()];else if("length"===n&&l(e)){const e=m(s);o.forEach(((t,n)=>{("length"===n||n>=e)&&a.push(t)}))}else switch(void 0!==n&&a.push(o.get(n)),t){case"add":l(e)?v(n)&&a.push(o.get("length")):(a.push(o.get(M)),h(e)&&a.push(o.get(x)));break;case"delete":l(e)||(a.push(o.get(M)),h(e)&&a.push(o.get(x)));break;case"set":h(e)&&a.push(o.get(M))}const c="production"!==process.env.NODE_ENV?{target:e,type:t,key:n,newValue:s,oldValue:r,oldTarget:i}:void 0;if(1===a.length)a[0]&&("production"!==process.env.NODE_ENV?V(a[0],c):V(a[0]));else{const e=[];for(const t of a)t&&e.push(...t);"production"!==process.env.NODE_ENV?V(S(e),c):V(S(e))}}function V(e,t){const n=l(e)?e:[...e];for(const e of n)e.computed&&U(e,t);for(const e of n)e.computed||U(e,t)}function U(e,t){(e!==j||e.allowRecurse)&&("production"!==process.env.NODE_ENV&&e.onTrigger&&e.onTrigger(o({effect:e},t)),e.scheduler?e.scheduler():e.run())}const D=function(e,t){const n=Object.create(null),s=e.split(",");for(let e=0;e<s.length;e++)n[s[e]]=!0;return t?e=>!!n[e.toLowerCase()]:e=>!!n[e]}("__proto__,__v_isRef,__isVue"),I=new Set(Object.getOwnPropertyNames(Symbol).filter((e=>"arguments"!==e&&"caller"!==e)).map((e=>Symbol[e])).filter(f)),C=H(),G=H(!0),F=function(){const e={};return["includes","indexOf","lastIndexOf"].forEach((t=>{e[t]=function(...e){const n=Se(this);for(let e=0,t=this.length;e<t;e++)T(n,"get",e+"");const s=n[t](...e);return-1===s||!1===s?n[t](...e.map(Se)):s}})),["push","pop","shift","unshift","splice"].forEach((t=>{e[t]=function(...e){B.push(L),L=!1;const n=Se(this)[t].apply(this,e);return function(){const e=B.pop();L=void 0===e||e}(),n}})),e}();function H(e=!1,t=!1){return function(n,s,r){if("__v_isReactive"===s)return!e;if("__v_isReadonly"===s)return e;if("__v_isShallow"===s)return t;if("__v_raw"===s&&r===(e?t?ge:ye:t?ve:we).get(n))return n;const i=l(n);if(!e&&i&&c(F,s))return Reflect.get(F,s,r);const o=Reflect.get(n,s,r);return(f(s)?I.has(s):D(s))?o:(e||T(n,"get",s),t?o:Ne(o)?i&&v(s)?o:o.value:u(o)?e?Ee(o):me(o):o)}}const J={get:C,set:function(e=!1){return function(t,n,s,r){let i=t[n];if(_e(i)&&Ne(i)&&!Ne(s))return!1;if(!e&&(function(e){return!(!e||!e.__v_isShallow)}(s)||_e(s)||(i=Se(i),s=Se(s)),!l(t)&&Ne(i)&&!Ne(s)))return i.value=s,!0;const o=l(t)&&v(n)?Number(n)<t.length:c(t,n),a=Reflect.set(t,n,s,r);return t===Se(r)&&(o?g(s,i)&&z(t,"set",n,s,i):z(t,"add",n,s)),a}}(),deleteProperty:function(e,t){const n=c(e,t),s=e[t],r=Reflect.deleteProperty(e,t);return r&&n&&z(e,"delete",t,void 0,s),r},has:function(e,t){const n=Reflect.has(e,t);return f(t)&&I.has(t)||T(e,"has",t),n},ownKeys:function(e){return T(e,"iterate",l(e)?"length":M),Reflect.ownKeys(e)}},K={get:G,set:(e,t)=>("production"!==process.env.NODE_ENV&&E(`Set operation on key "${String(t)}" failed: target is readonly.`,e),!0),deleteProperty:(e,t)=>("production"!==process.env.NODE_ENV&&E(`Delete operation on key "${String(t)}" failed: target is readonly.`,e),!0)},q=e=>e,Q=e=>Reflect.getPrototypeOf(e);function X(e,t,n=!1,s=!1){const r=Se(e=e.__v_raw),i=Se(t);n||(t!==i&&T(r,"get",t),T(r,"get",i));const{has:o}=Q(r),a=s?q:n?Oe:ke;return o.call(r,t)?a(e.get(t)):o.call(r,i)?a(e.get(i)):void(e!==r&&e.get(t))}function Y(e,t=!1){const n=this.__v_raw,s=Se(n),r=Se(e);return t||(e!==r&&T(s,"has",e),T(s,"has",r)),e===r?n.has(e):n.has(e)||n.has(r)}function Z(e,t=!1){return e=e.__v_raw,!t&&T(Se(e),"iterate",M),Reflect.get(e,"size",e)}function ee(e){e=Se(e);const t=Se(this);return Q(t).has.call(t,e)||(t.add(e),z(t,"add",e,e)),this}function te(e,t){t=Se(t);const n=Se(this),{has:s,get:r}=Q(n);let i=s.call(n,e);i?"production"!==process.env.NODE_ENV&&pe(n,s,e):(e=Se(e),i=s.call(n,e));const o=r.call(n,e);return n.set(e,t),i?g(t,o)&&z(n,"set",e,t,o):z(n,"add",e,t),this}function ne(e){const t=Se(this),{has:n,get:s}=Q(t);let r=n.call(t,e);r?"production"!==process.env.NODE_ENV&&pe(t,n,e):(e=Se(e),r=n.call(t,e));const i=s?s.call(t,e):void 0,o=t.delete(e);return r&&z(t,"delete",e,void 0,i),o}function se(){const e=Se(this),t=0!==e.size,n="production"!==process.env.NODE_ENV?h(e)?new Map(e):new Set(e):void 0,s=e.clear();return t&&z(e,"clear",void 0,void 0,n),s}function re(e,t){return function(n,s){const r=this,i=r.__v_raw,o=Se(i),a=t?q:e?Oe:ke;return!e&&T(o,"iterate",M),i.forEach(((e,t)=>n.call(s,a(e),a(t),r)))}}function ie(e,t,n){return function(...s){const r=this.__v_raw,i=Se(r),o=h(i),a="entries"===e||e===Symbol.iterator&&o,c="keys"===e&&o,l=r[e](...s),f=n?q:t?Oe:ke;return!t&&T(i,"iterate",c?x:M),{next(){const{value:e,done:t}=l.next();return t?{value:e,done:t}:{value:a?[f(e[0]),f(e[1])]:f(e),done:t}},[Symbol.iterator](){return this}}}}function oe(e){return function(...t){if("production"!==process.env.NODE_ENV){const n=t[0]?`on key "${t[0]}" `:"";console.warn(`${y(e)} operation ${n}failed: target is readonly.`,Se(this))}return"delete"!==e&&this}}const[ae,ce,le,he]=function(){const e={get(e){return X(this,e)},get size(){return Z(this)},has:Y,add:ee,set:te,delete:ne,clear:se,forEach:re(!1,!1)},t={get(e){return X(this,e,!1,!0)},get size(){return Z(this)},has:Y,add:ee,set:te,delete:ne,clear:se,forEach:re(!1,!0)},n={get(e){return X(this,e,!0)},get size(){return Z(this,!0)},has(e){return Y.call(this,e,!0)},add:oe("add"),set:oe("set"),delete:oe("delete"),clear:oe("clear"),forEach:re(!0,!1)},s={get(e){return X(this,e,!0,!0)},get size(){return Z(this,!0)},has(e){return Y.call(this,e,!0)},add:oe("add"),set:oe("set"),delete:oe("delete"),clear:oe("clear"),forEach:re(!0,!0)};return["keys","values","entries",Symbol.iterator].forEach((r=>{e[r]=ie(r,!1,!1),n[r]=ie(r,!0,!1),t[r]=ie(r,!1,!0),s[r]=ie(r,!0,!0)})),[e,n,t,s]}();function fe(e,t){const n=t?e?he:le:e?ce:ae;return(t,s,r)=>"__v_isReactive"===s?!e:"__v_isReadonly"===s?e:"__v_raw"===s?t:Reflect.get(c(n,s)&&s in t?n:t,s,r)}const ue={get:fe(!1,!1)},de={get:fe(!0,!1)};function pe(e,t,n){const s=Se(n);if(s!==n&&t.call(e,s)){const t=w(e);console.warn(`Reactive ${t} contains both the raw and reactive versions of the same object${"Map"===t?" as keys":""}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`)}}const we=new WeakMap,ve=new WeakMap,ye=new WeakMap,ge=new WeakMap;function me(e){return _e(e)?e:be(e,!1,J,ue,we)}function Ee(e){return be(e,!0,K,de,ye)}function be(e,t,n,s,r){if(!u(e))return"production"!==process.env.NODE_ENV&&console.warn(`value cannot be made reactive: ${String(e)}`),e;if(e.__v_raw&&(!t||!e.__v_isReactive))return e;const i=r.get(e);if(i)return i;const o=(a=e).__v_skip||!Object.isExtensible(a)?0:function(e){switch(e){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(w(a));var a;if(0===o)return e;const c=new Proxy(e,2===o?s:n);return r.set(e,c),c}function _e(e){return!(!e||!e.__v_isReadonly)}function Se(e){const t=e&&e.__v_raw;return t?Se(t):e}const ke=e=>u(e)?me(e):e,Oe=e=>u(e)?Ee(e):e;function Ne(e){return!(!e||!0!==e.__v_isRef)}const Ae=e=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${e}, but ${e} hasn't been registed as a broadcast event`,$e=e=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${e}, but the listener hasn't been registed`,Re=e=>`[@rallie/core] one of the callbacks of the broadcast event ${e} throws an uncaught error`,je=e=>`[@rallie/core] you are trying to remove a listener of the unicast event ${e}, but ${e} hasn't been registed as a unicast event`,Me=e=>`[@rallie/core] you are trying to register a unicast event ${e}, but it has been registered before`,xe=e=>`[@rallie/core] you have emitted ${e} unicast, but there is no listener of this event`,Pe=e=>`[@rallie/core] ${e} is existing, you are not allowed to create it again`,We=(e,t)=>`[@rallie/core] can not find any assets of the app ${e} on the bus ${t}`,Le=e=>`[@rallie/core] you are trying to activate app ${e}, but it was not created`,Be=e=>`[@rallie/core] state ${e} is private, you are not allowed to set it`,Te=e=>`[@rallie/core] please describe your action when you modify the state ${e}`,ze=e=>`[@rallie/core] it's not allowed to set or watch state ${e} before it is initialized`,Ve=e=>`[@rallie/core] duplicated initialized state ${e}`,Ue=e=>`[@rallie/core] it's not allowed to initialized state ${e} to a primitive value`,De=e=>`[@rallie/core] the bus named ${e} has been defined before, please rename your bus`,Ie=(e,t)=>`[@rallie/core] There is a circular dependency when activating the app ${e}, and the circular path is ${t.join("->")}`,Ce=()=>"[@rallie/core] next() called multiple times in the middleware",Ge=()=>"[@rallie/core] the middleware must be a function",Fe=(e,t)=>`[@rallie/core] the event ${e} is not in the events pool that you specified when calling on${t?"Unicast":"Broadcast"}`,He=e=>(t,n)=>{let s=-1;const r=i=>{if(i<=s)return Promise.reject(new Error(Ce()));s=i;let o=e[i];if(i===e.length&&(o=n),!o)return Promise.resolve();try{return Promise.resolve(o(t,r.bind(null,i+1)))}catch(e){return Promise.reject(e)}};return r(0)};var Je,Ke,qe,Qe,Xe,Ye,Ze,et,tt;class nt{constructor(){Je.set(this,{}),Ke.set(this,{})}addBroadcastEventListener(e,t){r(this,Je,"f")[e]=r(this,Je,"f")[e]||new Set,r(this,Je,"f")[e].add(t)}addUnicastEventListener(e,t){if(r(this,Ke,"f")[e])throw new Error(Me(e));r(this,Ke,"f")[e]=t}removeBroadcastEventListener(e,t){const n=r(this,Je,"f")[e];if(!n){const t=Ae(e);throw new Error(t)}if(!n.has(t)){const t=$e(e);throw new Error(t)}n.delete(t)}removeUnicastEventListener(e){if(!r(this,Ke,"f")[e]){const t=je(e);throw new Error(t)}delete r(this,Ke,"f")[e]}emitBroadcast(e,...t){r(this,Je,"f")[e]=r(this,Je,"f")[e]||new Set,r(this,Je,"f")[e].forEach((n=>{try{n(...t)}catch(n){console.error(Re(e)),console.error(n)}}))}emitUnicast(e,...t){const n=r(this,Ke,"f")[e];if(n)return n(...t);throw new Error(xe(e))}}Je=new WeakMap,Ke=new WeakMap;class st{constructor(e,t){qe.set(this,void 0),Qe.set(this,void 0),i(this,qe,e,"f"),i(this,Qe,t,"f"),r(this,Qe,"f")[e].watchers.add(this)}do(e){return this.handler=e,()=>this.unwatch()}unwatch(){null==this||this.stopEffect(),this.handler=null;const e=r(this,Qe,"f")[r(this,qe,"f")].watchers;e.has(this)&&e.delete(this)}}qe=new WeakMap,Qe=new WeakMap;class rt{constructor(e,t){Xe.add(this),Ye.set(this,void 0),Ze.set(this,void 0),i(this,Ye,e,"f"),i(this,Ze,t,"f")}onBroadcast(e){return Object.entries(e).forEach((([e,t])=>{r(this,Ye,"f").addBroadcastEventListener(e,t)})),t=>{r(this,Xe,"m",et).call(this,e,!1,t)}}onUnicast(e){return Object.entries(e).forEach((([e,t])=>{try{r(this,Ye,"f").addUnicastEventListener(e,t)}catch(e){console.error(e)}})),t=>{r(this,Xe,"m",et).call(this,e,!0,t)}}createBroadcaster(e){return new Proxy({},{get:(t,n)=>(...t)=>(null==e||e(n),r(this,Ye,"f").emitBroadcast(n,...t)),set:()=>!1})}createUnicaster(e){return new Proxy({},{get:(t,n)=>(...t)=>(null==e||e(n),r(this,Ye,"f").emitUnicast(n,...t)),set:()=>!1})}existState(e){return!!r(this,Ze,"f")[e]}initState(e,t,n=!1){if(this.existState(e))throw new Error(Ve(e));if(["string","number","boolean","undefined"].includes(typeof t))throw new Error(Ue(e));return r(this,Ze,"f")[e]={state:me(t),owner:n?this:null,watchers:new Set},r(this,Ye,"f").emitBroadcast("$state-initialized",e),this.getState(e)}getState(e,t){if(this.existState(e)){const n=Ee(r(this,Ze,"f")[e].state);return t?t(n):n}return null}setState(e,t,n){return s(this,void 0,void 0,(function*(){const s=r(this,Xe,"m",tt).call(this,e);if(!t)throw new Error(Te(e));{const e=n(s);yield Promise.resolve(e)}}))}watchState(e,t){if(!this.existState(e)){const t=ze(e);throw new Error(t)}let n=!1;const s=Ee(r(this,Ze,"f")[e].state),i=new st(e,r(this,Ze,"f")),a=function(e,t){e.effect&&(e=e.effect.fn);const n=new P(e);t&&(o(n,t),t.scope&&_(n,t.scope)),t&&t.lazy||n.run();const s=n.run.bind(n);return s.effect=n,s}((()=>t(s)),{lazy:!0,scheduler:()=>{n||(n=!0,Promise.resolve().then((()=>{var e;const r=Se(t(s));null===(e=i.handler)||void 0===e||e.call(i,r,i.oldWatchingStates),i.oldWatchingStates=Se(r),n=!1})))}});return i.oldWatchingStates=a(),i.stopEffect=()=>a.effect.stop(),i}}Ye=new WeakMap,Ze=new WeakMap,Xe=new WeakSet,et=function(e,t,n){let s=t?r(this,Ye,"f").removeUnicastEventListener:r(this,Ye,"f").removeBroadcastEventListener;s=s.bind(r(this,Ye,"f")),n?e[n]?(s(n,e[n]),delete e[n]):console.warn(Fe(n,t)):Object.entries(e).forEach((([e,t])=>{s(e,t)}))},tt=function(e){if(!this.existState(e)){const t=ze(e);throw new Error(t)}const t=r(this,Ze,"f")[e].owner;if(t!==this&&null!==t){const t=Be(e);throw new Error(t)}return r(this,Ze,"f")[e].state};class it{constructor(e){this.name=e,this.activated=null,this.dependencies=[],this.relatedApps=[],this.name=e,this.isRallieCoreApp=!0}relateTo(e){return this.relatedApps=Array.from(new Set([...this.relatedApps,...e])),this}relyOn(e){return this.relateTo(e),this.dependencies=Array.from(new Set([...this.dependencies,...e])),this}onActivate(e){return this.doActivate=e,this}}var ot,at,ct,lt,ht,ft,ut,dt,pt,wt,vt,yt,gt,mt,Et={loadScript:e=>s(void 0,void 0,void 0,(function*(){return new Promise((t=>{let n=null;if(e instanceof HTMLScriptElement)n=e;else{n=document.createElement("script");const t="string"!=typeof e?e:{type:"text/javascript",src:e};Object.entries(t).forEach((([e,t])=>{n.setAttribute(e,t)}))}n.src&&(n.onload=n.onerror=()=>{t()}),document.body.appendChild(n),n.src||t()}))})),loadLink:e=>{let t=null;if(e instanceof HTMLLinkElement)t=e;else{const n="string"!=typeof e?e:{rel:"stylesheet",type:"text/css",href:e};t=document.createElement("link"),Object.entries(n).forEach((([e,n])=>{t.setAttribute(e,n)}))}document.head.appendChild(t)}};class bt{constructor(e){ot.add(this),at.set(this,void 0),ct.set(this,new nt),lt.set(this,{}),ht.set(this,{}),ft.set(this,{}),this.conf=Ee({assets:{}}),ut.set(this,[]),dt.set(this,void 0),i(this,at,e,"f"),i(this,dt,He(r(this,ut,"f")),"f")}createSocket(){return new rt(r(this,ct,"f"),r(this,lt,"f"))}existApp(e){return!!r(this,ht,"f")[e]}createApp(e){if(this.existApp(e))throw new Error(Pe(e));const t=new it(e);return r(this,ht,"f")[e]=t,t}loadApp(e){return s(this,void 0,void 0,(function*(){r(this,ht,"f")[e]||(r(this,ft,"f")[e]||(r(this,ft,"f")[e]=new Promise(((t,n)=>{const s=r(this,ot,"m",wt).call(this,e);r(this,dt,"f").call(this,s,r(this,ot,"m",vt).bind(this)).then((()=>{e.startsWith("lib:")&&!r(this,ht,"f")[e]&&(r(this,ht,"f")[e]=!0),r(this,ht,"f")[e]||n(new Error(Le(e))),t()})).catch((e=>{n(e)}))}))),yield r(this,ft,"f")[e])}))}activateApp(e){return s(this,void 0,void 0,(function*(){yield r(this,ot,"m",yt).call(this,e,[])}))}config(e){return this.conf=Object.assign(Object.assign(Object.assign({},this.conf),e),{assets:Object.assign(Object.assign({},this.conf.assets),(null==e?void 0:e.assets)||{})}),this}use(e){if("function"!=typeof e)throw new Error(Ge());return r(this,ut,"f").push(e),i(this,dt,He(r(this,ut,"f")),"f"),this}}at=new WeakMap,ct=new WeakMap,lt=new WeakMap,ht=new WeakMap,ft=new WeakMap,ut=new WeakMap,dt=new WeakMap,ot=new WeakSet,pt=function(e){return r(this,ht,"f")[e]&&"boolean"!=typeof r(this,ht,"f")[e]},wt=function(e){return{name:e,loadScript:Et.loadScript,loadLink:Et.loadLink}},vt=function(e){return s(this,void 0,void 0,(function*(){const{name:t,loadScript:n=Et.loadScript,loadLink:s=Et.loadLink}=e,{assets:i}=this.conf;if(!i[t])throw new Error(We(t,r(this,at,"f")));if(i[t].css&&i[t].css.forEach((e=>{s(e)})),i[t].js)for(const e of i[t].js)yield n(e)}))},yt=function(e,t){return s(this,void 0,void 0,(function*(){if(yield this.loadApp(e),r(this,ot,"m",pt).call(this,e)){const n=r(this,ht,"f")[e];if(yield r(this,ot,"m",mt).call(this,n),t.includes(e)){const n=t.indexOf(e),s=[...t.slice(n),e];throw new Error(Ie(e,s))}if(t.push(e),!n.activated){const e=()=>s(this,void 0,void 0,(function*(){yield r(this,ot,"m",gt).call(this,n,t),n.doActivate&&(yield Promise.resolve(n.doActivate()))}));n.activated=e()}yield n.activated,t.pop()}}))},gt=function(e,t){return s(this,void 0,void 0,(function*(){if(0!==e.dependencies.length)for(const n of e.dependencies)yield r(this,ot,"m",yt).call(this,n,t)}))},mt=function(e){return s(this,void 0,void 0,(function*(){yield Promise.all(e.relatedApps.map((e=>this.loadApp(e))))}))};const _t={},St="DEFAULT_BUS",kt=(e=St)=>{let t=null,n=!1;const s=((e=St)=>window.RALLIE_BUS_STORE&&window.RALLIE_BUS_STORE[e])(e);return s?(t=s,n=!1):(t=((e=St)=>{if(void 0===window.RALLIE_BUS_STORE&&Reflect.defineProperty(window,"RALLIE_BUS_STORE",{value:_t,writable:!1}),window.RALLIE_BUS_STORE[e])throw new Error(De(e));{const t=new bt(e);return Reflect.defineProperty(window.RALLIE_BUS_STORE,e,{value:t,writable:!1}),t}})(e),n=!0),[t,n]},Ot={privateBus:e=>`${e}.bus`,stateNamespace:e=>`${e}.state`,isGlobalBusAccessible:"isGlobalBusAccessible",exportMethodName:"__RallieInnerExport__"},Nt=e=>`[rallie] ${e}`,At={stateNotInitialized:e=>Nt(` the block ${e}'s state is not initialized, please check:\n1. whether the block ${e} is loaded.\n2. whether the block ${e} has initialized the state`),duplicatedBlockName:e=>Nt(`the block ${e} is already registered before, please rename your block`),stateIsReadonly:e=>Nt(`the state of ${e} is readonly`)},$t=(e,t)=>new Proxy(e,{get:(e,n)=>(...s)=>(0,e[n])(s,t),set:()=>!1}),Rt=e=>{const t={};return Object.entries(e).forEach((([e,n])=>{t[e]=(e,t)=>n.call({trigger:t},...e)})),t};var jt,Mt,xt,Pt,Wt,Lt,Bt;class Tt{constructor(e,s,r){jt.set(this,void 0),this.name=e,n(this,jt,r,"f");const i=t(this,jt,"f").createBroadcaster(),o=t(this,jt,"f").createUnicaster();this.events=$t(i,s),this.methods=$t(o,s),Reflect.defineProperty(this,"state",{get:()=>t(this,jt,"f").getState(Ot.stateNamespace(this.name)),set:()=>{throw new Error(At.stateIsReadonly(this.name))}})}setState(e,n){if(t(this,jt,"f").existState(Ot.stateNamespace(this.name)))return t(this,jt,"f").setState(Ot.stateNamespace(this.name),e,n);throw new Error(At.stateNotInitialized(this.name))}watchState(e){if(t(this,jt,"f").existState(Ot.stateNamespace(this.name)))return t(this,jt,"f").watchState(Ot.stateNamespace(this.name),e);throw new Error(At.stateNotInitialized(this.name))}listenEvents(e){return t(this,jt,"f").onBroadcast(Rt(e))}}jt=new WeakMap;class zt extends Tt{constructor(e,t,s,r){const[i]=kt(Ot.privateBus(e)),o=i.createSocket();super(e,e,o),Mt.set(this,void 0),xt.set(this,void 0),Pt.set(this,void 0),Wt.set(this,void 0),Lt.set(this,void 0),Bt.set(this,{}),n(this,Wt,o,"f"),n(this,Mt,t,"f"),n(this,xt,s,"f"),n(this,Lt,t.createApp(e),"f"),n(this,Pt,r,"f")}initState(e,n){return t(this,Wt,"f").initState(Ot.stateNamespace(this.name),e,n),this}addMethods(e){return t(this,Wt,"f").onUnicast(Rt(e))}relyOn(e){return t(this,Lt,"f").relyOn(e),this}relateTo(e){return t(this,Lt,"f").relateTo(e),this}onActivate(e){return t(this,Lt,"f").onActivate(e),this}connect(e){if(!t(this,Bt,"f")[e]){const[n]=kt(Ot.privateBus(e)),s=n.createSocket();t(this,Bt,"f")[e]=new Tt(e,this.name,s)}return t(this,Bt,"f")[e]}load(e){return t(this,Mt,"f").loadApp(e)}activate(e){return t(this,Mt,"f").activateApp(e)}run(n){var s;return e(this,void 0,void 0,(function*(){const e=t(this,Pt,"f")||(null===(s=t(this,xt,"f").getState(Ot.isGlobalBusAccessible))||void 0===s?void 0:s.value),r=e=>{t(this,Pt,"f")&&t(this,xt,"f").setState(Ot.isGlobalBusAccessible,e?"unfreeze the enviroment":"freeze the enviroment",(t=>{t.value=e}))},i={isEntry:t(this,Pt,"f"),use:n=>{e&&t(this,Mt,"f").use(n)},config:n=>{e&&t(this,Mt,"f").config(n)},freeze:()=>{r(!1)},unfreeze:()=>{r(!0)}},o=n(new Proxy(i,{get:(e,n,s)=>"conf"===n?JSON.parse(JSON.stringify(t(this,Mt,"f").conf)):Reflect.get(e,n,s),set:()=>!1}));yield Promise.resolve(o)}))}}function Vt(e){const[t,n]=kt();if(t.existApp(e))throw new Error(At.duplicatedBlockName(e));const s=t.createSocket();return n&&s.initState(Ot.isGlobalBusAccessible,{value:!0},!0),new zt(e,t,s,n)}Mt=new WeakMap,xt=new WeakMap,Pt=new WeakMap,Wt=new WeakMap,Lt=new WeakMap,Bt=new WeakMap;export{Vt as createBlock}; | ||
function t(t,e,n,s){return new(n||(n=Promise))((function(i,r){function o(t){try{c(s.next(t))}catch(t){r(t)}}function a(t){try{c(s.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((s=s.apply(t,e||[])).next())}))}function e(t,e,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(t):s?s.value:e.get(t)}function n(t,e,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(t,n):i?i.value=n:e.set(t,n),n}function s(t,e,n,s){return new(n||(n=Promise))((function(i,r){function o(t){try{c(s.next(t))}catch(t){r(t)}}function a(t){try{c(s.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((s=s.apply(t,e||[])).next())}))}function i(t,e,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(t):s?s.value:e.get(t)}function r(t,e,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(t,n):i?i.value=n:e.set(t,n),n}const o=Object.assign,a=Object.prototype.hasOwnProperty,c=(t,e)=>a.call(t,e),h=Array.isArray,l=t=>"[object Map]"===p(t),f=t=>"symbol"==typeof t,u=t=>null!==t&&"object"==typeof t,d=Object.prototype.toString,p=t=>d.call(t),w=t=>p(t).slice(8,-1),v=t=>"string"==typeof t&&"NaN"!==t&&"-"!==t[0]&&""+parseInt(t,10)===t,y=(t,e)=>!Object.is(t,e),m=t=>{const e=parseFloat(t);return isNaN(e)?t:e};let g;function b(t,e=g){e&&e.active&&e.effects.push(t)}const _=t=>{const e=new Set(t);return e.w=0,e.n=0,e},E=t=>(t.w&R)>0,S=t=>(t.n&R)>0,k=new WeakMap;let A=0,R=1;const O=30;let x;const M=Symbol(""),P=Symbol("");class W{constructor(t,e=null,n){this.fn=t,this.scheduler=e,this.active=!0,this.deps=[],this.parent=void 0,b(this,n)}run(){if(!this.active)return this.fn();let t=x,e=$;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=x,x=this,$=!0,R=1<<++A,A<=O?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=R})(this):j(this),this.fn()}finally{A<=O&&(t=>{const{deps:e}=t;if(e.length){let n=0;for(let s=0;s<e.length;s++){const i=e[s];E(i)&&!S(i)?i.delete(t):e[n++]=i,i.w&=~R,i.n&=~R}e.length=n}})(this),R=1<<--A,x=this.parent,$=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){x===this?this.deferStop=!0:this.active&&(j(this),this.onStop&&this.onStop(),this.active=!1)}}function j(t){const{deps:e}=t;if(e.length){for(let n=0;n<e.length;n++)e[n].delete(t);e.length=0}}let $=!0;const L=[];function B(t,e,n){if($&&x){let e=k.get(t);e||k.set(t,e=new Map);let s=e.get(n);s||e.set(n,s=_()),function(t,e){let n=!1;A<=O?S(t)||(t.n|=R,n=!E(t)):n=!t.has(x),n&&(t.add(x),x.deps.push(t))}(s)}}function T(t,e,n,s,i,r){const o=k.get(t);if(!o)return;let a=[];if("clear"===e)a=[...o.values()];else if("length"===n&&h(t)){const t=m(s);o.forEach(((e,n)=>{("length"===n||n>=t)&&a.push(e)}))}else switch(void 0!==n&&a.push(o.get(n)),e){case"add":h(t)?v(n)&&a.push(o.get("length")):(a.push(o.get(M)),l(t)&&a.push(o.get(P)));break;case"delete":h(t)||(a.push(o.get(M)),l(t)&&a.push(o.get(P)));break;case"set":l(t)&&a.push(o.get(M))}if(1===a.length)a[0]&&z(a[0]);else{const t=[];for(const e of a)e&&t.push(...e);z(_(t))}}function z(t,e){const n=h(t)?t:[...t];for(const t of n)t.computed&&N(t);for(const t of n)t.computed||N(t)}function N(t,e){(t!==x||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}const U=function(t,e){const n=Object.create(null),s=t.split(",");for(let t=0;t<s.length;t++)n[s[t]]=!0;return e?t=>!!n[t.toLowerCase()]:t=>!!n[t]}("__proto__,__v_isRef,__isVue"),I=new Set(Object.getOwnPropertyNames(Symbol).filter((t=>"arguments"!==t&&"caller"!==t)).map((t=>Symbol[t])).filter(f)),C=H(),G=H(!0),F=function(){const t={};return["includes","indexOf","lastIndexOf"].forEach((e=>{t[e]=function(...t){const n=bt(this);for(let t=0,e=this.length;t<e;t++)B(n,0,t+"");const s=n[e](...t);return-1===s||!1===s?n[e](...t.map(bt)):s}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){L.push($),$=!1;const n=bt(this)[e].apply(this,t);return function(){const t=L.pop();$=void 0===t||t}(),n}})),t}();function H(t=!1,e=!1){return function(n,s,i){if("__v_isReactive"===s)return!t;if("__v_isReadonly"===s)return t;if("__v_isShallow"===s)return e;if("__v_raw"===s&&i===(t?e?wt:pt:e?dt:ut).get(n))return n;const r=h(n);if(!t&&r&&c(F,s))return Reflect.get(F,s,i);const o=Reflect.get(n,s,i);return(f(s)?I.has(s):U(s))?o:(t||B(n,0,s),e?o:St(o)?r&&v(s)?o:o.value:u(o)?t?yt(o):vt(o):o)}}const J={get:C,set:function(t=!1){return function(e,n,s,i){let r=e[n];if(gt(r)&&St(r)&&!St(s))return!1;if(!t&&(function(t){return!(!t||!t.__v_isShallow)}(s)||gt(s)||(r=bt(r),s=bt(s)),!h(e)&&St(r)&&!St(s)))return r.value=s,!0;const o=h(e)&&v(n)?Number(n)<e.length:c(e,n),a=Reflect.set(e,n,s,i);return e===bt(i)&&(o?y(s,r)&&T(e,"set",n,s):T(e,"add",n,s)),a}}(),deleteProperty:function(t,e){const n=c(t,e);t[e];const s=Reflect.deleteProperty(t,e);return s&&n&&T(t,"delete",e,void 0),s},has:function(t,e){const n=Reflect.has(t,e);return f(e)&&I.has(e)||B(t,0,e),n},ownKeys:function(t){return B(t,0,h(t)?"length":M),Reflect.ownKeys(t)}},K={get:G,set:(t,e)=>!0,deleteProperty:(t,e)=>!0},D=t=>t,V=t=>Reflect.getPrototypeOf(t);function q(t,e,n=!1,s=!1){const i=bt(t=t.__v_raw),r=bt(e);n||(e!==r&&B(i,0,e),B(i,0,r));const{has:o}=V(i),a=s?D:n?Et:_t;return o.call(i,e)?a(t.get(e)):o.call(i,r)?a(t.get(r)):void(t!==i&&t.get(e))}function Q(t,e=!1){const n=this.__v_raw,s=bt(n),i=bt(t);return e||(t!==i&&B(s,0,t),B(s,0,i)),t===i?n.has(t):n.has(t)||n.has(i)}function X(t,e=!1){return t=t.__v_raw,!e&&B(bt(t),0,M),Reflect.get(t,"size",t)}function Y(t){t=bt(t);const e=bt(this);return V(e).has.call(e,t)||(e.add(t),T(e,"add",t,t)),this}function Z(t,e){e=bt(e);const n=bt(this),{has:s,get:i}=V(n);let r=s.call(n,t);r||(t=bt(t),r=s.call(n,t));const o=i.call(n,t);return n.set(t,e),r?y(e,o)&&T(n,"set",t,e):T(n,"add",t,e),this}function tt(t){const e=bt(this),{has:n,get:s}=V(e);let i=n.call(e,t);i||(t=bt(t),i=n.call(e,t)),s&&s.call(e,t);const r=e.delete(t);return i&&T(e,"delete",t,void 0),r}function et(){const t=bt(this),e=0!==t.size,n=t.clear();return e&&T(t,"clear",void 0,void 0),n}function nt(t,e){return function(n,s){const i=this,r=i.__v_raw,o=bt(r),a=e?D:t?Et:_t;return!t&&B(o,0,M),r.forEach(((t,e)=>n.call(s,a(t),a(e),i)))}}function st(t,e,n){return function(...s){const i=this.__v_raw,r=bt(i),o=l(r),a="entries"===t||t===Symbol.iterator&&o,c="keys"===t&&o,h=i[t](...s),f=n?D:e?Et:_t;return!e&&B(r,0,c?P:M),{next(){const{value:t,done:e}=h.next();return e?{value:t,done:e}:{value:a?[f(t[0]),f(t[1])]:f(t),done:e}},[Symbol.iterator](){return this}}}}function it(t){return function(...e){return"delete"!==t&&this}}const[rt,ot,at,ct]=function(){const t={get(t){return q(this,t)},get size(){return X(this)},has:Q,add:Y,set:Z,delete:tt,clear:et,forEach:nt(!1,!1)},e={get(t){return q(this,t,!1,!0)},get size(){return X(this)},has:Q,add:Y,set:Z,delete:tt,clear:et,forEach:nt(!1,!0)},n={get(t){return q(this,t,!0)},get size(){return X(this,!0)},has(t){return Q.call(this,t,!0)},add:it("add"),set:it("set"),delete:it("delete"),clear:it("clear"),forEach:nt(!0,!1)},s={get(t){return q(this,t,!0,!0)},get size(){return X(this,!0)},has(t){return Q.call(this,t,!0)},add:it("add"),set:it("set"),delete:it("delete"),clear:it("clear"),forEach:nt(!0,!0)};return["keys","values","entries",Symbol.iterator].forEach((i=>{t[i]=st(i,!1,!1),n[i]=st(i,!0,!1),e[i]=st(i,!1,!0),s[i]=st(i,!0,!0)})),[t,n,e,s]}();function ht(t,e){const n=e?t?ct:at:t?ot:rt;return(e,s,i)=>"__v_isReactive"===s?!t:"__v_isReadonly"===s?t:"__v_raw"===s?e:Reflect.get(c(n,s)&&s in e?n:e,s,i)}const lt={get:ht(!1,!1)},ft={get:ht(!0,!1)},ut=new WeakMap,dt=new WeakMap,pt=new WeakMap,wt=new WeakMap;function vt(t){return gt(t)?t:mt(t,!1,J,lt,ut)}function yt(t){return mt(t,!0,K,ft,pt)}function mt(t,e,n,s,i){if(!u(t))return t;if(t.__v_raw&&(!e||!t.__v_isReactive))return t;const r=i.get(t);if(r)return r;const o=(a=t).__v_skip||!Object.isExtensible(a)?0:function(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(w(a));var a;if(0===o)return t;const c=new Proxy(t,2===o?s:n);return i.set(t,c),c}function gt(t){return!(!t||!t.__v_isReadonly)}function bt(t){const e=t&&t.__v_raw;return e?bt(e):t}const _t=t=>u(t)?vt(t):t,Et=t=>u(t)?yt(t):t;function St(t){return!(!t||!0!==t.__v_isRef)}const kt=t=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${t}, but ${t} hasn't been registed as a broadcast event`,At=t=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${t}, but the listener hasn't been registed`,Rt=t=>`[@rallie/core] one of the callbacks of the broadcast event ${t} throws an uncaught error`,Ot=t=>`[@rallie/core] you are trying to remove a listener of the unicast event ${t}, but ${t} hasn't been registed as a unicast event`,xt=t=>`[@rallie/core] you are trying to register a unicast event ${t}, but it has been registered before`,Mt=t=>`[@rallie/core] you have emitted ${t} unicast, but there is no listener of this event`,Pt=t=>`[@rallie/core] ${t} is existing, you are not allowed to create it again`,Wt=(t,e)=>`[@rallie/core] can not find any assets of the app ${t} on the bus ${e}`,jt=t=>`[@rallie/core] you are trying to activate app ${t}, but it was not created`,$t=t=>`[@rallie/core] state ${t} is private, you are not allowed to set it`,Lt=t=>`[@rallie/core] please describe your action when you modify the state ${t}`,Bt=t=>`[@rallie/core] it's not allowed to set or watch state ${t} before it is initialized`,Tt=t=>`[@rallie/core] duplicated initialized state ${t}`,zt=t=>`[@rallie/core] it's not allowed to initialized state ${t} to a primitive value`,Nt=t=>`[@rallie/core] the bus named ${t} has been defined before, please rename your bus`,Ut=(t,e)=>`[@rallie/core] There is a circular dependency when activating the app ${t}, and the circular path is ${e.join("->")}`,It=()=>"[@rallie/core] next() called multiple times in the middleware",Ct=()=>"[@rallie/core] the middleware must be a function",Gt=(t,e)=>`[@rallie/core] the event ${t} is not in the events pool that you specified when calling on${e?"Unicast":"Broadcast"}`,Ft=t=>(e,n)=>{let s=-1;const i=r=>{if(r<=s)return Promise.reject(new Error(It()));s=r;let o=t[r];if(r===t.length&&(o=n),!o)return Promise.resolve();try{return Promise.resolve(o(e,i.bind(null,r+1)))}catch(t){return Promise.reject(t)}};return i(0)};var Ht,Jt,Kt,Dt,Vt,qt,Qt,Xt,Yt;class Zt{constructor(){Ht.set(this,{}),Jt.set(this,{})}addBroadcastEventListener(t,e){i(this,Ht,"f")[t]=i(this,Ht,"f")[t]||new Set,i(this,Ht,"f")[t].add(e)}addUnicastEventListener(t,e){if(i(this,Jt,"f")[t])throw new Error(xt(t));i(this,Jt,"f")[t]=e}removeBroadcastEventListener(t,e){const n=i(this,Ht,"f")[t];if(!n){const e=kt(t);throw new Error(e)}if(!n.has(e)){const e=At(t);throw new Error(e)}n.delete(e)}removeUnicastEventListener(t){if(!i(this,Jt,"f")[t]){const e=Ot(t);throw new Error(e)}delete i(this,Jt,"f")[t]}emitBroadcast(t,...e){i(this,Ht,"f")[t]=i(this,Ht,"f")[t]||new Set,i(this,Ht,"f")[t].forEach((n=>{try{n(...e)}catch(n){console.error(Rt(t)),console.error(n)}}))}emitUnicast(t,...e){const n=i(this,Jt,"f")[t];if(n)return n(...e);throw new Error(Mt(t))}}Ht=new WeakMap,Jt=new WeakMap;class te{constructor(t,e){Kt.set(this,void 0),Dt.set(this,void 0),r(this,Kt,t,"f"),r(this,Dt,e,"f"),i(this,Dt,"f")[t].watchers.add(this)}do(t){return this.handler=t,()=>this.unwatch()}unwatch(){null==this||this.stopEffect(),this.handler=null;const t=i(this,Dt,"f")[i(this,Kt,"f")].watchers;t.has(this)&&t.delete(this)}}Kt=new WeakMap,Dt=new WeakMap;class ee{constructor(t,e){Vt.add(this),qt.set(this,void 0),Qt.set(this,void 0),r(this,qt,t,"f"),r(this,Qt,e,"f")}onBroadcast(t){return Object.entries(t).forEach((([t,e])=>{i(this,qt,"f").addBroadcastEventListener(t,e)})),e=>{i(this,Vt,"m",Xt).call(this,t,!1,e)}}onUnicast(t){return Object.entries(t).forEach((([t,e])=>{try{i(this,qt,"f").addUnicastEventListener(t,e)}catch(t){console.error(t)}})),e=>{i(this,Vt,"m",Xt).call(this,t,!0,e)}}createBroadcaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),i(this,qt,"f").emitBroadcast(n,...e)),set:()=>!1})}createUnicaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),i(this,qt,"f").emitUnicast(n,...e)),set:()=>!1})}existState(t){return!!i(this,Qt,"f")[t]}initState(t,e,n=!1){if(this.existState(t))throw new Error(Tt(t));if(["string","number","boolean","undefined"].includes(typeof e))throw new Error(zt(t));return i(this,Qt,"f")[t]={state:vt(e),owner:n?this:null,watchers:new Set},i(this,qt,"f").emitBroadcast("$state-initialized",t),this.getState(t)}getState(t,e){if(this.existState(t)){const n=yt(i(this,Qt,"f")[t].state);return e?e(n):n}return null}setState(t,e,n){return s(this,void 0,void 0,(function*(){const s=i(this,Vt,"m",Yt).call(this,t);if(!e)throw new Error(Lt(t));{const t=n(s);yield Promise.resolve(t)}}))}watchState(t,e){if(!this.existState(t)){const e=Bt(t);throw new Error(e)}let n=!1;const s=yt(i(this,Qt,"f")[t].state),r=new te(t,i(this,Qt,"f")),a=function(t,e){t.effect&&(t=t.effect.fn);const n=new W(t);e&&(o(n,e),e.scope&&b(n,e.scope)),e&&e.lazy||n.run();const s=n.run.bind(n);return s.effect=n,s}((()=>e(s)),{lazy:!0,scheduler:()=>{n||(n=!0,Promise.resolve().then((()=>{var t;const i=bt(e(s));null===(t=r.handler)||void 0===t||t.call(r,i,r.oldWatchingStates),r.oldWatchingStates=bt(i),n=!1})))}});return r.oldWatchingStates=a(),r.stopEffect=()=>a.effect.stop(),r}}qt=new WeakMap,Qt=new WeakMap,Vt=new WeakSet,Xt=function(t,e,n){let s=e?i(this,qt,"f").removeUnicastEventListener:i(this,qt,"f").removeBroadcastEventListener;s=s.bind(i(this,qt,"f")),n?t[n]?(s(n,t[n]),delete t[n]):console.warn(Gt(n,e)):Object.entries(t).forEach((([t,e])=>{s(t,e)}))},Yt=function(t){if(!this.existState(t)){const e=Bt(t);throw new Error(e)}const e=i(this,Qt,"f")[t].owner;if(e!==this&&null!==e){const e=$t(t);throw new Error(e)}return i(this,Qt,"f")[t].state};class ne{constructor(t){this.name=t,this.activated=null,this.dependencies=[],this.relatedApps=[],this.name=t,this.isRallieCoreApp=!0}relateTo(t){return this.relatedApps=Array.from(new Set([...this.relatedApps,...t])),this}relyOn(t){return this.relateTo(t),this.dependencies=Array.from(new Set([...this.dependencies,...t])),this}onActivate(t){return this.doActivate=t,this}}var se,ie,re,oe,ae,ce,he,le,fe,ue,de,pe,we,ve,ye={loadScript:t=>s(void 0,void 0,void 0,(function*(){return new Promise((e=>{let n=null;if(t instanceof HTMLScriptElement)n=t;else{n=document.createElement("script");const e="string"!=typeof t?t:{type:"text/javascript",src:t};Object.entries(e).forEach((([t,e])=>{n.setAttribute(t,e)}))}n.src&&(n.onload=n.onerror=()=>{e()}),document.body.appendChild(n),n.src||e()}))})),loadLink:t=>{let e=null;if(t instanceof HTMLLinkElement)e=t;else{const n="string"!=typeof t?t:{rel:"stylesheet",type:"text/css",href:t};e=document.createElement("link"),Object.entries(n).forEach((([t,n])=>{e.setAttribute(t,n)}))}document.head.appendChild(e)}};class me{constructor(t){se.add(this),ie.set(this,void 0),re.set(this,new Zt),oe.set(this,{}),ae.set(this,{}),ce.set(this,{}),this.conf=yt({assets:{}}),he.set(this,[]),le.set(this,void 0),r(this,ie,t,"f"),r(this,le,Ft(i(this,he,"f")),"f")}createSocket(){return new ee(i(this,re,"f"),i(this,oe,"f"))}existApp(t){return!!i(this,ae,"f")[t]}createApp(t){if(this.existApp(t))throw new Error(Pt(t));const e=new ne(t);return i(this,ae,"f")[t]=e,e}loadApp(t){return s(this,void 0,void 0,(function*(){i(this,ae,"f")[t]||(i(this,ce,"f")[t]||(i(this,ce,"f")[t]=new Promise(((e,n)=>{const s=i(this,se,"m",ue).call(this,t);i(this,le,"f").call(this,s,i(this,se,"m",de).bind(this)).then((()=>{t.startsWith("lib:")&&!i(this,ae,"f")[t]&&(i(this,ae,"f")[t]=!0),i(this,ae,"f")[t]||n(new Error(jt(t))),e()})).catch((t=>{n(t)}))}))),yield i(this,ce,"f")[t])}))}activateApp(t){return s(this,void 0,void 0,(function*(){yield i(this,se,"m",pe).call(this,t,[])}))}config(t){return this.conf=Object.assign(Object.assign(Object.assign({},this.conf),t),{assets:Object.assign(Object.assign({},this.conf.assets),(null==t?void 0:t.assets)||{})}),this}use(t){if("function"!=typeof t)throw new Error(Ct());return i(this,he,"f").push(t),r(this,le,Ft(i(this,he,"f")),"f"),this}}ie=new WeakMap,re=new WeakMap,oe=new WeakMap,ae=new WeakMap,ce=new WeakMap,he=new WeakMap,le=new WeakMap,se=new WeakSet,fe=function(t){return i(this,ae,"f")[t]&&"boolean"!=typeof i(this,ae,"f")[t]},ue=function(t){return{name:t,loadScript:ye.loadScript,loadLink:ye.loadLink}},de=function(t){return s(this,void 0,void 0,(function*(){const{name:e,loadScript:n=ye.loadScript,loadLink:s=ye.loadLink}=t,{assets:r}=this.conf;if(!r[e])throw new Error(Wt(e,i(this,ie,"f")));if(r[e].css&&r[e].css.forEach((t=>{s(t)})),r[e].js)for(const t of r[e].js)yield n(t)}))},pe=function(t,e){return s(this,void 0,void 0,(function*(){if(yield this.loadApp(t),i(this,se,"m",fe).call(this,t)){const n=i(this,ae,"f")[t];if(yield i(this,se,"m",ve).call(this,n),e.includes(t)){const n=e.indexOf(t),s=[...e.slice(n),t];throw new Error(Ut(t,s))}if(e.push(t),!n.activated){const t=()=>s(this,void 0,void 0,(function*(){yield i(this,se,"m",we).call(this,n,e),n.doActivate&&(yield Promise.resolve(n.doActivate()))}));n.activated=t()}yield n.activated,e.pop()}}))},we=function(t,e){return s(this,void 0,void 0,(function*(){if(0!==t.dependencies.length)for(const n of t.dependencies)yield i(this,se,"m",pe).call(this,n,e)}))},ve=function(t){return s(this,void 0,void 0,(function*(){yield Promise.all(t.relatedApps.map((t=>this.loadApp(t))))}))};const ge={},be="DEFAULT_BUS",_e=(t=be)=>{let e=null,n=!1;const s=((t=be)=>window.RALLIE_BUS_STORE&&window.RALLIE_BUS_STORE[t])(t);return s?(e=s,n=!1):(e=((t=be)=>{if(void 0===window.RALLIE_BUS_STORE&&Reflect.defineProperty(window,"RALLIE_BUS_STORE",{value:ge,writable:!1}),window.RALLIE_BUS_STORE[t])throw new Error(Nt(t));{const e=new me(t);return Reflect.defineProperty(window.RALLIE_BUS_STORE,t,{value:e,writable:!1}),e}})(t),n=!0),[e,n]},Ee={privateBus:t=>`${t}.bus`,stateNamespace:t=>`${t}.state`,isGlobalBusAccessible:"isGlobalBusAccessible",exportMethodName:"__RallieInnerExport__"},Se=t=>`[rallie] ${t}`,ke={stateNotInitialized:t=>Se(` the block ${t}'s state is not initialized, please check:\n1. whether the block ${t} is loaded.\n2. whether the block ${t} has initialized the state`),duplicatedBlockName:t=>Se(`the block ${t} is already registered before, please rename your block`),stateIsReadonly:t=>Se(`the state of ${t} is readonly`)},Ae=(t,e)=>new Proxy(t,{get:(t,n)=>(...s)=>(0,t[n])(s,e),set:()=>!1}),Re=t=>{const e={};return Object.entries(t).forEach((([t,n])=>{e[t]=(t,e)=>n.call({trigger:e},...t)})),e};var Oe,xe,Me,Pe,We,je,$e;class Le{constructor(t,s,i){Oe.set(this,void 0),this.name=t,n(this,Oe,i,"f");const r=e(this,Oe,"f").createBroadcaster(),o=e(this,Oe,"f").createUnicaster();this.events=Ae(r,s),this.methods=Ae(o,s),Reflect.defineProperty(this,"state",{get:()=>e(this,Oe,"f").getState(Ee.stateNamespace(this.name)),set:()=>{throw new Error(ke.stateIsReadonly(this.name))}})}setState(t,n){if(e(this,Oe,"f").existState(Ee.stateNamespace(this.name)))return e(this,Oe,"f").setState(Ee.stateNamespace(this.name),t,n);throw new Error(ke.stateNotInitialized(this.name))}watchState(t){if(e(this,Oe,"f").existState(Ee.stateNamespace(this.name)))return e(this,Oe,"f").watchState(Ee.stateNamespace(this.name),t);throw new Error(ke.stateNotInitialized(this.name))}listenEvents(t){return e(this,Oe,"f").onBroadcast(Re(t))}}Oe=new WeakMap;class Be extends Le{constructor(t,e,s,i){const[r]=_e(Ee.privateBus(t)),o=r.createSocket();super(t,t,o),xe.set(this,void 0),Me.set(this,void 0),Pe.set(this,void 0),We.set(this,void 0),je.set(this,void 0),$e.set(this,{}),n(this,We,o,"f"),n(this,xe,e,"f"),n(this,Me,s,"f"),n(this,je,e.createApp(t),"f"),n(this,Pe,i,"f")}initState(t,n){return e(this,We,"f").initState(Ee.stateNamespace(this.name),t,n),this}addMethods(t){return e(this,We,"f").onUnicast(Re(t))}relyOn(t){return e(this,je,"f").relyOn(t),this}relateTo(t){return e(this,je,"f").relateTo(t),this}onActivate(t){return e(this,je,"f").onActivate(t),this}connect(t){if(!e(this,$e,"f")[t]){const[n]=_e(Ee.privateBus(t)),s=n.createSocket();e(this,$e,"f")[t]=new Le(t,this.name,s)}return e(this,$e,"f")[t]}load(t){return e(this,xe,"f").loadApp(t)}activate(t){return e(this,xe,"f").activateApp(t)}run(n){var s;return t(this,void 0,void 0,(function*(){const t=e(this,Pe,"f")||(null===(s=e(this,Me,"f").getState(Ee.isGlobalBusAccessible))||void 0===s?void 0:s.value),i=t=>{e(this,Pe,"f")&&e(this,Me,"f").setState(Ee.isGlobalBusAccessible,t?"unfreeze the enviroment":"freeze the enviroment",(e=>{e.value=t}))},r={isEntry:e(this,Pe,"f"),use:n=>{t&&e(this,xe,"f").use(n)},config:n=>{t&&e(this,xe,"f").config(n)},freeze:()=>{i(!1)},unfreeze:()=>{i(!0)}},o=n(new Proxy(r,{get:(t,n,s)=>"conf"===n?JSON.parse(JSON.stringify(e(this,xe,"f").conf)):Reflect.get(t,n,s),set:()=>!1}));yield Promise.resolve(o)}))}}function Te(t){const[e,n]=_e();if(e.existApp(t))throw new Error(ke.duplicatedBlockName(t));const s=e.createSocket();return n&&s.initState(Ee.isGlobalBusAccessible,{value:!0},!0),new Be(t,e,s,n)}xe=new WeakMap,Me=new WeakMap,Pe=new WeakMap,We=new WeakMap,je=new WeakMap,$e=new WeakMap;export{Te as createBlock}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RallieBlock={})}(this,(function(e){"use strict";function t(e,t,n,s){return new(n||(n=Promise))((function(i,r){function o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))}function n(e,t,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(e):s?s.value:t.get(e)}function s(e,t,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,n):i?i.value=n:t.set(e,n),n}function i(e,t,n,s){return new(n||(n=Promise))((function(i,r){function o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))}function r(e,t,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(e):s?s.value:t.get(e)}function o(e,t,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,n):i?i.value=n:t.set(e,n),n}"production"===process.env.NODE_ENV||Object.freeze({}),"production"===process.env.NODE_ENV||Object.freeze([]);const a=Object.assign,c=Object.prototype.hasOwnProperty,l=(e,t)=>c.call(e,t),h=Array.isArray,f=e=>"[object Map]"===w(e),u=e=>"symbol"==typeof e,d=e=>null!==e&&"object"==typeof e,p=Object.prototype.toString,w=e=>p.call(e),v=e=>w(e).slice(8,-1),y=e=>"string"==typeof e&&"NaN"!==e&&"-"!==e[0]&&""+parseInt(e,10)===e,g=(e=>{const t=Object.create(null);return e=>t[e]||(t[e]=(e=>e.charAt(0).toUpperCase()+e.slice(1))(e))})(),m=(e,t)=>!Object.is(e,t),E=e=>{const t=parseFloat(e);return isNaN(t)?e:t};function b(e,...t){console.warn(`[Vue warn] ${e}`,...t)}let _;function S(e,t=_){t&&t.active&&t.effects.push(e)}const k=e=>{const t=new Set(e);return t.w=0,t.n=0,t},O=e=>(e.w&$)>0,N=e=>(e.n&$)>0,A=new WeakMap;let R=0,$=1;const j=30;let M;const x=Symbol("production"!==process.env.NODE_ENV?"iterate":""),P=Symbol("production"!==process.env.NODE_ENV?"Map key iterate":"");class W{constructor(e,t=null,n){this.fn=e,this.scheduler=t,this.active=!0,this.deps=[],this.parent=void 0,S(this,n)}run(){if(!this.active)return this.fn();let e=M,t=T;for(;e;){if(e===this)return;e=e.parent}try{return this.parent=M,M=this,T=!0,$=1<<++R,R<=j?(({deps:e})=>{if(e.length)for(let t=0;t<e.length;t++)e[t].w|=$})(this):B(this),this.fn()}finally{R<=j&&(e=>{const{deps:t}=e;if(t.length){let n=0;for(let s=0;s<t.length;s++){const i=t[s];O(i)&&!N(i)?i.delete(e):t[n++]=i,i.w&=~$,i.n&=~$}t.length=n}})(this),$=1<<--R,M=this.parent,T=t,this.parent=void 0,this.deferStop&&this.stop()}}stop(){M===this?this.deferStop=!0:this.active&&(B(this),this.onStop&&this.onStop(),this.active=!1)}}function B(e){const{deps:t}=e;if(t.length){for(let n=0;n<t.length;n++)t[n].delete(e);t.length=0}}let T=!0;const L=[];function z(e,t,n){if(T&&M){let s=A.get(e);s||A.set(e,s=new Map);let i=s.get(n);i||s.set(n,i=k()),function(e,t){let n=!1;R<=j?N(e)||(e.n|=$,n=!O(e)):n=!e.has(M),n&&(e.add(M),M.deps.push(e),"production"!==process.env.NODE_ENV&&M.onTrack&&M.onTrack(Object.assign({effect:M},t)))}(i,"production"!==process.env.NODE_ENV?{effect:M,target:e,type:t,key:n}:void 0)}}function V(e,t,n,s,i,r){const o=A.get(e);if(!o)return;let a=[];if("clear"===t)a=[...o.values()];else if("length"===n&&h(e)){const e=E(s);o.forEach(((t,n)=>{("length"===n||n>=e)&&a.push(t)}))}else switch(void 0!==n&&a.push(o.get(n)),t){case"add":h(e)?y(n)&&a.push(o.get("length")):(a.push(o.get(x)),f(e)&&a.push(o.get(P)));break;case"delete":h(e)||(a.push(o.get(x)),f(e)&&a.push(o.get(P)));break;case"set":f(e)&&a.push(o.get(x))}const c="production"!==process.env.NODE_ENV?{target:e,type:t,key:n,newValue:s,oldValue:i,oldTarget:r}:void 0;if(1===a.length)a[0]&&("production"!==process.env.NODE_ENV?U(a[0],c):U(a[0]));else{const e=[];for(const t of a)t&&e.push(...t);"production"!==process.env.NODE_ENV?U(k(e),c):U(k(e))}}function U(e,t){const n=h(e)?e:[...e];for(const e of n)e.computed&&D(e,t);for(const e of n)e.computed||D(e,t)}function D(e,t){(e!==M||e.allowRecurse)&&("production"!==process.env.NODE_ENV&&e.onTrigger&&e.onTrigger(a({effect:e},t)),e.scheduler?e.scheduler():e.run())}const I=function(e,t){const n=Object.create(null),s=e.split(",");for(let e=0;e<s.length;e++)n[s[e]]=!0;return t?e=>!!n[e.toLowerCase()]:e=>!!n[e]}("__proto__,__v_isRef,__isVue"),C=new Set(Object.getOwnPropertyNames(Symbol).filter((e=>"arguments"!==e&&"caller"!==e)).map((e=>Symbol[e])).filter(u)),G=J(),F=J(!0),H=function(){const e={};return["includes","indexOf","lastIndexOf"].forEach((t=>{e[t]=function(...e){const n=ke(this);for(let e=0,t=this.length;e<t;e++)z(n,"get",e+"");const s=n[t](...e);return-1===s||!1===s?n[t](...e.map(ke)):s}})),["push","pop","shift","unshift","splice"].forEach((t=>{e[t]=function(...e){L.push(T),T=!1;const n=ke(this)[t].apply(this,e);return function(){const e=L.pop();T=void 0===e||e}(),n}})),e}();function J(e=!1,t=!1){return function(n,s,i){if("__v_isReactive"===s)return!e;if("__v_isReadonly"===s)return e;if("__v_isShallow"===s)return t;if("__v_raw"===s&&i===(e?t?me:ge:t?ye:ve).get(n))return n;const r=h(n);if(!e&&r&&l(H,s))return Reflect.get(H,s,i);const o=Reflect.get(n,s,i);return(u(s)?C.has(s):I(s))?o:(e||z(n,"get",s),t?o:Ae(o)?r&&y(s)?o:o.value:d(o)?e?be(o):Ee(o):o)}}const K={get:G,set:function(e=!1){return function(t,n,s,i){let r=t[n];if(Se(r)&&Ae(r)&&!Ae(s))return!1;if(!e&&(function(e){return!(!e||!e.__v_isShallow)}(s)||Se(s)||(r=ke(r),s=ke(s)),!h(t)&&Ae(r)&&!Ae(s)))return r.value=s,!0;const o=h(t)&&y(n)?Number(n)<t.length:l(t,n),a=Reflect.set(t,n,s,i);return t===ke(i)&&(o?m(s,r)&&V(t,"set",n,s,r):V(t,"add",n,s)),a}}(),deleteProperty:function(e,t){const n=l(e,t),s=e[t],i=Reflect.deleteProperty(e,t);return i&&n&&V(e,"delete",t,void 0,s),i},has:function(e,t){const n=Reflect.has(e,t);return u(t)&&C.has(t)||z(e,"has",t),n},ownKeys:function(e){return z(e,"iterate",h(e)?"length":x),Reflect.ownKeys(e)}},q={get:F,set:(e,t)=>("production"!==process.env.NODE_ENV&&b(`Set operation on key "${String(t)}" failed: target is readonly.`,e),!0),deleteProperty:(e,t)=>("production"!==process.env.NODE_ENV&&b(`Delete operation on key "${String(t)}" failed: target is readonly.`,e),!0)},Q=e=>e,X=e=>Reflect.getPrototypeOf(e);function Y(e,t,n=!1,s=!1){const i=ke(e=e.__v_raw),r=ke(t);n||(t!==r&&z(i,"get",t),z(i,"get",r));const{has:o}=X(i),a=s?Q:n?Ne:Oe;return o.call(i,t)?a(e.get(t)):o.call(i,r)?a(e.get(r)):void(e!==i&&e.get(t))}function Z(e,t=!1){const n=this.__v_raw,s=ke(n),i=ke(e);return t||(e!==i&&z(s,"has",e),z(s,"has",i)),e===i?n.has(e):n.has(e)||n.has(i)}function ee(e,t=!1){return e=e.__v_raw,!t&&z(ke(e),"iterate",x),Reflect.get(e,"size",e)}function te(e){e=ke(e);const t=ke(this);return X(t).has.call(t,e)||(t.add(e),V(t,"add",e,e)),this}function ne(e,t){t=ke(t);const n=ke(this),{has:s,get:i}=X(n);let r=s.call(n,e);r?"production"!==process.env.NODE_ENV&&we(n,s,e):(e=ke(e),r=s.call(n,e));const o=i.call(n,e);return n.set(e,t),r?m(t,o)&&V(n,"set",e,t,o):V(n,"add",e,t),this}function se(e){const t=ke(this),{has:n,get:s}=X(t);let i=n.call(t,e);i?"production"!==process.env.NODE_ENV&&we(t,n,e):(e=ke(e),i=n.call(t,e));const r=s?s.call(t,e):void 0,o=t.delete(e);return i&&V(t,"delete",e,void 0,r),o}function ie(){const e=ke(this),t=0!==e.size,n="production"!==process.env.NODE_ENV?f(e)?new Map(e):new Set(e):void 0,s=e.clear();return t&&V(e,"clear",void 0,void 0,n),s}function re(e,t){return function(n,s){const i=this,r=i.__v_raw,o=ke(r),a=t?Q:e?Ne:Oe;return!e&&z(o,"iterate",x),r.forEach(((e,t)=>n.call(s,a(e),a(t),i)))}}function oe(e,t,n){return function(...s){const i=this.__v_raw,r=ke(i),o=f(r),a="entries"===e||e===Symbol.iterator&&o,c="keys"===e&&o,l=i[e](...s),h=n?Q:t?Ne:Oe;return!t&&z(r,"iterate",c?P:x),{next(){const{value:e,done:t}=l.next();return t?{value:e,done:t}:{value:a?[h(e[0]),h(e[1])]:h(e),done:t}},[Symbol.iterator](){return this}}}}function ae(e){return function(...t){if("production"!==process.env.NODE_ENV){const n=t[0]?`on key "${t[0]}" `:"";console.warn(`${g(e)} operation ${n}failed: target is readonly.`,ke(this))}return"delete"!==e&&this}}const[ce,le,he,fe]=function(){const e={get(e){return Y(this,e)},get size(){return ee(this)},has:Z,add:te,set:ne,delete:se,clear:ie,forEach:re(!1,!1)},t={get(e){return Y(this,e,!1,!0)},get size(){return ee(this)},has:Z,add:te,set:ne,delete:se,clear:ie,forEach:re(!1,!0)},n={get(e){return Y(this,e,!0)},get size(){return ee(this,!0)},has(e){return Z.call(this,e,!0)},add:ae("add"),set:ae("set"),delete:ae("delete"),clear:ae("clear"),forEach:re(!0,!1)},s={get(e){return Y(this,e,!0,!0)},get size(){return ee(this,!0)},has(e){return Z.call(this,e,!0)},add:ae("add"),set:ae("set"),delete:ae("delete"),clear:ae("clear"),forEach:re(!0,!0)};return["keys","values","entries",Symbol.iterator].forEach((i=>{e[i]=oe(i,!1,!1),n[i]=oe(i,!0,!1),t[i]=oe(i,!1,!0),s[i]=oe(i,!0,!0)})),[e,n,t,s]}();function ue(e,t){const n=t?e?fe:he:e?le:ce;return(t,s,i)=>"__v_isReactive"===s?!e:"__v_isReadonly"===s?e:"__v_raw"===s?t:Reflect.get(l(n,s)&&s in t?n:t,s,i)}const de={get:ue(!1,!1)},pe={get:ue(!0,!1)};function we(e,t,n){const s=ke(n);if(s!==n&&t.call(e,s)){const t=v(e);console.warn(`Reactive ${t} contains both the raw and reactive versions of the same object${"Map"===t?" as keys":""}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`)}}const ve=new WeakMap,ye=new WeakMap,ge=new WeakMap,me=new WeakMap;function Ee(e){return Se(e)?e:_e(e,!1,K,de,ve)}function be(e){return _e(e,!0,q,pe,ge)}function _e(e,t,n,s,i){if(!d(e))return"production"!==process.env.NODE_ENV&&console.warn(`value cannot be made reactive: ${String(e)}`),e;if(e.__v_raw&&(!t||!e.__v_isReactive))return e;const r=i.get(e);if(r)return r;const o=(a=e).__v_skip||!Object.isExtensible(a)?0:function(e){switch(e){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(v(a));var a;if(0===o)return e;const c=new Proxy(e,2===o?s:n);return i.set(e,c),c}function Se(e){return!(!e||!e.__v_isReadonly)}function ke(e){const t=e&&e.__v_raw;return t?ke(t):e}const Oe=e=>d(e)?Ee(e):e,Ne=e=>d(e)?be(e):e;function Ae(e){return!(!e||!0!==e.__v_isRef)}const Re=e=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${e}, but ${e} hasn't been registed as a broadcast event`,$e=e=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${e}, but the listener hasn't been registed`,je=e=>`[@rallie/core] one of the callbacks of the broadcast event ${e} throws an uncaught error`,Me=e=>`[@rallie/core] you are trying to remove a listener of the unicast event ${e}, but ${e} hasn't been registed as a unicast event`,xe=e=>`[@rallie/core] you are trying to register a unicast event ${e}, but it has been registered before`,Pe=e=>`[@rallie/core] you have emitted ${e} unicast, but there is no listener of this event`,We=e=>`[@rallie/core] ${e} is existing, you are not allowed to create it again`,Be=(e,t)=>`[@rallie/core] can not find any assets of the app ${e} on the bus ${t}`,Te=e=>`[@rallie/core] you are trying to activate app ${e}, but it was not created`,Le=e=>`[@rallie/core] state ${e} is private, you are not allowed to set it`,ze=e=>`[@rallie/core] please describe your action when you modify the state ${e}`,Ve=e=>`[@rallie/core] it's not allowed to set or watch state ${e} before it is initialized`,Ue=e=>`[@rallie/core] duplicated initialized state ${e}`,De=e=>`[@rallie/core] it's not allowed to initialized state ${e} to a primitive value`,Ie=e=>`[@rallie/core] the bus named ${e} has been defined before, please rename your bus`,Ce=(e,t)=>`[@rallie/core] There is a circular dependency when activating the app ${e}, and the circular path is ${t.join("->")}`,Ge=()=>"[@rallie/core] next() called multiple times in the middleware",Fe=()=>"[@rallie/core] the middleware must be a function",He=(e,t)=>`[@rallie/core] the event ${e} is not in the events pool that you specified when calling on${t?"Unicast":"Broadcast"}`,Je=e=>(t,n)=>{let s=-1;const i=r=>{if(r<=s)return Promise.reject(new Error(Ge()));s=r;let o=e[r];if(r===e.length&&(o=n),!o)return Promise.resolve();try{return Promise.resolve(o(t,i.bind(null,r+1)))}catch(e){return Promise.reject(e)}};return i(0)};var Ke,qe,Qe,Xe,Ye,Ze,et,tt,nt;class st{constructor(){Ke.set(this,{}),qe.set(this,{})}addBroadcastEventListener(e,t){r(this,Ke,"f")[e]=r(this,Ke,"f")[e]||new Set,r(this,Ke,"f")[e].add(t)}addUnicastEventListener(e,t){if(r(this,qe,"f")[e])throw new Error(xe(e));r(this,qe,"f")[e]=t}removeBroadcastEventListener(e,t){const n=r(this,Ke,"f")[e];if(!n){const t=Re(e);throw new Error(t)}if(!n.has(t)){const t=$e(e);throw new Error(t)}n.delete(t)}removeUnicastEventListener(e){if(!r(this,qe,"f")[e]){const t=Me(e);throw new Error(t)}delete r(this,qe,"f")[e]}emitBroadcast(e,...t){r(this,Ke,"f")[e]=r(this,Ke,"f")[e]||new Set,r(this,Ke,"f")[e].forEach((n=>{try{n(...t)}catch(n){console.error(je(e)),console.error(n)}}))}emitUnicast(e,...t){const n=r(this,qe,"f")[e];if(n)return n(...t);throw new Error(Pe(e))}}Ke=new WeakMap,qe=new WeakMap;class it{constructor(e,t){Qe.set(this,void 0),Xe.set(this,void 0),o(this,Qe,e,"f"),o(this,Xe,t,"f"),r(this,Xe,"f")[e].watchers.add(this)}do(e){return this.handler=e,()=>this.unwatch()}unwatch(){null==this||this.stopEffect(),this.handler=null;const e=r(this,Xe,"f")[r(this,Qe,"f")].watchers;e.has(this)&&e.delete(this)}}Qe=new WeakMap,Xe=new WeakMap;class rt{constructor(e,t){Ye.add(this),Ze.set(this,void 0),et.set(this,void 0),o(this,Ze,e,"f"),o(this,et,t,"f")}onBroadcast(e){return Object.entries(e).forEach((([e,t])=>{r(this,Ze,"f").addBroadcastEventListener(e,t)})),t=>{r(this,Ye,"m",tt).call(this,e,!1,t)}}onUnicast(e){return Object.entries(e).forEach((([e,t])=>{try{r(this,Ze,"f").addUnicastEventListener(e,t)}catch(e){console.error(e)}})),t=>{r(this,Ye,"m",tt).call(this,e,!0,t)}}createBroadcaster(e){return new Proxy({},{get:(t,n)=>(...t)=>(null==e||e(n),r(this,Ze,"f").emitBroadcast(n,...t)),set:()=>!1})}createUnicaster(e){return new Proxy({},{get:(t,n)=>(...t)=>(null==e||e(n),r(this,Ze,"f").emitUnicast(n,...t)),set:()=>!1})}existState(e){return!!r(this,et,"f")[e]}initState(e,t,n=!1){if(this.existState(e))throw new Error(Ue(e));if(["string","number","boolean","undefined"].includes(typeof t))throw new Error(De(e));return r(this,et,"f")[e]={state:Ee(t),owner:n?this:null,watchers:new Set},r(this,Ze,"f").emitBroadcast("$state-initialized",e),this.getState(e)}getState(e,t){if(this.existState(e)){const n=be(r(this,et,"f")[e].state);return t?t(n):n}return null}setState(e,t,n){return i(this,void 0,void 0,(function*(){const s=r(this,Ye,"m",nt).call(this,e);if(!t)throw new Error(ze(e));{const e=n(s);yield Promise.resolve(e)}}))}watchState(e,t){if(!this.existState(e)){const t=Ve(e);throw new Error(t)}let n=!1;const s=be(r(this,et,"f")[e].state),i=new it(e,r(this,et,"f")),o=function(e,t){e.effect&&(e=e.effect.fn);const n=new W(e);t&&(a(n,t),t.scope&&S(n,t.scope)),t&&t.lazy||n.run();const s=n.run.bind(n);return s.effect=n,s}((()=>t(s)),{lazy:!0,scheduler:()=>{n||(n=!0,Promise.resolve().then((()=>{var e;const r=ke(t(s));null===(e=i.handler)||void 0===e||e.call(i,r,i.oldWatchingStates),i.oldWatchingStates=ke(r),n=!1})))}});return i.oldWatchingStates=o(),i.stopEffect=()=>o.effect.stop(),i}}Ze=new WeakMap,et=new WeakMap,Ye=new WeakSet,tt=function(e,t,n){let s=t?r(this,Ze,"f").removeUnicastEventListener:r(this,Ze,"f").removeBroadcastEventListener;s=s.bind(r(this,Ze,"f")),n?e[n]?(s(n,e[n]),delete e[n]):console.warn(He(n,t)):Object.entries(e).forEach((([e,t])=>{s(e,t)}))},nt=function(e){if(!this.existState(e)){const t=Ve(e);throw new Error(t)}const t=r(this,et,"f")[e].owner;if(t!==this&&null!==t){const t=Le(e);throw new Error(t)}return r(this,et,"f")[e].state};class ot{constructor(e){this.name=e,this.activated=null,this.dependencies=[],this.relatedApps=[],this.name=e,this.isRallieCoreApp=!0}relateTo(e){return this.relatedApps=Array.from(new Set([...this.relatedApps,...e])),this}relyOn(e){return this.relateTo(e),this.dependencies=Array.from(new Set([...this.dependencies,...e])),this}onActivate(e){return this.doActivate=e,this}}var at,ct,lt,ht,ft,ut,dt,pt,wt,vt,yt,gt,mt,Et,bt={loadScript:e=>i(void 0,void 0,void 0,(function*(){return new Promise((t=>{let n=null;if(e instanceof HTMLScriptElement)n=e;else{n=document.createElement("script");const t="string"!=typeof e?e:{type:"text/javascript",src:e};Object.entries(t).forEach((([e,t])=>{n.setAttribute(e,t)}))}n.src&&(n.onload=n.onerror=()=>{t()}),document.body.appendChild(n),n.src||t()}))})),loadLink:e=>{let t=null;if(e instanceof HTMLLinkElement)t=e;else{const n="string"!=typeof e?e:{rel:"stylesheet",type:"text/css",href:e};t=document.createElement("link"),Object.entries(n).forEach((([e,n])=>{t.setAttribute(e,n)}))}document.head.appendChild(t)}};class _t{constructor(e){at.add(this),ct.set(this,void 0),lt.set(this,new st),ht.set(this,{}),ft.set(this,{}),ut.set(this,{}),this.conf=be({assets:{}}),dt.set(this,[]),pt.set(this,void 0),o(this,ct,e,"f"),o(this,pt,Je(r(this,dt,"f")),"f")}createSocket(){return new rt(r(this,lt,"f"),r(this,ht,"f"))}existApp(e){return!!r(this,ft,"f")[e]}createApp(e){if(this.existApp(e))throw new Error(We(e));const t=new ot(e);return r(this,ft,"f")[e]=t,t}loadApp(e){return i(this,void 0,void 0,(function*(){r(this,ft,"f")[e]||(r(this,ut,"f")[e]||(r(this,ut,"f")[e]=new Promise(((t,n)=>{const s=r(this,at,"m",vt).call(this,e);r(this,pt,"f").call(this,s,r(this,at,"m",yt).bind(this)).then((()=>{e.startsWith("lib:")&&!r(this,ft,"f")[e]&&(r(this,ft,"f")[e]=!0),r(this,ft,"f")[e]||n(new Error(Te(e))),t()})).catch((e=>{n(e)}))}))),yield r(this,ut,"f")[e])}))}activateApp(e){return i(this,void 0,void 0,(function*(){yield r(this,at,"m",gt).call(this,e,[])}))}config(e){return this.conf=Object.assign(Object.assign(Object.assign({},this.conf),e),{assets:Object.assign(Object.assign({},this.conf.assets),(null==e?void 0:e.assets)||{})}),this}use(e){if("function"!=typeof e)throw new Error(Fe());return r(this,dt,"f").push(e),o(this,pt,Je(r(this,dt,"f")),"f"),this}}ct=new WeakMap,lt=new WeakMap,ht=new WeakMap,ft=new WeakMap,ut=new WeakMap,dt=new WeakMap,pt=new WeakMap,at=new WeakSet,wt=function(e){return r(this,ft,"f")[e]&&"boolean"!=typeof r(this,ft,"f")[e]},vt=function(e){return{name:e,loadScript:bt.loadScript,loadLink:bt.loadLink}},yt=function(e){return i(this,void 0,void 0,(function*(){const{name:t,loadScript:n=bt.loadScript,loadLink:s=bt.loadLink}=e,{assets:i}=this.conf;if(!i[t])throw new Error(Be(t,r(this,ct,"f")));if(i[t].css&&i[t].css.forEach((e=>{s(e)})),i[t].js)for(const e of i[t].js)yield n(e)}))},gt=function(e,t){return i(this,void 0,void 0,(function*(){if(yield this.loadApp(e),r(this,at,"m",wt).call(this,e)){const n=r(this,ft,"f")[e];if(yield r(this,at,"m",Et).call(this,n),t.includes(e)){const n=t.indexOf(e),s=[...t.slice(n),e];throw new Error(Ce(e,s))}if(t.push(e),!n.activated){const e=()=>i(this,void 0,void 0,(function*(){yield r(this,at,"m",mt).call(this,n,t),n.doActivate&&(yield Promise.resolve(n.doActivate()))}));n.activated=e()}yield n.activated,t.pop()}}))},mt=function(e,t){return i(this,void 0,void 0,(function*(){if(0!==e.dependencies.length)for(const n of e.dependencies)yield r(this,at,"m",gt).call(this,n,t)}))},Et=function(e){return i(this,void 0,void 0,(function*(){yield Promise.all(e.relatedApps.map((e=>this.loadApp(e))))}))};const St={},kt="DEFAULT_BUS",Ot=(e=kt)=>{let t=null,n=!1;const s=((e=kt)=>window.RALLIE_BUS_STORE&&window.RALLIE_BUS_STORE[e])(e);return s?(t=s,n=!1):(t=((e=kt)=>{if(void 0===window.RALLIE_BUS_STORE&&Reflect.defineProperty(window,"RALLIE_BUS_STORE",{value:St,writable:!1}),window.RALLIE_BUS_STORE[e])throw new Error(Ie(e));{const t=new _t(e);return Reflect.defineProperty(window.RALLIE_BUS_STORE,e,{value:t,writable:!1}),t}})(e),n=!0),[t,n]},Nt={privateBus:e=>`${e}.bus`,stateNamespace:e=>`${e}.state`,isGlobalBusAccessible:"isGlobalBusAccessible",exportMethodName:"__RallieInnerExport__"},At=e=>`[rallie] ${e}`,Rt={stateNotInitialized:e=>At(` the block ${e}'s state is not initialized, please check:\n1. whether the block ${e} is loaded.\n2. whether the block ${e} has initialized the state`),duplicatedBlockName:e=>At(`the block ${e} is already registered before, please rename your block`),stateIsReadonly:e=>At(`the state of ${e} is readonly`)},$t=(e,t)=>new Proxy(e,{get:(e,n)=>(...s)=>(0,e[n])(s,t),set:()=>!1}),jt=e=>{const t={};return Object.entries(e).forEach((([e,n])=>{t[e]=(e,t)=>n.call({trigger:t},...e)})),t};var Mt,xt,Pt,Wt,Bt,Tt,Lt;class zt{constructor(e,t,i){Mt.set(this,void 0),this.name=e,s(this,Mt,i,"f");const r=n(this,Mt,"f").createBroadcaster(),o=n(this,Mt,"f").createUnicaster();this.events=$t(r,t),this.methods=$t(o,t),Reflect.defineProperty(this,"state",{get:()=>n(this,Mt,"f").getState(Nt.stateNamespace(this.name)),set:()=>{throw new Error(Rt.stateIsReadonly(this.name))}})}setState(e,t){if(n(this,Mt,"f").existState(Nt.stateNamespace(this.name)))return n(this,Mt,"f").setState(Nt.stateNamespace(this.name),e,t);throw new Error(Rt.stateNotInitialized(this.name))}watchState(e){if(n(this,Mt,"f").existState(Nt.stateNamespace(this.name)))return n(this,Mt,"f").watchState(Nt.stateNamespace(this.name),e);throw new Error(Rt.stateNotInitialized(this.name))}listenEvents(e){return n(this,Mt,"f").onBroadcast(jt(e))}}Mt=new WeakMap;class Vt extends zt{constructor(e,t,n,i){const[r]=Ot(Nt.privateBus(e)),o=r.createSocket();super(e,e,o),xt.set(this,void 0),Pt.set(this,void 0),Wt.set(this,void 0),Bt.set(this,void 0),Tt.set(this,void 0),Lt.set(this,{}),s(this,Bt,o,"f"),s(this,xt,t,"f"),s(this,Pt,n,"f"),s(this,Tt,t.createApp(e),"f"),s(this,Wt,i,"f")}initState(e,t){return n(this,Bt,"f").initState(Nt.stateNamespace(this.name),e,t),this}addMethods(e){return n(this,Bt,"f").onUnicast(jt(e))}relyOn(e){return n(this,Tt,"f").relyOn(e),this}relateTo(e){return n(this,Tt,"f").relateTo(e),this}onActivate(e){return n(this,Tt,"f").onActivate(e),this}connect(e){if(!n(this,Lt,"f")[e]){const[t]=Ot(Nt.privateBus(e)),s=t.createSocket();n(this,Lt,"f")[e]=new zt(e,this.name,s)}return n(this,Lt,"f")[e]}load(e){return n(this,xt,"f").loadApp(e)}activate(e){return n(this,xt,"f").activateApp(e)}run(e){var s;return t(this,void 0,void 0,(function*(){const t=n(this,Wt,"f")||(null===(s=n(this,Pt,"f").getState(Nt.isGlobalBusAccessible))||void 0===s?void 0:s.value),i=e=>{n(this,Wt,"f")&&n(this,Pt,"f").setState(Nt.isGlobalBusAccessible,e?"unfreeze the enviroment":"freeze the enviroment",(t=>{t.value=e}))},r={isEntry:n(this,Wt,"f"),use:e=>{t&&n(this,xt,"f").use(e)},config:e=>{t&&n(this,xt,"f").config(e)},freeze:()=>{i(!1)},unfreeze:()=>{i(!0)}},o=e(new Proxy(r,{get:(e,t,s)=>"conf"===t?JSON.parse(JSON.stringify(n(this,xt,"f").conf)):Reflect.get(e,t,s),set:()=>!1}));yield Promise.resolve(o)}))}}xt=new WeakMap,Pt=new WeakMap,Wt=new WeakMap,Bt=new WeakMap,Tt=new WeakMap,Lt=new WeakMap,e.createBlock=function(e){const[t,n]=Ot();if(t.existApp(e))throw new Error(Rt.duplicatedBlockName(e));const s=t.createSocket();return n&&s.initState(Nt.isGlobalBusAccessible,{value:!0},!0),new Vt(e,t,s,n)}})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RallieBlock={})}(this,(function(t){"use strict";function e(t,e,n,s){return new(n||(n=Promise))((function(i,r){function o(t){try{c(s.next(t))}catch(t){r(t)}}function a(t){try{c(s.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((s=s.apply(t,e||[])).next())}))}function n(t,e,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(t):s?s.value:e.get(t)}function s(t,e,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(t,n):i?i.value=n:e.set(t,n),n}function i(t,e,n,s){return new(n||(n=Promise))((function(i,r){function o(t){try{c(s.next(t))}catch(t){r(t)}}function a(t){try{c(s.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((s=s.apply(t,e||[])).next())}))}function r(t,e,n,s){if("a"===n&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?s:"a"===n?s.call(t):s?s.value:e.get(t)}function o(t,e,n,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(t,n):i?i.value=n:e.set(t,n),n}const a=Object.assign,c=Object.prototype.hasOwnProperty,l=(t,e)=>c.call(t,e),h=Array.isArray,f=t=>"[object Map]"===w(t),u=t=>"symbol"==typeof t,d=t=>null!==t&&"object"==typeof t,p=Object.prototype.toString,w=t=>p.call(t),v=t=>w(t).slice(8,-1),y=t=>"string"==typeof t&&"NaN"!==t&&"-"!==t[0]&&""+parseInt(t,10)===t,m=(t,e)=>!Object.is(t,e),g=t=>{const e=parseFloat(t);return isNaN(e)?t:e};let b;function _(t,e=b){e&&e.active&&e.effects.push(t)}const E=t=>{const e=new Set(t);return e.w=0,e.n=0,e},S=t=>(t.w&O)>0,k=t=>(t.n&O)>0,A=new WeakMap;let R=0,O=1;const x=30;let M;const P=Symbol(""),W=Symbol("");class j{constructor(t,e=null,n){this.fn=t,this.scheduler=e,this.active=!0,this.deps=[],this.parent=void 0,_(this,n)}run(){if(!this.active)return this.fn();let t=M,e=$;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=M,M=this,$=!0,O=1<<++R,R<=x?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=O})(this):B(this),this.fn()}finally{R<=x&&(t=>{const{deps:e}=t;if(e.length){let n=0;for(let s=0;s<e.length;s++){const i=e[s];S(i)&&!k(i)?i.delete(t):e[n++]=i,i.w&=~O,i.n&=~O}e.length=n}})(this),O=1<<--R,M=this.parent,$=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){M===this?this.deferStop=!0:this.active&&(B(this),this.onStop&&this.onStop(),this.active=!1)}}function B(t){const{deps:e}=t;if(e.length){for(let n=0;n<e.length;n++)e[n].delete(t);e.length=0}}let $=!0;const L=[];function T(t,e,n){if($&&M){let e=A.get(t);e||A.set(t,e=new Map);let s=e.get(n);s||e.set(n,s=E()),function(t,e){let n=!1;R<=x?k(t)||(t.n|=O,n=!S(t)):n=!t.has(M),n&&(t.add(M),M.deps.push(t))}(s)}}function z(t,e,n,s,i,r){const o=A.get(t);if(!o)return;let a=[];if("clear"===e)a=[...o.values()];else if("length"===n&&h(t)){const t=g(s);o.forEach(((e,n)=>{("length"===n||n>=t)&&a.push(e)}))}else switch(void 0!==n&&a.push(o.get(n)),e){case"add":h(t)?y(n)&&a.push(o.get("length")):(a.push(o.get(P)),f(t)&&a.push(o.get(W)));break;case"delete":h(t)||(a.push(o.get(P)),f(t)&&a.push(o.get(W)));break;case"set":f(t)&&a.push(o.get(P))}if(1===a.length)a[0]&&N(a[0]);else{const t=[];for(const e of a)e&&t.push(...e);N(E(t))}}function N(t,e){const n=h(t)?t:[...t];for(const t of n)t.computed&&U(t);for(const t of n)t.computed||U(t)}function U(t,e){(t!==M||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}const I=function(t,e){const n=Object.create(null),s=t.split(",");for(let t=0;t<s.length;t++)n[s[t]]=!0;return e?t=>!!n[t.toLowerCase()]:t=>!!n[t]}("__proto__,__v_isRef,__isVue"),C=new Set(Object.getOwnPropertyNames(Symbol).filter((t=>"arguments"!==t&&"caller"!==t)).map((t=>Symbol[t])).filter(u)),G=J(),F=J(!0),H=function(){const t={};return["includes","indexOf","lastIndexOf"].forEach((e=>{t[e]=function(...t){const n=_t(this);for(let t=0,e=this.length;t<e;t++)T(n,0,t+"");const s=n[e](...t);return-1===s||!1===s?n[e](...t.map(_t)):s}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){L.push($),$=!1;const n=_t(this)[e].apply(this,t);return function(){const t=L.pop();$=void 0===t||t}(),n}})),t}();function J(t=!1,e=!1){return function(n,s,i){if("__v_isReactive"===s)return!t;if("__v_isReadonly"===s)return t;if("__v_isShallow"===s)return e;if("__v_raw"===s&&i===(t?e?vt:wt:e?pt:dt).get(n))return n;const r=h(n);if(!t&&r&&l(H,s))return Reflect.get(H,s,i);const o=Reflect.get(n,s,i);return(u(s)?C.has(s):I(s))?o:(t||T(n,0,s),e?o:kt(o)?r&&y(s)?o:o.value:d(o)?t?mt(o):yt(o):o)}}const K={get:G,set:function(t=!1){return function(e,n,s,i){let r=e[n];if(bt(r)&&kt(r)&&!kt(s))return!1;if(!t&&(function(t){return!(!t||!t.__v_isShallow)}(s)||bt(s)||(r=_t(r),s=_t(s)),!h(e)&&kt(r)&&!kt(s)))return r.value=s,!0;const o=h(e)&&y(n)?Number(n)<e.length:l(e,n),a=Reflect.set(e,n,s,i);return e===_t(i)&&(o?m(s,r)&&z(e,"set",n,s):z(e,"add",n,s)),a}}(),deleteProperty:function(t,e){const n=l(t,e);t[e];const s=Reflect.deleteProperty(t,e);return s&&n&&z(t,"delete",e,void 0),s},has:function(t,e){const n=Reflect.has(t,e);return u(e)&&C.has(e)||T(t,0,e),n},ownKeys:function(t){return T(t,0,h(t)?"length":P),Reflect.ownKeys(t)}},D={get:F,set:(t,e)=>!0,deleteProperty:(t,e)=>!0},V=t=>t,q=t=>Reflect.getPrototypeOf(t);function Q(t,e,n=!1,s=!1){const i=_t(t=t.__v_raw),r=_t(e);n||(e!==r&&T(i,0,e),T(i,0,r));const{has:o}=q(i),a=s?V:n?St:Et;return o.call(i,e)?a(t.get(e)):o.call(i,r)?a(t.get(r)):void(t!==i&&t.get(e))}function X(t,e=!1){const n=this.__v_raw,s=_t(n),i=_t(t);return e||(t!==i&&T(s,0,t),T(s,0,i)),t===i?n.has(t):n.has(t)||n.has(i)}function Y(t,e=!1){return t=t.__v_raw,!e&&T(_t(t),0,P),Reflect.get(t,"size",t)}function Z(t){t=_t(t);const e=_t(this);return q(e).has.call(e,t)||(e.add(t),z(e,"add",t,t)),this}function tt(t,e){e=_t(e);const n=_t(this),{has:s,get:i}=q(n);let r=s.call(n,t);r||(t=_t(t),r=s.call(n,t));const o=i.call(n,t);return n.set(t,e),r?m(e,o)&&z(n,"set",t,e):z(n,"add",t,e),this}function et(t){const e=_t(this),{has:n,get:s}=q(e);let i=n.call(e,t);i||(t=_t(t),i=n.call(e,t)),s&&s.call(e,t);const r=e.delete(t);return i&&z(e,"delete",t,void 0),r}function nt(){const t=_t(this),e=0!==t.size,n=t.clear();return e&&z(t,"clear",void 0,void 0),n}function st(t,e){return function(n,s){const i=this,r=i.__v_raw,o=_t(r),a=e?V:t?St:Et;return!t&&T(o,0,P),r.forEach(((t,e)=>n.call(s,a(t),a(e),i)))}}function it(t,e,n){return function(...s){const i=this.__v_raw,r=_t(i),o=f(r),a="entries"===t||t===Symbol.iterator&&o,c="keys"===t&&o,l=i[t](...s),h=n?V:e?St:Et;return!e&&T(r,0,c?W:P),{next(){const{value:t,done:e}=l.next();return e?{value:t,done:e}:{value:a?[h(t[0]),h(t[1])]:h(t),done:e}},[Symbol.iterator](){return this}}}}function rt(t){return function(...e){return"delete"!==t&&this}}const[ot,at,ct,lt]=function(){const t={get(t){return Q(this,t)},get size(){return Y(this)},has:X,add:Z,set:tt,delete:et,clear:nt,forEach:st(!1,!1)},e={get(t){return Q(this,t,!1,!0)},get size(){return Y(this)},has:X,add:Z,set:tt,delete:et,clear:nt,forEach:st(!1,!0)},n={get(t){return Q(this,t,!0)},get size(){return Y(this,!0)},has(t){return X.call(this,t,!0)},add:rt("add"),set:rt("set"),delete:rt("delete"),clear:rt("clear"),forEach:st(!0,!1)},s={get(t){return Q(this,t,!0,!0)},get size(){return Y(this,!0)},has(t){return X.call(this,t,!0)},add:rt("add"),set:rt("set"),delete:rt("delete"),clear:rt("clear"),forEach:st(!0,!0)};return["keys","values","entries",Symbol.iterator].forEach((i=>{t[i]=it(i,!1,!1),n[i]=it(i,!0,!1),e[i]=it(i,!1,!0),s[i]=it(i,!0,!0)})),[t,n,e,s]}();function ht(t,e){const n=e?t?lt:ct:t?at:ot;return(e,s,i)=>"__v_isReactive"===s?!t:"__v_isReadonly"===s?t:"__v_raw"===s?e:Reflect.get(l(n,s)&&s in e?n:e,s,i)}const ft={get:ht(!1,!1)},ut={get:ht(!0,!1)},dt=new WeakMap,pt=new WeakMap,wt=new WeakMap,vt=new WeakMap;function yt(t){return bt(t)?t:gt(t,!1,K,ft,dt)}function mt(t){return gt(t,!0,D,ut,wt)}function gt(t,e,n,s,i){if(!d(t))return t;if(t.__v_raw&&(!e||!t.__v_isReactive))return t;const r=i.get(t);if(r)return r;const o=(a=t).__v_skip||!Object.isExtensible(a)?0:function(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(v(a));var a;if(0===o)return t;const c=new Proxy(t,2===o?s:n);return i.set(t,c),c}function bt(t){return!(!t||!t.__v_isReadonly)}function _t(t){const e=t&&t.__v_raw;return e?_t(e):t}const Et=t=>d(t)?yt(t):t,St=t=>d(t)?mt(t):t;function kt(t){return!(!t||!0!==t.__v_isRef)}const At=t=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${t}, but ${t} hasn't been registed as a broadcast event`,Rt=t=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${t}, but the listener hasn't been registed`,Ot=t=>`[@rallie/core] one of the callbacks of the broadcast event ${t} throws an uncaught error`,xt=t=>`[@rallie/core] you are trying to remove a listener of the unicast event ${t}, but ${t} hasn't been registed as a unicast event`,Mt=t=>`[@rallie/core] you are trying to register a unicast event ${t}, but it has been registered before`,Pt=t=>`[@rallie/core] you have emitted ${t} unicast, but there is no listener of this event`,Wt=t=>`[@rallie/core] ${t} is existing, you are not allowed to create it again`,jt=(t,e)=>`[@rallie/core] can not find any assets of the app ${t} on the bus ${e}`,Bt=t=>`[@rallie/core] you are trying to activate app ${t}, but it was not created`,$t=t=>`[@rallie/core] state ${t} is private, you are not allowed to set it`,Lt=t=>`[@rallie/core] please describe your action when you modify the state ${t}`,Tt=t=>`[@rallie/core] it's not allowed to set or watch state ${t} before it is initialized`,zt=t=>`[@rallie/core] duplicated initialized state ${t}`,Nt=t=>`[@rallie/core] it's not allowed to initialized state ${t} to a primitive value`,Ut=t=>`[@rallie/core] the bus named ${t} has been defined before, please rename your bus`,It=(t,e)=>`[@rallie/core] There is a circular dependency when activating the app ${t}, and the circular path is ${e.join("->")}`,Ct=()=>"[@rallie/core] next() called multiple times in the middleware",Gt=()=>"[@rallie/core] the middleware must be a function",Ft=(t,e)=>`[@rallie/core] the event ${t} is not in the events pool that you specified when calling on${e?"Unicast":"Broadcast"}`,Ht=t=>(e,n)=>{let s=-1;const i=r=>{if(r<=s)return Promise.reject(new Error(Ct()));s=r;let o=t[r];if(r===t.length&&(o=n),!o)return Promise.resolve();try{return Promise.resolve(o(e,i.bind(null,r+1)))}catch(t){return Promise.reject(t)}};return i(0)};var Jt,Kt,Dt,Vt,qt,Qt,Xt,Yt,Zt;class te{constructor(){Jt.set(this,{}),Kt.set(this,{})}addBroadcastEventListener(t,e){r(this,Jt,"f")[t]=r(this,Jt,"f")[t]||new Set,r(this,Jt,"f")[t].add(e)}addUnicastEventListener(t,e){if(r(this,Kt,"f")[t])throw new Error(Mt(t));r(this,Kt,"f")[t]=e}removeBroadcastEventListener(t,e){const n=r(this,Jt,"f")[t];if(!n){const e=At(t);throw new Error(e)}if(!n.has(e)){const e=Rt(t);throw new Error(e)}n.delete(e)}removeUnicastEventListener(t){if(!r(this,Kt,"f")[t]){const e=xt(t);throw new Error(e)}delete r(this,Kt,"f")[t]}emitBroadcast(t,...e){r(this,Jt,"f")[t]=r(this,Jt,"f")[t]||new Set,r(this,Jt,"f")[t].forEach((n=>{try{n(...e)}catch(n){console.error(Ot(t)),console.error(n)}}))}emitUnicast(t,...e){const n=r(this,Kt,"f")[t];if(n)return n(...e);throw new Error(Pt(t))}}Jt=new WeakMap,Kt=new WeakMap;class ee{constructor(t,e){Dt.set(this,void 0),Vt.set(this,void 0),o(this,Dt,t,"f"),o(this,Vt,e,"f"),r(this,Vt,"f")[t].watchers.add(this)}do(t){return this.handler=t,()=>this.unwatch()}unwatch(){null==this||this.stopEffect(),this.handler=null;const t=r(this,Vt,"f")[r(this,Dt,"f")].watchers;t.has(this)&&t.delete(this)}}Dt=new WeakMap,Vt=new WeakMap;class ne{constructor(t,e){qt.add(this),Qt.set(this,void 0),Xt.set(this,void 0),o(this,Qt,t,"f"),o(this,Xt,e,"f")}onBroadcast(t){return Object.entries(t).forEach((([t,e])=>{r(this,Qt,"f").addBroadcastEventListener(t,e)})),e=>{r(this,qt,"m",Yt).call(this,t,!1,e)}}onUnicast(t){return Object.entries(t).forEach((([t,e])=>{try{r(this,Qt,"f").addUnicastEventListener(t,e)}catch(t){console.error(t)}})),e=>{r(this,qt,"m",Yt).call(this,t,!0,e)}}createBroadcaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),r(this,Qt,"f").emitBroadcast(n,...e)),set:()=>!1})}createUnicaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),r(this,Qt,"f").emitUnicast(n,...e)),set:()=>!1})}existState(t){return!!r(this,Xt,"f")[t]}initState(t,e,n=!1){if(this.existState(t))throw new Error(zt(t));if(["string","number","boolean","undefined"].includes(typeof e))throw new Error(Nt(t));return r(this,Xt,"f")[t]={state:yt(e),owner:n?this:null,watchers:new Set},r(this,Qt,"f").emitBroadcast("$state-initialized",t),this.getState(t)}getState(t,e){if(this.existState(t)){const n=mt(r(this,Xt,"f")[t].state);return e?e(n):n}return null}setState(t,e,n){return i(this,void 0,void 0,(function*(){const s=r(this,qt,"m",Zt).call(this,t);if(!e)throw new Error(Lt(t));{const t=n(s);yield Promise.resolve(t)}}))}watchState(t,e){if(!this.existState(t)){const e=Tt(t);throw new Error(e)}let n=!1;const s=mt(r(this,Xt,"f")[t].state),i=new ee(t,r(this,Xt,"f")),o=function(t,e){t.effect&&(t=t.effect.fn);const n=new j(t);e&&(a(n,e),e.scope&&_(n,e.scope)),e&&e.lazy||n.run();const s=n.run.bind(n);return s.effect=n,s}((()=>e(s)),{lazy:!0,scheduler:()=>{n||(n=!0,Promise.resolve().then((()=>{var t;const r=_t(e(s));null===(t=i.handler)||void 0===t||t.call(i,r,i.oldWatchingStates),i.oldWatchingStates=_t(r),n=!1})))}});return i.oldWatchingStates=o(),i.stopEffect=()=>o.effect.stop(),i}}Qt=new WeakMap,Xt=new WeakMap,qt=new WeakSet,Yt=function(t,e,n){let s=e?r(this,Qt,"f").removeUnicastEventListener:r(this,Qt,"f").removeBroadcastEventListener;s=s.bind(r(this,Qt,"f")),n?t[n]?(s(n,t[n]),delete t[n]):console.warn(Ft(n,e)):Object.entries(t).forEach((([t,e])=>{s(t,e)}))},Zt=function(t){if(!this.existState(t)){const e=Tt(t);throw new Error(e)}const e=r(this,Xt,"f")[t].owner;if(e!==this&&null!==e){const e=$t(t);throw new Error(e)}return r(this,Xt,"f")[t].state};class se{constructor(t){this.name=t,this.activated=null,this.dependencies=[],this.relatedApps=[],this.name=t,this.isRallieCoreApp=!0}relateTo(t){return this.relatedApps=Array.from(new Set([...this.relatedApps,...t])),this}relyOn(t){return this.relateTo(t),this.dependencies=Array.from(new Set([...this.dependencies,...t])),this}onActivate(t){return this.doActivate=t,this}}var ie,re,oe,ae,ce,le,he,fe,ue,de,pe,we,ve,ye,me={loadScript:t=>i(void 0,void 0,void 0,(function*(){return new Promise((e=>{let n=null;if(t instanceof HTMLScriptElement)n=t;else{n=document.createElement("script");const e="string"!=typeof t?t:{type:"text/javascript",src:t};Object.entries(e).forEach((([t,e])=>{n.setAttribute(t,e)}))}n.src&&(n.onload=n.onerror=()=>{e()}),document.body.appendChild(n),n.src||e()}))})),loadLink:t=>{let e=null;if(t instanceof HTMLLinkElement)e=t;else{const n="string"!=typeof t?t:{rel:"stylesheet",type:"text/css",href:t};e=document.createElement("link"),Object.entries(n).forEach((([t,n])=>{e.setAttribute(t,n)}))}document.head.appendChild(e)}};class ge{constructor(t){ie.add(this),re.set(this,void 0),oe.set(this,new te),ae.set(this,{}),ce.set(this,{}),le.set(this,{}),this.conf=mt({assets:{}}),he.set(this,[]),fe.set(this,void 0),o(this,re,t,"f"),o(this,fe,Ht(r(this,he,"f")),"f")}createSocket(){return new ne(r(this,oe,"f"),r(this,ae,"f"))}existApp(t){return!!r(this,ce,"f")[t]}createApp(t){if(this.existApp(t))throw new Error(Wt(t));const e=new se(t);return r(this,ce,"f")[t]=e,e}loadApp(t){return i(this,void 0,void 0,(function*(){r(this,ce,"f")[t]||(r(this,le,"f")[t]||(r(this,le,"f")[t]=new Promise(((e,n)=>{const s=r(this,ie,"m",de).call(this,t);r(this,fe,"f").call(this,s,r(this,ie,"m",pe).bind(this)).then((()=>{t.startsWith("lib:")&&!r(this,ce,"f")[t]&&(r(this,ce,"f")[t]=!0),r(this,ce,"f")[t]||n(new Error(Bt(t))),e()})).catch((t=>{n(t)}))}))),yield r(this,le,"f")[t])}))}activateApp(t){return i(this,void 0,void 0,(function*(){yield r(this,ie,"m",we).call(this,t,[])}))}config(t){return this.conf=Object.assign(Object.assign(Object.assign({},this.conf),t),{assets:Object.assign(Object.assign({},this.conf.assets),(null==t?void 0:t.assets)||{})}),this}use(t){if("function"!=typeof t)throw new Error(Gt());return r(this,he,"f").push(t),o(this,fe,Ht(r(this,he,"f")),"f"),this}}re=new WeakMap,oe=new WeakMap,ae=new WeakMap,ce=new WeakMap,le=new WeakMap,he=new WeakMap,fe=new WeakMap,ie=new WeakSet,ue=function(t){return r(this,ce,"f")[t]&&"boolean"!=typeof r(this,ce,"f")[t]},de=function(t){return{name:t,loadScript:me.loadScript,loadLink:me.loadLink}},pe=function(t){return i(this,void 0,void 0,(function*(){const{name:e,loadScript:n=me.loadScript,loadLink:s=me.loadLink}=t,{assets:i}=this.conf;if(!i[e])throw new Error(jt(e,r(this,re,"f")));if(i[e].css&&i[e].css.forEach((t=>{s(t)})),i[e].js)for(const t of i[e].js)yield n(t)}))},we=function(t,e){return i(this,void 0,void 0,(function*(){if(yield this.loadApp(t),r(this,ie,"m",ue).call(this,t)){const n=r(this,ce,"f")[t];if(yield r(this,ie,"m",ye).call(this,n),e.includes(t)){const n=e.indexOf(t),s=[...e.slice(n),t];throw new Error(It(t,s))}if(e.push(t),!n.activated){const t=()=>i(this,void 0,void 0,(function*(){yield r(this,ie,"m",ve).call(this,n,e),n.doActivate&&(yield Promise.resolve(n.doActivate()))}));n.activated=t()}yield n.activated,e.pop()}}))},ve=function(t,e){return i(this,void 0,void 0,(function*(){if(0!==t.dependencies.length)for(const n of t.dependencies)yield r(this,ie,"m",we).call(this,n,e)}))},ye=function(t){return i(this,void 0,void 0,(function*(){yield Promise.all(t.relatedApps.map((t=>this.loadApp(t))))}))};const be={},_e="DEFAULT_BUS",Ee=(t=_e)=>{let e=null,n=!1;const s=((t=_e)=>window.RALLIE_BUS_STORE&&window.RALLIE_BUS_STORE[t])(t);return s?(e=s,n=!1):(e=((t=_e)=>{if(void 0===window.RALLIE_BUS_STORE&&Reflect.defineProperty(window,"RALLIE_BUS_STORE",{value:be,writable:!1}),window.RALLIE_BUS_STORE[t])throw new Error(Ut(t));{const e=new ge(t);return Reflect.defineProperty(window.RALLIE_BUS_STORE,t,{value:e,writable:!1}),e}})(t),n=!0),[e,n]},Se={privateBus:t=>`${t}.bus`,stateNamespace:t=>`${t}.state`,isGlobalBusAccessible:"isGlobalBusAccessible",exportMethodName:"__RallieInnerExport__"},ke=t=>`[rallie] ${t}`,Ae={stateNotInitialized:t=>ke(` the block ${t}'s state is not initialized, please check:\n1. whether the block ${t} is loaded.\n2. whether the block ${t} has initialized the state`),duplicatedBlockName:t=>ke(`the block ${t} is already registered before, please rename your block`),stateIsReadonly:t=>ke(`the state of ${t} is readonly`)},Re=(t,e)=>new Proxy(t,{get:(t,n)=>(...s)=>(0,t[n])(s,e),set:()=>!1}),Oe=t=>{const e={};return Object.entries(t).forEach((([t,n])=>{e[t]=(t,e)=>n.call({trigger:e},...t)})),e};var xe,Me,Pe,We,je,Be,$e;class Le{constructor(t,e,i){xe.set(this,void 0),this.name=t,s(this,xe,i,"f");const r=n(this,xe,"f").createBroadcaster(),o=n(this,xe,"f").createUnicaster();this.events=Re(r,e),this.methods=Re(o,e),Reflect.defineProperty(this,"state",{get:()=>n(this,xe,"f").getState(Se.stateNamespace(this.name)),set:()=>{throw new Error(Ae.stateIsReadonly(this.name))}})}setState(t,e){if(n(this,xe,"f").existState(Se.stateNamespace(this.name)))return n(this,xe,"f").setState(Se.stateNamespace(this.name),t,e);throw new Error(Ae.stateNotInitialized(this.name))}watchState(t){if(n(this,xe,"f").existState(Se.stateNamespace(this.name)))return n(this,xe,"f").watchState(Se.stateNamespace(this.name),t);throw new Error(Ae.stateNotInitialized(this.name))}listenEvents(t){return n(this,xe,"f").onBroadcast(Oe(t))}}xe=new WeakMap;class Te extends Le{constructor(t,e,n,i){const[r]=Ee(Se.privateBus(t)),o=r.createSocket();super(t,t,o),Me.set(this,void 0),Pe.set(this,void 0),We.set(this,void 0),je.set(this,void 0),Be.set(this,void 0),$e.set(this,{}),s(this,je,o,"f"),s(this,Me,e,"f"),s(this,Pe,n,"f"),s(this,Be,e.createApp(t),"f"),s(this,We,i,"f")}initState(t,e){return n(this,je,"f").initState(Se.stateNamespace(this.name),t,e),this}addMethods(t){return n(this,je,"f").onUnicast(Oe(t))}relyOn(t){return n(this,Be,"f").relyOn(t),this}relateTo(t){return n(this,Be,"f").relateTo(t),this}onActivate(t){return n(this,Be,"f").onActivate(t),this}connect(t){if(!n(this,$e,"f")[t]){const[e]=Ee(Se.privateBus(t)),s=e.createSocket();n(this,$e,"f")[t]=new Le(t,this.name,s)}return n(this,$e,"f")[t]}load(t){return n(this,Me,"f").loadApp(t)}activate(t){return n(this,Me,"f").activateApp(t)}run(t){var s;return e(this,void 0,void 0,(function*(){const e=n(this,We,"f")||(null===(s=n(this,Pe,"f").getState(Se.isGlobalBusAccessible))||void 0===s?void 0:s.value),i=t=>{n(this,We,"f")&&n(this,Pe,"f").setState(Se.isGlobalBusAccessible,t?"unfreeze the enviroment":"freeze the enviroment",(e=>{e.value=t}))},r={isEntry:n(this,We,"f"),use:t=>{e&&n(this,Me,"f").use(t)},config:t=>{e&&n(this,Me,"f").config(t)},freeze:()=>{i(!1)},unfreeze:()=>{i(!0)}},o=t(new Proxy(r,{get:(t,e,s)=>"conf"===e?JSON.parse(JSON.stringify(n(this,Me,"f").conf)):Reflect.get(t,e,s),set:()=>!1}));yield Promise.resolve(o)}))}}Me=new WeakMap,Pe=new WeakMap,We=new WeakMap,je=new WeakMap,Be=new WeakMap,$e=new WeakMap,t.createBlock=function(t){const[e,n]=Ee();if(e.existApp(t))throw new Error(Ae.duplicatedBlockName(t));const s=e.createSocket();return n&&s.initState(Se.isGlobalBusAccessible,{value:!0},!0),new Te(t,e,s,n)}})); |
{ | ||
"name": "@rallie/block", | ||
"version": "0.15.0", | ||
"version": "0.15.1", | ||
"description": "a progressive micro front framework", | ||
@@ -17,3 +17,3 @@ "main": "./dist/index.umd.js", | ||
"dependencies": { | ||
"@rallie/core": "0.15.0" | ||
"@rallie/core": "0.15.1" | ||
}, | ||
@@ -28,3 +28,3 @@ "repository": { | ||
"homepage": "https://github.com/ralliejs/rallie#readme", | ||
"gitHead": "cc71cecd94a81fcaa049fcd78319400ef60160b8" | ||
"gitHead": "c5fbcc7792b5f673ba54ca35b7460d8da2c29b14" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
73142
355
+ Added@rallie/core@0.15.1(transitive)
- Removed@rallie/core@0.15.0(transitive)
Updated@rallie/core@0.15.1