Jean-Yves Didier

multiple target for webpack

var ARCS=ARCS||{};ARCS.isInNode=function(){return"function"==typeof require&&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){return void 0===n.prototype?(console.error("Cannot create such a component"),0):(n.prototype.slots=[],n.prototype.signals={},n.slotList=function(){return n.prototype.slots},n.prototype.slotList=function(){return n.prototype.slots},n.prototype.signalList=function(){var t,e=[];for(t in n.prototype.signals)e.push(t);return e},n.signalList=function(){return n.prototype.signalList()},n.prototype.emit=function(n){var t,e,o,i=Array.prototype.slice.call(arguments,1);for(t in this.signals[n])e=this.signals[n][t].func,o=this.signals[n][t].obj,e.apply(o,i)},n.slot=function(t,e){var o;if(t instanceof Array)for(o=0;o<t.length;o++)n.prototype.slots.push(t[o]);else n.prototype.slots.push(t),void 0!==e&&(n.prototype[t]=e)},n.signal=function(t){var e;if(t instanceof Array)for(e=0;e<t.length;e++)n.prototype.signals[t[e]]=1;else n.prototype.signals[t]=1},void 0!==t&&n.slot(t),void 0!==e&&n.signal(e),n)},check:function(n){return void 0!==n.prototype&&(void 0!==n.prototype.signals&&void 0!==n.prototype.slots)},connect:function(n,t,e,o){var i,r;if(void 0===n.signals)throw ARCS.Component.SourceIsNotComponent;if(void 0===n.signals[t])throw ARCS.Component.UndefinedSignal;if(void 0===e[o])throw ARCS.Component.UndefinedSlot;if(!n.hasOwnProperty("signals"))for(r in i=n.signals,n.signals={},i)n.signals[r]=[];n.signals[t].push({obj:e,func:e[o]})},disconnect:function(n,t,e,o){var i;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(void 0===n[t])throw ARCS.Component.UndefinedSlot;n[t].apply(n,e)},config:function(n,t){"function"==typeof n.config&&n.config(t)}},ARCS.Context=function(n){var t={},e={},o={},i=[],r=this;if(o.StateMachine=ARCS.Statemachine,void 0!==n){var s;for(s in i=n.libraries,n.components)n.components.hasOwnProperty(s)&&(t[s]=n.components[s]);if(void 0!==n.constants)for(s in n.constants)n.constants.hasOwnProperty(s)&&(e[s]=n.constants[s])}var c=async function(n){return ARCS.isInNode()?new Promise((function(t,e){var o=require(n);void 0!==o?t(o):e("[ARCS] File not found")})):(await fetch(n)).json()},a=function(){var n,r=[];for(n in t)if(t.hasOwnProperty(n)){if(void 0===o[t[n].type])return console.error("[ARCS] Factory "+t[n].type+" not found."),void console.error("[ARCS] Context dump follows: ",i,t,e);var s=o[t[n].type];try{if(void 0!==t[n].value||void 0!==t[n].url||void 0!==t[n].ref){if(void 0!==t[n].value&&(t[n].instance=new s(t[n].value)),void 0!==t[n].url){console.log("loading data file",t[n].url),r.push(c(t[n].url).then(function(n,e){return function(o){return console.log("instanciating from data file"),t[n].instance=new e(o),Promise.resolve()}}(n,s)))}void 0!==t[n].ref&&void 0!==e[t[n].ref]&&(t[n].instance=new s(e[t[n].ref]))}else t[n].instance=new s}catch(t){console.error("[ARCS] Component of type ",n," not instanciated.",t)}}return Promise.all(r)};this.loadLibrary=function(n,t){var e=n,o=n;return ARCS.Context.currentContext=r,"string"!=typeof n&&(o=n.name,e=n.url),i.indexOf(o)<0&&i.push(o),import(e).then((function(n){for(s in n.default)n.default.hasOwnProperty(s)&&ARCS.Context.currentContext.setFactory(s,n.default[s]);void 0!==t&&t()})).catch((function(n){console.error("[ARCS] Trouble loading '",e,"' with reason -",n)}))},this.getComponentList=function(){var n,e=Object.keys(t);for(n=0;n<e.length;n++)t.hasOwnProperty(e[n])||e.splice(n--,1);return e},this.getConstant=function(n){return e[n]},this.getComponentType=function(n){if(void 0!==t[n])return t[n].type},this.getComponentValue=function(n){if(void 0!==t[n])return t[n].value},this.getComponent=function(n){if(void 0!==t[n])return t[n].instance},this.getComponentName=function(n){var e,o;for(o=t.getComponentList(),e=0;e<o.length;e++)if(t[o[e]].instance===n)return o[e]},this.setFactory=function(n,t){o[n]=t},this.toJSON=function(){var n,e={};for(n in t)t.hasOwnProperty(n)&&(e[n]={type:t[n].type,value:t[n].value});return e},this.setComponentValue=function(n,e){t[n].value=e},this.addComponent=function(n,e,i){var r;t[n]={},t[n].type=e,t[n].value=i;var s=o[e];void 0!==s&&(r=new s(i)),t[n].instance=r},this.removeComponent=function(n){delete t[n]},this.getFactory=function(n){return o[n]},this.getFactoryList=function(){return Object.keys(o)},this.instanciate=function(){
//! TODO
return function(){var n;ARCS.Context.currentContext=r;var t=[];for(n=0;n<i.length;n++)t.push(r.loadLibrary(i[n]));return Promise.all(t)}().then(a).catch((function(n){console.error("[ARCS] Trouble instanciating context",n)}))};var u=function(n,t){var e,o=Object.create(t);for(e in n)n.hasOwnProperty(e)&&(o[e]=n[e]);return o};this.chain=function(n,i,r){return[u(n,t),u(i,e),u(r,o)]},this.setParent=function(n){if(void 0!==n){var i=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(){return n},this.getSlot=function(){return t},this.getValue=function(){return e},this.invoke=function(){var o=n[t];void 0!==o?o.apply(n,e):console.error("Undefined slot %s of component %s",t,n)}},ARCS.Invocation.cast=function(n,t){if(void 0!==n.value){var e=t.getComponent(n.destination);return void 0===e&&console.error("[ARCS] Destination ",n.destination," is undefined"),new ARCS.Invocation(e,n.slot,n.value)}if(void 0!==n.ref)return new ARCS.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(){return n},this.getDestination=function(){return e},this.getSlot=function(){return o},this.getSignal=function(){return t}},ARCS.Connection.cast=function(n,t){return new ARCS.Connection(t.getComponent(n.source),n.signal,t.getComponent(n.destination),n.slot)},ARCS.Sheet=function(n){var t,e,o,i,r,s=new ARCS.Context,c=[],a=[],u=[],f=[],l=0,p=0,h=0,C=0;t=function(){var n;for(n=0;n<c.length;n++)c[n].invoke()},e=function(){var n;for(n=0;n<a.length;n++)a[n].invoke()},o=function(){var n;for(n=0;n<u.length;n++)u[n].invoke()},i=function(){var n;for(n=0;n<f.length;n++)f[n].connect()},r=function(){var n;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){var t=ARCS.Invocation.cast(n,s);return t.id=l++,c.push(t),t.id},this.addPostConnection=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=p++,a.push(t),t.id},this.addCleanup=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=h++,u.push(t),t.id},this.addConnection=function(n){var t=ARCS.Connection.cast(n,s);return t.id=C++,f.push(t),t.id};var d=function(n,t){for(var e=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)};var v=function(n,t,e){for(var o=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)};var g=function(n,t,e){for(var o,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=new ARCS.Context(t.context)).setParent(n),s.instanciate().then((function(){!function(n){var t=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)}))};var S=function(n){return{destination:s.getComponentName(n.getDestination()),slot:n.getSlot(),value:n.getValue()}};this.toJSON=function(){var n,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(){function n(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"}return function(n,t){function e(){this.constructor=n}e.prototype=t.prototype,n.prototype=new e}(n,Error),{SyntaxError:n,parse:function(t){var e,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){return n},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){return n.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"in o){if(!(o.startRule in r))throw new Error("Can't start parsing from rule \""+o.startRule+'".');s=r[o.startRule]}function j(n){return k!==n&&(k>n&&(k=0,F={line:1,column:1,seenCR:!1}),function(n,e,o){var i,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))}function q(e,o,i){var r=j(i),s=i<t.length?t.charAt(i):null;return null!==o&&function(n){var t=1;for(n.sort((function(n,t){return n.description<t.description?-1:n.description>t.description?1:0}));t<n.length;)n[t-1]===n[t]?n.splice(t,1):t++}(o),new n(null!==e?e:function(n,t){var e,o=new Array(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){function t(n){return n.charCodeAt(0).toString(16).toUpperCase()}return n.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)}function U(){return D()}function D(){var n,t,e,o;if(n=b,(t=Z())!==i){if(e=[],(o=z())!==i)for(;o!==i;)e.push(o),o=z();else e=c;e!==i?(n,n=t=a(t,e)):(b=n,n=c)}else b=n,n=c;return n===i&&(n=Z()),n}function z(){var n,t;return n=b,B()!==i&&(t=Z())!==i?(n,n=u(t)):(b=n,n=c),n===i&&(n=b,M()!==i&&(t=Z())!==i?(n,n=f(t)):(b=n,n=c)),n}function Z(){var n,e,o,r;return n=b,(e=V())!==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}function V(){var n,e,o;return L++,n=b,e=b,(o=J())!==i&&(o=t.substring(e,b)),(e=o)!==i&&(n,e=S(e)),L--,(n=e)===i&&(e=i,0===L&&_(g)),n}function J(){var n,e,o,r,s;if(n=b,(e=G())!==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=G())!==i?n=e=[e,o,r,s]:(b=n,n=c)}else b=n,n=c;else b=n,n=c;return n}function B(){var n,e,o,r;return n=b,(e=G())!==i?(38===t.charCodeAt(b)?(o=w,b++):(o=i,0===L&&_(x)),o!==i&&(r=G())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c),n}function M(){var n,e,o,r;return n=b,(e=G())!==i?(124===t.charCodeAt(b)?(o=P,b++):(o=i,0===L&&_(O)),o!==i&&(r=G())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c),n}function G(){var n,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));return n}if((e=s())!==i&&b===t.length)return e;throw e!==i&&b<t.length&&_({type:"end",description:"end of input"}),q(null,E,I)}}}(),ARCS.TokenEvent=function(){var n,t;this.promise=new Promise((function(e,o){n=e,t=o})),this.accept=function(){n()},this.abort=function(){t()}},ARCS.TransitionNetwork=function(){this.promise={},this.and=function(n){return this.promise=Promise.all([this.promise,n.promise]),this},this.or=function(n){return this.promise=Promise.race([this.promise,n.promise]),this}},ARCS.TransitionNetwork.build=function(n,t){var e,o,i,r;if("string"==typeof n){var s;t.hasOwnProperty(n)?s=t[n]:t[n]=s=new ARCS.TokenEvent;var c=new ARCS.TransitionNetwork;return c.promise=s.promise,c}for(e=ARCS.TransitionNetwork.build(n[0],t),r=1;r<n.length;r++)n[r].hasOwnProperty("and")?(i=ARCS.TransitionNetwork.build(n[r].and,t),o=e.and(i)):n[r].hasOwnProperty("or")?(i=ARCS.TransitionNetwork.build(n[r].or,t),o=e.or(i)):console.warn("[ARCS] Illegal tree"),e=o;return e},ARCS.Statemachine=new ARCS.Component.create((function(n){var t="",e="",o={},i="",r=this,s={},c={},a=function(n){var t;r.slots.indexOf(n)<0&&(r.slots.push(n),r[n]=(t=n,function(){r.setToken(t)}))},u=function(n){var t;if(o.hasOwnProperty(n))for(t in c={},o[n])o[n].hasOwnProperty(t)&&ARCS.TransitionNetwork.build(s[t],c).promise.then((function(){var e;for(e in c)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){var i,r=/([A-Za-z_]\w*)/g;try{var c;if("string"==typeof(c=ARCS.EventLogicParser.parse(t)))a(c);else for(;null!==(i=r.exec(t));)a(i[0]);s[t]=c,void 0===o[n]&&(o[n]={}),o[n][t]=e}catch(n){}},this.setToken=function(n){c.hasOwnProperty(n)&&c[n].accept()},this.setTransitions=function(n){var t,e;for(t in n)if(n.hasOwnProperty(t))for(e in n[t])n[t].hasOwnProperty(e)&&this.addTransition(t,e,n[t][e])},this.start=function(){console.log("statemachine",this,t,n),u(t)},void 0!==n&&(t=n.initial,e=n.final,this.setTransitions(n.transitions),i="")}),["setToken"],["requestSheet","requestTermination"]),ARCS.Application=function(){var n,t=new ARCS.Context,e={},o={},i=[],r=this,s="";this.export=function(){return{context:t,controller:t.getComponentName(o),sheets:e}},this.getContext=function(){return t},this.getSheetList=function(){return Object.keys(e)},this.getSheet=function(n){return e[n]},this.addSheet=function(n,o){e[n]=o,o.setContext(t)},this.removeSheet=function(n){delete e[n]},n=function(){var n,i,s;for(i=t.getComponent(o),o=i,s=Object.keys(e),n=0;n<s.length;n++)(i=new ARCS.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=new ARCS.Context(n.context),e=n.sheets,void 0===(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{ARCS as default};
\ No newline at end of file
/*! For license information please see arcs.min.js.LICENSE.txt */
var t={d:(n,e)=>{for(var o in e)t.o(e,o)&&!t.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:e[o]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n)},n={};t.d(n,{Z:()=>m});var e={SourceIsNotComponent:{message:"Source is not a component"},UndefinedSignal:{message:"Signal is not defined"},UndefinedSlot:{message:"Slot is not defined"},create:function(t,n,e){return void 0===t.prototype?(console.error("Cannot create such a component"),0):(t.prototype.slots=[],t.prototype.signals={},t.slotList=function(){return t.prototype.slots},t.prototype.slotList=function(){return t.prototype.slots},t.prototype.signalList=function(){var n,e=[];for(n in t.prototype.signals)e.push(n);return e},t.signalList=function(){return t.prototype.signalList()},t.prototype.emit=function(t){var n,e,o,i=Array.prototype.slice.call(arguments,1);for(n in this.signals[t])e=this.signals[t][n].func,o=this.signals[t][n].obj,e.apply(o,i)},t.slot=function(n,e){var o;if(n instanceof Array)for(o=0;o<n.length;o++)t.prototype.slots.push(n[o]);else t.prototype.slots.push(n),void 0!==e&&(t.prototype[n]=e)},t.signal=function(n){var e;if(n instanceof Array)for(e=0;e<n.length;e++)t.prototype.signals[n[e]]=1;else t.prototype.signals[n]=1},void 0!==n&&t.slot(n),void 0!==e&&t.signal(e),t)},check:function(t){return void 0!==t.prototype&&void 0!==t.prototype.signals&&void 0!==t.prototype.slots},connect:function(t,n,o,i){var r,s;if(void 0===t.signals)throw e.SourceIsNotComponent;if(void 0===t.signals[n])throw e.UndefinedSignal;if(void 0===o[i])throw e.UndefinedSlot;if(!t.hasOwnProperty("signals"))for(s in r=t.signals,t.signals={},r)t.signals[s]=[];t.signals[n].push({obj:o,func:o[i]})},disconnect:function(t,n,e,o){var i;for(i=0;i<t.signals[n].length;i++)t.signals[n][i].obj===e&&t.signals[n][i].func===e[o]&&(t.signals[n].splice(i,1),i--)},invoke:function(t,n,o){if(void 0===t[n])throw e.UndefinedSlot;t[n].apply(t,o)},config:function(t,n){"function"==typeof t.config&&t.config(n)}};const o=e,i=function(){var t,n;this.promise=new Promise((function(e,o){t=e,n=o})),this.accept=function(){t()},this.abort=function(){n()}};let r=function(){this.promise={},this.and=function(t){return this.promise=Promise.all([this.promise,t.promise]),this},this.or=function(t){return this.promise=Promise.race([this.promise,t.promise]),this}};r.build=function(t,n){var e,o,s,c;if("string"==typeof t){var a;n.hasOwnProperty(t)?a=n[t]:n[t]=a=new i;var u=new r;return u.promise=a.promise,u}for(e=r.build(t[0],n),c=1;c<t.length;c++)t[c].hasOwnProperty("and")?(s=r.build(t[c].and,n),o=e.and(s)):t[c].hasOwnProperty("or")?(s=r.build(t[c].or,n),o=e.or(s)):console.warn("[ARCS] Illegal tree"),e=o;return e};const s=r,c=function(){function t(t,n,e,o,i,r){this.message=t,this.expected=n,this.found=e,this.offset=o,this.line=i,this.column=r,this.name="SyntaxError"}return function(t,n){function e(){this.constructor=t}e.prototype=n.prototype,t.prototype=new e}(t,Error),{SyntaxError:t,parse:function(n){var e,o=arguments.length>1?arguments[1]:{},i={},r={start:D},s=D,c=i,a=function(t,n){return[t].concat(n)},u=function(t){return{and:t}},f=function(t){return{or:t}},l=function(t){return t},h="(",p={type:"literal",value:"(",description:'"("'},d=")",v={type:"literal",value:")",description:'")"'},g=function(t){return[t]},y={type:"other",description:"id"},m=function(t){return t.trim()},C=/^[_a-zA-Z]/,w={type:"class",value:"[_a-zA-Z]",description:"[_a-zA-Z]"},S=/^[_a-zA-Z0-9]/,P={type:"class",value:"[_a-zA-Z0-9]",description:"[_a-zA-Z0-9]"},A="&",O={type:"literal",value:"&",description:'"&"'},x="|",b={type:"literal",value:"|",description:'"|"'},R=/^[ \r\n\t]/,F={type:"class",value:"[ \\r\\n\\t]",description:"[ \\r\\n\\t]"},N=0,T=0,j={line:1,column:1,seenCR:!1},k=0,L=[],E=0;if("startRule"in o){if(!(o.startRule in r))throw new Error("Can't start parsing from rule \""+o.startRule+'".');s=r[o.startRule]}function _(t){return T!==t&&(T>t&&(T=0,j={line:1,column:1,seenCR:!1}),function(t,e,o){var i,r;for(i=e;i<o;i++)"\n"===(r=n.charAt(i))?(t.seenCR||t.line++,t.column=1,t.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(t.line++,t.column=1,t.seenCR=!0):(t.column++,t.seenCR=!1)}(j,T,t),T=t),j}function U(t){N<k||(N>k&&(k=N,L=[]),L.push(t))}function Z(e,o,i){var r=_(i),s=i<n.length?n.charAt(i):null;return null!==o&&function(t){var n=1;for(t.sort((function(t,n){return t.description<n.description?-1:t.description>n.description?1:0}));n<t.length;)t[n-1]===t[n]?t.splice(n,1):n++}(o),new t(null!==e?e:function(t,n){var e,o=new Array(t.length);for(e=0;e<t.length;e++)o[e]=t[e].description;return"Expected "+(t.length>1?o.slice(0,-1).join(", ")+" or "+o[t.length-1]:o[0])+" but "+(n?'"'+function(t){function n(t){return t.charCodeAt(0).toString(16).toUpperCase()}return t.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(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x80-\xFF]/g,(function(t){return"\\x"+n(t)})).replace(/[\u0180-\u0FFF]/g,(function(t){return"\\u0"+n(t)})).replace(/[\u1080-\uFFFF]/g,(function(t){return"\\u"+n(t)}))}(n)+'"':"end of input")+" found."}(o,s),o,s,i,r.line,r.column)}function D(){return I()}function I(){var t,n,e,o;if(t=N,(n=z())!==i){if(e=[],(o=q())!==i)for(;o!==i;)e.push(o),o=q();else e=c;e!==i?t=n=a(n,e):(N=t,t=c)}else N=t,t=c;return t===i&&(t=z()),t}function q(){var t,n;return t=N,M()!==i&&(n=z())!==i?t=u(n):(N=t,t=c),t===i&&(t=N,B()!==i&&(n=z())!==i?t=f(n):(N=t,t=c)),t}function z(){var t,e,o,r;return t=N,(e=V())!==i&&(e=l(e)),(t=e)===i&&(t=N,40===n.charCodeAt(N)?(e=h,N++):(e=i,0===E&&U(p)),e!==i&&(o=I())!==i?(41===n.charCodeAt(N)?(r=d,N++):(r=i,0===E&&U(v)),r!==i?t=e=g(o):(N=t,t=c)):(N=t,t=c)),t}function V(){var t,e,o;return E++,t=N,e=N,(o=J())!==i&&(o=n.substring(e,N)),(e=o)!==i&&(e=m(e)),E--,(t=e)===i&&(e=i,0===E&&U(y)),t}function J(){var t,e,o,r,s;if(t=N,(e=G())!==i)if(C.test(n.charAt(N))?(o=n.charAt(N),N++):(o=i,0===E&&U(w)),o!==i){for(r=[],S.test(n.charAt(N))?(s=n.charAt(N),N++):(s=i,0===E&&U(P));s!==i;)r.push(s),S.test(n.charAt(N))?(s=n.charAt(N),N++):(s=i,0===E&&U(P));r!==i&&(s=G())!==i?t=e=[e,o,r,s]:(N=t,t=c)}else N=t,t=c;else N=t,t=c;return t}function M(){var t,e,o,r;return t=N,(e=G())!==i?(38===n.charCodeAt(N)?(o=A,N++):(o=i,0===E&&U(O)),o!==i&&(r=G())!==i?t=e=[e,o,r]:(N=t,t=c)):(N=t,t=c),t}function B(){var t,e,o,r;return t=N,(e=G())!==i?(124===n.charCodeAt(N)?(o=x,N++):(o=i,0===E&&U(b)),o!==i&&(r=G())!==i?t=e=[e,o,r]:(N=t,t=c)):(N=t,t=c),t}function G(){var t,e;for(t=[],R.test(n.charAt(N))?(e=n.charAt(N),N++):(e=i,0===E&&U(F));e!==i;)t.push(e),R.test(n.charAt(N))?(e=n.charAt(N),N++):(e=i,0===E&&U(F));return t}if((e=s())!==i&&N===n.length)return e;throw e!==i&&N<n.length&&U({type:"end",description:"end of input"}),Z(null,L,k)}}}(),a=o.create((function(t){var n="",e="",o={},i="",r=this,a={},u={},f=function(t){var n;r.slots.indexOf(t)<0&&(r.slots.push(t),r[t]=(n=t,function(){r.setToken(n)}))},l=function(t){var n;if(o.hasOwnProperty(t))for(n in u={},o[t])o[t].hasOwnProperty(n)&&s.build(a[n],u).promise.then((function(){var e;for(e in u)u.hasOwnProperty(e)&&u[e].abort();l(o[t][n])}));i=t,r.emit("requestSheet",i),i===e&&r.emit("requestTermination")};this.setInitialState=function(t){i=n=t},this.setFinalState=function(t){e=t},this.addTransition=function(t,n,e){var i,r=/([A-Za-z_]\w*)/g;try{var s;if("string"==typeof(s=c.parse(n)))f(s);else for(;null!==(i=r.exec(n));)f(i[0]);a[n]=s,void 0===o[t]&&(o[t]={}),o[t][n]=e}catch(t){}},this.setToken=function(t){u.hasOwnProperty(t)&&u[t].accept()},this.setTransitions=function(t){var n,e;for(n in t)if(t.hasOwnProperty(n))for(e in t[n])t[n].hasOwnProperty(e)&&this.addTransition(n,e,t[n][e])},this.start=function(){l(n)},void 0!==t&&(n=t.initial,e=t.final,this.setTransitions(t.transitions),i="")}),["setToken"],["requestSheet","requestTermination"]);function u(){return"undefined"!=typeof process&&-1!==process.release.name.search(/node|io.js/)}let f=function(t){var n={},e={},o={},i=[],r=this;if(o.StateMachine=a,void 0!==t){var s;for(s in i=t.libraries,t.components)t.components.hasOwnProperty(s)&&(n[s]=t.components[s]);if(void 0!==t.constants)for(s in t.constants)t.constants.hasOwnProperty(s)&&(e[s]=t.constants[s])}var c=async function(t){return u()?new Promise((function(n,e){var o=require(t);void 0!==o?n(o):e("[ARCS] File not found")})):(await fetch(t)).json()},l=function(){var t,r=[];for(t in n)if(n.hasOwnProperty(t)){if(void 0===o[n[t].type])return console.error("[ARCS] Factory "+n[t].type+" not found."),void console.error("[ARCS] Context dump follows: ",i,n,e);var s=o[n[t].type];try{void 0!==n[t].value||void 0!==n[t].url||void 0!==n[t].ref?(void 0!==n[t].value&&(n[t].instance=new s(n[t].value)),void 0!==n[t].url&&(console.log("loading data file",n[t].url),r.push(c(n[t].url).then(function(t,e){return function(o){return console.log("instanciating from data file"),n[t].instance=new e(o),Promise.resolve()}}(t,s)))),void 0!==n[t].ref&&void 0!==e[n[t].ref]&&(n[t].instance=new s(e[n[t].ref]))):n[t].instance=new s}catch(n){console.error("[ARCS] Component of type ",t," not instanciated.",n)}}return Promise.all(r)};this.loadLibrary=function(t,n){var e=t,o=t;return f.currentContext=r,"string"!=typeof t&&(o=t.name,e=t.url),i.indexOf(o)<0&&i.push(o),import(e).then((function(t){for(s in t.default)t.default.hasOwnProperty(s)&&f.currentContext.setFactory(s,t.default[s]);void 0!==n&&n()})).catch((function(t){console.error("[ARCS] Trouble loading '",e,"' with reason -",{msg:t})}))},this.getComponentList=function(){var t,e=Object.keys(n);for(t=0;t<e.length;t++)n.hasOwnProperty(e[t])||e.splice(t--,1);return e},this.getConstant=function(t){return e[t]},this.getComponentType=function(t){if(void 0!==n[t])return n[t].type},this.getComponentValue=function(t){if(void 0!==n[t])return n[t].value},this.getComponent=function(t){if(void 0!==n[t])return n[t].instance},this.getComponentName=function(t){var e,o;for(o=n.getComponentList(),e=0;e<o.length;e++)if(n[o[e]].instance===t)return o[e]},this.setFactory=function(t,n){o[t]=n},this.toJSON=function(){var t,e={};for(t in n)n.hasOwnProperty(t)&&(e[t]={type:n[t].type,value:n[t].value});return e},this.setComponentValue=function(t,e){n[t].value=e},this.addComponent=function(t,e,i){var r;n[t]={},n[t].type=e,n[t].value=i;var s=o[e];void 0!==s&&(r=new s(i)),n[t].instance=r},this.removeComponent=function(t){delete n[t]},this.getFactory=function(t){return o[t]},this.getFactoryList=function(){return Object.keys(o)},this.instanciate=function(){return function(){var t;f.currentContext=r;var n=[];for(t=0;t<i.length;t++)n.push(r.loadLibrary(i[t]));return Promise.all(n)}().then(l).catch((function(t){console.error("[ARCS] Trouble instanciating context",t)}))};var h=function(t,n){var e,o=Object.create(n);for(e in t)t.hasOwnProperty(e)&&(o[e]=t[e]);return o};this.chain=function(t,i,r){return[h(t,n),h(i,e),h(r,o)]},this.setParent=function(t){if(void 0!==t){var i=t.chain(n,e,o);n=i[0],e=i[1],o=i[2]}}};f.currentContext=null;const l=f;let h=function(t,n,e){this.getDestination=function(){return t},this.getSlot=function(){return n},this.getValue=function(){return e},this.invoke=function(){var o=t[n];void 0!==o?o.apply(t,e):console.error("Undefined slot %s of component %s",n,t)}};h.cast=function(t,n){if(void 0!==t.value){var e=n.getComponent(t.destination);return void 0===e&&console.error("[ARCS] Destination ",t.destination," is undefined"),new h(e,t.slot,t.value)}if(void 0!==t.ref)return new h(n.getComponent(t.destination),t.slot,n.getConstant(t.ref))},h.PRE_CONNECTION=0,h.POST_CONNECTION=1,h.CLEAN_UP=2;const p=h;let d=function(t,n,e,i){this.connect=function(){try{o.connect(t,n,e,i)}catch(o){console.log(o,t,n,e,i)}},this.disconnect=function(){o.disconnect(t,n,e,i)},this.getSource=function(){return t},this.getDestination=function(){return e},this.getSlot=function(){return i},this.getSignal=function(){return n}};d.cast=function(t,n){return new d(n.getComponent(t.source),t.signal,n.getComponent(t.destination),t.slot)};const v=d,g=function(t){var n,e,o,i,r,s=new l,c=[],a=[],u=[],f=[],h=0,d=0,g=0,y=0;n=function(){var t;for(t=0;t<c.length;t++)c[t].invoke()},e=function(){var t;for(t=0;t<a.length;t++)a[t].invoke()},o=function(){var t;for(t=0;t<u.length;t++)u[t].invoke()},i=function(){var t;for(t=0;t<f.length;t++)f[t].connect()},r=function(){var t;for(t=0;t<f.length;t++)f[t].disconnect()},this.setContext=function(t){s=t},this.activate=function(){s.instanciate().then((function(){n(),i(),e()}))},this.deactivate=function(){r(),o()},this.addPreConnection=function(t){var n=p.cast(t,s);return n.id=h++,c.push(n),n.id},this.addPostConnection=function(t){var n=p.cast(t,s);return n.id=d++,a.push(n),n.id},this.addCleanup=function(t){var n=p.cast(t,s);return n.id=g++,u.push(n),n.id},this.addConnection=function(t){var n=v.cast(t,s);return n.id=y++,f.push(n),n.id};var m=function(t,n){for(var e=n.length;e--&&n[e].id!==t;);e>=0?n.splice(e,1):console.warn("Could not remove data with id",t)};this.removePreConnection=function(t){m(t,c)},this.removePostConnection=function(t){m(t,a)},this.removeCleanup=function(t){m(t,u)};var C=function(t,n,e){for(var o=e.length;o--&&e[o].id!==t;);o>=0&&(e[o].value=n)};this.changePreConnection=function(t,n){C(t,n,c)},this.changePostConnection=function(t,n){C(t,n,a)},this.changeCleanup=function(t,n){C(t,n,u)},this.removeConnection=function(t){m(t,f)};var w=function(t,n,e){for(var o,i=e.length,r=e.length;i--&&e[i].id!==t;);for(;r--&&e[r].id!==n;);i>=0&&r>=0&&(o=e[i],e[i]=e[r],e[r]=o,e[i].id=t,e[r].id=n)};this.swapConnections=function(t,n){w(t,n,f)},this.swapCleanups=function(t,n){w(t,n,u)},this.swapPreConnections=function(t,n){w(t,n,c)},this.swapPostConnections=function(t,n){w(t,n,a)},this.import=function(n){n.hasOwnProperty("context")&&(s=new l(n.context)).setParent(t),s.instanciate().then((function(){!function(t){var n=0,e=p.cast,o=v.cast;for(n=0;n<t.preconnections.length;n++)c.push(e(t.preconnections[n],s));for(n=0;n<t.postconnections.length;n++)a.push(e(t.postconnections[n],s));for(n=0;n<t.cleanups.length;n++)u.push(e(t.cleanups[n],s));for(n=0;n<t.connections.length;n++)f.push(o(t.connections[n],s))}(n)}))};var S=function(t){return{destination:s.getComponentName(t.getDestination()),slot:t.getSlot(),value:t.getValue()}};this.toJSON=function(){var t,n,e=[],o=[],i=[],r=[];for(t=0;t<f.length;t++)i.push((n=f[t],{source:s.getComponentName(n.getSource()),signal:n.getSignal(),destination:s.getComponentName(n.getDestination()),slot:n.getSlot()}));for(t=0;t<c.length;t++)e.push(S(c[t]));for(t=0;t<a.length;t++)o.push(S(a[t]));for(t=0;t<u.length;t++)r.push(S(u[t]));return{preconnections:e,postconnections:o,connections:i,cleanups:r}},s.setParent(t)};let y=function(){var t,n=new l,e={},i={},r=[],s=this,c="";this.export=function(){return{context:n,controller:n.getComponentName(i),sheets:e}},this.getContext=function(){return n},this.getSheetList=function(){return Object.keys(e)},this.getSheet=function(t){return e[t]},this.addSheet=function(t,o){e[t]=o,o.setContext(n)},this.removeSheet=function(t){delete e[t]},t=function(){var t,r,c;for(r=n.getComponent(i),i=r,c=Object.keys(e),t=0;t<c.length;t++)(r=new g(n)).import(e[c[t]],n),e[c[t]]=r;o.connect(i,"requestSheet",s,"setSheet"),o.connect(i,"requestTermination",s,"finish"),i.start()},this.setController=function(t){i=n.getComponent(t)},this.setSheet=function(t){e.hasOwnProperty(t)?(c&&e[c].deactivate(),e[c=t].activate()):console.warn("[ARCS] Tried to activate hollow sheet named: "+t)},this.finish=function(){c&&e[c].deactivate()},this.import=function(t){n=new l(t.context),e=t.sheets,void 0===(i=t.controller)&&console.error("[ARCS] Undefined controller. Cannot start application.")},this.setFactory=function(t,n){factories[t]=n},this.setDependency=function(t){r[t]={}},this.start=function(){console.log("[ARCS] Starting application..."),n.instanciate().then(t)}};y.setDependency=function(t,n){t.setDependency(n)},o.create(y),y.slot("setSheet"),y.slot("finish");const m={Component:o,isInNode:u,StateMachine:a,Context:l,Invocation:p,Connection:v,Sheet:g,Application:y};var C=n.Z;export{C as default};
\ No newline at end of file
......
......@@ -3,114 +3,161 @@ const jsdoc = require('jsdoc-webpack-plugin');
const copy = require('copy-webpack-plugin');
const eslint = require('eslint-webpack-plugin');
module.exports = {
experiments : {
outputModule: true
},
entry: {
'arcs' : {
import : './src/exports.js',
module.exports = [
{
name: "core",
experiments : {
outputModule: true
},
entry: {
'arcs' : {
import : './src/exports.js',
},
},
mode: 'none',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
library: {
type: 'module',
}
},
module: {
parser: {
javascript: {
commonjsMagicComments: true
}
}
},
plugins: [
new eslint({}),
new copy({
patterns: [
{ from :'src/arcs_browser.js', to: 'arcs_browser.js'},
{ from: 'src/arcs_node.mjs', to: 'arcs_node.mjs'}
]
})
]
},
mode: 'none',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
library: {
type: 'module',
}
},
module: {
parser: {
javascript: {
commonjsMagicComments: true
{
name: "core-min",
experiments : {
outputModule: true
},
entry: {
'arcs' : {
import : './src/exports.js',
},
},
mode: 'production',
output: {
filename: '[name].min.js',
path: path.resolve(__dirname, 'build'),
library: {
type: 'module',
}
},
module: {
parser: {
javascript: {
commonjsMagicComments: true
}
}
}
},
},
plugins: [
new jsdoc({
conf: 'docs/engine.conf.json',
destination: 'docs/engine',
template: 'docs/arcs',
}),
new jsdoc({
conf: 'docs/components.conf.json',
destination: 'docs/components',
template: 'docs/arcs',
}),
new copy({
patterns: [
{ from :'src/arcs_browser.js', to: 'arcs_browser.js'},
{ from: 'src/arcs_node.mjs', to: 'arcs_node.mjs'},
{ from: 'node_modules/tracking/build/tracking.js', to: '../deps/tracking/tracking.js'},
{ from: 'node_modules/three/build/three.module.js', to: '../deps/three.js/index.js'},
{
from: 'node_modules/three/examples/jsm/loaders/OBJLoader.js',
to: '../deps/objloader/index.js',
transform: function(content, path) {
return Buffer.from(content.toString().replace(
'../../../build/three.module.js',
'../three.js/index.js'
));
}
},
{
from: 'node_modules/three/examples/jsm/loaders/MTLLoader.js',
to: '../deps/mtlloader/index.js',
transform: function(content, path) {
return Buffer.from(content.toString().replace(
'../../../build/three.module.js',
'../three.js/index.js'
));
}
},
{
from: 'node_modules/three/examples/jsm/loaders/DDSLoader.js',
to: '../deps/ddsloader/index.js',
transform: function(content, path) {
return Buffer.from(content.toString().replace(
'../../../build/three.module.js',
'../three.js/index.js'
));
}
},
{
from: 'node_modules/js-aruco/src/aruco.js',
to: '../deps/aruco/index.js',
transform: function(content, path) {
return Buffer.from(content.toString()
.replace(
"var CV = require('./cv');",
"import CV from '../cv/index.js';"
)
.replace(
"module.exports = AR;",
"export default AR;"
)
);
}
},
{
from: 'node_modules/js-aruco/src/cv.js',
to: '../deps/cv/index.js',
transform: function(content, path) {
return Buffer.from(content.toString()
.replace(
"module.exports = CV;",
"export default CV;"
)
);
}
},
// TODO put here also files for dep directory.
// can also prepend content and replace strings using the transform property!
]
}),
new eslint({})
]
};
{
name: "doc",
mode: "development",
entry: {},
plugins: [
new jsdoc({
conf: 'docs/engine.conf.json',
destination: 'docs/engine',
template: 'docs/arcs',
}),
new jsdoc({
conf: 'docs/components.conf.json',
destination: 'docs/components',
template: 'docs/arcs',
}),
]
},
{
name: "deps",
mode: "production",
entry: {},
plugins: [
new copy({
patterns: [
{ from: 'node_modules/tracking/build/tracking.js', to: '../deps/tracking/tracking.js'},
{ from: 'node_modules/three/build/three.module.js', to: '../deps/three.js/index.js'},
{
from: 'node_modules/three/examples/jsm/loaders/OBJLoader.js',
to: '../deps/objloader/index.js',
transform: function(content, path) {
return Buffer.from(content.toString().replace(
'../../../build/three.module.js',
'../three.js/index.js'
));
}
},
{
from: 'node_modules/three/examples/jsm/loaders/MTLLoader.js',
to: '../deps/mtlloader/index.js',
transform: function(content, path) {
return Buffer.from(content.toString().replace(
'../../../build/three.module.js',
'../three.js/index.js'
));
}
},
{
from: 'node_modules/three/examples/jsm/loaders/DDSLoader.js',
to: '../deps/ddsloader/index.js',
transform: function(content, path) {
return Buffer.from(content.toString().replace(
'../../../build/three.module.js',
'../three.js/index.js'
));
}
},
{
from: 'node_modules/js-aruco/src/aruco.js',
to: '../deps/aruco/index.js',
transform: function(content, path) {
return Buffer.from(content.toString()
.replace(
"var CV = require('./cv');",
"import CV from '../cv/index.js';"
)
.replace(
"module.exports = AR;",
"export default AR;"
)
);
}
},
{
from: 'node_modules/js-aruco/src/cv.js',
to: '../deps/cv/index.js',
transform: function(content, path) {
return Buffer.from(content.toString()
.replace(
"module.exports = CV;",
"export default CV;"
)
);
}
},
// TODO put here also files for dep directory.
// can also prepend content and replace strings using the transform property!
]
}),
]
}
];
......