@vsirotin/ts-stop 1.13.0 → 2.4.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 (123) hide show
  1. package/ai/skills/sfsm-compare-json-uml-diagram/SKILL.md +62 -0
  2. package/ai/skills/sfsm-json-to-uml-diagram/SKILL.md +50 -0
  3. package/ai/skills/sfsm-uml-diagram-to-json/SKILL.md +49 -0
  4. package/lib/esm/sfsm/CommandReceiver.js +17 -0
  5. package/lib/esm/sfsm/ControllerHub.js +82 -0
  6. package/lib/esm/sfsm/FaResolver.js +24 -3
  7. package/lib/esm/sfsm/Sfsm.js +48 -7
  8. package/lib/esm/sfsm/SignalSender.js +27 -0
  9. package/lib/esm/sfsm/index.js +3 -1
  10. package/lib/sfsm/CommandReceiver.d.ts +23 -0
  11. package/lib/sfsm/CommandReceiver.d.ts.map +1 -0
  12. package/lib/sfsm/CommandReceiver.js +22 -0
  13. package/lib/sfsm/CommandReceiver.js.map +1 -0
  14. package/lib/sfsm/ControllerHub.d.ts +56 -0
  15. package/lib/sfsm/ControllerHub.d.ts.map +1 -0
  16. package/lib/sfsm/ControllerHub.js +87 -0
  17. package/lib/sfsm/ControllerHub.js.map +1 -0
  18. package/lib/sfsm/FaResolver.d.ts +14 -0
  19. package/lib/sfsm/FaResolver.d.ts.map +1 -1
  20. package/lib/sfsm/FaResolver.js +24 -3
  21. package/lib/sfsm/FaResolver.js.map +1 -1
  22. package/lib/sfsm/Sfsm.d.ts +26 -0
  23. package/lib/sfsm/Sfsm.d.ts.map +1 -1
  24. package/lib/sfsm/Sfsm.js +48 -7
  25. package/lib/sfsm/Sfsm.js.map +1 -1
  26. package/lib/sfsm/SignalSender.d.ts +24 -0
  27. package/lib/sfsm/SignalSender.d.ts.map +1 -0
  28. package/lib/sfsm/SignalSender.js +32 -0
  29. package/lib/sfsm/SignalSender.js.map +1 -0
  30. package/lib/sfsm/index.d.ts +3 -1
  31. package/lib/sfsm/index.d.ts.map +1 -1
  32. package/lib/sfsm/index.js +7 -3
  33. package/lib/sfsm/index.js.map +1 -1
  34. package/lib/sfsm/interfaces.d.ts +1 -1
  35. package/lib/sfsm/types.d.ts +21 -0
  36. package/lib/sfsm/types.d.ts.map +1 -1
  37. package/package.json +8 -5
  38. package/scripts/compare-compact-jsons.js +146 -0
  39. package/scripts/drawio-to-json.js +149 -0
  40. package/scripts/json-to-drawio-old.js +311 -0
  41. package/scripts/json-to-drawio.js +309 -0
  42. package/tutorial/01-finite-state-machine.md +223 -0
  43. package/tutorial/02-stacked-finite-state-machine.md +32 -0
  44. package/tutorial/03-advanced-themes.md +110 -0
  45. package/tutorial/04-tools.md +164 -0
  46. package/tutorial/images/Turnstile-img.png +0 -0
  47. package/tutorial/images/TurnstileBaseFA.png +0 -0
  48. package/LICENSE +0 -201
  49. package/LICENSE-COMMERCIAL.md +0 -41
  50. package/README.md +0 -19
  51. package/lib/DefaultState.d.ts +0 -9
  52. package/lib/DefaultState.d.ts.map +0 -1
  53. package/lib/DefaultState.js +0 -15
  54. package/lib/DefaultState.js.map +0 -1
  55. package/lib/FiniteStateMachine.d.ts +0 -227
  56. package/lib/FiniteStateMachine.d.ts.map +0 -1
  57. package/lib/FiniteStateMachine.js +0 -410
  58. package/lib/FiniteStateMachine.js.map +0 -1
  59. package/lib/IStateWithActions.d.ts +0 -18
  60. package/lib/IStateWithActions.d.ts.map +0 -1
  61. package/lib/IStateWithActions.js +0 -3
  62. package/lib/IStateWithActions.js.map +0 -1
  63. package/lib/IStateWithOutputSignal.d.ts +0 -4
  64. package/lib/IStateWithOutputSignal.d.ts.map +0 -1
  65. package/lib/IStateWithOutputSignal.js +0 -3
  66. package/lib/IStateWithOutputSignal.js.map +0 -1
  67. package/lib/MatrixBasedStateMachine.d.ts +0 -108
  68. package/lib/MatrixBasedStateMachine.d.ts.map +0 -1
  69. package/lib/MatrixBasedStateMachine.js +0 -132
  70. package/lib/MatrixBasedStateMachine.js.map +0 -1
  71. package/lib/TransitionMatrix.d.ts +0 -61
  72. package/lib/TransitionMatrix.d.ts.map +0 -1
  73. package/lib/TransitionMatrix.js +0 -104
  74. package/lib/TransitionMatrix.js.map +0 -1
  75. package/lib/esm/DefaultState.js +0 -10
  76. package/lib/esm/FiniteStateMachine.js +0 -405
  77. package/lib/esm/IStateWithActions.js +0 -1
  78. package/lib/esm/IStateWithOutputSignal.js +0 -1
  79. package/lib/esm/MatrixBasedStateMachine.js +0 -127
  80. package/lib/esm/TransitionMatrix.js +0 -98
  81. package/lib/esm/fa/DefaultState.js +0 -10
  82. package/lib/esm/fa/FiniteStateMachine.js +0 -405
  83. package/lib/esm/fa/IStateWithActions.js +0 -1
  84. package/lib/esm/fa/IStateWithOutputSignal.js +0 -1
  85. package/lib/esm/fa/MatrixBasedStateMachine.js +0 -127
  86. package/lib/esm/fa/TransitionMatrix.js +0 -98
  87. package/lib/esm/index.js +0 -9
  88. package/lib/esm/sfsm/ExternalWorldHub.js +0 -80
  89. package/lib/esm/sfsm/index.browser.js +0 -5
  90. package/lib/fa/DefaultState.d.ts +0 -9
  91. package/lib/fa/DefaultState.d.ts.map +0 -1
  92. package/lib/fa/DefaultState.js +0 -15
  93. package/lib/fa/DefaultState.js.map +0 -1
  94. package/lib/fa/FiniteStateMachine.d.ts +0 -227
  95. package/lib/fa/FiniteStateMachine.d.ts.map +0 -1
  96. package/lib/fa/FiniteStateMachine.js +0 -410
  97. package/lib/fa/FiniteStateMachine.js.map +0 -1
  98. package/lib/fa/IStateWithActions.d.ts +0 -18
  99. package/lib/fa/IStateWithActions.d.ts.map +0 -1
  100. package/lib/fa/IStateWithActions.js +0 -3
  101. package/lib/fa/IStateWithActions.js.map +0 -1
  102. package/lib/fa/IStateWithOutputSignal.d.ts +0 -4
  103. package/lib/fa/IStateWithOutputSignal.d.ts.map +0 -1
  104. package/lib/fa/IStateWithOutputSignal.js +0 -3
  105. package/lib/fa/IStateWithOutputSignal.js.map +0 -1
  106. package/lib/fa/MatrixBasedStateMachine.d.ts +0 -108
  107. package/lib/fa/MatrixBasedStateMachine.d.ts.map +0 -1
  108. package/lib/fa/MatrixBasedStateMachine.js +0 -132
  109. package/lib/fa/MatrixBasedStateMachine.js.map +0 -1
  110. package/lib/fa/TransitionMatrix.d.ts +0 -61
  111. package/lib/fa/TransitionMatrix.d.ts.map +0 -1
  112. package/lib/fa/TransitionMatrix.js +0 -104
  113. package/lib/fa/TransitionMatrix.js.map +0 -1
  114. package/lib/index.d.ts +0 -10
  115. package/lib/index.d.ts.map +0 -1
  116. package/lib/index.js +0 -26
  117. package/lib/index.js.map +0 -1
  118. package/lib/sfsm/ExternalWorldHub.d.ts +0 -52
  119. package/lib/sfsm/ExternalWorldHub.d.ts.map +0 -1
  120. package/lib/sfsm/ExternalWorldHub.js +0 -85
  121. package/lib/sfsm/ExternalWorldHub.js.map +0 -1
  122. package/lib/sfsm/index.browser.d.ts +0 -7
  123. package/scripts/publish-local.sh +0 -15
