autovisualizer 0.4.1 → 0.5.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.
package/README.md CHANGED
@@ -95,9 +95,45 @@ The chart shows states and events only, so it leaves the machine's name to your
95
95
 
96
96
  ### In READMEs, issues and pull requests
97
97
 
98
- Export the chart as an image. In [the app](https://auto-visualizer.vercel.app), **Save → SVG image** exports the chart as one self-contained SVG, and **Save → Animated SVG** exports every step you simulated since the last reset, like the demo above. Both follow the reader's light or dark setting, and readers who ask for less motion see the last step as a still image.
98
+ GitHub can't run the element, so give it an image. Put each chart in your Markdown as an SVG link with its source in a collapsed `<details>` block below it:
99
99
 
100
- To build one in CI, ask a chart on your docs page for its walkthrough as an animated SVG: `await element.toAnimatedSvg({ title, stepMs, direction })` (`direction` is `right`, the default, or `down`). It returns the SVG text, a frame per step, captioned with the step's event and note, so keep notes short. Call it from a headless browser once the chart has loaded:
100
+ ````md
101
+ ![Door statechart](docs/door.svg)
102
+ <details><summary>Statechart source</summary>
103
+
104
+ ```statechart walkthrough='[{"event":"OPEN","note":"someone knocks"}]'
105
+ import { createMachine } from "xstate"
106
+ export const door = createMachine({ id: "door", initial: "closed", states: { closed: { on: { OPEN: { target: "open" } } }, open: {} } })
107
+ ```
108
+ </details>
109
+ ````
110
+
111
+ Then let the action draw the images. With `render`, it finds each chart, draws it with the same export as the app, and commits the SVGs that changed. A chart with a `walkthrough` becomes an animated SVG. Attributes on the fence line are the element's own (`walkthrough`, `events`, `state`, `direction`), and source that starts with `{` is MachineJSON:
112
+
113
+ ```yaml
114
+ on:
115
+ pull_request:
116
+ paths: ['**/*.md']
117
+ permissions:
118
+ contents: write
119
+ jobs:
120
+ statecharts:
121
+ runs-on: ubuntu-latest
122
+ steps:
123
+ - uses: actions/checkout@v7
124
+ with: { ref: '${{ github.head_ref }}' }
125
+ - uses: actions/setup-node@v7
126
+ with: { node-version: 24 }
127
+ - uses: jagreehal/autovisualizer@main
128
+ with:
129
+ render: README.md docs/guide.md
130
+ ```
131
+
132
+ It draws in the runner's Chrome. To render locally, build the CLI and the embed from an Autovisualizer checkout (`pnpm build:review && pnpm build:embed`), then run `node /path/to/autovisualizer/dist/review/cli.mjs render README.md`.
133
+
134
+ You can also export by hand. In [the app](https://auto-visualizer.vercel.app), **Save → SVG image** exports the chart as one self-contained SVG, and **Save → Animated SVG** exports every step you simulated since the last reset, like the demo above. Both follow the reader's light or dark setting, and readers who ask for less motion see the last step as a still image.
135
+
136
+ From your own docs build, ask a chart on your page for its walkthrough as an animated SVG: `await element.toAnimatedSvg({ title, stepMs, direction })` (`direction` is `right`, the default, or `down`). It returns the SVG text, a frame per step, captioned with the step's event and note, so keep notes short. Call it from a headless browser once the chart has loaded:
101
137
 
102
138
  ```js
103
139
  const chart = page.locator("auto-visualizer#checkout")
@@ -127,7 +163,7 @@ steps:
127
163
  fail-on-regression: true # optional: fail when a machine lost a state or transition
128
164
  ```
129
165
 
130
- It finds machines in TypeScript or JavaScript that call `createMachine`, `setup().createMachine`, `setupEffect().createMachine` or `machineFromJSON`, and in MachineJSON files (`machineToJSON` output, or any `.json` with `states`). Removed states or transitions, and states that became unreachable, make the merge risk high. A target it can't read, or a file it couldn't run, makes it moderate. The first run takes about a minute.
166
+ It compares the pull request with the commit it branched from, so changes that landed on the base branch since then stay out of the review. It finds machines in TypeScript or JavaScript that call `createMachine`, `setup().createMachine`, `setupEffect().createMachine` or `machineFromJSON`, and in MachineJSON files (`machineToJSON` output, or any `.json` with `states`). Removed states or transitions, and states that became unreachable, make the merge risk high. A target it can't read, or a file it couldn't run, makes it moderate. The first run takes about a minute.
131
167
 
132
168
  The review runs the machine files, the same as your tests do. Imports other than `xstate`, `@xstate/effect` and `effect` get stand-ins, so a machine can import its own actions and helpers. Use the `pull_request` trigger. The action refuses `pull_request_target`, which would run a fork's code with a write token.
133
169
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autovisualizer",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "See and step through XState v6 and @xstate/effect machines in the browser.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Jag Reehal",