Sign in

    diagrams

    Diagramming for MoonBit: Mermaid, PlantUML, Draw.io, Graphviz DOT and more

    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    17 hours ago
    Downloads
    16

    No dependencies

    #moonrockz/diagrams

    Diagramming for MoonBit. The library will support formats such as Mermaid, PlantUML, Draw.io and Graphviz DOT.

    Each diagram kind has one model that does not depend on a format. All formats of that kind read into it and write from it. The packages are:

    PackageContents
    moonrockz/diagramsDiagnostic, Severity, Span and Position, which all modules use
    moonrockz/diagrams/sequenceThe immutable Sequence model, links, render properties and link resolution
    moonrockz/diagrams/renderThe Renderer trait, the Diagram enum and the Rendered result

    moonrockz/diagrams-mermaid reads Mermaid into these models, and moonrockz/diagrams-svg renders them as SVG. Requirements come as OpenSpec changes in openspec/changes/.

    #Sequence values

    Sequence holds ordered participants and events, a title and accessibility fields. Events are messages, notes, activation starts and ends, creation, destruction, nested frames and autonumber changes. Frames have one or more sections; each section has an optional label and ordered events. Constructors copy caller-owned arrays, including arrays nested in sections and notes.

    Participants have a declared kind, an optional box group, a link and render properties. Messages have a line style, a head at each end, an optional number, a link and render properties. Participant::with_properties and Message::with_properties return new values. Participant::render_kind chooses the render property kind and otherwise returns the declared kind.

    A Link has a typed LinkScheme, Smithy or OpenRpc, and a target string. Smithy targets use canonical IDs such as example.weather#Weather.

    Implement LinkSource for a pure source adapter and call resolve(sequence,source). Its participant and message methods return optional render properties for a link. Resolution visits nested frame sections, returns a new sequence and preserves participant and event order, labels, links, groups, numbering and metadata. An absent target produces a warning with code sequence/unresolved-link and the target, and preserves any existing properties. Source adapters cannot replace the diagram structure through this contract. The Smithy and OpenRPC adapters belong to later changes.

    Diagnostic

    pub(all) struct Diagnostic {
    code : String
    severity : Severity
    message : String
    span : Span?
    } derive(Eq,
    Debug
    )

    A problem that a reader, a converter or a renderer found. code is stable, for example mermaid/unknown-statement. span is absent when the problem has no place in a source text.

    Diagnostic::equal

    fn Diagnostic::equal(Diagnostic, Diagnostic) -> Bool

    Diagnostic::error

    fn Diagnostic::error(code : String, message : String, span? : Span) -> Diagnostic

    An error diagnostic.

    Diagnostic::not_equal

    fn Diagnostic::not_equal(x : Diagnostic, y : Diagnostic) -> Bool

    Diagnostic::warning

    fn Diagnostic::warning(code : String, message : String, span? : Span) -> Diagnostic

    A warning diagnostic.

    Position

    pub(all) struct Position {
    offset : Int
    line : Int
    column : Int
    } derive(Eq,
    Debug
    )

    A place in a source text. offset counts UTF-16 code units from the start. line and column start at 1, and column also counts UTF-16 code units.

    Position::equal

    fn Position::equal(Position, Position) -> Bool

    Position::not_equal

    fn Position::not_equal(x : Position, y : Position) -> Bool

    Position::to_repr

    Severity

    pub(all) enum Severity {
    Error
    Warning
    Info
    } derive(Eq,
    Debug
    )

    How serious a diagnostic is.

    Severity::equal

    fn Severity::equal(Severity, Severity) -> Bool

    Severity::not_equal

    fn Severity::not_equal(x : Severity, y : Severity) -> Bool

    Severity::to_repr

    Span

    pub(all) struct Span {
    start : Position
    end : Position
    } derive(Eq,
    Debug
    )

    The half-open range from start to end in a source text.

    Span::equal

    fn Span::equal(Span, Span) -> Bool

    Span::not_equal

    fn Span::not_equal(x : Span, y : Span) -> Bool

    Span::to_repr

    version

    fn version() -> String

    The module version, kept in sync with the root moon.mod.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io