@demlik/tea 0.7.0 → 0.8.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 (45) hide show
  1. package/dist/chart/index.d.ts +72 -789
  2. package/dist/chart/index.js +4 -232
  3. package/dist/chart/index.js.map +1 -1
  4. package/dist/chart/inspect/index.d.ts +85 -0
  5. package/dist/chart/inspect/index.js +5 -0
  6. package/dist/chart/inspect/index.js.map +1 -0
  7. package/dist/chart/inspect/react.d.ts +112 -0
  8. package/dist/chart/inspect/react.js +11 -0
  9. package/dist/chart/inspect/react.js.map +1 -0
  10. package/dist/chart/inspect/styles.css +286 -0
  11. package/dist/chart/lane/index.d.ts +361 -0
  12. package/dist/chart/lane/index.js +9 -0
  13. package/dist/chart/lane/index.js.map +1 -0
  14. package/dist/chart/lane/react.d.ts +83 -0
  15. package/dist/chart/lane/react.js +559 -0
  16. package/dist/chart/lane/react.js.map +1 -0
  17. package/dist/chart/lane/styles.css +498 -0
  18. package/dist/chart/report/index.d.ts +116 -0
  19. package/dist/chart/report/index.js +32 -0
  20. package/dist/chart/report/index.js.map +1 -0
  21. package/dist/chunk-5KJKJOFC.js +758 -0
  22. package/dist/chunk-5KJKJOFC.js.map +1 -0
  23. package/dist/chunk-E6GEDSF4.js +307 -0
  24. package/dist/chunk-E6GEDSF4.js.map +1 -0
  25. package/dist/chunk-JER5O7PQ.js +416 -0
  26. package/dist/chunk-JER5O7PQ.js.map +1 -0
  27. package/dist/chunk-UOC2PL46.js +13 -0
  28. package/dist/chunk-UOC2PL46.js.map +1 -0
  29. package/dist/chunk-WRAA7GVZ.js +209 -0
  30. package/dist/chunk-WRAA7GVZ.js.map +1 -0
  31. package/dist/chunk-ZCL7SCBK.js +685 -0
  32. package/dist/chunk-ZCL7SCBK.js.map +1 -0
  33. package/dist/chunk-ZD6PNZBK.js +457 -0
  34. package/dist/chunk-ZD6PNZBK.js.map +1 -0
  35. package/dist/devtools/index.js +2 -207
  36. package/dist/devtools/index.js.map +1 -1
  37. package/dist/fold-Blbhru48.d.ts +435 -0
  38. package/dist/graph-CcjWZVrd.d.ts +923 -0
  39. package/dist/machine-viz/index.d.ts +18 -1
  40. package/dist/machine-viz/index.js +2 -8
  41. package/dist/machine-viz/index.js.map +1 -1
  42. package/dist/reducer-BqyoVyBG.d.ts +447 -0
  43. package/dist/run-BVeqJDBF.d.ts +713 -0
  44. package/dist/samples-DCt6nF8H.d.ts +59 -0
  45. package/package.json +24 -1
@@ -1,791 +1,6 @@
1
1
  import { C as Cmd, T as Transitions, R as Reducer } from '../core-Bjc0bS8j.js';