@@ -1 +0,0 @@
1
- {"version":3,"file":"IStateWithActions.js","sourceRoot":"","sources":["../src/IStateWithActions.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- export interface IStateWithOutputSignal<SIGNAL> {
2
- getOutputSignal(): SIGNAL;
3
- }
4
- //# sourceMappingURL=IStateWithOutputSignal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IStateWithOutputSignal.d.ts","sourceRoot":"","sources":["../src/IStateWithOutputSignal.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,sBAAsB,CAAC,MAAM;IAC1C,eAAe,IAAI,MAAM,CAAC;CAC7B"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IStateWithOutputSignal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IStateWithOutputSignal.js","sourceRoot":"","sources":["../src/IStateWithOutputSignal.ts"],"names":[],"mappings":""}
@@ -1,108 +0,0 @@
1
- import { FiniteStateMachine } from './FiniteStateMachine';
2
- import { TransitionMatrix } from './TransitionMatrix';
3
- /**
4
- * Abstract base class for finite state machines that use transition matrices.
5
- *
6
- * This class extends FiniteStateMachine to provide a more intuitive way to define
7
- * state transitions using a 2D matrix representation instead of explicit transition arrays.
8
- *
9
- * The matrix format allows for visual representation of state transitions:
10
- * - Columns represent states
11
- * - Rows represent signals
12
- * - Cell values represent target states
13
- * - Empty cells represent invalid/ignored transitions
14
- *
15
- * @template STATE - The type representing possible states
16
- * @template SIGNAL - The type representing signals/events
17
- *
18
- * @example
19
- * ```typescript
20
- * // Example 1: Using explicit start state
21
- * class TurnstileMatrix extends MatrixBasedStateMachine<string, string> {
22
- * constructor() {
23
- * const matrix = transitionMatrix([
24
- * [ , "locked" , "unlocked" ],
25
- * [ "coin" , "unlocked" , ],
26
- * [ "push" , , "locked" ]
27
- * ]);
28
- * super(matrix, "locked"); // Explicit start state
29
- * }
30
- * }
31
- *
32
- * // Example 2: Using first state as start state (auto)
33
- * class TurnstileMatrixAuto extends MatrixBasedStateMachine<string, string> {
34
- * constructor() {
35
- * const matrix = transitionMatrix([
36
- * [ , "locked" , "unlocked" ], // "locked" becomes start state
37
- * [ "coin" , "unlocked" , ],
38
- * [ "push" , , "locked" ]
39
- * ]);
40
- * super(matrix); // Uses first state ("locked") as start state
41
- * }
42
- * }
43
- * ```
44
- */
45
- export declare abstract class MatrixBasedStateMachine<STATE, SIGNAL> extends FiniteStateMachine<STATE, SIGNAL> {
46
- /**
47
- * The transition matrix used to define state transitions.
48
- * Stored for potential debugging or inspection purposes.
49
- */
50
- protected readonly matrix: TransitionMatrix<STATE, SIGNAL>;
51
- /**
52
- * Creates a new matrix-based finite state machine.
53
- *
54
- * @param matrix - The transition matrix defining all states, signals, and transitions
55
- * @param startState - Optional. The initial state of the machine. If not provided,
56
- * the first state from the matrix (first column in header row) will be used.
57
- * If provided, must be one of the states in the matrix.
58
- *
59
- * @throws {Error} If matrix has no states
60
- * @throws {Error} If startState is provided but not found in the matrix states
61
- *
62
- * @example
63
- * ```typescript
64
- * // Constructor with explicit start state
65
- * const matrix = transitionMatrix([
66
- * [ , "locked" , "unlocked" ],
67
- * [ "coin" , "unlocked" , ],
68
- * [ "push" , , "locked" ]
69
- * ]);
70
- * super(matrix, "unlocked"); // Start in unlocked state
71
- *
72
- * // Constructor with auto start state (uses first state)
73
- * super(matrix); // Automatically starts in "locked" state
74
- * ```
75
- *
76
- * @example
77
- * ```typescript
78
- * // TurnstileMatrix implementation from test/Turnstile/TurnstileMatrix.ts
79
- * class TurnstileMatrix extends MatrixBasedStateMachine<string, string> {
80
- * constructor() {
81
- * const matrix = transitionMatrix([
82
- * [ , "locked" , "unlocked" ],
83
- * [ "coin" , "unlocked" , ],
84
- * [ "push" , , "locked" ]
85
- * ]);
86
- *
87
- * // Two ways to call the constructor:
88
- * super(matrix, "locked"); // Option 1: Explicit start state
89
- * // OR
90
- * super(matrix); // Option 2: Auto start state (uses "locked")
91
- * }
92
- *
93
- * insertCoin(): string { return this.sendSignal('coin'); }
94
- * pushThrough(): string { return this.sendSignal('push'); }
95
- * isLocked(): boolean { return this.getCurrentState() === 'locked'; }
96
- * isUnlocked(): boolean { return this.getCurrentState() === 'unlocked'; }
97
- * }
98
- * ```
99
- */
100
- constructor(matrix: TransitionMatrix<STATE, SIGNAL>, startState?: STATE);
101
- /**
102
- * Gets the transition matrix used by this state machine.
103
- *
104
- * @returns The transition matrix
105
- */
106
- getMatrix(): TransitionMatrix<STATE, SIGNAL>;
107
- }
108
- //# sourceMappingURL=MatrixBasedStateMachine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MatrixBasedStateMachine.d.ts","sourceRoot":"","sources":["../src/MatrixBasedStateMachine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAuB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,8BAAsB,uBAAuB,CAAC,KAAK,EAAE,MAAM,CAAE,SAAQ,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC;IAClG;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;gBACS,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,UAAU,CAAC,EAAE,KAAK;IAqCvE;;;;OAIG;IACH,SAAS,IAAI,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC;CAI/C"}
@@ -1,132 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MatrixBasedStateMachine = void 0;
4
- const FiniteStateMachine_1 = require("./FiniteStateMachine");
5
- /**
6
- * Abstract base class for finite state machines that use transition matrices.
7
- *
8
- * This class extends FiniteStateMachine to provide a more intuitive way to define
9
- * state transitions using a 2D matrix representation instead of explicit transition arrays.
10
- *
11
- * The matrix format allows for visual representation of state transitions:
12
- * - Columns represent states
13
- * - Rows represent signals
14
- * - Cell values represent target states
15
- * - Empty cells represent invalid/ignored transitions
16
- *
17
- * @template STATE - The type representing possible states
18
- * @template SIGNAL - The type representing signals/events
19
- *
20
- * @example
21
- * ```typescript
22
- * // Example 1: Using explicit start state
23
- * class TurnstileMatrix extends MatrixBasedStateMachine<string, string> {
24
- * constructor() {
25
- * const matrix = transitionMatrix([
26
- * [ , "locked" , "unlocked" ],
27
- * [ "coin" , "unlocked" , ],
28
- * [ "push" , , "locked" ]
29
- * ]);
30
- * super(matrix, "locked"); // Explicit start state
31
- * }
32
- * }
33
- *
34
- * // Example 2: Using first state as start state (auto)
35
- * class TurnstileMatrixAuto extends MatrixBasedStateMachine<string, string> {
36
- * constructor() {
37
- * const matrix = transitionMatrix([
38
- * [ , "locked" , "unlocked" ], // "locked" becomes start state
39
- * [ "coin" , "unlocked" , ],
40
- * [ "push" , , "locked" ]
41
- * ]);
42
- * super(matrix); // Uses first state ("locked") as start state
43
- * }
44
- * }
45
- * ```
46
- */
47
- class MatrixBasedStateMachine extends FiniteStateMachine_1.FiniteStateMachine {
48
- /**
49
- * Creates a new matrix-based finite state machine.
50
- *
51
- * @param matrix - The transition matrix defining all states, signals, and transitions
52
- * @param startState - Optional. The initial state of the machine. If not provided,
53
- * the first state from the matrix (first column in header row) will be used.
54
- * If provided, must be one of the states in the matrix.
55
- *
56
- * @throws {Error} If matrix has no states
57
- * @throws {Error} If startState is provided but not found in the matrix states
58
- *
59
- * @example
60
- * ```typescript
61
- * // Constructor with explicit start state
62
- * const matrix = transitionMatrix([
63
- * [ , "locked" , "unlocked" ],
64
- * [ "coin" , "unlocked" , ],
65
- * [ "push" , , "locked" ]
66
- * ]);
67
- * super(matrix, "unlocked"); // Start in unlocked state
68
- *
69
- * // Constructor with auto start state (uses first state)
70
- * super(matrix); // Automatically starts in "locked" state
71
- * ```
72
- *
73
- * @example
74
- * ```typescript
75
- * // TurnstileMatrix implementation from test/Turnstile/TurnstileMatrix.ts
76
- * class TurnstileMatrix extends MatrixBasedStateMachine<string, string> {
77
- * constructor() {
78
- * const matrix = transitionMatrix([
79
- * [ , "locked" , "unlocked" ],
80
- * [ "coin" , "unlocked" , ],
81
- * [ "push" , , "locked" ]
82
- * ]);
83
- *
84
- * // Two ways to call the constructor:
85
- * super(matrix, "locked"); // Option 1: Explicit start state
86
- * // OR
87
- * super(matrix); // Option 2: Auto start state (uses "locked")
88
- * }
89
- *
90
- * insertCoin(): string { return this.sendSignal('coin'); }
91
- * pushThrough(): string { return this.sendSignal('push'); }
92
- * isLocked(): boolean { return this.getCurrentState() === 'locked'; }
93
- * isUnlocked(): boolean { return this.getCurrentState() === 'unlocked'; }
94
- * }
95
- * ```
96
- */
97
- constructor(matrix, startState) {
98
- // Get states from matrix
99
- const states = matrix.getStates();
100
- // Validate matrix has states
101
- if (states.length === 0) {
102
- throw new Error('Matrix must contain at least one state');
103
- }
104
- // Determine the actual start state
105
- let actualStartState;
106
- if (startState !== undefined) {
107
- // Explicit start state provided - validate it exists
108
- if (!states.includes(startState)) {
109
- throw new Error(`Start state '${String(startState)}' not found in matrix states: [${states.map(s => String(s)).join(', ')}]`);
110
- }
111
- actualStartState = startState;
112
- }
113
- else {
114
- // No start state provided - use first state from matrix
115
- actualStartState = states[0];
116
- }
117
- // Call parent constructor with matrix-derived data
118
- super(matrix.getStates(), matrix.getSignals(), matrix.getTransitions(), actualStartState);
119
- // Store the matrix for potential future use
120
- this.matrix = matrix;
121
- }
122
- /**
123
- * Gets the transition matrix used by this state machine.
124
- *
125
- * @returns The transition matrix
126
- */
127
- getMatrix() {
128
- return this.matrix;
129
- }
130
- }
131
- exports.MatrixBasedStateMachine = MatrixBasedStateMachine;
132
- //# sourceMappingURL=MatrixBasedStateMachine.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MatrixBasedStateMachine.js","sourceRoot":"","sources":["../src/MatrixBasedStateMachine.ts"],"names":[],"mappings":";;;AAAA,6DAA+E;AAG/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAsB,uBAAuC,SAAQ,uCAAiC;IAOlG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;IACH,YAAY,MAAuC,EAAE,UAAkB;QACnE,yBAAyB;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAElC,6BAA6B;QAC7B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC9D,CAAC;QAED,mCAAmC;QACnC,IAAI,gBAAuB,CAAC;QAE5B,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC3B,qDAAqD;YACrD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CACX,gBAAgB,MAAM,CAAC,UAAU,CAAC,kCAAkC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC/G,CAAC;YACN,CAAC;YACD,gBAAgB,GAAG,UAAU,CAAC;QAClC,CAAC;aAAM,CAAC;YACJ,wDAAwD;YACxD,gBAAgB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC;QAED,mDAAmD;QACnD,KAAK,CACD,MAAM,CAAC,SAAS,EAAE,EAClB,MAAM,CAAC,UAAU,EAAE,EACnB,MAAM,CAAC,cAAc,EAAE,EACvB,gBAAgB,CACnB,CAAC;QAEF,4CAA4C;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;CAEJ;AAtGD,0DAsGC"}
@@ -1,61 +0,0 @@
1
- /**
2
- * Utility type to extract non-empty values from transition matrix
3
- */
4
- export type NonEmpty<T> = T extends "" | undefined | null ? never : T;
5
- /**
6
- * Creates transitions from a 2D matrix representation.
7
- *
8
- * Matrix format:
9
- * - First row: [undefined, ...states] - column headers
10
- * - Subsequent rows: [signal, ...transitions] - signal + target states
11
- * - Empty cells: undefined, null, "", or omitted
12
- *
13
- * @template STATE - Type for states
14
- * @template SIGNAL - Type for signals
15
- */
16
- export declare class TransitionMatrix<STATE, SIGNAL> {
17
- private states;
18
- private signals;
19
- private transitions;
20
- /**
21
- * Creates a transition matrix from a 2D array.
22
- *
23
- * @param matrix - 2D array where:
24
- * - matrix[0] = [undefined, ...states] (header row)
25
- * - matrix[i] = [signal, target1, target2, ...] (transition rows)
26
- *
27
- * @example
28
- * ```typescript
29
- * const matrix = [
30
- * [ , "locked" , "unlocked" ], // States header
31
- * [ "coin" , "unlocked" , ], // coin transitions
32
- * [ "push" , , "locked" ] // push transitions
33
- * ];
34
- * ```
35
- */
36
- static fromArray<S, G>(matrix: Array<Array<S | G | undefined | null | "">>): TransitionMatrix<NonEmpty<S>, NonEmpty<G>>;
37
- /**
38
- * Get all states from the matrix.
39
- */
40
- getStates(): STATE[];
41
- /**
42
- * Get all signals from the matrix.
43
- */
44
- getSignals(): SIGNAL[];
45
- /**
46
- * Get all transitions from the matrix.
47
- */
48
- getTransitions(): {
49
- from: STATE;
50
- to: STATE;
51
- signal: SIGNAL;
52
- }[];
53
- }
54
- /**
55
- * Helper function to create transition matrix from 2D array.
56
- *
57
- * @template S - State type
58
- * @template G - Signal type
59
- */
60
- export declare function transitionMatrix<S, G>(matrix: Array<Array<S | G | undefined | null | "">>): TransitionMatrix<NonEmpty<S>, NonEmpty<G>>;
61
- //# sourceMappingURL=TransitionMatrix.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TransitionMatrix.d.ts","sourceRoot":"","sources":["../src/TransitionMatrix.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,SAAS,GAAG,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC;AAEtE;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB,CAAC,KAAK,EAAE,MAAM;IACvC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,WAAW,CAAoD;IAEvE;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EACjB,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,GACpD,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAiD7C;;OAEG;IACH,SAAS,IAAI,KAAK,EAAE;IAIpB;;OAEG;IACH,UAAU,IAAI,MAAM,EAAE;IAItB;;OAEG;IACH,cAAc,IAAI;QAAE,IAAI,EAAE,KAAK,CAAC;QAAC,EAAE,EAAE,KAAK,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE;CAGjE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EACjC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,GACpD,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAE5C"}
@@ -1,104 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransitionMatrix = void 0;
4
- exports.transitionMatrix = transitionMatrix;
5
- /**
6
- * Creates transitions from a 2D matrix representation.
7
- *
8
- * Matrix format:
9
- * - First row: [undefined, ...states] - column headers
10
- * - Subsequent rows: [signal, ...transitions] - signal + target states
11
- * - Empty cells: undefined, null, "", or omitted
12
- *
13
- * @template STATE - Type for states
14
- * @template SIGNAL - Type for signals
15
- */
16
- class TransitionMatrix {
17
- constructor() {
18
- this.states = [];
19
- this.signals = [];
20
- this.transitions = [];
21
- }
22
- /**
23
- * Creates a transition matrix from a 2D array.
24
- *
25
- * @param matrix - 2D array where:
26
- * - matrix[0] = [undefined, ...states] (header row)
27
- * - matrix[i] = [signal, target1, target2, ...] (transition rows)
28
- *
29
- * @example
30
- * ```typescript
31
- * const matrix = [
32
- * [ , "locked" , "unlocked" ], // States header
33
- * [ "coin" , "unlocked" , ], // coin transitions
34
- * [ "push" , , "locked" ] // push transitions
35
- * ];
36
- * ```
37
- */
38
- static fromArray(matrix) {
39
- const instance = new TransitionMatrix();
40
- if (matrix.length === 0) {
41
- throw new Error('Matrix cannot be empty');
42
- }
43
- // Extract states from header row (skip first empty cell)
44
- const headerRow = matrix[0];
45
- const stateValues = headerRow.slice(1).filter(cell => cell !== undefined && cell !== null && cell !== "");
46
- // Type assertion: assume header row contains only states
47
- instance.states = stateValues;
48
- // Process each signal row
49
- for (let rowIndex = 1; rowIndex < matrix.length; rowIndex++) {
50
- const row = matrix[rowIndex];
51
- const signal = row[0];
52
- // Skip rows without valid signal
53
- if (!signal || signal === "" || signal === null || signal === undefined) {
54
- continue;
55
- }
56
- // Type assertion: assume first column contains only signals
57
- instance.signals.push(signal);
58
- // Process each state column
59
- for (let colIndex = 1; colIndex < row.length; colIndex++) {
60
- const targetState = row[colIndex];
61
- const fromState = instance.states[colIndex - 1];
62
- // If cell has a value, create transition
63
- if (targetState && targetState !== "" && targetState !== null && targetState !== undefined && fromState) {
64
- // Type assertion: assume cell values are states
65
- instance.transitions.push({
66
- from: fromState,
67
- to: targetState,
68
- signal: signal
69
- });
70
- }
71
- }
72
- }
73
- return instance;
74
- }
75
- /**
76
- * Get all states from the matrix.
77
- */
78
- getStates() {
79
- return [...this.states];
80
- }
81
- /**
82
- * Get all signals from the matrix.
83
- */
84
- getSignals() {
85
- return [...this.signals];
86
- }
87
- /**
88
- * Get all transitions from the matrix.
89
- */
90
- getTransitions() {
91
- return [...this.transitions];
92
- }
93
- }
94
- exports.TransitionMatrix = TransitionMatrix;
95
- /**
96
- * Helper function to create transition matrix from 2D array.
97
- *
98
- * @template S - State type
99
- * @template G - Signal type
100
- */
101
- function transitionMatrix(matrix) {
102
- return TransitionMatrix.fromArray(matrix);
103
- }
104
- //# sourceMappingURL=TransitionMatrix.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TransitionMatrix.js","sourceRoot":"","sources":["../src/TransitionMatrix.ts"],"names":[],"mappings":";;;AAoHA,4CAIC;AAnHD;;;;;;;;;;GAUG;AACH,MAAa,gBAAgB;IAA7B;QACY,WAAM,GAAY,EAAE,CAAC;QACrB,YAAO,GAAa,EAAE,CAAC;QACvB,gBAAW,GAAiD,EAAE,CAAC;IAyF3E,CAAC;IAvFG;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,SAAS,CACZ,MAAmD;QAEnD,MAAM,QAAQ,GAAG,IAAI,gBAAgB,EAA4B,CAAC;QAElE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC9C,CAAC;QAED,yDAAyD;QACzD,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5B,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CACjD,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,CACrD,CAAC;QAEF,yDAAyD;QACzD,QAAQ,CAAC,MAAM,GAAG,WAA4B,CAAC;QAE/C,0BAA0B;QAC1B,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC;YAC1D,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7B,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;YAEtB,iCAAiC;YACjC,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,EAAE,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACtE,SAAS;YACb,CAAC;YAED,4DAA4D;YAC5D,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,MAAqB,CAAC,CAAC;YAE7C,4BAA4B;YAC5B,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC;gBACvD,MAAM,WAAW,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAClC,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;gBAEhD,yCAAyC;gBACzC,IAAI,WAAW,IAAI,WAAW,KAAK,EAAE,IAAI,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS,IAAI,SAAS,EAAE,CAAC;oBACtG,gDAAgD;oBAChD,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC;wBACtB,IAAI,EAAE,SAAS;wBACf,EAAE,EAAE,WAA0B;wBAC9B,MAAM,EAAE,MAAqB;qBAChC,CAAC,CAAC;gBACP,CAAC;YACL,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,SAAS;QACL,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,UAAU;QACN,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,cAAc;QACV,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;CACJ;AA5FD,4CA4FC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC5B,MAAmD;IAEnD,OAAO,gBAAgB,CAAC,SAAS,CAAO,MAAM,CAAC,CAAC;AACpD,CAAC"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Marker base class for states that should be used processed by invalid signals and
3
- * in situation, then no transitions set for pair (current signal, current state).
4
- * Only one state in a state machine can have this role.
5
- */
6
- export class DefaultState {
7
- isDefaultState() {
8
- return true;
9
- }
10
- }