libpetri 1.8.5 → 2.1.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 (46) hide show
  1. package/README.md +47 -0
  2. package/dist/{chunk-B2D5DMTO.js → chunk-B2CV5M3L.js} +228 -9
  3. package/dist/chunk-B2CV5M3L.js.map +1 -0
  4. package/dist/chunk-H62Z76FY.js +1346 -0
  5. package/dist/chunk-H62Z76FY.js.map +1 -0
  6. package/dist/chunk-RNWTYK5B.js +419 -0
  7. package/dist/chunk-RNWTYK5B.js.map +1 -0
  8. package/dist/chunk-SXK2Z45Z.js +50 -0
  9. package/dist/chunk-SXK2Z45Z.js.map +1 -0
  10. package/dist/debug/index.d.ts +50 -3
  11. package/dist/debug/index.js +64 -6
  12. package/dist/debug/index.js.map +1 -1
  13. package/dist/doclet/index.d.ts +152 -31
  14. package/dist/doclet/index.js +458 -57
  15. package/dist/doclet/index.js.map +1 -1
  16. package/dist/doclet/resources/petrinet-diagrams.css +640 -7
  17. package/dist/doclet/resources/petrinet-diagrams.js +7238 -114
  18. package/dist/dot-exporter-WJMCJEFK.js +8 -0
  19. package/dist/{event-store-BnyHh3TF.d.ts → event-store-2zkXeQkd.d.ts} +1 -1
  20. package/dist/export/index.d.ts +18 -4
  21. package/dist/export/index.js +1 -1
  22. package/dist/index.d.ts +41 -5
  23. package/dist/index.js +1221 -35
  24. package/dist/index.js.map +1 -1
  25. package/dist/petri-net-BDrj4XZE.d.ts +1461 -0
  26. package/dist/render-QK57X4TP.js +73 -0
  27. package/dist/render-QK57X4TP.js.map +1 -0
  28. package/dist/verification/index.d.ts +3 -144
  29. package/dist/verification/index.js +30 -1214
  30. package/dist/verification/index.js.map +1 -1
  31. package/dist/viewer/index.d.ts +227 -0
  32. package/dist/viewer/index.js +877 -0
  33. package/dist/viewer/index.js.map +1 -0
  34. package/dist/viewer/layout/index.d.ts +200 -0
  35. package/dist/viewer/layout/index.js +15 -0
  36. package/dist/viewer/layout/index.js.map +1 -0
  37. package/dist/viewer/viewer-static.iife.js +3 -0
  38. package/dist/viewer/viewer.css +759 -0
  39. package/dist/viewer/viewer.iife.js +7243 -0
  40. package/package.json +28 -8
  41. package/dist/chunk-B2D5DMTO.js.map +0 -1
  42. package/dist/chunk-VQ4XMJTD.js +0 -107
  43. package/dist/chunk-VQ4XMJTD.js.map +0 -1
  44. package/dist/dot-exporter-3CVCH6J4.js +0 -8
  45. package/dist/petri-net-D-GN9g_D.d.ts +0 -570
  46. /package/dist/{dot-exporter-3CVCH6J4.js.map → dot-exporter-WJMCJEFK.js.map} +0 -0
package/README.md CHANGED
@@ -99,6 +99,53 @@ const marking = await executor.run();
99
99
  console.log(marking.peekTokens(output)); // [Token { value: 'HELLO' }]
100
100
  ```
101
101
 
102
+ ## Modular composition
103
+
104
+ Build large nets by reusing open-net fragments. A `SubnetDef` is a structurally
105
+ complete `PetriNet` plus a typed `Interface` of **ports** (typed places) and
106
+ **channels** (transitions). Instantiating renames every internal element with a
107
+ `prefix/name`; composing into a host substitutes port places and merges
108
+ channel transitions.
109
+
110
+ ```typescript
111
+ import { PetriNet, SubnetDef, FusionSet, place } from 'libpetri';
112
+
113
+ const items = place<string>('items');
114
+ const slots = place<string>('slots');
115
+ const put = place<string>('put');
116
+ const get = place<string>('get');
117
+
118
+ const buffer = SubnetDef.builder<void>('Buffer')
119
+ .place(items).place(slots)
120
+ .transition(enqueue).transition(dequeue)
121
+ .inputPort('put', put)
122
+ .outputPort('get', get)
123
+ .build();
124
+
125
+ const b1 = buffer.instantiate('b1').bindActions({ enqueue: enqueueImpl, dequeue: fork() });
126
+ const b2 = buffer.instantiate('b2').bindActions({ enqueue: enqueueImpl, dequeue: fork() });
127
+
128
+ const producerToB1 = place<string>('p1_to_b1');
129
+ const b1ToB2 = place<string>('b1_to_b2');
130
+ const b2ToConsumer = place<string>('b2_to_c');
131
+
132
+ const net = PetriNet.builder('Pipeline')
133
+ .compose(b1, (bind) =>
134
+ bind.bindPort('put', producerToB1).bindPort('get', b1ToB2))
135
+ .compose(b2, (bind) =>
136
+ bind.bindPort('put', b1ToB2).bindPort('get', b2ToConsumer))
137
+ .fuse(FusionSet.of('sharedSlots', b1.port<string>('slots'), b2.port<string>('slots')))
138
+ .build();
139
+ ```
140
+
141
+ Composition produces a flat `PetriNet`. Ports merge places by structural
142
+ rewrite; channels (`bindChannel`) merge transitions with arc union, timing
143
+ intersection, and caller-wins identity. `FusionSet` declares N-ary place
144
+ equivalence applied **after** all `compose(...)` calls, regardless of
145
+ registration order. Per-instance action overrides are supplied via
146
+ `Instance.bindActions({ originalName: action })`. See
147
+ [`spec/11-modular-composition.md`](../spec/11-modular-composition.md).
148
+
102
149
  ## Verification Example
103
150
 
104
151
  ```typescript
@@ -12,7 +12,9 @@ var NODE_STYLES = {
12
12
  environment: { shape: "circle", fill: "#f8d7da", stroke: "#721c24", penwidth: 2, style: "dashed", width: 0.35 },
13
13
  transition: { shape: "box", fill: "#fff3cd", stroke: "#856404", penwidth: 1, height: 0.4, width: 0.8 },
14
14
  "xor-junction": { shape: "diamond", fill: "#FFFFFF", stroke: "#333333", penwidth: 1, height: 0.3, width: 0.3 },
15
- "and-junction": { shape: "diamond", fill: "#FFFFFF", stroke: "#333333", penwidth: 1, height: 0.3, width: 0.3 }
15
+ "and-junction": { shape: "diamond", fill: "#FFFFFF", stroke: "#333333", penwidth: 1, height: 0.3, width: 0.3 },
16
+ "interface-port": { shape: "circle", fill: "#e7f1ff", stroke: "#1d4ed8", penwidth: 2, style: "dashed", width: 0.35 },
17
+ "sync-channel": { shape: "box", fill: "#f3e8ff", stroke: "#6d28d9", penwidth: 1.5, height: 0.4, width: 0.8 }
16
18
  };
