@codraft/core
Advanced tools
Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.Codraft=n():e.Codraft=n()}(window,(function(){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="/dist/",t(t.s=1)}([function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.d(__webpack_exports__,"a",(function(){return CodraftRunner}));class CodraftRunner{constructor(e,n,t,r,o=!1){this.__events=e,this.__conditions=n,this.__actions=t,this.__boxes=r.boxes,this.__usedCommands=r.used_commands,this.__isDebug=o,this.__commandHashMap=CodraftRunner.CreateHashMap([...this.__events,...this.__conditions,...this.__actions])}static CreateHashMap(e){const n=new Map;return e.forEach(e=>n.set(e.id,e)),n}static ParseVariables(e,n,t){const r={};for(const o in e)r[o]=CodraftRunner.ParseVariable(e[o],n,t);return r}static ParseVariable(variable,local,global){const regexp=/{{2}\s*(.*?)\s*}{2}/gim,equation=variable.replace(regexp,(e,n)=>{let t=null;return n in local?t=local[n]:n in global&&(t=global[n]),"string"!=typeof t&&(t=JSON.stringify(t)),t});let result;try{result=eval(equation)}catch(e){result=equation}return result}static RunCommand(e,n,t){return new Promise((r,o)=>{const a=CodraftRunner.ParseVariables(n,t.local,t.global);e.fn.call(a,t,r,o)})}static RunCommandAsync(e,n,t,r,o){const a=CodraftRunner.ParseVariables(n,t.local,t.global);e.fn.call(a,t,r,o)}static FindBox(e,n){var t;return null!==(t=e.find(e=>e.id===n))&&void 0!==t?t:null}async __runCommand(e,n){var t;const{command_id:r,variables:o}=e,a=null!==(t=this.__commandHashMap.get(r))&&void 0!==t?t:null;if(null!==a)return await CodraftRunner.RunCommand(a,o,n);throw new Error(`The '${r}' command not exists.`)}__runCommandAsync(e,n,t,r){var o;const{command_id:a,variables:s}=e,i=null!==(o=this.__commandHashMap.get(a))&&void 0!==o?o:null;if(null===i)throw new Error(`The '${a}' command not exists.`);CodraftRunner.RunCommandAsync(i,s,n,t,r)}__runCommands(e,n){return new Promise(async(t,r)=>{let o=!1;for(const t of e){if(o)return;await new Promise((e,r)=>this.__runCommand(t,n).then(e).catch(r)).catch(()=>{o=!0,r()})}t()})}__recursiveBox(e,n){const t=e.next_box_ids.filter(e=>CodraftRunner.FindBox(this.__boxes,e)).map(e=>CodraftRunner.FindBox(this.__boxes,e));this.__runCommands(e.conditions,n).then(()=>this.__runCommands(e.actions,n)).then(()=>{t.forEach(e=>this.__recursiveBox(e,n))})}__attachEvent(){this.__boxes.forEach(e=>{e.events.forEach(n=>{this.__runCommandAsync(n,{event:null,local:{},global:globalThis},n=>this.__recursiveBox(e,n),e=>console.error(e))})})}init(){this.__attachEvent()}}},function(e,n,t){"use strict";t.r(n);var r=t(0);t.d(n,"Runner",(function(){return r.a}))}])})); | ||
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.Codraft=n():e.Codraft=n()}(window,(function(){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="/dist/",t(t.s=1)}([function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.d(__webpack_exports__,"a",(function(){return CodraftRunner}));class CodraftRunner{constructor(e,n,t,r,o=!1){this.__events=e,this.__conditions=n,this.__actions=t,this.__boxes=r.boxes,this.__usedCommands=r.used_commands,this.__isDebug=o,this.__commandHashMap=CodraftRunner.CreateHashMap([...this.__events,...this.__conditions,...this.__actions])}static CreateHashMap(e){const n=new Map;return e.forEach(e=>n.set(e.id,e)),n}static ParseVariables(e,n,t){const r={};for(const o in e)r[o]=CodraftRunner.ParseVariable(e[o],n,t);return r}static ParseVariable(variable,local,global){const local_regexp=/{{2}\s*(.*?)\s*}{2}/gim,global_regexp=/{{3}\s*(.*?)\s*}{3}/gim,equation=variable.replace(global_regexp,(e,n)=>{let t=e;return n in global&&(t=global[n]),"string"!=typeof t&&(t=JSON.stringify(t)),t}).replace(local_regexp,(e,n)=>{let t=null;return n in local?t=local[n]:n in global&&(t=global[n]),"string"!=typeof t&&(t=JSON.stringify(t)),t});let result;try{result=eval(equation)}catch(e){result=equation}return result}static RunCommand(e,n,t){return new Promise((r,o)=>{const a=CodraftRunner.ParseVariables(n,t.local,t.global);e.fn.call(a,t,r,o)})}static RunCommandAsync(e,n,t,r,o){const a=CodraftRunner.ParseVariables(n,t.local,t.global);e.fn.call(a,t,r,o)}static FindBox(e,n){var t;return null!==(t=e.find(e=>e.id===n))&&void 0!==t?t:null}async __runCommand(e,n){var t;const{command_id:r,variables:o}=e,a=null!==(t=this.__commandHashMap.get(r))&&void 0!==t?t:null;if(null!==a)return await CodraftRunner.RunCommand(a,o,n);throw new Error(`The '${r}' command not exists.`)}__runCommandAsync(e,n,t,r){var o;const{command_id:a,variables:i}=e,s=null!==(o=this.__commandHashMap.get(a))&&void 0!==o?o:null;if(null===s)throw new Error(`The '${a}' command not exists.`);CodraftRunner.RunCommandAsync(s,i,n,t,r)}__runCommands(e,n){return new Promise(async(t,r)=>{let o=!1;for(const t of e){if(o)return;await new Promise((e,r)=>this.__runCommand(t,n).then(e).catch(r)).catch(()=>{o=!0,r()})}t()})}__recursiveBox(e,n){const t=e.next_box_ids.filter(e=>CodraftRunner.FindBox(this.__boxes,e)).map(e=>CodraftRunner.FindBox(this.__boxes,e));this.__runCommands(e.conditions,n).then(()=>this.__runCommands(e.actions,n)).then(()=>{t.forEach(e=>this.__recursiveBox(e,n))})}__attachEvent(){this.__boxes.forEach(e=>{e.events.forEach(n=>{this.__runCommandAsync(n,{event:null,local:{},global:globalThis},n=>this.__recursiveBox(e,n),e=>console.error(e))})})}init(){this.__attachEvent()}}},function(e,n,t){"use strict";t.r(n);var r=t(0);t.d(n,"Runner",(function(){return r.a}))}])})); |
{ | ||
"name": "@codraft/core", | ||
"version": "1.0.0-alpha.4", | ||
"version": "1.0.0-alpha.5", | ||
"description": "Codraft parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/core/src/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8221
0