@pairdraw/mermaid 0.16.2 → 0.17.0
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.
|
@@ -6,11 +6,12 @@ import { parseFragment } from "parse5";
|
|
|
6
6
|
//#region src/label.ts
|
|
7
7
|
/** The text HTML shows: its text nodes, and a line break for each `<br>`. */
|
|
8
8
|
function shownText(nodes) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
let text = "";
|
|
10
|
+
const stack = nodes.toReversed();
|
|
11
|
+
for (let node = stack.pop(); node; node = stack.pop()) if (node.nodeName === "#text" && "value" in node) text += node.value;
|
|
12
|
+
else if (node.nodeName === "br") text += "\n";
|
|
13
|
+
else if ("childNodes" in node) for (const child of node.childNodes.toReversed()) stack.push(child);
|
|
14
|
+
return text;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* A label's text as plain text and its format. Mermaid draws a label as HTML, so its tags only
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","names":["parseYAML"],"sources":["../../../src/label.ts","../../../src/flowchart/shapes.ts","../../../src/flowchart/builder.ts"],"sourcesContent":["import { decodeHTML } from 'entities'\nimport { parseFragment, type DefaultTreeAdapterTypes } from 'parse5'\n\nimport type { FlowLabel } from './flowchart/model'\nimport { decodeEntities } from './upstream/preprocess'\n\n/** A label as Mermaid's grammar hands it over: its text, and how that text is to be read. */\nexport interface GrammarText {\n text: string\n type: string\n}\n\ntype HTMLNode = DefaultTreeAdapterTypes.ChildNode\n\n/** The text HTML shows: its text nodes, and a line break for each `<br>`. */\nfunction shownText(nodes: HTMLNode[]): string {\n return nodes\n .map((node) => {\n if (node.nodeName === '#text' && 'value' in node) return node.value\n if (node.nodeName === 'br') return '\\n'\n return 'childNodes' in node ? shownText(node.childNodes) : ''\n })\n .join('')\n}\n\n/**\n * A label's text as plain text and its format. Mermaid draws a label as HTML, so its tags only\n * style the text, `<br>` breaks the line, and entities stand for characters. Markdown, written\n * in backticks, keeps its marks for whoever draws it.\n */\nexport function readLabel(label: GrammarText): FlowLabel {\n let text = decodeEntities(label.text.trim())\n // Mermaid drops the quotes around a label written in them.\n if (text.length >= 2 && text.startsWith('\"') && text.endsWith('\"')) text = text.slice(1, -1)\n if (label.type === 'markdown') return { text: decodeHTML(text), format: 'markdown' }\n return { text: shownText(parseFragment(text).childNodes), format: 'text' }\n}\n","/**\n * Mermaid's flowchart shapes by their short names, with the other names `@{ shape: … }` accepts\n * for each, from `rendering-util/rendering-elements/shapes.ts` in the pinned Mermaid release\n * (MIT, Copyright (c) 2014 - 2022 Knut Sveidqvist). `bun run generate:mermaid-sources --check`\n * reports when a newer release changes that file.\n */\nconst SHAPE_NAMES = {\n rect: ['proc', 'process', 'rectangle', 'squareRect'],\n rounded: ['event', 'roundedRect'],\n stadium: ['terminal', 'pill'],\n 'fr-rect': ['subprocess', 'subproc', 'framed-rectangle', 'subroutine'],\n cyl: ['db', 'database', 'cylinder'],\n datastore: ['data-store'],\n folder: ['directory'],\n bucket: [],\n console: [],\n browser: [],\n person: [],\n circle: ['circ'],\n bang: [],\n cloud: [],\n diam: ['decision', 'diamond', 'question'],\n hex: ['hexagon', 'prepare'],\n 'lean-r': ['lean-right', 'in-out', 'lean_right'],\n 'lean-l': ['lean-left', 'out-in', 'lean_left'],\n 'trap-b': ['priority', 'trapezoid-bottom', 'trapezoid'],\n 'trap-t': ['manual', 'trapezoid-top', 'inv-trapezoid', 'inv_trapezoid'],\n 'dbl-circ': ['double-circle', 'doublecircle'],\n text: [],\n 'notch-rect': ['card', 'notched-rectangle'],\n 'lin-rect': ['lined-rectangle', 'lined-process', 'lin-proc', 'shaded-process'],\n 'sm-circ': ['start', 'small-circle', 'stateStart'],\n 'fr-circ': ['stop', 'framed-circle', 'stateEnd'],\n fork: ['join', 'forkJoin'],\n hourglass: ['collate'],\n brace: ['comment', 'brace-l'],\n 'brace-r': [],\n braces: [],\n bolt: ['com-link', 'lightning-bolt'],\n doc: ['document'],\n delay: ['half-rounded-rectangle'],\n 'h-cyl': ['das', 'horizontal-cylinder'],\n 'lin-cyl': ['disk', 'lined-cylinder'],\n 'curv-trap': ['curved-trapezoid', 'display'],\n 'div-rect': ['div-proc', 'divided-rectangle', 'divided-process'],\n tri: ['extract', 'triangle'],\n 'win-pane': ['internal-storage', 'window-pane'],\n 'f-circ': ['junction', 'filled-circle'],\n 'notch-pent': ['loop-limit', 'notched-pentagon'],\n 'flip-tri': ['manual-file', 'flipped-triangle'],\n 'sl-rect': ['manual-input', 'sloped-rectangle'],\n docs: ['documents', 'st-doc', 'stacked-document'],\n 'st-rect': ['procs', 'processes', 'stacked-rectangle'],\n 'bow-rect': ['stored-data', 'bow-tie-rectangle'],\n 'cross-circ': ['summary', 'crossed-circle'],\n 'tag-doc': ['tagged-document'],\n 'tag-rect': ['tagged-rectangle', 'tag-proc', 'tagged-process'],\n flag: ['paper-tape'],\n odd: ['rect_left_inv_arrow'],\n 'lin-doc': ['lined-document']\n} as const satisfies Record<string, readonly string[]>\n\n/**\n * A flowchart node's shape, by Mermaid's short name for it, or `ellipse` for `A(-text-)`, which\n * Mermaid's grammar reads but its renderer refuses (mermaid-js/mermaid#5976).\n */\nexport type FlowShape = keyof typeof SHAPE_NAMES | 'ellipse'\n\nconst SHAPE_BY_NAME = new Map<string, FlowShape>(\n Object.entries(SHAPE_NAMES).flatMap(([shape, aliases]) =>\n [shape, ...aliases].map((name) => [name, shape as FlowShape] as const)\n )\n)\n\n/** The shape a name from `@{ shape: … }` stands for, or null for one Mermaid does not know. */\nexport function shapeNamed(name: string): FlowShape | null {\n return SHAPE_BY_NAME.get(name) ?? null\n}\n\n/**\n * The shape each bracket form stands for, by the vertex type Mermaid's grammar gives it: `[ ]` a\n * rectangle, `( )` a rounded one, `([ ])` a stadium, and so on.\n */\nconst BRACKET_SHAPES: Record<string, FlowShape> = {\n square: 'rect',\n rect: 'rect',\n round: 'rounded',\n ellipse: 'ellipse',\n stadium: 'stadium',\n subroutine: 'fr-rect',\n cylinder: 'cyl',\n circle: 'circle',\n doublecircle: 'dbl-circ',\n diamond: 'diam',\n hexagon: 'hex',\n odd: 'odd',\n trapezoid: 'trap-b',\n inv_trapezoid: 'trap-t',\n lean_right: 'lean-r',\n lean_left: 'lean-l'\n}\n\nexport function bracketShape(vertexType: string): FlowShape {\n return BRACKET_SHAPES[vertexType] ?? 'rect'\n}\n","import * as v from 'valibot'\nimport { parse as parseYAML } from 'yaml'\n\nimport { readLabel, type GrammarText } from '../label'\nimport type {\n FlowArrowhead,\n FlowDirection,\n FlowEdge,\n FlowNode,\n FlowStroke,\n FlowSubgraph,\n Flowchart\n} from './model'\nimport { bracketShape, shapeNamed } from './shapes'\n\n/** An edge as the grammar describes it before its ends are known. */\ninterface GrammarLink {\n type: string\n stroke: string\n length?: number\n text?: GrammarText\n id?: string\n}\n\n/** A `direction` statement inside a subgraph, as the grammar lists it among the members. */\ninterface DirectionStatement {\n stmt: 'dir'\n value: string\n}\n\nconst STROKES: Record<string, FlowStroke> = {\n normal: 'normal',\n thick: 'thick',\n dotted: 'dotted',\n invisible: 'invisible'\n}\n\nconst ARROWHEADS: Record<string, FlowArrowhead> = {\n arrow_point: 'arrow',\n arrow_circle: 'circle',\n arrow_cross: 'cross',\n arrow_open: 'none'\n}\n\n/** The arrowhead a link's first character opens it with, as in `<-->` or `o--o`. */\nconst START_HEADS: Record<string, string> = {\n '<': 'arrow_point',\n x: 'arrow_cross',\n o: 'arrow_circle'\n}\n\n/** The arrowhead a link's last character closes it with, and the one that opens it as well. */\nconst END_HEADS = new Map([\n ['x', { type: 'arrow_cross', opening: 'x' }],\n ['>', { type: 'arrow_point', opening: '<' }],\n ['o', { type: 'arrow_circle', opening: 'o' }]\n])\n\n/** Mermaid's longest edge: more dashes than this count as this many. */\nconst MAX_EDGE_LENGTH = 10\n\nfunction direction(text: string): FlowDirection {\n const dir = text.trim()\n if (dir.includes('<')) return 'RL'\n if (dir.includes('^')) return 'BT'\n if (dir.includes('>')) return 'LR'\n if (dir.includes('v')) return 'TB'\n if (dir === 'BT' || dir === 'LR' || dir === 'RL') return dir\n return 'TB'\n}\n\nfunction isDirectionStatement(item: unknown): item is DirectionStatement {\n return typeof item === 'object' && item !== null && 'stmt' in item && item.stmt === 'dir'\n}\n\n/** What `@{ … }` data sets that a node keeps; other keys, such as `icon`, are left out. */\nconst shapeDataSchema = v.looseObject({\n shape: v.optional(v.string()),\n label: v.optional(v.pipe(v.union([v.string(), v.number()]), v.toString())),\n labelType: v.optional(v.string())\n})\n\ntype ShapeData = v.InferOutput<typeof shapeDataSchema>\n\n/** `@{ … }` data, which is YAML, written as a flow mapping when it fits on one line. */\nfunction shapeData(text: string): ShapeData {\n const data: unknown = parseYAML(text.includes('\\n') ? `${text}\\n` : `{\\n${text}\\n}`)\n const parsed = v.safeParse(shapeDataSchema, data)\n return parsed.success ? parsed.output : {}\n}\n\nfunction arrowheads(type: string): { startArrow: FlowArrowhead; endArrow: FlowArrowhead } {\n if (type.startsWith('double_')) {\n const head = ARROWHEADS[type.slice('double_'.length)] ?? 'arrow'\n return { startArrow: head, endArrow: head }\n }\n return { startArrow: 'none', endArrow: ARROWHEADS[type] ?? 'arrow' }\n}\n\n/**\n * The `yy` object Mermaid's flowchart grammar calls as it parses, building a `Flowchart`. It\n * keeps the meaning Mermaid's `FlowDB` gives each call in the pinned release (MIT, Copyright (c)\n * 2014 - 2022 Knut Sveidqvist), without what only Mermaid's renderer needs: DOM ids, click\n * callbacks, sanitizing for the page, and edge animation.\n */\nexport class FlowchartBuilder {\n private dir: FlowDirection = 'TB'\n private readonly nodes = new Map<string, FlowNode>()\n private readonly edges: FlowEdge[] = []\n private readonly subgraphs: FlowSubgraph[] = []\n private readonly classDefs = new Map<string, string[]>()\n private defaultEdgeStyle: string[] = []\n private subgraphCount = 0\n private firstGraphSeen = false\n private accessibleTitle?: string\n private accessibleDescription?: string\n\n readonly lex = {\n /** True for the first `graph`/`flowchart` keyword only; a later one is text. */\n firstGraph: () => {\n if (this.firstGraphSeen) return false\n this.firstGraphSeen = true\n return true\n }\n }\n\n /**\n * The calls the grammar makes, as the plain object it copies them from: JISON copies `yy`'s\n * enumerable properties into its own state, which leaves out a class's methods.\n */\n grammarCalls() {\n return {\n lex: this.lex,\n setDirection: this.setDirection.bind(this),\n setAccTitle: this.setAccTitle.bind(this),\n setAccDescription: this.setAccDescription.bind(this),\n addVertex: this.addVertex.bind(this),\n destructLink: this.destructLink.bind(this),\n addLink: this.addLink.bind(this),\n updateLinkInterpolate: this.updateLinkInterpolate.bind(this),\n updateLink: this.updateLink.bind(this),\n addClass: this.addClass.bind(this),\n setClass: this.setClass.bind(this),\n setLink: this.setLink.bind(this),\n setTooltip: this.setTooltip.bind(this),\n setClickEvent: this.setClickEvent.bind(this),\n addSubGraph: this.addSubGraph.bind(this)\n }\n }\n\n result(title?: string): Flowchart {\n // `style` and `class` statements naming a subgraph style the subgraph, though the grammar\n // reports them as nodes.\n const subgraphIds = new Set(this.subgraphs.map((subgraph) => subgraph.id))\n for (const subgraph of this.subgraphs) {\n const node = this.nodes.get(subgraph.id)\n if (!node) continue\n subgraph.styles.push(...node.styles)\n subgraph.classes.push(...node.classes)\n }\n return {\n direction: this.dir,\n nodes: [...this.nodes.values()].filter((node) => !subgraphIds.has(node.id)),\n edges: this.edges.map((edge) => ({\n ...edge,\n styles: [...this.defaultEdgeStyle, ...edge.styles]\n })),\n subgraphs: this.subgraphs,\n classDefs: this.classDefs,\n title,\n accessibleTitle: this.accessibleTitle,\n accessibleDescription: this.accessibleDescription\n }\n }\n\n setDirection(dir: string): void {\n this.dir = direction(dir)\n }\n\n setAccTitle(text: string): void {\n this.accessibleTitle = text\n }\n\n setAccDescription(text: string): void {\n this.accessibleDescription = text\n }\n\n addVertex(\n id: string,\n text?: GrammarText,\n type?: string,\n styles?: string[],\n classes?: string[],\n _dir?: string,\n _props?: Record<string, unknown>,\n metadata?: string\n ): void {\n if (!id || id.trim().length === 0) return\n const data = metadata === undefined ? undefined : shapeData(metadata)\n // An edge's id, or `@{ … }` after a subgraph's, names that edge or subgraph, not a node;\n // the data it carries is animation and the like, which nothing here draws.\n if (this.edges.some((edge) => edge.id === id) || (data && this.isSubgraph(id))) return\n let node = this.nodes.get(id)\n if (!node) {\n node = {\n id,\n label: { text: id, format: 'text' },\n shape: 'rect',\n classes: [],\n styles: []\n }\n this.nodes.set(id, node)\n }\n if (text) node.label = readLabel(text)\n if (type !== undefined) node.shape = bracketShape(type)\n if (styles) node.styles.push(...styles)\n if (classes) node.classes.push(...classes)\n if (!data) return\n if (typeof data.shape === 'string') {\n const shape = data.shape === data.shape.toLowerCase() ? shapeNamed(data.shape) : null\n if (!shape) throw new Error(`No such shape: ${data.shape}.`)\n node.shape = shape\n }\n if (typeof data.label === 'string') {\n node.label = readLabel({\n text: data.label,\n type: data.labelType === 'text' || data.labelType === 'string' ? 'text' : 'markdown'\n })\n }\n }\n\n destructLink(end: string, start?: string): GrammarLink {\n const info = this.endOfLink(end)\n if (!start) return info\n const begin = this.startOfLink(start)\n if (begin.stroke !== info.stroke) return { type: 'INVALID', stroke: 'INVALID' }\n if (begin.type === 'arrow_open') return { ...info, type: info.type }\n if (begin.type !== info.type) return { type: 'INVALID', stroke: 'INVALID' }\n return { ...info, type: `double_${begin.type}` }\n }\n\n addLink(starts: string[], ends: string[], link: GrammarLink): void {\n const id = link.id?.replace('@', '')\n for (const from of starts) {\n for (const to of ends) {\n // In `A e1@--> B & C`, the id names the edge from the last start to the first end.\n const named = from === starts.at(-1) && to === ends[0]\n this.addEdge(from, to, link, named ? id : undefined)\n }\n }\n }\n\n updateLinkInterpolate(): void {\n // Curve styles are Mermaid's renderer's; connectors take their own line type.\n }\n\n updateLink(positions: ('default' | number)[], styles: string[]): void {\n for (const position of positions) {\n if (position === 'default') {\n this.defaultEdgeStyle = styles\n continue\n }\n const edge = this.edges.at(position)\n if (!edge || position < 0) {\n throw new Error(\n `The index ${position} for linkStyle is out of bounds. Valid indices for linkStyle are between 0 and ${this.edges.length - 1}.`\n )\n }\n edge.styles = styles\n }\n }\n\n addClass(ids: string, styles: string[]): void {\n // Commas and semicolons separate declarations; an escaped comma, as in `font-family:a\\,b`,\n // is part of one.\n const declarations = styles\n .join(',')\n .split(/(?<!\\\\)[,;]/)\n .map((declaration) => declaration.replaceAll('\\\\,', ','))\n for (const id of ids.split(',')) {\n const existing = this.classDefs.get(id) ?? []\n this.classDefs.set(id, [...existing, ...declarations])\n }\n }\n\n setClass(ids: string, className: string): void {\n for (const id of ids.split(',')) {\n const subgraph = this.subgraphs.find((candidate) => candidate.id === id)\n if (subgraph) subgraph.classes.push(className)\n else this.nodes.get(id)?.classes.push(className)\n }\n }\n\n setLink(ids: string, href: string, target?: string): void {\n for (const id of ids.split(',')) {\n const node = this.nodes.get(id)\n if (node) node.link = target ? { href, target } : { href }\n }\n }\n\n setTooltip(ids: string, tooltip?: string): void {\n if (tooltip === undefined) return\n for (const id of ids.split(',')) {\n const node = this.nodes.get(id)\n if (node) node.tooltip = tooltip\n }\n }\n\n setClickEvent(): void {\n // Callbacks run scripts on Mermaid's page; a design layer has none to run.\n }\n\n addSubGraph(\n idText: GrammarText | undefined,\n list: unknown[],\n titleText: GrammarText | undefined\n ): string {\n // `subgraph Some title` gives the title as the id too; an id with spaces is no id.\n let id = idText?.text.trim()\n if (idText && idText === titleText && /\\s/.test(idText.text)) id = undefined\n let dir: FlowDirection | undefined\n const members: string[] = []\n for (const item of list.flat()) {\n if (isDirectionStatement(item)) {\n dir = direction(item.value)\n continue\n }\n if (typeof item !== 'string' || item.trim() === '' || members.includes(item)) continue\n members.push(item)\n }\n const subgraphId = id ?? `subGraph${this.subgraphCount}`\n this.subgraphCount++\n // A node belongs to the subgraph that closes first, which is the innermost one, and a\n // subgraph never holds itself.\n const own = members.filter(\n (member) =>\n member !== subgraphId &&\n !this.subgraphs.some((subgraph) => subgraph.members.includes(member))\n )\n const existing = this.subgraphs.find((subgraph) => subgraph.id === subgraphId)\n if (existing) {\n // A repeated id adds to the first declaration, which keeps its title and direction.\n existing.members.push(...own)\n return subgraphId\n }\n this.subgraphs.push({\n id: subgraphId,\n title: titleText ? readLabel(titleText) : { text: '', format: 'text' },\n members: own,\n direction: dir,\n classes: [],\n styles: []\n })\n return subgraphId\n }\n\n private isSubgraph(id: string): boolean {\n return this.subgraphs.some((subgraph) => subgraph.id === id)\n }\n\n private addEdge(from: string, to: string, link: GrammarLink, id?: string): void {\n const label = link.text && readLabel(link.text)\n const edgeId =\n id && !this.edges.some((edge) => edge.id === id)\n ? id\n : `L_${from}_${to}_${this.edges.filter((edge) => edge.from === from && edge.to === to).length}`\n this.edges.push({\n id: edgeId,\n from,\n to,\n ...(label && label.text !== '' ? { label } : {}),\n ...arrowheads(link.type),\n stroke: STROKES[link.stroke] ?? 'normal',\n length: Math.min(link.length ?? 1, MAX_EDGE_LENGTH),\n styles: []\n })\n }\n\n private startOfLink(text: string): { type: string; stroke: string } {\n let rest = text.trim()\n let type = 'arrow_open'\n const head = rest[0]\n const opening = head && START_HEADS[head]\n if (opening) {\n type = opening\n rest = rest.slice(1)\n }\n let stroke = 'normal'\n if (rest.includes('=')) stroke = 'thick'\n if (rest.includes('.')) stroke = 'dotted'\n return { type, stroke }\n }\n\n private endOfLink(text: string): GrammarLink {\n const link = text.trim()\n let line = link.slice(0, -1)\n let type = 'arrow_open'\n const tail = link.slice(-1)\n const head = END_HEADS.get(tail)\n if (head) {\n type = head.type\n if (link.startsWith(head.opening)) {\n type = `double_${type}`\n line = line.slice(1)\n }\n }\n let stroke = 'normal'\n let length = line.length - 1\n if (line.startsWith('=')) stroke = 'thick'\n if (line.startsWith('~')) stroke = 'invisible'\n const dots = line.split('.').length - 1\n if (dots) {\n stroke = 'dotted'\n length = dots\n }\n return { type, stroke, length }\n }\n}\n"],"mappings":";;;;;;;AAeA,SAAS,UAAU,OAA2B;CAC5C,OAAO,MACJ,KAAK,SAAS;EACb,IAAI,KAAK,aAAa,WA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SAAS;EACb,IAAI,SAAS,KAAK,SAAS;EAC3B,IAAI,KAAK,WAAW,GAAG,GAAG,SAAS;EACnC,IAAI,KAAK,WAAW,GAAG,GAAG,SAAS;EACnC,MAAM,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS;EACtC,IAAI,MAAM;GACR,SAAS;GACT,SAAS;EACX;EACA,OAAO;GAAE;GAAM;GAAQ;EAAO;CAChC;AACF"}
|
|
1
|
+
{"version":3,"file":"builder.js","names":["parseYAML"],"sources":["../../../src/label.ts","../../../src/flowchart/shapes.ts","../../../src/flowchart/builder.ts"],"sourcesContent":["import { decodeHTML } from 'entities'\nimport { parseFragment, type DefaultTreeAdapterTypes } from 'parse5'\n\nimport type { FlowLabel } from './flowchart/model'\nimport { decodeEntities } from './upstream/preprocess'\n\n/** A label as Mermaid's grammar hands it over: its text, and how that text is to be read. */\nexport interface GrammarText {\n text: string\n type: string\n}\n\ntype HTMLNode = DefaultTreeAdapterTypes.ChildNode\n\n/** The text HTML shows: its text nodes, and a line break for each `<br>`. */\nfunction shownText(nodes: HTMLNode[]): string {\n let text = ''\n // A label can nest more tags than the call stack holds, so walk them with a stack of our own.\n const stack = nodes.toReversed()\n for (let node = stack.pop(); node; node = stack.pop()) {\n if (node.nodeName === '#text' && 'value' in node) text += node.value\n else if (node.nodeName === 'br') text += '\\n'\n else if ('childNodes' in node)\n for (const child of node.childNodes.toReversed()) stack.push(child)\n }\n return text\n}\n\n/**\n * A label's text as plain text and its format. Mermaid draws a label as HTML, so its tags only\n * style the text, `<br>` breaks the line, and entities stand for characters. Markdown, written\n * in backticks, keeps its marks for whoever draws it.\n */\nexport function readLabel(label: GrammarText): FlowLabel {\n let text = decodeEntities(label.text.trim())\n // Mermaid drops the quotes around a label written in them.\n if (text.length >= 2 && text.startsWith('\"') && text.endsWith('\"')) text = text.slice(1, -1)\n if (label.type === 'markdown') return { text: decodeHTML(text), format: 'markdown' }\n return { text: shownText(parseFragment(text).childNodes), format: 'text' }\n}\n","/**\n * Mermaid's flowchart shapes by their short names, with the other names `@{ shape: … }` accepts\n * for each, from `rendering-util/rendering-elements/shapes.ts` in the pinned Mermaid release\n * (MIT, Copyright (c) 2014 - 2022 Knut Sveidqvist). `bun run generate:mermaid-sources --check`\n * reports when a newer release changes that file.\n */\nconst SHAPE_NAMES = {\n rect: ['proc', 'process', 'rectangle', 'squareRect'],\n rounded: ['event', 'roundedRect'],\n stadium: ['terminal', 'pill'],\n 'fr-rect': ['subprocess', 'subproc', 'framed-rectangle', 'subroutine'],\n cyl: ['db', 'database', 'cylinder'],\n datastore: ['data-store'],\n folder: ['directory'],\n bucket: [],\n console: [],\n browser: [],\n person: [],\n circle: ['circ'],\n bang: [],\n cloud: [],\n diam: ['decision', 'diamond', 'question'],\n hex: ['hexagon', 'prepare'],\n 'lean-r': ['lean-right', 'in-out', 'lean_right'],\n 'lean-l': ['lean-left', 'out-in', 'lean_left'],\n 'trap-b': ['priority', 'trapezoid-bottom', 'trapezoid'],\n 'trap-t': ['manual', 'trapezoid-top', 'inv-trapezoid', 'inv_trapezoid'],\n 'dbl-circ': ['double-circle', 'doublecircle'],\n text: [],\n 'notch-rect': ['card', 'notched-rectangle'],\n 'lin-rect': ['lined-rectangle', 'lined-process', 'lin-proc', 'shaded-process'],\n 'sm-circ': ['start', 'small-circle', 'stateStart'],\n 'fr-circ': ['stop', 'framed-circle', 'stateEnd'],\n fork: ['join', 'forkJoin'],\n hourglass: ['collate'],\n brace: ['comment', 'brace-l'],\n 'brace-r': [],\n braces: [],\n bolt: ['com-link', 'lightning-bolt'],\n doc: ['document'],\n delay: ['half-rounded-rectangle'],\n 'h-cyl': ['das', 'horizontal-cylinder'],\n 'lin-cyl': ['disk', 'lined-cylinder'],\n 'curv-trap': ['curved-trapezoid', 'display'],\n 'div-rect': ['div-proc', 'divided-rectangle', 'divided-process'],\n tri: ['extract', 'triangle'],\n 'win-pane': ['internal-storage', 'window-pane'],\n 'f-circ': ['junction', 'filled-circle'],\n 'notch-pent': ['loop-limit', 'notched-pentagon'],\n 'flip-tri': ['manual-file', 'flipped-triangle'],\n 'sl-rect': ['manual-input', 'sloped-rectangle'],\n docs: ['documents', 'st-doc', 'stacked-document'],\n 'st-rect': ['procs', 'processes', 'stacked-rectangle'],\n 'bow-rect': ['stored-data', 'bow-tie-rectangle'],\n 'cross-circ': ['summary', 'crossed-circle'],\n 'tag-doc': ['tagged-document'],\n 'tag-rect': ['tagged-rectangle', 'tag-proc', 'tagged-process'],\n flag: ['paper-tape'],\n odd: ['rect_left_inv_arrow'],\n 'lin-doc': ['lined-document']\n} as const satisfies Record<string, readonly string[]>\n\n/**\n * A flowchart node's shape, by Mermaid's short name for it, or `ellipse` for `A(-text-)`, which\n * Mermaid's grammar reads but its renderer refuses (mermaid-js/mermaid#5976).\n */\nexport type FlowShape = keyof typeof SHAPE_NAMES | 'ellipse'\n\nconst SHAPE_BY_NAME = new Map<string, FlowShape>(\n Object.entries(SHAPE_NAMES).flatMap(([shape, aliases]) =>\n [shape, ...aliases].map((name) => [name, shape as FlowShape] as const)\n )\n)\n\n/** The shape a name from `@{ shape: … }` stands for, or null for one Mermaid does not know. */\nexport function shapeNamed(name: string): FlowShape | null {\n return SHAPE_BY_NAME.get(name) ?? null\n}\n\n/**\n * The shape each bracket form stands for, by the vertex type Mermaid's grammar gives it: `[ ]` a\n * rectangle, `( )` a rounded one, `([ ])` a stadium, and so on.\n */\nconst BRACKET_SHAPES: Record<string, FlowShape> = {\n square: 'rect',\n rect: 'rect',\n round: 'rounded',\n ellipse: 'ellipse',\n stadium: 'stadium',\n subroutine: 'fr-rect',\n cylinder: 'cyl',\n circle: 'circle',\n doublecircle: 'dbl-circ',\n diamond: 'diam',\n hexagon: 'hex',\n odd: 'odd',\n trapezoid: 'trap-b',\n inv_trapezoid: 'trap-t',\n lean_right: 'lean-r',\n lean_left: 'lean-l'\n}\n\nexport function bracketShape(vertexType: string): FlowShape {\n return BRACKET_SHAPES[vertexType] ?? 'rect'\n}\n","import * as v from 'valibot'\nimport { parse as parseYAML } from 'yaml'\n\nimport { readLabel, type GrammarText } from '../label'\nimport type {\n FlowArrowhead,\n FlowDirection,\n FlowEdge,\n FlowNode,\n FlowStroke,\n FlowSubgraph,\n Flowchart\n} from './model'\nimport { bracketShape, shapeNamed } from './shapes'\n\n/** An edge as the grammar describes it before its ends are known. */\ninterface GrammarLink {\n type: string\n stroke: string\n length?: number\n text?: GrammarText\n id?: string\n}\n\n/** A `direction` statement inside a subgraph, as the grammar lists it among the members. */\ninterface DirectionStatement {\n stmt: 'dir'\n value: string\n}\n\nconst STROKES: Record<string, FlowStroke> = {\n normal: 'normal',\n thick: 'thick',\n dotted: 'dotted',\n invisible: 'invisible'\n}\n\nconst ARROWHEADS: Record<string, FlowArrowhead> = {\n arrow_point: 'arrow',\n arrow_circle: 'circle',\n arrow_cross: 'cross',\n arrow_open: 'none'\n}\n\n/** The arrowhead a link's first character opens it with, as in `<-->` or `o--o`. */\nconst START_HEADS: Record<string, string> = {\n '<': 'arrow_point',\n x: 'arrow_cross',\n o: 'arrow_circle'\n}\n\n/** The arrowhead a link's last character closes it with, and the one that opens it as well. */\nconst END_HEADS = new Map([\n ['x', { type: 'arrow_cross', opening: 'x' }],\n ['>', { type: 'arrow_point', opening: '<' }],\n ['o', { type: 'arrow_circle', opening: 'o' }]\n])\n\n/** Mermaid's longest edge: more dashes than this count as this many. */\nconst MAX_EDGE_LENGTH = 10\n\nfunction direction(text: string): FlowDirection {\n const dir = text.trim()\n if (dir.includes('<')) return 'RL'\n if (dir.includes('^')) return 'BT'\n if (dir.includes('>')) return 'LR'\n if (dir.includes('v')) return 'TB'\n if (dir === 'BT' || dir === 'LR' || dir === 'RL') return dir\n return 'TB'\n}\n\nfunction isDirectionStatement(item: unknown): item is DirectionStatement {\n return typeof item === 'object' && item !== null && 'stmt' in item && item.stmt === 'dir'\n}\n\n/** What `@{ … }` data sets that a node keeps; other keys, such as `icon`, are left out. */\nconst shapeDataSchema = v.looseObject({\n shape: v.optional(v.string()),\n label: v.optional(v.pipe(v.union([v.string(), v.number()]), v.toString())),\n labelType: v.optional(v.string())\n})\n\ntype ShapeData = v.InferOutput<typeof shapeDataSchema>\n\n/** `@{ … }` data, which is YAML, written as a flow mapping when it fits on one line. */\nfunction shapeData(text: string): ShapeData {\n const data: unknown = parseYAML(text.includes('\\n') ? `${text}\\n` : `{\\n${text}\\n}`)\n const parsed = v.safeParse(shapeDataSchema, data)\n return parsed.success ? parsed.output : {}\n}\n\nfunction arrowheads(type: string): { startArrow: FlowArrowhead; endArrow: FlowArrowhead } {\n if (type.startsWith('double_')) {\n const head = ARROWHEADS[type.slice('double_'.length)] ?? 'arrow'\n return { startArrow: head, endArrow: head }\n }\n return { startArrow: 'none', endArrow: ARROWHEADS[type] ?? 'arrow' }\n}\n\n/**\n * The `yy` object Mermaid's flowchart grammar calls as it parses, building a `Flowchart`. It\n * keeps the meaning Mermaid's `FlowDB` gives each call in the pinned release (MIT, Copyright (c)\n * 2014 - 2022 Knut Sveidqvist), without what only Mermaid's renderer needs: DOM ids, click\n * callbacks, sanitizing for the page, and edge animation.\n */\nexport class FlowchartBuilder {\n private dir: FlowDirection = 'TB'\n private readonly nodes = new Map<string, FlowNode>()\n private readonly edges: FlowEdge[] = []\n private readonly subgraphs: FlowSubgraph[] = []\n private readonly classDefs = new Map<string, string[]>()\n private defaultEdgeStyle: string[] = []\n private subgraphCount = 0\n private firstGraphSeen = false\n private accessibleTitle?: string\n private accessibleDescription?: string\n\n readonly lex = {\n /** True for the first `graph`/`flowchart` keyword only; a later one is text. */\n firstGraph: () => {\n if (this.firstGraphSeen) return false\n this.firstGraphSeen = true\n return true\n }\n }\n\n /**\n * The calls the grammar makes, as the plain object it copies them from: JISON copies `yy`'s\n * enumerable properties into its own state, which leaves out a class's methods.\n */\n grammarCalls() {\n return {\n lex: this.lex,\n setDirection: this.setDirection.bind(this),\n setAccTitle: this.setAccTitle.bind(this),\n setAccDescription: this.setAccDescription.bind(this),\n addVertex: this.addVertex.bind(this),\n destructLink: this.destructLink.bind(this),\n addLink: this.addLink.bind(this),\n updateLinkInterpolate: this.updateLinkInterpolate.bind(this),\n updateLink: this.updateLink.bind(this),\n addClass: this.addClass.bind(this),\n setClass: this.setClass.bind(this),\n setLink: this.setLink.bind(this),\n setTooltip: this.setTooltip.bind(this),\n setClickEvent: this.setClickEvent.bind(this),\n addSubGraph: this.addSubGraph.bind(this)\n }\n }\n\n result(title?: string): Flowchart {\n // `style` and `class` statements naming a subgraph style the subgraph, though the grammar\n // reports them as nodes.\n const subgraphIds = new Set(this.subgraphs.map((subgraph) => subgraph.id))\n for (const subgraph of this.subgraphs) {\n const node = this.nodes.get(subgraph.id)\n if (!node) continue\n subgraph.styles.push(...node.styles)\n subgraph.classes.push(...node.classes)\n }\n return {\n direction: this.dir,\n nodes: [...this.nodes.values()].filter((node) => !subgraphIds.has(node.id)),\n edges: this.edges.map((edge) => ({\n ...edge,\n styles: [...this.defaultEdgeStyle, ...edge.styles]\n })),\n subgraphs: this.subgraphs,\n classDefs: this.classDefs,\n title,\n accessibleTitle: this.accessibleTitle,\n accessibleDescription: this.accessibleDescription\n }\n }\n\n setDirection(dir: string): void {\n this.dir = direction(dir)\n }\n\n setAccTitle(text: string): void {\n this.accessibleTitle = text\n }\n\n setAccDescription(text: string): void {\n this.accessibleDescription = text\n }\n\n addVertex(\n id: string,\n text?: GrammarText,\n type?: string,\n styles?: string[],\n classes?: string[],\n _dir?: string,\n _props?: Record<string, unknown>,\n metadata?: string\n ): void {\n if (!id || id.trim().length === 0) return\n const data = metadata === undefined ? undefined : shapeData(metadata)\n // An edge's id, or `@{ … }` after a subgraph's, names that edge or subgraph, not a node;\n // the data it carries is animation and the like, which nothing here draws.\n if (this.edges.some((edge) => edge.id === id) || (data && this.isSubgraph(id))) return\n let node = this.nodes.get(id)\n if (!node) {\n node = {\n id,\n label: { text: id, format: 'text' },\n shape: 'rect',\n classes: [],\n styles: []\n }\n this.nodes.set(id, node)\n }\n if (text) node.label = readLabel(text)\n if (type !== undefined) node.shape = bracketShape(type)\n if (styles) node.styles.push(...styles)\n if (classes) node.classes.push(...classes)\n if (!data) return\n if (typeof data.shape === 'string') {\n const shape = data.shape === data.shape.toLowerCase() ? shapeNamed(data.shape) : null\n if (!shape) throw new Error(`No such shape: ${data.shape}.`)\n node.shape = shape\n }\n if (typeof data.label === 'string') {\n node.label = readLabel({\n text: data.label,\n type: data.labelType === 'text' || data.labelType === 'string' ? 'text' : 'markdown'\n })\n }\n }\n\n destructLink(end: string, start?: string): GrammarLink {\n const info = this.endOfLink(end)\n if (!start) return info\n const begin = this.startOfLink(start)\n if (begin.stroke !== info.stroke) return { type: 'INVALID', stroke: 'INVALID' }\n if (begin.type === 'arrow_open') return { ...info, type: info.type }\n if (begin.type !== info.type) return { type: 'INVALID', stroke: 'INVALID' }\n return { ...info, type: `double_${begin.type}` }\n }\n\n addLink(starts: string[], ends: string[], link: GrammarLink): void {\n const id = link.id?.replace('@', '')\n for (const from of starts) {\n for (const to of ends) {\n // In `A e1@--> B & C`, the id names the edge from the last start to the first end.\n const named = from === starts.at(-1) && to === ends[0]\n this.addEdge(from, to, link, named ? id : undefined)\n }\n }\n }\n\n updateLinkInterpolate(): void {\n // Curve styles are Mermaid's renderer's; connectors take their own line type.\n }\n\n updateLink(positions: ('default' | number)[], styles: string[]): void {\n for (const position of positions) {\n if (position === 'default') {\n this.defaultEdgeStyle = styles\n continue\n }\n const edge = this.edges.at(position)\n if (!edge || position < 0) {\n throw new Error(\n `The index ${position} for linkStyle is out of bounds. Valid indices for linkStyle are between 0 and ${this.edges.length - 1}.`\n )\n }\n edge.styles = styles\n }\n }\n\n addClass(ids: string, styles: string[]): void {\n // Commas and semicolons separate declarations; an escaped comma, as in `font-family:a\\,b`,\n // is part of one.\n const declarations = styles\n .join(',')\n .split(/(?<!\\\\)[,;]/)\n .map((declaration) => declaration.replaceAll('\\\\,', ','))\n for (const id of ids.split(',')) {\n const existing = this.classDefs.get(id) ?? []\n this.classDefs.set(id, [...existing, ...declarations])\n }\n }\n\n setClass(ids: string, className: string): void {\n for (const id of ids.split(',')) {\n const subgraph = this.subgraphs.find((candidate) => candidate.id === id)\n if (subgraph) subgraph.classes.push(className)\n else this.nodes.get(id)?.classes.push(className)\n }\n }\n\n setLink(ids: string, href: string, target?: string): void {\n for (const id of ids.split(',')) {\n const node = this.nodes.get(id)\n if (node) node.link = target ? { href, target } : { href }\n }\n }\n\n setTooltip(ids: string, tooltip?: string): void {\n if (tooltip === undefined) return\n for (const id of ids.split(',')) {\n const node = this.nodes.get(id)\n if (node) node.tooltip = tooltip\n }\n }\n\n setClickEvent(): void {\n // Callbacks run scripts on Mermaid's page; a design layer has none to run.\n }\n\n addSubGraph(\n idText: GrammarText | undefined,\n list: unknown[],\n titleText: GrammarText | undefined\n ): string {\n // `subgraph Some title` gives the title as the id too; an id with spaces is no id.\n let id = idText?.text.trim()\n if (idText && idText === titleText && /\\s/.test(idText.text)) id = undefined\n let dir: FlowDirection | undefined\n const members: string[] = []\n for (const item of list.flat()) {\n if (isDirectionStatement(item)) {\n dir = direction(item.value)\n continue\n }\n if (typeof item !== 'string' || item.trim() === '' || members.includes(item)) continue\n members.push(item)\n }\n const subgraphId = id ?? `subGraph${this.subgraphCount}`\n this.subgraphCount++\n // A node belongs to the subgraph that closes first, which is the innermost one, and a\n // subgraph never holds itself.\n const own = members.filter(\n (member) =>\n member !== subgraphId &&\n !this.subgraphs.some((subgraph) => subgraph.members.includes(member))\n )\n const existing = this.subgraphs.find((subgraph) => subgraph.id === subgraphId)\n if (existing) {\n // A repeated id adds to the first declaration, which keeps its title and direction.\n existing.members.push(...own)\n return subgraphId\n }\n this.subgraphs.push({\n id: subgraphId,\n title: titleText ? readLabel(titleText) : { text: '', format: 'text' },\n members: own,\n direction: dir,\n classes: [],\n styles: []\n })\n return subgraphId\n }\n\n private isSubgraph(id: string): boolean {\n return this.subgraphs.some((subgraph) => subgraph.id === id)\n }\n\n private addEdge(from: string, to: string, link: GrammarLink, id?: string): void {\n const label = link.text && readLabel(link.text)\n const edgeId =\n id && !this.edges.some((edge) => edge.id === id)\n ? id\n : `L_${from}_${to}_${this.edges.filter((edge) => edge.from === from && edge.to === to).length}`\n this.edges.push({\n id: edgeId,\n from,\n to,\n ...(label && label.text !== '' ? { label } : {}),\n ...arrowheads(link.type),\n stroke: STROKES[link.stroke] ?? 'normal',\n length: Math.min(link.length ?? 1, MAX_EDGE_LENGTH),\n styles: []\n })\n }\n\n private startOfLink(text: string): { type: string; stroke: string } {\n let rest = text.trim()\n let type = 'arrow_open'\n const head = rest[0]\n const opening = head && START_HEADS[head]\n if (opening) {\n type = opening\n rest = rest.slice(1)\n }\n let stroke = 'normal'\n if (rest.includes('=')) stroke = 'thick'\n if (rest.includes('.')) stroke = 'dotted'\n return { type, stroke }\n }\n\n private endOfLink(text: string): GrammarLink {\n const link = text.trim()\n let line = link.slice(0, -1)\n let type = 'arrow_open'\n const tail = link.slice(-1)\n const head = END_HEADS.get(tail)\n if (head) {\n type = head.type\n if (link.startsWith(head.opening)) {\n type = `double_${type}`\n line = line.slice(1)\n }\n }\n let stroke = 'normal'\n let length = line.length - 1\n if (line.startsWith('=')) stroke = 'thick'\n if (line.startsWith('~')) stroke = 'invisible'\n const dots = line.split('.').length - 1\n if (dots) {\n stroke = 'dotted'\n length = dots\n }\n return { type, stroke, length }\n }\n}\n"],"mappings":";;;;;;;AAeA,SAAS,UAAU,OAA2B;CAC5C,IAAI,OAAO;CAEX,MAAM,QAAQ,MAAM,WAAW;CAC/B,KAAK,IAAI,OAAO,MAAM,IAAI,GAAG,MAAM,OAAO,MAAM,IAAI,GAClD,IAAI,KAAK,aAAa,WAAW,WAAW,MAAM,QAAQ,KAAK;MAC1D,IAAI,KAAK,aAAa,MAAM,QAAQ;MACpC,IAAI,gBAAgB,MACvB,KAAK,MAAM,SAAS,KAAK,WAAW,WAAW,GAAG,MAAM,KAAK,KAAK;CAEtE,OAAO;AACT;;;;;;AAOA,SAAgB,UAAU,O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I,MAAM;GACR,SAAS;GACT,SAAS;EACX;EACA,OAAO;GAAE;GAAM;GAAQ;EAAO;CAChC;AACF"}
|
package/package.json
CHANGED
package/src/label.ts
CHANGED
|
@@ -14,13 +14,16 @@ type HTMLNode = DefaultTreeAdapterTypes.ChildNode
|
|
|
14
14
|
|
|
15
15
|
/** The text HTML shows: its text nodes, and a line break for each `<br>`. */
|
|
16
16
|
function shownText(nodes: HTMLNode[]): string {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
let text = ''
|
|
18
|
+
// A label can nest more tags than the call stack holds, so walk them with a stack of our own.
|
|
19
|
+
const stack = nodes.toReversed()
|
|
20
|
+
for (let node = stack.pop(); node; node = stack.pop()) {
|
|
21
|
+
if (node.nodeName === '#text' && 'value' in node) text += node.value
|
|
22
|
+
else if (node.nodeName === 'br') text += '\n'
|
|
23
|
+
else if ('childNodes' in node)
|
|
24
|
+
for (const child of node.childNodes.toReversed()) stack.push(child)
|
|
25
|
+
}
|
|
26
|
+
return text
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
/**
|