state-machine-cat 12.0.11 → 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.
@@ -15,31 +15,19 @@ function renderTransitionAttributes(pTransition) {
15
15
  if (pTransition.type) {
16
16
  lReturnValue += ` type="${he.escape(pTransition.type)}"`;
17
17
  }
18
+ lReturnValue += ` target="${he.escape(pTransition.target)}"`;
18
19
  return lReturnValue;
19
20
  }
20
21
  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
- );
22
+ const lReturnValue = `
23
+ <transition${renderTransitionAttributes(pTransition)}/>`;
29
24
  return indentString(lReturnValue, pDepth * INDENT_LENGTH);
30
25
  }
31
26
  function renderActionTransition(pTransition, pDepth) {
32
- const lTransitionTemplate = `
33
- <transition{{transitionattributes}} target="{{target}}">
34
- {{action}}
27
+ const lReturnValue = `
28
+ <transition${renderTransitionAttributes(pTransition)}>
29
+ ${he.escape(pTransition.action)}
35
30
  </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
31
  return indentString(lReturnValue, pDepth * INDENT_LENGTH);
44
32
  }
45
33
  function renderTransition(pTransition, pDepth) {
@@ -53,33 +41,23 @@ function renderTransitions(pTransitions, pDepth) {
53
41
  .map((pTransition) => renderTransition(pTransition, pDepth))
54
42
  .join("");
55
43
  }
56
- function renderOnEntry(pOnEntry, pDepth) {
57
- const lOnEntryTemplate = `
58
- <onentry>{{entry}}</onentry>`;
59
- const lReturnValue = lOnEntryTemplate.replace(
60
- "{{entry}}",
61
- he.escape(pOnEntry),
62
- );
44
+ function renderSimpleTag(pOnExit, pTag, pDepth) {
45
+ const lReturnValue = `
46
+ <${pTag}>${he.escape(pOnExit)}</${pTag}>`;
63
47
  return indentString(lReturnValue, pDepth * INDENT_LENGTH);
64
48
  }
65
49
  function renderOnEntries(pOnEntries, pDepth) {
66
50
  return (pOnEntries ?? [])
67
- .map((pOnEntry) => renderOnEntry(pOnEntry, pDepth))
51
+ .map((pOnEntry) => renderSimpleTag(pOnEntry, "onentry", pDepth))
68
52
  .join("");
69
53
  }
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
54
  function renderOnExits(pOnExits, pDepth) {
77
55
  return (pOnExits ?? [])
78
- .map((pOnExit) => renderOnExit(pOnExit, pDepth))
56
+ .map((pOnExit) => renderSimpleTag(pOnExit, "onexit", pDepth))
79
57
  .join("");
80
58
  }
81
- function renderStateAtributes(pState) {
82
- let lReturnValue = "";
59
+ function renderStateAttributes(pState) {
60
+ let lReturnValue = ` id="${he.escape(pState.id)}"`;
83
61
  if (pState.initial) {
84
62
  lReturnValue += ` initial="${he.escape(pState.initial)}"`;
85
63
  }
@@ -89,17 +67,12 @@ function renderStateAtributes(pState) {
89
67
  return lReturnValue;
90
68
  }
91
69
  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));
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}>`;
103
76
  return indentString(lReturnValue, pDepth * INDENT_LENGTH);
104
77
  }
105
78
  function renderStates(pStates, pDepth = 1) {
@@ -109,11 +82,8 @@ function renderInitialAttribute(pInitialString) {
109
82
  return pInitialString ? `initial="${pInitialString}" ` : "";
110
83
  }
111
84
  export default function renderSCXML(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}}
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)}
114
87
  </scxml>
115
88
  `;
116
- return lDocumentTemplate
117
- .replace("{{initial}}", renderInitialAttribute(pSCJSON.initial))
118
- .replace("{{states}}", renderStates(pSCJSON.states));
119
89
  }
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "12.0.11";
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.11",
3
+ "version": "12.0.12",
4
4
  "description": "write beautiful state charts",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
@@ -53,7 +53,7 @@
53
53
  "@hpcc-js/wasm": "2.18.0",
54
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",