@statewalker/fsm-charts 0.2.5 → 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 (74) 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 -2
  21. package/dist/index-dom.d.ts +2 -49
  22. package/dist/index-dom.js +2 -2
  23. package/dist/index-html.d.ts +3 -2
  24. package/dist/index-html.js +2 -3
  25. package/dist/index-layout.d.ts +3 -77
  26. package/dist/index-layout.js +2 -3
  27. package/dist/index-runtime.d.ts +3 -141
  28. package/dist/index-runtime.js +2 -2
  29. package/dist/index.d.ts +11 -10
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +6 -7
  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 +53 -25
  41. package/src/config/concatTransitionsToString.ts +2 -2
  42. package/src/config/splitTransitionString.ts +1 -3
  43. package/src/config/toFsmStateConfig.ts +2 -9
  44. package/src/dom/buildSections.ts +3 -11
  45. package/src/dom/description-panels.ts +2 -4
  46. package/src/dom/getStatesDescriptions.ts +3 -9
  47. package/src/full/toFsmStateCharts.ts +1 -1
  48. package/src/html/buildStatechartStyles.ts +4 -14
  49. package/src/html/buildStatechartSvg.ts +2 -14
  50. package/src/html/buildStatechartsPanel.ts +1 -3
  51. package/src/layout/buildCharts.ts +1 -2
  52. package/src/layout/buildFlatCharts.ts +6 -8
  53. package/src/layout/getGraphParamsProvider.ts +3 -12
  54. package/src/runtime/RuntimeStatechartApi.ts +10 -32
  55. package/src/runtime/StateChartIndex.ts +6 -23
  56. package/src/types/GraphParamsProvider.ts +1 -4
  57. package/src/utils/BasisCurve.ts +5 -14
  58. package/src/utils/domToText.ts +2 -6
  59. package/src/utils/getPadding.ts +1 -2
  60. package/src/utils/newId.ts +2 -1
  61. package/src/utils/newRegistry.ts +12 -12
  62. package/src/utils/serializeAttrs.ts +3 -11
  63. package/src/utils/serializeCss.ts +1 -5
  64. package/src/utils/serializeStyle.ts +1 -4
  65. package/src/utils/toKebabCase.ts +1 -4
  66. package/dist/StateChart-BYBjTmC2.d.ts +0 -82
  67. package/dist/chunk-2LFUT2C6.js +0 -2691
  68. package/dist/chunk-ARZYBFNA.js +0 -133
  69. package/dist/chunk-CR2M4445.js +0 -608
  70. package/dist/chunk-FIQDLBWD.js +0 -9
  71. package/dist/chunk-GW2Z65BN.js +0 -429
  72. package/dist/chunk-PKBMQBKP.js +0 -5
  73. package/dist/chunk-RZ4FP6JB.js +0 -233
  74. package/dist/index-html-BBQqYoST.d.ts +0 -75
@@ -7,7 +7,6 @@ import type { Padding } from "../types/Padding.js";
7
7
  */
8
8
  export function getPadding(padding: Padding): [number, number, number, number] {
9
9
  if (typeof padding === "number") return [padding, padding, padding, padding];
10
- if (padding.length === 2)
11
- return [padding[0], padding[1], padding[0], padding[1]];
10
+ if (padding.length === 2) return [padding[0], padding[1], padding[0], padding[1]];
12
11
  return padding;
13
12
  }
@@ -1,5 +1,6 @@
1
1
  export function newId(prefix: string = "id"): string {
2
2
  const ns = newId as any;
3
- const id = (ns._idCounter = (ns._idCounter || 0) + 1);
3
+ ns._idCounter = (ns._idCounter || 0) + 1;
4
+ const id = ns._idCounter;
4
5
  return `${prefix}_${id}`;
5
6
  }
@@ -4,17 +4,12 @@ export type Registry = [
4
4
  unregister: (action: () => unknown) => void,
5
5
  ];
6
6
 
