flowfig 0.5.0 → 0.7.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/dist/gif.js CHANGED
@@ -1,12 +1,41 @@
1
+ import { endianness } from 'node:os';
1
2
  /** The delay of each of `count` frames in cs. The sum is round(count * 100 / fps). */
2
3
  export function delays(count, fps) {
3
- // Each delay is a whole cs: the rounding error moves between frames and does not add up.
4
4
  return Array.from({ length: count }, (_, i) => Math.round(((i + 1) * 100) / fps) - Math.round((i * 100) / fps));
5
5
  }
6
- // A color bin: 5 bits per channel, 32768 bins.
7
6
  const binOf = (rgb) => ((rgb >> 9) & 0x7c00) | ((rgb >> 6) & 0x3e0) | ((rgb >> 3) & 0x1f);
7
+ // Little-endian: a pixel word is A B G R, so this swaps R and B.
8
+ const rgbOf = (v) => ((v & 255) << 16) | (v & 0xff00) | ((v >> 16) & 255);
9
+ const CROP_LIMIT = 64 << 20;
10
+ function changedBox(a, b, width, height) {
11
+ let x0 = width, x1 = -1, y0 = -1, y1 = -1;
12
+ for (let y = 0; y < height; y++) {
13
+ const o = y * width;
14
+ let lo = 0;
15
+ while (lo < width && a[o + lo] === b[o + lo])
16
+ lo++;
17
+ if (lo === width)
18
+ continue;
19
+ let hi = width - 1;
20
+ while (a[o + hi] === b[o + hi])
21
+ hi--;
22
+ if (lo < x0)
23
+ x0 = lo;
24
+ if (hi > x1)
25
+ x1 = hi;
26
+ if (y0 < 0)
27
+ y0 = y;
28
+ y1 = y;
29
+ }
30
+ return y1 < 0 ? null : [x0, y0, x1, y1];
31
+ }
8
32
  const channel = (bin, c) => (bin >> (10 - 5 * c)) & 31;