2
-
3
- /**
4
- * A type smuggled through a value position. `ty<{ at: number }>()` is an empty
5
- * object at runtime whose TYPE remembers `{ at: number }` — which is what lets
6
- * an event declare its payload IN the chart instead of in a parallel type map
7
- * the author has to keep in step.
8
- */
9
- interface Ty<T> {
10
- readonly __ty: T;
11
- }
12
- declare const ty: <T>() => Ty<T>;
13
- /** `Ty<T>` → `T`; anything else (an absent `data`) → the neutral `unknown`. */
14
- type Payload<X> = X extends Ty<infer T> ? T : unknown;
15
- type EvMap<C> = C extends {
16
- readonly events: infer E;
17
- } ? E : never;
18
- type CmdMap<C> = C extends {
19
- readonly cmds: infer M;
20
- } ? M : Record<never, never>;
21
- type Groups<C> = C extends {
22
- readonly states: infer G;
23
- } ? G : never;
24
- type CtxOf<C> = C extends {
25
- readonly ctx: infer T;
26
- } ? Payload<T> : unknown;
27
- type EventName<C> = Extract<keyof EvMap<C>, string>;
28
- type CmdName<C> = Extract<keyof CmdMap<C>, string>;
29
- /** The named phases — `keyof states`. A group name is declared by BEING a key. */
30
- type GroupName<C> = Extract<keyof Groups<C>, string>;
31
- type StateName<C> = Extract<{
32
- [G in keyof Groups<C>]: keyof Groups<C>[G];
33
- }[keyof Groups<C>], string>;
34
- /** The node for state `S`, found by scanning the groups. Groups partition. */
35
- type NodeAt<C, S> = {
36
- [G in keyof Groups<C>]: S extends keyof Groups<C>[G] ? Groups<C>[G][S] : never;
37
- }[keyof Groups<C>];
38
- /** The phase `S` lives in. A union here means `S` was declared twice. */
39
- type GroupOf<C, S> = Extract<{
40
- [G in keyof Groups<C>]: S extends keyof Groups<C>[G] ? G : never;
41
- }[keyof Groups<C>], string>;
42
- type OnOf<X> = X extends {
43
- readonly on: infer O;
44
- } ? O : Record<never, never>;
45
- type IgnoreOf<X> = X extends {
46
- readonly ignore: readonly (infer I)[];
47
- } ? Extract<I, string> : never;
48
- type DataOf<X> = X extends {
49
- readonly data: infer D;
50
- } ? Payload<D> : unknown;
51
- type IsEndOf<X> = X extends {
52
- readonly end: true;
53
- } ? true : false;
54
- type IsInitialOf<X> = X extends {
55
- readonly initial: true;
56
- } ? true : false;
57
- type IsForeignOf<X> = X extends {
58
- readonly foreign: true;
59
- } ? true : false;
60
- type ScopeOf<X> = X extends {
61
- readonly scope: infer S;
62
- } ? S extends readonly string[] ? S[number] : S : never;
63
- type On<C, S> = OnOf<NodeAt<C, S>>;
64
- type IgnoredAt<C, S> = IgnoreOf<NodeAt<C, S>>;
65
- /** A cmd reference on an edge: one declared name, or an ORDERED list of them. */
66
- type CmdRef<N extends string> = N | readonly N[];
67
- type EdgeSpec<SN extends string, CN extends string> = SN | {
68
- readonly to: readonly SN[];
69
- readonly cell: string;
70
- } | {
71
- readonly target: SN;
72
- readonly cmd?: CmdRef<CN>;
73
- } | {
74
- readonly target: SN;
75
- readonly when: string;
76
- readonly otherwise: SN;
77
- /** Fires only when the guard HOLDS. */
78
- readonly cmd?: CmdRef<CN>;
79
- /** Fires only when the guard FAILS — `Cmd.when` lifted onto the edge. */
80
- readonly otherwiseCmd?: CmdRef<CN>;
81
- } | {
82
- readonly resume: {
83
- readonly fallback: SN;
84
- };
85
- readonly cmd?: CmdRef<CN>;
86
- };
87
- /** The `scope` field AS DECLARED — before the list is flattened to its members. */
88
- type ScopeDeclOf<X> = X extends {
89
- readonly scope: infer S;
90
- } ? S : never;
91
- type ScopeElems<S> = S extends readonly (infer T)[] ? T : S;
92
- /**
93
- * Is this event's `scope` something the AUTHOR wrote, or is it tsc's fallback?
94
- *
95
- * When some OTHER error in the chart literal (a typo'd target, say) defeats
96
- * inference of `C`, tsc falls back to the `Chart<C>` constraint, where `scope`
97
- * is the whole `"edges" | "all" | GroupName<C> | readonly (…)[]` universe. Left
98
- * alone that makes every event look live in every phase and buries the one real
99
- * diagnostic under a wall of spurious unhandled-pair demands.
100
- *
101
- * The fallback is recognised BY ITS SHAPE, not by what it happens to cover: it
102
- * is the one form that is a union MIXING a string with a list, which no literal
103
- * can produce. An author's scope is either a word (`"all"`) or a list
104
- * (`["edges", "p"]`) — never both at once.
105
- *
106
- * The older test — "a scope that spans the entire universe is no scope" — was a
107
- * proxy for this, and it misfired on the genuinely authored `["edges","all","p"]`:
108
- * the type layer read it as NO scope (so `MissingPairs<C>` was `never` and the
109
- * chart looked total) while `compile`'s `scopeList(…).includes("all")` read it as
110
- * live everywhere and threw `NoCellError` on the first msg. Testing the shape
111
- * instead makes the two layers agree by construction.
112
- *
113
- * A `string`-typed (non-literal) scope is also not authorable as a decision, so
114
- * it keeps the old reading of "no scope".
115
- */
116
- type IsAuthoredScope<X, S = ScopeDeclOf<X>> = [S] extends [string] ? [string] extends [S] ? false : true : [S] extends [readonly string[]] ? [string] extends [ScopeElems<S>] ? false : true : false;
117
- /** The event's declared scope, once it is established that it IS a declaration. */
118
- type ScopeAt<C, E extends keyof EvMap<C>> = [
119
- IsAuthoredScope<EvMap<C>[E]>
120
- ] extends [true] ? ScopeOf<EvMap<C>[E]> : never;
121
- /** The events that are LIVE at `S` — i.e. that `S` owes a decision about. */
122
- type LiveAt<C, S> = {
123
- [E in EventName<C>]: "all" extends ScopeAt<C, E> ? E : [GroupOf<C, S>] extends [ScopeAt<C, E>] ? E : never;
124
- }[EventName<C>];
125
- /** Pairs at `S` that are live, unhandled and unrefused. Empty = total. */
126
- type MissingAt<C, S> = [IsEndOf<NodeAt<C, S>>] extends [true] ? never : Exclude<LiveAt<C, S>, Extract<keyof On<C, S>, string> | IgnoredAt<C, S>>;
127
- /** Every unhandled pair in the whole chart — `never` when the chart is total. */
128
- type MissingPairs<C> = {
129
- [S in StateName<C>]: `${S}.${Extract<MissingAt<C, S>, string>}`;
130
- }[StateName<C>];
131
- type Chart<C> = {
132
- /** Data EVERY state carries. Declared once; intersected into all of them. */
133
- readonly ctx?: Ty<object>;
134
- readonly events: {
135
- readonly [E in keyof EvMap<C>]: {
136
- readonly data?: Ty<object>;
137
- /**
138
- * "This name is not mine." The Msg is minted by SOMEONE ELSE — a library
139
- * Sub (`@demlik/tea/deadline` dispatching `deadline_exceeded`), a host
140
- * bridge, another machine — so the author cannot rename it and the
141
- * compiler must not decorate it. A foreign event keeps its BARE name in
142
- * the emitted table under every namespace, which is what makes it the
143
- * same event across all N instances. Everything else — payload, `scope`,
144
- * totality, edges — is unchanged: it is a normal event that happens to
145
- * belong to someone else.
146
- */
147
- readonly foreign?: true;
148
- readonly scope: "edges" | "all" | GroupName<C> | readonly ("edges" | "all" | GroupName<C>)[];
149
- };
150
- };
151
- readonly cmds?: {
152
- readonly [N in keyof CmdMap<C>]: Ty<object>;
153
- };
154
- readonly states: {
155
- readonly [G in keyof Groups<C>]: {
156
- readonly [S in keyof Groups<C>[G]]: {
157
- /** Exactly one state in a machine-bearing chart marks itself the entry. */
158
- readonly initial?: true;
159
- /** Extra data only THIS state carries, on top of `ctx`. */
160
- readonly data?: Ty<object>;
161
- readonly on?: {
162
- readonly [E in EventName<C>]?: EdgeSpec<StateName<C>, CmdName<C>>;
163
- };
164
- /** Per-state exception: refuse a live event by name. */
165
- readonly ignore?: readonly EventName<C>[];
166
- readonly end?: true;
167
- };
168
- };
169
- };
170
- };
171
- type KnownEdgeField = "target" | "cmd" | "otherwiseCmd" | "when" | "otherwise" | "resume" | "to" | "cell";
172
- /**
173
- * A cell edge OWNS its transition end to end — it picks the target and returns
174
- * its own cmds. So every declarative field that would also decide one of those
175
- * is illegal ALONGSIDE it, rather than silently ignored by the walk:
176
- *
177
- * `cmd`/`otherwiseCmd` — the cell already returns the cmd list (req. 4)
178
- * `when`/`otherwise` — the cell already chose (a guard would choose twice)
179
- * `target`/`resume` — same fact as `to`, said a second way
180
- *
181
- * The `assign` bypass (req. 6) is caught one level up: `Assigns` is keyed by
182
- * `EdgeKey` MINUS the cell edges, so writing `"polling.poll_failed"` in the
183
- * assign bag of a cell edge is an excess property, named by tsc.
184
- */
185
- type CellFieldConflict = "target" | "cmd" | "otherwiseCmd" | "when" | "otherwise" | "resume";
186
- /**
187
- * A resume edge OWNS its transition the same way a cell edge does: the target
188
- * is `st.was ?? fallback`, which is neither declared nor chosen by a guard. So
189
- * every field that would ALSO decide the target is illegal alongside it, rather
190
- * than accepted and then skipped by the walk — `buildCell` tests `edge.resume`
191
- * first, so a `when` beside it is a guard the author writes, maintains and
192
- * reads as load-bearing, and which is never once called.
193
- *
194
- * `cmd` is absent from this list deliberately: `EdgeSpec` admits `{ resume, cmd }`
195
- * and the walk fires it, so it is a real, working field on a resume edge.
196
- * `to`/`cell` are absent because `CellCheck` already names that conflict.
197
- */
198
- type ResumeFieldConflict = "target" | "when" | "otherwise" | "otherwiseCmd";
199
- type ResumeCheck<X> = X extends {
200
- readonly resume: unknown;
201
- } ? [Extract<keyof X, ResumeFieldConflict>] extends [never] ? unknown : {
202
- readonly __resumeEdgeCannotAlsoDeclare: Extract<keyof X, ResumeFieldConflict>;
203
- } : unknown;
204
- /**
205
- * `when` and `otherwise` are ONE fact — "this edge branches" — written in two
206
- * halves, and half of it is not a decision, it is a hole.
207
- *
208
- * The two layers used to key the `{ then, else }` assign shape off different
209
- * halves: `Cell<C, X, …>` off `X extends { target; otherwise }`, `buildCell`
210
- * off `edge.when !== undefined`. Omit either field and they picked opposite
211
- * shapes — the chart compiled and then died with `payloadFn is not a function`
212
- * on the first message. Both layers now read `when`, and this makes the two
213
- * halves inseparable, so there is no shape left on which they could disagree.
214
- */
215
- type GuardPairCheck<X> = X extends {
216
- readonly when: string;
217
- } ? X extends {
218
- readonly otherwise: unknown;
219
- } ? unknown : {
220
- readonly __whenNeedsAnOtherwiseTarget: true;
221
- } : X extends {
222
- readonly otherwise: unknown;
223
- } ? {
224
- readonly __otherwiseNeedsAWhenGuard: true;
225
- } : unknown;
226
- type CellCheck<X> = X extends {
227
- readonly cell: string;
228
- } ? X extends {
229
- readonly to: readonly unknown[];
230
- } ? [Extract<keyof X, CellFieldConflict>] extends [never] ? unknown : {
231
- readonly __cellEdgeCannotAlsoDeclare: Extract<keyof X, CellFieldConflict>;
232
- } : {
233
- readonly __cellEdgeMustDeclareItsTargetsInTo: true;
234
- } : X extends {
235
- readonly to: readonly unknown[];
236
- } ? {
237
- readonly __toWithoutACellToPickFromIt: true;
238
- } : unknown;
239
- type EdgeCheck<X> = X extends string ? unknown : [Exclude<keyof X, KnownEdgeField>] extends [never] ? CellCheck<X> & ResumeCheck<X> & GuardPairCheck<X> & (X extends {
240
- readonly otherwiseCmd: unknown;
241
- } ? X extends {
242
- readonly when: string;
243
- } ? unknown : {
244
- readonly __otherwiseCmdWithoutAGuard: true;
245
- } : unknown) : {
246
- readonly __edgeHasUnknownField: Exclude<keyof X, KnownEdgeField>;
247
- };
248
- type KnownChartField = "ctx" | "events" | "cmds" | "states";
249
- type KnownEventField = "data" | "foreign" | "scope";
250
- type KnownNodeField = "initial" | "data" | "on" | "ignore" | "end";
251
- type UnknownKeys<X, Known extends string> = Exclude<keyof X, Known>;
252
- type EventCheck<X> = [UnknownKeys<X, KnownEventField>] extends [never] ? unknown : {
253
- readonly __eventHasUnknownField: UnknownKeys<X, KnownEventField>;
254
- };
255
- type NodeCheck<N> = [UnknownKeys<N, KnownNodeField>] extends [never] ? unknown : {
256
- readonly __stateNodeHasUnknownField: UnknownKeys<N, KnownNodeField>;
257
- };
258
- type StrictNode<C, N> = NodeCheck<N> & {
259
- readonly on?: {
260
- readonly [E in keyof OnOf<N>]: E extends EventName<C> ? EdgeCheck<OnOf<N>[E]> : {
261
- readonly __onDeclaresAnUndeclaredEvent: E;
262
- };
263
- };
264
- };
265
- type IsDegenerate<N> = [string] extends [N] ? true : false;
266
- type LiteralAlphabets<C> = ([IsDegenerate<StateName<C>>] extends [true] ? {
267
- readonly __stateNamesMustBeLiteralsNotAComputedStringKey: true;
268
- } : unknown) & ([IsDegenerate<EventName<C>>] extends [true] ? {
269
- readonly __eventNamesMustBeLiteralsNotAComputedStringKey: true;
270
- } : unknown) & ([IsDegenerate<CmdName<C>>] extends [true] ? {
271
- readonly __cmdNamesMustBeLiteralsNotAComputedStringKey: true;
272
- } : unknown) & ([IsDegenerate<GroupName<C>>] extends [true] ? {
273
- readonly __phaseNamesMustBeLiteralsNotAComputedStringKey: true;
274
- } : unknown);
275
- type Strict<C> = LiteralAlphabets<C> & ([UnknownKeys<C, KnownChartField>] extends [never] ? unknown : {
276
- readonly __chartHasUnknownField: UnknownKeys<C, KnownChartField>;
277
- }) & {
278
- readonly events: {
279
- readonly [E in keyof EvMap<C>]: EventCheck<EvMap<C>[E]>;
280
- };
281
- readonly states: {
282
- readonly [G in keyof Groups<C>]: {
283
- readonly [S in keyof Groups<C>[G]]: StrictNode<C, Groups<C>[G][S]>;
284
- };
285
- };
286
- };
287
- type Demand<S extends string, E extends string> = E extends string ? `unhandled pair "${S}.${E}" — declare it in \`on\`, or list "${E}" in this state's \`ignore\`, or narrow the \`scope\` of event "${E}"` : never;
288
- type IsUnion<T, U = T> = T extends unknown ? [U] extends [T] ? false : true : never;
289
- type Total<C> = {
290
- readonly events: {
291
- readonly [E in keyof EvMap<C>]: [IsForeignOf<EvMap<C>[E]>] extends [true] ? E extends `${string}.${string}` ? {
292
- readonly __foreignEventNameCannotContainADot: E;
293
- } : unknown : unknown;
294
- };
295
- readonly states: {
296
- readonly [G in keyof Groups<C>]: {
297
- readonly [S in keyof Groups<C>[G]]: ([MissingAt<C, S>] extends [never] ? unknown : {
298
- readonly [K in Demand<Extract<S, string>, Extract<MissingAt<C, S>, string>>]: never;
299
- }) & (Extract<S, string> extends `${string}.${string}` ? {
300
- readonly __stateNameCannotContainADot: S;
301
- } : unknown) & ([Extract<keyof On<C, S>, string>] extends [never] ? unknown : [IsEndOf<Groups<C>[G][S]>] extends [true] ? {
302
- readonly __endStateCannotDeclareEdges: keyof On<C, S>;
303
- } : unknown) & ([IsUnion<GroupOf<C, S>>] extends [true] ? {
304
- readonly __stateDeclaredInTwoPhases: GroupOf<C, S>;
305
- } : unknown) & ([Exclude<IgnoredAt<C, S>, LiveAt<C, S>>] extends [never] ? unknown : {
306
- readonly __refusalRefusesNothing: Exclude<IgnoredAt<C, S>, LiveAt<C, S>>;
307
- });
308
- };
309
- };
310
- };
311
- /**
312
- * `const C` preserves the nested literals with no `as const` at the call site
313
- * (without it every edge value widens to `string` and every derivation below
314
- * collapses). `Strict` and `Total` sit on the PARAMETER, not on the constraint:
315
- * intersecting them into the constraint makes the typo'd-target diagnostic
316
- * collapse to an index-signature complaint about `string` and lose tsc's
317
- * "Did you mean '"review"'?" suggestion.
318
- */
319
- declare function defineChart<const C extends Chart<C>>(c: C & Strict<C> & Total<C>): C;
320
- type EdgeAt<C, S, E> = E extends keyof On<C, S> ? On<C, S>[E] : never;
321
- /** The `State.Event` pairs that are ACTUALLY declared — not the cross product. */
322
- type EdgeKey<C> = {
323
- [S in StateName<C>]: `${S}.${Extract<keyof On<C, S>, string>}`;
324
- }[StateName<C>];
325
- /** The subset of `EdgeKey` whose transition is delegated to a cell. */
326
- type CellEdgeKey<C> = Extract<{
327
- [S in StateName<C>]: {
328
- [E in keyof On<C, S>]: On<C, S>[E] extends {
329
- readonly cell: string;
330
- } ? `${S}.${Extract<E, string>}` : never;
331
- }[keyof On<C, S>];
332
- }[StateName<C>], string>;
333
- /** The state marked `initial: true` — the chart's entry, as data. */
334
- type InitialState<C> = Extract<{
335
- [S in StateName<C>]: [IsInitialOf<NodeAt<C, S>>] extends [true] ? S : never;
336
- }[StateName<C>], string>;
337
- /** States that carry a `resume` edge out of them — the parking states. */
338
- type ParkingState<C> = Extract<{
339
- [S in StateName<C>]: {
340
- [E in keyof On<C, S>]: On<C, S>[E] extends {
341
- readonly resume: unknown;
342
- } ? S : never;
343
- }[keyof On<C, S>];
344
- }[StateName<C>], string>;
345
- /** The targets a CELL edge declares — the union its cell is clamped to. */
346
- type ToOf<X> = X extends {
347
- readonly to: readonly (infer T)[];
348
- } ? T : never;
349
- /**
350
- * Every state an edge can land on. A guarded edge contributes both arms; a
351
- * cell edge contributes its whole declared `to` fan-out — which is precisely
352
- * why the escape hatch does not blind the derivations (`ResumeTargets`,
353
- * `chartMermaid`) that read the graph's shape.
354
- */
355
- type TargetOf<X> = X extends string ? X : X extends {
356
- readonly to: readonly unknown[];
357
- } ? ToOf<X> : X extends {
358
- readonly target: infer T;
359
- } ? T | (X extends {
360
- readonly otherwise: infer O;
361
- } ? O : never) : never;
362
- /** States with an edge INTO `P` — i.e. the states you could be parked from. */
363
- type ResumeSource<C, P> = {
364
- [S in StateName<C>]: {
365
- [E in keyof On<C, S>]: P extends TargetOf<On<C, S>[E]> ? S : never;
366
- }[keyof On<C, S>];
367
- }[StateName<C>];
368
- /** The `fallback` declared on `P`'s resume edge — Umut's `?? initial`. */
369
- type FallbackOf<C, P> = {
370
- [E in keyof On<C, P>]: On<C, P>[E] extends {
371
- readonly resume: {
372
- readonly fallback: infer F;
373
- };
374
- } ? F : never;
375
- }[keyof On<C, P>];
376
- /**
377
- * Where a resume edge out of parking state `P` can land: any state with an edge
378
- * into `P`, plus the declared fallback. `was ?? initial` lifted to a type — and
379
- * DERIVED, so adding a `BLOCKED` edge from a new state widens the legal `was`.
380
- */
381
- type ResumeTargets<C, P> = Extract<ResumeSource<C, P> | FallbackOf<C, P>, string>;
382
- /**
383
- * `was` is INJECTED here, not authored: a parking state is one with a `resume`
384
- * edge, which the chart already says. Writing `blocked: Ctx & { was: … }` by
385
- * hand would be that same fact a second time.
386
- */
387
- type StateOf<C> = {
388
- [S in StateName<C>]: {
389
- readonly type: S;
390
- } & CtxOf<C> & DataOf<NodeAt<C, S>> & (S extends ParkingState<C> ? {
391
- readonly was: ResumeTargets<C, S>;
392
- } : unknown);
393
- }[StateName<C>];
394
- type MsgOf<C> = {
395
- [E in EventName<C>]: {
396
- readonly type: E;
397
- } & DataOf<EvMap<C>[E]>;
398
- }[EventName<C>];
399
- type CmdOf<C> = [CmdName<C>] extends [never] ? Cmd<never> : {
400
- [N in CmdName<C>]: {
401
- readonly type: N;
402
- } & Payload<CmdMap<C>[N]>;
403
- }[CmdName<C>];
404
- /** The events the chart declares FOREIGN — the names that are not ours to decorate. */
405
- type ForeignEvent<C> = Extract<{
406
- [E in EventName<C>]: [IsForeignOf<EvMap<C>[E]>] extends [true] ? E : never;
407
- }[EventName<C>], string>;
408
- /**
409
- * How the compiled table keys event `E`. Namespacing is PER-EVENT, not
410
- * per-machine: `NS` omitted (`undefined`) namespaces nothing, and a foreign
411
- * event keeps its bare name even under a namespace. Everything stays a literal.
412
- */
413
- type KeyOf<C, NS extends string | undefined, E extends string> = E extends ForeignEvent<C> ? E : NS extends string ? `${NS}.${E}` : E;
414
- /**
415
- * The Msg union AS THE COMPILED TABLE CONSUMES IT — the same derivation as
416
- * `MsgOf`, with the keys the namespace produces. Two namespaces give genuinely
417
- * disjoint literal unions for the author's OWN events, while the foreign events
418
- * are literally shared, because they are the same event.
419
- */
420
- type MsgIn<C, NS extends string | undefined = undefined> = {
421
- [E in EventName<C>]: {
422
- readonly type: KeyOf<C, NS, E>;
423
- } & DataOf<EvMap<C>[E]>;
424
- }[EventName<C>];
425
- type Narrow<U, K> = Extract<U, {
426
- type: K;
427
- }>;
428
- type Data<S, K> = K extends string ? Omit<Narrow<S, K>, "type"> : never;
429
- type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
430
- /**
431
- * What an `assign` must return for a given target. `was` is stripped when the
432
- * target is a parking state: the compiler injects it from `state.type`, so the
433
- * author can neither forget it nor type it wrong.
434
- */
435
- type Assigned<C, S, T> = T extends string ? T extends ParkingState<C> ? Omit<Data<S, T>, "was"> : Data<S, T> : never;
436
- /**
437
- * What `boot()` must return: the initial state's payload, minus the `type` the
438
- * compiler stamps on. The two degenerate charts get a NAMED marker type rather
439
- * than a silent `never`, so the diagnostic says which rule was broken.
440
- */
441
- type InitialData<C, S extends {
442
- type: string;
443
- }> = [
444
- InitialState<C>
445
- ] extends [never] ? {
446
- readonly __chartDeclaresNoInitialState: true;
447
- } : [IsUnion<InitialState<C>>] extends [true] ? {
448
- readonly __chartDeclaresManyInitialStates: InitialState<C>;
449
- } : Data<S, InitialState<C>>;
450
- type Fn<S, M, From, Ev, R> = (state: Narrow<S, From>, msg: Narrow<M, Ev>) => R;
451
- type Cell<C, X, S, M, From, Ev> = X extends {
452
- readonly resume: unknown;
453
- } ? Fn<S, M, From, Ev, UnionToIntersection<Assigned<C, S, ResumeTargets<C, From>>>> : X extends {
454
- readonly when: string;
455
- } ? {
456
- readonly then: Fn<S, M, From, Ev, Assigned<C, S, X extends {
457
- readonly target: infer T;
458
- } ? T : never>>;
459
- readonly else: Fn<S, M, From, Ev, Assigned<C, S, X extends {
460
- readonly otherwise: infer O;
461
- } ? O : never>>;
462
- } : X extends {
463
- readonly target: infer T;
464
- } ? Fn<S, M, From, Ev, Assigned<C, S, T>> : X extends string ? Fn<S, M, From, Ev, Assigned<C, S, X>> : never;
465
- /**
466
- * The payload builders — one per DECLARATIVE edge. Cell edges are excluded:
467
- * a cell returns the whole next state itself, so an `assign` entry for one
468
- * would be dead code the walk never calls. Because this is a mapped type over
469
- * a closed key union, writing that entry anyway is an excess property and tsc
470
- * names it (req. 6 — the bypass is a compile error, not a surprise).
471
- */
472
- type Assigns<C, S extends {
473
- type: string;
474
- }, M extends {
475
- type: string;
476
- }> = {
477
- [K in Exclude<EdgeKey<C>, CellEdgeKey<C>>]: K extends `${infer From}.${infer Ev}` ? Cell<C, EdgeAt<C, From, Ev>, S, M, From, Ev> : never;
478
- };
479
- type GuardName<C> = Extract<{
480
- [S in StateName<C>]: {
481
- [E in keyof On<C, S>]: On<C, S>[E] extends {
482
- readonly when: infer W;
483
- } ? W : never;
484
- }[keyof On<C, S>];
485
- }[StateName<C>], string>;
486
- /** Every cell named by a `{ to, cell }` edge — the escape hatch's alphabet. */
487
- type CellName<C> = Extract<{
488
- [S in StateName<C>]: {
489
- [E in keyof On<C, S>]: On<C, S>[E] extends {
490
- readonly cell: infer W;
491
- } ? W : never;
492
- }[keyof On<C, S>];
493
- }[StateName<C>], string>;
494
- /** Flatten a `CmdRef` — one name, or every name in an ordered list. */
495
- type Flatten<X> = X extends readonly string[] ? X[number] : X;
496
- /** Every cmd an edge can fire, across BOTH guard arms. */
497
- type EdgeCmds<X> = (X extends {
498
- readonly cmd: infer Q;
499
- } ? Flatten<Q> : never) | (X extends {
500
- readonly otherwiseCmd: infer Q;
501
- } ? Flatten<Q> : never);
502
- /** Every cmd name any edge in the chart actually FIRES declaratively. */
503
- type UsedCmdName<C> = Extract<{
504
- [S in StateName<C>]: {
505
- [E in keyof On<C, S>]: EdgeCmds<On<C, S>[E]>;
506
- }[keyof On<C, S>];
507
- }[StateName<C>], string>;
508
- /** What field `F` on an edge REFERENCES — a guard/cell name, or its cmd names. */
509
- type Referenced<X, F extends "when" | "cmd" | "cell"> = F extends "when" ? X extends {
510
- readonly when: infer W;
511
- } ? W : never : F extends "cell" ? X extends {
512
- readonly cell: infer W;
513
- } ? W : never : EdgeCmds<X>;
514
- /**
515
- * Scan the chart for every edge that references `Name` through field `F`.
516
- * `[Name] extends [Referenced<…>]` rather than an equality check, because an
517
- * edge's cmd list references SEVERAL names at once.
518
- */
519
- type SitesWhere<C, F extends "when" | "cmd" | "cell", Name> = {
520
- [S in StateName<C>]: {
521
- [E in keyof On<C, S>]: [Name] extends [Referenced<On<C, S>[E], F>] ? `${S}.${Extract<E, string>}` : never;
522
- }[keyof On<C, S>];
523
- }[StateName<C>];
524
- /**
525
- * `"review.FAIL"` → `[state: ReviewState, msg: FailMsg, at: "review.FAIL"]`.
526
- * Distributes over N sites, so a multi-site name yields a UNION OF TUPLES.
527
- *
528
- * The third element is the correlator. A union of tuples does not, on its own,
529
- * keep `state` and `msg` in step: narrowing `state.type` is a NESTED
530
- * discriminant, and TypeScript's dependent-parameter control-flow analysis
531
- * (TS 4.6, microsoft/TypeScript#47109) only re-narrows sibling parameters from
532
- * a discriminant that is a DIRECT, literal-typed element of the union. `at` is
533
- * exactly that: one `switch (at)` collapses the tuple union to a single member,
534
- * and `state` AND `msg` both narrow with it.
535
- *
536
- * For a single-site name `K` is not a union, so this is a lone tuple and the
537
- * author may keep writing `(s, m) => …`.
538
- */
539
- type SiteArgs<K, S, M> = K extends `${infer From}.${infer Ev}` ? [state: Narrow<S, From>, msg: Narrow<M, Ev>, at: K] : never;
540
- /**
541
- * THE POINT. A guard's parameters come from the edges that REFERENCE it, not
542
- * from a standalone registry declaration — so `retriesRemaining`, used only at
543
- * `review.FAIL`, receives exactly `review`'s state and `FAIL`'s msg.
544
- */
545
- type Guards<C, S extends {
546
- type: string;
547
- }, M extends {
548
- type: string;
549
- }> = {
550
- [N in GuardName<C>]: (...args: SiteArgs<SitesWhere<C, "when", N>, S, M>) => boolean;
551
- };
552
- /**
553
- * Same technique: a cmd's parameters come from the edges that REFERENCE it, and
554
- * the payload it owes is the one DECLARED in the chart's `cmds` section — the
555
- * single site where the effect alphabet lives. A cmd fired from two edges gets
556
- * the union of both sites' `[state, msg]` tuples.
557
- */
558
- type Cmds<C, S extends {
559
- type: string;
560
- }, M extends {
561
- type: string;
562
- }> = {
563
- [N in UsedCmdName<C>]: (...args: SiteArgs<SitesWhere<C, "cmd", N>, S, M>) => Payload<CmdMap<C>[N]>;
564
- };
565
- /**
566
- * THE ESCAPE HATCH's parts bag. Same shape and the same `SitesWhere`/`SiteArgs`
567
- * narrowing as `guards` and `cmds` — a cell used at one site gets exactly that
568
- * site's state and msg, a cell used at N sites gets the union of N tuples plus
569
- * the `at` correlator to discriminate on.
570
- *
571
- * What is different is the RETURN: a cell returns the transition itself,
572
- * `[nextState, cmds]`, clamped to the states the edge DECLARED in `to`. That
573
- * clamp is the whole bargain — code may decide, but only among the targets the
574
- * chart admits, so the chart stays a truthful drawing of the machine.
575
- */
576
- type Cells<C, S extends {
577
- type: string;
578
- }, M extends {
579
- type: string;
580
- }> = {
581
- [N in CellName<C>]: CellForm<C, SitesWhere<C, "cell", N>, S, M>;
582
- };
583
- /** The `to` union of every site `N` is used at, resolved to real State members. */
584
- type CellTarget<C, Sites, S> = Sites extends `${infer From}.${infer Ev}` ? Narrow<S, ToOf<EdgeAt<C, From, Ev>>> : never;
585
- type CellReturn<C, Sites, S> = readonly [
586
- CellTarget<C, Sites, S>,
587
- readonly CmdOf<C>[]
588
- ];
589
- /**
590
- * THE MULTI-SITE RETURN, EXACTLY. One entry per use site, each a lone tuple of
591
- * parameters and each clamped to THAT site's `to` — so `a.X` returning a `c` is
592
- * rejected at `a.X` rather than waved through because some OTHER site admits a
593
- * `c`. The `at` element is still passed (the walk hands it over uniformly), and
594
- * is simply redundant here: the key already says which site this is.
595
- */
596
- type CellBySite<C, Sites, S, M> = {
597
- readonly [K in Extract<Sites, string>]: (...args: SiteArgs<K, S, M>) => CellReturn<C, K, S>;
598
- };
599
- /**
600
- * A cell is written in ONE of two forms, and the choice is the precision dial.
601
- *
602
- * the FUNCTION form — one body, `switch (at)` inside. Parameters narrow per
603
- * site (the `SiteArgs` correlator); the RETURN does not, because the whole
604
- * thing is one rest signature over a union of tuples and TypeScript has no
605
- * dependent return type over that (5.7: a union of function types is
606
- * reduced back to exactly this shape, an intersection loses the parameter
607
- * correlation, and a generic on the site key correlates nothing and merely
608
- * rejects every body — all three measured, none of them work). The clamp is
609
- * therefore the union of every site's `to`.
610
- *
611
- * the PER-SITE form — one entry per site, each exact in both directions.
612
- *
613
- * The second is offered ONLY when the cell is genuinely multi-site: with one
614
- * site the function form is already exact in both directions, so its type stays
615
- * byte-for-byte what it was and the common case cannot regress.
616
- *
617
- * The looseness the function form keeps is closed at RUNTIME instead: the walk
618
- * checks the returned `type` against the edge's declared `to` and throws
619
- * `CellTargetError`. Worth less than a compile error, worth more than nothing —
620
- * and `to` is right there, so it costs one `includes`.
621
- */
622
- type CellForm<C, Sites, S, M> = ((...args: SiteArgs<Sites, S, M>) => CellReturn<C, Sites, S>) | ([IsUnion<Sites>] extends [true] ? CellBySite<C, Sites, S, M> : never);
623
- /** The declared state names — a flat tuple, not a grouped record of nodes. */
624
- type RStateName<C> = C extends {
625
- readonly states: readonly (infer S)[];
626
- } ? Extract<S, string> : never;
627
- /** The top-level edge bag. One edge per event; that IS the totality obligation. */
628
- type ROn<C> = C extends {
629
- readonly on: infer O;
630
- } ? O : never;
631
- type REdgeAt<C, E> = E extends keyof ROn<C> ? ROn<C>[E] : never;
632
- type ReducerChart<C> = {
633
- /** Data EVERY state carries — and, here, the ONLY data any state carries. */
634
- readonly ctx?: Ty<object>;
635
- readonly states: readonly RStateName<C>[];
636
- /** The entry state, by name. One word where the grid form marks a node. */
637
- readonly initial: RStateName<C>;
638
- readonly events: {
639
- readonly [E in keyof EvMap<C>]: {
640
- readonly data?: Ty<object>;
641
- /** Same meaning as the grid form's: this name is not ours to decorate. */
642
- readonly foreign?: true;
643
- };
644
- };
645
- readonly cmds?: {
646
- readonly [N in keyof CmdMap<C>]: Ty<object>;
647
- };
648
- /**
649
- * TOTAL, not partial. Every declared event owes an edge — the `?` the grid
650
- * form's per-state `on` carries is exactly what `Total<C>` had to police
651
- * there, and here the mapped type does it for free.
652
- */
653
- readonly on: {
654
- readonly [E in EventName<C>]: EdgeSpec<RStateName<C>, CmdName<C>>;
655
- };
656
- };
657
- /**
658
- * `resume` needs a phase dimension: `was` is derived from "the states with an
659
- * edge INTO the parking state", and here every edge is reachable from every
660
- * state, so the derivation degenerates to "all of them" and says nothing. It
661
- * is rejected by name rather than silently accepted and ignored by the walk.
662
- */
663
- type RStrictEdge<X> = X extends {
664
- readonly resume: unknown;
665
- } ? {
666
- readonly __resumeNeedsAPhaseDimension: true;
667
- } : EdgeCheck<X>;
668
- /** The reducer form's key alphabet — `scope` has no meaning without phases. */
669
- type KnownReducerChartField = "ctx" | "states" | "initial" | "events" | "cmds" | "on";
670
- type KnownReducerEventField = "data" | "foreign";
671
- type REventCheck<X> = [UnknownKeys<X, KnownReducerEventField>] extends [never] ? unknown : {
672
- readonly __eventHasUnknownField: UnknownKeys<X, KnownReducerEventField>;
673
- };
674
- type StrictR<C> = ([IsDegenerate<RStateName<C>>] extends [true] ? {
675
- readonly __stateNamesMustBeLiteralsNotAComputedStringKey: true;
676
- } : unknown) & ([IsDegenerate<EventName<C>>] extends [true] ? {
677
- readonly __eventNamesMustBeLiteralsNotAComputedStringKey: true;
678
- } : unknown) & ([IsDegenerate<CmdName<C>>] extends [true] ? {
679
- readonly __cmdNamesMustBeLiteralsNotAComputedStringKey: true;
680
- } : unknown) & ([UnknownKeys<C, KnownReducerChartField>] extends [never] ? unknown : {
681
- readonly __chartHasUnknownField: UnknownKeys<C, KnownReducerChartField>;
682
- }) & {
683
- readonly on: {
684
- readonly [E in keyof ROn<C>]: E extends EventName<C> ? RStrictEdge<ROn<C>[E]> : {
685
- readonly __onDeclaresAnUndeclaredEvent: E;
686
- };
687
- };
688
- readonly events: {
689
- readonly [E in keyof EvMap<C>]: REventCheck<EvMap<C>[E]> & ([IsForeignOf<EvMap<C>[E]>] extends [true] ? E extends `${string}.${string}` ? {
690
- readonly __foreignEventNameCannotContainADot: E;
691
- } : unknown : unknown);
692
- };
693
- };
694
- /** Same contract as `defineChart`, one dimension smaller. */
695
- declare function defineReducerChart<const C extends ReducerChart<C>>(c: C & StrictR<C>): C;
696
- /**
697
- * ONE object, not a union: every state carries `ctx` and nothing else, so the
698
- * only thing that varies is the tag. This is the original's
699
- * `interface State { phase: Phase; … }` with `phase` named `type`.
700
- */
701
- type RStateOf<C> = {
702
- readonly type: RStateName<C>;
703
- } & CtxOf<C>;
704
- /** The events whose transition is delegated to a cell. */
705
- type RCellEvent<C> = Extract<{
706
- [E in EventName<C>]: ROn<C>[E & keyof ROn<C>] extends {
707
- readonly cell: string;
708
- } ? E : never;
709
- }[EventName<C>], string>;
710
- type RNames<C, F extends "when" | "cmd" | "cell"> = Extract<{
711
- [E in keyof ROn<C>]: Referenced<ROn<C>[E], F>;
712
- }[keyof ROn<C>], string>;
713
- type RGuardName<C> = RNames<C, "when">;
714
- type RCellName<C> = RNames<C, "cell">;
715
- type RUsedCmdName<C> = RNames<C, "cmd">;
716
- /**
717
- * A site is an EVENT. The grid form's `SitesWhere` scans `state × event`; with
718
- * one dimension the scan is the same shape with the outer loop removed.
719
- */
720
- type RSitesWhere<C, F extends "when" | "cmd" | "cell", Name> = Extract<{
721
- [E in keyof ROn<C>]: [Name] extends [Referenced<ROn<C>[E], F>] ? E : never;
722
- }[keyof ROn<C>], string>;
723
- /**
724
- * The state is NOT narrowed — there is nothing to narrow it to. Everything
725
- * else is `SiteArgs` verbatim, including the `at` correlator that lets a
726
- * multi-site helper discriminate its msg with one `switch`.
727
- */
728
- type RSiteArgs<K, S, M> = K extends string ? [state: S, msg: Narrow<M, K>, at: K] : never;
729
- type RGuards<C, S, M extends {
730
- type: string;
731
- }> = {
732
- [N in RGuardName<C>]: (...args: RSiteArgs<RSitesWhere<C, "when", N>, S, M>) => boolean;
733
- };
734
- type RCmds<C, S, M extends {
735
- type: string;
736
- }> = {
737
- [N in RUsedCmdName<C>]: (...args: RSiteArgs<RSitesWhere<C, "cmd", N>, S, M>) => Payload<CmdMap<C>[N & keyof CmdMap<C>]>;
738
- };
739
- type RCells<C, S extends {
740
- type: string;
741
- }, M extends {
742
- type: string;
743
- }> = {
744
- [N in RCellName<C>]: RCellForm<C, RSitesWhere<C, "cell", N>, S, M>;
745
- };
746
- /** The `to` clamp, unchanged in spirit: the tag is restricted, `ctx` is not. */
747
- type RCellTarget<C, Sites> = Sites extends string ? {
748
- readonly type: Extract<ToOf<REdgeAt<C, Sites>>, string>;
749
- } & CtxOf<C> : never;
750
- type RCellReturn<C, Sites> = readonly [
751
- RCellTarget<C, Sites>,
752
- readonly CmdOf<C>[]
753
- ];
754
- /**
755
- * `CellForm`, with the phase dimension removed — the same two forms, offered on
756
- * the same condition, for the same reason. A site here is an EVENT, so the
757
- * per-site bag is keyed `"X" | "Y"` rather than `"a.X" | "b.Y"`; everything
758
- * else, including the runtime `CellTargetError` under the function form, is the
759
- * grid form's machinery reused verbatim (`buildCell` serves both).
760
- */
761
- type RCellForm<C, Sites, S, M extends {
762
- type: string;
763
- }> = ((...args: RSiteArgs<Sites, S, M>) => RCellReturn<C, Sites>) | ([IsUnion<Sites>] extends [true] ? {
764
- readonly [K in Extract<Sites, string>]: (...args: RSiteArgs<K, S, M>) => RCellReturn<C, K>;
765
- } : never);
766
- /**
767
- * What an `assign` returns: `ctx`, for every target. The compiler stamps
768
- * `type` from the edge, so — as in the grid form — the author cannot forget it
769
- * and cannot get it wrong.
770
- */
771
- type RAssigned<C> = CtxOf<C>;
772
- type RFn<S, M extends {
773
- type: string;
774
- }, E, R> = (state: S, msg: Narrow<M, E>) => R;
775
- type RCell<C, X, S, M extends {
776
- type: string;
777
- }, E> = X extends {
778
- readonly when: string;
779
- } ? {
780
- readonly then: RFn<S, M, E, RAssigned<C>>;
781
- readonly else: RFn<S, M, E, RAssigned<C>>;
782
- } : RFn<S, M, E, RAssigned<C>>;
783
- /** One builder per DECLARATIVE event. Cell events own their whole transition. */
784
- type RAssigns<C, S, M extends {
785
- type: string;
786
- }> = {
787
- [E in Exclude<EventName<C>, RCellEvent<C>>]: RCell<C, REdgeAt<C, E>, S, M, E>;
788
- };
2
+ import { A as Assigns, G as GuardName, l as Guards, U as UsedCmdName, m as Cmds, n as CellName, o as Cells, p as RAssigns, q as RGuardName, r as RGuards, s as RUsedCmdName, t as RCmds, u as RCellName, v as RCells, C as Chart, S as StateOf, M as MsgOf, a as CmdOf, j as MsgIn, R as ReducerChart, b as RStateOf, I as InitialData, f as InitialState } from '../graph-CcjWZVrd.js';
3
+ export { w as CmdEvent, x as CmdName, y as EdgeKey, z as EdgeSpec, B as EndPolarity, i as ErrorFinal, E as EventName, k as EventOrigin, F as ForeignEvent, D as GroupName, H as GroupOf, J as MissingPairs, O as OriginAt, P as ParkingState, K as RStateName, c as StateName, L as SubEvent, h as SuccessFinal, g as Ty, W as WorldEvent, N as WorldRole, Q as defineChart, V as defineReducerChart, X as ty } from '../graph-CcjWZVrd.js';
789
4
 
