@statewalker/fsm-charts 0.0.1

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 (132) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1 -0
  4. package/dist/StateChart-DNGQd1XG.d.ts +53 -0
  5. package/dist/chunk-3GGM3ZWL.js +2685 -0
  6. package/dist/chunk-NXWOFQMO.js +10 -0
  7. package/dist/chunk-TPNWHU7Y.js +437 -0
  8. package/dist/index-layout.d.ts +96 -0
  9. package/dist/index-layout.js +2 -0
  10. package/dist/index-svg.d.ts +25 -0
  11. package/dist/index-svg.js +2 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.js +3 -0
  14. package/package.json +60 -0
  15. package/src/FsmStateConfig.ts +5 -0
  16. package/src/dagre/acyclic.d.ts +2 -0
  17. package/src/dagre/acyclic.js +60 -0
  18. package/src/dagre/add-border-segments.d.ts +1 -0
  19. package/src/dagre/add-border-segments.js +36 -0
  20. package/src/dagre/coordinate-system.d.ts +2 -0
  21. package/src/dagre/coordinate-system.js +75 -0
  22. package/src/dagre/data/list.d.ts +12 -0
  23. package/src/dagre/data/list.js +55 -0
  24. package/src/dagre/debug.d.ts +2 -0
  25. package/src/dagre/debug.js +32 -0
  26. package/src/dagre/greedy-fas.d.ts +1 -0
  27. package/src/dagre/greedy-fas.js +126 -0
  28. package/src/dagre/index.d.ts +5 -0
  29. package/src/dagre/index.js +6 -0
  30. package/src/dagre/layout.d.ts +1 -0
  31. package/src/dagre/layout.js +466 -0
  32. package/src/dagre/nesting-graph.d.ts +2 -0
  33. package/src/dagre/nesting-graph.js +137 -0
  34. package/src/dagre/normalize.d.ts +2 -0
  35. package/src/dagre/normalize.js +91 -0
  36. package/src/dagre/order/add-subgraph-constraints.d.ts +1 -0
  37. package/src/dagre/order/add-subgraph-constraints.js +53 -0
  38. package/src/dagre/order/barycenter.d.ts +15 -0
  39. package/src/dagre/order/barycenter.js +31 -0
  40. package/src/dagre/order/build-layer-graph.d.ts +2 -0
  41. package/src/dagre/order/build-layer-graph.js +76 -0
  42. package/src/dagre/order/cross-count.d.ts +1 -0
  43. package/src/dagre/order/cross-count.js +82 -0
  44. package/src/dagre/order/index.d.ts +1 -0
  45. package/src/dagre/order/index.js +77 -0
  46. package/src/dagre/order/init-order.d.ts +1 -0
  47. package/src/dagre/order/init-order.js +44 -0
  48. package/src/dagre/order/resolve-conflicts.d.ts +1 -0
  49. package/src/dagre/order/resolve-conflicts.js +128 -0
  50. package/src/dagre/order/sort-subgraph.d.ts +8 -0
  51. package/src/dagre/order/sort-subgraph.js +78 -0
  52. package/src/dagre/order/sort.d.ts +6 -0
  53. package/src/dagre/order/sort.js +59 -0
  54. package/src/dagre/parent-dummy-chains.d.ts +1 -0
  55. package/src/dagre/parent-dummy-chains.js +86 -0
  56. package/src/dagre/position/bk.d.ts +31 -0
  57. package/src/dagre/position/bk.js +423 -0
  58. package/src/dagre/position/index.d.ts +1 -0
  59. package/src/dagre/position/index.js +31 -0
  60. package/src/dagre/rank/feasible-tree.d.ts +2 -0
  61. package/src/dagre/rank/feasible-tree.js +87 -0
  62. package/src/dagre/rank/index.d.ts +1 -0
  63. package/src/dagre/rank/index.js +52 -0
  64. package/src/dagre/rank/network-simplex.d.ts +16 -0
  65. package/src/dagre/rank/network-simplex.js +236 -0
  66. package/src/dagre/rank/util.d.ts +2 -0
  67. package/src/dagre/rank/util.js +63 -0
  68. package/src/dagre/util.d.ts +27 -0
  69. package/src/dagre/util.js +250 -0
  70. package/src/graphlib/alg/components.d.ts +1 -0
  71. package/src/graphlib/alg/components.js +27 -0
  72. package/src/graphlib/alg/dfs.d.ts +1 -0
  73. package/src/graphlib/alg/dfs.js +46 -0
  74. package/src/graphlib/alg/dijkstra-all.d.ts +1 -0
  75. package/src/graphlib/alg/dijkstra-all.js +14 -0
  76. package/src/graphlib/alg/dijkstra.d.ts +1 -0
  77. package/src/graphlib/alg/dijkstra.js +65 -0
  78. package/src/graphlib/alg/find-cycles.d.ts +1 -0
  79. package/src/graphlib/alg/find-cycles.js +10 -0
  80. package/src/graphlib/alg/floyd-warshall.d.ts +1 -0
  81. package/src/graphlib/alg/floyd-warshall.js +55 -0
  82. package/src/graphlib/alg/index.d.ts +24 -0
  83. package/src/graphlib/alg/index.js +25 -0
  84. package/src/graphlib/alg/is-acyclic.d.ts +1 -0
  85. package/src/graphlib/alg/is-acyclic.js +15 -0
  86. package/src/graphlib/alg/postorder.d.ts +1 -0
  87. package/src/graphlib/alg/postorder.js +7 -0
  88. package/src/graphlib/alg/preorder.d.ts +1 -0
  89. package/src/graphlib/alg/preorder.js +7 -0
  90. package/src/graphlib/alg/prim.d.ts +2 -0
  91. package/src/graphlib/alg/prim.js +52 -0
  92. package/src/graphlib/alg/tarjan.d.ts +1 -0
  93. package/src/graphlib/alg/tarjan.js +47 -0
  94. package/src/graphlib/alg/topsort.d.ts +5 -0
  95. package/src/graphlib/alg/topsort.js +36 -0
  96. package/src/graphlib/data/priority-queue.d.ts +59 -0
  97. package/src/graphlib/data/priority-queue.js +152 -0
  98. package/src/graphlib/graph.d.ts +55 -0
  99. package/src/graphlib/graph.js +510 -0
  100. package/src/graphlib/index.d.ts +3 -0
  101. package/src/graphlib/index.js +7 -0
  102. package/src/graphlib/json.d.ts +16 -0
  103. package/src/graphlib/json.js +63 -0
  104. package/src/index-layout.ts +1 -0
  105. package/src/index-svg.ts +1 -0
  106. package/src/index.ts +2 -0
  107. package/src/layout/Dimensions.ts +8 -0
  108. package/src/layout/GraphParamsProvider.ts +17 -0
  109. package/src/layout/Padding.ts +10 -0
  110. package/src/layout/Position.ts +4 -0
  111. package/src/layout/StateChart.ts +8 -0
  112. package/src/layout/StateGraphEdge.ts +14 -0
  113. package/src/layout/StateGraphNode.ts +12 -0
  114. package/src/layout/Transition.ts +5 -0
  115. package/src/layout/TransitionsGraph.ts +13 -0
  116. package/src/layout/buildCharts.ts +74 -0
  117. package/src/layout/buildFlatCharts.ts +142 -0
  118. package/src/layout/getGraphParamsProvider.ts +63 -0
  119. package/src/layout/getLabelDimensions.ts +59 -0
  120. package/src/layout/index.ts +15 -0
  121. package/src/lodash-es/_deleteme.js +291 -0
  122. package/src/lodash-es/index.ts +9 -0
  123. package/src/lodash-es/types.ts +35 -0
  124. package/src/svg/buildStatechartCss.ts +120 -0
  125. package/src/svg/buildStatechartSvg.ts +256 -0
  126. package/src/svg/buildStatechartsPanel.ts +38 -0
  127. package/src/svg/index.ts +3 -0
  128. package/src/utils/BasisCurve.ts +89 -0
  129. package/src/utils/getPadding.ts +13 -0
  130. package/src/utils/serializeAttrs.ts +28 -0
  131. package/src/utils/serializeStyle.ts +11 -0
  132. package/src/utils/toKebabCase.ts +18 -0
