@statewalker/fsm-charts 0.2.4 → 0.2.6

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 (155) hide show
  1. package/README.md +206 -1
  2. package/dist/StateChart-cXyVRcs-.d.ts +94 -0
  3. package/dist/StateChart-cXyVRcs-.d.ts.map +1 -0
  4. package/dist/StateChartIndex-BK2315qj.d.ts +142 -0
  5. package/dist/StateChartIndex-BK2315qj.d.ts.map +1 -0
  6. package/dist/StateChartIndex-BOIrc_nq.js +355 -0
  7. package/dist/StateChartIndex-BOIrc_nq.js.map +1 -0
  8. package/dist/buildStatechartsPanel-CxQlIwTh.js +494 -0
  9. package/dist/buildStatechartsPanel-CxQlIwTh.js.map +1 -0
  10. package/dist/buildStatechartsPanel-hCtZbdiF.d.ts +79 -0
  11. package/dist/buildStatechartsPanel-hCtZbdiF.d.ts.map +1 -0
  12. package/dist/defineProperty-C0rC37pP.js +39 -0
  13. package/dist/description-panels-DI2MNlbK.js +184 -0
  14. package/dist/description-panels-DI2MNlbK.js.map +1 -0
  15. package/dist/getLabelDimensions-BY0q7j3D.d.ts +79 -0
  16. package/dist/getLabelDimensions-BY0q7j3D.d.ts.map +1 -0
  17. package/dist/getPadding-Cw0e7G2v.js +25 -0
  18. package/dist/getPadding-Cw0e7G2v.js.map +1 -0
  19. package/dist/index-config.d.ts +3 -12
  20. package/dist/index-config.js +2 -1
  21. package/dist/index-dom.d.ts +2 -49
  22. package/dist/index-dom.js +2 -1
  23. package/dist/index-html.d.ts +3 -2
  24. package/dist/index-html.js +2 -2
  25. package/dist/index-layout.d.ts +3 -77
  26. package/dist/index-layout.js +2 -2
  27. package/dist/index-runtime.d.ts +3 -141
  28. package/dist/index-runtime.js +2 -1
  29. package/dist/index.d.ts +11 -10
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +6 -6
  32. package/dist/layout-Dp671N6q.js +2465 -0
  33. package/dist/layout-Dp671N6q.js.map +1 -0
  34. package/dist/newTreeBuilder-CvtLDjGj.d.ts +54 -0
  35. package/dist/newTreeBuilder-CvtLDjGj.d.ts.map +1 -0
  36. package/dist/toFsmStateConfig-DlJkyZni.js +135 -0
  37. package/dist/toFsmStateConfig-DlJkyZni.js.map +1 -0
  38. package/dist/toFsmStateConfig-DmOlTRjv.d.ts +15 -0
  39. package/dist/toFsmStateConfig-DmOlTRjv.d.ts.map +1 -0
  40. package/package.json +54 -28
  41. package/src/config/concatTransitionsToString.ts +4 -4
  42. package/src/config/index.ts +4 -4
  43. package/src/config/serializeProcessConfig.ts +3 -3
  44. package/src/config/splitTransitionString.ts +2 -4
  45. package/src/config/toFsmStateConfig.ts +5 -12
  46. package/src/dagre/acyclic.js +9 -10
  47. package/src/dagre/add-border-segments.js +11 -7
  48. package/src/dagre/coordinate-system.js +12 -12
  49. package/src/dagre/data/list.js +2 -2
  50. package/src/dagre/debug.d.ts +1 -1
  51. package/src/dagre/debug.js +11 -11
  52. package/src/dagre/greedy-fas.js +17 -21
  53. package/src/dagre/index.d.ts +4 -4
  54. package/src/dagre/index.js +4 -4
  55. package/src/dagre/layout.js +107 -96
  56. package/src/dagre/nesting-graph.js +13 -19
  57. package/src/dagre/normalize.js +7 -7
  58. package/src/dagre/order/add-subgraph-constraints.js +2 -2
  59. package/src/dagre/order/barycenter.d.ts +1 -1
  60. package/src/dagre/order/barycenter.js +4 -4
  61. package/src/dagre/order/build-layer-graph.d.ts +1 -1
  62. package/src/dagre/order/build-layer-graph.js +7 -9
  63. package/src/dagre/order/cross-count.js +14 -17
  64. package/src/dagre/order/index.js +19 -17
  65. package/src/dagre/order/init-order.js +5 -15
  66. package/src/dagre/order/resolve-conflicts.js +10 -14
  67. package/src/dagre/order/sort-subgraph.d.ts +1 -1
  68. package/src/dagre/order/sort-subgraph.js +13 -14
  69. package/src/dagre/order/sort.d.ts +1 -1
  70. package/src/dagre/order/sort.js +6 -10
  71. package/src/dagre/parent-dummy-chains.js +10 -4
  72. package/src/dagre/position/bk.d.ts +3 -3
  73. package/src/dagre/position/bk.js +84 -65
  74. package/src/dagre/position/index.js +7 -11
  75. package/src/dagre/rank/feasible-tree.d.ts +1 -1
  76. package/src/dagre/rank/feasible-tree.js +6 -6
  77. package/src/dagre/rank/index.js +6 -6
  78. package/src/dagre/rank/network-simplex.d.ts +0 -1
  79. package/src/dagre/rank/network-simplex.js +20 -25
  80. package/src/dagre/rank/util.js +2 -6
  81. package/src/dagre/util.d.ts +12 -6
  82. package/src/dagre/util.js +31 -37
  83. package/src/dom/buildSections.ts +15 -19
  84. package/src/dom/description-panels.ts +5 -7
  85. package/src/dom/getStatesDescriptions.ts +4 -10
  86. package/src/full/index.ts +1 -1
  87. package/src/full/toFsmStateCharts.ts +11 -11
  88. package/src/graphlib/alg/components.js +2 -2
  89. package/src/graphlib/alg/dfs.js +5 -5
  90. package/src/graphlib/alg/dijkstra-all.js +4 -4
  91. package/src/graphlib/alg/dijkstra.js +9 -12
  92. package/src/graphlib/alg/find-cycles.js +7 -5
  93. package/src/graphlib/alg/floyd-warshall.js +8 -11
  94. package/src/graphlib/alg/index.d.ts +11 -11
  95. package/src/graphlib/alg/index.js +11 -11
  96. package/src/graphlib/alg/is-acyclic.js +1 -1
  97. package/src/graphlib/alg/postorder.js +2 -2
  98. package/src/graphlib/alg/preorder.js +2 -2
  99. package/src/graphlib/alg/prim.d.ts +1 -1
  100. package/src/graphlib/alg/prim.js +5 -5
  101. package/src/graphlib/alg/tarjan.js +3 -3
  102. package/src/graphlib/alg/topsort.js +1 -1
  103. package/src/graphlib/data/priority-queue.js +8 -10
  104. package/src/graphlib/graph.js +53 -52
  105. package/src/graphlib/index.d.ts +2 -2
  106. package/src/graphlib/index.js +2 -2
  107. package/src/graphlib/json.d.ts +1 -1
  108. package/src/graphlib/json.js +6 -6
  109. package/src/html/buildStatechartCss.ts +2 -2
  110. package/src/html/buildStatechartStyles.ts +5 -15
  111. package/src/html/buildStatechartSvg.ts +8 -20
  112. package/src/html/buildStatechartsPanel.ts +3 -5
  113. package/src/html/index.ts +4 -4
  114. package/src/index-config.ts +2 -2
  115. package/src/index-dom.ts +1 -1
  116. package/src/index-html.ts +2 -2
  117. package/src/index-layout.ts +2 -2
  118. package/src/index-runtime.ts +2 -2
  119. package/src/index.ts +8 -8
  120. package/src/layout/buildCharts.ts +6 -7
  121. package/src/layout/buildFlatCharts.ts +17 -21
  122. package/src/layout/getGraphParamsProvider.ts +7 -19
  123. package/src/layout/getLabelDimensions.ts +5 -5
  124. package/src/layout/index.ts +5 -4
  125. package/src/lodash-es/index.ts +2 -2
  126. package/src/lodash-es/types.ts +37 -35
  127. package/src/runtime/RuntimeStatechartApi.ts +13 -46
  128. package/src/runtime/StateChartIndex.ts +7 -24
  129. package/src/runtime/index.ts +2 -2
  130. package/src/types/FsmStateConfig.ts +1 -1
  131. package/src/types/GraphParamsProvider.ts +3 -6
  132. package/src/types/Position.ts +1 -1
  133. package/src/types/StateChart.ts +2 -2
  134. package/src/types/StateGraphEdge.ts +2 -2
  135. package/src/types/StateGraphNode.ts +2 -2
  136. package/src/types/TransitionsGraph.ts +4 -4
  137. package/src/types/index.ts +11 -11
  138. package/src/utils/BasisCurve.ts +6 -15
  139. package/src/utils/domToText.ts +3 -7
  140. package/src/utils/getPadding.ts +2 -3
  141. package/src/utils/newId.ts +2 -1
  142. package/src/utils/newRegistry.ts +13 -13
  143. package/src/utils/serializeAttrs.ts +6 -14
  144. package/src/utils/serializeCss.ts +3 -7
  145. package/src/utils/serializeStyle.ts +2 -5
  146. package/src/utils/toKebabCase.ts +1 -4
  147. package/CHANGELOG.md +0 -1
  148. package/dist/StateChart-BYBjTmC2.d.ts +0 -82
  149. package/dist/chunk-36ZLXJVD.js +0 -606
  150. package/dist/chunk-AZBRQNTU.js +0 -2739
  151. package/dist/chunk-FIQDLBWD.js +0 -9
  152. package/dist/chunk-SVKVQY7B.js +0 -133
  153. package/dist/chunk-TZHCBZVP.js +0 -422
  154. package/dist/chunk-VILLJJJD.js +0 -231
  155. package/dist/index-html-DgSCNHkR.d.ts +0 -75