790
5
  /**
791
6
  * A cell returned a state OUTSIDE its edge's declared `to`.
@@ -929,6 +144,74 @@ declare function initialStateOf<const C extends Chart<C>>(chart: C): InitialStat
929
144
  declare function initFrom<const C extends Chart<C>, S extends {
930
145
  type: string;
931
146
  }, K extends Cmd>(chart: C, boot: () => InitialData<C, S>): (loaded: S | null) => readonly [S, readonly K[]];
932
- declare function chartMermaid<const C extends Chart<C>>(chart: C): string;
147
+ /** How many times each {@link edgeKey} was walked. */
148
+ type WalkCounts = ReadonlyMap<string, number>;
149
+ /**
150
+ * The key a {@link ChartMermaidOptions.walked} map is read by.
151
+ *
152
+ * One spelling, shared by whoever counts the walk and the drawing that marks
153
+ * it — the names are the chart's OWN, unsanitized, because the counter reads
154
+ * them off a log and has no business knowing what mermaid can spell.
155
+ *
156
+ * NOT `EdgeKey<C>` (`graph.ts`), despite the casing. That one is the SITE tag
157
+ * — `"state.event"` — which is what a guard or a cmd builder is keyed by,
158
+ * because a site is where code hangs. This one names a drawn ARROW, and a
159
+ * guarded site draws two of them, so it needs the target as well.
160
+ */
161
+ declare const edgeKey: (from: string, event: string, to: string) => string;
162
+ /**
163
+ * Options for {@link chartMermaid}. Every field is optional and every default
164
+ * reproduces the drawing this function emitted before options existed — a flat
165
+ * node set, `direction TB`, no title, no highlight, no polarity and no walk —
166
+ * so an existing caller is untouched.
167
+ *
168
+ * Shaped after `MachineVizOptions` (`../machine-viz`) where the two overlap
169
+ * (`direction`, `title`), because the two drawings are read side by side and a
170
+ * second spelling of the same knob is a fact said twice. What is NOT shared is
171
+ * `samples`: `toMermaid` needs them because it must EXECUTE a compiled cell to
172
+ * learn a target; the chart declares its targets, so there is nothing to
173
+ * resolve and nothing to sample.
174
+ */
175
+ interface ChartMermaidOptions {
176
+ /**
177
+ * Draw this state as the ACTIVE node — a `classDef`/`class` pair Mermaid
178
+ * renders with the highlight fill. Pass the live `state.type`. A name that is
179
+ * not in the chart is ignored rather than drawn as a phantom node.
180
+ */
181
+ readonly highlight?: string;
182
+ /**
183
+ * Draw each phase as a Mermaid COMPOSITE state (`state working { … }`).
184
+ *
185
+ * The chart groups its states into named phases and the flat drawing throws
186
+ * that away — which is the one structural fact `chartMermaid` knew and did
187
+ * not show. Off by default: turning it on changes the emitted text, and the
188
+ * drawing is something a reviewer approves rather than something that moves
189
+ * under them.
190
+ */
191
+ readonly phases?: boolean;
192
+ /**
193
+ * Draw the two ENDINGS differently — a dashed outline on every `end:
194
+ * "error"` final, a heavier one on every `end: true`.
195
+ *
196
+ * A success final and an error final both terminate, so both draw the `[*]`
197
+ * edge, and a picture that stopped there paints `shipped` and `frozen` alike
198
+ * in the one place a reader looks first. Off by default for the same reason
199
+ * `phases` is: it changes the emitted text.
200
+ */
201
+ readonly polarity?: boolean;
202
+ /**
203
+ * Edges the caller actually WALKED, keyed by {@link edgeKey} — each drawn
204
+ * edge that has a count picks up a `»` (or `»×N`) on its label.
205
+ *
206
+ * A missing or zero count marks nothing, so a chart nobody has run through
207
+ * draws exactly as it does without this option.
208
+ */
209
+ readonly walked?: WalkCounts;
210
+ /** Mermaid layout direction. Default `"TB"`. */
211
+ readonly direction?: "TB" | "LR";
212
+ /** Optional title, emitted as a Mermaid front-matter `title:` block. */
213
+ readonly title?: string;
214
+ }
215
+ declare function chartMermaid<const C extends Chart<C>>(chart: C, opts?: ChartMermaidOptions): string;
933
216
 
