Skip to content
D
Documentation

classes

reference
2 min readUpdated

Import these from @grafloria/engine.

Classes

ASTTransformer

ts
class ASTTransformer

Methods

  • transform(ast: DiagramNode, options: TransformOptions = {}): DiagramModel — Transform AST into DiagramModel
  • resetAutoPosition(startPosition: { x: number; y: number }): void — Reset auto-positioning state

BidirectionalSync

ts
class BidirectionalSync

Methods

  • constructor(options: SyncOptions = {})
  • initialize(diagram: DiagramModel, initialText?: string): void — Initialize sync with diagram and initial text
  • onTextChange(newText: string): void — Update text (called when user edits text)
  • markVisualEdit(): void — Mark next changes as from visual editor
  • markTextEdit(): void — Mark next changes as from text editor
  • getCurrentText(): string — Get current text
  • getDiagram(): DiagramModel | undefined — Get current diagram
  • getState(): Readonly<SyncState> — Get sync state
  • onSync(callback: SyncCallback): () => void — Add sync callback
  • pause(): void — Pause sync
  • resume(): void — Resume sync
  • forceSync(direction: 'text-to-visual' | 'visual-to-text'): void — Force sync in specific direction
  • dispose(): void — Dispose and cleanup

DiagramAnalyzer

ts
class DiagramAnalyzer

Methods

  • analyze(diagram: DiagramModel): DiagramAnalysis — Analyze diagram structure

DSLFormatter

ts
class DSLFormatter

Methods

  • constructor(options: FormatterOptions = {})
  • format(text: string): string — Format DSL text
  • wrapLongLines(text: string): string — Wrap long lines
  • normalizeWhitespace(text: string): string — Normalize whitespace
  • removeComments(text: string): string — Remove comments
  • addSectionHeaders(text: string): string — Add section headers
  • prettyPrint(text: string, addHeaders: boolean = false): string — Pretty print with all formatting options
  • minify(text: string): string — Minify (remove all formatting)

DSLGenerator

ts
class DSLGenerator

Methods

  • constructor()
  • generate(diagram: DiagramModel, options: GeneratorOptions = {}): string — Generate DSL text from diagram

IntegratedSyncManager

ts
class IntegratedSyncManager

Methods

  • constructor(options: IntegratedSyncOptions = {})
  • initialize(diagram: DiagramModel, initialText?: string): void — Initialize with diagram and optional initial text
  • onTextEdit(newText: string): void — Handle text editor changes
  • onVisualEdit(): void — Handle visual editor changes
  • getText(): string — Get current text
  • getDiagram(): DiagramModel | undefined — Get current diagram
  • getStatus(): SyncStatus — Get sync status
  • getMetrics(): SyncMetrics — Get sync metrics
  • async applyLayout(presetId?: string): Promise<void> — Apply layout to current diagram
  • suggestLayout(): LayoutSuggestion | null — Get layout suggestion
  • onTextChange(callback: TextChangeCallback): () => void — Subscribe to text changes
  • onDiagramChange(callback: DiagramChangeCallback): () => void — Subscribe to diagram changes
  • onStatusChange(callback: StatusCallback): () => void — Subscribe to status changes
  • pause(): void — Pause sync
  • resume(): void — Resume sync
  • forceSync(direction: 'text-to-visual' | 'visual-to-text'): void — Force sync in specific direction
  • resetMetrics(): void — Reset metrics
  • getFormattedStatus(): string — Get formatted status string
  • getMetricsSummary(): string — Get metrics summary
  • dispose(): void — Dispose and cleanup

LayoutApplicator

ts
class LayoutApplicator

Methods

  • constructor(options: LayoutApplicatorOptions = {})
  • async applyOptimalLayout( diagram: DiagramModel, ast?: DiagramNode ): Promise<LayoutApplicationResult> — Detect and apply optimal layout
  • async applyLayoutPreset(diagram: DiagramModel, presetId: string): Promise<void> — Apply a specific layout preset.
  • getLayoutRegistry(): LayoutRegistry — The registry presets are applied through. Injectable, so a host that has replaced a built-in layout (or registered its own) gets its version here too rather than a second, private copy of the built-ins.
  • setLayoutRegistry(registry: LayoutRegistry): void
  • async applyCustomLayout( diagram: DiagramModel, config: LayoutConfiguration ): Promise<LayoutApplicationResult> — Apply layout with custom configuration
  • suggestLayout(diagram: DiagramModel, ast?: DiagramNode): LayoutSuggestion — Get layout suggestion without applying
  • listPresets(): Array<{ id: string; name: string; category: string }> — List all available presets
  • setMinConfidence(threshold: number): void — Set minimum confidence threshold
  • addCustomLayout(id: string, config: LayoutConfiguration): void — Add custom layout preset
  • removeCustomLayout(id: string): boolean — Remove custom layout preset

LayoutDetector

ts
class LayoutDetector

Methods

  • detect(diagram: DiagramModel, ast?: DiagramNode): LayoutSuggestion — Detect optimal layout for a diagram

Lexer

ts
class Lexer

Methods

  • constructor(input: string)
  • tokenize(): Token[] — Tokenize the entire input

ParseError

ts
class ParseError extends Error

Properties

NameTypeDefaultDescription
namestring
messagestring
stack?string

Methods

  • constructor( message: string, public token: Token, public line: number, public column: number )

Parser

ts
class Parser

Methods

  • getErrors(): ParseError[] — The errors the last parse() RECOVERED from.
  • parse(tokens: Token[]): DiagramNode — Parse tokens into an AST

SyncStateManager

ts
class SyncStateManager

Methods

  • startSync(direction: SyncDirection): void — Mark sync as started
  • completeSync(direction: SyncDirection, duration: number): void — Mark sync as completed
  • failSync(error: string): void — Mark sync as failed
  • recordConflict( sources: [SyncDirection, SyncDirection], resolution: ConflictInfo['resolution'] ): void — Record a conflict
  • getStatus(): Readonly<SyncStatus> — Get current status
  • getMetrics(): Readonly<SyncMetrics> — Get metrics
  • getConflicts(limit: number = 10): ConflictInfo[] — Get recent conflicts
  • onStatusChange(callback: StatusChangeCallback): () => void — Subscribe to status changes
  • resetMetrics(): void — Reset metrics
  • getFormattedStatus(): string — Get formatted status for display
  • getMetricsSummary(): string — Get metrics summary

Was this page helpful?