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
@@ -0,0 +1,227 @@
1
+ import panzoom from 'panzoom';
2
+
3
+ /**
4
+ * Pan/zoom wrapper for the canonical libpetri viewer.
5
+ *
6
+ * Delegates to the `panzoom` library (no hand-rolled wheel handlers — we
7
+ * intentionally drop the IIFE/javadoc version's bespoke math in favour of
8
+ * a single battle-tested implementation). Defaults match the old debug-ui
9
+ * and dev-preview values so the canonical viewer feels identical to what
10
+ * users had before.
11
+ *
12
+ * @module viewer/pan-zoom
13
+ */
14
+
15
+ type PanzoomInstance = ReturnType<typeof panzoom>;
16
+ type PanzoomOptions = Parameters<typeof panzoom>[1];
17
+ /**
18
+ * Default panzoom configuration shared across all viewer surfaces.
19
+ *
20
+ * - `maxZoom: 1000` — effectively unlimited; lets users dive into ~150-node
21
+ * diagrams without hitting an artificial ceiling.
22
+ * - `minZoom: 0.02` — allows fitting very large nets in a small viewport.
23
+ * - `smoothScroll: false` — sharper interactive feel.
24
+ * - `zoomDoubleClickSpeed: 1` — single-click double-zoom toggle.
25
+ */
26
+ declare const DEFAULT_PANZOOM_OPTS: {
27
+ readonly smoothScroll: false;
28
+ readonly zoomDoubleClickSpeed: 1;
29
+ readonly maxZoom: 1000;
30
+ readonly minZoom: 0.02;
31
+ };
32
+
33
+ /**
34
+ * Cluster overlay for the canonical libpetri viewer.
35
+ *
36
+ * Post-processes a rendered SVG to surface subnet structure visually:
37
+ * 1. Discover `<g class="cluster">` subgraphs, derive each prefix from the
38
+ * contained `<title>` (Graphviz emits `cluster_<sanitizedPrefix>`).
39
+ * 2. Tag every contained `<g class="node">` with `data-instance="<prefix>"`
40
+ * so filtering can target it via attribute selectors.
41
+ * 3. Assign each cluster a deterministic HSL colour (FNV-1a hash + golden
42
+ * ratio hue increment) and paint its border.
43
+ * 4. Provide collapse/expand and "show only <prefix>" filtering.
44
+ *
45
+ * Unlike the previous debug-ui cluster-overlay, this module is instance-
46
+ * based: every `mount()` call gets its own `ClusterOverlay` so multiple
47
+ * viewers on the same page don't share collapse/isolate state.
48
+ *
49
+ * @module viewer/cluster-overlay
50
+ */
51
+ /** A discovered cluster with its DOM group, node count, and palette colour. */
52
+ interface ClusterDescriptor {
53
+ readonly prefix: string;
54
+ readonly group: SVGGElement;
55
+ readonly nodeCount: number;
56
+ readonly color: string;
57
+ }
58
+ /**
59
+ * Walk the SVG, find every `<g class="cluster">`, derive the prefix from
60
+ * each cluster's `<title>` (`cluster_<sanitized>`), and tag every cluster-
61
+ * interior `<g class="node">` with `data-instance="<prefix>"`. Returns one
62
+ * descriptor per cluster.
63
+ *
64
+ * Graphviz emits cluster nodes as SIBLINGS of the cluster `<g>`, not as
65
+ * children — `<g class="cluster">` only carries title, polygon border, and
66
+ * the cluster's text label. To recover cluster membership we match each
67
+ * node's `<title>` (the original graph id) against libpetri's prefixing
68
+ * convention: interior places are emitted as `p_<prefix>_<name>`,
69
+ * transitions as `t_<prefix>_<name>`, and junctions as `j_<prefix>_<name>`.
70
+ *
71
+ * Does not split nested-cluster prefixes (`outer_inner` could mean either
72
+ * `outer/inner` or a flat `outer_inner` prefix — Graphviz sanitisation is
73
+ * lossy). We treat every cluster as its own top-level entry, matching the
74
+ * doclet's pragmatism.
75
+ */
76
+ declare function discoverClusters(svg: SVGSVGElement): Map<string, ClusterDescriptor>;
77
+ /**
78
+ * Deterministic HSL palette. FNV-1a-ish hash of the prefix, multiplied by
79
+ * the golden-ratio fraction (0.61803...) to spread adjacent prefixes
80
+ * visually. Saturation/lightness are fixed (60% / 45%) so the palette
81
+ * stays readable on both the doc background and the dark debug UI.
82
+ */
83
+ declare function colorForPrefix(prefix: string): string;
84
+
85
+ interface VisibilityState {
86
+ /** Cluster short names currently visible. */
87
+ readonly visibleClusters: ReadonlySet<string>;
88
+ /**
89
+ * When false, hide every replica/shared place (`g.node.petri-replica`)
90
+ * regardless of which cluster it belongs to. The corresponding sidebar
91
+ * checkbox is labelled "Shared places".
92
+ */
93
+ readonly includeSharedPlaces: boolean;
94
+ }
95
+
96
+ /**
97
+ * CSS custom properties exposed by the canonical viewer stylesheet.
98
+ *
99
+ * Each property has a default in `viewer.css`. Consumers can override any of
100
+ * them at any scope (the viewer container, the document root, etc.) to
101
+ * theme the viewer without touching the canonical CSS.
102
+ *
103
+ * Names are listed here as a reference + so the IIFE bundle can expose them
104
+ * on `window.LibpetriViewer.cssVariables`. The list is informational — the
105
+ * stylesheet is still the source of truth.
106
+ *
107
+ * @module viewer/styles
108
+ */
109
+ /** CSS custom property names that the canonical stylesheet honours. */
110
+ declare const VIEWER_CSS_VARIABLES: readonly ["--lpv-bg", "--lpv-header-bg", "--lpv-border", "--lpv-text", "--lpv-muted", "--lpv-cluster-bg", "--lpv-cluster-bg-collapsed", "--lpv-cluster-stroke-width", "--lpv-cluster-stroke-dash", "--lpv-cluster-fill-tint", "--lpv-dim-opacity", "--lpv-active-filter-outline", "--lpv-legend-bg", "--lpv-chip-bg", "--lpv-chip-active-bg", "--lpv-sidebar-bg", "--lpv-sidebar-border", "--lpv-sidebar-text", "--lpv-sidebar-muted", "--lpv-sidebar-chip-bg", "--lpv-sidebar-chip-hover-bg", "--lpv-sidebar-chip-off-opacity", "--lpv-shared-glyph-color", "--lpv-replica-fill", "--lpv-replica-stroke", "--lpv-highlight-stroke", "--lpv-highlight-glow", "--lpv-neighbor-stroke", "--lpv-faded-node-opacity", "--lpv-faded-edge-opacity", "--lpv-faded-cluster-opacity"];
111
+
112
+ /**
113
+ * Canonical libpetri Petri-net diagram viewer.
114
+ *
115
+ * Single source of truth for DOT → SVG rendering + cluster overlay across
116
+ * all four surfaces:
117
+ * - debug-ui (live debugger)
118
+ * - dev-preview (Vite app)
119
+ * - Javadoc taglet (Java doclet)
120
+ * - Rustdoc embed (libpetri-docgen)
121
+ * - TypeDoc / typescript doclet
122
+ *
123
+ * Build outputs:
124
+ * - ESM: `dist/viewer/index.js` — consumed by Vite/Webpack/Node bundlers.
125
+ * - IIFE: `dist/viewer/viewer.iife.js` — self-contained, exposes
126
+ * `window.LibpetriViewer = { mount, ... }`. Used by the doc taglets
127
+ * that ship pre-rendered HTML pages without a bundler.
128
+ * - CSS: `dist/viewer/viewer.css` — canonical stylesheet (copied from
129
+ * `src/viewer/resources/viewer.css`).
130
+ *
131
+ * Edits to viewer behaviour MUST happen here. The three resource directories
132
+ * under `java/`, `rust/`, and `typescript/src/doclet/` are **build outputs**
133
+ * populated by `scripts/build-viewer.sh` and must not be hand-edited.
134
+ *
135
+ * @module viewer
136
+ */
137
+
138
+ /** Handle returned by {@link mount}. */
139
+ interface ViewerHandle {
140
+ /** The rendered root `<svg>` element. */
141
+ readonly svg: SVGSVGElement;
142
+ /** The panzoom instance attached to the SVG. */
143
+ readonly panzoom: PanzoomInstance;
144
+ /** Map of cluster prefix → descriptor for the current SVG. */
145
+ readonly clusters: ReadonlyMap<string, ClusterDescriptor>;
146
+ /** Prefixes currently marked collapsed on this handle. */
147
+ readonly collapsedPrefixes: ReadonlySet<string>;
148
+ /** Currently active "show only <prefix>" filter, or null. */
149
+ readonly activeFilter: string | null;
150
+ /** Collapse a single cluster by prefix. No-op if unknown. */
151
+ collapse(prefix: string): void;
152
+ /** Expand a single cluster by prefix. No-op if unknown. */
153
+ expand(prefix: string): void;
154
+ /** Collapse every discovered cluster. */
155
+ collapseAll(): void;
156
+ /** Expand every collapsed cluster. */
157
+ expandAll(): void;
158
+ /** Apply the "show only <prefix>" filter; pass `null` to clear. */
159
+ filter(prefix: string | null): void;
160
+ /** Reset pan/zoom to the identity transform. */
161
+ resetZoom(): void;
162
+ /** Scale and translate so the full diagram fits the host viewport. */
163
+ fit(): void;
164
+ /** Reports whether `graphId` is inside a currently-collapsed cluster. */
165
+ isInsideCollapsedCluster(graphId: string): boolean;
166
+ /**
167
+ * Highlight a node and every DOM copy of the same logical place; walk
168
+ * junctions to surface real neighbors. Pass `null` to clear. C0-only.
169
+ */
170
+ highlight(nodeId: string | null): void;
171
+ /** The node id currently highlighted, or `null`. */
172
+ readonly highlightedNodeId: string | null;
173
+ /**
174
+ * Set the cluster-visibility state: which clusters render, and whether
175
+ * directed-reachable orphans render. C0-only.
176
+ */
177
+ setVisibility(state: VisibilityState): void;
178
+ /** Tear down: dispose panzoom and detach listeners. */
179
+ dispose(): void;
180
+ }
181
+ /** Options accepted by {@link mount}. */
182
+ interface MountOptions {
183
+ /**
184
+ * Previous handle to dispose before mounting. Pass the handle returned
185
+ * by a prior `mount()` call so callers don't need to track it separately.
186
+ * Cluster collapse / filter state from `previousHandle` is preserved
187
+ * across the re-render so the user's intent survives a live re-draw.
188
+ */
189
+ readonly previousHandle?: ViewerHandle | null;
190
+ /** Per-call panzoom overrides; merged on top of {@link DEFAULT_PANZOOM_OPTS}. */
191
+ readonly panzoom?: PanzoomOptions;
192
+ /** Fired after a cluster's collapsed state changes via the handle API. */
193
+ readonly onClusterCollapse?: (prefix: string, collapsed: boolean) => void;
194
+ /** Fired after `filter()` runs, with the new filter prefix or null. */
195
+ readonly onClusterFilter?: (prefix: string | null) => void;
196
+ /** When true, append a legend sidebar + filter chip strip inside `container`. */
197
+ readonly chrome?: boolean;
198
+ /**
199
+ * Layout strategy. `'elk'` (default) runs the C0 pipeline — parse → fold
200
+ * → replicate → ELK → Graphviz `neato` pin mode — and tags replica
201
+ * nodes for the click-all-copies + ⇄ overlay. `'graphviz'` runs the
202
+ * plain Graphviz `dot` engine and skips replica tagging. The result is
203
+ * cached on the DOT hash; re-mounts on identical DOT skip the pipeline.
204
+ */
205
+ readonly layout?: 'elk' | 'graphviz';
206
+ }
207
+ /**
208
+ * Render a DOT source, mount the resulting SVG into `container`, wire pan/zoom,
209
+ * and surface cluster overlay controls.
210
+ *
211
+ * The container's existing children are removed before the new SVG is
212
+ * appended (the same teardown behaviour `renderDotToContainer` used to provide).
213
+ *
214
+ * Pass `dotSource === null` to adopt an SVG already present as a direct child
215
+ * of `container` (pre-rendered SVG path — e.g. the Java javadoc taglet emits
216
+ * `dot -Tsvg` at build time). In that mode the viewer never imports the
217
+ * runtime DOT renderer, which lets the static IIFE bundle drop `@viz-js/viz`
218
+ * entirely.
219
+ *
220
+ * NOTE: when shipping a pre-rendered SVG (`dotSource === null`), do NOT also
221
+ * pass `previousHandle` — the handle's `dispose()` runs before SVG detection
222
+ * and would orphan the host. The Java taglet mounts once per page so this is
223
+ * a non-issue in practice.
224
+ */
225
+ declare function mount(dotSource: string | null, container: HTMLElement, opts?: MountOptions): Promise<ViewerHandle>;
226
+
227
+ export { type ClusterDescriptor, DEFAULT_PANZOOM_OPTS, type MountOptions, type PanzoomInstance, type PanzoomOptions, VIEWER_CSS_VARIABLES, type ViewerHandle, colorForPrefix, discoverClusters, mount };