@@ -1,606 +0,0 @@
1
- import { getPadding } from './chunk-FIQDLBWD.js';
2
-
3
- // src/utils/toKebabCase.ts
4
- function toKebabCase(str) {
5
- str = (str || "").trim().replace(/\s+/gim, "-");
6
- str = str.replace(
7
- /([^A-Z]?)([A-Z])/g,
8
- (_, a, b) => a.toLowerCase() + "-" + b.toLowerCase()
9
- );
10
- return str;
11
- }
12
-
13
- // src/utils/serializeCss.ts
14
- function serializeCss(obj) {
15
- return visitStyle(obj).join("\n");
16
- function visitStyle(obj2, lines = [], prefixes = [""]) {
17
- for (const [key, style] of Object.entries(obj2)) {
18
- const selectors = [];
19
- for (const sel of key.split(",").map((_) => _.trim())) {
20
- for (const prefix of prefixes) {
21
- const selector = sel.replace(
22
- /^(.)/,
23
- (_, ch) => ch === "&" ? prefix : prefix.length > 0 ? prefix + " " + ch : ch
24
- );
25
- selectors.push(selector);
26
- }
27
- }
28
- const selectorRules = [];
29
- const extensions = [];
30
- for (let [key2, value] of Object.entries(style)) {
31
- if (typeof value === "object") {
32
- visitStyle({ [key2]: value }, extensions, selectors);
33
- } else {
34
- key2 = toKebabCase(key2);
35
- selectorRules.push(` ${key2}: ${value};`);
36
- }
37
- }
38
- if (selectorRules.length) {
39
- lines.push(`${selectors.join(",\n")} {`);
40
- lines.push(...selectorRules);
41
- lines.push(`}`);
42
- }
43
- lines.push(...extensions);
44
- }
45
- return lines;
46
- }
47
- }
48
-
49
- // src/html/buildStatechartStyles.ts
50
- var activeStatesStyle = {
51
- backgroundColor: "white",
52
- borderColor: "red",
53
- borderWidth: "2px",
54
- labelColor: "red"
55
- };
56
- var activeTransitionsStyle = {
57
- backgroundColor: "#eee",
58
- borderColor: "none",
59
- borderWidth: "0",
60
- lineColor: "red",
61
- lineWidth: "1px",
62
- labelColor: "red"
63
- };
64
- var selectedStatesStyle = {
65
- backgroundColor: "white",
66
- borderColor: "navy",
67
- borderWidth: "2px",
68
- labelColor: "navy"
69
- };
70
- var selectedTransitionsStyle = {
71
- backgroundColor: "#eee",
72
- borderColor: "none",
73
- borderWidth: "0",
74
- lineColor: "navy",
75
- lineWidth: "1px",
76
- labelColor: "navy"
77
- };
78
- function buildStateDetailsStyle({
79
- root = ":root"
80
- }) {
81
- return {
82
- [root]: {
83
- // --------------------------
84
- // Panels
85
- ".state-details": {
86
- backgroundColor: "var(--state-background-color, white)",
87
- border: "var(--state-border-width, 1px) solid var(--state-border-color, currentColor)",
88
- borderRadius: "0.5em",
89
- padding: "0.5em"
90
- },
91
- ".state-details__label": {
92
- cursor: "pointer",
93
- color: "var(--transition-label-color, currentColor)",
94
- fontFamily: "var(--state-label-font-family, sans-serif)",
95
- fontSize: "var(--state-label-font-size, 14px)"
96
- },
97
- ".state-details__content": {
98
- display: "flex",
99
- flexDirection: "column",
100
- gap: "0.5em"
101
- },
102
- ".state-details__chart": {
103
- maxWidth: "100%",
104
- overflow: "auto",
105
- scrollbarWidth: "thin"
106
- }
107
- }
108
- };
109
- }
110
- function buildStateDetailsStyleWithModifier({
111
- root = ":root",
112
- modifier,
113
- states
114
- }) {
115
- return {
116
- [root]: {
117
- //
118
- ".state-details": {
119
- [`&.state-details--${modifier}`]: {
120
- backgroundColor: `var(--state-${modifier}-background-color, ${states.backgroundColor})`,
121
- border: `var(--state-${modifier}-border-width, 1px) solid var(--state-${modifier}-border-color, currentColor)`
122
- }
123
- },
124
- ".state-details__label": {
125
- [`&.state-details__label--${modifier}`]: {
126
- color: `var(--state-${modifier}-label-color)`
127
- }
128
- }
129
- }
130
- };
131
- }
132
- function buildStatechartStylesWithModifier({
133
- root = ":root",
134
- modifier,
135
- states,
136
- transitions
137
- }) {
138
- return {
139
- [root]: {
140
- // --------------------------------------
141
- // Default values for transitions
142
- [`--transition-${modifier}-background-color`]: transitions.backgroundColor,
143
- [`--transition-${modifier}-border-color`]: transitions.borderColor,
144
- [`--transition-${modifier}-border-width`]: transitions.borderWidth,
145
- [`--transition-${modifier}-line-color`]: transitions.lineColor,
146
- [`--transition-${modifier}-line-width`]: transitions.lineWidth,
147
- [`--transition-${modifier}-label-color`]: transitions.labelColor,
148
- // --------------------------------------
149
- // Default values for states
150
- [`--state-${modifier}-background-color`]: states.backgroundColor,
151
- [`--state-${modifier}-border-color`]: states.borderColor,
152
- [`--state-${modifier}-border-width`]: states.borderWidth,
153
- [`--state-${modifier}-label-color`]: states.labelColor,
154
- ".state": {
155
- [`&.state--${modifier}`]: {
156
- "--state-background-color": `var(--state-${modifier}-background-color)`,
157
- "--state-border-color": `var(--state-${modifier}-border-color)`,
158
- "--state-border-width": `var(--state-${modifier}-border-width)`,
159
- "--state-label-color": `var(--state-${modifier}-label-color)`
160
- }
161
- },
162
- ".transition": {
163
- [`&.transition--${modifier}`]: {
164
- "--transition-background-color": `var(--transition-${modifier}-background-color)`,
165
- "--transition-border-color": `var(--transition-${modifier}-border-color)`,
166
- "--transition-border-width": `var(--transition-${modifier}-border-width)`,
167
- "--transition-line-color": `var(--transition-${modifier}-line-color)`,
168
- "--transition-line-width": `var(--transition-${modifier}-line-width)`,
169
- "--transition-label-color": `var(--transition-${modifier}-label-color)`
170
- }
171
- }
172
- }
173
- };
174
- }
175
- function buildStatechartStyles({
176
- root = ":root"
177
- }) {
178
- return {
179
- [root]: {
180
- // --------------------------------------
181
- // Transitions
182
- "--transition-background-color": "rgba(255,255,255,0.7)",
183
- "--transition-border-color": "none",
184
- "--transition-border-width": "1px",
185
- "--transition-line-color": "silver",
186
- "--transition-line-width": "1px",
187
- "--transition-label-color": "gray",
188
- "--transition-label-font-size": "12px",
189
- "--transition-label-font-family": "sans-serif",
190
- ".transition__marker": {
191
- fill: "var(--transition-line-color, currentColor)",
192
- stroke: "none"
193
- },
194
- ".transition__line": {
195
- stroke: "var(--transition-line-color, currentColor)",
196
- strokeWidth: "var(--transition-line-width, 1px)"
197
- },
198
- ".transition__box": {
199
- fill: "var(--transition-background-color, rgba(255,255,255,0.7))",
200
- stroke: "var(--transition-border-color, none)",
201
- strokeWidth: "var(--transition-border-width, 1px)",
202
- borderRadius: "0.5em",
203
- cursor: "pointer"
204
- },
205
- ".transition__label": {
206
- fill: "var(--transition-label-color, currentColor)",
207
- fontSize: "var(--transition-label-font-size, 12px)",
208
- fontFamily: "var(--transition-label-font-family, sans-serif)",
209
- cursor: "pointer"
210
- },
211
- // --------------------------------------
212
- // Normal states
213
- "--state-background-color": "white",
214
- "--state-border-color": "silver",
215
- "--state-border-width": "1px",
216
- "--state-label-color": "gray",
217
- "--state-label-font-size": "14px",
218
- "--state-label-font-family": "sans-serif",
219
- ".state__box": {
220
- fill: "var(--state-background-color, white)",
221
- stroke: "var(--state-border-color, currentColor)",
222
- strokeWidth: "var(--state-border-width, 1px)",
223
- borderRadius: "0.5em",
224
- cursor: "pointer"
225
- },
226
- ".state__label": {
227
- color: "var(--state-label-color, currentColor)",
228
- fill: "var(--state-label-color, currentColor)",
229
- fontSize: "var(--state-label-font-size, 14px)",
230
- fontFamily: "var(--state-label-font-family, sans-serif)",
231
- cursor: "pointer"
232
- },
233
- ".state__initial": {
234
- fill: "var(--state-border-color, currentColor)",
235
- stroke: "var(--state-border-color, currentColor)",
236
- strokeWidth: "var(--state-border-width, 2px)"
237
- },
238
- ".state__final": {
239
- fill: "white",
240
- stroke: "var(--state-border-color, currentColor)",
241
- strokeWidth: "var(--state-border-width, 2px)",
242
- // ---------------------------
243
- "&.state__final--inner": {
244
- fill: "var(--state-border-color, currentColor)",
245
- stroke: "none",
246
- strokeWidth: "0"
247
- }
248
- }
249
- }
250
- };
251
- }
252
-
253
- // src/html/buildStatechartCss.ts
254
- function buildStatechartCss({ prefix = "" } = {}) {
255
- const root = prefix || ":root";
256
- return [
257
- buildStatechartStyles({ root }),
258
- buildStatechartStylesWithModifier({
259
- root,
260
- modifier: "selected",
261
- states: selectedStatesStyle,
262
- transitions: selectedTransitionsStyle
263
- }),
264
- buildStatechartStylesWithModifier({
265
- root,
266
- modifier: "active",
267
- states: activeStatesStyle,
268
- transitions: activeTransitionsStyle
269
- }),
270
- buildStateDetailsStyle({ root }),
271
- buildStateDetailsStyleWithModifier({
272
- root,
273
- modifier: "selected",
274
- states: selectedStatesStyle
275
- }),
276
- buildStateDetailsStyleWithModifier({
277
- root,
278
- modifier: "active",
279
- states: activeStatesStyle
280
- })
281
- ].map(serializeCss).join("\n");
282
- }
283
-
284
- // src/utils/serializeAttrs.ts
285
- function serializeAttrs(attrs = {}, {
286
- prefix = "",
287
- transform = false
288
- } = {}) {
289
- const result = [];
290
- for (const [key, value] of Object.entries(attrs || {}).sort(
291
- ([a], [b]) => a > b ? 1 : -1
292
- )) {
293
- if (value === void 0 || value === null || value === "") continue;
294
- result.push(
295
- `${prefix}${escapeValue(key)}${"=" + JSON.stringify(
296
- escapeValue(transform ? toKebabCase(String(value)) : value)
297
- )}`
298
- );
299
- }
300
- return result.join(" ");
301
- function escapeValue(value) {
302
- return String(value).replaceAll(/</gim, "&lt;").replaceAll(/>/gim, "&gt;").replaceAll(/"/gim, "&qout;");
303
- }
304
- }
305
-
306
- // src/utils/BasisCurve.ts
307
- var BasisCurve = class {
308
- constructor(context) {
309
- this._x0 = 0;
310
- this._y0 = 0;
311
- this._x1 = 0;
312
- this._y1 = 0;
313
- this._point = 0;
314
- this._line = 0;
315
- this._context = context;
316
- }
317
- $point(x, y) {
318
- this._context.bezierCurveTo(
319
- (2 * this._x0 + this._x1) / 3,
320
- (2 * this._y0 + this._y1) / 3,
321
- (this._x0 + 2 * this._x1) / 3,
322
- (this._y0 + 2 * this._y1) / 3,
323
- (this._x0 + 4 * this._x1 + x) / 6,
324
- (this._y0 + 4 * this._y1 + y) / 6
325
- );
326
- }
327
- areaStart() {
328
- this._line = 0;
329
- }
330
- areaEnd() {
331
- this._line = NaN;
332
- }
333
- lineStart() {
334
- this._x0 = this._x1 = this._y0 = this._y1 = NaN;
335
- this._point = 0;
336
- }
337
- lineEnd() {
338
- switch (this._point) {
339
- case 3:
340
- this.$point(this._x1, this._y1);
341
- // falls through
342
- case 2:
343
- this._context.lineTo(this._x1, this._y1);
344
- break;
345
- }
346
- if (this._line || this._line !== 0 && this._point === 1)
347
- this._context.closePath();
348
- this._line = 1 - this._line;
349
- }
350
- point(x, y) {
351
- x = +x, y = +y;
352
- switch (this._point) {
353
- case 0:
354
- this._point = 1;
355
- this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y);
356
- break;
357
- case 1:
358
- this._point = 2;
359
- break;
360
- case 2:
361
- this._point = 3;
362
- this._context.lineTo(
363
- (5 * this._x0 + this._x1) / 6,
364
- (5 * this._y0 + this._y1) / 6
365
- );
366
- // falls through
367
- default:
368
- this.$point(x, y);
369
- break;
370
- }
371
- this._x0 = this._x1, this._x1 = x;
372
- this._y0 = this._y1, this._y1 = y;
373
- }
374
- };
375
-
376
- // src/html/buildStatechartSvg.ts
377
- function getBoxParams({
378
- x,
379
- y,
380
- width,
381
- height,
382
- padding = 0
383
- }) {
384
- const [top, right, bottom, left] = getPadding(padding);
385
- const h = Math.ceil(height - top - bottom);
386
- return {
387
- x: x + left,
388
- y: y - bottom - h,
389
- width: Math.ceil(width - left - right),
390
- height: h
391
- };
392
- }
393
- function buildStatechartSvg({
394
- graph: { width, height, nodes, edges },
395
- newId,
396
- stateFontSize = 14,
397
- transitionFontSize = 12,
398
- println,
399
- initialStateKey = "<initial>",
400
- finalStateKey = "<final>"
401
- }) {
402
- if (!nodes.length && !edges.length) return;
403
- width = Math.ceil(width);
404
- height = Math.ceil(height);
405
- println(
406
- `<svg ${serializeAttrs({
407
- class: "statechart",
408
- width,
409
- height,
410
- viewbox: `0 0 ${width} ${height}`,
411
- xmlns: "http://www.w3.org/2000/svg"
412
- })}>`
413
- );
414
- println(`<g class="statechart__transitions">`);
415
- const markerAttrs = serializeAttrs({
416
- refX: 19,
417
- refY: 7,
418
- markerWidth: 20,
419
- markerHeight: 14,
420
- orient: "auto",
421
- class: "transition__marker",
422
- stroke: "none",
423
- fill: "currentColor"
424
- });
425
- for (const edge of edges) {
426
- const { id, points, text } = edge;
427
- println(` <g class="transition" data-transition-id="${id}">`);
428
- const markerId = newId("marker");
429
- println(` <defs>`);
430
- println(` <marker id="${markerId}" ${markerAttrs}>`);
431
- println(` <path d="M 19,7 L9,13 L14,7 L9,1 Z"></path>`);
432
- println(` </marker>`);
433
- println(` </defs>`);
434
- const path = [];
435
- const round = (...n) => n.map(Math.round);
436
- const base = new BasisCurve({
437
- bezierCurveTo(x0, y0, x1, y1, x2, y2) {
438
- path.push("C" + round(x0, y0, x1, y1, x2, y2).join(","));
439
- },
440
- moveTo(x, y) {
441
- path.push("M" + round(x, y).join(","));
442
- },
443
- lineTo(x, y) {
444
- path.push("L" + round(x, y).join(","));
445
- },
446
- closePath() {
447
- path.push("Z");
448
- }
449
- });
450
- base.lineStart();
451
- for (const point of points) {
452
- base.point(point.x, point.y);
453
- }
454
- base.lineEnd();
455
- const serializedAttrs = serializeAttrs({
456
- class: "transition__line",
457
- fill: "none",
458
- stroke: "currentColor",
459
- strokeWidth: "1px",
460
- d: path.join(""),
461
- "marker-end": `url(#${markerId})`
462
- });
463
- println(` <path ${serializedAttrs} />`);
464
- if (text) {
465
- const { x, y, width: width2, height: height2 } = getBoxParams({
466
- ...edge,
467
- padding: 0
468
- });
469
- const rectAttrs = serializeAttrs({
470
- x,
471
- y: y - transitionFontSize,
472
- width: width2,
473
- height: height2,
474
- rx: Math.ceil(transitionFontSize / 2),
475
- ry: Math.ceil(transitionFontSize / 2),
476
- fill: "rgba(255,255,255,0.7)",
477
- stroke: "none",
478
- strokeWidth: "1",
479
- class: "transition__box"
480
- });
481
- println(` <rect ${rectAttrs} />`);
482
- const textAttrs = serializeAttrs({
483
- class: "transition__label",
484
- "text-anchor": "middle",
485
- fill: "currentColor",
486
- x: Math.round(x + width2 / 2),
487
- y: Math.round(y + height2 / 2 - transitionFontSize / 2)
488
- });
489
- println(` <text ${textAttrs}>${text}</text>`);
490
- }
491
- println(` </g>`);
492
- }
493
- println("</g>");
494
- const shift = stateFontSize / 4;
495
- const initialStateRadius = 6;
496
- const finalStateRadius = initialStateRadius / 2;
497
- println(`<g class="statechart__states">`);
498
- for (const node of nodes) {
499
- const { key, id, text } = node;
500
- const { x, y, width: width2, height: height2 } = getBoxParams({ ...node, padding: shift });
501
- println(` <g class="state" data-state-id="${id}">`);
502
- if (key === initialStateKey || key === finalStateKey) {
503
- const cx = Math.round(x + width2 / 2);
504
- const cy = Math.round(y + height2 / 2);
505
- if (key === initialStateKey) {
506
- const serializedAttrs = serializeAttrs({
507
- class: "state__initial",
508
- cx,
509
- cy,
510
- r: initialStateRadius,
511
- fill: "none",
512
- stroke: "currentColor",
513
- strokeWidth: "2"
514
- });
515
- println(` <circle ${serializedAttrs} />`);
516
- } else {
517
- let serializedAttrs = serializeAttrs({
518
- class: "state__final",
519
- cx,
520
- cy,
521
- r: initialStateRadius,
522
- fill: "none",
523
- stroke: "currentColor",
524
- strokeWidth: 2
525
- });
526
- println(` <circle ${serializedAttrs} />`);
527
- serializedAttrs = serializeAttrs({
528
- class: "state__final state__final--inner",
529
- cx,
530
- cy,
531
- r: finalStateRadius,
532
- fill: "currentColor",
533
- stroke: "none",
534
- strokeWidth: 0
535
- });
536
- println(` <circle ${serializedAttrs} />`);
537
- }
538
- } else {
539
- const rectAttrs = serializeAttrs({
540
- x,
541
- y,
542
- width: width2,
543
- height: height2,
544
- rx: Math.ceil(stateFontSize / 2),
545
- ry: Math.ceil(stateFontSize / 2),
546
- fill: "none",
547
- stroke: "currentColor",
548
- strokeWidth: "2",
549
- class: "state__box"
550
- });
551
- println(` <rect ${rectAttrs} />`);
552
- const textAttrs = serializeAttrs({
553
- class: "state__label",
554
- "text-anchor": "middle",
555
- fill: "currentColor",
556
- x: Math.round(x + width2 / 2),
557
- y: Math.round(y + height2 / 2 + stateFontSize / 4)
558
- });
559
- println(` <text ${textAttrs}>${text}</text>`);
560
- }
561
- println(" </g>");
562
- }
563
- println("</g>");
564
- println("</svg>");
565
- }
566
-
567
- // src/html/buildStatechartsPanel.ts
568
- function buildStatechartsPanel({
569
- statechart,
570
- newId,
571
- println,
572
- initialStateKey = "<initial>",
573
- finalStateKey = "<final>"
574
- }) {
575
- render(statechart, println);
576
- function render(statechart2, println2) {
577
- println2(
578
- ` <details class="state-details" data-state-id="${statechart2.id}">`
579
- );
580
- println2(
581
- ` <summary class="state-details__label">${statechart2.text ?? statechart2.state}</summary>`
582
- );
583
- println2(` <div class="state-details__content">`);
584
- const printChildren = (str) => println2(` ${str}`);
585
- if (statechart2.nodes.length) {
586
- println2(` <div class="state-details__chart">`);
587
- buildStatechartSvg({
588
- graph: statechart2,
589
- newId,
590
- println: printChildren,
591
- initialStateKey,
592
- finalStateKey
593
- });
594
- println2(` </div>`);
595
- }
596
- println2(` <div class="state-details__description">`);
597
- println2(` </div>`);
598
- for (const child of statechart2.children || []) {
599
- render(child, printChildren);
600
- }
601
- println2(` </div>`);
602
- println2(` </details>`);
603
- }
604
- }
605
-
606
- export { activeStatesStyle, activeTransitionsStyle, buildStateDetailsStyle, buildStateDetailsStyleWithModifier, buildStatechartCss, buildStatechartStyles, buildStatechartStylesWithModifier, buildStatechartSvg, buildStatechartsPanel, selectedStatesStyle, selectedTransitionsStyle, serializeCss, toKebabCase };