state-machine-cat 9.2.0 → 9.2.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 CHANGED
@@ -126,6 +126,12 @@ When you pass the `--desugar` (⨻ experimental) switch, state-machine-cat
126
126
  before rendering, transform some pseudo states into transitions - see
127
127
  [de-sugaring state machines](docs/desugar.md) for details.
128
128
 
129
+ ### Syntax highlighting
130
+
131
+ - For editors supporting tree sitter (like atom): there's [tree-sitter-smcat](https://github.com/sverweij/tree-sitter-smcat)
132
+ - The [atom-state-machine-cat-preview](https://github.com/sverweij/atom-state-machine-cat-preview) plugin includes syntax highlighting for atom as well.
133
+ - For vim there's [ambagasdowa/vim-syntax-smcat](https://github.com/ambagasdowa/vim-syntax-smcat/)
134
+
129
135
  ### State chart XML (SCXML)
130
136
 
131
137
  _state machine cat_ can write **and read** valid core constructs
@@ -76,4 +76,4 @@ var Pr=Object.create;var ue=Object.defineProperty,Or=Object.defineProperties,Cr=
76
76
  `)),t.cond&&(e.cond=t.cond),t["#text"]&&(e.action=K.default.decode(t["#text"]).trim()),t.type&&(e.type=t.type),e}function lo(t){let e={};typeof t=="string"?e.action=K.default.decode(t).trim():Object.assign(e,no(t));let n=Zr(e.event,e.cond,e.action);return n&&(e.label=n),e}function ao(t){return(e,n)=>{let d=(n.target||t.id).split(/\s+/),a=lo(n);return e.concat(d.map(o=>F({from:t.id,to:o},a)))}}function Se(t){return t.filter(e=>Object.prototype.hasOwnProperty.call(e,"transition")).reduce((e,n)=>e.concat((0,ke.default)(n.transition).reduce(ao(n),[])),[])}function kn(t){let e=Ie(t),n={};n.states=e.initial.map(pe("initial")).concat(e.state.map(pe("regular"))).concat(e.parallel.map(pe("parallel"))).concat(e.history.map(pe("history"))).concat(e.final.map(pe("final")));let d=Se(e.initial).concat(Se(e.state)).concat(Se(e.parallel));return d.length>0&&(n.transitions=d),n}function wn(t){let e=t.trim();if(Ne.default.validate(e)===!0){let n=Ne.default.parse(e,{attributeNamePrefix:"",ignoreAttributes:!1,tagValueProcessor:d=>K.default.decode(d),stopNodes:["onentry","onexit","transition"]});return kn((0,$n.default)(n,"scxml",{}))}throw new Error(`That doesn't look like valid xml ...
77
77
  `)}var Pn={$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 Cn=new On.default;function ro(t,e){if(!Cn.validate(t,e))throw new Error(`The provided JSON is not a valid state-machine-cat AST: ${Cn.errorsText()}.
78
78
  `)}var En={getAST(t,e){let n=t;return H.getOptionValue(e,"inputType")==="smcat"?n=xn(t):H.getOptionValue(e,"inputType")==="scxml"?n=wn(t):typeof t=="string"&&(n=JSON.parse(t)),ro(Pn,n),n}};var Ve=B(require("lodash.clonedeep")),De=B(require("lodash.reject"));function oo(t,e,n){return t?`${t}${n}${e}`:e}function so(t,e){let n=V(F(F({},t),e),{from:t.from,to:e.to});return e.action&&(n.action=oo(t.action,e.action,`
79
- `)),(n.event||n.cond||n.action)&&(n.label=je.formatLabel(n.event,n.cond,n.action)),n}function io(t,e,n){return t.reduce((d,a)=>(e.forEach((o,c)=>{o===a.to&&n[o]?d=d.concat(n[o].map(f=>so(a,f))):d=c===0?d.concat(a):d}),d),[])}function An(t,e,n){let d=(0,Ve.default)(t);return d.transitions&&e.length>0&&(d.transitions=io(d.transitions,e,n)),d.states=d.states.map(a=>a.statemachine?V(F({},a),{statemachine:An(a.statemachine,e,n)}):a),d}function _n(t,e){let n=(0,Ve.default)(t);return n.transitions&&(n.transitions=(0,De.default)(n.transitions,d=>e.some(a=>a===d.from||a===d.to))),n.states=(0,De.default)(n.states,d=>e.includes(d.name)).map(d=>d.statemachine?V(F({},d),{statemachine:_n(d.statemachine,e)}):d),n}var Fn=(t,e=["fork","junction","choice"])=>{let n=new D(t),d=n.findStatesByTypes(e).map(c=>c.name),a=d.reduce((c,f)=>(c[f]=n.findTransitionsByFrom(f),c),{}),o=An(t,d,a);return _n(o,d)};var nl=B(require("lodash.has")),ll=B(Hn());var Ln=B(require("lodash.clonedeep"));var xo=[{name:"fontname",value:'"Helvetica"'},{name:"fontsize",value:"12"},{name:"penwidth",value:"2.0"}],$o={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"}]},ko=[{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"}],wo=[{name:"fontname",value:"Helvetica"},{name:"fontsize",value:10}];function Ue(t){return`${t.name}=${t.value}`}var we={buildGraphAttributes:(t,e,n)=>xo.concat($o[t]||[]).concat(jo[e]||[]).concat(n||[]).map(Ue).join(" "),buildNodeAttributes:t=>ko.concat(t||[]).map(Ue).join(" "),buildEdgeAttributes:t=>wo.concat(t||[]).map(Ue).join(" ")};var qn=B(require("lodash.get"));function Po(t){return t.replace(/\\/g,"\\\\").replace(/\n\s*/g,"\\l").replace(/"/g,'\\"').concat("\\l")}function Oo(t){return t.replace(/\\/g,"\\\\").replace(/\n\s*/g," \\l").replace(/"/g,'\\"').concat(" \\l")}function Co(t){let e=t||"top-down";return e==="top-down"||e==="bottom-top"}function Eo(t,e){return e.from===e.to&&t.findStateByName(e.from).statemachine&&e.type!=="internal"}var z={escapeString:Po,escapeLabelString:Oo,isVertical:Co,isCompositeSelf:Eo};function In(t){return e=>e.type===t}function Ge(t){return e=>t.includes(e.type)}function Ao(t){return t.label=t.label||t.name,t}function _o(t){return Object.prototype.hasOwnProperty.call(t,"note")&&(t.noteName=`note_${t.name}`),t}function Fo(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 Ro(t){return t==="activity"?"":`${t}/ `}function To(t){let e=F({},t);return t.actions&&(e.actions=t.actions.map(n=>`${Ro(n.type)}${n.body}`)),e}function Bo(t){return Object.prototype.hasOwnProperty.call(t,"note")&&(t.noteFlattened=t.note.join("")),t}function Mo(t){return e=>{let n=(0,qn.default)((t||[]).find(d=>d.name==="color"),"value");return n&&!e.color&&Ge(["initial","fork","join","junction","forkjoin","final"])(e)&&(e.color=n),e}}function Ho(t){return t.note&&(t.note=t.note.map(z.escapeString)),t}function qo(t){return e=>Ge(["fork","join","forkjoin"])(e)?F({sizingExtras:z.isVertical(t)?"height=0.1":"width=0.1"},e):e}function Io(t){return t.type==="parallel"&&t.statemachine&&t.statemachine.states&&(t.statemachine.states=t.statemachine.states.map(e=>In("regular")(e)?V(F({},e),{parentIsParallel:!0}):e)),t}var R={isType:In,isOneOfTypes:Ge,setLabel:Ao,classifyState:Fo,nameNote:_o,flattenActions:To,flattenNote:Bo,recolor:Mo,escapeStateStrings:Ho,tipForkJoinStates:qo,flagParallelChildren:Io};function No(t){return t.note&&(t.note=t.note.map(z.escapeString)),t.label&&(t.label=z.escapeLabelString(t.label)),t}function So(t){return e=>{let n={};return e.isCompositeSelf&&(z.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"'}),F(F({},e),n)}}function Vo(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 Pe={escapeTransitionStrings:No,addPorts:So,classifyTransition:Vo};var Oe=class{constructor(){this.reset()}reset(){this.COUNTER=0}next(){return++this.COUNTER}nextAsString(){let e=10;return this.next().toString(e)}};var zn=B(Dn());var Un={};function Jo(t){return e=>(Object.prototype.hasOwnProperty.call(e,"statemachine")&&(e.nestedExternalSelfTransitions=t.findExternalSelfTransitions(e.name).map(n=>n.name)),e)}function Gn(t,e,n,d){return t.filter(a=>a.statemachine).forEach(a=>{a.statemachine.states=Gn(a.statemachine.states,e,n,d)}),t.map(R.setLabel).map(R.nameNote).map(R.classifyState).map(R.escapeStateStrings).map(R.flattenNote).map(R.flattenActions).map(R.flagParallelChildren).map(R.tipForkJoinStates(e)).map(R.recolor(n)).map(Jo(d))}function Qo(t){return t.initialStates=t.states.filter(R.isType("initial")),t.regularStates=t.states.filter(e=>R.isType("regular")(e)&&!e.statemachine),t.historyStates=t.states.filter(R.isType("history")),t.deepHistoryStates=t.states.filter(R.isType("deephistory")),t.choiceStates=t.states.filter(R.isType("choice")),t.forkjoinStates=t.states.filter(R.isOneOfTypes(["fork","join","forkjoin"])),t.junctionStates=t.states.filter(R.isType("junction")),t.terminateStates=t.states.filter(R.isType("terminate")),t.finalStates=t.states.filter(R.isType("final")),t.compositeStates=t.states.filter(e=>e.statemachine),t}function Wo(t){return e=>(t.findStateByName(e.from).statemachine&&(e.fromComposite=!0),t.findStateByName(e.to).statemachine&&(e.toComposite=!0),e)}function Yo(t){return e=>{let n={};return z.isCompositeSelf(t,e)&&(t.findStateByName(e.from).hasParent?n={hasParent:!0,isCompositeSelf:!0}:n={isCompositeSelf:!0}),F(F({},e),n)}}function Zo(t){return t.name=`tr_${t.from}_${t.to}_${Un.nextAsString()}`,Boolean(t.note)&&(t.noteName=`note_${t.name}`),t}function Ko(t,e){return t.flattenedTransitions.map(Zo).map(Pe.escapeTransitionStrings).map(Pe.classifyTransition).map(R.flattenNote).map(Wo(t)).map(Yo(t)).map(Pe.addPorts(e))}var Ce=(t,e)=>{e=e||{},Un=new Oe;let n=(0,Ln.default)(t),d=new D(n);return n.transitions=Ko(d,e.direction),n.states=Gn(n.states,e.direction,e.dotNodeAttrs,d),n=Qo(n),n.graphAttributes=we.buildGraphAttributes(H.getOptionValue(e,"engine"),H.getOptionValue(e,"direction"),e.dotGraphAttrs),n.nodeAttributes=we.buildNodeAttributes(e.dotNodeAttrs),n.edgeAttributes=we.buildEdgeAttributes(e.dotEdgeAttrs),(0,zn.default)(n)};var Xn=B(require("viz.js"));var es={oldsvg:"svg",oldps2:"ps2",oldeps:"eps"},Qe=(t,e)=>(0,Xn.default)(Ce(t,e),{engine:H.getOptionValue(e,"engine"),format:es[H.getOptionValue(e,"outputType")]||"svg"});var ts=/[\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,ns=/[-|.|0-9|\u00B7|\u0300-\u036F|\u203F-\u2040]/g;function Jn(t){return t.replace(ts,"_")}function ls(t){let e=Jn(t);return e.match(ns)&&(e=`_${t}`),e}var Ee=t=>(t=t||"",t.length===0?"__empty":ls(t[0]).concat(Jn(t.slice(1))));var as=/[\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,rs=/[.]/g;function Qn(t){return t.replace(as,"_")}function os(t){let e=Qn(t);return e.match(rs)&&(e=`_${t}`),e}function ss(t){return t=t.replace(/\s+/g," ").trim(),os(t[0]).concat(Qn(t.slice(1)))}var Wn=t=>(t=t||"",t.length===0?"empty":t.split(/[\n\r]+/).filter(e=>e.length>0).map(ss).join(" "));var is={regular:"state",initial:"initial",final:"final",terminate:"final",parallel:"parallel",history:"history",deephistory:"history"};function cs(t){return is[t]||"state"}function us(t){let e={target:Ee(t.to)};return Boolean(t.event)&&(e.event=Wn(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 fs(t,e){return t.filter(n=>n.type===e).map(n=>n.body)}function We(t,e,n,d){let a=fs(n,d);a.length>0&&(t[e]=(t[e]||[]).concat(a))}function ms(t,e){Boolean(e.actions)&&(We(t,"onentries",e.actions,"entry"),We(t,"onentries",e.actions,"activity"),We(t,"onexits",e.actions,"exit"))}function ps(t,e,n){let d=n.filter(a=>a.from===e.name).map(us);d.length>0&&(t.transitions=d)}function ds(t,e,n){if(Boolean(e.statemachine)){let d=ae(e.statemachine,null,n);t.states=(t.states||[]).concat(d.states),d.initial&&(t.initial=d.initial)}}function hs(t){return t=t||[],e=>{let n={kind:cs(e.type),id:Ee(e.name)};return e.type==="deephistory"&&(n.type="deep"),ms(n,e),ps(n,e,t),ds(n,e,t),n}}function gs(t){let e=null,n=t.states.filter(d=>d.type==="initial");return n.length>0&&(e=n[0].name),e}function ys(t,e){let n=e;if(e&&t.transitions){let d=t.transitions.filter(a=>a.from===e);d.length>0&&!d[0].action&&(n=d[0].to)}return n}function ae(t,e,n){let d=gs(t),a=ys(t,d),o={states:t.states.filter(c=>a&&a!==d?c.type!=="initial":!0).map(hs(n||new D(t).flattenedTransitions))};return a&&(o.initial=Ee(a)),o}var tl=B(el());function et(t){return(0,tl.default)(ae(t))}function tt(t){let e={smcat:ll.default,dot:Ce,svg:Qe,oldsvg:Qe,scjson:ae,scxml:et};return(0,nl.default)(e,t)?e[t]:n=>n}var al="9.2.0";function rl(t,e){let n=En.getAST(t,e),d=H.getOptionValue(e,"desugar");return tt(H.getOptionValue(e,"outputType"))(d?Fn(n):n,e)}var ol=al;function sl(){return H.getAllowedValues()}var js={render:rl,version:ol,getAllowedValues:sl};
79
+ `)),(n.event||n.cond||n.action)&&(n.label=je.formatLabel(n.event,n.cond,n.action)),n}function io(t,e,n){return t.reduce((d,a)=>(e.forEach((o,c)=>{o===a.to&&n[o]?d=d.concat(n[o].map(f=>so(a,f))):d=c===0?d.concat(a):d}),d),[])}function An(t,e,n){let d=(0,Ve.default)(t);return d.transitions&&e.length>0&&(d.transitions=io(d.transitions,e,n)),d.states=d.states.map(a=>a.statemachine?V(F({},a),{statemachine:An(a.statemachine,e,n)}):a),d}function _n(t,e){let n=(0,Ve.default)(t);return n.transitions&&(n.transitions=(0,De.default)(n.transitions,d=>e.some(a=>a===d.from||a===d.to))),n.states=(0,De.default)(n.states,d=>e.includes(d.name)).map(d=>d.statemachine?V(F({},d),{statemachine:_n(d.statemachine,e)}):d),n}var Fn=(t,e=["fork","junction","choice"])=>{let n=new D(t),d=n.findStatesByTypes(e).map(c=>c.name),a=d.reduce((c,f)=>(c[f]=n.findTransitionsByFrom(f),c),{}),o=An(t,d,a);return _n(o,d)};var nl=B(require("lodash.has")),ll=B(Hn());var Ln=B(require("lodash.clonedeep"));var xo=[{name:"fontname",value:'"Helvetica"'},{name:"fontsize",value:"12"},{name:"penwidth",value:"2.0"}],$o={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"}]},ko=[{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"}],wo=[{name:"fontname",value:"Helvetica"},{name:"fontsize",value:10}];function Ue(t){return`${t.name}=${t.value}`}var we={buildGraphAttributes:(t,e,n)=>xo.concat($o[t]||[]).concat(jo[e]||[]).concat(n||[]).map(Ue).join(" "),buildNodeAttributes:t=>ko.concat(t||[]).map(Ue).join(" "),buildEdgeAttributes:t=>wo.concat(t||[]).map(Ue).join(" ")};var qn=B(require("lodash.get"));function Po(t){return t.replace(/\\/g,"\\\\").replace(/\n\s*/g,"\\l").replace(/"/g,'\\"').concat("\\l")}function Oo(t){return t.replace(/\\/g,"\\\\").replace(/\n\s*/g," \\l").replace(/"/g,'\\"').concat(" \\l")}function Co(t){let e=t||"top-down";return e==="top-down"||e==="bottom-top"}function Eo(t,e){return e.from===e.to&&t.findStateByName(e.from).statemachine&&e.type!=="internal"}var z={escapeString:Po,escapeLabelString:Oo,isVertical:Co,isCompositeSelf:Eo};function In(t){return e=>e.type===t}function Ge(t){return e=>t.includes(e.type)}function Ao(t){return t.label=t.label||t.name,t}function _o(t){return Object.prototype.hasOwnProperty.call(t,"note")&&(t.noteName=`note_${t.name}`),t}function Fo(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 Ro(t){return t==="activity"?"":`${t}/ `}function To(t){let e=F({},t);return t.actions&&(e.actions=t.actions.map(n=>`${Ro(n.type)}${n.body}`)),e}function Bo(t){return Object.prototype.hasOwnProperty.call(t,"note")&&(t.noteFlattened=t.note.join("")),t}function Mo(t){return e=>{let n=(0,qn.default)((t||[]).find(d=>d.name==="color"),"value");return n&&!e.color&&Ge(["initial","fork","join","junction","forkjoin","final"])(e)&&(e.color=n),e}}function Ho(t){return t.note&&(t.note=t.note.map(z.escapeString)),t}function qo(t){return e=>Ge(["fork","join","forkjoin"])(e)?F({sizingExtras:z.isVertical(t)?"height=0.1":"width=0.1"},e):e}function Io(t){return t.type==="parallel"&&t.statemachine&&t.statemachine.states&&(t.statemachine.states=t.statemachine.states.map(e=>In("regular")(e)?V(F({},e),{parentIsParallel:!0}):e)),t}var R={isType:In,isOneOfTypes:Ge,setLabel:Ao,classifyState:Fo,nameNote:_o,flattenActions:To,flattenNote:Bo,recolor:Mo,escapeStateStrings:Ho,tipForkJoinStates:qo,flagParallelChildren:Io};function No(t){return t.note&&(t.note=t.note.map(z.escapeString)),t.label&&(t.label=z.escapeLabelString(t.label)),t}function So(t){return e=>{let n={};return e.isCompositeSelf&&(z.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"'}),F(F({},e),n)}}function Vo(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 Pe={escapeTransitionStrings:No,addPorts:So,classifyTransition:Vo};var Oe=class{constructor(){this.reset()}reset(){this.COUNTER=0}next(){return++this.COUNTER}nextAsString(){let e=10;return this.next().toString(e)}};var zn=B(Dn());var Un={};function Jo(t){return e=>(Object.prototype.hasOwnProperty.call(e,"statemachine")&&(e.nestedExternalSelfTransitions=t.findExternalSelfTransitions(e.name).map(n=>n.name)),e)}function Gn(t,e,n,d){return t.filter(a=>a.statemachine).forEach(a=>{a.statemachine.states=Gn(a.statemachine.states,e,n,d)}),t.map(R.setLabel).map(R.nameNote).map(R.classifyState).map(R.escapeStateStrings).map(R.flattenNote).map(R.flattenActions).map(R.flagParallelChildren).map(R.tipForkJoinStates(e)).map(R.recolor(n)).map(Jo(d))}function Qo(t){return t.initialStates=t.states.filter(R.isType("initial")),t.regularStates=t.states.filter(e=>R.isType("regular")(e)&&!e.statemachine),t.historyStates=t.states.filter(R.isType("history")),t.deepHistoryStates=t.states.filter(R.isType("deephistory")),t.choiceStates=t.states.filter(R.isType("choice")),t.forkjoinStates=t.states.filter(R.isOneOfTypes(["fork","join","forkjoin"])),t.junctionStates=t.states.filter(R.isType("junction")),t.terminateStates=t.states.filter(R.isType("terminate")),t.finalStates=t.states.filter(R.isType("final")),t.compositeStates=t.states.filter(e=>e.statemachine),t}function Wo(t){return e=>(t.findStateByName(e.from).statemachine&&(e.fromComposite=!0),t.findStateByName(e.to).statemachine&&(e.toComposite=!0),e)}function Yo(t){return e=>{let n={};return z.isCompositeSelf(t,e)&&(t.findStateByName(e.from).hasParent?n={hasParent:!0,isCompositeSelf:!0}:n={isCompositeSelf:!0}),F(F({},e),n)}}function Zo(t){return t.name=`tr_${t.from}_${t.to}_${Un.nextAsString()}`,Boolean(t.note)&&(t.noteName=`note_${t.name}`),t}function Ko(t,e){return t.flattenedTransitions.map(Zo).map(Pe.escapeTransitionStrings).map(Pe.classifyTransition).map(R.flattenNote).map(Wo(t)).map(Yo(t)).map(Pe.addPorts(e))}var Ce=(t,e)=>{e=e||{},Un=new Oe;let n=(0,Ln.default)(t),d=new D(n);return n.transitions=Ko(d,e.direction),n.states=Gn(n.states,e.direction,e.dotNodeAttrs,d),n=Qo(n),n.graphAttributes=we.buildGraphAttributes(H.getOptionValue(e,"engine"),H.getOptionValue(e,"direction"),e.dotGraphAttrs),n.nodeAttributes=we.buildNodeAttributes(e.dotNodeAttrs),n.edgeAttributes=we.buildEdgeAttributes(e.dotEdgeAttrs),(0,zn.default)(n)};var Xn=B(require("viz.js"));var es={oldsvg:"svg",oldps2:"ps2",oldeps:"eps"},Qe=(t,e)=>(0,Xn.default)(Ce(t,e),{engine:H.getOptionValue(e,"engine"),format:es[H.getOptionValue(e,"outputType")]||"svg"});var ts=/[\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,ns=/[-|.|0-9|\u00B7|\u0300-\u036F|\u203F-\u2040]/g;function Jn(t){return t.replace(ts,"_")}function ls(t){let e=Jn(t);return e.match(ns)&&(e=`_${t}`),e}var Ee=t=>(t=t||"",t.length===0?"__empty":ls(t[0]).concat(Jn(t.slice(1))));var as=/[\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,rs=/[.]/g;function Qn(t){return t.replace(as,"_")}function os(t){let e=Qn(t);return e.match(rs)&&(e=`_${t}`),e}function ss(t){return t=t.replace(/\s+/g," ").trim(),os(t[0]).concat(Qn(t.slice(1)))}var Wn=t=>(t=t||"",t.length===0?"empty":t.split(/[\n\r]+/).filter(e=>e.length>0).map(ss).join(" "));var is={regular:"state",initial:"initial",final:"final",terminate:"final",parallel:"parallel",history:"history",deephistory:"history"};function cs(t){return is[t]||"state"}function us(t){let e={target:Ee(t.to)};return Boolean(t.event)&&(e.event=Wn(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 fs(t,e){return t.filter(n=>n.type===e).map(n=>n.body)}function We(t,e,n,d){let a=fs(n,d);a.length>0&&(t[e]=(t[e]||[]).concat(a))}function ms(t,e){Boolean(e.actions)&&(We(t,"onentries",e.actions,"entry"),We(t,"onentries",e.actions,"activity"),We(t,"onexits",e.actions,"exit"))}function ps(t,e,n){let d=n.filter(a=>a.from===e.name).map(us);d.length>0&&(t.transitions=d)}function ds(t,e,n){if(Boolean(e.statemachine)){let d=ae(e.statemachine,null,n);t.states=(t.states||[]).concat(d.states),d.initial&&(t.initial=d.initial)}}function hs(t){return t=t||[],e=>{let n={kind:cs(e.type),id:Ee(e.name)};return e.type==="deephistory"&&(n.type="deep"),ms(n,e),ps(n,e,t),ds(n,e,t),n}}function gs(t){let e=null,n=t.states.filter(d=>d.type==="initial");return n.length>0&&(e=n[0].name),e}function ys(t,e){let n=e;if(e&&t.transitions){let d=t.transitions.filter(a=>a.from===e);d.length>0&&!d[0].action&&(n=d[0].to)}return n}function ae(t,e,n){let d=gs(t),a=ys(t,d),o={states:t.states.filter(c=>a&&a!==d?c.type!=="initial":!0).map(hs(n||new D(t).flattenedTransitions))};return a&&(o.initial=Ee(a)),o}var tl=B(el());function et(t){return(0,tl.default)(ae(t))}function tt(t){let e={smcat:ll.default,dot:Ce,svg:Qe,oldsvg:Qe,scjson:ae,scxml:et};return(0,nl.default)(e,t)?e[t]:n=>n}var al="9.2.1";function rl(t,e){let n=En.getAST(t,e),d=H.getOptionValue(e,"desugar");return tt(H.getOptionValue(e,"outputType"))(d?Fn(n):n,e)}var ol=al;function sl(){return H.getAllowedValues()}var js={render:rl,version:ol,getAllowedValues:sl};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-machine-cat",
3
- "version": "9.2.0",
3
+ "version": "9.2.1",
4
4
  "description": "write beautiful state charts",
5
5
  "main": "./dist/commonjs/index.js",
6
6
  "module": "./src/index.mjs",
@@ -90,6 +90,11 @@
90
90
  "policy": "wanted",
91
91
  "because": "some plugins are not compatible with eslint 8 yet"
92
92
  },
93
+ {
94
+ "package": "fast-xml-parser",
95
+ "policy": "wanted",
96
+ "because": "fast-xml-parser 4 is in beta (while using the 'latest' tag) and we prefer non-beta"
97
+ },
93
98
  {
94
99
  "package": "husky",
95
100
  "policy": "pin",
@@ -121,10 +126,10 @@
121
126
  "state-machine-cat": "bin/smcat.mjs"
122
127
  },
123
128
  "dependencies": {
124
- "ajv": "8.6.3",
125
- "chalk": "4.1.2",
126
- "commander": "8.2.0",
127
- "fast-xml-parser": "3.20.3",
129
+ "ajv": "8.8.2",
130
+ "chalk": "5.0.0",
131
+ "commander": "8.3.0",
132
+ "fast-xml-parser": "3.21.1",
128
133
  "get-stream": "6.0.1",
129
134
  "handlebars": "4.7.7",
130
135
  "he": "1.2.0",
@@ -139,32 +144,32 @@
139
144
  "wrap-ansi": "8.0.1"
140
145
  },
141
146
  "devDependencies": {
142
- "@typescript-eslint/eslint-plugin": "5.0.0",
143
- "@typescript-eslint/parser": "5.0.0",
147
+ "@typescript-eslint/eslint-plugin": "5.4.0",
148
+ "@typescript-eslint/parser": "5.4.0",
144
149
  "c8": "7.10.0",
145
150
  "chai": "4.3.4",
146
151
  "chai-as-promised": "7.1.1",
147
152
  "chai-json-schema": "1.5.1",
148
153
  "chai-xml": "0.4.0",
149
- "dependency-cruiser": "10.4.0",
150
- "esbuild": "0.13.4",
154
+ "dependency-cruiser": "11.0.0",
155
+ "esbuild": "0.14.0",
151
156
  "eslint": "^7.32.0",
152
157
  "eslint-config-moving-meadow": "2.0.9",
153
158
  "eslint-config-prettier": "8.3.0",
154
- "eslint-plugin-budapestian": "2.3.0",
155
- "eslint-plugin-import": "2.25.1",
159
+ "eslint-plugin-budapestian": "3.0.1",
160
+ "eslint-plugin-import": "2.25.3",
156
161
  "eslint-plugin-mocha": "9.0.0",
157
162
  "eslint-plugin-node": "11.1.0",
158
163
  "eslint-plugin-security": "1.4.0",
159
- "eslint-plugin-unicorn": "37.0.1",
164
+ "eslint-plugin-unicorn": "39.0.0",
160
165
  "husky": "4.3.0",
161
- "lint-staged": "11.2.3",
162
- "mocha": "9.1.2",
166
+ "lint-staged": "12.1.2",
167
+ "mocha": "9.1.3",
163
168
  "npm-run-all": "4.1.5",
164
169
  "peggy": "1.2.0",
165
- "prettier": "^2.4.1",
170
+ "prettier": "^2.5.0",
166
171
  "query-string": "7.0.1",
167
- "typescript": "4.4.3",
172
+ "typescript": "4.5.2",
168
173
  "upem": "^7.0.0",
169
174
  "xml-name-validator": "4.0.0"
170
175
  },
@@ -1,3 +1,7 @@
1
+ // seems eslint-plugin-import and eslint-plugin-node can't handle exports
2
+ // fields yet. No man overboard not checking against this, because dependency-cruiser
3
+ // will also find them
4
+ // eslint-disable-next-line import/no-unresolved, node/no-missing-import
1
5
  import chalk from "chalk";
2
6
  import indentString from "indent-string";
3
7
  import wrapAnsi from "wrap-ansi";
@@ -7,9 +11,9 @@ function wrapAndIndent(pString) {
7
11
  const lDogmaticMaxConsoleWidth = 78;
8
12
  const lDefaultIndent = 2;
9
13
 
10
- const MAX_WIDTH = lDogmaticMaxConsoleWidth - lDefaultIndent;
14
+ const lMaxWidth = lDogmaticMaxConsoleWidth - lDefaultIndent;
11
15
 
12
- return indentString(wrapAnsi(pString, MAX_WIDTH), lDefaultIndent);
16
+ return indentString(wrapAnsi(pString, lMaxWidth), lDefaultIndent);
13
17
  }
14
18
 
15
19
  export default (pDotIsAvailable = dotToVectorNative.isAvailable({})) => {
@@ -1,6 +1,10 @@
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
+ // eslint-disable-next-line import/no-unresolved, node/no-missing-import
4
8
  import chalk from "chalk";
5
9
  import options from "../../options.mjs";
6
10
  import ast2dot from "../dot/index.mjs";
package/src/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "9.2.0";
1
+ export const version = "9.2.1";