Skip to content

SfnDiagramGenerator

Defined in: src/index.ts:390

Class-based API for advanced usage with fluent interface

This class allows you to configure diagram options once and generate multiple diagrams with the same settings. Options can be updated using the fluent setOptions() method.

import { SfnDiagramGenerator } from 'sfn-diagram';
const generator = new SfnDiagramGenerator({
theme: 'dark',
layout: 'LR',
nodeWidth: 150
});
// Generate multiple diagrams with the same options
const diagram1 = generator.generateSvg({ aslDefinition: stateMachine1 });
const diagram2 = generator.generateSvg({ aslDefinition: stateMachine2 });
// Update options and generate more
generator.setOptions({ theme: 'light' });
const diagram3 = generator.generateSvg({ aslDefinition: stateMachine3 });
new SfnDiagramGenerator(options?): SfnDiagramGenerator;

Defined in: src/index.ts:410

Create a new diagram generator with default options

SfnDiagramGeneratorOptions = {}

Default diagram options for all subsequent generations. Pass cache (from createLayoutCache) to reuse layouts across renders; omitted, nothing is cached.

SfnDiagramGenerator

const generator = new SfnDiagramGenerator({ theme: 'dark', layout: 'LR' });
const generator = new SfnDiagramGenerator({ cache: createLayoutCache() });
generate(params): SvgOutput;

Defined in: src/index.ts:434

Generate a diagram (auto-detects format from options)

Pass format as a literal ('svg' or 'mermaid') to get the matching output type for this call. 'html' and 'png' throw, as in generateDiagram.

Generation parameters

string | AslDefinition

ASL definition as an object or JSON string

"svg"

Output format for this call only; overrides the constructor’s format. Omitted, the generator’s configured format is used (and the result type is the union).

SvgOutput

SVG output

const { svg } = generator.generate({ aslDefinition: myStateMachine, format: 'svg' });
generate(params): MermaidOutput;

Defined in: src/index.ts:446

Generate a Mermaid diagram for this call, whatever the configured format.

Generation parameters

string | AslDefinition

ASL definition as an object or JSON string

"mermaid"

Output format for this call only; overrides the constructor’s format.

MermaidOutput

Mermaid output

generator.generate({ aslDefinition, format: 'mermaid' }).code;
generate(params):
| SvgOutput
| MermaidOutput;

Defined in: src/index.ts:460

Generate a diagram in the generator’s configured format, or in a per-call format that is not known at compile time.

Generation parameters

string | AslDefinition

ASL definition as an object or JSON string

DiagramFormat

Output format for this call only; overrides the constructor’s format. Omitted, the generator’s configured format is used (and the result type is the union).

| SvgOutput | MermaidOutput

SVG or Mermaid output, based on the per-call or configured format

const result = generator.generate({ aslDefinition: myStateMachine });

generateMermaid(params): MermaidOutput;

Defined in: src/index.ts:504

Generate Mermaid diagram syntax

Generation parameters

string | AslDefinition

ASL definition as an object or JSON string

MermaidOutput

Mermaid output with code and metadata

const { code } = generator.generateMermaid({ aslDefinition: myStateMachine });

generateSvg(params): SvgOutput;

Defined in: src/index.ts:488

Generate an SVG diagram

Generation parameters

string | AslDefinition

ASL definition as an object or JSON string

SvgOutput

SVG output with diagram and metadata

const { svg } = generator.generateSvg({ aslDefinition: myStateMachine });

setOptions(options): this;

Defined in: src/index.ts:523

Update the generator’s default options (fluent interface)

Partial<DiagramOptions>

Partial options to merge with existing options

this

This generator instance for method chaining

generator
.setOptions({ theme: 'dark' })
.setOptions({ layout: 'LR' });
const result = generator.generateSvg({ aslDefinition: myAsl });