varARCS=ARCS||{};ARCS.isInNode=function(){return"function"==typeofrequire&&require.resolve},ARCS.Component={SourceIsNotComponent:{message:"Source is not a component"},UndefinedSignal:{message:"Signal is not defined"},UndefinedSlot:{message:"Slot is not defined"},create:function(n,t,e){returnvoid0===n.prototype?(console.error("Cannot create such a component"),0):(n.prototype.slots=[],n.prototype.signals={},n.slotList=function(){returnn.prototype.slots},n.prototype.slotList=function(){returnn.prototype.slots},n.prototype.signalList=function(){vart,e=[];for(tinn.prototype.signals)e.push(t);returne},n.signalList=function(){returnn.prototype.signalList()},n.prototype.emit=function(n){vart,e,o,i=Array.prototype.slice.call(arguments,1);for(tinthis.signals[n])e=this.signals[n][t].func,o=this.signals[n][t].obj,e.apply(o,i)},n.slot=function(t,e){varo;if(tinstanceofArray)for(o=0;o<t.length;o++)n.prototype.slots.push(t[o]);elsen.prototype.slots.push(t),void0!==e&&(n.prototype[t]=e)},n.signal=function(t){vare;if(tinstanceofArray)for(e=0;e<t.length;e++)n.prototype.signals[t[e]]=1;elsen.prototype.signals[t]=1},void0!==t&&n.slot(t),void0!==e&&n.signal(e),n)},check:function(n){returnvoid0!==n.prototype&&(void0!==n.prototype.signals&&void0!==n.prototype.slots)},connect:function(n,t,e,o){vari,r;if(void0===n.signals)throwARCS.Component.SourceIsNotComponent;if(void0===n.signals[t])throwARCS.Component.UndefinedSignal;if(void0===e[o])throwARCS.Component.UndefinedSlot;if(!n.hasOwnProperty("signals"))for(rini=n.signals,n.signals={},i)n.signals[r]=[];n.signals[t].push({obj:e,func:e[o]})},disconnect:function(n,t,e,o){vari;for(i=0;i<n.signals[t].length;i++)n.signals[t][i].obj===e&&n.signals[t][i].func===e[o]&&(n.signals[t].splice(i,1),i--)},invoke:function(n,t,e){if(void0===n[t])throwARCS.Component.UndefinedSlot;n[t].apply(n,e)},config:function(n,t){"function"==typeofn.config&&n.config(t)}},ARCS.Context=function(n){vart,e,o,i={},r={},s={},c=[],a=this;if(s.StateMachine=ARCS.Statemachine,void0!==n){for(pinc=n.libraries,n.components)n.components.hasOwnProperty(p)&&(i[p]=n.components[p]);if(void0!==n.constants)for(pinn.constants)n.constants.hasOwnProperty(p)&&(r[p]=n.constants[p])}e=asyncfunction(n){returnARCS.isInNode()?newPromise((function(t,e){varo=require(n);void0!==o?t(o):e("[ARCS] File not found")})):(awaitfetch(n)).json()},t=function(){varn;ARCS.Context.currentContext=a;vart=[];for(n=0;n<c.length;n++)t.push(loadLibrary(c[n]));returnPromise.all(t)},o=function(){varn,t=[];for(ninconsole.log(i),i)if(i.hasOwnProperty(n)){if(void0===s[i[n].type])returnconsole.error("[ARCS] Factory "+i[n].type+" not found."),voidconsole.error("[ARCS] Context dump follows: ",c,i,r);factory=s[i[n].type];try{if(void0!==i[n].value||void0!==i[n].url||void0!==i[n].ref){if(void0!==i[n].value&&(i[n].instance=newfactory(i[n].value)),void0!==i[n].url){console.log("loading data file",i[n].url),t.push(e(i[n].url).then(function(n,t){returnfunction(e){returnconsole.log("instanciating from data file"),i[n].instance=newt(e),Promise.resolve()}}(n,factory)))}void0!==i[n].ref&&void0!==r[i[n].ref]&&(i[n].instance=newfactory(r[i[n].ref]))}elsei[n].instance=newfactory}catch(t){console.error("[ARCS] Component of type ",n," not instanciated.",t)}}returnPromise.all(t)},this.loadLibrary=function(n,t){vare=n,o=n;returnARCS.Context.currentContext=a,"string"!=typeofn&&(o=n.name,e=n.url),c.push(o),import(e).then((function(n){for(pinn)n.hasOwnProperty(p)&&ARCS.Context.currentContext.setFactory(p,n[p]);void0!==t&&t()}))},this.getComponentList=function(){varn,t=Object.keys(i);for(n=0;n<t.length;n++)i.hasOwnProperty(t[n])||t.splice(n--,1);returnt},this.getConstant=function(n){returnr[n]},this.getComponentType=function(n){if(void0!==i[n])returni[n].type},this.getComponentValue=function(n){if(void0!==i[n])returni[n].value},this.getComponent=function(n){if(void0!==i[n])returni[n].instance},this.getComponentName=function(n){vart,e;for(e=i.getComponentList(),t=0;t<e.length;t++)if(i[e[t]].instance===n)returne[t]},this.setFactory=function(n,t){s[n]=t},this.toJSON=function(){varn,t={};for(nini)i.hasOwnProperty(n)&&(t[n]={type:i[n].type,value:i[n].value});returnt},this.setComponentValue=function(n,t){i[n].value=t},this.addComponent=function(n,t,e){varo;i[n]={},i[n].type=t,i[n].value=e;varr=s[t];void0!==r&&(o=newr(e)),i[n].instance=o},this.removeComponent=function(n){deletei[n]},this.getFactory=function(n){returns[n]},this.getFactoryList=function(){returnObject.keys(s)},this.instanciate=function(){returnt().then(o).catch((function(n){console.log("[ARCS] Trouble instanciating context",n)}))};varu=function(n,t){vare,o=Object.create(t);for(einn)n.hasOwnProperty(e)&&(o[e]=n[e]);returno};this.chain=function(n,t,e){return[u(n,i),u(t,r),u(e,s)]},this.setParent=function(n){if(void0!==n){vart=n.chain(i,r,s);i=t[0],r=t[1],s=t[2]}}},ARCS.Context.currentContext=null,ARCS.Invocation=function(n,t,e){this.getDestination=function(){returnn},this.getSlot=function(){returnt},this.getValue=function(){returne},this.invoke=function(){varo=n[t];void0!==o?o.apply(n,e):console.error("Undefined slot %s of component %s",t,n)}},ARCS.Invocation.cast=function(n,t){if(void0!==n.value){vare=t.getComponent(n.destination);returnvoid0===e&&console.error("[ARCS] Destination ",n.destination," is undefined"),newARCS.Invocation(e,n.slot,n.value)}if(void0!==n.ref)returnnewARCS.Invocation(t.getComponent(n.destination),n.slot,t.getConstant(n.ref))},ARCS.Invocation.PRE_CONNECTION=0,ARCS.Invocation.POST_CONNECTION=1,ARCS.Invocation.CLEAN_UP=2,ARCS.Connection=function(n,t,e,o){this.connect=function(){try{ARCS.Component.connect(n,t,e,o)}catch(i){console.log(i,n,t,e,o)}},this.disconnect=function(){ARCS.Component.disconnect(n,t,e,o)},this.getSource=function(){returnn},this.getDestination=function(){returne},this.getSlot=function(){returno},this.getSignal=function(){returnt}},ARCS.Connection.cast=function(n,t){returnnewARCS.Connection(t.getComponent(n.source),n.signal,t.getComponent(n.destination),n.slot)},ARCS.Sheet=function(n){vart,e,o,i,r,s=newARCS.Context,c=[],a=[],u=[],f=[],l=0,p=0,h=0,d=0;t=function(){varn;for(n=0;n<c.length;n++)c[n].invoke()},e=function(){varn;for(n=0;n<a.length;n++)a[n].invoke()},o=function(){varn;for(n=0;n<u.length;n++)u[n].invoke()},i=function(){varn;for(n=0;n<f.length;n++)f[n].connect()},r=function(){varn;for(n=0;n<f.length;n++)f[n].disconnect()},this.setContext=function(n){s=n},this.activate=function(){s.instanciate().then((function(){t(),i(),e()}))},this.deactivate=function(){r(),o()},this.addPreConnection=function(n){vart=ARCS.Invocation.cast(n,s);returnt.id=l++,c.push(t),t.id},this.addPostConnection=function(n){vart=ARCS.Invocation.cast(n,s);returnt.id=p++,a.push(t),t.id},this.addCleanup=function(n){vart=ARCS.Invocation.cast(n,s);returnt.id=h++,u.push(t),t.id},this.addConnection=function(n){vart=ARCS.Connection.cast(n,s);returnt.id=d++,f.push(t),t.id};varC=function(n,t){for(vare=t.length;e--&&t[e].id!==n;);e>=0?t.splice(e,1):console.warn("Could not remove data with id",n)};this.removePreConnection=function(n){C(n,c)},this.removePostConnection=function(n){C(n,a)},this.removeCleanup=function(n){C(n,u)};varv=function(n,t,e){for(varo=e.length;o--&&e[o].id!==n;);o>=0&&(e[o].value=t)};this.changePreConnection=function(n,t){v(n,t,c)},this.changePostConnection=function(n,t){v(n,t,a)},this.changeCleanup=function(n,t){v(n,t,u)},this.removeConnection=function(n){C(n,f)};varg=function(n,t,e){for(varo,i=e.length,r=e.length;i--&&e[i].id!==n;);for(;r--&&e[r].id!==t;);i>=0&&r>=0&&(o=e[i],e[i]=e[r],e[r]=o,e[i].id=n,e[r].id=t)};this.swapConnections=function(n,t){g(n,t,f)},this.swapCleanups=function(n,t){g(n,t,u)},this.swapPreConnections=function(n,t){g(n,t,c)},this.swapPostConnections=function(n,t){g(n,t,a)};this.import=function(t){t.hasOwnProperty("context")&&(s=newARCS.Context(t.context)).setParent(n),s.instanciate().then((function(){!function(n){vart=0,e=ARCS.Invocation.cast,o=ARCS.Connection.cast;for(t=0;t<n.preconnections.length;t++)c.push(e(n.preconnections[t],s));for(t=0;t<n.postconnections.length;t++)a.push(e(n.postconnections[t],s));for(t=0;t<n.cleanups.length;t++)u.push(e(n.cleanups[t],s));for(t=0;t<n.connections.length;t++)f.push(o(n.connections[t],s))}(t)}))};varS=function(n){return{destination:s.getComponentName(n.getDestination()),slot:n.getSlot(),value:n.getValue()}};this.toJSON=function(){varn,t,e=[],o=[],i=[],r=[];for(n=0;n<f.length;n++)i.push((t=f[n],{source:s.getComponentName(t.getSource()),signal:t.getSignal(),destination:s.getComponentName(t.getDestination()),slot:t.getSlot()}));for(n=0;n<c.length;n++)e.push(S(c[n]));for(n=0;n<a.length;n++)o.push(S(a[n]));for(n=0;n<u.length;n++)r.push(S(u[n]));return{preconnections:e,postconnections:o,connections:i,cleanups:r}},s.setParent(n)},ARCS.EventLogicParser=function(){functionn(n,t,e,o,i,r){this.message=n,this.expected=t,this.found=e,this.offset=o,this.line=i,this.column=r,this.name="SyntaxError"}returnfunction(n,t){functione(){this.constructor=n}e.prototype=t.prototype,n.prototype=newe}(n,Error),{SyntaxError:n,parse:function(t){vare,o=arguments.length>1?arguments[1]:{},i={},r={start:D},s=D,c=i,a=function(n,t){return[n].concat(t)},u=function(n){return{and:n}},f=function(n){return{or:n}},l=function(n){returnn},p="(",h={type:"literal",value:"(",description:'"("'},d=")",C={type:"literal",value:")",description:'")"'},v=function(n){return[n]},g={type:"other",description:"id"},S=function(n){returnn.trim()},m=/^[_a-zA-Z]/,A={type:"class",value:"[_a-zA-Z]",description:"[_a-zA-Z]"},y=/^[_a-zA-Z0-9]/,R={type:"class",value:"[_a-zA-Z0-9]",description:"[_a-zA-Z0-9]"},w="&",x={type:"literal",value:"&",description:'"&"'},P="|",O={type:"literal",value:"|",description:'"|"'},N=/^[\r\n\t]/,T={type:"class",value:"[ \\r\\n\\t]",description:"[ \\r\\n\\t]"},b=0,k=0,F={line:1,column:1,seenCR:!1},I=0,E=[],L=0;if("startRule"ino){if(!(o.startRuleinr))thrownewError("Can't start parsing from rule \""+o.startRule+'".');s=r[o.startRule]}functionq(n){returnk!==n&&(k>n&&(k=0,F={line:1,column:1,seenCR:!1}),function(n,e,o){vari,r;for(i=e;i<o;i++)"\n"===(r=t.charAt(i))?(n.seenCR||n.line++,n.column=1,n.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(n.line++,n.column=1,n.seenCR=!0):(n.column++,n.seenCR=!1)}(F,k,n),k=n),F}function_(n){b<I||(b>I&&(I=b,E=[]),E.push(n))}functionj(e,o,i){varr=q(i),s=i<t.length?t.charAt(i):null;returnnull!==o&&function(n){vart=1;for(n.sort((function(n,t){returnn.description<t.description?-1:n.description>t.description?1:0}));t<n.length;)n[t-1]===n[t]?n.splice(t,1):t++}(o),newn(null!==e?e:function(n,t){vare,o=newArray(n.length);for(e=0;e<n.length;e++)o[e]=n[e].description;return"Expected "+(n.length>1?o.slice(0,-1).join(", ")+" or "+o[n.length-1]:o[0])+" but "+(t?'"'+function(n){functiont(n){returnn.charCodeAt(0).toString(16).toUpperCase()}returnn.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,(function(n){return"\\x0"+t(n)})).replace(/[\x10-\x1F\x80-\xFF]/g,(function(n){return"\\x"+t(n)})).replace(/[\u0180-\u0FFF]/g,(function(n){return"\\u0"+t(n)})).replace(/[\u1080-\uFFFF]/g,(function(n){return"\\u"+t(n)}))}(t)+'"':"end of input")+" found."}(o,s),o,s,i,r.line,r.column)}functionD(){returnU()}functionU(){varn,t,e,o;if(n=b,(t=Z())!==i){if(e=[],(o=z())!==i)for(;o!==i;)e.push(o),o=z();elsee=c;e!==i?(n,n=t=a(t,e)):(b=n,n=c)}elseb=n,n=c;returnn===i&&(n=Z()),n}functionz(){varn,e;returnn=b,function(){varn,e,o,r;n=b,(e=V())!==i?(38===t.charCodeAt(b)?(o=w,b++):(o=i,0===L&&_(x)),o!==i&&(r=V())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c);returnn}()!==i&&(e=Z())!==i?(n,n=u(e)):(b=n,n=c),n===i&&(n=b,function(){varn,e,o,r;n=b,(e=V())!==i?(124===t.charCodeAt(b)?(o=P,b++):(o=i,0===L&&_(O)),o!==i&&(r=V())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c);returnn}()!==i&&(e=Z())!==i?(n,n=f(e)):(b=n,n=c)),n}functionZ(){varn,e,o,r;returnn=b,(e=function(){varn,e,o;L++,n=b,e=b,(o=function(){varn,e,o,r,s;if(n=b,(e=V())!==i)if(m.test(t.charAt(b))?(o=t.charAt(b),b++):(o=i,0===L&&_(A)),o!==i){for(r=[],y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));s!==i;)r.push(s),y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));r!==i&&(s=V())!==i?n=e=[e,o,r,s]:(b=n,n=c)}elseb=n,n=c;elseb=n,n=c;returnn}())!==i&&(o=t.substring(e,b));(e=o)!==i&&(n,e=S(e));L--,(n=e)===i&&(e=i,0===L&&_(g));returnn}())!==i&&(n,e=l(e)),(n=e)===i&&(n=b,40===t.charCodeAt(b)?(e=p,b++):(e=i,0===L&&_(h)),e!==i&&(o=U())!==i?(41===t.charCodeAt(b)?(r=d,b++):(r=i,0===L&&_(C)),r!==i?(n,n=e=v(o)):(b=n,n=c)):(b=n,n=c)),n}functionV(){varn,e;for(n=[],N.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(T));e!==i;)n.push(e),N.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(T));returnn}if((e=s())!==i&&b===t.length)returne;throwe!==i&&b<t.length&&_({type:"end",description:"end of input"}),j(null,E,I)}}}(),ARCS.TokenEvent=function(){varn,t;this.promise=newPromise((function(e,o){n=e,t=o})),this.accept=function(){n()},this.abort=function(){t()}},ARCS.TransitionNetwork=function(){this.promise={},this.and=function(n){returnthis.promise=Promise.all([this.promise,n.promise]),this},this.or=function(n){returnthis.promise=Promise.race([this.promise,n.promise]),this}},ARCS.TransitionNetwork.build=function(n,t){vare,o,r;if("string"==typeofn){vars;t.hasOwnProperty(n)?s=t[n]:t[n]=s=newARCS.TokenEvent;varc=newARCS.TransitionNetwork;returnc.promise=s.promise,c}for(e=ARCS.TransitionNetwork.build(n[0],t),i=1;i<n.length;i++)n[i].hasOwnProperty("and")?(r=ARCS.TransitionNetwork.build(n[i].and,t),o=e.and(r)):n[i].hasOwnProperty("or")?(r=ARCS.TransitionNetwork.build(n[i].or,t),o=e.or(r)):console.warn("[ARCS] Illegal tree"),e=o;returne},ARCS.Statemachine=newARCS.Component.create((function(n){vart="",e="",o={},i="",r=this,s={},c={},a=function(n){vart;r.slots.indexOf(n)<0&&(r.slots.push(n),r[n]=(t=n,function(){r.setToken(t)}))},u=function(n){vart;if(o.hasOwnProperty(n))for(tinc={},o[n])o[n].hasOwnProperty(t)&&ARCS.TransitionNetwork.build(s[t],c).promise.then((function(){vare;for(einc)c.hasOwnProperty(e)&&c[e].abort();u(o[n][t])}));i=n,r.emit("requestSheet",i),i===e&&r.emit("requestTermination")};this.setInitialState=function(n){i=t=n},this.setFinalState=function(n){e=n},this.addTransition=function(n,t,e){vari,r=/([A-Za-z_]\w*)/g;try{varc;if("string"==typeof(c=ARCS.EventLogicParser.parse(t)))a(c);elsefor(;null!==(i=r.exec(t));)a(i[0]);s[t]=c,void0===o[n]&&(o[n]={}),o[n][t]=e}catch(n){}},this.setToken=function(n){c.hasOwnProperty(n)&&c[n].accept()},this.setTransitions=function(n){vart,e;for(tinn)if(n.hasOwnProperty(t))for(einn[t])n[t].hasOwnProperty(e)&&this.addTransition(t,e,n[t][e])},this.start=function(){console.log("statemachine",this,t,n),u(t)},void0!==n&&(t=n.initial,e=n.final,this.setTransitions(n.transitions),i="")}),["setToken"],["requestSheet","requestTermination"]),ARCS.Application=function(){varn,t=newARCS.Context,e={},o={},i=[],r=this,s="";this.export=function(){return{context:t,controller:t.getComponentName(o),sheets:e}},this.getContext=function(){returnt},this.getSheetList=function(){returnObject.keys(e)},this.getSheet=function(n){returne[n]},this.addSheet=function(n,o){e[n]=o,o.setContext(t)},this.removeSheet=function(n){deletee[n]},n=function(){varn,i,s;for(i=t.getComponent(o),o=i,s=Object.keys(e),n=0;n<s.length;n++)(i=newARCS.Sheet(t)).import(e[s[n]],t),e[s[n]]=i;ARCS.Component.connect(o,"requestSheet",r,"setSheet"),ARCS.Component.connect(o,"requestTermination",r,"finish"),o.start()},this.setController=function(n){o=t.getComponent(n)},this.setSheet=function(n){e.hasOwnProperty(n)?(s&&e[s].deactivate(),e[s=n].activate()):console.warn("[ARCS] Tried to activate hollow sheet named: "+n)},this.finish=function(){s&&e[s].deactivate()},this.import=function(n){t=newARCS.Context(n.context),e=n.sheets,void0===(o=n.controller)&&console.error("[ARCS] Undefined controller. Cannot start application.")},this.setFactory=function(n,t){factories[n]=t},this.setDependency=function(n){i[n]={}},this.start=function(){console.log("[ARCS] Starting application"),t.instanciate().then(n)}},ARCS.Application.setDependency=function(n,t){n.setDependency(t)},ARCS.Component.create(ARCS.Application),ARCS.Application.slot("setSheet"),ARCS.Application.slot("finish"),arcs_module=function(n,t){vare,o;"undefined"!=typeofmodule&&module.parent.exports&&(ARCS=module.exports),void0===t&&(t=[]),e=function(t){vare,o;if(t.unshift(ARCS),void0===(e="function"==typeofn?n.apply(this,t):n))thrownewError("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n"+n);for(oine)e.hasOwnProperty(o)&&null!=ARCS.Context.currentContext&&ARCS.Context.currentContext.setFactory(o,e[o]);returnPromise.resolve()};vari=function(n){returnnewPromise((function(t,e){varo,i;ARCS.isInNode()?void0===(o=require(n))?e(n):t(o):(void0!==n.name&&((i={shim:{}}).shim[n.name]={exports:n.exports},void0!==n.deps&&(i.shim[n.name].deps=n.deps),require.config(i),n=n.name),require([n],(function(n){t(n)}),(function(t){console.log("[ARCS] Trouble with module ",n),e(n,t)})))}))},r=[];for(o=0;o<t.length;o++)r[o]=i(t[o]);ARCS.Context.currentContext.addLibraryPromise(Promise.all(r).then(e,(function(n){console.error("[ARCS] Failed to load dependency ",n)})))};exportdefaultARCS;
\ No newline at end of file
varARCS=ARCS||{};ARCS.isInNode=function(){return"function"==typeofrequire&&require.resolve},ARCS.Component={SourceIsNotComponent:{message:"Source is not a component"},UndefinedSignal:{message:"Signal is not defined"},UndefinedSlot:{message:"Slot is not defined"},create:function(n,t,e){returnvoid0===n.prototype?(console.error("Cannot create such a component"),0):(n.prototype.slots=[],n.prototype.signals={},n.slotList=function(){returnn.prototype.slots},n.prototype.slotList=function(){returnn.prototype.slots},n.prototype.signalList=function(){vart,e=[];for(tinn.prototype.signals)e.push(t);returne},n.signalList=function(){returnn.prototype.signalList()},n.prototype.emit=function(n){vart,e,o,i=Array.prototype.slice.call(arguments,1);for(tinthis.signals[n])e=this.signals[n][t].func,o=this.signals[n][t].obj,e.apply(o,i)},n.slot=function(t,e){varo;if(tinstanceofArray)for(o=0;o<t.length;o++)n.prototype.slots.push(t[o]);elsen.prototype.slots.push(t),void0!==e&&(n.prototype[t]=e)},n.signal=function(t){vare;if(tinstanceofArray)for(e=0;e<t.length;e++)n.prototype.signals[t[e]]=1;elsen.prototype.signals[t]=1},void0!==t&&n.slot(t),void0!==e&&n.signal(e),n)},check:function(n){returnvoid0!==n.prototype&&(void0!==n.prototype.signals&&void0!==n.prototype.slots)},connect:function(n,t,e,o){vari,r;if(void0===n.signals)throwARCS.Component.SourceIsNotComponent;if(void0===n.signals[t])throwARCS.Component.UndefinedSignal;if(void0===e[o])throwARCS.Component.UndefinedSlot;if(!n.hasOwnProperty("signals"))for(rini=n.signals,n.signals={},i)n.signals[r]=[];n.signals[t].push({obj:e,func:e[o]})},disconnect:function(n,t,e,o){vari;for(i=0;i<n.signals[t].length;i++)n.signals[t][i].obj===e&&n.signals[t][i].func===e[o]&&(n.signals[t].splice(i,1),i--)},invoke:function(n,t,e){if(void0===n[t])throwARCS.Component.UndefinedSlot;n[t].apply(n,e)},config:function(n,t){"function"==typeofn.config&&n.config(t)}},ARCS.Context=function(n){vart={},e={},o={},i=[],r=this;if(o.StateMachine=ARCS.Statemachine,void0!==n){vars;for(sini=n.libraries,n.components)n.components.hasOwnProperty(s)&&(t[s]=n.components[s]);if(void0!==n.constants)for(sinn.constants)n.constants.hasOwnProperty(s)&&(e[s]=n.constants[s])}varc=asyncfunction(n){returnARCS.isInNode()?newPromise((function(t,e){varo=require(n);void0!==o?t(o):e("[ARCS] File not found")})):(awaitfetch(n)).json()},a=function(){varn,r=[];for(nint)if(t.hasOwnProperty(n)){if(void0===o[t[n].type])returnconsole.error("[ARCS] Factory "+t[n].type+" not found."),voidconsole.error("[ARCS] Context dump follows: ",i,t,e);vars=o[t[n].type];try{if(void0!==t[n].value||void0!==t[n].url||void0!==t[n].ref){if(void0!==t[n].value&&(t[n].instance=news(t[n].value)),void0!==t[n].url){console.log("loading data file",t[n].url),r.push(c(t[n].url).then(function(n,e){returnfunction(o){returnconsole.log("instanciating from data file"),t[n].instance=newe(o),Promise.resolve()}}(n,s)))}void0!==t[n].ref&&void0!==e[t[n].ref]&&(t[n].instance=news(e[t[n].ref]))}elset[n].instance=news}catch(t){console.error("[ARCS] Component of type ",n," not instanciated.",t)}}returnPromise.all(r)};this.loadLibrary=function(n,t){vare=n,o=n;returnARCS.Context.currentContext=r,"string"!=typeofn&&(o=n.name,e=n.url),i.indexOf(o)<0&&i.push(o),import(e).then((function(n){for(sinn.default)n.default.hasOwnProperty(s)&&ARCS.Context.currentContext.setFactory(s,n.default[s]);void0!==t&&t()})).catch((function(n){console.error("[ARCS] Trouble loading '",e,"' with reason -",n)}))},this.getComponentList=function(){varn,e=Object.keys(t);for(n=0;n<e.length;n++)t.hasOwnProperty(e[n])||e.splice(n--,1);returne},this.getConstant=function(n){returne[n]},this.getComponentType=function(n){if(void0!==t[n])returnt[n].type},this.getComponentValue=function(n){if(void0!==t[n])returnt[n].value},this.getComponent=function(n){if(void0!==t[n])returnt[n].instance},this.getComponentName=function(n){vare,o;for(o=t.getComponentList(),e=0;e<o.length;e++)if(t[o[e]].instance===n)returno[e]},this.setFactory=function(n,t){o[n]=t},this.toJSON=function(){varn,e={};for(nint)t.hasOwnProperty(n)&&(e[n]={type:t[n].type,value:t[n].value});returne},this.setComponentValue=function(n,e){t[n].value=e},this.addComponent=function(n,e,i){varr;t[n]={},t[n].type=e,t[n].value=i;vars=o[e];void0!==s&&(r=news(i)),t[n].instance=r},this.removeComponent=function(n){deletet[n]},this.getFactory=function(n){returno[n]},this.getFactoryList=function(){returnObject.keys(o)},this.instanciate=function(){returnfunction(){varn;ARCS.Context.currentContext=r;vart=[];for(n=0;n<i.length;n++)t.push(r.loadLibrary(i[n]));returnPromise.all(t)}().then(a).catch((function(n){console.error("[ARCS] Trouble instanciating context",n)}))};varu=function(n,t){vare,o=Object.create(t);for(einn)n.hasOwnProperty(e)&&(o[e]=n[e]);returno};this.chain=function(n,i,r){return[u(n,t),u(i,e),u(r,o)]},this.setParent=function(n){if(void0!==n){vari=n.chain(t,e,o);t=i[0],e=i[1],o=i[2]}}},ARCS.Context.currentContext=null,ARCS.Invocation=function(n,t,e){this.getDestination=function(){returnn},this.getSlot=function(){returnt},this.getValue=function(){returne},this.invoke=function(){varo=n[t];void0!==o?o.apply(n,e):console.error("Undefined slot %s of component %s",t,n)}},ARCS.Invocation.cast=function(n,t){if(void0!==n.value){vare=t.getComponent(n.destination);returnvoid0===e&&console.error("[ARCS] Destination ",n.destination," is undefined"),newARCS.Invocation(e,n.slot,n.value)}if(void0!==n.ref)returnnewARCS.Invocation(t.getComponent(n.destination),n.slot,t.getConstant(n.ref))},ARCS.Invocation.PRE_CONNECTION=0,ARCS.Invocation.POST_CONNECTION=1,ARCS.Invocation.CLEAN_UP=2,ARCS.Connection=function(n,t,e,o){this.connect=function(){try{ARCS.Component.connect(n,t,e,o)}catch(i){console.log(i,n,t,e,o)}},this.disconnect=function(){ARCS.Component.disconnect(n,t,e,o)},this.getSource=function(){returnn},this.getDestination=function(){returne},this.getSlot=function(){returno},this.getSignal=function(){returnt}},ARCS.Connection.cast=function(n,t){returnnewARCS.Connection(t.getComponent(n.source),n.signal,t.getComponent(n.destination),n.slot)},ARCS.Sheet=function(n){vart,e,o,i,r,s=newARCS.Context,c=[],a=[],u=[],f=[],l=0,p=0,h=0,C=0;t=function(){varn;for(n=0;n<c.length;n++)c[n].invoke()},e=function(){varn;for(n=0;n<a.length;n++)a[n].invoke()},o=function(){varn;for(n=0;n<u.length;n++)u[n].invoke()},i=function(){varn;for(n=0;n<f.length;n++)f[n].connect()},r=function(){varn;for(n=0;n<f.length;n++)f[n].disconnect()},this.setContext=function(n){s=n},this.activate=function(){s.instanciate().then((function(){t(),i(),e()}))},this.deactivate=function(){r(),o()},this.addPreConnection=function(n){vart=ARCS.Invocation.cast(n,s);returnt.id=l++,c.push(t),t.id},this.addPostConnection=function(n){vart=ARCS.Invocation.cast(n,s);returnt.id=p++,a.push(t),t.id},this.addCleanup=function(n){vart=ARCS.Invocation.cast(n,s);returnt.id=h++,u.push(t),t.id},this.addConnection=function(n){vart=ARCS.Connection.cast(n,s);returnt.id=C++,f.push(t),t.id};vard=function(n,t){for(vare=t.length;e--&&t[e].id!==n;);e>=0?t.splice(e,1):console.warn("Could not remove data with id",n)};this.removePreConnection=function(n){d(n,c)},this.removePostConnection=function(n){d(n,a)},this.removeCleanup=function(n){d(n,u)};varv=function(n,t,e){for(varo=e.length;o--&&e[o].id!==n;);o>=0&&(e[o].value=t)};this.changePreConnection=function(n,t){v(n,t,c)},this.changePostConnection=function(n,t){v(n,t,a)},this.changeCleanup=function(n,t){v(n,t,u)},this.removeConnection=function(n){d(n,f)};varg=function(n,t,e){for(varo,i=e.length,r=e.length;i--&&e[i].id!==n;);for(;r--&&e[r].id!==t;);i>=0&&r>=0&&(o=e[i],e[i]=e[r],e[r]=o,e[i].id=n,e[r].id=t)};this.swapConnections=function(n,t){g(n,t,f)},this.swapCleanups=function(n,t){g(n,t,u)},this.swapPreConnections=function(n,t){g(n,t,c)},this.swapPostConnections=function(n,t){g(n,t,a)};this.import=function(t){t.hasOwnProperty("context")&&(s=newARCS.Context(t.context)).setParent(n),s.instanciate().then((function(){!function(n){vart=0,e=ARCS.Invocation.cast,o=ARCS.Connection.cast;for(t=0;t<n.preconnections.length;t++)c.push(e(n.preconnections[t],s));for(t=0;t<n.postconnections.length;t++)a.push(e(n.postconnections[t],s));for(t=0;t<n.cleanups.length;t++)u.push(e(n.cleanups[t],s));for(t=0;t<n.connections.length;t++)f.push(o(n.connections[t],s))}(t)}))};varS=function(n){return{destination:s.getComponentName(n.getDestination()),slot:n.getSlot(),value:n.getValue()}};this.toJSON=function(){varn,t,e=[],o=[],i=[],r=[];for(n=0;n<f.length;n++)i.push((t=f[n],{source:s.getComponentName(t.getSource()),signal:t.getSignal(),destination:s.getComponentName(t.getDestination()),slot:t.getSlot()}));for(n=0;n<c.length;n++)e.push(S(c[n]));for(n=0;n<a.length;n++)o.push(S(a[n]));for(n=0;n<u.length;n++)r.push(S(u[n]));return{preconnections:e,postconnections:o,connections:i,cleanups:r}},s.setParent(n)},ARCS.EventLogicParser=function(){functionn(n,t,e,o,i,r){this.message=n,this.expected=t,this.found=e,this.offset=o,this.line=i,this.column=r,this.name="SyntaxError"}returnfunction(n,t){functione(){this.constructor=n}e.prototype=t.prototype,n.prototype=newe}(n,Error),{SyntaxError:n,parse:function(t){vare,o=arguments.length>1?arguments[1]:{},i={},r={start:U},s=U,c=i,a=function(n,t){return[n].concat(t)},u=function(n){return{and:n}},f=function(n){return{or:n}},l=function(n){returnn},p="(",h={type:"literal",value:"(",description:'"("'},C=")",d={type:"literal",value:")",description:'")"'},v=function(n){return[n]},g={type:"other",description:"id"},S=function(n){returnn.trim()},A=/^[_a-zA-Z]/,m={type:"class",value:"[_a-zA-Z]",description:"[_a-zA-Z]"},y=/^[_a-zA-Z0-9]/,R={type:"class",value:"[_a-zA-Z0-9]",description:"[_a-zA-Z0-9]"},w="&",x={type:"literal",value:"&",description:'"&"'},P="|",O={type:"literal",value:"|",description:'"|"'},T=/^[\r\n\t]/,N={type:"class",value:"[ \\r\\n\\t]",description:"[ \\r\\n\\t]"},b=0,k=0,F={line:1,column:1,seenCR:!1},I=0,E=[],L=0;if("startRule"ino){if(!(o.startRuleinr))thrownewError("Can't start parsing from rule \""+o.startRule+'".');s=r[o.startRule]}functionj(n){returnk!==n&&(k>n&&(k=0,F={line:1,column:1,seenCR:!1}),function(n,e,o){vari,r;for(i=e;i<o;i++)"\n"===(r=t.charAt(i))?(n.seenCR||n.line++,n.column=1,n.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(n.line++,n.column=1,n.seenCR=!0):(n.column++,n.seenCR=!1)}(F,k,n),k=n),F}function_(n){b<I||(b>I&&(I=b,E=[]),E.push(n))}functionq(e,o,i){varr=j(i),s=i<t.length?t.charAt(i):null;returnnull!==o&&function(n){vart=1;for(n.sort((function(n,t){returnn.description<t.description?-1:n.description>t.description?1:0}));t<n.length;)n[t-1]===n[t]?n.splice(t,1):t++}(o),newn(null!==e?e:function(n,t){vare,o=newArray(n.length);for(e=0;e<n.length;e++)o[e]=n[e].description;return"Expected "+(n.length>1?o.slice(0,-1).join(", ")+" or "+o[n.length-1]:o[0])+" but "+(t?'"'+function(n){functiont(n){returnn.charCodeAt(0).toString(16).toUpperCase()}returnn.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,(function(n){return"\\x0"+t(n)})).replace(/[\x10-\x1F\x80-\xFF]/g,(function(n){return"\\x"+t(n)})).replace(/[\u0180-\u0FFF]/g,(function(n){return"\\u0"+t(n)})).replace(/[\u1080-\uFFFF]/g,(function(n){return"\\u"+t(n)}))}(t)+'"':"end of input")+" found."}(o,s),o,s,i,r.line,r.column)}functionU(){returnD()}functionD(){varn,t,e,o;if(n=b,(t=Z())!==i){if(e=[],(o=z())!==i)for(;o!==i;)e.push(o),o=z();elsee=c;e!==i?(n,n=t=a(t,e)):(b=n,n=c)}elseb=n,n=c;returnn===i&&(n=Z()),n}functionz(){varn,e;returnn=b,function(){varn,e,o,r;n=b,(e=V())!==i?(38===t.charCodeAt(b)?(o=w,b++):(o=i,0===L&&_(x)),o!==i&&(r=V())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c);returnn}()!==i&&(e=Z())!==i?(n,n=u(e)):(b=n,n=c),n===i&&(n=b,function(){varn,e,o,r;n=b,(e=V())!==i?(124===t.charCodeAt(b)?(o=P,b++):(o=i,0===L&&_(O)),o!==i&&(r=V())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c);returnn}()!==i&&(e=Z())!==i?(n,n=f(e)):(b=n,n=c)),n}functionZ(){varn,e,o,r;returnn=b,(e=function(){varn,e,o;L++,n=b,e=b,(o=function(){varn,e,o,r,s;if(n=b,(e=V())!==i)if(A.test(t.charAt(b))?(o=t.charAt(b),b++):(o=i,0===L&&_(m)),o!==i){for(r=[],y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));s!==i;)r.push(s),y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));r!==i&&(s=V())!==i?n=e=[e,o,r,s]:(b=n,n=c)}elseb=n,n=c;elseb=n,n=c;returnn}())!==i&&(o=t.substring(e,b));(e=o)!==i&&(n,e=S(e));L--,(n=e)===i&&(e=i,0===L&&_(g));returnn}())!==i&&(n,e=l(e)),(n=e)===i&&(n=b,40===t.charCodeAt(b)?(e=p,b++):(e=i,0===L&&_(h)),e!==i&&(o=D())!==i?(41===t.charCodeAt(b)?(r=C,b++):(r=i,0===L&&_(d)),r!==i?(n,n=e=v(o)):(b=n,n=c)):(b=n,n=c)),n}functionV(){varn,e;for(n=[],T.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(N));e!==i;)n.push(e),T.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(N));returnn}if((e=s())!==i&&b===t.length)returne;throwe!==i&&b<t.length&&_({type:"end",description:"end of input"}),q(null,E,I)}}}(),ARCS.TokenEvent=function(){varn,t;this.promise=newPromise((function(e,o){n=e,t=o})),this.accept=function(){n()},this.abort=function(){t()}},ARCS.TransitionNetwork=function(){this.promise={},this.and=function(n){returnthis.promise=Promise.all([this.promise,n.promise]),this},this.or=function(n){returnthis.promise=Promise.race([this.promise,n.promise]),this}},ARCS.TransitionNetwork.build=function(n,t){vare,o,r;if("string"==typeofn){vars;t.hasOwnProperty(n)?s=t[n]:t[n]=s=newARCS.TokenEvent;varc=newARCS.TransitionNetwork;returnc.promise=s.promise,c}for(e=ARCS.TransitionNetwork.build(n[0],t),i=1;i<n.length;i++)n[i].hasOwnProperty("and")?(r=ARCS.TransitionNetwork.build(n[i].and,t),o=e.and(r)):n[i].hasOwnProperty("or")?(r=ARCS.TransitionNetwork.build(n[i].or,t),o=e.or(r)):console.warn("[ARCS] Illegal tree"),e=o;returne},ARCS.Statemachine=newARCS.Component.create((function(n){vart="",e="",o={},i="",r=this,s={},c={},a=function(n){vart;r.slots.indexOf(n)<0&&(r.slots.push(n),r[n]=(t=n,function(){r.setToken(t)}))},u=function(n){vart;if(o.hasOwnProperty(n))for(tinc={},o[n])o[n].hasOwnProperty(t)&&ARCS.TransitionNetwork.build(s[t],c).promise.then((function(){vare;for(einc)c.hasOwnProperty(e)&&c[e].abort();u(o[n][t])}));i=n,r.emit("requestSheet",i),i===e&&r.emit("requestTermination")};this.setInitialState=function(n){i=t=n},this.setFinalState=function(n){e=n},this.addTransition=function(n,t,e){vari,r=/([A-Za-z_]\w*)/g;try{varc;if("string"==typeof(c=ARCS.EventLogicParser.parse(t)))a(c);elsefor(;null!==(i=r.exec(t));)a(i[0]);s[t]=c,void0===o[n]&&(o[n]={}),o[n][t]=e}catch(n){}},this.setToken=function(n){c.hasOwnProperty(n)&&c[n].accept()},this.setTransitions=function(n){vart,e;for(tinn)if(n.hasOwnProperty(t))for(einn[t])n[t].hasOwnProperty(e)&&this.addTransition(t,e,n[t][e])},this.start=function(){console.log("statemachine",this,t,n),u(t)},void0!==n&&(t=n.initial,e=n.final,this.setTransitions(n.transitions),i="")}),["setToken"],["requestSheet","requestTermination"]),ARCS.Application=function(){varn,t=newARCS.Context,e={},o={},i=[],r=this,s="";this.export=function(){return{context:t,controller:t.getComponentName(o),sheets:e}},this.getContext=function(){returnt},this.getSheetList=function(){returnObject.keys(e)},this.getSheet=function(n){returne[n]},this.addSheet=function(n,o){e[n]=o,o.setContext(t)},this.removeSheet=function(n){deletee[n]},n=function(){varn,i,s;for(i=t.getComponent(o),o=i,s=Object.keys(e),n=0;n<s.length;n++)(i=newARCS.Sheet(t)).import(e[s[n]],t),e[s[n]]=i;ARCS.Component.connect(o,"requestSheet",r,"setSheet"),ARCS.Component.connect(o,"requestTermination",r,"finish"),o.start()},this.setController=function(n){o=t.getComponent(n)},this.setSheet=function(n){e.hasOwnProperty(n)?(s&&e[s].deactivate(),e[s=n].activate()):console.warn("[ARCS] Tried to activate hollow sheet named: "+n)},this.finish=function(){s&&e[s].deactivate()},this.import=function(n){t=newARCS.Context(n.context),e=n.sheets,void0===(o=n.controller)&&console.error("[ARCS] Undefined controller. Cannot start application.")},this.setFactory=function(n,t){factories[n]=t},this.setDependency=function(n){i[n]={}},this.start=function(){console.log("[ARCS] Starting application..."),t.instanciate().then(n)}},ARCS.Application.setDependency=function(n,t){n.setDependency(t)},ARCS.Component.create(ARCS.Application),ARCS.Application.slot("setSheet"),ARCS.Application.slot("finish");export{ARCSasdefault};