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