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.
Example
Section titled “Example”import { SfnDiagramGenerator } from 'sfn-diagram';
const generator = new SfnDiagramGenerator({ theme: 'dark', layout: 'LR', nodeWidth: 150});
// Generate multiple diagrams with the same optionsconst diagram1 = generator.generateSvg({ aslDefinition: stateMachine1 });const diagram2 = generator.generateSvg({ aslDefinition: stateMachine2 });
// Update options and generate moregenerator.setOptions({ theme: 'light' });const diagram3 = generator.generateSvg({ aslDefinition: stateMachine3 });Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SfnDiagramGenerator(options?): SfnDiagramGenerator;Defined in: src/index.ts:410
Create a new diagram generator with default options
Parameters
Section titled “Parameters”options?
Section titled “options?”SfnDiagramGeneratorOptions = {}
Default diagram options for all subsequent generations. Pass cache
(from createLayoutCache) to reuse layouts across renders; omitted, nothing is cached.
Returns
Section titled “Returns”SfnDiagramGenerator
Examples
Section titled “Examples”const generator = new SfnDiagramGenerator({ theme: 'dark', layout: 'LR' });const generator = new SfnDiagramGenerator({ cache: createLayoutCache() });Methods
Section titled “Methods”generate()
Section titled “generate()”Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”params
Section titled “params”Generation parameters
aslDefinition
Section titled “aslDefinition”string | AslDefinition
ASL definition as an object or JSON string
format
Section titled “format”"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).
Returns
Section titled “Returns”SVG output
Example
Section titled “Example”const { svg } = generator.generate({ aslDefinition: myStateMachine, format: 'svg' });Call Signature
Section titled “Call Signature”generate(params): MermaidOutput;Defined in: src/index.ts:446
Generate a Mermaid diagram for this call, whatever the configured format.
Parameters
Section titled “Parameters”params
Section titled “params”Generation parameters
aslDefinition
Section titled “aslDefinition”string | AslDefinition
ASL definition as an object or JSON string
format
Section titled “format”"mermaid"
Output format for this call only; overrides the constructor’s
format.
Returns
Section titled “Returns”Mermaid output
Example
Section titled “Example”generator.generate({ aslDefinition, format: 'mermaid' }).code;Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”params
Section titled “params”Generation parameters
aslDefinition
Section titled “aslDefinition”string | AslDefinition
ASL definition as an object or JSON string
format?
Section titled “format?”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).
Returns
Section titled “Returns”SVG or Mermaid output, based on the per-call or configured format
Example
Section titled “Example”const result = generator.generate({ aslDefinition: myStateMachine });generateMermaid()
Section titled “generateMermaid()”generateMermaid(params): MermaidOutput;Defined in: src/index.ts:504
Generate Mermaid diagram syntax
Parameters
Section titled “Parameters”params
Section titled “params”Generation parameters
aslDefinition
Section titled “aslDefinition”string | AslDefinition
ASL definition as an object or JSON string
Returns
Section titled “Returns”Mermaid output with code and metadata
Example
Section titled “Example”const { code } = generator.generateMermaid({ aslDefinition: myStateMachine });generateSvg()
Section titled “generateSvg()”generateSvg(params): SvgOutput;Defined in: src/index.ts:488
Generate an SVG diagram
Parameters
Section titled “Parameters”params
Section titled “params”Generation parameters
aslDefinition
Section titled “aslDefinition”string | AslDefinition
ASL definition as an object or JSON string
Returns
Section titled “Returns”SVG output with diagram and metadata
Example
Section titled “Example”const { svg } = generator.generateSvg({ aslDefinition: myStateMachine });setOptions()
Section titled “setOptions()”setOptions(options): this;Defined in: src/index.ts:523
Update the generator’s default options (fluent interface)
Parameters
Section titled “Parameters”options
Section titled “options”Partial<DiagramOptions>
Partial options to merge with existing options
Returns
Section titled “Returns”this
This generator instance for method chaining
Example
Section titled “Example”generator .setOptions({ theme: 'dark' }) .setOptions({ layout: 'LR' });
const result = generator.generateSvg({ aslDefinition: myAsl });