934
- export { type Assigns, type CellName, CellTargetError, type Cells, type Chart, type CmdName, type CmdOf, type Cmds, type EdgeKey, type EdgeSpec, type EventName, type ForeignEvent, type GroupName, type GroupOf, type GuardName, type Guards, type InitialState, type MissingPairs, type MsgIn, type MsgOf, type ParkingState, type Parts, type RAssigns, type RCellName, type RCells, type RCmds, type RGuardName, type RGuards, type RParts, type RStateName, type RStateOf, type RUsedCmdName, type ReducerChart, type StateName, type StateOf, type Ty, type UsedCmdName, chartMermaid, compile, compileReducer, defineChart, defineReducerChart, initFrom, initialStateOf, reducerInitFrom, reducerMermaid, ty };
217
+ export { Assigns, CellName, CellTargetError, Cells, Chart, type ChartMermaidOptions, CmdOf, Cmds, GuardName, Guards, InitialState, MsgIn, MsgOf, type Parts, RAssigns, RCellName, RCells, RCmds, RGuardName, RGuards, type RParts, RStateOf, RUsedCmdName, ReducerChart, StateOf, UsedCmdName, type WalkCounts, chartMermaid, compile, compileReducer, edgeKey, initFrom, initialStateOf, reducerInitFrom, reducerMermaid };