7
- export function newRegistry(
8
- onError: (error: any) => unknown = console.error,
9
- ): Registry {
7
+ export function newRegistry(onError: (error: any) => unknown = console.error): Registry {
10
8
  let counter = 0;
11
- const registrations: Record<
12
- number,
13
- ((skip?: boolean) => void) & { action: () => void }
14
- > = {};
9
+ const registrations: Record<number, ((skip?: boolean) => void) & { action: () => void }> = {};
15
10
  const register = (action: () => unknown) => {
16
11
  const id = counter++;
17
- return (registrations[id] = Object.assign(
12
+ const registration = Object.assign(
18
13
  (skip?: boolean) => {
19
14
  try {
20
15
  delete registrations[id];
@@ -24,10 +19,15 @@ export function newRegistry(
24
19
  }
25
20
  },
26
21
  { action },
27
- ));
22
+ );
23
+ registrations[id] = registration;
24
+ return registration;
25
+ };
26
+ const unregister = (action: () => void) => {
27
+ for (const r of Object.values(registrations)) if (r.action === action) r(true);
28
+ };
29
+ const clear = () => {
30
+ for (const r of Object.values(registrations)) r();
28
31
  };
29
- const unregister = (action: () => void) =>
30
- Object.values(registrations).forEach((r) => r.action === action && r(true));
31
- const clear = () => Object.values(registrations).forEach((r) => r());
32
32
  return [register, clear, unregister];
33
33
  }
@@ -2,22 +2,14 @@ import { toKebabCase } from "./toKebabCase.js";
2
2
 
3
3
  export function serializeAttrs(
4
4
  attrs: Record<string, string | number | undefined> = {},
5
- {
6
- prefix = "",
7
- transform = false,
8
- }: { prefix?: string; transform?: boolean } = {},
5
+ { prefix = "", transform = false }: { prefix?: string; transform?: boolean } = {},
9
6
  ) {
10
7
  const result: string[] = [];
11
- for (const [key, value] of Object.entries(attrs || {}).sort(([a], [b]) =>
12
- a > b ? 1 : -1,
13
- )) {
8
+ for (const [key, value] of Object.entries(attrs || {}).sort(([a], [b]) => (a > b ? 1 : -1))) {
14
9
  if (value === undefined || value === null || value === "") continue;
15
10
  result.push(
16
11
  `${prefix}${escapeValue(key)}${
17
- "=" +
18
- JSON.stringify(
19
- escapeValue(transform ? toKebabCase(String(value)) : value),
20
- )
12
+ "=" + JSON.stringify(escapeValue(transform ? toKebabCase(String(value)) : value))
21
13
  }`,
22
14
  );
23
15
  }
@@ -5,11 +5,7 @@ export interface CssTree extends Record<string, string | number | CssTree> {}
5
5
  export function serializeCss(obj: CssTree) {
6
6
  return visitStyle(obj).join("\n");
7
7
 
8
- function visitStyle(
9
- obj: CssTree,
10
- lines: string[] = [],
11
- prefixes: string[] = [""],
12
- ) {
8
+ function visitStyle(obj: CssTree, lines: string[] = [], prefixes: string[] = [""]) {
13
9
  for (const [key, style] of Object.entries(obj)) {
14
10
  const selectors = [];
15
11
  for (const sel of key.split(",").map((_) => _.trim())) {
@@ -1,9 +1,6 @@
1
1
  import { toKebabCase } from "./toKebabCase.js";
2
2
 
3
- export function serializeStyle(
4
- style: Record<string, string>,
5
- separator = "; ",
6
- ) {
3
+ export function serializeStyle(style: Record<string, string>, separator = "; ") {
7
4
  const str = Object.entries(style)
8
5
  .map(([key, value]) => `${toKebabCase(key)}: ${value}`)
9
6
  .join(separator);
@@ -2,10 +2,7 @@ export function toKebabCase(str?: string): string {
2
2
  // Remove spaces:
3
3
  str = (str || "").trim().replace(/\s+/gim, "-");
4
4
  // Transform to kebab:
5
- str = str.replace(
6
- /([^A-Z]?)([A-Z])/g,
7
- (_, a, b) => `${a.toLowerCase()}-${b.toLowerCase()}`,
8
- );
5
+ str = str.replace(/([^A-Z]?)([A-Z])/g, (_, a, b) => `${a.toLowerCase()}-${b.toLowerCase()}`);
9
6
  return str;
10
7
 
11
8
  // return (
@@ -1,82 +0,0 @@
1
- /**
2
- * Visual element dimensions.
3
- * @typedef {Object} Dimensions
4
- */
5
- type Dimensions = {
6
- width: number;
7
- height: number;
8
- };
9
-
10
- /**
11
- * A transition from one state to another.
12
- * Contains the state before the transition, the event that triggers the transition, and the state after the transition.
13
- */
14
- type Transition = [string, string, string];
15
-
16
- type FsmStateConfig = {
17
- key: string;
18
- transitions?: Transition[];
19
- states?: FsmStateConfig[];
20
- } & Record<string, any>;
21
-
22
- /**
23
- * Human-readable label
24
- */
25
- type Label = {
26
- text: string;
27
- };
28
-
29
- /**
30
- * Provides default functions measuring dimensions for state nodes and transition edges in the graph.
31
- */
32
- type GraphParamsProvider = {
33
- getStateParams: (stateKey: string, state?: string) => Dimensions & Label & Record<string, any>;
34
- getTransitionParams: (fromStateKey: string, event: string, toStateKey: string) => Dimensions & Label & Record<string, any>;
35
- };
36
-
37
- /**
38
- * Padding type.
39
- */
40
- type Padding = [number, number, number, number] | [number, number] | number;
41
-
42
- /**
43
- * X/Y position of a node in the graph.
44
- */
45
- type Position = {
46
- x: number;
47
- y: number;
48
- };
49
-
50
- /**
51
- * Information about a state node in the graph.
52
- */
53
- type StateGraphNode = Dimensions & Position & {
54
- id: string;
55
- key: string;
56
- text: string;
57
- } & Record<string, any>;
58
-
59
- /**
60
- * Information about a state graph edge.
61
- */
62
- type StateGraphEdge = Dimensions & Position & {
63
- id: string;
64
- from: string;
65
- event: string;
66
- to: string;
67
- points: Position[];
68
- } & Record<string, any>;
69
-
70
- /**
71
- * Coordinates for state nodes and endges corresponding to state transitions.
72
- */
73
- type TransitionsGraph = Position & Dimensions & {
74
- nodes: StateGraphNode[];
75
- edges: StateGraphEdge[];
76
- };
77
-
78
- type StateChart = TransitionsGraph & StateGraphNode & {
79
- children?: StateChart[];
80
- } & Record<string, any>;
81
-
82
- export type { Dimensions as D, FsmStateConfig as F, GraphParamsProvider as G, Label as L, Padding as P, StateChart as S, Transition as T, Position as a, StateGraphEdge as b, StateGraphNode as c, TransitionsGraph as d };