17
19
  var EDGE_STYLES = {
18
20
  input: { color: "#333333", style: "solid", arrowhead: "normal" },
@@ -31,6 +33,192 @@ function edgeStyle(arcType) {
31
33
  return EDGE_STYLES[arcType];
32
34
  }
33
35
 
36
+ // src/export/subnet-prefixes.ts
37
+ function instancePrefixOf(nodeName) {
38
+ if (nodeName == null) return void 0;
39
+ const idx = nodeName.lastIndexOf("/");
40
+ if (idx <= 0) return void 0;
41
+ return nodeName.substring(0, idx);
42
+ }
43
+ function parentOf(prefix) {
44
+ if (prefix == null || prefix.length === 0) return void 0;
45
+ const idx = prefix.lastIndexOf("/");
46
+ if (idx <= 0) return void 0;
47
+ return prefix.substring(0, idx);
48
+ }
49
+
50
+ // src/export/cluster-builder.ts
51
+ var DEFAULT_CLUSTER_ATTRS = {
52
+ style: "rounded,dashed",
53
+ bgcolor: "#FAFAFA",
54
+ penwidth: "1.5"
55
+ };
56
+ function partition(nodes, edges, nodeIdToPrefix) {
57
+ if (nodeIdToPrefix.size === 0) {
58
+ return {
59
+ topLevelNodes: [...nodes],
60
+ topLevelEdges: [...edges],
61
+ topLevelSubgraphs: []
62
+ };
63
+ }
64
+ const prefixOrder = /* @__PURE__ */ new Map();
65
+ for (const prefix of nodeIdToPrefix.values()) {
66
+ registerPrefixChain(prefix, prefixOrder);
67
+ }
68
+ const prefixState = /* @__PURE__ */ new Map();
69
+ for (const prefix of prefixOrder.keys()) {
70
+ prefixState.set(prefix, { prefix, nodes: [], edges: [], childPrefixes: [] });
71
+ }
72
+ for (const prefix of prefixState.keys()) {
73
+ const parent = parentOf(prefix);
74
+ if (parent !== void 0) {
75
+ prefixState.get(parent).childPrefixes.push(prefix);
76
+ }
77
+ }
78
+ const topLevelNodes = [];
79
+ for (const node of nodes) {
80
+ const prefix = nodeIdToPrefix.get(node.id);
81
+ if (prefix === void 0) {
82
+ topLevelNodes.push(node);
83
+ } else {
84
+ prefixState.get(prefix).nodes.push(node);
85
+ }
86
+ }
87
+ const topLevelEdges = [];
88
+ for (const edge of edges) {
89
+ const fromPrefix = nodeIdToPrefix.get(edge.from);
90
+ const toPrefix = nodeIdToPrefix.get(edge.to);
91
+ const common = deepestCommonPrefix(fromPrefix, toPrefix);
92
+ if (common === void 0) {
93
+ topLevelEdges.push(edge);
94
+ } else {
95
+ prefixState.get(common).edges.push(edge);
96
+ }
97
+ }
98
+ for (const ghost of synthesizeGhostEdges(nodes, edges, nodeIdToPrefix)) {
99
+ topLevelEdges.push(ghost);
100
+ }
101
+ const built = /* @__PURE__ */ new Map();
102
+ const iterationOrder = [...prefixState.keys()].reverse();
103
+ for (const prefix of iterationOrder) {
104
+ const state = prefixState.get(prefix);
105
+ const children = [];
106
+ for (const childPrefix of state.childPrefixes) {
107
+ const child = built.get(childPrefix);
108
+ if (child !== void 0) {
109
+ children.push(child);
110
+ }
111
+ }
112
+ children.reverse();
113
+ const subgraph = {
114
+ id: sanitize(prefix),
115
+ label: prefix,
116
+ nodes: [...state.nodes],
117
+ edges: [...state.edges],
118
+ subgraphs: children,
119
+ attrs: DEFAULT_CLUSTER_ATTRS
120
+ };
121
+ built.set(prefix, subgraph);
122
+ }
123
+ const topLevelSubgraphs = [];
124
+ for (const prefix of prefixState.keys()) {
125
+ if (parentOf(prefix) === void 0) {
126
+ topLevelSubgraphs.push(built.get(prefix));
127
+ }
128
+ }
129
+ return {
130
+ topLevelNodes,
131
+ topLevelEdges,
132
+ topLevelSubgraphs
133
+ };
134
+ }
135
+ function registerPrefixChain(prefix, accumulator) {
136
+ if (prefix == null || prefix.length === 0) return;
137
+ const segments = prefix.split("/");
138
+ let built = "";
139
+ for (const seg of segments) {
140
+ if (built.length > 0) built += "/";
141
+ built += seg;
142
+ if (!accumulator.has(built)) {
143
+ accumulator.set(built, true);
144
+ }
145
+ }
146
+ }
147
+ function synthesizeGhostEdges(nodes, edges, nodeIdToPrefix) {
148
+ const incomingByOrphan = /* @__PURE__ */ new Map();
149
+ const outgoingByOrphan = /* @__PURE__ */ new Map();
150
+ for (const edge of edges) {
151
+ const fromHasPrefix = nodeIdToPrefix.has(edge.from);
152
+ const toHasPrefix = nodeIdToPrefix.has(edge.to);
153
+ if (fromHasPrefix && !toHasPrefix) {
154
+ let list = incomingByOrphan.get(edge.to);
155
+ if (list === void 0) {
156
+ list = [];
157
+ incomingByOrphan.set(edge.to, list);
158
+ }
159
+ list.push(edge);
160
+ }
161
+ if (!fromHasPrefix && toHasPrefix) {
162
+ let list = outgoingByOrphan.get(edge.from);
163
+ if (list === void 0) {
164
+ list = [];
165
+ outgoingByOrphan.set(edge.from, list);
166
+ }
167
+ list.push(edge);
168
+ }
169
+ }
170
+ const ghosts = /* @__PURE__ */ new Map();
171
+ for (const node of nodes) {
172
+ if (nodeIdToPrefix.has(node.id)) continue;
173
+ const incoming = incomingByOrphan.get(node.id);
174
+ const outgoing = outgoingByOrphan.get(node.id);
175
+ if (incoming === void 0 || outgoing === void 0) continue;
176
+ for (const eIn of incoming) {
177
+ const x = nodeIdToPrefix.get(eIn.from);
178
+ for (const eOut of outgoing) {
179
+ const y = nodeIdToPrefix.get(eOut.to);
180
+ if (x === y) continue;
181
+ const key = `${x}\0${y}`;
182
+ if (!ghosts.has(key)) {
183
+ ghosts.set(key, { from: eIn.from, to: eOut.to, x, y });
184
+ }
185
+ }
186
+ }
187
+ }
188
+ const result = [];
189
+ for (const { from, to, x, y } of ghosts.values()) {
190
+ result.push({
191
+ from,
192
+ to,
193
+ color: "#000000",
194
+ style: "invis",
195
+ arrowhead: "none",
196
+ arcType: "ghost",
197
+ attrs: {
198
+ ltail: "cluster_" + sanitize(x),
199
+ lhead: "cluster_" + sanitize(y)
200
+ }
201
+ });
202
+ }
203
+ return result;
204
+ }
205
+ function deepestCommonPrefix(a, b) {
206
+ if (a === void 0 || b === void 0) return void 0;
207
+ if (a === b) return a;
208
+ const aSegs = a.split("/");
209
+ const bSegs = b.split("/");
210
+ let built = "";
211
+ let matched = 0;
212
+ const min = Math.min(aSegs.length, bSegs.length);
213
+ for (let i = 0; i < min; i++) {
214
+ if (aSegs[i] !== bSegs[i]) break;
215
+ if (matched > 0) built += "/";
216
+ built += aSegs[i];
217
+ matched++;
218
+ }
219
+ return matched === 0 ? void 0 : built;
220
+ }
221
+
34
222
  // src/export/petri-net-mapper.ts
35
223
  var DEFAULT_DOT_CONFIG = {
36
224
  direction: "TB",
@@ -46,11 +234,13 @@ function mapToGraph(net, config = DEFAULT_DOT_CONFIG) {
46
234
  const envNames = config.environmentPlaces ?? /* @__PURE__ */ new Set();
47
235
  const nodes = [];
48
236
  const edges = [];
237
+ const nodeIdToPrefix = /* @__PURE__ */ new Map();
49
238
  for (const [name, info] of places) {
50
239
  const category = placeCategory(info, envNames.has(name));
51
240
  const style = nodeStyle(category);
241
+ const nodeId = "p_" + sanitize(name);
52
242
  nodes.push({
53
- id: "p_" + sanitize(name),
243
+ id: nodeId,
54
244
  label: "",
55
245
  shape: style.shape,
56
246
  fill: style.fill,
@@ -61,11 +251,16 @@ function mapToGraph(net, config = DEFAULT_DOT_CONFIG) {
61
251
  width: style.width,
62
252
  attrs: { xlabel: name, fixedsize: "true" }
63
253
  });
254
+ const prefix = instancePrefixOf(name);
255
+ if (prefix !== void 0) {
256
+ nodeIdToPrefix.set(nodeId, prefix);
257
+ }
64
258
  }
65
259
  for (const t of net.transitions) {
66
260
  const style = nodeStyle("transition");
261
+ const tid = "t_" + sanitize(t.name);
67
262
  nodes.push({
68
- id: "t_" + sanitize(t.name),
263
+ id: tid,
69
264
  label: transitionLabel(t, config),
70
265
  shape: style.shape,
71
266
  fill: style.fill,
@@ -75,10 +270,15 @@ function mapToGraph(net, config = DEFAULT_DOT_CONFIG) {
75
270
  height: style.height,
76
271
  width: style.width
77
272
  });
273
+ const prefix = instancePrefixOf(t.name);
274
+ if (prefix !== void 0) {
275
+ nodeIdToPrefix.set(tid, prefix);
276
+ }
78
277
  }
79
278
  for (const t of net.transitions) {
80
279
  const tid = "t_" + sanitize(t.name);
81
280
  const tSanitized = sanitize(t.name);
281
+ const tPrefix = instancePrefixOf(t.name);
82
282
  const resetPlaces = new Set(t.resets.map((r) => r.place.name));
83
283
  const combined = /* @__PURE__ */ new Set();
84
284
  for (const spec of t.inputSpecs) {
@@ -113,7 +313,9 @@ function mapToGraph(net, config = DEFAULT_DOT_CONFIG) {
113
313
  combined,
114
314
  nodes,
115
315
  edges,
116
- counter: 0
316
+ counter: 0,
317
+ transitionPrefix: tPrefix,
318
+ nodeIdToPrefix
117
319
  };
118
320
  emitOutput(t.outputSpec, tid, null, ctx);
119
321
  }
@@ -159,19 +361,21 @@ function mapToGraph(net, config = DEFAULT_DOT_CONFIG) {
159
361
  }
160
362
  }
161
363
  }
364
+ const partitioned = partition(nodes, edges, nodeIdToPrefix);
162
365
  return {
163
366
  id: sanitize(net.name),
164
367
  rankdir: config.direction,
165
- nodes,
166
- edges,
167
- subgraphs: [],
368
+ nodes: partitioned.topLevelNodes,
369
+ edges: partitioned.topLevelEdges,
370
+ subgraphs: partitioned.topLevelSubgraphs,
168
371
  graphAttrs: {
169
372
  nodesep: String(GRAPH.nodesep),
170
373
  ranksep: String(GRAPH.ranksep),
171
374
  forcelabels: String(GRAPH.forcelabels),
172
375
  overlap: String(GRAPH.overlap),
173
376
  fontname: FONT.family,
174
- outputorder: GRAPH.outputorder
377
+ outputorder: GRAPH.outputorder,
378
+ compound: "true"
175
379
  },
176
380
  nodeDefaults: {
177
381
  fontname: FONT.family,
@@ -271,6 +475,9 @@ function emitOutput(out, parentId, branchLabel, ctx) {
271
475
  width: jStyle.width,
272
476
  attrs: { fixedsize: "true", fontsize: "14" }
273
477
  });
478
+ if (ctx.transitionPrefix !== void 0) {
479
+ ctx.nodeIdToPrefix.set(junctionId, ctx.transitionPrefix);
480
+ }
274
481
  const outStyle = edgeStyle("output");
275
482
  ctx.edges.push({
276
483
  from: parentId,
@@ -421,6 +628,16 @@ function renderSubgraph(sg, indent) {
421
628
  for (const node of sg.nodes) {
422
629
  lines.push(`${indent} ${renderNode(node)}`);
423
630
  }
631
+ if (sg.subgraphs) {
632
+ for (const nested of sg.subgraphs) {
633
+ lines.push(...renderSubgraph(nested, indent + " "));
634
+ }
635
+ }
636
+ if (sg.edges) {
637
+ for (const e of sg.edges) {
638
+ lines.push(`${indent} ${renderEdge(e)}`);
639
+ }
640
+ }
424
641
  lines.push(`${indent}}`);
425
642
  return lines;
426
643
  }
@@ -465,10 +682,12 @@ export {
465
682
  GRAPH,
466
683
  nodeStyle,
467
684
  edgeStyle,
685
+ instancePrefixOf,
686
+ parentOf,
468
687
  DEFAULT_DOT_CONFIG,
469
688
  sanitize,
470
689
  mapToGraph,
471
690
  renderDot,
472
691
  dotExport
473
692
  };
474
- //# sourceMappingURL=chunk-B2D5DMTO.js.map
693
+ //# sourceMappingURL=chunk-B2CV5M3L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/export/styles.ts","../src/export/subnet-prefixes.ts","../src/export/cluster-builder.ts","../src/export/petri-net-mapper.ts","../src/export/dot-renderer.ts","../src/export/dot-exporter.ts"],"sourcesContent":["// GENERATED from spec/petri-net-styles.json — do not edit manually.\n// Regenerate with: scripts/generate-styles.sh\n\n/**\n * Style loader for Petri net visualization.\n *\n * Reads the shared style definition from `spec/petri-net-styles.json` and\n * exposes typed accessors for node and edge visual properties.\n *\n * @module export/styles\n */\n\nimport type { NodeShape, EdgeLineStyle, ArrowHead } from './graph.js';\n\n// ======================== Style Types ========================\n\nexport interface NodeVisual {\n readonly shape: NodeShape;\n readonly fill: string;\n readonly stroke: string;\n readonly penwidth: number;\n readonly style?: string;\n readonly height?: number;\n readonly width?: number;\n}\n\nexport interface EdgeVisual {\n readonly color: string;\n readonly style: EdgeLineStyle;\n readonly arrowhead: ArrowHead;\n readonly penwidth?: number;\n}\n\nexport interface FontStyle {\n readonly family: string;\n readonly nodeSize: number;\n readonly edgeSize: number;\n}\n\nexport interface GraphStyle {\n readonly nodesep: number;\n readonly ranksep: number;\n readonly forcelabels: boolean;\n readonly overlap: boolean;\n readonly outputorder: string;\n}\n\n// ======================== Inline Style Data ========================\n\n// Inlined from spec/petri-net-styles.json to avoid runtime JSON import issues.\n// Keep in sync with the spec file.\n\nconst NODE_STYLES: Record<NodeCategory, NodeVisual> = {\n place: { shape: 'circle', fill: '#FFFFFF', stroke: '#333333', penwidth: 1.5, width: 0.35 },\n start: { shape: 'circle', fill: '#d4edda', stroke: '#28a745', penwidth: 2.0, width: 0.35 },\n end: { shape: 'doublecircle', fill: '#cce5ff', stroke: '#004085', penwidth: 2.0, width: 0.35 },\n environment: { shape: 'circle', fill: '#f8d7da', stroke: '#721c24', penwidth: 2.0, style: 'dashed', width: 0.35 },\n transition: { shape: 'box', fill: '#fff3cd', stroke: '#856404', penwidth: 1.0, height: 0.4, width: 0.8 },\n 'xor-junction': { shape: 'diamond', fill: '#FFFFFF', stroke: '#333333', penwidth: 1.0, height: 0.3, width: 0.3 },\n 'and-junction': { shape: 'diamond', fill: '#FFFFFF', stroke: '#333333', penwidth: 1.0, height: 0.3, width: 0.3 },\n 'interface-port':{ shape: 'circle', fill: '#e7f1ff', stroke: '#1d4ed8', penwidth: 2.0, style: 'dashed', width: 0.35 },\n 'sync-channel': { shape: 'box', fill: '#f3e8ff', stroke: '#6d28d9', penwidth: 1.5, height: 0.4, width: 0.8 },\n};\n\nconst EDGE_STYLES: Record<EdgeCategory, EdgeVisual> = {\n input: { color: '#333333', style: 'solid', arrowhead: 'normal' },\n output: { color: '#333333', style: 'solid', arrowhead: 'normal' },\n inhibitor: { color: '#dc3545', style: 'solid', arrowhead: 'odot' },\n read: { color: '#6c757d', style: 'dashed', arrowhead: 'normal' },\n reset: { color: '#fd7e14', style: 'bold', arrowhead: 'normal', penwidth: 2.0 },\n 'reset-output': { color: '#fd7e14', style: 'bold', arrowhead: 'normal', penwidth: 2.0 },\n};\n\nexport const FONT: FontStyle = { family: 'Helvetica,Arial,sans-serif', nodeSize: 12, edgeSize: 10 };\n\nexport const GRAPH: GraphStyle = { nodesep: 0.5, ranksep: 0.75, forcelabels: true, overlap: false, outputorder: 'edgesfirst' };\n\n// ======================== Public API ========================\n\nexport type NodeCategory = 'place' | 'start' | 'end' | 'environment' | 'transition' | 'xor-junction' | 'and-junction' | 'interface-port' | 'sync-channel';\nexport type EdgeCategory = 'input' | 'output' | 'inhibitor' | 'read' | 'reset' | 'reset-output';\n\n/** Returns the visual style for the given node category. */\nexport function nodeStyle(category: NodeCategory): NodeVisual {\n return NODE_STYLES[category];\n}\n\n/** Returns the visual style for the given edge/arc type. */\nexport function edgeStyle(arcType: EdgeCategory): EdgeVisual {\n return EDGE_STYLES[arcType];\n}\n","/**\n * Prefix-derivation helpers for subnet-instance-aware export and debug\n * tooling, per `spec/11-modular-composition.md` **MOD-040** (export\n * grouping) and **MOD-041** (debug protocol subnet instances).\n *\n * The `\"/\"` character is the prefix separator established by **MOD-010**:\n * a node named `\"outer/inner/leaf\"` belongs to the cluster tree\n * `outer -> outer/inner`, with `\"leaf\"` as the un-prefixed final segment.\n *\n * This module is observability-only — it never inspects {@link\n * import('../core/subnet-def').SubnetDef} or {@link\n * import('../core/instance').Instance} objects, only the resulting\n * prefixed names that survived composition. That keeps consumers (DOT\n * exporter, debug protocol handler) decoupled from the modular-composition\n * layer per **MOD-023**.\n *\n * @module export/subnet-prefixes\n */\n\n/**\n * Returns the instance prefix carried by the given node name, or `undefined`\n * when the name has no `/` (i.e. is not part of any composed subnet\n * instance).\n *\n * The prefix is the substring up to (but not including) the **last** `/`\n * — so `\"producer1/internal\"` returns `\"producer1\"` and\n * `\"outer/inner/leaf\"` returns `\"outer/inner\"`. The bare segment after the\n * last `/` is the original (un-prefixed) place or transition name.\n *\n * @param nodeName the prefixed-or-flat node name\n * @returns the prefix, or `undefined` for flat names\n */\nexport function instancePrefixOf(nodeName: string | null | undefined): string | undefined {\n if (nodeName == null) return undefined;\n const idx = nodeName.lastIndexOf('/');\n if (idx <= 0) return undefined;\n return nodeName.substring(0, idx);\n}\n\n/**\n * Returns the parent prefix of a given prefix, or `undefined` if the prefix\n * is top-level (single segment, no `/`).\n *\n * Used by the debug protocol's {@code SubnetInstance.parentPrefix} field\n * per **MOD-041** for nested instances.\n *\n * @param prefix an instance prefix string (e.g. `\"outer/inner\"`)\n * @returns the parent prefix (e.g. `\"outer\"`), or `undefined` for top-level\n */\nexport function parentOf(prefix: string | null | undefined): string | undefined {\n if (prefix == null || prefix.length === 0) return undefined;\n const idx = prefix.lastIndexOf('/');\n if (idx <= 0) return undefined;\n return prefix.substring(0, idx);\n}\n\n/**\n * Returns the last (leaf) segment of a prefix, used as the cluster label per\n * **MOD-040**. For top-level prefixes the input itself is returned unchanged.\n *\n * @param prefix an instance prefix string\n * @returns the trailing segment after the last `/` (or the input when there\n * is no `/`)\n */\nexport function leafSegment(prefix: string | null | undefined): string | null | undefined {\n if (prefix == null || prefix.length === 0) return prefix;\n const idx = prefix.lastIndexOf('/');\n return idx < 0 ? prefix : prefix.substring(idx + 1);\n}\n","/**\n * Builds nested `subgraph cluster_*` blocks for DOT export per\n * `spec/11-modular-composition.md` **MOD-040** and `spec/09-export.md`\n * **EXP-016**.\n *\n * Given a flat list of nodes and edges plus a `nodeId -> prefix` map\n * produced during mapping (see {@link import('./petri-net-mapper.js').mapToGraph}),\n * this partitioner:\n *\n * 1. Walks every distinct prefix to produce the cluster tree (nested\n * {@link Subgraph} entries).\n * 2. Routes each node into the deepest cluster whose prefix equals the\n * node's prefix; nodes without a prefix stay at the top level.\n * 3. Routes each edge into the deepest cluster that contains **both**\n * endpoints; edges crossing cluster boundaries (or with at least one\n * top-level endpoint) stay at the top level so Graphviz routes them\n * correctly without truncating cluster boxes.\n * 4. Applies a default cluster style (rounded, dashed, light fill) when\n * none is provided — readable defaults sufficient until task #9 layers\n * the doclet styling on top.\n *\n * This partitioner is structural-only: it does not consult any\n * {@link import('../core/subnet-def').SubnetDef} or {@link\n * import('../core/instance').Instance} — it operates exclusively on the\n * flattened post-composition node names per **MOD-023**.\n *\n * @module export/cluster-builder\n */\n\nimport type { GraphEdge, GraphNode, Subgraph } from './graph.js';\nimport { sanitize } from './petri-net-mapper.js';\nimport { parentOf } from './subnet-prefixes.js';\n\n/** Result of partitioning nodes/edges into a clustered hierarchy. */\nexport interface Partition {\n readonly topLevelNodes: readonly GraphNode[];\n readonly topLevelEdges: readonly GraphEdge[];\n readonly topLevelSubgraphs: readonly Subgraph[];\n}\n\n/**\n * Default cluster styling (per [EXP-016] visual contract). These values\n * mirror the `cluster.subnet-cluster` entry in\n * `spec/petri-net-styles.json` so cross-language output stays\n * byte-equivalent.\n */\nexport const DEFAULT_CLUSTER_ATTRS: Readonly<Record<string, string>> = {\n style: 'rounded,dashed',\n bgcolor: '#FAFAFA',\n penwidth: '1.5',\n};\n\ninterface MutableCluster {\n readonly prefix: string;\n readonly nodes: GraphNode[];\n readonly edges: GraphEdge[];\n readonly childPrefixes: string[];\n}\n\n/**\n * Partitions nodes and edges into a cluster hierarchy. Mutates neither input\n * collection.\n *\n * @param nodes all nodes (places, transitions, junctions)\n * @param edges all edges\n * @param nodeIdToPrefix per-node instance prefix; absent entries stay\n * top-level\n * @returns the partitioned cluster hierarchy\n */\nexport function partition(\n nodes: readonly GraphNode[],\n edges: readonly GraphEdge[],\n nodeIdToPrefix: ReadonlyMap<string, string>,\n): Partition {\n // Fast path: no prefixes => no clusters. Preserves byte-equal output for\n // flat (non-composed) nets.\n if (nodeIdToPrefix.size === 0) {\n return {\n topLevelNodes: [...nodes],\n topLevelEdges: [...edges],\n topLevelSubgraphs: [],\n };\n }\n\n // Step 1: walk every prefix to produce the cluster tree shape. We need\n // every internal prefix node, not just leaf prefixes — e.g. a node\n // \"outer/inner/leaf\" requires both \"outer\" and \"outer/inner\" to exist as\n // cluster blocks per [EXP-016] / [MOD-013].\n //\n // We use a Map for insertion-order iteration (deterministic per [EXP-014]).\n const prefixOrder = new Map<string, true>();\n for (const prefix of nodeIdToPrefix.values()) {\n registerPrefixChain(prefix, prefixOrder);\n }\n\n // prefix -> (mutable nodes, mutable edges, mutable child prefixes)\n const prefixState = new Map<string, MutableCluster>();\n for (const prefix of prefixOrder.keys()) {\n prefixState.set(prefix, { prefix, nodes: [], edges: [], childPrefixes: [] });\n }\n // Wire parent -> child relationships.\n for (const prefix of prefixState.keys()) {\n const parent = parentOf(prefix);\n if (parent !== undefined) {\n prefixState.get(parent)!.childPrefixes.push(prefix);\n }\n }\n\n // Step 2: route nodes into their deepest cluster.\n const topLevelNodes: GraphNode[] = [];\n for (const node of nodes) {\n const prefix = nodeIdToPrefix.get(node.id);\n if (prefix === undefined) {\n topLevelNodes.push(node);\n } else {\n prefixState.get(prefix)!.nodes.push(node);\n }\n }\n\n // Step 3: route edges into the deepest cluster containing both endpoints.\n // Cross-cluster edges stay at top-level so Graphviz draws them between\n // cluster boxes rather than inside one.\n const topLevelEdges: GraphEdge[] = [];\n for (const edge of edges) {\n const fromPrefix = nodeIdToPrefix.get(edge.from);\n const toPrefix = nodeIdToPrefix.get(edge.to);\n const common = deepestCommonPrefix(fromPrefix, toPrefix);\n if (common === undefined) {\n topLevelEdges.push(edge);\n } else {\n prefixState.get(common)!.edges.push(edge);\n }\n }\n\n // Step 3.5: synthesize ghost edges for 1-hop cluster_X → orphan → cluster_Y\n // paths so Graphviz (with compound=true) can constrain the two clusters'\n // relative layout. Ghost edges are style=invis — they carry layout weight\n // only; the visible flow still goes through the orphan via the real edges.\n // Per spec EXP-017.\n for (const ghost of synthesizeGhostEdges(nodes, edges, nodeIdToPrefix)) {\n topLevelEdges.push(ghost);\n }\n\n // Step 4: assemble Subgraph records bottom-up so children are built before\n // they're consumed by parents.\n const built = new Map<string, Subgraph>();\n // Reverse the insertion order: parents were inserted before children in\n // registerPrefixChain so iterating reversed produces a deepest-first order.\n const iterationOrder = [...prefixState.keys()].reverse();\n for (const prefix of iterationOrder) {\n const state = prefixState.get(prefix)!;\n const children: Subgraph[] = [];\n for (const childPrefix of state.childPrefixes) {\n const child = built.get(childPrefix);\n if (child !== undefined) {\n children.push(child);\n }\n }\n // Children were built deepest-first, so they're reversed relative to\n // their original insertion order. Restore the original order.\n children.reverse();\n\n const subgraph: Subgraph = {\n id: sanitize(prefix),\n label: prefix,\n nodes: [...state.nodes],\n edges: [...state.edges],\n subgraphs: children,\n attrs: DEFAULT_CLUSTER_ATTRS,\n };\n built.set(prefix, subgraph);\n }\n\n // Top-level subgraphs are those whose prefix has no parent.\n const topLevelSubgraphs: Subgraph[] = [];\n for (const prefix of prefixState.keys()) {\n if (parentOf(prefix) === undefined) {\n topLevelSubgraphs.push(built.get(prefix)!);\n }\n }\n\n return {\n topLevelNodes,\n topLevelEdges,\n topLevelSubgraphs,\n };\n}\n\n/**\n * Walks a prefix root-to-leaf, registering every intermediate prefix in\n * `accumulator` (no-op when already present). Ensures parents are inserted\n * before children.\n */\nfunction registerPrefixChain(prefix: string | undefined, accumulator: Map<string, true>): void {\n if (prefix == null || prefix.length === 0) return;\n const segments = prefix.split('/');\n let built = '';\n for (const seg of segments) {\n if (built.length > 0) built += '/';\n built += seg;\n if (!accumulator.has(built)) {\n accumulator.set(built, true);\n }\n }\n}\n\n/**\n * Synthesizes one invisible ghost edge per ordered (cluster_X, cluster_Y)\n * pair that is bridged by at least one top-level orphan node via a 1-hop\n * path (i.e. some edge X-node → orphan and some edge orphan → Y-node). The\n * ghost edge carries `style=invis, ltail=cluster_<sanitizedX>,\n * lhead=cluster_<sanitizedY>` so Graphviz (with `compound=true`) treats it\n * as a real cluster-to-cluster layout constraint without producing any\n * visible artifact. Per spec EXP-017.\n *\n * Determinism: walks orphans in `nodes` order, walks each orphan's\n * incoming/outgoing edges in `edges` order. First-witness wins for anchor\n * node selection. This matches the iteration discipline in the Java/Rust\n * mirrors so cross-language byte-parity holds.\n */\nfunction synthesizeGhostEdges(\n nodes: readonly GraphNode[],\n edges: readonly GraphEdge[],\n nodeIdToPrefix: ReadonlyMap<string, string>,\n): GraphEdge[] {\n // Index edges by their orphan endpoint. An orphan is any node whose id is\n // not in nodeIdToPrefix.\n const incomingByOrphan = new Map<string, GraphEdge[]>();\n const outgoingByOrphan = new Map<string, GraphEdge[]>();\n for (const edge of edges) {\n const fromHasPrefix = nodeIdToPrefix.has(edge.from);\n const toHasPrefix = nodeIdToPrefix.has(edge.to);\n if (fromHasPrefix && !toHasPrefix) {\n let list = incomingByOrphan.get(edge.to);\n if (list === undefined) {\n list = [];\n incomingByOrphan.set(edge.to, list);\n }\n list.push(edge);\n }\n if (!fromHasPrefix && toHasPrefix) {\n let list = outgoingByOrphan.get(edge.from);\n if (list === undefined) {\n list = [];\n outgoingByOrphan.set(edge.from, list);\n }\n list.push(edge);\n }\n }\n\n // Walk orphans in nodes order. For each (clusterX_prefix, clusterY_prefix)\n // ordered pair with X !== Y, record the first witness anchor pair.\n // Map<\"X\\0Y\", { from, to, x, y }> — using an insertion-ordered Map for\n // deterministic emission order.\n const ghosts = new Map<string, { from: string; to: string; x: string; y: string }>();\n for (const node of nodes) {\n if (nodeIdToPrefix.has(node.id)) continue;\n const incoming = incomingByOrphan.get(node.id);\n const outgoing = outgoingByOrphan.get(node.id);\n if (incoming === undefined || outgoing === undefined) continue;\n for (const eIn of incoming) {\n const x = nodeIdToPrefix.get(eIn.from)!;\n for (const eOut of outgoing) {\n const y = nodeIdToPrefix.get(eOut.to)!;\n if (x === y) continue;\n const key = `${x}\\0${y}`;\n if (!ghosts.has(key)) {\n ghosts.set(key, { from: eIn.from, to: eOut.to, x, y });\n }\n }\n }\n }\n\n const result: GraphEdge[] = [];\n for (const { from, to, x, y } of ghosts.values()) {\n result.push({\n from,\n to,\n color: '#000000',\n style: 'invis',\n arrowhead: 'none',\n arcType: 'ghost',\n attrs: {\n ltail: 'cluster_' + sanitize(x),\n lhead: 'cluster_' + sanitize(y),\n },\n });\n }\n return result;\n}\n\n/**\n * Returns the deepest prefix that is a (non-strict) ancestor of both sides,\n * or `undefined` when there is no shared cluster (top-level routing).\n */\nfunction deepestCommonPrefix(a: string | undefined, b: string | undefined): string | undefined {\n if (a === undefined || b === undefined) return undefined;\n if (a === b) return a;\n\n const aSegs = a.split('/');\n const bSegs = b.split('/');\n let built = '';\n let matched = 0;\n const min = Math.min(aSegs.length, bSegs.length);\n for (let i = 0; i < min; i++) {\n if (aSegs[i] !== bSegs[i]) break;\n if (matched > 0) built += '/';\n built += aSegs[i];\n matched++;\n }\n return matched === 0 ? undefined : built;\n}\n","/**\n * Maps a PetriNet definition to a format-agnostic Graph.\n *\n * Petri net semantics live here. The mapper applies the visualization rules\n * specified in spec/09-export.md (EXP-012, EXP-013, EXP-014):\n *\n * - XOR / AND output groups with ≥2 children become synthetic junction nodes\n * (diamond for XOR, square for AND).\n * - Output + reset arcs to the same place collapse into a single edge styled\n * as the reset-output category and labelled \"reset+out\".\n * - Junction IDs use the form j_<transition>__<kind>_<idx>, where idx is a\n * depth-first pre-order counter starting at 0.\n *\n * @module export/petri-net-mapper\n */\n\nimport type { PetriNet } from '../core/petri-net.js';\nimport type { Transition } from '../core/transition.js';\nimport type { Out } from '../core/out.js';\nimport { earliest, latest, hasDeadline } from '../core/timing.js';\nimport type { Graph, GraphNode, GraphEdge, RankDir } from './graph.js';\nimport { nodeStyle, edgeStyle, FONT, GRAPH } from './styles.js';\nimport type { NodeCategory } from './styles.js';\nimport { partition } from './cluster-builder.js';\nimport { instancePrefixOf } from './subnet-prefixes.js';\n\n// ======================== Configuration ========================\n\nexport interface DotConfig {\n readonly direction: RankDir;\n readonly showTypes: boolean;\n readonly showIntervals: boolean;\n readonly showPriority: boolean;\n readonly environmentPlaces?: ReadonlySet<string>;\n}\n\nexport const DEFAULT_DOT_CONFIG: DotConfig = {\n direction: 'TB',\n showTypes: true,\n showIntervals: true,\n showPriority: true,\n};\n\n// ======================== Public API ========================\n\n/** Sanitizes a name for use as a graph node ID. */\nexport function sanitize(name: string): string {\n return name.replace(/[^a-zA-Z0-9_]/g, '_');\n}\n\n/** Maps a PetriNet to a format-agnostic Graph. */\nexport function mapToGraph(net: PetriNet, config: DotConfig = DEFAULT_DOT_CONFIG): Graph {\n const places = analyzePlaces(net);\n const envNames = config.environmentPlaces ?? new Set<string>();\n\n const nodes: GraphNode[] = [];\n const edges: GraphEdge[] = [];\n\n // Track each emitted node's instance prefix (per [MOD-040]) so we can\n // partition into subgraph clusters at the end. Nodes without a prefix (no\n // '/' in their semantic name) are absent from this map and stay at the top\n // level.\n const nodeIdToPrefix = new Map<string, string>();\n\n // Place nodes\n for (const [name, info] of places) {\n const category = placeCategory(info, envNames.has(name));\n const style = nodeStyle(category);\n const nodeId = 'p_' + sanitize(name);\n nodes.push({\n id: nodeId,\n label: '',\n shape: style.shape,\n fill: style.fill,\n stroke: style.stroke,\n penwidth: style.penwidth,\n semanticId: name,\n style: style.style,\n width: style.width,\n attrs: { xlabel: name, fixedsize: 'true' },\n });\n const prefix = instancePrefixOf(name);\n if (prefix !== undefined) {\n nodeIdToPrefix.set(nodeId, prefix);\n }\n }\n\n // Transition nodes\n for (const t of net.transitions) {\n const style = nodeStyle('transition');\n const tid = 't_' + sanitize(t.name);\n nodes.push({\n id: tid,\n label: transitionLabel(t, config),\n shape: style.shape,\n fill: style.fill,\n stroke: style.stroke,\n penwidth: style.penwidth,\n semanticId: t.name,\n height: style.height,\n width: style.width,\n });\n const prefix = instancePrefixOf(t.name);\n if (prefix !== undefined) {\n nodeIdToPrefix.set(tid, prefix);\n }\n }\n\n // Edges (and junction nodes)\n for (const t of net.transitions) {\n const tid = 't_' + sanitize(t.name);\n const tSanitized = sanitize(t.name);\n // Junctions inherit their parent transition's instance prefix — tracked\n // here so the partition step routes them correctly.\n const tPrefix = instancePrefixOf(t.name);\n const resetPlaces = new Set(t.resets.map(r => r.place.name));\n const combined = new Set<string>();\n\n // Input arcs from inputSpecs\n for (const spec of t.inputSpecs) {\n const pid = 'p_' + sanitize(spec.place.name);\n const inputStyle = edgeStyle('input');\n let label: string | undefined;\n switch (spec.type) {\n case 'exactly':\n label = `×${spec.count}`;\n break;\n case 'all':\n label = '*';\n break;\n case 'at-least':\n label = `≥${spec.minimum}`;\n break;\n }\n edges.push({\n from: pid,\n to: tid,\n label,\n color: inputStyle.color,\n style: inputStyle.style,\n arrowhead: inputStyle.arrowhead,\n arcType: 'input',\n });\n }\n\n // Output arcs from outputSpec — emits junction nodes + edges, marks combined places.\n if (t.outputSpec !== null) {\n const ctx: EmitCtx = {\n tSanitized,\n resetPlaces,\n combined,\n nodes,\n edges,\n counter: 0,\n transitionPrefix: tPrefix,\n nodeIdToPrefix,\n };\n emitOutput(t.outputSpec, tid, null, ctx);\n }\n\n // Inhibitor arcs\n for (const inh of t.inhibitors) {\n const pid = 'p_' + sanitize(inh.place.name);\n const inhStyle = edgeStyle('inhibitor');\n edges.push({\n from: pid,\n to: tid,\n color: inhStyle.color,\n style: inhStyle.style,\n arrowhead: inhStyle.arrowhead,\n arcType: 'inhibitor',\n });\n }\n\n // Read arcs\n for (const r of t.reads) {\n const pid = 'p_' + sanitize(r.place.name);\n const readStyle = edgeStyle('read');\n edges.push({\n from: pid,\n to: tid,\n label: 'read',\n color: readStyle.color,\n style: readStyle.style,\n arrowhead: readStyle.arrowhead,\n arcType: 'read',\n });\n }\n\n // Standalone reset arcs (only those not already combined with an output)\n for (const rst of t.resets) {\n if (!combined.has(rst.place.name)) {\n const pid = 'p_' + sanitize(rst.place.name);\n const resetStyle = edgeStyle('reset');\n edges.push({\n from: tid,\n to: pid,\n label: 'reset',\n color: resetStyle.color,\n style: resetStyle.style,\n arrowhead: resetStyle.arrowhead,\n penwidth: resetStyle.penwidth,\n arcType: 'reset',\n });\n }\n }\n }\n\n // Partition nodes/edges into subgraph clusters per [MOD-040] / [EXP-016].\n // When there are no prefixed names this is a structural no-op and the\n // resulting Graph is byte-identical to the pre-cluster output.\n const partitioned = partition(nodes, edges, nodeIdToPrefix);\n\n return {\n id: sanitize(net.name),\n rankdir: config.direction,\n nodes: partitioned.topLevelNodes,\n edges: partitioned.topLevelEdges,\n subgraphs: partitioned.topLevelSubgraphs,\n graphAttrs: {\n nodesep: String(GRAPH.nodesep),\n ranksep: String(GRAPH.ranksep),\n forcelabels: String(GRAPH.forcelabels),\n overlap: String(GRAPH.overlap),\n fontname: FONT.family,\n outputorder: GRAPH.outputorder,\n compound: 'true',\n },\n nodeDefaults: {\n fontname: FONT.family,\n fontsize: String(FONT.nodeSize),\n },\n edgeDefaults: {\n fontname: FONT.family,\n fontsize: String(FONT.edgeSize),\n },\n };\n}\n\n// ======================== Place Analysis ========================\n\ninterface PlaceInfo {\n hasIncoming: boolean;\n hasOutgoing: boolean;\n}\n\nfunction analyzePlaces(net: PetriNet): Map<string, PlaceInfo> {\n const map = new Map<string, PlaceInfo>();\n\n function ensure(name: string): PlaceInfo {\n let info = map.get(name);\n if (!info) {\n info = { hasIncoming: false, hasOutgoing: false };\n map.set(name, info);\n }\n return info;\n }\n\n for (const t of net.transitions) {\n for (const spec of t.inputSpecs) {\n ensure(spec.place.name).hasOutgoing = true;\n }\n if (t.outputSpec !== null) {\n for (const p of t.outputPlaces()) {\n ensure(p.name).hasIncoming = true;\n }\n }\n for (const inh of t.inhibitors) {\n ensure(inh.place.name);\n }\n for (const r of t.reads) {\n ensure(r.place.name).hasOutgoing = true;\n }\n for (const rst of t.resets) {\n ensure(rst.place.name);\n }\n }\n\n return map;\n}\n\nfunction placeCategory(info: PlaceInfo, isEnvironment: boolean): NodeCategory {\n if (isEnvironment) return 'environment';\n if (!info.hasIncoming) return 'start';\n if (!info.hasOutgoing) return 'end';\n return 'place';\n}\n\n// ======================== Helpers ========================\n\nfunction transitionLabel(t: Transition, config: DotConfig): string {\n const parts = [t.name];\n\n if (config.showIntervals) {\n const e = earliest(t.timing);\n const l = latest(t.timing);\n const max = hasDeadline(t.timing) ? String(l) : '∞';\n parts.push(`[${e}, ${max}]ms`);\n }\n\n if (config.showPriority && t.priority !== 0) {\n parts.push(`prio=${t.priority}`);\n }\n\n return parts.join(' ');\n}\n\n/**\n * Mutable per-transition state threaded through the recursive Out-tree walk.\n *\n * `counter` starts at 0 and increments once per emitted junction (depth-first\n * pre-order). `combined` accumulates place names where a reset+output combination\n * short-circuited the standalone reset edge.\n */\ninterface EmitCtx {\n readonly tSanitized: string;\n readonly resetPlaces: ReadonlySet<string>;\n readonly combined: Set<string>;\n readonly nodes: GraphNode[];\n readonly edges: GraphEdge[];\n counter: number;\n /**\n * Instance prefix (e.g. \"b1\" or \"outer/inner\") of the parent transition —\n * junction nodes inherit this so they live inside the right cluster per\n * [MOD-040]. Undefined for transitions that are not part of any composed\n * instance.\n */\n readonly transitionPrefix: string | undefined;\n /**\n * Shared map populated during mapping; junction emitters add their own\n * entries under transitionPrefix.\n */\n readonly nodeIdToPrefix: Map<string, string>;\n}\n\n/**\n * Emits output edges for an Out tree, inserting junction nodes for XOR/AND\n * groups with ≥2 children. Combined reset+output edges replace plain output\n * edges when a leaf place is also in `ctx.resetPlaces`.\n *\n * @param out current Out subtree\n * @param parentId id of the parent node (transition or junction)\n * @param branchLabel label to apply to the edge entering this Out (timeout/XOR-branch label)\n * @param ctx per-transition junction context (counter, reset set, accumulators)\n */\nfunction emitOutput(out: Out, parentId: string, branchLabel: string | null, ctx: EmitCtx): void {\n switch (out.type) {\n case 'place': {\n const pid = 'p_' + sanitize(out.place.name);\n pushLeafEdge(parentId, pid, out.place.name, branchLabel, ctx, false);\n return;\n }\n\n case 'forward-input': {\n const pid = 'p_' + sanitize(out.to.name);\n const fwdLabel = (branchLabel ? branchLabel + ' ' : '') + '⟵' + out.from.name;\n // ForwardInput is dashed; reset+out combination overrides if applicable.\n pushLeafEdge(parentId, pid, out.to.name, fwdLabel, ctx, true);\n return;\n }\n\n case 'and':\n case 'xor': {\n // Single-child groups collapse: pass through.\n if (out.children.length < 2) {\n if (out.children.length === 1) {\n emitOutput(out.children[0]!, parentId, branchLabel, ctx);\n }\n return;\n }\n\n // Insert junction node — diamond gateway with heavy ✕ / ✚ glyph as discriminator.\n const kind = out.type;\n const idx = ctx.counter++;\n const junctionId = `j_${ctx.tSanitized}__${kind}_${idx}`;\n const category: NodeCategory = kind === 'xor' ? 'xor-junction' : 'and-junction';\n const jStyle = nodeStyle(category);\n ctx.nodes.push({\n id: junctionId,\n label: kind === 'xor' ? '✕' : '✚',\n shape: jStyle.shape,\n fill: jStyle.fill,\n stroke: jStyle.stroke,\n penwidth: jStyle.penwidth,\n semanticId: junctionId,\n height: jStyle.height,\n width: jStyle.width,\n attrs: { fixedsize: 'true', fontsize: '14' },\n });\n // Junctions belong to their parent transition's cluster per [MOD-040].\n if (ctx.transitionPrefix !== undefined) {\n ctx.nodeIdToPrefix.set(junctionId, ctx.transitionPrefix);\n }\n\n // Edge parent → junction (carries any inherited branch/timeout label).\n const outStyle = edgeStyle('output');\n ctx.edges.push({\n from: parentId,\n to: junctionId,\n label: branchLabel ?? undefined,\n color: outStyle.color,\n style: outStyle.style,\n arrowhead: outStyle.arrowhead,\n arcType: 'output',\n });\n\n // Recurse children: XOR junction propagates per-branch labels; AND junction does not.\n for (const child of out.children) {\n const childLabel = kind === 'xor' ? inferBranchLabel(child) : null;\n emitOutput(child, junctionId, childLabel, ctx);\n }\n return;\n }\n\n case 'timeout': {\n // Override any inherited branchLabel: the timeout label fully describes\n // this branch (the XOR pre-inference resolves to the same string).\n const timeoutLabel = `⏱${out.afterMs}ms`;\n emitOutput(out.child, parentId, timeoutLabel, ctx);\n return;\n }\n }\n}\n\nfunction pushLeafEdge(\n fromId: string,\n toId: string,\n placeName: string,\n branchLabel: string | null,\n ctx: EmitCtx,\n isForwardInput: boolean,\n): void {\n if (ctx.resetPlaces.has(placeName)) {\n ctx.combined.add(placeName);\n const ro = edgeStyle('reset-output');\n ctx.edges.push({\n from: fromId,\n to: toId,\n label: 'reset+out',\n color: ro.color,\n style: ro.style,\n arrowhead: ro.arrowhead,\n penwidth: ro.penwidth,\n arcType: 'reset-output',\n });\n return;\n }\n\n const out = edgeStyle('output');\n ctx.edges.push({\n from: fromId,\n to: toId,\n label: branchLabel ?? undefined,\n color: out.color,\n style: isForwardInput ? 'dashed' : out.style,\n arrowhead: out.arrowhead,\n arcType: 'output',\n });\n}\n\nfunction inferBranchLabel(out: Out): string | null {\n switch (out.type) {\n case 'place': return out.place.name;\n case 'timeout': return `⏱${out.afterMs}ms`;\n case 'forward-input': return out.to.name;\n case 'and':\n case 'xor':\n return null;\n }\n}\n","/**\n * Renders a Graph to DOT (Graphviz) string.\n *\n * Pure function with zero Petri net knowledge. Operates solely on the\n * format-agnostic Graph model.\n *\n * @module export/dot-renderer\n */\n\nimport type { Graph, GraphNode, GraphEdge, Subgraph } from './graph.js';\n\n// ======================== Public API ========================\n\n/** Renders a Graph to a DOT string suitable for Graphviz. */\nexport function renderDot(graph: Graph): string {\n const lines: string[] = [];\n\n lines.push(`digraph ${quoteId(graph.id)} {`);\n\n // Graph attributes\n lines.push(` rankdir=${graph.rankdir};`);\n for (const [key, value] of Object.entries(graph.graphAttrs)) {\n lines.push(` ${key}=${quoteAttr(value)};`);\n }\n\n // Node defaults\n if (Object.keys(graph.nodeDefaults).length > 0) {\n lines.push(` node [${formatAttrs(graph.nodeDefaults)}];`);\n }\n\n // Edge defaults\n if (Object.keys(graph.edgeDefaults).length > 0) {\n lines.push(` edge [${formatAttrs(graph.edgeDefaults)}];`);\n }\n\n lines.push('');\n\n // Subgraphs\n for (const sg of graph.subgraphs) {\n lines.push(...renderSubgraph(sg, ' '));\n lines.push('');\n }\n\n // Nodes\n for (const node of graph.nodes) {\n lines.push(` ${renderNode(node)}`);\n }\n\n if (graph.nodes.length > 0) {\n lines.push('');\n }\n\n // Edges\n for (const edge of graph.edges) {\n lines.push(` ${renderEdge(edge)}`);\n }\n\n lines.push('}');\n\n return lines.join('\\n');\n}\n\n// ======================== Internal Rendering ========================\n\nfunction renderNode(node: GraphNode): string {\n const attrs: Record<string, string> = {\n label: node.label,\n shape: node.shape,\n style: node.style ? `\"filled,${node.style}\"` : 'filled',\n fillcolor: node.fill,\n color: node.stroke,\n penwidth: String(node.penwidth),\n };\n\n if (node.height !== undefined) {\n attrs['height'] = String(node.height);\n }\n if (node.width !== undefined) {\n attrs['width'] = String(node.width);\n }\n\n // Merge extra attrs\n if (node.attrs) {\n for (const [key, value] of Object.entries(node.attrs)) {\n attrs[key] = value;\n }\n }\n\n return `${quoteId(node.id)} [${formatNodeAttrs(attrs)}];`;\n}\n\nfunction renderEdge(edge: GraphEdge): string {\n const attrs: Record<string, string> = {\n color: edge.color,\n style: edge.style,\n arrowhead: edge.arrowhead,\n };\n\n if (edge.label !== undefined) {\n attrs['label'] = edge.label;\n }\n if (edge.penwidth !== undefined) {\n attrs['penwidth'] = String(edge.penwidth);\n }\n\n // Merge extra attrs\n if (edge.attrs) {\n for (const [key, value] of Object.entries(edge.attrs)) {\n attrs[key] = value;\n }\n }\n\n return `${quoteId(edge.from)} -> ${quoteId(edge.to)} [${formatNodeAttrs(attrs)}];`;\n}\n\nfunction renderSubgraph(sg: Subgraph, indent: string): string[] {\n const lines: string[] = [];\n lines.push(`${indent}subgraph ${quoteId('cluster_' + sg.id)} {`);\n\n if (sg.label !== undefined) {\n lines.push(`${indent} label=${quoteAttr(sg.label)};`);\n }\n\n if (sg.attrs) {\n for (const [key, value] of Object.entries(sg.attrs)) {\n lines.push(`${indent} ${key}=${quoteAttr(value)};`);\n }\n }\n\n for (const node of sg.nodes) {\n lines.push(`${indent} ${renderNode(node)}`);\n }\n\n // Nested clusters per EXP-016 / MOD-040.\n if (sg.subgraphs) {\n for (const nested of sg.subgraphs) {\n lines.push(...renderSubgraph(nested, indent + ' '));\n }\n }\n\n // Intra-cluster edges (both endpoints inside this cluster) — placed inside\n // the cluster so Graphviz routes them correctly. Cross-cluster edges live\n // on the top-level Graph.edges list.\n if (sg.edges) {\n for (const e of sg.edges) {\n lines.push(`${indent} ${renderEdge(e)}`);\n }\n }\n\n lines.push(`${indent}}`);\n return lines;\n}\n\n// ======================== DOT Quoting ========================\n\n/** Quotes a DOT identifier. Always quotes to be safe with special chars. */\nfunction quoteId(id: string): string {\n // DOT keywords that must be quoted\n if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(id) && !isDotKeyword(id)) {\n return id;\n }\n return `\"${escapeDot(id)}\"`;\n}\n\n/** Quotes a DOT attribute value. */\nfunction quoteAttr(value: string): string {\n // Numbers don't need quoting\n if (/^-?\\d+(\\.\\d+)?$/.test(value)) {\n return value;\n }\n return `\"${escapeDot(value)}\"`;\n}\n\n/** Escapes special characters for DOT strings. */\nfunction escapeDot(s: string): string {\n return s.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"');\n}\n\n/**\n * Formats node/edge attributes where certain values (like style with commas)\n * need special handling.\n */\nfunction formatNodeAttrs(attrs: Record<string, string>): string {\n return Object.entries(attrs)\n .map(([key, value]) => {\n // Style values that are already pre-quoted (contain the quote char)\n if (value.startsWith('\"') && value.endsWith('\"')) {\n return `${key}=${value}`;\n }\n return `${key}=${quoteAttr(value)}`;\n })\n .join(', ');\n}\n\n/** Formats simple key=value attributes. */\nfunction formatAttrs(attrs: Readonly<Record<string, string>>): string {\n return Object.entries(attrs)\n .map(([key, value]) => `${key}=${quoteAttr(value)}`)\n .join(', ');\n}\n\n/** DOT language keywords that must be quoted when used as identifiers. */\nfunction isDotKeyword(id: string): boolean {\n const lower = id.toLowerCase();\n return lower === 'graph' || lower === 'digraph' || lower === 'subgraph'\n || lower === 'node' || lower === 'edge' || lower === 'strict';\n}\n","/**\n * Convenience function for exporting a PetriNet to DOT format.\n *\n * @module export/dot-exporter\n */\n\nimport type { PetriNet } from '../core/petri-net.js';\nimport type { DotConfig } from './petri-net-mapper.js';\nimport { mapToGraph } from './petri-net-mapper.js';\nimport { renderDot } from './dot-renderer.js';\n\n/**\n * Exports a PetriNet to DOT (Graphviz) format.\n *\n * @param net the Petri net to export\n * @param config optional export configuration\n * @returns DOT string suitable for rendering with Graphviz\n */\nexport function dotExport(net: PetriNet, config?: DotConfig): string {\n return renderDot(mapToGraph(net, config));\n}\n"],"mappings":";;;;;;;AAoDA,IAAM,cAAgD;AAAA,EACpD,OAAiB,EAAE,OAAO,UAAW,MAAM,WAAW,QAAQ,WAAW,UAAU,KAAK,OAAO,KAAK;AAAA,EACpG,OAAiB,EAAE,OAAO,UAAW,MAAM,WAAW,QAAQ,WAAW,UAAU,GAAK,OAAO,KAAK;AAAA,EACpG,KAAiB,EAAE,OAAO,gBAAiB,MAAM,WAAW,QAAQ,WAAW,UAAU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