state-machine-cat 10.1.0-beta-1 → 10.1.1
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.
- package/README.md +1 -1
- package/bin/smcat.mjs +6 -4
- package/dist/commonjs/bundle.js +1 -1
- package/package.json +15 -13
- package/src/render/vector/vector-native-dot-with-fallback.mjs +13 -5
- package/src/version.mjs +1 -1
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ Usage: smcat [options] [infile]
|
|
|
77
77
|
|
|
78
78
|
Options:
|
|
79
79
|
-V, --version output the version number
|
|
80
|
-
-T --output-type <type> svg|eps|ps|ps2|dot|smcat|json|ast|scxml|oldsvg|scjson (default: "svg")
|
|
80
|
+
-T --output-type <type> svg|eps|ps|ps2|dot|smcat|json|ast|scxml|oldsvg|scjson|pdf|png (default: "svg")
|
|
81
81
|
-I --input-type <type> smcat|json|scxml (default: "smcat")
|
|
82
82
|
-E --engine <type> dot|circo|fdp|neato|osage|twopi (default: "dot")
|
|
83
83
|
-d --direction <dir> top-down|bottom-top|left-right|right-left (default: "top-down")
|
package/bin/smcat.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
2
3
|
import { program } from "commander";
|
|
3
4
|
import satisfies from "semver/functions/satisfies.js";
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
5
5
|
import actions from "../src/cli/actions.mjs";
|
|
6
6
|
import makeDescription from "../src/cli/make-description.mjs";
|
|
7
7
|
import normalize from "../src/cli/normalize.mjs";
|
|
@@ -86,9 +86,11 @@ try {
|
|
|
86
86
|
})
|
|
87
87
|
.arguments("[infile]")
|
|
88
88
|
.parse(process.argv);
|
|
89
|
-
actions
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
actions
|
|
90
|
+
.transform(
|
|
91
|
+
validations.validateArguments(normalize(program.args[0], program.opts()))
|
|
92
|
+
)
|
|
93
|
+
.catch(presentError);
|
|
92
94
|
} catch (pError) {
|
|
93
95
|
presentError(pError);
|
|
94
96
|
}
|
package/dist/commonjs/bundle.js
CHANGED
|
@@ -76,4 +76,4 @@ var Ta=Object.create;var ge=Object.defineProperty;var Ba=Object.getOwnPropertyDe
|
|
|
76
76
|
`)),t.cond&&(e.cond=t.cond),t["#text"]&&(e.action=W.default.decode(t["#text"]).trim()),t.type&&(e.type=t.type),e}function co(t){let e={};typeof t=="string"?e.action=W.default.decode(t).trim():Object.assign(e,so(t));let n=ro(e.event,e.cond,e.action);return n&&(e.label=n),e}function uo(t){return(e,n)=>{let d=(n.target||t.id).split(/\s+/),r=co(n);return e.concat(d.map(u=>({from:t.id,to:u,...r})))}}function Fe(t){return t.filter(e=>Object.prototype.hasOwnProperty.call(e,"transition")).reduce((e,n)=>e.concat((0,ve.default)(n.transition).reduce(uo(n),[])),[])}function hn(t){let e=_e(t),n={};n.states=e.initial.map(oe("initial")).concat(e.state.map(oe("regular"))).concat(e.parallel.map(oe("parallel"))).concat(e.history.map(oe("history"))).concat(e.final.map(oe("final")));let d=Fe(e.initial).concat(Fe(e.state)).concat(Fe(e.parallel));return d.length>0&&(n.transitions=d),n}function gn(t){let e=t.trim();if(Re.default.validate(e)===!0){let n=Re.default.parse(e,{attributeNamePrefix:"",ignoreAttributes:!1,tagValueProcessor:d=>W.default.decode(d),stopNodes:["onentry","onexit","transition"]});return hn((n==null?void 0:n.scxml)??{})}throw new Error(`That doesn't look like valid xml ...
|
|
77
77
|
`)}var yn={$schema:"http://json-schema.org/draft-07/schema#",title:"state-machine-cat abstract syntax tree schema",$ref:"#/definitions/StateMachineType",$id:"org.js.state-machine-cat/v7.4.0",definitions:{StateType:{type:"string",enum:["regular","initial","terminate","final","parallel","history","deephistory","choice","forkjoin","fork","join","junction"]},TransitionType:{type:"string",enum:["internal","external"]},NoteType:{type:"array",items:{type:"string"}},ActionTypeType:{type:"string",enum:["entry","activity","exit"]},ActionType:{type:"object",required:["type","body"],additionalProperties:!1,properties:{type:{$ref:"#/definitions/ActionTypeType"},body:{type:"string"}}},ClassType:{type:"string",pattern:"^[a-zA-Z0-9_\\- ]*$"},StateMachineType:{type:"object",additionalProperties:!1,required:["states"],properties:{states:{type:"array",items:{type:"object",required:["name","type"],additionalProperties:!1,properties:{name:{description:"The name and identifier of the state. Unique within the root state machine.",type:"string"},type:{description:"What kind of state (or pseudo state) this state is. E.g. 'regular' for normal states or 'initial', 'final', 'choice' etc for pseudo states. Most UML (pseudo-) states are supported.",$ref:"#/definitions/StateType"},label:{description:"The display label of the state. If it's not present, most renderers will use the states' name in stead.",type:"string"},color:{description:'Color to use for rendering the state. Accepts all css color names ("blue") and hex notation - with ("#0000FF77") or without ("#0000FF") transparency.',type:"string"},class:{description:"Class name to give the state in dot and svg output.",$ref:"#/definitions/ClassType"},active:{description:"If true the state is considered to be active and rendered as such.",type:"boolean"},typeExplicitlySet:{description:"The default parser derives the `type` from the `name` with inband signaling. The user can override that behavior by explicitly setting the `type`. This attribute is there to express that (and make sure that on next parses & processing it doesn't get accidentily re-derived from the name again).",type:"boolean"},isComposite:{description:"convenience, derived attribute - set to true if there's a state machine inside the state; false in all other cases. For internal use - @deprecated",type:"boolean"},actions:{type:"array",description:"A series of actions and their types. The type describe when the action takes place (on entry, exit, or otherwise ('activity'))",items:{$ref:"#/definitions/ActionType"}},note:{description:"Comments related to this state. Some renderers will use the note attribute to render a note (i.e. as a post-it) attached to the state.",$ref:"#/definitions/NoteType"},statemachine:{description:"state machine nested within the state.",$ref:"#/definitions/StateMachineType"}}}},transitions:{type:"array",items:{type:"object",required:["from","to"],additionalProperties:!1,properties:{from:{description:"The name of the state this transition transitions from",type:"string"},to:{description:"The name of the state this transition transitions to",type:"string"},label:{description:"A display label to represent this transition. Parsers can parse this label into events conditions and actions.",type:"string"},event:{description:"Event triggering the transition",type:"string"},cond:{description:"Condition for the transition to occur.",type:"string"},action:{description:"Action to execute when the transition occurs.",type:"string"},note:{description:"Comments related to this transition",$ref:"#/definitions/NoteType"},color:{description:'Color to use for rendering the transition. Accepts all css color names ("blue") and hex notation - with ("#0000FF77") or without ("#0000FF") transparency.',type:"string"},width:{description:"The line width to use for rendering the transition",type:"number",minimum:0,maximum:30},class:{description:"Class name to give the state in dot and svg output.",$ref:"#/definitions/ClassType"},type:{description:"Whether the transition is external (default) or internal. See https://www.w3.org/TR/scxml/#transition for details.",$ref:"#/definitions/TransitionType"}}}}}}}};var vn=new bn.default;function fo(t,e){if(!vn.validate(t,e))throw new Error(`The provided JSON is not a valid state-machine-cat AST: ${vn.errorsText()}.
|
|
78
78
|
`)}var $n={getAST(t,e){let n=t;return H.getOptionValue(e,"inputType")==="smcat"?n=pn(t):H.getOptionValue(e,"inputType")==="scxml"?n=gn(t):typeof t=="string"&&(n=JSON.parse(t)),fo(yn,n),n}};var Be=B(require("lodash/cloneDeep.js"),1),Te=B(require("lodash/reject.js"),1);function mo(t,e,n){return t?`${t}${n}${e}`:e}function po(t,e){let n={...t,...e,from:t.from,to:e.to};return e.action&&(n.action=mo(t.action,e.action,`
|
|
79
|
-
`)),(n.event||n.cond||n.action)&&(n.label=ye.formatLabel(n.event,n.cond,n.action)),n}function ho(t,e,n){return t.reduce((d,r)=>(e.forEach((u,s)=>{u===r.to&&n[u]?d=d.concat(n[u].map(f=>po(r,f))):d=s===0?d.concat(r):d}),d),[])}function xn(t,e,n){let d=(0,Be.default)(t);return d.transitions&&e.length>0&&(d.transitions=ho(d.transitions,e,n)),d.states=d.states.map(r=>r.statemachine?{...r,statemachine:xn(r.statemachine,e,n)}:r),d}function kn(t,e){let n=(0,Be.default)(t);return n.transitions&&(n.transitions=(0,Te.default)(n.transitions,d=>e.some(r=>r===d.from||r===d.to))),n.states=(0,Te.default)(n.states,d=>e.includes(d.name)).map(d=>d.statemachine?{...d,statemachine:kn(d.statemachine,e)}:d),n}var wn=(t,e=["fork","junction","choice"])=>{let n=new q(t),d=n.findStatesByTypes(e).map(s=>s.name),r=d.reduce((s,f)=>(s[f]=n.findTransitionsByFrom(f),s),{}),u=xn(t,d,r);return kn(u,d)};var Xn=B(require("lodash/has.js"),1),Jn=B(jn(),1);var Bn=B(require("lodash/cloneDeep.js"),1);var Oo=[{name:"fontname",value:'"Helvetica"'},{name:"fontsize",value:"12"},{name:"penwidth",value:"2.0"}],Eo={dot:[{name:"splines",value:"true"},{name:"ordering",value:"out"},{name:"compound",value:"true"},{name:"overlap",value:"scale"},{name:"nodesep",value:"0.3"},{name:"ranksep",value:"0.1"}],fdp:[{name:"K",value:"0.9"}],osage:[{name:"pack",value:"42"}],neato:[{name:"epsilon",value:"0.9"}]},jo={"bottom-top":[{name:"rankdir",value:"BT"}],"left-right":[{name:"rankdir",value:"LR"}],"right-left":[{name:"rankdir",value:"RL"}]},Ao=[{name:"shape",value:"plaintext"},{name:"style",value:"filled"},{name:"fillcolor",value:'"#FFFFFF01"'},{name:"fontname",value:"Helvetica"},{name:"fontsize",value:12},{name:"penwidth",value:"2.0"}],_o=[{name:"fontname",value:"Helvetica"},{name:"fontsize",value:10}];function Ie(t){return`${t.name}=${t.value}`}var be={buildGraphAttributes:(t,e,n)=>Oo.concat(Eo[t]||[]).concat(jo[e]||[]).concat(n||[]).map(Ie).join(" "),buildNodeAttributes:t=>Ao.concat(t||[]).map(Ie).join(" "),buildEdgeAttributes:t=>_o.concat(t||[]).map(Ie).join(" ")};function Fo(t){return t.replace(/\\/g,"\\\\").replace(/\n\s*/g,"\\l").replace(/"/g,'\\"').concat("\\l")}function Ro(t){return t.replace(/\\/g,"\\\\").replace(/\n\s*/g," \\l").replace(/"/g,'\\"').concat(" \\l")}function To(t){let e=t||"top-down";return e==="top-down"||e==="bottom-top"}function Bo(t,e){return e.from===e.to&&t.findStateByName(e.from).statemachine&&e.type!=="internal"}var N={escapeString:Fo,escapeLabelString:Ro,isVertical:To,isCompositeSelf:Bo};function An(t){return e=>e.type===t}function De(t){return e=>t.includes(e.type)}function Ho(t){return t.label=t.label||t.name,t}function qo(t){return Object.prototype.hasOwnProperty.call(t,"note")&&(t.noteName=`note_${t.name}`),t}function Io(t){let e=["state",t.type];return Object.prototype.hasOwnProperty.call(t,"class")&&e.push(t.class.trim().replace(/[ ]{2,}/g," ")),t.class=e.join(" "),t}function Do(t){return t==="activity"?"":`${t}/ `}function Lo(t){let e={...t};return t.actions&&(e.actions=t.actions.map(n=>`${Do(n.type)}${n.body}`)),e}function Vo(t){return Object.prototype.hasOwnProperty.call(t,"note")&&(t.noteFlattened=t.note.join("")),t}function No(t){return e=>{var d;let n=(d=(t||[]).find(r=>r.name==="color"))==null?void 0:d.value;return n&&!e.color&&De(["initial","fork","join","junction","forkjoin","final"])(e)&&(e.color=n),e}}function So(t){return t.note&&(t.note=t.note.map(N.escapeString)),t}function Mo(t){return e=>De(["fork","join","forkjoin"])(e)?{sizingExtras:N.isVertical(t)?"height=0.1":"width=0.1",...e}:e}function zo(t){return t.type==="parallel"&&t.statemachine&&t.statemachine.states&&(t.statemachine.states=t.statemachine.states.map(e=>An("regular")(e)?{...e,parentIsParallel:!0}:e)),t}var F={isType:An,isOneOfTypes:De,setLabel:Ho,classifyState:Io,nameNote:qo,flattenActions:Lo,flattenNote:Vo,recolor:No,escapeStateStrings:So,tipForkJoinStates:Mo,flagParallelChildren:zo};function Uo(t){return t.note&&(t.note=t.note.map(N.escapeString)),t.label&&(t.label=N.escapeLabelString(t.label)),t}function Go(t){return e=>{let n={};return e.isCompositeSelf&&(N.isVertical(t)?n={tailportflags:'tailport="e" headport="e"',headportflags:'tailport="w"'}:e.hasParent?n={tailportflags:'tailport="n" headport="n"',headportflags:'tailport="s"'}:n={tailportflags:'tailport="s" headport="s"',headportflags:'tailport="n"'}),{...e,...n}}}function Xo(t){let e=["transition"];return t.type&&e.push(t.type),t.class&&e.push(t.class.trim().replace(/[ ]{2,}/g," ")),t.class=e.join(" "),t}var $e={escapeTransitionStrings:Uo,addPorts:Go,classifyTransition:Xo};var ie=class{constructor(){this.reset()}reset(){this.COUNTER=0}next(){return++this.COUNTER}nextAsString(){return this.next().toString(10)}};var Hn=B(Tn(),1);var qn={};function ei(t){return e=>(Object.prototype.hasOwnProperty.call(e,"statemachine")&&(e.nestedExternalSelfTransitions=t.findExternalSelfTransitions(e.name).map(n=>n.name)),e)}function In(t,e,n,d){return t.filter(r=>r.statemachine).forEach(r=>{r.statemachine.states=In(r.statemachine.states,e,n,d)}),t.map(F.setLabel).map(F.nameNote).map(F.classifyState).map(F.escapeStateStrings).map(F.flattenNote).map(F.flattenActions).map(F.flagParallelChildren).map(F.tipForkJoinStates(e)).map(F.recolor(n)).map(ei(d))}function ti(t){return t.initialStates=t.states.filter(F.isType("initial")),t.regularStates=t.states.filter(e=>F.isType("regular")(e)&&!e.statemachine),t.historyStates=t.states.filter(F.isType("history")),t.deepHistoryStates=t.states.filter(F.isType("deephistory")),t.choiceStates=t.states.filter(F.isType("choice")),t.forkjoinStates=t.states.filter(F.isOneOfTypes(["fork","join","forkjoin"])),t.junctionStates=t.states.filter(F.isType("junction")),t.terminateStates=t.states.filter(F.isType("terminate")),t.finalStates=t.states.filter(F.isType("final")),t.compositeStates=t.states.filter(e=>e.statemachine),t}function ni(t){return e=>(t.findStateByName(e.from).statemachine&&(e.fromComposite=!0),t.findStateByName(e.to).statemachine&&(e.toComposite=!0),e)}function li(t){return e=>{let n={};return N.isCompositeSelf(t,e)&&(t.findStateByName(e.from).hasParent?n={hasParent:!0,isCompositeSelf:!0}:n={isCompositeSelf:!0}),{...e,...n}}}function ri(t){return t.name=`tr_${t.from}_${t.to}_${qn.nextAsString()}`,Boolean(t.note)&&(t.noteName=`note_${t.name}`),t}function ai(t,e){return t.flattenedTransitions.map(ri).map($e.escapeTransitionStrings).map($e.classifyTransition).map(F.flattenNote).map(ni(t)).map(li(t)).map($e.addPorts(e))}var xe=(t,e)=>{e=e||{},qn=new ie;let n=(0,Bn.default)(t),d=new q(n);return n.transitions=ai(d,e.direction),n.states=In(n.states,e.direction,e.dotNodeAttrs,d),n=ti(n),n.graphAttributes=be.buildGraphAttributes(H.getOptionValue(e,"engine"),H.getOptionValue(e,"direction"),e.dotGraphAttrs),n.nodeAttributes=be.buildNodeAttributes(e.dotNodeAttrs),n.edgeAttributes=be.buildEdgeAttributes(e.dotEdgeAttrs),(0,Hn.default)(n)};var Dn=B(require("viz.js"),1);var oi={oldsvg:"svg",oldps2:"ps2",oldeps:"eps"},Ne=(t,e)=>(0,Dn.default)(xe(t,e),{engine:H.getOptionValue(e,"engine"),format:oi[H.getOptionValue(e,"outputType")]||"svg"});var ii=/[\u0000-\u002C|\u002F|\u003B-\u0040|\u005B-\u0060|\u007B-\u00BF|\u00D7|\u00F7|\u0300-\u036F|\u037E|\u2000-\u200B|\u200E-\u206F|\u2190-\u2BFF|\u2FF0-\u3000|\uD800-\uF8FF|\uFDD0-\uFDEF|\uFFFE-\uFFFF]/g,si=/[-|.|0-9|\u00B7|\u0300-\u036F|\u203F-\u2040]/g;function Ln(t){return t.replace(ii,"_")}function ci(t){let e=Ln(t);return e.match(si)&&(e=`_${t}`),e}var ke=t=>(t=t||"",t.length===0?"__empty":ci(t[0]).concat(Ln(t.slice(1))));var ui=/[\u00B7|\u0300-\u036F|\u203F-\u2040|\u0000-\u0029|\u002B-\u002C|\u002F|\u003B-\u0040|\u005B-\u0060|\u007B-\u00BF|\u00D7|\u00F7|\u0300-\u036F|\u037E|\u2000-\u200B|\u200E-\u206F|\u2190-\u2BFF|\u2FF0-\u3000|\uD800-\uF8FF|\uFDD0-\uFDEF|\uFFFE-\uFFFF]/g,fi=/[.]/g;function Vn(t){return t.replace(ui,"_")}function mi(t){let e=Vn(t);return e.match(fi)&&(e=`_${t}`),e}function pi(t){return t=t.replace(/\s+/g," ").trim(),mi(t[0]).concat(Vn(t.slice(1)))}var Nn=t=>(t=t||"",t.length===0?"empty":t.split(/[\n\r]+/).filter(e=>e.length>0).map(pi).join(" "));var di={regular:"state",initial:"initial",final:"final",terminate:"final",parallel:"parallel",history:"history",deephistory:"history"};function hi(t){return di[t]||"state"}function gi(t){let e={target:ke(t.to)};return Boolean(t.event)&&(e.event=Nn(t.event)),Boolean(t.cond)&&(e.cond=t.cond),Boolean(t.action)&&(e.action=t.action),Boolean(t.type)&&(e.type=t.type),e}function yi(t,e){return t.filter(n=>n.type===e).map(n=>n.body)}function Se(t,e,n,d){let r=yi(n,d);r.length>0&&(t[e]=(t[e]||[]).concat(r))}function vi(t,e){Boolean(e.actions)&&(Se(t,"onentries",e.actions,"entry"),Se(t,"onentries",e.actions,"activity"),Se(t,"onexits",e.actions,"exit"))}function bi(t,e,n){let d=n.filter(r=>r.from===e.name).map(gi);d.length>0&&(t.transitions=d)}function $i(t,e,n){if(Boolean(e.statemachine)){let d=ee(e.statemachine,null,n);t.states=(t.states||[]).concat(d.states),d.initial&&(t.initial=d.initial)}}function xi(t){return t=t||[],e=>{let n={kind:hi(e.type),id:ke(e.name)};return e.type==="deephistory"&&(n.type="deep"),vi(n,e),bi(n,e,t),$i(n,e,t),n}}function ki(t){let e=null,n=t.states.filter(d=>d.type==="initial");return n.length>0&&(e=n[0].name),e}function wi(t,e){let n=e;if(e&&t.transitions){let d=t.transitions.filter(r=>r.from===e);d.length>0&&!d[0].action&&(n=d[0].to)}return n}function ee(t,e,n){let d=ki(t),r=wi(t,d),u={states:t.states.filter(s=>r&&r!==d?s.type!=="initial":!0).map(xi(n||new q(t).flattenedTransitions))};return r&&(u.initial=ke(r)),u}var Gn=B(Un(),1);function Ge(t){return(0,Gn.default)(ee(t))}function Xe(t){let e={smcat:Jn.default,dot:xe,svg:Ne,oldsvg:Ne,scjson:ee,scxml:Ge};return(0,Xn.default)(e,t)?e[t]:n=>n}var Qn="10.1.
|
|
79
|
+
`)),(n.event||n.cond||n.action)&&(n.label=ye.formatLabel(n.event,n.cond,n.action)),n}function ho(t,e,n){return t.reduce((d,r)=>(e.forEach((u,s)=>{u===r.to&&n[u]?d=d.concat(n[u].map(f=>po(r,f))):d=s===0?d.concat(r):d}),d),[])}function xn(t,e,n){let d=(0,Be.default)(t);return d.transitions&&e.length>0&&(d.transitions=ho(d.transitions,e,n)),d.states=d.states.map(r=>r.statemachine?{...r,statemachine:xn(r.statemachine,e,n)}:r),d}function kn(t,e){let n=(0,Be.default)(t);return n.transitions&&(n.transitions=(0,Te.default)(n.transitions,d=>e.some(r=>r===d.from||r===d.to))),n.states=(0,Te.default)(n.states,d=>e.includes(d.name)).map(d=>d.statemachine?{...d,statemachine:kn(d.statemachine,e)}:d),n}var wn=(t,e=["fork","junction","choice"])=>{let n=new q(t),d=n.findStatesByTypes(e).map(s=>s.name),r=d.reduce((s,f)=>(s[f]=n.findTransitionsByFrom(f),s),{}),u=xn(t,d,r);return kn(u,d)};var Xn=B(require("lodash/has.js"),1),Jn=B(jn(),1);var Bn=B(require("lodash/cloneDeep.js"),1);var Oo=[{name:"fontname",value:'"Helvetica"'},{name:"fontsize",value:"12"},{name:"penwidth",value:"2.0"}],Eo={dot:[{name:"splines",value:"true"},{name:"ordering",value:"out"},{name:"compound",value:"true"},{name:"overlap",value:"scale"},{name:"nodesep",value:"0.3"},{name:"ranksep",value:"0.1"}],fdp:[{name:"K",value:"0.9"}],osage:[{name:"pack",value:"42"}],neato:[{name:"epsilon",value:"0.9"}]},jo={"bottom-top":[{name:"rankdir",value:"BT"}],"left-right":[{name:"rankdir",value:"LR"}],"right-left":[{name:"rankdir",value:"RL"}]},Ao=[{name:"shape",value:"plaintext"},{name:"style",value:"filled"},{name:"fillcolor",value:'"#FFFFFF01"'},{name:"fontname",value:"Helvetica"},{name:"fontsize",value:12},{name:"penwidth",value:"2.0"}],_o=[{name:"fontname",value:"Helvetica"},{name:"fontsize",value:10}];function Ie(t){return`${t.name}=${t.value}`}var be={buildGraphAttributes:(t,e,n)=>Oo.concat(Eo[t]||[]).concat(jo[e]||[]).concat(n||[]).map(Ie).join(" "),buildNodeAttributes:t=>Ao.concat(t||[]).map(Ie).join(" "),buildEdgeAttributes:t=>_o.concat(t||[]).map(Ie).join(" ")};function Fo(t){return t.replace(/\\/g,"\\\\").replace(/\n\s*/g,"\\l").replace(/"/g,'\\"').concat("\\l")}function Ro(t){return t.replace(/\\/g,"\\\\").replace(/\n\s*/g," \\l").replace(/"/g,'\\"').concat(" \\l")}function To(t){let e=t||"top-down";return e==="top-down"||e==="bottom-top"}function Bo(t,e){return e.from===e.to&&t.findStateByName(e.from).statemachine&&e.type!=="internal"}var N={escapeString:Fo,escapeLabelString:Ro,isVertical:To,isCompositeSelf:Bo};function An(t){return e=>e.type===t}function De(t){return e=>t.includes(e.type)}function Ho(t){return t.label=t.label||t.name,t}function qo(t){return Object.prototype.hasOwnProperty.call(t,"note")&&(t.noteName=`note_${t.name}`),t}function Io(t){let e=["state",t.type];return Object.prototype.hasOwnProperty.call(t,"class")&&e.push(t.class.trim().replace(/[ ]{2,}/g," ")),t.class=e.join(" "),t}function Do(t){return t==="activity"?"":`${t}/ `}function Lo(t){let e={...t};return t.actions&&(e.actions=t.actions.map(n=>`${Do(n.type)}${n.body}`)),e}function Vo(t){return Object.prototype.hasOwnProperty.call(t,"note")&&(t.noteFlattened=t.note.join("")),t}function No(t){return e=>{var d;let n=(d=(t||[]).find(r=>r.name==="color"))==null?void 0:d.value;return n&&!e.color&&De(["initial","fork","join","junction","forkjoin","final"])(e)&&(e.color=n),e}}function So(t){return t.note&&(t.note=t.note.map(N.escapeString)),t}function Mo(t){return e=>De(["fork","join","forkjoin"])(e)?{sizingExtras:N.isVertical(t)?"height=0.1":"width=0.1",...e}:e}function zo(t){return t.type==="parallel"&&t.statemachine&&t.statemachine.states&&(t.statemachine.states=t.statemachine.states.map(e=>An("regular")(e)?{...e,parentIsParallel:!0}:e)),t}var F={isType:An,isOneOfTypes:De,setLabel:Ho,classifyState:Io,nameNote:qo,flattenActions:Lo,flattenNote:Vo,recolor:No,escapeStateStrings:So,tipForkJoinStates:Mo,flagParallelChildren:zo};function Uo(t){return t.note&&(t.note=t.note.map(N.escapeString)),t.label&&(t.label=N.escapeLabelString(t.label)),t}function Go(t){return e=>{let n={};return e.isCompositeSelf&&(N.isVertical(t)?n={tailportflags:'tailport="e" headport="e"',headportflags:'tailport="w"'}:e.hasParent?n={tailportflags:'tailport="n" headport="n"',headportflags:'tailport="s"'}:n={tailportflags:'tailport="s" headport="s"',headportflags:'tailport="n"'}),{...e,...n}}}function Xo(t){let e=["transition"];return t.type&&e.push(t.type),t.class&&e.push(t.class.trim().replace(/[ ]{2,}/g," ")),t.class=e.join(" "),t}var $e={escapeTransitionStrings:Uo,addPorts:Go,classifyTransition:Xo};var ie=class{constructor(){this.reset()}reset(){this.COUNTER=0}next(){return++this.COUNTER}nextAsString(){return this.next().toString(10)}};var Hn=B(Tn(),1);var qn={};function ei(t){return e=>(Object.prototype.hasOwnProperty.call(e,"statemachine")&&(e.nestedExternalSelfTransitions=t.findExternalSelfTransitions(e.name).map(n=>n.name)),e)}function In(t,e,n,d){return t.filter(r=>r.statemachine).forEach(r=>{r.statemachine.states=In(r.statemachine.states,e,n,d)}),t.map(F.setLabel).map(F.nameNote).map(F.classifyState).map(F.escapeStateStrings).map(F.flattenNote).map(F.flattenActions).map(F.flagParallelChildren).map(F.tipForkJoinStates(e)).map(F.recolor(n)).map(ei(d))}function ti(t){return t.initialStates=t.states.filter(F.isType("initial")),t.regularStates=t.states.filter(e=>F.isType("regular")(e)&&!e.statemachine),t.historyStates=t.states.filter(F.isType("history")),t.deepHistoryStates=t.states.filter(F.isType("deephistory")),t.choiceStates=t.states.filter(F.isType("choice")),t.forkjoinStates=t.states.filter(F.isOneOfTypes(["fork","join","forkjoin"])),t.junctionStates=t.states.filter(F.isType("junction")),t.terminateStates=t.states.filter(F.isType("terminate")),t.finalStates=t.states.filter(F.isType("final")),t.compositeStates=t.states.filter(e=>e.statemachine),t}function ni(t){return e=>(t.findStateByName(e.from).statemachine&&(e.fromComposite=!0),t.findStateByName(e.to).statemachine&&(e.toComposite=!0),e)}function li(t){return e=>{let n={};return N.isCompositeSelf(t,e)&&(t.findStateByName(e.from).hasParent?n={hasParent:!0,isCompositeSelf:!0}:n={isCompositeSelf:!0}),{...e,...n}}}function ri(t){return t.name=`tr_${t.from}_${t.to}_${qn.nextAsString()}`,Boolean(t.note)&&(t.noteName=`note_${t.name}`),t}function ai(t,e){return t.flattenedTransitions.map(ri).map($e.escapeTransitionStrings).map($e.classifyTransition).map(F.flattenNote).map(ni(t)).map(li(t)).map($e.addPorts(e))}var xe=(t,e)=>{e=e||{},qn=new ie;let n=(0,Bn.default)(t),d=new q(n);return n.transitions=ai(d,e.direction),n.states=In(n.states,e.direction,e.dotNodeAttrs,d),n=ti(n),n.graphAttributes=be.buildGraphAttributes(H.getOptionValue(e,"engine"),H.getOptionValue(e,"direction"),e.dotGraphAttrs),n.nodeAttributes=be.buildNodeAttributes(e.dotNodeAttrs),n.edgeAttributes=be.buildEdgeAttributes(e.dotEdgeAttrs),(0,Hn.default)(n)};var Dn=B(require("viz.js"),1);var oi={oldsvg:"svg",oldps2:"ps2",oldeps:"eps"},Ne=(t,e)=>(0,Dn.default)(xe(t,e),{engine:H.getOptionValue(e,"engine"),format:oi[H.getOptionValue(e,"outputType")]||"svg"});var ii=/[\u0000-\u002C|\u002F|\u003B-\u0040|\u005B-\u0060|\u007B-\u00BF|\u00D7|\u00F7|\u0300-\u036F|\u037E|\u2000-\u200B|\u200E-\u206F|\u2190-\u2BFF|\u2FF0-\u3000|\uD800-\uF8FF|\uFDD0-\uFDEF|\uFFFE-\uFFFF]/g,si=/[-|.|0-9|\u00B7|\u0300-\u036F|\u203F-\u2040]/g;function Ln(t){return t.replace(ii,"_")}function ci(t){let e=Ln(t);return e.match(si)&&(e=`_${t}`),e}var ke=t=>(t=t||"",t.length===0?"__empty":ci(t[0]).concat(Ln(t.slice(1))));var ui=/[\u00B7|\u0300-\u036F|\u203F-\u2040|\u0000-\u0029|\u002B-\u002C|\u002F|\u003B-\u0040|\u005B-\u0060|\u007B-\u00BF|\u00D7|\u00F7|\u0300-\u036F|\u037E|\u2000-\u200B|\u200E-\u206F|\u2190-\u2BFF|\u2FF0-\u3000|\uD800-\uF8FF|\uFDD0-\uFDEF|\uFFFE-\uFFFF]/g,fi=/[.]/g;function Vn(t){return t.replace(ui,"_")}function mi(t){let e=Vn(t);return e.match(fi)&&(e=`_${t}`),e}function pi(t){return t=t.replace(/\s+/g," ").trim(),mi(t[0]).concat(Vn(t.slice(1)))}var Nn=t=>(t=t||"",t.length===0?"empty":t.split(/[\n\r]+/).filter(e=>e.length>0).map(pi).join(" "));var di={regular:"state",initial:"initial",final:"final",terminate:"final",parallel:"parallel",history:"history",deephistory:"history"};function hi(t){return di[t]||"state"}function gi(t){let e={target:ke(t.to)};return Boolean(t.event)&&(e.event=Nn(t.event)),Boolean(t.cond)&&(e.cond=t.cond),Boolean(t.action)&&(e.action=t.action),Boolean(t.type)&&(e.type=t.type),e}function yi(t,e){return t.filter(n=>n.type===e).map(n=>n.body)}function Se(t,e,n,d){let r=yi(n,d);r.length>0&&(t[e]=(t[e]||[]).concat(r))}function vi(t,e){Boolean(e.actions)&&(Se(t,"onentries",e.actions,"entry"),Se(t,"onentries",e.actions,"activity"),Se(t,"onexits",e.actions,"exit"))}function bi(t,e,n){let d=n.filter(r=>r.from===e.name).map(gi);d.length>0&&(t.transitions=d)}function $i(t,e,n){if(Boolean(e.statemachine)){let d=ee(e.statemachine,null,n);t.states=(t.states||[]).concat(d.states),d.initial&&(t.initial=d.initial)}}function xi(t){return t=t||[],e=>{let n={kind:hi(e.type),id:ke(e.name)};return e.type==="deephistory"&&(n.type="deep"),vi(n,e),bi(n,e,t),$i(n,e,t),n}}function ki(t){let e=null,n=t.states.filter(d=>d.type==="initial");return n.length>0&&(e=n[0].name),e}function wi(t,e){let n=e;if(e&&t.transitions){let d=t.transitions.filter(r=>r.from===e);d.length>0&&!d[0].action&&(n=d[0].to)}return n}function ee(t,e,n){let d=ki(t),r=wi(t,d),u={states:t.states.filter(s=>r&&r!==d?s.type!=="initial":!0).map(xi(n||new q(t).flattenedTransitions))};return r&&(u.initial=ke(r)),u}var Gn=B(Un(),1);function Ge(t){return(0,Gn.default)(ee(t))}function Xe(t){let e={smcat:Jn.default,dot:xe,svg:Ne,oldsvg:Ne,scjson:ee,scxml:Ge};return(0,Xn.default)(e,t)?e[t]:n=>n}var Qn="10.1.1";function Wn(t,e){let n=$n.getAST(t,e),d=H.getOptionValue(e,"desugar");return Xe(H.getOptionValue(e,"outputType"))(d?wn(n):n,e)}var Yn=Qn;function Zn(){return H.getAllowedValues()}var ji={render:Wn,version:Yn,getAllowedValues:Zn};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-machine-cat",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.1",
|
|
4
4
|
"description": "write beautiful state charts",
|
|
5
5
|
"main": "./dist/commonjs/index.js",
|
|
6
6
|
"module": "./src/index.mjs",
|
|
@@ -394,49 +394,51 @@
|
|
|
394
394
|
},
|
|
395
395
|
"dependencies": {
|
|
396
396
|
"ajv": "8.11.0",
|
|
397
|
-
"chalk": "5.0
|
|
398
|
-
"commander": "9.4.
|
|
397
|
+
"chalk": "5.1.0",
|
|
398
|
+
"commander": "9.4.1",
|
|
399
399
|
"fast-xml-parser": "3.21.1",
|
|
400
400
|
"get-stream": "6.0.1",
|
|
401
401
|
"handlebars": "4.7.7",
|
|
402
402
|
"he": "1.2.0",
|
|
403
403
|
"indent-string": "5.0.0",
|
|
404
404
|
"lodash": "4.17.21",
|
|
405
|
-
"semver": "^7.3.
|
|
405
|
+
"semver": "^7.3.8",
|
|
406
406
|
"viz.js": "1.8.2",
|
|
407
407
|
"wrap-ansi": "8.0.1"
|
|
408
408
|
},
|
|
409
409
|
"devDependencies": {
|
|
410
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
411
|
-
"@typescript-eslint/parser": "5.
|
|
410
|
+
"@typescript-eslint/eslint-plugin": "5.39.0",
|
|
411
|
+
"@typescript-eslint/parser": "5.39.0",
|
|
412
412
|
"c8": "7.12.0",
|
|
413
413
|
"chai": "4.3.6",
|
|
414
414
|
"chai-as-promised": "7.1.1",
|
|
415
415
|
"chai-json-schema": "1.5.1",
|
|
416
416
|
"chai-xml": "0.4.0",
|
|
417
|
-
"dependency-cruiser": "11.
|
|
418
|
-
"esbuild": "0.15.
|
|
419
|
-
"eslint": "8.
|
|
417
|
+
"dependency-cruiser": "11.16.1",
|
|
418
|
+
"esbuild": "0.15.10",
|
|
419
|
+
"eslint": "8.25.0",
|
|
420
420
|
"eslint-config-moving-meadow": "4.0.2",
|
|
421
421
|
"eslint-config-prettier": "8.5.0",
|
|
422
|
-
"eslint-plugin-budapestian": "5.0.
|
|
422
|
+
"eslint-plugin-budapestian": "5.0.1",
|
|
423
423
|
"eslint-plugin-eslint-comments": "3.2.0",
|
|
424
424
|
"eslint-plugin-import": "2.26.0",
|
|
425
425
|
"eslint-plugin-mocha": "10.1.0",
|
|
426
426
|
"eslint-plugin-node": "11.1.0",
|
|
427
427
|
"eslint-plugin-security": "1.5.0",
|
|
428
|
-
"eslint-plugin-unicorn": "
|
|
428
|
+
"eslint-plugin-unicorn": "44.0.2",
|
|
429
429
|
"husky": "8.0.1",
|
|
430
|
+
"is-pdf": "1.0.0",
|
|
431
|
+
"is-png": "3.0.1",
|
|
430
432
|
"lint-staged": "13.0.3",
|
|
431
433
|
"mocha": "10.0.0",
|
|
432
434
|
"npm-run-all": "4.1.5",
|
|
433
435
|
"peggy": "2.0.1",
|
|
434
436
|
"prettier": "2.7.1",
|
|
435
437
|
"query-string": "7.1.1",
|
|
436
|
-
"typescript": "4.8.
|
|
438
|
+
"typescript": "4.8.4",
|
|
437
439
|
"upem": "7.3.0",
|
|
438
440
|
"watskeburt": "0.7.0",
|
|
439
|
-
"wireit": "0.7.
|
|
441
|
+
"wireit": "0.7.2",
|
|
440
442
|
"xml-name-validator": "4.0.0"
|
|
441
443
|
},
|
|
442
444
|
"eslintIgnore": [
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import dotToSvgJs from "viz.js";
|
|
2
2
|
import indentString from "indent-string";
|
|
3
3
|
import wrapAnsi from "wrap-ansi";
|
|
4
|
-
// seems eslint-plugin-import and eslint-plugin-node can't handle exports
|
|
5
|
-
// fields yet. No man overboard not checking against this, because dependency-cruiser
|
|
6
|
-
// will also find them
|
|
7
|
-
|
|
8
4
|
import chalk from "chalk";
|
|
9
5
|
import options from "../../options.mjs";
|
|
10
6
|
import ast2dot from "../dot/index.mjs";
|
|
@@ -12,6 +8,8 @@ import dotToVectorNative from "./dot-to-vector-native.mjs";
|
|
|
12
8
|
|
|
13
9
|
const DEFAULT_INDENT = 2;
|
|
14
10
|
const DOGMATIC_CONSOLE_WIDTH = 78;
|
|
11
|
+
const VIZ_JS_UNSUPPORTED_OUTPUT_FORMATS = ["pdf", "png"];
|
|
12
|
+
|
|
15
13
|
export default (pAST, pOptions) => {
|
|
16
14
|
const lDotProgram = ast2dot(pAST, pOptions);
|
|
17
15
|
const lDotOptions = {
|
|
@@ -22,12 +20,21 @@ export default (pAST, pOptions) => {
|
|
|
22
20
|
if (dotToVectorNative.isAvailable(pOptions)) {
|
|
23
21
|
return dotToVectorNative.convert(lDotProgram, lDotOptions);
|
|
24
22
|
} else {
|
|
23
|
+
if (VIZ_JS_UNSUPPORTED_OUTPUT_FORMATS.includes(lDotOptions.format)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
"GraphViz 'dot' executable not found. Falling back to viz.js.\n\n" +
|
|
26
|
+
"'viz.js' doesn't support the 'pdf' and 'png' output formats. Either " +
|
|
27
|
+
"select a format that it does support or install GraphViz " +
|
|
28
|
+
"(recommended), which has support for both formats.\n"
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
process.stderr.write(
|
|
26
33
|
indentString(
|
|
27
34
|
wrapAnsi(
|
|
28
35
|
`\n${chalk.yellow(
|
|
29
36
|
"warning:"
|
|
30
|
-
)} GraphViz 'dot' executable not found. Falling back to
|
|
37
|
+
)} GraphViz 'dot' executable not found. Falling back to viz.js.\n\n` +
|
|
31
38
|
"On node >=12 this fallback will trigger a warning from the " +
|
|
32
39
|
`node runtime:\n${chalk.italic(
|
|
33
40
|
"Invalid asm.js: Function definition doesn't match use"
|
|
@@ -41,6 +48,7 @@ export default (pAST, pOptions) => {
|
|
|
41
48
|
DEFAULT_INDENT
|
|
42
49
|
)
|
|
43
50
|
);
|
|
51
|
+
|
|
44
52
|
return dotToSvgJs(lDotProgram, lDotOptions);
|
|
45
53
|
}
|
|
46
54
|
};
|
package/src/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "10.1.
|
|
1
|
+
export const version = "10.1.1";
|