### Mermaid Flowchart Example Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Generate a Mermaid flowchart using the graph TD syntax. This example demonstrates a CI pipeline with stages for pushing code, running tests, building images, and deployment. ```mermaid graph TD subgraph ci [CI Pipeline] A[Push Code] --> B{Tests Pass?} B -->|Yes| C[Build Image] B -->|No| D[Fix & Retry] D -.-> A end C --> E([Deploy Staging]) E --> F{QA Approved?} F -->|Yes| G((Production)) F -->|No| D ``` -------------------------------- ### ER Diagram Example Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Illustrates the relationships between CUSTOMER, ORDER, PRODUCT, and LINE_ITEM entities. Useful for database schema visualization. ```mermaid erDiagram CUSTOMER { int id PK string name string email UK } ORDER { int id PK date created int customer_id FK } PRODUCT { int id PK string name float price } LINE_ITEM { int id PK int order_id FK int product_id FK int quantity } CUSTOMER ||--o{ ORDER : places ORDER ||--|{ LINE_ITEM : contains PRODUCT ||--o{ LINE_ITEM : includes ``` -------------------------------- ### Swift Package Manager Installation Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Add BeautifulMermaid to your Swift Package Manager dependencies in Package.swift. ```swift dependencies: [ .package(url: "https://github.com/lukilabs/beautiful-mermaid-swift", from: "1.0.0") ] ``` ```swift .target( name: "YourTarget", dependencies: [.product(name: "BeautifulMermaid", package: "beautiful-mermaid-swift")] ) ``` -------------------------------- ### Class Diagram Example Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Defines an abstract class 'Animal' and its subclasses 'Mammal', 'Bird', 'Dog', 'Cat', and 'Parrot'. Use this for object-oriented structure representation. ```mermaid classDiagram class Animal { <> +String name +int age +eat() void +sleep() void } class Mammal { +bool warmBlooded +nurse() void } class Bird { +bool canFly +layEggs() void } class Dog { +String breed +bark() void } class Cat { +bool isIndoor +purr() void } class Parrot { +String vocabulary +speak() void } Animal <|-- Mammal Animal <|-- Bird Mammal <|-- Dog Mammal <|-- Cat Bird <|-- Parrot ``` -------------------------------- ### Import VS Code Shiki Theme Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Import a VS Code color theme by providing its background, foreground, and focus border colors, along with token colors. This allows for custom theming of diagrams. ```swift let shikiTheme = DiagramTheme.ShikiTheme( type: "dark", colors: [ "editor.background": "#1e1e1e", "editor.foreground": "#d4d4d4", "focusBorder": "#007acc" ], tokenColors: [] ) let theme = DiagramTheme.fromShikiTheme(shikiTheme) ``` -------------------------------- ### Configure Layout Options Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Sets custom layout configuration for the Mermaid renderer. Allows adjustment of padding, node spacing, layer spacing, and component spacing. ```swift let config = LayoutConfig( padding: 20, nodeSpacing: 40, layerSpacing: 60, componentSpacing: 40 ) let renderer = MermaidImageRenderer() renderer.layoutConfig = config ``` -------------------------------- ### Generate Sequence Diagram in Mermaid Syntax Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Use this syntax to define actors, participants, and the flow of messages between them to create a sequence diagram. This is the core syntax for defining sequence diagrams. ```mermaid sequenceDiagram actor U as User participant App as Client App participant Auth as Auth Server participant API as Resource API U->>App: Click Login App->>Auth: Authorization request Auth->>U: Login page U->>Auth: Credentials Auth-->>App: Authorization code App->>Auth: Exchange code for token Auth-->>App: Access token App->>API: Request + token API-->>App: Protected resource App-->>U: Display data ``` -------------------------------- ### Basic Mermaid Rendering Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Render Mermaid code into image, SVG, or ASCII art formats using MermaidRenderer. Requires importing BeautifulMermaid. ```swift import BeautifulMermaid let mermaidCode = """ graph TD A[Start] --> B{Decision} B -->|Yes| C[Do Something] B -->|No| D[Do Something Else] C --> E[End] D --> E """ // Render as image let image = try MermaidRenderer.renderImage(source: mermaidCode) // Render as SVG let svg = try MermaidRenderer.renderSVG(source: mermaidCode, theme: .tokyoNight) // Render as ASCII art let ascii = try MermaidRenderer.renderASCII(source: mermaidCode, theme: .zincDark) ``` -------------------------------- ### Async Rendering Methods Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Perform rendering operations asynchronously for background processing. Use async variants of render methods like renderImageAsync, renderSVGAsync, and renderASCIIAsync. ```swift let image = try await MermaidRenderer.renderImageAsync(source: mermaidCode, theme: .nord) let svg = try await MermaidRenderer.renderSVGAsync(source: mermaidCode) let ascii = try await MermaidRenderer.renderASCIIAsync(source: mermaidCode) ``` -------------------------------- ### Exporting Diagrams as PNG/JPEG Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Use MermaidImageRenderer to export diagrams as PNG or JPEG data. Customize theme and scale before rendering. ```swift let renderer = MermaidImageRenderer() renderer.theme = .dracula renderer.scale = 3.0 let pngData = try renderer.renderPNG(from: mermaidCode) let jpegData = try renderer.renderJPEG(from: mermaidCode, quality: 0.9) ``` -------------------------------- ### Two-Color Diagram Theme Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Define a basic diagram theme using only background and foreground colors. The system derives other colors automatically. ```swift let theme = DiagramTheme( background: "#1a1b26", // Background color foreground: "#c0caf5" // Text/line color ) ``` -------------------------------- ### Mermaid State Diagram Syntax Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md This is the core syntax for defining a state diagram in Mermaid. It outlines the states and the transitions between them, including labels for transitions. ```mermaid stateDiagram-v2 [*] --> Closed Closed --> Connecting : connect Connecting --> Connected : success Connecting --> Closed : timeout Connected --> Disconnecting : close Connected --> Reconnecting : error Reconnecting --> Connected : success Reconnecting --> Closed : max_retries Disconnecting --> Closed : done Closed --> [*] ``` -------------------------------- ### Render Mermaid Image Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Renders a Mermaid diagram from source code into an image. Supports theme and scale options for customization. The default scale is 2.0 for Retina displays. ```swift let image = try MermaidRenderer.renderImage( source: code, theme: .tokyoNight, scale: 2.0 // Retina scale (default: 2.0) ) ``` -------------------------------- ### Enriched Diagram Theme Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Create a more customized diagram theme by optionally providing accent, muted, surface, and border colors in addition to background and foreground. ```swift let theme = DiagramTheme( background: "#1a1b26", foreground: "#c0caf5", line: "#565f89", // Edge lines accent: "#7aa2f7", // Highlighted elements muted: "#414868", // De-emphasized elements surface: "#24283b", // Node backgrounds border: "#414868" // Node borders ) ``` -------------------------------- ### SwiftUI Mermaid Diagram View Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Integrate Mermaid diagrams into SwiftUI views using the MermaidDiagramView. Specify the Mermaid source and theme. ```swift import SwiftUI import BeautifulMermaid struct ContentView: View { var body: some View { MermaidDiagramView( source: "graph TD; A-->B; B-->C;", theme: .catppuccinMocha ) } } ``` -------------------------------- ### UIKit/AppKit Mermaid View Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Use MermaidView, a native UIView/NSView subclass, to display Mermaid diagrams in UIKit or AppKit applications. Set the source and theme properties. ```swift import BeautifulMermaid let mermaidView = MermaidView(frame: CGRect(x: 0, y: 0, width: 400, height: 300)) mermaidView.source = "graph TD; A-->B; B-->C;" mermaidView.theme = .catppuccinMocha view.addSubview(mermaidView) ``` -------------------------------- ### XY Chart Definition Source: https://github.com/lukilabs/beautiful-mermaid-swift/blob/main/README.md Defines an XY chart with a title, x-axis labels, y-axis range, and data for bars and lines. This is the Mermaid syntax used to generate the chart. ```mermaid xychart-beta title "Sales Revenue" x-axis [jan, feb, mar, apr, may, jun] y-axis "Revenue (in $)" 4000 --> 11000 bar [5000, 6000, 7500, 8200, 9800, 10500] line [5000, 6000, 7500, 8200, 9800, 10500] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.