9
- /** Median cut: split the box with the widest channel range at its weighted median, until 256 boxes or one bin per box. */
33
+ function cropOf(px, [x0, y0, x1, y1], width) {
34
+ const w = x1 - x0 + 1, out = new Uint32Array(w * (y1 - y0 + 1));
35
+ for (let y = y0; y <= y1; y++)
36
+ out.set(px.subarray(y * width + x0, y * width + x1 + 1), (y - y0) * w);
37
+ return out;
38
+ }
10
39
  function medianCut(bins, counts) {
11
40
  const boxes = [bins];
12
41
  while (boxes.length < 256) {
@@ -36,7 +65,6 @@ function medianCut(bins, counts) {
36
65
  }
37
66
  return boxes;
38
67
  }
39
- /** The palette: the exact colors if there are 256 or fewer, else median cut over the bins. No dither. */
40
68
  function palette(exact, counts, sums) {
41
69
  const colors = new Uint8Array(768);
42
70
  if (exact) {
@@ -59,7 +87,6 @@ function palette(exact, counts, sums) {
59
87
  }
60
88
  colors.set([Math.round(r / n), Math.round(g / n), Math.round(b / n)], k * 3);
61
89
  });
62
- // Each bin maps to the palette color nearest to the mean color of the bin.
63
90
  const table = new Uint8Array(32768);
64
91
  for (const x of bins) {
65
92
  const r = sums[x * 3] / counts[x], g = sums[x * 3 + 1] / counts[x], b = sums[x * 3 + 2] / counts[x];
@@ -73,7 +100,6 @@ function palette(exact, counts, sums) {
73
100
  }
74
101
  return { colors, index: (rgb) => table[binOf(rgb)] };
75
102
  }
76
- /** GIF LZW: minimum code size 8, a clear code first, codes up to 12 bits, data in sub-blocks of 255 bytes or fewer. */
77
103
  function lzw(px, width, rect, byte) {
78
104
  const [x0, y0, x1, y1] = rect;
79
105
  const CLEAR = 256, END = 257;
@@ -115,7 +141,7 @@ function lzw(px, width, rect, byte) {
115
141
  [next, size] = [258, 9];
116
142
  }
117
143
  else {
118
- // The decoder runs one code behind: grow the size when the new code no longer fits.
144
+ // The decoder runs one code behind: grow the size one code early.
119
145
  if (next >= 1 << size)
120
146
  size++;
121
147
  dict.set((prefix << 8) | k, next++);
@@ -134,17 +160,19 @@ function lzw(px, width, rect, byte) {
134
160
  byte(0);
135
161
  }
136
162
  /** An animated GIF that loops forever. All frames have the size of the first frame. */
137
- // It yields to the event loop between frames, so a signal handler can run while the encode goes on.
163
+ // It yields between frames so a signal handler can run.
138
164
  export async function encodeGif(frames) {
139
165
  if (!frames.length)
140
166
  throw new Error('a GIF needs at least one frame');
141
- // Pass 1: count the colors of all frames.
167
+ if (endianness() !== 'LE')
168
+ throw new Error('flowfig gif needs a little-endian CPU');
142
169
  const counts = new Uint32Array(32768), sums = new Float64Array(32768 * 3);
143
170
  let exact = new Map(), width = 0, height = 0;
171
+ let before = null, kept = 0;
172
+ const crops = [];
144
173
  for (let f = 0; f < frames.length; f++) {
145
174
  if (frames[f].same && f > 0)
146
175
  continue;
147
- // A run of equal frames counts once, with the weight of the run.
148
176
  let weight = 1;
149
177
  while (f + weight < frames.length && frames[f + weight].same)
150
178
  weight++;
@@ -154,20 +182,39 @@ export async function encodeGif(frames) {
154
182
  [width, height] = [w, h];
155
183
  else if (w !== width || h !== height)
156
184
  throw new Error(`frame ${f + 1} is ${w} x ${h}; the first frame is ${width} x ${height}`);
157
- let last = -1, bin = 0;
158
- for (let i = 0; i < data.length; i += 4) {
159
- const rgb = (data[i] << 16) | (data[i + 1] << 8) | data[i + 2];
160
- if (rgb !== last) {
161
- last = rgb;
162
- bin = binOf(rgb);
163
- if (exact && !exact.has(rgb))
164
- exact = exact.size < 256 ? exact.set(rgb, exact.size) : null;
185
+ const px = new Uint32Array(data.buffer, data.byteOffset, data.length >> 2);
186
+ let last = px[0] & 0xffffff, run = 0;
187
+ const add = (v, n) => {
188
+ const rgb = rgbOf(v), bin = binOf(rgb), k = n * weight;
189
+ if (exact && !exact.has(rgb))
190
+ exact = exact.size < 256 ? exact.set(rgb, exact.size) : null;
191
+ counts[bin] += k;
192
+ sums[bin * 3] += (rgb >> 16) * k;
193
+ sums[bin * 3 + 1] += ((rgb >> 8) & 255) * k;
194
+ sums[bin * 3 + 2] += (rgb & 255) * k;
195
+ };
196
+ for (let i = 0; i < px.length; i++) {
197
+ const v = px[i] & 0xffffff;
198
+ if (v === last)
199
+ run++;
200
+ else {
201
+ add(last, run);
202
+ [last, run] = [v, 1];
165
203
  }
166
- counts[bin] += weight;
167
- sums[bin * 3] += data[i] * weight;
168
- sums[bin * 3 + 1] += data[i + 1] * weight;
169
- sums[bin * 3 + 2] += data[i + 2] * weight;
170
204
  }
205
+ add(last, run);
206
+ const box = before ? changedBox(px, before, width, height) : [0, 0, width - 1, height - 1];
207
+ if (!box)
208
+ crops[f] = null;
209
+ else {
210
+ const [x0, y0, x1, y1] = box;
211
+ const size = (x1 - x0 + 1) * (y1 - y0 + 1) * 4;
212
+ if (kept + size <= CROP_LIMIT) {
213
+ kept += size;
214
+ crops[f] = { x0, y0, x1, y1, px: before ? cropOf(px, box, width) : px };
215
+ }
216
+ }
217
+ before = px;
171
218
  }
172
219
  const { colors, index } = palette(exact, counts, sums);
173
220
  let buf = new Uint8Array(1 << 20), len = 0;
@@ -196,20 +243,34 @@ export async function encodeGif(frames) {
196
243
  bytes(0x21, 0xff, 11);
197
244
  text('NETSCAPE2.0');
198
245
  bytes(3, 1, 0, 0, 0); // loop count 0: loop forever
199
- // Pass 2: each frame as palette indices. A later frame sends only the rectangle that changed.
200
246
  let prev = null;
201
- for (const frame of frames) {
247
+ for (let i = 0; i < frames.length; i++) {
248
+ const frame = frames[i], crop = crops[i];
202
249
  await new Promise(setImmediate);
203
250
  let cur = prev;
204
- if (!(frame.same && prev)) {
205
- const { data } = frame.load();
251
+ if (crop === null && prev)
252
+ cur = prev;
253
+ else if (!(frame.same && prev)) {
206
254
  cur = new Uint8Array(width * height);
207
255
  let last = -1, k = 0;
208
- for (let p = 0, i = 0; p < cur.length; p++, i += 4) {
209
- const rgb = (data[i] << 16) | (data[i + 1] << 8) | data[i + 2];
210
- if (rgb !== last)
211
- [last, k] = [rgb, index(rgb)];
256
+ const put = (p, v) => {
257
+ v &= 0xffffff;
258
+ if (v !== last)
259
+ [last, k] = [v, index(rgbOf(v))];
212
260
  cur[p] = k;
261
+ };
262
+ if (crop) {
263
+ if (prev)
264
+ cur.set(prev);
265
+ for (let y = crop.y0, q = 0; y <= crop.y1; y++)
266
+ for (let x = crop.x0; x <= crop.x1; x++)
267
+ put(y * width + x, crop.px[q++]);
268
+ }
269
+ else {
270
+ const { data } = frame.load();
271
+ const px = new Uint32Array(data.buffer, data.byteOffset, data.length >> 2);
272
+ for (let p = 0; p < cur.length; p++)
273
+ put(p, px[p]);
213
274
  }
214
275
  }
215
276
  let rect = [0, 0, width - 1, height - 1];
@@ -217,19 +278,31 @@ export async function encodeGif(frames) {
217
278
  rect = [0, 0, -1, -1];
218
279
  else if (prev) {
219
280
  rect = [width, height, -1, -1];
220
- for (let y = 0, p = 0; y < height; y++)
221
- for (let x = 0; x < width; x++, p++)
222
- if (cur[p] !== prev[p]) {
223
- if (x < rect[0])
224
- rect[0] = x;
225
- if (x > rect[2])
226
- rect[2] = x;
227
- if (y < rect[1])
228
- rect[1] = y;
229
- rect[3] = y;
230
- }
281
+ const wide = (width & 3) === 0;
282
+ const a32 = wide ? new Uint32Array(cur.buffer) : cur, b32 = wide ? new Uint32Array(prev.buffer) : prev, row = wide ? width >> 2 : width;
283
+ for (let y = crop?.y0 ?? 0; y <= (crop?.y1 ?? height - 1); y++) {
284
+ let x = y * row;
285
+ const end = x + row;
286
+ while (x < end && a32[x] === b32[x])
287
+ x++;
288
+ if (x === end)
289
+ continue;
290
+ const o = y * width;
291
+ let x0 = 0, x1 = width - 1;
292
+ while (cur[o + x0] === prev[o + x0])
293
+ x0++;
294
+ while (cur[o + x1] === prev[o + x1])
295
+ x1--;
296
+ if (x0 < rect[0])
297
+ rect[0] = x0;
298
+ if (x1 > rect[2])
299
+ rect[2] = x1;
300
+ if (y < rect[1])
301
+ rect[1] = y;
302
+ rect[3] = y;
303
+ }
231
304
  }
232
- // No change: a 1 x 1 frame that paints the old color keeps the frame and its delay.
305
+ // A 1 x 1 frame in the old color keeps the frame and its delay.
233
306
  if (rect[2] < 0)
234
307
  rect = [0, 0, 0, 0];
235
308
  bytes(0x21, 0xf9, 4, 1 << 2); // disposal method 1: the next frame draws over this frame
package/dist/guide.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- /** The full guide, as Markdown. `flowfig docs` prints it. */
2
- export declare const GUIDE = "# flowfig guide\n\nflowfig draws animated flow figures. A figure has boxes, the edges between the boxes, and steps. In each step, a packet moves along\nthe edges. The output is one animated SVG with no script. The SVG plays in a GitHub README, in PR and issue comments, and in blog\nposts. A figure is about 5 to 50 kB.\n\nYou write a JSON spec. You never write SVG by hand. The command `npx flowfig` checks the spec and renders it.\n\n## What flowfig draws\n\nA spec has three forms.\n\n- The map (the default). The map shows the boxes and the edges. A packet moves along an edge in each beat.\n- The map with a rail (`\"rail\": true`). The rail is a lifeline diagram under the map. It has one row for each message.\n- The rail alone (`\"rail\": \"only\"`). Use it when the reader needs only the order of the messages, for example when the map is already in the same document.\n\nUse the rail for a sequence of messages: a request lifecycle, an API call chain, or a Mermaid `sequenceDiagram`. Put each message on\nan edge. Put each phase in a step. Put messages that run at the same time in one beat. Mark a message that does not wait for an\nanswer with `\"async\": true`: every send to a queue or a topic, every emitted event, and every call the caller does not await.\n\n## Scope: what flowfig draws and what it does not\n\nflowfig draws how something works: parts, the messages between them, and the order of the messages.\n\n| The user asks for | Draw |\n| ------------------------------------------ | ------------------------------------------------------------------------------------------ |\n| An architecture, a data flow, a pipeline | The map. Group parts by service, network or trust boundary. `store` for data at rest. |\n| A request lifecycle, a call chain | The map with `\"rail\": true`. One message per hop, with its real payload in `data`. |\n| A sequence diagram only | `\"rail\": \"only\"`. |\n| A state lifecycle, a state machine | One box per state, one edge per transition, labeled with its event. One step per path. Mark the first state with `mark: \"start\"` and each final state with `mark: \"end\"`. |\n| A flowchart with branches | `shape: \"decision\"` for each branch. One step per path. |\n| A roadmap or a timeline | `timeline: true`. One labeled group per track, in a `column` group. Items with `from` and `to` (dates), a milestone with `from` only, an edge for a dependency, `today` for the line. A dependent item starts after its source ends. |\n| A process across roles (a ticket, an order, a refund) | `lanes: true`. One labeled group per role, in a `column` group. Put each step in the lane of the role that does it. Link each step with `source` to the SOP heading. If the steps do not fit the width, flowfig wraps the time columns into blocks and links the blocks with labeled stubs, so keep the whole process in one figure. Give the outcomes of one decision the same `at`. |\n\nflowfig draws a roadmap or a timeline with dates (`timeline: true`), and converts a Mermaid `gantt` to it. flowfig does not\ndraw class or ER diagrams (fields, types, cardinality), charts of numbers or mind maps. If the user asks for one of these, say that\nflowfig does not draw it, suggest Mermaid (`classDiagram`, `erDiagram`), and draw nothing with flowfig.\n\n## Workflow\n\n### 1. Pick the scope\n\nIf the code has more than one flow, name each flow in the reply. Then draw one flow, or draw one structure view and call it a\nstructure view. If the user asks for the whole system, draw one top view with groups, or a set of figures that together cover\nevery part. Keep each figure to 12 boxes or fewer.\n\n### 2. Write the fact list\n\nBefore the spec, write a list of the facts that the figure must show. Take each fact from the code and from its wiring: config\nfiles, compose files, route tables and queue bindings (or from the pasted Mermaid). Give each fact its `file:line`:\n\n- every part (service, function, store, queue, external system);\n- every call, in order, written as `caller \u2192 callee: payload (file:line of the call)`. The edge in the spec goes from that caller\n to that callee;\n- every call that does not wait for an answer (fire and forget, a queue, a webhook, a callback), and every consumer of each queue\n or topic;\n- every branch and every error path (a rejected input, a retry, a dead-letter path);\n- every end state;\n- for a process document (an SOP): every deadline, every message to a person (an email, a notice), every choice that a person\n makes, and every wait for a reply. Put each one in a box `sub`, a step `say` or a `data` card. A small fact still counts.\n\nIf the code does not show a fact, leave the fact out. Do not guess a part, a name or an order.\n\n### 3. Write the spec\n\nEach fact becomes a box, an edge, a beat, a `data` card or a `show` row. Use the real names from the code as labels, and\nreal example data from the code or its tests. Keep each fact that you leave out, with the reason, for the reply.\nGive each box and edge that draws code a `source`, from the fact list: `\"src/auth/login.ts#verifyPassword\"`. A store or an outside part may have none.\nA box that draws a step from a document links to that document: `\"docs/sop/refunds.md#step-3-approve-the-refund\"`, the heading as a GitHub anchor. `verify` checks it the same way.\n\nMermaid mapping:\n\n| Mermaid | flowfig |\n| ---------------------------------------- | ------------------------------------------------------------------ |\n| `participant` | a box |\n| `A->>B: text` | an edge from A to B, and a hop with `data: \"text\"` |\n| `B-->>A: text` (a reply) | a hop on the same edge with `back: true` |\n| `A-)B: text` (async) | a hop with `async: true` |\n| `par ... and ... end` | the hops of all branches in one beat |\n| `alt` / `opt` | one step per path |\n| `stateDiagram` states and transitions | boxes, and edges labeled with the event |\n\n### 4. Render, then fix\n\n```bash\nnpx flowfig - out.svg <<'SPEC'\n{ \"props\": { \"layout\": ..., \"edges\": [...], \"steps\": [...] } }\nSPEC\n```\n\nThe quoted `<<'SPEC'` heredoc passes the JSON with no change. The command checks the spec first. If the check finds an error, the\ncommand writes no SVG and lists the faults. Fix each fault and render again.\n\n- Fix a layout fault by changing the layout first: put parts in rows or columns, route an edge `around`, or change a gap.\n Never remove a fact from the fact list to pass the check. If you must remove one, name it in the reply.\n- If `small-text` appears, the figure is too wide. Put the parts in two rows, move a detail from `label` to `sub`, or split\n the figure. Use more steps in one figure before you make a second figure. Keep the real name from the code in the label:\n `ReportsController` stays `ReportsController`, not `Controller`. Do not change `--width` to pass the check: the\n reader sees the figure at the real page width.\n- Fix every other warning, or tell the user why it stays.\n- Do not use `--no-check` to hide a fault.\n\n### 5. Read the figure back\n\nRun `npx flowfig --spec out.svg`. Compare the spec with the fact list. Check that each edge goes from the caller to the callee\nthat its fact names. Add each fact that is missing, fix each wrong edge, and render again.\n\nRun `npx flowfig verify out.svg` from the repo root. Fix each `missing-file` or `missing-symbol`.\n\n### 6. Look at the SVG\n\nThe check estimates the text width, so it cannot see everything. If you can open a browser, open the SVG and take a\nscreenshot. Wait a few seconds and take a second screenshot to see a later beat. If you cannot open a browser, write \"not\nlooked at\" in the reply. Never report a look that you did not do. A browser tool can block `file://` URLs. If it does, serve the folder\nwith `python3 -m http.server`.\n\n### 7. Write the reply\n\nThe reply has these parts, in this order:\n\n1. the path of each SVG;\n2. what each figure shows: the parts and the steps. Copy the counts from the `figure:` line of the check output. Copy every name\n from the read-back spec. Never count from memory;\n3. the scope: the flow you drew, why, and the other flows that exist;\n4. what the figure leaves out, and why;\n5. the two check lines that the render printed, `0 errors, 0 warnings` and `figure: ...`, copied as printed, and whether\n you looked at the SVG;\n6. one line `npx flowfig open <path>` for each SVG, at the end of the reply. Do not run that command yourself.\n\nTo change an SVG later, print its spec with `--spec`, change the spec, and render again.\n\n## Spec reference\n\n`props` has these fields.\n\n| Field | Type | Meaning |\n| ---------- | ----------------------- | ---------------------------------------------------------------------------------------------- |\n| `layout` | group | The boxes and how they line up. Required. |\n| `edges` | edge[] | The arrows between the boxes. Required. |\n| `steps` | step[] | The stories the figure tells. With no steps, the figure is a still map. |\n| `lanes` | `true` | Draw the layout as swimlanes: a `column` group of labeled groups, one per role. The boxes run left to right in step order. |\n| `timeline` | `true` | Draw the layout as a timeline: one labeled group per track, with the boxes placed by their `from` and `to` dates. |\n| `today` | `YYYY-MM-DD` | In a `timeline` figure: the date where the today line stops. Default: the last date of the items. |\n| `rail` | `true` or `\"only\"` | Draw the steps as a lifeline rail under the map. `\"only\"` draws the rail without the map. |\n| `speed` | number | Milliseconds a packet takes to cross one edge. Default: 900. |\n| `theme` | object | Colors: `accent`, `fg`, `muted`, `bg`, `surface`, `border`, `font`. Each color you omit keeps its built-in value. |\n\n### layout\n\nThe layout is a tree. A group has `children` and these optional fields.\n\n- `id`: a name that an edge can use to reach the group as a whole.\n- `label`: the title on the frame. Only a group with a `label` gets a frame.\n- `direction`: `\"row\"` (the default) or `\"column\"`.\n- `gap`: the space between children in px. Default: 28 for a column. For a row, the gap fits the widest edge label between two children (at least 56).\n- `align`: `\"start\"`, `\"center\"` or `\"end\"`. This sets where the children line up across the direction.\n\nEvery other item is a box.\n\n| Box field | Meaning |\n| --------- | --------------------------------------------------------------------------------------------------------- |\n| `id` | Required. The name that edges and steps use. It must be unique in the figure. |\n| `label` | Required. The title in the box. |\n| `sub` | A smaller line under the label. |\n| `shape` | `\"box\"` (default), `\"decision\"` (a diamond) or `\"store\"` (a database cylinder for data at rest). |\n| `at` | In a `lanes` figure: the time column of the box, 0 first. Default: the order in which the steps first reach the box. |\n| `from` | In a `timeline` figure: the start of the item, or the date of a milestone, as YYYY-MM-DD. |\n| `to` | In a `timeline` figure: the last day of the item, as YYYY-MM-DD. Without it the box is a milestone. |\n| `width` | Width in px. This overrides the width that the layout picks. |\n| `source` | The code this draws: `path` or `path#symbol`, relative to the repo root. `flowfig verify` checks it. |\n| `lines` | The least number of text lines that a content card keeps. The card still grows to fit its content. |\n| `tone` | The state color of the box: a 1 px border and a light tint. Use `blue`, `purple`, `green`, `orange`, `red` or `gray`. |\n| `mark` | `\"start\"` or `\"end\"` | A lifecycle mark: a filled dot before a start state, a ringed dot after an end state. |\n\n### edges\n\nAn edge has these fields.\n\n- `id`: the name that steps use. Default: `from->to`.\n- `from` and `to`: the `id` of a box or a group.\n- `label`: text on the edge, drawn as a small pill.\n- `around`: `\"above\"` or `\"below\"`. This routes the edge over or under the boxes in between (loops, skip-ahead edges).\n- `quiet`: if `true`, the SVG draws the edge only while a step uses it.\n- `source`: the code this edge draws, as `path` or `path#symbol`. `flowfig verify` checks it.\n\n### steps\n\nA step has `label` and `flow`. It can also have `caption` (the line under the figure while no beat has a `say`) and `nodes` (ids of\nboxes to highlight for the whole step).\n\n`flow` is a list of beats. A beat is one of these:\n\n- an edge id (a string);\n- an array of edge ids, which run at the same time;\n- an object `{ edges?, say?, show?, light?, ms? }`. A beat with no `edges` is a pause.\n\nThe beat fields:\n\n- `edges`: an edge id, a hop object, or an array of these. A hop object is `{ edge, back?, data?, tone?, async?, source? }`.\n - `back: true` runs the packet from the `to` box to the `from` box.\n - `data` is a small card that moves with the packet.\n - `async: true` marks a message that does not wait for an answer. The rail draws it dashed, with an `async` tag.\n - `tone`: the color of this hop for its beat. The packet, the data card, the edge, the label pill and the arrival box take the color. The trail after the beat stays the accent.\n - `green`: a success or a cache hit. `orange`: a warning, a miss or a retry. `red`: an error or a rejected input.\n - `gray`: idle or skipped. `purple`: async or background. `blue`: the default row color.\n - If the hop has no `tone`, the arrival box uses its box `tone`, then the accent. A hop `tone` wins over a box `tone`.\n- `say`: the caption for the beat.\n- `show`: `{ boxId: [row, ...] }`. This fills the content card of each named box. The card keeps the rows until the step ends.\n- `light`: ids of boxes to highlight for this beat.\n- `ms`: how long the beat lasts. Default: the time one packet needs to cross an edge.\n\nA row of a content card is `{ tag?, tone?, text, meta?, mark?, mono? }`.\n\n- `tag`: a short colored label at the start of the line.\n- `tone`: the color of the tag: `blue` (default), `purple`, `green`, `orange`, `red` or `gray`.\n- `text`: the main text.\n- `meta`: muted text after the main text.\n- `mark`: a mark at the right end of the line, such as a check or \"new\".\n- `mono`: if `true`, the text uses a monospace font.\n\n## Content rules\n\n- Give every box a stable `id`.\n- Use `shape: \"store\"` for data at rest (a database, a cache, a file, a queue). Use a plain box for a part that does work. Use `shape: \"decision\"` for a branch.\n- Keep one clear main path, left to right. Put side parts in a `column` group.\n- Use `quiet: true` on a long edge that crosses the picture. A quiet edge needs a beat that uses it, or the check reports\n `hidden-edge`.\n- In a rail, draw an error reply as a hop back on the same edge, with the error in `data` (`{ \"edge\": \"login\", \"back\": true,\n \"data\": \"401 CREDENTIALS_INVALID\" }`). A call that stays inside one part (a hash check, a guard) is not a message: put it in\n `say` or in a `show` row of that part.\n- Keep an SVG to one or two steps. The SVG plays every step in a loop, with no controls.\n- Use the React player, `<Flow {...props} />` from `flowfig`, for a page that needs tabs, pause or hover.\n\n## Example\n\n```json\n{\n \"props\": {\n \"layout\": {\n \"children\": [\n { \"id\": \"client\", \"label\": \"Browser\" },\n { \"id\": \"api\", \"label\": \"API Server\" },\n { \"id\": \"db\", \"label\": \"Database\", \"shape\": \"store\" }\n ]\n },\n \"edges\": [\n { \"id\": \"req\", \"from\": \"client\", \"to\": \"api\", \"label\": \"GET /users/42\" },\n { \"id\": \"q\", \"from\": \"api\", \"to\": \"db\", \"label\": \"SELECT\" }\n ],\n \"steps\": [\n {\n \"label\": \"read\",\n \"flow\": [\n { \"edges\": { \"edge\": \"req\", \"data\": \"GET /users/42\" }, \"say\": \"The browser asks for user 42.\" },\n { \"edges\": \"q\", \"show\": { \"db\": [{ \"tag\": \"row\", \"tone\": \"gray\", \"text\": \"Ada Lovelace\" }] }, \"say\": \"The API server reads the row.\" },\n { \"edges\": { \"edge\": \"req\", \"back\": true, \"data\": \"200 OK\" }, \"say\": \"The API server sends the user.\" }\n ]\n }\n ]\n }\n}\n```\n\n## Commands\n\n```bash\nnpx flowfig - out.svg < spec.json # render a spec from stdin\nnpx flowfig spec.json out.svg # render a spec file\nnpx flowfig figure.ts out.svg # render a module whose default export is a spec\nnpx flowfig check <input> [--json] # list the faults. The input can also be an SVG that flowfig wrote.\nnpx flowfig verify <input>... # check that the code each source names still exists\nnpx flowfig diff <old> <new> # list what changed in the spec between two figures\nnpx flowfig --spec out.svg # print the spec that an SVG carries\nnpx flowfig open out.svg # show the figure in the default browser\nnpx flowfig gif out.svg [out.gif] # write an animated GIF (needs Chrome, Edge, Chromium or Brave)\nnpx flowfig docs # print this guide\nnpx flowfig init # write these instructions for the coding agents of a repo\n```\n\nA render checks first and writes nothing on an error. `--strict` makes warnings errors. `--width` sets the page width.\n`--min-text` sets the smallest text that the reader should get. `--no-check` skips the check.\n";
3
- /** The short instruction text that `flowfig init` writes for each coding agent. */
1
+ export declare const GUIDE = "# flowfig guide\n\nflowfig draws animated flow figures. A figure has boxes, the edges between the boxes, and steps. In each step, a packet moves along\nthe edges. The output is one animated SVG with no script. The SVG plays in a GitHub README, in PR and issue comments, and in blog\nposts. A figure is about 5 to 50 kB.\n\nYou write a JSON spec. You never write SVG by hand. The command `npx flowfig` checks the spec and renders it.\n\n## What flowfig draws\n\nA spec has three forms.\n\n- The map (the default). The map shows the boxes and the edges. A packet moves along an edge in each beat.\n- The map with a rail (`\"rail\": true`). The rail is a lifeline diagram under the map. It has one row for each message.\n- The rail alone (`\"rail\": \"only\"`). Use it when the reader needs only the order of the messages, for example when the map is already in the same document.\n\nUse the rail for a sequence of messages: a request lifecycle, an API call chain, or a Mermaid `sequenceDiagram`. Put each message on\nan edge. Put each phase in a step. Put messages that run at the same time in one beat. Mark a message that does not wait for an\nanswer with `\"async\": true`: every send to a queue or a topic, every emitted event, and every call the caller does not await.\n\n## Scope: what flowfig draws and what it does not\n\nflowfig draws how something works: parts, the messages between them, and the order of the messages.\n\n| The user asks for | Draw |\n| ------------------------------------------ | ------------------------------------------------------------------------------------------ |\n| An architecture, a data flow, a pipeline | The map. Group parts by service, network or trust boundary. `store` for data at rest. |\n| A request lifecycle, a call chain | The map with `\"rail\": true`. One message per hop, with its real payload in `data`. |\n| A sequence diagram only | `\"rail\": \"only\"`. |\n| A state lifecycle, a state machine | One box per state, one edge per transition, labeled with its event. One step per path. Mark the first state with `mark: \"start\"` and each final state with `mark: \"end\"`. |\n| A flowchart with branches | `shape: \"decision\"` for each branch. One step per path. |\n| A roadmap or a timeline | `timeline: true`. One labeled group per track, in a `column` group. Items with `from` and `to` (dates), a milestone with `from` only, an edge for a dependency, `today` for the line. A dependent item starts after its source ends. |\n| A process across roles (a ticket, an order, a refund) | `lanes: true`. One labeled group per role, in a `column` group. Put each step in the lane of the role that does it. Link each step with `source` to the SOP heading. If the steps do not fit the width, flowfig wraps the time columns into blocks and links the blocks with labeled stubs, so keep the whole process in one figure. Give the outcomes of one decision the same `at`. |\n\nflowfig draws a roadmap or a timeline with dates (`timeline: true`), and converts a Mermaid `gantt` to it. flowfig does not\ndraw class or ER diagrams (fields, types, cardinality), charts of numbers or mind maps. If the user asks for one of these, say that\nflowfig does not draw it, suggest Mermaid (`classDiagram`, `erDiagram`), and draw nothing with flowfig.\n\n## Workflow\n\n### 1. Pick the scope\n\nIf the code has more than one flow, name each flow in the reply. Then draw one flow, or draw one structure view and call it a\nstructure view. If the user asks for the whole system, draw one top view with groups, or a set of figures that together cover\nevery part. Keep each figure to 12 boxes or fewer.\n\n### 2. Write the fact list\n\nBefore the spec, write a list of the facts that the figure must show. Take each fact from the code and from its wiring: config\nfiles, compose files, route tables and queue bindings (or from the pasted Mermaid). Give each fact its `file:line`:\n\n- every part (service, function, store, queue, external system);\n- every call, in order, written as `caller \u2192 callee: payload (file:line of the call)`. The edge in the spec goes from that caller\n to that callee;\n- every call that does not wait for an answer (fire and forget, a queue, a webhook, a callback), and every consumer of each queue\n or topic;\n- every branch and every error path (a rejected input, a retry, a dead-letter path);\n- every end state;\n- for a process document (an SOP): every deadline, every message to a person (an email, a notice), every choice that a person\n makes, and every wait for a reply. Put each one in a box `sub`, a step `say` or a `data` card. A small fact still counts.\n Draw each path to its end: after a rejection, also draw the next step that the document gives. Give each path its own step.\n\nIf the code does not show a fact, leave the fact out. Do not guess a part, a name or an order.\n\n### 3. Write the spec\n\nEach fact becomes a box, an edge, a beat, a `data` card or a `show` row. Use the real names from the code as labels, and\nreal example data from the code or its tests. Keep each fact that you leave out, with the reason, for the reply.\nGive each box and edge that draws code a `source`, from the fact list: `\"src/auth/login.ts#verifyPassword\"`. A store or an outside part may have none.\nA box that draws a step from a document links to that document: `\"docs/sop/refunds.md#step-3-approve-the-refund\"`, the heading as a GitHub anchor. `verify` checks it the same way.\n\nMermaid mapping:\n\n| Mermaid | flowfig |\n| ---------------------------------------- | ------------------------------------------------------------------ |\n| `participant` | a box |\n| `A->>B: text` | an edge from A to B, and a hop with `data: \"text\"` |\n| `B-->>A: text` (a reply) | a hop on the same edge with `back: true` |\n| `A-)B: text` (async) | a hop with `async: true` |\n| `par ... and ... end` | the hops of all branches in one beat |\n| `alt` / `opt` | one step per path |\n| `stateDiagram` states and transitions | boxes, and edges labeled with the event |\n\nA pasted design wins over the async rule: keep each arrow as the Mermaid draws it. `A->>B` stays a plain hop, also for a\nsend to a queue. Mark a hop async only for `-)`. If you think the design is wrong, say so in the reply.\n\n### 4. Render, then fix\n\n```bash\nnpx flowfig - out.svg <<'SPEC'\n{ \"props\": { \"layout\": ..., \"edges\": [...], \"steps\": [...] } }\nSPEC\n```\n\nThe quoted `<<'SPEC'` heredoc passes the JSON with no change. The command checks the spec first. If the check finds an error, the\ncommand writes no SVG and lists the faults. Fix each fault and render again.\n\n- Fix a layout fault by changing the layout first: put parts in rows or columns, route an edge `around`, or change a gap.\n Never remove a fact from the fact list to pass the check. If you must remove one, name it in the reply.\n- If `small-text` appears, the figure is too wide. Put the parts in two rows, move a detail from `label` to `sub`, or split\n the figure. Use more steps in one figure before you make a second figure. Keep the real name from the code in the label:\n `ReportsController` stays `ReportsController`, not `Controller`. Do not change `--width` to pass the check: the\n reader sees the figure at the real page width.\n- If `text-overflow` appears, a text is wider than its box. Give the box a larger `width`, move a detail from `label` to\n `sub`, or put the detail in the step `say`. Never cut a fact, a number or a unit to make a text fit: \"within 30 days of\n delivery\" does not become \"within 30 days\". If you must shorten a text, keep every fact and name the change in the reply.\n- Fix every other warning, or tell the user why it stays.\n- Do not use `--no-check` to hide a fault.\n\n### 5. Read the figure back\n\nRun `npx flowfig --spec out.svg`. Compare the spec with the fact list. Check that each edge goes from the caller to the callee\nthat its fact names. Add each fact that is missing, fix each wrong edge, and render again.\n\nRun `npx flowfig verify out.svg` from the repo root. Fix each `missing-file` or `missing-symbol`.\n\n### 6. Look at the SVG\n\nThe check estimates the text width, so it cannot see everything. If you can open a browser, open the SVG and take a\nscreenshot. Wait a few seconds and take a second screenshot to see a later beat. If you cannot open a browser, write \"not\nlooked at\" in the reply. Never report a look that you did not do. A browser tool can block `file://` URLs. If it does, serve the folder\nwith `python3 -m http.server`.\n\n### 7. Write the reply\n\nThe reply has these parts, in this order:\n\n1. the path of each SVG;\n2. what each figure shows: the parts and the steps. Copy the counts from the `figure:` line of the check output. Copy every name\n from the read-back spec. Never count from memory;\n3. the scope: the flow you drew, why, and the other flows that exist;\n4. what the figure leaves out, and why;\n5. the two check lines that the render printed, `0 errors, 0 warnings` and `figure: ...`, copied as printed, and whether\n you looked at the SVG;\n6. one line `npx flowfig open <path>` for each SVG, at the end of the reply. Do not run that command yourself.\n\nTo change an SVG later, print its spec with `--spec`, change the spec, and render again.\n\n## Spec reference\n\n`props` has these fields.\n\n| Field | Type | Meaning |\n| ---------- | ----------------------- | ---------------------------------------------------------------------------------------------- |\n| `layout` | group | The boxes and how they line up. Required. |\n| `edges` | edge[] | The arrows between the boxes. Required. |\n| `steps` | step[] | The stories the figure tells. With no steps, the figure is a still map. |\n| `lanes` | `true` | Draw the layout as swimlanes: a `column` group of labeled groups, one per role. The boxes run left to right in step order. |\n| `timeline` | `true` | Draw the layout as a timeline: one labeled group per track, with the boxes placed by their `from` and `to` dates. |\n| `today` | `YYYY-MM-DD` | In a `timeline` figure: the date where the today line stops. Default: the last date of the items. |\n| `rail` | `true` or `\"only\"` | Draw the steps as a lifeline rail under the map. `\"only\"` draws the rail without the map. |\n| `speed` | number | Milliseconds a packet takes to cross one edge. Default: 900. |\n| `theme` | object | Colors: `accent`, `fg`, `muted`, `bg`, `surface`, `border`, `font`. Each color you omit keeps its built-in value. |\n\n### layout\n\nThe layout is a tree. A group has `children` and these optional fields.\n\n- `id`: a name that an edge can use to reach the group as a whole.\n- `label`: the title on the frame. Only a group with a `label` gets a frame.\n- `direction`: `\"row\"` (the default) or `\"column\"`.\n- `gap`: the space between children in px. Default: 28 for a column. For a row, the gap fits the widest edge label between two children (at least 56).\n- `align`: `\"start\"`, `\"center\"` or `\"end\"`. This sets where the children line up across the direction.\n\nEvery other item is a box.\n\n| Box field | Meaning |\n| --------- | --------------------------------------------------------------------------------------------------------- |\n| `id` | Required. The name that edges and steps use. It must be unique in the figure. |\n| `label` | Required. The title in the box. |\n| `sub` | A smaller line under the label. |\n| `shape` | `\"box\"` (default), `\"decision\"` (a diamond) or `\"store\"` (a database cylinder for data at rest). |\n| `at` | In a `lanes` figure: the time column of the box, 0 first. Default: the order in which the steps first reach the box. |\n| `from` | In a `timeline` figure: the start of the item, or the date of a milestone, as YYYY-MM-DD. |\n| `to` | In a `timeline` figure: the last day of the item, as YYYY-MM-DD. Without it the box is a milestone. |\n| `width` | Width in px. This overrides the width that the layout picks. |\n| `source` | The code this draws: `path` or `path#symbol`, relative to the repo root. `flowfig verify` checks it. |\n| `lines` | The least number of text lines that a content card keeps. The card still grows to fit its content. |\n| `tone` | The state color of the box: a 1 px border and a light tint. Use `blue`, `purple`, `green`, `orange`, `red` or `gray`. |\n| `mark` | `\"start\"` or `\"end\"` | A lifecycle mark: a filled dot before a start state, a ringed dot after an end state. |\n\n### edges\n\nAn edge has these fields.\n\n- `id`: the name that steps use. Default: `from->to`.\n- `from` and `to`: the `id` of a box or a group.\n- `label`: text on the edge, drawn as a small pill.\n- `around`: `\"above\"` or `\"below\"`. This routes the edge over or under the boxes in between (loops, skip-ahead edges).\n- `quiet`: if `true`, the SVG draws the edge only while a step uses it.\n- `source`: the code this edge draws, as `path` or `path#symbol`. `flowfig verify` checks it.\n\n### steps\n\nA step has `label` and `flow`. It can also have `caption` (the line under the figure while no beat has a `say`) and `nodes` (ids of\nboxes to highlight for the whole step).\n\n`flow` is a list of beats. A beat is one of these:\n\n- an edge id (a string);\n- an array of edge ids, which run at the same time;\n- an object `{ edges?, say?, show?, light?, ms? }`. A beat with no `edges` is a pause.\n\nThe beat fields:\n\n- `edges`: an edge id, a hop object, or an array of these. A hop object is `{ edge, back?, data?, tone?, async?, source? }`.\n - `back: true` runs the packet from the `to` box to the `from` box.\n - `data` is a small card that moves with the packet.\n - `async: true` marks a message that does not wait for an answer. The rail draws it dashed, with an `async` tag.\n - `tone`: the color of this hop for its beat. The packet, the data card, the edge, the label pill and the arrival box take the color. The trail after the beat stays the accent.\n - `green`: a success or a cache hit. `orange`: a warning, a miss or a retry. `red`: an error or a rejected input.\n - `gray`: idle or skipped. `purple`: async or background. `blue`: the default row color.\n - If the hop has no `tone`, the arrival box uses its box `tone`, then the accent. A hop `tone` wins over a box `tone`.\n- `say`: the caption for the beat.\n- `show`: `{ boxId: [row, ...] }`. This fills the content card of each named box. The card keeps the rows until the step ends.\n- `light`: ids of boxes to highlight for this beat.\n- `ms`: how long the beat lasts. Default: the time one packet needs to cross an edge.\n\nA row of a content card is `{ tag?, tone?, text, meta?, mark?, mono? }`.\n\n- `tag`: a short colored label at the start of the line.\n- `tone`: the color of the tag: `blue` (default), `purple`, `green`, `orange`, `red` or `gray`.\n- `text`: the main text.\n- `meta`: muted text after the main text.\n- `mark`: a mark at the right end of the line, such as a check or \"new\".\n- `mono`: if `true`, the text uses a monospace font.\n\n## Content rules\n\n- Give every box a stable `id`.\n- Use `shape: \"store\"` for data at rest (a database, a cache, a file, a queue). Use a plain box for a part that does work. Use `shape: \"decision\"` for a branch.\n- Keep one clear main path, left to right. Put side parts in a `column` group.\n- Use `quiet: true` on a long edge that crosses the picture. A quiet edge needs a beat that uses it, or the check reports\n `hidden-edge`.\n- In a rail, draw an error reply as a hop back on the same edge, with the error in `data` (`{ \"edge\": \"login\", \"back\": true,\n \"data\": \"401 CREDENTIALS_INVALID\" }`). A call that stays inside one part (a hash check, a guard) is not a message: put it in\n `say` or in a `show` row of that part.\n- Keep an SVG to one or two steps. The SVG plays every step in a loop, with no controls.\n- Use the React player, `<Flow {...props} />` from `flowfig`, for a page that needs tabs, pause or hover.\n\n## Example\n\n```json\n{\n \"props\": {\n \"layout\": {\n \"children\": [\n { \"id\": \"client\", \"label\": \"Browser\" },\n { \"id\": \"api\", \"label\": \"API Server\" },\n { \"id\": \"db\", \"label\": \"Database\", \"shape\": \"store\" }\n ]\n },\n \"edges\": [\n { \"id\": \"req\", \"from\": \"client\", \"to\": \"api\", \"label\": \"GET /users/42\" },\n { \"id\": \"q\", \"from\": \"api\", \"to\": \"db\", \"label\": \"SELECT\" }\n ],\n \"steps\": [\n {\n \"label\": \"read\",\n \"flow\": [\n { \"edges\": { \"edge\": \"req\", \"data\": \"GET /users/42\" }, \"say\": \"The browser asks for user 42.\" },\n { \"edges\": \"q\", \"show\": { \"db\": [{ \"tag\": \"row\", \"tone\": \"gray\", \"text\": \"Ada Lovelace\" }] }, \"say\": \"The API server reads the row.\" },\n { \"edges\": { \"edge\": \"req\", \"back\": true, \"data\": \"200 OK\" }, \"say\": \"The API server sends the user.\" }\n ]\n }\n ]\n }\n}\n```\n\n## Commands\n\n```bash\nnpx flowfig - out.svg < spec.json # render a spec from stdin\nnpx flowfig spec.json out.svg # render a spec file\nnpx flowfig figure.ts out.svg # render a module whose default export is a spec\nnpx flowfig check <input> [--json] # list the faults. The input can also be an SVG that flowfig wrote.\nnpx flowfig verify <input>... # check that the code each source names still exists\nnpx flowfig diff <old> <new> # list what changed in the spec between two figures\nnpx flowfig --spec out.svg # print the spec that an SVG carries\nnpx flowfig open out.svg # show the figure in the default browser\nnpx flowfig gif out.svg [out.gif] # write an animated GIF (needs Chrome, Edge, Chromium or Brave)\nnpx flowfig docs # print this guide\nnpx flowfig init # write these instructions for the coding agents of a repo\n```\n\nA render checks first and writes nothing on an error. `--strict` makes warnings errors. `--width` sets the page width.\n`--min-text` sets the smallest text that the reader should get. `--no-check` skips the check.\n";
4
2
  export declare const AGENT_TEXT = "# Diagrams with flowfig\n\nIf the user names no other tool, use flowfig for every diagram, figure, flowchart or picture of how something works. Do not answer with a Mermaid block or ASCII art. Use it for an architecture, a data flow or pipeline, a request lifecycle,\na call sequence, a state lifecycle, or a flowchart. flowfig also converts a pasted Mermaid flowchart, `stateDiagram` or\n`sequenceDiagram`.\n\nflowfig draws a roadmap or a timeline with dates (`timeline: true`), and converts a Mermaid `gantt` to it. flowfig does not\ndraw class or ER diagrams or charts of numbers. For those, tell the user so, suggest Mermaid (`classDiagram`, `erDiagram`),\nand draw nothing with flowfig.\n\n1. Run `npx flowfig docs` and read it. If the command fails, stop: tell the user that flowfig is not available, give them\n `npm install --save-dev flowfig`, and draw nothing with another tool.\n2. Pick the scope. If the code has more than one flow, name each flow in the reply, then draw one flow, or draw one structure\n view and call it a structure view. If the user asks for the whole system, draw one top view with groups, or a set of figures\n that together cover every part. Keep each figure to 12 boxes or fewer. For a process that several roles do, use\n `lanes: true`, one labeled group per role. For a plan or a roadmap, read the dates from the document and use `timeline: true`.\n3. Write a fact list from the code and from its wiring (config, compose, route and queue files). Write each call as\n `caller \u2192 callee: payload (file:line of the call)`, in order. Include each async call and every consumer of a queue, each\n branch and error path, and each end state. Leave out what the code does not show.\n4. Write the spec from the fact list, with the real names and data. Render it with `npx flowfig - out.svg <<'SPEC'` and the\n JSON in the heredoc. Fix every fault by changing the layout first (rows, `around`, the gap). Never remove a fact to pass\n the check; if you must remove one, name it in the reply. If `small-text` appears, use two rows or split the figure; keep\n the real names; do not change `--width`. Give each box and edge that draws code a `source` (`file#symbol`) from the fact list.\n Mark every send to a queue or a topic, every emitted event, and every call the caller does not await with `async: true`.\n5. Run `npx flowfig --spec out.svg` and compare it with the fact list: each edge must go from the caller to the callee that the\n fact names. Fix each gap. Then run `npx flowfig verify out.svg` from the repo root and fix each fault.\n6. If you can open a browser, look at the SVG at two moments of the loop. If you cannot, write \"not looked at\" in the reply.\n Never report a look that you did not do.\n7. Reply with: the SVG path; what it shows, with the counts copied from the `figure:` line and the names copied from the read-back spec; what it leaves out and why;\n the two lines the render printed, `0 errors, 0 warnings` and `figure: ...`, copied as printed.\n End the reply with one line `npx flowfig open <path>` for each SVG. Do not run that command yourself.\n";
5
- /** The description of the Claude skill: the words that make the agent load it. */
6
3
  export declare const SKILL_DESCRIPTION = "Use for every request for a diagram, figure, flowchart or picture of how something works, when the user names no other tool. Do not answer with a Mermaid block or ASCII art. Use when the user asks for a diagram, figure or animation of how code or a system works: an architecture, a data flow, a pipeline, a request lifecycle, a call sequence, a state lifecycle, a flowchart, a roadmap or a timeline; when the user pastes a Mermaid flowchart, stateDiagram, sequenceDiagram or gantt to convert; or when the user asks for a class or ER diagram.";
package/dist/guide.js CHANGED
@@ -1,5 +1,3 @@
1
- // The texts that `flowfig docs` and `flowfig init` print or write. Plain strings, so they ship in dist/.
2
- /** The full guide, as Markdown. `flowfig docs` prints it. */
3
1
  export const GUIDE = `# flowfig guide
4
2
 
5
3
  flowfig draws animated flow figures. A figure has boxes, the edges between the boxes, and steps. In each step, a packet moves along
@@ -60,6 +58,7 @@ files, compose files, route tables and queue bindings (or from the pasted Mermai
60
58
  - every end state;
61
59
  - for a process document (an SOP): every deadline, every message to a person (an email, a notice), every choice that a person
62
60
  makes, and every wait for a reply. Put each one in a box \`sub\`, a step \`say\` or a \`data\` card. A small fact still counts.
61
+ Draw each path to its end: after a rejection, also draw the next step that the document gives. Give each path its own step.
63
62
 
64
63
  If the code does not show a fact, leave the fact out. Do not guess a part, a name or an order.
65
64
 
@@ -82,6 +81,9 @@ Mermaid mapping:
82
81
  | \`alt\` / \`opt\` | one step per path |
83
82
  | \`stateDiagram\` states and transitions | boxes, and edges labeled with the event |
84
83
 
84
+ A pasted design wins over the async rule: keep each arrow as the Mermaid draws it. \`A->>B\` stays a plain hop, also for a
85
+ send to a queue. Mark a hop async only for \`-)\`. If you think the design is wrong, say so in the reply.
86
+
85
87
  ### 4. Render, then fix
86
88
 
87
89
  \`\`\`bash
@@ -99,6 +101,9 @@ command writes no SVG and lists the faults. Fix each fault and render again.
99
101
  the figure. Use more steps in one figure before you make a second figure. Keep the real name from the code in the label:
100
102
  \`ReportsController\` stays \`ReportsController\`, not \`Controller\`. Do not change \`--width\` to pass the check: the
101
103
  reader sees the figure at the real page width.
104
+ - If \`text-overflow\` appears, a text is wider than its box. Give the box a larger \`width\`, move a detail from \`label\` to
105
+ \`sub\`, or put the detail in the step \`say\`. Never cut a fact, a number or a unit to make a text fit: "within 30 days of
106
+ delivery" does not become "within 30 days". If you must shorten a text, keep every fact and name the change in the reply.
102
107
  - Fix every other warning, or tell the user why it stays.
103
108
  - Do not use \`--no-check\` to hide a fault.
104
109
 
@@ -282,7 +287,6 @@ npx flowfig init # write these instructions for the coding
282
287
  A render checks first and writes nothing on an error. \`--strict\` makes warnings errors. \`--width\` sets the page width.
283
288
  \`--min-text\` sets the smallest text that the reader should get. \`--no-check\` skips the check.
284
289
  `;
285
- /** The short instruction text that `flowfig init` writes for each coding agent. */
286
290
  export const AGENT_TEXT = `# Diagrams with flowfig
287
291
 
288
292
  If the user names no other tool, use flowfig for every diagram, figure, flowchart or picture of how something works. Do not answer with a Mermaid block or ASCII art. Use it for an architecture, a data flow or pipeline, a request lifecycle,
@@ -315,5 +319,4 @@ and draw nothing with flowfig.
315
319
  the two lines the render printed, \`0 errors, 0 warnings\` and \`figure: ...\`, copied as printed.
316
320
  End the reply with one line \`npx flowfig open <path>\` for each SVG. Do not run that command yourself.
317
321
  `;
318
- /** The description of the Claude skill: the words that make the agent load it. */
319
322
  export const SKILL_DESCRIPTION = 'Use for every request for a diagram, figure, flowchart or picture of how something works, when the user names no other tool. Do not answer with a Mermaid block or ASCII art. Use when the user asks for a diagram, figure or animation of how code or a system works: an architecture, a data flow, a pipeline, a request lifecycle, a call sequence, a state lifecycle, a flowchart, a roadmap or a timeline; when the user pastes a Mermaid flowchart, stateDiagram, sequenceDiagram or gantt to convert; or when the user asks for a class or ER diagram.';
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { type FlowProps } from './model.ts';
2
2
  export type * from './model.ts';
3
3
  export { LIGHT, DARK } from './model.ts';
4
4
  /**
5
- * The interactive player for one figure: tabs for the steps, play and pause, speed, hover and full screen.
6
- * Give it a `FlowProps` spec. Use `toSvg` from `flowfig/svg` for a static animated SVG instead.
5
+ * The interactive player for one figure. Give it a `FlowProps` spec.
6
+ * Use `toSvg` from `flowfig/svg` for a static animated SVG.
7
7
  */
8
8
  export declare function Flow({ layout, edges, steps: stepsIn, theme, speed, autoplay, check, rail: withRail, lanes, timeline, today, }: FlowProps): import("react").JSX.Element;