Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rallie/block

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rallie/block - npm Package Compare versions

Comparing version 0.16.0 to 0.16.1

2

./dist/index.umd.js

@@ -1,1 +0,1 @@

!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)}}));
!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,r){return new(n||(n=Promise))((function(i,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(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((r=r.apply(t,e||[])).next())}))}function n(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function r(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}function i(t,e,n,r){return new(n||(n=Promise))((function(i,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(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((r=r.apply(t,e||[])).next())}))}function s(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function o(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;const a=Object.assign,c=Object.prototype.hasOwnProperty,h=(t,e)=>c.call(t,e),l=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);function g(t,e=undefined){e&&e.active&&e.effects.push(t)}const b=t=>{const e=new Set(t);return e.w=0,e.n=0,e},E=t=>(t.w&O)>0,S=t=>(t.n&O)>0,_=new WeakMap;let k=0,O=1;const A=30;let R;const P=Symbol(""),x=Symbol("");class W{constructor(t,e=null,n){this.fn=t,this.scheduler=e,this.active=!0,this.deps=[],this.parent=void 0,g(this,n)}run(){if(!this.active)return this.fn();let t=R,e=M;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=R,R=this,M=!0,O=1<<++k,k<=A?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=O})(this):j(this),this.fn()}finally{k<=A&&(t=>{const{deps:e}=t;if(e.length){let n=0;for(let r=0;r<e.length;r++){const i=e[r];E(i)&&!S(i)?i.delete(t):e[n++]=i,i.w&=~O,i.n&=~O}e.length=n}})(this),O=1<<--k,R=this.parent,M=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){R===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 M=!0;const $=[];function L(t,e,n){if(M&&R){let e=_.get(t);e||_.set(t,e=new Map);let r=e.get(n);r||e.set(n,r=b()),function(t,e){let n=!1;k<=A?S(t)||(t.n|=O,n=!E(t)):n=!t.has(R),n&&(t.add(R),R.deps.push(t))}(r)}}function T(t,e,n,r,i,s){const o=_.get(t);if(!o)return;let a=[];if("clear"===e)a=[...o.values()];else if("length"===n&&l(t)){const t=Number(r);o.forEach(((e,n)=>{("length"===n||n>=t)&&a.push(e)}))}else switch(void 0!==n&&a.push(o.get(n)),e){case"add":l(t)?y(n)&&a.push(o.get("length")):(a.push(o.get(P)),f(t)&&a.push(o.get(x)));break;case"delete":l(t)||(a.push(o.get(P)),f(t)&&a.push(o.get(x)));break;case"set":f(t)&&a.push(o.get(P))}if(1===a.length)a[0]&&B(a[0]);else{const t=[];for(const e of a)e&&t.push(...e);B(b(t))}}function B(t,e){const n=l(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!==R||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}const z=function(t,e){const n=Object.create(null),r=t.split(",");for(let t=0;t<r.length;t++)n[r[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)),I=K(),N=K(!0),H=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++)L(n,0,t+"");const r=n[e](...t);return-1===r||!1===r?n[e](...t.map(bt)):r}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){$.push(M),M=!1;const n=bt(this)[e].apply(this,t);return function(){const t=$.pop();M=void 0===t||t}(),n}})),t}();function J(t){const e=bt(this);return L(e,0,t),e.hasOwnProperty(t)}function K(t=!1,e=!1){return function(n,r,i){if("__v_isReactive"===r)return!t;if("__v_isReadonly"===r)return t;if("__v_isShallow"===r)return e;if("__v_raw"===r&&i===(t?e?wt:pt:e?dt:ut).get(n))return n;const s=l(n);if(!t){if(s&&h(H,r))return Reflect.get(H,r,i);if("hasOwnProperty"===r)return J}const o=Reflect.get(n,r,i);return(u(r)?C.has(r):z(r))?o:(t||L(n,0,r),e?o:_t(o)?s&&y(r)?o:o.value:d(o)?t?yt(o):vt(o):o)}}const D={get:I,set:function(t=!1){return function(e,n,r,i){let s=e[n];if(gt(s)&&_t(s)&&!_t(r))return!1;if(!t&&(function(t){return!(!t||!t.__v_isShallow)}(r)||gt(r)||(s=bt(s),r=bt(r)),!l(e)&&_t(s)&&!_t(r)))return s.value=r,!0;const o=l(e)&&y(n)?Number(n)<e.length:h(e,n),a=Reflect.set(e,n,r,i);return e===bt(i)&&(o?m(r,s)&&T(e,"set",n,r):T(e,"add",n,r)),a}}(),deleteProperty:function(t,e){const n=h(t,e);t[e];const r=Reflect.deleteProperty(t,e);return r&&n&&T(t,"delete",e,void 0),r},has:function(t,e){const n=Reflect.has(t,e);return u(e)&&C.has(e)||L(t,0,e),n},ownKeys:function(t){return L(t,0,l(t)?"length":P),Reflect.ownKeys(t)}},F={get:N,set:(t,e)=>!0,deleteProperty:(t,e)=>!0},G=t=>t,V=t=>Reflect.getPrototypeOf(t);function q(t,e,n=!1,r=!1){const i=bt(t=t.__v_raw),s=bt(e);n||(e!==s&&L(i,0,e),L(i,0,s));const{has:o}=V(i),a=r?G:n?St:Et;return o.call(i,e)?a(t.get(e)):o.call(i,s)?a(t.get(s)):void(t!==i&&t.get(e))}function Q(t,e=!1){const n=this.__v_raw,r=bt(n),i=bt(t);return e||(t!==i&&L(r,0,t),L(r,0,i)),t===i?n.has(t):n.has(t)||n.has(i)}function X(t,e=!1){return t=t.__v_raw,!e&&L(bt(t),0,P),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:r,get:i}=V(n);let s=r.call(n,t);s||(t=bt(t),s=r.call(n,t));const o=i.call(n,t);return n.set(t,e),s?m(e,o)&&T(n,"set",t,e):T(n,"add",t,e),this}function tt(t){const e=bt(this),{has:n,get:r}=V(e);let i=n.call(e,t);i||(t=bt(t),i=n.call(e,t)),r&&r.call(e,t);const s=e.delete(t);return i&&T(e,"delete",t,void 0),s}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,r){const i=this,s=i.__v_raw,o=bt(s),a=e?G:t?St:Et;return!t&&L(o,0,P),s.forEach(((t,e)=>n.call(r,a(t),a(e),i)))}}function rt(t,e,n){return function(...r){const i=this.__v_raw,s=bt(i),o=f(s),a="entries"===t||t===Symbol.iterator&&o,c="keys"===t&&o,h=i[t](...r),l=n?G:e?St:Et;return!e&&L(s,0,c?x:P),{next(){const{value:t,done:e}=h.next();return e?{value:t,done:e}:{value:a?[l(t[0]),l(t[1])]:l(t),done:e}},[Symbol.iterator](){return this}}}}function it(t){return function(...e){return"delete"!==t&&this}}const[st,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)},r={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]=rt(i,!1,!1),n[i]=rt(i,!0,!1),e[i]=rt(i,!1,!0),r[i]=rt(i,!0,!0)})),[t,n,e,r]}();function ht(t,e){const n=e?t?ct:at:t?ot:st;return(e,r,i)=>"__v_isReactive"===r?!t:"__v_isReadonly"===r?t:"__v_raw"===r?e:Reflect.get(h(n,r)&&r in e?n:e,r,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,D,lt,ut)}function yt(t){return mt(t,!0,F,ft,pt)}function mt(t,e,n,r,i){if(!d(t))return t;if(t.__v_raw&&(!e||!t.__v_isReactive))return t;const s=i.get(t);if(s)return s;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?r: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 Et=t=>d(t)?vt(t):t,St=t=>d(t)?yt(t):t;function _t(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`,Ot=t=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${t}, but the listener hasn't been registed`,At=t=>`[@rallie/core] one of the callbacks of the broadcast event ${t} throws an uncaught error`,Rt=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`,Pt=t=>`[@rallie/core] you are trying to register a unicast event ${t}, but it has been registered before`,xt=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}`,Mt=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`,Bt=t=>`[@rallie/core] duplicated initialized state ${t}`,Ut=t=>`[@rallie/core] it's not allowed to initialized state ${t} to a primitive value`,zt=t=>`[@rallie/core] the bus named ${t} has been defined before, please rename your bus`,Ct=(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",Nt=()=>"[@rallie/core] the middleware must be a function",Ht=(t,e)=>`[@rallie/core] the event ${t} is not in the events pool that you specified when calling on${e?"Unicast":"Broadcast"}`,Jt=t=>(e,n)=>{let r=-1;const i=s=>{if(s<=r)return Promise.reject(new Error(It()));r=s;let o=t[s];if(s===t.length&&(o=n),!o)return Promise.resolve();try{return Promise.resolve(o(e,i.bind(null,s+1)))}catch(t){return Promise.reject(t)}};return i(0)};var Kt,Dt,Ft,Gt,Vt,qt,Qt,Xt,Yt;class Zt{constructor(){Kt.set(this,{}),Dt.set(this,{})}addBroadcastEventListener(t,e){s(this,Kt,"f")[t]=s(this,Kt,"f")[t]||new Set,s(this,Kt,"f")[t].add(e)}addUnicastEventListener(t,e){if(s(this,Dt,"f")[t])throw new Error(Pt(t));s(this,Dt,"f")[t]=e}removeBroadcastEventListener(t,e){const n=s(this,Kt,"f")[t];if(!n){const e=kt(t);throw new Error(e)}if(!n.has(e)){const e=Ot(t);throw new Error(e)}n.delete(e)}removeUnicastEventListener(t){if(!s(this,Dt,"f")[t]){const e=Rt(t);throw new Error(e)}delete s(this,Dt,"f")[t]}emitBroadcast(t,...e){s(this,Kt,"f")[t]=s(this,Kt,"f")[t]||new Set,s(this,Kt,"f")[t].forEach((n=>{try{n(...e)}catch(n){console.error(At(t)),console.error(n)}}))}emitUnicast(t,...e){const n=s(this,Dt,"f")[t];if(n)return n(...e);throw new Error(xt(t))}}Kt=new WeakMap,Dt=new WeakMap;class te{constructor(t,e){Ft.set(this,void 0),Gt.set(this,void 0),o(this,Ft,t,"f"),o(this,Gt,e,"f"),s(this,Gt,"f")[t].watchers.add(this)}do(t){return this.handler=t,()=>this.unwatch()}unwatch(){null==this||this.stopEffect(),this.handler=null;const t=s(this,Gt,"f")[s(this,Ft,"f")].watchers;t.has(this)&&t.delete(this)}}Ft=new WeakMap,Gt=new WeakMap;class ee{constructor(t,e){Vt.add(this),qt.set(this,void 0),Qt.set(this,void 0),o(this,qt,t,"f"),o(this,Qt,e,"f")}onBroadcast(t){return Object.entries(t).forEach((([t,e])=>{s(this,qt,"f").addBroadcastEventListener(t,e)})),e=>{s(this,Vt,"m",Xt).call(this,t,!1,e)}}onUnicast(t){return Object.entries(t).forEach((([t,e])=>{try{s(this,qt,"f").addUnicastEventListener(t,e)}catch(t){console.error(t)}})),e=>{s(this,Vt,"m",Xt).call(this,t,!0,e)}}createBroadcaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),s(this,qt,"f").emitBroadcast(n,...e)),set:()=>!1})}createUnicaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),s(this,qt,"f").emitUnicast(n,...e)),set:()=>!1})}existState(t){return!!s(this,Qt,"f")[t]}initState(t,e,n=!1){if(this.existState(t))throw new Error(Bt(t));if(["string","number","boolean","undefined"].includes(typeof e))throw new Error(Ut(t));return s(this,Qt,"f")[t]={state:vt(e),owner:n?this:null,watchers:new Set},s(this,qt,"f").emitBroadcast("$state-initialized",t),this.getState(t)}getState(t,e){if(this.existState(t)){const n=yt(s(this,Qt,"f")[t].state);return e?e(n):n}return null}setState(t,e,n){return i(this,void 0,void 0,(function*(){const r=s(this,Vt,"m",Yt).call(this,t);if(!e)throw new Error(Lt(t));{const t=n(r);yield Promise.resolve(t)}}))}watchState(t,e){if(!this.existState(t)){const e=Tt(t);throw new Error(e)}let n=!1;const r=yt(s(this,Qt,"f")[t].state),i=new te(t,s(this,Qt,"f")),o=function(t,e){t.effect&&(t=t.effect.fn);const n=new W(t);e&&(a(n,e),e.scope&&g(n,e.scope)),e&&e.lazy||n.run();const r=n.run.bind(n);return r.effect=n,r}((()=>e(r)),{lazy:!0,scheduler:()=>{n||(n=!0,Promise.resolve().then((()=>{var t;const s=bt(e(r));null===(t=i.handler)||void 0===t||t.call(i,s,i.oldWatchingStates),i.oldWatchingStates=bt(s),n=!1})))}});return i.oldWatchingStates=o(),i.stopEffect=()=>o.effect.stop(),i}}qt=new WeakMap,Qt=new WeakMap,Vt=new WeakSet,Xt=function(t,e,n){let r=e?s(this,qt,"f").removeUnicastEventListener:s(this,qt,"f").removeBroadcastEventListener;r=r.bind(s(this,qt,"f")),n?t[n]?(r(n,t[n]),delete t[n]):console.warn(Ht(n,e)):Object.entries(t).forEach((([t,e])=>{r(t,e)}))},Yt=function(t){if(!this.existState(t)){const e=Tt(t);throw new Error(e)}const e=s(this,Qt,"f")[t].owner;if(e!==this&&null!==e){const e=$t(t);throw new Error(e)}return s(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 re,ie,se,oe,ae,ce,he,le,fe,ue,de,pe,we,ve,ye={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 me{constructor(t){re.add(this),ie.set(this,void 0),se.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),o(this,ie,t,"f"),o(this,le,Jt(s(this,he,"f")),"f")}createSocket(){return new ee(s(this,se,"f"),s(this,oe,"f"))}existApp(t){return!!s(this,ae,"f")[t]}createApp(t){if(this.existApp(t))throw new Error(Wt(t));const e=new ne(t);return s(this,ae,"f")[t]=e,e}loadApp(t){return i(this,void 0,void 0,(function*(){s(this,ae,"f")[t]||(s(this,ce,"f")[t]||(s(this,ce,"f")[t]=new Promise(((e,n)=>{const r=s(this,re,"m",ue).call(this,t);s(this,le,"f").call(this,r,s(this,re,"m",de).bind(this)).then((()=>{t.startsWith("lib:")&&!s(this,ae,"f")[t]&&(s(this,ae,"f")[t]=!0),s(this,ae,"f")[t]||n(new Error(Mt(t))),e()})).catch((t=>{n(t)}))}))),yield s(this,ce,"f")[t])}))}activateApp(t){return i(this,void 0,void 0,(function*(){yield s(this,re,"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(Nt());return s(this,he,"f").push(t),o(this,le,Jt(s(this,he,"f")),"f"),this}}ie=new WeakMap,se=new WeakMap,oe=new WeakMap,ae=new WeakMap,ce=new WeakMap,he=new WeakMap,le=new WeakMap,re=new WeakSet,fe=function(t){return s(this,ae,"f")[t]&&"boolean"!=typeof s(this,ae,"f")[t]},ue=function(t){return{name:t,loadScript:ye.loadScript,loadLink:ye.loadLink}},de=function(t){return i(this,void 0,void 0,(function*(){const{name:e,loadScript:n=ye.loadScript,loadLink:r=ye.loadLink}=t,{assets:i}=this.conf;if(!i[e])throw new Error(jt(e,s(this,ie,"f")));if(i[e].css&&i[e].css.forEach((t=>{r(t)})),i[e].js)for(const t of i[e].js)yield n(t)}))},pe=function(t,e){return i(this,void 0,void 0,(function*(){if(yield this.loadApp(t),s(this,re,"m",fe).call(this,t)){const n=s(this,ae,"f")[t];if(yield s(this,re,"m",ve).call(this,n),e.includes(t)){const n=e.indexOf(t),r=[...e.slice(n),t];throw new Error(Ct(t,r))}if(e.push(t),!n.activated){const t=()=>i(this,void 0,void 0,(function*(){yield s(this,re,"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 i(this,void 0,void 0,(function*(){if(0!==t.dependencies.length)for(const n of t.dependencies)yield s(this,re,"m",pe).call(this,n,e)}))},ve=function(t){return i(this,void 0,void 0,(function*(){yield Promise.all(t.relatedApps.map((t=>this.loadApp(t))))}))};const ge={},be="DEFAULT_BUS",Ee=(t=be)=>{let e=null,n=!1;const r=((t=be)=>window.RALLIE_BUS_STORE&&window.RALLIE_BUS_STORE[t])(t);return r?(e=r,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(zt(t));{const e=new me(t);return Reflect.defineProperty(window.RALLIE_BUS_STORE,t,{value:e,writable:!1}),e}})(t),n=!0),[e,n]},Se=t=>`${t}.bus`,_e=t=>`${t}.state`,ke="isGlobalBusAccessible",Oe=t=>`[rallie] ${t}`,Ae=t=>Oe(` 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`),Re=t=>Oe(`the block ${t} is already registered before, please rename your block`),Pe=t=>Oe(`the state of ${t} is readonly`),xe=(t,e)=>new Proxy(t,{get:(t,n)=>(...r)=>(0,t[n])(r,e),set:()=>!1}),We=t=>{const e={};return Object.entries(t).forEach((([t,n])=>{e[t]=(t,e)=>n.call({trigger:e},...t)})),e};var je,Me,$e,Le,Te,Be,Ue;class ze{constructor(t,e,i){je.set(this,void 0),this.name=t,r(this,je,i,"f");const s=n(this,je,"f").createBroadcaster(),o=n(this,je,"f").createUnicaster();this.events=xe(s,e),this.methods=xe(o,e),Reflect.defineProperty(this,"state",{get:()=>n(this,je,"f").getState(_e(this.name)),set:()=>{throw new Error(Pe(this.name))}})}setState(t,e){if(n(this,je,"f").existState(_e(this.name)))return n(this,je,"f").setState(_e(this.name),t,e);throw new Error(Ae(this.name))}watchState(t){if(n(this,je,"f").existState(_e(this.name)))return n(this,je,"f").watchState(_e(this.name),t);throw new Error(Ae(this.name))}listenEvents(t){return n(this,je,"f").onBroadcast(We(t))}}je=new WeakMap;class Ce extends ze{constructor(t,e,n,i){const[s]=Ee(Se(t)),o=s.createSocket();super(t,t,o),Me.set(this,void 0),$e.set(this,void 0),Le.set(this,void 0),Te.set(this,void 0),Be.set(this,void 0),Ue.set(this,{}),r(this,Te,o,"f"),r(this,Me,e,"f"),r(this,$e,n,"f"),r(this,Be,e.createApp(t),"f"),r(this,Le,i,"f")}initState(t,e){return n(this,Te,"f").initState(_e(this.name),t,e),this}addMethods(t){return n(this,Te,"f").onUnicast(We(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,Ue,"f")[t]){const[e]=Ee(Se(t)),r=e.createSocket();n(this,Ue,"f")[t]=new ze(t,this.name,r)}return n(this,Ue,"f")[t]}load(t){return n(this,Me,"f").loadApp(t)}activate(t){return n(this,Me,"f").activateApp(t)}run(t){var r;return e(this,void 0,void 0,(function*(){const e=n(this,Le,"f")||(null===(r=n(this,$e,"f").getState(ke))||void 0===r?void 0:r.value),i=t=>{n(this,Le,"f")&&n(this,$e,"f").setState(ke,t?"unfreeze the enviroment":"freeze the enviroment",(e=>{e.value=t}))},s={isEntry:n(this,Le,"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(s,{get:(t,e,r)=>"conf"===e?JSON.parse(JSON.stringify(n(this,Me,"f").conf)):Reflect.get(t,e,r),set:()=>!1}));yield Promise.resolve(o)}))}}Me=new WeakMap,$e=new WeakMap,Le=new WeakMap,Te=new WeakMap,Be=new WeakMap,Ue=new WeakMap,t.createBlock=function(t){const[e,n]=Ee();if(e.existApp(t))throw new Error(Re(t));const r=e.createSocket();return n&&r.initState(ke,{value:!0},!0),new Ce(t,e,r,n)}}));

@@ -0,0 +0,0 @@ import type { Socket } from '@rallie/core';

@@ -0,0 +0,0 @@ import { Bus, Socket, MiddlewareFnType, ConfType } from '@rallie/core';

@@ -0,0 +0,0 @@ import { CreatedBlock } from './created-block';

@@ -1,1 +0,1 @@

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};
function t(t,e,n,r){return new(n||(n=Promise))((function(i,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(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((r=r.apply(t,e||[])).next())}))}function e(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function n(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}function r(t,e,n,r){return new(n||(n=Promise))((function(i,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(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((r=r.apply(t,e||[])).next())}))}function i(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function s(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;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);function m(t,e=undefined){e&&e.active&&e.effects.push(t)}const g=t=>{const e=new Set(t);return e.w=0,e.n=0,e},b=t=>(t.w&k)>0,E=t=>(t.n&k)>0,S=new WeakMap;let _=0,k=1;const O=30;let A;const P=Symbol(""),R=Symbol("");class W{constructor(t,e=null,n){this.fn=t,this.scheduler=e,this.active=!0,this.deps=[],this.parent=void 0,m(this,n)}run(){if(!this.active)return this.fn();let t=A,e=j;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=A,A=this,j=!0,k=1<<++_,_<=O?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=k})(this):M(this),this.fn()}finally{_<=O&&(t=>{const{deps:e}=t;if(e.length){let n=0;for(let r=0;r<e.length;r++){const i=e[r];b(i)&&!E(i)?i.delete(t):e[n++]=i,i.w&=~k,i.n&=~k}e.length=n}})(this),k=1<<--_,A=this.parent,j=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){A===this?this.deferStop=!0:this.active&&(M(this),this.onStop&&this.onStop(),this.active=!1)}}function M(t){const{deps:e}=t;if(e.length){for(let n=0;n<e.length;n++)e[n].delete(t);e.length=0}}let j=!0;const x=[];function $(t,e,n){if(j&&A){let e=S.get(t);e||S.set(t,e=new Map);let r=e.get(n);r||e.set(n,r=g()),function(t,e){let n=!1;_<=O?E(t)||(t.n|=k,n=!b(t)):n=!t.has(A),n&&(t.add(A),A.deps.push(t))}(r)}}function L(t,e,n,r,i,s){const o=S.get(t);if(!o)return;let a=[];if("clear"===e)a=[...o.values()];else if("length"===n&&h(t)){const t=Number(r);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(P)),l(t)&&a.push(o.get(R)));break;case"delete":h(t)||(a.push(o.get(P)),l(t)&&a.push(o.get(R)));break;case"set":l(t)&&a.push(o.get(P))}if(1===a.length)a[0]&&T(a[0]);else{const t=[];for(const e of a)e&&t.push(...e);T(g(t))}}function T(t,e){const n=h(t)?t:[...t];for(const t of n)t.computed&&B(t);for(const t of n)t.computed||B(t)}function B(t,e){(t!==A||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}const U=function(t,e){const n=Object.create(null),r=t.split(",");for(let t=0;t<r.length;t++)n[r[t]]=!0;return e?t=>!!n[t.toLowerCase()]:t=>!!n[t]}("__proto__,__v_isRef,__isVue"),z=new Set(Object.getOwnPropertyNames(Symbol).filter((t=>"arguments"!==t&&"caller"!==t)).map((t=>Symbol[t])).filter(f)),C=J(),I=J(!0),N=function(){const t={};return["includes","indexOf","lastIndexOf"].forEach((e=>{t[e]=function(...t){const n=gt(this);for(let t=0,e=this.length;t<e;t++)$(n,0,t+"");const r=n[e](...t);return-1===r||!1===r?n[e](...t.map(gt)):r}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){x.push(j),j=!1;const n=gt(this)[e].apply(this,t);return function(){const t=x.pop();j=void 0===t||t}(),n}})),t}();function H(t){const e=gt(this);return $(e,0,t),e.hasOwnProperty(t)}function J(t=!1,e=!1){return function(n,r,i){if("__v_isReactive"===r)return!t;if("__v_isReadonly"===r)return t;if("__v_isShallow"===r)return e;if("__v_raw"===r&&i===(t?e?pt:dt:e?ut:ft).get(n))return n;const s=h(n);if(!t){if(s&&c(N,r))return Reflect.get(N,r,i);if("hasOwnProperty"===r)return H}const o=Reflect.get(n,r,i);return(f(r)?z.has(r):U(r))?o:(t||$(n,0,r),e?o:St(o)?s&&v(r)?o:o.value:u(o)?t?vt(o):wt(o):o)}}const K={get:C,set:function(t=!1){return function(e,n,r,i){let s=e[n];if(mt(s)&&St(s)&&!St(r))return!1;if(!t&&(function(t){return!(!t||!t.__v_isShallow)}(r)||mt(r)||(s=gt(s),r=gt(r)),!h(e)&&St(s)&&!St(r)))return s.value=r,!0;const o=h(e)&&v(n)?Number(n)<e.length:c(e,n),a=Reflect.set(e,n,r,i);return e===gt(i)&&(o?y(r,s)&&L(e,"set",n,r):L(e,"add",n,r)),a}}(),deleteProperty:function(t,e){const n=c(t,e);t[e];const r=Reflect.deleteProperty(t,e);return r&&n&&L(t,"delete",e,void 0),r},has:function(t,e){const n=Reflect.has(t,e);return f(e)&&z.has(e)||$(t,0,e),n},ownKeys:function(t){return $(t,0,h(t)?"length":P),Reflect.ownKeys(t)}},D={get:I,set:(t,e)=>!0,deleteProperty:(t,e)=>!0},F=t=>t,G=t=>Reflect.getPrototypeOf(t);function V(t,e,n=!1,r=!1){const i=gt(t=t.__v_raw),s=gt(e);n||(e!==s&&$(i,0,e),$(i,0,s));const{has:o}=G(i),a=r?F:n?Et:bt;return o.call(i,e)?a(t.get(e)):o.call(i,s)?a(t.get(s)):void(t!==i&&t.get(e))}function q(t,e=!1){const n=this.__v_raw,r=gt(n),i=gt(t);return e||(t!==i&&$(r,0,t),$(r,0,i)),t===i?n.has(t):n.has(t)||n.has(i)}function Q(t,e=!1){return t=t.__v_raw,!e&&$(gt(t),0,P),Reflect.get(t,"size",t)}function X(t){t=gt(t);const e=gt(this);return G(e).has.call(e,t)||(e.add(t),L(e,"add",t,t)),this}function Y(t,e){e=gt(e);const n=gt(this),{has:r,get:i}=G(n);let s=r.call(n,t);s||(t=gt(t),s=r.call(n,t));const o=i.call(n,t);return n.set(t,e),s?y(e,o)&&L(n,"set",t,e):L(n,"add",t,e),this}function Z(t){const e=gt(this),{has:n,get:r}=G(e);let i=n.call(e,t);i||(t=gt(t),i=n.call(e,t)),r&&r.call(e,t);const s=e.delete(t);return i&&L(e,"delete",t,void 0),s}function tt(){const t=gt(this),e=0!==t.size,n=t.clear();return e&&L(t,"clear",void 0,void 0),n}function et(t,e){return function(n,r){const i=this,s=i.__v_raw,o=gt(s),a=e?F:t?Et:bt;return!t&&$(o,0,P),s.forEach(((t,e)=>n.call(r,a(t),a(e),i)))}}function nt(t,e,n){return function(...r){const i=this.__v_raw,s=gt(i),o=l(s),a="entries"===t||t===Symbol.iterator&&o,c="keys"===t&&o,h=i[t](...r),f=n?F:e?Et:bt;return!e&&$(s,0,c?R:P),{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 rt(t){return function(...e){return"delete"!==t&&this}}const[it,st,ot,at]=function(){const t={get(t){return V(this,t)},get size(){return Q(this)},has:q,add:X,set:Y,delete:Z,clear:tt,forEach:et(!1,!1)},e={get(t){return V(this,t,!1,!0)},get size(){return Q(this)},has:q,add:X,set:Y,delete:Z,clear:tt,forEach:et(!1,!0)},n={get(t){return V(this,t,!0)},get size(){return Q(this,!0)},has(t){return q.call(this,t,!0)},add:rt("add"),set:rt("set"),delete:rt("delete"),clear:rt("clear"),forEach:et(!0,!1)},r={get(t){return V(this,t,!0,!0)},get size(){return Q(this,!0)},has(t){return q.call(this,t,!0)},add:rt("add"),set:rt("set"),delete:rt("delete"),clear:rt("clear"),forEach:et(!0,!0)};return["keys","values","entries",Symbol.iterator].forEach((i=>{t[i]=nt(i,!1,!1),n[i]=nt(i,!0,!1),e[i]=nt(i,!1,!0),r[i]=nt(i,!0,!0)})),[t,n,e,r]}();function ct(t,e){const n=e?t?at:ot:t?st:it;return(e,r,i)=>"__v_isReactive"===r?!t:"__v_isReadonly"===r?t:"__v_raw"===r?e:Reflect.get(c(n,r)&&r in e?n:e,r,i)}const ht={get:ct(!1,!1)},lt={get:ct(!0,!1)},ft=new WeakMap,ut=new WeakMap,dt=new WeakMap,pt=new WeakMap;function wt(t){return mt(t)?t:yt(t,!1,K,ht,ft)}function vt(t){return yt(t,!0,D,lt,dt)}function yt(t,e,n,r,i){if(!u(t))return t;if(t.__v_raw&&(!e||!t.__v_isReactive))return t;const s=i.get(t);if(s)return s;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?r:n);return i.set(t,c),c}function mt(t){return!(!t||!t.__v_isReadonly)}function gt(t){const e=t&&t.__v_raw;return e?gt(e):t}const bt=t=>u(t)?wt(t):t,Et=t=>u(t)?vt(t):t;function St(t){return!(!t||!0!==t.__v_isRef)}const _t=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`,kt=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`,At=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`,Pt=t=>`[@rallie/core] you are trying to register a unicast event ${t}, but it has been registered before`,Rt=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`,Mt=(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`,xt=t=>`[@rallie/core] state ${t} is private, you are not allowed to set it`,$t=t=>`[@rallie/core] please describe your action when you modify the state ${t}`,Lt=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}`,Bt=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`,zt=(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",It=()=>"[@rallie/core] the middleware must be a function",Nt=(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 r=-1;const i=s=>{if(s<=r)return Promise.reject(new Error(Ct()));r=s;let o=t[s];if(s===t.length&&(o=n),!o)return Promise.resolve();try{return Promise.resolve(o(e,i.bind(null,s+1)))}catch(t){return Promise.reject(t)}};return i(0)};var Jt,Kt,Dt,Ft,Gt,Vt,qt,Qt,Xt;class Yt{constructor(){Jt.set(this,{}),Kt.set(this,{})}addBroadcastEventListener(t,e){i(this,Jt,"f")[t]=i(this,Jt,"f")[t]||new Set,i(this,Jt,"f")[t].add(e)}addUnicastEventListener(t,e){if(i(this,Kt,"f")[t])throw new Error(Pt(t));i(this,Kt,"f")[t]=e}removeBroadcastEventListener(t,e){const n=i(this,Jt,"f")[t];if(!n){const e=_t(t);throw new Error(e)}if(!n.has(e)){const e=kt(t);throw new Error(e)}n.delete(e)}removeUnicastEventListener(t){if(!i(this,Kt,"f")[t]){const e=At(t);throw new Error(e)}delete i(this,Kt,"f")[t]}emitBroadcast(t,...e){i(this,Jt,"f")[t]=i(this,Jt,"f")[t]||new Set,i(this,Jt,"f")[t].forEach((n=>{try{n(...e)}catch(n){console.error(Ot(t)),console.error(n)}}))}emitUnicast(t,...e){const n=i(this,Kt,"f")[t];if(n)return n(...e);throw new Error(Rt(t))}}Jt=new WeakMap,Kt=new WeakMap;class Zt{constructor(t,e){Dt.set(this,void 0),Ft.set(this,void 0),s(this,Dt,t,"f"),s(this,Ft,e,"f"),i(this,Ft,"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,Ft,"f")[i(this,Dt,"f")].watchers;t.has(this)&&t.delete(this)}}Dt=new WeakMap,Ft=new WeakMap;class te{constructor(t,e){Gt.add(this),Vt.set(this,void 0),qt.set(this,void 0),s(this,Vt,t,"f"),s(this,qt,e,"f")}onBroadcast(t){return Object.entries(t).forEach((([t,e])=>{i(this,Vt,"f").addBroadcastEventListener(t,e)})),e=>{i(this,Gt,"m",Qt).call(this,t,!1,e)}}onUnicast(t){return Object.entries(t).forEach((([t,e])=>{try{i(this,Vt,"f").addUnicastEventListener(t,e)}catch(t){console.error(t)}})),e=>{i(this,Gt,"m",Qt).call(this,t,!0,e)}}createBroadcaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),i(this,Vt,"f").emitBroadcast(n,...e)),set:()=>!1})}createUnicaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),i(this,Vt,"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(Bt(t));return i(this,qt,"f")[t]={state:wt(e),owner:n?this:null,watchers:new Set},i(this,Vt,"f").emitBroadcast("$state-initialized",t),this.getState(t)}getState(t,e){if(this.existState(t)){const n=vt(i(this,qt,"f")[t].state);return e?e(n):n}return null}setState(t,e,n){return r(this,void 0,void 0,(function*(){const r=i(this,Gt,"m",Xt).call(this,t);if(!e)throw new Error($t(t));{const t=n(r);yield Promise.resolve(t)}}))}watchState(t,e){if(!this.existState(t)){const e=Lt(t);throw new Error(e)}let n=!1;const r=vt(i(this,qt,"f")[t].state),s=new Zt(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&&m(n,e.scope)),e&&e.lazy||n.run();const r=n.run.bind(n);return r.effect=n,r}((()=>e(r)),{lazy:!0,scheduler:()=>{n||(n=!0,Promise.resolve().then((()=>{var t;const i=gt(e(r));null===(t=s.handler)||void 0===t||t.call(s,i,s.oldWatchingStates),s.oldWatchingStates=gt(i),n=!1})))}});return s.oldWatchingStates=a(),s.stopEffect=()=>a.effect.stop(),s}}Vt=new WeakMap,qt=new WeakMap,Gt=new WeakSet,Qt=function(t,e,n){let r=e?i(this,Vt,"f").removeUnicastEventListener:i(this,Vt,"f").removeBroadcastEventListener;r=r.bind(i(this,Vt,"f")),n?t[n]?(r(n,t[n]),delete t[n]):console.warn(Nt(n,e)):Object.entries(t).forEach((([t,e])=>{r(t,e)}))},Xt=function(t){if(!this.existState(t)){const e=Lt(t);throw new Error(e)}const e=i(this,qt,"f")[t].owner;if(e!==this&&null!==e){const e=xt(t);throw new Error(e)}return i(this,qt,"f")[t].state};class ee{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 ne,re,ie,se,oe,ae,ce,he,le,fe,ue,de,pe,we,ve={loadScript:t=>r(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 ye{constructor(t){ne.add(this),re.set(this,void 0),ie.set(this,new Yt),se.set(this,{}),oe.set(this,{}),ae.set(this,{}),this.conf=vt({assets:{}}),ce.set(this,[]),he.set(this,void 0),s(this,re,t,"f"),s(this,he,Ht(i(this,ce,"f")),"f")}createSocket(){return new te(i(this,ie,"f"),i(this,se,"f"))}existApp(t){return!!i(this,oe,"f")[t]}createApp(t){if(this.existApp(t))throw new Error(Wt(t));const e=new ee(t);return i(this,oe,"f")[t]=e,e}loadApp(t){return r(this,void 0,void 0,(function*(){i(this,oe,"f")[t]||(i(this,ae,"f")[t]||(i(this,ae,"f")[t]=new Promise(((e,n)=>{const r=i(this,ne,"m",fe).call(this,t);i(this,he,"f").call(this,r,i(this,ne,"m",ue).bind(this)).then((()=>{t.startsWith("lib:")&&!i(this,oe,"f")[t]&&(i(this,oe,"f")[t]=!0),i(this,oe,"f")[t]||n(new Error(jt(t))),e()})).catch((t=>{n(t)}))}))),yield i(this,ae,"f")[t])}))}activateApp(t){return r(this,void 0,void 0,(function*(){yield i(this,ne,"m",de).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(It());return i(this,ce,"f").push(t),s(this,he,Ht(i(this,ce,"f")),"f"),this}}re=new WeakMap,ie=new WeakMap,se=new WeakMap,oe=new WeakMap,ae=new WeakMap,ce=new WeakMap,he=new WeakMap,ne=new WeakSet,le=function(t){return i(this,oe,"f")[t]&&"boolean"!=typeof i(this,oe,"f")[t]},fe=function(t){return{name:t,loadScript:ve.loadScript,loadLink:ve.loadLink}},ue=function(t){return r(this,void 0,void 0,(function*(){const{name:e,loadScript:n=ve.loadScript,loadLink:r=ve.loadLink}=t,{assets:s}=this.conf;if(!s[e])throw new Error(Mt(e,i(this,re,"f")));if(s[e].css&&s[e].css.forEach((t=>{r(t)})),s[e].js)for(const t of s[e].js)yield n(t)}))},de=function(t,e){return r(this,void 0,void 0,(function*(){if(yield this.loadApp(t),i(this,ne,"m",le).call(this,t)){const n=i(this,oe,"f")[t];if(yield i(this,ne,"m",we).call(this,n),e.includes(t)){const n=e.indexOf(t),r=[...e.slice(n),t];throw new Error(zt(t,r))}if(e.push(t),!n.activated){const t=()=>r(this,void 0,void 0,(function*(){yield i(this,ne,"m",pe).call(this,n,e),n.doActivate&&(yield Promise.resolve(n.doActivate()))}));n.activated=t()}yield n.activated,e.pop()}}))},pe=function(t,e){return r(this,void 0,void 0,(function*(){if(0!==t.dependencies.length)for(const n of t.dependencies)yield i(this,ne,"m",de).call(this,n,e)}))},we=function(t){return r(this,void 0,void 0,(function*(){yield Promise.all(t.relatedApps.map((t=>this.loadApp(t))))}))};const me={},ge="DEFAULT_BUS",be=(t=ge)=>{let e=null,n=!1;const r=((t=ge)=>window.RALLIE_BUS_STORE&&window.RALLIE_BUS_STORE[t])(t);return r?(e=r,n=!1):(e=((t=ge)=>{if(void 0===window.RALLIE_BUS_STORE&&Reflect.defineProperty(window,"RALLIE_BUS_STORE",{value:me,writable:!1}),window.RALLIE_BUS_STORE[t])throw new Error(Ut(t));{const e=new ye(t);return Reflect.defineProperty(window.RALLIE_BUS_STORE,t,{value:e,writable:!1}),e}})(t),n=!0),[e,n]},Ee=t=>`${t}.bus`,Se=t=>`${t}.state`,_e="isGlobalBusAccessible",ke=t=>`[rallie] ${t}`,Oe=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`),Ae=t=>ke(`the block ${t} is already registered before, please rename your block`),Pe=t=>ke(`the state of ${t} is readonly`),Re=(t,e)=>new Proxy(t,{get:(t,n)=>(...r)=>(0,t[n])(r,e),set:()=>!1}),We=t=>{const e={};return Object.entries(t).forEach((([t,n])=>{e[t]=(t,e)=>n.call({trigger:e},...t)})),e};var Me,je,xe,$e,Le,Te,Be;class Ue{constructor(t,r,i){Me.set(this,void 0),this.name=t,n(this,Me,i,"f");const s=e(this,Me,"f").createBroadcaster(),o=e(this,Me,"f").createUnicaster();this.events=Re(s,r),this.methods=Re(o,r),Reflect.defineProperty(this,"state",{get:()=>e(this,Me,"f").getState(Se(this.name)),set:()=>{throw new Error(Pe(this.name))}})}setState(t,n){if(e(this,Me,"f").existState(Se(this.name)))return e(this,Me,"f").setState(Se(this.name),t,n);throw new Error(Oe(this.name))}watchState(t){if(e(this,Me,"f").existState(Se(this.name)))return e(this,Me,"f").watchState(Se(this.name),t);throw new Error(Oe(this.name))}listenEvents(t){return e(this,Me,"f").onBroadcast(We(t))}}Me=new WeakMap;class ze extends Ue{constructor(t,e,r,i){const[s]=be(Ee(t)),o=s.createSocket();super(t,t,o),je.set(this,void 0),xe.set(this,void 0),$e.set(this,void 0),Le.set(this,void 0),Te.set(this,void 0),Be.set(this,{}),n(this,Le,o,"f"),n(this,je,e,"f"),n(this,xe,r,"f"),n(this,Te,e.createApp(t),"f"),n(this,$e,i,"f")}initState(t,n){return e(this,Le,"f").initState(Se(this.name),t,n),this}addMethods(t){return e(this,Le,"f").onUnicast(We(t))}relyOn(t){return e(this,Te,"f").relyOn(t),this}relateTo(t){return e(this,Te,"f").relateTo(t),this}onActivate(t){return e(this,Te,"f").onActivate(t),this}connect(t){if(!e(this,Be,"f")[t]){const[n]=be(Ee(t)),r=n.createSocket();e(this,Be,"f")[t]=new Ue(t,this.name,r)}return e(this,Be,"f")[t]}load(t){return e(this,je,"f").loadApp(t)}activate(t){return e(this,je,"f").activateApp(t)}run(n){var r;return t(this,void 0,void 0,(function*(){const t=e(this,$e,"f")||(null===(r=e(this,xe,"f").getState(_e))||void 0===r?void 0:r.value),i=t=>{e(this,$e,"f")&&e(this,xe,"f").setState(_e,t?"unfreeze the enviroment":"freeze the enviroment",(e=>{e.value=t}))},s={isEntry:e(this,$e,"f"),use:n=>{t&&e(this,je,"f").use(n)},config:n=>{t&&e(this,je,"f").config(n)},freeze:()=>{i(!1)},unfreeze:()=>{i(!0)}},o=n(new Proxy(s,{get:(t,n,r)=>"conf"===n?JSON.parse(JSON.stringify(e(this,je,"f").conf)):Reflect.get(t,n,r),set:()=>!1}));yield Promise.resolve(o)}))}}function Ce(t){const[e,n]=be();if(e.existApp(t))throw new Error(Ae(t));const r=e.createSocket();return n&&r.initState(_e,{value:!0},!0),new ze(t,e,r,n)}je=new WeakMap,xe=new WeakMap,$e=new WeakMap,Le=new WeakMap,Te=new WeakMap,Be=new WeakMap;export{Ce as createBlock};

@@ -1,1 +0,1 @@

!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)}}));
!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,r){return new(n||(n=Promise))((function(i,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(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((r=r.apply(t,e||[])).next())}))}function n(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function r(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}function i(t,e,n,r){return new(n||(n=Promise))((function(i,s){function o(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(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((r=r.apply(t,e||[])).next())}))}function s(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function o(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError,"function"==typeof SuppressedError&&SuppressedError;const a=Object.assign,c=Object.prototype.hasOwnProperty,h=(t,e)=>c.call(t,e),l=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);function g(t,e=undefined){e&&e.active&&e.effects.push(t)}const b=t=>{const e=new Set(t);return e.w=0,e.n=0,e},E=t=>(t.w&O)>0,S=t=>(t.n&O)>0,_=new WeakMap;let k=0,O=1;const A=30;let R;const P=Symbol(""),x=Symbol("");class W{constructor(t,e=null,n){this.fn=t,this.scheduler=e,this.active=!0,this.deps=[],this.parent=void 0,g(this,n)}run(){if(!this.active)return this.fn();let t=R,e=M;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=R,R=this,M=!0,O=1<<++k,k<=A?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=O})(this):j(this),this.fn()}finally{k<=A&&(t=>{const{deps:e}=t;if(e.length){let n=0;for(let r=0;r<e.length;r++){const i=e[r];E(i)&&!S(i)?i.delete(t):e[n++]=i,i.w&=~O,i.n&=~O}e.length=n}})(this),O=1<<--k,R=this.parent,M=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){R===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 M=!0;const $=[];function L(t,e,n){if(M&&R){let e=_.get(t);e||_.set(t,e=new Map);let r=e.get(n);r||e.set(n,r=b()),function(t,e){let n=!1;k<=A?S(t)||(t.n|=O,n=!E(t)):n=!t.has(R),n&&(t.add(R),R.deps.push(t))}(r)}}function T(t,e,n,r,i,s){const o=_.get(t);if(!o)return;let a=[];if("clear"===e)a=[...o.values()];else if("length"===n&&l(t)){const t=Number(r);o.forEach(((e,n)=>{("length"===n||n>=t)&&a.push(e)}))}else switch(void 0!==n&&a.push(o.get(n)),e){case"add":l(t)?y(n)&&a.push(o.get("length")):(a.push(o.get(P)),f(t)&&a.push(o.get(x)));break;case"delete":l(t)||(a.push(o.get(P)),f(t)&&a.push(o.get(x)));break;case"set":f(t)&&a.push(o.get(P))}if(1===a.length)a[0]&&B(a[0]);else{const t=[];for(const e of a)e&&t.push(...e);B(b(t))}}function B(t,e){const n=l(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!==R||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}const z=function(t,e){const n=Object.create(null),r=t.split(",");for(let t=0;t<r.length;t++)n[r[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)),I=K(),N=K(!0),H=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++)L(n,0,t+"");const r=n[e](...t);return-1===r||!1===r?n[e](...t.map(bt)):r}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){$.push(M),M=!1;const n=bt(this)[e].apply(this,t);return function(){const t=$.pop();M=void 0===t||t}(),n}})),t}();function J(t){const e=bt(this);return L(e,0,t),e.hasOwnProperty(t)}function K(t=!1,e=!1){return function(n,r,i){if("__v_isReactive"===r)return!t;if("__v_isReadonly"===r)return t;if("__v_isShallow"===r)return e;if("__v_raw"===r&&i===(t?e?wt:pt:e?dt:ut).get(n))return n;const s=l(n);if(!t){if(s&&h(H,r))return Reflect.get(H,r,i);if("hasOwnProperty"===r)return J}const o=Reflect.get(n,r,i);return(u(r)?C.has(r):z(r))?o:(t||L(n,0,r),e?o:_t(o)?s&&y(r)?o:o.value:d(o)?t?yt(o):vt(o):o)}}const D={get:I,set:function(t=!1){return function(e,n,r,i){let s=e[n];if(gt(s)&&_t(s)&&!_t(r))return!1;if(!t&&(function(t){return!(!t||!t.__v_isShallow)}(r)||gt(r)||(s=bt(s),r=bt(r)),!l(e)&&_t(s)&&!_t(r)))return s.value=r,!0;const o=l(e)&&y(n)?Number(n)<e.length:h(e,n),a=Reflect.set(e,n,r,i);return e===bt(i)&&(o?m(r,s)&&T(e,"set",n,r):T(e,"add",n,r)),a}}(),deleteProperty:function(t,e){const n=h(t,e);t[e];const r=Reflect.deleteProperty(t,e);return r&&n&&T(t,"delete",e,void 0),r},has:function(t,e){const n=Reflect.has(t,e);return u(e)&&C.has(e)||L(t,0,e),n},ownKeys:function(t){return L(t,0,l(t)?"length":P),Reflect.ownKeys(t)}},F={get:N,set:(t,e)=>!0,deleteProperty:(t,e)=>!0},G=t=>t,V=t=>Reflect.getPrototypeOf(t);function q(t,e,n=!1,r=!1){const i=bt(t=t.__v_raw),s=bt(e);n||(e!==s&&L(i,0,e),L(i,0,s));const{has:o}=V(i),a=r?G:n?St:Et;return o.call(i,e)?a(t.get(e)):o.call(i,s)?a(t.get(s)):void(t!==i&&t.get(e))}function Q(t,e=!1){const n=this.__v_raw,r=bt(n),i=bt(t);return e||(t!==i&&L(r,0,t),L(r,0,i)),t===i?n.has(t):n.has(t)||n.has(i)}function X(t,e=!1){return t=t.__v_raw,!e&&L(bt(t),0,P),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:r,get:i}=V(n);let s=r.call(n,t);s||(t=bt(t),s=r.call(n,t));const o=i.call(n,t);return n.set(t,e),s?m(e,o)&&T(n,"set",t,e):T(n,"add",t,e),this}function tt(t){const e=bt(this),{has:n,get:r}=V(e);let i=n.call(e,t);i||(t=bt(t),i=n.call(e,t)),r&&r.call(e,t);const s=e.delete(t);return i&&T(e,"delete",t,void 0),s}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,r){const i=this,s=i.__v_raw,o=bt(s),a=e?G:t?St:Et;return!t&&L(o,0,P),s.forEach(((t,e)=>n.call(r,a(t),a(e),i)))}}function rt(t,e,n){return function(...r){const i=this.__v_raw,s=bt(i),o=f(s),a="entries"===t||t===Symbol.iterator&&o,c="keys"===t&&o,h=i[t](...r),l=n?G:e?St:Et;return!e&&L(s,0,c?x:P),{next(){const{value:t,done:e}=h.next();return e?{value:t,done:e}:{value:a?[l(t[0]),l(t[1])]:l(t),done:e}},[Symbol.iterator](){return this}}}}function it(t){return function(...e){return"delete"!==t&&this}}const[st,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)},r={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]=rt(i,!1,!1),n[i]=rt(i,!0,!1),e[i]=rt(i,!1,!0),r[i]=rt(i,!0,!0)})),[t,n,e,r]}();function ht(t,e){const n=e?t?ct:at:t?ot:st;return(e,r,i)=>"__v_isReactive"===r?!t:"__v_isReadonly"===r?t:"__v_raw"===r?e:Reflect.get(h(n,r)&&r in e?n:e,r,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,D,lt,ut)}function yt(t){return mt(t,!0,F,ft,pt)}function mt(t,e,n,r,i){if(!d(t))return t;if(t.__v_raw&&(!e||!t.__v_isReactive))return t;const s=i.get(t);if(s)return s;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?r: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 Et=t=>d(t)?vt(t):t,St=t=>d(t)?yt(t):t;function _t(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`,Ot=t=>`[@rallie/core] you are trying to remove a listener of the broadcast event ${t}, but the listener hasn't been registed`,At=t=>`[@rallie/core] one of the callbacks of the broadcast event ${t} throws an uncaught error`,Rt=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`,Pt=t=>`[@rallie/core] you are trying to register a unicast event ${t}, but it has been registered before`,xt=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}`,Mt=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`,Bt=t=>`[@rallie/core] duplicated initialized state ${t}`,Ut=t=>`[@rallie/core] it's not allowed to initialized state ${t} to a primitive value`,zt=t=>`[@rallie/core] the bus named ${t} has been defined before, please rename your bus`,Ct=(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",Nt=()=>"[@rallie/core] the middleware must be a function",Ht=(t,e)=>`[@rallie/core] the event ${t} is not in the events pool that you specified when calling on${e?"Unicast":"Broadcast"}`,Jt=t=>(e,n)=>{let r=-1;const i=s=>{if(s<=r)return Promise.reject(new Error(It()));r=s;let o=t[s];if(s===t.length&&(o=n),!o)return Promise.resolve();try{return Promise.resolve(o(e,i.bind(null,s+1)))}catch(t){return Promise.reject(t)}};return i(0)};var Kt,Dt,Ft,Gt,Vt,qt,Qt,Xt,Yt;class Zt{constructor(){Kt.set(this,{}),Dt.set(this,{})}addBroadcastEventListener(t,e){s(this,Kt,"f")[t]=s(this,Kt,"f")[t]||new Set,s(this,Kt,"f")[t].add(e)}addUnicastEventListener(t,e){if(s(this,Dt,"f")[t])throw new Error(Pt(t));s(this,Dt,"f")[t]=e}removeBroadcastEventListener(t,e){const n=s(this,Kt,"f")[t];if(!n){const e=kt(t);throw new Error(e)}if(!n.has(e)){const e=Ot(t);throw new Error(e)}n.delete(e)}removeUnicastEventListener(t){if(!s(this,Dt,"f")[t]){const e=Rt(t);throw new Error(e)}delete s(this,Dt,"f")[t]}emitBroadcast(t,...e){s(this,Kt,"f")[t]=s(this,Kt,"f")[t]||new Set,s(this,Kt,"f")[t].forEach((n=>{try{n(...e)}catch(n){console.error(At(t)),console.error(n)}}))}emitUnicast(t,...e){const n=s(this,Dt,"f")[t];if(n)return n(...e);throw new Error(xt(t))}}Kt=new WeakMap,Dt=new WeakMap;class te{constructor(t,e){Ft.set(this,void 0),Gt.set(this,void 0),o(this,Ft,t,"f"),o(this,Gt,e,"f"),s(this,Gt,"f")[t].watchers.add(this)}do(t){return this.handler=t,()=>this.unwatch()}unwatch(){null==this||this.stopEffect(),this.handler=null;const t=s(this,Gt,"f")[s(this,Ft,"f")].watchers;t.has(this)&&t.delete(this)}}Ft=new WeakMap,Gt=new WeakMap;class ee{constructor(t,e){Vt.add(this),qt.set(this,void 0),Qt.set(this,void 0),o(this,qt,t,"f"),o(this,Qt,e,"f")}onBroadcast(t){return Object.entries(t).forEach((([t,e])=>{s(this,qt,"f").addBroadcastEventListener(t,e)})),e=>{s(this,Vt,"m",Xt).call(this,t,!1,e)}}onUnicast(t){return Object.entries(t).forEach((([t,e])=>{try{s(this,qt,"f").addUnicastEventListener(t,e)}catch(t){console.error(t)}})),e=>{s(this,Vt,"m",Xt).call(this,t,!0,e)}}createBroadcaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),s(this,qt,"f").emitBroadcast(n,...e)),set:()=>!1})}createUnicaster(t){return new Proxy({},{get:(e,n)=>(...e)=>(null==t||t(n),s(this,qt,"f").emitUnicast(n,...e)),set:()=>!1})}existState(t){return!!s(this,Qt,"f")[t]}initState(t,e,n=!1){if(this.existState(t))throw new Error(Bt(t));if(["string","number","boolean","undefined"].includes(typeof e))throw new Error(Ut(t));return s(this,Qt,"f")[t]={state:vt(e),owner:n?this:null,watchers:new Set},s(this,qt,"f").emitBroadcast("$state-initialized",t),this.getState(t)}getState(t,e){if(this.existState(t)){const n=yt(s(this,Qt,"f")[t].state);return e?e(n):n}return null}setState(t,e,n){return i(this,void 0,void 0,(function*(){const r=s(this,Vt,"m",Yt).call(this,t);if(!e)throw new Error(Lt(t));{const t=n(r);yield Promise.resolve(t)}}))}watchState(t,e){if(!this.existState(t)){const e=Tt(t);throw new Error(e)}let n=!1;const r=yt(s(this,Qt,"f")[t].state),i=new te(t,s(this,Qt,"f")),o=function(t,e){t.effect&&(t=t.effect.fn);const n=new W(t);e&&(a(n,e),e.scope&&g(n,e.scope)),e&&e.lazy||n.run();const r=n.run.bind(n);return r.effect=n,r}((()=>e(r)),{lazy:!0,scheduler:()=>{n||(n=!0,Promise.resolve().then((()=>{var t;const s=bt(e(r));null===(t=i.handler)||void 0===t||t.call(i,s,i.oldWatchingStates),i.oldWatchingStates=bt(s),n=!1})))}});return i.oldWatchingStates=o(),i.stopEffect=()=>o.effect.stop(),i}}qt=new WeakMap,Qt=new WeakMap,Vt=new WeakSet,Xt=function(t,e,n){let r=e?s(this,qt,"f").removeUnicastEventListener:s(this,qt,"f").removeBroadcastEventListener;r=r.bind(s(this,qt,"f")),n?t[n]?(r(n,t[n]),delete t[n]):console.warn(Ht(n,e)):Object.entries(t).forEach((([t,e])=>{r(t,e)}))},Yt=function(t){if(!this.existState(t)){const e=Tt(t);throw new Error(e)}const e=s(this,Qt,"f")[t].owner;if(e!==this&&null!==e){const e=$t(t);throw new Error(e)}return s(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 re,ie,se,oe,ae,ce,he,le,fe,ue,de,pe,we,ve,ye={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 me{constructor(t){re.add(this),ie.set(this,void 0),se.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),o(this,ie,t,"f"),o(this,le,Jt(s(this,he,"f")),"f")}createSocket(){return new ee(s(this,se,"f"),s(this,oe,"f"))}existApp(t){return!!s(this,ae,"f")[t]}createApp(t){if(this.existApp(t))throw new Error(Wt(t));const e=new ne(t);return s(this,ae,"f")[t]=e,e}loadApp(t){return i(this,void 0,void 0,(function*(){s(this,ae,"f")[t]||(s(this,ce,"f")[t]||(s(this,ce,"f")[t]=new Promise(((e,n)=>{const r=s(this,re,"m",ue).call(this,t);s(this,le,"f").call(this,r,s(this,re,"m",de).bind(this)).then((()=>{t.startsWith("lib:")&&!s(this,ae,"f")[t]&&(s(this,ae,"f")[t]=!0),s(this,ae,"f")[t]||n(new Error(Mt(t))),e()})).catch((t=>{n(t)}))}))),yield s(this,ce,"f")[t])}))}activateApp(t){return i(this,void 0,void 0,(function*(){yield s(this,re,"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(Nt());return s(this,he,"f").push(t),o(this,le,Jt(s(this,he,"f")),"f"),this}}ie=new WeakMap,se=new WeakMap,oe=new WeakMap,ae=new WeakMap,ce=new WeakMap,he=new WeakMap,le=new WeakMap,re=new WeakSet,fe=function(t){return s(this,ae,"f")[t]&&"boolean"!=typeof s(this,ae,"f")[t]},ue=function(t){return{name:t,loadScript:ye.loadScript,loadLink:ye.loadLink}},de=function(t){return i(this,void 0,void 0,(function*(){const{name:e,loadScript:n=ye.loadScript,loadLink:r=ye.loadLink}=t,{assets:i}=this.conf;if(!i[e])throw new Error(jt(e,s(this,ie,"f")));if(i[e].css&&i[e].css.forEach((t=>{r(t)})),i[e].js)for(const t of i[e].js)yield n(t)}))},pe=function(t,e){return i(this,void 0,void 0,(function*(){if(yield this.loadApp(t),s(this,re,"m",fe).call(this,t)){const n=s(this,ae,"f")[t];if(yield s(this,re,"m",ve).call(this,n),e.includes(t)){const n=e.indexOf(t),r=[...e.slice(n),t];throw new Error(Ct(t,r))}if(e.push(t),!n.activated){const t=()=>i(this,void 0,void 0,(function*(){yield s(this,re,"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 i(this,void 0,void 0,(function*(){if(0!==t.dependencies.length)for(const n of t.dependencies)yield s(this,re,"m",pe).call(this,n,e)}))},ve=function(t){return i(this,void 0,void 0,(function*(){yield Promise.all(t.relatedApps.map((t=>this.loadApp(t))))}))};const ge={},be="DEFAULT_BUS",Ee=(t=be)=>{let e=null,n=!1;const r=((t=be)=>window.RALLIE_BUS_STORE&&window.RALLIE_BUS_STORE[t])(t);return r?(e=r,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(zt(t));{const e=new me(t);return Reflect.defineProperty(window.RALLIE_BUS_STORE,t,{value:e,writable:!1}),e}})(t),n=!0),[e,n]},Se=t=>`${t}.bus`,_e=t=>`${t}.state`,ke="isGlobalBusAccessible",Oe=t=>`[rallie] ${t}`,Ae=t=>Oe(` 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`),Re=t=>Oe(`the block ${t} is already registered before, please rename your block`),Pe=t=>Oe(`the state of ${t} is readonly`),xe=(t,e)=>new Proxy(t,{get:(t,n)=>(...r)=>(0,t[n])(r,e),set:()=>!1}),We=t=>{const e={};return Object.entries(t).forEach((([t,n])=>{e[t]=(t,e)=>n.call({trigger:e},...t)})),e};var je,Me,$e,Le,Te,Be,Ue;class ze{constructor(t,e,i){je.set(this,void 0),this.name=t,r(this,je,i,"f");const s=n(this,je,"f").createBroadcaster(),o=n(this,je,"f").createUnicaster();this.events=xe(s,e),this.methods=xe(o,e),Reflect.defineProperty(this,"state",{get:()=>n(this,je,"f").getState(_e(this.name)),set:()=>{throw new Error(Pe(this.name))}})}setState(t,e){if(n(this,je,"f").existState(_e(this.name)))return n(this,je,"f").setState(_e(this.name),t,e);throw new Error(Ae(this.name))}watchState(t){if(n(this,je,"f").existState(_e(this.name)))return n(this,je,"f").watchState(_e(this.name),t);throw new Error(Ae(this.name))}listenEvents(t){return n(this,je,"f").onBroadcast(We(t))}}je=new WeakMap;class Ce extends ze{constructor(t,e,n,i){const[s]=Ee(Se(t)),o=s.createSocket();super(t,t,o),Me.set(this,void 0),$e.set(this,void 0),Le.set(this,void 0),Te.set(this,void 0),Be.set(this,void 0),Ue.set(this,{}),r(this,Te,o,"f"),r(this,Me,e,"f"),r(this,$e,n,"f"),r(this,Be,e.createApp(t),"f"),r(this,Le,i,"f")}initState(t,e){return n(this,Te,"f").initState(_e(this.name),t,e),this}addMethods(t){return n(this,Te,"f").onUnicast(We(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,Ue,"f")[t]){const[e]=Ee(Se(t)),r=e.createSocket();n(this,Ue,"f")[t]=new ze(t,this.name,r)}return n(this,Ue,"f")[t]}load(t){return n(this,Me,"f").loadApp(t)}activate(t){return n(this,Me,"f").activateApp(t)}run(t){var r;return e(this,void 0,void 0,(function*(){const e=n(this,Le,"f")||(null===(r=n(this,$e,"f").getState(ke))||void 0===r?void 0:r.value),i=t=>{n(this,Le,"f")&&n(this,$e,"f").setState(ke,t?"unfreeze the enviroment":"freeze the enviroment",(e=>{e.value=t}))},s={isEntry:n(this,Le,"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(s,{get:(t,e,r)=>"conf"===e?JSON.parse(JSON.stringify(n(this,Me,"f").conf)):Reflect.get(t,e,r),set:()=>!1}));yield Promise.resolve(o)}))}}Me=new WeakMap,$e=new WeakMap,Le=new WeakMap,Te=new WeakMap,Be=new WeakMap,Ue=new WeakMap,t.createBlock=function(t){const[e,n]=Ee();if(e.existApp(t))throw new Error(Re(t));const r=e.createSocket();return n&&r.initState(ke,{value:!0},!0),new Ce(t,e,r,n)}}));

@@ -0,0 +0,0 @@ export declare const constant: {

{
"name": "@rallie/block",
"version": "0.16.0",
"version": "0.16.1",
"description": "a progressive micro front framework",

@@ -17,3 +17,3 @@ "main": "./dist/index.umd.js",

"dependencies": {
"@rallie/core": "0.16.0"
"@rallie/core": "0.16.1"
},

@@ -28,3 +28,3 @@ "repository": {

"homepage": "https://github.com/ralliejs/rallie#readme",
"gitHead": "a7d26f83e61f737148896b61eae9ad18a25036fb"
"gitHead": "44f6fbfb8164f76dbe553398e54a4ae1717abd93"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc