state-machine-cat 12.0.10 → 12.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,89 @@
1
- import Handlebars from "handlebars/dist/handlebars.runtime.js";
2
- await import("./scxml.template.js");
3
- await import("./scxml.states.template.js");
4
- Handlebars.registerPartial(
5
- "scxml.states.template.hbs",
6
- Handlebars.templates["scxml.states.template.hbs"],
7
- );
1
+ import he from "he";
2
+ const INDENT_LENGTH = 4;
3
+ function indentString(pString, pCount) {
4
+ const lRegex = /^(?!\s*$)/gm;
5
+ return pString.replace(lRegex, " ".repeat(pCount));
6
+ }
7
+ function renderTransitionAttributes(pTransition) {
8
+ let lReturnValue = "";
9
+ if (pTransition.event) {
10
+ lReturnValue += ` event="${he.escape(pTransition.event)}"`;
11
+ }
12
+ if (pTransition.cond) {
13
+ lReturnValue += ` cond="${he.escape(pTransition.cond)}"`;
14
+ }
15
+ if (pTransition.type) {
16
+ lReturnValue += ` type="${he.escape(pTransition.type)}"`;
17
+ }
18
+ lReturnValue += ` target="${he.escape(pTransition.target)}"`;
19
+ return lReturnValue;
20
+ }
21
+ function renderRegularTransition(pTransition, pDepth) {
22
+ const lReturnValue = `
23
+ <transition${renderTransitionAttributes(pTransition)}/>`;
24
+ return indentString(lReturnValue, pDepth * INDENT_LENGTH);
25
+ }
26
+ function renderActionTransition(pTransition, pDepth) {
27
+ const lReturnValue = `
28
+ <transition${renderTransitionAttributes(pTransition)}>
29
+ ${he.escape(pTransition.action)}
30
+ </transition>`;
31
+ return indentString(lReturnValue, pDepth * INDENT_LENGTH);
32
+ }
33
+ function renderTransition(pTransition, pDepth) {
34
+ if (pTransition.action) {
35
+ return renderActionTransition(pTransition, pDepth);
36
+ }
37
+ return renderRegularTransition(pTransition, pDepth);
38
+ }
39
+ function renderTransitions(pTransitions, pDepth) {
40
+ return (pTransitions ?? [])
41
+ .map((pTransition) => renderTransition(pTransition, pDepth))
42
+ .join("");
43
+ }
44
+ function renderSimpleTag(pOnExit, pTag, pDepth) {
45
+ const lReturnValue = `
46
+ <${pTag}>${he.escape(pOnExit)}</${pTag}>`;
47
+ return indentString(lReturnValue, pDepth * INDENT_LENGTH);
48
+ }
49
+ function renderOnEntries(pOnEntries, pDepth) {
50
+ return (pOnEntries ?? [])
51
+ .map((pOnEntry) => renderSimpleTag(pOnEntry, "onentry", pDepth))
52
+ .join("");
53
+ }
54
+ function renderOnExits(pOnExits, pDepth) {
55
+ return (pOnExits ?? [])
56
+ .map((pOnExit) => renderSimpleTag(pOnExit, "onexit", pDepth))
57
+ .join("");
58
+ }
59
+ function renderStateAttributes(pState) {
60
+ let lReturnValue = ` id="${he.escape(pState.id)}"`;
61
+ if (pState.initial) {
62
+ lReturnValue += ` initial="${he.escape(pState.initial)}"`;
63
+ }
64
+ if (pState.type) {
65
+ lReturnValue += ` type="${he.escape(pState.type)}"`;
66
+ }
67
+ return lReturnValue;
68
+ }
69
+ function renderState(pState, pDepth) {
70
+ let lReturnValue = `\n<${pState.kind}${renderStateAttributes(pState)}>`;
71
+ lReturnValue += renderStates(pState.states, pDepth);
72
+ lReturnValue += renderOnEntries(pState.onentries, pDepth);
73
+ lReturnValue += renderOnExits(pState.onexits, pDepth);
74
+ lReturnValue += renderTransitions(pState.transitions, pDepth);
75
+ lReturnValue += `\n</${pState.kind}>`;
76
+ return indentString(lReturnValue, pDepth * INDENT_LENGTH);
77
+ }
78
+ function renderStates(pStates, pDepth = 1) {
79
+ return (pStates ?? []).map((pState) => renderState(pState, pDepth)).join("");
80
+ }
81
+ function renderInitialAttribute(pInitialString) {
82
+ return pInitialString ? `initial="${pInitialString}" ` : "";
83
+ }
8
84
  export default function renderSCXML(pSCJSON) {
9
- return Handlebars.templates["scxml.template.hbs"](pSCJSON);
85
+ return `<?xml version="1.0" encoding="UTF-8"?>
86
+ <scxml xmlns="http://www.w3.org/2005/07/scxml" ${renderInitialAttribute(pSCJSON.initial)}version="1.0">${renderStates(pSCJSON.states)}
87
+ </scxml>
88
+ `;
10
89
  }
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "12.0.10";
1
+ export const version = "12.0.12";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-machine-cat",
3
- "version": "12.0.10",
3
+ "version": "12.0.12",
4
4
  "description": "write beautiful state charts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
