{"version":3,"sources":["../src/index.ts","../src/constants/index.ts","../src/sequence/sequenceParser.ts","../src/sequence/errors/sequenceErrors.ts","../src/sequence/types/index.ts","../src/utils/index.ts","../src/state/errors/stateDiagramErrors.ts","../src/state/stateDiagram.ts","../src/state/stateParser.ts","../src/state/errors/stateErrors.ts"],"sourcesContent":["/**\n * @packageDocumentation\n *\n * The `@yantrix/mermaid-parser` package is a parser for Mermaid state diagrams,\n * designed to transform Mermaid state diagrams into a structured format that can be used by the Yantrix framework.\n *\n * It's important to point out that this parser does not process the special Yantrix subsyntax, even though it is written inside notes in Mermaid diagrams.\n * Further processing of the notes is done by the Yantrix parser.\n *\n * It's not encouraged to use this package individually, as it's useful only for processing Yantrix syntax during the creation of automatas\n * together with packages like `automata` and `yantrix-parser` (all of this is included inside of the `core` package).\n *\n *  See also:\n * - [Yantrix diagram syntax](/syntax)\n * - [Yantrix Parser API](/API/yantrix-parser/)\n */\n\nexport * from './constants/index.js';\nexport * from './sequence/sequenceParser.js';\nexport * from './state/stateDiagram.js';\nexport * from './state/stateParser.js';\nexport * from './state/types/index.js';\nexport * from './utils/index.js';\n","export const StartState = '~~~START~~~';\nexport const EndState = '~~~END~~~';\n","import mermaid from 'mermaid';\nimport { BlankInputError, InvalidInputError } from './errors/sequenceErrors.js';\nimport {\n\tarrowTypes,\n\tTActivationsDict,\n\tTActorsArray,\n\tTMessagesDict,\n\tTNotesDict,\n\tTParsedDiagramDict,\n\tTParsedMessagesArray,\n\tTParsedNotesArray,\n\tTParsedOtherElementsArray,\n\tTSeqTypes,\n\tTSequenceMermaidGraphDict,\n} from './types/index.js';\n\n/**\n * @brief Function that parses a diagram;\n * @param diagramText - diagram;\n * @returns Returns parsed diagram dictionary.\n */\nasync function diagramParser(diagramText: string): Promise<TParsedDiagramDict> {\n\tif (diagramText === '') {\n\t\tthrow new BlankInputError();\n\t}\n\ttry {\n\t\tmermaid.mermaidAPI.setConfig({ ...mermaid.mermaidAPI.defaultConfig });\n\t\tawait mermaid.mermaidAPI.initialize();\n\t\tconst diagram = await mermaid.mermaidAPI.getDiagramFromText(\n\t\t\tdiagramText,\n\t\t);\n\n\t\t// @ts-expect-error IMPLEMENTATION BUG\n\t\tconst parsedArray: any = diagram.db.getMessages();\n\n\t\tconst parsedMessages: TParsedMessagesArray = [];\n\n\t\t// @ts-expect-error IMPLEMENTATION BUG\n\t\tconst parsedActors: TActorsArray = diagram.db.getActorKeys();\n\t\tconst parsedNotes: TParsedNotesArray = [];\n\t\tconst parsedOtherElements: TParsedOtherElementsArray = [];\n\n\t\tfor (let i = 0; i < parsedArray.length; i++) {\n\t\t\tif (arrowTypes.includes(parsedArray[i].type)) {\n\t\t\t\tparsedMessages.push(parsedArray[i]);\n\t\t\t} else if (parsedArray[i].type === TSeqTypes.Note) {\n\t\t\t\tparsedNotes.push(parsedArray[i]);\n\t\t\t} else {\n\t\t\t\tparsedOtherElements.push(parsedArray[i]);\n\t\t\t}\n\t\t}\n\n\t\tconst parsedActivations: TActivationsDict = getActivations(\n\t\t\tparsedArray,\n\t\t\tparsedActors,\n\t\t);\n\n\t\tconst parsedDiagram: TParsedDiagramDict = {\n\t\t\tmessages: parsedMessages,\n\t\t\tactors: parsedActors,\n\t\t\tnotes: parsedNotes,\n\t\t\tothers: parsedOtherElements,\n\t\t\tactivations: parsedActivations,\n\t\t};\n\t\treturn parsedDiagram;\n\t} catch (e) {\n\t\tif (e instanceof Error) {\n\t\t\tif (e.name === 'Diagram SequenceDiagram already registered.') {\n\t\t\t\tmermaid.mermaidAPI.reset();\n\t\t\t\treturn diagramParser(diagramText);\n\t\t\t}\n\t\t}\n\n\t\tthrow new InvalidInputError((e as Error).message);\n\t}\n}\n\n/**\n * @brief This function creates a dictionary of messages links;\n * @param parsedMessages - array of sequence messages;\n * @param actors - array of diagram actors and participants;\n * @returns Returns a dictionary of messages links.\n */\nfunction getMessages(\n\tparsedMessages: TParsedMessagesArray,\n\tactors: TActorsArray,\n): TMessagesDict {\n\tconst messages: TMessagesDict = {};\n\n\tfor (let i = 0; i < actors.length; i++) {\n\t\tconst elementI = actors[i];\n\t\tif (!elementI)\n\t\t\tcontinue;\n\n\t\tmessages[elementI] = {};\n\t\tfor (let j = 0; j < actors.length; j++) {\n\t\t\tconst elementJ = actors[j];\n\t\t\tif (!elementJ)\n\t\t\t\tcontinue;\n\n\t\t\tmessages[elementI][elementJ] = null;\n\t\t}\n\t}\n\n\tfor (let i = 0; i < parsedMessages.length; i++) {\n\t\tconst parsed = parsedMessages[i];\n\t\tif (!parsed)\n\t\t\tcontinue;\n\n\t\tconst arrowMessage = parsed.message;\n\t\tconst from = parsed.from;\n\t\tconst to = parsed.to;\n\n\t\tif (messages[from]?.[to] === null) {\n\t\t\tmessages[from][to] = [arrowMessage];\n\t\t} else {\n\t\t\tmessages[from]?.[to]?.push(arrowMessage);\n\t\t}\n\t}\n\treturn messages;\n}\n\n/**\n * @brief A function that extracts notes from the sequence diagram;\n * @param parsedMessages - array of sequence messages;\n * @param actors - array of diagram actors and participants;\n * @returns Returns a dictionary of notes from the sequence diagram.\n */\nfunction getNotes(\n\tparsedMessages: TParsedMessagesArray,\n\tactors: TActorsArray,\n): TNotesDict {\n\tconst notes: TNotesDict = {};\n\n\tfor (let i = 0; i < actors.length; i++) {\n\t\tconst elementI = actors[i];\n\t\tif (!elementI)\n\t\t\tcontinue;\n\n\t\tnotes[elementI] = null;\n\t}\n\n\tfor (let i = 0; i < parsedMessages.length; i++) {\n\t\tconst parsed = parsedMessages[i];\n\t\tif (!parsed)\n\t\t\tcontinue;\n\n\t\tconst recievedMessage = parsed.message;\n\t\tlet fromIndex = actors.indexOf(parsed.from);\n\t\tconst toIndex = actors.indexOf(parsed.to);\n\n\t\twhile (fromIndex !== toIndex + 1) {\n\t\t\tconst from = actors[fromIndex];\n\t\t\tif (!from)\n\t\t\t\tcontinue;\n\n\t\t\tif (notes[from] === null) {\n\t\t\t\tnotes[from] = [recievedMessage];\n\t\t\t} else {\n\t\t\t\tnotes[from]?.push(recievedMessage);\n\t\t\t}\n\t\t\tfromIndex++;\n\t\t}\n\t}\n\treturn notes;\n}\n\n/**\n * @brief A function that collect messages that are located in the activation interval;\n * @param parsedArray - parsed diagram array;\n * @param actors - array of diagram actors and participants;\n * @returns Returns a dictionary of activation messages from the sequence diagram.\n */\nfunction getActivations(\n\tparsedArray: any,\n\tactors: TActorsArray,\n): TActivationsDict {\n\tconst activate: TActivationsDict = {};\n\tfor (let i = 0; i < actors.length; i++) {\n\t\tconst elementI = actors[i];\n\t\tif (!elementI)\n\t\t\tcontinue;\n\n\t\tactivate[elementI] = [];\n\t}\n\n\tfor (let i = 0; i < parsedArray.length; i++) {\n\t\tif (parsedArray[i].type === TSeqTypes.Activate) {\n\t\t\tconst currentActor: string = parsedArray[i].from;\n\t\t\tactivate[currentActor]?.push([]);\n\t\t\tconst len = activate[currentActor]!.length - 1;\n\t\t\tfor (let j = i - 1; j < parsedArray.length; j++) {\n\t\t\t\tif (arrowTypes.includes(parsedArray[j].type)\n\t\t\t\t\t&& parsedArray[j].from === currentActor) {\n\t\t\t\t\tactivate[currentActor]![len]?.push(parsedArray[j].message);\n\t\t\t\t} else if (parsedArray[j].type === TSeqTypes.Deactivate\n\t\t\t\t\t&& parsedArray[j].from === currentActor) {\n\t\t\t\t\tparsedArray[j].type = -1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn activate;\n}\n/**\n * @brief A function that builds a dictionary with information from the diagram;\n * @param parsedDiagram - a primary diagram dictionary;\n * @returns Returns dictionary with information from the diagram.\n */\nfunction markGraph(\n\tparsedDiagram: TParsedDiagramDict,\n): TSequenceMermaidGraphDict {\n\tconst messagesArray: TParsedMessagesArray = parsedDiagram.messages;\n\tconst actorsArray: TActorsArray = parsedDiagram.actors;\n\tconst notesArray: TParsedNotesArray = parsedDiagram.notes;\n\t// const othersElementsArray: TParsedOtherElementsArray = parsedDiagram['others'];\n\tconst activateDict: TActivationsDict = parsedDiagram.activations;\n\n\tconst mermaidGraph: TSequenceMermaidGraphDict = {\n\t\tmessages: getMessages(messagesArray, actorsArray),\n\t\tnotes: getNotes(notesArray, actorsArray),\n\t\tactors: actorsArray,\n\t\tactivations: activateDict,\n\t};\n\n\treturn mermaidGraph;\n}\n\n/**\n * The main function that collects all the information from the Mermaid diagram and transforms it\n * into a form appropriate for processing with other parts of the Yantrix toolkit.\n *\n * @param diagramText - Text of the diagram written in accordance with Mermaid syntax.\n * @returns Dictionary that contains information from the diagram for further processing.\n */\nexport async function parseSequenceDiagram(\n\tdiagramText: string,\n): Promise<TSequenceMermaidGraphDict> {\n\tconst parsedDiagram: TParsedDiagramDict = await diagramParser(diagramText);\n\tconst sequenceMermaidGraph: TSequenceMermaidGraphDict = markGraph(\n\t\tparsedDiagram,\n\t);\n\n\treturn sequenceMermaidGraph;\n}\n","export class InvalidInputError extends Error {\n\tconstructor(messages?: string) {\n\t\tsuper(`Invalid diagram input: ${messages}`);\n\t}\n}\n\nexport class BlankInputError extends Error {\n\tconstructor(messages?: string) {\n\t\tsuper(`the diagram is empty. ${messages}`);\n\t}\n}\n","/**\n * Dict type for notes;\n * https://mermaid.js.org/syntax/sequenceDiagram.html#notes\n */\nexport type TNotesDict = Record<string, null | string[]>;\n\n/**\n * Array type for actors;\n * https://mermaid.js.org/syntax/sequenceDiagram.html#actors\n */\nexport type TActorsArray = string[];\n\n/**\n * Dict type for messages;\n * https://mermaid.js.org/syntax/sequenceDiagram.html#messages\n */\nexport type TMessagesDict = Record<string, Record<string, null | string[]>>;\n\n/**\n * Dict type for messages that are located in the activation interval;\n * https://mermaid.js.org/syntax/sequenceDiagram.html#activations\n */\nexport type TActivationsDict = Record<string, string[][]>;\n\n/**\n * Dict type for mermaid parsed messages. Parser from mermaid library;\n * https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid/src/diagrams/sequence\n */\ntype TParsedMessagesDict = {\n\tfrom: string;\n\tmessage: string;\n\tto: string;\n\ttype: number;\n\twrap: boolean;\n};\n\n/**\n * Dict type for mermaid parsed other elements (other, then messages and notes). Parser from mermaid library;\n * https://github.com/mermaid-js/mermaid/tree/develop/packages/mermaid/src/diagrams/sequence\n */\ntype TParsedOtherElementsDict = {\n\tfrom: string | undefined;\n\tmessage: string | undefined;\n\tto: string | undefined;\n\ttype: number;\n\twrap: boolean;\n};\n\n// Array type that is responsible for collecting dictionaries of parsed messages;\nexport type TParsedMessagesArray = TParsedMessagesDict[];\n\n// Array type for dictionaries of parsed notes;\nexport type TParsedNotesArray = TParsedMessagesDict[];\n\n// Array type for dictionaries of parsed other elements;\nexport type TParsedOtherElementsArray = TParsedOtherElementsDict[];\n\n/**\n * Dict type that is responsible for collecting parsed messages, actors, notes, other elements\n * and activated messages. Parser from mermaid library;\n */\nexport type TParsedDiagramDict = {\n\tmessages: TParsedMessagesArray;\n\tactors: TActorsArray;\n\tnotes: TParsedNotesArray;\n\tothers: TParsedOtherElementsArray;\n\tactivations: TActivationsDict;\n};\n\n// Dict type for messages, actors, notes and activated messages;\nexport type TSequenceMermaidGraphDict = {\n\tmessages: TMessagesDict;\n\tnotes: TNotesDict;\n\tactors: TActorsArray;\n\tactivations: TActivationsDict;\n};\n\n// Enumeration with types from the mermaid parser;\nexport enum TSeqTypes {\n\tNote = 2,\n\tActivate = 17,\n\tDeactivate = 18,\n}\n\n// Enumeration with arrow types from the mermaid parser;\nexport const arrowTypes = [0, 1, 3, 4, 5, 6, 24, 25];\n","import { EndState, StartState } from '../constants';\n\nconst validStateRegex = /^[a-z][\\w-]{0,254}$/i;\nconst validFunctionRegex = /^[a-z]\\w{0,254}\\([\\w, $#]+\\)$/i;\nconst actionParamsRegex = /\\(([\\w=, $#]+)\\)/;\nconst expressionValueRegex = /[$#]\\w{0,254}(=\\w+)?/;\nexport function isValidStateId(state: string): boolean {\n\treturn state === StartState || state === EndState || validStateRegex.test(state);\n}\nexport function isValidInternalId(str: string): boolean {\n\treturn (\n\t\tstr.split(', ').length === 3\n\t\t&& str[0] !== undefined && str[1] !== undefined && str[2] !== undefined\n\t\t&& isValidStateId(str[0]) && isValidStateId(str[1])\n\t);\n}\nfunction isValidFunctionId(str: string): boolean {\n\treturn validFunctionRegex.test(str);\n}\n\nexport function compareActionChains(a: string[], b: string[]) {\n\tconst len = Math.max(a.length, b.length); // Compare up to the longest array's length\n\n\tfor (let i = 0; i < len; i++) {\n\t\tconst aVal = a[i] || ''; // Use empty string if array is shorter\n\t\tconst bVal = b[i] || '';\n\n\t\tconst aIsFunc = isValidFunctionId(aVal);\n\t\tconst bIsFunc = isValidFunctionId(bVal);\n\t\tconst aIsList = isValidInternalId(aVal);\n\t\tconst bIsList = isValidInternalId(bVal);\n\n\t\t// 1. Sort function-like strings first\n\t\tif (aIsFunc && !bIsFunc) return -1;\n\t\tif (!aIsFunc && bIsFunc) return 1;\n\n\t\t// 2. Sort list-like strings last\n\t\tif (aIsList && !bIsList) return 1;\n\t\tif (!aIsList && bIsList) return -1;\n\n\t\t// 3. Lexicographical comparison if both are the same type\n\t\tconst comparison = aVal.localeCompare(bVal);\n\t\tif (comparison !== 0) return comparison;\n\t}\n\n\treturn 0; // If all elements are the same\n}\n\nexport function extractActionId(str: string | undefined) {\n\tif (!str) return '';\n\telse return str.split('\\(')[0]!.trim();\n}\n\nexport function extractActionParams(str: string | undefined) {\n\tif (!str) return null;\n\n\tconst match = str.match(actionParamsRegex);\n\tif (match && match[1]) {\n\t\treturn match[1];\n\t} else {\n\t\treturn null;\n\t}\n}\n\nexport function hasExpressionValues(str: string | undefined) {\n\tif (!str) return false;\n\n\tconst match = str.match(expressionValueRegex);\n\tif (match && match.length > 0) return true;\n\telse return false;\n}\n","export class ChoiceCycleError extends Error {\n\tconstructor(messages?: string) {\n\t\tsuper(`Link to itself from the choice side. ${messages}`);\n\t}\n}\n","import { compareActionChains, isValidInternalId, isValidStateId } from '../utils/index.js';\nimport { ChoiceCycleError } from './errors/stateDiagramErrors.js';\nimport { TActionsStructure, TActionWithParams, TStateDiagramStructure } from './types/index.js';\n\nimport {\n\tTActionChain,\n\tTActionChainParams,\n\tTActionPathArray,\n\tTChoicesId,\n\tTDiagramAction,\n\tTDiagramActionChains,\n\tTDiagramStatesArray,\n\tTDiagramTransitions,\n\tTFromChoice,\n\tTFromChoiceArray,\n\tTNotesId,\n\tTStateDiagramMatrix,\n} from './types/stateDiagramTypes.js';\n\n/**\n * @brief A function collect notes from state;\n * @param stateDiagramStructure - base state diagram;\n * @returns Returns dict with notes.\n */\nfunction getNotesId(stateDiagramStructure: TStateDiagramStructure): TNotesId {\n\tconst notes = stateDiagramStructure.notes;\n\tconst notesId: TNotesId = {};\n\n\tfor (let i = 0; i < notes.length; i++) {\n\t\tconst note = notes[i];\n\t\tif (!note)\n\t\t\tcontinue;\n\n\t\tif (!Object.keys(notesId).includes(note.over)) {\n\t\t\tnotesId[note.over] = [];\n\t\t}\n\t\tconst notesArray: string[] = [];\n\t\tfor (let j = 0; j < note.text.length; j++) {\n\t\t\tconst noteArray = note.text[j]?.trim().split('\\n');\n\t\t\tif (!noteArray)\n\t\t\t\tcontinue;\n\n\t\t\tfor (let k = 0; k < noteArray.length; k++) {\n\t\t\t\tconst note = noteArray[k];\n\t\t\t\tif (!note)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tnotesArray.push(note.trim());\n\t\t\t}\n\t\t}\n\t\tnotesId[note.over]?.push(notesArray);\n\t}\n\treturn notesId;\n}\n\n/**\n * @brief A function that collect choices id;\n * @param stateDiagramStructure - base state diagram;\n * @returns Returns array with choices.\n */\nfunction getChoicesId(stateDiagramStructure: TStateDiagramStructure): TChoicesId {\n\tconst choices = stateDiagramStructure.choices;\n\tconst choicesId: TChoicesId = [];\n\tfor (let i = 0; i < choices.length; i++) {\n\t\tconst choice = choices[i];\n\t\tif (!choice)\n\t\t\tcontinue;\n\n\t\tchoicesId.push(choice.id);\n\t}\n\treturn choicesId;\n}\n\n/**\n * @brief A function add notes for choices;\n * @param notesId - dict with notes;\n * @param choice - choice state from which notes are collected;\n * @param choiceAction - the action in which notes are recorded;\n * @param fromChoices - actions that happens before choice;\n * @returns Returns updated fromChoices.\n */\nfunction addNotesForChoices(\n\tnotesId: TNotesId,\n\tchoice: string,\n\tchoiceAction: TFromChoice,\n\tfromChoices: TFromChoiceArray,\n): TFromChoiceArray {\n\tif (!Object.keys(notesId).includes(choice)) {\n\t\tnotesId[choice] = [['']];\n\t}\n\tfor (let j = 0; j < notesId[choice]!.length; j++) {\n\t\tconst noteId = notesId[choice]?.[j];\n\t\tif (!noteId)\n\t\t\tcontinue;\n\n\t\tchoiceAction.actionsPath[0]?.note.push(noteId);\n\t}\n\tfromChoices.push(choiceAction);\n\n\treturn fromChoices;\n}\n\n/**\n * @brief A function collect actions that happens before choice;\n * @param actions - actions from stateDiagramStructure;\n * @param choicesId - array with choices;\n * @param notesId - dict with notes;\n * @returns Returns from choices array.\n */\nfunction getFromChoices(actions: TActionsStructure, choicesId: TChoicesId, notesId: TNotesId): TFromChoiceArray {\n\tlet fromChoices: TFromChoiceArray = [];\n\tfor (let i = 0; i < actions.length; i++) {\n\t\tconst choice = actions[i]?.to;\n\t\tif (!choice)\n\t\t\tcontinue;\n\n\t\tif (choicesId.includes(choice)) {\n\t\t\tconst from = actions[i]?.from;\n\t\t\tif (!from)\n\t\t\t\tcontinue;\n\n\t\t\tconst actionId = actions[i]?.id;\n\t\t\tif (!actionId)\n\t\t\t\tcontinue;\n\n\t\t\tconst choiceAction: TFromChoice = {\n\t\t\t\tchoice,\n\t\t\t\tfrom,\n\t\t\t\tactionsPath: [\n\t\t\t\t\t{\n\t\t\t\t\t\taction: [actionId],\n\t\t\t\t\t\tnote: [],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t\tfromChoices = addNotesForChoices(notesId, choice, choiceAction, fromChoices);\n\t\t}\n\t}\n\treturn fromChoices;\n}\n\n/**\n * @brief A function that concat two action pathes;\n * @param fromChoice - first action path;\n * @param toChoice - second action path;\n * @returns Returns action path after concatenation.\n */\nfunction concatActionPathes(fromChoice: TActionPathArray, toChoice: TActionPathArray): TActionPathArray {\n\tconst actionPathArray: TActionPathArray = [];\n\tfor (let i = 0; i < fromChoice.length; i++) {\n\t\tfor (let j = 0; j < toChoice.length; j++) {\n\t\t\tconst toChoiceAction = toChoice[j]?.action;\n\t\t\tif (!toChoiceAction)\n\t\t\t\tcontinue;\n\n\t\t\tconst toChoiceNote = toChoice[j]?.note;\n\t\t\tif (!toChoiceNote)\n\t\t\t\tcontinue;\n\n\t\t\tconst action = fromChoice[i]?.action.concat(toChoiceAction);\n\t\t\tconst note = fromChoice[i]?.note.concat(toChoiceNote);\n\t\t\tif (!action || !note)\n\t\t\t\tcontinue;\n\n\t\t\tactionPathArray.push({ action, note });\n\t\t}\n\t}\n\treturn actionPathArray;\n}\n\n/**\n * @brief A function unravel choice;\n * @param choicesId - array with choices;\n * @param fromChoices - array with states, where the action is coming from;\n * @param from - state, where the action is coming from;\n * @param to - state, where the action is coming to;\n * @param transitions - matrix of transitions;\n * @returns Returns updated transitions.\n */\nfunction unravelChoices(\n\tchoicesId: TChoicesId,\n\tfromChoices: TFromChoiceArray,\n\tfrom: string,\n\tto: string,\n\tactionPathes: TActionPathArray,\n\ttransitions: TDiagramTransitions,\n): TDiagramTransitions {\n\tif (choicesId.includes(to)) {\n\t\tfromChoices.push({\n\t\t\tchoice: to,\n\t\t\tfrom,\n\t\t\tactionsPath: actionPathes,\n\t\t});\n\t} else {\n\t\tconst transitionsFrom = transitions[from];\n\t\tif (!transitionsFrom)\n\t\t\treturn transitions;\n\n\t\tif (!Object.keys(transitionsFrom).includes(to)) {\n\t\t\ttransitionsFrom[to] = {\n\t\t\t\tactionsPath: [],\n\t\t\t};\n\t\t}\n\n\t\tfor (let i = 0; i < actionPathes.length; i++) {\n\t\t\tconst actionPath = actionPathes[i];\n\t\t\tif (!actionPath)\n\t\t\t\tcontinue;\n\n\t\t\ttransitionsFrom[to]?.actionsPath.push(actionPath);\n\t\t}\n\t}\n\n\treturn transitions;\n}\n\n/**\n * @brief A function delete rows of choices;\n * @param transitions - matrix of transitions;\n * @param stateDiagramStructure - base state diagram;\n * @returns Returns updated transitions.\n */\nfunction deleteRowChoices(\n\ttransitions: TDiagramTransitions,\n\tstateDiagramStructure: TStateDiagramStructure,\n): TDiagramTransitions {\n\tconst choices = stateDiagramStructure.choices;\n\tfor (let i = 0; i < choices.length; i++) {\n\t\tconst choicesId = choices[i]?.id;\n\t\tif (choicesId)\n\t\t\tdelete transitions[choicesId];\n\t}\n\n\treturn transitions;\n}\n\n/**\n * @brief A function that unravel choices in transitions;\n * @param transitions - matrix of transitions;\n * @param stateDiagramStructure - base state diagram;\n * @returns Returns updated transitions.\n */\nfunction markChoicesInTransitions(\n\ttransitions: TDiagramTransitions,\n\tstateDiagramStructure: TStateDiagramStructure,\n): TDiagramTransitions {\n\tconst actions = stateDiagramStructure.actions;\n\tconst notesId = getNotesId(stateDiagramStructure);\n\tconst choicesId = getChoicesId(stateDiagramStructure);\n\tconst fromChoices = getFromChoices(actions, choicesId, notesId);\n\n\twhile (fromChoices.length) {\n\t\tconst fromChoice = fromChoices[fromChoices.length - 1];\n\t\tif (!fromChoice)\n\t\t\tcontinue;\n\n\t\tif (\n\t\t\tchoicesId.includes(fromChoice?.from)\n\t\t\t&& choicesId.includes(fromChoice?.choice)\n\t\t\t&& fromChoice?.from === fromChoice?.choice\n\t\t) {\n\t\t\tthrow new ChoiceCycleError(`${fromChoice?.from}-->${fromChoice?.choice}`);\n\t\t}\n\t\tfromChoices.pop();\n\t\tconst { choice, from } = fromChoice;\n\t\tconst toChoice = transitions[choice];\n\t\tif (!toChoice)\n\t\t\tcontinue;\n\n\t\tdelete transitions[from]?.[choice];\n\t\tconst toChoiceKeys = Object.keys(toChoice);\n\t\tfor (let i = 0; i < toChoiceKeys.length; i++) {\n\t\t\tconst to = toChoiceKeys[i];\n\t\t\tif (!to)\n\t\t\t\tcontinue;\n\n\t\t\tconst fromChoicePath = fromChoice?.actionsPath;\n\t\t\tconst toChoicePath = toChoice[to]?.actionsPath;\n\t\t\tif (!fromChoicePath || !toChoicePath)\n\t\t\t\tcontinue;\n\n\t\t\tconst actionPathes: TActionPathArray = concatActionPathes(fromChoicePath, toChoicePath);\n\t\t\ttransitions = unravelChoices(choicesId, fromChoices, from, to, actionPathes, transitions);\n\t\t}\n\t}\n\n\treturn deleteRowChoices(transitions, stateDiagramStructure);\n}\n\n/**\n * @brief A function that create matrix of transitions;\n * @param stateDiagramStructure - base state diagram;\n * @returns Returns matrix of transitions.\n */\nfunction getTransitions(stateDiagramStructure: TStateDiagramStructure): TDiagramTransitions {\n\tconst transitions: TDiagramTransitions = {};\n\tconst actions = stateDiagramStructure.actions;\n\n\tfor (let i = 0; i < actions.length; i++) {\n\t\tconst from = actions[i]?.from;\n\t\tconst to = actions[i]?.to;\n\t\tconst actionId = actions[i]?.id;\n\t\tif (!from || !to || !actionId)\n\t\t\tcontinue;\n\n\t\tconst action: TDiagramAction = {\n\t\t\tactionsPath: [],\n\t\t};\n\t\tif (!Object.keys(transitions).includes(from)) {\n\t\t\ttransitions[from] = {};\n\t\t}\n\n\t\tconst transitionsFrom = transitions[from];\n\t\tif (!transitionsFrom)\n\t\t\tcontinue;\n\n\t\tif (!Object.keys(transitionsFrom).includes(to)) {\n\t\t\ttransitions[from]![to] = action;\n\t\t}\n\n\t\ttransitions[from]?.[to]?.actionsPath.push({\n\t\t\taction: [actionId],\n\t\t\tnote: [],\n\t\t});\n\t}\n\n\treturn markChoicesInTransitions(transitions, stateDiagramStructure);\n}\n\n/**\n * @brief This function get actions pathes from matrix of transitions;\n * @param transitions - matrix of transitions;\n * @param stateId - The state for which actions pathes is being sought;\n * @returns Returns actions pathes.\n */\nfunction getActionsPathesForStates(transitions: TDiagramTransitions, stateId: string): TActionPathArray {\n\tconst actionsPath: TActionPathArray = [];\n\tif (!Object.keys(transitions).includes(stateId)) {\n\t\treturn [];\n\t}\n\tconst transitionsTo = transitions[stateId];\n\tif (!transitionsTo)\n\t\treturn [];\n\n\tconst transitionsToKeys = Object.keys(transitionsTo);\n\tfor (let i = 0; i < transitionsToKeys.length; i++) {\n\t\tconst to = transitionsToKeys[i];\n\t\tif (!to)\n\t\t\tcontinue;\n\n\t\tconst actionsPathTo = transitionsTo[to]?.actionsPath;\n\t\tif (!actionsPathTo)\n\t\t\tcontinue;\n\n\t\tfor (let j = 0; j < actionsPathTo.length; j++) {\n\t\t\tconst actionPath = actionsPathTo[j];\n\t\t\tif (!actionPath)\n\t\t\t\tcontinue;\n\n\t\t\tactionsPath.push(actionPath);\n\t\t}\n\t}\n\treturn actionsPath;\n}\n\nconst formattedStartOrEndDict: Record<string, '[*]'> = {\n\t'~~~START~~~': '[*]',\n\t'END_STATE': '[*]',\n} as const;\n\n/**\n * @brief This function get states from transitions and stateDiagramStructure;\n * @param stateDiagramStructure - state diagram structure;\n * @param transitions - matrix of transitions;\n * @returns Returns states.\n */\nfunction getStates(\n\tstateDiagramStructure: TStateDiagramStructure,\n\ttransitions: TDiagramTransitions,\n): TDiagramStatesArray {\n\tconst states: TDiagramStatesArray = [];\n\tconst notesId = getNotesId(stateDiagramStructure);\n\tconst notesIdKeys = Object.keys(notesId);\n\tconst choicesId = getChoicesId(stateDiagramStructure);\n\tfor (let i = 0; i < stateDiagramStructure.states.length; i++) {\n\t\tconst stateId = stateDiagramStructure.states[i]?.id;\n\t\tif (!stateId)\n\t\t\tcontinue;\n\n\t\tif (choicesId.includes(stateId)) {\n\t\t\tcontinue;\n\t\t}\n\t\tlet notes: string[][] = [];\n\n\t\tconst stateIdFormatted = formattedStartOrEndDict[stateId] || stateId;\n\n\t\tif (notesIdKeys.includes(stateIdFormatted)) {\n\t\t\tconst notesIdState = notesId[stateIdFormatted];\n\t\t\tif (!notesIdState)\n\t\t\t\tcontinue;\n\n\t\t\tnotes = notesIdState;\n\t\t}\n\n\t\tconst actionsPath: TActionPathArray = getActionsPathesForStates(transitions, stateId);\n\t\tconst caption = stateDiagramStructure.states[i]?.caption;\n\n\t\tif (!caption)\n\t\t\tcontinue;\n\n\t\tstates.push({\n\t\t\tid: stateId,\n\t\t\tcaption,\n\t\t\tactionsPath,\n\t\t\tnotes,\n\t\t});\n\t}\n\treturn states;\n}\n\n/**\n * @brief Checks if any states in a created structure are not valid;\n * @param states - list of states to check\n * @throw Throws an error if a state has an incorrect format\n */\nfunction checkValidStates(states: TDiagramStatesArray) {\n\tstates.forEach((state) => {\n\t\tconst { id } = state;\n\t\tif (!isValidStateId(id)) {\n\t\t\tthrow new Error(`Incorrect ID: ${id}`);\n\t\t}\n\t});\n}\n\n/*\n\taction chains are sequences of actions to be iterated on and processed when encountering forks.\n\tthis structure binds action paths with the exact state that the automata should transition to,\n\twhen every single segment in the chain resolves to TRUE\n*/\nfunction createActionChainsFromTransitions(stateDiagramStructure: TStateDiagramStructure, transitions: TDiagramTransitions): TDiagramActionChains {\n\tconst chains: TDiagramActionChains = {};\n\tfor (const state in transitions) {\n\t\tconst stateTransitions = transitions[state]!;\n\t\tconst chain: Record<string, TActionChainParams> = {};\n\n\t\tfor (const transition in stateTransitions) {\n\t\t\tconst actions: string[] | undefined = stateTransitions[transition]?.actionsPath[0]?.action;\n\t\t\tif (actions) {\n\t\t\t\tconst actionName = actions[0]!;\n\t\t\t\tconst actionInStructure = stateDiagramStructure.actions.find(a => a.id === actionName) as TActionWithParams;\n\t\t\t\tif (!chain[actionName]) {\n\t\t\t\t\tchain[actionName] = {\n\t\t\t\t\t\tchains: [],\n\t\t\t\t\t\tparams: actionInStructure?.params || null,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tchain[actionName].chains.push({\n\t\t\t\t\tchain: actions.slice(1).map((actionId) => {\n\t\t\t\t\t\tconst actionInStructure = stateDiagramStructure.actions.find(a => a.id === actionId) as TActionWithParams;\n\t\t\t\t\t\tif (actionInStructure && actionInStructure.predicate === true) {\n\t\t\t\t\t\t\treturn `${actionInStructure.id}(${actionInStructure.params})`;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn actionId;\n\t\t\t\t\t}),\n\t\t\t\t\tstate: transition,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tchains[state] = chain;\n\t}\n\treturn chains;\n}\n\n/*\n\tchecking default path for every level of action chain / segment of action path\n\teach level must have not more than 1 default path (i.e its name will be the internal ID instead of action/predicate/etc)\n*/\nfunction checkActionChainsDefaultPathsAndSort(actionChains: TDiagramActionChains) {\n\tfor (const state in actionChains) {\n\t\tconst possibleActions = actionChains[state]!;\n\t\tfor (const action in possibleActions) {\n\t\t\tconst defaultPaths: any = {};\n\t\t\tconst { chains } = possibleActions[action]!;\n\t\t\tfor (const { chain } of chains) {\n\t\t\t\tfor (let i = 0; i < chain.length; i++) {\n\t\t\t\t\tconst path = chain[i]!;\n\t\t\t\t\tif (isValidInternalId(path)) {\n\t\t\t\t\t\tconst nodeId = path.split(', ')[0]!;\n\t\t\t\t\t\tif (defaultPaths[nodeId] !== undefined && defaultPaths[nodeId] !== path) {\n\t\t\t\t\t\t\tthrow new Error(`Duplicate default path encountered: ${path}`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdefaultPaths[nodeId] = path;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst sortedChains = sortActionChains(chains);\n\t\t\tactionChains[state]![action]!.chains = sortedChains;\n\t\t}\n\t}\n}\n\nfunction sortActionChains(actionChains: TActionChain[]) {\n\treturn actionChains.sort((a, b) => compareActionChains(a.chain, b.chain));\n}\n\nfunction validateActions(stateDiagramStructure: TStateDiagramStructure) {\n\tconst actions = stateDiagramStructure.actions;\n\tconst map: Record<string, Set<string>> = {};\n\tfor (const action of actions) {\n\t\tif (!map[action.from]) {\n\t\t\tmap[action.from] = new Set();\n\t\t}\n\n\t\tif (map[action.from]?.has(action.id)) {\n\t\t\tthrow new Error(`Duplicate action ${action.id} identified in state ${action.from}`);\n\t\t} else {\n\t\t\tmap[action.from]?.add(action.id);\n\t\t}\n\t}\n}\n\n/**\n * This function creates a state diagram for Yantrix automata based on the information from a Mermaid diagram\n * @param stateDiagramStructure - State diagram structure;\n * @returns Dictionary of processed state diagram.\n */\nexport async function createStateDiagram(stateDiagramStructure: TStateDiagramStructure): Promise<TStateDiagramMatrix> {\n\tvalidateActions(stateDiagramStructure);\n\tconst transitions = getTransitions(stateDiagramStructure);\n\tconst states = getStates(stateDiagramStructure, transitions);\n\tconst actionChains = createActionChainsFromTransitions(stateDiagramStructure, transitions);\n\tcheckValidStates(states);\n\tcheckActionChainsDefaultPathsAndSort(actionChains);\n\treturn {\n\t\ttransitions,\n\t\tstates,\n\t\tactionChains,\n\t};\n}\n","import mermaid from 'mermaid';\nimport { EndState, StartState } from '../constants/index.js';\nimport { extractActionId, extractActionParams, hasExpressionValues } from '../utils/index.js';\n\nimport { BlankInputError, InvalidInputError } from './errors/stateErrors.js';\nimport {\n\tTActionsStructure,\n\tTActionWithParams,\n\tTChoice,\n\tTChoicesStructure,\n\tTFork,\n\tTForksStructure,\n\tTNote,\n\tTNotesStructure,\n\tTParsedDiagramArray,\n\tTState,\n\tTStateDiagramStructure,\n\tTStatesStructure,\n\tTTransitionsArray,\n} from './types/index.js';\n\n/**\n * @brief Function that parses a diagram;\n * @param diagramText - diagram [string];\n * @returns Returns parsed diagram dictionary.\n */\nasync function diagramParser(diagramText: string): Promise<TParsedDiagramArray> {\n\tdiagramText = diagramText.trim().replaceAll('\\t', '');\n\tif (diagramText === '') {\n\t\tthrow new BlankInputError();\n\t}\n\ttry {\n\t\tmermaid.mermaidAPI.setConfig({\n\t\t\t...mermaid.mermaidAPI.defaultConfig,\n\t\t});\n\t\tawait mermaid.mermaidAPI.initialize();\n\t\tconst diagram = await mermaid.mermaidAPI.getDiagramFromText(diagramText);\n\n\t\t// @ts-expect-error IMPLEMENTATION BUG\n\t\tconst parsedDiagram: TParsedDiagramArray = diagram.db.getRootDoc();\n\n\t\treturn parsedDiagram;\n\t} catch (e) {\n\t\tif (e instanceof Error) {\n\t\t\tif (e.message === 'Diagram stateDiagram already registered.') {\n\t\t\t\tmermaid.mermaidAPI.reset();\n\t\t\t\treturn diagramParser(diagramText);\n\t\t\t}\n\t\t}\n\n\t\tthrow new InvalidInputError((e as Error).message);\n\t}\n}\n\n/**\n * @brief This function collects transitions from a diagram;\n * @param parsedDiagram - a primary diagram dictionary;\n * @returns Returns the transitions from the diagram and their descriptions.\n */\n\nfunction getTransitions(parsedDiagram: TParsedDiagramArray): TTransitionsArray {\n\tconst transitions: TTransitionsArray = [];\n\tfor (let i = 0; i < parsedDiagram.length; i++) {\n\t\tif (parsedDiagram[i]?.stmt === 'relation') {\n\t\t\tconst directionI: string[] = [];\n\n\t\t\tconst tempSt1 = parsedDiagram[i]?.state1 as Record<string, string>;\n\t\t\tconst tempSt2 = parsedDiagram[i]?.state2 as Record<string, string>;\n\t\t\tconst st1 = tempSt1.id;\n\t\t\tconst st2 = tempSt2.id;\n\t\t\tif (!st1 || !st2)\n\t\t\t\tcontinue;\n\n\t\t\tif (st1 === '[*]' && st2 === '[*]') {\n\t\t\t\tdirectionI.push(StartState);\n\t\t\t\tdirectionI.push(EndState);\n\t\t\t}\n\t\t\tif (st1 === '[*]') {\n\t\t\t\tdirectionI.push(StartState);\n\t\t\t\tdirectionI.push(st2);\n\t\t\t} else if (st2 === '[*]') {\n\t\t\t\tdirectionI.push(st1);\n\t\t\t\tdirectionI.push(EndState);\n\t\t\t} else {\n\t\t\t\tdirectionI.push(st1);\n\t\t\t\tdirectionI.push(st2);\n\t\t\t}\n\t\t\tconst keys = Object.keys(parsedDiagram[i] as Record<string, string>);\n\t\t\tif (keys.includes('description')) {\n\t\t\t\tconst descr: string = parsedDiagram[i]?.description as string;\n\t\t\t\tdirectionI.push(descr);\n\t\t\t} else {\n\t\t\t\tdirectionI.push('');\n\t\t\t}\n\t\t\ttransitions.push(directionI);\n\t\t}\n\t}\n\treturn transitions;\n}\n\n/**\n * @brief This function collects the state captions(descriptions);\n * @param diagramStates - array of diagram elements;\n * @returns Returns an dictionary of state captions.\n */\nfunction getStatesCaption(parsedDiagram: TParsedDiagramArray): Record<string, string> {\n\tconst stateCaptions: Record<string, string> = {};\n\tfor (let i = 0; i < parsedDiagram.length; i++) {\n\t\tif (parsedDiagram[i]?.stmt === 'state') {\n\t\t\tconst keys = Object.keys(parsedDiagram[i] as Record<string, string>);\n\t\t\tif (keys.includes('type')) {\n\t\t\t\tif (parsedDiagram[i]?.type === 'default') {\n\t\t\t\t\tconst stateId: string = parsedDiagram[i]?.id as string;\n\t\t\t\t\tconst stateDesc: string = parsedDiagram[i]?.description as string;\n\t\t\t\t\tstateCaptions[stateId] = stateDesc;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn stateCaptions;\n}\n\n/**\n * @brief This function collects the elements that are in the mermaid state diagram;\n * @param transitions - array of transitions;\n * @returns Returns an array of diagram elements.\n */\nfunction getStates(parsedDiagram: TParsedDiagramArray, transitions: TTransitionsArray): TStatesStructure {\n\tconst diagramStates: TStatesStructure = [];\n\tconst stateCaptions: Record<string, string> = getStatesCaption(parsedDiagram);\n\tconst stateCaptionKeys = Object.keys(stateCaptions);\n\tconst visited: string[] = [];\n\tfor (let i = 0; i < transitions.length; i++) {\n\t\tfor (let j = 0; j < 2; j++) {\n\t\t\tconst element = transitions[i]?.[j] as string;\n\t\t\tif (!visited.includes(element)) {\n\t\t\t\tconst state: TState = {\n\t\t\t\t\tid: element,\n\t\t\t\t\tcaption: element,\n\t\t\t\t};\n\t\t\t\tif (stateCaptionKeys.includes(element)) {\n\t\t\t\t\tstate.caption = stateCaptions[element] as string;\n\t\t\t\t}\n\t\t\t\tdiagramStates.push(state);\n\t\t\t\tvisited.push(element);\n\t\t\t}\n\t\t}\n\t}\n\treturn diagramStates;\n}\n\n/**\n * @brief A function that finds choice elements;\n * @param parsedDiagram - a primary diagram dictionary;\n * @returns Returns array with choice elements;\n */\nfunction getChoices(parsedDiagram: TParsedDiagramArray): TChoicesStructure {\n\tconst choices: TChoicesStructure = [];\n\tfor (let i = 0; i < parsedDiagram.length; i++) {\n\t\tif (parsedDiagram[i]?.stmt === 'state') {\n\t\t\tconst keys = Object.keys(parsedDiagram[i] as Record<string, string>);\n\t\t\tif (keys.includes('type')) {\n\t\t\t\tconst stateType = parsedDiagram[i]?.type;\n\t\t\t\tif (stateType === 'choice') {\n\t\t\t\t\tconst choiceElement = parsedDiagram[i]?.id as string;\n\t\t\t\t\tconst choice: TChoice = {\n\t\t\t\t\t\tid: choiceElement,\n\t\t\t\t\t};\n\t\t\t\t\tchoices.push(choice);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn choices;\n}\n\n/**\n * @brief A function that finds fork and join elements;\n * @param parsedDiagram - a primary diagram dictionary;\n * @returns Returns array with fork and join elements;\n */\nfunction getForks(parsedDiagram: TParsedDiagramArray): TForksStructure {\n\tconst forks: TForksStructure = [];\n\tfor (let i = 0; i < parsedDiagram.length; i++) {\n\t\tif (parsedDiagram[i]?.stmt === 'state') {\n\t\t\tconst keys = Object.keys(parsedDiagram[i] as Record<string, string>);\n\t\t\tif (keys.includes('type')) {\n\t\t\t\tconst stateType = parsedDiagram[i]?.type;\n\t\t\t\tif (stateType === 'fork' || stateType === 'join') {\n\t\t\t\t\tconst forkElement = parsedDiagram[i]?.id as string;\n\t\t\t\t\tconst fork: TFork = {\n\t\t\t\t\t\tid: forkElement,\n\t\t\t\t\t};\n\t\t\t\t\tforks.push(fork);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn forks;\n}\n\n/**\n * @brief A function that extracts notes from the state diagram;\n * @param parsedDiagram - a primary diagram dictionary;\n * @param diagramStates - array of diagram elements;\n * @returns Returns a dictionary of notes from the state diagram.\n */\nfunction getNotes(parsedDiagram: TParsedDiagramArray): TNotesStructure {\n\tconst notes: TNotesStructure = [];\n\tconst visited: Record<string, number> = {};\n\tlet visitedCount = 0;\n\n\tfor (let i = 0; i < parsedDiagram.length; i++) {\n\t\tif (parsedDiagram[i]?.stmt === 'state') {\n\t\t\tconst keys = Object.keys(parsedDiagram[i] as Record<string, string>);\n\t\t\tif (keys.includes('note')) {\n\t\t\t\tconst noteKeys = Object.keys(parsedDiagram[i]?.note as Record<string, string>);\n\t\t\t\tif (noteKeys.includes('text')) {\n\t\t\t\t\tconst from = parsedDiagram[i]?.id as string;\n\t\t\t\t\tconst parsedDiagramNote = parsedDiagram[i]?.note as Record<string, string>;\n\t\t\t\t\tconst noteText = parsedDiagramNote.text as string;\n\t\t\t\t\tconst visitedKeys = Object.keys(visited);\n\t\t\t\t\tif (visitedKeys.includes(from)) {\n\t\t\t\t\t\tnotes[visited[from] as number]?.text.push(noteText);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst note: TNote = {\n\t\t\t\t\t\t\ttext: [noteText],\n\t\t\t\t\t\t\tover: from,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tnotes.push(note);\n\t\t\t\t\t\tvisited[from] = visitedCount;\n\t\t\t\t\t\tvisitedCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn notes;\n}\n\n/**\n * @brief This function generate unique id for anonymous action;\n * @param from - state, where the action is coming from;\n * @param to - state, where the action is coming to;\n * @param i - order number;\n * @returns Returns unique id for anonymous action.\n */\nfunction generateIdForAnonymousAction(from: string, to: string, num: number) {\n\treturn `${from}, ${to}, ${String(num)}`;\n}\n\n/**\n * @brief This function creates a dictionary of transitions action;\n * @param transitions - array of transitions;\n * @returns Returns a dictionary of transitions action.\n */\nfunction getActions(transitions: TTransitionsArray): TActionsStructure {\n\tconst actions: TActionsStructure = [];\n\tfor (let i = 0; i < transitions.length; i++) {\n\t\tlet actionIsInternal = false;\n\t\tlet actionIsPredicate = false;\n\n\t\tconst from = transitions[i]?.[0] as string;\n\t\tconst to = transitions[i]?.[1] as string;\n\t\tlet id = extractActionId(transitions[i]?.[2]) as string;\n\t\tif (id === '') {\n\t\t\tid = generateIdForAnonymousAction(from, to, i);\n\t\t\tactionIsInternal = true;\n\t\t}\n\t\tconst params = extractActionParams(transitions[i]?.[2]);\n\t\tif (params && hasExpressionValues(params)) {\n\t\t\tactionIsPredicate = true;\n\t\t}\n\t\tconst action: TActionWithParams = {\n\t\t\tfrom,\n\t\t\tto,\n\t\t\tid,\n\t\t\tparams,\n\t\t\tinternal: actionIsInternal,\n\t\t\tpredicate: actionIsPredicate,\n\t\t};\n\t\tactions.push(action);\n\t}\n\treturn actions;\n}\n\n/**\n * The main function that collects all the information from the Mermaid diagram and transforms it\n * into a form appropriate for processing with other parts of the Yantrix toolkit.\n *\n * @param diagramText - Text of the diagram written in accordance with Mermaid syntax.\n * @returns Dictionary that contains information from the diagram for further processing, such as:\n * - States\n * - Actions\n * - Notes with Yantrix subsyntax\n * - Forks with multiple choices\n */\nexport async function parseStateDiagram(diagramText: string): Promise<TStateDiagramStructure> {\n\tconst parsedDiagram: TParsedDiagramArray = await diagramParser(diagramText);\n\tconst transitions: TTransitionsArray = getTransitions(parsedDiagram);\n\tconst stateDiagramStructure: TStateDiagramStructure = {\n\t\tstates: getStates(parsedDiagram, transitions),\n\t\tactions: getActions(transitions),\n\t\tnotes: getNotes(parsedDiagram),\n\t\tchoices: getChoices(parsedDiagram),\n\t\tforks: getForks(parsedDiagram),\n\t};\n\treturn stateDiagramStructure;\n}\n","export class InvalidInputError extends Error {\n\tconstructor(messages?: string) {\n\t\tsuper(`Invalid diagram input: ${messages}`);\n\t}\n}\n\nexport class BlankInputError extends Error {\n\tconstructor(messages?: string) {\n\t\tsuper(`the diagram is empty. ${messages}`);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAa;AACnB,IAAM,WAAW;;;ACDxB,qBAAoB;;;ACAb,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAA7C,OAA6C;AAAA;AAAA;AAAA,EAC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A/BS,OAAAA,WAAA;AAwCT,SAAS,6BAA6B,MAAc,IAAY,KAAa;AAC5E,SAAO,GAAG,IAAI,KAAK,EAAE,KAAK,OAAO,GAAG,CAAC;AACtC;AAFS;AAST,SAAS,WAAW,aAAmD;AACtE,QAAM,UAA6B,CAAC;AACpC,WAAS,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;AAC5C,QAAI,mBAAmB;AACvB,QAAI,oBAAoB;AAExB,UAAM,OAAO,YAAY,CAAC,IAAI,CAAC;AAC/B,UAAM,KAAK,YAAY,CAAC,IAAI,CAAC;AAC7B,QAAI,KAAK,gBAAgB,YAAY,CAAC,IAAI,CAAC,CAAC;AAC5C,QAAI,OAAO,IAAI;AACd,WAAK,6BAA6B,MAAM,IAAI,CAAC;AAC7C,yBAAmB;AAAA,IACpB;AACA,UAAM,SAAS,oBAAoB,YAAY,CAAC,IAAI,CAAC,CAAC;AACtD,QAAI,UAAU,oBAAoB,MAAM,GAAG;AAC1C,0BAAoB;AAAA,IACrB;AACA,UAAM,SAA4B;AAAA,MACjC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV,WAAW;AAAA,IACZ;AACA,YAAQ,KAAK,MAAM;AAAA,EACpB;AACA,SAAO;AACR;AA5BS;AAyCT,eAAsB,kBAAkB,aAAsD;AAC7F,QAAM,gBAAqC,MAAMN,eAAc,WAAW;AAC1E,QAAM,cAAiCI,gBAAe,aAAa;AACnE,QAAM,wBAAgD;AAAA,IACrD,QAAQC,WAAU,eAAe,WAAW;AAAA,IAC5C,SAAS,WAAW,WAAW;AAAA,IAC/B,OAAOC,UAAS,aAAa;AAAA,IAC7B,SAAS,WAAW,aAAa;AAAA,IACjC,OAAO,SAAS,aAAa;AAAA,EAC9B;AACA,SAAO;AACR;AAXsB;","names":["mermaid","note","actionInStructure","import_mermaid","InvalidInputError","BlankInputError","diagramParser","BlankInputError","mermaid","InvalidInputError","getTransitions","getStates","getNotes"]}