Repository navigation
Mermaid Phase 2a: native class diagrams (unified renderer + dagre), Viewer, CLI and Pandoc support - #126
Merged
Conversation
Adds the DemaConsulting.CanvasNet.Mermaid package (core-only) and its test project, wired into CanvasNet.slnx. Units: - MermaidDocument (public API): MermaidDocument (Parse/Open/Measure/Render, IsSupported, metadata), MermaidOpenOptions, MermaidRenderOptions (Theme, Config, ThemeNames), MermaidLimits, MermaidLocation, MermaidDiagnostic, MermaidDiagnosticCodes, MermaidUnsupportedFeature, MermaidSize, the three exceptions, MermaidImageSource (theme fragment), internal MermaidReportSink and the pipeline seam (IMermaidDiagram, DiagramRenderContext, DiagramRegistry, temporary PendingDiagram for flowchart). - Syntax: Preprocessor (+ MappedText location map), DiagramDetector (all 40 mermaid 11.17.2 detectors in order), YamlSubsetParser (js-yaml 4.3.0 loader port, JSON_SCHEMA types; anchors/aliases/tags refused), SourceScanner (+ ScanPatterns, TokenCursor). - Scenegraph: SceneModel, ScenePainter (+ Text, Images). - third-party: README, LICENSE-mermaid.txt, LICENSE-js-yaml.txt. - benchmarks/visual-diff/mermaid/extract-sources.mjs (developer script). Known types other than flowchart give mermaid-diagram-unsupported with a 16x16 transparent picture (strict mode throws). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Units (Configuration subsystem): MermaidConfigResolver (+ MermaidConfig, Defaults, Merge, Validation), ThemeResolver (+ Default, Base, Dark, Forest, Neutral, Styles / FlowchartStyles), ColorMath (khroma 2.1.0 port), StyleDeclarations. - Effective configuration as mermaid 11.17.2 builds it: defaults < Theme option < Config (initialize, as mmdc -t/-c) < frontmatter config < init/initialize directives; assignWithDepth, lodash merge, sanitizeDirective, sanitize, detectInit (config key move), wrap, the flowchart init (layout, arrowMarkerAbsolute). - Located warnings: mermaid-config-secure-key, mermaid-config-unknown-key (nearest key hint), mermaid-config-invalid (JSON, wrong type dropped, refused strings, themes this version does not have, theme variables that are not colors). - Five themes with exact derivation order; flowchart and global style rules as resolved paint/font records; themeCSS rules of known selectors, others reported as mermaid-theme-css-unsupported; style subset with !important and mermaid-style-ignored. - The resolved configuration is in DiagramRenderContext.Config; the text's configuration drives the detector settings at open time. - Upstream vectors (622 khroma calls, 53 configurations incl. all 5 themes with and without themeVariables and darkMode) generated from the pinned mermaid in headless Chrome by benchmarks/visual-diff/mermaid/gen-theme-vectors.mjs; all match exactly. - third-party: LICENSE-khroma.txt and the provenance rows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Faithful port of graphlib and dagre from dagre-d3-es 7.0.14 (the version mermaid 11.17.2 uses), with JavaScript object key order, V8 sort steps and lodash semantics, metered by a per-diagram LayoutWorkMeter. Units: Graphlib (Graph, GraphEdge, ObjectKeyMap, GraphAlgorithms); Dagre (DagreLayout + Util, DagreAcyclic, DagreRanker + FeasibleTree + NetworkSimplex, DagreNesting, DagreNormalizer, DagreOrdering + Sort + CrossCount + Constraints, DagrePositioning + BrandesKoepf, DagreCoordinateSystem, LayoutWorkMeter, Lodash, DagreGraph, LayoutModel). Stage goldens: benchmarks/visual-diff/mermaid/gen-dagre-goldens.mjs runs dagre-d3-es on 224 seeded graphs (DAGs, cycles, nested clusters, labels, self loops, numeric ids, every rankdir, ranker and alignment); all 224 match exactly (ranks, orders, coordinates within 1e-9). Ported dagre unit cases per stage, work-meter pins, K30 limit and cancellation tests. Notices: LICENSE-dagre.txt and LICENSE-lodash.txt with provenance rows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Units (for the chunk 9 companion docs): - Flowchart/FlowchartParser (FlowchartParser.cs, .Lexer.cs with FlowchartTokens, .Statements.cs, .Links.cs): hand-written port of flow.jison (122 lexer rules, 21 start conditions, recursive-descent grammar, jison expected-token lists) - Flowchart/FlowchartModel (FlowchartModel.cs, .Elements.cs, .LayoutData.cs): port of flowDb.ts, getData() to LayoutData, unsupported-feature reports - Rendering/LayoutData (LayoutData, LayoutNode, LayoutEdge) and Rendering/ShapeNames (the 53 shapes + aliases registry; part of ShapeLibrary) - Syntax/HtmlSanitizer: Mermaid's sanitizeText (DOMPurify) for labels - MermaidDocument: DiagramRegistry parses flowcharts; PendingDiagram removed - Vectors: gen-flowchart-vectors.mjs + flowchart-vector-cases.mjs (207 original cases), Fixtures/upstream-vectors/flowchart-parser.json; 42 original Fixtures/flowchart/*.mmd for the chunk 6 goldens Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Chunk 5a of the rendering subsystem (node-level building blocks; cluster layout, edges and the pipeline follow in chunk 5b). Units: - Rendering/LabelBuilder (+ .Markdown, .MarkdownLexer, .Html, .Svg): createText / handle-markdown-text / splitText semantics, HTML-label rules (1.5 em lines, nowrap then break-spaces retry at the wrapping width, layout units of 1/64 px), SVG-label rules (tspans 1.1 em apart, getBBox with rounded ascent/descent), the HTML subset with mermaid-html-tag-ignored, fa: removal, mermaid-text-missing-glyph - Rendering/ShapeLibrary (+ .Basic, .Extended, .Images, .Intersect, .Parts): every v11 shape a flowchart can name (53 documented + aliases, legacy bracket shapes, state, choice, note, composite, anchor, icon/image shapes, collapsedGroup, the legacy ellipse) in the classic look, sized as insertMeasuredNode, with label placement, paint and intersect - Rendering/NodeImages: pictures only through the caller's resolver, natural sizes, mermaid-image-unresolved, MaxImages budget - Syntax/HtmlEntities: HTML 4 named references (HtmlSanitizer uses them) - benchmarks/visual-diff/mermaid/gen-shape-vectors.mjs and Fixtures/upstream-vectors/shapes.json (286 Chrome-measured cases) - third-party: LICENSE-marked.txt and the provenance rows Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Units: Rendering/ClusterLayout (+ .Extractor, .SelfLoops: dagre/index.js, mermaid-graphlib.js), Rendering/EdgeBuilder (+ .Curves: d3-shape curves, .Markers: markers.js/edgeMarker.ts), ShapeLibrary.Clusters (clusters.js rect, labelRect), FlowchartModel.Render (flowRenderer-v3-unified draw, insertTitle, setupViewPortForSVG). Flowcharts are now drawn: the render-failed stub is removed, the scene carries its NodeImages to the painter, and MermaidDocument.LayoutScene exposes the scene to tests. Adds third-party/LICENSE-d3.txt (d3-shape, ISC) and the curve vectors of gen-curve-vectors.mjs; tests for EdgeBuilder, ClusterLayout, the Rendering subsystem (checked against mermaid 11.17.2 in Chrome), flowchart system integration (fixtures, pixels, themes, styles, scale, determinism) and hardening (limits, K30, seeded mutation fuzzer). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- benchmarks/visual-diff: render-mermaid.mjs (mermaid-cli renderMermaid in headless Chrome with liberation.css injected before Mermaid measures; PNG at the natural size and the layout read back from the live SVG), liberation.css, compare-with-mermaid.ps1 (reports, never gates), update-mermaid-goldens.ps1, README section (incl. the gen-*.mjs scripts). - 41 flowchart layout goldens under Fixtures/reference with a README (versions, command, provenance, tolerances, 38-unicode exclusion). - MermaidReferenceLayoutTests: view box, node positions and boxes, subgraph rectangles, edges sampled at 21 points, edge label centers; 0.01 px (0.1 px for the two rough.js circle fixtures). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Viewer: SourceKind.Mermaid (.mmd, .mermaid; vector; IsDiagram), the built-in LoaderImageSource for Mermaid with the theme fragment parameter, SourceOptions, InputSelection and DiagramOptions for the theme, SourceInfo.Diagram (DiagramFacts), SourceLoader.Mermaid.cs (probe, page source with exact placement at the natural size or a scale, pictures through the sandboxed resolver, notes) and the exception map (mermaid-error, budget-exceeded, corrupt-input, size-limit, unsupported-feature). Tool: formats row (diagram), info diagram object, --theme for render and inspect, help topic mermaid (alias mmd) with examples, errors/limits/json/svg help, packed Mermaid notices, self-test 17 CanvasNetTool_RenderMermaid. Mermaid: ScenePainter stretches a picture that comes back at another size (preserveAspectRatio none). Units: Viewer SourceLoader (Mermaid partial), LoaderImageSource, InputSelection, SourceModels, ErrorCodes; Tool DiscoveryCommands, RenderCommand, InspectCommand, HelpTopics, Validation; Mermaid ScenePainter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… table Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…m support Adds the CanvasNetMermaid system, platform, MermaidDocument, subsystem (Syntax, Configuration, Graphlib, Dagre, Rendering, Scenegraph, Flowchart) and unit requirements, each linked to tests at its own level, the Viewer and Tool Mermaid requirements, and seven system-level tests (entry points, metadata, syntax errors, configuration precedence, pictures, reports, image source) that back the system requirements. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds the CanvasNetMermaid system design (architecture, interfaces, provenance, limits, fidelity and known differences, phase plan), the subsystem and unit designs, the mirrored verification designs, the definition and introduction updates, and the Viewer and Tool design and verification updates (source loader, discovery, render, help topics, seventeen self-tests). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds the CanvasNetMermaid SysML model (system, MermaidDocument, seven prefixed subsystem part defs and their units), the design views, the usesMermaid dependencies of the Viewer and Tool, and the CanvasNetMermaid review sets (Architecture, Design, Verification, AllRequirements, MermaidDocument, seven subsystems, thirty units) plus the Viewer Mermaid fixtures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add Dagre/NamespaceDoc.cs and list it in the Dagre review set. - Review the gallery diagrams with the Mermaid architecture set and link the gallery tests from CanvasNetMermaid-Flowcharts. - Add real subsystem tests for Syntax (scanner over the parser text, label sanitizing), Rendering (node pictures, MaxImages, reports), Scenegraph (pictures, painted-pixel limit, cancellation) and Flowchart (limits, database errors) and link them in place of the stand-ins. - Correct the HtmlSanitizer bound and the Syntax and Graphlib namespace documentation; remove the unused graphlib Components, Tarjan and FindCycles with their tests, requirements and documentation. - Remove mermaid-class-undefined: Mermaid 11.17.2 records an undefined class silently, so the code was never reported. - Build the default secure-key array with JsonValue.Create so the configuration works with reflection-based JSON disabled. - Document --param and --theme for inspect. - Widen the user-guide FileAssert check to <embed> pictures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…mage source size, filter) - A link still ending at a subgraph when dagre runs (subgraph used as a node of another subgraph, self-loop on a subgraph) now fails with a located mermaid-render-failed at the link, as Mermaid 11.17.2 fails on these diagrams (dagre longestPath: "Cannot set properties of undefined (setting 'rank')"). - Layout defect net: unexpected runtime exceptions of the layout become a located mermaid-render-failed with the original as inner exception; cancellation, documented failures and image-resolver exceptions pass unchanged. - Font sizes that cannot be drawn (zero or infinite in single precision, above 32768 px) are ignored with mermaid-style-ignored and the inherited size kept; dash patterns with an entry above the drawn magnitude are solid, huge dash offsets are reduced by whole periods. - MermaidImageSource takes the natural size without the surface-size check, so a diagram larger than the largest surface draws at a smaller requested size. - canvasnet.lua leaves a picture alone only for its own mermaid-diagram-unsupported report, not for one about an embedded picture (with an origin). - Requirements, design, verification and user guide updated; regression tests and a hostile corpus added. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…yph fallback, wrapping) - Remove the inline cspell:ignore from SourceLoaderMermaidImageTests (terms live in .cspell.yaml) - cluster-layout design: say "the pinned Mermaid" instead of a version number - mermaid help topic: linkStyle supports default and interpolate (matches the guide) - Mermaid system design: Noto draws glyphs Liberation lacks silently; only characters no bundled font has are drawn as the missing-glyph box and reported; fix the 38-unicode note; Known Differences names neo - Fix broken line wrapping and a missing blank line in the branch's docs and requirements Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…hart # Conflicts: # .cspell.yaml
Switch every test, fixture, and document example that used sequenceDiagram as the known-but-unsupported diagram type to classDiagram, so that turning sequence diagrams on in later chunks keeps every test green. No behavior change. - Mermaid.Tests: MermaidTestHelpers.SequenceText becomes ClassText; the MermaidUnsupportedDiagramTests and the MermaidDocument class test are renamed; the configuration and size tests use class text. - Viewer.Tests: new Fixtures/mermaid/class.mmd used by SourceLoaderMermaidTests. - Tool.Tests: render, info, and in-process tests use a class diagram and the renamed tests. - Pandoc filter test script: the unsupported, marker, embedded, and order cases use classDiagram. - Requirements, verification, design, and user guide (Example 53 and the unsupported examples) follow the renamed tests and the new example. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
#123 review) - Viewer: a diagram drawn at its natural size whose picture nodes without w/h enlarge the layout is charged the rest of its surface before it is returned (disposed and refused when it does not fit), and its SourceInfo reports the natural size of the drawn diagram; info still lays out without pictures (no other file is opened by a probe) - Tests: SourceLoader charge/refusal regressions and a CanvasNetViewer MaxDecodedPixels case - Mermaid: comment that the bw / 2 / 2 vertex of the image and icon outline reproduces Mermaid 11.17.2 - Docs: Viewer source-loader requirements, design, and verification; the help topic and user guides note that a load reports (and an embedding render charges) the drawn size Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Foundation for sequence diagrams (still unsupported after this commit): - SequenceConfig with every sequenceDiagram key and its 11.17.2 default, the setConf font overrides (top-level fontFamily/fontSize/fontWeight) and the effective wrap of the diagram's init; typed key validation (number-or-string font sizes and weights, alignment choices). - SequenceStyles: the sequence styles.js rules over the global rules, now shared with FlowchartStyles through DiagramStyles (flowchart rules unchanged), with cascade resolvers and drop-shadow filter parsing. - LabelBuilder text dimensions: calculateTextDimensions, wrapLabel, breakString, parseFontSize and splitBreaks, memoized per render with the lineBreakRegex lastIndex quirk, charged to the layout work meter. - SceneShadow on ScenePath and the box-blur drop shadow in ScenePainter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…is refused (PR #123 review) - Viewer: a diagram its pictures enlarge that does not fit is refused with the pixels of the whole drawn surface and the budget left once the charge before the draw is refunded (as the resolver reports a surface larger than its charge) - Tests: the refusal asserts the requested pixels (SourceLoader and CanvasNetViewer); a scale 2 and 1.5 case checks that the natural size is the scale-1 drawn size and the surface is that size times the scale - Docs: MermaidImages requirement and verification list the scale test; the design notes the refusal and that a diagram its pictures make smaller stays charged at the probed size; the help topic and user guides say the drawn size is charged by a Viewer render without a size (an embedding document always gives a size) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- render-mermaid.mjs reads the sequence layout back from the live SVG (actors top and bottom, lifelines, messages with markers, texts, numbers and central circles, notes, activations, frames, rect backgrounds, boxes, menus, title, paint order, computed paint) - update-mermaid-goldens.ps1 handles flowchart and sequence folders - 24 original sequence fixtures and their goldens - gen-sequence-vectors.mjs and sequence-parser.json (242 cases) - README updates for the harness and the golden format Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…mermaid/phase1b-sequence
Port mermaid 11.17.2's sequenceDiagram.jison and sequenceDb.ts into a new
Sequence namespace (not yet wired into the pipeline; sequence stays
reported as not supported until C5).
- SequenceParser: the 94 lexer rules and start conditions as linear
hand-written matchers (first match, ASCII case folding, jison's \b on
keywords), and a recursive-descent parser that checks jison's merged
LALR lookahead sets, so errors list the same expected tokens in the
same state; statements are applied after the whole parse (yy.apply).
- SequenceModel: participants (insertion order, prev/next, keyword type,
@{type, alias} metadata via YamlSubsetParser, in-place replacement),
boxes (parseBoxData with the browser color check), messages and line
types, notes, blocks, activations, create/destroy, links, link,
properties, autonumber, title and accessibility texts, Mermaid's
database errors, explicit wrap flags resolved per render, MaxNodes,
MaxNestingDepth and MaxLabelLength.
- Tests: parser, model and subsystem tests, and SequenceVectorTests over
all 242 cases of sequence-parser.json.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port of the 11.17.2 sequence renderer (sequenceRenderer.ts draw) and drawing functions (svgDraw.js): SequenceLayout with Mermaid's bounds model, actor margins, message, note and activation placement, the block layout, create and destroy, mirroring, the title and the view box, metered by MaxLayoutWork; and SequenceRenderer with participant boxes and the stick figure, lifelines, every arrow and its SVG markers (placed, scaled and clipped as SVG does), central connection circles, sequence numbers, notes, activations, drawText and byTspan text placement, and Mermaid's paint order. LabelBuilder measures SVG text with the rasterizer's glyph boxes at the ends of a line and collapses white space, as the browser's getBBox does. Not reachable until sequence is enabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SequenceModel implements IMermaidDiagram (no direction; the frontmatter title is the fallback of the title statement; a look other than classic is reported and drawn classic), the detector reports sequence as supported, and the registry parses it. The info text names a sequence diagram's counts participants, messages and boxes. Tests: MermaidSequenceReferenceLayoutTests compares every drawable fixture with its 11.17.2 golden (positions at 0.01 px, text boxes at 0.02 px) with a temporary NotYetDrawn list for the fixtures that need blocks, boxes, other participant types or menus; SequenceLayoutTests, SequenceRendererTests, MermaidSequenceIntegrationTests, the sequence fixtures laid out by SequenceTests, the detector hints, and the Viewer and Tool sequence probe, render and info tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Draw the rest of a sequence diagram as Mermaid 11.17.2 does: block frames (loop, alt/else, opt, par/and, par_over, critical/option, break) with their label boxes and titles, rect backgrounds and boxes lowered behind everything, the boundary, control, entity, database, collections and queue participants, properties classes, menus (sized always, drawn with forceMenus) and the old text placement. Report unknown participant types, $$ math, properties icons and the fo text placement; fail located on an empty block and on links of a type without a box. The reference test now compares frames, rects, boxes and menus, and all 24 sequence goldens pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Nested blocks over MaxNestingDepth, participants over MaxNodes, messages over MaxLabelLength, a wrap bomb and an activation storm against MaxLayoutWork and cancellation, deterministic renders of every sequence fixture, and a seeded mutation fuzzer over the sequence fixtures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update the tool help (mermaid.json with a sequence example, json.json, render and info usage), the Mermaid and Viewer doc comments, the package description and tags, the Pandoc filter header and its test (a sequence block is drawn by the filter), the third-party provenance of the ported sequence sources, the sequence golden tolerances, and the README and user guides (sequence syntax, settings, codes, differences, Example 58, and three gallery diagrams that the widened gallery test renders strictly). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
15 of 19 tasks
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Description
This is Mermaid Phase 2a: native class diagrams (
classDiagramandclassDiagram-v2) inDemaConsulting.CanvasNet.Mermaid. It targets the mermaid 11.17.2 source and builds on 1a (#123), 1b (#124) and #125.Class diagrams render through mermaid's unified renderer path with the existing dagre port, as mermaid v11 does. They work in the library, the Viewer, the
canvasnetCLI and the Pandoc filter. Phase 2 was split to stay under Copilot's 300-file review limit: state and ER diagrams follow in 2b, and pie, gantt and mindmap in Phase 3.What's in it
~T~, and static (underlined) and abstract classifiers;<<interface>>.MaxNodes, as subgraphs are), notes anddirection.classDef,cssClass,:::andstyle.link,clickandcallbackare kept as data and not drawn.Fidelity against mermaid 11.17.2
htmlLabels: false) is within 0.227 px: Chrome rasterizes one bold glyph a pixel wider, which can't be ported (known difference 27).The class known differences are items 27 to 31 in
docs/design/canvas-net-mermaid.md:>tspan fix-up is not ported, and KaTeX is drawn as written (29);Renders (CanvasNet | mermaid-cli | difference, at scale 2)
Relations (SSIM 0.9980)

Namespaces (SSIM 0.9976)

Cardinality labels (SSIM 0.9957)

Notes (SSIM 0.9970)

Type of Change
Related Issues
This is Mermaid support, Phase 2a (after 1a #123, 1b #124 and #125; 2b state/ER and 3 pie/gantt/mindmap follow). There is no issue to close.
Pre-Submission Checklist
Before submitting this pull request, ensure you have completed the following:
Build and Test
pwsh ./build.ps1passed (69,099 tests, 0 failed, 33 skipped symbolic-link tests)Code Quality
Quality Checks
Please run the following checks before submitting:
pwsh ./lint.ps1passed (exit 0)Testing
Documentation
Additional Notes