@@ -50,10 +50,10 @@
50
50
  "state-machine-cat": "bin/smcat.mjs"
51
51
  },
52
52
  "dependencies": {
53
- "@hpcc-js/wasm": "2.16.2",
54
- "ajv": "8.16.0",
53
+ "@hpcc-js/wasm": "2.18.0",
54
+ "ajv": "8.17.1",
55
55
  "commander": "12.1.0",
56
- "fast-xml-parser": "4.4.0",
56
+ "fast-xml-parser": "4.4.1",
57
57
  "handlebars": "4.7.8",
58
58
  "he": "1.2.0",
59
59
  "semver": "^7.6.2",
@@ -1 +0,0 @@
1
- var Handlebars=require("handlebars/dist/handlebars.runtime"),template=Handlebars.template,templates=Handlebars.templates=Handlebars.templates||{};templates["scxml.states.template.hbs"]=template({1:function(n,l,e,t,o){var a,r,i=null!=l?l:n.nullContext||{},u=n.hooks.helperMissing,c="function",s=n.escapeExpression,p=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return" <"+s(typeof(r=null!=(r=p(e,"kind")||(null!=l?p(l,"kind"):l))?r:u)==c?r.call(i,{name:"kind",hash:{},data:o,loc:{start:{line:2,column:5},end:{line:2,column:13}}}):r)+' id="'+s(typeof(r=null!=(r=p(e,"id")||(null!=l?p(l,"id"):l))?r:u)==c?r.call(i,{name:"id",hash:{},data:o,loc:{start:{line:2,column:18},end:{line:2,column:24}}}):r)+'"'+(null!=(a=p(e,"if").call(i,null!=l?p(l,"initial"):l,{name:"if",hash:{},fn:n.program(2,o,0),inverse:n.noop,data:o,loc:{start:{line:2,column:25},end:{line:2,column:69}}}))?a:"")+(null!=(a=p(e,"if").call(i,null!=l?p(l,"type"):l,{name:"if",hash:{},fn:n.program(4,o,0),inverse:n.noop,data:o,loc:{start:{line:2,column:69},end:{line:2,column:104}}}))?a:"")+">\n"+(null!=(a=n.invokePartial(p(t,"scxml.states.template.hbs"),l,{name:"scxml.states.template.hbs",data:o,indent:" ",helpers:e,partials:t,decorators:n.decorators}))?a:"")+(null!=(a=p(e,"each").call(i,null!=l?p(l,"onentries"):l,{name:"each",hash:{},fn:n.program(6,o,0),inverse:n.noop,data:o,loc:{start:{line:4,column:4},end:{line:6,column:13}}}))?a:"")+(null!=(a=p(e,"each").call(i,null!=l?p(l,"onexits"):l,{name:"each",hash:{},fn:n.program(8,o,0),inverse:n.noop,data:o,loc:{start:{line:7,column:4},end:{line:9,column:13}}}))?a:"")+(null!=(a=p(e,"each").call(i,null!=l?p(l,"transitions"):l,{name:"each",hash:{},fn:n.program(10,o,0),inverse:n.noop,data:o,loc:{start:{line:10,column:4},end:{line:18,column:13}}}))?a:"")+" </"+s(typeof(r=null!=(r=p(e,"kind")||(null!=l?p(l,"kind"):l))?r:u)==c?r.call(i,{name:"kind",hash:{},data:o,loc:{start:{line:19,column:6},end:{line:19,column:14}}}):r)+">\n"},2:function(n,l,e,t,o){var a=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return' initial="'+n.escapeExpression("function"==typeof(e=null!=(e=a(e,"initial")||(null!=l?a(l,"initial"):l))?e:n.hooks.helperMissing)?e.call(null!=l?l:n.nullContext||{},{name:"initial",hash:{},data:o,loc:{start:{line:2,column:50},end:{line:2,column:61}}}):e)+'"'},4:function(n,l,e,t,o){var a=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return' type="'+n.escapeExpression("function"==typeof(e=null!=(e=a(e,"type")||(null!=l?a(l,"type"):l))?e:n.hooks.helperMissing)?e.call(null!=l?l:n.nullContext||{},{name:"type",hash:{},data:o,loc:{start:{line:2,column:88},end:{line:2,column:96}}}):e)+'"'},6:function(n,l,e,t,o){return" <onentry>"+n.escapeExpression(n.lambda(l,l))+"</onentry>\n"},8:function(n,l,e,t,o){return" <onexit>"+n.escapeExpression(n.lambda(l,l))+"</onexit>\n"},10:function(n,l,e,t,o){var a=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return null!=(e=a(e,"if").call(null!=l?l:n.nullContext||{},null!=l?a(l,"action"):l,{name:"if",hash:{},fn:n.program(11,o,0),inverse:n.program(18,o,0),data:o,loc:{start:{line:11,column:8},end:{line:17,column:15}}}))?e:""},11:function(n,l,e,t,o){var a,r=null!=l?l:n.nullContext||{},i=n.hooks.helperMissing,u="function",c=n.escapeExpression,s=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return" <transition "+(null!=(a=s(e,"if").call(r,null!=l?s(l,"event"):l,{name:"if",hash:{},fn:n.program(12,o,0),inverse:n.noop,data:o,loc:{start:{line:12,column:20},end:{line:12,column:58}}}))?a:"")+(null!=(a=s(e,"if").call(r,null!=l?s(l,"cond"):l,{name:"if",hash:{},fn:n.program(14,o,0),inverse:n.noop,data:o,loc:{start:{line:12,column:58},end:{line:12,column:93}}}))?a:"")+(null!=(a=s(e,"if").call(r,null!=l?s(l,"type"):l,{name:"if",hash:{},fn:n.program(16,o,0),inverse:n.noop,data:o,loc:{start:{line:12,column:93},end:{line:12,column:128}}}))?a:"")+'target="'+c(typeof(n=null!=(n=s(e,"target")||(null!=l?s(l,"target"):l))?n:i)==u?n.call(r,{name:"target",hash:{},data:o,loc:{start:{line:12,column:136},end:{line:12,column:146}}}):n)+'">\n '+c(typeof(n=null!=(n=s(e,"action")||(null!=l?s(l,"action"):l))?n:i)==u?n.call(r,{name:"action",hash:{},data:o,loc:{start:{line:13,column:12},end:{line:13,column:22}}}):n)+"\n </transition>\n"},12:function(n,l,e,t,o){var a=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return'event="'+n.escapeExpression("function"==typeof(e=null!=(e=a(e,"event")||(null!=l?a(l,"event"):l))?e:n.hooks.helperMissing)?e.call(null!=l?l:n.nullContext||{},{name:"event",hash:{},data:o,loc:{start:{line:12,column:40},end:{line:12,column:49}}}):e)+'" '},14:function(n,l,e,t,o){var a=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return'cond="'+n.escapeExpression("function"==typeof(e=null!=(e=a(e,"cond")||(null!=l?a(l,"cond"):l))?e:n.hooks.helperMissing)?e.call(null!=l?l:n.nullContext||{},{name:"cond",hash:{},data:o,loc:{start:{line:12,column:76},end:{line:12,column:84}}}):e)+'" '},16:function(n,l,e,t,o){var a=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return'type="'+n.escapeExpression("function"==typeof(e=null!=(e=a(e,"type")||(null!=l?a(l,"type"):l))?e:n.hooks.helperMissing)?e.call(null!=l?l:n.nullContext||{},{name:"type",hash:{},data:o,loc:{start:{line:12,column:111},end:{line:12,column:119}}}):e)+'" '},18:function(n,l,e,t,o){var a,r=null!=l?l:n.nullContext||{},i=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return" <transition "+(null!=(a=i(e,"if").call(r,null!=l?i(l,"event"):l,{name:"if",hash:{},fn:n.program(12,o,0),inverse:n.noop,data:o,loc:{start:{line:16,column:20},end:{line:16,column:58}}}))?a:"")+(null!=(a=i(e,"if").call(r,null!=l?i(l,"cond"):l,{name:"if",hash:{},fn:n.program(14,o,0),inverse:n.noop,data:o,loc:{start:{line:16,column:58},end:{line:16,column:93}}}))?a:"")+(null!=(a=i(e,"if").call(r,null!=l?i(l,"type"):l,{name:"if",hash:{},fn:n.program(16,o,0),inverse:n.noop,data:o,loc:{start:{line:16,column:93},end:{line:16,column:128}}}))?a:"")+'target="'+n.escapeExpression("function"==typeof(a=null!=(a=i(e,"target")||(null!=l?i(l,"target"):l))?a:n.hooks.helperMissing)?a.call(r,{name:"target",hash:{},data:o,loc:{start:{line:16,column:136},end:{line:16,column:146}}}):a)+'"/>\n'},compiler:[8,">= 4.3.0"],main:function(n,l,e,t,o){var a=n.lookupProperty||function(n,l){if(Object.prototype.hasOwnProperty.call(n,l))return n[l]};return null!=(e=a(e,"each").call(null!=l?l:n.nullContext||{},null!=l?a(l,"states"):l,{name:"each",hash:{},fn:n.program(1,o,0),inverse:n.noop,data:o,loc:{start:{line:1,column:0},end:{line:20,column:9}}}))?e:""},usePartial:!0,useData:!0});
@@ -1 +0,0 @@
1
- var Handlebars=require("handlebars/dist/handlebars.runtime"),template=Handlebars.template,templates=Handlebars.templates=Handlebars.templates||{};templates["scxml.template.hbs"]=template({1:function(e,l,t,n,a){var r=e.lookupProperty||function(e,l){if(Object.prototype.hasOwnProperty.call(e,l))return e[l]};return'initial="'+e.escapeExpression("function"==typeof(t=null!=(t=r(t,"initial")||(null!=l?r(l,"initial"):l))?t:e.hooks.helperMissing)?t.call(null!=l?l:e.nullContext||{},{name:"initial",hash:{},data:a,loc:{start:{line:2,column:71},end:{line:2,column:82}}}):t)+'" '},compiler:[8,">= 4.3.0"],main:function(e,l,t,n,a){var r,s=e.lookupProperty||function(e,l){if(Object.prototype.hasOwnProperty.call(e,l))return e[l]};return'<?xml version="1.0" encoding="UTF-8"?>\n<scxml xmlns="http://www.w3.org/2005/07/scxml" '+(null!=(r=s(t,"if").call(null!=l?l:e.nullContext||{},null!=l?s(l,"initial"):l,{name:"if",hash:{},fn:e.program(1,a,0),inverse:e.noop,data:a,loc:{start:{line:2,column:47},end:{line:2,column:91}}}))?r:"")+'version="1.0">\n'+(null!=(r=e.invokePartial(s(n,"scxml.states.template.hbs"),l,{name:"scxml.states.template.hbs",data:a,helpers:t,partials:n,decorators:e.decorators}))?r:"")+"</scxml>\n"},usePartial:!0,useData:!0});