state-machine-cat 12.0.9 → 12.0.11

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,119 @@
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
+ return lReturnValue;
19
+ }
20
+ function renderRegularTransition(pTransition, pDepth) {
21
+ const lTransitionTemplate = `
22
+ <transition{{transitionattributes}} target="{{target}}"/>`;
23
+ const lReturnValue = lTransitionTemplate
24
+ .replace("{{target}}", he.escape(pTransition.target))
25
+ .replace(
26
+ "{{transitionattributes}}",
27
+ renderTransitionAttributes(pTransition),
28
+ );
29
+ return indentString(lReturnValue, pDepth * INDENT_LENGTH);
30
+ }
31
+ function renderActionTransition(pTransition, pDepth) {
32
+ const lTransitionTemplate = `
33
+ <transition{{transitionattributes}} target="{{target}}">
34
+ {{action}}
35
+ </transition>`;
36
+ const lReturnValue = lTransitionTemplate
37
+ .replace("{{target}}", he.escape(pTransition.target))
38
+ .replace(
39
+ "{{transitionattributes}}",
40
+ renderTransitionAttributes(pTransition),
41
+ )
42
+ .replace("{{action}}", he.escape(pTransition.action));
43
+ return indentString(lReturnValue, pDepth * INDENT_LENGTH);
44
+ }
45
+ function renderTransition(pTransition, pDepth) {
46
+ if (pTransition.action) {
47
+ return renderActionTransition(pTransition, pDepth);
48
+ }
49
+ return renderRegularTransition(pTransition, pDepth);
50
+ }
51
+ function renderTransitions(pTransitions, pDepth) {
52
+ return (pTransitions ?? [])
53
+ .map((pTransition) => renderTransition(pTransition, pDepth))
54
+ .join("");
55
+ }
56
+ function renderOnEntry(pOnEntry, pDepth) {
57
+ const lOnEntryTemplate = `
58
+ <onentry>{{entry}}</onentry>`;
59
+ const lReturnValue = lOnEntryTemplate.replace(
60
+ "{{entry}}",
61
+ he.escape(pOnEntry),
62
+ );
63
+ return indentString(lReturnValue, pDepth * INDENT_LENGTH);
64
+ }
65
+ function renderOnEntries(pOnEntries, pDepth) {
66
+ return (pOnEntries ?? [])
67
+ .map((pOnEntry) => renderOnEntry(pOnEntry, pDepth))
68
+ .join("");
69
+ }
70
+ function renderOnExit(pOnExit, pDepth) {
71
+ const lOnExitTemplate = `
72
+ <onexit>{{exit}}</onexit>`;
73
+ const lReturnValue = lOnExitTemplate.replace("{{exit}}", he.escape(pOnExit));
74
+ return indentString(lReturnValue, pDepth * INDENT_LENGTH);
75
+ }
76
+ function renderOnExits(pOnExits, pDepth) {
77
+ return (pOnExits ?? [])
78
+ .map((pOnExit) => renderOnExit(pOnExit, pDepth))
79
+ .join("");
80
+ }
81
+ function renderStateAtributes(pState) {
82
+ let lReturnValue = "";
83
+ if (pState.initial) {
84
+ lReturnValue += ` initial="${he.escape(pState.initial)}"`;
85
+ }
86
+ if (pState.type) {
87
+ lReturnValue += ` type="${he.escape(pState.type)}"`;
88
+ }
89
+ return lReturnValue;
90
+ }
91
+ function renderState(pState, pDepth) {
92
+ const lStateTemplate = `
93
+ <{{kind}} id="{{id}}"{{stateAttributes}}>{{states}}{{onentries}}{{onexits}}{{transitions}}
94
+ </{{kind}}>`;
95
+ const lReturnValue = lStateTemplate
96
+ .replaceAll("{{kind}}", pState.kind)
97
+ .replace("{{id}}", pState.id)
98
+ .replace("{{stateAttributes}}", renderStateAtributes(pState))
99
+ .replace("{{states}}", renderStates(pState.states, pDepth))
100
+ .replace("{{onentries}}", renderOnEntries(pState.onentries, pDepth))
101
+ .replace("{{onexits}}", renderOnExits(pState.onexits, pDepth))
102
+ .replace("{{transitions}}", renderTransitions(pState.transitions, pDepth));
103
+ return indentString(lReturnValue, pDepth * INDENT_LENGTH);
104
+ }
105
+ function renderStates(pStates, pDepth = 1) {
106
+ return (pStates ?? []).map((pState) => renderState(pState, pDepth)).join("");
107
+ }
108
+ function renderInitialAttribute(pInitialString) {
109
+ return pInitialString ? `initial="${pInitialString}" ` : "";
110
+ }
8
111
  export default function renderSCXML(pSCJSON) {
9
- return Handlebars.templates["scxml.template.hbs"](pSCJSON);
112
+ const lDocumentTemplate = `<?xml version="1.0" encoding="UTF-8"?>
113
+ <scxml xmlns="http://www.w3.org/2005/07/scxml" {{initial}}version="1.0">{{states}}
114
+ </scxml>
115
+ `;
116
+ return lDocumentTemplate
117
+ .replace("{{initial}}", renderInitialAttribute(pSCJSON.initial))
118
+ .replace("{{states}}", renderStates(pSCJSON.states));
10
119
  }
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "12.0.9";
1
+ export const version = "12.0.11";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-machine-cat",
3
- "version": "12.0.9",
3
+ "version": "12.0.11",
4
4
  "description": "write beautiful state charts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
@@ -50,13 +50,13 @@
50
50
  "state-machine-cat": "bin/smcat.mjs"
51
51
  },
52
52
  "dependencies": {
53
- "@hpcc-js/wasm": "2.16.2",
54
- "ajv": "8.13.0",
55
- "commander": "12.0.0",
56
- "fast-xml-parser": "4.3.6",
53
+ "@hpcc-js/wasm": "2.18.0",
54
+ "ajv": "8.17.1",
55
+ "commander": "12.1.0",
56
+ "fast-xml-parser": "4.4.0",
57
57
  "handlebars": "4.7.8",
58
58
  "he": "1.2.0",
59
- "semver": "^7.6.0",
59
+ "semver": "^7.6.2",
60
60
  "traverse": "0.6.8"
61
61
  },
62
62
  "engines": {
@@ -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});