@@ -0,0 +1,55 @@
1
+ export class Graph {
2
+ constructor(opts?: {});
3
+ _isDirected: any;
4
+ _isMultigraph: any;
5
+ _isCompound: any;
6
+ _label: any;
7
+ _defaultNodeLabelFn: () => any;
8
+ _defaultEdgeLabelFn: () => any;
9
+ _nodes: {};
10
+ _parent: {};
11
+ _children: {};
12
+ _in: {};
13
+ _preds: {};
14
+ _out: {};
15
+ _sucs: {};
16
+ _edgeObjs: {};
17
+ _edgeLabels: {};
18
+ isDirected(): any;
19
+ isMultigraph(): any;
20
+ isCompound(): any;
21
+ setGraph(label: any): Graph;
22
+ graph(): any;
23
+ setDefaultNodeLabel(newDefault: any): Graph;
24
+ nodeCount(): number;
25
+ nodes(): string[];
26
+ sources(): string[];
27
+ sinks(): string[];
28
+ setNodes(vs: any, value: any, ...args: any[]): Graph;
29
+ setNode(v: any, value: any, ...args: any[]): Graph;
30
+ node(v: any): any;
31
+ hasNode(v: any): boolean;
32
+ removeNode(v: any): Graph;
33
+ setParent(v: any, parent: any): Graph;
34
+ _removeFromParentsChildList(v: any): void;
35
+ parent(v: any): any;
36
+ children(v: any): string[];
37
+ predecessors(v: any): string[];
38
+ successors(v: any): string[];
39
+ neighbors(v: any): string[];
40
+ isLeaf(v: any): boolean;
41
+ filterNodes(filter: any): any;
42
+ setDefaultEdgeLabel(newDefault: any): Graph;
43
+ edgeCount(): number;
44
+ edges(): any[];
45
+ setPath(vs: any, value: any, ...args: any[]): Graph;
46
+ setEdge(...args: any[]): Graph;
47
+ edge(v: any, w: any, name: any, ...args: any[]): any;
48
+ hasEdge(v: any, w: any, name: any, ...args: any[]): boolean;
49
+ removeEdge(v: any, w: any, name: any, ...args: any[]): Graph;
50
+ inEdges(v: any, u: any): any[];
51
+ outEdges(v: any, w: any): any[];
52
+ nodeEdges(v: any, w: any): any[];
53
+ _nodeCount: number;
54
+ _edgeCount: number;
55
+ }
@@ -0,0 +1,510 @@
1
+ import { _ } from '../lodash-es/index.ts';
2
+
3
+ var DEFAULT_EDGE_NAME = '\x00';
4
+ var GRAPH_NODE = '\x00';
5
+ var EDGE_KEY_DELIM = '\x01';
6
+
7
+ // Implementation notes:
8
+ //
9
+ // * Node id query functions should return string ids for the nodes
10
+ // * Edge id query functions should return an "edgeObj", edge object, that is
11
+ // composed of enough information to uniquely identify an edge: {v, w, name}.
12
+ // * Internally we use an "edgeId", a stringified form of the edgeObj, to
13
+ // reference edges. This is because we need a performant way to look these
14
+ // edges up and, object properties, which have string keys, are the closest
15
+ // we're going to get to a performant hashtable in JavaScript.
16
+
17
+ // Implementation notes:
18
+ //
19
+ // * Node id query functions should return string ids for the nodes
20
+ // * Edge id query functions should return an "edgeObj", edge object, that is
21
+ // composed of enough information to uniquely identify an edge: {v, w, name}.
22
+ // * Internally we use an "edgeId", a stringified form of the edgeObj, to
23
+ // reference edges. This is because we need a performant way to look these
24
+ // edges up and, object properties, which have string keys, are the closest
25
+ // we're going to get to a performant hashtable in JavaScript.
26
+ export class Graph {
27
+ constructor(opts = {}) {
28
+ this._isDirected = _.has(opts, 'directed') ? opts.directed : true;
29
+ this._isMultigraph = _.has(opts, 'multigraph') ? opts.multigraph : false;
30
+ this._isCompound = _.has(opts, 'compound') ? opts.compound : false;
31
+
32
+ // Label for the graph itself
33
+ this._label = undefined;
34
+
35
+ // Defaults to be set when creating a new node
36
+ this._defaultNodeLabelFn = _.constant(undefined);
37
+
38
+ // Defaults to be set when creating a new edge
39
+ this._defaultEdgeLabelFn = _.constant(undefined);
40
+
41
+ // v -> label
42
+ this._nodes = {};
43
+
44
+ if (this._isCompound) {
45
+ // v -> parent
46
+ this._parent = {};
47
+
48
+ // v -> children
49
+ this._children = {};
50
+ this._children[GRAPH_NODE] = {};
51
+ }
52
+
53
+ // v -> edgeObj
54
+ this._in = {};
55
+
56
+ // u -> v -> Number
57
+ this._preds = {};
58
+
59
+ // v -> edgeObj
60
+ this._out = {};
61
+
62
+ // v -> w -> Number
63
+ this._sucs = {};
64
+
65
+ // e -> edgeObj
66
+ this._edgeObjs = {};
67
+
68
+ // e -> label
69
+ this._edgeLabels = {};
70
+ }
71
+ /* === Graph functions ========= */
72
+ isDirected() {
73
+ return this._isDirected;
74
+ }
75
+ isMultigraph() {
76
+ return this._isMultigraph;
77
+ }
78
+ isCompound() {
79
+ return this._isCompound;
80
+ }
81
+ setGraph(label) {
82
+ this._label = label;
83
+ return this;
84
+ }
85
+ graph() {
86
+ return this._label;
87
+ }
88
+ /* === Node functions ========== */
89
+ setDefaultNodeLabel(newDefault) {
90
+ if (!_.isFunction(newDefault)) {
91
+ newDefault = _.constant(newDefault);
92
+ }
93
+ this._defaultNodeLabelFn = newDefault;
94
+ return this;
95
+ }
96
+ nodeCount() {
97
+ return this._nodeCount;
98
+ }
99
+ nodes() {
100
+ return _.keys(this._nodes);
101
+ }
102
+ sources() {
103
+ var self = this;
104
+ return _.filter(this.nodes(), function (v) {
105
+ return _.isEmpty(self._in[v]);
106
+ });
107
+ }
108
+ sinks() {
109
+ var self = this;
110
+ return _.filter(this.nodes(), function (v) {
111
+ return _.isEmpty(self._out[v]);
112
+ });
113
+ }
114
+ setNodes(vs, value) {
115
+ var args = arguments;
116
+ var self = this;
117
+ _.each(vs, function (v) {
118
+ if (args.length > 1) {
119
+ self.setNode(v, value);
120
+ } else {
121
+ self.setNode(v);
122
+ }
123
+ });
124
+ return this;
125
+ }
126
+ setNode(v, value) {
127
+ if (_.has(this._nodes, v)) {
128
+ if (arguments.length > 1) {
129
+ this._nodes[v] = value;
130
+ }
131
+ return this;
132
+ }
133
+
134
+ // @ts-expect-error
135
+ this._nodes[v] = arguments.length > 1 ? value : this._defaultNodeLabelFn(v);
136
+ if (this._isCompound) {
137
+ this._parent[v] = GRAPH_NODE;
138
+ this._children[v] = {};
139
+ this._children[GRAPH_NODE][v] = true;
140
+ }
141
+ this._in[v] = {};
142
+ this._preds[v] = {};
143
+ this._out[v] = {};
144
+ this._sucs[v] = {};
145
+ ++this._nodeCount;
146
+ return this;
147
+ }
148
+ node(v) {
149
+ return this._nodes[v];
150
+ }
151
+ hasNode(v) {
152
+ return _.has(this._nodes, v);
153
+ }
154
+ removeNode(v) {
155
+ var self = this;
156
+ if (_.has(this._nodes, v)) {
157
+ var removeEdge = function (e) {
158
+ self.removeEdge(self._edgeObjs[e]);
159
+ };
160
+ delete this._nodes[v];
161
+ if (this._isCompound) {
162
+ this._removeFromParentsChildList(v);
163
+ delete this._parent[v];
164
+ _.each(this.children(v), function (child) {
165
+ self.setParent(child);
166
+ });
167
+ delete this._children[v];
168
+ }
169
+ _.each(_.keys(this._in[v]), removeEdge);
170
+ delete this._in[v];
171
+ delete this._preds[v];
172
+ _.each(_.keys(this._out[v]), removeEdge);
173
+ delete this._out[v];
174
+ delete this._sucs[v];
175
+ --this._nodeCount;
176
+ }
177
+ return this;
178
+ }
179
+ setParent(v, parent) {
180
+ if (!this._isCompound) {
181
+ throw new Error('Cannot set parent in a non-compound graph');
182
+ }
183
+
184
+ if (_.isUndefined(parent)) {
185
+ parent = GRAPH_NODE;
186
+ } else {
187
+ // Coerce parent to string
188
+ parent += '';
189
+ for (var ancestor = parent; !_.isUndefined(ancestor); ancestor = this.parent(ancestor)) {
190
+ if (ancestor === v) {
191
+ throw new Error('Setting ' + parent + ' as parent of ' + v + ' would create a cycle');
192
+ }
193
+ }
194
+
195
+ this.setNode(parent);
196
+ }
197
+
198
+ this.setNode(v);
199
+ this._removeFromParentsChildList(v);
200
+ this._parent[v] = parent;
201
+ this._children[parent][v] = true;
202
+ return this;
203
+ }
204
+ _removeFromParentsChildList(v) {
205
+ delete this._children[this._parent[v]][v];
206
+ }
207
+ parent(v) {
208
+ if (this._isCompound) {
209
+ var parent = this._parent[v];
210
+ if (parent !== GRAPH_NODE) {
211
+ return parent;
212
+ }
213
+ }
214
+ }
215
+ children(v) {
216
+ if (_.isUndefined(v)) {
217
+ v = GRAPH_NODE;
218
+ }
219
+
220
+ if (this._isCompound) {
221
+ var children = this._children[v];
222
+ if (children) {
223
+ return _.keys(children);
224
+ }
225
+ } else if (v === GRAPH_NODE) {
226
+ return this.nodes();
227
+ } else if (this.hasNode(v)) {
228
+ return [];
229
+ }
230
+ }
231
+ predecessors(v) {
232
+ var predsV = this._preds[v];
233
+ if (predsV) {
234
+ return _.keys(predsV);
235
+ }
236
+ }
237
+ successors(v) {
238
+ var sucsV = this._sucs[v];
239
+ if (sucsV) {
240
+ return _.keys(sucsV);
241
+ }
242
+ }
243
+ neighbors(v) {
244
+ var preds = this.predecessors(v);
245
+ if (preds) {
246
+ return _.union(preds, this.successors(v));
247
+ }
248
+ }
249
+ isLeaf(v) {
250
+ var neighbors;
251
+ if (this.isDirected()) {
252
+ neighbors = this.successors(v);
253
+ } else {
254
+ neighbors = this.neighbors(v);
255
+ }
256
+ return neighbors.length === 0;
257
+ }
258
+ filterNodes(filter) {
259
+ // @ts-expect-error
260
+ var copy = new this.constructor({
261
+ directed: this._isDirected,
262
+ multigraph: this._isMultigraph,
263
+ compound: this._isCompound,
264
+ });
265
+
266
+ copy.setGraph(this.graph());
267
+
268
+ var self = this;
269
+ _.each(this._nodes, function (value, v) {
270
+ if (filter(v)) {
271
+ copy.setNode(v, value);
272
+ }
273
+ });
274
+
275
+ _.each(this._edgeObjs, function (e) {
276
+ // @ts-expect-error
277
+ if (copy.hasNode(e.v) && copy.hasNode(e.w)) {
278
+ copy.setEdge(e, self.edge(e));
279
+ }
280
+ });
281
+
282
+ var parents = {};
283
+ function findParent(v) {
284
+ var parent = self.parent(v);
285
+ if (parent === undefined || copy.hasNode(parent)) {
286
+ parents[v] = parent;
287
+ return parent;
288
+ } else if (parent in parents) {
289
+ return parents[parent];
290
+ } else {
291
+ return findParent(parent);
292
+ }
293
+ }
294
+
295
+ if (this._isCompound) {
296
+ _.each(copy.nodes(), function (v) {
297
+ copy.setParent(v, findParent(v));
298
+ });
299
+ }
300
+
301
+ return copy;
302
+ }
303
+ /* === Edge functions ========== */
304
+ setDefaultEdgeLabel(newDefault) {
305
+ if (!_.isFunction(newDefault)) {
306
+ newDefault = _.constant(newDefault);
307
+ }
308
+ this._defaultEdgeLabelFn = newDefault;
309
+ return this;
310
+ }
311
+ edgeCount() {
312
+ return this._edgeCount;
313
+ }
314
+ edges() {
315
+ return _.values(this._edgeObjs);
316
+ }
317
+ setPath(vs, value) {
318
+ var self = this;
319
+ var args = arguments;
320
+ _.reduce(vs, function (v, w) {
321
+ if (args.length > 1) {
322
+ self.setEdge(v, w, value);
323
+ } else {
324
+ self.setEdge(v, w);
325
+ }
326
+ return w;
327
+ });
328
+ return this;
329
+ }
330
+ /*
331
+ * setEdge(v, w, [value, [name]])
332
+ * setEdge({ v, w, [name] }, [value])
333
+ */
334
+ setEdge() {
335
+ var v, w, name, value;
336
+ var valueSpecified = false;
337
+ var arg0 = arguments[0];
338
+
339
+ if (typeof arg0 === 'object' && arg0 !== null && 'v' in arg0) {
340
+ v = arg0.v;
341
+ w = arg0.w;
342
+ name = arg0.name;
343
+ if (arguments.length === 2) {
344
+ value = arguments[1];
345
+ valueSpecified = true;
346
+ }
347
+ } else {
348
+ v = arg0;
349
+ w = arguments[1];
350
+ name = arguments[3];
351
+ if (arguments.length > 2) {
352
+ value = arguments[2];
353
+ valueSpecified = true;
354
+ }
355
+ }
356
+
357
+ v = '' + v;
358
+ w = '' + w;
359
+ if (!_.isUndefined(name)) {
360
+ name = '' + name;
361
+ }
362
+
363
+ var e = edgeArgsToId(this._isDirected, v, w, name);
364
+ if (_.has(this._edgeLabels, e)) {
365
+ if (valueSpecified) {
366
+ this._edgeLabels[e] = value;
367
+ }
368
+ return this;
369
+ }
370
+
371
+ if (!_.isUndefined(name) && !this._isMultigraph) {
372
+ throw new Error('Cannot set a named edge when isMultigraph = false');
373
+ }
374
+
375
+ // It didn't exist, so we need to create it.
376
+ // First ensure the nodes exist.
377
+ this.setNode(v);
378
+ this.setNode(w);
379
+
380
+ // @ts-expect-error
381
+ this._edgeLabels[e] = valueSpecified ? value : this._defaultEdgeLabelFn(v, w, name);
382
+
383
+ var edgeObj = edgeArgsToObj(this._isDirected, v, w, name);
384
+ // Ensure we add undirected edges in a consistent way.
385
+ v = edgeObj.v;
386
+ w = edgeObj.w;
387
+
388
+ Object.freeze(edgeObj);
389
+ this._edgeObjs[e] = edgeObj;
390
+ incrementOrInitEntry(this._preds[w], v);
391
+ incrementOrInitEntry(this._sucs[v], w);
392
+ this._in[w][e] = edgeObj;
393
+ this._out[v][e] = edgeObj;
394
+ this._edgeCount++;
395
+ return this;
396
+ }
397
+ edge(v, w, name) {
398
+ var e =
399
+ arguments.length === 1
400
+ ? edgeObjToId(this._isDirected, arguments[0])
401
+ : edgeArgsToId(this._isDirected, v, w, name);
402
+ return this._edgeLabels[e];
403
+ }
404
+ hasEdge(v, w, name) {
405
+ var e =
406
+ arguments.length === 1
407
+ ? edgeObjToId(this._isDirected, arguments[0])
408
+ : edgeArgsToId(this._isDirected, v, w, name);
409
+ return _.has(this._edgeLabels, e);
410
+ }
411
+ removeEdge(v, w, name) {
412
+ var e =
413
+ arguments.length === 1
414
+ ? edgeObjToId(this._isDirected, arguments[0])
415
+ : edgeArgsToId(this._isDirected, v, w, name);
416
+ var edge = this._edgeObjs[e];
417
+ if (edge) {
418
+ v = edge.v;
419
+ w = edge.w;
420
+ delete this._edgeLabels[e];
421
+ delete this._edgeObjs[e];
422
+ decrementOrRemoveEntry(this._preds[w], v);
423
+ decrementOrRemoveEntry(this._sucs[v], w);
424
+ delete this._in[w][e];
425
+ delete this._out[v][e];
426
+ this._edgeCount--;
427
+ }
428
+ return this;
429
+ }
430
+ inEdges(v, u) {
431
+ var inV = this._in[v];
432
+ if (inV) {
433
+ var edges = _.values(inV);
434
+ if (!u) {
435
+ return edges;
436
+ }
437
+ return _.filter(edges, function (edge) {
438
+ return edge.v === u;
439
+ });
440
+ }
441
+ }
442
+ outEdges(v, w) {
443
+ var outV = this._out[v];
444
+ if (outV) {
445
+ var edges = _.values(outV);
446
+ if (!w) {
447
+ return edges;
448
+ }
449
+ return _.filter(edges, function (edge) {
450
+ return edge.w === w;
451
+ });
452
+ }
453
+ }
454
+ nodeEdges(v, w) {
455
+ var inEdges = this.inEdges(v, w);
456
+ if (inEdges) {
457
+ return inEdges.concat(this.outEdges(v, w));
458
+ }
459
+ }
460
+ }
461
+
462
+ /* Number of nodes in the graph. Should only be changed by the implementation. */
463
+ Graph.prototype._nodeCount = 0;
464
+
465
+ /* Number of edges in the graph. Should only be changed by the implementation. */
466
+ Graph.prototype._edgeCount = 0;
467
+
468
+ function incrementOrInitEntry(map, k) {
469
+ if (map[k]) {
470
+ map[k]++;
471
+ } else {
472
+ map[k] = 1;
473
+ }
474
+ }
475
+
476
+ function decrementOrRemoveEntry(map, k) {
477
+ if (!--map[k]) {
478
+ delete map[k];
479
+ }
480
+ }
481
+
482
+ function edgeArgsToId(isDirected, v_, w_, name) {
483
+ var v = '' + v_;
484
+ var w = '' + w_;
485
+ if (!isDirected && v > w) {
486
+ var tmp = v;
487
+ v = w;
488
+ w = tmp;
489
+ }
490
+ return v + EDGE_KEY_DELIM + w + EDGE_KEY_DELIM + (_.isUndefined(name) ? DEFAULT_EDGE_NAME : name);
491
+ }
492
+
493
+ function edgeArgsToObj(isDirected, v_, w_, name) {
494
+ var v = '' + v_;
495
+ var w = '' + w_;
496
+ if (!isDirected && v > w) {
497
+ var tmp = v;
498
+ v = w;
499
+ w = tmp;
500
+ }
501
+ var edgeObj = { v: v, w: w };
502
+ if (name) {
503
+ edgeObj.name = name;
504
+ }
505
+ return edgeObj;
506
+ }
507
+
508
+ function edgeObjToId(isDirected, edgeObj) {
509
+ return edgeArgsToId(isDirected, edgeObj.v, edgeObj.w, edgeObj.name);
510
+ }
@@ -0,0 +1,3 @@
1
+ import { Graph } from './graph.js';
2
+ export const version: '2.1.9-pre';
3
+ export { Graph };
@@ -0,0 +1,7 @@
1
+ // Includes only the "core" of graphlib
2
+
3
+ import { Graph } from './graph.js';
4
+
5
+ const version = '2.1.9-pre';
6
+
7
+ export { Graph, version };
@@ -0,0 +1,16 @@
1
+ export function write(g: any): {
2
+ options: {
3
+ directed: any;
4
+ multigraph: any;
5
+ compound: any;
6
+ };
7
+ nodes: {
8
+ v: any;
9
+ }[];
10
+ edges: {
11
+ v: any;
12
+ w: any;
13
+ }[];
14
+ };
15
+ export function read(json: any): Graph;
16
+ import { Graph } from './graph.js';
@@ -0,0 +1,63 @@
1
+ import { _ } from '../lodash-es/index.ts';
2
+ import { Graph } from './graph.js';
3
+
4
+ export { write, read };
5
+
6
+ function write(g) {
7
+ var json = {
8
+ options: {
9
+ directed: g.isDirected(),
10
+ multigraph: g.isMultigraph(),
11
+ compound: g.isCompound(),
12
+ },
13
+ nodes: writeNodes(g),
14
+ edges: writeEdges(g),
15
+ };
16
+ if (!_.isUndefined(g.graph())) {
17
+ json.value = _.clone(g.graph());
18
+ }
19
+ return json;
20
+ }
21
+
22
+ function writeNodes(g) {
23
+ return _.map(g.nodes(), function (v) {
24
+ var nodeValue = g.node(v);
25
+ var parent = g.parent(v);
26
+ var node = { v: v };
27
+ if (!_.isUndefined(nodeValue)) {
28
+ node.value = nodeValue;
29
+ }
30
+ if (!_.isUndefined(parent)) {
31
+ node.parent = parent;
32
+ }
33
+ return node;
34
+ });
35
+ }
36
+
37
+ function writeEdges(g) {
38
+ return _.map(g.edges(), function (e) {
39
+ var edgeValue = g.edge(e);
40
+ var edge = { v: e.v, w: e.w };
41
+ if (!_.isUndefined(e.name)) {
42
+ edge.name = e.name;
43
+ }
44
+ if (!_.isUndefined(edgeValue)) {
45
+ edge.value = edgeValue;
46
+ }
47
+ return edge;
48
+ });
49
+ }
50
+
51
+ function read(json) {
52
+ var g = new Graph(json.options).setGraph(json.value);
53
+ _.each(json.nodes, function (entry) {
54
+ g.setNode(entry.v, entry.value);
55
+ if (entry.parent) {
56
+ g.setParent(entry.v, entry.parent);
57
+ }
58
+ });
59
+ _.each(json.edges, function (entry) {
60
+ g.setEdge({ v: entry.v, w: entry.w, name: entry.name }, entry.value);
61
+ });
62
+ return g;
63
+ }
@@ -0,0 +1 @@
1
+ export * from "./layout/index.ts";
@@ -0,0 +1 @@
1
+ export * from "./svg/index.ts";
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./index-layout.ts";
2
+ export * from "./index-svg.ts";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Visual element dimensions.
3
+ * @typedef {Object} Dimensions
4
+ */
5
+ export type Dimensions = {
6
+ width: number;
7
+ height: number;
8
+ };
@@ -0,0 +1,17 @@
1
+ import type { Dimensions } from "./Dimensions.ts";
2
+
3
+ /**
4
+ * Provides default functions measuring dimensions for state nodes and transition edges in the graph.
5
+ */
6
+ export type GraphParamsProvider = {
7
+ getStateParams: (
8
+ stateKey: string,
9
+ state?: string
10
+ ) => Dimensions & Record<string, any>;
11
+ getTransitionParams: (
12
+ fromStateKey: string,
13
+ event: string,
14
+ toStateKey: string
15
+ ) => Dimensions & Record<string, any>;
16
+ };
17
+
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Padding type.
3
+ */
4
+ export type Padding =
5
+ // Top, right, bottom, and left padding values
6
+ | [number, number, number, number]
7
+ // Vertical and horizontal padding values
8
+ | [number, number]
9
+ // The same as [top, right, bottom, left]
10
+ | number;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * X/Y position of a node in the graph.
3
+ */
4
+ export type Position = { x: number; y: number; };