Jean-Yves Didier

added full support for a remote console

...@@ -14,6 +14,7 @@ __webpack_require__.r(__webpack_exports__); ...@@ -14,6 +14,7 @@ __webpack_require__.r(__webpack_exports__);
14 /* harmony import */ var _connection_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(9); 14 /* harmony import */ var _connection_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(9);
15 /* harmony import */ var _sheet_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(10); 15 /* harmony import */ var _sheet_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(10);
16 /* harmony import */ var _application_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(11); 16 /* harmony import */ var _application_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(11);
17 +/* harmony import */ var _remoteconsole_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(12);
17 // no longer needed with the use of imports 18 // no longer needed with the use of imports
18 19
19 20
...@@ -25,6 +26,7 @@ __webpack_require__.r(__webpack_exports__); ...@@ -25,6 +26,7 @@ __webpack_require__.r(__webpack_exports__);
25 26
26 27
27 28
29 +
28 let ARCS = { 30 let ARCS = {
29 Component: _component_js__WEBPACK_IMPORTED_MODULE_0__["default"], 31 Component: _component_js__WEBPACK_IMPORTED_MODULE_0__["default"],
30 isInNode : _isinnode_js__WEBPACK_IMPORTED_MODULE_2__["default"], 32 isInNode : _isinnode_js__WEBPACK_IMPORTED_MODULE_2__["default"],
...@@ -33,6 +35,7 @@ let ARCS = { ...@@ -33,6 +35,7 @@ let ARCS = {
33 Invocation: _invocation_js__WEBPACK_IMPORTED_MODULE_4__["default"], 35 Invocation: _invocation_js__WEBPACK_IMPORTED_MODULE_4__["default"],
34 Connection: _connection_js__WEBPACK_IMPORTED_MODULE_5__["default"], 36 Connection: _connection_js__WEBPACK_IMPORTED_MODULE_5__["default"],
35 Sheet: _sheet_js__WEBPACK_IMPORTED_MODULE_6__["default"], 37 Sheet: _sheet_js__WEBPACK_IMPORTED_MODULE_6__["default"],
38 + RemoteConsole: _remoteconsole_js__WEBPACK_IMPORTED_MODULE_8__["default"],
36 Application: _application_js__WEBPACK_IMPORTED_MODULE_7__["default"], 39 Application: _application_js__WEBPACK_IMPORTED_MODULE_7__["default"],
37 __lib__: ()=>{} 40 __lib__: ()=>{}
38 }; 41 };
...@@ -2565,6 +2568,113 @@ Application.slot("finish"); ...@@ -2565,6 +2568,113 @@ Application.slot("finish");
2565 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Application); 2568 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Application);
2566 2569
2567 2570
2571 +/***/ }),
2572 +/* 12 */
2573 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2574 +
2575 +__webpack_require__.r(__webpack_exports__);
2576 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
2577 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
2578 +/* harmony export */ });
2579 +
2580 +class RemoteConsole {
2581 + #stack= [];
2582 + #server;
2583 + #idxSource;
2584 + _log = globalThis.console.log;
2585 + _info = globalThis.console.info;
2586 + _warn = globalThis.console.warn;
2587 + _error = globalThis.console.error;
2588 +
2589 + constructor(address) {
2590 + let self = this;
2591 +
2592 + console.error = this.error;
2593 + console.warn = this.warn;
2594 + console.info = this.info;
2595 + console.log = this.log;
2596 + console.tainted = true;
2597 +
2598 + if (globalThis.window) {
2599 + globalThis.window.onerror = this.runtimeException;
2600 + }
2601 +
2602 + if (globalThis.WebSocket && globalThis.navigator) {
2603 + this.#server = new globalThis.WebSocket(address);
2604 + this.#idxSource = (globalThis.navigator.userAgent.match(/firefox|fxios/i))?2:3;
2605 + this.#server.onopen = function() {
2606 + self.#flush();
2607 + }
2608 + }
2609 + }
2610 +
2611 + #currentPlace() {
2612 + let err = new Error();
2613 + let lst = err.stack.split("\n");
2614 + return lst[this.#idxSource];
2615 + }
2616 +
2617 + #send(data) {
2618 + if (!this.#server) return ;
2619 +
2620 + if (this.#server.readyState === WebSocket.OPEN ) {
2621 + this.#server.send(data);
2622 + } else {
2623 + this.#stack.push(data);
2624 + }
2625 + }
2626 +
2627 + #flush () {
2628 + if (!this.#server) return ;
2629 +
2630 + if (this.#server.readyState !== WebSocket.OPEN)
2631 + return ;
2632 + this.#stack.forEach(elt => this.#server.send(elt));
2633 + this.#stack = [];
2634 + }
2635 +
2636 + #notify(type) {
2637 + let self = this;
2638 + return function() {
2639 + let obj = { type, args: Array.from(arguments), context: self.#currentPlace() };
2640 + self[`_${type}`].apply(globalThis.console, obj.args);
2641 +
2642 + let serializedObject = "";
2643 +
2644 + try {
2645 + serializedObject = JSON.stringify(obj);
2646 + } catch(e) {
2647 + obj.args= [ 'Argument(s) not serializable' ];
2648 + serializedObject = JSON.stringify(obj);
2649 + }
2650 + self.#send(serializedObject);
2651 + };
2652 + }
2653 +
2654 + #runtimeException (msg, url, line, column,err) {
2655 + if (!this.#server) return false;
2656 +
2657 + this.#server.send(
2658 + JSON.stringify(
2659 + {type: "exception", args: [{ message: msg, url: url, line: line, column: column }] }
2660 + )
2661 + );
2662 + return false;
2663 + }
2664 +
2665 + log = this.#notify('log');
2666 + info = this.#notify('info');
2667 + warn = this.#notify('warn');
2668 + error = this.#notify('error');
2669 +
2670 +};
2671 +
2672 +
2673 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (RemoteConsole);
2674 +
2675 +
2676 +
2677 +
2568 /***/ }) 2678 /***/ })
2569 /******/ ]); 2679 /******/ ]);
2570 /************************************************************************/ 2680 /************************************************************************/
......
1 /*! For license information please see arcs.min.js.LICENSE.txt */ 1 /*! For license information please see arcs.min.js.LICENSE.txt */
2 -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:()=>w});class e{constructor(t,n){this.slots=[],this.signals={},void 0!==t&&this.slot(t),void 0!==n&&this.signal(n)}slotList(){return this.slots}signalList(){return Object.keys(this.signals)}emit(t){let 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)}slot(t,n){let e=this;t instanceof Array?t.forEach((t=>{e.slots.includes(t)||e.slot(t)})):(this.slots.includes(t)||this.slots.push(t),void 0!==n&&(this[t]=n))}signal(t){let n=this;t instanceof Array?t.forEach((t=>{n.signals[t]=[]})):this.signals[t]=[]}static create(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 this.slots},t.prototype.signalList=function(){return Object.keys(this.signals)},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.prototype.slot=function(n,e){this.hasOwnProperty("slots")||(this.slots=t.prototype.slots.map((t=>t))),this.slots.includes(n)||this.slots.push(n),this[n]=e},t.prototype.signal=function(n){this.hasOwnProperty("signals")||(this.signals={},Object.assign(this.signals,t.prototype.signals)),this.signals[n]=[]},t.slot=function(n,e){var o;if(n instanceof Array)for(o=0;o<n.length;o++)t.prototype.slots.includes(n[o])||t.prototype.slots.push(n[o]);else t.prototype.slots.includes(n)||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]]=[];else t.prototype.signals[n]=[]},void 0!==n&&t.slot(n),void 0!==e&&t.signal(e),t)}static check(t){return void 0!==t.prototype&&void 0!==t.prototype.signals&&void 0!==t.prototype.slots}static connect(t,n,o,i){var s,r;if(void 0===t.signals)throw e.SourceIsNotComponent;if(void 0===t.signals[n]){let t=Object.assign({},e.UndefinedSignal);throw t.message=t.message+': "'+n+'"',t}if(void 0===o[i]){let t=Object.assign({},e.UndefinedSlot);throw t.message=t.message+': "'+i+'"',t}if(!t.hasOwnProperty("signals"))for(r in s=t.signals,t.signals={},s)t.signals[r]=[];t.signals[n].push({obj:o,func:o[i]})}static disconnect(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--)}static invoke(t,n,o){if(void 0===t[n])throw e.UndefinedSlot;t[n].apply(t,o)}static config(t,n){"function"==typeof t.config&&t.config(n)}}e.SourceIsNotComponent={message:"Source is not a component"},e.UndefinedSignal={message:"Signal is not defined"},e.UndefinedSlot={message:"Slot is not defined"};const o=e,i=function(t,n){this.eval=function(){return t[n]}},s=function(t,n,e){this.eval=function(){return n.eval(t)||e.eval(t)}},r=function(t,n,e){this.eval=function(t){return n.eval(t)&&e.eval(t)}};let c={build:function(t,n){var e,o,a,u;if("string"==typeof t)return n[t]=n[t]??!1,new i(n,t);for(e=c.build(t[0],n),u=1;u<t.length;u++)t[u].hasOwnProperty("and")?(a=c.build(t[u].and,n),o=new r(n,e,a)):t[u].hasOwnProperty("or")?(a=c.build(t[u].or,n),o=new s(n,e,a)):console.warn("[ARCS] Illegal tree"),e=o;return e}};const a=c,u=function(){function t(t,n,e,o,i,s){this.message=t,this.expected=n,this.found=e,this.offset=o,this.line=i,this.column=s,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={},s={start:Z},r=Z,c=i,a=function(t,n){return[t].concat(n)},u=function(t){return{and:t}},l=function(t){return{or:t}},f=function(t){return t},h="(",p={type:"literal",value:"(",description:'"("'},d=")",g={type:"literal",value:")",description:'")"'},v=function(t){return[t]},y={type:"other",description:"id"},C=function(t){return t.trim()},m=/^[_a-zA-Z]/,w={type:"class",value:"[_a-zA-Z]",description:"[_a-zA-Z]"},S=/^[_a-zA-Z0-9]/,A={type:"class",value:"[_a-zA-Z0-9]",description:"[_a-zA-Z0-9]"},O="&",P={type:"literal",value:"&",description:'"&"'},x="|",b={type:"literal",value:"|",description:'"|"'},R=/^[ \r\n\t]/,j={type:"class",value:"[ \\r\\n\\t]",description:"[ \\r\\n\\t]"},F=0,k=0,N={line:1,column:1,seenCR:!1},T=0,L=[],E=0;if("startRule"in o){if(!(o.startRule in s))throw new Error("Can't start parsing from rule \""+o.startRule+'".');r=s[o.startRule]}function I(t){return k!==t&&(k>t&&(k=0,N={line:1,column:1,seenCR:!1}),function(t,e,o){var i,s;for(i=e;i<o;i++)"\n"===(s=n.charAt(i))?(t.seenCR||t.line++,t.column=1,t.seenCR=!1):"\r"===s||"\u2028"===s||"\u2029"===s?(t.line++,t.column=1,t.seenCR=!0):(t.column++,t.seenCR=!1)}(N,k,t),k=t),N}function _(t){F<T||(F>T&&(T=F,L=[]),L.push(t))}function U(e,o,i){var s=I(i),r=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,r),o,r,i,s.line,s.column)}function Z(){return D()}function D(){var t,n,e,o;if(t=F,(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):(F=t,t=c)}else F=t,t=c;return t===i&&(t=z()),t}function q(){var t,n;return t=F,M()!==i&&(n=z())!==i?t=u(n):(F=t,t=c),t===i&&(t=F,B()!==i&&(n=z())!==i?t=l(n):(F=t,t=c)),t}function z(){var t,e,o,s;return t=F,(e=V())!==i&&(e=f(e)),(t=e)===i&&(t=F,40===n.charCodeAt(F)?(e=h,F++):(e=i,0===E&&_(p)),e!==i&&(o=D())!==i?(41===n.charCodeAt(F)?(s=d,F++):(s=i,0===E&&_(g)),s!==i?t=e=v(o):(F=t,t=c)):(F=t,t=c)),t}function V(){var t,e,o;return E++,t=F,e=F,(o=J())!==i&&(o=n.substring(e,F)),(e=o)!==i&&(e=C(e)),E--,(t=e)===i&&(e=i,0===E&&_(y)),t}function J(){var t,e,o,s,r;if(t=F,(e=$())!==i)if(m.test(n.charAt(F))?(o=n.charAt(F),F++):(o=i,0===E&&_(w)),o!==i){for(s=[],S.test(n.charAt(F))?(r=n.charAt(F),F++):(r=i,0===E&&_(A));r!==i;)s.push(r),S.test(n.charAt(F))?(r=n.charAt(F),F++):(r=i,0===E&&_(A));s!==i&&(r=$())!==i?t=e=[e,o,s,r]:(F=t,t=c)}else F=t,t=c;else F=t,t=c;return t}function M(){var t,e,o,s;return t=F,(e=$())!==i?(38===n.charCodeAt(F)?(o=O,F++):(o=i,0===E&&_(P)),o!==i&&(s=$())!==i?t=e=[e,o,s]:(F=t,t=c)):(F=t,t=c),t}function B(){var t,e,o,s;return t=F,(e=$())!==i?(124===n.charCodeAt(F)?(o=x,F++):(o=i,0===E&&_(b)),o!==i&&(s=$())!==i?t=e=[e,o,s]:(F=t,t=c)):(F=t,t=c),t}function $(){var t,e;for(t=[],R.test(n.charAt(F))?(e=n.charAt(F),F++):(e=i,0===E&&_(j));e!==i;)t.push(e),R.test(n.charAt(F))?(e=n.charAt(F),F++):(e=i,0===E&&_(j));return t}if((e=r())!==i&&F===n.length)return e;throw e!==i&&F<n.length&&_({type:"end",description:"end of input"}),U(null,L,T)}}}(),l=o.create((function(t){var n="",e="",o={},i="",s=this,r={},c={},l={},f=function(t){var n;s.slots.indexOf(t)<0&&s.slot(t,(n=t,function(){s.setToken(n)}))},h=function(t){var n;if(Object.keys(c).forEach((t=>c[t]=!1)),o.hasOwnProperty(t))for(n in c={},o[t])o[t].hasOwnProperty(n)&&(l[n]=a.build(r[t][n],c));i=t,s.emit("requestSheet",i),i===e&&s.emit("requestTermination")};this.setInitialState=function(t){i=n=t},this.setFinalState=function(t){e=t},this.addTransition=function(t,n,e){var i,s=/([A-Za-z_]\w*)/g;try{var c;if("string"==typeof(c=u.parse(n)))f(c);else for(;null!==(i=s.exec(n));)f(i[0]);r[t]=r[t]||{},r[t][n]=c,void 0===o[t]&&(o[t]={}),o[t][n]=e}catch(t){}},this.setToken=function(t){c.hasOwnProperty(t)&&(c[t]=!0);for(const[t,n]of Object.entries(l))n.eval()&&(l={},h(o[i][t]))},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(){h(n)},void 0!==t&&(n=t.initial,e=t.final,this.setTransitions(t.transitions),i="")}),["setToken"],["requestSheet","requestTermination"]);let f=function(t){let n={},e={},o={},i=[],s=this,r=!1;o.StateMachine=l,void 0!==t&&(i=t.libraries,Object.assign(n,t.components),Object.assign(e,t.constants));var c=async function(t){return w()?new Promise((function(n,e){var o=require(t);void 0!==o?n(o):e("[ARCS] File not found")})):(await fetch(t)).json()};this.loadLibrary=function(t,n){var e=t,o=t;return f.currentContext=s,"string"!=typeof t&&(o=t.name,e=t.url),i.indexOf(o)<0&&i.push(o),import(e).then((function(t){for(p in t.default)t.default.hasOwnProperty(p)&&f.currentContext.setFactory(p,t.default[p]);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.addFactories=function(t){for(p in r=!0,t)t.hasOwnProperty(p)&&(o[p]=t[p])},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 s;n[t]={},n[t].type=e,n[t].value=i;var r=o[e];void 0!==r&&(s=new r(i)),n[t].instance=s},this.removeComponent=function(t){delete n[t]},this.getFactory=function(t){return o[t]},this.getFactoryList=function(){return Object.keys(o)},this.instanciate=async function(){try{r||await function(){var t;f.currentContext=s;var n=[];for(t=0;t<i.length;t++)n.push(s.loadLibrary(i[t]));return Promise.all(n)}(),await async function(){var t,s=[];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 r=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 r(n[t].value)),void 0!==n[t].url&&(console.log("loading data file",n[t].url),s.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,r)))),void 0!==n[t].ref&&void 0!==e[n[t].ref]&&(n[t].instance=new r(e[n[t].ref]))):n[t].instance=new r}catch(n){console.error("[ARCS] Component of type ",t," not instanciated.",n)}}return Promise.all(s)}()}catch(t){console.error("[ARCS] Trouble instanciating context",t)}};var a=function(t,n){return Object.create(n,t)};this.chain=function(t,i,s){return[a(t,n),a(i,e),a(s,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 h=f;let d=function(t,n,e){this.getDestination=function(){return t},this.getSlot=function(){return n},this.getValue=function(){return e},this.invoke=function(){let o=t[n];void 0!==o?o.apply(t,e):console.error("Undefined slot %s of component %s",n,t)}};d.cast=function(t,n){if(void 0!==t.call){let n=t.call.split(".");t.destination=n[0],t.slot=n[1]}let e=n.getComponent(t.destination);if(void 0===e&&console.error("[ARCS] Destination ",t.destination," is undefined"),void 0!==t.value)return new d(e,t.slot,t.value);if(void 0!==t.ref)return new d(e,t.slot,n.getConstant(t.ref));if(void 0!==t.storage){let n=null;return"undefined"!=typeof localStorage&&null===localStorage.getItem(`ARCS.${storage.key}`)&&void 0!==t.storage.default&&(n=t.storage.default),new d(e,t.slot,n)}return new d(e,t.slot)},d.PRE_CONNECTION=0,d.POST_CONNECTION=1,d.CLEAN_UP=2;const g=d;let v=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}};v.cast=function(t,n){if(void 0!==t.from){let n=t.from.split(".");t.source=n[0],t.signal=n[1]}if(void 0!==t.to){let n=t.to.split(".");t.destination=n[0],t.slot=n[1]}return new v(n.getComponent(t.source),t.signal,n.getComponent(t.destination),t.slot)};const y=v,C=function(t){var n,e,o,i,s,r=new h,c=[],a=[],u=[],l=[],f=0,p=0,d=0,v=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<l.length;t++)l[t].connect()},s=function(){var t;for(t=0;t<l.length;t++)l[t].disconnect()},this.setContext=function(t){r=t},this.activate=function(){r.instanciate().then((function(){n(),i(),e()}))},this.deactivate=function(){s(),o()},this.addPreConnection=function(t){var n=g.cast(t,r);return n.id=f++,c.push(n),n.id},this.addPostConnection=function(t){var n=g.cast(t,r);return n.id=p++,a.push(n),n.id},this.addCleanup=function(t){var n=g.cast(t,r);return n.id=d++,u.push(n),n.id},this.addConnection=function(t){var n=y.cast(t,r);return n.id=v++,l.push(n),n.id};let C=function(t,n){let e=n.length;for(;e--&&n[e].id!==t;);e>=0?n.splice(e,1):console.warn("Could not remove data with id",t)};this.removePreConnection=function(t){C(t,c)},this.removePostConnection=function(t){C(t,a)},this.removeCleanup=function(t){C(t,u)};var m=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){m(t,n,c)},this.changePostConnection=function(t,n){m(t,n,a)},this.changeCleanup=function(t,n){m(t,n,u)},this.removeConnection=function(t){C(t,l)};let w=function(t,n,e){let o,i=e.length,s=e.length;for(;i--&&e[i].id!==t;);for(;s--&&e[s].id!==n;);i>=0&&s>=0&&(o=e[i],e[i]=e[s],e[s]=o,e[i].id=t,e[s].id=n)};this.swapConnections=function(t,n){w(t,n,l)},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")&&(r=new h(n.context)).setParent(t),r.instanciate().then((function(){!function(t){let n=0,e=g.cast,o=y.cast;if(void 0!==t.preconnections)for(n=0;n<t.preconnections.length;n++)c.push(e(t.preconnections[n],r));if(void 0!==t.postconnections)for(n=0;n<t.postconnections.length;n++)a.push(e(t.postconnections[n],r));if(void 0!==t.cleanups)for(n=0;n<t.cleanups.length;n++)u.push(e(t.cleanups[n],r));if(void 0!==t.connections)for(n=0;n<t.connections.length;n++)l.push(o(t.connections[n],r))}(n)}))};let S=function(t){return{destination:r.getComponentName(t.getDestination()),slot:t.getSlot(),value:t.getValue()}};this.toJSON=function(){let t,n=[],e=[],o=[],i=[];for(t=0;t<l.length;t++)o.push((s=l[t],{source:r.getComponentName(s.getSource()),signal:s.getSignal(),destination:r.getComponentName(s.getDestination()),slot:s.getSlot()}));var s;for(t=0;t<c.length;t++)n.push(S(c[t]));for(t=0;t<a.length;t++)e.push(S(a[t]));for(t=0;t<u.length;t++)i.push(S(u[t]));return{preconnections:n,postconnections:e,connections:o,cleanups:i}},r.setParent(t)};let m=function(){var t=new h,n={},e={},i=[],s=this,r="";this.export=function(){return{context:t,controller:t.getComponentName(e),sheets:n}},this.getContext=function(){return t},this.getSheetList=function(){return Object.keys(n)},this.getSheet=function(t){return n[t]},this.addSheet=function(e,o){n[e]=o,o.setContext(t)},this.removeSheet=function(t){delete n[t]},this.launch=function(){var i,r,c;if(console.log("[ARCS] Starting application..."),r=t.getComponent(e),void 0!==(e=r)){for(c=Object.keys(n),i=0;i<c.length;i++)(r=new C(t)).import(n[c[i]],t),n[c[i]]=r;o.connect(e,"requestSheet",s,"setSheet"),o.connect(e,"requestTermination",s,"finish"),e.start()}else console.error("[ARCS] undefined controller")},this.setController=function(n){e=t.getComponent(n)},this.setSheet=function(t){n.hasOwnProperty(t)?(r&&n[r].deactivate(),n[r=t].activate()):console.warn("[ARCS] Tried to activate hollow sheet named: "+t)},this.finish=function(){r&&n[r].deactivate()},this.import=function(o){t=new h(o.context),n=o.sheets,void 0===(e=o.controller)&&console.error("[ARCS] Undefined controller. Cannot start application.")},this.setFactory=function(t,n){factories[t]=n},this.setDependency=function(t){i[t]={}},this.start=async function(){console.log("[ARCS] Instanciating components..."),await t.instanciate(),this.launch()}};m.setDependency=function(t,n){t.setDependency(n)},o.create(m),m.slot("setSheet"),m.slot("finish");const w={Component:o,isInNode:function(){return"undefined"!=typeof process&&-1!==process.release.name.search(/node|io.js/)},StateMachine:l,Context:h,Invocation:g,Connection:y,Sheet:C,Application:m};var S=n.Z;export{S as default};
...\ No newline at end of file ...\ No newline at end of file
2 +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:()=>S});class e{constructor(t,n){this.slots=[],this.signals={},void 0!==t&&this.slot(t),void 0!==n&&this.signal(n)}slotList(){return this.slots}signalList(){return Object.keys(this.signals)}emit(t){let 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)}slot(t,n){let e=this;t instanceof Array?t.forEach((t=>{e.slots.includes(t)||e.slot(t)})):(this.slots.includes(t)||this.slots.push(t),void 0!==n&&(this[t]=n))}signal(t){let n=this;t instanceof Array?t.forEach((t=>{n.signals[t]=[]})):this.signals[t]=[]}static create(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 this.slots},t.prototype.signalList=function(){return Object.keys(this.signals)},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.prototype.slot=function(n,e){this.hasOwnProperty("slots")||(this.slots=t.prototype.slots.map((t=>t))),this.slots.includes(n)||this.slots.push(n),this[n]=e},t.prototype.signal=function(n){this.hasOwnProperty("signals")||(this.signals={},Object.assign(this.signals,t.prototype.signals)),this.signals[n]=[]},t.slot=function(n,e){var o;if(n instanceof Array)for(o=0;o<n.length;o++)t.prototype.slots.includes(n[o])||t.prototype.slots.push(n[o]);else t.prototype.slots.includes(n)||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]]=[];else t.prototype.signals[n]=[]},void 0!==n&&t.slot(n),void 0!==e&&t.signal(e),t)}static check(t){return void 0!==t.prototype&&void 0!==t.prototype.signals&&void 0!==t.prototype.slots}static connect(t,n,o,i){var s,r;if(void 0===t.signals)throw e.SourceIsNotComponent;if(void 0===t.signals[n]){let t=Object.assign({},e.UndefinedSignal);throw t.message=t.message+': "'+n+'"',t}if(void 0===o[i]){let t=Object.assign({},e.UndefinedSlot);throw t.message=t.message+': "'+i+'"',t}if(!t.hasOwnProperty("signals"))for(r in s=t.signals,t.signals={},s)t.signals[r]=[];t.signals[n].push({obj:o,func:o[i]})}static disconnect(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--)}static invoke(t,n,o){if(void 0===t[n])throw e.UndefinedSlot;t[n].apply(t,o)}static config(t,n){"function"==typeof t.config&&t.config(n)}}e.SourceIsNotComponent={message:"Source is not a component"},e.UndefinedSignal={message:"Signal is not defined"},e.UndefinedSlot={message:"Slot is not defined"};const o=e,i=function(t,n){this.eval=function(){return t[n]}},s=function(t,n,e){this.eval=function(){return n.eval(t)||e.eval(t)}},r=function(t,n,e){this.eval=function(t){return n.eval(t)&&e.eval(t)}};let a={build:function(t,n){var e,o,c,l;if("string"==typeof t)return n[t]=n[t]??!1,new i(n,t);for(e=a.build(t[0],n),l=1;l<t.length;l++)t[l].hasOwnProperty("and")?(c=a.build(t[l].and,n),o=new r(n,e,c)):t[l].hasOwnProperty("or")?(c=a.build(t[l].or,n),o=new s(n,e,c)):console.warn("[ARCS] Illegal tree"),e=o;return e}};const c=a,l=function(){function t(t,n,e,o,i,s){this.message=t,this.expected=n,this.found=e,this.offset=o,this.line=i,this.column=s,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,i,s,r,a,c=arguments.length>1?arguments[1]:{},l={},u={start:q},f=q,h=l,p=function(t,n){return[t].concat(n)},d=function(t){return{and:t}},g=function(t){return{or:t}},v=function(t){return t},y="(",m={type:"literal",value:"(",description:'"("'},C=")",w={type:"literal",value:")",description:'")"'},S=function(t){return[t]},b={type:"other",description:"id"},A=function(t){return t.trim()},O=/^[_a-zA-Z]/,x={type:"class",value:"[_a-zA-Z]",description:"[_a-zA-Z]"},P=/^[_a-zA-Z0-9]/,T={type:"class",value:"[_a-zA-Z0-9]",description:"[_a-zA-Z0-9]"},k="&",R={type:"literal",value:"&",description:'"&"'},j="|",N={type:"literal",value:"|",description:'"|"'},F=/^[ \r\n\t]/,E={type:"class",value:"[ \\r\\n\\t]",description:"[ \\r\\n\\t]"},_=0,L=0,I={line:1,column:1,seenCR:!1},U=0,Z=[],z=0;if("startRule"in c){if(!(c.startRule in u))throw new Error("Can't start parsing from rule \""+c.startRule+'".');f=u[c.startRule]}function D(t){_<U||(_>U&&(U=_,Z=[]),Z.push(t))}function q(){return J()}function J(){var t,n,e,o;if(t=_,(n=W())!==l){if(e=[],(o=V())!==l)for(;o!==l;)e.push(o),o=V();else e=h;e!==l?t=n=p(n,e):(_=t,t=h)}else _=t,t=h;return t===l&&(t=W()),t}function V(){var t,e,o;return t=_,e=function(){var t,e,o,i;return t=_,(e=M())!==l?(38===n.charCodeAt(_)?(o=k,_++):(o=l,0===z&&D(R)),o!==l&&(i=M())!==l?t=e=[e,o,i]:(_=t,t=h)):(_=t,t=h),t}(),e!==l&&(o=W())!==l?t=e=d(o):(_=t,t=h),t===l&&(t=_,e=function(){var t,e,o,i;return t=_,(e=M())!==l?(124===n.charCodeAt(_)?(o=j,_++):(o=l,0===z&&D(N)),o!==l&&(i=M())!==l?t=e=[e,o,i]:(_=t,t=h)):(_=t,t=h),t}(),e!==l&&(o=W())!==l?t=e=g(o):(_=t,t=h)),t}function W(){var t,e,o,i;return t=_,e=function(){var t,e,o;return z++,t=_,e=_,o=function(){var t,e,o,i,s;if(t=_,(e=M())!==l)if(O.test(n.charAt(_))?(o=n.charAt(_),_++):(o=l,0===z&&D(x)),o!==l){for(i=[],P.test(n.charAt(_))?(s=n.charAt(_),_++):(s=l,0===z&&D(T));s!==l;)i.push(s),P.test(n.charAt(_))?(s=n.charAt(_),_++):(s=l,0===z&&D(T));i!==l&&(s=M())!==l?t=e=[e,o,i,s]:(_=t,t=h)}else _=t,t=h;else _=t,t=h;return t}(),o!==l&&(o=n.substring(e,_)),(e=o)!==l&&(e=A(e)),z--,(t=e)===l&&(e=l,0===z&&D(b)),t}(),e!==l&&(e=v(e)),(t=e)===l&&(t=_,40===n.charCodeAt(_)?(e=y,_++):(e=l,0===z&&D(m)),e!==l&&(o=J())!==l?(41===n.charCodeAt(_)?(i=C,_++):(i=l,0===z&&D(w)),i!==l?t=e=S(o):(_=t,t=h)):(_=t,t=h)),t}function M(){var t,e;for(t=[],F.test(n.charAt(_))?(e=n.charAt(_),_++):(e=l,0===z&&D(E));e!==l;)t.push(e),F.test(n.charAt(_))?(e=n.charAt(_),_++):(e=l,0===z&&D(E));return t}if((e=f())!==l&&_===n.length)return e;throw e!==l&&_<n.length&&D({type:"end",description:"end of input"}),o=null,i=Z,r=function(t){return L!==t&&(L>t&&(L=0,I={line:1,column:1,seenCR:!1}),function(t,e,o){var i,s;for(i=e;i<o;i++)"\n"===(s=n.charAt(i))?(t.seenCR||t.line++,t.column=1,t.seenCR=!1):"\r"===s||"\u2028"===s||"\u2029"===s?(t.line++,t.column=1,t.seenCR=!0):(t.column++,t.seenCR=!1)}(I,L,t),L=t),I}(s=U),a=s<n.length?n.charAt(s):null,null!==i&&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++}(i),new t(null!==o?o: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."}(i,a),i,a,s,r.line,r.column)}}}(),u=o.create((function(t){var n="",e="",o={},i="",s=this,r={},a={},u={},f=function(t){var n;s.slots.indexOf(t)<0&&s.slot(t,(n=t,function(){s.setToken(n)}))},h=function(t){var n;if(Object.keys(a).forEach((t=>a[t]=!1)),o.hasOwnProperty(t))for(n in a={},o[t])o[t].hasOwnProperty(n)&&(u[n]=c.build(r[t][n],a));i=t,s.emit("requestSheet",i),i===e&&s.emit("requestTermination")};this.setInitialState=function(t){i=n=t},this.setFinalState=function(t){e=t},this.addTransition=function(t,n,e){var i,s=/([A-Za-z_]\w*)/g;try{var a;if("string"==typeof(a=l.parse(n)))f(a);else for(;null!==(i=s.exec(n));)f(i[0]);r[t]=r[t]||{},r[t][n]=a,void 0===o[t]&&(o[t]={}),o[t][n]=e}catch(t){}},this.setToken=function(t){a.hasOwnProperty(t)&&(a[t]=!0);for(const[t,n]of Object.entries(u))n.eval()&&(u={},h(o[i][t]))},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(){h(n)},void 0!==t&&(n=t.initial,e=t.final,this.setTransitions(t.transitions),i="")}),["setToken"],["requestSheet","requestTermination"]);let f=function(t){let n={},e={},o={},i=[],s=this,r=!1;o.StateMachine=u,void 0!==t&&(i=t.libraries,Object.assign(n,t.components),Object.assign(e,t.constants));var a=async function(t){return S()?new Promise((function(n,e){var o=require(t);void 0!==o?n(o):e("[ARCS] File not found")})):(await fetch(t)).json()};this.loadLibrary=function(t,n){var e=t,o=t;return f.currentContext=s,"string"!=typeof t&&(o=t.name,e=t.url),i.indexOf(o)<0&&i.push(o),import(e).then((function(t){for(let n in t.default)t.default.hasOwnProperty(n)&&f.currentContext.setFactory(n,t.default[n]);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.addFactories=function(t){for(p in r=!0,t)t.hasOwnProperty(p)&&(o[p]=t[p])},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 s;n[t]={},n[t].type=e,n[t].value=i;var r=o[e];void 0!==r&&(s=new r(i)),n[t].instance=s},this.removeComponent=function(t){delete n[t]},this.getFactory=function(t){return o[t]},this.getFactoryList=function(){return Object.keys(o)},this.instanciate=async function(){try{r||await function(){var t;f.currentContext=s;var n=[];for(t=0;t<i.length;t++)n.push(s.loadLibrary(i[t]));return Promise.all(n)}(),await async function(){var t,s=[];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 r=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 r(n[t].value)),void 0!==n[t].url&&(console.log("loading data file",n[t].url),s.push(a(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,r)))),void 0!==n[t].ref&&void 0!==e[n[t].ref]&&(n[t].instance=new r(e[n[t].ref]))):n[t].instance=new r}catch(n){console.error("[ARCS] Component of type ",t," not instanciated.",n)}}return Promise.all(s)}()}catch(t){console.error("[ARCS] Trouble instanciating context",t)}};var c=function(t,n){return Object.create(n,t)};this.chain=function(t,i,s){return[c(t,n),c(i,e),c(s,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 h=f;let d=function(t,n,e){this.getDestination=function(){return t},this.getSlot=function(){return n},this.getValue=function(){return e},this.invoke=function(){let o=t[n];void 0!==o?o.apply(t,e):console.error("Undefined slot %s of component %s",n,t)}};d.cast=function(t,n){if(void 0!==t.call){let n=t.call.split(".");t.destination=n[0],t.slot=n[1]}let e=n.getComponent(t.destination);if(void 0===e&&console.error("[ARCS] Destination ",t.destination," is undefined"),void 0!==t.value)return new d(e,t.slot,t.value);if(void 0!==t.ref)return new d(e,t.slot,n.getConstant(t.ref));if(void 0!==t.storage){let n=null;return"undefined"!=typeof localStorage&&null===localStorage.getItem(`ARCS.${storage.key}`)&&void 0!==t.storage.default&&(n=t.storage.default),new d(e,t.slot,n)}return new d(e,t.slot)},d.PRE_CONNECTION=0,d.POST_CONNECTION=1,d.CLEAN_UP=2;const g=d;let v=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}};v.cast=function(t,n){if(void 0!==t.from){let n=t.from.split(".");t.source=n[0],t.signal=n[1]}if(void 0!==t.to){let n=t.to.split(".");t.destination=n[0],t.slot=n[1]}return new v(n.getComponent(t.source),t.signal,n.getComponent(t.destination),t.slot)};const y=v,m=function(t){var n,e,o,i,s,r=new h,a=[],c=[],l=[],u=[],f=0,p=0,d=0,v=0;n=function(){var t;for(t=0;t<a.length;t++)a[t].invoke()},e=function(){var t;for(t=0;t<c.length;t++)c[t].invoke()},o=function(){var t;for(t=0;t<l.length;t++)l[t].invoke()},i=function(){var t;for(t=0;t<u.length;t++)u[t].connect()},s=function(){var t;for(t=0;t<u.length;t++)u[t].disconnect()},this.setContext=function(t){r=t},this.activate=function(){r.instanciate().then((function(){n(),i(),e()}))},this.deactivate=function(){s(),o()},this.addPreConnection=function(t){var n=g.cast(t,r);return n.id=f++,a.push(n),n.id},this.addPostConnection=function(t){var n=g.cast(t,r);return n.id=p++,c.push(n),n.id},this.addCleanup=function(t){var n=g.cast(t,r);return n.id=d++,l.push(n),n.id},this.addConnection=function(t){var n=y.cast(t,r);return n.id=v++,u.push(n),n.id};let m=function(t,n){let e=n.length;for(;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,a)},this.removePostConnection=function(t){m(t,c)},this.removeCleanup=function(t){m(t,l)};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,a)},this.changePostConnection=function(t,n){C(t,n,c)},this.changeCleanup=function(t,n){C(t,n,l)},this.removeConnection=function(t){m(t,u)};let w=function(t,n,e){let o,i=e.length,s=e.length;for(;i--&&e[i].id!==t;);for(;s--&&e[s].id!==n;);i>=0&&s>=0&&(o=e[i],e[i]=e[s],e[s]=o,e[i].id=t,e[s].id=n)};this.swapConnections=function(t,n){w(t,n,u)},this.swapCleanups=function(t,n){w(t,n,l)},this.swapPreConnections=function(t,n){w(t,n,a)},this.swapPostConnections=function(t,n){w(t,n,c)},this.import=function(n){n.hasOwnProperty("context")&&(r=new h(n.context)).setParent(t),r.instanciate().then((function(){!function(t){let n=0,e=g.cast,o=y.cast;if(void 0!==t.preconnections)for(n=0;n<t.preconnections.length;n++)a.push(e(t.preconnections[n],r));if(void 0!==t.postconnections)for(n=0;n<t.postconnections.length;n++)c.push(e(t.postconnections[n],r));if(void 0!==t.cleanups)for(n=0;n<t.cleanups.length;n++)l.push(e(t.cleanups[n],r));if(void 0!==t.connections)for(n=0;n<t.connections.length;n++)u.push(o(t.connections[n],r))}(n)}))};let S=function(t){return{destination:r.getComponentName(t.getDestination()),slot:t.getSlot(),value:t.getValue()}};this.toJSON=function(){let t,n=[],e=[],o=[],i=[];for(t=0;t<u.length;t++)o.push((s=u[t],{source:r.getComponentName(s.getSource()),signal:s.getSignal(),destination:r.getComponentName(s.getDestination()),slot:s.getSlot()}));var s;for(t=0;t<a.length;t++)n.push(S(a[t]));for(t=0;t<c.length;t++)e.push(S(c[t]));for(t=0;t<l.length;t++)i.push(S(l[t]));return{preconnections:n,postconnections:e,connections:o,cleanups:i}},r.setParent(t)};let C=function(){var t=new h,n={},e={},i=[],s=this,r="";this.export=function(){return{context:t,controller:t.getComponentName(e),sheets:n}},this.getContext=function(){return t},this.getSheetList=function(){return Object.keys(n)},this.getSheet=function(t){return n[t]},this.addSheet=function(e,o){n[e]=o,o.setContext(t)},this.removeSheet=function(t){delete n[t]},this.launch=function(){var i,r,a;if(console.log("[ARCS] Starting application..."),r=t.getComponent(e),void 0!==(e=r)){for(a=Object.keys(n),i=0;i<a.length;i++)(r=new m(t)).import(n[a[i]],t),n[a[i]]=r;o.connect(e,"requestSheet",s,"setSheet"),o.connect(e,"requestTermination",s,"finish"),e.start()}else console.error("[ARCS] undefined controller")},this.setController=function(n){e=t.getComponent(n)},this.setSheet=function(t){n.hasOwnProperty(t)?(r&&n[r].deactivate(),n[r=t].activate()):console.warn("[ARCS] Tried to activate hollow sheet named: "+t)},this.finish=function(){r&&n[r].deactivate()},this.import=function(o){t=new h(o.context),n=o.sheets,void 0===(e=o.controller)&&console.error("[ARCS] Undefined controller. Cannot start application.")},this.setFactory=function(t,n){factories[t]=n},this.setDependency=function(t){i[t]={}},this.start=async function(){console.log("[ARCS] Instanciating components..."),await t.instanciate(),this.launch()}};C.setDependency=function(t,n){t.setDependency(n)},o.create(C),C.slot("setSheet"),C.slot("finish");const w=C,S={Component:o,isInNode:function(){return"undefined"!=typeof process&&-1!==process.release.name.search(/node|io.js/)},StateMachine:u,Context:h,Invocation:g,Connection:y,Sheet:m,RemoteConsole:class{#t=[];#n;#e;_log=globalThis.console.log;_info=globalThis.console.info;_warn=globalThis.console.warn;_error=globalThis.console.error;constructor(t){let n=this;console.error=this.error,console.warn=this.warn,console.info=this.info,console.log=this.log,console.tainted=!0,globalThis.window&&(globalThis.window.onerror=this.runtimeException),globalThis.WebSocket&&globalThis.navigator&&(this.#n=new globalThis.WebSocket(t),this.#e=globalThis.navigator.userAgent.match(/firefox|fxios/i)?2:3,this.#n.onopen=function(){n.#o()})}#i(){return(new Error).stack.split("\n")[this.#e]}#s(t){this.#n&&(this.#n.readyState===WebSocket.OPEN?this.#n.send(t):this.#t.push(t))}#o(){this.#n&&this.#n.readyState===WebSocket.OPEN&&(this.#t.forEach((t=>this.#n.send(t))),this.#t=[])}#r(t){let n=this;return function(){let e={type:t,args:Array.from(arguments),context:n.#i()};n[`_${t}`].apply(globalThis.console,e.args);let o="";try{o=JSON.stringify(e)}catch(t){e.args=["Argument(s) not serializable"],o=JSON.stringify(e)}n.#s(o)}}#a(t,n,e,o,i){return!!this.#n&&(this.#n.send(JSON.stringify({type:"exception",args:[{message:t,url:n,line:e,column:o}]})),!1)}log=this.#r("log");info=this.#r("info");warn=this.#r("warn");error=this.#r("error")},Application:w,__lib__:()=>{}};var b=n.Z;export{b as default};
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -18,7 +18,12 @@ let baseUrl, appDescription, requireMarkup, xhr; ...@@ -18,7 +18,12 @@ let baseUrl, appDescription, requireMarkup, xhr;
18 requireMarkup = document.querySelector('[data-arcsapp]'); 18 requireMarkup = document.querySelector('[data-arcsapp]');
19 if (requireMarkup !== undefined) { 19 if (requireMarkup !== undefined) {
20 baseUrl = requireMarkup.dataset.baseUrl ; 20 baseUrl = requireMarkup.dataset.baseUrl ;
21 - appDescription = requireMarkup.dataset.arcsapp || "arcsapp.json"; 21 + appDescription = requireMarkup.dataset.arcsapp || "arcsapp.json";
22 +
23 + if( "remoteConsole" in requireMarkup.dataset ) {
24 + let address = requireMarkup.dataset.remoteConsole || "ws://localhost:8088";
25 + let remoteConsole = new ARCS.RemoteConsole(address);
26 + }
22 } 27 }
23 28
24 29
......
...@@ -37,8 +37,9 @@ ...@@ -37,8 +37,9 @@
37 "license": "GPL-3.0-or-later", 37 "license": "GPL-3.0-or-later",
38 "devDependencies": { 38 "devDependencies": {
39 "chai": "4.3.4", 39 "chai": "4.3.4",
40 + "chalk": "^5.2.0",
41 + "ws": "^8.13.0",
40 "copy-webpack-plugin": "^9.0.1", 42 "copy-webpack-plugin": "^9.0.1",
41 - "eslint": "^8.7.0",
42 "eslint-webpack-plugin": "^3.0.1", 43 "eslint-webpack-plugin": "^3.0.1",
43 "jsdoc-webpack-plugin": "^0.3.0", 44 "jsdoc-webpack-plugin": "^0.3.0",
44 "mocha": "^9.1.4", 45 "mocha": "^9.1.4",
......
...@@ -8,6 +8,7 @@ import Invocation from './invocation.js'; ...@@ -8,6 +8,7 @@ import Invocation from './invocation.js';
8 import Connection from './connection.js'; 8 import Connection from './connection.js';
9 import Sheet from './sheet.js'; 9 import Sheet from './sheet.js';
10 import Application from './application.js'; 10 import Application from './application.js';
11 +import RemoteConsole from './remoteconsole.js';
11 12
12 let ARCS = { 13 let ARCS = {
13 Component: Component, 14 Component: Component,
...@@ -17,6 +18,7 @@ let ARCS = { ...@@ -17,6 +18,7 @@ let ARCS = {
17 Invocation: Invocation, 18 Invocation: Invocation,
18 Connection: Connection, 19 Connection: Connection,
19 Sheet: Sheet, 20 Sheet: Sheet,
21 + RemoteConsole: RemoteConsole,
20 Application: Application, 22 Application: Application,
21 __lib__: ()=>{} 23 __lib__: ()=>{}
22 }; 24 };
......
...@@ -18,7 +18,12 @@ let baseUrl, appDescription, requireMarkup, xhr; ...@@ -18,7 +18,12 @@ let baseUrl, appDescription, requireMarkup, xhr;
18 requireMarkup = document.querySelector('[data-arcsapp]'); 18 requireMarkup = document.querySelector('[data-arcsapp]');
19 if (requireMarkup !== undefined) { 19 if (requireMarkup !== undefined) {
20 baseUrl = requireMarkup.dataset.baseUrl ; 20 baseUrl = requireMarkup.dataset.baseUrl ;
21 - appDescription = requireMarkup.dataset.arcsapp || "arcsapp.json"; 21 + appDescription = requireMarkup.dataset.arcsapp || "arcsapp.json";
22 +
23 + if( "remoteConsole" in requireMarkup.dataset ) {
24 + let address = requireMarkup.dataset.remoteConsole || "ws://localhost:8088";
25 + let remoteConsole = new ARCS.RemoteConsole(address);
26 + }
22 } 27 }
23 28
24 29
......
1 -
2 -class ARCSRemoteConsole {
3 - #stack= [];
4 - #server;
5 - #idxSource;
6 -
7 - constructor(address) {
8 - this.#server = new globalThis.WebSocket(address);
9 - this.#idxSource = (globalThis.navigator.userAgent.match(/firefox|fxios/i))?2:3;
10 - let self = this;
11 -
12 - this.#server.onopen = function() {
13 - self.flush();
14 - }
15 - }
16 -
17 - #currentPlace() {
18 - let err = new Error();
19 - let lst = err.stack.split("\n");
20 - return lst[this.#idxSource];
21 - }
22 -
23 - #send(data) {
24 - if (server.readyState === WebSocket.OPEN ) {
25 - server.send(data);
26 - } else {
27 - this.#stack.push(data);
28 - }
29 - }
30 -
31 - #flush () {
32 - if (server.readyState !== WebSocket.OPEN)
33 - return ;
34 - this.#stack.forEach(elt => server.send(elt));
35 - this.#stack = [];
36 - }
37 -
38 - #notify(type) {
39 - let self = this;
40 - return function() {
41 - let obj = { type, args: Array.from(arguments), context: self.#currentPlace() };
42 -
43 - let serializedObject = "";
44 -
45 - try {
46 - serializedObject = JSON.stringify(obj);
47 - } catch(e) {
48 - obj.args= [ 'Argument(s) not serializable' ];
49 - serializedObject = JSON.stringify(obj);
50 - }
51 - self.#send(serializedObject);
52 - };
53 - }
54 -
55 - #runtimeException (msg, url, line, column,err) {
56 - server.send(
57 - JSON.stringify(
58 - {type: "exception", args: [{ message: msg, url: url, line: line, column: column }] }
59 - )
60 - );
61 - return false;
62 - }
63 -
64 - log = this.notify('log');
65 - info = this.notify('info');
66 - warn = this.notify('warn');
67 - error = this.notify('error');
68 -
69 - static init(address) {
70 - let _address = address || 'ws://localhost:8088';
71 - const remoteConsole = new ARCSRemoteConsole(address);
72 -
73 - const console = globalThis.console;
74 - console.error = remoteConsole.error;
75 - console.warn = remoteConsole.warn;
76 - console.info = remoteConsole.info;
77 - console.log = remoteConsole.log;
78 - console.tainted = true;
79 - const window = globalThis.window;
80 - window.onerror = remoteConsole.runtimeException;
81 - }
82 -
83 -}
84 -
...@@ -25,7 +25,7 @@ class RemoteConsole { ...@@ -25,7 +25,7 @@ class RemoteConsole {
25 this.#server = new globalThis.WebSocket(address); 25 this.#server = new globalThis.WebSocket(address);
26 this.#idxSource = (globalThis.navigator.userAgent.match(/firefox|fxios/i))?2:3; 26 this.#idxSource = (globalThis.navigator.userAgent.match(/firefox|fxios/i))?2:3;
27 this.#server.onopen = function() { 27 this.#server.onopen = function() {
28 - self.flush(); 28 + self.#flush();
29 } 29 }
30 } 30 }
31 } 31 }
......
1 +import WebSocket, {WebSocketServer} from 'ws';
2 +import Chalk from 'chalk';
3 +
4 +let serverConfig = {
5 + port: 8088,
6 +};
7 +
8 +
9 +if (process.argv.length > 2) {
10 + serverConfig.port = parseInt(process.argv[2]);
11 +}
12 +
13 +let wss = new WebSocketServer(serverConfig);
14 +wss.on('connection', function (ws) {
15 + ws.on('message', function (message) {
16 + let obj = JSON.parse(message);
17 + switch(obj.type) {
18 + case 'log':
19 + console.log(Chalk.green("[log]"), Chalk.white.dim(obj.context),"\n", ...obj.args);
20 + break;
21 + case 'info':
22 + console.log(Chalk.cyan("[info]"), Chalk.white.dim(obj.context),"\n", ...obj.args);
23 + break;
24 + case 'warn':
25 + console.log(Chalk.yellow("[warn]"),Chalk.white.dim(obj.context),"\n", ...obj.args);
26 + break;
27 + case 'error':
28 + console.log(Chalk.red("[error]"), Chalk.white.dim(obj.context),"\n", ...obj.args);
29 + break;
30 + }
31 + //console.log('received: %s', message);
32 + });
33 +});