sfn-diagram 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +160 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # sfn-diagram
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/sfn-diagram.svg)](https://www.npmjs.com/package/sfn-diagram)
4
+ [![npm downloads](https://img.shields.io/npm/dm/sfn-diagram.svg)](https://www.npmjs.com/package/sfn-diagram)
5
+ [![Unit Test](https://github.com/yusufaf/sfn-diagram/actions/workflows/unit-test.yml/badge.svg)](https://github.com/yusufaf/sfn-diagram/actions/workflows/unit-test.yml)
4
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
7
  [![Live Playground](https://img.shields.io/badge/playground-live-brightgreen)](https://yusufaf.github.io/sfn-diagram/)
6
8
 
@@ -8,6 +10,30 @@ Generate beautiful, interactive diagrams from AWS Step Functions ASL (Amazon Sta
8
10
 
9
11
  **▶ [Try it in the live playground](https://yusufaf.github.io/sfn-diagram/)** — paste any ASL definition and preview the diagram instantly, no install required.
10
12
 
13
+ <picture>
14
+ <source media="(prefers-color-scheme: dark)" srcset="examples/outputs/parallel-dark.svg">
15
+ <img src="examples/outputs/parallel-light.svg" alt="Example diagram of a Parallel state Step Functions workflow generated by sfn-diagram" width="410">
16
+ </picture>
17
+
18
+ ## Table of Contents
19
+
20
+ - [What it looks like](#what-it-looks-like)
21
+ - [Why sfn-diagram](#why-sfn-diagram)
22
+ - [Features](#features)
23
+ - [Installation](#installation)
24
+ - [Runtime Support](#runtime-support)
25
+ - [Command-line Usage](#command-line-usage)
26
+ - [Docker](#docker)
27
+ - [Quick Start](#quick-start)
28
+ - [API Reference](#api-reference)
29
+ - [Configuration Options](#configuration-options)
30
+ - [Supported State Types](#supported-state-types)
31
+ - [Examples](#examples)
32
+ - [TypeScript Support](#typescript-support)
33
+ - [Use with your framework](#use-with-your-framework)
34
+ - [Ecosystem](#ecosystem)
35
+ - [Contributing](#contributing)
36
+
11
37
  ## What it looks like
12
38
 
13
39
  Give it an ASL definition like this order-processing workflow ([`examples/order-processing.asl.json`](examples/order-processing.asl.json)):
@@ -57,6 +83,21 @@ stateDiagram-v2
57
83
  class OrderComplete successState
58
84
  ```
59
85
 
86
+ ## Why sfn-diagram
87
+
88
+ There's no shortage of ways to look at a state machine — this is where sfn-diagram fits versus the other two most common options:
89
+
90
+ | | **sfn-diagram** | AWS Console visualizer | Mermaid Live Editor |
91
+ |---|---|---|---|
92
+ | Input | ASL, CloudFormation/SAM/CDK templates, live AWS state machines | Deployed state machine only | Manual Mermaid you write by hand |
93
+ | Output | SVG, Mermaid, PNG, interactive HTML | Static graph in-browser | Mermaid diagram only |
94
+ | CI / PR integration | [GitHub Action](#github-action) posts a diff overlay on every PR that touches ASL | None | None |
95
+ | Execution overlays | Paints a real run's path/status/duration onto the diagram | Basic per-execution highlighting, console-only | Not applicable |
96
+ | Runs where | CLI, Node, browser, edge runtimes | AWS Console only | Web app only |
97
+ | Automation | Full programmatic API (`generateSvg`, `generateMermaid`, etc.) | None — UI only | None — UI only |
98
+
99
+ In short: reach for the AWS Console visualizer to eyeball a state machine you already deployed, reach for Mermaid Live if you're hand-drawing a diagram from scratch — reach for sfn-diagram when you want diagrams generated automatically from your actual definition, checked into CI, and diffed on every pull request.
100
+
60
101
  ## Features
61
102
 
62
103
  - **Multiple Output Formats**: SVG (D3.js), Mermaid syntax, and PNG
@@ -760,6 +801,120 @@ import type {
760
801
  import type { PngOutput, ExportPngParams } from 'sfn-diagram/png';
761
802
  ```
762
803
 
804
+ ## Use with your framework
805
+
806
+ `generateSvg()` returns an SVG **string** and the core has no DOM dependency, so any
807
+ framework can render a diagram by injecting that string. There is nothing React-specific
808
+ in the core — [`sfn-diagram-react`](packages/sfn-diagram-react/) exists for convenience,
809
+ not necessity.
810
+
811
+ Each snippet below is the whole integration. See [API Reference](#api-reference) for the
812
+ full option set (`theme`, `layout`, `showIcons`, …) and [`generateMermaid`](#generatemermaidparams)
813
+ if you would rather emit Mermaid than SVG.
814
+
815
+ **Svelte 5**
816
+
817
+ ```svelte
818
+ <script lang="ts">
819
+ import { generateSvg } from 'sfn-diagram';
820
+
821
+ let { definition } = $props();
822
+ const svg = $derived(generateSvg({ aslDefinition: definition }).svg);
823
+ </script>
824
+
825
+ {@html svg}
826
+ ```
827
+
828
+ **Vue 3**
829
+
830
+ ```vue
831
+ <script setup lang="ts">
832
+ import { computed } from 'vue';
833
+ import { generateSvg } from 'sfn-diagram';
834
+ import type { AslDefinition } from 'sfn-diagram';
835
+
836
+ const props = defineProps<{ definition: AslDefinition | string }>();
837
+ const svg = computed(() => generateSvg({ aslDefinition: props.definition }).svg);
838
+ </script>
839
+
840
+ <template>
841
+ <div v-html="svg" />
842
+ </template>
843
+ ```
844
+
845
+ **Solid**
846
+
847
+ ```tsx
848
+ import { createMemo } from 'solid-js';
849
+ import { generateSvg } from 'sfn-diagram';
850
+ import type { AslDefinition } from 'sfn-diagram';
851
+
852
+ export function SfnDiagram(props: { definition: AslDefinition | string }) {
853
+ const svg = createMemo(() => generateSvg({ aslDefinition: props.definition }).svg);
854
+ return <div innerHTML={svg()} />;
855
+ }
856
+ ```
857
+
858
+ **Angular**
859
+
860
+ `[innerHTML]` strips SVG unless the value is marked trusted, so the sanitizer bypass is required.
861
+
862
+ ```ts
863
+ import { Component, computed, inject, input } from '@angular/core';
864
+ import { DomSanitizer } from '@angular/platform-browser';
865
+ import { generateSvg } from 'sfn-diagram';
866
+ import type { AslDefinition } from 'sfn-diagram';
867
+
868
+ @Component({
869
+ selector: 'sfn-diagram',
870
+ template: `<div [innerHTML]="svg()"></div>`,
871
+ })
872
+ export class SfnDiagramComponent {
873
+ readonly definition = input.required<AslDefinition | string>();
874
+ private readonly sanitizer = inject(DomSanitizer);
875
+
876
+ readonly svg = computed(() =>
877
+ this.sanitizer.bypassSecurityTrustHtml(
878
+ generateSvg({ aslDefinition: this.definition() }).svg
879
+ )
880
+ );
881
+ }
882
+ ```
883
+
884
+ **Astro**
885
+
886
+ Astro runs the frontmatter at build time, so the diagram ships as static markup with
887
+ **zero client-side JavaScript** — the DOM-free core at its best. (Astro also hosts React
888
+ islands, so `sfn-diagram-react` works there too if you need interactivity.)
889
+
890
+ ```astro
891
+ ---
892
+ import { generateSvg } from 'sfn-diagram';
893
+ // `?raw` gives the file as a string, which `aslDefinition` accepts directly
894
+ import definition from '../workflows/order-processing.asl.json?raw';
895
+
896
+ const { svg } = generateSvg({ aslDefinition: definition, theme: 'light' });
897
+ ---
898
+
899
+ <Fragment set:html={svg} />
900
+ ```
901
+
902
+ **Vanilla JS / htmx / anything else**
903
+
904
+ ```js
905
+ import { generateSvg } from 'sfn-diagram';
906
+
907
+ const response = await fetch('/workflows/order-processing.asl.json');
908
+ const { svg } = generateSvg({ aslDefinition: await response.text() });
909
+ document.querySelector('#diagram').innerHTML = svg;
910
+ ```
911
+
912
+ > **On the "unsafe HTML" APIs.** Every snippet above uses its framework's raw-HTML escape
913
+ > hatch (`{@html}`, `v-html`, `innerHTML`, `dangerouslySetInnerHTML`). The SVG builder
914
+ > HTML-escapes every attribute and text value it emits, following the HTML serialization
915
+ > algorithm, so state names, comments, and choice conditions taken from your ASL are
916
+ > escaped before they reach the string.
917
+
763
918
  ## Ecosystem
764
919
 
765
920
  ### Playground
@@ -790,7 +945,11 @@ code --install-extension vscode-sfn-diagram-*.vsix
790
945
 
791
946
  ### React Component
792
947
 
793
- Render diagrams in a React app with the [`sfn-diagram-react`](packages/sfn-diagram-react/) package. It wraps `generateSvg`/`generateMermaid` in a component with the same platform-agnostic core, so it works in any React renderer.
948
+ Render diagrams in a React app with the [`sfn-diagram-react`](https://www.npmjs.com/package/sfn-diagram-react) package ([source](packages/sfn-diagram-react/)). It wraps `generateSvg`/`generateMermaid` in a component with the same platform-agnostic core, so it works in any React renderer. React 18 and 19 are both supported.
949
+
950
+ ```bash
951
+ npm install sfn-diagram-react sfn-diagram react
952
+ ```
794
953
 
795
954
  ```tsx
796
955
  import { SfnDiagram } from 'sfn-diagram-react';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sfn-diagram",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Generate SVG, Mermaid, HTML, and PNG diagrams from AWS Step Functions ASL definitions, CloudFormation/CDK templates, or live AWS state machines",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@9.15.9",